]> git.sesse.net Git - rdpsrv/commitdiff
Import X server from vnc-3.3.7.
authorSteinar H. Gunderson <sesse@samfundet.no>
Fri, 4 Feb 2005 14:48:36 +0000 (14:48 +0000)
committerSteinar H. Gunderson <sesse@samfundet.no>
Fri, 4 Feb 2005 14:48:36 +0000 (14:48 +0000)
836 files changed:
Xserver/INSTALL.PS [new file with mode: 0644]
Xserver/INSTALL.TXT [new file with mode: 0644]
Xserver/Imakefile [new file with mode: 0644]
Xserver/LABEL [new file with mode: 0644]
Xserver/Makefile [new file with mode: 0644]
Xserver/README [new file with mode: 0644]
Xserver/RELNOTES.PS [new file with mode: 0644]
Xserver/RELNOTES.TXT [new file with mode: 0644]
Xserver/bug-report [new file with mode: 0644]
Xserver/config/Imakefile [new file with mode: 0644]
Xserver/config/cf/Amoeba.cf [new file with mode: 0644]
Xserver/config/cf/DGUX.cf [new file with mode: 0644]
Xserver/config/cf/FreeBSD.cf [new file with mode: 0644]
Xserver/config/cf/Imake.cf [new file with mode: 0644]
Xserver/config/cf/Imake.rules [new file with mode: 0644]
Xserver/config/cf/Imake.tmpl [new file with mode: 0644]
Xserver/config/cf/Imakefile [new file with mode: 0644]
Xserver/config/cf/Library.tmpl [new file with mode: 0644]
Xserver/config/cf/Mips.cf [new file with mode: 0644]
Xserver/config/cf/Motif.rules [new file with mode: 0644]
Xserver/config/cf/Motif.tmpl [new file with mode: 0644]
Xserver/config/cf/NetBSD.cf [new file with mode: 0644]
Xserver/config/cf/Oki.cf [new file with mode: 0644]
Xserver/config/cf/OpenBSD.cf [new file with mode: 0644]
Xserver/config/cf/README [new file with mode: 0644]
Xserver/config/cf/Server.tmpl [new file with mode: 0644]
Xserver/config/cf/ServerLib.tmpl [new file with mode: 0644]
Xserver/config/cf/Threads.tmpl [new file with mode: 0644]
Xserver/config/cf/Win32.cf [new file with mode: 0644]
Xserver/config/cf/Win32.rules [new file with mode: 0644]
Xserver/config/cf/WinLib.tmpl [new file with mode: 0644]
Xserver/config/cf/X11.rules [new file with mode: 0644]
Xserver/config/cf/X11.tmpl [new file with mode: 0644]
Xserver/config/cf/apollo.cf [new file with mode: 0644]
Xserver/config/cf/bsd.cf [new file with mode: 0644]
Xserver/config/cf/bsdLib.rules [new file with mode: 0644]
Xserver/config/cf/bsdLib.tmpl [new file with mode: 0644]
Xserver/config/cf/bsdi.cf [new file with mode: 0644]
Xserver/config/cf/cde.rules [new file with mode: 0644]
Xserver/config/cf/cde.tmpl [new file with mode: 0644]
Xserver/config/cf/convex.cf [new file with mode: 0644]
Xserver/config/cf/cray.cf [new file with mode: 0644]
Xserver/config/cf/fujitsu.cf [new file with mode: 0644]
Xserver/config/cf/generic.cf [new file with mode: 0644]
Xserver/config/cf/hp.cf [new file with mode: 0644]
Xserver/config/cf/hpLib.rules [new file with mode: 0644]
Xserver/config/cf/hpLib.tmpl [new file with mode: 0644]
Xserver/config/cf/ibm.cf [new file with mode: 0644]
Xserver/config/cf/ibmLib.rules [new file with mode: 0644]
Xserver/config/cf/ibmLib.tmpl [new file with mode: 0644]
Xserver/config/cf/isc.cf [new file with mode: 0644]
Xserver/config/cf/linux.cf [new file with mode: 0644]
Xserver/config/cf/lnxLib.rules [new file with mode: 0644]
Xserver/config/cf/lnxLib.tmpl [new file with mode: 0644]
Xserver/config/cf/lnxdoc.rules [new file with mode: 0644]
Xserver/config/cf/lnxdoc.tmpl [new file with mode: 0644]
Xserver/config/cf/luna.cf [new file with mode: 0644]
Xserver/config/cf/lynx.cf [new file with mode: 0644]
Xserver/config/cf/macII.cf [new file with mode: 0644]
Xserver/config/cf/mach.cf [new file with mode: 0644]
Xserver/config/cf/minix.cf [new file with mode: 0644]
Xserver/config/cf/moto.cf [new file with mode: 0644]
Xserver/config/cf/ncr.cf [new file with mode: 0644]
Xserver/config/cf/nec.cf [new file with mode: 0644]
Xserver/config/cf/necLib.rules [new file with mode: 0644]
Xserver/config/cf/necLib.tmpl [new file with mode: 0644]
Xserver/config/cf/noop.rules [new file with mode: 0644]
Xserver/config/cf/oldlib.rules [new file with mode: 0644]
Xserver/config/cf/os2.cf [new file with mode: 0644]
Xserver/config/cf/os2.rules [new file with mode: 0644]
Xserver/config/cf/os2Lib.rules [new file with mode: 0644]
Xserver/config/cf/os2Lib.tmpl [new file with mode: 0644]
Xserver/config/cf/osf1.cf [new file with mode: 0644]
Xserver/config/cf/osfLib.rules [new file with mode: 0644]
Xserver/config/cf/osfLib.tmpl [new file with mode: 0644]
Xserver/config/cf/pegasus.cf [new file with mode: 0644]
Xserver/config/cf/sco.cf [new file with mode: 0644]
Xserver/config/cf/sco5.cf [new file with mode: 0644]
Xserver/config/cf/scoLib.rules [new file with mode: 0644]
Xserver/config/cf/sequent.cf [new file with mode: 0644]
Xserver/config/cf/sgi.cf [new file with mode: 0644]
Xserver/config/cf/sgiLib.rules [new file with mode: 0644]
Xserver/config/cf/sgiLib.tmpl [new file with mode: 0644]
Xserver/config/cf/site.def [new file with mode: 0644]
Xserver/config/cf/sony.cf [new file with mode: 0644]
Xserver/config/cf/sun.cf [new file with mode: 0644]
Xserver/config/cf/sunLib.rules [new file with mode: 0644]
Xserver/config/cf/sunLib.tmpl [new file with mode: 0644]
Xserver/config/cf/sv3Lib.rules [new file with mode: 0644]
Xserver/config/cf/sv3Lib.tmpl [new file with mode: 0644]
Xserver/config/cf/sv4Lib.rules [new file with mode: 0644]
Xserver/config/cf/sv4Lib.tmpl [new file with mode: 0644]
Xserver/config/cf/svr3.cf [new file with mode: 0644]
Xserver/config/cf/svr4.cf [new file with mode: 0644]
Xserver/config/cf/ultrix.cf [new file with mode: 0644]
Xserver/config/cf/usl.cf [new file with mode: 0644]
Xserver/config/cf/vnc.def [new file with mode: 0644]
Xserver/config/cf/vnclibs.def [new file with mode: 0644]
Xserver/config/cf/vnclibs.def.in [new file with mode: 0644]
Xserver/config/cf/x386.cf [new file with mode: 0644]
Xserver/config/cf/xf86.rules [new file with mode: 0644]
Xserver/config/cf/xf86.tmpl [new file with mode: 0644]
Xserver/config/cf/xf86site.def [new file with mode: 0644]
Xserver/config/cf/xfree86.cf [new file with mode: 0644]
Xserver/config/imake/Imakefile [new file with mode: 0644]
Xserver/config/imake/Makefile.ini [new file with mode: 0644]
Xserver/config/imake/ccimake.c [new file with mode: 0644]
Xserver/config/imake/imake.c [new file with mode: 0644]
Xserver/config/imake/imake.man [new file with mode: 0644]
Xserver/config/imake/imakemdep.h [new file with mode: 0644]
Xserver/config/imake/imakesvc.cmd [new file with mode: 0644]
Xserver/config/makedepend/Imakefile [new file with mode: 0644]
Xserver/config/makedepend/cpp.ed [new file with mode: 0644]
Xserver/config/makedepend/cppsetup.c [new file with mode: 0644]
Xserver/config/makedepend/def.h [new file with mode: 0644]
Xserver/config/makedepend/ifparser.c [new file with mode: 0644]
Xserver/config/makedepend/ifparser.h [new file with mode: 0644]
Xserver/config/makedepend/include.c [new file with mode: 0644]
Xserver/config/makedepend/main.c [new file with mode: 0644]
Xserver/config/makedepend/mkdepend.man [new file with mode: 0644]
Xserver/config/makedepend/parse.c [new file with mode: 0644]
Xserver/config/makedepend/pr.c [new file with mode: 0644]
Xserver/config/util/Imakefile [new file with mode: 0644]
Xserver/config/util/Makefile.ini [new file with mode: 0644]
Xserver/config/util/added.cmd [new file with mode: 0644]
Xserver/config/util/aminstall.sh [new file with mode: 0644]
Xserver/config/util/bsdinst.sh [new file with mode: 0755]
Xserver/config/util/buildos2.cmd [new file with mode: 0644]
Xserver/config/util/checktree.c [new file with mode: 0644]
Xserver/config/util/chownxterm.c [new file with mode: 0644]
Xserver/config/util/crayar.sh [new file with mode: 0755]
Xserver/config/util/elistgen.hp [new file with mode: 0644]
Xserver/config/util/elistgen.ibm [new file with mode: 0644]
Xserver/config/util/elistgen.sun [new file with mode: 0644]
Xserver/config/util/elistgen.usl [new file with mode: 0644]
Xserver/config/util/gccmdep.cpp [new file with mode: 0644]
Xserver/config/util/indir.cmd [new file with mode: 0644]
Xserver/config/util/install.sh [new file with mode: 0755]
Xserver/config/util/instos2.cmd [new file with mode: 0644]
Xserver/config/util/lndir.c [new file with mode: 0644]
Xserver/config/util/lndir.man [new file with mode: 0644]
Xserver/config/util/makeg.man [new file with mode: 0644]
Xserver/config/util/makeg.sh [new file with mode: 0755]
Xserver/config/util/makestrs.c [new file with mode: 0644]
Xserver/config/util/makestrs.man [new file with mode: 0644]
Xserver/config/util/mdepend.cpp [new file with mode: 0644]
Xserver/config/util/mergelib.cpp [new file with mode: 0755]
Xserver/config/util/mkdirhier.c [new file with mode: 0644]
Xserver/config/util/mkdirhier.cmd [new file with mode: 0644]
Xserver/config/util/mkdirhier.man [new file with mode: 0644]
Xserver/config/util/mkdirhier.sh [new file with mode: 0755]
Xserver/config/util/mkshadow/Imakefile [new file with mode: 0644]
Xserver/config/util/mkshadow/README [new file with mode: 0644]
Xserver/config/util/mkshadow/mkshadow.c [new file with mode: 0644]
Xserver/config/util/mkshadow/savedir.c [new file with mode: 0644]
Xserver/config/util/mkshadow/wildmat.c [new file with mode: 0644]
Xserver/config/util/os2inst.cmd [new file with mode: 0644]
Xserver/config/util/remove.cmd [new file with mode: 0644]
Xserver/config/util/syminst.sh [new file with mode: 0755]
Xserver/config/util/x11mf.sh [new file with mode: 0755]
Xserver/config/util/xmake.cmd [new file with mode: 0644]
Xserver/config/util/xmkmf.cmd [new file with mode: 0644]
Xserver/config/util/xmkmf.cpp [new file with mode: 0644]
Xserver/config/util/xmkmf.man [new file with mode: 0644]
Xserver/include/DECkeysym.h [new file with mode: 0644]
Xserver/include/HPkeysym.h [new file with mode: 0644]
Xserver/include/Imakefile [new file with mode: 0644]
Xserver/include/Sunkeysym.h [new file with mode: 0644]
Xserver/include/X.h [new file with mode: 0644]
Xserver/include/XWDFile.h [new file with mode: 0644]
Xserver/include/Xalloca.h [new file with mode: 0644]
Xserver/include/Xatom.h [new file with mode: 0644]
Xserver/include/Xfuncproto.h [new file with mode: 0644]
Xserver/include/Xfuncs.h [new file with mode: 0644]
Xserver/include/Xmd.h [new file with mode: 0644]
Xserver/include/Xos.h [new file with mode: 0644]
Xserver/include/Xos_r.h [new file with mode: 0644]
Xserver/include/Xosdefs.h [new file with mode: 0644]
Xserver/include/Xpoll.h [new file with mode: 0644]
Xserver/include/Xproto.h [new file with mode: 0644]
Xserver/include/Xprotostr.h [new file with mode: 0644]
Xserver/include/Xthreads.h [new file with mode: 0644]
Xserver/include/Xw32defs.h [new file with mode: 0644]
Xserver/include/Xwinsock.h [new file with mode: 0644]
Xserver/include/ap_keysym.h [new file with mode: 0644]
Xserver/include/bitmaps/1x1 [new file with mode: 0644]
Xserver/include/bitmaps/2x2 [new file with mode: 0644]
Xserver/include/bitmaps/Imakefile [new file with mode: 0644]
Xserver/include/bitmaps/black [new file with mode: 0644]
Xserver/include/bitmaps/boxes [new file with mode: 0644]
Xserver/include/bitmaps/calculator [new file with mode: 0644]
Xserver/include/bitmaps/cntr_ptr [new file with mode: 0644]
Xserver/include/bitmaps/cntr_ptrmsk [new file with mode: 0644]
Xserver/include/bitmaps/cross_weave [new file with mode: 0644]
Xserver/include/bitmaps/dimple1 [new file with mode: 0644]
Xserver/include/bitmaps/dimple3 [new file with mode: 0644]
Xserver/include/bitmaps/dot [new file with mode: 0644]
Xserver/include/bitmaps/dropbar7 [new file with mode: 0644]
Xserver/include/bitmaps/dropbar8 [new file with mode: 0644]
Xserver/include/bitmaps/escherknot [new file with mode: 0644]
Xserver/include/bitmaps/flagdown [new file with mode: 0644]
Xserver/include/bitmaps/flagup [new file with mode: 0644]
Xserver/include/bitmaps/flipped_gray [new file with mode: 0644]
Xserver/include/bitmaps/gray [new file with mode: 0644]
Xserver/include/bitmaps/gray1 [new file with mode: 0644]
Xserver/include/bitmaps/gray3 [new file with mode: 0644]
Xserver/include/bitmaps/grid16 [new file with mode: 0644]
Xserver/include/bitmaps/grid2 [new file with mode: 0644]
Xserver/include/bitmaps/grid4 [new file with mode: 0644]
Xserver/include/bitmaps/grid8 [new file with mode: 0644]
Xserver/include/bitmaps/hlines2 [new file with mode: 0644]
Xserver/include/bitmaps/hlines3 [new file with mode: 0644]
Xserver/include/bitmaps/icon [new file with mode: 0644]
Xserver/include/bitmaps/keyboard16 [new file with mode: 0644]
Xserver/include/bitmaps/left_ptr [new file with mode: 0644]
Xserver/include/bitmaps/left_ptrmsk [new file with mode: 0644]
Xserver/include/bitmaps/letters [new file with mode: 0644]
Xserver/include/bitmaps/light_gray [new file with mode: 0644]
Xserver/include/bitmaps/mailempty [new file with mode: 0644]
Xserver/include/bitmaps/mailemptymsk [new file with mode: 0644]
Xserver/include/bitmaps/mailfull [new file with mode: 0644]
Xserver/include/bitmaps/mailfullmsk [new file with mode: 0644]
Xserver/include/bitmaps/mensetmanus [new file with mode: 0644]
Xserver/include/bitmaps/menu10 [new file with mode: 0644]
Xserver/include/bitmaps/menu12 [new file with mode: 0644]
Xserver/include/bitmaps/menu16 [new file with mode: 0644]
Xserver/include/bitmaps/menu6 [new file with mode: 0644]
Xserver/include/bitmaps/menu8 [new file with mode: 0644]
Xserver/include/bitmaps/noletters [new file with mode: 0644]
Xserver/include/bitmaps/opendot [new file with mode: 0644]
Xserver/include/bitmaps/opendotMask [new file with mode: 0644]
Xserver/include/bitmaps/plaid [new file with mode: 0644]
Xserver/include/bitmaps/right_ptr [new file with mode: 0644]
Xserver/include/bitmaps/right_ptrmsk [new file with mode: 0644]
Xserver/include/bitmaps/root_weave [new file with mode: 0644]
Xserver/include/bitmaps/scales [new file with mode: 0644]
Xserver/include/bitmaps/sipb [new file with mode: 0644]
Xserver/include/bitmaps/star [new file with mode: 0644]
Xserver/include/bitmaps/starMask [new file with mode: 0644]
Xserver/include/bitmaps/stipple [new file with mode: 0644]
Xserver/include/bitmaps/target [new file with mode: 0644]
Xserver/include/bitmaps/terminal [new file with mode: 0644]
Xserver/include/bitmaps/tie_fighter [new file with mode: 0644]
Xserver/include/bitmaps/vlines2 [new file with mode: 0644]
Xserver/include/bitmaps/vlines3 [new file with mode: 0644]
Xserver/include/bitmaps/weird_size [new file with mode: 0644]
Xserver/include/bitmaps/wide_weave [new file with mode: 0644]
Xserver/include/bitmaps/wingdogs [new file with mode: 0644]
Xserver/include/bitmaps/woman [new file with mode: 0644]
Xserver/include/bitmaps/xfd_icon [new file with mode: 0644]
Xserver/include/bitmaps/xlogo11 [new file with mode: 0644]
Xserver/include/bitmaps/xlogo16 [new file with mode: 0644]
Xserver/include/bitmaps/xlogo32 [new file with mode: 0644]
Xserver/include/bitmaps/xlogo64 [new file with mode: 0644]
Xserver/include/bitmaps/xsnow [new file with mode: 0644]
Xserver/include/extensions/Imakefile [new file with mode: 0644]
Xserver/include/extensions/MITMisc.h [new file with mode: 0644]
Xserver/include/extensions/Print.h [new file with mode: 0644]
Xserver/include/extensions/Printstr.h [new file with mode: 0644]
Xserver/include/extensions/XI.h [new file with mode: 0644]
Xserver/include/extensions/XIE.h [new file with mode: 0644]
Xserver/include/extensions/XIEproto.h [new file with mode: 0644]
Xserver/include/extensions/XIEprotost.h [new file with mode: 0644]
Xserver/include/extensions/XInput.h [new file with mode: 0644]
Xserver/include/extensions/XIproto.h [new file with mode: 0644]
Xserver/include/extensions/XKB.h [new file with mode: 0644]
Xserver/include/extensions/XKBgeom.h [new file with mode: 0644]
Xserver/include/extensions/XKBproto.h [new file with mode: 0644]
Xserver/include/extensions/XKBsrv.h [new file with mode: 0644]
Xserver/include/extensions/XKBstr.h [new file with mode: 0644]
Xserver/include/extensions/XLbx.h [new file with mode: 0644]
Xserver/include/extensions/XShm.h [new file with mode: 0644]
Xserver/include/extensions/XTest.h [new file with mode: 0644]
Xserver/include/extensions/Xag.h [new file with mode: 0644]
Xserver/include/extensions/Xagsrv.h [new file with mode: 0644]
Xserver/include/extensions/Xagstr.h [new file with mode: 0644]
Xserver/include/extensions/Xdbe.h [new file with mode: 0644]
Xserver/include/extensions/Xdbeproto.h [new file with mode: 0644]
Xserver/include/extensions/Xext.h [new file with mode: 0644]
Xserver/include/extensions/bigreqstr.h [new file with mode: 0644]
Xserver/include/extensions/dpms.h [new file with mode: 0644]
Xserver/include/extensions/dpmsstr.h [new file with mode: 0644]
Xserver/include/extensions/extutil.h [new file with mode: 0644]
Xserver/include/extensions/lbxbuf.h [new file with mode: 0644]
Xserver/include/extensions/lbxbufstr.h [new file with mode: 0644]
Xserver/include/extensions/lbxdeltastr.h [new file with mode: 0644]
Xserver/include/extensions/lbximage.h [new file with mode: 0644]
Xserver/include/extensions/lbxopts.h [new file with mode: 0644]
Xserver/include/extensions/lbxstr.h [new file with mode: 0644]
Xserver/include/extensions/lbxzlib.h [new file with mode: 0644]
Xserver/include/extensions/mitmiscstr.h [new file with mode: 0644]
Xserver/include/extensions/multibuf.h [new file with mode: 0644]
Xserver/include/extensions/multibufst.h [new file with mode: 0644]
Xserver/include/extensions/record.h [new file with mode: 0644]
Xserver/include/extensions/recordstr.h [new file with mode: 0644]
Xserver/include/extensions/saver.h [new file with mode: 0644]
Xserver/include/extensions/saverproto.h [new file with mode: 0644]
Xserver/include/extensions/scrnsaver.h [new file with mode: 0644]
Xserver/include/extensions/security.h [new file with mode: 0644]
Xserver/include/extensions/securstr.h [new file with mode: 0644]
Xserver/include/extensions/shape.h [new file with mode: 0644]
Xserver/include/extensions/shapestr.h [new file with mode: 0644]
Xserver/include/extensions/shmstr.h [new file with mode: 0644]
Xserver/include/extensions/sync.h [new file with mode: 0644]
Xserver/include/extensions/syncstr.h [new file with mode: 0644]
Xserver/include/extensions/xcmiscstr.h [new file with mode: 0644]
Xserver/include/extensions/xf86dga.h [new file with mode: 0644]
Xserver/include/extensions/xf86dgastr.h [new file with mode: 0644]
Xserver/include/extensions/xf86misc.h [new file with mode: 0644]
Xserver/include/extensions/xf86mscstr.h [new file with mode: 0644]
Xserver/include/extensions/xf86vmode.h [new file with mode: 0644]
Xserver/include/extensions/xf86vmstr.h [new file with mode: 0644]
Xserver/include/extensions/xtestext1.h [new file with mode: 0644]
Xserver/include/extensions/xteststr.h [new file with mode: 0644]
Xserver/include/fonts/FS.h [new file with mode: 0644]
Xserver/include/fonts/FSproto.h [new file with mode: 0644]
Xserver/include/fonts/Imakefile [new file with mode: 0644]
Xserver/include/fonts/font.h [new file with mode: 0644]
Xserver/include/fonts/fontstruct.h [new file with mode: 0644]
Xserver/include/fonts/fsmasks.h [new file with mode: 0644]
Xserver/include/keysym.h [new file with mode: 0644]
Xserver/include/keysymdef.h [new file with mode: 0644]
Xserver/lib/Imakefile [new file with mode: 0644]
Xserver/lib/X11/Imakefile [new file with mode: 0644]
Xserver/lib/X11/XKBlib.h [new file with mode: 0644]
Xserver/lib/X11/Xcms.h [new file with mode: 0644]
Xserver/lib/X11/Xlib.h [new file with mode: 0644]
Xserver/lib/X11/Xlibint.h [new file with mode: 0644]
Xserver/lib/X11/Xlocale.h [new file with mode: 0644]
Xserver/lib/X11/Xresource.h [new file with mode: 0644]
Xserver/lib/X11/Xutil.h [new file with mode: 0644]
Xserver/lib/X11/cursorfont.h [new file with mode: 0644]
Xserver/lib/Xau/AuDispose.c [new file with mode: 0644]
Xserver/lib/Xau/AuFileName.c [new file with mode: 0644]
Xserver/lib/Xau/AuGetAddr.c [new file with mode: 0644]
Xserver/lib/Xau/AuGetBest.c [new file with mode: 0644]
Xserver/lib/Xau/AuLock.c [new file with mode: 0644]
Xserver/lib/Xau/AuRead.c [new file with mode: 0644]
Xserver/lib/Xau/AuUnlock.c [new file with mode: 0644]
Xserver/lib/Xau/AuWrite.c [new file with mode: 0644]
Xserver/lib/Xau/Autest.c [new file with mode: 0644]
Xserver/lib/Xau/Imakefile [new file with mode: 0644]
Xserver/lib/Xau/README [new file with mode: 0644]
Xserver/lib/Xau/Xauth.h [new file with mode: 0644]
Xserver/lib/Xau/k5encode.c [new file with mode: 0644]
Xserver/lib/Xdmcp/A8Eq.c [new file with mode: 0644]
Xserver/lib/Xdmcp/AA16.c [new file with mode: 0644]
Xserver/lib/Xdmcp/AA32.c [new file with mode: 0644]
Xserver/lib/Xdmcp/AA8.c [new file with mode: 0644]
Xserver/lib/Xdmcp/Alloc.c [new file with mode: 0644]
Xserver/lib/Xdmcp/AofA8.c [new file with mode: 0644]
Xserver/lib/Xdmcp/CA8.c [new file with mode: 0644]
Xserver/lib/Xdmcp/CmpKey.c [new file with mode: 0644]
Xserver/lib/Xdmcp/DA16.c [new file with mode: 0644]
Xserver/lib/Xdmcp/DA32.c [new file with mode: 0644]
Xserver/lib/Xdmcp/DA8.c [new file with mode: 0644]
Xserver/lib/Xdmcp/DAofA8.c [new file with mode: 0644]
Xserver/lib/Xdmcp/DecKey.c [new file with mode: 0644]
Xserver/lib/Xdmcp/Fill.c [new file with mode: 0644]
Xserver/lib/Xdmcp/Flush.c [new file with mode: 0644]
Xserver/lib/Xdmcp/GenKey.c [new file with mode: 0644]
Xserver/lib/Xdmcp/Imakefile [new file with mode: 0644]
Xserver/lib/Xdmcp/IncKey.c [new file with mode: 0644]
Xserver/lib/Xdmcp/RA16.c [new file with mode: 0644]
Xserver/lib/Xdmcp/RA32.c [new file with mode: 0644]
Xserver/lib/Xdmcp/RA8.c [new file with mode: 0644]
Xserver/lib/Xdmcp/RAofA8.c [new file with mode: 0644]
Xserver/lib/Xdmcp/RC16.c [new file with mode: 0644]
Xserver/lib/Xdmcp/RC32.c [new file with mode: 0644]
Xserver/lib/Xdmcp/RC8.c [new file with mode: 0644]
Xserver/lib/Xdmcp/RHead.c [new file with mode: 0644]
Xserver/lib/Xdmcp/RR.c [new file with mode: 0644]
Xserver/lib/Xdmcp/RaA16.c [new file with mode: 0644]
Xserver/lib/Xdmcp/RaA32.c [new file with mode: 0644]
Xserver/lib/Xdmcp/RaA8.c [new file with mode: 0644]
Xserver/lib/Xdmcp/RaAoA8.c [new file with mode: 0644]
Xserver/lib/Xdmcp/Unwrap.c [new file with mode: 0644]
Xserver/lib/Xdmcp/WA16.c [new file with mode: 0644]
Xserver/lib/Xdmcp/WA32.c [new file with mode: 0644]
Xserver/lib/Xdmcp/WA8.c [new file with mode: 0644]
Xserver/lib/Xdmcp/WAofA8.c [new file with mode: 0644]
Xserver/lib/Xdmcp/WC16.c [new file with mode: 0644]
Xserver/lib/Xdmcp/WC32.c [new file with mode: 0644]
Xserver/lib/Xdmcp/WC8.c [new file with mode: 0644]
Xserver/lib/Xdmcp/Whead.c [new file with mode: 0644]
Xserver/lib/Xdmcp/Wrap.c [new file with mode: 0644]
Xserver/lib/Xdmcp/Wrap.h [new file with mode: 0644]
Xserver/lib/Xdmcp/Wraphelp.c [new file with mode: 0644]
Xserver/lib/Xdmcp/Xdmcp.h [new file with mode: 0644]
Xserver/lib/font/Imakefile [new file with mode: 0644]
Xserver/lib/font/Speedo/Imakefile [new file with mode: 0644]
Xserver/lib/font/Speedo/adobe-iso.h [new file with mode: 0644]
Xserver/lib/font/Speedo/bics-iso.h [new file with mode: 0644]
Xserver/lib/font/Speedo/do_char.c [new file with mode: 0644]
Xserver/lib/font/Speedo/do_trns.c [new file with mode: 0644]
Xserver/lib/font/Speedo/htest.c [new file with mode: 0644]
Xserver/lib/font/Speedo/iface.c [new file with mode: 0644]
Xserver/lib/font/Speedo/keys.h [new file with mode: 0644]
Xserver/lib/font/Speedo/nsample.c [new file with mode: 0644]
Xserver/lib/font/Speedo/out_bl2d.c [new file with mode: 0644]
Xserver/lib/font/Speedo/out_blk.c [new file with mode: 0644]
Xserver/lib/font/Speedo/out_outl.c [new file with mode: 0644]
Xserver/lib/font/Speedo/out_scrn.c [new file with mode: 0644]
Xserver/lib/font/Speedo/out_util.c [new file with mode: 0644]
Xserver/lib/font/Speedo/reset.c [new file with mode: 0644]
Xserver/lib/font/Speedo/set_spcs.c [new file with mode: 0644]
Xserver/lib/font/Speedo/set_trns.c [new file with mode: 0644]
Xserver/lib/font/Speedo/spdo_prv.h [new file with mode: 0644]
Xserver/lib/font/Speedo/speedo.h [new file with mode: 0644]
Xserver/lib/font/Speedo/spencode.c [new file with mode: 0644]
Xserver/lib/font/Speedo/sperr.c [new file with mode: 0644]
Xserver/lib/font/Speedo/spfile.c [new file with mode: 0644]
Xserver/lib/font/Speedo/spfont.c [new file with mode: 0644]
Xserver/lib/font/Speedo/spfuncs.c [new file with mode: 0644]
Xserver/lib/font/Speedo/spglyph.c [new file with mode: 0644]
Xserver/lib/font/Speedo/spinfo.c [new file with mode: 0644]
Xserver/lib/font/Speedo/spint.h [new file with mode: 0644]
Xserver/lib/font/Speedo/sptobdf.c [new file with mode: 0644]
Xserver/lib/font/Speedo/useropt.h [new file with mode: 0644]
Xserver/lib/font/Type1/Imakefile [new file with mode: 0644]
Xserver/lib/font/Type1/arith.c [new file with mode: 0644]
Xserver/lib/font/Type1/arith.h [new file with mode: 0644]
Xserver/lib/font/Type1/blues.h [new file with mode: 0644]
Xserver/lib/font/Type1/cluts.h [new file with mode: 0644]
Xserver/lib/font/Type1/curves.c [new file with mode: 0644]
Xserver/lib/font/Type1/curves.h [new file with mode: 0644]
Xserver/lib/font/Type1/digit.h [new file with mode: 0644]
Xserver/lib/font/Type1/fontfcn.c [new file with mode: 0644]
Xserver/lib/font/Type1/fontfcn.h [new file with mode: 0644]
Xserver/lib/font/Type1/fonts.h [new file with mode: 0644]
Xserver/lib/font/Type1/hdigit.h [new file with mode: 0644]
Xserver/lib/font/Type1/hints.c [new file with mode: 0644]
Xserver/lib/font/Type1/hints.h [new file with mode: 0644]
Xserver/lib/font/Type1/lines.c [new file with mode: 0644]
Xserver/lib/font/Type1/lines.h [new file with mode: 0644]
Xserver/lib/font/Type1/minimain.c [new file with mode: 0644]
Xserver/lib/font/Type1/objects.c [new file with mode: 0644]
Xserver/lib/font/Type1/objects.h [new file with mode: 0644]
Xserver/lib/font/Type1/paths.c [new file with mode: 0644]
Xserver/lib/font/Type1/paths.h [new file with mode: 0644]
Xserver/lib/font/Type1/pictures.h [new file with mode: 0644]
Xserver/lib/font/Type1/regions.c [new file with mode: 0644]
Xserver/lib/font/Type1/regions.h [new file with mode: 0644]
Xserver/lib/font/Type1/scanfont.c [new file with mode: 0644]
Xserver/lib/font/Type1/spaces.c [new file with mode: 0644]
Xserver/lib/font/Type1/spaces.h [new file with mode: 0644]
Xserver/lib/font/Type1/strokes.h [new file with mode: 0644]
Xserver/lib/font/Type1/t1funcs.c [new file with mode: 0644]
Xserver/lib/font/Type1/t1hdigit.h [new file with mode: 0644]
Xserver/lib/font/Type1/t1imager.h [new file with mode: 0644]
Xserver/lib/font/Type1/t1info.c [new file with mode: 0644]
Xserver/lib/font/Type1/t1intf.h [new file with mode: 0644]
Xserver/lib/font/Type1/t1io.c [new file with mode: 0644]
Xserver/lib/font/Type1/t1malloc.c [new file with mode: 0644]
Xserver/lib/font/Type1/t1snap.c [new file with mode: 0644]
Xserver/lib/font/Type1/t1stdio.h [new file with mode: 0644]
Xserver/lib/font/Type1/t1stub.c [new file with mode: 0644]
Xserver/lib/font/Type1/t1test.c [new file with mode: 0644]
Xserver/lib/font/Type1/token.c [new file with mode: 0644]
Xserver/lib/font/Type1/token.h [new file with mode: 0644]
Xserver/lib/font/Type1/tokst.h [new file with mode: 0644]
Xserver/lib/font/Type1/trig.h [new file with mode: 0644]
Xserver/lib/font/Type1/type1.c [new file with mode: 0644]
Xserver/lib/font/Type1/util.c [new file with mode: 0644]
Xserver/lib/font/Type1/util.h [new file with mode: 0644]
Xserver/lib/font/bitmap/Imakefile [new file with mode: 0644]
Xserver/lib/font/bitmap/bdfint.h [new file with mode: 0644]
Xserver/lib/font/bitmap/bdfread.c [new file with mode: 0644]
Xserver/lib/font/bitmap/bdfutils.c [new file with mode: 0644]
Xserver/lib/font/bitmap/bitmap.c [new file with mode: 0644]
Xserver/lib/font/bitmap/bitmapfunc.c [new file with mode: 0644]
Xserver/lib/font/bitmap/bitmaputil.c [new file with mode: 0644]
Xserver/lib/font/bitmap/bitscale.c [new file with mode: 0644]
Xserver/lib/font/bitmap/fontink.c [new file with mode: 0644]
Xserver/lib/font/bitmap/pcf.h [new file with mode: 0644]
Xserver/lib/font/bitmap/pcfread.c [new file with mode: 0644]
Xserver/lib/font/bitmap/pcfwrite.c [new file with mode: 0644]
Xserver/lib/font/bitmap/snfread.c [new file with mode: 0644]
Xserver/lib/font/bitmap/snfstr.h [new file with mode: 0644]
Xserver/lib/font/fc/Imakefile [new file with mode: 0644]
Xserver/lib/font/fc/fsconvert.c [new file with mode: 0644]
Xserver/lib/font/fc/fserve.c [new file with mode: 0644]
Xserver/lib/font/fc/fserve.h [new file with mode: 0644]
Xserver/lib/font/fc/fservestr.h [new file with mode: 0644]
Xserver/lib/font/fc/fsio.c [new file with mode: 0644]
Xserver/lib/font/fc/fsio.h [new file with mode: 0644]
Xserver/lib/font/fc/fslibos.h [new file with mode: 0644]
Xserver/lib/font/fontfile/Imakefile [new file with mode: 0644]
Xserver/lib/font/fontfile/bitsource.c [new file with mode: 0644]
Xserver/lib/font/fontfile/bufio.c [new file with mode: 0644]
Xserver/lib/font/fontfile/decompress.c [new file with mode: 0644]
Xserver/lib/font/fontfile/defaults.c [new file with mode: 0644]
Xserver/lib/font/fontfile/dirfile.c [new file with mode: 0644]
Xserver/lib/font/fontfile/ffcheck.c [new file with mode: 0644]
Xserver/lib/font/fontfile/fileio.c [new file with mode: 0644]
Xserver/lib/font/fontfile/filewr.c [new file with mode: 0644]
Xserver/lib/font/fontfile/fontdir.c [new file with mode: 0644]
Xserver/lib/font/fontfile/fontfile.c [new file with mode: 0644]
Xserver/lib/font/fontfile/fontscale.c [new file with mode: 0644]
Xserver/lib/font/fontfile/gunzip.c [new file with mode: 0644]
Xserver/lib/font/fontfile/printerfont.c [new file with mode: 0644]
Xserver/lib/font/fontfile/register.c [new file with mode: 0644]
Xserver/lib/font/fontfile/renderers.c [new file with mode: 0644]
Xserver/lib/font/include/bitmap.h [new file with mode: 0644]
Xserver/lib/font/include/bufio.h [new file with mode: 0644]
Xserver/lib/font/include/fntfil.h [new file with mode: 0644]
Xserver/lib/font/include/fntfilio.h [new file with mode: 0644]
Xserver/lib/font/include/fntfilst.h [new file with mode: 0644]
Xserver/lib/font/include/fontmisc.h [new file with mode: 0644]
Xserver/lib/font/include/fontshow.h [new file with mode: 0644]
Xserver/lib/font/include/fontxlfd.h [new file with mode: 0644]
Xserver/lib/font/util/Imakefile [new file with mode: 0644]
Xserver/lib/font/util/atom.c [new file with mode: 0644]
Xserver/lib/font/util/fontaccel.c [new file with mode: 0644]
Xserver/lib/font/util/fontnames.c [new file with mode: 0644]
Xserver/lib/font/util/fontutil.c [new file with mode: 0644]
Xserver/lib/font/util/fontxlfd.c [new file with mode: 0644]
Xserver/lib/font/util/format.c [new file with mode: 0644]
Xserver/lib/font/util/miscutil.c [new file with mode: 0644]
Xserver/lib/font/util/patcache.c [new file with mode: 0644]
Xserver/lib/font/util/private.c [new file with mode: 0644]
Xserver/lib/font/util/utilbitmap.c [new file with mode: 0644]
Xserver/lib/xtrans/Imakefile [new file with mode: 0644]
Xserver/lib/xtrans/Xtrans.c [new file with mode: 0644]
Xserver/lib/xtrans/Xtrans.h [new file with mode: 0644]
Xserver/lib/xtrans/Xtransam.c [new file with mode: 0644]
Xserver/lib/xtrans/Xtransdnet.c [new file with mode: 0644]
Xserver/lib/xtrans/Xtransint.h [new file with mode: 0644]
Xserver/lib/xtrans/Xtranslcl.c [new file with mode: 0644]
Xserver/lib/xtrans/Xtransmnx.c [new file with mode: 0644]
Xserver/lib/xtrans/Xtransos2.c [new file with mode: 0644]
Xserver/lib/xtrans/Xtranssock.c [new file with mode: 0644]
Xserver/lib/xtrans/Xtranstli.c [new file with mode: 0644]
Xserver/lib/xtrans/Xtransutil.c [new file with mode: 0644]
Xserver/lib/xtrans/transport.c [new file with mode: 0644]
Xserver/programs/Imakefile [new file with mode: 0644]
Xserver/programs/Xserver/Imakefile [new file with mode: 0644]
Xserver/programs/Xserver/Xext/Imakefile [new file with mode: 0644]
Xserver/programs/Xserver/Xext/SecurityPolicy [new file with mode: 0644]
Xserver/programs/Xserver/Xext/appgroup.c [new file with mode: 0644]
Xserver/programs/Xserver/Xext/bigreq.c [new file with mode: 0644]
Xserver/programs/Xserver/Xext/dpms.c [new file with mode: 0644]
Xserver/programs/Xserver/Xext/mbuf.c [new file with mode: 0644]
Xserver/programs/Xserver/Xext/mbufbf.c [new file with mode: 0644]
Xserver/programs/Xserver/Xext/mbufpx.c [new file with mode: 0644]
Xserver/programs/Xserver/Xext/mitmisc.c [new file with mode: 0644]
Xserver/programs/Xserver/Xext/saver.c [new file with mode: 0644]
Xserver/programs/Xserver/Xext/security.c [new file with mode: 0644]
Xserver/programs/Xserver/Xext/shape.c [new file with mode: 0644]
Xserver/programs/Xserver/Xext/shm.c [new file with mode: 0644]
Xserver/programs/Xserver/Xext/sleepuntil.c [new file with mode: 0644]
Xserver/programs/Xserver/Xext/sync.c [new file with mode: 0644]
Xserver/programs/Xserver/Xext/xcmisc.c [new file with mode: 0644]
Xserver/programs/Xserver/Xext/xf86dga.c [new file with mode: 0644]
Xserver/programs/Xserver/Xext/xf86misc.c [new file with mode: 0644]
Xserver/programs/Xserver/Xext/xf86vmode.c [new file with mode: 0644]
Xserver/programs/Xserver/Xext/xprint.c [new file with mode: 0644]
Xserver/programs/Xserver/Xext/xtest.c [new file with mode: 0644]
Xserver/programs/Xserver/Xext/xtest1.frags [new file with mode: 0644]
Xserver/programs/Xserver/Xext/xtest1dd.c [new file with mode: 0644]
Xserver/programs/Xserver/Xext/xtest1dd.h [new file with mode: 0644]
Xserver/programs/Xserver/Xext/xtest1di.c [new file with mode: 0644]
Xserver/programs/Xserver/Xprint/DiPrint.h [new file with mode: 0644]
Xserver/programs/Xserver/Xserver.man [new file with mode: 0644]
Xserver/programs/Xserver/Xvnc.man [new file with mode: 0644]
Xserver/programs/Xserver/cfb/Imakefile [new file with mode: 0644]
Xserver/programs/Xserver/cfb/cfb.h [new file with mode: 0644]
Xserver/programs/Xserver/cfb/cfb8bit.c [new file with mode: 0644]
Xserver/programs/Xserver/cfb/cfb8bit.h [new file with mode: 0644]
Xserver/programs/Xserver/cfb/cfb8cppl.c [new file with mode: 0644]
Xserver/programs/Xserver/cfb/cfb8line.c [new file with mode: 0644]
Xserver/programs/Xserver/cfb/cfballpriv.c [new file with mode: 0644]
Xserver/programs/Xserver/cfb/cfbbitblt.c [new file with mode: 0644]
Xserver/programs/Xserver/cfb/cfbblt.c [new file with mode: 0644]
Xserver/programs/Xserver/cfb/cfbbres.c [new file with mode: 0644]
Xserver/programs/Xserver/cfb/cfbbresd.c [new file with mode: 0644]
Xserver/programs/Xserver/cfb/cfbbstore.c [new file with mode: 0644]
Xserver/programs/Xserver/cfb/cfbcmap.c [new file with mode: 0644]
Xserver/programs/Xserver/cfb/cfbfillarc.c [new file with mode: 0644]
Xserver/programs/Xserver/cfb/cfbfillrct.c [new file with mode: 0644]
Xserver/programs/Xserver/cfb/cfbfillsp.c [new file with mode: 0644]
Xserver/programs/Xserver/cfb/cfbgc.c [new file with mode: 0644]
Xserver/programs/Xserver/cfb/cfbgetsp.c [new file with mode: 0644]
Xserver/programs/Xserver/cfb/cfbglblt8.c [new file with mode: 0644]
Xserver/programs/Xserver/cfb/cfbhrzvert.c [new file with mode: 0644]
Xserver/programs/Xserver/cfb/cfbigblt8.c [new file with mode: 0644]
Xserver/programs/Xserver/cfb/cfbimage.c [new file with mode: 0644]
Xserver/programs/Xserver/cfb/cfbline.c [new file with mode: 0644]
Xserver/programs/Xserver/cfb/cfbmap.h [new file with mode: 0644]
Xserver/programs/Xserver/cfb/cfbmskbits.c [new file with mode: 0644]
Xserver/programs/Xserver/cfb/cfbmskbits.h [new file with mode: 0644]
Xserver/programs/Xserver/cfb/cfbpixmap.c [new file with mode: 0644]
Xserver/programs/Xserver/cfb/cfbply1rct.c [new file with mode: 0644]
Xserver/programs/Xserver/cfb/cfbpntwin.c [new file with mode: 0644]
Xserver/programs/Xserver/cfb/cfbpolypnt.c [new file with mode: 0644]
Xserver/programs/Xserver/cfb/cfbpush8.c [new file with mode: 0644]
Xserver/programs/Xserver/cfb/cfbrctstp8.c [new file with mode: 0644]
Xserver/programs/Xserver/cfb/cfbrrop.c [new file with mode: 0644]
Xserver/programs/Xserver/cfb/cfbrrop.h [new file with mode: 0644]
Xserver/programs/Xserver/cfb/cfbscrinit.c [new file with mode: 0644]
Xserver/programs/Xserver/cfb/cfbsetsp.c [new file with mode: 0644]
Xserver/programs/Xserver/cfb/cfbsolid.c [new file with mode: 0644]
Xserver/programs/Xserver/cfb/cfbteblt8.c [new file with mode: 0644]
Xserver/programs/Xserver/cfb/cfbtegblt.c [new file with mode: 0644]
Xserver/programs/Xserver/cfb/cfbtile32.c [new file with mode: 0644]
Xserver/programs/Xserver/cfb/cfbtileodd.c [new file with mode: 0644]
Xserver/programs/Xserver/cfb/cfbwindow.c [new file with mode: 0644]
Xserver/programs/Xserver/cfb/cfbzerarc.c [new file with mode: 0644]
Xserver/programs/Xserver/cfb/stip68kgnu.h [new file with mode: 0644]
Xserver/programs/Xserver/cfb/stipmips.s [new file with mode: 0644]
Xserver/programs/Xserver/cfb/stipple68k.s [new file with mode: 0644]
Xserver/programs/Xserver/cfb/stipsparc.s [new file with mode: 0644]
Xserver/programs/Xserver/cfb/stipsprc32.s [new file with mode: 0644]
Xserver/programs/Xserver/cfb16/Imakefile [new file with mode: 0644]
Xserver/programs/Xserver/cfb24/Imakefile [new file with mode: 0644]
Xserver/programs/Xserver/cfb24/cfbrrop24.h [new file with mode: 0644]
Xserver/programs/Xserver/cfb32/Imakefile [new file with mode: 0644]
Xserver/programs/Xserver/dix/BuiltInAtoms [new file with mode: 0644]
Xserver/programs/Xserver/dix/CHANGES [new file with mode: 0644]
Xserver/programs/Xserver/dix/Imakefile [new file with mode: 0644]
Xserver/programs/Xserver/dix/atom.c [new file with mode: 0644]
Xserver/programs/Xserver/dix/buildatoms [new file with mode: 0755]
Xserver/programs/Xserver/dix/colormap.c [new file with mode: 0644]
Xserver/programs/Xserver/dix/cursor.c [new file with mode: 0644]
Xserver/programs/Xserver/dix/devices.c [new file with mode: 0644]
Xserver/programs/Xserver/dix/dispatch.c [new file with mode: 0644]
Xserver/programs/Xserver/dix/dispatch.h [new file with mode: 0644]
Xserver/programs/Xserver/dix/dixfonts.c [new file with mode: 0644]
Xserver/programs/Xserver/dix/dixutils.c [new file with mode: 0644]
Xserver/programs/Xserver/dix/events.c [new file with mode: 0644]
Xserver/programs/Xserver/dix/extension.c [new file with mode: 0644]
Xserver/programs/Xserver/dix/ffs.c [new file with mode: 0644]
Xserver/programs/Xserver/dix/gc.c [new file with mode: 0644]
Xserver/programs/Xserver/dix/globals.c [new file with mode: 0644]
Xserver/programs/Xserver/dix/glyphcurs.c [new file with mode: 0644]
Xserver/programs/Xserver/dix/grabs.c [new file with mode: 0644]
Xserver/programs/Xserver/dix/initatoms.c [new file with mode: 0644]
Xserver/programs/Xserver/dix/main.c [new file with mode: 0644]
Xserver/programs/Xserver/dix/pixmap.c [new file with mode: 0644]
Xserver/programs/Xserver/dix/privates.c [new file with mode: 0644]
Xserver/programs/Xserver/dix/property.c [new file with mode: 0644]
Xserver/programs/Xserver/dix/resource.c [new file with mode: 0644]
Xserver/programs/Xserver/dix/swaprep.c [new file with mode: 0644]
Xserver/programs/Xserver/dix/swapreq.c [new file with mode: 0644]
Xserver/programs/Xserver/dix/swapreq.h [new file with mode: 0644]
Xserver/programs/Xserver/dix/tables.c [new file with mode: 0644]
Xserver/programs/Xserver/dix/window.c [new file with mode: 0644]
Xserver/programs/Xserver/dix/xpstubs.c [new file with mode: 0644]
Xserver/programs/Xserver/hw/vnc/Imakefile [new file with mode: 0644]
Xserver/programs/Xserver/hw/vnc/README [new file with mode: 0644]
Xserver/programs/Xserver/hw/vnc/auth.c [new file with mode: 0644]
Xserver/programs/Xserver/hw/vnc/buildtime.c [new file with mode: 0644]
Xserver/programs/Xserver/hw/vnc/cmap.c [new file with mode: 0644]
Xserver/programs/Xserver/hw/vnc/corre.c [new file with mode: 0644]
Xserver/programs/Xserver/hw/vnc/cutpaste.c [new file with mode: 0644]
Xserver/programs/Xserver/hw/vnc/dispcur.c [new file with mode: 0644]
Xserver/programs/Xserver/hw/vnc/dispcur.h [new file with mode: 0644]
Xserver/programs/Xserver/hw/vnc/draw.c [new file with mode: 0644]
Xserver/programs/Xserver/hw/vnc/hextile.c [new file with mode: 0644]
Xserver/programs/Xserver/hw/vnc/httpd.c [new file with mode: 0644]
Xserver/programs/Xserver/hw/vnc/init.c [new file with mode: 0644]
Xserver/programs/Xserver/hw/vnc/kbdptr.c [new file with mode: 0644]
Xserver/programs/Xserver/hw/vnc/rfb.h [new file with mode: 0644]
Xserver/programs/Xserver/hw/vnc/rfbserver.c [new file with mode: 0644]
Xserver/programs/Xserver/hw/vnc/rre.c [new file with mode: 0644]
Xserver/programs/Xserver/hw/vnc/sockets.c [new file with mode: 0644]
Xserver/programs/Xserver/hw/vnc/sprite.c [new file with mode: 0644]
Xserver/programs/Xserver/hw/vnc/sprite.h [new file with mode: 0644]
Xserver/programs/Xserver/hw/vnc/spritest.h [new file with mode: 0644]
Xserver/programs/Xserver/hw/vnc/stats.c [new file with mode: 0644]
Xserver/programs/Xserver/hw/vnc/tableinitcmtemplate.c [new file with mode: 0644]
Xserver/programs/Xserver/hw/vnc/tableinittctemplate.c [new file with mode: 0644]
Xserver/programs/Xserver/hw/vnc/tabletranstemplate.c [new file with mode: 0644]
Xserver/programs/Xserver/hw/vnc/translate.c [new file with mode: 0644]
Xserver/programs/Xserver/hw/vnc/zrle.cc [new file with mode: 0644]
Xserver/programs/Xserver/hw/xfree86/common/compiler.h [new file with mode: 0644]
Xserver/programs/Xserver/hw/xfree86/common/scoasm.h [new file with mode: 0644]
Xserver/programs/Xserver/include/Imakefile [new file with mode: 0644]
Xserver/programs/Xserver/include/XIstubs.h [new file with mode: 0644]
Xserver/programs/Xserver/include/closestr.h [new file with mode: 0644]
Xserver/programs/Xserver/include/closure.h [new file with mode: 0644]
Xserver/programs/Xserver/include/colormap.h [new file with mode: 0644]
Xserver/programs/Xserver/include/colormapst.h [new file with mode: 0644]
Xserver/programs/Xserver/include/cursor.h [new file with mode: 0644]
Xserver/programs/Xserver/include/cursorstr.h [new file with mode: 0644]
Xserver/programs/Xserver/include/dix.h [new file with mode: 0644]
Xserver/programs/Xserver/include/dixevents.h [new file with mode: 0644]
Xserver/programs/Xserver/include/dixfont.h [new file with mode: 0644]
Xserver/programs/Xserver/include/dixfontstr.h [new file with mode: 0644]
Xserver/programs/Xserver/include/dixgrabs.h [new file with mode: 0644]
Xserver/programs/Xserver/include/dixstruct.h [new file with mode: 0644]
Xserver/programs/Xserver/include/exevents.h [new file with mode: 0644]
Xserver/programs/Xserver/include/extension.h [new file with mode: 0644]
Xserver/programs/Xserver/include/extinit.h [new file with mode: 0644]
Xserver/programs/Xserver/include/extnsionst.h [new file with mode: 0644]
Xserver/programs/Xserver/include/gc.h [new file with mode: 0644]
Xserver/programs/Xserver/include/gcstruct.h [new file with mode: 0644]
Xserver/programs/Xserver/include/input.h [new file with mode: 0644]
Xserver/programs/Xserver/include/inputstr.h [new file with mode: 0644]
Xserver/programs/Xserver/include/misc.h [new file with mode: 0644]
Xserver/programs/Xserver/include/miscstruct.h [new file with mode: 0644]
Xserver/programs/Xserver/include/opaque.h [new file with mode: 0644]
Xserver/programs/Xserver/include/os.h [new file with mode: 0644]
Xserver/programs/Xserver/include/pixmap.h [new file with mode: 0644]
Xserver/programs/Xserver/include/pixmapstr.h [new file with mode: 0644]
Xserver/programs/Xserver/include/property.h [new file with mode: 0644]
Xserver/programs/Xserver/include/propertyst.h [new file with mode: 0644]
Xserver/programs/Xserver/include/region.h [new file with mode: 0644]
Xserver/programs/Xserver/include/regionstr.h [new file with mode: 0644]
Xserver/programs/Xserver/include/resource.h [new file with mode: 0644]
Xserver/programs/Xserver/include/rgb.h [new file with mode: 0644]
Xserver/programs/Xserver/include/screenint.h [new file with mode: 0644]
Xserver/programs/Xserver/include/scrnintstr.h [new file with mode: 0644]
Xserver/programs/Xserver/include/selection.h [new file with mode: 0644]
Xserver/programs/Xserver/include/servermd.h [new file with mode: 0644]
Xserver/programs/Xserver/include/site.h [new file with mode: 0644]
Xserver/programs/Xserver/include/swaprep.h [new file with mode: 0644]
Xserver/programs/Xserver/include/validate.h [new file with mode: 0644]
Xserver/programs/Xserver/include/window.h [new file with mode: 0644]
Xserver/programs/Xserver/include/windowstr.h [new file with mode: 0644]
Xserver/programs/Xserver/mfb/Imakefile [new file with mode: 0644]
Xserver/programs/Xserver/mfb/fastblt.h [new file with mode: 0644]
Xserver/programs/Xserver/mfb/maskbits.c [new file with mode: 0644]
Xserver/programs/Xserver/mfb/maskbits.h [new file with mode: 0644]
Xserver/programs/Xserver/mfb/mergerop.h [new file with mode: 0644]
Xserver/programs/Xserver/mfb/mfb.h [new file with mode: 0644]
Xserver/programs/Xserver/mfb/mfbbitblt.c [new file with mode: 0644]
Xserver/programs/Xserver/mfb/mfbblt.c [new file with mode: 0644]
Xserver/programs/Xserver/mfb/mfbbres.c [new file with mode: 0644]
Xserver/programs/Xserver/mfb/mfbbresd.c [new file with mode: 0644]
Xserver/programs/Xserver/mfb/mfbbstore.c [new file with mode: 0644]
Xserver/programs/Xserver/mfb/mfbclip.c [new file with mode: 0644]
Xserver/programs/Xserver/mfb/mfbcmap.c [new file with mode: 0644]
Xserver/programs/Xserver/mfb/mfbfillarc.c [new file with mode: 0644]
Xserver/programs/Xserver/mfb/mfbfillrct.c [new file with mode: 0644]
Xserver/programs/Xserver/mfb/mfbfillsp.c [new file with mode: 0644]
Xserver/programs/Xserver/mfb/mfbfont.c [new file with mode: 0644]
Xserver/programs/Xserver/mfb/mfbgc.c [new file with mode: 0644]
Xserver/programs/Xserver/mfb/mfbgetsp.c [new file with mode: 0644]
Xserver/programs/Xserver/mfb/mfbhrzvert.c [new file with mode: 0644]
Xserver/programs/Xserver/mfb/mfbimage.c [new file with mode: 0644]
Xserver/programs/Xserver/mfb/mfbimggblt.c [new file with mode: 0644]
Xserver/programs/Xserver/mfb/mfbline.c [new file with mode: 0644]
Xserver/programs/Xserver/mfb/mfbmisc.c [new file with mode: 0644]
Xserver/programs/Xserver/mfb/mfbpixmap.c [new file with mode: 0644]
Xserver/programs/Xserver/mfb/mfbply1rct.c [new file with mode: 0644]
Xserver/programs/Xserver/mfb/mfbplygblt.c [new file with mode: 0644]
Xserver/programs/Xserver/mfb/mfbpntarea.c [new file with mode: 0644]
Xserver/programs/Xserver/mfb/mfbpntwin.c [new file with mode: 0644]
Xserver/programs/Xserver/mfb/mfbpolypnt.c [new file with mode: 0644]
Xserver/programs/Xserver/mfb/mfbpushpxl.c [new file with mode: 0644]
Xserver/programs/Xserver/mfb/mfbscrclse.c [new file with mode: 0644]
Xserver/programs/Xserver/mfb/mfbscrinit.c [new file with mode: 0644]
Xserver/programs/Xserver/mfb/mfbsetsp.c [new file with mode: 0644]
Xserver/programs/Xserver/mfb/mfbtegblt.c [new file with mode: 0644]
Xserver/programs/Xserver/mfb/mfbtile.c [new file with mode: 0644]
Xserver/programs/Xserver/mfb/mfbwindow.c [new file with mode: 0644]
Xserver/programs/Xserver/mfb/mfbzerarc.c [new file with mode: 0644]
Xserver/programs/Xserver/mi/Imakefile [new file with mode: 0644]
Xserver/programs/Xserver/mi/cbrt.c [new file with mode: 0644]
Xserver/programs/Xserver/mi/mi.h [new file with mode: 0644]
Xserver/programs/Xserver/mi/miarc.c [new file with mode: 0644]
Xserver/programs/Xserver/mi/mibitblt.c [new file with mode: 0644]
Xserver/programs/Xserver/mi/mibstore.c [new file with mode: 0644]
Xserver/programs/Xserver/mi/mibstore.h [new file with mode: 0644]
Xserver/programs/Xserver/mi/mibstorest.h [new file with mode: 0644]
Xserver/programs/Xserver/mi/miclipn.c [new file with mode: 0644]
Xserver/programs/Xserver/mi/micursor.c [new file with mode: 0644]
Xserver/programs/Xserver/mi/midash.c [new file with mode: 0644]
Xserver/programs/Xserver/mi/midispcur.c [new file with mode: 0644]
Xserver/programs/Xserver/mi/mieq.c [new file with mode: 0644]
Xserver/programs/Xserver/mi/miexpose.c [new file with mode: 0644]
Xserver/programs/Xserver/mi/mifillarc.c [new file with mode: 0644]
Xserver/programs/Xserver/mi/mifillarc.h [new file with mode: 0644]
Xserver/programs/Xserver/mi/mifillrct.c [new file with mode: 0644]
Xserver/programs/Xserver/mi/mifpoly.h [new file with mode: 0644]
Xserver/programs/Xserver/mi/mifpolycon.c [new file with mode: 0644]
Xserver/programs/Xserver/mi/migc.c [new file with mode: 0644]
Xserver/programs/Xserver/mi/migc.h [new file with mode: 0644]
Xserver/programs/Xserver/mi/miglblt.c [new file with mode: 0644]
Xserver/programs/Xserver/mi/miinitext.c [new file with mode: 0644]
Xserver/programs/Xserver/mi/miline.h [new file with mode: 0644]
Xserver/programs/Xserver/mi/mipointer.c [new file with mode: 0644]
Xserver/programs/Xserver/mi/mipointer.h [new file with mode: 0644]
Xserver/programs/Xserver/mi/mipointrst.h [new file with mode: 0644]
Xserver/programs/Xserver/mi/mipoly.c [new file with mode: 0644]
Xserver/programs/Xserver/mi/mipoly.h [new file with mode: 0644]
Xserver/programs/Xserver/mi/mipolycon.c [new file with mode: 0644]
Xserver/programs/Xserver/mi/mipolygen.c [new file with mode: 0644]
Xserver/programs/Xserver/mi/mipolypnt.c [new file with mode: 0644]
Xserver/programs/Xserver/mi/mipolyrect.c [new file with mode: 0644]
Xserver/programs/Xserver/mi/mipolyseg.c [new file with mode: 0644]
Xserver/programs/Xserver/mi/mipolytext.c [new file with mode: 0644]
Xserver/programs/Xserver/mi/mipolyutil.c [new file with mode: 0644]
Xserver/programs/Xserver/mi/mipushpxl.c [new file with mode: 0644]
Xserver/programs/Xserver/mi/miregion.c [new file with mode: 0644]
Xserver/programs/Xserver/mi/miscanfill.h [new file with mode: 0644]
Xserver/programs/Xserver/mi/miscrinit.c [new file with mode: 0644]
Xserver/programs/Xserver/mi/mispans.c [new file with mode: 0644]
Xserver/programs/Xserver/mi/mispans.h [new file with mode: 0644]
Xserver/programs/Xserver/mi/misprite.c [new file with mode: 0644]
Xserver/programs/Xserver/mi/misprite.h [new file with mode: 0644]
Xserver/programs/Xserver/mi/mispritest.h [new file with mode: 0644]
Xserver/programs/Xserver/mi/mistruct.h [new file with mode: 0644]
Xserver/programs/Xserver/mi/mivalidate.h [new file with mode: 0644]
Xserver/programs/Xserver/mi/mivaltree.c [new file with mode: 0644]
Xserver/programs/Xserver/mi/miwideline.c [new file with mode: 0644]
Xserver/programs/Xserver/mi/miwideline.h [new file with mode: 0644]
Xserver/programs/Xserver/mi/miwindow.c [new file with mode: 0644]
Xserver/programs/Xserver/mi/mizerarc.c [new file with mode: 0644]
Xserver/programs/Xserver/mi/mizerarc.h [new file with mode: 0644]
Xserver/programs/Xserver/mi/mizerline.c [new file with mode: 0644]
Xserver/programs/Xserver/os/Imakefile [new file with mode: 0644]
Xserver/programs/Xserver/os/WaitFor.c [new file with mode: 0644]
Xserver/programs/Xserver/os/access.c [new file with mode: 0644]
Xserver/programs/Xserver/os/auth.c [new file with mode: 0644]
Xserver/programs/Xserver/os/connection.c [new file with mode: 0644]
Xserver/programs/Xserver/os/decompress.c [new file with mode: 0644]
Xserver/programs/Xserver/os/genalloca.c [new file with mode: 0644]
Xserver/programs/Xserver/os/hpsocket.c [new file with mode: 0644]
Xserver/programs/Xserver/os/io.c [new file with mode: 0644]
Xserver/programs/Xserver/os/iopreader.c [new file with mode: 0644]
Xserver/programs/Xserver/os/k5auth.c [new file with mode: 0644]
Xserver/programs/Xserver/os/lbxio.c [new file with mode: 0644]
Xserver/programs/Xserver/os/mitauth.c [new file with mode: 0644]
Xserver/programs/Xserver/os/oscolor.c [new file with mode: 0644]
Xserver/programs/Xserver/os/osdep.h [new file with mode: 0644]
Xserver/programs/Xserver/os/osinit.c [new file with mode: 0644]
Xserver/programs/Xserver/os/rpcauth.c [new file with mode: 0644]
Xserver/programs/Xserver/os/secauth.c [new file with mode: 0644]
Xserver/programs/Xserver/os/utils.c [new file with mode: 0644]
Xserver/programs/Xserver/os/wrapper.c [new file with mode: 0644]
Xserver/programs/Xserver/os/xalloc.c [new file with mode: 0644]
Xserver/programs/Xserver/os/xdmauth.c [new file with mode: 0644]
Xserver/programs/Xserver/os/xdmcp.c [new file with mode: 0644]
Xserver/registry [new file with mode: 0644]

diff --git a/Xserver/INSTALL.PS b/Xserver/INSTALL.PS
new file mode 100644 (file)
index 0000000..122e934
--- /dev/null
@@ -0,0 +1,982 @@
+%!PS-Adobe-3.0
+%%Creator: groff version 1.09
+%%CreationDate: Sun Dec 22 20:42:59 1996
+%%DocumentNeededResources: font Times-Bold
+%%+ font Times-Italic
+%%+ font Times-Roman
+%%DocumentSuppliedResources: procset grops 1.09 0
+%%Pages: 13
+%%PageOrder: Ascend
+%%Orientation: Portrait
+%%EndComments
+%%BeginProlog
+%%BeginResource: procset grops 1.09 0
+/setpacking where{
+pop
+currentpacking
+true setpacking
+}if
+/grops 120 dict dup begin
+/SC 32 def
+/A/show load def
+/B{0 SC 3 -1 roll widthshow}bind def
+/C{0 exch ashow}bind def
+/D{0 exch 0 SC 5 2 roll awidthshow}bind def
+/E{0 rmoveto show}bind def
+/F{0 rmoveto 0 SC 3 -1 roll widthshow}bind def
+/G{0 rmoveto 0 exch ashow}bind def
+/H{0 rmoveto 0 exch 0 SC 5 2 roll awidthshow}bind def
+/I{0 exch rmoveto show}bind def
+/J{0 exch rmoveto 0 SC 3 -1 roll widthshow}bind def
+/K{0 exch rmoveto 0 exch ashow}bind def
+/L{0 exch rmoveto 0 exch 0 SC 5 2 roll awidthshow}bind def
+/M{rmoveto show}bind def
+/N{rmoveto 0 SC 3 -1 roll widthshow}bind def
+/O{rmoveto 0 exch ashow}bind def
+/P{rmoveto 0 exch 0 SC 5 2 roll awidthshow}bind def
+/Q{moveto show}bind def
+/R{moveto 0 SC 3 -1 roll widthshow}bind def
+/S{moveto 0 exch ashow}bind def
+/T{moveto 0 exch 0 SC 5 2 roll awidthshow}bind def
+/SF{
+findfont exch
+[exch dup 0 exch 0 exch neg 0 0]makefont
+dup setfont
+[exch/setfont cvx]cvx bind def
+}bind def
+/MF{
+findfont
+[5 2 roll
+0 3 1 roll 
+neg 0 0]makefont
+dup setfont
+[exch/setfont cvx]cvx bind def
+}bind def
+/level0 0 def
+/RES 0 def
+/PL 0 def
+/LS 0 def
+/PLG{
+gsave newpath clippath pathbbox grestore
+exch pop add exch pop
+}bind def
+/BP{
+/level0 save def
+1 setlinecap
+1 setlinejoin
+72 RES div dup scale
+LS{
+90 rotate
+}{
+0 PL translate
+}ifelse
+1 -1 scale
+}bind def
+/EP{
+level0 restore
+showpage
+}bind def
+/DA{
+newpath arcn stroke
+}bind def
+/SN{
+transform
+.25 sub exch .25 sub exch
+round .25 add exch round .25 add exch
+itransform
+}bind def
+/DL{
+SN
+moveto
+SN
+lineto stroke
+}bind def
+/DC{
+newpath 0 360 arc closepath
+}bind def
+/TM matrix def
+/DE{
+TM currentmatrix pop
+translate scale newpath 0 0 .5 0 360 arc closepath
+TM setmatrix
+}bind def
+/RC/rcurveto load def
+/RL/rlineto load def
+/ST/stroke load def
+/MT/moveto load def
+/CL/closepath load def
+/FL{
+currentgray exch setgray fill setgray
+}bind def
+/BL/fill load def
+/LW/setlinewidth load def
+/RE{
+findfont
+dup maxlength 1 index/FontName known not{1 add}if dict begin
+{
+1 index/FID ne{def}{ pop pop}ifelse
+}forall
+/Encoding exch def
+dup/FontName exch def
+currentdict end definefont pop
+}bind def
+/DEFS 0 def
+/EBEGIN{
+moveto
+DEFS begin
+}bind def
+/EEND/end load def
+/CNT 0 def
+/level1 0 def
+/PBEGIN{
+/level1 save def
+translate
+div 3 1 roll div exch scale
+neg exch neg exch translate
+0 setgray
+0 setlinecap
+1 setlinewidth
+0 setlinejoin
+10 setmiterlimit
+[] 0 setdash
+/setstrokeadjust where{
+pop
+false setstrokeadjust
+}if
+/setoverprint where{
+pop
+false setoverprint
+}if
+newpath
+/CNT countdictstack def
+userdict begin
+/showpage{} def
+}bind def
+/PEND{
+clear
+countdictstack CNT sub{end}repeat
+level1 restore
+}bind def
+end def
+/setpacking where{
+pop
+setpacking
+}if
+%%EndResource
+%%IncludeResource: font Times-Bold
+%%IncludeResource: font Times-Italic
+%%IncludeResource: font Times-Roman
+grops begin/DEFS 1 dict def DEFS begin/u{.001 mul}bind def end/RES 72
+def/PL 792 def/LS false def/ENC0[/asciicircum/asciitilde/Scaron/Zcaron
+/scaron/zcaron/Ydieresis/trademark/quotesingle/.notdef/.notdef/.notdef
+/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef
+/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef
+/.notdef/.notdef/space/exclam/quotedbl/numbersign/dollar/percent
+/ampersand/quoteright/parenleft/parenright/asterisk/plus/comma/hyphen
+/period/slash/zero/one/two/three/four/five/six/seven/eight/nine/colon
+/semicolon/less/equal/greater/question/at/A/B/C/D/E/F/G/H/I/J/K/L/M/N/O
+/P/Q/R/S/T/U/V/W/X/Y/Z/bracketleft/backslash/bracketright/circumflex
+/underscore/quoteleft/a/b/c/d/e/f/g/h/i/j/k/l/m/n/o/p/q/r/s/t/u/v/w/x/y
+/z/braceleft/bar/braceright/tilde/.notdef/quotesinglbase/guillemotleft
+/guillemotright/bullet/florin/fraction/perthousand/dagger/daggerdbl
+/endash/emdash/ff/fi/fl/ffi/ffl/dotlessi/dotlessj/grave/hungarumlaut
+/dotaccent/breve/caron/ring/ogonek/quotedblleft/quotedblright/oe/lslash
+/quotedblbase/OE/Lslash/.notdef/exclamdown/cent/sterling/currency/yen
+/brokenbar/section/dieresis/copyright/ordfeminine/guilsinglleft
+/logicalnot/minus/registered/macron/degree/plusminus/twosuperior
+/threesuperior/acute/mu/paragraph/periodcentered/cedilla/onesuperior
+/ordmasculine/guilsinglright/onequarter/onehalf/threequarters
+/questiondown/Agrave/Aacute/Acircumflex/Atilde/Adieresis/Aring/AE
+/Ccedilla/Egrave/Eacute/Ecircumflex/Edieresis/Igrave/Iacute/Icircumflex
+/Idieresis/Eth/Ntilde/Ograve/Oacute/Ocircumflex/Otilde/Odieresis
+/multiply/Oslash/Ugrave/Uacute/Ucircumflex/Udieresis/Yacute/Thorn
+/germandbls/agrave/aacute/acircumflex/atilde/adieresis/aring/ae/ccedilla
+/egrave/eacute/ecircumflex/edieresis/igrave/iacute/icircumflex/idieresis
+/eth/ntilde/ograve/oacute/ocircumflex/otilde/odieresis/divide/oslash
+/ugrave/uacute/ucircumflex/udieresis/yacute/thorn/ydieresis]def
+/Times-Roman@0 ENC0/Times-Roman RE/Times-Italic@0 ENC0/Times-Italic RE
+/Times-Bold@0 ENC0/Times-Bold RE
+%%EndProlog
+%%Page: title 1
+%%BeginPageSetup
+BP
+%%EndPageSetup
+/F0 15/Times-Bold@0 SF(Building and Installing the X W)159.51 123 Q
+(indo)-.27 E 3.75(wS)-.15 G(ystem)-3.75 E/F1 11/Times-Italic@0 SF
+(Stephen Gildea)272.241 219 Q/F2 11/Times-Roman@0 SF 2.75(XC)274.677 249
+S(onsortium)-2.75 E(March 5, 1996)273.77 333 Q(Updated F)251.704 357 Q
+(or Release 6.3)-.165 E EP
+%%Page: copyr 2
+%%BeginPageSetup
+BP
+%%EndPageSetup
+/F0 11/Times-Roman@0 SF(Cop)72 192 Q
+(yright \251 1995, 1996 X Consortium)-.11 E/F1 9/Times-Roman@0 SF
+(Permission is hereby granted, free of char)72 206.6 Q(ge, to an)-.162 E
+2.25(yp)-.135 G(erson obtaining a cop)-2.25 E 2.25(yo)-.09 G 2.25(ft)
+-2.25 G(his softw)-2.25 E(are and associated documentation \214les)-.09
+E(\(the `)72 217.6 Q(`Softw)-.75 E(are')-.09 E
+('\), to deal in the Softw)-.75 E(are without restriction, including wi\
+thout limitation the rights to use, cop)-.09 E 1.17 -.585(y, m)-.09 H
+(odify).585 E 2.25(,m)-.585 G(er)-2.25 E(ge,)-.162 E(publish, distrib)72
+228.6 Q(ute, sublicense, and/or sell copies of the Softw)-.18 E
+(are, and to permit persons to whom the Softw)-.09 E
+(are is furnished to do)-.09 E(so, subject to the follo)72 239.6 Q
+(wing conditions:)-.225 E(The abo)72 254.2 Q .27 -.135(ve c)-.135 H(op)
+.135 E(yright notice and this permission notice shall be included in al\
+l copies or substantial portions of the Softw)-.09 E(are.)-.09 E
+(THE SOFTW)72 268.8 Q(ARE IS PR)-1.08 E -.45(OV)-.36 G(IDED `).45 E -.72
+(`A)-.75 G 2.25(SI).72 G(S')-2.25 E(', WITHOUT W)-.75 E
+(ARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUD-)-1.08 E(ING B)72 279.8
+Q(UT NO)-.09 E 2.25(TL)-.36 G(IMITED T)-2.25 E 2.25(OT)-.162 G(HE W)
+-2.25 E(ARRANTIES OF MERCHANT)-1.08 E(ABILITY)-.837 E 2.25(,F)-1.161 G
+(ITNESS FOR A P)-2.25 E(AR)-.828 E(TICULAR PURPOSE)-.54 E
+(AND NONINFRINGEMENT)72 290.8 Q 4.5(.I)-.666 G 2.25(NN)-4.5 G 2.25(OE)
+-2.25 G(VENT SHALL THE X CONSOR)-2.25 E(TIUM BE LIABLE FOR ANY CLAIM, D)
+-.54 E(AMA)-.36 E(GES)-.36 E(OR O)72 301.8 Q(THER LIABILITY)-.36 E 2.25
+(,W)-1.161 G(HETHER IN AN A)-2.25 E(CTION OF CONTRA)-.36 E(CT)-.36 E
+2.25(,T)-.666 G(OR)-2.412 E 2.25(TO)-.54 G 2.25(RO)-2.25 G(THER)-2.61 E
+(WISE, ARISING FR)-.495 E(OM, OUT OF)-.36 E
+(OR IN CONNECTION WITH THE SOFTW)72 312.8 Q(ARE OR THE USE OR O)-1.08 E
+(THER DEALINGS IN THE SOFTW)-.36 E(ARE.)-1.08 E(Except as contained in \
+this notice, the name of the X Consortium shall not be used in adv)72
+327.4 Q(ertising or otherwise to promote the)-.135 E
+(sale, use or other dealings in this Softw)72 338.4 Q
+(are without prior written authorization from the X Consortium.)-.09 E
+/F2 9/Times-Italic@0 SF 2.25(XW)72 353 S(indow System)-2.745 E F1
+(is a trademark of X Consortium, Inc.)2.25 E EP
+%%Page: i 3
+%%BeginPageSetup
+BP
+%%EndPageSetup
+/F0 13/Times-Bold@0 SF -1.196(Ta)257.126 85 S(ble of Contents)1.196 E/F1
+11/Times-Roman@0 SF(1. Easy Build Instructions)72 127.6 Q -2.75 11
+(........................ 1)7.221 H(2. Building X)72 144.2 Q -2.75 11
+(............................ 1)6.297 H(2.1. Preparing the Site)72 160.8
+Q -2.75 11(......................... 1)9.674 H
+(2.2. Unpacking the Distrib)72 177.4 Q 6.836(ution .)-.22 F -2.75 11
+(..................... 2)11 H(2.2.1. Unpacking a Compressed FTP Distrib)
+72 194 Q 10.807(ution .)-.22 F -2.75 11(............... 2)11 H
+(2.2.2. Unpacking a gzipped FTP Distrib)72 210.6 Q 2.865(ution .)-.22 F
+-2.75 11(................. 2)11 H
+(2.2.3. Unpacking a Split Compressed FTP Distrib)72 227.2 Q 1.017
+(ution .)-.22 F -2.75 11(.............. 2)11 H(2.2.4. Unpacking the T)72
+243.8 Q(ape Distrib)-.88 E 2.227(ution .)-.22 F -2.75 11
+(................... 3)11 H(2.2.5. Using the CD-R)72 260.4 Q 2.469(OM .)
+-.44 F -2.75 11(....................... 3)11 H(2.3. Apply P)72 277 Q
+8.31(atches .)-.165 F -2.75 11(......................... 3)11 H
+(2.4. Symbolic Link T)72 293.6 Q 7.001(rees .)-.385 F -2.75 11
+(....................... 3)11 H(2.5. Con\214guration P)72 310.2 Q .676
+(arameters .)-.165 F -2.75 11(...................... 3)11 H
+(2.6. System Build Notes)72 326.8 Q -2.75 11(........................ 5)
+14.239 H(2.6.1. gcc)72 343.4 Q -2.75 11(............................. 5)
+9.982 H(2.6.2. Other GNU tools)72 360 Q -2.75 11
+(......................... 5)4.482 H(2.6.3. SparcW)72 376.6 Q(orks 2.0)
+-.88 E -2.75 11(......................... 5)10.257 H
+(2.6.4. CenterLine C under Solaris 2)72 393.2 Q -2.75 11
+(..................... 5)6.319 H(2.6.5. IBM AIX 4.1.4)72 409.8 Q -2.75
+11(......................... 6)12.424 H(2.6.6. SunOS 4)72 426.4 Q -2.75
+11(........................... 6)13.326 H(2.6.7. Microsoft W)72 443 Q
+(indo)-.44 E(ws NT)-.275 E -2.75 11(....................... 6)2.755 H
+(2.6.8. Omron Luna)72 459.6 Q -2.75 11(.......................... 6)
+9.982 H(2.7. The Build)72 476.2 Q -2.75 11
+(............................ 7)2.942 H(2.8. Installing X)72 492.8 Q
+-2.75 11(........................... 7)8.75 H
+(2.8.1. System Installation Notes)72 509.4 Q -2.75 11
+(...................... 7)8.442 H(2.8.1.1. The X Serv)72 526 Q
+(er on AIX 4)-.165 E -2.75 11(...................... 7)9.861 H
+(2.9. Shared Libraries)72 542.6 Q -2.75 11(......................... 8)
+15.493 H(2.10. Setting Up xterm)72 559.2 Q -2.75 11
+(......................... 8)7.221 H(2.11. Starting Serv)72 575.8 Q
+(ers at System Boot)-.165 E -2.75 11(.................... 8)11.357 H
+(2.11.1. On BSD-based systems using /etc/rc)72 592.4 Q -2.75 11
+(.................. 8)10.29 H(2.11.2. On SystemV)72 609 Q
+(-based systems)-1.1 E -2.75 11(..................... 9)8.024 H
+(2.12. Using OPEN LOOK applications)72 625.6 Q -2.75 11
+(.................... 9)4.79 H(2.13. Reb)72 642.2 Q(uilding after P)-.22
+E 13.733(atches .)-.165 F -8.25 11(..................... 1)11 H(0)-11 E
+(2.14. F)72 658.8 Q(ormatting the Documentation)-.165 E -8.25 11
+(.................... 1)16.252 H(0)-11 E(i)304.471 769 Q EP
+%%Page: blank 4
+showpage
+%%Page: 1 5
+%%BeginPageSetup
+BP
+%%EndPageSetup
+/F0 11/Times-Bold@0 SF 2.75(1. Easy)72 85 R(Build Instructions)2.75 E/F1
+11/Times-Roman@0 SF
+(This quick summary is no substitute for reading the full b)72 101.6 Q
+(uild instructions later in this document.)-.22 E(Edit)72 118.2 Q F0
+(xc/con\214g/cf/site.def)2.75 E F1(for local preferences.)2.75 E
+(If you w)5.5 E(ant to b)-.11 E(uild with)-.22 E/F2 11/Times-Italic@0 SF
+(gcc)2.75 E F1(uncomment the)2.75 E F0(HasGcc2)2.75 E F1 2.75(line. If)
+72 131.2 R(you w)2.75 E(ant to install some)-.11 E(where other than)
+-.275 E F0(/usr/X11R6.3)2.75 E F1 2.75(,c)C(hange)-2.75 E F0(Pr)2.75 E
+(ojectRoot)-.198 E F1 5.5(.\()C(Do)-5.5 E F2(not)2.75 E F1(use)2.75 E F0
+(DESTDIR)72 144.2 Q F1(.\))A(If an)72 160.8 Q 2.75<798c>-.165 G -.165
+(xe)-2.75 G 2.75(sh).165 G -2.475 -.22(av e)-2.75 H
+(been released by the X Consortium, stop here and follo)2.97 E 2.75(wt)
+-.275 G(he instructions at the top of)-2.75 E(each patch, b)72 173.8 Q
+(ut don')-.22 E 2.75(td)-.198 G 2.75(oa)-2.75 G .33 -.165(ny o)-2.75 H
+2.75(ft).165 G(he)-2.75 E F2(mak)2.75 E(e)-.11 E F1
+(commands suggested in the patches.)2.75 E(Then continue here.)5.5 E
+(Check the appropriate v)72 190.4 Q(endor)-.165 E(-speci\214c)-.22 E F0
+(.cf)2.75 E F1(\214le in)2.75 E F0(xc/con\214g/cf/)2.75 E F1(to mak)2.75
+E 2.75(es)-.11 G(ure that)-2.75 E F0(OSMajorV)2.75 E(ersion)-1.1 E F1
+(and)2.75 E F0(OSMinorV)72 203.4 Q(ersion)-1.1 E F1
+(are set correctly for your system.)2.75 E(Ov)5.5 E(erride them in)-.165
+E F0(site.def)2.75 E F1(if necessary)2.75 E(.)-.715 E(See if there is a)
+72 220 Q F0(BootstrapCFlags)2.75 E F1
+(mentioned in the comments in the v)2.75 E(endor)-.165 E(-speci\214c)
+-.22 E F0(.cf)2.75 E F1 2.75(\214le. If)2.75 F(there isn')2.75 E(t)-.198
+E(one,)72 233 Q F2(cd)2.75 E F1(to the)2.75 E F0(xc)2.75 E F1
+(directory and type:)2.75 E 2.75(%m)108 252 S(ak)-2.75 E 2.75(eW)-.11 G
+(orld >& w)-3.63 E(orld.log)-.11 E(If there is a)72 274.6 Q F0
+(BootstrapCFlags)2.75 E F1 2.75(,t)C(ak)-2.75 E 2.75(ei)-.11 G(ts v)
+-2.75 E(alue and type:)-.275 E 2.75(%m)108 293.6 S(ak)-2.75 E 2.75(eW)
+-.11 G(orld BOO)-3.63 E(TSTRAPCFLA)-.44 E(GS=")-.44 E F2(value)A F1 2.75
+(">)C 2.75(&w)-2.75 G(orld.log)-2.86 E(Do not call the output \214le `)
+72 316.2 Q(`mak)-.916 E(e.log')-.11 E 2.75('w)-.916 G(hen doing `)-2.75
+E(`mak)-.916 E 2.75(eW)-.11 G(orld')-3.63 E 2.75('. After)-.916 F 2.75
+(as)2.75 G(uccessful b)-2.75 E(uild, you can)-.22 E(install with:)72
+329.2 Q 2.75(%m)108 348.2 S(ak)-2.75 E 2.75(ei)-.11 G
+(nstall >& install.log)-2.75 E -1.21(Yo)72 370.8 S 2.75(uc)1.21 G
+(an install manual pages with:)-2.75 E 2.75(%m)108 389.8 S(ak)-2.75 E
+2.75(ei)-.11 G(nstall.man >& man.log)-2.75 E(While the system is b)72
+412.4 Q(uilding \(or if things f)-.22 E
+(ail\), read the rest of these installation instructions.)-.11 E F0 2.75
+(2. Building)72 464.4 R(X)2.75 E F1(This document gi)72 494 Q -.165(ve)
+-.275 G 2.75(sd).165 G(etailed instructions for b)-2.75 E
+(uilding Release 6: getting it of)-.22 E 2.75(ft)-.275 G(he distrib)
+-2.75 E(ution medium,)-.22 E
+(con\214guring, compiling, installing, running, and updating.)72 507 Q
+(Release Notes are in)72 523.6 Q F0(xc/RELNO)2.75 E(TES.*)-.44 E F1(\(v)
+2.75 E(arious formats\) in the distrib)-.275 E(ution.)-.22 E
+(More recent information about ne)72 540.2 Q(wly-disco)-.275 E -.165(ve)
+-.165 G(red problems may be found in the).165 E F2 -1.947 -.605(Fr e)
+2.75 H(quently Ask).605 E(ed Ques-)-.11 E(tions)72 553.2 Q F1
+(posting appearing monthly on the comp.windo)2.75 E(ws.x ne)-.275 E
+(wsgroup and xpert mailing list.)-.275 E(It is also)5.5 E -.22(av)72
+566.2 S(ailable via anon)-.055 E(ymous FTP on)-.165 E F0(ftp.x.or)2.75 E
+(g)-.11 E F1(in the \214le)2.75 E F0(contrib/faqs/F)2.75 E -1.98 -.495
+(AQ .)-.99 H(Z).495 E F1 2.75(,o)C 2.75(ro)-2.75 G 2.75(ny)-2.75 G
+(our local X mirror site.)-2.75 E F0 2.75(2.1. Pr)72 605.2 R
+(eparing the Site)-.198 E F1(If you are unpacking tar \214les, you will\
+ need about 130 Mb to hold the)72 634.8 Q F0(xc/)2.75 E F1 2.75(part. T)
+2.75 F 2.75(oi)-.88 G(nstall requires 30-50)-2.75 E(Mb assuming you ha)
+72 647.8 Q .33 -.165(ve s)-.22 H(hared libraries \(80-100 Mb without\).)
+.165 E -1.21(Yo)5.5 G 2.75(uw)1.21 G(ill need an equi)-2.75 E -.275(va)
+-.275 G(lent amount of).275 E -.165(ex)72 660.8 S(tra space to b).165 E
+(uild, since you also need room for all the object \214les.)-.22 E
+(Distrib)72 677.4 Q(uted as tar \214les, Release 6.3 core is di)-.22 E
+(vided into parts as follo)-.275 E(ws:)-.275 E(1)303.25 769 Q EP
+%%Page: 2 6
+%%BeginPageSetup
+BP
+%%EndPageSetup
+/F0 11/Times-Roman@0 SF 2.75(XW)72 49 S(indo)-3.19 E 2.75(wS)-.275 G
+(ystem Installation V)-2.75 E(ersion 11, Release 6.3 Snapshot)-1.221 E
+71.348(xc-1.tar contains)108 85 R -2.365 -.275(ev e)2.75 H
+(rything in xc/ that isn').275 E 2.75(ti)-.198 G 2.75(nt)-2.75 G
+(he other tar \214les)-2.75 E 71.348(xc-2.tar contains)108 98 R
+(xc/fonts, xc/doc/specs, xc/util)2.75 E 71.348(xc-3.tar contains)108 111
+R(xc/doc/hardcop)2.75 E(y)-.11 E(If you de\214ne BuildF)72 133.6 Q
+(onts to NO, you only need to unpack xc-1.tar to b)-.165 E 2.75
+(uild. If)-.22 F(you b)2.75 E(uild fonts, then you)-.22 E
+(will also need xc-2.tar to b)72 146.6 Q(uild.)-.22 E/F1 11/Times-Bold@0
+SF 2.75(2.2. Unpacking)72 185.6 R(the Distrib)2.75 E(ution)-.22 E F0
+(The distrib)72 215.2 Q(ution normally comes as multiple tar \214les, e\
+ither on tape or across a netw)-.22 E(ork, or as a CD-R)-.11 E(OM.)-.44
+E F1 2.75(2.2.1. Unpacking)72 254.2 R 2.75(aC)2.75 G(ompr)-2.75 E
+(essed FTP Distrib)-.198 E(ution)-.22 E F0(If you ha)72 283.8 Q .33
+-.165(ve o)-.22 H(btained compressed tar \214les o).165 E -.165(ve)-.165
+G 2.75(rt).165 G(he netw)-2.75 E
+(ork, create a directory to hold the sources and)-.11 E/F2 11
+/Times-Italic@0 SF(cd)2.75 E F0(into it:)72 296.8 Q(mkdir)108 315.8 Q F2
+(sour)2.75 E(cedir)-.407 E F0(cd)108 328.8 Q F2(sour)2.75 E(cedir)-.407
+E F0(Then for each tar \214le)72 347.8 Q F1(xc\255*.tar)2.75 E(.Z)-1.1 E
+F0 2.75(,e)C -.165(xe)-2.915 G(cute this:).165 E(zcat)108 366.8 Q F2
+(ftp-dir)5.5 E F0(/xc\255)A F2(N)A F0(.tar)A(.Z | tar xf)-.605 E<ad>5.5
+E F1 2.75(2.2.2. Unpacking)72 411.8 R 2.75(ag)2.75 G(zipped FTP Distrib)
+-2.75 E(ution)-.22 E F0(If you ha)72 441.4 Q .33 -.165(ve o)-.22 H
+(btained gzipped tar \214les o).165 E -.165(ve)-.165 G 2.75(rt).165 G
+(he netw)-2.75 E(ork, create a directory to hold the sources and)-.11 E
+F2(cd)2.75 E F0(into)2.75 E(it:)72 454.4 Q(mkdir)108 473.4 Q F2(sour)
+2.75 E(cedir)-.407 E F0(cd)108 486.4 Q F2(sour)2.75 E(cedir)-.407 E F0
+(Then for each tar \214le)72 505.4 Q F1(xc\255*.tar)2.75 E(.gz)-1.1 E F0
+2.75(,e)C -.165(xe)-2.915 G(cute this:).165 E 2.75(gunzip \255c)108
+524.4 R F2(ftp-dir)5.5 E F0(/xc\255)A F2(N)A F0(.tar)A(.gz | tar xf)
+-.605 E<ad>5.5 E F1 2.75(2.2.3. Unpacking)72 569.4 R 2.75(aS)2.75 G
+(plit Compr)-2.75 E(essed FTP Distrib)-.198 E(ution)-.22 E F0(If you ha)
+72 599 Q .33 -.165(ve o)-.22 H
+(btained compressed and split tar \214les o).165 E -.165(ve)-.165 G 2.75
+(rt).165 G(he netw)-2.75 E(ork, create a directory to hold the)-.11 E
+(sources:)72 612 Q(mkdir)108 631 Q F2(sour)2.75 E(cedir)-.407 E F0
+(Then for each directory)72 650 Q F1(xc\255*)2.75 E F0(:)A(cd)108 669 Q
+F2(ftp-dir)2.75 E F0(/xc\255)A F2(N)A F0(cat xc\255)108 682 Q F2(N)A F0
+(.?? | uncompress | \(cd)A F2(sour)2.75 E(cedir)-.407 E F0 2.75(;t)1.833
+G(ar xf)-2.75 E 1.833<ad29>5.5 G(2)303.25 769 Q EP
+%%Page: 3 7
+%%BeginPageSetup
+BP
+%%EndPageSetup
+/F0 11/Times-Roman@0 SF 2.75(XV)72 49 S(ersion 11, Release 6.3 Snapshot)
+-3.971 E 2.75(XW)175.4 G(indo)-3.19 E 2.75(wS)-.275 G
+(ystem Installation)-2.75 E/F1 11/Times-Bold@0 SF 2.75(2.2.4. Unpacking)
+72 85 R(the T)2.75 E(ape Distrib)-1.012 E(ution)-.22 E F0(If you ha)72
+114.6 Q .33 -.165(ve o)-.22 H
+(btained a tape, create a directory to hold the sources and untar e).165
+E -.165(ve)-.275 G(rything into that directory:).165 E(mkdir)108 133.6 Q
+/F2 11/Times-Italic@0 SF(sour)2.75 E(cedir)-.407 E F0(cd)108 146.6 Q F2
+(sour)2.75 E(cedir)-.407 E F0(tar xf)108 159.6 Q F2(tape-de)2.75 E(vice)
+-.165 E F1 2.75(2.2.5. Using)72 204.6 R(the CD-R)2.75 E(OM)-.33 E F0
+(If you ha)72 234.2 Q .33 -.165(ve o)-.22 H(btained a CD-R).165 E
+(OM, you don')-.44 E 2.75(th)-.198 G -2.475 -.22(av e)-2.75 H(to do an)
+2.97 E(ything to unpack it.)-.165 E(Ho)5.5 E(we)-.275 E -.165(ve)-.275 G
+.88 -.44(r, y).165 H(ou will ha).44 E .33 -.165(ve t)-.22 H(o).165 E
+(create a symbolic link tree to b)72 247.2 Q(uild X.)-.22 E(See the ne)
+5.5 E(xt section.)-.165 E 1.76 -.88(To m)72 263.8 T(ount the CD-R).88 E
+(OM, see the mount\(8\) manual page on your system or the liner notes t\
+hat came with)-.44 E(the CD-R)72 276.8 Q 2.75(OM. Some)-.44 F
+(systems, e.g., Solaris 2, can automatically mount the CD-R)2.75 E
+(OM for you.)-.44 E F1 2.75(2.3. A)72 315.8 R(pply P)-.275 E(atches)-.11
+E F0(If there are \214x)72 345.4 Q
+(es released that are more recent than your distrib)-.165 E
+(ution, apply them no)-.22 E 4.18 -.715(w. F)-.275 H(ollo).55 E 2.75(wt)
+-.275 G(he instruc-)-2.75 E(tions at the top of each patch, b)72 358.4 Q
+(ut don')-.22 E 2.75(td)-.198 G 2.75(oa)-2.75 G .33 -.165(ny m)-2.75 H
+(ak).165 E 2.75(ec)-.11 G 2.75(ommands. See)-2.75 F(the section `)2.75 E
+(`Public P)-.916 E(atches')-.165 E 2.75('l)-.916 G(ater)-2.75 E
+(in this document.)72 371.4 Q(Then continue here.)5.5 E F1 2.75
+(2.4. Symbolic)72 410.4 R(Link T)2.75 E -.198(re)-.814 G(es).198 E F0
+(If you e)72 440 Q(xpect to b)-.165 E(uild the distrib)-.22 E
+(ution on more than one machine using a shared source tree, or you are)
+-.22 E -.22(bu)72 453 S(ilding from CD-R).22 E(OM, or you just w)-.44 E
+(ant to k)-.11 E(eep the source tree pure, you may w)-.11 E
+(ant to use the program)-.11 E F1(xc/con\214g/util/lndir)72 466 Q(.c)
+-1.1 E F0(to create a symbolic link tree on each b)2.75 E(uild machine.)
+-.22 E(The links may use an addi-)5.5 E(tional 10 me)72 479 Q -.055(ga)
+-.165 G(bytes, b).055 E(ut it is cheaper than ha)-.22 E
+(ving multiple copies of the source tree.)-.22 E(It may be trick)72
+495.6 Q 2.75(yt)-.165 G 2.75(oc)-2.75 G(ompile)-2.75 E F2(lndir)2.75 E
+F0(before the distrib)2.75 E(ution is b)-.22 E 2.75(uilt. If)-.22 F
+(you ha)2.75 E .33 -.165(ve a c)-.22 H(op).165 E 2.75(yf)-.11 G
+(rom a pre)-2.75 E(vious)-.275 E(release, use that.)72 508.6 Q F1(Mak)
+5.5 E(e\214le.ini)-.11 E F0(can be used for b)2.75 E(uilding)-.22 E F2
+(lndir)2.75 E F0(the \214rst time.)2.75 E -1.21(Yo)5.5 G 2.75(um)1.21 G
+(ay ha)-2.75 E .33 -.165(ve t)-.22 H 2.75(os).165 G(pecify)-2.75 E F1
+(OSFLA)72 521.6 Q(GS=\255D)-.605 E F2(something)A F0
+(to get it to compile.)2.75 E(What you w)5.5 E(ould pass as)-.11 E F1
+(BOO)2.75 E(TSTRAPCFLA)-.44 E(GS)-.605 E F0(might)2.75 E -.11(wo)72
+534.6 S 2.75(rk. The).11 F(command line looks something lik)2.75 E 2.75
+(et)-.11 G(his:)-2.75 E(mak)108 553.6 Q 5.5<65ad>-.11 G 5.5(fM)-5.5 G
+(ak)-5.5 E 2.75(e\214le.ini OSFLA)-.11 F(GS=\255D)-.44 E F2<8d61>A(g)
+-.11 E F0 1.76 -.88(To u)72 576.2 T
+(se a symbolic link tree, create a directory for the b).88 E(uild,)-.22
+E F2(cd)2.75 E F0(to it, and type this:)2.75 E(lndir)108 595.2 Q F2
+(sour)2.75 E(cedir)-.407 E F0(where)72 617.8 Q F2(sour)2.75 E(cedir)
+-.407 E F0
+(is the pathname of the directory where you stored the sources.)2.75 E
+(All of the b)5.5 E(uild instruc-)-.22 E(tions gi)72 630.8 Q -.165(ve)
+-.275 G 2.75(nb).165 G(elo)-2.75 E 2.75(ws)-.275 G
+(hould then be done in the b)-2.75 E
+(uild directory on each machine, rather than in the source)-.22 E
+(directory)72 643.8 Q(.)-.715 E F1(xc/con\214g/util/mkshado)72 660.4 Q
+(w/)-.11 E F0(contains)2.75 E F2(mkshadow)2.75 E F0 2.75(,a)C 2.75(na)
+-2.75 G(lternati)-2.75 E .33 -.165(ve p)-.275 H(rogram to).165 E F2
+(lndir)2.75 E F0(.)A F1 2.75(2.5. Con\214guration)72 699.4 R -.11(Pa)
+2.75 G(rameters).11 E F0
+(Build information for each source directory is in \214les called)72 729
+Q F1(Imak)2.75 E(e\214le)-.11 E F0 5.5(.A)C(n)-5.5 E F1(Imak)2.75 E
+(e\214le)-.11 E F0 2.75(,a)C(long with local)-2.75 E(3)303.25 769 Q EP
+%%Page: 4 8
+%%BeginPageSetup
+BP
+%%EndPageSetup
+/F0 11/Times-Roman@0 SF 2.75(XW)72 49 S(indo)-3.19 E 2.75(wS)-.275 G
+(ystem Installation V)-2.75 E(ersion 11, Release 6.3 Snapshot)-1.221 E
+(con\214guration information in)72 85 Q/F1 11/Times-Bold@0 SF
+(xc/con\214g/cf/)2.75 E F0 2.75(,i)C 2.75(su)-2.75 G(sed by the program)
+-2.75 E/F2 11/Times-Italic@0 SF(imak)2.75 E(e)-.11 E F0(to generate a)
+2.75 E F1(Mak)2.75 E(e\214le)-.11 E F0(.)A
+(Most of the con\214guration w)72 101.6 Q(ork prior to b)-.11 E
+(uilding the release is to set parameters so that)-.22 E F2(imak)2.75 E
+(e)-.11 E F0(will gener)2.75 E(-)-.22 E(ate correct \214les.)72 114.6 Q
+(Most of those parameters are set in)5.5 E F1(xc/con\214g/cf/site.def)
+2.75 E F0 5.5(.Y)C(ou will also need to check the)-6.71 E(appropriate v)
+72 127.6 Q(endor)-.165 E(-speci\214c)-.22 E F1(.cf)2.75 E F0(\214le in)
+2.75 E F1(xc/con\214g/cf/)2.75 E F0(to mak)2.75 E 2.75(es)-.11 G
+(ure that OSMajorV)-2.75 E(ersion, OSMinorV)-1.221 E(ersion,)-1.221 E
+(and OsT)72 140.6 Q(een)-.77 E(yV)-.165 E
+(ersion are set correctly for your system.)-1.221 E(Ov)5.5 E
+(erride them in)-.165 E F1(site.def)2.75 E F0(if necessary)2.75 E(.)
+-.715 E(The)72 157.2 Q F1(site.def)2.75 E F0(\214le has tw)2.75 E 2.75
+(op)-.11 G(arts, one protected with `)-2.75 E(`#ifdef BeforeV)-.916 E
+(endorCF')-1.221 E 2.75('a)-.916 G(nd one with `)-2.75 E(`#ifdef)-.916 E
+(AfterV)72 170.2 Q(endorCF')-1.221 E 2.75('. The)-.916 F
+(\214le is actually processed twice, once before the)2.75 E F1(.cf)2.75
+E F0(\214le and once after)2.75 E 5.5(.A)-.605 G(bout the)-5.5 E
+(only thing you need to set in the `)72 183.2 Q(`before')-.916 E 2.75
+('s)-.916 G(ection is)-2.75 E F1(HasGcc2)2.75 E F0 2.75(;j)C
+(ust about e)-2.75 E -.165(ve)-.275 G(rything else can be set in the)
+.165 E -.916(``)72 196.2 S(after').916 E 2.75('s)-.916 G(ection.)-2.75 E
+(The sample)72 212.8 Q F1(site.def)2.75 E F0
+(also has commented out support to include another \214le,)2.75 E F1
+(host.def)2.75 E F0 5.5(.T)C(his scheme may)-5.5 E(be useful if you w)72
+225.8 Q(ant to set most parameters site-wide, b)-.11 E
+(ut some parameters v)-.22 E(ary from machine to)-.275 E 2.75
+(machine. If)72 238.8 R(you use a symbolic link tree, you can share)2.75
+E F1(site.def)2.75 E F0(across all machines, and gi)2.75 E .33 -.165
+(ve e)-.275 H(ach).165 E(machine its o)72 251.8 Q(wn cop)-.275 E 2.75
+(yo)-.11 G(f)-2.75 E F1(host.def)2.75 E F0(.)A
+(The con\214g parameters are listed in)72 268.4 Q F1
+(xc/con\214g/cf/README)2.75 E F0 2.75(,b)C
+(ut here are some of the more common)-2.97 E
+(parameters that you may wish to set in)72 281.4 Q F1(site.def)2.75 E F0
+(.)A F1(Pr)72 298 Q(ojectRoot)-.198 E F0
+(The destination where X will be installed.)97 311 Q(This v)5.5 E
+(ariable needs to be set before you b)-.275 E(uild, as some)-.22 E
+(programs that read \214les at run-time ha)97 324 Q .33 -.165(ve t)-.22
+H(he installation directory compiled in to them.).165 E(Assuming)5.5 E
+(you ha)97 337 Q .33 -.165(ve s)-.22 H(et the v).165 E
+(ariable to some v)-.275 E(alue /)-.275 E F2(path)A F0 2.75<2c8c>C
+(les will be installed into /)-2.75 E F2(path)A F0(/bin,)A(/)97 350 Q F2
+(path)A F0(/include/X11, /)A F2(path)A F0(/lib, and /)A F2(path)A F0
+(/man.)A F1(HasGcc)72 366.6 Q F0(Set to)97 379.6 Q F1(YES)2.75 E F0
+(to b)2.75 E(uild with)-.22 E F2(gcc)2.75 E F0 -.165(ve)2.75 G(rsion 1.)
+.165 E F1(HasGcc2)72 396.2 Q F0(Set to)97 409.2 Q F1(YES)2.75 E F0(to b)
+2.75 E(uild with)-.22 E F2(gcc)2.75 E F0 -.165(ve)2.75 G(rsion 2.).165 E
+(Both this option and)5.5 E F1(HasGcc)2.75 E F0
+(look for a compiler named)2.75 E F2(gcc)97 422.2 Q F0 2.75(,b)C(ut)
+-2.97 E F1(HasGcc2)2.75 E F0(will cause the b)2.75 E
+(uild to use more features of)-.22 E F2(gcc)2.75 E F0
+(2, such as the ability to compile)2.75 E(shared libraries.)97 435.2 Q
+F1(BuildXInputExt)72 451.8 Q F0(Set to)97 464.8 Q F1(YES)2.75 E F0(to b)
+2.75 E(uild the X Input Extension.)-.22 E(This e)5.5 E
+(xtension requires de)-.165 E(vice-dependent support in the)-.275 E 2.75
+(Xs)97 477.8 S(erv)-2.75 E(er)-.165 E 2.75(,w)-.44 G(hich e)-2.75 E
+(xists only in)-.165 E F2(Xhp)2.75 E F0(in our implementation.)2.75 E F1
+(BuildP)72 494.4 Q(exExt)-.22 E F0(Set to)97 507.4 Q F1(NO)2.75 E F0
+(to not b)2.75 E(uild the PEX serv)-.22 E(er e)-.165 E
+(xtension and fonts.)-.165 E F1(DefaultUsrBin)72 524 Q F0
+(This is a directory where programs will be found e)97 537 Q -.165(ve)
+-.275 G 2.75(ni).165 G 2.75(fP)-2.75 G -1.221(AT)-3.762 G 2.75(Hi)1.221
+G 2.75(sn)-2.75 G(ot set in the en)-2.75 E 2.75(vironment. It)-.44 F(is)
+2.75 E(independent of ProjectRoot and def)97 550 Q(aults to)-.11 E F1
+(/usr/bin)2.75 E F0 5.5(.I)C 2.75(ti)-5.5 G 2.75(su)-2.75 G(sed, for e)
+-2.75 E(xample, when connecting from)-.165 E 2.75(ar)97 563 S
+(emote system via)-2.75 E F2 -.11(rs)2.75 G(h).11 E F0 5.5(.T)C(he)-5.5
+E F2 -.11(rs)2.75 G(tart).11 E F0(program installs its serv)2.75 E
+(er in this directory)-.165 E(.)-.715 E F1(InstallSer)72 579.6 Q -.11
+(ve)-.11 G(rSetUID).11 E F0(Some systems require the X serv)97 592.6 Q
+(er to run as root to access the de)-.165 E(vices it needs.)-.275 E
+(If you are on such a)5.5 E(system and will not be using)97 605.6 Q F2
+(xdm)2.75 E F0 2.75(,y)C(ou can set this v)-2.75 E(ariable to)-.275 E F1
+(YES)2.75 E F0(to install the X serv)2.75 E(er setuid to)-.165 E 2.75
+(root. Note)97 618.6 R(that the X serv)2.75 E
+(er has not been analyzed by the X Consortium for security in such an)
+-.165 E(installation; talk to your system manager before setting this v)
+97 631.6 Q(ariable.)-.275 E F1(InstallXdmCon\214g)72 648.2 Q F0(By def)
+97 661.2 Q
+(ault set to NO, which suppresses installing xdm con\214g \214les o)-.11
+E -.165(ve)-.165 G 2.75(re).165 G(xisting ones.)-2.915 E(Lea)5.5 E .33
+-.165(ve i)-.22 H 2.75(ts).165 G(et to)-2.75 E
+(NO if your site has customized the \214les in)97 674.2 Q F1
+(/usr/X11R6.3/lib/X11/xdm)2.75 E F0 2.75(,a)C 2.75(sm)-2.75 G(an)-2.75 E
+2.75(ys)-.165 G(ites do.)-2.75 E(If you)5.5 E(don')97 687.2 Q 2.75(ti)
+-.198 G(nstall the ne)-2.75 E 2.75<778c>-.275 G(les, mer)-2.75 E(ge an)
+-.198 E 2.75(yc)-.165 G(hanges present in the ne)-2.75 E 2.75<778c>-.275
+G(les.)-2.75 E F1(MotifBC)72 703.8 Q F0(Causes Xlib and Xt to w)97 716.8
+Q(ork around some b)-.11 E(ugs in older v)-.22 E(ersions of Motif.)-.165
+E(Set to)5.5 E F1(YES)2.75 E F0(only if you)2.75 E
+(will be linking with Motif v)97 729.8 Q(ersion 1.1.1, 1.1.2, or 1.1.3.)
+-.165 E(4)303.25 769 Q EP
+%%Page: 5 9
+%%BeginPageSetup
+BP
+%%EndPageSetup
+/F0 11/Times-Roman@0 SF 2.75(XV)72 49 S(ersion 11, Release 6.3 Snapshot)
+-3.971 E 2.75(XW)175.4 G(indo)-3.19 E 2.75(wS)-.275 G
+(ystem Installation)-2.75 E/F1 11/Times-Bold@0 SF(GetV)72 85 Q(aluesBC)
+-1.012 E F0(Setting this v)97 98 Q(ariable to)-.275 E F1(YES)2.75 E F0
+(allo)2.75 E(ws ille)-.275 E -.055(ga)-.165 G 2.75(lX).055 G(tGetV)-2.75
+E(alues requests with NULL Ar)-1.221 E(gV)-.198 E(al to usually suc-)
+-1.221 E(ceed, as R5 did.)97 111 Q
+(Some applications erroneously rely on this beha)5.5 E(vior)-.22 E 5.5
+(.S)-.605 G(upport for this will be)-5.5 E(remo)97 124 Q -.165(ve)-.165
+G 2.75(di).165 G 2.75(naf)-2.75 G(uture release.)-2.75 E(The follo)72
+140.6 Q(wing v)-.275 E(endor)-.165 E(-speci\214c)-.22 E F1(.cf)2.75 E F0
+(\214les are in the release b)2.75 E(ut ha)-.22 E .33 -.165(ve n)-.22 H
+(ot been tested recently and hence prob-).165 E(ably need changes to w)
+72 153.6 Q(ork:)-.11 E F1(apollo.cf)2.75 E F0(,)A F1(bsd.cf)2.75 E F0(,)
+A F1(con)2.75 E -.11(ve)-.44 G(x.cf).11 E F0(,)A F1(DGUX.cf)2.75 E F0(,)
+A F1(luna.cf)2.75 E F0(,)A F1(macII.cf)2.75 E F0(,)A F1(Mips.cf)2.75 E
+F0(,)A F1(moto.cf)2.75 E F0(,)A F1(Oki.cf)72 166.6 Q F0(,)A F1
+(pegasus.cf)2.75 E F0(,)A F1(x386.cf)2.75 E F0(.)A F1(Amoeba.cf)5.5 E F0
+(is kno)2.75 E(wn to require additional patches.)-.275 E(The \214le)72
+183.2 Q F1(xc/lib/Xdmcp/Wraphelp.c)2.75 E F0 2.75(,f)C(or XDM-A)-2.75 E
+(UTHORIZA)-.605 E(TION-1, is not included in this release.)-1.221 E F1
+2.75(2.6. System)72 222.2 R(Build Notes)2.75 E F0
+(This section contains hints on b)72 251.8 Q
+(uilding X with speci\214c compilers and operating systems.)-.22 E
+(If the b)72 268.4 Q(uild isn')-.22 E 2.75<748c>-.198 G
+(nding things right, mak)-2.75 E 2.75(es)-.11 G
+(ure you are using a compiler for your operating system.)-2.75 E -.165
+(Fo)5.5 G(r).165 E -.165(ex)72 281.4 S(ample, a pre-compiled).165 E/F2
+11/Times-Italic@0 SF(gcc)2.75 E F0(for a dif)2.75 E
+(ferent OS will not ha)-.275 E .33 -.165(ve r)-.22 H
+(ight symbols de\214ned, so).165 E F2(imak)2.75 E(e)-.11 E F0(will not)
+2.75 E -.11(wo)72 294.4 S(rk correctly).11 E(.)-.715 E F1 2.75
+(2.6.1. gcc)72 333.4 R F2(gcc)72 350 Q F0 -.165(ve)2.75 G
+(rsion 2 is in re).165 E
+(gular use at the X Consortium on Sparc platforms.)-.165 E(Set the v)5.5
+E(ariable)-.275 E F1(HasGcc2)2.75 E F0 5.5(.X)C(will)-2.75 E
+(not compile on some systems with)72 363 Q F2(gcc)2.75 E F0 -.165(ve)
+2.75 G
+(rsion 2.5, 2.5.1, or 2.5.2 because of an incorrect declaration of).165
+E(memmo)72 376 Q -.165(ve)-.165 G(\(\) in a gcc include \214le.).165 E
+(If you are using a)72 392.6 Q F2(gcc)2.75 E F0 -.165(ve)2.75 G
+(rsion older than 2.7 on Solaris x86, you need to specify).165 E F1(BOO)
+72 405.6 Q(TSTRAPCFLA)-.44 E(GS="\255Dsun")-.605 E F0(in the `)2.75 E
+(`mak)-.916 E 2.75(eW)-.11 G(orld')-3.63 E 2.75('c)-.916 G(ommand.)-2.75
+E F1 2.75(2.6.2. Other)72 444.6 R(GNU tools)2.75 E F0
+(Use of the GNU assembler)72 461.2 Q(,)-.44 E F2(as)2.75 E F0 2.75(,o)C
+2.75(rl)-2.75 G(ink)-2.75 E(er)-.11 E(,)-.44 E F2(ld)2.75 E F0 2.75(,i)C
+2.75(sn)-2.75 G(ot supported.)-2.75 E(GNU)5.5 E F2(mak)2.75 E(e)-.11 E
+F0(is not supported.)2.75 E F1 2.75(2.6.3. Spar)72 500.2 R(cW)-.198 E
+(orks 2.0)-.825 E F0(If you ha)72 529.8 Q .33 -.165(ve a n)-.22 H
+(on-threaded program and w).165 E(ant to deb)-.11 E
+(ug it with the old SparcW)-.22 E(orks 2.0 dbx, you will need)-.88 E
+(to use the thread stubs library in)72 542.8 Q F1
+(xc/util/misc/thr_stubs.c)2.75 E F0 5.5(.C)C(ompile it as follo)-5.5 E
+(ws:)-.275 E(cc -c thr_stubs.c)108 561.8 Q
+(ar cq libthr_stubs.a thr_stubs.o)108 574.8 Q(ranlib libthr_stubs.a)108
+587.8 Q(Install libthr_stubs.a in the same directory with your X librar\
+ies \(e.g.,)72 606.8 Q F1(/usr/X11R6.3/lib/libthr_stubs.a)2.75 E F0(\).)
+A(Add the follo)72 619.8 Q(wing line to)-.275 E F1(site.def)2.75 E F0(:)
+A(#de\214ne ExtraLibraries)108 638.8 Q(\255lsock)5.5 E 2.75(et \255lnsl)
+-.11 F($\(CDEB)2.75 E(UGFLA)-.11 E(GS:\255g=\255lthr_stubs\))-.44 E
+(This e)72 657.8 Q(xample uses a)-.165 E F2(mak)2.75 E(e)-.11 E F0
+(macro substitution; not all)2.75 E F2(mak)2.75 E(e)-.11 E F0
+(implementations support this feature.)2.75 E F1 2.75(2.6.4. CenterLine)
+72 696.8 R 2.75(Cu)2.75 G(nder Solaris 2)-2.75 E F0
+(If you are using the CenterLine C compiler to compile the distrib)72
+726.4 Q(ution under Solaris 2, place the)-.22 E(5)303.25 769 Q EP
+%%Page: 6 10
+%%BeginPageSetup
+BP
+%%EndPageSetup
+/F0 11/Times-Roman@0 SF 2.75(XW)72 49 S(indo)-3.19 E 2.75(wS)-.275 G
+(ystem Installation V)-2.75 E(ersion 11, Release 6.3 Snapshot)-1.221 E
+(follo)72 85 Q(wing line in your)-.275 E/F1 11/Times-Bold@0 SF(site.def)
+2.75 E F0(:)A(#de\214ne HasCenterLineC YES)108 104 Q
+(If clcc is not in your def)72 123 Q(ault search path, add this line to)
+-.11 E F1(site.def)2.75 E F0(:)A(#de\214ne CcCmd /path/to/your/clcc)108
+142 Q(If you are using CodeCenter 4.0.4 or earlier)72 164.6 Q 2.75(,t)
+-.44 G(he follo)-2.75 E(wing \214les trigger b)-.275 E(ugs in the)-.22 E
+/F2 11/Times-Italic@0 SF(clcc)2.75 E F0(optimizer:)2.75 E
+(xc/programs/Xserv)108 183.6 Q(er/cfb16/cfbgetsp.c)-.165 E
+(xc/programs/Xserv)108 196.6 Q(er/cfb16/cfb\214llsp.c)-.165 E
+(xc/programs/Xserv)108 209.6 Q(er/cfb/cfbgetsp.c)-.165 E(Thus to b)72
+232.2 Q(uild the serv)-.22 E(er)-.165 E 2.75(,y)-.44 G(ou will ha)-2.75
+E .33 -.165(ve t)-.22 H 2.75(oc).165 G
+(ompile these \214les by hand with the)-2.75 E F1<ad67>2.75 E F0
+(\215ag:)2.75 E 2.75(%c)108 251.2 S 2.75(dx)-2.75 G(c/programs/Xserv)
+-2.75 E(er/cfb16)-.165 E 2.75(%m)108 264.2 S(ak)-2.75 E 2.75(eC)-.11 G
+(DEB)-2.75 E(UGFLA)-.11 E(GS="\255g" cfbgetsp.o cfb\214llsp.o)-.44 E
+2.75(%c)108 277.2 S 2.75(d.)-2.75 G(./cfb)-2.75 E 2.75(%m)108 290.2 S
+(ak)-2.75 E 2.75(eC)-.11 G(DEB)-2.75 E(UGFLA)-.11 E
+(GS="\255g" cfbgetsp.o)-.44 E(This optimizer b)72 309.2 Q
+(ug appears to be \214x)-.22 E(ed in CodeCenter 4.0.6.)-.165 E F1 2.75
+(2.6.5. IBM)72 348.2 R(AIX 4.1.4)2.75 E F0(On AIX 4.1.4, the \214le)72
+377.8 Q F1(lib/f)2.75 E(ont/T)-.275 E(ype1/objects.c)-.814 E F0
+(must be compiled without optimization \()2.75 E F1<ad4f>A F0 2.75(\)e)C
+(lse the X)-2.75 E(serv)72 390.8 Q(er will e)-.165 E(xit when T)-.165 E
+(ype 1 fonts are used.)-.88 E F1 2.75(2.6.6. SunOS)72 429.8 R(4)2.75 E
+F0(SunOS 4.0 and earlier need BOO)72 459.4 Q(TSTRAPCFLA)-.44 E
+(GS=-DNOSTDHDRS because the)-.44 E 2.75(yd)-.165 G 2.75(on)-2.75 G
+(ot ha)-2.75 E .33 -.165(ve u)-.22 H(nistd.h).165 E(nor stdlib)72 472.4
+Q 2.75(.h. Do)-.44 F F2(not)2.75 E F0(supply a BOO)2.75 E(TSTRAPCFLA)
+-.44 E(GS when b)-.44 E(uilding an)-.22 E 2.75(yS)-.165 G(unOS 4.1 v)
+-2.75 E(ersion.)-.165 E F1 2.75(2.6.7. Micr)72 511.4 R(osoft W)-.198 E
+(indo)-.198 E(ws NT)-.11 E F0(All of the base libraries are supported, \
+including multi-threading in Xlib and Xt, b)72 541 Q
+(ut some of the more)-.22 E(complicated applications, speci\214cally)72
+554 Q F2(xterm)2.75 E F0(and)2.75 E F2(xdm)2.75 E F0 2.75(,a)C
+(re not supported.)-2.75 E(There are also some other rough edges in the\
+ implementation, such as lack of support for non-sock)72 570.6 Q
+(et \214le)-.11 E
+(descriptors as Xt alternate inputs and not using the re)72 583.6 Q
+(gistry for con\214gurable parameters lik)-.165 E 2.75(et)-.11 G
+(he system)-2.75 E(\214lenames and search paths.)72 596.6 Q(The)72 613.2
+Q F2(Xnest)2.75 E F0(serv)2.75 E(er has been made to run on NT)-.165 E
+5.5(.I)-.814 G 2.75(tr)-5.5 G(equires a real X serv)-2.75 E
+(er for output still.)-.165 E F1 2.75(2.6.8. Omr)72 652.2 R(on Luna)
+-.198 E F0(The Omron Luna platform is no longer supported.)72 681.8 Q
+(The Luna v)5.5 E(ersion of the)-.165 E F2(mak)2.75 E(e)-.11 E F0
+(program doesn')2.75 E 2.75(td)-.198 G(e\214ne)-2.75 E
+(the standard macro MAKE, so you must run it as `)72 694.8 Q(`mak)-.916
+E 2.75(eM)-.11 G(AKE=mak)-2.75 E(e')-.11 E 2.75('a)-.916 G 2.75(tt)-2.75
+G(op le)-2.75 E -.165(ve)-.275 G(l, e.g., `).165 E(`mak)-.916 E(e)-.11 E
+(MAKE=mak)72 707.8 Q 2.75(eW)-.11 G(orld')-3.63 E('.)-.916 E(6)303.25
+769 Q EP
+%%Page: 7 11
+%%BeginPageSetup
+BP
+%%EndPageSetup
+/F0 11/Times-Roman@0 SF 2.75(XV)72 49 S(ersion 11, Release 6.3 Snapshot)
+-3.971 E 2.75(XW)175.4 G(indo)-3.19 E 2.75(wS)-.275 G
+(ystem Installation)-2.75 E/F1 11/Times-Bold@0 SF 2.75(2.7. The)72 85 R
+(Build)2.75 E F0(On NT)72 114.6 Q 2.75(,t)-.814 G(ype)-2.75 E(nmak)108
+133.6 Q 2.75(eW)-.11 G(orld.W)-3.63 E(in32 > w)-.44 E(orld.log)-.11 E
+(On other systems, \214nd the BootstrapCFlags line, if an)72 152.6 Q
+1.43 -.715(y, i)-.165 H 2.75(nt).715 G(he v)-2.75 E(endor)-.165 E
+(-speci\214c)-.22 E F1(.cf)2.75 E F0 2.75(\214le. If)2.75 F(there isn')
+2.75 E 2.75(to)-.198 G(ne,)-2.75 E(type)72 165.6 Q 2.75(%m)108 184.6 S
+(ak)-2.75 E 2.75(eW)-.11 G(orld >& w)-3.63 E(orld.log)-.11 E
+(otherwise type)72 203.6 Q 2.75(%m)108 222.6 S(ak)-2.75 E 2.75(eW)-.11 G
+(orld BOO)-3.63 E(TSTRAPCFLA)-.44 E(GS="v)-.44 E(alue" >& w)-.275 E
+(orld.log)-.11 E -1.21(Yo)72 245.2 S 2.75(uc)1.21 G
+(an call the output \214le something other than `)-2.75 E(`w)-.916 E
+(orld.log')-.11 E(', b)-.916 E(ut do not call it `)-.22 E(`mak)-.916 E
+(e.log')-.11 E 2.75('b)-.916 G(ecause \214les)-2.75 E
+(with this name are automatically deleted during the `)72 258.2 Q
+(`cleaning')-.916 E 2.75('s)-.916 G(tage of the b)-2.75 E(uild.)-.22 E
+(Because the b)72 274.8 Q(uild can tak)-.22 E 2.75(es)-.11 G -2.365
+-.275(ev e)-2.75 H(ral hours to complete, you will probably w).275 E
+(ant to run it in the background)-.11 E(and k)72 287.8 Q(eep a w)-.11 E
+(atch on the output.)-.11 E -.165(Fo)5.5 G 2.75(re).165 G(xample:)-2.915
+E 2.75(%m)108 306.8 S(ak)-2.75 E 2.75(eW)-.11 G(orld >& w)-3.63 E
+(orld.log &)-.11 E 2.75(%t)108 319.8 S 2.75(ail \255f w)-2.75 F
+(orld.log)-.11 E
+(If something goes wrong, the easiest thing is to just start o)72 342.4
+Q -.165(ve)-.165 G 2.75(r\().165 G(typing `)-2.75 E(`mak)-.916 E 2.75
+(eW)-.11 G(orld')-3.63 E 2.75('a)-.916 G -.055(ga)-2.75 G(in\) once you)
+.055 E(ha)72 355.4 Q .33 -.165(ve c)-.22 H(orrected the problem.).165 E
+F1 2.75(2.8. Installing)72 394.4 R(X)2.75 E F0(If e)72 424 Q -.165(ve)
+-.275 G(rything is b).165 E(uilt successfully)-.22 E 2.75(,y)-.715 G
+(ou can install the softw)-2.75 E(are by typing the follo)-.11 E
+(wing as root:)-.275 E 2.75(%m)108 443 S(ak)-2.75 E 2.75(ei)-.11 G
+(nstall >& install.log)-2.75 E(Ag)72 465.6 Q(ain, you might w)-.055 E
+(ant to run this in the background and use)-.11 E/F2 11/Times-Italic@0
+SF(tail)2.75 E F0(to w)2.75 E(atch the progress.)-.11 E -1.21(Yo)72
+482.2 S 2.75(uc)1.21 G(an install the manual pages by typing the follo)
+-2.75 E(wing as root:)-.275 E 2.75(%m)108 501.2 S(ak)-2.75 E 2.75(ei)
+-.11 G(nstall.man >& man.log)-2.75 E F1 2.75(2.8.1. System)72 546.2 R
+(Installation Notes)2.75 E F0(This section contains hints on installing\
+ and using X with speci\214c compilers and operating systems.)72 575.8 Q
+F1 2.75(2.8.1.1. The)72 614.8 R 2.75(XS)2.75 G(er)-2.75 E -.11(ve)-.11 G
+2.75(ro).11 G 2.75(nA)-2.75 G(IX 4)-2.75 E F0 -.165(Fo)72 644.4 S 2.75
+(rI).165 G(BM')-2.75 E 2.75(sA)-.605 G(IX 4, you need to mak)-2.75 E
+2.75(es)-.11 G(ure the LFT de)-2.75 E
+(vice is associated with the correct graphics adapter)-.275 E(.)-.605 E
+(It')72 657.4 Q 2.75(sao)-.605 G(ne-time setup that does)-2.75 E F2(not)
+2.75 E F0(happen automatically)2.75 E 2.75(,e)-.715 G -.165(ve)-3.025 G
+2.75(ni).165 G 2.75(ft)-2.75 G(here')-2.75 E 2.75(so)-.605 G
+(nly one graphics adapter in the)-2.75 E 2.75(system. T)72 670.4 R 2.75
+(oc)-.88 G(on\214gure the LFT de)-2.75 E(vice properly)-.275 E 2.75(,b)
+-.715 G(ecome root and start SMIT)-2.75 E 5.5(.G)-.814 G 2.75(ot)-5.5 G
+2.75(ot)-2.75 G(he `)-2.75 E(`De)-.916 E(vices')-.275 E 2.75('c)-.916 G
+(ate-)-2.75 E(gory)72 683.4 Q 2.75(,c)-.715 G(hoose `)-2.75 E(`LFT')
+-.916 E(', then `)-.916 E(`Displays')-.916 E(', then `)-.916 E(`Mo)-.916
+E .33 -.165(ve t)-.165 H(he LFT to Another Display').165 E('.)-.916 E
+(Select `)72 700 Q(`Both')-.916 E 2.75('f)-.916 G
+(or when the change should tak)-2.75 E 2.75(ee)-.11 G -.275(ff)-2.75 G
+(ect, then select the display adapter where you w).275 E(ant to)-.11 E
+(run the X serv)72 713 Q(er)-.165 E 5.5(.C)-.605 G
+(on\214rm the changes and e)-5.5 E(xit SMIT)-.165 E 2.75(;f)-.605 G
+(rom no)-2.75 E 2.75(wo)-.275 G(n, you should be able to run the serv)
+-2.75 E(er)-.165 E(just \214ne.)72 726 Q(7)303.25 769 Q EP
+%%Page: 8 12
+%%BeginPageSetup
+BP
+%%EndPageSetup
+/F0 11/Times-Roman@0 SF 2.75(XW)72 49 S(indo)-3.19 E 2.75(wS)-.275 G
+(ystem Installation V)-2.75 E(ersion 11, Release 6.3 Snapshot)-1.221 E
+1.76 -.88(To r)72 85 T(un).88 E/F1 11/Times-Italic@0 SF(Xibm)2.75 E F0
+(from)2.75 E F1(xdm)2.75 E F0 2.75(,y)C(ou must pro)-2.75 E(vide the `)
+-.165 E(`\255force')-.916 E 2.75<278d>-.916 G(ag on the serv)-2.75 E
+(er command line in the)-.165 E/F2 11/Times-Bold@0 SF(Xser)2.75 E -.11
+(ve)-.11 G(rs).11 E F0(\214le.)72 98 Q F2 2.75(2.9. Shar)72 137 R
+(ed Libraries)-.198 E F0(The v)72 166.6 Q
+(ersion number of some of the the shared libraries has been changed.)
+-.165 E(On SunOS 4, which supports)5.5 E(minor v)72 179.6 Q
+(ersion numbers for shared libraries, programs link)-.165 E
+(ed with the R6 libraries will use the ne)-.11 E(w)-.275 E
+(libraries with no special action required.)72 192.6 Q
+(On other platforms you ha)5.5 E .33 -.165(ve t)-.22 H(he follo).165 E
+(wing choices:)-.275 E 14(1. K)72 209.2 R(eep the old v)-.275 E
+(ersions of the libraries around.)-.165 E 14(2. Relink)72 225.8 R
+(all applications with the ne)2.75 E 2.75(wl)-.275 G(ibraries.)-2.75 E
+14(3. Create)72 242.4 R 2.75(al)2.75 G(ink from the old name to the ne)
+-2.75 E 2.75(wn)-.275 G(ame.)-2.75 E -.165(Fo)97 259 S 2.75(re).165 G
+(xample, to ha)-2.915 E .33 -.165(ve p)-.22 H(rograms that were link)
+.165 E(ed ag)-.11 E(ainst libX11.so.6.0 use libX11.so.6.3, mak)-.055 E
+2.75(et)-.11 G(his)-2.75 E(link:)97 272 Q 2.75(ln \255s)133 291 R
+(libX11.so.6.3 libX11.so.6.0)2.75 E F2 2.75(2.10. Setting)72 336 R
+(Up xterm)2.75 E F0(If your)72 365.6 Q F2(/etc/termcap)2.75 E F0(and)
+2.75 E F2(/usr/lib/terminf)2.75 E(o)-.275 E F0(databases do not ha)2.75
+E .33 -.165(ve c)-.22 H(orrect entries for).165 E F1(xterm)2.75 E F0
+2.75(,u)C(se the sample)-2.75 E(entries pro)72 378.6 Q
+(vided in the directory)-.165 E F2(xc/pr)2.75 E(ograms/xterm/)-.198 E F0
+5.5(.S)C(ystem V users may need to compile and install)-5.5 E(the)72
+391.6 Q F2(terminf)2.75 E(o)-.275 E F0(entry with the)2.75 E F1(tic)2.75
+E F0(utility)2.75 E(.)-.715 E(Since each)72 408.2 Q F1(xterm)2.75 E F0(\
+will need a separate pseudoterminal, you need a reasonable number of th\
+em for normal)2.75 E -.165(exe)72 421.2 S 2.75(cution. Y).165 F
+(ou probably will w)-1.21 E
+(ant at least 32 on a small, multiuser system.)-.11 E
+(On most systems, each pty)5.5 E(has tw)72 434.2 Q 2.75(od)-.11 G -.275
+(ev)-2.75 G(ices, a master and a sla).275 E -.165(ve)-.22 G 2.75(,w).165
+G(hich are usually named /de)-2.75 E(v/tty[pqrstu][0-f] and)-.275 E(/de)
+72 447.2 Q 2.75(v/pty[pqrstu][0-f]. If)-.275 F(you don')2.75 E 2.75(th)
+-.198 G -2.475 -.22(av e)-2.75 H(at least the `)2.97 E(`p')-.916 E 2.75
+('a)-.916 G(nd `)-2.75 E(`q')-.916 E 2.75('s)-.916 G
+(ets con\214gured \(try typing `)-2.75 E(`ls)-.916 E(/de)72 460.2 Q
+(v/?ty??')-.275 E('\), you should ha)-.916 E .33 -.165(ve y)-.22 H
+(our system administrator add them.).165 E
+(This is commonly done by running)5.5 E(the)72 473.2 Q F1(MAKEDEV)2.75 E
+F0(script in the)2.75 E F2(/de)2.75 E(v)-.165 E F0
+(directory with appropriate ar)2.75 E(guments.)-.198 E F2 2.75
+(2.11. Starting)72 512.2 R(Ser)2.75 E -.11(ve)-.11 G(rs at System Boot)
+.11 E F0(The)72 541.8 Q F1(xfs)2.75 E F0(and)2.75 E F1(xdm)2.75 E F0
+(programs are designed to be run automatically at system startup.)2.75 E
+(Please read the manual)5.5 E(pages for details on setting up con\214gu\
+ration \214les; reasonable sample \214les are in)72 554.8 Q F2(xc/pr)72
+567.8 Q(ograms/xdm/con\214g/)-.198 E F0(and)2.75 E F2(xc/pr)2.75 E
+(ograms/xfs/)-.198 E F0(.)A F2 2.75(2.11.1. On)72 606.8 R
+(BSD-based systems using /etc/r)2.75 E(c)-.198 E F0
+(If your system uses an)72 636.4 Q F2(/etc/r)2.75 E(c)-.198 E F0(\214le\
+ at boot time, you can usually enable these programs by placing the fol\
+-)2.75 E(lo)72 649.4 Q(wing at or near the end of the \214le:)-.275 E
+(if [ \255f /usr/X11R6.3/bin/xfs ]; then)108 668.4 Q
+(/usr/X11R6.3/bin/xfs & echo \255n ' xfs')130 681.4 Q<8c>108 694.4 Q
+(if [ \255f /usr/X11R6.3/bin/xdm ]; then)108 720.4 Q(8)303.25 769 Q EP
+%%Page: 9 13
+%%BeginPageSetup
+BP
+%%EndPageSetup
+/F0 11/Times-Roman@0 SF 2.75(XV)72 49 S(ersion 11, Release 6.3 Snapshot)
+-3.971 E 2.75(XW)175.4 G(indo)-3.19 E 2.75(wS)-.275 G
+(ystem Installation)-2.75 E(/usr/X11R6.3/bin/xdm; echo \255n ' xdm')130
+85 Q<8c>108 98 Q(Since)72 120.6 Q/F1 11/Times-Italic@0 SF(xfs)2.75 E F0
+(can serv)2.75 E 2.75(ef)-.165 G(onts o)-2.75 E -.165(ve)-.165 G 2.75
+(rt).165 G(he netw)-2.75 E(ork, you do not need to run a font serv)-.11
+E(er on e)-.165 E -.165(ve)-.275 G(ry machine with an).165 E 2.75(Xd)72
+133.6 S(isplay)-2.75 E 5.5(.Y)-.715 G(ou should start)-6.71 E F1(xfs)
+2.75 E F0(before)2.75 E F1(xdm)2.75 E F0 2.75(,s)C(ince)-2.75 E F1(xdm)
+2.75 E F0(may start an X serv)2.75 E(er which is a client of the font)
+-.165 E(serv)72 146.6 Q(er)-.165 E(.)-.605 E(The e)72 163.2 Q
+(xamples here use)-.165 E/F2 11/Times-Bold@0 SF(/usr/X11R6.3/bin)2.75 E
+F0 2.75(,b)C(ut if you ha)-2.97 E .33 -.165(ve i)-.22 H
+(nstalled into a dif).165 E(ferent directory by setting \(or)-.275 E
+(unsetting\))72 176.2 Q F2(Pr)2.75 E(ojectRoot)-.198 E F0
+(then you need to substitute the correct directory)2.75 E(.)-.715 E
+(If you are unsure about ho)72 192.8 Q 2.75(ws)-.275 G(ystem boot w)
+-2.75 E(orks, or if your system does not use)-.11 E F2(/etc/r)2.75 E(c)
+-.198 E F0 2.75(,c)C(onsult your sys-)-2.75 E
+(tem administrator for help.)72 205.8 Q F2 2.75(2.11.2. On)72 244.8 R
+(SystemV)2.75 E(-based systems)-.814 E F0(There are tw)72 274.4 Q 2.75
+(ow)-.11 G(ays you can get On systems with a)-2.86 E F2(/etc/inittab)
+2.75 E F0(\214le, you can edit this \214le to add the lines)2.75 E
+(xfs:3:once:/usr/X11R6.3/bin/xfs)108 293.4 Q
+(xdm:3:once:/usr/X11R6.3/bin/xdm)108 306.4 Q(On some systems, you can e\
+dit a \214le in /etc/init.d to run the X Consortium xdm instead of the \
+v)72 329 Q(endor')-.165 E(s)-.605 E(product xdm.)72 342 Q(On Son)5.5 E
+2.75(yt)-.165 G(his \214le is /etc/init.d/consxdm.)-2.75 E
+(On IRIX edit /etc/init.d/xdm.)5.5 E F2 2.75(2.12. Using)72 381 R
+(OPEN LOOK applications)2.75 E F0 -1.21(Yo)72 410.6 S 2.75(uc)1.21 G
+(an use the X11R6 Xsun serv)-2.75 E(er with OPEN LOOK applications, b)
+-.165 E(ut you must pass the)-.22 E F2(\255swapLk)2.75 E(eys)-.11 E F0
+(\215ag to the serv)72 423.6 Q
+(er on startup, or the OPEN LOOK Undo, Cop)-.165 E 1.43 -.715(y, P)-.11
+H(aste, Find, and Cut k).55 E -.165(ey)-.11 G 2.75(sm).165 G(ay not w)
+-2.75 E(ork)-.11 E(correctly)72 436.6 Q 5.5(.F)-.715 G(or e)-5.665 E
+(xample, to run Sun')-.165 E 2.75(sO)-.605 G(penW)-2.75 E(indo)-.44 E
+(ws 3.3 desktop en)-.275 E(vironment with an X11R6 serv)-.44 E(er)-.165
+E 2.75(,u)-.44 G(se)-2.75 E(the command:)72 449.6 Q 2.75(%o)108 468.6 S
+2.75(penwin \255serv)-2.75 F 2.75(er /usr/X11R6.3/bin/Xsun \255sw)-.165
+F(apLk)-.11 E -.165(ey)-.11 G(s).165 E(The k)72 491.2 Q -.165(ey)-.11 G
+(syms reported by k).165 E -.165(ey)-.11 G 2.75(so).165 G 2.75(nt)-2.75
+G(he numeric k)-2.75 E -.165(ey)-.11 G(pad ha).165 E .33 -.165(ve a)-.22
+H(lso changed since X11R5; if you \214nd that).165 E(OpenW)72 504.2 Q
+(indo)-.44 E(ws applications do not respond to k)-.275 E -.165(ey)-.11 G
+(pad k).165 E -.165(ey)-.11 G 2.75(sa).165 G(nd cursor control k)-2.75 E
+-.165(ey)-.11 G 2.75(sw).165 G(hen using the R6)-2.75 E(serv)72 517.2 Q
+(er)-.165 E 2.75(,y)-.44 G(ou can remap the k)-2.75 E -.165(ey)-.11 G
+(pad to generate R5 style k).165 E -.165(ey)-.11 G(syms using the follo)
+.165 E(wing)-.275 E F1(xmodmap)2.75 E F0(commands:)2.75 E -.11(ke)108
+536.2 S(ysym P)-.055 E(ause = F21)-.165 E -.11(ke)108 549.2 S
+(ysym Print = F22)-.055 E -.11(ke)108 562.2 S(ysym Break = F23)-.055 E
+-.11(ke)108 575.2 S(ysym KP_Equal = F24)-.055 E -.11(ke)108 588.2 S
+(ysym KP_Di)-.055 E(vide = F25)-.275 E -.11(ke)108 601.2 S
+(ysym KP_Multiply = F26)-.055 E -.11(ke)108 614.2 S(ysym KP_Home = F27)
+-.055 E -.11(ke)108 627.2 S(ysym KP_Up = Up)-.055 E -.11(ke)108 640.2 S
+(ysym KP_Prior = F29)-.055 E -.11(ke)108 653.2 S(ysym KP_Left = Left)
+-.055 E -.11(ke)108 666.2 S(ycode 100 = F31)-.055 E -.11(ke)108 679.2 S
+(ysym KP_Right = Right)-.055 E -.11(ke)108 692.2 S(ysym KP_End = F33)
+-.055 E -.11(ke)108 705.2 S(ysym KP_Do)-.055 E(wn = Do)-.275 E(wn)-.275
+E -.11(ke)108 718.2 S(ysym KP_Ne)-.055 E(xt = F35)-.165 E -.11(ke)108
+731.2 S(ysym KP_Insert = Insert)-.055 E(9)303.25 769 Q EP
+%%Page: 10 14
+%%BeginPageSetup
+BP
+%%EndPageSetup
+/F0 11/Times-Roman@0 SF 2.75(XW)72 49 S(indo)-3.19 E 2.75(wS)-.275 G
+(ystem Installation V)-2.75 E(ersion 11, Release 6.3 Snapshot)-1.221 E
+-.11(ke)108 85 S(ysym KP_Delete = Delete)-.055 E/F1 11/Times-Bold@0 SF
+2.75(2.13. Reb)72 130 R(uilding after P)-.22 E(atches)-.11 E F0 -1.21
+(Yo)72 159.6 S 2.75(us)1.21 G(houldn')-2.75 E 2.75(tn)-.198 G
+(eed this right a)-2.75 E -.11(wa)-.165 G 1.43 -.715(y, b).11 H(ut e)
+.495 E -.165(ve)-.275 G(ntually you are probably going to mak).165 E
+2.75(ec)-.11 G(hanges to the sources,)-2.75 E(for e)72 172.6 Q
+(xample by applying an)-.165 E 2.75(yp)-.165 G
+(ublic patches that may be released.)-2.75 E(Each patch comes with e)72
+189.2 Q(xplicit instructions at the top of it saying what to do.)-.165 E
+(Thus the procedure here is)5.5 E(only an o)72 202.2 Q -.165(ve)-.165 G
+(rvie).165 E 2.75(wo)-.275 G 2.75(ft)-2.75 G
+(he types of commands that might be necessary to reb)-2.75 E
+(uild X after changing it.)-.22 E(If you are b)72 218.8 Q
+(uilding from CD-R)-.22 E
+(OM, apply the patches to the symbolic link tree.)-.44 E
+(The links to changed \214les)5.5 E
+(will be replaced with local \214les containing the ne)72 231.8 Q 2.75
+(wc)-.275 G(ontents.)-2.75 E
+(If only source \214les are changed, you should be able to reb)72 248.4
+Q(uild just by going to the)-.22 E F1(xc)2.75 E F0(directory in your)
+2.75 E -.22(bu)72 261.4 S(ild tree and typing:).22 E 2.75(%m)108 280.4 S
+(ak)-2.75 E 2.75(e>)-.11 G 2.75(&m)-2.75 G(ak)-2.75 E(e.log)-.11 E(If c\
+on\214guration \214les are changed, the safest thing to do is type:)72
+303 Q 2.75(%m)108 322 S(ak)-2.75 E 2.75(eE)-.11 G -.165(ve)-2.75 G
+(rything >& e).165 E -.165(ve)-.275 G(ry).165 E(.log)-.715 E -.916(``)72
+344.6 S(Ev).916 E(erything')-.165 E 2.75('i)-.916 G 2.75(ss)-2.75 G
+(imilar to `)-2.75 E(`W)-.916 E(orld')-.88 E 2.75('i)-.916 G 2.75(nt)
+-2.75 G(hat it reb)-2.75 E(uilds e)-.22 E -.165(ve)-.275 G(ry).165 E F1
+(Mak)2.75 E(e\214le)-.11 E F0 2.75(,b)C(ut unlik)-2.97 E 2.75(e`)-.11 G
+(`W)-3.666 E(orld')-.88 E 2.75('i)-.916 G 2.75(td)-2.75 G(oes not)-2.75
+E(delete the e)72 357.6 Q(xisting objects, libraries, and e)-.165 E
+-.165(xe)-.165 G(cutables, and only reb).165 E
+(uilds what is out of date.)-.22 E F1 2.75(2.14. F)72 396.6 R
+(ormatting the Documentation)-.275 E F0(The PostScript \214les in)72
+426.2 Q F1(xc/doc/hardcopy)2.75 E F0
+(can be generated from the sources in)2.75 E F1(xc/doc/specs)2.75 E F0
+5.5(.M)C(ost of the)-5.5 E(documentation is in trof)72 439.2 Q 2.75(fu)
+-.275 G(sing the)-2.75 E(\255ms macros.)4.583 E(The easiest w)5.5 E
+(ay to format it is to use the Imak)-.11 E(e\214les pro-)-.11 E(vided.)
+72 452.2 Q(Set the name of your local trof)72 468.8 Q 2.75(fp)-.275 G
+(rogram by setting the v)-2.75 E(ariable)-.275 E F1 -1.32 -.814(Tr o)
+2.75 H(ffCmd).814 E F0(in)2.75 E F1(xc/con\214g/cf/site.def)2.75 E F0
+5.5(.T)C(hen)-5.5 E -.22(bu)72 481.8 S(ild the Mak).22 E(e\214les:)-.11
+E(cd xc/doc)108 500.8 Q(mak)108 513.8 Q 2.75(eS)-.11 G(UBDIRS=specs Mak)
+-2.75 E(e\214les)-.11 E(Finally)72 536.4 Q 2.75(,g)-.715 G 2.75(ot)-2.75
+G 2.75(ot)-2.75 G(he directory you are interested in and type `)-2.75 E
+(`mak)-.916 E(e')-.11 E 2.75('t)-.916 G 2.75(here. This)-2.75 F
+(command will generate)2.75 E F1(.PS)2.75 E F0 2.75(\214les. Y)72 549.4
+R(ou can also generate te)-1.21 E
+(xt \214les by specifying the document name with a)-.165 E F1(.txt)2.75
+E F0 -.165(ex)2.75 G(tension as a).165 E/F2 11/Times-Italic@0 SF(mak)
+2.75 E(e)-.11 E F0(tar)72 562.4 Q(get, e.g., `)-.198 E(`mak)-.916 E 2.75
+(ei)-.11 G(cccm.txt')-2.75 E('.)-.916 E(10)300.5 769 Q EP
+%%Trailer
+end
+%%EOF
diff --git a/Xserver/INSTALL.TXT b/Xserver/INSTALL.TXT
new file mode 100644 (file)
index 0000000..786c88d
--- /dev/null
@@ -0,0 +1,749 @@
+
+
+
+
+
+
+
+
+
+             Building and Installing the X Window System
+
+
+
+
+
+
+
+
+                            Stephen Gildea
+
+                             X Consortium
+
+
+
+
+
+
+                            March 5, 1996
+
+                       Updated For Release 6.3
+
+
+
+
+
+
+
+
+
+
+Copyright c 1995, 1996 X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a
+copy of        this software and associated documentation files (the
+"Software"), to        deal in the Software without restriction, including
+without        limitation the rights to use, copy, modify, merge, publish, dis-
+tribute, sublicense, and/or sell copies        of the Software, and to permit
+persons        to whom the Software is furnished to do so, subject to the fol-
+lowing conditions:
+
+The above copyright notice and this permission notice shall be included
+in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS        PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES        OF MERCHANTABIL-
+ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT
+SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM,        DAMAGES OR OTHER LIABIL-
+ITY, WHETHER IN        AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION        WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+IN THE SOFTWARE.
+
+Except as contained in this notice, the        name of the X Consortium shall
+not be used in advertising or otherwise        to promote the sale, use or
+other dealings in this Software        without prior written authorization from
+the X Consortium.
+
+X Window System        is a trademark of X Consortium, Inc.
+
+
+1.  Easy Build Instructions
+
+This quick summary is no substitute for        reading the full build instruc-
+tions later in this document.
+
+Edit xc/config/cf/site.def for local preferences.  If you want to build
+with gcc uncomment the HasGcc2 line.  If you want to install somewhere
+other than /usr/X11R6.3, change        ProjectRoot.  (Do not use DESTDIR.)
+
+If any fixes have been released        by the X Consortium, stop here and fol-
+low the        instructions at the top of each patch, but don't do any of the
+make commands suggested        in the patches.  Then continue here.
+
+Check the appropriate vendor-specific .cf file in xc/config/cf/        to make
+sure that OSMajorVersion and OSMinorVersion are        set correctly for your
+system.         Override them in site.def if necessary.
+
+See if there is        a BootstrapCFlags mentioned in the comments in the
+vendor-specific        .cf file.  If there isn't one, cd to the xc directory
+and type:
+
+       % make World >& world.log
+
+
+If there is a BootstrapCFlags, take its        value and type:
+
+       % make World BOOTSTRAPCFLAGS="value" >& world.log
+
+
+Do not call the        output file "make.log" when doing "make World".  After a
+successful build, you can install with:
+
+       % make install >& install.log
+
+
+You can        install manual pages with:
+
+       % make install.man >& man.log
+
+
+While the system is building (or if things fail), read the rest        of these
+installation instructions.
+
+
+
+2.  Building X
+
+
+This document gives detailed instructions for building Release 6:  get-
+ting it        off the distribution medium, configuring, compiling, installing,
+running, and updating.
+
+Release        Notes are in xc/RELNOTES.* (various formats) in the distribu-
+tion.
+
+More recent information        about newly-discovered problems may be found in
+the Frequently Asked Questions posting appearing monthly on the
+comp.windows.x newsgroup and xpert mailing list.  It is        also available
+via anonymous FTP on ftp.x.org in the file contrib/faqs/FAQ.Z, or on
+your local X mirror site.
+
+
+2.1.  Preparing        the Site
+
+
+If you are unpacking tar files,        you will need about 130 Mb to hold the
+xc/ part.  To install requires 30-50 Mb        assuming you have shared
+libraries (80-100 Mb without). You will need an equivalent amount of
+extra space to build, since you        also need room for all the object files.
+
+Distributed as tar files, Release 6.3 core is divided into parts as fol-
+lows:
+
+
+       xc-1.tar       contains everything in xc/ that isn't in the other tar files
+       xc-2.tar       contains xc/fonts, xc/doc/specs, xc/util
+       xc-3.tar       contains xc/doc/hardcopy
+
+
+If you define BuildFonts to NO,        you only need to unpack xc-1.tar to
+build. If you build fonts, then you will also need xc-2.tar to build.
+
+
+2.2.  Unpacking        the Distribution
+
+
+The distribution normally comes        as multiple tar files, either on tape or
+across a network, or as        a CD-ROM.
+
+
+2.2.1. Unpacking a Compressed FTP Distribution
+
+
+If you have obtained compressed        tar files over the network, create a
+directory to hold the sources and cd into it:
+
+       mkdir sourcedir
+       cd sourcedir
+
+Then for each tar file xc-*.tar.Z, execute this:
+
+       zcat ftp-dir/xc-N.tar.Z | tar xf -
+
+
+
+2.2.2. Unpacking a gzipped FTP Distribution
+
+
+If you have obtained gzipped tar files over the        network, create a direc-
+tory to        hold the sources and cd into it:
+
+       mkdir sourcedir
+       cd sourcedir
+
+Then for each tar file xc-*.tar.gz, execute this:
+
+       gunzip -c ftp-dir/xc-N.tar.gz | tar xf -
+
+
+
+2.2.3. Unpacking a Split Compressed FTP Distribution
+
+
+If you have obtained compressed        and split tar files over the network,
+create a directory to hold the sources:
+
+       mkdir sourcedir
+
+Then for each directory        xc-*:
+
+       cd ftp-dir/xc-N
+       cat xc-N.?? | uncompress | (cd sourcedir; tar xf -)
+
+
+
+2.2.4. Unpacking the Tape Distribution
+
+
+If you have obtained a tape, create a directory        to hold the sources and
+untar everything into that directory:
+
+       mkdir sourcedir
+       cd sourcedir
+       tar xf tape-device
+
+
+
+2.2.5. Using the CD-ROM
+
+
+If you have obtained a CD-ROM, you don't have to do anything to        unpack
+it.  However, you will have to create a        symbolic link tree to build X.
+See the        next section.
+
+To mount the CD-ROM, see the mount(8) manual page on your system or the
+liner notes that came with the CD-ROM. Some systems, e.g., Solaris 2,
+can automatically mount        the CD-ROM for you.
+
+
+2.3.  Apply Patches
+
+
+If there are fixes released that are more recent than your distribution,
+apply them now.         Follow the instructions at the top of each patch, but
+don't do any make commands.  See the section "Public Patches" later in
+this document. Then continue here.
+
+
+2.4.  Symbolic Link Trees
+
+
+If you expect to build the distribution        on more than one machine using a
+shared source tree, or you are building        from CD-ROM, or you just want to
+keep the source        tree pure, you may want to use the program
+xc/config/util/lndir.c to create a symbolic link tree on each build
+machine.  The links may        use an additional 10 megabytes, but it is
+cheaper        than having multiple copies of the source tree.
+
+It may be tricky to compile lndir before the distribution is built.  If
+you have a copy        from a previous release, use that.  Makefile.ini can be
+used for building lndir        the first time.  You may have to specify
+OSFLAGS=-Dsomething to get it to compile.  What        you would pass as
+BOOTSTRAPCFLAGS        might work.  The command line looks something like this:
+
+       make -f Makefile.ini OSFLAGS=-Dflag
+
+
+To use a symbolic link tree, create a directory        for the build, cd to it,
+and type this:
+
+       lndir sourcedir
+
+
+where sourcedir        is the pathname of the directory where you stored the
+sources.  All of the build instructions        given below should then be done
+in the build directory on each machine,        rather than in the source direc-
+tory.
+
+xc/config/util/mkshadow/ contains mkshadow, an alternative program to
+lndir.
+
+
+2.5.  Configuration Parameters
+
+
+Build information for each source directory is in files        called
+Imakefile.  An Imakefile, along        with local configuration information in
+xc/config/cf/, is used by the program imake to generate        a Makefile.
+
+Most of        the configuration work prior to building the release is to set
+parameters so that imake will generate correct files.  Most of those
+parameters are set in xc/config/cf/site.def.  You will also need to
+check the appropriate vendor-specific .cf file in xc/config/cf/        to make
+sure that OSMajorVersion, OSMinorVersion, and OsTeenyVersion are set
+correctly for your system.  Override them in site.def if necessary.
+
+The site.def file has two parts, one protected with "#ifdef BeforeVen-
+dorCF" and one with "#ifdef AfterVendorCF".  The file is actually pro-
+cessed twice, once before the .cf file and once        after.  About the only
+thing you need to set in the "before" section is HasGcc2; just about
+everything else        can be set in the "after" section.
+
+The sample site.def also has commented out support to include another
+file, host.def.         This scheme may be useful if you want to set most
+parameters site-wide, but some parameters vary from machine to machine.
+If you use a symbolic link tree, you can share site.def        across all
+machines, and give each        machine its own copy of host.def.
+
+The config parameters are listed in xc/config/cf/README, but here are
+some of        the more common parameters that you may wish to set in site.def.
+
+ProjectRoot
+     The destination where X will be installed.         This variable needs to
+     be        set before you build, as some programs that read files at run-
+     time have the installation        directory compiled in to them.  Assuming
+     you have set the variable to some value /path, files will be
+     installed into /path/bin, /path/include/X11, /path/lib, and
+     /path/man.
+
+HasGccSet to YES to build with gcc version 1.
+
+HasGcc2
+     Set to YES        to build with gcc version 2.  Both this option and
+     HasGcc look for a compiler        named gcc, but HasGcc2 will cause the
+     build to use more features        of gcc 2, such as the ability to compile
+     shared libraries.
+
+BuildXInputExt
+     Set to YES        to build the X Input Extension.  This extension requires
+     device-dependent support in the X server, which exists only in Xhp
+     in        our implementation.
+
+BuildPexExt
+     Set to NO to not build the        PEX server extension and fonts.
+
+DefaultUsrBin
+     This is a directory where programs        will be found even if PATH is
+     not set in        the environment.  It is independent of ProjectRoot and
+     defaults to /usr/bin.  It is used,        for example, when connecting
+     from a remote system via rsh.  The        rstart program installs its
+     server in this directory.
+
+InstallServerSetUID
+     Some systems require the X        server to run as root to access the dev-
+     ices it needs.  If        you are on such a system and will not be using
+     xdm, you can set this variable to YES to install the X server
+     setuid to root.  Note that        the X server has not been analyzed by
+     the X Consortium for security in such an installation; talk to your
+     system manager before setting this        variable.
+
+InstallXdmConfig
+     By        default set to NO, which suppresses installing xdm config files
+     over existing ones.  Leave        it set to NO if your site has customized
+     the files in /usr/X11R6.3/lib/X11/xdm, as many sites do.  If you
+     don't install the new files, merge        any changes present in the new
+     files.
+
+MotifBC
+     Causes Xlib and Xt        to work around some bugs in older versions of
+     Motif.  Set to YES        only if you will be linking with Motif version
+     1.1.1, 1.1.2, or 1.1.3.
+
+GetValuesBC
+     Setting this variable to YES allows illegal XtGetValues requests
+     with NULL ArgVal to usually succeed, as R5        did.  Some applications
+     erroneously rely on this behavior.         Support for this will be
+     removed in        a future release.
+
+The following vendor-specific .cf files        are in the release but have not
+been tested recently and hence probably        need changes to work:
+apollo.cf, bsd.cf, convex.cf, DGUX.cf, luna.cf,        macII.cf, Mips.cf,
+moto.cf, Oki.cf, pegasus.cf, x386.cf.  Amoeba.cf is known to require
+additional patches.
+
+The file xc/lib/Xdmcp/Wraphelp.c, for XDM-AUTHORIZATION-1, is not
+included in this release.
+
+
+2.6.  System Build Notes
+
+
+This section contains hints on building        X with specific compilers and
+operating systems.
+
+If the build isn't finding things right, make sure you are using a com-
+piler for your operating system.  For example, a pre-compiled gcc for a
+different OS will not have right symbols defined, so imake will        not work
+correctly.
+
+
+2.6.1. gcc
+
+gcc version 2 is in regular use        at the X Consortium on Sparc platforms.
+Set the        variable HasGcc2.  X will not compile on some systems with gcc
+version        2.5, 2.5.1, or 2.5.2 because of an incorrect declaration of mem-
+move() in a gcc        include file.
+
+If you are using a gcc version older than 2.7 on Solaris x86, you need
+to specify BOOTSTRAPCFLAGS="-Dsun" in the "make        World" command.
+
+
+2.6.2. Other GNU tools
+
+Use of the GNU assembler, as, or linker, ld, is        not supported.  GNU make
+is not supported.
+
+
+2.6.3. SparcWorks 2.0
+
+
+If you have a non-threaded program and want to debug it        with the old
+SparcWorks 2.0 dbx, you        will need to use the thread stubs library in
+xc/util/misc/thr_stubs.c.  Compile it as follows:
+
+       cc -c thr_stubs.c
+       ar cq libthr_stubs.a thr_stubs.o
+       ranlib libthr_stubs.a
+
+Install        libthr_stubs.a in the same directory with your X libraries
+(e.g., /usr/X11R6.3/lib/libthr_stubs.a).  Add the following line to
+site.def:
+
+       #define ExtraLibraries -lsocket -lnsl $(CDEBUGFLAGS:-g=-lthr_stubs)
+
+This example uses a make macro substitution; not all make implementa-
+tions support this feature.
+
+
+2.6.4. CenterLine C under Solaris 2
+
+
+If you are using the CenterLine        C compiler to compile the distribution
+under Solaris 2, place the following line in your site.def:
+
+       #define HasCenterLineC YES
+
+If clcc        is not in your default search path, add this line to site.def:
+
+       #define CcCmd /path/to/your/clcc
+
+
+If you are using CodeCenter 4.0.4 or earlier, the following files
+trigger        bugs in the clcc optimizer:
+
+       xc/programs/Xserver/cfb16/cfbgetsp.c
+       xc/programs/Xserver/cfb16/cfbfillsp.c
+       xc/programs/Xserver/cfb/cfbgetsp.c
+
+
+Thus to        build the server, you will have to compile these files by hand
+with the -g flag:
+
+       % cd xc/programs/Xserver/cfb16
+       % make CDEBUGFLAGS="-g" cfbgetsp.o cfbfillsp.o
+       % cd ../cfb
+       % make CDEBUGFLAGS="-g" cfbgetsp.o
+
+This optimizer bug appears to be fixed in CodeCenter 4.0.6.
+
+
+2.6.5. IBM AIX 4.1.4
+
+
+On AIX 4.1.4, the file lib/font/Type1/objects.c        must be compiled without
+optimization (-O) else the X server will exit when Type        1 fonts are
+used.
+
+
+2.6.6. SunOS 4
+
+
+SunOS 4.0 and earlier need BOOTSTRAPCFLAGS=-DNOSTDHDRS because they do
+not have unistd.h nor stdlib.h.         Do not supply a BOOTSTRAPCFLAGS when
+building any SunOS 4.1 version.
+
+
+2.6.7. Microsoft Windows NT
+
+
+All of the base        libraries are supported, including multi-threading in
+Xlib and Xt, but some of the more complicated applications, specifically
+xterm and xdm, are not supported.
+
+There are also some other rough        edges in the implementation, such as
+lack of        support for non-socket file descriptors as Xt alternate inputs
+and not        using the registry for configurable parameters like the system
+filenames and search paths.
+
+The Xnest server has been made to run on NT.  It requires a real X
+server for output still.
+
+
+2.6.8. Omron Luna
+
+
+The Omron Luna platform        is no longer supported.  The Luna version of the
+make program doesn't define the        standard macro MAKE, so you must run it
+as "make MAKE=make" at top level, e.g.,        "make MAKE=make World".
+
+
+2.7.  The Build
+
+
+On NT, type
+
+       nmake World.Win32 > world.log
+
+On other systems, find the BootstrapCFlags line, if any, in the        vendor-
+specific .cf file.  If there isn't one,        type
+
+       % make World >& world.log
+
+otherwise type
+
+       % make World BOOTSTRAPCFLAGS="value" >& world.log
+
+
+You can        call the output file something other than "world.log", but do
+not call it "make.log" because files with this name are        automatically
+deleted        during the "cleaning" stage of the build.
+
+Because        the build can take several hours to complete, you will probably
+want to        run it in the background and keep a watch on the output.  For
+example:
+
+       % make World >& world.log &
+       % tail -f world.log
+
+
+If something goes wrong, the easiest thing is to just start over (typing
+"make World" again) once you have corrected the        problem.
+
+
+2.8.  Installing X
+
+
+If everything is built successfully, you can install the software by
+typing the following as        root:
+
+       % make install >& install.log
+
+
+Again, you might want to run this in the background and        use tail to
+watch the progress.
+
+You can        install the manual pages by typing the following as root:
+
+       % make install.man >& man.log
+
+
+
+2.8.1. System Installation Notes
+
+
+This section contains hints on installing and using X with specific com-
+pilers and operating systems.
+
+
+2.8.1.1.  The X        Server on AIX 4
+
+
+For IBM's AIX 4, you need to make sure the LFT device is associated with
+the correct graphics adapter.  It's a one-time setup that does not hap-
+pen automatically, even        if there's only one graphics adapter in the sys-
+tem.  To configure the LFT device properly, become root        and start SMIT.
+Go to the "Devices" category, choose "LFT", then "Displays", then "Move
+the LFT        to Another Display".
+
+Select "Both" for when the change should take effect, then select the
+display        adapter where you want to run the X server.  Confirm the changes
+and exit SMIT; from now        on, you should be able to run the server just
+fine.
+
+To run Xibm from xdm, you must provide the "-force" flag on the        server
+command        line in the Xservers file.
+
+
+2.9.  Shared Libraries
+
+
+The version number of some of the the shared libraries has been        changed.
+On SunOS 4, which supports minor version numbers for shared libraries,
+programs linked        with the R6 libraries will use the new libraries with no
+special        action required.  On other platforms you have the following
+choices:
+
+1.   Keep the old versions of the libraries around.
+
+2.   Relink all        applications with the new libraries.
+
+3.   Create a link from        the old name to the new name.
+
+     For example, to have programs that        were linked against
+     libX11.so.6.0 use libX11.so.6.3, make this        link:
+
+            ln -s libX11.so.6.3 libX11.so.6.0
+
+
+
+2.10.  Setting Up xterm
+
+
+If your        /etc/termcap and /usr/lib/terminfo databases do not have correct
+entries        for xterm, use the sample entries provided in the directory
+xc/programs/xterm/.  System V users may        need to compile and install the
+terminfo entry with the        tic utility.
+
+Since each xterm will need a separate pseudoterminal, you need a reason-
+able number of them for        normal execution.  You probably will want at
+least 32 on a small, multiuser system. On most systems, each pty has
+two devices, a master and a slave, which are usually named
+/dev/tty[pqrstu][0-f] and /dev/pty[pqrstu][0-f].  If you don't have at
+least the "p" and "q" sets configured (try typing "ls /dev/?ty??"), you
+should have your system        administrator add them.  This is commonly done
+by running the MAKEDEV script in the /dev directory with appropriate ar-
+guments.
+
+
+2.11.  Starting        Servers at System Boot
+
+
+The xfs        and xdm programs are designed to be run automatically at system
+startup.  Please read the manual pages for details on setting up confi-
+guration files;        reasonable sample files are in xc/programs/xdm/config/
+and xc/programs/xfs/.
+
+
+2.11.1.         On BSD-based systems using /etc/rc
+
+
+If your        system uses an /etc/rc file at boot time, you can usually enable
+these programs by placing the following        at or near the end of the file:
+
+       if [ -f /usr/X11R6.3/bin/xfs ]; then
+               /usr/X11R6.3/bin/xfs & echo -n ' xfs'
+       fi
+
+       if [ -f /usr/X11R6.3/bin/xdm ]; then
+               /usr/X11R6.3/bin/xdm; echo -n ' xdm'
+       fi
+
+
+Since xfs can serve fonts over the network, you        do not need to run a
+font server on every machine with an X display.         You should start xfs
+before xdm, since xdm may start        an X server which is a client of the
+font server.
+
+The examples here use /usr/X11R6.3/bin,        but if you have installed into a
+different directory by setting (or unsetting) ProjectRoot then you need
+to substitute the correct directory.
+
+If you are unsure about        how system boot works, or if your system does
+not use        /etc/rc, consult your system administrator for help.
+
+
+2.11.2.         On SystemV-based systems
+
+
+There are two ways you can get On systems with a /etc/inittab file, you
+can edit this file to add the lines
+
+       xfs:3:once:/usr/X11R6.3/bin/xfs
+       xdm:3:once:/usr/X11R6.3/bin/xdm
+
+
+On some        systems, you can edit a file in /etc/init.d to run the X Consor-
+tium xdm instead of the        vendor's product xdm.  On Sony this file is
+/etc/init.d/consxdm.  On IRIX edit /etc/init.d/xdm.
+
+
+2.12.  Using OPEN LOOK applications
+
+
+You can        use the X11R6 Xsun server with OPEN LOOK applications, but you
+must pass the -swapLkeys flag to the server on startup,        or the OPEN LOOK
+Undo, Copy, Paste, Find, and Cut keys may not work correctly.  For exam-
+ple, to        run Sun's OpenWindows 3.3 desktop environment with an X11R6
+server,        use the command:
+
+       % openwin -server /usr/X11R6.3/bin/Xsun -swapLkeys
+
+
+The keysyms reported by        keys on the numeric keypad have also changed
+since X11R5; if        you find that OpenWindows applications do not respond to
+keypad keys and        cursor control keys when using the R6 server, you can
+remap the keypad to generate R5        style keysyms using the following xmod-
+map commands:
+
+       keysym Pause = F21
+       keysym Print = F22
+       keysym Break = F23
+       keysym KP_Equal = F24
+       keysym KP_Divide = F25
+       keysym KP_Multiply = F26
+       keysym KP_Home = F27
+       keysym KP_Up = Up
+       keysym KP_Prior = F29
+       keysym KP_Left = Left
+       keycode 100 = F31
+       keysym KP_Right = Right
+       keysym KP_End = F33
+       keysym KP_Down = Down
+       keysym KP_Next = F35
+       keysym KP_Insert = Insert
+       keysym KP_Delete = Delete
+
+
+
+2.13.  Rebuilding after        Patches
+
+
+You shouldn't need this        right away, but eventually you are probably go-
+ing to make changes to the sources, for        example by applying any public
+patches        that may be released.
+
+Each patch comes with explicit instructions at the top of it saying what
+to do. Thus the procedure here is only an overview of the types of com-
+mands that might be necessary to rebuild X after changing it.
+
+If you are building from CD-ROM, apply the patches to the symbolic link
+tree.  The links to changed files will be replaced with        local files con-
+taining        the new contents.
+
+If only        source files are changed, you should be able to rebuild just by
+going to the xc        directory in your build tree and typing:
+
+       % make >& make.log
+
+
+If configuration files are changed, the        safest thing to do is type:
+
+       % make Everything >& every.log
+
+
+"Everything" is        similar to "World" in that it rebuilds every Makefile,
+but unlike "World" it does not delete the existing objects, libraries,
+and executables, and only rebuilds what        is out of date.
+
+
+2.14.  Formatting the Documentation
+
+
+The PostScript files in        xc/doc/hardcopy can be generated from the
+sources        in xc/doc/specs.  Most of the documentation is in troff using
+the -ms        macros.  The easiest way to format it is to use the Imakefiles
+provided.
+
+Set the        name of your local troff program by setting the variable
+TroffCmd in xc/config/cf/site.def.  Then build the Makefiles:
+
+       cd xc/doc
+       make SUBDIRS=specs Makefiles
+
+
+Finally, go to the directory you are interested        in and type "make"
+there. This command will generate .PS files.  You can also generate
+text files by specifying the document name with        a .txt extension as a
+make target, e.g., "make icccm.txt".
+
+
diff --git a/Xserver/Imakefile b/Xserver/Imakefile
new file mode 100644 (file)
index 0000000..35dbfe4
--- /dev/null
@@ -0,0 +1,203 @@
+XCOMM $XConsortium: Imakefile /main/137 1996/10/08 07:38:14 swick $
+XCOMM $XFree86: xc/Imakefile,v 3.11.2.2 1998/02/28 04:47:00 dawes Exp $
+#define IHaveSubdirs
+#define PassCDebugFlags CDEBUGFLAGS="$(CDEBUGFLAGS)"
+
+RELEASE = "Release 6.3"
+#ifndef OSName
+#define OSName Unknown Operating System!
+#endif
+
+#if !BuildServersOnly
+#if BuildFonts
+        FONTSDIR = fonts
+#endif
+#ifndef Win32Architecture
+        DOCSDIR = doc
+        NLSSUBDIR = nls
+#endif
+#endif
+
+        SUBDIRS = include config lib $(NLSSUBDIR) \
+                  programs $(FONTSDIR) $(DOCSDIR)
+  LNINSTALLDIRS = lib
+
+#if HasParallelMake
+#ifdef ParallelDefines
+        PARALLELOPTS = ParallelDefines
+#endif
+#endif
+
+MakeSubdirs($(SUBDIRS))
+
+MakeLintSubdirs($(LNINSTALLDIRS),install.ln,install.ln)
+
+MakeLintSubdirs($(LNINSTALLDIRS),external.ln,lintlib)
+
+DependSubdirs($(SUBDIRS))
+
+#define IHaveSpecialMakefileTarget
+
+#ifndef Win32Architecture
+#ifndef OS2Architecture
+VerifyOS::
+       @echo ""
+       @echo Building on OSName "("OSMajorVersion"."OSMinorVersion"."OSTeenyVersion")."
+       @echo ""
+#ifdef LinuxArchitecture
+       @echo libc version LinuxCLibMajorVersion"."LinuxCLibMinorVersion"."LinuxCLibTeenyVersion
+       @echo ""
+#endif
+
+includes::
+       MakeDir($(BUILDINCDIR))
+       MakeDir($(BUILDBINDIR))
+
+XCOMM
+XCOMM Watch out!!!  Make sure you do make includes after removing X11....
+XCOMM
+clean::
+       $(RM) -r $(BUILDINCDIR)
+       $(RM) -r $(BUILDLIBDIR)
+       $(RM) -r $(BUILDBINDIR)
+
+      MAKE_OPTS = -f xmakefile
+
+World::
+       $(MAKE) $(MFLAGS) $(MAKE_OPTS) $(PARALLELOPTS) all
+
+Everything::
+       @echo ""
+       @echo Rebuilding $(RELEASE) of the X Window System.
+       @echo ""
+       @date
+       @echo ""
+       cd $(IMAKESRC) && if [ -f Makefile ]; then \
+           $(MAKE) $(MFLAGS) BOOTSTRAPCFLAGS="$(BOOTSTRAPCFLAGS)"; \
+       else \
+           $(MAKE) $(MFLAGS) -f Makefile.ini BOOTSTRAPCFLAGS="$(BOOTSTRAPCFLAGS)"; \
+       fi
+       -$(RM) xmakefile.bak; $(MV) xmakefile xmakefile.bak
+       $(MAKE) $(MFLAGS) xmakefile
+       $(MAKE) $(MFLAGS) $(MAKE_OPTS) Makefiles
+       $(MAKE) $(MFLAGS) $(MAKE_OPTS) includes
+       $(MAKE) $(MFLAGS) $(MAKE_OPTS) depend
+       $(MAKE) $(MFLAGS) $(MAKE_OPTS) $(WORLDOPTS)
+       @echo ""
+       @date
+       @echo ""
+       @echo Rebuild of $(RELEASE) of the X Window System complete.
+       @echo ""
+
+XCOMM clean out link tree looking for stuff that should get checked in
+dangerous_strip_clean::
+       $(MAKE) -k clean
+       find . -type l -exec rm {} \;
+       find . \( \! \( -type d -o -name Makefile \) \) -print
+
+#else /* OS2Architecture */
+VerifyOS::
+       @echo :
+       @echo Building on OSName.
+       @echo :
+
+includes::
+       MakeDir($(subst /,\,$(BUILDINCDIR)))
+
+XCOMM
+XCOMM Watch out!!!  Make sure you do make includes after removing X11....
+XCOMM
+clean::
+       $(RM) -r $(BUILDINCDIR)
+       $(RM) -r $(BUILDLIBDIR)
+
+Everything::
+       @echo :
+       @echo Building $(RELEASE) of the X Window System on OS/2
+       @echo :
+       @echo :
+       \indir $(IMAKESRC) $(MAKE) $(MFLAGS) SHELL= -f Makefile.ini BOOTSTRAPCFLAGS=-Zexe
+       if exist Makefile.bak del Makefile.bak
+       if exist MAkefile ren Makefile Makefile.bak
+       $(MAKE) $(MFLAGS) -f Makefile.bak Makefile
+       $(MAKE) $(MFLAGS) SHELL= VerifyOS
+       $(MAKE) $(MFLAGS) SHELL= Makefiles
+       $(MAKE) $(MFLAGS) SHELL= clean
+       $(MAKE) $(MFLAGS) SHELL= includes
+       $(MAKE) $(MFLAGS) SHELL= depend
+       $(MAKE) $(MFLAGS)
+       @echo :
+       @echo :
+       @echo Rebuild of $(RELEASE) of the X Window System complete.
+       @echo :
+
+#ifdef ProjectRoot
+install::
+       MakeDir($(subst /,\,$(PROJECTROOT)))
+#endif
+
+install::
+       MakeDir($(subst /,\,$(INCROOT)))
+       MakeDir($(subst /,\,$(USRLIBDIR)))
+       MakeDir($(subst /,\,$(LIBDIR)))
+
+#endif
+#else /* not Win32Architecture else */
+VerifyOS::
+       @echo :
+       @echo Building on OSName.
+       @echo :
+
+includes::
+       MakeDir($(BUILDINCDIR:/=\))
+
+XCOMM
+XCOMM Watch out!!!  Make sure you do make includes after removing X11....
+XCOMM
+clean::
+       RmTreeCmd $(BUILDINCDIR:/=\)
+       RmTreeCmd $(BUILDLIBDIR:/=\)
+
+Everything::
+       @echo :
+       @echo Rebuilding $(RELEASE) of the X Window System.
+       @echo :
+       @echo :
+       cd $(IMAKESRC)
+       $(MAKE) $(MFLAGS) -f Makefile.ini imake.exe
+       cd ..\..
+       RMoveToBakFile(xmakefile)
+       $(MAKE) $(MFLAGS) xmakefile
+       $(MAKE) $(MFLAGS) $(MAKE_OPTS) Makefiles
+       $(MAKE) $(MFLAGS) $(MAKE_OPTS) includes
+       $(MAKE) $(MFLAGS) $(MAKE_OPTS) depend
+       $(MAKE) $(MFLAGS) $(MAKE_OPTS) $(WORLDOPTS)
+       @echo :
+       @echo :
+       @echo Rebuild of $(RELEASE) of the X Window System complete.
+       @echo :
+
+#ifdef ProjectRoot
+install::
+       MakeDir($(PROJECTROOT:/=\))
+#endif
+
+install::
+       MakeDir($(INCROOT:/=\))
+       MakeDir($(USRLIBDIR:/=\))
+       MakeDir($(LIBDIR:/=\))
+
+#endif /* not Win32Architecture else */
+
+XCOMM special target to determine if the xmakefile exists. 
+XCOMM Works on both Unix and NMAKE.EXE
+xmakefile-exists::
+
+
+#ifndef MakeManKeywords
+#define MakeManKeywords YES    /* install.man rebuilds "man -k" database? */
+#endif
+
+#undef BootstrapCleanSubdirs
+#define BootstrapCleanSubdirs BOOTSTRAPSUBDIRS="$(BOOTSTRAPSUBDIRS)"
+BOOTSTRAPSUBDIRS = imake makedepend
diff --git a/Xserver/LABEL b/Xserver/LABEL
new file mode 100644 (file)
index 0000000..a881e68
--- /dev/null
@@ -0,0 +1,128 @@
+                    X Window System, Version 11
+                            Release 6.3
+
+                       Portions Copyright by:
+
+                            X Consortium
+
+                                and
+                                  
+                             Mark Adler
+                     Adobe Systems Incorporated
+                          AGE Logic, Inc.
+                        Gerrit Jan Akkerman
+                           Corin Anderson
+                             Doug Anson
+                        Apollo Computer Inc.
+                        Ares Software Corp.
+                                ATI
+                             AT&T, Inc.
+                          Robert V. Baron
+                           David Bateman
+                          Bigelow & Holmes
+                          Bitstream, Inc.
+                             Jon Block
+                            Adam de Boor
+                           Manfred Brands
+                          Richard Burdick
+                          Cognition Corp.
+                          Simon P. Cooper
+                           Regis Cridlig
+                           Robin Cutshaw
+                          Daniver Limited
+                    Daewoo Electronics Co.,Ltd.
+                      Data General Corporation
+                            David Dawes
+                           Jorge Delgado
+                   Digital Equipment Corporation
+              Evans & Sutherland Computer Corporation
+                          Rickard E. Faith
+                            Erik Fortune
+                   Free Software Foundation, Inc.
+                          Joseph Friedman
+                        Fuji Xerox Co., Ltd.
+                          Fujitsu Limited
+                Fujitsu Open Systems Solutions, Inc.
+                          Jean-loup Gailly
+                             Tiago Gons
+                           Pascal Haible
+                          Harm Hanemaayer
+                            Randy Hendry
+                           Matthieu Herrb
+                      Hewlett-Packard Company
+                           Hitachi, Ltd.
+                           David Holland
+                           Philip Homburg
+                           Alan Hourihane
+                          IBM Corporation
+             The Institute of Software, Academia Sinica
+                  INTERACTIVE Systems Corporation
+                         Kaleb S. Keithley
+                             Jeff Kirk
+                       Marc Aurele La France
+                            Glenn G. Lai
+                            Scott Laird
+                           Thomas G. Lane
+                            Steven Lang
+                         Harry Langenbacher
+                          Patrick Lecoanet
+                            Sam Leffler
+                          Frederic Lepied
+                    Lexmark International, Inc.
+                         Sebastien Marineau
+                         Michael P. Marking
+                          Kevin E. Martin
+                            Davor Matic
+                          David McCullough
+                            David McKay
+                    MIPS Computer Systems, Inc.
+                              Joe Moss
+                           Thomas Mueller
+                            Rich Murphey
+                       NCR Corporation, Inc.
+                      Netscape Communications
+                  Network Computing Devices, Inc.
+                            Novell, Inc.
+                      NTT Software Corporation
+                     Number Nine Computer Corp.
+                            NVIDIA Corp.
+                            Erik Nygren
+                              Hans Oey
+                      Kazuyuki (ikko-) Okamoto
+                 Oki Technosystems Laboratory, Inc.
+                         OMRON Corporation
+                      Open Software Foundation
+                            Panacea Inc.
+                           Prentice Hall
+                     Quarterdeck Office Systems
+              Regents of the University of California
+                           Bill Reynolds
+                            Thomas Roell
+                   The Santa Cruz Operation, Inc.
+                          Dale Schumacher
+                           Paolo Severini
+                         ShoGraphics, Inc.
+              Silicon Graphics Computer Systems, Inc.
+                          Sony Corporation
+                                SRI
+                           Craig Struble
+                       Sun Microsystems, Inc.
+                           SunSoft, Inc.
+                          Tektronix, Inc.
+                          Finn Thoegersen
+                             Jon Tombs
+                           Linus Torvalds
+                           TOSHIBA Corp.
+                           Peter Trattler
+                           James Tsillas
+                       UniSoft Group Limited
+                   UNIX System Laboratories, Inc.
+                            Holger Veit
+                         Vrije Universiteit
+                             Larry Wall
+                         David E. Wexelblat
+                           Thomas Wolfram
+                           Henry A. Worth
+                       Wyse Technology, Inc.
+                     The XFree86 Project, Inc.
+                          Orest Zborowski
diff --git a/Xserver/Makefile b/Xserver/Makefile
new file mode 100644 (file)
index 0000000..35bbe68
--- /dev/null
@@ -0,0 +1,193 @@
+# $XConsortium: Makefile /main/36 1996/11/13 14:42:50 lehors $
+# $XFree86: xc/Makefile,v 3.6.2.2 1998/02/07 00:44:32 dawes Exp $
+
+# Luna users will need to either run make as "make MAKE=make"
+# or add "MAKE = make" to this file.
+
+RELEASE = "Release 6.3"
+SHELL = /bin/sh
+RM = rm -f
+MV = mv
+WORLDOPTS = -k
+WIN32WORLDOPTS = -i
+TOP = .
+CURRENT_DIR = .
+CONFIGSRC = $(TOP)/config
+IMAKESRC = $(CONFIGSRC)/imake
+DEPENDSRC = $(CONFIGSRC)/makedepend
+DEPENDTOP = ../..
+IMAKETOP = ../..
+IRULESRC = $(CONFIGSRC)/cf
+IMAKE = imake
+IMAKE_CMD = $(IMAKE) -I$(IRULESRC) $(IMAKE_DEFINES)
+MAKE_OPTS = -f xmakefile
+MAKE_CMD = $(MAKE) $(MAKE_OPTS)
+FLAGS = $(MFLAGS) -f Makefile.ini BOOTSTRAPCFLAGS="$(BOOTSTRAPCFLAGS)"
+
+all:
+       @$(MAKE_CMD) xmakefile-exists || $(MAKE) all-initial
+       @$(MAKE_CMD) $@
+
+all-initial:
+       @echo Please use make World, or on NT use nmake World.Win32.
+       @echo Check the configuration parameters in the $(IRULESRC) directory,
+       @echo and pass BOOTSTRAPCFLAGS if necessary.
+       @echo Read the release notes carefully before proceeding.
+       @echo Do not name your log file make.log or it will be deleted.
+
+World:
+       @echo ""
+       @echo Building $(RELEASE) of the X Window System.
+       @echo ""
+       @case "x$(BOOTSTRAPCFLAGS)" in x) \
+       echo I hope you checked the configuration parameters in $(IRULESRC) ; \
+       echo to see if you need to pass BOOTSTRAPCFLAGS. ; \
+       echo "" ; \
+       ;; esac;
+       @date
+       @echo ""
+       @if [ ! -f $(IRULESRC)/host.def ]; then \
+           if [ ! -f $(TOP)/lib/Xt/Imakefile ]; then \
+               echo "#define BuildServersOnly YES" > $(IRULESRC)/host.def; \
+           else \
+               if [ ! -f $(TOP)/fonts/Imakefile ]; then \
+                   echo "#define BuildFonts NO" > $(IRULESRC)/host.def; \
+               else \
+                   echo "" > $(IRULESRC)/host.def; \
+               fi \
+           fi \
+       fi
+       cd $(IMAKESRC) && $(MAKE) $(FLAGS) clean
+       $(MAKE) $(MFLAGS) Makefile.boot
+       $(MAKE_CMD) $(MFLAGS) VerifyOS
+       $(MAKE_CMD) $(MFLAGS) Makefiles
+       $(MAKE_CMD) $(MFLAGS) clean BOOTSTRAPSUBDIRS=
+       $(MAKE_CMD) $(MFLAGS) includes
+       $(MAKE_CMD) $(MFLAGS) depend
+       $(MAKE_CMD) $(MFLAGS) $(WORLDOPTS) World
+       @echo ""
+       @date
+       @echo ""
+       @echo Full build of $(RELEASE) of the X Window System complete.
+       @echo ""
+
+.PRECIOUS: Makefile
+
+# This is just a sequence of bootstrapping steps we have to do.
+# The steps are listed as separate targets so clearmake can wink in
+# the Makefile.proto files.
+Makefile.boot: imake.proto $(DEPENDSRC)/Makefile.proto depend.bootstrap $(IMAKESRC)/Makefile.proto imake.bootstrap
+
+imake.proto:
+       cd $(IMAKESRC) && $(MAKE) $(FLAGS)
+       $(RM) $(DEPENDSRC)/Makefile.proto
+
+$(DEPENDSRC)/Makefile.proto:
+       $(IMAKE_CMD) -s $(DEPENDSRC)/Makefile.proto -f $(DEPENDSRC)/Imakefile -DTOPDIR=$(DEPENDTOP) -DCURDIR=$(DEPENDSRC)
+
+depend.bootstrap:
+       cd $(DEPENDSRC) && $(RM) -r Makefile Makefile.dep makedepend *.o bootstrap
+       cd $(DEPENDSRC) && $(MAKE) -f Makefile.proto bootstrap
+
+$(IMAKESRC)/Makefile.proto:
+       $(IMAKE_CMD) -s $(IMAKESRC)/Makefile.proto -f $(IMAKESRC)/Imakefile -DTOPDIR=$(IMAKETOP) -DCURDIR=$(IMAKESRC)
+
+imake.bootstrap:
+       cd $(IMAKESRC) && $(MAKE) -f Makefile.proto bootstrapdepend
+       cd $(IMAKESRC) && $(MAKE) $(FLAGS) bootstrap
+       cd $(IMAKESRC) && $(MAKE) -f Makefile.proto all 
+       -@if [ -f xmakefile ]; then set -x; \
+         $(RM) xmakefile.bak; $(MV) xmakefile xmakefile.bak; \
+         else exit 0; fi
+       $(MAKE) $(MFLAGS) xmakefile
+
+Makefile::
+       $(MAKE) $(MFLAGS) xmakefile
+
+xmakefile: Imakefile
+       $(IMAKE_CMD) -s xmakefile -DTOPDIR=$(TOP) -DCURDIR=$(CURRENT_DIR)
+
+World.Win32:
+       @echo :
+       @echo Building $(RELEASE) of the X Window System.
+       @echo :
+       @echo :
+       -@if not exist $(IRULESRC)\host.def echo > $(IRULESRC)\host.def
+       cd $(IMAKESRC)
+       $(MAKE) -f Makefile.ini clean.Win32
+       $(MAKE) -f Makefile.ini imake.exe
+       cd ..\..
+       -if exist xmakefile.bak del xmakefile.bak
+       -if exist xmakefile ren xmakefile xmakefile.bak
+       $(IMAKE:/=\) -s xmakefile -I$(IRULESRC) $(IMAKE_DEFINES) -DTOPDIR=$(TOP) -DCURDIR=$(CURRENT_DIR)
+       $(MAKE_CMD) $(MFLAGS) VerifyOS
+       $(MAKE_CMD) $(MFLAGS) Makefiles
+       $(MAKE_CMD) $(MFLAGS) clean
+       cd $(CONFIGSRC)\util
+       $(MAKE) mkdirhier.exe
+       cd ..\..
+       $(MAKE_CMD) $(MFLAGS) includes
+       $(MAKE_CMD) $(MFLAGS) depend
+       $(MAKE_CMD) $(MFLAGS) $(WIN32WORLDOPTS)
+       @echo :
+       @echo :
+       @echo Full build of $(RELEASE) of the X Window System complete.
+       @echo :
+
+World.OS2:
+       @echo :
+       @echo Building $(RELEASE) of the X Window System on OS/2.
+       @echo :
+       @echo :
+       -@if not exist $(IRULESRC)\host.def echo > $(IRULESRC)\host.def
+       \indir $(IMAKESRC) $(MAKE) SHELL= -f Makefile.ini clean.os2
+       \indir $(IMAKESRC) $(MAKE) SHELL= CC=gcc -f Makefile.ini imake.os2
+       -if exist Makefile.bak del Makefile.bak
+       -if exist Makefile ren Makefile Makefile.bak
+       $(subst /,\,$(IMAKE)) -I$(IRULESRC) $(IMAKE_DEFINES) -DTOPDIR=$(TOP) -DCURDIR=$(CURRENT_DIR)
+       $(MAKE) $(MFLAGS) VerifyOS
+       $(MAKE) $(MFLAGS) Makefiles
+       $(MAKE) $(MFLAGS) clean
+       $(MAKE) $(MFLAGS) includes
+       $(MAKE) $(MFLAGS) depend
+       $(MAKE) $(MFLAGS)  
+       @echo :
+       @echo :
+       @echo Full build of $(RELEASE) of the X Window System complete.
+       @echo :
+
+# don't allow any default rules in this Makefile
+.SUFFIXES:
+# quiet "make" programs that display a message if suffix list empty
+.SUFFIXES: .Dummy
+
+# a copy of every rule that might be invoked at top level
+
+clean:
+           $(MAKE_CMD) $@
+dangerous_strip_clean:
+           $(MAKE_CMD) $@
+depend:
+           $(MAKE_CMD) $@
+Everything:
+           $(MAKE_CMD) $@
+external.ln:
+           $(MAKE_CMD) $@
+includes:
+           $(MAKE_CMD) $@
+install.linkkit:
+           $(MAKE_CMD) $@
+install.ln:
+           $(MAKE_CMD) $@
+install.man:
+           $(MAKE_CMD) $@
+install:
+           $(MAKE_CMD) $@
+Makefiles:
+           $(MAKE_CMD) $@
+man_keywords:
+           $(MAKE_CMD) $@
+tags:
+           $(MAKE_CMD) $@
+VerifyOS:
+           $(MAKE_CMD) $@
diff --git a/Xserver/README b/Xserver/README
new file mode 100644 (file)
index 0000000..d434942
--- /dev/null
@@ -0,0 +1,23 @@
+=======================
+Xvnc - the VNC X server
+=======================
+
+This is the top level directory for Xvnc, the VNC X server (or the X VNC
+server, depending on how you look at it).
+
+It is based on the XFree86 3.3.2 "server only" distribution, which in turn is
+based on the X11R6.3 distribution from the X consortium.
+
+To build Xvnc, simply do "make World" in this directory (make sure you have run
+./configure in the directory above this one first - this generates the file
+config/cf/vnclibs.def which is needed for the build).  If the build is
+successful, the binary will be left in programs/Xserver.
+
+If you have trouble building you may need to play around with the imake
+configuration files in the directory config/cf.  Read the X consortium files
+RELNOTES.TXT and INSTALL.TXT.  Also see the file config/cf/vnc.def for
+information specific to Xvnc.
+
+The code specific to the VNC X server is in programs/Xserver/hw/vnc.  The rest
+of the code is a cut-down version of the standard XFree86 distribution without
+many of the later X extensions or hardware-specific code.
diff --git a/Xserver/RELNOTES.PS b/Xserver/RELNOTES.PS
new file mode 100644 (file)
index 0000000..df6bf85
--- /dev/null
@@ -0,0 +1,1732 @@
+%!PS-Adobe-3.0
+%%Creator: groff version 1.09
+%%CreationDate: Sun Dec 22 21:51:06 1996
+%%DocumentNeededResources: font Times-Bold
+%%+ font Times-Italic
+%%+ font Times-Roman
+%%+ font Courier
+%%DocumentSuppliedResources: procset grops 1.09 0
+%%Pages: 24
+%%PageOrder: Ascend
+%%Orientation: Portrait
+%%EndComments
+%%BeginProlog
+%%BeginResource: procset grops 1.09 0
+/setpacking where{
+pop
+currentpacking
+true setpacking
+}if
+/grops 120 dict dup begin
+/SC 32 def
+/A/show load def
+/B{0 SC 3 -1 roll widthshow}bind def
+/C{0 exch ashow}bind def
+/D{0 exch 0 SC 5 2 roll awidthshow}bind def
+/E{0 rmoveto show}bind def
+/F{0 rmoveto 0 SC 3 -1 roll widthshow}bind def
+/G{0 rmoveto 0 exch ashow}bind def
+/H{0 rmoveto 0 exch 0 SC 5 2 roll awidthshow}bind def
+/I{0 exch rmoveto show}bind def
+/J{0 exch rmoveto 0 SC 3 -1 roll widthshow}bind def
+/K{0 exch rmoveto 0 exch ashow}bind def
+/L{0 exch rmoveto 0 exch 0 SC 5 2 roll awidthshow}bind def
+/M{rmoveto show}bind def
+/N{rmoveto 0 SC 3 -1 roll widthshow}bind def
+/O{rmoveto 0 exch ashow}bind def
+/P{rmoveto 0 exch 0 SC 5 2 roll awidthshow}bind def
+/Q{moveto show}bind def
+/R{moveto 0 SC 3 -1 roll widthshow}bind def
+/S{moveto 0 exch ashow}bind def
+/T{moveto 0 exch 0 SC 5 2 roll awidthshow}bind def
+/SF{
+findfont exch
+[exch dup 0 exch 0 exch neg 0 0]makefont
+dup setfont
+[exch/setfont cvx]cvx bind def
+}bind def
+/MF{
+findfont
+[5 2 roll
+0 3 1 roll 
+neg 0 0]makefont
+dup setfont
+[exch/setfont cvx]cvx bind def
+}bind def
+/level0 0 def
+/RES 0 def
+/PL 0 def
+/LS 0 def
+/PLG{
+gsave newpath clippath pathbbox grestore
+exch pop add exch pop
+}bind def
+/BP{
+/level0 save def
+1 setlinecap
+1 setlinejoin
+72 RES div dup scale
+LS{
+90 rotate
+}{
+0 PL translate
+}ifelse
+1 -1 scale
+}bind def
+/EP{
+level0 restore
+showpage
+}bind def
+/DA{
+newpath arcn stroke
+}bind def
+/SN{
+transform
+.25 sub exch .25 sub exch
+round .25 add exch round .25 add exch
+itransform
+}bind def
+/DL{
+SN
+moveto
+SN
+lineto stroke
+}bind def
+/DC{
+newpath 0 360 arc closepath
+}bind def
+/TM matrix def
+/DE{
+TM currentmatrix pop
+translate scale newpath 0 0 .5 0 360 arc closepath
+TM setmatrix
+}bind def
+/RC/rcurveto load def
+/RL/rlineto load def
+/ST/stroke load def
+/MT/moveto load def
+/CL/closepath load def
+/FL{
+currentgray exch setgray fill setgray
+}bind def
+/BL/fill load def
+/LW/setlinewidth load def
+/RE{
+findfont
+dup maxlength 1 index/FontName known not{1 add}if dict begin
+{
+1 index/FID ne{def}{ pop pop}ifelse
+}forall
+/Encoding exch def
+dup/FontName exch def
+currentdict end definefont pop
+}bind def
+/DEFS 0 def
+/EBEGIN{
+moveto
+DEFS begin
+}bind def
+/EEND/end load def
+/CNT 0 def
+/level1 0 def
+/PBEGIN{
+/level1 save def
+translate
+div 3 1 roll div exch scale
+neg exch neg exch translate
+0 setgray
+0 setlinecap
+1 setlinewidth
+0 setlinejoin
+10 setmiterlimit
+[] 0 setdash
+/setstrokeadjust where{
+pop
+false setstrokeadjust
+}if
+/setoverprint where{
+pop
+false setoverprint
+}if
+newpath
+/CNT countdictstack def
+userdict begin
+/showpage{} def
+}bind def
+/PEND{
+clear
+countdictstack CNT sub{end}repeat
+level1 restore
+}bind def
+end def
+/setpacking where{
+pop
+setpacking
+}if
+%%EndResource
+%%IncludeResource: font Times-Bold
+%%IncludeResource: font Times-Italic
+%%IncludeResource: font Times-Roman
+%%IncludeResource: font Courier
+grops begin/DEFS 1 dict def DEFS begin/u{.001 mul}bind def end/RES 72
+def/PL 792 def/LS false def/ENC0[/asciicircum/asciitilde/Scaron/Zcaron
+/scaron/zcaron/Ydieresis/trademark/quotesingle/.notdef/.notdef/.notdef
+/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef
+/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef
+/.notdef/.notdef/space/exclam/quotedbl/numbersign/dollar/percent
+/ampersand/quoteright/parenleft/parenright/asterisk/plus/comma/hyphen
+/period/slash/zero/one/two/three/four/five/six/seven/eight/nine/colon
+/semicolon/less/equal/greater/question/at/A/B/C/D/E/F/G/H/I/J/K/L/M/N/O
+/P/Q/R/S/T/U/V/W/X/Y/Z/bracketleft/backslash/bracketright/circumflex
+/underscore/quoteleft/a/b/c/d/e/f/g/h/i/j/k/l/m/n/o/p/q/r/s/t/u/v/w/x/y
+/z/braceleft/bar/braceright/tilde/.notdef/quotesinglbase/guillemotleft
+/guillemotright/bullet/florin/fraction/perthousand/dagger/daggerdbl
+/endash/emdash/ff/fi/fl/ffi/ffl/dotlessi/dotlessj/grave/hungarumlaut
+/dotaccent/breve/caron/ring/ogonek/quotedblleft/quotedblright/oe/lslash
+/quotedblbase/OE/Lslash/.notdef/exclamdown/cent/sterling/currency/yen
+/brokenbar/section/dieresis/copyright/ordfeminine/guilsinglleft
+/logicalnot/minus/registered/macron/degree/plusminus/twosuperior
+/threesuperior/acute/mu/paragraph/periodcentered/cedilla/onesuperior
+/ordmasculine/guilsinglright/onequarter/onehalf/threequarters
+/questiondown/Agrave/Aacute/Acircumflex/Atilde/Adieresis/Aring/AE
+/Ccedilla/Egrave/Eacute/Ecircumflex/Edieresis/Igrave/Iacute/Icircumflex
+/Idieresis/Eth/Ntilde/Ograve/Oacute/Ocircumflex/Otilde/Odieresis
+/multiply/Oslash/Ugrave/Uacute/Ucircumflex/Udieresis/Yacute/Thorn
+/germandbls/agrave/aacute/acircumflex/atilde/adieresis/aring/ae/ccedilla
+/egrave/eacute/ecircumflex/edieresis/igrave/iacute/icircumflex/idieresis
+/eth/ntilde/ograve/oacute/ocircumflex/otilde/odieresis/divide/oslash
+/ugrave/uacute/ucircumflex/udieresis/yacute/thorn/ydieresis]def
+/Courier@0 ENC0/Courier RE/Times-Roman@0 ENC0/Times-Roman RE
+/Times-Italic@0 ENC0/Times-Italic RE/Times-Bold@0 ENC0/Times-Bold RE
+%%EndProlog
+%%Page: title 1
+%%BeginPageSetup
+BP
+%%EndPageSetup
+/F0 15/Times-Bold@0 SF 3.75(XW)209.67 123 S(indo)-4.02 E 3.75(wS)-.15 G
+(ystem, V)-3.75 E(ersion 11)-1.5 E(Release 6.3)270.592 138 Q/F1 14
+/Times-Bold@0 SF(Release Notes)264.987 168 Q/F2 11/Times-Italic@0 SF
+2.75(XC)264.139 264 S(onsortium, Inc.)-2.75 E/F3 11/Times-Roman@0 SF
+(December 23, 1996)262.775 354 Q EP
+%%Page: copyr 2
+%%BeginPageSetup
+BP
+%%EndPageSetup
+/F0 11/Times-Roman@0 SF(Cop)72 192 Q(yright \251 1996 X Consortium)-.11
+E/F1 9/Times-Roman@0 SF(Permission is hereby granted, free of char)72
+206.6 Q(ge, to an)-.162 E 2.25(yp)-.135 G(erson obtaining a cop)-2.25 E
+2.25(yo)-.09 G 2.25(ft)-2.25 G(his softw)-2.25 E
+(are and associated documentation \214les)-.09 E(\(the `)72 217.6 Q
+(`Softw)-.75 E(are')-.09 E('\), to deal in the Softw)-.75 E(are without\
+ restriction, including without limitation the rights to use, cop)-.09 E
+1.17 -.585(y, m)-.09 H(odify).585 E 2.25(,m)-.585 G(er)-2.25 E(ge,)-.162
+E(publish, distrib)72 228.6 Q
+(ute, sublicense, and/or sell copies of the Softw)-.18 E
+(are, and to permit persons to whom the Softw)-.09 E
+(are is furnished to do)-.09 E(so, subject to the follo)72 239.6 Q
+(wing conditions:)-.225 E(The abo)72 254.2 Q .27 -.135(ve c)-.135 H(op)
+.135 E(yright notice and this permission notice shall be included in al\
+l copies or substantial portions of the Softw)-.09 E(are.)-.09 E
+(THE SOFTW)72 268.8 Q(ARE IS PR)-1.08 E -.45(OV)-.36 G(IDED `).45 E -.72
+(`A)-.75 G 2.25(SI).72 G(S')-2.25 E(', WITHOUT W)-.75 E
+(ARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUD-)-1.08 E(ING B)72 279.8
+Q(UT NO)-.09 E 2.25(TL)-.36 G(IMITED T)-2.25 E 2.25(OT)-.162 G(HE W)
+-2.25 E(ARRANTIES OF MERCHANT)-1.08 E(ABILITY)-.837 E 2.25(,F)-1.161 G
+(ITNESS FOR A P)-2.25 E(AR)-.828 E(TICULAR PURPOSE)-.54 E
+(AND NONINFRINGEMENT)72 290.8 Q 4.5(.I)-.666 G 2.25(NN)-4.5 G 2.25(OE)
+-2.25 G(VENT SHALL THE X CONSOR)-2.25 E(TIUM BE LIABLE FOR ANY CLAIM, D)
+-.54 E(AMA)-.36 E(GES)-.36 E(OR O)72 301.8 Q(THER LIABILITY)-.36 E 2.25
+(,W)-1.161 G(HETHER IN AN A)-2.25 E(CTION OF CONTRA)-.36 E(CT)-.36 E
+2.25(,T)-.666 G(OR)-2.412 E 2.25(TO)-.54 G 2.25(RO)-2.25 G(THER)-2.61 E
+(WISE, ARISING FR)-.495 E(OM, OUT OF)-.36 E
+(OR IN CONNECTION WITH THE SOFTW)72 312.8 Q(ARE OR THE USE OR O)-1.08 E
+(THER DEALINGS IN THE SOFTW)-.36 E(ARE.)-1.08 E(Except as contained in \
+this notice, the name of the X Consortium shall not be used in adv)72
+327.4 Q(ertising or otherwise to promote the)-.135 E
+(sale, use or other dealings in this Softw)72 338.4 Q
+(are without prior written authorization from the X Consortium.)-.09 E
+/F2 9/Times-Italic@0 SF 2.25(XW)72 353 S(indow System)-2.745 E F1
+(is a trademark of X Consortium, Inc.)2.25 E EP
+%%Page: i 3
+%%BeginPageSetup
+BP
+%%EndPageSetup
+/F0 13/Times-Bold@0 SF -1.196(Ta)257.126 85 S(ble of Contents)1.196 E/F1
+11/Times-Roman@0 SF(1. What Is Release 6.3)72 127.6 Q -2.75 11
+(......................... 1)8.772 H(1.1. Ov)72 144.2 Q(ervie)-.165 E
+2.75(wo)-.275 G 2.75(ft)-2.75 G(he X Consortium Release)-2.75 E -2.75 11
+(.................. 1)11.357 H(1.2. Supported Systems)72 160.8 Q -2.75
+11(......................... 2)3.855 H(1.2.1. Supported Display De)72
+177.4 Q 12.402(vices .)-.275 F -2.75 11(.................... 2)11 H
+(1.3. The XC T)72 194 Q .599(ree .)-.385 F -2.75 11
+(.......................... 2)11 H(1.4. X Re)72 210.6 Q 10.444(gistry .)
+-.165 F -2.75 11(.......................... 3)11 H
+(1.5. Extensions Supported)72 227.2 Q -2.75 11
+(........................ 3)6 H(1.6. Implementation P)72 243.8 Q 5.879
+(arameters .)-.165 F -2.75 11(..................... 3)11 H
+(2. What is Unchanged in Release 6.3)72 260.4 Q -2.75 11
+(.................... 5)13.975 H(3. What Is Ne)72 277 Q 2.75(wi)-.275 G
+2.75(nR)-2.75 G(elease 6.3)-2.75 E -2.75 11(...................... 5)
+15.471 H(3.1. OS Support)72 293.6 Q -2.75 11
+(........................... 5)9.355 H(3.2. Ne)72 310.2 Q 2.75(wS)-.275
+G 5.373(tandards .)-2.75 F -2.75 11(......................... 6)11 H
+(3.3. Lo)72 326.8 Q 2.75(wB)-.275 G(andwidth X Extension)-2.75 E -2.75
+11(..................... 6)15.141 H(3.4. RX: X Remote eXecution)72 343.4
+Q -2.75 11(...................... 6)15.79 H(3.4.1. Preparing Y)72 360 Q
+(our W)-1.21 E(eb Serv)-.88 E 11.654(er .)-.165 F -2.75 11
+(.................... 7)11 H(3.4.2. The RX Helper Program)72 376.6 Q
+-2.75 11(...................... 8)13.051 H(3.4.3. The RX Netscape Na)72
+393.2 Q(vig)-.22 E(ator Plug-in)-.055 E -2.75 11(................... 8)
+2.942 H(3.4.4. T)72 409.8 Q(rying Embedding W)-.385 E(ith an Old X Serv)
+-.44 E 5.791(er .)-.165 F -2.75 11(................ 9)11 H
+(3.4.5. Setting Up Y)72 426.4 Q(our Own Applications T)-1.21 E 2.75(oR)
+-.88 G(un Ov)-2.75 E(er The W)-.165 E 13.139(eb .)-.88 F -2.75 11
+(.......... 9)11 H(3.5. Security Extension)72 443 Q -8.25 11
+(......................... 1)5.087 H(0)-11 E
+(3.5.1. Untrusted Application Beha)72 459.6 Q 5.318(vior .)-.22 F -8.25
+11(................... 1)11 H(0)-11 E(3.5.1.1. Beha)72 476.2 Q
+(viors That Are Implementation-Dependent)-.22 E -8.25 11
+(.............. 1)12.985 H(0)-11 E(3.5.1.2. Beha)72 492.8 Q
+(viors That Are Not Lik)-.22 E(ely T)-.11 E 2.75(oC)-.88 G 5.406
+(hange .)-2.75 F -8.25 11(............... 1)11 H(1)-11 E
+(3.6. Application Group Extension)72 509.4 Q -8.25 11
+(..................... 1)13.953 H(1)-11 E(3.7. Print Extension)72 526 Q
+-8.25 11(.......................... 1)6.605 H(2)-11 E
+(3.7.1. Running an X Print Serv)72 542.6 Q 1.589(er .)-.165 F -8.25 11
+(..................... 1)11 H(2)-11 E(3.7.2. Specifying The Print Serv)
+72 559.2 Q(er T)-.165 E 2.75(oAC)-.88 G 10.114(lient .)-2.75 F -8.25 11
+(................ 1)11 H(3)-11 E(3.8. Proxy Management Protocol)72 575.8
+Q -8.25 11(...................... 1)3.261 H(3)-11 E
+(3.9. Con\214guration)72 592.4 Q -8.25 11(.......................... 1)
+13.634 H(3)-11 E(3.10. Documentation)72 609 Q -8.25 11
+(......................... 1)15.174 H(4)-11 E(3.11. Header Files)72
+625.6 Q -8.25 11(.......................... 1)13.348 H(4)-11 E
+(3.12. X Serv)72 642.2 Q 13.513(er .)-.165 F -8.25 11
+(.......................... 1)11 H(4)-11 E(3.12.1. Ne)72 658.8 Q 2.75
+(wD)-.275 G -.275(ev)-2.75 G(ice Support).275 E -8.25 11
+(....................... 1)10.543 H(4)-11 E(3.12.2. Internal Changes)72
+675.4 Q -8.25 11(........................ 1)13.656 H(4)-11 E
+(3.13. ICE Library Addition)72 692 Q -8.25 11(....................... 1)
+15.174 H(5)-11 E(3.14. Xlib V)72 708.6 Q(ertical Writing and User)-1.221
+E(-De\214ned Characters)-.22 E -8.25 11(.............. 1)10.554 H(5)-11
+E(3.15. Xt Geometry Management Deb)72 725.2 Q 12.677(ugger .)-.22 F
+-8.25 11(................. 1)11 H(5)-11 E(i)304.471 769 Q EP
+%%Page: ii 4
+%%BeginPageSetup
+BP
+%%EndPageSetup
+/F0 11/Times-Roman@0 SF 2.75(XW)72 49 S(indo)-3.19 E 2.75(wS)-.275 G
+(ystem Release Notes)-2.75 E 2.75(XV)205.364 G(ersion 11, Release 6.3)
+-3.971 E(3.16. Ne)72 85 Q 2.75(wP)-.275 G 1.094(rograms .)-2.75 F -8.25
+11(......................... 1)11 H(6)-11 E(3.16.1. Using The LBX Proxy)
+72 101.6 Q -8.25 11(...................... 1)16.087 H(6)-11 E
+(3.17. Major Additions to Existing Programs)72 118.2 Q -8.25 11
+(.................. 1)10.576 H(7)-11 E(3.18. ANSI\214cation)72 134.8 Q
+-8.25 11(.......................... 1)10.587 H(7)-11 E(4. Kno)72 151.4 Q
+(wn Bugs)-.275 E -8.25 11(........................... 1)11.775 H(8)-11 E
+(5. Filing Bug Reports)72 168 Q -8.25 11(......................... 1)
+12.402 H(8)-11 E(6. Ackno)72 184.6 Q 6.902(wledgements .)-.275 F -8.25
+11(........................ 1)11 H(8)-11 E(ii)302.942 769 Q EP
+%%Page: 1 5
+%%BeginPageSetup
+BP
+%%EndPageSetup
+/F0 11/Times-Bold@0 SF 2.75(1. What)72 85 R(Is Release 6.3)2.75 E/F1 11
+/Times-Roman@0 SF
+(This is the last X Consortium implementation of the X W)72 114.6 Q
+(indo)-.44 E 2.75(wS)-.275 G 2.75(ystem. X)-2.75 F(is a v)2.75 E(endor)
+-.165 E(-neutral, system-)-.22 E(architecture neutral netw)72 127.6 Q
+(ork-transparent windo)-.11 E 2.75(ws)-.275 G(ystem and user interf)
+-2.75 E(ace standard.)-.11 E 2.75(Xr)5.5 G(uns on a wide)-2.75 E
+(range of computing and graphics machines.)72 140.6 Q -.165(Fo)5.5 G
+2.75(ra).165 G 2.75(no)-2.75 G -.165(ve)-2.915 G(rvie).165 E 2.75(wo)
+-.275 G 2.75(fX)-2.75 G 2.75(,s)-2.75 G(ee the)-2.75 E/F2 11
+/Times-Italic@0 SF(X)2.75 E F1(manual page.)2.75 E
+(R6.3 is an update to R6.1.)72 157.2 Q
+(It is compatible with R6 and R6.1 at the source and protocol le)5.5 E
+-.165(ve)-.275 G(ls in all).165 E(respects, and binaries are upw)72
+170.2 Q(ard-compatible.)-.11 E(What about Release 6.2?)72 186.8 Q(Relea\
+se 6.2 is a proper subset of Release 6.3 produced at the request of the\
+ OSF)5.5 E(Common Desktop En)72 199.8 Q(vironment program.)-.44 E(It w)
+5.5 E(as produced by the X Consortium and is being released by)-.11 E
+(OSF simultaneously with CDE 2.1.)72 212.8 Q
+(Release 6.2 contains only the print e)5.5 E
+(xtension and the Xlib implemen-)-.165 E(tation of v)72 225.8 Q
+(ertical writing and user)-.165 E(-de\214ned character support.)-.22 E
+(The X Consortium w)72 242.4 Q(as an independent, not-for)-.11 E
+(-pro\214t membership corporation formed in 1993 as the suc-)-.22 E
+(cessor to the MIT X Consortium and dissolv)72 255.4 Q
+(ed at the end of 1996.)-.165 E(Refer to the)5.5 E F2(Consortium)2.75 E
+F1(man page for)2.75 E(additional details about the X Consortium.)72
+268.4 Q(See)72 285 Q F0(xc/INST)2.75 E(ALL.PS)-.99 E F1
+(\(PostScript\) or)2.75 E F0(xc/INST)2.75 E(ALL.TXT)-.99 E F1
+(\(plain te)2.75 E(xt\) for instructions on ho)-.165 E 2.75(wt)-.275 G
+2.75(ob)-2.75 G(uild and)-2.97 E(install this softw)72 298 Q(are.)-.11 E
+F0 2.75(1.1. Ov)72 337 R(er)-.11 E(view of the X Consortium Release)-.11
+E F1(The X Consortium softw)72 366.6 Q
+(are and documentation in Release 6.3 is in directory)-.11 E F0(xc/)2.75
+E F1(and contains the follo)2.75 E(w-)-.275 E(ing:)72 379.6 Q F0 2.75
+(XC)72 396.2 S(onsortium Standards)-2.75 E F1
+(The X Consortium produced standards:)97 409.2 Q
+(documents which de\214ne netw)5.5 E(ork protocols, programming)-.11 E
+(interf)97 422.2 Q(aces, and other aspects of the X en)-.11 E 2.75
+(vironment. See)-.44 F(the)2.75 E F2(XStandar)2.75 E(ds)-.407 E F1
+(manual page for a list of)2.75 E(standards.)97 435.2 Q F0
+(Implementations)72 451.8 Q F1 -.165(Fo)97 464.8 S 2.75(rm).165 G
+(ost of our standards, we pro)-2.75 E
+(vide high-quality implementations to demonstrate proof of con-)-.165 E
+(cept and to gi)97 477.8 Q .33 -.165(ve e)-.275 H(arly adopters and v)
+.165 E(endors a base to use.)-.165 E(These are not)5.5 E F2 -.407(re)
+2.75 G(fer).407 E(ence)-.407 E F1(implementations;)2.75 E
+(the written speci\214cations de\214ne the standards.)97 490.8 Q F0
+-.275(Fo)72 507.4 S(nts).275 E F1 2.75(Ac)97 520.4 S
+(ollection of bitmap and outline fonts are included in the distrib)-2.75
+E(ution, contrib)-.22 E(uted by v)-.22 E(arious indi-)-.275 E
+(viduals and companies.)97 533.4 Q F0(Utility Libraries)72 550 Q F1 2.75
+(An)97 563 S(umber of libraries, such as)-2.75 E F2(Xmu)2.75 E F1
+(and the)2.75 E F2(Athena W)2.75 E(idg)-.605 E(et Set)-.11 E F1 2.75(,a)
+C(re included.)-2.75 E(These are not stan-)5.5 E(dards, b)97 576 Q
+(ut are used in b)-.22 E
+(uilding X Consortium applications and may be useful in b)-.22 E
+(uilding other appli-)-.22 E(cations.)97 589 Q F0(Pr)72 605.6 Q(ograms)
+-.198 E F1 1.76 -.88(We a)97 618.6 T(lso pro).88 E
+(vide a number of application programs.)-.165 E 2.75(Af)5.5 G .55 -.275
+(ew o)-2.75 H 2.75(ft).275 G(hese programs, such as)-2.75 E F2(xdm)2.75
+E F1(\(or its)2.75 E(equi)97 631.6 Q -.275(va)-.275 G
+(lent\), should be considered essential in almost all en).275 E 2.75
+(vironments. The)-.44 F(rest of the applications)2.75 E
+(carry no special status; the)97 644.6 Q 2.75(ya)-.165 G
+(re simply programs that ha)-2.75 E .33 -.165(ve b)-.22 H(een de).165 E
+-.165(ve)-.275 G(loped and/or maintained by X).165 E(Consortium staf)97
+657.6 Q 2.75(f. In)-.275 F(some cases, you will \214nd better substitut\
+es for these programs contrib)2.75 E(uted by)-.22 E(others.)97 670.6 Q
+(1)303.25 769 Q EP
+%%Page: 2 6
+%%BeginPageSetup
+BP
+%%EndPageSetup
+/F0 11/Times-Roman@0 SF 2.75(XW)72 49 S(indo)-3.19 E 2.75(wS)-.275 G
+(ystem Release Notes)-2.75 E 2.75(XV)205.364 G(ersion 11, Release 6.3)
+-3.971 E/F1 11/Times-Bold@0 SF 2.75(1.2. Supported)72 85 R(Systems)2.75
+E F0 1.76 -.88(We b)72 114.6 T
+(uilt and tested this release on the follo).66 E(wing systems:)-.275 E
+(AIX 4.2)108 137.2 Q(Digital Unix 4.0A)108 150.2 Q(HP-UX 10.01)108 163.2
+Q(IRIX 6.2)108 176.2 Q(Solaris 2.5)108 189.2 Q
+(UNIX System V/386 Release 4.2 \(No)108 202.2 Q -.165(ve)-.165 G
+(ll UnixW).165 E(are\) V)-.88 E(ersion 2.02)-1.221 E 1.76 -.88(We a)72
+221.2 T(lso b).88 E(uilt this release on the follo)-.22 E
+(wing and did some minimal testing:)-.275 E(FreeBSD 2.1.6)108 240.2 Q
+(Linux 1.2.13 \(Yggdrasil\) and 2.0.0 \(Slackw)108 253.2 Q(are 3.1\))
+-.11 E(SCO Open Serv)108 266.2 Q(er 5.0)-.165 E(SunOS 4.1.4)108 279.2 Q
+-.44(Wi)108 292.2 S(ndo).44 E(ws NT 4.0)-.275 E(In all cases e)72 314.8
+Q(xcept SunOS we ha)-.165 E .33 -.165(ve u)-.22 H(sed the v).165 E
+(endor')-.165 E 2.75(sc)-.605 G(ompiler)-2.75 E 5.5(.O)-.605 G 2.75(nS)
+-5.5 G(unOS we b)-2.75 E(uild with)-.22 E/F2 11/Times-Italic@0 SF(gcc)
+2.75 E F0(.)A F1 2.75(1.2.1. Supported)72 353.8 R(Display De)2.75 E
+(vices)-.165 E F0(This release includes the necessary de)72 383.4 Q
+(vice-dependent support to b)-.275 E(uild a nati)-.22 E .33 -.165
+(ve X s)-.275 H(erv).165 E(er for the follo)-.165 E(wing)-.275 E
+(platforms:)72 396.4 Q(AIX: Xibm with Sk)108 419 Q(yw)-.165 E
+(ay display adapter)-.11 E(HP-UX: Xhp)108 432 Q
+(Digital Unix: Xdec on Alpha AXP with PMA)108 445 Q(G-B frame b)-.44 E
+(uf)-.22 E(fer)-.275 E
+(SunOS/Solaris: Xsun -- see the Xsun man page for supported frame b)108
+458 Q(uf)-.22 E(fers)-.275 E(Ultrix)108 471 Q/F3 7.7/Times-Roman@0 SF(1)
+-4.51 I F0(:Xdec)2.75 4.51 M
+(XFree86: See the XF_* man pages for supported video cards)108 484 Q
+(In addition to the abo)72 503 Q -.165(ve)-.165 G 2.75(,t).165 G
+(he Xvfb and Xnest serv)-2.75 E(ers can be b)-.165 E
+(uilt on most platforms.)-.22 E(Nati)72 519.6 Q .33 -.165(ve s)-.275 H
+(erv).165 E(ers are not b)-.165 E(uilt on IRIX or Microsoft W)-.22 E
+(indo)-.44 E(ws NT)-.275 E(.)-.814 E F1 2.75(1.3. The)72 558.6 R(XC T)
+2.75 E -.198(re)-.814 G(e).198 E F0(The general layout under)72 588.2 Q
+F1(xc/)2.75 E F0(is as follo)2.75 E(ws:)-.275 E .32 LW 144 698.2 72
+698.2 DL/F4 5.6/Times-Roman@0 SF(1)82 706.72 Q/F5 8/Times-Roman@0 SF(th\
+is is not a full ANSI C and POSIX platform and the full release will no\
+ longer b)2 3.28 M(uild here.)-.16 E(But we ha)4 E .24 -.12(ve n)-.16 H
+(ot intentionally remo).12 E -.12(ve)-.12 G 2(da).12 G .24 -.12(ny o)-2
+H(ld).12 E 2(support. I.e.)72 720 R/F6 8/Times-Italic@0 SF(no guar)2 E
+(antees)-.12 E F5 -.16(bu)2 G 2(tw).16 G 2(eh)-2 G(ope we')-2 E .24 -.12
+(ve l)-.4 H
+(eft open the possibility of someone else making the release w).12 E
+(ork ag)-.08 E(ain on Ultrix.)-.04 E F0(2)303.25 769 Q EP
+%%Page: 3 7
+%%BeginPageSetup
+BP
+%%EndPageSetup
+/F0 11/Times-Roman@0 SF 2.75(XV)72 49 S(ersion 11, Release 6.3)-3.971 E
+2.75(XW)205.364 G(indo)-3.19 E 2.75(wS)-.275 G(ystem Release Notes)-2.75
+E 110.692(con\214g/ con\214g)72 85 R(\214les,)2.75 E/F1 11
+/Times-Italic@0 SF(imak)2.75 E(e)-.11 E F0(,)A F1(mak)2.75 E(edepend)
+-.11 E F0 2.75(,b)C(uild utilities)-2.97 E 122.308(doc/ all)72 98 R
+(documentation other than per)2.75 E(-program manual pages)-.22 E
+116.192(fonts/ BDF)72 111 R 2.75(,S)-.88 G(peedo, T)-2.75 E(ype1 fonts)
+-.88 E 105.808(include/ include)72 124 R
+(\214les shared by multiple directories)2.75 E 126.576(lib/ all)72 137 R
+(libraries)2.75 E 125.355(nls/ national)72 150 R
+(language support \214les)2.75 E 96.645(programs/ all)72 163 R
+(programs, including the X serv)2.75 E(er and)-.165 E F1 -.407(rg)2.75 G
+(b).407 E F0(util/)72 176 Q F1(patc)126.268 E(h)-.165 E F0(,)A F1(compr)
+2.75 E(ess)-.407 E F0 2.75(,o)C(ther utilities)-2.75 E -.22(bu)72 189 S
+95.039(g-report b).22 F(ug reporting template)-.22 E(re)72 202 Q 107.81
+(gistry X)-.165 F(Re)2.75 E(gistry)-.165 E(This \214le is)72 224.6 Q/F2
+11/Times-Bold@0 SF(xc/RELNO)2.75 E(TES.*)-.44 E F0 2.75(,i)C 2.75(nv)
+-2.75 G(arious formats.)-3.025 E(The documentation source \214les)5.5 E
+F2(RELNO)2.75 E(TES.ms)-.44 E F0(and)2.75 E F2(INST)72 237.6 Q(ALL.ms)
+-.99 E F0(are in the)2.75 E F2(xc/doc/misc/)2.75 E F0(directory)2.75 E
+(.)-.715 E F2 2.75(1.4. X)72 276.6 R(Registry)2.75 E F0
+(The X Consortium maintained a re)72 306.2 Q
+(gistry of certain X-related items to aid in a)-.165 E -.22(vo)-.22 G
+(iding con\215icts and to aid).22 E(in sharing of such items.)72 319.2 Q
+(The re)72 335.8 Q(gistry is in the \214le)-.165 E F2(xc/r)2.75 E
+(egistry)-.198 E F0(in the distrib)2.75 E 2.75(ution. The)-.22 F
+(latest v)2.75 E(ersion may also be a)-.165 E -.275(va)-.22 G
+(ilable by send-).275 E(ing a message to xstuf)72 348.8 Q(f@x.or)-.275 E
+2.75(g. The)-.198 F(message can ha)2.75 E .33 -.165(ve a s)-.22 H
+(ubject line and no body).165 E 2.75(,o)-.715 G 2.75(ras)-2.75 G
+(ingle-line body)-2.75 E
+(and no subject; in either case the line should look lik)72 361.8 Q 2.75
+(et)-.11 G(his:)-2.75 E(send docs re)108 380.8 Q(gistry)-.165 E F2 2.75
+(1.5. Extensions)72 425.8 R(Supported)2.75 E F0(The core distrib)72
+455.4 Q(ution includes the follo)-.22 E(wing e)-.275 E
+(xtensions: BIG-REQ)-.165 E(UESTS, DOUBLE-B)-.11 E(UFFER, LBX,)-.11 E
+(MIT)72 468.4 Q(-SHM, MIT)-1.012 E(-SUNDR)-1.012 E -1.221(Y-)-.715 G
+(NONST)1.221 E(AND)-1.023 E(ARD, Multi-Buf)-.44 E
+(fering, RECORD, SECURITY)-.275 E 2.75(,S)-1.419 G(HAPE, SYNC,)-2.75 E
+(X3D-PEX, XC-APPGR)72 481.4 Q(OUP)-.44 E 2.75(,X)-1.221 G
+(C-MISC, XFree86-V)-2.75 E(idModeExtension, XIE, XInputExtension, XKEY)
+-.66 E(-)-1.221 E(BO)72 494.4 Q(ARD, XpExtension \(printing\), XTEST)
+-.385 E 2.75(,a)-.814 G(nd XT)-2.75 E(estExtension1.)-.77 E
+(Not all of these e)72 511 Q(xtensions are standards; see the)-.165 E F1
+(XStandar)2.75 E(ds)-.407 E F0(manual page.)2.75 E(Some of these e)5.5 E
+(xtensions are)-.165 E(not supported on all platforms.)72 524 Q F2 2.75
+(1.6. Implementation)72 563 R -.11(Pa)2.75 G(rameters).11 E F0
+(Some of the speci\214cations de\214ne some beha)72 592.6 Q
+(vior as implementation-dependent.)-.22 E(Implementations of X)5.5 E
+(Consortium standards need to document ho)72 605.6 Q 2.75(wt)-.275 G
+(hose parameters are implemented; this section does so.)-2.75 E
+(XFILESEARCHP)72 622.2 Q -1.221(AT)-1.012 G 2.75(Hd)1.221 G(ef)-2.75 E
+(ault)-.11 E(This def)97 635.2 Q(ault can be set at b)-.11 E
+(uild time by setting the)-.22 E F1(imak)2.75 E(e)-.11 E F0 -.275(va)
+2.75 G(riables XFileSearchP).275 E(athDef)-.165 E(ault,)-.11 E
+(XAppLoadDir)97 648.2 Q 2.75(,X)-.44 G(FileSearchP)-2.75 E
+(athBase, and ProjectRoot in)-.165 E F2(site.def)2.75 E F0 5.5(.S)C(ee)
+-5.5 E F2(xc/con\214g/cf/README)2.75 E F0(for)2.75 E(instructions and)97
+661.2 Q F2(xc/con\214g/cf/X11.tmpl)2.75 E/F3 7.7/Times-Roman@0 SF(2)
+-4.51 I F0(for details of ho)2.75 4.51 M 2.75(wt)-.275 G
+(hese con\214guration v)-2.75 E(ariables are used.)-.275 E(By def)97
+677.8 Q(ault ProjectRoot is /usr/X11R6.3 and XFILESEARCHP)-.11 E -1.221
+(AT)-1.012 G 2.75(Hh)1.221 G(as these components:)-2.75 E
+(/usr/X11R6.3/lib/X11/%L/%T/%N%C%S)133 696.8 Q
+(/usr/X11R6.3/lib/X11/%l/%T/%N%C%S)133 709.8 Q .32 LW 144 717.8 72 717.8
+DL/F4 5.6/Times-Roman@0 SF(2)82 726.32 Q/F5 8/Times-Roman@0 SF
+(This \214le w)2 3.28 M(as renamed from Project.tmpl in R6.1 in order t\
+o support multiple projects \(e.g. CDE/Motif\) in the same con\214g dir\
+ectory)-.08 E(.)-.52 E F0(3)303.25 769 Q EP
+%%Page: 4 8
+%%BeginPageSetup
+BP
+%%EndPageSetup
+/F0 11/Times-Roman@0 SF 2.75(XW)72 49 S(indo)-3.19 E 2.75(wS)-.275 G
+(ystem Release Notes)-2.75 E 2.75(XV)205.364 G(ersion 11, Release 6.3)
+-3.971 E(/usr/X11R6.3/lib/X11/%T/%N%C%S)133 85 Q
+(/usr/X11R6.3/lib/X11/%L/%T/%N%S)133 98 Q
+(/usr/X11R6.3/lib/X11/%l/%T/%N%S)133 111 Q(/usr/X11R6.3/lib/X11/%T/%N%S)
+133 124 Q(XUSERFILESEARCHP)72 146.6 Q -1.221(AT)-1.012 G 2.75(Hd)1.221 G
+(ef)-2.75 E(ault)-.11 E(If the en)97 159.6 Q(vironment v)-.44 E
+(ariable XAPPLRESDIR is de\214ned, the def)-.275 E(ault v)-.11 E
+(alue of XUSERFILESEARCH-)-.275 E -1.012(PA)97 172.6 S(TH has the follo)
+-.209 E(wing components:)-.275 E($XAPPLRESDIR/%L/%N%C)133 191.6 Q
+($XAPPLRESDIR/%l/%N%C)133 204.6 Q($XAPPLRESDIR/%N%C)133 217.6 Q
+($HOME/%N%C)133 230.6 Q($XAPPLRESDIR/%L/%N)133 243.6 Q
+($XAPPLRESDIR/%l/%N)133 256.6 Q($XAPPLRESDIR/%N)133 269.6 Q($HOME/%N)133
+282.6 Q(Otherwise it has these components:)97 301.6 Q($HOME/%L/%N%C)133
+320.6 Q($HOME/%l/%N%C)133 333.6 Q($HOME/%N%C)133 346.6 Q($HOME/%L/%N)133
+359.6 Q($HOME/%l/%N)133 372.6 Q($HOME/%N)133 385.6 Q(XKEYSYMDB def)72
+408.2 Q(ault)-.11 E(Def)97 421.2 Q(aults to)-.11 E/F1 11/Times-Bold@0 SF
+(/usr/X11R6.3/lib/X11/XK)2.75 E(eysymDB)-.275 E F0 2.75(,a)C(ssuming)
+-2.75 E F1(Pr)2.75 E(ojectRoot)-.198 E F0(is set to)2.75 E F1
+(/usr/X11R6.3)2.75 E F0(.)A(XCMSDB def)72 437.8 Q(ault)-.11 E(Def)97
+450.8 Q(aults to)-.11 E F1(/usr/X11R6.3/lib/X11/Xcms.txt)2.75 E F0 2.75
+(,a)C(ssuming)-2.75 E F1(Pr)2.75 E(ojectRoot)-.198 E F0(is set to)2.75 E
+F1(/usr/X11R6.3)2.75 E F0(.)A(XLOCALEDIR def)72 467.4 Q(ault)-.11 E(Def)
+97 480.4 Q(aults to the directory)-.11 E F1(/usr/X11R6.3/lib/X11/locale)
+2.75 E F0 2.75(,a)C(ssuming)-2.75 E F1(Pr)2.75 E(ojectRoot)-.198 E F0
+(is set to)2.75 E F1(/usr/X11R6.3)97 493.4 Q F0 5.5(.T)C
+(he XLOCALEDIR v)-5.5 E
+(ariable can contain multiple colon-separated pathnames.)-.275 E
+(XErrorDB location)72 510 Q(The Xlib error database \214le is)97 523 Q
+F1(/usr/X11R6.3/lib/X11/XErr)2.75 E(orDB)-.198 E F0 2.75(,a)C(ssuming)
+-2.75 E F1(Pr)2.75 E(ojectRoot)-.198 E F0(is set to)2.75 E F1
+(/usr/X11R6.3)97 536 Q F0(.)A(XtErrorDB location)72 552.6 Q
+(The Xt error database \214le is)97 565.6 Q F1
+(/usr/X11R6.3/lib/X11/XtErr)2.75 E(orDB)-.198 E F0 2.75(,a)C(ssuming)
+-2.75 E F1(Pr)2.75 E(ojectRoot)-.198 E F0(is set to)2.75 E F1
+(/usr/X11R6.3)97 578.6 Q F0(.)A(Supported Locales)72 595.2 Q 2.75(Xl)97
+608.2 S(ocales supported are in)-2.75 E F1(locale.dir)2.75 E F0 2.75(;t)
+C(he mapping between v)-2.75 E(arious system locale names and X)-.275 E
+(locale names is in)97 621.2 Q F1(locale.alias)2.75 E F0 5.5(.B)C
+(oth \214les are shipped in the)-5.5 E F1(xc/nls/X11/locale/)2.75 E F0
+(directory and)2.75 E(installed in the XLocaleDir directory \(e.g.)97
+634.2 Q F1(/usr/X11R6.3/lib/X11/locale/)2.75 E F0(\).)A
+(Input Methods supported)72 650.8 Q(The core distrib)97 663.8 Q
+(ution does not include an)-.22 E 2.75(yi)-.165 G(nput method serv)-2.75
+E 2.75(ers. Ho)-.165 F(we)-.275 E -.165(ve)-.275 G .88 -.44(r, X).165 H
+(lib supplies a def).44 E(ault)-.11 E -.22(bu)97 676.8 S
+(ilt-in input method that supports compose processing in 8-bit locales.)
+.22 E(Compose \214les are pro)5.5 E(vided)-.165 E
+(for Latin-1 and Latin-2.)97 689.8 Q(The b)5.5 E
+(uilt-in input method can support other locales, gi)-.22 E -.165(ve)
+-.275 G 2.75(ns).165 G(uitable com-)-2.75 E(pose \214les.)97 702.8 Q
+(See)5.5 E F1(xc/nls/X11/locale/Compose/iso8859-*)2.75 E F0
+(for the supported compositions.)2.75 E(There are input method serv)72
+719.4 Q(ers a)-.165 E -.275(va)-.22 G(ilable on the net.).275 E(4)303.25
+769 Q EP
+%%Page: 5 9
+%%BeginPageSetup
+BP
+%%EndPageSetup
+/F0 11/Times-Roman@0 SF 2.75(XV)72 49 S(ersion 11, Release 6.3)-3.971 E
+2.75(XW)205.364 G(indo)-3.19 E 2.75(wS)-.275 G(ystem Release Notes)-2.75
+E/F1 11/Times-Bold@0 SF 2.75(2. What)72 85 R
+(is Unchanged in Release 6.3)2.75 E F0(As this is an update release, th\
+ere is a great deal of stability in the standards, libraries, and clien\
+ts.)72 114.6 Q(No)5.5 E -.165(ex)72 127.6 S
+(isting standards other than the ICE library speci\214cation ha).165 E
+.33 -.165(ve c)-.22 H(hanged in a material w).165 E(ay)-.11 E 2.75(,t)
+-.715 G(hough se)-2.75 E -.165(ve)-.275 G(ral).165 E(documents ha)72
+140.6 Q .33 -.165(ve b)-.22 H(een updated with editorial impro).165 E
+-.165(ve)-.165 G 2.75(ments. There).165 F(is one ne)2.75 E 2.75(wi)-.275
+G(nterf)-2.75 E(ace added to the ICE)-.11 E(library)72 153.6 Q/F2 11
+/Times-Italic@0 SF(libICE)2.75 E F0 2.75(;s)C(ee belo)-2.75 E 4.18 -.715
+(w. T)-.275 H(he e).715 E(xtension library)-.165 E(,)-.715 E F2(libXe)
+2.75 E(xt)-.22 E F0 2.75(,i)C 2.75(su)-2.75 G
+(pdated to include the LBX, security)-2.75 E 2.75(,a)-.715 G(nd)-2.75 E
+(application group e)72 166.6 Q(xtension interf)-.165 E 2.75(aces. All)
+-.11 F(pre)2.75 E(vious interf)-.275 E
+(aces in these and all other libraries are)-.11 E(unchanged.)72 179.6 Q
+F1 2.75(3. What)72 231.6 R(Is New in Release 6.3)2.75 E F0
+(This section describes changes in the X Consortium distrib)72 261.2 Q
+(ution since Release 6.1.)-.22 E(All libraries, protocols, and serv)72
+277.8 Q(ers are compatible with Release 6 and Release 6.1.)-.165 E
+(That is, R6 and R6.1)5.5 E(clients and applications will w)72 290.8 Q
+(ork with R6.3 libraries and serv)-.11 E 2.75(ers. Most)-.165 F
+(R6.3 clients will w)2.75 E(ork with R6.1)-.11 E(and R6 libraries e)72
+303.8 Q(xcept those that use the ne)-.165 E 2.75(wi)-.275 G(nterf)-2.75
+E(aces in libICE, libXe)-.11 E(xt, and libXp.)-.165 E(The major ne)72
+320.4 Q 2.75(wf)-.275 G(unctionality in R6.3 is support for W)-2.75 E
+(orld W)-.88 E(ide W)-.44 E(eb inte)-.88 E
+(gration, protection of data from)-.165 E -.814(``)72 333.4 S
+(untrusted').814 E 2.75('c)-.814 G
+(lient connections, a bandwidth- and latenc)-2.75 E
+(y-optimized protocol for using X across the Inter)-.165 E(-)-.22 E
+(net, a print protocol follo)72 346.4 Q
+(wing the Xlib API, and support for v)-.275 E(ertical te)-.165 E
+(xt writing and user)-.165 E(-de\214ned charac-)-.22 E
+(ters in the Xlib implementation.)72 359.4 Q F1 2.75(3.1. OS)72 398.4 R
+(Support)2.75 E F0(The follo)72 428 Q(wing platforms ha)-.275 E .33
+-.165(ve a n)-.22 H -.275(ew).165 G(er operating system v).275 E
+(ersion supported:)-.165 E 72.855(System R6.1)72 450.6 R(R6.3)86.913 E
+85.703(AIX 4.1.4)72 476.6 R(4.2)86 E(Digital Unix)72 489.6 Q 84.163
+(3.2C 4.0A)52.692 F 71.645(HP-UX 10.01)72 502.6 R 82.645(IRIX 5.3)72
+515.6 R(6.2)94.25 E 74.692(Solaris 2.4)72 528.6 R(2.5)94.25 E(UnixW)72
+541.6 Q 60.315(are 2.02)-.88 F 1.76 -.88(We a)72 564.2 T(lso b).88 E
+(uilt on the follo)-.22 E(wing platforms, ho)-.275 E(we)-.275 E -.165
+(ve)-.275 G 2.75(rf).165 G(ull support is not guaranteed:)-2.75 E 72.855
+(System R6.1)72 586.8 R(R6.3)86.913 E 64.308(FreeBSD 2.1.0)72 612.8 R
+(2.1.6)86 E 78.971(Linux 1.2.13)72 625.8 R(2.0)80.5 E(SCO Open Serv)72
+638.8 Q 25.984(er 5.0)-.165 F 74.076(SunOS 4.1.3)72 651.8 R(4.1.4)86 E
+-.44(Wi)72 664.8 S(ndo).44 E(ws NT)-.275 E 91.5(3.5 4.0)49.139 F(5)
+303.25 769 Q EP
+%%Page: 6 10
+%%BeginPageSetup
+BP
+%%EndPageSetup
+/F0 11/Times-Roman@0 SF 2.75(XW)72 49 S(indo)-3.19 E 2.75(wS)-.275 G
+(ystem Release Notes)-2.75 E 2.75(XV)205.364 G(ersion 11, Release 6.3)
+-3.971 E/F1 11/Times-Bold@0 SF 2.75(3.2. New)72 85 R(Standards)2.75 E F0
+(The follo)72 114.6 Q(wing are ne)-.275 E 2.75(wXC)-.275 G
+(onsortium standards in Release 6.3.)-2.75 E(Each is described in its o)
+5.5 E(wn section)-.275 E(belo)72 127.6 Q -.715(w.)-.275 G(Lo)108 146.6 Q
+2.75(wB)-.275 G(andwidth X Extension)-2.75 E(RX: X Remote Ex)108 159.6 Q
+(ecution MIME type)-.165 E(Security Extension)108 172.6 Q
+(Application Group Extension)108 185.6 Q(Print Extension)108 198.6 Q
+(Proxy Management Protocol)108 211.6 Q F1 2.75(3.3. Lo)72 256.6 R 2.75
+(wB)-.11 G(and)-2.75 E(width X Extension)-.165 E F0(The Lo)72 286.2 Q
+2.75(wB)-.275 G(andwidth X e)-2.75 E(xtension \(LBX\) de\214nes se)-.165
+E -.165(ve)-.275 G(ral compression and local caching techniques to).165
+E(impro)72 299.2 Q .33 -.165(ve p)-.165 H(erformance on wide area netw)
+.165 E(orks and also on slo)-.11 E(wer)-.275 E(-speed connections.)-.22
+E(These reduce the)5.5 E(amount of protocol data transported o)72 312.2
+Q -.165(ve)-.165 G 2.75(rt).165 G(he netw)-2.75 E
+(ork and reduce the number of client-to-serv)-.11 E(er roundtrips)-.165
+E(required for common application startup operations.)72 325.2 Q(LBX w)
+72 341.8 Q(as referred to as X.f)-.11 E(ast in some materials b)-.11 E
+(ut we elected to not go through the implementation and)-.22 E
+(change all the names.)72 354.8 Q 1.76 -.88(To a)5.5 H -.22(vo).66 G
+(id an).22 E 2.75(yc)-.165 G(onfusion with an e)-2.75 E
+(xternal name dif)-.165 E(ferent from the internal name in)-.275 E
+(the implementation, we elected to drop the `)72 367.8 Q(`X.f)-.814 E
+(ast')-.11 E 2.75('m)-.814 G(onik)-2.75 E(er)-.11 E(.)-.605 E
+(LBX is implemented in tw)72 384.4 Q 2.75(op)-.11 G(ieces; an X serv)
+-2.75 E(er e)-.165 E(xtension and a proxy application.)-.165 E
+(The X serv)5.5 E(er e)-.165 E(xten-)-.165 E(sion pro)72 397.4 Q
+(vides the ne)-.165 E 2.75(wo)-.275 G(ptimized protocol.)-2.75 E
+(The proxy application,)5.5 E/F2 11/Times-Italic@0 SF(lbxpr)2.75 E(oxy)
+-.495 E F0 2.75(,t)C(ranslates a normal client X)-2.75 E
+(protocol stream into an LBX stream.)72 410.4 Q(This permits an)5.5 E
+2.75(ye)-.165 G(xisting application to g)-2.915 E
+(ain the bene\214t of the opti-)-.055 E(mized protocol with no changes.)
+72 423.4 Q
+(The proxy is especially useful when multiple applications are running)
+5.5 E(on the same local area netw)72 436.4 Q
+(ork separated from the X serv)-.11 E(er by a slo)-.165 E(wer netw)-.275
+E 2.75(ork. In)-.11 F(this case the full ben-)2.75 E(e\214t of the loca\
+l cache is shared by each application using the same proxy process.)72
+449.4 Q(The speci\214cation for LBX is in)72 466 Q F1
+(xc/doc/specs/Xext/lbx.mif)2.75 E F0(\(FrameMak)2.75 E
+(er interchange source\) and)-.11 E F1(xc/doc/hardcopy/Xext/lbx.PS.Z)72
+479 Q F0(\(compressed PostScript\).)2.75 E F1 2.75(3.4. RX:)72 518 R
+2.75(XR)2.75 G(emote eXecution)-2.75 E F0(The remote e)72 547.6 Q -.165
+(xe)-.165 G(cution \(RX\) service speci\214es a MIME format for in).165
+E -.22(vo)-.44 G(king applications remotely).22 E 2.75(,f)-.715 G(or)
+-2.75 E -.165(ex)72 560.6 S(ample via a W).165 E(orld W)-.88 E(ide W)
+-.44 E(eb bro)-.88 E(wser)-.275 E 5.5(.T)-.605 G
+(his RX format speci\214es a syntax for listing netw)-5.5 E
+(ork services)-.11 E(required by the application, for e)72 573.6 Q
+(xample an X display serv)-.165 E(er)-.165 E 5.5(.T)-.605 G
+(he requesting W)-5.5 E(eb bro)-.88 E(wser must identify)-.275 E
+(speci\214c instances of the services in the request to in)72 586.6 Q
+-.22(vo)-.44 G .22 -.11(ke t).22 H(he application.).11 E(The distrib)72
+603.2 Q(ution contains a helper program \()-.22 E F2(xrx)A F0 2.75(\)a)C
+(nd a Netscape Na)-2.75 E(vig)-.22 E(ator plug-in \()-.055 E F2(libxrx)A
+F0 2.75(\)t)C(hat demon-)-2.75 E(strate this protocol.)72 616.2 Q
+(The plug-in requires Na)5.5 E(vig)-.22 E(ator 3.0.)-.055 E 1.76 -.88
+(We h)72 632.8 T -2.475 -.22(av e).88 H(only been able to test the plug\
+-in on HP-UX, IRIX, Digital Unix, and Solaris2.)2.97 E(Netscape Na)5.5 E
+(vi-)-.22 E -.055(ga)72 645.8 S
+(tor binaries for other platforms are either not a).055 E -.275(va)-.22
+G(ilable at all or were not a).275 E -.275(va)-.22 G
+(ilable in time to be included).275 E(in the testing for this release.)
+72 658.8 Q(The speci\214cation for the RX mime type is in)72 675.4 Q F1
+(xc/doc/specs/RX/RX.mif)2.75 E F0(\(FrameMak)2.75 E
+(er interchange source\))-.11 E(and)72 688.4 Q F1
+(xc/doc/hardcopy/RX/RX.PS.Z)2.75 E F0(\(compressed PostScript\).)2.75 E
+(The follo)72 705 Q
+(wing section describes the procedure to set up your en)-.275 E
+(vironment and try the e)-.44 E(xamples pro)-.165 E(vided)-.165 E
+(in this distrib)72 718 Q(ution.)-.22 E(6)303.25 769 Q EP
+%%Page: 7 11
+%%BeginPageSetup
+BP
+%%EndPageSetup
+/F0 11/Times-Roman@0 SF 2.75(XV)72 49 S(ersion 11, Release 6.3)-3.971 E
+2.75(XW)205.364 G(indo)-3.19 E 2.75(wS)-.275 G(ystem Release Notes)-2.75
+E/F1 11/Times-Bold@0 SF 2.75(3.4.1. Pr)72 85 R(eparing Y)-.198 E(our W)
+-1.221 E(eb Ser)-.715 E -.11(ve)-.11 G(r).11 E F0(In order to demonstra\
+te the RX helper program and the RX Netscape plug-in you need to ha)72
+114.6 Q .33 -.165(ve a)-.22 H(ccess to).165 E(an HTTP serv)72 127.6 Q
+(er to install `)-.165 E(`common g)-.814 E(ate)-.055 E -.11(wa)-.275 G
+2.75(yi).11 G(nterf)-2.75 E(ace')-.11 E 2.75('\()-.814 G(CGI\) scripts.)
+-2.75 E(While CGI programs can be writ-)5.5 E(ten in an)72 140.6 Q 2.75
+(yc)-.165 G(ompiled or interpreted language, the sample CGI programs in\
+ the distrib)-2.75 E(ution are written in)-.22 E(perl.)72 153.6 Q
+(If you don')72 170.2 Q 2.75(tc)-.198 G(urrently ha)-2.75 E .33 -.165
+(ve a w)-.22 H(eb serv).165 E(er the NCSA serv)-.165 E
+(er is a good one to try)-.165 E 5.5(.B)-.715 G(inaries for v)-5.5 E
+(arious sys-)-.275 E(tems are a)72 183.2 Q -.275(va)-.22 G(ilable at:)
+.275 E(http://hoohoo.ncsa.uiuc.edu/docs/setup/PreEx)108 200.2 Q(ec.html)
+-.165 E(If you don')72 216.8 Q 2.75(th)-.198 G -2.475 -.22(av e)-2.75 H
+(perl you can get the source code from:)2.97 E
+(ftp://prep.ai.mit.edu/pub/gnu/perl-4.036.tar)108 233.8 Q(.gz)-.605 E
+-1.21(Yo)72 250.4 S 2.75(un)1.21 G
+(eed to install the HTML, RX, and CGI sample \214les into your serv)
+-2.75 E(er')-.165 E 2.75(sH)-.605 G(TML and CGI directories.)-2.75 E
+(The process can be partially automated by adding the follo)72 263.4 Q
+(wing de\214nitions to your)-.275 E F1(site.def)2.75 E F0(or)2.75 E F1
+(host.def)2.75 E F0(\214le:)72 276.4 Q -.88(We)72 306 S(bServ).88 E
+31.317(er de\214nes)-.165 F(the hostname and port of your web serv)2.75
+E(er)-.165 E 2.75(,f)-.44 G(or e)-2.75 E(xample)-.165 E/F2 11/Courier@0
+SF(#define WebServer www.myorg.org:8001)180 323 Q F0 42.471
+(HtmlDir de\214nes)72 345.6 R
+(the path at which HTML and RX documents are installed, for e)2.75 E
+(xample)-.165 E F2(#define HtmlDir /usr/local/etc/httpd/htdocs)180 362.6
+Q F0 33.297(CgiBinDir de\214nes)72 385.2 R
+(the path at which CGI programs are installed, for e)2.75 E(xample)-.165
+E F2(#define CgiBinDir /usr/local/etc/httpd/cgi-bin)180 402.2 Q F0
+14.377(ProxyManager de\214nes)72 424.8 R(the transport scheme, hostname\
+, and port for CGI programs to contact the)2.75 E(Proxy Manager)154.5
+437.8 Q 5.5(.S)-.605 G(ee the)-5.5 E/F3 11/Times-Italic@0 SF(pr)2.75 E
+(oxymngr)-.495 E F0(man pages for further details.)2.75 E -.88(Ty)5.5 G
+(pically the proxy).88 E(manager host will be the same as your web serv)
+154.5 450.8 Q(er)-.165 E 2.75(,f)-.44 G(or e)-2.75 E(xample:)-.165 E F2
+(#define ProxyManager tcp/www.myorg.org:6500)180 467.8 Q F0(Then mak)72
+490.4 Q 2.75(et)-.11 G(he Mak)-2.75 E(e\214les and b)-.11 E
+(uild the directories with the follo)-.22 E(wing command sequence:)-.275
+E F2(cd xc/programs/xrx/htdocs)99.5 509.4 Q
+(xmkmf ../../.. programs/xrx/htdocs)99.5 522.4 Q(make)99.5 535.4 Q
+(make install)99.5 548.4 Q(cd ../cgi-bin)99.5 561.4 Q
+(xmkmf ../../.. programs/xrx/cgi-bin)99.5 574.4 Q(make)99.5 587.4 Q
+(make install)99.5 600.4 Q F0(These directories are not automatically b)
+72 623 Q(uilt or installed by the top le)-.22 E -.165(ve)-.275 G 2.75
+(lM).165 G(ak)-2.75 E(e\214le because the)-.11 E 2.75(yi)-.165 G
+(nstall out-)-2.75 E(side the ProjectRoot.)72 636 Q -1.21(Yo)72 652.6 S
+2.75(ua)1.21 G(lso need to con\214gure your web serv)-2.75 E
+(er so that \214les with the e)-.165 E(xtension name `)-.165 E(`rx')
+-.814 E 2.75('a)-.814 G(re of the MIME)-2.75 E(type `)72 665.6 Q
+(`application/x-rx')-.814 E 2.75('. See)-.814 F(your HTTP serv)2.75 E
+(er')-.165 E 2.75(sc)-.605 G
+(on\214guration documentation for the right procedure to)-2.75 E(do so.)
+72 678.6 Q(7)303.25 769 Q EP
+%%Page: 8 12
+%%BeginPageSetup
+BP
+%%EndPageSetup
+/F0 11/Times-Roman@0 SF 2.75(XW)72 49 S(indo)-3.19 E 2.75(wS)-.275 G
+(ystem Release Notes)-2.75 E 2.75(XV)205.364 G(ersion 11, Release 6.3)
+-3.971 E/F1 11/Times-Bold@0 SF 2.75(3.4.2. The)72 85 R(RX Helper Pr)2.75
+E(ogram)-.198 E F0(The helper program,)72 114.6 Q/F2 11/Times-Italic@0
+SF(xrx)2.75 E F0 2.75(,m)C(ay be used with an)-2.75 E 2.75(yW)-.165 G
+(eb bro)-3.63 E(wser to interpret the ne)-.275 E 2.75(wR)-.275 G 2.75
+(Xd)-2.75 G(ocument type.)-2.75 E
+(The RX helper program is installed in <ProjectRoot>/bin \(e.g.)72 131.2
+Q 2.75(/usr/X11R6.3/bin/\). Y)5.5 F(ou will need to con-)-1.21 E
+(\214gure your web bro)72 144.2 Q(wser to use it for RX documents by ad\
+ding a line to your $HOME/.mailcap:)-.275 E/F3 11/Courier@0 SF
+(application/x-rx; /X11/bin/xrx %s)108 161.2 Q F0 -1.21(Yo)72 177.8 S
+2.75(um)1.21 G(ay need to refer to your web bro)-2.75 E(wser')-.275 E
+2.75(sd)-.605 G(ocumentation for e)-2.75 E
+(xact instructions on con\214guring helper)-.165 E(applications.)72
+190.8 Q(The helper program is acti)72 207.4 Q -.275(va)-.275 G
+(ted by your bro).275 E(wser as soon as you retrie)-.275 E .33 -.165
+(ve a)-.275 H .33 -.165(ny d).165 H(ocument of the MIME type).165 E
+(application/x-rx. All you need to do is to point your bro)72 220.4 Q
+(wser at the URL:)-.275 E F3(http://your.web.server/xload.rx)108 237.4 Q
+F0(The application \(i.e.)72 254 Q F2(xload)2.75 E F0 2.75(\)s)C
+(hould appear on your DISPLA)-2.75 E 2.75(Ya)-1.155 G 2.75(san)-2.75 G
+.55 -.275(ew t)-2.75 H(op-le).275 E -.165(ve)-.275 G 2.75(lc).165 G 2.75
+(lient. The)-2.75 F(client will be)2.75 E(running on your web serv)72
+267 Q(er host and connected to your X serv)-.165 E(er)-.165 E 5.5(.I)
+-.605 G 2.75(fy)-5.5 G(our X serv)-2.75 E(er supports the SECU-)-.165 E
+(RITY e)72 280 Q
+(xtension the client will be running as an untrusted client.)-.165 E F1
+2.75(3.4.3. The)72 319 R(RX Netscape Na)2.75 E(vigator Plug-in)-.275 E
+F0(The Na)72 348.6 Q(vig)-.22 E
+(ator plug-in supports all the functions of)-.055 E F2(xrx)2.75 E F0
+(and in addition uses the ne)2.75 E 2.75(wX)-.275 G(C-APPGR)-2.75 E(OUP)
+-.44 E -.165(ex)72 361.6 S(tension, if your X serv).165 E(er pro)-.165 E
+(vides it, to cause the remotely launched application to be embedded wi\
+thin)-.165 E(the bro)72 374.6 Q(wser page from which it w)-.275 E
+(as launched.)-.11 E
+(The HTML page links to an RX document via the EMBED tag, a Netscape e)
+72 391.2 Q(xtension to HTML.)-.165 E(The RX)5.5 E(document pro)72 404.2
+Q(vides the plug-in with the list of services the application w)-.165 E
+(ants to use.)-.11 E(Based on this infor)5.5 E(-)-.22 E
+(mation, the plug-in sets the v)72 417.2 Q
+(arious requested services, including creating authorization k)-.275 E
+-.165(ey)-.11 G(s, and passes).165 E(the rele)72 430.2 Q -.275(va)-.275
+G(nt data to the application through an HTTP GET request of the associa\
+ted CGI script.).275 E(The W)5.5 E(eb)-.88 E(serv)72 443.2 Q(er then e)
+-.165 E -.165(xe)-.165 G(cutes the CGI script to start the application.)
+.165 E 1.76 -.88(To b)72 459.8 T 2.75(ea).88 G
+(ble to use the RX plug-in you need Netscape Na)-2.75 E(vig)-.22 E
+(ator 3.0.)-.055 E(Binaries for v)5.5 E(arious systems can be)-.275 E
+(found at:)72 472.8 Q F3
+(http://home.netscape.com/comprod/mirror/client_download.html)108 489.8
+Q F0 1.76 -.88(To c)72 506.4 T(omplete the installation of the Netscape\
+ plug-in, \214nd the \214le named).88 E F2(libxrx.so.6.3)2.75 E F0(or)
+2.75 E F2(libxrx.sl.6.3)2.75 E F0(\(or)2.75 E(similar)72 519.4 Q 2.75
+(,d)-.44 G(epending on your platform\) in <ProjectRoot>/lib \(e.g.)-2.75
+E F1(/usr/X11R6.3/lib)2.75 E F0 2.75(\)a)C(nd cop)-2.75 E 2.75(yi)-.11 G
+2.75(tt)-2.75 G 2.75(oe)-2.75 G(ither)-2.75 E(/usr/local/lib/netscape/p\
+lugins or $HOME/.netscape/plugins. Do not install the symlinks)72 532.4
+Q F2(libxrx.so)2.75 E F0(or)2.75 E F2(libxrx.sl)72 545.4 Q F0 2.75(;t)C
+(he)-2.75 E 2.75(ym)-.165 G(ay confuse Netscape.)-2.75 E -1.21(Yo)72 562
+S 2.75(us)1.21 G(hould remo)-2.75 E .33 -.165(ve o)-.165 H 2.75(rc).165
+G(omment out the line you may ha)-2.75 E .33 -.165(ve p)-.22 H(re).165 E
+(viously added in your mailcap \214le to use)-.275 E
+(the RX helper program, otherwise the plug-in will not be enabled.)72
+575 Q(\(The usual comment character for)5.5 E(mailcap is `)72 588 Q(`#')
+-.814 E('.\))-.814 E(If you are already running Netscape Na)72 604.6 Q
+(vig)-.22 E(ator)-.055 E 2.75(,y)-.44 G(ou need to e)-2.75 E
+(xit and restart it after cop)-.165 E(ying the plug-in)-.11 E
+(library so the ne)72 617.6 Q 2.75(wp)-.275 G(lug-in will be found.)
+-2.75 E(Once this is done you can check that Na)5.5 E(vig)-.22 E
+(ator has successfully)-.055 E(loaded the plug-in by checking the `)72
+630.6 Q -.88(`A)-.814 G(bout Plug-ins').88 E 2.75('p)-.814 G
+(age from the Help menu. This should sho)-2.75 E 2.75(ws)-.275 G(ome-)
+-2.75 E(thing lik)72 643.6 Q(e:)-.11 E(8)303.25 769 Q EP
+%%Page: 9 13
+%%BeginPageSetup
+BP
+%%EndPageSetup
+/F0 11/Times-Roman@0 SF 2.75(XV)72 49 S(ersion 11, Release 6.3)-3.971 E
+2.75(XW)205.364 G(indo)-3.19 E 2.75(wS)-.275 G(ystem Release Notes)-2.75
+E(RX Plug-in)195.75 85 Q
+(File name: /usr/guest/netscape/plugins/libxrx.sl.6.3)110.5 111 Q 2.75
+(XR)110.5 137 S(emote Acti)-2.75 E -.275(va)-.275 G(tion Plug-in).275 E
+(Mime T)110.5 163 Q 36.296(ype Description)-.88 F(Suf)99.874 E<8c78>
+-.275 E 33.632(es Enabled)-.165 F 16.782(application/x-rx X)110.5 176 R
+(Remote Acti)2.75 E -.275(va)-.275 G(tion Plug-in).275 E 54.587(xrx Y)
+22.5 F(es)-1.1 E(The plug-in will be acti)72 198.6 Q -.275(va)-.275 G
+(ted by Netscape Na).275 E(vig)-.22 E(ator as soon as you retrie)-.055 E
+.33 -.165(ve a)-.275 H .33 -.165(ny d).165 H(ocument of the MIME).165 E
+(type application/x-rx.)72 211.6 Q(Se)5.5 E -.165(ve)-.275 G
+(ral samples are included in the distrib).165 E
+(ution. The most basic one is xload. All)-.22 E
+(you need to do is point your bro)72 224.6 Q(wser at the page:)-.275 E
+/F1 11/Courier@0 SF(http://your.web.server/xload.html)108 241.6 Q F0
+(If something goes wrong check on the all the pre)72 258.2 Q
+(vious steps listed abo)-.275 E .33 -.165(ve a)-.165 H(nd try ag).165 E
+2.75(ain. Once)-.055 F(xload is)2.75 E -.11(wo)72 271.2 S
+(rking you can try some of the other e).11 E(xamples in the distrib)
+-.165 E(ution such as bitmap.html or dtcm.html.)-.22 E/F2 11
+/Times-Bold@0 SF 2.75(3.4.4. T)72 310.2 R(rying Embedding W)-.814 E
+(ith an Old X Ser)-.198 E -.11(ve)-.11 G(r).11 E F0(The Netscape Na)72
+339.8 Q(vig)-.22 E(ator plug-in,)-.055 E/F3 11/Times-Italic@0 SF(libxrx)
+2.75 E F0 2.75(,w)C(ill w)-2.75 E(ork with an X serv)-.11 E
+(er that does not contain the application)-.165 E(group or security e)72
+352.8 Q 2.75(xtensions. The)-.165 F
+(application will be started as a separate top-le)2.75 E -.165(ve)-.275
+G 2.75(lc).165 G(lient.)-2.75 E(If you wish to try out the embedding f)
+72 369.4 Q(acilities without replacing your desktop X serv)-.11 E(er)
+-.165 E 2.75(,y)-.44 G(ou may use the)-2.75 E F3(Xnest)72 382.4 Q F0
+(serv)2.75 E(er)-.165 E(.)-.605 E 2.75(At)72 399 S(ypical)-2.75 E F3
+(Xnest)2.75 E F0(session w)2.75 E(ould look lik)-.11 E 2.75(et)-.11 G
+(he follo)-2.75 E(wing:)-.275 E F1 6.6(%X)99.5 418 S(nest :11)-6.6 E 6.6
+(%x)99.5 431 S(term -display :11)-6.6 E F0(These tw)72 453.6 Q 2.75(oc)
+-.11 G(ommands start a `)-2.75 E(`nested')-.814 E 2.75('s)-.814 G(erv)
+-2.75 E(er and a terminal emulator within that serv)-.165 E(er)-.165 E
+5.5(.Y)-.605 G(our f)-6.71 E -.22(avo)-.11 G(rite).22 E(windo)72 466.6 Q
+2.75(wm)-.275 G(anager and Netscape Na)-2.75 E(vig)-.22 E(ator can no)
+-.055 E 2.75(wb)-.275 G 2.75(ee)-2.75 G -.165(xe)-2.915 G
+(cuted from the nested xterm windo).165 E 4.18 -.715(w. Y)-.275 H
+(ou may)-.495 E
+(wish to \214rst disable access control in the nested serv)72 479.6 Q
+(er by running `)-.165 E(`xhost +')-.814 E 2.75('i)-.814 G 2.75(nt)-2.75
+G(he nested xterm.)-2.75 E F2 2.75(3.4.5. Setting)72 518.6 R(Up Y)2.75 E
+(our Own A)-1.221 E(pplications T)-.275 E 2.75(oR)-1.012 G(un Ov)-2.75 E
+(er The W)-.11 E(eb)-.715 E F0(Based on the e)72 548.2 Q(xamples pro)
+-.165 E(vided in the distrib)-.165 E
+(ution it should be easy to set up your web serv)-.22 E(er to run your)
+-.165 E -.275(ow)72 561.2 S 2.75(na).275 G 2.75(pplications. Ev)-2.75 F
+(ery application requires 3 additional \214les to identify it to W)-.165
+E(eb bro)-.88 E(wsers:)-.275 E 16.384(myapp.html An)99.5 580.2 R
+(HTML page to present the application embedded)2.75 E 27.395
+(myapp.rx The)99.5 593.2 R(RX document describing the application)2.75 E
+28(myapp.pl The)99.5 606.2 R(CGI script to start the application)2.75 E
+(Note that the separate `)72 625.2 Q(`.rx')-.814 E 2.75<278c>-.814 G(le\
+ could be omitted by implementing the CGI script such that if it is in)
+-2.75 E -.22(vo)-.44 G -.11(ke).22 G(d).11 E(without a Q)72 638.2 Q(UER)
+-.11 E(Y_STRING it will return the RX content.)-.715 E 1.76 -.88(We d)
+5.5 H(ecided not to do so in the distrib).88 E(uted)-.22 E -.165(ex)72
+651.2 S(amples for purpose of clarity).165 E(.)-.715 E
+(The xload demo pro)72 667.8 Q(vides a good starting point. Simply mak)
+-.165 E 2.75(eac)-.11 G(op)-2.75 E 2.75(yo)-.11 G 2.75(fe)-2.75 G
+(ach of the \214les xload.rx,)-2.75 E
+(xload.html, and xload.pl. Then look inside them for e)72 680.8 Q -.165
+(ve)-.275 G(ry instance of `).165 E(`xload')-.814 E 2.75('a)-.814 G
+(nd change it to whate)-2.75 E -.165(ve)-.275 G(r).165 E
+(is appropriate for your application.)72 693.8 Q -1.21(Yo)72 710.4 S
+2.75(uw)1.21 G(ill not be able to run the dtcm demo unless you ha)-2.75
+E -.165(ve)-.22 G F3(dtcm)2.915 E F0
+(\(a CDE component\) installed on your)2.75 E(web serv)72 723.4 Q
+(er host.)-.165 E(This e)5.5 E(xample sho)-.165 E(ws ho)-.275 E 2.75
+(waC)-.275 G(GI script w)-2.75 E(ould look when an X Print serv)-.11 E
+(er is requested.)-.165 E(9)303.25 769 Q EP
+%%Page: 10 14
+%%BeginPageSetup
+BP
+%%EndPageSetup
+/F0 11/Times-Roman@0 SF 2.75(XW)72 49 S(indo)-3.19 E 2.75(wS)-.275 G
+(ystem Release Notes)-2.75 E 2.75(XV)205.364 G(ersion 11, Release 6.3)
+-3.971 E(The script)72 85 Q/F1 11/Times-Italic@0 SF(dtcm.pl)2.75 E F0
+(is, for that reason, slightly more complicated than other e)2.75 E
+(xamples.)-.165 E/F2 11/Times-Bold@0 SF 2.75(3.5. Security)72 124 R
+(Extension)2.75 E F0(The SECURITY e)72 153.6 Q(xtension contains ne)
+-.165 E 2.75(wp)-.275 G(rotocol needed to pro)-2.75 E
+(vide enhanced X serv)-.165 E(er security)-.165 E 5.5(.T)-.715 G(his)
+-5.5 E -.165(ex)72 166.6 S
+(tension adds to the X protocol the concepts of `).165 E(`trusted')-.814
+E 2.75('a)-.814 G(nd `)-2.75 E(`untrusted')-.814 E 2.75('c)-.814 G 2.75
+(lients. The)-2.75 F(trust status of a)2.75 E
+(client is determined by the authorization used at connection setup.)72
+179.6 Q(All clients using host-based authoriza-)5.5 E
+(tion are considered `)72 192.6 Q(`trusted')-.814 E 2.75('. Clients)
+-.814 F(using other authorization protocols may be either trusted or)
+2.75 E(untrusted depending on the data included in the connection autho\
+rization phase.)72 205.6 Q(The requests in the security e)72 222.2 Q(xt\
+ension permit a trusted client to create multiple authorization entries\
+ for a)-.165 E(single authorization protocol.)72 235.2 Q
+(Each entry is tagged with the trust status to be associated with an)5.5
+E 2.75(yc)-.165 G(lient)-2.75 E(presenting that authorization.)72 248.2
+Q(When a connection identifying an `)72 264.8 Q(`untrusted')-.814 E 2.75
+('c)-.814 G(lient is accepted, the client is restricted from performing)
+-2.75 E(certain operations that w)72 277.8 Q
+(ould steal or modify data that is held by the serv)-.11 E
+(er for trusted clients.)-.165 E(An)5.5 E
+(untrusted client performing a disallo)72 290.8 Q
+(wed operation will recei)-.275 E .33 -.165(ve p)-.275 H
+(rotocol errors.).165 E(Such a client may be)5.5 E
+(written to catch these errors and continue operation.)72 303.8 Q
+(When a client is untrusted, the serv)72 320.4 Q
+(er will also limit the e)-.165 E(xtensions that are a)-.165 E -.275(va)
+-.22 G(ilable to the client.).275 E(Each X)5.5 E(protocol e)72 333.4 Q(\
+xtension is responsible for de\214ning what operations are permitted to\
+ untrusted clients; by)-.165 E(def)72 346.4 Q(ault, the entire e)-.11 E
+(xtension is hidden.)-.165 E(The speci\214cation for the SECURITY e)72
+363 Q(xtension is in)-.165 E F2(xc/doc/specs/Xext/security)2.75 E(.tex)
+-.77 E F0(\(LaT)2.75 E(eX source\) and)-.77 E F2
+(xc/doc/hardcopy/Xext/security)72 376 Q(.PS.Z)-.77 E F0
+(\(compressed PostScript\).)2.75 E F2 2.75(3.5.1. Untrusted)72 415 R
+-.275(Ap)2.75 G(plication Beha).275 E(vior)-.275 E F0
+(Most applications w)72 444.6 Q
+(ork normally when run as untrusted clients, b)-.11 E
+(ut since the security e)-.22 E(xtension changes)-.165 E(the semantics \
+of certain parts of the X protocol, it is no surprise that some clients\
+ beha)72 457.6 Q .33 -.165(ve d)-.22 H(if).165 E(ferently when)-.275 E
+2.75(untrusted. W)72 470.6 R 2.75(en)-.88 G(ote the follo)-2.75 E
+(wing signi\214cant beha)-.275 E(vior changes, separated into tw)-.22 E
+2.75(oc)-.11 G(ate)-2.75 E(gories: changes)-.165 E(that we e)72 483.6 Q
+(xpect could disappear or mutate if the implementation were impro)-.165
+E -.165(ve)-.165 G 2.75(di).165 G 2.75(naf)-2.75 G(uture release, and)
+-2.75 E(changes we e)72 496.6 Q(xpect are permanent, le)-.165 E
+(gitimate defenses ag)-.165 E(ainst data loss or leakage.)-.055 E F2
+2.75(3.5.1.1. Beha)72 535.6 R(viors That Ar)-.275 E 2.75(eI)-.198 G
+(mplementation-Dependent)-2.75 E F0(The follo)72 565.2 Q(wing beha)-.275
+E(viors when running the respecti)-.22 E .33 -.165(ve a)-.275 H
+(pplications as untrusted are not mandated by the).165 E
+(security design b)72 578.2 Q(ut are side ef)-.22 E
+(fects of limitations in the current implementation.)-.275 E F1(ocloc)72
+594.8 Q(k)-.22 E F0(is square because the SHAPE e)2.75 E(xtension hasn')
+-.165 E 2.75(tb)-.198 G(een mark)-2.75 E(ed secure yet.)-.11 E
+(Similarly)5.5 E 2.75(,X)-.715 G .33 -.165(aw a)-2.75 H(pplica-).165 E
+(tions that use o)72 607.8 Q -.275(va)-.165 G 2.75(lb).275 G
+(uttons will ha)-2.97 E .33 -.165(ve r)-.22 H(ectangular b).165 E
+(uttons instead.)-.22 E(An)72 624.4 Q 2.75(ya)-.165 G
+(pplication that depends on an e)-2.75 E
+(xtension other than XC-MISC, LBX, or BIG-REQ)-.165 E(UESTS will ha)-.11
+E -.165(ve)-.22 G(dif)72 637.4 Q(ferent beha)-.275 E(vior)-.22 E 2.75
+(,a)-.44 G 2.75(sn)-2.75 G 2.75(oo)-2.75 G(ther e)-2.75 E
+(xtensions are currently mark)-.165 E(ed secure.)-.11 E
+(The core clients af)5.5 E(fected are)-.275 E F1(xieperf)72 650.4 Q F0
+(and all the xkb utilities.)2.75 E F1(emacs)72 667 Q F0 -.165(ex)2.75 G
+(its with a W).165 E(indo)-.44 E 2.75(we)-.275 G
+(rror when trying to use the QueryPointer request on the root windo)
+-2.75 E 2.75(ww)-.275 G(hen)-2.75 E(you click in a b)72 680 Q(uf)-.22 E
+(fer)-.275 E(.)-.605 E F1 -1.705 -.605(Fr a)72 696.6 T(meMak).605 E(er)
+-.11 E F0 2.75(,a)C(nd)-2.75 E F1(xwd -r)2.75 E(oot)-.495 E F0(both e)
+2.75 E(xit with a W)-.165 E(indo)-.44 E 2.75(we)-.275 G
+(rror when trying to use the GetW)-2.75 E(indo)-.44 E(wAttrib)-.275 E
+(utes)-.22 E(request on a windo)72 709.6 Q 2.75(wm)-.275 G
+(anager frame windo)-2.75 E -.715(w.)-.275 G(10)300.5 769 Q EP
+%%Page: 11 15
+%%BeginPageSetup
+BP
+%%EndPageSetup
+/F0 11/Times-Roman@0 SF 2.75(XV)72 49 S(ersion 11, Release 6.3)-3.971 E
+2.75(XW)205.364 G(indo)-3.19 E 2.75(wS)-.275 G(ystem Release Notes)-2.75
+E(All the remaining changes are in)72 85 Q -.22(vo)-.44 G(lv).22 E
+(ed in some w)-.165 E(ay with windo)-.11 E 2.75(wp)-.275 G 2.75
+(roperties. Some)-2.75 F(of these beha)2.75 E(viors)-.22 E
+(can be modi\214ed with changes to the SecurityPolic)72 98 Q 2.75<798c>
+-.165 G(le; see the)-2.75 E/F1 11/Times-Italic@0 SF(Xserver)2.75 E F0
+(man page.)2.75 E(Se)72 114.6 Q -.165(ve)-.275 G(ral clients e).165 E
+(xit with a W)-.165 E(indo)-.44 E 2.75(we)-.275 G
+(rror when trying to use the DeleteProperty request on v)-2.75 E
+(arious proper)-.275 E(-)-.22 E(ties on the root windo)72 127.6 Q 4.18
+-.715(w. T)-.275 H(hese include).715 E F1(xcmsdb -r)2.75 E(emo)-.407 E
+(ve)-.11 E F0(,)A F1(xpr)2.75 E(op -r)-.495 E(oot -r)-.495 E(emo)-.407 E
+(ve)-.11 E F0 2.75(,a)C(nd)-2.75 E F1(xstdcmap -delete)2.75 E F0(.)A F1
+(xpr)72 144.2 Q(op)-.495 E F0 -.165(ex)2.75 G
+(its with an Atom error when attempting to access protected properties.)
+.165 E(The follo)72 160.8 Q(wing tw)-.275 E 2.75(oc)-.11 G
+(hanges require, in addition, a `)-2.75 E
+(`trusted selection intermediary')-.814 E 2.75('t)-.814 G 2.75(op)-2.75
+G(ro)-2.75 E(vide selection)-.165 E
+(transfer from untrusted to trusted clients \(and vice-v)72 173.8 Q 2.75
+(ersa\). R6.3)-.165 F(does not include such a trusted intermedi-)2.75 E
+(ary)72 186.8 Q(.)-.715 E F1(xterm)72 203.4 Q F0 -.165(ex)2.75 G
+(its with an Atom error when it tries to store the property v).165 E
+(alue during a selection transfer \(paste\))-.275 E
+(to a trusted selection requester)72 216.4 Q(.)-.605 E(The `)72 233 Q
+(`cop)-.814 E 2.75(y0t)-.11 G 2.75(oP)-2.75 G(RIMAR)-2.75 E(Y')-.715 E
+2.75('b)-.814 G(utton of)-2.97 E F1(xcutsel)2.75 E F0(does not w)2.75 E
+(ork.)-.11 E
+(Selection transfer from untrusted clients to trusted clients f)72 249.6
+Q(ails when the untrusted client attempts to use)-.11 E(SendEv)72 262.6
+Q(ent to generate the SelectionNotify e)-.165 E -.165(ve)-.275 G
+(nt for the requester).165 E 5.5(.M)-.605 G
+(ost requesters will treat this as a)-5.5 E
+(transfer timeout and continue.)72 275.6 Q
+(Xt-based applications will create an additional Atom each time such a)
+5.5 E(transfer is attempted.)72 288.6 Q/F2 11/Times-Bold@0 SF 2.75
+(3.5.1.2. Beha)72 327.6 R(viors That Ar)-.275 E 2.75(eN)-.198 G(ot Lik)
+-2.75 E(ely T)-.11 E 2.75(oC)-1.012 G(hange)-2.75 E F0(The follo)72
+357.2 Q(wing beha)-.275 E
+(viors represent actions performed by the applications that are disallo)
+-.22 E(wed by design.)-.275 E F1(editr)72 373.8 Q(es)-.407 E F0(will f)
+2.75 E(ail when pointed at a trusted client when it tries to read windo)
+-.11 E 2.75(wp)-.275 G(roperties on a windo)-2.75 E(w)-.275 E -.275(ow)
+72 386.8 S(ned by that client.).275 E F1(Xnest)72 403.4 Q F0 -.165(ex)
+2.75 G
+(its on startup with an Access error as it tries to use the ChangeK).165
+E -.165(ey)-.275 G(boardControl request.).165 E(The ne)72 420 Q(w)-.275
+E F1 -.11(ge)2.75 G(ner).11 E(ate)-.165 E F0(option to)2.75 E F1(xauth)
+2.75 E F0 -.11(fa)2.75 G
+(ils because untrusted applications are not allo).11 E
+(wed to create additional)-.275 E(authorizations.)72 433 Q F1(xhost)72
+449.6 Q F0(cannot be used to modify the host access list.)2.75 E F1(xma)
+72 466.2 Q(g)-.11 E F0(gets an unending stream of Dra)2.75 E -.11(wa)
+-.165 G
+(ble errors as it tries to use the PolyRectangle request on the root).11
+E(windo)72 479.2 Q 4.18 -.715(w. I)-.275 H 2.75(fy).715 G
+(ou click to select a location to magnify)-2.75 E 2.75(,x)-.715 G
+(mag gets a Dra)-2.75 E -.11(wa)-.165 G
+(ble error as it tries to use the).11 E
+(GetImage request on the root windo)72 492.2 Q -.715(w.)-.275 G F1(xma)
+6.215 E(g)-.11 E F0(could be modi\214ed to e)2.75 E
+(xit gracefully under these conditions.)-.165 E F1(netscape)72 508.8 Q
+F0 -.165(ex)2.75 G(its on startup with a Dra).165 E -.11(wa)-.165 G
+(ble error when trying to use the GetImage request on the root win-).11
+E(do)72 521.8 Q -.715(w.)-.275 G F1(xmodmap)72 538.4 Q F0 -.165(ex)2.75
+G(its with an Access error when trying to use the ChangeK).165 E -.165
+(ey)-.275 G(boardMapping request.).165 E F1(xset)72 555 Q F0(with the)
+2.75 E F1(b)2.75 E F0(,)A F1(c)2.75 E F0(,)A F1(led)2.75 E F0 2.75(,o)C
+(r)-2.75 E F1(r)2.75 E F0(options e)2.75 E
+(xits with an Access error when trying to use the ChangeK)-.165 E -.165
+(ey)-.275 G(board-).165 E(Control request.)72 568 Q -.44(Wi)5.5 G
+(th the).44 E F1(bc)2.75 E F0(option, it can')2.75 E 2.75<748c>-.198 G
+(nd the MIT)-2.75 E(-SUNDR)-1.012 E -1.221(Y-)-.715 G(NONST)1.221 E(AND)
+-1.023 E(ARD e)-.44 E(xtension and)-.165 E -.165(ex)72 581 S
+(its gracefully).165 E(.)-.715 E F1(xsetr)72 597.6 Q(oot)-.495 E F0
+-.165(ex)2.75 G(its with a W).165 E(indo)-.44 E 2.75(we)-.275 G
+(rror when trying to use the ChangeW)-2.75 E(indo)-.44 E(wAttrib)-.275 E
+(utes request on the root)-.22 E(windo)72 610.6 Q -.715(w.)-.275 G F2
+2.75(3.6. A)72 649.6 R(pplication Gr)-.275 E(oup Extension)-.198 E F0
+(The application group e)72 679.2 Q(xtension \(XC-APPGR)-.165 E
+(OUP\) pro)-.44 E(vides ne)-.165 E 2.75(wp)-.275 G
+(rotocol to implement Application)-2.75 E(Groups \(`)72 692.2 Q -.88(`A)
+-.814 G(ppGroups').88 E 2.75('\). The)-.814 F(AppGroup f)2.75 E
+(acility allo)-.11 E(ws other clients to share the SubstructureRedirect)
+-.275 E(mechanism with the windo)72 705.2 Q 2.75(wm)-.275 G(anager)-2.75
+E 5.5(.T)-.605 G(his allo)-5.5 E(ws another client called the `)-.275 E
+(`application group leader')-.814 E(',)-.814 E(such as a web bro)72
+718.2 Q(wser)-.275 E 2.75(,t)-.44 G 2.75(oi)-2.75 G(ntercept a MapReque\
+st made by a third application and reparent its windo)-2.75 E(w)-.275 E
+(into the web bro)72 731.2 Q(wser before the windo)-.275 E 2.75(wm)-.275
+G(anager tak)-2.75 E(es control.)-.11 E
+(The AppGroup leader may also limit the)5.5 E(11)300.5 769 Q EP
+%%Page: 12 16
+%%BeginPageSetup
+BP
+%%EndPageSetup
+/F0 11/Times-Roman@0 SF 2.75(XW)72 49 S(indo)-3.19 E 2.75(wS)-.275 G
+(ystem Release Notes)-2.75 E 2.75(XV)205.364 G(ersion 11, Release 6.3)
+-3.971 E(screens and visuals a)72 85 Q -.275(va)-.22 G
+(ilable to the applications in the group.).275 E(Users who ha)72 101.6 Q
+.33 -.165(ve a)-.22 H 2.75(nX).165 G(C-APPGR)-2.75 E
+(OUP enhanced X serv)-.44 E(er and an RX plug-in for their Netscape Na)
+-.165 E(vig)-.22 E(ator)-.055 E(web bro)72 114.6 Q
+(wser can run programs remotely o)-.275 E -.165(ve)-.165 G 2.75(rt).165
+G(he web and ha)-2.75 E .33 -.165(ve t)-.22 H
+(he output appear as part of the presenta-).165 E(tion in their web bro)
+72 127.6 Q(wser)-.275 E(.)-.605 E(The only w)72 144.2 Q(ay for an appli\
+cation to become a member of an AppGroup is by using an authorization g\
+ener)-.11 E(-)-.22 E(ated using the ne)72 157.2 Q 2.75(ws)-.275 G
+(ecurity e)-2.75 E 2.75(xtension. Whene)-.165 F -.165(ve)-.275 G 2.75
+(ra).165 G 2.75(na)-2.75 G(pplication connects to the serv)-2.75 E(er)
+-.165 E 2.75(,t)-.44 G(he authorization)-2.75 E(that it used to connect\
+ is tested to see if it belongs to an AppGroup. This means that the Aut\
+horization)72 170.2 Q(data must be transmitted to the remote host where\
+ the application will be run. In the case of RX, HTTP is)72 183.2 Q
+(used to send the Authorization.)72 196.2 Q(Sites who ha)5.5 E .33 -.165
+(ve c)-.22 H(oncerns about sending unencrypted authorization data).165 E
+(such as MIT)72 209.2 Q(-MA)-1.012 E
+(GIC-COOKIE-1 via HTTP should con\214gure their web serv)-.44 E
+(ers and web bro)-.165 E(wsers to use)-.275 E(SHTTP or SSL.)72 222.2 Q
+(The speci\214cation for the XC-APPGR)72 238.8 Q(OUP e)-.44 E
+(xtension is in)-.165 E/F1 11/Times-Bold@0 SF(xc/doc/specs/Xext/A)2.75 E
+(ppGr)-.275 E(oup.mif)-.198 E F0(\(FrameMak)72 251.8 Q
+(er interchange source\) and)-.11 E F1(xc/doc/hardcopy/Xext/A)2.75 E
+(ppGr)-.275 E(oup.PS.Z)-.198 E F0(\(compressed PostScript\).)2.75 E F1
+2.75(3.7. Print)72 290.8 R(Extension)2.75 E F0(The print e)72 320.4 Q
+(xtension supports output to hardcop)-.165 E 2.75(yd)-.11 G -.275(ev)
+-2.75 G(ices using the core X dra).275 E(wing requests.)-.165 E
+(The print)5.5 E -.165(ex)72 333.4 S
+(tension adds requests for job and page control and de\214nes ho).165 E
+2.75(ws)-.275 G(peci\214c printer attrib)-2.75 E(utes are communi-)-.22
+E(cated between the serv)72 346.4 Q(er and printing clients.)-.165 E
+(Printer attrib)5.5 E(ute speci\214cations are modeled after the ISO)
+-.22 E(10175 speci\214cation.)72 359.4 Q(An X client that w)72 376 Q
+(ants to produce hardcop)-.11 E 2.75(yo)-.11 G
+(utput will typically open a second connection to an X print)-2.75 E
+(serv)72 389 Q(er)-.165 E 2.75(,p)-.44 G
+(roduce a print job, and then close the print serv)-2.75 E
+(er connection.)-.165 E(The print serv)5.5 E(er may be the same)-.165 E
+(process as the display serv)72 402 Q(er \(the term `)-.165 E
+(`video serv)-.814 E(er')-.165 E 2.75('i)-.814 G 2.75(ss)-2.75 G
+(ometimes used\) although the implementation)-2.75 E(pro)72 415 Q
+(vided in R6.3 does not completely support video and print serv)-.165 E
+(ers in the same binary)-.165 E(.)-.715 E
+(The speci\214cation for the print e)72 431.6 Q(xtension is in)-.165 E
+F1(xc/doc/specs/XPRINT/xp_pr)2.75 E(oto.mif)-.198 E F0(\(FrameMak)2.75 E
+(er inter)-.11 E(-)-.22 E(change source\) and)72 444.6 Q F1
+(xc/doc/hardcopy/XPRINT/xp_pr)2.75 E(oto.PS.Z)-.198 E F0
+(\(compressed PostScript\).)2.75 E(The library)5.5 E
+(API speci\214cation is in)72 457.6 Q F1(xc/doc/specs/XPRINT/xp_library)
+2.75 E(.mif)-.77 E F0(\(FrameMak)2.75 E(er interchange source\) and)-.11
+E F1(xc/doc/hardcopy/XPRINT/xp_library)72 470.6 Q(.PS.Z)-.77 E F0
+(\(compressed PostScript\).)2.75 E F1 2.75(3.7.1. Running)72 509.6 R
+(an X Print Ser)2.75 E -.11(ve)-.11 G(r).11 E F0(The print serv)72 539.2
+Q(er is simply an X serv)-.165 E(er with the print e)-.165 E
+(xtension and special DDX implementations.)-.165 E(The X)5.5 E
+(Print Serv)72 552.2 Q(er is started lik)-.165 E 2.75(ea)-.11 G .33
+-.165(ny o)-2.75 H(ther X serv).165 E(er)-.165 E(.)-.605 E
+(Here is a sample command line for use with a typical con\214guration:)
+72 568.8 Q/F2 11/Courier@0 SF 6.6(%X)99.5 587.8 S(prt :1 -ac)-6.6 E F0
+(The options used in the e)72 610.4 Q(xample are:)-.165 E 43.692(:1 On)
+72 627 R 2.75(ah)2.75 G(ost that is running a video display serv)-2.75 E
+(er you will need to specify a dif)-.165 E(ferent display)-.275 E
+(from the def)127 640 Q(ault.)-.11 E 38.819(-ac Disable)72 656.6 R
+(access control, since no simple mechanism for sharing k)2.75 E -.165
+(ey)-.11 G 2.75(si).165 G 2.75(sp)-2.75 G(ro)-2.75 E(vided.)-.165 E
+(The X print serv)72 673.2 Q(er supports the follo)-.165 E
+(wing additional options:)-.275 E 18.029(-XpFile Points)72 689.8 R
+(to the directory containing the print serv)2.75 E
+(er con\214guration \214les.)-.165 E(XPCONFIGDIR)72 706.4 Q(En)127 719.4
+Q(vironment v)-.44 E(ariable specifying alternati)-.275 E .33 -.165
+(ve l)-.275 H(ocation of the print serv).165 E
+(er con\214guration \214les.)-.165 E(12)300.5 769 Q EP
+%%Page: 13 17
+%%BeginPageSetup
+BP
+%%EndPageSetup
+/F0 11/Times-Roman@0 SF 2.75(XV)72 49 S(ersion 11, Release 6.3)-3.971 E
+2.75(XW)205.364 G(indo)-3.19 E 2.75(wS)-.275 G(ystem Release Notes)-2.75
+E(The print serv)72 85 Q(er)-.165 E(,)-.44 E/F1 11/Times-Italic@0 SF
+(Xprt)2.75 E F0 2.75(,i)C 2.75(sb)-2.75 G
+(uilt only if the con\214g option XprtServ)-2.97 E(er is YES.)-.165 E
+-.165(Fo)5.5 G(ur printer DDXen are pro-).165 E(vided, each with a sepa\
+rate con\214g option to control whether or not it will be included: XpR\
+asterDDX,)72 98 Q(XpColorPclDDX, XpMonoPclDDX, XpPostScriptDDX; see)72
+111 Q/F2 11/Times-Bold@0 SF(xc/con\214g/cf/README)2.75 E F0 5.5(.X)C
+(prtServ)-5.5 E(er)-.165 E(def)72 124 Q(aults to the v)-.11 E
+(alue of BuildServ)-.275 E(er \(i.e.)-.165 E F1(Xprt)2.75 E F0
+(will be b)2.75 E(uilt by def)-.22 E(ault on all platforms that b)-.11 E
+(uild a full X)-.22 E(serv)72 137 Q 2.75(er\). XpRasterDDX)-.165 F
+(and XpMonoPclDDX def)2.75 E(ault to NO.)-.11 E
+(XpColorPclDDX and XpPostScriptDDX)5.5 E(def)72 150 Q(ault to YES.)-.11
+E(The print serv)72 166.6 Q(er is con\214gured through a directory of c\
+on\214guration \214les that de\214ne printer model types and)-.165 E
+(instances of printer models.)72 179.6 Q(An e)5.5 E
+(xample con\214guration tree is pro)-.165 E(vided in)-.165 E F2(xc/pr)72
+192.6 Q(ograms/Xser)-.198 E -.11(ve)-.11 G(r/XpCon\214g/).11 E F0 5.5
+(.S)C(ee also)-5.5 E F2(xc/doc/specs/Xser)2.75 E -.11(ve)-.11 G
+(r/Xprt.mif).11 E F0(\(FrameMak)2.75 E(er interchange)-.11 E
+(source\) and)72 205.6 Q F2(xc/doc/hardcopy/Xser)2.75 E -.11(ve)-.11 G
+(r/Xprt.PS.Z).11 E F0
+(\(compressed PostScript\) for further instructions on)2.75 E
+(con\214guring)72 218.6 Q F1(Xprt)2.75 E F0(.)A F2 2.75
+(3.7.2. Specifying)72 257.6 R(The Print Ser)2.75 E -.11(ve)-.11 G 2.75
+(rT).11 G 2.75(oAC)-3.762 G(lient)-2.75 E F0(By con)72 287.2 Q -.165(ve)
+-.44 G(ntion, clients locate the print serv).165 E(er using the en)-.165
+E(vironment v)-.44 E(ariable XPRINTER.)-.275 E(The syntax of)5.5 E
+(XPRINTER is an augmented DISPLA)72 300.2 Q 2.024 -1.012(Y; i)-1.155 H
+(.e.)1.012 E(printerName@host:display)108 317.2 Q(where `)72 333.8 Q
+(`printerName')-.814 E 2.75('i)-.814 G 2.75(so)-2.75 G
+(ne of the printer instances listed in the print serv)-2.75 E
+(er con\214guration \214les.)-.165 E(The use)5.5 E
+(of XPRINTER and its syntax is an application con)72 346.8 Q -.165(ve)
+-.44 G(ntion only; there is nothing in the supplied libraries).165 E
+(that uses \(or parses\) this en)72 359.8 Q(vironment v)-.44 E(ariable.)
+-.275 E F2 2.75(3.8. Pr)72 398.8 R(oxy Management Pr)-.198 E(otocol)
+-.198 E F0
+(The Proxy Management Protocol is an ICE based protocol that pro)72
+428.4 Q(vides a w)-.165 E(ay for application serv)-.11 E(ers to)-.165 E
+(easily locate proxy services such as the LBX proxy and the X \214re)72
+441.4 Q -.11(wa)-.275 G(ll proxy).11 E(.)-.715 E -.88(Ty)72 458 S
+(pically).88 E 2.75(,as)-.715 G(ervice called a `)-2.75 E
+(`proxy manager')-.814 E 2.75('i)-.814 G 2.75(sr)-2.75 G
+(esponsible for resolving requests for proxy services,)-2.75 E
+(starting ne)72 471 Q 2.75(wp)-.275 G(roxies when appropriate, and k)
+-2.75 E(eeping track of all of the a)-.11 E -.275(va)-.22 G
+(ilable proxy services.).275 E(The)5.5 E(proxy manager stri)72 484 Q
+-.165(ve)-.275 G 2.75(st).165 G 2.75(or)-2.75 G(euse e)-2.75 E
+(xisting proxy processes whene)-.165 E -.165(ve)-.275 G 2.75(rp).165 G
+(ossible.)-2.75 E(The Proxy Management Protocol is described in)72 500.6
+Q F2(xc/doc/specs/PM/PM_spec)2.75 E F0(.)A F2 2.75(3.9. Con\214guration)
+72 539.6 R F0(As in R6.1, the top-le)72 569.2 Q -.165(ve)-.275 G 2.75
+(lM).165 G(ak)-2.75 E(e\214le is no longer o)-.11 E -.165(ve)-.165 G
+-.22(r-).165 G(ridden by the \214rst b).22 E 2.75(uild. Instead)-.22 F
+2.75(an)2.75 G .55 -.275(ew \214)-2.75 H(le).275 E F1(xmak)2.75 E
+(e\214le)-.11 E F0(is created.)72 582.2 Q
+(Thus is it not necessary to tak)5.5 E 2.75(ea)-.11 G .33 -.165(ny a)
+-2.75 H(dditional steps to reset the b).165 E(uilds.)-.22 E(The \214le)
+72 598.8 Q F2(xc/con\214g/cf/README)2.75 E F0(pro)2.75 E
+(vides more guidance on ho)-.165 E 2.75(wt)-.275 G 2.75(ow)-2.75 G
+(rite an Imak)-2.75 E(e\214le, including a list of)-.11 E -.275(va)72
+611.8 S(riables that may be set in an Imak).275 E 2.75(e\214le. This)
+-.11 F(\214le is strongly recommended reading for Imak)2.75 E(e\214le)
+-.11 E(authors.)72 624.8 Q(The LaT)72 641.4 Q(eX te)-.77 E
+(xt processor is supported as of R6.1.)-.165 E(If you ha)5.5 E .33 -.165
+(ve L)-.22 H(aT).165 E(eX on your system, turn on HasLate)-.77 E(x)-.165
+E(to ha)72 654.4 Q .33 -.165(ve t)-.22 H(he Mak).165 E(eLate)-.11 E
+(xDoc rule use it.)-.165 E
+(Also since R6.1, with System V Release 4 \(SVR4\) compilers we no)72
+671 Q 2.75(wu)-.275 G(se the)-2.75 E(\255Xa \(ANSI C with nati)4.583 E
+-.165(ve)-.275 G -.165(ex)72 684 S
+(tensions\) compiler \215ag rather than).165 E(\255Xc \(limit en)4.583 E
+(vironment to that speci\214ed in the standard\).)-.44 E(This pro-)5.5 E
+(vides access to the full richness of the platform.)72 697 Q
+(Unfortunately)5.5 E 2.75(,i)-.715 G 2.75(ta)-2.75 G
+(lso de\214nes the preprocessor symbol)-2.75 E .916(__)72 710 S -1.834
+(STDC_ _)-.916 F(to 0, instead of 1 as speci\214ed by the standard.)2.75
+E(Therefore we use `)5.5 E(`#ifdef _)-.916 E -1.834(_STDC_ _').916 F
+2.75('i)-.916 G 2.75(no)-2.75 G(ur)-2.75 E(sources rather than `)72 723
+Q(`#if _)-.916 E -1.834(_STDC_ _').916 F 2.75('. On)-.916 F
+(HP-UX systems we use the)2.75 E(\255Ae compiler option instead of)4.583
+E(13)300.5 769 Q EP
+%%Page: 14 18
+%%BeginPageSetup
+BP
+%%EndPageSetup
+/F0 11/Times-Roman@0 SF 2.75(XW)72 49 S(indo)-3.19 E 2.75(wS)-.275 G
+(ystem Release Notes)-2.75 E 2.75(XV)205.364 G(ersion 11, Release 6.3)
+-3.971 E(\255Aa, also to access the full en)73.833 85 Q(vironment of)
+-.44 E(fered by the platform.)-.275 E(As in R6.1, the imak)72 101.6 Q
+2.75(ev)-.11 G(ariables)-3.025 E/F1 11/Times-Bold@0 SF
+(InstallXdmCon\214g)2.75 E F0(,)A F1(InstallXinitCon\214g)2.75 E F0 2.75
+(,a)C(nd)-2.75 E F1(InstallA)2.75 E(ppDefFiles)-.275 E F0(sup-)2.75 E
+(press o)72 114.6 Q -.165(ve)-.165 G(rwriting e).165 E
+(xisting \214les; if the \214les didn')-.165 E 2.75(tp)-.198 G(re)-2.75
+E(viously e)-.275 E(xist, the \214les are al)-.165 E -.11(wa)-.11 G
+(ys installed.).11 E(This)5.5 E(interpretation mak)72 127.6 Q
+(es bootstrapping a ne)-.11 E 2.75(ws)-.275 G
+(ystem easier than in R6 and earlier releases.)-2.75 E 2.75(An)72 144.2
+S .55 -.275(ew c)-2.75 H(on\214guration b).275 E(uild option, GzipF)-.22
+E(ontCompression, has been added to use)-.165 E/F2 11/Times-Italic@0 SF
+(gzip)2.75 E F0(rather than)2.75 E F2(compr)2.75 E(ess)-.407 E F0
+(for font compression.)72 157.2 Q(It def)5.5 E(aults to NO.)-.11 E
+(The b)72 173.8 Q(uild creates a ne)-.22 E 2.75(wd)-.275 G(irectory)
+-2.75 E F1(xc/exports)2.75 E F0
+(into which the header \214les, libraries, and certain b)2.75 E
+(uild utility)-.22 E(binaries are symlink)72 186.8 Q 2.75(ed. This)-.11
+F(greatly simpli\214es Imak)2.75 E
+(e\214le construction and supports multiple de)-.11 E -.165(ve)-.275 G
+(lopment).165 E
+(projects \(such as X, Motif, and CDE\) on a single system.)72 199.8 Q
+(Imak)72 216.4 Q 2.75(er)-.11 G(ules and template \214les for b)-2.75 E
+(uilding Motif and CDE were contrib)-.22 E
+(uted by the OSF CDE/Motif pro-)-.22 E(ject and are included in R6.3.)72
+229.4 Q F1 2.75(3.10. Documentation)72 268.4 R F0(Additional X serv)72
+298 Q(er internals documentation is pro)-.165 E(vided in the)-.165 E F1
+(/xc/doc/specs/Xser)2.75 E -.11(ve)-.11 G(r/).11 E F0(directory for the)
+2.75 E(XC-APPGR)72 311 Q(OUP and SECURITY e)-.44 E 2.75(xtensions. An)
+-.165 F(analysis and rationale for the SECURITY e)2.75 E(xtension)-.165
+E(will also be found in that directory)72 324 Q 5.5(.S)-.715 G
+(peci\214cations for the other ne)-5.5 E 2.75(ws)-.275 G
+(tandards are in)-2.75 E F1(/xc/doc/specs/RX/)2.75 E F0(,)A F1
+(/xc/doc/specs/XPRINT/)72 337 Q F0 2.75(,a)C(nd)-2.75 E F1
+(/xc/doc/specs/Xext/)2.75 E F0(.)A F1 2.75(3.11. Header)72 376 R(Files)
+2.75 E(xc/include/Xos_r)72 405.6 Q(.h)-1.1 E F0(is a ne)2.75 E 2.75(wh)
+-.275 G(eader \214le to promote portable source code using thread-safe \
+implementa-)-2.75 E
+(tions of getpwnam, getpwuid, gethostbyname, gethostbyaddr)72 418.6 Q
+2.75(,a)-.44 G(nd getservbyname.)-2.75 E(It is not required by)5.5 E(an)
+72 431.6 Q 2.75(yXC)-.165 G(onsortium standard.)-2.75 E F1 2.75(3.12. X)
+72 470.6 R(Ser)2.75 E -.11(ve)-.11 G(r).11 E F0(The security)72 500.2 Q
+2.75(,L)-.715 G(BX, printing, and AppGroup e)-2.75 E
+(xtensions are all ne)-.165 E 4.18 -.715(w. I)-.275 H 2.75(nR).715 G
+(6.3 only MIT)-2.75 E(-MA)-1.012 E(GIC-)-.44 E
+(COOKIE-1 is supported in the security e)72 513.2 Q 2.75(xtension. P)
+-.165 F(arts of the security polic)-.165 E 2.75(ya)-.165 G
+(re con\214gured at run-time)-2.75 E(from the \214le)72 526.2 Q F1
+(/usr/X11R6.3/lib/X11/xser)2.75 E -.11(ve)-.11 G(r/SecurityP).11 E
+(olicy)-.22 E F0 5.5(.S)C(ite-de\214ned polic)-5.5 E 2.75(ys)-.165 G
+(trings used by)-2.75 E F2(xfwp)2.75 E F0(and)2.75 E
+(rules for property access by untrusted clients are de\214ned there.)72
+539.2 Q(See the)5.5 E F2(Xserver)2.75 E F0(man page for full details.)
+2.75 E F1 2.75(3.12.1. New)72 578.2 R(De)2.75 E(vice Support)-.165 E F0
+(Support has been added for the Sun TCX frame b)72 607.8 Q(uf)-.22 E
+(fer as a dumb 8-bit frame b)-.275 E(uf)-.22 E(fer on Solaris 2.5.)-.275
+E(Ne)72 624.4 Q 2.75(wX)-.275 G(Free86 serv)-2.75 E
+(ers based on XFree86 3.2 are included.)-.165 E F1 2.75(3.12.2. Inter)72
+663.4 R(nal Changes)-.165 E F0(The security e)72 693 Q(xtension pro)
+-.165 E(vides ne)-.165 E 2.75(wi)-.275 G
+(nternal resource ID lookup interf)-2.75 E
+(aces that incorporate the access)-.11 E(control lookup.)72 706 Q
+(In order to be declared secure and therefore be made a)5.5 E -.275(va)
+-.22 G(ilable to untrusted clients, other).275 E -.165(ex)72 719 S
+(tensions should, at a minimum, be changed to use these interf).165 E
+2.75(aces. Depending)-.11 F(on what the e)2.75 E(xtension)-.165 E(does,\
+ more may need to be done in its implementation before it can appropria\
+tely be labeled `)72 732 Q(`secure')-.814 E('.)-.814 E(14)300.5 769 Q EP
+%%Page: 15 19
+%%BeginPageSetup
+BP
+%%EndPageSetup
+/F0 11/Times-Roman@0 SF 2.75(XV)72 49 S(ersion 11, Release 6.3)-3.971 E
+2.75(XW)205.364 G(indo)-3.19 E 2.75(wS)-.275 G(ystem Release Notes)-2.75
+E(Refer to the documents)72 85 Q/F1 11/Times-Bold@0 SF
+(xc/doc/specs/Xser)2.75 E -.11(ve)-.11 G(r/appgr).11 E(oup.ms)-.198 E F0
+(and)2.75 E F1(xc/doc/specs/Xser)2.75 E -.11(ve)-.11 G(r/secint.tex).11
+E F0(for)2.75 E
+(implementation details of the application group and security e)72 98 Q
+(xtensions, respecti)-.165 E -.165(ve)-.275 G(ly).165 E(.)-.715 E F1
+2.75(3.13. ICE)72 137 R(Library Addition)2.75 E F0 1.76 -.88(To s)72
+166.6 T(upport proxy managers and \214re).88 E -.11(wa)-.275 G
+(ll proxies using ICE on well-kno).11 E
+(wn TCP ports, an additional inter)-.275 E(-)-.22 E -.11(fa)72 179.6 S
+(ce has been added to the ICE library).11 E 5.5(.T)-.715 G(his ne)-5.5 E
+2.75(wi)-.275 G(nterf)-2.75 E(ace, IceListenF)-.11 E(orW)-.165 E(ellKno)
+-.88 E(wnConnections, has)-.275 E(equi)72 192.6 Q -.275(va)-.275 G
+(lent calling parameters to IceListenF).275 E
+(orConnections plus an ICE netw)-.165 E(ork id parameter)-.11 E(.)-.605
+E F1 2.75(3.14. Xlib)72 231.6 R -1.1(Ve)2.75 G(rtical Writing and User)
+1.1 E(-De\214ned Characters)-.407 E F0(The Xlib output method implement\
+ation has been enhanced to support the XOM v)72 261.2 Q(alue dra)-.275 E
+(wing direction)-.165 E(XOMOrientation_TTB_R)72 274.2 Q 2.75(TL. V)-.66
+F(ertical writing information and other locale speci\214c information i\
+s read)-1.221 E(from the \214le <XLocaleDir>/%L/XLC_LOCALE where the XL\
+ocaleDir con\214guration option def)72 287.2 Q(aults to)-.11 E F1
+(/usr/X11R6.3/lib/X11/locale)72 300.2 Q F0(.)A(The X[mb|wc]T)72 316.8 Q
+-.165(ex)-.77 G(tEscapement functions no).165 E 2.75(wr)-.275 G
+(eturn the te)-2.75 E(xt escapement in pix)-.165 E(els for the v)-.165 E
+(ertical or hori-)-.165 E
+(zontal direction depending on the XNOrientation XOCV)72 329.8 Q(alue.)
+-1.221 E(The X[mb|wc]Dra)72 346.4 Q(wString functions will no)-.165 E
+2.75(wr)-.275 G(ender a character string in the v)-2.75 E
+(ertical or horizontal direc-)-.165 E
+(tion depending on the XNOrientation XOCV)72 359.4 Q(alue.)-1.221 E
+(The Xlib NLS database implementation has been enhanced to support e)72
+376 Q(xtended se)-.165 E(gments used for inter)-.165 E(-)-.22 E
+(changing non-standard code sets.)72 389 Q
+(Support has been added for control sequences and encoding names)5.5 E
+(used in e)72 402 Q(xtended se)-.165 E(gments and con)-.165 E -.165(ve)
+-.44 G(rsion of glyph inde).165 E -.165(xe)-.165 G 2.75(sw).165 G
+(hen interchanging data in e)-2.75 E(xtended se)-.165 E(g-)-.165 E
+(ments.)72 415 Q F1 2.75(3.15. Xt)72 454 R(Geometry Management Deb)2.75
+E(ugger)-.22 E F0(Daniel Dardailler')72 483.6 Q 2.75(s`)-.605 G(`GeoT)
+-3.564 E(attler')-.88 E 2.75('c)-.814 G(ode has been mer)-2.75 E
+(ged into the Xt Intrinsics library implementation.)-.198 E
+(This is not a standard.)72 496.6 Q
+(If libXt is compiled with the XT_GEO_T)5.5 E -1.221(AT)-1.023 G
+(TLER symbol de\214ned \(currently there)1.221 E(is no b)72 509.6 Q
+(uild con\214guration support to do this\) then a `)-.22 E(`geoT)-.814 E
+(attler')-.88 E 2.75('r)-.814 G(esource may be speci\214ed for an)-2.75
+E 2.75(yw)-.165 G(idget)-2.75 E(in an application.)72 522.6 Q
+(If the geoT)5.5 E(attler resource for a widget instance is T)-.88 E
+(rue then libXt will generate deb)-.385 E(ug-)-.22 E
+(ging information to stdout when the widget mak)72 535.6 Q
+(es geometry change requests.)-.11 E -.165(Fo)72 552.2 S 2.75(re).165 G
+(xample, if the resources specify:)-2.915 E/F2 11/Courier@0 SF
+(myapp*draw.XmScale.geoTattler: ON)99.5 571.2 Q
+(*XmScrollBar.geoTattler:ON)99.5 584.2 Q
+(*XmRowColumn.exit_button.geoTattler:ON)99.5 597.2 Q F0
+(then geometry management deb)72 616.2 Q(ugging information will be gen\
+erated for all the XmScale children of the)-.22 E(widget named dra)72
+629.2 Q 1.43 -.715(w, a)-.165 H
+(ll the XmScrollBars, and the widget named e).715 E(xit_b)-.165 E
+(utton in an)-.22 E 2.75(yX)-.165 G(mRo)-2.75 E(wColumn.)-.275 E(15)
+300.5 769 Q EP
+%%Page: 16 20
+%%BeginPageSetup
+BP
+%%EndPageSetup
+/F0 11/Times-Roman@0 SF 2.75(XW)72 49 S(indo)-3.19 E 2.75(wS)-.275 G
+(ystem Release Notes)-2.75 E 2.75(XV)205.364 G(ersion 11, Release 6.3)
+-3.971 E/F1 11/Times-Bold@0 SF 2.75(3.16. New)72 85 R(Pr)2.75 E(ograms)
+-.198 E F0(There are ne)72 114.6 Q 2.75(wc)-.275 G(ore programs)-2.75 E
+/F2 11/Times-Italic@0 SF(lbxpr)2.75 E(oxy)-.495 E F0(,)A F2(pr)2.75 E
+(oxymngr)-.495 E F0(,)A F2(x\214ndpr)2.75 E(oxy)-.495 E F0(,)A F2(xfwp)
+2.75 E F0(,)A F2(Xprt)2.75 E F0 2.75(,a)C(nd)-2.75 E F2(xrx)2.75 E F0(.)
+A 23.529(lbxproxy The)72 144.2 R F2(lbxpr)2.75 E(oxy)-.495 E F0
+(program is used to `)2.75 E(`translate')-.814 E 2.75('Xp)-.814 G
+(rotocol to LBX protocol.)-2.75 E(It should be)5.5 E -.165(exe)138 157.2
+S(cuted on the same host as the client application or on a host connect\
+ed to the client host).165 E(by a f)138 170.2 Q(ast netw)-.11 E(ork.)
+-.11 E F2(lbxpr)5.5 E(oxy)-.495 E F0
+(appears to the clients using it as another X serv)2.75 E
+(er; that is, the)-.165 E(clients connect through it using the con)138
+183.2 Q -.165(ve)-.44 G(ntional DISPLA).165 E 2.75(Ys)-1.155 G
+(yntax, specifying the proxy)-2.75 E(host in place of the serv)138 196.2
+Q(er)-.165 E(.)-.605 E F2(lbxpr)5.5 E(oxy)-.495 E F0
+(can be used stand-alone or in conjunction with)2.75 E F2(pr)2.75 E(ox-)
+-.495 E(ymngr)138 209.2 Q F0(and)2.75 E F2(x\214ndpr)2.75 E(oxy)-.495 E
+F0 5.5(.S)C(ee the)-5.5 E F2(lbxpr)2.75 E(oxy)-.495 E F0
+(man page for further details.)2.75 E(proxymngr)72 225.8 Q F2(pr)17.116
+E(oxymngr)-.495 E F0(is a process that runs continuously to control oth\
+er proxy applications, such as)2.75 E F2(lbxpr)138 238.8 Q(oxy)-.495 E
+F0(and)2.75 E F2(xfwp)2.75 E F0 5.5(.I)C 2.75(tm)-5.5 G
+(aintains a list of acti)-2.75 E .33 -.165(ve p)-.275 H
+(roxy processes and responds to queries).165 E(from)138 251.8 Q F2
+(x\214ndpr)2.75 E(oxy)-.495 E F0 5.5(.S)C(ee the)-5.5 E F2(pr)2.75 E
+(oxymngr)-.495 E F0(man pages for further details.)2.75 E(x\214ndproxy)
+72 268.4 Q F2(x\214ndpr)17.721 E(oxy)-.495 E F0
+(is used to locate a running proxy process for a gi)2.75 E -.165(ve)
+-.275 G 2.75(nn).165 G(etw)-2.75 E(ork service, such as)-.11 E F2(lbxpr)
+138 281.4 Q(oxy)-.495 E F0(or)2.75 E F2(xfwp)2.75 E F0 2.75(,o)C 2.75
+(rt)-2.75 G 2.75(or)-2.75 G
+(equest that a proxy be started if one is not already running.)-2.75 E
+F2(x\214nd-)5.5 E(pr)138 294.4 Q(oxy)-.495 E F0(communicates with)2.75 E
+F2(pr)2.75 E(oxymngr)-.495 E F0(to perform the actual w)2.75 E(ork.)-.11
+E(xfwp)72 311 Q F2(xfwp)43.395 E F0(is the X \214re)2.75 E -.11(wa)-.275
+G(ll application proxy).11 E 5.5(.I)-.715 G 2.75(ti)-5.5 G 2.75(sd)-2.75
+G(esigned to run on a netw)-2.75 E(ork \214re)-.11 E -.11(wa)-.275 G
+(ll host).11 E(and relay X protocol between applications \(typically ou\
+tside the \214re)138 324 Q -.11(wa)-.275 G(ll\) and the X serv).11 E(er)
+-.165 E(\(inside the \214re)138 337 Q -.11(wa)-.275 G(ll\).).11 E F2
+(xfwp)5.5 E F0(appears to the clients using it as another X serv)2.75 E
+(er; that is, clients)-.165 E(connect through it using the con)138 350 Q
+-.165(ve)-.44 G(ntional DISPLA).165 E 2.75(Ys)-1.155 G(yntax.)-2.75 E F2
+(xfwp)5.5 E F0(will not do an)2.75 E(ything)-.165 E(useful without)138
+363 Q F2(pr)2.75 E(oxymngr)-.495 E F0(and)2.75 E F2(x\214ndpr)2.75 E
+(oxy)-.495 E F0(or)2.75 E F2(xrx)2.75 E F0 5.5(.S)C(ee the)-5.5 E F2
+(xfwp)2.75 E F0(man page for further details.)2.75 E(Xprt)72 379.6 Q F2
+(Xprt)45.837 E F0(is the print serv)2.75 E(er)-.165 E 2.75(,b)-.44 G
+(uilt as part of the Xserv)-2.97 E(er b)-.165 E(uild if the)-.22 E F1
+(XprtSer)2.75 E -.11(ve)-.11 G(r).11 E F0(con\214g option is)2.75 E 2.75
+(YES. The)138 392.6 R(print serv)2.75 E
+(er supports printing to PostScript and PCL de)-.165 E
+(vices, as well as raster)-.275 E(output to an)138 405.6 Q F2(xwd)2.75 E
+F0(format \214le \(and thence to an)2.75 E 2.75(yp)-.165 G(rinter that)
+-2.75 E F2(xpr)2.75 E F0 2.75(supports\). The)2.75 F(print e)2.75 E
+(xten-)-.165 E(sion w)138 418.6 Q(as designed to be inte)-.11 E
+(grated with the `)-.165 E(`video')-.814 E 2.75('s)-.814 G(erv)-2.75 E
+(er in a single process b)-.165 E(ut the R6.3)-.22 E
+(implementation does not support a combined video and print serv)138
+431.6 Q(er)-.165 E 5.5(.D)-.605 G(etails of con\214gura-)-5.5 E
+(tion for)138 444.6 Q F2(Xprt)2.75 E F0(are in)2.75 E F1
+(xc/doc/specs/Xser)2.75 E -.11(ve)-.11 G(r/Xprt.mif).11 E F0(\(FrameMak)
+2.75 E(er interchange source\) and)-.11 E F1(xc/doc/hardcopy/Xser)138
+457.6 Q -.11(ve)-.11 G(r/Xprt.PS.Z).11 E F0(\(compressed PostScript\).)
+2.75 E(xrx, libxrx)72 474.2 Q F2(xrx)19.558 E F0(is the W)2.75 E(eb bro)
+-.88 E
+(wser helper application that interprets documents in the RX MIME type)
+-.275 E(to remotely launch applications via the W)138 487.2 Q(eb)-.88 E
+5.5(.I)-.44 G(ts companion)-5.5 E F2(libxrx)2.75 E F0(is a plug-in for)
+2.75 E(Netscape Na)138 500.2 Q(vig)-.22 E(ator 3.0 that supports in add\
+ition the capability to visually embed the)-.055 E
+(remote applications in the associated bro)138 513.2 Q(wser W)-.275 E
+(eb page windo)-.88 E 4.18 -.715(w. S)-.275 H(ee the).715 E F2(xrx)2.75
+E F0(man page for)2.75 E(further details.)138 526.2 Q F1 2.75
+(3.16.1. Using)72 565.2 R(The LBX Pr)2.75 E(oxy)-.198 E F0
+(The implementation of)72 594.8 Q F2(lbxpr)2.75 E(oxy)-.495 E F0(pro)
+2.75 E
+(vided here will support an arbitrary number of clients connecting to)
+-.165 E(the same X serv)72 607.8 Q(er)-.165 E 5.5(.A)-.605 G(separate)
+-2.75 E F2(lbxpr)2.75 E(oxy)-.495 E F0
+(process is required for each separate X serv)2.75 E(er process.)-.165 E
+2.75(At)5.5 G(ypical)-2.75 E(command line to in)72 620.8 Q -.22(vo)-.44
+G -.11(ke).22 G F2(lbxpr)2.86 E(oxy)-.495 E F0(is)2.75 E/F3 11/Courier@0
+SF(lbxproxy :22 -display myhost:0)108 639.8 Q F0
+(This command runs a proxy with the X serv)72 662.4 Q(er `)-.165 E
+(`myhost:0')-.814 E 2.75('a)-.814 G 2.75(st)-2.75 G(he tar)-2.75 E 2.75
+(get. Clients)-.198 F(must connect to the)2.75 E(proxy using `)72 675.4
+Q(`proxyhost:22')-.814 E 2.75('a)-.814 G 2.75(st)-2.75 G(he DISPLA)-2.75
+E 5.588 -1.419(Y. T)-1.155 H
+(he .Xauthority \214le for these clients must contain an entry)1.419 E
+(for serv)72 688.4 Q(er `)-.165 E(`proxyhost:22')-.814 E 2.75('w)-.814 G
+(ith the same MIT)-2.75 E(-MA)-1.012 E(GIC-COOKIE as `)-.44 E
+(`myhost:0')-.814 E(', or the X serv)-.814 E(er must be)-.165 E
+(con\214gured to permit connections from an)72 701.4 Q 2.75(yh)-.165 G
+(ost on the netw)-2.75 E(ork.)-.11 E(16)300.5 769 Q EP
+%%Page: 17 21
+%%BeginPageSetup
+BP
+%%EndPageSetup
+/F0 11/Times-Roman@0 SF 2.75(XV)72 49 S(ersion 11, Release 6.3)-3.971 E
+2.75(XW)205.364 G(indo)-3.19 E 2.75(wS)-.275 G(ystem Release Notes)-2.75
+E(Here is an e)72 85 Q(xample sho)-.165 E(wing ho)-.275 E 2.75(wt)-.275
+G 2.75(os)-2.75 G(etup the appropriate .Xauthority entries:)-2.75 E/F1
+11/Courier@0 SF 6.6(%l)99.5 104 S(bxproxy :22 -display myws:0)-6.6 E 6.6
+(%x)99.5 117 S(auth list)-6.6 E 6.6
+(myws:0 MIT-MAGIC-COOKIE-1 7fd231ccdce2)99.5 130 R 6.6
+(myws/unix:0 MIT-MAGIC-COOKIE-1 7fd231ccdce2)99.5 143 R 6.6(%x)99.5 156
+S(auth -f $HOME/proxyauth add proxyhost:22 .)-6.6 E(7fd231ccdce2)13.2 E
+6.6(xauth: creating)99.5 169 R(new authority file /usr/myself/proxyauth)
+6.6 E 6.6(%x)99.5 182 S(auth -f $HOME/proxyauth)-6.6 E
+(add proxyhost/unix:22 .)13.2 E(7fd231ccdce2)13.2 E 6.6(%s)99.5 195 S
+(etenv XAUTHORITY $HOME/proxyauth)-6.6 E F0(In this e)72 217.6 Q
+(xample, the authorization tok)-.165 E
+(en for display 0 is copied into a ne)-.11 E 2.75<778c>-.275 G(le `)
+-2.75 E(`proxyauth')-.814 E 2.75('a)-.814 G(nd associated)-2.75 E
+(with the LBX proxy serv)72 230.6 Q(er display number \(22\).)-.165 E
+(The ne)5.5 E 2.75(wa)-.275 G
+(uthority \214le may then be copied to another)-2.75 E
+(host and used as the v)72 243.6 Q(alue of the XA)-.275 E(UTHORITY en)
+-.605 E(vironment v)-.44 E(ariable.)-.275 E(The)72 260.2 Q/F2 11
+/Times-Italic@0 SF(pr)2.75 E(oxymngr)-.495 E F0
+(daemon is usually con\214gured to in)2.75 E -.22(vo)-.44 G -.11(ke).22
+G F2(lbxpr)2.86 E(oxy)-.495 E F0(automatically when a user or a CGI)2.75
+E(script runs)72 273.2 Q F2(x\214ndpr)2.75 E(oxy -name LBX)-.495 E F0(.)
+A(See the)72 289.8 Q F2(lbxpr)2.75 E(oxy)-.495 E F0
+(man page for further details.)2.75 E/F3 11/Times-Bold@0 SF 2.75
+(3.17. Major)72 328.8 R(Additions to Existing Pr)2.75 E(ograms)-.198 E
+F0(The)72 358.4 Q F2 -.11(ge)2.75 G(ner).11 E(ate)-.165 E F0(option of)
+2.75 E F2(xauth)2.75 E F0
+(is used to obtain additional authorization tok)2.75 E
+(ens for client connections.)-.11 E(These authorization tok)72 371.4 Q(\
+ens may specify that the client using them is to be restricted in the o\
+perations that)-.11 E(may be performed in the X serv)72 384.4 Q(er)-.165
+E 5.5(.T)-.605 G(he authorization tok)-5.5 E
+(ens may be independently re)-.11 E -.22(vo)-.275 G -.11(ke).22 G 2.75
+(d. Refer).11 F(to the)2.75 E(SECURITY e)72 397.4 Q
+(xtension for further details on authorizations.)-.165 E(The)72 414 Q F2
+(xauth)2.75 E F0(man page gi)2.75 E -.165(ve)-.275 G 2.75(sf).165 G
+(ull details on the ne)-2.75 E 2.75(wg)-.275 G(enerate command.)-2.75 E
+(Here is an e)5.5 E(xample use:)-.165 E F1
+(xauth -f untrusted-auth-file g :0 . timeout 0)99.5 433 Q
+(setenv XAUTHORITY untrusted-auth-file)99.5 446 Q F0(This will cause)72
+465 Q F2(xauth)2.75 E F0(to contact serv)2.75 E(er `)-.165 E(`:0')-.814
+E 2.75('t)-.814 G 2.75(og)-2.75 G
+(et a long-lasting untrusted cookie which it then stores in)-2.75 E 2.75
+(untrusted-auth-\214le. By)72 478 R(setting XA)2.75 E
+(UTHORITY to point to untrusted-auth-\214le, subsequent applications)
+-.605 E(run from this shell to serv)72 491 Q(er :0 will be untrusted.)
+-.165 E(The `)5.5 E(`g')-.814 E 2.75('i)-.814 G 2.75(ss)-2.75 G
+(hort for `)-2.75 E(`generate')-.814 E(', and the `)-.814 E(`.)-.814 E
+1.628 -.814('' i)-.77 H 2.75(ss).814 G(hort for)-2.75 E -.814(``)72 504
+S(MIT).814 E(-MA)-1.012 E(GIC-COOKIE-1')-.44 E 2.75('. If)-.814 F
+(you omit the -f ar)2.75 E(gument,)-.198 E F2(xauth)2.75 E F0
+(will use $XA)2.75 E(UTHORITY \(or ~/.Xau-)-.605 E
+(thority\), which may not be what you w)72 517 Q
+(ant, especially if you are creating an untrusted auth.)-.11 E(This is)
+5.5 E(because)72 530 Q F2(xauth)2.75 E F0(will replace the trusted auth\
+ in ~/.Xauthority \(put there by xdm\) with the untrusted one, pre-)2.75
+E -.165(ve)72 543 S(nting you from making an).165 E 2.75(yf)-.165 G
+(urther trusted connections to the serv)-2.75 E(er)-.165 E(.)-.605 E
+(The)72 569 Q F2(xterm)2.75 E F0(terminal emulator no)2.75 E 2.75(ws)
+-.275 G(upports the acti)-2.75 E .33 -.165(ve i)-.275 H(con mode that w)
+.165 E(as in X v)-.11 E(ersion 10 Release 4.)-.165 E(See)5.5 E(the)72
+582 Q F2(xterm)2.75 E F0(man page for further details.)2.75 E
+(There is support in the)5.5 E F2(xterm)2.75 E F0(source to b)2.75 E
+(uild xterm without the)-.22 E(acti)72 595 Q .33 -.165(ve i)-.275 H
+(con mode for those who may care for some reason to not pro).165 E
+(vide it.)-.165 E F3 2.75(3.18. ANSI\214cation)72 634 R F0(As noted pre)
+72 663.6 Q(viously under `)-.275 E(`Con\214guration Files')-.916 E
+(', for pragmatic reasons we changed the w)-.916 E(ay we use)-.11 E .916
+(__)72 676.6 S -1.834(STDC_ _)-.916 F(to test for standard C compilers.)
+2.75 E(R6.1 w)5.5 E(as of)-.11 E
+(\214cially the last release that supported traditional)-.275 E(K&R C.)
+72 689.6 Q(R6.3 assumes a standard C compiler and en)5.5 E 2.75
+(vironment. W)-.44 F 2.75(eh)-.88 G -2.475 -.22(av e)-2.75 H
+(not intentionally remo)2.97 E -.165(ve)-.165 G 2.75(da).165 G -.165(ny)
+-2.75 G
+(K&R C support from old code; most of the release will continue to b)72
+702.6 Q(uild on older platforms.)-.22 E(17)300.5 769 Q EP
+%%Page: 18 22
+%%BeginPageSetup
+BP
+%%EndPageSetup
+/F0 11/Times-Roman@0 SF 2.75(XW)72 49 S(indo)-3.19 E 2.75(wS)-.275 G
+(ystem Release Notes)-2.75 E 2.75(XV)205.364 G(ersion 11, Release 6.3)
+-3.971 E/F1 11/Times-Bold@0 SF 2.75(4. Kno)72 85 R(wn Bugs)-.11 E F0
+(There are no e)72 114.6 Q(xamples in this release sho)-.165 E(wing ho)
+-.275 E 2.75(wt)-.275 G 2.75(ou)-2.75 G(se the print e)-2.75 E 2.75
+(xtension. CDE)-.165 F(2.1 has se)2.75 E -.165(ve)-.275 G(ral such).165
+E(applications.)72 127.6 Q/F2 11/Times-Italic@0 SF(lbxpr)72 144.2 Q(oxy)
+-.495 E F0 -.11(fa)2.75 G(ils to start on SCO Open Serv).11 E(er)-.165 E
+(.)-.605 E F2(x11perf)72 160.8 Q F0(running through)2.75 E F2(lbxpr)2.75
+E(oxy)-.495 E F0(will tickle a dra)2.75 E(wing b)-.165 E
+(ug in cfb-based X serv)-.22 E(ers that causes some lines)-.165 E
+(and curv)72 173.8 Q(es to be dra)-.165 E
+(wn to the wrong coordinates and outside the windo)-.165 E 2.75(wb)-.275
+G 2.75(oundaries. Use)-2.75 F(the)2.75 E F2(-no)2.75 E(gfx)-.11 E F0
+(option to)72 186.8 Q F2(lbxpr)2.75 E(oxy)-.495 E F0(as a w)2.75 E
+(orkaround on af)-.11 E(fected serv)-.275 E(ers.)-.165 E(If)72 203.4 Q
+F2(pr)2.75 E(oxymngr)-.495 E F0 -.165(ex)2.75 G
+(its abnormally all managed proxies die.).165 E
+(Documentation is missing on ho)72 220 Q 2.75(wt)-.275 G 2.75(ou)-2.75 G
+(se the v)-2.75 E(ertical writing and user)-.165 E
+(-de\214ned character support.)-.22 E(Documentation is sparse on ho)72
+236.6 Q 2.75(wt)-.275 G 2.75(oc)-2.75 G(on\214gure)-2.75 E F2(Xprt)2.75
+E F0(.)A(There are no e)72 253.2 Q(xample fonts in the release with v)
+-.165 E(ertical te)-.165 E(xt escapement \(`)-.165 E(`v)-.814 E
+(ertical writing fonts')-.165 E('\).)-.814 E F1 2.75(5. Filing)72 305.2
+R(Bug Reports)2.75 E F0(If you \214nd a reproducible b)72 334.8 Q
+(ug in softw)-.22 E(are in the)-.11 E F1(xc/)2.75 E F0(directory)2.75 E
+2.75(,o)-.715 G 2.75<728c>-2.75 G(nd b)-2.75 E(ugs in the)-.22 E F1(xc)
+2.75 E F0(documentation,)2.75 E(please send a b)72 347.8 Q
+(ug report to The Open Group using the form in the \214le)-.22 E F1
+(xc/b)2.75 E(ug-r)-.22 E(eport)-.198 E F0(and this destination)2.75 E
+(address:)72 360.8 Q(xb)108 379.8 Q(ugs@x.or)-.22 E(g)-.198 E
+(Please try to pro)72 402.4 Q(vide all of the information requested on \
+the form if it is applicable; the little e)-.165 E(xtra time)-.165 E
+(you spend on the report will mak)72 415.4 Q 2.75(ei)-.11 G 2.75(tm)
+-2.75 G(uch easier for someone to reproduce, \214nd, and \214x the b)
+-2.75 E(ug.)-.22 E(Bugs in the contrib)72 432 Q(uted softw)-.22 E
+(are that is a)-.11 E -.275(va)-.22 G
+(ilable on the net are not handled on an).275 E 2.75(yo)-.165 G -.275
+<668c>-2.75 G(cial basis.).275 E(Consult)5.5 E
+(the documentation for the indi)72 445 Q(vidual softw)-.275 E
+(are to see where \(if an)-.11 E(ywhere\) to report the b)-.165 E 2.75
+(ug. Man)-.22 F 2.75(ya)-.165 G(uthors)-2.75 E(of contrib)72 458 Q
+(uted softw)-.22 E(are subscribe to the mailing list `)-.11 E
+(`contrib-b)-.916 E(ugs')-.22 E 2.75('h)-.916 G(osted at x.or)-2.75 E
+(g, so this might be a)-.198 E(useful place to report b)72 471 Q 2.75
+(ugs. \(T)-.22 F 2.75(os)-.88 G(ubscribe to contrib-b)-2.75 E
+(ugs yourself, send email to contrib-b)-.22 E(ugs-)-.22 E(request@x.or)
+72 484 Q(g.\))-.198 E F1 2.75(6. Ackno)72 536 R(wledgements)-.11 E F0
+(Release 6.3 of X V)72 565.6 Q(ersion 11 w)-1.221 E
+(as brought to you by the X staf)-.11 E 2.75(fa)-.275 G 2.75(tt)-2.75 G
+(he X Consortium, Inc.: Donna Con)-2.75 E -.165(ve)-.44 G(rse).165 E
+(\(emeritus\), Jim F)72 578.6 Q(ournier)-.165 E 2.75(,S)-.44 G
+(tephen Gildea \(emeritus\), Kaleb K)-2.75 E(eithle)-.275 E 1.43 -.715
+(y, M)-.165 H(att Landau \(emeritus\), Arnaud Le).715 E
+(Hors, Ralph Mor \(emeritus\), Bob Schei\215er)72 591.6 Q 2.75(,R)-.44 G
+(alph Swick, Ray T)-2.75 E(ice, Mark W)-.385 E
+(elch \(emeritus\), and Da)-.88 E -.165(ve)-.22 G -.44(Wi)72 604.6 S
+(ggins \(emeritus\).).44 E -.275(Kev)5.5 G(in Samborn and Geor).275 E
+(ge Tsang \(emeritus\) of the CDE staf)-.198 E 2.75(fa)-.275 G 2.75(tXC)
+-2.75 G(onsortium, Inc.)-2.75 E -.11(wo)72 617.6 S(rk).11 E
+(ed hard on the print e)-.11 E(xtension, including the PostScript dri)
+-.165 E -.165(ve)-.275 G(r; Da).165 E(vid Kaelbling of the CDE staf)-.22
+E(f)-.275 E(con)72 630.6 Q -.165(ve)-.44 G -.198(rg).165 G
+(ed the X, Motif, and CDE imak).198 E
+(e/con\214g support and helped with Xos_r)-.11 E
+(.h; and Daniel Dardailler)-.605 E(\(emeritus\) of the CDE staf)72 643.6
+Q 2.75(fc)-.275 G(ontrib)-2.75 E(uted the libXt geometry tracing code.)
+-.22 E(Also, contractors Reed)5.5 E
+(Augliere, Roger Helmendach \(Liberty Systems\), and Ann Piche)72 656.6
+Q 2.75(ye)-.165 G(ach w)-2.75 E(ork)-.11 E(ed on critical components.)
+-.11 E(Se)72 673.2 Q -.165(ve)-.275 G(ral companies and indi).165 E
+(viduals ha)-.275 E .33 -.165(ve c)-.22 H(ooperated and w).165 E(ork)
+-.11 E(ed e)-.11 E(xtremely hard to mak)-.165 E 2.75(et)-.11 G
+(his release a)-2.75 E(reality)72 686.2 Q 2.75(,a)-.715 G
+(nd our thanks go out to them.)-2.75 E -1.21(Yo)5.5 G 2.75(uw)1.21 G
+(ill \214nd man)-2.75 E 2.75(yo)-.165 G 2.75(ft)-2.75 G
+(hem listed in the ackno)-2.75 E(wledgements in the)-.275 E(indi)72
+699.2 Q(vidual speci\214cations.)-.275 E -.275(Ke)72 715.8 S 2.75(nR)
+.275 G(aeb)-2.75 E(urn of XFree86 and Cygnus Support contrib)-.22 E
+(uted the gzip font compression support.)-.22 E(18)300.5 769 Q EP
+%%Page: 19 23
+%%BeginPageSetup
+BP
+%%EndPageSetup
+/F0 11/Times-Roman@0 SF 2.75(XV)72 49 S(ersion 11, Release 6.3)-3.971 E
+2.75(XW)205.364 G(indo)-3.19 E 2.75(wS)-.275 G(ystem Release Notes)-2.75
+E(The Common Desktop En)72 85 Q
+(vironment sponsors Digital Equipment Corp, Fujitsu, He)-.44 E(wlett-P)
+-.275 E(ackard, Hitachi,)-.165 E(IBM, No)72 98 Q -.165(ve)-.165 G
+(ll, and SunSoft jointly contrib).165 E(uted the print e)-.22 E
+(xtension and the Xlib v)-.165 E(ertical writing and user)-.165 E(-)-.22
+E(de\214ned character support.)72 111 Q(Ax)5.5 E(el Deininger)-.165 E
+2.75(,H)-.44 G(arry Phinne)-2.75 E 1.43 -.715(y, T)-.165 H
+(om Gilg, Charles Prince, and Jim Miller all)-.165 E(from He)72 124 Q
+(wlett-P)-.275 E(ackard did the print e)-.165 E
+(xtension and PCL and raster dri)-.165 E -.165(ve)-.275 G 2.75
+(rs. Fujitsu).165 F(did the Xlib v)2.75 E(ertical)-.165 E
+(writing and user)72 137 Q(-de\214ned character support.)-.22 E(19)300.5
+769 Q EP
+%%Page: 20 24
+%%BeginPageSetup
+BP
+%%EndPageSetup
+/F0 11/Times-Roman@0 SF 2.75(XW)72 49 S(indo)-3.19 E 2.75(wS)-.275 G
+(ystem Release Notes)-2.75 E 2.75(XV)205.364 G(ersion 11, Release 6.3)
+-3.971 E(20)300.5 769 Q EP
+%%Trailer
+end
+%%EOF
diff --git a/Xserver/RELNOTES.TXT b/Xserver/RELNOTES.TXT
new file mode 100644 (file)
index 0000000..8e47fef
--- /dev/null
@@ -0,0 +1,1301 @@
+
+
+
+
+
+
+
+
+
+                     X Window System, Version 11
+                             Release 6.3
+
+                            Release Notes
+
+
+
+
+
+
+
+
+                          X Consortium, Inc.
+
+                          December 23, 1996
+
+
+
+
+
+
+
+
+
+
+Copyright c 1996 X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a
+copy of        this software and associated documentation files (the
+"Software"), to        deal in the Software without restriction, including
+without        limitation the rights to use, copy, modify, merge, publish, dis-
+tribute, sublicense, and/or sell copies        of the Software, and to permit
+persons        to whom the Software is furnished to do so, subject to the fol-
+lowing conditions:
+
+The above copyright notice and this permission notice shall be included
+in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS        PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES        OF MERCHANTABIL-
+ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT
+SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM,        DAMAGES OR OTHER LIABIL-
+ITY, WHETHER IN        AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION        WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+IN THE SOFTWARE.
+
+Except as contained in this notice, the        name of the X Consortium shall
+not be used in advertising or otherwise        to promote the sale, use or
+other dealings in this Software        without prior written authorization from
+the X Consortium.
+
+X Window System        is a trademark of X Consortium, Inc.
+
+
+
+1.  What Is Release 6.3
+
+
+This is        the last X Consortium implementation of the X Window System.  X
+is a vendor-neutral, system-architecture neutral network-transparent
+window system and user interface standard.  X runs on a        wide range of
+computing and graphics machines.  For an overview of X,        see the X manual
+page.
+
+R6.3 is        an update to R6.1.  It is compatible with R6 and R6.1 at the
+source and protocol levels in all respects, and        binaries are upward-
+compatible.
+
+What about Release 6.2?         Release 6.2 is a proper subset of Release 6.3
+produced at the        request of the OSF Common Desktop Environment program.
+It was produced        by the X Consortium and is being released by OSF simul-
+taneously with CDE 2.1.         Release 6.2 contains only the print extension
+and the        Xlib implementation of vertical writing and user-defined charac-
+ter support.
+
+The X Consortium was an        independent, not-for-profit membership corpora-
+tion formed in 1993 as the successor to        the MIT X Consortium and dis-
+solved at the end of 1996.  Refer to the Consortium man        page for addi-
+tional details about the X Consortium.
+
+See xc/INSTALL.PS (PostScript) or xc/INSTALL.TXT (plain        text) for
+instructions on        how to build and install this software.
+
+
+1.1.  Overview of the X        Consortium Release
+
+
+The X Consortium software and documentation in Release 6.3 is in direc-
+tory xc/ and contains the following:
+
+X Consortium Standards
+     The X Consortium produced standards:  documents which define net-
+     work protocols, programming interfaces, and other aspects of the X
+     environment.  See the XStandards manual page for a        list of stan-
+     dards.
+
+Implementations
+     For most of our standards,        we provide high-quality implementations
+     to        demonstrate proof of concept and to give early adopters and ven-
+     dors a base to use.  These        are not reference implementations; the
+     written specifications define the standards.
+
+Fonts
+     A collection of bitmap and        outline fonts are included in the dis-
+     tribution,        contributed by various individuals and companies.
+
+Utility        Libraries
+     A number of libraries, such as Xmu        and the Athena Widget Set, are
+     included. These are not standards, but are used in building X Con-
+     sortium applications and may be useful in building        other applica-
+     tions.
+
+Programs
+     We        also provide a number of application programs.  A few of these
+     programs, such as xdm (or its equivalent),        should be considered
+     essential in almost all environments.  The        rest of the applications
+     carry no special status; they are simply programs that have been
+     developed and/or maintained by X Consortium staff.         In some cases,
+     you will find better substitutes for these        programs contributed by
+     others.
+
+
+1.2.  Supported        Systems
+
+
+We built and tested this release on the        following systems:
+
+
+       AIX 4.2
+       Digital Unix 4.0A
+       HP-UX 10.01
+       IRIX 6.2
+       Solaris 2.5
+       UNIX System V/386 Release 4.2 (Novell UnixWare) Version 2.02
+
+We also        built this release on the following and did some minimal test-
+ing:
+
+       FreeBSD 2.1.6
+       Linux 1.2.13 (Yggdrasil) and 2.0.0 (Slackware 3.1)
+       SCO Open Server 5.0
+       SunOS 4.1.4
+       Windows NT 4.0
+
+
+In all cases except SunOS we have used the vendor's compiler.  On SunOS
+we build with gcc.
+
+
+1.2.1. Supported Display Devices
+
+
+This release includes the necessary device-dependent support to        build a
+native X server        for the following platforms:
+
+       XFree86: See the XF_* man pages for supported video cards
+
+       AIX: Xibm with Skyway display adapter
+       HP-UX: Xhp
+       Digital Unix: Xdec on Alpha AXP with PMAG-B frame buffer
+       SunOS/Solaris: Xsun -- see the Xsun man page for supported frame buffers
+       Ultrix[1] :Xdec
+
+In addition to the above, the Xvfb and Xnest servers can be built on
+most platforms.
+
+Native servers are not built on        IRIX or Microsoft Windows NT.
+
+
+1.3.  The XC Tree
+
+
+The general layout under xc/ is        as follows:
+
+
+config/                    config files, imake, makedepend, build utilities
+doc/               all documentation other than per-program manual pages
+fonts/             BDF, Speedo, Type1 fonts
+include/           include files shared by multiple directories
+lib/               all libraries
+nls/               national language support files
+programs/          all programs, including the X server and rgb
+util/              patch, compress, other utilities
+bug-report         bug reporting template
+registry           X Registry
+
+
+This file is xc/RELNOTES.*, in various formats.         The documentation
+source files RELNOTES.ms and INSTALL.ms        are in the xc/doc/misc/ direc-
+tory.
+
+
+1.4.  X        Registry
+
+
+The X Consortium maintained a registry of certain X-related items to aid
+in avoiding conflicts and to aid in sharing of such items.
+
+The registry is        in the file xc/registry in the distribution.  The latest
+version        may also be available by sending a message to xstuff@x.org.  The
+message        can have a subject line and no body, or a single-line body and
+no subject; in either case the line should look        like this:
+
+       send docs registry
+
+
+
+1.5.  Extensions Supported
+
+
+The core distribution includes the following extensions:  BIG-REQUESTS,
+DOUBLE-BUFFER, LBX, MIT-SHM, MIT-SUNDRY-NONSTANDARD, Multi-Buffering,
+RECORD,        SECURITY, SHAPE, SYNC, X3D-PEX, XC-APPGROUP, XC-MISC, XFree86-
+VidModeExtension, XIE, XInputExtension,        XKEYBOARD, XpExtension (print-
+ing), XTEST, and XTestExtension1.
+
+Not all        of these extensions are standards; see the XStandards manual
+page.  Some of these extensions        are not supported on all platforms.
+
+
+1.6.  Implementation Parameters
+
+
+Some of        the specifications define some behavior as implementation-
+dependent.  Implementations of X Consortium standards need to document
+how those parameters are implemented; this section does        so.
+
+XFILESEARCHPATH        default
+     This default can be set at        build time by setting the imake vari-
+     ables XFileSearchPathDefault, XAppLoadDir,        XFileSearchPathBase, and
+     ProjectRoot in site.def.  See xc/config/cf/README for instructions
+     and xc/config/cf/X11.tmpl[2] for details of how these configuration
+     variables are used.
+
+     By        default ProjectRoot is /usr/X11R6.3 and XFILESEARCHPATH has
+     these components:
+
+            /usr/X11R6.3/lib/X11/%L/%T/%N%C%S
+            /usr/X11R6.3/lib/X11/%l/%T/%N%C%S
+            /usr/X11R6.3/lib/X11/%T/%N%C%S
+            /usr/X11R6.3/lib/X11/%L/%T/%N%S
+            /usr/X11R6.3/lib/X11/%l/%T/%N%S
+            /usr/X11R6.3/lib/X11/%T/%N%S
+
+
+XUSERFILESEARCHPATH default
+     If        the environment variable XAPPLRESDIR is defined, the default
+     value of XUSERFILESEARCHPATH has the following components:
+
+            $XAPPLRESDIR/%L/%N%C
+            $XAPPLRESDIR/%l/%N%C
+            $XAPPLRESDIR/%N%C
+            $HOME/%N%C
+            $XAPPLRESDIR/%L/%N
+            $XAPPLRESDIR/%l/%N
+            $XAPPLRESDIR/%N
+            $HOME/%N
+
+     Otherwise it has these components:
+
+            $HOME/%L/%N%C
+            $HOME/%l/%N%C
+            $HOME/%N%C
+            $HOME/%L/%N
+            $HOME/%l/%N
+            $HOME/%N
+
+
+XKEYSYMDB default
+     Defaults to /usr/X11R6.3/lib/X11/XKeysymDB, assuming ProjectRoot is
+     set to /usr/X11R6.3.
+
+XCMSDB default
+     Defaults to /usr/X11R6.3/lib/X11/Xcms.txt,        assuming ProjectRoot is
+     set to /usr/X11R6.3.
+
+XLOCALEDIR default
+     Defaults to the directory /usr/X11R6.3/lib/X11/locale, assuming
+     ProjectRoot is set        to /usr/X11R6.3.  The XLOCALEDIR variable can
+     contain multiple colon-separated pathnames.
+
+XErrorDB location
+     The Xlib error database file is /usr/X11R6.3/lib/X11/XErrorDB,
+     assuming ProjectRoot is set to /usr/X11R6.3.
+
+XtErrorDB location
+     The Xt error database file        is /usr/X11R6.3/lib/X11/XtErrorDB,
+     assuming ProjectRoot is set to /usr/X11R6.3.
+
+Supported Locales
+     X locales supported are in        locale.dir; the mapping between various
+     system locale names and X locale names is in locale.alias.         Both
+     files are shipped in the xc/nls/X11/locale/ directory and installed
+     in        the XLocaleDir directory (e.g. /usr/X11R6.3/lib/X11/locale/).
+
+Input Methods supported
+     The core distribution does        not include any input method servers.
+     However, Xlib supplies a default built-in input method that sup-
+     ports compose processing in 8-bit locales.         Compose files are pro-
+     vided for Latin-1 and Latin-2.  The built-in input        method can sup-
+     port other        locales, given suitable compose files.  See
+     xc/nls/X11/locale/Compose/iso8859-* for the supported compositions.
+
+There are input        method servers available on the net.
+
+
+
+2.  What is Unchanged in Release 6.3
+
+
+As this        is an update release, there is a great deal of stability in the
+standards, libraries, and clients.  No existing        standards other than the
+ICE library specification have changed in a material way, though several
+documents have been updated with editorial improvements.  There        is one
+new interface added to the ICE library libICE; see below.  The extension
+library, libXext, is updated to        include the LBX, security, and applica-
+tion group extension interfaces.  All previous interfaces in these and
+all other libraries are        unchanged.
+
+
+
+3.  What Is New        in Release 6.3
+
+
+This section describes changes in the X        Consortium distribution since
+Release        6.1.
+
+All libraries, protocols, and servers are compatible with Release 6 and
+Release        6.1.  That is, R6 and R6.1 clients and applications will work
+with R6.3 libraries and        servers.  Most R6.3 clients will work with R6.1
+and R6 libraries except        those that use the new interfaces in libICE,
+libXext, and libXp.
+
+The major new functionality in R6.3 is support for World Wide Web
+integration, protection        of data from ``untrusted'' client connections, a
+bandwidth- and latency-optimized protocol for using X across the Inter-
+net, a print protocol following        the Xlib API, and support for vertical
+text writing and user-defined characters in the        Xlib implementation.
+
+
+3.1.  OS Support
+
+
+The following platforms        have a newer operating system version supported:
+
+
+System        R6.1           R6.3
+
+AIX           4.1.4          4.2
+Digital        Unix   3.2C           4.0A
+HP-UX         10.01
+IRIX          5.3            6.2
+Solaris               2.4            2.5
+UnixWare       2.02
+
+
+We also        built on the following platforms, however full support is not
+guaranteed:
+
+
+System        R6.1           R6.3
+
+FreeBSD               2.1.0          2.1.6
+Linux         1.2.13         2.0
+SCO Open Server                      5.0
+SunOS         4.1.3          4.1.4
+Windows        NT     3.5            4.0
+
+
+
+3.2.  New Standards
+
+
+The following are new X        Consortium standards in Release 6.3.  Each is
+described in its own section below.
+
+       Low Bandwidth X Extension
+       RX: X Remote Execution MIME type
+       Security Extension
+       Application Group Extension
+       Print Extension
+       Proxy Management Protocol
+
+
+
+3.3.  Low Bandwidth X Extension
+
+
+The Low        Bandwidth X extension (LBX) defines several compression and
+local caching techniques to improve performance        on wide area networks
+and also on slower-speed connections.  These reduce the        amount of proto-
+col data transported over the network and reduce the number of client-
+to-server roundtrips required for common application startup operations.
+
+LBX was        referred to as X.fast in some materials but we elected to not go
+through        the implementation and change all the names.  To avoid any con-
+fusion with an external        name different from the internal name in the
+implementation,        we elected to drop the ``X.fast'' moniker.
+
+LBX is implemented in two pieces; an X server extension        and a proxy
+application.  The X server extension provides the new optimized        proto-
+col.  The proxy        application, lbxproxy, translates a normal client X pro-
+tocol stream into an LBX stream.  This permits any existing application
+to gain        the benefit of the optimized protocol with no changes.  The
+proxy is especially useful when        multiple applications are running on the
+same local area        network separated from the X server by a slower network.
+In this        case the full benefit of the local cache is shared by each
+application using the same proxy process.
+
+The specification for LBX is in        xc/doc/specs/Xext/lbx.mif (FrameMaker
+interchange source) and        xc/doc/hardcopy/Xext/lbx.PS.Z (compressed
+PostScript).
+
+
+3.4.  RX: X Remote eXecution
+
+
+The remote execution (RX) service specifies a MIME format for invoking
+applications remotely, for example via a World Wide Web        browser.  This
+RX format specifies a syntax for listing network services required by
+the application, for example an        X display server.  The requesting Web
+browser        must identify specific instances of the services in the request
+to invoke the application.
+
+The distribution contains a helper program (xrx) and a Netscape        Naviga-
+tor plug-in (libxrx) that demonstrate this protocol.  The plug-in
+requires Navigator 3.0.
+
+We have        only been able to test the plug-in on HP-UX, IRIX, Digital Unix,
+and Solaris2.  Netscape        Navigator binaries for other platforms are
+either not available at        all or were not available in time to be included
+in the testing for this        release.
+
+The specification for the RX mime type is in xc/doc/specs/RX/RX.mif
+(FrameMaker interchange        source) and xc/doc/hardcopy/RX/RX.PS.Z
+(compressed PostScript).
+
+The following section describes        the procedure to set up your environment
+and try        the examples provided in this distribution.
+
+
+3.4.1. Preparing Your Web Server
+
+
+In order to demonstrate        the RX helper program and the RX Netscape plug-
+in you need to have access to an HTTP server to        install ``common gateway
+interface'' (CGI) scripts.  While CGI programs can be written in any
+compiled or interpreted        language, the sample CGI programs in the distri-
+bution are written in perl.
+
+If you don't currently have a web server the NCSA server is a good one
+to try.         Binaries for various systems are available at:
+
+     http://hoohoo.ncsa.uiuc.edu/docs/setup/PreExec.html
+
+If you don't have perl you can get the source code from:
+     ftp://prep.ai.mit.edu/pub/gnu/perl-4.036.tar.gz
+
+You need to install the        HTML, RX, and CGI sample files into your
+server's HTML and CGI directories.  The        process can be partially
+automated by adding the        following definitions to your site.def or
+host.def file:
+
+
+WebServer      defines the hostname and        port of your web server, for
+              example
+
+              #define WebServer www.myorg.org:8001
+
+HtmlDir               defines the path at which HTML and RX documents are
+              installed, for example
+
+              #define HtmlDir /usr/local/etc/httpd/htdocs
+
+CgiBinDir      defines the path        at which CGI programs are installed, for
+              example
+
+              #define CgiBinDir /usr/local/etc/httpd/cgi-bin
+
+ProxyManager   defines the transport scheme, hostname, and port        for CGI
+              programs to contact the Proxy Manager.  See the proxymngr
+              man pages for further details.  Typically the proxy
+              manager host will be the same as your web server, for
+              example:
+
+              #define ProxyManager tcp/www.myorg.org:6500
+
+Then make the Makefiles        and build the directories with the following
+command        sequence:
+
+cd xc/programs/xrx/htdocs
+xmkmf ../../.. programs/xrx/htdocs
+make
+make install
+cd ../cgi-bin
+xmkmf ../../.. programs/xrx/cgi-bin
+make
+make install
+
+
+These directories are not automatically        built or installed by the top
+level Makefile because they install outside the        ProjectRoot.
+
+You also need to configure your        web server so that files with the exten-
+sion name ``rx'' are of        the MIME type ``application/x-rx''.  See your
+HTTP server's configuration documentation for the right        procedure to do
+so.
+
+
+3.4.2. The RX Helper Program
+
+
+The helper program, xrx, may be        used with any Web browser to interpret
+the new        RX document type.
+
+The RX helper program is installed in <ProjectRoot>/bin        (e.g.
+/usr/X11R6.3/bin/).  You will need to configure        your web browser to use
+it for RX documents by adding a        line to your $HOME/.mailcap:
+
+     application/x-rx; /X11/bin/xrx %s
+
+You may        need to refer to your web browser's documentation for exact
+instructions on        configuring helper applications.
+
+The helper program is activated        by your browser as soon as you retrieve
+any document of        the MIME type application/x-rx. All you need to do is to
+point your browser at the URL:
+     http://your.web.server/xload.rx
+
+The application        (i.e. xload) should appear on your DISPLAY as a new
+top-level client.  The client will be running on your web server host
+and connected to your X        server.  If your X server supports the SECURITY
+extension the client will be running as        an untrusted client.
+
+
+3.4.3. The RX Netscape Navigator Plug-in
+
+
+The Navigator plug-in supports all the functions of xrx        and in addition
+uses the new XC-APPGROUP extension, if your X server provides it, to
+cause the remotely launched application        to be embedded within the
+browser        page from which it was launched.
+
+The HTML page links to an RX document via the EMBED tag, a Netscape
+extension to HTML.  The        RX document provides the plug-in with the list
+of services the        application wants to use.  Based on this information,
+the plug-in sets the various requested services, including creating
+authorization keys, and        passes the relevant data to the application
+through        an HTTP GET request of the associated CGI script.  The Web
+server then executes the CGI script to start the application.
+
+To be able to use the RX plug-in you need Netscape Navigator 3.0.
+Binaries for various systems can be found at:
+
+     http://home.netscape.com/comprod/mirror/client_download.html
+
+To complete the        installation of the Netscape plug-in, find the file
+named libxrx.so.6.3 or libxrx.sl.6.3 (or similar, depending on your
+platform) in <ProjectRoot>/lib (e.g. /usr/X11R6.3/lib) and copy        it to
+either /usr/local/lib/netscape/plugins or $HOME/.netscape/plugins. Do
+not install the        symlinks libxrx.so or libxrx.sl; they may confuse
+Netscape.
+
+You should remove or comment out the line you may have previously added
+in your        mailcap file to use the RX helper program, otherwise the plug-in
+will not be enabled.  (The usual comment character for mailcap is
+``#''.)
+
+If you are already running Netscape Navigator, you need        to exit and res-
+tart it        after copying the plug-in library so the new plug-in will be
+found. Once this is done you can check that Navigator has successfully
+loaded the plug-in by checking the ``About Plug-ins'' page from        the Help
+menu. This should show something like:
+
+
+                                  RX Plug-in
+
+    File name: /usr/guest/netscape/plugins/libxrx.sl.6.3
+
+    X Remote Activation        Plug-in
+
+    Mime Type Description         Suffixes  Enabled
+    application/x-rx              X Remote Activation Plug-inxrxYes
+
+
+The plug-in will be activated by Netscape Navigator as soon as you
+retrieve any document of the MIME type application/x-rx.  Several sam-
+ples are included in the distribution. The most        basic one is xload. All
+you need to do is point        your browser at the page:
+     http://your.web.server/xload.html
+
+If something goes wrong        check on the all the previous steps listed above
+and try        again.  Once xload is working you can try some of the other
+examples in the        distribution such as bitmap.html or dtcm.html.
+
+
+3.4.4. Trying Embedding With an Old X Server
+
+
+The Netscape Navigator plug-in,        libxrx, will work with an X server that
+does not contain the application group or security extensions. The
+application will be started as a separate top-level client.
+
+If you wish to try out the embedding facilities        without replacing your
+desktop        X server, you may use the Xnest server.
+
+A typical Xnest        session would look like the following:
+
+% Xnest        :11
+% xterm        -display :11
+
+
+These two commands start a ``nested'' server and a terminal emulator
+within that server.  Your favorite window manager and Netscape Navigator
+can now        be executed from the nested xterm window.  You may wish to first
+disable        access control in the nested server by running ``xhost +'' in
+the nested xterm.
+
+
+3.4.5. Setting Up Your Own Applications To Run Over The Web
+
+
+Based on the examples provided in the distribution it should be        easy to
+set up your web        server to run your own applications.  Every application
+requires 3 additional files to identify        it to Web browsers:
+
+myapp.htmlAn HTML page to present the application embedded
+myapp.rx  The RX document describing the application
+myapp.pl  The CGI script to start the application
+
+Note that the separate ``.rx'' file could be omitted by        implementing the
+CGI script such        that if it is invoked without a QUERY_STRING it will
+return the RX content. We decided not to do so in the distributed exam-
+ples for purpose of clarity.
+
+The xload demo provides        a good starting point. Simply make a copy of
+each of        the files xload.rx, xload.html, and xload.pl. Then look inside
+them for every instance        of ``xload'' and change it to whatever is
+appropriate for        your application.
+
+You will not be        able to run the dtcm demo unless you have dtcm (a CDE
+component) installed on        your web server host.  This example shows how a
+CGI script would look when an X        Print server is requested. The script
+dtcm.pl        is, for that reason, slightly more complicated than other exam-
+ples.
+
+
+3.5.  Security Extension
+
+
+The SECURITY extension contains        new protocol needed to provide enhanced
+X server security.  This extension adds        to the X protocol the concepts
+of ``trusted'' and ``untrusted'' clients.  The trust status of a client
+is determined by the authorization used        at connection setup.  All
+clients        using host-based authorization are considered ``trusted''.
+Clients        using other authorization protocols may be either trusted or
+untrusted depending on the data        included in the connection authorization
+phase.
+
+The requests in        the security extension permit a trusted client to create
+multiple authorization entries for a single authorization protocol.
+Each entry is tagged with the trust status to be associated with any
+client presenting that authorization.
+
+When a connection identifying an ``untrusted'' client is accepted, the
+client is restricted from performing certain operations        that would steal
+or modify data that is held by the server for trusted clients. An
+untrusted client performing a disallowed operation will        receive protocol
+errors.         Such a client may be written to catch these errors and continue
+operation.
+
+When a client is untrusted, the        server will also limit the extensions
+that are available to the client.  Each        X protocol extension is respon-
+sible for defining what        operations are permitted to untrusted clients;
+by default, the        entire extension is hidden.
+
+The specification for the SECURITY extension is        in
+xc/doc/specs/Xext/security.tex (LaTeX source) and
+xc/doc/hardcopy/Xext/security.PS.Z (compressed PostScript).
+
+
+3.5.1. Untrusted Application Behavior
+
+
+Most applications work normally        when run as untrusted clients, but since
+the security extension changes the semantics of        certain parts of the X
+protocol, it is        no surprise that some clients behave differently when
+untrusted.  We note the        following significant behavior changes,
+separated into two categories: changes that we expect could disappear or
+mutate if the implementation were improved in a        future release, and
+changes        we expect are permanent, legitimate defenses against data loss
+or leakage.
+
+
+3.5.1.1.  Behaviors That Are Implementation-Dependent
+
+
+The following behaviors        when running the respective applications as
+untrusted are not mandated by the security design but are side effects
+of limitations in the current implementation.
+
+oclock is square because the SHAPE extension hasn't been marked        secure
+yet.  Similarly, Xaw applications that use oval        buttons will have rec-
+tangular buttons instead.
+
+Any application        that depends on an extension other than XC-MISC, LBX, or
+BIG-REQUESTS will have different behavior, as no other extensions are
+currently marked secure.  The core clients affected are        xieperf and all
+the xkb        utilities.
+
+emacs exits with a Window error        when trying to use the QueryPointer
+request        on the root window when you click in a buffer.
+
+FrameMaker, and        xwd -root both exit with a Window error when trying to
+use the        GetWindowAttributes request on a window manager frame window.
+
+All the        remaining changes are involved in some way with window proper-
+ties.  Some of these behaviors can be modified with changes to the Secu-
+rityPolicy file; see the Xserver man page.
+
+Several        clients exit with a Window error when trying to use the
+DeleteProperty request on various properties on        the root window.  These
+include        xcmsdb -remove, xprop -root -remove, and xstdcmap -delete.
+
+xprop exits with an Atom error when attempting to access protected pro-
+perties.
+
+The following two changes require, in addition,        a ``trusted selection
+intermediary'' to provide selection transfer from untrusted to trusted
+clients        (and vice-versa).  R6.3 does not include such a trusted
+intermediary.
+
+xterm exits with an Atom error when it tries to        store the property value
+during a selection transfer (paste) to a trusted selection requester.
+
+The ``copy 0 to        PRIMARY'' button of xcutsel does not work.
+
+Selection transfer from        untrusted clients to trusted clients fails when
+the untrusted client attempts to use SendEvent to generate the Selec-
+tionNotify event for the requester.  Most requesters will treat        this as
+a transfer timeout and continue.  Xt-based applications        will create an
+additional Atom        each time such a transfer is attempted.
+
+
+3.5.1.2.  Behaviors That Are Not Likely        To Change
+
+
+The following behaviors        represent actions performed by the applications
+that are disallowed by design.
+
+editres        will fail when pointed at a trusted client when it tries to read
+window properties on a window owned by that client.
+
+Xnest exits on startup with an Access error as it tries        to use the
+ChangeKeyboardControl request.
+
+The new        generate option to xauth fails because untrusted applications
+are not        allowed to create additional authorizations.
+
+xhost cannot be        used to modify the host access list.
+
+xmag gets an unending stream of        Drawable errors as it tries to use the
+PolyRectangle request on the root window.  If you click        to select a
+location to magnify, xmag gets a Drawable error        as it tries to use the
+GetImage request on the        root window.  xmag could be modified to exit
+gracefully under these conditions.
+
+netscape exits on startup with a Drawable error        when trying to use the
+GetImage request on the        root window.
+
+xmodmap        exits with an Access error when trying to use the ChangeKey-
+boardMapping request.
+
+xset with the b, c, led, or r options exits with an Access error when
+trying to use the ChangeKeyboardControl        request.  With the bc option, it
+can't find the MIT-SUNDRY-NONSTANDARD extension        and exits gracefully.
+
+xsetroot exits with a Window error when        trying to use the ChangeWin-
+dowAttributes request on the root window.
+
+
+3.6.  Application Group        Extension
+
+
+The application        group extension (XC-APPGROUP) provides new protocol to
+implement Application Groups (``AppGroups'').  The AppGroup facility
+allows other clients to        share the SubstructureRedirect mechanism with
+the window manager.  This allows another client        called the ``application
+group leader'',        such as a web browser, to intercept a MapRequest made by
+a third        application and reparent its window into the web browser before
+the window manager takes control.  The AppGroup        leader may also limit
+the screens and        visuals available to the applications in the group.
+
+Users who have an XC-APPGROUP enhanced X server        and an RX plug-in for
+their Netscape Navigator web browser can run programs remotely over the
+web and        have the output appear as part of the presentation in their web
+browser.
+
+The only way for an application        to become a member of an AppGroup is by
+using an authorization generated using the new security        extension.
+Whenever an application        connects to the server, the authorization that
+it used        to connect is tested to see if it belongs to an AppGroup. This
+means that the Authorization data must be transmitted to the remote host
+where the application will be run. In the case of RX, HTTP is used to
+send the Authorization.         Sites who have concerns about sending unen-
+crypted        authorization data such as MIT-MAGIC-COOKIE-1 via HTTP should
+configure their        web servers and web browsers to use SHTTP or SSL.
+
+The specification for the XC-APPGROUP extension        is in
+xc/doc/specs/Xext/AppGroup.mif (FrameMaker interchange source) and
+xc/doc/hardcopy/Xext/AppGroup.PS.Z (compressed PostScript).
+
+
+3.7.  Print Extension
+
+
+The print extension supports output to hardcopy        devices using the core X
+drawing        requests.  The print extension adds requests for job and page
+control        and defines how specific printer attributes are communicated
+between        the server and printing clients.  Printer attribute specifica-
+tions are modeled after        the ISO 10175 specification.
+
+An X client that wants to produce hardcopy output will typically open a
+second connection to an        X print server, produce a print job, and then
+close the print        server connection.  The print server may be the same
+process        as the display server (the term ``video server'' is sometimes
+used) although the implementation provided in R6.3 does        not completely
+support        video and print servers in the same binary.
+
+The specification for the print        extension is in
+xc/doc/specs/XPRINT/xp_proto.mif (FrameMaker interchange source) and
+xc/doc/hardcopy/XPRINT/xp_proto.PS.Z (compressed PostScript).  The
+library        API specification is in xc/doc/specs/XPRINT/xp_library.mif
+(FrameMaker interchange        source) and
+xc/doc/hardcopy/XPRINT/xp_library.PS.Z (compressed PostScript).
+
+
+3.7.1. Running an X Print Server
+
+
+The print server is simply an X        server with the print extension and spe-
+cial DDX implementations.  The X Print Server is started like any other
+X server.
+
+Here is        a sample command line for use with a typical configuration:
+
+% Xprt :1 -ac
+
+
+The options used in the        example are:
+
+:1       On a host that is running a video display server you will need
+         to specify a different display from the default.
+
+-ac      Disable access control, since no simple mechanism for sharing
+         keys is provided.
+
+The X print server supports the        following additional options:
+
+-XpFile          Points to the directory containing the print server configura-
+         tion files.
+
+XPCONFIGDIREnvironment variable        specifying alternative location of the
+         print server configuration files.
+
+The print server, Xprt,        is built only if the config option XprtServer is
+YES.  Four printer DDXen are provided, each with a separate config
+option to control whether or not it will be included: XpRasterDDX,
+XpColorPclDDX, XpMonoPclDDX, XpPostScriptDDX; see xc/config/cf/README.
+XprtServer defaults to the value of BuildServer        (i.e. Xprt will be built
+by default on all platforms that build a full X        server).  XpRasterDDX
+and XpMonoPclDDX default to NO.         XpColorPclDDX and XpPostScriptDDX
+default        to YES.
+
+The print server is configured through a directory of configuration
+files that define printer model        types and instances of printer models.
+An example configuration tree is provided in
+xc/programs/Xserver/XpConfig/. See also xc/doc/specs/Xserver/Xprt.mif
+(FrameMaker interchange        source) and xc/doc/hardcopy/Xserver/Xprt.PS.Z
+(compressed PostScript)        for further instructions on configuring Xprt.
+
+
+3.7.2. Specifying The Print Server To A Client
+
+
+By convention, clients locate the print        server using the environment
+variable XPRINTER.  The        syntax of XPRINTER is an augmented DISPLAY; i.e.
+
+     printerName@host:display
+
+where ``printerName'' is one of        the printer instances listed in the
+print server configuration files.  The use of XPRINTER and its syntax is
+an application convention only;        there is nothing in the supplied
+libraries that uses (or        parses) this environment variable.
+
+
+3.8.  Proxy Management Protocol
+
+
+The Proxy Management Protocol is an ICE        based protocol that provides a
+way for        application servers to easily locate proxy services such as the
+LBX proxy and the X firewall proxy.
+
+Typically, a service called a ``proxy manager''        is responsible for
+resolving requests for proxy services, starting        new proxies when
+appropriate, and keeping track of all of the available proxy services.
+The proxy manager strives to reuse existing proxy processes whenever
+possible.
+
+The Proxy Management Protocol is described in xc/doc/specs/PM/PM_spec.
+
+
+3.9.  Configuration
+
+
+As in R6.1, the        top-level Makefile is no longer over-ridden by the first
+build. Instead a new file xmakefile is created.  Thus is it not neces-
+sary to        take any additional steps to reset the builds.
+
+The file xc/config/cf/README provides more guidance on how to write an
+Imakefile, including a list of variables that may be set in an
+Imakefile.  This file is strongly recommended reading for Imakefile
+authors.
+
+The LaTeX text processor is supported as of R6.1.  If you have LaTeX on
+your system, turn on HasLatex to have the MakeLatexDoc rule use        it.
+
+Also since R6.1, with System V Release 4 (SVR4)        compilers we now use the
+-Xa (ANSI C with native        extensions) compiler flag rather than -Xc (limit
+environment to that specified in the standard).         This provides access to
+the full richness of the platform.  Unfortunately, it also defines the
+preprocessor symbol __STDC__ to        0, instead of 1 as specified by the
+standard.  Therefore we        use "#ifdef __STDC__" in our sources rather than
+"#if __STDC__".         On HP-UX systems we use the -Ae compiler option instead
+of -Aa,        also to access the full environment offered by the platform.
+
+As in R6.1, the        imake variables InstallXdmConfig, InstallXinitConfig,
+and InstallAppDefFiles suppress        overwriting existing files; if the files
+didn't previously exist, the files are always installed.  This interpre-
+tation makes bootstrapping a new system        easier than in R6 and earlier
+releases.
+
+A new configuration build option, GzipFontCompression, has been        added to
+use gzip rather        than compress for font compression.  It defaults to NO.
+
+The build creates a new        directory xc/exports into which the header
+files, libraries, and certain build utility binaries are symlinked.
+This greatly simplifies        Imakefile construction and supports multiple
+development projects (such as X, Motif,        and CDE) on a single system.
+
+Imake rules and        template files for building Motif and CDE were contri-
+buted by the OSF CDE/Motif project and are included in R6.3.
+
+
+3.10.  Documentation
+
+
+Additional X server internals documentation is provided        in the
+/xc/doc/specs/Xserver/ directory for the XC-APPGROUP and SECURITY exten-
+sions. An analysis and rationale for the SECURITY extension will also
+be found in that directory.  Specifications for        the other new standards
+are in /xc/doc/specs/RX/, /xc/doc/specs/XPRINT/, and
+/xc/doc/specs/Xext/.
+
+
+3.11.  Header Files
+
+
+xc/include/Xos_r.h is a        new header file to promote portable source code
+using thread-safe implementations of getpwnam, getpwuid, gethostbyname,
+gethostbyaddr, and getservbyname.  It is not required by any X Consor-
+tium standard.
+
+
+3.12.  X Server
+
+
+The security, LBX, printing, and AppGroup extensions are all new.  In
+R6.3 only MIT-MAGIC-COOKIE-1 is        supported in the security extension.
+Parts of the security policy are configured at run-time        from the file
+/usr/X11R6.3/lib/X11/xserver/SecurityPolicy.  Site-defined policy
+strings        used by xfwp and rules for property access by untrusted clients
+are defined there.  See        the Xserver man page for full details.
+
+
+3.12.1.         New Device Support
+
+
+Support        has been added for the Sun TCX frame buffer as a dumb 8-bit
+frame buffer on        Solaris 2.5.
+
+New XFree86 servers based on XFree86 3.2 are included.
+
+
+3.12.2.         Internal Changes
+
+
+The security extension provides        new internal resource ID lookup inter-
+faces that incorporate the access control lookup.  In order to be
+declared secure        and therefore be made available to untrusted clients,
+other extensions should, at a minimum, be changed to use these inter-
+faces. Depending on what the extension does, more may need to be done
+in its implementation before it        can appropriately be labeled ``secure''.
+
+Refer to the documents xc/doc/specs/Xserver/appgroup.ms        and
+xc/doc/specs/Xserver/secint.tex        for implementation details of the appli-
+cation group and security extensions, respectively.
+
+
+3.13.  ICE Library Addition
+
+
+To support proxy managers and firewall proxies using ICE on well-known
+TCP ports, an additional interface has been added to the ICE library.
+This new interface, IceListenForWellKnownConnections, has equivalent
+calling        parameters to IceListenForConnections plus an ICE network id
+parameter.
+
+
+3.14.  Xlib Vertical Writing and User-Defined Characters
+
+
+The Xlib output        method implementation has been enhanced to support the
+XOM value drawing direction XOMOrientation_TTB_RTL.  Vertical writing
+information and        other locale specific information is read from the file
+<XLocaleDir>/%L/XLC_LOCALE where the XLocaleDir        configuration option
+defaults to /usr/X11R6.3/lib/X11/locale.
+
+The X[mb|wc]TextEscapement functions now return        the text escapement in
+pixels for the vertical        or horizontal direction depending on the
+XNOrientation XOCValue.
+
+The X[mb|wc]DrawString functions will now render a character string in
+the vertical or        horizontal direction depending on the XNOrientation
+XOCValue.
+
+The Xlib NLS database implementation has been enhanced to support
+extended segments used for interchanging non-standard code sets.  Sup-
+port has been added for        control sequences and encoding names used in
+extended segments and conversion of glyph indexes when interchanging
+data in        extended segments.
+
+
+3.15.  Xt Geometry Management Debugger
+
+
+Daniel Dardailler's ``GeoTattler'' code        has been merged into the Xt
+Intrinsics library implementation.  This is not        a standard.  If libXt is
+compiled with the XT_GEO_TATTLER symbol        defined (currently there is no
+build configuration support to do this)        then a ``geoTattler'' resource
+may be specified for any widget        in an application.  If the geoTattler
+resource for a widget instance is True then libXt will generate        debug-
+ging information to stdout when        the widget makes geometry change
+requests.
+
+For example, if        the resources specify:
+
+myapp*draw.XmScale.geoTattler: ON
+*XmScrollBar.geoTattler:ON
+*XmRowColumn.exit_button.geoTattler:ON
+
+then geometry management debugging information will be generated for all
+the XmScale children of        the widget named draw, all the XmScrollBars, and
+the widget named exit_button in        any XmRowColumn.
+
+3.16.  New Programs
+
+
+There are new core programs lbxproxy, proxymngr, xfindproxy, xfwp, Xprt,
+and xrx.
+
+
+lbxproxy    The        lbxproxy program is used to ``translate'' X protocol to
+           LBX protocol.  It should be executed on the same host as the
+           client application or on a host connected to the client host
+           by a fast network.  lbxproxy appears to the clients using it
+           as another X server; that is, the clients connect through it
+           using the conventional DISPLAY syntax, specifying the proxy
+           host in place of the server.  lbxproxy can be used stand-
+           alone or in conjunction with proxymngr and xfindproxy.  See
+           the lbxproxy man page for further details.
+
+proxymngr   proxymngr is a process that        runs continuously to control
+           other proxy applications, such as lbxproxy and xfwp.  It
+           maintains a list of active proxy processes and responds to
+           queries from xfindproxy.  See the proxymngr man pages for
+           further details.
+
+xfindproxy  xfindproxy is used to locate a running proxy process for a
+           given network service, such as lbxproxy or xfwp, or to
+           request that a proxy be started if one is not already run-
+           ning.  xfindproxy communicates with proxymngr to perform the
+           actual work.
+
+xfwp       xfwp is the X firewall application proxy.  It is designed to
+           run on a network firewall host and relay X protocol between
+           applications (typically outside the firewall) and the X
+           server (inside the firewall).  xfwp appears to the clients
+           using it as another X server; that is, clients connect
+           through it using the conventional DISPLAY syntax.  xfwp will
+           not do anything useful without proxymngr and xfindproxy or
+           xrx.  See the xfwp man page for further details.
+
+Xprt       Xprt is the print server, built as part of the Xserver build
+           if the XprtServer config option is YES.  The print server
+           supports printing to PostScript and PCL devices, as well as
+           raster output to an xwd format file (and thence to any
+           printer that xpr supports).  The print extension was
+           designed to be integrated with the ``video'' server in a
+           single process but the R6.3 implementation does not support
+           a combined video and print server.  Details of configuration
+           for Xprt are in xc/doc/specs/Xserver/Xprt.mif (FrameMaker
+           interchange source) and xc/doc/hardcopy/Xserver/Xprt.PS.Z
+           (compressed PostScript).
+
+xrx, libxrx xrx        is the Web browser helper application that interprets
+           documents in the RX MIME type to remotely launch applica-
+           tions via the Web.  Its companion libxrx is a plug-in for
+           Netscape Navigator 3.0 that supports in addition the capa-
+           bility to visually embed the remote applications in the
+           associated browser Web page window.  See the xrx man page
+           for further details.
+
+
+3.16.1.         Using The LBX Proxy
+
+
+The implementation of lbxproxy provided        here will support an arbitrary
+number of clients connecting to        the same X server.  A separate lbxproxy
+process        is required for each separate X server process.  A typical com-
+mand line to invoke lbxproxy is
+lbxproxy :22 -display myhost:0
+
+
+This command runs a proxy with the X server ``myhost:0'' as the        target.
+Clients        must connect to the proxy using ``proxyhost:22'' as the DISPLAY.
+The .Xauthority        file for these clients must contain an entry for server
+``proxyhost:22'' with the same MIT-MAGIC-COOKIE        as ``myhost:0'', or the
+X server must be configured to permit connections from any host        on the
+network.
+
+Here is        an example showing how to setup the appropriate .Xauthority
+entries:
+
+% lbxproxy :22 -display        myws:0
+% xauth        list
+myws:0 MIT-MAGIC-COOKIE-1  7fd231ccdce2
+myws/unix:0  MIT-MAGIC-COOKIE-1         7fd231ccdce2
+% xauth        -f $HOME/proxyauth add proxyhost:22 .  7fd231ccdce2
+xauth: creating new authority file /usr/myself/proxyauth
+% xauth        -f $HOME/proxyauth  add proxyhost/unix:22 .  7fd231ccdce2
+% setenv XAUTHORITY $HOME/proxyauth
+
+
+In this        example, the authorization token for display 0 is copied into a
+new file ``proxyauth'' and associated with the LBX proxy server        display
+number (22).  The new authority        file may then be copied to another host
+and used as the        value of the XAUTHORITY environment variable.
+
+The proxymngr daemon is        usually configured to invoke lbxproxy automati-
+cally when a user or a CGI script runs xfindproxy -name        LBX.
+
+See the        lbxproxy man page for further details.
+
+
+3.17.  Major Additions to Existing Programs
+
+
+The generate option of xauth is        used to obtain additional authorization
+tokens for client connections. These authorization tokens may specify
+that the client        using them is to be restricted in the operations that
+may be performed in the        X server.  The authorization tokens may be
+independently revoked. Refer to the SECURITY extension for further
+details        on authorizations.
+
+The xauth man page gives full details on the new generate command.  Here
+is an example use:
+
+xauth -f untrusted-auth-file g :0 . timeout 0
+setenv XAUTHORITY untrusted-auth-file
+
+This will cause        xauth to contact server ``:0'' to get a long-lasting
+untrusted cookie which it then stores in untrusted-auth-file.  By set-
+ting XAUTHORITY        to point to untrusted-auth-file, subsequent applications
+run from this shell to server :0 will be untrusted.  The ``g'' is short
+for ``generate'', and the ``.''        is short for ``MIT-MAGIC-COOKIE-1''.  If
+you omit the -f        argument, xauth will use $XAUTHORITY (or ~/.Xauthority),
+which may not be what you want,        especially if you are creating an
+untrusted auth.         This is because xauth will replace the trusted auth in
+~/.Xauthority (put there by xdm) with the untrusted one, preventing you
+from making any        further trusted connections to the server.
+
+The xterm terminal emulator now        supports the active icon mode that was
+in X version 10        Release 4.  See the xterm man page for further details.
+There is support in the        xterm source to build xterm without the active
+icon mode for those who        may care for some reason to not provide it.
+
+
+3.18.  ANSIfication
+
+
+As noted previously under "Configuration Files", for pragmatic reasons
+we changed the way we use __STDC__ to test for standard        C compilers.
+R6.1 was officially the        last release that supported traditional K&R C.
+R6.3 assumes a standard        C compiler and environment.  We have not inten-
+tionally removed any K&R C support from        old code; most of the release
+will continue to build on older        platforms.
+
+
+
+4.  Known Bugs
+
+
+There are no examples in this release showing how to use the print
+extension.  CDE        2.1 has several such applications.
+
+lbxproxy fails to start        on SCO Open Server.
+
+x11perf        running through lbxproxy will tickle a drawing bug in cfb-based
+X servers that causes some lines and curves to be drawn        to the wrong
+coordinates and        outside the window boundaries.  Use the -nogfx option to
+lbxproxy as a workaround on affected servers.
+
+If proxymngr exits abnormally all managed proxies die.
+
+Documentation is missing on how        to use the vertical writing and user-
+defined        character support.
+
+Documentation is sparse        on how to configure Xprt.
+
+There are no example fonts in the release with vertical        text escapement
+(``vertical writing fonts'').
+
+
+
+5.  Filing Bug Reports
+
+
+If you find a reproducible bug in software in the xc/ directory, or find
+bugs in        the xc documentation, please send a bug report to The Open Group
+using the form in the file xc/bug-report and this destination address:
+
+       xbugs@x.org
+
+
+Please try to provide all of the information requested on the form if it
+is applicable; the little extra        time you spend on the report will make
+it much        easier for someone to reproduce, find, and fix the bug.
+
+Bugs in        the contributed software that is available on the net are not
+handled        on any official basis.  Consult the documentation for the indi-
+vidual software        to see where (if anywhere) to report the bug.  Many
+authors        of contributed software subscribe to the mailing list "contrib-
+bugs" hosted at        x.org, so this might be a useful place to report bugs.
+(To subscribe to contrib-bugs yourself,        send email to contrib-bugs-
+request@x.org.)
+
+
+
+6.  Acknowledgements
+
+
+Release        6.3 of X Version 11 was brought to you by the X staff at the X
+Consortium, Inc.:  Donna Converse (emeritus), Jim Fournier, Stephen Gil-
+dea (emeritus),        Kaleb Keithley, Matt Landau (emeritus), Arnaud Le Hors,
+Ralph Mor (emeritus), Bob Scheifler, Ralph Swick, Ray Tice, Mark Welch
+(emeritus), and        Dave Wiggins (emeritus).  Kevin Samborn and George Tsang
+(emeritus) of the CDE staff at X Consortium, Inc. worked hard on the
+print extension, including the PostScript driver; David        Kaelbling of the
+CDE staff converged the        X, Motif, and CDE imake/config support and
+helped with Xos_r.h; and Daniel        Dardailler (emeritus) of the CDE staff
+contributed the        libXt geometry tracing code.  Also, contractors Reed
+Augliere, Roger        Helmendach (Liberty Systems), and Ann Pichey each worked
+on critical components.
+
+Several        companies and individuals have cooperated and worked extremely
+hard to        make this release a reality, and our thanks go out to them.  You
+will find many of them listed in the acknowledgements in the individual
+specifications.
+
+Ken Raeburn of XFree86 and Cygnus Support contributed the gzip font
+compression support.
+
+The Common Desktop Environment sponsors        Digital Equipment Corp, Fujitsu,
+Hewlett-Packard, Hitachi, IBM, Novell, and SunSoft jointly contributed
+the print extension and        the Xlib vertical writing and user-defined char-
+acter support. Axel Deininger, Harry Phinney, Tom Gilg, Charles Prince,
+and Jim        Miller all from Hewlett-Packard did the print extension and PCL
+and raster drivers.  Fujitsu did the Xlib vertical writing and user-
+defined        character support.
+
+
diff --git a/Xserver/bug-report b/Xserver/bug-report
new file mode 100644 (file)
index 0000000..a822cdc
--- /dev/null
@@ -0,0 +1,64 @@
+To: xbugs@x.org
+Subject: [area]: [synopsis]   [replace with actual area and short description]
+
+     VERSION:
+
+R6.3, public-patch-2
+[X Consortium public patches edit this line to indicate the patch level]
+
+     CLIENT MACHINE and OPERATING SYSTEM:
+
+[e.g. Sparc/SunOS 5.3, DECstation 5000/Ultrix 4.3, HP 9000-730/HP-UX 9.1]
+
+     DISPLAY TYPE:
+
+[e.g. Sun GX, 8-bit framebuffer, IBM Skyway ...]
+
+     WINDOW MANAGER:
+
+[e.g. twm, mwm, gwm, olwm, ...]
+
+     COMPILER:
+
+[e.g. native ANSI cc, native cc, gcc 2.5.8, ...]
+
+     AREA:
+
+[Area of the source tree affected,
+e.g., Xserver, Xlib, Xt, Xaw, PEX, twm, xterm, xmh, config, ....
+Please only one area per bug report.]
+
+     SYNOPSIS:
+
+[Brief description of the problem and where it is located]
+
+     DESCRIPTION:
+
+[Detailed description of problem.  Don't just say "<blah>
+doesn't work, here's a fix," explain what your program does
+to get to the <blah> state.  If this is a request for an
+enhancement, justify it.]
+
+     REPEAT BY:
+
+[What you did to get the error; include test program or session
+transcript if at all possible.  If you include a program, make
+sure it depends only on libraries in the X distribution, not
+on any vendor or third-party libraries.  Be specific; if we can't
+reproduce it, we can't fix it.  Don't just say "run this program
+and it will be obvious," tell us exactly what we should see when
+the program is run.  Bug reports without a clear, deterministic
+way of reproducing them will be fixed only after all bug reports
+that do.]
+
+     SAMPLE FIX:
+
+[Preferred, but not necessary.  Please send context diffs (`diff 
+-c original-file fixed-file`).  Be sure to include our "XConsortium" 
+ident line in any diffs.  The best way to do this is to add your 
+own versioning line immediately after ours.]
+
+[PLEASE make your Subject: line as descriptive as possible.
+Subjects like "xterm bug" or "bug report" are not helpful!]
+[Remove all the explanatory text in brackets before mailing.]
+[Send to xbugs@x.org, as shown in the sample message header above]
diff --git a/Xserver/config/Imakefile b/Xserver/config/Imakefile
new file mode 100644 (file)
index 0000000..26b3dd0
--- /dev/null
@@ -0,0 +1,12 @@
+XCOMM $XConsortium: Imakefile /main/6 1996/09/28 16:04:42 rws $
+#define IHaveSubdirs
+#define PassCDebugFlags CDEBUGFLAGS="$(CDEBUGFLAGS)"
+
+#undef BootstrapCleanSubdirs
+#define BootstrapCleanSubdirs BOOTSTRAPSUBDIRS="$(BOOTSTRAPSUBDIRS)"
+
+BOOTSTRAPSUBDIRS = imake makedepend
+SUBDIRS = cf $(BOOTSTRAPSUBDIRS) util
+
+MakeSubdirs($(SUBDIRS))
+DependSubdirs($(SUBDIRS))
diff --git a/Xserver/config/cf/Amoeba.cf b/Xserver/config/cf/Amoeba.cf
new file mode 100644 (file)
index 0000000..a844789
--- /dev/null
@@ -0,0 +1,430 @@
+XCOMM platform:  $XConsortium: Amoeba.cf /main/12 1996/09/28 16:04:48 rws $
+XCOMM platform:  $XFree86: xc/config/cf/Amoeba.cf,v 3.9 1996/12/23 05:50:00 dawes Exp $
+
+/*  The presence of this configuration file in the X distribution
+ *  does not imply full support for the system it describes.
+ *  Additional patches from The XFree86 Project, Inc. will be required to 
+ *  compile the X distribution on Amoeba.  According to them, these patches
+ *  will also be made available at the regular Amoeba ftp site
+ *  ftp.am.cs.vu.nl.
+ */
+
+/*
+ * Configuration file for Amoeba 5.2
+ */
+
+#ifndef OSName
+#define OSName                  Amoeba 5.2
+#endif
+XCOMM operating system:  OSName
+#ifndef OSMajorVersion
+#define OSMajorVersion          5
+#endif
+#ifndef OSMinorVersion
+#define OSMinorVersion          2
+#endif
+#ifndef OSTeenyVersion
+#define OSTeenyVersion          0
+#endif
+#ifndef OSVendor
+#define OSVendor                Vrije Universiteit
+#endif
+
+#define AmoebaArchitecture     YES
+
+/* Configuration defaults */
+#ifndef AmoebaTop
+#define AmoebaTop              __AM_TOP__
+#endif
+#ifndef AmoebaBin
+#define AmoebaBin              $(ATOP)/bin.sun4
+#endif
+#ifndef AmoebaConf
+#define AmoebaConf             __AM_CONF__
+#endif
+
+#define HasNdbm                        YES
+#define NeedSdbm               YES
+#define HasShm                 NO
+#define HasSecureRPC           NO
+#define SetTtyGroup            NO
+#define HasPutenv              YES
+#define HasSockets              NO
+#define HasStreams              NO
+
+#if defined(Sun3Architecture) || defined(SparcArchitecture)
+#define XsunAmoebaServer       YES
+#define XsunAmoebaMonoServer   YES
+#endif
+
+#define BuildFonts              NO
+#define BuildFontServer         NO
+#define BuildPexExt            NO
+#define BuildXIE               NO
+
+#define YaccCmd                 byacc
+#define TermcapLibrary          /* in libajax */
+#define LexLib                 /* not needed */
+
+#define PexCCOptions           DefaultCCOptions
+#define ServerOSDefines                XFree86ServerOSDefines
+
+#define UsrLibDir               $(DESTDIR)/profile/module/x11/lib
+#define LibDir                  $(DESTDIR)/profile/module/x11/lib
+#define ManDirectoryRoot        $(DESTDIR)/profile/module/x11/man
+#define BinDir                  $(DESTDIR)/profile/module/x11/bin
+#define IncRoot                 $(DESTDIR)/profile/module/x11/include
+#define FontDir                 $(DESTDIR)/profile/module/x11/fonts/$(ARCH)
+#define DefaultRGBDatabase      $(DESTDIR)/profile/module/x11/lib/rgb/$(ARCH)/rgb
+
+#define ManSuffix               1
+#define ManPath                 ManDirectoryRoot
+#define XmanLocalSearchPath     ManDirectoryRoot
+
+#define DefaultUserPath         :/bin:$(BINDIR)
+#define DefaultSystemPath       /bin:$(BINDIR):
+
+#define StandardIncludes        -I$(ATOP)/src/h \
+                               -I$(ATOP)/src/h/posix \
+                               -I$(ATOP)/src/h/posix/machdep/$(ARCH) \
+                               -I$(ATOP)/src/h/machdep/arch/$(ARCH) \
+                               -I$(ATOP)/src/h/toolset/$(TOOLSET)
+
+#define Malloc0ReturnsNull      YES
+#define ServerInstallFlags      -s 32
+#define FontDefines             -DFONT_SNF
+#define ConnectionFlags         -DAMTCPCONN -DAMRPCCONN
+#define ServerXdmcpDefines     /* no -DXDMCP */
+#define UseRgbTxt              YES
+#define NdbmDefines            -DSDBM -DNDBM -I$(XINCLUDESRC)
+#define DBMLibrary             /* $(LIBSRC)/sdbm/libsdbm.a */
+
+#if defined(i386Architecture)
+#ifndef AckToolset
+#define AckToolset              YES
+#define ExtraFPLoadFlags       -fp
+#endif
+#define XF86MonoServer         YES
+#endif
+
+#if defined(Sun3Architecture)
+#ifndef AckToolset
+#define AckToolset              YES
+#endif
+#endif
+
+#if AckToolset
+#define CcCmd                   ack
+#define ServerCcCmd             ack
+#define LdCmd                   ack
+#define AckArchOption          -mam_$(ARCH)
+#define DefaultCCOptions        AckArchOption
+#define LibraryCCOptions        AckArchOption
+#define LdCombineFlags          -Rled-r -c.out
+#define ArCmd                  aal clrv
+#define RanlibCmd              /bin/true
+#define AsCmd                  AmoebaConf/$(ARCH).$(TOOLSET)/toolset/do_as AckArchOption
+#define AsIncl                 -I$(ATOP)/src/h/machdep/arch/$(ARCH)
+#define AsmDefines             -DACK_ASSEMBLER
+#define LdPreLib               /**/
+#define LdPostLib              /**/
+#endif
+
+#if defined(SparcArchitecture)
+#define AllocateLocalDefines   -DINCLUDE_ALLOCA_H
+
+#define CcCmd                   cc
+#define ServerCcCmd             cc
+#define LdCmd                   AmoebaConf/$(ARCH).$(TOOLSET)/toolset/do_gld
+#define DefaultCCOptions        -sun4
+#define LibraryCCOptions        -sun4
+#define AmoebaCompilerDefs     -Usun
+#define ServerExtraDefines     AllocateLocalDefines
+#define LdPostLib              /**/
+#endif
+
+#ifndef AmoebaCompilerDefs
+#define AmoebaCompilerDefs     /**/
+#endif
+
+#define CommonAmoebaDefines     -DAMOEBA -D$(ARCH) AmoebaCompilerDefs
+#define StandardDefines         CommonAmoebaDefines
+#define StandardCppDefines      StandardDefines
+
+#ifndef ExtraFPLoadFlags
+#define ExtraFPLoadFlags
+#endif
+#define MathLibrary            $(ALIB)/math/libmath.a
+#define OSLibraries             $(ALIB)/ajax/libajax.a \
+                               $(ALIB)/amoeba/libamoeba.a \
+                               MathLibrary \
+                               ExtraFPLoadFlags
+#define ServerExtraSysLibs     $(CBRT) OSLibraries
+#define ExtraLoadFlags         OSLibraries
+
+ATOP            = AmoebaTop
+ALIB            = AmoebaConf/$(ARCH).$(TOOLSET)/lib
+#if AckToolset 
+/* The ACK toolset already links in the appropriate head.o by default */
+HEAD            =
+#else
+HEAD            = $(ALIB)/head/head.o
+#endif
+
+ABIN            = AmoebaBin
+AINSTALL        = /bin/sh $(CONFIGSRC)/util/aminstall.sh $(ABIN)
+AINSTALLFLAGS   =
+TOB             = /bin/sh $(CONFIGSRC)/util/aminstall.sh $(ABIN)
+MKXDIRHIER      = /bin/sh $(CONFIGSRC)/util/ammkdirhier.sh $(ABIN)
+
+/* Make wizardy: */
+COMPILE.c=$(CC) $(CFLAGS) $(CPPFLAGS) -c
+LINK.c=$(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS)
+
+#if defined(i386Architecture)
+ARCH            = i80386
+TOOLSET         = ack
+ALDFLAGS        = /* -mam_i80386 now in CCopts */ -.c -Rcv-s32
+
+#include <xfree86.cf>
+#endif
+
+#if defined(Sun3Architecture)
+ARCH            = mc68000
+TOOLSET         = ack
+ALDFLAGS        =  -.c -Rcv-s32
+#endif
+
+#if defined(SparcArchitecture)
+ARCH            = sparc
+TOOLSET         = sun
+SPARCLIBDIR     = AmoebaBin/gnu/sparc
+ALDFLAGS        = -mam_sparc -n -Ttext 40000 -Bstatic -e start -L$(SPARCLIBDIR)
+#endif
+
+#define BootstrapCFlags                -DAMOEBA -DCROSS_$(ARCH) -DCROSS_COMPILE
+
+/*
+ * The rest of this files consists of rules to allow cross-compilation
+ * and installation of binaries and data files from the Unix host to
+ * the Amoeba file system.
+ */
+
+/* #ifdef CROSS_COMPILING */
+#define CrossCompiling          YES
+
+#define HostLinkRule(target, flags, src, libs)  cc -o target src
+
+#define LinkRule(program,options,objects,libraries) \
+$(LD) $(ALDFLAGS) $(HEAD) -o program options objects libraries $(EXTRA_LOAD_FLAGS)
+
+/* ComplexHostProgramTarget - Compile a program such that we can run
+ * it on this host, i.e., don't use the default cross compiler.
+ */
+#ifndef ComplexHostProgramTarget
+#define        ComplexHostProgramTarget(program)                               @@\
+              CC=cc                                                    @@\
+    STD_INCLUDES=                                                      @@\
+          CFLAGS=$(TOP_INCLUDES) $(INCLUDES) $(BOOTSTRAPCFLAGS)                @@\
+EXTRA_LOAD_FLAGS=                                                      @@\
+        PROGRAM = program                                              @@\
+                                                                       @@\
+AllTarget(program)                                                     @@\
+                                                                       @@\
+program: $(OBJS) $(DEPLIBS)                                            @@\
+       RemoveTargetProgram($@)                                         @@\
+       HostLinkRule($@,$(_NOOP_),$(OBJS),$(DEPLIBS) $(LOCAL_LIBRARIES)) @@\
+                                                                       @@\
+DependTarget()                                                         @@\
+                                                                       @@\
+LintTarget()                                                           @@\
+                                                                       @@\
+clean::                                                                        @@\
+       RemoveFile(ProgramTargetName(program))
+#endif /* ComplexHostProgramTarget */
+
+#ifndef SimpleHostProgramTarget
+#define SimpleHostProgramTarget(program)                               @@\
+           OBJS = program.o                                            @@\
+           SRCS = program.c                                            @@\
+                                                                       @@\
+ComplexHostProgramTarget(program)
+#endif /* SimpleHostProgramTarget */
+
+
+#ifndef Concat
+#if (__STDC__ && !defined(UnixCpp)) || defined(AnsiCpp)
+#define Concat(a,b)a##b
+#else
+#define Concat(a,b)a/**/b
+#endif
+#endif
+
+/*
+ * LintLibReferences - variables for lint libraries
+ */
+#ifndef LintLibReferences
+#define LintLibReferences(varname,libname,libsource)                   @@\
+Concat(LINT,varname) = Concat(libsource/llib-,libname.ln)
+#endif
+
+/*
+ * UnsharedLibReferences - variables for unshared libraries
+ */
+#ifndef UnsharedLibReferences
+#define UnsharedLibReferences(varname,libname,libsource)               @@\
+Concat3(DEP,varname,LIB) = Concat($(BUILDLIBDIR)/lib,libname.a)                @@\
+     Concat(varname,LIB) = Concat($(BUILDLIBDIR)/lib,libname.a)                @@\
+LintLibReferences(varname,libname,libsource)
+#endif
+
+#ifndef InstallLibrary
+#define        InstallLibrary(libname,dest)                                    @@\
+install:: Concat(lib,libname.a)                                                @@\
+       @echo '** TODO: Install Library ' Concat(lib,libname.a)
+#endif /* InstallLibrary */
+
+#ifndef MergeIntoInstalledLibrary
+#define MergeIntoInstalledLibrary(tolib,fromlib)                       @@\
+install::  fromlib                                                     @@\
+       @echo '** TODO: merge ' fromlib into tolib
+#endif /* MergeIntoInstalledLibrary */
+
+#ifndef InstallLibraryAlias
+#define        InstallLibraryAlias(libname,alias,dest)                         @@\
+install::                                                              @@\
+       @echo '** TODO: Install lib alias ' libname alias dest
+#endif /* InstallLibraryAlias */
+
+#ifndef InstallLintLibrary
+#define        InstallLintLibrary(libname,dest)                                @@\
+install.ln:: Concat(llib-l,libname.ln)                                 @@\
+       @echo '** TODO: Install lintlib ' Concat(llib-l,libname.ln)
+#endif /* InstallLintLibrary */
+
+#ifndef InstallManPageLong
+#define        InstallManPageLong(file,destdir,dest)                           @@\
+install.man:: file.man                                                 @@\
+       @echo '** TODO: Install man page ' file.man
+#endif /* InstallManPageLong */
+
+#ifndef InstallGenManPageLong
+#define        InstallGenManPageLong(file,destdir,dest,suffix)                 @@\
+install.man:: file.man                                                 @@\
+       @echo '** TODO: Install man page ' file.man
+#endif /* InstallGenManPageLong */
+
+#ifndef InstallManPageAliases
+#define        InstallManPageAliases(file,destdir,aliases)                     @@\
+install.man::                                                          @@\
+       @(TMP=/tmp/tmp.$$$$; \                                          @@\
+       $(RM) $${TMP}; \                                                @@\
+       echo .so `basename destdir`/file.$(MANSUFFIX) > $${TMP}; \      @@\
+       for i in aliases; do (set -x; \                                 @@\
+       $(TOB) $${TMP} $(DESTDIR)destdir/$$i.$(MANSUFFIX)); \           @@\
+       done; \                                                         @@\
+       $(RM) $${TMP})
+#endif /* InstallManPageAliases */
+
+#ifndef InstallGenManPageAliases
+#define        InstallGenManPageAliases(file,destdir,suffix,aliases)           @@\
+install.man::                                                          @@\
+       @(TMP=/tmp/tmp.$$$$; \                                          @@\
+       $(RM) $${TMP}; \                                                @@\
+       echo .so `basename destdir`/file.suffix > $${TMP}; \            @@\
+       for i in aliases; do (set -x; \                                 @@\
+       $(TOB) $${TMP} $(DESTDIR)destdir/$$i.suffix); \                 @@\
+       done; \                                                         @@\
+       $(RM) $${TMP})
+#endif /* InstallGenManPageAliases */
+
+#ifndef InstallNamedNonExec
+#define        InstallNamedNonExec(srcname,dstname,dest)                       @@\
+install:: srcname                                                      @@\
+       $(MKXDIRHIER) $(DESTDIR)dest                                    @@\
+       $(TOB) srcname $(DESTDIR)dest/dstname
+#endif /* InstallNamedNonExec */
+
+#ifndef InstallNonExecFile
+#define        InstallNonExecFile(file,dest)                                   @@\
+install:: file                                                         @@\
+       $(MKXDIRHIER) dest                                              @@\
+       $(TOB) file dest/file
+#endif /* InstallNonExecFile */
+
+#ifndef InstallNonExec
+#define        InstallNonExec(file,dest)                                       @@\
+install:: file                                                         @@\
+       $(TOB) file dest/file
+#endif /* InstallNonExec */
+
+#ifndef InstallProgramWithFlags
+#define InstallProgramWithFlags(program,dest,flags)                    @@\
+install:: program                                                      @@\
+       $(MKXDIRHIER) dest/program                                      @@\
+       $(AINSTALL) $(AINSTALLFLAGS) program dest/program/pd.$(ARCH)
+#endif /* InstallProgramWithFlags */
+
+#ifndef InstallScript
+#define        InstallScript(program,dest)                                     @@\
+install:: program.script                                               @@\
+       $(TOB) program.script dest/program
+#endif /* InstallScript */
+
+#ifndef InstallNamedScript
+#define        InstallNamedScript(srcname,dstname,dest)                        @@\
+install:: srcname                                                      @@\
+       $(TOB) srcname dest/dstname
+#endif /* InstallNamedScript */
+
+#ifndef InstallNamedProg
+#define        InstallNamedProg(srcname,dstname,dest)                          @@\
+install:: srcname                                                      @@\
+       $(MKXDIRHIER) $(DESTDIR)dest/dstname                            @@\
+       $(AINSTALL) $(AINSTALLFLAGS) srcname $(DESTDIR)dest/dstname/pd.$(ARCH)
+#endif /* InstallNamedProg */
+
+#ifndef InstallMultipleDestFlags
+#define InstallMultipleDestFlags(step,list,dest,flags)                 @@\
+step:: list                                                            @@\
+       $(MKXDIRHIER) $(DESTDIR)dest                                    @@\
+       @case '${MFLAGS}' in *[i]*) set +e;; esac; \                    @@\
+       for i in list; do \                                             @@\
+               (set -x; $(TOB) $$i dest/$$i); \                        @@\
+       done
+#endif /* InstallMultipleDestFlags */
+
+#ifndef InstallMultipleProg
+#define InstallMultipleProg(list,dest)                                 @@\
+install:: list                                                         @@\
+       @case '${MFLAGS}' in *[i]*) set +e;; esac; \                    @@\
+       for i in list; do \                                             @@\
+           (set -x; \                                                  @@\
+               $(MKXDIRHIER) $(DESTDIR)dest/$$i; \                     @@\
+               $(AINSTALL) $(AINSTALLFLAGS) $$i dest/$$i/pd.$(ARCH));\ @@\
+       done
+#endif /* InstallMultipleProg */
+
+#ifndef InstallAppDefaults
+#if InstallAppDefFiles
+#define        InstallAppDefaults(class)                                       @@\
+install:: class.ad                                                     @@\
+       $(MKXDIRHIER) $(XAPPLOADDIR)                                    @@\
+       $(TOB) class.ad $(DESTDIR)$(XAPPLOADDIR)/class
+#else
+#define        InstallAppDefaults(class)
+#endif /* InstallAppDefFiles */
+#endif /* InstallAppDefaults */
+
+#ifndef InstallAppDefaultsLong
+#if InstallAppDefFiles
+#define        InstallAppDefaultsLong(file,class)                              @@\
+install:: file.ad                                                      @@\
+       $(MKXDIRHIER) $(DESTDIR)$(XAPPLOADDIR)                          @@\
+       $(TOB) file.ad $(DESTDIR)$(XAPPLOADDIR)/class
+#else
+#define        InstallAppDefaultsLong(file,class)
+#endif /* InstallAppDefFiles */
+#endif /* InstallAppDefaultsLong */
+
+/* #endif CROSS_COMPILE */
diff --git a/Xserver/config/cf/DGUX.cf b/Xserver/config/cf/DGUX.cf
new file mode 100644 (file)
index 0000000..f790afe
--- /dev/null
@@ -0,0 +1,22 @@
+XCOMM platform:  $XConsortium: DGUX.cf /main/5 1996/09/28 16:04:56 rws $
+
+#ifndef OSName
+#define OSName            DG/UX 4.32
+#endif
+XCOMM operating system:  OSName
+#ifndef OSMajorVersion
+#define OSMajorVersion    4
+#endif
+#ifndef OSMinorVersion
+#define OSMinorVersion    32
+#endif
+
+#define BootstrapCFlags   -DDGUX
+#define StandardDefines   -DDGUX -DSYSV
+#define SystemV           YES
+#define HasPutenv         YES
+#define HasGcc            YES
+#define BuildServer       NO
+#define UNCOMPRESSPATH /usr/bin/X11/uncompress
+
+#define ExtraFilesToClean *.lg
diff --git a/Xserver/config/cf/FreeBSD.cf b/Xserver/config/cf/FreeBSD.cf
new file mode 100644 (file)
index 0000000..b93e3af
--- /dev/null
@@ -0,0 +1,364 @@
+XCOMM platform:  $TOG: FreeBSD.cf /main/18 1997/06/12 07:40:35 kaleb $
+XCOMM platform:  $XFree86: xc/config/cf/FreeBSD.cf,v 3.58.2.11 1998/03/01 01:08:59 dawes Exp $
+
+#ifndef OSName
+#define OSName                 DefaultOSName
+#endif
+#ifndef OSVendor
+#define OSVendor               /**/
+#endif
+#ifndef OSMajorVersion
+#define OSMajorVersion         DefaultOSMajorVersion
+#endif
+#ifndef OSMinorVersion
+#define OSMinorVersion         DefaultOSMinorVersion
+#endif
+#ifndef OSTeenyVersion
+#define OSTeenyVersion         DefaultOSTeenyVersion
+#endif
+XCOMM operating system:  OSName (OSMajorVersion./**/OSMinorVersion./**/OSTeenyVersion)
+
+#define HasGcc                 YES
+#define HasGcc2                        YES
+#define HasCplusplus           YES
+#define HasGcc2ForCplusplus    YES
+#define GccUsesGas             YES
+#define UseGas                 YES
+#define GnuCpp                 YES
+#define HasNdbm                YES
+#define HasPutenv              YES
+#define HasSnprintf            YES
+#define HasBSD44Sockets        YES
+#ifndef HasLibCrypt
+# define HasLibCrypt           YES
+#endif
+#ifndef HasShm
+# define HasShm                YES
+#endif
+#define HasWChar32             YES
+
+#define AvoidNullMakeCommand   YES
+#define StripInstalledPrograms YES
+#define CompressAllFonts       YES
+#define Malloc0ReturnsNull     YES
+#define NeedConstPrototypes    YES
+#define NeedFunctionPrototypes YES
+#define NeedNestedPrototypes   YES
+#define NeedVarargsPrototypes  YES
+#define NeedWidePrototypes     NO
+
+#define MkdirHierCmd           mkdir -p
+
+#define CcCmd                  cc
+#define CppCmd                 /usr/libexec/cpp
+#define PreProcessCmd          CppCmd
+#define StandardCppDefines     -traditional
+#if defined(UseInstalled) && (!defined(XF86LinkKit) || !XF86LinkKit)
+#define DefaultCCOptions       /**/
+#else
+#define DefaultCCOptions       -ansi -pedantic -Dasm=__asm
+#endif
+#ifndef ExtraLibraries
+#define ExtraLibraries         /**/
+#endif
+#ifndef UseGnuMalloc
+/* 2.2 doesn't really have GnuMalloc */
+#if OSMajorVersion < 2 || (OSMajorVersion == 2 && OSMinorVersion < 2)
+#define UseGnuMalloc           YES
+#else
+#define UseGnuMalloc           NO
+#endif
+#endif
+
+/* 2.2.2 and later has setusercontext() */
+#if OSMajorVersion > 2 || (OSMajorVersion == 2 && OSMinorVersion > 2) || \
+     (OSMajorVersion == 2 && OSMinorVersion == 2 && OSTeenyVersion >= 2)
+#define HasSetUserContext      YES
+#endif
+
+/* 
+ * This doesn't work the way it does on every other system. On FreeBSD it's
+ * only a "hint, not a demand", whatever that means. Note that this is not 
+ * what it says in the ld and ld.so man pages, which are rather vague on the
+ * matter.
+ *
+ * But we do know that if a) you do what the X Project team does and set your 
+ * ProjectRoot to something like "/X11", and b) you have other X libraries, 
+ * e.g. in /usr/X11R6/lib, and you have added /usr/X11R6/lib to your 
+ * ld.so.cache with ldconfig, then any programs linked with this "hint" will
+ * find that ld.so ignores the "hint" at runtime and loads the libraries in 
+ * the ld.so.cache, i.e.the wrong ones, instead! Empirically we find that
+ * the run-path is only used as a last resort to find the libraries, after
+ * the LD_LIBRARY_PATH and ld.so.cache.
+ *
+ * N. B. to FreeBSD users who are not familiar with the semantics of the run-
+ * path on other systems. The run-path is akin to a per-program ld.so.cache. 
+ * If a program is linked with a run-path, that run-path should take 
+ * precedence over _everything_ else! In my opinion ldconfig and the 
+ * ld.so.cache should be deprecated immediately now that FreeBSD has run-
+ * paths. Any program that needs libraries that are outside the "well known" 
+ * locations should be linked with a run-path.
+ *
+ * All of which begs the question: If this option doesn't work in any useful
+ * way, why did they (FreeBSD) bother to add it? It would be nice if FreeBSD
+ * would fix ld.so so that run-paths are truly useful.
+ *
+ * Using run-paths is added with the intent that vendors who ship X for 
+ * FreeBSD should use it too. Once everyone uses it then there will be no 
+ * reason for FreeBSD to assume that it knows where X libraries are installed 
+ * and they can remove it from the list of directories they add to ld.so.cache 
+ * in their /etc/rc file.
+ */
+#if OSMajorVersion > 2 || (OsMajorVersion == 2 && OSMinorVersion >= 2)
+#ifndef ExtraLoadFlags
+#define ExtraLoadFlags         -Wl,-R,$(USRLIBDIRPATH)
+#endif
+#endif
+
+#ifndef GnuMallocLibrary
+#define GnuMallocLibrary       -lgnumalloc
+#endif
+
+#if (OSMajorVersion > 2) || (OSMajorVersion == 2 && OSMinorVersion >= 2) \
+       || (OSMajorVersion == 2 && OSMinorVersion == 1 && OSTeenyVersion >= 6)
+/* 2.1.6 and 2.2 have libz */
+#ifndef HasZlib
+#define HasZlib                YES
+#endif
+#endif
+
+#if OSMajorVersion > 2 || (OSMajorVersion == 2 && OSMinorVersion >= 2) || \
+    (OSMajorVersion == 2 && OSMinorVersion == 2 && OSTeenyVersion > 2)
+/*
+ * FreeBSD 2.2.5 or later.
+ *
+ * Don't make any assumptions about the version of Tcl in the base OS.
+ * These settings assume that the tcl-7.6 and tk-4.2 packages have been
+ * installed.
+ *
+ * Note the static libs in some versions of the FreeBSD packages are
+ * broken.  The symptom of this is unresolved symbols when linking
+ * XF86Setup.  If you run into this problem, either build your own
+ * static libs from the standard Tcl and Tk source, or change the
+ * definitions of XF86SetupUsesStatic{Tcl,Tk}.  The latter is not
+ * recommended for binaries that are going to be redistributed.
+ */
+#ifndef TkLibName
+#define TkLibName              tk42
+#endif
+#ifndef TkIncDir
+#define TkIncDir               /usr/local/include/tk4.2
+#endif
+#ifndef TclLibName
+#define TclLibName             tcl76
+#endif
+#ifndef TclIncDir
+#define TclIncDir              /usr/local/include/tcl7.6
+#endif
+#else
+#if OSMajorVersion == 2 && OSMinorVersion == 2
+/*
+ * FreeBSD 2.2 prior to 2.2.5
+ *
+ * Note: the tk-4.1 package for FreeBSD doesn't have the static lib, so
+ * you'll have to build it yourself, or change the definition of
+ * XF86SetupUsesStaticTk.
+ */
+#ifndef TkLibName
+#define TkLibName              tk41
+#endif
+#ifndef TclLibName
+#define TclLibName             tcl
+#endif
+#ifndef TclLibDir
+#define TclLibDir              /usr/lib
+#endif
+#ifndef TclIncDir
+#define TclIncDir              /usr/include
+#endif
+/* FreeBSD 2.2 has libtcl in the base system */
+#ifndef XF86SetupUsesStaticTcl
+#define XF86SetupUsesStaticTcl NO
+#endif
+
+#else /* ! 2.2 or later */
+
+#if OSMajorVersion == 2 && OSMinorVersion == 1 && OSTeenyVersion >= 6
+
+/*
+ * 2.1.x with x >=6 has tk 4.1 and tcl 7.5 in the packages collection.
+ * Neither packages include the static libs, so you either need to build
+ * them yourself or set XF86SetupUsesStaticTcl and XF86SetupUsesStaticTk
+ * to NO.  This isn't the default because we don't want the XFree86
+ * binaries to have these packages as a dependency.
+ */
+
+#ifndef TkLibName
+#define TkLibName              tk41
+#endif
+#ifndef TclLibName
+#define TclLibName             tcl75
+#endif
+
+#else /* ! 2.1.6 or later */
+
+#ifndef TkLibName
+#define TkLibName              tk40
+#endif
+#ifndef TclLibName
+#define TclLibName             tcl74
+#endif
+
+#endif
+#endif
+#endif
+
+#undef  InstallCmd
+#define InstallCmd             /usr/bin/install
+
+#if GccUsesGas
+# define GccGasOption          -DGCCUSESGAS
+# define AsmDefines            -DUSE_GAS
+#else
+# define GccGasOption /**/
+#endif
+
+#define ServerExtraDefines GccGasOption XFree86ServerDefines
+
+#define StandardDefines        -DCSRG_BASED
+
+#if OSMajorVersion > 1
+#define ServerOSDefines                XFree86ServerOSDefines -DDDXTIME
+#define XawI18nDefines         -DUSE_XWCHAR_STRING
+#define HasMakefileSafeInclude YES
+#define IncludeMakefile(file) @@# dependencies are in .depend
+#define DependFileName         .depend
+#ifndef BuildDynamicLoading
+#define BuildDynamicLoading    YES
+#endif
+#ifndef ForceNormalLib
+#define ForceNormalLib         YES
+#endif
+#define HasMkstemp             YES
+#else
+#define ServerOSDefines                XFree86ServerOSDefines -DDDXTIME -DXNO_SYSCONF
+#define XawI18nDefines         -DUSE_XWCHAR_STRING -DUSE_XMBTOWC
+#endif
+
+/* The GCC strength-reduce bug is fixed for FreeBSD 2.1.5 and later */
+#ifndef DefaultGcc2i386Opt
+#if OSMajorVersion > 2 || (OSMajorVersion == 2 && OSMinorVersion > 1) || (OSMajorVersion == 2 && OSMinorVersion == 1 && OSTeenyVersion >= 5)
+#define DefaultGcc2i386Opt -O2
+#endif
+#endif
+
+#ifdef i386Architecture
+# define OptimizedCDebugFlags DefaultGcc2i386Opt
+#else
+# define OptimizedCDebugFlags -O2
+#endif
+
+#ifndef PreIncDir
+# define PreIncDir     /usr/include
+#endif
+
+#define TroffCmd        groff -Tps
+#define SetTtyGroup     YES
+
+#ifndef ExtraFilesToClean
+# define ExtraFilesToClean *.core
+#endif
+
+#define DefaultUserPath                /bin:/usr/bin:/sbin:/usr/sbin:$(BINDIR):/usr/gnu/bin:/usr/local/bin
+#define DefaultSystemPath      /bin:/usr/bin:/sbin:/usr/sbin:$(BINDIR)
+#ifndef SystemManDirectory
+#define SystemManDirectory     /usr/share/man
+#endif
+
+#define InstKmemFlags  -g kmem -m 2755
+
+/*
+ * Compress manual pages
+ */
+#ifndef CompressManPages
+# define CompressManPages        YES
+#endif
+
+#if CompressManPages
+
+#ifndef CompressManCmd
+# define CompressManCmd                gzip -n
+#endif
+   COMPRESSMANCMD = CompressManCmd
+
+#ifndef InstallManPageLong
+#define InstallManPageLong(file,destdir,dest)                           @@\
+install.man:: file.man                                                  @@\
+       MakeDir($(DESTDIR)destdir)                                      @@\
+       $(RM) $(DESTDIR)destdir/dest.$(MANSUFFIX)*                      @@\
+       $(INSTALL) -c $(INSTMANFLAGS) file.man \                        @@\
+          $(DESTDIR)destdir/dest.$(MANSUFFIX)                           @@\
+       -$(COMPRESSMANCMD) $(DESTDIR)destdir/dest.$(MANSUFFIX)
+#endif
+
+#ifndef InstallGenManPageLong
+#define InstallGenManPageLong(file,destdir,dest,suffix)                 @@\
+install.man:: file.man                                                  @@\
+       MakeDir($(DESTDIR)destdir)                                      @@\
+       $(RM) $(DESTDIR)destdir/dest.suffix*                            @@\
+       $(INSTALL) -c $(INSTMANFLAGS) file.man \                        @@\
+          $(DESTDIR)destdir/dest.suffix                                 @@\
+       -$(COMPRESSMANCMD) $(DESTDIR)destdir/dest.suffix
+#endif
+
+#ifndef InstallMultipleMan
+#define InstallMultipleMan(list,dest)                                   @@\
+install.man:: list                                                      @@\
+       MakeDir($(DESTDIR)dest)                                         @@\
+       @case '${MFLAGS}' in *[i]*) set +e;; esac; \                    @@\
+       for i in list; do \                                             @@\
+               (set -x; \                                              @@\
+               MNAME=`echo $$i | cut -f1 -d.`; \                       @@\
+               $(RM) $(DESTDIR)dest/$${MNAME}*; \                      @@\
+               $(INSTALL) -c $(INSTMANFLAGS) $$i \                     @@\
+                 $(DESTDIR)dest/$${MNAME}.$(MANSUFFIX); \              @@\
+               $(COMPRESSMANCMD) $(DESTDIR)dest/$${MNAME}.$(MANSUFFIX)); \  @@\
+       done
+#endif
+
+/*
+ * InstallManPageAliases - install soft links for aliases.
+ */
+#ifndef InstallManPageAliases
+#define InstallManPageAliases(file,destdir,aliases)                     @@\
+install.man::                                                           @@\
+       @(SUFFIX=`echo $(DESTDIR)destdir/file.* | sed -e 's,.*/[^\.]*.,,'`; \ @@\
+       for i in aliases; do (set -x; \                                 @@\
+       $(RM) $(DESTDIR)destdir/$$i.*; \                                @@\
+       (cd $(DESTDIR)destdir; $(LN) file.$${SUFFIX} \                  @@\
+       $$i.$${SUFFIX})); \                                             @@\
+       done)
+#endif
+
+/*
+ * InstallGenManPageAliases - install soft links for aliases.
+ */
+#ifndef InstallGenManPageAliases
+#define InstallGenManPageAliases(file,destdir,suffix,aliases)              @@\
+       InstallManPageAliases(file,destdir,aliases)
+#endif
+#endif
+
+#if OSMajorVersion > 2 || (OSMajorVersion == 2 && OSMinorVersion >= 1)
+#define HasBsdMake     YES
+#endif
+
+#ifndef StaticLibrary
+#define StaticLibrary(libpath,libname) -Wl,-Bstatic Concat(-L,libpath) Concat(-l,libname) -Wl,-Bdynamic
+#endif
+
+#include <bsdLib.rules>
+
+#ifdef i386Architecture
+#include <xfree86.cf>
+#endif
diff --git a/Xserver/config/cf/Imake.cf b/Xserver/config/cf/Imake.cf
new file mode 100644 (file)
index 0000000..2c3a71b
--- /dev/null
@@ -0,0 +1,963 @@
+XCOMM $Xorg: Imake.cf,v 1.4 2000/08/17 19:41:45 cpqbld Exp $
+/*
+ * To add support for another platform:
+ * 
+ *     1.  Identify a machine-specific cpp symbol.  If your preprocessor 
+ *         does not have any built in, you will need to add the symbol to the
+ *         cpp_argv table in config/imake/imakemdep.h and rebuild imake with
+ *         the BOOTSTRAPCFLAGS variable set (see the macII for an example).
+ *
+ *     2.  Add all machine-specific cpp symbols (either defined by you or by
+ *         the preprocessor or compiler) to the predefs table in 
+ *         config/imake/imakemdep.h.
+ *
+ *     3.  But a new #ifdef block below that defines MacroIncludeFile and
+ *         MacroFile for your new platform and then #undefs the machine-
+ *         specific preprocessor symbols (to avoid problems with file names).
+ *
+ *     4.  Create a .cf file with the name given by MacroFile.
+ */
+XCOMM $XFree86: xc/config/cf/Imake.cf,v 3.66 2001/04/18 16:13:17 dawes Exp $
+
+#if defined(__APPLE__)
+# undef __APPLE__
+# define MacroIncludeFile <darwin.cf>
+# define MacroFile darwin.cf
+# define DarwinArchitecture
+# ifdef __ppc__
+#  define PpcDarwinArchitecture
+#  undef __ppc__
+# endif
+# ifdef __i386__
+#  define i386DarwinArchitecture
+#  undef __i386__
+# endif
+#endif
+
+#if defined(clipper) || defined(__clipper__)
+# undef clipper
+# define MacroIncludeFile <ingr.cf>
+# define MacroFile ingr.cf
+# define IngrArchitecture
+#endif /* clipper */
+
+#ifdef __CYGWIN__
+#define MacroIncludeFile <cygwin.cf>
+#define MacroFile cygwin.cf
+#define cygwinArchitecture
+#define i386Architecture
+#undef i386
+#undef __i386__
+#undef _X86_
+#undef __CYGWIN__
+#endif /* CYGWIN */
+
+#ifdef ultrix
+# define MacroIncludeFile <ultrix.cf>
+# define MacroFile ultrix.cf
+# ifdef vax
+#  undef vax
+#  define VaxArchitecture
+# endif
+# ifdef mips
+#  undef mips
+#  define MipsArchitecture
+#  define MipselArchitecture
+# endif
+# undef ultrix
+# define UltrixArchitecture
+#endif /* ultrix */
+
+#if defined(vax) && !defined(UltrixArchitecture)
+# define MacroIncludeFile <bsd.cf>
+# define MacroFile bsd.cf
+# undef vax
+# define BSDArchitecture
+# define VaxArchitecture
+#endif /* vax */
+
+#ifdef bsdi
+# define MacroIncludeFile <bsdi.cf>
+# define MacroFile bsdi.cf
+# undef bsdi
+# define BSDOSArchitecture
+# if defined(__i386__) || defined(i386)
+#  define i386BsdArchitecture
+#  define i386Architecture
+#  undef i386
+#  undef __i386__
+# endif
+# if defined(__sparc__) || defined(__sparc_v9__) || defined(sparc)
+#  define SparcArchitecture
+#  undef sparc
+#  undef __sparc__
+#  undef __sparc_v9__
+# endif
+#endif /* bsdi */
+
+#ifdef __OpenBSD__
+# undef __OpenBSD__
+# undef __NetBSD__
+# define OpenBSDArchitecture
+# define MacroIncludeFile <OpenBSD.cf>
+# define MacroFile OpenBSD.cf
+# ifdef __i386__
+#  define i386BsdArchitecture
+#  define i386Architecture
+#  undef i386
+# endif
+# if defined(__sparc__) || defined(sparc)
+#  define SparcArchitecture
+#  undef sparc
+# endif
+# ifdef mips
+#   define MipsArchitecture
+#   ifdef arc
+#     define ArcArchitecture
+#     undef arc
+#   endif
+#   ifdef pmax
+#     define PmaxArchitecture
+#     undef pmax
+#   endif
+#   undef mips
+# endif
+# ifdef __alpha__
+#   define AlphaArchitecture
+#   undef __alpha__
+# endif
+# ifdef mc68020
+#  define Mc68020Architecture
+#  if defined(amiga)
+#   define AmigaArchitecture
+#   undef amiga
+#  endif
+#  if defined(hp300)
+#   define Hp300Architecture
+#   undef hp300
+#  endif
+#  if defined(mac68k)
+#    define Mac68kArchitecture
+#    undef mac68k
+#  endif
+#  if defined(mvme68k)
+#   define Mvme68kArchitecture
+#   undef mvme68k
+#  endif
+#  if defined(sun3) 
+#   define Sun3Architecture
+#   undef sun3
+#  endif
+#  undef mc68000
+# endif
+# ifdef __powerpc__
+#  define PpcArchitecture
+#  undef __powerpc__
+# endif
+#endif /* OpenBSD */
+
+#ifdef __NetBSD__
+# define MacroIncludeFile <NetBSD.cf>
+# define MacroFile NetBSD.cf
+# undef __NetBSD__
+# define NetBSDArchitecture
+# ifdef __i386__
+#  define i386BsdArchitecture
+#  define i386Architecture
+#  undef i386
+# endif
+# if defined(__sparc__) || defined(sparc)
+#  define SparcArchitecture
+#  undef sparc
+# endif
+# ifdef mips
+#   define MipsArchitecture
+#   define ArcArchitecture
+#   undef mips
+# endif
+# ifdef __alpha__
+#   define AlphaArchitecture
+#   undef __alpha__
+# endif
+# ifdef mc68000
+#   define Mc68020Architecture
+# endif
+# ifdef __arm32__
+#   define Arm32Architecture
+#   undef __arm32__
+# endif
+# ifdef __vax__
+#   define VaxArchitecture
+#   undef __vax__
+# endif
+# ifdef __powerpc__
+#   define PpcArchitecture
+#   undef __powerpc__
+# endif
+#endif /* NetBSD */
+
+#ifdef __FreeBSD__
+# define MacroIncludeFile <FreeBSD.cf>
+# define MacroFile FreeBSD.cf
+# undef __FreeBSD__
+# define FreeBSDArchitecture
+# ifdef __i386__
+#  define i386BsdArchitecture
+#  define i386Architecture
+#  undef i386
+# endif
+# ifdef __alpha__
+#  define AlphaBsdArchitecture
+#  define AlphaArchitecture
+#  undef __alpha__
+# endif
+#endif /* __FreeBSD__ */
+
+#ifdef AMOEBA
+ /* Should be before the 'sun' entry because we may be cross-compiling */
+# define MacroIncludeFile <Amoeba.cf>
+# define MacroFile Amoeba.cf
+# if defined(i80386) || defined(__i80386__)
+#  undef i80386
+#  define i386Architecture
+# else
+#  if defined(mc68000) || defined(__mc68000__)
+#   undef mc68000
+#   define Sun3Architecture
+#   define SunArchitecture
+#  else
+#   if defined(sparc) || defined(__sparc__)
+#    undef sparc
+#    define SparcArchitecture
+#    define SunArchitecture
+#   endif
+#  endif
+#  undef sun
+# endif
+#endif /* AMOEBA */
+
+#ifdef sun
+# define MacroIncludeFile <sun.cf>
+# define MacroFile sun.cf
+# ifdef SVR4
+#  undef SVR4
+#  define SVR4Architecture
+# endif
+# ifdef sparc
+#  undef sparc
+# define SparcArchitecture
+# endif
+# ifdef mc68000
+#  undef mc68000
+# define Sun3Architecture
+# endif
+# ifdef i386
+#  undef i386
+#  define i386Architecture
+# endif
+# undef sun
+# define SunArchitecture
+#endif /* sun */
+
+#ifdef hpux
+# define MacroIncludeFile <hp.cf>
+# define MacroFile hp.cf
+# undef hpux
+# define HPArchitecture
+#endif /* hpux */
+
+#ifdef sco
+# define MacroIncludeFile <sco5.cf>
+# define MacroFile sco5.cf
+# undef sco
+# undef USL
+# undef SYSV
+# undef i386
+# undef SCO
+# undef SVR4
+# define i386Architecture
+# define SCOArchitecture
+# define i386SVR3Architecture
+# define SVR3Architecture
+# define i386ScoArchitecture
+# define i386Sco325Architecture
+#endif /* sco - SCO Open Server 5 */
+
+#ifdef USL
+# define MacroIncludeFile <usl.cf>
+# define MacroFile usl.cf
+# undef USL
+# undef SVR4
+# undef i386
+# define SVR4Architecture
+# define i386Architecture
+# define USLArchitecture
+#endif /* USL */
+
+#ifdef NCR
+# define MacroIncludeFile <ncr.cf>
+# define MacroFile ncr.cf
+# undef NCR
+# undef SVR4
+# undef i386
+# define SVR4Architecture
+# define i386Architecture
+# define NCRArchitecture
+#endif /* NCR */
+
+#ifdef apollo
+# define MacroIncludeFile <apollo.cf>
+# define MacroFile apollo.cf
+# undef apollo
+# define ApolloArchitecture
+#endif /* apollo */
+
+#ifdef sony
+# define MacroIncludeFile <sony.cf>
+# define MacroFile sony.cf
+# undef sony
+# undef sony_news
+# define SonyArchitecture
+# ifdef mc68020
+#  undef mc68020
+#  undef mc68030
+#  define Mc68020Architecture
+# endif
+# ifdef mips
+#  undef mips
+#  define MipsArchitecture
+# endif
+# ifdef __svr4
+#  define SVR4Architecture
+# else
+#  if !defined(bsd43) || defined(SYSTYPE_SYSV) || defined(_SYSTYPE_SYSV)
+#   define SonySysvArchitecture
+#  else
+#   define SonyBsdArchitecture
+#  endif
+# endif
+#endif /* sony */
+
+#ifdef M4310
+# define MacroIncludeFile <pegasus.cf>
+# define MacroFile pegasus.cf
+# undef M4310
+# define PegasusArchitecture
+#endif /* M4310 */
+
+#ifdef M4330
+# define MacroIncludeFile <m4330.cf>
+# define MacroFile m4330.cf
+# undef  M4330
+# define M4330Architecture
+#endif /* M4330 */
+
+#ifdef macII
+# define MacroIncludeFile <macII.cf>
+# define MacroFile macII.cf
+# undef  macII
+# define MacIIArchitecture
+#endif /* macII */
+
+#ifdef _CRAY
+# define MacroIncludeFile <cray.cf>
+# define MacroFile cray.cf
+# undef cray
+# undef CRAY
+# undef CRAY1
+# undef CRAY2
+# undef YMP
+# define CrayArchitecture
+#endif /* _CRAY */
+
+#ifdef sgi
+# define MacroIncludeFile <sgi.cf>
+# define MacroFile sgi.cf
+# undef sgi
+# define SGIArchitecture
+# undef mips
+# undef __mips
+# define MipsArchitecture
+# ifdef _SVR4
+#  undef _SVR4
+#  define SVR4Architecture
+# endif
+# ifdef _SYSTYPE_SVR4
+#  undef _SYSTYPE_SVR4
+#  define SVR4Architecture
+# endif
+#endif /* sgi */
+
+#ifdef stellar
+# define MacroIncludeFile <stellar.cf>
+# define MacroFile stellar.cf
+# undef stellar
+# define StellarArchitecture
+#endif /* stellar */
+
+#if defined(ibm) || defined(_IBMR2) || defined(ibm032) || defined(aix)
+# define MacroIncludeFile <ibm.cf>
+# define MacroFile ibm.cf
+# ifdef ibm
+#  undef ibm
+# endif
+# define IBMArchitecture
+# ifdef i386
+#  undef i386
+#  define PS2Architecture
+# endif
+# ifdef ibm032
+#  undef ibm032
+#  define RtArchitecture
+# endif
+# ifdef aix
+#  undef aix
+#  define AIXArchitecture
+# endif
+# ifdef _IBMR2
+#  undef _IBMR2
+#  define RsArchitecture
+# endif
+#endif /* ibm */
+
+#ifdef luna
+# undef luna
+# define MacroIncludeFile <luna.cf>
+# define MacroFile luna.cf
+# define LunaArchitecture
+# ifdef mc68000
+#  undef mc68000
+#  define Mc68000Architecture
+# else
+#  undef mc88000
+#  define Mc88000Architecture
+# endif
+#endif /* luna */
+
+#ifdef Mips
+#  define MacroIncludeFile <Mips.cf>
+#  define MacroFile Mips.cf
+#  undef Mips
+#  undef mips
+#  if defined(SYSTYPE_BSD43) || defined(BSD) || defined(BSD43)
+#    define MipsBsdArchitecture
+#  else /* BSD */
+#    define MipsSysvArchitecture
+#  endif /* BSD */
+#endif /* Mips */
+
+#ifdef MOTOROLA
+# define MacroIncludeFile <moto.cf>
+# define MacroFile moto.cf
+# undef MOTOROLA       
+# ifdef SYSV
+#  define MotoR3Architecture
+# endif
+# ifdef SVR4
+#  define MotoR4Architecture
+# endif
+#endif /* MOTOROLA */
+
+#if defined(SVR4) && !defined(DGUX)
+# ifdef i386
+#  define i386Architecture
+#  undef i386
+# endif
+# ifdef PC98
+#  define PANIX98Architecture
+#  undef PC98
+# endif
+# define SVR4Architecture
+# define MacroIncludeFile <svr4.cf>
+# define MacroFile svr4.cf
+# undef SVR4
+#endif /* SVR4 */
+
+#ifdef SYSV
+# ifdef i386
+# undef i386
+#  ifdef ISC
+#   define i386Architecture    
+#   define i386SVR3Architecture        
+#   define MacroIncludeFile <isc.cf>
+#   define MacroFile isc.cf
+#   define i386IscArchitecture
+#   undef ISC
+#   ifdef ISC202
+#    define IscVersion 202
+#    undef ISC202
+#   else
+#    ifdef ISC30
+#     define IscVersion 300
+#     undef ISC30
+#    else
+#     ifdef ISC40
+#      define IscVersion 400
+#      undef ISC40
+#     else
+#      define IscVersion 221
+#     endif /* ISC40 */
+#    endif /* ISC30 */
+#   endif /* ISC202 */
+#  endif /* ISC */
+#  ifndef MacroFile
+#   define i386SVR3Architecture
+#   define MacroIncludeFile <x386.cf>
+#   define MacroFile x386.cf
+#  endif /* MacroFile */
+# endif /* i386 */
+#endif /* SYSV */
+
+/* SYSV386 is here for backward compatibility only */
+#ifdef SYSV386
+# undef i386
+# ifdef SVR4
+#  define i386Architecture
+#  define SVR4Architecture
+#  define i386SVR4Architecture
+#  define MacroIncludeFile <svr4.cf>
+#  define MacroFile svr4.cf
+#  undef SVR4
+# else /* ! SVR4 */
+#  ifdef ISC
+#   define i386Architecture    
+#   define i386SVR3Architecture        
+#   define MacroIncludeFile <isc.cf>
+#   define MacroFile isc.cf
+#   define i386IscArchitecture
+#   undef ISC
+#   ifdef ISC202
+#    define IscVersion 202
+#    undef ISC202
+#   else
+#    ifdef ISC30
+#     define IscVersion 300
+#     undef ISC30
+#    else
+#     ifdef ISC40
+#      define IscVersion 400
+#      undef ISC40
+#     else
+#      define IscVersion 221
+#     endif /* ISC40 */
+#    endif /* ISC30 */
+#   endif /* ISC202 */
+#  endif /* ISC */
+#  ifndef MacroFile
+#   define i386SVR3Architecture
+#   define MacroIncludeFile <x386.cf>
+#   define MacroFile x386.cf
+#  endif /* MacroFile */
+# endif /* ! SVR4 */
+#endif /* SYSV386 */
+
+#ifdef DGUX
+# define i386Architecture
+# define SVR4Architecture
+# define MacroIncludeFile <DGUX.cf>
+# define MacroFile DGUX.cf
+# undef DGUX
+# define DguxArchitecture
+#endif /* DGUX */
+
+#ifdef __convex__
+# define MacroIncludeFile <convex.cf>
+# define MacroFile convex.cf
+# ifdef convex
+#  undef convex
+# endif
+# define ConvexArchitecture
+#endif /* _convex_ */
+
+#ifdef __osf__
+# define MacroIncludeFile <osf1.cf>
+# define MacroFile osf1.cf
+# define OSF1Architecture
+# undef __osf__
+# ifdef __mips__
+#  undef __mips__
+#  define MipsArchitecture
+#  define MipselArchitecture
+# endif
+# ifdef __alpha
+#  undef __alpha
+#  define AlphaArchitecture
+# endif
+#endif /* __osf__ */
+
+#ifdef Oki
+# define MacroIncludeFile <Oki.cf>
+# define MacroFile Oki.cf
+# undef Oki
+# define i860SVR4Architecture
+# define SVR4Architecture
+# undef SVR4
+#endif /* Oki */
+
+#ifdef WIN32
+# define MacroIncludeFile <Win32.cf>
+# define MacroFile Win32.cf
+# define Win32Architecture
+#endif /* WIN32 */
+
+#ifdef linux 
+# define MacroIncludeFile <linux.cf>
+# define MacroFile linux.cf
+# undef linux
+# define LinuxArchitecture
+# ifdef i386
+#  ifndef i386Architecture
+#   define i386Architecture
+#  endif
+#  undef i386
+XCOMM Keep cpp from replacing path elements containing i486/i586/i686
+#  ifdef i486
+#  ifndef i386Architecture
+#   define i386Architecture
+#  endif
+#   undef i486
+#  endif
+#  ifdef i586
+#  ifndef i386Architecture
+#   define i386Architecture
+#  endif
+#   undef i586
+#  endif
+#  ifdef i686
+#  ifndef i386Architecture
+#   define i386Architecture
+#  endif
+#   undef i686
+#  endif
+#  ifdef k6
+#  ifndef i386Architecture
+#   define i386Architecture
+#  endif
+#   undef k6
+#  endif
+# endif /* k6 */
+# ifdef __i386__
+#  ifndef i386Architecture
+#   define i386Architecture
+#  endif
+#  undef __i386__
+# endif /* __i386__ */
+# ifdef __i486__
+#  ifndef i386Architecture
+#   define i386Architecture
+#  endif
+#  undef __i486__
+# endif /* __i486__ */
+# ifdef __i586__
+#  ifndef i386Architecture
+#   define i386Architecture
+#  endif
+#  undef __i586__
+# endif /* __i586__ */
+# ifdef __i686__
+#  ifndef i386Architecture
+#   define i386Architecture
+#  endif
+#  undef __i686__
+# endif /* __i686__ */
+# ifdef __k6__
+#  ifndef i386Architecture
+#   define i386Architecture
+#  endif
+#  undef __k6__
+# endif /* __k6__ */
+# ifdef __i386
+#  ifndef i386Architecture
+#   define i386Architecture
+#  endif
+#  undef __i386
+# endif /* __i386 */
+# ifdef __i486
+#  ifndef i386Architecture
+#   define i386Architecture
+#  endif
+#  undef __i486
+# endif /* __i486 */
+# ifdef __i586
+#  ifndef i386Architecture
+#   define i386Architecture
+#  endif
+#  undef __i586
+# endif /* __i586 */
+# ifdef __i686
+#  ifndef i386Architecture
+#   define i386Architecture
+#  endif
+#  undef __i686
+# endif /* __i686 */
+# ifdef __k6
+#  ifndef i386Architecture
+#   define i386Architecture
+#  endif
+#  undef __k6
+# endif /* __k6 */
+# ifdef __s390__
+#   define s390Architecture
+#  undef __s390__
+# endif /* s390 */
+# ifdef __alpha
+#  define AlphaArchitecture
+#  undef __alpha
+# endif /* __alpha */
+# ifdef __alpha__
+#  ifndef AlphaArchitecture
+#   define AlphaArchitecture
+#  endif
+#  undef __alpha__
+# endif /* __alpha__ */
+# ifdef __arm__
+#  define Arm32Architecture
+#  undef arm
+#  undef __arm
+#  undef __arm__
+# endif
+# ifdef mc68000
+#  define Mc68020Architecture
+#  undef mc68000
+# endif /* mc68000 */
+# ifdef powerpc
+#  define PpcArchitecture
+#  undef powerpc
+# endif
+# ifdef __powerpc__
+#  ifndef PpcArchitecture
+#   define PpcArchitecture
+#  endif
+#  undef __powerpc__
+# endif
+# ifdef sparc
+#  define SparcArchitecture
+#  undef sparc
+# endif
+# ifdef __sparc__
+#  ifndef SparcArchitecture
+#   define SparcArchitecture
+#  endif
+#  undef __sparc__
+# endif
+# ifdef x86_64 
+#  define x86_64Architecture
+#  undef x86_64 
+# endif
+# ifdef __x86_64__
+#  ifndef x86_64Architecture
+#   define x86_64Architecture
+#  endif
+#  undef __x86_64__
+# endif
+# ifdef ia64 
+#  define ia64Architecture
+#  undef ia64 
+# endif
+# ifdef __ia64__
+#  ifndef ia64Architecture
+#   define ia64Architecture
+#  endif
+#  undef __ia64__
+# endif
+# if defined(mips) || defined(__mips__)
+#  define MipsArchitecture
+#  undef mips
+#  undef __mips__
+#  if defined(MIPSEL) || defined(_MIPSEL)
+#   define MipselArchitecture
+#  endif
+#  undef MIPSEL
+#  undef _MIPSEL
+# endif
+# ifdef __hppa__
+#  ifndef HPArchitecture
+#   define HPArchitecture
+#  endif
+#  undef __hppa__
+# endif /* __hppa__ */
+# ifdef __sh__
+#  ifndef SuperHArchitecture
+#   define SuperHArchitecture
+#  endif
+#  ifdef __BIG_ENDIAN__
+#   ifndef SuperHebArchitecture
+#    define SuperHebArchitecture
+#   endif
+#  endif
+#  undef __sh__
+# endif /* __sh__ */
+# if defined(__SH3__) || defined(__sh3__)
+#  ifndef SuperH3Architecture
+#   define SuperH3Architecture
+#  endif
+#  undef __SH3__
+#  undef __sh3__
+# endif /* __SH3__ or __sh3__ */
+# ifdef __SH4__
+#  ifdef __SH4_NOFPU__
+#   ifndef SuperH4NOFPUArchitecture
+#    define SuperH4NOFPUArchitecture
+#   endif
+#   undef __SH4_NOFPU__
+#  else
+#   ifndef SuperH4Architecture
+#    define SuperH4Architecture
+#   endif
+#  endif
+#  undef __SH4__
+# endif /* __SH4__ */
+XCOMM  for compatibility with 3.3.x 
+# ifdef PpcArchitecture
+#  define PowerPCArchitecture
+# endif
+#endif /* linux */
+
+#if (defined(__Lynx__) || defined(Lynx)) && (defined(i386) || defined(__i386__) || defined(__x86__) || defined(__powerpc__) || defined(__sparc__) || defined(sparc))
+# define MacroIncludeFile <lynx.cf>
+# define MacroFile lynx.cf
+# define LynxOSArchitecture
+# undef __Lynx__
+# undef Lynx
+# undef lynx
+# if defined(i386) || defined(__i386__) || defined(__x86__)
+#  define i386Architecture
+#  undef i386
+#  undef __i386__
+#  undef __x86__
+# endif
+# ifdef __powerpc__
+#  define PpcArchitecture
+#  undef __powerpc__
+# endif
+# if defined(sparc) || defined(__sparc__)
+#  define SparcArchitecture
+#  undef sparc
+#  undef __sparc__
+# endif
+/* for compatibility with 3.3.x */
+# ifdef PpcArchitecture
+#  define PowerPCArchitecture
+# endif
+#endif /* LynxOS AT/PPC/microSPARC */
+
+#ifdef __uxp__
+# define MacroIncludeFile <fujitsu.cf>
+# define MacroFile fujitsu.cf
+# define FujitsuArchitecture
+# undef __uxp__
+# define UXPArchitecture
+# define SVR4Architecture
+# ifdef sparc
+#  undef sparc
+#  define SparcArchitecture
+# endif
+#endif /* __uxp__ */
+
+#ifdef __sxg__
+# define MacroIncludeFile <fujitsu.cf>
+# define MacroFile fujitsu.cf
+# define FujitsuArchitecture
+# undef __sxg__
+# define mc68000Architecture
+#endif /* __sxg__ */
+
+#ifdef _SEQUENT_
+/* undefine assignments resulting from -DSVR4 */
+# undef MacroIncludeFile
+# define MacroIncludeFile <sequent.cf>
+# undef MacroFile
+# define MacroFile sequent.cf
+# undef _SEQUENT_
+# define DynixPtxArchitecture
+# define SequentArchitecture
+#endif
+
+#if defined(_nec_ews_svr4) || defined(nec_ews_svr4) || defined(nec_ews_svr2) || defined(SX) || defined(_nec_up) || defined(_nec_ft) || defined(PC_UX)
+# ifdef nec
+#  undef nec
+# endif
+# define MacroIncludeFile <nec.cf>
+# define MacroFile nec.cf
+# define NecArchitecture
+#endif
+
+#ifdef minix 
+#define MacroIncludeFile <minix.cf>
+#define MacroFile minix.cf
+#undef minix
+#define MinixArchitecture
+#define i386Architecture
+#endif /* minix */
+
+#ifdef MACH
+#ifdef __GNU__
+#define MacroIncludeFile <gnu.cf>
+#define MacroFile gnu.cf
+#define GNUMachArchitecture
+#else
+#define MacroIncludeFile <mach.cf>
+#define MacroFile mach.cf
+#endif
+#undef MACH
+#ifdef i386
+#define i386MachArchitecture
+#define i386Architecture
+#endif /* i386 */
+#undef i386
+#endif /* MACH */
+
+/* On NetBSD, `unix' is not defined, and cpp emits a warning every time
+ * it sees a test using the `unix' symbol */
+#if !defined(NetBSDArchitecture) || (defined(NetBSDArchitecture) && DefaultOSMajorVersion == 1 && DefaultOSMinorVersion <= 3)
+#ifdef unix
+#undef unix
+#endif
+#endif
+
+#ifdef emxos2
+#define MacroIncludeFile <os2.cf>
+#define MacroFile os2.cf
+#define OS2Architecture
+#define i386Architecture
+#endif /* emxos2 */
+
+#if defined(__QNX__) && !defined(__QNXNTO__)
+#define MacroIncludeFile <QNX4.cf>
+#define MacroFile QNX4.cf
+#define QNX4Architecture
+#define i386Architecture
+#endif /* QNX4 */
+
+#ifdef __QNXNTO__
+#define MacroIncludeFile <nto.cf>
+#define MacroFile nto.cf
+#define NTOArchitecture
+#ifdef PPC
+# define PPCArchitecture
+# undef PPC
+#else
+#ifdef MIPS
+# define mipsArchitecture
+# undef MIPS
+#else
+#ifdef i386
+# define i386Architecture
+# undef i386
+#endif
+#endif
+#endif
+#endif /* QNX/Neutrino */
+
+#ifdef SparcArchitecture
+# if defined(__sparc_v9) || defined(__arch64__)
+#  define Sparc64Architecture
+# endif
+#endif
+
+#ifndef MacroIncludeFile
+XCOMM WARNING:  Imake.cf not configured; guessing at definitions!!!
+XCOMM This might mean that BOOTSTRAPCFLAGS was not set when building imake.
+#define MacroIncludeFile <generic.cf>
+#define MacroFile generic.cf
+#endif
diff --git a/Xserver/config/cf/Imake.rules b/Xserver/config/cf/Imake.rules
new file mode 100644 (file)
index 0000000..5ab9a18
--- /dev/null
@@ -0,0 +1,2650 @@
+XCOMM ---------------------------------------------------------------------
+XCOMM Imake rules for building libraries, programs, scripts, and data files
+XCOMM rules:  $TOG: Imake.rules /main/222 1997/07/17 20:04:40 kaleb $
+XCOMM rules:  $XFree86: xc/config/cf/Imake.rules,v 3.33.2.7 1998/02/06 09:02:17 dawes Exp $
+
+/*
+ *                MACHINE-INDEPENDENT RULES; DO NOT MODIFY
+ *
+ * Warning, when defining rules: make sure you do not include both a trailing
+ * backslash and double ampersand backslash or else you will get an extra
+ * backslash in the Makefile.
+ * 
+ * The following macros are defined for the various templates and Imakefiles
+ * (for a list of the applicable make variables, see the template files):
+ * 
+ * Concat                      (a,b)
+ * Concat3                     (a,b,c)
+ * Concat4                     (a,b,c,d)
+ * _Use                                (a,b)
+ * _UseCat                     (a,b,c)
+ * _MUse                       (a,b)
+ * _MUseCat                    (a,b,c)
+ * ProgramTargetName           (target)
+ * RunProgram                  (progvar,options)
+ * RunProgramWithSetup         (setup,progvar,options)
+ * RemoveFile                  (file)
+ * RemoveFiles                 (files)
+ * CenterLoadTarget            (target,srclist,libs,defines)
+ * CenterProgramTarget         (program,srclist,objlist,locallibs,syslibs)
+ * SentinelLinkTarget          (step,program,linklist)
+ * SentinelProgramTarget       (program,deplist,linklist)
+ * SentinelCplusplusProgramTarget      (program,deplist,linklist)
+ * PurifyLinkTarget            (step,program,linklist)
+ * PurifyProgramTarget         (program,deplist,linklist)
+ * PurifyCplusplusProgramTarget        (program,deplist,linklist)
+ * ProofLinkTarget             (step,program,linklist)
+ * ProofProgramTarget          (program,deplist,linklist)
+ * ProofCplusplusProgramTarget (program,deplist,linklist)
+ * ProofCleanTarget            ()
+ * RemoveTargetProgram         (program)
+ * MakeDir                     (dir)
+ * BuildIncludesTop            (srclist)
+ * BuildIncludes               (srclist,dstsubdir,dstupdir)
+ * LinkRule                    (program,options,objects,libraries)
+ * HostLinkRule                        (program,options,objects,libraries)
+ * NoCmpScript                 (target)
+ * NoConfigRec                 (target)
+ * NormalProgramTarget         (program,objects,deplibs,locallibs,syslibs)
+ * SetUIDProgramTarget         (program,objects,deplibs,locallibs,syslibs)
+ * SingleProgramTarget         (program,objects,locallibs,syslibs)
+ * SimpleProgramTarget         (program)
+ * ComplexProgramTarget                (program)
+ * ComplexProgramTarget_1      (program,locallib,syslib)
+ * ComplexProgramTarget_2      (program,locallib,syslib)
+ * ComplexProgramTarget_3      (program,locallib,syslib)
+ * ServerTargetWithFlags       (server,subdirs,objects,libs,syslibs,flags)
+ * ServerTarget                        (server,subdirs,objects,libs,syslibs)
+ * MoveToBakFile               (file)
+ * RMoveToBakFile              (file)
+ * RanLibrary                  (args)
+ * LibraryTargetName           (libname)
+ * LibraryTargetNameSuffix     (libname,suffix)
+ * InstallNamedTarget          (step,srcname,flags,dest,dstname)
+ * InstallTarget               (step,file,flags,dest)
+ * InstallLibrary              (libname,dest)
+ * MergeIntoInstalledLibrary   (tolib,fromlib)
+ * InstallLibraryAlias         (libname,alias,dest)
+ * InstallLintLibrary          (libname,dest)
+ * InstallManPageLong          (file,destdir,dest)
+ * InstallManPage              (file,destdir)
+ * InstallManPageAliases       (file,destdir,aliases)
+ * ManKeywordsTarget           (manpath)
+ * InstallNamedNonExec         (srcname,dstname,dest)
+ * InstallNonExecFile          (file,dest)
+ * InstallNonExecFileNoClobber (file,dest)
+ * InstallNonExec              (file,dest)
+ * InstallProgramWithFlags     (program,dest,flags)
+ * InstallProgram              (program,dest)
+ * InstallScript               (program,dest)
+ * InstallNamedProg            (srcname,dstname,dest)
+ * InstallNamedProgNoClobber   (srcname,dstname,dest)
+ * MakeFlagsToShellFlags       (makeflags,shellcmd)
+ * MakeNamedTargetSubdir       (dir,flags,subname)
+ * LinkFileList                        (step,list,dir,sub)
+ * LinkVarDirectory            (mdir,cdir,rdir,ldir)
+ * InstallMultipleDestFlags    (step,list,dest,flags)
+ * InstallMultipleDest         (step,list,dest)
+ * InstallMultiple             (list,dest)
+ * InstallMultipleFlags                (list,dest,flags)
+ * InstallMultipleMan          (list,dest)
+ * DependDependency            ()
+ * DependTarget                        ()
+ * DependTarget3               (srcs1,srcs2,srcs3)
+ * CleanTarget                 ()
+ * TagsTarget                  ()
+ * ImakeDependency             (target)
+ * BuildMakefileTarget         (notused,imakeflags)
+ * MakefileTarget              ()
+ * LibMkdir                    (dir)
+ * LibCleanDir                 (dir)
+ * LintLibReferences           (varname,libname,libsource)
+ * UnsharedLibReferences       (varname,libname,libsource)
+ * ProjectUnsharedLibReferences        (varname,libname,libsource,buildlibdir)
+ * SharedLibDependencies       (libname,libsource,revname)
+ * SharedDSLibDependencies     (libname,libsource,revname)
+ * SharedLibReferences         (varname,libname,libsource,revname,rev)
+ * SharedDSLibReferences       (varname,libname,libsource,revname,rev)
+ * ObjectCompile               (options)
+ * NormalLibObjCompile         (options)
+ * NormalSharedLibObjCompile   (options)
+ * LibObjCompile               (dir,options)
+ * DebuggedLibObjCompile       (options)
+ * ProfiledLibObjCompile       (options)
+ * SharedLibObjCompile         (options)
+ * NormalLibraryObjectRule     ()
+ * NormalFortranObjectRule     ()
+ * ObjectFromSpecialSource     (dst,src,flags)
+ * SpecialObjectRule           (objs,depends,options)
+ * SpecialCObjectRule          (basename,depends,options)
+ * LexFile                     (file)
+ * YaccFile                    (file,flags)
+ * YaccFileNoFlags             (file)
+ * MakeLibrary                 (libname,objlist)
+ * NormalLibraryTarget         (libname,objlist)
+ * NormalLibraryTarget2                (libname,objlist1,objlist2)
+ * NormalLibraryTarget3                (libname,objlist1,objlist2,objlist3)
+ * NormalDepLibraryTarget      (libname,deplist,objlist)
+ * UnsharedLibraryTarget       (libname,objlist,down,up)
+ * UnsharedLibraryTarget3      (libname,objlist1,objlist2,objlist3,down,up)
+ * SubdirLibraryRule           (objlist)
+ * ProfiledLibraryTarget       (libname,objlist)
+ * DebuggedLibraryTarget       (libname,objlist)
+ * AliasedLibraryTarget                (libname,alias)
+ * NormalRelocatableTarget     (objname,objlist)
+ * ProfiledRelocatableTarget   (objname,objlist)
+ * DebuggedRelocatableTarget   (objname,objlist)
+ * LintLibraryTarget           (libname,srclist)
+ * NormalLintTarget            (srclist)
+ * LintTarget                  ()
+ * LinkSourceFile              (src,dir)
+ * LinkFile                    (tofile,fromfile)
+ * MakeSubincludesForBuild     (step,dir,srclist)
+ * LangNamedTargetSubdirs      (lang,name,dirs,verb,flags,subname)
+ * LangNamedMakeSubdirs                (lang,name,dirs)
+ * LangMakeSubdirs             (lang,dirs)
+ * NamedTargetSubdirs          (name,dirs,verb,flags,subname)
+ * NamedMakeSubdirs            (name,dirs)
+ * MakeSubdirs                 (dirs)
+ * DependSubdirs               (dirs)
+ * ForceSubdirs                        (dirs)
+ * InstallSubdirs              (dirs)
+ * InstallManSubdirs           (dirs)
+ * IncludesSubdirs             (dirs)
+ * NamedCleanSubdirs           (name,dirs)
+ * CleanSubdirs                        (dirs)
+ * NamedTagSubdirs             (name,dirs)
+ * TagSubdirs                  (dirs)
+ * MakeLintSubdirs             (dirs,target,subtarget)
+ * LintSubdirs                 (dirs)
+ * MakeLintLibSubdirs          (dirs)
+ * MakeMakeSubdirs             (dirs,target)
+ * MakefileSubdirs             (dirs)
+ * CppScriptTarget             (dst,src,defs,deplist)
+ * MakeScriptFromCpp           (name,defs)
+ * CppFileTarget               (dst,src,defs,deplist)
+ * CppSourceFile               (dst,src,defs,deplist)
+ * MakeDirectories             (step,dirs)
+ * AllTarget                   (depends)
+ * StaticLibrary               (libpath,libname)
+ * MakeMutex                   (targets)
+ *
+ *
+ * The following are in specific <os>Lib.rules:
+ *
+ * SharedLibraryTarget         (libname,rev,solist,down,up)
+ * SharedLibraryDataTarget     (libname,rev,salist)
+ * InstallSharedLibrary                (libname,rev,dest)
+ * InstallSharedLibraryData    (libname,rev,dest)
+ * 
+ */
+
+#define NullParameter
+
+/* if [ -d ] or [ ! -d ] causes make to fail, define this as - */
+#ifndef DirFailPrefix
+#define DirFailPrefix
+#endif
+
+/*
+ * NoCmpScript - suppress clearmake build script comparison.
+ */
+#ifndef NoCmpScript
+#if HasClearmake
+#define NoCmpScript(targ)                                              @@\
+XCOMM special target for clearmake                                     @@\
+.NO_CMP_SCRIPT: targ
+#else
+#define NoCmpScript(targ) /**/
+#endif
+#endif
+
+/*
+ * NoConfigRec - suppress using clearmake configuration records.
+ */
+#ifndef NoConfigRec
+#if HasClearmake
+#define NoConfigRec(targ)                                              @@\
+XCOMM special target for clearmake                                     @@\
+.NO_CONFIG_REC: targ
+#else
+#define NoConfigRec(targ) /**/
+#endif
+#endif
+
+/*
+ * Concat - concatenates two strings.
+ */
+#ifndef Concat
+#if (__STDC__ && !defined(UnixCpp)) || defined(AnsiCpp)
+#define Concat(a,b)a##b
+#else
+#define Concat(a,b)a/**/b
+#endif
+#endif
+
+/*
+ * Concat3 - concatenates three strings.
+ */
+#ifndef Concat3
+#if (__STDC__ && !defined(UnixCpp)) || defined(AnsiCpp)
+#define Concat3(a,b,c)a##b##c
+#else
+#define Concat3(a,b,c)a/**/b/**/c
+#endif
+#endif
+
+/*
+ * Concat4 - concatenates four strings.
+ */
+#ifndef Concat4
+#if (__STDC__ && !defined(UnixCpp)) || defined(AnsiCpp)
+#define Concat4(a,b,c,d)a##b##c##d
+#else
+#define Concat4(a,b,c,d)a/**/b/**/c/**/d
+#endif
+#endif
+
+/*
+ * _XUse - makes a choice based on UseInstalledX11.
+ */
+#ifndef _XUse
+# if defined(UseInstalled) || UseInstalledX11
+#  define _XUse(a,b) a
+# else
+#  define _XUse(a,b) b
+# endif
+#endif /* _XUse */
+
+/*
+ * _Use - makes a choice based on UseInstalled.
+ */
+#ifndef _Use
+# define _Use  _XUse
+#endif /* _Use */
+
+/*
+ * _XUseCat - combination of _XUse and Concat.
+ *           exists to avoid problems with some preprocessors
+ */
+#ifndef _XUseCat
+# if (__STDC__ && !defined(UnixCpp)) || defined(AnsiCpp)
+#  if defined(UseInstalled) || UseInstalledX11
+#   define _XUseCat(a,b,c) a##c
+#  else
+#   define _XUseCat(a,b,c) b##c
+#  endif
+# else
+#  if defined(UseInstalled) || UseInstalledX11
+#   define _XUseCat(a,b,c) a/**/c
+#  else
+#   define _XUseCat(a,b,c) b/**/c
+#  endif
+# endif
+#endif /* _XUseCat */
+
+/*
+ * _UseCat - combination of _Use and Concat.
+ *           exists to avoid problems with some preprocessors
+ */
+#ifndef _UseCat
+# define _UseCat       _XUseCat
+#endif /* _UseCat */
+
+#ifndef ProgramTargetName
+#define ProgramTargetName(target)target
+#endif
+
+#ifndef RunProgram
+#define RunProgram(progvar,options) $(progvar) options
+#endif
+
+#ifndef RunProgramWithSetup
+#define RunProgramWithSetup(setup,progvar,options) setup $(progvar) options
+#endif
+
+#ifndef RemoveFile
+#define RemoveFile(file) $(RM) file
+#endif /* RemoveFile */
+
+#ifndef RemoveFiles
+#define RemoveFiles(files) $(RM) files
+#endif /* RemoveFiles */
+
+/*
+ * CenterLoadTarget - generate rules to load files into CodeCenter
+ */
+#ifndef CenterLoadTarget
+#if HasCodeCenter
+#define CenterLoadTarget(target,srclist,libs,defines)                  @@\
+ProgramTargetName(target):: srclist                                    @@\
+       XCOMM load defines srclist libs
+#else
+#define CenterLoadTarget(target,srclist,libs,defines) /**/
+#endif
+#endif /* CenterLoadTarget */
+
+/*
+ * CenterProgramTarget - generate rules to make CodeCenter read in sources
+ * and objects.
+ */
+#ifndef CenterProgramTarget
+#define CenterProgramTarget(program,srclist,objlist,locallibs,syslibs) @@\
+CenterLoadTarget(Concat(debug_,program),srclist,$(EXTRA_LDOPTIONS) $(LOCAL_LDFLAGS) $(LDPRELIBS) locallibs $(LDLIBS) syslibs,$(ALLDEFINES)) @@\
+                                                                       @@\
+CenterLoadTarget(Concat(odebug_,program),objlist,$(EXTRA_LDOPTIONS) $(LOCAL_LDFLAGS) $(LDPRELIBS) locallibs $(LDLIBS) syslibs,$(ALLDEFINES))
+#endif /* CenterProgramTarget */
+
+#ifndef SentinelLinkTarget
+#if HasSentinel
+#define SentinelLinkTarget(step,program,linklist)                      @@\
+ProgramTargetName(step.sentinel):                                      @@\
+       RemoveTargetProgram($@)                                         @@\
+       $(CCENVSETUP) $(SENTINEL) $(SENTINELOPTIONS) $(CC) -o program.sentinel $(LDOPTIONS) linklist $(EXTRA_LOAD_FLAGS)
+#else
+#define SentinelLinkTarget(step,program,linklist) /**/
+#endif
+#endif /* SentinelLinkTarget */
+
+/*
+ * SentinelProgramTarget - generate rules to make Sentinel image
+ */
+#ifndef SentinelProgramTarget
+#if HasSentinel
+#define        SentinelProgramTarget(program,deplist,linklist)                 @@\
+ProgramTargetName(program.sentinel): deplist                           @@\
+       RemoveTargetProgram($@)                                         @@\
+       $(CCENVSETUP) $(SENTINEL) $(SENTINELOPTIONS) $(CC) -o $@ $(LDOPTIONS) linklist $(EXTRA_LOAD_FLAGS) @@\
+                                                                       @@\
+clean clean.sentinel::                                                 @@\
+       RemoveFile(program.sentinel)
+#else
+#define        SentinelProgramTarget(program,deplist,linklist) /**/
+#endif
+#endif /* SentinelProgramTarget */
+
+/*
+ * SentinelCplusplusProgramTarget - generate rules to make Sentinel image 
+ */
+#ifndef SentinelCplusplusProgramTarget
+#if HasSentinel
+#define        SentinelCplusplusProgramTarget(program,deplist,linklist)        @@\
+ProgramTargetName(program.sentinel): deplist                           @@\
+       RemoveTargetProgram($@)                                         @@\
+       $(CXXENVSETUP) $(SENTINEL) $(SENTINELOPTIONS) $(CXX) -o $@ $(CXXLDOPTIONS) linklist $(EXTRA_LOAD_FLAGS) @@\
+                                                                       @@\
+clean clean.sentinel::                                                 @@\
+       RemoveFile(program.sentinel)
+#else
+#define        SentinelCplusplusProgramTarget(program,deplist,linklist) /**/
+#endif
+#endif /* SentinelCplusplusProgramTarget */
+
+#ifndef PurifyLinkTarget
+#if HasPurify
+#define PurifyLinkTarget(step,program,linklist)                                @@\
+ProgramTargetName(step.pure):                                          @@\
+       RemoveTargetProgram($@)                                         @@\
+       $(CCENVSETUP) $(PURIFY) $(PURIFYOPTIONS) $(CC) -o program.pure $(LDOPTIONS) linklist $(EXTRA_LOAD_FLAGS)
+#else
+#define PurifyLinkTarget(step,program,linklist) /**/
+#endif
+#endif /* PurifyLinkTarget */
+
+/*
+ * PurifyProgramTarget - generate rules to make Purify'ed image
+ */
+#ifndef PurifyProgramTarget
+#if HasPurify
+#define        PurifyProgramTarget(program,deplist,linklist)                   @@\
+ProgramTargetName(program.pure): deplist                               @@\
+       RemoveTargetProgram($@)                                         @@\
+       $(CCENVSETUP) $(PURIFY) $(PURIFYOPTIONS) $(CC) -o $@ $(LDOPTIONS) linklist $(EXTRA_LOAD_FLAGS) @@\
+                                                                       @@\
+clean clean.pure::                                                     @@\
+       RemoveFile(program.pure)
+#else
+#define        PurifyProgramTarget(program,deplist,linklist) /**/
+#endif
+#endif /* PurifyProgramTarget */
+
+/*
+ * PurifyCplusplusProgramTarget - generate rules to make Purify'ed image
+ */
+#ifndef PurifyCplusplusProgramTarget
+#if HasPurify
+#define        PurifyCplusplusProgramTarget(program,deplist,linklist)          @@\
+ProgramTargetName(program.pure): deplist                               @@\
+       RemoveTargetProgram($@)                                         @@\
+       $(CXXENVSETUP) $(PURIFY) $(PURIFYOPTIONS) $(CXX) -o $@ $(CXXLDOPTIONS) linklist $(EXTRA_LOAD_FLAGS) @@\
+                                                                       @@\
+clean clean.pure::                                                     @@\
+       RemoveFile(program.pure)
+#else
+#define        PurifyCplusplusProgramTarget(program,deplist,linklist) /**/
+#endif
+#endif /* PurifyCplusplusProgramTarget */
+
+#ifndef ProofLinkTarget
+#if HasTestCenter
+#define ProofLinkTarget(step,program,linklist)                         @@\
+ProgramTargetName(step.tc):                                            @@\
+       RemoveTargetProgram($@)                                         @@\
+       $(CCENVSETUP) $(PROOF) $(PROOFOPTIONS) $(CC) -o program.tc $(LDOPTIONS) linklist $(EXTRA_LOAD_FLAGS)
+#else
+#define ProofLinkTarget(step,program,linklist) /**/
+#endif
+#endif /* ProofLinkTarget */
+
+/*
+ * ProofProgramTarget - generate rules to make Proof'ed image
+ */
+#ifndef ProofProgramTarget
+#if HasTestCenter
+#define        ProofProgramTarget(program,deplist,linklist)                    @@\
+ProgramTargetName(program.tc): deplist                                 @@\
+       RemoveTargetProgram($@)                                         @@\
+       $(CCENVSETUP) $(PROOF) $(PROOFOPTIONS) $(CC) -o $@ $(LDOPTIONS) linklist $(EXTRA_LOAD_FLAGS) @@\
+                                                                       @@\
+clean clean.tc::                                                       @@\
+       RemoveFiles(program.tc program.tc.*.*)
+#else
+#define        ProofProgramTarget(program,deplist,linklist) /**/
+#endif
+#endif /* ProofProgramTarget */
+
+/*
+ * ProofCplusplusProgramTarget - generate rules to make Proof'ed image
+ */
+#ifndef ProofCplusplusProgramTarget
+#if HasTestCenter
+#define        ProofCplusplusProgramTarget(program,deplist,linklist)           @@\
+ProgramTargetName(program.tc): deplist                                 @@\
+       RemoveTargetProgram($@)                                         @@\
+       $(CXXENVSETUP) $(PROOF) $(PROOFOPTIONS) $(CXX) -o $@ $(CXXLDOPTIONS) linklist $(EXTRA_LOAD_FLAGS) @@\
+                                                                       @@\
+clean clean.tc::                                                       @@\
+       RemoveFiles(program.tc program.tc.*.*)
+#else
+#define        ProofCplusplusProgramTarget(program,deplist,linklist) /**/
+#endif
+#endif /* ProofCplusplusProgramTarget */
+
+#ifndef ProofCleanTarget
+#if HasTestCenter
+#define ProofCleanTarget()                                             @@\
+clean clean.tc::                                                       @@\
+       $(RM) -r TC.Cache
+#else
+#define ProofCleanTarget() /**/
+#endif
+#endif /* ProofCleanTarget */
+
+#ifndef RemoveTargetProgram
+#if RemoveTargetProgramByMoving
+#define RemoveTargetProgram(program) \
+-if [ -f program ]; then RemoveFile(Concat(program,~)); $(MV) program Concat(program,~); fi
+#else
+#define RemoveTargetProgram(program) RemoveFile(program)
+#endif
+#endif /* RemoveTargetProgram */
+
+#ifndef MakeDir
+#define MakeDir(dir) DirFailPrefix@if [ -d dir ]; then set +x; \       @@\
+               else (set -x; $(MKDIRHIER) dir); fi
+#endif /* MakeDir */
+
+#ifndef BuildIncludesTop
+#define BuildIncludesTop(srclist)                                      @@\
+includes:: srclist                                                     @@\
+       MakeDir($(BUILDINCDIR))                                         @@\
+       @(set -x; cd $(BUILDINCDIR) && for i in srclist; do \           @@\
+               RemoveFile($$i); \                                      @@\
+               $(LN) $(BUILDINCTOP)/$(CURRENT_DIR)/$$i .; \            @@\
+       done)
+#endif /* BuildIncludesTop */
+
+#ifndef BuildIncludes
+#define BuildIncludes(srclist,dstsubdir,dstupdir)                      @@\
+includes:: srclist                                                     @@\
+       MakeDir($(BUILDINCDIR)/dstsubdir)                               @@\
+       @(set -x; cd $(BUILDINCDIR)/dstsubdir && for i in srclist; do \ @@\
+               RemoveFile($$i); \                                      @@\
+               $(LN) $(BUILDINCTOP)/dstupdir/$(CURRENT_DIR)/$$i .; \   @@\
+       done)
+#endif /* BuildIncludes */
+
+/*
+ * LinkBuildBinary - export a binary from the build tree.
+ */
+#ifndef LinkBuildBinary
+#define LinkBuildBinary(binary)                                                @@\
+all:: $(BUILDBINDIR)/binary binary                                     @@\
+                                                                       @@\
+$(BUILDBINDIR)/binary: binary                                          @@\
+       RemoveFile($@)                                                  @@\
+       cd $(BUILDBINDIR) && $(LN) $(BUILDBINTOP)/$(CURRENT_DIR)/binary .
+#endif /* LinkBuildBinary */
+
+#ifndef BuildInterfaces
+#define BuildInterfaces(srclist,dstsubdir,dstupdir)                    @@\
+interfaces::                                                           @@\
+       MakeDir($(BUILDINCDIR)/dstsubdir)                               @@\
+       @(set -x; cd $(BUILDINCDIR)/dstsubdir && for i in srclist; do \ @@\
+               RemoveFile($$i); \                                      @@\
+               $(LN) $(BUILDINCTOP)/dstupdir/$(CURRENT_DIR)/$$i .; \   @@\
+       done)
+#endif /* BuildInterfaces */
+
+/*
+ * LinkRule - link a program
+ */
+#ifndef LinkRule
+#define LinkRule(program,options,objects,libraries) \
+$(CCLINK) -o program options objects libraries $(EXTRA_LOAD_FLAGS)
+#endif /* LinkRule */
+
+/*
+ * HostLinkRule - link a utility to be used on the build host
+ * (differs from LinkRule if cross compiling)
+ */
+#ifndef HostLinkRule
+#define HostLinkRule LinkRule
+#endif
+
+#ifndef CplusplusLinkRule
+#define CplusplusLinkRule(program,options,objects,libraries) \
+$(CXXLINK) -o program options objects libraries $(EXTRA_LOAD_FLAGS)
+#endif /* CplusplusLinkRule */
+
+/*
+ * NormalProgramTarget - generate rules to compile and link the indicated 
+ * program; since it does not use any default object files, it may be used for
+ * multiple programs in the same Imakefile.
+ */
+#ifndef NormalProgramTarget
+#define        NormalProgramTarget(program,objects,deplibs,locallibs,syslibs)  @@\
+ProgramTargetName(program): objects deplibs                            @@\
+       RemoveTargetProgram($@)                                         @@\
+       LinkRule($@,$(LDOPTIONS),objects,locallibs $(LDLIBS) syslibs)   @@\
+                                                                       @@\
+SentinelProgramTarget(program,objects deplibs,objects locallibs $(LDLIBS) syslibs) @@\
+PurifyProgramTarget(program,objects deplibs,objects locallibs $(LDLIBS) syslibs) @@\
+ProofProgramTarget(program,objects deplibs,objects locallibs $(LDLIBS) syslibs) @@\
+                                                                       @@\
+clean::                                                                        @@\
+       RemoveFile(ProgramTargetName(program))
+#endif /* NormalProgramTarget */
+
+
+/*
+ * NormalCplusplusProgramTarget - Like NormalTargetProgram, but uses
+ * C++ linking rules.
+ */
+#ifndef NormalCplusplusProgramTarget
+#define        NormalCplusplusProgramTarget(program,objects,deplibs,locallibs,syslibs) @@\
+ProgramTargetName(program): objects deplibs                            @@\
+       RemoveTargetProgram($@)                                         @@\
+       CplusplusLinkRule($@,$(CXXLDOPTIONS),objects,locallibs $(LDLIBS) syslibs) @@\
+                                                                       @@\
+SentinelCplusplusProgramTarget(program,objects deplibs,objects locallibs $(LDLIBS) syslibs) @@\
+PurifyCplusplusProgramTarget(program,objects deplibs,objects locallibs $(LDLIBS) syslibs) @@\
+ProofCplusplusProgramTarget(program,objects deplibs,objects locallibs $(LDLIBS) syslibs) @@\
+                                                                       @@\
+clean::                                                                        @@\
+       RemoveFile(ProgramTargetName(program))
+#endif /* NormalCplusplusProgramTarget */
+
+
+#ifndef SetUIDProgramTarget
+#define SetUIDProgramTarget NormalProgramTarget
+#endif
+
+
+/*
+ * SingleProgramTarget - obsolete version of NormalProgramTarget that does
+ * not have deplibs.
+ */
+#ifndef SingleProgramTarget
+#define        SingleProgramTarget(program,objects,locallibs,syslibs)          @@\
+NormalProgramTarget(program,objects,NullParameter,locallibs,syslibs)
+#endif /* SingleProgramTarget */
+
+/*
+ * SimpleProgramTarget - generate rules for compiling and linking programs
+ * that only have one C source file.  It should only be used in Imakefiles 
+ * that describe a single program.
+ */
+#ifndef SimpleProgramTarget
+#define        SimpleProgramTarget(program)                                    @@\
+           OBJS = program.o                                            @@\
+           SRCS = program.c                                            @@\
+                                                                       @@\
+ComplexProgramTarget(program)
+#endif /* SimpleProgramTarget */
+
+#ifndef SimpleCplusplusProgramTarget
+#define SimpleCplusplusProgramTarget(program)                          @@\
+           OBJS = program.o                                            @@\
+           SRCS = program.CCsuf                                                @@\
+                                                                       @@\
+ComplexCplusplusProgramTarget(program)
+#endif /* SimpleCplusplusProgramTarget */
+
+#ifndef ProgramTargetHelper
+#define        ProgramTargetHelper(program,srcs,objs,deplib,locallib,syslib)   @@\
+ProgramTargetName(program): $(objs) $(deplib)                          @@\
+       RemoveTargetProgram($@)                                         @@\
+       LinkRule($@,$(LDOPTIONS),$(objs),locallib $(LDLIBS) syslib)     @@\
+                                                                       @@\
+CenterProgramTarget(program,$(srcs),$(objs),locallib,syslib)           @@\
+SentinelProgramTarget(program,$(objs) $(deplib),$(objs) locallib $(LDLIBS) syslib) @@\
+PurifyProgramTarget(program,$(objs) $(deplib),$(objs) locallib $(LDLIBS) syslib) @@\
+ProofProgramTarget(program,$(objs) $(deplib),$(objs) locallib $(LDLIBS) syslib) @@\
+                                                                       @@\
+InstallProgram(program,$(BINDIR))                                      @@\
+InstallManPage(program,$(MANDIR))
+#endif /* ProgramTargetHelper */
+
+#ifndef ProgramTargetHelperNoMan
+#define        ProgramTargetHelperNoMan(program,srcs,objs,deplib,locallib,syslib) @@\
+ProgramTargetName(program): $(objs) $(deplib)                          @@\
+       RemoveTargetProgram($@)                                         @@\
+       LinkRule($@,$(LDOPTIONS),$(objs),locallib $(LDLIBS) syslib)     @@\
+                                                                       @@\
+CenterProgramTarget(program,$(srcs),$(objs),locallib,syslib)           @@\
+SentinelProgramTarget(program,$(objs) $(deplib),$(objs) locallib $(LDLIBS) syslib) @@\
+PurifyProgramTarget(program,$(objs) $(deplib),$(objs) locallib $(LDLIBS) syslib) @@\
+ProofProgramTarget(program,$(objs) $(deplib),$(objs) locallib $(LDLIBS) syslib) @@\
+                                                                       @@\
+InstallProgram(program,$(BINDIR))
+#endif /* ProgramTargetHelperNoMan */
+
+#ifndef CplusplusProgramTargetHelper
+#define        CplusplusProgramTargetHelper(program,srcs,objs,deplib,locallib,syslib) @@\
+ProgramTargetName(program): $(objs) $(deplib)                          @@\
+       RemoveTargetProgram($@)                                         @@\
+       CplusplusLinkRule($@,$(CXXLDOPTIONS),$(objs),locallib $(LDLIBS) syslib) @@\
+                                                                       @@\
+CenterProgramTarget(program,$(srcs),$(objs),locallib,syslib)           @@\
+SentinelCplusplusProgramTarget(program,$(objs) $(deplib),$(objs) locallib $(LDLIBS) syslib) @@\
+PurifyCplusplusProgramTarget(program,$(objs) $(deplib),$(objs) locallib $(LDLIBS) syslib) @@\
+ProofCplusplusProgramTarget(program,$(objs) $(deplib),$(objs) locallib $(LDLIBS) syslib) @@\
+                                                                       @@\
+InstallProgram(program,$(BINDIR))                                      @@\
+InstallManPage(program,$(MANDIR))
+#endif /* CplusplusProgramTargetHelper */
+
+/*
+ * ComplexProgramTarget - generate rules for compiling and linking the 
+ * program specified by $(OBJS) and $(SRCS), installing the program and its
+ * man page, and generating dependencies.  It should only be used in 
+ * Imakefiles that describe a single program.
+ */
+#ifndef ComplexProgramTarget
+#define        ComplexProgramTarget(program)                                   @@\
+        PROGRAM = program                                              @@\
+                                                                       @@\
+AllTarget(program)                                                     @@\
+                                                                       @@\
+ProgramTargetHelper(program,SRCS,OBJS,DEPLIBS,$(LOCAL_LIBRARIES),NullParameter) @@\
+                                                                       @@\
+DependTarget()                                                         @@\
+LintTarget()                                                           @@\
+                                                                       @@\
+clean::                                                                        @@\
+       RemoveFile(ProgramTargetName(program))
+#endif /* ComplexProgramTarget */
+
+#ifndef ComplexCplusplusProgramTarget
+#define        ComplexCplusplusProgramTarget(program)                          @@\
+        PROGRAM = program                                              @@\
+                                                                       @@\
+AllTarget(program)                                                     @@\
+                                                                       @@\
+CplusplusProgramTargetHelper(program,SRCS,OBJS,DEPLIBS,$(LOCAL_LIBRARIES),NullParameter) @@\
+                                                                       @@\
+DependTarget()                                                         @@\
+LintTarget()                                                           @@\
+                                                                       @@\
+clean::                                                                        @@\
+       RemoveFile(ProgramTargetName(program))
+#endif /* ComplexCplusplusProgramTarget */
+
+/*
+ * ComplexProgramTargetNoMan - generate rules for compiling and linking
+ * the program specified by $(OBJS) and $(SRCS), installing the program 
+ * and generating dependencies.  It should only be used in Imakefiles
+ * that describe a single program.
+ */
+#ifndef ComplexProgramTargetNoMan
+#define        ComplexProgramTargetNoMan(program)                      @@\
+        PROGRAM = program                                              @@\
+                                                                       @@\
+AllTarget(program)                                                     @@\
+                                                                       @@\
+ProgramTargetHelperNoMan(program,SRCS,OBJS,DEPLIBS,$(LOCAL_LIBRARIES),NullParameter) @@\
+                                                                       @@\
+DependTarget()                                                         @@\
+LintTarget()                                                           @@\
+                                                                       @@\
+clean::                                                                @@\
+       RemoveFile(ProgramTargetName(program))
+#endif /* ComplexProgramTargetNoMan */
+
+/*
+ * ComplexProgramTarget_1 - generate rules for compiling and linking the
+ * program specified by $(OBJS1) and $(SRCS1), installing the program and its
+ * man page, and generating dependencies for it and any programs described
+ * by $(SRCS2) through $(SRCS10).  It should be used to build the primary 
+ * program in Imakefiles that describe multiple programs.
+ */
+#ifndef ComplexProgramTarget_1
+#define        ComplexProgramTarget_1(program,locallib,syslib)                 @@\
+  OBJS = $(OBJS1) $(OBJS2) $(OBJS3) $(OBJS4) $(OBJS5) \                        @@\
+         $(OBJS6) $(OBJS7) $(OBJS8) $(OBJS9) $(OBJS10)                 @@\
+  SRCS = $(SRCS1) $(SRCS2) $(SRCS3) $(SRCS4) $(SRCS5) \                        @@\
+         $(SRCS6) $(SRCS7) $(SRCS8) $(SRCS9) $(SRCS10)                 @@\
+                                                                       @@\
+AllTarget($(PROGRAMS))                                                 @@\
+                                                                       @@\
+ProgramTargetHelper(program,SRCS1,OBJS1,DEPLIBS1,locallib,syslib)      @@\
+                                                                       @@\
+DependTarget()                                                         @@\
+LintTarget()                                                           @@\
+                                                                       @@\
+clean::                                                                        @@\
+       RemoveFiles($(PROGRAMS))
+#endif /* ComplexProgramTarget_1 */
+
+#ifndef ComplexCplusplusProgramTarget_1
+#define        ComplexCplusplusProgramTarget_1(program,locallib,syslib)        @@\
+  OBJS = $(OBJS1) $(OBJS2) $(OBJS3) $(OBJS4) $(OBJS5) \                        @@\
+         $(OBJS6) $(OBJS7) $(OBJS8) $(OBJS9) $(OBJS10)                 @@\
+  SRCS = $(SRCS1) $(SRCS2) $(SRCS3) $(SRCS4) $(SRCS5) \                        @@\
+         $(SRCS6) $(SRCS7) $(SRCS8) $(SRCS9) $(SRCS10)                 @@\
+                                                                       @@\
+AllTarget($(PROGRAMS))                                                 @@\
+                                                                       @@\
+CplusplusProgramTargetHelper(program,SRCS1,OBJS1,DEPLIBS1,locallib,syslib)@@\
+                                                                       @@\
+DependTarget()                                                         @@\
+LintTarget()                                                           @@\
+                                                                       @@\
+clean::                                                                        @@\
+       RemoveFiles($(PROGRAMS))
+#endif /* ComplexCplusplusProgramTarget_1 */
+
+/*
+ * ComplexProgramTarget_2 - generate rules for compiling and linking the
+ * program specified by $(OBJS2) and $(SRCS2) and installing the program and
+ * man page.  It should be used to build the second program in Imakefiles 
+ * describing more than one program.
+ */
+#ifndef ComplexProgramTarget_2
+#define        ComplexProgramTarget_2(program,locallib,syslib)                 @@\
+ProgramTargetHelper(program,SRCS2,OBJS2,DEPLIBS2,locallib,syslib)
+#endif /* ComplexProgramTarget_2 */
+
+#ifndef ComplexCplusplusProgramTarget_2
+#define        ComplexCplusplusProgramTarget_2(program,locallib,syslib)        @@\
+CplusplusProgramTargetHelper(program,SRCS2,OBJS2,DEPLIBS2,locallib,syslib)
+#endif /* ComplexCplusplusProgramTarget_2 */
+
+/*
+ * ComplexProgramTarget_3 - generate rules for compiling and linking the
+ * program specified by $(OBJS3) and $(SRCS3) and installing the program and
+ * man page.  It should be used to build the third program in Imakefiles 
+ * describing more than one program.
+ */
+#ifndef ComplexProgramTarget_3
+#define        ComplexProgramTarget_3(program,locallib,syslib)                 @@\
+ProgramTargetHelper(program,SRCS3,OBJS3,DEPLIBS3,locallib,syslib)
+#endif /* ComplexProgramTarget_3 */
+
+#ifndef ComplexCplusplusProgramTarget_3
+#define        ComplexCplusplusProgramTarget_3(program,locallib,syslib)        @@\
+CplusplusProgramTargetHelper(program,SRCS3,OBJS3,DEPLIBS3,locallib,syslib)
+#endif /* ComplexCplusplusProgramTarget_3 */
+
+/*
+ * ComplexProgramTarget_4 - generate rules for compiling and linking the
+ * program specified by $(OBJS4) and $(SRCS4) and installing the program and
+ * man page.  It should be used to build the third program in Imakefiles 
+ * describing more than one program.
+ */
+#ifndef ComplexProgramTarget_4
+#define        ComplexProgramTarget_4(program,locallib,syslib)                 @@\
+ProgramTargetHelper(program,SRCS4,OBJS4,DEPLIBS4,locallib,syslib)
+#endif /* ComplexProgramTarget_4 */
+
+#ifndef ComplexCplusplusProgramTarget_4
+#define        ComplexCplusplusProgramTarget_4(program,locallib,syslib)        @@\
+CplusplusProgramTargetHelper(program,SRCS4,OBJS4,DEPLIBS4,locallib,syslib)
+#endif /* ComplexCplusplusProgramTarget_4 */
+
+/*
+ * ComplexProgramTarget_5 - generate rules for compiling and linking the
+ * program specified by $(OBJS5) and $(SRCS5) and installing the program and
+ * man page.  It should be used to build the third program in Imakefiles 
+ * describing more than one program.
+ */
+#ifndef ComplexProgramTarget_5
+#define        ComplexProgramTarget_5(program,locallib,syslib)                 @@\
+ProgramTargetHelper(program,SRCS5,OBJS5,DEPLIBS5,locallib,syslib)
+#endif /* ComplexProgramTarget_5 */
+
+#ifndef ComplexCplusplusProgramTarget_5
+#define        ComplexCplusplusProgramTarget_5(program,locallib,syslib)        @@\
+CplusplusProgramTargetHelper(program,SRCS5,OBJS5,DEPLIBS5,locallib,syslib)
+#endif /* ComplexCplusplusProgramTarget_5 */
+
+/*
+ * ComplexProgramTarget_6 - generate rules for compiling and linking the
+ * program specified by $(OBJS6) and $(SRCS6) and installing the program and
+ * man page.  It should be used to build the third program in Imakefiles 
+ * describing more than one program.
+ */
+#ifndef ComplexProgramTarget_6
+#define        ComplexProgramTarget_6(program,locallib,syslib)                 @@\
+ProgramTargetHelper(program,SRCS6,OBJS6,DEPLIBS6,locallib,syslib)
+#endif /* ComplexProgramTarget_6 */
+
+#ifndef ComplexCplusplusProgramTarget_6
+#define        ComplexCplusplusProgramTarget_6(program,locallib,syslib)        @@\
+CplusplusProgramTargetHelper(program,SRCS6,OBJS6,DEPLIBS6,locallib,syslib)
+#endif /* ComplexCplusplusProgramTarget_6 */
+
+/*
+ * ComplexProgramTarget_7 - generate rules for compiling and linking the
+ * program specified by $(OBJS7) and $(SRCS7) and installing the program and
+ * man page.  It should be used to build the third program in Imakefiles 
+ * describing more than one program.
+ */
+#ifndef ComplexProgramTarget_7
+#define        ComplexProgramTarget_7(program,locallib,syslib)                 @@\
+ProgramTargetHelper(program,SRCS7,OBJS7,DEPLIBS7,locallib,syslib)
+#endif /* ComplexProgramTarget_7 */
+
+#ifndef ComplexCplusplusProgramTarget_7
+#define        ComplexCplusplusProgramTarget_7(program,locallib,syslib)        @@\
+CplusplusProgramTargetHelper(program,SRCS7,OBJS7,DEPLIBS7,locallib,syslib)
+#endif /* ComplexCplusplusProgramTarget_7 */
+
+/*
+ * ComplexProgramTarget_8 - generate rules for compiling and linking the
+ * program specified by $(OBJS8) and $(SRCS8) and installing the program and
+ * man page.  It should be used to build the third program in Imakefiles 
+ * describing more than one program.
+ */
+#ifndef ComplexProgramTarget_8
+#define        ComplexProgramTarget_8(program,locallib,syslib)                 @@\
+ProgramTargetHelper(program,SRCS8,OBJS8,DEPLIBS8,locallib,syslib)
+#endif /* ComplexProgramTarget_8 */
+
+#ifndef ComplexCplusplusProgramTarget_8
+#define        ComplexCplusplusProgramTarget_8(program,locallib,syslib)        @@\
+CplusplusProgramTargetHelper(program,SRCS8,OBJS8,DEPLIBS8,locallib,syslib)
+#endif /* ComplexCplusplusProgramTarget_8 */
+
+/*
+ * ComplexProgramTarget_9 - generate rules for compiling and linking the
+ * program specified by $(OBJS9) and $(SRCS9) and installing the program and
+ * man page.  It should be used to build the third program in Imakefiles 
+ * describing more than one program.
+ */
+#ifndef ComplexProgramTarget_9
+#define        ComplexProgramTarget_9(program,locallib,syslib)                 @@\
+ProgramTargetHelper(program,SRCS9,OBJS9,DEPLIBS9,locallib,syslib)
+#endif /* ComplexProgramTarget_9 */
+
+#ifndef ComplexCplusplusProgramTarget_9
+#define        ComplexCplusplusProgramTarget_9(program,locallib,syslib)        @@\
+CplusplusProgramTargetHelper(program,SRCS9,OBJS9,DEPLIBS9,locallib,syslib)
+#endif /* ComplexCplusplusProgramTarget_9 */
+
+/*
+ * ComplexProgramTarget_10 - generate rules for compiling and linking the
+ * program specified by $(OBJS10) and $(SRCS10) and installing the program and
+ * man page.  It should be used to build the third program in Imakefiles 
+ * describing more than one program.
+ */
+#ifndef ComplexProgramTarget_10
+#define        ComplexProgramTarget_10(program,locallib,syslib)                @@\
+ProgramTargetHelper(program,SRCS10,OBJS10,DEPLIBS10,locallib,syslib)
+#endif /* ComplexProgramTarget_10 */
+
+#ifndef ComplexCplusplusProgramTarget_10
+#define        ComplexCplusplusProgramTarget_10(program,locallib,syslib)       @@\
+CplusplusProgramTargetHelper(program,SRCS10,OBJS10,DEPLIBS10,locallib,syslib)
+#endif /* ComplexCplusplusProgramTarget_10 */
+
+#ifndef MoveToBakFile
+#define MoveToBakFile(file) -@if [ -f file ]; then set -x; \           @@\
+       $(MV) file file.bak; else exit 0; fi
+#endif /* MoveToBakFile */
+
+#ifndef RMoveToBakFile
+#define RMoveToBakFile(file) -@if [ -f file ]; then set -x; \          @@\
+       RemoveFile(file.bak); $(MV) file file.bak; \                    @@\
+       else exit 0; fi
+#endif /* RMoveToBakFile */
+
+/*
+ * ServerTargetWithFlags - generate rules to compile, link, and relink a server
+ */
+#ifndef ServerTargetWithFlags
+#define        ServerTargetWithFlags(server,subdirs,objects,libs,syslibs,flags) @@\
+AllTarget(ProgramTargetName(server))                                   @@\
+ProgramTargetName(server): subdirs objects libs                                @@\
+       MoveToBakFile($@)                                               @@\
+       LinkRule($@,$(LDOPTIONS),objects,libs $(LDLIBS) syslibs) @@\
+                                                                       @@\
+Concat(load,server):                                                   @@\
+       MoveToBakFile(ProgramTargetName(server))                        @@\
+       LinkRule(ProgramTargetName(server),$(LDOPTIONS),objects,libs $(LDLIBS) syslibs) @@\
+                                                                       @@\
+loadX:: Concat(load,server)                                            @@\
+                                                                       @@\
+SentinelProgramTarget(server,subdirs objects libs,objects libs $(LDLIBS) syslibs) @@\
+SentinelLinkTarget(Concat(load,server),server,objects libs $(LDLIBS) syslibs) @@\
+PurifyProgramTarget(server,subdirs objects libs,objects libs $(LDLIBS) syslibs) @@\
+PurifyLinkTarget(Concat(load,server),server,objects libs $(LDLIBS) syslibs) @@\
+ProofProgramTarget(server,subdirs objects libs,objects libs $(LDLIBS) syslibs) @@\
+ProofLinkTarget(Concat(load,server),server,objects libs $(LDLIBS) syslibs) @@\
+                                                                       @@\
+InstallProgramWithFlags(server,$(BINDIR),flags)                                @@\
+                                                                       @@\
+clean::                                                                        @@\
+       RemoveFile(ProgramTargetName(server))
+#endif /* ServerTargetWithFlags */
+
+/*
+ * ServerTarget - rules to compile, link, and relink a normal server
+ */
+#ifndef ServerTarget
+#define        ServerTarget(server,subdirs,objects,libs,syslibs)               @@\
+ServerTargetWithFlags(server,subdirs,objects,libs,syslibs,$(_NOOP_))
+#endif /* ServerTarget */
+
+#if DoRanlibCmd
+#define RanLibrary(args) $(RANLIB) args
+#else
+#define RanLibrary(args) $(_NULLCMD_)
+#endif
+
+#ifndef LibraryTargetName
+#define LibraryTargetName(libname)Concat(lib,libname.a)
+#endif
+
+#ifndef LibraryTargetNameSuffix
+#define LibraryTargetNameSuffix(libname,suffix)Concat3(lib,libname,suffix.a)
+#endif
+
+#ifndef InstallNamedTarget
+#define InstallNamedTarget(step,srcname,flags,dest,dstname)            @@\
+step:: srcname                                                         @@\
+       MakeDir($(DESTDIR)dest)                                         @@\
+       $(INSTALL) $(INSTALLFLAGS) flags srcname $(DESTDIR)dest/dstname
+#endif /* InstallNamedTarget */
+
+/*
+ * InstallNamedTargetNoClobber - Like InstallNamedTarget, but doesn't
+ * do the install if an installed version already exists.  Useful
+ * for files that might have local customizations that you don't
+ * want to clobber.  Config files are good candidates for this.
+ */
+#ifndef InstallNamedTargetNoClobber
+#define InstallNamedTargetNoClobber(step,srcname,flags,dest,dstname)   @@\
+step:: srcname                                                         @@\
+       MakeDir($(DESTDIR)dest)                                         @@\
+       @if [ -f $(DESTDIR)dest/dstname ]; then \                       @@\
+        echo "Not overwriting existing" $(DESTDIR)dest/dstname; \      @@\
+       else set -x; \                                                  @@\
+        $(INSTALL) $(INSTALLFLAGS) flags srcname $(DESTDIR)dest/dstname; fi
+#endif /* InstallNamedTargetNoClobber */
+
+#ifndef InstallTarget
+#define InstallTarget(step,file,flags,dest)                            @@\
+InstallNamedTarget(step,file,flags,dest,file)
+#endif /* InstallTarget */
+
+/*
+ * InstallLibrary - generate rules to install the indicated library.
+ */
+#ifndef InstallLibrary
+#define        InstallLibrary(libname,dest)                                    @@\
+install:: LibraryTargetName(libname)                                   @@\
+       MakeDir($(DESTDIR)dest)                                         @@\
+       $(INSTALL) $(INSTALLFLAGS) $(INSTLIBFLAGS) LibraryTargetName(libname) $(DESTDIR)dest @@\
+       RanLibrary($(RANLIBINSTFLAGS) $(DESTDIR)dest/LibraryTargetName(libname))
+#endif /* InstallLibrary */
+
+
+/*
+ * InstallLinkKitLibrary - rule to install Link Kit library.
+ *                         (only used for XFree86). This is a no-op
+ *                         rule so that Imakefiles on non-XFree86 systems
+ *                         continue to build Makefiles correctly.
+ */
+#ifndef InstallLinkKitLibrary
+#define InstallLinkKitLibrary(lib,dir)
+#endif
+
+
+/*
+ * InstallLinkKitNamedLibrary - rule to install Link Kit library.
+ *                         (only used for XFree86). This is a no-op
+ *                         rule so that Imakefiles on non-XFree86 systems
+ *                         continue to build Makefiles correctly.
+ */
+#ifndef InstallLinkKitNamedLibrary
+#define InstallLinkKitNamedLibrary(lib,dlib,dir)
+#endif
+
+
+/*
+ * MergeIntoInstalledLibrary - generate rules to merge one library into another
+ */
+#ifndef MergeIntoInstalledLibrary
+#define MergeIntoInstalledLibrary(tolib,fromlib)                       @@\
+install::  fromlib                                                     @@\
+       $(SCRIPTSRC)/mergelib $(DESTDIR)tolib fromlib
+#endif /* MergeIntoInstalledLibrary */
+
+/*
+ * InstallLibraryAlias - generate rules to create a link from one library name
+ * to another for the purposes of aliasing.
+ */
+#ifndef InstallLibraryAlias
+#define        InstallLibraryAlias(libname,alias,dest)                         @@\
+install::                                                              @@\
+       -(cd $(DESTDIR)dest && ( \                                      @@\
+               RemoveFile(LibraryTargetName(alias)); \                 @@\
+               $(LN) LibraryTargetName(libname) LibraryTargetName(alias)))
+#endif /* InstallLibraryAlias */
+
+
+/*
+ * InstallLintLibrary - generate rules to install the indicated lint library.
+ */
+#ifndef InstallLintLibrary
+#define        InstallLintLibrary(libname,dest)                                @@\
+InstallTarget(install.ln,Concat(llib-l,libname.ln),$(INSTLIBFLAGS),dest)
+#endif /* InstallLintLibrary */
+
+
+/*
+ * InstallManPageLong - generate rules to install the indicated manual page,
+ * giving it an alternate name.  This is used for installing man pages whose
+ * base name without the .man suffix would normally be longer than 8 characters
+ * (the limit for using source code control systems on files systems with 
+ * short file names).
+ */
+#ifndef InstallManPageLong
+#define        InstallManPageLong(file,destdir,dest)                           @@\
+InstallNamedTarget(install.man,file.man,$(INSTMANFLAGS),destdir,dest.$(MANSUFFIX))
+#endif /* InstallManPageLong */
+
+
+/*
+ * InstallManPage - generate rules to install the indicated manual page.
+ */
+#ifndef InstallManPage
+#define        InstallManPage(file,destdir)                                    @@\
+InstallManPageLong(file,destdir,file)
+#endif /* InstallManPage */
+
+
+/*
+ * InstallManPageAliases - generate rules to install manual page aliases.
+ */
+#ifndef InstallManPageAliases
+#define        InstallManPageAliases(file,destdir,aliases)                     @@\
+install.man::                                                          @@\
+       @(TMP=/tmp/tmp.$$$$; \                                          @@\
+       RemoveFile($${TMP}); \                                          @@\
+       echo .so `basename destdir`/file.$(MANSUFFIX) > $${TMP}; \      @@\
+       for i in aliases; do (set -x; \                                 @@\
+       $(INSTALL) $(INSTALLFLAGS) $(INSTMANFLAGS) $${TMP} $(DESTDIR)destdir/$$i.$(MANSUFFIX)); \ @@\
+       done; \                                                         @@\
+       RemoveFile($${TMP}))
+#endif /* InstallManPageAliases */
+
+
+/*
+ * InstallGenManPageLong - More general rules for installing manual pages --
+ * doesn't assume MANSUFFIX.
+ */
+#ifndef InstallGenManPageLong
+#define        InstallGenManPageLong(file,destdir,dest,suffix)                 @@\
+install.man:: file.man                                                 @@\
+       MakeDir($(DESTDIR)destdir)                                      @@\
+       $(INSTALL) -c $(INSTMANFLAGS) file.man $(DESTDIR)destdir/dest.suffix
+#endif /* InstallGenManPageLong */
+
+
+/*
+ * InstallGenManPage - general equivalent of InstallManPage
+ */
+#ifndef InstallGenManPage
+#define        InstallGenManPage(file,destdir,suffix)                          @@\
+InstallGenManPageLong(file,destdir,file,suffix)
+#endif /* InstallGenManPage */
+
+
+/*
+ * InstallGenManPageAliases - general equivalent of InstallManPageAliases
+ */
+#ifndef InstallGenManPageAliases
+#define        InstallGenManPageAliases(file,destdir,suffix,aliases)           @@\
+install.man::                                                          @@\
+       @(TMP=/tmp/tmp.$$$$; \                                          @@\
+       RemoveFile($${TMP}); \                                          @@\
+       echo .so `basename destdir`/file.suffix > $${TMP}; \            @@\
+       for i in aliases; do (set -x; \                                 @@\
+       $(INSTALL) $(INSTALLFLAGS) $(INSTMANFLAGS) $${TMP} $(DESTDIR)destdir/$$i.suffix); \ @@\
+       done; \                                                         @@\
+       RemoveFile($${TMP}))
+#endif /* InstallGenManPageAliases */
+
+/*
+ * ManKeywordsTarget - generate the database used by "man -k".
+ * This rule updates the index in the directory "manpath", which
+ * indexes all the manual pages in the section subdirectories under
+ * it.  An update command is defined only on systems that have a
+ * per MANPATH element index.  If the OS supports only one system-wide
+ * database, we don't update it, because then we can't do cross
+ * installations or use a non-empty DESTDIR for testing.
+ */
+#ifndef ManKeywordsTarget
+#define ManKeywordsTarget(manpath) man_keywords::
+#endif
+
+/*
+ * InstallNamedNonExec - generate rules to install a data file
+ */
+#ifndef InstallNamedNonExec
+#define        InstallNamedNonExec(srcname,dstname,dest)                       @@\
+InstallNamedTarget(install,srcname,$(INSTDATFLAGS),dest,dstname)
+#endif /* InstallNamedNonExec */
+
+
+/*
+ * InstallLinkKitNamedNonExec - rule for installing server Link Kit files.
+ *                         (only used for XFree86). This is a no-op
+ *                         rule so that Imakefiles on non-XFree86 systems
+ *                         continue to build Makefiles correctly.
+ */
+#ifndef InstallLinkKitNamedNonExec
+#define InstallLinkKitNamedNonExec(srcname,dstname,dest)
+#endif
+
+
+/*
+ * InstallNonExecFile - generate rules to install a data file
+ */
+#ifndef InstallNonExecFile
+#define InstallNonExecFile(file,dest)                                  @@\
+InstallTarget(install,file,$(INSTDATFLAGS),dest)
+#endif /* InstallNonExecFile */
+
+
+/*
+ * InstallNonExecFileNoClobber - install a data file once
+ */
+#ifndef InstallNonExecFileNoClobber
+#define InstallNonExecFileNoClobber(file,dest)                         @@\
+InstallNamedTargetNoClobber(install,file,$(INSTDATFLAGS),dest,file)
+#endif /* InstallNonExecFileNoClobber */
+
+
+/*
+ * InstallLinkKitNonExecFile - rule for installing server Link Kit files.
+ *                         (only used for XFree86). This is a no-op
+ *                         rule so that Imakefiles on non-XFree86 systems
+ *                         continue to build Makefiles correctly.
+ */
+#ifndef InstallLinkKitNonExecFile
+#define InstallLinkKitNonExecFile(file,dir)
+#endif
+
+
+/*
+ * InstallNonExec - generate rules to install a data file, but does not
+ * try to create the destination directory (deprecated)
+ */
+#ifndef InstallNonExec
+#define        InstallNonExec(file,dest)                                       @@\
+install:: file                                                         @@\
+       $(INSTALL) $(INSTALLFLAGS) $(INSTDATFLAGS) file $(DESTDIR)dest
+#endif /* InstallNonExec */
+
+
+/*
+ * InstallProgramWithFlags - generate rules to install an executable program
+ * using given install flags.
+ */
+#ifndef InstallProgramWithFlags
+#define InstallProgramWithFlags(program,dest,flags)                    @@\
+InstallTarget(install,ProgramTargetName(program),$(INSTPGMFLAGS) flags,dest)
+#endif /* InstallProgramWithFlags */
+
+
+/*
+ * InstallProgram - generate rules to install an executable program using any
+ * special install flags set in $(INSTALLFLAGS).
+ */
+#ifndef InstallProgram
+#define        InstallProgram(program,dest)                                    @@\
+InstallProgramWithFlags(program,dest,NullParameter)
+#endif /* InstallProgram */
+
+
+
+/*
+ * InstallScript - install a shell script.
+ */
+#ifndef InstallScript
+#define        InstallScript(program,dest)                                     @@\
+InstallNamedTarget(install,program.script,$(INSTBINFLAGS),dest,program)
+#endif /* InstallScript */
+
+
+/*
+ * InstallNamedProg - install a program with renaming and no stripping.
+ */
+#ifndef InstallNamedProg
+#define InstallNamedProg(srcname,dstname,dest)                         @@\
+InstallNamedTarget(install,srcname,$(INSTBINFLAGS),dest,dstname)
+#endif /* InstallNamedProg */
+
+
+/*
+ * InstallNamedProgNoClobber - Like InstallNamedProg, but doesn't
+ * do the install if an installed version already exists.
+ */
+#ifndef InstallNamedProgNoClobber
+#define InstallNamedProgNoClobber(srcname,dstname,dest)                        @@\
+InstallNamedTargetNoClobber(install,srcname,$(INSTBINFLAGS),dest,dstname)
+#endif /* InstallNamedProgNoClobber */
+
+
+/*
+ * InstallLinkKitNamedProg - rule for installing server Link Kit files.
+ *                         (only used for XFree86). This is a no-op
+ *                         rule so that Imakefiles on non-XFree86 systems
+ *                         continue to build Makefiles correctly.
+ */
+#ifndef InstallLinkKitNamedProg
+#define InstallLinkKitNamedProg(srcname,dstname,dest)
+#endif
+
+
+/*
+ * MakeFlagsToShellFlags - set variables before starting a loop.
+ * makeflags is the set of "make" flags to check.
+ * shellcmd is the shell command to execute if any of the flags are set.
+ *
+ * The usual use of this rule is to translate make's "don't quit on error"
+ * flags into the equivalent for the shell.  To do this, "make -i" always
+ * becomes "set +e".  "make -k" should also turn on "set +e" if the target
+ * is building subdirectories.  That is, subdirectories are independent
+ * and should appear to be multiple targets, even though they are
+ * implemented in a loop in a single target.
+ */
+#ifndef MakeFlagsToShellFlags
+#define MakeFlagsToShellFlags(makeflags,shellcmd)\
+       for flag in ${MAKEFLAGS} ''; do \                               @@\
+         case "$$flag" in *=*) ;; *[makeflags]*) shellcmd;; esac; done
+#endif
+
+/*
+ * MakeNamedTargetSubdir - do make in a subdir.
+ */
+#ifndef MakeNamedTargetSubdir
+#define MakeNamedTargetSubdir(dir,flags,subname)\
+               (cd dir && $(MAKE) $(MFLAGS) $(PARALLELMFLAGS) \        @@\
+                       flags subname)
+#endif
+
+/*
+ * LinkFileList - link a list of files from one place to another
+ */
+#ifndef LinkFileList
+#define LinkFileList(step,list,dir,sub)                                        @@\
+step:: list                                                            @@\
+       @MakeFlagsToShellFlags(i,set +e); \                             @@\
+       echo "  cd" dir; cd dir && \                                    @@\
+       for i in list; do (set -x; RemoveFile($$i); $(LN) sub/$$i .); done
+#endif
+
+
+/*
+ * LinkVarDirectory
+ *
+ * Make links from $LIBDIR (<ProjectRoot>/lib/X11) to /var/X11/
+ * For example /usr/X11R6/lib/X11/xdm ==> /var/X11/xdm so that X can be
+ * run from a read-only volume like a CD-ROM.
+ */
+#ifndef LinkVarDirectory
+#if HasVarDirectory && HasSymLinks
+#define LinkVarDirectory(mdir,cdir,rdir,ldir)                          @@\
+install::                                                              @@\
+       MakeDir(Concat($(DESTDIR)$(LIBDIR)/,cdir))                      @@\
+       MakeDir(Concat($(VARDIR)/,mdir))                                @@\
+       @MakeFlagsToShellFlags(i,set +e); \                             @@\
+       if [ -d Concat($(DESTDIR)$(LIBDIR)/,cdir) ]; then \             @@\
+         cd Concat($(DESTDIR)$(LIBDIR)/,cdir); \                       @@\
+         if [ -d rdir -a ! -h rdir ]; then \                           @@\
+           (cd rdir; tar cf - . | (cd Concat($(VARDIR)/,mdir); tar xf -; exit 0); exit 0); \ @@\
+         fi; \                                                         @@\
+         $(RM) -r rdir; \                                              @@\
+         $(LN) Concat($(VARDIR)/,mdir) ldir; \                         @@\
+       fi
+#else
+#define LinkVarDirectory(mdir,cdir,rdir,ldir)
+#endif
+#endif
+
+
+/*
+ * InstallMultipleDestFlags - generate rules to install multiple files at
+ * once during a particular step in the build using a specific set of install 
+ * flags.
+ */
+#ifndef InstallMultipleDestFlags
+#define InstallMultipleDestFlags(step,list,dest,flags)                 @@\
+step:: list                                                            @@\
+       MakeDir($(DESTDIR)dest)                                         @@\
+       @MakeFlagsToShellFlags(i,set +e); \                             @@\
+       for i in list; do \                                             @@\
+               (set -x; $(INSTALL) $(INSTALLFLAGS) flags $$i $(DESTDIR)dest); \        @@\
+       done
+#endif /* InstallMultipleDestFlags */
+
+
+/*
+ * InstallLinkKitMultipleDestFlags - rule for installing server Link Kit files.
+ *                         (only used for XFree86). This is a no-op
+ *                         rule so that Imakefiles on non-XFree86 systems
+ *                         continue to build Makefiles correctly.
+ */
+#ifndef InstallLinkKitMultipleDestFlags
+#define InstallLinkKitMultipleDestFlags(list,dest,flags)
+#endif
+
+
+/*
+ * InstallMultipleDest - generate rules to install multiple files at once
+ * during a particular step in the build using any install flags set in 
+ * $(INSTDATFLAGS).
+ */
+#ifndef InstallMultipleDest
+#define InstallMultipleDest(step,list,dest)                            @@\
+InstallMultipleDestFlags(step,list,dest,$(INSTDATFLAGS))
+#endif /* InstallMultipleDest */
+
+/*
+ * InstallMultiple - generate rules to install multiple files at once 
+ * during the install step of the build using any install flags set in 
+ * $(INSTALLFLAGS).
+ */
+#ifndef InstallMultiple
+#define        InstallMultiple(list,dest)                                      @@\
+InstallMultipleDest(install,list,dest)
+#endif /* InstallMultiple */
+
+
+/*
+ * InstallMultipleFlags - generate rules to install multiple files at once
+ * during the install step of the build using the given install flags.
+ */
+#ifndef InstallMultipleFlags
+#define InstallMultipleFlags(list,dest,flags)                          @@\
+InstallMultipleDestFlags(install,list,dest,flags)
+#endif /* InstallMultipleFlags */
+
+
+/*
+ * InstallMultipleMan - generate rules to install a variety of manual pages
+ * during the install.man step of the build.
+ */
+#ifndef InstallMultipleMan
+#define InstallMultipleMan(list,dest)                                  @@\
+InstallMultipleDestFlags(install.man,list,dest,$(INSTMANFLAGS))
+#endif /* InstallMultipleMan */
+
+/*
+ * IncludeMakefile - rule to include another Makefile.
+ * Must not generate an error or even a warning if the named file
+ * is not present, since we use this to include Makefile.dep, which
+ * may not be built yet.
+ * This is defined non-null iff HasMakefileSafeInclude is YES.
+ * The double-@ is to ensure no leading spaces on the line.
+ */
+#ifndef IncludeMakefile
+#if HasClearmake
+#define IncludeMakefile(file) @@sinclude file
+#else
+#if HasBsdMake
+#define IncludeMakefile(file) @@# dependencies are in .depend
+#else
+#define IncludeMakefile(file) /**/
+#endif
+#endif
+#endif
+
+/*
+ * DependDependencyStatement - Used by DependDependency to set up the
+ * most specific dependency, which differs based on whether we support
+ * a separate Makefile.dep on this platform.
+ */
+#ifndef DependDependencyStatement
+#if HasMakefileSafeInclude
+#define DependDependencyStatement()                                    @@\
+DependFileName:: ProgramTargetName($(DEPEND))
+#else
+#define DependDependencyStatement()                                    @@\
+depend:: ProgramTargetName($(DEPEND))
+#endif
+#endif
+
+/*
+ * DependDependency - generate rules to build the makedepend program if 
+ * this Imakefile is within the source tree.
+ */
+#ifndef DependDependency
+#ifdef UseInstalled
+#define DependDependency() /**/
+#else
+#define DependDependency()                                             @@\
+DependDependencyStatement()                                            @@\
+                                                                       @@\
+NoCmpScript(ProgramTargetName($(DEPEND)))                              @@\
+                                                                       @@\
+ProgramTargetName($(DEPEND)):                                          @@\
+       @echo "checking $@ over in $(DEPENDSRC) first..."; \            @@\
+       cd $(DEPENDSRC) && $(MAKE); \                                   @@\
+       echo "okay, continuing in $(CURRENT_DIR)"
+
+#endif /* UseInstalled */
+#endif /* DependDependency */
+
+
+/*
+ * DependTarget - generate rules to compute dependencies for all files listed
+ * in $(SRCS).
+ */
+#ifndef DependTarget
+#if HasMakefileSafeInclude
+#define DependTarget()                                                 @@\
+DependDependency()                                                     @@\
+                                                                       @@\
+depend:: DependFileName                                                        @@\
+                                                                       @@\
+DependFileName::                                                       @@\
+       RemoveFile($@)                                                  @@\
+       RunProgram(DEPEND,-f- $(DEPENDFLAGS) -- $(ALLDEFINES) $(DEPEND_DEFINES) -- $(SRCS)) > $@
+#else /* HasMakefileSafeInclude */
+#define        DependTarget()                                                  @@\
+DependDependency()                                                     @@\
+                                                                       @@\
+depend::                                                               @@\
+       RunProgram(DEPEND,$(DEPENDFLAGS) -- $(ALLDEFINES) $(DEPEND_DEFINES) -- $(SRCS))
+#endif /* HasMakefileSafeInclude else */
+#endif /* DependTarget */
+
+/*
+ * DependTarget3 - generate rules to compute dependencies for all files given.
+ */
+#ifndef DependTarget3
+#if HasMakefileSafeInclude
+#define DependTarget3(srcs1,srcs2,srcs3)                               @@\
+DependDependency()                                                     @@\
+                                                                       @@\
+depend:: DependFileName                                                        @@\
+                                                                       @@\
+DependFileName::                                                       @@\
+       RemoveFile($@)                                                  @@\
+       RunProgram(DEPEND,-f- $(DEPENDFLAGS) -- $(ALLDEFINES) $(DEPEND_DEFINES) -- srcs1) > $@  @@\
+       RunProgram(DEPEND,-f- $(DEPENDFLAGS) -- $(ALLDEFINES) $(DEPEND_DEFINES) -- srcs2) >> $@ @@\
+       RunProgram(DEPEND,-f- $(DEPENDFLAGS) -- $(ALLDEFINES) $(DEPEND_DEFINES) -- srcs3) >> $@
+#else /* HasMakefileSafeInclude */
+#define        DependTarget3(srcs1,srcs2,srcs3)                                @@\
+DependDependency()                                                     @@\
+                                                                       @@\
+depend::                                                               @@\
+       RunProgram(DEPEND,$(DEPENDFLAGS) -- $(ALLDEFINES) $(DEPEND_DEFINES) -- srcs1)   @@\
+       RunProgram(DEPEND,-a $(DEPENDFLAGS) -- $(ALLDEFINES) $(DEPEND_DEFINES) -- srcs2)        @@\
+       RunProgram(DEPEND,-a $(DEPENDFLAGS) -- $(ALLDEFINES) $(DEPEND_DEFINES) -- srcs3)
+#endif /* HasMakefileSafeInclude else */
+#endif /* DependTarget3 */
+
+
+/*
+ * CleanTarget - generate rules to remove any garbage files
+ */
+#ifndef CleanTarget
+#define        CleanTarget()                                                   @@\
+clean::                                                                        @@\
+       $(RM) FilesToClean ExtraFilesToClean "#"*                       @@\
+                                                                       @@\
+ProofCleanTarget()
+#endif /* CleanTarget */
+
+
+/*
+ * TagsTarget - generate rules to compute tags files for C source code.
+ */
+#ifndef TagsTarget
+#define        TagsTarget()                                                    @@\
+tags::                                                                 @@\
+       $(TAGS) -w *.[ch]                                               @@\
+       $(TAGS) -xw *.[ch] > TAGS
+#endif /* TagsTarget */
+
+
+/*
+ * ImakeDependency - generate rules to compile imake if this Imakefile is
+ * within the source tree.
+ */
+#ifndef ImakeDependency
+#ifdef UseInstalled
+#define ImakeDependency(target) /**/
+#else
+#define ImakeDependency(target)                                                @@\
+target:: ProgramTargetName($(IMAKE))                                   @@\
+                                                                       @@\
+NoCmpScript(ProgramTargetName($(IMAKE)) $(IMAKE).Osuf)                 @@\
+                                                                       @@\
+ProgramTargetName($(IMAKE)) $(IMAKE).Osuf:                             @@\
+       -@(cd $(IMAKESRC) && if [ -f Makefile ]; then \                 @@\
+       echo "checking $@ in $(IMAKESRC) first..."; $(MAKE) all; else \ @@\
+       echo "bootstrapping $@ from Makefile.ini in $(IMAKESRC) first..."; \    @@\
+       $(MAKE) -f Makefile.ini BOOTSTRAPCFLAGS="$(BOOTSTRAPCFLAGS)"; fi; \     @@\
+       echo "okay, continuing in $(CURRENT_DIR)")
+#endif /* UseInstalled */
+#endif /* ImakeDependency */
+
+
+/*
+ * BuildMakefileTarget - generate rules to build a Makefile from an Imakefile
+ * and any special imake flags.  This is generally done automatically by the
+ * template or by any special Imakefiles.  The first argument exists just
+ * because imakeflags is usually empty and some preprocessors will complain
+ * if an empty argument is passed as the sole argument to a macro.
+ */
+#ifndef BuildMakefileTarget
+#define        BuildMakefileTarget(notused,imakeflags)                         @@\
+ImakeDependency(Makefile)                                              @@\
+                                                                       @@\
+Makefile::                                                             @@\
+       RMoveToBakFile(Makefile)                                        @@\
+       $(IMAKE_CMD) -DTOPDIR=$(TOP) -DCURDIR=$(CURRENT_DIR) imakeflags
+
+#endif /* BuildMakefileTarget */
+
+
+/*
+ * MakefileTarget - generate rules to build a normal Makefile.
+ */
+#ifndef MakefileTarget
+#define MakefileTarget()                                               @@\
+BuildMakefileTarget(Imakefile,NullParameter)
+#endif /* MakefileTarget */
+
+
+/*
+ * LibMkdir - helper for creating library object subdirectories
+ */
+#ifndef LibMkdir
+#define LibMkdir(dir) DirFailPrefix@if [ -d dir ]; then exit 0; else set -x; mkdir dir; fi
+#endif
+
+#ifndef LibMkdirLinkSubdirs
+#define LibMkdirLinkSubdirs(dir) DirFailPrefix@if [ -d dir ]; then \   @@\
+           exit 0; \                                                   @@\
+       else \                                                          @@\
+           echo "mkdir dir"; mkdir dir; \                              @@\
+           for i in $(SUBDIRS); do \                                   @@\
+             j=`echo "$$i" | sed -e 's;[^/]\{1,\};..;g'`; \            @@\
+             $(MKDIRHIER) "dir/`dirname $$i`"; \                       @@\
+             echo $(LN) "$$j/$$i/dir" "dir/$$i"; \                     @@\
+             $(LN) "$$j/$$i/dir" "dir/$$i"; \                          @@\
+           done; \                                                     @@\
+       fi
+#endif
+
+/*
+ * LibCleanDir - helper for cleaning library object subdirectories
+ */
+#ifndef LibCleanDir
+#define LibCleanDir(dir) -@if [ -d dir ]; then \                       @@\
+               set -x; $(RM) -r dir; else exit 0; fi
+#endif
+
+/*
+ * LintLibReferences - variables for lint libraries
+ */
+#ifndef LintLibReferences
+#define LintLibReferences(varname,libname,libsource)                   @@\
+Concat(LINT,varname) = _UseCat($(LINTLIBDIR)/llib-l,libsource/llib-,libname.ln)
+#endif
+
+
+/*
+ * UnsharedLibReferences - variables for unshared libraries
+ */
+#ifndef UnsharedLibReferences
+#define UnsharedLibReferences(varname,libname,libsource)               @@\
+ProjectUnsharedLibReferences(varname,libname,libsource,$(BUILDLIBDIR))
+#endif
+
+/*
+ * ProjectUnsharedLibReferences - variables for unshared libraries
+ */
+#ifndef ProjectUnsharedLibReferences
+#define ProjectUnsharedLibReferences(varname,libname,libsource,buildlibdir)    @@\
+Concat3(DEP,varname,LIB) = _UseCat($(USRLIBDIR)/,buildlibdir/,LibraryTargetName(libname))      @@\
+Concat(varname,LIB) = LoaderLibPrefix Concat(-l,libname)               @@\
+LintLibReferences(varname,libname,libsource)
+#endif
+
+/*
+ * SharedLibDependencies - shared library dependencies
+ */
+#ifndef SharedLibDependencies
+#define SharedLibDependencies(libname,libsource,revname) /**/
+#endif
+
+/*
+ * SharedDSLibDependencies - shared library dependencies with data separation
+ */
+#ifndef SharedDSLibDependencies
+#define SharedDSLibDependencies(libname,libsource,revname) /**/
+#endif
+
+/*
+ * SharedLibReferences - variables for shared libraries
+ */
+#ifndef SharedLibReferences
+#define SharedLibReferences(varname,libname,libsource,revname,rev)     @@\
+revname = rev                                                          @@\
+Concat3(DEP,varname,LIB) = SharedLibDependencies(libname,libsource,revname) @@\
+Concat(varname,LIB) = LoaderLibPrefix Concat(-l,libname)               @@\
+LintLibReferences(varname,libname,libsource)
+#endif
+
+/*
+ * SharedDSLibReferences - variables for shared libraries with data separation
+ */
+#ifndef SharedDSLibReferences
+#define SharedDSLibReferences(varname,libname,libsource,revname,rev)   @@\
+revname = rev                                                          @@\
+Concat3(DEP,varname,LIB) = SharedDSLibDependencies(libname,libsource,revname) @@\
+Concat(varname,LIB) = LoaderLibPrefix Concat(-l,libname)               @@\
+LintLibReferences(varname,libname,libsource)
+#endif
+
+/*
+ * CPPOnlyCompile - run C compiler's preprocessor only
+ */
+#ifndef CPPOnlyCompile
+#define CPPOnlyCompile(src,options) RemoveFile($@)                     @@\
+       ClearmakeOSName \
+       $(CC) -E $(CFLAGS) options src > $@
+#endif
+
+/*
+ * ObjectCompile - compile fragment for a normal object file
+ */
+#ifndef ObjectCompile
+#define ObjectCompile(options) RemoveFile($@)                          @@\
+       ClearmakeOSName \
+       $(CC) -c $(CFLAGS) options $*.c
+#endif
+
+#ifndef ObjectCplusplusCompile
+#define ObjectCplusplusCompile(options) RemoveFile($@)                 @@\
+       ClearmakeOSName \
+       $(CXX) -c $(CXXFLAGS) options $*.CCsuf
+#endif
+
+/*
+ * NormalLibObjCompile - compile fragment for a normal library object file
+ */
+#ifndef NormalLibObjCompile
+#define NormalLibObjCompile(options) ObjectCompile(options)
+#endif
+
+#ifndef NormalLibObjCplusplusCompile
+#define NormalLibObjCplusplusCompile(options) ObjectCplusplusCompile(options)
+#endif
+
+/*
+ * NormalSharedLibObjCompile - compile fragment for shared objects
+ */
+#ifndef NormalSharedLibObjCompile
+#define NormalSharedLibObjCompile(options) NormalLibObjCompile(options $(SHLIBDEF) $(SHAREDCODEDEF) $(PICFLAGS))
+#endif
+
+#ifndef NormalSharedLibObjCplusplusCompile
+#define NormalSharedLibObjCplusplusCompile(options) NormalLibObjCplusplusCompile(options $(SHLIBDEF) $(SHAREDCODEDEF) $(CXXPICFLAGS))
+#endif
+
+/*
+ * LibObjCompile - compile fragment for unshared/profiled/debugged objects
+ */
+#ifndef LibObjCompile
+#if HasGcc || HasGcc2
+#define LibObjCompile(dir,options) RemoveFiles($@ dir/$@)              @@\
+       ClearmakeOSName \
+       $(CC) -c $(CCOPTIONS) $(ALLDEFINES) options $*.c -o dir/$@
+#else
+#define LibObjCompile(dir,options) RemoveFiles($@ dir/$@)              @@\
+       ClearmakeOSName \
+       $(CC) -c $(CCOPTIONS) $(ALLDEFINES) options $*.c                @@\
+       $(MV) $@ dir/$@
+#endif
+#endif
+
+#ifndef LibObjCplusplusCompile
+#if HasGcc || HasGcc2
+#define LibObjCplusplusCompile(dir,options) RemoveFiles($@ dir/$@)     @@\
+       ClearmakeOSName \
+       $(CXX) -c $(CXXOPTIONS) $(CXXDEFINES) options $*.CCsuf -o dir/$@
+#else
+#define LibObjCplusplusCompile(dir,options) RemoveFiles($@ dir/$@)     @@\
+       ClearmakeOSName \
+       $(CXX) -c $(CXXOPTIONS) $(CXXDEFINES) options $*.CCsuf          @@\
+       $(MV) $@ dir/$@
+#endif
+#endif
+
+/*
+ * DebuggedLibObjCompile - compile fragment for debugged objects
+ */
+#ifndef DebuggedLibObjCompile
+#define DebuggedLibObjCompile(options) LibObjCompile(debugger,DebuggableCDebugFlags options)
+#endif
+
+#ifndef DebuggedLibObjCplusplusCompile
+#define DebuggedLibObjCplusplusCompile(options) LibObjCplusplusCompile(debugger,DebuggableCplusplusDebugFlags options)
+#endif
+
+/*
+ * ProfiledLibObjCompile - compile fragment for profiled objects
+ */
+#ifndef ProfiledLibObjCompile
+#define ProfiledLibObjCompile(options) LibObjCompile(profiled,ProfiledCDebugFlags options)
+#endif
+
+#ifndef ProfiledLibObjCplusplusCompile
+#define ProfiledLibObjCplusplusCompile(options) LibObjCplusplusCompile(profiled,ProfiledCplusplusDebugFlags options)
+#endif
+
+/*
+ * UnsharedLibObjCompile - compile fragment for unshared objects
+ */
+#ifndef UnsharedLibObjCompile
+#define UnsharedLibObjCompile(options) LibObjCompile(unshared,$(CDEBUGFLAGS) options)
+#endif
+
+#ifndef UnsharedLibObjCplusplusCompile
+#define UnsharedLibObjCplusplusCompile(options) LibObjCplusplusCompile(unshared,$(CXXDEBUGFLAGS) options)
+#endif
+
+/*
+ * SharedLibObjCompile - compile fragment for shared objects
+ */
+#ifndef SharedLibObjCompile
+#define SharedLibObjCompile(options) LibObjCompile(shared,options $(SHLIBDEF) $(SHAREDCODEDEF) $(PICFLAGS) $(CDEBUGFLAGS))
+#endif
+
+/*
+ * NormalLibraryObjectRule - for simple libraries
+ */
+#ifndef NormalLibraryObjectRule
+#define        NormalLibraryObjectRule()                                       @@\
+.c.Osuf:                                                               @@\
+       NormalLibObjCompile($(_NOOP_))
+#endif /* NormalLibraryObjectRule */
+
+#ifndef NormalCplusplusObjectRule
+#define NormalCplusplusObjectRule()                                    @@\
+.CCsuf.Osuf:                                                           @@\
+       NormalLibObjCplusplusCompile($(_NOOP_))
+#endif
+
+#ifndef NormalFortranObjectRule
+#define NormalFortranObjectRule()                                      @@\
+.f.Osuf:                                                               @@\
+       RemoveFile($@)                                                  @@\
+       ClearmakeOSName \
+       $(FC) -c $(FCFLAGS) $*.f
+#endif
+
+/*
+ * SpecialObjectRule - generate rules to compile a file with special flags.
+ */
+#ifndef SpecialObjectRule
+#define SpecialObjectRule(objs,depends,options)                                @@\
+objs:  depends                                                         @@\
+       ObjectCompile(options)
+#endif /* SpecialObjectRule */
+
+#ifndef SpecialCplusplusObjectRule
+#define SpecialCplusplusObjectRule(baseobj,basedep,options)            @@\
+baseobj.Osuf:  basedep.CCsuf                                           @@\
+       ObjectCplusplusCompile(options)
+#endif /* SpecialCplusplusObjectRule */
+
+/*
+ * SpecialCObjectRule - generate rules to compile a C file with special flags.
+ *                     also handles CodeCenter rules
+ */
+#ifndef SpecialCObjectRule
+#define SpecialCObjectRule(basename,depends,options)                   @@\
+SpecialObjectRule(basename.Osuf,basename.c depends,options)            @@\
+                                                                       @@\
+basename.i: basename.c depends                                         @@\
+       CPPOnlyCompile(basename.c,options)                              @@\
+                                                                       @@\
+CenterLoadTarget(debug_src,basename.c,NullParameter,$(ALLDEFINES) options)
+#endif /* SpecialCObjectRule */
+
+
+#ifndef ObjectFromSpecialSource
+#define ObjectFromSpecialSource(dst,src,flags)                         @@\
+NoConfigRec(dst.c)                                                     @@\
+                                                                       @@\
+dst.c:  src.c                                                          @@\
+       RemoveFile($@)                                                  @@\
+       $(LN) $? $@                                                     @@\
+                                                                       @@\
+SpecialCObjectRule(dst,NullParameter,flags)                            @@\
+                                                                       @@\
+includes:: dst.c                                                       @@\
+                                                                       @@\
+depend::  dst.c                                                                @@\
+                                                                       @@\
+clean::                                                                        @@\
+       RemoveFile(dst.c)
+#endif /* ObjectFromSpecialSource */
+
+#ifndef LexFileExplicit
+#if HasClearmake               /* provide a place to hang ClearmakeOSName */
+#define LexFileExplicit(file)                                          @@\
+file.c: file.l                                                         @@\
+       ClearmakeOSName \
+       $(LEX) $(LFLAGS) file.l                                         @@\
+       $(MV) lex.yy.c file.c
+#else
+#define LexFileExplicit(file) /* the default rule is fine */
+#endif
+#endif
+
+#ifndef LexFile
+#define LexFile(file)                                                  @@\
+LexFileExplicit(file)                                                  @@\
+                                                                       @@\
+depend:: file.c                                                                @@\
+                                                                       @@\
+clean::                                                                        @@\
+       RemoveFiles(lex.yy.c file.c)
+#endif /* LexFile */
+
+#ifndef YaccFile
+#if HasGnuMake
+#define YaccFile(file,flags)                                           @@\
+depend:: file.c                                                                @@\
+                                                                       @@\
+file.h: file.c                                                         @@\
+                                                                       @@\
+file.c: file.y                                                         @@\
+       ClearmakeOSName \
+       $(YACC) flags file.y                                            @@\
+       $(MV) y.tab.c file.c                                            @@\
+       @if [ -f y.tab.h ]; then set -x; $(MV) y.tab.h file.h; \        @@\
+       else exit 0; fi                                                 @@\
+                                                                       @@\
+clean::                                                                        @@\
+       RemoveFiles(y.tab.c y.tab.h file.h file.c)
+#else
+#define YaccFile(file,flags)                                           @@\
+depend:: file.c                                                                @@\
+                                                                       @@\
+file.h file.c: file.y                                                  @@\
+       ClearmakeOSName \
+       $(YACC) flags file.y                                            @@\
+       $(MV) y.tab.c file.c                                            @@\
+       @if [ -f y.tab.h ]; then set -x; $(MV) y.tab.h file.h; \        @@\
+       else exit 0; fi                                                 @@\
+                                                                       @@\
+clean::                                                                        @@\
+       RemoveFiles(y.tab.c y.tab.h file.h file.c)
+#endif
+#endif /* YaccFile */
+
+#ifndef YaccFileNoFlags
+#define YaccFileNoFlags(file)                                          @@\
+depend:: file.c                                                                @@\
+                                                                       @@\
+file.c: file.y                                                         @@\
+       ClearmakeOSName \
+       $(YACC) file.y                                                  @@\
+       $(MV) y.tab.c file.c                                            @@\
+                                                                       @@\
+clean::                                                                        @@\
+       RemoveFiles(y.tab.c file.c)
+#endif /* YaccFileNoFlags */
+
+
+#ifndef MakeLibrary
+#define MakeLibrary(libname,objlist) $(AR) libname objlist
+#endif
+
+#ifndef LinkBuildLibrary
+#ifdef UseInstalled
+#define LinkBuildLibrary(lib) $(_NULLCMD_)
+#else
+#define LinkBuildLibrary(lib) MakeDir($(BUILDLIBDIR))                  @@\
+       RemoveFile($(BUILDLIBDIR)/lib)                                  @@\
+       cd $(BUILDLIBDIR) && $(LN) $(BUILDLIBTOP)/$(CURRENT_DIR)/lib .
+#endif
+#endif /* LinkBuildLibrary */
+
+#ifndef _LinkBuildLibrary /* will get redefined elsewhere */
+#define _LinkBuildLibrary(lib) $(_NULLCMD_)
+#endif /* _LinkBuildLibrary */
+
+/*
+ * NormalLibraryTarget - generate rules to create a library.
+ */
+#ifndef NormalLibraryTarget
+#define        NormalLibraryTarget(libname,objlist)                            @@\
+AllTarget(LibraryTargetName(libname))                                  @@\
+                                                                       @@\
+LibraryTargetName(libname): objlist $(EXTRALIBRARYDEPS)                        @@\
+       RemoveFile($@)                                                  @@\
+       MakeLibrary($@,objlist)                                         @@\
+       RanLibrary($@)                                                  @@\
+       _LinkBuildLibrary($@)
+#endif /* NormalLibraryTarget */
+
+
+/*
+ * NormalLibraryTarget2 - generate rules to create a library in two steps.
+ * This is used to create libraries with large numbers of files.
+ */
+#ifndef NormalLibraryTarget2
+#define        NormalLibraryTarget2(libname,objlist1,objlist2)                 @@\
+AllTarget(LibraryTargetName(libname))                                  @@\
+                                                                       @@\
+LibraryTargetName(libname): objlist1 objlist2 $(EXTRALIBRARYDEPS)      @@\
+       RemoveFile($@)                                                  @@\
+       MakeLibrary($@,objlist1)                                        @@\
+       MakeLibrary($@,objlist2)                                        @@\
+       RanLibrary($@)                                                  @@\
+       _LinkBuildLibrary($@)
+#endif /* NormalLibraryTarget2 */
+
+
+/*
+ * NormalLibraryTarget3 - generate rules to create a library in three steps.
+ * This is used to create libraries with very large numbers of files.
+ */
+#ifndef NormalLibraryTarget3
+#define        NormalLibraryTarget3(libname,objlist1,objlist2,objlist3)        @@\
+AllTarget(LibraryTargetName(libname))                                  @@\
+                                                                       @@\
+LibraryTargetName(libname): objlist1 objlist2 objlist3 $(EXTRALIBRARYDEPS)     @@\
+       RemoveFile($@)                                                  @@\
+       MakeLibrary($@,objlist1)                                        @@\
+       MakeLibrary($@,objlist2)                                        @@\
+       MakeLibrary($@,objlist3)                                        @@\
+       RanLibrary($@)                                                  @@\
+       _LinkBuildLibrary($@)
+#endif /* NormalLibraryTarget3 */
+
+
+/*
+ * NormalDepLibraryTarget - generate rules to create a library.
+ */
+#ifndef NormalDepLibraryTarget
+#define        NormalDepLibraryTarget(libname,deplist,objlist)                 @@\
+AllTarget(LibraryTargetName(libname))                                  @@\
+                                                                       @@\
+LibraryTargetName(libname): deplist $(EXTRALIBRARYDEPS)                        @@\
+       RemoveFile($@)                                                  @@\
+       MakeLibrary($@,objlist)                                         @@\
+       RanLibrary($@)                                                  @@\
+       _LinkBuildLibrary($@)
+#endif /* NormalDepLibraryTarget */
+
+
+/*
+ * UnsharedLibraryTarget - generate rules to create a library.
+ */
+#ifndef UnsharedLibraryTarget
+#define        UnsharedLibraryTarget(libname,objlist,down,up)                  @@\
+AllTarget(LibraryTargetName(libname))                                  @@\
+                                                                       @@\
+LibraryTargetName(libname): objlist $(EXTRALIBRARYDEPS)                        @@\
+       RemoveFile($@)                                                  @@\
+       (cd down && MakeLibrary(up/$@,objlist))                         @@\
+       RanLibrary($@)                                                  @@\
+       _LinkBuildLibrary($@)
+#endif /* UnsharedLibraryTarget */
+
+
+/*
+ * UnsharedLibraryTarget3 - generate rules to create a library in three steps.
+ * This is used to create libraries with very large numbers of files.
+ */
+#ifndef UnsharedLibraryTarget3
+#define        UnsharedLibraryTarget3(libname,objlist1,objlist2,objlist3,down,up) @@\
+AllTarget(LibraryTargetName(libname))                                  @@\
+                                                                       @@\
+LibraryTargetName(libname): objlist1 objlist2 objlist3 $(EXTRALIBRARYDEPS)     @@\
+       RemoveFile($@)                                                  @@\
+       (cd down && MakeLibrary(up/$@,objlist1))                        @@\
+       (cd down && MakeLibrary(up/$@,objlist2))                        @@\
+       (cd down && MakeLibrary(up/$@,objlist3))                        @@\
+       RanLibrary($@)                                                  @@\
+       _LinkBuildLibrary($@)
+#endif /* UnsharedLibraryTarget3 */
+
+
+/*
+ * SubdirLibraryRule -
+ */
+#ifndef SubdirLibraryRule
+#define        SubdirLibraryRule(objlist)                                      @@\
+all:: DONE                                                             @@\
+                                                                       @@\
+DONE: objlist                                                          @@\
+       RemoveFile($@)                                                  @@\
+       touch $@                                                        @@\
+                                                                       @@\
+clean::                                                                        @@\
+       RemoveFile(DONE)
+#endif /* SubdirLibraryRule */
+
+
+/*
+ * ProfiledLibraryTarget - generate rules to create a profiled library.
+ */
+#ifndef ProfiledLibraryTarget
+#define        ProfiledLibraryTarget(libname,objlist)                          @@\
+AllTarget(LibraryTargetNameSuffix(libname,_p))                         @@\
+                                                                       @@\
+LibraryTargetNameSuffix(libname,_p): objlist $(EXTRALIBRARYDEPS)       @@\
+       RemoveFile($@)                                                  @@\
+       cd profiled && MakeLibrary(../$@,objlist)                       @@\
+       RanLibrary($@)
+
+#endif /* ProfiledLibraryTarget */
+
+
+/*
+ * DebuggedLibraryTarget - generate rules to create a debuggable library.
+ */
+#ifndef DebuggedLibraryTarget
+#define        DebuggedLibraryTarget(libname,objlist)                          @@\
+AllTarget(LibraryTargetNameSuffix(libname,_d))                         @@\
+                                                                       @@\
+LibraryTargetNameSuffix(libname,_d): objlist $(EXTRALIBRARYDEPS)       @@\
+       RemoveFile($@)                                                  @@\
+       cd debugger && MakeLibrary(../$@,objlist)                       @@\
+       RanLibrary($@)
+
+#endif /* DebuggedLibraryTarget */
+
+
+/*
+ * AliasedLibraryTarget - generate rules to link one library to another.
+ */
+#ifndef AliasedLibraryTarget
+#define        AliasedLibraryTarget(libname,alias)                             @@\
+AllTarget(LibraryTargetName(alias))                                    @@\
+                                                                       @@\
+LibraryTargetName(alias): LibraryTargetName(libname)                   @@\
+       RemoveFile($@)                                                  @@\
+       $(LN) LibraryTargetName(libname) $@                             @@\
+                                                                       @@\
+clean::                                                                        @@\
+       RemoveFile(LibraryTargetName(alias))
+#endif /* AliasedLibraryTarget */
+
+
+/*
+ * NormalRelocatableTarget - generate rules to produce a relocatable object
+ * file instead of a library.  
+ */
+#ifndef NormalRelocatableTarget
+#define        NormalRelocatableTarget(objname,objlist)                        @@\
+AllTarget(objname.Osuf)                                                        @@\
+                                                                       @@\
+objname.Osuf: objlist $(EXTRALIBRARYDEPS)                              @@\
+       RemoveFile($@)                                                  @@\
+       $(LD) $(LDCOMBINEFLAGS) objlist -o $@
+#endif /* NormalRelocatableTarget */
+
+
+/*
+ * ProfiledRelocatableTarget - generate rules to produce a profiled relocatable
+ * object file instead of a library.
+ */
+#ifndef ProfiledRelocatableTarget
+#define        ProfiledRelocatableTarget(objname,objlist)                      @@\
+AllTarget(Concat(objname,_p.Osuf))                                     @@\
+                                                                       @@\
+Concat(objname,_p.Osuf): objlist $(EXTRALIBRARYDEPS)                   @@\
+       RemoveFile($@)                                                  @@\
+       $(LD) -X -r objlist -o $@
+
+#endif /* ProfiledRelocatableTarget */
+
+
+/*
+ * DebuggedRelocatableTarget - generate rules to produce a debuggable 
+ * relocatable object file instead of a library.
+ */
+#ifndef DebuggedRelocatableTarget
+#define        DebuggedRelocatableTarget(objname,objlist)                      @@\
+AllTarget(Concat(objname,_d.Osuf))                                     @@\
+                                                                       @@\
+Concat(objname,_d.Osuf): objlist $(EXTRALIBRARYDEPS)                   @@\
+       RemoveFile($@)                                                  @@\
+       $(LD) -X -r objlist -o $@
+
+#endif /* DebuggedRelocatableTarget */
+
+
+/*
+ * LintLibraryTarget - generate rules to create a lint library.  Note that the
+ * lint library is always forced to be newer than the library itself.
+ */
+#ifndef LintLibraryTarget
+#define        LintLibraryTarget(libname,srclist)                              @@\
+lintlib:: Concat(llib-l,libname.ln)                                    @@\
+                                                                       @@\
+Concat(llib-l,libname.ln): srclist $(EXTRALIBRARYDEPS)                 @@\
+       RemoveFile($@)                                                  @@\
+       $(LINT) Concat($(LINTLIBFLAG),libname) $(LINTFLAGS) srclist
+#endif /* LintLibraryTarget */
+
+
+/*
+ * NormalLintTarget - generate rules to lint a set of sources.
+ */
+#ifndef NormalLintTarget
+#define NormalLintTarget(srclist)                                      @@\
+lint:                                                                  @@\
+       $(LINT) $(LINTFLAGS) srclist $(LINTLIBS)                        @@\
+lint1:                                                                 @@\
+       $(LINT) $(LINTFLAGS) $(FILE) $(LINTLIBS)
+#endif /* NormalLintTarget */
+
+
+/*
+ * LintTarget - generate rules to lint $(SRCS)
+ */
+#ifndef LintTarget
+#define LintTarget()                                                   @@\
+NormalLintTarget($(SRCS))
+#endif
+
+
+/*
+ * LinkSourceFile - snag source file from some other directory
+ */
+#ifndef LinkSourceFile
+#define LinkSourceFile(src,dir)                                                @@\
+src:  dir/src                                                          @@\
+       RemoveFile($@)                                                  @@\
+       $(LN) $? $@                                                     @@\
+                                                                       @@\
+NoConfigRec(src)                                                       @@\
+                                                                       @@\
+includes:: src                                                         @@\
+                                                                       @@\
+depend:: src                                                           @@\
+                                                                       @@\
+clean::                                                                        @@\
+       RemoveFile(src)
+#endif
+
+
+/*
+ * LinkFile - link a file
+ */
+#ifndef LinkFile
+#define LinkFile(tofile,fromfile)                                      @@\
+tofile:: fromfile                                                      @@\
+       RemoveFile($@)                                                  @@\
+       $(LN) $? $@                                                     @@\
+                                                                       @@\
+NoConfigRec(tofile)                                                    @@\
+                                                                       @@\
+includes:: tofile                                                      @@\
+                                                                       @@\
+depend:: tofile                                                                @@\
+                                                                       @@\
+clean::                                                                        @@\
+       RemoveFile(tofile)
+#endif
+
+
+#ifndef MakeSubincludesForBuild
+#define MakeSubincludesForBuild(step,dir,srclist)                      @@\
+step::  dir srclist                                                    @@\
+       @-(list=`echo srclist | sed -e 's/[^ ]*\///g'`; \               @@\
+               set -x; cd dir && RemoveFiles($$list))                  @@\
+       @for i in srclist; do \                                         @@\
+               (set -x; cd dir && $(LN) ../$$i .); \                   @@\
+       done                                                            @@\
+                                                                       @@\
+dir::                                                                  @@\
+       $(MKDIRHIER) dir                                                @@\
+                                                                       @@\
+clean::                                                                        @@\
+       @-(if [ -d dir ]; then \                                        @@\
+               list=`echo srclist | sed -e 's/[^ ]*\///g'`; \          @@\
+               set -x; cd dir && RemoveFile($$list); else exit 0; fi)
+#endif
+
+
+/*
+ * LangNamedTargetSubdirs - recursively make a series of steps
+ */
+#ifndef LangNamedTargetSubdirs
+#define LangNamedTargetSubdirs(lang,name,dirs,verb,flags,subname)      @@\
+name::                                                                 @@\
+       @MakeFlagsToShellFlags(ik,set +e); \                            @@\
+       for i in dirs ;\                                                @@\
+       do \                                                            @@\
+               echo verb "in $(CURRENT_DIR)/$$i..."; \                 @@\
+               (cd $$i && LANG=lang $(MAKE) $(MFLAGS) flags subname);\ @@\
+       done
+#endif
+
+
+/*
+ * NamedMakeSubdirs - generate rules to do makes in the given subdirectories.
+ * If you want CDEBUGFLAGS passed along to subdirectories, provide a line like
+ * the following in the appropriate Imakefile
+ * 
+ *         #define PassCDebugFlags 'CDEBUGFLAGS=$(CDEBUGFLAGS)'
+ */
+#ifndef LangNamedMakeSubdirs
+#define LangNamedMakeSubdirs(lang,name,dirs) \
+LangNamedTargetSubdirs(lang,name,dirs,"making" name,PassCDebugFlags,all)
+#endif /* LangNamedMakeSubdirs */
+
+#ifndef LangMakeSubdirs
+#define LangMakeSubdirs(lang,dirs)                                     @@\
+LangNamedMakeSubdirs(lang,all,dirs)
+#endif /* LangMakeSubdirs */
+
+
+
+/*
+ * NamedTargetSubdirs - recursively make a series of steps
+ */
+#ifndef NamedTargetSubdirs
+#define NamedTargetSubdirs(name,dirs,verb,flags,subname)               @@\
+name::                                                                 @@\
+       @MakeFlagsToShellFlags(ik,set +e); \                            @@\
+       for i in dirs ;\                                                @@\
+       do \                                                            @@\
+               echo verb "in $(CURRENT_DIR)/$$i..."; \                 @@\
+               MakeNamedTargetSubdir($$i,flags,subname); \             @@\
+       done
+#endif
+
+
+/*
+ * NamedMakeSubdirs - generate rules to do makes in the given subdirectories.
+ * If you want CDEBUGFLAGS passed along to subdirectories, provide a line like
+ * the following in the appropriate Imakefile
+ * 
+ *         #define PassCDebugFlags 'CDEBUGFLAGS=$(CDEBUGFLAGS)'
+ */
+#ifndef NamedMakeSubdirs
+#define NamedMakeSubdirs(name,dirs) \
+NamedTargetSubdirs(name,dirs,"making" name,PassCDebugFlags,all)
+#endif /* NamedMakeSubdirs */
+
+#ifndef MakeSubdirs
+#define MakeSubdirs(dirs)                                              @@\
+NamedMakeSubdirs(all,dirs)
+#endif /* MakeSubdirs */
+
+
+/*
+ * DependSubdirs - generate rules to recursively compute dependencies as
+ * part of the make depend step.
+ */
+#ifndef DependSubdirs
+#define DependSubdirs(dirs) \
+NamedTargetSubdirs(depend,dirs,"depending",NullParameter,depend)
+#endif /* DependSubdirs */
+
+
+/*
+ * ForceSubdirs - force make to build subdirectories
+ */
+#ifndef ForceSubdirs
+#if !HasBsdMake
+#define ForceSubdirs(dirs)                                             @@\
+dirs: FRC                                                              @@\
+       @echo "making all in $(CURRENT_DIR)/$@..."                      @@\
+       @MakeNamedTargetSubdir($@,PassCDebugFlags,all)                  @@\
+                                                                       @@\
+FRC:
+#else
+/* For BSD 4.4 make */
+#define ForceSubdirs(dirs)                                             @@\
+dirs: .EXEC                                                            @@\
+       @cd $@ ; echo "making all in $(CURRENT_DIR)/$@..."; \           @@\
+       $(MAKE) $(MFLAGS) PassCDebugFlags all                           @@\
+                                                                       @@\
+.EXEC:
+#endif
+#endif /* ForceSubdirs */
+
+/*
+ * InstallSubdirs - generate rules to recursively install programs and files.
+ */
+#ifndef InstallSubdirs
+#define InstallSubdirs(dirs) \
+NamedTargetSubdirs(install,dirs,"installing",DESTDIR=$(DESTDIR),install)
+#endif /* InstallSubdirs */
+
+
+/*
+ * InstallManSubdirs - generate rules to recursively install manual pages.
+ */
+#ifndef InstallManSubdirs
+#define InstallManSubdirs(dirs) \
+NamedTargetSubdirs(install.man,dirs,"installing man pages",DESTDIR=$(DESTDIR),install.man)
+#endif /* InstallManSubdirs */
+
+
+/*
+ * IncludesSubdirs - generate rules to recursively put include files in build
+ */
+#ifndef IncludesSubdirs
+#define IncludesSubdirs(dirs) \
+NamedTargetSubdirs(includes,dirs,including,NullParameter,includes)
+#endif
+
+
+/*
+ * InstallLinkKitSubdirs - generate rules to recursively install server Link
+ *                         Kit (only used for XFree86). This is a no-op
+ *                         rule so that Imakefiles on non-XFree86 systems
+ *                         continue to build Makefiles correctly.
+ */
+#ifndef InstallLinkKitSubdirs
+#define InstallLinkKitSubdirs(dirs)
+#endif
+
+
+/*
+ * CleanSubdirs - generate rules to recursively clean out garbage files.
+ */
+#define BootstrapCleanSubdirs /**/     /* used at top-level */
+#ifndef NamedCleanSubdirs
+#define NamedCleanSubdirs(name,dirs) \
+NamedTargetSubdirs(name,dirs,"cleaning",BootstrapCleanSubdirs,clean)
+#endif /* NamedCleanSubdirs */
+
+#ifndef CleanSubdirs
+#define CleanSubdirs(dirs) \
+NamedCleanSubdirs(clean,dirs)
+#endif
+
+
+/*
+ * TagSubdirs - generate rules to recursively create tags files.
+ */
+#ifndef NamedTagSubdirs
+#define NamedTagSubdirs(name,dirs) \
+NamedTargetSubdirs(name,dirs,"tagging",TAGS='$(TAGS)',tags)
+#endif /* TagSubdirs */
+
+#ifndef TagSubdirs
+#define TagSubdirs(dirs) \
+NamedTagSubdirs(tags,dirs)
+#endif
+
+/*
+ * MakeLintSubdirs - generate rules to recursively lint directories as part 
+ * of the named step.
+ */
+#ifndef MakeLintSubdirs
+#define MakeLintSubdirs(dirs,target,subtarget) \
+NamedTargetSubdirs(target,dirs,"linting" for target and subtarget,DESTDIR=$(DESTDIR) LINTOPTS='$(LINTOPTS)',subtarget)
+#endif /* MakeLintSubdirs */
+
+
+/*
+ * LintSubdirs - generate rules to recursively lint directories as part of 
+ * the make lint step.
+ */
+#ifndef LintSubdirs
+#define LintSubdirs(dirs)                                              @@\
+MakeLintSubdirs(dirs,lint,lint)
+#endif /* LintSubdirs */
+
+
+/*
+ * MakeLintLibSubdirs - generate rules to recursively create lint libraries.
+ */
+#ifndef MakeLintLibSubdirs
+#define MakeLintLibSubdirs(dirs)                                       @@\
+MakeLintSubdirs(dirs,lintlib,lintlib)
+#endif /* MakeLintLibSubdirs */
+
+
+/*
+ * MakeMakeSubdirs - generate rules to recursively recreate Makefiles as part
+ * of the specified step in the build.  If $(TOP) is set to an absolute path, 
+ * do not prepend the ../ prefix.  This makes running things outside of the 
+ * source tree much easier.
+ * $(ONESUBDIR)/Makefile exists as a separate, explicit target so that
+ * clearmake will know what its goal is and do wink-in.
+ */
+#ifndef MakeMakeSubdirs
+#define MakeMakeSubdirs(dirs,target)                                   @@\
+$(ONESUBDIR)/Makefile:                                                 @@\
+       @MakeFlagsToShellFlags(n,executeit="no"); \                     @@\
+       cd $(ONESUBDIR) && \                                            @@\
+       if [ "$$executeit" != "no" ]; then \                            @@\
+               ImakeSubCmdHelper -DTOPDIR=$(IMAKETOP) -DCURDIR=$(ONECURDIR)$(ONESUBDIR); \ @@\
+       fi;                                                             @@\
+                                                                       @@\
+target::                                                               @@\
+       -@MakeFlagsToShellFlags(ik,set +e); \                           @@\
+       MakeFlagsToShellFlags(n,executeit="no"); \                      @@\
+       for i in dirs ;\                                                @@\
+       do \                                                            @@\
+               case "$(CURRENT_DIR)" in \                              @@\
+               .) curdir= ;; \                                         @@\
+               *) curdir=$(CURRENT_DIR)/ ;; \                          @@\
+               esac; \                                                 @@\
+               echo "making Makefiles in $$curdir$$i..."; \            @@\
+               itmp=`echo $$i | sed -e 's;^\./;;g' -e 's;/\./;/;g'`; \ @@\
+               curtmp="$(CURRENT_DIR)" \                               @@\
+               toptmp=""; \                                            @@\
+               case "$$itmp" in \                                      @@\
+                   ../?*) \                                            @@\
+                       while echo "$$itmp" | grep '^\.\./' > /dev/null;\       @@\
+                         do \                                          @@\
+                            toptmp="/`basename $$curtmp`$$toptmp"; \   @@\
+                            curtmp="`dirname $$curtmp`"; \             @@\
+                            itmp="`echo $$itmp | sed 's;\.\./;;'`"; \  @@\
+                         done \                                        @@\
+                   ;; \                                                @@\
+               esac; \                                                 @@\
+               case "$$itmp" in \                                      @@\
+               */?*/?*/?*/?*)  newtop=../../../../..;; \               @@\
+               */?*/?*/?*)     newtop=../../../..;; \                  @@\
+               */?*/?*)        newtop=../../..;; \                     @@\
+               */?*)           newtop=../..;; \                        @@\
+               *)              newtop=..;; \                           @@\
+               esac; \                                                 @@\
+               newtop="$$newtop$$toptmp"; \                            @@\
+               case "$(TOP)" in \                                      @@\
+               /?*) imaketop=$(TOP) \                                  @@\
+                    imakeprefix= ;; \                                  @@\
+               .) imaketop=$$newtop \                                  @@\
+                  imakeprefix=$$newtop/ ;; \                           @@\
+               *) imaketop=$$newtop/$(TOP) \                           @@\
+                  imakeprefix=$$newtop/ ;; \                           @@\
+               esac; \                                                 @@\
+               RemoveFile($$i/Makefile.bak); \                         @@\
+               if [ -f $$i/Makefile ]; then \                          @@\
+                       echo "  $(MV) Makefile Makefile.bak"; \         @@\
+                       if [ "$$executeit" != "no" ]; then \            @@\
+                               $(MV) $$i/Makefile $$i/Makefile.bak; \  @@\
+                       fi; \                                           @@\
+               fi; \                                                   @@\
+               $(MAKE) $(MFLAGS) $(MAKE_OPTS) ONESUBDIR=$$i ONECURDIR=$$curdir IMAKETOP=$$imaketop IMAKEPREFIX=$$imakeprefix $$i/Makefile; \   @@\
+               if [ -d $$i ] ; then \                                  @@\
+                       cd $$i; \                                       @@\
+                       $(MAKE) $(MFLAGS) Makefiles; \                  @@\
+                       cd $$newtop; \                                  @@\
+               else \                                                  @@\
+                       exit 1; \                                       @@\
+               fi; \                                                   @@\
+       done
+
+#ifdef UseInstalled
+#define ImakeSubCmdHelper $(IMAKE_CMD)
+#else
+#define ImakeSubCmdHelper $(IMAKEPREFIX)$(IMAKE) -I$(IMAKEPREFIX)$(IRULESRC) $(IMAKE_DEFINES)
+#endif
+
+#endif /* MakeMakeSubdirs */
+
+
+/*
+ * MakefileSubdirs - generate rules to create Makefiles.
+ */
+#ifndef MakefileSubdirs
+#define MakefileSubdirs(dirs)                                          @@\
+MakeMakeSubdirs(dirs,Makefiles)
+#endif /* MakefileSubdirs */
+
+/*
+ * Translate XCOMM into pound sign with sed, rather than passing -DXCOMM=XCOMM
+ * to cpp, because that trick does not work on all ANSI C preprocessors.
+ * Also delete line numbers from the cpp output (-P is not portable, I guess).
+ */
+#ifndef CppSedMagic
+#define CppSedMagic sed -e '/^#  *[0-9][0-9]*  *.*$$/d' -e '/^XCOMM$$/s//#/' -e '/^XCOMM[^a-zA-Z0-9_]/s/^XCOMM/#/'
+#endif /* CppSedMagic */
+
+#ifndef CppFileTarget
+#define CppFileTarget(dst,src,defs,deplist)                            @@\
+dst::  src deplist                                                     @@\
+       RemoveFile($@)                                                  @@\
+       ClearmakeOSName \
+       $(CPP) CppNoLineInfoOption defs <src | CppSedMagic >$@          @@\
+                                                                       @@\
+clean::                                                                        @@\
+       RemoveFiles(dst)
+#endif /* CppFileTarget */
+
+/*
+ * CppScriptTarget - generate rules to create a shell script by running the
+ * input through cpp.  If the ExecableScripts configuration parameter is not
+ * set, then make sure that the first line begins with a colon.
+ */
+#ifndef CppScriptTarget
+#if ExecableScripts            /* can use #! instead of colon */
+#define CppScriptTarget(dst,src,defs,deplist)                          @@\
+dst::  src deplist                                                     @@\
+       RemoveFile($@)                                                  @@\
+       ClearmakeOSName \
+       $(CPP) CppNoLineInfoOption defs <src | CppSedMagic >$@          @@\
+       chmod a+x $@                                                    @@\
+                                                                       @@\
+clean::                                                                        @@\
+       RemoveFiles(dst)
+#else
+#define CppScriptTarget(dst,src,defs,deplist)                          @@\
+dst::  src deplist                                                     @@\
+       RemoveFile($@)                                                  @@\
+       ClearmakeOSName \
+       echo \: >$@                                                     @@\
+       sed '1d' src | $(CPP) CppNoLineInfoOption defs | CppSedMagic >>$@       @@\
+       chmod a+x $@                                                    @@\
+                                                                       @@\
+clean::                                                                        @@\
+       RemoveFile(dst)
+#endif /* ExecableScripts */
+#endif /* CppScriptTarget */
+
+
+/*
+ * MakeScriptFromCpp - generate rules to create a script from a file with a
+ * .cpp suffix.
+ */
+#ifndef MakeScriptFromCpp
+#define MakeScriptFromCpp(name,defs)                                   @@\
+CppScriptTarget(name,name.cpp,defs,NullParameter)
+#endif /* MakeScriptFromCpp */
+
+#ifndef CppSourceFile
+#define CppSourceFile(dst,src,defs,deplist)                            @@\
+CppFileTarget(dst,src,defs,deplist)                                    @@\
+                                                                       @@\
+includes:: dst                                                         @@\
+                                                                       @@\
+depend:: dst
+#endif /* CppFileTarget */
+
+/*
+ * MakeDirectories - generate rules to create a hierarchy of directories.
+ */
+#ifndef MakeDirectories
+#define MakeDirectories(step,dirs)                                     @@\
+step::                                                                 @@\
+       DirFailPrefix@MakeFlagsToShellFlags(i,set +e); \                @@\
+       for i in dirs; do if [ -d $(DESTDIR)$$i ]; then \               @@\
+               set +x; else (set -x; $(MKDIRHIER) $(DESTDIR)$$i); fi; \ @@\
+       done
+#endif /* MakeDirectories */
+
+
+/*
+ * AllTarget - generate rules to build necessary things during make all.
+ */
+#ifndef AllTarget
+#define AllTarget(depends)                                             @@\
+all:: depends
+#endif /* AllTarget */
+
+#ifdef DefineOldLibraryRules
+#include <oldlib.rules>
+#endif
+
+#ifndef StaticLibrary
+#define StaticLibrary(libpath,libname) Concat3(libpath,/,LibraryTargetName(libname))
+#endif
+
+/*
+ * MakeMutex - generate mutex rules for parallel make
+ */
+#ifndef MakeMutex
+#ifdef MutexDirective
+#define MakeMutex(targets)                                             @@\
+MutexDirective:        targets
+#endif /* MutexDirective */
+#endif /* MakeMutex */
diff --git a/Xserver/config/cf/Imake.tmpl b/Xserver/config/cf/Imake.tmpl
new file mode 100644 (file)
index 0000000..c0422e0
--- /dev/null
@@ -0,0 +1,1428 @@
+XCOMM ----------------------------------------------------------------------
+XCOMM Makefile generated from IMAKE_TEMPLATE and INCLUDE_IMAKEFILE
+XCOMM $TOG: Imake.tmpl /main/245 1997/05/20 10:05:47 kaleb $
+XCOMM
+XCOMM
+XCOMM
+XCOMM
+XCOMM $XFree86: xc/config/cf/Imake.tmpl,v 3.32.2.8 1998/02/08 11:19:24 dawes Exp $
+XCOMM ----------------------------------------------------------------------
+
+/*
+ * generic imake template
+ */
+
+/*
+ * Modify Imake.cf when adding a new architecture, do not modify this file.
+ * Platform-specific parameters may be set in the appropriate <vendor>.cf
+ * configuration files.  Site-specific parameters should be set in the file
+ * site.def.  Full rebuilds are recommended if any parameters are changed.
+ * If your C preprocessor does not define any unique symbols, you will need
+ * to set BOOTSTRAPCFLAGS when rebuilding imake (usually when doing
+ * "make World" the first time).
+ */
+
+#define ImakeConfigRelease 6
+
+#define        YES     1
+#define NO     0
+
+/* Ensure that "all" is the default target in the Makefile. */
+all::
+
+.SUFFIXES: .i
+
+#include <Imake.cf>
+
+XCOMM -----------------------------------------------------------------------
+XCOMM site-specific configuration parameters that need to come before
+XCOMM the platform-specific parameters - edit site.def to change
+#define BeforeVendorCF
+#include <site.def>
+#undef BeforeVendorCF
+
+#if defined(HasGcc2) && !defined(HasGcc)
+# define HasGcc HasGcc2
+#endif
+
+#ifndef HasClearmake
+# define HasClearmake NO
+#endif
+
+/*
+ * ClearmakeOSName - insert the current OS type into the clearmake
+ * build script, so .o files from different platforms cannot be winked in.
+ * If clearmake finds the build script for two .o files is the same, it
+ * will share the .o, even across different architectures.  Inserting the
+ * O/S name into the build script in a comment prevents unwanted sharing.
+ * Note the trailing double-@ in the macro: end a line using this macro
+ * with backslash without the double-@ usually used.
+ * Like this:
+ *
+ * #define SomeRule() @@\
+ *     something or other @@\
+ *     ClearmakeOSName \
+ *     something else @@\
+ *     and more
+ */
+#ifndef ClearmakeOSName
+# if HasClearmake
+#  define ClearmakeOSName @ XCOMM $(OSNAME) @@
+# else
+#  define ClearmakeOSName /**/
+# endif
+#endif
+
+#if HasClearmake
+# ifndef MakeCmd
+#  define MakeCmd clearmake
+# endif
+#endif
+
+#if HasClearmake
+XCOMM ----------------------------------------------------------------------
+.c.o:
+       ClearmakeOSName $(CC) -c $(CFLAGS) $*.c
+#endif
+
+XCOMM ----------------------------------------------------------------------
+XCOMM platform-specific configuration parameters - edit MacroFile to change
+#include MacroIncludeFile
+
+XCOMM ----------------------------------------------------------------------
+XCOMM site-specific configuration parameters that go after
+XCOMM the platform-specific parameters - edit site.def to change
+#define AfterVendorCF
+#include <site.def>
+#undef AfterVendorCF
+
+/*
+ * defaults for various generic parameters; set in site.def if needed
+ */
+
+/* the following are needed before we can include Imake.rules */
+
+#ifndef HasVarDirectory
+#define HasVarDirectory                NO
+#endif
+#ifndef HasSymLinks
+#define HasSymLinks            YES
+#endif
+#ifndef SystemV
+#define SystemV                        NO      /* SYSV (R3) */
+#endif
+#ifndef SystemV4
+#define SystemV4               NO      /* SVR4 */
+#endif
+#ifndef HasCodeCenter
+#define HasCodeCenter          NO
+#endif
+#ifndef HasSentinel
+#define HasSentinel            NO
+#endif
+#ifndef HasPurify
+#define HasPurify              NO
+#endif
+#ifndef HasTestCenter
+#define HasTestCenter          NO
+#endif
+#ifndef HasBsdMake
+#define HasBsdMake             NO
+#endif
+#ifndef HasGnuMake
+#define HasGnuMake             NO
+#endif
+#ifndef HasParallelMake
+#define HasParallelMake                NO
+#endif
+#ifndef RemoveTargetProgramByMoving
+#define RemoveTargetProgramByMoving NO
+#endif
+#ifndef DoRanlibCmd
+#if SystemV || SystemV4
+#define DoRanlibCmd NO
+#else
+#define DoRanlibCmd YES
+#endif
+#endif
+#ifndef ExecableScripts
+#if SystemV
+#define ExecableScripts                NO
+#else
+#define ExecableScripts                YES     /* kernel exec() can handle #! */
+#endif
+#endif
+
+#ifndef HasMakefileSafeInclude     /* -include or sinclude in a Makefile */
+#if HasClearmake || HasBsdMake
+#define HasMakefileSafeInclude YES
+#else
+#define HasMakefileSafeInclude NO   /* see also vendor-specific .cf files */
+#endif
+#endif
+
+#include <Imake.rules>
+
+#ifndef HasSharedLibraries
+#define HasSharedLibraries NO
+#endif
+#ifndef OSMajorVersion
+#define OSMajorVersion          0
+#endif
+#ifndef OSMinorVersion
+#define OSMinorVersion          0
+#endif
+#ifndef OSTeenyVersion
+#define OSTeenyVersion          0
+#endif
+#ifndef UnalignedReferencesAllowed
+#define UnalignedReferencesAllowed NO  /* if arbitrary deref is okay */
+#endif
+#ifndef AvoidNullMakeCommand
+#if !HasBsdMake
+#define AvoidNullMakeCommand NO
+#else
+#define AvoidNullMakeCommand YES
+#endif
+#endif
+#if AvoidNullMakeCommand
+#ifndef NullMakeCommand
+#define NullMakeCommand                @ echo -n
+#endif
+/*
+ * An obscure bug in BSD4.3's original make causes it not to recognize a
+ * macro definition if the macro name starts with a non-alpha and in
+ * column one.
+ */
+ _NULLCMD_ = NullMakeCommand
+#endif
+
+#ifndef CrossCompiling
+#define CrossCompiling         NO
+#endif
+#ifndef BourneShell                    /* to force shell in makefile */
+#define BourneShell            /bin/sh
+#endif
+#ifndef ConstructMFLAGS
+#if SystemV
+#define ConstructMFLAGS                YES     /* build MFLAGS from MAKEFLAGS */
+#else
+#define ConstructMFLAGS                NO      /* build MFLAGS from MAKEFLAGS */
+#endif
+#endif
+
+#ifndef ConstructMAKEFLAGS             /* needed on old BSD-based? */
+#define ConstructMAKEFLAGS     NO      /* build MAKEFLAGS from MFLAGS */
+#endif
+
+#ifndef HasLargeTmp
+#define HasLargeTmp            NO      /* be paranoid */
+#endif
+
+#ifndef HasBSD44Sockets
+#define HasBSD44Sockets                NO
+#endif
+#ifndef HasSockets
+#define HasSockets             YES
+#endif
+#ifndef HasStreams
+#define HasStreams             !HasSockets
+#endif
+#ifndef HasDECnet
+#define HasDECnet              NO
+#endif
+#ifndef HasPoll
+#if SystemV || SystemV4
+#define HasPoll                        YES
+#else
+#define HasPoll                        NO
+#endif
+#endif
+#ifndef HasVFork
+#if SystemV
+#define HasVFork               NO      /* not yet... */
+#else
+#define HasVFork               YES
+#endif
+#endif
+#ifndef HasSetUserContext
+#define HasSetUserContext      NO
+#endif
+#ifndef HasLibCrypt
+#define HasLibCrypt            NO
+#endif
+#ifndef HasPutenv
+#define HasPutenv              NO      /* assume not */
+#endif
+#ifndef HasVoidSignalReturn
+#define HasVoidSignalReturn    YES     /* assume yes */
+#endif
+#ifndef HasBsearch
+#define HasBsearch             YES     /* assume yes */
+#endif
+#ifndef HasSnprintf
+#define HasSnprintf            NO      /* assume not */
+#endif
+#ifndef HasMkstemp
+#define HasMkstemp             NO      /* assume not */
+#endif
+#ifndef HasFortran
+#define HasFortran             NO
+#endif
+#ifndef HasCplusplus
+#if HasGcc2ForCplusplus
+#define HasCplusplus           YES
+#else
+#define HasCplusplus           NO
+#endif
+#endif
+#ifndef HasNdbm
+#define HasNdbm                        NO
+#endif
+#ifndef HasSecureRPC
+#define HasSecureRPC           NO      /* if you have Secure RPC */
+#endif
+#ifndef HasKrb5
+#define HasKrb5                        NO      /* if you have Kerberos V5 */
+#endif
+#ifndef HasLatex
+#define HasLatex               YES
+#endif
+#ifndef HasShm
+#if SystemV || SystemV4
+#define HasShm                 YES
+#else
+#define HasShm                 NO
+#endif
+#endif
+#ifndef HasCbrt
+#define HasCbrt                        YES
+#endif
+#ifndef HasFfs
+#define HasFfs                 YES
+#endif
+#ifndef HasZlib
+#define HasZlib                        NO
+#endif
+#if !HasZlib           /* if OS doesn't have it, we'll build it */
+#undef GzipLibrary     /* GzipLibrary was valid only if HasZlib */
+#endif
+#ifndef GzipLibrary    /* if OS config didn't define it, assume it's -lz */
+#define GzipLibrary -lz
+#endif
+#if HasKrb5
+#ifndef Krb5Includes
+#define Krb5Includes -I/krb5/include
+#endif
+#ifndef Krb5Libraries
+#define Krb5Libraries -L/krb5/lib -L/usr/isode/lib -lkrb5 -lcrypto -lisode -lcom_err -ldbm
+#endif
+#else
+#undef Krb5Includes
+#define Krb5Includes /**/
+#undef Krb5Libraries
+#define Krb5Libraries /**/
+#endif
+#ifndef UseGnuMalloc
+#define UseGnuMalloc           NO
+#endif
+#ifndef GnuMallocLibrary
+#define GnuMallocLibrary -lgmalloc
+#endif
+#ifndef MallocLibraries
+#if UseGnuMalloc
+#define MallocLibraries        GnuMallocLibrary
+#else
+#define MallocLibraries        /**/
+#endif
+#endif
+#ifndef HasTk
+#define HasTk NO
+#endif
+#ifndef TkLibName
+#if HasTk
+#define TkLibName tk
+#else
+#define TkLibName
+#endif
+#endif
+TKLIBNAME = TkLibName
+#ifndef TkLibDir
+#if HasTk
+#define TkLibDir /usr/local/lib
+#else
+#define TkLibDir
+#endif
+#endif
+TKLIBDIR = TkLibDir
+#ifndef TkIncDir
+#if HasTk
+#define TkIncDir /usr/local/include
+#else
+#define TkIncDir
+#endif
+#endif
+#ifndef TkLibrary
+#ifdef HasTk
+#define TkLibrary Concat(-L,$(TKLIBDIR)) Concat(-l,$(TKLIBNAME))
+#else
+#define TkLibrary
+#endif
+#endif
+#ifndef HasTcl
+#define HasTcl NO
+#endif
+#ifndef TclLibName
+#if HasTcl
+#define TclLibName tcl
+#else
+#define TclLibName
+#endif
+#endif
+TCLLIBNAME = TclLibName
+#ifndef TclLibDir
+#if HasTcl
+#define TclLibDir /usr/local/lib
+#else
+#define TclLibDir
+#endif
+#endif
+TCLIBDIR = TclLibDir
+#ifndef TclIncDir
+#if HasTcl
+#define TclIncDir /usr/local/include
+#else
+#define TclIncDir
+#endif
+#endif
+#ifndef TclLibrary
+#ifdef HasTcl
+#define TclLibrary Concat(-L,$(TCLLIBDIR)) Concat(-l,$(TCLLIBNAME))
+#else
+#define TclLibrary
+#endif
+#endif
+#ifndef NeedConstPrototypes
+#define NeedConstPrototypes    NO
+#endif
+#ifndef NeedVarargsPrototypes
+#define NeedVarargsPrototypes  NO
+#endif
+#ifndef NeedNestedPrototypes
+#define NeedNestedPrototypes   NO
+#endif
+#ifndef NeedFunctionPrototypes
+#define NeedFunctionPrototypes (NeedVarargsPrototypes || NeedNestedPrototypes)
+#endif
+#ifndef NeedWidePrototypes
+#define NeedWidePrototypes     YES     /* mix and match ANSI-C, non-ANSI */
+#endif
+
+#ifndef StripInstalledPrograms
+#define StripInstalledPrograms NO      /* leave symbol table just in case */
+#endif
+#ifndef UseCCMakeDepend                        /* use slow cc -E script */
+#define UseCCMakeDepend NO
+#endif
+#ifndef UseGccMakeDepend               /* use slowish but correct gcc -M */
+#define UseGccMakeDepend NO
+#endif
+
+/* DefaultUsrBin is independent of ProjectRoot.
+   This is a directory where programs will be found even if PATH
+   is not set, for example when coming in remotely via rsh. */
+#ifndef DefaultUsrBin
+#define        DefaultUsrBin /usr/bin
+#endif
+
+#ifndef UsrLibDir
+#ifdef ProjectRoot
+#define UsrLibDir Concat(ProjectRoot,/lib)
+#ifndef AlternateUsrLibDir
+#define AlternateUsrLibDir YES
+#endif
+#else
+#define UsrLibDir /usr/lib
+#ifndef AlternateUsrLibDir
+#define AlternateUsrLibDir NO
+#endif
+#endif
+#else
+#ifndef AlternateUsrLibDir
+#define AlternateUsrLibDir YES
+#endif
+#endif
+#ifndef VarLibDir
+#ifdef ProjectVar
+#define VarLibDir Concat(ProjectVar,/lib)
+#else
+#define VarLibDir /var/lib
+#endif
+#endif
+
+#ifndef ShLibDir
+#define ShLibDir UsrLibDir
+#endif
+#ifndef IncRoot
+#ifdef ProjectRoot
+#define IncRoot Concat(ProjectRoot,/include)
+#ifndef AlternateIncRoot
+#define AlternateIncRoot YES
+#endif
+#else
+#define IncRoot /usr/include
+#ifndef AlternateIncRoot
+#define AlternateIncRoot NO
+#endif
+#endif
+#else
+#ifndef AlternateIncRoot
+#define AlternateIncRoot YES
+#endif
+#endif
+#ifndef LintlibDir
+#define LintlibDir $(USRLIBDIR)/lint
+#endif
+#ifndef SystemManDirectory
+#if SystemV4
+#define SystemManDirectory /usr/share/man
+#else
+#define SystemManDirectory /usr/share/man
+#endif
+#endif
+#ifndef ManDirectoryRoot
+#ifdef ProjectRoot
+#define ManDirectoryRoot Concat(ProjectRoot,/man)
+#else
+#define ManDirectoryRoot SystemManDirectory
+#endif
+#endif
+#ifndef ManPath
+#define ManPath ManDirectoryRoot
+#endif
+#ifndef ManSourcePath
+#define ManSourcePath $(MANPATH)/man
+#endif
+#ifndef ManDir
+#define ManDir $(MANSOURCEPATH)$(MANSUFFIX)
+#endif
+#ifndef LibmanDir
+#define LibmanDir $(MANSOURCEPATH)$(LIBMANSUFFIX)
+#endif
+#ifndef FileManDir
+#define FileManDir $(MANSOURCEPATH)$(FILEMANSUFFIX)
+#endif
+#ifndef ConfigSrc
+#define ConfigSrc $(TOP)/config
+#endif
+#ifndef DependDir
+#if UseCCMakeDepend || UseGccMakeDepend
+#define DependDir $(CONFIGSRC)/util
+#else
+#define DependDir $(CONFIGSRC)/makedepend
+#endif
+#endif
+#ifndef UNCOMPRESSPATH
+#define UNCOMPRESSPATH /usr/ucb/uncompress
+#endif
+#ifndef OptimizedCDebugFlags
+#define OptimizedCDebugFlags -O
+#endif
+#ifndef OptimizedCplusplusDebugFlags
+#define OptimizedCplusplusDebugFlags OptimizedCDebugFlags
+#endif
+#ifndef DebuggableCDebugFlags
+#define DebuggableCDebugFlags -g
+#endif
+#ifndef DebuggableCplusplusDebugFlags
+#define DebuggableCplusplusDebugFlags DebuggableCDebugFlags
+#endif
+#ifndef ProfiledCDebugFlags
+#define ProfiledCDebugFlags -pg
+#endif
+#ifndef ProfiledCplusplusDebugFlags
+#define ProfiledCplusplusDebugFlags ProfiledCDebugFlags
+#endif
+#ifndef NoOpCDebugFlags
+#define NoOpCDebugFlags /**/
+#endif
+#ifndef DefaultCDebugFlags
+#define DefaultCDebugFlags OptimizedCDebugFlags
+#endif
+#ifndef DefaultCplusplusDebugFlags
+#define DefaultCplusplusDebugFlags OptimizedCplusplusDebugFlags
+#endif
+#ifndef DefaultCCOptions
+#define DefaultCCOptions /* floating point, etc. */
+#endif
+#ifndef DefaultCplusplusOptions
+#define DefaultCplusplusOptions /* floating point, etc. */
+#endif
+#ifndef NoRConst
+#define NoRConst NO /* YES if const for structs of funcs is bad */
+#endif
+#ifndef InstPgmFlags
+#define InstPgmFlags -s
+#endif
+#ifndef InstBinFlags
+#define InstBinFlags -m 0755
+#endif
+#ifndef InstUidFlags
+#define InstUidFlags -m 4711
+#endif
+#ifndef InstLibFlags
+#define InstLibFlags -m 0644
+#endif
+#ifndef InstIncFlags
+#define InstIncFlags -m 0444
+#endif
+#ifndef InstManFlags
+#define InstManFlags -m 0444
+#endif
+#ifndef InstDatFlags
+#define InstDatFlags -m 0444
+#endif
+#ifndef InstKmemFlags     /* put -g kmem -m 2711 in site.def... */
+#define InstKmemFlags InstUidFlags
+#endif
+#ifndef ParallelMakeFlags
+#define ParallelMakeFlags /**/
+#endif
+#ifndef ArCmdBase
+#define ArCmdBase ar
+#endif
+#ifndef ArCmd
+#if HasLargeTmp || SystemV4
+#define ArCmd ArCmdBase cq
+#else
+#define ArCmd ArCmdBase clq
+#endif
+#endif
+#ifndef ArAddCmd
+#if HasLargeTmp || SystemV4
+#define ArAddCmd ArCmdBase ru
+#else
+#define ArAddCmd ArCmdBase rul
+#endif
+#endif
+#ifndef ArExtCmd
+#if HasLargeTmp || SystemV4
+#define ArExtCmd ArCmdBase x
+#else
+#define ArExtCmd ArCmdBase xl
+#endif
+#endif
+#ifndef BootstrapCFlags
+#define BootstrapCFlags /**/
+#endif
+#ifndef HasGcc2
+#define HasGcc2 NO
+#endif
+#ifndef HasGcc
+#define HasGcc HasGcc2
+#endif
+#ifndef HasGcc2ForCplusplus
+#define HasGcc2ForCplusplus NO
+#endif
+#ifndef HasCenterLineC
+#define HasCenterLineC NO
+#endif
+#ifndef HasCenterLineCplusplus
+#define HasCenterLineCplusplus NO
+#endif
+#ifndef CcCmd
+#if HasGcc2
+#define CcCmd gcc -fpcc-struct-return 
+#else
+#if HasGcc
+#define CcCmd gcc -fstrength-reduce -fpcc-struct-return 
+#else
+#if HasCenterLineC
+#define CcCmd clcc
+#else
+#define CcCmd cc
+#endif
+#endif
+#endif
+#endif
+#ifndef CplusplusCmd
+#if HasGcc2ForCplusplus
+#define CplusplusCmd g++
+#else
+#define CplusplusCmd CC
+#endif
+#endif
+#ifndef CplusplusFilt
+# define CplusplusFilt c++filt
+#endif
+#ifndef CplusplusLibC
+#define CplusplusLibC /**/
+#endif
+#ifndef CplusplusStandardDefines
+#define CplusplusStandardDefines StandardDefines
+#endif
+#ifndef CplusplusExtraDefines
+#define CplusplusExtraDefines /**/
+#endif
+#ifndef CplusplusExtraIncludes
+#define CplusplusExtraIncludes /**/
+#endif
+#ifndef CplusplusDependIncludes
+#define CplusplusDependIncludes /**/
+#endif
+#ifndef CplusplusOptions
+#define CplusplusOptions /**/
+#endif
+#ifndef CplusplusSpecialOptions
+#define CplusplusSpecialOptions /**/
+#endif
+#if HasFortran
+#ifndef FortranCmd
+#define FortranCmd f77
+#endif
+#ifndef FortranFlags
+#define FortranFlags /**/
+#endif
+#ifndef FortranDebugFlags      /* for -O or -g */
+#define FortranDebugFlags /**/
+#endif
+#endif
+#ifndef AsCmd
+#define AsCmd as
+#endif
+#ifndef CompressCmd
+#define CompressCmd compress
+#endif
+#ifndef GzipCmd
+#define GzipCmd gzip
+#endif
+#ifndef CppCmd
+#define CppCmd /lib/cpp
+#endif
+#ifndef CppNoLineInfoOption
+#define CppNoLineInfoOption /**/
+#endif
+#ifndef PreProcessCmd
+#define PreProcessCmd CcCmd -E
+#endif
+#ifndef InstallCmd             /* hack should be in project */
+#if SystemV || SystemV4
+#ifdef UseInstalled            /* assume BINDIR in path */
+#define InstallCmd bsdinst
+#else
+#define InstallCmd $(SHELL) $(CONFIGSRC)/util/bsdinst.sh
+#endif
+#else
+#define InstallCmd install
+#endif
+#endif
+#ifndef InstallFlags
+#define InstallFlags -c
+#endif
+#ifndef LdCmd
+#define LdCmd ld
+#endif
+#ifndef LexCmd
+#define LexCmd lex
+#endif
+#ifndef LexLib
+#define LexLib -ll
+#endif
+#ifndef YaccCmd
+#define YaccCmd yacc
+#endif
+#ifndef CplusplusYaccCmd
+#define CplusplusYaccCmd YaccCmd
+#endif
+#ifndef LintCmd
+#define LintCmd lint
+#endif
+#ifndef LintLibFlag
+#if SystemV || SystemV4
+#define LintLibFlag -o
+#else
+#define LintLibFlag -C
+#endif
+#endif
+#ifndef LintOpts
+#if SystemV || SystemV4
+#define LintOpts -bh
+#else
+#define LintOpts -axz
+#endif
+#endif
+#ifndef CpCmd
+#define CpCmd cp
+#endif
+#ifndef LnCmd /* can use cp instead of ln if necessary */
+#if HasSymLinks
+#define LnCmd ln -s
+#else
+#define LnCmd ln
+#endif
+#endif
+#ifndef MakeCmd
+#define MakeCmd make
+#endif
+#ifndef MvCmd
+#define MvCmd mv -f
+#endif
+#ifndef RanlibCmd
+#define RanlibCmd ranlib
+#endif
+#ifndef RanlibInstFlags
+#define RanlibInstFlags /**/
+#endif
+#ifndef RmCmd
+#define RmCmd rm -f
+#endif
+#ifndef StandardIncludes       /* for platform-specifics */
+#define StandardIncludes /**/
+#endif
+#ifndef StandardDefines
+#if SystemV
+#define StandardDefines -DSYSV
+#else
+#if SystemV4
+#define StandardDefines -DSVR4
+#else
+#define StandardDefines /**/
+#endif
+#endif
+#endif
+#ifndef StandardCppDefines
+#define StandardCppDefines StandardDefines
+#endif
+#ifndef Malloc0ReturnsNull
+#if UseGnuMalloc
+#define Malloc0ReturnsNull YES
+#else
+#define Malloc0ReturnsNull NO
+#endif
+#endif
+#if Malloc0ReturnsNull
+#ifndef Malloc0ReturnsNullDefines
+#define Malloc0ReturnsNullDefines -DMALLOC_0_RETURNS_NULL
+#endif
+#endif
+#ifndef ToolkitStringsABIOptions
+#define ToolkitStringsABIOptions /**/
+#endif
+#ifndef NdbmDefines
+#if HasNdbm
+#define NdbmDefines -DNDBM
+#else
+#define NdbmDefines /**/
+#endif
+#endif
+#ifndef LdPreLib
+#if !defined(UseInstalled)
+#define LdPreLib -L$(BUILDLIBDIR)
+#else
+#if AlternateUsrLibDir
+#define LdPreLib -L$(USRLIBDIR)
+#else
+#define LdPreLib /**/
+#endif
+#endif
+#endif
+#ifndef LdPostLib
+#if !defined(UseInstalled) && AlternateUsrLibDir && !HasLdRunPath
+#define LdPostLib -L$(USRLIBDIR)
+#else
+#define LdPostLib /**/
+#endif
+#endif
+#ifndef MathLibrary
+#define MathLibrary -lm
+#endif
+#ifndef DBMLibrary
+#define DBMLibrary -ldbm
+#endif
+#ifndef DlLibrary
+#define DlLibrary -ldl
+#endif
+#ifndef ExtraLibraries
+#if SystemV4
+#if HasSockets
+#define ExtraLibraries -lsocket -lnsl -lw
+#else
+#define ExtraLibraries -lnsl -lw
+#endif
+#else
+#define ExtraLibraries /**/
+#endif
+#endif
+#ifndef ExtraLoadOptions
+#define ExtraLoadOptions /**/
+#endif
+#ifndef ExtraLoadFlags
+#define ExtraLoadFlags /**/
+#endif
+#ifndef LdCombineFlags
+#if SystemV4
+#define LdCombineFlags -r
+#else
+#define LdCombineFlags -X -r
+#endif
+#endif
+#ifndef LdStripFlags
+#define LdStripFlags -x
+#endif
+#ifndef TagsCmd
+#define TagsCmd ctags
+#endif
+#ifndef LoaderLibPrefix
+#define LoaderLibPrefix /**/
+#endif
+#ifndef ImakeCmd
+#ifdef UseInstalled            /* assume BINDIR in path */
+#define ImakeCmd imake
+#else
+#define ImakeCmd $(IMAKESRC)/imake
+#endif
+#endif
+#ifndef DependCmd
+#if UseGccMakeDepend
+#ifdef UseInstalled            /* assume BINDIR in path */
+#define DependCmd gccmakedep
+#else
+#define DependCmd $(DEPENDSRC)/gccmakedep
+#endif
+#else
+#ifdef UseInstalled            /* assume BINDIR in path */
+#define DependCmd makedepend
+#else
+#define DependCmd $(DEPENDSRC)/makedepend
+#endif
+#endif
+#endif
+#ifndef DependFlags
+#define DependFlags /**/
+#endif
+#ifndef DependFileName
+#if !HasBsdMake
+#define DependFileName Makefile.dep
+#else
+#define DependFileName .depend
+#endif
+#endif
+#ifndef ExportListCmd
+# ifndef ExportListGenSource
+#  define ExportListCmd                /**/
+# elif !defined(UseInstalled)
+#  define ExportListCmd                $(CONFIGSRC)/util/exportlistgen
+# else
+#  define ExportListCmd                exportlistgen
+# endif
+#endif
+#ifndef MkdirHierCmd
+#ifdef UseInstalled            /* assume BINDIR in path */
+#define MkdirHierCmd mkdirhier
+#else
+#define MkdirHierCmd $(SHELL) $(CONFIGSRC)/util/mkdirhier.sh
+#endif
+#endif
+#ifndef TroffCmd
+#define TroffCmd psroff
+#endif
+#ifndef NroffCmd
+#define NroffCmd nroff
+#endif
+#ifndef MsMacros
+#define MsMacros -ms
+#endif
+#ifndef ManMacros
+#define ManMacros -man
+#endif
+#ifndef TblCmd
+#define TblCmd tbl
+#endif
+#ifndef EqnCmd
+#define EqnCmd eqn
+#endif
+#ifndef NeqnCmd
+#define NeqnCmd neqn
+#endif
+#ifndef ColCmd
+#define ColCmd col
+#endif
+#ifndef DvipsCmd
+#define DvipsCmd dvips
+#endif
+#ifndef LatexCmd
+#define LatexCmd latex
+#endif
+#if HasSentinel
+#ifndef SentinelCmd
+#define SentinelCmd sentinel
+#endif
+#ifndef SentinelOptions
+#define SentinelOptions /**/
+#endif
+#endif
+#if HasPurify
+#ifndef PurifyCmd
+#define PurifyCmd purify
+#endif
+#ifndef PurifyOptions
+#define PurifyOptions /**/
+#endif
+#endif
+#if HasTestCenter
+#ifndef ProofCmd
+#define ProofCmd proof
+#endif
+#ifndef ProofOptions
+#define ProofOptions /**/
+#endif
+#endif
+#ifndef PathSeparator
+#define PathSeparator /
+#endif
+#ifndef Osuf
+#define Osuf o
+#endif
+#ifndef CCsuf
+#define CCsuf cc
+#endif
+#ifndef SHsuf
+#define SHsuf sh
+#endif
+#ifndef ManSuffix
+#define ManSuffix      n               /* use just one tab or cpp will die */
+#endif
+#ifndef LibManSuffix
+#define LibManSuffix   3               /* use just one tab or cpp will die */
+#endif
+#ifndef FileManSuffix
+#if SystemV || SystemV4 || defined(OSF1Architecture)
+#define FileManSuffix  4               /* use just one tab or cpp will die */
+#else
+#define FileManSuffix  5               /* use just one tab or cpp will die */
+#endif
+#endif
+#ifndef ExpandManNames
+#if SystemV
+#define ExpandManNames NO
+#else
+#define ExpandManNames YES
+#endif
+#endif
+#ifndef TOPDIR
+#define TOPDIR .
+#endif
+#ifndef CURDIR
+#define CURDIR .
+#endif
+#ifndef SiteIConfigFiles
+#define SiteIConfigFiles /**/
+#endif
+#ifndef OtherIConfigFiles
+#define OtherIConfigFiles /**/
+#endif
+#ifndef ExtraFilesToClean
+#define ExtraFilesToClean /**/
+#endif
+#ifndef FilesToClean
+#define FilesToClean *.CKP *.ln *.BAK *.bak *.Osuf core errs ,* *~ *.a .emacs_* tags TAGS make.log MakeOut 
+#endif
+
+          PATHSEP = PathSeparator
+            SHELL = BourneShell
+
+              TOP = TOPDIR
+      CURRENT_DIR = CURDIR
+
+            IMAKE = ImakeCmd
+           DEPEND = DependCmd
+        MKDIRHIER = MkdirHierCmd
+    EXPORTLISTGEN = ExportListCmd
+        CONFIGSRC = ConfigSrc
+         IMAKESRC = $(CONFIGSRC)/imake
+        DEPENDSRC = DependDir
+
+          INCROOT = IncRoot            /* base of where to put header files */
+        USRLIBDIR = UsrLibDir          /* nonshared libraries */
+        VARLIBDIR = VarLibDir          /* xdm runtime files */
+         SHLIBDIR = ShLibDir            /* shared libraries */
+       LINTLIBDIR = LintlibDir         /* lint libraries */
+          MANPATH = ManPath            /* top of manual page tree */
+    MANSOURCEPATH = ManSourcePath      /* prefix for man page sources */
+           MANDIR = ManDir             /* man pages for commands */
+        LIBMANDIR = LibmanDir          /* man pages for library routines */
+       FILEMANDIR = FileManDir         /* man pages for config files */
+
+               AR = ArCmd
+  BOOTSTRAPCFLAGS = BootstrapCFlags    /* set if cpp does not have uniq sym */
+               CC = CcCmd
+               AS = AsCmd
+#if HasFortran
+               FC = FortranCmd
+      FDEBUGFLAGS = FortranDebugFlags
+          FCFLAGS = FortranFlags $(FDEBUGFLAGS)
+#endif
+#if HasCplusplus
+
+.SUFFIXES: .CCsuf
+
+              CXX = CplusplusCmd
+          CXXFILT = CplusplusFilt
+           CXXLIB = CplusplusLibC
+    CXXDEBUGFLAGS = DefaultCplusplusDebugFlags
+CXXDEPENDINCLUDES = CplusplusDependIncludes
+ CXXEXTRA_DEFINES = CplusplusExtraDefines
+CXXEXTRA_INCLUDES = CplusplusExtraIncludes
+   CXXSTD_DEFINES = CplusplusStandardDefines $(CXXPROJECT_DEFINES)
+       CXXOPTIONS = CplusplusOptions
+      CXXINCLUDES = $(INCLUDES) $(TOP_INCLUDES) $(CXXEXTRA_INCLUDES) 
+       CXXDEFINES = $(CXXINCLUDES) $(CXXSTD_DEFINES) $(THREADS_CXXDEFINES) $(CXXEXTRA_DEFINES) $(DEFINES)
+         CXXFLAGS = $(CXXDEBUGFLAGS) $(CXXOPTIONS) $(THREADS_CXXFLAGS) $(CXXDEFINES)
+#endif
+         COMPRESS = CompressCmd
+          GZIPCMD = GzipCmd
+              CPP = CppCmd $(STD_CPP_DEFINES)          /* simple filters */
+    PREPROCESSCMD = PreProcessCmd $(STD_CPP_DEFINES)   /* prefered; mdep */
+          INSTALL = InstallCmd
+     INSTALLFLAGS = InstallFlags
+               LD = LdCmd
+              LEX = LexCmd
+           LEXLIB = LexLib
+             YACC = YaccCmd
+           CCYACC = CplusplusYaccCmd
+             LINT = LintCmd
+      LINTLIBFLAG = LintLibFlag
+         LINTOPTS = LintOpts
+               LN = LnCmd
+             MAKE = MakeCmd
+               MV = MvCmd
+               CP = CpCmd
+#if DoRanlibCmd
+           RANLIB = RanlibCmd
+  RANLIBINSTFLAGS = RanlibInstFlags
+#endif
+               RM = RmCmd
+        MANSUFFIX = ManSuffix          /* suffix for command man pages */
+     LIBMANSUFFIX = LibManSuffix       /* suffix for library man pages */
+    FILEMANSUFFIX = FileManSuffix      /* suffix for config file man pages */
+            TROFF = TroffCmd
+            NROFF = NroffCmd
+         MSMACROS = MsMacros
+        MANMACROS = ManMacros
+              TBL = TblCmd
+              EQN = EqnCmd
+             NEQN = NeqnCmd
+              COL = ColCmd
+#if HasLatex
+            DVIPS = DvipsCmd
+            LATEX = LatexCmd
+#endif
+#if HasSentinel
+         SENTINEL = SentinelCmd
+  SENTINELOPTIONS = SentinelOptions
+#endif
+#if HasPurify
+           PURIFY = PurifyCmd
+    PURIFYOPTIONS = PurifyOptions
+#endif
+#if HasTestCenter
+           PROOF = ProofCmd
+    PROOFOPTIONS = ProofOptions
+#endif
+     STD_INCLUDES = StandardIncludes
+  STD_CPP_DEFINES = StandardCppDefines $(PROJECT_DEFINES)
+      STD_DEFINES = StandardDefines $(PROJECT_DEFINES)
+ EXTRA_LOAD_FLAGS = ExtraLoadFlags
+  EXTRA_LDOPTIONS = ExtraLoadOptions
+  EXTRA_LIBRARIES = MallocLibraries ExtraLibraries Krb5Libraries
+             TAGS = TagsCmd
+#if ConstructMFLAGS
+           MFLAGS = -$(MAKEFLAGS)
+#endif
+#if ConstructMAKEFLAGS
+        MAKEFLAGS = $(MFLAGS)
+#endif
+   PARALLELMFLAGS = ParallelMakeFlags
+#if HasSharedLibraries
+    SHAREDCODEDEF = SharedCodeDef
+         SHLIBDEF = SharedLibraryDef
+#ifdef SharedLibraryLoadFlags
+     SHLIBLDFLAGS = SharedLibraryLoadFlags
+#endif
+/*
+ * Here we set up flags needed to produce position-independent code 
+ * when doing C and C++ compilation.  The default if you specify C
+ * PIC flags without also specifying C++ PIC flags is to assume that 
+ * the C flags work for both.  If your C++ compiler requires different
+ * flags, specify them explicitly in PositionIndependentCplusplusFlags.
+ */
+#ifdef PositionIndependentCFlags
+         PICFLAGS = PositionIndependentCFlags
+#endif
+#ifdef PositionIndependentCplusplusFlags
+      CXXPICFLAGS = PositionIndependentCplusplusFlags
+#else
+#ifdef PositionIndependentCFlags
+      CXXPICFLAGS = PositionIndependentCFlags
+#endif
+#endif
+#endif
+#if !HasVoidSignalReturn
+   SIGNAL_DEFINES = -DSIGNALRETURNSINT
+#endif
+/*
+ * The following supports forcing of function prototypes
+ */
+#if NeedFunctionPrototypes && NeedVarargsPrototypes && NeedConstPrototypes && NeedNestedPrototypes
+#define _funcprotodef -DFUNCPROTO=15
+#else
+#if NeedFunctionPrototypes && NeedVarargsPrototypes && NeedNestedPrototypes
+#define _funcprotodef -DFUNCPROTO=11
+#else
+#if NeedFunctionPrototypes && NeedNestedPrototypes
+#define _funcprotodef -DFUNCPROTO=9
+#else
+#if NeedFunctionPrototypes && NeedVarargsPrototypes && NeedConstPrototypes
+#define _funcprotodef -DFUNCPROTO=7
+#else
+#if NeedFunctionPrototypes && NeedConstPrototypes
+#define _funcprotodef -DFUNCPROTO=5
+#else
+#if NeedFunctionPrototypes && NeedVarargsPrototypes
+#define _funcprotodef -DFUNCPROTO=3
+#else
+#if NeedFunctionPrototypes
+#define _funcprotodef -DFUNCPROTO
+#else
+#define _funcprotodef /**/
+#endif
+#endif
+#endif
+#endif
+#endif
+#endif
+#endif
+#if NeedWidePrototypes
+#define _wideprotodef /**/
+#else
+#define _wideprotodef -DNARROWPROTO
+#endif
+    PROTO_DEFINES = _funcprotodef _wideprotodef 
+#undef _funcprotodef
+#undef _wideprotodef
+
+#if StripInstalledPrograms
+     INSTPGMFLAGS = InstPgmFlags       /* install flags for stripping */
+#else
+     INSTPGMFLAGS = 
+#endif
+     INSTBINFLAGS = InstBinFlags       /* install flags for programs */
+     INSTUIDFLAGS = InstUidFlags       /* install flags for setuid programs */
+     INSTLIBFLAGS = InstLibFlags       /* install flags for libraries */
+     INSTINCFLAGS = InstIncFlags       /* install flags for headers */
+     INSTMANFLAGS = InstManFlags       /* install flags for man pages */
+     INSTDATFLAGS = InstDatFlags       /* install flags for data files */
+    INSTKMEMFLAGS = InstKmemFlags      /* install flags for /dev/kmem progs */
+
+#ifdef ProjectRoot
+      PROJECTROOT = ProjectRoot
+#endif
+#ifdef UseInstalled
+# if AlternateIncRoot
+#  define TopInclude   -I$(INCROOT)
+# else
+#  define TopInclude   /**/
+# endif
+#else
+# define TopInclude    -I$(TOP)
+#endif
+      CDEBUGFLAGS = DefaultCDebugFlags
+        CCOPTIONS = DefaultCCOptions   /* to distinguish from param flags */
+/*
+ * STD_INCLUDES contains system-specific includes
+ * TOP_INCLUDES specifies how to get to /usr/include or its build substitute
+ * EXTRA_INCLUDES contains project-specific includes set in project incfiles
+ * INCLUDES contains client-specific includes set in Imakefile
+ * LOCAL_LDFLAGS contains client-specific ld flags flags set in Imakefile
+ */
+      ALLINCLUDES = $(INCLUDES) $(EXTRA_INCLUDES) $(TOP_INCLUDES) $(STD_INCLUDES)
+       ALLDEFINES = $(ALLINCLUDES) $(STD_DEFINES) $(EXTRA_DEFINES) $(PROTO_DEFINES) $(THREADS_DEFINES) $(DEFINES)
+           CFLAGS = $(CDEBUGFLAGS) $(CCOPTIONS) $(THREADS_CFLAGS) $(ALLDEFINES)
+        LINTFLAGS = $(LINTOPTS) -DLINT $(ALLDEFINES) $(DEPEND_DEFINES)
+         LDPRELIB = LdPreLib
+        LDPOSTLIB = LdPostLib
+        LDOPTIONS = $(CDEBUGFLAGS) $(CCOPTIONS)  $(EXTRA_LDOPTIONS) $(THREADS_LDFLAGS) $(LOCAL_LDFLAGS) $(LDPRELIBS)
+     CXXLDOPTIONS = $(CXXDEBUGFLAGS) $(CXXOPTIONS) $(EXTRA_LDOPTIONS) $(THREADS_CXXLDFLAGS) $(LOCAL_LDFLAGS) $(LDPRELIBS)
+
+           LDLIBS = $(LDPOSTLIBS) $(THREADS_LIBS) $(SYS_LIBRARIES) $(EXTRA_LIBRARIES)
+#if HasBrokenCCForLink
+           CCLINK = LdCmd
+#else
+#if AlternateUsrLibDir && HasLdRunPath
+       CCENVSETUP = LD_RUN_PATH=$(USRLIBDIRPATH)
+           CCLINK = $(CCENVSETUP) $(CC)
+#else
+           CCLINK = $(CC)
+#endif
+#endif
+#if AlternateUsrLibDir && HasLdRunPath
+      CXXENVSETUP = LD_RUN_PATH=$(USRLIBDIRPATH)
+          CXXLINK = $(CXXENVSETUP) $(CXX)
+#else
+          CXXLINK = $(CXX)
+#endif
+     LDSTRIPFLAGS = LdStripFlags
+   LDCOMBINEFLAGS = LdCombineFlags
+      DEPENDFLAGS = DependFlags
+
+XCOMM Not sure this belongs here
+         TKLIBDIR = TkLibDir
+         TKINCDIR = TkIncDir
+        TKLIBNAME = TkLibName
+        TKLIBRARY = TkLibrary
+        TCLLIBDIR = TclLibDir
+        TCLINCDIR = TclIncDir
+       TCLLIBNAME = TclLibName
+       TCLLIBRARY = TclLibrary
+
+        MACROFILE = MacroFile
+           RM_CMD = $(RM)
+
+    IMAKE_DEFINES = /* leave blank, for command line use only */
+#ifdef UseInstalled
+         IRULESRC = $(CONFIGDIR)       /* used in rules file */
+        IMAKE_CMD = $(IMAKE) -DUseInstalled -I$(IRULESRC) $(IMAKE_DEFINES)
+#else
+         IRULESRC = $(CONFIGSRC)/cf
+        IMAKE_CMD = $(IMAKE) -I$(IRULESRC) $(IMAKE_DEFINES)
+#endif
+#if !HasClearmake
+     /* clearmake records relevant defines and flags in the build script,
+       so it knows when they change and we don't need this coarser-level
+       dependency.  We also don't want it, since it prevents sharing if
+       even one config file, say site.def or host.def, changes. */
+     ICONFIGFILES = $(IRULESRC)/Imake.tmpl $(IRULESRC)/X11.tmpl \
+                       $(IRULESRC)/site.def $(IRULESRC)/$(MACROFILE) \
+                       OtherIConfigFiles SiteIConfigFiles $(EXTRA_ICONFIGFILES)
+#endif
+
+#ifndef TopLevelProject
+# define TopLevelProject       X11
+#endif
+#ifndef ProjectRulesFile
+# define ProjectRulesFile      Concat3(<,TopLevelProject,.rules>)
+#endif
+#include ProjectRulesFile
+#ifndef LocalRulesFile
+/* need this to make ANSI-style preprocessors happy */
+#define LocalRulesFile <noop.rules>
+#endif
+#include LocalRulesFile
+
+/*
+ * get project-specific configuration and rules
+ */
+#ifndef ProjectTmplFile
+#define ProjectTmplFile                Concat3(<,TopLevelProject,.tmpl>)
+#endif
+#include ProjectTmplFile
+#ifndef LocalTmplFile
+/* need this to make ANSI-style preprocessors happy */
+#define LocalTmplFile <noop.rules>
+#endif
+#include LocalTmplFile
+
+#ifdef FixupLibReferences
+FixupLibReferences()
+#endif
+
+/* ConfigDir comes from X11.tmpl */
+        CONFIGDIR = ConfigDir          /* build configuration information */
+#if HasClearmake
+           OSNAME = OSName
+#endif
+    USRLIBDIRPATH = UsrLibDirPath
+        LDPRELIBS = LdPreLibs
+       LDPOSTLIBS = LdPostLibs
+     TOP_INCLUDES = TopIncludes
+  PROJECT_DEFINES = ProjectDefines
+#if HasCplusplus
+CXXPROJECT_DEFINES = CplusplusProjectDefines
+#endif
+
+XCOMM ----------------------------------------------------------------------
+XCOMM start of Imakefile
+#include INCLUDE_IMAKEFILE
+
+XCOMM ----------------------------------------------------------------------
+XCOMM common rules for all Makefiles - do not edit
+
+.c.i:
+       CPPOnlyCompile($*.c,$(_NOOP_))
+/*
+ * These need to be here so that rules in Imakefile occur first;  the blank
+ * emptyrule is to make sure that an empty Imakefile does not default to make
+ * clean.
+ */
+emptyrule::
+
+CleanTarget()
+
+#ifndef IHaveSpecialMakefileTarget
+MakefileTarget()
+#endif
+
+TagsTarget()
+#ifdef MakefileAdditions
+MakefileAdditions()
+#endif
+
+CenterLoadTarget(debug_src,$(SRCS),NullParameter,$(ALLDEFINES))
+
+CenterLoadTarget(debug_obj,$(OBJS),NullParameter,$(ALLDEFINES))
+
+ManKeywordsTarget($(MANPATH))
+
+#ifdef IHaveSubdirs
+XCOMM ----------------------------------------------------------------------
+XCOMM rules for building in SUBDIRS - do not edit
+
+InstallSubdirs($(SUBDIRS))
+InstallManSubdirs($(SUBDIRS))
+InstallLinkKitSubdirs($(SUBDIRS))
+CleanSubdirs($(SUBDIRS))
+TagSubdirs($(SUBDIRS))
+MakefileSubdirs($(SUBDIRS))
+IncludesSubdirs($(SUBDIRS))
+
+#endif
+
+/* must be after all install.man rules that install anything */
+#if MakeManKeywords            /* typically only at top level */
+install.man:: man_keywords
+#endif
+
+#ifndef IHaveSubdirs
+XCOMM ----------------------------------------------------------------------
+XCOMM empty rules for directories that do not have SUBDIRS - do not edit
+
+install::
+       @echo "install in $(CURRENT_DIR) done"
+
+install.man::
+       @echo "install.man in $(CURRENT_DIR) done"
+
+install.linkkit::
+       @echo "install.linkkit in $(CURRENT_DIR) done"
+
+Makefiles::
+
+includes::
+
+depend::
+
+#endif /* if subdirectory rules are needed */
+
+XCOMM ----------------------------------------------------------------------
+XCOMM dependencies generated by makedepend
+IncludeMakefile(DependFileName)
diff --git a/Xserver/config/cf/Imakefile b/Xserver/config/cf/Imakefile
new file mode 100644 (file)
index 0000000..4dfd0db
--- /dev/null
@@ -0,0 +1,142 @@
+XCOMM $XConsortium: Imakefile /main/38 1996/11/07 14:43:46 kaleb $
+XCOMM $XFree86: xc/config/cf/Imakefile,v 3.13.2.2 1997/07/27 02:41:03 dawes Exp $
+
+XCOMM Some compilers generate fatal errors if an -L directory does
+XCOMM not exist.  Since BUILDLIBDIR may not exist yet suppress its use.
+         LDPRELIB =
+        LDPRELIBS =
+
+#ifdef LocalConfigFiles
+LOCALFILES = LocalConfigFiles
+#endif
+
+#ifndef InstallEmptyHostDef
+HOSTDEFFILES = \
+host.def
+#endif
+
+DEFFILES = \
+xf86site.def \
+$(HOSTDEFFILES) \
+site.def
+
+RULEFILES = \
+Imake.rules \
+Motif.rules \
+Win32.rules \
+X11.rules \
+bsdLib.rules \
+cde.rules \
+hpLib.rules \
+ibmLib.rules \
+lnxLib.rules \
+lnxdoc.rules \
+necLib.rules \
+noop.rules \
+oldlib.rules \
+os2.rules \
+os2Lib.rules \
+os2Lib.rules \
+osfLib.rules \
+scoLib.rules \
+sgiLib.rules \
+sunLib.rules \
+sv3Lib.rules \
+sv4Lib.rules \
+xf86.rules
+
+TMPLFILES = \
+Imake.tmpl \
+Library.tmpl \
+Motif.tmpl \
+Server.tmpl \
+ServerLib.tmpl \
+Threads.tmpl \
+WinLib.tmpl \
+X11.tmpl \
+bsdLib.tmpl \
+cde.tmpl \
+hpLib.tmpl \
+ibmLib.tmpl \
+lnxLib.tmpl \
+lnxdoc.tmpl \
+necLib.tmpl \
+os2Lib.tmpl \
+osfLib.tmpl \
+sgiLib.tmpl \
+sunLib.tmpl \
+sv3Lib.tmpl \
+sv4Lib.tmpl \
+xf86.tmpl
+
+CFFILES = \
+Imake.cf \
+Amoeba.cf \
+DGUX.cf \
+FreeBSD.cf \
+Mips.cf \
+NetBSD.cf \
+OpenBSD.cf \
+Oki.cf \
+Win32.cf \
+apollo.cf \
+bsd.cf \
+bsdi.cf \
+convex.cf \
+cray.cf \
+fujitsu.cf \
+generic.cf \
+hp.cf \
+ibm.cf \
+isc.cf \
+linux.cf \
+luna.cf \
+macII.cf \
+mach.cf \
+minix.cf \
+moto.cf \
+ncr.cf \
+nec.cf \
+os2.cf \
+osf1.cf \
+pegasus.cf \
+sco.cf \
+sco5.cf \
+sequent.cf \
+sgi.cf \
+sony.cf \
+sun.cf \
+svr3.cf \
+svr4.cf \
+ultrix.cf \
+usl.cf \
+lynx.cf \
+x386.cf \
+xfree86.cf
+
+INSTFILES = $(RULEFILES) $(TMPLFILES) $(DEFFILES) $(CFFILES) $(LOCALFILES)
+
+all::
+
+InstallMultipleDestFlags(install,$(INSTFILES),$(CONFIGDIR),$(INSTDATFLAGS))
+InstallLinkKitMultipleDestFlags($(INSTFILES),$(LINKKITDIR)/config/cf,$(INSTDATFLAGS))
+
+#ifdef InstallEmptyHostDef
+install::
+       @(TMP=/tmp/tmp.$$$$; \
+       RemoveFile($${TMP}); \
+       echo "" > $${TMP}; \
+       $(INSTALL) $(INSTALLFLAGS) $(INSTDATFLAGS) $${TMP} \
+               $(DESTDIR)$(CONFIGDIR)/host.def; \
+       RemoveFile($${TMP}))
+
+#ifdef XFree86Version
+install.linkkit::
+       @(TMP=/tmp/tmp.$$$$; \
+       RemoveFile($${TMP}); \
+       echo "" > $${TMP}; \
+       $(INSTALL) $(INSTALLFLAGS) $(INSTDATFLAGS) $${TMP} \
+               $(DESTDIR)$(LINKKITDIR)/config/cf/host.def; \
+       RemoveFile($${TMP}))
+#endif
+#endif
diff --git a/Xserver/config/cf/Library.tmpl b/Xserver/config/cf/Library.tmpl
new file mode 100644 (file)
index 0000000..ba2445b
--- /dev/null
@@ -0,0 +1,412 @@
+/*
+ * Library imakefile info  - this contains any special redefinitions, etc.
+ * that Imakefiles in the various library subtrees will need.
+ *
+ * Before including this, you must set the following boolean variables:
+ * DoNormalLib, DoSharedLib, DoDebugLib, DoProfileLib
+ *
+ * To get automatic generation of standard rules, also set the variables:
+ * LibName, SoRev, HasSharedData, and optionally HugeLibrary and IncSubdir.
+ *
+ * To suppress installation of the library define LibInstall NO.
+ * To suppress creating (and installing) the library define LibCreate NO.
+ * To suppress installing headers define LibHeaders NO.
+ * Define LargePICTable YES if large (32-bit) PIC tables are needed.
+ */
+
+XCOMM $TOG: Library.tmpl /main/44 1997/04/28 11:47:53 kaleb $
+
+
+
+
+XCOMM $XFree86: xc/config/cf/Library.tmpl,v 3.5.2.1 1997/06/11 12:08:29 dawes Exp $
+
+#ifndef LibraryCplusplusOptions
+# if DoSharedLib && defined(SharedLibraryCplusplusOptions)
+#  define LibraryCplusplusOptions SharedLibraryCplusplusOptions
+# else
+#  define LibraryCplusplusOptions DefaultCplusplusOptions
+# endif
+#endif
+#ifndef LibraryDefines
+# define LibraryDefines StandardDefines
+#endif
+#ifndef LibraryCDebugFlags
+# define LibraryCDebugFlags DefaultCDebugFlags
+#endif
+#ifndef LibraryCplusplusDebugFlags
+# define LibraryCplusplusDebugFlags DefaultCplusplusDebugFlags
+#endif
+#ifndef SeparateSharedCompile
+# define SeparateSharedCompile YES
+#endif
+
+#ifndef CplusplusSource
+# ifndef LibraryCcCmd
+#  if DoSharedLib && defined(SharedLibraryCcCmd)
+#   define LibraryCcCmd SharedLibraryCcCmd
+#  else
+#   define LibraryCcCmd CcCmd
+#  endif
+# endif
+# ifndef LibraryCCOptions
+#  if DoSharedLib && defined(SharedLibraryCCOptions)
+#   define LibraryCCOptions SharedLibraryCCOptions
+#  else
+#   define LibraryCCOptions DefaultCCOptions
+#  endif
+# endif
+
+         CC = LibraryCcCmd
+  CCOPTIONS = LibraryCCOptions
+STD_DEFINES = LibraryDefines $(PROJECT_DEFINES)
+CDEBUGFLAGS = LibraryCDebugFlags
+# if defined(LargePICTable) && LargePICTable && defined(LargePositionIndependentCFlags)
+   PICFLAGS = LargePositionIndependentCFlags
+# endif
+#else
+# ifndef LibraryCplusplusCmd
+#  if DoSharedLib && defined(SharedLibraryCplusplusCmd)
+#   define LibraryCplusplusCmd SharedLibraryCplusplusCmd
+#  else
+#   define LibraryCplusplusCmd CplusplusCmd
+#  endif
+# endif
+# ifndef LibraryCplusplusOptions
+#  if DoSharedLib && defined(SharedLibraryCplusplusOptions)
+#   define LibraryCplusplusOptions SharedLibraryCplusplusOptions
+#  else
+#   define LibraryCplusplusOptions DefaultCplusplusOptions
+#  endif
+# endif
+
+          CXX = LibraryCplusplusCmd
+   CXXOPTIONS = LibraryCplusplusOptions
+  STD_DEFINES = LibraryDefines $(PROJECT_DEFINES)
+CXXDEBUGFLAGS = LibraryCplusplusDebugFlags
+# if defined(LargePICTable) && LargePICTable
+#  ifdef LargePositionIndependentCplusplusFlags
+  CXXPICFLAGS = LargePositionIndependentCplusplusFlags
+#  elif defined(LargePositionIndependentCFlags)
+  CXXPICFLAGS = LargePositionIndependentCFlags
+#  endif
+# endif
+#endif
+
+LIB_MT_DEFINES = LibraryMTDefines
+
+#if defined(IHaveSubdirs) && HasSymLinks
+#define _LibMkdir LibMkdirLinkSubdirs
+#else
+#define _LibMkdir LibMkdir
+#endif
+
+#if DoDebugLib
+# define _DebuggedLibMkdir() _LibMkdir(debugger)
+# define _DebuggedObjCompile(options) DebuggedLibObjCompile(options)
+# define _DebuggedObjCplusplusCompile(options) DebuggedLibObjCplusplusCompile(options)
+# define _DebuggedCleanDir() LibCleanDir(debugger)
+#else
+# define _DebuggedLibMkdir() $(_NULLCMD_)
+# define _DebuggedObjCompile(options) $(_NULLCMD_)
+# define _DebuggedObjCplusplusCompile(options) $(_NULLCMD_)
+# define _DebuggedCleanDir() $(_NULLCMD_)
+#endif
+
+#if DoProfileLib
+# define _ProfiledLibMkdir() _LibMkdir(profiled)
+# define _ProfiledObjCompile(options) ProfiledLibObjCompile(options)
+# define _ProfiledObjCplusplusCompile(options) ProfiledLibObjCplusplusCompile(options)
+# define _ProfiledCleanDir() LibCleanDir(profiled)
+#else
+# define _ProfiledLibMkdir() $(_NULLCMD_)
+# define _ProfiledObjCompile(options) $(_NULLCMD_)
+# define _ProfiledObjCplusplusCompile(options) $(_NULLCMD_)
+# define _ProfiledCleanDir() $(_NULLCMD_)
+#endif
+
+#if !DoNormalLib
+# define _NormalLibMkdir() $(_NULLCMD_)
+# define _NormalObjCompile(options) $(_NULLCMD_)
+# define _NormalObjCplusplusCompile(options) $(_NULLCMD_)
+# define _NormalCleanDir() $(_NULLCMD_)
+#else
+# if DoSharedLib && SeparateSharedCompile
+#  define _NormalLibMkdir() _LibMkdir(unshared)
+#  define _NormalObjCompile(options) UnsharedLibObjCompile(options)
+#  define _NormalObjCplusplusCompile(options) UnsharedLibObjCplusplusCompile(options)
+#  define _NormalCleanDir() LibCleanDir(unshared)
+# else
+#  define _NormalLibMkdir() $(_NULLCMD_)
+#  define _NormalObjCompile(options) NormalLibObjCompile(options)
+#  define _NormalObjCplusplusCompile(options) NormalLibObjCplusplusCompile(options)
+#  define _NormalCleanDir() $(_NULLCMD_)
+# endif
+#endif
+
+#if !DoSharedLib || (DoNormalLib && !SeparateSharedCompile)
+# define _SharedObjCompile(options) $(_NULLCMD_)
+# define _SharedObjCplusplusCompile(options) $(_NULLCMD_)
+#else
+# if SeparateSharedCompile
+#  define _SharedObjCompile(options) NormalSharedLibObjCompile(options)
+#  define _SharedObjCplusplusCompile(options) NormalSharedLibObjCplusplusCompile(options)
+#else
+# define _SharedObjCompile(options) NormalLibObjCompile(options)
+# define _SharedObjCplusplusCompile(options) NormalLibObjCplusplusCompile(options)
+#endif
+#endif
+
+#ifndef CplusplusSource
+# define SRCsuf c
+#else
+# define SRCsuf CCsuf
+# ifdef SunArchitecture
+.SUFFIXES: .CCsuf
+# endif
+#endif
+
+#define _CompileObj(target, options)                                   @@\
+target                                                                 @@\
+       _DebuggedObjCompile(options)                                    @@\
+       _ProfiledObjCompile(options)                                    @@\
+       _NormalObjCompile(options)                                      @@\
+       _SharedObjCompile(options)
+
+#ifdef CplusplusSource
+# define _CompileObjCplusplus(target, options)                         @@\
+target                                                                 @@\
+       _DebuggedObjCplusplusCompile(options)                           @@\
+       _ProfiledObjCplusplusCompile(options)                           @@\
+       _NormalObjCplusplusCompile(options)                             @@\
+       _SharedObjCplusplusCompile(options)
+#else
+# define _CompileObjCplusplus(target, options)
+#endif
+
+#ifndef LibraryObjectRule
+# define LibraryObjectRule()                                           @@\
+all::                                                                  @@\
+       _DebuggedLibMkdir()                                             @@\
+       _ProfiledLibMkdir()                                             @@\
+       _NormalLibMkdir()                                               @@\
+                                                                       @@\
+includes::                                                             @@\
+       _DebuggedLibMkdir()                                             @@\
+       _ProfiledLibMkdir()                                             @@\
+       _NormalLibMkdir()                                               @@\
+                                                                       @@\
+_CompileObj(.c.Osuf:,$(_NOOP_))                                                @@\
+_CompileObjCplusplus(.SRCsuf.Osuf:,$(_NOOP_))                          @@\
+                                                                       @@\
+clean::                                                                        @@\
+       _DebuggedCleanDir()                                             @@\
+       _ProfiledCleanDir()                                             @@\
+       _NormalCleanDir()                                               @@\
+
+#endif /* LibraryObjectRule */
+
+#ifndef SpecialLibObjectRule
+# define SpecialLibObjectRule(objs,depends,options)                    @@\
+_CompileObj(objs: depends,options)
+#endif /* SpecialLibObjectRule */
+
+#ifndef SpecialCLibObjectRule
+# define SpecialCLibObjectRule(basename,depends,options)               @@\
+_CompileObj(basename.Osuf: basename.SRCsuf depends,options)            @@\
+                                                                       @@\
+basename.i: basename.SRCsuf depends                                    @@\
+       CPPOnlyCompile(basename.SRCsuf,options)                         @@\
+                                                                       @@\
+CenterLoadTarget(debug_src,basename.SRCsuf,NullParameter,$(ALLDEFINES) options)
+#endif /* SpecialCLibObjectRule */
+
+#ifndef SpecialCplusplusLibObjectRule
+# define SpecialCplusplusLibObjectRule(basename,depends,options)       @@\
+_CompileObjCplusplus(basename.Osuf: basename.SRCsuf depends,options)   @@\
+                                                                       @@\
+CenterLoadTarget(debug_src,basename.SRCsuf,NullParameter,$(ALLDEFINES) options)
+#endif /* SpecialCplusplusLibObjectRule */
+
+/*
+ * ToolkitMakeStrings generates a string-table, i.e., a C source
+ * file and the matching header(s), e.g., Xt's StringDefs.c, StringDefs.h,
+ * and Shell.h files; or Motif's XmStrDefs.c and XmStrDefs.h files.
+ *
+ * The 'files' argument is the list of files that will be produced by
+ * this rule, e.g., for Xt they would be "Shell.h StringDefs.c StringDefs.h"
+ * and for Motif they would be "XmStrDefs.c XmStrDefs.h".
+ *
+ * The 'source' argument is the string-list file to be parsed, e.g., in
+ * Xt that would be "util/string.list".  For Motif 2.0 it would be
+ * "../../tools/makestr/xmstring.list", and for Motif-CDE1 it would be
+ * "util/xmstring.list".
+ *
+ * The 'options' argument is passed by the library's Imakefile, see the
+ * Xt Imakefile for an example.  Typically this would be nothing, -intelabi,
+ * or -sparcabi; there are other choices, but these are typical.
+ *
+ * The 'depends' argument names additional files the target files
+ * depend on.  It should name the #ctmpl and #htmpl files from the
+ * 'source' file.
+ *
+ * The 'dest' argument is the C source output file.  For Xt this should
+ * be "StringDefs.c", and for all versions of Motif it would be "XmStrDefs.c"
+ *
+ * Headers are generated and named according to data in the 'source'
+ * file.
+ */
+/*
+ * The NoCmpScript
+ * prevents clearmake from trying to remake makestrs if it exists.
+ * Including both $(MAKESTRS) and $(MAKESTRS).o as primary targets
+ * prevents clearmake from trying to recompile makestrs from here.
+ * We have includes, not files, depend on makestrs to try to get
+ * clearmake to wink in the files.  Bug in clearmake 2.0.2?
+ */
+
+#ifndef MakeStringsDependency
+# define MakeStringsDependency                                         @@\
+MAKESTRS = $(CONFIGSRC)/util/makestrs                                  @@\
+NoCmpScript(ProgramTargetName($(MAKESTRS)) $(MAKESTRS).Osuf)           @@\
+                                                                       @@\
+ProgramTargetName($(MAKESTRS)) $(MAKESTRS).Osuf:                       @@\
+       cd $(CONFIGSRC)/util && $(MAKE) ProgramTargetName(makestrs)     @@\
+                                                                       @@\
+includes:: ProgramTargetName($(MAKESTRS))
+#endif
+#ifndef ToolkitMakeStrings
+# if defined(LibTookitMakeStringsDependency) && LibTookitMakeStringsDependency
+#  define ToolkitMakeStrings(files,source,options,depends,dest)                @@\
+files: source depends                                                  @@\
+       RemoveFiles(files)                                              @@\
+       RunProgram(MAKESTRS,options < source > dest)                    @@\
+                                                                       @@\
+AllTarget(files)                                                       @@\
+                                                                       @@\
+includes:: files                                                       @@\
+                                                                       @@\
+depend:: files                                                         @@\
+                                                                       @@\
+clean::                                                                        @@\
+       RemoveFiles(files)
+# else
+#  define ToolkitMakeStrings(files,source,options,depends,dest)                @@\
+MakeStringsDependency                                                  @@\
+                                                                       @@\
+files: source depends                                                  @@\
+       RemoveFiles(files)                                              @@\
+       RunProgram(MAKESTRS,options < source > dest)                    @@\
+                                                                       @@\
+AllTarget(files)                                                       @@\
+                                                                       @@\
+includes:: files                                                       @@\
+                                                                       @@\
+depend:: files                                                         @@\
+                                                                       @@\
+clean::                                                                        @@\
+       RemoveFiles(files)
+# endif
+#endif /* ToolkitMakeStrings */
+
+#ifdef LibName
+
+LIBNAME = LibName
+
+# if defined(LibTookitMakeStringsDependency) && LibTookitMakeStringsDependency
+/*
+ * Do ToolkitMakeStrings() before BuildIncludes so makestrs is still
+ * built first, even if the generated header will be installed.
+ */
+MakeStringsDependency
+# endif
+
+LibraryObjectRule()
+
+# undef _LinkBuildLibrary
+# if !defined(LibInstall) || LibInstall
+#  define _LinkBuildLibrary(lib) LinkBuildLibrary(lib)
+# else
+#  define _LinkBuildLibrary(lib) $(_NULLCMD_)
+# endif
+
+# if !defined(LibCreate) || LibCreate
+#  if DoSharedLib
+#   if HugeLibrary && defined(SharedLibraryTarget3)
+SharedLibraryTarget3($(LIBNAME),$(SoRev),$(OBJS1),$(OBJS2),$(OBJS3),.,.)
+#   else
+SharedLibraryTarget($(LIBNAME),$(SoRev),$(OBJS),.,.)
+#   endif
+#   if !defined(LibInstall) || LibInstall
+InstallSharedLibrary($(LIBNAME),$(SoRev),$(SHLIBDIR))
+#   endif
+#   if HasSharedData
+SharedLibraryDataTarget($(LIBNAME),$(SoRev),$(UNSHAREDOBJS))
+#    if !defined(LibInstall) || LibInstall
+InstallSharedLibraryData($(LIBNAME),$(SoRev),$(SHLIBDIR))
+#    endif
+#   endif
+#  endif
+#  if DoNormalLib
+#   if HugeLibrary
+#    if DoSharedLib && SeparateSharedCompile
+UnsharedLibraryTarget3($(LIBNAME),$(OBJS1),$(OBJS2),$(OBJS3),unshared,..)
+#    else
+NormalLibraryTarget3($(LIBNAME),$(OBJS1),$(OBJS2),$(OBJS3))
+#    endif
+#   else
+#    if DoSharedLib && SeparateSharedCompile
+UnsharedLibraryTarget($(LIBNAME),$(OBJS),unshared,..)
+#    else
+NormalLibraryTarget($(LIBNAME),$(OBJS))
+#    endif
+#   endif
+#   if !defined(LibInstall) || LibInstall
+InstallLibrary($(LIBNAME),$(USRLIBDIR))
+#   endif
+#  endif
+#  if DoProfileLib
+ProfiledLibraryTarget($(LIBNAME),$(OBJS))
+#   if !defined(LibInstall) || LibInstall
+InstallLibrary($(LIBNAME)_p,$(USRLIBDIR))
+#   endif
+#  endif
+#  if DoDebugLib
+DebuggedLibraryTarget($(LIBNAME),$(OBJS))
+#   if !defined(LibInstall) || LibInstall
+InstallLibrary($(LIBNAME)_d,$(USRLIBDIR))
+#   endif
+#  endif
+
+LintLibraryTarget($(LIBNAME),$(SRCS))
+#  if !defined(LibInstall) || LibInstall
+InstallLintLibrary($(LIBNAME),$(LINTLIBDIR))
+#  endif
+# else /* not LibCreate */
+#  if HugeLibrary
+AllTarget($(OBJS1))
+AllTarget($(OBJS2))
+AllTarget($(OBJS3))
+#  else
+AllTarget($(OBJS))
+#  endif
+# endif /* LibCreate */
+# ifdef IncSubdir
+#  ifdef IncSubSubdir
+BuildIncludes($(HEADERS),IncSubdir/IncSubSubdir,../..)
+InstallMultipleFlags($(HEADERS),$(INCDIR)/IncSubdir/IncSubSubdir,$(INSTINCFLAGS))
+#  else
+BuildIncludes($(HEADERS),IncSubdir,..)
+InstallMultipleFlags($(HEADERS),$(INCDIR)/IncSubdir,$(INSTINCFLAGS))
+#  endif
+# else
+#  ifndef CplusplusSource
+#   if !defined(LibHeaders) || LibHeaders
+BuildIncludesTop($(HEADERS))
+InstallMultipleFlags($(HEADERS),$(INCDIR),$(INSTINCFLAGS))
+#   endif
+#  endif
+# endif
+
+NormalLintTarget($(SRCS))
+#endif /* defined(LibName) */
diff --git a/Xserver/config/cf/Mips.cf b/Xserver/config/cf/Mips.cf
new file mode 100644 (file)
index 0000000..ad2184a
--- /dev/null
@@ -0,0 +1,72 @@
+/*
+ * Set version numbers before making makefiles.
+ * 
+ * X11r5 only builds using the berkeley libraries and compiler.  Make
+ * sure your path includes /bsd43/bin before /bin/ or /usr/bin.
+ */
+
+#ifndef OSName
+#define OSName            RISCOS
+#endif
+#ifndef OSMajorVersion
+#define OSMajorVersion    4
+#endif
+#ifndef OSMinorVersion
+#define OSMinorVersion    50
+#endif
+
+XCOMM platform:  $XConsortium: Mips.cf /main/17 1996/09/28 16:06:25 rws $
+XCOMM operating system:  OSName
+
+/***************************************************************************
+ *                      Platform-specific parameters                      *
+ ***************************************************************************/
+
+#define HasVoidSignalReturn            NO
+#define SetTtyGroup                    YES
+#define UnalignedReferencesAllowed     NO     /* if arbitrary deref okay */
+#define HasBsearch                     NO
+
+#define MipsArchitecture
+#define MakeEnv -e
+
+#define DefaultCCOptions -signed -systype bsd43 -Olimit 2000 -Wf,-XNd8400,-XNp12000
+#define StandardDefines -DMips -DBSD43
+#define PostIncDir /usr/include/bsd43
+#define ExtraLibraries -lmld
+#define ArCmd ar clr
+#define BootstrapCFlags -DMips
+#define InstallCmd /etc/mipsinstall -f
+#define MakeCmd make MakeEnv
+#define DoRanlibCmd NO
+#define AllocateLocalDefines -DINCLUDE_ALLOCA_H
+
+/***************************************************************************
+ *                                                                         *
+ *                     DEFINE PARAMETERS FOR BUILDING                     *
+ *                                                                         *
+ ***************************************************************************/
+
+#define XmipsServer    YES
+
+/***************************************************************************
+ *                                                                         *
+ *           OVERRIDE ANY CONFIGURATION PARAMETERS FROM Imake.tmpl        *
+ *                                                                         *
+ ***************************************************************************/
+
+#define SpecialMalloc          NO
+
+#define PrimaryScreenResolution        110
+
+#define ConstructMFLAGS        NO              /* build MFLAGS from MAKEFLAGS */
+
+#define DefaultUserPath /usr/net:/bin:/usr/bin:$(BINDIR):/usr/ucb
+#define DefaultSystemPath /usr/net:/bin:/usr/bin:/etc:$(BINDIR):/usr/ucb
+
+/* mips manuals are really complicated.  This certainly won't work. */
+
+#define ManDirectoryRoot /man/cat
+#define ManSourcePath $(MANPATH)/man
+
+#define InstKmemFlags -g sys -m 2711
diff --git a/Xserver/config/cf/Motif.rules b/Xserver/config/cf/Motif.rules
new file mode 100644 (file)
index 0000000..dda9a8b
--- /dev/null
@@ -0,0 +1,709 @@
+/* 
+ *  @OSF_COPYRIGHT@
+ *  COPYRIGHT NOTICE
+ *  Copyright (c) 1990, 1991, 1992, 1993 Open Software Foundation, Inc.
+ *  ALL RIGHTS RESERVED (MOTIF). See the file named COPYRIGHT.MOTIF for
+ *  the full copyright text.
+ *
+ * (c) Copyright 1996 Digital Equipment Corporation.
+ * (c) Copyright 1996 Hewlett-Packard Company.
+ * (c) Copyright 1996 International Business Machines Corp.
+ * (c) Copyright 1996 Sun Microsystems, Inc.
+ * (c) Copyright 1996 Novell, Inc. 
+ * (c) Copyright 1996 FUJITSU LIMITED.
+ * (c) Copyright 1996 Hitachi.
+ */ 
+XCOMM $TOG: Motif.rules /main/3 1997/03/24 09:10:35 mgreess $
+
+/* Note whether we are the top level project. */
+#ifndef SeenTopLevelProject
+# define SeenTopLevelProject   YES
+# define MotifIsTopLevelProject        YES
+#else
+# define MotifIsTopLevelProject        NO
+#endif
+
+/* Include the X11 project rules file. */
+#include <X11.rules>
+
+
+/* Use the in-tree Motif by default. */
+#ifndef UseInstalledMotif
+# define UseInstalledMotif     NO
+#endif
+#ifdef UseInstalled
+# undef UseInstalledMotif
+# define UseInstalledMotif     YES
+#endif
+
+#ifndef ImportMotif
+# ifdef UseImports
+#  define ImportMotif          YES
+# else
+#  define ImportMotif          NO
+# endif
+#endif
+#if UseInstalledMotif
+# undef ImportMotif
+# define ImportMotif           NO
+#endif
+
+#ifndef MSimpleProgramTarget
+#define MSimpleProgramTarget(program)                                   @@\
+AllTarget(program)                                                      @@\
+                                                                       @@\
+program: program.o $(DEPS) $(DEPLIBS)                                  @@\
+       RemoveTargetProgram($@)                                         @@\
+       $(CC) -o $@ program.o $(LDOPTIONS) $(DEPS) $(LOCAL_LIBRARIES) $(LDLIBS) $(EXTRA_LOAD_FLAGS)  @@\
+                                                                       @@\
+clean::                                                                 @@\
+       $(RM) program
+#endif
+
+#ifndef MSimpleUilTarget
+#define MSimpleUilTarget(program)                                       @@\
+MSimpleProgramTarget(program)                                          @@\
+                                                                       @@\
+InstallProgram(program,$(BINDIR))                                      @@\
+                                                                       @@\
+MSimpleUidTarget(program)
+#endif
+
+/*
+ * UILFLAGS contains site/vendor-specific flags
+ * defined by UilFlags, which supposed to be set in *.cf or
+ * site.def files.
+ * LOCAL_UILFLAGS(_n) contains client-specific uil flags set in Imakefile
+ */
+
+#ifndef MSimpleUidTarget
+#define MSimpleUidTarget(program)                                       @@\
+AllTarget(program.uid)                                                  @@\
+                                                                       @@\
+program.uid: program.uil $(DEPUIL)                                      @@\
+       RemoveTargetProgram($@)                                         @@\
+       $(CLIENTENVSETUP) $(UIL) $(UILFLAGS) $(LOCAL_UILFLAGS) -o $@ program.uil $(UIL_INCLUDES)        @@\
+                                                                       @@\
+InstallNonExecFile(program.uid,$(UIDDIR))                               @@\
+                                                                        @@\
+clean::                                                                 @@\
+       $(RM) program.uid
+#endif
+
+#ifndef MSimpleUidLocaleTarget
+#define MSimpleUidLocaleTarget(program,locale)                          @@\
+AllTarget(program.uid)                                                  @@\
+                                                                       @@\
+program.uid: program.uil $(DEPUIL)                                      @@\
+       RemoveTargetProgram($@)                                         @@\
+       $(CLIENTENVSETUP) $(UIL) $(UILFLAGS) $(LOCAL_UILFLAGS) -o $@ program.uil $(UIL_INCLUDES)        @@\
+                                                                       @@\
+InstallNonExecFile(program.uid,$(LIBDIR)/locale/uid)                    @@\
+                                                                        @@\
+clean::                                                                 @@\
+       $(RM) program.uid
+#endif
+
+#ifndef MComplexUidTarget_1
+#define MComplexUidTarget_1(program)                                    @@\
+                                                                       @@\
+AllTarget(program.uid)                                                  @@\
+                                                                       @@\
+program.uid:  $(UILS1) $(DEPUIL)                                        @@\
+       RemoveTargetProgram($@)                                         @@\
+       $(CLIENTENVSETUP) $(UIL) $(UILFLAGS) $(LOCAL_UILFLAGS_1) -o $@ program.uil $(UIL_INCLUDES)      @@\
+                                                                       @@\
+InstallNonExecFile(program.uid,$(UIDDIR))                               @@\
+                                                                        @@\
+clean::                                                                 @@\
+       $(RM) program.uid
+#endif
+
+#ifndef MComplexUidTarget_2
+#define MComplexUidTarget_2(program)                                    @@\
+                                                                       @@\
+AllTarget(program.uid)                                                  @@\
+                                                                       @@\
+program.uid:  $(UILS2) $(DEPUIL)                                        @@\
+       RemoveTargetProgram($@)                                         @@\
+       $(CLIENTENVSETUP) $(UIL) $(UILFLAGS) $(LOCAL_UILFLAGS_2) -o $@ program.uil $(UIL_INCLUDES)      @@\
+                                                                       @@\
+InstallNonExecFile(program.uid,$(UIDDIR))                               @@\
+                                                                        @@\
+clean::                                                                 @@\
+       $(RM) program.uid
+#endif
+
+#ifndef MComplexUidTarget_3
+#define MComplexUidTarget_3(program)                                    @@\
+                                                                       @@\
+AllTarget(program.uid)                                                  @@\
+                                                                       @@\
+program.uid:  $(UILS3) $(DEPUIL)                                        @@\
+       RemoveTargetProgram($@)                                         @@\
+       $(CLIENTENVSETUP) $(UIL) $(UILFLAGS) $(LOCAL_UILFLAGS_3) -o $@ program.uil $(UIL_INCLUDES)      @@\
+                                                                       @@\
+InstallNonExecFile(program.uid,$(UIDDIR))                               @@\
+                                                                        @@\
+clean::                                                                 @@\
+       $(RM) program.uid
+#endif
+
+#ifndef MComplexUidTarget_4
+#define MComplexUidTarget_4(program)                                    @@\
+                                                                       @@\
+AllTarget(program.uid)                                                  @@\
+                                                                       @@\
+program.uid:  $(UILS4) $(DEPUIL)                                        @@\
+       RemoveTargetProgram($@)                                         @@\
+       $(CLIENTENVSETUP) $(UIL) $(UILFLAGS) $(LOCAL_UILFLAGS_4) -o $@ program.uil $(UIL_INCLUDES)      @@\
+                                                                       @@\
+InstallNonExecFile(program.uid,$(UIDDIR))                               @@\
+                                                                        @@\
+clean::                                                                 @@\
+       $(RM) program.uid
+#endif
+
+#ifndef MComplexUidTarget_5
+#define MComplexUidTarget_5(program)                                    @@\
+                                                                       @@\
+AllTarget(program.uid)                                                  @@\
+                                                                       @@\
+program.uid:  $(UILS5) $(DEPUIL)                                        @@\
+       RemoveTargetProgram($@)                                         @@\
+       $(CLIENTENVSETUP) $(UIL) $(UILFLAGS) $(LOCAL_UILFLAGS_5) -o $@ program.uil $(UIL_INCLUDES)      @@\
+                                                                       @@\
+InstallNonExecFile(program.uid,$(UIDDIR))                               @@\
+                                                                        @@\
+clean::                                                                 @@\
+       $(RM) program.uid
+#endif
+
+#ifndef MComplexUidTarget_6
+#define MComplexUidTarget_6(program)                                    @@\
+                                                                       @@\
+AllTarget(program.uid)                                                  @@\
+                                                                       @@\
+program.uid:  $(UILS6) $(DEPUIL)                                        @@\
+       RemoveTargetProgram($@)                                         @@\
+       $(CLIENTENVSETUP) $(UIL) $(UILFLAGS) $(LOCAL_UILFLAGS_6) -o $@ program.uil $(UIL_INCLUDES)      @@\
+                                                                       @@\
+InstallNonExecFile(program.uid,$(UIDDIR))                               @@\
+                                                                        @@\
+clean::                                                                 @@\
+       $(RM) program.uid
+#endif
+
+#ifndef MComplexUidTarget_7
+#define MComplexUidTarget_7(program)                                    @@\
+                                                                       @@\
+AllTarget(program.uid)                                                  @@\
+                                                                       @@\
+program.uid:  $(UILS7) $(DEPUIL)                                        @@\
+       RemoveTargetProgram($@)                                         @@\
+       $(CLIENTENVSETUP) $(UIL) $(UILFLAGS) $(LOCAL_UILFLAGS_7) -o $@ program.uil $(UIL_INCLUDES)      @@\
+                                                                       @@\
+InstallNonExecFile(program.uid,$(UIDDIR))                               @@\
+                                                                        @@\
+clean::                                                                 @@\
+       $(RM) program.uid
+#endif
+
+#ifndef MComplexUidTarget_8
+#define MComplexUidTarget_8(program)                                    @@\
+                                                                       @@\
+AllTarget(program.uid)                                                  @@\
+                                                                       @@\
+program.uid:  $(UILS8) $(DEPUIL)                                        @@\
+       RemoveTargetProgram($@)                                         @@\
+       $(CLIENTENVSETUP) $(UIL) $(UILFLAGS) $(LOCAL_UILFLAGS_8) -o $@ program.uil $(UIL_INCLUDES)      @@\
+                                                                       @@\
+InstallNonExecFile(program.uid,$(UIDDIR))                               @@\
+                                                                        @@\
+clean::                                                                 @@\
+       $(RM) program.uid
+#endif
+
+#ifndef MComplexUidTarget_9
+#define MComplexUidTarget_9(program)                                    @@\
+                                                                       @@\
+AllTarget(program.uid)                                                  @@\
+                                                                       @@\
+program.uid:  $(UILS9) $(DEPUIL)                                        @@\
+       RemoveTargetProgram($@)                                         @@\
+       $(CLIENTENVSETUP) $(UIL) $(UILFLAGS) $(LOCAL_UILFLAGS_9) -o $@ program.uil $(UIL_INCLUDES)      @@\
+                                                                       @@\
+InstallNonExecFile(program.uid,$(UIDDIR))                               @@\
+                                                                        @@\
+clean::                                                                 @@\
+       $(RM) program.uid
+#endif
+
+#ifndef MComplexUidTarget_10
+#define MComplexUidTarget_10(program)                                   @@\
+                                                                       @@\
+AllTarget(program.uid)                                                  @@\
+                                                                       @@\
+program.uid:  $(UILS10) $(DEPUIL)                                       @@\
+       RemoveTargetProgram($@)                                         @@\
+       $(CLIENTENVSETUP) $(UIL) $(UILFLAGS) $(LOCAL_UILFLAGS_10) -o $@ program.uil $(UIL_INCLUDES)     @@\
+                                                                       @@\
+InstallNonExecFile(program.uid,$(UIDDIR))                               @@\
+                                                                        @@\
+clean::                                                                 @@\
+       $(RM) program.uid
+#endif
+
+#ifndef MComplexProgramTarget
+#define        MComplexProgramTarget(program,locallib,syslib)                  @@\
+        PROGRAM = program                                              @@\
+                                                                       @@\
+AllTarget(program)                                                     @@\
+                                                                       @@\
+program: $(OBJS) $(DEPLIBS)                                            @@\
+       RemoveTargetProgram($@)                                         @@\
+       $(CC) -o $@ $(LDOPTIONS) $(OBJS) locallib $(LDLIBS) syslib $(EXTRA_LOAD_FLAGS)  @@\
+                                                                       @@\
+CenterProgramTarget(program,$(SRCS),$(OBJS),locallib,syslib)           @@\
+                                                                       @@\
+InstallProgram(program,$(BINDIR))                                      @@\
+                                                                       @@\
+install.man::                                                          @@\
+       @echo To install documentation for $(PROGRAM), consult the Release Notes        @@\
+       @echo and/or README file in the current directory.              @@\
+DependTarget()                                                         @@\
+LintTarget()                                                           @@\
+                                                                       @@\
+clean::                                                                        @@\
+       $(RM) $(PROGRAM)
+#endif
+
+#ifndef MComplexProgramTarget_1
+#define        MComplexProgramTarget_1(program,locallib,syslib)                @@\
+            OBJS = $(OBJS1) $(OBJS2) $(OBJS3)                          @@\
+            SRCS = $(SRCS1) $(SRCS2) $(SRCS3)                          @@\
+                                                                       @@\
+AllTarget($(PROGRAMS))                                                 @@\
+                                                                       @@\
+program: $(OBJS1) $(DEPLIBS1)                                          @@\
+       RemoveTargetProgram($@)                                         @@\
+       $(CC) -o $@ $(LDOPTIONS) $(OBJS1) locallib $(LDLIBS) syslib $(EXTRA_LOAD_FLAGS) @@\
+                                                                       @@\
+CenterProgramTarget(program,$(SRCS1),$(OBJS1),locallib,syslib)         @@\
+                                                                       @@\
+InstallProgram(program,$(BINDIR))                                      @@\
+                                                                       @@\
+install.man::                                                          @@\
+       @echo To install documentation for $(PROGRAMS), consult the Release Notes       @@\
+       @echo and/or README file in the current directory.              @@\
+DependTarget()                                                         @@\
+LintTarget()                                                           @@\
+                                                                       @@\
+clean::                                                                        @@\
+       $(RM) $(PROGRAMS)
+#endif
+
+#ifndef MComplexProgramTarget_2
+#define        MComplexProgramTarget_2(program,locallib,syslib)                @@\
+program: $(OBJS2) $(DEPLIBS2)                                          @@\
+       RemoveTargetProgram($@)                                         @@\
+       $(CC) -o $@ $(LDOPTIONS) $(OBJS2) locallib $(LDLIBS) syslib $(EXTRA_LOAD_FLAGS) @@\
+                                                                       @@\
+CenterProgramTarget(program,$(SRCS2),$(OBJS2),locallib,syslib)         @@\
+                                                                       @@\
+InstallProgram(program,$(BINDIR))
+#endif
+
+#ifndef MComplexProgramTarget_3
+#define        MComplexProgramTarget_3(program,locallib,syslib)                @@\
+        PROGRAM_3 = program                                    @@\
+program: $(OBJS3) $(DEPLIBS3)                                          @@\
+       RemoveTargetProgram($@)                                         @@\
+       $(CC) -o $@ $(LDOPTIONS) $(OBJS3) locallib $(LDLIBS) syslib $(EXTRA_LOAD_FLAGS) @@\
+                                                                       @@\
+CenterProgramTarget(program,$(SRCS3),$(OBJS3),locallib,syslib)         @@\
+                                                                       @@\
+InstallProgram(program,$(BINDIR))
+#endif
+
+#ifndef MComplexProgramTarget_4
+#define        MComplexProgramTarget_4(program,locallib,syslib)                @@\
+        PROGRAM_4 = program                                    @@\
+program: $(OBJS4) $(DEPLIBS4)                                          @@\
+       RemoveTargetProgram($@)                                         @@\
+       $(CC) -o $@ $(LDOPTIONS) $(OBJS4) locallib $(LDLIBS) syslib $(EXTRA_LOAD_FLAGS) @@\
+                                                                       @@\
+CenterProgramTarget(program,$(SRCS4),$(OBJS4),locallib,syslib)         @@\
+                                                                       @@\
+InstallProgram(program,$(BINDIR))
+#endif
+
+#ifndef MComplexProgramTarget_5
+#define        MComplexProgramTarget_5(program,locallib,syslib)                @@\
+        PROGRAM_5 = program                                    @@\
+program: $(OBJS5) $(DEPLIBS5)                                          @@\
+       RemoveTargetProgram($@)                                         @@\
+       $(CC) -o $@ $(LDOPTIONS) $(OBJS5) locallib $(LDLIBS) syslib $(EXTRA_LOAD_FLAGS) @@\
+                                                                       @@\
+CenterProgramTarget(program,$(SRCS5),$(OBJS5),locallib,syslib)         @@\
+                                                                       @@\
+InstallProgram(program,$(BINDIR))
+#endif
+
+#ifndef MComplexProgramTarget_6
+#define        MComplexProgramTarget_6(program,locallib,syslib)                @@\
+        PROGRAM_6 = program                                    @@\
+program: $(OBJS6) $(DEPLIBS6)                                          @@\
+       RemoveTargetProgram($@)                                         @@\
+       $(CC) -o $@ $(LDOPTIONS) $(OBJS6) locallib $(LDLIBS) syslib $(EXTRA_LOAD_FLAGS) @@\
+                                                                       @@\
+CenterProgramTarget(program,$(SRCS6),$(OBJS6),locallib,syslib)         @@\
+                                                                       @@\
+InstallProgram(program,$(BINDIR))
+#endif
+
+#ifndef MComplexProgramTarget_7
+#define        MComplexProgramTarget_7(program,locallib,syslib)                @@\
+        PROGRAM_7 = program                                    @@\
+program: $(OBJS7) $(DEPLIBS7)                                          @@\
+       RemoveTargetProgram($@)                                         @@\
+       $(CC) -o $@ $(LDOPTIONS) $(OBJS7) locallib $(LDLIBS) syslib $(EXTRA_LOAD_FLAGS) @@\
+                                                                       @@\
+CenterProgramTarget(program,$(SRCS7),$(OBJS7),locallib,syslib)         @@\
+                                                                       @@\
+InstallProgram(program,$(BINDIR))
+#endif
+
+#ifndef MComplexProgramTarget_8
+#define        MComplexProgramTarget_8(program,locallib,syslib)                @@\
+        PROGRAM_8 = program                                    @@\
+program: $(OBJS8) $(DEPLIBS8)                                          @@\
+       RemoveTargetProgram($@)                                         @@\
+       $(CC) -o $@ $(LDOPTIONS) $(OBJS8) locallib $(LDLIBS) syslib $(EXTRA_LOAD_FLAGS) @@\
+                                                                       @@\
+CenterProgramTarget(program,$(SRCS8),$(OBJS8),locallib,syslib)         @@\
+                                                                       @@\
+InstallProgram(program,$(BINDIR))
+#endif
+
+#ifndef MComplexProgramTarget_9
+#define        MComplexProgramTarget_9(program,locallib,syslib)                @@\
+        PROGRAM_9 = program                                    @@\
+program: $(OBJS9) $(DEPLIBS9)                                          @@\
+       RemoveTargetProgram($@)                                         @@\
+       $(CC) -o $@ $(LDOPTIONS) $(OBJS9) locallib $(LDLIBS) syslib $(EXTRA_LOAD_FLAGS) @@\
+                                                                       @@\
+CenterProgramTarget(program,$(SRCS9),$(OBJS9),locallib,syslib)         @@\
+                                                                       @@\
+InstallProgram(program,$(BINDIR))
+#endif
+
+#ifdef AUTOMATION
+#ifndef TestPPTarget
+#define TestPPTarget(root)                                             @@\
+all:: root.Scr root.Dat                                                        @@\
+                                                                       @@\
+root.Dat: root.dat                                                     @@\
+       $(RM) root.Dat                                                  @@\
+       $(COMMONPP) $(DEFINES) root.dat                                 @@\
+root.Scr: root.scr                                                     @@\
+       $(RM) root.Scr                                                  @@\
+       $(COMMONPP) $(DEFINES) root.scr
+#endif 
+#else
+#ifndef TestPPTarget
+#define TestPPTarget(root)                                              @@\
+all:: root.Dat                                                          @@\
+                                                                        @@\
+root.Dat: root.dat                                                      @@\
+       $(RM) root.Dat                                                  @@\
+       $(COMMONPP) $(DEFINES) root.dat
+#endif
+#endif
+
+#ifdef AUTOMATION
+#ifndef TestPPTargetScr
+#define TestPPTargetScr(root)                                           @@\
+all:: root.Scr                                                          @@\
+                                                                        @@\
+root.Scr: root.scr                                                     @@\
+       $(RM) root.Scr                                                  @@\
+       $(COMMONPP) $(DEFINES) root.scr
+#endif
+#else
+#ifndef TestPPTargetScr
+#define TestPPTargetScr(root)  /**/
+#endif
+#endif
+
+#ifdef AUTOMATION
+#ifndef TestPPTargetDat
+#define TestPPTargetDat(root)                                              @@\
+all:: root.Dat                                                          @@\
+                                                                        @@\
+root.Dat: root.dat                                                      @@\
+       $(RM) root.Dat                                                  @@\
+       $(COMMONPP) $(DEFINES) root.dat
+#endif
+#endif
+#ifndef AUTOMATION
+#ifndef TestPPTargetDat
+#define TestPPTargetDat(root)                                              @@\
+all:: root.Dat                                                          @@\
+                                                                        @@\
+root.Dat: root.dat                                                      @@\
+       $(RM) root.Dat                                                  @@\
+       $(COMMONPP) $(DEFINES) root.dat
+#endif
+#endif
+
+
+#ifndef NO_AUTOMATION
+#ifndef RunTarget
+#define RunTarget()                                                    @@\
+all::  RUN                                                             @@\
+                                                                       @@\
+RUN:   always                                                          @@\
+       $(GENRUN) $(CURRENT_DIR) $(MTOP) $(DEFINES)                     @@\
+                                                                       @@\
+always:                                                                @@\
+       $(RM) RUN
+#endif
+#else
+#ifdef UseVista
+#ifndef RunTarget
+#define RunTarget()                                                    @@\
+all::  RUN                                                             @@\
+                                                                       @@\
+RUN:   always                                                          @@\
+       $(MANRUN) $(CURRENT_DIR) $(MTOP) $(DEFINES)                     @@\
+                                                                       @@\
+always:                                                                @@\
+       $(RM) RUN
+#endif
+#else
+#ifdef UsePurify
+#ifndef RunTarget
+#define RunTarget()                                                    @@\
+all::  RUN                                                             @@\
+                                                                       @@\
+RUN:   always                                                          @@\
+       $(MANRUN) $(CURRENT_DIR) $(MTOP) $(DEFINES)                     @@\
+                                                                       @@\
+always:                                                                @@\
+       $(RM) RUN
+#endif
+#else
+#ifndef RunTarget
+#define RunTarget()                                                    @@\
+all::  RUN                                                             @@\
+                                                                       @@\
+RUN:   always                                                          @@\
+                                                                       @@\
+always:                                                                @@\
+
+#endif
+#endif
+#endif
+#endif
+#ifdef UseVista
+#ifndef VistaMapRule
+#define VistaMapRule(targetmap,depend)                                 @@\
+all:: targetmap                                                                @@\
+                                                                       @@\
+targetmap: depend                                                      @@\
+       $(RM) $(MTOP)/tests/Vista/targetmap                             @@\
+       CATCMD *.M > $(MTOP)/tests/Vista/targetmap
+#endif
+#ifndef ComplexVistaMapRule
+#define ComplexVistaMapRule(program,filelist)                          @@\
+all::  program.M                                                       @@\
+                                                                       @@\
+program.M: filelist                                                    @@\
+       $(RM) program.vista.tmpfile                                     @@\
+       touch program.vista.tmpfile                                     @@\
+       @case '${MFLAGS}' in *[ik]*) set +e;; esac;                     @@\
+       @for i in filelist; do \                                        @@\
+               cat `basename $$i .o`.M >> program.vista.tmpfile ; done @@\
+       $(RM) program.M                                                 @@\
+       $(MV) program.vista.tmpfile program.M                           @@\
+                                                                       @@\
+clean::                                                                        @@\
+       $(RM) *.M
+#endif
+
+#endif
+
+/*  Rule for making shadow trees.      */
+#ifndef MakeShadowTree
+#define MakeShadowTree(name,dirs)                      @@\
+all::                                                  @@\
+       @case '${MFLAGS}' in *[ik]*) set +e;; esac;     @@\
+       MakeDir(name)                                   @@\
+       @for i in dirs; \                               @@\
+        do if [ -d $$i/name ]; then \                  @@\
+        exit 0; else set -x; mkdir $$i/name; fi \      @@\
+       done                                            @@\
+       @for i in dirs; \                               @@\
+       do if [ -r name/$$i ]; then \                   @@\
+               set +x; \                               @@\
+               else (set -x; $(LN) ../$$i/name  name/$$i); fi \@@\
+       done
+#endif
+
+#ifdef BuildPlusPlus
+
+/* Rules for C++ */
+
+/*
+ * "CPlusPlusObjectCompile" - compile fragment for a normal C++ object file
+*/
+#ifndef CPlusPlusObjectCompile
+#define CPlusPlusObjectCompile(options) $(RM) $@                       @@\
+       $(CPLUSPLUSCOM) -c $(CPLUSPLUSFLAGS) options $*.cxx
+#endif
+
+#ifndef CPlusPlusObjectRule
+#define CPlusPlusObjectRule()                                          @@\
+.cxx.o:                                                                        @@\
+       CPlusPlusObjectCompile($(_NOOP_))
+#endif /* CPlusPlusObjectRule */
+
+#ifndef MCPlusPlusSimpleProgramTarget
+#define MCPlusPlusSimpleProgramTarget(program)                          @@\
+AllTarget(program)                                                      @@\
+                                                                       @@\
+program: program.o $(DEPS) $(DEPLIBS)                                  @@\
+       RemoveTargetProgram($@)                                         @@\
+       $(CPLUSPLUSLINKCOM) -o $@ program.o $(LDOPTIONS) $(DEPS) $(LOCAL_LIBRARIES) $(CPLUSPLUSLIBS) $(LDLIBS) $(EXTRA_LOAD_FLAGS)  @@\
+                                                                       @@\
+clean::                                                                 @@\
+       $(RM) program
+#endif
+
+#ifndef MCPlusPlusComplexProgramTarget
+#define        MCPlusPlusComplexProgramTarget(program,locallib,syslib)         @@\
+        PROGRAM = program                                              @@\
+                                                                       @@\
+AllTarget(program)                                                     @@\
+                                                                       @@\
+program: $(OBJS) $(DEPLIBS)                                            @@\
+       RemoveTargetProgram($@)                                         @@\
+       $(CPLUSPLUSLINKCOM) -o $@ $(LDOPTIONS) $(OBJS) locallib $(CPLUSPLUSLIBS) $(LDLIBS) syslib $(EXTRA_LOAD_FLAGS)   @@\
+                                                                       @@\
+CenterProgramTarget(program,$(SRCS),$(OBJS),locallib,syslib)           @@\
+                                                                       @@\
+InstallProgram(program,$(BINDIR))                                      @@\
+                                                                       @@\
+install.man::                                                          @@\
+       @echo To install documentation for $(PROGRAM), consult the Release Notes        @@\
+       @echo and/or README file in the current directory.              @@\
+DependTarget()                                                         @@\
+LintTarget()                                                           @@\
+                                                                       @@\
+clean::                                                                        @@\
+       $(RM) $(PROGRAM)
+#endif
+
+#endif /* BuildPlusPlus */
+
+/* Rules for message catalog building */
+#ifndef Real_MessageCatalogRule
+#define Real_MessageCatalogRule(prefix)                                        @@\
+prefix.cat Concat(prefix,MsgCatI.h):                                   @@\
+       $(RM) Concat(prefix,MsgCatI.h) prefix.cat $(MLOCSRC)/C/msg/prefix.msg   @@\
+       $(MKCATTOOL) Concat(prefix,MsgCatI.h) prefix.msg > $(MLOCSRC)/C/msg/prefix.msg  @@\
+       $(GENCAT) prefix.cat $(MLOCSRC)/C/msg/prefix.msg                @@\
+                                                                       @@\
+includes:: prefix.cat Concat(prefix,MsgCatI.h)                         @@\
+                                                                       @@\
+depend:: prefix.cat Concat(prefix,MsgCatI.h)                           @@\
+                                                                       @@\
+all:: prefix.cat                                                       @@\
+                                                                       @@\
+clean::                                                                        @@\
+       $(RM) prefix.cat Concat(prefix,MsgCatI.h)
+#endif
+#define Stub_MessageCatalogRule(prefix)        /**/
+
+
+/* The X BuildLibDir is now an import, not an export. */
+#if UseImports || ImportX11
+# ifndef XBuildLibDir
+#  define XBuildLibDir $(TOP)/imports/x11/lib
+# endif
+#endif
+
+
+/* Search the Motif ProjectRoot too if it is different. */
+#ifdef MotifProjectRoot
+# define MUsrLibDirPath        Concat(XUsrLibDirPath,:$(MPROJECTROOT)/lib)
+#else
+# define MUsrLibDirPath        XUsrLibDirPath
+#endif
+#ifdef UsrLibDirPath
+# undef UsrLibDirPath
+#endif
+#define UsrLibDirPath  MUsrLibDirPath
+
+#if ImportMotif
+# define MLdPreLibs    -L$(MLIBSRC)
+#elif defined(UseInstalledMotif) && defined(MotifProjectRoot)
+# define MLdPreLibs    -L$(MPROJECTROOT)/lib
+#else
+# define MLdPreLibs    /**/
+#endif
+#ifdef LdPreLibs
+# undef LdPreLibs
+#endif
+#define LdPreLibs      LdPreLib MLdPreLibs XLdPreLibs
+
+#ifdef LdPostLibs
+# undef LdPostLibs
+#endif
+#ifdef MotifProjectRoot
+# define MLdPostLibs   -L$(MPROJECTROOT)/lib
+#else
+# define MLdPostLibs   /**/
+#endif
+#define LdPostLibs     LdPostLib MLdPostLibs XLdPostLibs
+
+#ifdef TopIncludes
+# undef TopIncludes
+#endif
+#define TopIncludes    TopInclude $(TOP_MOTIF_INCLUDES) $(TOP_X_INCLUDES)
+
+#if UseInstalledMotif && defined(MotifProjectRoot)
+# define MotifBuildLibPath     $(MPROJECTROOT)/lib
+#elif UseInstalledMotif
+# define MotifBuildLibPath     $(USRLIBDIR)
+#elif ImportMotif
+# define MotifBuildLibPath     $(MLIBSRC)
+#else
+# define MotifBuildLibPath     $(TOP)/exports/lib
+#endif
+#ifdef BuildLibPath
+# undef BuildLibPath
+#endif
+#ifdef SystemBuildLibPath
+# define BuildLibPath  $(MOTIFENVLIBDIR):$(XENVLIBDIR):$(SYSTEMENVLIBDIR)
+#else
+# define BuildLibPath  $(MOTIFENVLIBDIR):$(XENVLIBDIR)
+#endif
+
+#ifndef MotifProjectDefines
+# define MotifProjectDefines   MotifDefines MessageCatalogDefines
+#endif
+#ifdef ProjectDefines
+# undef ProjectDefines
+#endif
+#define ProjectDefines X11ProjectDefines MotifProjectDefines
+
+#ifndef MotifCplusplusProjectDefines
+# define MotifCplusplusProjectDefines  MotifProjectDefines
+#endif
+#ifdef CplusplusProjectDefines
+# undef CplusplusProjectDefines
+#endif
+#define CplusplusProjectDefines        \
+       X11CplusplusProjectDefines MotifCplusplusProjectDefines
diff --git a/Xserver/config/cf/Motif.tmpl b/Xserver/config/cf/Motif.tmpl
new file mode 100644 (file)
index 0000000..e421300
--- /dev/null
@@ -0,0 +1,568 @@
+/* 
+ *  @OSF_COPYRIGHT@
+ *  COPYRIGHT NOTICE
+ *  Copyright (c) 1990, 1991, 1992, 1993 Open Software Foundation, Inc.
+ *  ALL RIGHTS RESERVED (MOTIF). See the file named COPYRIGHT.MOTIF for
+ *  the full copyright text.
+ *
+ * (c) Copyright 1996 Digital Equipment Corporation.
+ * (c) Copyright 1996 Hewlett-Packard Company.
+ * (c) Copyright 1996 International Business Machines Corp.
+ * (c) Copyright 1996 Sun Microsystems, Inc.
+ * (c) Copyright 1996 Novell, Inc. 
+ * (c) Copyright 1996 FUJITSU LIMITED.
+ * (c) Copyright 1996 Hitachi.
+ */ 
+XCOMM $XConsortium: Motif.tmpl /main/2 1996/12/04 10:12:55 swick $
+
+/* Include the X11 project template file. */
+#include <X11.tmpl>
+
+#ifdef AUTOMATION
+# ifndef Automation
+#  define Automation   YES
+# endif
+#else
+# define NO_AUTOMATION
+#endif
+
+#ifdef USE_VISTACC
+# ifndef UseVista
+#  define UseVista
+# endif
+# ifndef CATCMD
+#  define CATCMD cat
+# endif
+#endif
+
+#ifdef USE_PURIFY
+# ifndef UsePurify
+#  define UsePurify
+# endif
+#endif
+
+#ifdef DEBUG_GEOMETRY
+# ifndef DebugGeometry
+#  define DebugGeometry YES
+# endif
+#endif
+
+
+#ifndef _MUse
+# if UseInstalledMotif
+#  define _MUse(a,b) a
+# else
+#  define _MUse(a,b) b
+# endif
+#endif
+
+#ifndef _MUseCat
+# if (defined(__STDC__) && !defined(UnixCpp)) || defined(AnsiCpp)
+#  if UseInstalledMotif
+#   define _MUseCat(a,b,c) a##c
+#  else
+#   define _MUseCat(a,b,c) b##c
+#  endif
+# else
+#  if UseInstalledMotif
+#   define _MUseCat(a,b,c) a/**/c
+#  else
+#   define _MUseCat(a,b,c) b/**/c
+#  endif
+# endif
+#endif
+
+#ifndef MTop
+# if ImportMotif
+#  define MTop $(TOP)/imports/motif
+# else
+#  define MTop $(TOP)
+# endif
+#endif
+
+#ifndef BuildDocDir
+# define BuildDocDir $(BUILDINCROOT)/doc
+#endif
+#ifndef BuildLocDir
+# define BuildLocDir $(BUILDINCROOT)/localized
+#endif
+
+#ifndef MotifDefines
+# define MotifDefines /**/
+#endif
+
+#ifndef XmDefines
+# define XmDefines  /**/
+#endif
+
+/* To compile without SHAPE extension, set this to -DNO_SHAPE */
+#ifndef MwmDefines
+# define MwmDefines /**/
+#endif
+
+#ifndef UilFlags
+# define UilFlags /**/
+#endif
+
+#ifndef TestDefines
+# define TestDefines /**/
+#endif
+
+#ifndef AutoDefines
+# if Automation
+#  define AutoDefines -DAUTOMATION
+# else
+#  define AutoDefines /**/
+# endif
+#endif
+
+#ifndef AutoIncludes
+# if Automation
+#  define AutoIncludes -I$(AUTOSCRIPTSRC)
+# else
+#  define AutoIncludes /**/
+# endif
+#endif
+
+#ifdef UsePurify
+# define PurifyFilesToClean *.pure_linkinfo *.pure_hardlink
+#else
+# define PurifyFilesToClean
+#endif
+#if Automation
+# define TestExtraFilesToClean *.Dat *.Scr PurifyFilesToClean
+#else 
+# define TestExtraFilesToClean *.Dat PurifyFilesToClean
+#endif 
+
+#ifndef UsrIncDir
+# define UsrIncDir IncRoot
+#endif
+
+/* Place to install .uid files */
+#ifndef UidDir
+# define UidDir $(LIBDIR)/uid
+#endif
+
+#ifndef XmExtraLibraries
+# define XmExtraLibraries /**/
+#endif
+
+#ifndef YaccFlags
+# define YaccFlags /**/
+#endif
+
+#define MotifSharedRev         2.1
+
+#ifndef SharedLibXm
+# define SharedLibXm           HasSharedLibraries
+#endif
+#ifndef NormalLibXm
+# define NormalLibXm           (!SharedLibXm | ForceNormalLib)
+#endif
+#ifndef DebugLibXm
+# define DebugLibXm            NO
+#endif
+#ifndef ProfileLibXm
+# define ProfileLibXm          NO
+#endif
+#ifndef SharedXmRev
+# define SharedXmRev           MotifSharedRev
+#endif
+
+#ifndef SharedLibMrm
+# define SharedLibMrm          HasSharedLibraries
+#endif
+#ifndef NormalLibMrm
+# define NormalLibMrm          (!SharedLibMrm | ForceNormalLib)
+#endif
+#ifndef DebugLibMrm
+# define DebugLibMrm           NO
+#endif
+#ifndef ProfileLibMrm
+# define ProfileLibMrm         NO
+#endif
+#ifndef SharedMrmRev
+# define SharedMrmRev          MotifSharedRev
+#endif
+
+#ifndef SharedLibUil
+# define SharedLibUil          HasSharedLibraries
+#endif
+#ifndef NormalLibUil
+# define NormalLibUil          (!SharedLibUil | ForceNormalLib)
+#endif
+#ifndef DebugLibUil
+# define DebugLibUil           NO
+#endif
+#ifndef ProfileLibUil
+# define ProfileLibUil         NO
+#endif
+#ifndef SharedUilRev
+# define SharedUilRev          MotifSharedRev
+#endif
+
+#ifndef SharedLibACommon
+# define SharedLibACommon      HasSharedLibraries
+#endif
+#ifndef NormalLibACommon
+# define NormalLibACommon      (!SharedLibACommon | ForceNormalLib)
+#endif
+#ifndef DebugLibACommon
+# define DebugLibACommon       NO
+#endif
+#ifndef ProfileLibACommon
+# define ProfileLibACommon     NO
+#endif
+#ifndef SharedACommonRev
+# define SharedACommonRev      MotifSharedRev
+#endif
+
+#ifndef SharedLibScript
+# define SharedLibScript       HasSharedLibraries
+#endif
+#ifndef NormalLibScript
+# define NormalLibScript       (!SharedLibScript | ForceNormalLib)
+#endif
+#ifndef DebugLibScript
+# define DebugLibScript                NO
+#endif
+#ifndef ProfileLibScript
+# define ProfileLibScript      NO
+#endif
+#ifndef SharedScriptRev
+# define SharedScriptRev       MotifSharedRev
+#endif
+
+#ifndef SharedLibUtil
+# define SharedLibUtil         HasSharedLibraries
+#endif
+#ifndef NormalLibUtil
+# define NormalLibUtil         (!SharedLibUtil | ForceNormalLib)
+#endif
+#ifndef DebugLibUtil
+# define DebugLibUtil          NO
+#endif
+#ifndef ProfileLibUtil
+# define ProfileLibUtil                NO
+#endif
+#ifndef SharedUtilRev
+# define SharedUtilRev         MotifSharedRev
+#endif
+
+#ifndef SharedLibCreate
+# define SharedLibCreate       HasSharedLibraries
+#endif
+#ifndef NormalLibCreate
+# define NormalLibCreate       (!SharedLibCreate | ForceNormalLib)
+#endif
+#ifndef DebugLibCreate
+# define DebugLibCreate                NO
+#endif
+#ifndef ProfileLibCreate
+# define ProfileLibCreate      NO
+#endif
+#ifndef SharedCreateRev
+# define SharedCreateRev       MotifSharedRev
+#endif
+
+#ifndef SharedLibVisual
+# define SharedLibVisual       HasSharedLibraries
+#endif
+#ifndef NormalLibVisual
+# define NormalLibVisual       (!SharedLibVisual | ForceNormalLib)
+#endif
+#ifndef DebugLibVisual
+# define DebugLibVisual                NO
+#endif
+#ifndef ProfileLibVisual
+# define ProfileLibVisual      NO
+#endif
+#ifndef SharedVisualRev
+# define SharedVisualRev       MotifSharedRev
+#endif
+
+#ifndef SharedLibSynth
+# define SharedLibSynth                HasSharedLibraries
+#endif
+#ifndef NormalLibSynth
+# define NormalLibSynth                (!SharedLibSynth | ForceNormalLib)
+#endif
+#ifndef DebugLibSynth
+# define DebugLibSynth         NO
+#endif
+#ifndef ProfileLibSynth
+# define ProfileLibSynth       NO
+#endif
+#ifndef SharedSynthRev
+# define SharedSynthRev                MotifSharedRev
+#endif
+
+#ifndef SharedLibMCommon
+# define SharedLibMCommon      HasSharedLibraries
+#endif
+#ifndef NormalLibMCommon
+# define NormalLibMCommon      (!SharedLibMCommon | ForceNormalLib)
+#endif
+#ifndef DebugLibMCommon
+# define DebugLibMCommon       NO
+#endif
+#ifndef ProfileLibMCommon
+# define ProfileLibMCommon     NO
+#endif
+#ifndef SharedMCommonRev
+# define SharedMCommonRev      MotifSharedRev
+#endif
+
+#ifndef XmClientLibs
+# define XmClientLibs $(XMLIB) $(XTOOLLIB) $(XPLIB) $(XLIB) $(XMEXTRA_LIBS)
+#endif
+#ifndef XmClientDepLibs
+# define XmClientDepLibs $(DEPXMLIB) $(DEPXTOOLLIB) $(DEPXPLIB) $(DEPXLIB)
+#endif
+
+#ifndef MrmClientLibs 
+# define MrmClientLibs $(MRESOURCELIB) $(XMLIB) $(XTOOLLIB) $(XPLIB) $(XLIB) $(XMEXTRA_LIBS)
+#endif
+#ifndef MrmClientDepLibs
+# define MrmClientDepLibs $(DEPMRESOURCELIB) $(DEPXMLIB) $(DEPXTOOLLIB) $(DEPXPLIB) $(DEPXLIB)
+#endif
+
+#ifndef UilClientLibs
+# define UilClientLibs $(UILLIB) $(MRESOURCELIB) $(XMLIB) $(XTOOLLIB) $(XPLIB) $(XLIB) $(XMEXTRA_LIBS)
+#endif
+#ifndef UilClientDepLibs
+# define UilClientDepLibs $(DEPUILLIB) $(DEPMRESOURCELIB) $(DEPXMLIB) $(DEPXTOOLLIB) $(DEPXPLIB) $(DEPXLIB)
+#endif
+
+#ifndef TestClientLibs
+# define TestClientLibs $(PURIFYLIBS) $(TESTCOMLIB) \
+               $(AUTOSCRIPTLIB) $(AUTOUTILLIB) \
+               $(AUTOCREATELIB) $(AUTOVISUALLIB) $(AUTOSYNTHLIB) \
+       $(XMLIB) $(TESTGEOLIB) $(XTOOLLIB) $(XPLIB) $(XLIB) \
+       $(AUTOEXTRALIBS) $(XMEXTRA_LIBS)
+#endif
+#ifndef TestUilClientLibs
+# define TestUilClientLibs $(PURIFYLIBS) $(TESTUILCOMLIB) $(TESTCOMLIB) \
+               $(AUTOSCRIPTLIB) $(AUTOUTILLIB) \
+               $(AUTOCREATELIB) $(AUTOVISUALLIB) $(AUTOSYNTHLIB) \
+       $(UILLIB) $(MRESOURCELIB) $(XMLIB) $(TESTGEOLIB) \
+       $(XTOOLLIB) $(XPLIB) $(XLIB) $(AUTOEXTRALIBS) $(XMEXTRA_LIBS)
+#endif
+#ifndef TestClientDepLibs
+# define TestClientDepLibs XmClientDepLibs
+#endif
+#ifndef TestUilClientDepLibs
+# define TestUilClientDepLibs UilClientDepLibs
+#endif
+
+
+              MTOP = MTop
+TOP_MOTIF_INCLUDES = -I$(MINCLUDESRC)
+#if defined(UseInstalled) || (UseInstalledMotif && UseInstalledX11)
+      UIL_INCLUDES = -I$(USRINCDIR)/uil
+#else
+      UIL_INCLUDES = -I$(UILSRC)
+#endif
+#ifdef BuildLibPathVar
+    MOTIFENVLIBDIR = MotifBuildLibPath
+#endif
+
+/* Message catalog usage */
+#ifndef GencatCmd
+# define GencatCmd             gencat
+#endif
+#ifndef GencatFlags
+# define GencatFlags           /**/
+#endif
+#if defined(NoMessageCatalog)
+# define BuildMessageCatalog   NO
+# define MessageCatalogDefines -DNO_MESSAGE_CATALOG
+#else
+# define BuildMessageCatalog   YES 
+# define MessageCatalogDefines /**/
+#endif
+#ifndef MessageCatalogRule
+# if BuildMessageCatalog
+#  define MessageCatalogRule(prefix)   Real_MessageCatalogRule(prefix)
+# else
+#  define MessageCatalogRule(prefix)   Stub_MessageCatalogRule(prefix)
+# endif
+#endif
+
+      USRINCDIR = UsrIncDir
+         UIDDIR = UidDir
+        TESTSRC = $(MTOP)/tests
+        TESTLIB = $(TESTSRC)/lib
+  GENERALSRCLIB = $(TESTSRC)/General/lib
+  GENERALSRCBIN = $(TESTSRC)/General/bin
+   MANUALSRCLIB = $(TESTSRC)/Manual/lib
+   MANUALSRCBIN = $(TESTSRC)/Manual/bin
+     AUTOSRCLIB = $(TESTSRC)/Auto/lib
+     AUTOSRCBIN = $(TESTSRC)/Auto/bin
+       COMMONPP = $(GENERALSRCBIN)/Commonpp
+         GENRUN = $(GENERALSRCBIN)/Genrun
+         MANRUN = $(GENERALSRCBIN)/Manrun
+#ifdef DebugLib
+  TESTMALLOCSRC = $(GENERALSRCLIB)/Malloc
+#endif
+#ifdef DebugGeometry
+     TESTGEOSRC = $(TESTLIB)/Geometry
+#endif
+#ifdef Automation
+     TESTCOMSRC = $(AUTOSRCLIB)/Common
+  AUTOSCRIPTSRC = $(AUTOSRCLIB)/Script
+   AUTOSYNTHSRC = $(AUTOSRCLIB)/Synth
+  AUTOCREATESRC = $(AUTOSRCLIB)/Create
+  AUTOVISUALSRC = $(AUTOSRCLIB)/Visual
+    AUTOUTILSRC = $(AUTOSRCLIB)/Util
+  AUTOEXTRALIBS = -ll -ly -lm
+#else
+     TESTCOMSRC = $(MANUALSRCLIB)/Common
+#endif
+
+    BUILDDOCDIR = BuildDocDir
+    BUILDLOCDIR = BuildLocDir
+
+/* MTOOLKITSRC  should be removed */
+    MTOOLKITSRC = $(TOOLKITSRC)
+#if ImportMotif || UseInstalledMotif
+    MINCLUDESRC = $(MTOP)/include
+        MDOCSRC = $(MTOP)/doc
+        MLOCSRC = $(MTOP)/localized
+#else
+    MINCLUDESRC = $(MTOP)/exports/include
+        MLOCSRC = $(MTOP)/exports/localized
+#endif
+        MLIBSRC = $(MTOP)/lib
+     MCLIENTSRC = $(MTOP)/clients
+       MDEMOSRC = $(MTOP)/demos
+     MWIDGETSRC = $(MLIBSRC)/Xm
+   MRESOURCESRC = $(MLIBSRC)/Mrm
+         UILSRC = $(MCLIENTSRC)/uil
+#ifdef MotifProjectRoot
+   MPROJECTROOT = MotifProjectRoot
+#endif
+
+            UIL = _MUse(uil,$(UILSRC)/uil)
+         DEPUIL = _MUseCat($(BINDIR),$(UILSRC),/uil)
+
+   XMEXTRA_LIBS = XmExtraLibraries
+
+/* These libraries use UseInstalledMotif instead of UseInstalled. */
+#undef _Use
+#undef _UseCat
+#define _Use    _MUse
+#define _UseCat _MUseCat
+
+#ifndef MBuildLibDir
+# define MBuildLibDir  BuildLibDir
+#endif
+
+#if SharedLibXm
+SharedLibReferences(XM,Xm,$(MWIDGETSRC),SOXMREV,SharedXmRev)
+#else
+ProjectUnsharedLibReferences(XM,Xm,$(MWIDGETSRC),MBuildLibDir)
+#endif
+
+#if SharedLibMrm
+SharedLibReferences(MRESOURCE,Mrm,$(MRESOURCESRC),SOMRMREV,SharedMrmRev)
+#else
+ProjectUnsharedLibReferences(MRESOURCE,Mrm,$(MRESOURCESRC),MBuildLibDir)
+#endif
+
+#if SharedLibUil
+SharedLibReferences(UIL,Uil,$(UILSRC),SOUILREV,SharedUilRev)
+#else
+ProjectUnsharedLibReferences(UIL,Uil,$(UILSRC),MBuildLibDir)
+#endif
+
+#ifdef DebugGeometry
+ProjectUnsharedLibReferences(TESTGEO,XtGeo,$(TESTGEOSRC),MBuildLibDir)
+#endif
+
+#if Automation
+
+# if SharedLibACommon
+SharedLibReferences(TESTCOM,ACommon,$(TESTCOMSRC),SOACOMMONREV,SharedACommonRev)
+# else
+ProjectUnsharedLibReferences(TESTCOM,ACommon,$(TESTCOMSRC),MBuildLibDir)
+# endif
+
+TESTUILCOMLIB = $(TESTCOMSRC)/libACommonUil.a
+
+# if SharedLibScript
+SharedLibReferences(AUTOSCRIPT,Script,$(AUTOSCRIPTSRC),SOSCRIPTREV,SharedScriptRev)
+# else
+ProjectUnsharedLibReferences(AUTOSCRIPT,Script,$(AUTOSCRIPTSRC),MBuildLibDir)
+# endif
+
+# if SharedLibSynth
+SharedLibReferences(AUTOSYNTH,Synth,$(AUTOSYNTHSRC),SOSYNTHREV,SharedSynthRev)
+# else
+ProjectUnsharedLibReferences(AUTOSYNTH,Synth,$(AUTOSYNTHSRC),MBuildLibDir)
+# endif
+
+# if SharedLibCreate
+SharedLibReferences(AUTOCREATE,Create,$(AUTOCREATESRC),SOCREATEREV,SharedCreateRev)
+# else
+ProjectUnsharedLibReferences(AUTOCREATE,Create,$(AUTOCREATESRC),MBuildLibDir)
+# endif
+
+# if SharedLibVisual
+SharedLibReferences(AUTOVISUAL,Visual,$(AUTOVISUALSRC),SOVISUALREV,SharedVisualRev)
+# else
+ProjectUnsharedLibReferences(AUTOVISUAL,Visual,$(AUTOVISUALSRC),MBuildLibDir)
+# endif
+
+# if SharedLibUtil
+SharedLibReferences(AUTOUTIL,Util,$(AUTOUTILSRC),SOUTILREV,SharedUtilRev)
+# else
+ProjectUnsharedLibReferences(AUTOUTIL,Util,$(AUTOUTILSRC),MBuildLibDir)
+# endif
+
+#else   /* Manual */
+
+# if SharedLibMCommon
+SharedLibReferences(TESTCOM,MCommon,$(TESTCOMSRC),SOMCOMMONREV,SharedMCommonRev)
+# else
+ProjectUnsharedLibReferences(TESTCOM,MCommon,$(TESTCOMSRC),MBuildLibDir)
+# endif
+TESTUILCOMLIB = $(TESTCOMSRC)/libMCommonUil.a
+
+#endif  /* Automation */
+
+
+/* Revert to the normal library rules. */
+#undef _Use
+#undef _UseCat
+#define _Use    _XUse
+#define _UseCat _XUseCat
+
+
+#ifdef UsePurify
+     PURIFYLIBS = $(PURIFYHOME)/purify_stubs.a
+#endif
+  LINTMRESOURCE = $(MRESOURCESRC)/libMrm.a
+LINTXMWIDGETLIB = $(MWIDGETSRC)/llib-l/Xm.ln
+     LINTXMTOOL = $(MTOOLKITSRC)/llib-lXt.ln
+     LINTUILLIB = $(UILSRC)/llib-lUil.ln
+
+      YACCFLAGS = YaccFlags
+       UILFLAGS = UilFlags
+    GENCATFLAGS = GencatFlags
+         GENCAT = GencatCmd $(GENCATFLAGS)
+      MKCATTOOL = $(MLOCSRC)/util/mkcatdefs
+
+         RM_CMD = $(RM) FilesToClean ExtraFilesToClean TestExtraFilesToClean
+
+#if NeedDefaultDepLibs
+# if HasSharedLibraries || defined(UseInstalled)
+        DEPLIBS = $(DEPXMLIB) $(DEPXTOOLLIB) $(DEPXPLIB) $(DEPXLIB)
+# else
+        DEPLIBS = $(LOCAL_LIBRARIES)
+# endif
+        DEPLIBS1 = $(DEPLIBS)
+        DEPLIBS2 = $(DEPLIBS)
+        DEPLIBS3 = $(DEPLIBS)
+#endif /* NeedDefaultDepLibs */
diff --git a/Xserver/config/cf/NetBSD.cf b/Xserver/config/cf/NetBSD.cf
new file mode 100644 (file)
index 0000000..cf64c76
--- /dev/null
@@ -0,0 +1,377 @@
+XCOMM platform:  $XConsortium: NetBSD.cf /main/16 1996/10/31 14:47:14 kaleb $
+
+
+
+XCOMM platform:  $XFree86: xc/config/cf/NetBSD.cf,v 3.49.2.9 1997/07/26 06:30:39 dawes Exp $
+
+
+#ifndef OSName
+#define OSName                 DefaultOSName OSBinaryType
+#endif
+#ifndef OSMajorVersion
+#define OSMajorVersion         DefaultOSMajorVersion
+#endif
+#ifndef OSMinorVersion
+#define OSMinorVersion         DefaultOSMinorVersion
+#endif
+#ifndef OSTeenyVersion
+#define OSTeenyVersion         DefaultOSTeenyVersion
+#endif
+
+
+#ifndef OSVendor
+#define        OSVendor        /**/
+#endif
+XCOMM operating system:  OSName (OSMajorVersion./**/OSMinorVersion./**/OSTeenyVersion)
+
+/*
+ * C library features
+ */
+#if ((OSMajorVersion > 1) || \
+     (OSMajorVersion == 1 && OSMinorVersion > 2) || \
+     (OSMajorVersion == 1 && OSMinorVersion == 2 && OSTeenyVersion > 1))
+#  define HasPoll                      YES
+#endif
+#define HasNdbm                YES
+#define HasPutenv              YES
+#define HasSnprintf            YES
+#define HasBSD44Sockets        YES
+#define Malloc0ReturnsNull     NO
+#define SetTtyGroup            YES
+#define DBMLibrary             /**/
+#ifndef HasLibCrypt
+# define HasLibCrypt           YES
+#endif
+#ifndef HasShm
+# if OSMajorVersion == 0 && OSMinorVersion == 9 && OSTeenyVersion == 2
+/*
+ * Shm memory was removed in 0.9B because it was encumbered.
+ * A free version was added in 0.9C
+ */
+#  define HasShm               NO
+# else
+#  define HasShm               YES
+# endif
+#endif
+#define HasWChar32             YES
+/*
+ * There's a bug in NetBSD 1.0, 1.1 and 1.2 dlsym()
+ */
+#if ((OSMajorVersion == 1 && OSMinorVersion < 2) || \
+     (OSMajorVersion == 1 && OSMinorVersion == 2 && OSTeenyVersion < 2))
+#  define HasDlsymBug          YES
+#endif
+/* Mkstemp is there since 1.2 (at least) */
+#if (!(OSMajorVersion == 0 || \
+       (OSMajorVersion == 1 && OSMinorVersion < 2))) 
+#define HasMkstemp             YES
+#endif
+/*
+ * Compiler Features
+ */
+#undef HasGcc
+#define HasGcc                 YES
+#define HasGcc2                        YES
+#ifndef HasGcc2ForCplusplus
+#define HasGcc2ForCplusplus    YES
+#endif
+#define GccUsesGas             YES
+#define UseGas                 YES
+#define GnuCpp                 YES
+
+#define NeedConstPrototypes    YES
+#define NeedFunctionPrototypes YES
+#define NeedNestedPrototypes   YES
+#define NeedVarargsPrototypes  YES
+#define NeedWidePrototypes     NO
+
+#define MkdirHierCmd           mkdir -p
+
+#define CppCmd                 /usr/libexec/cpp
+#define StandardCppDefines     -traditional
+#define PreProcessCmd          CppCmd
+#define PreIncDir              /usr/include
+
+#undef CcCmd
+#define CcCmd                  gcc
+#if defined(UseInstalled) && (!defined(XF86LinkKit) || !XF86LinkKit)
+#define DefaultCCOptions       /**/
+#else
+#define DefaultCCOptions       -ansi -Dasm=__asm
+#endif
+
+#define GccGasOption           -DGCCUSESGAS
+#define AsmDefines             -DUSE_GAS
+
+/* UseElfFormat defaults to YES if __ELF__ set */
+#ifndef UseElfFormat
+# ifdef __ELF__
+#  undef __ELF__                       /* other imake files shouldn't care */
+#  define UseElfFormat YES
+# else
+#  define UseElfFormat NO
+# endif
+#endif
+
+/*
+ * Dynamic loading supported starting in 1.0 on a.out platforms,
+ * and on all ELF platforms.
+ *
+ * XXX May not be correct on NetBSD/pmax (ELF, but might not have
+ * working shared libs).
+ */
+#if ((OSMajorVersion > 0) && \
+     !defined(AlphaArchitecture) && !defined(MipsArchitecture)) || \
+    UseElfFormat
+# ifndef BuildDynamicLoading
+# define BuildDynamicLoading   YES
+# endif
+#endif
+
+#if UseElfFormat
+#define DlLibrary              -rdynamic /* no -ldl yet */
+#else
+#define DlLibrary              /**/
+#endif
+
+#ifdef i386Architecture
+# define OptimizedCDebugFlags  DefaultGcc2i386Opt
+# if OSMajorVersion < 1
+#  define ServerOSDefines      XFree86ServerOSDefines -DDDXTIME -DXNO_SYSCONF
+# else
+#  define ServerOSDefines      XFree86ServerOSDefines -DDDXTIME
+# endif
+# if OSMajorVersion == 1 && OSMinorVersion >= 1 || OSMajorVersion >= 2
+#  define ServerExtraSysLibs   -li386 DlLibrary
+# endif
+#else
+# define OptimizedCDebugFlags  -O2
+# if defined(SparcArchitecture) || defined(AlphaArchitecture)
+#  define ServerOSDefines      -DDDXOSINIT
+# else
+#  define ServerOSDefines      /**/
+# endif
+# if BuildDynamicLoading
+#  define ServerExtraSysLibs   DlLibrary
+# else
+#  define ServerExtraSysLibs   /**/
+# endif
+#endif
+#ifdef i386Architecture
+# define ServerExtraDefines GccGasOption XFree86ServerDefines
+# ifndef XFree86ConsoleDefines
+#  define XFree86ConsoleDefines -DPCCONS_SUPPORT -DPCVT_SUPPORT
+# endif
+#else
+# if defined(AlphaArchitecture)
+#  define ServerExtraDefines GccGasOption -D_XSERVER64
+# else
+#  define ServerExtraDefines GccGasOption
+# endif
+#endif
+
+#define StandardDefines        -DCSRG_BASED
+#define XawI18nDefines -DUSE_XWCHAR_STRING -DUSE_XMBTOWC
+
+#ifndef ExtraLibraries
+#define ExtraLibraries         /**/
+#endif
+#ifndef UseGnuMalloc
+#  define UseGnuMalloc         YES
+#endif
+#ifndef GnuMallocLibrary
+#define GnuMallocLibrary       -lgnumalloc
+#endif
+
+#if ((OSMajorVersion > 1) || \
+     (OSMajorVersion == 1 && OSMinorVersion > 2) || \
+     (OSMajorVersion == 1 && OSMinorVersion == 2 && OSTeenyVersion > 1))
+#ifndef HasZlib
+#define HasZlib                          YES
+#endif
+#endif 
+
+#define        AdmDir                  /var/log
+
+/*
+ * Make & install Features
+ */
+#define HasBsdMake             YES
+#define StripInstalledPrograms YES
+#define CompressAllFonts       YES
+#define GzipFontCompression    YES
+#define DefaultUserPath                /bin:/usr/bin:/usr/local/bin:$(BINDIR)
+#define DefaultSystemPath      /sbin:/usr/sbin:/bin:/usr/bin:$(BINDIR)
+
+#ifdef  InstallCmd
+# undef  InstallCmd
+# define InstallCmd            /usr/bin/install
+#endif
+
+#ifndef ExtraFilesToClean
+# define ExtraFilesToClean     *.core
+#endif
+
+/*
+ * Documentation formatting
+ */
+#define NeqnCmd                        neqn -Tlatin1
+#define NroffCmd               nroff -Tlatin1
+#define        EqnCmd                  eqn -Tps
+#define TroffCmd               groff -Tps
+
+/*
+ * To use the NetBSD Aperture driver
+ */
+#if defined(i386Architecture)
+#ifndef HasNetBSDApertureDriver
+#define HasNetBSDApertureDriver        YES
+#endif
+#endif
+
+/*
+ * ForceSubdirs - force make to build subdirectories
+ * 
+ * For BSD 4.4 make 
+ */
+#define ForceSubdirs(dirs)                                             @@\
+dirs:  .EXEC                                                           @@\
+       @cd $@ ; echo "making all in $(CURRENT_DIR)/$@..."; \           @@\
+       $(MAKE) $(MFLAGS) PassCDebugFlags all                           @@\
+                                                                       @@\
+.EXEC:
+
+XCOMM Man pages need to be formatted when installed, so override the default
+XCOMM imake rules.
+
+#define ManSuffix      1
+#define FileManSuffix  5
+#define ManSourcePath  $(MANPATH)/cat
+
+#define InstallManPageLong(file,destdir,dest)                           @@\
+all:: file.0                                                           @@\
+                                                                       @@\
+file.0:: file.man                                                      @@\
+       @if [ -f file.man ]; \                                          @@\
+       then \                                                          @@\
+       cat file.man | $(NEQN) | $(TBL) | $(NROFF) $(MANMACROS) | $(COL) >/tmp/$$$$.man; \      @@\
+       cp /tmp/$$$$.man file.0; \                                      @@\
+       $(RM) /tmp/$$$$.man; \                                          @@\
+       fi                                                              @@\
+                                                                       @@\
+install.man::                                                           @@\
+       MakeDir($(DESTDIR)destdir)                                      @@\
+       -@if [ -f file.0 ]; \                                           @@\
+       then \                                                          @@\
+       $(INSTALL) -c $(INSTMANFLAGS) file.0 $(DESTDIR)destdir/dest.0; \@@\
+       fi
+
+#define InstallGenManPageLong(file,destdir,dest,suffix)                        @@\
+       InstallManPageLong(file,destdir,dest)
+
+#define InstallMultipleManSuffix(list,dest,suff)                        @@\
+install.man::                                                          @@\
+       MakeDir($(DESTDIR)dest)                                         @@\
+       case '${MFLAGS}' in *[i]*) set +e;; esac; \                     @@\
+       for i in list; do \                                             @@\
+         (set -x; \                                                    @@\
+         cat $$i.suff | $(NEQN) | $(TBL) | $(NROFF) $(MANMACROS) | $(COL) >/tmp/$$$$.suff; \   @@\
+         $(INSTALL) -c $(INSTMANFLAGS) /tmp/$$$$.suff $(DESTDIR)dest/$$i.0; \  @@\
+         $(RM) /tmp/$$$$.suff); \                                              @@\
+       done
+
+#define InstallMultipleMan(list,dest)                                   @@\
+       InstallMultipleManSuffix(list,dest,man)
+
+#define InstallManPageAliases(file,destdir,aliases)                     @@\
+install.man::                                                          @@\
+       @case '${MFLAGS}' in *[i]*) set +e;; esac; \                    @@\
+       for i in aliases; do \                                          @@\
+               (set -x; \                                              @@\
+               $(RM) $(DESTDIR)destdir/$$i.0;\                         @@\
+               (cd $(DESTDIR)/destdir; $(LN) file.0 $$i.0);\           @@\
+               ); \                                                    @@\
+       done
+
+#define InstallGenManPageAliases(file,destdir,suffix,aliases)          @@\
+       InstallManPageAliases(file,destdir,aliases)
+
+/*
+ * Shared libraries supported starting in 1.0 on a.out platforms,
+ * and on all ELF platforms.
+ *
+ * XXX May not be correct on NetBSD/pmax (ELF, but might not have
+ * working shared libs).
+ */
+#if ((OSMajorVersion > 0) && \
+     !defined(AlphaArchitecture) && !defined(MipsArchitecture)) || \
+    UseElfFormat
+# ifndef HasSharedLibraries
+# define HasSharedLibraries    YES
+# endif
+#endif
+
+#ifndef OSBinaryType
+#if UseElfFormat
+#define OSBinaryType   [ELF]
+#else
+#define OSBinaryType   /**/
+#endif
+#endif
+
+#ifndef HasSharedLibraries
+#define HasSharedLibraries     NO
+#endif 
+
+#if HasSharedLibraries
+#include <bsdLib.rules>
+#endif /* HasSharedLibraries */
+
+#ifdef i386Architecture
+# include <xfree86.cf>
+#endif
+
+/*
+ * Definitions for the SUN server on NetBSD/sparc
+ */
+#ifdef SparcArchitecture
+#ifndef Xsun24Server
+#define Xsun24Server   NO
+#endif
+#ifndef XsunServer
+#define XsunServer     YES
+#endif
+#ifndef XsunMonoServer
+#define XsunMonoServer YES
+#endif
+#ifndef BuildScreenSaverLibrary
+#define BuildScreenSaverLibrary        YES
+#endif
+/*
+ * XFree86 uses its own (more portable) database routines to speed up 
+ * the RGB database lookups
+ * However, if you want to use ndbm anyway, you can set that to NO in 
+ * site.def
+ */
+#ifndef UseRgbTxt
+#define UseRgbTxt      YES
+#endif
+#endif
+
+/*
+ * Definition for compiling on MIPS machines
+ */
+#ifdef MipsArchitecture
+#define PositionIndependentCFlags
+#define SharedLibraryLoadFlags -x -shared --whole-archive -soname `echo $@ |
+sed 's/\.[0-9]*$$//'`
+#define SharedXtReqs $(XLIBONLY) $(SMLIB) $(ICELIB)
+#define SharedXmuReqs $(LDPRELIB) $(XTOOLONLYLIB) $(XONLYLIB) $(EXTENSIONLIB)
+#endif
+
+/*
+ * Definition for compiling on Alpha machines
+ */
+#ifdef AlphaArchitecture
+#define        BuildServer     NO
+#endif
diff --git a/Xserver/config/cf/Oki.cf b/Xserver/config/cf/Oki.cf
new file mode 100644 (file)
index 0000000..d51766b
--- /dev/null
@@ -0,0 +1,30 @@
+XCOMM platform:  $XConsortium: Oki.cf /main/16 1996/09/28 16:06:53 rws $
+
+#ifndef OSName
+#define OSName                 Unix System V/860 Release 4.0 Version 3
+#endif
+XCOMM operating system:  OSName
+#ifndef OSMajorVersion
+#define OSMajorVersion         4
+#endif
+#ifndef OSMinorVersion
+#define OSMinorVersion         0
+#endif
+#ifndef OSTeenyVersion
+#define OSTeenyVersion         3
+#endif
+
+#define BootstrapCFlags                -DOki
+#define SystemV4               YES
+#define HasLdRunPath           YES
+#define ConnectionFlags                -DTCPCONN -DUNIXCONN -DLOCALCONN
+#define SetTtyGroup            YES
+#define HasPutenv              YES
+#define HasPoll                 YES
+#define PatheticCpp            YES
+#define CcCmd                  /usr/bin/cc
+#define StandardDefines -DSVR4 -Di860
+#define DefaultCCOptions       -Xa
+#define BuildServer             NO
+#define ToolkitStringsABIOptions -intelabi
+#include <sv4Lib.rules>
diff --git a/Xserver/config/cf/OpenBSD.cf b/Xserver/config/cf/OpenBSD.cf
new file mode 100644 (file)
index 0000000..c55eb40
--- /dev/null
@@ -0,0 +1,482 @@
+XCOMM platform:  $XFree86: xc/config/cf/OpenBSD.cf,v 3.1.2.11 1998/02/15 16:08:33 hohndel Exp $
+XCOMM $OpenBSD: OpenBSD.cf,v 1.11 1997/12/09 03:03:48 gene Exp $
+
+#ifndef OSName
+#define OSName                 DefaultOSName OSBinaryType
+#endif
+#ifndef OSMajorVersion
+#define OSMajorVersion         DefaultOSMajorVersion
+#endif
+#ifndef OSMinorVersion
+#define OSMinorVersion         DefaultOSMinorVersion
+#endif
+#ifndef OSTeenyVersion
+#define OSTeenyVersion         DefaultOSTeenyVersion
+#endif
+
+#ifndef OSVendor
+#define        OSVendor        /**/
+#endif
+XCOMM operating system:  OSName (OSMajorVersion./**/OSMinorVersion./**/OSTeenyVersion)
+
+/*
+ * C library features
+ */
+#define HasPoll                        YES
+#define HasNdbm                YES
+#define HasPutenv              YES
+#define HasSnprintf            YES
+#define HasBSD44Sockets        YES
+#define Malloc0ReturnsNull     NO
+#define SetTtyGroup            YES
+#define DBMLibrary             /**/
+#define HasLibCrypt            NO
+#define HasShm                 YES
+#define HasWChar32             YES
+#define HasMkstemp             YES
+
+/*
+ * Compiler Features
+ */
+#undef HasGcc
+#define HasGcc                 YES
+#define HasGcc2                        YES
+#ifndef HasGcc2ForCplusplus
+#define HasGcc2ForCplusplus    YES
+#endif
+#define GccUsesGas             YES
+#define UseGas                 YES
+#define GnuCpp                 YES
+
+
+#define NeedConstPrototypes    YES
+#define NeedFunctionPrototypes YES
+#define NeedNestedPrototypes   YES
+#define NeedVarargsPrototypes  YES
+#define NeedWidePrototypes     NO
+
+#define MkdirHierCmd           mkdir -p
+
+#define CppCmd                 /usr/libexec/cpp
+#define StandardCppDefines     -traditional
+#define PreProcessCmd          CppCmd
+#define PreIncDir              DefaultGccIncludeDir
+
+#undef CcCmd
+#define CcCmd                  gcc
+#if defined(UseInstalled) && (!defined(XF86LinkKit) || !XF86LinkKit)
+#define DefaultCCOptions       /**/
+#else
+#define DefaultCCOptions       -ansi -Dasm=__asm
+#endif
+
+#define GccGasOption           -DGCCUSESGAS
+#define AsmDefines             -DUSE_GAS
+
+
+#ifdef i386Architecture
+# define OptimizedCDebugFlags  DefaultGcc2i386Opt
+# define ServerOSDefines       XFree86ServerOSDefines -DDDXTIME
+# define ServerExtraSysLibs    -li386
+#else
+# define OptimizedCDebugFlags  -O2
+# if defined(SparcArchitecture) || defined(AlphaArchitecture) || defined(AmigaArchitecture) || defined(Sun3Architecture)
+#  define ServerOSDefines      -DDDXOSINIT
+# else
+#  define ServerOSDefines      /**/
+# endif
+#endif
+#if defined(i386Architecture) || defined(ArcArchitecture)
+# define ServerExtraDefines GccGasOption XFree86ServerDefines
+# ifndef XFree86ConsoleDefines
+#  if defined(ArcArchitecture)
+#   define XFree86ConsoleDefines -DPCCONS_SUPPORT
+#  else
+#   define XFree86ConsoleDefines -DPCCONS_SUPPORT -DPCVT_SUPPORT
+#  endif
+# endif
+#else
+# if defined(AlphaArchitecture)
+#  define ServerExtraDefines GccGasOption -D_XSERVER64
+# else
+#  if !defined(Sun3Architecture)
+#   define ServerExtraDefines GccGasOption
+#  endif
+# endif
+#endif
+
+#define StandardDefines        -DCSRG_BASED
+#define XawI18nDefines -DUSE_XWCHAR_STRING -DUSE_XMBTOWC
+
+
+#ifndef ExtraLibraries
+#define ExtraLibraries         /**/
+#endif
+#define UseGnuMalloc           NO
+
+#define HasZlib                        YES
+
+#define        AdmDir                  /var/log
+
+/*
+ * Make & install Features
+ */
+
+#define HasBsdMake             YES
+
+#define StripInstalledPrograms YES
+#define CompressAllFonts       YES
+#define GzipFontCompression    YES
+#define DefaultUserPath                /bin:/usr/bin:/usr/local/bin:$(BINDIR)
+#define DefaultSystemPath      /sbin:/usr/sbin:/bin:/usr/bin:$(BINDIR)
+
+#ifdef  InstallCmd
+# undef  InstallCmd
+# define InstallCmd            /usr/bin/install
+#endif
+
+#ifndef ExtraFilesToClean
+# define ExtraFilesToClean     *.core
+#endif
+
+/*
+ * Documentation formatting
+ */
+#define NeqnCmd                        neqn -Tlatin1
+#define NroffCmd               nroff -Tlatin1
+#define        EqnCmd                  eqn -Tps
+#define TroffCmd               groff -Tps
+
+/*
+ * To use the NetBSD Aperture driver
+ */
+#if defined(i386Architecture)
+#ifndef HasNetBSDApertureDriver
+#define HasNetBSDApertureDriver        YES
+#endif
+#endif
+
+
+
+XCOMM Man pages need to be formatted when installed, so override the default
+XCOMM imake rules.
+
+#define ManSuffix      1
+#define FileManSuffix  5
+#define ManSourcePath  $(MANPATH)/cat
+
+#define InstallManPageLong(file,destdir,dest)                           @@\
+all:: file.0                                                           @@\
+                                                                       @@\
+file.0:: file.man                                                      @@\
+       @if [ -f file.man ]; \                                          @@\
+       then \                                                          @@\
+       cat file.man | $(NEQN) | $(TBL) | $(NROFF) $(MANMACROS) | $(COL) >/tmp/$$$$.man; \      @@\
+       cp /tmp/$$$$.man file.0; \                                      @@\
+       $(RM) /tmp/$$$$.man; \                                          @@\
+       fi                                                              @@\
+                                                                       @@\
+install.man::                                                           @@\
+       MakeDir($(DESTDIR)destdir)                                      @@\
+       -@if [ -f file.0 ]; \                                           @@\
+       then \                                                          @@\
+       $(INSTALL) -c $(INSTMANFLAGS) file.0 $(DESTDIR)destdir/dest.0; \@@\
+       fi
+
+#define InstallGenManPageLong(file,destdir,dest,suffix)                        @@\
+       InstallManPageLong(file,destdir,dest)
+
+#define InstallMultipleManSuffix(list,dest,suff)                        @@\
+install.man::                                                          @@\
+       MakeDir($(DESTDIR)dest)                                         @@\
+       case '${MFLAGS}' in *[i]*) set +e;; esac; \                     @@\
+       for i in list; do \                                             @@\
+         (set -x; \                                                    @@\
+         cat $$i.suff | $(NEQN) | $(TBL) | $(NROFF) $(MANMACROS) | $(COL) >/tmp/$$$$.suff; \   @@\
+         $(INSTALL) -c $(INSTMANFLAGS) /tmp/$$$$.suff $(DESTDIR)dest/$$i.0; \  @@\
+         $(RM) /tmp/$$$$.suff); \                                              @@\
+       done
+
+#define InstallMultipleMan(list,dest)                                   @@\
+       InstallMultipleManSuffix(list,dest,man)
+
+#define InstallManPageAliases(file,destdir,aliases)                     @@\
+install.man::                                                          @@\
+       @case '${MFLAGS}' in *[i]*) set +e;; esac; \                    @@\
+       for i in aliases; do \                                          @@\
+               (set -x; \                                              @@\
+               $(RM) $(DESTDIR)destdir/$$i.0;\                         @@\
+               (cd $(DESTDIR)/destdir; $(LN) file.0 $$i.0);\           @@\
+               ); \                                                    @@\
+       done
+
+#define InstallGenManPageAliases(file,destdir,suffix,aliases)          @@\
+       InstallManPageAliases(file,destdir,aliases)
+
+
+
+/*
+ * Architecture specific sections - put all architecture dependent
+ * options and setting here into the correct section
+ */
+
+/*
+ * Definitions for the alpha architecture
+ */
+#ifdef AlphaArchitecture
+
+# define XF86Contrib
+# include <xf86.rules>
+# define BuildServer           NO
+# define XnestServer           NO
+# define XVirtualFramebufferServer     NO
+
+ /*
+  * For the current ECOFF system
+  */
+# define HasSharedLibraries    NO
+# define UseElfFormat          NO
+# define BuildDynamicLoading   NO
+ /*
+  * For the upcoming ELF system
+  */
+# if 0 /* NOT YET */
+#  define HasSharedLibraries   YES
+#  define UseElfFormat         YES
+#  define BuildDynamicLoading  YES
+# endif
+
+#endif /* AlphaArchitecture */
+
+
+/*
+ * Definitions for the i386 architecture
+ */
+#ifdef i386Architecture
+
+/*
+ * For safety reasons, don't install the X server setuid on OpenBSD
+ * use xdm instead
+ */
+# define InstallXserverSetUID  NO
+
+# define BuildDynamicLoading   YES
+# include <xfree86.cf>
+
+#endif /* i386Architecture */
+
+
+/*
+ * Definitions for the m68k architecture (currently amiga, hp300,
+ * mac68k, mvme68k, sun3)
+ */
+#ifdef Mc68020Architecture
+
+/*
+ * Function CSE makes gas -k not recognize external function calls as lazily
+ * resolvable symbols, thus sometimes making ld.so report undefined symbol
+ * errors on symbols found in shared library members that would never be 
+ * called.  Ask niklas@openbsd.org for details.
+ */
+# define PositionIndependentCFlags -fpic -fno-function-cse
+
+#endif /* Mc68020Architecture */
+
+
+/*
+ * Definitions for the amiga architecture
+ */
+#ifdef AmigaArchitecture
+
+# define XF86Contrib
+# include <xf86.rules>
+# define BuildServer           NO
+
+#endif /* AmigaArchitecture */
+
+
+/*
+ * Definitions for the hp300 architecture
+ */
+#ifdef Hp300Architecture
+
+# include <xf86.rules>
+# define BuildServer           NO
+
+#endif /* Hp300Architecture */
+
+
+/*
+ * Definitions for the mac68k architecture
+ */
+#ifdef mac68kArchitecture
+
+# include <xf86.rules>
+# define BuildServer           NO
+
+#endif /* Mac68kArchitecture */
+
+
+/*
+ * Definitions for the mvme68k architecture
+ */
+#ifdef Mvme68kArchitecture
+
+# include <xf86.rules>
+# define BuildServer           NO
+
+#endif /* Mvme68kArchitecture */
+
+
+/*
+ * Definitions for the sun3 architecture
+ */
+#ifdef Sun3Architecture
+
+# include <xf86.rules>
+
+# define OptimizedCDebugFlags  -O2
+# define ServerOSDefines       -DDDXOSINIT
+# define BootstrapCFlags       -Dsun3
+# define UnalignedReferencesAllowed YES /* changes _XtCopyArgs() */
+/* Note: -ansi turns off -Dmc68000 */
+# define ServerExtraDefines    GccGasOption -Dmc68000 -Dmc68020
+
+# ifndef Xsun24Server
+#  define Xsun24Server         NO
+# endif
+# ifndef XsunServer
+#  define XsunServer           NO
+# endif
+# ifndef XsunMonoServer
+#  define XsunMonoServer       YES
+# endif
+
+# ifndef BuildXKB
+#  define BuildXKB             NO
+# endif
+
+# ifndef BuildXKBlib
+#  define BuildXKBlib          NO
+# endif
+
+# ifndef BuildPexExt
+#  define BuildPexExt          (XsunServer || Xsun24Server)
+# endif
+
+#endif /* Sun3Architecture */
+
+
+/*
+ * Definitions for the mips architecture (currently arc, pmax)
+ */
+#ifdef MipsArchitecture
+
+ /*
+  * Mips ELF shared libs need some special handling.
+  */
+# define PositionIndependentCFlags
+# define SharedLibraryLoadFlags -x -shared --whole-archive -soname `echo $@ | sed 's/\.[0-9]*$$//'`
+# define SharedXtReqs -L$(BUILDLIBDIR) $(XLIBONLY) $(SMLIB) $(ICELIB)
+# define SharedXmuReqs $(LDPRELIB) $(XTOOLONLYLIB) $(XONLYLIB) $(EXTENSIONLIB)
+
+#endif /* MipsArchitecture */
+
+
+/*
+ * Definitions for the arc architecture
+ */
+#ifdef ArcArchitecture
+
+# include <xfree86.cf>
+
+#endif /* ArcArchitecture */
+
+
+/*
+ * Definitions for the pmax architecture
+ */
+#ifdef PmaxArchitecture
+
+# include <xf86.rules>
+# define BuildServer           NO
+
+#endif /* PmaxArchitecture */
+
+
+/*
+ * Definitions for the sparc architecture
+ */
+#ifdef SparcArchitecture
+
+# include <xf86.rules>
+
+# ifndef Xsun24Server
+# define Xsun24Server  YES
+# endif
+# ifndef XsunServer
+# define XsunServer    YES
+# endif
+# ifndef XsunMonoServer
+# define XsunMonoServer        YES
+# endif
+
+#define XkbServerDefines  -DXKB_ALWAYS_USES_SOFT_REPEAT
+
+# ifndef BuildPexExt
+#  define BuildPexExt  (XsunServer || Xsun24Server)
+# endif
+#endif /* SparcArchitecture */
+
+
+/* End or architecture specific section */
+
+/*
+ * Generic settings for all architectures
+ */
+
+#ifndef XVirtualFramebufferServer
+# undef BuildServer
+# define BuildServer                   YES
+# define XVirtualFramebufferServer     YES
+#endif
+
+#ifndef XnestServer
+# undef BuildServer
+# define BuildServer                   YES
+# define XnestServer                   YES
+#endif
+
+#ifndef BuildScreenSaverLibrary
+# define BuildScreenSaverLibrary       YES
+#endif
+
+#ifndef ForceNormalLib
+# define ForceNormalLib                        YES
+#endif
+
+#ifndef BuildDynamicLoading
+# define BuildDynamicLoading           NO
+#endif
+
+/*
+ * XFree86 uses its own (more portable) database routines to speed up 
+ * the RGB database lookups
+ * However, if you want to use ndbm anyway, you can set that to NO in 
+ * site.def
+ */
+#ifndef UseRgbTxt
+# define UseRgbTxt                     YES
+#endif
+
+#ifndef OSBinaryType
+# if UseElfFormat
+#  define OSBinaryType                 [ELF]
+# else 
+#  define OSBinaryType                 /**/
+# endif
+#endif
+
+/* This must come last */
+#include <bsdLib.rules>
+
diff --git a/Xserver/config/cf/README b/Xserver/config/cf/README
new file mode 100644 (file)
index 0000000..b16bd85
--- /dev/null
@@ -0,0 +1,681 @@
+$TOG: README /main/66 1997/05/20 10:05:36 kaleb $
+
+
+
+
+$XFree86: xc/config/cf/README,v 1.1.1.9.2.3 1998/01/23 12:35:07 dawes Exp $
+
+The easiest way to write an Imakefile is to find another one that does
+something similar and copy/modify it!
+
+To change any of these variables, edit the site.def file.
+
+Imake.tmpl provides defaults for the following variables:
+
+       AlternateIncRoot        compiler needs -I to find project includes
+       AlternateUsrLibDir      linker needs -L to find project libraries
+       ArCmd                   command used to create libraries
+       ArCmdBase               program name part of ArCmd
+       ArAddCmd                flags to have ArCmdBase add files to a library
+       ArExtCmd                flags to have ArCmdBase extract files
+       AsCmd                   command used to run assembler
+       BootstrapCFlags         missing cpp symbols needed to get started
+       BourneShell             command used to run Bourne Shell
+       CCsuf                   suffix that C++ source files have
+       CURDIR                  current directory relative to top of sources
+       CcCmd                   command to run C compiler
+       CompressCmd             command to run compress program
+       GzipCmd                 command to run gzip program
+       ConstructMFLAGS         System V option to set MFLAGS make variable
+       CpCmd                   command to copy one file to another
+       CplusplusCmd            command to run C++ compiler
+       CplusplusFilt           command to run C++ name demangler
+       CplusplusYaccCmd        command to produce C++ source from yacc source
+       CppCmd                  command to run C preprocessor
+       CrossCompiling          cross compiling? (not fully supported)
+       DebuggableCDebugFlags   C compiler -I's and -D's to turn on debug info
+       DefaultCCOptions        default special C compiler options
+       DefaultCDebugFlags      debug/optimize flags for programs
+       DefaultUsrBin           program directory used even if PATH not set
+       DependFlags             extra makedepend flags
+       DoRanlibCmd             boolean for system uses ranlib
+       EqnCmd                  command used for eqn
+       ExecableScripts         boolean for systems that can exec() #!/bin/sh
+       ExpandManNames          boolean to expand man pages names to long form
+       ExtraFilesToClean       extra files to remove on make clean
+       ExtraLibraries          system-specific libraries need to link
+       ExtraLoadFlags          system-specific loader flags
+       FileManSuffix           man suffix for file format pages
+       FilesToClean            files to delete in make clean
+       FortranCmd              command to run Fortran compiler
+       FortranDebugFlags       flags for Fortran debug info
+       FortranFlags            Fortran compiler flags
+       HasBSD44Sockets         boolean for system has BSD4.4 sockets
+       HasBsdMake              use the 4.4BSD variant of the make program?
+       HasBsearch              boolean for libc has bsearch()
+       HasBrokenCCForLink      boolean for brain damaged cc driver
+       HasCenterLineC          boolean for system has CenterLine C compiler
+       HasCenterLineCplusplus  boolean for system has CenterLine C++ compiler
+       HasClearmake            use Clearcase's clearmake make program?
+       HasCodeCenter           boolean for system has CodeCenter
+       HasCplusplus            system has a C++ compiler?
+       HasDECnet               system has DECnet?
+       HasFortran              boolean for system has Fortran compiler
+       HasGcc                  boolean for system has GNU gcc compiler
+       HasGcc2                 boolean for system has GNU gcc 2.x compiler
+       HasGcc2ForCplusplus     use gcc 2 for C++ programs?
+       HasGnuMake              use the GNU make program?
+       HasKrb5                 system has Kerberos version 5 support?
+       HasLargeTmp             boolean for system has /tmp space
+       HasLatex                system has LaTeX document preparation software
+       HasLibCrypt             boolean for system has libcrypt
+       HasNdbm                 boolean for system has ndbm routines
+       HasPoll                 use poll() syscall?
+       HasPurify               boolean for system has Purify
+       HasPutenv               boolean for libc has putenv()
+       HasSecureRPC            boolean for Sun Secure RPC
+       HasSetUserContext       boolean for setusercontext()
+       HasSentinel             boolean for system has Sentinel available
+       HasSharedLibraries      boolean for system has shared libraries
+       HasShm                  boolean for System V shared memory
+       HasSockets              boolean for system has BSD sockets
+       HasStrcasecmp           boolean for system implements str[n]casecmp
+       HasStreams              use STREAMS I/O interface?
+       HasSymLinks             boolean for system has symbolic links
+       HasTestCenter           boolean for system has TestCenter
+       HasVarDirectory         boolean for system has /var
+       HasVFork                boolean for system has vfork()
+       HasVoidSignalReturn     boolean for POSIX signal() procs
+       HasZlib                 boolean for system has libz
+       IncRoot                 parent of X11 include directory
+       InstBinFlags            install flags for binaries
+       InstDatFlags            install flags for data files
+       InstIncFlags            install flags for header files
+       InstKmemFlags           install flags for xload to get at /dev/kmem
+       InstLibFlags            install flags for libraries
+       InstManFlags            install flags for manual pages
+       InstPgmFlags            install flags for normal programs
+       InstUidFlags            install flags for xterm to chown /dev/ptys
+       InstallCmd              command to install files
+       Krb5Includes            where to include Kerberos header files from
+       Krb5Libraries           where to load Kerberos libraries from
+       LdCmd                   command to run loader
+       LdCombineFlags          flags for incremental loading
+       LexCmd                  command to run lex
+       LexLib                  library for programs using lex output
+       LintCmd                 command to run lint
+       LintLibFlag             flags to generate lint libraries
+       LintOpts                lint options to control strictness
+       LnCmd                   command to link two files
+       LoaderLibPrefix         loader flags before libraries
+       LocalRulesFile          site-specific file with additional imake rules
+       LocalTmplFile           file with additional imake variables
+       MacroFile               name of machine-dependent config params file
+       MacroIncludeFile        <MacroFile>
+       MakeCmd                 command to run make
+       Malloc0ReturnsNull      boolean for malloc(0) == NULL
+       Malloc0ReturnsNullDefines -D's to build libX11/libXt
+       MathLibrary             library for programs using C math functions
+       MsMacros                macro flag for TroffCmd, normally "-ms"
+       MvCmd                   command to rename a file
+       NdbmDefines             -D's to turn on use of ndbm routines
+       NeedConstPrototoypes    whether const is supported
+       NeedFunctionPrototypes  whether or not to force function prototypes
+       NeedNestedPrototypes    whether nested prototypes are supported
+       NeedVarargsPrototypes   whether varargs prototypes are supported
+       NeedWidePrototypes      whether or not to widen function prototypes
+       NoOpCDebugFlags         C compiler flags to not debug or optimize
+       NoRConst                YES if const for structs of funcs is bad
+       OSMajorVersion          major version number of operating system
+       OSMinorVersion          minor version number of operating system
+       OptimizedCDebugFlags    C compiler flags to turn on optimization
+       PreProcessCmd           command to run /lib/cpp on scripts
+       RanlibCmd               command to clean up libraries
+       RanlibInstFlags         flags to ranlib after copying
+       RmCmd                   command to delete files
+       ShLibDir                directory in which to install shared libraries
+       StandardCppDefines      -D's for running cpp
+       StandardDefines         -D's for running C compiler
+       StandardIncludes        -I's for running C compiler
+       StripInstalledPrograms  boolean for sites that want to install -s
+       SystemV                 boolean for systems that are at least SVR2
+       SystemV4                boolean for SVR4 systems
+       TOPDIR                  relative path to top of sources
+       TagsCmd                 command to run tags
+       TblCmd                  command to run tbl
+       TroffCmd                command to run troff to get PostScript
+       UNCOMPRESSPATH          command to run uncompress
+       UnalignedReferencesAllowed      boolean for unaligned copies ok
+       UsrLibDir               directory in which to install libraries
+       VarDirectory            directory in /var for logs, etc., and config
+       YaccCmd                 command to run yacc
+
+X11.tmpl provides defaults for the following variables:
+
+       AdmDir                  directory containing system log files
+       AllocateLocalDefines    -D's to turn on alloca()
+       BDFTOSNFFILT            command to run bdftosnf
+       BaseExtensionDefines    universal extensions to use
+       BinDir                  directory in which to install programs
+       BuildAppgroup           build AppGroup extension
+       BuildFontServer         build font server
+       BuildFonts              build pcf fonts
+       BuildIncRoot            relative path to location of headers in build
+       BuildIncTop             path from build includes directory to top
+       BuildLBX                build LBX (aka X.fast) server extension
+       BuildPexExt             build PEX server extension and fonts
+       BuildPhigs              build Phigs (obsolete)
+       BuildServer             build X server
+       BuildXAudio             build Audio 
+       BuildXAServer           build Audio server
+       BuildXIE                build X Image Extension
+       BuildDIS                build Document Imaging Subset of XIE
+       BuildXCSecurity         Build Security Extension
+       BuildXInputExt          build X Input extension (requires ddx support,
+                                       which exists only in Xhp)
+       BuildXInputLib          build X Input library
+       BuildXKB                build X Keyboard Extension?
+       BuildXKBlib             build X Keyboard Extension into Xlib?
+       UseXKBInClients         Use XKB functions in normal clients?
+       BuildDBE                build DOUBLE-BUFFER extension
+       BuildMultibuffer        build Multibuffer extension (obsolete)
+       BuildRECORD             Build RECORD extension
+       BuildPlugin             build xrx plug-in for web browsers
+       ConfigDir               install directory for config files
+       ConnectionFlags         -D's for supported transports
+       ContribDir              location of user-contributed sources
+       DebugLibFS              build libFS_d.a
+       DebugLibICE             build libICE_d.a
+       DebugLibPex             build libPEX5_d.a
+       DebugLibSM              build libSM_d.a
+       DebugLibX11             build libX11_d.a
+       DebugLibXau             build libXau_d.a
+       DebugLibXaw             build libXaw_d.a
+       DebugLibXdmcp           build libXdmcp_d.a
+       DebugLibXext            build libXext_d.a
+       DebugLibXi              build libXi_d.a
+       DebugLibXie             build libXie_d.a
+       DebugLibXmu             build libXmu_d.a
+       DebugLibXt              build libXt_d.a
+       DebugLibXtst            build libXtst_d.a
+       DebugLibXag             build libXag_d.a
+       DebugOldX               build liboldX_d.a
+       DefaultFSConfigFile     default font server config file
+       DefaultFontPath         default server font path
+       DefaultRGBDatabase      default server rgb color database
+       DefaultSystemPath       default system xdm PATH environment variable
+       DefaultSystemShell      default /bin/sh
+       DefaultUserPath         default user xdm PATH environment variable
+       DependCmd               command to run makedepend
+       DependDir               build directory containing makedepend program
+       ExtensionDefines        -D's for universal extensions
+       ExtensionOSDefines      -D's for additional extensions
+       FontCompilerFlags       flags for bdftosnf
+       FontDefines             -D's to turn on font options
+       FontDir                 directory in which to install fonts
+       FontFilters             -D's to specify font conversion filters
+       FontOSDefines           -D's for which fonts to support
+       ForceNormalLib          force building of .a in addition to shared lib
+       GzipFontCompression     boolean for using gzip instead of compress
+       HasXdmAuth              boolean for using XDM-AUTHORIZATION-1;
+                                       needs Wraphelp.c, see Release Notes
+       InstallAppDefFiles      install new app defaults files over old?
+       InstallFSConfig         install fs config file over old?
+       InstallLibManPages      boolean for installing library man pages
+       InstallSecurityConfig   install server security policy file over old?
+       InstallXdmConfig        install xdm config files over old?
+       InstallXinitConfig      install xinit config files over old?
+       LibDir                  directory in which to install X11 support files
+       LibManSuffix            man suffix for library pages
+       LibmanDir               directory in which to install library man pages
+       LintlibDir              directory in which to install lint libs
+       ManDir                  directory in which to install program man pages
+       ManDirectoryRoot        parent of man directories relative to root
+       ManPath                 full path of parent directory
+       ManSourcePath           common prefix of man page directories
+       ManSuffix               man suffix for programs
+       NeedDefaultDepLibs      boolean for enabling default DEPLIBS
+       NlsDir                  directory in which to install nls files
+       NormalLibFS             build libFS.a
+       NormalLibICE            build libICE.a
+       NormalLibPex            build libPEX5.a
+       NormalLibPhigs          build libphigs.a
+       NormalLibSM             build libSM.a
+       NormalLibX11            build libX11.a
+       NormalLibXau            build libXau.a
+       NormalLibXaw            build libXaw.a
+       NormalLibXdmcp          build libXdmcp.a
+       NormalLibXext           build libXext.a
+       NormalLibXi             build libXi.a
+       NormalLibXie            build libXie.a
+       NormalLibXmu            build libXmu.a
+       NormalLibXt             build libXt.a
+       NormalLibXtst           build libXtst.a
+       NormalLibXag            build libXag.a
+       NormalOldX              build liboldX.a
+       OsNameDefines           beats me
+       PexApiDir               PEX include file location
+       PexCCOptions            special options for building PEX library
+       PexCDebugFlags          special flags for building PEX library
+       PexClientDefines        special -D's for building PEX clients
+       PexDipexDefines         special -D's for building PEX di files
+       PexPhigsDefines         special -D's for building PEX library
+       PexShmIPC               boolean for using shared memory in phigsmon
+       PhigsInclude            include directory for phigs clients
+       PrimaryScreenResolution resolution of default server screen
+       ProfileLibFS            build libFS_p.a
+       ProfileLibICE           build libICE_p.a
+       ProfileLibPex           build libPEX5_p.a
+       ProfileLibSM            build libSM_p.a
+       ProfileLibX11           build libX11_p.a
+       ProfileLibXau           build libXau_p.a
+       ProfileLibXaw           build libXaw_p.a
+       ProfileLibXdmcp         build libXdmcp_p.a
+       ProfileLibXext          build libXext_p.a
+       ProfileLibXi            build libXi_p.a
+       ProfileLibXie           build libXie_p.a
+       ProfileLibXmu           build libXmu_p.a
+       ProfileLibXt            build libXt_p.a
+       ProfileLibXtst          build libXtst_p.a
+       ProfileLibXag           build libXag_p.a
+       ProfileOldX             build liboldX_p.a
+       ProjectX                version indicating this is the X Window System
+       RemoveTargetProgramByMoving     boolean for rm -f that doesn't
+       SHELLPATH               -D for /bin/sh
+       ServerConfigDir         directory for server security config files
+       ServerDefines           complete -D's for server
+       ServerExtraDefines      special -D's for server
+       ServerOSDefines         OS -D's for server
+       ServerAssertDefines     -DNDEBUG for no assertions, /**/ for assertions
+       SharedLibFS             boolean for making sharable libFS.so
+       SharedLibICE            boolean for making sharable libICE.so
+       SharedLibPex            boolean for making sharable libPEX5.so
+       SharedLibPhigs          boolean for making sharable libphigs.so
+       SharedLibSM             boolean for making sharable libSM.so
+       SharedLibX11            boolean for making sharable libX11.so
+       SharedLibXau            boolean for making sharable libXau.so
+       SharedLibXaw            boolean for making sharable libXaw.so
+       SharedLibXdmcp          boolean for making sharable libXdmcp.so
+       SharedLibXext           boolean for making sharable libXext.so
+       SharedLibXi             boolean for making sharable libXi.so
+       SharedLibXie            boolean for making sharable libXie.so
+       SharedLibXmu            boolean for making sharable libXmu.so
+       SharedLibXt             boolean for making sharable libXt.so
+       SharedLibXtst           boolean for making sharable libXtst.so
+       SharedLibXag            boolean for making sharable libXag.so
+       SharedOldX              boolean for making sharable liboldX.so
+       ShmDefines              MIT-SHM define
+       TwmDir                  directory in which to install twm config files
+       UseCCMakeDepend         boolean for using alternate makedepend script
+       UseRgbTxt               use rgb.txt file as is instead of DBM-compiled
+       VendorHasX11R6_3libXext don't need Security & AppGroup in xrx plug-in
+       XAppLoadDir             directory in which to install app defaults
+       XFileSearchPathBase     base file search path
+       XFileSearchPathDefault  default path to search for app defaults files
+       XInputDefines           XINPUT define
+       XMalloc0ReturnsNullDefines -D's specifically for libX11
+       XawClientDepLibs        DEPLIBS for clients that use Xaw
+       XawClientLibs           LOCAL_LIBRARIES for clients that use Xaw
+       XdmConfigurationSubdirectory    name of default xdm configuration
+       XdmDir                  directory in which to install xdm files
+       XdmServersType          type of xdm Xservers file to install
+       XinitDir                directory in which to install xinit files
+       XPrintDir               parent of X Print server config directory
+       XprtServer              build the X Print server
+       XmanLocalSearchPath     non-standard path for man pages
+       XtErrorPrefix           leading text in XtError() msg; eg. 'X Toolkit '
+       XtWarningPrefix         leading text in XtWarning()msg, same as above
+       XtMalloc0ReturnsNullDefines -D's specifically for libXt
+       ZBDFTOSNFFILT           -D to run uncompress and bdftosnf
+
+
+Library.tmpl provides defaults for the following variables:
+
+       AvoidNullMakeCommand    for makes that spout about $(_NULLCMD_)
+       LibraryCCOptions        special C compiler options for libraries
+       LibraryCDebugFlags      library debug/optimize flags to override defs
+       LibraryCcCmd            command to run C compiler in libraries
+       LibraryCplusplusOptions special C++ options for libraries
+       LibraryCplusplusDebugFlags  library debug/optimize flags for C++
+       LibraryCplusplusCmd     command to run C++ compiler in libraries
+       LibraryDefines          -D's for libraries
+       SeparateSharedCompile   shared and unshared libs use same binaries?
+
+
+Server.tmpl provides defaults for the following variables:
+
+       ServerCCOptions         server C compiler options to override defaults
+       ServerCcCmd             command to run C compiler in server
+       ServerCDebugFlags       server debug/opt compiler flags
+       ServerDefines           server standard -D's
+       InstallServerSetUID     does this system need X server suid to root?
+
+
+Threads.tmpl provides defaults for the following variables:
+
+       LocalThreads            whether to enable multi-threading support
+       LocalThreadsDefines     -D flags needed in this directory
+
+
+An <os>Lib.rules file provides defaults for the following variables:
+
+       HasSharedLibraries      boolean for using shared libraries
+       SharedDataSeparation    boolean indicating separate data/code
+       SharedCodeDef           -D's for compiling shared library files
+       SharedLibraryDef        -D's for defining which kind of shared lib
+       ShLibIncludeFile        location of the <os>Lib.tmpl file
+       SharedLibraryLoadFlags  loader flags when making the library
+       UseExportLists          boolean for using an export list
+       PositionIndependentCFlags               PIC compiler flags for C
+       PositionIndependentCplusplusFlags       PIC compiler flags for C++
+
+         Note: PositionIndependentCplusplusFlags is only required if the 
+         C and C++ compilers use different flags to build PIC code.  The
+         default configuration will try to use PositionIndependentCFlags 
+         for both C and C++ compiles.
+
+An <os>Lib.tmpl file provides defaults for the following variables:
+
+       SharedFSReqs            required libs for libFS.so
+       SharedFSRev             version number for libFS.so
+       SharedICEReqs           required libs for libICE.so
+       SharedICERev            version number for libICE.so
+       SharedOldXReqs          required libs for liboldX.so
+       SharedOldXRev           version number for liboldX.so
+       SharedPexReqs           required libs for libPEX5.so
+       SharedPexRev            version number for libPEX5.so
+       SharedSMReqs            required libs for libSM.so
+       SharedSMRev             version number for libSM.so
+       SharedX11Reqs           required libs for libX11.so
+       SharedX11Rev            version number for libX11.so
+       SharedXauReqs           required libs for libXau.so
+       SharedXauRev            version number for libXau.so
+       SharedXawReqs           required libs for libXaw.so
+       SharedXawRev            version number for libXaw.so
+       SharedXdmcpReqs         required libs for libXdmcp.so
+       SharedXdmcpRev          version number for libXdmcp.so
+       SharedXextReqs          required libs for libXext.so
+       SharedXextRev           version number for libXext.so
+       SharedXiReqs            required libs for libXi.so
+       SharedXiRev             version number for libXi.so
+       SharedXieReqs           required libs for libXie.so
+       SharedXieRev            version number for libXie.so
+       SharedXmuReqs           required libs for libXmu.so
+       SharedXmuRev            version number for libXmu.so
+       SharedXtReqs            required libs for libXt.so
+       SharedXtRev             version number for libXt.so
+       SharedXtstReqs          required libs for libXtst.so
+       SharedXtstRev           version number for libXtst.so
+       SharedXmReqs            required libs for libXm.so
+       SharedXmRev             version number for libXm.so
+       SharedMrmReqs           required libs for libMrm.so
+       SharedMrmRev            version number for libMrm.so
+       SharedUilReqs           required libs for libUil.so
+       SharedUilRev            version number for libUil.so
+       SharedTtReqs            required libs for libtt.so
+       SharedTtRev             version number for libtt.so
+       SharedPamReqs           required libs for libpam.so
+       SharedPamRev            version number for libpam.so
+       SharedDtSvcReqs         required libs for libDtSvc.so
+       SharedDtSvcRev          version number for libDtSvc.so
+       SharedDtSearchReqs      required libs for libDtSearch.so
+       SharedDtSearchRev       version number for libDtSearch.so
+       SharedDtWidgetReqs      required libs for libDtWidget.so
+       SharedDtWidgetRev       version number for libDtWidget.so
+       SharedDtHelpReqs        required libs for libDtHelp.so
+       SharedDtHelpRev         version number for libDtHelp.so
+       SharedDtPrintReqs       required libs for libDtPrint.so
+       SharedDtPrintRev        version number for libDtPrint.so
+       SharedDtTermReqs        required libs for libDtTerm.so
+       SharedDtTermRev         version number for libDtTerm.so
+       SharedDtMrmReqs         required libs for libDtMrm.so
+       SharedDtMrmRev          version number for libDtMrm.so
+
+The following variables are used by some part of the tree:
+
+       AckToolset              programs/Xserver/hw/xfree86
+       BuildChooser            build the xdm chooser program?
+       SharedLibXdmGreet       use xdm shared dynamic greeter library?
+       LatexCmd                command to run LaTeX on a document
+       DvipsCmd                command to turn .dvi file into PostScript
+       MotifBC                 using Motif 1.1.1, 1.1.2, or 1.1.3?
+       GetValuesBC             compat GetValues behavior for broken apps?
+       NeedBerklib             application needs libXbsd?
+       SvgaConfig              default SVGA configuration
+       HasGetReturnAddress     util/memleak
+       HasShadowPasswd         system has getspnam() function
+       XnestServer             build X server with Xlib-based ddx
+       XVirtualFramebufferServer       build X server with virtual memory framebuffer
+       XpRasterDDX             include the raster print ddx driver
+       XpColorPclDDX           include the color PCL print ddx driver
+       XpMonoPclDDX            include the monochrome PCL print ddx driver
+       XpPostScriptDDX         include the PostScript print ddx driver
+       WebServer               host:port of your Web server (see programs/xrx)
+       HtmlDir                 path used by Web server for HTML and RX docs
+       CgiBinDir               path used by Web server for CGI programs
+       ProxyManager            ICE network ID to contact a running proxymngr
+
+
+Make Variables
+
+The following make variables are used by imake rules and may be set in
+an individual Imakefile.
+
+DEFINES                        program-specific -D flags and other arguments
+                       to pass to the C compiler, lint, and makedepend.
+DEPEND_DEFINES         program-specific flags in addition to
+                       $(DEFINES) to pass to lint and makedepend.
+                       This is usually used when there are special
+                       compilation rules for individual files, and
+                       the defines passed to those files affect
+                       makedepend results.  If they can be passed to
+                       all files during the makedepend step without
+                       affecting the results for other files,
+                       DEPEND_DEFINES is used to do that.  Example is
+                       the Xlib Imakefile.
+INCLUDES               program-specific -I flags.
+HEADERS                        .h files to install with "make includes" and
+                       "make install".  If this Imakefile includes
+                       Library.tmpl there are no headers, include
+                       this line instead of a HEADERS definition:
+                       #define LibHeaders NO
+REQUIREDLIBS           when building a shared library, other libraries used
+                       by this library that should be referenced at
+                       link time.
+LINTLIBS               program-specific libraries for lint.
+LOCAL_LDFLAGS          program-specific flags for the linker.
+LOCAL_LIBRARIES                project libraries (usually specified
+                       as -lname) needed by this program.
+                       For example, "-lXt -lXext -lX11".
+                       Used by SimpleProgramTarget and
+                       ComplexProgramTarget* rules.
+                       Do not include any system-specific libraries here.
+SYS_LIBRARIES          system libraries (usually specified
+                       as -lname) needed by this program.
+                       For example "MathLibrary".
+                       Do not include any system-specific libraries
+                       such as "-lnsl" here; they are automatically
+                       added to the link command by the
+                       vendor-specific .cf file.
+SUBDIRS                        for an Imakefile in a directory containing
+                       subdirectories, this names the subdirectories.
+                       Such an Imakefile also needs to #define IHaveSubdirs
+                       and call MakeSubdirs() and DependSubdirs().
+MANSUFFIX              suffix used by InstallManPage* rules.
+                       May be set to $(LIBMANSUFFIX) or $(FILEMANSUFFIX) in
+                       directories for libraries or data files.
+
+
+Rule-specific variables that may be set in an individual Imakefile.
+If you aren't using these rules, you may need variables with a similar
+function, but you need not use these names.  However, following these
+conventions may make your Imakefile easier to read and maintain.
+
+DEPLIBS                        library dependencies for ComplexProgramTarget
+SRCS                   source files used by ComplexProgramTarget and
+                       DependTarget.
+OBJS                   object files used by ComplexProgramTarget
+PROGRAMS               default target used with ComplexProgramTarget_(n)
+SRCS1                  source files used by ComplexProgramTarget_1
+OBJS1                  object files used by ComplexProgramTarget_1
+DEPLIBS1               library dependencies for ComplexProgramTarget_1
+SRCS2                  source files used by ComplexProgramTarget_2
+OBJS2                  object files used by ComplexProgramTarget_2
+DEPLIBS2               library dependencies for ComplexProgramTarget_2
+SRCS3                  source files used by ComplexProgramTarget_3
+OBJS3                  object files used by ComplexProgramTarget_3
+DEPLIBS3               library dependencies for ComplexProgramTarget_3
+
+Variables that can be set on the make command line:
+
+DESTDIR                        directory under which "make install" should
+                       install instead of "/"; used only for testing
+                       "make install" rules.
+FILE                   file for "lint1" target to run lint on.
+CDEBUGFLAGS            -g and/or -O flag to control C compiler optimization.
+CXXDEBUGFLAGS          -g and/or -O flag to control C++ optimization.
+LDSTRIPFLAGS           flag to have linker strip objects (typically -x).
+                       Typically set to the empty string to prevent
+                       the linker from stripping objects; use this
+                       way when setting CDEBUGFLAGS to "-g".
+
+These variables are set in project-specific files such as X11.tmpl.
+They should NOT be set in an Imakefile.  These variables are sometimes
+misused; they are included here to remind Imakefile writers NOT to use
+them:
+
+EXTRA_DEFINES          project-specific -D flags
+EXTRA_INCLUDES         project-specific -I flags
+EXTRA_ICONFIGFILES     Additional project-specific imake config files
+                       to add to ICONFIGFILES.
+                       This is a list of files that define variables
+                       that might affect compilation of some files.
+
+Many other make variables are set up by the imake config files and can
+be used in an Imakefile.  The easiest way to discover them is to look
+at the Makefile generated by an empty Imakefile.
+
+
+Comments
+
+Use C comment syntax in an Imakefile for comments that should not
+appear in the resulting Makefile.
+Use "XCOMM" at the start of each
+line to produce a comment that will appear in the Makefile.
+(The "XCOMM" will
+be translated into the Makefile comment character "#" by imake.)
+Do NOT use "#" as a comment character in Imakefiles; it confuses the C
+preprocessor used by imake on some systems.
+
+
+Imake variables
+
+Don't abuse the variables in X11.tmpl that describe
+particular pieces of X by using them to describe your own subsystems.
+Instead, create new variables that are defaulted using
+Imake.tmpl variables.
+
+
+Examples
+
+Since the easiest way to write an Imakefile is to start with one that
+works, here are some short, easy-to-read Imakefile examples in the X
+distribution:
+
+with subdirs:  config/Imakefile
+library:       lib/Xau/Imakefile
+simple program: programs/xdpyinfo/Imakefile
+complex progs:  programs/xclipboard/Imakefile
+complex prog:  programs/xmodmap/Imakefile
+
+Common Rules
+
+Here are some of the common rules for building programs.  How to use
+them is described in Imake.rules and in the O'Reilly book "Software
+Portability with imake."
+
+Basic program-building rules
+
+All of these except NormalProgramTarget also generate rules to install
+the program and its manual page, and to generate dependencies.
+
+SimpleProgramTarget    Use if there is only one program to be made
+                       and it has only one source file.
+
+ComplexProgramTarget   Use if there is only one program to be made
+                       and it has multiple source files.  Set SRCS to
+                       the names of the source files, set OBJS to
+                       the names of the object files, and set DEPLIBS
+                       to the libraries that this program depends on.
+
+ComplexProgramTarget_1 Like ComplexProgramTarget, but uses SRCS1,
+                       OBJS1, and DEPLIBS1 and can be used with
+                       ComplexProgramTarget_2 and ComplexProgramTarget_3
+                       to build up to three programs in the same directory.
+                       Set PROGRAMS to the programs built by all of
+                       these rules.  For more than 3 programs, use
+                       NormalProgramTarget for each.
+ComplexProgramTarget_2 Use after ComplexProgramTarget_1 for the
+                       second program in a directory.  Uses SRCS2,
+                       OBJS2, and DEPLIBS2.
+ComplexProgramTarget_3 Use after ComplexProgramTarget_2 for the
+                       third program in a directory.  Uses SRCS3,
+                       OBJS3, and DEPLIBS3.
+
+NormalProgramTarget    Build a program.  Can be used multiple times
+                       with different arguments in the same Imakefile.
+
+Lower level rules, often used with NormalProgramTarget
+
+InstallProgram         install a program.
+
+InstallManPage         install a manual page.
+
+DependTarget()         include once at end of Imakefile with
+                       NormalProgramTarget rules or that uses Library.tmpl.
+                       Generates dependencies for files named in SRCS.
+
+Manual page rules, commonly used only in special documentation directories:
+
+InstallManPage
+InstallManPageLong
+InstallManPageAliases
+
+Other rules:
+
+SpecialCObjectRule     Compile a C file with special flags.
+AllTarget              Declare additional targets to build.
+InstallAppDefaults     Install X application defaults file.
+
+Imakefile for directory with subdirectories
+
+XCOMM this is a sample Imakefile for a directory containing subdirectories
+#define IHaveSubdirs
+#define PassCDebugFlags CDEBUGFLAGS="$(CDEBUGFLAGS)"
+SUBDIRS = list of subdirs ...
+MakeSubdirs($(SUBDIRS))
+DependSubdirs($(SUBDIRS))
+
+
+Common Targets
+
+These targets are typically NOT defined explicitly by the Imakefile
+writer; rather they are generated automatically by imake rules.
+They are listed here for the convenience of people using the resulting
+Makefile, not people writing the original Imakefile.
+
+all                    Default rule; builds whatever is in this directory.
+Makefile               Remake the Makefile (use after changing Imakefile).
+                       Run "make depend" after.
+Makefiles              Remake all Makefiles in subdirectories.  (Does
+                       nothing if no subdirectories.)
+                       Run "make depend" after.
+includes               Generate and install in the tree any necessary
+                       header files.
+depend                 Update dependencies in the Makefile calculated
+                       by examining the source files.
+install                        Install what "make all" built on the system.
+install.man            Install manual pages.
+clean                  Remove built objects and other derived files.
+lint                   Run lint.
+tags                   Create a tags file.
diff --git a/Xserver/config/cf/Server.tmpl b/Xserver/config/cf/Server.tmpl
new file mode 100644 (file)
index 0000000..d1c86e0
--- /dev/null
@@ -0,0 +1,95 @@
+/*
+ * Server imakefile info  - this contains any special redefinitions, etc.
+ * that Imakefiles in the server subtree will need.
+ */
+
+XCOMM $XConsortium: Server.tmpl /main/14 1996/04/30 14:37:27 mw $
+XCOMM $XFree86: xc/config/cf/Server.tmpl,v 3.3.2.3 1998/02/07 00:54:21 dawes Exp $
+
+#define PassCDebugFlags CDEBUGFLAGS="$(CDEBUGFLAGS)" LDSTRIPFLAGS="$(LDSTRIPFLAGS)"
+
+#ifndef ServerCcCmd
+#define ServerCcCmd CcCmd
+#endif
+#ifndef ServerCCOptions
+#define ServerCCOptions DefaultCCOptions
+#endif
+#ifndef ServerDefines
+#define ServerDefines StandardDefines
+#endif
+#ifndef ServerCDebugFlags
+#define ServerCDebugFlags DefaultCDebugFlags
+#endif
+#ifndef DoThreadedServer
+#define DoThreadedServer NO
+#endif
+#ifndef XserverNeedsSetUID
+#define XserverNeedsSetUID NO
+#endif
+#ifndef UseXserverWrapper
+#define UseXserverWrapper XserverNeedsSetUID
+#endif
+#ifndef InstallServerSetUID
+#define InstallServerSetUID (XserverNeedsSetUID && !UseXserverWrapper)
+#endif
+
+/*
+ * SetUIDServerTarget - compile, link, and relink a setuid server
+ */
+#ifndef SetUIDServerTarget
+#if InstallServerSetUID
+#define        SetUIDServerTarget(server,subdirs,objects,libs,syslibs)         @@\
+ServerTargetWithFlags(server,subdirs,objects,libs,syslibs,$(INSTUIDFLAGS))
+#else
+#define        SetUIDServerTarget ServerTarget
+#endif
+#endif /* SetUIDServerTarget */
+
+/*
+ * BuildDynamicLoading - dynamic module support
+ */
+#ifndef BuildDynamicLoading
+#define BuildDynamicLoading            NO
+#endif
+
+/*
+ * ExtensionsDynamicModules - compile server extensions as dynamic modules
+ */
+#ifndef ExtensionsDynamicModules
+#define ExtensionsDynamicModules       BuildDynamicLoading
+#endif
+
+#ifndef PexDynamicModule
+#define PexDynamicModule       ExtensionsDynamicModules
+#endif
+#ifndef XieDynamicModule
+#define XieDynamicModule       ExtensionsDynamicModules
+#endif
+#ifndef GlxModule
+#define GlxModule      ExtensionsDynamicModules
+#endif
+
+         CC = ServerCcCmd
+  CCOPTIONS = ServerCCOptions
+#if DoThreadedServer
+SERVER_THREAD_DEFINES = XThreadsDefines ThreadTypeDefines
+#endif
+STD_DEFINES = ServerDefines $(SERVER_THREAD_DEFINES)
+CDEBUGFLAGS = ServerCDebugFlags
+EXT_DEFINES = ExtensionDefines
+
+#if GlxModule | DoLoadableServer
+GLX_DEFINES = GlxDefines -DGLX_MODULE
+#else
+GLX_DEFINES = GlxDefines
+#endif
+
+#ifndef GlxStaticServerLib
+#define GlxStubLib     YES
+#else
+#define GlxStubLib     NO
+#endif
+
+#ifdef XFree86Version
+#include <xf86.tmpl>
+#endif
diff --git a/Xserver/config/cf/ServerLib.tmpl b/Xserver/config/cf/ServerLib.tmpl
new file mode 100644 (file)
index 0000000..fe38049
--- /dev/null
@@ -0,0 +1,141 @@
+XCOMM $XFree86: xc/config/cf/ServerLib.tmpl,v 3.0 1996/10/03 08:28:07 dawes Exp $
+/*
+ * Server Library imakefile info - this contains any special
+ * redefinitions, etc. that Imakefiles in the various server library 
+ * subtrees will need.
+ *
+ * Before including this, you must set the following boolean variables:
+ * DoSharedLib, DoNormalLib, DoDebugLib, DoProfileLib
+ *
+ */
+
+#ifndef DoNormalLib
+#define DoNormalLib    YES
+#endif
+
+#ifndef LibraryDefines
+#define LibraryDefines StandardDefines
+#endif
+#ifndef LibraryCDebugFlags
+#define LibraryCDebugFlags DefaultCDebugFlags
+#endif
+#ifndef SeparateSharedCompile
+#define SeparateSharedCompile YES
+#endif
+#ifndef SharedServerLibraryDef
+#define SharedServerLibraryDef $(__NOOP__)
+#endif
+
+#ifndef LibraryCcCmd
+#if DoSharedLib && defined(SharedLibraryCcCmd)
+#define LibraryCcCmd SharedLibraryCcCmd
+#else
+#define LibraryCcCmd CcCmd
+#endif
+#endif
+#ifndef LibraryCCOptions
+#if DoSharedLib && defined(SharedLibraryCCOptions)
+#define LibraryCCOptions SharedLibraryCCOptions
+#else
+#define LibraryCCOptions DefaultCCOptions
+#endif
+#endif
+
+#if DoDebugLib
+#define _DebuggedLibMkdir() LibMkdir(debugger)
+#define _DebuggedObjCompile(options) DebuggedLibObjCompile(options)
+#define _DebuggedCleanDir() LibCleanDir(debugger)
+#else
+#define _DebuggedLibMkdir() $(_NULLCMD_)
+#define _DebuggedObjCompile(options) $(_NULLCMD_)
+#define _DebuggedCleanDir() $(_NULLCMD_)
+#endif
+
+#if DoProfileLib
+#define _ProfiledLibMkdir() LibMkdir(profiled)
+#define _ProfiledObjCompile(options) ProfiledLibObjCompile(options)
+#define _ProfiledCleanDir() LibCleanDir(profiled)
+#else
+#define _ProfiledLibMkdir() $(_NULLCMD_)
+#define _ProfiledObjCompile(options) $(_NULLCMD_)
+#define _ProfiledCleanDir() $(_NULLCMD_)
+#endif
+
+#if !DoNormalLib
+#define _NormalLibMkdir() $(_NULLCMD_)
+#define _NormalObjCompile(options) $(_NULLCMD_)
+#define _NormalCleanDir() $(_NULLCMD_)
+#else
+#if DoSharedLib && SeparateSharedCompile
+#define _NormalLibMkdir() LibMkdir(unshared)
+#define _NormalObjCompile(options) UnsharedLibObjCompile(options)
+#define _NormalCleanDir() LibCleanDir(unshared)
+#else
+#define _NormalLibMkdir() $(_NULLCMD_)
+#define _NormalObjCompile(options) NormalLibObjCompile(options)
+#define _NormalCleanDir() $(_NULLCMD_)
+#endif
+#endif
+
+#if !DoSharedLib || (DoNormalLib && !SeparateSharedCompile)
+#define _SharedObjCompile(options) $(_NULLCMD_)
+#else
+#if SeparateSharedCompile
+#define _SharedObjCompile(options) NormalSharedLibObjCompile(options)
+#else
+#define _SharedObjCompile(options) NormalLibObjCompile(options)
+#endif
+#endif
+
+#define SRCsuf c
+
+#ifndef LibraryObjectRule
+#define LibraryObjectRule()                                            @@\
+all::                                                                  @@\
+       _DebuggedLibMkdir()                                             @@\
+       _ProfiledLibMkdir()                                             @@\
+       _NormalLibMkdir()                                               @@\
+                                                                       @@\
+includes::                                                             @@\
+       _DebuggedLibMkdir()                                             @@\
+       _ProfiledLibMkdir()                                             @@\
+       _NormalLibMkdir()                                               @@\
+                                                                       @@\
+.SRCsuf.Osuf:                                                          @@\
+       _DebuggedObjCompile($(_NOOP_))                                  @@\
+       _ProfiledObjCompile($(_NOOP_))                                  @@\
+       _NormalObjCompile($(_NOOP_))                                    @@\
+       _SharedObjCompile(SharedServerLibraryDef)                       @@\
+                                                                       @@\
+clean::                                                                        @@\
+       _DebuggedCleanDir()                                             @@\
+       _ProfiledCleanDir()                                             @@\
+       _NormalCleanDir()                                               @@\
+
+#endif /* LibraryObjectRule */
+
+#ifndef SpecialLibObjectRule
+#define SpecialLibObjectRule(objs,depends,options)                     @@\
+objs: depends                                                          @@\
+       _DebuggedObjCompile(options)                                    @@\
+       _ProfiledObjCompile(options)                                    @@\
+       _NormalObjCompile(options)                                      @@\
+       _SharedObjCompile(options)                                      @@\
+
+#endif /* SpecialLibObjectRule */
+
+#ifndef SpecialCLibObjectRule
+#define SpecialCLibObjectRule(basename,depends,options)                        @@\
+SpecialLibObjectRule(basename.Osuf,basename.SRCsuf depends,options)    @@\
+                                                                       @@\
+basename.i: basename.SRCsuf depends                                    @@\
+       CPPOnlyCompile(basename.SRCsuf,options)                         @@\
+                                                                       @@\
+CenterLoadTarget(debug_src,basename.SRCsuf,NullParameter,$(ALLDEFINES) options)
+#endif /* SpecialCLibObjectRule */
+
+#if DoSharedLib
+LibraryObjectRule()
+#else
+NormalLibraryObjectRule()
+#endif
diff --git a/Xserver/config/cf/Threads.tmpl b/Xserver/config/cf/Threads.tmpl
new file mode 100644 (file)
index 0000000..a505fce
--- /dev/null
@@ -0,0 +1,98 @@
+XCOMM $XConsortium: Threads.tmpl /main/11 1996/09/28 16:07:06 rws $
+XCOMM $XFree86: xc/config/cf/Threads.tmpl,v 3.2 1996/12/23 05:50:12 dawes Exp $
+
+/*
+ * For a multi-threaded application or library,
+ * Define LocalThreadsDefines in your Imakefile (unless you like the
+ * project default), then include this file.
+ * Everything else should be automatic. 
+ */
+
+#ifndef LocalThreadsDefines
+#ifdef ProjectThreadsDefines
+#define LocalThreadsDefines ProjectThreadsDefines
+#else
+#define LocalThreadsDefines /**/
+#endif
+#endif
+
+#ifndef LocalThreads
+#ifdef ThreadedProject
+#define LocalThreads ThreadedProject
+#else
+#define LocalThreads YES
+#endif
+#endif
+
+#ifndef ThreadTypeDefines
+#if HasCThreads
+#define ThreadTypeDefines -DCTHREADS
+#else
+#define ThreadTypeDefines /**/
+#endif
+#endif
+#ifndef SystemMTDefines
+#define SystemMTDefines /**/
+#endif
+#ifndef LibraryMTDefines
+#define LibraryMTDefines /**/
+#endif
+#ifndef HasThreadSafeAPI               /* does it have getpwnam_r, etc. */
+#define HasThreadSafeAPI YES
+#endif
+#ifndef MTSafeAPIDefines
+#if HasThreadSafeAPI
+#define MTSafeAPIDefines -DXUSE_MTSAFE_API
+#else
+#define MTSafeAPIDefines /**/
+#endif
+#endif
+#ifndef ThreadPreStdAPIDefines
+#define ThreadPreStdAPIDefines /* nominally for POSIX P1003.4a (Draft 4) API */
+#endif
+#ifndef CplusplusSystemMTDefines
+# ifdef SystemMTDefines
+#  define CplusplusSystemMTDefines SystemMTDefines
+# else
+#  define CplusplusSystemMTDefines /**/
+# endif
+#endif
+#ifndef ThreadsCompileFlags
+#define ThreadsCompileFlags /**/
+#endif
+#ifndef ThreadsCplusplusCompileFlags
+# ifdef ThreadsCompileFlags
+#  define ThreadsCplusplusCompileFlags ThreadsCompileFlags
+# else
+#  define ThreadsCplusplusCompileFlags /**/
+# endif
+#endif
+
+#ifndef ThreadsLibraries
+#define ThreadsLibraries /**/
+#endif
+#ifndef ThreadsCplusplusLibraries
+# ifdef ThreadsLibraries
+#  define ThreadsCplusplusLibraries ThreadsLibraries
+# else
+#  define ThreadsCplusplusLibraries /**/
+# endif
+#endif
+#ifndef ThreadsLoadFlags
+#define ThreadsLoadFlags ThreadsCompileFlags
+#endif
+#ifndef ThreadsCplusplusLoadFlags
+#define ThreadsCplusplusLoadFlags ThreadsCplusplusCompileFlags
+#endif
+
+#if LocalThreads
+    THREADS_CFLAGS = ThreadsCompileFlags
+   THREADS_DEFINES = LocalThreadsDefines ThreadTypeDefines SystemMTDefines MTSafeAPIDefines ThreadPreStdAPIDefines $(LIB_MT_DEFINES)
+   THREADS_LDFLAGS = ThreadsLoadFlags
+      THREADS_LIBS = ThreadsLibraries
+
+  THREADS_CXXFLAGS = ThreadsCplusplusCompileFlags
+THREADS_CXXDEFINES = LocalThreadsDefines ThreadTypeDefines CplusplusSystemMTDefines MTSafeAPIDefines ThreadPreStdAPIDefines $(LIB_MT_DEFINES)
+THREADS_CXXLDFLAGS = ThreadsCplusplusLoadFlags
+   THREADS_CXXLIBS = ThreadsCplusplusLibraries
+#endif
diff --git a/Xserver/config/cf/Win32.cf b/Xserver/config/cf/Win32.cf
new file mode 100644 (file)
index 0000000..c44d528
--- /dev/null
@@ -0,0 +1,128 @@
+XCOMM platform:  $XConsortium: Win32.cf /main/51 1996/12/19 14:20:08 lehors $
+
+#ifndef OSName
+#define OSName                 Microsoft Windows NT 4.0
+#endif
+XCOMM operating system:  OSName
+#ifndef OSMajorVersion
+#define OSMajorVersion         4
+#endif
+#ifndef OSMinorVersion
+#define OSMinorVersion         0
+#endif
+#ifndef OSTeenyVersion
+#define OSTeenyVersion         0
+#endif
+
+#ifndef CompilerMajorVersion
+/* 0 == NT 3.1 Win32 SDK, 2 == MSVC++ 2, 4 == MSVC 4 */
+#define CompilerMajorVersion   4       
+#endif
+
+#define BootstrapCFlags                -DWIN32
+#ifdef _M_IX86
+#define CpuDefines -D_X86_
+#endif
+/* brain-damaged windows headers will not compile with -Za */
+#define StandardDefines -DWIN32 -DWIN32_LEAN_AND_MEAN -D_DLL -D_MT -D__STDC__ CpuDefines
+#if CompilerMajorVersion < 4
+#define DefaultCCOptions -nologo -batch -G4 -W2
+#else
+#define DefaultCCOptions -nologo -G4 -W2
+#endif
+#if CompilerMajorVersion < 4
+#define DebuggableCDebugFlags -Zi
+#else
+#define DebuggableCDebugFlags -Zi -Od
+#endif
+#define ThreadedX              YES
+#define HasThreadSafeAPI       NO
+#define CpCmd copy
+#define LnCmd copy
+#define MvCmd ren
+#define RmCmd del
+#ifndef RmTreeCmd
+/*#define RmTreeCmd del /q /s */
+#define RmTreeCmd rm -rfx
+#endif
+#define CcCmd cl
+#define HasCplusplus           YES
+#define CplusplusCmd cl
+#if CompilerMajorVersion < 4
+#define PreProcessCmd CcCmd -nologo -batch -EP
+#define CppCmd  CcCmd -nologo -batch -E
+#else
+#define PreProcessCmd CcCmd -nologo -EP
+#define CppCmd  CcCmd -nologo -E
+#endif
+#define PatheticCpp            YES
+#define ConstructMFLAGS                YES
+#if (CompilerMajorVersion == 0)
+#define ArCmdBase lib32
+#else
+#define ArCmdBase lib
+#endif
+#define ArCmd ArCmdBase
+#define CplusplusCmd cl
+#define MkdirHierCmd mkdir
+#define InstallCmd copy
+#define InstPgmFlags /**/
+#define InstBinFlags /**/
+#define InstUidFlags /**/
+#define InstLibFlags /**/
+#define InstIncFlags /**/
+#define InstManFlags /**/
+#define InstDatFlags /**/
+#define InstallFlags /**/
+#if (CompilerMajorVersion == 0)
+#define ExtraLibraries crtdll.lib kernel32.lib wsock32.lib
+#elif (CompilerMajorVersion < 4)
+#define ExtraLibraries msvcrt.lib kernel32.lib wsock32.lib
+#else
+#define ExtraLibraries msvcrt.lib kernel32.lib wsock32.lib -link -nodefaultlib:libc
+#endif
+#define MakeCmd nmake -nologo
+#if (CompilerMajorVersion == 0)
+#define LdCmd link32
+#else
+#define LdCmd link
+#endif
+#define MathLibrary
+#define HasSymLinks            NO
+#define HasVarDirectory                NO
+#define HasPutenv              YES
+#define Osuf obj
+#ifndef CCsuf
+#define CCsuf cxx
+#endif
+#define BuildServer            NO
+#define ConnectionFlags                -DTCPCONN
+
+/* override as necessary in site.def/host.def */
+#ifndef StdIncDir
+#define StdIncDir              C:/MSDEVSTD/INCLUDE
+#endif
+#define LdPreLib /**/
+#define LdPostLib /**/
+#ifndef UseInstalled
+#define ImakeCmd $(IMAKESRC:/=\)\imake
+#define DependCmd $(DEPENDSRC:/=\)\makedepend
+#endif
+#define DependFlags -D_WIN32
+#define FilesToClean *.bak *.obj *.lib make.log
+#define ShLibDir $(BINDIR)
+
+#define XFileSearchPathBase Concat4($(LIBDIR)/;L/;T/;N;C,;S:$(LIBDIR)/;l/;T/;N;C,;S:$(LIBDIR)/;T/;N;C,;S:$(LIBDIR)/;L/;T/;N;S:$(LIBDIR)/;l/;T/;N;S:$(LIBDIR)/;T/;N;S)
+
+#define XawI18nDefines         -DHAS_WCHAR_H
+#define UseRgbTxt  YES
+#define HasCbrt NO
+#define HasFfs NO
+#define HasXdmAuth NO
+
+/* the following components haven't been ported yet */
+#define BuildLBX NO
+#define BuildXprint NO
+#define XprtServer NO
+
+#include <Win32.rules>
diff --git a/Xserver/config/cf/Win32.rules b/Xserver/config/cf/Win32.rules
new file mode 100644 (file)
index 0000000..5090686
--- /dev/null
@@ -0,0 +1,528 @@
+XCOMM platform:  $XConsortium: Win32.rules /main/49 1996/12/02 14:12:47 kaleb $
+
+#define HasSharedLibraries YES
+#define NeedLibInsideFlag YES
+#define SharedLibXaw NO
+#define SharedLibXmu NO
+#define SharedLibXt NO
+#define SharedDataSeparation NO
+#define SharedCodeDef /**/
+#define SharedLibraryDef /**/
+#define ShLibIncludeFile <WinLib.tmpl>
+#define SharedLibraryLoadFlags -dll
+#define PositionIndependentCFlags /**/
+
+.c.obj:
+       $(CC) -c $*.c @<<
+       $(CFLAGS)
+<<
+
+#if HasCplusplus
+.CCsuf.obj:
+       $(CXX) -c $*.CCsuf @<<
+       $(CFLAGS)
+<<
+#endif
+
+#define ProgramTargetName(target) target.exe
+
+#define RunProgram(progvar,options) $(progvar:/=\) options
+
+#define RemoveFile(file) if exist file $(RM) file
+
+#define RemoveFiles(files) @$(MAKE) $(MFLAGS) -f <<                    @@\
+.SUFFIXES:                                                             @@\
+                                                                       @@\
+all: files                                                             @@\
+       !for %%i in ( Avoid.Error $$** ) do if exist %%i $(RM) %%i      @@\
+                                                                       @@\
+Avoid.Error files:                                                     @@\
+<<
+
+#define MakeDir(dir) -$(MKDIRHIER) dir
+
+#define ObjectCompile(options) RemoveFile($@)                          @@\
+       $(CC) -c $*.c @<<                                               @@\
+       $(CFLAGS) options                                               @@\
+<<
+
+#define LibObjCompile(dir,options) RemoveFiles($@ dir\$@)              @@\
+       $(CC) -c  $*.c @<<                                              @@\
+       $(CCOPTIONS) $(ALLDEFINES) options                              @@\
+<<                                                                     @@\
+       $(MV) $@ dir\$@
+
+#define BuildIncludesTop(srclist,dstsubdir,dstupdir)                   @@\
+includes:: srclist                                                     @@\
+       MakeDir($(BUILDINCDIR:/=\))                                     @@\
+       @$(MAKE) $(MFLAGS) -f <<                                        @@\
+.SUFFIXES:                                                             @@\
+                                                                       @@\
+all: srclist                                                           @@\
+       cd $(BUILDINCDIR:/=\)                                           @@\
+       !RemoveFile($$**)                                               @@\
+       !$(LN) $(BUILDINCTOP:/=\)\$(CURRENT_DIR:/=\)\$$** .             @@\
+                                                                       @@\
+Avoid.Error srclist:                                                   @@\
+<<
+
+#define BuildIncludes(srclist,dstsubdir,dstupdir)                      @@\
+XVARdef0 = $(BUILDINCDIR)/dstsubdir                                    @@\
+XVARdef1 = $(BUILDINCTOP)/dstupdir/$(CURRENT_DIR)                      @@\
+                                                                       @@\
+includes:: srclist                                                     @@\
+       MakeDir($(XVARuse0:/=\))                                        @@\
+       @$(MAKE) -A $(MFLAGS) -f <<                                     @@\
+.SUFFIXES:                                                             @@\
+                                                                       @@\
+all: srclist                                                           @@\
+       cd $(XVARuse0:/=\)                                              @@\
+       !RemoveFile($$**)                                               @@\
+       !$(LN) $(XVARuse1:/=\)\$$** .                                   @@\
+                                                                       @@\
+Avoid.Error srclist:                                                   @@\
+<<
+
+#define LinkFileList(step,list,dir,sub)                                        @@\
+XVARdef0 = dir                                                         @@\
+XVARdef1 = sub                                                         @@\
+XVARdef2 = list                                                                @@\
+                                                                       @@\
+step:: $(XVARuse2:/=\)                                                 @@\
+       cd $(XVARuse0:/=\)                                              @@\
+       !RemoveFile($**)                                                @@\
+       !$(LN) $(XVARuse1:/=\)\\$** .
+
+#define LinkRule(program,options,objects,libraries) \
+$(CCLINK) Concat(-Fe,program) options objects libraries $(EXTRA_LOAD_FLAGS)
+
+#define NormalProgramTarget(program,objects,deplibs,locallibs,syslibs) @@\
+XVARdef0 = objects                                                     @@\
+                                                                       @@\
+ProgramTargetName(program): $(XVARuse0:.o=.obj) deplibs                        @@\
+       RemoveTargetProgram($@)                                         @@\
+       LinkRule($@,$(LDOPTIONS),$(XVARuse0:.o=.obj),locallibs $(LDLIBS) syslibs) @@\
+                                                                       @@\
+clean::                                                                        @@\
+       RemoveFile(ProgramTargetName(program))
+
+#define ProgramTargetHelper(program,srcs,objs,deplib,locallib,syslib)  @@\
+ProgramTargetName(program): $(objs:.o=.obj) $(deplib)                  @@\
+       RemoveTargetProgram($@)                                         @@\
+       LinkRule($@,$(LDOPTIONS),$(objs:.o=.obj),locallib $(LDLIBS) syslib) @@\
+                                                                       @@\
+InstallProgram(program,$(BINDIR))                                      @@\
+InstallManPage(program,$(MANDIR))
+
+#define ComplexProgramTarget(program)                                  @@\
+PROGRAM = ProgramTargetName(program)                                   @@\
+                                                                       @@\
+AllTarget(ProgramTargetName(program))                                  @@\
+                                                                       @@\
+ProgramTargetHelper(program,SRCS,OBJS,DEPLIBS,$(LOCAL_LIBRARIES),NullParameter) @@\
+                                                                       @@\
+DependTarget()                                                         @@\
+LintTarget()                                                           @@\
+                                                                       @@\
+clean::                                                                        @@\
+       RemoveFile($(PROGRAM))
+
+#define ComplexProgramTarget_1(program,locallib,syslib)                        @@\
+OBJS = $(OBJS1) $(OBJS2) $(OBJS3)                                      @@\
+SRCS = $(SRCS1) $(SRCS2) $(SRCS3)                                      @@\
+PROGRAM1 = ProgramTargetName(program)                                  @@\
+                                                                       @@\
+AllTarget($(PROGRAM1) $(PROGRAM2) $(PROGRAM3))                         @@\
+                                                                       @@\
+ProgramTargetHelper(program,SRCS1,OBJS1,DEPLIBS1,locallib,syslib)      @@\
+                                                                       @@\
+DependTarget()                                                         @@\
+LintTarget()                                                           @@\
+                                                                       @@\
+clean::                                                                        @@\
+       for %%i in ($(PROGRAMS)) do $(RM) ProgramTargetName(%%i)
+
+#define ComplexProgramTarget_2(program,locallib,syslib)                        @@\
+PROGRAM2 = ProgramTargetName(program)                                  @@\
+                                                                       @@\
+ProgramTargetHelper(program,SRCS2,OBJS2,DEPLIBS2,locallib,syslib)
+
+#define ComplexProgramTarget_3(program,locallib,syslib)                        @@\
+PROGRAM3 = ProgramTargetName(program)                                  @@\
+                                                                       @@\
+ProgramTargetHelper(program,SRCS3,OBJS3,DEPLIBS3,locallib,syslib)
+
+#define MoveToBakFile(file) -@if exist file $(MV) file file.bak
+
+#define RMoveToBakFile(file) -RemoveFile(file.bak)                     @@\
+       -@if exist file $(MV) file file.bak
+
+#define InstallMultipleDestFlags(step,list,dest,flags)                 @@\
+XVARdef0 = $(DESTDIR)dest                                              @@\
+                                                                       @@\
+step:: list                                                            @@\
+       MakeDir($(XVARuse0:/=\))                                        @@\
+       !$(INSTALL) $(INSTALLFLAGS) flags $** $(XVARuse0:/=\)
+
+#define        CleanTarget()                                                   @@\
+clean::                                                                        @@\
+       RemoveFiles(FilesToClean ExtraFilesToClean)
+
+#define LibraryTargetName(libname)libname.lib
+
+#define LibraryTargetNameSuffix(libname,suffix)Concat(libname,suffix.lib)
+
+#define MakeLibrary(libname,objlist) $(AR) @<<                         @@\
+-out:libname objlist                                                   @@\
+<<
+
+#define LinkSourceFile(src,dir)                                                @@\
+XVARdef0 = dir/src                                                     @@\
+                                                                       @@\
+src:  $(XVARuse0:/=\)                                                  @@\
+       RemoveFile($@)                                                  @@\
+       $(LN) $? $@                                                     @@\
+                                                                       @@\
+includes:: src                                                         @@\
+                                                                       @@\
+depends:: src                                                          @@\
+                                                                       @@\
+clean::                                                                        @@\
+       RemoveFile(src)
+
+#define LinkFile(tofile,fromfile)                                      @@\
+XVARdef0 = fromfile                                                    @@\
+tofile:: $(XVARuse0:/=\)                                               @@\
+       RemoveFile($@)                                                  @@\
+       $(LN) $? $@                                                     @@\
+                                                                       @@\
+includes:: tofile                                                      @@\
+                                                                       @@\
+depend:: tofile                                                                @@\
+                                                                       @@\
+clean::                                                                        @@\
+       RemoveFile(tofile)
+
+
+#define        NormalLibraryTarget(libname,objlist)                            @@\
+AllTarget(LibraryTargetName(libname))                                  @@\
+                                                                       @@\
+XVARdef0 = objlist                                                     @@\
+                                                                       @@\
+LibraryTargetName(libname): $(XVARuse0:.o=.obj) $(EXTRALIBRARYDEPS)    @@\
+       RemoveFile($@)                                                  @@\
+       MakeLibrary($@,$(XVARuse0:.o=.obj))                             @@\
+       LinkBuildLibrary($@)
+
+#define        NormalLibraryTarget2(libname,objlist1,objlist2)                 @@\
+NormalLibraryTarget(libname,objlist1 objlist2)
+
+#define        NormalLibraryTarget3(libname,objlist1,objlist2,objlist3)        @@\
+NormalLibraryTarget(libname,objlist1 objlist2 objlist3)
+
+#define        NormalDepLibraryTarget(libname,deplist,objlist)                 @@\
+AllTarget(LibraryTargetName(libname))                                  @@\
+                                                                       @@\
+XVARdef0 = deplist                                                     @@\
+XVARdef1 = objlist                                                     @@\
+XVARdef2 = $(XVARuse1:/=\)                                             @@\
+                                                                       @@\
+LibraryTargetName(libname): $(XVARuse0:/=\) $(EXTRALIBRARYDEPS)                @@\
+       RemoveFile($@)                                                  @@\
+       MakeLibrary($@,$(XVARuse2:.o=.obj))                             @@\
+       LinkBuildLibrary($@)
+
+#define        ProfiledLibraryTarget(libname,objlist)                          @@\
+AllTarget(LibraryTargetNameSuffix(libname,_p))                         @@\
+                                                                       @@\
+XVARdef0 = objlist                                                     @@\
+                                                                       @@\
+LibraryTargetNameSuffix(libname,_p): $(XVARuse0:.o=.obj) $(EXTRALIBRARYDEPS)   @@\
+       RemoveFile($@)                                                  @@\
+       cd profiled                                                     @@\
+       MakeLibrary(..\$@,$(XVARuse0:.o=.obj))                          @@\
+       cd ..
+
+#define        DebuggedLibraryTarget(libname,objlist)                          @@\
+AllTarget(LibraryTargetNameSuffix(libname,_d))                         @@\
+                                                                       @@\
+XVARdef0 = objlist                                                     @@\
+                                                                       @@\
+LibraryTargetNameSuffix(libname,_d): $(XVARuse0:.o=.obj) $(EXTRALIBRARYDEPS)   @@\
+       RemoveFile($@)                                                  @@\
+       cd debugger                                                     @@\
+       MakeLibrary(..\$@,$(XVARuse0:.o=.obj))                          @@\
+       cd ..
+
+#ifndef UseInstalled
+#define ImakeDependency(target)                                                @@\
+target:: ProgramTargetName($(IMAKE))                                   @@\
+                                                                       @@\
+ProgramTargetName($(IMAKE)):                                           @@\
+       <<tmp.bat                                                       @@\
+       cd $(IMAKESRC:/=\)                                              @@\
+       if exist Makefile $(MAKE) all                                   @@\
+       if not exist Makefile $(MAKE) -f Makefile.ini BOOTSTRAPCFLAGS="$(BOOTSTRAPCFLAGS)" @@\
+<<
+#endif
+
+#ifndef UseInstalled
+#define DependDependency()                                             @@\
+depend:: ProgramTargetName($(DEPEND))                                  @@\
+                                                                       @@\
+ProgramTargetName($(DEPEND)):                                          @@\
+       <<tmp.bat                                                       @@\
+       cd $(DEPENDSRC:/=\)                                             @@\
+       $(MAKE)                                                         @@\
+<<
+#endif
+
+#define        DependTarget()                                                  @@\
+DependDependency()                                                     @@\
+                                                                       @@\
+depend::                                                               @@\
+       $(DEPEND:/=\) @<<                                               @@\
+$(DEPENDFLAGS) -- $(ALLDEFINES) $(DEPEND_DEFINES) -- $(SRCS)           @@\
+<<
+
+#define        DependTarget3(srcs1,srcs2,srcs3)                                @@\
+DependDependency()                                                     @@\
+                                                                       @@\
+depend::                                                               @@\
+       $(DEPEND:/=\) @<<                                               @@\
+$(DEPENDFLAGS) -- $(ALLDEFINES) $(DEPEND_DEFINES) -- srcs1 srcs2 srcs3 @@\
+<<
+
+#define ForceSubdirs(dirs)                                             @@\
+Avoid.Error dirs: FRC                                                  @@\
+       @cd $@                                                          @@\
+       @echo making all in $(CURRENT_DIR)/$@...                        @@\
+       $(MAKE) $(MFLAGS) PassCDebugFlags all                           @@\
+       cd ..                                                           @@\
+                                                                       @@\
+FRC:
+
+#define MakeMakeSubdirs(dirs,target)                                   @@\
+XVARdef0 = dirs                                                                @@\
+XVARdef1 = $$                                                          @@\
+                                                                       @@\
+target::                                                               @@\
+       @$(MAKE) -A $(MFLAGS) -f <<                                     @@\
+.SUFFIXES:                                                             @@\
+                                                                       @@\
+all: $(XVARuse0:/=\)                                                   @@\
+                                                                       @@\
+Avoid.Error $(XVARuse0:/=\):                                           @@\
+       cd $(XVARuse1)@                                                 @@\
+       RMoveToBakFile(Makefile)                                        @@\
+       ImakeSubCmdHelper -DTOPDIR=../$(TOP) -DCURDIR=$(CURRENT_DIR)/$(XVARuse1)@ @@\
+       $(MAKE) $(MFLAGS) Makefiles                                     @@\
+       cd ..                                                           @@\
+<<
+
+#ifdef UseInstalled
+# define ImakeSubCmdHelper $(IMAKE_CMD)
+#else
+# define ImakeSubCmdHelper ..\$(IMAKE) -I../$(IRULESRC) $(IMAKE_DEFINES)
+#endif
+
+#define NamedTargetSubdirs(name,dirs,verb,flags,subname)               @@\
+XVARdef0 = dirs                                                                @@\
+XVARdef1 = $$                                                          @@\
+                                                                       @@\
+name::                                                                 @@\
+       @$(MAKE) -A $(MFLAGS) -f <<                                     @@\
+.SUFFIXES:                                                             @@\
+                                                                       @@\
+all: $(XVARuse0:/=\)                                                   @@\
+                                                                       @@\
+Avoid.Error $(XVARuse0:/=\):                                           @@\
+       cd $(XVARuse1)@                                                 @@\
+       @echo verb in $(CURRENT_DIR)/$(XVARuse1)@...                    @@\
+       $(MAKE) $(MFLAGS) flags subname                                 @@\
+       cd ..                                                           @@\
+<<
+
+#define UnsharedLibReferences(varname,libname,libsource)               @@\
+Concat3(DEP,varname,LIB) = _UseCat($(USRLIBDIR)/,libsource/,libname.lib) @@\
+Concat(varname,LIB) = LoaderLibPrefix _Use(libname.lib,$(Concat3(DEP,varname,LIB))) @@\
+LintLibReferences(varname,libname,libsource)
+
+#define SharedLibReferences(varname,libname,libsource,revname,rev)     @@\
+revname = rev                                                          @@\
+UnsharedLibReferences(varname,libname,libsource)
+
+#define        SubdirLibraryRule(objlist)                                      @@\
+XVARdef0 = objlist                                                     @@\
+                                                                       @@\
+all:: DONE                                                             @@\
+                                                                       @@\
+DONE: $(XVARuse0:.o=.obj)                                              @@\
+       RemoveFile($@)                                                  @@\
+       echo - > $@                                                     @@\
+                                                                       @@\
+clean::                                                                        @@\
+       RemoveFile(DONE)
+
+#define CppScriptTarget(dst,src,defs,deplist)                          @@\
+dst::                                                                  @@\
+       @echo sorry, unable to make $@
+
+#define CppFileTarget(dst,src,defs,deplist)                            @@\
+XFAKEVAR = X                                                           @@\
+dst::  src deplist                                                     @@\
+       RemoveFile($@)                                                  @@\
+       $(PREPROCESSCMD) -I. <<CppTmpFile.c @<< >$@                     @@\
+       XCOMM define $(XFAKEVAR)COMM XCOMM                              @@\
+       XCOMM include <src>                                             @@\
+<<                                                                     @@\
+       defs                                                            @@\
+<<                                                                     @@\
+                                                                       @@\
+clean::                                                                        @@\
+       RemoveFiles(dst)
+
+#define InstallNamedTarget(step,srcname,flags,dest,dstname)            @@\
+XVARdef0 = $(DESTDIR)dest                                              @@\
+                                                                       @@\
+step:: srcname                                                         @@\
+       MakeDir($(XVARuse0:/=\))                                        @@\
+       $(INSTALL) $(INSTALLFLAGS) flags srcname $(XVARuse0:/=\)\\dstname
+
+#define InstallNamedTargetNoClobber(step,srcname,flags,dest,dstname)   @@\
+XVARdef0 = $(DESTDIR)dest                                              @@\
+                                                                       @@\
+step:: srcname                                                         @@\
+       MakeDir($(XVARuse0:/=\))                                        @@\
+       @if exist $(XVARuse0:/=\)\\dstname echo Not overwriting existing $(XVARuse0:/=\)\\dstname @@\
+       if not exist $(XVARuse0:/=\)\\dstname $(INSTALL) $(INSTALLFLAGS) flags srcname $(XVARuse0:/=\)\\dstname
+
+
+#define        InstallLibrary(libname,dest)                                    @@\
+InstallTarget(install,LibraryTargetName(libname),$(INSTLIBFLAGS),dest)
+
+#define        InstallScript(program,dest) /**/
+
+#define        InstallNamedProg(srcname,dstname,dest)                          @@\
+install:: srcname                                                      @@\
+       @echo sorry, unable to install srcname
+
+#define        InstallSharedLibrary(libname,rev,dest)                          @@\
+InstallTarget(install,LibraryTargetName(libname),$(INSTLIBFLAGS),$(USRLIBDIR)) @@\
+InstallTarget(install,libname.dll,$(INSTLIBFLAGS),dest)
+
+#define        InstallSharedLibraryData(libname,rev,dest)
+
+#define MakeDLL(libname,solist) $(LD) @<<                              @@\
+SharedLibraryLoadFlags -out:libname.dll libname.exp solist             @@\
+<<
+
+#define SharedLibraryTarget(libname,rev,solist,down,up)                        @@\
+AllTarget(libname.dll)                                                 @@\
+                                                                       @@\
+CppFileTarget(libname.def,libname-def.cpp,-DLIBRARY_VERSION=rev,$(ICONFIGFILES)) @@\
+                                                                       @@\
+XVARdef0 = solist                                                      @@\
+                                                                       @@\
+LibraryTargetName(libname): $(XVARuse0:.o=.obj) libname.def $(EXTRALIBRARYDEPS)        @@\
+       RemoveFile($@)                                                  @@\
+       MakeLibrary($@,-def:libname.def $(XVARuse0:.o=.obj))            @@\
+       LinkBuildLibrary($@)                                            @@\
+       RemoveFile(libname.dll)                                         @@\
+       MakeDLL(libname,$(XVARuse0:.o=.obj) $(REQUIREDLIBS) $(EXTRA_LIBRARIES)) @@\
+       LinkBuildDLL(libname.dll)                                       @@\
+                                                                       @@\
+libname.dll: LibraryTargetName(libname) $(EXTRALIBRARYDEPS)            @@\
+       RemoveFile(libname.dll)                                         @@\
+       MakeDLL(libname,$(XVARuse0:.o=.obj) $(REQUIREDLIBS) $(EXTRA_LIBRARIES)) @@\
+       LinkBuildDLL(libname.dll)                                       @@\
+                                                                       @@\
+clean::                                                                        @@\
+       RemoveFile(LibraryTargetName(libname))                          @@\
+       RemoveFile(libname.dll)
+
+#define SharedLibraryDataTarget(libname,rev,salist)
+
+#define ObjectCplusplusCompile(options) RemoveFile($@)                 @@\
+       $(CXX) -c $*.CCsuf @<<                                          @@\
+       $(CFLAGS) options                                               @@\
+<<
+
+#define CplusplusLinkRule LinkRule
+
+#define CplusplusProgramTargetHelper ProgramTargetHelper
+
+#ifndef ComplexCplusplusProgramTarget
+#define        ComplexCplusplusProgramTarget(program)                          @@\
+        PROGRAM = ProgramTargetName(program)                           @@\
+                                                                       @@\
+AllTarget(ProgramTargetName(program))                                  @@\
+                                                                       @@\
+CplusplusProgramTargetHelper(program,SRCS,OBJS,DEPLIBS,$(LOCAL_LIBRARIES),NullParameter) @@\
+                                                                       @@\
+DependTarget()                                                         @@\
+LintTarget()                                                           @@\
+                                                                       @@\
+clean::                                                                        @@\
+       RemoveFile(ProgramTargetName(program))
+#endif /* ComplexCplusplusProgramTarget */
+
+#ifndef UseInstalled
+# define LinkBuildDLL(binary) MakeDir($(BUILDBINDIR:/=\))              @@\
+       RemoveFile(Concat($(BUILDBINDIR:/=\)\,binary))                  @@\
+       cd $(BUILDBINDIR:/=\) && $(LN) Concat($(BUILDBINTOP:/=\)\$(CURRENT_DIR:/=\)\,binary) .
+
+# ifdef LinkBuildBinary
+#  undef LinkBuildBinary
+# endif
+# define LinkBuildBinary(binary)                                       @@\
+all:: $(BUILDBINDIR)\ProgramTargetName(binary) ProgramTargetName(binary) @@\
+                                                                       @@\
+$(BUILDBINDIR)\ProgramTargetName(binary): ProgramTargetName(binary)    @@\
+       MakeDir($(BUILDBINDIR:/=\))                                     @@\
+       RemoveFile($(BUILDBINDIR:/=\)\ProgramTargetName(binary)))       @@\
+       cd $(BUILDBINDIR:/=\) && $(LN) $(BUILDBINTOP:/=\)\$(CURRENT_DIR:/=\)\ProgramTargetName(binary) .
+
+# ifdef LinkBuildLibrary
+#  undef LinkBuildLibrary
+# endif
+# define LinkBuildLibrary(lib) MakeDir($(BUILDLIBDIR:/=\))             @@\
+       RemoveFile(Concat($(BUILDLIBDIR:/=\)\,lib))                     @@\
+       cd $(BUILDLIBDIR:/=\) && $(LN) Concat($(BUILDLIBTOP:/=\)\$(CURRENT_DIR:/=\)\,lib) .
+
+#endif
+
+#ifndef ProjectUnsharedLibReferences
+#define ProjectUnsharedLibReferences(varname,libname,libsource,buildlibdir) @@\
+Concat3(DEP,varname,LIB) = _UseCat($(USRLIBDIR)/lib,buildlibdir/,libname.lib)  @@\
+Concat(varname,LIB) = $(Concat3(DEP,varname,LIB))                      @@\
+LintLibReferences(varname,libname,libsource)
+#endif
+
+
+/*
+ * ServerTargetWithFlags - generate rules to compile, link, and relink a server
+ */
+#ifndef ServerTargetWithFlags
+#define        ServerTargetWithFlags(server,subdirs,objects,libs,syslibs,flags) @@\
+XVARdef0 = objects                                                     @@\
+                                                                       @@\
+AllTarget(ProgramTargetName(server))                                   @@\
+ProgramTargetName(server): subdirs $(XVARuse0:.o=.obj) libs            @@\
+       MoveToBakFile($@)                                               @@\
+       LinkRule($@,$(LDOPTIONS),$(XVARuse0:.o=.obj),libs $(LDLIBS) syslibs) @@\
+                                                                       @@\
+Concat(load,server):                                                   @@\
+       MoveToBakFile(ProgramTargetName(server))                        @@\
+       LinkRule(ProgramTargetName(server),$(LDOPTIONS),$(XVARuse0:.o=.obj),libs $(LDLIBS) syslibs) @@\
+                                                                       @@\
+loadX:: Concat(load,server)                                            @@\
+                                                                       @@\
+ProofProgramTarget(server,subdirs objects libs,objects libs $(LDLIBS) syslibs) @@\
+ProofLinkTarget(Concat(load,server),server,objects libs $(LDLIBS) syslibs) @@\
+                                                                       @@\
+InstallProgramWithFlags(server,$(BINDIR),flags)                                @@\
+                                                                       @@\
+clean::                                                                        @@\
+       RemoveFile(ProgramTargetName(server))
+#endif /* ServerTargetWithFlags */
diff --git a/Xserver/config/cf/WinLib.tmpl b/Xserver/config/cf/WinLib.tmpl
new file mode 100644 (file)
index 0000000..bf13f06
--- /dev/null
@@ -0,0 +1,13 @@
+XCOMM $XConsortium: WinLib.tmpl /main/3 1996/11/13 14:43:09 lehors $
+
+#define SharedOldXReqs $(LDPRELIBS) $(XLIBONLY)
+#define SharedXtReqs $(LDPRELIBS) $(XLIBONLY)
+#define SharedXawReqs $(LDPRELIBS) $(XMULIB) $(XTOOLLIB) $(XLIB)
+#define SharedXmuReqs $(LDPRELIBS) $(XTOOLLIB) $(XLIB)
+#define SharedXextReqs $(LDPRELIBS) $(XLIBONLY)
+#define SharedXiReqs $(LDPRELIBS) $(XLIB)
+#define SharedPexReqs $(LDPRELIBS) $(XLIBONLY) MathLibrary
+#define SharedXtstReqs $(LDPRELIBS) $(XLIB)
+#define SharedXieReqs $(LDPRELIBS) $(XLIBONLY)
+#define SharedSMReqs $(LDPRELIBS) $(ICELIB)
+#define SharedXpReqs $(LDPRELIBS) $(XAUTHLIB) $(EXTENSIONLIB) $(XLIBONLY)
diff --git a/Xserver/config/cf/X11.rules b/Xserver/config/cf/X11.rules
new file mode 100644 (file)
index 0000000..915897d
--- /dev/null
@@ -0,0 +1,102 @@
+XCOMM $TOG: X11.rules /main/4 1997/04/30 15:23:24 kaleb $
+
+/* Note whether we are the top level project. */
+#ifndef SeenTopLevelProject
+# define SeenTopLevelProject   YES
+# define X11IsTopLevelProject  YES
+#else
+# define X11IsTopLevelProject  NO
+#endif
+
+/* 
+ * If no clues are given assume X11 is in the tree, otherwise
+ * UseInstalled overrides UseImports.  Do not do both. 
+ */
+#ifndef UseInstalledX11
+# define UseInstalledX11       NO
+#endif
+#ifdef UseInstalled
+# undef UseInstalledX11
+# define UseInstalledX11       YES
+#endif
+
+#ifndef ImportX11
+# ifdef UseImports
+#  define ImportX11            YES
+# else
+#  define ImportX11            NO
+# endif
+#endif
+#if UseInstalledX11
+# undef ImportX11
+# define ImportX11             NO
+#endif
+
+#ifdef X11ProjectRoot
+# define XUsrLibDirPath        $(USRLIBDIR):$(XPROJECTROOT)/lib
+#else
+# define XUsrLibDirPath        $(USRLIBDIR)
+#endif
+#ifdef UsrLibDirPath
+# undef UsrLibDirPath
+#endif
+#define UsrLibDirPath  XUsrLibDirPath
+
+#if ImportX11
+# define XLdPreLibs    -L$(LIBSRC)
+#elif defined(UseInstalledX11) && defined(X11ProjectRoot)
+# define XLdPreLibs    -L$(XPROJECTROOT)/lib
+#else
+# define XLdPreLibs    /**/
+#endif
+#ifdef LdPreLibs
+# undef LdPreLibs
+#endif
+#define LdPreLibs      LdPreLib XLdPreLibs
+
+#ifdef X11ProjectRoot
+# define XLdPostLibs   -L$(XPROJECTROOT)/lib
+#else
+# define XLdPostLibs   /**/
+#endif
+#ifdef LdPostLibs
+# undef LdPostLibs
+#endif
+#define LdPostLibs     LdPostLib XLdPostLibs
+
+#if ImportX11
+# define TopXInclude   -I$(TOP)/imports/x11/include
+#elif !UseInstalledX11
+# define TopXInclude   -I$(TOP)/exports/include
+#else
+# define TopXInclude   -I$(XPROJECTROOT)/include
+#endif
+#ifdef TopIncludes
+# undef TopIncludes
+#endif
+#define TopIncludes    TopInclude $(TOP_X_INCLUDES)
+
+#if UseInstalledX11 && defined(X11ProjectRoot)
+# define X11BuildLibPath       $(XPROJECTROOT)/lib
+#elif UseInstalledX11
+# define X11BuildLibPath       $(USRLIBDIR)
+#elif ImportX11
+# define X11BuildLibPath       $(XTOP)/lib
+#else
+# define X11BuildLibPath       $(TOP)/exports/lib
+#endif
+#ifdef SystemBuildLibPath
+# define BuildLibPath          $(XENVLIBDIR):$(SYSTEMENVLIBDIR)
+#else
+# define BuildLibPath          $(XENVLIBDIR)
+#endif
+
+#ifndef X11ProjectDefines
+# define X11ProjectDefines     /**/
+#endif
+#define ProjectDefines X11ProjectDefines
+
+#ifndef X11CplusplusProjectDefines
+# define X11CplusplusProjectDefines    X11ProjectDefines
+#endif
+#define CplusplusProjectDefines        X11CplusplusProjectDefines
diff --git a/Xserver/config/cf/X11.tmpl b/Xserver/config/cf/X11.tmpl
new file mode 100644 (file)
index 0000000..4ec1b49
--- /dev/null
@@ -0,0 +1,1815 @@
+XCOMM ----------------------------------------------------------------------
+XCOMM X Window System Build Parameters and Rules
+XCOMM $TOG: X11.tmpl /main/292 1997/05/20 10:05:59 kaleb $
+XCOMM
+XCOMM
+XCOMM
+XCOMM
+XCOMM $XFree86: xc/config/cf/X11.tmpl,v 1.8.2.4 1998/01/23 12:35:08 dawes Exp $
+
+/***************************************************************************
+ *                                                                         *
+ *                            DEFAULT DEFINITIONS                          *
+ *                                                                         *
+ * The following section contains defaults for things that can             *
+ * overridden in the various *.cf and site.def files.  DO NOT EDIT!        *
+ *                                                                         *
+ **************************************************************************/
+
+#define ProjectX               603     /* do *not* change this line */
+
+/* The following project-specific rules are defined at the end of this file:
+ *
+ * InstallAppDefaults          (class)
+ * InstallAppDefaultsLong      (file,class)
+ * MakeFontsDir                        (deplist)
+ * MakeFonts                   ()
+ * InstallFontObjs             (objs,dest)
+ * InstallFonts                        (dest)
+ * InstallFontAliases          (dest)
+ * FontSrc                     (basename)
+ * FontBaseObj                 (basename)
+ * InstallFontScale            (dest)
+ * UncompressedFontTarget      (basename)
+ * CompressedFontTarget                (basename)
+ * FontTarget                  (basename)
+ * FontObj                     (basename)
+ * MakeXkbDir                  (basedir,subdir)
+ */
+
+/*
+ * X-specific things
+ */
+#ifndef HasXServer
+#define HasXServer             YES
+#endif
+#ifndef BuildServer
+#define BuildServer            HasXServer
+#endif
+#ifndef BuildServersOnly
+#define BuildServersOnly       NO
+#endif
+#ifndef BuildFontServer
+#define BuildFontServer                YES
+#endif
+#ifndef BuildFonts
+#define BuildFonts             (BuildServer | BuildFontServer)
+#endif
+#ifndef Build75DpiFonts
+#define Build75DpiFonts                YES
+#endif
+#ifndef Build100DpiFonts
+#define Build100DpiFonts       YES
+#endif
+#ifndef BuildSpeedoFonts
+#define BuildSpeedoFonts       YES
+#endif
+#ifndef BuildType1Fonts
+#define BuildType1Fonts                YES
+#endif
+#ifndef BuildCyrillicFonts
+#define BuildCyrillicFonts     NO
+#endif
+#ifndef UseKoi8RForCyrillic
+#define UseKoi8RForCyrillic    NO
+#endif
+#ifndef HasXAudio
+#define HasXAudio              NO
+#endif
+#ifndef BuildXAudio
+#define BuildXAudio            (HasXAudio & HasCplusplus)
+#endif
+#ifndef HasXAServer
+#define HasXAServer            NO
+#endif
+#ifndef BuildXAServer
+#define BuildXAServer          (HasXAServer & HasCplusplus)
+#endif
+#ifndef BuildMITMiscExt
+#define BuildMITMiscExt                YES
+#endif
+#ifndef BuildTestExt
+#define BuildTestExt           YES
+#endif
+#ifndef BuildSyncExt
+#define BuildSyncExt           YES
+#endif
+#ifndef BuildXCMiscExt
+#define BuildXCMiscExt         YES
+#endif
+#ifndef BuildShapeExt
+#define BuildShapeExt          YES
+#endif
+#ifndef BuildBigReqsExt
+#define BuildBigReqsExt                YES
+#endif
+#ifndef BuildPhigs
+#define BuildPhigs             NO
+#endif
+#ifndef BuildPexExt
+#define BuildPexExt            NO
+#endif
+#ifndef BuildXInputExt
+#define BuildXInputExt         NO
+#endif
+#ifndef BuildDIS
+#define BuildDIS               NO
+#endif
+#ifndef BuildXIE
+#define BuildXIE               YES
+#endif
+#ifndef BuildXIElib
+#define BuildXIElib            BuildXIE
+#endif
+#ifndef BuildXKB
+#define BuildXKB               YES
+#endif
+#ifndef BuildXKBlib
+#define BuildXKBlib            BuildXKB
+#endif
+#ifndef BuildXKBuilib
+#define BuildXKBuilib          BuildXKB
+#endif
+       /*
+        * WARNING: Setting UseXKBInClients to YES cause incompatibilities
+        *          between many clients (such as xterm) and pre-XKB shared
+        *          libraries.
+        */
+#ifndef UseXKBInClients
+#define        UseXKBInClients         NO      /* use XKB in "normal" clients? */
+#endif
+#ifndef BuildDBE
+#define BuildDBE               YES
+#endif
+#ifndef BuildDBElib
+#define BuildDBElib            BuildDBE
+#endif
+#ifndef BuildMultibuffer
+#define BuildMultibuffer       NO
+#endif
+#ifndef BuildRECORD
+#define BuildRECORD            YES
+#endif
+#ifndef BuildRECORDlib
+#define BuildRECORDlib         BuildRECORD
+#endif
+#ifndef BuildLBX
+#define BuildLBX               YES
+#endif
+#ifndef BuildXCSecurity
+#define BuildXCSecurity                YES
+#endif
+#ifndef BuildAppgroup
+#define BuildAppgroup          YES
+#endif
+#ifndef HasPlugin
+#define HasPlugin              NO
+#endif
+#ifndef BuildPlugin
+#define BuildPlugin            HasPlugin
+#endif
+#ifndef XprtServer
+#define XprtServer             BuildServer
+#endif
+#ifndef BuildXprint
+#if XprtServer
+#define BuildXprint            YES
+#else
+#define BuildXprint            NO
+#endif
+#endif
+#ifndef BuildScreenSaverExt
+#define BuildScreenSaverExt    NO
+#endif
+#ifndef BuildScreenSaverLibrary
+#define BuildScreenSaverLibrary        BuildScreenSaverExt
+#endif
+#ifndef BuildXF86VidModeExt
+#define BuildXF86VidModeExt    NO
+#endif
+#ifndef BuildXF86VidModeLibrary
+#define BuildXF86VidModeLibrary BuildXF86VidModeExt
+#endif
+#ifndef BuildXF86MiscExt
+#define BuildXF86MiscExt       NO
+#endif
+#ifndef BuildXF86MiscLibrary
+#define BuildXF86MiscLibrary   BuildXF86MiscExt
+#endif
+#ifndef BuildXF86DGA
+#define BuildXF86DGA           NO
+#endif
+#ifndef BuildXF86DGALibrary
+#define BuildXF86DGALibrary    BuildXF86DGA
+#endif
+#ifndef BuildDPMSExt
+#define BuildDPMSExt           NO
+#endif
+#ifndef BuildDPMSLibrary
+#define BuildDPMSLibrary       BuildDPMSExt
+#endif
+
+#ifndef InstallLibManPages
+#define InstallLibManPages     YES
+#endif
+#ifndef InstallXtermSetUID
+#define InstallXtermSetUID     YES     /* xterm needs to be set uid */
+#endif
+#ifndef InstallXinitConfig
+#define InstallXinitConfig     NO      /* install sample xinit config */
+#endif
+#ifndef InstallXdmConfig
+#define InstallXdmConfig       NO      /* install sample xdm config */
+#endif
+#ifndef XdmServersType                 /* what Xservers files to use */
+#if BuildServer
+#define XdmServersType ws
+#else
+#define XdmServersType fs
+#endif
+#endif
+#ifndef InstallFSConfig
+#define InstallFSConfig                NO      /* install sample fs config */
+#endif
+#ifndef InstallAppDefFiles
+#define InstallAppDefFiles     YES     /* install application defaults */
+#endif
+#ifndef CompressAllFonts
+#define CompressAllFonts       NO
+#endif
+#ifndef ThreadedX
+#if HasPosixThreads || HasCThreads
+#define ThreadedX              YES     /* multi-threaded libraries */
+#else
+#define ThreadedX              NO
+#endif
+#endif
+#ifndef ThreadedProject
+#define ThreadedProject ThreadedX
+#endif
+#ifndef HasWChar32
+#define HasWChar32             SystemV4
+#endif
+#ifndef HasXdmAuth
+#define HasXdmAuth             NO      /* if you can not use XDM-AUTH* */
+#endif
+#ifndef PrimaryScreenResolution
+#define PrimaryScreenResolution 72             /* a common resolution */
+#endif
+#ifndef DefaultFontPath
+#if PrimaryScreenResolution < 88               /* (75 + 100) / 2 */
+#define DefaultFontPath $(FONTDIR)/misc/,$(FONTDIR)/Speedo/,$(FONTDIR)/Type1/,$(FONTDIR)/75dpi/,$(FONTDIR)/100dpi/
+#else
+#define DefaultFontPath $(FONTDIR)/misc/,$(FONTDIR)/Speedo/,$(FONTDIR)/Type1/,$(FONTDIR)/100dpi/,$(FONTDIR)/75dpi/
+#endif
+#endif
+#ifndef DefaultRGBDatabase
+#define DefaultRGBDatabase $(LIBDIR)/rgb
+#endif
+#ifndef UseRgbTxt
+#define UseRgbTxt              NO      /* default is to compile with dbm */
+#endif
+#ifndef UseMemLeak
+#define UseMemLeak             NO
+#endif
+#ifndef SpecialMalloc
+#define SpecialMalloc          NO
+#endif
+#ifndef UseInternalMalloc
+#define UseInternalMalloc      NO
+#endif
+#ifndef FontCompilerFlags
+#define FontCompilerFlags -t
+#endif
+#ifndef ConnectionFlags
+#if HasStreams
+#define ConnectionFlags -DSTREAMSCONN
+#else
+#if HasDECnet
+#define ConnectionFlags -DTCPCONN -DUNIXCONN -DDNETCONN
+#else
+#define ConnectionFlags -DTCPCONN -DUNIXCONN
+#endif
+#endif
+#endif
+#ifndef ProjectThreadsDefines
+#define ProjectThreadsDefines -DXTHREADS
+#endif
+#ifndef FontOSDefines
+#define FontOSDefines /**/
+#endif
+#ifndef FontDefines
+#define FontDefines -DFONT_SNF -DFONT_BDF -DFONT_PCF -DCOMPRESSED_FONTS FontOSDefines
+#endif
+#ifndef XawI18nDefines
+#if SystemV4
+#define XawI18nDefines -DHAS_WCTYPE_H
+#else
+#define XawI18nDefines -DUSE_XWCHAR_STRING
+#endif
+#endif
+#if Malloc0ReturnsNull
+#ifndef XMalloc0ReturnsNullDefines
+#define XMalloc0ReturnsNullDefines Malloc0ReturnsNullDefines
+#endif
+#ifndef XtMalloc0ReturnsNullDefines
+#define XtMalloc0ReturnsNullDefines Malloc0ReturnsNullDefines
+#endif
+#endif
+#ifndef ExtensionOSDefines
+#define ExtensionOSDefines /**/
+#endif
+
+#ifndef ExtensionDefines
+#ifndef MITMiscDefines
+#if BuildMITMiscExt
+#define MITMiscDefines -DMITMISC
+#else
+#define MITMiscDefines /**/
+#endif
+#endif
+#ifndef XTestDefines
+#if BuildTestExt
+#define XTestDefines -DXTEST
+#else
+#define XTestDefines /**/
+#endif
+#endif
+#ifndef XSyncDefines
+#if BuildSyncExt
+#define XSyncDefines -DXSYNC
+#else
+#define XSyncDefines /**/
+#endif
+#endif
+#ifndef XCMiscDefines
+#if BuildXCMiscExt
+#define XCMiscDefines -DXCMISC
+#else
+#define XCMiscDefines /**/
+#endif
+#endif
+#ifndef ShapeDefines
+#if BuildShapeExt
+#define ShapeDefines -DSHAPE
+#else
+#define ShapeDefines /**/
+#endif
+#endif
+#ifndef PexDefines
+#if BuildPexExt
+#define PexDefines -DPEXEXT
+#else
+#define PexDefines /**/
+#endif
+#endif
+#ifndef GlxDefines
+#if BuildGlxExt
+#define GlxDefines -DGLXEXT
+#else
+#define GlxDefines /**/
+#endif
+#endif
+#ifndef ShmDefines
+#if HasShm
+#define ShmDefines -DMITSHM
+#else
+#define ShmDefines /**/
+#endif
+#endif
+#ifndef XInputDefines
+#if BuildXInputExt
+#define XInputDefines -DXINPUT
+#else
+#define XInputDefines /**/
+#endif
+#endif
+#ifndef XieDefines
+#if BuildXIE
+#define XieDefines -DXIE
+#else
+#define XieDefines /**/
+#endif
+#endif
+#ifndef PrintOnlyServer
+#define PrintOnlyServer YES
+#endif
+#ifndef XprintDefines
+#if BuildXprint
+#if PrintOnlyServer
+#define XprintDefines -DPIXPRIV
+#else
+#define XprintDefines -DXPRINT -DPIXPRIV
+#endif
+#else
+#define XprintDefines /**/
+#endif
+#endif
+#ifndef XkbDefines
+#if BuildXKB
+#define XkbDefines -DXKB
+#else
+#define XkbDefines /**/
+#endif
+#endif
+#ifndef XkbClientDefines
+#if UseXKBInClients
+#define XkbClientDefines -DXKB
+#else
+#define XkbClientDefines /**/
+#endif
+#endif
+#ifndef XkbServerDefines
+#define XkbServerDefines /**/
+#endif
+#ifndef LbxDefines
+#if BuildLBX
+#define LbxDefines -DLBX
+#else
+#define LbxDefines /**/
+#endif
+#endif
+#ifndef BigReqDefines
+#if BuildBigReqsExt
+#define BigReqDefines -DBIGREQS
+#else
+#define BigReqDefines /**/
+#endif
+#endif
+
+#ifndef DBEDefines
+#if BuildDBE
+#define DBEDefines -DDBE
+#else
+#define DBEDefines /**/
+#endif
+#endif
+
+#ifndef PervasiveDBEDefines
+#define PervasiveDBEDefines /* -DNEED_DBE_BUF_BITS -DNEED_DBE_BUF_VALIDATE */
+#endif
+
+#ifndef MultibufferDefines
+#if BuildMultibuffer
+#define MultibufferDefines -DMULTIBUFFER
+#else
+#define MultibufferDefines /**/
+#endif
+#endif
+
+#ifndef ScreenSaverExtensionDefines
+#if BuildScreenSaverExt
+#define ScreenSaverExtensionDefines -DSCREENSAVER
+#else
+#define ScreenSaverExtensionDefines /**/
+#endif
+#endif
+#ifndef VidTuneExtensionDefines
+#if BuildXF86VidModeExt
+#define VidTuneExtensionDefines -DXF86VIDMODE
+#else
+#define VidTuneExtensionDefines /**/
+#endif
+#endif
+#ifndef XF86MiscExtensionDefines
+#if BuildXF86MiscExt
+#define XF86MiscExtensionDefines -DXF86MISC
+#else
+#define XF86MiscExtensionDefines /**/
+#endif
+#endif
+
+#ifndef DPMSExtensionDefines
+#if BuildDPMSExt
+#define DPMSExtensionDefines -DDPMSExtension
+#else
+#define DPMSExtensionDefines /**/
+#endif
+#endif
+
+#ifndef RECORDDefines
+#if BuildRECORD
+#define RECORDDefines -DXRECORD
+#else
+#define RECORDDefines /**/
+#endif
+#endif
+
+#ifndef AppgroupDefines
+#if BuildAppgroup
+#define AppgroupDefines -DXAPPGROUP
+#else
+#define AppgroupDefines /**/
+#endif
+#endif
+
+#ifndef XCSecurityDefines
+#if BuildXCSecurity
+#define XCSecurityDefines -DXCSECURITY
+#else
+#define XCSecurityDefines /**/
+#endif
+#endif
+
+#ifndef SitePervasiveExtensionDefines
+#define SitePervasiveExtensionDefines /**/
+#endif
+#ifndef PervasiveExtensionDefines
+#define PervasiveExtensionDefines ShapeDefines XInputDefines XkbDefines \
+                                 LbxDefines AppgroupDefines \
+                                 XCSecurityDefines PervasiveDBEDefines \
+                                 DPMSExtensionDefines \
+                                 XprintDefines SitePervasiveExtensionDefines
+#endif
+#ifndef SiteExtensionDefines
+#define SiteExtensionDefines /**/
+#endif
+#ifndef BaseExtensionDefines
+#define BaseExtensionDefines MultibufferDefines MITMiscDefines XTestDefines \
+                            XSyncDefines XCMiscDefines RECORDDefines \
+                            PexDefines GlxDefines ShmDefines XieDefines BigReqDefines \
+                            VidTuneExtensionDefines XF86MiscExtensionDefines \
+                            DBEDefines ScreenSaverExtensionDefines \
+                            SiteExtensionDefines
+#endif
+#define ExtensionDefines BaseExtensionDefines ExtensionOSDefines
+#endif /* ExtensionDefines */
+
+#ifndef HasStrcasecmp
+#define HasStrcasecmp YES
+#endif
+
+#ifndef StrcasecmpDefines
+# if HasStrcasecmp
+#  define StrcasecmpDefines /**/
+# else
+#  define StrcasecmpDefines -DNEED_STRCASECMP
+# endif
+#endif
+
+#ifndef ServerXdmcpDefines
+#define ServerXdmcpDefines -DXDMCP
+#endif
+#ifndef ServerOSDefines
+#define ServerOSDefines /**/
+#endif
+#if HasKrb5
+#ifndef Krb5Defines
+#define Krb5Defines -DK5AUTH
+#endif
+#else
+#define Krb5Defines /**/
+#endif
+#ifndef ServerExtraDefines
+#define ServerExtraDefines /* -DPIXPRIV */
+#endif
+#ifndef ServerAssertDefines
+#define ServerAssertDefines -DNDEBUG
+#endif
+#ifndef ServerDefines
+#define ServerDefines StandardDefines PervasiveExtensionDefines ServerExtraDefines ServerAssertDefines
+#endif
+#ifndef PexDipexDefines
+#define PexDipexDefines /**/
+#endif
+#ifndef PexDdpexDefines
+#define PexDdpexDefines /**/
+#endif
+#ifndef PexPhigsDefines
+#ifndef PexShmIPC
+#define PexShmIPC HasShm
+#endif
+#if PexShmIPC
+#define PexPhigsDefines /**/
+#else
+#define PexPhigsDefines -DPEX_API_SOCKET_IPC
+#endif
+#endif
+#ifndef PexClientDefines
+#define PexClientDefines -DPEX_SI_PHIGS
+#endif
+#ifndef PhigsInclude
+#ifdef UseInstalled
+#define PhigsInclude -I$(INCDIR)/X11
+#else
+#define PhigsInclude -I$(BUILDINCDIR)
+#endif
+#endif
+#ifndef PexCDebugFlags
+#define PexCDebugFlags DebuggableCDebugFlags
+#endif
+#ifndef PexCCOptions
+#ifdef LibraryCCOptions
+#define PexCCOptions LibraryCCOptions
+#else
+#define PexCCOptions DefaultCCOptions
+#endif
+#endif
+#ifndef DefaultFSConfigFile
+#define DefaultFSConfigFile $(LIBDIR)/fs/config
+#endif
+#ifndef BinDir
+#ifdef ProjectRoot
+#define BinDir Concat(ProjectRoot,/bin)
+#else
+#define BinDir /usr/bin/X11
+#endif
+#endif
+#ifndef BuildIncRoot
+#define BuildIncRoot $(TOP)/exports
+#endif
+#ifndef BuildIncDir
+#define BuildIncDir $(BUILDINCROOT)/include
+#endif
+#ifndef BuildIncTop
+#define BuildIncTop ../..      /* relative to BuildIncDir */
+#endif
+#ifndef XTop
+# if ImportX11
+#  define XTop $(TOP)/imports/x11
+# else
+#  define XTop $(TOP)
+# endif
+#endif
+#ifndef XBuildIncRoot
+# if ImportX11
+#  define XBuildIncRoot        $(XTOP)
+# else
+#  define XBuildIncRoot        $(XTOP)/exports
+# endif
+#endif
+#ifndef XBuildIncDir
+# define XBuildIncDir  $(XBUILDINCROOT)/include/X11
+#endif
+#ifndef XBuildIncTop
+# define XBuildIncTop  ../../..
+#endif
+#ifndef XBuildBinDir
+# define XBuildBinDir  $(XBUILDINCROOT)/bin
+#endif
+#ifndef BuildBinDir
+#define BuildBinDir $(TOP)/exports/bin
+#endif
+#ifndef BuildBinTop
+#define BuildBinTop ../..      /* relative to BuildBinDir */
+#endif
+#ifndef BuildLibDir
+#define BuildLibDir $(TOP)/exports/lib
+#endif
+#ifndef BuildLibTop
+#define BuildLibTop ../..      /* relative to BuildLibDir */
+#endif
+#ifndef LibDir
+#define LibDir $(USRLIBDIR)/X11
+#endif
+#ifndef ConfigDir
+#define ConfigDir $(LIBDIR)/config
+#endif
+#ifndef FontDir
+#define FontDir $(LIBDIR)/fonts
+#endif
+#ifndef AdmDir
+#define AdmDir /usr/adm
+#endif
+#ifndef XinitDir
+#define XinitDir $(LIBDIR)/xinit
+#endif
+#ifndef XdmDir
+#define XdmDir $(LIBDIR)/xdm
+#endif
+#ifndef XdmVarDir
+#define XdmVarDir $(VARLIBDIR)/xdm
+#endif
+#ifndef XdmAuthDir
+#define XdmAuthDir $(LIBDIR)/xdm
+#endif
+#ifndef XdmConfigurationSubdirectory           /* under xdm sources */
+#define XdmConfigurationSubdirectory config
+#endif
+#ifndef TwmDir
+#define TwmDir $(LIBDIR)/twm
+#endif
+#ifndef XsmDir
+#define XsmDir $(LIBDIR)/xsm
+#endif
+#ifndef NlsDir
+#define NlsDir $(LIBDIR)/nls
+#endif
+#ifndef XLocaleDir
+#define XLocaleDir $(LIBDIR)/locale
+#endif
+#ifndef PexApiDir
+#define PexApiDir $(LIBDIR)/PEX
+#endif
+#ifndef LbxproxyDir
+#define LbxproxyDir $(LIBDIR)/lbxproxy
+#endif
+#ifndef LbxproxyConfigSubdir           /* under lbxproxy sources */
+#define LbxproxyConfigSubdir config
+#endif
+#ifndef ProxyManagerDir
+#define ProxyManagerDir $(LIBDIR)/proxymngr
+#endif
+#ifndef XPrintDir
+#define XPrintDir $(LIBDIR)
+#endif
+#ifndef ServerConfigDir
+#define ServerConfigDir $(LIBDIR)/xserver
+#endif
+#ifndef VarDirectory
+#define VarDirectory /var/X11
+#endif
+#ifndef InstallSecurityConfig
+#define InstallSecurityConfig YES      /* Install sample security policy */
+#endif
+#ifndef XFileSearchPathBase
+/* avoid SCCS keyword */
+#define XFileSearchPathBase Concat4($(LIBDIR)/%L/%T/%N%C,%S:$(LIBDIR)/%l/%T/%N%C,%S:$(LIBDIR)/%T/%N%C,%S:$(LIBDIR)/%L/%T/%N%S:$(LIBDIR)/%l/%T/%N%S:$(LIBDIR)/%T/%N%S)
+#endif
+#ifndef XFileSearchPathDefault
+#ifdef XAppLoadDir
+/* avoid SCCS keyword */
+#define XFileSearchPathDefault XAppLoadDir/Concat(%N%C,%S):XAppLoadDir/%N%S:XFileSearchPathBase
+#else
+#define XFileSearchPathDefault XFileSearchPathBase
+#endif
+#endif
+#ifndef XAppLoadDir
+#define XAppLoadDir /etc/app-defaults
+#endif
+#ifndef XtErrorPrefix
+#define XtErrorPrefix /* as empty string */
+#endif
+#ifndef XtExtraDefines
+#define XtExtraDefines /* as empty string */
+#endif
+#ifndef XtWarningPrefix
+#define XtWarningPrefix /* as empty string */
+#endif
+#ifndef OsNameDefines
+#define OsNameDefines /* as nothing */
+#endif
+#ifndef DefaultUserPath                        /* for xdm */
+#define DefaultUserPath :/bin:/usr/bin:$(BINDIR):/usr/ucb
+#endif
+#ifndef DefaultSystemPath              /* for xdm */
+#define DefaultSystemPath /etc:/bin:/usr/bin:$(BINDIR):/usr/ucb
+#endif
+#ifndef DefaultSystemShell             /* for xdm to set in SHELL */
+#define DefaultSystemShell BourneShell
+#endif
+#ifndef ContribDir
+#define ContribDir $(XTOP)/../contrib  /* contrib is outside core tree */
+#endif
+#ifndef UnsupportedDir
+#define UnsupportedDir $(XTOP)/unsupported
+#endif
+#ifndef AllocateLocalDefines
+#define AllocateLocalDefines /**/
+#endif
+
+#ifndef ForceNormalLib
+#define ForceNormalLib (HasGcc && !HasGcc2)
+#endif
+
+#ifndef XkbComp
+#define XkbComp xkbcomp
+#endif
+
+XCOMM -----------------------------------------------------------------------
+XCOMM X Window System make variables; these need to be coordinated with rules
+
+/*
+ * This list must be reflected in the DIRS_TO_BUILD list in the top-level
+ * Makefile.
+ */
+             XTOP = XTop
+           BINDIR = BinDir             /* programs */
+     BUILDINCROOT = BuildIncRoot       /* base of build loc */
+      BUILDINCDIR = BuildIncDir                /* built headers */
+      BUILDINCTOP = BuildIncTop                /* top relative to BUILDINCDIR */
+      BUILDLIBDIR = BuildLibDir                /* built libraries */
+      BUILDLIBTOP = BuildLibTop                /* top relative to BUILDLIBDIR */
+      BUILDBINDIR = BuildBinDir                /* built binaries */
+      BUILDBINTOP = BuildBinTop                /* top relative to BUILDBINDIR */
+    XBUILDINCROOT = XBuildIncRoot      /* base of X build loc */
+     XBUILDINCDIR = XBuildIncDir
+     XBUILDINCTOP = XBuildIncTop
+     XBUILDBINDIR = XBuildBinDir
+           INCDIR = $(INCROOT)         /* header files */
+           ADMDIR = AdmDir             /* server log files */
+           LIBDIR = LibDir             /* rgb, XErrorDB, etc. */
+   TOP_X_INCLUDES = TopXInclude
+
+#ifdef VarDirectory
+           VARDIR = VarDirectory
+#endif
+
+          FONTDIR = FontDir            /* font directories */
+         XINITDIR = XinitDir           /* xinit config files */
+           XDMDIR = XdmDir             /* xdm config files */
+        XDMVARDIR = XdmVarDir          /* xdm config files */
+           TWMDIR = TwmDir             /* twm config files */
+           XSMDIR = XsmDir             /* xsm config files */
+           NLSDIR = NlsDir             /* nls files */
+       XLOCALEDIR = XLocaleDir         /* locale files */
+        PEXAPIDIR = PexApiDir          /* PEX support files */
+      LBXPROXYDIR = LbxproxyDir                /* lbxproxy files */
+  PROXYMANAGERDIR = ProxyManagerDir    /* proxy manager config files */
+        XPRINTDIR = XPrintDir          /* print config file root */
+      XAPPLOADDIR = XAppLoadDir                /* application default resource dir */
+       FONTCFLAGS = FontCompilerFlags
+
+     INSTAPPFLAGS = $(INSTDATFLAGS)    /* XXX - this should go away - XXX */
+
+#if UseInstalledX11
+              RGB = rgb                        /* assume BINDIR in path */
+            FONTC = bdftopcf           /* assume BINDIR in path */
+        MKFONTDIR = mkfontdir          /* assume BINDIR in path */
+#else
+              RGB = $(CLIENTENVSETUP) $(XBUILDBINDIR)/rgb
+            FONTC = $(CLIENTENVSETUP) $(XBUILDBINDIR)/bdftopcf
+        MKFONTDIR = $(CLIENTENVSETUP) $(XBUILDBINDIR)/mkfontdir
+#endif
+
+       DOCUTILSRC = $(XTOP)/doc/util
+        CLIENTSRC = $(TOP)/clients
+          DEMOSRC = $(TOP)/demos
+       XDOCMACROS = $(DOCUTILSRC)/macros.t
+       XIDXMACROS = $(DOCUTILSRC)/indexmacros.t
+       PROGRAMSRC = $(TOP)/programs
+           LIBSRC = $(XTOP)/lib
+          FONTSRC = $(XTOP)/fonts
+       INCLUDESRC = BuildIncDir
+      XINCLUDESRC = $(INCLUDESRC)/X11
+        SERVERSRC = $(XTOP)/programs/Xserver
+       CONTRIBSRC = ContribDir
+   UNSUPPORTEDSRC = UnsupportedDir
+           DOCSRC = $(XTOP)/doc
+           RGBSRC = $(XTOP)/programs/rgb
+      BDFTOPCFSRC = $(PROGRAMSRC)/bdftopcf
+     MKFONTDIRSRC = $(PROGRAMSRC)/mkfontdir
+    FONTSERVERSRC = $(PROGRAMSRC)/xfs
+       FONTINCSRC = $(XTOP)/include/fonts
+        EXTINCSRC = $(XTOP)/include/extensions
+     TRANSCOMMSRC = $(LIBSRC)/xtrans
+   TRANS_INCLUDES = -I$(TRANSCOMMSRC)
+#ifdef X11ProjectRoot
+     XPROJECTROOT = X11ProjectRoot
+#endif
+#if HasSharedLibraries
+#ifndef DontUseLibPathVar
+#ifndef BuildLibPathVar
+#define BuildLibPathVar LD_LIBRARY_PATH
+#endif
+#endif
+#endif
+#ifdef BuildLibPathVar
+# ifdef SystemBuildLibPath
+  SYSTEMENVLIBDIR = SystemBuildLibPath
+# endif
+       XENVLIBDIR = X11BuildLibPath
+   CLIENTENVSETUP = BuildLibPathVar=BuildLibPath
+#else
+   CLIENTENVSETUP = 
+#endif
+
+#ifndef ShLibIncludeFile
+/* need this to make ANSI-style preprocessors happy */
+#define ShLibIncludeFile <noop.rules>
+#endif
+
+#include ShLibIncludeFile
+
+#ifndef XBuildLibDir
+# define XBuildLibDir  BuildLibDir
+#endif
+
+#ifndef SharedLibX11
+#define SharedLibX11 HasSharedLibraries
+#endif
+#ifndef NormalLibX11
+#define NormalLibX11 (!SharedLibX11 | ForceNormalLib)
+#endif
+#ifndef DebugLibX11
+#define DebugLibX11            NO      /* debugged X library */
+#endif
+#ifndef ProfileLibX11
+#define ProfileLibX11          NO      /* profiled X library */
+#endif
+          XLIBSRC = $(LIBSRC)/X11
+#if SharedLibX11
+#ifndef SharedX11Rev
+#define SharedX11Rev 6.1
+#endif
+SharedLibReferences(XONLY,X11,$(XLIBSRC),SOXLIBREV,SharedX11Rev)
+#else
+ProjectUnsharedLibReferences(XONLY,X11,$(XLIBSRC),XBuildLibDir)
+#endif
+         XLIBONLY = $(XONLYLIB)
+
+#if BuildThreadStubLibrary
+#ifndef SharedLibXThrStub
+#define SharedLibXThrStub YES
+#endif
+#ifndef NormalLibXThrStub
+#define NormalLibXThrStub NO
+#endif
+#ifndef DebugLibXThrStub
+#define DebugLibXThrStub NO
+#endif
+#ifndef ProfileLibXThrStub
+#define ProfileLibXThrStub NO
+#endif
+   XTHRSTUBLIBSRC = $(LIBSRC)/XThrStub
+#if SharedLibXThrStub
+#ifndef SharedXThrStubRev
+#define SharedXThrStubRev 6.0
+#endif
+SharedLibReferences(XTHRSTUB,XThrStub,$(XTHRSTUBLIBSRC),SOXTHRSTUBREV,SharedXThrStubRev)
+#else
+ProjectUnsharedLibReferences(XTHRSTUB,XThrStub,$(XTHRSTUBSRC),XBuildLibDir)
+#endif
+#endif
+
+#if BuildScreenSaverLibrary
+#ifndef SharedLibXss
+#define SharedLibXss   NO
+#endif
+#ifndef NormalLibXss
+#define NormalLibXss   YES
+#endif
+#ifndef DebugLibXss
+#define DebugLibXss    NO
+#endif
+#ifndef ProfileLibXss
+#define ProfileLibXss  NO
+#endif
+#endif
+
+#if BuildXF86MiscLibrary
+#ifndef SharedLibXxf86misc
+#define SharedLibXxf86misc     NO
+#endif
+#ifndef NormalLibXxf86misc
+#define NormalLibXxf86misc     YES
+#endif
+#ifndef DebugLibXxf86misc
+#define DebugLibXxf86misc      NO
+#endif
+#ifndef ProfileLibXxf86misc
+#define ProfileLibXxf86misc    NO
+#endif
+#endif
+
+#if BuildXF86VidModeLibrary
+#ifndef SharedLibXxf86vm
+#define SharedLibXxf86vm       NO
+#endif
+#ifndef NormalLibXxf86vm
+#define NormalLibXxf86vm       YES
+#endif
+#ifndef DebugLibXxf86vm
+#define DebugLibXxf86vm                NO
+#endif
+#ifndef ProfileLibXxf86vm
+#define ProfileLibXxf86vm      NO
+#endif
+#endif
+
+#if BuildXF86DGALibrary
+#ifndef SharedLibXxf86dga
+#define SharedLibXxf86dga      NO
+#endif
+#ifndef NormalLibXxf86dga
+#define NormalLibXxf86dga      YES
+#endif
+#ifndef DebugLibXxf86dga
+#define DebugLibXxf86dga       NO
+#endif
+#ifndef ProfileLibXxf86dga
+#define ProfileLibXxf86dga     NO
+#endif
+#endif
+
+#if BuildDPMSLibrary
+#ifndef SharedLibXdpms
+#define SharedLibXdpms         NO
+#endif
+#ifndef NormalLibXdpms
+#define NormalLibXdpms         YES
+#endif
+#ifndef DebugLibXdpms
+#define DebugLibXdpms          NO
+#endif
+#ifndef ProfileLibXdpms
+#define ProfileLibXdpms                NO
+#endif
+#endif
+
+#ifndef SharedLibXext
+#define SharedLibXext HasSharedLibraries
+#endif
+#ifndef NormalLibXext
+#define NormalLibXext (!SharedLibXext | ForceNormalLib)
+#endif
+#ifndef DebugLibXext
+#define DebugLibXext           NO      /* debugged Xext library */
+#endif
+#ifndef ProfileLibXext
+#define ProfileLibXext         NO      /* profiled Xext library */
+#endif
+      XEXTLIBSRC = $(LIBSRC)/Xext
+#if SharedLibXext
+#ifndef SharedXextRev
+#define SharedXextRev 6.3
+#endif
+SharedLibReferences(EXTENSION,Xext,$(XEXTLIBSRC),SOXEXTREV,SharedXextRev)
+#else
+ProjectUnsharedLibReferences(EXTENSION,Xext,$(XEXTLIBSRC),XBuildLibDir)
+#endif
+LINTEXTENSIONLIB = $(LINTEXTENSION)
+          DEPXLIB = $(DEPEXTENSIONLIB) $(DEPXONLYLIB)
+             XLIB = $(EXTENSIONLIB) $(XONLYLIB)
+         LINTXLIB = $(LINTXONLYLIB)
+
+#if BuildScreenSaverLibrary
+    XSSLIBSRC = $(LIBSRC)/Xss
+#if SharedLibXss
+#ifndef SharedXssRev
+#define SharedXssRev 1.0
+#endif
+SharedLibReferences(XSS,Xss,$(XSSLIBSRC),SOXSSREV,SharedXssRev)
+#else
+ProjectUnsharedLibReferences(XSS,Xss,$(XSSLIBSRC),XBuildLibDir)
+#endif
+#endif
+
+#if BuildXF86MiscLibrary
+    XXF86MISCLIBSRC = $(LIBSRC)/Xxf86misc
+#if SharedLibXxf86misc
+#ifndef SharedXxf86miscRev
+#define SharedXxf86miscRev 1.0
+#endif
+SharedLibReferences(XXF86MISC,Xxf86misc,$(XXF86MISCLIBSRC),SOXXF86MISCREV,SharedXxf86miscRev)
+#else
+ProjectUnsharedLibReferences(XXF86MISC,Xxf86misc,$(XXF86MISCLIBSRC),XBuildLibDir)
+#endif
+#endif
+
+#if BuildXF86VidModeLibrary
+    XXF86VMLIBSRC = $(LIBSRC)/Xxf86vm
+#if SharedLibXxf86vm
+#ifndef SharedXxf86vmRev
+#define SharedXxf86vmRev 1.0
+#endif
+SharedLibReferences(XXF86VM,Xxf86vm,$(XXF86VMLIBSRC),SOXXF86VMREV,SharedXxf86vmRev)
+#else
+ProjectUnsharedLibReferences(XXF86VM,Xxf86vm,$(XXF86VMLIBSRC),XBuildLibDir)
+#endif
+#endif
+
+#if BuildXF86DGALibrary
+    XXF86DGALIBSRC = $(LIBSRC)/Xxf86dga
+#if SharedLibXxf86dga
+#ifndef SharedXxf86dgaRev
+#define SharedXxf86dgaRev 1.0
+#endif
+SharedLibReferences(XXF86DGA,Xxf86dga,$(XXF86DGALIBSRC),SOXXF86DGAREV,SharedXxf86dgaRev)
+#else
+ProjectUnsharedLibReferences(XXF86DGA,Xxf86dga,$(XXF86DGALIBSRC),XBuildLibDir)
+#endif
+#endif
+
+#if BuildDPMSLibrary
+    XDPMSLIBSRC = $(LIBSRC)/Xdpms
+#if SharedLibXdpms
+#ifndef SharedXdpmsRev
+#define SharedXdpmsRev 1.0
+#endif
+SharedLibReferences(XDPMS,Xdpms,$(XDPMSLIBSRC),SOXDPMSREV,SharedXdpmsRev)
+#else
+ProjectUnsharedLibReferences(XDPMS,Xdpms,$(XDPMSLIBSRC),XBuildLibDir)
+#endif
+#endif
+
+#ifndef SharedLibXau
+#define SharedLibXau NO                /* don't need shared form */
+#endif
+#ifndef NormalLibXau
+#define NormalLibXau (!SharedLibXau | ForceNormalLib)
+#endif
+#ifndef DebugLibXau
+#define DebugLibXau            NO      /* debugged auth library */
+#endif
+#ifndef ProfileLibXau
+#define ProfileLibXau          NO      /* profiled auth library */
+#endif
+         XAUTHSRC = $(LIBSRC)/Xau
+#if SharedLibXau
+#ifndef SharedXauRev
+#define SharedXauRev 6.0
+#endif
+SharedLibReferences(XAUTH,Xau,$(XAUTHSRC),SOXAUTHREV,SharedXauRev)
+#else
+ProjectUnsharedLibReferences(XAUTH,Xau,$(XAUTHSRC),XBuildLibDir)
+#endif
+
+#ifndef SharedLibXdmcp
+#define SharedLibXdmcp NO      /* don't need shared form */
+#endif
+#ifndef NormalLibXdmcp
+#define NormalLibXdmcp (!SharedLibXdmcp | ForceNormalLib)
+#endif
+#ifndef DebugLibXdmcp
+#define DebugLibXdmcp          NO      /* debugged XDMCP library */
+#endif
+#ifndef ProfileLibXdmcp
+#define ProfileLibXdmcp                NO      /* profiled XDMCP library */
+#endif
+      XDMCPLIBSRC = $(LIBSRC)/Xdmcp
+#if SharedLibXdmcp
+#ifndef SharedXdmcpRev
+#define SharedXdmcpRev 6.0
+#endif
+SharedLibReferences(XDMCP,Xdmcp,$(XDMCPLIBSRC),SOXDMCPREV,SharedXdmcpRev)
+#else
+ProjectUnsharedLibReferences(XDMCP,Xdmcp,$(XDMCPLIBSRC),XBuildLibDir)
+#endif
+
+#ifndef SharedLibXmu
+#define SharedLibXmu HasSharedLibraries
+#endif
+#ifndef NormalLibXmu
+#define NormalLibXmu (!SharedLibXmu | ForceNormalLib)
+#endif
+#ifndef DebugLibXmu
+#define DebugLibXmu            NO      /* debugged Xmu library */
+#endif
+#ifndef ProfileLibXmu
+#define ProfileLibXmu          NO      /* profiled Xmu library */
+#endif
+           XMUSRC = $(LIBSRC)/Xmu
+#if SharedLibXmu
+#ifndef SharedXmuRev
+#define SharedXmuRev 6.0
+#endif
+SharedDSLibReferences(XMU,Xmu,$(XMUSRC),SOXMUREV,SharedXmuRev)
+#else
+ProjectUnsharedLibReferences(XMU,Xmu,$(XMUSRC),XBuildLibDir)
+#endif
+
+#ifndef SharedOldX
+#define SharedOldX HasSharedLibraries
+#endif
+#ifndef NormalOldX
+#define NormalOldX (!SharedOldX | ForceNormalLib)
+#endif
+#ifndef DebugOldX
+#define DebugOldX              NO      /* debugged old X library */
+#endif
+#ifndef ProfileOldX
+#define ProfileOldX            NO      /* profiled old X library */
+#endif
+       OLDXLIBSRC = $(LIBSRC)/oldX
+#if SharedOldX
+#ifndef SharedOldXRev
+#define SharedOldXRev 6.0
+#endif
+SharedLibReferences(OLDX,oldX,$(OLDXLIBSRC),SOOLDXREV,SharedOldXRev)
+#else
+ProjectUnsharedLibReferences(OLDX,oldX,$(OLDXLIBSRC),XBuildLibDir)
+#endif
+
+#ifndef SharedLibXp
+#define SharedLibXp HasSharedLibraries
+#endif
+#ifndef NormalLibXp
+#define NormalLibXp (!SharedLibXp | ForceNormalLib)
+#endif
+#ifndef DebugLibXp
+#define DebugLibXp              NO      /* debugged Xp library */
+#endif
+#ifndef ProfileLibXp
+#define ProfileLibXp            NO      /* profiled Xp library */
+#endif
+         XPLIBSRC = $(LIBSRC)/Xp
+#if SharedLibXp
+#ifndef SharedXpRev
+#define SharedXpRev 6.2
+#endif
+SharedLibReferences(XP,Xp,$(XPLIBSRC),SOXPREV,SharedXpRev)
+#else
+ProjectUnsharedLibReferences(XP,Xp,$(XPLIBSRC),XBuildLibDir)
+#endif
+
+#ifndef SharedLibXt
+#define SharedLibXt HasSharedLibraries
+#endif
+#ifndef NormalLibXt
+#define NormalLibXt (!SharedLibXt | ForceNormalLib)
+#endif
+#ifndef DebugLibXt
+#define DebugLibXt             NO      /* debugged toolkit library */
+#endif
+#ifndef ProfileLibXt
+#define ProfileLibXt           NO      /* profiled toolkit library */
+#endif
+       TOOLKITSRC = $(LIBSRC)/Xt
+#if SharedLibXt
+#ifndef SharedXtRev
+#define SharedXtRev 6.0
+#endif
+SharedDSLibReferences(XTOOLONLY,Xt,$(TOOLKITSRC),SOXTREV,SharedXtRev)
+#else
+ProjectUnsharedLibReferences(XTOOLONLY,Xt,$(TOOLKITSRC),XBuildLibDir)
+#endif
+      DEPXTOOLLIB = $(DEPXTOOLONLYLIB) $(DEPSMLIB) $(DEPICELIB)
+         XTOOLLIB = $(XTOOLONLYLIB) $(SMLIB) $(ICELIB)
+     LINTXTOOLLIB = $(LINTXTOOLONLYLIB)
+
+#ifndef SharedLibXa
+#define SharedLibXa    (HasSharedLibraries & HasCplusplus)
+#endif
+#ifndef NormalLibXa
+/* #define NormalLibXa ((!SharedLibXa | ForceNormalLib) & HasCplusplus) */
+#define NormalLibXa    YES /* needed for current tests, will correct later */
+#endif
+#ifndef DebugLibXa
+#define DebugLibXa     NO      /* debugged audio library */
+#endif
+#ifndef ProfileLibXa
+#define ProfileLibXa   NO      /* profiled audio library */
+#endif
+       XALIBSRC = $(LIBSRC)/Xa
+#if SharedLibXa
+#ifndef SharedXaRev
+#define SharedXaRev 1.0
+#endif
+SharedLibReferences(XA,Xa,$(XALIBSRC),SOXAREV,SharedXaRev)
+#else
+UnsharedLibReferences(XA,Xa,$(XALIBSRC))
+#endif
+
+#ifndef SharedLibXaw
+#define SharedLibXaw HasSharedLibraries
+#endif
+#ifndef NormalLibXaw
+#define NormalLibXaw (!SharedLibXaw | ForceNormalLib)
+#endif
+#ifndef DebugLibXaw
+#define DebugLibXaw            NO      /* debugged widget library */
+#endif
+#ifndef ProfileLibXaw
+#define ProfileLibXaw          NO      /* profiled widget library */
+#endif
+       AWIDGETSRC = $(LIBSRC)/Xaw
+#if SharedLibXaw
+#ifndef SharedXawRev
+#define SharedXawRev 6.1
+#endif
+SharedDSLibReferences(XAW,Xaw,$(AWIDGETSRC),SOXAWREV,SharedXawRev)
+#else
+ProjectUnsharedLibReferences(XAW,Xaw,$(AWIDGETSRC),XBuildLibDir)
+#endif
+
+#ifndef SharedLibXi
+#define SharedLibXi HasSharedLibraries
+#endif
+#ifndef NormalLibXi
+#define NormalLibXi (!SharedLibXi | ForceNormalLib)
+#endif
+#ifndef DebugLibXi
+#define DebugLibXi             NO      /* debugged Xi library */
+#endif
+#ifndef ProfileLibXi
+#define ProfileLibXi           NO      /* profiled Xi library */
+#endif
+         XILIBSRC = $(LIBSRC)/Xi
+#if SharedLibXi
+#ifndef SharedXiRev
+#define SharedXiRev 6.0
+#endif
+SharedLibReferences(XI,Xi,$(XILIBSRC),SOXINPUTREV,SharedXiRev)
+#else
+ProjectUnsharedLibReferences(XI,Xi,$(XILIBSRC),XBuildLibDir)
+#endif
+
+#ifndef SharedLibXtst
+#define SharedLibXtst HasSharedLibraries
+#endif
+#ifndef NormalLibXtst
+#define NormalLibXtst (!SharedLibXtst | ForceNormalLib)
+#endif
+#ifndef DebugLibXtst
+#define DebugLibXtst           NO      /* debugged Xtst library */
+#endif
+#ifndef ProfileLibXtst
+#define ProfileLibXtst         NO      /* profiled Xtst library */
+#endif
+      XTESTLIBSRC = $(LIBSRC)/Xtst
+#if SharedLibXtst
+#ifndef SharedXtstRev
+#define SharedXtstRev 6.1
+#endif
+SharedLibReferences(XTEST,Xtst,$(XTESTLIBSRC),SOXTESTREV,SharedXtstRev)
+#else
+ProjectUnsharedLibReferences(XTEST,Xtst,$(XTESTLIBSRC),XBuildLibDir)
+#endif
+
+#ifndef SharedLibPex
+#define SharedLibPex HasSharedLibraries
+#endif
+#ifndef NormalLibPex
+#define NormalLibPex (!SharedLibPex | ForceNormalLib)
+#endif
+#ifndef DebugLibPex
+#define DebugLibPex            NO      /* debugged PEX5 library */
+#endif
+#ifndef ProfileLibPex
+#define ProfileLibPex          NO      /* profiled PEX5 library */
+#endif
+        PEXLIBSRC = $(LIBSRC)/PEX5
+#if SharedLibPex
+#ifndef SharedPexRev
+#define SharedPexRev 6.0
+#endif
+SharedLibReferences(PEX,PEX5,$(PEXLIBSRC),SOPEXREV,SharedPexRev)
+#else
+ProjectUnsharedLibReferences(PEX,PEX5,$(PEXLIBSRC),XBuildLibDir)
+#endif
+
+#ifndef SharedLibXie
+#define SharedLibXie HasSharedLibraries
+#endif
+#ifndef NormalLibXie
+#define NormalLibXie (!SharedLibXie | ForceNormalLib)
+#endif
+#ifndef DebugLibXie
+#define DebugLibXie            NO      /* debugged XIE library */
+#endif
+#ifndef ProfileLibXie
+#define ProfileLibXie          NO      /* profiled XIE library */
+#endif
+        XIELIBSRC = $(LIBSRC)/XIE
+#if SharedLibXie
+#ifndef SharedXieRev
+#define SharedXieRev 6.0
+#endif
+SharedLibReferences(XIE,XIE,$(XIELIBSRC),SOXIEREV,SharedXieRev)
+#else
+ProjectUnsharedLibReferences(XIE,XIE,$(XIELIBSRC),XBuildLibDir)
+#endif
+
+#ifndef SharedLibPhigs
+#define SharedLibPhigs NO      /* XXX - haven't made it sharable yet */
+#endif
+#ifndef NormalLibPhigs
+#define NormalLibPhigs (!SharedLibPhigs | ForceNormalLib)
+#endif
+      PHIGSLIBSRC = $(LIBSRC)/PHIGS
+#if SharedLibPhigs
+#ifndef SharedPhigsRev
+#define SharedPhigsRev 6.0
+#endif
+SharedLibReferences(PHIGS,phigs,$(PHIGSLIBSRC),SOPHIGSREV,SharedPhigsRev)
+#else
+ProjectUnsharedLibReferences(PHIGS,phigs,$(PHIGSLIBSRC),XBuildLibDir)
+#endif
+
+ProjectUnsharedLibReferences(XBSD,Xbsd,$(LIBSRC)/Xbsd,XBuildLibDir)
+
+#ifndef SharedLibICE
+#define SharedLibICE HasSharedLibraries
+#endif
+#ifndef NormalLibICE
+#define NormalLibICE (!SharedLibICE | ForceNormalLib)
+#endif
+#ifndef DebugLibICE
+#define DebugLibICE            NO      /* debugged ICE library */
+#endif
+#ifndef ProfileLibICE
+#define ProfileLibICE          NO      /* profiled ICE library */
+#endif
+           ICESRC = $(LIBSRC)/ICE
+#if SharedLibICE
+#ifndef SharedICERev
+#define SharedICERev 6.3
+#endif
+SharedLibReferences(ICE,ICE,$(ICESRC),SOICEREV,SharedICERev)
+#else
+ProjectUnsharedLibReferences(ICE,ICE,$(ICESRC),XBuildLibDir)
+#endif
+
+#ifndef SharedLibSM
+#define SharedLibSM HasSharedLibraries
+#endif
+#ifndef NormalLibSM
+#define NormalLibSM (!SharedLibSM | ForceNormalLib)
+#endif
+#ifndef DebugLibSM
+#define DebugLibSM             NO      /* debugged SM library */
+#endif
+#ifndef ProfileLibSM
+#define ProfileLibSM           NO      /* profiled SM library */
+#endif
+            SMSRC = $(LIBSRC)/SM
+#if SharedLibSM
+#ifndef SharedSMRev
+#define SharedSMRev 6.0
+#endif
+SharedLibReferences(SM,SM,$(SMSRC),SOSMREV,SharedSMRev)
+#else
+ProjectUnsharedLibReferences(SM,SM,$(SMSRC),XBuildLibDir)
+#endif
+
+#ifndef SharedLibXkey
+#define SharedLibXkey HasSharedLibraries
+#endif
+#ifndef NormalLibXkey
+#define NormalLibXkey (!SharedLibXkey | ForceNormalLib)
+#endif
+#ifndef DebugLibXkey
+#define DebugLibXkey           NO      /* debugged Xkey library */
+#endif
+#ifndef ProfileLibXkey
+#define ProfileLibXkey         NO      /* profiled Xkey library */
+#endif
+           XKEYSRC = $(LIBSRC)/Xkey
+#if SharedLibXkey
+#ifndef SharedXkeyRev
+#define SharedXkeyRev 6.0
+#endif
+SharedLibReferences(XKEY,Xkey,$(XKEYSRC),SOXKEYREV,SharedXkeyRev)
+#else
+ProjectUnsharedLibReferences(XKEY,Xkey,$(XKEYSRC),XBuildLibDir)
+#endif
+
+#ifndef SharedLibFS
+#define SharedLibFS            NO      /* for now */
+#endif
+#ifndef NormalLibFS
+#define NormalLibFS (!SharedLibFS | ForceNormalLib)
+#endif
+#ifndef DebugLibFS
+#define DebugLibFS             NO      /* debugged FS library */
+#endif
+#ifndef ProfileLibFS
+#define ProfileLibFS           NO      /* profiled FS library */
+#endif
+         FSLIBSRC = $(LIBSRC)/FS
+#if SharedLibFS
+#ifndef SharedFSRev
+#define SharedFSRev 6.0
+#endif
+SharedLibReferences(FS,FS,$(FSLIBSRC),SOFSREV,SharedFSRev)
+#else
+ProjectUnsharedLibReferences(FS,FS,$(FSLIBSRC),XBuildLibDir)
+#endif
+
+         FONTLIBSRC = $(LIBSRC)/font
+ProjectUnsharedLibReferences(FONT,font,$(FONTLIBSRC),XBuildLibDir)
+
+          XPMLIBSRC = $(LIBSRC)/Xpm
+#if SharedLibXpm
+#ifndef SharedXpmRev
+#define SharedXpmRev 4.8
+#endif
+SharedLibReferences(XPM,Xpm,$(XPMLIBSRC),SOXPMREV,SharedXpmRev)
+#else
+ProjectUnsharedLibReferences(XPM,Xpm,$(XPMLIBSRC),XBuildLibDir)
+#endif
+
+#ifndef LdLibraryPath
+#define LdLibraryPath LD_LIBRARY_PATH
+#endif
+
+#ifdef BuildXKBlib
+    XKBFILELIBSRC = $(LIBSRC)/xkbfile
+ProjectUnsharedLibReferences(XKBFILE,xkbfile,$(XKBFILELIBSRC),XBuildLibDir)
+#ifndef XkbClientDepLibs
+#if UseXKBInClients
+#define XkbClientDepLibs $(DEPXKBFILELIB)
+#else
+#define XkbClientDepLibs /**/
+#endif
+#endif
+#ifndef XkbClientLibs
+#if UseXKBInClients
+#define XkbClientLibs $(XKBFILELIB)
+#else
+#define XkbClientLibs /**/
+#endif
+#endif
+#if defined(UseInstalled) || defined(OS2Architecture)
+     XKBCOMPCMD = XkbComp                       /* assume BINDIR in path */
+#else
+     XKBCOMPSRC = $(PROGRAMSRC)/xkbcomp
+     XKBCOMPCMD = $(CLIENTENVSETUP) $(XKBCOMPSRC)/xkbcomp
+#endif
+#else /* !BuildXKBlib */
+#ifndef XkbClientDepLibs
+#define XkbClientDepLibs
+#endif
+#ifndef XkbClientLibs
+#define XkbClientLibs
+#endif
+#endif /* BuildXKBlib */
+
+#ifdef BuildXKBuilib
+    XKBUILIBSRC = $(LIBSRC)/xkbui
+ProjectUnsharedLibReferences(XKBUI,xkbui,$(XKBUILIBSRC),XBuildLibDir)
+#ifndef XkbuiLibs
+#define        XkbuiLibs $(XKBUILIB)
+#endif
+#ifndef XkbuiDepLibs
+#define        XkbuiDepLibs $(DEPXKBFILELIB)
+#endif
+#else /* !BuildXKBuilib */
+#ifndef XkbuiLibs
+#define        XkbuiLibs
+#endif
+#ifndef XkbuiDepLibs
+#define        XkbuiDepLibs
+#endif
+#endif /* BuildXKBuilib */
+
+#ifndef XawClientDepLibs
+#define XawClientDepLibs $(DEPXAWLIB) $(DEPXMULIB) $(DEPXTOOLLIB) $(DEPXLIB)
+#endif
+#ifndef XawClientLibs
+#define XawClientLibs $(XAWLIB) $(XMULIB) $(XTOOLLIB) $(XLIB)
+#endif
+
+#ifndef NeedDefaultDepLibs
+#define NeedDefaultDepLibs YES
+#endif
+
+#if NeedDefaultDepLibs
+/*
+ * Individual libraries should override this
+ */
+#if HasSharedLibraries || defined(UseInstalled)
+          DEPLIBS = $(DEPXAWLIB) $(DEPXMULIB) $(DEPXTOOLLIB) $(DEPXLIB)
+#else
+          DEPLIBS = $(LOCAL_LIBRARIES)
+#endif
+         DEPLIBS1 = $(DEPLIBS)
+         DEPLIBS2 = $(DEPLIBS)
+         DEPLIBS3 = $(DEPLIBS)
+         DEPLIBS4 = $(DEPLIBS)
+         DEPLIBS5 = $(DEPLIBS)
+         DEPLIBS6 = $(DEPLIBS)
+         DEPLIBS7 = $(DEPLIBS)
+         DEPLIBS8 = $(DEPLIBS)
+         DEPLIBS9 = $(DEPLIBS)
+         DEPLIBS10 = $(DEPLIBS)
+#endif /* NeedDefaultDepLibs */
+
+
+/*
+ * InstallAppDefaults - simple rules to install application default file
+ */
+#ifndef InstallAppDefaults
+#define InstallAppDefaults(class) InstallAppDefaultsLong(class,class)
+#endif /* InstallAppDefaults */
+
+/*
+ * InstallAppDefaultsLong - general rule to install application default file
+ * if the InstallAppDefFiles configuration parameter is set.
+ */
+#ifndef InstallAppDefaultsLong
+#if InstallAppDefFiles
+#define InstallAppDefaultsLong(file,class)                             @@\
+LinkVarDirectory(app-defaults,.,app-defaults,.)                                @@\
+InstallNamedTarget(install,file.ad,$(INSTAPPFLAGS),$(XAPPLOADDIR),class)
+#else
+#define InstallAppDefaultsLong(file,class)                             @@\
+LinkVarDirectory(app-defaults,.,app-defaults,.)                                @@\
+InstallNamedTargetNoClobber(install,file.ad,$(INSTAPPFLAGS),$(XAPPLOADDIR),class)
+#endif /* InstallAppDefFiles */
+#endif /* InstallAppDefaultsLong */
+
+/*
+ * MakeFontsDir - generate rules to build fonts.dir database.
+ */
+#ifndef MakeFontsDir
+#define MakeFontsDir(deplist)                                          @@\
+all:: fonts.dir                                                                @@\
+                                                                       @@\
+fonts.dir:  deplist                                                    @@\
+       RunProgram(MKFONTDIR,.)                                         @@\
+                                                                       @@\
+clean::                                                                        @@\
+       RemoveFile(fonts.dir)
+#endif /* MakeFontsDir */
+
+
+/*
+ * MakeFonts - generate rules to build font database.
+ */
+#ifndef MakeFonts
+#define MakeFonts()                                                    @@\
+all::  $(OBJS)                                                         @@\
+                                                                       @@\
+MakeFontsDir($(OBJS))                                                  @@\
+                                                                       @@\
+clean::                                                                        @@\
+       RemoveFiles(*.pcf *.pcf.Z *.pcf.gz)
+#endif /* MakeFonts */
+
+
+/*
+ * InstallFontObjs - generate rules to install font files
+ */
+#ifndef InstallFontObjs
+#define InstallFontObjs(objs,dest)                                     @@\
+InstallMultipleFlags(objs,dest,$(INSTDATFLAGS))                                @@\
+                                                                       @@\
+InstallTarget(install,fonts.dir,$(INSTDATFLAGS),dest)
+#endif /* InstallFontObjs */
+
+
+/*
+ * InstallFonts - generate rules to install font files
+ */
+#ifndef InstallFonts
+#define InstallFonts(dest)                                             @@\
+InstallFontObjs($(OBJS),dest)
+#endif /* InstallFonts */
+
+
+/*
+ * InstallFontAliases - generate rules to install font aliases databases. 
+ */
+#ifndef InstallFontAliases
+#define InstallFontAliases(dest)                                       @@\
+InstallTarget(install,fonts.alias,$(INSTDATFLAGS),dest)
+#endif /* InstallFontAliases */
+
+#ifndef FontSrc
+#define FontSrc(basename) basename.bdf
+#endif
+
+#ifndef FontBaseObj
+#define FontBaseObj(basename)basename.pcf
+#endif
+
+/*
+ * InstallFontScale - generate rules to install font scale database.
+ */
+#ifndef InstallFontScale
+#define InstallFontScale(dest)                                         @@\
+InstallTarget(install,fonts.scale,$(INSTDATFLAGS),dest)
+#endif /* InstallFontScale */
+
+/*
+ * UncompressedFontTarget
+ */
+#ifndef UncompressedFontTarget
+#define UncompressedFontTarget(basename)                               @@\
+FontBaseObj(basename):  FontSrc(basename)                              @@\
+       RunProgram(FONTC,$(FONTCFLAGS) $? -o $@)
+#endif /* UncompressedFontTarget */
+
+/*
+ * CompressedFontTarget
+ */
+#ifndef GzipFontCompression
+#define GzipFontCompression NO
+#endif
+
+#ifndef CompressedFontTarget
+#if GzipFontCompression
+#define CompressedFontTarget(basename)                                 @@\
+FontBaseObj(basename).gz:  FontSrc(basename)                           @@\
+       RunProgram(FONTC,$(FONTCFLAGS) $?) | $(GZIPCMD) > $@
+#else
+#define CompressedFontTarget(basename)                                 @@\
+FontBaseObj(basename).Z:  FontSrc(basename)                            @@\
+       RunProgram(FONTC,$(FONTCFLAGS) $?) | $(COMPRESS) > $@
+#endif
+#endif /* CompressedFontTarget */
+
+#if !defined(FontTarget) && !defined(FontObj)
+#ifdef CompressAllFonts
+#define FontTarget(basename) CompressedFontTarget(basename)
+#if GzipFontCompression
+#define FontObj(basename) FontBaseObj(basename).gz
+#else
+#define FontObj(basename) FontBaseObj(basename).Z
+#endif
+#else
+#define FontTarget(basename) UncompressedFontTarget(basename)
+#define FontObj(basename) FontBaseObj(basename)
+#endif /* CompressAllFonts */
+#endif
+
+/*
+ * MakeXkbDir
+ */
+#ifndef MakeXkbDir
+#define MakeXkbDir(basedir,subdir)                                     @@\
+all::   Concat(subdir,.dir)                                            @@\
+                                                                       @@\
+Concat(subdir,.dir):                                                   @@\
+       $(XKBCOMPCMD) -lfhlpR -o Concat(subdir,.dir) '*'                @@\
+                                                                       @@\
+InstallTarget(install,Concat(subdir,.dir),$(INSTDATFLAGS),basedir)
+#endif
+
+/*
+ * PostProcessTroffPS - by default moves the working output into place,
+ * but can be a hook for more complicated post-processing.
+ */
+#ifndef PostProcessTroffPS
+#define PostProcessTroffPS(temp,real) $(MV) temp real
+#endif
+
+#ifndef MakeSimpleDoc
+#define MakeSimpleDoc(file,srcs)                                       @@\
+all:: file.PS                                                          @@\
+.PRECIOUS: file.PS                                                     @@\
+                                                                       @@\
+file.PS: srcs                                                          @@\
+       -$(TROFF) $(MSMACROS) $(XDOCMACROS) srcs 2> index.raw > file.nPS \@@\
+       && PostProcessTroffPS(file.nPS,$@)                              @@\
+       @if grep '^[^1-9.]' index.raw; then exit 1; else test $$? = 1; fi @@\
+                                                                       @@\
+file.txt: srcs                                                         @@\
+       $(NROFF) $(MSMACROS) $(XDOCMACROS) srcs 2> index.raw > $@       @@\
+                                                                       @@\
+clean::                                                                        @@\
+       $(RM) index.raw file.nPS file.PS file.txt
+#endif
+
+#ifndef MakeTblDoc
+#define MakeTblDoc(file,srcs)                                          @@\
+all:: file.PS                                                          @@\
+.PRECIOUS: file.PS                                                     @@\
+                                                                       @@\
+file.PS: srcs                                                          @@\
+       -$(TBL) $(XDOCMACROS) srcs | $(TROFF) $(MSMACROS) 2> index.raw > file.nPS \@@\
+       && PostProcessTroffPS(file.nPS,$@)                              @@\
+       @if grep '^[^1-9.]' index.raw; then exit 1; else test $$? = 1; fi @@\
+                                                                       @@\
+file.txt: srcs                                                         @@\
+       $(TBL) $(XDOCMACROS) srcs | $(NROFF) $(MSMACROS) 2> index.raw | $(COL) > $@     @@\
+                                                                       @@\
+clean::                                                                        @@\
+       $(RM) index.raw file.nPS file.PS file.txt
+#endif
+
+#ifndef MakeEqnDoc
+#define MakeEqnDoc(file,srcs)                                          @@\
+all:: file.PS                                                          @@\
+.PRECIOUS: file.PS                                                     @@\
+                                                                       @@\
+file.PS: srcs                                                          @@\
+       -$(TBL) $(XDOCMACROS) srcs | $(EQN) | $(TROFF) $(MSMACROS) 2> index.raw > file.nPS \@@\
+       && PostProcessTroffPS(file.nPS,$@)                              @@\
+       @if grep '^[^1-9.]' index.raw; then exit 1; else test $$? = 1; fi @@\
+                                                                       @@\
+file.txt: srcs                                                         @@\
+       $(TBL) $(XDOCMACROS) srcs | $(NEQN) | $(NROFF) $(MSMACROS) 2> index.raw | $(COL) > $@ @@\
+                                                                       @@\
+clean::                                                                        @@\
+       $(RM) index.raw file.nPS file.PS file.txt
+#endif
+
+#ifndef MakeDocIndex
+#define MakeDocIndex(file,srcs)                                                @@\
+all:: file.idx.PS                                                      @@\
+                                                                       @@\
+file.idx.PS: srcs index.raw                                            @@\
+       tail -1 index.raw > index.pageno                                @@\
+       grep '^[1-9]' index.raw | sort -f '-t:' +1 -3 +0n -1n | awk -f $(DOCUTILSRC)/fixindex.awk | awk -f $(DOCUTILSRC)/block.awk > index.troff @@\
+       cat srcs $(XIDXMACROS) index.troff | $(TROFF) -me > file.idx.nPS \@@\
+       && $(MV) file.idx.nPS $@                                        @@\
+       $(RM) index.troff index.pageno                                  @@\
+                                                                       @@\
+clean::                                                                        @@\
+       $(RM) index.troff index.pageno file.idx.nPS file.idx.PS
+#endif
+
+#ifndef MakeLatexDoc
+#if HasLatex
+#define MakeLatexDoc(file,src)                                         @@\
+all:: file.PS                                                          @@\
+                                                                       @@\
+file.dvi: src                                                          @@\
+       $(LATEX) src                                                    @@\
+                                                                       @@\
+file.PS: file.dvi                                                      @@\
+       $(DVIPS) -o file.nPS file && $(MV) file.nPS $@                  @@\
+                                                                       @@\
+clean::                                                                @@\
+       RemoveFiles(file.nPS file.PS file.dvi file.log)                 @@\
+       RemoveFiles(file.aux file.toc file.lof file.lot)
+#else /* HasLatex */
+#define MakeLatexDoc(file,src)                                         @@\
+all::                                                                  @@\
+file.PS: src                                                           @@\
+       @echo "cannot make file.PS: no latex on this system"; exit 1
+#endif /* HasLatex (else) */
+#endif /* MakeLatexDoc */
diff --git a/Xserver/config/cf/apollo.cf b/Xserver/config/cf/apollo.cf
new file mode 100644 (file)
index 0000000..a802b1a
--- /dev/null
@@ -0,0 +1,38 @@
+XCOMM platform:  $XConsortium: apollo.cf /main/34 1996/09/28 16:09:07 rws $
+
+/*
+ * Minimally tested, and only in the bsd4.3 environment.  X_NOT_POSIX is not
+ * in Xosdefs.h, because we suspect someone might want to try building with
+ * POSIX support in the sysv environment (the OS doc seems to imply that
+ * POSIX is supported in sysv).
+ */
+
+#ifndef OSName
+#define OSName            Domain/OS SR10.3
+#endif
+XCOMM operating system:  OSName
+#ifndef OSMajorVersion
+#define OSMajorVersion    10
+#endif
+#ifndef OSMinorVersion
+#define OSMinorVersion    3
+#endif
+
+#ifndef CCompilerMajorVersion
+#define CCompilerMajorVersion 6
+#endif
+#ifndef CCompilerMinorVersion
+#define CCompilerMinorVersion 8
+#endif
+
+#define StandardDefines -DX_NOT_POSIX
+#define BuildServer    NO
+#define HasNdbm                YES
+#define ConnectionFlags        -DTCPCONN
+
+#define        InstallManPageLong(file,destdir,dest)                           @@\
+install.man:: file.man                                                 @@\
+       MakeDir($(DESTDIR)destdir)                                      @@\
+       $(NROFF) $(MANMACROS) file.man > file.mantxt                            @@\
+       $(INSTALL) -c $(INSTMANFLAGS) file.mantxt $(DESTDIR)destdir/dest.$(MANSUFFIX) @@\
+       $(RM) file.mantxt
diff --git a/Xserver/config/cf/bsd.cf b/Xserver/config/cf/bsd.cf
new file mode 100644 (file)
index 0000000..feba08c
--- /dev/null
@@ -0,0 +1,29 @@
+XCOMM platform:  $XConsortium: bsd.cf /main/24 1996/09/28 16:09:13 rws $
+
+#ifndef OSName
+#define OSName            4.3bsd
+#endif
+XCOMM operating system:  OSName
+#ifndef OSMajorVersion
+#define OSMajorVersion    4
+#endif
+#ifndef OSMinorVersion
+#define OSMinorVersion    3
+#endif
+
+#define BootstrapCFlags -DNOSTDHDRS
+#define StandardDefines -DNOSTDHDRS -DCSRG_BASED
+#define HasVoidSignalReturn NO
+#define HasBsearch NO
+#define DirFailPrefix -
+#define AvoidNullMakeCommand   YES
+
+#define BuildServer NO
+
+#ifdef VaxArchitecture
+#define UnalignedReferencesAllowed YES        /* if arbitrary deref is okay */
+#endif
+
+#if OSMajorVersion >= 4 && OSMinorVersion >= 3
+#define SetTtyGroup YES
+#endif
diff --git a/Xserver/config/cf/bsdLib.rules b/Xserver/config/cf/bsdLib.rules
new file mode 100644 (file)
index 0000000..9e3aed0
--- /dev/null
@@ -0,0 +1,238 @@
+XCOMM $XConsortium: bsdLib.rules /main/3 1996/09/28 16:09:18 rws $
+
+
+
+
+
+XCOMM $XFree86: xc/config/cf/bsdLib.rules,v 3.4.2.1 1997/05/11 05:04:04 dawes Exp $
+/*
+ * NetBSD/FreeBSD shared library rules
+ */
+
+#ifndef UseElfFormat
+#define UseElfFormat NO
+#endif
+
+#if !UseElfFormat
+/* a.out shared libs */
+#ifndef HasSharedLibraries
+#define HasSharedLibraries YES
+#endif
+#ifndef SharedDataSeparation
+#define SharedDataSeparation NO
+#endif
+#ifndef SharedCodeDef
+#define SharedCodeDef
+#endif
+#ifndef SharedLibraryDef
+#define SharedLibraryDef -DBSDSHLIB
+#endif
+#ifndef ShLibIncludeFile
+#define ShLibIncludeFile <bsdLib.tmpl>
+#endif
+#ifndef SharedLibraryLoadFlags
+#define SharedLibraryLoadFlags -Bshareable
+#endif
+#ifndef PositionIndependentCFlags
+#define PositionIndependentCFlags -fpic
+#endif
+
+/*
+ * InstallSharedLibrary - generate rules to install the shared library.
+ */
+#ifndef InstallSharedLibrary
+#define InstallSharedLibrary(libname,rev,dest)                         @@\
+install:: Concat(lib,libname.so.rev)                                   @@\
+       MakeDir($(DESTDIR)dest)                                         @@\
+       $(INSTALL) -c $(INSTLIBFLAGS) Concat(lib,libname.so.rev) $(DESTDIR)dest 
+@@\
+
+#endif /* InstallSharedLibrary */
+
+/*
+ * SharedLibraryTarget - generate rules to create a shared library;
+ * build it into a different name so that we do not hose people by having
+ * the library gone for long periods.
+ */
+#ifndef SharedLibraryTarget
+#define SharedLibraryTarget(libname,rev,solist,down,up)                        @@\
+AllTarget(Concat(lib,libname.so.rev))                                  @@\
+                                                                       @@\
+Concat(lib,libname.so.rev):  solist $(EXTRALIBRARYDEPS)                        @@\
+       $(RM) $@~                                                       @@\
+       (cd down; $(LD) -o up/$@~ $(SHLIBLDFLAGS) solist $(REQUIREDLIBS)) @@\
+       $(RM) $@                                                        @@\
+       $(MV) $@~ $@                                                    @@\
+       LinkBuildLibrary($@)                                            @@\
+                                                                       @@\
+clean::                                                                        @@\
+       $(RM) Concat(lib,libname.so.rev)
+
+#endif /* SharedLibraryTarget */
+
+#ifndef SharedDepModuleTarget
+#define SharedDepModuleTarget(name,deps,solist)                                @@\
+AllTarget(name)                                                                @@\
+                                                                       @@\
+name: deps                                                             @@\
+       $(RM) $@~                                                       @@\
+       $(LD) -o $@~ $(SHLIBLDFLAGS) solist $(REQUIREDLIBS)             @@\
+       $(RM) $@                                                        @@\
+       $(MV) $@~ $@                                                    @@\
+                                                                       @@\
+clean::                                                                        @@\
+       $(RM) name
+
+#endif /* SharedDepModuleTarget */
+
+/*
+ * SharedLibraryDataTarget - generate rules to create shlib data file;
+ */
+#ifndef SharedLibraryDataTarget
+#define SharedLibraryDataTarget(libname,rev,salist)
+#endif /* SharedLibraryDataTarget */
+
+#ifndef InstallSharedLibraryData
+#define InstallSharedLibraryData(libname,rev,dest)
+#endif /* InstallSharedLibraryData */
+
+/*
+ * SharedLibReferences - variables for shared libraries
+ */
+#ifndef SharedLibReferences
+#define SharedLibReferences(varname,libname,libsource,revname,rev)     @@\
+revname = rev                                                          @@\
+Concat3(DEP,varname,LIB) = SharedLibDependencies(libname,libsource,revname) @@\
+Concat(varname,LIB) = LoaderLibPrefix Concat(-l,libname)               @@\
+LintLibReferences(varname,libname,libsource)
+#endif
+
+/*
+ * SharedDSLibReferences - variables for shared libraries
+ */
+#ifndef SharedDSLibReferences
+#define SharedDSLibReferences(varname,libname,libsource,revname,rev)   @@\
+revname = rev                                                          @@\
+Concat3(DEP,varname,LIB) = SharedDSLibDependencies(libname,libsource,revname) @@\
+Concat(varname,LIB) = LoaderLibPrefix Concat(-l,libname) Concat3(Shared,libname,Reqs)          @@\
+LintLibReferences(varname,libname,libsource)
+#endif
+
+#else /* UseElfFormat */
+
+/*
+ * NetBSD/FreeBSD (ELF) shared library rules
+ * Cloned from Linux ELF rules, with the following major change:
+ *
+ *     Shared libraries depend on -lc.  Since we don't have to worry
+ *     about libc vs. libg, etc., this is a good idea.  (This is actually
+ *     implied by using $(CC) to build the shared libraries.)
+ */
+
+#ifndef HasSharedLibraries
+#define HasSharedLibraries YES
+#endif
+#ifndef ForceNormalLib
+#define ForceNormalLib YES
+#endif
+
+#ifndef BaseShLibReqs
+#define BaseShLibReqs          /* -lc implied by $(CC) */
+#endif
+
+#ifndef SharedDataSeparation
+#define SharedDataSeparation NO
+#endif
+#ifndef SharedCodeDef
+#define SharedCodeDef /**/
+#endif
+#ifndef SharedLibraryDef
+#define SharedLibraryDef /**/
+#endif
+#ifndef ShLibIncludeFile
+#define ShLibIncludeFile <bsdLib.tmpl>
+#endif
+#ifndef SharedLibraryLoadFlags
+#define SharedLibraryLoadFlags -shared -Wl,-rpath,$(USRLIBDIR)
+#endif
+#ifndef PositionIndependentCFlags
+#define PositionIndependentCFlags -fPIC
+#endif
+#ifndef PositionIndependentCplusplusFlags
+#define PositionIndependentCplusplusFlags -fPIC
+#endif
+#ifndef ExtraLoadFlags
+#ifdef UseInstalled
+#define ExtraLoadFlags -Wl,-rpath,$(USRLIBDIRPATH)
+#else
+#define ExtraLoadFlags -Wl,-rpath,$(USRLIBDIRPATH) -Wl,-rpath-link,$(BUILDLIBDIR)
+#endif
+#endif
+
+/*
+ * InstallSharedLibrary - generate rules to install the shared library.
+ * NOTE: file must be executable, hence "INSTBINFLAGS"
+ */
+#ifndef InstallSharedLibrary
+#define InstallSharedLibrary(libname,rev,dest)                         @@\
+install:: Concat(lib,libname.so.rev)                                   @@\
+       MakeDir($(DESTDIR)dest)                                         @@\
+       $(INSTALL) $(INSTALLFLAGS) $(INSTBINFLAGS) Concat(lib,libname.so.rev) $(DESTDIR)dest @@\
+       (T=`echo Concat($(DESTDIR)dest/lib,libname.so.rev) | sed 's/\.[^\.]*$$//'`;\
+               $(RM) $$T && $(LN) Concat(lib,libname.so.rev) $$T)      @@\
+       (T=`echo Concat($(DESTDIR)dest/lib,libname.so.rev) | sed 's/\.so.*$$/.so/'`;\
+               $(RM) $$T && $(LN) Concat(lib,libname.so.rev) $$T)      @@\
+       $(RM) Concat($(DESTDIR)dest/lib,libname.so)                     @@\
+       $(LN) Concat(lib,libname.so.rev) Concat($(DESTDIR)dest/lib,libname.so)
+#endif /* InstallSharedLibrary */
+
+/*
+ * InstallSharedLibraryData - generate rules to install the shared library data
+ */
+#ifndef InstallSharedLibraryData
+#define InstallSharedLibraryData(libname,rev,dest)
+#endif /* InstallSharedLibraryData */
+
+
+/*
+ * SharedLibraryTarget - generate rules to create a shared library;
+ * build it into a different name so that we do not hose people by having
+ * the library gone for long periods.
+ */
+#ifndef SharedLibraryTarget
+#ifdef UseInstalled  
+#define LinkBuildSonameLibrary(lib) true
+#else
+#define LinkBuildSonameLibrary(lib) (RemoveFile($(BUILDLIBDIR)/lib); \
+       cd $(BUILDLIBDIR); $(LN) $(BUILDINCTOP)/$(CURRENT_DIR)/lib .)
+#endif
+
+#define SharedLibraryTarget(libname,rev,solist,down,up)                        @@\
+AllTarget(Concat(lib,libname.so.rev))                                  @@\
+                                                                       @@\
+Concat(lib,libname.so.rev):  solist                                    @@\
+       $(RM) $@~                                                       @@\
+       SONAME=`echo $@ | sed 's/\.[^\.]*$$//'`; \                      @@\
+               (cd down; $(CC) -o up/$@~ $(SHLIBLDFLAGS) -Wl,-soname,$$SONAME solist $(REQUIREDLIBS) BaseShLibReqs); \ @@\
+               $(RM) $$SONAME; $(LN) $@ $$SONAME; \                    @@\
+               LinkBuildSonameLibrary($$SONAME)                        @@\
+       $(RM) $@                                                        @@\
+       $(MV) $@~ $@                                                    @@\
+       $(RM) Concat(lib,libname.so)                                    @@\
+       $(LN) $@ Concat(lib,libname.so)                                 @@\
+       LinkBuildLibrary($@)                                            @@\
+       LinkBuildLibrary(Concat(lib,libname.so))                        @@\
+                                                                       @@\
+clean::                                                                        @@\
+       $(RM) Concat(lib,libname.so.rev)
+
+#endif /* SharedLibraryTarget */
+
+/*
+ * SharedLibraryDataTarget - generate rules to create shlib data file;
+ */
+#ifndef SharedLibraryDataTarget
+#define SharedLibraryDataTarget(libname,rev,salist)
+#endif /* SharedLibraryTarget */
+
+#endif /* UseElfFormat */
diff --git a/Xserver/config/cf/bsdLib.tmpl b/Xserver/config/cf/bsdLib.tmpl
new file mode 100644 (file)
index 0000000..57266d3
--- /dev/null
@@ -0,0 +1,59 @@
+XCOMM $XConsortium: bsdLib.tmpl /main/3 1996/09/28 16:09:25 rws $
+XCOMM $XFree86: xc/config/cf/bsdLib.tmpl,v 3.3.2.1 1997/07/27 02:41:03 dawes Exp $
+
+/*
+ * NetBSD/FreeBSD/OpenBSD shared library template
+ */
+
+#if !UseElfFormat
+
+#ifndef SharedXtReqs
+#define SharedXtReqs /**/
+#endif
+#ifndef SharedXawReqs
+#define SharedXawReqs /**/
+#endif
+#ifndef SharedXmuReqs
+# if !defined(Mc68020Architecture) || !defined(OpenBSDArchitecture)
+#  define SharedXmuReqs $(LDPRELIBS) $(XTOOLONLYLIB) $(XONLYLIB)
+# else
+   /* At least the hp300 and the sun3 OpenBSD ports need that */
+#  define SharedXmuReqs $(LDPRELIBS) $(XTOOLLIB) $(EXTENSIONLIB) $(XONLYLIB)
+# endif
+#endif
+
+#else /* UseElfFormat */
+
+/*
+ * NetBSD/FreeBSD (ELF) shared library template
+ * Cloned from Linux ELF rules, but with a minor number.
+ */
+
+#ifndef FixupLibReferences
+#define FixupLibReferences()                                           @@\
+XMULIBONLY = -lXmu                                                     @@\
+XMULIB = $(XMULIBONLY) $(XTOOLLIB) $(XLIB)
+#endif
+
+#ifndef XawClientLibs
+#define XawClientLibs $(XAWLIB) $(XMULIBONLY) $(XTOOLLIB) $(XLIB)
+#endif
+
+#define CplusplusLibC
+#define FrescoSysLibs  CplusplusLibC MathLibrary
+
+#define SharedX11Reqs
+#define SharedOldXReqs $(LDPRELIB) $(XLIBONLY)
+#define SharedXtReqs   $(LDPRELIB) $(XLIBONLY) $(SMLIB) $(ICELIB)
+#define SharedXawReqs  $(LDPRELIB) $(XMULIB) $(XTOOLLIB) $(XLIB)
+#define SharedXmuReqs  $(LDPRELIB) $(XTOOLLIB) $(XLIB)
+#define SharedXextReqs $(LDPRELIB) $(XLIBONLY)
+#define SharedXiReqs   $(LDPRELIB) $(XLIB)
+#define SharedPexReqs  $(LDPRELIB) $(XLIBONLY) MathLibrary
+#define SharedXtstReqs $(LDPRELIB) $(XLIB)
+#define SharedXieReqs  $(LDPRELIB) $(XLIBONLY)
+#define SharedSMReqs   $(LDPRELIB) $(ICELIB)
+#define SharedFrescoReqs       $(LDPRELIB) $(XLIBONLY) FrescoSysLibs
+#define SharedXtfReqs  $(LDPRELIB) $(FRESCOLIB) $(XTOOLLIB) $(XLIB) FrescoSysLibs
+
+#endif /* UseElfFormat */
diff --git a/Xserver/config/cf/bsdi.cf b/Xserver/config/cf/bsdi.cf
new file mode 100644 (file)
index 0000000..f457e95
--- /dev/null
@@ -0,0 +1,151 @@
+XCOMM platform:  $XConsortium: bsdi.cf /main/22 1996/09/28 16:09:30 rws $
+XCOMM platform:  $XFree86: xc/config/cf/bsdi.cf,v 3.23.2.5 1998/02/09 14:33:21 robin Exp $
+
+#ifndef OSName
+#define OSName            BSD/OS 2.0
+#endif
+#ifndef OSVendor
+#define OSVendor          BSDI
+#endif
+XCOMM operating system:  OSName
+#ifndef OSMajorVersion
+#define OSMajorVersion    2
+#endif
+#ifndef OSMinorVersion
+#define OSMinorVersion    0
+#endif
+
+#define HasPutenv      YES
+#define HasBSD44Sockets        YES
+
+XCOMM BSD/OS 2.0 comes with gcc 2.6.3 installed as gcc2 and gcc.
+XCOMM gcc 1.42 is installed as cc.
+XCOMM BSD/386 1.1 comes with gcc 2.5.8 installed as gcc2.
+XCOMM BSD/386 1.0 comes with gcc 1.40 as the only compiler.
+XCOMM The default is to use gcc2 on release 2.0 and 1.1 and gcc1 on 1.0
+XCOMM The defaults can be altered by defining "HasGcc2" as YES or NO in
+XCOMM xf86site.def
+
+#ifndef HasGcc
+# define HasGcc                        YES
+#endif
+#if OSMajorVersion > 1 || OSMinorVersion >= 1
+# ifndef HasGcc2
+#  define HasGcc2              YES
+# endif
+#endif
+#if HasGcc2
+# ifndef HasGcc2ForCplusplus
+#  define HasGcc2ForCplusplus  YES
+# endif
+# define CcCmd                 gcc2
+# define OptimizedCDebugFlags  DefaultGcc2i386Opt
+#else
+# define CcCmd                 cc
+# define OptimizedCDebugFlags  -O
+#endif
+#define CppCmd         /usr/bin/cpp
+#define TroffCmd       groff -Tps
+#define MkdirHierCmd   mkdir -p
+#define SetTtyGroup    YES
+#define HasNdbm                YES
+#define HasWChar32      YES
+#define DirFailPrefix -
+#define AvoidNullMakeCommand YES
+# ifndef GccUsesGas
+#  define GccUsesGas    YES
+# endif
+#if HasGcc
+#if defined(UseInstalled) && (!defined(XF86LinkKit) || !XF86LinkKit)
+#define DefaultCCOptions       /**/
+#else
+#define DefaultCCOptions       -ansi
+#endif
+#endif
+
+#if GccUsesGas
+# define GccGasOption -DGCCUSESGAS
+#else
+# define GccGasOption /**/
+#endif
+
+#define HasShm YES
+#define ServerExtraDefines GccGasOption XFree86ServerDefines
+#define ServerOSDefines XFree86ServerOSDefines -DDDXTIME
+#define XFree86ConsoleDefines /**/
+#define AsmDefines -DUSE_GAS
+
+#define StandardDefines        -DCSRG_BASED
+
+#define InstallCmd /usr/bin/install
+#define        EqnCmd eqn -Tps
+#define        NeqnCmd eqn -Tascii
+          COL = col
+         NEQN = NeqnCmd
+        NROFF = nroff
+
+#define DefaultUserPath                :/bin:/usr/bin:/usr/local/bin:$(BINDIR)
+#define DefaultSystemPath      /sbin:/usr/sbin:/bin:/usr/bin:$(BINDIR)
+
+XCOMM Man pages need to be formatted when installed, so override the default
+XCOMM imake rules.
+
+#define ManSuffix       1
+#define ManSourcePath   $(MANPATH)/cat
+
+#define InstallManPageLong(file,destdir,dest)                           @@\
+all:: file.0                                                           @@\
+                                                                       @@\
+file.0:: file.man                                                      @@\
+       @if [ -f file.man ]; \                                          @@\
+       then \                                                          @@\
+       cat file.man | $(NEQN) | $(TBL) | $(NROFF) $(MANMACROS) | $(COL) >/tmp/$$$$.man; \      @@\
+       cp /tmp/$$$$.man file.0; \                                      @@\
+       $(RM) /tmp/$$$$.man; \                                          @@\
+       fi                                                              @@\
+                                                                       @@\
+file.man::                                                             @@\
+                                                                       @@\
+install.man::                                                           @@\
+       MakeDir($(DESTDIR)destdir)                                      @@\
+       -@if [ -f file.0 ]; \                                           @@\
+       then \                                                          @@\
+       $(INSTALL) -c $(INSTMANFLAGS) file.0 $(DESTDIR)destdir/dest.0; \@@\
+       fi
+
+#define InstallGenManPageLong(file,destdir,dest,suffix)                        @@\
+       InstallManPageLong(file,destdir,dest)
+
+#define InstallMultipleManSuffix(list,dest,suff)                        @@\
+install.man::                                                          @@\
+       MakeDir($(DESTDIR)dest)                                         @@\
+       case '${MFLAGS}' in *[i]*) set +e;; esac; \                     @@\
+       for i in list; do \                                             @@\
+         (set -x; \                                                    @@\
+         cat $$i.suff | $(NEQN) | $(TBL) | $(NROFF) $(MANMACROS) | $(COL) >/tmp/$$$$.suff; \   @@\
+         $(INSTALL) -c $(INSTMANFLAGS) /tmp/$$$$.suff $(DESTDIR)dest/$$i.0; \  @@\
+         $(RM) /tmp/$$$$.suff); \                                              @@\
+       done
+
+#define InstallMultipleMan(list,dest)                                   @@\
+       InstallMultipleManSuffix(list,dest,man)
+
+#define InstallManPageAliases(file,destdir,aliases)                     @@\
+install.man::                                                          @@\
+       @case '${MFLAGS}' in *[i]*) set +e;; esac; \                    @@\
+       for i in aliases; do \                                          @@\
+               (set -x; \                                              @@\
+               $(RM) $(DESTDIR)destdir/$$i.0;\                         @@\
+               (cd $(DESTDIR)destdir; $(LN) file.0 $$i.0);\            @@\
+               ); \                                                    @@\
+       done
+
+#define InstallGenManPageAliases(file,destdir,suffix,aliases)          @@\
+       InstallManPageAliases(file,destdir,aliases)
+
+/*
+ * These seem redundant, but leave them in for now.
+ */
+#define i386Bsd 1
+#define i386Bsdi 1
+#include <xfree86.cf>
diff --git a/Xserver/config/cf/cde.rules b/Xserver/config/cf/cde.rules
new file mode 100644 (file)
index 0000000..108cf48
--- /dev/null
@@ -0,0 +1,226 @@
+/* 
+ *  @OSF_COPYRIGHT@
+ *  COPYRIGHT NOTICE
+ *  Copyright (c) 1990, 1991, 1992, 1993 Open Software Foundation, Inc.
+ *  ALL RIGHTS RESERVED (MOTIF). See the file named COPYRIGHT.MOTIF for
+ *  the full copyright text.
+ *
+ * (c) Copyright 1996 Digital Equipment Corporation.
+ * (c) Copyright 1996 Hewlett-Packard Company.
+ * (c) Copyright 1996 International Business Machines Corp.
+ * (c) Copyright 1996 Sun Microsystems, Inc.
+ * (c) Copyright 1996 Novell, Inc. 
+ * (c) Copyright 1996 FUJITSU LIMITED.
+ * (c) Copyright 1996 Hitachi.
+ */ 
+XCOMM $XConsortium: cde.rules /main/2 1996/12/04 10:13:04 swick $
+
+/* Note whether we are the top level project. */
+#ifndef SeenTopLevelProject
+# define SeenTopLevelProject   YES
+# define CDEIsTopLevelProject  YES
+#else
+# define CDEIsTopLevelProject  NO
+#endif
+
+/* Include the Motif project rules file. */
+#include <Motif.rules>
+
+
+/* Use the in-tree CDE by default. */
+#ifndef UseInstalledCDE
+# define UseInstalledCDE       NO
+#endif
+#ifdef UseInstalled
+# undef UseInstalledCDE
+# define UseInstalledCDE       YES
+#endif
+
+#ifndef ImportCDE
+# ifdef UseImports
+#  define ImportCDE            YES
+# else
+#  define ImportCDE            NO
+# endif
+#endif
+#if UseInstalledCDE
+# undef ImportCDE
+# define ImportCDE             NO
+#endif
+
+/* If CDE has a different ProjectRoot we need to search the regular ones too. */
+#ifdef CDEProjectRoot
+# define CUsrLibDirPath        Concat(MUsrLibDirPath,:$(CDEPROJECTROOT)/lib)
+#else
+# define CUsrLibDirPath        MUsrLibDirPath
+#endif
+#ifdef UsrLibDirPath
+# undef UsrLibDirPath
+#endif
+#define UsrLibDirPath  CUsrLibDirPath
+
+#if ImportCDE
+# define CLdPreLibs    -L$(CDELIBSRC)
+#elif defined(UseInstalledCDE) && defined(CDEProjectRoot)
+# define CLdPreLibs    -L$(CDEPROJECTROOT)/lib
+#else
+# define CLdPreLibs    /**/
+#endif
+#ifdef LdPreLibs
+# undef LdPreLibs
+#endif
+#define LdPreLibs      LdPreLib CLdPreLibs MLdPreLibs XLdPreLibs
+
+#ifdef CDEProjectRoot
+# define CLdPostLibs   -L$(CDEPROJECTROOT)/lib
+#else
+# define CLdPostLibs   /**/
+#endif
+#ifdef LdPostLibs
+# undef LdPostLibs
+#endif
+#define LdPostLibs     LdPostLib CLdPostLibs MLdPostLibs XLdPostLibs
+
+#ifdef TopIncludes
+# undef TopIncludes
+#endif
+#define TopIncludes    TopInclude $(TOP_CDE_INCLUDES) $(TOP_MOTIF_INCLUDES) $(TOP_X_INCLUDES)
+
+#if UseInstalledCDE && defined(CdeProjectRoot)
+# define CDEBuildLibPath       $(CDEPROJECTROOT)/lib
+#elif UseInstalledCDE
+# define CDEBuildLibPath       $(USRLIBDIR)
+#elif ImportCDE
+# define CDEBuildLibPath       $(CDELIBSRC)
+#else
+# define CDEBuildLibPath       $(TOP)/exports/lib
+#endif
+#ifdef BuildLibPath
+# undef BuildLibPath
+#endif
+#ifdef SystemBuildLibPath
+# define BuildLibPath          \
+$(DTENVLIBDIR):$(MOTIFENVLIBDIR):$(XENVLIBDIR):$(SYSTEMENVLIBDIR)
+#else
+# define BuildLibPath          $(DTENVLIBDIR):$(MOTIFENVLIBDIR):$(XENVLIBDIR)
+#endif
+
+
+#ifndef CdeInstallationTop
+# define CdeInstallationTop    /usr/dt
+#endif
+#ifndef CdeConfigurationTop
+# define CdeConfigurationTop   /etc/dt
+#endif
+#ifndef CdeLogFilesTop
+# define CdeLogFilesTop                /var/dt
+#endif
+#ifndef CdeUserTop
+# define CdeUserTop            .dt
+#endif
+
+#ifndef CdeProjectDefines
+# define CdeProjectDefines     \
+       -DANSICPP -DMULTIBYTE -DNLS16 \
+       -DOSMAJORVERSION=OSMajorVersion -DOSMINORVERSION=OSMinorVersion
+#endif
+#ifdef ProjectDefines
+# undef ProjectDefines
+#endif
+#define ProjectDefines X11ProjectDefines MotifProjectDefines CdeProjectDefines
+
+#ifndef CdeCplusplusProjectDefines
+# define CdeCplusplusProjectDefines    CdeProjectDefines
+#endif
+#ifdef CplusplusProjectDefines
+# undef CplusplusProjectDefines
+#endif
+#define CplusplusProjectDefines        \
+       X11CplusplusProjectDefines MotifCplusplusProjectDefines CdeCplusplusProjectDefines
+
+/*
+ * Doc build rules
+ */
+
+/*
+ * MakeSdlVolume - generate rules to create an SDL volume, in the specified
+ * directory, from an SGML source doc.
+ * Note: the volume name must match the directory name.
+ */
+#ifndef MakeSdlVolume
+#define MakeSdlVolume(vol,dir,env,opts,dep)                            @@\
+all:: dir/vol.sdl                                                      @@\
+                                                                       @@\
+dir/vol.sdl: dep                                                       @@\
+       MakeDir(dir)                                                    @@\
+       env $(DTDOCBOOK) $(DTDOCBOOKOPTIONS) opts -o dir/vol.sdl vol/book.sgm   @@\
+                                                                       @@\
+clean::                                                                        @@\
+       $(RM) dir/vol.sdl vol/book.log
+#endif
+
+/*
+ * MakeTocFile - generate rules to create an SGML TOC file.
+ * Note: the volume name must match the directory name.
+ */
+#ifndef MakeTocFile
+#define MakeTocFile(vol,env,opts,ttle,ident,dep)                                       @@\
+all:: vol/TOC.sgm                                                      @@\
+                                                                       @@\
+vol/TOC.sgm: dep                                                       @@\
+       MakeDir($(DTINFOGENTMPDIR))                                     @@\
+       env $(DTINFOGEN) tocgen -T $(DTINFOGENTMPDIR) $(DTINFOGENOPTIONS) opts -f vol/TOC.sgm -id ident -title ttle vol/book.sgm        @@\
+                                                                       @@\
+clean::                                                                        @@\
+       $(RM) vol/TOC.sgm
+#endif
+
+#ifndef MakeTocFile3
+#define MakeTocFile3(vol,env,opts,ttle,ident,dep1,dep2,dep3)                   @@\
+all:: vol/TOC.sgm                                                      @@\
+                                                                       @@\
+vol/TOC.sgm: dep1                                                      @@\
+vol/TOC.sgm: dep2                                                      @@\
+vol/TOC.sgm: dep3                                                      @@\
+       MakeDir($(DTINFOGENTMPDIR))                                     @@\
+       env $(DTINFOGEN) tocgen -T $(DTINFOGENTMPDIR) $(DTINFOGENOPTIONS) opts -f vol/TOC.sgm -id ident -title ttle vol/book.sgm        @@\
+                                                                       @@\
+clean::                                                                        @@\
+       $(RM) vol/TOC.sgm
+#endif
+
+/*
+ * TocFileDep - generate TOC file dependency rule
+ */
+#ifndef TocFileDep
+#define TocFileDep(vol,dep)                                            @@\
+vol/TOC.sgm: dep
+#endif
+
+/*
+ * MakeInfolib - generate rules to create an infolib.
+ */
+#ifndef MakeInfolib
+#define MakeInfolib(infolib,bkcase,env,opts,dep)                       @@\
+all:: infolib/bkcase/dtsearch/dtsearch.ocf                             @@\
+                                                                       @@\
+infolib/bkcase/dtsearch/dtsearch.ocf: dep                              @@\
+       MakeDir($(DTINFOGENTMPDIR))                                     @@\
+       MakeDir(infolib)                                                @@\
+       env $(DTINFOGEN) build -T $(DTINFOGENTMPDIR) $(DTINFOGENOPTIONS) opts -l infolib bookcase.bc
+#endif
+
+/*
+ * InfolibDep - generate infolib dependency rule - Highly depending on MMDB!
+ */
+#ifndef InfolibDep
+#define InfolibDep(infolib,bkcase,dep)                                 @@\
+infolib/bkcase/dtsearch/dtsearch.ocf: dep
+#endif
+
+#ifndef InfolibDep3
+#define InfolibDep3(infolib,bkcase,dep1,dep2,dep3)                     @@\
+infolib/bkcase/dtsearch/dtsearch.ocf: dep1                             @@\
+infolib/bkcase/dtsearch/dtsearch.ocf: dep2                             @@\
+infolib/bkcase/dtsearch/dtsearch.ocf: dep3
+#endif
diff --git a/Xserver/config/cf/cde.tmpl b/Xserver/config/cf/cde.tmpl
new file mode 100644 (file)
index 0000000..5dfa301
--- /dev/null
@@ -0,0 +1,439 @@
+XCOMM $XConsortium: cde.tmpl /main/2 1996/12/04 10:13:09 swick $
+
+/* Include the Motif project template file. */
+#include <Motif.tmpl>
+
+#ifndef _CUse
+# if UseInstalledCDE
+#  define _CUse(a,b) a
+# else
+#  define _CUse(a,b) b
+# endif
+#endif
+
+#ifndef _CUseCat
+# if (defined(__STDC__) && !defined(UnixCpp)) || defined(AnsiCpp)
+#  if UseInstalledCDE
+#   define _CUseCat(a,b,c) a##c
+#  else
+#   define _CUseCat(a,b,c) b##c
+#  endif
+# else
+#  if UseInstalledCDE
+#   define _CUseCat(a,b,c) a/**/c
+#  else
+#   define _CUseCat(a,b,c) b/**/c
+#  endif
+# endif
+#endif
+
+#ifndef CDETop
+# if ImportCDE
+#  define CDETop $(TOP)/imports/cde
+# else
+#  define CDETop $(TOP)
+# endif
+#endif
+
+#define CDESharedRev           2.1
+
+#ifndef SharedLibPam
+# define SharedLibPam          HasSharedLibraries
+#endif
+#ifndef NormalLibPam
+# define NormalLibPam          (!SharedLibPam | ForceNormalLib)
+#endif
+#ifndef DebugLibPam
+# define DebugLibPam           NO
+#endif
+#ifndef ProfileLibPam
+# define ProfileLibPam         NO
+#endif
+#ifndef SharedPamRev
+# define SharedPamRev          CDESharedRev
+#endif
+
+#ifndef SharedLibTt
+# define SharedLibTt           HasSharedLibraries
+#endif
+#ifndef NormalLibTt
+# define NormalLibTt           (!SharedLibTt | ForceNormalLib)
+#endif
+#ifndef DebugLibTt
+# define DebugLibTt            NO
+#endif
+#ifndef ProfileLibTt
+# define ProfileLibTt          NO
+#endif
+#ifndef SharedTtRev
+# define SharedTtRev           CDESharedRev
+#endif
+
+#ifndef SharedLibDtSvc
+# define SharedLibDtSvc                HasSharedLibraries
+#endif
+#ifndef NormalLibDtSvc
+# define NormalLibDtSvc                (!SharedLibDtSvc | ForceNormalLib)
+#endif
+#ifndef DebugLibDtSvc
+# define DebugLibDtSvc         NO
+#endif
+#ifndef ProfileLibDtSvc
+# define ProfileLibDtSvc       NO
+#endif
+#ifndef SharedDtSvcRev
+# define SharedDtSvcRev                CDESharedRev
+#endif
+
+#ifndef SharedLibDtSearch
+# define SharedLibDtSearch     HasSharedLibraries
+#endif
+#ifndef NormalLibDtSearch
+# define NormalLibDtSearch     (!SharedLibDtSearch | ForceNormalLib)
+#endif
+#ifndef DebugLibDtSearch
+# define DebugLibDtSearch      NO
+#endif
+#ifndef ProfileLibDtSearch
+# define ProfileLibDtSearch    NO
+#endif
+#ifndef SharedDtSearchRev
+# define SharedDtSearchRev     CDESharedRev
+#endif
+
+#ifndef SharedLibDtWidget
+# define SharedLibDtWidget     HasSharedLibraries
+#endif
+#ifndef NormalLibDtWidget
+# define NormalLibDtWidget     (!SharedLibDtWidget | ForceNormalLib)
+#endif
+#ifndef DebugLibDtWidget
+# define DebugLibDtWidget      NO
+#endif
+#ifndef ProfileLibDtWidget
+# define ProfileLibDtWidget    NO
+#endif
+#ifndef SharedDtWidgetRev
+# define SharedDtWidgetRev     CDESharedRev
+#endif
+
+#ifndef SharedLibDtHelp
+# define SharedLibDtHelp       HasSharedLibraries
+#endif
+#ifndef NormalLibDtHelp
+# define NormalLibDtHelp       (!SharedLibDtHelp | ForceNormalLib)
+#endif
+#ifndef DebugLibDtHelp
+# define DebugLibDtHelp                NO
+#endif
+#ifndef ProfileLibDtHelp
+# define ProfileLibDtHelp      NO
+#endif
+#ifndef SharedDtHelpRev
+# define SharedDtHelpRev       CDESharedRev
+#endif
+
+#ifndef SharedLibDtPrint
+# define SharedLibDtPrint      HasSharedLibraries
+#endif
+#ifndef NormalLibDtPrint
+# define NormalLibDtPrint      (!SharedLibDtPrint | ForceNormalLib)
+#endif
+#ifndef DebugLibDtPrint
+# define DebugLibDtPrint       NO
+#endif
+#ifndef ProfileLibDtPrint
+# define ProfileLibDtPrint     NO
+#endif
+#ifndef SharedDtPrintRev
+# define SharedDtPrintRev      CDESharedRev
+#endif
+
+#ifndef SharedLibDtTerm
+# define SharedLibDtTerm       HasSharedLibraries
+#endif
+#ifndef NormalLibDtTerm
+# define NormalLibDtTerm       (!SharedLibDtTerm | ForceNormalLib)
+#endif
+#ifndef DebugLibDtTerm
+# define DebugLibDtTerm                NO
+#endif
+#ifndef ProfileLibDtTerm
+# define ProfileLibDtTerm      NO
+#endif
+#ifndef SharedDtTermRev
+# define SharedDtTermRev       CDESharedRev
+#endif
+
+#ifndef SharedLibDtMrm
+# define SharedLibDtMrm                HasSharedLibraries
+#endif
+#ifndef NormalLibDtMrm
+# define NormalLibDtMrm                (!SharedLibDtMrm | ForceNormalLib)
+#endif
+#ifndef DebugLibDtMrm
+# define DebugLibDtMrm         NO
+#endif
+#ifndef ProfileLibDtMrm
+# define ProfileLibDtMrm       NO
+#endif
+#ifndef SharedDtMrmRev
+# define SharedDtMrmRev                CDESharedRev
+#endif
+
+#ifndef SharedLibDtMmdb
+# define SharedLibDtMmdb       HasSharedLibraries
+#endif
+#ifndef NormalLibDtMmdb
+# define NormalLibDtMmdb       (!SharedLibDtMmdb | ForceNormalLib)
+#endif
+#ifndef DebugLibDtMmdb
+# define DebugLibDtMmdb                NO
+#endif
+#ifndef ProfileLibDtMmdb
+# define ProfileLibDtMmdb      NO
+#endif
+#ifndef SharedDtMmdbRev
+# define SharedDtMmdbRev       CDESharedRev
+#endif
+
+#ifndef SharedLibCsa
+# define SharedLibCsa          HasSharedLibraries
+#endif
+#ifndef NormalLibCsa
+# define NormalLibCsa          (!SharedLibCsa | ForceNormalLib)
+#endif
+#ifndef DebugLibCsa
+# define DebugLibCsa           NO
+#endif
+#ifndef ProfileLibCsa
+# define ProfileLibCsa         NO
+#endif
+#ifndef SharedCsaRev
+# define SharedCsaRev          CDESharedRev
+#endif
+
+#ifndef DtLocalesToBuild
+#define DtLocalesToBuild de_DE.ISO8859-1 es_ES.ISO8859-1 fr_FR.ISO8859-1 it_IT.ISO8859-1 ja_JP.dt-eucJP
+#endif
+
+#ifndef DtCodeGen
+# if UseInstalledCDE
+#  define DtCodeGen dtcodegen
+# else
+#  define DtCodeGen $(CLIENTENVSETUP) $(CDESRC)/dtappbuilder/src/abmf/dtcodegen
+# endif
+#endif
+
+#ifndef BuildCDEDoc
+# define BuildCDEDoc YES
+#endif
+
+#ifndef UseNSGMLS
+# ifdef SunArchitecture
+#  define UseNSGMLS NO
+# else
+#  define UseNSGMLS YES
+# endif
+#endif
+#ifndef SGMLParser
+# if UseNSGMLS
+#  define SGMLDir $(NSGMLSSRC)
+#  define SGMLParser $(NSGMLSSRC)/nsgmls
+# else
+#  define SGMLDir $(SGMLSSRC)
+#  define SGMLParser $(SGMLSSRC)/sgmls
+# endif
+#endif
+
+#ifndef DtInfoGen
+# if UseInstalledCDE
+#  define DtInfoGen dtinfogen
+# else
+#  define DtInfoGen $(CLIENTENVSETUP) $(DTLCXENVSETUP) DTINFO_HOME=$(DTINFOGENSRC) DTINFO_BIN=$(DTINFOGENSRC)/install:$(DTINFOGENSRC)/mmdb/StyleSheet:$(DTINFOGENSRC)/mmdb/src:SGMLDir:$(CDESRC)/dtsr $(DTINFOGENSRC)/infolib/etc/dtinfogen
+# endif
+#endif
+#ifndef DtInfoGenTmpDir
+#  define DtInfoGenTmpDir $(TOP)/doc/tmp
+#endif
+
+#ifndef DtDocBook
+# if UseInstalledCDE
+#  define DtDocBook dtdocbook
+# else
+#  define DtDocBook $(CLIENTENVSETUP) $(DTLCXENVSETUP) $(CDESRC)/dtdocbook/doc2sdl/dtdocbook
+# endif
+#endif
+#ifndef DtDocBookOptions
+# if UseInstalledCDE
+#  define DtDocBookOptions
+# else
+#  define DtDocBookOptions -t $(CDESRC)/dtdocbook/doc2sdl -H $(HELPTAGPASS2DEF) -I $(CDESRC)/dtdocbook/instant/instant -L $(CDESRC)/dtdocbook/xlate_locale/xlate_locale -S SGMLParser
+# endif
+#endif
+
+           CDETOP = CDETop
+#if ImportCDE || UseInstalledCDE
+    CDEINCLUDESRC = $(CDETOP)/include
+#else
+    CDEINCLUDESRC = $(CDETOP)/exports/include
+#endif
+ TOP_CDE_INCLUDES = -I$(CDEINCLUDESRC)
+        CDELIBSRC = $(CDETOP)/lib
+           PAMSRC = $(CDELIBSRC)/pam/libpam
+            TTSRC = $(CDELIBSRC)/tt
+         DTSVCSRC = $(CDELIBSRC)/DtSvc
+      DTSEARCHSRC = $(CDELIBSRC)/DtSearch
+      DTWIDGETSRC = $(CDELIBSRC)/DtWidget
+        DTHELPSRC = $(CDELIBSRC)/DtHelp
+       DTPRINTSRC = $(CDELIBSRC)/DtPrint
+        DTTERMSRC = $(CDELIBSRC)/DtTerm
+         DTMRMSRC = $(CDELIBSRC)/DtMrm
+        DTMMDBSRC = $(CDELIBSRC)/DtMmdb
+           CSASRC = $(CDELIBSRC)/csa
+           CDESRC = $(CDETOP)/programs
+#ifdef BuildLibPathVar
+      DTENVLIBDIR = CDEBuildLibPath
+#endif
+#ifdef CDEProjectRoot
+   CDEPROJECTROOT = CDEProjectRoot
+#endif
+ CDE_INSTALLATION_TOP = CdeInstallationTop
+CDE_CONFIGURATION_TOP = CdeConfigurationTop
+     CDE_LOGFILES_TOP = CdeLogFilesTop
+         CDE_USER_TOP = CdeUserTop
+
+        DTCODEGEN = DtCodeGen
+    HELPPARSERSRC = $(CDESRC)/dthelp/parser
+          HELPTAG = _CUseCat($(BINDIR),$(HELPPARSERSRC)/helptag,/dthelptag)
+  HELPTAGPASS1DEF = _CUseCat($(BINDIR),$(HELPPARSERSRC)/pass1/helptag,/dthelp_htag1)
+  HELPTAGPASS2DEF = _CUseCat($(BINDIR),$(HELPPARSERSRC)/pass2/htag2,/dthelp_htag2)
+        DTDOCBOOK = DtDocBook
+ DTDOCBOOKOPTIONS = DtDocBookOptions
+#if UseNSGMLS
+        NSGMLSSRC = $(CDESRC)/nsgmls
+#else
+         SGMLSSRC = $(CDESRC)/dtdocbook/sgmls
+#endif
+     DTINFOGENSRC = $(CDESRC)/dtinfo/dtinfogen
+        DTINFOGEN = DtInfoGen
+  DTINFOGENTMPDIR = DtInfoGenTmpDir
+#ifdef DtInfoGenOptions
+ DTINFOGENOPTIONS = DtInfoGenOptions
+#endif
+#ifdef ArchitectureDefines
+ ARCHITECTURE_DEFINES = ArchitectureDefines
+#endif
+#if !UseInstalledCDE
+DTLCXENVSETUP = DTLCXSEARCHPATH=$(DTHELPSRC)
+#endif
+
+#ifndef TtClientLibs
+# define TtClientLibs $(TTLIB) $(XLIB)
+#endif
+#ifndef TtClientDepLibs
+# define TtClientDepLibs $(DEPTTLIB) $(DEPXLIB)
+#endif
+
+/* These libraries use UseInstalledCDE instead of UseInstalled. */
+#undef _Use
+#undef _UseCat
+#define _Use    _CUse
+#define _UseCat _CUseCat
+
+#ifndef CDEBuildLibDir
+# define CDEBuildLibDir        BuildLibDir
+#endif
+
+#if SharedLibPam
+SharedLibReferences(PAM,pam,$(PAMSRC),SOPAMREV,SharedPamRev)
+#else
+ProjectUnsharedLibReferences(PAM,pam,$(PAMSRC),CDEBuildLibDir)
+#endif
+
+#if SharedLibTt
+SharedLibReferences(TT,tt,$(TTSRC)/lib,SOTTREV,SharedTtRev)
+#else
+ProjectUnsharedLibReferences(TT,tt,$(TTSRC)/lib,CDEBuildLibDir)
+#endif
+
+#if SharedLibDtSvc
+SharedLibReferences(DTSVC,DtSvc,$(DTSVCSRC),SODTSVCREV,SharedDtSvcRev)
+#else
+ProjectUnsharedLibReferences(DTSVC,DtSvc,$(DTSVCSRC),CDEBuildLibDir)
+#endif
+
+#if SharedLibDtSearch
+SharedLibReferences(DTSEARCH,DtSearch,$(DTSEARCHSRC),SODTSEARCHREV,SharedDtSearchRev)
+#else
+ProjectUnsharedLibReferences(DTSEARCH,DtSearch,$(DTSEARCHSRC),CDEBuildLibDir)
+#endif
+
+#if SharedLibDtWidget
+SharedLibReferences(DTWIDGET,DtWidget,$(DTWIDGETSRC),SODTWIDGETREV,SharedDtWidgetRev)
+#else
+ProjectUnsharedLibReferences(DTWIDGET,DtWidget,$(DTWIDGETSRC),CDEBuildLibDir)
+#endif
+
+#if SharedLibDtHelp
+SharedLibReferences(DTHELP,DtHelp,$(DTHELPSRC),SODTHELPREV,SharedDtHelpRev)
+#else
+ProjectUnsharedLibReferences(DTHELP,DtHelp,$(DTHELPSRC),CDEBuildLibDir)
+#endif
+
+#if SharedLibDtPrint
+SharedLibReferences(DTPRINT,DtPrint,$(DTPRINTSRC),SODTPRINTREV,SharedDtPrintRev)
+#else
+ProjectUnsharedLibReferences(DTPRINT,DtPrint,$(DTPRINTSRC),CDEBuildLibDir)
+#endif
+
+#if SharedLibDtTerm
+SharedLibReferences(DTTERM,DtTerm,$(DTTERMSRC),SODTTERMREV,SharedDtTermRev)
+#else
+ProjectUnsharedLibReferences(DTTERM,DtTerm,$(DTTERMSRC),CDEBuildLibDir)
+#endif
+
+#if SharedLibDtMrm
+SharedLibReferences(DTMRM,DtMrm,$(DTMRMSRC),SODTMRMREV,SharedDtMrmRev)
+#else
+ProjectUnsharedLibReferences(DTMRM,DtMrm,$(DTMRMSRC),CDEBuildLibDir)
+#endif
+
+#if SharedLibDtMmdb
+SharedLibReferences(DTMMDB,DtMmdb,$(DTMMDBSRC),SODTMMDBREV,SharedDtMmdbRev)
+#else
+ProjectUnsharedLibReferences(DTMMDB,DtMmdb,$(DTMMDBSRC),CDEBuildLibDir)
+#endif
+
+#if SharedLibDtCm
+SharedLibReferences(DTCM,DtCm,$(DTCMSRC),SODTCMREV,SharedDtCmRev)
+#else
+ProjectUnsharedLibReferences(DTCM,DtCm,$(DTCMSRC),CDEBuildLibDir)
+#endif
+
+#if SharedLibCsa
+SharedLibReferences(CSA,csa,$(CSASRC),SOCSAREV,SharedCsaRev)
+#else
+ProjectUnsharedLibReferences(CSA,csa,$(CSASRC),CDEBuildLibDir)
+#endif
+
+
+/* Revert to the normal library rules. */
+#undef _Use
+#undef _UseCat
+#define _Use    _XUse
+#define _UseCat _XUseCat
+
+
+#ifndef DtClientLibs
+# define DtClientLibs $(DTPRINTLIB) $(DTHELPLIB) $(DTWIDGETLIB) $(DTSVCLIB) $(TTLIB) $(XMLIB) $(XTOOLLIB) $(XPLIB) $(XLIB)
+#endif
+#ifndef DepDtClientLibs
+# define DepDtClientLibs $(DEPDTPRINTLIB) $(DEPDTHELPLIB) $(DEPDTWIDGETLIB) $(DEPDTSVCLIB) $(DEPTTLIB) $(DEPXMLIB) $(DEPXTOOLLIB) $(DEPXPLIB) $(DEPXLIB)
+#endif
+#ifndef DtClientSysLibs
+# define DtClientSysLibs $(DYNLIBSYSLIB) $(ICONVSYSLIB) $(REGEXSYSLIB) -lm
+#endif
+#ifndef DtClientExtraLibs
+# define DtClientExtraLibs /**/
+#endif
diff --git a/Xserver/config/cf/convex.cf b/Xserver/config/cf/convex.cf
new file mode 100644 (file)
index 0000000..deb6d76
--- /dev/null
@@ -0,0 +1,102 @@
+XCOMM platform:  $XConsortium: convex.cf /main/4 1996/09/28 16:09:50 rws $
+
+#ifndef OSName
+#define OSName                 ConvexOS V9.0
+#endif
+XCOMM operating system:  OSName
+#ifndef OSMajorVersion
+#define OSMajorVersion         9
+#endif
+#ifndef OSMinorVersion
+#define OSMinorVersion         0 
+#endif
+#ifndef VersionNumber
+#define VersionNumber          0.0.0.0
+#endif
+
+#define BootstrapCFlags        -tm c1
+#define SetTtyGroup            YES
+#define BuildServer             NO
+#define ConnectionFlags                -DTCPCONN -DUNIXCONN -DCOVUENETCONN
+#define InstallXdmConfig       YES
+#define XdmDir                 $(LIBDIR)/xdm-sample
+#define XdmServersType fs      /* one tab here */
+#define HasXmWidgets           NO
+#define InstKmemFlags          -g kmem -m 2711 -v $(VERSION)
+#define InstScriptFlags                -m 0755 -g bin
+#define InstManFlags           -m 0444 -g bin
+#define DefaultCCOptions       -fn -tm c1 
+#define LibraryCCOptions        -fx -tm c1 
+#define StripFlags             -r -x
+#define HasSecureOS            YES
+#define BuildExamples          YES
+#define BuildMotif             NO
+#define BuildConvexClients     YES
+#define MotifBC                        YES
+#define UilCommand             uil
+#define ExampleDir             $(LIBDIR)/examples
+#define UnSupDir               $(LIBDIR)/unsupported
+#define BuildTestExt           YES
+#define DefaultScreenSaverTime 0
+
+#if BuildTestExt
+#define TestDefines -DXTESTEXT1
+#else
+#define TestDefines /**/
+#endif
+
+#define ExtensionOSDefines TestDefines
+
+        VERSION = VersionNumber
+            UIL = UilCommand
+       UNSUPDIR = UnSupDir     /* unsupported examples and code */
+
+/*
+ * _Use - makes a choice based on UseInstalled.
+ */
+#ifndef _Use
+#ifdef UseInstalled
+#define _Use(a,b) a
+#else
+#define _Use(a,b) b
+#endif
+#endif
+
+/*
+ * _UseCat - combination of _Use and Concat.
+ *           exists to avoid problems with some preprocessors
+ */
+#ifndef _UseCat
+#if (defined(__STDC__) || (defined(__convex__) && defined(__stdc__)))
+&& !defined(UnixCpp)
+#ifdef UseInstalled
+#define _UseCat(a,b,c) a##c
+#else
+#define _UseCat(a,b,c) b##c
+#endif
+#else
+#ifdef UseInstalled
+#define _UseCat(a,b,c) a/**/c
+#else
+#define _UseCat(a,b,c) b/**/c
+#endif
+#endif
+#endif
+
+#if HasXmWidgets
+   MRESOURCESRC = $(LIBSRC)/Mrm
+DEPMRESOURCELIB = _UseCat($(USRLIBDIR),$(MRESOURCESRC),/libMrm.a)
+   MRESOURCELIB = LoaderLibPrefix _Use(-lMrm,$(DEPMRESOURCELIB))
+LINTMRESOURCELIB= _UseCat($(LINTLIBDIR),$(MRESOURCESRC),/llib-lMrm.ln)
+
+       XMLIBSRC = $(LIBSRC)/Xm
+       DEPXMLIB = _UseCat($(USRLIBDIR),$(XMLIBSRC),/libXm.a)
+          XMLIB = LoaderLibPrefix _Use(-lXm,$(DEPXMLIB))
+      LINTXMLIB = _UseCat($(LINTLIBDIR),$(XMLIBSRC),/llib-lXm.ln)
+
+      UILLIBSRC = $(LIBSRC)/uil
+      DEPUILLIB = _UseCat($(USRLIBDIR),$(UILLIBSRC),/libUil.a)
+         UILLIB = LoaderLibPrefix _Use(-lUil,$(DEPUILLIB))
+     LINTUILLIB = _UseCat($(LINTLIBDIR),$(UILLIBSRC),/llib-lUil.ln)
+
+#endif
diff --git a/Xserver/config/cf/cray.cf b/Xserver/config/cf/cray.cf
new file mode 100644 (file)
index 0000000..78f36c5
--- /dev/null
@@ -0,0 +1,50 @@
+XCOMM platform:  $XConsortium: cray.cf /main/52 1996/09/28 16:09:55 rws $
+
+#ifndef OSName
+#define OSName                 UNICOS 8.0
+#endif
+XCOMM operating system:  OSName
+#ifndef OSMajorVersion
+#define OSMajorVersion         8
+#endif
+#ifndef OSMinorVersion
+#define OSMinorVersion         0
+#endif
+
+#define SystemV                        YES
+#define Malloc0ReturnsNull     YES
+#define RemoveTargetProgramByMoving YES
+#define ArCmd                  bld cr
+#define StandardDefines                -DSYSV -DUSG
+#define ExecableScripts                NO
+#define HasPoll                        NO
+#define HasXServer             NO
+#define ConnectionFlags                -DTCPCONN
+#define HasShm                 NO
+#define PexNativeFPFormat      PEXCRAY_Floating
+#define NativeFPFormat         CRAY_Float
+#ifdef UseInstalled
+#define InstallCmd              install
+#else
+#define InstallCmd              $(SHELL) $(CONFIGSRC)/util/install.sh
+#endif
+
+#ifdef _CRAY2
+#define DefaultCCOptions       -hpagelm -hlimitlm
+#endif
+
+#if OSMajorVersion >= 6
+#define PreProcessCmd          /lib/pcpp
+#define CppCmd                 /lib/pcpp
+#else
+#  if OSMajorVersion == 5
+#  define PreProcessCmd        /lib/cpp
+#  define CppCmd               /lib/cpp
+#  define ExtraLoadFlags        -lnet
+#  endif
+#endif
+
+/* XKB library code does not work here yet */
+#define BuildXKBlib NO
+
+#define MotifDefines           -DNO_REGEX -DNO_REGCOMP
diff --git a/Xserver/config/cf/fujitsu.cf b/Xserver/config/cf/fujitsu.cf
new file mode 100644 (file)
index 0000000..d2c8c34
--- /dev/null
@@ -0,0 +1,95 @@
+XCOMM platform:  $TOG: fujitsu.cf /main/9 1997/04/17 14:11:44 barstow $
+
+#ifndef OSName
+# define OSName                DefaultOSName
+#endif
+#ifndef OSMajorVersion
+# define OSMajorVersion        DefaultOSMajorVersion
+#endif
+#ifndef OSMinorVersion
+# define OSMinorVersion        DefaultOSMinorVersion
+#endif
+XCOMM operating system: OSName (OSMajorVersion./**/OSMinorVersion)
+
+#define PatheticCpp       YES
+
+#ifdef SparcArchitecture
+
+#define BootstrapCFlags    -D__uxp__
+#define StandardDefines    -D__uxp__ -DSVR4 -DANSICPP
+#define StandardCppDefines -D__uxp__ -DSVR4 -DANSICPP
+
+#define CppCmd             /usr/ccs/lib/cpp
+
+#ifndef  ArCmdBase
+# define ArCmdBase     /usr/ccs/bin/ar
+#endif
+#ifndef  AsCmd
+# define AsCmd         /usr/ccs/bin/as
+#endif
+#ifndef  CcCmd
+# define CcCmd         /usr/ccs/bin/cc
+#endif
+#ifndef  CplusplusCmd
+# define CplusplusCmd  /opt/uxpcplus/bin/CC
+#endif
+#ifndef  CplusplusFilt
+# define CplusplusFilt /opt/uxpcplus/bin/c++filt
+#endif
+#ifndef  CplusplusDependIncludes
+# define CplusplusDependIncludes       -I/opt/uxpcplus/include/CC
+#endif
+#ifndef  LdCmd
+# define LdCmd         /usr/ccs/bin/ld
+#endif
+#ifndef  LexCmd
+# define LexCmd                /usr/ccs/bin/lex
+#endif
+#ifndef  YaccCmd
+# define YaccCmd       /usr/ccs/bin/yacc
+#endif
+
+#define BuildLibPathVar           LD_LIBRARY_PATH
+#define SystemV4          YES
+#define HasSockets         YES
+#define DBMLibrary         /* ndbm modules are in -lc */
+#define HasNdbm            YES
+#ifndef HasLdRunPath
+#define HasLdRunPath       YES
+#endif
+#define BuildServer        NO
+
+#include <sv4Lib.rules>
+
+#endif
+
+#ifdef mc68000Architecture
+
+#define BootstrapCFlags    -D__sxg__
+#define StandardDefines    -D__sxg__ -DSYSV -DUSG -DNOSTDHDRS -I/usr/xwin/include
+#define StandardCppDefines -D__sxg__ -DSYSV -DUSG -DNOSTDHDRS -I/usr/xwin/include
+
+#define LnCmd              ln
+
+#define DoRanlibCmd        NO 
+#define DefaultCCOptions   +Z384
+#define ExtraLibraries     -lXbsd -lsocket -lu
+#define TermcapLibrary     -lcurses
+#define BuildServer        NO
+#define HasSymLinks        NO
+#define HasVFork           NO
+#define XawI18nDefines     -DUSE_XWCHAR_STRING -DUSE_XMBTOWC
+
+#endif
+
+#define GencatFlags            -m
+
+#define DtSvcDefines           -DXK_MISCELLANY -DMULTIBYTE -DNO_REGCOMP -DHAVE_PTMS
+#define DtSearchDefines                -DI18N_MSG DtSvcDefines -DNEED_STRCASECMP
+#define DtWidgetDefines                DtSearchDefines
+
+#define ArchitectureDefines    -DUXP_ARCHITECTURE
+
+#define CdeProjectDefines \
+       -DMULTIBYTE -DNLS16 \
+       -DOSMAJORVERSION=OSMajorVersion -DOSMINORVERSION=OSMinorVersion
diff --git a/Xserver/config/cf/generic.cf b/Xserver/config/cf/generic.cf
new file mode 100644 (file)
index 0000000..de2b098
--- /dev/null
@@ -0,0 +1,21 @@
+XCOMM platform:  $XConsortium: generic.cf /main/8 1996/09/28 16:10:06 rws $
+
+#ifndef OSName
+#define OSName            Unknown Operating System
+#endif
+XCOMM operating system:  OSName
+#ifndef OSMajorVersion
+#define OSMajorVersion    0
+#endif
+#ifndef OSMinorVersion
+#define OSMinorVersion    0
+#endif
+
+#ifdef SYSV
+#define SystemV                YES
+#endif
+#ifdef SVR4
+#define SystemV4       YES
+#endif
+
+#define BuildServer    NO
diff --git a/Xserver/config/cf/hp.cf b/Xserver/config/cf/hp.cf
new file mode 100644 (file)
index 0000000..145714f
--- /dev/null
@@ -0,0 +1,207 @@
+XCOMM platform:  $TOG: hp.cf /main/85 1997/04/17 14:11:34 barstow $
+
+#ifndef OSName
+# define OSName                DefaultOSName
+#endif
+#ifndef OSMajorVersion
+# define OSMajorVersion        DefaultOSMajorVersion
+#endif
+#ifndef OSMinorVersion
+# define OSMinorVersion        DefaultOSMinorVersion
+#endif
+#ifndef OSTeenyVersion
+# define OSTeenyVersion        DefaultOSTeenyVersion
+#endif
+XCOMM operating system:  OSName (OSMajorVersion.OSMinorVersion.OSTeenyVersion)
+
+
+/* The default yacc options are too small for Uil.y. */
+#define YaccFlags -Nm15000
+
+/*
+ * C++ compiler setup.  This file knows what options to use with 
+ * certain compilers, including HP C++ and CenterLine C++.
+ * 
+ * For HP C++, define HasHPCplusplus to YES in site.def.  
+ * For CenterLine C++, define HasCenterLineCplusplus to YES in site.def.
+ * For other compilers, define HasCplusplus to YES in site.def, and 
+ *    check to see if you need to provide values for CplusplusOptions
+ *    and/or DefaultCplusplusOptions.
+ *
+ * In any case, you may also need to set CplusplusDependIncludes.
+ */
+
+#if HasHPCplusplus
+# ifndef  HasCplusplus
+#  define HasCplusplus YES
+# endif
+# ifndef  DefaultCplusplusOptions
+#  define DefaultCplusplusOptions      -Aa
+# endif
+# ifndef  CplusplusOptions
+#  define CplusplusOptions             -Aa
+# endif
+# ifndef  CplusplusCmd
+#  define CplusplusCmd                         /opt/CC/bin/CC
+# endif
+# ifndef  CplusplusDependIncludes 
+#  define CplusplusDependIncludes      -I/opt/CC/include/CC
+# endif
+#endif
+
+#ifndef  CcCmd
+# define CcCmd                 /opt/ansic/bin/cc
+#endif
+#ifndef  YaccCmd
+# define YaccCmd               /opt/langtools/bin/yacc
+#endif
+#ifndef  LexCmd
+# define LexCmd                        /opt/langtools/bin/lex
+#endif
+#ifndef  LintCmd
+# define LintCmd               /opt/ansic/bin/lint
+#endif
+
+#if HasCenterLineCplusplus
+# ifndef HasCplusplus
+#  define HasCplusplus                 YES
+# endif
+# ifndef OptimizedCplusplusDebugFlags
+#  define OptimizedCplusplusDebugFlags -O
+# endif
+# ifndef CplusplusDependIncludes 
+#  define CplusplusDependIncludes -I/usr/local/CenterLine/clc++/pa-hpux8/incl
+# endif
+#endif
+
+
+#define SystemV                                YES
+#define Malloc0ReturnsNull             YES
+
+#ifdef __hp9000s800
+# ifndef OptimizedCDebugFlags
+#  define OptimizedCDebugFlags         +O1
+# endif
+# ifndef DefaultCCOptions
+#  define DefaultCCOptions             -Ae +ESlit
+# endif
+# ifndef SharedLibraryCCOptions
+#  define SharedLibraryCCOptions       -Ae
+# endif
+# define StandardDefines               -Dhpux -DSYSV
+# define ServerExtraDefines            -DXOS -DBSTORE -DSOFTWARE_CURSOR -DNO_ALLOCA -DSCREEN_PIXMAPS -DMERGE_SAVE_UNDERS -DHAS_IFREQ -DFORCE_SEPARATE_PRIVATE
+
+# if OSMajorVersion > 9
+#  include <hpLib.rules>
+# endif
+
+#else /* __hp9000s800 */
+# define StandardDefines       -Dhpux -DSYSV
+# if OSMajorVersion < 8
+#  define DefaultCCOptions     -Wc,-Nd4000,-Ns4100,-Ne700,-Np200,-Nw300
+#  define PexCCOptions         -Wp,-H150000 -Wc,-Nd4000,-Ns8100,-Ne700,-Np200
+# else
+#  define OptimizedCDebugFlags +O1
+#  define PexCCOptions         -Wp,-H250000
+# endif
+# define PexShmIPC             NO
+# define LintOpts              -ax -Nd4000 -Ns8000 -Ne700 -Np200 -Na25000
+#endif
+#define MvCmd                  mv -f
+#define LdCombineFlags         -r
+#define ExecableScripts                YES
+#define HasVFork               YES
+#define HasPoll                        YES
+#define RemoveTargetProgramByMoving    YES
+#define ExpandManNames         YES
+#define HasPutenv              YES
+#define HasNdbm                        YES
+#define DBMLibrary             /usr/lib/libdbm.a
+#define PrimaryScreenResolution        91
+#define ExtensionOSDefines     -DHPINPUT # -DXTESTEXT1
+#define XhpServer              NO
+#define ServerExtraSysLibs     -ldld
+#ifndef BuildXInputExt
+# define BuildXInputExt                NO
+#endif
+#define BuildPex NO 
+#define BuildPexExt NO 
+#define XvncServer YES 
+#define HPFastScrolling                YES
+#ifndef BuildServer
+# define BuildServer           __hp9000s700
+#endif
+#define NeedBerklib            NO
+#define XawI18nDefines         -DHAS_WCHAR_H -DHAS_ISW_FUNCS
+
+#if OSMajorVersion < 6 || (OSMajorVersion == 6 && OSMinorVersion < 2)
+# define ConnectionFlags       -DTCPCONN       /* no unix sockets */
+#endif
+
+#if OSMajorVersion > 8
+#define HasWChar32             YES
+#define HasPlugin              YES
+#endif
+
+#ifdef __hp9000s300
+# ifndef CompatabilityDefines
+#  define CompatabilityDefines -D__hp9000s300 -Dhp9000s300
+# endif
+#elif defined(__hp9000s700)
+# ifndef CompatabilityDefines
+#  define CompatabilityDefines -D__hp9000s800 -Dhp9000s800 -D__hp9000s700
+# endif
+#else
+# ifndef CompatabilityDefines
+#  define CompatabilityDefines -D__hp9000s800 -Dhp9000s800
+# endif
+#endif
+
+#ifndef OsDefines
+# if OSMajorVersion > 9
+#  define OsDefines    -DhpV4 -DHPUX
+# else
+#  define OsDefines    -DHPUX
+# endif
+#endif
+
+#if OSMajorVersion > 9
+# if ThreadedX
+#  define MTSafeAPIDefines     -DXUSE_MTSAFE_API -DXUSE_NETDB_R_API
+# endif
+# define CppCmd                        /opt/langtools/lbin/cpp
+#endif
+
+/* CC does not recognize -Ae, and has a different meaning for +e. */
+/* +e also confuses cpp. */
+#define AnsiDefines            -Ae -D_HPUX_SOURCE
+#define CplusplusAnsiDefines   -Aa -D_HPUX_SOURCE
+
+#define BuildLibPathVar        SHLIB_PATH
+
+#define CdeBaseProjectDefines \
+       -DNLS16 -DMALLOC_0_RETURNS_NULL -DMERGE -D__hpux \
+       -DOSMAJORVERSION=OSMajorVersion -DOSMINORVERSION=OSMinorVersion \
+       CompatabilityDefines OsDefines
+
+#define CdeProjectDefines      CdeBaseProjectDefines AnsiDefines
+#define CdeCplusplusProjectDefines     \
+                               CdeBaseProjectDefines CplusplusAnsiDefines
+
+#define DtSvcDefines           -DXK_MISCELLANY -DMULTIBYTE -DMESSAGE_CAT
+#define DtSearchDefines                -DI18N_MSG DtSvcDefines
+#define DtWidgetDefines                DtSearchDefines
+#define DtPrintDefines         DtSearchDefines
+#if OSMajorVersion > 9
+#define DtMailDefines          \
+  -DBIG_ENDIAN -DDO_ANONYMOUS_MAP -DNEED_MMAP_WRAPPER -DSENDMAIL_LOCKS \
+  -DMAILGROUP_REQUIRED -DMAIL_SPOOL_PATH=\"/var/mail/%s\"
+#else
+#define DtMailDefines          \
+  -DBIG_ENDIAN -DDO_ANONYMOUS_MAP -DNEED_MMAP_WRAPPER -DSENDMAIL_LOCKS \
+  -DMAILGROUP_REQUIRED -DMAIL_SPOOL_PATH=\"/usr/mail/%s\"
+#endif
+
+#define ArchitectureDefines    -DHP_ARCHITECTURE
+
+#define ExportListGenSource    elistgen.hp
diff --git a/Xserver/config/cf/hpLib.rules b/Xserver/config/cf/hpLib.rules
new file mode 100644 (file)
index 0000000..c780fff
--- /dev/null
@@ -0,0 +1,119 @@
+XCOMM $XConsortium: hpLib.rules /main/16 1996/12/04 11:44:35 swick $
+
+/*
+ * HP shared library rules
+ */
+
+#ifndef HasSharedLibraries
+# define HasSharedLibraries YES
+#endif
+#ifndef SharedDataSeparation
+# define SharedDataSeparation NO
+#endif
+#ifndef SharedCodeDef
+# define SharedCodeDef /**/
+#endif
+#ifndef SharedLibraryDef
+# define SharedLibraryDef /**/
+#endif
+#ifndef ShLibIncludeFile
+# define ShLibIncludeFile <hpLib.tmpl>
+#endif
+#ifndef SharedLibraryLoadFlags
+# define SharedLibraryLoadFlags -b
+#endif
+#ifndef PositionIndependentCFlags
+# define PositionIndependentCFlags +z
+#endif
+#ifndef LargePositionIndependentCFlags
+# define LargePositionIndependentCFlags +Z
+#endif
+#ifndef InstLibFlags
+# define InstLibFlags -m 0555
+#endif
+#ifndef UseInstalled
+/* assert: LdPostLib pulls in -L$(USRLIBDIR), so it doesn't need to be here */
+# define ExtraLoadFlags -Wl,+s -Wl,+b$(USRLIBDIRPATH)
+#endif
+#ifndef UseExportLists
+# define UseExportLists        YES
+#endif
+
+/* Pre-linking shared libraries is supported in HP/UX 10. */
+#if OSMajorVersion > 9
+# define HPRequiredLibs        $(LDPRELIBS) $(REQUIREDLIBS) +s +b $(USRLIBDIRPATH)
+#else
+# define HPRequiredLibs        $(REQUIREDLIBS)
+#endif
+
+#ifndef LinkWithExports
+# if UseExportLists
+#  define LinkWithExports(libname,rev,solist,down,up) \
+       (cd down; $(LD) -o up/$@~ $(SHLIBLDFLAGS) +h $@ solist HPRequiredLibs)  @@\
+       if [ -f Concat(lib,libname.elist) ]; then \                     @@\
+           RemoveFiles($@.exports $@.list); \                          @@\
+           $(CPP) $(ALLINCLUDES) $(EXTRA_DEFINES) $(PROTO_DEFINES) $(THREADS_DEFINES) $(DEFINES) Concat(lib,libname.elist) | CppSedMagic >$@.list; \   @@\
+           $(EXPORTLISTGEN) $@~ $@.list > $@.exports; \                @@\
+           (cd down; $(LD) -c up/$@.exports -o up/$@~ $(SHLIBLDFLAGS) +h $@ solist HPRequiredLibs); \ @@\
+           RemoveFiles($@.exports $@.list); \                          @@\
+       fi
+# else
+#  define LinkWithExports(libname,rev,solist,down,up) \
+       (cd down; $(LD) -o up/$@~ $(SHLIBLDFLAGS) +h $@ solist HPRequiredLibs)
+# endif
+#endif
+
+/*
+ * InstallSharedLibrary - generate rules to install the shared library.
+ */
+#ifndef InstallSharedLibrary
+# define InstallSharedLibrary(libname,rev,dest)                                @@\
+install:: Concat(lib,libname.sl.rev)                                   @@\
+       MakeDir($(DESTDIR)dest)                                         @@\
+       RMoveToBakFile(Concat($(DESTDIR)dest/lib,libname.sl.rev))       @@\
+       $(INSTALL) $(INSTALLFLAGS) $(INSTLIBFLAGS) Concat(lib,libname.sl.rev) $(DESTDIR)dest @@\
+       $(RM) Concat($(DESTDIR)dest/lib,libname.sl)                     @@\
+       cd $(DESTDIR)dest; $(LN) Concat(lib,libname.sl.rev) Concat(lib,libname.sl) @@\
+       -RemoveFile(Concat(lib,libname.sl.rev.bak))
+
+#endif /* InstallSharedLibrary */
+
+/*
+ * InstallSharedLibraryData - generate rules to install the shared library data
+ */
+#ifndef InstallSharedLibraryData
+# define InstallSharedLibraryData(libname,rev,dest)
+#endif /* InstallSharedLibraryData */
+
+
+/*
+ * SharedLibraryTarget - generate rules to create a shared library;
+ * build it into a different name so that we do not hose people by having
+ * the library gone for long periods.
+ */
+#ifndef SharedLibraryTarget
+# define SharedLibraryTarget(libname,rev,solist,down,up)               @@\
+AllTarget(Concat(lib,libname.sl.rev))                                  @@\
+                                                                       @@\
+Concat(lib,libname.sl.rev):  solist $(EXTRALIBRARYDEPS)                        @@\
+       $(RM) $@~                                                       @@\
+       LinkWithExports(libname,rev,solist,down,up)                     @@\
+       -RemoveFiles($@ $@.bak)                                         @@\
+       MoveToBakFile($@)                                               @@\
+       $(MV) $@~ $@                                                    @@\
+       $(RM) Concat(lib,libname.sl)                                    @@\
+       $(LN) $@ Concat(lib,libname.sl)                                 @@\
+       LinkBuildLibrary($@)                                            @@\
+       LinkBuildLibrary(Concat(lib,libname.sl))                        @@\
+                                                                       @@\
+clean::                                                                        @@\
+       $(RM) Concat(lib,libname.sl.rev) Concat(lib,libname.sl)
+
+#endif /* SharedLibraryTarget */
+
+/*
+ * SharedLibraryDataTarget - generate rules to create shlib data file;
+ */
+#ifndef SharedLibraryDataTarget
+# define SharedLibraryDataTarget(libname,rev,salist)
+#endif /* SharedLibraryTarget */
diff --git a/Xserver/config/cf/hpLib.tmpl b/Xserver/config/cf/hpLib.tmpl
new file mode 100644 (file)
index 0000000..42e18a6
--- /dev/null
@@ -0,0 +1,37 @@
+XCOMM $XConsortium: hpLib.tmpl /main/10 1996/12/04 11:57:22 swick $
+
+/*
+ * HP shared library template
+ */
+
+#define SharedThreadReqs       /**/
+#define SharedOldXReqs         $(XLIBONLY)
+#define SharedX11Reqs          SharedThreadReqs
+#define SharedXtReqs           $(XLIBONLY) $(SMLIB) $(ICELIB) SharedThreadReqs
+#define SharedXawReqs          $(XMULIB) $(XTOOLLIB) $(XLIB)
+#define SharedXmuReqs          $(XTOOLLIB) $(XLIB)
+#define SharedXextReqs         $(XLIBONLY)
+#define SharedXiReqs           $(XLIB)
+#define SharedPexReqs          $(XLIBONLY) MathLibrary
+#define SharedXtstReqs         $(XLIB)
+#define SharedXieReqs          $(XLIBONLY)
+#define SharedSMReqs           $(ICELIB)
+#define SharedXpReqs           $(XLIB)
+
+#define SharedXReqs            $(XTOOLLIB) $(XPLIB) $(XLIB) SharedThreadReqs
+#define SharedXmReqs           SharedXReqs
+#define SharedMrmReqs          $(XMLIB) SharedXReqs
+#define SharedUilReqs          $(MRESOURCELIB) $(XMLIB) SharedXReqs
+
+/* #define SharedPamReqs */
+#define SharedTtReqs           $(XTOOLLIB) $(XLIB) SharedThreadReqs $(CXXLIB)
+#define SharedDtSvcReqs                $(TTLIB) $(XMLIB) SharedXReqs -lm $(CXXLIB)
+#define SharedDtMmdbReqs       $(DTSVCLIB) $(TTLIB) $(XMLIB) SharedXReqs -lm $(CXXLIB)
+#define SharedDtSearchReqs     -lm
+#define SharedDtWidgetReqs     $(DTSVCLIB) $(XMLIB) SharedXReqs -lm $(CXXLIB)
+#define SharedDtHelpReqs       $(DTSVCLIB) $(XMLIB) SharedXReqs -lm
+#define SharedDtPrintReqs      $(DTSVCLIB) $(DTHELPLIB) $(XMLIB) SharedXReqs -lm $(CXXLIB)
+#define SharedDtTermReqs       $(DTHELPLIB) $(DTSVCLIB) $(XMLIB) SharedXReqs -lm
+#define SharedDtMrmReqs                $(DTTERMLIB) $(DTPRINTLIB) $(DTHELPLIB) $(DTWIDGETLIB) $(MRESOURCELIB) $(XMLIB) SharedXReqs -lm
+#define SharedDtMailReqs       $(DTHELPLIB) $(DTSVCLIB) $(XMLIB) SharedXReqs -lm $(CXXLIB)
+#define SharedCsaReqs          $(DTSVCLIB) $(XMLIB) SharedXReqs -lm
diff --git a/Xserver/config/cf/ibm.cf b/Xserver/config/cf/ibm.cf
new file mode 100644 (file)
index 0000000..3450537
--- /dev/null
@@ -0,0 +1,168 @@
+XCOMM platform:  $XConsortium: ibm.cf /main/80 1996/12/26 08:52:31 kaleb $
+
+#ifndef OSName
+# define OSName                DefaultOSName
+#endif
+#ifndef OSMajorVersion
+# define OSMajorVersion        DefaultOSMajorVersion
+#endif
+#ifndef OSMinorVersion
+# define OSMinorVersion        DefaultOSMinorVersion
+#endif
+#ifndef OSTeenyVersion
+# ifdef DefaultOSTeenyVersion
+#  define OSTeenyVersion       DefaultOSTeenyVersion
+# elif (OSMajorVersion == 4) && (OSMinorVersion == 1)
+#  define OSTeenyVersion       3
+# else
+#  define OSTeenyVersion       0
+# endif
+#endif
+XCOMM operating system:  OSName (OSMajorVersion.OSMinorVersion.OSTeenyVersion)
+
+#if OSMajorVersion > 3 || (OSMajorVersion == 3 && OSMinorVersion >= 2)
+#define HasBSD44Sockets                YES
+#define HasPutenv              YES
+/*
+ * If you do not have threads support installed, put
+ * #define HasPosixThreads     NO
+ * in the BeforeVendorCF section of your site.def.
+ */
+#if !defined(HasPosixThreads) && ((OSMajorVersion == 3 && (OSMinorVersion > 2 || (OSMinorVersion == 2 && OSTeenyVersion > 4))) || (OSMajorVersion == 4 && (OSMinorVersion > 1 || (OSMinorVersion == 1 && OSTeenyVersion > 1))))
+#define HasPosixThreads                YES
+#endif
+#if HasPosixThreads
+#ifndef ThreadedX
+#define ThreadedX              YES
+#define MTSafeAPIDefines       -DXUSE_MTSAFE_API -DXUSE_NETDB_R_API
+#endif
+#endif
+#endif /* OS > 3.2 */
+
+/*
+ * For IBM platforms, we must define both the location of the compiler
+ * and the location of its standard C++ library.  The library location
+ * is needed to resolve dependent library symbols if we build our own
+ * C++ shared libraries.
+ */
+
+#if !HasGcc2ForCplusplus
+# ifndef CplusplusCmd
+#  if ThreadedX
+#   define CplusplusCmd                xlC_r
+#  else
+#   define CplusplusCmd                xlC
+#  endif
+# endif
+#endif
+
+#ifndef CplusplusFilt
+# define CplusplusFilt         /usr/lpp/xlC/bin/c++filt
+#endif
+#ifndef CplusplusLibC
+# if ThreadedX
+#  define CplusplusLibC                /usr/lpp/xlC/lib/libC.a
+# else
+#  define CplusplusLibC                /usr/lpp/xlC/lib/libC_r.a
+# endif
+#endif
+#if !HasGcc2ForCplusplus
+# ifndef CplusplusDependIncludes
+#  define CplusplusDependIncludes -I/usr/lpp/xlC/include
+# endif
+#endif
+
+/*
+ * IBM's xlC refuses to compile files unless their names end in ".C".
+ * As an alternative to this fix, one could edit /etc/xlC.cfg
+ * to change the suffix accepted by the compiler, but we prefer not 
+ * requiring users to reconfigure their C++ compilers to make them work.
+ * We also have to override the default SUFFIXES to defeat the use of
+ * the builtin .C -> .o file, which doesn't use the right flags.
+ */
+
+.SUFFIXES:
+.SUFFIXES: .o .c .y .l .s .sh .h .f .Y .L .cxx
+
+#define NormalLibObjCplusplusCompile(options) test -r $*.C || $(LN) $*.CCsuf $*.C @@\
+       $(CXX) -c $(CXXFLAGS) options $*.C
+
+#define SpecialCplusplusObjectRule(baseobj,basedep,options)            @@\
+baseobj.Osuf:  basedep.CCsuf                                           @@\
+       test -r basedep.C || $(LN) basedep.CCsuf basedep.C              @@\
+       $(CXX) -c $(CXXFLAGS) options basedep.C
+
+
+#define BuildLibPathVar                LIBPATH
+#define SystemV                        YES
+#define LdCombineFlags         -r
+#define ExecableScripts                YES
+#define Malloc0ReturnsNull     YES
+#define CppCmd                 /usr/ccs/lib/cpp
+#define ExpandManNames         YES
+#define ExtensionOSDefines     # -DXTESTEXT1
+#define XibmServer             NO
+#define ibmIncludeSKYWAY       YES
+
+/* IBM cpp has slightly non-standard line directives, but supports -P */
+#define CppNoLineInfoOption    -P
+
+#if OSMajorVersion > 3
+#define StandardDefines                -DSYSV -DAIXV3 -DAIXV4 -D_ALL_SOURCE
+#define XawI18nDefines         -DHAS_WCHAR_H -DHAS_ISW_FUNCS
+#define ServerExtraDefines     -D_IBM_LFT
+#if ThreadedX
+#define CcCmd                  xlc_r
+#else
+#define CcCmd                  xlc
+#endif
+#define SystemMTDefines                /* xlc_r defines -D_THREAD_SAFE */
+#define ThreadsLibraries       -lpthreads /* xlc_r does -lc_r */
+#define ThreadsCplusplusLibraries      -lpthreads
+#define AvoidNullMakeCommand   YES
+#define NullMakeCommand                @ echo
+/* AIX 4 appends all MAKEFLAGS (even dups), so cannot pass on command line. */
+#define ConstructMFLAGS                NO
+#define LdPreLib               _Use(-L$(USRLIBDIR),-L$(BUILDLIBDIR))
+#define ExtraFilesToClean      *.inp
+#else  /* OSMajorVersion < 4 */
+#define StandardDefines         -DSYSV -DAIXV3 -D_ALL_SOURCE
+#define ServerExtraDefines     -D_IBM_HFT
+#define CcCmd                  xlc
+#define ThreadPreStdAPIDefines -DXPRE_STANDARD_API
+#define SystemMTDefines                -D_THREAD_SAFE
+#define ThreadsLibraries       -lpthreads -lc_r
+#endif /* OSMajorVersion */
+
+#define OPERATING_SYSTEM       AIX /* directory name under server/ddx/ibm/ */
+#define InstallCmd              /usr/ucb/install
+#include <ibmLib.rules>
+
+#ifndef ManKeywordsTarget
+#define ManKeywordsTarget(manpath)                                     @@\
+man_keywords::                                                         @@\
+       /usr/lib/makewhatis $(DESTDIR)manpath
+#endif
+
+#define DtMailDefines          \
+  -DI_HAVE_NO_BOOL -DI_HAVE_SELECT_H \
+  -DBIG_ENDIAN -DSTRCASECMP_NOT_DEFINED -DDO_ANONYMOUS_MAP -DSENDMAIL_LOCKS \
+  -DMAILGROUP_REQUIRED -DMAIL_SPOOL_PATH=\"/var/spool/mail/%s\"
+
+#define ArchitectureDefines    -DIBM_ARCHITECTURE
+
+#define ExportListGenSource    elistgen.ibm
+
+#define CdeProjectDefines \
+       -D_AIX -D__AIX -D__aix -D_aix -Daix -DMULTIBYTE -DNLS16 -DMESSAGE_CAT \
+       -DOSMAJORVERSION=OSMajorVersion -DOSMINORVERSION=OSMinorVersion -DAIX
+
+/*
+ * -D__STR31__ disables inlining of memcpy to work around optimization bug
+ * in XLC v1.2.0.7. Bug report filed as PMR 8X196, branch 060.
+ */
+#ifndef OptimizedCDebugFlags
+#define OptimizedCDebugFlags   -O -D__STR31__ -DNDEBUG
+#endif
+
+#define CdeTicDefines  -DHAS_KNL -DHAS_KTAB
diff --git a/Xserver/config/cf/ibmLib.rules b/Xserver/config/cf/ibmLib.rules
new file mode 100644 (file)
index 0000000..d837cb7
--- /dev/null
@@ -0,0 +1,204 @@
+XCOMM $XConsortium: ibmLib.rules /main/15 1996/12/30 16:06:05 kaleb $
+
+/*
+ * AIX shared library rules
+ */
+
+#ifndef HasSharedLibraries
+# define HasSharedLibraries YES
+#endif
+#ifndef ForceNormalLib
+# define ForceNormalLib NO
+#endif
+#ifndef SharedDataSeparation
+# define SharedDataSeparation NO
+#endif
+#ifndef SharedCodeDef
+# define SharedCodeDef -DSHAREDCODE
+#endif
+#ifndef SharedLibraryDef
+# define SharedLibraryDef -DAIXSHLIB
+#endif
+#ifndef ShLibIncludeFile
+# define ShLibIncludeFile <ibmLib.tmpl>
+#endif
+#ifndef PositionIndependentCFlags
+# define PositionIndependentCFlags -bM\:SRE
+#endif
+#ifndef ExtraLoadFlags
+# define ExtraLoadFlags -bnodelcsect
+#endif
+#if !defined(LdPostLib) && !defined(UseInstalled) && OSMajorVersion > 3
+# if ThreadedX
+#  define LdPostLib -blibpath:$(USRLIBDIRPATH):/usr/lib/threads:/usr/lib:/lib
+# else
+#  define LdPostLib -blibpath:$(USRLIBDIRPATH):/usr/lib:/lib
+# endif
+# define SharedLibPostRef $(LDPOSTLIBS)
+#endif
+#ifndef SharedLibPostRef
+# define SharedLibPostRef $(LDPOSTLIBS)
+#endif
+#if ThreadedX
+# define BaseShLibReqs -lc_r -lm
+#else
+# define BaseShLibReqs -lc -lm
+#endif
+#ifndef UseExportLists
+# define UseExportLists YES
+#endif
+
+/*
+ * MakeExportList - generate an export list file for linking libraries.
+ */
+#ifndef MakeExportList
+# if UseExportLists
+#  define MakeExportList(libname,result) \
+       @-RemoveFile(result)                                            @@\
+       case ,$(SHR4OBJLIBS), in *,libname,*) shr4obj=shr4.o;; esac &&\ @@\
+               echo "#! $@ ($${shr4obj:-shr.o})" > result              @@\
+       if [ -f Concat(lib,libname.elist) ]; then \                     @@\
+           $(CPP) $(ALLINCLUDES) $(EXTRA_DEFINES) $(PROTO_DEFINES) $(THREADS_DEFINES) $(DEFINES) Concat(lib,libname.elist) | CppSedMagic > $@.list; \  @@\
+           $(EXPORTLISTGEN) $@~ $@.list >> result; \                   @@\
+           RemoveFile($@.list); \                                      @@\
+       else \                                                          @@\
+           dump -g $@~ | sed -n -e 's/^[       ]*[0-9][0-9]*[   ]*\([^  .][^    ]*\)$$/\1/p' >> result; \      @@\
+       fi;
+# else
+#  define MakeExportList(libname,result) \
+       @-RemoveFile(result)                                            @@\
+       case ,$(SHR4OBJLIBS), in *,libname,*) shr4obj=shr4.o;; esac &&\ @@\
+               echo "#! $@ ($${shr4obj:-shr.o})" > result              @@\
+       dump -g $@~ | sed -n -e 's/^[   ]*[0-9][0-9]*[   ]*\([^  .][^    ]*\)$$/\1/p' >> result;
+# endif
+#endif /* MakeExportList */
+
+
+#if !defined(UseInstalled) && !defined(UseInstalledX11) \
+    && !defined(UseImports) && !defined(ImportX11)
+   /* we want this to be defined only when building X */
+
+# if OSMajorVersion < 4
+/*
+ * SharedDSLibReferences - variables for shared libraries
+ */
+
+#  ifndef SharedLibReferences
+#   define SharedLibReferences(varname,libname,libsource,revname,rev)  @@\
+Concat3(DEP,varname,LIB) = /**/                                                @@\
+Concat(varname,LIB) = _Use(Concat(-l,libname),Concat(libsource/lib,libname.a)) @@\
+LintLibReferences(varname,libname,libsource)
+#  endif
+
+# else
+
+#  ifndef SharedLibReferences
+#   define SharedLibReferences(varname,libname,libsource,revname,rev)  @@\
+Concat3(DEP,varname,LIB) = /**/                                                @@\
+Concat(varname,LIB) = _Use(Concat(-l,libname),Concat($(BUILDLIBDIR),/libname.imp) Concat3($(BUILDLIBDIR),/lib,libname.a)) @@\
+LintLibReferences(varname,libname,libsource)
+#  endif
+
+# endif
+
+/*
+ * SharedDSLibReferences - variables for shared libraries
+ */
+# ifndef SharedDSLibReferences
+#  define SharedDSLibReferences(varname,libname,libsource,revname,rev) @@\
+SharedLibReferences(varname,libname,libsource,revname,rev)
+# endif
+
+# if OSMajorVersion == 4
+/*
+ * UnsharedLibReferences - variables for unshared libraries
+ */
+#  ifndef UnsharedLibReferences
+#   define UnsharedLibReferences(varname,libname,libsource)            @@\
+Concat3(DEP,varname,LIB) = _UseCat($(USRLIBDIR)/lib,$(BUILDLIBDIR)/lib,libname.a)      @@\
+Concat(varname,LIB) = _Use(Concat(-l,libname),Concat($(BUILDLIBDIR)/lib,libname.a))    @@\
+LintLibReferences(varname,libname,libsource)
+#  endif
+# endif
+
+#endif /* !defined(UseInstalled) && !defined(UseInstalledX11) ... */
+
+
+/*
+ * InstallSharedLibrary - generate rules to install the shared library.
+ */
+#ifndef InstallSharedLibrary
+# define InstallSharedLibrary(libname,rev,dest)                                @@\
+InstallLibrary(libname,dest)
+#endif /* InstallSharedLibrary */
+
+/*
+ * InstallSharedLibraryData - generate rules to install the shared library data
+ */
+#ifndef InstallSharedLibraryData
+# define InstallSharedLibraryData(libname,rev,dest)
+#endif /* InstallSharedLibraryData */
+
+/*
+ * SharedLibraryTarget - generate rules to create a shared library;
+ * build it into a different name so that the we do not hose people by having
+ * the library gone for long periods.
+ *
+ * IBM uses an unusual shared object file name (shr4.o) in some libraries. 
+ * Duplicate this behavior to preserve compatibility with IBM's libraries.
+ */
+#if OSMajorVersion < 4
+
+# ifndef SharedLibraryTarget
+#  define SharedLibraryTarget(libname,rev,solist,down,up)              @@\
+AllTarget(Concat(lib,libname.a))                                       @@\
+                                                                       @@\
+Concat(lib,libname.a):  solist $(UNSHAREDOBJS) $(EXTRALIBRARYDEPS)     @@\
+       $(RM) $@~ shr.o shr4.o                                          @@\
+       (cd down; $(AR) up/$@~ solist)                                  @@\
+       dump -g $@~ | sed -n -e 's/^[   ]*[0-9][0-9]*[   ]*\([^  .][^    ]*\)$$/\1/p' > $@.syms @@\
+       $(LD) -o shr.o $@~ -H512 -T512 -bM\:SRE -bE\:$@.syms $(REQUIREDLIBS) BaseShLibReqs SharedLibPostRef     @@\
+       $(LN) shr.o shr4.o                                              @@\
+       $(RM) $@~                                                       @@\
+       case ,$(SHR4OBJLIBS), in *,libname,*) shr4obj=shr4.o;; esac &&\ @@\
+               $(AR) $@~ $${shr4obj} shr.o $(UNSHAREDOBJS)             @@\
+       $(RM) $@.syms $@ shr.o shr4.o                                   @@\
+       $(MV) $@~ $@                                                    @@\
+       LinkBuildLibrary($@)                                            @@\
+                                                                       @@\
+clean::                                                                        @@\
+       $(RM) Concat(lib,libname.a)
+# endif /* SharedLibraryTarget */
+
+#else /* OSMajorVersion >= 4 */
+
+# ifndef SharedLibraryTarget
+#  define SharedLibraryTarget(libname,rev,solist,down,up)              @@\
+AllTarget(Concat(lib,libname.a))                                       @@\
+                                                                       @@\
+Concat(lib,libname.a):  solist $(UNSHAREDOBJS) $(EXTRALIBRARYDEPS)     @@\
+       RemoveFiles($@~ shr.o shr4.o)                                   @@\
+       (cd down; $(AR) up/$@~ solist)                                  @@\
+       MakeExportList(libname,libname.imp)                             @@\
+       $(LD) -o shr.o $@~ -H512 -T512 -bM\:SRE -bE\:libname.imp -bnoentry $(REQUIREDLIBS) BaseShLibReqs $(LDPOSTLIBS)  @@\
+       $(LN) shr.o shr4.o                                              @@\
+       RemoveFile($@~)                                                 @@\
+       case ,$(SHR4OBJLIBS), in *,libname,*) shr4obj=shr4.o;; esac &&\ @@\
+               $(AR) $@~ $${shr4obj} shr.o $(UNSHAREDOBJS)             @@\
+       RemoveFile($@)                                                  @@\
+       $(MV) $@~ $@                                                    @@\
+       LinkBuildLibrary($@)                                            @@\
+       LinkBuildLibrary(libname.imp)                                   @@\
+                                                                       @@\
+clean::                                                                        @@\
+       $(RM) Concat(lib,libname.a)
+# endif /* SharedLibraryTarget */
+
+#endif
+
+/*
+ * SharedLibraryDataTarget - generate rules to create shlib data file;
+ */
+#ifndef SharedLibraryDataTarget
+# define SharedLibraryDataTarget(libname,rev,salist)
+#endif /* SharedLibraryTarget */
diff --git a/Xserver/config/cf/ibmLib.tmpl b/Xserver/config/cf/ibmLib.tmpl
new file mode 100644 (file)
index 0000000..f989d76
--- /dev/null
@@ -0,0 +1,76 @@
+XCOMM $XConsortium: ibmLib.tmpl /main/21 1996/12/04 12:21:49 swick $
+
+/*
+ * AIX shared library template
+ */
+
+/*
+ * IBM used an unusual shared object file name in some librares. 
+ * Mimic this behavior to preserve compatibility with IBM's libraries.
+ */
+#ifndef IBMShr4Compatibility
+#define IBMShr4Compatibility   YES
+#endif
+
+/*
+ * Imake thinks lines with colons are the result of a broken cpp
+ * inserting extra leading whitespace, so use ',' as a separator.
+ */
+#if IBMShr4Compatibility
+      SHR4OBJLIBS = X11,Xt,oldX,Xm,Mrm,Uil
+#endif
+
+#if ThreadedX
+#define SharedThreadReqs -lpthreads
+#define SharedX11Reqs -lpthreads
+#else
+#define SharedThreadReqs /**/
+#endif
+
+#define SharedXextReqs $(XLIBONLY)
+#define SharedXmuReqs  $(XTOOLLIB) $(XLIB)
+#define SharedOldXReqs $(XLIBONLY)
+#define SharedXtReqs   $(XLIBONLY) $(SMLIB) $(ICELIB) SharedThreadReqs
+#define SharedXawReqs  $(XMULIB) $(XTOOLLIB) $(XLIB)
+#define SharedXiReqs   $(XLIB)
+#define SharedXtstReqs $(XLIB)
+#define SharedPexReqs  $(XLIBONLY)
+#define SharedXieReqs  $(XLIBONLY)
+#define SharedSMReqs   $(ICELIB)
+#define SharedXpReqs   $(XLIB)
+
+#define SharedXReqs    $(XTOOLLIB) $(XPLIB) $(XLIB) SharedThreadReqs
+#define SharedXmReqs   $(LDPRELIBS) SharedXReqs
+#define SharedMrmReqs  $(LDPRELIBS) $(XMLIB) SharedXReqs
+#define SharedUilReqs  $(LDPRELIBS) $(MRESOURCELIB) $(XMLIB) SharedXReqs
+
+/* #define SharedPamReqs */
+#define SharedTtReqs   $(LDPRELIBS) SharedXReqs $(CXXLIB)
+#define SharedDtSvcReqs        $(LDPRELIBS) $(TTLIB) $(XMLIB) SharedXReqs $(CXXLIB)
+#define SharedDtMmdbReqs $(LDPRELIBS) $(DTSVCLIB) $(TTLIB) $(XMLIB) SharedXReqs $(CXXLIB)
+#define SharedDtSearchReqs $(LDPRELIBS) -lisode
+#define SharedDtWidgetReqs $(LDPRELIBS) $(DTSVCLIB) $(XMLIB) SharedXReqs 
+#define SharedDtHelpReqs $(LDPRELIBS) $(DTSVCLIB) $(XMLIB) SharedXReqs -liconv
+#define SharedDtPrintReqs $(LDPRELIBS) $(DTSVCLIB) $(DTHELPLIB) $(XMLIB) SharedXReqs
+#define SharedDtTermReqs $(LDPRELIBS) $(DTHELPLIB) $(DTSVCLIB) $(XMLIB) SharedXReqs -liconv -lm
+#define SharedDtMrmReqs $(LDPRELIBS) $(DTTERMLIB) $(DTPRINTLIB) $(DTHELPLIB) $(DTWIDGETLIB) $(MRESOURCELIB) $(XMLIB) SharedXReqs
+#define SharedCsaReqs  $(LDPRELIBS) $(DTSVCLIB) $(XMLIB) SharedXReqs
+
+#if !defined(UseInstalled) && !defined(UseInstalledX11) \
+    && !defined(UseImports) && !defined(ImportX11)
+   /* we want this to be defined only when building X */
+# ifndef FixupLibReferences
+# define FixupLibReferences()                                          @@\
+DEPXTOOLLIB = _UseCat($(USRLIBDIR),$(TOOLKITSRC),/libXt.a)
+# endif
+#endif
+
+/* The inbuf paramter to iconv(3) is "const char**", not "char **" */
+ICONV_INBUF_DEFINE = -DICONV_INBUF_CONST
+
+ICONVSYSLIB = -liconv
+
+#if (OSMajorVersion > 4) || ((OSMajorVersion == 4) && (OSMinorVersion >= 2))
+DYNLIBSYSLIB = -ldl
+#endif
+
diff --git a/Xserver/config/cf/isc.cf b/Xserver/config/cf/isc.cf
new file mode 100644 (file)
index 0000000..2c04c7f
--- /dev/null
@@ -0,0 +1,214 @@
+XCOMM $XConsortium: isc.cf /main/1 1996/10/31 14:45:18 kaleb $
+
+
+
+XCOMM platform:  $XFree86: xc/config/cf/isc.cf,v 3.11.2.1 1998/02/15 16:08:33 hohndel Exp $
+
+#ifndef HasGcc2
+#define HasGcc2                        YES
+#endif
+
+/* INTERACTIVE UNIX SYSTEM (IUS) Version 3.x 4.x */
+
+#if IscVersion > 300
+# define ISCVerDef -DISC40 -DISC30
+# define OSVendor              (IUS Version 4.x)
+#else
+# if IscVersion == 300
+#  define ISCVerDef -DISC30
+#  define OSVendor             (ISC Version 3.0)
+# else
+#  if IscVersion == 202
+#   define OSVendor            (ISC Version 2.0.2)
+#   define ISCVerDef -DISC202
+#  else
+#   define OSVendor            (ISC Version 2.2.1)
+#   define ISCVerDef -DISC22
+#  endif
+# endif
+#endif
+
+/* gcc 2.7.2 tested Optimization Flags                               */
+#ifndef DefaultGcc2i386Opt
+# define DefaultGcc2i386Opt    -m486 -O2 -fno-strength-reduce -malign-loops=2 -malign-jumps=2 -malign-functions=2
+/* -fomit-frame-pointer */ 
+#endif
+
+/* For a POSIXized build on Interactive maybe needed to use gcc2.7.2 */
+#ifndef UsePosix
+# define UsePosix              YES
+#endif
+
+/* ISC 4.1Mu 
+#define IscCompileVersion      410
+*/
+
+#if !defined(IscCompileVersion) && IscVersion < 410
+/* ISC 4.0 compatible */
+#define IscCompileVersion      400
+#endif
+
+#if IscCompileVersion == 400
+
+/* binaries which should run on ISC 4.0 or for the build on a real 4.0 System */
+# define UseChmod              YES
+
+/* for compatibility with ISC 4.0 - reported by Ami Fischmann            */
+/* troubles when linking with libX11.a build on ISC4.1 and used with 4.0 */
+# define HasSnprintf           NO
+# define UseXwctomb            YES
+
+#endif
+
+#if defined(UseXwctomb)
+# define XwctombDefine -DUSE_XMBTOWC 
+#else
+# define XwctombDefine 
+#endif 
+
+#if defined(UseChmod)
+# define IscCompatDefines      XwctombDefine -DUSE_CHMOD
+#else
+# define IscCompatDefines      XwctombDefine
+#endif 
+
+#ifdef UsePosix
+# define PosixDefines          -posix -D_SYSV3 -D_POSIX_SOURCE 
+#else
+# define PosixDefines
+#endif
+
+#define OSDefines              -DISC ISCVerDef IscCompatDefines
+
+/*
+#define OSName                 Unix System V/386 Release 3.2
+#define OSMajorVersion         3
+#define OSMinorVersion         2
+*/
+#ifndef OSMajorVersion
+#define OSMajorVersion         DefaultOSMajorVersion
+#endif
+#ifndef OSMinorVersion
+#define OSMinorVersion         DefaultOSMinorVersion
+#endif
+#ifndef OSTeenyVersion
+#define OSTeenyVersion         DefaultOSTeenyVersion
+#endif
+
+#ifndef OSName
+#define OSName                 INTERACTIVE UNIX System V/386 Release 3.2
+#endif
+
+XCOMM operating system: OSName (OSMajorVersion./**/OSMinorVersion./**/OSTeenyVersion)
+
+/* Note, cpp already does -Di386 */
+#define BootstrapCFlags                OSDefines -DSYSV
+
+#if IscVersion > 202
+# define LocalLibraries        -lpt
+# define PosixLibraries        -lcposix
+#else
+# define LocalLibraries        MallocLibrary -lpt
+# define PosixLibraries
+#endif
+
+#define SocketLibraries                -linet
+
+#ifndef GnuMallocLibrary
+#ifndef UseIscLd
+# define GnuMallocLibrary      -L/usr/local/lib -lgmalloc
+#else
+# define GnuMallocLibrary       /usr/local/lib/libgmalloc.a
+#endif
+#endif
+
+#ifndef MallocLibrary
+# if UseGnuMalloc
+#  define MallocLibrary                GnuMallocLibrary
+# else
+#  define MallocLibrary                -lmalloc
+# endif
+#endif
+
+#ifndef ExtraLibraries
+# if UseGnuMalloc
+#  define ExtraLibraries SocketLibraries LocalLibraries MallocLibrary PosixLibraries
+# else
+#  define ExtraLibraries SocketLibraries LocalLibraries PosixLibraries
+# endif
+#endif
+
+/* Don't know if this is necessary, but it avoids breaking the current setup */
+#define MallocLibraries                /**/
+
+#if UseXwctomb
+#define XawI18nDefines         -DUSE_XWCHAR_STRING
+#else
+#define XawI18nDefines         -DUSE_XWCHAR_STRING -DUSE_XMBTOWC
+#endif
+
+#if HasCbrt
+#define MathLibrary -loptm
+#endif
+
+#ifdef UseInlineMath
+#define InlineMathDefines      -DUseInlineMath
+#if !HasCbrt
+#define ServerExtraSysLibs     $(CBRT) MathLibrary
+#endif
+#endif
+
+#ifndef ServerExtraSysLibs
+#define ServerExtraSysLibs     $(CBRT)
+#endif
+
+#define ServerExtraDefines     SVR3mmapFlags XFree86ServerDefines
+
+#if IscVersion > 300
+# ifndef HasSymLinks
+#  define HasSymLinks           YES
+# endif
+#endif
+
+#define HasShm                 YES
+
+#ifndef HasSnprintf
+#define HasSnprintf            YES
+#endif
+
+#ifndef HasLibCrypt
+#define HasLibCrypt            YES
+#define SpecialLibCrypt        -lcrypt
+#endif
+
+#ifndef DefaultCDebugFlags
+# if HasGcc2
+#  define DefaultCDebugFlags DefaultGcc2i386Opt PosixDefines InlineMathDefines
+# else
+#  define DefaultCDebugFlags -O PosixDefines InlineMathDefines
+# endif
+#endif
+
+#if HasGcc2
+# define CcCmd gcc 
+#endif
+
+#ifndef DefaultCplusplusOptions
+#define DefaultCplusplusOptions        -fno-implicit-templates
+#endif
+
+#ifndef ConnectionFlags
+#define ConnectionFlags -DLOCALCONN -DTCPCONN 
+/* -DSTREAMSCONN -DUNIXCONN -- does not work on ISC SVR3 */
+#endif
+
+#define CompressManCmd $(COMPRESS) -v
+
+#define XmanSearchPath /usr/catman
+
+#ifndef RemoveDSDENroffMacros
+#define RemoveDSDENroffMacros   YES
+#endif
+
+#include <svr3.cf>
+
diff --git a/Xserver/config/cf/linux.cf b/Xserver/config/cf/linux.cf
new file mode 100644 (file)
index 0000000..2bbbcc8
--- /dev/null
@@ -0,0 +1,883 @@
+XCOMM platform:  $Xorg: linux.cf,v 1.3 2000/08/17 19:41:47 cpqbld Exp $
+
+
+
+
+
+XCOMM platform:  $XFree86: xc/config/cf/linux.cf,v 3.165 2001/04/19 19:54:43 dawes Exp $
+
+#ifndef LinuxElfDefault
+# define LinuxElfDefault       YES
+#endif
+
+#ifndef UseElfFormat
+# define UseElfFormat          LinuxElfDefault
+#endif
+
+#ifndef OSBinaryType
+# if UseElfFormat
+#  define OSBinaryType         [ELF]
+# else
+#  ifdef AlphaArchitecture
+#   define OSBinaryType                [ECOFF]
+#  else
+#   define OSBinaryType                [a.out]
+#  endif
+# endif
+#endif
+
+#ifndef OSName
+# define OSName                        DefaultOSName OSBinaryType
+#endif
+
+#ifndef OSVendor
+# define OSVendor              /**/
+#endif
+#ifndef OSMajorVersion
+# define OSMajorVersion                DefaultOSMajorVersion
+#endif
+#ifndef OSMinorVersion
+# define OSMinorVersion                DefaultOSMinorVersion
+#endif
+#ifndef OSTeenyVersion
+# define OSTeenyVersion                DefaultOSTeenyVersion
+#endif
+
+#ifndef LinuxDistribution
+# define LinuxDistribution     DefaultLinuxDistribution
+/*
+  Add "#define LinuxDistribution Linux<mumble>" to your site.def or host.def.
+  Currently only LinuxSuSE, LinuxRedHat and LinuxDebian will be figured out
+  automatically.
+  Valid values are (from the list at www.linux.org in Oct. '97):
+    LinuxUnknown    (0)
+    LinuxSuSE       (1)
+    LinuxCaldera    (2)
+    LinuxCraftworks (3)
+    LinuxDebian     (4)
+    LinuxInfoMagic  (5)
+    LinuxKheops     (6)
+    LinuxPro        (7)
+    LinuxRedHat     (8)
+    LinuxSlackware  (9)
+    LinuxTurbo      (10)
+    LinuxWare       (11)
+    LinuxYggdrasil  (12)
+*/
+#endif
+#ifndef LinuxDistName
+# define LinuxDistName         DefaultLinuxDistName
+#endif
+#ifndef LinuxCLibMajorVersion
+# define LinuxCLibMajorVersion DefaultLinuxCLibMajorVersion
+#endif
+#ifndef LinuxCLibMinorVersion
+# define LinuxCLibMinorVersion DefaultLinuxCLibMinorVersion
+#endif
+#ifndef LinuxCLibTeenyVersion
+# define LinuxCLibTeenyVersion DefaultLinuxCLibTeenyVersion
+#endif
+
+#ifndef LinuxBinUtilsMajorVersion
+# define LinuxBinUtilsMajorVersion     DefaultLinuxBinUtilsMajorVersion
+#endif
+
+XCOMM operating system:  OSName (OSMajorVersion./**/OSMinorVersion./**/OSTeenyVersion)
+XCOMM libc:    (LinuxCLibMajorVersion./**/LinuxCLibMinorVersion./**/LinuxCLibTeenyVersion)
+XCOMM binutils:        (LinuxBinUtilsMajorVersion)
+
+#if LinuxDistribution == LinuxDebian
+# define SystemManDirectory    /usr/share/man
+# define HasPam                        YES
+# define HasTk                 YES
+# define TkLibDir              /usr/lib
+# define TkIncDir              /usr/include
+# define TkLibName             tk8.3
+# define XF86SetupUsesStaticTk NO
+# define HasTcl                        YES
+# define TclLibDir             /usr/lib
+# define TclIncDir             /usr/include
+# define TclLibName            tcl8.3
+# define XF86SetupUsesStaticTcl        NO
+/* un-comment this when it is un-broken */
+/* # define JoystickSupport YES */
+# define InstallXinitConfig    YES
+# define InstallXdmConfig      YES
+# define InstallFSConfig       YES
+# define DebuggableLibraries   YES
+# define ForceNormalLib                YES
+# define BuildSpecsDocs                YES
+# define SpecsDocDirs          CTEXT GL ICCCM X11 Xext Xv i18n xterm
+# define XAppLoadDir           EtcX11Directory/app-defaults
+# define XFileSearchPathDefault        Concat4(EtcX11Directory/%L/%T/%N%C,%S:EtcX11Directory/%l/%T/%N%C,%S:EtcX11Directory/%T/%N%C,%S:EtcX11Directory/%L/%T/%N%S:EtcX11Directory/%l/%T/%N%S:EtcX11Directory/%T/%N%S):Concat4($(LIBDIR)/%L/%T/%N%C,%S:$(LIBDIR)/%l/%T/%N%C,%S:$(LIBDIR)/%T/%N%C,%S:$(LIBDIR)/%L/%T/%N%S:$(LIBDIR)/%l/%T/%N%S:$(LIBDIR)/%T/%N%S)
+/* the relative symlink created by this rule causes problems for us */
+# if InstallAppDefFiles
+#  define InstallAppDefaultsLong(file,class)                           @@\
+InstallNamedTarget(install,file.ad,$(INSTAPPFLAGS),$(XAPPLOADDIR),class)
+# else
+#  define InstallAppDefaultsLong(file,class)                           @@\
+InstallNamedTargetNoClobber(install,file.ad,$(INSTAPPFLAGS),$(XAPPLOADDIR),class)
+# endif /* InstallAppDefFiles */
+# define SharedLibXdmGreet     NO
+# define LinkGLToUsrInclude    NO
+# define LinkGLToUsrLib                NO
+# define SharedLibFont         NO
+# define HasZlib               YES
+# define BuildGLXLibrary       YES
+# define BuildGLULibrary       YES
+# define BuildRman             NO
+# define BuildHtmlManPages     NO
+# define FSUseSyslog           YES
+
+/*
+ *
+ */
+# define DebianMaintainer      "xfree86@packages.debian.org"
+/*
+ *
+ */
+
+# ifdef DebianMaintainer
+#  define BuilderEMailAddr     "submit@bugs.debian.org"
+#  define XFree86Devel         YES
+#  define BuildAllSpecsDocs    YES
+/* we build-depend on libfreetype6-dev (FreeType 2.x) */
+#  define BuildFreetype2Library        NO
+#  define HasFreetype2         YES
+/* m68k has no 2.4 kernel yet */
+#  ifndef Mc68020Architecture
+#   define HasLinuxInput               YES
+#  endif
+#  define HasXdmAuth           YES
+#  define HasLatex             YES
+/* at present, glide2 only works on i386 */
+#  ifdef i386Architecture
+#   define HasGlide2           YES
+#   define Glide2IncDir                /usr/include/glide
+#  endif /* i386Architecture */
+/* at present, glide3 only works on alpha and i386 */
+#  if defined(i386Architecture) || defined(AlphaArchitecture)
+#   define HasGlide3           YES
+#   define Glide3IncDir                /usr/include/glide3
+#  endif /* i386Architecture || AlphaArchitecture */
+/* extended instruction set support */
+#  ifdef i386Architecture
+#   define HasMMXSupport       YES
+#   define Has3DNowSupport     YES
+/* 2.4 is not yet the official (or predominant) kernel in unstable */
+#   define HasKatmaiSupport    NO
+#  endif /* i386Architecture */
+# endif /* DebianMaintainer */
+#endif /* LinuxDebian */
+
+#if LinuxDistribution == LinuxRedHat
+#define FSUseSyslog            YES
+#endif
+
+/*
+ * The Linux BinUtils major version.  25 => 2.5.x, which is what is included
+ * with Slackware 3.0
+ *
+ * This remains for compatibility only.
+ *
+ */
+#ifndef BinUtilsMajorVersion
+# define BinUtilsMajorVersion  LinuxBinUtilsMajorVersion
+#endif
+
+#if (LinuxCLibMajorVersion >= 6 || LinuxDistribution == LinuxSuSE)
+# define LinuxLocaleDefines    /**/
+#else
+# define LinuxLocaleDefines    -DX_LOCALE
+#endif
+
+#ifndef  LinuxAdditionalIncludes
+# define LinuxAdditionalIncludes       /**/
+#endif
+
+#ifndef LinuxGnuSourceDefines
+# ifdef UseInstalled
+#  define LinuxGnuSourceDefines        /**/
+# else
+#  define LinuxGnuSourceDefines        -D_GNU_SOURCE
+# endif
+#endif
+
+#if LinuxCLibMajorVersion >= 6
+# define LinuxSourceDefines    -D_POSIX_C_SOURCE=199309L \
+                               -D_POSIX_SOURCE -D_XOPEN_SOURCE \
+                               -D_BSD_SOURCE -D_SVID_SOURCE \
+                               LinuxAdditionalIncludes LinuxGnuSourceDefines \
+                               LinuxLocaleDefines
+# define XawI18nDefines                -DHAS_WCHAR_H -DHAS_WCTYPE_H -DNO_WIDEC_H
+# define HasPosixThreads       YES
+# define ThreadedX             YES
+# define HasThreadSafeAPI      YES
+# define ThreadsLibraries      -lpthread
+# define SystemMTDefines       -D_REENTRANT
+# ifndef HasLibCrypt
+#  define HasLibCrypt          YES
+# endif
+/* netscape wraps select but not poll as of communicator 4.72 */
+# ifndef HasPoll
+#  define HasPoll              NO
+# endif
+#else
+# define LinuxSourceDefines    -D_POSIX_SOURCE -D_POSIX_C_SOURCE=2 \
+                               -D_BSD_SOURCE -D_SVID_SOURCE \
+                               LinuxGnuSourceDefines LinuxLocaleDefines
+# define XawI18nDefines                -DUSE_XWCHAR_STRING -DUSE_XMBTOWC
+# ifndef HasLibCrypt
+#  define HasLibCrypt          NO
+# endif
+#endif
+
+#ifndef InstallXloadSetGID
+#define InstallXloadSetGID     NO
+#endif
+
+/* <linux/input.h> support mainly for USB support */
+#ifndef HasLinuxInput
+# if OSMajorVersion > 2 || (OSMajorVersion == 2 && OSMinorVersion >= 4)
+#  define HasLinuxInput YES
+# endif
+#endif
+
+/* On x86, determine whether to build with MTRR support */
+#ifndef HasMTRRSupport
+# ifdef i386Architecture
+/* There is no certain way to know if <asm/mtrr.h> is available,
+   but it made it into kernel 2.2, so... */
+#  if OSMajorVersion > 2 || (OSMajorVersion == 2 && OSMinorVersion >= 2)
+#   define HasMTRRSupport      YES
+#  else
+#   define HasMTRRSupport      NO
+#  endif
+# else
+#  define HasMTRRSupport       NO      /* no for non-ix86 */
+# endif
+#endif
+
+#ifndef XF86INT10_BUILD
+# ifdef i386Architecture
+#  define XF86INT10_BUILD      X86VM
+# else
+#  define XF86INT10_BUILD      X86EMU_GENERIC
+# endif
+#endif
+
+/* The DRM module requires kernel services that appeared in late 2.1.x
+   kernels and are known to be present in 2.2.x kernels. */
+#ifndef BuildXF86DRI
+#  if defined(i386Architecture)
+#    if OSMajorVersion > 2 || (OSMajorVersion == 2 && OSMinorVersion >= 2)
+#      define BuildXF86DRI     YES
+#    else
+#      define BuildXF86DRI     NO
+#    endif
+#  elif defined(AlphaArchitecture)
+#    define BuildXF86DRI       YES
+#  elif defined(Arm32Architecture)
+#    define BuildXF86DRI       NO
+#  elif defined(HPArchitecture)
+#    define BuildXF86DRI       NO
+#  elif defined(x86_64Architecture)
+#    define BuildXF86DRI       YES
+#  elif defined(ia64Architecture)
+#    define BuildXF86DRI       YES
+#  elif defined(Mc68020Architecture)
+#    define BuildXF86DRI       NO
+#  elif defined(MipsArchitecture)
+#    define BuildXF86DRI       NO
+#  elif defined(PpcArchitecture)
+#    define BuildXF86DRI       YES
+#  elif defined(s390Architecture)
+#    define BuildXF86DRI       NO
+#  elif defined(SparcArchitecture)
+#    define BuildXF86DRI       YES
+#  else
+#    define BuildXF86DRI       NO
+#  endif
+#endif
+
+/*
+ * Build shared libGL and the DRI modules without -fPIC.  This improves
+ * performance.  Do this only on architectures that can handle missing PIC
+ * symbols in shared libraries.
+ */
+#if BuildXF86DRI
+#  if defined(AlphaArchitecture) || defined(Arm32Architecture) || defined(i386Architecture) || defined(SparcArchitecture)
+#   define BuildLibGlxWithoutPIC       YES
+#  endif
+#endif
+
+/* The DRM module requires kernel services that appeared in late 2.1.x
+   kernels and are known to be present in 2.2.x kernels.  Unfortunately,
+   the kernel API is a moving target and the module may break with new
+   kernel revisions.  So, we'll only build the module for kernels that are
+   known to be supported by the module. */
+#ifndef BuildXF86DRM
+#  if defined(i386Architecture) || defined(x86_64Architecture) || defined(ia64Architecture) || defined(SparcArchitecture) || defined(AlphaArchitecture)
+#    if OSMajorVersion == 2
+       /* Only tested for Linux 2.2.0 through 2.2.12 */
+#      if OSMinorVersion == 2 && OSTeenyVersion <= 12
+#        define BuildXF86DRM   YES
+#      else
+         /* Only tested for Linux 2.3.0 through 2.3.18 */
+#        if OSMinorVersion == 3 && OSTeenyVersion <= 18
+#          define BuildXF86DRM YES
+#        else
+           /* Note: add more conditions when 2.4.x and 2.5.x are released */
+#          define BuildXF86DRM NO
+#        endif
+#      endif
+#    else
+       /* Note: add more conditions when 3.0.x and 3.1.x are released */
+#      define BuildXF86DRM     NO
+#    endif
+#  else
+#    define BuildXF86DRM       NO
+#  endif
+#endif
+
+#ifndef HasAgpGart
+#  if defined(i386Architecture) || defined(x86_64Architecture) || defined(ia64Architecture)
+     /* The AGPGART header file is included in os-support/linux, which
+        allows all drivers that depend on AGP to build properly. */
+#    define HasAgpGart YES
+#  else
+#    define HasAgpGart NO
+#  endif
+#endif
+
+/* Support for Intel's Katmai Native Instructions, also known as the
+ * Streaming SIMD Extensions, was introduced in the 2.4.x kernels.
+ */
+#ifndef HasKatmaiSupport
+#  ifdef i386Architecture
+#    if OSMajorVersion > 2 || (OSMajorVersion == 2 && OSMinorVersion >= 4)
+#      define HasKatmaiSupport         YES
+#    else
+#      define HasKatmaiSupport         NO
+#    endif
+#  else
+#    define HasKatmaiSupport           NO
+#  endif
+#endif
+
+/*
+ * Support for MMX isn't present in the Assembler used in Red Hat 4.2, so
+ * don't enable it for libc5 as a reasonable default.
+ */
+#ifndef HasMMXSupport
+#  ifdef i386Architecture
+#    if (LinuxCLibMajorVersion > 5)
+#      define HasMMXSupport            YES
+#    else
+#      define HasMMXSupport            NO
+#    endif
+#  else
+#    define HasMMXSupport              NO
+#  endif
+#endif
+
+/*
+ * Support for 3DNow isn't present in the Assembler used in Red Hat 4.2, so
+ * don't enable it for libc5 as a reasonable default.
+ *
+ * XXX This is preliminary.
+ */
+#ifndef Has3DNowSupport
+#  ifdef i386Architecture
+#    if (LinuxCLibMajorVersion > 5)
+#      define Has3DNowSupport          YES
+#    else
+#      define Has3DNowSupport          NO
+#    endif
+#  else
+#    define Has3DNowSupport            NO
+#  endif
+#endif
+
+/*
+ * libGLU doesn't build correctly on a libc5 system.
+ */
+#if !defined(BuildGLULibrary) && (LinuxCLibMajorVersion < 6)
+# define BuildGLULibrary               NO
+#endif
+
+/*
+ * The Rush extension support.
+ */
+#ifndef BuildXF86RushExt
+# define BuildXF86RushExt      YES
+#endif
+
+#ifndef LinuxFBDevSupport
+# define LinuxFBDevSupport     YES
+#endif
+
+/* For compatibility */
+#define SourceDefines          LinuxSourceDefines
+
+#define BuildLibPathVar                LD_LIBRARY_PATH
+#define GccUsesGas             YES
+#define UseGas                 YES
+#define GnuCpp                 YES
+#if UseElfFormat
+# define HasDlopen             YES
+#endif
+#ifndef HasShadowPasswd
+# if UseElfFormat
+#  define HasShadowPasswd      YES
+# else
+#  define HasShadowPasswd      NO
+# endif
+#endif
+#define HasPutenv              YES
+#define HasShm                 YES
+#define HasSockets             YES
+#if UseElfFormat || defined(AlphaArchitecture)
+#define HasSnprintf            YES
+#define HasMkstemp             YES
+#endif
+#if OSMajorVersion >= 2
+#define HasUsableFileMmap      YES
+#endif
+#ifndef HasNCurses
+#define HasNCurses             YES
+#endif
+
+#ifndef HasGroff
+#define HasGroff               YES
+#endif
+
+#define AvoidNullMakeCommand   YES
+#ifndef DebuggableLibraries
+#define DebuggableLibraries    NO
+#endif
+#define CompressAllFonts       YES
+#define Malloc0ReturnsNull     YES
+#define NeedConstPrototypes    YES
+#define NeedFunctionPrototypes YES
+#define NeedNestedPrototypes   YES
+#define NeedVarargsPrototypes  YES
+#ifndef NeedWidePrototypes
+#define NeedWidePrototypes     NO
+#endif
+#define SetTtyGroup            YES
+
+#ifndef UseStaticTermcapLib
+#define UseStaticTermcapLib    NO
+#endif
+
+#ifndef HasCookieMaker
+#define HasCookieMaker         YES
+#define MkCookieCmd            mcookie
+#endif
+
+#ifndef BourneShell
+/*
+ * This will cause builds/installs to terminate on errors, as on other
+ * platforms.
+ */
+#define BourneShell            /bin/sh -e
+#endif
+
+#define MkdirHierCmd           mkdir -p
+
+#if LinuxElfDefault
+# if UseElfFormat
+#  ifdef MipsArchitecture
+#   ifndef AsCmd
+#     define AsCmd             gcc -c -x assembler-with-cpp
+#   endif
+#   ifndef DoLoadableServer
+#     define DoLoadableServer  NO
+#   endif
+#  endif /* MipsArchitecure */
+#  ifndef CcCmd
+#   define CcCmd               gcc
+#  endif
+#  ifndef AsCmd
+#   define AsCmd               as
+#  endif
+#  ifndef LdCmd
+#   define LdCmd               ld
+#  endif
+#  define AsmDefines           -D__ELF__
+#  define CplusplusCmd         c++
+#  ifndef LinuxUsesNcurses
+#   if LinuxCLibMajorVersion >= 6 || (LinuxDistribution == LinuxSuSE)
+#    define LinuxUsesNcurses   YES
+#   else
+#    define LinuxUsesNcurses   NO
+#   endif
+#  endif
+#  ifndef TermcapLibrary
+#   if UseStaticTermcapLib
+#    if LinuxUsesNcurses
+#     define TermcapLibrary    StaticLibrary(/usr/lib,ncurses)
+#    else
+#     define TermcapLibrary    StaticLibrary(/usr/lib/termcap,termcap)
+#    endif
+#   else
+#    if LinuxUsesNcurses
+#     define TermcapLibrary    -lncurses
+#    else
+#     define TermcapLibrary    -ltermcap
+#    endif
+#   endif
+#  endif
+# else
+#  ifdef AlphaArchitecture
+#   define CcCmd               gcc -b alpha-linuxecoff
+#   define CplusplusCmd                g++ -b alpha-linuxecoff
+#   define AsCmd               /usr/alpha-linuxecoff/bin/as
+#   define LdCmd               /usr/alpha-linuxecoff/bin/ld -m alpha
+#   define AsmDefines          -DUSE_GAS -U__ELF__
+#  endif /* AlphaArchitecture */
+#  ifdef HPArchitecture
+#   define CcCmd               gcc
+#   define CplusplusCmd                g++
+#   define AsCmd               as
+#   define LdCmd               ld
+#   define AsmDefines          -DUSE_GAS -U__ELF__
+#  endif /* HPArchitecture */
+#  ifdef x86_64Architecture
+#   define CcCmd               gcc
+#   define CplusplusCmd                g++
+#   define AsCmd               as
+#   define LdCmd               ld
+#   define AsmDefines          -DUSE_GAS -U__ELF__
+#  endif /* x86_64Architecture */
+#  ifdef ia64Architecture
+#   define CcCmd               gcc
+#   define CplusplusCmd                g++
+#   define AsCmd               as
+#   define LdCmd               ld
+#   define AsmDefines          -DUSE_GAS -U__ELF__
+#  endif /* ia64Architecture */
+#  ifdef i386Architecture
+#   define CcCmd               gcc -b i486-linuxaout
+#   define CplusplusCmd                g++ -b i486-linuxaout
+#   define AsCmd               /usr/i486-linuxaout/bin/as
+#   define LdCmd               /usr/i486-linuxaout/bin/ld -m i386linux
+#   define AsmDefines          -DUSE_GAS -U__ELF__
+#  endif /* i386Architecture */
+#  ifdef Mc68020Architecture
+#   define CcCmd               gcc -b m68k-linuxaout
+#   define CplusplusCmd                g++ -b m68k-linuxaout
+#   define AsCmd               /usr/m68k-linuxaout/bin/as
+#   define LdCmd               /usr/m68k-linuxaout/bin/ld -m m68klinux
+#   define AsmDefines          -DUSE_GAS -U__ELF__
+#  endif /* Mc68020Architecture */
+# endif
+#else
+# if UseElfFormat
+#  ifdef AlphaArchitecture
+#   define CcCmd               gcc -b alpha-linux
+#   define AsCmd               /usr/alpha-linux/bin/as
+#   define LdCmd               ld -m elf64alpha
+#   define AsmDefines          -D__ELF__
+#   define CplusplusCmd                c++ -b alpha-linux
+#  endif /* AlphaArchitecture */
+#  ifdef x86_64Architecture
+#   define CcCmd               gcc
+#   define CplusplusCmd                g++
+#   define AsCmd               as
+#   define LdCmd               ld
+#   define AsmDefines          -D__ELF__
+#  endif /* x86_64Architecture */
+#  ifdef ia64Architecture
+#   define CcCmd               gcc
+#   define CplusplusCmd                g++
+#   define AsCmd               as
+#   define LdCmd               ld
+#   define AsmDefines          -D__ELF__
+#  endif /* ia64Architecture */
+#  ifdef HPArchitecture
+#   define CcCmd               gcc
+#   define CplusplusCmd                g++
+#   define AsCmd               as
+#   define LdCmd               ld
+#   define AsmDefines          -D__ELF__
+#   define SharedLibXau                YES
+#  endif /* HPArchitecture */
+#  ifdef i386Architecture
+#   define CcCmd               gcc -b i486-linux
+#   define AsCmd               /usr/i486-linux/bin/as
+#   define LdCmd               ld -m elf_i386
+#   define AsmDefines          -D__ELF__
+#   define CplusplusCmd                c++ -b i486-linux
+#  endif /* i386Architecture */
+#  ifdef Mc68020Architecture
+#   define CcCmd               gcc -b m68k-linux
+#   define AsCmd               /usr/m68k-linux/bin/as
+#   define LdCmd               ld -m m68kelf
+#   define AsmDefines          -D__ELF__
+#   define CplusplusCmd                c++ -b m68k-linux
+#  endif /* Mc68020Architecture */
+# else
+#  define CcCmd                        gcc
+#  define AsCmd                        as
+#  define LdCmd                        ld
+#  define AsmDefines           -DUSE_GAS
+# endif
+#endif
+#if UseElfFormat
+# ifndef DoLoadableServer
+# ifdef HPArchitecture
+#  define DoLoadableServer     NO
+# else
+#  define DoLoadableServer     YES
+# endif
+# endif
+#endif
+#ifndef CppCmd
+# define CppCmd                        /lib/cpp
+#endif
+/* Some Linux distributions have yacc, some don't. All have bison. */
+#define YaccCmd                        bison -y
+#define LexCmd                 flex -l
+#define HasFlex                        YES
+#define LexLib                 -lfl
+#define PreProcessCmd          CcCmd -E
+#define PostIncDir             DefaultGccIncludeDir
+#define LdCombineFlags         -r
+#ifndef LdPostLib
+# define LdPostLib             /* Never needed */
+#endif
+#define HasWChar32             YES
+#define StandardCppOptions     -traditional
+#define StandardCppDefines     StandardDefines
+
+#define HasVarRun              YES
+#define VarDbDirectory         $(VARDIR)/lib
+
+#ifndef XF86OSCardDrivers
+# define XF86OSCardDrivers     v4l
+#endif
+
+#if UseElfFormat
+# define HasPlugin                     YES
+# define VendorHasX11R6_3libXext       YES     /* XC or XFree86 >= 3.3.1 */
+#endif
+
+#ifdef i386Architecture
+# ifndef OptimizedCDebugFlags
+#  define OptimizedCDebugFlags -O
+# endif
+# define LinuxMachineDefines   -D__i386__
+# define ServerOSDefines       XFree86ServerOSDefines -DDDXTIME -DPART_NET
+# define ServerExtraDefines    -DGCCUSESGAS XFree86ServerDefines
+#endif /* i386Architecture */
+
+#ifdef s390Architecture
+# define DefaultCCOptions      -fsigned-char
+# ifndef OptimizedCDebugFlags
+#  define OptimizedCDebugFlags -O2
+# endif
+# define LinuxMachineDefines   -D__s390__
+# define ServerOSDefines       XFree86ServerOSDefines -DDDXTIME -DPART_NET
+# define ServerExtraDefines    -DGCCUSESGAS XFree86ServerDefines
+#endif /* s390Architecture */
+
+#ifdef AlphaArchitecture
+# ifndef OptimizedCDebugFlags
+#  define OptimizedCDebugFlags -O
+# endif
+# define LinuxMachineDefines   -D__alpha__
+# define ServerOSDefines       XFree86ServerOSDefines -DDDXTIME -DPART_NET
+# define ServerExtraDefines    -DGCCUSESGAS XFree86ServerDefines -D_XSERVER64 -DJENSEN_SUPPORT
+# ifdef UseCompaqMathLibrary
+#  define MathLibrary          -lcpml -lm
+# endif
+#endif /* AlphaArchitecture */
+
+#ifdef Arm32Architecture
+# define DefaultCCOptions      -fsigned-char
+# ifndef OptimizedCDebugFlags
+#  define OptimizedCDebugFlags -O3
+# endif
+# define LinuxMachineDefines   -D__arm__ -D__arm32__ -U__arm -Uarm
+# define ServerOSDefines       XFree86ServerOSDefines -DDDXTIME -DPART_NET
+# define ServerExtraDefines    -DGCCUSESGAS XFree86ServerDefines
+#endif /* Arm32Achitecture */
+
+#ifdef x86_64Architecture
+# ifndef OptimizedCDebugFlags
+#  define OptimizedCDebugFlags -O2
+# endif
+# define LinuxMachineDefines   -D__x86_64__
+# define ServerOSDefines       XFree86ServerOSDefines -DDDXTIME -DPART_NET
+# define ServerExtraDefines    -DGCCUSESGAS XFree86ServerDefines -D_XSERVER64
+#endif /* x86_64Architecture */
+
+#ifdef ia64Architecture
+# ifndef OptimizedCDebugFlags
+#  define OptimizedCDebugFlags -O2
+# endif
+# define LinuxMachineDefines   -D__ia64__
+# define ServerOSDefines       XFree86ServerOSDefines -DDDXTIME -DPART_NET
+# define ServerExtraDefines    -DGCCUSESGAS XFree86ServerDefines -D_XSERVER64
+#endif /* ia64Architecture */
+
+#ifdef Mc68020Architecture
+# ifndef OptimizedCDebugFlags
+#  define OptimizedCDebugFlags -O2
+# endif
+# define LinuxMachineDefines   -D__mc68000__
+# define ServerOSDefines       XFree86ServerOSDefines -DDDXTIME -DPART_NET
+# define ServerExtraDefines    -DGCCUSESGAS XFree86ServerDefines
+#endif /* Mc68020Architecture */
+
+#ifdef PpcArchitecture
+# define DefaultCCOptions      -fsigned-char
+# ifndef OptimizedCDebugFlags
+#  define OptimizedCDebugFlags -O
+# endif
+# define LinuxMachineDefines   -D__powerpc__
+# define ServerOSDefines       XFree86ServerOSDefines -DDDXTIME -DPART_NET
+# define ServerExtraDefines    -DGCCUSESGAS XFree86ServerDefines
+#endif /* PpcArchitecture */
+
+#ifdef SparcArchitecture
+# ifndef OptimizedCDebugFlags
+#  define OptimizedCDebugFlags -O2
+# endif
+# define LinuxMachineDefines   -D__sparc__
+# define ServerOSDefines       XFree86ServerOSDefines -DDDXTIME -DPART_NET
+# define ServerExtraDefines    -DHAVE_DOMAINS -DGCCUSESGAS XFree86ServerDefines
+# define AsVISOption           -Av9a
+# ifdef Sparc64Architecture
+#  define AsOutputArchSize     64
+# else
+#  define AsOutputArchSize     32
+# endif
+#endif
+
+#ifdef MipsArchitecture
+# ifndef OptimizedCDebugFlags
+#  define OptimizedCDebugFlags -O2
+# endif
+# define LinuxMachineDefines   -D__mips__
+# define ServerOSDefines       XFree86ServerOSDefines -DDDXTIME -DPART_NET
+# define ServerExtraDefines    -DGCCUSESGAS XFree86ServerDefines
+#endif
+
+#ifdef HPArchitecture
+# define OptimizedCDebugFlags  -O2
+# define LinuxMachineDefines   -D__hppa__
+# define ServerOSDefines       XFree86ServerOSDefines -DDDXTIME -DPART_NET
+# define ServerExtraDefines    -DGCCUSESGAS XFree86ServerDefines
+#endif
+
+#ifdef SuperHArchitecture
+# ifndef SuperHArchOptFlags
+#  ifdef SuperH4Architecture
+#   define SuperHArchOptFlags   -m4
+#  elif defined(SuperH4NOFPUArchitecture)
+#   define SuperHArchOptFlags   -m4-nofpu
+#  else
+#   define SuperHArchOptFlags   -m3
+#  endif
+# endif 
+# ifndef SuperHebArchitecture
+#  ifdef SuperHebArchitecture
+#   define SuperHEndianFlags    -mb
+#  else
+#   define SuperHEndianFlags    -ml
+#  endif
+# endif
+# ifndef OptimizedCDebugFlags
+#  define OptimizedCDebugFlags  -O2 SuperHArchOptFlags SuperHEndianFlags
+# endif
+# define LinuxMachineDefines    -D__sh__
+# define ServerOSDefines        XFree86ServerOSDefines -DDDXTIME -DPART_NET
+# define ServerExtraDefines     -DGCCUSESGAS XFree86ServerDefines
+#endif
+
+#ifndef StandardDefines
+# define StandardDefines       -Dlinux LinuxMachineDefines LinuxSourceDefines
+#endif
+
+#if UseElfFormat
+# define DlLibrary             -rdynamic -ldl
+#else
+# define DlLibrary             /**/
+#endif
+
+#define ServerExtraSysLibs     /**/
+
+#ifndef PamLibraries
+#define PamLibraries           -lpam DlLibrary
+#endif
+
+#ifndef PamMiscLibraries
+#define PamMiscLibraries       -lpam_misc
+#endif
+
+#if HasDECnet
+# define ConnectionFlags       -DUNIXCONN -DTCPCONN -DDNETCONN
+# define ExtraLibraries                -ldnet
+#else
+# define ConnectionFlags       -DUNIXCONN -DTCPCONN
+#endif
+
+/* Some of these man page defaults are overriden in the above OS sections */
+#ifndef ManSuffix
+# define ManSuffix     1x
+#endif
+#ifndef ManDir
+# define ManDir                $(MANSOURCEPATH)1
+#endif
+#ifndef LibManSuffix
+# define LibManSuffix  3x
+#endif
+#ifndef LibmanDir
+# define LibmanDir     $(MANSOURCEPATH)3
+#endif
+#ifndef FileManSuffix
+# define FileManSuffix 5x
+#endif
+#ifndef FileManDir
+# define FileManDir    $(MANSOURCEPATH)5
+#endif
+
+#ifndef StaticLibrary
+# define StaticLibrary(libpath,libname) -Wl,-Bstatic Concat(-L,libpath) Concat(-l,libname) -Wl,-Bdynamic
+#endif
+
+#ifndef LinkGLToUsrLib
+# define LinkGLToUsrLib                YES
+#endif
+# ifndef LinkGLToUsrInclude
+# define LinkGLToUsrInclude    YES
+#endif
+
+
+#define HasGnuMake             YES
+
+#define MakeNamedTargetSubdir(dir,flags,subname)\
+       $(MAKE) -C dir $(MFLAGS) $(PARALLELMFLAGS) flags subname
+
+#define ArchitectureDefines    -DLINUX_ARCHITECTURE
+
+#define TtClientLibs $(TTLIB) $(XTOOLLIB) $(XLIB)
+#define TtClientDepLibs $(DEPTTLIB) $(DEPXTOOLLIB) $(DEPXLIB)
+
+#ifdef s390Architecture
+# define HasXServer    NO
+#endif
+
+#include <lnxLib.rules>
+#ifdef KDriveXServer
+# include <kdrive.cf>
+#else
+# include <xfree86.cf>
+#endif
+
+#ifndef XFree86ServerOSDefines
+# define XFree86ServerOSDefines
+#endif
diff --git a/Xserver/config/cf/lnxLib.rules b/Xserver/config/cf/lnxLib.rules
new file mode 100644 (file)
index 0000000..ade66d7
--- /dev/null
@@ -0,0 +1,565 @@
+XCOMM $XConsortium: lnxLib.rules /main/13 1996/09/28 16:11:01 rws $
+XCOMM $XFree86: xc/config/cf/lnxLib.rules,v 3.28.2.3 1997/06/22 10:32:20 dawes Exp $
+
+/*
+ * Linux shared library rules (DLL & ELF versions)
+ */
+#ifndef HasSharedLibraries
+#define HasSharedLibraries YES
+#endif
+#ifndef ForceNormalLib
+#define ForceNormalLib NO
+#endif
+
+#define SharedOldX NO
+
+#if UseElfFormat
+
+#if (LinuxCLibMajorVersion >= 5 && LinuxCLibMinorVersion >= 4) || LinuxCLibMajorVersion >= 6
+#undef SpecialMalloc
+#define SpecialMalloc NO
+#undef UseInternalMalloc
+#define UseInternalMalloc NO
+#endif
+
+/*
+ *     #define BaseShLibReqs   -lc
+ *
+ * I don't want to use this since the normal ELF executables should
+ * be linked with libc.so. If it is not, i.e., static, the variables in
+ * libc.so which is loaded in because of the other shared libraries
+ * may have different values than the ones in the static ELF
+ * executables. That happens if the binaries are linked with libg.a
+ * or libc_p.a.
+ *
+ * If an ELF executable linked with libg.a or libc_p.a loads a shared
+ * object which needs libc.so via dlopen (), I think it should fail.
+ * It is a very bad idea. The moral story is DON'T USE dlopen () IN
+ * ELF EXECUTABLES LINKED WITH libg.a OR libc_p.a. H.J.
+ *
+ */
+#define BaseShLibReqs
+
+#ifndef SharedDataSeparation
+#define SharedDataSeparation NO
+#endif
+#ifndef SharedCodeDef
+#define SharedCodeDef /**/
+#endif
+#ifndef SharedLibraryDef
+#define SharedLibraryDef /**/
+#endif
+#ifndef ShLibIncludeFile
+#define ShLibIncludeFile <lnxLib.tmpl>
+#endif
+#ifndef SharedLibraryLoadFlags
+#define SharedLibraryLoadFlags -shared
+#endif
+#ifndef PositionIndependentCFlags
+#define PositionIndependentCFlags -fPIC
+#endif
+#ifndef PositionIndependentCplusplusFlags
+#define PositionIndependentCplusplusFlags -fPIC
+#endif
+#ifndef ExtraLoadFlags
+#if LinuxBinUtilsMajorVersion >= 26
+#ifdef UseInstalled
+#if LinuxBinUtilsMajorVersion < 27
+#define ExtraLoadFlags -Wl,-rpath-link,$(USRLIBDIRPATH)
+#endif
+#else
+#define ExtraLoadFlags -Wl,-rpath-link,$(BUILDLIBDIR)
+#endif
+#else
+#define ExtraLoadFlags -Wl,-rpath,$(USRLIBDIRPATH)
+#endif
+#endif
+
+/*
+ * InstallSharedLibrary - generate rules to install the shared library.
+ * NOTE: file must be executable, hence "INSTBINFLAGS"
+ */
+#ifndef InstallSharedLibrary
+#define        InstallSharedLibrary(libname,rev,dest)                          @@\
+install:: Concat(lib,libname.so.rev)                                   @@\
+       MakeDir($(DESTDIR)dest)                                         @@\
+       $(INSTALL) $(INSTALLFLAGS) $(INSTBINFLAGS) Concat(lib,libname.so.rev) $(DESTDIR)dest @@\
+       @T=`echo Concat($(DESTDIR)dest/lib,libname.so.rev) | sed 's/\.[^\.]*$$//'`;\
+         set -x; $(RM) $$T && $(LN) Concat(lib,libname.so.rev) $$T     @@\
+       $(RM) Concat($(DESTDIR)dest/lib,libname.so)                     @@\
+       $(LN) Concat(lib,libname.so.rev) Concat($(DESTDIR)dest/lib,libname.so)
+#endif /* InstallSharedLibrary */
+
+/*
+ * InstallSharedLibraryData - generate rules to install the shared library data
+ */
+#ifndef InstallSharedLibraryData
+#define        InstallSharedLibraryData(libname,rev,dest)
+#endif /* InstallSharedLibraryData */
+
+
+/*
+ * SharedLibraryTarget - generate rules to create a shared library;
+ * build it into a different name so that we do not hose people by having
+ * the library gone for long periods.
+ */
+#ifndef SharedLibraryTarget
+#ifdef UseInstalled
+#define LinkBuildSonameLibrary(lib) true
+#else
+#define LinkBuildSonameLibrary(lib) (RemoveFile($(BUILDLIBDIR)/lib); \
+       cd $(BUILDLIBDIR); $(LN) $(BUILDINCTOP)/$(CURRENT_DIR)/lib .)
+#endif
+
+#define SharedLibraryTarget(libname,rev,solist,down,up)                        @@\
+AllTarget(Concat(lib,libname.so.rev))                                  @@\
+                                                                       @@\
+Concat(lib,libname.so.rev):  solist $(EXTRALIBRARYDEPS)                        @@\
+       $(RM) $@~                                                       @@\
+       @SONAME=`echo $@ | sed 's/\.[^\.]*$$//'`; set -x; \             @@\
+               (cd down; $(CC) -o up/$@~ $(SHLIBLDFLAGS) -Wl,-soname,$$SONAME solist $(REQUIREDLIBS) BaseShLibReqs); \ @@\
+               $(RM) $$SONAME; $(LN) $@ $$SONAME; \                    @@\
+               LinkBuildSonameLibrary($$SONAME)                        @@\
+       $(RM) $@                                                        @@\
+       $(MV) $@~ $@                                                    @@\
+       $(RM) Concat(lib,libname.so)                                    @@\
+       $(LN) $@ Concat(lib,libname.so)                                 @@\
+       LinkBuildLibrary($@)                                            @@\
+       LinkBuildLibrary(Concat(lib,libname.so))                        @@\
+                                                                       @@\
+clean::                                                                        @@\
+       @MAJREV=`expr rev : '\(.*\)\.'`; \                              @@\
+       set -x; $(RM) Concat(lib,libname.so.$$MAJREV)                   @@\
+       $(RM) Concat(lib,libname.so.rev) Concat(lib,libname.so)
+
+#endif /* SharedLibraryTarget */
+
+#ifndef SharedDepModuleTarget
+#define SharedDepModuleTarget(name,deps,solist)                                @@\
+AllTarget(name)                                                                @@\
+                                                                       @@\
+name: deps                                                             @@\
+       $(RM) $@~                                                       @@\
+       $(CC) -o $@~ $(SHLIBLDFLAGS) solist $(REQUIREDLIBS) BaseShLibReqs @@\
+       $(RM) $@                                                        @@\
+       $(MV) $@~ $@                                                    @@\
+                                                                       @@\
+clean::                                                                        @@\
+       $(RM) name
+
+#endif /* SharedDepModuleTarget */
+
+/*
+ * SharedLibraryDataTarget - generate rules to create shlib data file;
+ */
+#ifndef SharedLibraryDataTarget
+#define SharedLibraryDataTarget(libname,rev,salist)
+#endif /* SharedLibraryTarget */
+
+#else /* UseElfFormat */
+
+#ifndef SharedDataSeparation
+#define SharedDataSeparation NO
+#endif
+#ifndef SharedCodeDef
+#define SharedCodeDef /**/
+#endif
+#ifndef SharedLibraryDef
+#define SharedLibraryDef /**/
+#endif
+#ifndef ShLibIncludeFile
+#define ShLibIncludeFile <lnxLib.tmpl>
+#endif
+#ifndef SharedLibraryLoadFlags
+#define SharedLibraryLoadFlags /**/
+#endif
+#ifndef PositionIndependentCFlags
+#define PositionIndependentCFlags -B/usr/bin/jump
+#endif
+
+/*
+ * These definitions are now extended to work with the X sources and
+ * external sources wishing to build shared libs.
+ *
+ * A library can create it's own shlibs (.so) or can be incorporated into
+ * another "host" lib. All libraries generate stub (.sa) files.
+ * A "host" lib does all the work to generate the stubs for itself and its
+ * "guests", invoking the "guest" Makefiles to create the objects for
+ * inclusion into the "host" shlib. A "guest" lib will ask the "host" to
+ * create the stubfiles, then copy its own into its directory.
+ * Most external libs are "host" libs; the concept of "guest" is a holdover
+ * from older libs during the days of scarce shared library address space.
+ *
+ * To create a simple "host" shared lib, Xfoo, define:
+ *
+ *  JUMP_ROOT_Xfoo = <source directory>
+ *  JUMP_IS_HOST_Xfoo = YES
+ *  JUMP_STUBLIBS_Xfoo = libXfoo.sa
+ *  JUMP_DIR_Xfoo = $(JUMP_ROOT_Xfoo)/shared           <work directory>
+ *  JUMP_DEFS_Xfoo = -DFOO                             <defs for jump files>
+ *  JUMP_VARS_Xfoo = $(JUMP_ROOT_Xfoo)/jump_vars       <see DLL docs>
+ *  JUMP_FUNCS_Xfoo = $(JUMP_ROOT_Xfoo)/jump_funcs     <see DLL docs>
+ *  JUMP_IGNORE_Xfoo = $(JUMP_ROOT_Xfoo)/jump_ignore   <see DLL docs>
+ *  JUMP_EXPORT_Xfoo = $(JUMP_DIR_Xfoo)/jump.vars      <exported symbols>
+ *  JUMP_IMPORT_Xfoo = $(JUMP_EXPORT_Xbar)             <imported symbols>
+ *  JUMP_ADDRESS_Xfoo = 0xXXXXXXXX                     <fill in with address>
+ *  JUMP_JUMPTABLESIZE_Xfoo = 0x4000                   <adjust if necessary>
+ *  JUMP_GOTSIZE_Xfoo = 4096                           <adjust if necessary>
+ *  JUMP_STUBNAMES_Xfoo = libXfoo                      <and others>
+ *  JUMP_STUBS_IMPORT_Xfoo = /usr/lib/libc.sa          <and others>
+ *  JUMP_LDLIBS_Xfoo = `$(CC) --print-libgcc-file-name` -lc <and others>
+ *
+ * To create a complex "host", you need to add
+ *  JUMP_SIBARS_Xt = jump/libXbar.a~                   <and others>
+ * These are the archives of the shared objects of the "guest" libs. They
+ * need to be added to the JUMP_LDLIBS_Xfoo lines.
+ *
+ * For further clarification, study the definitions of libXaw, a simple "host"
+ * lib, libXt, a complex "host" lib, and libXmu, one of libXts "guests".
+ *
+ * As a hint of how to start (with the DLL docs), touch jump_vars, jump_funcs
+ * and jump_ignore, then compile. Then massage the jump.vars and jump.funcs
+ * files in the shared subdirectory into jump_xxx files.
+ */
+
+#ifndef UseInstalled
+XCOMM These are only needed to build the server
+
+#if LinuxElfDefault
+LIBC_SA = /usr/i486-linuxaout/lib/libc.sa
+LIBM_SA = /usr/i486-linuxaout/lib/libm.sa
+#else
+LIBC_SA = /usr/lib/libc.sa
+LIBM_SA = /usr/lib/libm.sa
+#endif
+
+JUMP_LDLIBS_libc = `$(CC) --print-libgcc-file-name` -lc
+
+XCOMM libX11.so (X11, SM, ICE)
+JUMP_ROOT_X11 = $(XLIBSRC)
+JUMP_IS_HOST_X11 = YES
+JUMP_STUBLIBS_X11 = libX11.sa libSM.sa libICE.sa
+JUMP_SIBDIRS_X11 = $(JUMP_ROOT_SM) $(JUMP_ROOT_ICE)
+JUMP_DIR_X11 = $(JUMP_ROOT_X11)/shared
+JUMP_DEFS_X11 = $(XDMAUTHDEFS) $(XKB_DEFINES)
+JUMP_VARS_X11 = $(JUMP_ROOT_X11)/jump_vars
+JUMP_FUNCS_X11 = $(JUMP_ROOT_X11)/jump_funcs
+JUMP_IGNORE_X11 = $(JUMP_ROOT_X11)/jump_ignore
+JUMP_EXPORT_X11 = $(JUMP_DIR_X11)/jump.vars
+JUMP_ADDRESS_X11 = 0x60200000
+JUMP_JUMPTABLESIZE_X11 = 0x4000
+JUMP_GOTSIZE_X11 = 4096
+JUMP_STUBNAMES_X11 = libX11 libSM libICE
+JUMP_STUBS_IMPORT_X11 = $(LIBC_SA)
+JUMP_SIBARS_X11 = jump/libSM.a~ jump/libICE.a~
+JUMP_LDLIBS_X11 = $(JUMP_SIBARS_X11) $(JUMP_LDLIBS_libc)
+
+XCOMM libSM (part of libX11.so)
+JUMP_ROOT_SM = $(SMSRC)
+JUMP_IS_HOST_SM = NO
+JUMP_HOST_SM = $(JUMP_ROOT_X11)
+JUMP_DIR_SM = $(JUMP_DIR_X11)
+
+XCOMM libICE (part of libX11.so)
+JUMP_ROOT_ICE = $(ICESRC)
+JUMP_IS_HOST_ICE = NO
+JUMP_HOST_ICE = $(JUMP_ROOT_X11)
+JUMP_DIR_ICE = $(JUMP_DIR_X11)
+
+XCOMM libXt.so (Xt, Xmu, Xext, Xi, Xtst, Xp)
+JUMP_ROOT_Xt = $(TOOLKITSRC)
+JUMP_IS_HOST_Xt = YES
+JUMP_STUBLIBS_Xt = libXt.sa libXmu.sa libXext.sa libXi.sa libXtst.sa libXp.sa
+JUMP_SUBDIRS_Xt = $(JUMP_ROOT_X11)
+JUMP_SIBDIRS_Xt = $(JUMP_ROOT_Xmu) $(JUMP_ROOT_Xext) \
+       $(JUMP_ROOT_Xi) $(JUMP_ROOT_Xtst) $(JUMP_ROOT_Xp)
+JUMP_DIR_Xt = $(JUMP_ROOT_Xt)/shared
+JUMP_VARS_Xt = $(JUMP_ROOT_Xt)/jump_vars
+JUMP_FUNCS_Xt = $(JUMP_ROOT_Xt)/jump_funcs
+JUMP_IGNORE_Xt = $(JUMP_ROOT_Xt)/jump_ignore
+JUMP_EXPORT_Xt = $(JUMP_DIR_Xt)/jump.vars
+JUMP_IMPORT_Xt = $(JUMP_EXPORT_X11)
+JUMP_ADDRESS_Xt = 0x602a0000
+JUMP_JUMPTABLESIZE_Xt = 0x4000
+JUMP_GOTSIZE_Xt = 4096
+JUMP_STUBNAMES_Xt = libXt libXmu libXext libXi libXtst libXp
+JUMP_STUBS_IMPORT_Xt = $(JUMP_STUBS_IMPORT_X11)
+JUMP_SIBARS_Xt = jump/libXmu.a~ jump/libXext.a~ jump/libXi.a~ jump/libXtst.a~ jump/libXp.a~
+JUMP_LDLIBS_Xt = $(JUMP_SIBARS_Xt) $(JUMP_ROOT_ICE)/libICE.sa \
+       $(JUMP_ROOT_SM)/libSM.sa $(JUMP_ROOT_X11)/libX11.sa $(JUMP_LDLIBS_libc)
+
+XCOMM libXmu (part of libXt.so)
+JUMP_ROOT_Xmu = $(XMUSRC)
+JUMP_IS_HOST_Xmu = NO
+JUMP_HOST_Xmu = $(JUMP_ROOT_Xt)
+JUMP_DIR_Xmu = $(JUMP_DIR_Xt)
+
+XCOMM libXext (part of libXt.so)
+JUMP_ROOT_Xext = $(XEXTLIBSRC)
+JUMP_IS_HOST_Xext = NO
+JUMP_HOST_Xext = $(JUMP_ROOT_Xt)
+JUMP_DIR_Xext = $(JUMP_DIR_Xt)
+
+XCOMM libXi (part of libXt.so)
+JUMP_ROOT_Xi = $(XILIBSRC)
+JUMP_IS_HOST_Xi = NO
+JUMP_HOST_Xi = $(JUMP_ROOT_Xt)
+JUMP_DIR_Xi = $(JUMP_DIR_Xt)
+
+XCOMM libXtst (part of libXt.so)
+JUMP_ROOT_Xtst = $(XTESTLIBSRC)
+JUMP_IS_HOST_Xtst = NO
+JUMP_HOST_Xtst = $(JUMP_ROOT_Xt)
+JUMP_DIR_Xtst = $(JUMP_DIR_Xt)
+
+XCOMM libXp (part of libXt.so)
+JUMP_ROOT_Xp = $(XPLIBSRC)
+JUMP_IS_HOST_Xp = NO
+JUMP_HOST_Xp = $(JUMP_ROOT_Xt)
+JUMP_DIR_Xp = $(JUMP_DIR_Xt)
+
+XCOMM libXaw.so (Xaw)
+JUMP_ROOT_Xaw = $(AWIDGETSRC)
+JUMP_IS_HOST_Xaw = YES
+JUMP_STUBLIBS_Xaw = libXaw.sa
+JUMP_SUBDIRS_Xaw = $(JUMP_ROOT_Xt)
+JUMP_DIR_Xaw = $(JUMP_ROOT_Xaw)/shared
+JUMP_VARS_Xaw = $(JUMP_ROOT_Xaw)/jump_vars
+JUMP_FUNCS_Xaw = $(JUMP_ROOT_Xaw)/jump_funcs
+JUMP_IGNORE_Xaw = $(JUMP_ROOT_Xaw)/jump_ignore
+JUMP_EXPORT_Xaw = $(JUMP_DIR_Xaw)/jump.vars
+JUMP_IMPORT_Xaw = $(JUMP_EXPORT_Xt) $(JUMP_EXPORT_X11)
+JUMP_ADDRESS_Xaw = 0x60300000
+JUMP_JUMPTABLESIZE_Xaw = 0x4000
+JUMP_GOTSIZE_Xaw = 4096
+JUMP_STUBNAMES_Xaw = libXaw
+JUMP_STUBS_IMPORT_Xaw = $(JUMP_STUBS_IMPORT_X11)
+JUMP_LDLIBS_Xaw = $(JUMP_ROOT_Xt)/libXt.sa $(JUMP_ROOT_Xt)/libXmu.sa \
+       $(JUMP_ROOT_Xt)/libXext.sa $(JUMP_ROOT_X11)/libX11.sa \
+       $(JUMP_LDLIBS_libc)
+
+# libPEX.so (PEX5)
+JUMP_ROOT_PEX5 = $(PEXLIBSRC)
+JUMP_IS_HOST_PEX5 = YES
+JUMP_STUBLIBS_PEX5 = libPEX5.sa
+JUMP_SUBDIRS_PEX5 = $(JUMP_ROOT_X11)
+JUMP_DIR_PEX5 = $(JUMP_ROOT_PEX5)/shared
+JUMP_VARS_PEX5 = $(JUMP_ROOT_PEX5)/jump_vars
+JUMP_FUNCS_PEX5 = $(JUMP_ROOT_PEX5)/jump_funcs
+JUMP_IGNORE_PEX5 = $(JUMP_ROOT_PEX5)/jump_ignore
+JUMP_EXPORT_PEX5 = $(JUMP_DIR_PEX5)/jump.vars
+JUMP_IMPORT_PEX5 = $(JUMP_EXPORT_X11)
+JUMP_ADDRESS_PEX5 = 0x60b00000
+JUMP_JUMPTABLESIZE_PEX5 = 0x4000
+JUMP_GOTSIZE_PEX5 = 4096
+JUMP_STUBNAMES_PEX5 = libPEX5
+JUMP_STUBS_IMPORT_PEX5 = $(JUMP_STUBS_IMPORT_X11) $(LIBM_SA)
+JUMP_LDLIBS_PEX5 = $(JUMP_ROOT_X11)/libX11.sa $(JUMP_LDLIBS_libc) -lm
+
+# libXIE.so (XIE)
+JUMP_ROOT_XIE = $(XIELIBSRC)
+JUMP_IS_HOST_XIE = YES
+JUMP_STUBLIBS_XIE = libXIE.sa
+JUMP_SUBDIRS_XIE = $(JUMP_ROOT_X11)
+JUMP_DIR_XIE = $(JUMP_ROOT_XIE)/shared
+JUMP_VARS_XIE = $(JUMP_ROOT_XIE)/jump_vars
+JUMP_FUNCS_XIE = $(JUMP_ROOT_XIE)/jump_funcs
+JUMP_IGNORE_XIE = $(JUMP_ROOT_XIE)/jump_ignore
+JUMP_EXPORT_XIE = $(JUMP_DIR_XIE)/jump.vars
+JUMP_IMPORT_XIE = $(JUMP_EXPORT_X11)
+JUMP_ADDRESS_XIE = 0x60be0000
+JUMP_JUMPTABLESIZE_XIE = 0x4000
+JUMP_GOTSIZE_XIE = 4096
+JUMP_STUBNAMES_XIE = libXIE
+JUMP_STUBS_IMPORT_XIE = $(JUMP_STUBS_IMPORT_X11) $(LIBM_SA)
+JUMP_LDLIBS_XIE = $(JUMP_ROOT_X11)/libX11.sa $(JUMP_LDLIBS_libc) -lm
+
+#endif /* !UseInstalled */
+
+/*
+ * SharedLibraryDataTarget - generate rules to create shared data file
+ */
+#ifndef SharedLibraryDataTarget
+#define SharedLibraryDataTarget(libname,rev,salist)
+#endif
+
+/*
+ * SharedLibraryTarget - generate rules to create a shared library;
+ * There are two basic flavors of libs: self-generating, which create
+ * their own (and possibly other) libs, and hosted, which rely on another
+ * lib for all the work.
+ */
+#ifndef SharedLibraryTarget
+#define SharedLibraryTarget(libname,rev,solist,down,up)                        @@\
+XCOMM This logic is such to compile the libs in their proper order,    @@\
+XCOMM remain dependent on subsidiary libs, and yet minimize local work @@\
+                                                                       @@\
+JUMP_DIR=./jump                                                                @@\
+JUMP_LIB=Concat(lib,libname)                                           @@\
+                                                                       @@\
+XCOMM  this is needed for newer gnumake versions                       @@\
+export JUMP_DIR JUMP_LIB                                               @@\
+                                                                       @@\
+JUMP_IS_HOST=$(Concat(JUMP_IS_HOST_,libname))                          @@\
+JUMP_AR=$(JUMP_DIR)/Concat(lib,libname.a~)                             @@\
+JUMP_SA=Concat(lib,libname.sa)                                         @@\
+JUMP_SO=Concat(lib,libname.so.rev)                                     @@\
+                                                                       @@\
+JUMP_HOST=$(Concat(JUMP_HOST_,libname))                                        @@\
+                                                                       @@\
+INSTSOLIBFLAGS=-m 0555                                                 @@\
+                                                                       @@\
+AllTarget($(BUILDLIBDIR)/$(JUMP_SA))                                   @@\
+                                                                       @@\
+$(BUILDLIBDIR)/$(JUMP_SA): $(JUMP_SA)                                  @@\
+       LinkBuildLibrary($(JUMP_SA))                                    @@\
+                                                                       @@\
+$(JUMP_SA) $(Concat(JUMP_STUBLIBS_,libname)) do_JUMP_SA: \
+               down/mk_JUMP_SA_$(JUMP_IS_HOST)                         @@\
+                                                                       @@\
+down/mk_JUMP_SA_0:: mk_JUMP_HOST                                       @@\
+                                                                       @@\
+down/mk_JUMP_SA_0:: $(JUMP_HOST)/$(JUMP_SA)                            @@\
+       $(RM) $(JUMP_SA)                                                @@\
+       $(LN) $(JUMP_HOST)/$(JUMP_SA) $(JUMP_SA)                        @@\
+       touch $@                                                        @@\
+                                                                       @@\
+down/mk_JUMP_SA_1:: $(JUMP_SO)                                         @@\
+                                                                       @@\
+down/mk_JUMP_SA_1:: down/mk_JUMP_SO_2                                  @@\
+       $(RM) $(Concat(JUMP_STUBLIBS_,libname))                         @@\
+       mkstubs -v rev -l $(JUMP_LIB) \
+               -a $(Concat(JUMP_ADDRESS_,libname)) \
+               -j $(Concat(JUMP_JUMPTABLESIZE_,libname)) \
+               -g $(Concat(JUMP_GOTSIZE_,libname)) \
+               -- $(Concat(JUMP_STUBNAMES_,libname))                   @@\
+       verify-shlib -l $(JUMP_SO) \
+               $(Concat(JUMP_STUBLIBS_,libname))                       @@\
+       $(MV) verify.out $(JUMP_DIR)                                    @@\
+       touch $@                                                        @@\
+                                                                       @@\
+mk_JUMP_HOST:                                                          @@\
+       @echo checking stub library $(JUMP_SA) in $(JUMP_HOST)...       @@\
+       @(cd $(JUMP_HOST); $(MAKE) $(MFLAGS) $(JUMP_SA)) || exit 1      @@\
+       @echo ok. continuing in $(Concat(JUMP_ROOT_,libname))...        @@\
+                                                                       @@\
+$(JUMP_SO): down/mk_JUMP_SO_$(JUMP_IS_HOST)                            @@\
+                                                                       @@\
+down/mk_JUMP_SO_0:                                                     @@\
+                                                                       @@\
+down/mk_JUMP_SO_1:: $(JUMP_AR) mk_JUMP_SIBDIRS down/mk_JUMP_SO_2       @@\
+                                                                       @@\
+down/mk_JUMP_SO_2: down/mk_JUMP_AR $(Concat(JUMP_SIBARS_,libname))     @@\
+       $(RM) $(JUMP_SO)                                                @@\
+       mkimage -f -v rev -l $(JUMP_LIB) \
+               -a $(Concat(JUMP_ADDRESS_,libname)) \
+               -j $(Concat(JUMP_JUMPTABLESIZE_,libname)) \
+               -g $(Concat(JUMP_GOTSIZE_,libname)) \
+               -- $(JUMP_AR) $(Concat(JUMP_LDLIBS_,libname))           @@\
+       $(RM) $(JUMP_DIR)/__jump.s $(JUMP_DIR)/__jump.o                 @@\
+       LinkBuildLibrary($(JUMP_SO))                                    @@\
+       touch $@                                                        @@\
+                                                                       @@\
+mk_JUMP_SIBDIRS:                                                       @@\
+       @for d in $(Concat(JUMP_SIBDIRS_,libname)); do \
+               echo checking ar library in $$d...; \
+               (cd $$d ; $(MAKE) $(MFLAGS) fastdo_JUMP_AR) || exit 1; \
+               echo ok. continuing in $(Concat(JUMP_ROOT_,libname))...;done@@\
+                                                                       @@\
+fastdo_JUMP_AR: $(JUMP_DIR) down/mk_JUMP_AR                            @@\
+                                                                       @@\
+$(JUMP_AR) do_JUMP_AR:: jumpsetup down/mk_JUMP_AR                      @@\
+                                                                       @@\
+jumpsetup: $(JUMP_DIR) jumpsetup_$(JUMP_IS_HOST)                       @@\
+                                                                       @@\
+$(JUMP_DIR):                                                           @@\
+       $(RM) jump                                                      @@\
+       LibMkdir($(Concat(JUMP_DIR_,libname)))                          @@\
+       $(LN) $(Concat(JUMP_DIR_,libname)) jump                         @@\
+                                                                       @@\
+jumpsetup_0:                                                           @@\
+       @echo doing jump setup in host $(JUMP_HOST)...                  @@\
+       @(cd $(JUMP_HOST); $(MAKE) $(MFLAGS) jumpsetup) || exit 1       @@\
+       @echo ok. continuing in $(Concat(JUMP_ROOT_,libname))...        @@\
+                                                                       @@\
+jumpsetup_1::                                                          @@\
+       @for d in $(Concat(JUMP_SUBDIRS_,libname)); do \
+               echo checking stub library in $$d...; \
+               (cd $$d ; $(MAKE) $(MFLAGS) do_JUMP_SA) || exit 1; \
+               echo ok. continuing in $(Concat(JUMP_ROOT_,libname))...;done@@\
+                                                                       @@\
+jumpsetup_1:: $(JUMP_DIR)/jump.funcs $(JUMP_DIR)/jump.vars \
+       $(JUMP_DIR)/jump.ignore $(JUMP_DIR)/jump.import                 @@\
+                                                                       @@\
+$(JUMP_DIR)/jump.funcs: $(Concat(JUMP_FUNCS_,libname))                 @@\
+       $(RM) $(JUMP_DIR)/jump.funcs                                    @@\
+       cat $(Concat(JUMP_FUNCS_,libname)) | \
+               $(CPP) $(ALLDEFINES) $(Concat(JUMP_DEFS_,libname)) > $@ @@\
+                                                                       @@\
+$(JUMP_DIR)/jump.vars: $(Concat(JUMP_VARS_,libname))                   @@\
+       $(RM) $(JUMP_DIR)/jump.vars                                     @@\
+       cat $(Concat(JUMP_VARS_,libname)) | \
+               $(CPP) $(ALLDEFINES) $(Concat(JUMP_DEFS_,libname)) > $@ @@\
+                                                                       @@\
+$(JUMP_DIR)/jump.ignore: $(Concat(JUMP_IGNORE_,libname))               @@\
+       $(RM) $(JUMP_DIR)/jump.ignore                                   @@\
+       cat $(Concat(JUMP_IGNORE_,libname)) | \
+               $(CPP) $(ALLDEFINES) $(Concat(JUMP_DEFS_,libname)) > $@ @@\
+                                                                       @@\
+$(JUMP_DIR)/jump.import: $(JUMP_DIR)/stubs.import \
+               $(Concat(JUMP_IMPORT_,libname))                         @@\
+       $(RM) $(JUMP_DIR)/jump.import                                   @@\
+       cat $(JUMP_DIR)/stubs.import $(Concat(JUMP_IMPORT_,libname)) > $@ @@\
+                                                                       @@\
+$(JUMP_DIR)/stubs.import: $(Concat(JUMP_STUBS_IMPORT_,libname))                @@\
+       $(RM) $(JUMP_DIR)/stubs.import                                  @@\
+       nm --no-cplus $(Concat(JUMP_STUBS_IMPORT_,libname)) | grep '__GOT__' | \
+               sed 's/__GOT__/_/' > $@                                 @@\
+                                                                       @@\
+down/mk_JUMP_AR: solist                                                        @@\
+       $(RM) $(JUMP_AR)                                                @@\
+       @if [ -s $(JUMP_DIR)/jump.log ]; then \
+               echo "Error: Leftover globals for shared lib"; \
+               exit 1; fi                                              @@\
+       (cd down; $(AR) up/$(JUMP_AR) solist) || exit 1                 @@\
+       $(RANLIB) $(JUMP_AR)                                            @@\
+       touch $@                                                        @@\
+                                                                       @@\
+clean:: jumpclean                                                      @@\
+                                                                       @@\
+jumpclean: jumpclean_$(JUMP_IS_HOST)                                   @@\
+       $(RM) $(JUMP_SA) down/mk_JUMP_AR                                @@\
+       $(RM) -r $(JUMP_DIR)                                            @@\
+                                                                       @@\
+jumpclean_0:                                                           @@\
+       $(RM) down/mk_JUMP_SA_0                                         @@\
+       $(RM) $(JUMP_HOST)/$(JUMP_SA)                                   @@\
+                                                                       @@\
+jumpclean_1:                                                           @@\
+       $(RM) -r $(JUMP_SO) $(Concat(JUMP_DIR_,libname)) \              @@\
+               down/mk_JUMP_SA_1 down/mk_JUMP_SO_1 down/mk_JUMP_SO_2
+#endif /* SharedLibraryTarget */
+
+/*
+ * InstallSharedLibrary - generate rules to install the shared library.
+ */
+#ifndef InstallSharedLibrary
+#define        InstallSharedLibrary(libname,rev,dest)                          @@\
+install:: $(JUMP_SA) $(JUMP_SO)                                                @@\
+       MakeDir($(DESTDIR)dest)                                         @@\
+       @if [ "$(JUMP_IS_HOST)" = YES ]; then \
+               (T=$(DESTDIR)dest/`echo $(JUMP_SO)|sed 's/\.[^\.]*$$//'`;\
+               set -x; \
+               $(INSTALL) -s -c $(INSTSOLIBFLAGS) $(JUMP_SO) $(DESTDIR)dest; \
+               $(RM) $$T && $(LN) $(JUMP_SO) $$T); fi                  @@\
+       $(INSTALL) -c $(INSTLIBFLAGS) $(JUMP_SA) $(DESTDIR)dest
+#endif /* InstallSharedLibrary */
+
+/*
+ * InstallSharedLibraryData - generate rules to install the shared library data
+ */
+#ifndef InstallSharedLibraryData
+#define        InstallSharedLibraryData(libname,rev,dest)
+#endif /* InstallSharedLibraryData */
+
+#endif /* UseElfFormat */
diff --git a/Xserver/config/cf/lnxLib.tmpl b/Xserver/config/cf/lnxLib.tmpl
new file mode 100644 (file)
index 0000000..ebf7307
--- /dev/null
@@ -0,0 +1,41 @@
+XCOMM $XConsortium: lnxLib.tmpl,v 1.5 95/01/11 21:44:44 kaleb Exp $
+XCOMM $XFree86: xc/config/cf/lnxLib.tmpl,v 3.9 1996/02/24 04:32:52 dawes Exp $
+
+/*
+ * Linux shared library template
+ */
+
+#if UseElfFormat
+
+#ifndef FixupLibReferences
+#define FixupLibReferences()                                           @@\
+XMULIBONLY = -lXmu                                                     @@\
+XMULIB = $(XMULIBONLY) $(XTOOLLIB) $(XLIB)
+#endif
+
+#ifndef XawClientLibs
+#define XawClientLibs $(XAWLIB) $(XMULIBONLY) $(XTOOLLIB) $(XLIB)
+#endif
+
+#define CplusplusLibC
+
+#define SharedX11Reqs
+#define SharedOldXReqs $(LDPRELIB) $(XLIBONLY)
+#define SharedXtReqs   $(LDPRELIB) $(XLIBONLY) $(SMLIB) $(ICELIB)
+#define SharedXawReqs  $(LDPRELIB) $(XMULIB) $(XTOOLLIB) $(XLIB)
+#define SharedXmuReqs  $(LDPRELIB) $(XTOOLLIB) $(XLIB)
+#define SharedXextReqs $(LDPRELIB) $(XLIBONLY)
+#define SharedXiReqs   $(LDPRELIB) $(XLIB)
+#define SharedPexReqs  $(LDPRELIB) $(XLIBONLY) MathLibrary
+#define SharedXtstReqs $(LDPRELIB) $(XLIB)
+#define SharedXieReqs  $(LDPRELIB) $(XLIBONLY)
+#define SharedSMReqs   $(LDPRELIB) $(ICELIB)
+
+#else  /* UseElfFormat */
+
+#ifndef FixupLibReferences
+#define FixupLibReferences()                                           @@\
+XMULIB = -lXmu $(XLIB)
+#endif
+
+#endif /* UseElfFormat */
diff --git a/Xserver/config/cf/lnxdoc.rules b/Xserver/config/cf/lnxdoc.rules
new file mode 100644 (file)
index 0000000..71881a6
--- /dev/null
@@ -0,0 +1,166 @@
+XCOMM $XFree86: xc/config/cf/lnxdoc.rules,v 3.9 1997/01/26 05:10:25 dawes Exp $
+XCOMM
+XCOMM Rules for formatting Linuxdoc-SGML documentation
+XCOMM
+
+#include <lnxdoc.tmpl>
+
+#ifdef DontInstallLinuxDoc
+#define LinuxDocInstall(file,dest)     /* do nothing */
+#define LinuxDocInstallMultiple(files,dest)    /* do nothing */
+#else
+#define LinuxDocInstall(file,dest)     InstallNonExecFile(file,dest)
+#define LinuxDocInstallMultiple(files,dest)                            @@\
+InstallMultipleDest(install,files,dest)
+#endif
+
+#if !HasSgmlFmt
+/* Version for Linuxdoc-SGML */
+#if BuildLinuxDocPS
+#define LinuxDocSgmlToPs(sgmlfile,base)                                @@\
+AllTarget(base.ps)                                                     @@\
+                                                                       @@\
+base.ps: sgmlfile                                                      @@\
+       RemoveFile(base.dvi)                                            @@\
+       $(LINUXDOCFORMAT) -T latex sgmlfile | \                         @@\
+           $(LINUXDOCLATEX) -d > base.dvi                              @@\
+       RemoveFile(base.ps)                                             @@\
+       $(DVIPS) $(DVIPSOPTIONS) -o base._ps base.dvi && \              @@\
+           $(MV) base._ps $@                                           @@\
+       RemoveFile(base.dvi)                                            @@\
+                                                                       @@\
+LinuxDocInstall(base.ps,$(XFREE86PSDOCDIR))                            @@\
+                                                                       @@\
+clean::                                                                        @@\
+       RemoveFiles(base.dvi base._ps base.ps)
+#else
+#define LinuxDocSgmlToPs(sgmlfile,base) /**/
+#endif
+
+#if BuildLinuxDocText
+#define LinuxDocSgmlToText(sgmlfile,textfile)                          @@\
+AllTarget(textfile)                                                    @@\
+                                                                       @@\
+textfile: sgmlfile                                                     @@\
+       RemoveFile(textfile)                                            @@\
+       $(LINUXDOCFORMAT) -T nroff sgmlfile | \                         @@\
+           $(LINUXDOCROFF) | $(XFREE86IDENTFIX) > _$@ && \             @@\
+           $(MV) _$@ $@                                                @@\
+                                                                       @@\
+LinuxDocInstall(textfile,$(XFREE86DOCDIR))                             @@\
+                                                                       @@\
+clean::                                                                        @@\
+       RemoveFiles(Concat(_,textfile) textfile)
+#else
+#define LinuxDocSgmlToText(sgmlfile,textfile) /**/
+#endif
+
+/*
+ * The 'echo' stuff here is a bit of a hack, but 'set -x' doesn't show
+ * what is going on.
+ */
+#if BuildLinuxDocHtml
+#define LinuxDocSgmlToHtml(sgmlfile,base)                              @@\
+AllTarget(base.html)                                                   @@\
+                                                                       @@\
+base.html: sgmlfile                                                    @@\
+       @(TMP=/tmp/tmp.$$$$; \                                          @@\
+         RemoveFile($${TMP}); \                                        @@\
+         echo RemoveFiles(base*.html); \                               @@\
+         RemoveFiles(base*.html); \                                    @@\
+         echo "$(LINUXDOCFORMAT) -T html sgmlfile |" \                 @@\
+           "$(LINUXDOCPREHTML) | $(LINUXDOCFIXREF) > $${TMP}"; \       @@\
+         $(LINUXDOCFORMAT) -T html sgmlfile | \                        @@\
+           $(LINUXDOCPREHTML) | $(LINUXDOCFIXREF) > $${TMP};    \      @@\
+         echo "$(LINUXDOCFORMAT) -T html sgmlfile |" \                 @@\
+           "$(LINUXDOCPREHTML) >> $${TMP}"; \                          @@\
+         $(LINUXDOCFORMAT) -T html sgmlfile | \                        @@\
+           $(LINUXDOCPREHTML) >> $${TMP}; \                            @@\
+         echo "$(LINUXDOCHTML) base < $${TMP} > base.html &&" \        @@\
+           "$(MV) base._html $@"; \                                    @@\
+         $(LINUXDOCHTML) base < $${TMP} > base._html && \              @@\
+           $(MV) base._html $@; \                                      @@\
+         RemoveFile($${TMP}))                                          @@\
+                                                                       @@\
+LinuxDocInstallMultiple(base*.html,$(XFREE86HTMLDOCDIR))               @@\
+                                                                       @@\
+clean::                                                                        @@\
+       RemoveFiles(base*.html base._html)
+#else
+#define LinuxDocSgmlToHtml(sgmlfile,base) /**/
+#endif
+
+#else /* HasSgmlFmt */
+
+/* Version for FreeBSD's sgmlfmt */
+#if BuildLinuxDocPS
+#define LinuxDocSgmlToPs(sgmlfile,base)                                @@\
+AllTarget(base.ps)                                                     @@\
+                                                                       @@\
+base.ps: sgmlfile                                                      @@\
+       RemoveFile(base.ps)                                             @@\
+       @(BASE=`basename sgmlfile .sgml`;\                              @@\
+         set -x;\                                                      @@\
+         RemoveFile($$BASE.ps);\                                       @@\
+         $(SGMLFMTCMD) -f ps sgmlfile && $(MV) $$BASE.ps $@)           @@\
+                                                                       @@\
+LinuxDocInstall(base.ps,$(XFREE86PSDOCDIR))                            @@\
+                                                                       @@\
+clean::                                                                        @@\
+       RemoveFile(base.ps)
+#else
+#define LinuxDocSgmlToPs(sgmlfile,base) /**/
+#endif
+
+#if BuildLinuxDocText
+#define LinuxDocSgmlToText(sgmlfile,textfile)                          @@\
+AllTarget(textfile)                                                    @@\
+                                                                       @@\
+textfile: sgmlfile                                                     @@\
+       RemoveFile(textfile)                                            @@\
+       @(BASE=`basename sgmlfile .sgml`;\                              @@\
+         set -x;\                                                      @@\
+         RemoveFile($$BASE.latin1);\                                   @@\
+         $(SGMLFMTCMD) -f latin1 sgmlfile; \                           @@\
+         $(XFREE86IDENTFIX) < $$BASE.latin1 > _$@ && $(MV) _$@ $@)     @@\
+                                                                       @@\
+LinuxDocInstall(textfile,$(XFREE86DOCDIR))                             @@\
+                                                                       @@\
+clean::                                                                        @@\
+       RemoveFiles(Concat(_,textfile) textfile)
+#else
+#define LinuxDocSgmlToText(sgmlfile,textfile) /**/
+#endif
+
+#if BuildLinuxDocHtml
+#define LinuxDocSgmlToHtml(sgmlfile,base)                              @@\
+AllTarget(base.html)                                                   @@\
+                                                                       @@\
+base.html: sgmlfile                                                    @@\
+       @if [ sgmlfile != base.sgml ]; then $(LN) sgmlfile base.sgml; fi @@\
+       RemoveFiles(base*.html)                                         @@\
+       $(SGMLFMTCMD) -f html base.sgml || RemoveFile($@)               @@\
+       @if [ sgmlfile != base.sgml ]; then RemoveFile(base.sgml); fi   @@\
+                                                                       @@\
+LinuxDocInstallMultiple(base*.html,$(XFREE86HTMLDOCDIR))               @@\
+                                                                       @@\
+clean::                                                                        @@\
+       RemoveFiles(base*.html)
+#else
+#define LinuxDocSgmlToHtml(sgmlfile,base) /**/
+#endif
+
+#endif /* HasSgmlFmt */
+
+
+#define LinuxDocTargetLong(sgmlfile,textfile,base)                     @@\
+LinuxDocSgmlToText(sgmlfile,textfile)                                  @@\
+LinuxDocSgmlToHtml(sgmlfile,base)                                      @@\
+LinuxDocSgmlToPs(sgmlfile,base)
+
+#define LinuxDocReadmeTarget(base)                                     @@\
+LinuxDocTargetLong(base.sgml,README.base,base)
+
+#define LinuxDocTarget(base)                                           @@\
+LinuxDocTargetLong(base.sgml,base,base)
+
diff --git a/Xserver/config/cf/lnxdoc.tmpl b/Xserver/config/cf/lnxdoc.tmpl
new file mode 100644 (file)
index 0000000..4809643
--- /dev/null
@@ -0,0 +1,101 @@
+XCOMM $XFree86: xc/config/cf/lnxdoc.tmpl,v 3.5 1997/01/26 05:10:26 dawes Exp $
+XCOMM
+
+#ifndef HasLinuxDoc
+#define HasLinuxDoc            NO
+#endif
+
+#ifndef HasSgmlFmt
+#define HasSgmlFmt             NO
+#endif
+
+#ifndef LinuxDocDir
+#define LinuxDocDir            /usr/local/linuxdoc-sgml
+#endif
+
+#ifndef LinuxDocBinDir
+#define LinuxDocBinDir         $(LINUXDOCPATH)/bin
+#endif
+
+#ifndef LinuxDocFormatCmd
+#define LinuxDocFormatCmd      $(LINUXDOCBIN)/ldformat
+#endif
+
+#ifndef LinuxDocRoffCmd
+#define LinuxDocRoffCmd                $(LINUXDOCBIN)/qroff
+#endif
+
+#ifndef XFree86IdentFix
+#define XFree86IdentFix                sed '/\$$\XFree86:/s/\$$/Generated from /'
+#endif
+
+#ifndef LinuxDocFixrefCmd
+#define LinuxDocFixrefCmd      $(LINUXDOCBIN)/fixref
+#endif
+
+#ifndef LinuxDocPreHtmlCmd
+#define LinuxDocPreHtmlCmd     $(LINUXDOCBIN)/prehtml
+#endif
+
+#ifndef LinuxDocHtmlCmd
+#define LinuxDocHtmlCmd                $(LINUXDOCBIN)/html2html
+#endif
+
+#ifndef HasLatex
+#define HasLatex               NO
+#endif
+
+#ifndef LinuxDocLatexCmd
+#define LinuxDocLatexCmd       $(LINUXDOCBIN)/qtex
+#endif
+
+#ifndef SgmlFmtCmd
+#define SgmlFmtCmd             sgmlfmt
+#endif
+
+#ifndef HasDvips
+#define HasDvips               NO
+#endif
+
+#ifndef DvipsOptions
+#define DvipsOptions           /**/
+#endif
+
+#ifndef DvipsCmd
+#define DvipsCmd               dvips
+#endif
+
+#ifndef BuildLinuxDocText
+#define BuildLinuxDocText      HasLinuxDoc
+#endif
+
+#ifndef BuildLinuxDocHtml
+#define BuildLinuxDocHtml      NO
+#endif
+
+#ifndef BuildLinuxDocPS
+#define BuildLinuxDocPS                (HasLatex && HasDvips) || HasSgmlFmt
+#endif
+
+
+     LINUXDOCPATH = LinuxDocDir
+      LINUXDOCENV = LINUXDOC=$(LINUXDOCPATH)
+      LINUXDOCBIN = LinuxDocBinDir
+   LINUXDOCFORMAT = $(LINUXDOCENV) LinuxDocFormatCmd
+     LINUXDOCROFF = $(LINUXDOCENV) LinuxDocRoffCmd
+    LINUXDOCLATEX = $(LINUXDOCENV) LinuxDocLatexCmd
+   LINUXDOCFIXREF = $(LINUXDOCENV) LinuxDocFixrefCmd
+  LINUXDOCPREHTML = $(LINUXDOCENV) LinuxDocPreHtmlCmd
+     LINUXDOCHTML = $(LINUXDOCENV) LinuxDocHtmlCmd
+  XFREE86IDENTFIX = XFree86IdentFix
+            DVIPS = DvipsCmd
+     DVIPSOPTIONS = DvipsOptions
+       SGMLFMTCMD = SgmlFmtCmd
+
+XCOMM Some extra things to clean
+
+#ifdef ExtraFilesToClean
+#undef ExtraFilesToClean
+#endif
+#define ExtraFilesToClean *.aux *.dvi *.log *.tex *.toc *.html *.ps *.latin1
+
diff --git a/Xserver/config/cf/luna.cf b/Xserver/config/cf/luna.cf
new file mode 100644 (file)
index 0000000..cb5d99c
--- /dev/null
@@ -0,0 +1,117 @@
+XCOMM platform:  $XConsortium: luna.cf /main/35 1996/09/28 16:11:11 rws $
+/*
+ *     Please set the values for OSMajorVerion and OSMinorVersion
+ *     before making makefiles.         
+ *
+ *     The Luna version of the make program doesn't define the standard
+ *     macro MAKE, so you must run it as "make MAKE=make" at top level,
+ *     e.g., "make MAKE=make World"
+ */
+
+#ifdef Mc68000Architecture
+# ifdef luna2
+#ifndef OSName
+#define OSName            Mach 2.5 Vers 1.40
+#endif
+#ifndef OSMajorVersion
+#define OSMajorVersion    1
+#endif
+#ifndef OSMinorVersion
+#define OSMinorVersion    40
+#endif
+# else 
+#ifndef OSName
+#define OSName            UNIOS-B 4.3BSD UNIX: 2.00
+#endif
+#ifndef OSMajorVersion
+#define OSMajorVersion    2
+#endif
+#ifndef OSMinorVersion
+#define OSMinorVersion    0
+#endif
+#define DirFailPrefix -
+# endif
+#else  /* Mc88000Architecture */
+#ifndef OSName
+#define OSName            Mach 2.5 Vers 2.00.1
+#endif
+#ifndef OSMajorVersion
+#define OSMajorVersion    2
+#endif
+#ifndef OSMinorVersion
+#define OSMinorVersion    0
+#endif
+#ifndef OSTeenyVersion
+#define OSTeenyVersion    1
+#endif
+#endif
+XCOMM operating system:  OSName
+
+#define HasBsearch             NO
+#define HasVoidSignalReturn    NO
+#define HasGcc                 YES
+#define HasCThreads            YES
+#define HasThreadSafeAPI       NO
+#define Malloc0ReturnsNull     HasCThreads    /* -lthreads fails, -lc works */
+#define XawI18nDefines         -DHAS_WCHAR_H -DHAS_ISW_FUNCS
+#define BootstrapCFlags                -DUSE_CC_E -DNFS_STDOUT_BUG
+
+#define ThreadsLibraries               -lthreads -lmach
+#define ThreadsCplusplusLibraries      -lthreads -lmach
+
+#define PrimaryScreenResolution 100
+#define        BuildXKB        YES
+
+#ifdef Mc68000Architecture
+#ifdef luna2
+#if ((OSMajorVersion <= 1) && (OSMinorVersion < 40))
+#define ServerExtraDefines -DUNUSE_DRV_TIME -DUNUSE_SIGIO_SIGNAL 
+#endif
+#else  /* luna1 */
+#if ((OSMajorVersion <= 1) && (OSMinorVersion <= 60))
+#define StandardDefines         -Dluna -Duniosb
+#endif
+#if ((OSMajorVersion < 2) || ((OSMajorVersion == 2) && (OSMinorVersion < 1)))
+#define ServerExtraDefines -DUNUSE_DRV_TIME -DUNUSE_SIGIO_SIGNAL 
+#endif
+#endif /* luna2 */
+#if HasGcc
+#define OptimizedCDebugFlags    -O -traditional
+#define ServerCDebugFlags       -Dmc68020 -O -traditional
+#else  /* cc */
+#define OptimizedCDebugFlags    -O -Z18
+#define ServerCDebugFlags       -Dmc68020 -O -Z18
+#endif /* HasGcc */
+#endif /* Mc68000Architecture */
+
+
+#ifdef Mc88000Architecture
+#if ((OSMajorVersion <= 1) && (OSMinorVersion <= 12))
+#define ServerExtraDefines -DUNUSE_DRV_TIME -DUNUSE_SIGIO_SIGNAL 
+#endif
+#define HasNdbm                        YES
+#define ExtraLibraries         -li18n
+#if HasGcc
+#define CcCmd                   gcc -fstrength-reduce
+#define PreIncDir              /usr/local/lib/gcc/gcc-include
+#define OptimizedCDebugFlags    -O2 /* -traditional */
+#else
+#define PreIncDir              /usr/lib/ccom/include
+#endif
+#define PostIncDir             /usr/mach/include
+#endif
+
+#ifdef Mc68000Architecture
+#define UnalignedReferencesAllowed YES  /* if arbitrary deref is okay */
+#define BuildPexExt            NO              
+#define XlunaServer            YES
+#endif
+
+#ifdef Mc88000Architecture
+#define BuildPexExt            NO
+#define XlunaServer            YES
+#endif
+
+#if ((OSMajorVersion >= 2) && (OSMinorVersion >= 0) && (OSTeenyVersion >= 1))
+#define HasWChar32              YES
+#endif
diff --git a/Xserver/config/cf/lynx.cf b/Xserver/config/cf/lynx.cf
new file mode 100644 (file)
index 0000000..257380a
--- /dev/null
@@ -0,0 +1,316 @@
+XCOMM platform:  $XFree86: xc/config/cf/lynx.cf,v 3.12.2.6 1998/02/01 16:03:19 robin Exp $
+
+#ifdef i386Architecture
+# define OSName                        LynxOS AT
+#endif
+#ifdef ppcArchitecture
+# define OSName                        LynxOS PowerPC
+#endif
+#ifdef SparcArchitecture
+# define OSName                        LynxOS microSPARC
+#endif
+#define OSVendor               (LYNX Real-Time Systems, Inc)
+#define OSMajorVersion         2
+#define OSMinorVersion         5
+#define OSTeenyVersion         0
+
+#define HasGcc                 YES
+#if OSMajorVersion == 2 && OSMinorVersion > 2
+# define HasGcc2               YES
+# ifndef HasGcc2ForCplusplus
+#  define HasGcc2ForCplusplus  YES
+# endif
+#else
+# define HasGcc2               NO
+#endif
+#ifndef HasGcc2ForCplusplus
+# define HasGcc2ForCplusplus   YES
+#endif
+#define GccUsesGas             YES
+#define UseGas                 YES
+#define GnuCpp                 YES
+#define HasShadowPasswd                NO
+#ifndef HasLibCrypt
+# define HasLibCrypt           NO
+#endif
+#define HasPutenv              YES
+#define HasShm                 YES
+#define HasSockets             YES
+#define HasVFork               NO
+#define HasVarDirectory                NO
+#if OSMajorVersion == 2 && OSMinorVersion > 4
+# define HasBSD44Sockets       YES
+#endif
+
+#define HasPosixThreads                YES
+#define ThreadedX              YES
+#define HasThreadSafeAPI       YES     /* only 2.[345].0 ?? */
+#if HasGcc2
+# if OSMajorVersion == 2 && OSMinorVersion == 3
+#  define ThreadsCompileFlags  -mposix -mthreads
+#  define ThreadsCplusplusCompileFlags -mposix -mthreads
+# else
+#  define ThreadsCompileFlags  -mthreads
+#  define ThreadsCplusplusCompileFlags -mthreads
+# endif
+#else
+# define ThreadsCompileFlags   -m
+# define ThreadsCplusplusCompileFlags  -m
+#endif
+#if OSMajorVersion == 2 && OSMinorVersion < 3
+# define ThreadsLibraries /lib/thread/libc.a /lib/thread/libc_p.a
+#endif
+#if OSMinorVersion <= 5
+# define ThreadPreStdAPIDefines        -DXPRE_STANDARD_API
+#endif
+#define AvoidNullMakeCommand   YES
+#if OSMajorVersion == 2 && OSMinorVersion > 2
+#define StripInstalledPrograms YES
+#else
+/* under LynxOS AT V2.x /bin/strip will leave file.unstripped around
+ * and fail if installing across different file systems
+ */
+#define StripInstalledPrograms NO
+#endif
+#define CompressAllFonts       YES
+#define Malloc0ReturnsNull     NO
+#define NeedConstPrototypes    YES
+#define NeedFunctionPrototypes YES
+#define NeedNestedPrototypes   YES
+#define NeedVarargsPrototypes  YES
+#define NeedWidePrototypes     NO
+
+#if HasGcc2
+# if OSMajorVersion == 2 && OSMinorVersion == 3
+#  define CplusplusCmd         g++ -mposix
+#  define CcCmd                        gcc -mposix
+# else
+#  define CplusplusCmd         g++
+#  define CcCmd                        gcc
+# endif
+# if OSMajorVersion == 2 && OSMinorVersion == 5
+#  define DefaultCCOptions -ansi -pedantic -fcommon
+# endif
+#else
+# define CplusplusCmd          g++ 
+# define CcCmd                 gcc 
+# define DefaultCCOptions      -ansi
+# define GccGasOption          -DGCCUSESGAS /* For SuperProbe */
+#endif
+#define AsCmd                  as
+#define LdCmd                  ld
+#define AsmDefines             -DUSE_GAS
+#define CppCmd                 /lib/cpp
+#define YaccCmd                        bison -y
+/* make sure we take the right flex on 2.3.0 and 2.4.0 */
+#define LexCmd                 /bin/flex
+#if OSMinorVersion >= 5
+# define LexLib                        -lfl
+#else
+# define LexLib                        /**/
+#endif
+/* On LynxOS AT 2.3.0 /lib/libm.a is a symbolic link to /lib/libc.a, so we
+ * screw up some POSIX functionality when -lm comes before -lc_p in our
+ * ld argument list. For LynxOS-AT we don't need -lm but for others we 
+ * do (e.g. SPARC)
+ */
+#if OSMajorVersion == 2 && OSMinorVersion == 3
+# define MathLibrary           -lc_p -lm
+# define TermcapLibrary                -lc_p -ltermcap
+#else
+# define MathLibrary           -lm
+# define TermcapLibrary                -ltermcap
+#endif
+#define PreProcessCmd          CcCmd -E
+#if HasGcc2
+# define PostIncDir            DefaultGccIncludeDir
+#endif
+#define LdCombineFlags         -r
+#if HasGcc2
+# ifdef i386Architecture
+#  define OptimizedCDebugFlags DefaultGcc2i386Opt
+# else
+#  define OptimizedCDebugFlags -O2
+# endif
+#else
+# define OptimizedCDebugFlags  -O
+#endif
+#if OSMajorVersion == 2 && OSMinorVersion <= 2
+# define StandardDefines               -DLynx -DLynx_22 -DX_NOT_POSIX
+#else
+# if defined(i386Architecture) && OSMajorVersion == 2 && OSMinorVersion > 4
+/* need __i386__ for 2.5.0 AT and higher */
+#  define StandardDefines              -DLynx -DX_LOCALE -D__i386__
+# else
+#  define StandardDefines              -DLynx -DX_LOCALE
+# endif
+#endif
+#define StandardCppDefines     -traditional StandardDefines
+#ifdef i386Architecture
+# define ServerOSDefines       XFree86ServerOSDefines -DDDXTIME -DPART_NET
+# define ServerExtraDefines    -DGCCUSESGAS XFree86ServerDefines
+#else
+# if defined(SparcArchitecture)
+#  define SparcConsoleDefines  -DPATCHED_CONSOLE
+#  define ServerOSDefines      -DDDXOSINIT
+#  define ServerExtraDefines   -DGCCUSESGAS SparcConsoleDefines
+#  define XkbServerDefines     -DXKB_ALWAYS_USES_SOFT_REPEAT
+# else
+#  define ServerOSDefines      /**/
+#  define ServerExtraDefines   -DGCCUSESGAS
+# endif
+#endif
+#define ServerExtraSysLibs     $(CBRT) MathLibrary
+#define ConnectionFlags                -DUNIXCONN -DTCPCONN
+#if OSMajorVersion == 2 && OSMinorVersion < 5
+# define ExtraLibraries                -lbsd
+#else
+# define ExtraLibraries                -lbsd -llynx
+#endif
+#if !HasGcc2
+# define ExtraLoadFlags                -k
+#endif
+#if OSMajorVersion == 2 && OSMinorVersion <= 2
+# define XawI18nDefines                -DUSE_XWCHAR_STRING -DUSE_XMBTOWC
+#endif
+
+/* define HasMotif to YES for LynxOS with Motif
+ * installed according to the notes in README.LynxOS.
+ */
+#ifndef HasMotif
+# define HasMotif              NO
+#endif
+#if HasMotif
+# ifndef UseInstalledMotif
+#  define UseInstalledMotif    YES
+# endif
+# ifndef SaberProgramTarget
+#  define SaberProgramTarget(program,srclist,objlist,locallibs,syslibs) /**/
+# endif
+# define LocalTmplFile         <Motif.tmpl>
+# define LocalRulesFile                <Motif.rules>
+#endif
+
+#define ManSourcePath   $(MANPATH)/cat
+
+#ifndef ManSuffix
+# define ManSuffix     1
+#endif
+#ifndef ManDir
+# define ManDir                $(MANSOURCEPATH)1
+#endif
+#ifndef LibManSuffix
+# define LibManSuffix  3
+#endif
+#ifndef LibmanDir
+# define LibmanDir     $(MANSOURCEPATH)3
+#endif
+#ifndef FileManSuffix
+# define FileManSuffix 5
+#endif
+#ifndef FileManDir
+# define FileManDir    $(MANSOURCEPATH)5
+#endif
+
+/* groff 1.09 compiles right out of the box with LynxOS 2.3,
+ * so if you want to have manual pages you should install groff 1.09
+ * before you run 'make install.man'
+ */
+#ifndef InstallManPageLong
+#define InstallManPageLong(file,destdir,dest)                           @@\
+install.man:: file.man                                                  @@\
+       MakeDir($(DESTDIR)destdir)                                      @@\
+       $(RM) $(DESTDIR)destdir/dest.$(MANSUFFIX)*                      @@\
+       groff -e -t -man -Tascii file.man >/tmp/file.man                @@\
+       $(INSTALL) -c $(INSTMANFLAGS) /tmp/file.man $(DESTDIR)destdir/dest.$(MANSUFFIX) @@\
+       echo dest dest $(MANSUFFIX) >> $(DESTDIR)destdir/LIST$(MANSUFFIX) @@\
+       gawk '                                  \                       @@\
+       /^\.SH[         ]*NAME/         {       \                       @@\
+               getline; sub("\\\\", "(" p ") "); print; exit   \       @@\
+       }' p=$(MANSUFFIX) file.man  >> $(DESTDIR)destdir/../whatis      @@\
+       $(RM) /tmp/file.man
+#endif
+
+#ifndef InstallManPageAliases
+#define InstallManPageAliases(file,destdir,aliases)                     @@\
+install.man::                                                           @@\
+       @(SUFFIX=`echo $(DESTDIR)destdir/file.* | cut -f2,3 -d.`; \     @@\
+       for i in aliases; do (set -x; \                                 @@\
+       $(RM) $(DESTDIR)destdir/$$i.*; \                                @@\
+       (cd $(DESTDIR)destdir; $(LN) file.$${SUFFIX} \                  @@\
+       $$i.$${SUFFIX})); \                                             @@\
+       echo $$i dest $(MANSUFFIX) >> $(DESTDIR)destdir/LIST$(MANSUFFIX); \ @@\
+       done)
+#endif
+
+#ifndef InstallGenManPageLong
+#define InstallGenManPageLong(file,destdir,dest,suffix)                 @@\
+install.man:: file.man                                                  @@\
+       MakeDir($(DESTDIR)destdir)                                      @@\
+       $(RM) $(DESTDIR)destdir/dest.suffix*                            @@\
+       groff -e -t -man -Tascii file.man >/tmp/file.man                @@\
+       $(INSTALL) -c $(INSTMANFLAGS) /tmp/file.man $(DESTDIR)destdir/dest.suffix @@\
+       echo dest dest suffix >> $(DESTDIR)destdir/Concat(LIST,suffix)   @@\
+       gawk '                                  \                       @@\
+       /^\.SH[         ]*NAME/         {       \                       @@\
+               getline; sub("\\\\", "(" p ") "); print; exit   \       @@\
+       }' p=suffix file.man  >> $(DESTDIR)destdir/../whatis    @@\
+       $(RM) /tmp/file.man)
+#endif
+
+#ifndef InstallMultipleMan
+#define InstallMultipleMan(list,dest)                                   @@\
+install.man:: list                                                      @@\
+       MakeDir($(DESTDIR)dest)                                         @@\
+       @case '${MFLAGS}' in *[i]*) set +e;; esac; \                    @@\
+       for i in list; do \                                             @@\
+               (set -x; \                                              @@\
+               MNAME=`echo $$i | cut -f1 -d.`; \                       @@\
+               $(RM) $(DESTDIR)dest/$${MNAME}*; \                      @@\
+               groff -e -t -man -Tascii $$i >/tmp/$$i; \               @@\
+               $(INSTALL) -c $(INSTMANFLAGS) /tmp/$$i $(DESTDIR)dest/$${MNAME}.$(MANSUFFIX); \      @@\
+               echo $${MNAME} $${MNAME} $(MANSUFFIX) >> $(DESTDIR)dest/LIST$(MANSUFFIX)\  @@\
+               gawk '                                                  \  @@\
+               /^\.SH[         ]*NAME/         {                       \  @@\
+                       getline; sub("\\\\", "(" p ") "); print; exit   \  @@\
+               }' p=$(MANSUFFIX) $$i  >> $(DESTDIR)dest/../whatis      \  @@\
+               $(RM) /tmp/$$i); \                                         @@\
+       done
+#endif
+
+/*
+ * Definitions for the SUN server on LynxOS SPARC
+ */
+#ifdef SparcArchitecture
+# define XsunLynxServer                        YES
+# define XsunLynxMonoServer            NO
+# define BuildPexExt                   YES
+# define BuildXIE                      YES
+# ifndef BuildScreenSaverLibrary
+#  define BuildScreenSaverLibrary      YES
+# endif
+# if BuildXInputExt
+#  undef BuildXInputExt
+# endif
+# define BuildXInputExt                        NO
+# if BuildDPMSExt
+#  undef BuildDPMSExt
+# endif
+# define BuildDPMSExt                  NO
+# define BuildXF86MiscExt              NO
+/*
+ * XFree86 uses its own (more portable) database routines to speed up 
+ * the RGB database lookups
+ * However, if you want to use ndbm anyway, you can set that to NO in 
+ * site.def
+ */
+# ifndef UseRgbTxt
+#  define UseRgbTxt    YES
+# endif
+#endif
+
+#ifndef i386Architecture
+# define BuildXF86DGA NO
+#endif
+
+#include <xfree86.cf>
diff --git a/Xserver/config/cf/macII.cf b/Xserver/config/cf/macII.cf
new file mode 100644 (file)
index 0000000..90d1c86
--- /dev/null
@@ -0,0 +1,53 @@
+XCOMM platform:  $XConsortium: macII.cf /main/50 1996/09/28 16:11:19 rws $
+
+#ifndef OSName
+#define OSName            A/UX 3.0.1
+#endif
+#ifndef OSMajorVersion
+#define OSMajorVersion    3
+#endif
+#ifndef OSMinorVersion
+#define OSMinorVersion    0
+#endif
+#ifndef OSTeenyVersion
+#define OSTeenyVersion    1
+#endif
+XCOMM operating system:  OSName
+
+#if HasGcc
+#define BootstrapCFlags   -DmacII
+#endif
+#define SystemV             YES
+#define HasPoll                    NO
+#define NeedBerklib         YES
+#define ExtraLibraries      $(XBSDLIB) -lposix -lm -lmr
+#define Malloc0ReturnsNull  YES
+#define StandardDefines     -DmacII -DSYSV
+#define ExecableScripts     NO
+#define RemoveTargetProgramByMoving YES
+#define ExpandManNames      YES
+#define PexShmIPC           NO
+#define XmacIIServer        YES
+#define XawI18nDefines      -DUSE_XWCHAR_STRING -DUSE_XMBTOWC
+#if MacHasc89
+#define CcCmd c89 -D_POSIX_SOURCE
+#else
+#define HasVoidSignalReturn NO
+#endif
+#if OSMajorVersion <= 2
+#define ServerExtraDefines  -DSUPPORT_2_0
+#endif
+#define InstKmemFlags      -g sys -m 2711
+#define ExtensionOSDefines  -DXTESTEXT1
+
+#if !HasGcc
+#define DefaultCCOptions -A 3
+#define PexCCOptions -A 4
+#endif
+
+/*
+ * If you wish to override the man page directories, do so here using just
+ * one tab between the parameter name (e.g. ManDirectoryRoot) and the
+ * value so that cpp doesn't get confused.
+ */
+#define ManDirectoryRoot       /usr/catman/u_man
diff --git a/Xserver/config/cf/mach.cf b/Xserver/config/cf/mach.cf
new file mode 100644 (file)
index 0000000..ec1d60d
--- /dev/null
@@ -0,0 +1,81 @@
+XCOMM $TOG: mach.cf /main/2 1997/06/08 20:08:20 kaleb $
+
+
+
+XCOMM platform:  $XFree86: xc/config/cf/mach.cf,v 3.7.2.2 1997/07/05 15:55:29 dawes Exp $
+
+#define OSName           Mach 2.5/3.0
+#define OSVendor          /**/
+XCOMM operating system:  OSName
+#define OSMajorVersion         1
+#define OSMinorVersion         1
+
+#define HasGcc                         YES
+#define HasGcc2                        YES
+#define GccUsesGas             YES
+#define UseGas                 YES
+#define GnuCpp                 YES
+#define UseGccMakeDepend       YES
+#ifndef HasGcc2ForCplusplus
+#define HasGcc2ForCplusplus    YES
+#endif
+
+#define CcCmd                  gcc
+#define CppCmd                 /usr/mach3/lib/gcc-lib/i386-mach/2.3.3/cpp
+#define PreProcessCmd          /usr/mach3/lib/gcc-lib/i386-mach/2.3.3/cpp
+#define DefaultCCOptions       /**/
+#define GccGasOption           -DGCCUSESGAS
+#if HasGcc2 && defined(i386Architecture)
+#define OptimizedCDebugFlags   DefaultGcc2i386Opt
+#else
+#define OptimizedCDebugFlags   -O2
+#endif
+
+#define AsmDefines             -DUSE_GAS
+#define BootstrapCFlags                -DNOSTDHDRS
+#define ExtensionOSDefines     /* -DXTESTEXT1 */
+#define ServerExtraSysLibs     /usr/lib/libmach.a
+#ifdef i386Architecture
+#define ServerExtraDefines     GccGasOption XFree86ServerDefines
+#else
+#define ServerExtraDefines     GccGasOption
+#endif
+#define StandardCppDefines     -traditional
+#define StandardDefines                -DNOSTDHDRS -DMACH386
+#define ServerOSDefines                XFree86ServerOSDefines -DDDXTIME
+
+#define AvoidNullMakeCommand   YES
+#define CompressAllFonts       YES
+#define DirFailPrefix -
+#define HasNdbm                YES
+#define HasPutenv              YES
+#define Malloc0ReturnsNull     YES
+#define NeedConstPrototypes    YES
+#define NeedFunctionPrototypes YES
+#define NeedNestedPrototypes   YES
+#define NeedVarargsPrototypes  YES
+#define NeedWidePrototypes     NO
+#define StripInstalledPrograms YES
+
+#ifndef GnuMallocLibrary
+#define GnuMallocLibrary       /* -lgnumalloc */
+#endif
+
+#ifdef InstallCmd
+#undef  InstallCmd
+#endif
+#define InstallCmd             /usr/bin/install
+
+#ifndef PreIncDir
+# define PreIncDir     /usr/include
+#endif
+
+#define TroffCmd        groff -Tps
+
+#ifndef ExtraFilesToClean
+# define ExtraFilesToClean *.core
+#endif
+
+#ifdef i386Architecture
+# include <xfree86.cf>
+#endif
diff --git a/Xserver/config/cf/minix.cf b/Xserver/config/cf/minix.cf
new file mode 100644 (file)
index 0000000..661eaa3
--- /dev/null
@@ -0,0 +1,64 @@
+XCOMM $XConsortium: minix.cf /main/1 1996/10/31 14:47:22 kaleb $
+
+
+
+XCOMM platform:  $XFree86: xc/config/cf/minix.cf,v 3.4 1996/12/27 06:50:21 dawes Exp $
+
+
+/*
+ * If you want to change any of these, do it in the BeforeVendorCF part
+ * of site.def
+ */
+#define OSName                 Minix-386vm
+#define OSVendor               /* philip@cs.vu.nl */
+#define OSMajorVersion         1
+#define OSMinorVersion         6
+#define OSTeenyVersion         25.1.0
+
+#define AcdGcc
+
+#ifdef AcdGcc
+#define ServerExtraDefines     -DGCCUSESGAS XFree86ServerDefines
+#define AsmDefines             -DUSE_GAS
+#define GccGasOption           -DGCCUSESGAS /* For SuperProbe */
+#endif
+
+/* Defaults for Minix */
+
+#define ConnectionFlags                -DMNX_TCPCONN
+#define StandardDefines                -D_MINIX -DMINIX -D_POSIX_SOURCE
+#define StandardIncludes       
+
+#define DoRanlibCmd            NO
+#define AvoidNullMakeCommand   YES
+#define HasSockets             NO
+#define HasStreams             NO
+#define HasVFork               NO
+#define HasNdbm                        YES
+#define        ExtraLibraries          -lnbio
+#define NeedConstPrototypes    YES
+#define NeedVarargsPrototypes  YES
+#define NeedNestedPrototypes   YES
+/* #define UseCCMakeDepend             YES */
+#define        DefaultCCOptions        -wo -fsoft
+#define ArCmd                  CcCmd -c.a -o
+#define ArAddCmd               ArCmd
+#define CcCmd                  acd -descr gcc -name cc
+#define AsCmd                  CcCmd -c
+#define CppCmd                 /usr/lib/cpp
+#define LdCmd                  CcCmd
+#define LdCombineFlags         -r
+#define LexLib                 /* */
+
+#define        SetTtyGroup             YES     /* for xterm */
+#define HasPutenv              YES     /* for xsm */
+
+#ifndef AssembleObject
+#define AssembleObject(flags) $(RM) $@                                    @@\
+       $(CPP) AsmDefines $(DEFINES) $(INCLUDES) flags $*.s | \           @@\
+           grep -v '^\#' > $*.i.s                                        @@\
+       $(AS) -o $*.o $*.i.s                                              @@\
+       $(RM) $*.i.s
+#endif
+
+#include <xfree86.cf>
diff --git a/Xserver/config/cf/moto.cf b/Xserver/config/cf/moto.cf
new file mode 100644 (file)
index 0000000..d6243a6
--- /dev/null
@@ -0,0 +1,58 @@
+XCOMM platform:  $XConsortium: moto.cf /main/16 1996/09/28 16:11:24 rws $
+
+#if defined(MotoR3Architecture)
+
+#ifndef OSName
+#define OSName                 Motorola R32V2/R3V6.2
+#endif
+#ifndef OSMajorVersion
+#define OSMajorVersion         3
+#endif
+#ifndef OSMinorVersion
+#define OSMinorVersion         2
+#endif
+
+#define SystemV                        YES
+#define BootstrapCFlags                -DSYSV -DMOTOROLA
+#define StandardDefines                -DSYSV -DUSG -DMOTOROLA
+#define Malloc0ReturnsNull     YES
+#define BuildServer            NO
+#define UseCCMakeDepend                YES
+#define OptimizedCDebugFlags   /* -O */
+
+#define DefaultUserPath        :/bin:/usr/bin:$(BINDIR)
+#define DefaultSystemPath      /etc:/bin:/usr/bin:$(BINDIR)
+
+#endif /* MotoR3Architecture */
+
+
+#if defined(MotoR4Architecture)
+
+#ifndef OSName
+#define OSName                 Motorola R40V4
+#endif
+#ifndef OSMajorVersion
+#define OSMajorVersion         4
+#endif
+#ifndef OSMinorVersion
+#define OSMinorVersion         4
+#endif
+
+#define SystemV4               YES
+#define BootstrapCFlags                -DSVR4 -DMOTOROLA
+#define StandardDefines         -DSVR4 -DMOTOROLA
+#define BuildServer            NO
+
+#define CppCmd                  /usr/ccs/lib/cpp
+#define LdCmd                   /usr/ccs/bin/ld
+#define LexCmd                  /usr/ccs/bin/lex
+#define MakeCmd                 /usr/ccs/bin/make
+#define YaccCmd                 /usr/ccs/bin/yacc
+#define CcCmd                   /bin/cc     /* a front-end to gcc/CI5 */
+#define DefaultCCOptions                    /* -Xc  no longer needed */
+
+#include <sv4Lib.rules>
+
+#endif /* MotoR4Architecture */
+
+XCOMM operating system:  OSName
diff --git a/Xserver/config/cf/ncr.cf b/Xserver/config/cf/ncr.cf
new file mode 100644 (file)
index 0000000..61279d3
--- /dev/null
@@ -0,0 +1,125 @@
+XCOMM platform:  $XConsortium: ncr.cf /main/28 1996/09/28 16:11:31 rws $
+XCOMM platform:  $XFree86: xc/config/cf/ncr.cf,v 3.18 1996/12/27 06:50:22 dawes Exp $
+
+#ifndef OSName
+#define OSName                 Unix System V Release 4/MP-RAS
+#endif
+#ifndef OSVendor
+#define OSVendor               NCR
+#endif
+XCOMM operating system:  OSName
+
+#define BootstrapCFlags                -DNCR
+#define HasStreams             YES
+#define XawI18nDefines         -DUSE_XWCHAR_STRING
+
+/* Build Flags */
+
+XCOMM
+XCOMM These flags build correctly on SVR4/MP-RAS 3.0. If building on
+XCOMM SVR4/MP-RAS 2.X, you must add -DWINTCP to StandardDefines
+XCOMM
+#define StandardDefines                -DSVR4 -DNCR -Di386
+#define DefaultCCOptions       -Xa -Hnocopyr -W0,-asm
+#define DefaultCDebugFlags     -O3
+#define AllocateLocalDefines   -DINCLUDE_ALLOCA_H
+#define ServerExtraDefines      -DNO_SECONDARY AllocateLocalDefines XFree86ServerDefines
+#define ServerOSDefines         -DDDXTIME XFree86ServerOSDefines
+#define ToolkitStringsABIOptions -intelabi
+
+XCOMM This has not been tested, don't turn it on yet.
+XCOMM #define ExtensionOSDefines       -DXTESTEXT1
+
+#define ExtraLoadFlags -lc -L/usr/ucblib -lucb -lm -lgen -lcmd
+
+/* Setup proper ownership of installed files */
+
+#define StripInstalledPrograms YES
+#define InstPgmFlags           -s -m 0711 -o bin -g bin
+#define InstBinFlags           -m 0755 -o bin -g bin
+#define InstUidFlags           -m 4711 -o root -g bin
+#define InstLibFlags           -m 0644 -o bin -g bin
+#define InstIncFlags           -m 0444 -o bin -g bin
+#define InstManFlags           -m 0444 -o bin -g bin
+#define InstDatFlags           -m 0444 -o bin -g bin
+
+/* Various Configuration settings */
+
+#define DefaultUserPath                /bin:/sbin:/usr/bin:/usr/sbin:$(BINDIR):/usr/ucb
+#define DefaultSystemPath      /etc:/bin:/usr/bin:/sbin:/usr/sbin:$(BINDIR):/usr/ucb
+#define ExtraFilesToClean      *.z
+
+/* Create man pages properly */
+#define BookFormatManPages     YES
+#define ManDirectoryRoot       /usr/catman/X115
+#define ManSuffix              1X
+#define LibManSuffix           3X
+#define FileManSuffix          4X
+#define ManSourcePath          $(MANPATH)/g
+#define XmanSearchPath         /usr/catman
+
+#define        TblCmd /usr/ucb/tbl
+#define        EqnCmd /usr/ucb/eqn
+#define ColCmd /usr/bin/col
+#define NeqnCmd /usr/ucb/neqn
+#define NroffCmd /usr/ucb/nroff -Tlp
+
+/*
+ * Man pages need to be formatted when installed, so override the default
+ * imake rules.
+ */
+#define InstallManPageLong(file,destdir,dest)                           @@\
+all:: file.z                                                           @@\
+                                                                       @@\
+file.z:: file.man                                                      @@\
+       @if [ -f file.man ]; \                                          @@\
+       then \                                                          @@\
+       cat file.man | $(NEQN) | $(TBL) | $(NROFF) $(MANMACROS) | $(COL) >/tmp/$$$$.man; \      @@\
+       $(RM) /tmp/$$$$.man.z; \                                        @@\
+       pack -f /tmp/$$$$.man; \                                        @@\
+       cp /tmp/$$$$.man.z file.z; \                                    @@\
+       $(RM) /tmp/$$$$.man.z; \                                        @@\
+       fi                                                              @@\
+                                                                       @@\
+file.man::                                                             @@\
+                                                                       @@\
+install.man::                                                           @@\
+       MakeDir($(DESTDIR)destdir)                                      @@\
+       -@if [ -f file.z ]; \                                           @@\
+       then \                                                          @@\
+       $(INSTALL) -c $(INSTMANFLAGS) file.z $(DESTDIR)destdir/dest.z; \@@\
+       fi
+
+#define InstallGenManPageLong(file,destdir,dest,suffix)                        @@\
+       InstallManPageLong(file,destdir,dest)
+
+#define InstallMultipleManSuffix(list,dest,suff)                        @@\
+install.man::                                                          @@\
+       MakeDir($(DESTDIR)dest)                                         @@\
+       MakeFlagsToShellFlags(i,set +e); \                              @@\
+       for i in list; do \                                             @@\
+         (set -x; \                                                    @@\
+         cat $$i.suff | $(NEQN) | $(TBL) | $(NROFF) $(MANMACROS) | $(COL) >/tmp/$$$$.suff; \   @@\
+         pack -f /tmp/$$$$.suff; \                                     @@\
+         $(INSTALL) -c $(INSTMANFLAGS) /tmp/$$$$.suff.z $(DESTDIR)dest/$$i.z; \        @@\
+         $(RM) /tmp/$$$$.suff.z); \                                            @@\
+       done
+
+#define InstallMultipleMan(list,dest)                                   @@\
+       InstallMultipleManSuffix(list,dest,man)
+
+#define InstallManPageAliases(file,destdir,aliases)                     @@\
+install.man::                                                          @@\
+       @MakeFlagsToShellFlags(i,set +e); \                             @@\
+       for i in aliases; do \                                          @@\
+               (set -x; \                                              @@\
+               $(RM) $(DESTDIR)destdir/$$i.z;\                         @@\
+               (cd $(DESTDIR)destdir; $(LN) file.z $$i.z);\            @@\
+               ); \                                                    @@\
+       done
+
+#define InstallGenManPageAliases(file,destdir,suffix,aliases)          @@\
+       InstallManPageAliases(file,destdir,aliases)
+
+#include <svr4.cf>
diff --git a/Xserver/config/cf/nec.cf b/Xserver/config/cf/nec.cf
new file mode 100644 (file)
index 0000000..364dfcd
--- /dev/null
@@ -0,0 +1,131 @@
+XCOMM platform:  $XConsortium: nec.cf /main/4 1996/09/28 16:11:37 rws $
+
+#ifdef nec_ews_svr2
+# define NecCISCArchitecture
+#else /* !defined(nec_ews_svr2) */
+# if defined(nec_ews_svr4) || defined(_nec_ews_svr4) || defined(_nec_up)
+#  define NecRISCArchitecture
+# else /* !(defined(nec_ews_svr4) || defined(_nec_ews_svr4) || defined(_nec_up)) */
+#  ifdef SX
+#   define NecSX3Architecture
+#  else /* !defined(SX) */
+#   ifdef _nec_ft
+#    define NecFaultTolerantArchitecture
+#   else /* !defined(_nec_ft) */
+#    ifdef PC_UX
+#     define NecPCArchitecture
+#    endif /* PC_UX */
+#   endif /* !defined(_nec_ft) */
+#  endif /* !defined(SX) */
+# endif /* !(defined(nec_ews_svr4) || defined(_nec_ews_svr4) || defined(_nec_up)) */
+#endif /* !defined(nec_ews_svr2) */
+
+#ifdef NecCISCArchitecture
+#ifndef OSName
+#define OSName                 EWS-UX/V
+#endif
+#ifndef OSMajorVersion
+#define OSMajorVersion         10
+#endif
+#ifndef OSMinorVersion
+#define OSMinorVersion         1
+#endif
+#define HasSharedLibraries     NO
+#define HasVoidSignalReturn    NO
+#define HasSockets             YES
+#define SystemV                        YES
+#define StandardDefines                -Dnec_ews -Dnec_ews_svr2 -DUSG -DSYSV
+#define StandardCppDefines     -Dnec_ews -Dnec_ews_svr2 -DUSG -DSYSV
+#define LnCmd                  ln -s
+        LEXOPTION = -j
+#endif
+
+#ifdef NecRISCArchitecture
+# ifdef _nec_up
+#ifndef OSName
+#define OSName                 UP-UX/V
+#endif
+#ifndef OSMajorVersion
+#define OSMajorVersion         5
+#endif
+#ifndef OSMinorVersion
+#define OSMinorVersion         1
+#endif
+# else
+#ifndef OSName
+#define OSName                 EWS-UX/V\(Rel4.2\)
+#endif
+#ifndef OSMajorVersion
+#define OSMajorVersion         9
+#endif
+#ifndef OSMinorVersion
+#define OSMinorVersion         1
+#endif
+# endif
+#define HasSharedLibraries     YES
+#define HasVoidSignalReturn    YES
+#define SystemV4               YES
+#define HasSockets             YES
+#endif
+
+#ifdef NecSX3Architecture
+#ifndef OSName
+#define OSName                 SUPER-UX
+#endif
+#ifndef OSMajorVersion
+#define OSMajorVersion         3
+#endif
+#ifndef OSMinorVersion
+#define OSMinorVersion         1
+#endif
+#define SystemV                        YES
+#define HasSharedLibraries     NO
+#define HasVoidSignalReturn    YES
+#endif
+
+#ifdef NecFaultTolerantArchitecture
+#ifndef OSName
+#define OSName                 FT-UX/V
+#endif
+#ifndef OSMajorVersion
+#define OSMajorVersion         5
+#endif
+#ifndef OSMinorVersion
+#define OSMinorVersion         1
+#endif
+#define HasSharedLibraries     YES
+#define HasVoidSignalReturn    YES
+#define SystemV4               YES
+#define HasSockets             YES
+#endif
+
+#ifdef NecPCArchitecture
+#ifndef OSName
+#define OSName                 PC-UX/V
+#endif
+#ifndef OSMajorVersion
+#define OSMajorVersion         3
+#endif
+#ifndef OSMinorVersion
+#define OSMinorVersion         1
+#endif
+#define HasSharedLibraries     NO
+#define HasVoidSignalReturn    NO
+#define SystemV                        YES
+#endif
+
+#define HasSaberC      NO              /* for machines that have it */
+#define HasGcc         NO
+#define HasBsearch     YES
+
+#define DefaultCCOptions       -Wf,-XNp9000,-XNd6000
+#define ExtraLibraries         -lsocket -lnsl -lw
+
+#define BuildServer                    NO
+/* #define InstallCmd $(INS) */
+#define        RemoveTargetProgramByMoving     YES
+
+#include <necLib.rules>
+
+#define LibraryCCOptions DefaultCCOptions
+#define LibraryDefines  StandardDefines
diff --git a/Xserver/config/cf/necLib.rules b/Xserver/config/cf/necLib.rules
new file mode 100644 (file)
index 0000000..cfc8222
--- /dev/null
@@ -0,0 +1,103 @@
+XCOMM $XConsortium: necLib.rules /main/4 1996/09/28 16:11:42 rws $
+
+/*
+ * NECOS shared library rules
+ */
+
+#ifndef HasSharedLibraries
+#define HasSharedLibraries YES
+#endif
+#ifndef SharedDataSeparation
+#define SharedDataSeparation YES
+#endif
+#ifndef SharedCodeDef
+#define SharedCodeDef
+#endif
+#ifndef SharedLibraryDef
+#define SharedLibraryDef
+#endif
+#ifndef ShLibIncludeFile
+#define ShLibIncludeFile <necLib.tmpl>
+#endif
+#ifndef SharedLibraryLoadFlags
+#define SharedLibraryLoadFlags
+#endif
+#ifndef PositionIndependentCFlags
+#define PositionIndependentCFlags
+#endif
+
+
+#ifndef SeparateSharedCompile
+#define SeparateSharedCompile NO
+#endif
+
+#define SharedLibObjCompile(options) $(_NULLCMD_)
+
+/*
+ * InstallSharedLibrary - generate rules to install the shared library.
+ */
+#ifndef InstallSharedLibrary
+#define        InstallSharedLibrary(libname,rev,dest)                          @@\
+install:: Concat(lib,libname.so.rev)                                   @@\
+       MakeDir($(DESTDIR)dest)                                         @@\
+       $(INSTALL) -c $(INSTLIBFLAGS) Concat(lib,libname.so.rev) $(DESTDIR)dest @@\
+       cd $(DESTDIR)/dest; $(LN) Concat(lib,libname.so.rev) Concat(lib,libname.so)     @@\
+
+#endif /* InstallSharedLibrary */
+
+/*
+ * InstallSharedLibraryData - generate rules to install the shared library data
+ */
+#ifndef InstallSharedLibraryData
+#define        InstallSharedLibraryData(libname,rev,dest)                      @@\
+install:: Concat(lib,libname.sa.rev)                                   @@\
+       MakeDir($(DESTDIR)dest)                                         @@\
+       $(INSTALL) -c $(INSTLIBFLAGS) Concat(lib,libname.sa.rev) $(DESTDIR)dest @@\
+       RanLibrary($(RANLIBINSTFLAGS) Concat($(DESTDIR)dest/lib,libname.sa.rev))
+
+#endif /* InstallSharedLibraryData */
+
+/*
+ * SharedLibraryTarget - generate rules to create a shared library;
+ * build it into a different name so that we do not hose people by having
+ * the library gone for long periods.
+ */
+#ifndef SharedLibraryTarget
+#define SharedLibraryTarget(libname,rev,solist,down,up)                        @@\
+AllTarget(Concat(lib,libname.so.rev))                                  @@\
+                                                                       @@\
+Concat(lib,libname.so.rev):  solist $(EXTRALIBRARYDEPS)                        @@\
+       $(RM) $@~                                                       @@\
+       $(CC) -G -o $@~ $(SHLIBLDFLAGS) solist                          @@\
+       $(RM) $@                                                        @@\
+       $(MV) $@~ $@                                                    @@\
+                                                                       @@\
+AllTarget(Concat(lib,libname.so))                                      @@\
+                                                                       @@\
+Concat(lib,libname.so):  Concat(lib,libname.so.rev)                    @@\
+       $(RM) $@                                                        @@\
+       $(LN) $? $@                                                     @@\
+       LinkBuildLibrary($@)                                            @@\
+       LinkBuildLibrary(Concat(lib,libname.so))                        @@\
+                                                                       @@\
+clean::                                                                        @@\
+       $(RM) Concat(lib,libname.so.rev)
+
+#endif /* SharedLibraryTarget */
+
+/*
+ * SharedLibraryDataTarget - generate rules to create shlib data file;
+ */
+#ifndef SharedLibraryDataTarget
+#define SharedLibraryDataTarget(libname,rev,salist)                    @@\
+AllTarget(Concat(lib,libname.sa.rev))                                  @@\
+                                                                       @@\
+Concat(lib,libname.sa.rev):  salist $(EXTRALIBRARYDEPS)                        @@\
+       $(RM) $@                                                        @@\
+       $(AR) $@ salist                                                 @@\
+       RanLibrary($@)                                                  @@\
+                                                                       @@\
+clean::                                                                        @@\
+       $(RM) Concat(lib,libname.sa.rev)
+
+#endif /* SharedLibraryDataTarget */
diff --git a/Xserver/config/cf/necLib.tmpl b/Xserver/config/cf/necLib.tmpl
new file mode 100644 (file)
index 0000000..2e7f04b
--- /dev/null
@@ -0,0 +1,29 @@
+XCOMM $XConsortium: necLib.tmpl,v 1.1 94/03/26 18:15:22 rws Exp $
+
+/*
+ * NEC shared library template
+ */
+
+#ifndef SharedXlibRev
+#define SharedXlibRev 4.10
+#endif
+#ifndef SharedOldXRev
+#define SharedOldXRev 4.10
+#endif
+#ifndef SharedXtRev
+#define SharedXtRev 4.10
+#endif
+#ifndef SharedXawRev
+#define SharedXawRev 5.0
+#endif
+#ifndef SharedXmuRev
+#define SharedXmuRev 4.10
+#endif
+#ifndef SharedXextRev
+#define SharedXextRev 4.10
+#endif
+#ifndef SharedXinputRev
+#define SharedXinputRev 4.10
+#endif
+
+#include <sv4Lib.tmpl>
diff --git a/Xserver/config/cf/noop.rules b/Xserver/config/cf/noop.rules
new file mode 100644 (file)
index 0000000..8b13789
--- /dev/null
@@ -0,0 +1 @@
+
diff --git a/Xserver/config/cf/oldlib.rules b/Xserver/config/cf/oldlib.rules
new file mode 100644 (file)
index 0000000..52faa69
--- /dev/null
@@ -0,0 +1,109 @@
+/* You should not use these any more, use new Library.tmpl insead */
+
+XCOMM $XConsortium: oldlib.rules,v 1.2 91/04/09 19:15:13 rws Exp $
+
+/*
+ * ProfiledLibraryObjectRule - generate make rules to build both profiled
+ * and "normal" objects.
+ */
+#ifndef ProfiledLibraryObjectRule
+#define        ProfiledLibraryObjectRule()                                     @@\
+all::                                                                  @@\
+       LibMkdir(profiled)                                              @@\
+                                                                       @@\
+.c.o:                                                                  @@\
+       ProfiledLibObjCompile(NullParameter)                            @@\
+       NormalLibObjCompile(NullParameter)                              @@\
+                                                                       @@\
+clean::                                                                        @@\
+       LibCleanDir(profiled)                                           @@\
+
+#endif /* ProfiledLibraryObjectRule */
+
+
+/*
+ * DebuggedLibraryObjectRule - generate make rules to build both debuggable
+ * and "normal" objects.
+ */
+#ifndef DebuggedLibraryObjectRule
+#define        DebuggedLibraryObjectRule()                                     @@\
+all::                                                                  @@\
+       LibMkdir(debugger)                                              @@\
+                                                                       @@\
+.c.o:                                                                  @@\
+       DebuggedLibObjCompile(NullParameter)                            @@\
+       NormalLibObjCompile(NullParameter)                              @@\
+                                                                       @@\
+clean::                                                                        @@\
+       LibCleanDir(debugger)                                           @@\
+
+#endif /* DebuggedLibraryObjectRule */
+
+
+/*
+ * DebuggedAndProfiledLibraryOjbectRule - generate make rules to build
+ * debuggable, profiled, and "normal" objects.
+ */
+#ifndef DebuggedAndProfiledLibraryObjectRule
+#define        DebuggedAndProfiledLibraryObjectRule()                          @@\
+all::                                                                  @@\
+       LibMkdir(profiled)                                              @@\
+       LibMkdir(debugger)                                              @@\
+                                                                       @@\
+.c.o:                                                                  @@\
+       ProfiledLibObjCompile(NullParameter)                            @@\
+       DebuggedLibObjCompile(NullParameter)                            @@\
+       NormalLibObjCompile(NullParameter)                              @@\
+                                                                       @@\
+clean::                                                                        @@\
+       LibCleanDir(profiled)                                           @@\
+       LibCleanDir(debugger)                                           @@\
+
+#endif /* DebuggedAndProfiledLibraryObjectRule */
+
+
+/*
+ * SpecialProfiledObjectRule - generate rules to compile a file with special
+ * flags and to make a profiled version.
+ */
+#ifndef SpecialProfiledObjectRule
+#define        SpecialProfiledObjectRule(objs,depends,options)                 @@\
+all::                                                                  @@\
+       LibMkdir(profiled)                                              @@\
+                                                                       @@\
+objs:  depends                                                         @@\
+       ProfiledLibObjCompile(options)                                  @@\
+       NormalLibObjCompile(options)
+#endif /* SpecialProfiledObjectRule */
+
+
+/*
+ * SpecialDebuggedObjectRule - generate rules to compile a file with special
+ * flags and to make a debuggable version.
+ */
+#ifndef SpecialDebuggedObjectRule
+#define        SpecialDebuggedObjectRule(objs,depends,options)                 @@\
+all::                                                                  @@\
+       LibMkdir(debugger)                                              @@\
+                                                                       @@\
+objs:  depends                                                         @@\
+       DebuggedLibObjCompile(options)                                  @@\
+       NormalLibObjCompile(options)
+#endif /* SpecialDebuggedObjectRule */
+
+
+/*
+ * SpecialDebuggedAndProfiledObjectRule - generate rules to compile a file 
+ * with special flags and to make debuggable and profiled versions.
+ */
+#ifndef SpecialDebuggedAndProfiledObjectRule
+#define        SpecialDebuggedAndProfiledObjectRule(objs,depends,options)      @@\
+all::                                                                  @@\
+       LibMkdir(profiled)                                              @@\
+       LibMkdir(debugger)                                              @@\
+                                                                       @@\
+objs:  depends                                                         @@\
+       ProfiledLibObjCompile(options)                                  @@\
+       DebuggedLibObjCompile(options)                                  @@\
+       NormalLibObjCompile(options)
+#endif /* SpecialDebuggedAndProfiledObjectRule */
diff --git a/Xserver/config/cf/os2.cf b/Xserver/config/cf/os2.cf
new file mode 100644 (file)
index 0000000..d9811a4
--- /dev/null
@@ -0,0 +1,252 @@
+XCOMM $XConsortium: os2.cf /main/1 1996/10/31 14:47:25 kaleb $
+
+
+
+XCOMM platform:  $XFree86: xc/config/cf/os2.cf,v 3.18.2.4 1998/02/22 01:04:50 robin Exp $
+
+#define OSName           OS/2
+#define OSVendor        IBM
+#define OSMajorVersion    3
+#define OSMinorVersion    0
+
+/*
+ * C library features
+ */
+#ifdef __EMX__
+
+/* set this to what you like (almost :-) 
+ * OS/2 does a nonstandard bootstrap of imake 
+ */
+#define BootstrapCFlags   -DBSD43
+
+/* X_WCHAR and X_LOCALE are set in Xosdefs.h */
+#define StandardDefines   /**/
+#define XawI18nDefines    -DUSE_XWCHAR_STRING -DUSE_XMBTOWC
+
+/* This will redirect everything to /XFree86
+ * Care will be taken that programs that need a file from this tree
+ * will add the environment variable X11ROOT to the search path
+ * so you can redirect the stuff to a different drive
+ */
+#ifdef ProjectRoot
+#undef ProjectRoot
+#endif
+/* This will be mangled with a drive letter in most OS/2 rules ... */
+#define ProjectRoot    /XFree86
+
+/* ... but not when a user tries to compile something from a different drive 
+ * Please report any directories missed to Holger.Veit@gmd.de 
+*/
+#ifdef UseInstalled
+#define IncRoot $(X11ROOT)/XFree86/include
+#define LdPreLib -L$(X11ROOT)/XFree86/lib
+#endif
+
+/* more directories */
+#define AdmDir                 $(LIBDIR)/adm
+#define ConfigDir              $(X11ROOT)$(LIBDIR)/config
+        DESTDIR = $(X11ROOT)
+
+/* for the man pages */
+#define BookFormatManPages     YES
+#define ManDirectoryRoot /XFree86/man/man
+#define ManSuffix      1
+#define LibManSuffix   3
+#define FileManSuffix  4
+#define XmanSearchPath /XFree86/man/man
+#define ManSourcePath  $(MANPATH)
+
+/* you must have installed groff! */
+#define TblCmd         tbl
+#define ColCmd         cat
+#define NeqnCmd                eqn 
+#define NroffCmd       groff -Tascii
+#define        EqnCmd          eqn -Tascii
+#define TroffCmd        groff -Tps
+         NEQN = NeqnCmd
+        NROFF = NroffCmd
+
+/* A set of standard defines: */
+#define OSDefines              -D__EMX__ -D__i386__ -Demxos2 -D_POSIX_SOURCE \
+                               -D_BSD_SOURCE -D_GNU_SOURCE
+
+#define BuildXKB               YES
+#define BuildImplibs           YES
+#define BuildLBX               YES
+
+/* some more properties of the OS/2 implementation */
+#define HasNdbm                YES
+#define HasPutenv              YES
+#define HasSockets             YES
+#define HasSnprintf            YES
+#define HasBsearch             NO
+#define HasLargeTmp            NO
+#define HasPoll                        NO
+#define HasBSD44Sockets        NO
+#define HasSecureRPC           NO
+#define        HasSymLinks             NO
+#define HasVFork               NO
+#define HasVarDirectory                NO
+#define HasStrcasecmp          NO
+#define Malloc0ReturnsNull     YES
+#define SetTtyGroup            NO
+#ifndef HasLibCrypt
+# define HasLibCrypt           NO
+#endif
+#ifndef HasShm
+# define HasShm                YES
+#endif
+#define ConnectionFlags                -DTCPCONN -DOS2PIPECONN
+#define StdIncDir $(C_INCLUDE_PATH)
+
+/* XF86Setup stuff - does not work yet! */
+#define HasTcl                 NO
+/*define TclLibDir             $(X11ROOT)$(SHLIBDIR)*/
+/*define TclIncDir             $(X11ROOT)$(INCROOT)/tcl*/
+/*define TclLibName            xtcl*/
+
+#define HasTk                  NO
+/*define TkLibDir              $(X11ROOT)$(SHLIBDIR)*/
+/*define TkIncDir              $(X11ROOT)$(INCROOT)/tk*/
+/*define TkLibName             xtk*/
+
+/*
+ * Compiler Features
+ */
+#define HasGcc                 YES
+#define HasGcc2                        YES
+#define HasCplusplus           YES
+#define HasGcc2ForCplusplus    YES
+#define GccUsesGas             YES
+#define UseGas                 YES
+#define GnuCpp                 YES
+#define DoRanlibCmd            YES
+#define NeedConstPrototypes    YES
+#define NeedFunctionPrototypes YES
+#define NeedNestedPrototypes   YES
+#define NeedVarargsPrototypes  YES
+#define NeedWidePrototypes     NO
+
+#define CppCmd cpp
+#define StandardCppDefines     -traditional
+#define PreProcessCmd  CppCmd
+
+#define CcCmd  gcc
+#define DefaultCCOptions       -D__ST_MT_ERRNO__ -Zmtd -Zsysv-signals
+#define LibraryCCOptions       -D__ST_MT_ERRNO__ -Zmtd -Zsysv-signals
+#define ServerCCOptions        -D__ST_MT_ERRNO__ -Zmtd -Zsysv-signals
+
+#define CplusplusCmd g++
+#define CplusplusOptions       -Zmtd -Zsysv-signals
+
+#define MakeCmd x11make 
+#define AsCmd  gcc -S
+#define GccGasOption   -DGCCUSESGAS
+#define AsmDefines     -DUSE_GAS
+
+#define InstallCmd     install
+
+#define LdCmd  ld
+#define ExtraLoadFlags -Zbin-files
+#define ExtraLibraries -lsocket -lbsd
+
+/* quite a number of programs you need, most of them the same as
+ * with Unix, but listed here for completeness
+ */
+#define ArCmd  ar cq
+#define RanlibCmd      ar s
+#define BourneShell    /**/
+#define LexCmd flex -l
+#define LexLib -lfl
+#define YaccCmd        yacc
+#define LintCmd        /**/
+#define MvCmd  mv
+#define CompressCmd    compress
+#define GzipCmd        gzip
+#define LnCmd cp
+#define CpCmd cp
+#define RmCmd  ImakeHelper 4 
+
+#ifndef UseInstalled
+#define ImakeCmd \imake
+#define MkdirHierCmd \mkdirhier
+#define DependCmd \makedepend
+#else
+/* imake and mkdirhier come from Imake.tmpl, but DependCmd must be overriden */
+#define DependCmd makedepend
+#endif
+
+/* "shell scripts" in OS/2 have this extension */
+#define SHsuf cmd
+
+#define InstPgmFlags /**/
+#define InstBinFlags /**/
+#define InstUidFlags /**/
+#define InstLibFlags /**/
+#define InstIncFlags /**/
+#define InstManFlags /**/
+#define InstDatFlags /**/
+#define InstallFlags /**/
+
+#define OptimizedCDebugFlags   DefaultGcc2i386Opt
+#define ServerOSDefines        XFree86ServerOSDefines -DDDXTIME
+#define ServerExtraDefines GccGasOption XFree86ServerDefines
+
+#if HasShm
+# define ServerExtraSysLibs    -lshm
+#endif
+
+/*
+ * Make & install Features
+ */
+
+#define AvoidNullMakeCommand   YES
+_NULLCMD_ = @ rem
+#define NullMakeCommand        @ rem
+#define StripInstalledPrograms NO
+#define CompressAllFonts       YES
+#define CompressManPages       YES
+#define GzipFontCompression    YES
+#define DefaultUserPath                .;/os2;/emx/bin;/tcpip/bin;$(BINDIR)
+#define DefaultSystemPath      /os2;/emx/bin;$(BINDIR)
+
+#ifndef ExtraFilesToClean
+# define ExtraFilesToClean     *.~* *.exe *.dll *.obj *.lib *.map
+#endif
+
+#if CompressManPages
+#define CompressManCmd gzip -n
+   COMPRESSMANCMD = CompressManCmd
+#endif
+
+#define ProgramTargetName(target)target.exe
+
+/* we don't name libraries lib*.a */
+#define LibraryTargetName(libname) libname.a
+#define LibraryTargetNameSuffix(libname,suffix)Concat(libname,suffix.a)
+
+/* ... and we even don't do it in rules that should have used the above
+ * LibraryTargetName macro
+ */
+#ifndef UnSharedLibReferences
+#define UnsharedLibReferences(varname,libname,libsource)               @@\
+Concat3(DEP,varname,LIB) = _UseCat($(USRLIBDIR)/,$(BUILDLIBDIR)/,libname.a)    @@\
+Concat(varname,LIB) = LoaderLibPrefix Concat(-l,libname)               @@\
+LintLibReferences(varname,libname,libsource)
+#endif
+
+#ifndef SharedLibReferences
+#define SharedLibReferences(varname,libname,libsource,revname,rev)     @@\
+Concat3(DEP,varname,LIB) = SharedLibDependencies(libname,libsource,revname) @@\
+Concat(varname,LIB) = LoaderLibPrefix Concat(-l,libname)               @@\
+LintLibReferences(varname,libname,libsource)
+#endif
+
+#include <os2.rules>
+#include <os2Lib.rules>
+
+# include <xfree86.cf>
+
+#else
+#error You must edit os2.cf for your (non-EMX) OS/2 dev system
+#endif
diff --git a/Xserver/config/cf/os2.rules b/Xserver/config/cf/os2.rules
new file mode 100644 (file)
index 0000000..998ff48
--- /dev/null
@@ -0,0 +1,537 @@
+XCOMM $XConsortium: os2.rules /main/1 1996/10/31 14:47:27 kaleb $
+
+
+
+XCOMM platform:  $XFree86: xc/config/cf/os2.rules,v 3.15 1997/01/05 11:49:39 dawes Exp $
+
+.SUFFIXES: .Osuf .c .CCsuf
+
+.c.Osuf:
+       $(CC) $(CFLAGS) -c $*.c
+
+#if HasCplusplus
+.CCsuf.Osuf:
+       $(CXX) $(CFLAGS) -c $*.CCsuf
+#endif
+
+#ifndef UseInstalled
+#define ImakeHelper \imakesvc
+#define IMmode n
+#define ImakeIndir \indir
+#define ImakeSubCmdHelper \imake -I$(IRULESRC) $(IMAKE_DEFINES)
+#define Fontc \bdftopcf
+#define MkFontDir \mkfontdir
+#define XkbComp \xkbcomp
+#else
+#define ImakeHelper imakesvc
+#define IMmode u
+#define ImakeIndir indir
+#define ImakeSubCmdHelper $(IMAKE_CMD)
+#define Fontc bdftopcf
+#define MkFontDir mkfontdir
+#define XkbComp xkbcomp
+#endif
+
+#define echo ImakeHelper 8 
+#define RunProgram(progvar,options) $(subst /,\,$(progvar)) options
+#define RemoveFile(file) $(RM) file
+#define RemoveFiles(files) $(RM) files
+#define NeedLdLibraryPathForXkbComp NO
+
+#define LibObjCompile(dir,options) RemoveFiles($@ dir\$@)              @@\
+       $(CC) $(CCOPTIONS) $(ALLDEFINES) options -c  $*.c               @@\
+       $(MV) $@ dir\$@
+
+#define MakeDir(dir) $(MKDIRHIER) dir
+
+#define BuildIncludesTop(srclist)                                      @@\
+includes:: srclist                                                     @@\
+       MakeDir($(BUILDINCDIR))                                         @@\
+       @for %i in (srclist) do ImakeHelper 2 $(BUILDINCDIR) $(BUILDINCTOP) $(CURRENT_DIR) %i
+
+#define        ProgramTargetHelper(program,srcs,objs,deplib,locallib,syslib)   @@\
+ProgramTargetName(program): $(objs)                                    @@\
+       RemoveTargetProgram($@)                                         @@\
+       LinkRule($@,$(LDOPTIONS),$(objs),locallib $(LDLIBS) syslib)     @@\
+                                                                       @@\
+InstallProgram(program,$(BINDIR))                                      @@\
+InstallManPage(program,$(MANDIR))
+
+#if 0
+#define        ProgramTargetHelperNoMan(program,srcs,objs,deplib,locallib,syslib)      @@\
+ProgramTargetName(program): $(objs)                                    @@\
+       RemoveTargetProgram($@)                                         @@\
+       LinkRule($@,$(LDOPTIONS),$(objs),locallib $(LDLIBS) syslib)     @@\
+                                                                       @@\
+InstallProgram(program,$(BINDIR))
+#endif
+
+
+#define BuildIncludes(srclist,dstsubdir,dstupdir)                      @@\
+includes:: srclist                                                     @@\
+       MakeDir($(BUILDINCDIR)/dstsubdir)                               @@\
+       @for %i in (srclist) do ImakeHelper 3 $(BUILDINCTOP)/dstupdir/$(CURRENT_DIR) $(BUILDINCDIR)/dstsubdir %i
+
+#define LinkFileList(step,list,dir,sub)                                        @@\
+step::  list                                                           @@\
+       @for %i in (list) do ImakeHelper 3 sub dir %i
+
+#define ComplexProgramTarget(program)                                  @@\
+PROGRAM = ProgramTargetName(program)                                   @@\
+                                                                       @@\
+AllTarget(ProgramTargetName(program))                                  @@\
+                                                                       @@\
+ProgramTargetHelper(program,SRCS,OBJS,DEPLIBS,$(LOCAL_LIBRARIES),NullParameter) @@\
+                                                                       @@\
+DependTarget()                                                         @@\
+LintTarget()                                                           @@\
+                                                                       @@\
+clean::                                                                        @@\
+       RemoveFile($(PROGRAM))
+
+#define ComplexProgramTarget_1(program,locallib,syslib)                        @@\
+OBJS = $(OBJS1) $(OBJS2) $(OBJS3)                                      @@\
+SRCS = $(SRCS1) $(SRCS2) $(SRCS3)                                      @@\
+PROGRAM1 = ProgramTargetName(program)                                  @@\
+                                                                       @@\
+AllTarget($(PROGRAM1) $(PROGRAM2) $(PROGRAM3))                         @@\
+                                                                       @@\
+ProgramTargetHelper(program,SRCS1,OBJS1,DEPLIBS1,locallib,syslib)      @@\
+                                                                       @@\
+DependTarget()                                                         @@\
+LintTarget()                                                           @@\
+                                                                       @@\
+clean::                                                                        @@\
+       RemoveFiles($(PROGRAMS))
+
+#define ComplexProgramTarget_2(program,locallib,syslib)                        @@\
+PROGRAM2 = ProgramTargetName(program)                                  @@\
+                                                                       @@\
+ProgramTargetHelper(program,SRCS2,OBJS2,DEPLIBS2,locallib,syslib)
+
+#define ComplexProgramTarget_3(program,locallib,syslib)                        @@\
+PROGRAM3 = ProgramTargetName(program)                                  @@\
+                                                                       @@\
+ProgramTargetHelper(program,SRCS3,OBJS3,DEPLIBS3,locallib,syslib)
+
+#define NormalProgramTarget(program,objects,deplibs,locallibs,syslibs) @@\
+ProgramTargetName(program): objects                                    @@\
+       RemoveTargetProgram($@)                                         @@\
+       LinkRule($@,$(LDOPTIONS),objects,locallibs $(LDLIBS) syslibs)   @@\
+                                                                       @@\
+clean::                                                                        @@\
+       RemoveFile(ProgramTargetName(program))
+
+#if 0
+#define ComplexProgramTargetNoMan(program)                             @@\
+PROGRAM = ProgramTargetName(program)                                   @@\
+                                                                       @@\
+AllTarget(ProgramTargetName(program))                                  @@\
+                                                                       @@\
+ProgramTargetHelperNoMan(program,SRCS,OBJS,DEPLIBS,$(LOCAL_LIBRARIES),NullParameter) @@\
+                                                                       @@\
+DependTarget()                                                         @@\
+LintTarget()                                                           @@\
+                                                                       @@\
+clean::                                                                        @@\
+       RemoveFile($(PROGRAM))
+#endif
+
+#define MoveToBakFile(file) ImakeHelper 5 file
+
+#define RMoveToBakFile(file) ImakeHelper 6 file
+
+#define InstallMultipleDestFlags(step,list,dest,flags)                 @@\
+step:: list                                                            @@\
+       MakeDir($(DESTDIR)dest)                                                 @@\
+       $(INSTALL) $(INSTALLFLAGS) flags list $(subst /,\,$(DESTDIR)dest)
+
+#define        CleanTarget()                                                   @@\
+clean::                                                                        @@\
+       RemoveFiles(FilesToClean ExtraFilesToClean)
+
+#define LinkSourceFile(src,dir)                                                @@\
+src:                                                                   @@\
+       ImakeHelper 3 dir . src                                         @@\
+                                                                       @@\
+includes:: src                                                         @@\
+                                                                       @@\
+depends:: src                                                          @@\
+                                                                       @@\
+clean::                                                                        @@\
+       RemoveFile(src)
+
+#define LinkFile(tofile,fromfile)                                      @@\
+tofile:: fromfile                                                      @@\
+       ImakeHelper 7 fromfile tofile                                   @@\
+                                                                       @@\
+includes:: tofile                                                      @@\
+                                                                       @@\
+depend:: tofile                                                                @@\
+                                                                       @@\
+clean::                                                                        @@\
+       RemoveFile(tofile)
+
+#ifndef UseInstalled
+#define ImakeDependency(target)                                                @@\
+target:: ProgramTargetName($(IMAKE))                                   @@\
+                                                                       @@\
+ProgramTargetName($(IMAKE)):                                           @@\
+       @ImakeIndir $(IMAKESRC) if exist Makefile $(MAKE) SHELL= MAKE=x11make all               @@\
+       @ImakeIndir $(IMAKESRC) if not exist Makefile $(MAKE) SHELL= MAKE=x11make -f Makefile.ini BOOTSTRAPCFLAGS="$(BOOTSTRAPCFLAGS)"
+#endif
+
+#ifndef UseInstalled
+#define DependDependency()                                             @@\
+depend:: ProgramTargetName($(DEPEND))                                  @@\
+                                                                       @@\
+ProgramTargetName($(DEPEND)):                                          @@\
+       @ImakeIndir $(DEPENDSRC) $(MAKE) SHELL= MAKE=x11make 
+#endif
+
+#define        DependTarget()                                                  @@\
+DependDependency()                                                     @@\
+                                                                       @@\
+depend::                                                               @@\
+       $(subst /,\,$(DEPEND)) $(DEPENDFLAGS) -- $(ALLDEFINES) $(DEPEND_DEFINES) -- $(SRCS)
+
+#define        DependTarget3(srcs1,srcs2,srcs3)                                @@\
+DependDependency()                                                     @@\
+
+/* Currently this stuff doesn't work correctly for libX11
+depend::                                                               @@\
+       $(subst /,\,$(DEPEND)) $(DEPENDFLAGS) -- $(ALLDEFINES) $(DEPEND_DEFINES) -- srcs1 @@\
+       $(subst /,\,$(DEPEND)) $(DEPENDFLAGS) -- $(ALLDEFINES) $(DEPEND_DEFINES) -- srcs2 @@\
+       $(subst /,\,$(DEPEND)) $(DEPENDFLAGS) -- $(ALLDEFINES) $(DEPEND_DEFINES) -- srcs3
+*/
+
+#define ForceSubdirs(dirs)                                             @@\
+dirs: DONE                                                             @@\
+                                                                       @@\
+DONE:                                                                  @@\
+       @for %i in (dirs) do ImakeIndir %i $(MAKE) SHELL= MAKE=x11make $(MFLAGS) PassCDebugFlags all @@\
+       touch DONE                                                      @@\
+                                                                       @@\
+clean::                                                                        @@\
+       RemoveFile(DONE)
+
+#define MakeMakeSubdirs(dirs,target)                                   @@\
+MMSDIRS = dirs                                                         @@\
+MMSTOP = $(TOP)                                                                @@\
+MMSRULES = $(IRULESRC)                                                 @@\
+MMSCUR = $(CURRENT_DIR)                                                        @@\
+target::                                                               @@\
+       @for %i in ($(subst /,\,$(MMSDIRS))) do ImakeHelper 1 IMmode %i $(MMSRULES) $(MMSTOP) $(MMSCUR)
+
+#define NamedTargetSubdirs(name,dirs,verb,flags,subname)               @@\
+Concat(SUBST,name) = dirs                                              @@\
+name::                                                                 @@\
+       @for %i in ($(subst /,\,$(Concat(SUBST,name)))) do ImakeIndir %i $(MAKE) SHELL= MAKE=x11make $(MFLAGS) flags subname
+
+#define InstallNamedTarget(step,srcname,flags,dest,dstname)            @@\
+step:: srcname                                                         @@\
+       MakeDir($(DESTDIR)dest)                                         @@\
+       $(INSTALL) $(INSTALLFLAGS) flags srcname $(subst \,/,$(DESTDIR)dest)/dstname
+
+#define        BuildMakefileTarget(notused,imakeflags)                         @@\
+ImakeDependency(Makefile)                                              @@\
+                                                                       @@\
+Makefile::                                                             @@\
+       RMoveToBakFile(Makefile)                                        @@\
+       ImakeSubCmdHelper -DTOPDIR=$(TOP) -DCURDIR=$(CURRENT_DIR) imakeflags
+
+#define AssembleObject(flags) $(RM) $@                                  @@\
+       $(CPP) AsmDefines $(DEFINES) $(INCLUDES) flags $*.s | \         @@\
+           grep -v '^\#' > _tmp_.s                                     @@\
+       $(CC) $(CFLAGS) -o $*.Osuf -c _tmp_.s                           @@\
+       $(RM) _tmp_.s
+
+#define NormalAsmObjectRule()                                           @@\
+.s.Osuf:                                                                @@\
+       AssembleObject($(_NOOP_))
+
+#define ObjectMapIncludeFromSpecialSource(dst,src,flags)               @@\
+dst.c: src.c                                                           @@\
+       ImakeHelper 9 $@ mfbmap.h $?                                    @@\
+                                                                       @@\
+SpecialCObjectRule(dst,NullParameter,flags)                            @@\
+                                                                       @@\
+depend:: dst.c                                                         @@\
+                                                                       @@\
+clean::                                                                        @@\
+       RemoveFile(dst.c)
+
+#define FontBaseObj(basename)basename.pcf
+/*
+ * UncompressedFontTarget
+ */
+#define UncompressedFontTarget(basename)                               @@\
+FontBaseObj(basename):  FontSrc(basename)                              @@\
+       Fontc $(FONTCFLAGS) $? -o $@
+
+/*
+ * CompressedFontTarget
+ */
+#ifndef CompressedFontTarget
+#if GzipFontCompression
+#define CompressedFontTarget(basename)                                 @@\
+FontBaseObj(basename).gz:  FontSrc(basename)                           @@\
+       Fontc $(FONTCFLAGS) $? | $(GZIPCMD) > $@
+#else
+#define CompressedFontTarget(basename)                                 @@\
+FontBaseObj(basename).Z:  FontSrc(basename)                            @@\
+       Fontc $(FONTCFLAGS) $? | $(COMPRESS) > $@
+#endif
+#endif
+
+/*
+ * MakeFontsDir - generate rules to build fonts.dir database.
+ */
+#define MakeFontsDir(deplist)                                          @@\
+all:: fonts.dir                                                                @@\
+                                                                       @@\
+fonts.dir:  deplist                                                    @@\
+       MkFontDir .                                                     @@\
+                                                                       @@\
+clean::                                                                        @@\
+       RemoveFile(fonts.dir)
+
+/* OS/2 scripts are based on REXX
+ * it is just the SHELL variable that is messed up that forces me to
+ * modify this rule
+ */
+#define ConfigTargetLong(target,dep,script,args,extra)                 @@\
+all:: Configure                                                                @@\
+                                                                       @@\
+Configure:: target.o                                                   @@\
+                                                                       @@\
+target.c: script dep                                                   @@\
+       $(MAKE) SHELL= MAKE=x11make $(MFLAGS) extra Concat(Build,target)                        @@\
+                                                                       @@\
+Concat(Build,target):                                                  @@\
+       $(RM) target.c                                                  @@\
+       script args                                                     @@\
+                                                                       @@\
+clean::                                                                        @@\
+       $(RM) target.c
+
+#ifndef ServerTargetWithFlags
+#define        ServerTargetWithFlags(server,subdirs,objects,libs,syslibs,flags) @@\
+AllTarget(ProgramTargetName(server))                                   @@\
+ProgramTargetName(server): subdirs objects libs                                @@\
+       MoveToBakFile($@)                                               @@\
+       LinkRule($@,$(LDOPTIONS),objects,libs $(LDLIBS) syslibs)        @@\
+       emxbind -a ProgramTargetName(server) -h255                      @@\
+                                                                       @@\
+Concat(load,server):                                                   @@\
+       MoveToBakFile(ProgramTargetName(server))                        @@\
+       LinkRule(ProgramTargetName(server),$(LDOPTIONS),objects,libs $(LDLIBS) syslibs) @@\
+                                                                       @@\
+loadX:: Concat(load,server)                                            @@\
+                                                                       @@\
+SentinelProgramTarget(server,subdirs objects libs,objects libs $(LDLIBS) syslibs) @@\
+SentinelLinkTarget(Concat(load,server),server,objects libs $(LDLIBS) syslibs) @@\
+PurifyProgramTarget(server,subdirs objects libs,objects libs $(LDLIBS) syslibs) @@\
+PurifyLinkTarget(Concat(load,server),server,objects libs $(LDLIBS) syslibs) @@\
+ProofProgramTarget(server,subdirs objects libs,objects libs $(LDLIBS) syslibs) @@\
+ProofLinkTarget(Concat(load,server),server,objects libs $(LDLIBS) syslibs) @@\
+                                                                       @@\
+InstallProgramWithFlags(server,$(BINDIR),flags)                                @@\
+                                                                       @@\
+clean::                                                                        @@\
+       RemoveFile(ProgramTargetName(server))
+#endif /* ServerTargetWithFlags */
+
+/*
+ * ServerTarget - rules to compile, link, and relink a normal server
+ * Need a .def file for OS/2
+ */
+#ifndef ServerTarget
+#define        ServerTarget(server,subdirs,objects,libs,syslibs)               @@\
+ServerTargetWithFlags(server,subdirs,objects,libs,syslibs server.def,$(_NOOP_)) @@\
+                                                                       @@\
+ProgramTargetName(server): server.def
+#endif /* ServerTarget */
+
+/*
+ * ToolkitMakeStrings generates a string-table, i.e., a C source
+ * file and the matching header(s), e.g., Xt's StringDefs.c, StringDefs.h,
+ * and Shell.h files; or Motif's XmStrDefs.c and XmStrDefs.h files.
+ *
+ * The 'files' argument is the list of files that will be produced by
+ * this rule, e.g., for Xt they would be "Shell.h StringDefs.c StringDefs.h"
+ * and for Motif they would be "XmStrDefs.c XmStrDefs.h".
+ *
+ * The 'source' argument is the string-list file to be parsed, e.g., in
+ * Xt that would be "util/string.list".  For Motif 2.0 it would be
+ * "../../tools/makestr/xmstring.list", and for Motif-CDE1 it would be
+ * "util/xmstring.list".
+ *
+ * The 'options' argument is passed by the library's Imakefile, see the
+ * Xt Imakefile for an example.  Typically this would be nothing, -intelabi,
+ * or -sparcabi; there are other choices, but these are typical.
+ *
+ * The 'depends' argument names additional files the target files
+ * depend on.  It should name the #ctmpl and #htmpl files from the
+ * 'source' file.
+ *
+ * The 'dest' argument is the C source output file.  For Xt this should
+ * be "StringDefs.c", and for all versions of Motif it would be "XmStrDefs.c"
+ *
+ * Headers are generated and named according to data in the 'source'
+ * file.
+ */
+
+#ifndef ToolkitMakeStrings
+#define ToolkitMakeStrings(files,source,options,depends,dest)          @@\
+MAKESTRS = $(CONFIGSRC)/util/makestrs                                  @@\
+MAKESTRS1 = /makestrs.exe                                              @@\
+                                                                       @@\
+ProgramTargetName($(MAKESTRS)): $(MAKESTRS).c                          @@\
+       ImakeIndir $(CONFIGSRC)/util make SHELL= ProgramTargetName(makestrs)    @@\
+       ImakeHelper 7 $(CONFIGSRC)/util/makestrs.exe /                  @@\
+                                                                       @@\
+files: ProgramTargetName($(MAKESTRS)) source depends                   @@\
+       RemoveFiles(files)                                              @@\
+       RunProgram(MAKESTRS1,options < source > dest)                   @@\
+                                                                       @@\
+AllTarget(files)                                                       @@\
+                                                                       @@\
+includes:: files                                                       @@\
+                                                                       @@\
+depend:: files                                                         @@\
+                                                                       @@\
+clean::                                                                        @@\
+       RemoveFiles(files)
+
+#endif /* ToolkitMakeStrings */
+
+/*#define CppSedMagic SedMagic*/
+#define CppSedMagic sed -e '/^#  *[0-9][0-9]*  *.*$$/d' -e 's/^XCOMM/#/g' -e 's/^XCOMM[^a-zA-Z0-9_]/#/g'
+
+#ifndef InstallNamedTargetNoClobber
+#define InstallNamedTargetNoClobber(step,srcname,flags,dest,dstname)   @@\
+step:: srcname                                                         @@\
+       MakeDir($(DESTDIR)dest)                                         @@\
+       if not exist $(subst /,\,$(DESTDIR)dest)\dstname $(INSTALL) $(INSTALLFLAGS) flags srcname $(DESTDIR)dest/dstname
+
+#endif /* InstallNamedTargetNoClobber */
+
+#if CompressManPages
+
+#ifndef InstallManPageLong
+#define InstallManPageLong(file,destdir,dest)                           @@\
+install.man:: file.man                                                  @@\
+       MakeDir($(DESTDIR)destdir)                                      @@\
+       ImakeHelper 12 file $(DESTDIR)destdir dest
+#endif
+
+#ifndef InstallManPageAliases
+#define InstallManPageAliases(file,destdir,aliases)                     @@\
+install.man::                                                           @@\
+       MakeDir($(DESTDIR)destdir)                                      @@\
+       for %i in (aliases) do $(INSTALL) $(DESTDIR)destdir/file.gz $(DESTDIR)destdir/%i.gz
+#endif
+
+#ifndef InstallGenManPageLong
+#define InstallGenManPageLong(file,destdir,dest,suffix)                 @@\
+install.man:: file.man                                                  @@\
+       MakeDir($(DESTDIR)destdir)                                      @@\
+       ImakeHelper 12 file $(DESTDIR)destdir dest
+#endif
+
+#ifndef InstallMultipleMan
+#define InstallMultipleMan(list,dest)                                   @@\
+install.man:: list                                                      @@\
+       MakeDir($(DESTDIR)dest)                                         @@\
+       for %i in (list) do ImakeHelper 12 %i $(DESTDIR)dest %i
+#endif
+
+#else /* CompressManPages */
+
+#ifndef InstallManPageLong
+#define InstallManPageLong(file,destdir,dest)                           @@\
+install.man:: file.man                                                  @@\
+       MakeDir($(DESTDIR)destdir)                                      @@\
+       ImakeHelper 10 file $(DESTDIR)destdir dest $(MANSUFFIX)
+#endif
+
+#ifndef InstallManPageAliases
+#define InstallManPageAliases(file,destdir,aliases)                     @@\
+install.man::                                                           @@\
+       MakeDir($(DESTDIR)destdir)                                      @@\
+       for %i in (aliases) do $(INSTALL) $(DESTDIR)destdir/file.$(MANSUFFIX) $(DESTDIR)destdir/%i.$(MANSUFFIX) 
+#endif
+
+#ifndef InstallGenManPageLong
+#define InstallGenManPageLong(file,destdir,dest,suffix)                 @@\
+install.man:: file.man                                                  @@\
+       MakeDir($(DESTDIR)destdir)                                      @@\
+       ImakeHelper 10 file $(DESTDIR)destdir dest suffix
+#endif
+
+#ifndef InstallMultipleMan
+#define InstallMultipleMan(list,dest)                                   @@\
+install.man:: list                                                      @@\
+       MakeDir($(DESTDIR)dest)                                         @@\
+       for %i in (list) do ImakeHelper 10 %i $(DESTDIR)dest %i $(MANSUFFIX)
+#endif
+
+#endif
+
+#ifndef NormalLintTarget
+#define NormalLintTarget(srclist)
+#endif /* NormalLintTarget */
+
+#ifndef MakeDirectories
+#define MakeDirectories(step,dirs)                                     @@\
+step::                                                                 @@\
+       -for %i in (dirs) do $(MKDIRHIER) $(DESTDIR)%i
+#endif /* MakeDirectories */
+
+#ifndef YaccFile
+#define YaccFile(file,flags)                                           @@\
+depend:: file.c                                                                @@\
+                                                                       @@\
+file.h file.c: file.y                                                  @@\
+       $(YACC) flags file.y                                            @@\
+       $(MV) y.tab.c file.c                                            @@\
+       @if exist y.tab.h $(MV) y.tab.h file.h                          @@\
+                                                                       @@\
+clean::                                                                        @@\
+       RemoveFiles(y.tab.c y.tab.h file.h file.c)
+#endif /* YaccFile */
+
+#ifndef StaticLibrary
+#define StaticLibrary(libpath,libname) Concat4(libpath,/,libname,_s.a)
+#endif
+
+#ifndef MakeXkbDir
+#define MakeXkbDir(basedir,subdir)                                     @@\
+all::  Concat(subdir,.dir)                                             @@\
+                                                                       @@\
+Concat(subdir,.dir):                                                   @@\
+       $(XKBCOMPCMD) -lfhlpR -o Concat(subdir,.dir) *                  @@\
+                                                                       @@\
+InstallTarget(install,Concat(subdir,.dir),$(INSTDATFLAGS),basedir)
+#endif
+
+/* This is to replace an ugly hack in /xc/nls/XLC_LOCALE */
+/* the corresponding Imake.rules rule would be:
+   define LinkFileSpecial(gotodir,tofile,fromfile)     @@\
+        @MakeFlagsToShellFlags(i,set +e); \            @@\
+       cd dir && (set -x; RemoveFile(tofile); $(LN) fromfile tofile)
+ */
+#ifndef LinkFileSpecial
+#define LinkFileSpecial(gotodir,tofile,fromfile)                       @@\
+       ImakeHelper 13 gotodir fromfile tofile
+#endif
+
+#ifndef LinkBuildBinary
+#define LinkBuildBinary(binary)                                                @@\
+all:: $(BUILDBINDIR)/binary binary                                     @@\
+                                                                       @@\
+$(BUILDBINDIR)/binary: binary                                          @@\
+       ImakeHelper 13 $(BUILDBINDIR) $(BUILDBINTOP)/$(CURRENT_DIR)/binary binary @@\
+       $(CP) binary /
+#endif /* LinkBuildBinary */
diff --git a/Xserver/config/cf/os2Lib.rules b/Xserver/config/cf/os2Lib.rules
new file mode 100644 (file)
index 0000000..aa6e525
--- /dev/null
@@ -0,0 +1,244 @@
+XCOMM $XConsortium: os2Lib.rules /main/1 1996/10/31 14:47:29 kaleb $
+
+
+
+XCOMM $XFree86: xc/config/cf/os2Lib.rules,v 3.7 1997/01/27 06:12:49 dawes Exp $
+
+/*
+ * OS2/EMX shared library rules (DLL version)
+ */
+#ifndef __EMX__
+#error You must edit os2Lib.rules for your (non-EMX) OS/2 dev system
+#endif
+
+#ifndef HasSharedLibraries
+#define HasSharedLibraries YES
+#endif
+#ifndef ForceNormalLib
+#define ForceNormalLib NO
+#endif
+
+#define SharedOldX NO
+
+#ifndef SharedDataSeparation
+#define SharedDataSeparation NO
+#endif
+#ifndef SharedCodeDef
+#define SharedCodeDef /**/
+#endif
+#ifndef SharedLibraryDef
+#define SharedLibraryDef /**/
+#endif
+#ifndef ShLibIncludeFile
+#define ShLibIncludeFile <os2Lib.tmpl>
+#endif
+#ifndef SharedLibraryLoadFlags
+#define SharedLibraryLoadFlags /**/
+#endif
+#ifndef PositionIndependentCFlags
+#define PositionIndependentCFlags -Zdll -Zomf -Zmtd
+#endif
+
+#ifndef NormalSharedLibObjCompile
+#define NormalSharedLibObjCompile(options) $(RM) $@                        @@\
+       $(CC) -c $(CFLAGS) options $(SHLIBDEF) $(SHAREDCODEDEF) $(PICFLAGS) $*.c @@\
+       touch $*.o
+#endif
+
+#ifndef InstallSharedLibrary
+#ifdef BuildImplibs
+#define InstallSharedLibrary(libname,rev,dest)                         @@\
+install:: libname.dll libname.a        libname.lib                             @@\
+       MakeDir($(DESTDIR)dest)                                         @@\
+       $(INSTALL) -c $(INSTLIBFLAGS) libname.dll $(DESTDIR)dest        @@\
+       $(INSTALL) -c $(INSTLIBFLAGS) libname.a $(DESTDIR)dest          @@\
+       $(INSTALL) -c $(INSTLIBFLAGS) libname.lib $(DESTDIR)dest
+#else
+#define InstallSharedLibrary(libname,rev,dest)                         @@\
+install:: libname.dll libname.a                                                @@\
+       MakeDir($(DESTDIR)dest)                                         @@\
+       $(INSTALL) -c $(INSTLIBFLAGS) libname.a $(DESTDIR)dest          @@\
+       $(INSTALL) -c $(INSTLIBFLAGS) libname.dll $(DESTDIR)dest
+#endif
+#endif /* InstallSharedLibrary */
+
+/*#ifdef UseInstalled
+#define LinkBuildLibrary(lib) $(_NULLCMD_)
+#else*/
+#define LinkBuildLibrary(lib) MakeDir($(BUILDLIBDIR))                  @@\
+       RemoveFile($(BUILDLIBDIR)/lib)                                  @@\
+       ImakeIndir $(BUILDLIBDIR) $(LN) $(BUILDINCTOP)/$(CURRENT_DIR)/lib .
+/*#endif*/
+
+        EMXIMP = emximp
+        EMXOMF = emxomf
+          SHLD = gcc -Zomf -Zdll -Zmtd
+     SHADDLIBS = -lbsd -lsocket -lc_import
+#ifndef BuildDllSupportLibs
+/*#ifdef UseInstalled
+#define BuildDllSupportLibs(slib) $(_NULLCMD_)
+#else*/
+#define BuildDllSupportLibs(slib)                                      @@\
+       $(EMXIMP) -o slib.imp slib.def                                  @@\
+       $(EMXIMP) -o slib.a slib.imp                                    @@\
+       $(EMXOMF) -s -l slib.a                                          @@\
+       LinkBuildLibrary(slib.a)                                        @@\
+       LinkBuildLibrary(slib.lib)
+/*#endif*/
+#endif
+
+#ifndef BuildDllSupportLibs2
+/*#ifdef UseInstalled
+#define BuildDllSupportLibs2(slib) $(_NULLCMD_)
+#else*/
+#define BuildDllSupportLibs2(slib)                                     @@\
+       $(EMXIMP) -o slib.imp Concat3(slib,os2,.def)                    @@\
+       $(EMXIMP) -o slib.a slib.imp                                    @@\
+       $(EMXOMF) -s -l slib.a                                          @@\
+       LinkBuildLibrary(slib.a)                                        @@\
+       LinkBuildLibrary(slib.lib)
+/*#endif*/
+#endif
+
+#ifndef BuildLibSupportLibs
+/*#ifdef UseInstalled
+#define BuildLibSupportLibs(slib) $(_NULLCMD_)
+#else*/
+#define BuildLibSupportLibs(slib)                                      @@\
+       $(EMXOMF) -s -l slib.a                                          @@\
+       LinkBuildLibrary(slib.a)                                        @@\
+       LinkBuildLibrary(slib.lib)
+/*#endif*/
+#endif
+
+#ifndef SharedLibraryTarget
+#define SharedLibraryTarget(libname,rev,solist,down,up)                        @@\
+AllTarget(libname.dll)                                                 @@\
+.SUFFIXES: .obj .rsp .def                                              @@\
+        LBRPATH = $(subst /,\,$(LIBRARY_PATH))                         @@\
+        LBRDEF = Concat3(libname,os2,.def)                             @@\
+       LBRCPPDEF = Concat3(libname,os2,-def.cpp)                       @@\
+       LBRRSP = Concat3(libname,os2,.rsp)                              @@\
+                                                                       @@\
+link.rsp: $(LBRRSP) $(LBRDEF)                                          @@\
+       @echo $(LBRPATH)"\\dll0.obj+" >link.rsp                         @@\
+       @cat $(LBRRSP) >>link.rsp                                       @@\
+       @echo $(LBRPATH)\\mt\\ $(LBRPATH)\\ $(REQUIREDLIBS) bsd socket c_alias c_static c_import os2 emx2 end >>link.rsp        @@\
+       @echo $(LBRDEF) >>link.rsp                                      @@\
+                                                                       @@\
+libname.dll:  $(OBJS) link.rsp                                         @@\
+       link386 @link.rsp >nul                                          @@\
+       BuildDllSupportLibs2(libname)                                   @@\
+       LinkBuildLibrary(libname.dll)                                   @@\
+                                                                       @@\
+clean::                                                                        @@\
+       $(RM) libname.lib libname.imp *.obj link.rsp
+#endif /* SharedLibraryTarget */
+
+#ifndef NormalLibraryTarget
+#define        NormalLibraryTarget(libname,objlist)                            @@\
+AllTarget(LibraryTargetName(libname))                                  @@\
+                                                                       @@\
+LibraryTargetName(libname): objlist                                    @@\
+       RemoveFile($@)                                                  @@\
+       MakeLibrary($@,objlist)                                         @@\
+       RanLibrary($@)                                                  @@\
+       BuildLibSupportLibs($*)
+#endif /* NormalLibraryTarget */
+
+#ifndef NormalDepLibraryTarget
+#define        NormalDepLibraryTarget(libname,deplist,objlist)                 @@\
+AllTarget(LibraryTargetName(libname))                                  @@\
+                                                                       @@\
+LibraryTargetName(libname): deplist                                    @@\
+       RemoveFile($@)                                                  @@\
+       MakeLibrary($@,objlist)                                         @@\
+       RanLibrary($@)                                                  @@\
+       BuildLibSupportLibs($*)
+#endif /* NormalDepLibraryTarget */
+
+#ifndef SharedLibraryDataTarget
+#define SharedLibraryDataTarget(libname,rev,salist)
+#endif /* SharedLibraryDataTarget */
+
+#ifndef InstallSharedLibraryData
+#define InstallSharedLibraryData(libname,rev,dest)
+#endif /* InstallSharedLibraryData */
+
+#ifndef InstallLibrary
+#define        InstallLibrary(libname,dest)                                    @@\
+install:: LibraryTargetName(libname)                                   @@\
+       MakeDir($(DESTDIR)dest)                                         @@\
+       $(INSTALL) $(INSTALLFLAGS) $(INSTLIBFLAGS) LibraryTargetName(libname) $(DESTDIR)dest @@\
+       $(INSTALL) $(INSTALLFLAGS) $(INSTLIBFLAGS) Concat(libname,.lib) $(DESTDIR)dest @@\
+       RanLibrary($(RANLIBINSTFLAGS) $(DESTDIR)dest/LibraryTargetName(libname))
+#endif /* InstallLibrary */
+
+#ifndef LibMkdir
+#define LibMkdir(dir) ImakeHelper 11 dir
+#endif
+
+#ifndef LibCleanDir
+#define LibCleanDir(dir)                                               @@\
+       ImakeIndir dir call RemoveFiles(*.Osuf)
+#endif
+
+#define MakeStaticLibrary(libname) $(AR) libname *.o
+
+#ifndef UnsharedLibraryTarget
+#define        UnsharedLibraryTarget(libname,objlist,down,up)                  @@\
+AllTarget(LibraryTargetName(Concat(libname,_s)))                       @@\
+                                                                       @@\
+LibraryTargetName(Concat(libname,_s)): objlist                         @@\
+       RemoveFile($@)                                                  @@\
+       ImakeIndir down MakeStaticLibrary(up/$@)                        @@\
+       RanLibrary($@)                                                  @@\
+       _LinkBuildLibrary($@)                                           @@\
+                                                                       @@\
+install::      LibraryTargetName(Concat(libname,_s))                   @@\
+       $(INSTALL) $(INSTALLFLAGS) $(INSTLIBFLAGS) LibraryTargetName(Concat(libname,_s)) $(DESTDIR)$(SHLIBDIR)
+#endif
+
+#ifndef UnsharedLibraryTarget3
+#define        UnsharedLibraryTarget3(libname,objlist1,objlist2,objlist3,down,up) @@\
+AllTarget(LibraryTargetName(Concat(libname,_s)))                       @@\
+                                                                       @@\
+LibraryTargetName(Concat(libname,_s)): objlist1 objlist2 objlist3      @@\
+       RemoveFile($@)                                                  @@\
+       ImakeIndir down MakeStaticLibrary(up/$@)                        @@\
+       RanLibrary($@)                                                  @@\
+       _LinkBuildLibrary($@)                                           @@\
+                                                                       @@\
+install::      LibraryTargetName(Concat(libname,_s))                   @@\
+       $(INSTALL) $(INSTALLFLAGS) $(INSTLIBFLAGS) LibraryTargetName(Concat(libname,_s)) $(DESTDIR)$(SHLIBDIR)
+#endif /* UnsharedLibraryTarget3 */
+
+/*
+ * DebuggedLibraryTarget - generate rules to create a debuggable library.
+ */
+#ifndef DebuggedLibraryTarget
+#define        DebuggedLibraryTarget(libname,objlist)                          @@\
+AllTarget(LibraryTargetNameSuffix(libname,_d))                         @@\
+                                                                       @@\
+LibraryTargetNameSuffix(libname,_d): objlist $(EXTRALIBRARYDEPS)       @@\
+       RemoveFile($@)                                                  @@\
+       ImakeIndir debugger MakeStaticLibrary(../$@)                    @@\
+       RanLibrary($@)                                                  @@\
+       _LinkBuildLibrary($@)
+
+#endif /* DebuggedLibraryTarget */
+
+/*
+ * ProfiledLibraryTarget - generate rules to create a profiled library.
+ */
+#ifndef ProfiledLibraryTarget
+#define        ProfiledLibraryTarget(libname,objlist)                          @@\
+AllTarget(LibraryTargetNameSuffix(libname,_p))                         @@\
+                                                                       @@\
+LibraryTargetNameSuffix(libname,_p): objlist $(EXTRALIBRARYDEPS)       @@\
+       RemoveFile($@)                                                  @@\
+       ImakeIndir profiled MakeStaticLibrary(../$@)                    @@\
+       RanLibrary($@)                                                  @@\
+       _LinkBuildLibrary($@)
+
+#endif /* ProfiledLibraryTarget */
diff --git a/Xserver/config/cf/os2Lib.tmpl b/Xserver/config/cf/os2Lib.tmpl
new file mode 100644 (file)
index 0000000..d4d4ed4
--- /dev/null
@@ -0,0 +1,119 @@
+XCOMM $XConsortium: os2Lib.tmpl /main/1 1996/10/31 14:47:31 kaleb $
+
+
+
+XCOMM $XFree86: xc/config/cf/os2Lib.tmpl,v 3.5 1997/01/05 11:49:40 dawes Exp $
+
+/*
+ * OS2/EMX shared library template
+ */
+#ifndef __EMX__
+#error You must edit os2Lib.tmpl for your (non-EMX) OS/2 dev system
+#endif
+
+/* note these are special because of linking with link386 */
+#ifdef NOT_EMX
+#define SharedXtReqs $(LDPRELIB) $(XLIBONLY)
+#define SharedXawReqs $(LDPRELIB) $(XMULIB) $(XTOOLLIB) $(XLIB)
+#define SharedXmuReqs $(LDPRELIB) $(XTOOLLIB) $(XLIB)
+#define SharedSMReqs $(LDPRELIB) $(ICELIB)
+#define SharedXextReqs $(LDPRELIB) $(XLIBONLY)
+#define SharedXiReqs $(LDPRELIB) $(XLIB)
+#define SharedXieReqs $(LDPRELIB) $(XLIB)
+#define SharedXtstReqs $(LDPRELIB) $(XLIB)
+#define SharedOldXReqs $(LDPRELIB) $(XLIBONLY)
+#define SharedPexReqs $(LDPRELIB) $(XLIBONLY) MathLibrary
+#define SharedXpReqs $(LDPRELIBS) $(XLIB)
+#else
+#define SharedXtReqs ..\\..\\exports\\lib\\ ICE SM X11
+#define SharedXawReqs ..\\..\\exports\\lib\\ Xmu Xt X11 Xext
+#define SharedXmuReqs ..\\..\\exports\\lib\\ Xt X11 Xext
+#define SharedSMReqs ..\\..\\exports\\lib\\ ICE
+#define SharedXextReqs ..\\..\\exports\\lib\\ X11
+#define SharedXiReqs ..\\..\\exports\\lib\\ X11 Xext
+#define SharedXieReqs ..\\..\\exports\\lib\\ X11 Xext
+#define SharedXtstReqs ..\\..\\exports\\lib\\ X11 Xext
+#define SharedOldXReqs ..\\..\\exports\\lib\\ X11 Xext
+#define SharedPexReqs ..\\..\\exports\\lib\\ X11 m
+#define SharedXpReqs ..\\..\\exports\\lib\\ X11 Xext
+#endif
+
+/*
+ * By setting this in your Imakefile, you can force using static libraries
+ * to be linked with you app, rather than DLLs
+ */
+#ifndef LinkStatically
+#define LinkStatically NO
+#endif
+
+#if LinkStatically
+#define SDlibX11 -lX11_s
+#define SDlibXExt -lXExt_s
+#define SDlibXmu -lXmu_s
+#define SDlibXt -lXt_s
+#define SDlibXaw -lXaw_s
+#define SDlibXi -lXi_s
+#define SDlibXIE -lXIE_s
+#define SDlibXtst -lXtst_s
+#define SDlibPEX5 -lPEX5_s
+#define SDlibXp -lXp_s
+#else
+#define SDlibX11 -lX11
+#define SDlibXExt -lXExt
+#define SDlibXmu -lXmu
+#define SDlibXt -lXt
+#define SDlibXaw -lXaw
+#define SDlibXi -lXi
+#define SDlibXIE -lXIE
+#define SDlibXtst -lXtst
+#define SDlibPEX5 -lPEX5
+#define SDlibXp -lXp
+#endif
+
+/*
+ * and now a little bit of magic for using imake without source tree; if we
+ * are using shared libraries, we really do not need to depend on anything
+ */
+#if SharedLibXext
+ DEPEXTENSIONLIB = 
+    EXTENSIONLIB = _Use(SDlibXExt,-L$(EXTENSIONSRC)/lib SDlibXExt)
+#endif
+#if SharedLibX11
+         DEPXLIB = 
+            XLIB = $(EXTENSIONLIB) _Use(SDlibX11,-L$(XLIBSRC) SDlibX11)
+#endif
+#if SharedLibXmu
+       DEPXMULIB = 
+          XMULIB = _Use(SDlibXmu,-L$(XMUSRC) SDlibXmu) $(XLIB)
+#ifndef XawClientLibs
+#define XawClientLibs $(XAWLIB) $(XMULIB) $(XTOOLLIB) $(XLIB)
+#endif
+#endif
+#if SharedOldX
+      DEPOLDXLIB = 
+         OLDXLIB = _Use(-loldX,-L$(OLDXLIBSRC) -loldX)
+#endif
+#if SharedLibXt
+     DEPXTOOLLIB = 
+        XTOOLLIB = _Use(SDlibXt,-L$(TOOLKITSRC) SDlibXt)
+#endif
+#if SharedLibXaw
+       DEPXAWLIB = 
+          XAWLIB = _Use(SDlibXaw,-L$(AWIDGETSRC) SDlibXaw)
+#endif
+#if SharedLibXi
+        DEPXILIB = 
+           XILIB = _Use(SDlibXi,-L$(XILIBSRC) SDlibXi)
+#endif
+#if SharedLibXTest
+    DEPXTESTLIB = 
+       XTESTLIB = _Use(SDlibXtst,-L$(EXTENSIONSRC)/lib/xtest SDlibXtst)
+#endif
+#if SharedLibPex
+      DEPPEXLIB = 
+         PEXLIB = _Use(SDlibPEX5,-L$(PEXLIBSRC) SDlibPEX5)
+#endif
+#if SharedLibXp
+ DEPEXTENSIONLIB = 
+    EXTENSIONLIB = _Use(SDlibXp,-L$(EXTENSIONSRC)/lib SDlibXp)
+#endif
diff --git a/Xserver/config/cf/osf1.cf b/Xserver/config/cf/osf1.cf
new file mode 100644 (file)
index 0000000..f976df7
--- /dev/null
@@ -0,0 +1,206 @@
+XCOMM platform:  $TOG: osf1.cf /main/74 1997/05/27 15:51:24 kaleb $
+/* only tested with Digital OSF/1 */
+
+#ifndef OSName
+# define OSName                DefaultOSName
+#endif
+#ifndef OSMajorVersion
+# define OSMajorVersion        DefaultOSMajorVersion
+#endif
+#ifndef OSMinorVersion
+# define OSMinorVersion DefaultOSMinorVersion
+#endif
+XCOMM operating system: OSName (OSMajorVersion.OSMinorVersion)
+
+#define StandardCppDefines     -D__osf__ StandardDefines
+#define BuildLibPathVar                _RLD_ROOT=/dev/null LD_LIBRARY_PATH
+#define HasPutenv              YES
+#define Malloc0ReturnsNull     YES
+#define HasNdbm                        YES
+#define HasShm                 YES
+#define AvoidNullMakeCommand   YES
+#define NullMakeCommand                @ echo
+#define HasPosixThreads                YES
+#define SystemMTDefines                -D_REENTRANT
+#define CplusplusSystemMTDefines -D_REENTRANT
+#define HasPoll                        YES
+#define HasVFork                NO
+#define HasPlugin              YES
+#define InstallCmd             installbsd
+#define RanlibCmd              ranlib -t
+#if OSMajorVersion > 1 || OSMinorVersion > 0
+#define ModernOSF1             YES
+#else
+#define ModernOSF1             NO
+#define ShLibDir               /usr/shlib
+#define SharedLibPex           NO  /* losing, no shared -lm */
+#endif
+#define ThreadedX              ModernOSF1
+
+#if ThreadedX
+#define MTSafeAPIDefines       -DXUSE_MTSAFE_API -DXUSE_NETDB_R_API
+#if OSMajorVersion < 4
+#define ThreadsLibraries               -lpthreads -lmach -lc_r
+#define ThreadsCplusplusLibraries      -lpthreads -lmach
+#define ThreadPreStdAPIDefines         -DXPRE_STANDARD_API
+#else
+#define ThreadsLibraries               -lpthread -lmach -lexc -lc
+#define ThreadsCplusplusLibraries      -lpthread -lmach -lexc
+#define LibraryMTDefines               -DUSE_TIS_SUPPORT
+#endif
+#endif
+
+#if ModernOSF1
+#ifndef OptimizedCDebugFlags
+#define OptimizedCDebugFlags   -O2 -Olimit 2000
+#endif
+#ifndef ExtraLoadFlags
+/*
+ * In OSF/1 3.0 Digital has shared libXdmcp and libXau. What's more,
+ * the link editor has different search semantics, i.e. it will search
+ * for shared libraries first, then, if it can't find a shared lib, it
+ * will use a static lib. By using -oldstyle_liblookup the linker will
+ * follow "normal" semantics for linking libraries and will get the
+ * static libraries we really want. By 3.2 they no longer have libXdmcp 
+ * and libXau as shared libraries and we can omit -oldstyle_liblookup. 
+ * (What did they have in 3.1?)
+ */
+#if OSMajorVersion == 3 && OSMinorVersion == 0
+#define ExtraLoadFlags         -Wl,-rpath,$(USRLIBDIRPATH),-oldstyle_liblookup
+#else
+#define ExtraLoadFlags                 -Wl,-rpath,$(USRLIBDIRPATH)
+#endif
+#endif
+#if OSMajorVersion > 3
+#define TermcapLibrary         -lcurses
+#endif
+#if OSMajorVersion >= 3
+#define HasMkstemp             YES
+#endif
+#endif
+
+/*
+ * C++ compiler setup.  This file knows what options to use with the
+ * DEC C++ compiler, and may learn about other compilers in the future.
+ * 
+ * For DEC C++, define HasDECCplusplus to YES in site.def.  
+ *
+ * For g++ 2.6.x, define HasGcc2ForCplusplus to YES in site.def.
+ *
+ * For other compilers, define HasCplusplus to YES in site.def, and 
+ *    check to see if you need to provide values for CplusplusOptions
+ *    and/or DefaultCplusplusOptions.
+ *
+ * In any case, you may also need to set CplusplusDependIncludes.
+ *
+ * Note: For DEC C++, the -call_shared option really only needs to 
+ * appear when linking C++ executables, not when actually compiling
+ * the C++ sources.  But since there's no imake variable that lets
+ * us insert flags only into the C++ link stage, we use -call_shared
+ * on all compilations when building executables.  This could be 
+ * considered a deficiency in the current imake configuration
+ */
+
+#if HasDECCplusplus
+#ifndef HasCplusplus 
+#define HasCplusplus YES
+#endif
+#ifndef CplusplusCmd
+#define CplusplusCmd /usr/bin/cxx
+#endif
+#ifndef CplusplusFilt
+# define CplusplusFilt /usr/bin/demangle
+#endif
+#ifndef CplusplusDependIncludes 
+#define CplusplusDependIncludes -D__DECCXX -I/usr/include/cxx
+#endif
+#ifndef CplusplusLibDir
+#define CplusplusLibDir /usr/lib/cmplrs/cxx
+#endif
+#ifndef CplusplusLibC
+#define CplusplusLibC -L/usr/lib/cmplrs/cxx -lcxx
+#endif
+#ifndef CplusplusOptions
+#define CplusplusOptions -call_shared
+#endif
+#endif /* HasDECCplusplus */
+
+
+#if HasGcc2ForCplusplus
+#ifndef CplusplusLibC
+#define CplusplusLibC `$(CXX) -print-libgcc-file-name`
+#endif 
+#endif /* HasGcc2ForCplusplus */
+
+#ifdef CplusplusLibDir
+# define SystemBuildLibPath    \
+/usr/shlib:/usr/ccs/lib:CplusplusLibDir:/usr/lib/cmplrs/cc:/usr/lib:/usr/local/lib:/var/shlib
+#else
+# define SystemBuildLibPath    \
+/usr/shlib:/usr/ccs/lib:/usr/lib/cmplrs/cc:/usr/lib:/usr/local/lib:/var/shlib
+#endif
+
+#include <osfLib.rules>
+#define NoRConst               YES
+
+#ifdef AlphaArchitecture
+#ifndef HasWChar32
+#define HasWChar32             YES
+#endif
+#define ServerExtraDefines     -D_XSERVER64
+#define ServerOSDefines                -DDDXTIME
+#ifndef DefaultCCOptions
+#define DefaultCCOptions       -std1
+#endif
+#ifndef XawI18nDefines
+#define XawI18nDefines         -DHAS_WCHAR_H
+#endif
+#ifndef BuildServer
+#define BuildServer            NO
+#endif
+
+/* For DtHelp's TIFF processing routines. */
+#define LSBBitOrder            YES
+
+#define MotifDefines           -DNO_REGCOMP -DNO_REGEX -DSTRINGS_ALIGNED
+#define DtSvcDefines           -DXK_MISCELLANY -DMULTIBYTE -DMESSAGE_CAT
+#define DtSearchDefines                -DI18N_MSG DtSvcDefines
+#define DtWidgetDefines                DtSearchDefines
+#define DtPrintDefines         DtSearchDefines
+#define DtMailDefines          \
+  -DNEED_MMAP_WRAPPER -DSENDMAIL_LOCKS -DMAIL_SPOOL_PATH=\"/var/spool/mail/%s\"
+
+#define ArchitectureDefines    -DALPHA_ARCHITECTURE
+#endif
+
+#ifdef MipsArchitecture
+#define DefaultCCOptions       -Xa
+#define XdecServer YES
+#define ServerOSDefines -DDDXTIME
+#define PexCCOptions -Xa -Wf,-XNp15000,-XNd15000
+#define NormalLibObjCompile(options)   ClearmakeOSName                   \
+       $(RM) $@ $*.os \                                                @@\
+       && $(CC) -c options $(CFLAGS) $*.c \                            @@\
+       && $(LD) $(LDSTRIPFLAGS) -r $@ -o $*.os \                       @@\
+       && $(MV) $*.os $@
+#endif
+
+#if !HasClearmake
+#ifndef HasMakefileSafeInclude
+#define HasMakefileSafeInclude YES
+#endif
+#ifndef IncludeMakefile
+#define IncludeMakefile(file) @@-include file
+#endif
+#endif
+
+#ifndef ManKeywordsTarget
+#define ManKeywordsTarget(manpath)                                     @@\
+man_keywords::                                                         @@\
+       catman -M $(DESTDIR)manpath -w
+#endif
+
+#define CdeTicDefines  -DHAS_KNL -DHAS_KTAB
+#define CdeProjectDefines \
+       -DDEC -DMULTIBYTE -DNLS16 \
+       -DOSMAJORVERSION=OSMajorVersion -DOSMINORVERSION=OSMinorVersion
diff --git a/Xserver/config/cf/osfLib.rules b/Xserver/config/cf/osfLib.rules
new file mode 100644 (file)
index 0000000..1218d86
--- /dev/null
@@ -0,0 +1,118 @@
+XCOMM $XConsortium: osfLib.rules /main/16 1996/09/28 16:11:55 rws $
+
+/*
+ * OSF/1 shared library rules
+ */
+
+#ifndef HasSharedLibraries
+#define HasSharedLibraries YES
+#endif
+#ifndef SeparateSharedCompile
+#define SeparateSharedCompile NO
+#endif
+#ifndef SharedDataSeparation
+#define SharedDataSeparation NO
+#endif
+#ifndef SharedCodeDef
+#define SharedCodeDef /**/
+#endif
+#ifndef SharedLibraryDef
+#define SharedLibraryDef /**/
+#endif
+#ifndef ShLibIncludeFile
+#define ShLibIncludeFile <osfLib.tmpl>
+#endif
+#ifndef SharedLibraryLoadFlags
+#define SharedLibraryLoadFlags -shared -no_archive
+#endif
+
+#ifndef PositionIndependentCFlags
+#define PositionIndependentCFlags /**/
+#endif
+
+/*
+ * InstallSharedLibrary - generate rules to install the shared library.
+ */
+#ifndef InstallSharedLibrary
+#define        InstallSharedLibrary(libname,rev,dest)                          @@\
+install:: Concat(lib,libname.so.rev)                                   @@\
+       MakeDir($(DESTDIR)dest)                                         @@\
+       $(INSTALL) $(INSTALLFLAGS) $(INSTLIBFLAGS) Concat(lib,libname.so.rev) $(DESTDIR)dest @@\
+       $(RM) Concat($(DESTDIR)dest/lib,libname.so)                     @@\
+       cd $(DESTDIR)dest; $(LN) Concat(lib,libname.so.rev) Concat(lib,libname.so)
+
+#endif /* InstallSharedLibrary */
+
+/*
+ * InstallSharedLibraryData - generate rules to install the shared library data
+ */
+#ifndef InstallSharedLibraryData
+#define        InstallSharedLibraryData(libname,rev,dest)
+#endif /* InstallSharedLibraryData */
+
+#ifndef PackageName(libname)
+#if ModernOSF1
+#define PackageName(libname) /**/
+#define Objects(objlist) -all objlist -none 
+#else
+#define PackageName(libname) -package libname
+#define Objects(objlist) objlist
+#endif
+#endif
+#if ThreadedX && ModernOSF1 && OSMajorVersion < 4
+#define BaseShLibReqs -lc_r -lc
+#else
+#define BaseShLibReqs -lc
+#endif
+
+/*
+ * SharedLibraryTarget - generate rules to create a shared library;
+ * build it into a different name so that we do not hose people by having
+ * the library gone for long periods.
+ */
+#ifndef SharedLibraryTarget
+#if SeparateSharedCompile
+#define SharedLibraryTarget(libname,rev,solist,down,up)                        @@\
+AllTarget(Concat(lib,libname.so.rev))                                  @@\
+                                                                       @@\
+Concat(lib,libname.so.rev):  solist $(EXTRALIBRARYDEPS)                        @@\
+       $(RM) $@~                                                       @@\
+       (cd down; $(LD) -o up/$@~ $(SHLIBLDFLAGS) PackageName($@) \     @@\
+               -soname $@ Objects(solist) \                            @@\
+               $(REQUIREDLIBS) BaseShLibReqs)                          @@\
+       $(RM) $@                                                        @@\
+       $(MV) $@~ $@                                                    @@\
+       $(RM) Concat(lib,libname.so)                                    @@\
+       $(LN) $@ Concat(lib,libname.so)                                 @@\
+       LinkBuildLibrary($@)                                            @@\
+       LinkBuildLibrary(Concat(lib,libname.so))                        @@\
+                                                                       @@\
+clean::                                                                        @@\
+       $(RM) Concat(lib,libname.so.rev) Concat(lib,libname.so)
+#else
+#define SharedLibraryTarget(libname,rev,solist,down,up)                        @@\
+AllTarget(Concat(lib,libname.so.rev))                                  @@\
+                                                                       @@\
+Concat(lib,libname.so.rev):  solist $(EXTRALIBRARYDEPS)                        @@\
+       $(RM) $@~                                                       @@\
+       $(LD) -o $@~ $(SHLIBLDFLAGS) PackageName($@) \                  @@\
+               -soname $@ Objects(solist) \                            @@\
+               $(REQUIREDLIBS) BaseShLibReqs                           @@\
+       $(RM) $@                                                        @@\
+       $(MV) $@~ $@                                                    @@\
+       $(RM) Concat(lib,libname.so)                                    @@\
+       $(LN) $@ Concat(lib,libname.so)                                 @@\
+       LinkBuildLibrary($@)                                            @@\
+       LinkBuildLibrary(Concat(lib,libname.so))                        @@\
+                                                                       @@\
+clean::                                                                        @@\
+       $(RM) Concat(lib,libname.so.rev) Concat(lib,libname.so)
+#endif /* SeparateSharedCompile */
+#endif /* SharedLibraryTarget */
+
+/*
+ * SharedLibraryDataTarget - generate rules to create shlib data file;
+ */
+#ifndef SharedLibraryDataTarget
+#define SharedLibraryDataTarget(libname,rev,salist)
+#endif /* SharedLibraryTarget */
diff --git a/Xserver/config/cf/osfLib.tmpl b/Xserver/config/cf/osfLib.tmpl
new file mode 100644 (file)
index 0000000..a67c410
--- /dev/null
@@ -0,0 +1,52 @@
+XCOMM $XConsortium: osfLib.tmpl /main/22 1996/09/28 16:12:00 rws $
+
+/*
+ * OSF/1 shared library template
+ */
+
+#if ThreadedX && ModernOSF1
+#if OSMajorVersion < 4
+#define SharedX11Reqs -lpthreads -lmach
+#endif
+#endif
+#define SharedOldXReqs $(LDPRELIBS) $(XLIBONLY)
+
+#if ThreadedX && ModernOSF1 && OSMajorVersion < 4
+#define SharedThreadReqs -lpthreads -lmach
+#else
+#define SharedThreadReqs /**/
+#endif
+#define SharedXtReqs $(LDPRELIBS) $(XLIBONLY) $(SMLIB) $(ICELIB) SharedThreadReqs
+#if ModernOSF1
+#define SharedXawReqs $(LDPRELIBS) $(XMULIB) $(XTOOLLIB) $(XLIB)
+#else
+#define SharedXawReqs $(LDPRELIBS) $(XMULIB) $(XTOOLLIB) $(XLIB) -init _XawFixupVendorShell
+#endif
+#define SharedXmuReqs $(LDPRELIBS) $(XTOOLLIB) $(XLIB)
+#define SharedXextReqs $(LDPRELIBS) $(XLIBONLY)
+#define SharedXiReqs $(LDPRELIBS) $(XLIB)
+#define SharedPexReqs $(LDPRELIBS) $(XLIBONLY) MathLibrary
+#define SharedXtstReqs $(LDPRELIBS) $(XLIB)
+#define SharedXieReqs $(LDPRELIBS) $(XLIBONLY)
+#define SharedSMReqs $(LDPRELIBS) $(ICELIB)
+#define SharedXpReqs $(LDPRELIBS) $(XLIB)
+
+#define SharedXReqs $(XTOOLLIB) $(XPLIB) $(XLIB) SharedThreadReqs $(LDPOSTLIBS)
+#define SharedXmReqs $(LDPRELIBS) SharedXReqs
+#define SharedMrmReqs $(LDPRELIBS) $(XMLIB) SharedXReqs
+#define SharedUilReqs $(LDPRELIBS) $(MRESOURCELIB) $(XMLIB) SharedXReqs
+
+/* #define SharedPamReqs */
+#define SharedTtReqs $(LDPRELIBS) $(XTOOLLIB) $(XLIB) SharedThreadReqs $(CXXLIB)
+#define SharedDtSvcReqs $(LDPRELIBS) $(TTLIB) $(XMLIB) SharedXReqs -lm $(CXXLIB)
+#define SharedDtMmdbReqs $(LDPRELIBS) $(DTSVCLIB) $(TTLIB) $(XMLIB) SharedXReqs -lm $(CXXLIB)
+#define SharedDtSearchReqs $(LDPRELIBS) -lm
+#define SharedDtWidgetReqs $(LDPRELIBS) $(DTSVCLIB) $(XMLIB) SharedXReqs -lm $(CXXLIB)
+#define SharedDtHelpReqs $(LDPRELIBS) $(DTSVCLIB) $(XMLIB) SharedXReqs -lm -liconv
+#define SharedDtPrintReqs $(LDPRELIBS) $(DTSVCLIB) $(DTHELPLIB) $(XMLIB) SharedXReqs -lm $(CXXLIB)
+#define SharedDtTermReqs $(LDPRELIBS) $(DTHELPLIB) $(DTSVCLIB) $(XMLIB) SharedXReqs -lm
+#define SharedDtMrmReqs $(LDPRELIBS) $(DTTERMLIB) $(DTPRINTLIB) $(DTHELPLIB) $(DTWIDGETLIB) $(MRESOURCELIB) $(XMLIB) SharedXReqs -lm
+#define SharedDtMailReqs $(LDPRELIBS) $(DTHELPLIB) $(DTSVCLIB) $(XMLIB) SharedXReqs -liconv -lm $(CXXLIB)
+#define SharedCsaReqs $(LDPRELIBS) $(DTSVCLIB) $(XMLIB) SharedXReqs -lm
+
+ICONVSYSLIB = -liconv
diff --git a/Xserver/config/cf/pegasus.cf b/Xserver/config/cf/pegasus.cf
new file mode 100644 (file)
index 0000000..507effa
--- /dev/null
@@ -0,0 +1,34 @@
+XCOMM platform:  $XConsortium: pegasus.cf /main/38 1996/09/28 16:12:05 rws $
+
+#ifndef OSName
+#define OSName             UTek 4.0
+#endif
+XCOMM operating system:  OSName
+#ifndef OSMajorVersion
+#define OSMajorVersion     4
+#endif
+#ifndef OSMinorVersion
+#define OSMinorVersion     0
+#endif
+
+#define HasNdbm                   YES
+#define HasVoidSignalReturn NO
+
+#define BootstrapCFlags    -DM4310 -DUTEK
+#define StandardDefines    -DM4310 -DUTEK -Dpegasus 
+
+#if HasGcc
+/* put back all of the -Ds which -ansi removes */
+#define CcCmd gcc -ansi -fstrength-reduce -fpcc-struct-return -Dmc68000 -Dtektronix -Dutek -Dunix -Dm68k
+#endif
+
+#define BuildServer NO
+/* #define XtekServer YES */
+
+#define ServerExtraDefines   -DM4310 -DM4317
+#define ServerOSDefines -DDDXTIME
+#define FontFilters BDFTOSNFFILT SHELLPATH
+#define PrimaryScreenResolution 95
+
+.DIRECTORIES:          /* Turn off directory search for RCS */
+
diff --git a/Xserver/config/cf/sco.cf b/Xserver/config/cf/sco.cf
new file mode 100644 (file)
index 0000000..3073e03
--- /dev/null
@@ -0,0 +1,206 @@
+XCOMM platform:  $XConsortium: sco.cf /main/5 1996/12/04 10:12:36 swick $
+XCOMM platform:  $XFree86: xc/config/cf/sco.cf,v 3.12.2.1 1997/05/24 13:38:09 dawes Exp $
+
+/*
+ * This is sco.cf, for SCO Open Server 5.0.2 and SCO UNIX.
+ * Please mail hug@netcom.com with any questions.
+ *
+ * This section is common to all versions of SCO
+ */
+
+#ifndef ScoOsMouse
+# define ScoOsMouse             YES
+#endif
+
+#ifndef OSVendor
+#define OSVendor                Santa Cruz Operation
+#endif
+
+#define PosixLibraries          /**/
+#define Malloc0ReturnsNull      YES
+#define RemoveDSDENroffMacros   NO
+#define ExtraLibraries          -lsocket -lmalloc -lpt
+
+#define ManSourcePath           $(MANPATH)/cat.
+
+#ifndef CompressManPages
+#define CompressManPages        YES
+#endif
+
+#if ScoOsMouse
+# define ServerExtraDefines     -DUSE_OSMOUSE XFree86ServerDefines
+# define ServerExtraSysLibs     $(CBRT) -lm -levent
+#else
+# define ServerExtraSysLibs     $(CBRT) -lm
+#endif
+
+/*
+ * XBSDLIB is included with the Socket libraries, because SCO needs Xbsd
+ * as its bcopy routine doesn't handle overlapping regions. If HasSockets
+ * If HasSockets is false the XINETLIB does it for us anyway.
+ */
+#define SocketLibraries                $(XBSDLIB) -lsocket
+
+#define ConnectionFlags         -DLOCALCONN -DTCPCONN -DFD_SETSIZE=256
+
+#if defined(i386Sco324Architecture) || defined(i386Sco325Architecture)
+# ifndef HasSymLinks
+#  define HasSymLinks           YES
+# endif
+# define CompressManCmd         $(COMPRESS) -v
+#else /* SCO 3.2.2 */
+# ifndef HasSymLinks
+#  define HasSymLinks           NO
+# endif
+# define CommpressManCmd        pack
+#endif
+
+/*
+ * Due to the extra '.' chars in the SCO man pages file name we have
+ * to provide our own version of this macro.
+ */
+
+#define InstallManPageAliases(file,destdir,aliases)                     @@\
+install.man::                                                           @@\
+        @(SUFFIX=`echo $(DESTDIR)destdir/file.* | cut -f3,4 -d.`; \     @@\
+        for i in aliases; do (set -x; \                                 @@\
+        $(RM) $(DESTDIR)destdir/$$i.*; \                                @@\
+        (cd $(DESTDIR)destdir; $(LN) file.$${SUFFIX} \                  @@\
+        $$i.$${SUFFIX})); \                                             @@\
+        done)
+
+/*
+ * This is the SCO Open Server 5.0.2 section. BOOTSTRAPCFLAGS is computed
+ * automatically. You can simply run make World.
+ */
+#ifdef i386Sco325Architecture
+#ifndef OSName
+#define OSName                  OpenServer Release 5
+#endif
+#ifndef OSMajorVersion
+#define OSMajorVersion          5
+#endif
+#ifndef OSMinorVersion
+#define OSMinorVersion          0
+#endif
+#ifndef OSTeenyVersion
+#define OSTeenyVersion          2
+#endif
+
+#define StandardDefines         -Dsco -DSCO -DSYSV -Di386 -DSCO325 -DSCO324
+#ifdef HasGcc2
+# define DefaultCCOptions       -melf
+# define CcCmd                  gcc
+# define ExtraLoadOptions       -melf
+# define DefaultCDebugFlags     DefaultGcc2i386Opt
+# define OptimizedCDebugFlags   DefaultGcc2i386Opt
+#else
+# define DefaultCCOptions       -dy 
+# define CcCmd                  cc
+# define ExtraLoadOptions       -b elf
+# define DefaultCDebugFlags     -O2
+# define OptimizedCDebugFlags   -O2
+#endif
+
+#define XawI18nDefines          -DHAS_WCHAR_H -DHAS_ISW_FUNCS
+#define NeedWidePrototypes      NO
+#define ServerOSDefines         -DDDXTIME
+#define ToolkitStringsABIOptions -intelabi
+#define ThreadedX               NO
+#define HasThreadSafeAPI        NO
+#define HasNdbm                 YES
+#define HasVFork                YES
+#define HasPutenv               YES
+#define ExecableScripts         YES
+#define HasShadowPasswd         YES
+
+#ifndef HasLibCrypt
+# define HasLibCrypt            YES
+# define SpecialLibCrypt        -lcrypt
+#endif
+
+#ifndef ForceNormalLib
+# define ForceNormalLib         YES 
+#endif
+
+#define SharedLibXmu            NO
+#define SystemV                 YES
+#define LdCombineFlags          -r 
+
+#define HasLdRunPath            YES
+#define HasPoll                 YES
+#define PatheticCpp             YES
+
+#define ArCmdBase               ar
+#define AsCmd                   as
+#define CppCmd                  /lib/cpp
+#define LdCmd                   ld
+#define LexCmd                  lex
+#define MakeCmd                 make
+#define YaccCmd                 yacc
+
+#include <scoLib.rules>  /* minor changes to sv4Lib.rules */
+#include <sv4Lib.rules>
+
+#define DtSvcDefines           -DXK_MISCELLANY -DMULTIBYTE
+#define DtSearchDefines                -DI18N_MSG DtSvcDefines
+#define DtWidgetDefines                DtSearchDefines
+#define DtPrintDefines         DtSearchDefines
+
+#else /* !i386Sco325Architecture */
+/*
+ * This is the SCO 3.2v4.x and SCO 3.2v2.x section
+ */
+
+/* You must manually compute BootstrapCFlags for initial build */
+
+#define        OSMinorVersion  2
+
+#ifdef i386Sco324Architecture
+# define BootstrapCFlags        -DSYSV -Di386 -DSCO -DSCO324
+# define OSTeenyVersion         4
+# define OSName                 (SCO Version 3.2.4)
+# define OSDefines              -DSCO -DSCO324 -Dsco -Dsco324 -DBROKEN_FTOL \
+                                -D_NO_PROTOTYPE -D_SVID
+#else
+# define BootstrapCFlags        -DSYSV -Di386 -DSCO
+# define OSTeenyVersion         2
+# define OSName                 (SCO Version 3.2.2)
+# define OSDefines              -DSCO -Dsco -DBROKEN_FTOL -DNO_PROTOTYPE \
+                                -D_SVID
+#endif
+
+#ifdef i386Sco324Architecture
+/*
+ * if your gcc is compiled with STDC_VALUE=0 then change the 1 to 0
+ */
+# define GCC_STDC_VALUE         1
+# if !GCC_STDC_VALUE
+#  define OSDefines             -DSCO -DSCO324 -Dsco -Dsco324 -DBROKEN_FTOL \
+                                -D_NO_PROTOTYPE -D_SVID -D__STDC__=1
+#  undef StandardCppDefines
+#  define StandardCppDefines    -DUNIXCPP=1 StandardDefines
+# endif
+#endif
+
+#define XawI18nDefines             -DUSE_XWCHAR_STRING -DUSE_XMBTOWC
+
+/*
+ * The user should override this in their site.def if they have the real
+ * crypt library. We default to the international crypt library here as
+ * anyone may obtain that.
+ */
+
+#ifndef HasLibCrypt
+# define HasLibCrypt            YES
+# define SpecialLibCrypt        -lcrypt_i
+#endif
+
+#include <svr3.cf>
+
+#endif /* SCO 3.2.4 and SCO 3.2.2 section */
+
+#ifdef i386Architecture
+#include <xfree86.cf>
+#endif
+
diff --git a/Xserver/config/cf/sco5.cf b/Xserver/config/cf/sco5.cf
new file mode 100644 (file)
index 0000000..9e07e31
--- /dev/null
@@ -0,0 +1,139 @@
+XCOMM $XFree86: xc/config/cf/sco5.cf,v 3.1.2.4 1997/07/19 04:59:08 dawes Exp $
+
+/*
+ * This is for SCO Open Server 5.0.2 or later.
+ */
+
+#ifndef ScoOsMouse
+# define ScoOsMouse             YES
+#endif
+
+#ifndef OSName
+#define OSName                  UNIX System V/386 Open Server 5.0.4
+#endif
+#ifndef OSVendor
+#define OSVendor                SCO
+#endif
+#ifndef OSMajorVersion
+#define OSMajorVersion          5
+#endif
+#ifndef OSMinorVersion
+#define OSMinorVersion          0
+#endif
+#ifndef OSTeenyVersion
+#define OSTeenyVersion          4
+#endif
+
+/*
+ * Note: We define FD_SETSIZE here (as opposed to in ConnectionFlags) to
+ * guarantee that the same FD_SETSIZE is used. Havoc abounds if we do not
+ * do this, as some files which include sys/socket.h and sys/types.h will
+ * have different values for FD_SETSIZE.
+ */
+
+#define StandardDefines         -Dsco -DSCO -DSYSV -Di386 -DSCO325 -DFD_SETSIZE=256 -D_NO_STATIC
+#ifdef HasGcc2
+# define DefaultCCOptions       -melf
+# define CcCmd                  gcc
+# define ExtraLoadOptions       -melf
+# define DefaultCDebugFlags     -O
+# define OptimizedCDebugFlags   -O
+#else
+# define DefaultCCOptions       -dy 
+# define CcCmd                  cc
+# define ExtraLoadOptions       -b elf
+# define DefaultCDebugFlags     -O
+# define OptimizedCDebugFlags   -O
+#endif
+
+#ifndef PexDynamicModule
+#define PexDynamicModule        YES
+#endif
+#ifndef XieDynamicModule
+#define XieDynamicModule        YES
+#endif
+
+#ifndef HasSymLinks
+# define HasSymLinks            YES
+#endif
+
+#ifdef BuildDynamicLoading
+#define SCODynamicFlags         -Wl,-Bexport
+#endif
+
+#define XawI18nDefines          -DHAS_WCHAR_H -DHAS_ISW_FUNCS
+#if ScoOsMouse
+# define ServerExtraSysLibs     $(CBRT) -lm -levent SCODynamicFlags
+# define ServerExtraDefines     ServerCCOptions -DUSE_OSMOUSE XFree86ServerDefines
+#else
+# define ServerExtraSysLibs     $(CBRT) -lm SCODynamicFlags
+# define ServerExtraDefines     ServerCCOptions XFree86ServerDefines
+#endif
+#define ExtraLibraries          -lsocket
+#define NeedWidePrototypes      NO
+#define ServerOSDefines         -DDDXTIME
+#define ToolkitStringsABIOptions -intelabi
+#define ThreadedX               NO
+#define HasThreadSafeAPI        NO
+#define HasNdbm                 YES
+#define HasVFork                YES
+#define HasPutenv               YES
+#define ExecableScripts         YES
+#define HasShadowPasswd         YES
+#define ManSourcePath           $(MANPATH)/cat.
+#define Malloc0ReturnsNull      YES
+#define RemoveDSDENroffMacros   NO
+#define CompressManPages        YES
+
+#ifndef HasLibCrypt
+# define HasLibCrypt            YES
+# define SpecialLibCrypt        -lcrypt
+#endif
+#define PosixLibraries          /**/
+
+#ifndef ForceNormalLib
+# define ForceNormalLib         YES 
+#endif
+
+#define SharedLibXmu            NO
+#define SystemV                 YES
+#define LdCombineFlags          -r 
+
+#define HasLdRunPath            YES
+#define HasPoll                 NO
+#define PatheticCpp             YES
+
+#define ArCmdBase               ar
+#define AsCmd                   as
+#define CppCmd                  /lib/cpp
+#define LdCmd                   ld
+#define LexCmd                  lex
+#define MakeCmd                        make
+#define YaccCmd                 yacc
+
+#define DefaultUserPath         /bin:/usr/bin:$(BINDIR):/usr/bin/X11:/usr/local/bin:/etc
+#define DefaultSystemPath       /etc:/bin:/usr/bin:$(BINDIR):/usr/bin/X11
+
+/*
+ * If you are compiling on an SCO Open Server release prior to 5.0.2,
+ * you may need to remove -DLOCALCONN. There have been reports of it
+ * working on some 5.0.0 machines but not others.
+ */
+#define ConnectionFlags         -DLOCALCONN -DTCPCONN -DUNIXCONN
+
+#define InstallManPageAliases(file,destdir,aliases)                     @@\
+install.man::                                                           @@\
+        @(SUFFIX=`echo $(DESTDIR)destdir/file.* | cut -f3,4 -d.`; \     @@\
+        for i in aliases; do (set -x; \                                 @@\
+        $(RM) $(DESTDIR)destdir/$$i.*; \                                @@\
+        (cd $(DESTDIR)destdir; $(LN) file.$${SUFFIX} \                  @@\
+        $$i.$${SUFFIX})); \                                             @@\
+        done)
+
+#include <scoLib.rules>  /* minor changes to sv4Lib.rules */
+#include <sv4Lib.rules>
+
+#ifdef i386Architecture
+#include <xfree86.cf>
+#endif
+
diff --git a/Xserver/config/cf/scoLib.rules b/Xserver/config/cf/scoLib.rules
new file mode 100644 (file)
index 0000000..21a7ff6
--- /dev/null
@@ -0,0 +1,43 @@
+XCOMM $XConsortium: scoLib.rules /main/2 1996/09/28 16:12:20 rws $
+XCOMM $XFree86: xc/config/cf/scoLib.rules,v 1.1.1.2.2.2 1997/07/19 12:59:10 dawes Exp $
+
+/*
+ * SharedLibraryTarget3 - generate rules to create a shared library;
+ * build it into a different name so that we do not hose people by having
+ * the library gone for long periods.  
+ *
+ * Work around SCO sh enviroment size problem.
+ */
+#ifndef SharedLibraryTarget3
+#define SharedLibraryTarget3(libname,rev,solist1,solist2,solist3,down,up)      @@\
+AllTarget(Concat(lib,libname.so.rev))                                  @@\
+                                                                       @@\
+Concat(lib,libname.so.rev): solist1 solist2 solist3 $(EXTRALIBRARYDEPS)        @@\
+       $(RM) $@~                                                       @@\
+       echo -n $(LD) -o up/$@~ $(SHLIBLDFLAGS) -h $(DESTDIR)$(SHLIBDIR)/$@ solist1 " " > Concat(down/lib,cmd)  @@\
+       echo -n solist2 " " >> Concat(down/lib,cmd)                     @@\
+       echo -n solist3  >> Concat(down/lib,cmd)                        @@\
+       (cd down; $(SHELL) Concat(./lib,cmd))                           @@\
+       $(RM) $@ Concat(lib,tmp1) Concat(lib,tmp2)                      @@\
+       $(MV) $@~ $@                                                    @@\
+       $(RM) Concat(lib,libname.so)                                    @@\
+       $(LN) $@ Concat(lib,libname.so)                                 @@\
+       LinkBuildLibrary($@)                                            @@\
+       LinkBuildLibrary(Concat(lib,libname.so))                        @@\
+                                                                       @@\
+clean::                                                                        @@\
+       $(RM) Concat(lib,libname.so.rev) Concat(lib,libname.so)
+
+#endif /* SharedLibraryTarget */
+
+/*
+ * Redefine this so we can drop -b elf and build COFF objects for the
+ * archived library.  This assumes -b elf is hanging out in CCOPTIONS
+ */
+#ifndef UnsharedLibObjCompile
+#define UnsharedLibObjCompile(options) RemoveFile($@)                  @@\
+        ClearmakeOSName                                                  \
+        $(CC) -c $(CDEBUGFLAGS) $(THREADS_CFLAGS) $(ALLDEFINES) options $*.c @@\
+        $(MV) $@ unshared/$@
+#endif
+
diff --git a/Xserver/config/cf/sequent.cf b/Xserver/config/cf/sequent.cf
new file mode 100644 (file)
index 0000000..be7db5f
--- /dev/null
@@ -0,0 +1,84 @@
+XCOMM platform:  $XConsortium: sequent.cf /main/4 1996/12/04 10:10:49 swick $
+/*
+ * SET VERSION NUMBERS BEFORE MAKING MAKEFILES; also, you'll need to install
+ * util/scripts/bsdinstall.sh before doing a "make install"
+ */
+
+#if defined(DynixPtxArchitecture) || defined(_SEQUENT_)
+
+# ifndef OSName
+#  define OSName               Dynix/ptx
+# endif
+# ifndef OSMajorVersion
+#  define OSMajorVersion       2
+# endif
+# ifndef OSMinorVersion
+#  define OSMinorVersion       0
+# endif
+
+# define SystemV               YES
+# define SymbolTableFlags
+# define DefaultCCOptions      SymbolTableFlags
+# define SharedLibraryCCOptions        DefaultCCOptions
+# define StandardDefines               -DSYSV
+# define MotifDefines          -DSTRINGS_ALIGNED -DNO_REGCOMP
+# define ExtraLibraries                $(XBSDLIB) -lsocket -linet -lnsl -lseq
+# define XmExtraLibraries      /* -lgen (not official i386 ABI?) */
+
+# define NeedBerklib           YES
+# define HasShadowPasswd       YES
+# define InstallXdmConfig      YES
+# define HasSockets            YES
+
+/*
+ * Plan to remove Prototypes defines and use -Xc with
+ * Dynix/ptx:
+ *   OSMajorVersion=4
+ *   OSMinorVersion=0
+ * Using -Xc with Version 4.0 will elliminate most warnings
+ */
+# define NeedFunctionPrototypes        YES
+# define NeedNestedPrototypes  YES
+# define NeedConstPrototypes   YES
+# define NeedVarargsPrototypes YES
+
+
+/*
+ * unfortunately pbmplus uses this...
+ */
+RANLIB = :
+
+#endif /* defined(DynixPtxArchitecture) || defined(_SEQUENT_) */
+
+#if defined(Dynix3Architecture) || defined(sequent)
+
+# ifndef OSName
+#  define OSName               Dynix 3
+# endif
+# ifndef OSMajorVersion
+#  define OSMajorVersion       3
+# endif
+# ifndef OSMinorVersion
+#  define OSMinorVersion       2
+# endif
+
+# define SymbolTableFlags      -W0,-Nn7500 -W0,-Nd10000
+# define DefaultCCOptions      SymbolTableFlags
+# define StandardDefines       -DX_NOT_STDC_ENV -DX_NOT_POSIX
+# define ExtraLibraries                -lseq
+
+# define HasVoidSignalReturn   NO
+# define HasBsearch            NO
+
+# define SetTtyGroup           YES
+
+#endif /* defined(Dynix3Architecture) || defined(sequent) */
+
+#define BuildServer            NO
+#define BuildXInputLib         NO
+#define BuildPexClients                NO
+
+#define LnCmd                  ln -s
+
+/* libgen is not part of the i386 ABI.  (Are both architectures i386??) */
+#define UseLocalRegex          YES
diff --git a/Xserver/config/cf/sgi.cf b/Xserver/config/cf/sgi.cf
new file mode 100644 (file)
index 0000000..38f2344
--- /dev/null
@@ -0,0 +1,233 @@
+XCOMM platform:  $TOG: sgi.cf /main/45 1997/06/18 18:01:03 kaleb $
+
+#ifndef OSName
+# define OSName                DefaultOSName
+#endif
+#ifndef OSMajorVersion
+# define OSMajorVersion        DefaultOSMajorVersion
+#endif
+#ifndef OSMinorVersion
+# define OSMinorVersion        DefaultOSMinorVersion
+#endif
+#ifndef OSTeenyVersion
+# define OSTeenyVersion        DefaultOSTeenyVersion 
+#endif
+XCOMM operating system: OSName (OSMajorVersion.OSMinorVersion.OSTeenyVersion)
+
+#if OSMajorVersion < 4
+/* We do not guarantee this will work */
+#define BootstrapCFlags                -DX_WCHAR -DX_LOCALE -DX_USEBFUNCS -DSYSV
+#define StandardDefines                -DX_WCHAR -DX_LOCALE -DX_USEBFUNCS -DSYSV
+#define SetTtyGroup            NO
+#else
+#define HasPlugin              YES
+#define SetTtyGroup            YES
+#define ExtraFilesToClean      so_locations
+#endif
+
+#if OSMajorVersion < 5
+#define SystemV                        YES
+#define XawI18nDefines         -DUSE_XWCHAR_STRING -DUSE_XMBTOWC
+#else
+#define BootstrapCFlags                -DSVR4
+#define StandardDefines                -DSVR4
+#define SystemV4               YES
+#define HasWChar32              YES
+#define HasVFork               NO
+#if OSMajorVersion < 6
+#define XawI18nDefines         -DHAS_WCTYPE_H -DHAS_ISW_FUNCS
+#else
+#define XawI18nDefines         -DHAS_WCHAR_H -DHAS_ISW_FUNCS
+#endif
+#define AllocateLocalDefines   -DINCLUDE_ALLOCA_H
+#ifndef ExtraLoadFlags
+#define ExtraLoadFlags -Wl,-rpath,$(USRLIBDIRPATH)
+#endif
+#endif
+
+/*
+ * To build 64-bit binaries define Mips64Architecture in your site.def or
+ * host.def file. This is usually on done at the X Consortium to test
+ * big endian 64-bit cleanliness.
+ * To build 32-bit binaries using the old 32-bit mode, define
+ * NoMipsN32Archtecture in your site.def or host.def file.
+ * Otherwise the default is to use the "new 32" mode as requested by SGI.
+ */
+#ifndef MipsN32Architecture
+#if !defined(Mips64Architecture) && !defined(NoMipsN32Architecture)
+#define MipsN32Architecture YES
+#endif
+#endif
+
+#ifdef Mips64Architecture
+# define BuildLibPathVar       _RLD_ROOT=/dev/null LD_LIBRARY64_PATH
+# define SystemBuildLibPath    /usr/lib64:/lib64
+# define LdCmd                 ld -64
+#elif defined(MipsN32Architecture)
+# define BuildLibPathVar       _RLD_ROOT=/dev/null LD_LIBRARYN32_PATH
+# define SystemBuildLibPath    /usr/lib32:/lib32
+# define LdCmd                 ld -n32
+#else
+# define BuildLibPathVar       _RLD_ROOT=/dev/null LD_LIBRARY_PATH
+# define SystemBuildLibPath    /usr/lib:/lib
+#endif
+#define HasCplusplus           YES
+#define Malloc0ReturnsNull     YES     /* IRIX [56].x -lmalloc needs this */
+#define HasPutenv              YES
+#define ExecableScripts                YES
+#define HasNdbm                        YES
+#define HasPoll                 YES
+#define ExpandManNames          YES
+#ifndef BuildXInputExt
+#define BuildXInputExt         YES
+#endif
+
+#if OSMajorVersion > 3 || (OSMajorVersion == 3 && OSMinorVersion > 2)
+#define NeedVarargsPrototypes  YES
+#define NeedConstPrototypes    YES
+#define NeedWidePrototypes     NO
+#endif
+
+#include <sgiLib.rules>
+
+#if OSMajorVersion < 5
+#define SymbolTables -Wf,-XNp16000,-XNd16000,-XNh2000
+#define PexSymbolTables -Wf,-XNp15000,-XNd15000,-XNh2000
+#define ServerSymbolTables -Wf,-XNp8000,-XNh2000,-XNd8000
+#else
+#define SymbolTables
+#define PexSymbolTables 
+#define ServerSymbolTables
+#endif
+
+/* this is for floating point, ANSI cpp */
+#if OSMajorVersion < 5
+/* Extra libraries provide : yp, sysV malloc, shared libc, and widechar */
+# define ExtraLibraries -lsun -lmalloc -lc_s -lw
+# define sgiCCOptions -xansi -D__STDC__=1 -float
+#else
+# if OSMajorVersion < 6
+#  define sgiCCOptions -xansi
+# else
+#  define CppCmd cc -E
+#  ifdef Mips64Architecture
+/* set Mips64Architecture in host.def. Usually don't need it but we
+ * (the X Consortium) want a  64-bit big-endian machine to test on. */
+#   define sgiCCOptions -xansi -mips3 -64
+#   define DlLibrary /**/
+#  elif defined(MipsN32Architecture)
+/* Set MipsN32Architecture to build "new" 32-bit objs with a 32-bit kernel. */
+#   define sgiCCOptions -xansi -mips3 -n32
+#  else
+#   define sgiCCOptions -xansi
+#  endif
+#  if OSMinorVersion > 1
+/* if you haven't installed patch 1361, 1403, or 1645 on IRIX 6.2 then you
+ * must add "#define HasPosixThreads NO" in your site.def or host.def file
+ */
+#   ifndef HasPosixThreads
+#    define HasPosixThreads    YES
+#   endif
+#   define ThreadedX HasPosixThreads
+#   define ThreadsLibraries -lpthread
+/* 
+ * Add "#define HasSgiThreadsPatch1403 NO" to your site.def or host.def if 
+ * that's which patch you have.
+ */
+#   ifndef HasSgiThreadsPatch1403
+#    define HasSgiThreadsPatch1403 YES
+#   endif
+#   if (HasSgiThreadsPatch1403) 
+#    define SystemMTDefines -D_POSIX_THREAD_SAFE_FUNCTIONS
+#   endif
+#  endif
+# endif
+/* SGI's -lsocket -lnsl is broken, at least in 5.2, so override here */
+# define ExtraLibraries /**/
+#endif
+
+#define DefaultCCOptions sgiCCOptions SymbolTables
+#define PexCCOptions sgiCCOptions PexSymbolTables
+#define ServerCCOptions sgiCCOptions ServerSymbolTables
+
+/* For SGI C++ compiler, need to search extra dirs in make depend */
+#ifndef CplusplusDependIncludes
+#define CplusplusDependIncludes -I/usr/include/CC
+#endif
+
+/* At SGI, we don't need this */
+#define ConstructMFLAGS                NO      /* build MFLAGS from MAKEFLAGS */
+
+/* Used only for compressed fonts */
+#define UNCOMPRESSPATH /usr/bsd/uncompress
+
+/* Normally used only to conditionally chose the default font path order */
+#define PrimaryScreenResolution 96
+
+/* Override Imake.tmpl's "-X" flag */
+#define LdCombineFlags -r
+
+/* Installation Build Parameters */
+#define InstKmemFlags -m 2711 -g sys
+
+#define ArCmd ar scq
+
+/* for xdm or anyone else to use */
+#define DefaultUserPath :/usr/sbin:/usr/bsd:/usr/bin:/bin:$(BINDIR):/etc:/usr/etc
+#define DefaultSystemPath /usr/sbin:/usr/bsd:/bin:/etc:/usr/bin:/usr/etc:$(BINDIR)
+
+#ifndef BuildServer
+#define BuildServer             NO
+#endif
+#define ServerOSDefines                -DDDXTIME 
+/* only need this for binary compatibility with their ddx */
+#ifndef Mips64Architecture
+#define ServerExtraDefines     -DNEED_LINEHELPER AllocateLocalDefines
+#else
+#define ServerExtraDefines     -D_XSERVER64 -DNEED_LINEHELPER AllocateLocalDefines
+#endif
+
+/* Changed to a single shell command for pmake/smake */
+#if OSMajorVersion < 5
+/*
+ * NormalLibObjCompile - compile fragment for a library object file
+ *     do ld -x to remove line number symbols for libraries
+ */
+#define NormalLibObjCompile(options)   ClearmakeOSName                   \
+       $(RM) $@ $*.os \                                                @@\
+       && $(CC) -c options $(CFLAGS) $*.c \                            @@\
+       && $(LD) $(LDSTRIPFLAGS) -r $@ -o $*.os \                       @@\
+       && $(MV) $*.os $@
+#endif
+
+#define LibObjCompile(dir,options) ClearmakeOSName                       \
+       $(RM) $@ dir/$@ \                                               @@\
+       && $(CC) -c $(CCOPTIONS) $(ALLDEFINES) options $*.c \           @@\
+       && $(MV) $@ dir/$@
+
+#ifndef HasMakefileSafeInclude
+#define HasMakefileSafeInclude YES
+#endif
+#ifndef IncludeMakefile
+#define IncludeMakefile(file) @@sinclude file
+#endif
+
+/* needs to find nroff on the system to work */
+#ifndef ManKeywordsTarget
+#define ManKeywordsTarget(manpath)                                     @@\
+man_keywords::                                                         @@\
+       /usr/lib/makewhatis -M $(DESTDIR)manpath $(DESTDIR)manpath/whatis
+#endif
+
+#define MotifDefines           -DSYS_DIR -DPORT_NOVFORK -DNO_REGCOMP
+
+#ifndef CppFileTarget
+#define CppFileTarget(dst,src,defs,deplist)                            @@\
+dst::  src deplist                                                     @@\
+       RemoveFile($@)                                                  @@\
+       ClearmakeOSName \
+       $(CPP) CppNoLineInfoOption defs src | CppSedMagic >$@;          @@\
+                                                                       @@\
+clean::                                                                        @@\
+       RemoveFiles(dst)
+#endif /* CppFileTarget */
diff --git a/Xserver/config/cf/sgiLib.rules b/Xserver/config/cf/sgiLib.rules
new file mode 100644 (file)
index 0000000..ef066d4
--- /dev/null
@@ -0,0 +1,166 @@
+XCOMM $XConsortium: sgiLib.rules /main/16 1996/09/28 18:11:04 rws $
+
+#ifndef HasSharedLibraries
+#define HasSharedLibraries YES
+#endif
+#if OSMajorVersion < 5
+#ifndef SharedDataSeparation
+#define SharedDataSeparation YES
+#endif
+#define SharedCodeDef -DSHAREDCODE
+#define SharedLibraryDef -DATTSHAREDLIB
+#define PositionIndependentCFlags -G 0
+
+/*
+ * SharedLibraryTarget - generate rules to create a shared library;
+ * build it into a different name so that we don't hose people by having
+ * the library gone for long periods.
+ */
+#define SharedLibraryTarget(libname,rev,solist,down,up)                        @@\
+AllTarget(Concat3(lib,libname,_s))                                     @@\
+                                                                       @@\
+Concat3(lib,libname,_s): sharedlib.o solist Concat(lib,libname.spec) $(EXTRALIBRARYDEPS)       @@\
+       $(RM) $@ $@.a \                                                 @@\
+       && cd down \                                                    @@\
+       && mkshlib -s Concat(up/lib,libname.spec) -t up/$@ -h up/$@.a \ @@\
+       && ar rs up/$@.a sharedlib.o                                    @@\
+       LinkBuildLibrary($@)                                            @@\
+       LinkBuildLibrary($@.a)                                          @@\
+                                                                       @@\
+clean::                                                                        @@\
+       $(RM) Concat3(lib,libname,_s) Concat3(lib,libname,_s.a)
+
+#define SharedLibraryDataTarget(libname,rev,salist)
+
+/*
+ * InstallSharedLibrary - generate rules to install the shared library.
+ * NOTE: file must be executable, hence "INSTBINFLAGS"
+ */
+#define        InstallSharedLibrary(libname,rev,dest)                          @@\
+install:: Concat3(lib,libname,_s)                                      @@\
+       MakeDir($(DESTDIR)dest)                                         @@\
+       $(INSTALL) $(INSTALLFLAGS) $(INSTLIBFLAGS) Concat3(lib,libname,_s.a) $(DESTDIR)dest @@\
+       $(INSTALL) $(INSTALLFLAGS) $(INSTBINFLAGS) Concat3(lib,libname,_s) $(DESTDIR)dest
+
+
+/*
+ * InstallSharedLibraryData - generate rules to install the shared library data
+ */
+#define        InstallSharedLibraryData(libname,rev,dest)                      @@\
+InstallTarget(install,Concat3(lib,libname,_s.a),$(INSTLIBFLAGS),dest)
+
+#else /* OSMajorVersion >= 5 */
+
+#ifndef SharedDataSeparation
+#define SharedDataSeparation NO
+#endif
+#ifndef SharedCodeDef
+#define SharedCodeDef /**/
+#endif
+#ifndef SharedLibraryDef
+#define SharedLibraryDef /**/
+#endif
+#ifndef ShLibIncludeFile
+#define ShLibIncludeFile <sgiLib.tmpl>
+#endif
+#ifndef SharedLibraryLoadFlags
+#if OSMajorVersion < 6
+#define SharedLibraryLoadFlags -shared
+#else
+#ifndef Mips64Architecture
+#define SharedLibraryLoadFlags -shared
+#else
+#define SharedLibraryLoadFlags -shared -mips3
+#endif
+#endif
+#endif
+/* -KPIC is redundant, PIC is always used unless you specify -non_shared */
+#ifndef PositionIndependentCFlags
+#define PositionIndependentCFlags -KPIC
+#endif
+#ifndef PositionIndependentCplusplusFlags
+#define PositionIndependentCplusplusFlags -KPIC
+#endif
+
+/*
+ * SGI's cc passes an undocumented flag to ld that causes it to look for
+ * -lX11 and force use of libX11.so.1.  And it can't be turned off.  Sigh.
+ * So we install one of those, too, in the shared library install target.
+ */
+
+/*
+ * InstallSharedLibrary - generate rules to install the shared library.
+ */
+#ifndef InstallSharedLibrary
+#define        InstallSharedLibrary(libname,rev,dest)                          @@\
+install:: Concat(lib,libname.so.rev)                                   @@\
+       MakeDir($(DESTDIR)dest)                                         @@\
+       $(INSTALL) $(INSTALLFLAGS) $(INSTLIBFLAGS) Concat(lib,libname.so.rev) $(DESTDIR)dest @@\
+       $(RM) Concat($(DESTDIR)dest/lib,libname.so)                     @@\
+       cd $(DESTDIR)dest; $(LN) Concat(lib,libname.so.rev) Concat(lib,libname.so) @@\
+       if [ "libname" = X11 ]; then \                                  @@\
+           RemoveFile(Concat($(DESTDIR)dest/lib,libname.so.1)); \      @@\
+           cd $(DESTDIR)dest; $(LN) Concat(lib,libname.so.rev) Concat(lib,libname.so.1);\ @@\
+       fi
+
+#endif /* InstallSharedLibrary */
+
+/*
+ * InstallSharedLibraryData - generate rules to install the shared library data
+ */
+#ifndef InstallSharedLibraryData
+#define        InstallSharedLibraryData(libname,rev,dest)
+#endif /* InstallSharedLibraryData */
+
+
+/*
+ * SharedLibraryTarget - generate rules to create a shared library;
+ * build it into a different name so that we do not hose people by having
+ * the library gone for long periods.
+ */
+
+/*
+ * SGI's cc passes an undocumented flag to ld that causes it to look for
+ * -lX11 and force use of libX11.so.1.  Sigh.  So we make one of those, too,
+ * in the shared library build target.
+ */
+
+#ifndef sgiX11soHack
+#ifdef UseInstalled
+#define sgiX11soHack(libname) /**/
+#else
+#define sgiX11soHack(libname) if [ "libname" = X11 ]; then \           @@\
+           RemoveFile($(BUILDLIBDIR)/Concat(lib,libname.so.1)); \      @@\
+           cd $(BUILDLIBDIR); $(LN) $(BUILDINCTOP)/$(CURRENT_DIR)/$@ Concat(lib,libname.so.1); \ @@\
+       fi
+#endif
+#endif /* sgiX11soHack */
+
+#ifndef SharedLibraryTarget
+#define SharedLibraryTarget(libname,rev,solist,down,up)                        @@\
+AllTarget(Concat(lib,libname.so.rev))                                  @@\
+                                                                       @@\
+Concat(lib,libname.so.rev):  solist $(EXTRALIBRARYDEPS)                        @@\
+       $(RM) $@~                                                       @@\
+       (cd down; $(CCENVSETUP) $(LD) -o up/$@~ $(SHLIBLDFLAGS) -soname $@ solist $(REQUIREDLIBS))      @@\
+       $(RM) $@                                                        @@\
+       $(MV) $@~ $@                                                    @@\
+       $(RM) Concat(lib,libname.so)                                    @@\
+       $(LN) $@ Concat(lib,libname.so)                                 @@\
+       LinkBuildLibrary($@)                                            @@\
+       LinkBuildLibrary(Concat(lib,libname.so))                        @@\
+       sgiX11soHack(libname)                                           @@\
+                                                                       @@\
+clean::                                                                        @@\
+       $(RM) Concat(lib,libname.so.rev) Concat(lib,libname.so) so_locations
+
+#endif /* SharedLibraryTarget */
+
+/*
+ * SharedLibraryDataTarget - generate rules to create shlib data file;
+ */
+#ifndef SharedLibraryDataTarget
+#define SharedLibraryDataTarget(libname,rev,salist)
+#endif /* SharedLibraryTarget */
+
+#endif /* OsMajorVersion < 5 else */
diff --git a/Xserver/config/cf/sgiLib.tmpl b/Xserver/config/cf/sgiLib.tmpl
new file mode 100644 (file)
index 0000000..a9c28f6
--- /dev/null
@@ -0,0 +1,14 @@
+XCOMM $XConsortium: sgiLib.tmpl /main/2 1996/09/28 16:12:44 rws $
+
+/*
+ * SGI shared library template
+ */
+#define SharedXtReqs $(LDPRELIBS) $(XLIBONLY) -delay_load $(SMLIB) -delay_load $(ICELIB)
+#define SharedXmuReqs $(LDPRELIBS) $(XTOOLONLYLIB)
+#define SharedXawReqs -lw
+#define SharedXpReqs $(LDPRELIBS) $(XLIB)
+
+#define SharedXReqs $(XTOOLLIB) $(XPLIB) $(XLIB) -lgen
+#define SharedXmReqs $(LDPRELIBS) SharedXReqs
+#define SharedMrmReqs $(LDPRELIBS) $(XMLIB) SharedXReqs
+#define SharedUilReqs $(LDPRELIBS) $(MRESOURCELIB) $(XMLIB) SharedXReqs
diff --git a/Xserver/config/cf/site.def b/Xserver/config/cf/site.def
new file mode 100644 (file)
index 0000000..1b79fe8
--- /dev/null
@@ -0,0 +1,165 @@
+XCOMM site:  $XConsortium: site.def /main/revisionist/4 1996/12/31 08:02:07 kaleb $
+XCOMM site:  $XFree86: xc/config/cf/site.def,v 3.17.2.1 1997/06/22 10:32:21 dawes Exp $
+
+/***************************************************************************
+ *                                                                         *
+ *                        SITE-SPECIFIC DEFINITIONS                       *
+ *                                                                         *
+ * This file contains two halves, one included before the vendor-specific  *
+ * configuration file (.cf file), and one included after the .cf file.     *
+ * The before-half should be protected by #ifdef BeforeVendorCF, and the   *
+ * after-half should be protected by #ifdef AfterVendorCF.                 *
+ *                                                                         *
+ * The before-half should only set things that the .cf file depends on.    *
+ * For the .cf files shipped in this release, the main variables in this   *
+ * category are HasGcc, HasGcc2, HasCplusplus, OSMajorVersion,             *
+ * OSMinorVersion, and OSTeenyVersion.                                     *
+ *                                                                         *
+ * The after-half should contain all other definitions.  For example,      *
+ * place your ProjectRoot definition here.                                 *
+ *                                                                         *
+ * OS Major and Minor version numbers should be changed directly in the    *
+ * .cf file, not overridden in site.def.                                   *
+ *                                                                         *
+ ***************************************************************************/
+
+/* if you want host-specific customization, this is one way to do it */
+/*
+#ifndef SiteIConfigFiles
+#define SiteIConfigFiles $(IRULESRC)/host.def
+#define LocalConfigFiles host.def
+#endif
+*/
+
+
+#ifdef BeforeVendorCF
+
+/*
+ * Include this for easy XFree86 customisations
+ */
+
+/*================================================================
+   BEGIN ORL VNC modification
+   Use vnc.def instead of xf86site.def and host.def */
+
+/* REMOVE
+#ifndef SiteIConfigFiles
+#define SiteIConfigFiles $(IRULESRC)/xf86site.def $(IRULESRC)/host.def
+#endif
+
+#include <host.def>
+
+#include <xf86site.def>
+*/
+
+#define SiteIConfigFiles $(IRULESRC)/vnc.def
+#include <vnc.def>
+
+/* END ORL VNC modification
+================================================================*/
+
+/* On systems where cpp doesn't expand correctly macros in include directives
+ * the two following macros need to be defined directly (where "X11" is
+ * really whatever the TopLevelProject macro is defined to be).
+ */
+# if defined(AIXArchitecture) || defined(SVR4Architecture) || \
+     defined(SCOArchitecture) || defined(Win32Architecture) || \
+     defined(UXPArchitecture) || defined(SunArchitecture) || \
+     defined(i386IscArchitecture)
+#  ifndef ProjectRulesFile
+#   define ProjectRulesFile    <X11.rules>
+#  endif
+#  ifndef ProjectTmplFile
+#   define ProjectTmplFile     <X11.tmpl>
+#  endif
+# endif
+
+/*
+#ifndef HasGcc2
+#define HasGcc2 YES
+#endif
+*/
+
+#endif /* BeforeVendorCF */
+
+#ifdef AfterVendorCF
+
+/*================================================================
+   BEGIN ORL VNC modification
+   Define ProjectRoot in vnc.def */
+
+/* REMOVE
+#ifndef ProjectRoot
+#define ProjectRoot /usr/X11R6
+#endif
+*/
+
+/* END ORL VNC modification
+================================================================*/
+
+/* Only set HasXdmAuth to YES if you have a Wraphelp.c file. */
+#define HasXdmAuth YES
+
+/* #define PreIncDir DefaultGccIncludeDir */
+
+/*
+#if defined(SunArchitecture) && defined(SparcArchitecture)
+#define HasCodeCenter  YES
+#ifndef SVR4Architecture
+#define HasTestCenter  YES
+#endif
+#endif
+*/
+
+/*
+#ifdef __hp9000s800
+#define HasCodeCenter  YES
+#endif
+*/
+
+/*
+#if defined(SunArchitecture) && defined(SparcArchitecture) && !defined(SVR4Architecture)
+#define HasPurify      YES
+#endif
+*/
+
+/*
+#define HasSentinel    YES
+*/
+
+/*
+#undef DefaultUserPath
+#define DefaultUserPath /bin:/usr/bin:$(BINDIR):/usr/ucb:/usr/local/bin
+*/
+
+
+/* You do NOT need SetUID if you only run the server under xdm */
+/* You MAY need SetUID if users run the server by hand or under xinit */
+/* Consult your system administrator before making the X server setuid */
+/*
+#if defined(SunArchitecture) && OSMajorVersion > 4
+#define InstallXserverSetUID YES
+#endif
+*/
+
+/* You do NOT need SetUID if you only run the server under xdm */
+/* You MAY need SetUID if users run the server by hand or under xinit */
+/* Consult your system administrator before making the X server setuid */
+/*
+#ifdef XFree86Version
+#define InstallXserverSetUID YES
+#endif
+*/
+
+/*================================================================
+   BEGIN ORL VNC modification
+   No host.def */
+
+/* REMOVE
+#include <host.def>
+*/
+
+/* END ORL VNC modification
+================================================================*/
+
+#endif /* AfterVendorCF */
diff --git a/Xserver/config/cf/sony.cf b/Xserver/config/cf/sony.cf
new file mode 100644 (file)
index 0000000..02821b3
--- /dev/null
@@ -0,0 +1,103 @@
+XCOMM platform:  $XConsortium: sony.cf /main/69 1996/09/29 18:19:36 kaleb $
+
+#ifdef SonyBsdArchitecture
+
+#ifndef OSName
+#define OSName                  NEWS-OS 4.2.1C
+#endif
+#ifndef OSMajorVersion
+#define OSMajorVersion          4
+#endif
+#ifndef OSMinorVersion
+#define OSMinorVersion          2
+#endif
+#ifndef OSTeenyVersion
+#define OSTeenyVersion          1
+#endif
+#define SetTtyGroup             YES
+#define HasVoidSignalReturn     NO
+#define HasNdbm                 YES
+#define DirFailPrefix -
+#define InstKmemFlags          -g kmem -m 2711
+#define DefaultUserPath :/bin:/usr/bin:$(BINDIR):/usr/ucb:/usr/sony/bin:
+#define DefaultSystemPath /etc:/usr/etc:/bin:/usr/bin:$(BINDIR):/usr/ucb:/usr/sony/bin:
+#ifdef MipsArchitecture
+#define ExtraLibraries         -lmld
+#define LintOpts               -ax
+#define LintLibFlag            -o
+#define DefaultCCOptions       -Wf,-XNh2000,-XNd6000,-XNp10000 -Olimit 2000
+#define PexCCOptions           -Wf,-XNh2000,-XNd15000,-XNp15000 -Olimit 2000
+#else
+#define HasFortran             YES
+#endif
+#if OSMajorVersion >= 4
+#define HasShm                 YES
+#define HasPutenv              YES
+#define HasSecureRPC           YES
+#define XdmDir                 /etc/xdm
+#if OSMinorVersion >= 1
+#define HasBsearch             YES
+#else
+#define HasBsearch             NO
+#endif
+#else
+#define StandardDefines                -DNOSTDHDRS
+#define HasBsearch             NO
+#endif
+
+#else
+
+#ifndef OSName
+#define OSName                 DefaultOSName
+#endif
+#ifndef OSMajorVersion
+#define OSMajorVersion         DefaultOSMajorVersion
+#endif
+#ifndef OSMinorVersion
+#define OSMinorVersion         DefaultOSMinorVersion
+#endif
+#ifndef OSTeenyVersion
+#define OSTeenyVersion         DefaultOSTeenyVersion
+#endif
+XCOMM operating system:  OSName (OSMajorVersion./**/OSMinorVersion./**/OSTeenyVersion)
+
+#define BootstrapCFlags                -Dsony
+#define SystemV4               YES
+#define HasVFork               NO
+#define CcCmd                  /usr/bin/cc
+#define LdCmd                  /usr/bin/ld
+#if OSMajorVersion >= 6
+#define DefaultCCOptions       -Xa -Wf,-XNp9000,-XNd6000
+#define PexCCOptions           -Xa -Wf,-XNp15000,-XNd15000
+#define SharedLibraryLoadFlags -G -rpath $(USRLIBDIRPATH)
+#define PositionIndependentCFlags -K PIC -Wx,-G 0
+#define PositionIndependentCplusplusFlags -K PIC -Wx,-G 0
+#define SharedXmuReqs $(LDPRELIBS) $(XTOOLLIB) $(XLIB)
+#define FixupLibReferences() /**/
+#include <sv4Lib.rules>
+#else
+#define DefaultCCOptions       -Wf,-XNp9000,-XNd6000
+#define PexCCOptions           -Wf,-XNp15000,-XNd15000
+#endif
+
+#endif
+
+/*
+ * SONY C++ compiler is based on vanilla cfront, which means it
+ * refuses to compile files unless their names end in ".C".  We
+ * have to completely override .SUFFIXES to avoid using the builtin
+ * .C to .o rule in cases where the link to foo.C is already there,
+ * because the builtin rule doesn't use the right compilation flags.
+ */
+
+.SUFFIXES:
+.SUFFIXES: .o .c .y .l .s .sh .h .f .Y .L .cxx
+
+#define NormalLibObjCplusplusCompile(options) test -r $*.C || $(LN) $*.CCsuf $*.C @@\
+       $(CXX) -c $(CXXFLAGS) options $*.C
+
+XCOMM operating system:  OSName
+
+#ifndef BuildServer
+#define BuildServer             NO
+#endif
diff --git a/Xserver/config/cf/sun.cf b/Xserver/config/cf/sun.cf
new file mode 100644 (file)
index 0000000..2bb4c68
--- /dev/null
@@ -0,0 +1,385 @@
+XCOMM platform:  $TOG: sun.cf /main/163 1997/06/08 20:08:23 kaleb $
+
+
+
+
+XCOMM platform:  $XFree86: xc/config/cf/sun.cf,v 3.31.2.7 1997/12/01 13:31:17 dawes Exp $
+
+#ifndef OSName
+# define OSName                DefaultOSName
+#endif
+#ifndef OSMajorVersion
+# define OSMajorVersion        DefaultOSMajorVersion
+#endif
+#ifndef OSMinorVersion
+# define OSMinorVersion        DefaultOSMinorVersion
+#endif
+#ifndef OSTeenyVersion
+# define OSTeenyVersion        DefaultOSTeenyVersion
+#endif
+XCOMM operating system:  OSName (OSMajorVersion./**/OSMinorVersion./**/OSTeenyVersion)
+
+/*
+ * Compiler setup.  This sun.cf file knows what options to use with 
+ * certain compilers, including Sun C, CenterLine C, and gcc.  It 
+ * also understands how to set some of the options for various C++
+ * compilers, including Sun C++ and CenterLine C++.
+ *
+ * === C Compiler Setup ==========================================
+ *
+ * For SunPro C, define HasSunC to YES in site.def.  
+ * For CenterLine C, define HasCenterLineC to YES in site.def
+ * For gcc or gcc2, define HasGcc or HasGcc2 to YES in site.def
+ * For other compilers, define HasSunC to NO in site.def, then 
+ *    provide appropriate values for the various compiler related
+ *    configuration varibles used here.
+ * 
+ * If you say you have the SunPro C compiler, we assume you have 
+ * version 2.0.x of the compiler.  If you have version 3.0.x instead, 
+ * define CCompilerMajorVersion as 3 in site.def
+ *
+ * If you don't tell us which C compiler you have, we assume you have 
+ * the SunPro C compiler under Solaris 2.x, and the bundled /bin/cc 
+ * under SunOS 4.1.x
+ *
+ * === C++ Compiler Setup ==========================================
+ *
+ * For SunPro C++, define HasSunCplusplus to YES in site.def
+ * For CenterLine C++, define HasCenterLineCplusplus to YES in site.def
+ * For Gnu g++ 2.6.x, define HasGcc2ForCplusplus to YES in site.def
+ * For other compilers, define HasCplusplus to YES in site.def, and 
+ *    check to see if you need to provide values for CplusplusOptions
+ *    and/or DefaultCplusplusOptions.
+ *
+ * In any case, you may also need to set CplusplusDependIncludes.
+ *
+ * If you say you have the SunPro C++ compiler, we assume you have 
+ * version 3.0.x of the compiler.  If you have version 4.0.x instead, 
+ * define CplusplusCompilerMajorVersion as 4 in site.def.
+ *
+ */
+
+#ifndef HasGcc2
+#define HasGcc2 NO
+#endif
+#ifndef HasGcc
+#define HasGcc HasGcc2
+#endif
+
+#ifndef HasSunC
+# if (HasCenterLineC || HasGcc || HasGcc2 || OSMajorVersion < 5)
+#  define HasSunC NO
+# else
+#  define HasSunC YES
+# endif
+#endif
+
+#if HasSunC 
+# ifndef CCompilerMajorVersion
+#  define CCompilerMajorVersion 3
+#  define DefaultCDebugFlags   -xO3
+#  define OptimizedCDebugFlags -xO3
+# endif
+#endif
+
+#if HasSunCplusplus
+# ifndef HasCplusplus
+#  define HasCplusplus YES
+#  define OptimizedCplusplusDebugFlags -xO3
+# endif
+# ifndef CplusplusCompilerMajorVersion
+#  define CplusplusCompilerMajorVersion        4
+# endif
+#endif
+
+#if HasCenterLineC
+# ifndef CcCmd
+#  define CcCmd clcc
+# endif
+#endif
+
+#if HasCenterLineCplusplus
+# ifndef HasCplusplus
+#  define HasCplusplus YES
+# endif
+# ifndef DefaultCplusplusOptions
+#  define DefaultCplusplusOptions -Xa
+# endif
+# ifndef CplusplusOptions
+#  define CplusplusOptions -Xa
+# endif
+#endif
+
+
+#if OSMajorVersion < 4 || (OSMajorVersion == 4 && OSMinorVersion < 1)
+/* We do not guarantee this will work */
+# define BootstrapCFlags       -DNOSTDHDRS
+# define StandardDefines       -DNOSTDHDRS
+# define XawI18nDefines                -DUSE_XWCHAR_STRING -DUSE_XMBTOWC
+#endif
+
+#if OSMajorVersion == 4 
+# if OSMinorVersion == 1
+#  define HasPoll              YES
+# endif
+# if OSMinorVersion > 1 || (OSMinorVersion == 1 && OSTeenyVersion > 1)
+/* You ALSO need this if you have Sun ld patch 100170-06 or later to 4.1.1 */
+#  define SunPost411FCSLd      YES
+# endif
+#endif
+
+#ifdef i386Architecture
+# if OSMajorVersion > 4
+#  define ServerExtraDefines AllocateLocalDefines XFree86ServerDefines -D__EXTENSIONS__
+#  define ServerOSDefines    XFree86ServerOSDefines
+# else
+#  define ServerExtraDefines AllocateLocalDefines
+#  define ServerOSDefines   -DDDXOSINIT
+# endif
+#else
+# define ServerExtraDefines AllocateLocalDefines
+# define ServerOSDefines   -DDDXOSINIT
+#endif
+
+#define XkbServerDefines  -DXKB_ALWAYS_USES_SOFT_REPEAT
+
+#if OSMajorVersion > 4
+#if HasSunC
+/* 
+ * Assume /opt/SUNWspro/bin/ contains symlinks to the appropriate tools
+ */
+#ifndef  CcCmd
+# define CcCmd         /opt/SUNWspro/bin/cc
+#endif
+#ifndef  CplusplusCmd
+# define CplusplusCmd  /opt/SUNWspro/bin/CC
+#endif
+#ifndef  CplusplusFilt
+# define CplusplusFilt /opt/SUNWspro/bin/c++filt
+#endif
+#ifndef  CplusplusDependIncludes
+# define CplusplusDependIncludes       -I/opt/SUNWspro/SC3.0/include/CC
+#endif
+#endif
+
+# if HasSunC && (CCompilerMajorVersion < 3)
+#  define BootstrapCFlags      -DSVR4
+# else
+#  define BootstrapCFlags      /* none needed */
+# endif
+# ifndef XawI18nDefines
+#  if OSMinorVersion < 4
+#   define XawI18nDefines    -DHAS_WCTYPE_H -DHAS_ISW_FUNCS
+#  else
+#   define XawI18nDefines    -DHAS_WCHAR_H -DHAS_ISW_FUNCS
+#  endif
+# endif
+# if OSMinorVersion > 3
+#  define InstallCmd       /usr/ucb/install
+# endif
+# ifdef i386Architecture
+#  define StandardDefines        -Dsun -Di386 -DSVR4 -D__i386
+#  define ToolkitStringsABIOptions     -intelabi
+# else
+#  define StandardDefines        -Dsun -DSVR4
+#  define ToolkitStringsABIOptions     -sparcabi
+#  define HasPlugin         YES
+# endif
+# define ExtraLibraries    -lsocket -lnsl
+# if OSMinorVersion > 1
+#  define ThreadedX      YES
+#  define MTSafeAPIDefines     -DXUSE_MTSAFE_API -DXUSE_NETDB_R_API
+#  if HasSunC && CCompilerMajorVersion > 2
+#   define ThreadsCompileFlags -mt
+#  else
+#   define SystemMTDefines -D_REENTRANT
+#   define ThreadsLibraries -lthread
+#  endif
+#  if HasSunCplusplus && CplusplusCompilerMajorVersion > 3
+#   define ThreadsCplusplusCompileFlags -mt
+#  else
+#   define CplusplusSystemMTDefines -D_REENTRANT
+#   define ThreadsCplusplusLibraries -lthread
+#  endif
+# endif                /* OSMinorVersion > 1 */
+# ifndef UseExportLists
+#  if OSMinorVersion > 4
+#   define UseExportLists YES
+#  else
+#   define UseExportLists NO
+#  endif
+# endif
+# define HasVFork          NO
+# define InstKmemFlags   -g sys -m 2711
+# define ShLibIncludeFile <sunLib.tmpl>
+/*
+ * Set flags for position independent code before including sv4Lib.rules
+ * if the compiler in use doesn't use standard SVR4 flags
+ */
+# if HasSunC || HasCenterLineC
+#  define PositionIndependentCFlags -Kpic
+#  define LargePositionIndependentCFlags -KPIC
+# endif
+# if HasSunCplusplus || HasCenterLineCplusplus
+#  define PositionIndependentCplusplusFlags -pic
+#  define LargePositionIndependentCplusplusFlags -PIC
+# endif
+#else /* not OSMajorVersion > 4 */
+#define InstKmemFlags    -g kmem -m 2711
+#include <sunLib.rules>
+#endif /* OSMajorVersion > 4 (else) */
+
+#define BuildLibPathVar          LD_LIBRARY_PATH
+#define HasNdbm                  YES
+#define HasShm           YES
+#define HasSecureRPC     YES
+#define SetTtyGroup      YES
+#define HasPutenv        YES
+#ifndef i386Architecture
+# ifndef Xsun24Server
+#  define Xsun24Server   NO            /* color, mono, multiple depths */
+# endif
+# ifndef XsunServer
+#  define XsunServer     YES           /* color and mono, 8 bit only */
+# endif
+# ifndef XsunMonoServer
+#  define XsunMonoServer         NO            /* monochrome only */
+# endif
+# ifndef BuildPexExt
+#  define BuildPexExt    (XsunServer || Xsun24Server)
+# endif
+#endif /* not i386Architecture */
+
+#if (OSMajorVersion > 4) && defined(i386Architecture)
+#ifndef HasSolx86ApertureDriver
+#define HasSolx86ApertureDriver        YES
+#endif
+#endif
+
+#if HasGcc
+# if OSMajorVersion > 4 && defined(i386Architecture)
+#  ifndef DefaultCCOptions
+#   if UseInstalled
+#    define DefaultCCOptions -DNO_ASM
+#   else
+#    if OSMinorVersion > 3
+#     define DefaultCCOptions -ansi -pedantic -DNO_ASM
+#    else
+#     define DefaultCCOptions -DNO_ASM
+#    endif
+#   endif
+#  endif
+# endif
+# if HasGcc2
+#  ifndef OptimizedCDebugFlags
+#   ifdef i386Architecture
+#    define OptimizedCDebugFlags DefaultGcc2i386Opt
+#   else
+#    define OptimizedCDebugFlags -O2
+#   endif
+#  endif
+# else
+#  define SharedLibraryCcCmd cc
+#  define ExtraLoadFlags -B/usr/bin/
+#  define AllocateLocalDefines /**/
+
+.c.o:
+       ClearmakeOSName $(CC) -c $(CFLAGS) $*.c
+
+# endif /* HasGcc2 (else) */
+
+#else /* not HasGcc */
+
+# define AllocateLocalDefines -DINCLUDE_ALLOCA_H
+
+/* Set up compiler-dependent options for Sun C */
+
+# if HasSunC
+#  ifdef Sun3Architecture
+#   ifndef DefaultCCOptions
+#    define DefaultCCOptions -f68881 -pipe
+#   endif
+#  else        /* not defined(Sun3Architecture) */
+#   if OSMajorVersion < 5
+#    ifndef DefaultCCOptions
+#     define DefaultCCOptions -pipe
+#    endif
+#   else /* OSMajorVersion >= 5*/
+#    ifndef DefaultCCOptions
+#     define DefaultCCOptions -Xa
+#    endif
+#   endif      
+#  endif       
+# endif
+
+/* Set compiler-dependent options for CenterLine C */
+
+# if HasCenterLineC
+#  ifndef DefaultCCOptions
+#   define DefaultCCOptions -Xt -w1 -DANSICPP -U__HIGHC__
+#  endif
+#  ifndef NeedConstPrototypes
+#   define NeedConstPrototypes YES
+#  endif
+#  ifndef NeedNestedPrototypes
+#   define NeedNestedPrototypes YES
+#  endif
+#  ifndef NeedVarargsPrototypes
+#   define NeedVarargsPrototypes YES
+#  endif
+# endif
+
+
+# define PexCCOptions DefaultCCOptions
+
+#endif /* HasGcc (else) */
+
+#if OSMajorVersion < 5
+# define SharedAllocateLocalDefines -DINCLUDE_ALLOCA_H
+# define LibraryCCOptions /* don't want special floating point */
+#endif /* OSMajorVersion < 5 */
+
+#if OSMajorVersion > 4
+# include <svr4.cf>
+#endif
+
+#ifndef ManKeywordsTarget
+# define ManKeywordsTarget(manpath)                                    @@\
+man_keywords::                                                         @@\
+       catman -M $(DESTDIR)manpath -w
+#endif
+
+#if !defined(UsePamLibrary)
+# if (OSMajorVersion > 5) || ((OSMajorVersion == 5) && (OSMinorVersion >= 4))
+#  define UsePamLibrary                YES
+# endif
+#endif
+
+#define MotifDefines                   \
+       -DNO_ISDIR -DNO_REGCOMP -DNO_ALLOCA -DBOGUS_MB_MAX -DNO_CONST
+#define PamUnixDefines         -DPAM_NIS
+#define TtLargePICTable                YES
+#define DtSvcDefines           -DXK_MISCELLANY -DMULTIBYTE -DNO_REGCOMP
+#define DtSearchDefines                -DI18N_MSG DtSvcDefines
+#define DtWidgetDefines                DtSearchDefines
+#define DtPrintDefines         DtSearchDefines
+
+#define baseDtMailDefines      \
+       -DSunOS=OSMajorVersion\#\#OSMinorVersion -DMMAP_NORESERVE -DSPRO_V2
+#ifndef i386Architecture
+# define DtMailDefines         baseDtMailDefines
+#else
+# define DtMailDefines         -DBIG_ENDIAN baseDtMailDefines
+#endif
+
+#define ArchitectureDefines    -DSUN_ARCHITECTURE
+
+#define TtClientExtraLibs      ExtraLibraries -ldl -lintl
+
+#define ExportListGenSource    elistgen.sun
+#define ShlibExportListOpt(filename)   -M filename
+
+#define CdeProjectDefines \
+       -DMULTIBYTE -DNLS16 -DMESSAGE_CAT -D_XOPEN_VERSION=4 \
+       -D_XOPEN_SOURCE -D__EXTENSIONS__ \
+       -DOSMAJORVERSION=OSMajorVersion -DOSMINORVERSION=OSMinorVersion
diff --git a/Xserver/config/cf/sunLib.rules b/Xserver/config/cf/sunLib.rules
new file mode 100644 (file)
index 0000000..a3e7554
--- /dev/null
@@ -0,0 +1,111 @@
+XCOMM $XConsortium: sunLib.rules /main/15 1996/09/28 16:13:16 rws $
+
+/*
+ * SunOS shared library rules
+ */
+
+#ifndef HasSharedLibraries
+#define HasSharedLibraries YES
+#endif
+#ifndef SharedDataSeparation
+#define SharedDataSeparation YES
+#endif
+#ifndef SharedCodeDef
+#define SharedCodeDef -DSHAREDCODE
+#endif
+#ifndef SharedLibraryDef
+#define SharedLibraryDef -DSUNSHLIB
+#endif
+#ifndef ShLibIncludeFile
+#define ShLibIncludeFile <sunLib.tmpl>
+#endif
+#ifndef SharedLibraryLoadFlags
+#define SharedLibraryLoadFlags -assert pure-text
+#endif
+#ifndef PositionIndependentCFlags
+#if HasGcc2
+#define PositionIndependentCFlags -fpic
+#else
+#define PositionIndependentCFlags -pic
+#endif
+#endif
+#ifndef PositionIndependentCplusplusFlags
+#if HasGcc2ForCplusplus
+#define PositionIndependentCplusplusFlags -fpic
+#else
+#define PositionIndependentCplusplusFlags -pic
+#endif
+#endif
+
+/*
+ * SharedDSLibDependencies - shared library dependencies with data separation
+ */
+#ifndef SharedDSLibDependencies
+#define SharedDSLibDependencies(libname,libsource,revname) _UseCat($(USRLIBDIR)/lib,libsource/lib,libname.sa.$(revname))
+#endif
+
+/*
+ * InstallSharedLibrary - generate rules to install the shared library.
+ */
+#ifndef InstallSharedLibrary
+#define        InstallSharedLibrary(libname,rev,dest)                          @@\
+InstallTarget(install,Concat(lib,libname.so.rev),$(INSTLIBFLAGS),dest)
+#endif /* InstallSharedLibrary */
+
+/*
+ * InstallSharedLibraryData - generate rules to install the shared library data
+ */
+#ifndef InstallSharedLibraryData
+#define        InstallSharedLibraryData(libname,rev,dest)                      @@\
+install:: Concat(lib,libname.sa.rev)                                   @@\
+       MakeDir($(DESTDIR)dest)                                         @@\
+       $(INSTALL) $(INSTALLFLAGS) $(INSTLIBFLAGS) Concat(lib,libname.sa.rev) $(DESTDIR)dest @@\
+       RanLibrary($(RANLIBINSTFLAGS) Concat($(DESTDIR)dest/lib,libname.sa.rev))
+#endif /* InstallSharedLibraryData */
+
+#if HasPurify
+#define PureCleanSharedLibrary(libname,rev)                            @@\
+clean clean.pure::                                                     @@\
+       $(RM) Concat3(lib,libname,_pure_*.so.rev)
+#else
+#define PureCleanSharedLibrary(libname,rev) /**/
+#endif
+
+/*
+ * SharedLibraryTarget - generate rules to create a shared library;
+ * build it into a different name so that we do not hose people by having
+ * the library gone for long periods.
+ */
+#ifndef SharedLibraryTarget
+#define SharedLibraryTarget(libname,rev,solist,down,up)                        @@\
+AllTarget(Concat(lib,libname.so.rev))                                  @@\
+                                                                       @@\
+Concat(lib,libname.so.rev):  solist $(EXTRALIBRARYDEPS)                        @@\
+       $(RM) $@~                                                       @@\
+       (cd down; $(LD) -o up/$@~ $(SHLIBLDFLAGS) solist $(REQUIREDLIBS)) @@\
+       $(RM) $@                                                        @@\
+       $(MV) $@~ $@                                                    @@\
+       LinkBuildLibrary($@)                                            @@\
+                                                                       @@\
+clean::                                                                        @@\
+       $(RM) Concat(lib,libname.so.rev)                                @@\
+                                                                       @@\
+PureCleanSharedLibrary(libname,rev)
+#endif /* SharedLibraryTarget */
+
+/*
+ * SharedLibraryDataTarget - generate rules to create shlib data file;
+ */
+#ifndef SharedLibraryDataTarget
+#define SharedLibraryDataTarget(libname,rev,salist)                    @@\
+AllTarget(Concat(lib,libname.sa.rev))                                  @@\
+                                                                       @@\
+Concat(lib,libname.sa.rev):  salist                                    @@\
+       $(RM) $@                                                        @@\
+       $(AR) $@ salist                                                 @@\
+       RanLibrary($@)                                                  @@\
+       LinkBuildLibrary($@)                                            @@\
+                                                                       @@\
+clean::                                                                        @@\
+       $(RM) Concat(lib,libname.sa.rev)
+#endif /* SharedLibraryDataTarget */
diff --git a/Xserver/config/cf/sunLib.tmpl b/Xserver/config/cf/sunLib.tmpl
new file mode 100644 (file)
index 0000000..7eb4fa1
--- /dev/null
@@ -0,0 +1,91 @@
+XCOMM $TOG: sunLib.tmpl /main/45 1997/02/13 13:52:59 kaleb $
+
+
+
+
+XCOMM $XFree86: xc/config/cf/sunLib.tmpl,v 3.7.2.1 1997/05/03 09:43:09 dawes Exp $
+
+/*
+ * SunOS shared library template
+ */
+
+#if OSMajorVersion <= 4
+
+# if SunPost411FCSLd
+#  define SharedXmuReqs $(LDPRELIBS) $(XTOOLLIB) $(XLIB)
+# endif
+
+#ifndef SharedX11Rev
+#define SharedX11Rev 4.30
+#endif
+#ifndef SharedOldXRev
+#define SharedOldXRev 4.20
+#endif
+#ifndef SharedXtRev
+#define SharedXtRev 4.20
+#endif
+#ifndef SharedXawRev
+#define SharedXawRev 6.10
+#endif
+#ifndef SharedXmuRev
+#define SharedXmuRev 4.20
+#endif
+#ifndef SharedXextRev
+#define SharedXextRev 4.40
+#endif
+#ifndef SharedXiRev
+#define SharedXiRev 4.20
+#endif
+#ifndef SharedXtstRev
+#define SharedXtstRev 1.20
+#endif
+#ifndef SharedPexRev
+#define SharedPexRev 1.10
+#endif
+
+#else                          /* else it's Solaris */
+
+# if ThreadedX
+#  if OSMinorVersion > 3
+#   define SharedThreadReqs /**/
+#   define SharedX11Reqs /**/
+#  endif
+# endif
+# define SharedXmuReqs $(LDPRELIBS) $(XTOOLLIB) $(XLIB)
+# define FixupLibReferences() /**/
+
+# define SharedPamReqs -ldl
+# define SharedPamUnixReqs $(LDPRELIBS) -lpam $(LDPOSTLIBS) -lnsl -lmp -lcmd SharedThreadReqs
+# define SharedPamSampleReqs $(LDPRELIBS) -lpam $(LDPOSTLIBS) SharedThreadReqs
+# define SharedPamDialAuthReqs $(LDPRELIBS) -lpam $(LDPOSTLIBS) SharedThreadReqs
+# define SharedPamRhostsAuthReqs $(LDPRELIBS) -lpam $(LDPOSTLIBS) -lsocket SharedThreadReqs
+# define SharedPamDceAuthReqs $(LDPRELIBS) -lpam $(LDPOSTLIBS) -ldce -lnsl -lsocket SharedThreadReqs
+# define SharedTtReqs -lnsl -lsocket -lintl -ldl -lc -lw
+# define SharedDtSvcReqs $(LDPRELIBS) $(TTLIB) $(XMLIB) $(XTOOLLIB) $(XPLIB) $(XLIB) $(LDPOSTLIBS) SharedThreadReqs -lgen -lc -lsocket -lnsl -ldl
+# define SharedDtMmdbReqs $(LDPRELIBS) $(DTSVCLIB) $(TTLIB) $(XMLIB) $(XTOOLLIB) $(XPLIB) $(XLIB) $(LDPOSTLIBS) SharedThreadReqs -lgen -lc -lsocket -lnsl -ldl
+# define SharedDtSearchReqs -lm -lc
+# define SharedDtWidgetReqs $(LDPRELIBS) $(DTSVCLIB) $(XMLIB) -lintl $(LDPOSTLIBS) -lw -lm -lc
+# define SharedDtHelpReqs $(LDPRELIBS) $(DTSVCLIB) $(XMLIB) $(XTOOLLIB) $(XPLIB) $(XLIB) $(LDPOSTLIBS) -lw -lgen -lm -lc
+# define SharedDtPrintReqs $(LDPRELIBS) $(DTSVCLIB) $(DTHELPLIB) $(XMLIB) -lintl $(LDPOSTLIBS) -lw -lm -lc
+# define SharedDtTermReqs SharedDtHelpReqs -ldl -lgen
+# define SharedDtMrmReqs $(LDPRELIBS) $(DTTERMLIB) $(DTPRINTLIB) $(DTHELPLIB) $(DTWIDGETLIB) $(MRESOURCELIB) $(XMLIB) $(XTOOLLIB) $(XPLIB) $(XLIB) $(LDPOSTLIBS) -lw -lsocket -lnsl -lc
+# define SharedDtMailReqs $(LDPRELIBS) -lw $(CXXLIB) -lm -ldl
+# define SharedCsaReqs $(LDPRELIBS) $(DTSVCLIB) $(XMLIB) SharedXmReqs
+
+# define DtClientExtraLibs -lintl
+
+/* The inbuf paramter to iconv(3) is "const char**", not "char **" */
+ICONV_INBUF_DEFINE = -DICONV_INBUF_CONST=const
+
+# if HasCplusplus
+#  if HasGcc2ForCplusplus
+UNSHARED_CXXLIB = -static -lC
+#  else
+UNSHARED_CXXLIB = -Bstatic -lC -Bdynamic -lm -lc -Bstatic
+#  endif
+# endif
+
+# define IafSysLib     /**/
+# include <sv4Lib.tmpl>
+
+#endif
diff --git a/Xserver/config/cf/sv3Lib.rules b/Xserver/config/cf/sv3Lib.rules
new file mode 100644 (file)
index 0000000..312b101
--- /dev/null
@@ -0,0 +1,232 @@
+XCOMM $XConsortium: sv3Lib.rules /main/1 1996/10/31 14:47:33 kaleb $
+
+
+
+XCOMM $XFree86: xc/config/cf/sv3Lib.rules,v 3.1 1996/12/27 06:50:27 dawes Exp $
+/*
+ * SVR3 shared library rules
+ * Copyright (c) 1992, 1993 by Thomas Wolfram, Berlin, Germany
+ * Author: Thomas Wolfram, thomas@aeon.in-berlin.de, wolf@prz.tu-berlin.de
+ * Conception derived partially from work of Thomas Roell
+ */
+
+#ifndef HasSharedLibraries
+#define HasSharedLibraries NO          /* JUST FOR NOW */
+#endif
+#ifndef ForceNormalLib
+#define ForceNormalLib YES
+#endif
+
+#ifndef SharedLibSM
+#define SharedLibSM HasSharedLibraries
+#endif
+#ifndef SharedLibXau
+#define SharedLibXau HasSharedLibraries
+#endif
+#ifndef SharedLibXdmcp
+#define SharedLibXdmcp HasSharedLibraries
+#endif
+#ifndef SharedLibXi
+#define SharedLibXi HasSharedLibraries
+#endif
+#ifndef SharedLibXie
+#define SharedLibXie HasSharedLibraries
+#endif
+#ifndef SharedLibXtst
+#define SharedLibXtst HasSharedLibraries
+#endif
+#ifndef SharedLibPhigs
+#define SharedLibPhigs HasSharedLibraries
+#endif
+#ifndef SharedLibICE
+#define SharedLibICE HasSharedLibraries
+#endif
+#ifndef SharedLibFS
+#define SharedLibFS HasSharedLibraries
+#endif
+#ifndef SharedLibX11
+#define SharedLibX11 HasSharedLibraries
+#endif
+#ifndef SharedOldX
+#define SharedOldX NO          /* it's obsolete */
+#endif
+#ifndef SharedLibXt
+#define SharedLibXt HasSharedLibraries
+#endif
+#ifndef SharedLibXaw
+#define SharedLibXaw HasSharedLibraries
+#endif
+#ifndef SharedLibXmu
+#define SharedLibXmu HasSharedLibraries
+#endif
+#ifndef SharedLibXext
+#define SharedLibXext HasSharedLibraries
+#endif
+#ifndef SharedLibPex
+#define SharedLibPex NO
+#endif
+
+#ifndef SharedDataSeparation
+#define SharedDataSeparation NO
+#endif
+#ifndef SharedCodeDef
+#define SharedCodeDef /**/
+#endif
+#ifndef SharedLibraryDef
+#define SharedLibraryDef -DSVR3SHLIB
+#endif
+#ifndef ShLibIncludeFile
+#define ShLibIncludeFile <sv3Lib.tmpl>
+#endif
+#ifndef SharedLibraryLoadFlags
+#define SharedLibraryLoadFlags -q
+#endif
+
+#ifndef PositionIndependentCFlags
+# if HasGcc2
+#  define PositionIndependentCFlags -msvr3-shlib  
+# else
+#  define PositionIndependentCFlags /**/
+# endif
+#endif
+
+#ifndef PositionIndependentCplusplusFlags
+# if HasGcc2
+#  define PositionIndependentCplusplusFlags -msvr3-shlib  
+# else
+#  define PositionIndependentCplusplusFlags /**/
+# endif
+#endif
+
+#if 0
+/*
+ * LibCleanDir - helper for cleaning library object subdirectories
+ */
+#ifndef LibCleanDir
+#define LibCleanDir(dir) -@if [ -d dir ]; then \                           @@\
+                (set -x; cd dir; $(RM) *.o *.sd); else exit 0; fi
+#endif
+
+/*
+ * SharedLibObjCompile - compile fragment for shared objects
+ */
+#ifndef SharedLibObjCompile
+#define SharedLibObjCompile(options) $(RM) shared/$@                      @@\
+       cat import.h $*.c >_$*.c                                           @@\
+        $(CC) -c $(ANSICCOPTIONS) $(CCOPTIONS) $(ALLDEFINES) options \     @@\
+$(SHLIBDEF) $(SHAREDCODEDEF) $(PICFLAGS) $(CDEBUGFLAGS) _$*.c              @@\
+       $(MV) _$*.o shared/$@                                              @@\
+       $(RM) _$*.c
+#endif
+
+/*
+ * NormalSharedLibObjCompile - compile fragment for shared object when
+ * a normal library is not being built
+ */
+#ifndef NormalSharedLibObjCompile
+#define NormalSharedLibObjCompile(options) $(RM) $@                        @@\
+       cat import.h $*.c >_$*.c                                           @@\
+        $(CC) -c $(CFLAGS) options $(SHLIBDEF) $(SHAREDCODEDEF) $(PICFLAGS) _$*.c @@\
+       $(MV) _$*.o $@                                                     @@\
+       $(RM) _$*.c
+#endif
+
+
+#ifndef LibraryObjectRule
+#define LibraryObjectRule()                                             @@\
+all::                                                                   @@\
+        _DebuggedLibMkdir()                                             @@\
+        _ProfiledLibMkdir()                                             @@\
+        _SharedLibMkdir()                                               @@\
+                                                                        @@\
+includes::                                                              @@\
+        _DebuggedLibMkdir()                                             @@\
+        _ProfiledLibMkdir()                                             @@\
+        _SharedLibMkdir()                                               @@\
+                                                                        @@\
+.c.o:                                                                   @@\
+        _DebuggedObjCompile($(_NOOP_))                                  @@\
+        _ProfiledObjCompile($(_NOOP_))                                  @@\
+        _SharedObjCompile($(_NOOP_))                                    @@\
+        _NormalObjCompile($(_NOOP_))                                    @@\
+                                                                        @@\
+.SUFFIXES: .sd                                                          @@\
+.c.sd:                                                                  @@\
+        _SharedDatCompile(-DSVR3SHDAT)                                  @@\
+                                                                        @@\
+clean::                                                                 @@\
+        _DebuggedCleanDir()                                             @@\
+        _ProfiledCleanDir()                                             @@\
+        _SharedCleanDir()                                               @@\
+
+#endif /* LibraryObjectRule */
+
+
+/*
+ * InstallSharedLibrary - generate rules to install the shared library.
+ */
+#ifndef InstallSharedLibrary
+#if StripInstalledPrograms
+#define        InstallSharedLibrary(libname,rev,dest)                          @@\
+install:: Concat(lib,libname.rev)                                      @@\
+       MakeDir($(DESTDIR)dest)                                         @@\
+       $(INSTALL) -c $(INSTLIBFLAGS) Concat3(lib,libname,_s.a) $(DESTDIR)dest @@\
+       MakeDir($(DESTDIR)$(LIBDIR)/shlib)                              @@\
+        $(INSTALL) -c $(INSTPGMFLAGS) Concat(lib,libname.rev) \         @@\
+       $(DESTDIR)$(LIBDIR)/shlib                                       @@\
+       strip Concat($(DESTDIR)$(LIBDIR)/shlib/lib,libname.rev)         @@\
+       mcs -d Concat($(DESTDIR)$(LIBDIR)/shlib/lib,libname.rev)
+#else
+#define        InstallSharedLibrary(libname,rev,dest)                          @@\
+install:: Concat(lib,libname.rev)                                      @@\
+       MakeDir($(DESTDIR)dest)                                         @@\
+       $(INSTALL) -c $(INSTLIBFLAGS) Concat3(lib,libname,_s.a) $(DESTDIR)dest @@\
+       MakeDir($(DESTDIR)$(LIBDIR)/shlib)                              @@\
+        $(INSTALL) -c $(INSTPGMFLAGS) Concat(lib,libname.rev) \         @@\
+       $(DESTDIR)$(LIBDIR)/shlib
+#endif
+
+#endif /* InstallSharedLibrary */
+
+/*
+ * InstallSharedLibraryData - generate rules to install the shared library data
+ */
+#ifndef InstallSharedLibraryData
+#define        InstallSharedLibraryData(libname,rev,dest)
+#endif /* InstallSharedLibraryData */
+
+
+/*
+ * SharedLibraryTarget - generate rules to create a shared library;
+ * build it into a different name so that we do not hose people by having
+ * the library gone for long periods.
+ */
+#ifndef SharedLibraryTarget
+#define SharedLibraryTarget(libname,rev,solist,down,up)                        @@\
+AllTarget(Concat(lib,libname.rev))                                     @@\
+                                                                       @@\
+Concat(lib,libname.rev):  solist                                       @@\
+       $(RM) $@ Concat3(lib,libname,_s.a)                              @@\
+        $(CPP) -DDOWN=down ConnectionFlags ShlibDefines Concat(lib,libname.def) | \ @@\
+        sed -e '/^#  *[0-9][0-9]*  *.*$$/d; /^$$/d' >spec.cpp           @@\
+        sed -e '1,/#libraries/d; /#externals/,$$d' spec.cpp | \         @@\
+        nawk '{ system("ar x " $$1 " " $$2 )}'                          @@\
+        echo "#target " Concat($(LIBDIR)/shlib/lib,libname.rev) >spec   @@\
+        sed -e '/#libraries/,$$d' spec.cpp >>spec                             @@\
+        mkshlib -s spec -t $@ -h Concat3(lib,libname,_s.a) $(SHLIBLDFLAGS)    @@\
+        ar rulv Concat3(lib,libname,_s.a) `sed -e '1,/#externals/d' spec.cpp` @@\
+        $(RM) spec.cpp spec                                             @@\
+                                                                       @@\
+clean::                                                                        @@\
+       $(RM) Concat(lib,libname.rev) Concat3(lib,libname,_s.a)
+
+#endif /* SharedLibraryTarget */
+
+/*
+ * SharedLibraryDataTarget - generate rules to create shlib data file;
+ */
+#ifndef SharedLibraryDataTarget
+#define SharedLibraryDataTarget(libname,rev,salist)
+#endif /* SharedLibraryTarget */
+
+#endif
diff --git a/Xserver/config/cf/sv3Lib.tmpl b/Xserver/config/cf/sv3Lib.tmpl
new file mode 100644 (file)
index 0000000..7935321
--- /dev/null
@@ -0,0 +1,77 @@
+XCOMM $XConsortium: sv3Lib.tmpl /main/1 1996/10/31 14:47:35 kaleb $
+
+
+
+XCOMM $XFree86: xc/config/cf/sv3Lib.tmpl,v 3.1 1996/12/27 06:50:28 dawes Exp $
+/*
+ * SVR3 shared library template
+ * Copyright (c) 1992, 1993 by Thomas Wolfram, Berlin, Germany
+ * Author: Thomas Wolfram, thomas@aeon.in-berlin.de, wolf@prz.tu-berlin.de
+ * Conception derived partially from work of Thomas Roell
+ */
+
+#ifndef SharedXlibRev
+#define SharedXlibRev 6.0.0
+#endif
+#ifndef SharedOldXRev
+#define SharedOldXRev 6.0
+#endif
+#ifndef SharedXtRev
+#define SharedXtRev 6.0
+#endif
+#ifndef SharedXawRev
+#define SharedXawRev 6.0
+#endif
+#ifndef SharedXmuRev
+#define SharedXmuRev 6.0
+#endif
+#ifndef SharedXextRev
+#define SharedXextRev 6.0
+#endif
+#ifndef SharedXinputRev
+#define SharedXinputRev 6.0
+#endif
+#ifndef SharedPexRev
+#define SharedPexRev 1.0
+#endif
+
+     SHLIBLDFLAGS = SharedLibraryLoadFlags
+         PICFLAGS = PositionIndependentCFlags
+
+/*
+ * and now a little bit of magic for using imake without source tree; if we
+ * are using shared libraries, we really do not need to depend on anything
+ */
+#if SharedLibXext
+  DEPEXTENSIONLIB = _UseCat($(USRLIBDIR),$(EXTENSIONSRC)/lib,/libXext_s.a)
+     EXTENSIONLIB = LoaderLibPrefix _Use(-lXext_s, $(DEPEXTENSIONLIB))
+#endif
+#if SharedLibX
+          DEPXLIB = $(DEPEXTENSIONLIB) _UseCat($(USRLIBDIR),$(XLIBSRC),/libX11_s.a)
+             XLIB = $(EXTENSIONLIB) LoaderLibPrefix _Use(-lX11_s,$(XLIBSRC)/libX11_s.a)
+#endif
+#if SharedLibXmu
+        DEPXMULIB = _UseCat($(USRLIBDIR),$(XMUSRC),/libXmu_s.a)
+           XMULIB = LoaderLibPrefix _Use(-lXmu_s,$(DEPXMULIB))
+#endif
+#if SharedOldLibX
+       DEPOLDXLIB = _UseCat($(USRLIBDIR),$(OLDXLIBSRC),/liboldX_s.a)
+          OLDXLIB = LoaderLibPrefix _Use(-loldX_s,$(DEPOLDXLIB))
+#endif
+#if SharedLibXt
+      DEPXTOOLLIB = _UseCat($(USRLIBDIR),$(TOOLKITSRC),/libXt_s.a)
+         XTOOLLIB = LoaderLibPrefix _Use(-lXt_s,$(DEPXTOOLLIB))
+#endif
+#if SharedLibXaw
+        DEPXAWLIB = _UseCat($(USRLIBDIR),$(AWIDGETSRC),/libXaw_s.a)
+           XAWLIB = LoaderLibPrefix _Use(-lXaw_s,$(DEPXAWLIB))
+#endif
+#if SharedLibXinput
+         DEPXILIB = _UseCat($(USRLIBDIR),$(XILIBSRC),/libXi_s.a)
+            XILIB = LoaderLibPrefix _Use(-lXi_s,$(DEPXILIB))
+#endif
+#if SharedLibPhigs
+      DEPPHIGSLIB = _UseCat($(USRLIBDIR),$(PHIGSLIBSRC),/libphigs_s.a)
+         PHIGSLIB = LoaderLibPrefix _Use(-lphigs_s,$(DEPPHIGSLIB))
+#endif
+
diff --git a/Xserver/config/cf/sv4Lib.rules b/Xserver/config/cf/sv4Lib.rules
new file mode 100644 (file)
index 0000000..3860f0d
--- /dev/null
@@ -0,0 +1,137 @@
+XCOMM $XConsortium: sv4Lib.rules /main/18 1996/09/28 16:13:29 rws $
+XCOMM $XFree86: xc/config/cf/sv4Lib.rules,v 3.4 1996/12/23 05:50:34 dawes Exp $
+
+/*
+ * SVR4 shared library rules
+ */
+
+#ifndef HasSharedLibraries
+# define HasSharedLibraries YES
+#endif
+#ifndef SharedDataSeparation
+# define SharedDataSeparation NO
+#endif
+#ifndef SharedCodeDef
+# define SharedCodeDef /**/
+#endif
+#ifndef SharedLibraryDef
+# define SharedLibraryDef /**/
+#endif
+#ifndef ShLibIncludeFile
+# define ShLibIncludeFile <sv4Lib.tmpl>
+#endif
+#ifndef SharedLibraryLoadFlags
+# define SharedLibraryLoadFlags -G -z text
+#endif
+#ifndef PositionIndependentCFlags
+# if HasGcc2
+#  define PositionIndependentCFlags -fpic
+# else
+#  define PositionIndependentCFlags -K PIC
+# endif
+#endif
+#ifndef PositionIndependentCplusplusFlags
+# if HasGcc2ForCplusplus
+#  define PositionIndependentCplusplusFlags -fpic
+# else
+#  define PositionIndependentCplusplusFlags -K PIC
+# endif
+#endif
+#ifndef UseExportLists
+# define UseExportLists NO
+#endif
+
+/*
+ * InstallSharedLibrary - generate rules to install the shared library.
+ */
+#ifndef InstallSharedLibrary
+#if StripInstalledPrograms
+# define InstallSharedLibrary(libname,rev,dest)                                @@\
+install:: Concat(lib,libname.so.rev)                                   @@\
+       MakeDir($(DESTDIR)dest)                                         @@\
+       $(INSTALL) $(INSTALLFLAGS) $(INSTLIBFLAGS) Concat(lib,libname.so.rev) $(DESTDIR)dest @@\
+       mcs -d Concat($(DESTDIR)dest/lib,libname.so.rev)                @@\
+       $(RM) Concat($(DESTDIR)dest/lib,libname.so)                     @@\
+       cd $(DESTDIR)dest; $(LN) Concat(lib,libname.so.rev) Concat(lib,libname.so)
+#else
+# define InstallSharedLibrary(libname,rev,dest)                                @@\
+install:: Concat(lib,libname.so.rev)                                   @@\
+       MakeDir($(DESTDIR)dest)                                         @@\
+       $(INSTALL) $(INSTALLFLAGS) $(INSTLIBFLAGS) Concat(lib,libname.so.rev) $(DESTDIR)dest @@\
+       $(RM) Concat($(DESTDIR)dest/lib,libname.so)                     @@\
+       cd $(DESTDIR)dest; $(LN) Concat(lib,libname.so.rev) Concat(lib,libname.so)
+#endif
+
+#endif /* InstallSharedLibrary */
+
+/*
+ * InstallSharedLibraryData - generate rules to install the shared library data
+ */
+#ifndef InstallSharedLibraryData
+# define InstallSharedLibraryData(libname,rev,dest)
+#endif /* InstallSharedLibraryData */
+
+#ifndef LinkWithExports
+# if UseExportLists
+#  define LinkWithExports(libname,rev,solist,down,up) \
+       (cd down; $(CCENVSETUP) $(LD) -o up/$@~ $(SHLIBLDFLAGS) -h $@ solist $(REQUIREDLIBS))   @@\
+       if [ -f Concat(lib,libname.elist) ]; then \                     @@\
+           $(RM) down/$@.exports $@.list; \                            @@\
+           $(CPP) $(ALLINCLUDES) $(EXTRA_DEFINES) $(PROTO_DEFINES) $(THREADS_DEFINES) $(DEFINES) Concat(lib,libname.elist) | CppSedMagic >$@.list; \   @@\
+           $(EXPORTLISTGEN) $@~ $@.list > down/$@.exports; \           @@\
+           (cd down; $(CCENVSETUP) $(LD) -o up/$@~ $(SHLIBLDFLAGS) -h $@ ShlibExportListOpt($@.exports) solist $(REQUIREDLIBS)); \     @@\
+           $(RM) down/$@.exports $@.list; \                            @@\
+       fi;
+# else
+#  define LinkWithExports(libname,rev,solist,down,up) \
+       (cd down; $(CCENVSETUP) $(LD) -o up/$@~ $(SHLIBLDFLAGS) -h $@ solist $(REQUIREDLIBS))
+# endif
+#endif
+
+/*
+ * SharedLibraryTarget - generate rules to create a shared library;
+ * build it into a different name so that we do not hose people by having
+ * the library gone for long periods.
+ */
+#ifndef SharedLibraryTarget
+# define SharedLibraryTarget(libname,rev,solist,down,up)               @@\
+AllTarget(Concat(lib,libname.so.rev))                                  @@\
+                                                                       @@\
+Concat(lib,libname.so.rev):  solist $(EXTRALIBRARYDEPS)                        @@\
+       $(RM) $@~                                                       @@\
+       LinkWithExports(libname,rev,solist,down,up)                     @@\
+       $(RM) $@                                                        @@\
+       $(MV) $@~ $@                                                    @@\
+       $(RM) Concat(lib,libname.so)                                    @@\
+       $(LN) $@ Concat(lib,libname.so)                                 @@\
+       LinkBuildLibrary($@)                                            @@\
+       LinkBuildLibrary(Concat(lib,libname.so))                        @@\
+                                                                       @@\
+clean::                                                                        @@\
+       $(RM) Concat(lib,libname.so.rev) Concat(lib,libname.so)
+
+#endif /* SharedLibraryTarget */
+
+
+#ifndef SharedDepModuleTarget
+#define SharedDepModuleTarget(name,deps,solist)                                @@\
+AllTarget(name)                                                                @@\
+                                                                       @@\
+name: deps                                                             @@\
+       $(RM) $@~                                                       @@\
+       $(LD) -o $@~ $(SHLIBLDFLAGS) solist $(REQUIREDLIBS)             @@\
+       $(RM) $@                                                        @@\
+       $(MV) $@~ $@                                                    @@\
+                                                                       @@\
+clean::                                                                        @@\
+       $(RM) name
+
+#endif /* SharedDepModuleTarget */
+
+
+/*
+ * SharedLibraryDataTarget - generate rules to create shlib data file;
+ */
+#ifndef SharedLibraryDataTarget
+# define SharedLibraryDataTarget(libname,rev,salist)
+#endif /* SharedLibraryTarget */
diff --git a/Xserver/config/cf/sv4Lib.tmpl b/Xserver/config/cf/sv4Lib.tmpl
new file mode 100644 (file)
index 0000000..503ae12
--- /dev/null
@@ -0,0 +1,77 @@
+XCOMM $XConsortium: sv4Lib.tmpl /main/23 1996/12/04 10:11:01 swick $
+
+/*
+ * SVR4 shared library template
+ */
+
+XCOMM $XFree86: xc/config/cf/sv4Lib.tmpl,v 3.3 1996/12/30 13:57:39 dawes Exp $
+
+/* SVR4 shared libraries are deficient in link semantics */
+XMULIBONLY = -lXmu
+#ifndef FixupLibReferences
+# define FixupLibReferences()                                          @@\
+XMULIB = $(XMULIBONLY) -z nodefs
+#endif
+#ifndef XawClientLibs
+# define XawClientLibs $(XAWLIB) $(XMULIBONLY) $(XTOOLLIB) $(XLIB)
+#endif
+
+#if 0
+/* This causes problems on SVR4.0 */
+#ifndef SharedICEReqs
+# define SharedICEReqs -lsocket
+#endif
+#endif
+
+#if ThreadedX
+# ifndef SharedThreadReqs
+#  define SharedThreadReqs -lthread
+# endif
+# ifndef SharedX11Reqs
+#  define SharedX11Reqs -lthread
+# endif
+#else
+# ifndef SharedThreadReqs
+#  define SharedThreadReqs
+# endif
+#endif
+
+#ifndef SharedXReqs
+# define SharedXReqs $(XTOOLLIB) $(XPLIB) $(XLIB) SharedThreadReqs $(LDPOSTLIBS)
+#endif
+
+#ifndef SharedXmReqs
+# define SharedXmReqs $(LDPRELIBS) SharedXReqs -lgen -lsocket -lnsl -lw -lc
+#endif
+
+#ifndef SharedMrmReqs
+# define SharedMrmReqs $(LDPRELIBS) $(XMLIB) SharedXReqs -lgen -lsocket -lnsl -lw -lc
+#endif
+
+#ifndef SharedUilReqs
+# define SharedUilReqs $(LDPRELIBS) $(MRESOURCELIB) $(XMLIB) SharedXReqs -lgen -lsocket -lnsl -lw -lc
+#endif
+
+#ifndef SharedDtSvcReqs
+# define SharedDtSvcReqs $(LDPRELIBS) $(TTLIB) $(XMLIB) SharedXReqs
+#endif
+
+#ifndef SharedDtMmdbReqs
+# define SharedDtMmdbReqs $(LDPRELIBS) $(DTSVCLIB) $(TTLIB) $(XMLIB) SharedXReqs
+#endif
+
+#ifndef SharedDtHelpReqs
+# define SharedDtHelpReqs $(LDPRELIBS) $(DTSVCLIB) $(XMLIB) SharedXReqs
+#endif
+
+#ifndef DtClientExtraLibs
+# define DtClientExtraLibs -lresolv
+#endif
+
+REGEXSYSLIB = -lgen
+DYNLIBSYSLIB = -ldl
+
+#ifndef IafSysLib
+# define IafSysLib     -liaf
+#endif
+IAFSYSLIB = IafSysLib
diff --git a/Xserver/config/cf/svr3.cf b/Xserver/config/cf/svr3.cf
new file mode 100644 (file)
index 0000000..920b894
--- /dev/null
@@ -0,0 +1,335 @@
+XCOMM $XConsortium: svr3.cf /main/1 1996/10/31 14:47:37 kaleb $
+
+
+
+XCOMM $XFree86: xc/config/cf/svr3.cf,v 3.9.2.1 1997/05/24 13:38:09 dawes Exp $
+
+#ifndef HasGcc
+#define HasGcc      YES
+#endif
+#ifndef HasGcc2
+#define HasGcc2     YES
+#endif
+#ifndef GccUsesGas
+#define GccUsesGas  NO
+#endif
+#ifndef UseGas
+#define UseGas      NO
+#endif
+#ifndef GnuCpp
+#define GnuCpp      NO
+#endif
+
+#ifndef Gcc2MOption
+# if HasGcc2
+#  define Gcc2MOption /* */
+# else
+#  define Gcc2MOption /* */
+# endif
+#endif
+
+#ifndef HasShadowPasswd
+# define HasShadowPasswd       YES
+#endif
+
+#ifndef HasLibCrypt
+# define HasLibCrypt           NO
+#endif
+
+#ifndef HasSVR3mmapDrv
+# define HasSVR3mmapDrv                NO
+#endif
+
+#if HasSVR3mmapDrv
+# define SVR3mmapFlags         -DHAS_SVR3_MMAPDRV
+#else
+# define SVR3mmapFlags                 /**/
+#endif
+
+#ifndef HasSockets
+# define HasSockets            YES
+#endif
+
+#ifndef XmanSearchPath
+#define XmanSearchPath         /usr/share/man
+#endif
+
+/*
+ *     Most SVR3 do not have symbolic links, only some of the newer ones
+ */
+#ifndef HasSymLinks
+# define HasSymLinks NO
+#endif
+
+#ifndef StripInstalledPrograms
+# define StripInstalledPrograms        YES
+#endif
+
+#ifndef MotifBC
+# define MotifBC               YES
+#endif
+
+#ifndef CompressAllFonts
+# define CompressAllFonts      YES
+#endif
+
+/*
+ * A default OS name
+ */
+#ifndef OSName
+#ifdef i386Architecture
+#define        OSName  UNIX System V/386 Release 3
+#else
+#define        OSName  UNIX System V Release 3
+#endif
+#endif
+#ifndef OSVendor
+#define OSVendor /**/
+#endif
+
+/*
+ * The default version will be 3.0.0 which should be
+ * the least common denominator of all SVR3
+ */
+
+#ifndef OSMajorVersion
+#define        OSMajorVersion  3
+#endif
+#ifndef OSMinorVersion
+#define        OSMinorVersion  0
+#endif
+#ifndef OSTeenyVersion
+#define        OSTeenyVersion  0
+#endif
+#ifndef BootstrapCFlags
+#ifdef SYSV386
+#define BootstrapCFlags         -DSYSV -DSYSV386
+#else
+#define BootstrapCFlags         -DSYSV
+#endif
+#endif
+
+/* Some stuff that all SYSV's should have */
+
+#define SystemV        YES
+
+#ifndef NeedBerklib
+#define NeedBerklib    YES
+#endif
+#ifndef HasPoll
+#define HasPoll                YES
+#endif
+#ifndef SVR3Architecture
+#define SVR3Architecture
+#endif
+#ifndef PatheticCpp
+#define PatheticCpp    YES
+#endif
+
+#ifndef StandardDefines
+#ifdef i386Architecture
+#define StandardDefines                -DSYSV OSDefines -Di386
+#else
+#define StandardDefines                -DSYSV OSDefines
+#endif
+#endif
+
+#ifndef ServerOSDefines
+# ifdef i386Architecture
+#  define ServerOSDefines -DDDXTIME XFree86ServerOSDefines -DPART_NET
+# else
+#  define ServerOSDefines -DDDXTIME
+# endif
+#endif
+
+#ifndef XawI18nDefines
+# define XawI18nDefines          -DUSE_XWCHAR_STRING
+#endif
+
+#ifndef DefaultCDebugFlags
+# if HasGcc2
+#  if defined(i386Architecture)
+#   define DefaultCDebugFlags DefaultGcc2i386Opt
+#  else
+#   define DefaultCDebugFlags -O2
+#  endif
+# else
+#  define DefaultCDebugFlags -O
+# endif
+#endif
+
+#ifndef LdCombineFlags
+#define LdCombineFlags -r
+#endif
+
+#if HasGcc
+# if HasGcc2
+#  define DefaultCCOptions Gcc2MOption -DNO_ASM -fpcc-struct-return \
+                          -fwritable-strings
+#  define LibraryCCOptions Gcc2MOption -DNO_ASM -fpcc-struct-return
+#  if defined(i386Architecture)
+#   define OptimizedCDebugFlags DefaultGcc2i386Opt
+#  else
+#   define OptimizedCDebugFlags -O2
+#  endif
+# else
+#  define DefaultCCOptions -DNO_ASM -fpcc-struct-return -fwritable-strings
+#  define LibraryCCOptions -DNO_ASM -fpcc-struct-return
+#  define OptimizedCDebugFlags -O -fstrength-reduce
+# endif
+# define ShlibDefines -D__GNUC__ $(XDMAUTHDEFS)
+#else
+# define ShlibDefines $(XDMAUTHDEFS)
+#endif
+
+#ifndef Malloc0ReturnsNull
+#define Malloc0ReturnsNull     YES
+#endif
+
+#ifndef SocketLibraries
+# define SocketLibraries /**/
+#endif
+#ifndef LocalLibraries
+# define LocalLibraries /**/
+#endif
+#ifndef ExtraLibraries
+# if HasSockets
+#  define ExtraLibraries SocketLibraries LocalLibraries
+# else
+#  define ExtraLibraries LocalLibraries
+# endif
+#endif
+
+#if RemoveDSDENroffMacros
+# define RemoveDSDENroffMacrosCmd sed -e '/^\.D[S|E]$$/d' 
+#else
+# define RemoveDSDENroffMacrosCmd cat
+#endif
+
+#ifndef ConnectionFlags
+# define ConnectionFlags       -DLOCALCONN -DTCPCONN
+#endif
+
+#ifndef FormattedManPages
+# define FormattedManPages     YES
+#endif
+
+#ifndef ManSuffix
+# define ManSuffix               1x
+# define ManDir                        $(MANSOURCEPATH)1
+#endif
+#ifndef LibManSuffix
+# define LibManSuffix            3x
+# define LibmanDir             $(MANSOURCEPATH)3
+#endif
+#ifndef FileManSuffix
+# define FileManSuffix           4
+#endif
+
+/*
+ * Compress manual pages, default on ISC and SCO
+ */
+#ifndef CompressManPages
+# define CompressManPages        YES
+#endif
+
+/*
+ * The .DS and .DE macros used in some manual pages are obsolete
+ * in the often used ISC's Textprocessing Workbench 2.1.0 and break it,
+ * so it's better to remove these previously
+ */
+#ifndef RemoveDSDENroffMacros
+# define RemoveDSDENroffMacros   NO
+#endif
+
+#if RemoveDSDENroffMacros
+# define RemoveDSDENroffMacrosCmd sed -e '/^\.D[S|E]$$/d' 
+#else
+# define RemoveDSDENroffMacrosCmd cat
+#endif
+
+#ifndef CompressManCmd
+# define CompressManCmd @true
+#endif
+
+     RMDSDEMACCMD = RemoveDSDENroffMacrosCmd
+   COMPRESSMANCMD = CompressManCmd
+
+#if FormattedManPages
+
+#ifndef InstallManPageLong
+#define InstallManPageLong(file,destdir,dest)                           @@\
+install.man:: file.man                                                  @@\
+        MakeDir($(DESTDIR)destdir)                                      @@\
+        $(RM) $(DESTDIR)destdir/dest.$(MANSUFFIX)*                      @@\
+        $(RMDSDEMACCMD) file.man | neqn | nroff -man >/tmp/file.man     @@\
+        $(INSTALL) -c $(INSTMANFLAGS) /tmp/file.man $(DESTDIR)destdir/dest.$(MANSUFFIX) @@\
+        -$(COMPRESSMANCMD) $(DESTDIR)destdir/dest.$(MANSUFFIX)          @@\
+        $(RM) /tmp/file.man
+#endif
+
+#ifndef InstallGenManPageLong
+#define InstallGenManPageLong(file,destdir,dest,suffix)                 @@\
+install.man:: file.man                                                  @@\
+        MakeDir($(DESTDIR)destdir)                                      @@\
+        $(RM) $(DESTDIR)destdir/dest.suffix*                            @@\
+        $(RMDSDEMACCMD) file.man | neqn | nroff -man >/tmp/file.man     @@\
+        $(INSTALL) -c $(INSTMANFLAGS) /tmp/file.man $(DESTDIR)destdir/dest.suffix @@\
+        -$(COMPRESSMANCMD) $(DESTDIR)destdir/dest.suffix                @@\
+        $(RM) /tmp/file.man
+#endif
+
+#ifndef InstallMultipleMan
+#define InstallMultipleMan(list,dest)                                   @@\
+install.man:: list                                                      @@\
+       MakeDir($(DESTDIR)dest)                                         @@\
+        @case '${MFLAGS}' in *[i]*) set +e;; esac; \                    @@\
+        for i in list; do \                                             @@\
+                (set -x; \                                              @@\
+                MNAME=`echo $$i | cut -f1 -d.`; \                      @@\
+                $(RM) $(DESTDIR)dest/$${MNAME}*; \                      @@\
+                $(RMDSDEMACCMD) $$i | neqn | nroff -man >/tmp/$$i; \    @@\
+                $(INSTALL) -c $(INSTMANFLAGS) /tmp/$$i $(DESTDIR)dest/$${MNAME}.$(MANSUFFIX); \      @@\
+                $(COMPRESSMANCMD) $(DESTDIR)dest/$${MNAME}.$(MANSUFFIX); \  @@\
+                $(RM) /tmp/$$i); \                                      @@\
+        done
+#endif
+
+/*
+ * InstallManPageAliases - generate rules to install manual page aliases.
+ * (Make hard links on SVR3.)
+ */
+#ifndef InstallManPageAliases
+#define InstallManPageAliases(file,destdir,aliases)                     @@\
+install.man::                                                           @@\
+        @(SUFFIX=`echo $(DESTDIR)destdir/file.* | cut -f2,3 -d.`; \     @@\
+        for i in aliases; do (set -x; \                                 @@\
+        $(RM) $(DESTDIR)destdir/$$i.*; \                                @@\
+        (cd $(DESTDIR)destdir; $(LN) file.$${SUFFIX} \                  @@\
+        $$i.$${SUFFIX})); \                                             @@\
+        done)
+#endif
+
+#ifndef InstallGenManPageAliases
+#define InstallGenManPageAliases(file,destdir,suffix,aliases)          @@\
+       InstallManPageAliases(file,destdir,aliases)
+#endif
+
+#endif /* FormattedManPages */
+
+/* If you have trouble with make bombing out in Xlib, try uncommenting this. */
+/* You will not get dependencies as a result, but better than nothing. */
+#ifndef MakeHashTableBug
+#define MakeHashTableBug        NO
+#endif
+
+#if MakeHashTableBug
+#define DependTarget3(srcs1,srcs2,srcs3)
+#endif
+
+#include <sv3Lib.rules>
+
+#ifdef i386Architecture
+#include <xfree86.cf>
+#endif
+
diff --git a/Xserver/config/cf/svr4.cf b/Xserver/config/cf/svr4.cf
new file mode 100644 (file)
index 0000000..93f60e0
--- /dev/null
@@ -0,0 +1,214 @@
+XCOMM $TOG: svr4.cf /main/17 1997/06/08 20:08:31 kaleb $
+XCOMM $XFree86: xc/config/cf/svr4.cf,v 3.25.2.2 1997/07/05 15:55:30 dawes Exp $
+/*
+ * A default OS name
+ */
+#ifndef OSName
+#ifdef i386Architecture
+#define        OSName  UNIX System V/386 Release 4
+#else
+#define        OSName  UNIX System V Release 4
+#endif
+#endif
+#ifndef OSVendor
+#define OSVendor /**/
+#endif
+
+/*
+ * The default version will be 4.0.0 which should be
+ * the least common denominator of all SVR4
+ */
+
+#ifndef OSMajorVersion
+#define        OSMajorVersion  4
+#endif
+#ifndef OSMinorVersion
+#define        OSMinorVersion  0
+#endif
+#ifndef OSTeenyVersion
+#define        OSTeenyVersion  0
+#endif
+#ifndef BootstrapCFlags
+#ifdef i386Architecture
+#define BootstrapCFlags                -DSVR4 -Di386
+#else
+#ifdef SYSV386
+#define BootstrapCFlags                -DSVR4 -Di386
+#else
+#define BootstrapCFlags                -DSVR4
+#endif
+#endif
+#endif
+
+/* Some stuff that all SVR4s should have */
+
+#define SystemV4               YES
+#ifndef HasLdRunPath
+#define HasLdRunPath           YES
+#endif
+#define HasPoll                        YES
+#ifndef SVR4Architecture
+#define SVR4Architecture
+#endif
+#ifndef PatheticCpp
+#define PatheticCpp            YES
+#endif
+#define Malloc0ReturnsNull     YES             /* in case -lmalloc used */
+
+/*
+ * Here are the default paths to use to pick up tools for building.
+ */
+#ifndef ArCmdBase
+#define        ArCmdBase       /usr/ccs/bin/ar
+#endif
+#ifndef AsCmd
+#define        AsCmd   /usr/ccs/bin/as
+#endif
+#ifndef CppCmd
+#define        CppCmd  /usr/ccs/lib/cpp
+#endif
+#ifndef LdCmd
+#define        LdCmd   /usr/ccs/bin/ld
+#endif
+#ifndef LexCmd
+#define        LexCmd  /usr/ccs/bin/lex
+#endif
+#ifndef YaccCmd
+#define        YaccCmd /usr/ccs/bin/yacc
+#endif
+#ifndef MkdirHierCmd
+#define MkdirHierCmd mkdir -p
+#endif
+
+#ifndef SunArchitecture
+/*
+ * These come from usl.cf, and at least some are required by other
+ * SVR4 versions
+ */
+#ifndef UseLocalRegex
+#define UseLocalRegex          YES
+#endif
+#ifndef XmDefines
+#define XmDefines              \
+       -DNO_REGCOMP -DNEED_STRCASECMP \
+       -DSUPPORT_ZERO_WIDTH -DHAS_WIDECHAR_FUNCTIONS
+#endif
+#ifndef DtSvcDefines
+#define DtSvcDefines           -DXK_MISCELLANY -DMULTIBYTE -DNO_REGCOMP
+#endif
+#ifndef DtSearchDefines
+#define DtSearchDefines                -DI18N_MSG DtSvcDefines
+#endif
+#ifndef DtWidgetDefines
+#define DtWidgetDefines                DtSearchDefines
+#endif
+#ifndef DtPrintDefines
+#define DtPrintDefines         DtSearchDefines
+#endif
+#ifndef HasStrcasecmp
+#define HasStrcasecmp          NO
+#endif
+#endif
+
+#ifndef SunArchitecture
+#if (OSMinorVersion == 0)
+#ifndef XawI18nDefines
+#define XawI18nDefines         -DUSE_XWCHAR_STRING
+#endif
+#endif
+#endif
+
+#ifndef HasGcc2
+#define HasGcc2 NO
+#endif
+#ifndef HasGcc
+#define HasGcc HasGcc2
+#endif
+
+#ifdef i386Architecture
+#ifndef SunArchitecture
+#if (OSMinorVersion > 2) || ((OSMinorVersion == 2) && (OSTeenyVersion >= 2))
+#ifndef StandardDefines
+#define StandardDefines                -DSVR4 -DSVR42MP -Di386
+#endif
+#ifndef HasParallelMake
+#define HasParallelMake                YES
+#endif
+#if HasParallelMake
+#define ParallelDefines                -P -B
+#define MutexDirective         .MUTEX
+#endif
+#else /* SVR4 < 4.2.2 */
+#ifndef StandardDefines
+#define StandardDefines                -DSVR4 -Di386
+#endif
+#endif
+#endif
+#ifndef ToolkitStringsABIOptions
+#define ToolkitStringsABIOptions -intelabi -earlyR6bc
+#endif
+#ifndef DefaultCCOptions
+#if !HasGcc
+#define DefaultCCOptions -Xa -Dasm=__asm
+#else
+#ifdef UseInstalled
+#define DefaultCCOptions /**/
+#else
+#define DefaultCCOptions -ansi -pedantic
+#endif
+#endif
+#endif
+#ifndef DefaultCDebugFlags
+#if HasGcc
+#if HasGcc2
+#define DefaultCDebugFlags DefaultGcc2i386Opt
+#else
+#define DefaultCDebugFlags -O2
+#endif
+#else
+#define DefaultCDebugFlags -O
+#endif
+#endif
+#ifndef ServerOSDefines
+#define ServerOSDefines -DDDXTIME XFree86ServerOSDefines
+#endif
+#ifndef BuildDynamicLoading
+#define BuildDynamicLoading NO
+#endif
+#if BuildDynamicLoading
+#define ServerExtraSysLibs -ldl
+#endif
+#endif
+
+/*
+ * The TLI interface is more robust on most SVR4s, so it will be the default.
+ */
+#if !defined(SunArchitecture)
+#ifndef ConnectionFlags
+#define ConnectionFlags        -DSTREAMSCONN -DUNIXCONN -DLOCALCONN
+#endif
+#endif
+
+#ifndef ManSuffix
+#define ManSuffix               1x
+#define ManDir                 $(MANSOURCEPATH)1
+#endif
+#ifndef LibManSuffix
+#define LibManSuffix            3x
+#define LibmanDir              $(MANSOURCEPATH)3
+#endif
+#ifndef FileManSuffix
+#define FileManSuffix           4
+#endif
+
+#ifndef StaticLibrary
+#if !HasGcc
+#define StaticLibrary(libpath,libname) -B static Concat(-L,libpath) Concat(-l,libname) -B dynamic
+#endif
+#endif
+
+#ifdef i386Architecture
+#include <xfree86.cf>
+#endif
+
+#include <sv4Lib.rules>
diff --git a/Xserver/config/cf/ultrix.cf b/Xserver/config/cf/ultrix.cf
new file mode 100644 (file)
index 0000000..a9c8a18
--- /dev/null
@@ -0,0 +1,77 @@
+XCOMM platform:  $XConsortium: ultrix.cf /main/68 1996/09/28 16:13:46 rws $
+
+#ifndef OSName
+# define OSName                DefaultOSName
+#endif
+#ifndef OSMajorVersion
+# define OSMajorVersion        DefaultOSMajorVersion
+#endif
+#ifndef OSMinorVersion
+# define OSMinorVersion DefaultOSMinorVersion
+#endif
+XCOMM operating system: OSName (OSMajorVersion.OSMinorVersion)
+
+#define HasNdbm YES
+#define HasPutenv YES
+#define HasShm YES
+#define LintLibFlag -o
+#define LintOpts -ax
+
+#if HasDECnet
+#define ExtraLibraries -ldnet
+#endif
+
+#if ThreadedX
+/* if you want to experiment, turn this on, but no guarantees */
+#define HasThreadSafeAPI       NO
+#define HasPosixThreads                YES
+#define ThreadPreStdAPIDefines -DXPRE_STANDARD_API
+#define ExtraLibraries         -lpthreads -li
+#endif
+
+#ifdef VaxArchitecture
+#define PexNativeFPFormat PEXDEC_F_Floating
+#define NativeFPFormat DEC_F_Float
+#define UnalignedReferencesAllowed YES        /* if arbitrary deref is okay */
+#define BuildServer NO
+#endif
+
+#ifdef MipsArchitecture
+#if OSMajorVersion > 4 || (OSMajorVersion == 4 && OSMinorVersion >= 2)
+/*#define XdecServer YES
+#define ServerOSDefines -DDDXTIME*/
+/* Even under ultrix 4.2, the compiler miscompiles some alloca calls */
+#define AllocateLocalDefines /* -DINCLUDE_ALLOCA_H */
+#else
+#define BuildServer NO
+#define AllocateLocalDefines /**/
+#endif
+#if !HasGcc
+#define NeedFunctionPrototypes YES
+#define PexCCOptions -Wf,-XNp15000,-XNd15000
+/*
+ * NormalLibObjCompile - compile fragment for a library object file
+ *     do ld -x to remove line number symbols for libraries
+ */
+#define NormalLibObjCompile(options) $(RM) $@ $*.os \                  @@\
+       && $(CC) -c options $(CFLAGS) $*.c \                            @@\
+       && $(LD) $(LDSTRIPFLAGS) -r $@ -o $*.os \                       @@\
+       && $(MV) $*.os $@
+#endif
+#endif
+
+#if HasGcc
+#ifdef VaxArchitecture
+#define CcCmd gcc -ansi -Dvax -Dultrix -fpcc-struct-return
+#endif
+#ifdef MipsArchitecture
+#define CcCmd gcc -ansi -Dmips -Dultrix -fpcc-struct-return
+#endif
+#define ServerCCOptions /* */
+#define AllocateLocalDefines /* */
+#endif
+
+#define ServerExtraDefines AllocateLocalDefines
+#define HasWChar32 YES
+
+#define MotifDefines           -DNO_REGEX -DNO_REGCOMP -DNO_CONST
diff --git a/Xserver/config/cf/usl.cf b/Xserver/config/cf/usl.cf
new file mode 100644 (file)
index 0000000..ed41623
--- /dev/null
@@ -0,0 +1,112 @@
+XCOMM platform:  $TOG: usl.cf /main/50 1997/04/17 14:11:39 barstow $
+
+
+
+
+XCOMM platform:  $XFree86: xc/config/cf/usl.cf,v 3.13.2.1 1997/05/03 09:43:10 dawes Exp $
+
+#ifndef OSName
+# define OSName                DefaultOSName
+#endif
+#ifndef OSMajorVersion
+# define OSMajorVersion        DefaultOSMajorVersion
+#endif
+#ifndef OSMinorVersion
+# define OSMinorVersion        DefaultOSMinorVersion
+#endif
+#ifndef OSTeenyVersion
+# define OSTeenyVersion        DefaultOSTeenyVersion
+#endif
+XCOMM operating system: OSName (OSMajorVersion./**/OSMinorVersion./**/OSTeenyVersion)
+
+#ifndef  CcCmd
+# define CcCmd                 /usr/ccs/bin/cc
+#endif
+#ifndef  CplusplusCmd
+# define CplusplusCmd          /usr/ccs/bin/CC
+#endif
+#ifndef  CplusplusFilt
+# define CplusplusFilt         /usr/ccs/bin/c++filt
+#endif
+#ifndef  CplusplusDependIncludes
+# define CplusplusDependIncludes       -I/usr/include/CC
+#endif
+
+#define BootstrapCFlags                /* none needed */
+#define StandardDefines                -DUSL -DSVR4 -Di386
+#define NeedWidePrototypes     NO      /* experimental */
+#define ServerExtraDefines     -D__USLC__ XFree86ServerDefines
+#define ServerOSDefines                -DDDXTIME XFree86ServerOSDefines
+#define ToolkitStringsABIOptions -intelabi
+#if OSMajorVersion < 2
+#define XawI18nDefines         -DHAS_WCTYPE_H -DHAS_ISW_FUNCS
+#else
+#define XawI18nDefines         -DHAS_WCHAR_H -DHAS_ISW_FUNCS
+#endif
+#if OSTeenyVersion > 1
+# define ExtraLibraries                -lsocket -lnsl -lgen -lw
+# define ThreadedX             YES
+# define HasThreadSafeAPI      NO
+/* UnixWare does not have MT-safe pwd routines. */
+# define MTSafeAPIDefines      \
+-DXUSE_MTSAFE_API -DXNO_MTSAFE_PWDAPI -DXNO_MTSAFE_GRPAPI
+# define SystemMTDefines       -D_REENTRANT
+# define ThreadsLibraries      -lthread
+# define ThreadsCplusplusLibraries     -lthread
+# define DefaultCCOptions      -W0,-2A -Xa -Dasm=__asm
+#endif
+#define BuildLibPathVar          LD_LIBRARY_PATH
+
+#ifndef UseExportLists
+# define UseExportLists YES
+#endif
+
+#define GencatFlags            -m
+
+#include <svr4.cf>
+
+/*
+ * When generating templates the UnixWare 2.02 C++ compiler leaves
+ * protected .i files behind.  Remove them so other people can
+ * compile too.
+ */
+#ifndef ObjectCplusplusCompile
+#define ObjectCplusplusCompile(options) RemoveFiles($@ $*.i)           @@\
+       ClearmakeOSName \
+       $(CXX) -c $(CXXFLAGS) options $*.CCsuf
+#endif
+
+/* USL does not have a shared regex library. */
+#define UseLocalRegex          YES
+
+#define XmDefines              \
+       -DNO_REGCOMP -DNEED_STRCASECMP \
+       -DSUPPORT_ZERO_WIDTH -DHAS_WIDECHAR_FUNCTIONS
+#define DtSvcDefines           -DXK_MISCELLANY -DMULTIBYTE -DNO_REGCOMP
+#define DtSearchDefines                -DI18N_MSG DtSvcDefines
+#define DtWidgetDefines                DtSearchDefines
+#define DtPrintDefines         DtSearchDefines
+
+#define HasStrcasecmp          NO
+
+/* For DtHelp's TIFF processing routines. */
+#define LSBBitOrder            YES
+
+#define ArchitectureDefines    -DUSL_ARCHITECTURE
+
+#define ExportListGenSource    elistgen.usl
+#define ShlibExportListOpt(filename)   Concat(-Bexport:,filename)
+
+/* Remove -lc because select.o is not relocatable. */
+/* Remove -lgen (and set UseLocalRegex) because no shared library exists. */
+#define SharedXmReqs $(LDPRELIBS) SharedXReqs -lsocket -lnsl -lw
+#define SharedMrmReqs $(LDPRELIBS) $(XMLIB) SharedXReqs -lsocket -lnsl -lw
+#define SharedUilReqs $(LDPRELIBS) $(MRESOURCELIB) $(XMLIB) SharedXReqs -lsocket -lnsl -lw
+  
+/* <X11/Xos_r.h> requires process locking for missing _r functions */
+#define TtClientLibs $(TTLIB) $(XTOOLLIB) $(XLIB)
+#define TtClientDepLibs $(DEPTTLIB) $(DEPXTOOLLIB) $(DEPXLIB)
+
+#define CdeProjectDefines \
+       -DANSICPP -DMULTIBYTE -DNLS16 -DNEED_STRCASECMP \
+       -DOSMAJORVERSION=OSMajorVersion -DOSMINORVERSION=OSMinorVersion
diff --git a/Xserver/config/cf/vnc.def b/Xserver/config/cf/vnc.def
new file mode 100644 (file)
index 0000000..bd18428
--- /dev/null
@@ -0,0 +1,134 @@
+/*****************************************************************************/
+/*
+ * vnc.def
+ *
+ * Some imake configuration defines for building Xvnc.  If you build Xvnc
+ * on a new platform you may need to change things in here.  If possible
+ * try and make changes here rather than in the vendor .cf file to make it
+ * easier to upgrade to later versions of the XFree86 distribution.
+ */
+
+/*****************************************************************************/
+/*
+ * First try to switch off all the extras that we don't want.  This includes
+ * all sorts of extensions, and any X servers for particular hardware.  You
+ * should be able to put back any extensions you want by getting the code from
+ * the XFree86 distribution and changing the #define here to YES.
+ */
+
+#define BuildFontServer                NO
+#define BuildFonts             NO
+#define BuildXInputExt         NO
+#define BuildScreenSaverExt    NO
+#define BuildPexExt            NO
+#define BuildXIE               NO
+#define BuildXIElib            NO
+#define BuildGlxExt             NO
+#define BuildXKB               NO
+#define BuildXKBlib            NO
+#define BuildLBX               NO
+#define BuildXprint            NO
+#define BuildDBE               NO
+#define BuildDBElib            NO
+#define BuildRECORD            NO
+#define BuildRECORDlib         NO
+#define BuildScreenSaverLibrary        NO
+#define BuildXF86MiscLibrary   NO
+#define BuildXF86DGALibrary    NO
+#define BuildXF86VidModeLibrary        NO
+#define BuildDPMSLibrary       NO
+#define BuildXKBuilib          NO
+#define BuildXF86DGA           NO
+#define BuildDPMSExt           NO
+#define BuildXF86VidModeExt    NO
+#define BuildXF86MiscExt       NO
+#define BuildXF86Setup         NO
+#define BuildAppgroup          NO
+#define BuildXCSecurity                NO
+#define BuildPC98Servers       NO
+
+#define X386Server              NO
+#define XF68FBDevServer         NO
+#define XF86AGXServer           NO
+#define XF86I128Server          NO
+#define XF86I8514Server         NO
+#define XF86Mach32Server        NO
+#define XF86Mach64Server        NO
+#define XF86Mach8Server         NO
+#define XF86MonoDualServer      NO
+#define XF86MonoServer          NO
+#define XF86P9000Server         NO
+#define XF86S3Server            NO
+#define XF86S3VServer           NO
+#define XF86SVGAServer          NO
+#define XF86TGAServer           NO
+#define XF86VGA16DualServer     NO
+#define XF86VGA16Server         NO
+#define XF86W32Server           NO
+#define XF98EGCServer           NO
+#define XF98GA968Server         NO
+#define XF98GANBWAPServer       NO
+#define XF98MGAServer           NO
+#define XF98NEC480Server        NO
+#define XF98NECS3Server         NO
+#define XF98NKVNECServer        NO
+#define XF98PWLBServer          NO
+#define XF98PWSKBServer         NO
+#define XF98SVGAServer          NO
+#define XF98TGUIServer          NO
+#define XF98WABEPServer         NO
+#define XF98WABSServer          NO
+#define XF98WSNAServer          NO
+#define XVirtualFramebufferServer      NO
+#define XdecServer              NO
+#define XhpServer               NO
+#define XibmServer              NO
+#define XmacIIServer            NO
+#define XmipsServer             NO
+#define XnestServer             NO
+#define XprtServer              NO
+#define Xsun24Server            NO
+#define XsunAmoebaMonoServer    NO
+#define XsunAmoebaServer        NO
+#define XsunMonoServer          NO
+#define XsunServer              NO
+
+
+/*****************************************************************************/
+/*
+ * All we want to build is the Xvnc server
+ */
+
+#define XvncServer             YES
+#define BuildServersOnly       YES
+#define BuildServer            YES
+
+#define XVendorString          "RealVNC Ltd"
+#define XVendorRelease         3370
+#define XvncRelease            "3.3.7"
+
+
+/*****************************************************************************/
+/*
+ * Try to work out the default X installation place for various platforms.
+ * You may need to change this.
+ */
+
+#ifdef SunArchitecture
+#define ProjectRoot /usr/openwin
+#else
+#ifdef i386Architecture
+#define ProjectRoot /usr/X11R6
+#endif
+#endif
+
+
+/*****************************************************************************/
+/*
+ * At ORL we use gcc on our Suns.  If you use gcc then you may also need to
+ * change config/imake/Makefile.ini which has CC=cc hard-coded.
+ */
+
+#ifdef SunArchitecture
+#define HasGcc2 YES
+#endif
diff --git a/Xserver/config/cf/vnclibs.def b/Xserver/config/cf/vnclibs.def
new file mode 100644 (file)
index 0000000..98dc8b2
--- /dev/null
@@ -0,0 +1,24 @@
+/*
+ * vnclibs.def.in - tells Xvnc where to pick up external VNC libraries
+ *
+ * Whenever you change this file, you need to run configure and then remake
+ * the Makefiles in
+ * lib/font/fontfile, programs/Xserver and programs/Xserver/hw/vnc 
+ */
+
+CXX = c++
+CXXFLAGS = -O2 -Wall
+
+CCLINK = $(CXX)
+
+RFB_TOP = $(TOP)/..
+
+top_srcdir = $(RFB_TOP)
+
+ZLIB_INCLUDE = 
+
+VNCLIBS = $(RFB_TOP)/rdr/librdr.a $(RFB_TOP)/rfb/librfb.a -lz
+
+VNCSYSLIBS =
+
+VNCCPPFLAGS = -I$(RFB_TOP)
diff --git a/Xserver/config/cf/vnclibs.def.in b/Xserver/config/cf/vnclibs.def.in
new file mode 100644 (file)
index 0000000..f4ade04
--- /dev/null
@@ -0,0 +1,24 @@
+/*
+ * vnclibs.def.in - tells Xvnc where to pick up external VNC libraries
+ *
+ * Whenever you change this file, you need to run configure and then remake
+ * the Makefiles in
+ * lib/font/fontfile, programs/Xserver and programs/Xserver/hw/vnc 
+ */
+
+CXX = @CXX@
+CXXFLAGS = @CXXFLAGS@
+
+CCLINK = $(CXX)
+
+RFB_TOP = $(TOP)/..
+
+top_srcdir = $(RFB_TOP)
+
+ZLIB_INCLUDE = @ZLIB_INCLUDE@
+
+VNCLIBS = $(RFB_TOP)/rdr/librdr.a $(RFB_TOP)/rfb/librfb.a @ZLIB_LIB@
+
+VNCSYSLIBS =
+
+VNCCPPFLAGS = -I$(RFB_TOP)
diff --git a/Xserver/config/cf/x386.cf b/Xserver/config/cf/x386.cf
new file mode 100644 (file)
index 0000000..1d9c7c8
--- /dev/null
@@ -0,0 +1,149 @@
+XCOMM platform:  $XConsortium: x386.cf /main/15 1996/09/28 16:14:00 rws $
+
+/*****************************************************************************
+ *                       Site-specfic parameters                            *
+ *****************************************************************************/
+
+/*
+ * there are some switches to set appropriate...
+ */
+
+#define HasGcc                 YES     /* doesn't work for SVR4 */
+#define HasNdbm                        YES     /* correct for GNU dbm & SVR4 */
+#define StripInstalledPrograms YES
+#define X386Server             YES
+#define ExtensionOSDefines     -DXTESTEXT1
+#define MotifBC                        YES
+
+/*****************************************************************************
+ *                        Do not change anything below                       *
+ *****************************************************************************/
+
+/* You must manually compute BootstrapCFlags for initial build */
+#define BootstrapCFlags                OSDefines OSRelease
+
+#define StandardDefines                OSDefines OSRelease
+#define LdCombineFlags         -r
+
+#if defined(i386SVR3Architecture)
+
+#define SystemV                        YES
+
+#define NeedBerklib            YES
+#define HasSymLinks            NO
+
+/*
+ * V/386 Release 3.2
+ */
+#ifdef ISC
+/* INTERACTIVE UNIX Version 2.2.1 */
+# define OSVendor              "Interactive System Corp."
+# define OSDefines             -DISC
+# define LocalLibraries                -lpt
+# define PosixLibraries                -lcposix
+# define SocketLibraries        -linet
+#endif
+
+#ifdef ESIX
+#define OSVendor               "ESIX System Inc."
+#define OSDefines              -DESIX
+#define LocalLibraries         -lpt
+#define SocketLibraries                -lnet -lnsl_s
+#define PosixLibraries         /**/
+#endif
+
+#ifdef ATT
+#define OSDefines              -DATT
+#define OSVendor               "AT&T"
+#define LocalLibraries         -lpt
+#define SocketLibraries                -lnet -lnsl_s    /* just a guess */
+#define PosixLibraries         /**/
+#endif
+
+#define OSName                 Unix System V/386 Release 3.2
+#define OSMajorVersion         3
+#define OSMinorVersion         2
+#define OSRelease              -DSYSV -DSYSV386
+
+#if HasGcc
+# define CcCmd gcc -DNO_ASM -fstrength-reduce -fpcc-struct-return -fwritable-strings
+# define LibraryCcCmd gcc -DNO_ASM -fstrength-reduce -fpcc-struct-return
+# define ShlibDefines -D__GNUC__ -DGNULIB=/usr/local/lib/gcc-gnulib
+#else
+# define ShlibDefines /**/
+#endif
+
+#if HasSockets
+/* # define ConnectionFlags -DLOCALCONN -DTCPCONN */
+# define ConnectionFlags -DTCPCONN
+# define ExtraLibraries SocketLibraries LocalLibraries -lc_s PosixLibraries
+#else
+# define ConnectionFlags -DLOCALCONN
+# define ExtraLibraries $(LIBDIR)/etc/inetemul.o LocalLibraries -lc_s PosixLibraries
+#endif
+
+/* #include <sv3Lib.rules> */  /* not working yet */
+
+/*
+ * Man pages need to be formatted when installed, so override the default
+ * imake rules.
+ */
+#define InstallManPageLong(file,destdir,dest)                           @@\
+install.man:: file.man                                                  @@\
+       $(RM) destdir/dest.$(MANSUFFIX)                                 @@\
+       cat file.man | $(NEQN) | $(NROFF) $(MANMACROS) >/tmp/file.man   @@\
+       $(INSTALL) -c $(INSTMANFLAGS) /tmp/file.man destdir/dest.$(MANSUFFIX) @@\
+       $(RM) /tmp/file.man
+
+#define InstallMultipleMan(list,dest)                                   @@\
+install.man:: list                                                      @@\
+       @MakeFlagsToShellFlags(i,set +e); \                             @@\
+       for i in list; do \                                             @@\
+               (set -x; \                                              @@\
+               $(RM) dest/$$i; \                                       @@\
+               cat $$i | $(NEQN) | $(NROFF) $(MANMACROS) >/tmp/$$i; \  @@\
+               $(INSTALL) -c $(INSTMANFLAGS) /tmp/$$i dest/$$i; \      @@\
+               $(RM) /tmp/$$i); \                                      @@\
+       done
+
+/* If you have trouble with make bombing out in Xlib, try uncommenting this. */
+/* You will not get dependencies as a result, but better than nothing. */
+/* #define DependTarget3(srcs1,srcs2,srcs3) */
+
+#endif /* i386SVR3Architecture */
+
+
+/*
+ * V/386 Release 4.0
+ */
+#if defined(i386SVR4Architecture)
+
+#define SystemV4               YES
+
+/* this is now just for Dell's one */
+
+#ifdef DELL
+#define OSDefines              -DDELL
+#define OSVendor               "DELL Computer Corp."
+#endif
+
+#define OSName                 Unix System V/386 Release 4.0
+#define OSMajorVersion         4
+#define OSMinorVersion         0
+#define OSRelease              -DSVR4 -DSYSV386
+
+#if HasGcc
+# define CcCmd                 gcc -ansi -fstrength-reduce -fpcc-struct-return -Di386
+# if HasSharedLibraries
+#  define LibraryCcCmd cc -Xa -Di386 -Dasm=__asm
+# endif
+#else
+# define CcCmd         cc -Xa -Di386 -Dasm=__asm
+#endif
+
+#include <sv4Lib.rules>
+
+#endif /* i386SVR4Architecture */
+
+
+XCOMM operating system:  OSName OSVendor
diff --git a/Xserver/config/cf/xf86.rules b/Xserver/config/cf/xf86.rules
new file mode 100644 (file)
index 0000000..66bbe3f
--- /dev/null
@@ -0,0 +1,186 @@
+XCOMM $XConsortium: xf86.rules /main/9 1996/10/31 14:54:26 kaleb $
+XCOMM $XFree86: xc/config/cf/xf86.rules,v 3.16.2.1 1997/05/18 12:00:01 dawes Exp $
+
+/*
+ * These rules are needed to build the Xfree86 X Servers
+ */
+
+#ifndef CPPOnlyAsm
+#define CPPOnlyAsm(basename,options) RemoveFile(basename.i)            @@\
+       $(CPP) AsmDefines $(DEFINES) $(INCLUDES) options basename.s | \ @@\
+               grep -v '^\#' > basename.i
+#endif
+
+#ifndef AssembleObject
+#define AssembleObject(flags) CPPOnlyAsm($*,flags)                     @@\
+       RemoveFile($*.o)                                                @@\
+       $(AS) -o $*.o $*.i                                              @@\
+       RemoveFile($*.i)
+#endif
+
+#ifndef NormalAsmObjectRule
+#define NormalAsmObjectRule()                                          @@\
+.s.o:                                                                  @@\
+       AssembleObject($(_NOOP_))                                       @@\
+                                                                       @@\
+.s.i:                                                                  @@\
+       CPPOnlyAsm($*,$(_NOOP_))
+#endif
+
+#ifndef ObjectFromSpecialAsmSource
+#define ObjectFromSpecialAsmSource(dst,src,flags)                      @@\
+dst.s:  src.s                                                          @@\
+       RemoveFile($@)                                                  @@\
+       $(LN) $? $@                                                     @@\
+                                                                       @@\
+dst.o:  dst.s                                                          @@\
+       AssembleObject(flags)                                           @@\
+                                                                       @@\
+dst.i:  dst.s                                                          @@\
+       CPPOnlyAsm(dst,flags)                                           @@\
+                                                                       @@\
+depend:: dst.s                                                         @@\
+                                                                       @@\
+clean::                                                                        @@\
+       RemoveFile(dst.s)
+#endif
+
+#ifndef ObjectFromAsmSource
+#define ObjectFromAsmSource(src,flags)                                 @@\
+                                                                       @@\
+src.o:  src.s                                                          @@\
+       AssembleObject(flags)                                           @@\
+                                                                       @@\
+src.i:  src.s                                                          @@\
+       CPPOnlyAsm(dst,flags)                                           @@\
+                                                                       @@\
+depend:: src.s
+#endif
+
+#ifndef ObjectMapIncludeFromSpecialSource
+#define ObjectMapIncludeFromSpecialSource(dst,src,flags)               @@\
+dst.c: src.c                                                           @@\
+       RemoveFile($@)                                                  @@\
+       echo "#include \"mfbmap.h\"" > $@                               @@\
+       echo "#include \"$?\"" >> $@                                    @@\
+                                                                       @@\
+SpecialCObjectRule(dst,NullParameter,flags)                            @@\
+                                                                       @@\
+depend::       dst.c                                                   @@\
+                                                                       @@\
+clean::                                                                        @@\
+       RemoveFile(dst.c)
+#endif
+
+
+/*
+ * Rules for building config files from scripts
+ */
+
+#ifndef Depend
+# define Depend depend
+#endif
+#ifndef ConfigTargetLong
+#define ConfigTargetLong(target,dep,script,args,extra)                 @@\
+all:: Configure                                                                @@\
+                                                                       @@\
+Configure:: target.o                                                   @@\
+                                                                       @@\
+target.c: script dep                                                   @@\
+       $(MAKE) $(MFLAGS) Makefile                                      @@\
+       $(MAKE) $(MFLAGS) extra Concat(Build,target)                    @@\
+                                                                       @@\
+Concat(Build,target):                                                  @@\
+       $(RM) target.c                                                  @@\
+       $(SHELL) script args                                            @@\
+                                                                       @@\
+clean::                                                                        @@\
+       $(RM) target.c
+#endif
+
+#define ConfigTarget(target,dep,script,args) ConfigTargetLong(target,dep,script,args,Depend)
+
+#define ConfigTargetNoDepend(target,dep,script,args) ConfigTargetLong(target,dep,script,args,)
+
+#if !XF86LinkKit
+
+/*
+ * Rules for installing LinkKit parts (target is install.linkkit)
+ */
+
+#ifndef InstallLinkKitNonExecFile
+#define InstallLinkKitNonExecFile(file,dest)                           @@\
+install.linkkit:: file                                                 @@\
+       MakeDir($(DESTDIR)dest)                                         @@\
+       $(INSTALL) -c $(INSTDATFLAGS) file $(DESTDIR)dest
+#endif
+
+#ifndef InstallLinkKitLibrary
+#define InstallLinkKitLibrary(libname,dest)                            @@\
+install.linkkit:: Concat(lib,libname.a)                                        @@\
+       MakeDir($(DESTDIR)dest)                                         @@\
+       $(INSTALL) -c $(INSTLIBFLAGS) Concat(lib,libname.a) $(DESTDIR)dest @@\
+       RanLibrary($(RANLIBINSTFLAGS) Concat($(DESTDIR)dest/lib,libname.a))
+#endif
+
+#ifndef InstallLinkKitNamedLibrary
+#define InstallLinkKitNamedLibrary(libname,dlibname,dest)              @@\
+install.linkkit:: Concat(lib,libname.a)                                        @@\
+       MakeDir($(DESTDIR)dest)                                         @@\
+       $(INSTALL) -c $(INSTLIBFLAGS) Concat(lib,libname.a) \           @@\
+         Concat($(DESTDIR)dest/lib,dlibname.a)                         @@\
+       RanLibrary($(RANLIBINSTFLAGS) Concat($(DESTDIR)dest/lib,dlibname.a))
+#endif
+
+#ifndef InstallLinkKitNamedNonExec
+#define InstallLinkKitNamedNonExec(srcname,dstname,dest)               @@\
+install.linkkit:: srcname                                              @@\
+       MakeDir($(DESTDIR)dest)                                         @@\
+       $(INSTALL) -c $(INSTDATFLAGS) srcname $(DESTDIR)dest/dstname
+#endif
+
+#ifndef InstallLinkKitNamedProg
+#define InstallLinkKitNamedProg(srcname,dstname,dest)                  @@\
+install.linkkit:: srcname                                              @@\
+       MakeDir($(DESTDIR)dest)                                         @@\
+       $(INSTALL) -c $(INSTBINFLAGS) srcname $(DESTDIR)dest/dstname
+#endif
+
+#ifndef InstallLinkKitSubdirs
+#define InstallLinkKitSubdirs(dirs) \
+NamedTargetSubdirs(install.linkkit,dirs,"installing link kit",DESTDIR='$(DESTDIR)',install.linkkit)
+#endif
+
+#ifndef InstallLinkKitMultipleDestFlags
+#define InstallLinkKitMultipleDestFlags(list,dest,flags) \
+InstallMultipleDestFlags(install.linkkit,list,dest,flags)
+#endif
+
+#endif /* !XF86LinkKit */
+
+/*
+ * DynamicModuleTarget - build a module to be dynamically loaded
+ */
+#ifndef DynamicModuleTarget
+#define DynamicModuleTarget(module,modlist)                            @@\
+AllTarget(module)                                                      @@\
+                                                                       @@\
+module: modlist                                                                @@\
+       RemoveFile($@)                                                  @@\
+       $(LD) -o $@ $(SHLIBLDFLAGS) modlist                             @@\
+                                                                       @@\
+clean::                                                                        @@\
+       RemoveFile(module)
+#endif /* DynamicModuleTarget */
+
+/*
+ * InstallDynamicModule - install a dynamic module
+ */
+#ifndef InstallDynamicModule
+#define InstallDynamicModule(module,dest)                              @@\
+install:: module                                                       @@\
+       MakeDir($(DESTDIR)dest)                                         @@\
+       $(INSTALL) -c module $(DESTDIR)dest
+#endif
+
diff --git a/Xserver/config/cf/xf86.tmpl b/Xserver/config/cf/xf86.tmpl
new file mode 100644 (file)
index 0000000..55420a0
--- /dev/null
@@ -0,0 +1,65 @@
+XCOMM $XConsortium: xf86.tmpl /main/2 1996/10/31 15:01:41 kaleb $
+
+
+
+XCOMM $XFree86: xc/config/cf/xf86.tmpl,v 3.11 1996/12/27 06:50:30 dawes Exp $
+
+#if XF86LinkKit
+    TOP_INCLUDES = TopIncludes
+   IMAKE_DEFINES = -DXF86LinkKit=1
+#ifdef UseInstalled
+       IMAKE_CMD = $(IMAKE) -DUseInstalled -I$(TOP) -I$(IRULESRC) \
+                  $(IMAKE_DEFINES)
+#else
+       IMAKE_CMD = $(IMAKE) -I$(TOP) -I$(IRULESRC) $(IMAKE_DEFINES)
+#endif
+
+#undef ImakeSubCmdHelper
+#ifdef UseInstalled
+#define ImakeSubCmdHelper $(IMAKE) -DUseInstalled -I$(IMAKETOP) \
+                         -I$(IRULESRC) $(IMAKE_DEFINES)
+#else
+#define ImakeSubCmdHelper $(IMAKEPREFIX)$(IMAKE) -I$(IMAKETOP) \
+                         -I$(IMAKEPREFIX)$(IRULESRC) $(IMAKE_DEFINES)
+#endif
+#endif
+
+#ifndef JoystickSupport
+#define JoystickSupport                NO
+#endif
+#ifndef WacomSupport
+#define WacomSupport           NO
+#endif
+#ifndef ElographicsSupport
+#define ElographicsSupport     NO
+#endif
+#ifndef SummaSketchSupport
+#define SummaSketchSupport     NO
+#endif
+
+#if BuildDynamicLoading
+       MODULEDIR = $(USRLIBDIR)/modules
+#endif
+
+#if !BuildDynamicLoading && BuildXInputExt
+# if JoystickSupport
+#  define JoystickDefines -DJOYSTICK_SUPPORT
+# else
+#  define JoystickDefines
+# endif
+# if WacomSupport
+#  define WacomDefines -DWACOM_SUPPORT
+# else
+#  define WacomDefines
+# endif
+# if ElographicsSupport
+#  define ElographicsDefines -DELOGRAPHICS_SUPPORT
+# else
+#  define ElographicsDefines
+# endif
+# if SummaSketchSupport
+#  define SummaSketchDefines -DSUMMASKETCH_SUPPORT
+# else
+#  define SummaSketchDefines
+# endif
+#endif
diff --git a/Xserver/config/cf/xf86site.def b/Xserver/config/cf/xf86site.def
new file mode 100644 (file)
index 0000000..5139bc2
--- /dev/null
@@ -0,0 +1,577 @@
+XCOMM $XFree86: xc/config/cf/xf86site.def,v 3.101.2.15 1998/02/24 19:05:42 hohndel Exp $
+/******************************************************************************/
+/*
+ * This file is to provide a quick method for most people to change the
+ * behaviour of their XFree86 installation without having to fully
+ * understand the workings of site.def and all the various '.cf' files.
+ *
+ * These are the most common settings you would choose for compiling and
+ * installing XFree86 on the systems supported by it.
+ *
+ * A good way to use this file is to copy it to host.def, and make the
+ * changes there.  That way, future patches to this file won't fail.
+ * The host.def file will never be patched.
+ *
+ * The distributed version of this file should contain no uncommented
+ * definitions.  Such default definitions belong in xfree86.cf.
+ */
+/******************************************************************************/
+
+/*
+ * If you have build-specific modifications in your host.def file, but
+ * want an empty host.def file installed when doing 'make install',
+ * uncomment the following
+ *
+#define InstallEmptyHostDef
+ */
+
+/*
+ * If using GCC 2.x on a system where it isn't the default, uncomment
+ * the following
+ *
+#define HasGcc2                YES
+#define HasGcc         YES
+ */
+
+/*
+ * If using GCC 2.x with C++ on a system where it isn't the default, uncomment
+ * the following.
+ *
+#define HasGcc2ForCplusplus    YES
+ */
+
+/*
+ * The default optimisation flags for GCC 2.x.  -fno-strength-reduce is
+ * here to work around a bug in -O2 for GCC 2.x on i386 platforms.
+ * If you are using a version that doesn't have this bug, you can
+ * uncomment the following line, and remove '-fno-strength-reduce'
+ * If you are building binaries for a 486, it may be beneficial to add
+ * -m486
+ *
+#define DefaultGcc2i386Opt     -O2 -fno-strength-reduce
+ */
+
+/*
+ * For Linux, this should match the Binutils version you have.  This example
+ * is for 2.6.0.7.  See linux.cf for the default setting.
+ *
+ * This should automatically get set correctly by imake.
+ *
+#define LinuxBinUtilsMajorVersion      26
+ */
+
+/*
+ * For Linux, these should match the libc version you have.  This example
+ * is for libc.5.4.x.  See linux.cf for the default setting.
+ *
+ * This should automatically get set correctly by imake.
+ *
+#define LinuxCLibMajorVersion  5
+#define LinuxClibMinorVersion  4
+ */
+
+/*
+ * If you want to use the GNU malloc library, uncomment this
+ *
+#define UseGnuMalloc           YES
+ */
+
+/*
+ * Set this to whatever is required to access the GNU malloc library.
+ * The default is '-lgmalloc' unless is specified in the OS's .cf file.
+ *
+#define GnuMallocLibrary       -L/usr/local/lib -lgmalloc
+ */
+
+/*
+ * To disable the internal Xserver malloc, set this to NO
+ *
+#define UseInternalMalloc      YES
+ */
+
+/*
+ * Some Linux releases don't have a libtermcap.  In this case you may need
+ * to uncomment the following
+ *
+#define TermcapLibrary         -lncurses
+ */
+
+/*
+ * If you have Tk (which is required to build XF86Setup), uncomment this
+ * Note: version 4.0 or 4.1 is required, and XF86Setup links it statically by
+ * default.
+ *
+#define HasTk                  YES
+ */
+
+/*
+ * Set the paths and names for your Tk library if they don't match the
+ * defaults (check your OS .cf file or Imake.tmpl for the defaults).
+ *
+ * Common values for TkLibName are tk4.0, tk4.1, etc.
+ *
+ * Some Linux releases need TkIncDir set to /usr/include/tcl, and some
+ * need it set to /usr/X11R6/include.
+ *
+ * Some Linux releases need TkLibDir set to /usr/X11R6/lib
+ *
+#define TkLibDir               /usr/local/lib
+#define TkIncDir               /usr/local/include
+#define TkLibName              tk
+ */
+
+/*
+ * By default, XF86Setup is linked with a static Tk library.  To change
+ * that, uncomment the following line.
+ *
+#define XF86SetupUsesStaticTk  NO
+ */
+
+/*
+ * If you have Tcl (which is required to build XF86Setup), uncomment this
+ * Note: version 7.4 or 7.5 is required, and XF86Setup links it statically by
+ * default.
+ *
+#define HasTcl                 YES
+ */
+
+/*
+ * Set the paths and names for your Tcl library if they don't match the
+ * defaults (check your OS .cf file or Imake.tmpl for the defaults).
+ *
+ * Common values for TclLibName are tcl7.4, tcl7.5, etc.
+ *
+ * Some Linux releases need TclIncDir set to /usr/include/tcl.
+ *
+#define TclLibDir              /usr/local/lib
+#define TclIncDir              /usr/local/include
+#define TclLibName             tcl
+ */
+
+/*
+ * By default, XF86Setup is linked with a static Tcl library.  To change
+ * that, uncomment the following line.
+ *
+#define XF86SetupUsesStaticTcl NO
+ */
+
+/*
+ * Which servers do you wish to build, you can save a lot of disk space
+ * by only compiling the server you will be using.  It will also save you
+ * considerable compile time.
+ *
+ * The following servers are supported in Intel x86 platforms
+ *
+#define XF86SVGAServer          NO
+#define XF86VGA16Server         NO
+#define XF86VGA16DualServer    NO
+#define XF86MonoServer          NO
+#define XF86MonoDualServer     NO
+#define XF86S3Server            NO
+#define XF86S3VServer           NO
+#define XF86I8514Server         NO
+#define XF86Mach8Server         NO
+#define XF86Mach32Server        NO
+#define XF86Mach64Server        NO
+#define XF86P9000Server                NO
+#define XF86AGXServer          NO
+#define XF86W32Server          NO
+#define XF86I128Server         NO
+ */
+
+/*
+ * Which servers do you wish to build, you can save a lot of disk space
+ * by only compiling the server you will be using.  It will also save you
+ * considerable compile time.
+ *
+ * The following servers are supported on Digital Alpha platforms:
+ *
+#define XF86SVGAServer          NO
+#define XF86MonoServer          NO
+#define XF86S3Server            NO
+#define XF86S3VServer           NO
+#define XF86P9000Server                NO
+#define XF86TGAServer          NO
+ */
+
+/*
+ * Which servers do you wish to build, you can save a lot of disk space
+ * by only compiling the server you will be using.  It will also save you
+ * considerable compile time.
+ *
+ * The following server is supported on Mips/Arc platforms:
+ *
+#define XF86S3Server            NO
+ */
+
+/*
+ * PC98 X servers
+ *
+ * Uncommenting the following automatically enables all PC98 servers
+ *
+#define BuildPC98Servers       YES
+ */
+
+/*
+ * To enable/disable individual PC98 servers, use these
+ *
+#define XF98EGCServer          YES
+#define XF98GANBWAPServer      YES
+#define XF98NEC480Server       YES
+#define XF98NKVNECServer       YES
+#define XF98WABSServer         YES
+#define XF98WABEPServer                YES
+#define XF98WSNAServer         YES
+#define XF98TGUIServer         YES
+#define XF98MGAServer          YES
+#define XF98SVGAServer         YES
+#define XF98NECS3Server                YES
+#define XF98PWSKBServer                YES
+#define XF98PWLBServer         YES
+#define XF98GA968Server                YES
+ */
+
+/*
+ * The following server is supported on Motorola 68k platforms:
+ *
+#define XF68FBDevServer                NO
+ */
+
+/*
+ * To disable building the Xnest server, uncomment this.
+ *
+#define XnestServer            NO
+ */
+
+/*
+ * To disable building Xvfb, uncomment this.
+ *
+#define XVirtualFramebufferServer      NO
+ */
+
+/*
+ * Set the default server (ie the one that gets the sym-link to "X")
+ *
+#define ServerToInstall                XF86_S3
+ */
+
+
+/*
+ * Server configuration parameters.  The defaults are shown here:
+ */
+
+/*
+ * SVGA server:
+ *
+#define XF86SvgaDrivers                nv et4000 et3000 pvga1 gvga ati sis tvga8900 \
+                               cirrus ncr77c22 compaq mga oak al2101 ali \
+                               cl64xx video7 ark mx realtek apm \
+                               s3v s3_svga chips generic
+ */
+
+/*
+ * VGA16 server:
+ *
+#define XF86Vga16Drivers       et4000 et3000 ncr77c22 ati sis tvga8900 oak \
+                               cl64xx generic 
+ */
+
+/*
+ * VGA2 driver in Mono server:
+ *
+#define XF86Vga2Drivers                et4000 et3000 pvga1 gvga ati sis tvga8900 \
+                               cirrus ncr77c22 oak cl64xx generic
+ */
+
+/*
+ * Mono driver in Mono or VGA16 server:
+ *
+#define XF86MonoDrivers                hgc1280 sigma apollo hercules
+ */
+
+/*
+ * ET4000/W32 server:
+ *
+#define XF86W32Drivers         et4000w32
+ */
+
+/*
+ * BSD Console driver support (for FreeBSD and NetBSD).
+ *
+ * By default, support is included for pccons and pcvt for NetBSD, and
+ * pccons, syscons and pcvt for FreeBSD.
+ *
+ * To change the list of supported drivers, set the following parameter.
+ * Possible values are -DPCCONS_SUPPORT, -DSYSCONS_SUPPORT, -DPCVT_SUPPORT,
+ * -DCODRV_SUPPORT.  The following example includes support for syscons and
+ * pcvt only.
+ *
+#define XFree86ConsoleDefines  -DSYSCONS_SUPPORT -DPCVT_SUPPORT
+ */
+
+/*
+ * The X servers need to run as root on most OSs.  We're now using a
+ * wrapper in that case, but we still need to make it known that the
+ * servers need SetUID.  When only using xdm, this (and the wrapper)
+ * are not required.  Disabling this automatically disables use of the
+ * wrapper.
+ *
+ * If you're only starting the Xservers with xdm set this to NO
+ *
+#define XserverNeedsSetUID     NO
+ */
+
+/*
+ * To disable building the font server, uncomment this.
+ *
+#define BuildFontServer                NO
+ */
+
+/*
+ * Do you want to Build Fonts (Usually you only want to build and install
+ * fonts once, if this is a first time install you will want to build the
+ * fonts)
+ *
+#define BuildFonts             NO
+ */
+
+/*
+ * To not build/install the 75dpi fonts, uncomment the following
+ *
+#define Build75DpiFonts                NO
+ */
+
+/*
+ * To not build/install the 100dpi fonts, uncomment the following
+ *
+#define Build100DpiFonts       NO
+ */
+
+/*
+ * To not build/install the Speedo fonts, uncomment the following
+ *
+#define BuildSpeedoFonts       NO
+ */
+
+/*
+ * To not build/install the Type1 fonts, uncomment the following
+ *
+#define BuildType1Fonts                NO
+ */
+
+/*
+ * To not build/install the Cyrillic fonts, uncomment the following
+ *
+#define BuildCyrillicFonts     NO
+ */
+
+/*
+ * To build only the servers with a cut-down source tree, uncomment
+ * this.
+ *
+#define BuildServersOnly       YES
+ */
+
+/*
+ * To disable building XInput support, uncomment this
+ *
+#define BuildXInputExt         NO
+ */
+
+/*
+ * Select the XInput devices you want by setting them to YES.       
+ *
+ * Note: Joystick support is only included for Linux and FreeBSD at the
+ * moment.  For Linux it requires the Joystick module to be installed (it
+ * isn't part of the standard kernel distribution).  For FreeBSD, a kernel
+ * will need to be built with the Joystick driver in order to be able to
+ * use this.
+ *
+#define JoystickSupport                NO
+#define WacomSupport           YES
+#define ElographicsSupport     YES 
+#define SummaSketchSupport     YES
+ */
+
+/*
+ * if your system supports dynamic loading of modules using
+ * dlopen set this to YES.
+ *
+#define BuildDynamicLoading    YES
+ */
+
+/*
+ * To disable the ScreenSaver Extension, uncomment this line.
+ *
+#define BuildScreenSaverExt    NO
+ */
+
+/*
+ * If you don't want to build PEX, uncomment this.
+ *
+#define BuildPexExt            NO
+ */
+
+/*
+ * If you don't want to build XIE, uncomment this.
+ *
+#define BuildXIE               NO
+ */
+
+/*
+ * If you don't want to build support for an external GLX server module or
+ * library, uncomment this.
+ *
+ * NOTE: XFree86 3.3 does not include GLX server source, module, or
+ *       functional libraries. Building in support does not require
+ *       availability of a GLX package, but will allow it to be used
+ *       when released (by dynamic load or relinking).  
+ *
+#define BuildGlxExt             NO
+ */
+
+/*
+ * If you aren't building with support for loadable modules and wish
+ * to statically link external GLX server libs instead of the default
+ * non-functional stub library, uncomment the following define and
+ * specify the space-seperated pathnames of those libraries here.
+ *
+#define GlxStaticServerLib     /full/path/name/to/glx/servGL/libServerGlx.a \
+                               /full/path/name/to/glx/servGL/libMesaGlx.a
+ */ 
+
+/*
+ * If you want to build only the DIS (Document Imaging Subset of XIE)
+ * uncomment this line.  This option is only relevant when XIE is built.
+ *
+#define BuildDIS               YES
+ */
+
+/*
+ * By default, the sample config files for xinit, xdm and xfs are installed
+ * only when there is no pre-existing version installed.  Uncommenting the
+ * following lines will force the sample versions to be installed even if
+ * it means over-writing existing versions.
+ *
+#define InstallXinitConfig     YES
+#define InstallXdmConfig       YES
+#define InstallFSConfig                YES
+ */
+
+/*
+ * By default the application defaults files are always installed.
+ * Uncommenting the the following will prevent exising application
+ * defaults files from being over-written.
+ *
+#define InstallAppDefFiles     NO
+ */
+
+/*
+ * If you are running Solaris x86, and want to disable building support
+ * for the aperture driver, uncomment this.
+ *
+#define HasSolx86ApertureDriver        NO
+ */
+
+/*
+ * If you are running NetBSD 0.9C or later, or OpenBSD and want to disable
+ * building support for the NetBSD aperture driver, uncomment this.
+ *
+#define HasNetBSDApertureDriver NO
+ */
+
+/*
+ * If you are running SVR3 and have the mmap driver installed (for linear
+ * framebuffer access) uncomment this.
+ *
+#define HasSVR3mmapDrv YES
+ */
+
+/*
+ * If you are using an SVR3 (like ISC 4.x) which supports long file names,
+ * you can * uncomment this to have manual pages installed under their
+ * full names
+ *
+#define ExpandManNames         YES
+ */
+
+/*
+ * For a POSIXized build on Interactive uncomment this
+ * Could be used with gcc 'till Version 2.6.3
+ * Should be used with gcc 2.7.2. 
+ *
+#define UsePosix               YES
+ */
+
+/*
+ * If you want XDMAUTH support (if you have Wraphelp.c), uncomment this.
+ *
+#define HasXdmAuth             YES
+ */
+
+/*
+ * To forceably build static libraries in addition to shared libraries,
+ * uncomment this.
+ *
+#define ForceNormalLib         YES
+ */
+
+/*
+ * Uncomment this if your default tools (eg, gcc, ld, as, etc) are
+ * not the Linux ELF versions.
+ *
+#define LinuxElfDefault                NO
+ */
+
+/*
+ * To use ELF format shared libraries for Linux, uncomment this.
+ * Note: gcc-2.6.0-941008 and gas-941008 (or later) is required for this.
+ * Check linux.cf if you have problems regarding the location of elf-aware
+ * gcc and gas binaries.
+ *
+ * The default setting of this is the same as the setting of LinuxElfDefault
+ *
+#define UseElfFormat           YES
+ */
+
+/*
+ * If you have trouble with make bombing out in Xlib, try uncommenting this.
+ * You will not get dependencies as a result, but better than nothing.
+ *
+#define MakeHashTableBug        YES
+ */
+
+/*
+ * If you do not want your man pages compress under SVR3 systems that
+ * support it, uncomment this.
+ *
+#define CompressManPages        NO
+ */
+
+/*
+ * LinuxDoc stuff.  Uncomment those of these you want.  Check in
+ * lnxdoc.tmpl for other things you might need to define/change here.
+ *
+#define HasLinuxDoc            YES
+#define HasLatex               YES
+#define HasDvips               YES
+#define BuildLinuxDocHtml      YES
+#define BuildAllDocs           YES
+ */
+
+/*
+ * To install Japanese versions of the documentation uncomment this.
+ * Note: The Japanese documentation consists of a subset of the
+ * XFree86 3.1 docs.
+ *
+#define InstallJapaneseDocs    YES
+ */
+
+/*
+ * By default, XF86Contrib is defined so build only those parts of
+ * of the contrib distribution supported by XFree86.  To prevent this
+ * from being defined, uncomment the following.
+ *
+#define DontDefineXF86Contrib
+ */
+
diff --git a/Xserver/config/cf/xfree86.cf b/Xserver/config/cf/xfree86.cf
new file mode 100644 (file)
index 0000000..470cb66
--- /dev/null
@@ -0,0 +1,1228 @@
+XCOMM $XFree86: xc/config/cf/xfree86.cf,v 3.129.2.22 1998/02/24 19:05:43 hohndel Exp $
+/*
+ * This configuration file contains all of the configuration
+ * information for the XFree86 based X Servers.
+ *
+ * Most of these settings can be overridden in a vendor.cf or the
+ * BeforeVendor part of the site.def file.
+ */
+XCOMM $XConsortium: xfree86.cf /main/34 1996/12/06 11:45:18 rws $
+
+/*
+ * The LinkKit needs to inherit some settings (from the xc build that
+ * generated it) before we go too much further...
+ */
+#ifndef XF86LinkKit
+#define XF86LinkKit    NO
+#endif
+#if XF86LinkKit
+#include <LinkKit.tmpl>
+#endif
+
+/*
+ * Default settings for which X Servers to build.
+ */
+
+/*
+ * For Intel x86 platforms, the default is to build all X servers which
+ * are supported on this platform.
+ */
+#ifdef i386Architecture
+#ifndef XF86SVGAServer
+#define XF86SVGAServer          YES
+#endif
+#ifndef XF86VGA16Server
+#define XF86VGA16Server         YES
+#endif
+#ifndef XF86VGA16DualServer
+#define XF86VGA16DualServer    YES
+#endif
+#ifndef XF86MonoServer
+#define XF86MonoServer          YES
+#endif
+#ifndef XF86MonoDualServer
+#define XF86MonoDualServer     YES
+#endif
+#ifndef XF86S3Server
+#define XF86S3Server            YES
+#endif
+#ifndef XF86S3VServer
+#define XF86S3VServer          YES
+#endif
+#ifndef XF86I8514Server
+#define XF86I8514Server         YES
+#endif
+#ifndef XF86Mach8Server
+#define XF86Mach8Server         YES
+#endif
+#ifndef XF86Mach32Server
+#define XF86Mach32Server        YES
+#endif
+#ifndef XF86Mach64Server
+#define XF86Mach64Server        YES
+#endif
+#ifndef XF86P9000Server
+#define XF86P9000Server                YES
+#endif
+#ifndef XF86AGXServer
+#define XF86AGXServer          YES
+#endif
+#ifndef XF86W32Server
+#define XF86W32Server          YES
+#endif
+#ifndef XF86I128Server
+#define XF86I128Server         YES
+#endif
+#ifndef XF86GLINTServer
+#define XF86GLINTServer                YES
+#endif
+#if defined(LinuxArchitecture)
+#ifndef XF86FBDevServer
+#define XF86FBDevServer                YES
+#endif
+#endif
+#endif
+
+/*
+ * For Digital Alpha platforms, the default is to build all X servers which
+ * are supported on this platform.
+ */
+#ifdef AlphaArchitecture
+#ifndef XF86S3Server
+#define XF86S3Server           YES
+#endif
+#ifndef XF86S3VServer
+#define XF86S3VServer          YES
+#endif
+#ifndef XF86Mach64Server
+#define XF86Mach64Server       YES
+#endif
+#ifndef XF86P9000Server
+#define XF86P9000Server                YES
+#endif
+#ifndef XF86I128Server
+#define XF86I128Server         YES
+#endif
+#ifndef XF86TGAServer
+#define XF86TGAServer          YES
+#endif
+#ifndef XF86SVGAServer
+#define XF86SVGAServer         YES
+#endif
+#ifndef XF86VGA16Server
+#define XF86VGA16Server                YES
+#endif
+#ifndef XF86MonoServer
+#define XF86MonoServer         YES
+#endif
+#ifndef XF86GLINTServer
+#define XF86GLINTServer                YES
+#endif
+#if defined(LinuxArchitecture)
+#ifndef XF86FBDevServer
+#define XF86FBDevServer                YES
+#endif
+#endif
+#ifndef XF86SvgaDrivers
+#define XF86SvgaDrivers                mga s3v
+#endif
+#ifndef XF86Vga16Drivers
+#define XF86Vga16Drivers       generic
+#endif
+#ifndef XF86Vga2Drivers
+#define XF86Vga2Drivers                generic
+#endif
+#endif
+
+/*
+ * For Motorola 68k platforms, the default is to build all X servers which
+ * are supported on this platform.
+ */
+#ifdef Mc68020Architecture
+#ifndef XF68FBDevServer
+#define XF68FBDevServer                YES
+#define XF68FBDev77C32         NO
+#define XF68FBDevIMSTT         NO
+#define XF68FBDevMach64                NO
+#define XF68FBDevPermedia2     NO
+#endif
+#ifndef BuildXF86Setup
+#define BuildXF86Setup         NO
+#endif
+#endif
+
+/*
+ * For ARM platforms, the default is to build all X servers which
+ * are supported on this platform.
+ */
+#ifdef ArmArchitecture
+#ifndef XF68FBDevServer
+#define XF68FBDevServer                YES
+#define XF68FBDevCFB8          YES
+#define XF68FBDevCFB16         YES
+#define XF68FBDevCFB24         YES
+#define XF68FBDevCFB32         YES
+#define XF68FBDevIPLAN2p2      NO
+#define XF68FBDevIPLAN2p4      NO
+#define XF68FBDevIPLAN2p8      NO
+#define XF68FBDevILBM          NO
+#define XF68FBDevAFB           NO
+#define XF68FBDev77C32         NO
+#define XF68FBDevMach64                NO
+#define XF68FBDevIMSTT         NO
+#define XF68FBDevPermedia2     NO
+#endif
+#ifndef BuildXF86Setup
+#define BuildXF86Setup         NO
+#endif
+#endif
+
+/*
+ * For Mips/Arc platforms, the default is to build all X servers which
+ * are supported on this platform.
+ */
+#ifdef ArcArchitecture
+#ifndef XF86S3Server
+#define XF86S3Server           YES
+#endif
+#if defined(LinuxArchitecture)
+#ifndef XF86FBDevServer
+#define XF86FBDevServer                YES
+#endif
+#endif
+#ifndef BuildXF86Setup
+#define BuildXF86Setup         NO
+#endif
+#endif
+
+/*
+ * For PowerPC platforms, the default is to build all X servers which
+ * are supported on this platform.
+ */
+#ifdef PowerPCArchitecture
+#ifndef XF86SVGAServer
+#define XF86SVGAServer         NO
+#endif
+#ifndef XF86VGA16Server
+#define XF86VGA16Server                NO
+#endif
+#ifndef XF86S3Server
+#define XF86S3Server           NO
+#endif
+#ifndef XF68FBDevServer
+#define XF68FBDevServer                YES
+#define XF68FBDevCFB8          YES
+#define XF68FBDevCFB16         YES
+#define XF68FBDevCFB24         NO
+#define XF68FBDevCFB32         YES
+#define XF68FBDevIPLAN2p2      NO
+#define XF68FBDevIPLAN2p4      NO
+#define XF68FBDevIPLAN2p8      NO
+#define XF68FBDevILBM          NO
+#define XF68FBDevAFB           YES
+#define XF68FBDev77C32         YES
+#define XF68FBDevIMSTT         YES
+#define XF68FBDevMach64                YES
+#define XF68FBDevPermedia2     YES
+#endif
+#ifndef BuildXF86Setup
+#define BuildXF86Setup         NO
+#endif
+#endif
+
+/* For SPARC PCI platforms, the default is to build all X servers which are
+ * supported on this platform.
+ */
+#ifdef SparcArchitecture
+#ifndef XF86Mach64Server
+#define XF86Mach64Server       YES
+#endif
+#ifndef BuildXF86Setup
+#define BuildXF86Setup         NO
+#endif
+#endif
+
+/*
+ * The following disables all X servers not already enabled above
+ */
+#ifndef XF86VGA16Server
+# define XF86VGA16Server       NO
+# ifndef XF86VGA16DualServer
+#  define XF86VGA16DualServer  NO
+# endif
+#endif
+
+#ifndef XF86MonoServer
+# define XF86MonoServer                NO
+# ifndef XF86MonoDualServer
+#  define XF86MonoDualServer   NO
+# endif
+#endif
+
+#ifndef XF86S3Server
+# define XF86S3Server          NO
+#endif
+
+#ifndef XF86S3VServer
+# define XF86S3VServer         NO
+#endif
+
+#ifndef XF86I8514Server
+# define XF86I8514Server       NO
+#endif
+
+#ifndef XF86Mach8Server
+# define XF86Mach8Server       NO
+#endif
+
+#ifndef XF86Mach32Server
+# define XF86Mach32Server      NO
+#endif
+
+#ifndef XF86Mach64Server
+# define XF86Mach64Server      NO
+#endif
+
+#ifndef XF86AGXServer
+# define XF86AGXServer         NO
+#endif
+
+#ifndef XF86P9000Server
+# define XF86P9000Server       NO
+#endif
+
+#ifndef XF86W32Server
+# define XF86W32Server         NO
+#endif
+
+#ifndef XF86I128Server
+# define XF86I128Server                NO
+#endif
+
+#ifndef XF86GLINTServer
+# define XF86GLINTServer       NO
+#endif
+
+#ifndef XF86TGAServer
+# define XF86TGAServer         NO
+#endif
+
+#if XF86S3Server
+# define XF86S3Dir             s3
+#else
+# define XF86S3Dir             /**/
+#endif
+
+#if XF86S3VServer
+# define XF86S3VDir            s3_virge
+#else
+# define XF86S3VDir            /**/
+#endif
+
+#if XF86I8514Server
+# define XF86I8514Dir          ibm8514
+#else
+# define XF86I8514Dir          /**/
+#endif
+
+#if XF86Mach8Server
+# define XF86Mach8Dir          mach8
+#else
+# define XF86Mach8Dir          /**/
+#endif
+
+#if XF86Mach32Server
+# define XF86Mach32Dir         mach32
+#else
+# define XF86Mach32Dir         /**/
+#endif
+
+#if XF86Mach64Server
+# define XF86Mach64Dir         mach64
+#else
+# define XF86Mach64Dir         /**/
+#endif
+
+#if XF86P9000Server
+# define XF86P9000Dir          p9000
+#else
+# define XF86P9000Dir          /**/
+#endif
+
+#if XF86AGXServer
+# define XF86AGXDir            agx
+#else
+# define XF86AGXDir            /**/
+#endif
+
+#if XF86W32Server
+# define XF86W32Dir            et4000w32
+#else
+# define XF86W32Dir            /**/
+#endif
+
+#if XF86I128Server
+# define XF86I128Dir           i128
+#else
+# define XF86I128Dir           /**/
+#endif
+
+#if XF86GLINTServer
+# define XF86GLINTDir          glint
+#else
+# define XF86GLINTDir          /**/
+#endif
+
+#if XF86TGAServer
+# define XF86TGADir            tga
+#else
+# define XF86TGADir            /**/
+#endif
+
+#ifndef BuildPC98Servers
+#define BuildPC98Servers       NO
+#endif
+
+#ifndef XF98GANBWAPServer
+# define XF98GANBWAPServer     BuildPC98Servers
+#endif
+
+#ifndef XF98NEC480Server
+# define XF98NEC480Server      BuildPC98Servers
+#endif
+
+#ifndef XF98NKVNECServer
+# define XF98NKVNECServer      BuildPC98Servers
+#endif
+
+#ifndef XF98WABSServer
+# define XF98WABSServer                BuildPC98Servers
+#endif
+
+#ifndef XF98WABEPServer
+# define XF98WABEPServer       BuildPC98Servers
+#endif
+
+#ifndef XF98WSNAServer
+# define XF98WSNAServer                BuildPC98Servers
+#endif
+
+#ifndef XF98TGUIServer
+# define XF98TGUIServer                BuildPC98Servers
+#endif
+
+#ifndef XF98MGAServer
+# define XF98MGAServer         BuildPC98Servers
+#endif
+
+#ifndef XF98SVGAServer
+# define XF98SVGAServer                BuildPC98Servers
+#endif
+
+#ifndef XF98EGCServer
+# define XF98EGCServer         BuildPC98Servers
+#endif
+
+#ifndef XF98NECS3Server
+# define XF98NECS3Server       BuildPC98Servers
+#endif
+
+#ifndef XF98PWSKBServer
+# define XF98PWSKBServer       BuildPC98Servers
+#endif
+
+#ifndef XF98PWLBServer
+#define XF98PWLBServer         BuildPC98Servers
+#endif
+
+#ifndef XF98GA968Server
+#define XF98GA968Server                BuildPC98Servers
+#endif
+
+#if XF98NECS3Server
+# define XF98NECS3Dir          s3nec
+#else
+# define XF98NECS3Dir          /**/
+#endif
+
+#if XF98PWSKBServer
+# define XF98PWSKBDir          s3pwskb
+#else
+# define XF98PWSKBDir          /**/
+#endif
+
+#if XF98PWLBServer
+# define XF98PWLBDir           s3pwlb
+#else
+# define XF98PWLBDir           /**/
+#endif
+
+#if XF98GA968Server
+# define XF98GA968Dir          s3ga968
+#else
+# define XF98GA968Dir          /**/
+#endif
+
+#undef XF86AccelServerDirs
+#define XF86AccelServerDirs    XF86S3Dir XF86S3VDir XF86I8514Dir \
+                               XF86Mach8Dir XF86Mach32Dir XF86Mach64Dir \
+                               XF86P9000Dir XF86AGXDir XF86W32Dir \
+                               XF86I128Dir XF86GLINTDir XF86TGADir
+
+#undef XF86AccelServer
+#if XF86S3Server || XF86S3VServer || XF86I8514Server || XF86Mach8Server || \
+    XF86Mach32Server || XF86Mach64Server || XF86P9000Server || \
+    XF86AGXServer || XF86W32Server || XF86I128Server || XF86TGAServer || \
+    XF86GLINTServer
+# define XF86AccelServer       YES
+#else
+# define XF86AccelServer       NO
+#endif
+
+#undef XF98AccelServerDirs
+#define XF98AccelServerDirs   XF98NECS3Dir XF98PWSKBDir XF98PWLBDir XF98GA968Dir
+
+#undef XF98AccelServer
+#if XF98NECS3Server || XF98PWSKBServer || XF98PWLBServer || XF98GA968Server
+# define XF98AccelServer       YES
+#else
+# define XF98AccelServer       NO
+#endif
+
+/*
+ * Driver list for several of the X Servers.
+ */
+#ifndef XF86SvgaDrivers
+# ifdef AlphaArchitecture
+#  define XF86SvgaDrivers      mga tvga8900 s3v nv
+# else
+#  if defined(LinuxArchitecture)
+#   define XF86SvgaDrivers     nv et4000 et3000 pvga1 gvga r128 ati sis tvga8900 \
+                               cirrus ncr77c22 compaq mga oak al2101 \
+                               ali cl64xx video7 ark mx realtek s3_savage s3v apm \
+                               s3_svga neo chips cyrix rendition p9x00 \
+                               spc8110 i740 i810 tdfx smi generic
+#  else
+#   define XF86SvgaDrivers     nv et4000 et3000 pvga1 gvga r128 ati sis tvga8900 \
+                               cirrus ncr77c22 compaq mga oak al2101 \
+                               ali cl64xx video7 ark mx realtek s3v apm \
+                               s3_svga neo chips cyrix rendition p9x00 \
+                               spc8110 i740 i810 tdfx smi generic
+#  endif
+# endif
+#endif
+
+#ifndef XF98SvgaDrivers
+# define XF98SvgaDrivers       generic
+#endif
+
+#ifndef XF86Vga16Drivers
+# define XF86Vga16Drivers      et4000 et3000 ncr77c22 ati sis tvga8900 \
+                               oak cl64xx generic
+#endif
+
+#ifndef XF98Vga16Drivers
+# define XF98Vga16Drivers      generic
+#endif
+
+#ifndef XF86Vga2Drivers
+# ifdef AlphaArchitecture
+#  define XF86Vga2Drivers      generic
+# else
+#  define XF86Vga2Drivers      et4000 et3000 pvga1 gvga ati sis tvga8900 \
+                               cirrus ncr77c22 /*compaq*/ oak cl64xx generic
+# endif
+#endif
+
+#ifndef XF86Vga2Banked
+# define XF86Vga2Banked                YES
+#endif
+
+#ifndef XF86MonoDrivers
+# define XF86MonoDrivers       hgc1280 sigma apollo hercules
+#endif
+
+/* This doesn't do everything (yet) */
+#ifndef XF86S3Drivers
+# if !defined(AlphaArchitecture)
+#  define XF86S3Drivers                newmmio mmio_928 s3_generic
+# else
+#  define XF86S3Drivers                newmmio mmio_928 s3_generic
+# endif
+#endif
+
+#ifndef XF86S3VDrivers
+# define XF86S3VDrivers                s3_virge
+#endif
+
+#ifndef XF86W32Drivers
+# define XF86W32Drivers                et4000w32
+#endif
+
+#if XF68FBDevServer || XF86FBDevServer
+# ifndef XF68FBDevIPLAN2p2
+#  define XF68FBDevIPLAN2p2    YES
+# endif
+# ifndef XF68FBDevIPLAN2p4
+#  define XF68FBDevIPLAN2p4    YES
+# endif
+# ifndef XF68FBDevIPLAN2p8
+#  define XF68FBDevIPLAN2p8    YES
+# endif
+# ifndef XF68FBDevILBM
+#  define XF68FBDevILBM                YES
+# endif
+# ifndef XF68FBDevAFB
+#  define XF68FBDevAFB         YES
+# endif
+# ifndef XF68FBDevCFB8
+#  define XF68FBDevCFB8                YES
+# endif
+# ifndef XF68FBDevCFB16
+#  define XF68FBDevCFB16       YES
+# endif
+# ifndef XF68FBDevCFB24
+#  if defined(i386Architecture) || defined(AlphaArchitecture)
+#   define XF68FBDevCFB24      YES
+#  else
+#   define XF68FBDevCFB24      NO
+#  endif
+# endif
+# ifndef XF68FBDevCFB32
+#  define XF68FBDevCFB32       YES
+# endif
+/* Accelerated stuff */
+# ifndef XF68FBDev77C32
+#  define XF68FBDev77C32       YES
+# endif
+# ifndef XF68FBDevIMSTT
+#  define XF68FBDevIMSTT       YES
+# endif
+# ifndef XF68FBDevMach64
+#  define XF68FBDevMach64      YES
+# endif
+# ifndef XF68FBDevPermedia2
+#  define XF68FBDevPermedia2   YES
+# endif
+#else
+# ifndef XF68FBDevIPLAN2p2
+#  define XF68FBDevIPLAN2p2    NO
+# endif
+# ifndef XF68FBDevIPLAN2p4
+#  define XF68FBDevIPLAN2p4    NO
+# endif
+# ifndef XF68FBDevIPLAN2p8
+#  define XF68FBDevIPLAN2p8    NO
+# endif
+# ifndef XF68FBDevILBM
+#  define XF68FBDevILBM                NO
+# endif
+# ifndef XF68FBDevAFB
+#  define XF68FBDevAFB         NO
+# endif
+# ifndef XF68FBDevCFB8
+#  define XF68FBDevCFB8                NO
+# endif
+# ifndef XF68FBDevCFB16
+#  define XF68FBDevCFB16       NO
+# endif
+# ifndef XF68FBDevCFB24
+#  define XF68FBDevCFB24       NO
+# endif
+# ifndef XF68FBDevCFB32
+#  define XF68FBDevCFB32       NO
+# endif
+# ifndef XF68FBDev77C32
+#  define XF68FBDev77C32       NO
+# endif
+# ifndef XF68FBDevIMSTT
+#  define XF68FBDevIMSTT       NO
+# endif
+# ifndef XF68FBDevMach64
+#  define XF68FBDevMach64      NO
+# endif
+# ifndef XF68FBDevPermedia2
+#  define XF68FBDevPermedia2   NO
+# endif
+#endif
+
+#ifndef XnestServer
+#define XnestServer            YES
+#endif
+
+#ifndef XVirtualFramebufferServer
+#define XVirtualFramebufferServer YES
+#endif
+
+/*
+ * The X servers need to run as root on most OSs.  We're now using a
+ * wrapper in that case, but we still need to make it known that the
+ * servers need SetUID.  When only using xdm, this (and the wrapper)
+ * are not required.  Disabling this automatically disables use of the
+ * wrapper.
+ */
+#if !defined(i386MachArchitecture) && !defined(OS2Architecture)
+#ifndef XserverNeedsSetUID
+#define XserverNeedsSetUID     YES
+#endif
+#endif
+
+/*
+ * The server-side of PEX is not 64-bit clean.
+ */
+#ifndef BuildPextExt
+#ifdef AlphaArchitecture
+#define BuildPexExt            NO
+#endif
+#endif
+
+/*
+ * PEX doesn't work for 1-bit and 4-bit servers
+ */
+#if !defined(BuildPexExt) || BuildPexExt
+#undef BuildPexExt
+#if XF86AccelServer || XF86SVGAServer || XF98AccelServer || \
+    XF98GANBWAPServer || XF98NEC480Server || XF98NKVNECServer || \
+    XF98WABSServer || XF98WABEPServer || XF98WSNAServer || XF98TGUIServer || \
+    XF98MGAServer || XF98SVGAServer || XF68FBDevServer || XF86FBDevServer
+#define BuildPexExt            YES
+#else
+#define BuildPexExt            NO
+#endif
+#endif
+
+/*
+ * Build GLX server interface
+ *   --- Does't work for 1-bit and 4-bit servers
+ */
+#if !defined(BuildGlxExt) || BuildGlxExt
+#  undef BuildGlxExt
+#  if XF86AccelServer || XF86SVGAServer || XF98AccelServer || \
+      XF98GANBWAPServer || XF98NEC480Server || XF98NKVNECServer || \
+      XF98WABSServer || XF98WABEPServer || XF98WSNAServer || XF98TGUIServer || \
+      XF98MGAServer || XF98SVGAServer || XF68FBDevServer || XF86FBDevServer
+#    define BuildGlxExt             YES
+#  else
+#    define BuildGlxExt             NO
+#  endif
+#endif
+
+/*
+ * XIE doesn't work for our 1-bit and 4-bit servers
+ */
+#if !defined(BuildXIE) || BuildXIE
+#undef BuildXIE
+#if XF86AccelServer || XF86SVGAServer || XF98AccelServer || \
+    XF98GANBWAPServer || XF98NEC480Server || XF98NKVNECServer || \
+    XF98WABSServer || XF98WABEPServer || XF98WSNAServer || XF98TGUIServer || \
+    XF98MGAServer || XF98SVGAServer || XF68FBDevServer || XF86FBDevServer
+#define BuildXIE               YES
+#else
+#define BuildXIE               NO
+#endif
+#endif
+
+#ifndef BuildXIElib
+#define BuildXIElib    YES
+#endif
+
+#ifndef BuildDBElib
+#define BuildDBElib    YES
+#endif
+
+#ifndef BuildRECORDlib
+#define BuildRECORDlib YES
+#endif
+
+#ifndef BuildXKBlib
+#define BuildXKBlib    YES
+#endif
+
+#ifndef BuildScreenSaverExt
+#define BuildScreenSaverExt    YES
+#endif
+
+/*
+ * Build XInput support
+ */
+#ifndef BuildXInputExt
+#define BuildXInputExt         YES
+#endif
+
+/*
+ * Include support for these XInput devices
+ */
+#ifndef WacomSupport
+#define WacomSupport           YES
+#endif
+#ifndef ElographicsSupport
+#define ElographicsSupport     YES
+#endif
+#ifndef DynaproSupport
+#define DynaproSupport         YES
+#endif
+#ifndef MicroTouchSupport
+#define MicroTouchSupport      YES
+#endif
+#ifndef SummaSketchSupport
+#define SummaSketchSupport     YES
+#endif
+#ifndef AceCadSupport
+#define AceCadSupport          YES
+#endif
+#ifndef DialBoxSupport
+#if SystemV || SystemV4
+#define DialBoxSupport         NO
+#else
+#define DialBoxSupport         YES
+#endif
+#endif
+#ifndef JoystickSupport
+#define JoystickSupport                NO
+#endif
+#ifndef CalcompSupport
+#define CalcompSupport         YES
+#endif
+
+/*
+ * Build the extra extension libs even when not including the extra extensions
+ * in the servers
+ */
+#ifndef BuildScreenSaverLibrary
+#define BuildScreenSaverLibrary        YES
+#endif
+#ifndef BuildXF86MiscLibrary
+#define BuildXF86MiscLibrary   YES
+#endif
+#ifndef BuildXF86DGALibrary
+#define BuildXF86DGALibrary    YES
+#endif
+#ifndef BuildXF86VidModeLibrary
+#define BuildXF86VidModeLibrary        YES
+#endif
+#ifndef BuildDPMSLibrary
+#define BuildDPMSLibrary       YES
+#endif
+
+/*
+ * Build the XFree86-VidMode extension
+ */
+#ifndef BuildXF86VidModeExt
+#define BuildXF86VidModeExt            YES
+#endif
+
+/*
+ * Build the XFree86-Misc extension
+ */
+#ifndef BuildXF86MiscExt
+#define BuildXF86MiscExt               YES
+#endif
+
+/*
+ * Build XF86Setup -- needs Tk and Tcl
+ */
+#ifndef BuildXF86Setup
+#if HasTk && HasTcl && BuildXF86VidModeLibrary && BuildXF86MiscLibrary && BuildXKBlib
+#define BuildXF86Setup                 YES
+#else
+#define BuildXF86Setup                 NO
+#endif
+#endif
+
+/*
+ * Build Japanese versions of XF86Setup -- needs Japanised Tk and Tcl
+ */
+#ifndef BuildJpXF86Setup
+#if HasJpTk && HasJpTcl && BuildXF86VidModeLibrary && BuildXF86MiscLibrary && BuildXKBlib
+#define BuildJpXF86Setup               YES
+#else
+#define BuildJpXF86Setup               NO
+#endif
+#endif
+
+#ifndef XF86SetupUsesStaticTk
+#define XF86SetupUsesStaticTk          YES
+#endif
+#ifndef XF86SetupUsesStaticTcl
+#define XF86SetupUsesStaticTcl         YES
+#endif
+
+/*
+ * Build the XFree86 DGA support
+ */
+#ifndef BuildXF86DGA
+#define BuildXF86DGA                   YES
+#endif
+
+/*
+ * Build the DPMS extension support
+ */
+#ifndef BuildDPMSExt
+#define BuildDPMSExt                   YES
+#endif
+
+#if Malloc0ReturnsNull
+#ifndef XtMalloc0ReturnsNullDefines
+#define XtMalloc0ReturnsNullDefines    Malloc0ReturnsNullDefines -DXTMALLOC_BC
+#endif
+#endif
+
+#ifndef UseInternalMalloc
+#define UseInternalMalloc      YES
+#endif
+
+#ifndef HasDlsymBug
+#define HasDlsymBug            NO
+#endif
+
+/*
+ * The expiry date for beta versions
+ *
+ * 853286400 is Wed Jan 15 00:00:00 1997 GMT
+ * 855964800 is Sat Feb 15 00:00:00 1997 GMT
+ * 866332800 is Sun Jun 15 00:00:00 1997 GMT
+ */
+#ifndef XF86ServerExpiry
+#define XF86ServerExpiry 866332800
+#endif
+
+/*
+ * Build the font server
+ */
+#ifndef BuildFontServer
+#define BuildFontServer                YES
+#endif
+
+/*
+ * By default, build all of the fonts.
+ */
+#ifndef Build75DpiFonts
+#define Build75DpiFonts                YES
+#endif
+#ifndef Build100DpiFonts
+#define Build100DpiFonts       YES
+#endif
+#ifndef BuildSpeedoFonts
+#define BuildSpeedoFonts       YES
+#endif
+#ifndef BuildType1Fonts
+#define BuildType1Fonts                YES
+#endif
+#ifndef BuildCyrillicFonts
+#define BuildCyrillicFonts     YES
+#endif
+#ifndef UseKoi8RForCyrillic
+#define UseKoi8RForCyrillic    YES
+#endif
+
+/*
+ * By default, create the local font directory
+ */
+#ifndef MakeLocalFontDir
+#define MakeLocalFontDir       YES
+#endif
+
+/*
+ * Build scanpci?
+ */
+#ifndef BuildScanpci
+#if SystemV || SystemV4 || (defined(LinuxArchitecture) && !defined(Mc68020Architecture) && !defined(PowerPCArchitecture) && !defined(ArmArchitecture)) || defined(i386BsdArchitecture) || defined(LynxOSArchitecture) || defined(OS2Architecture)
+#define BuildScanpci           YES
+#else
+#define BuildScanpci           NO
+#endif
+#endif
+
+#ifndef CompressAllFonts
+#define CompressAllFonts       YES
+#endif
+
+#ifndef GzipFontCompression
+#define GzipFontCompression    YES
+#endif
+
+#ifndef StripInstalledPrograms
+#define StripInstalledPrograms YES
+#endif
+
+#ifndef HasLinuxDoc
+#define HasLinuxDoc            NO
+#endif
+
+#ifndef InstallJapaneseDocs
+#define InstallJapaneseDocs    NO
+#endif
+
+#if BuildXF86DGA
+#define XFree86DGADefines      -DXFreeXDGA
+#else
+#define XFree86DGADefines      /**/
+#endif
+
+#ifndef MakeHasPosixVariableSubstitutions
+#if !HasBsdMake
+#define MakeHasPosixVariableSubstitutions      NO
+#else
+#define MakeHasPosixVariableSubstitutions      YES
+#endif
+#endif
+
+/* Server defines required for all OSs */
+#ifndef XFree86ServerDefines
+#define XFree86ServerDefines   -DSTATIC_COLOR -DAVOID_GLYPHBLT -DPIXPRIV LinkKitDefines XFree86DGADefines
+#endif
+
+#ifndef XFree86ServerOSDefines
+#define XFree86ServerOSDefines -DDDXOSINIT -DSERVER_LOCK -DDDXOSFATALERROR
+#endif
+
+#ifndef XFree86ConsoleDefines
+#ifdef i386BsdArchitecture
+#define XFree86ConsoleDefines  -DPCCONS_SUPPORT -DSYSCONS_SUPPORT -DPCVT_SUPPORT
+#else
+#define XFree86ConsoleDefines  /**/
+#endif
+#endif
+
+/* Support for USB mouse */
+#ifndef UsbMouseSupport
+#define UsbMouseSupport        NO
+#endif
+/* Does this OS has libusb ? */
+#ifndef HasLibUsb
+#define HasLibUsb      NO
+#endif
+
+#ifndef UseServerLock
+#define UseServerLock  YES
+#endif
+
+#if XF86LinkKit
+/*
+ * Definitions for LinkKit self-containment.  This should work whether or not
+ * UseInstalled is defined.
+ */
+# ifndef HasLdRunPath
+#  define HasLdRunPath NO
+# endif
+
+# ifndef TopIncludes
+#  ifdef IncRoot
+#   define TopIncludes -I$(INCROOT)
+#  else
+#   define TopIncludes /**/
+#  endif
+# endif
+# ifndef ClientLibDir
+#  if defined(UsrLibDir) || HasLdRunPath
+#   define ClientLibDir        /**/
+#  else
+#   define ClientLibDir        -L$(USRLIBDIR)
+#  endif
+# endif
+# ifndef LdPreLib
+#  if defined(LdPostLib) && defined(UsrLibDir) && !HasLdRunPath
+#   define LdPreLib    -L$(USRLIBDIR)
+#  else
+#   define LdPreLib    /**/
+#  endif
+# endif
+# ifndef LdPostLib
+#  if defined(UsrLibDir) && !HasLdRunPath
+#   define LdPostLib   -L$(USRLIBDIR)
+#  else
+#   define LdPostLib   /**/
+#  endif
+# endif
+
+#endif
+
+#ifndef LinkKitDefines
+#if XF86LinkKit
+#define LinkKitDefines -DLINKKIT
+#else
+#define LinkKitDefines /**/
+#endif
+#endif
+
+#ifndef ServerExtraDefines
+#define ServerExtraDefines     XFree86ServerDefines
+#endif
+
+#ifndef ServerOSDefines
+#define ServerOSDefines                XFree86ServerOSDefines
+#endif
+
+#ifndef LinkKitDir
+#define LinkKitDir     $(USRLIBDIR)/Server
+#endif
+
+LINKKITDIR = LinkKitDir
+XF98LINKKITDIR = LinkKitDir
+
+/*
+ * Some commonly refered to directories are defined here.
+ */
+
+#if XF86LinkKit
+       XF86SRC = $(TOP)
+  XF86ACCELSRC = $(XF86SRC)/lib86
+    XF86COMSRC = $(XF86SRC)/lib86
+ XF86CONFIGSRC = $(XF86SRC)
+     XF86HWSRC = $(XF86SRC)/lib86
+     XF86OSSRC = $(XF86SRC)/lib86
+     DRIVERSRC = $(XF86SRC)/drivers
+  VGADRIVERSRC = $(XF86SRC)/drivers/vga256
+VGA16DRIVERSRC = $(XF86SRC)/drivers/vga16
+ VGA2DRIVERSRC = $(XF86SRC)/drivers/vga2
+ MONODRIVERSRC = $(XF86SRC)/drivers/mono
+   S3DRIVERSRC = $(XF86SRC)/drivers/s3
+  S3VDRIVERSRC = $(XF86SRC)/drivers/s3_virge
+
+           XF98SRC = $(TOP)
+      XF98ACCELSRC = $(XF98SRC)/lib98
+        XF98COMSRC = $(XF98SRC)/lib98
+     XF98CONFIGSRC = $(XF98SRC)
+         XF98HWSRC = $(XF98SRC)/lib98
+      XF98HWNECSRC = $(XF98SRC)/lib98
+    XF98HWPWSKBSRC = $(XF98SRC)/lib98
+     XF98HWPWLBSRC = $(XF98SRC)/lib98
+    XF98HWGA968SRC = $(XF98SRC)/lib98
+         XF98OSSRC = $(XF98SRC)/lib98
+     XF98DRIVERSRC = $(XF98SRC)/drivers98
+  XF98VGADRIVERSRC = $(XF98SRC)/drivers98/vga256
+XF98VGA16DRIVERSRC = $(XF98SRC)/drivers98/vga16
+ XF98VGA2DRIVERSRC = $(XF98SRC)/drivers98/vga2
+ XF98MONODRIVERSRC = $(XF98SRC)/drivers98/mono
+XF98NECS3DRIVERSRC = $(XF98SRC)/drivers98/s3nec
+XF98PWSKBDRIVERSRC = $(XF98SRC)/drivers98/s3pwskb
+ XF98PWLBDRIVERSRC = $(XF98SRC)/drivers98/s3pwlb
+XF98GA968DRIVERSRC = $(XF98SRC)/drivers98/s3ga968
+
+#ifdef SiteIConfigFiles
+#undef SiteIConfigFiles
+#endif
+#define SiteIConfigFiles $(TOP)/xf86site.def $(TOP)/Imakefile $(IRULESRC)/host.def
+#else
+       XF86SRC = $(SERVERSRC)/hw/xfree86
+  XF86ACCELSRC = $(XF86SRC)/accel
+    XF86COMSRC = $(XF86SRC)/common
+ XF86CONFIGSRC = $(XF86COMSRC)
+     XF86HWSRC = $(XF86SRC)/common_hw
+     XF86OSSRC = $(XF86SRC)/os-support
+  VGADRIVERSRC = $(XF86SRC)/vga256/drivers
+VGA16DRIVERSRC = $(XF86SRC)/vga16/drivers
+ VGA2DRIVERSRC = $(XF86SRC)/vga2/drivers
+ MONODRIVERSRC = $(XF86SRC)/mono/drivers
+   S3DRIVERSRC = $(XF86SRC)/accel/s3/drivers
+  S3VDRIVERSRC = $(XF86SRC)/accel/s3_virge/drivers
+
+       XF68SRC = $(SERVERSRC)/hw/xfree68
+    XF68COMSRC = $(XF68SRC)/common
+ XF68CONFIGSRC = $(XF68COMSRC)
+     XF68OSSRC = $(XF68SRC)/os-support
+
+           XF98SRC = $(SERVERSRC)/hw/xfree98
+      XF98ACCELSRC = $(XF98SRC)/accel
+        XF98COMSRC = $(XF98SRC)/common
+     XF98CONFIGSRC = $(XF98COMSRC)
+         XF98HWSRC = $(XF98SRC)/common_hw/generic
+      XF98HWNECSRC = $(XF98SRC)/common_hw/nec
+    XF98HWPWSKBSRC = $(XF98SRC)/common_hw/pwskb
+     XF98HWPWLBSRC = $(XF98SRC)/common_hw/pwlb
+    XF98HWGA968SRC = $(XF98SRC)/common_hw/ga968
+         XF98OSSRC = $(XF98SRC)/os-support
+  XF98VGADRIVERSRC = $(XF98SRC)/vga256/drivers
+XF98VGA16DRIVERSRC = $(XF98SRC)/vga16/drivers
+ XF98VGA2DRIVERSRC = $(XF98SRC)/vga2/drivers
+ XF98MONODRIVERSRC = $(XF98SRC)/mono/drivers
+XF98NECS3DRIVERSRC = $(XF98SRC)/accel/s3nec/drivers
+XF98PWSKBDRIVERSRC = $(XF98SRC)/accel/s3pwskb/drivers
+ XF98PWLBDRIVERSRC = $(XF98SRC)/accel/s3pwlb/drivers
+XF98GA968DRIVERSRC = $(XF98SRC)/accel/s3ga968/drivers
+#endif
+
+/*
+ * Installed location of the XFree86 documentation
+ */
+
+        XFREE86DOCDIR = $(LIBDIR)/doc
+      XFREE86PSDOCDIR = $(XFREE86DOCDIR)/PostScript
+    XFREE86HTMLDOCDIR = $(XFREE86DOCDIR)/html
+XFREE86JAPANESEDOCDIR = $(XFREE86DOCDIR)/Japanese
+
+/*
+ * Other stuff used in the X Server source.
+ */
+
+#ifndef AsmDefines
+#define AsmDefines /**/
+#endif
+
+#ifndef OtherIConfigFiles
+#define OtherIConfigFiles $(IRULESRC)/xfree86.cf $(IRULESRC)/xf86.rules
+#endif
+
+#ifndef XFree86Version
+#define XFree86Version 3320
+#endif
+
+#ifndef XVendorString
+#define XVendorString  "The XFree86 Project, Inc"
+#endif
+
+#ifndef XVendorRelease
+#define XVendorRelease XFree86Version
+#endif
+
+#ifndef UseRgbTxt
+#define UseRgbTxt      YES
+#endif
+
+#ifndef ManSuffix
+#define ManSuffix      1
+#endif
+
+/*
+ * GNU Compiler stuff
+ */
+#ifndef HasGcc2
+#define HasGcc2 NO
+#endif
+#ifndef HasGcc
+#define HasGcc HasGcc2
+#endif
+#ifndef HasGcc2ForCplusplus
+#define HasGcc2ForCplusplus HasGcc2
+#endif
+
+#if HasGcc
+#ifndef DefaultCCOptions
+#ifdef UseInstalled
+#define DefaultCCOptions /* -ansi */
+#else
+#define DefaultCCOptions -ansi -pedantic
+#endif
+#endif
+#if defined(UseInstalled) || XF86LinkKit
+#ifndef UseGccMakeDepend
+#define UseGccMakeDepend YES
+#endif
+#endif
+#endif
+
+#if HasGcc2 && defined(i386Architecture)
+#ifndef DefaultGcc2i386Opt
+#define DefaultGcc2i386Opt -O2 -fno-strength-reduce
+#endif
+#endif
+
+#ifndef DontDefineXF86Contrib
+#define XF86Contrib
+#endif
+
+#ifndef HasMktemp
+#define HasMktemp      YES
+#endif
+
+#include <xf86.rules>
diff --git a/Xserver/config/imake/Imakefile b/Xserver/config/imake/Imakefile
new file mode 100644 (file)
index 0000000..16734bc
--- /dev/null
@@ -0,0 +1,54 @@
+XCOMM $TOG: Imakefile /main/10 1997/04/30 15:39:17 kaleb $
+XCOMM
+XCOMM
+XCOMM
+XCOMM
+XCOMM $XFree86: xc/config/imake/Imakefile,v 3.6.2.1 1997/06/11 12:08:33 dawes Exp $
+
+XCOMM Some compilers generate fatal errors if an -L directory does
+XCOMM not exist.  Since BUILDLIBDIR may not exist yet suppress its use.
+         LDPRELIB =
+        LDPRELIBS =
+
+DEPLIBS = 
+
+INCLUDES = -I$(TOP)/include $(TOP_X_INCLUDES)/X11
+CPP_PROGRAM = CppCmd
+CPP_DEFINES = -DCPP_PROGRAM="\"$(CPP_PROGRAM)\""
+DEFINES = $(SIGNAL_DEFINES) $(BOOTSTRAPCFLAGS) $(CPP_DEFINES)
+
+#if defined(MacIIArchitecture) || defined(SequentArchitecture) || defined(i386ScoArchitecture)
+XBSDLIB = /**/
+#endif
+
+#if !defined(OS2Architecture)
+#undef ImakeDependency
+#define ImakeDependency(dummy) @@\
+Makefile::  ProgramTargetName(imake)
+
+#if CrossCompiling
+SimpleHostProgramTarget(imake)
+#else
+SimpleProgramTarget(imake)
+#endif
+InstallLinkKitNamedProg(imake,imake,$(LINKKITDIR)/config/imake)
+#else /* OS2Architecture */
+all::
+
+CCOPTIONS = -Zsysv-signals
+EXTRA_LIBRARIES = /*nothing*/
+SimpleProgramTarget(imake)
+InstallLinkKitNamedProg(imake,imake,$(LINKKITDIR)/config/imake)
+InstallNamedProg(imakesvc.cmd,imakesvc.cmd,$(BINDIR))
+InstallLinkKitNamedProg(imakesvc.cmd,imakesvc.cmd,$(LINKKITDIR)/config/imake)
+#endif
+
+#if HasClearmake
+bootstrapdepend: depend
+#else
+bootstrapdepend:
+#endif
+
+clean::
+       RemoveFile(ProgramTargetName(ccimake))
+       $(RM) -r bootstrap
diff --git a/Xserver/config/imake/Makefile.ini b/Xserver/config/imake/Makefile.ini
new file mode 100644 (file)
index 0000000..4846ab4
--- /dev/null
@@ -0,0 +1,73 @@
+# $TOG: Makefile.ini /main/25 1997/02/19 18:00:59 mgreess $
+#
+#   WARNING    WARNING    WARNING    WARNING    WARNING    WARNING    WARNING
+#
+# This is NOT an automatically generated Makefile!  It is hand-crafted as a 
+# bootstrap, may need editing for your system.  The BOOTSTRAPCFLAGS variable
+# may be given at the top of the build tree for systems that do not define
+# any machine-specific preprocessor symbols.
+#
+# $XFree86: xc/config/imake/Makefile.ini,v 3.4.2.1 1997/06/11 12:08:33 dawes Exp $
+
+BOOTSTRAPCFLAGS = 
+CC = cc
+CDEBUGFLAGS = -O
+INCLUDES = -I../../include -I../../imports/x11/include/X11
+CFLAGS = $(BOOTSTRAPCFLAGS) $(CDEBUGFLAGS) $(INCLUDES)
+SHELL = /bin/sh
+RM = rm -f
+MV = mv
+MAKE = make
+RM_CMD = $(RM) *.CKP *.ln *.BAK *.bak *.o core errs ,* *~ *.a \
+        tags TAGS make.log
+NPROC = 1
+
+imake::
+       @echo "making imake with BOOTSTRAPCFLAGS=$(BOOTSTRAPCFLAGS) in config/imake"
+
+imake:: imake.o
+       $(CC) -o imake $(CFLAGS) imake.o
+
+imake.o: ccimake imake.c
+       $(CC) -c $(CFLAGS) `./ccimake` imake.c
+
+ccimake: ccimake.c
+       $(CC) -o ccimake $(CFLAGS) ccimake.c
+
+# a derived object erroneously would get shared across platforms by clearmake
+.NO_CONFIG_REC: ccimake
+
+bootstrap:
+       -@if [ -d bootstrap ]; then exit 0; else set -x; mkdir bootstrap; fi
+       $(MV) *.o imake bootstrap
+
+relink:
+       $(RM) imake
+       $(MAKE) $(MFLAGS) imake
+
+clean:
+       $(RM) ccimake imake.o imake
+       $(RM_CMD) \#*
+       $(RM) -r Makefile.proto Makefile Makefile.dep bootstrap
+
+depend:
+
+imake.exe::
+       @echo making imake with BOOTSTRAPCFLAGS=-DWIN32
+
+imake.exe:: imake.obj
+       cl -nologo imake.obj libc.lib kernel32.lib
+
+imake.obj: imake.c
+       cl -nologo -W2 -D__STDC__ -c -DWIN32 $(CFLAGS) imake.c
+
+clean.Win32:
+       if exist imake.exe del imake.exe
+       if exist imake.obj del imake.obj
+
+clean.os2:
+       imakesvc 4 imake imake.exe imake.o /imake.exe
+
+imake.os2: imake.c
+       $(CC) -DBSD43 $(CFLAGS) -o imake.exe imake.c
+       copy imake.exe \\ 
diff --git a/Xserver/config/imake/ccimake.c b/Xserver/config/imake/ccimake.c
new file mode 100644 (file)
index 0000000..d917902
--- /dev/null
@@ -0,0 +1,47 @@
+/* $XConsortium: ccimake.c /main/15 1996/09/28 16:14:25 rws $ */
+/*
+
+Copyright (c) 1993, 1994  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+*/
+
+/* 
+ * Warning:  This file must be kept as simple as posible so that it can 
+ * compile without any special flags on all systems.  Do not touch it unless
+ * you *really* know what you're doing.  Make changes in imakemdep.h, not here.
+ */
+
+#define CCIMAKE                        /* only get imake_ccflags definitions */
+#include "imakemdep.h"         /* things to set when porting imake */
+
+#ifndef imake_ccflags
+#define imake_ccflags "-O"
+#endif
+
+main()
+{
+       write(1, imake_ccflags, sizeof(imake_ccflags) - 1);
+       exit(0);
+}
+
diff --git a/Xserver/config/imake/imake.c b/Xserver/config/imake/imake.c
new file mode 100644 (file)
index 0000000..ced0096
--- /dev/null
@@ -0,0 +1,1509 @@
+/* $TOG: imake.c /main/97 1997/06/20 20:23:51 kaleb $ */
+
+/***************************************************************************
+ *                                                                         *
+ *                                Porting Note                             *
+ *                                                                         *
+ * Add the value of BOOTSTRAPCFLAGS to the cpp_argv table so that it will  *
+ * be passed to the template file.                                         *
+ *                                                                         *
+ ***************************************************************************/
+/* $XFree86: xc/config/imake/imake.c,v 3.13.2.16 1998/03/01 00:34:54 dawes Exp $ */
+
+/*
+ * 
+Copyright (c) 1985, 1986, 1987  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+ * 
+ * Original Author:
+ *     Todd Brunhoff
+ *     Tektronix, inc.
+ *     While a guest engineer at Project Athena, MIT
+ *
+ * imake: the include-make program.
+ *
+ * Usage: imake [-Idir] [-Ddefine] [-T template] [-f imakefile ] [-C Imakefile.c ] [-s] [-e] [-v] [make flags]
+ *
+ * Imake takes a template file (Imake.tmpl) and a prototype (Imakefile)
+ * and runs cpp on them producing a Makefile.  It then optionally runs make
+ * on the Makefile.
+ * Options:
+ *             -D      define.  Same as cpp -D argument.
+ *             -I      Include directory.  Same as cpp -I argument.
+ *             -T      template.  Designate a template other
+ *                     than Imake.tmpl
+ *             -f      specify the Imakefile file
+ *             -C      specify the name to use instead of Imakefile.c
+ *             -s[F]   show.  Show the produced makefile on the standard
+ *                     output.  Make is not run is this case.  If a file
+ *                     argument is provided, the output is placed there.
+ *              -e[F]   execute instead of show; optionally name Makefile F
+ *             -v      verbose.  Show the make command line executed.
+ *
+ * Environment variables:
+ *             
+ *             IMAKEINCLUDE    Include directory to use in addition to "."
+ *             IMAKECPP        Cpp to use instead of /lib/cpp
+ *             IMAKEMAKE       make program to use other than what is
+ *                             found by searching the $PATH variable.
+ * Other features:
+ *     imake reads the entire cpp output into memory and then scans it
+ *     for occurences of "@@".  If it encounters them, it replaces it with
+ *     a newline.  It also trims any trailing white space on output lines
+ *     (because make gets upset at them).  This helps when cpp expands
+ *     multi-line macros but you want them to appear on multiple lines.
+ *     It also changes occurences of "XCOMM" to "#", to avoid problems
+ *     with treating commands as invalid preprocessor commands.
+ *
+ *     The macros MAKEFILE and MAKE are provided as macros
+ *     to make.  MAKEFILE is set to imake's makefile (not the constructed,
+ *     preprocessed one) and MAKE is set to argv[0], i.e. the name of
+ *     the imake program.
+ *
+ * Theory of operation:
+ *   1. Determine the name of the imakefile from the command line (-f)
+ *     or from the content of the current directory (Imakefile or imakefile).
+ *     Call this <imakefile>.  This gets added to the arguments for
+ *     make as MAKEFILE=<imakefile>.
+ *   2. Determine the name of the template from the command line (-T)
+ *     or the default, Imake.tmpl.  Call this <template>
+ *   3. Determine the name of the imakeCfile from the command line (-C)
+ *     or the default, Imakefile.c.  Call this <imakeCfile>
+ *   4. Store lines of input into <imakeCfile>:
+ *     - A c-style comment header (see ImakefileCHeader below), used
+ *       to recognize temporary files generated by imake.
+ *     - If DEFAULT_OS_NAME is defined, format the utsname struct and
+ *       call the result <defaultOsName>.  Add:
+ *             #define DefaultOSName <defaultOsName>
+ *     - If DEFAULT_OS_MAJOR_REV is defined, format the utsname struct
+ *       and call the result <defaultOsMajorVersion>.  Add:
+ *             #define DefaultOSMajorVersion <defaultOsMajorVersion>
+ *     - If DEFAULT_OS_MINOR_REV is defined, format the utsname struct
+ *       and call the result <defaultOsMinorVersion>.  Add:
+ *             #define DefaultOSMinorVersion <defaultOsMinorVersion>
+ *     - If DEFAULT_OS_TEENY_REV is defined, format the utsname struct
+ *       and call the result <defaultOsTeenyVersion>.  Add:
+ *             #define DefaultOSTeenyVersion <defaultOsTeenyVersion>
+ *      - If DEFAULT_MACHINE_ARCITECTURE is defined, format the utsname struct
+ *        and define the corresponding macro. (For example on the amiga,
+ *        this will define amiga in addition to m68k).    
+ *     - If the file "localdefines" is readable in the current
+ *       directory, print a warning message to stderr and add: 
+ *             #define IMAKE_LOCAL_DEFINES     "localdefines"
+ *             #include IMAKE_LOCAL_DEFINES
+ *     - If the file "admindefines" is readable in the current
+ *       directory, print a warning message to stderr and add: 
+ *             #define IMAKE_ADMIN_DEFINES     "admindefines"
+ *             #include IMAKE_ADMIN_DEFINES
+ *     - The following lines:
+ *             #define INCLUDE_IMAKEFILE       < <imakefile> >
+ *             #define IMAKE_TEMPLATE          " <template> "
+ *             #include IMAKE_TEMPLATE
+ *     - If the file "adminmacros" is readable in the current
+ *       directory, print a warning message to stderr and add: 
+ *             #define IMAKE_ADMIN_MACROS      "adminmacros"
+ *             #include IMAKE_ADMIN_MACROS
+ *     - If the file "localmacros" is readable in the current
+ *       directory, print a warning message to stderr and add: 
+ *             #define IMAKE_LOCAL_MACROS      "localmacros"
+ *             #include IMAKE_LOCAL_MACROS
+ *   5. Start up cpp and provide it with this file.
+ *     Note that the define for INCLUDE_IMAKEFILE is intended for
+ *     use in the template file.  This implies that the imake is
+ *     useless unless the template file contains at least the line
+ *             #include INCLUDE_IMAKEFILE
+ *   6. Gather the output from cpp, and clean it up, expanding @@ to
+ *     newlines, stripping trailing white space, cpp control lines,
+ *     and extra blank lines, and changing XCOMM to #.  This cleaned
+ *     output is placed in a new file, default "Makefile", but can
+ *     be specified with -s or -e options.
+ *   7. Optionally start up make on the resulting file.
+ *
+ * The design of the template makefile should therefore be:
+ *     <set global macros like CFLAGS, etc.>
+ *     <include machine dependent additions>
+ *     #include INCLUDE_IMAKEFILE
+ *     <add any global targets like 'clean' and long dependencies>
+ */
+#if defined(__FreeBSD__) || defined(__NetBSD__)
+/* This needs to be before _POSIX_SOURCE gets defined */
+# include <sys/param.h>
+# include <sys/types.h>
+# include <sys/sysctl.h>
+#endif
+#include <stdio.h>
+#include "Xosdefs.h"
+#ifndef X_NOT_STDC_ENV
+#include <string.h>
+#endif
+#include <ctype.h>
+#ifdef WIN32
+# include "Xw32defs.h"
+#endif
+#ifndef X_NOT_POSIX
+# ifndef _POSIX_SOURCE
+#  define _POSIX_SOURCE
+# endif
+#endif
+#include <sys/types.h>
+#include <fcntl.h>
+#ifdef X_NOT_POSIX
+# ifndef WIN32
+#  include <sys/file.h>
+# endif
+#else
+# include <unistd.h>
+#endif
+#ifdef ISC
+# include <unistd.h>
+#endif
+#if defined(X_NOT_POSIX) || defined(_POSIX_SOURCE)
+# include <signal.h>
+#else
+# define _POSIX_SOURCE
+# include <signal.h>
+# undef _POSIX_SOURCE
+#endif
+#if !defined(SIGCHLD) && defined(SIGCLD)
+# define SIGCHLD               SIGCLD
+#endif
+#include <sys/stat.h>
+#ifndef X_NOT_POSIX
+# ifdef _POSIX_SOURCE
+#  ifdef SCO325
+#   include <sys/procset.h>
+#   include <sys/siginfo.h>
+#  endif
+#  include <sys/wait.h>
+# else
+#  define _POSIX_SOURCE
+#  include <sys/wait.h>
+#  undef _POSIX_SOURCE
+# endif
+# define waitCode(w)   WEXITSTATUS(w)
+# define waitSig(w)    WTERMSIG(w)
+typedef int            waitType;
+#else /* X_NOT_POSIX */
+# ifdef SYSV
+#  define waitCode(w)  (((w) >> 8) & 0x7f)
+#  define waitSig(w)   ((w) & 0xff)
+typedef int            waitType;
+# else /* SYSV */
+#  ifdef WIN32
+#   include <process.h>
+typedef int            waitType;
+#  else
+#   include <sys/wait.h>
+#   define waitCode(w) ((w).w_T.w_Retcode)
+#   define waitSig(w)  ((w).w_T.w_Termsig)
+typedef union wait     waitType;
+#  endif
+# endif
+# ifndef WIFSIGNALED
+#  define WIFSIGNALED(w) waitSig(w)
+# endif
+# ifndef WIFEXITED
+#  define WIFEXITED(w) waitCode(w)
+# endif
+#endif /* X_NOT_POSIX */
+#ifndef X_NOT_STDC_ENV
+# include <stdlib.h>
+#else
+char *malloc(), *realloc();
+void exit();
+#endif
+#if defined(macII) && !defined(__STDC__)  /* stdlib.h fails to define these */
+char *malloc(), *realloc();
+#endif /* macII */
+#ifdef X_NOT_STDC_ENV
+extern char    *getenv();
+#endif
+#include <errno.h>
+#ifdef X_NOT_STDC_ENV
+extern int     errno;
+#endif
+#ifdef __minix_vmd
+#define USE_FREOPEN            1
+#endif
+
+#if !(defined(X_NOT_STDC_ENV) || (defined(sun) && !defined(SVR4)) || defined(macII))
+#define USE_STRERROR           1
+#endif
+#ifdef __EMX__
+#define USE_STRERROR           1
+#endif
+#ifndef WIN32
+#include <sys/utsname.h>
+#endif
+#ifndef SYS_NMLN
+# ifdef _SYS_NMLN
+#  define SYS_NMLN _SYS_NMLN
+# else
+#  define SYS_NMLN 257
+# endif
+#endif
+#ifdef linux
+#include <limits.h>
+#endif
+/* 
+ * is strstr() in <strings.h> on X_NOT_STDC_ENV? 
+ * are there any X_NOT_STDC_ENV machines left in the world?
+ */
+#include <string.h>
+#include "imakemdep.h"
+
+/*
+ * This define of strerror is copied from (and should be identical to)
+ * Xos.h, which we don't want to include here for bootstrapping reasons.
+ */
+#ifndef USE_STRERROR
+# ifndef strerror
+extern char *sys_errlist[];
+extern int sys_nerr;
+#  define strerror(n) \
+    (((n) >= 0 && (n) < sys_nerr) ? sys_errlist[n] : "unknown error")
+# endif
+#endif
+
+#define        TRUE            1
+#define        FALSE           0
+
+#ifdef FIXUP_CPP_WHITESPACE
+int    InRule = FALSE;
+# ifdef INLINE_SYNTAX
+int    InInline = 0;
+# endif
+#endif
+#ifdef MAGIC_MAKE_VARS
+int xvariable = 0;
+int xvariables[10];
+#endif
+
+/*
+ * Some versions of cpp reduce all tabs in macro expansion to a single
+ * space.  In addition, the escaped newline may be replaced with a
+ * space instead of being deleted.  Blech.
+ */
+#ifdef FIXUP_CPP_WHITESPACE
+void KludgeOutputLine(), KludgeResetRule();
+#else
+# define KludgeOutputLine(arg)
+# define KludgeResetRule()
+#endif
+
+typedef        unsigned char   boolean;
+
+#ifdef USE_CC_E
+# ifndef DEFAULT_CC
+#  define DEFAULT_CC "cc"
+# endif
+#else
+# ifndef DEFAULT_CPP
+#  ifdef CPP_PROGRAM
+#   define DEFAULT_CPP CPP_PROGRAM
+#  else
+#   define DEFAULT_CPP "/lib/cpp"
+#  endif
+# endif
+#endif
+
+char *cpp = NULL;
+
+char   *tmpMakefile    = "/tmp/Imf.XXXXXX";
+char   *tmpImakefile    = "/tmp/IIf.XXXXXX";
+char   *make_argv[ ARGUMENTS ] = {
+#ifdef WIN32
+    "nmake"
+#else
+    "make"
+#endif
+};
+
+int    make_argindex;
+int    cpp_argindex;
+char   *Imakefile = NULL;
+char   *Makefile = "Makefile";
+char   *Template = "Imake.tmpl";
+char   *ImakefileC = "Imakefile.c";
+boolean haveImakefileC = FALSE;
+char   *cleanedImakefile = NULL;
+char   *program;
+char   *FindImakefile();
+char   *ReadLine();
+char   *CleanCppInput();
+char   *Strdup();
+char   *Emalloc();
+void   LogFatalI(), LogFatal(), LogMsg();
+
+void   showit();
+void   wrapup();
+void   init();
+void   AddMakeArg();
+void   AddCppArg();
+void   SetOpts();
+void   CheckImakefileC();
+void   cppit();
+void   makeit();
+void   CleanCppOutput();
+boolean        isempty();
+void   writetmpfile();
+
+boolean        verbose = FALSE;
+boolean        show = TRUE;
+
+int
+main(argc, argv)
+       int     argc;
+       char    **argv;
+{
+       FILE    *tmpfd;
+       char    makeMacro[ BUFSIZ ];
+       char    makefileMacro[ BUFSIZ ];
+
+       program = argv[0];
+       init();
+       SetOpts(argc, argv);
+
+       Imakefile = FindImakefile(Imakefile);
+       CheckImakefileC(ImakefileC);
+       if (Makefile)
+               tmpMakefile = Makefile;
+       else {
+               tmpMakefile = Strdup(tmpMakefile);
+               (void) mktemp(tmpMakefile);
+       }
+       AddMakeArg("-f");
+       AddMakeArg( tmpMakefile );
+       sprintf(makeMacro, "MAKE=%s", program);
+       AddMakeArg( makeMacro );
+       sprintf(makefileMacro, "MAKEFILE=%s", Imakefile);
+       AddMakeArg( makefileMacro );
+
+       if ((tmpfd = fopen(tmpMakefile, "w+")) == NULL)
+               LogFatal("Cannot create temporary file %s.", tmpMakefile);
+
+       cleanedImakefile = CleanCppInput(Imakefile);
+       cppit(cleanedImakefile, Template, ImakefileC, tmpfd, tmpMakefile);
+
+       if (show) {
+               if (Makefile == NULL)
+                       showit(tmpfd);
+       } else
+               makeit();
+       wrapup();
+       exit(0);
+}
+
+void
+showit(fd)
+       FILE    *fd;
+{
+       char    buf[ BUFSIZ ];
+       int     red;
+
+       fseek(fd, 0, 0);
+       while ((red = fread(buf, 1, BUFSIZ, fd)) > 0)
+               writetmpfile(stdout, buf, red, "stdout");
+       if (red < 0)
+           LogFatal("Cannot read %s.", tmpMakefile);
+}
+
+void
+wrapup()
+{
+       if (tmpMakefile != Makefile)
+               unlink(tmpMakefile);
+       if (cleanedImakefile && cleanedImakefile != Imakefile)
+               unlink(cleanedImakefile);
+       if (haveImakefileC)
+               unlink(ImakefileC);
+}
+
+#ifdef SIGNALRETURNSINT
+int
+#else
+void
+#endif
+catch(sig)
+       int     sig;
+{
+       errno = 0;
+       LogFatalI("Signal %d.", sig);
+}
+
+/*
+ * Initialize some variables.
+ */
+void
+init()
+{
+       register char   *p;
+
+       make_argindex=0;
+       while (make_argv[ make_argindex ] != NULL)
+               make_argindex++;
+       cpp_argindex = 0;
+       while (cpp_argv[ cpp_argindex ] != NULL)
+               cpp_argindex++;
+
+       /*
+        * See if the standard include directory is different than
+        * the default.  Or if cpp is not the default.  Or if the make
+        * found by the PATH variable is not the default.
+        */
+       if (p = getenv("IMAKEINCLUDE")) {
+               if (*p != '-' || *(p+1) != 'I')
+                       LogFatal("Environment var IMAKEINCLUDE %s",
+                               "must begin with -I");
+               AddCppArg(p);
+               for (; *p; p++)
+                       if (*p == ' ') {
+                               *p++ = '\0';
+                               AddCppArg(p);
+                       }
+       }
+       if (p = getenv("IMAKECPP"))
+               cpp = p;
+       if (p = getenv("IMAKEMAKE"))
+               make_argv[0] = p;
+
+       if (signal(SIGINT, SIG_IGN) != SIG_IGN)
+               signal(SIGINT, catch);
+#ifdef SIGCHLD
+       signal(SIGCHLD, SIG_DFL);
+#endif
+}
+
+void
+AddMakeArg(arg)
+       char    *arg;
+{
+       errno = 0;
+       if (make_argindex >= ARGUMENTS-1)
+               LogFatal("Out of internal storage.", "");
+       make_argv[ make_argindex++ ] = arg;
+       make_argv[ make_argindex ] = NULL;
+}
+
+void
+AddCppArg(arg)
+       char    *arg;
+{
+       errno = 0;
+       if (cpp_argindex >= ARGUMENTS-1)
+               LogFatal("Out of internal storage.", "");
+       cpp_argv[ cpp_argindex++ ] = arg;
+       cpp_argv[ cpp_argindex ] = NULL;
+}
+
+void
+SetOpts(argc, argv)
+       int     argc;
+       char    **argv;
+{
+       errno = 0;
+       /*
+        * Now gather the arguments for make
+        */
+       for(argc--, argv++; argc; argc--, argv++) {
+           /*
+            * We intercept these flags.
+            */
+           if (argv[0][0] == '-') {
+               if (argv[0][1] == 'D') {
+                   AddCppArg(argv[0]);
+               } else if (argv[0][1] == 'I') {
+                   AddCppArg(argv[0]);
+               } else if (argv[0][1] == 'f') {
+                   if (argv[0][2])
+                       Imakefile = argv[0]+2;
+                   else {
+                       argc--, argv++;
+                       if (! argc)
+                           LogFatal("No description arg after -f flag", "");
+                       Imakefile = argv[0];
+                   }
+               } else if (argv[0][1] == 's') {
+                   if (argv[0][2])
+                       Makefile = ((argv[0][2] == '-') && !argv[0][3]) ?
+                           NULL : argv[0]+2;
+                   else {
+                       argc--, argv++;
+                       if (!argc)
+                           LogFatal("No description arg after -s flag", "");
+                       Makefile = ((argv[0][0] == '-') && !argv[0][1]) ?
+                           NULL : argv[0];
+                   }
+                   show = TRUE;
+               } else if (argv[0][1] == 'e') {
+                  Makefile = (argv[0][2] ? argv[0]+2 : NULL);
+                  show = FALSE;
+               } else if (argv[0][1] == 'T') {
+                   if (argv[0][2])
+                       Template = argv[0]+2;
+                   else {
+                       argc--, argv++;
+                       if (! argc)
+                           LogFatal("No description arg after -T flag", "");
+                       Template = argv[0];
+                   }
+               } else if (argv[0][1] == 'C') {
+                   if (argv[0][2])
+                       ImakefileC = argv[0]+2;
+                   else {
+                       argc--, argv++;
+                       if (! argc)
+                           LogFatal("No imakeCfile arg after -C flag", "");
+                       ImakefileC = argv[0];
+                   }
+               } else if (argv[0][1] == 'v') {
+                   verbose = TRUE;
+               } else
+                   AddMakeArg(argv[0]);
+           } else
+               AddMakeArg(argv[0]);
+       }
+#ifdef USE_CC_E
+       if (!cpp)
+       {
+               AddCppArg("-E");
+               cpp = DEFAULT_CC;
+       }
+#else
+       if (!cpp)
+               cpp = DEFAULT_CPP;
+#endif
+       cpp_argv[0] = cpp;
+       AddCppArg(ImakefileC);
+}
+
+char *
+FindImakefile(Imakefile)
+       char    *Imakefile;
+{
+       if (Imakefile) {
+               if (access(Imakefile, R_OK) < 0)
+                       LogFatal("Cannot find %s.", Imakefile);
+       } else {
+               if (access("Imakefile", R_OK) < 0)
+                       if (access("imakefile", R_OK) < 0)
+                               LogFatal("No description file.", "");
+                       else
+                               Imakefile = "imakefile";
+               else
+                       Imakefile = "Imakefile";
+       }
+       return(Imakefile);
+}
+
+void
+LogFatalI(s, i)
+       char *s;
+       int i;
+{
+       /*NOSTRICT*/
+       LogFatal(s, (char *)(long)i);
+}
+
+void
+LogFatal(x0,x1)
+       char *x0, *x1;
+{
+       static boolean  entered = FALSE;
+
+       if (entered)
+               return;
+       entered = TRUE;
+
+       LogMsg(x0, x1);
+       fprintf(stderr, "  Stop.\n");
+       wrapup();
+       exit(1);
+}
+
+void
+LogMsg(x0,x1)
+       char *x0, *x1;
+{
+       int error_number = errno;
+
+       if (error_number) {
+               fprintf(stderr, "%s: ", program);
+               fprintf(stderr, "%s\n", strerror(error_number));
+       }
+       fprintf(stderr, "%s: ", program);
+       fprintf(stderr, x0, x1);
+       fprintf(stderr, "\n");
+}
+
+void
+showargs(argv)
+       char    **argv;
+{
+       for (; *argv; argv++)
+               fprintf(stderr, "%s ", *argv);
+       fprintf(stderr, "\n");
+}
+
+#define ImakefileCHeader "/* imake - temporary file */"
+
+void
+CheckImakefileC(masterc)
+       char *masterc;
+{
+       char mkcbuf[1024];
+       FILE *inFile;
+
+       if (access(masterc, F_OK) == 0) {
+               inFile = fopen(masterc, "r");
+               if (inFile == NULL)
+                       LogFatal("Refuse to overwrite: %s", masterc);
+               if ((fgets(mkcbuf, sizeof(mkcbuf), inFile) &&
+                    strncmp(mkcbuf, ImakefileCHeader, 
+                            sizeof(ImakefileCHeader)-1)))
+               {
+                       fclose(inFile);
+                       LogFatal("Refuse to overwrite: %s", masterc);
+               }
+               fclose(inFile);
+       }
+}
+
+#define LocalDefineFmt "#define %s \"%s\"\n"
+#define IncludeFmt     "#include %s\n"
+#define ImakeDefSym    "INCLUDE_IMAKEFILE"
+#define ImakeTmplSym   "IMAKE_TEMPLATE"
+#define OverrideWarning        "Warning: local file \"%s\" overrides global macros."
+
+boolean
+optional_include(inFile, defsym, fname)
+        FILE   *inFile;
+        char    *defsym;
+        char    *fname;
+{
+       errno = 0;
+       if (access(fname, R_OK) == 0) {
+               LogMsg(OverrideWarning, fname);
+               return (fprintf(inFile, LocalDefineFmt, defsym, fname) < 0 ||
+                       fprintf(inFile, IncludeFmt, defsym) < 0);
+       }
+       return FALSE;
+}
+
+void
+doit(outfd, cmd, argv)
+       FILE    *outfd;
+       char    *cmd;
+       char    **argv;
+{
+       int     pid;
+       waitType        status;
+
+       /*
+        * Fork and exec the command.
+        */
+#ifdef WIN32
+       if (outfd)
+               dup2(fileno(outfd), 1);
+       status = _spawnvp(_P_WAIT, cmd, argv);
+       if (status < 0)
+               LogFatal("Cannot spawn %s.", cmd);
+       if (status > 0)
+               LogFatalI("Exit code %d.", status);
+#else
+       pid = fork();
+       if (pid < 0)
+               LogFatal("Cannot fork.", "");
+       if (pid) {      /* parent... simply wait */
+               while (wait(&status) > 0) {
+                       errno = 0;
+                       if (WIFSIGNALED(status))
+                               LogFatalI("Signal %d.", waitSig(status));
+                       if (WIFEXITED(status) && waitCode(status))
+                               LogFatalI("Exit code %d.", waitCode(status));
+               }
+       }
+       else {  /* child... dup and exec cmd */
+               if (verbose)
+                       showargs(argv);
+               if (outfd)
+                       dup2(fileno(outfd), 1);
+               execvp(cmd, argv);
+               LogFatal("Cannot exec %s.", cmd);
+       }
+#endif
+}
+
+#ifndef WIN32
+static void
+parse_utsname(name, fmt, result, msg)
+     struct utsname *name;
+     char *fmt;
+     char *result;
+     char *msg;
+{
+  char buf[SYS_NMLN * 5 + 1];
+  char *ptr = buf;
+  int arg;
+
+  /* Assemble all the pieces into a buffer. */
+  for (arg = 0; fmt[arg] != ' '; arg++)
+    {
+      /* Our buffer is only guaranteed to hold 5 arguments. */
+      if (arg >= 5)
+       LogFatal(msg, fmt);
+
+      switch (fmt[arg])
+       {
+       case 's':
+         if (arg > 0)
+           *ptr++ = ' ';
+         strcpy(ptr, name->sysname);
+         ptr += strlen(ptr);
+         break;
+
+       case 'n':
+         if (arg > 0)
+           *ptr++ = ' ';
+         strcpy(ptr, name->nodename);
+         ptr += strlen(ptr);
+         break;
+
+       case 'r':
+         if (arg > 0)
+           *ptr++ = ' ';
+         strcpy(ptr, name->release);
+         ptr += strlen(ptr);
+         break;
+
+       case 'v':
+         if (arg > 0)
+           *ptr++ = ' ';
+         strcpy(ptr, name->version);
+         ptr += strlen(ptr);
+         break;
+
+       case 'm':
+         if (arg > 0)
+           *ptr++ = ' ';
+         strcpy(ptr, name->machine);
+         ptr += strlen(ptr);
+         break;
+
+       default:
+         LogFatal(msg, fmt);
+       }
+    }
+
+  /* Just in case... */
+  if (strlen(buf) >= sizeof(buf))
+    LogFatal("Buffer overflow parsing uname.", "");
+
+  /* Parse the buffer.  The sscanf() return value is rarely correct. */
+  *result = '\0';
+  (void) sscanf(buf, fmt + arg + 1, result);
+}
+
+/* Trim leading 0's and periods from version names.  The 0's cause
+   the number to be interpreted as octal numbers.  Some version strings
+   have the potential for different numbers of .'s in them.
+ */
+       
+static char *
+trim_version(p)
+       char *p;
+{
+
+       if (p != 0 && *p != '\0')
+       {
+               while ((*p == '0' || *p == '.') && *(p + 1) != '\0')
+                       ++p;
+       }
+       return (p);
+}
+#endif
+
+
+#ifdef linux
+const char *libc_c=
+"#include <stdio.h>\n"
+"#include <ctype.h>\n"
+"\n"
+"#if 0\n"
+"#pragma weak gnu_get_libc_version\n"
+"#pragma weak __libc_version\n"
+"#pragma weak __linux_C_lib_version\n"
+"#else\n"
+"asm (\".weak gnu_get_libc_version\");\n"
+"asm (\".weak __libc_version\");\n"
+"asm (\".weak __linux_C_lib_version\");\n"
+"#endif\n"
+"\n"
+"extern const char * gnu_get_libc_version (void);\n"
+"extern const char * __linux_C_lib_version;\n"
+"extern const char __libc_version [];\n"
+"\n"
+"int\n"
+"main ()\n"
+"{\n"
+"  int libcmajor = 0, libcminor = 0, libcteeny = 0;\n"
+"\n"
+"  if (((&__linux_C_lib_version != 0)\n"
+"       && ((&__libc_version != 0) || (gnu_get_libc_version != 0)))\n"
+"      || (!(&__linux_C_lib_version != 0) && !(&__libc_version != 0)\n"
+"        && !(gnu_get_libc_version != 0)))\n"
+"  {\n"
+"    libcmajor = 0;\n"
+"    libcminor = 0;\n"
+"    libcteeny = 0;\n"
+"  }\n"
+"  else\n"
+"  {\n"
+"    const char * ptr;\n"
+"    int glibcmajor = 0;\n"
+"\n"
+"    if (gnu_get_libc_version != 0)\n"
+"    {\n"
+"      ptr = gnu_get_libc_version ();\n"
+"      glibcmajor = 4;\n"
+"    }\n"
+"    else if (&__libc_version != 0)\n"
+"    {\n"
+"      ptr = __libc_version;\n"
+"      glibcmajor = 4;\n"
+"    }\n"
+"    else\n"
+"      ptr = __linux_C_lib_version;\n"
+"\n"
+"    while (!isdigit (*ptr))\n"
+"      ptr++;\n"
+"\n"
+"    sscanf (ptr, \"%d.%d.%d\", &libcmajor, &libcminor, &libcteeny);\n"
+"    libcmajor += glibcmajor;\n"
+"  }\n"
+"\n"
+"  printf(\"#define DefaultLinuxCLibMajorVersion %d\\n\", libcmajor);\n"
+"  printf(\"#define DefaultLinuxCLibMinorVersion %d\\n\", libcminor);\n"
+"  printf(\"#define DefaultLinuxCLibTeenyVersion %d\\n\", libcteeny);\n"
+"\n"
+"  return 0;\n"
+"}\n"
+;
+
+static void get_libc_version(inFile)
+  FILE* inFile;
+{
+  char *aout = tmpnam (NULL);
+  FILE *fp;
+  const char *format = "%s -o %s -x c -";
+  char *cc;
+  int len;
+  char *command;
+
+  cc = getenv ("CC");
+  if (cc == NULL)
+    cc = "gcc";
+  len = strlen (aout) + strlen (format) + strlen (cc);
+  if (len < 128) len = 128;
+  command = alloca (len);
+
+  if (snprintf (command , len, format, cc, aout) == len)
+    abort ();
+
+  fp = popen (command, "w");
+  if (fp == NULL || fprintf (fp, "%s\n", libc_c) < 0
+      || pclose (fp) != 0)
+    abort ();
+
+  fp = popen (aout, "r");
+  if (fp == NULL)
+    abort ();
+
+  while (fgets (command, len, fp))
+    fprintf (inFile, command);
+  
+  len = pclose (fp);
+  remove (aout);
+  if (len)
+    abort ();
+}
+
+static void get_ld_version(inFile)
+  FILE* inFile;
+{
+  FILE* ldprog = popen ("ld -v", "r");
+  char c;
+  int ldmajor, ldminor;
+
+  if (ldprog) {
+    do {
+      c = fgetc (ldprog);
+    } while (c != EOF && !isdigit (c));
+    ungetc (c, ldprog);
+    (void) fscanf (ldprog, "%d.%d", &ldmajor, &ldminor);
+    fprintf(inFile, "#define DefaultLinuxBinUtilsMajorVersion %d\n", 
+           ldmajor * 10 + ldminor);    
+    pclose (ldprog);
+  }
+}
+#endif
+
+#ifndef PATH_MAX
+#define PATH_MAX 1024
+#endif
+
+#ifndef __EMX__
+static void get_gcc_incdir(inFile)
+  FILE* inFile;
+{
+  static char* gcc_path[] = {
+#if defined(linux) || defined(__OpenBSD__)
+    "/usr/bin/cc",     /* for Linux PostIncDir */
+#endif
+    "/usr/local/bin/gcc",
+    "/opt/gnu/bin/gcc"
+  };
+  struct stat sb;
+  int i;
+  FILE* gccproc;
+  char buf[PATH_MAX];
+  char cmd[PATH_MAX];
+  char* ptr;
+
+  buf[0] = '\0';
+  for (i = 0; i < sizeof gcc_path / sizeof gcc_path[0]; i++) {
+    if (lstat (gcc_path[i], &sb) == 0) {
+      strcpy (cmd, gcc_path[i]);
+      strcat (cmd, " --print-libgcc-file-name");
+      if ((gccproc = popen (cmd, "r")) != NULL) {
+       if (fgets (buf, PATH_MAX, gccproc) != NULL) {
+         ptr = strstr (buf, "libgcc.a");
+         if (ptr) strcpy (ptr, "include");
+       }
+       (void) pclose (gccproc);
+       break;
+      }
+    }
+  }
+  if (buf[0])
+    fprintf (inFile, "#define DefaultGccIncludeDir %s\n", buf);
+}
+#endif
+
+boolean
+define_os_defaults(inFile)
+       FILE    *inFile;
+{
+#if !defined(WIN32) && !defined(__EMX__)
+#if (defined(DEFAULT_OS_NAME) || defined(DEFAULT_OS_MAJOR_REV) || \
+     defined(DEFAULT_OS_MINOR_REV) || defined(DEFAUL_OS_TEENY_REV))
+       struct utsname name;
+       char buf[SYS_NMLN * 5 + 1];
+
+       /* Obtain the system information. */
+       if (uname(&name) < 0)
+               LogFatal("Cannot invoke uname", "");
+
+# ifdef DEFAULT_OS_NAME
+       parse_utsname(&name, DEFAULT_OS_NAME, buf, 
+                     "Bad DEFAULT_OS_NAME syntax %s");
+#  ifdef DEFAULT_OS_NAME_FROB
+       DEFAULT_OS_NAME_FROB(buf, sizeof buf);
+#  endif
+       if (buf[0] != '\0')
+               fprintf(inFile, "#define DefaultOSName %s\n", buf);
+# endif
+
+# ifdef DEFAULT_OS_MAJOR_REV
+       parse_utsname(&name, DEFAULT_OS_MAJOR_REV, buf,
+                     "Bad DEFAULT_OS_MAJOR_REV syntax %s");
+#  ifdef DEFAULT_OS_MAJOR_REV_FROB
+       DEFAULT_OS_MAJOR_REV_FROB(buf, sizeof buf);
+#  endif
+       fprintf(inFile, "#define DefaultOSMajorVersion %s\n",
+               *buf ? trim_version(buf) : "0");
+# endif
+
+# ifdef DEFAULT_OS_MINOR_REV
+       parse_utsname(&name, DEFAULT_OS_MINOR_REV, buf,
+                     "Bad DEFAULT_OS_MINOR_REV syntax %s");
+#  ifdef DEFAULT_OS_MINOR_REV_FROB
+       DEFAULT_OS_MINOR_REV_FROB(buf, sizeof buf);
+#  endif
+       fprintf(inFile, "#define DefaultOSMinorVersion %s\n",
+               *buf ? trim_version(buf) : "0");
+# endif
+
+# ifdef DEFAULT_OS_TEENY_REV
+       parse_utsname(&name, DEFAULT_OS_TEENY_REV, buf,
+                     "Bad DEFAULT_OS_TEENY_REV syntax %s");
+#  ifdef DEFAULT_OS_TEENY_REV_FROB
+       DEFAULT_OS_TEENY_REV_FROB(buf, sizeof buf);
+#  endif
+       fprintf(inFile, "#define DefaultOSTeenyVersion %s\n",
+               *buf ? trim_version(buf) : "0");
+# endif
+# ifdef DEFAULT_MACHINE_ARCHITECTURE
+       parse_utsname(&name, DEFAULT_MACHINE_ARCHITECTURE, buf, 
+                     "Bad DEFAULT_MACHINE_ARCHITECTURE %s");
+       fprintf(inFile, "#ifndef %s\n# define %s\n#endif\n", buf, buf);
+# endif
+#endif
+#ifdef linux
+    get_libc_version (inFile);
+    get_ld_version(inFile);
+#endif
+    get_gcc_incdir(inFile);
+#endif /* WIN32 */
+       return FALSE;
+}
+
+void
+cppit(imakefile, template, masterc, outfd, outfname)
+       char    *imakefile;
+       char    *template;
+       char    *masterc;
+       FILE    *outfd;
+       char    *outfname;
+{
+       FILE    *inFile;
+
+       haveImakefileC = TRUE;
+       inFile = fopen(masterc, "w");
+       if (inFile == NULL)
+               LogFatal("Cannot open %s for output.", masterc);
+       if (fprintf(inFile, "%s\n", ImakefileCHeader) < 0 ||
+           define_os_defaults(inFile) ||
+           optional_include(inFile, "IMAKE_LOCAL_DEFINES", "localdefines") ||
+           optional_include(inFile, "IMAKE_ADMIN_DEFINES", "admindefines") ||
+           fprintf(inFile, "#define %s <%s>\n", ImakeDefSym, imakefile) < 0 ||
+           fprintf(inFile, LocalDefineFmt, ImakeTmplSym, template) < 0 ||
+           fprintf(inFile, IncludeFmt, ImakeTmplSym) < 0 ||
+           optional_include(inFile, "IMAKE_ADMIN_MACROS", "adminmacros") ||
+           optional_include(inFile, "IMAKE_LOCAL_MACROS", "localmacros") ||
+           fflush(inFile) || 
+           fclose(inFile))
+               LogFatal("Cannot write to %s.", masterc);
+       /*
+        * Fork and exec cpp
+        */
+       doit(outfd, cpp, cpp_argv);
+       CleanCppOutput(outfd, outfname);
+}
+
+void
+makeit()
+{
+       doit(NULL, make_argv[0], make_argv);
+}
+
+char *
+CleanCppInput(imakefile)
+       char    *imakefile;
+{
+       FILE    *outFile = NULL;
+       FILE    *inFile;
+       char    *buf,           /* buffer for file content */
+               *pbuf,          /* walking pointer to buf */
+               *punwritten,    /* pointer to unwritten portion of buf */
+               *ptoken,        /* pointer to # token */
+               *pend,          /* pointer to end of # token */
+               savec;          /* temporary character holder */
+       int     count;
+       struct stat     st;
+
+       /*
+        * grab the entire file.
+        */
+       if (!(inFile = fopen(imakefile, "r")))
+               LogFatal("Cannot open %s for input.", imakefile);
+       if (fstat(fileno(inFile), &st) < 0)
+               LogFatal("Cannot stat %s for size.", imakefile);
+       buf = Emalloc((int)st.st_size+3);
+       count = fread(buf + 2, 1, st.st_size, inFile);
+       if (count == 0  &&  st.st_size != 0)
+               LogFatal("Cannot read %s:", imakefile);
+       fclose(inFile);
+       buf[0] = '\n';
+       buf[1] = '\n';
+       buf[count + 2] = '\0';
+
+       punwritten = pbuf = buf + 2;
+       while (*pbuf) {
+           /* for compatibility, replace make comments for cpp */
+           if (*pbuf == '#' && pbuf[-1] == '\n' && pbuf[-2] != '\\') {
+               ptoken = pbuf+1;
+               while (*ptoken == ' ' || *ptoken == '\t')
+                       ptoken++;
+               pend = ptoken;
+               while (*pend && *pend != ' ' && *pend != '\t' && *pend != '\n')
+                       pend++;
+               savec = *pend;
+               *pend = '\0';
+               if (strcmp(ptoken, "define") &&
+                   strcmp(ptoken, "if") &&
+                   strcmp(ptoken, "ifdef") &&
+                   strcmp(ptoken, "ifndef") &&
+                   strcmp(ptoken, "include") &&
+                   strcmp(ptoken, "line") &&
+                   strcmp(ptoken, "else") &&
+                   strcmp(ptoken, "elif") &&
+                   strcmp(ptoken, "endif") &&
+                   strcmp(ptoken, "error") &&
+                   strcmp(ptoken, "pragma") &&
+                   strcmp(ptoken, "undef")) {
+                   if (outFile == NULL) {
+                       tmpImakefile = Strdup(tmpImakefile);
+                       (void) mktemp(tmpImakefile);
+                       outFile = fopen(tmpImakefile, "w");
+                       if (outFile == NULL)
+                           LogFatal("Cannot open %s for write.",
+                               tmpImakefile);
+                   }
+                   writetmpfile(outFile, punwritten, pbuf-punwritten,
+                                tmpImakefile);
+                   if (ptoken > pbuf + 1)
+                       writetmpfile(outFile, "XCOMM", 5, tmpImakefile);
+                   else
+                       writetmpfile(outFile, "XCOMM ", 6, tmpImakefile);
+                   punwritten = pbuf + 1;
+               }
+               *pend = savec;
+           }
+           pbuf++;
+       }
+       if (outFile) {
+           writetmpfile(outFile, punwritten, pbuf-punwritten, tmpImakefile);
+           fclose(outFile);
+           return tmpImakefile;
+       }
+
+       return(imakefile);
+}
+
+void
+CleanCppOutput(tmpfd, tmpfname)
+       FILE    *tmpfd;
+       char    *tmpfname;
+{
+       char    *input;
+       int     blankline = 0;
+
+       while(input = ReadLine(tmpfd, tmpfname)) {
+               if (isempty(input)) {
+                       if (blankline++)
+                               continue;
+                       KludgeResetRule();
+               } else {
+                       blankline = 0;
+                       KludgeOutputLine(&input);
+                       writetmpfile(tmpfd, input, strlen(input), tmpfname);
+               }
+               writetmpfile(tmpfd, "\n", 1, tmpfname);
+       }
+       fflush(tmpfd);
+#ifdef NFS_STDOUT_BUG
+       /*
+        * On some systems, NFS seems to leave a large number of nulls at
+        * the end of the file.  Ralph Swick says that this kludge makes the
+        * problem go away.
+        */
+       ftruncate (fileno(tmpfd), (off_t)ftell(tmpfd));
+#endif
+}
+
+/*
+ * Determine if a line has nothing in it.  As a side effect, we trim white
+ * space from the end of the line.  Cpp magic cookies are also thrown away.
+ * "XCOMM" token is transformed to "#".
+ */
+boolean
+isempty(line)
+       register char   *line;
+{
+       register char   *pend;
+
+       /*
+        * Check for lines of the form
+        *      # n "...
+        * or
+        *      # line n "...
+        */
+       if (*line == '#') {
+               pend = line+1;
+               if (*pend == ' ')
+                       pend++;
+               if (*pend == 'l' && pend[1] == 'i' && pend[2] == 'n' &&
+                   pend[3] == 'e' && pend[4] == ' ')
+                       pend += 5;
+               if (isdigit(*pend)) {
+                       do {
+                           pend++;
+                       } while (isdigit(*pend));
+                       if (*pend == '\n' || *pend == '\0')
+                               return(TRUE);
+                       if (*pend++ == ' ' && *pend == '"')
+                               return(TRUE);
+               }
+               while (*pend)
+                   pend++;
+       } else {
+           for (pend = line; *pend; pend++) {
+               if (*pend == 'X' && pend[1] == 'C' && pend[2] == 'O' &&
+                   pend[3] == 'M' && pend[4] == 'M' &&
+                   (pend == line || pend[-1] == ' ' || pend[-1] == '\t') &&
+                   (pend[5] == ' ' || pend[5] == '\t' || pend[5] == '\0'))
+               {
+                   *pend = '#';
+                   strcpy(pend+1, pend+5);
+               }
+#ifdef MAGIC_MAKE_VARS
+               if (*pend == 'X' && pend[1] == 'V' && pend[2] == 'A' &&
+                   pend[3] == 'R')
+               {
+                   char varbuf[5];
+                   int i;
+
+                   if (pend[4] == 'd' && pend[5] == 'e' && pend[6] == 'f' &&
+                       pend[7] >= '0' && pend[7] <= '9')
+                   {
+                       i = pend[7] - '0';
+                       sprintf(varbuf, "%0.4d", xvariable);
+                       strncpy(pend+4, varbuf, 4);
+                       xvariables[i] = xvariable;
+                       xvariable = (xvariable + 1) % 10000;
+                   }
+                   else if (pend[4] == 'u' && pend[5] == 's' &&
+                            pend[6] == 'e' && pend[7] >= '0' &&
+                            pend[7] <= '9')
+                   {
+                       i = pend[7] - '0';
+                       sprintf(varbuf, "%0.4d", xvariables[i]);
+                       strncpy(pend+4, varbuf, 4);
+                   }
+               }
+#endif
+           }
+       }
+       while (--pend >= line && (*pend == ' ' || *pend == '\t')) ;
+       pend[1] = '\0';
+       return (*line == '\0');
+}
+
+/*ARGSUSED*/
+char *
+ReadLine(tmpfd, tmpfname)
+       FILE    *tmpfd;
+       char    *tmpfname;
+{
+       static boolean  initialized = FALSE;
+       static char     *buf, *pline, *end;
+       register char   *p1, *p2;
+
+       if (! initialized) {
+#ifdef WIN32
+               FILE *fp = tmpfd;
+#endif
+               int     total_red;
+               struct stat     st;
+
+               /*
+                * Slurp it all up.
+                */
+               fseek(tmpfd, 0, 0);
+               if (fstat(fileno(tmpfd), &st) < 0)
+                       LogFatal("cannot stat %s for size", tmpMakefile);
+               pline = buf = Emalloc((int)st.st_size+1);
+               total_red = fread(buf, 1, st.st_size, tmpfd);
+               if (total_red == 0  &&  st.st_size != 0)
+                       LogFatal("cannot read %s", tmpMakefile);
+               end = buf + total_red;
+               *end = '\0';
+               fseek(tmpfd, 0, 0);
+#if defined(SYSV) || defined(WIN32) || defined(USE_FREOPEN)
+               tmpfd = freopen(tmpfname, "w+", tmpfd);
+#ifdef WIN32
+               if (! tmpfd) /* if failed try again */
+                       tmpfd = freopen(tmpfname, "w+", fp);
+#endif
+               if (! tmpfd)
+                       LogFatal("cannot reopen %s\n", tmpfname);
+#else  /* !SYSV */
+               ftruncate(fileno(tmpfd), (off_t) 0);
+#endif /* !SYSV */
+               initialized = TRUE;
+           fprintf (tmpfd, "# Makefile generated by imake - do not edit!\n");
+           fprintf (tmpfd, "# %s\n",
+               "$TOG: imake.c /main/97 1997/06/20 20:23:51 kaleb $");
+       }
+
+       for (p1 = pline; p1 < end; p1++) {
+               if (*p1 == '@' && *(p1+1) == '@'
+                   /* ignore ClearCase version-extended pathnames */
+                   && !(p1 != pline && !isspace(*(p1-1)) && *(p1+2) == '/'))
+               { /* soft EOL */
+                       *p1++ = '\0';
+                       p1++; /* skip over second @ */
+                       break;
+               }
+               else if (*p1 == '\n') { /* real EOL */
+#ifdef WIN32
+                       if (p1 > pline && p1[-1] == '\r')
+                               p1[-1] = '\0';
+#endif
+                       *p1++ = '\0';
+                       break;
+               }
+       }
+
+       /*
+        * return NULL at the end of the file.
+        */
+       p2 = (pline == p1 ? NULL : pline);
+       pline = p1;
+       return(p2);
+}
+
+void
+writetmpfile(fd, buf, cnt, fname)
+       FILE    *fd;
+       int     cnt;
+       char    *buf;
+       char    *fname;
+{
+       if (fwrite(buf, sizeof(char), cnt, fd) == -1)
+               LogFatal("Cannot write to %s.", fname);
+}
+
+char *
+Emalloc(size)
+       int     size;
+{
+       char    *p;
+
+       if ((p = malloc(size)) == NULL)
+               LogFatalI("Cannot allocate %d bytes", size);
+       return(p);
+}
+
+#ifdef FIXUP_CPP_WHITESPACE
+void
+KludgeOutputLine(pline)
+       char    **pline;
+{
+       char    *p = *pline;
+       char    quotechar = '\0';
+
+       switch (*p) {
+           case '#':   /*Comment - ignore*/
+               break;
+           case '\t':  /*Already tabbed - ignore it*/
+               break;
+           case ' ':   /*May need a tab*/
+           default:
+# ifdef INLINE_SYNTAX
+               if (*p == '<' && p[1] == '<') { /* inline file close */
+                   InInline--;
+                   InRule = TRUE;
+                   break;
+               }
+# endif
+               /*
+                * The following cases should not be treated as beginning of 
+                * rules:
+                * variable := name     (GNU make)
+                * variable = .*:.*     (':' should be allowed as value)
+                *      sed 's:/a:/b:'  (: used in quoted values)
+                */
+               for (; *p; p++) {
+                   if (quotechar) {
+                       if (quotechar == '\\' ||
+                           (*p == quotechar &&
+# ifdef WIN32
+                            quotechar != ')' &&
+# endif
+                            p[-1] != '\\'))
+                           quotechar = '\0';
+                       continue;
+                   }
+                   switch (*p) {
+                   case '\\':
+                   case '"':
+                   case '\'':
+                       quotechar = *p;
+                       break;
+                   case '(':
+                       quotechar = ')';
+                       break;
+                   case '{':
+                       quotechar = '}';
+                       break;
+                   case '[':
+                       quotechar = ']';
+                       break;
+                   case '=':
+# ifdef REMOVE_CPP_LEADSPACE
+                       if (!InRule && **pline == ' ') {
+                           while (**pline == ' ')
+                               (*pline)++;
+                       }
+# endif
+                       goto breakfor;
+# ifdef INLINE_SYNTAX
+                   case '<':
+                       if (p[1] == '<') /* inline file start */
+                           InInline++;
+                       break;
+# endif
+                   case ':':
+                       if (p[1] == '=')
+                           goto breakfor;
+                       while (**pline == ' ')
+                           (*pline)++;
+                       InRule = TRUE;
+                       return;
+                   }
+               }
+breakfor:
+               if (InRule && **pline == ' ')
+                   **pline = '\t';
+               break;
+       }
+}
+
+void
+KludgeResetRule()
+{
+       InRule = FALSE;
+}
+#endif /* FIXUP_CPP_WHITESPACE */
+
+char *
+Strdup(cp)
+       register char *cp;
+{
+       register char *new = Emalloc(strlen(cp) + 1);
+
+       strcpy(new, cp);
+       return new;
+}
diff --git a/Xserver/config/imake/imake.man b/Xserver/config/imake/imake.man
new file mode 100644 (file)
index 0000000..d1f162b
--- /dev/null
@@ -0,0 +1,256 @@
+.\" $XConsortium: imake.man /main/29 1996/09/28 16:14:42 rws $
+.\" Copyright (c) 1993, 1994  X Consortium
+.\" 
+.\" Permission is hereby granted, free of charge, to any person obtaining
+.\" a copy of this software and associated documentation files (the
+.\" "Software"), to deal in the Software without restriction, including
+.\" without limitation the rights to use, copy, modify, merge, publish,
+.\" distribute, sublicense, and/or sell copies of the Software, and to
+.\" permit persons to whom the Software is furnished to do so, subject to
+.\" the following conditions:
+.\" 
+.\" The above copyright notice and this permission notice shall be included
+.\" in all copies or substantial portions of the Software.
+.\" 
+.\" THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+.\" OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+.\" MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+.\" IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR
+.\" OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+.\" ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+.\" OTHER DEALINGS IN THE SOFTWARE.
+.\" 
+.\" Except as contained in this notice, the name of the X Consortium shall
+.\" not be used in advertising or otherwise to promote the sale, use or
+.\" other dealings in this Software without prior written authorization
+.\" from the X Consortium.
+.TH IMAKE 1 "Release 6.1" "X Version 11"
+.SH NAME
+imake \- C preprocessor interface to the make utility
+.SH SYNOPSIS
+\fBimake\fP [ \fB\-D\fP\fIdefine\fP ] [ \fB\-I\fP\fIdir\fP ]
+[ \fB\-T\fP\fItemplate\fP ]
+[ \fB\-f\fP \fIfilename\fP ] [ \fB\-C\fP \fIfilename\fP ]
+[ \fB\-s\fP \fIfilename\fP ] [ \fB\-e\fP ]
+[ \fB\-v\fP ]
+.SH DESCRIPTION
+.I Imake
+is used to 
+generate \fIMakefiles\fP from a template, a set of \fIcpp\fP macro functions,
+and a per-directory input file called an \fIImakefile\fP.  This allows machine
+dependencies (such as compiler options, alternate command names, and special
+\fImake\fP rules) to be kept separate from the descriptions of the
+various items to be built.
+.SH OPTIONS
+The following command line options may be passed to \fIimake\fP:
+.TP 8
+.B \-D\fIdefine\fP
+This option is passed directly to \fIcpp\fP.  It is typically used to set
+directory-specific variables.  For example, the X Window System uses this
+flag to set \fITOPDIR\fP to the name of the directory containing the top
+of the core distribution and \fICURDIR\fP to the name of the current 
+directory, relative to the top.
+.TP 8
+.B \-I\fIdirectory\fP
+This option is passed directly to \fIcpp\fP.  It is typically used to 
+indicate the directory in which the \fIimake\fP template and configuration
+files may be found.
+.TP 8
+.B \-T\fItemplate\fP
+This option specifies the name of the master template file (which is usually
+located in the directory specified with \fI\-I\fP) used by \fIcpp\fP.
+The default is \fIImake.tmpl\fP.
+.TP 8
+.B \-f \fIfilename\fP
+This option specifies the name of the per-directory input file.  The default
+is \fIImakefile\fP.
+.TP 8
+.B \-C \fIfilename\fP
+This option specifies the name of the .c file that is constructed in the
+current directory.  The default is \fIImakefile.c\fP.
+.TP 8
+.B \-s \fIfilename\fP
+This option specifies the name of the \fImake\fP description file to be 
+generated but \fImake\fP should not be invoked.
+If the \fIfilename\fP is a dash (\-), the 
+output is written to \fIstdout\fP.  The default is to generate, but
+not execute, a \fIMakefile\fP.
+.TP 8
+.B \-e
+This option indicates the \fIimake\fP should execute the generated
+\fIMakefile\fP.  The default is to leave this to the user.
+.TP 8
+.B \-v
+This option indicates that \fIimake\fP should print the \fIcpp\fP command line 
+that it is using to generate the \fIMakefile\fP.
+.SH "HOW IT WORKS"
+\fIImake\fP invokes \fIcpp\fP with any \fI\-I\fP or \fI\-D\fP flags passed
+on the command line and passes the name of a file containing the
+following 3 lines:
+.sp
+.nf
+               #define IMAKE_TEMPLATE "Imake.tmpl"
+               #define INCLUDE_IMAKEFILE <Imakefile>
+               #include IMAKE_TEMPLATE
+.fi
+.sp
+where \fIImake.tmpl\fP and \fIImakefile\fP may be overridden by the 
+\fI\-T\fP and \fI\-f\fP command options, respectively.
+.PP
+The IMAKE_TEMPLATE typically
+reads in a file containing machine-dependent parameters 
+(specified as \fIcpp\fP symbols), a site-specific parameters file,
+a file defining variables,
+a file
+containing \fIcpp\fP macro functions for generating \fImake\fP rules, and
+finally the \fIImakefile\fP (specified by INCLUDE_IMAKEFILE) in the current 
+directory.  The \fIImakefile\fP uses the macro functions to indicate what
+targets should be built; \fIimake\fP takes care of generating the appropriate
+rules.
+.PP
+.I Imake
+configuration files contain two types of variables, imake variables
+and make variables.  The imake variables are interpreted by cpp when
+.I imake
+is run.  By convention they are mixed case.  The make variables are
+written into the
+.I Makefile
+for later interpretation by
+.I make.
+By convention make variables are upper case.
+.PP
+The rules file (usually named \fIImake.rules\fP in the configuration
+directory) contains a variety of \fIcpp\fP macro functions that are
+configured according to the current platform.  \fIImake\fP replaces 
+any occurrences of the string ``@@'' with a newline to allow macros that
+generate more than one line of \fImake\fP rules.  
+For example, the macro
+.ta 1i 1.6i 5i
+.nf
+
+#define        program_target(program, objlist)        @@\e
+program:       objlist         @@\e
+       $(CC)  \-o  $@  objlist  $(LDFLAGS)
+
+.fi
+when called with
+.I "program_target(foo, foo1.o  foo2.o)"
+will expand to
+.nf
+
+foo:   foo1.o  foo2.o
+       $(CC)  \-o  $@  foo1.o  foo2.o  $(LDFLAGS)
+
+.fi
+.PP
+\fIImake\fP also replaces any occurrences of the word ``XCOMM'' with
+the character ``#'' to permit placing comments in the Makefile without
+causing ``invalid directive'' errors from the preprocessor.
+.PP
+Some complex \fIimake\fP macros require generated \fImake\fP variables
+local to each invocation of the macro, often because their value
+depends on parameters passed to the macro.
+Such variables can be created by using an \fIimake\fP variable
+of the form \fBXVARdef\fP\fIn\fP, where \fIn\fP is a single digit.
+A unique \fImake\fP variable will be substituted.  Later occurrences
+of the variable \fBXVARuse\fP\fIn\fP will
+be replaced by the variable created by the corresponding
+\fBXVARdef\fP\fIn\fP.
+.PP
+On systems whose \fIcpp\fP reduces multiple tabs and spaces to a single
+space, \fIimake\fP attempts to put back any necessary tabs (\fImake\fP is
+very picky about the difference between tabs and spaces).  For this reason,
+colons (:) in command lines must be preceded by a backslash (\\).
+.SH "USE WITH THE X WINDOW SYSTEM"
+The X Window System uses \fIimake\fP extensively, for both full builds within
+the source tree and external software.  As mentioned above, two special
+variables, \fITOPDIR\fP and \fICURDIR,\fP are set to make referencing files
+using relative path names easier.  For example, the following command is
+generated automatically to build the \fIMakefile\fP in the directory
+\fIlib/X/\fP (relative to the top of the sources):
+.sp
+.nf
+       %  ../.././config/imake  \-I../.././config  \\
+               \-DTOPDIR=../../.   \-DCURDIR=./lib/X
+.fi
+.sp
+When building X programs outside the source tree, a special symbol
+\fIUseInstalled\fP is defined and \fITOPDIR\fP and
+\fICURDIR\fP are omitted.  If the configuration files have been
+properly installed, the script \fIxmkmf\fP(1) may be used.
+.SH "INPUT FILES"
+Here is a summary of the files read by
+.I imake
+as used by X.
+The indentation shows what files include what other files.
+.nf
+.sp
+.ta 3i
+    Imake.tmpl generic variables
+        site.def       site-specific, BeforeVendorCF defined
+        *.cf   machine-specific
+            *Lib.rules shared library rules
+        site.def       site-specific, AfterVendorCF defined
+        Imake.rules    rules
+        Project.tmpl   X-specific variables
+            *Lib.tmpl  shared library variables
+        Imakefile
+            Library.tmpl       library rules
+            Server.tmpl        server rules
+            Threads.tmpl       multi-threaded rules
+.fi
+.LP
+Note that \fIsite.def\fP gets included twice, once before the
+\fI*.cf\fP file and once after.  Although most site customizations
+should be specified after the \fI*.cf\fP file, some, such as the
+choice of compiler, need to be specified before, because other
+variable settings may depend on them.
+.LP
+The first time \fIsite.def\fP is included, the variable BeforeVendorCF
+is defined, and the second time, the variable AfterVendorCF is
+defined.  All code in \fIsite.def\fP should be inside an #ifdef for
+one of these symbols.
+.SH FILES
+.ta 3i
+Imakefile.c    temporary input file for cpp
+.br
+/tmp/Imf.XXXXXX        temporary Makefile for -s
+.br
+/tmp/IIf.XXXXXX        temporary Imakefile if specified Imakefile uses # comments
+.br
+/lib/cpp       default C preprocessor
+.DT
+.SH "SEE ALSO"
+make(1), xmkmf(1)
+.br
+S. I. Feldman,
+.I
+Make \(em A Program for Maintaining Computer Programs
+.SH "ENVIRONMENT VARIABLES"
+The following environment variables may be set, however their use is not
+recommended as they introduce dependencies that are not readily apparent
+when \fIimake\fP is run:
+.TP 5
+.B IMAKEINCLUDE
+If defined, this specifies a ``\-I'' include argument to pass to the
+C preprocessor.  E.g., ``\-I/usr/X11/config''.
+.TP 5
+.B IMAKECPP
+If defined, this should be a valid path to a preprocessor program.
+E.g., ``/usr/local/cpp''.
+By default,
+.I imake
+will use /lib/cpp.
+.TP 5
+.B IMAKEMAKE
+If defined, this should be a valid path to a make program,
+such as ``/usr/local/make''.
+By default,
+.I imake
+will use whatever
+.I make
+program is found using
+.I execvp(3).
+This variable is only used if the ``\-e'' option is specified.
+.SH "AUTHOR"
+Todd Brunhoff, Tektronix and MIT Project Athena; Jim Fulton, MIT X Consortium
diff --git a/Xserver/config/imake/imakemdep.h b/Xserver/config/imake/imakemdep.h
new file mode 100644 (file)
index 0000000..d81ccb3
--- /dev/null
@@ -0,0 +1,916 @@
+/* $TOG: imakemdep.h /main/101 1997/06/06 09:13:20 bill $ */
+/*
+
+Copyright (c) 1993, 1994  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+*/
+/* $XFree86: xc/config/imake/imakemdep.h,v 3.24.2.3 1997/07/27 02:41:05 dawes Exp $ */
+
+
+/* 
+ * This file contains machine-dependent constants for the imake utility.
+ * When porting imake, read each of the steps below and add in any necessary
+ * definitions.  In general you should *not* edit ccimake.c or imake.c!
+ */
+
+#ifdef CCIMAKE
+/*
+ * Step 1:  imake_ccflags
+ *     Define any special flags that will be needed to get imake.c to compile.
+ *     These will be passed to the compile along with the contents of the
+ *     make variable BOOTSTRAPCFLAGS.
+ */
+#if defined(clipper) || defined(__clipper__)
+#define imake_ccflags "-O -DSYSV -DBOOTSTRAPCFLAGS=-DSYSV"
+#endif
+
+#ifdef hpux
+#ifdef hp9000s800
+#define imake_ccflags "-DSYSV"
+#else
+#define imake_ccflags "-Wc,-Nd4000,-Ns3000 -DSYSV"
+#endif
+#endif
+
+#if defined(macII) || defined(_AUX_SOURCE)
+#define imake_ccflags "-DmacII -DSYSV"
+#endif
+
+#ifdef stellar
+#define imake_ccflags "-DSYSV"
+#endif
+
+#if defined(USL) || defined(__USLC__) || defined(Oki) || defined(NCR)
+#define imake_ccflags "-Xa -DSVR4"
+#endif
+
+/* SCO may define __USLC__ so put this after the USL check */
+#if defined(M_UNIX) || defined(_SCO_DS)
+#ifdef imake_ccflags
+#undef imake_ccflags
+#endif
+#define imake_ccflags "-Dsco -DSYSV"
+#endif
+
+#ifdef sony
+#if defined(SYSTYPE_SYSV) || defined(_SYSTYPE_SYSV)
+#define imake_ccflags "-DSVR4"
+#else
+#include <sys/param.h>
+#if NEWSOS < 41
+#define imake_ccflags "-Dbsd43 -DNOSTDHDRS"
+#else
+#if NEWSOS < 42
+#define imake_ccflags "-Dbsd43"
+#endif
+#endif
+#endif
+#endif
+
+#ifdef _CRAY
+#define imake_ccflags "-DSYSV -DUSG"
+#endif
+
+#if defined(_IBMR2) || defined(aix)
+#define imake_ccflags "-Daix -DSYSV"
+#endif
+
+#ifdef Mips
+#  if defined(SYSTYPE_BSD) || defined(BSD) || defined(BSD43)
+#    define imake_ccflags "-DBSD43"
+#  else 
+#    define imake_ccflags "-DSYSV"
+#  endif
+#endif 
+
+#ifdef is68k
+#define imake_ccflags "-Dluna -Duniosb"
+#endif
+
+#ifdef SYSV386
+# ifdef SVR4
+#  define imake_ccflags "-Xa -DSVR4"
+# else
+#  define imake_ccflags "-DSYSV"
+# endif
+#endif
+
+#ifdef SVR4
+# ifdef i386
+#  define imake_ccflags "-Xa -DSVR4"
+# endif
+#endif
+
+#ifdef SYSV
+# ifdef i386
+#  define imake_ccflags "-DSYSV"
+# endif
+#endif
+
+#ifdef __convex__
+#define imake_ccflags "-fn -tm c1"
+#endif
+
+#ifdef apollo
+#define imake_ccflags "-DX_NOT_POSIX"
+#endif
+
+#ifdef WIN32
+#if _MSC_VER < 1000
+#define imake_ccflags "-nologo -batch -D__STDC__"
+#else
+#define imake_ccflags "-nologo -D__STDC__"
+#endif
+#endif
+
+#ifdef __uxp__
+#define imake_ccflags "-DSVR4 -DANSICPP"
+#endif
+
+#ifdef __sxg__
+#define imake_ccflags "-DSYSV -DUSG -DNOSTDHDRS"
+#endif
+
+#ifdef sequent
+#define imake_ccflags "-DX_NOT_STDC_ENV -DX_NOT_POSIX"
+#endif
+
+#ifdef _SEQUENT_
+#define imake_ccflags "-DSYSV -DUSG"
+#endif
+
+#if defined(SX) || defined(PC_UX)
+#define imake_ccflags "-DSYSV"
+#endif
+
+#ifdef nec_ews_svr2
+#define imake_ccflags "-DUSG"
+#endif
+
+#if defined(nec_ews_svr4) || defined(_nec_ews_svr4) || defined(_nec_up) || defined(_nec_ft)
+#define imake_ccflags "-DSVR4"
+#endif
+
+#ifdef  MACH
+#define imake_ccflags "-DNOSTDHDRS"
+#endif
+
+/* this is for OS/2 under EMX. This won't work with DOS */
+#if defined(__EMX__)
+#define imake_ccflags "-DBSD43"
+#endif
+
+#else /* not CCIMAKE */
+#ifndef MAKEDEPEND
+/*
+ * Step 2:  dup2
+ *     If your OS doesn't have a dup2() system call to duplicate one file
+ *     descriptor onto another, define such a mechanism here (if you don't
+ *     already fall under the existing category(ies).
+ */
+#if defined(SYSV) && !defined(_CRAY) && !defined(Mips) && !defined(_SEQUENT_) && !defined(sco)
+#define        dup2(fd1,fd2)   ((fd1 == fd2) ? fd1 : (close(fd2), \
+                                              fcntl(fd1, F_DUPFD, fd2)))
+#endif
+
+
+/*
+ * Step 3:  FIXUP_CPP_WHITESPACE
+ *     If your cpp collapses tabs macro expansions into a single space and
+ *     replaces escaped newlines with a space, define this symbol.  This will
+ *     cause imake to attempt to patch up the generated Makefile by looking
+ *     for lines that have colons in them (this is why the rules file escapes
+ *     all colons).  One way to tell if you need this is to see whether or not
+ *     your Makefiles have no tabs in them and lots of @@ strings.
+ */
+#if defined(sun) || defined(SYSV) || defined(SVR4) || defined(hcx) || defined(WIN32) || defined(sco) || (defined(AMOEBA) && defined(CROSS_COMPILE))
+#define FIXUP_CPP_WHITESPACE
+#endif
+#ifdef WIN32
+#define REMOVE_CPP_LEADSPACE
+#define INLINE_SYNTAX
+#define MAGIC_MAKE_VARS
+#endif
+#ifdef __minix_vmd
+#define FIXUP_CPP_WHITESPACE
+#endif
+
+/*
+ * Step 4:  USE_CC_E, DEFAULT_CC, DEFAULT_CPP
+ *     If you want to use cc -E instead of cpp, define USE_CC_E.
+ *     If use cc -E but want a different compiler, define DEFAULT_CC.
+ *     If the cpp you need is not in /lib/cpp, define DEFAULT_CPP.
+ */
+#ifdef hpux
+#define USE_CC_E
+#endif
+#ifdef WIN32
+#define USE_CC_E
+#define DEFAULT_CC "cl"
+#endif
+#ifdef apollo
+#define DEFAULT_CPP "/usr/lib/cpp"
+#endif
+#if defined(clipper) || defined(__clipper__)
+#define DEFAULT_CPP "/usr/lib/cpp"
+#endif
+#if defined(_IBMR2) && !defined(DEFAULT_CPP)
+#define DEFAULT_CPP "/usr/ccs/lib/cpp"
+#endif
+#if defined(sun) && (defined(SVR4) || defined(__svr4__) || defined(__SVR4) || defined(__sol__))
+#define DEFAULT_CPP "/usr/ccs/lib/cpp"
+#endif
+#ifdef __bsdi__
+#define DEFAULT_CPP "/usr/bin/cpp"
+#endif
+#ifdef __uxp__
+#define DEFAULT_CPP "/usr/ccs/lib/cpp"
+#endif
+#ifdef __sxg__
+#define DEFAULT_CPP "/usr/lib/cpp"
+#endif
+#ifdef _CRAY
+#define DEFAULT_CPP "/lib/pcpp"
+#endif
+#if defined(__386BSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__FreeBSD__)
+#define DEFAULT_CPP "/usr/libexec/cpp"
+#endif
+#if defined(__sgi) && defined(__ANSI_CPP__)
+#define USE_CC_E
+#endif
+#ifdef  MACH
+#define USE_CC_E
+#endif
+#ifdef __minix_vmd
+#define DEFAULT_CPP "/usr/lib/cpp"
+#endif
+#if defined(__EMX__)
+/* expects cpp in PATH */
+#define DEFAULT_CPP "cpp"
+#endif
+
+/*
+ * Step 5:  cpp_argv
+ *     The following table contains the flags that should be passed
+ *     whenever a Makefile is being generated.  If your preprocessor 
+ *     doesn't predefine any unique symbols, choose one and add it to the
+ *     end of this table.  Then, do the following:
+ * 
+ *         a.  Use this symbol in Imake.tmpl when setting MacroFile.
+ *         b.  Put this symbol in the definition of BootstrapCFlags in your
+ *             <platform>.cf file.
+ *         c.  When doing a make World, always add "BOOTSTRAPCFLAGS=-Dsymbol" 
+ *             to the end of the command line.
+ * 
+ *     Note that you may define more than one symbol (useful for platforms 
+ *     that support multiple operating systems).
+ */
+
+#define        ARGUMENTS 50    /* number of arguments in various arrays */
+char *cpp_argv[ARGUMENTS] = {
+       "cc",           /* replaced by the actual program to exec */
+       "-I.",          /* add current directory to include path */
+#ifdef unix
+       "-Uunix",       /* remove unix symbol so that filename unix.c okay */
+#endif
+#if defined(__386BSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__FreeBSD__) || defined(MACH)
+# ifdef __i386__
+       "-D__i386__",
+# endif
+# ifdef __GNUC__
+       "-traditional",
+# endif
+#endif
+#ifdef M4330
+       "-DM4330",      /* Tektronix */
+#endif
+#ifdef M4310
+       "-DM4310",      /* Tektronix */
+#endif
+#if defined(macII) || defined(_AUX_SOURCE)
+       "-DmacII",      /* Apple A/UX */
+#endif
+#if defined(USL) || defined(__USLC__)
+       "-DUSL",        /* USL */
+#endif
+#ifdef sony
+       "-Dsony",       /* Sony */
+#if !defined(SYSTYPE_SYSV) && !defined(_SYSTYPE_SYSV) && NEWSOS < 42
+       "-Dbsd43",
+#endif
+#endif
+#ifdef _IBMR2
+       "-D_IBMR2",     /* IBM RS-6000 (we ensured that aix is defined above */
+#ifndef aix
+#define aix            /* allow BOOTSTRAPCFLAGS="-D_IBMR2" */
+#endif
+#endif /* _IBMR2 */
+#ifdef aix
+       "-Daix",        /* AIX instead of AOS */
+#ifndef ibm
+#define ibm            /* allow BOOTSTRAPCFLAGS="-Daix" */
+#endif
+#endif /* aix */
+#ifdef ibm
+       "-Dibm",        /* IBM PS/2 and RT under both AOS and AIX */
+#endif
+#ifdef luna
+       "-Dluna",       /* OMRON luna 68K and 88K */
+#ifdef luna1
+       "-Dluna1",
+#endif
+#ifdef luna88k         /* need not on UniOS-Mach Vers. 1.13 */
+       "-traditional", /* for some older version            */
+#endif                 /* instead of "-DXCOMM=\\#"          */
+#ifdef uniosb
+       "-Duniosb",
+#endif
+#ifdef uniosu
+       "-Duniosu",
+#endif
+#endif /* luna */
+#ifdef _CRAY           /* Cray */
+       "-Ucray",
+#endif
+#ifdef Mips
+       "-DMips",       /* Define and use Mips for Mips Co. OS/mach. */
+# if defined(SYSTYPE_BSD) || defined(BSD) || defined(BSD43)
+       "-DBSD43",      /* Mips RISCOS supports two environments */
+# else
+       "-DSYSV",       /* System V environment is the default */
+# endif
+#endif /* Mips */
+#ifdef MOTOROLA
+       "-DMOTOROLA",    /* Motorola Delta Systems */
+# ifdef SYSV
+       "-DSYSV", 
+# endif
+# ifdef SVR4
+       "-DSVR4",
+# endif
+#endif /* MOTOROLA */
+#if defined(M_UNIX) || defined(sco)
+       "-Dsco",
+       "-DSYSV",
+#endif
+#ifdef i386
+       "-Di386",
+# ifdef SVR4
+       "-DSVR4",
+# endif
+# ifdef SYSV
+       "-DSYSV",
+#  ifdef ISC
+       "-DISC",
+#   ifdef ISC40
+       "-DISC40",       /* ISC 4.0 */
+#   else
+#    ifdef ISC202
+       "-DISC202",      /* ISC 2.0.2 */
+#    else
+#     ifdef ISC30
+       "-DISC30",       /* ISC 3.0 */
+#     else
+       "-DISC22",       /* ISC 2.2.1 */
+#     endif
+#    endif
+#   endif
+#  endif
+#  ifdef SCO
+       "-DSCO",
+#   ifdef _SCO_DS
+    "-DSCO325 -DSVR4",
+#   endif
+#  endif
+# endif
+# ifdef ESIX
+       "-DESIX",
+# endif
+# ifdef ATT
+       "-DATT",
+# endif
+# ifdef DELL
+       "-DDELL",
+# endif
+#endif
+#ifdef SYSV386           /* System V/386 folks, obsolete */
+       "-Di386",
+# ifdef SVR4
+       "-DSVR4",
+# endif
+# ifdef ISC
+       "-DISC",
+#  ifdef ISC40
+       "-DISC40",       /* ISC 4.0 */
+#  else
+#   ifdef ISC202
+       "-DISC202",      /* ISC 2.0.2 */
+#   else
+#    ifdef ISC30
+       "-DISC30",       /* ISC 3.0 */
+#    else
+       "-DISC22",       /* ISC 2.2.1 */
+#    endif
+#   endif
+#  endif
+# endif
+# ifdef SCO
+       "-DSCO",
+#  ifdef _SCO_DS
+       "-DSCO325 -DSVR4",
+#  endif
+# endif
+# ifdef ESIX
+       "-DESIX",
+# endif
+# ifdef ATT
+       "-DATT",
+# endif
+# ifdef DELL
+       "-DDELL",
+# endif
+#endif
+#ifdef __osf__
+       "-D__osf__",
+# ifdef __mips__
+       "-D__mips__",
+# endif
+# ifdef __alpha
+       "-D__alpha",
+# endif
+# ifdef __alpha__
+       "-D__alpha__",
+# endif
+# ifdef __i386__
+       "-D__i386__",
+# endif
+# ifdef __s390__
+       "-D__s390__",
+# endif
+# ifdef __GNUC__
+       "-traditional",
+# endif
+#endif
+#ifdef Oki
+       "-DOki",
+#endif
+#ifdef sun
+#if defined(SVR4) || defined(__svr4__) || defined(__SVR4) || defined(__sol__)
+       "-DSVR4",
+#endif
+#endif
+#ifdef WIN32
+       "-DWIN32",
+       "-nologo",
+#if _MSC_VER < 1000
+       "-batch",
+#endif
+       "-D__STDC__",
+#endif
+#ifdef NCR
+       "-DNCR",        /* NCR */
+#endif
+#ifdef linux
+        "-traditional",
+        "-Dlinux",
+#endif
+#ifdef __uxp__
+       "-D__uxp__",
+#endif
+#ifdef __sxg__
+       "-D__sxg__",
+#endif
+#ifdef nec_ews_svr2
+       "-Dnec_ews_svr2",
+#endif
+#ifdef AMOEBA
+       "-DAMOEBA",
+# ifdef CROSS_COMPILE
+       "-DCROSS_COMPILE",
+#  ifdef CROSS_i80386
+       "-Di80386",
+#  endif
+#  ifdef CROSS_sparc
+       "-Dsparc",
+#  endif
+#  ifdef CROSS_mc68000
+       "-Dmc68000",
+#  endif
+# else
+#  ifdef i80386
+       "-Di80386",
+#  endif
+#  ifdef sparc
+       "-Dsparc",
+#  endif
+#  ifdef mc68000
+       "-Dmc68000",
+#  endif
+# endif
+#endif
+#if defined(__sgi) && defined(__ANSI_CPP__)
+       "-cckr",
+#endif
+#ifdef __minix_vmd
+       "-Dminix",
+#endif
+
+#if defined(__EMX__)
+       "-traditional",
+       "-Demxos2",
+#endif
+
+};
+
+
+/*
+ * Step 6: DEFAULT_OS_MAJOR_REV, DEFAULT_OS_MINOR_REV, DEFAULT_OS_TEENY_REV,
+ *     and DEFAULT_OS_NAME.
+ *     If your systems provides a way to generate the default major,
+ *     minor, teeny, or system names at runtime add commands below.
+ *     The syntax of the _REV strings is 'f fmt' where 'f' is an argument
+ *     you would give to uname, and "fmt" is a scanf() format string.
+ *     Supported uname arguments are "snrvm", and if you specify multiple
+ *     arguments they will be separated by spaces.  No more than 5 arguments
+ *     may be given.  Unlike uname() order of arguments matters.
+ *
+ *     DEFAULT_OS_MAJOR_REV_FROB, DEFAULT_OS_MINOR_REV_FROB,
+ *     DEFAULT_OS_TEENY_REV_FROB, and DEFAULT_OS_NAME_FROB can be used to
+ *     modify the results of the use of the various strings.
+ */
+#if defined(aix)
+/* uname -v returns "x" (e.g. "4"), and uname -r returns "y" (e.g. "1") */
+# define DEFAULT_OS_MAJOR_REV  "v %[0-9]"
+# define DEFAULT_OS_MINOR_REV  "r %[0-9]"
+/* No information available to generate default OSTeenyVersion value. */
+# define DEFAULT_OS_NAME       "srvm %[^\n]"
+#elif defined(sun) || defined(sgi) || defined(ultrix) || defined(__uxp__) || defined(sony)
+/* uname -r returns "x.y[.z]", e.g. "5.4" or "4.1.3" */
+# define DEFAULT_OS_MAJOR_REV  "r %[0-9]"
+# define DEFAULT_OS_MINOR_REV  "r %*d.%[0-9]"
+# define DEFAULT_OS_TEENY_REV  "r %*d.%*d.%[0-9]"
+# define DEFAULT_OS_NAME       "srvm %[^\n]"
+#elif defined(hpux)
+/* uname -r returns "W.x.yz", e.g. "B.10.01" */
+# define DEFAULT_OS_MAJOR_REV  "r %*[^.].%[0-9]"
+# define DEFAULT_OS_MINOR_REV  "r %*[^.].%*d.%1s"
+# define DEFAULT_OS_TEENY_REV  "r %*[^.].%*d.%*c%[0-9]"
+# define DEFAULT_OS_NAME       "srvm %[^\n]"
+#elif defined(USL) || defined(__USLC__)
+/* uname -v returns "x.yz" or "x.y.z", e.g. "2.02" or "2.1.2". */
+# define DEFAULT_OS_MAJOR_REV  "v %[0-9]"
+# define DEFAULT_OS_MINOR_REV  "v %*d.%1s"
+# define DEFAULT_OS_TEENY_REV  "v %*d.%*c%[.0-9]"
+# define DEFAULT_OS_NAME       "srvm %[^\n]"
+#elif defined(__osf__)
+/* uname -r returns "Wx.y", e.g. "V3.2" or "T4.0" */
+# define DEFAULT_OS_MAJOR_REV  "r %*[^0-9]%[0-9]"
+# define DEFAULT_OS_MINOR_REV  "r %*[^.].%[0-9]"
+# define DEFAULT_OS_NAME       "srvm %[^\n]"
+#elif defined(__uxp__)
+/* NOTE: "x.y[.z]" above handles UXP/DF.  This is a sample alternative. */
+/* uname -v returns "VxLy Yzzzzz ....", e.g. "V20L10 Y95021 Increment 5 ..." */
+# define DEFAULT_OS_MAJOR_REV  "v V%[0-9]"
+# define DEFAULT_OS_MINOR_REV  "v V%*dL%[0-9]"
+# define DEFAULT_OS_NAME       "srvm %[^\n]"
+#elif defined(linux)
+# define DEFAULT_OS_MAJOR_REV  "r %[0-9]"
+# define DEFAULT_OS_MINOR_REV  "r %*d.%[0-9]"
+# define DEFAULT_OS_TEENY_REV  "r %*d.%*d.%[0-9]"
+# define DEFAULT_OS_NAME       "srm %[^\n]"
+#elif defined(ISC)
+/* ISC all Versions ? */
+/* uname -r returns "x.y", e.g. "3.2" ,uname -v returns "x" e.g. "2" */
+# define DEFAULT_OS_MAJOR_REV   "r %[0-9]"
+# define DEFAULT_OS_MINOR_REV   "r %*d.%[0-9]"
+# define DEFAULT_OS_TEENY_REV   "v %[0-9]" 
+/* # define DEFAULT_OS_NAME        "srm %[^\n]" */ /* Not useful on ISC */
+#elif defined(__FreeBSD__) || defined(__OpenBSD__)
+/* BSD/OS too? */
+/* uname -r returns "x.y[.z]-mumble", e.g. "2.1.5-RELEASE" or "2.2-0801SNAP" */
+# define DEFAULT_OS_MAJOR_REV   "r %[0-9]"
+# define DEFAULT_OS_MINOR_REV   "r %*d.%[0-9]"
+# define DEFAULT_OS_TEENY_REV   "r %*d.%*d.%[0-9]" 
+# define DEFAULT_OS_NAME        "srm %[^\n]"
+# if defined(__FreeBSD__)
+/* Use an alternate way to find the teeny version for -STABLE, -SNAP versions */
+#  define DEFAULT_OS_TEENY_REV_FROB(buf, size)                         \
+    do {                                                               \
+       if (*buf == 0) {                                                \
+               int __mib[2];                                           \
+               size_t __len;                                           \
+               int __osrel;                                            \
+                                                                       \
+               __mib[0] = CTL_KERN;                                    \
+               __mib[1] = KERN_OSRELDATE;                              \
+               __len = sizeof(__osrel);                                \
+               sysctl(__mib, 2, &__osrel, &__len, NULL, 0);            \
+               if (__osrel < 210000) {                                 \
+                       if (__osrel < 199607)                           \
+                               buf[0] = '0';                           \
+                       else if (__osrel < 199612)                      \
+                               buf[0] = '5';                           \
+                       else if (__osrel == 199612)                     \
+                               buf[0] = '6';                           \
+                       else                                            \
+                               buf[0] = '8'; /* guess */               \
+               } else {                                                \
+                       buf[0] = ((__osrel / 1000) % 10) + '0';         \
+               }                                                       \
+               buf[1] = 0;                                             \
+       }                                                               \
+    } while (0)
+# else
+   /* OpenBSD - Add DEFAULT_MACHINE_ARCHITECTURE */
+#  define DEFAULT_MACHINE_ARCHITECTURE "m %[^\n]"
+# endif
+#elif defined(__NetBSD__)
+/*
+ * uname -r returns "x.y([ABCD...]|_mumble)", e.g.:
+ *     1.2     1.2_BETA        1.2A    1.2B
+ *
+ * That means that we have to do something special to turn the
+ * TEENY revision into a form that we can use (i.e., a string of
+ * decimal digits).
+ *
+ * We also frob the name DEFAULT_OS_NAME so that it looks like the
+ * 'standard' NetBSD name for the version, e.g. "NetBSD/i386 1.2B" for
+ * NetBSD 1.2B on an i386.
+ */
+# define DEFAULT_OS_MAJOR_REV   "r %[0-9]"
+# define DEFAULT_OS_MINOR_REV   "r %*d.%[0-9]"
+# define DEFAULT_OS_TEENY_REV   "r %*d.%*d%[A-Z]" 
+# define DEFAULT_OS_TEENY_REV_FROB(buf, size)                          \
+    do {                                                               \
+       if (*(buf) >= 'A' && *(buf) <= 'Z') /* sanity check */          \
+               snprintf((buf), (size), "%d", *(buf) - 'A' + 1);        \
+       else                                                            \
+           *(buf) = '\0';                                              \
+    } while (0)
+# define DEFAULT_OS_NAME        "smr %[^\n]"
+# define DEFAULT_OS_NAME_FROB(buf, size)                               \
+    do {                                                               \
+       char *__sp;                                                     \
+       if ((__sp = strchr((buf), ' ')) != NULL)                        \
+               *__sp = '/';                                            \
+    } while (0)
+#endif
+
+#else /* else MAKEDEPEND */
+/*
+ * Step 7:  predefs
+ *     If your compiler and/or preprocessor define any specific symbols, add
+ *     them to the the following table.  The definition of struct symtab is
+ *     in util/makedepend/def.h.
+ */
+struct symtab  predefs[] = {
+#ifdef apollo
+       {"apollo", "1"},
+#endif
+#if defined(clipper) || defined(__clipper__)
+       {"clipper", "1"},
+       {"__clipper__", "1"},
+       {"clix", "1"},
+       {"__clix__", "1"},
+#endif
+#ifdef ibm032
+       {"ibm032", "1"},
+#endif
+#ifdef ibm
+       {"ibm", "1"},
+#endif
+#ifdef aix
+       {"aix", "1"},
+#endif
+#ifdef sun
+       {"sun", "1"},
+#endif
+#ifdef sun2
+       {"sun2", "1"},
+#endif
+#ifdef sun3
+       {"sun3", "1"},
+#endif
+#ifdef sun4
+       {"sun4", "1"},
+#endif
+#ifdef sparc
+       {"sparc", "1"},
+#endif
+#ifdef __sparc__
+       {"__sparc__", "1"},
+#endif
+#ifdef hpux
+       {"hpux", "1"},
+#endif
+#ifdef __hpux
+       {"__hpux", "1"},
+#endif
+#ifdef __hp9000s800
+       {"__hp9000s800", "1"},
+#endif
+#ifdef __hp9000s700
+       {"__hp9000s700", "1"},
+#endif
+#ifdef vax
+       {"vax", "1"},
+#endif
+#ifdef VMS
+       {"VMS", "1"},
+#endif
+#ifdef cray
+       {"cray", "1"},
+#endif
+#ifdef CRAY
+       {"CRAY", "1"},
+#endif
+#ifdef _CRAY
+       {"_CRAY", "1"},
+#endif
+#ifdef att
+       {"att", "1"},
+#endif
+#ifdef mips
+       {"mips", "1"},
+#endif
+#ifdef __mips__
+       {"__mips__", "1"},
+#endif
+#ifdef ultrix
+       {"ultrix", "1"},
+#endif
+#ifdef stellar
+       {"stellar", "1"},
+#endif
+#ifdef mc68000
+       {"mc68000", "1"},
+#endif
+#ifdef mc68020
+       {"mc68020", "1"},
+#endif
+#ifdef __GNUC__
+       {"__GNUC__", "1"},
+#endif
+#if __STDC__
+       {"__STDC__", "1"},
+#endif
+#ifdef __HIGHC__
+       {"__HIGHC__", "1"},
+#endif
+#ifdef CMU
+       {"CMU", "1"},
+#endif
+#ifdef luna
+       {"luna", "1"},
+#ifdef luna1
+       {"luna1", "1"},
+#endif
+#ifdef luna2
+       {"luna2", "1"},
+#endif
+#ifdef luna88k
+       {"luna88k", "1"},
+#endif
+#ifdef uniosb
+       {"uniosb", "1"},
+#endif
+#ifdef uniosu
+       {"uniosu", "1"},
+#endif
+#endif
+#ifdef ieeep754
+       {"ieeep754", "1"},
+#endif
+#ifdef is68k
+       {"is68k", "1"},
+#endif
+#ifdef m68k
+        {"m68k", "1"},
+#endif
+#ifdef m88k
+        {"m88k", "1"},
+#endif
+#ifdef __m88k__
+       {"__m88k__", "1"},
+#endif
+#ifdef bsd43
+       {"bsd43", "1"},
+#endif
+#ifdef hcx
+       {"hcx", "1"},
+#endif
+#ifdef sony
+       {"sony", "1"},
+#ifdef SYSTYPE_SYSV
+       {"SYSTYPE_SYSV", "1"},
+#endif
+#ifdef _SYSTYPE_SYSV
+       {"_SYSTYPE_SYSV", "1"},
+#endif
+#endif
+#ifdef __OSF__
+       {"__OSF__", "1"},
+#endif
+#ifdef __osf__
+       {"__osf__", "1"},
+#endif
+#ifdef __alpha
+       {"__alpha", "1"},
+#endif
+#ifdef __alpha__
+       {"__alpha__", "1"},
+#endif
+#ifdef __DECC
+       {"__DECC",  "1"},
+#endif
+#ifdef __decc
+       {"__decc",  "1"},
+#endif
+#ifdef __unix__
+       {"__unix__", "1"},
+#endif
+#ifdef __uxp__
+       {"__uxp__", "1"},
+#endif
+#ifdef __sxg__
+       {"__sxg__", "1"},
+#endif
+#ifdef _SEQUENT_
+       {"_SEQUENT_", "1"},
+       {"__STDC__", "1"},
+#endif
+#ifdef __bsdi__
+       {"__bsdi__", "1"},
+#endif
+#ifdef nec_ews_svr2
+       {"nec_ews_svr2", "1"},
+#endif
+#ifdef nec_ews_svr4
+       {"nec_ews_svr4", "1"},
+#endif
+#ifdef _nec_ews_svr4
+       {"_nec_ews_svr4", "1"},
+#endif
+#ifdef _nec_up
+       {"_nec_up", "1"},
+#endif
+#ifdef SX
+       {"SX", "1"},
+#endif
+#ifdef nec
+       {"nec", "1"},
+#endif
+#ifdef _nec_ft
+       {"_nec_ft", "1"},
+#endif
+#ifdef PC_UX
+       {"PC_UX", "1"},
+#endif
+#ifdef sgi
+       {"sgi", "1"},
+#endif
+#ifdef __sgi
+       {"__sgi", "1"},
+#endif
+#ifdef __FreeBSD__
+       {"__FreeBSD__", "1"},
+#endif
+#ifdef __OpenBSD__
+       {"__OpenBSD__", "1"},
+#endif
+#ifdef __NetBSD__
+       {"__NetBSD__", "1"},
+#endif
+#ifdef __ELF__
+       {"__ELF__", "1"},
+#endif
+#ifdef __EMX__
+       {"__EMX__", "1"},
+#endif
+       /* add any additional symbols before this line */
+       {NULL, NULL}
+};
+
+#endif /* MAKEDEPEND */
+#endif /* CCIMAKE */
diff --git a/Xserver/config/imake/imakesvc.cmd b/Xserver/config/imake/imakesvc.cmd
new file mode 100644 (file)
index 0000000..4e310d6
--- /dev/null
@@ -0,0 +1,273 @@
+/* Rexx OS/2
+ * This script serves as a helper cmd file for imake. Install this in
+ * the path just like imake itself.
+ *
+ * $XFree86: xc/config/imake/imakesvc.cmd,v 3.10.2.1 1997/07/19 04:59:10 dawes Exp $
+ */
+'@echo off'
+ADDRESS CMD
+CALL RxFuncAdd 'SysFileDelete', 'RexxUtil', 'SysFileDelete'
+CALL RxFuncAdd 'SysFileTree', 'RexxUtil', 'SysFileTree'
+CALL RxFuncAdd 'SysRmDir', 'RexxUtil', 'SysRmDir'
+CALL RxFuncAdd 'SysMkDir', 'RexxUtil', 'SysMkDir'
+
+PARSE ARG all
+code = WORD(all,1)
+
+SELECT
+   WHEN code=1 THEN DO
+      /* imakesvc 1 u/n dir ruledir top current */
+      instflg = WORD(all,2)
+      imakecmd = '\imake'
+      ruledir = WORD(all,4)
+      topdir = WORD(all,5)
+      currentdir = WORD(all,6)
+      IF instflg = 'u' THEN DO 
+         root = VALUE('X11ROOT',,'OS2ENVIRONMENT')
+         IF root = '' THEN DO
+            SAY 'Fatal error: no X11ROOT environment variable found!'
+            EXIT 99
+         END
+         imakecmd = 'imake'
+        IF POS(':',ruledir) = 0 THEN
+            ruledir1 = root||ruledir
+        ELSE
+           ruledir1 = ruledir
+         topdir1 = topdir
+         useinst = '-DUseInstalled'
+      END 
+      ELSE DO
+         /* in n mode, we must add a prefix ../ for MakeMakeSubdirs */
+         ruledir1 = '../'||ruledir
+         topdir1 = '../'||topdir
+         useinst = ''
+      END
+
+      ruledir = ruledir1
+      topdir = topdir1
+      curdir = DIRECTORY()
+      dir = fixbadprefix(WORD(all,3))
+      d = DIRECTORY(dir)
+      dirfwd=TRANSLATE(dir,'/','\')
+      RC = SysFileDelete('Makefile.bak')
+      IF exists('Makefile') THEN REN Makefile Makefile.bak
+      /* There is a difficulty in the Imakefiles. Some builds refer
+       * to directories that are in a different subtree. We need to adjust
+       * the CURDIR and TOPDIR and -I paths
+       */
+      IF SUBSTR(dirfwd,1,2)='..' THEN DO
+         /* must recalculate passed topdir, currentdir, and ruledir */
+         ndist = nlevels(topdir)
+         ncurdir = './'striplevel(dirfwd,ndist-1)
+         ntopdir = maketop(nlevels(ncurdir))
+         nruledir = ntopdir||'/config/cf'
+      END 
+      ELSE DO
+         /* this is simple it is relative to this dir */
+         pfx = downlevels(dirfwd)
+         nruledir = ruledir
+         IF instflg = 'n' THEN DO /*sm120296*/
+            nruledir = pfx||ruledir
+         END
+         ntopdir = pfx||topdir
+         ncurdir = currentdir  /* use to be pfx || currentdir */
+      END
+      imakecmd useinst '-I'nruledir' -DTOPDIR='ntopdir' -DCURDIR='ncurdir'/'dirfwd
+      'x11make MAKE=x11make SHELL= Makefiles'
+      d = DIRECTORY(curdir)
+   END
+   WHEN code=2 THEN DO
+      /* imakesvc 2 buildincdir buildinctop currentdir file */
+      bid = WORD(all,3)
+      cid = WORD(all,4)
+      fil = WORD(all,5)
+      curdir = DIRECTORY()
+      d = DIRECTORY(WORD(all,2))
+      rc = SysFileDelete(fil)
+      dir = TRANSLATE(bid'/'cid'/'fil,'\','/')
+      COPY dir .' >nul 2>&1 '
+      d = DIRECTORY(curdir)
+   END
+   WHEN code=3 THEN DO
+      /* imakesvc 3 subdir updir file */
+      sdi = WORD(all,2)
+      fil = WORD(all,4)
+      curdir = DIRECTORY()
+      d = DIRECTORY(WORD(all,3))
+      rc = SysFileDelete(fil)
+      dir = TRANSLATE(sdi'/'fil,'\','/')
+      COPY dir' . >nul 2>&1'
+      d = DIRECTORY(curdir)
+   END
+   WHEN code=4 THEN DO
+      /* imakesvc 4 [-r] files... */
+      rec = WORD(all,2)
+      fp = 2
+      IF rec = '-r' THEN fp = 3 
+      ELSE rec = '-n'
+      DO i=fp TO WORDS(all)
+        CALL discard rec,TRANSLATE(WORD(all,i),'\','/')
+      END      
+   END
+   WHEN code=5 THEN DO
+      /* imakesvc 5 file */
+      file = TRANSLATE(WORD(all,2),'\','/')
+      RC = SysFileDelete(file'.bak')
+      if exists(file) THEN 'REN 'file file||'.bak'
+   END
+   WHEN code=6 THEN DO
+      /* imakesvc 6 file */
+      file = TRANSLATE(WORD(all,2),'\','/')
+      CALL SysFileDelete(file||'.bak')
+      if exists(file) THEN 'REN 'file file||'.bak'
+   END
+   WHEN code=7 THEN DO
+      /* imakesvc 7 from to */
+      from = TRANSLATE(WORD(all,2),'\','/')
+      to = TRANSLATE(WORD(all,3),'\','/')
+      CALL SysFileDelete(to)
+      COPY from to' >nul 2>&1'
+   END
+   WHEN code=8 THEN DO
+      /* imakesvc 8 arg */
+      SAY SUBWORD(TRANSLATE(all,'  ','222c'x),2)
+   END
+   WHEN code=9 THEN DO
+      /* imakesvc 9 dst.c incl.h src.c */
+      dst = TRANSLATE(WORD(all,2),'\','/')
+      src = TRANSLATE(WORD(all,4),'\','/')
+      CALL SysFileDelete(dst)
+      CALL LINEOUT dst,'#include "'WORD(all,3)'"'
+      CALL LINEOUT dst,'#include "'src'"'
+      CALL LINEOUT dst 
+   END
+   WHEN code=10 THEN DO
+      /* imakesvc 10 srcfile destdir destfile suffix */
+      src = stripsuffix(WORD(all,2))
+      destdir = TRANSLATE(WORD(all,3),'\','/')
+      dest = stripsuffix(WORD(all,4))
+      suffix = WORD(all,5)
+      tgt = destdir'\'dest'.'suffix
+      /* if you have no col.exe get one from 4.4BSD */
+      'groff -e -t -man -Tascii 'src'.man | col -b >'tgt
+   END
+   WHEN code=11 THEN DO
+      /* imakesvc 11 dirtomake */
+      dirtomake = TRANSLATE(WORD(all,2),'\','/')
+      rc = SysMkDir(dirtomake)
+   END
+   WHEN code=12 THEN DO
+      /* imakesvc 12 srcfile destdir destfile */
+      src = stripsuffix(WORD(all,2))
+      destdir = TRANSLATE(WORD(all,3),'\','/')
+      dest = stripsuffix(WORD(all,4))
+      tgt = destdir'\'dest'.gz'
+      /* if you have no col.exe get one from 4.4BSD */
+      'groff -e -t -man -Tascii 'src'.man | col -b | gzip -n >'tgt
+   END
+   WHEN code=13 THEN DO
+      /* imakesvc 13 indir fromfile tofile */
+      ind = TRANSLATE(WORD(all,2),'\','/')
+      frm = TRANSLATE(WORD(all,3),'\','/')
+      tof = ind'\'WORD(all,4)
+      IF \(exists(ind)) THEN MKDIR ind
+      rc = SysFileDelete(tof)
+      COPY frm' 'tof
+   END
+   OTHERWISE NOP
+END
+RETURN
+
+downlevels:
+oldpos = 1
+pfx = ''
+DO FOREVER
+   newpos = POS('/',ARG(1),oldpos)
+   IF newpos = 0 THEN LEAVE
+   newpfx = '../'pfx
+   oldpos = newpos+1
+   pfx = newpfx
+END
+RETURN pfx
+
+/* returns 1, if file exists */
+exists:
+'DIR "'arg(1)'" >nul 2>&1'
+IF rc = 0 THEN return 1
+RETURN 0
+
+discard: PROCEDURE
+rec=ARG(1)
+files=ARG(2)
+IF rec = '-r' THEN DO
+   old = DIRECTORY()
+   nd = DIRECTORY
+   CALL SysFileTree files, 'deld', 'DO'
+   IF deld.0 > 0 THEN DO
+      DO m=1 TO deld.0
+         CALL DIRECTORY deld.m
+         CALL discard '-R' .
+         CALL DIRECTORY ..
+         CALL SysRmDir deld.m
+      END 
+      CALL SysRmDir files
+   END
+   CALL SysFileTree files, 'delf', 'FO'
+   DO k=1 TO delf.0
+      DEL '"'delf.k'"' '>nul 2>&1'
+   END
+   CALL SysRmDir files
+END 
+ELSE DO
+   DEL '"'files'"' '>nul 2>&1'
+END
+RETURN
+
+/* somehow make or cmd manages to convert a relative path ..\..\. to ..... */
+fixbadprefix:
+count = 1
+str = ARG(1)
+DO WHILE SUBSTR(str,count,2) = '..'
+   count = count+1
+   str = INSERT('\',str,count)
+   count = count+2
+END
+RETURN str
+
+striplevel:
+str=ARG(1)
+n=arg(2)
+DO count=0 TO n
+   p = POS('/',str)
+   IF p = 0 THEN LEAVE
+   str = DELSTR(str,1,p)
+END
+RETURN str
+
+nlevels:
+str = ARG(1)
+count = 0
+oldpos = 1
+DO FOREVER
+   newpos = POS('/',str,oldpos)
+   IF newpos = 0 THEN LEAVE
+   oldpos = newpos + 1
+   count = count + 1
+END
+RETURN count
+
+maketop:
+str = ''
+n = ARG(1)
+DO k=1 TO n
+  str = str||'../'
+END
+RETURN str||'.'
+
+stripsuffix:
+str = ARG(1)
+spos = POS('.',str)
+IF spos = 0 THEN
+   RETURN str
+ELSE
+   RETURN LEFT(str,spos-1)
diff --git a/Xserver/config/makedepend/Imakefile b/Xserver/config/makedepend/Imakefile
new file mode 100644 (file)
index 0000000..89fa643
--- /dev/null
@@ -0,0 +1,92 @@
+XCOMM $TOG: Imakefile /main/27 1997/04/30 15:38:09 kaleb $
+XCOMM
+XCOMM
+XCOMM
+XCOMM
+XCOMM $XFree86: xc/config/makedepend/Imakefile,v 3.4.2.1 1997/06/11 12:08:35 dawes Exp $
+
+    SRCS = include.c main.c parse.c pr.c cppsetup.c ifparser.c 
+    OBJS = include.o main.o parse.o pr.o cppsetup.o ifparser.o 
+
+XCOMM Some compilers generate fatal errors if an -L directory does
+XCOMM not exist.  Since BUILDLIBDIR may not exist yet suppress its use.
+         LDPRELIB =
+        LDPRELIBS =
+
+#if HasGcc && !defined(PreIncDir)
+#define PreIncDir /usr/local/lib/gcc-include
+#endif
+#ifdef PreIncDir
+PREINCDIR = PreIncDir
+PREINC_DEFINES = -DPREINCDIR=\"$(PREINCDIR)\"
+#endif
+#ifndef StdIncDir
+#define StdIncDir /usr/include
+#endif
+STDINCDIR = StdIncDir
+STDINC_DEFINES = -DINCLUDEDIR=\"$(STDINCDIR)\"
+#ifdef PostIncDir
+POSTINCDIR = PostIncDir
+POSTINC_DEFINES = -DPOSTINCDIR=\"$(POSTINCDIR)\"
+#endif
+INC_DEFINES = $(PREINC_DEFINES) $(STDINC_DEFINES) $(POSTINC_DEFINES)
+OSUF = .Osuf
+OSUF_DEFINES = -DOBJSUFFIX=\"$(OSUF)\"
+MAIN_DEFINES = $(INC_DEFINES) $(SIGNAL_DEFINES) $(OSUF_DEFINES)
+INCLUDES = -I$(IMAKESRC) -I$(TOP)/include $(TOP_X_INCLUDES)/X11
+
+ DEPLIBS =
+
+#if defined(MacIIArchitecture) || defined(SequentArchitecture) || defined(i386ScoArchitecture)
+ XBSDLIB = /**/
+#endif
+
+AllTarget(ProgramTargetName(makedepend))
+
+/*
+ * bootstrapping: want to build the real makedepend
+ * only after we've run "make depend" here.  That way
+ * the program has the right dependencies for clearmake.
+ * Save the bootstrap original files so they can be winked in
+ * to other views.
+ */
+
+#if HasClearmake
+bootstrap:
+       test -h X11 || $(LN) TOPDIR/include X11
+       $(MAKE) -f Makefile.proto TOP_INCLUDES=-I. makedepend
+
+depend::
+       $(MAKE) -f Makefile.proto depend
+       test -d bootstrap || mkdir bootstrap
+       $(MV) *.o makedepend bootstrap
+       $(MAKE) -f Makefile.proto makedepend
+
+clean::
+       $(RM) -r bootstrap
+       $(RM) X11
+#else
+bootstrap:
+#endif /* HasClearmake */
+
+clean::
+       $(RM) Makefile.proto
+
+#undef InstallManPage
+#define InstallManPage(file,dest) /* as nothing */
+#if CrossCompiling
+ComplexHostProgramTarget(makedepend)
+#else
+ComplexProgramTarget(makedepend)
+#endif
+
+SpecialCObjectRule(main,$(ICONFIGFILES),$(MAIN_DEFINES))
+
+InstallManPageLong(mkdepend,$(MANDIR),makedepend)
+
+#ifdef OS2Architecture
+all::
+       $(CP) ProgramTargetName(makedepend) /
+#endif
+
+InstallLinkKitNamedProg(makedepend,makedepend,$(LINKKITDIR)/config/makedepend)
diff --git a/Xserver/config/makedepend/cpp.ed b/Xserver/config/makedepend/cpp.ed
new file mode 100644 (file)
index 0000000..ffa586f
--- /dev/null
@@ -0,0 +1,75 @@
+#
+# $XConsortium: cpp.ed,v 1.3 89/12/12 12:44:18 jim Exp $
+#
+# $Locker $
+#
+/struct symtab stab/d
+/struct symtab \*defloc;/d
+/struct symtab \*udfloc;/d
+/struct symtab \*incloc;/d
+/struct symtab \*ifloc;/d
+/struct symtab \*elsloc;/d
+/struct symtab \*eifloc;/d
+/struct symtab \*ifdloc;/d
+/struct symtab \*ifnloc;/d
+/struct symtab \*ysysloc;/d
+/struct symtab \*varloc;/d
+/struct symtab \*lneloc;/d
+/struct symtab \*ulnloc;/d
+/struct symtab \*uflloc;/d
+/^sayline(/s/$/        DELETED/p
+.,/^}/d
+/^unfill(/s/$/ DELETED/p
+.-1,/^}/d
+/^doincl(/s/$/ DELETED/p
+.-1,/^}/d
+/^equfrm(/s/$/ DELETED/p
+.,/^}/d
+/^dodef(/s/$/  DELETED/p
+.-1,/^}/d
+/^control(/s/$/        DELETED/p
+.-1,/^}/d
+/^savestring(/s/$/     DELETED/p
+.-1,/^}/d
+/^stsym(/s/$/  DELETED/p
+.-1,/^}/d
+/^ppsym(/s/$/  DELETED/p
+.-1,/^}/d
+/^yyerror(/s/$/        DELETED/p
+.,/^}/d
+/^ppwarn(/s/$/ DELETED/p
+.,/^}/d
+/^lookup(/s/$/ DELETED/p
+.-1,/^}/d
+/^subst(/s/$/  DELETED/p
+.-1,/^}/d
+/^trmdir(/s/$/ DELETED/p
+.-1,/^}/d
+/^copy(/s/$/   DELETED/p
+.-1,/^}/d
+/^pperror(/s/$/        DELETED/p
+.,/^}/d
+/^main(/s/$/   CHANGED to cpp_varsetup(argc,argv)/p
+.c
+cpp_varsetup(argc,argv)
+.
+/^strdex(/s/$/ DELETED/p
+.-1,/^}/d
+/^ for(i=1; i<argc; i++)/s/$/  To the end DELETED/p
+.,$c
+}
+.
+/^dump(/s/$/   DELETED/p
+.,/^}/c
+dump() { fatal("dump\n"); }
+.
+/^refill(/s/$/ DELETED/p
+.,/^}/c
+refill() { fatal("refill\n"); }
+.
+/^slookup(/s/$/        DELETED/p
+.-1,/^}/c
+static struct symtab *slookup() { fatal("slookup\n"); }
+.
+w
+q
diff --git a/Xserver/config/makedepend/cppsetup.c b/Xserver/config/makedepend/cppsetup.c
new file mode 100644 (file)
index 0000000..a5a17ca
--- /dev/null
@@ -0,0 +1,243 @@
+/* $XConsortium: cppsetup.c /main/17 1996/09/28 16:15:03 rws $ */
+/*
+
+Copyright (c) 1993, 1994  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+*/
+/* $XFree86: xc/config/makedepend/cppsetup.c,v 3.2 1996/12/30 13:57:53 dawes Exp $ */
+
+#include "def.h"
+
+#ifdef CPP
+/*
+ * This file is strictly for the sake of cpy.y and yylex.c (if
+ * you indeed have the source for cpp).
+ */
+#define IB 1
+#define SB 2
+#define NB 4
+#define CB 8
+#define QB 16
+#define WB 32
+#define SALT '#'
+#if defined(pdp11) || defined(vax) || defined(ns16000) || defined(mc68000) || defined(ibm032)
+#define COFF 128
+#else
+#define COFF 0
+#endif
+/*
+ * These variables used by cpy.y and yylex.c
+ */
+extern char    *outp, *inp, *newp, *pend;
+extern char    *ptrtab;
+extern char    fastab[];
+extern char    slotab[];
+
+/*
+ * cppsetup
+ */
+struct filepointer     *currentfile;
+struct inclist         *currentinc;
+
+cppsetup(line, filep, inc)
+       register char   *line;
+       register struct filepointer     *filep;
+       register struct inclist         *inc;
+{
+       register char *p, savec;
+       static boolean setupdone = FALSE;
+       boolean value;
+
+       if (!setupdone) {
+               cpp_varsetup();
+               setupdone = TRUE;
+       }
+
+       currentfile = filep;
+       currentinc = inc;
+       inp = newp = line;
+       for (p=newp; *p; p++)
+               ;
+
+       /*
+        * put a newline back on the end, and set up pend, etc.
+        */
+       *p++ = '\n';
+       savec = *p;
+       *p = '\0';
+       pend = p;
+
+       ptrtab = slotab+COFF;
+       *--inp = SALT; 
+       outp=inp; 
+       value = yyparse();
+       *p = savec;
+       return(value);
+}
+
+struct symtab **lookup(symbol)
+       char    *symbol;
+{
+       static struct symtab    *undefined;
+       struct symtab   **sp;
+
+       sp = isdefined(symbol, currentinc, NULL);
+       if (sp == NULL) {
+               sp = &undefined;
+               (*sp)->s_value = NULL;
+       }
+       return (sp);
+}
+
+pperror(tag, x0,x1,x2,x3,x4)
+       int     tag,x0,x1,x2,x3,x4;
+{
+       warning("\"%s\", line %d: ", currentinc->i_file, currentfile->f_line);
+       warning(x0,x1,x2,x3,x4);
+}
+
+
+yyerror(s)
+       register char   *s;
+{
+       fatalerr("Fatal error: %s\n", s);
+}
+#else /* not CPP */
+
+#include "ifparser.h"
+struct _parse_data {
+    struct filepointer *filep;
+    struct inclist *inc;
+    const char *line;
+};
+
+static const char *
+my_if_errors (ip, cp, expecting)
+    IfParser *ip;
+    const char *cp;
+    const char *expecting;
+{
+    struct _parse_data *pd = (struct _parse_data *) ip->data;
+    int lineno = pd->filep->f_line;
+    char *filename = pd->inc->i_file;
+    char prefix[300];
+    int prefixlen;
+    int i;
+
+    sprintf (prefix, "\"%s\":%d", filename, lineno);
+    prefixlen = strlen(prefix);
+    fprintf (stderr, "%s:  %s", prefix, pd->line);
+    i = cp - pd->line;
+    if (i > 0 && pd->line[i-1] != '\n') {
+       putc ('\n', stderr);
+    }
+    for (i += prefixlen + 3; i > 0; i--) {
+       putc (' ', stderr);
+    }
+    fprintf (stderr, "^--- expecting %s\n", expecting);
+    return NULL;
+}
+
+
+#define MAXNAMELEN 256
+
+static struct symtab **
+lookup_variable (ip, var, len)
+    IfParser *ip;
+    const char *var;
+    int len;
+{
+    char tmpbuf[MAXNAMELEN + 1];
+    struct _parse_data *pd = (struct _parse_data *) ip->data;
+
+    if (len > MAXNAMELEN)
+       return 0;
+
+    strncpy (tmpbuf, var, len);
+    tmpbuf[len] = '\0';
+    return isdefined (tmpbuf, pd->inc, NULL);
+}
+
+
+static int
+my_eval_defined (ip, var, len)
+    IfParser *ip;
+    const char *var;
+    int len;
+{
+    if (lookup_variable (ip, var, len))
+       return 1;
+    else
+       return 0;
+}
+
+#define isvarfirstletter(ccc) (isalpha(ccc) || (ccc) == '_')
+
+static long
+my_eval_variable (ip, var, len)
+    IfParser *ip;
+    const char *var;
+    int len;
+{
+    struct symtab **s;
+
+    s = lookup_variable (ip, var, len);
+    if (!s)
+       return 0;
+    do {
+       var = (*s)->s_value;
+       if (!isvarfirstletter(*var))
+           break;
+       s = lookup_variable (ip, var, strlen(var));
+    } while (s);
+
+    return strtol(var, NULL, 0);
+}
+
+
+cppsetup(line, filep, inc)
+       register char   *line;
+       register struct filepointer     *filep;
+       register struct inclist         *inc;
+{
+    IfParser ip;
+    struct _parse_data pd;
+    long val = 0;
+
+    pd.filep = filep;
+    pd.inc = inc;
+    pd.line = line;
+    ip.funcs.handle_error = my_if_errors;
+    ip.funcs.eval_defined = my_eval_defined;
+    ip.funcs.eval_variable = my_eval_variable;
+    ip.data = (char *) &pd;
+
+    (void) ParseIfExpression (&ip, line, &val);
+    if (val)
+       return IF;
+    else
+       return IFFALSE;
+}
+#endif /* CPP */
+
diff --git a/Xserver/config/makedepend/def.h b/Xserver/config/makedepend/def.h
new file mode 100644 (file)
index 0000000..d220cef
--- /dev/null
@@ -0,0 +1,152 @@
+/* $XConsortium: def.h /main/30 1996/12/04 10:11:12 swick $ */
+/* $XFree86: xc/config/makedepend/def.h,v 3.3 1997/01/12 10:38:17 dawes Exp $ */
+/*
+
+Copyright (c) 1993, 1994  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+*/
+
+#include "Xos.h"
+#include "Xfuncproto.h"
+#include <stdio.h>
+#ifndef X_NOT_STDC_ENV
+#include <string.h>
+#endif
+#include <ctype.h>
+#ifndef X_NOT_POSIX
+#ifndef _POSIX_SOURCE
+#define _POSIX_SOURCE
+#endif
+#endif
+#include <sys/types.h>
+#include <fcntl.h>
+#include <sys/stat.h>
+
+#define MAXDEFINES     512
+#define MAXFILES       1024
+#define MAXDIRS                64
+#define SYMTABINC      10      /* must be > 1 for define() to work right */
+#define        TRUE            1
+#define        FALSE           0
+
+/* the following must match the directives table in main.c */
+#define        IF              0
+#define        IFDEF           1
+#define        IFNDEF          2
+#define        ELSE            3
+#define        ENDIF           4
+#define        DEFINE          5
+#define        UNDEF           6
+#define        INCLUDE         7
+#define        LINE            8
+#define        PRAGMA          9
+#define ERROR           10
+#define IDENT           11
+#define SCCS            12
+#define ELIF            13
+#define EJECT           14
+#define WARNING         15
+#define IFFALSE         16     /* pseudo value --- never matched */
+#define ELIFFALSE       17     /* pseudo value --- never matched */
+#define INCLUDEDOT      18     /* pseudo value --- never matched */
+#define IFGUESSFALSE    19     /* pseudo value --- never matched */
+#define ELIFGUESSFALSE  20     /* pseudo value --- never matched */
+
+#ifdef DEBUG
+extern int     _debugmask;
+/*
+ * debug levels are:
+ * 
+ *     0       show ifn*(def)*,endif
+ *     1       trace defined/!defined
+ *     2       show #include
+ *     3       show #include SYMBOL
+ *     4-6     unused
+ */
+#define debug(level,arg) { if (_debugmask & (1 << level)) warning arg; }
+#else
+#define        debug(level,arg) /**/
+#endif /* DEBUG */
+
+typedef        unsigned char boolean;
+
+struct symtab {
+       char    *s_name;
+       char    *s_value;
+};
+
+/* possible i_flag */
+#define DEFCHECKED     (1<<0)  /* whether defines have been checked */
+#define NOTIFIED       (1<<1)  /* whether we have revealed includes */
+#define MARKED         (1<<2)  /* whether it's in the makefile */
+#define SEARCHED       (1<<3)  /* whether we have read this */
+#define FINISHED       (1<<4)  /* whether we are done reading this */
+#define INCLUDED_SYM   (1<<5)  /* whether #include SYMBOL was found
+                                  Can't use i_list if TRUE */
+struct inclist {
+       char            *i_incstring;   /* string from #include line */
+       char            *i_file;        /* path name of the include file */
+       struct inclist  **i_list;       /* list of files it itself includes */
+       int             i_listlen;      /* length of i_list */
+       struct symtab   **i_defs;       /* symbol table for this file and its
+                                          children when merged */
+       int             i_ndefs;        /* current # defines */
+       boolean         *i_merged;      /* whether we have merged child
+                                          defines */
+       unsigned char   i_flags;
+};
+
+struct filepointer {
+       char    *f_p;
+       char    *f_base;
+       char    *f_end;
+       long    f_len;
+       long    f_line;
+};
+
+#ifndef X_NOT_STDC_ENV
+#include <stdlib.h>
+#if defined(macII) && !defined(__STDC__)  /* stdlib.h fails to define these */
+char *malloc(), *realloc();
+#endif /* macII */
+#else
+char                   *malloc();
+char                   *realloc();
+#endif
+
+char                   *copy();
+char                   *base_name();
+char                   *x_getline();
+struct symtab          **slookup();
+struct symtab          **isdefined();
+struct symtab          **fdefined();
+struct filepointer     *getfile();
+struct inclist         *newinclude();
+struct inclist         *inc_path();
+
+#if NeedVarargsPrototypes
+extern void fatalerr(char *, ...);
+extern void warning(char *, ...);
+extern void warning1(char *, ...);
+#endif
diff --git a/Xserver/config/makedepend/ifparser.c b/Xserver/config/makedepend/ifparser.c
new file mode 100644 (file)
index 0000000..dfac152
--- /dev/null
@@ -0,0 +1,544 @@
+/*
+ * $XConsortium: ifparser.c /main/10 1996/09/28 16:15:18 rws $
+ * $XFree86: xc/config/makedepend/ifparser.c,v 3.6 1996/12/30 13:57:55 dawes Exp $
+ *
+ * Copyright 1992 Network Computing Devices, Inc.
+ * 
+ * Permission to use, copy, modify, and distribute this software and its
+ * documentation for any purpose and without fee is hereby granted, provided
+ * that the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the name of Network Computing Devices may not be
+ * used in advertising or publicity pertaining to distribution of the software
+ * without specific, written prior permission.  Network Computing Devices makes
+ * no representations about the suitability of this software for any purpose.
+ * It is provided ``as is'' without express or implied warranty.
+ * 
+ * NETWORK COMPUTING DEVICES DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
+ * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS,
+ * IN NO EVENT SHALL NETWORK COMPUTING DEVICES BE LIABLE FOR ANY SPECIAL,
+ * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
+ * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
+ * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+ * PERFORMANCE OF THIS SOFTWARE.
+ * 
+ * Author:  Jim Fulton
+ *          Network Computing Devices, Inc.
+ * 
+ * Simple if statement processor
+ *
+ * This module can be used to evaluate string representations of C language
+ * if constructs.  It accepts the following grammar:
+ * 
+ *     EXPRESSION      :=      VALUE
+ *                      |      VALUE  BINOP    EXPRESSION
+ *                      |      VALUE   '?'     EXPRESSION ':'  EXPRESSION
+ * 
+ *     VALUE           :=      '('  EXPRESSION  ')'
+ *                      |      '!'  VALUE
+ *                      |      '-'  VALUE
+ *                      |      '~'  VALUE
+ *                      |      'defined'  '('  variable  ')'
+ *                      |      'defined'  variable
+ *                      |      # variable '(' variable-list ')'
+ *                      |      variable
+ *                      |      number
+ * 
+ *     BINOP           :=      '*'     |  '/'  |  '%'
+ *                      |      '+'     |  '-'
+ *                      |      '<<'    |  '>>'
+ *                      |      '<'     |  '>'  |  '<='  |  '>='
+ *                      |      '=='    |  '!='
+ *                      |      '&'     |  '^'  |  '|'
+ *                      |      '&&'    |  '||'
+ * 
+ * The normal C order of precedence is supported.
+ * 
+ * 
+ * External Entry Points:
+ * 
+ *     ParseIfExpression               parse a string for #if
+ */
+
+#include "ifparser.h"
+#include <ctype.h>
+
+/****************************************************************************
+                  Internal Macros and Utilities for Parser
+ ****************************************************************************/
+
+#define DO(val) if (!(val)) return NULL
+#define CALLFUNC(ggg,fff) (*((ggg)->funcs.fff))
+#define SKIPSPACE(ccc) while (isspace(*ccc)) ccc++
+#define isvarfirstletter(ccc) (isalpha(ccc) || (ccc) == '_')
+
+
+static const char *
+parse_variable (g, cp, varp)
+    IfParser *g;
+    const char *cp;
+    const char **varp;
+{
+    SKIPSPACE (cp);
+
+    if (!isvarfirstletter (*cp))
+       return CALLFUNC(g, handle_error) (g, cp, "variable name");
+
+    *varp = cp;
+    /* EMPTY */
+    for (cp++; isalnum(*cp) || *cp == '_'; cp++) ;
+    return cp;
+}
+
+
+static const char *
+parse_number (g, cp, valp)
+    IfParser *g;
+    const char *cp;
+    long *valp;
+{
+    SKIPSPACE (cp);
+
+    if (!isdigit(*cp))
+       return CALLFUNC(g, handle_error) (g, cp, "number");
+
+    *valp = strtol(cp, &cp, 0);
+    /* skip trailing qualifiers */
+    while (*cp == 'U' || *cp == 'u' || *cp == 'L' || *cp == 'l') cp++;
+#if 0
+    *valp = atoi (cp);
+    /* EMPTY */
+    for (cp++; isdigit(*cp); cp++) ;
+#endif
+    return cp;
+}
+
+static const char *
+parse_character (g, cp, valp)
+    IfParser *g;
+    const char *cp;
+    long *valp;
+{
+    char val;
+
+    SKIPSPACE (cp);
+    if (*cp == '\\')
+       switch (cp[1]) {
+       case 'n': val = '\n'; break;
+       case 't': val = '\t'; break;
+       case 'v': val = '\v'; break;
+       case 'b': val = '\b'; break;
+       case 'r': val = '\r'; break;
+       case 'f': val = '\f'; break;
+       case 'a': val = '\a'; break;
+       case '\\': val = '\\'; break;
+       case '?': val = '\?'; break;
+       case '\'': val = '\''; break;
+       case '\"': val = '\"'; break;
+       case 'x': val = (char) strtol (cp + 2, NULL, 16); break;
+       default: val = (char) strtol (cp + 1, NULL, 8); break;
+       }
+    else
+       val = *cp;
+    while (*cp != '\'') cp++;
+    *valp = (long) val;
+    return cp;
+}
+
+static const char *
+parse_value (g, cp, valp)
+    IfParser *g;
+    const char *cp;
+    long *valp;
+{
+    const char *var;
+
+    *valp = 0;
+
+    SKIPSPACE (cp);
+    if (!*cp)
+       return cp;
+
+    switch (*cp) {
+      case '(':
+       DO (cp = ParseIfExpression (g, cp + 1, valp));
+       SKIPSPACE (cp);
+       if (*cp != ')') 
+           return CALLFUNC(g, handle_error) (g, cp, ")");
+
+       return cp + 1;                  /* skip the right paren */
+
+      case '!':
+       DO (cp = parse_value (g, cp + 1, valp));
+       *valp = !(*valp);
+       return cp;
+
+      case '-':
+       DO (cp = parse_value (g, cp + 1, valp));
+       *valp = -(*valp);
+       return cp;
+
+      case '~':
+       DO (cp = parse_value (g, cp + 1, valp));
+       *valp = ~(*valp);
+       return cp;
+
+      case '#':
+       DO (cp = parse_variable (g, cp + 1, &var));
+       SKIPSPACE (cp);
+       if (*cp != '(')
+           return CALLFUNC(g, handle_error) (g, cp, "(");
+       do {
+           DO (cp = parse_variable (g, cp + 1, &var));
+           SKIPSPACE (cp);
+       } while (*cp && *cp != ')');
+       if (*cp != ')')
+           return CALLFUNC(g, handle_error) (g, cp, ")");
+       *valp = 1; /* XXX */
+       return cp + 1;
+
+      case '\'':
+       DO (cp = parse_character (g, cp + 1, valp));
+       if (*cp != '\'')
+           return CALLFUNC(g, handle_error) (g, cp, "'");
+       return cp + 1;
+
+      case 'd':
+       if (strncmp (cp, "defined", 7) == 0 && !isalnum(cp[7])) {
+           int paren = 0;
+           int len;
+
+           cp += 7;
+           SKIPSPACE (cp);
+           if (*cp == '(') {
+               paren = 1;
+               cp++;
+           }
+           DO (cp = parse_variable (g, cp, &var));
+           len = cp - var;
+           SKIPSPACE (cp);
+           if (paren && *cp != ')')
+               return CALLFUNC(g, handle_error) (g, cp, ")");
+           *valp = (*(g->funcs.eval_defined)) (g, var, len);
+           return cp + paren;          /* skip the right paren */
+       }
+       /* fall out */
+    }
+
+    if (isdigit(*cp)) {
+       DO (cp = parse_number (g, cp, valp));
+    } else if (!isvarfirstletter(*cp))
+       return CALLFUNC(g, handle_error) (g, cp, "variable or number");
+    else {
+       DO (cp = parse_variable (g, cp, &var));
+       *valp = (*(g->funcs.eval_variable)) (g, var, cp - var);
+    }
+    
+    return cp;
+}
+
+
+
+static const char *
+parse_product (g, cp, valp)
+    IfParser *g;
+    const char *cp;
+    long *valp;
+{
+    long rightval;
+
+    DO (cp = parse_value (g, cp, valp));
+    SKIPSPACE (cp);
+
+    switch (*cp) {
+      case '*':
+       DO (cp = parse_product (g, cp + 1, &rightval));
+       *valp = (*valp * rightval);
+       break;
+
+      case '/':
+       DO (cp = parse_product (g, cp + 1, &rightval));
+       *valp = (*valp / rightval);
+       break;
+
+      case '%':
+       DO (cp = parse_product (g, cp + 1, &rightval));
+       *valp = (*valp % rightval);
+       break;
+    }
+    return cp;
+}
+
+
+static const char *
+parse_sum (g, cp, valp)
+    IfParser *g;
+    const char *cp;
+    long *valp;
+{
+    long rightval;
+
+    DO (cp = parse_product (g, cp, valp));
+    SKIPSPACE (cp);
+
+    switch (*cp) {
+      case '+':
+       DO (cp = parse_sum (g, cp + 1, &rightval));
+       *valp = (*valp + rightval);
+       break;
+
+      case '-':
+       DO (cp = parse_sum (g, cp + 1, &rightval));
+       *valp = (*valp - rightval);
+       break;
+    }
+    return cp;
+}
+
+
+static const char *
+parse_shift (g, cp, valp)
+    IfParser *g;
+    const char *cp;
+    long *valp;
+{
+    long rightval;
+
+    DO (cp = parse_sum (g, cp, valp));
+    SKIPSPACE (cp);
+
+    switch (*cp) {
+      case '<':
+       if (cp[1] == '<') {
+           DO (cp = parse_shift (g, cp + 2, &rightval));
+           *valp = (*valp << rightval);
+       }
+       break;
+
+      case '>':
+       if (cp[1] == '>') {
+           DO (cp = parse_shift (g, cp + 2, &rightval));
+           *valp = (*valp >> rightval);
+       }
+       break;
+    }
+    return cp;
+}
+
+
+static const char *
+parse_inequality (g, cp, valp)
+    IfParser *g;
+    const char *cp;
+    long *valp;
+{
+    long rightval;
+
+    DO (cp = parse_shift (g, cp, valp));
+    SKIPSPACE (cp);
+
+    switch (*cp) {
+      case '<':
+       if (cp[1] == '=') {
+           DO (cp = parse_inequality (g, cp + 2, &rightval));
+           *valp = (*valp <= rightval);
+       } else {
+           DO (cp = parse_inequality (g, cp + 1, &rightval));
+           *valp = (*valp < rightval);
+       }
+       break;
+
+      case '>':
+       if (cp[1] == '=') {
+           DO (cp = parse_inequality (g, cp + 2, &rightval));
+           *valp = (*valp >= rightval);
+       } else {
+           DO (cp = parse_inequality (g, cp + 1, &rightval));
+           *valp = (*valp > rightval);
+       }
+       break;
+    }
+    return cp;
+}
+
+
+static const char *
+parse_equality (g, cp, valp)
+    IfParser *g;
+    const char *cp;
+    long *valp;
+{
+    long rightval;
+
+    DO (cp = parse_inequality (g, cp, valp));
+    SKIPSPACE (cp);
+
+    switch (*cp) {
+      case '=':
+       if (cp[1] == '=')
+           cp++;
+       DO (cp = parse_equality (g, cp + 1, &rightval));
+       *valp = (*valp == rightval);
+       break;
+
+      case '!':
+       if (cp[1] != '=')
+           break;
+       DO (cp = parse_equality (g, cp + 2, &rightval));
+       *valp = (*valp != rightval);
+       break;
+    }
+    return cp;
+}
+
+
+static const char *
+parse_band (g, cp, valp)
+    IfParser *g;
+    const char *cp;
+    long *valp;
+{
+    long rightval;
+
+    DO (cp = parse_equality (g, cp, valp));
+    SKIPSPACE (cp);
+
+    switch (*cp) {
+      case '&':
+       if (cp[1] != '&') {
+           DO (cp = parse_band (g, cp + 1, &rightval));
+           *valp = (*valp & rightval);
+       }
+       break;
+    }
+    return cp;
+}
+
+
+static const char *
+parse_bxor (g, cp, valp)
+    IfParser *g;
+    const char *cp;
+    long *valp;
+{
+    long rightval;
+
+    DO (cp = parse_band (g, cp, valp));
+    SKIPSPACE (cp);
+
+    switch (*cp) {
+      case '^':
+       DO (cp = parse_bxor (g, cp + 1, &rightval));
+       *valp = (*valp ^ rightval);
+       break;
+    }
+    return cp;
+}
+
+
+static const char *
+parse_bor (g, cp, valp)
+    IfParser *g;
+    const char *cp;
+    long *valp;
+{
+    long rightval;
+
+    DO (cp = parse_bxor (g, cp, valp));
+    SKIPSPACE (cp);
+
+    switch (*cp) {
+      case '|':
+       if (cp[1] != '|') {
+           DO (cp = parse_bor (g, cp + 1, &rightval));
+           *valp = (*valp | rightval);
+       }
+       break;
+    }
+    return cp;
+}
+
+
+static const char *
+parse_land (g, cp, valp)
+    IfParser *g;
+    const char *cp;
+    long *valp;
+{
+    long rightval;
+
+    DO (cp = parse_bor (g, cp, valp));
+    SKIPSPACE (cp);
+
+    switch (*cp) {
+      case '&':
+       if (cp[1] != '&')
+           return CALLFUNC(g, handle_error) (g, cp, "&&");
+       DO (cp = parse_land (g, cp + 2, &rightval));
+       *valp = (*valp && rightval);
+       break;
+    }
+    return cp;
+}
+
+
+static const char *
+parse_lor (g, cp, valp)
+    IfParser *g;
+    const char *cp;
+    long *valp;
+{
+    long rightval;
+
+    DO (cp = parse_land (g, cp, valp));
+    SKIPSPACE (cp);
+
+    switch (*cp) {
+      case '|':
+       if (cp[1] != '|')
+           return CALLFUNC(g, handle_error) (g, cp, "||");
+       DO (cp = parse_lor (g, cp + 2, &rightval));
+       *valp = (*valp || rightval);
+       break;
+    }
+    return cp;
+}
+
+
+static const char *
+parse_cond(g, cp, valp)
+    IfParser *g;
+    const char *cp;
+    long *valp;
+{
+    long trueval, falseval;
+
+    DO (cp = parse_lor (g, cp, valp));
+    SKIPSPACE (cp);
+
+    switch (*cp) {
+      case '?':
+       DO (cp = parse_cond (g, cp + 1, &trueval));
+       SKIPSPACE (cp);
+       if (*cp != ':')
+           return CALLFUNC(g, handle_error) (g, cp, ":");
+       DO (cp = parse_cond (g, cp + 1, &falseval));
+       *valp = (*valp ? trueval : falseval);
+       break;
+    }
+    return cp;
+}
+
+
+/****************************************************************************
+                            External Entry Points
+ ****************************************************************************/
+
+const char *
+ParseIfExpression (g, cp, valp)
+    IfParser *g;
+    const char *cp;
+    long *valp;
+{
+    return parse_cond (g, cp, valp);
+}
diff --git a/Xserver/config/makedepend/ifparser.h b/Xserver/config/makedepend/ifparser.h
new file mode 100644 (file)
index 0000000..a9fd47f
--- /dev/null
@@ -0,0 +1,86 @@
+/*
+ * $XConsortium: ifparser.h /main/4 1996/09/28 16:15:24 rws $
+ *
+ * Copyright 1992 Network Computing Devices, Inc.
+ * 
+ * Permission to use, copy, modify, and distribute this software and its
+ * documentation for any purpose and without fee is hereby granted, provided
+ * that the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the name of Network Computing Devices may not be
+ * used in advertising or publicity pertaining to distribution of the software
+ * without specific, written prior permission.  Network Computing Devices makes
+ * no representations about the suitability of this software for any purpose.
+ * It is provided ``as is'' without express or implied warranty.
+ * 
+ * NETWORK COMPUTING DEVICES DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
+ * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS,
+ * IN NO EVENT SHALL NETWORK COMPUTING DEVICES BE LIABLE FOR ANY SPECIAL,
+ * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
+ * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
+ * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+ * PERFORMANCE OF THIS SOFTWARE.
+ * 
+ * Author:  Jim Fulton
+ *          Network Computing Devices, Inc.
+ * 
+ * Simple if statement processor
+ *
+ * This module can be used to evaluate string representations of C language
+ * if constructs.  It accepts the following grammar:
+ * 
+ *     EXPRESSION      :=      VALUE
+ *                      |      VALUE  BINOP    EXPRESSION
+ *                      |      VALUE   '?'     EXPRESSION ':'  EXPRESSION
+ * 
+ *     VALUE           :=      '('  EXPRESSION  ')'
+ *                      |      '!'  VALUE
+ *                      |      '-'  VALUE
+ *                      |      '~'  VALUE
+ *                      |      'defined'  '('  variable  ')'
+ *                      |      variable
+ *                      |      number
+ * 
+ *     BINOP           :=      '*'     |  '/'  |  '%'
+ *                      |      '+'     |  '-'
+ *                      |      '<<'    |  '>>'
+ *                      |      '<'     |  '>'  |  '<='  |  '>='
+ *                      |      '=='    |  '!='
+ *                      |      '&'     |  '^'  |  '|'
+ *                      |      '&&'    |  '||'
+ * 
+ * The normal C order of precedence is supported.
+ * 
+ * 
+ * External Entry Points:
+ * 
+ *     ParseIfExpression               parse a string for #if
+ */
+
+/* $XFree86: xc/config/makedepend/ifparser.h,v 3.2 1996/12/30 13:57:56 dawes Exp $ */
+
+#include <stdio.h>
+
+#define const /**/
+typedef int Bool;
+#define False 0
+#define True 1
+
+typedef struct _if_parser {
+    struct {                           /* functions */
+       char *(*handle_error) (/* struct _if_parser *, const char *,
+                                const char * */);
+       long (*eval_variable) (/* struct _if_parser *, const char *, int */);
+       int (*eval_defined) (/* struct _if_parser *, const char *, int */);
+    } funcs;
+    char *data;
+} IfParser;
+
+char *ParseIfExpression (
+#ifdef __STDC__
+    IfParser *, 
+    const char *, 
+    long *
+#endif
+);
+
diff --git a/Xserver/config/makedepend/include.c b/Xserver/config/makedepend/include.c
new file mode 100644 (file)
index 0000000..61fa57d
--- /dev/null
@@ -0,0 +1,320 @@
+/* $XConsortium: include.c /main/20 1996/12/04 10:11:18 swick $ */
+/*
+
+Copyright (c) 1993, 1994  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+*/
+
+
+#include "def.h"
+
+extern struct  inclist inclist[ MAXFILES ],
+                       *inclistp;
+extern char    *includedirs[ ];
+extern char    *notdotdot[ ];
+extern boolean show_where_not;
+extern boolean warn_multiple;
+
+boolean
+isdot(p)
+       register char   *p;
+{
+       if(p && *p++ == '.' && *p++ == '\0')
+               return(TRUE);
+       return(FALSE);
+}
+
+boolean
+isdotdot(p)
+       register char   *p;
+{
+       if(p && *p++ == '.' && *p++ == '.' && *p++ == '\0')
+               return(TRUE);
+       return(FALSE);
+}
+
+boolean
+issymbolic(dir, component)
+       register char   *dir, *component;
+{
+#ifdef S_IFLNK
+       struct stat     st;
+       char    buf[ BUFSIZ ], **pp;
+
+       sprintf(buf, "%s%s%s", dir, *dir ? "/" : "", component);
+       for (pp=notdotdot; *pp; pp++)
+               if (strcmp(*pp, buf) == 0)
+                       return (TRUE);
+       if (lstat(buf, &st) == 0
+       && (st.st_mode & S_IFMT) == S_IFLNK) {
+               *pp++ = copy(buf);
+               if (pp >= &notdotdot[ MAXDIRS ])
+                       fatalerr("out of .. dirs, increase MAXDIRS\n");
+               return(TRUE);
+       }
+#endif
+       return(FALSE);
+}
+
+/*
+ * Occasionally, pathnames are created that look like .../x/../y
+ * Any of the 'x/..' sequences within the name can be eliminated.
+ * (but only if 'x' is not a symbolic link!!)
+ */
+void
+remove_dotdot(path)
+       char    *path;
+{
+       register char   *end, *from, *to, **cp;
+       char            *components[ MAXFILES ],
+                       newpath[ BUFSIZ ];
+       boolean         component_copied;
+
+       /*
+        * slice path up into components.
+        */
+       to = newpath;
+       if (*path == '/')
+               *to++ = '/';
+       *to = '\0';
+       cp = components;
+       for (from=end=path; *end; end++)
+               if (*end == '/') {
+                       while (*end == '/')
+                               *end++ = '\0';
+                       if (*from)
+                               *cp++ = from;
+                       from = end;
+               }
+       *cp++ = from;
+       *cp = NULL;
+
+       /*
+        * Recursively remove all 'x/..' component pairs.
+        */
+       cp = components;
+       while(*cp) {
+               if (!isdot(*cp) && !isdotdot(*cp) && isdotdot(*(cp+1))
+                   && !issymbolic(newpath, *cp))
+               {
+                   char **fp = cp + 2;
+                   char **tp = cp;
+
+                   do 
+                       *tp++ = *fp; /* move all the pointers down */
+                   while (*fp++);
+                   if (cp != components)
+                       cp--;   /* go back and check for nested ".." */
+               } else {
+                   cp++;
+               }
+       }
+       /*
+        * Concatenate the remaining path elements.
+        */
+       cp = components;
+       component_copied = FALSE;
+       while(*cp) {
+               if (component_copied)
+                       *to++ = '/';
+               component_copied = TRUE;
+               for (from = *cp; *from; )
+                       *to++ = *from++;
+               *to = '\0';
+               cp++;
+       }
+       *to++ = '\0';
+
+       /*
+        * copy the reconstituted path back to our pointer.
+        */
+       strcpy(path, newpath);
+}
+
+/*
+ * Add an include file to the list of those included by 'file'.
+ */
+struct inclist *newinclude(newfile, incstring)
+       register char   *newfile, *incstring;
+{
+       register struct inclist *ip;
+
+       /*
+        * First, put this file on the global list of include files.
+        */
+       ip = inclistp++;
+       if (inclistp == inclist + MAXFILES - 1)
+               fatalerr("out of space: increase MAXFILES\n");
+       ip->i_file = copy(newfile);
+
+       if (incstring == NULL)
+               ip->i_incstring = ip->i_file;
+       else
+               ip->i_incstring = copy(incstring);
+
+       return(ip);
+}
+
+void
+included_by(ip, newfile)
+       register struct inclist *ip, *newfile;
+{
+       register int i;
+
+       if (ip == NULL)
+               return;
+       /*
+        * Put this include file (newfile) on the list of files included
+        * by 'file'.  If 'file' is NULL, then it is not an include
+        * file itself (i.e. was probably mentioned on the command line).
+        * If it is already on the list, don't stick it on again.
+        */
+       if (ip->i_list == NULL) {
+               ip->i_list = (struct inclist **)
+                       malloc(sizeof(struct inclist *) * ++ip->i_listlen);
+               ip->i_merged = (boolean *)
+                   malloc(sizeof(boolean) * ip->i_listlen);
+       } else {
+               for (i=0; i<ip->i_listlen; i++)
+                       if (ip->i_list[ i ] == newfile) {
+                           i = strlen(newfile->i_file);
+                           if (!(ip->i_flags & INCLUDED_SYM) &&
+                               !(i > 2 &&
+                                 newfile->i_file[i-1] == 'c' &&
+                                 newfile->i_file[i-2] == '.'))
+                           {
+                               /* only bitch if ip has */
+                               /* no #include SYMBOL lines  */
+                               /* and is not a .c file */
+                               if (warn_multiple)
+                               {
+                                       warning("%s includes %s more than once!\n",
+                                               ip->i_file, newfile->i_file);
+                                       warning1("Already have\n");
+                                       for (i=0; i<ip->i_listlen; i++)
+                                               warning1("\t%s\n", ip->i_list[i]->i_file);
+                               }
+                           }
+                           return;
+                       }
+               ip->i_list = (struct inclist **) realloc(ip->i_list,
+                       sizeof(struct inclist *) * ++ip->i_listlen);
+               ip->i_merged = (boolean *)
+                   realloc(ip->i_merged, sizeof(boolean) * ip->i_listlen);
+       }
+       ip->i_list[ ip->i_listlen-1 ] = newfile;
+       ip->i_merged[ ip->i_listlen-1 ] = FALSE;
+}
+
+void
+inc_clean ()
+{
+       register struct inclist *ip;
+
+       for (ip = inclist; ip < inclistp; ip++) {
+               ip->i_flags &= ~MARKED;
+       }
+}
+
+struct inclist *inc_path(file, include, dot)
+       register char   *file,
+                       *include;
+       boolean dot;
+{
+       static char     path[ BUFSIZ ];
+       register char           **pp, *p;
+       register struct inclist *ip;
+       struct stat     st;
+       boolean found = FALSE;
+
+       /*
+        * Check all previously found include files for a path that
+        * has already been expanded.
+        */
+       for (ip = inclist; ip->i_file; ip++)
+           if ((strcmp(ip->i_incstring, include) == 0) &&
+               !(ip->i_flags & INCLUDED_SYM))
+           {
+               found = TRUE;
+               break;
+           }
+
+       /*
+        * If the path was surrounded by "" or is an absolute path,
+        * then check the exact path provided.
+        */
+       if (!found && (dot || *include == '/')) {
+               if (stat(include, &st) == 0) {
+                       ip = newinclude(include, include);
+                       found = TRUE;
+               }
+               else if (show_where_not)
+                       warning1("\tnot in %s\n", include);
+       }
+
+       /*
+        * If the path was surrounded by "" see if this include file is in the
+        * directory of the file being parsed.
+        */
+       if (!found && dot) {
+               for (p=file+strlen(file); p>file; p--)
+                       if (*p == '/')
+                               break;
+               if (p == file)
+                       strcpy(path, include);
+               else {
+                       strncpy(path, file, (p-file) + 1);
+                       path[ (p-file) + 1 ] = '\0';
+                       strcpy(path + (p-file) + 1, include);
+               }
+               remove_dotdot(path);
+               if (stat(path, &st) == 0) {
+                       ip = newinclude(path, include);
+                       found = TRUE;
+               }
+               else if (show_where_not)
+                       warning1("\tnot in %s\n", path);
+       }
+
+       /*
+        * Check the include directories specified. (standard include dir
+        * should be at the end.)
+        */
+       if (!found)
+               for (pp = includedirs; *pp; pp++) {
+                       sprintf(path, "%s/%s", *pp, include);
+                       remove_dotdot(path);
+                       if (stat(path, &st) == 0) {
+                               ip = newinclude(path, include);
+                               found = TRUE;
+                               break;
+                       }
+                       else if (show_where_not)
+                               warning1("\tnot in %s\n", path);
+               }
+
+       if (!found)
+               ip = NULL;
+       return(ip);
+}
diff --git a/Xserver/config/makedepend/main.c b/Xserver/config/makedepend/main.c
new file mode 100644 (file)
index 0000000..477cc75
--- /dev/null
@@ -0,0 +1,782 @@
+/* $XConsortium: main.c /main/84 1996/12/04 10:11:23 swick $ */
+/* $XFree86: xc/config/makedepend/main.c,v 3.11.2.1 1997/05/11 05:04:07 dawes Exp $ */
+/*
+
+Copyright (c) 1993, 1994  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+*/
+
+#include "def.h"
+#ifdef hpux
+#define sigvec sigvector
+#endif /* hpux */
+
+#ifdef X_POSIX_C_SOURCE
+#define _POSIX_C_SOURCE X_POSIX_C_SOURCE
+#include <signal.h>
+#undef _POSIX_C_SOURCE
+#else
+#if defined(X_NOT_POSIX) || defined(_POSIX_SOURCE)
+#include <signal.h>
+#else
+#define _POSIX_SOURCE
+#include <signal.h>
+#undef _POSIX_SOURCE
+#endif
+#endif
+
+#if NeedVarargsPrototypes
+#include <stdarg.h>
+#endif
+
+#ifdef MINIX
+#define USE_CHMOD      1
+#endif
+
+#ifdef DEBUG
+int    _debugmask;
+#endif
+
+char *ProgramName;
+
+char   *directives[] = {
+       "if",
+       "ifdef",
+       "ifndef",
+       "else",
+       "endif",
+       "define",
+       "undef",
+       "include",
+       "line",
+       "pragma",
+       "error",
+       "ident",
+       "sccs",
+       "elif",
+       "eject",
+       "warning",
+       NULL
+};
+
+#define MAKEDEPEND
+#include "imakemdep.h" /* from config sources */
+#undef MAKEDEPEND
+
+struct inclist inclist[ MAXFILES ],
+               *inclistp = inclist,
+               maininclist;
+
+char   *filelist[ MAXFILES ];
+char   *includedirs[ MAXDIRS + 1 ];
+char   *notdotdot[ MAXDIRS ];
+char   *objprefix = "";
+char   *objsuffix = OBJSUFFIX;
+char   *startat = "# DO NOT DELETE";
+int    width = 78;
+boolean        append = FALSE;
+boolean        printed = FALSE;
+boolean        verbose = FALSE;
+boolean        show_where_not = FALSE;
+boolean warn_multiple = FALSE; /* Warn on multiple includes of same file */
+
+void freefile();
+void redirect();
+#if !NeedVarargsPrototypes
+void fatalerr();
+void warning();
+void warning1();
+#endif
+
+static
+#ifdef SIGNALRETURNSINT
+int
+#else
+void
+#endif
+catch (sig)
+    int sig;
+{
+       fflush (stdout);
+       fatalerr ("got signal %d\n", sig);
+}
+
+#if defined(USG) || (defined(i386) && defined(SYSV)) || defined(WIN32) || defined(__EMX__) || defined(Lynx_22)
+#define USGISH
+#endif
+
+#ifndef USGISH
+#ifndef _POSIX_SOURCE
+#define sigaction sigvec
+#define sa_handler sv_handler
+#define sa_mask sv_mask
+#define sa_flags sv_flags
+#endif
+struct sigaction sig_act;
+#endif /* USGISH */
+
+main(argc, argv)
+       int     argc;
+       char    **argv;
+{
+       register char   **fp = filelist;
+       register char   **incp = includedirs;
+       register char   *p;
+       register struct inclist *ip;
+       char    *makefile = NULL;
+       struct filepointer      *filecontent;
+       struct symtab *psymp = predefs;
+       char *endmarker = NULL;
+       char *defincdir = NULL;
+       char **undeflist = NULL;
+       int numundefs = 0, i;
+
+       ProgramName = argv[0];
+
+       while (psymp->s_name)
+       {
+           define2(psymp->s_name, psymp->s_value, &maininclist);
+           psymp++;
+       }
+       if (argc == 2 && argv[1][0] == '@') {
+           struct stat ast;
+           int afd;
+           char *args;
+           char **nargv;
+           int nargc;
+           char quotechar = '\0';
+
+           nargc = 1;
+           if ((afd = open(argv[1]+1, O_RDONLY)) < 0)
+               fatalerr("cannot open \"%s\"\n", argv[1]+1);
+           fstat(afd, &ast);
+           args = (char *)malloc(ast.st_size + 1);
+           if ((ast.st_size = read(afd, args, ast.st_size)) < 0)
+               fatalerr("failed to read %s\n", argv[1]+1);
+           args[ast.st_size] = '\0';
+           close(afd);
+           for (p = args; *p; p++) {
+               if (quotechar) {
+                   if (quotechar == '\\' ||
+                       (*p == quotechar && p[-1] != '\\'))
+                       quotechar = '\0';
+                   continue;
+               }
+               switch (*p) {
+               case '\\':
+               case '"':
+               case '\'':
+                   quotechar = *p;
+                   break;
+               case ' ':
+               case '\n':
+                   *p = '\0';
+                   if (p > args && p[-1])
+                       nargc++;
+                   break;
+               }
+           }
+           if (p[-1])
+               nargc++;
+           nargv = (char **)malloc(nargc * sizeof(char *));
+           nargv[0] = argv[0];
+           argc = 1;
+           for (p = args; argc < nargc; p += strlen(p) + 1)
+               if (*p) nargv[argc++] = p;
+           argv = nargv;
+       }
+       for(argc--, argv++; argc; argc--, argv++) {
+               /* if looking for endmarker then check before parsing */
+               if (endmarker && strcmp (endmarker, *argv) == 0) {
+                   endmarker = NULL;
+                   continue;
+               }
+               if (**argv != '-') {
+                       /* treat +thing as an option for C++ */
+                       if (endmarker && **argv == '+')
+                               continue;
+                       *fp++ = argv[0];
+                       continue;
+               }
+               switch(argv[0][1]) {
+               case '-':
+                       endmarker = &argv[0][2];
+                       if (endmarker[0] == '\0') endmarker = "--";
+                       break;
+               case 'D':
+                       if (argv[0][2] == '\0') {
+                               argv++;
+                               argc--;
+                       }
+                       for (p=argv[0] + 2; *p ; p++)
+                               if (*p == '=') {
+                                       *p = ' ';
+                                       break;
+                               }
+                       define(argv[0] + 2, &maininclist);
+                       break;
+               case 'I':
+                       if (incp >= includedirs + MAXDIRS)
+                           fatalerr("Too many -I flags.\n");
+                       *incp++ = argv[0]+2;
+                       if (**(incp-1) == '\0') {
+                               *(incp-1) = *(++argv);
+                               argc--;
+                       }
+                       break;
+               case 'U':
+                       /* Undef's override all -D's so save them up */
+                       numundefs++;
+                       if (numundefs == 1)
+                           undeflist = malloc(sizeof(char *));
+                       else
+                           undeflist = realloc(undeflist,
+                                               numundefs * sizeof(char *));
+                       if (argv[0][2] == '\0') {
+                               argv++;
+                               argc--;
+                       }
+                       undeflist[numundefs - 1] = argv[0] + 2;
+                       break;
+               case 'Y':
+                       defincdir = argv[0]+2;
+                       break;
+               /* do not use if endmarker processing */
+               case 'a':
+                       if (endmarker) break;
+                       append = TRUE;
+                       break;
+               case 'w':
+                       if (endmarker) break;
+                       if (argv[0][2] == '\0') {
+                               argv++;
+                               argc--;
+                               width = atoi(argv[0]);
+                       } else
+                               width = atoi(argv[0]+2);
+                       break;
+               case 'o':
+                       if (endmarker) break;
+                       if (argv[0][2] == '\0') {
+                               argv++;
+                               argc--;
+                               objsuffix = argv[0];
+                       } else
+                               objsuffix = argv[0]+2;
+                       break;
+               case 'p':
+                       if (endmarker) break;
+                       if (argv[0][2] == '\0') {
+                               argv++;
+                               argc--;
+                               objprefix = argv[0];
+                       } else
+                               objprefix = argv[0]+2;
+                       break;
+               case 'v':
+                       if (endmarker) break;
+                       verbose = TRUE;
+#ifdef DEBUG
+                       if (argv[0][2])
+                               _debugmask = atoi(argv[0]+2);
+#endif
+                       break;
+               case 's':
+                       if (endmarker) break;
+                       startat = argv[0]+2;
+                       if (*startat == '\0') {
+                               startat = *(++argv);
+                               argc--;
+                       }
+                       if (*startat != '#')
+                               fatalerr("-s flag's value should start %s\n",
+                                       "with '#'.");
+                       break;
+               case 'f':
+                       if (endmarker) break;
+                       makefile = argv[0]+2;
+                       if (*makefile == '\0') {
+                               makefile = *(++argv);
+                               argc--;
+                       }
+                       break;
+
+               case 'm':
+                       warn_multiple = TRUE;
+                       break;
+                       
+               /* Ignore -O, -g so we can just pass ${CFLAGS} to
+                  makedepend
+                */
+               case 'O':
+               case 'g':
+                       break;
+               default:
+                       if (endmarker) break;
+       /*              fatalerr("unknown opt = %s\n", argv[0]); */
+                       warning("ignoring option %s\n", argv[0]);
+               }
+       }
+       /* Now do the undefs from the command line */
+       for (i = 0; i < numundefs; i++)
+           undefine(undeflist[i], &maininclist);
+       if (numundefs > 0)
+           free(undeflist);
+
+       if (!defincdir) {
+#ifdef PREINCDIR
+           if (incp >= includedirs + MAXDIRS)
+               fatalerr("Too many -I flags.\n");
+           *incp++ = PREINCDIR;
+#endif
+#ifdef __EMX__
+           {
+               char *emxinc = getenv("C_INCLUDE_PATH");
+               /* can have more than one component */
+               if (emxinc) {
+                   char *beg, *end;
+                   beg= (char*)strdup(emxinc);
+                   for (;;) {
+                       end = (char*)strchr(beg,';');
+                       if (end) *end = 0;
+                       if (incp >= includedirs + MAXDIRS)
+                               fatalerr("Too many include dirs\n");
+                       *incp++ = beg;
+                       if (!end) break;
+                       beg = end+1;
+                   }
+               }
+           }
+#else /* !__EMX__, does not use INCLUDEDIR at all */
+           if (incp >= includedirs + MAXDIRS)
+               fatalerr("Too many -I flags.\n");
+           *incp++ = INCLUDEDIR;
+#endif
+
+#ifdef POSTINCDIR
+           if (incp >= includedirs + MAXDIRS)
+               fatalerr("Too many -I flags.\n");
+           *incp++ = POSTINCDIR;
+#endif
+       } else if (*defincdir) {
+           if (incp >= includedirs + MAXDIRS)
+               fatalerr("Too many -I flags.\n");
+           *incp++ = defincdir;
+       }
+
+       redirect(startat, makefile);
+
+       /*
+        * catch signals.
+        */
+#ifdef USGISH
+/*  should really reset SIGINT to SIG_IGN if it was.  */
+#ifdef SIGHUP
+       signal (SIGHUP, catch);
+#endif
+       signal (SIGINT, catch);
+#ifdef SIGQUIT
+       signal (SIGQUIT, catch);
+#endif
+       signal (SIGILL, catch);
+#ifdef SIGBUS
+       signal (SIGBUS, catch);
+#endif
+       signal (SIGSEGV, catch);
+#ifdef SIGSYS
+       signal (SIGSYS, catch);
+#endif
+#else
+       sig_act.sa_handler = catch;
+#ifdef _POSIX_SOURCE
+       sigemptyset(&sig_act.sa_mask);
+       sigaddset(&sig_act.sa_mask, SIGINT);
+       sigaddset(&sig_act.sa_mask, SIGQUIT);
+#ifdef SIGBUS
+       sigaddset(&sig_act.sa_mask, SIGBUS);
+#endif
+       sigaddset(&sig_act.sa_mask, SIGILL);
+       sigaddset(&sig_act.sa_mask, SIGSEGV);
+       sigaddset(&sig_act.sa_mask, SIGHUP);
+       sigaddset(&sig_act.sa_mask, SIGPIPE);
+#ifdef SIGSYS
+       sigaddset(&sig_act.sa_mask, SIGSYS);
+#endif
+#else
+       sig_act.sa_mask = ((1<<(SIGINT -1))
+                          |(1<<(SIGQUIT-1))
+#ifdef SIGBUS
+                          |(1<<(SIGBUS-1))
+#endif
+                          |(1<<(SIGILL-1))
+                          |(1<<(SIGSEGV-1))
+                          |(1<<(SIGHUP-1))
+                          |(1<<(SIGPIPE-1))
+#ifdef SIGSYS
+                          |(1<<(SIGSYS-1))
+#endif
+                          );
+#endif /* _POSIX_SOURCE */
+       sig_act.sa_flags = 0;
+       sigaction(SIGHUP, &sig_act, (struct sigaction *)0);
+       sigaction(SIGINT, &sig_act, (struct sigaction *)0);
+       sigaction(SIGQUIT, &sig_act, (struct sigaction *)0);
+       sigaction(SIGILL, &sig_act, (struct sigaction *)0);
+#ifdef SIGBUS
+       sigaction(SIGBUS, &sig_act, (struct sigaction *)0);
+#endif
+       sigaction(SIGSEGV, &sig_act, (struct sigaction *)0);
+#ifdef SIGSYS
+       sigaction(SIGSYS, &sig_act, (struct sigaction *)0);
+#endif
+#endif /* USGISH */
+
+       /*
+        * now peruse through the list of files.
+        */
+       for(fp=filelist; *fp; fp++) {
+               filecontent = getfile(*fp);
+               ip = newinclude(*fp, (char *)NULL);
+
+               find_includes(filecontent, ip, ip, 0, FALSE);
+               freefile(filecontent);
+               recursive_pr_include(ip, ip->i_file, base_name(*fp));
+               inc_clean();
+       }
+       if (printed)
+               printf("\n");
+       exit(0);
+}
+
+#ifdef __EMX__
+/*
+ * eliminate \r chars from file
+ */
+static int elim_cr(char *buf, int sz)
+{
+       int i,wp;
+       for (i= wp = 0; i<sz; i++) {
+               if (buf[i] != '\r')
+                       buf[wp++] = buf[i];
+       }
+       return wp;
+}
+#endif
+
+struct filepointer *getfile(file)
+       char    *file;
+{
+       register int    fd;
+       struct filepointer      *content;
+       struct stat     st;
+
+       content = (struct filepointer *)malloc(sizeof(struct filepointer));
+       if ((fd = open(file, O_RDONLY)) < 0) {
+               warning("cannot open \"%s\"\n", file);
+               content->f_p = content->f_base = content->f_end = (char *)malloc(1);
+               *content->f_p = '\0';
+               return(content);
+       }
+       fstat(fd, &st);
+       content->f_base = (char *)malloc(st.st_size+1);
+       if (content->f_base == NULL)
+               fatalerr("cannot allocate mem\n");
+       if ((st.st_size = read(fd, content->f_base, st.st_size)) < 0)
+               fatalerr("failed to read %s\n", file);
+#ifdef __EMX__
+       st.st_size = elim_cr(content->f_base,st.st_size);
+#endif
+       close(fd);
+       content->f_len = st.st_size+1;
+       content->f_p = content->f_base;
+       content->f_end = content->f_base + st.st_size;
+       *content->f_end = '\0';
+       content->f_line = 0;
+       return(content);
+}
+
+void
+freefile(fp)
+       struct filepointer      *fp;
+{
+       free(fp->f_base);
+       free(fp);
+}
+
+char *copy(str)
+       register char   *str;
+{
+       register char   *p = (char *)malloc(strlen(str) + 1);
+
+       strcpy(p, str);
+       return(p);
+}
+
+match(str, list)
+       register char   *str, **list;
+{
+       register int    i;
+
+       for (i=0; *list; i++, list++)
+               if (strcmp(str, *list) == 0)
+                       return(i);
+       return(-1);
+}
+
+/*
+ * Get the next line.  We only return lines beginning with '#' since that
+ * is all this program is ever interested in.
+ */
+char *x_getline(filep)
+       register struct filepointer     *filep;
+{
+       register char   *p,     /* walking pointer */
+                       *eof,   /* end of file pointer */
+                       *bol;   /* beginning of line pointer */
+       register int    lineno; /* line number */
+
+       p = filep->f_p;
+       eof = filep->f_end;
+       if (p >= eof)
+               return((char *)NULL);
+       lineno = filep->f_line;
+
+       for(bol = p--; ++p < eof; ) {
+               if (*p == '/' && *(p+1) == '*') { /* consume comments */
+                       *p++ = ' ', *p++ = ' ';
+                       while (*p) {
+                               if (*p == '*' && *(p+1) == '/') {
+                                       *p++ = ' ', *p = ' ';
+                                       break;
+                               }
+                               else if (*p == '\n')
+                                       lineno++;
+                               *p++ = ' ';
+                       }
+                       continue;
+               }
+#if defined(WIN32) || defined(__EMX__)
+               else if (*p == '/' && *(p+1) == '/') { /* consume comments */
+                       *p++ = ' ', *p++ = ' ';
+                       while (*p && *p != '\n')
+                               *p++ = ' ';
+                       lineno++;
+                       continue;
+               }
+#endif
+               else if (*p == '\\') {
+                       if (*(p+1) == '\n') {
+                               *p = ' ';
+                               *(p+1) = ' ';
+                               lineno++;
+                       }
+               }
+               else if (*p == '\n') {
+                       lineno++;
+                       if (*bol == '#') {
+                               register char *cp;
+
+                               *p++ = '\0';
+                               /* punt lines with just # (yacc generated) */
+                               for (cp = bol+1; 
+                                    *cp && (*cp == ' ' || *cp == '\t'); cp++);
+                               if (*cp) goto done;
+                       }
+                       bol = p+1;
+               }
+       }
+       if (*bol != '#')
+               bol = NULL;
+done:
+       filep->f_p = p;
+       filep->f_line = lineno;
+       return(bol);
+}
+
+/*
+ * Strip the file name down to what we want to see in the Makefile.
+ * It will have objprefix and objsuffix around it.
+ */
+char *base_name(file)
+       register char   *file;
+{
+       register char   *p;
+
+       file = copy(file);
+       for(p=file+strlen(file); p>file && *p != '.'; p--) ;
+
+       if (*p == '.')
+               *p = '\0';
+       return(file);
+}
+
+#if defined(USG) && !defined(CRAY) && !defined(SVR4) && !defined(__EMX__) && !defined(clipper) && !defined(__clipper__)
+int rename (from, to)
+    char *from, *to;
+{
+    (void) unlink (to);
+    if (link (from, to) == 0) {
+       unlink (from);
+       return 0;
+    } else {
+       return -1;
+    }
+}
+#endif /* USGISH */
+
+void
+redirect(line, makefile)
+       char    *line,
+               *makefile;
+{
+       struct stat     st;
+       FILE    *fdin, *fdout;
+       char    backup[ BUFSIZ ],
+               buf[ BUFSIZ ];
+       boolean found = FALSE;
+       int     len;
+
+       /*
+        * if makefile is "-" then let it pour onto stdout.
+        */
+       if (makefile && *makefile == '-' && *(makefile+1) == '\0') {
+               puts(line);
+               return;
+       }
+
+       /*
+        * use a default makefile is not specified.
+        */
+       if (!makefile) {
+               if (stat("Makefile", &st) == 0)
+                       makefile = "Makefile";
+               else if (stat("makefile", &st) == 0)
+                       makefile = "makefile";
+               else
+                       fatalerr("[mM]akefile is not present\n");
+       }
+       else
+           stat(makefile, &st);
+       if ((fdin = fopen(makefile, "r")) == NULL)
+               fatalerr("cannot open \"%s\"\n", makefile);
+       sprintf(backup, "%s.bak", makefile);
+       unlink(backup);
+#if defined(WIN32) || defined(__EMX__)
+       fclose(fdin);
+#endif
+       if (rename(makefile, backup) < 0)
+               fatalerr("cannot rename %s to %s\n", makefile, backup);
+#if defined(WIN32) || defined(__EMX__)
+       if ((fdin = fopen(backup, "r")) == NULL)
+               fatalerr("cannot open \"%s\"\n", backup);
+#endif
+       if ((fdout = freopen(makefile, "w", stdout)) == NULL)
+               fatalerr("cannot open \"%s\"\n", backup);
+       len = strlen(line);
+       while (!found && fgets(buf, BUFSIZ, fdin)) {
+               if (*buf == '#' && strncmp(line, buf, len) == 0)
+                       found = TRUE;
+               fputs(buf, fdout);
+       }
+       if (!found) {
+               if (verbose)
+               warning("Adding new delimiting line \"%s\" and dependencies...\n",
+                       line);
+               puts(line); /* same as fputs(fdout); but with newline */
+       } else if (append) {
+           while (fgets(buf, BUFSIZ, fdin)) {
+               fputs(buf, fdout);
+           }
+       }
+       fflush(fdout);
+#if defined(USGISH) || defined(_SEQUENT_) || defined(USE_CHMOD)
+       chmod(makefile, st.st_mode);
+#else
+        fchmod(fileno(fdout), st.st_mode);
+#endif /* USGISH */
+}
+
+void
+#if NeedVarargsPrototypes
+fatalerr(char *msg, ...)
+#else
+/*VARARGS*/
+fatalerr(msg,x1,x2,x3,x4,x5,x6,x7,x8,x9)
+    char *msg;
+#endif
+{
+#if NeedVarargsPrototypes
+       va_list args;
+#endif
+       fprintf(stderr, "%s: error:  ", ProgramName);
+#if NeedVarargsPrototypes
+       va_start(args, msg);
+       vfprintf(stderr, msg, args);
+       va_end(args);
+#else
+       fprintf(stderr, msg,x1,x2,x3,x4,x5,x6,x7,x8,x9);
+#endif
+       exit (1);
+}
+
+void
+#if NeedVarargsPrototypes
+warning(char *msg, ...)
+#else
+/*VARARGS0*/
+warning(msg,x1,x2,x3,x4,x5,x6,x7,x8,x9)
+    char *msg;
+#endif
+{
+#if NeedVarargsPrototypes
+       va_list args;
+#endif
+       fprintf(stderr, "%s: warning:  ", ProgramName);
+#if NeedVarargsPrototypes
+       va_start(args, msg);
+       vfprintf(stderr, msg, args);
+       va_end(args);
+#else
+       fprintf(stderr, msg,x1,x2,x3,x4,x5,x6,x7,x8,x9);
+#endif
+}
+
+void
+#if NeedVarargsPrototypes
+warning1(char *msg, ...)
+#else
+/*VARARGS0*/
+warning1(msg,x1,x2,x3,x4,x5,x6,x7,x8,x9)
+    char *msg;
+#endif
+{
+#if NeedVarargsPrototypes
+       va_list args;
+       va_start(args, msg);
+       vfprintf(stderr, msg, args);
+       va_end(args);
+#else
+       fprintf(stderr, msg,x1,x2,x3,x4,x5,x6,x7,x8,x9);
+#endif
+}
diff --git a/Xserver/config/makedepend/mkdepend.man b/Xserver/config/makedepend/mkdepend.man
new file mode 100644 (file)
index 0000000..d475e95
--- /dev/null
@@ -0,0 +1,373 @@
+.\" $XConsortium: mkdepend.man /main/19 1996/09/28 16:15:44 rws $
+.\" Copyright (c) 1993, 1994  X Consortium
+.\" 
+.\" Permission is hereby granted, free of charge, to any person obtaining a
+.\" copy of this software and associated documentation files (the "Software"), 
+.\" to deal in the Software without restriction, including without limitation 
+.\" the rights to use, copy, modify, merge, publish, distribute, sublicense, 
+.\" and/or sell copies of the Software, and to permit persons to whom the 
+.\" Software furnished to do so, subject to the following conditions:
+.\" 
+.\" The above copyright notice and this permission notice shall be included in
+.\" all copies or substantial portions of the Software.
+.\" 
+.\" THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+.\" IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+.\" FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL 
+.\" THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 
+.\" WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF 
+.\" OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 
+.\" SOFTWARE.
+.\" 
+.\" Except as contained in this notice, the name of the X Consortium shall not 
+.\" be used in advertising or otherwise to promote the sale, use or other 
+.\" dealing in this Software without prior written authorization from the 
+.\" X Consortium.
+.TH MAKEDEPEND 1 "Release 6.1" "X Version 11"
+.UC 4
+.SH NAME
+makedepend \- create dependencies in makefiles
+.SH SYNOPSIS
+.B makedepend
+[
+.BI \-D name\fB=\fPdef
+] [
+.BI \-D name
+] [
+.BI \-I includedir
+] [
+.BI \-Y includedir
+] [
+.B \-a
+] [
+.BI \-f makefile
+] [
+.BI \-o objsuffix
+] [
+.BI \-p objprefix
+] [
+.BI \-s string
+] [
+.BI \-w width
+] [
+.B \-v
+] [
+.B \-m
+] [
+\-\^\-
+.I otheroptions
+\-\^\-
+]
+.I sourcefile
+\&.\|.\|.
+.br
+.SH DESCRIPTION
+The
+.B makedepend
+program reads each
+.I sourcefile
+in sequence and parses it like a C-preprocessor,
+processing all
+.I #include,
+.I #define,
+.I #undef,
+.I #ifdef,
+.I #ifndef,
+.I #endif,
+.I #if,
+.I #elif
+and
+.I #else
+directives so that it can correctly tell which
+.I #include,
+directives would be used in a compilation.
+Any
+.I #include,
+directives can reference files having other
+.I #include
+directives, and parsing will occur in these files as well.
+.PP
+Every file that a
+.I sourcefile
+includes,
+directly or indirectly,
+is what
+.B makedepend
+calls a \fIdependency.\fP
+These dependencies are then written to a
+.I makefile
+in such a way that
+.B make(1)
+will know which object files must be recompiled when a dependency has changed.
+.PP
+By default,
+.B makedepend
+places its output in the file named
+.I makefile
+if it exists, otherwise
+.I Makefile.
+An alternate makefile may be specified with the
+.B \-f
+option.
+It first searches the makefile for
+the line
+.sp
+    # DO NOT DELETE THIS LINE \-\^\- make depend depends on it.
+.sp
+or one provided with the
+.B \-s
+option,
+as a delimiter for the dependency output.
+If it finds it, it will delete everything
+following this to the end of the makefile
+and put the output after this line.
+If it doesn't find it, the program
+will append the string to the end of the makefile
+and place the output following that.
+For each
+.I sourcefile
+appearing on the command line,
+.B makedepend
+puts lines in the makefile of the form
+.sp
+     sourcefile.o:\0dfile .\|.\|.
+.sp
+Where \fIsourcefile.o\fP is the name from the command
+line with its suffix replaced with ``.o'',
+and \fIdfile\fP is a dependency discovered in a
+.I #include
+directive while parsing
+.I sourcefile
+or one of the files it included.
+.SH EXAMPLE
+Normally,
+.B makedepend
+will be used in a makefile target so that typing ``make depend'' will
+bring the dependencies up to date for the makefile.
+For example,
+.nf
+    SRCS\0=\0file1.c\0file2.c\0.\|.\|.
+    CFLAGS\0=\0\-O\0\-DHACK\0\-I\^.\^.\^/foobar\0\-xyz
+    depend:
+            makedepend\0\-\^\-\0$(CFLAGS)\0\-\^\-\0$(SRCS)
+.fi
+.SH OPTIONS
+The program
+will ignore any option that it does not understand so that you may use
+the same arguments that you would for
+.B cc(1).
+.TP 5
+.B \-D\fIname\fP=\fIdef\fP \fRor\fP \-D\fIname\fP
+Define.
+This places a definition for
+.I name
+in
+.B makedepend's
+symbol table.
+Without 
+.I =def\|
+the symbol becomes defined as ``1''.
+.TP 5
+.B \-I\fIincludedir\fP
+Include directory.
+This option tells
+.B makedepend
+to prepend
+.I includedir
+to its list of directories to search when it encounters
+a
+.I #include
+directive.
+By default,
+.B makedepend
+only searches the standard include directories (usually /usr/include
+and possibly a compiler-dependent directory).
+.TP 5
+.B \-Y\fIincludedir\fP
+Replace all of the standard include directories with the single specified
+include directory; you can omit the
+.I includedir
+to simply prevent searching the standard include directories.
+.TP 5
+.B \-a
+Append the dependencies to the end of the file instead of replacing them. 
+.TP 5
+.B \-f\fImakefile\fP
+Filename.
+This allows you to specify an alternate makefile in which
+.B makedepend
+can place its output.
+Specifying ``\-'' as the file name (i.e., \fB\-f\-\fP) sends the
+output to standard output instead of modifying an existing file.
+.TP 5
+.B \-o\fIobjsuffix\fP
+Object file suffix.
+Some systems may have object files whose suffix is something other
+than ``.o''.
+This option allows you to specify another suffix, such as
+``.b'' with
+.I \-o.b
+or ``:obj''
+with
+.I \-o:obj
+and so forth.
+.TP 5
+.B \-p\fIobjprefix\fP
+Object file prefix.
+The prefix is prepended to the name of the object file. This is
+usually used to designate a different directory for the object file.
+The default is the empty string.
+.TP 5
+.B \-s\fIstring\fP
+Starting string delimiter.
+This option permits you to specify
+a different string for
+.B makedepend
+to look for in the makefile.
+.TP 5
+.B \-w\fIwidth\fP
+Line width.
+Normally,
+.B makedepend
+will ensure that every output line that it writes will be no wider than
+78 characters for the sake of readability.
+This option enables you to change this width.
+.TP 5
+.B \-v
+Verbose operation.
+This option causes 
+.B makedepend
+to emit the list of files included by each input file on standard output.
+.TP 5
+.B \-m
+Warn about multiple inclusion.
+This option causes 
+.B makedepend
+to produce a warning if any input file includes another file more than
+once.  In previous versions of 
+.B makedepend
+this was the default behavior; the default has been changed to better
+match the behavior of the C compiler, which does not consider multiple
+inclusion to be an error.  This option is provided for backward 
+compatibility, and to aid in debugging problems related to multiple
+inclusion.
+.TP 5
+.B "\-\^\- \fIoptions\fP \-\^\-"
+If
+.B makedepend
+encounters a double hyphen (\-\^\-) in the argument list,
+then any unrecognized argument following it
+will be silently ignored; a second double hyphen terminates this
+special treatment.
+In this way,
+.B makedepend
+can be made to safely ignore esoteric compiler arguments that might
+normally be found in a CFLAGS
+.B make
+macro (see the
+.B EXAMPLE
+section above).
+All options that
+.B makedepend
+recognizes and appear between the pair of double hyphens
+are processed normally.
+.SH ALGORITHM
+The approach used in this program enables it to run an order of magnitude
+faster than any other ``dependency generator'' I have ever seen.
+Central to this performance are two assumptions:
+that all files compiled by a single
+makefile will be compiled with roughly the same
+.I \-I
+and
+.I \-D
+options;
+and that most files in a single directory will include largely the
+same files.
+.PP
+Given these assumptions,
+.B makedepend
+expects to be called once for each makefile, with
+all source files that are maintained by the
+makefile appearing on the command line.
+It parses each source and include
+file exactly once, maintaining an internal symbol table
+for each.
+Thus, the first file on the command line will take an amount of time
+proportional to the amount of time that a normal C preprocessor takes.
+But on subsequent files, if it encounters an include file
+that it has already parsed, it does not parse it again.
+.PP
+For example,
+imagine you are compiling two files,
+.I file1.c
+and
+.I file2.c,
+they each include the header file
+.I header.h,
+and the file
+.I header.h
+in turn includes the files
+.I def1.h
+and
+.I def2.h.
+When you run the command
+.sp
+    makedepend\0file1.c\0file2.c
+.sp
+.B makedepend
+will parse
+.I file1.c
+and consequently,
+.I header.h
+and then
+.I def1.h
+and
+.I def2.h.
+It then decides that the dependencies for this file are
+.sp
+    file1.o:\0header.h\0def1.h\0def2.h
+.sp
+But when the program parses
+.I file2.c
+and discovers that it, too, includes
+.I header.h,
+it does not parse the file,
+but simply adds
+.I header.h,
+.I def1.h
+and
+.I def2.h
+to the list of dependencies for
+.I file2.o.
+.SH "SEE ALSO"
+cc(1), make(1)
+.SH BUGS
+.B makedepend
+parses, but does not currently evaluate, the SVR4
+#predicate(token-list) preprocessor expression;
+such expressions are simply assumed to be true.
+This may cause the wrong
+.I #include
+directives to be evaluated.
+.PP
+Imagine you are parsing two files,
+say
+.I file1.c
+and
+.I file2.c,
+each includes the file
+.I def.h.
+The list of files that
+.I def.h
+includes might truly be different when
+.I def.h
+is included by
+.I file1.c
+than when it is included by
+.I file2.c.
+But once
+.B makedepend
+arrives at a list of dependencies for a file,
+it is cast in concrete.
+.SH AUTHOR
+Todd Brunhoff, Tektronix, Inc. and MIT Project Athena
diff --git a/Xserver/config/makedepend/parse.c b/Xserver/config/makedepend/parse.c
new file mode 100644 (file)
index 0000000..2b3b164
--- /dev/null
@@ -0,0 +1,647 @@
+/* $XConsortium: parse.c /main/33 1996/12/04 10:11:28 swick $ */
+/*
+
+Copyright (c) 1993, 1994  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+*/
+/* $XFree86: xc/config/makedepend/parse.c,v 1.3 1997/01/12 10:39:45 dawes Exp $ */
+
+#include "def.h"
+
+extern char    *directives[];
+extern struct inclist  maininclist;
+
+int
+gobble(filep, file, file_red)
+       register struct filepointer *filep;
+       struct inclist          *file, *file_red;
+{
+       register char   *line;
+       register int    type;
+
+       while (line = x_getline(filep)) {
+               switch(type = deftype(line, filep, file_red, file, FALSE)) {
+               case IF:
+               case IFFALSE:
+               case IFGUESSFALSE:
+               case IFDEF:
+               case IFNDEF:
+                       type = gobble(filep, file, file_red);
+                       while ((type == ELIF) || (type == ELIFFALSE) ||
+                              (type == ELIFGUESSFALSE))
+                           type = gobble(filep, file, file_red);
+                       if (type == ELSE)
+                               (void)gobble(filep, file, file_red);
+                       break;
+               case ELSE:
+               case ENDIF:
+                       debug(0,("%s, line %d: #%s\n",
+                               file->i_file, filep->f_line,
+                               directives[type]));
+                       return(type);
+               case DEFINE:
+               case UNDEF:
+               case INCLUDE:
+               case INCLUDEDOT:
+               case PRAGMA:
+               case ERROR:
+               case IDENT:
+               case SCCS:
+               case EJECT:
+               case WARNING:
+                       break;
+               case ELIF:
+               case ELIFFALSE:
+               case ELIFGUESSFALSE:
+                       return(type);
+               case -1:
+                       warning("%s, line %d: unknown directive == \"%s\"\n",
+                               file_red->i_file, filep->f_line, line);
+                       break;
+               }
+       }
+       return(-1);
+}
+
+/*
+ * Decide what type of # directive this line is.
+ */
+int deftype (line, filep, file_red, file, parse_it)
+       register char   *line;
+       register struct filepointer *filep;
+       register struct inclist *file_red, *file;
+       int     parse_it;
+{
+       register char   *p;
+       char    *directive, savechar;
+       register int    ret;
+
+       /*
+        * Parse the directive...
+        */
+       directive=line+1;
+       while (*directive == ' ' || *directive == '\t')
+               directive++;
+
+       p = directive;
+       while (*p >= 'a' && *p <= 'z')
+               p++;
+       savechar = *p;
+       *p = '\0';
+       ret = match(directive, directives);
+       *p = savechar;
+
+       /* If we don't recognize this compiler directive or we happen to just
+        * be gobbling up text while waiting for an #endif or #elif or #else
+        * in the case of an #elif we must check the zero_value and return an
+        * ELIF or an ELIFFALSE.
+        */
+
+       if (ret == ELIF && !parse_it)
+       {
+           while (*p == ' ' || *p == '\t')
+               p++;
+           /*
+            * parse an expression.
+            */
+           debug(0,("%s, line %d: #elif %s ",
+                  file->i_file, filep->f_line, p));
+           ret = zero_value(p, filep, file_red);
+           if (ret != IF)
+           {
+               debug(0,("false...\n"));
+               if (ret == IFFALSE)
+                   return(ELIFFALSE);
+               else
+                   return(ELIFGUESSFALSE);
+           }
+           else
+           {
+               debug(0,("true...\n"));
+               return(ELIF);
+           }
+       }
+
+       if (ret < 0 || ! parse_it)
+               return(ret);
+
+       /*
+        * now decide how to parse the directive, and do it.
+        */
+       while (*p == ' ' || *p == '\t')
+               p++;
+       switch (ret) {
+       case IF:
+               /*
+                * parse an expression.
+                */
+               ret = zero_value(p, filep, file_red);
+               debug(0,("%s, line %d: %s #if %s\n",
+                        file->i_file, filep->f_line, ret?"false":"true", p));
+               break;
+       case IFDEF:
+       case IFNDEF:
+               debug(0,("%s, line %d: #%s %s\n",
+                       file->i_file, filep->f_line, directives[ret], p));
+       case UNDEF:
+               /*
+                * separate the name of a single symbol.
+                */
+               while (isalnum(*p) || *p == '_')
+                       *line++ = *p++;
+               *line = '\0';
+               break;
+       case INCLUDE:
+               debug(2,("%s, line %d: #include %s\n",
+                       file->i_file, filep->f_line, p));
+
+               /* Support ANSI macro substitution */
+               {
+                   struct symtab **sym = isdefined(p, file_red, NULL);
+                   while (sym) {
+                       p = (*sym)->s_value;
+                       debug(3,("%s : #includes SYMBOL %s = %s\n",
+                              file->i_incstring,
+                              (*sym) -> s_name,
+                              (*sym) -> s_value));
+                       /* mark file as having included a 'soft include' */
+                       file->i_flags |= INCLUDED_SYM; 
+                       sym = isdefined(p, file_red, NULL);
+                   }
+               }
+
+               /*
+                * Separate the name of the include file.
+                */
+               while (*p && *p != '"' && *p != '<')
+                       p++;
+               if (! *p)
+                       return(-2);
+               if (*p++ == '"') {
+                       ret = INCLUDEDOT;
+                       while (*p && *p != '"')
+                               *line++ = *p++;
+               } else
+                       while (*p && *p != '>')
+                               *line++ = *p++;
+               *line = '\0';
+               break;
+       case DEFINE:
+               /*
+                * copy the definition back to the beginning of the line.
+                */
+               strcpy (line, p);
+               break;
+       case ELSE:
+       case ENDIF:
+       case ELIF:
+       case PRAGMA:
+       case ERROR:
+       case IDENT:
+       case SCCS:
+       case EJECT:
+       case WARNING:
+               debug(0,("%s, line %d: #%s\n",
+                       file->i_file, filep->f_line, directives[ret]));
+               /*
+                * nothing to do.
+                */
+               break;
+       }
+       return(ret);
+}
+
+struct symtab **fdefined(symbol, file, srcfile)
+       register char   *symbol;
+       struct inclist  *file;
+       struct inclist  **srcfile;
+{
+       register struct inclist **ip;
+       register struct symtab  **val;
+       register int    i;
+       static int      recurse_lvl = 0;
+
+       if (file->i_flags & DEFCHECKED)
+               return(NULL);
+       file->i_flags |= DEFCHECKED;
+       if (val = slookup(symbol, file))
+               debug(1,("%s defined in %s as %s\n",
+                        symbol, file->i_file, (*val)->s_value));
+       if (val == NULL && file->i_list)
+               {
+               for (ip = file->i_list, i=0; i < file->i_listlen; i++, ip++)
+                       if (file->i_merged[i]==FALSE) {
+                               val = fdefined(symbol, *ip, srcfile);
+                               if ((*ip)->i_flags & FINISHED) {
+                                       merge2defines(file,*ip);
+                                       file->i_merged[i]=TRUE;
+                                   }
+                               if (val!=NULL) break;
+                       }
+               }
+       else if (val != NULL && srcfile != NULL) *srcfile = file;
+       recurse_lvl--;
+       file->i_flags &= ~DEFCHECKED;
+
+       return(val);
+}
+
+struct symtab **isdefined(symbol, file, srcfile)
+       register char   *symbol;
+       struct inclist  *file;
+       struct inclist  **srcfile;
+{
+       register struct symtab  **val;
+
+       if (val = slookup(symbol, &maininclist)) {
+               debug(1,("%s defined on command line\n", symbol));
+               if (srcfile != NULL) *srcfile = &maininclist;
+               return(val);
+       }
+       if (val = fdefined(symbol, file, srcfile))
+               return(val);
+       debug(1,("%s not defined in %s\n", symbol, file->i_file));
+       return(NULL);
+}
+
+/*
+ * Return type based on if the #if expression evaluates to 0
+ */
+int
+zero_value(exp, filep, file_red)
+       register char   *exp;
+       register struct filepointer *filep;
+       register struct inclist *file_red;
+{
+       if (cppsetup(exp, filep, file_red))
+           return(IFFALSE);
+       else
+           return(IF);
+}
+
+void
+define2(name, val, file)
+       char    *name, *val;
+       struct inclist  *file;
+{
+    int first, last, below;
+    register struct symtab **sp = NULL, **dest;
+    struct symtab *stab;
+
+    /* Make space if it's needed */
+    if (file->i_defs == NULL)
+    {
+       file->i_defs = (struct symtab **)
+                       malloc(sizeof (struct symtab*) * SYMTABINC);
+       file->i_ndefs = 0;
+    }
+    else if (!(file->i_ndefs % SYMTABINC))
+       file->i_defs = (struct symtab **)
+                       realloc(file->i_defs,
+                          sizeof(struct symtab*)*(file->i_ndefs+SYMTABINC));
+
+    if (file->i_defs == NULL)
+       fatalerr("malloc()/realloc() failure in insert_defn()\n");
+
+    below = first = 0;
+    last = file->i_ndefs - 1;
+    while (last >= first)
+    {
+       /* Fast inline binary search */
+       register char *s1;
+       register char *s2;
+       register int middle = (first + last) / 2;
+
+       /* Fast inline strchr() */
+       s1 = name;
+       s2 = file->i_defs[middle]->s_name;
+       while (*s1++ == *s2++)
+           if (s2[-1] == '\0') break;
+
+       /* If exact match, set sp and break */
+       if (*--s1 == *--s2) 
+       {
+           sp = file->i_defs + middle;
+           break;
+       }
+
+       /* If name > i_defs[middle] ... */
+       if (*s1 > *s2) 
+       {
+           below = first;
+           first = middle + 1;
+       }
+       /* else ... */
+       else
+       {
+           below = last = middle - 1;
+       }
+    }
+
+    /* Search is done.  If we found an exact match to the symbol name,
+       just replace its s_value */
+    if (sp != NULL)
+    {
+       free((*sp)->s_value);
+       (*sp)->s_value = copy(val);
+       return;
+    }
+
+    sp = file->i_defs + file->i_ndefs++;
+    dest = file->i_defs + below + 1;
+    while (sp > dest)
+    {
+       *sp = sp[-1];
+       sp--;
+    }
+    stab = (struct symtab *) malloc(sizeof (struct symtab));
+    if (stab == NULL)
+       fatalerr("malloc()/realloc() failure in insert_defn()\n");
+
+    stab->s_name = copy(name);
+    stab->s_value = copy(val);
+    *sp = stab;
+}
+
+void
+define(def, file)
+       char    *def;
+       struct inclist  *file;
+{
+    char *val;
+
+    /* Separate symbol name and its value */
+    val = def;
+    while (isalnum(*val) || *val == '_')
+       val++;
+    if (*val)
+       *val++ = '\0';
+    while (*val == ' ' || *val == '\t')
+       val++;
+
+    if (!*val)
+       val = "1";
+    define2(def, val, file);
+}
+
+struct symtab **slookup(symbol, file)
+       register char   *symbol;
+       register struct inclist *file;
+{
+       register int first = 0;
+       register int last = file->i_ndefs - 1;
+
+       if (file) while (last >= first)
+       {
+           /* Fast inline binary search */
+           register char *s1;
+           register char *s2;
+           register int middle = (first + last) / 2;
+
+           /* Fast inline strchr() */
+           s1 = symbol;
+           s2 = file->i_defs[middle]->s_name;
+           while (*s1++ == *s2++)
+               if (s2[-1] == '\0') break;
+
+           /* If exact match, we're done */
+           if (*--s1 == *--s2) 
+           {
+               return file->i_defs + middle;
+           }
+
+           /* If symbol > i_defs[middle] ... */
+           if (*s1 > *s2) 
+           {
+               first = middle + 1;
+           }
+           /* else ... */
+           else
+           {
+               last = middle - 1;
+           }
+       }
+       return(NULL);
+}
+
+int merge2defines(file1, file2)
+       struct inclist  *file1;
+       struct inclist  *file2;
+{
+       if ((file1!=NULL) && (file2!=NULL)) 
+        {
+               int first1 = 0;
+               int last1 = file1->i_ndefs - 1;
+
+               int first2 = 0;
+               int last2 = file2->i_ndefs - 1;
+
+                int first=0;
+                struct symtab** i_defs = NULL;
+               int deflen=file1->i_ndefs+file2->i_ndefs;
+
+                if (deflen>0)
+                { 
+                       /* make sure deflen % SYMTABINC == 0 is still true */
+                       deflen += (SYMTABINC - deflen % SYMTABINC) % SYMTABINC;
+                       i_defs=(struct symtab**)
+                           malloc(deflen*sizeof(struct symtab*));
+                       if (i_defs==NULL) return 0;
+               }
+
+               while ((last1 >= first1) && (last2 >= first2))
+               {
+                       char *s1=file1->i_defs[first1]->s_name;
+                       char *s2=file2->i_defs[first2]->s_name;
+
+                       if (strcmp(s1,s2) < 0)
+                               i_defs[first++]=file1->i_defs[first1++];
+                       else if (strcmp(s1,s2) > 0)
+                               i_defs[first++]=file2->i_defs[first2++];
+                        else /* equal */
+                        {
+                               i_defs[first++]=file2->i_defs[first2++];
+                                first1++;
+                        }
+               }
+               while (last1 >= first1)
+               {
+                        i_defs[first++]=file1->i_defs[first1++];
+               }
+               while (last2 >= first2)
+               {
+                        i_defs[first++]=file2->i_defs[first2++];
+               }
+
+                if (file1->i_defs) free(file1->i_defs);
+                file1->i_defs=i_defs;
+                file1->i_ndefs=first;
+                
+               return 1;
+       }
+       return 0;
+}
+
+void
+undefine(symbol, file)
+       char    *symbol;
+       register struct inclist *file;
+{
+       register struct symtab **ptr;
+       struct inclist *srcfile;
+       while ((ptr = isdefined(symbol, file, &srcfile)) != NULL)
+       {
+           srcfile->i_ndefs--;
+           for (; ptr < srcfile->i_defs + srcfile->i_ndefs; ptr++)
+               *ptr = ptr[1];
+       }
+}
+
+int
+find_includes(filep, file, file_red, recursion, failOK)
+       struct filepointer      *filep;
+       struct inclist          *file, *file_red;
+       int                     recursion;
+       boolean                 failOK;
+{
+       register char   *line;
+       register int    type;
+       boolean recfailOK;
+
+       while (line = x_getline(filep)) {
+               switch(type = deftype(line, filep, file_red, file, TRUE)) {
+               case IF:
+               doif:
+                       type = find_includes(filep, file,
+                               file_red, recursion+1, failOK);
+                       while ((type == ELIF) || (type == ELIFFALSE) ||
+                              (type == ELIFGUESSFALSE))
+                               type = gobble(filep, file, file_red);
+                       if (type == ELSE)
+                               gobble(filep, file, file_red);
+                       break;
+               case IFFALSE:
+               case IFGUESSFALSE:
+                   doiffalse:
+                       if (type == IFGUESSFALSE || type == ELIFGUESSFALSE)
+                           recfailOK = TRUE;
+                       else
+                           recfailOK = failOK;
+                       type = gobble(filep, file, file_red);
+                       if (type == ELSE)
+                           find_includes(filep, file,
+                                         file_red, recursion+1, recfailOK);
+                       else
+                       if (type == ELIF)
+                           goto doif;
+                       else
+                       if ((type == ELIFFALSE) || (type == ELIFGUESSFALSE))
+                           goto doiffalse;
+                       break;
+               case IFDEF:
+               case IFNDEF:
+                       if ((type == IFDEF && isdefined(line, file_red, NULL))
+                        || (type == IFNDEF && !isdefined(line, file_red, NULL))) {
+                               debug(1,(type == IFNDEF ?
+                                   "line %d: %s !def'd in %s via %s%s\n" : "",
+                                   filep->f_line, line,
+                                   file->i_file, file_red->i_file, ": doit"));
+                               type = find_includes(filep, file,
+                                       file_red, recursion+1, failOK);
+                               while (type == ELIF || type == ELIFFALSE || type == ELIFGUESSFALSE)
+                                       type = gobble(filep, file, file_red);
+                               if (type == ELSE)
+                                       gobble(filep, file, file_red);
+                       }
+                       else {
+                               debug(1,(type == IFDEF ?
+                                   "line %d: %s !def'd in %s via %s%s\n" : "",
+                                   filep->f_line, line,
+                                   file->i_file, file_red->i_file, ": gobble"));
+                               type = gobble(filep, file, file_red);
+                               if (type == ELSE)
+                                       find_includes(filep, file,
+                                               file_red, recursion+1, failOK);
+                               else if (type == ELIF)
+                                       goto doif;
+                               else if (type == ELIFFALSE || type == ELIFGUESSFALSE)
+                                       goto doiffalse;
+                       }
+                       break;
+               case ELSE:
+               case ELIFFALSE:
+               case ELIFGUESSFALSE:
+               case ELIF:
+                       if (!recursion)
+                               gobble(filep, file, file_red);
+               case ENDIF:
+                       if (recursion)
+                               return(type);
+               case DEFINE:
+                       define(line, file);
+                       break;
+               case UNDEF:
+                       if (!*line) {
+                           warning("%s, line %d: incomplete undef == \"%s\"\n",
+                               file_red->i_file, filep->f_line, line);
+                           break;
+                       }
+                       undefine(line, file_red);
+                       break;
+               case INCLUDE:
+                       add_include(filep, file, file_red, line, FALSE, failOK);
+                       break;
+               case INCLUDEDOT:
+                       add_include(filep, file, file_red, line, TRUE, failOK);
+                       break;
+               case ERROR:
+               case WARNING:
+                       warning("%s: %d: %s\n", file_red->i_file,
+                                filep->f_line, line);
+                       break;
+                   
+               case PRAGMA:
+               case IDENT:
+               case SCCS:
+               case EJECT:
+                       break;
+               case -1:
+                       warning("%s", file_red->i_file);
+                       if (file_red != file)
+                           warning1(" (reading %s)", file->i_file);
+                       warning1(", line %d: unknown directive == \"%s\"\n",
+                                filep->f_line, line);
+                       break;
+               case -2:
+                       warning("%s", file_red->i_file);
+                       if (file_red != file)
+                           warning1(" (reading %s)", file->i_file);
+                       warning1(", line %d: incomplete include == \"%s\"\n",
+                                filep->f_line, line);
+                       break;
+               }
+       }
+       file->i_flags |= FINISHED;
+       return(-1);
+}
diff --git a/Xserver/config/makedepend/pr.c b/Xserver/config/makedepend/pr.c
new file mode 100644 (file)
index 0000000..7c4ecd6
--- /dev/null
@@ -0,0 +1,130 @@
+/* $XConsortium: pr.c /main/20 1996/12/04 10:11:41 swick $ */
+/*
+
+Copyright (c) 1993, 1994  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+*/
+
+#include "def.h"
+
+extern struct  inclist inclist[ MAXFILES ],
+                       *inclistp;
+extern char    *objprefix;
+extern char    *objsuffix;
+extern int     width;
+extern boolean printed;
+extern boolean verbose;
+extern boolean show_where_not;
+
+void
+add_include(filep, file, file_red, include, dot, failOK)
+       struct filepointer      *filep;
+       struct inclist  *file, *file_red;
+       char    *include;
+       boolean dot;
+{
+       register struct inclist *newfile;
+       register struct filepointer     *content;
+
+       /*
+        * First decide what the pathname of this include file really is.
+        */
+       newfile = inc_path(file->i_file, include, dot);
+       if (newfile == NULL) {
+               if (failOK)
+                   return;
+               if (file != file_red)
+                       warning("%s (reading %s, line %d): ",
+                               file_red->i_file, file->i_file, filep->f_line);
+               else
+                       warning("%s, line %d: ", file->i_file, filep->f_line);
+               warning1("cannot find include file \"%s\"\n", include);
+               show_where_not = TRUE;
+               newfile = inc_path(file->i_file, include, dot);
+               show_where_not = FALSE;
+       }
+
+       if (newfile) {
+               included_by(file, newfile);
+               if (!(newfile->i_flags & SEARCHED)) {
+                       newfile->i_flags |= SEARCHED;
+                       content = getfile(newfile->i_file);
+                       find_includes(content, newfile, file_red, 0, failOK);
+                       freefile(content);
+               }
+       }
+}
+
+void
+pr(ip, file, base)
+       register struct inclist  *ip;
+       char    *file, *base;
+{
+       static char     *lastfile;
+       static int      current_len;
+       register int    len, i;
+       char    buf[ BUFSIZ ];
+
+       printed = TRUE;
+       len = strlen(ip->i_file)+1;
+       if (current_len + len > width || file != lastfile) {
+               lastfile = file;
+               sprintf(buf, "\n%s%s%s: %s", objprefix, base, objsuffix,
+                       ip->i_file);
+               len = current_len = strlen(buf);
+       }
+       else {
+               buf[0] = ' ';
+               strcpy(buf+1, ip->i_file);
+               current_len += len;
+       }
+       fwrite(buf, len, 1, stdout);
+
+       /*
+        * If verbose is set, then print out what this file includes.
+        */
+       if (! verbose || ip->i_list == NULL || ip->i_flags & NOTIFIED)
+               return;
+       ip->i_flags |= NOTIFIED;
+       lastfile = NULL;
+       printf("\n# %s includes:", ip->i_file);
+       for (i=0; i<ip->i_listlen; i++)
+               printf("\n#\t%s", ip->i_list[ i ]->i_incstring);
+}
+
+void
+recursive_pr_include(head, file, base)
+       register struct inclist *head;
+       register char   *file, *base;
+{
+       register int    i;
+
+       if (head->i_flags & MARKED)
+               return;
+       head->i_flags |= MARKED;
+       if (head->i_file != file)
+               pr(head, file, base);
+       for (i=0; i<head->i_listlen; i++)
+               recursive_pr_include(head->i_list[ i ], file, base);
+}
diff --git a/Xserver/config/util/Imakefile b/Xserver/config/util/Imakefile
new file mode 100644 (file)
index 0000000..a51b8e9
--- /dev/null
@@ -0,0 +1,101 @@
+XCOMM $XConsortium: Imakefile /main/16 1996/11/13 14:43:28 lehors $
+XCOMM $XFree86: xc/config/util/Imakefile,v 3.15 1996/12/23 05:56:12 dawes Exp $
+
+#if UseCCMakeDepend
+MDEP_PROG = makedepend
+#endif
+
+#ifdef ExportListGenSource
+EXPORTLISTGEN = exportlistgen
+#endif
+
+#ifdef Win32Architecture
+CMKDIRHIER = mkdirhier.exe
+#endif
+
+#ifndef OS2Architecture
+GCCMDEP_PROG = gccmakedep
+#endif
+
+PROGRAMS = xmkmf $(MDEP_PROG) $(GCCMDEP_PROG) mergelib ProgramTargetName(makestrs) $(EXPORTLISTGEN) $(CMKDIRHIER)
+DEPLIBS =
+#ifndef Win32Architecture
+  EXTRA_LIBRARIES =
+#endif
+
+XCOMM Some compilers generate fatal errors if an -L directory does
+XCOMM not exist.  Since BUILDLIBDIR may not exist yet suppress its use.
+         LDPRELIB =
+        LDPRELIBS =
+
+all:: $(PROGRAMS)
+
+#if HasGcc
+GCCCMD = $(CC)
+#else
+GCCCMD = gcc
+#endif
+
+includes:: ProgramTargetName(makestrs)
+
+#ifdef ExportListGenSource
+CppScriptTarget(exportlistgen,ExportListGenSource,-DCXXFILT=$(CXXFILT),)
+InstallNamedProg(exportlistgen,exportlistgen,$(BINDIR))
+#endif
+
+CppScriptTarget(xmkmf,xmkmf.cpp,-DCONFIGDIRSPEC='"'"-I$(CONFIGDIR)"'"',$(ICONFIGFILES))
+CppScriptTarget(makedepend,mdepend.cpp,-DPREPROC='"'"$(PREPROCESSCMD)"'"',$(ICONFIGFILES))
+CppScriptTarget(mergelib,mergelib.cpp,"-DARCMD=$(AR)" "-DRANLIB=$(RANLIB)",$(ICONFIGFILES))
+#ifndef OS2Architecture
+CppScriptTarget(gccmakedep,gccmdep.cpp,-DCCCMD='"'"$(GCCCMD)"'"' -DRMCMD='"'"$(RM)"'"' -DLNCMD='"'"$(LN)"'"' -DMVCMD='"'"$(MV)"'"',$(ICONFIGFILES))
+#endif
+
+#if HasSymLinks
+#if CrossCompiling
+SimpleHostProgramTarget(lndir)
+#else
+SimpleProgramTarget(lndir)
+#endif
+#endif
+
+#ifdef Win32Architecture
+SimpleProgramTarget(mkdirhier)
+#endif
+
+NormalProgramTarget(makestrs,makestrs.o,,,)
+
+InstallManPage(makestrs,$(MANDIR))
+
+InstallManPage(xmkmf,$(MANDIR))
+
+#if defined(OS2Architecture)
+includes:: makestrs.exe
+       ImakeHelper 7 makestrs.exe /makestrs.exe
+
+InstallNamedProg(mkdirhier.cmd,mkdirhier.cmd,$(BINDIR))
+InstallNamedProg(indir.cmd,indir.cmd,$(BINDIR))
+InstallNamedProg(os2inst.cmd,os2inst.cmd,$(BINDIR))
+InstallNamedProg(xmkmf.cmd,xmkmf.cmd,$(BINDIR))
+InstallNamedProg(xmake.cmd,make.cmd,$(BINDIR))
+InstallLinkKitNamedProg(mkdirhier.cmd,mkdirhier.cmd,$(LINKKITDIR)/config/util)
+InstallLinkKitNamedProg(indir.cmd,indir.cmd,$(LINKKITDIR)/config/util)
+InstallLinkKitNamedProg(os2inst.cmd,os2inst.cmd,$(LINKKITDIR)/config/util)
+#else
+InstallNamedProg(xmkmf,xmkmf,$(BINDIR))
+InstallNamedProg(mkdirhier.sh,mkdirhier,$(BINDIR))
+InstallNamedProg(gccmakedep,gccmakedep,$(BINDIR))
+InstallLinkKitNamedProg(mkdirhier.sh,mkdirhier.sh,$(LINKKITDIR)/config/util)
+InstallLinkKitNamedProg(gccmakedep,gccmakedep,$(LINKKITDIR)/config/util)
+InstallNamedProg(mergelib,mergelib,$(BINDIR))
+InstallNamedProg(makeg.sh,makeg,$(BINDIR))
+InstallManPage(makeg,$(MANDIR))
+#endif
+InstallManPage(mkdirhier,$(MANDIR))
+#if UseCCMakeDepend
+InstallNamedProg(makedepend,makedepend,$(BINDIR))
+InstallLinkKitNamedProg(makedepend,makedepend,$(LINKKITDIR)/config/util)
+#endif
+#if SystemV || SystemV4
+InstallNamedProg(bsdinst.sh,bsdinst,$(BINDIR))
+InstallLinkKitNamedProg(bsdinst.sh,bsdinst.sh,$(LINKKITDIR)/config/util)
+#endif
diff --git a/Xserver/config/util/Makefile.ini b/Xserver/config/util/Makefile.ini
new file mode 100644 (file)
index 0000000..5b8d1f4
--- /dev/null
@@ -0,0 +1,20 @@
+# $XConsortium: Makefile.ini,v 1.2 94/04/17 14:55:28 gildea Exp $
+#
+# A way to get lndir built the first time, before you have imake up
+# and running.  You may well have to specify OSFLAGS=-D<something> to
+# get it to compile, which values are embedded in config files.  What
+# you would pass as BOOTSTRAPCFLAGS might work.
+
+OSFLAGS = 
+CC = cc
+CDEBUGFLAGS = -O
+INCLUDES = -I.
+CFLAGS = $(OSFLAGS) $(CDEBUGFLAGS) $(INCLUDES)
+SHELL = /bin/sh
+RM = rm -f
+LN = ln -s
+
+lndir:
+       $(LN) ../../include X11
+       $(CC) -o lndir $(CFLAGS) lndir.c
+       $(RM) X11
diff --git a/Xserver/config/util/added.cmd b/Xserver/config/util/added.cmd
new file mode 100644 (file)
index 0000000..aa63f16
--- /dev/null
@@ -0,0 +1,23 @@
+/* OS/2 REXX script to create nonexisting directories
+ * run with 'added dirlist_file'
+ * where dirlist_file is a XFree86 added-* file
+ *
+ * $XFree86: xc/config/util/added.cmd,v 3.0 1994/10/20 06:01:00 dawes Exp $
+ */
+
+file = arg(1)
+linein(file,1,0)
+curdir = directory()
+do while lines(file)=1
+  fs = strip(filespec("path",linein(file)),'t','/')
+  newdir = directory(fs)
+  if newdir='' then do
+    say 'create directory='fs
+    call directory(curdir)
+    call 'xc\config\util\mkdirhier.cmd' fs
+  end 
+  else do
+    say 'found directory='newdir
+    call directory(curdir)
+  end
+end
diff --git a/Xserver/config/util/aminstall.sh b/Xserver/config/util/aminstall.sh
new file mode 100644 (file)
index 0000000..6a8def3
--- /dev/null
@@ -0,0 +1,74 @@
+#!/bin/sh
+# $XConsortium: aminstall.sh,v 1.1 94/03/29 15:54:08 gildea Exp $
+# aminstall - transfer cross-compiled files to system running Amoeba.
+# Usage: aminstall binary-directory [-s stksz] unix-source amoeba-dest
+
+#
+# Default soap mask for files
+#
+SPMASK=0xFF:2:2
+export SPMASK
+PROG=$0
+USAGE="Usage: $PROG binary-directory unix-source amoeba-dest"
+
+#
+# Argument check
+#
+case $# in
+3|5)   ;;
+*)     echo $USAGE >&2
+       exit 1
+       ;;
+esac
+
+bindir=$1
+stksz=
+case $2 in
+-s)    if [ $# -ne 5 ]
+       then
+           echo $USAGE >&2
+           exit 1
+       fi
+       stksz="-s $3"
+       shift
+       shift
+       ;;
+esac
+
+unxfile=$2
+dest=$3
+
+#
+# Change /public .... into /super (just for installation)
+#
+stripped=`echo $dest | sed 's:^/public::'`
+if [ X$dest != X$stripped ]; then
+    dest=/super$stripped
+fi
+
+#
+# If the file already exists, then delete it
+#
+INFO=`$bindir/std_info $dest 2>&1`
+case $INFO in
+*"not found"*) ;;
+*failed*)      ;;
+*bytes*)       $bindir/del -f $dest
+               ;;
+/??????)       echo $PROG: cannot install over directory 1>&2
+               exit
+               ;;
+*)             $bindir/del -d $dest
+               ;;
+esac
+
+#
+# Transfer the file to Amoeba
+#
+$bindir/../bin.scripts/ainstall $stksz $unxfile $dest > /dev/null 2>&1
+if [ $? -ne 0 ]
+then
+       echo "This is not binary - using tob"
+       $bindir/tob $unxfile $dest
+fi
+
diff --git a/Xserver/config/util/bsdinst.sh b/Xserver/config/util/bsdinst.sh
new file mode 100755 (executable)
index 0000000..3ac7afa
--- /dev/null
@@ -0,0 +1,168 @@
+#!/bin/sh
+
+# $XFree86: xc/config/util/bsdinst.sh,v 3.3 1996/12/23 05:56:13 dawes Exp $
+#
+# This accepts bsd-style install arguments and makes the appropriate calls
+# to the System V install.
+# $XConsortium: bsdinst.sh /main/8 1996/09/28 16:16:11 rws $
+
+flags=""
+dst=""
+src=""
+dostrip=""
+owner=""
+group=""
+mode=""
+bargs=$*
+
+while [ x$1 != x ]; do
+    case $1 in 
+       -c) shift
+           continue;;
+
+       -m) flags="$flags $1 $2 "
+           mode="$2"
+           shift
+           shift
+           continue;;
+
+       -o) flags="$flags -u $2 "
+           owner="$2"
+           shift
+           shift
+           continue;;
+
+       -g) flags="$flags $1 $2 "
+           group="$2"
+           shift
+           shift
+           continue;;
+
+       -s) dostrip="strip"
+           shift
+           continue;;
+
+       *)  if [ x$src = x ] 
+           then
+               src=$1
+           else
+               dst=$1
+           fi
+           shift
+           continue;;
+    esac
+done
+
+if [ x$src = x ] 
+then
+       echo "$0:  no input file specified"
+       exit 1
+fi
+
+if [ x$dst = x ] 
+then
+       echo "$0:  no destination specified"
+       exit 1
+fi
+
+if [ -x /usr/ucb/install ]
+then
+       if [ -d "$dst" ]
+       then
+               dst=$dst/`basename "$src"`
+       fi
+       case "$group" in
+       "")
+               bargs="-g other $bargs"
+               ;;
+       esac
+       /usr/ucb/install $bargs
+       if [ x$dostrip = xstrip -a -x /usr/bin/mcs ]
+       then
+               /usr/bin/mcs -d $dst
+       fi
+       exit 0
+fi
+       
+case "$mode" in
+"")
+       ;;
+*)
+       case "$owner" in
+       "")
+               flags="$flags -u root"
+               ;;
+       esac
+       ;;
+esac
+
+
+# set up some variable to be used later
+
+rmcmd=""
+srcdir="."
+
+# if the destination isn't a directory we'll need to copy it first
+
+if [ ! -d $dst ]
+then
+       dstbase=`basename $dst`
+       cp $src /tmp/$dstbase
+       rmcmd="rm -f /tmp/$dstbase"
+       src=$dstbase
+       srcdir=/tmp
+       dst="`echo $dst | sed 's,^\(.*\)/.*$,\1,'`"
+       if [ x$dst = x ]
+       then
+               dst="."
+       fi
+fi
+
+
+# If the src file has a directory, copy it to /tmp to make install happy
+
+srcbase=`basename $src`
+
+if [ "$src" != "$srcbase" ] && [ "$src" != "./$srcbase" ] 
+then
+       cp $src /tmp/$srcbase
+       src=$srcbase
+       srcdir=/tmp
+       rmcmd="rm -f /tmp/$srcbase"
+fi
+
+# do the actual install
+
+if [ -f /usr/sbin/install ]
+then
+       installcmd=/usr/sbin/install
+elif [ -f /etc/install ]
+then
+       installcmd=/etc/install
+else
+       installcmd=install
+fi
+
+# This rm is commented out because some people want to be able to
+# install through symbolic links.  Uncomment it if it offends you.
+# rm -f $dst/$srcbase
+(cd $srcdir ; $installcmd -f $dst $flags $src)
+
+if [ x$dostrip = xstrip ]
+then
+       strip $dst/$srcbase
+       if [ -x /usr/bin/mcs ]
+       then
+               /usr/bin/mcs -d $dst/$srcbase
+       fi
+fi
+
+if [ x$mode != x ]
+then
+       chmod $mode $dst/$srcbase
+fi
+
+# and clean up
+
+$rmcmd
+
diff --git a/Xserver/config/util/buildos2.cmd b/Xserver/config/util/buildos2.cmd
new file mode 100644 (file)
index 0000000..b2c6978
--- /dev/null
@@ -0,0 +1,110 @@
+/* REXX */
+/* $XFree86: xc/config/util/buildos2.cmd,v 3.7.2.1 1997/05/12 12:52:09 hohndel Exp $
+ * this file is supposed to run from the xc/ dir.
+ * you must copy it manually to there before using. It is just here
+ * in order not to be in the root dir.
+ *
+ * copy some essential files to a location where we find them again
+ */
+'@echo off'
+env = 'OS2ENVIRONMENT'
+'copy config\util\indir.cmd \ > nul 2>&1'
+'copy config\util\mkdirhier.cmd \ > nul 2>&1'
+'copy config\imake\imakesvc.cmd \ > nul 2>&1'
+
+IF \ exists('config\cf\host.def') THEN
+    CALL LINEOUT 'config\cf\host.def',' '
+
+CALL create_makefile
+
+CALL VALUE 'GCCOPT','-pipe',env
+CALL VALUE 'EMXLOAD',5,env
+CALL VALUE 'MAKEFLAGS','--no-print-directory',env
+'emxload -e x11make.exe rm.exe mv.exe'
+'emxload -e -gcc -omf'
+
+'x11make MAKE=x11make SHELL= MFLAGS="MAKE=x11make CC=gcc BOOTSTRAPCFLAGS=-DBSD43 SHELL= " World.OS2 2>&1 | tee buildxc.log'
+
+EXIT
+
+/* returns 1, if file exists */
+exists:
+       IF STREAM(arg(1), 'C', 'QUERY EXISTS') = '' THEN
+               RETURN 0
+       ELSE
+               RETURN 1
+
+create_makefile:
+IF exists(Makefile) THEN del Makefile
+CALL LINEOUT 'Makefile','RELEASE = "Release 6.3"',1
+CALL LINEOUT 'Makefile','SHELL = /bin/sh'
+CALL LINEOUT 'Makefile','RM = rm -f'
+CALL LINEOUT 'Makefile','MV = mv'
+CALL LINEOUT 'Makefile','WORLDOPTS = -k'
+CALL LINEOUT 'Makefile','TOP = .'
+CALL LINEOUT 'Makefile','CURRENT_DIR = .'
+CALL LINEOUT 'Makefile','CONFIGSRC = $(TOP)/config'
+CALL LINEOUT 'Makefile','IMAKESRC = $(CONFIGSRC)/imake'
+CALL LINEOUT 'Makefile','DEPENDSRC = $(CONFIGSRC)/makedepend'
+CALL LINEOUT 'Makefile','DEPENDTOP = ../..'
+CALL LINEOUT 'Makefile','IMAKETOP = ../..'
+CALL LINEOUT 'Makefile','IRULESRC = $(CONFIGSRC)/cf'
+CALL LINEOUT 'Makefile','IMAKE = $(IMAKESRC)/imake'
+CALL LINEOUT 'Makefile','IMAKE_CMD = $(IMAKE) -I$(IRULESRC) $(IMAKE_DEFINES)'
+CALL LINEOUT 'Makefile','MAKE_OPTS = '
+CALL LINEOUT 'Makefile','MAKE_CMD = $(MAKE) $(MAKE_OPTS)'
+CALL LINEOUT 'Makefile','FLAGS = $(MFLAGS) -f Makefile.ini BOOTSTRAPCFLAGS="$(BOOTSTRAPCFLAGS)"'
+CALL LINEOUT 'Makefile',' '
+CALL LINEOUT 'Makefile','World.OS2:'
+CALL LINEOUT 'Makefile','      @echo :'
+CALL LINEOUT 'Makefile','      @echo Building $(RELEASE) of the X Window System on OS/2.'
+CALL LINEOUT 'Makefile','      @echo :'
+CALL LINEOUT 'Makefile','      @echo :'
+CALL LINEOUT 'Makefile','      \indir $(IMAKESRC) $(MAKE) SHELL= -f Makefile.ini clean.os2'
+CALL LINEOUT 'Makefile','      \indir $(IMAKESRC) $(MAKE) SHELL= CC=gcc -f Makefile.ini imake.os2'
+CALL LINEOUT 'Makefile','      -if exist Makefile.bak del Makefile.bak'
+CALL LINEOUT 'Makefile','      -if exist Makefile ren Makefile Makefile.bak'
+CALL LINEOUT 'Makefile','      $(subst /,\,$(IMAKE)) -I$(IRULESRC) $(IMAKE_DEFINES) -DTOPDIR=$(TOP) -DCURDIR=$(CURRENT_DIR)'
+CALL LINEOUT 'Makefile','      $(MAKE) $(MFLAGS) VerifyOS'
+CALL LINEOUT 'Makefile','      $(MAKE) $(MFLAGS) Makefiles'
+CALL LINEOUT 'Makefile','      $(MAKE) $(MFLAGS) clean'
+CALL LINEOUT 'Makefile','      $(MAKE) $(MFLAGS) includes'
+CALL LINEOUT 'Makefile','      $(MAKE) $(MFLAGS) depend'
+CALL LINEOUT 'Makefile','      $(MAKE) $(MFLAGS)  '
+CALL LINEOUT 'Makefile','      @echo :'
+CALL LINEOUT 'Makefile','      @echo :'
+CALL LINEOUT 'Makefile','      @echo Full build of $(RELEASE) of the X Window System complete.'
+CALL LINEOUT 'Makefile','      @echo :'
+CALL LINEOUT 'Makefile',' '
+CALL LINEOUT 'Makefile','# dont allow any default rules in this Makefile'
+CALL LINEOUT 'Makefile','.SUFFIXES:'
+CALL LINEOUT 'Makefile','# quiet "make" programs that display a message if suffix list empty'
+CALL LINEOUT 'Makefile','.SUFFIXES: .Dummy'
+CALL LINEOUT 'Makefile',' '
+CALL LINEOUT 'Makefile','# a copy of every rule that might be invoked at top level'
+CALL LINEOUT 'Makefile',' '
+CALL LINEOUT 'Makefile','clean:'
+CALL LINEOUT 'Makefile','          $(MAKE_CMD) $@'
+CALL LINEOUT 'Makefile','dangerous_strip_clean:'
+CALL LINEOUT 'Makefile','          $(MAKE_CMD) $@'
+CALL LINEOUT 'Makefile','depend:'
+CALL LINEOUT 'Makefile','          $(MAKE_CMD) $@'
+CALL LINEOUT 'Makefile','Everything:'
+CALL LINEOUT 'Makefile','          $(MAKE_CMD) $@'
+CALL LINEOUT 'Makefile','includes:'
+CALL LINEOUT 'Makefile','          $(MAKE_CMD) $@'
+CALL LINEOUT 'Makefile','install.man:'
+CALL LINEOUT 'Makefile','          $(MAKE_CMD) $@'
+CALL LINEOUT 'Makefile','install:'
+CALL LINEOUT 'Makefile','          $(MAKE_CMD) $@'
+CALL LINEOUT 'Makefile','Makefiles:'
+CALL LINEOUT 'Makefile','          $(MAKE_CMD) $@'
+CALL LINEOUT 'Makefile','man_keywords:'
+CALL LINEOUT 'Makefile','          $(MAKE_CMD) $@'
+CALL LINEOUT 'Makefile','tags:'
+CALL LINEOUT 'Makefile','          $(MAKE_CMD) $@'
+CALL LINEOUT 'Makefile','VerifyOS:'
+CALL LINEOUT 'Makefile','          $(MAKE_CMD) $@'
+CALL LINEOUT 'Makefile',' '
+CALL STREAM 'Makefile','c','close'
+RETURN
diff --git a/Xserver/config/util/checktree.c b/Xserver/config/util/checktree.c
new file mode 100644 (file)
index 0000000..6d477c6
--- /dev/null
@@ -0,0 +1,343 @@
+/* $XConsortium: checktree.c,v 1.7 94/04/17 20:10:40 gildea Exp $ */
+
+/*
+
+Copyright (c) 1993  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+*/
+
+#include <X11/Xos.h>
+#include <stdio.h>
+#include <sys/stat.h>
+#include <sys/param.h>
+#include <errno.h>
+
+#ifndef X_NOT_POSIX
+#include <dirent.h>
+#else
+#ifdef SYSV
+#include <dirent.h>
+#else
+#ifdef USG
+#include <dirent.h>
+#else
+#include <sys/dir.h>
+#ifndef dirent
+#define dirent direct
+#endif
+#endif
+#endif
+#endif
+
+#ifdef S_IFLNK
+#define Stat lstat
+#else
+#define Stat stat
+#endif
+
+#define CHARSALLOWED \
+"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_."
+
+#define fmode_bits_minset 0444
+#define fmode_bits_maxset 0777
+#define fmode_bits_write  0222
+#define dmode_bits_minset 0775
+
+#ifdef X_NOT_STDC_ENV
+extern int errno;
+#endif
+
+int dorcs = 1;                 /* check RCS file */
+int do83 = 1;                  /* check for 8+3 clash */
+int doro = 1;                  /* disallow writable (checked out) files */
+int dodot = 1;                 /* disallow .files */
+int dotwiddle = 1;             /* disallow file~ */
+
+int dontcare(fn)
+    char *fn;
+{
+    char *cp;
+
+    if (fn[strlen(fn) - 1] == '~')
+       return 1;
+    cp = strrchr(fn, '.');
+    return cp && (!strcmp(cp + 1, "Z") || !strcmp(cp + 1, "PS"));
+}
+
+checkfile(fullname, fn, fs)
+    char *fullname, *fn;
+    struct stat *fs;
+{
+    char *cp;
+    int maxlen = 12;
+    int len, mode;
+
+    if (dodot && fn[0] == '.') {
+       printf("dot file: %s\n", fullname);
+       return;
+    }
+    for (len = 0, cp = fn; *cp; len++, cp++) {
+       if (!strchr(CHARSALLOWED, *cp)) {
+           if (dotwiddle || *cp != '~' || cp[1])
+               printf ("bad character: %s\n", fullname);
+           break;
+       }
+    }
+    if (len > maxlen && !dontcare(fn))
+       printf("too long (%d): %s\n", len, fullname);
+#ifdef S_IFLNK
+    if ((fs->st_mode & S_IFLNK) == S_IFLNK) {
+       printf("symbolic link: %s\n", fullname);
+       return;
+    }
+#endif
+    mode = fs->st_mode & (~S_IFMT);
+    if ((fs->st_mode & S_IFDIR) == S_IFDIR) {
+       maxlen = 14;
+       if ((mode & dmode_bits_minset) != dmode_bits_minset)
+           printf("directory mode 0%o not minimum 0%o: %s\n",
+                  mode, dmode_bits_minset, fullname);
+    } else if ((fs->st_mode & S_IFREG) != S_IFREG)
+       printf("not a regular file: %s\n", fullname);
+    else {
+       if ((mode & fmode_bits_minset) != fmode_bits_minset)
+           printf("file mode 0%o not minimum 0%o: %s\n",
+                  fs->st_mode, fmode_bits_minset, fullname);
+       if (fs->st_nlink != 1)
+           printf("%d links instead of 1: %s\n", fs->st_nlink, fullname);
+       if (doro && (mode & fmode_bits_write) && !dontcare(fn))
+           printf("writable: %s\n", fullname);
+    }
+    if ((mode & ~fmode_bits_maxset) != 0)
+       printf("mode 0%o outside maximum set 0%o: %s\n",
+              mode, fmode_bits_maxset, fullname);
+}
+
+void
+checkrcs(dir, p)
+    char *dir;
+    char *p;
+{
+    DIR *df;
+    struct dirent *dp;
+    struct stat fs;
+    int i;
+
+    if (!(df = opendir(dir))) {
+       fprintf(stderr, "cannot open: %s\n", dir);
+       return;
+    }
+    while (dp = readdir(df)) {
+       i = strlen(dp->d_name);
+       if (dp->d_name[i - 1] == 'v' && dp->d_name[i - 2] == ',') {
+           strcpy(p, dp->d_name);
+           p[i - 2] = '\0';
+           if (Stat(dir, &fs) < 0) {
+               strcpy(p, "RCS/");
+               strcat(p, dp->d_name);
+               printf("not used: %s\n", dir);
+           }
+       }
+    }
+    closedir(df);
+}
+
+int
+Strncmp(cp1, cp2, n)
+    char *cp1, *cp2;
+    int n;
+{
+    char c1, c2;
+
+    for (; --n >= 0 && *cp1 && *cp2; cp1++, cp2++) {
+       if (*cp1 != *cp2) {
+           c1 = *cp1;
+           c2 = *cp2;
+           if (c1 >= 'A' && c1 <= 'Z')
+               c1 += 'a' - 'A';
+           else if (c1 == '-')
+               c1 = '_';
+           if (c2 >= 'A' && c2 <= 'Z')
+               c2 += 'a' - 'A';
+           else if (c2 == '-')
+               c2 = '_';
+           if (c1 != c2)
+               return (int)c1 - (int)c2;
+       }
+    }
+    if (n < 0)
+       return 0;
+    return (int)*cp1 - (int)*cp2;
+}
+
+int
+fncomp(n1, n2)
+    char **n1, **n2;
+{
+    int i, res;
+    char *cp1, *cp2;
+    char c1, c2;
+
+    i = Strncmp(*n1, *n2, 8);
+    if (!i) {
+       cp1 = strrchr(*n1, '.');
+       cp2 = strrchr(*n2, '.');
+       if (cp1 || cp2) {
+           if (!cp1)
+               return -1;
+           if (!cp2)
+               return 1;
+           i = Strncmp(cp1 + 1, cp2 + 1, 3);
+       }
+    }
+    return i;
+}
+
+void
+checkdir(dir)
+    char *dir;
+{
+    DIR *df;
+    struct dirent *dp;
+    char *p;
+    struct stat fs;
+    char *s, **names;
+    int i, max;
+
+    if (!(df = opendir(dir))) {
+       fprintf(stderr, "cannot open: %s\n", dir);
+       return;
+    }
+    p = dir + strlen(dir);
+    if (p[-1] != '/')
+       *p++ = '/';
+    i = 0;
+    max = 0;
+    names = NULL;
+    while (dp = readdir(df)) {
+       strcpy(p, dp->d_name);
+       if (Stat(dir, &fs) < 0) {
+           perror(dir);
+           continue;
+       }
+       if ((fs.st_mode & S_IFDIR) == S_IFDIR) {
+           if (dp->d_name[0] == '.' &&
+               (dp->d_name[1] == '\0' || (dp->d_name[1] == '.' &&
+                                          dp->d_name[2] == '\0')))
+               continue;
+           if (!strcmp (dp->d_name, "RCS")) {
+               if (dorcs)
+                   checkrcs(dir, p);
+               continue;
+           }
+           if (!strcmp (dp->d_name, "SCCS"))
+               continue;
+           if (!strcmp (dp->d_name, "CVS.adm"))
+               continue;
+           checkfile(dir, p, &fs);
+           checkdir(dir);
+           continue;
+       }
+       checkfile(dir, p, &fs);
+       if (dorcs && !dontcare(dp->d_name)) {
+           strcpy(p, "RCS/");
+           strcat(p, dp->d_name);
+           strcat(p, ",v");
+           if (Stat(dir, &fs) < 0) {
+               strcpy(p, dp->d_name);
+               printf("no RCS: %s\n", dir);
+           }
+       }
+       if (do83) {
+           s = (char *)malloc(strlen(dp->d_name) + 1);
+           strcpy(s, dp->d_name);
+           if (i >= max) {
+               max += 25;
+               if (names)
+                   names = (char **)realloc((char *)names,
+                                            (max + 1) * sizeof(char *));
+               else
+                   names = (char **)malloc((max + 1) * sizeof(char *));
+           }
+           names[i++] = s;
+       }
+    }
+    closedir(df);
+    if (do83) {
+       qsort((char *)names, i, sizeof(char *), fncomp);
+       max = i - 1;
+       *p = '\0';
+       for (i = 0; i < max; i++) {
+           if (!fncomp(&names[i], &names[i + 1]))
+               printf("8+3 clash: %s%s and %s\n",
+                      dir, names[i], names[i + 1]);
+           free(names[i]);
+       }
+       if (names) {
+           free(names[i]);
+           free((char *)names);
+       }
+    }
+}
+
+main(argc, argv)
+    int argc;
+    char **argv;
+{
+    char buf[2048];
+
+    argc--;
+    argv++;
+    while (argc > 0) {
+       if (!strcmp(*argv, "-rcs")) {
+           dorcs = 0;
+           argc--;
+           argv++;
+       } else if (!strcmp(*argv, "-83")) {
+           do83 = 0;
+           argc--;
+           argv++;
+       } else if (!strcmp(*argv, "-ro")) {
+           doro = 0;
+           argc--;
+           argv++;
+       } else if (!strcmp(*argv, "-dot")) {
+           dodot = 0;
+           argc--;
+           argv++;
+       } else if (!strcmp(*argv, "-twiddle")) {
+           dotwiddle = 0;
+           argc--;
+           argv++;
+       } else
+           break;
+    }
+    if (!argc) {
+       strcpy(buf, ".");
+       checkdir(buf);
+    } else
+       while (--argc >= 0) {
+           strcpy(buf, *argv++);
+           checkdir(buf);
+       }
+}
diff --git a/Xserver/config/util/chownxterm.c b/Xserver/config/util/chownxterm.c
new file mode 100644 (file)
index 0000000..a68e671
--- /dev/null
@@ -0,0 +1,76 @@
+/* $XConsortium: chownxterm.c,v 1.3 94/04/17 20:10:41 gildea Exp $ */
+/*
+
+Copyright (c) 1993, 1994  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+*/
+
+/*
+ * chownxterm --- make xterm suid root
+ *
+ * By Stephen Gildea, December 1993
+ */
+
+
+#define XTERM_PATH "/x11/programs/xterm/xterm"
+
+#include <stdio.h>
+#include <errno.h>
+
+char *prog_name;
+
+void help()
+{
+    setgid(getgid());
+    setuid(getuid());
+    printf("chown-xterm makes %s suid root\n", XTERM_PATH);
+    printf("This is necessary on Ultrix for /dev/tty operation.\n");
+    exit(0);
+}
+
+void print_error(err_string)
+    char *err_string;
+{
+    setgid(getgid());
+    setuid(getuid());
+    fprintf(stderr, "%s: \"%s\"", prog_name, err_string);
+    perror(" failed");
+    exit(1);
+}
+
+main(argc, argv)
+    int argc;
+    char **argv;
+{
+    prog_name = argv[0];
+    if (argc >= 2 && strcmp(argv[1], "-help") == 0) {
+       help();
+    } else {
+       if (chown(XTERM_PATH, 0, -1) != 0)
+           print_error("chown root " XTERM_PATH);
+       if (chmod(XTERM_PATH, 04555) != 0)
+           print_error("chmod 4555 " XTERM_PATH);
+    }
+    exit(0);
+}
diff --git a/Xserver/config/util/crayar.sh b/Xserver/config/util/crayar.sh
new file mode 100755 (executable)
index 0000000..6296de5
--- /dev/null
@@ -0,0 +1,9 @@
+#!/bin/sh
+lib=$1
+shift
+if cray2; then
+        bld cr $lib `lorder $* | tsort`
+else
+        ar clq $lib $*
+fi
+
diff --git a/Xserver/config/util/elistgen.hp b/Xserver/config/util/elistgen.hp
new file mode 100644 (file)
index 0000000..60a4b52
--- /dev/null
@@ -0,0 +1,202 @@
+XCOMM!/bin/sh
+XCOMM $XConsortium: elistgen.hp /main/2 1996/12/04 10:13:14 swick $
+XCOMM
+XCOMM #########################################################################
+XCOMM Construct shared-library export lists for HP-UX based on standardized
+XCOMM export list description file
+XCOMM
+XCOMM Usage: exportlistgen libfoo.sl libfoo.elist > libfoo.lopt
+XCOMM
+XCOMM  libfoo.sl    => shared library of interest
+XCOMM  libfoo.elist => Meta description of necessary export list.
+XCOMM
+XCOMM The output may then be passed to the linker to reconstruct the
+XCOMM shared library.  For unknown reasons naming only exported symbols
+XCOMM with "+e" does not work for debuggable C++ code, even though "nm"
+XCOMM reports no difference between the resulting libraries.  The linker
+XCOMM complains that "first non-inline virtual function" is not defined for
+XCOMM vtables.  We instead hide internal symbols with "-h" as a work-around.
+XCOMM
+XCOMM Author: Aloke Gupta 5/25/94.
+XCOMM (c) Copyright 1996 Digital Equipment Corporation.
+XCOMM (c) Copyright 1994,1996 Hewlett-Packard Company.
+XCOMM (c) Copyright 1996 International Business Machines Corp.
+XCOMM (c) Copyright 1996 Sun Microsystems, Inc.
+XCOMM (c) Copyright 1996 Novell, Inc.
+XCOMM (c) Copyright 1996 FUJITSU LIMITED.
+XCOMM (c) Copyright 1996 Hitachi.
+XCOMM
+XCOMM #########################################################################
+
+XCOMM Utility programs
+FILTER=CXXFILT                 # C++ symbol demangler
+AWK=awk                                # awk
+PATH=/usr/bin:/bin:/usr/ucb    # For nm, cat, pr, expand, awk, c++filt
+
+XCOMM Temporary files
+EXPORTLIST=/tmp/elistgen1.$$   # list of export symbols from "libfoo.elist"
+NMLIST=/tmp/elistgen2.$$       # name list from libfoo.sl
+FILTLIST=/tmp/elistgen3.$$     # demangled (C++) version of NMLIST
+
+XCOMM Print useful information at the top of the output
+echo "#" `date`
+echo "# This linker options list was produced by" $0
+echo "# Input export list description taken from:" $2
+echo "# Target library:" $1
+echo "# Target Operating System:" `uname -msrv`
+echo "# "
+
+XCOMM Extract the globally visible symbols from target library
+XCOMM The NMLIST generated here is later used to cross-check the symbols in the
+XCOMM supplied export-list.
+XCOMM
+nm -p $1 | $AWK '
+    / [cCTDB][S ] [^\$]/{print $3}   # Text, Data, BSS, or Secondary symbols
+' > $NMLIST
+
+XCOMM Demangle the global library symbols. This operation is necessary to
+XCOMM convert mangled C++ symbols into their C++ notation.
+${FILTER:-cat} $NMLIST > $FILTLIST
+
+XCOMM
+XCOMM Cleanup the export-list description file.
+XCOMM Note that C++ symbols may have embedded spaces in them.
+XCOMM
+cat $2 | $AWK '
+    BEGIN           {
+       csyms      = 0;         # C   language symbols in libfoo.list
+       cplusplus  = 0;         # C++ language symbols in libfoo.list
+       isyms      = 0;         # C   internal symbols in libfoo.elist
+       icplusplus = 0;         # C++ internal symbols in libfoo.elist
+       implicit = "";          # Handling of implicit symbols.
+    }
+    $1 == "default" {
+       # A default clause suppresses warnings about implicit symbols.
+       if ($2 != "" && $2 != "force" && $2 != "public" && 
+           $2 != "private" && $2 != "internal") {
+           print "# Warning: illegal default clause:", $2 | "cat 1>&2";
+           next;
+       }
+       if (implicit != "")
+           print "# Warning: multiple default clauses." | "cat 1>&2";
+        implicit = $2;
+       next;
+    }
+    $1 == "force" || $1 == "public" || $1 == "private" {
+       csyms ++;
+       print $1 ";;" $2;
+       next;
+    }
+    $1 == "publicC++" || $1 == "privateC++" {
+       cplusplus ++;
+       string = $2;
+       for (n = 3; n <= NF; n++)
+           string = string " " $n;
+       print $1 ";;" string;
+       next;
+    }
+    $1 == "internal" {
+       isyms ++;
+       print $1 ";;" $2;
+       next;
+    }
+    $1 == "internalC++" {
+       icplusplus ++;
+       string = $2;
+       for (n = 3; n <= NF; n++)
+           string = string " " $n;
+       print $1 ";;" string;
+       next;
+    }
+    END  {
+       printf("# Exporting %d C and %d C++ symbols, hiding %d and %d.\n",
+               csyms, cplusplus, isyms, icplusplus) | "cat 1>&2";
+       if (implicit != "") {
+           print "# Unspecified symbols are " implicit "." | "cat 1>&2";
+           print "default;;" implicit;
+       }
+    }
+' > $EXPORTLIST
+
+XCOMM Read in the above files and write result to stdout.  The contents
+XCOMM of NMLIST and FILTLIST are used to construct a symbol lookup table.
+XCOMM The contents of EXPORTLIST are converted with the help of this table.
+XCOMM Use ";" as a delimiter in the symbol lookup table.
+XCOMM
+(pr -m -s";" -t -w1024 $NMLIST $FILTLIST| expand -t 1;cat $EXPORTLIST ) | $AWK '
+    BEGIN {
+       FS = ";";
+       implicit = 0;
+    }
+    NF == 2 {
+       # This is "pr" output, i.e., symbol translation table.
+       syms[$2] = $1;
+       next;
+    }
+    NF == 3 && $1 == "default" {
+       # Treatment of unspecified symbols.
+       if ($3 == "internal" || $3 == "internalC++")
+           implicit = 1;
+       else if ($3 == "private" || $3 == "privateC++")
+           implicit = 2;
+       else if ($3 == "public" || $3 == "publicC++")
+           implicit = 3;
+       else # $3 == "force"
+           implicit = 4;
+        next;
+    }
+    NF == 3 {
+       # Parse our instructions for this symbol.
+       if ($1 == "internal" || $1 == "internalC++")
+           export = 1;
+       else if ($1 == "private" || $1 == "privateC++")
+           export = 2;
+       else if ($1 == "public" || $1 == "publicC++")
+           export = 3;
+       else # $1 == "force"
+           export = 4;
+
+       # Process it.
+       if (length(syms[$3]) > 0) {
+           if (donelist[$3])
+               print "# Warning: Duplicate entry for", $3,
+                       "in export list" | "cat 1>&2";
+           if (donelist[$3] < export)
+               donelist[$3] = export;
+       } else {
+           if (export == 4)
+               donelist[$3] = export;
+           else
+               print "# Warning:", $3,
+                   "was not in the nm list for this library" | "cat 1>&2";
+       }
+       next;
+    }
+    END {
+       # Force implicit exporting of errno.
+       if (! donelist["errno"])
+           donelist["errno"] = 4;
+
+       # Complain about some implicit symbols.
+       for (i in syms) {
+           if (!donelist[i] && (length(syms[i]) > 0)) {
+               # Ignore automatic symbols generated by the C++ compiler.
+               if (implicit == 0 && 
+                   (syms[i] !~ /^__noperfopt__/) &&
+                   (syms[i] !~ /^__ptbl_vec__/) &&
+                   (syms[i] !~ /^__vtbl__[0-9]*_/) &&
+                   (syms[i] !~ /^__cfront_version_[0-9]*_xxxxxxxx$/))
+                   print "# Warning:", syms[i],
+                         "was not in the export list" | "cat 1>&2";
+               donelist[i] = implicit;
+           }
+           if ((donelist[i] > 1) && (length(syms[i]) > 0))
+               print "-e", syms[i];
+       }
+    }
+'
+
+XCOMM Clean up temporary files
+rm $EXPORTLIST
+rm $NMLIST
+rm $FILTLIST
diff --git a/Xserver/config/util/elistgen.ibm b/Xserver/config/util/elistgen.ibm
new file mode 100644 (file)
index 0000000..b1f99d1
--- /dev/null
@@ -0,0 +1,220 @@
+XCOMM!/bin/sh
+XCOMM $XConsortium: elistgen.ibm /main/2 1996/12/04 10:13:18 swick $
+XCOMM
+XCOMM #########################################################################
+XCOMM Construct shared-library export lists for IBM-AIX based on standardized
+XCOMM export list description file
+XCOMM
+XCOMM Usage: elistgen libfoo.sl libfoo.elist > libfoo.lopt
+XCOMM
+XCOMM  libfoo.a     => shared library of interest
+XCOMM  libfoo.elist => Meta description of necessary export list.
+XCOMM
+XCOMM    The output file, "libfoo.lopt" may then be passed to the IBM linker to 
+XCOMM    reconstruct the shared library, libfoo.sl.
+XCOMM
+XCOMM Author: Yanling Qi 10/03/94, Last updated 10/03/94
+XCOMM (c) Copyright 1996 Digital Equipment Corporation.
+XCOMM (c) Copyright 1996 Hewlett-Packard Company.
+XCOMM (c) Copyright 1994,1996 International Business Machines Corp.
+XCOMM (c) Copyright 1996 Sun Microsystems, Inc.
+XCOMM (c) Copyright 1996 Novell, Inc. 
+XCOMM (c) Copyright 1996 FUJITSU LIMITED.
+XCOMM (c) Copyright 1996 Hitachi.
+XCOMM
+XCOMM #########################################################################
+
+#define HASH #
+
+XCOMM Utility programs
+FILTER=CXXFILT                 # C++ symbol demangler
+AWK=awk                                # awk
+
+XCOMM For dump, cat, pr, expand, awk, c++filt
+PATH=/usr/bin:/bin:/usr/ucb:/usr/lpp/xlC/bin
+
+XCOMM Temporary files
+EXPORTLIST=/tmp/elistgen1.$$   # export directives from "libfoo.list"
+NMLIST=/tmp/elistgen2.$$       # name list from libfoo.sl
+FILTLIST=/tmp/elistgen3.$$     # demangled (C++) version of above
+
+XCOMM Print useful information
+echo "*" `date`
+echo "* This linker options list was produced by" $0
+echo "* Input export list description taken from:" $2
+echo "* Target library:" $1
+echo "* Target Operating System:" `uname`
+echo "*"
+
+XCOMM Extract the globally visible symbols from target library
+dump -g $1 | $AWK  '$1 ~ /[0-9][0-9]/ && $2 !~ /^[\.]/ {print $2}' > $NMLIST
+
+XCOMM Demangle the global library symbols
+${FILTER:-cat} $NMLIST > $FILTLIST
+
+XCOMM
+XCOMM Clean up the export-list description file.
+XCOMM Note that C++ symbols may have embedded spaces in them.
+XCOMM
+$AWK '
+    BEGIN {
+       csyms     = 0;          # C   language symbols in libfoo.list
+       cplusplus = 0;          # C++ language symbols in libfoo.list
+       isyms     = 0;          # C   internal symbols in libfoo.list
+       iplusplus = 0;          # C++ internal symbols in libfoo.list
+       count     = 0;          # Running count of symbols
+       implicit  = "";         # Handling of implicit symbols.
+    }
+    $1 == "default" {
+       HASH A default clause suppresses warnings about implicit symbols.
+       if ($2 != "" && $2 != "force" && $2 != "public" && 
+           $2 != "private" && $2 != "internal") {
+           print "# Warning: illegal default clause:", $2 | "cat 1>&2";
+           next;
+       }
+       if (implicit != "")
+           print "# Warning: multiple default clauses." | "cat 1>&2";
+        implicit = $2;
+       next;
+    }
+    $1 == "force" || $1 == "public" || $1 == "private" {
+       csyms ++;
+       symbol[count++] = $1 ";;" $2;
+       next;
+    }
+    $1 == "publicC++" || $1 == "privateC++" {
+       HASH forceC++ is unsupported because we only know how to demangle,
+       HASH not how to mangle symbols, and the final ld input file must
+       HASH be mangled.
+       cplusplus ++;
+       string = $2;
+       for (n = 3; n <= NF; n++)
+           string = string " " $n;
+       symbol[count++] = $1 ";;" string;
+       next;
+    }
+    $1 == "internal" {
+       isyms ++;
+       symbol[count++] = $1 ";;" $2;
+       next;
+    }
+    $1 == "internalC++" {
+       iplusplus ++;
+       string = ";;" $2;
+       for (n = 3; n <= NF; n++)
+           string = string " " $n;
+       symbol[count++] = $1 ";;" string;
+       next;
+    }
+    $1 == "#line" || $1 == "#" {
+       HASH cpp will have removed comments, but may have added other stuff.
+       next;
+    }
+    NF > 0 {
+       print "# Warning: unrecognized directive:", $0 | "cat 1>&2";
+       next;
+    }
+    END  {
+       printf("# Exporting %d C and %d C++ symbols, hiding %d and %d.\n",
+              csyms, cplusplus, isyms, iplusplus) | "cat 1>&2";
+       if (implicit != "") {
+           print "# Unspecified symbols are " implicit "." | "cat 1>&2";
+           print "default;;" implicit;
+       }
+       for (i in symbol)
+           print symbol[i];
+    }
+' $2 > $EXPORTLIST
+
+XCOMM
+XCOMM Read in the above files and write result to stdout.  Use the
+XCOMM delimiter ";" to identify the entries in the symbol lookup table.
+XCOMM
+(pr -m -s";" -t -w1024 $NMLIST $FILTLIST | expand -t 1; cat $EXPORTLIST) | $AWK '
+    BEGIN {
+       FS = ";";
+       implicit = 0;
+    }
+    NF == 2 {
+       HASH This is "pr" output, i.e., symbol translation table
+       r2=$2
+       gsub(/ /,"",r2);       # Remove spaces because c++filt is unpredictable
+       syms[r2] = $1;
+       r1=$1;
+       gsub(/ /,"",r1);
+       mangled[r1] = 1;       # Save the mangling because the export lists
+                              HASH sometimes use it instead of a prototype.
+       next;
+    }
+    NF == 3 && $1 == "default" {
+       HASH Treatment of unspecified symbols.
+       if ($3 == "internal")
+           implicit = 1;
+       else if ($3 == "private" || $3 == "privateC++")
+           implicit = 2;
+       else if ($3 == "public" || $3 == "publicC++")
+           implicit = 3;
+       else # $3 == "force"
+           implicit = 4;
+        next;
+    }
+    NF == 3 {
+       HASH Generate canonical demangled form as an alternate symbol.
+       alt=$3;
+       gsub(/ \.\.\./,",...",alt); # change " ..." to ",..." to match c++filt
+       gsub(/ /,"",alt);           # remove all spaces
+       gsub(/\(void\)/,"()",alt);  # change "(void)" to "()" to match c++filt
+
+       HASH Parse our instructions for this symbol.
+       if ($1 == "internal" || $1 == "internalC++")
+           export = 1;
+       else if ($1 == "private" || $1 == "privateC++")
+           export = 2;
+       else if ($1 == "public" || $1 == "publicC++")
+           export = 3;
+       else # $1 == "force"
+           export = 4;
+
+       HASH Process it.
+       if ((length(syms[alt]) > 0) || mangled[alt]) {
+           HASH This symbol is present in the library.
+           if (donelist[alt])
+               print "# Warning: Duplicate entry for", $3, 
+                   "in export list" | "cat 1>&2";
+           if (donelist[alt] < export) {
+               if (export > 1)
+                   print syms[alt];
+               donelist[alt] = export;
+           }
+       } else { 
+           HASH Print forced-export symbols without complaining.
+           if (export == 4) {
+               print alt;
+               donelist[alt] = export;
+           } else {
+               print "# Warning:", $3,
+                   "was not in the nm list for this library" | "cat 1>&2";
+           }
+       }
+
+       next;
+    }
+    END { 
+       HASH Process implicit symbols.
+       for (i in syms) {
+           if ((! donelist[i]) && (length(syms[i]) > 0)) {
+               HASH Do not complain about C++ virtual function tables.
+               if (implicit == 0 && syms[i] !~ /^__vft[0-9]*_/)
+                   print "# Warning:", syms[i],
+                       "was not in the export list" | "cat 1>&2";
+               if (implicit > 1)
+                   print syms[i];
+           }
+       }
+    }
+'
+
+XCOMM Clean up temporary files
+rm $EXPORTLIST
+rm $NMLIST
+rm $FILTLIST
diff --git a/Xserver/config/util/elistgen.sun b/Xserver/config/util/elistgen.sun
new file mode 100644 (file)
index 0000000..4af7acb
--- /dev/null
@@ -0,0 +1,243 @@
+XCOMM!/bin/sh -f
+XCOMM $XConsortium: exportlistgen.sun /main/3 1996/10/11 13:54:11 swick $
+XCOMM
+XCOMM ########################################################################
+XCOMM Construct shared-library scoping mapfile for Solaris based on standardized
+XCOMM export list description file
+XCOMM
+XCOMM Usage: exportlistgen libfoo.so libfoo.elist > mapfile.scope
+XCOMM
+XCOMM  libfoo.so    => shared library of interest
+XCOMM  libfoo.elist => Meta description of necessary export list.
+XCOMM
+XCOMM    The output file, "mapfile.scope" may then be passed to the Solaris 
+XCOMM    linker to reconstruct the shared library, libfoo.so.
+XCOMM
+XCOMM ########################################################################
+
+XCOMM Utility programs
+FILTER=CXXFILT                 # C++ symbol demangler
+AWK=awk                                # Awk
+
+XCOMM For nm, cat, pr, expand, awk, c++filt
+PATH=/usr/bin:/bin:/usr/ccs/bin:/usr/ucb:/opt/SUNWspro/bin
+
+XCOMM Try to detect broken versions of c++filt.
+if [ `echo _okay | ${FILTER:-cat}` != "_okay" ]; then
+    if [ -x /opt/SUNWspro/bin/c++filt ]; then
+       echo "# Your $FILTER is broken -- using /opt/SUNWspro/bin/c++filt."
+       FILTER=/opt/SUNWspro/bin/c++filt
+    else
+       echo "# ERROR: no working $FILTER available."
+       exit 1
+    fi;
+fi;
+
+XCOMM Temporary files
+EXPORTLIST=/tmp/elistgen1.$$   # export directives from "libfoo.list"
+NMLIST=/tmp/elistgen2.$$       # name list from libfoo.sl
+FILTLIST=/tmp/elistgen3.$$     # demangled (C++) version of above
+
+XCOMM Print useful information at the top of the output
+echo "#" `date`
+echo "# This scoping mapfile was produced by" $0
+echo "# Export list description taken from:" $2
+echo "# Target library:" $1
+echo "# Target Operating System:" `uname -msrv`
+echo "# "
+
+XCOMM Extract the globally visible symbols from target library
+XCOMM The NMLIST generated here is later used to cross-check the symbols in the
+nm -p $1 | $AWK '/ [ TDBS] /{print $3}' > $NMLIST
+
+XCOMM Extract the globally visible symbols from target library
+XCOMM The NMLIST generated here is later used to cross-check the symbols in the
+${FILTER:-cat} $NMLIST > $FILTLIST
+
+XCOMM Clean up the export-list description file.  Sort the directives.
+$AWK '
+    BEGIN {
+       csyms     = 0;  # C   public symbols in libfoo.list
+       cplusplus = 0;  # C++ public symbols in libfoo.list
+       isyms     = 0;  # C   internal symbols in libfoo.list
+       iplusplus = 0;  # C++ internal symbols in libfoo.list
+       implicit  = ""; # Handling of implicit symbols
+    }
+    $1 == "default" {
+       # A default clause suppresses warnings about implicit symbols.
+       if ($2 != "" && $2 != "force" && $2 != "public" && $2 != "private" && $2 != "internal") {
+           print "# Warning: illegal default clause:", $2 | "cat 1>&2";
+           next;
+       }
+       if (implicit != "")
+           print "# Warning: multiple default clauses." | "cat 1>&2";
+       implicit = $2;
+       next;
+    }
+    $1 == "force" {
+       csyms ++;
+       print $1 ";;" $2;
+       next;
+    }
+    $1 == "public" {
+       csyms ++;
+       print $1 ";;" $2;
+       next;
+    }
+    $1 == "publicC++" {
+       cplusplus ++;
+       string = $2;
+       for (n = 3; n <= NF; n++)
+           string = string " " $n;
+       print $1 ";;" string;
+       next;
+    }
+    $1 == "private" {
+       csyms ++;
+       print $1 ";;" $2;
+       next;
+    }
+    $1 == "privateC++" {
+       cplusplus ++;
+       string = $2;
+       for (n = 3; n <= NF; n++)
+           string = string " " $n;
+       print $1 ";;" string;
+       next;
+    }
+    $1 == "internal" {
+       isyms ++;
+       print $1 ";;" $2;
+       next;
+    }
+    $1 == "internalC++" {
+       iplusplus ++;
+       string = $2;
+       for (n = 3; n <= NF; n++)
+           string = string " " $n;
+       print $1 ";;" string;
+       next;
+    }
+    $1 == "#line" || $1 == "#" {
+       # cpp will have removed comments, but may have added other stuff.
+       next;
+    }
+    NF > 0 {
+       print "# Warning: unrecognized directive:", $0 | "cat 1>&2";
+       next;
+    }
+    END {
+       printf("# Exporting %d C and %d C++ symbols, hiding %d and %d.\n", csyms, cplusplus, isyms, iplusplus) | "cat 1>&2";
+       if (implicit != "") {
+           print "# Unspecified symbols are " implicit "." | "cat 1>&2";
+           print "default;;" implicit;
+       }
+    }
+' $2 1>$EXPORTLIST
+
+
+XCOMM Read in the above files and write result to stdout.  The contents
+XCOMM of NMLIST and FILTLIST are used to construct a symbol lookup table.
+XCOMM The contents of EXPORTLIST are converted with the help of this table.
+XCOMM Use ";" as a delimiter in the symbol lookup table.
+(pr -m -s";" -t -w1024 $NMLIST $FILTLIST | expand -1; cat $EXPORTLIST) | $AWK '
+    BEGIN {
+       FS = ";";
+       implicit = 0;
+    }
+    NF == 2 {
+       # This is "pr" output, i.e., symbol translation table
+       syms[$2] = $1;
+       next;
+    }
+    NF == 3 && $1 == "default" {
+       # Treatment of unspecified symbols.
+       if ($3 == "internal" || $3 == "internalC++")
+           implicit = 1;
+       else if ($3 == "private" || $3 == "privateC++")
+           implicit = 2;
+       else if ($3 == "public" || $3 == "publicC++")
+           implicit = 3;
+       else # $3 == "force"
+           implicit = 4;
+       next;
+    }
+    NF == 3 {
+       # An export directive.  Parse our instructions for this symbol.
+       if ($1 == "internal" || $1 == "internalC++")
+           export = 1;
+       else if ($3 == "private" || $3 == "privateC++")
+           export = 2;
+       else if ($3 == "public" || $3 == "publicC++")
+           export = 3;
+       else # $3 == "force"
+           export = 4;
+
+       if (length(syms[$3]) > 0) {
+           if (donelist[$3])
+               print "# Warning: Duplicate entry for", $3, "in export list" | "cat 1>&2";
+           if (donelist[$3] < export)
+               donelist[$3] = export;
+       } else { 
+           if (export == 4)
+               donelist[$3] = export;
+           else
+               print "# Warning:", $3, "was not in the nm list for this library" | "cat 1>&2";
+       }
+       next;
+    }
+    END { 
+       # Ignore magic linker symbols.
+       if (implicit == 0) {
+           if (!donelist["_DYNAMIC"])
+               donelist["_DYNAMIC"] = 1;
+           if (!donelist["_GLOBAL_OFFSET_TABLE_"])
+               donelist["_GLOBAL_OFFSET_TABLE_"] = 1;
+           if (!donelist["_PROCEDURE_LINKAGE_TABLE_"])
+               donelist["_PROCEDURE_LINKAGE_TABLE_"] = 1;
+           if (!donelist["_edata"])
+               donelist["_edata"] = 1;
+           if (!donelist["_end"])
+               donelist["_end"] = 1;
+           if (!donelist["_etext"])
+               donelist["_etext"] = 1;
+        }
+
+       # Process implicit symbols.
+       for (i in syms) {
+           if (donelist[i] == 0 && length(syms[i]) > 0) {
+               if (implicit == 0) {
+                   # Ignore magic symbols introduced by the C++ compiler.
+                   if ((syms[i] !~ /^__vtbl__[0-9]*_/) && (syms[i] !~ /^__ptbl_vec__/))
+                       print "# Warning:", syms[i], "was not in the export list" | "cat 1>&2";
+               } else {
+                   donelist[i] = implicit;
+               }
+           }
+       }
+
+       # Generate the linker file.
+       print "";
+       print "SUNW.1.1 {";
+       print "    global:";
+       for (i in syms)
+           if (donelist[i] >= 2 && length(syms[i]) > 0)
+               print "        " syms[i] ";";
+       print "    local:";
+       print "        *;";
+       print "};";
+
+       print "";
+       print "SUNW_private.1.1 {";
+       print "    global:";
+       for (i in syms)
+           if (donelist[i] == 1 && length(syms[i]) > 0)
+               print "        " syms[i] ";";
+       print "} SUNW.1.1;"
+    }
+'
+
+XCOMM Clean up temporary files
+rm $EXPORTLIST
+rm $NMLIST
+rm $FILTLIST
diff --git a/Xserver/config/util/elistgen.usl b/Xserver/config/util/elistgen.usl
new file mode 100644 (file)
index 0000000..0923b52
--- /dev/null
@@ -0,0 +1,219 @@
+XCOMM!/bin/sh
+XCOMM $XConsortium: elistgen.usl /main/2 1996/12/04 10:13:26 swick $
+XCOMM
+XCOMM #########################################################################
+XCOMM Construct shared-library export lists for Novell based on standardized
+XCOMM export list description file
+XCOMM
+XCOMM Usage: exportlistgen libFoo.so libFoo.elist > libFoo.lopt
+XCOMM
+XCOMM  libFoo.so    => shared library of interest
+XCOMM  libFoo.elist => Meta description of necessary export list.
+XCOMM
+XCOMM    The output file, "libFoo.lopt" may then be passed to the linker to 
+XCOMM    reconstruct the shared library.
+XCOMM
+XCOMM (c) Copyright 1996 Digital Equipment Corporation.
+XCOMM (c) Copyright 1996 Hewlett-Packard Company.
+XCOMM (c) Copyright 1996 International Business Machines Corp.
+XCOMM (c) Copyright 1996 Sun Microsystems, Inc.
+XCOMM (c) Copyright 1996 Novell, Inc. 
+XCOMM (c) Copyright 1996 FUJITSU LIMITED.
+XCOMM (c) Copyright 1996 Hitachi.
+XCOMM
+XCOMM #########################################################################
+
+XCOMM Utility programs
+FILTER=CXXFILT                 # C++ symbol demangler
+AWK=awk                                # awk
+
+XCOMM For nm, cat, pr, expand, awk, c++filt
+PATH=/usr/bin:/bin:/usr/ucb:/usr/ccs/bin
+
+XCOMM Temporary files
+EXPORTLIST=/tmp/elistgen1.$$   # list of export symbols from "libfoo.elist"
+NMLIST=/tmp/elistgen2.$$       # name list from libfoo.sl
+FILTLIST=/tmp/elistgen3.$$     # demangled (C++) version of NMLIST
+
+XCOMM Print useful information at the top of the output
+echo "#" `date`
+echo "# This linker options list was produced by" $0
+echo "# Input export list description taken from:" $2
+echo "# Target library:" $1
+echo "# Target Operating System:" `uname -msrv`
+echo "# "
+
+XCOMM Extract the globally visible symbols from target library.
+XCOMM The NMLIST generated here is later used to cross-check the symbols in the
+XCOMM supplied export-list.
+nm -p $1 | $AWK '
+    / [TD] [^\$]/{print $3}   # Text, Data, BSS, or Secondary symbols
+' > $NMLIST
+
+XCOMM Demangle the global library symbols. This operation is necessary to convert
+XCOMM mangled C++ symbols into their C++ notation.
+${FILTER:-cat} $NMLIST > $FILTLIST
+
+XCOMM Clean up the export-list description file.
+XCOMM Note that C++ symbols may have embedded spaces in them.
+cat $2 | $AWK '
+    BEGIN           {
+       csyms     = 0;          # C   language symbols in libfoo.list
+       cplusplus = 0;          # C++ language symbols in libfoo.list
+       isyms     = 0;          # C   internal symbols in libfoo.elist
+       iplusplus = 0;          # C++ internal symbols in libfoo.elist
+       implicit  = "";         # Handling of implicit symbols
+    }
+    $1 == "default" {
+       # A default clause suppresses warnings about implicit symbols.
+       if ($2 != "" && $2 != "force" && $2 != "public" && 
+           $2 != "private" && $2 != "internal") {
+           print "# Warning: illegal default clause:", $2 | "cat 1>&2";
+           next;
+       }
+       if (implicit != "")
+           print "# Warning: multiple default clauses." | "cat 1>&2";
+        implicit = $2;
+       next;
+    }
+    $1 == "force" || $1 == "public" || $1 == "private" {
+       csyms ++;
+       print $1 ";;" $2;
+       next;
+    }
+    $1 == "publicC++" || $1 == "privateC++" {
+       cplusplus ++;
+       string = $2;
+       for (n = 3; n <= NF; n++) {
+           string = string " " $n;
+       }
+       print $1 ";;" string;
+       next;
+    }
+    $1 == "internal" {
+       isyms ++;
+       print $1 ";;" $2;
+       next;
+    }
+    $1 == "internalC++" {
+       iplusplus ++;
+       string = $2;
+       for (n = 3; n <= NF; n++) {
+           string = string " " $n;
+       }
+       print $1 ";;" string;
+       next;
+    }
+    $1 == "#line" || $1 == "#" {
+       # cpp will have removed comments, but may have added other stuff.
+       next;
+    }
+    NF > 0 {
+       print "# Warning: unrecognized directive:", $0 | "cat 1>&2";
+       next;
+    }
+    END  {
+       printf("# Exporting %d C and %d C++ symbols, hiding %d and %d.\n",
+                           csyms, cplusplus, isyms, iplusplus) | "cat 1>&2";
+       if (implicit != "") {
+           print "# Unspecified symbols are " implicit "." | "cat 1>&2";
+           print "default;;" implicit;
+       }
+    }
+' > $EXPORTLIST
+
+XCOMM Read in the above files and write result to stdout.  The contents
+XCOMM of NMLIST and FILTLIST are used to construct a symbol lookup table.
+XCOMM The contents of EXPORTLIST are converted with the help of this table.
+XCOMM Use ";" as a delimiter in the symbol lookup table.
+(pr -m -s";" -t -w1024 $NMLIST $FILTLIST | expand -1; cat $EXPORTLIST) | $AWK '
+    BEGIN {
+       FS = ";";
+       implicit = 0;
+    }
+    NF == 2 {
+       # This is "pr" output, i.e., symbol translation table
+       syms[$2] = $1;
+       next;
+    }
+    NF == 3 && $1 == "default" {
+       # Treatment of unspecified symbols.
+       if ($3 == "internal")
+           implicit = 1;
+       else if ($3 == "private" || $3 == "privateC++")
+           implicit = 2;
+       else if ($3 == "public" || $3 == "publicC++")
+           implicit = 3;
+       else # $3 == "force"
+           implicit = 4;
+        next;
+    }
+    NF == 3 {
+       # Parse our instructions for this symbol.
+       if ($1 == "internal" || $1 == "internalC++")
+           export = 1;
+       else if ($1 == "private" || $1 == "privateC++")
+           export = 2;
+       else if ($1 == "public" || $1 == "publicC++")
+           export = 3;
+       else # $1 == "force"
+           export = 4;
+
+       # Process it.
+       if (length(syms[$3]) > 0) {
+           # This symbol is present in the library.
+           if (donelist[$3])
+               print "# Warning: Duplicate entry for", $3, 
+                   "in export list" | "cat 1>&2";
+           if (donelist[$3] < export) {
+               if (export > 1)
+                   print syms[$3];
+               donelist[$3] = export;
+           }
+       } else { 
+           # Do not complain about unknown forced-export symbols.
+           if (export == 4) {
+               print $3;
+               donelist[$3] = export;
+           } else
+               print "# Warning:", $3,
+                   "was not in the nm list for this library" | "cat 1>&2";
+       }
+
+       next;
+    }
+    END { 
+       # Ignore built-in linker symbols.
+       if (implicit == 0) {
+           if (!donelist["_DYNAMIC"])
+               donelist["_DYNAMIC"] = 1;
+           if (!donelist["_GLOBAL_OFFSET_TABLE_"])
+               donelist["_GLOBAL_OFFSET_TABLE_"] = 1;
+           if (!donelist["_edata"])
+               donelist["_edata"] = 1;
+           if (!donelist["_end"])
+               donelist["_end"] = 1;
+           if (!donelist["_etext"])
+               donelist["_etext"] = 1;
+       }
+
+       # Process implicit symbols.
+       for (i in syms) {
+           if (!donelist[i] && (length(syms[i]) > 0)) {
+               # Ignore C++ compiler symbols
+               if (implicit == 0 &&
+                   (syms[i] !~ /^__vtbl__[0-9]*_/) &&
+                   (syms[i] !~ /^__cpp_unixware_[0-9]*$/))
+                   print "# Warning:", syms[i],
+                         "was not in the export list" | "cat 1>&2";
+               if (implicit > 1)
+                   print syms[i];
+           }
+       }
+    }
+'
+
+XCOMM Clean up temporary files
+rm $EXPORTLIST
+rm $NMLIST
+rm $FILTLIST
diff --git a/Xserver/config/util/gccmdep.cpp b/Xserver/config/util/gccmdep.cpp
new file mode 100644 (file)
index 0000000..d8c25ad
--- /dev/null
@@ -0,0 +1,136 @@
+XCOMM!/bin/sh
+
+XCOMM
+XCOMM makedepend which uses 'gcc -M'
+XCOMM
+XCOMM $XFree86: xc/config/util/gccmdep.cpp,v 3.3 1996/02/25 01:16:15 dawes Exp $
+XCOMM
+XCOMM Based on mdepend.cpp and code supplied by Hongjiu Lu <hjl@nynexst.com>
+XCOMM
+
+TMP=/tmp/mdep$$
+CC=CCCMD
+RM=RMCMD
+LN=LNCMD
+MV=MVCMD
+
+trap "$RM ${TMP}*; exit 1" 1 2 15
+trap "$RM ${TMP}*; exit 0" 1 2 13
+
+files=
+makefile=
+endmarker=
+magic_string='# DO NOT DELETE'
+append=n
+args=
+asmfiles=
+
+while [ $# != 0 ]; do
+    if [ "$endmarker"x != x -a "$endmarker" = "$1" ]; then
+       endmarker=
+    else
+       case "$1" in
+           -D*|-I*)
+               args="$args '$1'"
+               ;;
+           -g|-o)
+               ;;
+           *)
+               if [ "$endmarker"x = x ]; then
+                   case $1 in
+XCOMM ignore these flags
+                       -w|-o|-cc)
+                           shift
+                           ;;
+                       -v)
+                           ;;
+                       -s)
+                           magic_string="$2"
+                           shift
+                           ;;
+                       -f-)
+                           makefile="-"
+                           ;;
+                       -f)
+                           makefile="$2"
+                           shift
+                           ;;
+                       --*)
+                           endmarker=`echo $1 | sed 's/^\-\-//'`
+                           if [ "$endmarker"x = x ]; then
+                               endmarker="--"
+                           fi
+                           ;;
+                       -a)
+                           append=y
+                           ;;
+                       -*)
+                           echo "Unknown option '$1' ignored" 1>&2
+                           ;;
+                       *)
+                           files="$files $1"
+                           ;;
+                   esac
+               fi
+               ;;
+       esac
+    fi
+    shift
+done
+
+if [ x"$files" = x ]; then
+XCOMM Nothing to do
+    exit 0
+fi
+
+case "$makefile" in
+    '')
+       if [ -r makefile ]; then
+           makefile=makefile
+       elif [ -r Makefile ]; then
+           makefile=Makefile
+       else
+           echo 'no makefile or Makefile found' 1>&2
+           exit 1
+       fi
+       ;;
+esac
+
+if [ X"$makefile" != X- ]; then
+    if [ x"$append" = xn ]; then
+        sed -e "/^$magic_string/,\$d" < $makefile > $TMP
+        echo "$magic_string" >> $TMP
+    else
+        cp $makefile $TMP
+    fi
+fi
+
+XCOMM need to link .s files to .S
+for i in $files; do
+    case $i in
+       *.s)
+           dir=`dirname $i`
+           base=`basename $i .s`
+           (cd $dir; $RM ${base}.S; $LN ${base}.s ${base}.S)
+           asmfiles="$asmfiles ${base}.S"
+           ;;
+    esac
+done
+
+CMD="$CC -M $args `echo $files | sed -e 's,\.s$,\.S,g' -e 's,\.s ,\.S ,g'` | \
+       sed -e 's,\.S$,\.s,g' -e 's,\.S ,\.s ,g'"
+if [ X"$makefile" != X- ]; then
+    CMD="$CMD >> $TMP"
+fi
+eval $CMD
+if [ X"$makefile" != X- ]; then
+    $RM ${makefile}.bak
+    $MV $makefile ${makefile}.bak
+    $MV $TMP $makefile
+fi
+
+if [ x"$asmfiles" != x ]; then
+    $RM $asmfiles
+fi
+$RM ${TMP}*
+exit 0
diff --git a/Xserver/config/util/indir.cmd b/Xserver/config/util/indir.cmd
new file mode 100644 (file)
index 0000000..7120274
--- /dev/null
@@ -0,0 +1,23 @@
+/* OS/2 rexx script to emulate the "cd dir; command" mechanism in make
+ * which does not work with stupid CMD.EXE
+ *
+ * $XFree86: xc/config/util/indir.cmd,v 3.1 1996/01/24 21:56:12 dawes Exp $
+ */
+curdir = directory()
+line = fixbadprefix(arg(1))
+new = directory(word(line,1))
+subword(line,2)
+old = directory(curdir)
+exit
+
+/* somehow make or cmd manages to convert a relative path ..\..\. to ..... */
+fixbadprefix:
+count = 1
+str = ARG(1)
+DO WHILE SUBSTR(str,count,2) = '..'
+   count = count+1
+   str = INSERT('\',str,count)
+   count = count+2
+END
+RETURN str
+
diff --git a/Xserver/config/util/install.sh b/Xserver/config/util/install.sh
new file mode 100755 (executable)
index 0000000..33d8e0d
--- /dev/null
@@ -0,0 +1,108 @@
+#!/bin/sh
+
+#
+# install - install a program, script, or datafile
+#
+# $XConsortium: install.sh,v 1.2 89/12/18 14:47:22 jim Exp $
+#
+# This script is compatible with the BSD install script, but was written
+# from scratch.
+#
+
+
+# set DOITPROG to echo to test this script
+
+doit="${DOITPROG:-}"
+
+
+# put in absolute paths if you don't have them in your path; or use env. vars.
+
+mvprog="${MVPROG:-mv}"
+cpprog="${CPPROG:-cp}"
+chmodprog="${CHMODPROG:-chmod}"
+chownprog="${CHOWNPROG:-chown}"
+chgrpprog="${CHGRPPROG:-chgrp}"
+stripprog="${STRIPPROG:-strip}"
+rmprog="${RMPROG:-rm}"
+
+instcmd="$mvprog"
+chmodcmd=""
+chowncmd=""
+chgrpcmd=""
+stripcmd=""
+rmcmd="$rmprog -f"
+src=""
+dst=""
+
+while [ x"$1" != x ]; do
+    case $1 in
+       -c) instcmd="$cpprog"
+           shift
+           continue;;
+
+       -m) chmodcmd="$chmodprog $2"
+           shift
+           shift
+           continue;;
+
+       -o) chowncmd="$chownprog $2"
+           shift
+           shift
+           continue;;
+
+       -g) chgrpcmd="$chgrpprog $2"
+           shift
+           shift
+           continue;;
+
+       -s) stripcmd="$stripprog"
+           shift
+           continue;;
+
+       *)  if [ x"$src" = x ]
+           then
+               src=$1
+           else
+               dst=$1
+           fi
+           shift
+           continue;;
+    esac
+done
+
+if [ x"$src" = x ]
+then
+       echo "install:  no input file specified"
+       exit 1
+fi
+
+if [ x"$dst" = x ]
+then
+       echo "install:  no destination specified"
+       exit 1
+fi
+
+
+# if destination is a directory, append the input filename; if your system
+# does not like double slashes in filenames, you may need to add some logic
+
+if [ -d $dst ]
+then
+       dst="$dst"/`basename $src`
+fi
+
+
+# get rid of the old one and mode the new one in
+
+$doit $rmcmd $dst
+$doit $instcmd $src $dst
+
+
+# and set any options; do chmod last to preserve setuid bits
+
+if [ x"$chowncmd" != x ]; then $doit $chowncmd $dst; fi
+if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dst; fi
+if [ x"$stripcmd" != x ]; then $doit $stripcmd $dst; fi
+if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dst; fi
+
+exit 0
diff --git a/Xserver/config/util/instos2.cmd b/Xserver/config/util/instos2.cmd
new file mode 100644 (file)
index 0000000..501cf67
--- /dev/null
@@ -0,0 +1,13 @@
+@echo off
+rem $XFree86: xc/config/util/instos2.cmd,v 3.0 1996/01/24 21:56:14 dawes Exp $
+rem this file is supposed to run from the xc/ dir.
+rem you must copy it manually to there before using. It is just here
+rem in order not to be in the root dir.
+rem
+set GCCOPT=-pipe
+set EMXLOAD=5
+emxload make.exe gcc.exe rm.exe mv.exe
+make SHELL= MFLAGS="CC=gcc" install 2>&1 | tee instxc.log
+rem
+rem
+echo INSTALL OF XFREE86/OS2 IS FINISHED
diff --git a/Xserver/config/util/lndir.c b/Xserver/config/util/lndir.c
new file mode 100644 (file)
index 0000000..1ffb9c4
--- /dev/null
@@ -0,0 +1,357 @@
+/* $XConsortium: lndir.c /main/16 1996/09/28 16:16:40 rws $ */
+/* $XFree86: xc/config/util/lndir.c,v 3.6 1997/01/18 06:51:01 dawes Exp $ */
+/* Create shadow link tree (after X11R4 script of the same name)
+   Mark Reinhold (mbr@lcs.mit.edu)/3 January 1990 */
+
+/* 
+Copyright (c) 1990,  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+*/
+
+/* From the original /bin/sh script:
+
+  Used to create a copy of the a directory tree that has links for all
+  non-directories (except those named RCS, SCCS or CVS.adm).  If you are
+  building the distribution on more than one machine, you should use
+  this technique.
+
+  If your master sources are located in /usr/local/src/X and you would like
+  your link tree to be in /usr/local/src/new-X, do the following:
+
+       %  mkdir /usr/local/src/new-X
+       %  cd /usr/local/src/new-X
+       %  lndir ../X
+*/
+
+#include <X11/Xos.h>
+#include <X11/Xfuncproto.h>
+#include <stdio.h>
+#include <sys/stat.h>
+#if !defined(MINIX) && !defined(Lynx)
+#include <sys/param.h>
+#endif
+#include <errno.h>
+
+#ifndef X_NOT_POSIX
+#include <dirent.h>
+#else
+#ifdef SYSV
+#include <dirent.h>
+#else
+#ifdef USG
+#include <dirent.h>
+#else
+#include <sys/dir.h>
+#ifndef dirent
+#define dirent direct
+#endif
+#endif
+#endif
+#endif
+#ifndef MAXPATHLEN
+#define MAXPATHLEN 2048
+#endif
+
+#if NeedVarargsPrototypes
+#include <stdarg.h>
+#endif
+
+#ifdef X_NOT_STDC_ENV
+extern int errno;
+#endif
+int silent = 0;                        /* -silent */
+int ignore_links = 0;          /* -ignorelinks */
+
+char *rcurdir;
+char *curdir;
+
+void
+quit (
+#if NeedVarargsPrototypes
+    int code, char * fmt, ...)
+#else
+    code, fmt, a1, a2, a3)
+    char *fmt;
+#endif
+{
+#if NeedVarargsPrototypes
+    va_list args;
+    va_start(args, fmt);
+    vfprintf (stderr, fmt, args);
+    va_end(args);
+#else
+    fprintf (stderr, fmt, a1, a2, a3);
+#endif
+    putc ('\n', stderr);
+    exit (code);
+}
+
+void
+quiterr (code, s)
+    char *s;
+{
+    perror (s);
+    exit (code);
+}
+
+void
+msg (
+#if NeedVarargsPrototypes
+    char * fmt, ...)
+#else
+    fmt, a1, a2, a3)
+    char *fmt;
+#endif
+{
+#if NeedVarargsPrototypes
+    va_list args;
+#endif
+    if (curdir) {
+       fprintf (stderr, "%s:\n", curdir);
+       curdir = 0;
+    }
+#if NeedVarargsPrototypes
+    va_start(args, fmt);
+    vfprintf (stderr, fmt, args);
+    va_end(args);
+#else
+    fprintf (stderr, fmt, a1, a2, a3);
+#endif
+    putc ('\n', stderr);
+}
+
+void
+mperror (s)
+    char *s;
+{
+    if (curdir) {
+       fprintf (stderr, "%s:\n", curdir);
+       curdir = 0;
+    }
+    perror (s);
+}
+
+
+int equivalent(lname, rname)
+    char *lname;
+    char *rname;
+{
+    char *s;
+
+    if (!strcmp(lname, rname))
+       return 1;
+    for (s = lname; *s && (s = strchr(s, '/')); s++) {
+       while (s[1] == '/')
+           strcpy(s+1, s+2);
+    }
+    return !strcmp(lname, rname);
+}
+
+
+/* Recursively create symbolic links from the current directory to the "from"
+   directory.  Assumes that files described by fs and ts are directories. */
+
+dodir (fn, fs, ts, rel)
+char *fn;                      /* name of "from" directory, either absolute or
+                                  relative to cwd */
+struct stat *fs, *ts;          /* stats for the "from" directory and cwd */
+int rel;                       /* if true, prepend "../" to fn before using */
+{
+    DIR *df;
+    struct dirent *dp;
+    char buf[MAXPATHLEN + 1], *p;
+    char symbuf[MAXPATHLEN + 1];
+    char basesym[MAXPATHLEN + 1];
+    struct stat sb, sc;
+    int n_dirs;
+    int symlen;
+    int basesymlen = -1;
+    char *ocurdir;
+
+    if ((fs->st_dev == ts->st_dev) && (fs->st_ino == ts->st_ino)) {
+       msg ("%s: From and to directories are identical!", fn);
+       return 1;
+    }
+
+    if (rel)
+       strcpy (buf, "../");
+    else
+       buf[0] = '\0';
+    strcat (buf, fn);
+    
+    if (!(df = opendir (buf))) {
+       msg ("%s: Cannot opendir", buf);
+       return 1;
+    }
+
+    p = buf + strlen (buf);
+    *p++ = '/';
+    n_dirs = fs->st_nlink;
+    while (dp = readdir (df)) {
+       if (dp->d_name[strlen(dp->d_name) - 1] == '~')
+           continue;
+       strcpy (p, dp->d_name);
+
+       if (n_dirs > 0) {
+           if (stat (buf, &sb) < 0) {
+               mperror (buf);
+               continue;
+           }
+
+#ifdef S_ISDIR
+           if(S_ISDIR(sb.st_mode))
+#else
+           if (sb.st_mode & S_IFDIR) 
+#endif
+           {
+               /* directory */
+               n_dirs--;
+               if (dp->d_name[0] == '.' &&
+                   (dp->d_name[1] == '\0' || (dp->d_name[1] == '.' &&
+                                              dp->d_name[2] == '\0')))
+                   continue;
+               if (!strcmp (dp->d_name, "RCS"))
+                   continue;
+               if (!strcmp (dp->d_name, "SCCS"))
+                   continue;
+               if (!strcmp (dp->d_name, "CVS"))
+                   continue;
+               if (!strcmp (dp->d_name, "CVS.adm"))
+                   continue;
+               ocurdir = rcurdir;
+               rcurdir = buf;
+               curdir = silent ? buf : (char *)0;
+               if (!silent)
+                   printf ("%s:\n", buf);
+               if ((stat (dp->d_name, &sc) < 0) && (errno == ENOENT)) {
+                   if (mkdir (dp->d_name, 0777) < 0 ||
+                       stat (dp->d_name, &sc) < 0) {
+                       mperror (dp->d_name);
+                       curdir = rcurdir = ocurdir;
+                       continue;
+                   }
+               }
+               if (readlink (dp->d_name, symbuf, sizeof(symbuf) - 1) >= 0) {
+                   msg ("%s: is a link instead of a directory", dp->d_name);
+                   curdir = rcurdir = ocurdir;
+                   continue;
+               }
+               if (chdir (dp->d_name) < 0) {
+                   mperror (dp->d_name);
+                   curdir = rcurdir = ocurdir;
+                   continue;
+               }
+               dodir (buf, &sb, &sc, (buf[0] != '/'));
+               if (chdir ("..") < 0)
+                   quiterr (1, "..");
+               curdir = rcurdir = ocurdir;
+               continue;
+           }
+       }
+
+       /* non-directory */
+       symlen = readlink (dp->d_name, symbuf, sizeof(symbuf) - 1);
+       if (symlen >= 0)
+           symbuf[symlen] = '\0';
+
+       /* The option to ignore links exists mostly because
+          checking for them slows us down by 10-20%.
+          But it is off by default because this really is a useful check. */
+       if (!ignore_links) {
+           /* see if the file in the base tree was a symlink */
+           basesymlen = readlink(buf, basesym, sizeof(basesym) - 1);
+           if (basesymlen >= 0)
+               basesym[basesymlen] = '\0';
+       }
+
+       if (symlen >= 0) {
+           /* Link exists in new tree.  Print message if it doesn't match. */
+           if (!equivalent (basesymlen>=0 ? basesym : buf, symbuf))
+               msg ("%s: %s", dp->d_name, symbuf);
+       } else {
+           if (symlink (basesymlen>=0 ? basesym : buf, dp->d_name) < 0)
+               mperror (dp->d_name);
+       }
+    }
+
+    closedir (df);
+    return 0;
+}
+
+
+main (ac, av)
+int ac;
+char **av;
+{
+    char *prog_name = av[0];
+    char *fn, *tn;
+    struct stat fs, ts;
+
+    while (++av, --ac) {
+       if (strcmp(*av, "-silent") == 0)
+           silent = 1;
+       else if (strcmp(*av, "-ignorelinks") == 0)
+           ignore_links = 1;
+       else if (strcmp(*av, "--") == 0) {
+           ++av, --ac;
+           break;
+       }
+       else
+           break;
+    }
+
+    if (ac < 1 || ac > 2)
+       quit (1, "usage: %s [-silent] [-ignorelinks] fromdir [todir]",
+             prog_name);
+
+    fn = av[0];
+    if (ac == 2)
+       tn = av[1];
+    else
+       tn = ".";
+
+    /* to directory */
+    if (stat (tn, &ts) < 0)
+       quiterr (1, tn);
+#ifdef S_ISDIR
+    if (!(S_ISDIR(ts.st_mode)))
+#else
+    if (!(ts.st_mode & S_IFDIR))
+#endif
+       quit (2, "%s: Not a directory", tn);
+    if (chdir (tn) < 0)
+       quiterr (1, tn);
+
+    /* from directory */
+    if (stat (fn, &fs) < 0)
+       quiterr (1, fn);
+#ifdef S_ISDIR
+    if (!(S_ISDIR(fs.st_mode)))
+#else
+    if (!(fs.st_mode & S_IFDIR))
+#endif
+       quit (2, "%s: Not a directory", fn);
+
+    exit (dodir (fn, &fs, &ts, 0));
+}
diff --git a/Xserver/config/util/lndir.man b/Xserver/config/util/lndir.man
new file mode 100644 (file)
index 0000000..b56bbf2
--- /dev/null
@@ -0,0 +1,129 @@
+.\" $XConsortium: lndir.man /main/10 1996/09/28 16:16:45 rws $
+.\"
+.\" Copyright (c) 1993, 1994  X Consortium
+.\" 
+.\" Permission is hereby granted, free of charge, to any person obtaining
+.\" a copy of this software and associated documentation files (the
+.\" "Software"), to deal in the Software without restriction, including
+.\" without limitation the rights to use, copy, modify, merge, publish,
+.\" distribute, sublicense, and/or sell copies of the Software, and to
+.\" permit persons to whom the Software is furnished to do so, subject to
+.\" the following conditions:
+.\" 
+.\" The above copyright notice and this permission notice shall be
+.\" included in all copies or substantial portions of the Software.
+.\" 
+.\" THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+.\" EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+.\" MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+.\" IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR
+.\" OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+.\" ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+.\" OTHER DEALINGS IN THE SOFTWARE.
+.\" 
+.\" Except as contained in this notice, the name of the X Consortium shall
+.\" not be used in advertising or otherwise to promote the sale, use or
+.\" other dealings in this Software without prior written authorization
+.\" from the X Consortium.
+.\" 
+.TH LNDIR 1 "Release 6.1" "X Version 11"
+.SH NAME
+lndir \- create a shadow directory of symbolic links to another directory tree
+.SH SYNOPSIS
+.B lndir
+[
+.B \-silent
+] [
+.B \-ignorelinks
+]
+.I \|fromdir\|
+[
+.I todir
+]
+.SH DESCRIPTION
+The
+.I lndir
+program makes a shadow copy 
+.I todir 
+of a directory tree
+.I fromdir, 
+except that the shadow is not
+populated with real files but instead with symbolic links pointing at
+the real files in the 
+.I fromdir
+directory tree.  This is usually useful for maintaining source code for
+different machine architectures.  You create a shadow directory
+containing links to the real source, which you will have usually
+mounted from a remote machine.  You can build in the shadow tree, and
+the object files will be in the shadow directory, while the
+source files in the shadow directory are just symlinks to the real
+files.
+.PP
+This scheme has the advantage that if you update the source, you need not 
+propagate the change to the other architectures by hand, since all
+source in all shadow directories are symlinks to the real thing: just cd
+to the shadow directory and recompile away.
+.PP
+The
+.I todir
+argument is optional and defaults to the current directory.  The
+.I fromdir
+argument may be relative (e.g., ../src) and is relative to
+.I todir
+(not the current directory).
+.PP 
+.\" CVS.adm is used by the Concurrent Versions System.
+Note that RCS, SCCS, CVS and CVS.adm directories are not shadowed.
+.PP
+If you add files, simply run
+.I lndir
+again.  New files will be silently added.  Old files will be
+checked that they have the correct link.
+.PP
+Deleting files is a more painful problem; the symlinks will
+just point into never never land.
+.PP
+If a file in \fIfromdir\fP is a symbolic link, \fIlndir\fP will make
+the same link in \fItodir\fP rather than making a link back to the
+(symbolic link) entry in \fIfromdir.\fP  The \fB\-ignorelinks\fP flag
+changes this behavior.
+.SH OPTIONS
+.IP \-silent
+Normally \fIlndir\fP outputs the name of each subdirectory as it
+descends into it.  The \fB\-silent\fP option suppresses these status
+messages.
+.IP \-ignorelinks
+Causes the program to not treat symbolic links in \fIfromdir\fP
+specially.  The link created in \fItodir\fP will point back to the
+corresponding (symbolic link) file in \fIfromdir\fP.
+If the link is to a directory, this is almost certainly the wrong thing.
+.IP
+This option exists mostly to emulate the behavior the C version of
+\fIlndir\fP had in X11R6.  Its use is not recommended.
+.SH DIAGNOSTICS
+The program displays the name of each subdirectory it enters, followed
+by a colon.  The \fB\-silent\fP option suppresses these messages.
+.PP
+A warning message is displayed if the symbolic link cannot be created.
+The usual problem is that a regular file of the same name already
+exists.
+.PP
+If the link already exists but doesn't point to the correct file, the
+program prints the link name and the location where it does point.
+.SH BUGS
+The
+.I patch
+program gets upset if it cannot change the files.  You should never run
+.I patch
+from a shadow directory anyway.
+.PP
+You need to use something like
+.nf
+       find todir \|\-type l \|\-print \||\| xargs rm
+.fi
+to clear out all files before you can relink (if fromdir moved, for instance).
+Something like
+.nf
+        find . \|\\! \|\-type d \|\-print
+.fi
+will find all files that are not directories.
diff --git a/Xserver/config/util/makeg.man b/Xserver/config/util/makeg.man
new file mode 100644 (file)
index 0000000..8ded8b0
--- /dev/null
@@ -0,0 +1,63 @@
+.\" $XConsortium: makeg.man /main/1 1996/02/02 18:48:20 gildea $
+.\" Copyright (c) 1996  X Consortium
+.\" 
+.\" Permission is hereby granted, free of charge, to any person obtaining
+.\" a copy of this software and associated documentation files (the
+.\" "Software"), to deal in the Software without restriction, including
+.\" without limitation the rights to use, copy, modify, merge, publish,
+.\" distribute, sublicense, and/or sell copies of the Software, and to
+.\" permit persons to whom the Software is furnished to do so, subject to
+.\" the following conditions:
+.\" 
+.\" The above copyright notice and this permission notice shall be
+.\" included in all copies or substantial portions of the Software.
+.\" 
+.\" THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+.\" EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+.\" MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+.\" IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR
+.\" OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+.\" ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+.\" OTHER DEALINGS IN THE SOFTWARE.
+.\" 
+.\" Except as contained in this notice, the name of the X Consortium shall
+.\" not be used in advertising or otherwise to promote the sale, use or
+.\" other dealings in this Software without prior written authorization
+.\" from the X Consortium.
+.\"
+.TH MAKEG 1 "Release 6.1" "X Version 11"
+.SH NAME
+makeg \- make a debuggable executable
+.SH SYNOPSIS
+.B makeg
+[
+.I make-options .\|.\|.
+] [
+.I targets  .\|.\|.
+]
+.SH DESCRIPTION
+The
+.I makeg
+script runs
+.I make,
+passing it variable settings to create a debuggable target when used
+with a Makefile generated by
+.I imake.
+For example, it arranges for the C compiler to be called with the
+.B \-g
+option.
+.SH ENVIRONMENT
+.TP 8
+.B MAKE
+The
+.I make
+program to use.  Default ``make''.
+.TP 8
+.B GDB
+Set to a non-null value if using the
+.I gdb
+debugger on Solaris 2, which requires additional debugging options to
+be passed to the compiler.
+.SH "SEE ALSO"
+.I make (1),
+.I imake (1)
diff --git a/Xserver/config/util/makeg.sh b/Xserver/config/util/makeg.sh
new file mode 100755 (executable)
index 0000000..0b68a10
--- /dev/null
@@ -0,0 +1,13 @@
+#! /bin/sh
+# makeg - run "make" with options necessary to make a debuggable executable
+# $XConsortium: makeg.sh /main/4 1996/06/13 11:45:08 ray $
+
+# set GDB=1 in your environment if using gdb on Solaris 2.
+
+make="${MAKE-make}"
+flags="CDEBUGFLAGS=-g CXXDEBUGFLAGS=-g"
+
+# gdb on Solaris needs the stabs included in the executable
+test "${GDB+yes}" = yes && flags="$flags -xs"
+
+exec "$make" $flags LDSTRIPFLAGS= ${1+"$@"}
diff --git a/Xserver/config/util/makestrs.c b/Xserver/config/util/makestrs.c
new file mode 100644 (file)
index 0000000..d2a9551
--- /dev/null
@@ -0,0 +1,741 @@
+/* $XConsortium: makestrs.c /main/10 1996/11/22 07:27:41 kaleb $ */
+
+/*
+
+Copyright (c) 1991  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+*/
+
+/* Constructs string definitions */
+
+#include <stdio.h>
+#include <X11/Xos.h>
+#ifndef X_NOT_STDC_ENV
+#include <stdlib.h>
+#else
+char *malloc();
+#endif
+#if defined(macII) && !defined(__STDC__)  /* stdlib.h fails to define these */
+char *malloc();
+#endif /* macII */
+
+typedef struct _TableEnt {
+    struct _TableEnt* next;
+    char* left;
+    char* right;
+    int offset;
+} TableEnt;
+
+typedef struct _Table {
+    struct _Table* next;
+    TableEnt* tableent;
+    TableEnt* tableentcurrent;
+    TableEnt** tableenttail;
+    char* name;
+    int offset;
+} Table;
+
+typedef struct _File {
+    struct _File* next;
+    FILE* tmpl;
+    char* name;
+    Table* table;
+    Table* tablecurrent;
+    Table** tabletail;
+} File;
+
+static File* file = NULL;
+static File* filecurrent = NULL;
+static File** filetail = &file;
+static char* conststr;
+static char* prefixstr = NULL;
+static char* featurestr = NULL;
+static char* ctmplstr = NULL;
+static char* fileprotstr;
+static char* externrefstr;
+static char* externdefstr;
+
+#define X_DEFAULT_ABI  0
+#define X_ARRAYPER_ABI 1
+#define X_INTEL_ABI    2
+#define X_INTEL_ABI_BC 3
+#define X_SPARC_ABI    4
+#define X_FUNCTION_ABI 5
+
+#define X_MAGIC_STRING "<<<STRING_TABLE_GOES_HERE>>>"
+
+static void WriteHeaderProlog (f, phile)
+    FILE* f;
+    File* phile;
+{
+    Table* t;
+    TableEnt* te;
+
+    (void) fprintf (f, "#ifdef %s\n", featurestr);
+    for (t = phile->table; t; t = t->next)
+       for (te = t->tableent; te; te = te->next) {
+           if (strcmp (te->left, "RAtom") == 0) {
+               (void) fprintf (f, 
+                       "#ifndef %s%s\n#define %s%s \"%s\"\n#endif\n",
+                       prefixstr, te->left, prefixstr, te->left, te->right);
+           } else {
+               (void) fprintf (f, 
+                       "#define %s%s \"%s\"\n",
+                       prefixstr, te->left, te->right);
+           }
+       }
+    (void) fprintf (f, "%s", "#else\n");
+}
+
+static void IntelABIWriteHeader (f, phile)
+    FILE* f;
+    File* phile;
+{
+    Table* t;
+    TableEnt* te;
+
+    WriteHeaderProlog (f, phile);
+
+    for (t = phile->table; t; t = t->next) {
+      (void) fprintf (f, "%s %sConst char %s[];\n", 
+                     externrefstr, conststr ? conststr : fileprotstr, t->name);
+       for (te = t->tableent; te; te = te->next)
+           (void) fprintf (f, 
+               "#ifndef %s%s\n#define %s%s ((char*)&%s[%d])\n#endif\n",
+               prefixstr, te->left, prefixstr, te->left, t->name, te->offset);
+    }
+
+    (void) fprintf (f, "#endif /* %s */\n", featurestr);
+}
+
+static void SPARCABIWriteHeader (f, phile)
+    FILE* f;
+    File* phile;
+{
+    Table* t;
+    TableEnt* te;
+
+    for (t = phile->table; t; t = t->next)
+       for (te = t->tableent; te; te = te->next)
+           (void) fprintf (f, "#define %s%s \"%s\"\n",
+                           prefixstr, te->left, te->right);
+}
+
+static void FunctionWriteHeader (f, phile)
+    FILE* f;
+    File* phile;
+{
+    Table* t;
+    TableEnt* te;
+
+    WriteHeaderProlog (f, phile);
+
+    (void) fprintf (f, "%s %sConst char* %s();\n", 
+                   externrefstr, conststr ? conststr : fileprotstr, 
+                   phile->table->name);
+
+    for (t = phile->table; t; t = t->next)
+       for (te = t->tableent; te; te = te->next)
+           (void) fprintf (f, 
+               "#ifndef %s%s\n#define %s%s (%s(%d))\n#endif\n",
+               prefixstr, te->left, prefixstr, te->left, phile->table->name, 
+               te->offset);
+
+    (void) fprintf (f, "#endif /* %s */\n", featurestr);
+}
+
+static void ArrayperWriteHeader (f, phile)
+    FILE* f;
+    File* phile;
+{
+    Table* t;
+    TableEnt* te;
+
+    WriteHeaderProlog (f, phile);
+
+    for (t = phile->table; t; t = t->next)
+        for (te = t->tableent; te; te = te->next)
+           (void) fprintf (f, 
+                           "#ifndef %s%s\n%s %sConst char %s%s[];\n#endif\n",
+                           prefixstr, te->left, 
+                           externrefstr, conststr ? conststr : fileprotstr, 
+                           prefixstr, te->left);
+
+    (void) fprintf (f, "#endif /* %s */\n", featurestr);
+}
+
+static void DefaultWriteHeader (f, phile)
+    FILE* f;
+    File* phile;
+{
+    Table* t;
+    TableEnt* te;
+
+    WriteHeaderProlog (f, phile);
+
+    (void) fprintf (f, "%s %sConst char %s[];\n", 
+                   externrefstr, conststr ? conststr : fileprotstr, 
+                   phile->table->name);
+
+    for (t = phile->table; t; t = t->next)
+       for (te = t->tableent; te; te = te->next)
+           (void) fprintf (f, 
+               "#ifndef %s%s\n#define %s%s ((char*)&%s[%d])\n#endif\n",
+               prefixstr, te->left, prefixstr, te->left, phile->table->name, 
+               te->offset);
+
+    (void) fprintf (f, "#endif /* %s */\n", featurestr);
+}
+
+static void CopyTmplProlog (tmpl, f)
+    FILE* tmpl;
+    FILE* f;
+{
+    char buf[1024];
+    static char* magic_string = X_MAGIC_STRING;
+    int magic_string_len = strlen (magic_string);
+
+    while (fgets (buf, sizeof buf, tmpl)) {
+       if (strncmp (buf, magic_string, magic_string_len) == 0) {
+           return;
+       }
+       (void) fputs (buf, f);
+    }
+}
+
+static void CopyTmplEpilog (tmpl, f)
+    FILE* tmpl;
+    FILE* f;
+{
+    char buf[1024];
+
+    while (fgets (buf, sizeof buf, tmpl))
+       (void) fputs (buf, f);
+}
+
+static char* abistring[] = {
+    "Default", "Array per string", "Intel", "Intel BC", "SPARC", "Function" };
+
+static void WriteHeader (tagline, phile, abi)
+    char* tagline;
+    File* phile;
+    int abi;
+{
+    FILE* f;
+    char* tmp;
+    Table* t;
+    TableEnt* te;
+    static void (*headerproc[])() = { 
+       DefaultWriteHeader, ArrayperWriteHeader,
+       IntelABIWriteHeader, IntelABIWriteHeader,
+       SPARCABIWriteHeader, FunctionWriteHeader };
+
+    if ((f = fopen (phile->name, "w+")) == NULL) exit (1);
+
+    if (phile->tmpl) CopyTmplProlog (phile->tmpl, f);
+
+    (void) fprintf (f, 
+       "%s\n%s\n/* %s ABI version -- Do not edit */\n", 
+       "/* $XConsortium: makestrs.c /main/10 1996/11/22 07:27:41 kaleb $ */",
+       "/* This file is automatically generated. */",
+       abistring[abi]);
+
+    if (tagline) (void) fprintf (f, "/* %s */\n\n", tagline);
+
+    /* do the right thing for Motif, i.e. avoid _XmXmStrDefs_h_ */
+    if (strcmp (prefixstr, "Xm") == 0) {
+       if ((fileprotstr = malloc (strlen (phile->name) + 3)) == NULL)
+          exit (1);
+       (void) sprintf (fileprotstr, "_%s_", phile->name);
+    } else {
+       if ((fileprotstr = malloc (strlen (phile->name) + strlen (prefixstr) +  3)) == NULL)
+          exit (1);
+       (void) sprintf (fileprotstr, "_%s%s_", prefixstr, phile->name);
+    }
+
+    for (tmp = fileprotstr; *tmp; tmp++) if (*tmp == '.') *tmp = '_';
+
+    (*headerproc[abi])(f, phile);
+
+    if (phile->tmpl) CopyTmplEpilog (phile->tmpl, f);
+
+    (void) free (fileprotstr);
+    (void) fclose (phile->tmpl);
+    (void) fclose (f);
+}
+
+static void WriteSourceLine (te, abi, fudge)
+    TableEnt* te;
+    int abi;
+{
+    char* c;
+
+    for (c = te->right; *c; c++) (void) printf ("'%c',", *c);
+    (void) printf ("%c", '0');
+    if (te->next || fudge) (void) printf ("%c", ',');
+    (void) printf ("%s", "\n");
+}
+
+static char* const_string = "%s %sConst char %s[] = {\n";
+
+static void IntelABIWriteSource (abi)
+    int abi;
+{
+    File* phile;
+
+    for (phile = file; phile; phile = phile->next) {
+       Table* t;
+       TableEnt* te;
+
+       for (t = phile->table; t; t = t->next) {
+           (void) printf (const_string, externdefstr, 
+                          conststr ? conststr : "", t->name);
+           for (te = t->tableent; te; te = te->next)
+               WriteSourceLine (te, abi, 0);
+           (void) printf ("%s\n\n", "};");
+       }
+    }
+}
+
+static void IntelABIBCWriteSource (abi)
+    int abi;
+{
+    File* phile;
+
+    for (phile = file; phile; phile = phile->next) {
+       Table* t;
+       TableEnt* te;
+
+       (void) printf (const_string, externdefstr, 
+                      conststr ? conststr : "", phile->table->name);
+
+       for (t = phile->table; t; t = t->next) 
+           for (te = t->tableent; te; te = te->next)
+               WriteSourceLine (te, abi, t->next ? 1 : 0);
+       (void) printf ("%s\n\n", "};");
+
+       if (phile->table->next) {
+           (void) printf (const_string, externdefstr, 
+                          conststr ? conststr : "", phile->table->next->name);
+           for (t = phile->table->next; t; t = t->next) 
+               for (te = t->tableent; te; te = te->next)
+                   WriteSourceLine (te, abi, 0);
+           (void) printf ("%s\n\n", "};");
+       }
+    }
+}
+
+static void FunctionWriteSource (abi)
+    int abi;
+{
+    File* phile;
+
+    for (phile = file; phile; phile = phile->next) {
+       Table* t;
+       TableEnt* te;
+
+       (void) printf ("static %sConst char _%s[] = {\n", 
+                      conststr ? conststr : "", phile->table->name);
+
+       for (t = phile->table; t; t = t->next) 
+           for (te = t->tableent; te; te = te->next)
+               WriteSourceLine (te, abi, t->next ? 1 : 0);
+       (void) printf ("%s\n\n", "};");
+
+       (void) printf ("%sConst char* %s(index)\n    int index;\n{\n    return &_%s[index];\n}\n\n",
+                      conststr ? conststr : "", 
+                      phile->table->name, phile->table->name);
+    }
+}
+
+static void ArrayperWriteSource (abi)
+    int abi;
+{
+    File* phile;
+    static int done_atom;
+
+    for (phile = file; phile; phile = phile->next) {
+       Table* t;
+       TableEnt* te;
+
+       for (t = phile->table; t; t = t->next) 
+           for (te = t->tableent; te; te = te->next) {
+               if (strcmp (te->left, "RAtom") == 0) {
+                   if (done_atom) return;
+                   done_atom = 1;
+               }
+               (void) printf ("%s %sConst char %s%s[] = \"%s\";\n",
+                              externdefstr, conststr ? conststr : prefixstr, 
+                              te->left, te->right);
+           }
+    }
+}
+
+static void DefaultWriteSource (abi)
+    int abi;
+{
+    File* phile;
+
+    for (phile = file; phile; phile = phile->next) {
+       Table* t;
+       TableEnt* te;
+
+       (void) printf (const_string, externdefstr, conststr ? conststr : "",
+                      phile->table->name);
+
+       for (t = phile->table; t; t = t->next) 
+           for (te = t->tableent; te; te = te->next)
+               WriteSourceLine (te, abi, t->next ? 1 : 0);
+       (void) printf ("%s\n\n", "};");
+    }
+}
+
+static void WriteSource(tagline, abi)
+    char* tagline;
+    int abi;
+{
+    static void (*sourceproc[])() = { 
+       DefaultWriteSource, ArrayperWriteSource,
+       IntelABIWriteSource, IntelABIBCWriteSource,
+       DefaultWriteSource, FunctionWriteSource };
+
+    FILE* tmpl;
+
+    if (ctmplstr) {
+       tmpl = fopen (ctmplstr, "r");
+
+       if (tmpl) CopyTmplProlog (tmpl, stdout);
+       else {
+           (void) fprintf (stderr, "Expected template %s, not found\n",
+                           ctmplstr);
+           exit (1);
+       }
+    } else
+       tmpl = NULL;
+
+
+    (void) printf ("%s\n%s\n/* %s ABI version -- Do not edit */\n", 
+                  "/* $XConsortium: makestrs.c /main/10 1996/11/22 07:27:41 kaleb $ */",
+                  "/* This file is automatically generated. */",
+                  abistring[abi]);
+
+    if (tagline) (void) printf ("/* %s */\n\n", tagline);
+
+    (*sourceproc[abi])(abi);
+
+    if (tmpl) CopyTmplEpilog (tmpl, stdout);
+}
+
+static void DoLine(buf)
+    char* buf;
+{
+#define X_NO_TOKEN 0
+#define X_FILE_TOKEN 1
+#define X_TABLE_TOKEN 2
+#define X_PREFIX_TOKEN 3
+#define X_FEATURE_TOKEN 4
+#define X_EXTERNREF_TOKEN 5
+#define X_EXTERNDEF_TOKEN 6
+#define X_CTMPL_TOKEN 7
+#define X_HTMPL_TOKEN 8
+#define X_CONST_TOKEN 9
+
+    int token;
+    char lbuf[1024];
+    static char* file_str = "#file";
+    static char* table_str = "#table";
+    static char* prefix_str = "#prefix";
+    static char* feature_str = "#feature";
+    static char* externref_str = "#externref";
+    static char* externdef_str = "#externdef";
+    static char* ctmpl_str = "#ctmpl";
+    static char* htmpl_str = "#htmpl";
+    static char* const_str = "#const";
+
+    if (strncmp (buf, file_str, strlen (file_str)) == 0) 
+       token = X_FILE_TOKEN;
+    else if (strncmp (buf, table_str, strlen (table_str)) == 0) 
+       token = X_TABLE_TOKEN;
+    else if (strncmp (buf, prefix_str, strlen (prefix_str)) == 0) 
+       token = X_PREFIX_TOKEN;
+    else if (strncmp (buf, feature_str, strlen (feature_str)) == 0) 
+       token = X_FEATURE_TOKEN;
+    else if (strncmp (buf, externref_str, strlen (externref_str)) == 0) 
+       token = X_EXTERNREF_TOKEN;
+    else if (strncmp (buf, externdef_str, strlen (externdef_str)) == 0) 
+       token = X_EXTERNDEF_TOKEN;
+    else if (strncmp (buf, ctmpl_str, strlen (ctmpl_str)) == 0) 
+       token = X_CTMPL_TOKEN;
+    else if (strncmp (buf, htmpl_str, strlen (htmpl_str)) == 0) 
+       token = X_HTMPL_TOKEN;
+    else if (strncmp (buf, const_str, strlen (const_str)) == 0) 
+       token = X_CONST_TOKEN;
+    else
+        token = X_NO_TOKEN;
+
+    switch (token) {
+    case X_FILE_TOKEN:
+       {
+           File* phile;
+
+           if ((phile = (File*) malloc (sizeof(File))) == NULL) 
+               exit(1);
+           if ((phile->name = malloc (strlen (buf + strlen (file_str)) + 1)) == NULL) 
+               exit(1);
+           (void) strcpy (phile->name, buf + strlen (file_str) + 1);
+           phile->table = NULL;
+           phile->tablecurrent = NULL;
+           phile->tabletail = &phile->table;
+           phile->next = NULL;
+           phile->tmpl = NULL;
+
+           *filetail = phile;
+           filetail = &phile->next;
+           filecurrent = phile;
+       }
+       break;
+    case X_TABLE_TOKEN:
+       {
+           Table* table;
+           if ((table = (Table*) malloc (sizeof(Table))) == NULL) 
+               exit(1);
+           if ((table->name = malloc (strlen (buf + strlen (table_str)) + 1)) == NULL) 
+               exit(1);
+           (void) strcpy (table->name, buf + strlen (table_str) + 1);
+           table->tableent = NULL;
+           table->tableentcurrent = NULL;
+           table->tableenttail = &table->tableent;
+           table->next = NULL;
+           table->offset = 0;
+
+           *filecurrent->tabletail = table;
+           filecurrent->tabletail = &table->next;
+           filecurrent->tablecurrent = table;
+       }
+       break;
+    case X_PREFIX_TOKEN:
+       if ((prefixstr = malloc (strlen (buf + strlen (prefix_str)) + 1)) == NULL) 
+           exit(1);
+       (void) strcpy (prefixstr, buf + strlen (prefix_str) + 1);
+       break;
+    case X_FEATURE_TOKEN:
+       if ((featurestr = malloc (strlen (buf + strlen (feature_str)) + 1)) == NULL) 
+           exit(1);
+       (void) strcpy (featurestr, buf + strlen (feature_str) + 1);
+       break;
+    case X_EXTERNREF_TOKEN:
+       if ((externrefstr = malloc (strlen (buf + strlen (externref_str)) + 1)) == NULL) 
+           exit(1);
+       (void) strcpy (externrefstr, buf + strlen (externref_str) + 1);
+       break;
+    case X_EXTERNDEF_TOKEN:
+       if ((externdefstr = malloc (strlen (buf + strlen (externdef_str)) + 1)) == NULL) 
+           exit(1);
+       (void) strcpy (externdefstr, buf + strlen (externdef_str) + 1);
+       break;
+    case X_CTMPL_TOKEN:
+       if ((ctmplstr = malloc (strlen (buf + strlen (ctmpl_str)) + 1)) == NULL) 
+           exit(1);
+       (void) strcpy (ctmplstr, buf + strlen (ctmpl_str) + 1);
+       break;
+    case X_HTMPL_TOKEN:
+       if ((filecurrent->tmpl = fopen (buf + strlen (htmpl_str) + 1, "r")) == NULL) {
+           (void) fprintf (stderr, 
+                           "Expected template %s, not found\n", htmpl_str);
+           exit (1);
+       }
+       break;
+    case X_CONST_TOKEN:
+       if ((conststr = malloc (strlen (buf + strlen (const_str)) + 1)) == NULL)
+           exit(1);
+       (void) strcpy (conststr, buf + strlen (const_str) + 1);
+       break;
+    default:
+       {
+           char* right;
+           TableEnt* tableent;
+           int llen;
+           int rlen;
+           int len;
+
+           if (right = index(buf, ' '))
+               *right++ = 0;
+           else
+               right = buf + 1;
+           if (buf[0] == 'H') {
+               strcpy (lbuf, prefixstr);
+               strcat (lbuf, right);
+               right = lbuf;
+           }
+
+           llen = len = strlen(buf) + 1;
+           rlen = strlen(right) + 1;
+           if (right != buf + 1) len += rlen;
+           if ((tableent = (TableEnt*)malloc(sizeof(TableEnt) + len)) == NULL)
+               exit(1);
+           tableent->left = (char *)(tableent + 1);
+           strcpy(tableent->left, buf);
+           if (llen != len) {
+               tableent->right = tableent->left + llen;
+               strcpy(tableent->right, right);
+           } else {
+               tableent->right = tableent->left + 1;
+           }
+           tableent->next = NULL;
+
+           *filecurrent->tablecurrent->tableenttail = tableent;
+           filecurrent->tablecurrent->tableenttail = &tableent->next;
+           filecurrent->tablecurrent->tableentcurrent = tableent;
+       }
+       break;
+    }
+}
+
+static void IntelABIIndexEntries (file)
+    File* file;
+{
+    Table* t;
+    TableEnt* te;
+
+    for (t = file->table; t; t = t->next)
+       for (te = t->tableent; te; te = te->next) {
+           te->offset = t->offset;
+           t->offset += strlen (te->right);
+           t->offset++;
+    }
+}
+
+static void DefaultIndexEntries (file)
+    File* file;
+{
+    Table* t;
+    TableEnt* te;
+    int offset = 0;
+
+    for (t = file->table; t; t = t->next)
+       for (te = t->tableent; te; te = te->next) {
+           te->offset = offset;
+           offset += strlen (te->right);
+           offset++;
+    }
+}
+
+static void IndexEntries (file,abi)
+    File* file;
+    int abi;
+{
+    switch (abi) {
+    case X_SPARC_ABI:
+       break;
+    case X_INTEL_ABI:
+    case X_INTEL_ABI_BC:
+       IntelABIIndexEntries (file);
+       break;
+    default:
+       DefaultIndexEntries (file);
+       break;
+    }
+}
+
+static char* DoComment (line)
+    char* line;
+{
+    char* tag;
+    char* eol;
+    char* ret;
+    int len;
+
+    /* assume that the first line with two '$' in it is the RCS tag line */
+    if ((tag = index (line, '$')) == NULL) return NULL;
+    if ((eol = index (tag + 1, '$')) == NULL) return NULL;
+    len = eol - tag;
+    if ((ret = malloc (len)) == NULL)
+       exit (1);
+    (void) strncpy (ret, tag + 1, len - 1);
+    ret[len - 2] = 0;
+    return ret;
+}
+
+int main(argc, argv)
+    int argc;
+    char** argv;
+{
+    int len, i;
+    char* tagline = NULL;
+    File* phile;
+    FILE *f;
+    char buf[1024];
+    int abi = 
+#ifndef ARRAYPERSTR
+       X_DEFAULT_ABI;
+#else
+       X_ARRAYPER_ABI;
+#endif
+
+    f = stdin;
+    if (argc > 1) {
+       for (i = 1; i < argc; i++) {
+           if (strcmp (argv[i], "-f") == 0) {
+               if (++i < argc)
+                   f = fopen (argv[i], "r");
+               else
+                   return 1;
+           }
+           if (strcmp (argv[i], "-sparcabi") == 0)
+               abi = X_SPARC_ABI;
+           if (strcmp (argv[i], "-intelabi") == 0)
+               abi = X_INTEL_ABI;
+           if (strcmp (argv[i], "-functionabi") == 0)
+               abi = X_FUNCTION_ABI;
+           if (strcmp (argv[i], "-earlyR6bc") == 0 && abi == X_INTEL_ABI)
+               abi = X_INTEL_ABI_BC;
+           if (strcmp (argv[i], "-arrayperabi") == 0)
+               abi = X_ARRAYPER_ABI;
+#ifdef ARRAYPERSTR
+           if (strcmp (argv[i], "-defaultabi") == 0)
+               abi = X_DEFAULT_ABI;
+#endif
+       }
+    }
+
+    if (f == NULL) return 1;
+    while (fgets(buf, sizeof buf, f)) {
+       if (!buf[0] || buf[0] == '\n') 
+           continue;
+       if (buf[0] == '!') {
+           if (tagline) continue;
+           tagline = DoComment (buf);
+           continue;
+       }
+       if (buf[(len = strlen (buf) - 1)] == '\n') buf[len] = '\0';
+       DoLine(buf);
+    }
+    for (phile = file; phile; phile = phile->next) {
+       if (abi != X_ARRAYPER_ABI) IndexEntries (phile, abi);
+       WriteHeader (tagline, phile, abi);
+    }
+    WriteSource(tagline, abi);
+    return 0;
+}
+
diff --git a/Xserver/config/util/makestrs.man b/Xserver/config/util/makestrs.man
new file mode 100644 (file)
index 0000000..d8692b7
--- /dev/null
@@ -0,0 +1,213 @@
+.\" $XConsortium: makestrs.man /main/3 1996/09/28 16:16:52 rws $
+.\" Copyright (c) 1993, 1994  X Consortium
+.\" 
+.\" Permission is hereby granted, free of charge, to any person obtaining a
+.\" copy of this software and associated documentation files (the "Software"), 
+.\" to deal in the Software without restriction, including without limitation 
+.\" the rights to use, copy, modify, merge, publish, distribute, sublicense, 
+.\" and/or sell copies of the Software, and to permit persons to whom the 
+.\" Software furnished to do so, subject to the following conditions:
+.\" 
+.\" The above copyright notice and this permission notice shall be included in
+.\" all copies or substantial portions of the Software.
+.\" 
+.\" THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+.\" IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+.\" FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL 
+.\" THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 
+.\" WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF 
+.\" OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 
+.\" SOFTWARE.
+.\" 
+.\" Except as contained in this notice, the name of the X Consortium shall not 
+.\" be used in advertising or otherwise to promote the sale, use or other 
+.\" dealing in this Software without prior written authorization from the 
+.\" X Consortium.
+.TH MAKESTRS 1 "Release 6.1" "X Version 11"
+.SH NAME
+makestrs \- makes string table C source and header(s)
+.SH SYNOPSIS
+.B makestrs [-f source] [-abioptions ...]
+.SH DESCRIPTION
+The
+.I makestrs
+command creates string table C source files and headers.
+If
+.I -f
+.I source
+is not specified
+.I makestrs
+will read from
+.I stdin.
+The C source file is always written to
+.I stdout.
+.I makestrs
+creates one or more C header files as specified in the source file.
+The following options may be specified:
+.I -sparcabi,
+.I -intelabi,
+.I -functionabi,
+.I -arrayperabi,
+and
+.I -defaultabi.
+.LP
+.I -sparcabi 
+is used on SPARC platforms conforming to the SPARC 
+Compliance Definition, i.e. SVR4/Solaris.
+.LP
+.I -intelabi 
+is used on Intel platforms conforming to the System 
+V Application Binary Interface, i.e. SVR4.
+.LP
+.I -earlyR6abi 
+may be used in addition to 
+.I -intelabi 
+for situations 
+where the vendor wishes to maintain binary compatiblity between 
+X11R6 public-patch 11 (and earlier) and X11R6 public-patch 12 (and later).
+.LP
+.I -functionabi 
+generates a functional abi to the string table. This 
+mechanism imposes a severe performance penalty and it's recommended 
+that you not use it.
+.LP
+.I -arrayperabi 
+results in a separate array for each string. This is 
+the default behavior if makestrs was compiled with -DARRAYPERSTR 
+(it almost never is).
+.LP
+.I -defaultabi 
+forces the generation of the "normal" string table even 
+if makestrs was compiled with -DARRAYPERSTR. Since makestrs is almost 
+never compiled with -DARRAYPERSTR this is the default behavior if 
+no abioptions are specified.
+.SH SYNTAX
+The syntax for string-list file is (items in square brackets are optional):
+.RS 4
+#prefix <text>
+.RE
+.RS 4
+#feature <text>
+.RE
+.RS 4
+#externref <text>
+.RE
+.RS 4
+#externdef [<text>]
+.RE
+.RS 4
+[#ctempl <text>]
+.RE
+.LP
+.RS 4
+#file <filename>
+.RE
+.RS 4
+#table <tablename>
+.RE
+.RS 4
+[#htempl]
+.RE
+.RS 4
+<text>
+.RE
+.RS 4
+...
+.RE
+.RS 4
+<text>
+.RE
+.RS 4
+[#table <tablename>
+.RE
+.RS 4
+<text>
+.RE
+.RS 4
+...
+.RE
+.RS 4
+<text>
+.RE
+.RS 4
+...
+.RE
+.RS 4
+#table <tablename>
+.RE
+.RS 4
+...]
+.RE
+.RS 4
+[#file <filename>
+.RE
+.RS 4
+...]
+.RE
+.LP
+In words you may have one or more #file directives. Each #file may have
+one or more #table directives.
+.LP
+The #prefix directive determines the string that makestr will prefix
+to each definition.
+.LP
+The #feature directive determines the string that makestr will use
+for the feature-test macro, e.g. X[TM]STRINGDEFINES.
+.LP
+The #externref directive determines the string that makestr will use
+for the extern clause, typically this will be "extern" but Motif wants
+it to be "externalref"
+.LP
+The #externdef directive determines the string that makestr will use
+for the declaration, typically this will be the null string (note that
+makestrs requires a trailing space in this case, i.e. "#externdef "),
+and Motif will use "externaldef(_xmstrings).
+.LP
+The #ctmpl directive determines the name of the file used as a template
+for the C source file that is generated
+.LP
+Each #file <filename> directive will result in a corresponding header 
+file by that name containing the appropriate definitions as specified
+by command line options. A single C source file containing the
+declarations for the definitions in all the headers will be printed
+to stdout.
+.LP
+The #htmpl directive determines the name of the file used as a template
+for the C header file that is generated.
+.LP
+Each #table <tablename> directive will be processed in accordance with
+the ABI. On most platforms all tables will be catenated into a single
+table with the name of the first table for that file. To conform to
+the Intel ABI separate tables will be generated with the names indicated.
+.LP
+The template files specified by the #ctmpl and #htmpl directives
+are processed by copying line for line from the template file to
+the appropriate output file. The line containing the string
+.I <<<STRING_TABLE_GOES_HERE>>>
+is not copied to the output file. The appropriate data is then
+copied to the output file and then the remainder of the template
+file is copied to the output file.
+.SH BUGS
+makestrs is not very forgiving of syntax errors. Sometimes you need
+a trailing space after # directives, other times they will mess you
+up. No warning messages are emitted.
+.SH SEE ALSO
+SPARC Compliance Definition 2.2., SPARC International Inc.,
+535 Middlefield Road, Suite 210, Menlo Park, CA  94025
+.LP
+System V Application Binary Interface, Third Edition, 
+ISBN 0-13-100439-5
+UNIX Press, PTR Prentice Hall, 113 Sylvan Avenue, Englewood Cliffs, 
+NJ  07632
+.LP
+System V Application Binary Interface, Third Edition, Intel386
+Architecture Processor Supplement
+ISBN 0-13-104670-5
+UNIX Press, PTR Prentice Hall, 113 Sylvan Avenue, Englewood Cliffs, 
+NJ  07632
+.LP
+System V Application Binary Interface, Third Edition, SPARC
+Architecture Processor Supplement
+ISBN 0-13-104696-9
+UNIX Press, PTR Prentice Hall, 113 Sylvan Avenue, Englewood Cliffs, 
+NJ  07632
diff --git a/Xserver/config/util/mdepend.cpp b/Xserver/config/util/mdepend.cpp
new file mode 100644 (file)
index 0000000..9c6b684
--- /dev/null
@@ -0,0 +1,246 @@
+XCOMM!/bin/sh
+XCOMM
+XCOMM $TOG: mdepend.cpp /main/13 1997/06/20 21:12:18 kaleb $
+XCOMM
+XCOMM  Do the equivalent of the 'makedepend' program, but do it right.
+XCOMM
+XCOMM  Usage:
+XCOMM
+XCOMM  makedepend [cpp-flags] [-w width] [-s magic-string] [-f makefile]
+XCOMM    [-o object-suffix]
+XCOMM
+XCOMM  Notes:
+XCOMM
+XCOMM  The C compiler used can be overridden with the environment
+XCOMM  variable "CC".
+XCOMM
+XCOMM  The "-v" switch of the "makedepend" program is not supported.
+XCOMM
+XCOMM
+XCOMM  This script should
+XCOMM  work on both USG and BSD systems.  However, when System V.4 comes out,
+XCOMM  USG users will probably have to change "silent" to "-s" instead of
+XCOMM  "-" (at least, that is what the documentation implies).
+XCOMM
+XCOMM $XFree86: xc/config/util/mdepend.cpp,v 3.1.8.1 1997/06/29 08:43:27 dawes Exp $
+XCOMM
+
+CC=PREPROC
+
+silent='-'
+
+TMP=/tmp/mdep$$
+CPPCMD=${TMP}a
+DEPENDLINES=${TMP}b
+TMPMAKEFILE=${TMP}c
+MAGICLINE=${TMP}d
+ARGS=${TMP}e
+
+trap "rm -f ${TMP}*; exit 1" 1 2 15
+trap "rm -f ${TMP}*; exit 0" 1 2 13
+
+echo " \c" > $CPPCMD
+if [ `wc -c < $CPPCMD` -eq 1 ]
+then
+    c="\c"
+    n=
+else
+    c=
+    n="-n"
+fi
+
+echo $n "$c" >$ARGS
+
+files=
+makefile=
+magic_string='# DO NOT DELETE'
+objsuffix='.o'
+width=78
+endmarker=""
+verbose=n
+append=n
+
+while [ $# != 0 ]
+do
+    if [ "$endmarker"x != x ] && [ "$endmarker" = "$1" ]; then
+       endmarker=""
+    else
+       case "$1" in
+           -D*|-I*)
+               echo $n " '$1'$c" >> $ARGS
+               ;;
+
+           -g|-O)      # ignore so we can just pass $(CFLAGS) in
+               ;;
+
+           *)
+               if [ "$endmarker"x = x ]; then
+                   case "$1" in        
+                       -w)
+                           width="$2"
+                           shift
+                           ;;
+                       -s)
+                           magic_string="$2"
+                           shift
+                           ;;
+                       -f*)
+                           if [ "$1" = "-f-" ]; then
+                               makefile="-"
+                           else
+                               makefile="$2"
+                               shift
+                           fi
+                           ;;
+                       -o)
+                           objsuffix="$2"
+                           shift
+                           ;;
+                       
+                       --*)
+                           echo "$1" | sed 's/^\-\-//' >${TMP}end
+                           endmarker="`cat ${TMP}end`"
+                           rm -f ${TMP}end
+                           if [ "$endmarker"x = x ]; then
+                               endmarker="--"
+                           fi
+                           ;;
+                       -v)
+                           verbose="y"
+                           ;;
+
+                       -a)
+                           append="y"
+                           ;;
+
+                       -cc)
+                           CC="$2"
+                           shift
+                           ;;
+
+                       -*)
+                           echo "Unknown option '$1' ignored" 1>&2
+                           ;;
+                       *)
+                           files="$files $1"
+                           ;;
+                   esac
+               fi
+               ;;
+       esac
+    fi
+    shift
+done
+echo ' $*' >> $ARGS
+
+echo "#!/bin/sh" > $CPPCMD
+echo "exec $CC `cat $ARGS`" >> $CPPCMD
+chmod +x $CPPCMD
+rm $ARGS
+
+case "$makefile" in
+    '')
+       if [ -r makefile ]
+       then
+           makefile=makefile
+       elif [ -r Makefile ]
+       then
+           makefile=Makefile
+       else
+           echo 'no makefile or Makefile found' 1>&2
+           exit 1
+       fi
+       ;;
+    -)
+       makefile=$TMPMAKEFILE
+       ;;
+esac
+
+if [ "$verbose"x = "y"x ]; then 
+    cat $CPPCMD
+fi
+
+echo '' > $DEPENDLINES
+for i in $files
+do
+    $CPPCMD $i \
+      | sed -n "/^#/s;^;$i ;p"
+done \
+  | sed -e 's|/[^/.][^/]*/\.\.||g' -e 's|/\.[^.][^/]*/\.\.||g' \
+    -e 's|"||g' -e 's| \./| |' \
+  | awk '{
+       if ($1 != $4  &&  $2 != "#ident" && $2 != "#pragma")
+           {
+           ofile = substr ($1, 1, length ($1) - 2) "'"$objsuffix"'"
+           print ofile, $4
+           }
+       }' \
+  | sort -u \
+  | awk '
+           {
+           newrec = rec " " $2
+           if ($1 != old1)
+               {
+               old1 = $1
+               if (rec != "")
+                   print rec
+               rec = $1 ": " $2
+               }
+           else if (length (newrec) > '"$width"')
+               {
+               print rec
+               rec = $1 ": " $2
+               }
+           else
+               rec = newrec
+           }
+       END \
+           {
+           if (rec != "")
+               print rec
+           }' \
+  | egrep -v '^[^:]*:[         ]*$' >> $DEPENDLINES
+
+trap "" 1 2 13 15      # Now we are committed
+case "$makefile" in
+    $TMPMAKEFILE)
+       ;;
+    *)
+       rm -f $makefile.bak
+       cp $makefile $makefile.bak
+       echo "Appending dependencies to $makefile"
+       ;;
+esac
+
+XCOMM
+XCOMM If not -a, append the magic string and a blank line so that
+XCOMM /^$magic_string/+1,\$d can be used to delete everything from after
+XCOMM the magic string to the end of the file.  Then, append a blank
+XCOMM line again and then the dependencies.
+XCOMM
+if [ "$append" = "n" ]
+then
+    cat >> $makefile << END_OF_APPEND
+
+$magic_string
+
+END_OF_APPEND
+    ed $silent $makefile << END_OF_ED_SCRIPT
+/^$magic_string/+1,\$d
+w
+q
+END_OF_ED_SCRIPT
+    echo '' >>$makefile
+fi
+
+cat $DEPENDLINES >>$makefile
+
+case "$makefile" in
+    $TMPMAKEFILE)
+       cat $TMPMAKEFILE
+       ;;
+
+esac
+
+rm -f ${TMP}*
+exit 0
diff --git a/Xserver/config/util/mergelib.cpp b/Xserver/config/util/mergelib.cpp
new file mode 100755 (executable)
index 0000000..1c8d3ff
--- /dev/null
@@ -0,0 +1,103 @@
+XCOMM!/bin/sh
+XCOMM
+XCOMM $XConsortium: mergelib.cpp,v 1.4 94/04/17 20:10:43 rws Exp $
+XCOMM 
+XCOMM Copyright (c) 1989  X Consortium
+XCOMM 
+XCOMM Permission is hereby granted, free of charge, to any person obtaining a copy
+XCOMM of this software and associated documentation files (the "Software"), to deal
+XCOMM in the Software without restriction, including without limitation the rights
+XCOMM to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+XCOMM copies of the Software, and to permit persons to whom the Software is
+XCOMM furnished to do so, subject to the following conditions:
+XCOMM 
+XCOMM The above copyright notice and this permission notice shall be included in
+XCOMM all copies or substantial portions of the Software.
+XCOMM 
+XCOMM THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+XCOMM IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+XCOMM FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+XCOMM X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+XCOMM AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+XCOMM CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+XCOMM 
+XCOMM Except as contained in this notice, the name of the X Consortium shall not be
+XCOMM used in advertising or otherwise to promote the sale, use or other dealings
+XCOMM in this Software without prior written authorization from the X Consortium.
+XCOMM 
+XCOMM Author:  Jim Fulton, MIT X Consortium
+XCOMM 
+XCOMM mergelib - merge one library into another; this is commonly used by X
+XCOMM     to add the extension library into the base Xlib.
+XCOMM
+
+usage="usage:  $0  to-library from-library [object-filename-prefix]"
+objprefix=_
+
+case $# in
+    2) ;;
+    3) objprefix=$3 ;;
+    *) echo "$usage" 1>&2; exit 1 ;;
+esac
+
+tolib=$1
+fromlib=$2
+
+if [ ! -f $fromlib ]; then
+    echo "$0:  no such from-library $fromlib" 1>&2
+    exit 1
+fi
+
+if [ ! -f $tolib ]; then
+    echo "$0:  no such to-library $tolib" 1>&2
+    exit 1
+fi
+
+
+XCOMM
+XCOMM Create a temp directory, and figure out how to reference the 
+XCOMM object files from it (i.e. relative vs. absolute path names).
+XCOMM
+
+tmpdir=tmp.$$
+origdir=..
+
+mkdir $tmpdir
+
+if [ ! -d $tmpdir ]; then
+    echo "$0:  unable to create temporary directory $tmpdir" 1>&2
+    exit 1
+fi
+
+case "$fromlib" in
+    /?*) upfrom= ;;
+    *)  upfrom=../ ;;
+esac
+
+case "$tolib" in
+    /?*) upto= ;;
+    *)  upto=../ ;;
+esac
+
+
+XCOMM
+XCOMM In the temp directory, extract all of the object files and prefix
+XCOMM them with some symbol to avoid name clashes with the base library.
+XCOMM
+cd $tmpdir
+ar x ${upfrom}$fromlib
+for i in *.o; do
+    mv $i ${objprefix}$i
+done
+
+
+XCOMM
+XCOMM Merge in the object modules, ranlib (if appropriate) and cleanup
+XCOMM
+ARCMD ${upto}$tolib *.o
+RANLIB ${upto}$tolib
+cd $origdir
+rm -rf $tmpdir
+
+
+
diff --git a/Xserver/config/util/mkdirhier.c b/Xserver/config/util/mkdirhier.c
new file mode 100644 (file)
index 0000000..8fbba1b
--- /dev/null
@@ -0,0 +1,77 @@
+/* $TOG: mkdirhier.c /main/2 1997/06/05 18:09:26 kaleb $ */
+/*
+
+Copyright (C) 1996 X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be included
+in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR
+OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall
+not be used in advertising or otherwise to promote the sale, use or
+other dealings in this Software without prior written authorization
+from the X Consortium.
+
+*/
+
+/*
+ * Simple mkdirhier program for Windows NT
+ */
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <direct.h>
+#include <stdlib.h>\r
+#include <string.h>
+
+char *
+next_sep(char *path)
+{
+    while (*path)
+       if (*path == '/' || *path == '\\')
+           return path;
+       else
+           path++;
+    return NULL;
+}
+
+int
+main(int argc, char *argv[])
+{
+    char *dirname, *next, *prev;
+    char buf[1024];
+    struct _stat sb;
+
+    if (argc < 2)
+       exit(1);
+    dirname = argv[1];
+
+    prev = dirname;
+    while (next = next_sep(prev)) {
+       strncpy(buf, dirname, next - dirname);
+       buf[next - dirname] = '\0';
+       /* if parent dir doesn't exist yet create it */
+       if (_stat(buf, &sb))
+           _mkdir(buf);        /* no error checking to avoid barfing on C: */
+       prev = next + 1;
+    }
+    if (_mkdir(dirname) == -1) {
+       perror("mkdirhier failed");
+       exit(1);
+    }
+    exit(0);
+}
diff --git a/Xserver/config/util/mkdirhier.cmd b/Xserver/config/util/mkdirhier.cmd
new file mode 100644 (file)
index 0000000..5978f38
--- /dev/null
@@ -0,0 +1,54 @@
+/* OS/2 REXX SCRIPT */
+/* $XFree86: xc/config/util/mkdirhier.cmd,v 3.2 1996/02/19 12:16:51 dawes Exp $ */
+
+CALL RxFuncAdd 'SysMkDir', 'RexxUtil', 'SysMkDir'
+
+IF ARG() = 0 THEN DO
+       SAY "mkdirhier: usage: mkdirhier directory ..."
+       EXIT 1
+END
+
+curdir=DIRECTORY()
+drive=DELSTR(curdir,3)
+
+status=""
+PARSE ARG all
+
+DO i=1 TO WORDS(all)
+       direc = TRANSLATE(WORD(all,i),'/','\')
+       SELECT
+       WHEN direc = "" THEN DO
+               SAY "mkdirhier: empty directory name"
+               status=1
+               ITERATE
+               END
+       WHEN POS('0a'x,direc) > 0 THEN DO
+               SAY "mkdirhier: directory name contains a newline: '" direc "'"
+               status=1
+               ITERATE
+               END
+       OTHERWISE NOP
+       END
+       IF POS(":",direc) = 0 THEN direc = INSERT(drive,direc)
+
+       dirbuf.0 = direc
+       DO k=1 TO 1000
+               direc1 = STRIP(direc,"t","/")
+               dpath1 = FILESPEC("path",direc1)
+               dirbuf.k=FILESPEC("drive",direc1)||STRIP(dpath1,"t","/")
+               IF POS("/",dirbuf.k) = 0 THEN LEAVE k
+               direc=dirbuf.k
+       END
+       DO m=k-1 TO 0 BY -1
+               dospath = TRANSLATE(dirbuf.m,'\','/')
+               targetdir=DIRECTORY(dospath)
+               IF targetdir = dospath THEN
+                       NOP
+               ELSE
+                       CALL SysMkDir(dospath)
+               CALL DIRECTORY curdir
+       END
+END
+
+
+EXIT status
diff --git a/Xserver/config/util/mkdirhier.man b/Xserver/config/util/mkdirhier.man
new file mode 100644 (file)
index 0000000..0df84a7
--- /dev/null
@@ -0,0 +1,40 @@
+.\" $XConsortium: mkdirhier.man /main/9 1996/09/28 16:17:00 rws $
+.\" Copyright (c) 1993, 1994  X Consortium
+.\" 
+.\" Permission is hereby granted, free of charge, to any person obtaining a
+.\" copy of this software and associated documentation files (the "Software"), 
+.\" to deal in the Software without restriction, including without limitation 
+.\" the rights to use, copy, modify, merge, publish, distribute, sublicense, 
+.\" and/or sell copies of the Software, and to permit persons to whom the 
+.\" Software furnished to do so, subject to the following conditions:
+.\" 
+.\" The above copyright notice and this permission notice shall be included in
+.\" all copies or substantial portions of the Software.
+.\" 
+.\" THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+.\" IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+.\" FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL 
+.\" THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 
+.\" WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF 
+.\" OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 
+.\" SOFTWARE.
+.\" 
+.\" Except as contained in this notice, the name of the X Consortium shall not 
+.\" be used in advertising or otherwise to promote the sale, use or other 
+.\" dealing in this Software without prior written authorization from the 
+.\" X Consortium.
+.TH MKDIRHIER 1 "Release 6.1" "X Version 11"
+.SH NAME
+mkdirhier \- makes a directory hierarchy
+.SH SYNOPSIS
+.B mkdirhier
+directory ...
+.SH DESCRIPTION
+The
+.I mkdirhier
+command creates the specified directories. Unlike
+.I mkdir
+if any of the parent directories of the specified directory
+do not exist, it creates them as well.
+.SH "SEE ALSO"
+mkdir(1)
diff --git a/Xserver/config/util/mkdirhier.sh b/Xserver/config/util/mkdirhier.sh
new file mode 100755 (executable)
index 0000000..889094d
--- /dev/null
@@ -0,0 +1,67 @@
+#!/bin/sh
+# $XConsortium: mkdirhier.sh,v 1.7 94/03/24 15:46:34 gildea Exp $
+# Courtesy of Paul Eggert
+
+newline='
+'
+IFS=$newline
+
+case ${1--} in
+-*) echo >&2 "mkdirhier: usage: mkdirhier directory ..."; exit 1
+esac
+
+status=
+
+for directory
+do
+       case $directory in
+       '')
+               echo >&2 "mkdirhier: empty directory name"
+               status=1
+               continue;;
+       *"$newline"*)
+               echo >&2 "mkdirhier: directory name contains a newline: \`\`$directory''"
+               status=1
+               continue;;
+       ///*) prefix=/;; # See Posix 2.3 "path".
+       //*) prefix=//;;
+       /*) prefix=/;;
+       -*) prefix=./;;
+       *) prefix=
+       esac
+
+       IFS=/
+       set x $directory
+       case $2 in
+           */*)        # IFS parsing is broken
+               IFS=' '
+               set x `echo $directory | tr / ' '`
+               ;;
+       esac
+       IFS=$newline
+       shift
+
+       for filename
+       do
+               path=$prefix$filename
+               prefix=$path/
+               shift
+
+               test -d "$path" || {
+                       paths=$path
+                       for filename
+                       do
+                               if [ "$filename" != "." ]; then
+                                       path=$path/$filename
+                                       paths=$paths$newline$path
+                               fi
+                       done
+
+                       mkdir $paths || status=$?
+
+                       break
+               }
+       done
+  done
+
+exit $status
diff --git a/Xserver/config/util/mkshadow/Imakefile b/Xserver/config/util/mkshadow/Imakefile
new file mode 100644 (file)
index 0000000..38b0614
--- /dev/null
@@ -0,0 +1,5 @@
+XCOMM $XConsortium: Imakefile,v 1.1 94/04/13 18:44:40 rws Exp $
+           SRCS = mkshadow.c savedir.c wildmat.c
+           OBJS = mkshadow.o savedir.o wildmat.o
+
+ComplexProgramTarget(mkshadow)
diff --git a/Xserver/config/util/mkshadow/README b/Xserver/config/util/mkshadow/README
new file mode 100644 (file)
index 0000000..eea4b8b
--- /dev/null
@@ -0,0 +1,38 @@
+The mkshadow programs makes a "shadow tree" of a directory tree.
+It logically copies all of the "MASTER" directory into ".".
+However, ordinary files, and RCS/SCCS directories are "copied"
+by creating a sybolic link to the corresponding file in MASTER.
+
+The wildmat.c file is by Rich Salz, and from comp.sources.misc, volume 17.
+The savedir.c file is lightly modified from the version written
+by David MacKenzie for GNU fileutils; the Free Software Foundation
+has graciously agreed to waive their usual copyright so this
+program can be distributed by the X Consortium.
+
+If you have problems compiling savedir.c, try setting the DIRENT make
+variable as suggested in the Makefile.
+
+ * Usage: mkshadow [-X exclude_file] [-x exclude_pattern] ... MASTER
+ * Makes the current directory be a "shadow copy" of MASTER.
+ * Sort of like a recursive copy of MASTER to .
+ * However, symbolic links are used instead of actually
+ * copying (non-directory) files.
+ * Also, directories named RCS or SCCS are shared (with a symbolic link).
+ * Warning messages are printed for files (and directories) in .
+ * that don't match a corresponding file in MASTER (though
+ * symbolic links are silently removed).
+ * Also, a warning message is printed for non-directory files
+ * under . that are  not symbolic links.
+ *
+ * Files and directories can be excluded from the sharing
+ * with the -X and -x flags. The flag `-x pattern' (or `-xpattern')
+ * means that mkshadow should ignore any file whose name matches
+ * the pattern. The pattern is a "globbing" pattern, i.e. the
+ * characters *?[^-] are interpreted as by the shell.
+ * If the pattern contains a '/' is is matched against the complete
+ * current path (relative to '.'); otherwise, it is matched
+ * against the last component of the path.
+ * A `-X filename' flag means to read a set of exclusion patterns
+ * from the named file, one pattern to a line.
+
+Author: Per Bothner. bothner@cygnus.com. November 1990, 1993.
diff --git a/Xserver/config/util/mkshadow/mkshadow.c b/Xserver/config/util/mkshadow/mkshadow.c
new file mode 100644 (file)
index 0000000..8bd998a
--- /dev/null
@@ -0,0 +1,378 @@
+/* $XConsortium: mkshadow.c /main/2 1996/12/04 10:11:51 swick $ */
+/* mkshadow.c - make a "shadow copy" of a directory tree with symlinks.
+   Copyright 1990, 1993 Free Software Foundation, Inc.
+
+   Permission to use, copy, modify, and distribute this program for
+   any purpose and without fee is hereby granted, provided that this
+   copyright and permission notice appear on all copies, and that
+   notice be given that copying and distribution is by permission of
+   the Free Software Foundation.  The Free Software Foundation makes
+   no representations about the suitability of this software for any
+   purpose.  It is provided "as is" without expressed or implied
+   warranty.
+
+   (The FSF has modified its usual distribution terms, for this file,
+   as a courtesy to the X project.)  */
+
+/*
+ * Usage: mkshadow [-X exclude_file] [-x exclude_pattern] ... MASTER [SHADOW]
+ * Makes SHADOW be a "shadow copy" of MASTER.  SHADOW defaults to the current
+ * directory. Sort of like a recursive copy of MASTER to SHADOW.
+ * However, symbolic links are used instead of actually
+ * copying (non-directory) files.
+ * Also, directories named RCS or SCCS are shared (with a symbolic link).
+ * Warning messages are printed for files (and directories) in .
+ * that don't match a corresponding file in MASTER (though
+ * symbolic links are silently removed).
+ * Also, a warning message is printed for non-directory files
+ * under SHADOW that are not symbolic links.
+ *
+ * Files and directories can be excluded from the sharing
+ * with the -X and -x flags. The flag `-x pattern' (or `-xpattern')
+ * means that mkshadow should ignore any file whose name matches
+ * the pattern. The pattern is a "globbing" pattern, i.e. the
+ * characters *?[^-] are interpreted as by the shell.
+ * If the pattern contains a '/' is is matched against the complete
+ * current path (relative to '.'); otherwise, it is matched
+ * against the last component of the path.
+ * A `-X filename' flag means to read a set of exclusion patterns
+ * from the named file, one pattern to a line.
+ *
+ * Originally written by Per Bothner at University of Wisconsin-Madison,
+ * inspired by the lndir script distributed with X11.
+ * Modified by Per Bothner <bothner@cygnus.com> November 1993
+ * to more-or-less follow Posix.
+ */
+
+#include <sys/types.h>
+#include <stdio.h>
+#ifdef BSD
+#include <strings.h>
+#define strchr index
+#else
+#include <string.h>
+#endif
+#include <sys/stat.h>
+#if defined(S_IFDIR) && !defined(S_ISDIR)
+#define S_ISDIR(mode) (((mode) & S_IFMT) == S_IFDIR)
+#endif
+#if defined(S_IFLNK) && !defined(S_ISLNK)
+#define S_ISLNK(mode) (((mode) & S_IFMT) == S_IFLNK)
+#endif
+#ifndef S_ISLNK
+#define lstat stat
+#endif
+#ifndef MAXPATHLEN
+#define MAXPATHLEN 1024
+#endif
+#include <errno.h>
+#ifndef errno
+extern int errno;
+#endif
+
+extern char * savedir();
+
+fatal(msg)
+     char *msg;
+{
+    if (errno) perror(msg ? msg : "");
+    else if (msg) fprintf(stderr, "mkshadow: %s\n", msg);
+    exit(-1);
+}
+
+/* When handling symbolic links to relative directories,
+ * we need to prepend "../" to the "source".
+ * We preallocate MAX_DEPTH repetations of "../" using a simple trick.
+ */
+#define MAX_DEPTH 20
+#define PREPEND_BUFFER_SIZE (MAX_DEPTH*3)
+char master_buffer[MAXPATHLEN+PREPEND_BUFFER_SIZE] =
+    "../../../../../../../../../../../../../../../../../../../../";
+/* The logical start of the master_buffer is defined by
+ * master_start, which skips the fixed prepend area.
+ */
+#define master_start (master_buffer+PREPEND_BUFFER_SIZE)
+char shadow_buffer[MAXPATHLEN];
+
+void bad_args(msg)
+{
+    if (msg) fprintf(stderr, "%s\n", msg);
+    fprintf (stderr, "usage: mkshadow [-X exclude_file] [-x exclude_pattern]");
+    fprintf (stderr, " master [shadow]\n");
+    exit(-1);
+}
+
+int exclude_count = 0;
+char **exclude_patterns = NULL;
+int exclude_limit = 0;
+
+void add_exclude(pattern)
+    char *pattern;
+{
+    if (exclude_limit == 0) {
+       exclude_limit = 100;
+       exclude_patterns = (char**)malloc(exclude_limit * sizeof(char*));
+    } else if (exclude_count + 1 >= exclude_limit) {
+       exclude_limit += 100;
+       exclude_patterns = (char**)realloc(exclude_patterns, 
+                                          exclude_limit * sizeof(char*));
+    }
+    exclude_patterns[exclude_count] = pattern;
+    exclude_count++;
+}
+
+void add_exclude_file(name)
+     char *name;
+{
+    char buf[MAXPATHLEN];
+    FILE *file = fopen(name, "r");
+    if (file == NULL) fatal("failed to find -X (exclude) file");
+    for (;;) {
+       int len;
+       char *str = fgets(buf, MAXPATHLEN, file);
+       if (str == NULL) break;
+       len = strlen(str);
+       if (len && str[len-1] == '\n') str[--len] = 0;
+       if (!len) continue;
+       str = (char*)malloc(len+1);
+       strcpy(str, buf);
+       add_exclude(str);
+    }
+    fclose(file);
+}
+
+main(argc, argv)
+     char **argv;
+{
+    char *master_name = NULL;
+    char *shadow_name = NULL;
+    int i;
+    for (i = 1; i < argc; i++) {
+       if (argv[i][0] == '-') {
+           switch(argv[i][1]) {
+             case 'X':
+               if (argv[i][2]) add_exclude_file(&argv[i][2]);
+               else if (++i >= argc) bad_args(NULL);
+               else add_exclude_file(argv[i]);
+               break;
+             case 'x':
+               if (argv[i][2]) add_exclude(&argv[i][2]);
+               else if (++i >= argc) bad_args(NULL);
+               else add_exclude(argv[i]);
+               break;
+             default:
+               bad_args(NULL);
+           }
+       } else if (master_name == NULL)
+           master_name = argv[i];
+       else if (shadow_name == NULL)
+           shadow_name = argv[i];
+       else bad_args (NULL);
+    }
+
+    if (master_name == NULL) bad_args(NULL);
+    if (shadow_name == NULL)
+       shadow_name = ".";
+    else if ((shadow_name[0] != '.' || shadow_name[1])
+            && master_name[0] != '/') {
+       fprintf(stderr, "Shadowing a relative directory pathname to a \n");
+       fprintf(stderr, "shadow other than '.' is not supported!\n");
+       exit(-1);
+    }
+    strcpy(shadow_buffer, shadow_name);
+    strcpy(master_start, master_name);
+    DoCopy(master_start, shadow_buffer, 0);
+    return 0;
+}
+
+int compare_strings(ptr1, ptr2)
+     char **ptr1, **ptr2;
+{
+    return strcmp(*ptr1, *ptr2);
+}
+
+void MakeLink(master, current, depth)
+     char *master;
+     char *current;
+     int depth;
+{
+    if (master[0] != '/') {
+       /* Source directory was specified with a relative pathname. */
+       if (master != master_start) {
+           fatal("Internal bug: bad string buffer use");
+       }
+       /* Pre-pend "../" depth times. This compensates for
+        * the directories we've entered. */
+       master -= 3 * depth;
+    }
+    if (symlink(master, current)) {
+       fprintf(stderr, "Failed to create symbolic link %s->%s\n",
+               current, master);
+       exit (-1);
+    }
+}
+
+
+/* Get a sorted NULL_terminator array of (char*) using 'names'
+ * (created by save_dir) as data.
+ */
+char ** get_name_pointers(names)
+     char *names;
+{
+    int n_names = 0;
+    int names_buf_size = 64;
+    char *namep;
+    char ** pointers = (char**)malloc(names_buf_size * sizeof(char*));
+    if (!names || !pointers) fatal("virtual memory exhausted");
+
+    for (namep = names; *namep; namep += strlen(namep) + 1) {
+       if (n_names + 1 >= names_buf_size) {
+           names_buf_size *= 2;
+           pointers = (char**)realloc(pointers,
+                                      names_buf_size * sizeof(char*));
+           if (!pointers) fatal("virtual memory exhausted");
+       }
+       pointers[n_names++] = namep;
+    }
+    pointers[n_names] = 0;
+    qsort(pointers, n_names, sizeof(char*), compare_strings);
+    return pointers;
+}
+
+/* Recursively shadow the directory whose name is in MASTER
+ * (which is == MASTER_START) into the destination directory named CURRENT.
+ */
+
+DoCopy(master, current, depth)
+     char *master; /* The source directory. */
+     char *current; /* The destination directory. */
+     int depth;
+{
+    struct stat stat_master, stat_current;
+    char **master_pointer, **current_pointer;
+    char **master_names, **current_names;
+    char *master_end, *current_end;
+    char *master_name_buf, *current_name_buf;
+    master_end = master + strlen(master);
+    current_end = current + strlen(current);
+
+    /* Get rid of terminal '/' */
+    if (master_end[-1] == '/' && master != master_end - 1)
+       *--master_end = 0;
+    if (current_end[-1] == '/' && current != current_end - 1)
+       *--current_end = 0;
+
+    if (depth >= MAX_DEPTH) {
+       fprintf(stderr,
+               "Nesting too deep (depth %d at %s). Probable circularity.\n",
+               depth, master);
+       exit(-1);
+    }
+
+    master_name_buf = savedir(master, 500);
+    if (master_name_buf == NULL) {
+       fprintf(stderr, "Not enough memory or no such directory: %s\n",
+               master);
+       exit(-1);
+    }
+    current_name_buf = savedir(current, 500);
+    if (current_name_buf == NULL) {
+       fprintf(stderr, "Not enough memory or no such directory: %s\n",
+               current);
+       exit(-1);
+    }
+
+    master_names = get_name_pointers(master_name_buf);
+    current_names = get_name_pointers(current_name_buf);
+
+    master_pointer = master_names;
+    current_pointer = current_names;
+    for (;;) {
+       int cmp, ipat;
+       int in_master, in_current;
+       char *cur_name;
+       if (*master_pointer == NULL && *current_pointer == NULL)
+           break;
+       if (*master_pointer == NULL) cmp = 1;
+       else if (*current_pointer == NULL) cmp = -1;
+       else cmp = strcmp(*master_pointer, *current_pointer);
+       if (cmp < 0) { /* file only exists in master directory */
+           in_master = 1; in_current = 0;
+       } else if (cmp == 0) { /* file exists in both directories */
+           in_master = 1; in_current = 1;
+       } else { /* file only exists in current directory */
+           in_current = 1; in_master = 0;
+       }
+       cur_name = in_master ? *master_pointer : *current_pointer;
+       sprintf(master_end, "/%s", cur_name);
+       sprintf(current_end, "/%s", cur_name);
+       for (ipat = 0; ipat < exclude_count; ipat++) {
+           char *pat = exclude_patterns[ipat];
+           char *cur;
+           if (strchr(pat, '/')) cur = current + 2; /* Skip initial "./" */
+           else cur = cur_name;
+           if (wildmat(cur, pat)) goto skip;
+       }
+       if (in_master)
+           if (lstat(master, &stat_master) != 0) fatal("stat failed");
+       if (in_current)
+           if (lstat(current, &stat_current) != 0) fatal("stat failed");
+       if (in_current && !in_master) {
+           if (S_ISLNK(stat_current.st_mode))
+               if (unlink(current)) {
+                   fprintf(stderr, "Failed to remove symbolic link %s.\n",
+                           current);
+               }
+               else
+                   fprintf(stderr, "Removed symbolic link %s.\n",
+                           current);
+           else {
+               fprintf(stderr,
+                       "The file %s does not exist in the master tree.\n",
+                       current);
+           }
+       }
+       else if (S_ISDIR(stat_master.st_mode)
+                && strcmp(cur_name, "RCS") != 0
+                && strcmp(cur_name, "SCCS") != 0) {
+           if (!in_current) {
+               if (mkdir(current, 0775)) fatal("mkdir failed");
+           }
+           else if (stat(current, &stat_current)) fatal("stat failed");
+           if (!in_current || stat_current.st_dev != stat_master.st_dev
+               || stat_current.st_ino != stat_master.st_ino)
+               DoCopy(master, current, depth+1);
+           else
+               fprintf(stderr, "Link %s is the same as directory %s.\n",
+                       current, master);
+       }
+       else {
+           if (!in_current)
+               MakeLink(master, current, depth);
+           else if (!S_ISLNK(stat_current.st_mode)) {
+               fprintf(stderr, "Existing file %s is not a symbolc link.\n",
+                       current);
+           } else {
+               if (stat(current, &stat_current) || stat(master, &stat_master))
+                   fatal("stat failed");
+               if (stat_current.st_dev != stat_master.st_dev
+                   || stat_current.st_ino != stat_master.st_ino) {
+                   fprintf(stderr, "Fixing incorrect symbolic link %s.\n",
+                           current);
+                   if (unlink(current)) {
+                       fprintf(stderr, "Failed to remove symbolic link %s.\n",
+                               current);
+                   }
+                   else
+                       MakeLink(master, current, depth);
+               }
+           }
+       }
+      skip:
+       if (in_master) master_pointer++;
+       if (in_current) current_pointer++;
+    }
+
+    free(master_names); free(current_names);
+    free(master_name_buf); free(current_name_buf);
+}
diff --git a/Xserver/config/util/mkshadow/savedir.c b/Xserver/config/util/mkshadow/savedir.c
new file mode 100644 (file)
index 0000000..28ae884
--- /dev/null
@@ -0,0 +1,125 @@
+/* $XConsortium: savedir.c,v 1.1 94/04/13 18:26:54 rws Exp $ */
+/* savedir.c -- save the list of files in a directory in a string
+   Copyright 1990, 1993 Free Software Foundation, Inc.
+
+   Permission to use, copy, modify, and distribute this program for
+   any purpose and without fee is hereby granted, provided that this
+   copyright and permission notice appear on all copies, and that
+   notice be given that copying and distribution is by permission of
+   the Free Software Foundation.  The Free Software Foundation makes
+   no representations about the suitability of this software for any
+   purpose.  It is provided "as is" without expressed or implied
+   warranty.
+
+   (The FSF has modified its usual distribution terms, for this file,
+   as a courtesy to the X project.)  */
+
+/* Written by David MacKenzie <djm@ai.mit.edu>.
+   Modified to use <dirent.h> by default.  Per Bothner <bothner@cygnus.com>. */
+
+#include <sys/types.h>
+#if !defined(DIRECT) && !defined(BSD)
+#include <dirent.h>
+#define NLENGTH(direct) (strlen((direct)->d_name))
+#else
+#undef dirent
+#define dirent direct
+#define NLENGTH(direct) ((direct)->d_namlen)
+#ifdef BSD
+#include <sys/dir.h>
+#else
+#ifdef SYSNDIR
+#include <sys/ndir.h>
+#else
+#include <ndir.h>
+#endif
+#endif
+#endif
+
+#if defined(VOID_CLOSEDIR) || defined(BSD)
+/* Fake a return value. */
+#define CLOSEDIR(d) (closedir (d), 0)
+#else
+#define CLOSEDIR(d) closedir (d)
+#endif
+
+#ifdef STDC_HEADERS
+#include <stdlib.h>
+#include <string.h>
+#else
+char *malloc ();
+char *realloc ();
+int strlen ();
+#ifndef NULL
+#define NULL 0
+#endif
+#endif
+
+char *stpcpy ();
+
+/* Return a freshly allocated string containing the filenames
+   in directory DIR, separated by '\0' characters;
+   the end is marked by two '\0' characters in a row.
+   NAME_SIZE is the number of bytes to initially allocate
+   for the string; it will be enlarged as needed.
+   Return NULL if DIR cannot be opened or if out of memory. */
+
+char *
+savedir (dir, name_size)
+     char *dir;
+     unsigned name_size;
+{
+  DIR *dirp;
+  struct dirent *dp;
+  char *name_space;
+  char *namep;
+
+  dirp = opendir (dir);
+  if (dirp == NULL)
+    return NULL;
+
+  name_space = (char *) malloc (name_size);
+  if (name_space == NULL)
+    {
+      closedir (dirp);
+      return NULL;
+    }
+  namep = name_space;
+
+  while ((dp = readdir (dirp)) != NULL)
+    {
+      /* Skip "." and ".." (some NFS filesystems' directories lack them). */
+      if (dp->d_name[0] != '.'
+         || (dp->d_name[1] != '\0'
+             && (dp->d_name[1] != '.' || dp->d_name[2] != '\0')))
+       {
+         unsigned size_needed = (namep - name_space) + NLENGTH (dp) + 2;
+
+         if (size_needed > name_size)
+           {
+             char *new_name_space;
+
+             while (size_needed > name_size)
+               name_size += 1024;
+
+             new_name_space = realloc (name_space, name_size);
+             if (new_name_space == NULL)
+               {
+                 closedir (dirp);
+                 return NULL;
+               }
+             namep += new_name_space - name_space;
+             name_space = new_name_space;
+           }
+         strcpy (namep, dp->d_name);
+         namep += strlen (namep) + 1;
+       }
+    }
+  *namep = '\0';
+  if (CLOSEDIR (dirp))
+    {
+      free (name_space);
+      return NULL;
+    }
+  return name_space;
+}
diff --git a/Xserver/config/util/mkshadow/wildmat.c b/Xserver/config/util/mkshadow/wildmat.c
new file mode 100644 (file)
index 0000000..2e408e9
--- /dev/null
@@ -0,0 +1,167 @@
+/* $XConsortium: wildmat.c,v 1.2 94/04/13 18:40:59 rws Exp $ */
+/*
+**
+**  Do shell-style pattern matching for ?, \, [], and * characters.
+**  Might not be robust in face of malformed patterns; e.g., "foo[a-"
+**  could cause a segmentation violation.  It is 8bit clean.
+**
+**  Written by Rich $alz, mirror!rs, Wed Nov 26 19:03:17 EST 1986.
+**  Rich $alz is now <rsalz@bbn.com>.
+**  April, 1991:  Replaced mutually-recursive calls with in-line code
+**  for the star character.
+**
+**  Special thanks to Lars Mathiesen <thorinn@diku.dk> for the ABORT code.
+**  This can greatly speed up failing wildcard patterns.  For example:
+**     pattern: -*-*-*-*-*-*-12-*-*-*-m-*-*-*
+**     text 1:  -adobe-courier-bold-o-normal--12-120-75-75-m-70-iso8859-1
+**     text 2:  -adobe-courier-bold-o-normal--12-120-75-75-X-70-iso8859-1
+**  Text 1 matches with 51 calls, while text 2 fails with 54 calls.  Without
+**  the ABORT, then it takes 22310 calls to fail.  Ugh.  The following
+**  explanation is from Lars:
+**  The precondition that must be fulfilled is that DoMatch will consume
+**  at least one character in text.  This is true if *p is neither '*' nor
+**  '\0'.)  The last return has ABORT instead of FALSE to avoid quadratic
+**  behaviour in cases like pattern "*a*b*c*d" with text "abcxxxxx".  With
+**  FALSE, each star-loop has to run to the end of the text; with ABORT
+**  only the last one does.
+**
+**  Once the control of one instance of DoMatch enters the star-loop, that
+**  instance will return either TRUE or ABORT, and any calling instance
+**  will therefore return immediately after (without calling recursively
+**  again).  In effect, only one star-loop is ever active.  It would be
+**  possible to modify the code to maintain this context explicitly,
+**  eliminating all recursive calls at the cost of some complication and
+**  loss of clarity (and the ABORT stuff seems to be unclear enough by
+**  itself).  I think it would be unwise to try to get this into a
+**  released version unless you have a good test data base to try it out
+**  on.
+*/
+
+#define TRUE                   1
+#define FALSE                  0
+#define ABORT                  -1
+
+
+    /* What character marks an inverted character class? */
+#define NEGATE_CLASS           '^'
+    /* Is "*" a common pattern? */
+#define OPTIMIZE_JUST_STAR
+    /* Do tar(1) matching rules, which ignore a trailing slash? */
+#undef MATCH_TAR_PATTERN
+
+
+/*
+**  Match text and p, return TRUE, FALSE, or ABORT.
+*/
+static int
+DoMatch(text, p)
+    register char      *text;
+    register char      *p;
+{
+    register int       last;
+    register int       matched;
+    register int       reverse;
+
+    for ( ; *p; text++, p++) {
+       if (*text == '\0' && *p != '*')
+           return ABORT;
+       switch (*p) {
+       case '\\':
+           /* Literal match with following character. */
+           p++;
+           /* FALLTHROUGH */
+       default:
+           if (*text != *p)
+               return FALSE;
+           continue;
+       case '?':
+           /* Match anything. */
+           continue;
+       case '*':
+           while (*++p == '*')
+               /* Consecutive stars act just like one. */
+               continue;
+           if (*p == '\0')
+               /* Trailing star matches everything. */
+               return TRUE;
+           while (*text)
+               if ((matched = DoMatch(text++, p)) != FALSE)
+                   return matched;
+           return ABORT;
+       case '[':
+           reverse = p[1] == NEGATE_CLASS ? TRUE : FALSE;
+           if (reverse)
+               /* Inverted character class. */
+               p++;
+           for (last = 0400, matched = FALSE; *++p && *p != ']'; last = *p)
+               /* This next line requires a good C compiler. */
+               if (*p == '-' ? *text <= *++p && *text >= last : *text == *p)
+                   matched = TRUE;
+           if (matched == reverse)
+               return FALSE;
+           continue;
+       }
+    }
+
+#ifdef MATCH_TAR_PATTERN
+    if (*text == '/')
+       return TRUE;
+#endif /* MATCH_TAR_ATTERN */
+    return *text == '\0';
+}
+
+
+/*
+**  User-level routine.  Returns TRUE or FALSE.
+*/
+int
+wildmat(text, p)
+    char       *text;
+    char       *p;
+{
+#ifdef OPTIMIZE_JUST_STAR
+    if (p[0] == '*' && p[1] == '\0')
+       return TRUE;
+#endif /* OPTIMIZE_JUST_STAR */
+    return DoMatch(text, p) == TRUE;
+}
+
+\f
+
+#ifdef TEST
+#include <stdio.h>
+
+/* Yes, we use gets not fgets.  Sue me. */
+extern char    *gets();
+
+
+main()
+{
+    char        p[80];
+    char        text[80];
+
+    printf("Wildmat tester.  Enter pattern, then strings to test.\n");
+    printf("A blank line gets prompts for a new pattern; a blank pattern\n");
+    printf("exits the program.\n");
+
+    for ( ; ; ) {
+       printf("\nEnter pattern:  ");
+       (void)fflush(stdout);
+       if (gets(p) == NULL || p[0] == '\0')
+           break;
+       for ( ; ; ) {
+           printf("Enter text:  ");
+           (void)fflush(stdout);
+           if (gets(text) == NULL)
+               exit(0);
+           if (text[0] == '\0')
+               /* Blank line; go back and get a new pattern. */
+               break;
+           printf("      %s\n", wildmat(text, p) ? "YES" : "NO");
+       }
+    }
+
+    exit(0);
+    /* NOTREACHED */
+}
+#endif /* TEST */
diff --git a/Xserver/config/util/os2inst.cmd b/Xserver/config/util/os2inst.cmd
new file mode 100644 (file)
index 0000000..1a8d1ae
--- /dev/null
@@ -0,0 +1,50 @@
+/* OS/2 REXX SCRIPT */
+
+/* $XFree86: xc/config/util/os2inst.cmd,v 3.1 1996/02/19 12:16:52 dawes Exp $
+ *
+ * This is a wrapper for the install command. As any utility, 
+ * install could have been lifted from the BSD sources, but I just wanted
+ * to play with Rexx a bit :-)  (hv)
+ * Note the similarity to the Unix shell scripts
+ */
+
+dst=""
+src=""
+
+'@ECHO OFF'
+PARSE ARG all
+DO i=1 TO WORDS(all)
+       w = WORD(all,i)
+       SELECT
+       WHEN w = "-c" THEN NOP
+       WHEN w = "-m" THEN
+               i = i + 1
+               /* ignore mode */
+       WHEN w = "-o" THEN
+               i = i + 1
+               /* ignore owner */
+       WHEN w = "-g" THEN
+               i = i + 1
+               /* ignore group */
+       WHEN w = "-s" THEN NOP
+       OTHERWISE
+               IF src = "" THEN
+                       src = w
+               ELSE
+                       dst = w
+       END
+END
+
+IF src = "" THEN DO
+       SAY "os2inst:  no input file specified"
+       EXIT 1
+END
+
+IF dst = "" THEN DO
+       SAY "os2inst:  no destination specified"
+       EXIT 1
+END
+
+ADDRESS CMD 'copy' src dst '> nul'
+
+EXIT
diff --git a/Xserver/config/util/remove.cmd b/Xserver/config/util/remove.cmd
new file mode 100644 (file)
index 0000000..a9c7a8a
--- /dev/null
@@ -0,0 +1,14 @@
+/* OS/2 REXX script to remove cleaned files
+ * run with 'remove dirlist_file'
+ * where dirlist_file is be a XFree86 removed-* file
+ *
+ * $XFree86: xc/config/util/remove.cmd,v 3.0 1994/10/20 06:01:04 dawes Exp $
+ */
+'@echo off'
+file = arg(1)
+linein(file,1,0)
+curdir = directory()
+do while lines(file)=1
+  fs = translate(linein(file),'\','/')
+  del fs
+end
diff --git a/Xserver/config/util/syminst.sh b/Xserver/config/util/syminst.sh
new file mode 100755 (executable)
index 0000000..f9e1863
--- /dev/null
@@ -0,0 +1,90 @@
+#!/bin/sh
+
+#
+# syminst - install with a symbolic link back to the build tree
+#
+
+# set DOITPROG to echo to test this script
+
+doit="${DOITPROG-}"
+
+
+# put in absolute paths if you don't have them in your path; or use env. vars.
+
+lnprog="${LNPROG-ln -s}"
+rmprog="${RMPROG-rm}"
+
+instcmd="$lnprog"
+rmcmd="$rmprog -f"
+srcdir=`pwd`/
+src=""
+dst=""
+
+while [ x"$1" != x ]; do
+    case $1 in
+       -c) shift
+           continue;;
+
+       -m) shift
+           shift
+           continue;;
+
+       -o) shift
+           shift
+           continue;;
+
+       -g) shift
+           shift
+           continue;;
+
+       -s) shift
+           continue;;
+
+       -DIR) srcdir=`echo $2 | sed 's;/\./;/;g'`/
+             shift
+              shift
+              continue;;
+
+       *)  if [ x"$src" = x ]
+           then
+               src=$1
+           else
+               dst=$1
+           fi
+           shift
+           continue;;
+    esac
+done
+
+if [ x"$src" = x ]
+then
+       echo "syminst:  no input file specified"
+       exit 1
+fi
+
+if [ x"$dst" = x ]
+then
+       echo "syminst:  no destination specified"
+       exit 1
+fi
+
+
+# if destination is a directory, append the input filename; if your system
+# does not like double slashes in filenames, you may need to add some logic
+
+if [ -d $dst ]
+then
+       dst="$dst"/`basename $src`
+fi
+
+case $src in
+    /*) srcdir=""
+       instcmd=cp;;
+esac
+
+# get rid of the old one and mode the new one in
+
+$doit $rmcmd $dst
+$doit $instcmd $srcdir$src $dst
+
+exit 0
diff --git a/Xserver/config/util/x11mf.sh b/Xserver/config/util/x11mf.sh
new file mode 100755 (executable)
index 0000000..2c44194
--- /dev/null
@@ -0,0 +1,28 @@
+#!/bin/sh
+
+# 
+# generate a Makefile within the build tree
+# 
+# usage:  x11mf [treedir]
+# 
+
+if [ x$1 != x ]; then
+       tree=$1
+else
+       tree=/x11
+fi
+
+dir=`pwd`
+top=`(cd $tree; /bin/pwd)`
+intree=no
+
+case $dir in
+       $top*)  intree=yes;;
+esac
+
+if [ $intree != yes ]; then
+       echo "$0:  Must be underneath $tree"
+       exit 1
+fi
+
+(cd ..; make SUBDIRS=`basename $dir` Makefiles)
diff --git a/Xserver/config/util/xmake.cmd b/Xserver/config/util/xmake.cmd
new file mode 100644 (file)
index 0000000..f00cf71
--- /dev/null
@@ -0,0 +1,5 @@
+/* REXX */
+/* $XFree86: xc/config/util/xmake.cmd,v 3.1 1996/03/10 11:50:47 dawes Exp $ */
+'@echo off'
+PARSE ARG a1 a2 a3 a4 a5 a6 a7 a8 a9 a10
+x11make.exe 'MAKE=x11make.exe SHELL=' a1 a2 a3 a4 a5 a6 a7 a8 a9 a10
diff --git a/Xserver/config/util/xmkmf.cmd b/Xserver/config/util/xmkmf.cmd
new file mode 100644 (file)
index 0000000..7c4b3d5
--- /dev/null
@@ -0,0 +1,81 @@
+/* OS/2 REXX */
+/* make a Makefile from an Imakefile from inside or outside the sources
+ * 
+ * $XFree86: xc/config/util/xmkmf.cmd,v 3.1 1996/04/15 11:14:27 dawes Exp $
+ */
+'@ECHO OFF'
+
+/* this is actually used here */
+x11root = getenv('X11ROOT')
+
+/* these ones are checked only, because later scripts rely on their existance */
+libpath = getenv('LIBRARY_PATH')
+incpath = getenv('C_INCLUDE_PATH')
+
+/* get args */
+PARSE ARG arg0 arg1 arg2 arg3
+
+/* from here almost everything is the same as in the xmkmf sh script */
+topdir = ''
+curdir = '.'
+do_all = 0
+
+IF arg0 = '-a' THEN DO
+       do_all = 1
+       arg0 = arg1
+       arg1 = arg2
+       arg2 = arg3
+END
+ELSE DO
+       do_all = 0
+END
+
+IF \(arg0 = '') THEN DO
+       IF \(arg1 = '') THEN
+               curdir = arg1
+       topdir = arg0
+END
+IF \(arg2 = '') | SUBSTR(topdir,1,1) = '-' THEN DO
+       SAY 'usage:  xmkmf [-a] [top_of_sources_pathname [current_directory]]'
+       EXIT
+END
+
+IF exists('Makefile') THEN DO
+       SAY 'mv -f Makefile Makefile.bak'
+       'COPY Makefile Makefile.bak >nul 2>&1'
+       'DEL Makefile >nul 2>&1'
+END
+
+IF topdir = '' THEN
+       iargs = '-DUseInstalled -I'x11root'/XFree86/lib/X11/config'
+ELSE
+       iargs = '-I'topdir'/config/cf -DTOPDIR='topdir' -DCURDIR='curdir
+
+SAY 'imake 'iargs
+IF do_all = 1 THEN DO
+       'imake 'iargs
+       SAY 'make Makefiles'
+       CALL make 'Makefiles'
+       SAY 'make includes'
+       CALL make 'includes'
+       SAY 'make depend'
+       CALL make 'depend'
+END
+ELSE
+       'imake 'iargs
+
+EXIT
+
+exists:
+'DIR "'ARG(1)'" > nul 2>nul'
+IF rc = 0 THEN RETURN 1
+RETURN 0
+
+getenv:
+x = VALUE(ARG(1),,'OS2ENVIRONMENT')
+
+IF x = '' THEN DO
+       SAY 'No 'ARG(1)' environment variable set!'
+       EXIT
+END
+RETURN x
diff --git a/Xserver/config/util/xmkmf.cpp b/Xserver/config/util/xmkmf.cpp
new file mode 100644 (file)
index 0000000..d32a834
--- /dev/null
@@ -0,0 +1,58 @@
+XCOMM!/bin/sh
+
+XCOMM
+XCOMM make a Makefile from an Imakefile from inside or outside the sources
+XCOMM 
+XCOMM $XConsortium: xmkmf.cpp /main/22 1996/09/28 16:17:05 rws $
+
+usage="usage:  $0 [-a] [top_of_sources_pathname [current_directory]]"
+
+configdirspec=CONFIGDIRSPEC
+topdir=
+curdir=.
+do_all=
+
+case "$1" in
+-a)
+    do_all="yes"
+    shift
+    ;;
+esac
+
+case $# in 
+    0) ;;
+    1) topdir=$1 ;;
+    2) topdir=$1  curdir=$2 ;;
+    *) echo "$usage" 1>&2; exit 1 ;;
+esac
+
+case "$topdir" in
+    -*) echo "$usage" 1>&2; exit 1 ;;
+esac
+
+if [ -f Makefile ]; then 
+    echo mv -f Makefile Makefile.bak
+    mv -f Makefile Makefile.bak
+fi
+
+if [ "$topdir" = "" ]; then
+    args="-DUseInstalled "$configdirspec
+else
+    args="-I$topdir/config/cf -DTOPDIR=$topdir -DCURDIR=$curdir"
+fi
+
+echo imake $args
+case "$do_all" in
+yes)
+    imake $args && 
+    echo "make Makefiles" &&
+    make Makefiles &&
+    echo "make includes" &&
+    make includes &&
+    echo "make depend" &&
+    make depend
+    ;;
+*)
+    imake $args
+    ;;
+esac
diff --git a/Xserver/config/util/xmkmf.man b/Xserver/config/util/xmkmf.man
new file mode 100644 (file)
index 0000000..8aeeb0e
--- /dev/null
@@ -0,0 +1,87 @@
+.\" $XConsortium: xmkmf.man /main/8 1996/09/28 16:17:10 rws $
+.\" Copyright (c) 1993, 1994  X Consortium
+.\" 
+.\" Permission is hereby granted, free of charge, to any person obtaining a
+.\" copy of this software and associated documentation files (the "Software"), 
+.\" to deal in the Software without restriction, including without limitation 
+.\" the rights to use, copy, modify, merge, publish, distribute, sublicense, 
+.\" and/or sell copies of the Software, and to permit persons to whom the 
+.\" Software furnished to do so, subject to the following conditions:
+.\" 
+.\" The above copyright notice and this permission notice shall be included in
+.\" all copies or substantial portions of the Software.
+.\" 
+.\" THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+.\" IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+.\" FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL 
+.\" THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 
+.\" WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF 
+.\" OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 
+.\" SOFTWARE.
+.\" 
+.\" Except as contained in this notice, the name of the X Consortium shall not 
+.\" be used in advertising or otherwise to promote the sale, use or other 
+.\" dealing in this Software without prior written authorization from the 
+.\" X Consortium.
+.TH XMKMF 1 "Release 6.1" "X Version 11"
+.SH NAME
+xmkmf \- create a Makefile from an Imakefile
+.SH SYNOPSIS
+.B xmkmf
+[ -a ] [
+.I topdir
+[
+.I curdir
+] ]
+.SH DESCRIPTION
+The
+.I xmkmf
+command is the normal way to create a
+.I Makefile 
+from an
+.I Imakefile
+shipped with third-party software.
+.PP
+When invoked with no arguments in a directory containing an
+.I Imakefile,
+the
+.I imake
+program is run with arguments appropriate for your system
+(configured into
+.I xmkmf
+when X was built) and generates a
+.I Makefile.
+.PP
+When invoked with the
+.I \-a
+option,
+.I xmkmf
+builds the
+.I Makefile
+in the current directory, and then automatically executes
+``make Makefiles'' (in case there are subdirectories),
+``make includes'',
+and ``make depend'' for you.
+This is the normal way to configure software that is outside
+the X Consortium build tree.
+.PP
+If working inside the X Consortium build tree (unlikely unless you 
+are an X developer, and even then this option is never really used), the
+.I topdir
+argument should be specified as the relative pathname from the
+current directory to the top of the build tree.  Optionally,
+.I curdir
+may be specified as a relative pathname from the top of the build
+tree to the current directory.  It is necessary to supply
+.I curdir
+if the current directory has subdirectories, or the
+.I Makefile
+will not be able to build the subdirectories.
+If a
+.I topdir
+is given,
+.I xmkmf
+assumes nothing is installed on your system and looks for files in
+the build tree instead of using the installed versions.
+.SH "SEE ALSO"
+imake(1)
diff --git a/Xserver/include/DECkeysym.h b/Xserver/include/DECkeysym.h
new file mode 100644 (file)
index 0000000..d8ab5a4
--- /dev/null
@@ -0,0 +1,68 @@
+/* $XConsortium: DECkeysym.h,v 1.4 94/04/17 20:10:47 rws Exp $ */
+
+/***********************************************************
+
+Copyright (c) 1988  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+
+Copyright 1988 by Digital Equipment Corporation, Maynard, Massachusetts.
+
+                        All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and its 
+documentation for any purpose and without fee is hereby granted, 
+provided that the above copyright notice appear in all copies and that
+both that copyright notice and this permission notice appear in 
+supporting documentation, and that the name of Digital not be
+used in advertising or publicity pertaining to distribution of the
+software without specific, written prior permission.  
+
+DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
+ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
+DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
+ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+SOFTWARE.
+
+******************************************************************/
+
+/*
+ * DEC private keysyms
+ * (29th bit set)
+ */
+
+/* two-key compose sequence initiators, chosen to map to Latin1 characters */
+
+#define DXK_ring_accent         0x1000FEB0
+#define DXK_circumflex_accent   0x1000FE5E
+#define DXK_cedilla_accent      0x1000FE2C
+#define DXK_acute_accent        0x1000FE27
+#define DXK_grave_accent        0x1000FE60
+#define DXK_tilde               0x1000FE7E
+#define DXK_diaeresis           0x1000FE22
+
+/* special keysym for LK2** "Remove" key on editing keypad */
+
+#define DXK_Remove     0x1000FF00   /* Remove */
diff --git a/Xserver/include/HPkeysym.h b/Xserver/include/HPkeysym.h
new file mode 100644 (file)
index 0000000..87b79c3
--- /dev/null
@@ -0,0 +1,159 @@
+/* $XConsortium: HPkeysym.h,v 1.14 94/04/17 20:30:20 rws Exp $ */
+/*
+
+Copyright (c) 1987  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be included
+in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR
+OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall
+not be used in advertising or otherwise to promote the sale, use or
+other dealings in this Software without prior written authorization
+from the X Consortium.
+
+Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts,
+
+                        All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and its
+documentation for any purpose and without fee is hereby granted,
+provided that the above copyright notice appear in all copies and that
+both that copyright notice and this permission notice appear in
+supporting documentation, and that the names of Hewlett Packard
+or Digital not be
+used in advertising or publicity pertaining to distribution of the
+software without specific, written prior permission.
+
+DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
+ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
+DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
+ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+SOFTWARE.
+
+HEWLETT-PACKARD MAKES NO WARRANTY OF ANY KIND WITH REGARD
+TO THIS SOFWARE, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+PURPOSE.  Hewlett-Packard shall not be liable for errors
+contained herein or direct, indirect, special, incidental or
+consequential damages in connection with the furnishing,
+performance, or use of this material.
+
+*/
+
+#define hpXK_ClearLine         0x1000FF6F
+#define hpXK_InsertLine                0x1000FF70
+#define hpXK_DeleteLine                0x1000FF71
+#define hpXK_InsertChar                0x1000FF72
+#define hpXK_DeleteChar                0x1000FF73
+#define hpXK_BackTab           0x1000FF74
+#define hpXK_KP_BackTab                0x1000FF75
+#define hpXK_Modelock1         0x1000FF48
+#define hpXK_Modelock2         0x1000FF49
+#define hpXK_Reset             0x1000FF6C
+#define hpXK_System            0x1000FF6D
+#define hpXK_User              0x1000FF6E
+#define hpXK_mute_acute                0x100000A8
+#define hpXK_mute_grave                0x100000A9
+#define hpXK_mute_asciicircum  0x100000AA
+#define hpXK_mute_diaeresis    0x100000AB
+#define hpXK_mute_asciitilde   0x100000AC
+#define hpXK_lira              0x100000AF
+#define hpXK_guilder           0x100000BE
+#define hpXK_Ydiaeresis                0x100000EE
+#define hpXK_IO                        0x100000EE
+#define hpXK_longminus         0x100000F6
+#define hpXK_block             0x100000FC
+
+
+#ifndef _OSF_Keysyms
+#define _OSF_Keysyms
+
+#define osfXK_Copy             0x1004FF02
+#define osfXK_Cut              0x1004FF03
+#define osfXK_Paste            0x1004FF04
+#define osfXK_BackTab          0x1004FF07
+#define osfXK_BackSpace                0x1004FF08
+#define osfXK_Clear            0x1004FF0B
+#define osfXK_Escape           0x1004FF1B
+#define osfXK_AddMode          0x1004FF31
+#define osfXK_PrimaryPaste     0x1004FF32
+#define osfXK_QuickPaste       0x1004FF33
+#define osfXK_PageLeft         0x1004FF40
+#define osfXK_PageUp           0x1004FF41
+#define osfXK_PageDown         0x1004FF42
+#define osfXK_PageRight                0x1004FF43
+#define osfXK_Activate         0x1004FF44
+#define osfXK_MenuBar          0x1004FF45
+#define osfXK_Left             0x1004FF51
+#define osfXK_Up               0x1004FF52
+#define osfXK_Right            0x1004FF53
+#define osfXK_Down             0x1004FF54
+#define osfXK_EndLine          0x1004FF57
+#define osfXK_BeginLine                0x1004FF58
+#define osfXK_EndData          0x1004FF59
+#define osfXK_BeginData                0x1004FF5A
+#define osfXK_PrevMenu         0x1004FF5B
+#define osfXK_NextMenu         0x1004FF5C
+#define osfXK_PrevField                0x1004FF5D
+#define osfXK_NextField                0x1004FF5E
+#define osfXK_Select           0x1004FF60
+#define osfXK_Insert           0x1004FF63
+#define osfXK_Undo             0x1004FF65
+#define osfXK_Menu             0x1004FF67
+#define osfXK_Cancel           0x1004FF69
+#define osfXK_Help             0x1004FF6A
+#define osfXK_SelectAll                0x1004FF71
+#define osfXK_DeselectAll      0x1004FF72
+#define osfXK_Reselect         0x1004FF73
+#define osfXK_Extend           0x1004FF74
+#define osfXK_Restore          0x1004FF78
+#define osfXK_Delete           0x1004FFFF
+
+#endif /* _OSF_Keysyms */
+
+
+/**************************************************************
+ * The use of the following macros is deprecated.
+ * They are listed below only for backwards compatibility.
+ */
+#define XK_Reset                0x1000FF6C
+#define XK_System               0x1000FF6D
+#define XK_User                 0x1000FF6E
+#define XK_ClearLine            0x1000FF6F
+#define XK_InsertLine           0x1000FF70
+#define XK_DeleteLine           0x1000FF71
+#define XK_InsertChar           0x1000FF72
+#define XK_DeleteChar           0x1000FF73
+#define XK_BackTab              0x1000FF74
+#define XK_KP_BackTab           0x1000FF75
+#define XK_Ext16bit_L           0x1000FF76
+#define XK_Ext16bit_R           0x1000FF77
+#define XK_mute_acute           0x100000a8
+#define XK_mute_grave           0x100000a9
+#define XK_mute_asciicircum     0x100000aa
+#define XK_mute_diaeresis       0x100000ab
+#define XK_mute_asciitilde      0x100000ac
+#define XK_lira                 0x100000af
+#define XK_guilder              0x100000be
+#define XK_Ydiaeresis           0x100000ee
+#define XK_IO                   0x100000ee
+#define XK_longminus            0x100000f6
+#define XK_block                0x100000fc
diff --git a/Xserver/include/Imakefile b/Xserver/include/Imakefile
new file mode 100644 (file)
index 0000000..b07dde2
--- /dev/null
@@ -0,0 +1,57 @@
+XCOMM $TOG: Imakefile /main/93 1997/06/13 15:34:58 kaleb $
+
+
+
+
+XCOMM $XFree86: xc/include/Imakefile,v 3.9.2.1 1997/06/15 07:25:25 dawes Exp $
+#define IHaveSubdirs
+#define PassCDebugFlags /**/
+
+SUBDIRS = bitmaps extensions fonts
+
+#ifdef Win32Architecture
+EXTRA_HEADERS = Xw32defs.h Xwinsock.h
+#endif
+
+HEADERS = DECkeysym.h \
+       HPkeysym.h \
+       Sunkeysym.h \
+       X.h \
+       XWDFile.h \
+       Xalloca.h \
+       Xatom.h \
+       Xfuncproto.h \
+       Xfuncs.h \
+       Xmd.h \
+       Xos.h \
+       Xos_r.h \
+       Xosdefs.h \
+       Xpoll.h \
+       Xproto.h \
+       Xprotostr.h \
+       Xthreads.h \
+       ap_keysym.h \
+       keysym.h \
+       keysymdef.h \
+       $(EXTRA_HEADERS)
+
+all::
+
+BuildIncludes($(HEADERS),X11,..)
+
+InstallMultipleFlags($(HEADERS),$(INCDIR)/X11,$(INSTINCFLAGS))
+MakeSubdirs($(SUBDIRS))
+
+InstallLinkKitNonExecFile(X.h,$(LINKKITDIR)/include/X11)
+InstallLinkKitNonExecFile(Xalloca.h,$(LINKKITDIR)/include/X11)
+InstallLinkKitNonExecFile(Xfuncproto.h,$(LINKKITDIR)/include/X11)
+InstallLinkKitNonExecFile(Xfuncs.h,$(LINKKITDIR)/include/X11)
+InstallLinkKitNonExecFile(Xmd.h,$(LINKKITDIR)/include/X11)
+InstallLinkKitNonExecFile(Xos.h,$(LINKKITDIR)/include/X11)
+InstallLinkKitNonExecFile(Xosdefs.h,$(LINKKITDIR)/include/X11)
+InstallLinkKitNonExecFile(Xproto.h,$(LINKKITDIR)/include/X11)
+InstallLinkKitNonExecFile(Xprotostr.h,$(LINKKITDIR)/include/X11)
+
+depend::
+
+clean::
diff --git a/Xserver/include/Sunkeysym.h b/Xserver/include/Sunkeysym.h
new file mode 100644 (file)
index 0000000..86c805b
--- /dev/null
@@ -0,0 +1,113 @@
+/* $XConsortium: Sunkeysym.h,v 1.5 94/04/17 20:10:47 rws Exp $ */
+
+/************************************************************
+
+Copyright (c) 1991  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+
+Copyright 1991 by Sun Microsystems, Inc. Mountain View, CA.
+
+                    All Rights Reserved
+
+Permission  to  use,  copy,  modify,  and  distribute   this
+software  and  its documentation for any purpose and without
+fee is hereby granted, provided that the above copyright no-
+tice  appear  in all copies and that both that copyright no-
+tice and this permission notice appear in  supporting  docu-
+mentation,  and  that the name of Sun not be used in
+advertising or publicity pertaining to distribution  of  the
+software  without specific prior written permission. Sun 
+makes  no  representations about the suitability  of this
+software for any purpose. It is provided "as is" without any
+express or implied warranty.
+
+SUN DISCLAIMS ALL WARRANTIES WITH REGARD TO  THIS  SOFTWARE,
+INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FIT-
+NESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SUN BE  LI-
+ABLE  FOR  ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
+ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,  DATA  OR
+PROFITS,  WHETHER  IN  AN  ACTION OF CONTRACT, NEGLIGENCE OR
+OTHER TORTUOUS ACTION, ARISING OUT OF OR IN CONNECTION  WITH
+THE USE OR PERFORMANCE OF THIS SOFTWARE.
+
+***********************************************************/
+
+/*
+ * Floating Accent
+ */
+
+#define        SunXK_FA_Grave          0x1005FF00
+#define        SunXK_FA_Circum         0x1005FF01
+#define        SunXK_FA_Tilde          0x1005FF02
+#define        SunXK_FA_Acute          0x1005FF03
+#define        SunXK_FA_Diaeresis      0x1005FF04
+#define        SunXK_FA_Cedilla        0x1005FF05
+
+/*
+ * Miscellaneous Functions
+ */
+
+#define        SunXK_F36               0x1005FF10      /* Labeled F11 */
+#define        SunXK_F37               0x1005FF11      /* Labeled F12 */
+
+#define SunXK_Sys_Req          0x1005FF60
+#define SunXK_Print_Screen     0x0000FF61      /* Same as XK_Print */
+
+/*
+ * International & Multi-Key Character Composition
+ */
+
+#define SunXK_Compose          0x0000FF20      /* Same as XK_Multi_key */
+#define SunXK_AltGraph         0x0000FF7E      /* Same as XK_Mode_switch */
+
+/*
+ * Cursor Control
+ */
+
+#define SunXK_PageUp           0x0000FF55      /* Same as XK_Prior */
+#define SunXK_PageDown         0x0000FF56      /* Same as XK_Next */
+
+/*
+ * Open Look Functions
+ */
+
+#define SunXK_Undo             0x0000FF65      /* Same as XK_Undo */
+#define SunXK_Again            0x0000FF66      /* Same as XK_Redo */
+#define SunXK_Find             0x0000FF68      /* Same as XK_Find */
+#define SunXK_Stop             0x0000FF69      /* Same as XK_Cancel */
+#define SunXK_Props            0x1005FF70
+#define SunXK_Front            0x1005FF71
+#define SunXK_Copy             0x1005FF72
+#define SunXK_Open             0x1005FF73
+#define SunXK_Paste            0x1005FF74
+#define SunXK_Cut              0x1005FF75
+
+#define SunXK_PowerSwitch              0x1005FF76
+#define SunXK_AudioLowerVolume         0x1005FF77
+#define SunXK_AudioMute                        0x1005FF78
+#define SunXK_AudioRaiseVolume         0x1005FF79
+#define SunXK_VideoDegauss             0x1005FF7A
+#define SunXK_VideoLowerBrightness     0x1005FF7B
+#define SunXK_VideoRaiseBrightness     0x1005FF7C
+#define SunXK_PowerSwitchShift         0x1005FF7D
diff --git a/Xserver/include/X.h b/Xserver/include/X.h
new file mode 100644 (file)
index 0000000..f131adc
--- /dev/null
@@ -0,0 +1,693 @@
+/*
+ *     $XConsortium: X.h,v 1.69 94/04/17 20:10:48 dpw Exp $
+ */
+
+/* Definitions for the X window system likely to be used by applications */
+
+#ifndef X_H
+#define X_H
+
+/***********************************************************
+
+Copyright (c) 1987  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+
+Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
+
+                        All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and its 
+documentation for any purpose and without fee is hereby granted, 
+provided that the above copyright notice appear in all copies and that
+both that copyright notice and this permission notice appear in 
+supporting documentation, and that the name of Digital not be
+used in advertising or publicity pertaining to distribution of the
+software without specific, written prior permission.  
+
+DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
+ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
+DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
+ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+SOFTWARE.
+
+******************************************************************/
+#define X_PROTOCOL     11              /* current protocol version */
+#define X_PROTOCOL_REVISION 0          /* current minor version */
+
+/* Resources */
+
+/*
+ * _XSERVER64 must ONLY be defined when compiling X server sources on
+ * systems where unsigned long is not 32 bits, must NOT be used in
+ * client or library code.
+ */
+#ifndef _XSERVER64
+typedef unsigned long XID;
+typedef unsigned long Mask;
+typedef unsigned long Atom;
+typedef unsigned long VisualID;
+typedef unsigned long Time;
+#else
+#include <X11/Xmd.h>
+typedef CARD32 XID;
+typedef CARD32 Mask;
+typedef CARD32 Atom;
+typedef CARD32 VisualID;
+typedef CARD32 Time;
+#endif
+
+typedef XID Window;
+typedef XID Drawable;
+typedef XID Font;
+typedef XID Pixmap;
+typedef XID Cursor;
+typedef XID Colormap;
+typedef XID GContext;
+typedef XID KeySym;
+
+typedef unsigned char KeyCode;
+
+/*****************************************************************
+ * RESERVED RESOURCE AND CONSTANT DEFINITIONS
+ *****************************************************************/
+
+#define None                 0L        /* universal null resource or null atom */
+
+#define ParentRelative       1L        /* background pixmap in CreateWindow
+                                   and ChangeWindowAttributes */
+
+#define CopyFromParent       0L        /* border pixmap in CreateWindow
+                                      and ChangeWindowAttributes
+                                  special VisualID and special window
+                                      class passed to CreateWindow */
+
+#define PointerWindow        0L        /* destination window in SendEvent */
+#define InputFocus           1L        /* destination window in SendEvent */
+
+#define PointerRoot          1L        /* focus window in SetInputFocus */
+
+#define AnyPropertyType      0L        /* special Atom, passed to GetProperty */
+
+#define AnyKey              0L /* special Key Code, passed to GrabKey */
+
+#define AnyButton            0L        /* special Button Code, passed to GrabButton */
+
+#define AllTemporary         0L        /* special Resource ID passed to KillClient */
+
+#define CurrentTime          0L        /* special Time */
+
+#define NoSymbol            0L /* special KeySym */
+
+/***************************************************************** 
+ * EVENT DEFINITIONS 
+ *****************************************************************/
+
+/* Input Event Masks. Used as event-mask window attribute and as arguments
+   to Grab requests.  Not to be confused with event names.  */
+
+#define NoEventMask                    0L
+#define KeyPressMask                   (1L<<0)  
+#define KeyReleaseMask                 (1L<<1)  
+#define ButtonPressMask                        (1L<<2)  
+#define ButtonReleaseMask              (1L<<3)  
+#define EnterWindowMask                        (1L<<4)  
+#define LeaveWindowMask                        (1L<<5)  
+#define PointerMotionMask              (1L<<6)  
+#define PointerMotionHintMask          (1L<<7)  
+#define Button1MotionMask              (1L<<8)  
+#define Button2MotionMask              (1L<<9)  
+#define Button3MotionMask              (1L<<10) 
+#define Button4MotionMask              (1L<<11) 
+#define Button5MotionMask              (1L<<12) 
+#define ButtonMotionMask               (1L<<13) 
+#define KeymapStateMask                        (1L<<14)
+#define ExposureMask                   (1L<<15) 
+#define VisibilityChangeMask           (1L<<16) 
+#define StructureNotifyMask            (1L<<17) 
+#define ResizeRedirectMask             (1L<<18) 
+#define SubstructureNotifyMask         (1L<<19) 
+#define SubstructureRedirectMask       (1L<<20) 
+#define FocusChangeMask                        (1L<<21) 
+#define PropertyChangeMask             (1L<<22) 
+#define ColormapChangeMask             (1L<<23) 
+#define OwnerGrabButtonMask            (1L<<24) 
+
+/* Event names.  Used in "type" field in XEvent structures.  Not to be
+confused with event masks above.  They start from 2 because 0 and 1
+are reserved in the protocol for errors and replies. */
+
+#define KeyPress               2
+#define KeyRelease             3
+#define ButtonPress            4
+#define ButtonRelease          5
+#define MotionNotify           6
+#define EnterNotify            7
+#define LeaveNotify            8
+#define FocusIn                        9
+#define FocusOut               10
+#define KeymapNotify           11
+#define Expose                 12
+#define GraphicsExpose         13
+#define NoExpose               14
+#define VisibilityNotify       15
+#define CreateNotify           16
+#define DestroyNotify          17
+#define UnmapNotify            18
+#define MapNotify              19
+#define MapRequest             20
+#define ReparentNotify         21
+#define ConfigureNotify                22
+#define ConfigureRequest       23
+#define GravityNotify          24
+#define ResizeRequest          25
+#define CirculateNotify                26
+#define CirculateRequest       27
+#define PropertyNotify         28
+#define SelectionClear         29
+#define SelectionRequest       30
+#define SelectionNotify                31
+#define ColormapNotify         32
+#define ClientMessage          33
+#define MappingNotify          34
+#define LASTEvent              35      /* must be bigger than any event # */
+
+
+/* Key masks. Used as modifiers to GrabButton and GrabKey, results of QueryPointer,
+   state in various key-, mouse-, and button-related events. */
+
+#define ShiftMask              (1<<0)
+#define LockMask               (1<<1)
+#define ControlMask            (1<<2)
+#define Mod1Mask               (1<<3)
+#define Mod2Mask               (1<<4)
+#define Mod3Mask               (1<<5)
+#define Mod4Mask               (1<<6)
+#define Mod5Mask               (1<<7)
+
+/* modifier names.  Used to build a SetModifierMapping request or
+   to read a GetModifierMapping request.  These correspond to the
+   masks defined above. */
+#define ShiftMapIndex          0
+#define LockMapIndex           1
+#define ControlMapIndex                2
+#define Mod1MapIndex           3
+#define Mod2MapIndex           4
+#define Mod3MapIndex           5
+#define Mod4MapIndex           6
+#define Mod5MapIndex           7
+
+
+/* button masks.  Used in same manner as Key masks above. Not to be confused
+   with button names below. */
+
+#define Button1Mask            (1<<8)
+#define Button2Mask            (1<<9)
+#define Button3Mask            (1<<10)
+#define Button4Mask            (1<<11)
+#define Button5Mask            (1<<12)
+
+#define AnyModifier            (1<<15)  /* used in GrabButton, GrabKey */
+
+
+/* button names. Used as arguments to GrabButton and as detail in ButtonPress
+   and ButtonRelease events.  Not to be confused with button masks above.
+   Note that 0 is already defined above as "AnyButton".  */
+
+#define Button1                        1
+#define Button2                        2
+#define Button3                        3
+#define Button4                        4
+#define Button5                        5
+
+/* Notify modes */
+
+#define NotifyNormal           0
+#define NotifyGrab             1
+#define NotifyUngrab           2
+#define NotifyWhileGrabbed     3
+
+#define NotifyHint             1       /* for MotionNotify events */
+                      
+/* Notify detail */
+
+#define NotifyAncestor         0
+#define NotifyVirtual          1
+#define NotifyInferior         2
+#define NotifyNonlinear                3
+#define NotifyNonlinearVirtual 4
+#define NotifyPointer          5
+#define NotifyPointerRoot      6
+#define NotifyDetailNone       7
+
+/* Visibility notify */
+
+#define VisibilityUnobscured           0
+#define VisibilityPartiallyObscured    1
+#define VisibilityFullyObscured                2
+
+/* Circulation request */
+
+#define PlaceOnTop             0
+#define PlaceOnBottom          1
+
+/* protocol families */
+
+#define FamilyInternet         0
+#define FamilyDECnet           1
+#define FamilyChaos            2
+
+/* Property notification */
+
+#define PropertyNewValue       0
+#define PropertyDelete         1
+
+/* Color Map notification */
+
+#define ColormapUninstalled    0
+#define ColormapInstalled      1
+
+/* GrabPointer, GrabButton, GrabKeyboard, GrabKey Modes */
+
+#define GrabModeSync           0
+#define GrabModeAsync          1
+
+/* GrabPointer, GrabKeyboard reply status */
+
+#define GrabSuccess            0
+#define AlreadyGrabbed         1
+#define GrabInvalidTime                2
+#define GrabNotViewable                3
+#define GrabFrozen             4
+
+/* AllowEvents modes */
+
+#define AsyncPointer           0
+#define SyncPointer            1
+#define ReplayPointer          2
+#define AsyncKeyboard          3
+#define SyncKeyboard           4
+#define ReplayKeyboard         5
+#define AsyncBoth              6
+#define SyncBoth               7
+
+/* Used in SetInputFocus, GetInputFocus */
+
+#define RevertToNone           (int)None
+#define RevertToPointerRoot    (int)PointerRoot
+#define RevertToParent         2
+
+/*****************************************************************
+ * ERROR CODES 
+ *****************************************************************/
+
+#define Success                   0    /* everything's okay */
+#define BadRequest        1    /* bad request code */
+#define BadValue          2    /* int parameter out of range */
+#define BadWindow         3    /* parameter not a Window */
+#define BadPixmap         4    /* parameter not a Pixmap */
+#define BadAtom                   5    /* parameter not an Atom */
+#define BadCursor         6    /* parameter not a Cursor */
+#define BadFont                   7    /* parameter not a Font */
+#define BadMatch          8    /* parameter mismatch */
+#define BadDrawable       9    /* parameter not a Pixmap or Window */
+#define BadAccess        10    /* depending on context:
+                                - key/button already grabbed
+                                - attempt to free an illegal 
+                                  cmap entry 
+                               - attempt to store into a read-only 
+                                  color map entry.
+                               - attempt to modify the access control
+                                  list from other than the local host.
+                               */
+#define BadAlloc         11    /* insufficient resources */
+#define BadColor         12    /* no such colormap */
+#define BadGC            13    /* parameter not a GC */
+#define BadIDChoice      14    /* choice not in range or already used */
+#define BadName                  15    /* font or color name doesn't exist */
+#define BadLength        16    /* Request length incorrect */
+#define BadImplementation 17   /* server is defective */
+
+#define FirstExtensionError    128
+#define LastExtensionError     255
+
+/*****************************************************************
+ * WINDOW DEFINITIONS 
+ *****************************************************************/
+
+/* Window classes used by CreateWindow */
+/* Note that CopyFromParent is already defined as 0 above */
+
+#define InputOutput            1
+#define InputOnly              2
+
+/* Window attributes for CreateWindow and ChangeWindowAttributes */
+
+#define CWBackPixmap           (1L<<0)
+#define CWBackPixel            (1L<<1)
+#define CWBorderPixmap         (1L<<2)
+#define CWBorderPixel           (1L<<3)
+#define CWBitGravity           (1L<<4)
+#define CWWinGravity           (1L<<5)
+#define CWBackingStore          (1L<<6)
+#define CWBackingPlanes                (1L<<7)
+#define CWBackingPixel         (1L<<8)
+#define CWOverrideRedirect     (1L<<9)
+#define CWSaveUnder            (1L<<10)
+#define CWEventMask            (1L<<11)
+#define CWDontPropagate                (1L<<12)
+#define CWColormap             (1L<<13)
+#define CWCursor               (1L<<14)
+
+/* ConfigureWindow structure */
+
+#define CWX                    (1<<0)
+#define CWY                    (1<<1)
+#define CWWidth                        (1<<2)
+#define CWHeight               (1<<3)
+#define CWBorderWidth          (1<<4)
+#define CWSibling              (1<<5)
+#define CWStackMode            (1<<6)
+
+
+/* Bit Gravity */
+
+#define ForgetGravity          0
+#define NorthWestGravity       1
+#define NorthGravity           2
+#define NorthEastGravity       3
+#define WestGravity            4
+#define CenterGravity          5
+#define EastGravity            6
+#define SouthWestGravity       7
+#define SouthGravity           8
+#define SouthEastGravity       9
+#define StaticGravity          10
+
+/* Window gravity + bit gravity above */
+
+#define UnmapGravity           0
+
+/* Used in CreateWindow for backing-store hint */
+
+#define NotUseful               0
+#define WhenMapped              1
+#define Always                  2
+
+/* Used in GetWindowAttributes reply */
+
+#define IsUnmapped             0
+#define IsUnviewable           1
+#define IsViewable             2
+
+/* Used in ChangeSaveSet */
+
+#define SetModeInsert           0
+#define SetModeDelete           1
+
+/* Used in ChangeCloseDownMode */
+
+#define DestroyAll              0
+#define RetainPermanent         1
+#define RetainTemporary         2
+
+/* Window stacking method (in configureWindow) */
+
+#define Above                   0
+#define Below                   1
+#define TopIf                   2
+#define BottomIf                3
+#define Opposite                4
+
+/* Circulation direction */
+
+#define RaiseLowest             0
+#define LowerHighest            1
+
+/* Property modes */
+
+#define PropModeReplace         0
+#define PropModePrepend         1
+#define PropModeAppend          2
+
+/*****************************************************************
+ * GRAPHICS DEFINITIONS
+ *****************************************************************/
+
+/* graphics functions, as in GC.alu */
+
+#define        GXclear                 0x0             /* 0 */
+#define GXand                  0x1             /* src AND dst */
+#define GXandReverse           0x2             /* src AND NOT dst */
+#define GXcopy                 0x3             /* src */
+#define GXandInverted          0x4             /* NOT src AND dst */
+#define        GXnoop                  0x5             /* dst */
+#define GXxor                  0x6             /* src XOR dst */
+#define GXor                   0x7             /* src OR dst */
+#define GXnor                  0x8             /* NOT src AND NOT dst */
+#define GXequiv                        0x9             /* NOT src XOR dst */
+#define GXinvert               0xa             /* NOT dst */
+#define GXorReverse            0xb             /* src OR NOT dst */
+#define GXcopyInverted         0xc             /* NOT src */
+#define GXorInverted           0xd             /* NOT src OR dst */
+#define GXnand                 0xe             /* NOT src OR NOT dst */
+#define GXset                  0xf             /* 1 */
+
+/* LineStyle */
+
+#define LineSolid              0
+#define LineOnOffDash          1
+#define LineDoubleDash         2
+
+/* capStyle */
+
+#define CapNotLast             0
+#define CapButt                        1
+#define CapRound               2
+#define CapProjecting          3
+
+/* joinStyle */
+
+#define JoinMiter              0
+#define JoinRound              1
+#define JoinBevel              2
+
+/* fillStyle */
+
+#define FillSolid              0
+#define FillTiled              1
+#define FillStippled           2
+#define FillOpaqueStippled     3
+
+/* fillRule */
+
+#define EvenOddRule            0
+#define WindingRule            1
+
+/* subwindow mode */
+
+#define ClipByChildren         0
+#define IncludeInferiors       1
+
+/* SetClipRectangles ordering */
+
+#define Unsorted               0
+#define YSorted                        1
+#define YXSorted               2
+#define YXBanded               3
+
+/* CoordinateMode for drawing routines */
+
+#define CoordModeOrigin                0       /* relative to the origin */
+#define CoordModePrevious       1      /* relative to previous point */
+
+/* Polygon shapes */
+
+#define Complex                        0       /* paths may intersect */
+#define Nonconvex              1       /* no paths intersect, but not convex */
+#define Convex                 2       /* wholly convex */
+
+/* Arc modes for PolyFillArc */
+
+#define ArcChord               0       /* join endpoints of arc */
+#define ArcPieSlice            1       /* join endpoints to center of arc */
+
+/* GC components: masks used in CreateGC, CopyGC, ChangeGC, OR'ed into
+   GC.stateChanges */
+
+#define GCFunction              (1L<<0)
+#define GCPlaneMask             (1L<<1)
+#define GCForeground            (1L<<2)
+#define GCBackground            (1L<<3)
+#define GCLineWidth             (1L<<4)
+#define GCLineStyle             (1L<<5)
+#define GCCapStyle              (1L<<6)
+#define GCJoinStyle            (1L<<7)
+#define GCFillStyle            (1L<<8)
+#define GCFillRule             (1L<<9) 
+#define GCTile                 (1L<<10)
+#define GCStipple              (1L<<11)
+#define GCTileStipXOrigin      (1L<<12)
+#define GCTileStipYOrigin      (1L<<13)
+#define GCFont                         (1L<<14)
+#define GCSubwindowMode                (1L<<15)
+#define GCGraphicsExposures     (1L<<16)
+#define GCClipXOrigin          (1L<<17)
+#define GCClipYOrigin          (1L<<18)
+#define GCClipMask             (1L<<19)
+#define GCDashOffset           (1L<<20)
+#define GCDashList             (1L<<21)
+#define GCArcMode              (1L<<22)
+
+#define GCLastBit              22
+/*****************************************************************
+ * FONTS 
+ *****************************************************************/
+
+/* used in QueryFont -- draw direction */
+
+#define FontLeftToRight                0
+#define FontRightToLeft                1
+
+#define FontChange             255
+
+/*****************************************************************
+ *  IMAGING 
+ *****************************************************************/
+
+/* ImageFormat -- PutImage, GetImage */
+
+#define XYBitmap               0       /* depth 1, XYFormat */
+#define XYPixmap               1       /* depth == drawable depth */
+#define ZPixmap                        2       /* depth == drawable depth */
+
+/*****************************************************************
+ *  COLOR MAP STUFF 
+ *****************************************************************/
+
+/* For CreateColormap */
+
+#define AllocNone              0       /* create map with no entries */
+#define AllocAll               1       /* allocate entire map writeable */
+
+
+/* Flags used in StoreNamedColor, StoreColors */
+
+#define DoRed                  (1<<0)
+#define DoGreen                        (1<<1)
+#define DoBlue                 (1<<2)
+
+/*****************************************************************
+ * CURSOR STUFF
+ *****************************************************************/
+
+/* QueryBestSize Class */
+
+#define CursorShape            0       /* largest size that can be displayed */
+#define TileShape              1       /* size tiled fastest */
+#define StippleShape           2       /* size stippled fastest */
+
+/***************************************************************** 
+ * KEYBOARD/POINTER STUFF
+ *****************************************************************/
+
+#define AutoRepeatModeOff      0
+#define AutoRepeatModeOn       1
+#define AutoRepeatModeDefault  2
+
+#define LedModeOff             0
+#define LedModeOn              1
+
+/* masks for ChangeKeyboardControl */
+
+#define KBKeyClickPercent      (1L<<0)
+#define KBBellPercent          (1L<<1)
+#define KBBellPitch            (1L<<2)
+#define KBBellDuration         (1L<<3)
+#define KBLed                  (1L<<4)
+#define KBLedMode              (1L<<5)
+#define KBKey                  (1L<<6)
+#define KBAutoRepeatMode       (1L<<7)
+
+#define MappingSuccess         0
+#define MappingBusy            1
+#define MappingFailed          2
+
+#define MappingModifier                0
+#define MappingKeyboard                1
+#define MappingPointer         2
+
+/*****************************************************************
+ * SCREEN SAVER STUFF 
+ *****************************************************************/
+
+#define DontPreferBlanking     0
+#define PreferBlanking         1
+#define DefaultBlanking                2
+
+#define DisableScreenSaver     0
+#define DisableScreenInterval  0
+
+#define DontAllowExposures     0
+#define AllowExposures         1
+#define DefaultExposures       2
+
+/* for ForceScreenSaver */
+
+#define ScreenSaverReset 0
+#define ScreenSaverActive 1
+
+/*****************************************************************
+ * HOSTS AND CONNECTIONS
+ *****************************************************************/
+
+/* for ChangeHosts */
+
+#define HostInsert             0
+#define HostDelete             1
+
+/* for ChangeAccessControl */
+
+#define EnableAccess           1      
+#define DisableAccess          0
+
+/* Display classes  used in opening the connection 
+ * Note that the statically allocated ones are even numbered and the
+ * dynamically changeable ones are odd numbered */
+
+#define StaticGray             0
+#define GrayScale              1
+#define StaticColor            2
+#define PseudoColor            3
+#define TrueColor              4
+#define DirectColor            5
+
+
+/* Byte order  used in imageByteOrder and bitmapBitOrder */
+
+#define LSBFirst               0
+#define MSBFirst               1
+
+#endif /* X_H */
diff --git a/Xserver/include/XWDFile.h b/Xserver/include/XWDFile.h
new file mode 100644 (file)
index 0000000..141ae65
--- /dev/null
@@ -0,0 +1,115 @@
+/* $XConsortium: XWDFile.h /main/18 1995/12/07 10:24:58 kaleb $ */
+/*
+
+Copyright (c) 1985, 1986  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+*/
+
+/*
+ * XWDFile.h   MIT Project Athena, X Window system window raster
+ *             image dumper, dump file format header file.
+ *
+ *  Author:    Tony Della Fera, DEC
+ *             27-Jun-85
+ * 
+ * Modifier:    William F. Wyatt, SAO
+ *              18-Nov-86  - version 6 for saving/restoring color maps
+ */
+
+#ifndef XWDFILE_H
+#define XWDFILE_H
+
+#include <X11/Xmd.h>
+
+#define XWD_FILE_VERSION 7
+#define sz_XWDheader 100
+#define sz_XWDColor 12
+
+typedef CARD32 xwdval;         /* for old broken programs */
+
+/* Values in the file are most significant byte first. */
+
+typedef struct _xwd_file_header {
+       /* header_size = SIZEOF(XWDheader) + length of null-terminated
+        * window name. */
+       CARD32 header_size B32;         
+
+       CARD32 file_version B32;        /* = XWD_FILE_VERSION above */
+       CARD32 pixmap_format B32;       /* ZPixmap or XYPixmap */
+       CARD32 pixmap_depth B32;        /* Pixmap depth */
+       CARD32 pixmap_width B32;        /* Pixmap width */
+       CARD32 pixmap_height B32;       /* Pixmap height */
+       CARD32 xoffset B32;             /* Bitmap x offset, normally 0 */
+       CARD32 byte_order B32;          /* of image data: MSBFirst, LSBFirst */
+
+       /* bitmap_unit applies to bitmaps (depth 1 format XY) only.
+        * It is the number of bits that each scanline is padded to. */
+       CARD32 bitmap_unit B32;         
+
+       CARD32 bitmap_bit_order B32;    /* bitmaps only: MSBFirst, LSBFirst */
+
+       /* bitmap_pad applies to pixmaps (non-bitmaps) only.
+        * It is the number of bits that each scanline is padded to. */
+       CARD32 bitmap_pad B32;          
+
+       CARD32 bits_per_pixel B32;      /* Bits per pixel */
+
+       /* bytes_per_line is pixmap_width padded to bitmap_unit (bitmaps)
+        * or bitmap_pad (pixmaps).  It is the delta (in bytes) to get
+        * to the same x position on an adjacent row. */
+       CARD32 bytes_per_line B32;
+       CARD32 visual_class B32;        /* Class of colormap */
+       CARD32 red_mask B32;            /* Z red mask */
+       CARD32 green_mask B32;          /* Z green mask */
+       CARD32 blue_mask B32;           /* Z blue mask */
+       CARD32 bits_per_rgb B32;        /* Log2 of distinct color values */
+       CARD32 colormap_entries B32;    /* Number of entries in colormap; not used? */
+       CARD32 ncolors B32;             /* Number of XWDColor structures */
+       CARD32 window_width B32;        /* Window width */
+       CARD32 window_height B32;       /* Window height */
+       CARD32 window_x B32;            /* Window upper left X coordinate */
+       CARD32 window_y B32;            /* Window upper left Y coordinate */
+       CARD32 window_bdrwidth B32;     /* Window border width */
+} XWDFileHeader;
+
+/* Null-terminated window name follows the above structure. */
+
+/* Next comes XWDColor structures, at offset XWDFileHeader.header_size in
+ * the file.  XWDFileHeader.ncolors tells how many XWDColor structures
+ * there are.
+ */
+
+typedef struct {
+        CARD32 pixel B32;
+        CARD16 red B16;
+       CARD16  green B16;
+       CARD16  blue B16;
+        CARD8  flags;
+        CARD8  pad;
+} XWDColor;
+
+/* Last comes the image data in the format described by XWDFileHeader. */
+
+#endif /* XWDFILE_H */
+
diff --git a/Xserver/include/Xalloca.h b/Xserver/include/Xalloca.h
new file mode 100644 (file)
index 0000000..a730603
--- /dev/null
@@ -0,0 +1,137 @@
+/* $XConsortium: Xalloca.h /main/6 1996/09/28 16:17:22 rws $ */
+
+/*
+
+Copyright (c) 1995  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR
+OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall
+not be used in advertising or otherwise to promote the sale, use or
+other dealings in this Software without prior written authorization
+from the X Consortium.
+
+*/
+
+/*
+ * The purpose of this header is to define the macros ALLOCATE_LOCAL and
+ * DEALLOCATE_LOCAL appropriately for the platform being compiled on.
+ * These macros are used to make fast, function-local memory allocations.
+ * Their characteristics are as follows:
+ *
+ * void *ALLOCATE_LOCAL(int size)
+ *    Returns a pointer to size bytes of memory, or NULL if the allocation
+ *    failed.  The memory must be freed with DEALLOCATE_LOCAL before the
+ *    function that made the allocation returns.  You should not ask for
+ *    large blocks of memory with this function, since on many platforms
+ *    the memory comes from the stack, which may have limited size.
+ *
+ * void DEALLOCATE_LOCAL(void *)
+ *    Frees the memory allocated by ALLOCATE_LOCAL.  Omission of this
+ *    step may be harmless on some platforms, but will result in
+ *    memory leaks or worse on others.
+ *
+ * Before including this file, you should define two macros,
+ * ALLOCATE_LOCAL_FALLBACK and DEALLOCATE_LOCAL_FALLBACK, that have the
+ * same characteristics as ALLOCATE_LOCAL and DEALLOCATE_LOCAL.  The
+ * header uses the fallbacks if it doesn't know a "better" way to define
+ * ALLOCATE_LOCAL and DEALLOCATE_LOCAL.  Typical usage would be:
+ *
+ *    #define ALLOCATE_LOCAL_FALLBACK(_size) malloc(_size)
+ *    #define DEALLOCATE_LOCAL_FALLBACK(_ptr) free(_ptr)
+ *    #include "Xalloca.h"
+ */
+
+#ifndef XALLOCA_H
+#define XALLOCA_H 1
+
+#ifdef INCLUDE_ALLOCA_H
+#  include <alloca.h>
+#endif
+
+#ifndef NO_ALLOCA
+/*
+ * os-dependent definition of local allocation and deallocation
+ * If you want something other than (DE)ALLOCATE_LOCAL_FALLBACK
+ * for ALLOCATE/DEALLOCATE_LOCAL then you add that in here.
+ */
+#  if defined(__HIGHC__)
+#    ifndef NCR
+       extern char *alloca();
+#      if HCVERSION < 21003
+#        define ALLOCATE_LOCAL(size)   alloca((int)(size))
+         pragma on(alloca);
+#      else /* HCVERSION >= 21003 */
+#        define        ALLOCATE_LOCAL(size)    _Alloca((int)(size))
+#      endif /* HCVERSION < 21003 */
+#    else /* NCR */
+#      define ALLOCATE_LOCAL(size)     alloca(size)
+#    endif
+#  define DEALLOCATE_LOCAL(ptr)  /* as nothing */
+#  endif /* defined(__HIGHC__) */
+
+
+#  ifdef __GNUC__
+#    ifndef alloca
+#      define alloca __builtin_alloca
+#    endif /* !alloca */
+#    define ALLOCATE_LOCAL(size) alloca((int)(size))
+#    define DEALLOCATE_LOCAL(ptr)  /* as nothing */
+#  else /* ! __GNUC__ */
+
+/*
+ * warning: old mips alloca (pre 2.10) is unusable, new one is built in
+ * Test is easy, the new one is named __builtin_alloca and comes
+ * from alloca.h which #defines alloca.
+ */
+#    ifndef NCR
+#      if defined(vax) || defined(sun) || defined(apollo) || defined(stellar) || defined(USL) || defined(alloca)
+/*
+ * Some System V boxes extract alloca.o from /lib/libPW.a; if you
+ * decide that you don't want to use alloca, you might want to fix it here.
+ */
+/* alloca might be a macro taking one arg (hi, Sun!), so give it one. */
+#        ifndef __sgi                  /* IRIX 5/6 has definition */
+#          define __Xnullarg           /* as nothing */
+#          ifndef X_NOT_STDC_ENV
+             extern void *alloca(__Xnullarg);
+#          else
+             extern char *alloca(__Xnullarg);
+#          endif
+#        endif /* __sgi */
+#        define ALLOCATE_LOCAL(size) alloca((int)(size))
+#        define DEALLOCATE_LOCAL(ptr)  /* as nothing */
+#      endif /* who does alloca */
+#    endif /* NCR */
+#  endif /* __GNUC__ */
+
+#endif /* NO_ALLOCA */
+
+#if !defined(ALLOCATE_LOCAL)
+#  if defined(ALLOCATE_LOCAL_FALLBACK) && defined(DEALLOCATE_LOCAL_FALLBACK)
+#    define ALLOCATE_LOCAL(_size)  ALLOCATE_LOCAL_FALLBACK(_size)
+#    define DEALLOCATE_LOCAL(_ptr) DEALLOCATE_LOCAL_FALLBACK(_ptr)
+#  else /* no fallbacks supplied; error */
+#    define ALLOCATE_LOCAL(_size)  ALLOCATE_LOCAL_FALLBACK undefined!
+#    define DEALLOCATE_LOCAL(_ptr) DEALLOCATE_LOCAL_FALLBACK undefined!
+#  endif /* defined(ALLOCATE_LOCAL_FALLBACK && DEALLOCATE_LOCAL_FALLBACK) */
+#endif /* !defined(ALLOCATE_LOCAL) */
+
+#endif /* XALLOCA_H */
diff --git a/Xserver/include/Xatom.h b/Xserver/include/Xatom.h
new file mode 100644 (file)
index 0000000..485a423
--- /dev/null
@@ -0,0 +1,79 @@
+#ifndef XATOM_H
+#define XATOM_H 1
+
+/* THIS IS A GENERATED FILE
+ *
+ * Do not change!  Changing this file implies a protocol change!
+ */
+
+#define XA_PRIMARY ((Atom) 1)
+#define XA_SECONDARY ((Atom) 2)
+#define XA_ARC ((Atom) 3)
+#define XA_ATOM ((Atom) 4)
+#define XA_BITMAP ((Atom) 5)
+#define XA_CARDINAL ((Atom) 6)
+#define XA_COLORMAP ((Atom) 7)
+#define XA_CURSOR ((Atom) 8)
+#define XA_CUT_BUFFER0 ((Atom) 9)
+#define XA_CUT_BUFFER1 ((Atom) 10)
+#define XA_CUT_BUFFER2 ((Atom) 11)
+#define XA_CUT_BUFFER3 ((Atom) 12)
+#define XA_CUT_BUFFER4 ((Atom) 13)
+#define XA_CUT_BUFFER5 ((Atom) 14)
+#define XA_CUT_BUFFER6 ((Atom) 15)
+#define XA_CUT_BUFFER7 ((Atom) 16)
+#define XA_DRAWABLE ((Atom) 17)
+#define XA_FONT ((Atom) 18)
+#define XA_INTEGER ((Atom) 19)
+#define XA_PIXMAP ((Atom) 20)
+#define XA_POINT ((Atom) 21)
+#define XA_RECTANGLE ((Atom) 22)
+#define XA_RESOURCE_MANAGER ((Atom) 23)
+#define XA_RGB_COLOR_MAP ((Atom) 24)
+#define XA_RGB_BEST_MAP ((Atom) 25)
+#define XA_RGB_BLUE_MAP ((Atom) 26)
+#define XA_RGB_DEFAULT_MAP ((Atom) 27)
+#define XA_RGB_GRAY_MAP ((Atom) 28)
+#define XA_RGB_GREEN_MAP ((Atom) 29)
+#define XA_RGB_RED_MAP ((Atom) 30)
+#define XA_STRING ((Atom) 31)
+#define XA_VISUALID ((Atom) 32)
+#define XA_WINDOW ((Atom) 33)
+#define XA_WM_COMMAND ((Atom) 34)
+#define XA_WM_HINTS ((Atom) 35)
+#define XA_WM_CLIENT_MACHINE ((Atom) 36)
+#define XA_WM_ICON_NAME ((Atom) 37)
+#define XA_WM_ICON_SIZE ((Atom) 38)
+#define XA_WM_NAME ((Atom) 39)
+#define XA_WM_NORMAL_HINTS ((Atom) 40)
+#define XA_WM_SIZE_HINTS ((Atom) 41)
+#define XA_WM_ZOOM_HINTS ((Atom) 42)
+#define XA_MIN_SPACE ((Atom) 43)
+#define XA_NORM_SPACE ((Atom) 44)
+#define XA_MAX_SPACE ((Atom) 45)
+#define XA_END_SPACE ((Atom) 46)
+#define XA_SUPERSCRIPT_X ((Atom) 47)
+#define XA_SUPERSCRIPT_Y ((Atom) 48)
+#define XA_SUBSCRIPT_X ((Atom) 49)
+#define XA_SUBSCRIPT_Y ((Atom) 50)
+#define XA_UNDERLINE_POSITION ((Atom) 51)
+#define XA_UNDERLINE_THICKNESS ((Atom) 52)
+#define XA_STRIKEOUT_ASCENT ((Atom) 53)
+#define XA_STRIKEOUT_DESCENT ((Atom) 54)
+#define XA_ITALIC_ANGLE ((Atom) 55)
+#define XA_X_HEIGHT ((Atom) 56)
+#define XA_QUAD_WIDTH ((Atom) 57)
+#define XA_WEIGHT ((Atom) 58)
+#define XA_POINT_SIZE ((Atom) 59)
+#define XA_RESOLUTION ((Atom) 60)
+#define XA_COPYRIGHT ((Atom) 61)
+#define XA_NOTICE ((Atom) 62)
+#define XA_FONT_NAME ((Atom) 63)
+#define XA_FAMILY_NAME ((Atom) 64)
+#define XA_FULL_NAME ((Atom) 65)
+#define XA_CAP_HEIGHT ((Atom) 66)
+#define XA_WM_CLASS ((Atom) 67)
+#define XA_WM_TRANSIENT_FOR ((Atom) 68)
+
+#define XA_LAST_PREDEFINED ((Atom) 68)
+#endif /* XATOM_H */
diff --git a/Xserver/include/Xfuncproto.h b/Xserver/include/Xfuncproto.h
new file mode 100644 (file)
index 0000000..594d341
--- /dev/null
@@ -0,0 +1,88 @@
+/* $XConsortium: Xfuncproto.h,v 1.9 95/06/08 23:20:39 gildea Exp $ */
+/* 
+ * 
+Copyright (c) 1989, 1991  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+ *
+ */
+
+/* Definitions to make function prototypes manageable */
+
+#ifndef _XFUNCPROTO_H_
+#define _XFUNCPROTO_H_
+
+#ifndef NeedFunctionPrototypes
+#if defined(FUNCPROTO) || defined(__STDC__) || defined(__cplusplus) || defined(c_plusplus)
+#define NeedFunctionPrototypes 1
+#else
+#define NeedFunctionPrototypes 0
+#endif
+#endif /* NeedFunctionPrototypes */
+
+#ifndef NeedVarargsPrototypes
+#if defined(__STDC__) || defined(__cplusplus) || defined(c_plusplus) || (FUNCPROTO&2)
+#define NeedVarargsPrototypes 1
+#else
+#define NeedVarargsPrototypes 0
+#endif
+#endif /* NeedVarargsPrototypes */
+
+#if NeedFunctionPrototypes
+
+#ifndef NeedNestedPrototypes
+#if defined(__STDC__) || defined(__cplusplus) || defined(c_plusplus) || (FUNCPROTO&8)
+#define NeedNestedPrototypes 1
+#else
+#define NeedNestedPrototypes 0
+#endif
+#endif /* NeedNestedPrototypes */
+
+#ifndef _Xconst
+#if defined(__STDC__) || defined(__cplusplus) || defined(c_plusplus) || (FUNCPROTO&4)
+#define _Xconst const
+#else
+#define _Xconst
+#endif
+#endif /* _Xconst */
+
+#ifndef NeedWidePrototypes
+#ifdef NARROWPROTO
+#define NeedWidePrototypes 0
+#else
+#define NeedWidePrototypes 1           /* default to make interropt. easier */
+#endif
+#endif /* NeedWidePrototypes */
+
+#endif /* NeedFunctionPrototypes */
+
+#ifndef _XFUNCPROTOBEGIN
+#ifdef __cplusplus                     /* for C++ V2.0 */
+#define _XFUNCPROTOBEGIN extern "C" {  /* do not leave open across includes */
+#define _XFUNCPROTOEND }
+#else
+#define _XFUNCPROTOBEGIN
+#define _XFUNCPROTOEND
+#endif
+#endif /* _XFUNCPROTOBEGIN */
+
+#endif /* _XFUNCPROTO_H_ */
diff --git a/Xserver/include/Xfuncs.h b/Xserver/include/Xfuncs.h
new file mode 100644 (file)
index 0000000..ab8d3c1
--- /dev/null
@@ -0,0 +1,98 @@
+/*
+ * $XConsortium: Xfuncs.h,v 1.16 94/12/01 16:25:53 kaleb Exp $
+ * $XFree86: xc/include/Xfuncs.h,v 3.2 1995/01/28 15:42:03 dawes Exp $
+ * 
+ * 
+Copyright (c) 1990  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+ *
+ */
+
+#ifndef _XFUNCS_H_
+#define _XFUNCS_H_
+
+#include <X11/Xosdefs.h>
+
+/* the old Xfuncs.h, for pre-R6 */
+
+#ifdef X_USEBFUNCS
+void bcopy();
+void bzero();
+int bcmp();
+#else
+#if (__STDC__ && !defined(X_NOT_STDC_ENV) && !defined(sun) && !defined(macII) && !defined(apollo)) || defined(SVR4) || defined(hpux) || defined(_IBMR2) || defined(_SEQUENT_) || defined(__osf__)
+#include <string.h>
+#define _XFUNCS_H_INCLUDED_STRING_H
+#define bcopy(b1,b2,len) memmove(b2, b1, (size_t)(len))
+#define bzero(b,len) memset(b, 0, (size_t)(len))
+#define bcmp(b1,b2,len) memcmp(b1, b2, (size_t)(len))
+#else
+#ifdef sgi
+#include <bstring.h>
+#else
+#ifdef SYSV
+#include <memory.h>
+void bcopy();
+#define bzero(b,len) memset(b, 0, len)
+#define bcmp(b1,b2,len) memcmp(b1, b2, len)
+#else
+#ifdef __EMX__
+#include <strings.h>
+#define _XFUNCS_H_INCLUDED_STRING_H
+/* bcopy, bcmp, bzero declared */
+#else /* bsd */
+void bcopy();
+void bzero();
+int bcmp();
+#endif
+#endif /* SYSV */
+#endif /* sgi */
+#endif /* __STDC__ and relatives */
+#endif /* X_USEBFUNCS */
+
+/* the new Xfuncs.h */
+
+#if !defined(X_NOT_STDC_ENV) && (!defined(sun) || defined(SVR4))
+/* the ANSI C way */
+#ifndef _XFUNCS_H_INCLUDED_STRING_H
+#include <string.h>
+#endif
+#undef bzero
+#define bzero(b,len) memset(b,0,len)
+#else /* else X_NOT_STDC_ENV or SunOS 4 */
+#if defined(SYSV) || defined(luna) || defined(sun) || defined(__sxg__)
+#include <memory.h>
+#define memmove(dst,src,len) bcopy((char *)(src),(char *)(dst),(int)(len))
+#if defined(SYSV) && defined(_XBCOPYFUNC)
+#undef memmove
+#define memmove(dst,src,len) _XBCOPYFUNC((char *)(src),(char *)(dst),(int)(len))
+#define _XNEEDBCOPYFUNC
+#endif
+#else /* else vanilla BSD */
+#define memmove(dst,src,len) bcopy((char *)(src),(char *)(dst),(int)(len))
+#define memcpy(dst,src,len) bcopy((char *)(src),(char *)(dst),(int)(len))
+#define memcmp(b1,b2,len) bcmp((char *)(b1),(char *)(b2),(int)(len))
+#endif /* SYSV else */
+#endif /* ! X_NOT_STDC_ENV else */
+
+#endif /* _XFUNCS_H_ */
diff --git a/Xserver/include/Xmd.h b/Xserver/include/Xmd.h
new file mode 100644 (file)
index 0000000..5d2b85a
--- /dev/null
@@ -0,0 +1,206 @@
+/***********************************************************
+
+Copyright (c) 1987  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+
+Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
+
+                        All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and its 
+documentation for any purpose and without fee is hereby granted, 
+provided that the above copyright notice appear in all copies and that
+both that copyright notice and this permission notice appear in 
+supporting documentation, and that the name of Digital not be
+used in advertising or publicity pertaining to distribution of the
+software without specific, written prior permission.  
+
+DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
+ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
+DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
+ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+SOFTWARE.
+
+******************************************************************/
+#ifndef XMD_H
+#define XMD_H 1
+/* $XConsortium: Xmd.h,v 1.49 95/06/08 23:20:39 gildea Exp $ */
+/* $XFree86: xc/include/Xmd.h,v 3.4 1996/12/31 04:15:20 dawes Exp $ */
+/*
+ *  Xmd.h: MACHINE DEPENDENT DECLARATIONS.
+ */
+
+/*
+ * Special per-machine configuration flags.
+ */
+#ifdef CRAY
+#define WORD64                         /* 64-bit architecture */
+#endif
+#if defined(__alpha) || defined(__alpha__)
+#define LONG64                         /* 32/64-bit architecture */
+#endif
+#ifdef __sgi
+#if (_MIPS_SZLONG == 64)
+#define LONG64
+#endif
+#endif
+
+/*
+ * Stuff to handle large architecture machines; the constants were generated
+ * on a 32-bit machine and must coorespond to the protocol.
+ */
+#ifdef WORD64
+#define MUSTCOPY
+#endif /* WORD64 */
+
+
+/*
+ * Definition of macro used to set constants for size of network structures;
+ * machines with preprocessors that can't handle all of the sz_ symbols
+ * can define this macro to be sizeof(x) if and only if their compiler doesn't
+ * pad out structures (esp. the xTextElt structure which contains only two 
+ * one-byte fields).  Network structures should always define sz_symbols.
+ *
+ * The sz_ prefix is used instead of something more descriptive so that the
+ * symbols are no more than 32 characters long (which causes problems for some
+ * compilers and preprocessors).
+ *
+ * The extra indirection in the __STDC__ case is to get macro arguments to
+ * expand correctly before the concatenation, rather than afterward.
+ */
+#if ((defined(__STDC__) || defined(__cplusplus) || defined(c_plusplus)) && !defined(UNIXCPP)) || defined(ANSICPP)
+#define _SIZEOF(x) sz_##x
+#define SIZEOF(x) _SIZEOF(x)
+#else
+#define SIZEOF(x) sz_/**/x
+#endif /* if ANSI C compiler else not */
+
+/*
+ * Bitfield suffixes for the protocol structure elements, if you
+ * need them.  Note that bitfields are not guarranteed to be signed
+ * (or even unsigned) according to ANSI C.
+ */
+#ifdef WORD64
+typedef long INT64;
+typedef unsigned long CARD64;
+#define B32 :32
+#define B16 :16
+#ifdef UNSIGNEDBITFIELDS
+typedef unsigned int INT32;
+typedef unsigned int INT16;
+#else
+#ifdef __STDC__
+typedef signed int INT32;
+typedef signed int INT16;
+#else
+typedef int INT32;
+typedef int INT16;
+#endif
+#endif
+#else
+#define B32
+#define B16
+#ifdef LONG64
+typedef long INT64;
+typedef int INT32;
+#else
+typedef long INT32;
+#endif
+typedef short INT16;
+#endif
+
+#if defined(__STDC__) || defined(sgi) || defined(AIXV3)
+typedef signed char    INT8;
+#else
+typedef char           INT8;
+#endif
+
+#ifdef LONG64
+typedef unsigned long CARD64;
+typedef unsigned int CARD32;
+#else
+typedef unsigned long CARD32;
+#endif
+typedef unsigned short CARD16;
+typedef unsigned char  CARD8;
+
+typedef CARD32         BITS32;
+typedef CARD16         BITS16;
+
+#ifndef __EMX__
+typedef CARD8          BYTE;
+typedef CARD8           BOOL;
+#else
+/*
+ * This is bad style, but the central include file <os2.h> declares them
+ * as well
+ */
+#define BYTE           CARD8
+#define BOOL           CARD8
+#endif
+
+
+/*
+ * definitions for sign-extending bitfields on 64-bit architectures
+ */
+#if defined(WORD64) && defined(UNSIGNEDBITFIELDS)
+#define cvtINT8toInt(val)   (((val) & 0x00000080) ? ((val) | 0xffffffffffffff00) : (val))
+#define cvtINT16toInt(val)  (((val) & 0x00008000) ? ((val) | 0xffffffffffff0000) : (val))
+#define cvtINT32toInt(val)  (((val) & 0x80000000) ? ((val) | 0xffffffff00000000) : (val))
+#define cvtINT8toShort(val)  cvtINT8toInt(val)
+#define cvtINT16toShort(val) cvtINT16toInt(val)
+#define cvtINT32toShort(val) cvtINT32toInt(val)
+#define cvtINT8toLong(val)  cvtINT8toInt(val)
+#define cvtINT16toLong(val) cvtINT16toInt(val)
+#define cvtINT32toLong(val) cvtINT32toInt(val)
+#else
+#define cvtINT8toInt(val) (val)
+#define cvtINT16toInt(val) (val)
+#define cvtINT32toInt(val) (val)
+#define cvtINT8toShort(val) (val)
+#define cvtINT16toShort(val) (val)
+#define cvtINT32toShort(val) (val)
+#define cvtINT8toLong(val) (val)
+#define cvtINT16toLong(val) (val)
+#define cvtINT32toLong(val) (val)
+#endif /* WORD64 and UNSIGNEDBITFIELDS */
+
+
+
+#ifdef MUSTCOPY
+/*
+ * This macro must not cast or else pointers will get aligned and be wrong
+ */
+#define NEXTPTR(p,t)  (((char *) p) + SIZEOF(t))
+#else /* else not MUSTCOPY, this is used for 32-bit machines */
+/*
+ * this version should leave result of type (t *), but that should only be 
+ * used when not in MUSTCOPY
+ */  
+#define NEXTPTR(p,t) (((t *)(p)) + 1)
+#endif /* MUSTCOPY - used machines whose C structs don't line up with proto */
+
+#endif /* XMD_H */
diff --git a/Xserver/include/Xos.h b/Xserver/include/Xos.h
new file mode 100644 (file)
index 0000000..f2f0084
--- /dev/null
@@ -0,0 +1,317 @@
+/*
+ * $XConsortium: Xos.h /main/70 1996/11/15 16:00:41 kaleb $
+ * $XFree86: xc/include/Xos.h,v 3.21.2.1 1998/01/23 12:35:11 dawes Exp $
+ * 
+ * 
+Copyright (c) 1987  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+ *
+ * The X Window System is a Trademark of X Consortium.
+ *
+ */
+
+/* This is a collection of things to try and minimize system dependencies
+ * in a "signficant" number of source files.
+ */
+
+#ifndef _XOS_H_
+#define _XOS_H_
+
+#include <X11/Xosdefs.h>
+
+/*
+ * Get major data types (esp. caddr_t)
+ */
+
+#ifdef USG
+#ifndef __TYPES__
+#ifdef CRAY
+#define word word_t
+#endif /* CRAY */
+#include <sys/types.h>                 /* forgot to protect it... */
+#define __TYPES__
+#endif /* __TYPES__ */
+#else /* USG */
+#if defined(_POSIX_SOURCE) && (defined(MOTOROLA) || defined(AMOEBA))
+#undef _POSIX_SOURCE
+#include <sys/types.h>
+#define _POSIX_SOURCE
+#else
+#include <sys/types.h>
+#endif
+#endif /* USG */
+
+
+/*
+ * Just about everyone needs the strings routines.  We provide both forms here,
+ * index/rindex and strchr/strrchr, so any systems that don't provide them all
+ * need to have #defines here.
+ *
+ * NOTE: The following ISN'T true for this XFree86 version of this file.
+ *
+ * These macros are defined this way, rather than, e.g.:
+ *    #defined index(s,c) strchr(s,c)
+ * because someone might be using them as function pointers, and such
+ * a change would break compatibility for anyone who's relying on them
+ * being the way they currently are. So we're stuck with them this way,
+ * which can be really inconvenient. :-(
+ */
+
+#ifndef X_NOT_STDC_ENV
+
+#include <string.h>
+#ifdef __STDC__
+#ifndef index
+#define index(s,c) (strchr((s),(c)))
+#endif
+#ifndef rindex
+#define rindex(s,c) (strrchr((s),(c)))
+#endif
+#else
+#ifndef index
+#define index strchr
+#endif
+#ifndef rindex
+#define rindex strrchr
+#endif
+#endif
+
+#else
+
+#ifdef SYSV
+#if defined(clipper) || defined(__clipper__)
+#include <malloc.h>
+#endif
+#include <string.h>
+#define index strchr
+#define rindex strrchr
+#else
+#include <strings.h>
+#define strchr index
+#define strrchr rindex
+#endif
+
+#endif /* X_NOT_STDC_ENV */
+
+/*
+ * strerror()
+ */
+#if (defined(X_NOT_STDC_ENV) || (defined(sun) && !defined(SVR4)) || defined(macII)) && !defined(__GLIBC__)
+#ifndef strerror
+extern char *sys_errlist[];
+extern int sys_nerr;
+#define strerror(n) \
+    (((n) >= 0 && (n) < sys_nerr) ? sys_errlist[n] : "unknown error")
+#endif
+#endif
+
+/*
+ * Get open(2) constants
+ */
+#ifdef X_NOT_POSIX
+#include <fcntl.h>
+#if defined(USL) || defined(CRAY) || defined(MOTOROLA) || (defined(i386) && (defined(SYSV) || defined(SVR4))) || defined(__sxg__)
+#include <unistd.h>
+#endif
+#ifdef WIN32
+#include <X11/Xw32defs.h>
+#else
+#include <sys/file.h>
+#endif
+#else /* X_NOT_POSIX */
+#if !defined(_POSIX_SOURCE) && defined(macII)
+#define _POSIX_SOURCE
+#include <fcntl.h>
+#include <unistd.h>
+#undef _POSIX_SOURCE
+#else
+#include <fcntl.h>
+#include <unistd.h>
+#endif
+#endif /* X_NOT_POSIX else */
+
+#ifdef CSRG_BASED
+#include <stdlib.h>
+#include <unistd.h>
+#endif /* CSRG_BASED */
+
+/*
+ * Get struct timeval
+ */
+
+#ifdef SYSV
+
+#ifndef USL
+#include <sys/time.h>
+#endif
+#include <time.h>
+#ifdef CRAY
+#undef word
+#endif /* CRAY */
+#if defined(USG) && !defined(CRAY) && !defined(MOTOROLA) && !defined(uniosu) && !defined(__sxg__) && !defined(clipper) && !defined(__clipper__)
+struct timeval {
+    long tv_sec;
+    long tv_usec;
+};
+#ifndef USL_SHARELIB
+struct timezone {
+    int tz_minuteswest;
+    int tz_dsttime;
+};
+#endif /* USL_SHARELIB */
+#endif /* USG */
+
+#ifdef _SEQUENT_
+struct timezone {
+    int tz_minuteswest;
+    int tz_dsttime;
+};
+#endif /* _SEQUENT_ */
+
+#else /* not SYSV */
+
+#if defined(_ANSI_SOURCE) && defined(__bsdi__)
+#undef _ANSI_SOURCE
+#include <sys/time.h>
+#define _ANSI_SOURCE
+#endif
+
+#if defined(_POSIX_SOURCE) && defined(SVR4)
+/* need to omit _POSIX_SOURCE in order to get what we want in SVR4 */
+#undef _POSIX_SOURCE
+#include <sys/time.h>
+#define _POSIX_SOURCE
+#else /* defined(_POSIX_SOURCE) && defined(SVR4) */
+#ifdef WIN32
+#include <time.h>
+#if !defined(_WINSOCKAPI_) && !defined(_WILLWINSOCK_)
+struct timeval {
+    long    tv_sec;         /* seconds */
+    long    tv_usec;        /* and microseconds */
+};
+#endif
+#include <sys/timeb.h>
+#define gettimeofday(t) \
+{ \
+    struct _timeb _gtodtmp; \
+    _ftime (&_gtodtmp); \
+    (t)->tv_sec = _gtodtmp.time; \
+    (t)->tv_usec = _gtodtmp.millitm * 1000; \
+}
+#else /* WIN32 */
+#ifdef _SEQUENT_
+#include <time.h>
+#else /* _SEQUENT_ */
+#ifdef AMOEBA
+#include <time.h>
+#include <sys/time.h>
+#else /* AMOEBA */
+#ifdef MINIX
+#include <time.h>
+#else /* !MINIX */
+#ifndef Lynx
+#include <sys/time.h>
+#else
+#include <time.h>
+#endif /* Lynx */
+#endif /* MINIX */
+#endif /* AMOEBA */
+#endif /* _SEQUENT_ */
+#endif /* WIN32 else */
+#endif /* defined(_POSIX_SOURCE) && defined(SVR4) */
+
+#endif /* SYSV */
+
+/* define X_GETTIMEOFDAY macro, a portable gettimeofday() */
+#if defined(_XOPEN_XPG4) || defined(_XOPEN_UNIX) /* _XOPEN_UNIX is XPG4.2 */
+#define X_GETTIMEOFDAY(t) gettimeofday(t, (struct timezone*)0)
+#else
+#if defined(SVR4) || defined(VMS) || defined(WIN32)
+#define X_GETTIMEOFDAY(t) gettimeofday(t)
+#else
+#define X_GETTIMEOFDAY(t) gettimeofday(t, (struct timezone*)0)
+#endif
+#endif /* XPG4 else */
+
+#ifdef MINIX
+#include <errno.h>
+#include <net/gen/in.h>
+#include <net/gen/socket.h>
+#include <net/gen/udp.h>
+#include <net/gen/udp_hdr.h>
+
+struct sockaddr
+{
+       u16_t sa_family;
+       char sa_data[14];
+};
+
+struct sockaddr_in
+{
+       u16_t sin_family;
+       u16_t sin_port;
+       struct
+       {
+               ipaddr_t s_addr;
+       } sin_addr;
+       char sin_zero[8];
+};
+
+struct in_addr
+{
+       ipaddr_t s_addr;
+};
+
+typedef char *caddr_t;
+typedef unsigned char u_char;
+#endif /* MINIX */
+
+#ifdef __EMX__
+typedef unsigned long fd_mask;
+#endif
+
+/* use POSIX name for signal */
+#if defined(X_NOT_POSIX) && defined(SYSV) && !defined(SIGCHLD) && !defined(ISC)
+#define SIGCHLD SIGCLD
+#endif
+
+#ifdef ISC
+#include <sys/bsdtypes.h>
+#include <sys/limits.h>
+#define NGROUPS 16
+#endif
+
+#if defined(ISC) || defined(__EMX__)
+/*
+ *     Some OS's may not have this
+ */
+
+#define X_NO_SYS_UN 1
+
+struct sockaddr_un {
+       short   sun_family;
+       char    sun_path[108];
+};
+#endif
+
+#endif /* _XOS_H_ */
diff --git a/Xserver/include/Xos_r.h b/Xserver/include/Xos_r.h
new file mode 100644 (file)
index 0000000..dd039ab
--- /dev/null
@@ -0,0 +1,1105 @@
+/* $XConsortium: Xos_r.h /main/5 1996/12/18 16:29:14 lehors $ */
+/* 
+Copyright (c) 1996  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+*/
+/* $XFree86: xc/include/Xos_r.h,v 1.3 1997/01/18 07:17:11 dawes Exp $ */
+
+/* 
+ * Various and sundry Thread-Safe functions used by X11, Motif, and CDE.
+ *
+ * Use this file in MT-safe code where you would have included
+ *     <dirent.h>      for readdir()
+ *     <grp.h>         for getgrgid() or getgrnam()
+ *     <netdb.h>       for gethostbyname(), gethostbyaddr(), or getservbyname()
+ *     <pwd.h>         for getpwnam() or getpwuid()
+ *     <string.h>      for strtok()
+ *     <time.h>        for asctime(), ctime(), localtime(), or gmtime()
+ *     <unistd.h>      for getlogin() or ttyname()
+ * or their thread-safe analogs.
+ *
+ * If you are on a platform that defines XTHREADS but does not have
+ * MT-safe system API (e.g. UnixWare) you must define _Xos_processLock
+ * and _Xos_processUnlock macros before including this header.  If
+ * you are on OSF/1 V3.2 and plan to use readdir(), you must also define
+ * _Xos_isThreadsInitialized.  For convenience XOS_USE_XLIB_LOCKING or
+ * XOS_USE_XT_LOCKING may be defined to obtain either Xlib-only or
+ * Xt-based versions of these macros.  These macros won't result in
+ * truly thread-safe calls, but they are better than nothing.  If you
+ * do not want locking in this situation define XOS_USE_NO_LOCKING.
+ *
+ * NOTE: On systems lacking approriate _r functions Gethostbyname(),
+ *     Gethostbyaddr(), and Getservbyname() do NOT copy the host or
+ *     protocol lists!
+ *
+ * NOTE: On systems lacking appropriate _r functions Getgrgid() and
+ *     Getgrnam() do NOT copy the list of group members!
+ *
+ * This header is nominally intended to simplify porting X11, Motif, and 
+ * CDE; it may be useful to other people too.  The structure below is
+ * complicated, mostly because P1003.1c (the IEEE POSIX Threads spec)
+ * went through lots of drafts, and some vendors shipped systems based
+ * on draft API that were changed later.  Unfortunately POSIX did not
+ * provide a feature-test macro for distinguishing each of the drafts.
+ */
+
+/*
+ * This header has several parts.  Search for "Effective prototypes"
+ * to locate the beginning of a section.
+ */
+
+/* This header can be included multiple times with different defines! */
+#ifndef _XOS_R_H_
+# define _XOS_R_H_
+
+# include <X11/Xos.h>
+# include <X11/Xfuncs.h>
+
+# ifndef X_NOT_POSIX
+#  ifdef _POSIX_SOURCE
+#   include <limits.h>
+#  else
+#   define _POSIX_SOURCE
+#   include <limits.h>
+#   undef _POSIX_SOURCE
+#  endif
+# endif
+#endif /* _XOS_R_H */
+
+#ifndef WIN32
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+# if defined(XOS_USE_XLIB_LOCKING)
+#  ifndef XAllocIDs /* Xlibint.h does not have multiple include protection */
+typedef struct _LockInfoRec *LockInfoPtr;
+extern LockInfoPtr _Xglobal_lock;
+#  endif
+#  ifndef _Xos_isThreadInitialized
+#   define _Xos_isThreadInitialized    (_Xglobal_lock)
+#  endif
+#  if defined(XTHREADS_WARN) || defined(XTHREADS_FILE_LINE)
+#   ifndef XAllocIDs /* Xlibint.h does not have multiple include protection */
+#    include <X11/Xfuncproto.h>        /* for NeedFunctionPrototypes */
+extern void (*_XLockMutex_fn)(
+#    if NeedFunctionPrototypes
+    LockInfoPtr        /* lock */, char * /* file */, int /* line */
+#    endif
+);
+extern void (*_XUnlockMutex_fn)(
+#    if NeedFunctionPrototypes
+    LockInfoPtr        /* lock */, char * /* file */, int /* line */
+#    endif
+);
+#   endif
+#   ifndef _Xos_processLock
+#    define _Xos_processLock   \
+  (_XLockMutex_fn ? (*_XLockMutex_fn)(_Xglobal_lock,__FILE__,__LINE__) : 0)
+#   endif
+#   ifndef _Xos_processUnlock
+#    define _Xos_processUnlock \
+  (_XUnlockMutex_fn ? (*_XUnlockMutex_fn)(_Xglobal_lock,__FILE__,__LINE__) : 0)
+#   endif
+#  else
+#   ifndef XAllocIDs /* Xlibint.h does not have multiple include protection */
+#    include <X11/Xfuncproto.h>        /* for NeedFunctionPrototypes */
+extern void (*_XLockMutex_fn)(
+#    if NeedFunctionPrototypes
+    LockInfoPtr        /* lock */
+#    endif
+);
+extern void (*_XUnlockMutex_fn)(
+#    if NeedFunctionPrototypes
+    LockInfoPtr        /* lock */
+#    endif
+);
+#   endif
+#   ifndef _Xos_processLock
+#    define _Xos_processLock   \
+  (_XLockMutex_fn ? ((*_XLockMutex_fn)(_Xglobal_lock), 0) : 0)
+#   endif
+#   ifndef _Xos_processUnlock
+#    define _Xos_processUnlock \
+  (_XUnlockMutex_fn ? ((*_XUnlockMutex_fn)(_Xglobal_lock), 0) : 0)
+#   endif
+#  endif
+# elif defined(XOS_USE_XT_LOCKING)
+extern void (*_XtProcessLock)();
+#  ifndef _XtintrinsicP_h
+#   include <X11/Xfuncproto.h> /* for NeedFunctionPrototypes */
+extern void XtProcessLock(
+#   if NeedFunctionPrototypes
+    void
+#   endif
+);
+extern void XtProcessUnlock(
+#   if NeedFunctionPrototypes
+    void
+#   endif
+);
+#  endif
+#  ifndef _Xos_isThreadInitialized
+#   define _Xos_isThreadInitialized    _XtProcessLock
+#  endif
+#  ifndef _Xos_processLock
+#   define _Xos_processLock            XtProcessLock()
+#  endif
+#  ifndef _Xos_processUnlock
+#   define _Xos_processUnlock          XtProcessUnlock()
+#  endif
+# elif defined(XOS_USE_NO_LOCKING)
+#  ifndef _Xos_isThreadInitialized
+#   define _Xos_isThreadInitialized    0
+#  endif
+#  ifndef _Xos_processLock
+#   define _Xos_processLock            0
+#  endif
+#  ifndef _Xos_processUnlock
+#   define _Xos_processUnlock          0
+#  endif
+# endif
+
+#endif /* !defined WIN32 */
+
+/* 
+ * Solaris 2.5 has SVR4 thread-safe API, but defines the POSIX
+ * thread-safe feature test macro.  Fix the feature test macro.
+ */
+#if defined(sun) && defined(_POSIX_THREAD_SAFE_FUNCTIONS)
+# undef _POSIX_THREAD_SAFE_FUNCTIONS
+#endif
+
+
+/***** <pwd.h> wrappers *****/
+
+/*
+ * Effective prototypes for <pwd.h> wrappers:
+ *
+ * #define X_INCLUDE_PWD_H
+ * #define XOS_USE_..._LOCKING
+ * #include <X11/Xos_r.h>
+ *
+ * typedef ... _Xgetpwparams;
+ *
+ * struct passwd* _XGetpwnam(const char *name, _Xgetpwparams);
+ * struct passwd* _XGetpwuid(uid_t uid, _Xgetpwparams);
+ */
+
+#if defined(X_INCLUDE_PWD_H) && !defined(_XOS_INCLUDED_PWD_H)
+# include <pwd.h>
+# if defined(XUSE_MTSAFE_API) || defined(XUSE_MTSAFE_PWDAPI)
+#  define XOS_USE_MTSAFE_PWDAPI 1
+# endif
+#endif
+
+#if !defined(X_INCLUDE_PWD_H) || defined(_XOS_INCLUDED_PWD_H)
+/* Do nothing */
+
+#elif !defined(XTHREADS) && !defined(X_FORCE_USE_MTSAFE_API)
+/* Use regular, unsafe API. */
+# if defined(X_NOT_POSIX) && !defined(i386) && !defined(SYSV)
+extern struct passwd *getpwuid(), *getpwnam();
+# endif
+typedef int _Xgetpwparams;     /* dummy */
+# define _XGetpwuid(u,p)       getpwuid((u))
+# define _XGetpwnam(u,p)       getpwnam((u))
+
+#elif !defined(XOS_USE_MTSAFE_PWDAPI) || defined(XNO_MTSAFE_PWDAPI)
+/* UnixWare 2.0, or other systems with thread support but no _r API. */
+typedef struct {
+  struct passwd pws;
+  char   pwbuf[1024];
+  struct passwd* pwp;
+  size_t len;
+} _Xgetpwparams;
+# define _Xpw_copyPasswd(p) \
+   (memcpy(&(p).pws, (p).pwp, sizeof(struct passwd)), \
+    ((p).pws.pw_name = (p).pwbuf), \
+    ((p).len = strlen((p).pwp->pw_name)), \
+    strcpy((p).pws.pw_name, (p).pwp->pw_name), \
+    ((p).pws.pw_passwd = (p).pws.pw_name + (p).len + 1), \
+    ((p).len = strlen((p).pwp->pw_passwd)), \
+    strcpy((p).pws.pw_passwd,(p).pwp->pw_passwd), \
+    ((p).pws.pw_age = (p).pws.pw_passwd + (p).len + 1), \
+    ((p).len = strlen((p).pwp->pw_age)), \
+    strcpy((p).pws.pw_age, (p).pwp->pw_age), \
+    ((p).pws.pw_comment = (p).pws.pw_age + (p).len + 1), \
+    ((p).len = strlen((p).pwp->pw_comment)), \
+    strcpy((p).pws.pw_comment, (p).pwp->pw_comment), \
+    ((p).pws.pw_gecos = (p).pws.pw_comment + (p).len + 1), \
+    ((p).len = strlen((p).pwp->pw_gecos)), \
+    strcpy((p).pws.pw_gecos, (p).pwp->pw_gecos), \
+    ((p).pws.pw_dir = (p).pws.pw_comment + (p).len + 1), \
+    ((p).len = strlen((p).pwp->pw_dir)), \
+    strcpy((p).pws.pw_dir, (p).pwp->pw_dir), \
+    ((p).pws.pw_shell = (p).pws.pw_dir + (p).len + 1), \
+    ((p).len = strlen((p).pwp->pw_shell)), \
+    strcpy((p).pws.pw_shell, (p).pwp->pw_shell), \
+    ((p).pwp = &(p).pws), \
+    0 )
+# define _XGetpwuid(u,p) \
+( (_Xos_processLock), \
+  (((p).pwp = getpwuid((u))) ? _Xpw_copyPasswd(p) : 0), \
+  (_Xos_processUnlock), \
+  (p).pwp )
+# define _XGetpwnam(u,p) \
+( (_Xos_processLock), \
+  (((p).pwp = getpwnam((u))) ? _Xpw_copyPasswd(p) : 0), \
+  (_Xos_processUnlock), \
+  (p).pwp )
+
+#elif !defined(_POSIX_THREAD_SAFE_FUNCTIONS)
+/* SVR4 threads, AIX 4.2.0 and earlier and OSF/1 3.2 and earlier pthreads */
+# if defined(Lynx) && !defined(LINE_MAX)
+#  define LINE_MAX     2048            /* what Xthreads.h does */
+# endif
+typedef struct {
+  struct passwd pws;
+  char pwbuf[LINE_MAX];
+} _Xgetpwparams;
+# if defined(_POSIX_REENTRANT_FUNCTIONS) || !defined(SVR4) || defined(Lynx)
+#  ifndef Lynx
+#   define _XGetpwuid(u,p) \
+((getpwuid_r((u),&(p).pws,(p).pwbuf,sizeof((p).pwbuf)) == -1) ? NULL : &(p).pws)
+#   define _XGetpwnam(u,p) \
+((getpwnam_r((u),&(p).pws,(p).pwbuf,sizeof((p).pwbuf)) == -1) ? NULL : &(p).pws)
+#  else /* Lynx */
+#   define _XGetpwuid(u,p) \
+((getpwuid_r(&(p).pws,(u),(p).pwbuf,sizeof((p).pwbuf)) == -1) ? NULL : &(p).pws)
+#   define _XGetpwnam(u,p) \
+((getpwnam_r(&(p).pws,(u),(p).pwbuf,sizeof((p).pwbuf)) == -1) ? NULL : &(p).pws)
+#  endif
+# else /* SVR4 */
+#  define _XGetpwuid(u,p) \
+((getpwuid_r((u),&(p).pws,(p).pwbuf,sizeof((p).pwbuf)) == NULL) ? NULL : &(p).pws)
+#  define _XGetpwnam(u,p) \
+((getpwnam_r((u),&(p).pws,(p).pwbuf,sizeof((p).pwbuf)) == NULL) ? NULL : &(p).pws)
+# endif /* SVR4 */
+
+#else /* _POSIX_THREAD_SAFE_FUNCTIONS */
+/* Digital UNIX 4.0, but not (beta) T4.0-1 */
+# if defined(__osf__)
+/* OSF/1 V4.0 <pwd.h> doesn't declare the _P routines, breaking under C++. */
+extern int _Pgetpwuid_r(uid_t, struct passwd *, char *, size_t, struct passwd **);
+extern int _Pgetpwnam_r(const char *, struct passwd *, char *, size_t, struct passwd **);
+# endif
+typedef struct {
+  struct passwd pws;
+  char pwbuf[LINE_MAX];
+  struct passwd* pwp;
+} _Xgetpwparams;
+typedef int _Xgetpwret;
+# define _XGetpwuid(u,p) \
+((getpwuid_r((u),&(p).pws,(p).pwbuf,sizeof((p).pwbuf),&(p).pwp) == -1) ? \
+ NULL : (p).pwp)
+# define _XGetpwnam(u,p) \
+((getpwnam_r((u),&(p).pws,(p).pwbuf,sizeof((p).pwbuf),&(p).pwp) == -1) ? \
+ NULL : (p).pwp)
+#endif /* X_INCLUDE_PWD_H */
+
+#if defined(X_INCLUDE_PWD_H) && !defined(_XOS_INCLUDED_PWD_H)
+# define _XOS_INCLUDED_PWD_H
+#endif
+
+
+/***** <netdb.h> wrappers *****/
+
+/* 
+ * Effective prototypes for <netdb.h> wrappers:
+ *
+ * NOTE: On systems lacking the appropriate _r functions Gethostbyname(),
+ *     Gethostbyaddr(), and Getservbyname() do NOT copy the host or
+ *     protocol lists!
+ *
+ * #define X_INCLUDE_NETDB_H
+ * #define XOS_USE_..._LOCKING
+ * #include <X11/Xos_r.h>
+ *
+ * typedef ... _Xgethostbynameparams;
+ * typedef ... _Xgetservbynameparams;
+ *
+ * struct hostent* _XGethostbyname(const char* name,_Xgethostbynameparams);
+ * struct hostent* _XGethostbyaddr(const char* addr, int len, int type, 
+ *                                _Xgethostbynameparams);
+ * struct servent* _XGetservbyname(const char* name, const char* proto,
+ *                              _Xgetservbynameparams);
+ */
+
+#if defined(X_INCLUDE_NETDB_H) && !defined(_XOS_INCLUDED_NETDB_H) \
+    && !defined(WIN32)
+# include <netdb.h>
+# if defined(XUSE_MTSAFE_API) || defined(XUSE_MTSAFE_NETDBAPI)
+#  define XOS_USE_MTSAFE_NETDBAPI 1
+# endif
+#endif
+
+#if !defined(X_INCLUDE_NETDB_H) || defined(_XOS_INCLUDED_NETDB_H)
+/* Do nothing. */
+
+#elif !defined(XTHREADS) && !defined(X_FORCE_USE_MTSAFE_API)
+/* Use regular, unsafe API. */
+typedef int _Xgethostbynameparams; /* dummy */
+typedef int _Xgetservbynameparams; /* dummy */
+# define _XGethostbyname(h,hp)         gethostbyname((h))
+# define _XGethostbyaddr(a,al,t,hp)    gethostbyaddr((a),(al),(t))
+# define _XGetservbyname(s,p,sp)       getservbyname((s),(p))
+
+#elif !defined(XOS_USE_MTSAFE_NETDBAPI) || defined(XNO_MTSAFE_NETDBAPI)
+/* UnixWare 2.0, or other systems with thread support but no _r API. */
+/* WARNING:  The h_addr_list and s_aliases values are *not* copied! */
+
+typedef struct {
+  struct hostent hent;
+  char           h_name[MAXHOSTNAMELEN];
+  struct hostent *hptr;
+} _Xgethostbynameparams;
+typedef struct {
+  struct servent sent;
+  char           s_name[255];
+  char          s_proto[255];
+  struct servent *sptr;
+} _Xgetservbynameparams;
+# define _Xg_copyHostent(hp) \
+   (memcpy(&(hp).hent, (hp).hptr, sizeof(struct hostent)), \
+    strcpy((hp).h_name, (hp).hptr->h_name), \
+    ((hp).hent.h_name = (hp).h_name), \
+    ((hp).hptr = &(hp).hent), \
+     0 )
+# define _Xg_copyServent(sp) \
+   (memcpy(&(sp).sent, (sp).sptr, sizeof(struct servent)), \
+    strcpy((sp).s_name, (sp).sptr->s_name), \
+    ((sp).sent.s_name = (sp).s_name), \
+    strcpy((sp).s_proto, (sp).sptr->s_proto), \
+    ((sp).sent.s_proto = (sp).s_proto), \
+    ((sp).sptr = &(sp).sent), \
+    0 )
+# define _XGethostbyname(h,hp) \
+   ((_Xos_processLock), \
+    (((hp).hptr = gethostbyname((h))) ? _Xg_copyHostent(hp) : 0), \
+    (_Xos_processUnlock), \
+    (hp).hptr )
+# define _XGethostbyaddr(a,al,t,hp) \
+   ((_Xos_processLock), \
+    (((hp).hptr = gethostbyaddr((a),(al),(t))) ? _Xg_copyHostent(hp) : 0), \
+    (_Xos_processUnlock), \
+    (hp).hptr )
+# define _XGetservbyname(s,p,sp) \
+   ((_Xos_processLock), \
+    (((sp).sptr = getservbyname((s),(p))) ? _Xg_copyServent(sp) : 0), \
+    (_Xos_processUnlock), \
+    (sp).sptr )
+
+#elif defined(XUSE_NETDB_R_API)
+/*
+ * POSIX does not specify _r equivalents for <netdb.h> API, but some
+ * vendors provide them anyway.  Use them only when explicitly asked.
+ */
+# ifdef _POSIX_REENTRANT_FUNCTIONS
+#  ifndef _POSIX_THREAD_SAFE_FUNCTIONS
+#   if defined(AIXV3) || defined(AIXV4) || defined(__osf__)
+#    define X_POSIX_THREAD_SAFE_FUNCTIONS 1
+#   endif
+#  endif
+# endif
+# ifdef _POSIX_THREAD_SAFE_FUNCTIONS
+#  define X_POSIX_THREAD_SAFE_FUNCTIONS 1
+# endif
+
+# ifndef X_POSIX_THREAD_SAFE_FUNCTIONS
+typedef struct {
+    struct hostent      hent;
+    char                hbuf[LINE_MAX];
+    int                 herr;
+} _Xgethostbynameparams;
+typedef struct {
+    struct servent      sent;
+    char                sbuf[LINE_MAX];
+} _Xgetservbynameparams;
+#  define _XGethostbyname(h,hp) \
+  gethostbyname_r((h),&(hp).hent,(hp).hbuf,sizeof((hp).hbuf),&(hp).herr)
+#  define _XGethostbyaddr(a,al,t,hp) \
+  gethostbyaddr_r((a),(al),(t),&(hp).hent,(hp).hbuf,sizeof((hp).hbuf),&(hp).herr)
+#  define _XGetservbyname(s,p,sp) \
+  getservbyname_r((s),(p),&(sp).sent,(sp).sbuf,sizeof((sp).sbuf))
+# else
+typedef struct {
+  struct hostent      hent;
+  struct hostent_data hdata;
+} _Xgethostbynameparams;
+typedef struct {
+  struct servent      sent;
+  struct servent_data sdata;
+} _Xgetservbynameparams;
+#  define _XGethostbyname(h,hp) \
+  (bzero((char*)&(hp).hdata,sizeof((hp).hdata)),       \
+   ((gethostbyname_r((h),&(hp).hent,&(hp).hdata) == -1) ? NULL : &(hp).hent))
+#  define _XGethostbyaddr(a,al,t,hp) \
+  (bzero((char*)&(hp).hdata,sizeof((hp).hdata)),       \
+   ((gethostbyaddr_r((a),(al),(t),&(hp).hent,&(hp).hdata) == -1) ? NULL : &(hp).hent))
+#  define _XGetservbyname(s,p,sp) \
+  (bzero((char*)&(sp).sdata,sizeof((sp).sdata)),       \
+   ((getservbyname_r((s),(p),&(sp).sent,&(sp).sdata) == -1) ? NULL : &(sp).sent) )
+# endif
+# ifdef X_POSIX_THREAD_SAFE_FUNCTIONS
+#  undef X_POSIX_THREAD_SAFE_FUNCTIONS
+# endif
+
+#else
+/* The regular API is assumed to be MT-safe under POSIX. */
+typedef int _Xgethostbynameparams; /* dummy */
+typedef int _Xgetservbynameparams; /* dummy */
+# define _XGethostbyname(h,hp)         gethostbyname((h))
+# define _XGethostbyaddr(a,al,t,hp)    gethostbyaddr((a),(al),(t))
+# define _XGetservbyname(s,p,sp)       getservbyname((s),(p))
+#endif /* X_INCLUDE_NETDB_H */
+
+#if defined(X_INCLUDE_NETDB_H) && !defined(_XOS_INCLUDED_NETDB_H)
+# define _XOS_INCLUDED_NETDB_H
+#endif
+
+
+/***** <dirent.h> wrappers *****/
+
+/*
+ * Effective prototypes for <dirent.h> wrappers:
+ *
+ * #define X_INCLUDE_DIRENT_H
+ * #define XOS_USE_..._LOCKING
+ * #include <X11/Xos_r.h>
+ * 
+ * typedef ... _Xreaddirparams;
+ *
+ * struct dirent *_XReaddir(DIR *dir_pointer, _Xreaddirparams);
+ */
+
+#if defined(X_INCLUDE_DIRENT_H) && !defined(_XOS_INCLUDED_DIRENT_H)
+# include <sys/types.h>
+# if !defined(X_NOT_POSIX) || defined(SYSV) || defined(USG)
+#  include <dirent.h>
+# else
+#  include <sys/dir.h>
+#  ifndef dirent
+#   define dirent direct
+#  endif
+# endif
+# if defined(XUSE_MTSAFE_API) || defined(XUSE_MTSAFE_DIRENTAPI)
+#  define XOS_USE_MTSAFE_DIRENTAPI 1
+# endif
+#endif
+
+#if !defined(X_INCLUDE_DIRENT_H) || defined(_XOS_INCLUDED_DIRENT_H)
+/* Do nothing. */
+
+#elif !defined(XTHREADS) && !defined(X_FORCE_USE_MTSAFE_API)
+/* Use regular, unsafe API. */
+typedef int _Xreaddirparams;   /* dummy */
+# define _XReaddir(d,p)        readdir(d)
+
+#elif !defined(XOS_USE_MTSAFE_DIRENTAPI) || defined(XNO_MTSAFE_DIRENTAPI)
+/* Systems with thread support but no _r API. */
+typedef struct {
+  struct dirent *result;
+  struct dirent dir_entry;
+# ifdef _POSIX_PATH_MAX
+  char buf[_POSIX_PATH_MAX];
+# elif defined(NAME_MAX)
+  char buf[NAME_MAX];
+# else
+  char buf[255];
+# endif
+} _Xreaddirparams;
+
+# define _XReaddir(d,p)        \
+ ( (_Xos_processLock),                                          \
+   (((p).result = readdir((d))) ?                               \
+    (memcpy(&((p).dir_entry), (p).result, (p).result->d_reclen), \
+     ((p).result = &(p).dir_entry), 0) :                        \
+    0),                                                                 \
+   (_Xos_processUnlock),                                        \
+   (p).result )
+
+#else
+typedef struct {
+  struct dirent *result;
+  struct dirent dir_entry;
+# ifdef _POSIX_PATH_MAX
+  char buf[_POSIX_PATH_MAX];
+# elif defined(NAME_MAX)
+  char buf[NAME_MAX];
+# else
+  char buf[255];
+# endif
+} _Xreaddirparams;
+
+# if defined(AIXV3) || defined(AIXV4) || defined(_POSIX_THREAD_SAFE_FUNCTIONS)
+/* AIX defines the draft POSIX symbol, but uses the final API. */
+/* POSIX final API, returns (int)0 on success. */
+#  if defined(__osf__)
+/* OSF/1 V4.0 <dirent.h> doesn't declare _Preaddir_r, breaking under C++. */
+extern int _Preaddir_r(DIR *, struct dirent *, struct dirent **);
+#  endif
+#  define _XReaddir(d,p)                                               \
+    (readdir_r((d), &((p).dir_entry), &((p).result)) ? NULL : (p).result)
+# elif defined(_POSIX_REENTRANT_FUNCTIONS) && defined(__osf__)
+/*
+ * OSF/1 V3.2 readdir_r() will SEGV if the main program is not
+ * explicitly linked with -lc_r.  The library REQUIREDLIBS don't help.
+ * Assume that if threads have been initialized we're linked properly.
+ */
+#  define _XReaddir(d,p)                                               \
+ ( (_Xos_isThreadInitialized) ?                                                \
+   (readdir_r((d), &((p).dir_entry)) ? NULL : &((p).dir_entry)) :      \
+   ((_Xos_processLock),                                                        \
+    (((p).result = readdir((d))) ?                                     \
+     (memcpy(&((p).dir_entry), (p).result, (p).result->d_reclen),      \
+      ((p).result = &(p).dir_entry), 0) :                              \
+     0),                                                               \
+    (_Xos_processUnlock),                                              \
+    (p).result) )
+# elif defined(_POSIX_REENTRANT_FUNCTIONS)
+/* POSIX draft API, returns (int)0 on success. */
+#  define _XReaddir(d,p)       \
+    (readdir_r((d),&((p).dir_entry)) ? NULL : &((p).dir_entry))
+# elif defined(SVR4)
+/* Pre-POSIX API, returns non-NULL on success. */
+#  define _XReaddir(d,p)       (readdir_r((d), &(p).dir_entry))
+# else
+/* We have no idea what is going on.  Fake it all using process locks. */
+#  define _XReaddir(d,p)       \
+    ( (_Xos_processLock),                                              \
+      (((p).result = readdir((d))) ?                                   \
+       (memcpy(&((p).dir_entry), (p).result, (p).result->d_reclen),    \
+       ((p).result = &(p).dir_entry), 0) :                             \
+       0),                                                             \
+      (_Xos_processUnlock),                                            \
+      (p).result )
+# endif
+#endif /* X_INCLUDE_DIRENT_H */
+
+#if defined(X_INCLUDE_DIRENT_H) && !defined(_XOS_INCLUDED_DIRENT_H)
+# define _XOS_INCLUDED_DIRENT_H
+#endif
+
+
+/***** <unistd.h> wrappers *****/
+
+/*
+ * Effective prototypes for <unistd.h> wrappers:
+ *
+ * #define X_INCLUDE_UNISTD_H
+ * #define XOS_USE_..._LOCKING
+ * #include <X11/Xos_r.h>
+ * 
+ * typedef ... _Xgetloginparams;
+ * typedef ... _Xttynameparams;
+ *
+ * char *_XGetlogin(_Xgetloginparams);
+ * char *_XTtyname(int, _Xttynameparams);
+ */
+
+#if defined(X_INCLUDE_UNISTD_H) && !defined(_XOS_INCLUDED_UNISTD_H)
+/* <unistd.h> already included by <X11/Xos.h> */
+# if defined(XUSE_MTSAFE_API) || defined(XUSE_MTSAFE_UNISTDAPI)
+#  define XOS_USE_MTSAFE_UNISTDAPI 1
+# endif
+#endif
+
+#if !defined(X_INCLUDE_UNISTD_H) || defined(_XOS_INCLUDED_UNISTD_H)
+/* Do nothing. */
+
+#elif !defined(XTHREADS) && !defined(X_FORCE_USE_MTSAFE_API)
+/* Use regular, unsafe API. */
+typedef int _Xgetloginparams;  /* dummy */
+typedef int _Xttynameparams;   /* dummy */
+# define _XGetlogin(p) getlogin()
+# define _XTtyname(f)  ttyname((f))
+
+#elif !defined(XOS_USE_MTSAFE_UNISTDAPI) || defined(XNO_MTSAFE_UNISTDAPI)
+/* Systems with thread support but no _r API. */
+typedef struct {
+  char *result;
+# if defined(MAXLOGNAME)
+  char buf[MAXLOGNAME];
+# elif defined(LOGIN_NAME_MAX)
+  char buf[LOGIN_NAME_MAX];
+# else
+  char buf[64];
+# endif
+} _Xgetloginparams;
+typedef struct {
+  char *result;
+# ifdef TTY_NAME_MAX
+  char buf[TTY_NAME_MAX];
+# elif defined(_POSIX_TTY_NAME_MAX)
+  char buf[_POSIX_TTY_NAME_MAX];
+# elif defined(_POSIX_PATH_MAX)
+  char buf[_POSIX_PATH_MAX];
+# else
+  char buf[256];
+# endif
+} _Xttynameparams;
+
+# define _XGetlogin(p) \
+ ( (_Xos_processLock), \
+   (((p).result = getlogin()) ? \
+    (strncpy((p).buf, (p).result, sizeof((p).buf)), \
+     ((p).buf[sizeof((p).buf)-1] = '\0'), \
+     ((p).result = (p).buf), 0) : 0), \
+   (_Xos_processUnlock), \
+   (p).result )
+#define _XTtyname(f,p) \
+ ( (_Xos_processLock), \
+   (((p).result = ttyname(f)) ? \
+    (strncpy((p).buf, (p).result, sizeof((p).buf)), \
+     ((p).buf[sizeof((p).buf)-1] = '\0'), \
+     ((p).result = (p).buf), 0) : 0), \
+   (_Xos_processUnlock), \
+   (p).result )
+
+#elif defined(_POSIX_THREAD_SAFE_FUNCTIONS) || defined(_POSIX_REENTRANT_FUNCTIONS)
+/* POSIX API.
+ *
+ * extern int getlogin_r(char *, size_t);
+ * extern int ttyname_r(int, char *, size_t);
+ */
+typedef struct {
+# if defined(MAXLOGNAME)
+  char buf[MAXLOGNAME];
+# elif defined(LOGIN_NAME_MAX)
+  char buf[LOGIN_NAME_MAX];
+# else
+  char buf[64];
+# endif
+} _Xgetloginparams;
+typedef struct {
+# ifdef TTY_NAME_MAX
+  char buf[TTY_NAME_MAX];
+# elif defined(_POSIX_TTY_NAME_MAX)
+  char buf[_POSIX_TTY_NAME_MAX];
+# elif defined(_POSIX_PATH_MAX)
+  char buf[_POSIX_PATH_MAX];
+# else
+  char buf[256];
+# endif
+} _Xttynameparams;
+
+# define _XGetlogin(p) (getlogin_r((p).buf, sizeof((p).buf)) ? NULL : (p).buf)
+# define _XTtyname(f,p)        \
+       (ttyname_r((f), (p).buf, sizeof((p).buf)) ? NULL : (p).buf)
+
+#else
+/* Pre-POSIX API.
+ *
+ * extern char *getlogin_r(char *, size_t);
+ * extern char *ttyname_r(int, char *, size_t);
+ */
+typedef struct {
+# if defined(MAXLOGNAME)
+  char buf[MAXLOGNAME];
+# elif defined(LOGIN_NAME_MAX)
+  char buf[LOGIN_NAME_MAX];
+# else
+  char buf[64];
+# endif
+} _Xgetloginparams;
+typedef struct {
+# ifdef TTY_NAME_MAX
+  char buf[TTY_NAME_MAX];
+# elif defined(_POSIX_TTY_NAME_MAX)
+  char buf[_POSIX_TTY_NAME_MAX];
+# elif defined(_POSIX_PATH_MAX)
+  char buf[_POSIX_PATH_MAX];
+# else
+  char buf[256];
+# endif
+} _Xttynameparams;
+
+# define _XGetlogin(p) getlogin_r((p).buf, sizeof((p).buf))
+# define _XTtyname(f,p)        ttyname_r((f), (p).buf, sizeof((p).buf))
+#endif /* X_INCLUDE_UNISTD_H */
+
+#if defined(X_INCLUDE_UNISTD_H) && !defined(_XOS_INCLUDED_UNISTD_H)
+# define _XOS_INCLUDED_UNISTD_H
+#endif
+
+
+/***** <string.h> wrappers *****/
+
+/*
+ * Effective prototypes for <string.h> wrappers:
+ *
+ * #define X_INCLUDE_STRING_H
+ * #define XOS_USE_..._LOCKING
+ * #include <X11/Xos_r.h>
+ *
+ * typedef ... _Xstrtokparams;
+ *
+ * char *_XStrtok(char *, const char*, _Xstrtokparams);
+ */
+
+#if defined(X_INCLUDE_STRING_H) && !defined(_XOS_INCLUDED_STRING_H)
+/* <string.h> has already been included by <X11/Xos.h> */
+# if defined(XUSE_MTSAFE_API) || defined(XUSE_MTSAFE_STRINGAPI)
+#  define XOS_USE_MTSAFE_STRINGAPI 1
+# endif
+#endif
+
+#if !defined(X_INCLUDE_STRING_H) || defined(_XOS_INCLUDED_STRING_H)
+/* Do nothing. */
+
+#elif !defined(XTHREADS) && !defined(X_FORCE_USE_MTSAFE_API)
+/* Use regular, unsafe API. */
+typedef int _Xstrtokparams;    /* dummy */
+# define _XStrtok(s1,s2,p)     strtok((s1),(s2))
+
+#elif !defined(XOS_USE_MTSAFE_STRINGAPI) || defined(XNO_MTSAFE_STRINGAPI)
+/* Systems with thread support but no _r API. */
+typedef char *_Xstrtokparams;
+# define _XStrtok(s1,s2,p) \
+ ( (_Xos_processLock), \
+   ((p) = strtok((s1),(s2))), \
+   (_Xos_processUnlock), \
+   (p) )
+
+#else
+/* POSIX or pre-POSIX API. */
+typedef char * _Xstrtokparams;
+# define _XStrtok(s1,s2,p)     strtok_r((s1),(s2),&(p))
+#endif /* X_INCLUDE_STRING_H */
+
+
+/***** <time.h> wrappers *****/
+
+/*
+ * Effective prototypes for <time.h> wrappers:
+ *
+ * #define X_INCLUDE_TIME_H
+ * #define XOS_USE_..._LOCKING
+ * #include <X11/Xos_r.h>
+ *
+ * typedef ... _Xatimeparams;
+ * typedef ... _Xctimeparams;
+ * typedef ... _Xgtimeparams;
+ * typedef ... _Xltimeparams;
+ *
+ * char *_XAsctime(const struct tm *, _Xatimeparams);
+ * char *_XCtime(const time_t *, _Xctimeparams);
+ * struct tm *_XGmtime(const time_t *, _Xgtimeparams);
+ * struct tm *_XLocaltime(const time_t *, _Xltimeparams);
+ */
+
+#if defined(X_INCLUDE_TIME_H) && !defined(_XOS_INCLUDED_TIME_H)
+# include <time.h>
+# if defined(XUSE_MTSAFE_API) || defined(XUSE_MTSAFE_TIMEAPI)
+#  define XOS_USE_MTSAFE_TIMEAPI 1
+# endif
+#endif
+
+#if !defined(X_INCLUDE_TIME_H) || defined(_XOS_INCLUDED_TIME_H)
+/* Do nothing. */
+
+#elif !defined(XTHREADS) && !defined(X_FORCE_USE_MTSAFE_API)
+/* Use regular, unsafe API. */
+typedef int _Xatimeparams;     /* dummy */
+# define _XAsctime(t,p)                asctime((t))
+typedef int _Xctimeparams;     /* dummy */
+# define _XCtime(t,p)          ctime((t))
+typedef int _Xgtimeparams;     /* dummy */
+# define _XGmtime(t,p)         gmtime((t))
+typedef int _Xltimeparams;     /* dummy */
+# define _XLocaltime(t,p)      localtime((t))
+
+#elif !defined(XOS_USE_MTSAFE_TIMEAPI) || defined(XNO_MTSAFE_TIMEAPI)
+/* Systems with thread support but no _r API. */
+typedef struct {
+# ifdef TIMELEN
+  char buf[TIMELEN];
+# else
+  char buf[26];
+# endif
+  char *result;
+} _Xctimeparams, _Xatimeparams;
+typedef struct {
+  struct tm buf;
+  struct tm *result;
+} _Xgtimeparams, _Xltimeparams;
+# define _XAsctime(t,p) \
+ ( (_Xos_processLock), \
+   (((p).result = asctime((t))) ? \
+    (strncpy((p).buf, (p).result, sizeof((p).buf)), (p).result = &(p).buf) : \
+    0), \
+   (_Xos_processUnlock), \
+   (p).result )
+# define _XCtime(t,p) \
+ ( (_Xos_processLock), \
+   (((p).result = ctime((t))) ? \
+    (strncpy((p).buf, (p).result, sizeof((p).buf)), (p).result = &(p).buf) : \
+    0), \
+   (_Xos_processUnlock), \
+   (p).result )
+# define _XGmtime(t,p) \
+ ( (_Xos_processLock), \
+   (((p).result = gmtime(t)) ? \
+    (memcpy(&(p).buf, (p).result, sizeof((p).buf)), (p).result = &(p).buf) : \
+    0), \
+   (_Xos_processUnlock), \
+   (p).result )
+# define _XLocaltime(t,p) \
+ ( (_Xos_processLock), \
+   (((p).result = localtime(t)) ? \
+    (memcpy(&(p).buf, (p).result, sizeof((p).buf)), (p).result = &(p).buf) : \
+    0), \
+   (_Xos_processUnlock), \
+   (p).result )
+
+#elif !defined(_POSIX_THREAD_SAFE_FUNCTIONS) && (defined(__osf__) || defined(hpV4))
+/* Returns (int)0 on success.  OSF/1 v3.2, HP/UX 10
+ *
+ * extern int asctime_r(const struct tm *timeptr, char *buffer, int buflen);
+ * extern int ctime_r(const time_t *timer, char *buffer, int buflen);
+ * extern int gmtime_r(const time_t *timer, struct tm *result);
+ * extern int localtime_r(const time_t *timer, struct tm *result);
+ */
+# ifdef TIMELEN
+typedef char _Xatimeparams[TIMELEN];
+typedef char _Xctimeparams[TIMELEN];
+# else
+typedef char _Xatimeparams[26];
+typedef char _Xctimeparams[26];
+# endif
+typedef struct tm _Xgtimeparams;
+typedef struct tm _Xltimeparams;
+# define _XAsctime(t,p)                (asctime_r((t),(p),sizeof((p))) ? NULL : (p))
+# define _XCtime(t,p)          (ctime_r((t),(p),sizeof((p))) ? NULL : (p))
+# define _XGmtime(t,p)         (gmtime_r((t),&(p)) ? NULL : &(p))
+# define _XLocaltime(t,p)      (localtime_r((t),&(p)) ? NULL : &(p))
+
+#elif !defined(_POSIX_THREAD_SAFE_FUNCTIONS) && defined(sun)
+/* Returns NULL on failure.  Solaris 2.5
+ *
+ * extern char *asctime_r(const struct tm *tm,char *buf, int buflen);
+ * extern char *ctime_r(const time_t *clock, char *buf, int buflen);
+ * extern struct tm *gmtime_r(const time_t *clock, struct tm *res);
+ * extern struct tm *localtime_r(const time_t *clock, struct tm *res);
+ */
+# ifdef TIMELEN
+typedef char _Xatimeparams[TIMELEN];
+typedef char _Xctimeparams[TIMELEN];
+# else
+typedef char _Xatimeparams[26];
+typedef char _Xctimeparams[26];
+# endif
+typedef struct tm _Xgtimeparams;
+typedef struct tm _Xltimeparams;
+# define _XAsctime(t,p)                asctime_r((t),(p),sizeof((p)))
+# define _XCtime(t,p)          ctime_r((t),(p),sizeof((p)))
+# define _XGmtime(t,p)         gmtime_r((t),&(p))
+# define _XLocaltime(t,p)      localtime_r((t),&(p))
+
+#else /* defined(_POSIX_THREAD_SAFE_FUNCTIONS) */
+/* POSIX final API.  OSF/1 v4.0, AIX, etc.
+ *
+ * extern char *asctime_r(const struct tm *timeptr, char *buffer);
+ * extern char *ctime_r(const time_t *timer, char *buffer);
+ * extern struct tm *gmtime_r(const time_t *timer, struct tm *result);
+ * extern struct tm *localtime_r(const time_t *timer, struct tm *result);
+ */
+# if defined(__osf__)
+/* OSF/1 V4.0 <time.h> doesn't declare the _P routines, breaking under C++. */
+extern char *_Pasctime_r(const struct tm *, char *);
+extern char *_Pctime_r(const time_t *, char *);
+extern struct tm *_Plocaltime_r(const time_t *, struct tm *);
+# endif
+# ifdef TIMELEN
+typedef char _Xatimeparams[TIMELEN];
+typedef char _Xctimeparams[TIMELEN];
+# else
+typedef char _Xatimeparams[26];
+typedef char _Xctimeparams[26];
+# endif
+typedef struct tm _Xgtimeparams;
+typedef struct tm _Xltimeparams;
+# define _XAsctime(t,p)                asctime_r((t),(p))
+# define _XCtime(t,p)          ctime_r((t),(p))
+# define _XGmtime(t,p)         gmtime_r((t),&(p))
+# define _XLocaltime(t,p)      localtime_r((t),&(p))
+#endif /* X_INCLUDE_TIME_H */
+
+#if defined(X_INCLUDE_TIME_H) && !defined(_XOS_INCLUDED_TIME_H)
+# define _XOS_INCLUDED_TIME_H
+#endif
+
+
+/***** <grp.h> wrappers *****/
+
+/*
+ * Effective prototypes for <grp.h> wrappers:
+ *
+ * NOTE: On systems lacking appropriate _r functions Getgrgid() and
+ *     Getgrnam() do NOT copy the list of group members!
+ *
+ * Remember that fgetgrent(), setgrent(), getgrent(), and endgrent()
+ * are not included in POSIX.
+ *
+ * #define X_INCLUDE_GRP_H
+ * #define XOS_USE_..._LOCKING
+ * #include <X11/Xos_r.h>
+ *
+ * typedef ... _Xgetgrparams;
+ *
+ * struct group *_XGetgrgid(gid_t, _Xgetgrparams);
+ * struct group *_XGetgrnam(const char *, _Xgetgrparams);
+ */
+
+#if defined(X_INCLUDE_GRP_H) && !defined(_XOS_INCLUDED_GRP_H)
+# include <grp.h>
+# if defined(XUSE_MTSAFE_API) || defined(XUSE_MTSAFE_GRPAPI)
+#  define XOS_USE_MTSAFE_GRPAPI 1
+# endif
+#endif
+
+#if !defined(X_INCLUDE_GRP_H) || defined(_XOS_INCLUDED_GRP_H)
+/* Do nothing. */
+
+#elif !defined(XTHREADS) && !defined(X_FORCE_USE_MTSAFE_API)
+/* Use regular, unsafe API. */
+typedef int _Xgetgrparams;     /* dummy */
+#define _XGetgrgid(g,p)        getgrgid((g))
+#define _XGetgrnam(n,p)        getgrnam((n))
+
+#elif !defined(XOS_USE_MTSAFE_GRPAPI) || defined(XNO_MTSAFE_GRPAPI)
+/* Systems with thread support but no _r API.  UnixWare 2.0. */
+typedef struct {
+  struct group grp;
+#ifdef LINE_MAX
+  char buf[LINE_MAX];  /* Should be sysconf(_SC_GETGR_R_SIZE_MAX)? */
+#else
+  char buf[1024];      /* Should be sysconf(_SC_GETGR_R_SIZE_MAX)? */
+#endif
+  struct group *pgrp;
+  size_t len;
+} _Xgetgrparams;
+#ifdef SVR4
+/* Copy the gr_passwd field too. */
+# define _Xgrp_copyGroup(p) \
+ ( memcpy(&(p).grp, (p).pgrp, sizeof(struct group)), \
+   ((p).grp.gr_name = (p).buf), \
+   ((p).len = strlen((p).pgrp->gr_name)), \
+   strcpy((p).grp.gr_name, (p).pgrp->gr_name), \
+   ((p).grp.gr_passwd = (p).grp.gr_name + (p).len + 1), \
+   ((p).pgrp = &(p).grp), \
+   0 )
+#else
+# define _Xgrp_copyGroup(p) \
+ ( memcpy(&(p).grp, (p).pgrp, sizeof(struct group)), \
+   ((p).grp.gr_name = (p).buf), \
+   strcpy((p).grp.gr_name, (p).pgrp->gr_name), \
+   ((p).pgrp = &(p).grp), \
+   0 )
+#endif
+#define _XGetgrgid(g,p) \
+ ( (_Xos_processLock), \
+   (((p).pgrp = getgrgid((g))) ? _Xgrp_copyGroup(p) : 0), \
+   (_Xos_processUnlock), \
+   (p).pgrp )
+#define _XGetgrnam(n,p) \
+ ( (_Xos_processLock), \
+   (((p).pgrp = getgrnam((n))) ? _Xgrp_copyGroup(p) : 0), \
+   (_Xos_processUnlock), \
+   (p).pgrp )
+
+#elif !defined(_POSIX_THREAD_SAFE_FUNCTIONS) && (defined(sun) || defined(__osf__))
+/* Non-POSIX API.  Solaris, DEC v3.2.
+ *
+ * extern struct group *getgrgid_r(gid_t, struct group *, char *, int);
+ * extern struct group *getgrnam_r(const char *, struct group *, char *, int);
+ */
+typedef struct {
+  struct group grp;
+#ifdef LINE_MAX
+  char buf[LINE_MAX];  /* Should be sysconf(_SC_GETGR_R_SIZE_MAX)? */
+#else
+  char buf[1024];      /* Should be sysconf(_SC_GETGR_R_SIZE_MAX)? */
+#endif
+} _Xgetgrparams;
+#define _XGetgrgid(g,p)        getgrgid_r((g), &(p).grp, (p).buf, sizeof((p).buf))
+#define _XGetgrnam(n,p)        getgrnam_r((n), &(p).grp, (p).buf, sizeof((p).buf))
+
+#elif !defined(_POSIX_THREAD_SAFE_FUNCTIONS)
+/* Non-POSIX API.  HP/UX 10, AIX 4.
+ *
+ * extern int getgrgid_r(gid_t, struct group *, char *, int);
+ * extern int getgrnam_r(const char *, struct group *, char *, int);
+ */
+typedef struct {
+  struct group grp;
+#ifdef LINE_MAX
+  char buf[LINE_MAX];  /* Should be sysconf(_SC_GETGR_R_SIZE_MAX)? */
+#else
+  char buf[1024];      /* Should be sysconf(_SC_GETGR_R_SIZE_MAX)? */
+#endif
+} _Xgetgrparams;
+#define _XGetgrgid(g,p)        \
+ ((getgrgid_r((g), &(p).grp, (p).buf, sizeof((p).buf)) ? NULL : &(p).grp))
+#define _XGetgrnam(n,p)        \
+ ((getgrnam_r((n), &(p).grp, (p).buf, sizeof((p).buf)) ? NULL : &(p).grp))
+
+#else
+/* POSIX final API.  DEC v4.0, IRIX 6.2.
+ *
+ * int getgrgid_r(gid_t, struct group *, char *, size_t, struct group **);
+ * int getgrnam_r(const char *, struct group *, char *, size_t, struct group **);
+ */
+# if defined(__osf__)
+/* OSF/1 V4.0 <grp.h> doesn't declare the _P routines, breaking under C++. */
+extern int _Pgetgrgid_r(gid_t, struct group *, char *, size_t, struct group **);
+extern int _Pgetgrnam_r(const char *, struct group *, char *, size_t, struct group **);
+# endif
+typedef struct {
+  struct group grp;
+#ifdef LINE_MAX
+  char buf[LINE_MAX];  /* Should be sysconf(_SC_GETGR_R_SIZE_MAX)? */
+#else
+  char buf[1024];      /* Should be sysconf(_SC_GETGR_R_SIZE_MAX)? */
+#endif
+  struct group *result;
+} _Xgetgrparams;
+
+#define _XGetgrgid(g,p)        \
+ ((getgrgid_r((g), &(p).grp, (p).buf, sizeof((p).buf), &(p).result) ? \
+   NULL : (p).result))
+#define _XGetgrnam(n,p)        \
+ ((getgrnam_r((n), &(p).grp, (p).buf, sizeof((p).buf), &(p).result) ? \
+   NULL : (p).result))
+#endif
+
+#if defined(X_INCLUDE_GRP_H) && !defined(_XOS_INCLUDED_GRP_H)
+# define _XOS_INCLUDED_GRP_H
+#endif
+
+
+#ifdef __cplusplus
+}  /* Close scope of 'extern "C"' declaration which encloses file. */
+#endif
diff --git a/Xserver/include/Xosdefs.h b/Xserver/include/Xosdefs.h
new file mode 100644 (file)
index 0000000..864d537
--- /dev/null
@@ -0,0 +1,128 @@
+/*
+ * O/S-dependent (mis)feature macro definitions
+ *
+ * $XConsortium: Xosdefs.h /main/16 1996/09/28 16:17:29 rws $
+ * $XFree86: xc/include/Xosdefs.h,v 3.11 1996/12/23 05:58:09 dawes Exp $
+ *
+Copyright (c) 1991  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+ */
+
+#ifndef _XOSDEFS_H_
+#define _XOSDEFS_H_
+
+/*
+ * X_NOT_STDC_ENV means does not have ANSI C header files.  Lack of this
+ * symbol does NOT mean that the system has stdarg.h.
+ *
+ * X_NOT_POSIX means does not have POSIX header files.  Lack of this
+ * symbol does NOT mean that the POSIX environment is the default.
+ * You may still have to define _POSIX_SOURCE to get it.
+ */
+
+#ifdef NOSTDHDRS
+#define X_NOT_POSIX
+#define X_NOT_STDC_ENV
+#endif
+
+#ifdef sony
+#if !defined(SYSTYPE_SYSV) && !defined(_SYSTYPE_SYSV)
+#define X_NOT_POSIX
+#endif
+#endif
+
+#ifdef UTEK
+#define X_NOT_POSIX
+#define X_NOT_STDC_ENV
+#endif
+
+#ifdef vax
+#ifndef ultrix                 /* assume vanilla BSD */
+#define X_NOT_POSIX
+#define X_NOT_STDC_ENV
+#endif
+#endif
+
+#ifdef luna
+#define X_NOT_POSIX
+#define X_NOT_STDC_ENV
+#endif
+
+#ifdef Mips
+#define X_NOT_POSIX
+#define X_NOT_STDC_ENV
+#endif
+  
+#ifdef USL
+#ifdef SYSV /* (release 3.2) */
+#define X_NOT_POSIX
+#define X_NOT_STDC_ENV
+#endif
+#endif
+
+#ifdef i386
+#ifdef SYSV
+#if !(defined(ISC) && defined(_POSIX_SOURCE))
+#ifndef SCO
+#ifndef _SCO_DS /* SCO 5.0 has SVR4 header files */
+#define X_NOT_POSIX
+#endif
+#define X_NOT_STDC_ENV
+#endif
+#endif /* !(defined(ISC) && defined(_POSIX_SOURCE)) */
+#endif
+#endif
+
+#ifdef MOTOROLA
+#ifdef SYSV
+#define X_NOT_STDC_ENV
+#endif
+#endif
+
+#ifdef sun
+#ifdef SVR4
+/* define this to whatever it needs to be */
+#define X_POSIX_C_SOURCE 199300L
+#endif
+#endif
+
+#ifdef WIN32
+#ifndef _POSIX_
+#define X_NOT_POSIX
+#endif
+#endif
+
+#if defined(nec_ews_svr2) || defined(SX) || defined(PC_UX)
+#define X_NOT_POSIX
+#define X_NOT_STDC_ENV
+#endif
+
+#ifdef __EMX__
+#define USGISH
+/* EMX claims to be ANSI, so X_NOT_STDC_ENV does not hold */
+/* could have been provided as std flags as well */
+#define X_WCHAR
+#define X_LOCALE
+#endif
+
+#endif /* _XOSDEFS_H_ */
diff --git a/Xserver/include/Xpoll.h b/Xserver/include/Xpoll.h
new file mode 100644 (file)
index 0000000..be2850a
--- /dev/null
@@ -0,0 +1,228 @@
+/* $XConsortium: Xpoll.h /main/6 1996/12/02 10:25:52 lehors $ */
+
+/*
+
+Copyright (c) 1994  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be included
+in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR
+OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall
+not be used in advertising or otherwise to promote the sale, use or
+other dealings in this Software without prior written authorization
+from the X Consortium.
+
+*/
+
+#ifndef _XPOLL_H_
+#define _XPOLL_H_
+
+#ifndef WIN32
+
+#ifndef USE_POLL
+
+#include <X11/Xos.h>
+#if (defined(SVR4) || defined(CRAY) || defined(AIXV3)) && !defined(FD_SETSIZE)
+#include <sys/select.h>
+#ifdef luna
+#include <sysent.h>
+#endif
+#endif
+/* AIX 4.2 fubar-ed <sys/select.h>, so go to heroic measures to get it */
+#if defined(AIXV4) && !defined(NFDBITS)
+#include <sys/select.h>
+#endif
+#include <X11/Xmd.h>
+#ifdef CSRG_BASED
+#include <sys/param.h>
+# if BSD < 199103
+typedef long fd_mask;
+# endif
+#endif
+
+#define XFD_SETSIZE    256
+#ifndef FD_SETSIZE
+#define FD_SETSIZE     XFD_SETSIZE
+#endif
+
+#ifndef NBBY
+#define NBBY   8               /* number of bits in a byte */
+#endif
+
+#ifndef NFDBITS
+#define NFDBITS (sizeof(fd_mask) * NBBY)       /* bits per mask */
+#endif
+
+#ifndef howmany
+#define howmany(x,y)   (((x)+((y)-1))/(y))
+#endif
+
+#ifdef BSD
+# if BSD < 198911      /* 198911 == OSF/1, 199103 == CSRG_BASED */
+#  ifndef luna         /* and even though on LUNA BSD ==  43, it has it */
+typedef struct fd_set {
+       fd_mask fds_bits[howmany(FD_SETSIZE, NFDBITS)];
+} fd_set;
+#  endif
+# endif
+#endif
+
+#ifdef hpux /* and perhaps old BSD ??? */
+#define Select(n,r,w,e,t) select(n,(int*)r,(int*)w,(int*)e,(struct timeval*)t)
+#else
+#define Select(n,r,w,e,t) select(n,(fd_set*)r,(fd_set*)w,(fd_set*)e,(struct timeval*)t)
+#endif
+
+#ifndef FD_SET
+#define FD_SET(n, p)    ((p)->fds_bits[(n)/NFDBITS] |= (1 << ((n) % NFDBITS)))
+#endif
+#ifndef FD_CLR
+#define FD_CLR(n, p)    ((p)->fds_bits[(n)/NFDBITS] &= ~(1 << ((n) % NFDBITS)))
+#endif
+#ifndef FD_ISSET
+#define FD_ISSET(n, p)  ((p)->fds_bits[(n)/NFDBITS] & (1 << ((n) % NFDBITS)))
+#endif
+#ifndef FD_ZERO
+#define FD_ZERO(p)      bzero((char *)(p), sizeof(*(p)))
+#endif
+
+/*
+ * The following macros are used by the servers only. There is an
+ * explicit assumption that the bit array in the fd_set is at least
+ * 256 bits long (8 32-bit words). This is true on most modern POSIX 
+ * systems. Note that this is merely an optimization for the servers
+ * based on assumptions about the way that file descripters are
+ * allocated on POSIX systems. 
+ *
+ * When porting X to new systems it is important to adjust these
+ * macros if the system has fewer than 256 bits in the fd_set bit
+ * array.
+ */
+#define XFD_ANYSET(p) \
+               ((p)->fds_bits[0] || (p)->fds_bits[1] || \
+               (p)->fds_bits[2] || (p)->fds_bits[3] || \
+               (p)->fds_bits[4] || (p)->fds_bits[5] || \
+               (p)->fds_bits[6] || (p)->fds_bits[7])
+
+#define XFD_COPYSET(src,dst) \
+               (dst)->fds_bits[0] = (src)->fds_bits[0]; \
+               (dst)->fds_bits[1] = (src)->fds_bits[1]; \
+               (dst)->fds_bits[2] = (src)->fds_bits[2]; \
+               (dst)->fds_bits[3] = (src)->fds_bits[3]; \
+               (dst)->fds_bits[4] = (src)->fds_bits[4]; \
+               (dst)->fds_bits[5] = (src)->fds_bits[5]; \
+               (dst)->fds_bits[6] = (src)->fds_bits[6]; \
+               (dst)->fds_bits[7] = (src)->fds_bits[7];
+
+#define XFD_ANDSET(dst,b1,b2) \
+               (dst)->fds_bits[0] = ((b1)->fds_bits[0] & (b2)->fds_bits[0]); \
+               (dst)->fds_bits[1] = ((b1)->fds_bits[1] & (b2)->fds_bits[1]); \
+               (dst)->fds_bits[2] = ((b1)->fds_bits[2] & (b2)->fds_bits[2]); \
+               (dst)->fds_bits[3] = ((b1)->fds_bits[3] & (b2)->fds_bits[3]); \
+               (dst)->fds_bits[4] = ((b1)->fds_bits[4] & (b2)->fds_bits[4]); \
+               (dst)->fds_bits[5] = ((b1)->fds_bits[5] & (b2)->fds_bits[5]); \
+               (dst)->fds_bits[6] = ((b1)->fds_bits[6] & (b2)->fds_bits[6]); \
+               (dst)->fds_bits[7] = ((b1)->fds_bits[7] & (b2)->fds_bits[7]);
+
+#define XFD_ORSET(dst,b1,b2) \
+               (dst)->fds_bits[0] = ((b1)->fds_bits[0] | (b2)->fds_bits[0]); \
+               (dst)->fds_bits[1] = ((b1)->fds_bits[1] | (b2)->fds_bits[1]); \
+               (dst)->fds_bits[2] = ((b1)->fds_bits[2] | (b2)->fds_bits[2]); \
+               (dst)->fds_bits[3] = ((b1)->fds_bits[3] | (b2)->fds_bits[3]); \
+               (dst)->fds_bits[4] = ((b1)->fds_bits[4] | (b2)->fds_bits[4]); \
+               (dst)->fds_bits[5] = ((b1)->fds_bits[5] | (b2)->fds_bits[5]); \
+               (dst)->fds_bits[6] = ((b1)->fds_bits[6] | (b2)->fds_bits[6]); \
+               (dst)->fds_bits[7] = ((b1)->fds_bits[7] | (b2)->fds_bits[7]);
+
+#define XFD_UNSET(dst,b1) \
+               (dst)->fds_bits[0] &= ~((b1)->fds_bits[0]); \
+               (dst)->fds_bits[1] &= ~((b1)->fds_bits[1]); \
+               (dst)->fds_bits[2] &= ~((b1)->fds_bits[2]); \
+               (dst)->fds_bits[3] &= ~((b1)->fds_bits[3]); \
+               (dst)->fds_bits[4] &= ~((b1)->fds_bits[4]); \
+               (dst)->fds_bits[5] &= ~((b1)->fds_bits[5]); \
+               (dst)->fds_bits[6] &= ~((b1)->fds_bits[6]); \
+               (dst)->fds_bits[7] &= ~((b1)->fds_bits[7]);
+
+#else /* USE_POLL */
+#include <sys/poll.h>
+#endif /* USE_POLL */
+
+#else /* WIN32 */
+
+#define XFD_SETSIZE    256
+#ifndef FD_SETSIZE
+#define FD_SETSIZE     XFD_SETSIZE
+#endif
+#include <X11/Xwinsock.h>
+
+#define Select(n,r,w,e,t) select(0,(fd_set*)r,(fd_set*)w,(fd_set*)e,(struct timeval*)t)
+
+#define XFD_SETCOUNT(p)        (((fd_set FAR *)(p))->fd_count)
+#define XFD_FD(p,i) (((fd_set FAR *)(p))->fd_array[i])
+#define XFD_ANYSET(p)  XFD_SETCOUNT(p)
+
+#define XFD_COPYSET(src,dst) { \
+    u_int __i; \
+    FD_ZERO(dst); \
+    for (__i = 0; __i < XFD_SETCOUNT(src) ; __i++) { \
+        XFD_FD(dst,__i) = XFD_FD(src,__i); \
+    } \
+    XFD_SETCOUNT(dst) = XFD_SETCOUNT(src); \
+}
+
+#define XFD_ANDSET(dst,b1,b2) { \
+    u_int __i; \
+    FD_ZERO(dst); \
+    for (__i = 0; __i < XFD_SETCOUNT(b1) ; __i++) { \
+        if (FD_ISSET(XFD_FD(b1,__i), b2)) \
+          FD_SET(XFD_FD(b1,__i), dst); \
+    } \
+}
+
+#define XFD_ORSET(dst,b1,b2) { \
+    u_int __i; \
+    XFD_COPYSET(b1,dst); \
+    for (__i = 0; __i < XFD_SETCOUNT(b2) ; __i++) { \
+        if (!FD_ISSET(XFD_FD(b2,__i), dst)) \
+          FD_SET(XFD_FD(b2,__i), dst); \
+    } \
+}
+
+/* this one is really sub-optimal */
+#define XFD_UNSET(dst,b1) { \
+    u_int __i; \
+    for (__i = 0; __i < XFD_SETCOUNT(b1) ; __i++) { \
+       FD_CLR(XFD_FD(b1,__i), dst); \
+    } \
+}
+
+/* we have to pay the price of having an array here, unlike with bitmasks
+   calling twice FD_SET with the same fd is not transparent, so be careful */
+#undef FD_SET
+#define FD_SET(fd,set) do { \
+    if (XFD_SETCOUNT(set) < FD_SETSIZE && !FD_ISSET(fd,set)) \
+        XFD_FD(set,XFD_SETCOUNT(set)++)=(fd); \
+} while(0)
+
+#define getdtablesize() FD_SETSIZE 
+
+#endif /* WIN32 */
+
+#endif /* _XPOLL_H_ */
diff --git a/Xserver/include/Xproto.h b/Xserver/include/Xproto.h
new file mode 100644 (file)
index 0000000..58e047b
--- /dev/null
@@ -0,0 +1,2130 @@
+/*
+ *     $XConsortium: Xproto.h /main/21 1996/03/20 15:27:51 mor $
+ */
+
+/* Definitions for the X window system used by server and c bindings */
+
+/*
+ * This packet-construction scheme makes the following assumptions:
+ *
+ * 1. The compiler is able
+ * to generate code which addresses one- and two-byte quantities.
+ * In the worst case, this would be done with bit-fields.  If bit-fields
+ * are used it may be necessary to reorder the request fields in this file,
+ * depending on the order in which the machine assigns bit fields to
+ * machine words.  There may also be a problem with sign extension,
+ * as K+R specify that bitfields are always unsigned.
+ *
+ * 2. 2- and 4-byte fields in packet structures must be ordered by hand
+ * such that they are naturally-aligned, so that no compiler will ever
+ * insert padding bytes.
+ *
+ * 3. All packets are hand-padded to a multiple of 4 bytes, for
+ * the same reason.
+ */
+
+#ifndef XPROTO_H
+#define XPROTO_H
+
+/***********************************************************
+
+Copyright (c) 1987  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+
+Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
+
+                        All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and its 
+documentation for any purpose and without fee is hereby granted, 
+provided that the above copyright notice appear in all copies and that
+both that copyright notice and this permission notice appear in 
+supporting documentation, and that the name of Digital not be
+used in advertising or publicity pertaining to distribution of the
+software without specific, written prior permission.  
+
+DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
+ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
+DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
+ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+SOFTWARE.
+
+******************************************************************/
+
+#include <X11/Xmd.h>
+#include <X11/Xprotostr.h>
+
+/*
+ * Define constants for the sizes of the network packets.  The sz_ prefix is
+ * used instead of something more descriptive so that the symbols are no more
+ * than 32 characters in length (which causes problems for some compilers).
+ */
+#define sz_xSegment 8
+#define sz_xPoint 4
+#define sz_xRectangle 8
+#define sz_xArc 12
+#define sz_xConnClientPrefix 12
+#define sz_xConnSetupPrefix 8
+#define sz_xConnSetup 32
+#define sz_xPixmapFormat 8
+#define sz_xDepth 8
+#define sz_xVisualType 24
+#define sz_xWindowRoot 40
+#define sz_xTimecoord 8
+#define sz_xHostEntry 4
+#define sz_xCharInfo 12
+#define sz_xFontProp 8
+#define sz_xTextElt 2
+#define sz_xColorItem 12
+#define sz_xrgb 8
+#define sz_xGenericReply 32
+#define sz_xGetWindowAttributesReply 44
+#define sz_xGetGeometryReply 32
+#define sz_xQueryTreeReply 32
+#define sz_xInternAtomReply 32
+#define sz_xGetAtomNameReply 32
+#define sz_xGetPropertyReply 32
+#define sz_xListPropertiesReply 32
+#define sz_xGetSelectionOwnerReply 32
+#define sz_xGrabPointerReply 32
+#define sz_xQueryPointerReply 32
+#define sz_xGetMotionEventsReply 32
+#define sz_xTranslateCoordsReply 32
+#define sz_xGetInputFocusReply 32
+#define sz_xQueryKeymapReply 40
+#define sz_xQueryFontReply 60
+#define sz_xQueryTextExtentsReply 32
+#define sz_xListFontsReply 32
+#define sz_xGetFontPathReply 32
+#define sz_xGetImageReply 32
+#define sz_xListInstalledColormapsReply 32
+#define sz_xAllocColorReply 32
+#define sz_xAllocNamedColorReply 32
+#define sz_xAllocColorCellsReply 32
+#define sz_xAllocColorPlanesReply 32
+#define sz_xQueryColorsReply 32
+#define sz_xLookupColorReply 32
+#define sz_xQueryBestSizeReply 32
+#define sz_xQueryExtensionReply 32
+#define sz_xListExtensionsReply 32
+#define sz_xSetMappingReply 32
+#define sz_xGetKeyboardControlReply 52
+#define sz_xGetPointerControlReply 32
+#define sz_xGetScreenSaverReply 32
+#define sz_xListHostsReply 32
+#define sz_xSetModifierMappingReply 32
+#define sz_xError 32
+#define sz_xEvent 32
+#define sz_xKeymapEvent 32
+#define sz_xReq 4
+#define sz_xResourceReq 8
+#define sz_xCreateWindowReq 32
+#define sz_xChangeWindowAttributesReq 12
+#define sz_xChangeSaveSetReq 8
+#define sz_xReparentWindowReq 16
+#define sz_xConfigureWindowReq 12
+#define sz_xCirculateWindowReq 8
+#define sz_xInternAtomReq 8
+#define sz_xChangePropertyReq 24
+#define sz_xDeletePropertyReq 12
+#define sz_xGetPropertyReq 24
+#define sz_xSetSelectionOwnerReq 16
+#define sz_xConvertSelectionReq 24
+#define sz_xSendEventReq 44
+#define sz_xGrabPointerReq 24
+#define sz_xGrabButtonReq 24
+#define sz_xUngrabButtonReq 12
+#define sz_xChangeActivePointerGrabReq 16
+#define sz_xGrabKeyboardReq 16
+#define sz_xGrabKeyReq 16
+#define sz_xUngrabKeyReq 12
+#define sz_xAllowEventsReq 8
+#define sz_xGetMotionEventsReq 16
+#define sz_xTranslateCoordsReq 16
+#define sz_xWarpPointerReq 24
+#define sz_xSetInputFocusReq 12
+#define sz_xOpenFontReq 12
+#define sz_xQueryTextExtentsReq 8
+#define sz_xListFontsReq 8
+#define sz_xSetFontPathReq 8
+#define sz_xCreatePixmapReq 16
+#define sz_xCreateGCReq 16
+#define sz_xChangeGCReq 12
+#define sz_xCopyGCReq 16
+#define sz_xSetDashesReq 12
+#define sz_xSetClipRectanglesReq 12
+#define sz_xCopyAreaReq 28
+#define sz_xCopyPlaneReq 32
+#define sz_xPolyPointReq 12
+#define sz_xPolySegmentReq 12
+#define sz_xFillPolyReq 16
+#define sz_xPutImageReq 24
+#define sz_xGetImageReq 20
+#define sz_xPolyTextReq 16
+#define sz_xImageTextReq 16
+#define sz_xCreateColormapReq 16
+#define sz_xCopyColormapAndFreeReq 12
+#define sz_xAllocColorReq 16
+#define sz_xAllocNamedColorReq 12
+#define sz_xAllocColorCellsReq 12
+#define sz_xAllocColorPlanesReq 16
+#define sz_xFreeColorsReq 12
+#define sz_xStoreColorsReq 8
+#define sz_xStoreNamedColorReq 16
+#define sz_xQueryColorsReq 8
+#define sz_xLookupColorReq 12
+#define sz_xCreateCursorReq 32
+#define sz_xCreateGlyphCursorReq 32
+#define sz_xRecolorCursorReq 20
+#define sz_xQueryBestSizeReq 12
+#define sz_xQueryExtensionReq 8
+#define sz_xChangeKeyboardControlReq 8
+#define sz_xBellReq 4
+#define sz_xChangePointerControlReq 12
+#define sz_xSetScreenSaverReq 12
+#define sz_xChangeHostsReq 8
+#define sz_xListHostsReq 4
+#define sz_xChangeModeReq 4
+#define sz_xRotatePropertiesReq 12
+#define sz_xReply 32
+#define sz_xGrabKeyboardReply 32
+#define sz_xListFontsWithInfoReply 60
+#define sz_xSetPointerMappingReply 32
+#define sz_xGetKeyboardMappingReply 32
+#define sz_xGetPointerMappingReply 32
+#define sz_xGetModifierMappingReply 32
+#define sz_xListFontsWithInfoReq 8
+#define sz_xPolyLineReq 12
+#define sz_xPolyArcReq 12
+#define sz_xPolyRectangleReq 12
+#define sz_xPolyFillRectangleReq 12
+#define sz_xPolyFillArcReq 12
+#define sz_xPolyText8Req 16
+#define sz_xPolyText16Req 16
+#define sz_xImageText8Req 16
+#define sz_xImageText16Req 16
+#define sz_xSetPointerMappingReq 4
+#define sz_xForceScreenSaverReq 4
+#define sz_xSetCloseDownModeReq 4
+#define sz_xClearAreaReq 16
+#define sz_xSetAccessControlReq 4
+#define sz_xGetKeyboardMappingReq 8
+#define sz_xSetModifierMappingReq 4
+#define sz_xPropIconSize 24
+#define sz_xChangeKeyboardMappingReq 8
+
+
+/* For the purpose of the structure definitions in this file,
+we must redefine the following types in terms of Xmd.h's types, which may
+include bit fields.  All of these are #undef'd at the end of this file,
+restoring the definitions in X.h.  */
+
+#define Window CARD32
+#define Drawable CARD32
+#define Font CARD32
+#define Pixmap CARD32
+#define Cursor CARD32
+#define Colormap CARD32
+#define GContext CARD32
+#define Atom CARD32
+#define VisualID CARD32
+#define Time CARD32
+#define KeyCode CARD8
+#define KeySym CARD32
+
+#define X_TCP_PORT 6000     /* add display number */
+
+#define xTrue        1
+#define xFalse       0
+
+
+typedef CARD16 KeyButMask;
+
+/***************** 
+   connection setup structure.  This is followed by
+   numRoots xWindowRoot structs.
+*****************/
+
+typedef struct {
+    CARD8      byteOrder;
+    BYTE       pad;
+    CARD16     majorVersion B16, minorVersion B16;
+    CARD16     nbytesAuthProto B16;    /* Authorization protocol */
+    CARD16     nbytesAuthString B16;   /* Authorization string */
+    CARD16     pad2 B16;
+} xConnClientPrefix;
+
+typedef struct {
+    CARD8          success;
+    BYTE           lengthReason; /*num bytes in string following if failure */
+    CARD16         majorVersion B16, 
+                   minorVersion B16;
+    CARD16         length B16;  /* 1/4 additional bytes in setup info */
+} xConnSetupPrefix;
+
+
+typedef struct {
+    CARD32         release B32;
+    CARD32         ridBase B32, 
+                   ridMask B32;
+    CARD32         motionBufferSize B32;
+    CARD16         nbytesVendor B16;  /* number of bytes in vendor string */
+    CARD16         maxRequestSize B16;
+    CARD8          numRoots;          /* number of roots structs to follow */
+    CARD8          numFormats;        /* number of pixmap formats */
+    CARD8          imageByteOrder;        /* LSBFirst, MSBFirst */
+    CARD8          bitmapBitOrder;        /* LeastSignificant, MostSign...*/
+    CARD8          bitmapScanlineUnit,     /* 8, 16, 32 */
+                   bitmapScanlinePad;     /* 8, 16, 32 */
+    KeyCode       minKeyCode, maxKeyCode;
+    CARD32        pad2 B32;
+} xConnSetup;
+
+typedef struct {
+    CARD8          depth;
+    CARD8          bitsPerPixel;
+    CARD8          scanLinePad;
+    CARD8          pad1;
+    CARD32        pad2 B32;
+} xPixmapFormat;
+
+/* window root */
+
+typedef struct {
+    CARD8      depth;
+    CARD8      pad1;
+    CARD16     nVisuals B16;  /* number of xVisualType structures following */
+    CARD32     pad2 B32;
+    } xDepth;
+
+typedef struct {
+    VisualID visualID B32;
+#if defined(__cplusplus) || defined(c_plusplus)
+    CARD8 c_class;
+#else
+    CARD8 class;
+#endif
+    CARD8 bitsPerRGB;
+    CARD16 colormapEntries B16;
+    CARD32 redMask B32, greenMask B32, blueMask B32;
+    CARD32 pad B32;
+    } xVisualType;
+
+typedef struct {
+    Window         windowId B32;
+    Colormap       defaultColormap B32;
+    CARD32         whitePixel B32, blackPixel B32;
+    CARD32         currentInputMask B32;   
+    CARD16         pixWidth B16, pixHeight B16;
+    CARD16         mmWidth B16, mmHeight B16;
+    CARD16         minInstalledMaps B16, maxInstalledMaps B16;
+    VisualID       rootVisualID B32;
+    CARD8          backingStore;
+    BOOL           saveUnders;
+    CARD8          rootDepth;
+    CARD8          nDepths;  /* number of xDepth structures following */
+} xWindowRoot;
+\f
+
+/*****************************************************************
+ * Structure Defns
+ *   Structures needed for replies 
+ *****************************************************************/
+
+/* Used in GetMotionEvents */
+
+typedef struct {
+    CARD32 time B32;
+    INT16 x B16, y B16;
+} xTimecoord;
+
+typedef struct {
+    CARD8 family;
+    BYTE pad;
+    CARD16 length B16;
+} xHostEntry;
+
+typedef struct {
+    INT16 leftSideBearing B16,
+         rightSideBearing B16,
+         characterWidth B16,
+         ascent B16,
+         descent B16;
+    CARD16 attributes B16;
+} xCharInfo;
+
+typedef struct {
+    Atom name B32;
+    CARD32 value B32;
+} xFontProp;
+
+/*
+ * non-aligned big-endian font ID follows this struct
+ */
+typedef struct {           /* followed by string */
+    CARD8 len; /* number of *characters* in string, or FontChange (255)
+                  for font change, or 0 if just delta given */
+    INT8 delta;
+} xTextElt;
+
+
+typedef struct {        
+    CARD32 pixel B32;
+    CARD16 red B16, green B16, blue B16;
+    CARD8 flags;  /* DoRed, DoGreen, DoBlue booleans */
+    CARD8 pad;
+} xColorItem;
+
+
+typedef struct {
+    CARD16 red B16, green B16, blue B16, pad B16;
+} xrgb;
+
+typedef CARD8 KEYCODE;
+\f
+
+/*****************
+ * XRep:
+ *    meant to be 32 byte quantity 
+ *****************/
+
+/* GenericReply is the common format of all replies.  The "data" items
+   are specific to each individual reply type. */
+
+typedef struct {       
+    BYTE type;              /* X_Reply */
+    BYTE data1;             /* depends on reply type */
+    CARD16 sequenceNumber B16;  /* of last request received by server */
+    CARD32 length B32;      /* 4 byte quantities beyond size of GenericReply */
+    CARD32 data00 B32;
+    CARD32 data01 B32;
+    CARD32 data02 B32;
+    CARD32 data03 B32;
+    CARD32 data04 B32;
+    CARD32 data05 B32;
+    } xGenericReply;
+
+/* Individual reply formats. */
+
+typedef struct {
+    BYTE type;  /* X_Reply */
+    CARD8 backingStore;
+    CARD16 sequenceNumber B16;
+    CARD32 length B32; /* NOT 0; this is an extra-large reply */
+    VisualID visualID B32;
+#if defined(__cplusplus) || defined(c_plusplus)
+    CARD16 c_class B16;
+#else
+    CARD16 class B16;
+#endif
+    CARD8 bitGravity;
+    CARD8 winGravity;
+    CARD32 backingBitPlanes B32;
+    CARD32 backingPixel B32;
+    BOOL saveUnder;
+    BOOL mapInstalled;
+    CARD8 mapState;
+    BOOL override;
+    Colormap colormap B32;
+    CARD32 allEventMasks B32;
+    CARD32 yourEventMask B32;
+    CARD16 doNotPropagateMask B16;
+    CARD16 pad B16;
+    } xGetWindowAttributesReply;
+
+typedef struct {
+    BYTE type;   /* X_Reply */
+    CARD8 depth;
+    CARD16 sequenceNumber B16;
+    CARD32 length B32;  /* 0 */
+    Window root B32;
+    INT16 x B16, y B16;
+    CARD16 width B16, height B16;
+    CARD16 borderWidth B16;
+    CARD16 pad1 B16;
+    CARD32 pad2 B32;
+    CARD32 pad3 B32;
+    } xGetGeometryReply;
+
+typedef struct {
+    BYTE type;  /* X_Reply */
+    BYTE pad1;
+    CARD16 sequenceNumber B16;
+    CARD32 length B32;
+    Window root B32, parent B32;
+    CARD16 nChildren B16;
+    CARD16 pad2 B16;
+    CARD32 pad3 B32;
+    CARD32 pad4 B32;
+    CARD32 pad5 B32;
+    } xQueryTreeReply;
+
+typedef struct {
+    BYTE type;  /* X_Reply */
+    BYTE pad1;
+    CARD16 sequenceNumber B16;
+    CARD32 length B32; /* 0 */
+    Atom atom B32;
+    CARD32 pad2 B32;
+    CARD32 pad3 B32;
+    CARD32 pad4 B32;
+    CARD32 pad5 B32;
+    CARD32 pad6 B32;
+    } xInternAtomReply;
+
+typedef struct {
+    BYTE type;  /* X_Reply */
+    BYTE pad1;
+    CARD16 sequenceNumber B16;
+    CARD32 length B32;  /* of additional bytes */
+    CARD16 nameLength B16;  /* # of characters in name */
+    CARD16 pad2 B16;
+    CARD32 pad3 B32;
+    CARD32 pad4 B32;
+    CARD32 pad5 B32;
+    CARD32 pad6 B32;
+    CARD32 pad7 B32;
+    } xGetAtomNameReply;
+
+typedef struct {
+    BYTE type;  /* X_Reply */
+    CARD8 format;
+    CARD16 sequenceNumber B16;
+    CARD32 length B32; /* of additional bytes */
+    Atom propertyType B32;
+    CARD32 bytesAfter B32;
+    CARD32 nItems B32; /* # of 8, 16, or 32-bit entities in reply */
+    CARD32 pad1 B32;
+    CARD32 pad2 B32;
+    CARD32 pad3 B32;
+    } xGetPropertyReply;
+
+typedef struct {
+    BYTE type;  /* X_Reply */
+    BYTE pad1;
+    CARD16 sequenceNumber B16;
+    CARD32 length B32;
+    CARD16 nProperties B16;
+    CARD16 pad2 B16;
+    CARD32 pad3 B32;
+    CARD32 pad4 B32;
+    CARD32 pad5 B32;
+    CARD32 pad6 B32;
+    CARD32 pad7 B32;
+    } xListPropertiesReply;
+
+typedef struct {
+    BYTE type;  /* X_Reply */
+    BYTE pad1;
+    CARD16 sequenceNumber B16;
+    CARD32 length B32;  /* 0 */
+    Window owner B32;
+    CARD32 pad2 B32;
+    CARD32 pad3 B32;
+    CARD32 pad4 B32;
+    CARD32 pad5 B32;
+    CARD32 pad6 B32;
+    } xGetSelectionOwnerReply;
+
+typedef struct {
+    BYTE type;  /* X_Reply */
+    BYTE status;
+    CARD16 sequenceNumber B16;
+    CARD32 length B32;  /* 0 */
+    CARD32 pad1 B32;
+    CARD32 pad2 B32;
+    CARD32 pad3 B32;
+    CARD32 pad4 B32;
+    CARD32 pad5 B32;
+    CARD32 pad6 B32;
+    } xGrabPointerReply;
+
+typedef xGrabPointerReply xGrabKeyboardReply;
+
+typedef struct {
+    BYTE type;  /* X_Reply */
+    BOOL sameScreen;
+    CARD16 sequenceNumber B16;
+    CARD32 length B32;  /* 0 */
+    Window root B32, child B32;
+    INT16 rootX B16, rootY B16, winX B16, winY B16;
+    CARD16 mask B16;
+    CARD16 pad1 B16;
+    CARD32 pad B32;
+    } xQueryPointerReply;
+
+typedef struct {
+    BYTE type;  /* X_Reply */
+    BYTE pad1;
+    CARD16 sequenceNumber B16;
+    CARD32 length B32;
+    CARD32 nEvents B32;
+    CARD32 pad2 B32;
+    CARD32 pad3 B32;
+    CARD32 pad4 B32;
+    CARD32 pad5 B32;
+    CARD32 pad6 B32;
+    } xGetMotionEventsReply;
+
+typedef struct {
+    BYTE type;  /* X_Reply */
+    BOOL sameScreen;
+    CARD16 sequenceNumber B16;
+    CARD32 length B32; /* 0 */
+    Window child B32;
+    INT16 dstX B16, dstY B16;
+    CARD32 pad2 B32;
+    CARD32 pad3 B32;
+    CARD32 pad4 B32;
+    CARD32 pad5 B32;
+    } xTranslateCoordsReply;
+
+typedef struct {
+    BYTE type;  /* X_Reply */
+    CARD8 revertTo;
+    CARD16 sequenceNumber B16;
+    CARD32 length B32;  /* 0 */
+    Window focus B32;
+    CARD32 pad1 B32;
+    CARD32 pad2 B32;
+    CARD32 pad3 B32;
+    CARD32 pad4 B32;
+    CARD32 pad5 B32;
+    } xGetInputFocusReply;
+
+typedef struct {
+    BYTE type;  /* X_Reply */
+    BYTE pad1;
+    CARD16 sequenceNumber B16;
+    CARD32 length B32;  /* 2, NOT 0; this is an extra-large reply */
+    BYTE map[32];
+    } xQueryKeymapReply;
+
+/* Warning: this MUST match (up to component renaming) xListFontsWithInfoReply */
+typedef struct _xQueryFontReply {
+    BYTE type;  /* X_Reply */
+    BYTE pad1;
+    CARD16 sequenceNumber B16;
+    CARD32 length B32;  /* definitely > 0, even if "nCharInfos" is 0 */
+    xCharInfo minBounds; 
+#ifndef WORD64
+    CARD32 walign1 B32;
+#endif
+    xCharInfo maxBounds; 
+#ifndef WORD64
+    CARD32 walign2 B32;
+#endif
+    CARD16 minCharOrByte2 B16, maxCharOrByte2 B16;
+    CARD16 defaultChar B16;
+    CARD16 nFontProps B16;  /* followed by this many xFontProp structures */
+    CARD8 drawDirection;
+    CARD8 minByte1, maxByte1;
+    BOOL allCharsExist;
+    INT16 fontAscent B16, fontDescent B16;
+    CARD32 nCharInfos B32; /* followed by this many xCharInfo structures */
+} xQueryFontReply;
+
+typedef struct {
+    BYTE type;  /* X_Reply */
+    CARD8 drawDirection;
+    CARD16 sequenceNumber B16;
+    CARD32 length B32;  /* 0 */
+    INT16 fontAscent B16, fontDescent B16;
+    INT16 overallAscent B16, overallDescent B16;
+    INT32 overallWidth B32, overallLeft B32, overallRight B32;
+    CARD32 pad B32;
+    } xQueryTextExtentsReply;
+
+typedef struct {
+    BYTE type;  /* X_Reply */
+    BYTE pad1;
+    CARD16 sequenceNumber B16;
+    CARD32 length B32;
+    CARD16 nFonts B16;
+    CARD16 pad2 B16;
+    CARD32 pad3 B32;
+    CARD32 pad4 B32;
+    CARD32 pad5 B32;
+    CARD32 pad6 B32;
+    CARD32 pad7 B32;
+    } xListFontsReply;
+
+/* Warning: this MUST match (up to component renaming) xQueryFontReply */
+typedef struct {
+    BYTE type;  /* X_Reply */
+    CARD8 nameLength;  /* 0 indicates end-of-reply-sequence */
+    CARD16 sequenceNumber B16;
+    CARD32 length B32;  /* definitely > 0, even if "nameLength" is 0 */
+    xCharInfo minBounds; 
+#ifndef WORD64
+    CARD32 walign1 B32;
+#endif
+    xCharInfo maxBounds; 
+#ifndef WORD64
+    CARD32 walign2 B32;
+#endif
+    CARD16 minCharOrByte2 B16, maxCharOrByte2 B16;
+    CARD16 defaultChar B16;
+    CARD16 nFontProps B16;  /* followed by this many xFontProp structures */
+    CARD8 drawDirection;
+    CARD8 minByte1, maxByte1;
+    BOOL allCharsExist;
+    INT16 fontAscent B16, fontDescent B16;
+    CARD32 nReplies B32;   /* hint as to how many more replies might be coming */
+} xListFontsWithInfoReply;
+
+typedef struct {
+    BYTE type;  /* X_Reply */
+    BYTE pad1;
+    CARD16 sequenceNumber B16;
+    CARD32 length B32;
+    CARD16 nPaths B16;
+    CARD16 pad2 B16;
+    CARD32 pad3 B32;
+    CARD32 pad4 B32;
+    CARD32 pad5 B32;
+    CARD32 pad6 B32;
+    CARD32 pad7 B32;
+    } xGetFontPathReply;
+
+typedef struct {
+    BYTE type;  /* X_Reply */
+    CARD8 depth;
+    CARD16 sequenceNumber B16;
+    CARD32 length B32;
+    VisualID visual B32;
+    CARD32 pad3 B32;
+    CARD32 pad4 B32;
+    CARD32 pad5 B32;
+    CARD32 pad6 B32;
+    CARD32 pad7 B32;
+    } xGetImageReply;
+
+typedef struct {
+    BYTE type;  /* X_Reply */
+    BYTE pad1;
+    CARD16 sequenceNumber B16;
+    CARD32 length B32;
+    CARD16 nColormaps B16;
+    CARD16 pad2 B16;
+    CARD32 pad3 B32;
+    CARD32 pad4 B32;
+    CARD32 pad5 B32;
+    CARD32 pad6 B32;
+    CARD32 pad7 B32;
+    } xListInstalledColormapsReply;
+
+typedef struct {
+    BYTE type; /* X_Reply */
+    BYTE pad1;
+    CARD16 sequenceNumber B16;
+    CARD32 length B32;   /* 0 */
+    CARD16 red B16, green B16, blue B16;
+    CARD16 pad2 B16;
+    CARD32 pixel B32;
+    CARD32 pad3 B32;
+    CARD32 pad4 B32;
+    CARD32 pad5 B32;
+    } xAllocColorReply;
+
+typedef struct {
+    BYTE type; /* X_Reply */
+    BYTE pad1;
+    CARD16 sequenceNumber B16;
+    CARD32 length B32;  /* 0 */
+    CARD32 pixel B32;
+    CARD16 exactRed B16, exactGreen B16, exactBlue B16;
+    CARD16 screenRed B16, screenGreen B16, screenBlue B16;
+    CARD32 pad2 B32;
+    CARD32 pad3 B32;
+    } xAllocNamedColorReply;
+
+typedef struct {
+    BYTE type;  /* X_Reply */
+    BYTE pad1;
+    CARD16 sequenceNumber B16;
+    CARD32 length B32;
+    CARD16 nPixels B16, nMasks B16;
+    CARD32 pad3 B32;
+    CARD32 pad4 B32;
+    CARD32 pad5 B32;
+    CARD32 pad6 B32;
+    CARD32 pad7 B32;
+    } xAllocColorCellsReply;
+
+typedef struct {
+    BYTE type; /* X_Reply */
+    BYTE pad1;
+    CARD16 sequenceNumber B16;
+    CARD32 length B32;
+    CARD16 nPixels B16;
+    CARD16 pad2 B16;
+    CARD32 redMask B32, greenMask B32, blueMask B32;
+    CARD32 pad3 B32;
+    CARD32 pad4 B32;
+    } xAllocColorPlanesReply;
+
+typedef struct {
+    BYTE type; /* X_Reply */
+    BYTE pad1;
+    CARD16 sequenceNumber B16;
+    CARD32 length B32;
+    CARD16 nColors B16;
+    CARD16 pad2 B16;
+    CARD32 pad3 B32;
+    CARD32 pad4 B32;
+    CARD32 pad5 B32;
+    CARD32 pad6 B32;
+    CARD32 pad7 B32;
+    } xQueryColorsReply;
+
+typedef struct {
+    BYTE type;  /* X_Reply */
+    BYTE pad1;
+    CARD16 sequenceNumber B16;
+    CARD32 length B32;  /* 0 */
+    CARD16 exactRed B16, exactGreen B16, exactBlue B16;
+    CARD16 screenRed B16, screenGreen B16, screenBlue B16;
+    CARD32 pad3 B32;
+    CARD32 pad4 B32;
+    CARD32 pad5 B32;
+    } xLookupColorReply;
+
+typedef struct {
+    BYTE type;  /* X_Reply */
+    BYTE pad1;
+    CARD16 sequenceNumber B16;
+    CARD32 length B32;  /* 0 */
+    CARD16 width B16, height B16;
+    CARD32 pad3 B32;
+    CARD32 pad4 B32;
+    CARD32 pad5 B32;
+    CARD32 pad6 B32;
+    CARD32 pad7 B32;
+    } xQueryBestSizeReply;
+
+typedef struct {
+    BYTE type;  /* X_Reply */
+    BYTE pad1;
+    CARD16 sequenceNumber B16;
+    CARD32 length B32; /* 0 */
+    BOOL  present;
+    CARD8 major_opcode;
+    CARD8 first_event;
+    CARD8 first_error;
+    CARD32 pad3 B32;
+    CARD32 pad4 B32;
+    CARD32 pad5 B32;
+    CARD32 pad6 B32;
+    CARD32 pad7 B32;
+    } xQueryExtensionReply;
+
+typedef struct {
+    BYTE type;  /* X_Reply */
+    CARD8 nExtensions;
+    CARD16 sequenceNumber B16;
+    CARD32 length B32;
+    CARD32 pad2 B32;
+    CARD32 pad3 B32;
+    CARD32 pad4 B32;
+    CARD32 pad5 B32;
+    CARD32 pad6 B32;
+    CARD32 pad7 B32;
+    } xListExtensionsReply;
+
+
+typedef struct {
+    BYTE   type;  /* X_Reply */
+    CARD8  success;
+    CARD16 sequenceNumber B16;
+    CARD32 length B32;
+    CARD32 pad2 B32;
+    CARD32 pad3 B32;
+    CARD32 pad4 B32;
+    CARD32 pad5 B32;
+    CARD32 pad6 B32;
+    CARD32 pad7 B32;
+    } xSetMappingReply;
+typedef xSetMappingReply xSetPointerMappingReply;
+typedef xSetMappingReply xSetModifierMappingReply;
+
+typedef struct {
+    BYTE type;  /* X_Reply */
+    CARD8 nElts;  /* how many elements does the map have */
+    CARD16 sequenceNumber B16;
+    CARD32 length B32;
+    CARD32 pad2 B32;
+    CARD32 pad3 B32;
+    CARD32 pad4 B32;
+    CARD32 pad5 B32;
+    CARD32 pad6 B32;
+    CARD32 pad7 B32;
+    } xGetPointerMappingReply;
+
+typedef struct {
+    BYTE type;
+    CARD8 keySymsPerKeyCode;
+    CARD16 sequenceNumber B16;
+    CARD32 length B32;
+    CARD32 pad2 B32;
+    CARD32 pad3 B32;
+    CARD32 pad4 B32;
+    CARD32 pad5 B32;
+    CARD32 pad6 B32;
+    CARD32 pad7 B32;
+} xGetKeyboardMappingReply;    
+
+typedef struct {
+    BYTE type;
+    CARD8 numKeyPerModifier;
+    CARD16 sequenceNumber B16;
+    CARD32 length B32;
+    CARD32 pad1 B32;
+    CARD32 pad2 B32;
+    CARD32 pad3 B32;
+    CARD32 pad4 B32;
+    CARD32 pad5 B32;
+    CARD32 pad6 B32;
+} xGetModifierMappingReply;
+
+typedef struct {
+    BYTE type;  /* X_Reply */
+    BOOL globalAutoRepeat;
+    CARD16 sequenceNumber B16;
+    CARD32 length B32;  /* 5 */
+    CARD32 ledMask B32;
+    CARD8 keyClickPercent, bellPercent;
+    CARD16 bellPitch B16, bellDuration B16;
+    CARD16 pad B16;
+    BYTE map[32];  /* bit masks start here */
+    } xGetKeyboardControlReply;
+
+typedef struct {
+    BYTE type;  /* X_Reply */
+    BYTE pad1;
+    CARD16 sequenceNumber B16;
+    CARD32 length B32;  /* 0 */
+    CARD16 accelNumerator B16, accelDenominator B16;
+    CARD16 threshold B16;
+    CARD16 pad2 B16;
+    CARD32 pad3 B32;
+    CARD32 pad4 B32;
+    CARD32 pad5 B32;
+    CARD32 pad6 B32;
+    } xGetPointerControlReply;
+
+typedef struct {
+    BYTE type;  /* X_Reply */
+    BYTE pad1;
+    CARD16 sequenceNumber B16;
+    CARD32 length B32;  /* 0 */
+    CARD16 timeout B16, interval B16;
+    BOOL preferBlanking;
+    BOOL allowExposures;
+    CARD16 pad2 B16;
+    CARD32 pad3 B32;
+    CARD32 pad4 B32;
+    CARD32 pad5 B32;
+    CARD32 pad6 B32;
+    } xGetScreenSaverReply;
+
+typedef struct {
+    BYTE type;  /* X_Reply */
+    BOOL enabled;
+    CARD16 sequenceNumber B16;
+    CARD32 length B32;
+    CARD16 nHosts B16;
+    CARD16 pad1 B16;
+    CARD32 pad3 B32;
+    CARD32 pad4 B32;
+    CARD32 pad5 B32;
+    CARD32 pad6 B32;
+    CARD32 pad7 B32;
+    } xListHostsReply;
+
+\f
+
+
+/*****************************************************************
+ * Xerror
+ *    All errors  are 32 bytes 
+ *****************************************************************/
+
+typedef struct {
+    BYTE type;                  /* X_Error */
+    BYTE errorCode;
+    CARD16 sequenceNumber B16;       /* the nth request from this client */
+    CARD32 resourceID B32;
+    CARD16 minorCode B16;
+    CARD8 majorCode;
+    BYTE pad1;
+    CARD32 pad3 B32;
+    CARD32 pad4 B32;
+    CARD32 pad5 B32;
+    CARD32 pad6 B32;
+    CARD32 pad7 B32;
+} xError;
+
+/*****************************************************************
+ * xEvent
+ *    All events are 32 bytes
+ *****************************************************************/
+
+typedef struct _xEvent {
+    union {
+       struct {
+           BYTE type;
+           BYTE detail;
+           CARD16 sequenceNumber B16;
+           } u;
+       struct {
+            CARD32 pad00 B32;
+           Time time B32;
+           Window root B32, event B32, child B32;
+           INT16 rootX B16, rootY B16, eventX B16, eventY B16;
+           KeyButMask state B16;
+           BOOL sameScreen;            
+           BYTE pad1;
+       } keyButtonPointer;
+       struct {
+            CARD32 pad00 B32;
+            Time time B32;
+           Window root B32, event B32, child B32;
+           INT16 rootX B16, rootY B16, eventX B16, eventY B16;
+           KeyButMask state B16;
+           BYTE mode;                  /* really XMode */
+           BYTE flags;         /* sameScreen and focus booleans, packed together */
+#define ELFlagFocus        (1<<0)
+#define ELFlagSameScreen   (1<<1)
+       } enterLeave;
+       struct {
+            CARD32 pad00 B32;
+           Window window B32;
+           BYTE mode;                  /* really XMode */
+           BYTE pad1, pad2, pad3;
+       } focus;
+       struct {
+            CARD32 pad00 B32;
+           Window window B32;
+           CARD16 x B16, y B16, width B16, height B16;
+           CARD16 count B16;
+           CARD16 pad2 B16;
+       } expose;
+       struct {
+            CARD32 pad00 B32;
+           Drawable drawable B32;
+           CARD16 x B16, y B16, width B16, height B16;
+           CARD16 minorEvent B16;
+           CARD16 count B16;
+           BYTE majorEvent;
+           BYTE pad1, pad2, pad3;
+       } graphicsExposure;
+       struct {
+            CARD32 pad00 B32;
+           Drawable drawable B32;
+           CARD16 minorEvent B16;
+           BYTE majorEvent;
+           BYTE bpad;
+       } noExposure;
+       struct {
+            CARD32 pad00 B32;
+           Window window B32;
+           CARD8 state;
+           BYTE pad1, pad2, pad3;
+       } visibility;
+       struct {
+            CARD32 pad00 B32;
+           Window parent B32, window B32;
+           INT16 x B16, y B16;
+           CARD16 width B16, height B16, borderWidth B16;
+           BOOL override;
+           BYTE bpad;
+        } createNotify;
+/*
+ * The event feilds in the structures for DestroyNotify, UnmapNotify,
+ * MapNotify, ReparentNotify, ConfigureNotify, CirclulateNotify, GravityNotify,
+ * must be at the same offset because server internal code is depending upon
+ * this to patch up the events before they are delivered.
+ * Also note that MapRequest, ConfigureRequest and CirculateRequest have
+ * the same offset for the event window.
+ */
+       struct {
+            CARD32 pad00 B32;
+           Window event B32, window B32;
+       } destroyNotify;
+       struct {
+            CARD32 pad00 B32;
+           Window event B32, window B32;
+           BOOL fromConfigure;
+           BYTE pad1, pad2, pad3;
+        } unmapNotify;
+       struct {
+            CARD32 pad00 B32;
+           Window event B32, window B32;
+           BOOL override;
+           BYTE pad1, pad2, pad3;
+        } mapNotify;
+       struct {
+            CARD32 pad00 B32;
+           Window parent B32, window B32;
+        } mapRequest;
+       struct {
+            CARD32 pad00 B32;
+           Window event B32, window B32, parent B32;
+           INT16 x B16, y B16;
+           BOOL override;
+           BYTE pad1, pad2, pad3;
+       } reparent;
+       struct {
+            CARD32 pad00 B32;
+           Window event B32, window B32, aboveSibling B32;
+           INT16 x B16, y B16;
+           CARD16 width B16, height B16, borderWidth B16;
+           BOOL override;              
+           BYTE bpad;
+       } configureNotify;
+       struct {
+            CARD32 pad00 B32;
+           Window parent B32, window B32, sibling B32;
+           INT16 x B16, y B16;
+           CARD16 width B16, height B16, borderWidth B16;
+           CARD16 valueMask B16;
+           CARD32 pad1 B32;
+       } configureRequest;
+       struct {
+            CARD32 pad00 B32;
+           Window event B32, window B32;
+           INT16 x B16, y B16;
+           CARD32 pad1 B32, pad2 B32, pad3 B32, pad4 B32;
+       } gravity;
+       struct {
+            CARD32 pad00 B32;
+           Window window B32;
+           CARD16 width B16, height B16;
+       } resizeRequest;
+       struct {
+/* The event field in the circulate record is really the parent when this
+   is used as a CirculateRequest insteaad of a CircluateNotify */
+            CARD32 pad00 B32;
+           Window event B32, window B32, parent B32;
+           BYTE place;                 /* Top or Bottom */
+           BYTE pad1, pad2, pad3;
+       } circulate;
+       struct {
+            CARD32 pad00 B32;
+           Window window B32;
+           Atom atom B32;
+           Time time B32;
+           BYTE state;                 /* NewValue or Deleted */
+           BYTE pad1;
+           CARD16 pad2 B16;
+       } property;
+       struct {
+            CARD32 pad00 B32;
+            Time time B32;     
+           Window window B32;
+           Atom atom B32;
+       } selectionClear;
+       struct {
+            CARD32 pad00 B32;
+            Time time B32;    
+           Window owner B32, requestor B32;
+           Atom selection B32, target B32, property B32;
+       } selectionRequest;
+       struct {
+            CARD32 pad00 B32;
+            Time time B32;   
+           Window requestor B32;
+           Atom selection B32, target B32, property B32;
+       } selectionNotify;
+       struct {
+            CARD32 pad00 B32;
+           Window window B32;
+           Colormap colormap B32;
+#if defined(__cplusplus) || defined(c_plusplus)
+           BOOL c_new;
+#else
+           BOOL new;
+#endif
+           BYTE state;                 /* Installed or UnInstalled */
+           BYTE pad1, pad2;
+       } colormap;
+       struct {
+           CARD32 pad00 B32;
+           CARD8 request;
+           KeyCode firstKeyCode;
+           CARD8 count;
+           BYTE pad1;
+       } mappingNotify;
+       struct {
+            CARD32 pad00 B32;
+           Window window B32;
+           union {
+               struct {
+                   Atom type B32;
+                   INT32 longs0 B32;
+                   INT32 longs1 B32;
+                   INT32 longs2 B32;
+                   INT32 longs3 B32;
+                   INT32 longs4 B32;
+               } l;
+               struct {
+                   Atom type B32;
+                   INT16 shorts0 B16;
+                   INT16 shorts1 B16;
+                   INT16 shorts2 B16;
+                   INT16 shorts3 B16;
+                   INT16 shorts4 B16;
+                   INT16 shorts5 B16;
+                   INT16 shorts6 B16;
+                   INT16 shorts7 B16;
+                   INT16 shorts8 B16;
+                   INT16 shorts9 B16;
+               } s;
+               struct {
+                   Atom type B32;
+                   INT8 bytes[20];
+               } b;
+           } u; 
+       } clientMessage;
+    } u;
+} xEvent;
+
+/* KeymapNotify events are not included in the above union because they
+   are different from all other events: they do not have a "detail"
+   or "sequenceNumber", so there is room for a 248-bit key mask. */
+
+typedef struct {
+    BYTE type;
+    BYTE map[31];
+    } xKeymapEvent;
+
+#define XEventSize (sizeof(xEvent))
+
+/* XReply is the union of all the replies above whose "fixed part"
+fits in 32 bytes.  It does NOT include GetWindowAttributesReply,
+QueryFontReply, QueryKeymapReply, or GetKeyboardControlReply 
+ListFontsWithInfoReply */
+
+typedef union {
+    xGenericReply generic;
+    xGetGeometryReply geom;
+    xQueryTreeReply tree;
+    xInternAtomReply atom;
+    xGetAtomNameReply atomName;
+    xGetPropertyReply property;
+    xListPropertiesReply listProperties;
+    xGetSelectionOwnerReply selection;
+    xGrabPointerReply grabPointer;
+    xGrabKeyboardReply grabKeyboard;
+    xQueryPointerReply pointer;
+    xGetMotionEventsReply motionEvents;
+    xTranslateCoordsReply coords;
+    xGetInputFocusReply inputFocus;
+    xQueryTextExtentsReply textExtents;
+    xListFontsReply fonts;
+    xGetFontPathReply fontPath;
+    xGetImageReply image;
+    xListInstalledColormapsReply colormaps;
+    xAllocColorReply allocColor;
+    xAllocNamedColorReply allocNamedColor;
+    xAllocColorCellsReply colorCells;
+    xAllocColorPlanesReply colorPlanes;
+    xQueryColorsReply colors;
+    xLookupColorReply lookupColor;
+    xQueryBestSizeReply bestSize;
+    xQueryExtensionReply extension;
+    xListExtensionsReply extensions;
+    xSetModifierMappingReply setModifierMapping;
+    xGetModifierMappingReply getModifierMapping;
+    xSetPointerMappingReply setPointerMapping;
+    xGetKeyboardMappingReply getKeyboardMapping;
+    xGetPointerMappingReply getPointerMapping;
+    xGetPointerControlReply pointerControl;
+    xGetScreenSaverReply screenSaver;
+    xListHostsReply hosts;
+    xError error;
+    xEvent event;
+} xReply;
+
+\f
+
+/*****************************************************************
+ * REQUESTS
+ *****************************************************************/
+
+
+/* Request structure */
+
+typedef struct _xReq {
+       CARD8 reqType;
+       CARD8 data;            /* meaning depends on request type */
+       CARD16 length B16;         /* length in 4 bytes quantities 
+                                 of whole request, including this header */
+} xReq;
+
+/*****************************************************************
+ *  structures that follow request. 
+ *****************************************************************/
+
+/* ResourceReq is used for any request which has a resource ID 
+   (or Atom or Time) as its one and only argument.  */
+
+typedef struct {
+    CARD8 reqType;
+    BYTE pad;
+    CARD16 length B16;
+    CARD32 id B32;  /* a Window, Drawable, Font, GContext, Pixmap, etc. */
+    } xResourceReq;
+
+typedef struct {
+    CARD8 reqType;
+    CARD8 depth;
+    CARD16 length B16;
+    Window wid B32, parent B32;
+    INT16 x B16, y B16;
+    CARD16 width B16, height B16, borderWidth B16;  
+#if defined(__cplusplus) || defined(c_plusplus)
+    CARD16 c_class B16;
+#else
+    CARD16 class B16;
+#endif
+    VisualID visual B32;
+    CARD32 mask B32;
+} xCreateWindowReq;
+
+typedef struct {
+    CARD8 reqType;
+    BYTE pad;
+    CARD16 length B16;
+    Window window B32;
+    CARD32 valueMask B32; 
+} xChangeWindowAttributesReq;
+
+typedef struct {
+    CARD8 reqType;
+    BYTE mode;
+    CARD16 length B16;
+    Window window B32;
+} xChangeSaveSetReq;
+
+typedef struct {
+    CARD8 reqType;
+    BYTE pad;
+    CARD16 length B16;
+    Window window B32, parent B32;
+    INT16 x B16, y B16;
+} xReparentWindowReq;
+
+typedef struct {
+    CARD8 reqType;
+    CARD8 pad;
+    CARD16 length B16;
+    Window window B32;
+    CARD16 mask B16;
+    CARD16 pad2 B16;
+} xConfigureWindowReq;
+
+typedef struct {
+    CARD8 reqType;
+    CARD8 direction;
+    CARD16 length B16;
+    Window window B32;
+} xCirculateWindowReq;
+
+typedef struct {    /* followed by padded string */
+    CARD8 reqType;
+    BOOL onlyIfExists;
+    CARD16 length B16;
+    CARD16 nbytes  B16;    /* number of bytes in string */
+    CARD16 pad B16;
+} xInternAtomReq;
+
+typedef struct {
+    CARD8 reqType;
+    CARD8 mode;
+    CARD16 length B16;
+    Window window B32;
+    Atom property B32, type B32;
+    CARD8 format;
+    BYTE pad[3];
+    CARD32 nUnits B32;     /* length of stuff following, depends on format */
+} xChangePropertyReq;
+
+typedef struct {
+    CARD8 reqType;
+    BYTE pad;
+    CARD16 length B16;
+    Window window B32;
+    Atom property B32;
+} xDeletePropertyReq;
+
+typedef struct {
+    CARD8 reqType;
+#if defined(__cplusplus) || defined(c_plusplus)
+    BOOL c_delete;
+#else
+    BOOL delete;
+#endif
+    CARD16 length B16;
+    Window window B32;
+    Atom property B32, type B32;
+    CARD32 longOffset B32;
+    CARD32 longLength B32;
+} xGetPropertyReq;
+typedef struct {
+    CARD8 reqType;
+    BYTE pad;
+    CARD16 length B16;
+    Window window B32;
+    Atom selection B32;
+    Time time B32;
+} xSetSelectionOwnerReq;
+
+typedef struct {
+    CARD8 reqType;
+    BYTE pad;
+    CARD16 length B16;
+    Window requestor B32;
+    Atom selection B32, target B32, property B32;
+    Time time B32;
+    } xConvertSelectionReq;
+
+typedef struct {
+    CARD8 reqType;
+    BOOL propagate;
+    CARD16 length B16;
+    Window destination B32;
+    CARD32 eventMask B32;
+#ifdef WORD64
+    /* the structure should have been quad-aligned */
+    BYTE eventdata[SIZEOF(xEvent)];
+#else
+    xEvent event;
+#endif /* WORD64 */
+} xSendEventReq;
+
+typedef struct {
+    CARD8 reqType;
+    BOOL ownerEvents;
+    CARD16 length B16;
+    Window grabWindow B32;
+    CARD16 eventMask B16;
+    BYTE pointerMode, keyboardMode;
+    Window confineTo B32;
+    Cursor cursor B32;
+    Time time B32;
+} xGrabPointerReq;
+
+typedef struct {
+    CARD8 reqType;
+    BOOL ownerEvents;
+    CARD16 length B16;
+    Window grabWindow B32;
+    CARD16 eventMask B16;
+    BYTE pointerMode, keyboardMode;
+    Window confineTo B32;
+    Cursor cursor B32;
+    CARD8 button;
+    BYTE pad;
+    CARD16 modifiers B16;
+} xGrabButtonReq;
+
+typedef struct {
+    CARD8 reqType;
+    CARD8 button;
+    CARD16 length B16;
+    Window grabWindow B32;
+    CARD16 modifiers B16;
+    CARD16 pad B16;
+} xUngrabButtonReq;
+
+typedef struct {
+    CARD8 reqType;
+    BYTE pad;
+    CARD16 length B16;
+    Cursor cursor B32;
+    Time time B32;
+    CARD16 eventMask B16;
+    CARD16 pad2 B16;
+} xChangeActivePointerGrabReq;
+
+typedef struct {
+    CARD8 reqType;
+    BOOL ownerEvents;
+    CARD16 length B16;
+    Window grabWindow B32;
+    Time time B32;
+    BYTE pointerMode, keyboardMode;  
+    CARD16 pad B16;
+} xGrabKeyboardReq;
+
+typedef struct {
+    CARD8 reqType;
+    BOOL ownerEvents;
+    CARD16 length B16;
+    Window grabWindow B32;
+    CARD16 modifiers B16;
+    CARD8 key;
+    BYTE pointerMode, keyboardMode;  
+    BYTE pad1, pad2, pad3;
+} xGrabKeyReq;
+
+typedef struct {
+    CARD8 reqType;
+    CARD8 key;
+    CARD16 length B16;
+    Window grabWindow B32;
+    CARD16 modifiers B16;
+    CARD16 pad B16;
+} xUngrabKeyReq;
+
+typedef struct {
+    CARD8 reqType;
+    CARD8 mode;
+    CARD16 length B16;
+    Time time B32;
+} xAllowEventsReq;
+
+typedef struct {
+    CARD8 reqType;
+    BYTE pad;
+    CARD16 length B16;
+    Window window B32;
+    Time start B32, stop B32;
+} xGetMotionEventsReq;
+
+typedef struct {
+    CARD8 reqType;
+    BYTE pad;
+    CARD16 length B16;
+    Window srcWid B32, dstWid B32;
+    INT16 srcX B16, srcY B16;
+} xTranslateCoordsReq;
+
+typedef struct {
+    CARD8 reqType;
+    BYTE pad;
+    CARD16 length B16;
+    Window srcWid B32, dstWid B32;
+    INT16 srcX B16, srcY B16;
+    CARD16 srcWidth B16, srcHeight B16;
+    INT16 dstX B16, dstY B16;
+} xWarpPointerReq;
+
+typedef struct {
+    CARD8 reqType;
+    CARD8 revertTo;
+    CARD16 length B16;
+    Window focus B32;
+    Time time B32;
+} xSetInputFocusReq;
+
+typedef struct {
+    CARD8 reqType;
+    BYTE pad;
+    CARD16 length B16;
+    Font fid B32;
+    CARD16 nbytes B16;
+    BYTE pad1, pad2;   /* string follows on word boundary */
+} xOpenFontReq;
+
+typedef struct {
+    CARD8 reqType;
+    BOOL oddLength;
+    CARD16 length B16;
+    Font fid B32;
+    } xQueryTextExtentsReq;
+
+typedef struct {
+    CARD8 reqType;
+    BYTE pad;
+    CARD16 length B16;
+    CARD16 maxNames B16;
+    CARD16 nbytes B16;  /* followed immediately by string bytes */
+} xListFontsReq;
+
+typedef xListFontsReq xListFontsWithInfoReq;
+
+typedef struct {
+    CARD8 reqType;
+    BYTE pad;
+    CARD16 length B16;
+    CARD16 nFonts B16;
+    BYTE pad1, pad2;   /* LISTofSTRING8 follows on word boundary */
+} xSetFontPathReq;
+
+typedef struct {
+    CARD8 reqType;
+    CARD8 depth;
+    CARD16 length B16;
+    Pixmap pid B32;
+    Drawable drawable B32;
+    CARD16 width B16, height B16;
+} xCreatePixmapReq;
+
+typedef struct {
+    CARD8 reqType;
+    BYTE pad;
+    CARD16 length B16;
+    GContext gc B32;
+    Drawable drawable B32;
+    CARD32 mask B32;
+} xCreateGCReq;
+
+typedef struct {
+    CARD8 reqType;
+    BYTE pad;
+    CARD16 length B16;
+    GContext gc B32;
+    CARD32 mask B32;
+} xChangeGCReq;    
+
+typedef struct {
+    CARD8 reqType;
+    BYTE pad;
+    CARD16 length B16;
+    GContext srcGC B32, dstGC B32;
+    CARD32 mask B32;
+} xCopyGCReq;    
+
+typedef struct {
+    CARD8 reqType;
+    BYTE pad;
+    CARD16 length B16;
+    GContext gc B32;
+    CARD16 dashOffset B16;
+    CARD16 nDashes B16;        /* length LISTofCARD8 of values following */
+} xSetDashesReq;    
+
+typedef struct {
+    CARD8 reqType;
+    BYTE ordering;
+    CARD16 length B16;
+    GContext gc B32;
+    INT16 xOrigin B16, yOrigin B16;
+} xSetClipRectanglesReq;    
+
+typedef struct {
+    CARD8 reqType;
+    BOOL exposures;
+    CARD16 length B16;
+    Window window B32;
+    INT16 x B16, y B16;
+    CARD16 width B16, height B16;
+} xClearAreaReq;
+
+typedef struct {
+    CARD8 reqType;
+    BYTE pad;
+    CARD16 length B16;
+    Drawable srcDrawable B32, dstDrawable B32;
+    GContext gc B32;
+    INT16 srcX B16, srcY B16, dstX B16, dstY B16;
+    CARD16 width B16, height B16;
+} xCopyAreaReq;    
+
+typedef struct {
+    CARD8 reqType;
+    BYTE pad;
+    CARD16 length B16;
+    Drawable srcDrawable B32, dstDrawable B32;
+    GContext gc B32;
+    INT16 srcX B16, srcY B16, dstX B16, dstY B16;
+    CARD16 width B16, height B16;
+    CARD32 bitPlane B32;
+} xCopyPlaneReq;    
+
+typedef struct {
+    CARD8 reqType;
+    BYTE coordMode;
+    CARD16 length B16;
+    Drawable drawable B32;
+    GContext gc B32;
+} xPolyPointReq;    
+
+typedef xPolyPointReq xPolyLineReq;  /* same request structure */
+
+/* The following used for PolySegment, PolyRectangle, PolyArc, PolyFillRectangle, PolyFillArc */
+
+typedef struct {
+    CARD8 reqType;
+    BYTE pad;
+    CARD16 length B16;
+    Drawable drawable B32;
+    GContext gc B32;
+} xPolySegmentReq;    
+
+typedef xPolySegmentReq xPolyArcReq;
+typedef xPolySegmentReq xPolyRectangleReq;
+typedef xPolySegmentReq xPolyFillRectangleReq;
+typedef xPolySegmentReq xPolyFillArcReq;
+
+typedef struct _FillPolyReq {
+    CARD8 reqType;
+    BYTE pad;
+    CARD16 length B16;
+    Drawable drawable B32;
+    GContext gc B32;
+    BYTE shape;
+    BYTE coordMode;
+    CARD16 pad1 B16;
+} xFillPolyReq;    
+
+
+typedef struct _PutImageReq {
+    CARD8 reqType;
+    CARD8 format;
+    CARD16 length B16;
+    Drawable drawable B32;
+    GContext gc B32;
+    CARD16 width B16, height B16;
+    INT16 dstX B16, dstY B16;
+    CARD8 leftPad;
+    CARD8 depth;
+    CARD16 pad B16;
+} xPutImageReq;    
+
+typedef struct {
+    CARD8 reqType;
+    CARD8 format;
+    CARD16 length B16;
+    Drawable drawable B32;
+    INT16 x B16, y B16;
+    CARD16 width B16, height B16;
+    CARD32 planeMask B32;
+} xGetImageReq;    
+
+/* the folloiwng used by PolyText8 and PolyText16 */
+
+typedef struct {
+    CARD8 reqType;
+    CARD8 pad;
+    CARD16 length B16;
+    Drawable drawable B32;
+    GContext gc B32;
+    INT16 x B16, y B16;                /* items (xTextElt) start after struct */
+} xPolyTextReq;    
+
+typedef xPolyTextReq xPolyText8Req;
+typedef xPolyTextReq xPolyText16Req;
+
+typedef struct {
+    CARD8 reqType;
+    BYTE nChars;
+    CARD16 length B16;
+    Drawable drawable B32;
+    GContext gc B32;
+    INT16 x B16, y B16;
+} xImageTextReq;    
+
+typedef xImageTextReq xImageText8Req;
+typedef xImageTextReq xImageText16Req;
+
+typedef struct {
+    CARD8 reqType;
+    BYTE alloc;
+    CARD16 length B16;
+    Colormap mid B32;
+    Window window B32;
+    VisualID visual B32;
+} xCreateColormapReq;    
+
+typedef struct {
+    CARD8 reqType;
+    BYTE pad;
+    CARD16 length B16;
+    Colormap mid B32;
+    Colormap srcCmap B32;
+} xCopyColormapAndFreeReq;    
+
+typedef struct {
+    CARD8 reqType;
+    BYTE pad;
+    CARD16 length B16;
+    Colormap cmap B32;
+    CARD16 red B16, green B16, blue B16;
+    CARD16 pad2 B16;
+} xAllocColorReq;    
+
+typedef struct {
+    CARD8 reqType;
+    BYTE pad;
+    CARD16 length B16;
+    Colormap cmap B32;
+    CARD16 nbytes B16;  /* followed by structure */
+    BYTE pad1, pad2;
+} xAllocNamedColorReq;    
+
+typedef struct {
+    CARD8 reqType;
+    BOOL contiguous;
+    CARD16 length B16;
+    Colormap cmap B32;
+    CARD16 colors B16, planes B16;
+} xAllocColorCellsReq;    
+
+typedef struct {
+    CARD8 reqType;
+    BOOL contiguous;
+    CARD16 length B16;
+    Colormap cmap B32;
+    CARD16 colors B16, red B16, green B16, blue B16;
+} xAllocColorPlanesReq;    
+
+typedef struct {
+    CARD8 reqType;
+    BYTE pad;
+    CARD16 length B16;
+    Colormap cmap B32;
+    CARD32 planeMask B32;
+} xFreeColorsReq;    
+
+typedef struct {
+    CARD8 reqType;
+    BYTE pad;
+    CARD16 length B16;
+    Colormap cmap B32;
+} xStoreColorsReq;    
+
+typedef struct {
+    CARD8 reqType;
+    CARD8 flags;   /* DoRed, DoGreen, DoBlue, as in xColorItem */
+    CARD16 length B16;
+    Colormap cmap B32;
+    CARD32 pixel B32;
+    CARD16 nbytes B16;  /* number of name string bytes following structure */
+    BYTE pad1, pad2;
+    } xStoreNamedColorReq;
+
+typedef struct {
+    CARD8 reqType;
+    BYTE pad;
+    CARD16 length B16;
+    Colormap cmap B32;
+} xQueryColorsReq;    
+
+typedef struct {    /* followed  by string of length len */
+    CARD8 reqType;
+    BYTE pad;
+    CARD16 length B16;
+    Colormap cmap B32;
+    CARD16 nbytes B16;  /* number of string bytes following structure*/
+    BYTE pad1, pad2;
+} xLookupColorReq;    
+
+typedef struct {
+    CARD8 reqType;
+    BYTE pad;
+    CARD16 length B16;
+    Cursor cid B32;
+    Pixmap source B32, mask B32;
+    CARD16 foreRed B16, foreGreen B16, foreBlue B16;
+    CARD16 backRed B16, backGreen B16, backBlue B16;
+    CARD16 x B16, y B16;
+} xCreateCursorReq;    
+
+typedef struct {
+    CARD8 reqType;
+    BYTE pad;
+    CARD16 length B16;
+    Cursor cid B32;
+    Font source B32, mask B32;
+    CARD16 sourceChar B16, maskChar B16;
+    CARD16 foreRed B16, foreGreen B16, foreBlue B16;
+    CARD16 backRed B16, backGreen B16, backBlue B16;
+} xCreateGlyphCursorReq;    
+
+typedef struct {
+    CARD8 reqType;
+    BYTE pad;
+    CARD16 length B16;
+    Cursor cursor B32;
+    CARD16 foreRed B16, foreGreen B16, foreBlue B16;
+    CARD16 backRed B16, backGreen B16, backBlue B16;
+} xRecolorCursorReq;    
+
+typedef struct {
+    CARD8 reqType;
+#if defined(__cplusplus) || defined(c_plusplus)
+    CARD8 c_class;
+#else
+    CARD8 class;
+#endif
+    CARD16 length B16;
+    Drawable drawable B32;
+    CARD16 width B16, height B16;
+} xQueryBestSizeReq;    
+
+typedef struct {
+    CARD8 reqType;
+    BYTE pad;
+    CARD16 length B16;
+    CARD16 nbytes B16;  /* number of string bytes following structure */
+    BYTE pad1, pad2;
+} xQueryExtensionReq;
+
+typedef struct {
+    CARD8   reqType;
+    CARD8   numKeyPerModifier;
+    CARD16  length B16;
+} xSetModifierMappingReq;
+
+typedef struct {
+    CARD8 reqType;
+    CARD8 nElts;  /* how many elements in the map */
+    CARD16 length B16;
+} xSetPointerMappingReq;
+
+typedef struct {
+    CARD8 reqType;
+    BYTE pad;
+    CARD16 length B16;
+    KeyCode firstKeyCode;
+    CARD8 count;
+    CARD16 pad1 B16;
+} xGetKeyboardMappingReq;    
+
+typedef struct {
+    CARD8 reqType;
+    CARD8 keyCodes;
+    CARD16 length B16;
+    KeyCode firstKeyCode;
+    CARD8 keySymsPerKeyCode;
+    CARD16 pad1 B16;
+} xChangeKeyboardMappingReq;
+
+typedef struct {
+    CARD8 reqType;
+    BYTE pad;
+    CARD16 length B16;
+    CARD32 mask B32;
+} xChangeKeyboardControlReq;    
+
+typedef struct {
+    CARD8 reqType;
+    INT8 percent;  /* -100 to 100 */
+    CARD16 length B16;
+} xBellReq;    
+
+typedef struct {
+    CARD8 reqType;
+    BYTE pad;
+    CARD16 length B16;
+    INT16 accelNum B16, accelDenum B16;
+    INT16 threshold B16;             
+    BOOL doAccel, doThresh;
+} xChangePointerControlReq;    
+
+typedef struct {
+    CARD8 reqType;
+    BYTE pad;
+    CARD16 length B16;
+    INT16 timeout B16, interval B16;
+    BYTE preferBlank, allowExpose;  
+    CARD16 pad2 B16;
+} xSetScreenSaverReq;    
+
+typedef struct {
+    CARD8 reqType;
+    BYTE mode;
+    CARD16 length B16;
+    CARD8 hostFamily;
+    BYTE pad;
+    CARD16 hostLength B16;
+} xChangeHostsReq;    
+
+typedef struct {
+    CARD8 reqType;
+    BYTE pad;
+    CARD16 length B16;
+    } xListHostsReq;
+
+typedef struct {
+    CARD8 reqType;
+    BYTE mode;
+    CARD16 length B16;
+    } xChangeModeReq;
+
+typedef xChangeModeReq xSetAccessControlReq;
+typedef xChangeModeReq xSetCloseDownModeReq;
+typedef xChangeModeReq xForceScreenSaverReq;
+
+typedef struct { /* followed by LIST of ATOM */
+    CARD8 reqType;
+    BYTE pad;
+    CARD16 length B16;
+    Window window B32;
+    CARD16 nAtoms B16;
+    INT16 nPositions B16;
+    } xRotatePropertiesReq;
+    
+\f
+
+/* Reply codes */
+
+#define X_Reply                1               /* Normal reply */
+#define X_Error                0               /* Error */
+
+/* Request codes */
+
+#define X_CreateWindow                  1              
+#define X_ChangeWindowAttributes        2        
+#define X_GetWindowAttributes           3     
+#define X_DestroyWindow                 4
+#define X_DestroySubwindows             5   
+#define X_ChangeSaveSet                 6
+#define X_ReparentWindow                7
+#define X_MapWindow                     8
+#define X_MapSubwindows                 9
+#define X_UnmapWindow                  10
+#define X_UnmapSubwindows              11  
+#define X_ConfigureWindow              12  
+#define X_CirculateWindow              13  
+#define X_GetGeometry                  14
+#define X_QueryTree                    15
+#define X_InternAtom                   16
+#define X_GetAtomName                  17
+#define X_ChangeProperty               18 
+#define X_DeleteProperty               19 
+#define X_GetProperty                  20
+#define X_ListProperties               21 
+#define X_SetSelectionOwner            22    
+#define X_GetSelectionOwner            23    
+#define X_ConvertSelection             24   
+#define X_SendEvent                    25
+#define X_GrabPointer                  26
+#define X_UngrabPointer                27
+#define X_GrabButton                   28
+#define X_UngrabButton                 29
+#define X_ChangeActivePointerGrab      30          
+#define X_GrabKeyboard                 31
+#define X_UngrabKeyboard               32 
+#define X_GrabKey                      33
+#define X_UngrabKey                    34
+#define X_AllowEvents                  35       
+#define X_GrabServer                   36      
+#define X_UngrabServer                 37        
+#define X_QueryPointer                 38        
+#define X_GetMotionEvents              39           
+#define X_TranslateCoords              40                
+#define X_WarpPointer                  41       
+#define X_SetInputFocus                42         
+#define X_GetInputFocus                43         
+#define X_QueryKeymap                  44       
+#define X_OpenFont                     45    
+#define X_CloseFont                    46     
+#define X_QueryFont                    47
+#define X_QueryTextExtents             48     
+#define X_ListFonts                    49  
+#define X_ListFontsWithInfo                   50 
+#define X_SetFontPath                  51 
+#define X_GetFontPath                  52 
+#define X_CreatePixmap                 53        
+#define X_FreePixmap                   54      
+#define X_CreateGC                     55    
+#define X_ChangeGC                     56    
+#define X_CopyGC                       57  
+#define X_SetDashes                    58     
+#define X_SetClipRectangles            59             
+#define X_FreeGC                       60  
+#define X_ClearArea                    61             
+#define X_CopyArea                     62    
+#define X_CopyPlane                    63     
+#define X_PolyPoint                    64     
+#define X_PolyLine                     65    
+#define X_PolySegment                  66       
+#define X_PolyRectangle                67         
+#define X_PolyArc                      68   
+#define X_FillPoly                     69    
+#define X_PolyFillRectangle            70             
+#define X_PolyFillArc                  71       
+#define X_PutImage                     72    
+#define X_GetImage                     73 
+#define X_PolyText8                    74     
+#define X_PolyText16                   75      
+#define X_ImageText8                   76      
+#define X_ImageText16                  77       
+#define X_CreateColormap               78          
+#define X_FreeColormap                 79        
+#define X_CopyColormapAndFree          80               
+#define X_InstallColormap              81           
+#define X_UninstallColormap            82             
+#define X_ListInstalledColormaps       83                  
+#define X_AllocColor                   84      
+#define X_AllocNamedColor              85           
+#define X_AllocColorCells              86           
+#define X_AllocColorPlanes             87            
+#define X_FreeColors                   88      
+#define X_StoreColors                  89       
+#define X_StoreNamedColor              90           
+#define X_QueryColors                  91       
+#define X_LookupColor                  92       
+#define X_CreateCursor                 93        
+#define X_CreateGlyphCursor            94             
+#define X_FreeCursor                   95      
+#define X_RecolorCursor                96         
+#define X_QueryBestSize                97         
+#define X_QueryExtension               98          
+#define X_ListExtensions               99          
+#define X_ChangeKeyboardMapping        100
+#define X_GetKeyboardMapping           101
+#define X_ChangeKeyboardControl        102                
+#define X_GetKeyboardControl           103             
+#define X_Bell                         104
+#define X_ChangePointerControl         105
+#define X_GetPointerControl            106
+#define X_SetScreenSaver               107          
+#define X_GetScreenSaver               108          
+#define X_ChangeHosts                  109       
+#define X_ListHosts                    110     
+#define X_SetAccessControl             111               
+#define X_SetCloseDownMode             112
+#define X_KillClient                   113 
+#define X_RotateProperties            114
+#define X_ForceScreenSaver            115
+#define X_SetPointerMapping            116
+#define X_GetPointerMapping            117
+#define X_SetModifierMapping          118
+#define X_GetModifierMapping          119
+#define X_NoOperation                  127
+
+/* restore these definitions back to the typedefs in X.h */
+#undef Window
+#undef Drawable
+#undef Font
+#undef Pixmap
+#undef Cursor
+#undef Colormap
+#undef GContext
+#undef Atom
+#undef VisualID
+#undef Time
+#undef KeyCode
+#undef KeySym
+
+#endif /* XPROTO_H */
diff --git a/Xserver/include/Xprotostr.h b/Xserver/include/Xprotostr.h
new file mode 100644 (file)
index 0000000..8d213dc
--- /dev/null
@@ -0,0 +1,79 @@
+/* $XConsortium: Xprotostr.h,v 1.5 94/04/17 20:10:53 rws Exp $ */
+#ifndef XPROTOSTRUCTS_H
+#define XPROTOSTRUCTS_H
+
+/***********************************************************
+
+Copyright (c) 1987  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+
+Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
+
+                        All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and its 
+documentation for any purpose and without fee is hereby granted, 
+provided that the above copyright notice appear in all copies and that
+both that copyright notice and this permission notice appear in 
+supporting documentation, and that the name of Digital not be
+used in advertising or publicity pertaining to distribution of the
+software without specific, written prior permission.  
+
+DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
+ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
+DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
+ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+SOFTWARE.
+
+******************************************************************/
+#include <X11/Xmd.h>
+
+/* Used by PolySegment */
+
+typedef struct _xSegment {
+    INT16 x1 B16, y1 B16, x2 B16, y2 B16;
+} xSegment;
+
+/* POINT */
+
+typedef struct _xPoint {
+       INT16           x B16, y B16;
+} xPoint;
+
+typedef struct _xRectangle {
+    INT16 x B16, y B16;
+    CARD16  width B16, height B16;
+} xRectangle;
+
+/*  ARC  */
+
+typedef struct _xArc {
+    INT16 x B16, y B16;
+    CARD16   width B16, height B16;
+    INT16   angle1 B16, angle2 B16;
+} xArc;
+
+#endif /* XPROTOSTRUCTS_H */
diff --git a/Xserver/include/Xthreads.h b/Xserver/include/Xthreads.h
new file mode 100644 (file)
index 0000000..884c857
--- /dev/null
@@ -0,0 +1,292 @@
+/*
+ * $XConsortium: Xthreads.h /main/35 1996/12/04 10:23:02 lehors $
+ * $XFree86: xc/include/Xthreads.h,v 3.3 1996/12/23 05:58:11 dawes Exp $
+ *
+ * 
+Copyright (c) 1993  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+ * *
+ */
+
+#ifndef _XTHREADS_H_
+#define _XTHREADS_H_
+
+/* Redefine these to XtMalloc/XtFree or whatever you want before including
+ * this header file.
+ */
+#ifndef xmalloc
+#define xmalloc malloc
+#endif
+#ifndef xfree
+#define xfree free
+#endif
+
+#ifdef CTHREADS
+#include <cthreads.h>
+typedef cthread_t xthread_t;
+typedef struct condition xcondition_rec;
+typedef struct mutex xmutex_rec;
+#define xthread_init() cthread_init()
+#define xthread_self cthread_self
+#define xthread_fork(func,closure) cthread_fork(func,closure)
+#define xthread_yield() cthread_yield()
+#define xthread_exit(v) cthread_exit(v)
+#define xthread_set_name(t,str) cthread_set_name(t,str)
+#define xmutex_init(m) mutex_init(m)
+#define xmutex_clear(m) mutex_clear(m)
+#define xmutex_lock(m) mutex_lock(m)
+#define xmutex_unlock(m) mutex_unlock(m)
+#define xmutex_set_name(m,str) mutex_set_name(m,str)
+#define xcondition_init(cv) condition_init(cv)
+#define xcondition_clear(cv) condition_clear(cv)
+#define xcondition_wait(cv,m) condition_wait(cv,m)
+#define xcondition_signal(cv) condition_signal(cv)
+#define xcondition_broadcast(cv) condition_broadcast(cv)
+#define xcondition_set_name(cv,str) condition_set_name(cv,str)
+#else /* !CTHREADS */
+#if defined(SVR4) && !defined(__sgi)
+#include <thread.h>
+#include <synch.h>
+#ifndef LINE_MAX
+#define LINE_MAX 2048
+#endif
+typedef thread_t xthread_t;
+typedef thread_key_t xthread_key_t;
+typedef cond_t xcondition_rec;
+typedef mutex_t xmutex_rec;
+#define xthread_self thr_self
+#define xthread_fork(func,closure) thr_create(NULL,0,func,closure,THR_NEW_LWP|THR_DETACHED,NULL)
+#define xthread_yield() thr_yield()
+#define xthread_exit(v) thr_exit(v)
+#define xthread_key_create(kp,d) thr_keycreate(kp,d)
+#ifdef sun
+#define xthread_key_delete(k) 0
+#else
+#define xthread_key_delete(k) thr_keydelete(k)
+#endif
+#define xthread_set_specific(k,v) thr_setspecific(k,v)
+#define xthread_get_specific(k,vp) thr_getspecific(k,vp)
+#define XMUTEX_INITIALIZER {0}
+#define xmutex_init(m) mutex_init(m,USYNC_THREAD,0)
+#define xmutex_clear(m) mutex_destroy(m)
+#define xmutex_lock(m) mutex_lock(m)
+#define xmutex_unlock(m) mutex_unlock(m)
+#define xcondition_init(cv) cond_init(cv,USYNC_THREAD,0)
+#define xcondition_clear(cv) cond_destroy(cv)
+#define xcondition_wait(cv,m) cond_wait(cv,m)
+#define xcondition_signal(cv) cond_signal(cv)
+#define xcondition_broadcast(cv) cond_broadcast(cv)
+#else /* !SVR4 */
+#ifdef WIN32
+#define BOOL wBOOL
+#ifdef Status
+#undef Status
+#define Status wStatus
+#endif
+#include <windows.h>
+#ifdef Status
+#undef Status
+#define Status int
+#endif
+#undef BOOL
+typedef DWORD xthread_t;
+typedef DWORD xthread_key_t;
+struct _xthread_waiter {
+    HANDLE sem;
+    struct _xthread_waiter *next;
+};
+typedef struct {
+    CRITICAL_SECTION cs;
+    struct _xthread_waiter *waiters;
+} xcondition_rec;
+typedef CRITICAL_SECTION xmutex_rec;
+#define xthread_init() _Xthread_init()
+#define xthread_self GetCurrentThreadId
+#define xthread_fork(func,closure) { \
+    DWORD _tmptid; \
+    CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)func, (LPVOID)closure, 0, \
+                &_tmptid); \
+}
+#define xthread_yield() Sleep(0)
+#define xthread_exit(v) ExitThread((DWORD)(v))
+#define xthread_key_create(kp,d) *(kp) = TlsAlloc()
+#define xthread_key_delete(k) TlsFree(k)
+#define xthread_set_specific(k,v) TlsSetValue(k,v)
+#define xthread_get_specific(k,vp) TlsGetValue(k)
+#define xmutex_init(m) InitializeCriticalSection(m)
+#define xmutex_clear(m) DeleteCriticalSection(m)
+#define _XMUTEX_NESTS
+#define xmutex_lock(m) EnterCriticalSection(m)
+#define xmutex_unlock(m) LeaveCriticalSection(m)
+#define xcondition_init(cv) { \
+    InitializeCriticalSection(&(cv)->cs); \
+    (cv)->waiters = NULL; \
+}
+#define xcondition_clear(cv) DeleteCriticalSection(&(cv)->cs)
+extern struct _xthread_waiter *_Xthread_waiter();
+#define xcondition_wait(cv,m) { \
+    struct _xthread_waiter *_tmpthr = _Xthread_waiter(); \
+    EnterCriticalSection(&(cv)->cs); \
+    _tmpthr->next = (cv)->waiters; \
+    (cv)->waiters = _tmpthr; \
+    LeaveCriticalSection(&(cv)->cs); \
+    LeaveCriticalSection(m); \
+    WaitForSingleObject(_tmpthr->sem, INFINITE); \
+    EnterCriticalSection(m); \
+}
+#define xcondition_signal(cv) { \
+    EnterCriticalSection(&(cv)->cs); \
+    if ((cv)->waiters) { \
+        ReleaseSemaphore((cv)->waiters->sem, 1, NULL); \
+       (cv)->waiters = (cv)->waiters->next; \
+    } \
+    LeaveCriticalSection(&(cv)->cs); \
+}
+#define xcondition_broadcast(cv) { \
+    struct _xthread_waiter *_tmpthr; \
+    EnterCriticalSection(&(cv)->cs); \
+    for (_tmpthr = (cv)->waiters; _tmpthr; _tmpthr = _tmpthr->next) \
+       ReleaseSemaphore(_tmpthr->sem, 1, NULL); \
+    (cv)->waiters = NULL; \
+    LeaveCriticalSection(&(cv)->cs); \
+}
+#else /* !WIN32 */
+#ifdef USE_TIS_SUPPORT
+/*
+ * TIS support is intended for thread safe libraries.
+ * This should not be used for general client programming.
+ */
+#include <tis.h>
+typedef pthread_t xthread_t;
+typedef pthread_key_t xthread_key_t;
+typedef pthread_cond_t xcondition_rec;
+typedef pthread_mutex_t xmutex_rec;
+#define xthread_self tis_self
+#define xthread_fork(func,closure) { pthread_t _tmpxthr; \
+        pthread_create(&_tmpxthr,NULL,func,closure); }
+#define xthread_yield() pthread_yield_np()
+#define xthread_exit(v) pthread_exit(v)
+#define xthread_key_create(kp,d) tis_key_create(kp,d)
+#define xthread_key_delete(k) tis_key_delete(k)
+#define xthread_set_specific(k,v) tis_setspecific(k,v)
+#define xthread_get_specific(k,vp) *(vp) = tis_getspecific(k)
+#define XMUTEX_INITIALIZER PTHREAD_MUTEX_INITIALIZER
+#define xmutex_init(m) tis_mutex_init(m)
+#define xmutex_clear(m) tis_mutex_destroy(m)
+#define xmutex_lock(m) tis_mutex_lock(m)
+#define xmutex_unlock(m) tis_mutex_unlock(m)
+#define xcondition_init(c) tis_cond_init(c)
+#define xcondition_clear(c) tis_cond_destroy(c)
+#define xcondition_wait(c,m) tis_cond_wait(c,m)
+#define xcondition_signal(c) tis_cond_signal(c)
+#define xcondition_broadcast(c) tis_cond_broadcast(c)
+#else
+#include <pthread.h>
+#ifndef LINE_MAX
+#define LINE_MAX 2048
+#endif
+typedef pthread_t xthread_t;
+typedef pthread_key_t xthread_key_t;
+typedef pthread_cond_t xcondition_rec;
+typedef pthread_mutex_t xmutex_rec;
+#define xthread_self pthread_self
+#define xthread_yield() pthread_yield()
+#define xthread_exit(v) pthread_exit(v)
+#define xthread_set_specific(k,v) pthread_setspecific(k,v)
+#define xmutex_clear(m) pthread_mutex_destroy(m)
+#define xmutex_lock(m) pthread_mutex_lock(m)
+#define xmutex_unlock(m) pthread_mutex_unlock(m)
+#ifndef XPRE_STANDARD_API
+#define xthread_key_create(kp,d) pthread_key_create(kp,d)
+#define xthread_key_delete(k) pthread_key_delete(k)
+#define xthread_get_specific(k,vp) *(vp) = pthread_getspecific(k)
+#define xthread_fork(func,closure) { pthread_t _tmpxthr; \
+       pthread_create(&_tmpxthr,NULL,func,closure); }
+#define XMUTEX_INITIALIZER PTHREAD_MUTEX_INITIALIZER
+#define xmutex_init(m) pthread_mutex_init(m, NULL)
+#define xcondition_init(c) pthread_cond_init(c, NULL)
+#else /* XPRE_STANDARD_API */
+#define xthread_key_create(kp,d) pthread_keycreate(kp,d)
+#define xthread_key_delete(k) 0
+#define xthread_get_specific(k,vp) pthread_getspecific(k,vp)
+#define xthread_fork(func,closure) { pthread_t _tmpxthr; \
+       pthread_create(&_tmpxthr,pthread_attr_default,func,closure); }
+#define xmutex_init(m) pthread_mutex_init(m, pthread_mutexattr_default)
+#define xcondition_init(c) pthread_cond_init(c, pthread_condattr_default)
+#endif /* XPRE_STANDARD_API */
+#define xcondition_clear(c) pthread_cond_destroy(c)
+#define xcondition_wait(c,m) pthread_cond_wait(c,m)
+#define xcondition_signal(c) pthread_cond_signal(c)
+#define xcondition_broadcast(c) pthread_cond_broadcast(c)
+#if defined(_DECTHREADS_) || defined(linux)
+static xthread_t _X_no_thread_id;
+#define xthread_have_id(id) !pthread_equal(id, _X_no_thread_id)
+#define xthread_clear_id(id) id = _X_no_thread_id
+#define xthread_equal(id1,id2) pthread_equal(id1, id2)
+#endif /* _DECTHREADS_ || linux */
+#if _CMA_VENDOR_ == _CMA__IBM
+#ifdef DEBUG                   /* too much of a hack to enable normally */
+/* see also cma__obj_set_name() */
+#define xmutex_set_name(m,str) ((char**)(m)->field1)[5] = (str)
+#define xcondition_set_name(cv,str) ((char**)(cv)->field1)[5] = (str)
+#endif /* DEBUG */
+#endif /* _CMA_VENDOR_ == _CMA__IBM */
+#endif /* USE_TIS_SUPPORT */
+#endif /* WIN32 */
+#endif /* SVR4 */
+#endif /* CTHREADS */
+typedef xcondition_rec *xcondition_t;
+typedef xmutex_rec *xmutex_t;
+#ifndef xcondition_malloc
+#define xcondition_malloc() (xcondition_t)xmalloc(sizeof(xcondition_rec))
+#endif
+#ifndef xcondition_free
+#define xcondition_free(c) xfree((char *)c)
+#endif
+#ifndef xmutex_malloc
+#define xmutex_malloc() (xmutex_t)xmalloc(sizeof(xmutex_rec))
+#endif
+#ifndef xmutex_free
+#define xmutex_free(m) xfree((char *)m)
+#endif
+#ifndef xthread_have_id
+#define xthread_have_id(id) id
+#endif
+#ifndef xthread_clear_id
+#define xthread_clear_id(id) id = 0
+#endif
+#ifndef xthread_equal
+#define xthread_equal(id1,id2) ((id1) == (id2))
+#endif
+/* aids understood by some debuggers */
+#ifndef xthread_set_name
+#define xthread_set_name(t,str)
+#endif
+#ifndef xmutex_set_name
+#define xmutex_set_name(m,str)
+#endif
+#ifndef xcondition_set_name
+#define xcondition_set_name(cv,str)
+#endif
+
+#endif /* _XTHREADS_H_ */
diff --git a/Xserver/include/Xw32defs.h b/Xserver/include/Xw32defs.h
new file mode 100644 (file)
index 0000000..3fb3e4c
--- /dev/null
@@ -0,0 +1,74 @@
+/* $XConsortium: Xw32defs.h /main/5 1996/11/13 14:43:44 lehors $ */
+
+#ifndef _XW32DEFS_H
+#define  _XW32DEFS_H
+
+typedef char *caddr_t;
+
+#define access    _access
+#define alloca    _alloca
+#define chdir  _chdir
+#define chmod     _chmod
+#define close     _close
+#define creat     _creat
+#define dup       _dup
+#define dup2      _dup2
+#define environ     _environ
+#define execl   _execl
+#define execle  _execle
+#define execlp  _execlp
+#define execlpe  _execlpe
+#define execv   _execv
+#define execve  _execve
+#define execvp  _execvp
+#define execvpe  _execvpe
+#define fdopen   _fdopen
+#define fileno   _fileno
+#define fstat   _fstat
+#define getcwd _getcwd
+#define getpid  _getpid
+#define hypot          _hypot
+#define isascii __isascii
+#define isatty    _isatty
+#define lseek     _lseek
+#define mkdir  _mkdir
+#define mktemp    _mktemp
+#define open      _open
+#define putenv     _putenv
+#define read      _read
+#define rmdir  _rmdir
+#define sleep(x) _sleep((x) * 1000)
+#define stat    _stat
+#define sys_errlist _sys_errlist
+#define sys_nerr    _sys_nerr
+#define umask     _umask
+#define unlink    _unlink
+#define write     _write
+#define random   rand
+#define srandom  srand
+
+#define O_RDONLY    _O_RDONLY
+#define O_WRONLY    _O_WRONLY
+#define O_RDWR     _O_RDWR
+#define O_APPEND    _O_APPEND
+#define O_CREAT     _O_CREAT
+#define O_TRUNC     _O_TRUNC
+#define O_EXCL     _O_EXCL
+#define O_TEXT     _O_TEXT
+#define O_BINARY    _O_BINARY
+#define O_RAW      _O_BINARY
+
+#define S_IFMT  _S_IFMT
+#define S_IFDIR  _S_IFDIR
+#define S_IFCHR  _S_IFCHR
+#define S_IFREG  _S_IFREG
+#define S_IREAD  _S_IREAD
+#define S_IWRITE _S_IWRITE
+#define S_IEXEC  _S_IEXEC
+
+#define        F_OK    0
+#define        X_OK    1
+#define        W_OK    2
+#define        R_OK    4
+
+#endif
diff --git a/Xserver/include/Xwinsock.h b/Xserver/include/Xwinsock.h
new file mode 100644 (file)
index 0000000..8f7d5b2
--- /dev/null
@@ -0,0 +1,52 @@
+/* $XConsortium: Xwinsock.h /main/1 1996/11/13 14:43:47 lehors $ */
+/*
+
+Copyright (C) 1996 X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a
+copy of this software and associated documentation files (the "Soft-
+ware"), to deal in the Software without restriction, including without
+limitation the rights to use, copy, modify, merge, publish, distribute,
+sublicense, and/or sell copies of the Software, and to permit persons to
+whom the Software is furnished to do so, subject to the following condi-
+tions:
+
+The above copyright notice and this permission notice shall be included
+in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL-
+ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT
+SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABIL-
+ITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall
+not be used in advertising or otherwise to promote the sale, use or
+other dealings in this Software without prior written authorization from
+the X Consortium.
+
+*/
+
+/*
+ * This header file has for sole purpose to allow to include winsock.h
+ * without getting any name conflicts with our code.
+ * Conflicts come from the fact that including winsock.h actually pulls
+ * in the whole Windows API...
+ */
+
+#define BOOL wBOOL
+#undef Status
+#define Status wStatus
+#define ATOM wATOM
+#define FreeResource wFreeResource
+#include <winsock.h>
+#undef Status
+#define Status int
+#undef BOOL
+#undef ATOM
+#undef FreeResource
+#undef CreateWindowA
+#undef RT_FONT
+#undef RT_CURSOR
diff --git a/Xserver/include/ap_keysym.h b/Xserver/include/ap_keysym.h
new file mode 100644 (file)
index 0000000..9a11971
--- /dev/null
@@ -0,0 +1,51 @@
+/******************************************************************
+Copyright 1987 by Apollo Computer Inc., Chelmsford, Massachusetts.
+Copyright 1989 by Hewlett-Packard Company.
+
+                        All Rights Reserved
+
+Permission to use, duplicate, change, and distribute this software and
+its documentation for any purpose and without fee is granted, provided
+that the above copyright notice appear in such copy and that this
+copyright notice appear in all supporting documentation, and that the
+names of Apollo Computer Inc., the Hewlett-Packard Company, or the X
+Consortium not be used in advertising or publicity pertaining to
+distribution of the software without written prior permission.
+
+HEWLETT-PACKARD MAKES NO WARRANTY OF ANY KIND WITH REGARD
+TO THIS SOFWARE, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 
+PURPOSE.  Hewlett-Packard shall not be liable for errors 
+contained herein or direct, indirect, special, incidental or 
+consequential damages in connection with the furnishing, 
+performance, or use of this material.
+
+This software is not subject to any license of the American
+Telephone and Telegraph Company or of the Regents of the
+University of California.
+******************************************************************/
+
+#define apXK_LineDel            0x1000FF00
+#define apXK_CharDel            0x1000FF01
+#define apXK_Copy               0x1000FF02
+#define apXK_Cut                0x1000FF03
+#define apXK_Paste              0x1000FF04
+#define apXK_Move               0x1000FF05
+#define apXK_Grow               0x1000FF06
+#define apXK_Cmd                0x1000FF07
+#define apXK_Shell              0x1000FF08
+#define apXK_LeftBar            0x1000FF09
+#define apXK_RightBar           0x1000FF0A
+#define apXK_LeftBox            0x1000FF0B
+#define apXK_RightBox           0x1000FF0C
+#define apXK_UpBox              0x1000FF0D
+#define apXK_DownBox            0x1000FF0E
+#define apXK_Pop                0x1000FF0F
+#define apXK_Read               0x1000FF10
+#define apXK_Edit               0x1000FF11
+#define apXK_Save               0x1000FF12
+#define apXK_Exit               0x1000FF13
+#define apXK_Repeat             0x1000FF14
+
+#define apXK_KP_parenleft       0x1000FFA8
+#define apXK_KP_parenright      0x1000FFA9
diff --git a/Xserver/include/bitmaps/1x1 b/Xserver/include/bitmaps/1x1
new file mode 100644 (file)
index 0000000..6d013d4
--- /dev/null
@@ -0,0 +1,6 @@
+#define 1x1_width 16
+#define 1x1_height 16
+static char 1x1_bits[] = {
+   0xff, 0xff, 0x55, 0x55, 0xff, 0xff, 0x55, 0x55, 0xff, 0xff, 0x55, 0x55,
+   0xff, 0xff, 0x55, 0x55, 0xff, 0xff, 0x55, 0x55, 0xff, 0xff, 0x55, 0x55,
+   0xff, 0xff, 0x55, 0x55, 0xff, 0xff, 0x55, 0x55};
diff --git a/Xserver/include/bitmaps/2x2 b/Xserver/include/bitmaps/2x2
new file mode 100644 (file)
index 0000000..8490457
--- /dev/null
@@ -0,0 +1,6 @@
+#define 2x2_width 16
+#define 2x2_height 16
+static char 2x2_bits[] = {
+   0xff, 0xff, 0xff, 0xff, 0x33, 0x33, 0x33, 0x33, 0xff, 0xff, 0xff, 0xff,
+   0x33, 0x33, 0x33, 0x33, 0xff, 0xff, 0xff, 0xff, 0x33, 0x33, 0x33, 0x33,
+   0xff, 0xff, 0xff, 0xff, 0x33, 0x33, 0x33, 0x33};
diff --git a/Xserver/include/bitmaps/Imakefile b/Xserver/include/bitmaps/Imakefile
new file mode 100644 (file)
index 0000000..013439e
--- /dev/null
@@ -0,0 +1,79 @@
+XCOMM $XConsortium: Imakefile /main/32 1996/09/28 16:17:53 rws $
+
+HEADERS = \
+       1x1 \
+       2x2 \
+       black \
+       boxes \
+       calculator \
+       cntr_ptr \
+       cntr_ptrmsk \
+       cross_weave \
+       dimple1 \
+       dimple3 \
+       dot \
+       dropbar7 \
+       dropbar8 \
+       escherknot \
+       flagdown \
+       flagup \
+       flipped_gray \
+       gray \
+       gray1 \
+       gray3 \
+       grid2 \
+       grid4 \
+       grid8 \
+       grid16 \
+       hlines2 \
+       hlines3 \
+       icon \
+       keyboard16 \
+       left_ptr \
+       left_ptrmsk \
+       letters \
+       light_gray \
+       mailempty \
+       mailemptymsk \
+       mailfull \
+       mailfullmsk \
+       mensetmanus \
+       menu6 \
+       menu8 \
+       menu10 \
+       menu12 \
+       menu16 \
+       noletters \
+       opendot \
+       opendotMask \
+       plaid \
+       right_ptr \
+       right_ptrmsk \
+       root_weave \
+       scales \
+       sipb \
+       star \
+       starMask \
+       stipple \
+       target \
+       terminal \
+       tie_fighter \
+       vlines2 \
+       vlines3 \
+       weird_size \
+       wide_weave \
+       wingdogs \
+       woman \
+       xfd_icon \
+       xlogo11 \
+       xlogo16 \
+       xlogo32 \
+       xlogo64 \
+       xsnow
+
+
+all::
+
+BuildIncludes($(HEADERS),X11/bitmaps,../..)
+
+InstallMultipleFlags($(HEADERS),$(INCDIR)/X11/bitmaps,$(INSTINCFLAGS))
diff --git a/Xserver/include/bitmaps/black b/Xserver/include/bitmaps/black
new file mode 100644 (file)
index 0000000..3a1ec90
--- /dev/null
@@ -0,0 +1,6 @@
+#define black_width 16
+#define black_height 16
+static char black_bits[] = {
+   0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+   0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+   0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
diff --git a/Xserver/include/bitmaps/boxes b/Xserver/include/bitmaps/boxes
new file mode 100644 (file)
index 0000000..0deb801
--- /dev/null
@@ -0,0 +1,6 @@
+#define boxes_width 16
+#define boxes_height 16
+static char boxes_bits[] = {
+   0x0f, 0x0f, 0x09, 0x09, 0x09, 0x09, 0x0f, 0x0f, 0xf0, 0xf0, 0x90, 0x90,
+   0x90, 0x90, 0xf0, 0xf0, 0x0f, 0x0f, 0x09, 0x09, 0x09, 0x09, 0x0f, 0x0f,
+   0xf0, 0xf0, 0x90, 0x90, 0x90, 0x90, 0xf0, 0xf0};
diff --git a/Xserver/include/bitmaps/calculator b/Xserver/include/bitmaps/calculator
new file mode 100644 (file)
index 0000000..2be3b9d
--- /dev/null
@@ -0,0 +1,19 @@
+#define icon_width 28
+#define icon_height 48
+static char icon_bits[] = {
+   0xff, 0xff, 0xff, 0x0f, 0xff, 0xff, 0xff, 0x0f, 0x03, 0x00, 0x00, 0x0c,
+   0xd3, 0x5d, 0x5d, 0x0c, 0x13, 0x51, 0x45, 0x0c, 0xd3, 0xdd, 0xdd, 0x0d,
+   0x53, 0x10, 0x51, 0x0d, 0xd3, 0x1d, 0xdd, 0x0d, 0x03, 0x00, 0x00, 0x0c,
+   0xff, 0xff, 0xff, 0x0f, 0xff, 0xff, 0xff, 0x0f, 0x01, 0x00, 0x00, 0x08,
+   0xbd, 0xf7, 0xde, 0x0b, 0xbd, 0xf7, 0xde, 0x0b, 0x01, 0x00, 0x00, 0x08,
+   0xbd, 0xf7, 0xde, 0x0b, 0xa5, 0x94, 0x52, 0x0a, 0xbd, 0xf7, 0xde, 0x0b,
+   0x01, 0x00, 0x00, 0x08, 0xbd, 0xf7, 0xde, 0x0b, 0xbd, 0xf7, 0xde, 0x0b,
+   0xbd, 0xf7, 0xde, 0x0b, 0x01, 0x00, 0x00, 0x08, 0xbd, 0xf7, 0xde, 0x0b,
+   0xbd, 0xf7, 0xde, 0x0b, 0xbd, 0xf7, 0xde, 0x0b, 0x01, 0x00, 0x00, 0x08,
+   0xbd, 0xf7, 0xde, 0x0b, 0xbd, 0x94, 0xd2, 0x0b, 0xbd, 0x94, 0xd2, 0x0b,
+   0xbd, 0xf7, 0xde, 0x0b, 0x01, 0x00, 0x00, 0x08, 0xbd, 0xf7, 0xde, 0x0b,
+   0xbd, 0x94, 0xd2, 0x0b, 0xbd, 0x94, 0xd2, 0x0b, 0xbd, 0xf7, 0xde, 0x0b,
+   0x01, 0x00, 0x00, 0x08, 0xbd, 0xf7, 0xde, 0x0b, 0xbd, 0x94, 0xd2, 0x0b,
+   0xbd, 0x94, 0xd2, 0x0b, 0xbd, 0xf7, 0xde, 0x0b, 0x01, 0x00, 0x00, 0x08,
+   0xbd, 0xff, 0xde, 0x0b, 0xbd, 0x80, 0xd2, 0x0b, 0xbd, 0x80, 0xd2, 0x0b,
+   0xbd, 0xff, 0xde, 0x0b, 0x01, 0x00, 0x00, 0x08, 0xff, 0xff, 0xff, 0x0f};
diff --git a/Xserver/include/bitmaps/cntr_ptr b/Xserver/include/bitmaps/cntr_ptr
new file mode 100644 (file)
index 0000000..eddb25f
--- /dev/null
@@ -0,0 +1,8 @@
+#define cntr_ptr_width 16
+#define cntr_ptr_height 16
+#define cntr_ptr_x_hot 7
+#define cntr_ptr_y_hot 1
+static char cntr_ptr_bits[] = {
+   0x00, 0x00, 0x80, 0x01, 0x80, 0x01, 0xc0, 0x03, 0xc0, 0x03, 0xe0, 0x07,
+   0xe0, 0x07, 0xf0, 0x0f, 0xf0, 0x0f, 0x98, 0x19, 0x88, 0x11, 0x80, 0x01,
+   0x80, 0x01, 0x80, 0x01, 0x80, 0x01, 0x00, 0x00};
diff --git a/Xserver/include/bitmaps/cntr_ptrmsk b/Xserver/include/bitmaps/cntr_ptrmsk
new file mode 100644 (file)
index 0000000..d3607a4
--- /dev/null
@@ -0,0 +1,6 @@
+#define cntr_ptrmsk_width 16
+#define cntr_ptrmsk_height 16
+static char cntr_ptrmsk_bits[] = {
+   0xc0, 0x03, 0xc0, 0x03, 0xe0, 0x07, 0xe0, 0x07, 0xf0, 0x0f, 0xf0, 0x0f,
+   0xf8, 0x1f, 0xf8, 0x1f, 0xfc, 0x3f, 0xfc, 0x3f, 0xfc, 0x3f, 0xdc, 0x3b,
+   0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03};
diff --git a/Xserver/include/bitmaps/cross_weave b/Xserver/include/bitmaps/cross_weave
new file mode 100644 (file)
index 0000000..40de9e4
--- /dev/null
@@ -0,0 +1,6 @@
+#define cross_weave_width 16
+#define cross_weave_height 16
+static char cross_weave_bits[] = {
+   0x55, 0x55, 0x88, 0x88, 0x55, 0x55, 0x22, 0x22, 0x55, 0x55, 0x88, 0x88,
+   0x55, 0x55, 0x22, 0x22, 0x55, 0x55, 0x88, 0x88, 0x55, 0x55, 0x22, 0x22,
+   0x55, 0x55, 0x88, 0x88, 0x55, 0x55, 0x22, 0x22};
diff --git a/Xserver/include/bitmaps/dimple1 b/Xserver/include/bitmaps/dimple1
new file mode 100644 (file)
index 0000000..9144605
--- /dev/null
@@ -0,0 +1,6 @@
+#define dimple1_width 16
+#define dimple1_height 16
+static char dimple1_bits[] = {
+   0x55, 0x55, 0x00, 0x00, 0x55, 0x55, 0x00, 0x00, 0x55, 0x55, 0x00, 0x00,
+   0x55, 0x55, 0x00, 0x00, 0x55, 0x55, 0x00, 0x00, 0x55, 0x55, 0x00, 0x00,
+   0x55, 0x55, 0x00, 0x00, 0x55, 0x55, 0x00, 0x00};
diff --git a/Xserver/include/bitmaps/dimple3 b/Xserver/include/bitmaps/dimple3
new file mode 100644 (file)
index 0000000..209b4e8
--- /dev/null
@@ -0,0 +1,6 @@
+#define dimple3_width 16
+#define dimple3_height 16
+static char dimple3_bits[] = {
+   0x11, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x11, 0x11, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x11, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x11, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
diff --git a/Xserver/include/bitmaps/dot b/Xserver/include/bitmaps/dot
new file mode 100644 (file)
index 0000000..e403eeb
--- /dev/null
@@ -0,0 +1,6 @@
+#define dot_width 16
+#define dot_height 16
+static char dot_bits[] = {
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x03, 0xf0, 0x0f, 0xf0, 0x0f,
+   0xf8, 0x1f, 0xf8, 0x1f, 0xf8, 0x1f, 0xf8, 0x1f, 0xf0, 0x0f, 0xf0, 0x0f,
+   0xc0, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
diff --git a/Xserver/include/bitmaps/dropbar7 b/Xserver/include/bitmaps/dropbar7
new file mode 100644 (file)
index 0000000..2689300
--- /dev/null
@@ -0,0 +1,4 @@
+#define bar7_width 7
+#define bar7_height 7
+static char bar7_bits[] = {
+   0x00, 0x3f, 0x61, 0x61, 0x7f, 0x7e, 0x00};
diff --git a/Xserver/include/bitmaps/dropbar8 b/Xserver/include/bitmaps/dropbar8
new file mode 100644 (file)
index 0000000..d7cfdeb
--- /dev/null
@@ -0,0 +1,4 @@
+#define dropbar8_width 8
+#define dropbar8_height 8
+static char dropbar8_bits[] = {
+   0x00, 0x7f, 0xc1, 0xc1, 0xc1, 0xff, 0xfe, 0x00};
diff --git a/Xserver/include/bitmaps/escherknot b/Xserver/include/bitmaps/escherknot
new file mode 100644 (file)
index 0000000..80bc471
--- /dev/null
@@ -0,0 +1,473 @@
+#define escherknot_width 216
+#define escherknot_height 208
+
+static char escherknot_bits[] = {
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfa, 0x5f,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0xf0, 0x6f, 0xf6, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0xc0, 0xff, 0x3a, 0x13, 0xff, 0x01, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x0d, 0x02, 0x51, 0x71, 0x0e, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x2f, 0x20, 0xd9, 0x88,
+ 0x9b, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x82,
+ 0xac, 0x44, 0x4e, 0x1c, 0xf3, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x1e, 0x40, 0x02, 0x44, 0x60, 0xe2, 0xfc, 0x06, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x80, 0x25, 0x09, 0x90, 0x22, 0x13, 0xb7, 0x9a, 0x1e,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x00, 0x00, 0x40, 0x10, 0x89,
+ 0x18, 0xe3, 0x3b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1c, 0x04, 0x08,
+ 0x01, 0x10, 0xc8, 0xa8, 0xd5, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x83, 0x80, 0x20, 0x40, 0x82, 0x00, 0x66, 0x9c, 0xec, 0x01, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0xc0, 0x00, 0x00, 0x00, 0x08, 0x08, 0x24, 0x12, 0x93, 0x5b,
+ 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x70, 0x12, 0x80, 0x04, 0x01, 0x00, 0x80,
+ 0x19, 0x33, 0xfa, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x80, 0x80, 0x00,
+ 0x20, 0x08, 0x12, 0xc4, 0x68, 0x26, 0x1c, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03,
+ 0x02, 0x04, 0x24, 0x00, 0x01, 0x40, 0x24, 0x8c, 0xcd, 0x3f, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00,
+ 0x00, 0x80, 0x49, 0x10, 0x90, 0x00, 0x21, 0x20, 0x08, 0x11, 0x43, 0xd9,
+ 0x7e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe8,
+ 0xff, 0xff, 0x0b, 0x00, 0x60, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x80, 0x30, 0xb9, 0xf2, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0xc0, 0x97, 0x04, 0x08, 0xfe, 0x05, 0x30, 0x10, 0x12, 0x20, 0x20,
+ 0x04, 0x00, 0x80, 0x48, 0x0c, 0xa3, 0xff, 0x01, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x3e, 0x92, 0x20, 0x49, 0x40, 0x3e, 0x0e, 0x82,
+ 0x00, 0x84, 0x25, 0x01, 0x80, 0x00, 0x80, 0xc8, 0x34, 0xed, 0x03, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x25, 0x01, 0x04, 0x01, 0x08,
+ 0xd0, 0x17, 0x00, 0x80, 0x25, 0x01, 0xad, 0x04, 0x12, 0x20, 0x23, 0x4c,
+ 0x6a, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x5c, 0x02, 0x48,
+ 0x92, 0x20, 0x41, 0x92, 0x9e, 0x80, 0x24, 0x24, 0x29, 0x00, 0x04, 0x00,
+ 0x10, 0x98, 0xcc, 0xff, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80,
+ 0x4f, 0x10, 0x01, 0x90, 0x24, 0x40, 0x12, 0xf0, 0x00, 0x24, 0x41, 0x0b,
+ 0xa9, 0x10, 0x00, 0x00, 0x04, 0xd9, 0x96, 0x0e, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0xe0, 0x00, 0x92, 0x48, 0x02, 0x04, 0x09, 0xc0, 0x84, 0x8f,
+ 0x29, 0x2d, 0xf8, 0xa9, 0x02, 0x00, 0x00, 0x20, 0x90, 0xf4, 0x1e, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x98, 0x24, 0x91, 0x04, 0x50, 0x22, 0x24,
+ 0x1b, 0x12, 0x7a, 0x48, 0xca, 0x03, 0x21, 0x10, 0x00, 0x00, 0x48, 0x93,
+ 0xff, 0x3b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x9e, 0x24, 0x92, 0x20,
+ 0x81, 0xda, 0x24, 0xc8, 0x16, 0xd0, 0xe7, 0x50, 0xd2, 0xbf, 0x03, 0x00,
+ 0x80, 0x00, 0x30, 0x29, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x03,
+ 0x20, 0x80, 0x24, 0x41, 0x12, 0x2a, 0x41, 0xb2, 0x80, 0x33, 0x0e, 0x7e,
+ 0x88, 0x1c, 0x01, 0x00, 0xa0, 0x24, 0x69, 0x75, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0xe0, 0x82, 0x44, 0x11, 0x24, 0x09, 0x90, 0xa4, 0x4d, 0xd2, 0x92,
+ 0x9e, 0xd3, 0x83, 0x6b, 0x62, 0x00, 0x00, 0x10, 0x22, 0xff, 0x7f, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x30, 0x42, 0x04, 0x92, 0x24, 0x6b, 0x53, 0x32,
+ 0x59, 0x90, 0x16, 0xfa, 0xb4, 0xf4, 0xff, 0x0f, 0x01, 0x00, 0x90, 0x68,
+ 0x4a, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x28, 0x90, 0x24, 0x11, 0x24,
+ 0x49, 0xda, 0x82, 0xc5, 0x92, 0xd2, 0xd0, 0x9e, 0x1e, 0x00, 0x78, 0x0a,
+ 0x00, 0x00, 0x05, 0xd2, 0xfa, 0x00, 0x00, 0x00, 0x00, 0x00, 0x4c, 0x02,
+ 0x44, 0xb2, 0x65, 0xea, 0x49, 0x9e, 0x2c, 0x4b, 0x1a, 0xd2, 0xeb, 0xe3,
+ 0xff, 0xc7, 0x09, 0x00, 0x20, 0x68, 0xff, 0xd6, 0x01, 0x00, 0x00, 0x00,
+ 0x00, 0x0b, 0x90, 0x40, 0x92, 0x24, 0x09, 0x5f, 0xd2, 0x64, 0x59, 0x72,
+ 0x56, 0x7f, 0xfd, 0xdf, 0x1f, 0x12, 0x00, 0x20, 0x49, 0x92, 0xde, 0x01,
+ 0x00, 0x00, 0x00, 0x80, 0x41, 0x92, 0x4c, 0x92, 0x24, 0x25, 0xc9, 0x8b,
+ 0x2e, 0xcb, 0x92, 0x4b, 0x5a, 0x2f, 0x75, 0xf4, 0x04, 0x00, 0x00, 0x41,
+ 0xf6, 0x74, 0x01, 0x00, 0x00, 0x00, 0x40, 0x49, 0x02, 0x00, 0xba, 0xb6,
+ 0xfd, 0x49, 0xf8, 0x74, 0x6d, 0x4b, 0x72, 0xed, 0xdb, 0xff, 0xcf, 0x53,
+ 0x00, 0x00, 0x48, 0xb6, 0xd7, 0x03, 0x00, 0x00, 0x00, 0x60, 0x48, 0x10,
+ 0xc9, 0x93, 0x24, 0x00, 0x7b, 0xc3, 0xa6, 0x69, 0x58, 0x5a, 0xfb, 0xfa,
+ 0xa5, 0xbe, 0x16, 0x00, 0x00, 0x92, 0xa4, 0xfd, 0x03, 0x00, 0x00, 0x00,
+ 0x30, 0x01, 0x20, 0x5d, 0xa2, 0xfe, 0x7f, 0x01, 0x4f, 0x1a, 0xcd, 0x6b,
+ 0x6a, 0xa9, 0x5f, 0xff, 0xf3, 0x24, 0x01, 0x40, 0xc0, 0xb4, 0xf4, 0x03,
+ 0x00, 0x00, 0x00, 0x2c, 0x88, 0x84, 0x89, 0xb6, 0x00, 0x24, 0x7d, 0x69,
+ 0xf2, 0x34, 0xad, 0x99, 0x2d, 0xf7, 0xff, 0x9f, 0x4b, 0x00, 0x00, 0x92,
+ 0xa6, 0xad, 0x07, 0x00, 0x00, 0x00, 0x06, 0x91, 0x24, 0xe9, 0xa4, 0xfd,
+ 0xa5, 0xa9, 0x4b, 0x93, 0xe7, 0x34, 0x63, 0xf9, 0xfc, 0xd5, 0xef, 0x16,
+ 0x00, 0x40, 0x90, 0xb4, 0xbd, 0x07, 0x00, 0x00, 0x00, 0x6a, 0x80, 0x4c,
+ 0x96, 0xbe, 0x2d, 0xfd, 0x2f, 0x7c, 0x5e, 0x9c, 0x67, 0xad, 0xa5, 0xfd,
+ 0xff, 0xbf, 0x29, 0x00, 0x00, 0x92, 0x76, 0xed, 0x06, 0x00, 0x00, 0x00,
+ 0x05, 0x12, 0x48, 0x53, 0x25, 0x65, 0x25, 0xf4, 0xe5, 0xd3, 0x72, 0x9c,
+ 0x35, 0xdf, 0xf6, 0x7f, 0xf5, 0x56, 0x00, 0x00, 0x92, 0xa4, 0xed, 0x0f,
+ 0x00, 0x00, 0x80, 0x49, 0x20, 0x59, 0x38, 0xec, 0xff, 0xff, 0xad, 0x2f,
+ 0x5d, 0xd3, 0x33, 0xe6, 0x24, 0xed, 0xff, 0xdf, 0x2d, 0x01, 0x40, 0x80,
+ 0x24, 0xbd, 0x07, 0x00, 0x00, 0xc0, 0x48, 0x24, 0x49, 0x87, 0x37, 0x21,
+ 0xa0, 0xbd, 0xf4, 0x79, 0x4f, 0xc7, 0x9c, 0xde, 0xf6, 0xff, 0xff, 0x5b,
+ 0x08, 0x00, 0x92, 0xfc, 0xe9, 0x0e, 0x00, 0x00, 0x20, 0x89, 0x40, 0xd3,
+ 0xf4, 0x49, 0xff, 0xff, 0xe7, 0x2f, 0xcf, 0x79, 0x9c, 0x53, 0xb2, 0x35,
+ 0xff, 0xff, 0x37, 0x00, 0x40, 0x90, 0x24, 0xef, 0x0e, 0x00, 0x00, 0x30,
+ 0x91, 0x49, 0x32, 0x2d, 0xff, 0x6b, 0xb7, 0xbd, 0xbc, 0x3c, 0xef, 0x79,
+ 0xce, 0xde, 0xd6, 0xfd, 0xff, 0x9f, 0x00, 0x00, 0x92, 0xa6, 0xad, 0x0b,
+ 0x00, 0x00, 0x30, 0x11, 0x89, 0x8c, 0xcb, 0x5b, 0xba, 0xaf, 0xf6, 0xd7,
+ 0xe7, 0x35, 0xe7, 0x59, 0xb3, 0xfb, 0xff, 0xff, 0x7f, 0x04, 0x40, 0x80,
+ 0xe4, 0xb9, 0x1f, 0x00, 0x00, 0x48, 0x22, 0x91, 0x66, 0x79, 0xeb, 0xff,
+ 0xff, 0xdf, 0xbe, 0xbe, 0xe7, 0x8c, 0x75, 0x6b, 0x4a, 0xfa, 0xbf, 0x7f,
+ 0x00, 0x00, 0x82, 0x24, 0xef, 0x0e, 0x00, 0x00, 0x4c, 0x22, 0xb2, 0x79,
+ 0x5e, 0xfa, 0x5b, 0xa9, 0xfd, 0xeb, 0xf5, 0x9c, 0x3d, 0xc6, 0xcc, 0xee,
+ 0xed, 0x01, 0xf8, 0x00, 0x40, 0x82, 0xb6, 0xa9, 0x1b, 0x00, 0x00, 0x94,
+ 0x64, 0x66, 0x8e, 0xd3, 0x97, 0xfe, 0xff, 0xd7, 0xdf, 0x9f, 0x7b, 0xf3,
+ 0x3c, 0x35, 0x59, 0x6b, 0x00, 0x70, 0x00, 0x00, 0x40, 0xe4, 0xed, 0x1e,
+ 0x00, 0x00, 0x92, 0xc4, 0x34, 0xf3, 0xfc, 0xfd, 0x5f, 0xad, 0x7d, 0xfa,
+ 0x7a, 0xce, 0x8e, 0xb3, 0x76, 0x2f, 0xfd, 0x00, 0xe0, 0x04, 0x00, 0x9a,
+ 0x26, 0xaf, 0x1e, 0x00, 0x00, 0x13, 0x88, 0xcc, 0xb5, 0x3f, 0xbf, 0xff,
+ 0xff, 0xd7, 0xef, 0xef, 0xbd, 0x79, 0x6a, 0xde, 0xec, 0xab, 0x01, 0xc0,
+ 0x00, 0x00, 0x40, 0xb6, 0xbd, 0x1b, 0x00, 0x00, 0x05, 0x91, 0xeb, 0x5c,
+ 0xeb, 0xeb, 0xff, 0xff, 0xff, 0x7e, 0xef, 0x6b, 0xef, 0xcd, 0x99, 0xb3,
+ 0xe4, 0x07, 0x80, 0x00, 0x40, 0x49, 0xb2, 0xe5, 0x1a, 0x00, 0x80, 0x20,
+ 0x32, 0xb1, 0xe7, 0x79, 0x7f, 0xf7, 0xff, 0xfd, 0xeb, 0xbd, 0xfe, 0x2c,
+ 0x3d, 0x6b, 0xb6, 0xaf, 0x06, 0x80, 0x00, 0x00, 0x41, 0x96, 0xfe, 0x1e,
+ 0x00, 0x80, 0x44, 0xb2, 0x9b, 0xf9, 0xde, 0xff, 0xff, 0xff, 0x7f, 0xbf,
+ 0xf7, 0xbb, 0xb3, 0x77, 0xce, 0xce, 0xb6, 0x0d, 0x80, 0x01, 0x00, 0x49,
+ 0xf2, 0x94, 0x1f, 0x00, 0x40, 0x49, 0x44, 0xe6, 0x9e, 0x77, 0xff, 0xff,
+ 0xff, 0xff, 0xff, 0xbf, 0xf7, 0x7e, 0xd6, 0xbc, 0xd9, 0xba, 0x3b, 0x80,
+ 0x00, 0x00, 0x64, 0x93, 0xf7, 0x1b, 0x00, 0x40, 0x89, 0xec, 0x7e, 0x67,
+ 0xbd, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xce, 0xdb, 0x99, 0x33, 0x37,
+ 0xd3, 0x36, 0x80, 0x01, 0x80, 0x24, 0xda, 0xd6, 0x1e, 0x00, 0x20, 0x90,
+ 0x99, 0x99, 0x7b, 0xef, 0xfb, 0xff, 0xff, 0xff, 0xff, 0xef, 0xbd, 0x37,
+ 0x63, 0xf3, 0x66, 0xdb, 0x7a, 0x80, 0x00, 0x00, 0x24, 0x59, 0xde, 0x1f,
+ 0x00, 0x60, 0x12, 0xb3, 0xf7, 0xdd, 0xfb, 0xfe, 0xff, 0xff, 0xff, 0xff,
+ 0xbf, 0xf7, 0xfe, 0x6e, 0xce, 0xdd, 0x6d, 0xd7, 0x80, 0x00, 0x80, 0x20,
+ 0xcb, 0xfb, 0x1f, 0x00, 0x10, 0x20, 0x6e, 0x66, 0x76, 0xff, 0xff, 0xff,
+ 0xff, 0xff, 0xff, 0xef, 0xde, 0xdb, 0x9b, 0x99, 0xb3, 0x5d, 0x6b, 0x81,
+ 0x00, 0x40, 0x96, 0x59, 0x6a, 0x1f, 0x00, 0x98, 0xc4, 0xe4, 0xdf, 0xff,
+ 0xfb, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7b, 0x6f, 0x7b, 0x37, 0x7f,
+ 0xb3, 0xdd, 0x83, 0x00, 0x00, 0xb0, 0xed, 0xef, 0x1d, 0x00, 0x10, 0x88,
+ 0x9e, 0xdd, 0xcd, 0xbd, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf7, 0xed,
+ 0x6c, 0xe6, 0xcc, 0x76, 0x6d, 0xc1, 0x00, 0x40, 0x91, 0x24, 0x7b, 0x1f,
+ 0x00, 0x08, 0xd1, 0xf1, 0x66, 0x76, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+ 0xff, 0xdf, 0xbd, 0xbf, 0xd9, 0xdd, 0xdd, 0xb6, 0x47, 0x00, 0x00, 0xd8,
+ 0xb4, 0xad, 0x1f, 0x00, 0x24, 0x24, 0x6f, 0xf6, 0xff, 0xff, 0xff, 0xff,
+ 0xff, 0xff, 0xff, 0xff, 0x7f, 0x7f, 0xb7, 0x9d, 0x33, 0xd9, 0x96, 0x4e,
+ 0x00, 0x20, 0x49, 0xf7, 0xfd, 0x1e, 0x00, 0x48, 0xe4, 0xac, 0xb9, 0xdd,
+ 0xfe, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xef, 0xdd, 0x76, 0xb6,
+ 0xb7, 0xfd, 0x7a, 0x00, 0x00, 0x44, 0x96, 0xb7, 0x1f, 0x00, 0x02, 0x9a,
+ 0xbe, 0x6f, 0x77, 0xff, 0xff, 0x7f, 0x61, 0xd9, 0xff, 0xff, 0xff, 0xfd,
+ 0xdd, 0x66, 0xed, 0x66, 0x5b, 0x37, 0x00, 0x90, 0x64, 0xb9, 0xf6, 0x1f,
+ 0x00, 0x02, 0xc9, 0xf3, 0xee, 0xfd, 0xff, 0xff, 0x2f, 0x24, 0x4f, 0xfe,
+ 0xff, 0xff, 0x7f, 0x37, 0xdb, 0xcd, 0x7c, 0xff, 0x3a, 0x00, 0x88, 0x24,
+ 0xdb, 0xde, 0x1a, 0x00, 0x13, 0x31, 0x6f, 0xbb, 0xdf, 0xff, 0xff, 0x21,
+ 0xa0, 0x64, 0xf3, 0xff, 0xff, 0xe7, 0xff, 0x96, 0xbb, 0x9b, 0xa5, 0x1d,
+ 0x00, 0x60, 0x32, 0xe9, 0xdb, 0x0f, 0x00, 0x65, 0xe6, 0x3c, 0xfb, 0xf6,
+ 0xff, 0x7f, 0x10, 0xa4, 0xb5, 0x9d, 0xfe, 0xdf, 0xdf, 0xdd, 0x6d, 0x32,
+ 0xb3, 0x7d, 0x0d, 0x00, 0x0b, 0x93, 0x7c, 0x7b, 0x0f, 0x00, 0x89, 0xdc,
+ 0xb3, 0xed, 0xfb, 0xff, 0x1f, 0x10, 0x90, 0x92, 0xd9, 0xfe, 0x7f, 0xff,
+ 0x77, 0xdb, 0xee, 0x6e, 0xdb, 0x0e, 0x00, 0x20, 0xdd, 0x66, 0x6f, 0x0f,
+ 0x80, 0x91, 0x5a, 0xfb, 0xbe, 0xef, 0xff, 0x0f, 0x10, 0xda, 0x92, 0xee,
+ 0xff, 0xff, 0xff, 0xf7, 0xb7, 0xcd, 0xee, 0xde, 0x07, 0x00, 0x24, 0x49,
+ 0xb6, 0xed, 0x0f, 0x00, 0x12, 0x6b, 0xcd, 0xf3, 0xbe, 0xff, 0x07, 0x08,
+ 0x48, 0xda, 0x76, 0xb7, 0xff, 0xff, 0xdd, 0x6e, 0xba, 0x99, 0x65, 0x03,
+ 0x40, 0x92, 0xe4, 0xba, 0xbd, 0x0e, 0x80, 0x62, 0xed, 0x7d, 0x5f, 0xf7,
+ 0xff, 0x01, 0x08, 0x28, 0xc9, 0x26, 0xbb, 0xff, 0xff, 0xff, 0x99, 0xb7,
+ 0xbb, 0x7d, 0x03, 0x00, 0x89, 0x64, 0xdb, 0xf6, 0x07, 0x40, 0x0c, 0x35,
+ 0xe7, 0x79, 0xdd, 0xff, 0x01, 0x84, 0xa5, 0x7d, 0xba, 0xdd, 0xfe, 0x7f,
+ 0xbf, 0xbf, 0x6d, 0x76, 0xdb, 0x01, 0x00, 0x48, 0x36, 0xdb, 0xd6, 0x07,
+ 0xc0, 0x88, 0xb4, 0xb6, 0xbf, 0xff, 0x7f, 0x00, 0x0c, 0x24, 0x44, 0xdb,
+ 0xed, 0xff, 0xdf, 0xef, 0x6e, 0xdb, 0x6e, 0xb7, 0x00, 0x80, 0x44, 0x93,
+ 0xed, 0x5b, 0x07, 0x40, 0x91, 0xd2, 0xfa, 0xfc, 0xf6, 0x7f, 0x00, 0x02,
+ 0xb4, 0x35, 0xd9, 0xef, 0xff, 0xff, 0xfb, 0xef, 0xb6, 0xc9, 0xe4, 0x00,
+ 0x10, 0x24, 0xd9, 0x6d, 0xfb, 0x03, 0x00, 0x27, 0xfe, 0xd3, 0xd6, 0xdb,
+ 0x3f, 0x00, 0xa2, 0x94, 0xb4, 0xdb, 0x7c, 0xff, 0xff, 0xbf, 0xd9, 0xad,
+ 0xdb, 0x7d, 0x00, 0x40, 0x32, 0xd9, 0xb6, 0xef, 0x03, 0x60, 0xe4, 0x5a,
+ 0x5f, 0x5f, 0xff, 0x1f, 0x00, 0x02, 0x52, 0x92, 0xec, 0xb6, 0xff, 0xff,
+ 0xef, 0xff, 0x6d, 0xb6, 0x3b, 0x00, 0x28, 0x90, 0xcc, 0xbe, 0xfd, 0x03,
+ 0xa0, 0x88, 0xeb, 0xf9, 0xfd, 0xf5, 0x1f, 0x00, 0x82, 0x53, 0xbb, 0x6d,
+ 0xf7, 0xff, 0xf9, 0xff, 0x6f, 0xdb, 0x6d, 0x1b, 0x00, 0x04, 0xc9, 0x66,
+ 0xdb, 0x57, 0x03, 0xa0, 0x52, 0xaf, 0xa7, 0x97, 0xff, 0x0f, 0x00, 0x51,
+ 0x48, 0xda, 0x66, 0xdb, 0xff, 0xf8, 0xdf, 0xed, 0xbe, 0xed, 0x0e, 0x00,
+ 0x92, 0x64, 0x32, 0xeb, 0xf6, 0x01, 0x20, 0x63, 0xbd, 0xbc, 0xfc, 0xfa,
+ 0x0f, 0x00, 0x09, 0x20, 0x89, 0x3e, 0xff, 0xff, 0xe0, 0x7f, 0xdf, 0x6f,
+ 0xdb, 0x07, 0x00, 0x01, 0x24, 0xbb, 0xed, 0xfe, 0x01, 0xa0, 0xce, 0xf5,
+ 0xf6, 0xdb, 0xdf, 0x07, 0x00, 0x41, 0xad, 0x5f, 0xf2, 0xed, 0xff, 0xc0,
+ 0xff, 0xbf, 0xdd, 0x92, 0x03, 0x00, 0x44, 0xb2, 0xd9, 0x7d, 0xfb, 0x01,
+ 0xe0, 0xaa, 0xdf, 0x9b, 0x7f, 0xfb, 0x07, 0x80, 0x28, 0x21, 0x64, 0xbb,
+ 0x7f, 0x7f, 0x80, 0xff, 0xf6, 0xbb, 0xee, 0x03, 0x80, 0x22, 0x99, 0xed,
+ 0xb6, 0xff, 0x00, 0x90, 0xb8, 0x5e, 0x5b, 0x6b, 0xed, 0x03, 0x00, 0x01,
+ 0xa6, 0x6d, 0xdb, 0xf6, 0x7f, 0x00, 0xff, 0xff, 0xf6, 0xcd, 0x00, 0x40,
+ 0x10, 0xc9, 0x6c, 0xff, 0xf7, 0x00, 0xa0, 0xe3, 0x72, 0xeb, 0xef, 0xff,
+ 0x03, 0x80, 0xe0, 0x90, 0x24, 0xdb, 0xbd, 0x3f, 0x00, 0xfe, 0xdb, 0x6f,
+ 0xfb, 0x00, 0x00, 0x89, 0x4c, 0xb6, 0xd9, 0x7e, 0x00, 0x70, 0xaf, 0xaf,
+ 0x6f, 0xb5, 0xde, 0x03, 0x80, 0x94, 0x92, 0xb6, 0xf9, 0xf6, 0x3f, 0x00,
+ 0xfc, 0xbf, 0xdd, 0x7b, 0x00, 0x10, 0x48, 0x26, 0xb3, 0xdf, 0x7f, 0x00,
+ 0x70, 0xd8, 0xae, 0xfd, 0xff, 0xf7, 0x03, 0x80, 0x00, 0xd2, 0x36, 0xcf,
+ 0xdf, 0x3f, 0x00, 0xb8, 0x6d, 0xdf, 0x16, 0x00, 0x48, 0x44, 0xb2, 0xfb,
+ 0x6c, 0x3f, 0x00, 0x50, 0x75, 0xfd, 0xa5, 0xd5, 0xfe, 0x01, 0x40, 0xd1,
+ 0x12, 0xa2, 0x7d, 0xfb, 0x1f, 0x00, 0xf0, 0xff, 0xbf, 0x0d, 0x00, 0x20,
+ 0x12, 0x9b, 0xcd, 0xf6, 0x3f, 0x00, 0x90, 0xd5, 0xa7, 0xfd, 0x77, 0xab,
+ 0x03, 0x40, 0x1c, 0xc8, 0xbe, 0x6d, 0xfb, 0x1f, 0x00, 0xe0, 0xff, 0xee,
+ 0x07, 0x00, 0x04, 0x91, 0xc9, 0x7e, 0xbf, 0x1f, 0x00, 0x30, 0x57, 0xbf,
+ 0xa6, 0xde, 0xfd, 0x01, 0x40, 0x40, 0x6b, 0xd3, 0x6e, 0xef, 0x0f, 0x00,
+ 0xc0, 0xeb, 0x7d, 0x03, 0x00, 0x90, 0xc8, 0x6c, 0x76, 0xfb, 0x0f, 0x00,
+ 0x70, 0x5c, 0xe5, 0xf7, 0xfa, 0xeb, 0x01, 0x40, 0x50, 0x49, 0x92, 0xf4,
+ 0xfd, 0x0f, 0x00, 0xc0, 0xff, 0xdb, 0x01, 0x80, 0x44, 0x44, 0x66, 0xbb,
+ 0x6f, 0x0f, 0x00, 0xd0, 0xf1, 0x95, 0xf6, 0x6f, 0xad, 0x01, 0x40, 0x08,
+ 0x78, 0xdb, 0xb6, 0xef, 0x0f, 0x00, 0x00, 0xdf, 0xd6, 0x00, 0x00, 0x20,
+ 0x32, 0xb3, 0xdb, 0xfd, 0x0f, 0x00, 0x10, 0xd7, 0xf7, 0xb6, 0xd8, 0xeb,
+ 0x03, 0x20, 0x43, 0x27, 0xd9, 0xb6, 0xfd, 0x0f, 0x00, 0x00, 0xff, 0x7e,
+ 0x00, 0x40, 0x12, 0x93, 0xd9, 0xec, 0xb6, 0x07, 0x00, 0x70, 0x55, 0xdd,
+ 0xf6, 0x6f, 0xbb, 0x01, 0x40, 0x28, 0xa1, 0x6f, 0xb6, 0xb7, 0x0f, 0x00,
+ 0x00, 0xde, 0x1f, 0x00, 0x80, 0x88, 0xd8, 0xcc, 0x66, 0xff, 0x03, 0x00,
+ 0x70, 0xf4, 0xf5, 0xdb, 0xaa, 0xee, 0x01, 0x60, 0x28, 0x2d, 0x49, 0xf7,
+ 0xf6, 0x07, 0x00, 0x00, 0x7c, 0x0f, 0x00, 0x08, 0x48, 0x66, 0x6e, 0xfb,
+ 0xef, 0x03, 0x00, 0xd0, 0xd5, 0xdf, 0x52, 0xff, 0xda, 0x03, 0x20, 0xa3,
+ 0xa5, 0xd9, 0xb2, 0xff, 0x07, 0x00, 0x00, 0xf8, 0x07, 0x00, 0x20, 0x22,
+ 0x33, 0x37, 0xbf, 0xfd, 0x01, 0x00, 0x70, 0x5f, 0xf7, 0xfe, 0xab, 0x6b,
+ 0x02, 0xa0, 0xa8, 0xb4, 0x6d, 0xdf, 0xf6, 0x07, 0x00, 0x00, 0xf8, 0x01,
+ 0x00, 0x12, 0x33, 0x11, 0xd9, 0xdd, 0xff, 0x01, 0x00, 0x70, 0x75, 0xd5,
+ 0x52, 0xea, 0x8a, 0x03, 0x20, 0x84, 0x36, 0x69, 0xba, 0xdb, 0x07, 0x00,
+ 0x00, 0xf0, 0x01, 0x00, 0x81, 0xc8, 0xcc, 0xdd, 0xed, 0xff, 0x00, 0x00,
+ 0x60, 0xd5, 0xdf, 0xf6, 0xae, 0x6b, 0x03, 0x00, 0xa1, 0xa4, 0x6d, 0xdf,
+ 0xfe, 0x07, 0x00, 0x00, 0x60, 0x00, 0x40, 0x44, 0xc6, 0xcc, 0x64, 0xb7,
+ 0xfd, 0x00, 0x00, 0xe0, 0x55, 0xf7, 0xd6, 0xea, 0xba, 0x07, 0x20, 0x94,
+ 0x94, 0x6d, 0xfb, 0xdb, 0x07, 0x00, 0x00, 0x20, 0x00, 0x20, 0x20, 0x32,
+ 0x76, 0x77, 0xff, 0x7f, 0x00, 0x00, 0x60, 0x7d, 0xd5, 0xb6, 0x3f, 0xaf,
+ 0x06, 0xa0, 0xa4, 0x95, 0x6c, 0x9b, 0xee, 0x07, 0x00, 0x00, 0x18, 0x00,
+ 0x10, 0x92, 0x15, 0x73, 0xbb, 0xd9, 0x3f, 0x00, 0x00, 0xe0, 0xf5, 0xff,
+ 0xf7, 0x6a, 0xa9, 0x06, 0x80, 0xa2, 0xb4, 0x6d, 0xfb, 0xfb, 0x07, 0x00,
+ 0x00, 0x04, 0x00, 0x84, 0x88, 0xc8, 0x99, 0xdd, 0xff, 0x3f, 0x00, 0x00,
+ 0xe0, 0x8b, 0xff, 0x96, 0x6a, 0xb6, 0x0a, 0xa0, 0x94, 0x96, 0x64, 0xdb,
+ 0xee, 0x07, 0x00, 0x00, 0x03, 0x08, 0x20, 0x60, 0x66, 0xec, 0xee, 0xb6,
+ 0x1d, 0x00, 0x00, 0xc0, 0x7e, 0xa5, 0xf4, 0xab, 0x55, 0x0d, 0x20, 0xe7,
+ 0xd4, 0x6d, 0xdb, 0xfb, 0x07, 0x00, 0x80, 0x00, 0x00, 0x09, 0x12, 0x33,
+ 0x67, 0x77, 0xff, 0x0f, 0x00, 0x00, 0xc0, 0xfa, 0xff, 0xb7, 0x7a, 0x55,
+ 0x19, 0x90, 0x91, 0xd4, 0x64, 0xdb, 0xee, 0x07, 0x00, 0x40, 0x00, 0x81,
+ 0x04, 0x88, 0x91, 0x3b, 0xbb, 0xfd, 0x0f, 0x00, 0x00, 0xc0, 0xab, 0xbf,
+ 0xed, 0x4e, 0xbb, 0x32, 0x20, 0x94, 0x96, 0x6c, 0xff, 0xfa, 0x03, 0x00,
+ 0x30, 0x40, 0x20, 0x20, 0x64, 0xcc, 0xdc, 0xdd, 0xff, 0x07, 0x00, 0x00,
+ 0xc0, 0xeb, 0xea, 0xfd, 0xd5, 0xaa, 0x2a, 0x20, 0xd7, 0xb0, 0x6d, 0x93,
+ 0xef, 0x07, 0x00, 0x08, 0x00, 0x08, 0x01, 0x23, 0xee, 0xee, 0xee, 0xfb,
+ 0x03, 0x00, 0x00, 0xc0, 0xfe, 0xff, 0x2d, 0xdd, 0x6a, 0x49, 0xd0, 0x90,
+ 0x9a, 0x64, 0xdf, 0xea, 0x07, 0x00, 0x03, 0x80, 0x40, 0x8c, 0x98, 0x33,
+ 0xb3, 0xbb, 0xff, 0x01, 0x00, 0x00, 0xc0, 0xa5, 0x7b, 0x6d, 0xa7, 0x56,
+ 0xc5, 0xa0, 0x94, 0x94, 0x6f, 0xd3, 0xbb, 0x07, 0x80, 0x10, 0x0c, 0x12,
+ 0x40, 0xc6, 0xb9, 0xdb, 0xfb, 0xfd, 0x01, 0x00, 0x00, 0x80, 0x97, 0xee,
+ 0xdf, 0xba, 0x54, 0x1a, 0xa1, 0xe5, 0xd2, 0x64, 0x7e, 0xee, 0x07, 0x60,
+ 0x02, 0x80, 0x00, 0x31, 0x62, 0xcc, 0xdc, 0xee, 0x7f, 0x00, 0x00, 0x00,
+ 0x80, 0xff, 0xff, 0xdb, 0xaa, 0xb5, 0x8a, 0x86, 0x98, 0x96, 0x6d, 0x9b,
+ 0xea, 0x07, 0x98, 0x00, 0x22, 0x44, 0x88, 0x39, 0x77, 0x77, 0xff, 0x7f,
+ 0x00, 0x00, 0x00, 0x80, 0x7d, 0x77, 0xba, 0x7b, 0x2d, 0x55, 0x3c, 0xa6,
+ 0xb4, 0x6c, 0xf6, 0xaf, 0x07, 0x07, 0x90, 0x88, 0x20, 0x42, 0x9c, 0xbb,
+ 0xbb, 0xbb, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x4b, 0xbd, 0xbf, 0x55, 0x53,
+ 0xa5, 0xb2, 0xa1, 0xb4, 0xc9, 0x9f, 0xda, 0xcf, 0x28, 0x24, 0x42, 0x08,
+ 0x31, 0xe6, 0xcc, 0xdd, 0xff, 0x7f, 0x00, 0x00, 0x00, 0x00, 0xff, 0xef,
+ 0xb7, 0xbd, 0xde, 0x12, 0xd1, 0xac, 0x95, 0x4d, 0xf2, 0x56, 0x9f, 0x88,
+ 0x80, 0x10, 0xc2, 0x9c, 0x73, 0x77, 0xef, 0xfe, 0x7f, 0x00, 0x00, 0x00,
+ 0x00, 0xbf, 0xfb, 0xed, 0xeb, 0x35, 0x95, 0x72, 0xa2, 0x35, 0xcd, 0xb6,
+ 0xd6, 0x2f, 0x21, 0x24, 0x04, 0x31, 0xc6, 0x98, 0x33, 0xf7, 0xff, 0xff,
+ 0x00, 0x00, 0x00, 0x00, 0xd6, 0x6a, 0x7f, 0x5b, 0xab, 0x2d, 0x28, 0x23,
+ 0x65, 0xd9, 0xb6, 0x55, 0x5f, 0x88, 0x08, 0x43, 0x0c, 0x61, 0xde, 0xdd,
+ 0xfb, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x76, 0xff, 0x4d, 0xd7, 0x4d,
+ 0x4a, 0xa5, 0x29, 0x2d, 0xdb, 0xbe, 0x55, 0x1f, 0x22, 0x42, 0x28, 0xc2,
+ 0x39, 0xe7, 0xee, 0xee, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0xdc, 0x7f,
+ 0xfb, 0xb6, 0xb6, 0x95, 0x70, 0x2e, 0xa5, 0xd9, 0x24, 0x5d, 0x5f, 0x8a,
+ 0x28, 0x88, 0x31, 0x9e, 0x39, 0x73, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00,
+ 0x00, 0xec, 0xb7, 0xdf, 0x6c, 0xb5, 0x65, 0x26, 0xa3, 0x39, 0x9b, 0xfc,
+ 0x85, 0x5d, 0x21, 0x04, 0x63, 0x1c, 0xe6, 0xdd, 0xbd, 0xfb, 0xff, 0xff,
+ 0x01, 0x00, 0x00, 0x00, 0xb8, 0xfa, 0xb6, 0x6f, 0x4d, 0x9a, 0x28, 0x59,
+ 0x4d, 0xd3, 0x2f, 0xf5, 0x3f, 0x8c, 0xd1, 0x18, 0xc6, 0x31, 0xf6, 0xdd,
+ 0xfe, 0xff, 0xfe, 0x01, 0x00, 0x00, 0x00, 0xf8, 0xff, 0xef, 0xb9, 0xb6,
+ 0x25, 0xe1, 0x4d, 0x69, 0xba, 0x6c, 0xad, 0x3c, 0x41, 0x14, 0x84, 0xe9,
+ 0x9e, 0x37, 0xf7, 0xff, 0xff, 0xfb, 0x03, 0x00, 0x00, 0x00, 0x70, 0x5d,
+ 0x3d, 0x9f, 0x3d, 0x6d, 0x26, 0x52, 0x59, 0xb6, 0x6d, 0xab, 0x7f, 0x14,
+ 0x82, 0xe1, 0x39, 0xe6, 0xdd, 0xfb, 0xff, 0xbf, 0xff, 0x01, 0x00, 0x00,
+ 0x00, 0xf0, 0xf6, 0x6f, 0x77, 0xcd, 0x92, 0xd0, 0x52, 0x4b, 0xb3, 0x49,
+ 0x0b, 0x3a, 0x41, 0x61, 0x38, 0x9e, 0x73, 0xee, 0xdc, 0xff, 0xff, 0xfd,
+ 0x03, 0x00, 0x00, 0x00, 0xf0, 0xff, 0xd7, 0x65, 0xda, 0x66, 0x63, 0x9d,
+ 0xf2, 0x36, 0x7b, 0x6a, 0x7f, 0x14, 0x18, 0x8e, 0xe7, 0xd9, 0x7b, 0xff,
+ 0xff, 0xef, 0xff, 0x03, 0x00, 0x00, 0x00, 0xe0, 0xff, 0xff, 0xdd, 0xb6,
+ 0xc9, 0x4c, 0x46, 0x9a, 0x64, 0xcb, 0x5b, 0xed, 0x06, 0xc6, 0xe3, 0x71,
+ 0xde, 0xbd, 0xff, 0xff, 0x7f, 0xff, 0x07, 0x00, 0x00, 0x00, 0xc0, 0x7f,
+ 0x7f, 0xff, 0x59, 0x37, 0x75, 0xbb, 0x96, 0x66, 0xdb, 0x56, 0xf7, 0xe0,
+ 0xf2, 0x74, 0x9e, 0x77, 0xef, 0xfd, 0xff, 0xeb, 0xed, 0x03, 0x00, 0x00,
+ 0x00, 0xc0, 0xea, 0xdf, 0xb3, 0xdb, 0xde, 0xc6, 0x81, 0xb0, 0x6c, 0xba,
+ 0xb4, 0xf6, 0x38, 0x18, 0x3c, 0xe7, 0x9c, 0xfb, 0xff, 0x7f, 0xff, 0xff,
+ 0x07, 0x00, 0x00, 0x00, 0x80, 0xff, 0xf7, 0x6e, 0x66, 0xd9, 0x99, 0xac,
+ 0xa4, 0xcd, 0x96, 0xa5, 0xea, 0x03, 0xa7, 0xcf, 0x79, 0xef, 0xfd, 0xff,
+ 0xff, 0xff, 0xff, 0x07, 0x00, 0x00, 0x00, 0x00, 0xff, 0xfd, 0xef, 0xdf,
+ 0x6f, 0xef, 0x72, 0x65, 0xd9, 0xb6, 0xad, 0xe8, 0xc1, 0xe1, 0xf1, 0xbe,
+ 0x7b, 0xef, 0xff, 0xdf, 0x7a, 0xfb, 0x07, 0x00, 0x00, 0x00, 0x00, 0xfe,
+ 0x5f, 0xdd, 0x9d, 0xac, 0x99, 0x84, 0x29, 0xcd, 0x3c, 0x4f, 0x9d, 0x7d,
+ 0x3c, 0x9e, 0xe7, 0xbe, 0xff, 0xff, 0xff, 0xff, 0xef, 0x0f, 0x00, 0x00,
+ 0x00, 0x00, 0xfe, 0xff, 0x77, 0x7b, 0x33, 0xe7, 0x5a, 0x49, 0x9b, 0x65,
+ 0x59, 0x75, 0x07, 0x97, 0xf7, 0xbb, 0xef, 0xff, 0xff, 0xdb, 0xfe, 0xff,
+ 0x07, 0x00, 0x00, 0x00, 0x00, 0xfc, 0xf7, 0x3f, 0xe7, 0xcf, 0x9c, 0x51,
+ 0x4d, 0xb0, 0x6d, 0x4b, 0xc9, 0xd3, 0xf5, 0x79, 0xfe, 0xfb, 0xff, 0xff,
+ 0xdb, 0xda, 0xfe, 0x0f, 0x00, 0x00, 0x00, 0x00, 0xf8, 0xff, 0xef, 0xde,
+ 0xdd, 0xf3, 0x4d, 0x52, 0x36, 0xcb, 0xd2, 0x3a, 0x7e, 0x3c, 0xde, 0xe7,
+ 0xbe, 0xff, 0x7f, 0xda, 0xff, 0xdf, 0x0f, 0x00, 0x00, 0x00, 0x00, 0xf8,
+ 0xff, 0xfb, 0xdd, 0x73, 0x8f, 0xa5, 0x9a, 0xe6, 0xd9, 0xb6, 0xe2, 0x4e,
+ 0xc7, 0xf7, 0xfd, 0xff, 0xff, 0xff, 0xf7, 0xf6, 0xff, 0x0f, 0x00, 0x00,
+ 0x00, 0x00, 0xe0, 0xff, 0xff, 0x7f, 0xee, 0x79, 0xb2, 0xb2, 0x2c, 0x9f,
+ 0xb6, 0x54, 0xfe, 0xfb, 0x79, 0xbf, 0xff, 0xff, 0x5f, 0xda, 0xff, 0xfa,
+ 0x0f, 0x00, 0x00, 0x00, 0x00, 0xe0, 0xff, 0xff, 0xf7, 0xbf, 0xe7, 0x4b,
+ 0xb4, 0x69, 0xd3, 0x2c, 0x25, 0xbd, 0xbc, 0xcf, 0xf7, 0xfd, 0xff, 0xd7,
+ 0xf6, 0xfe, 0xdf, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x80, 0xff, 0xbf, 0x9d,
+ 0xf1, 0x3e, 0x57, 0x25, 0xcb, 0xb6, 0x6d, 0xa9, 0xb5, 0xef, 0xfb, 0xff,
+ 0xff, 0xff, 0xd5, 0xda, 0xd6, 0xff, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x80,
+ 0xff, 0xff, 0xfb, 0xcf, 0xf5, 0x25, 0x65, 0xd9, 0x66, 0x5b, 0x4a, 0xfa,
+ 0xf9, 0x7e, 0xff, 0xff, 0xff, 0xf6, 0xd6, 0xdf, 0xfa, 0x0f, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0xfe, 0xff, 0xef, 0x3e, 0xf7, 0x9f, 0x5b, 0x92, 0x6c,
+ 0xdb, 0x52, 0xe5, 0xbe, 0xdf, 0xff, 0xff, 0xbf, 0x51, 0xda, 0xfa, 0x7f,
+ 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0xff, 0xff, 0x7b, 0x9f, 0xe7,
+ 0x4c, 0xb3, 0x4d, 0xd3, 0x54, 0xd9, 0xe7, 0xfb, 0xff, 0xff, 0x5f, 0xdc,
+ 0xfa, 0xdf, 0xff, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0xff, 0x7f,
+ 0xe7, 0xf9, 0x3a, 0xd3, 0xa6, 0xe9, 0xb6, 0xa5, 0xca, 0xf9, 0xfd, 0xff,
+ 0xff, 0x83, 0x42, 0xd2, 0xff, 0xfb, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0xf0, 0xff, 0xfd, 0xbf, 0xef, 0x4f, 0xd5, 0x64, 0xdb, 0x26, 0x4d, 0x30,
+ 0x7f, 0xff, 0xff, 0xff, 0x91, 0xda, 0xdb, 0xda, 0xdf, 0x1f, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0xe0, 0xff, 0xbf, 0xff, 0x7d, 0xbe, 0xb5, 0x6d, 0x97,
+ 0x6d, 0x93, 0x56, 0xdf, 0xff, 0xff, 0x7f, 0x81, 0x4a, 0xda, 0x7f, 0xff,
+ 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0xff, 0xff, 0xef, 0xeb, 0xbb,
+ 0xa6, 0x4d, 0x73, 0xcd, 0x92, 0xaa, 0xfe, 0xff, 0xff, 0x1f, 0x01, 0x6a,
+ 0x5b, 0xfb, 0xfb, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff,
+ 0xfd, 0xbf, 0x5f, 0x3b, 0xdb, 0x36, 0xbb, 0x26, 0x4c, 0xf9, 0xff, 0xff,
+ 0x0f, 0xa3, 0x2a, 0xe9, 0x7f, 0xff, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0xee, 0xff, 0xff, 0xfe, 0xfe, 0xcc, 0x91, 0xec, 0x93, 0x6d, 0x93,
+ 0xf2, 0xff, 0xff, 0x03, 0x00, 0x6a, 0x6d, 0x6f, 0xff, 0x1f, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0xf8, 0xff, 0xff, 0xf7, 0x6f, 0x76, 0xb6, 0xcd,
+ 0x76, 0xc9, 0x2a, 0xe9, 0xff, 0xff, 0x00, 0x02, 0x24, 0xed, 0xf9, 0xed,
+ 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0xff, 0xff, 0xdf, 0xff,
+ 0xd9, 0x66, 0x9b, 0x6c, 0x93, 0x54, 0xc5, 0xff, 0x3f, 0x00, 0x01, 0x95,
+ 0xb5, 0xaf, 0xff, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0xff,
+ 0xff, 0xff, 0xfd, 0xae, 0x7d, 0xde, 0x6d, 0xf6, 0xa1, 0x8a, 0xff, 0x0f,
+ 0x00, 0x81, 0x90, 0xb4, 0xfd, 0xfd, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x80, 0xff, 0xff, 0xff, 0xff, 0xf7, 0xcd, 0xb2, 0xdb, 0x2c, 0xcb,
+ 0x54, 0xfe, 0x01, 0x00, 0x01, 0xd2, 0xb6, 0xb7, 0xff, 0x0f, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0xff, 0xff, 0xff, 0x39, 0xdb, 0x76,
+ 0xb3, 0x4b, 0xb6, 0x0a, 0xfe, 0x00, 0x00, 0x01, 0x48, 0xda, 0xfe, 0xff,
+ 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0xff, 0xff, 0xff,
+ 0xcf, 0xb9, 0x6d, 0xb6, 0xd9, 0xa5, 0x75, 0x1c, 0x00, 0x80, 0x80, 0x20,
+ 0xdb, 0xda, 0xbe, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0,
+ 0xff, 0xff, 0xff, 0x77, 0x96, 0xd9, 0x26, 0xb3, 0x4d, 0x82, 0x11, 0x00,
+ 0x80, 0x80, 0x24, 0x6d, 0xff, 0xf7, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x80, 0xff, 0xff, 0xff, 0xbb, 0x67, 0xdb, 0xdd, 0x36, 0xd9,
+ 0x54, 0x60, 0x00, 0xc0, 0x00, 0x92, 0x65, 0x6b, 0xff, 0x0f, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0xff, 0xff, 0x4f, 0x7d, 0x96,
+ 0xd9, 0x6c, 0x36, 0xad, 0xc2, 0x00, 0x60, 0x00, 0xc8, 0xb6, 0x6d, 0xff,
+ 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0xff, 0xff,
+ 0xff, 0xc8, 0x76, 0xbb, 0xcb, 0x64, 0x52, 0x02, 0x03, 0x10, 0x00, 0x64,
+ 0xda, 0xff, 0xfb, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x80, 0xff, 0xff, 0x5f, 0xd7, 0x4d, 0x33, 0x99, 0xdd, 0x96, 0x04, 0x2c,
+ 0x1c, 0x40, 0x22, 0xdb, 0xb6, 0xff, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0xfc, 0xff, 0xdf, 0xb5, 0xed, 0xe6, 0x36, 0x9b,
+ 0x6c, 0x29, 0xf0, 0x03, 0x00, 0x99, 0x6c, 0xfb, 0xfd, 0x07, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0xff, 0x7f, 0x35, 0xbb,
+ 0xec, 0x76, 0x33, 0x91, 0x02, 0x00, 0x00, 0x00, 0x64, 0x67, 0xdf, 0xff,
+ 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfc,
+ 0xbf, 0x6f, 0x9b, 0x9d, 0xc9, 0xce, 0x36, 0x49, 0x00, 0x00, 0x00, 0x93,
+ 0xb1, 0xdd, 0xfe, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x40, 0xff, 0x6a, 0x76, 0xbb, 0xdd, 0xd9, 0x64, 0x12, 0x01,
+ 0x00, 0x40, 0x98, 0xdd, 0x6d, 0xff, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0xdf, 0x66, 0x73, 0x33, 0xbb,
+ 0x9d, 0x4d, 0x00, 0x00, 0x00, 0x63, 0xe6, 0xf6, 0xff, 0x07, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xed, 0xfd,
+ 0xee, 0xee, 0x36, 0x73, 0x2b, 0x04, 0x00, 0xa0, 0x38, 0x75, 0xbf, 0xff,
+ 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x7f, 0xd9, 0xec, 0xce, 0x66, 0x66, 0x66, 0x22, 0x04, 0x00, 0xc6,
+ 0x99, 0xbb, 0xff, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x5e, 0xb3, 0xdb, 0xb9, 0xcd, 0xc9, 0x88, 0x89,
+ 0x00, 0x68, 0x31, 0xee, 0xdd, 0xff, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf6, 0xbe, 0xbb, 0x9b, 0x3f,
+ 0xbb, 0x33, 0x23, 0x04, 0x00, 0x8c, 0xf3, 0xee, 0xff, 0x03, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xbc, 0x67,
+ 0x76, 0x77, 0xb2, 0x66, 0xce, 0x0c, 0xd1, 0xd6, 0xe3, 0x79, 0xf7, 0xff,
+ 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0xf8, 0xfd, 0xef, 0xe6, 0xee, 0xce, 0x9c, 0x31, 0x16, 0x00, 0x3c,
+ 0x9e, 0xfb, 0xff, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x78, 0x9f, 0xdb, 0xdc, 0x9d, 0x99, 0x33, 0xc6,
+ 0xc1, 0xff, 0x8f, 0xe7, 0xbb, 0xff, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0xf7, 0xbd, 0xbb, 0x33,
+ 0x7b, 0xee, 0x18, 0x1e, 0x50, 0xf0, 0xf9, 0xfe, 0xff, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x7b,
+ 0xf7, 0x77, 0xf7, 0xe6, 0x9c, 0xe3, 0xf0, 0x4d, 0xff, 0x7c, 0xef, 0xff,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0xc0, 0xdf, 0x76, 0x7f, 0xcf, 0x9e, 0x73, 0x8f, 0x07, 0xff, 0x0b,
+ 0xdf, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x80, 0xee, 0xcd, 0xdd, 0x9d, 0x7b, 0xf7, 0x7c,
+ 0x7a, 0x00, 0xf0, 0xe7, 0xfd, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x7f, 0xbf, 0xdd, 0x7b,
+ 0x6b, 0x9e, 0xf3, 0xe1, 0xff, 0xff, 0x7d, 0xff, 0x7f, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xee,
+ 0xb7, 0xbb, 0x7b, 0xee, 0x79, 0x8f, 0x0f, 0xfa, 0x2f, 0xff, 0xf7, 0x3f,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x7e, 0xff, 0x77, 0xef, 0xdd, 0x77, 0x7c, 0xfe, 0x02, 0xe8,
+ 0xcf, 0xff, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0xef, 0xee, 0xdd, 0xb3, 0xcf, 0xf3,
+ 0xf1, 0xff, 0xff, 0xf9, 0xfe, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0xfb, 0xff, 0xbf,
+ 0xef, 0xbe, 0xcf, 0x8f, 0xfe, 0x5f, 0xfe, 0xff, 0x0f, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0,
+ 0xbf, 0xbb, 0xf7, 0xde, 0x79, 0x3e, 0xff, 0x52, 0xd2, 0xdf, 0xff, 0x0f,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0xe0, 0xef, 0xef, 0xef, 0x3c, 0xef, 0xf9, 0xf8, 0xff, 0xff,
+ 0xf7, 0xff, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xff, 0xee, 0xdc, 0xf7, 0xfe, 0xe7,
+ 0x97, 0xfe, 0xff, 0xfe, 0xff, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xbf,
+ 0xef, 0xbf, 0x3e, 0xff, 0xda, 0xf6, 0xff, 0xff, 0x03, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0xfe, 0xbf, 0xf7, 0xfe, 0xf7, 0xff, 0xfe, 0xff, 0xff, 0xff, 0xff, 0x01,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0xfe, 0xff, 0xde, 0xbd, 0xef, 0xfb, 0xd7, 0xff, 0xbf,
+ 0xfd, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0xff, 0xff, 0xf7, 0x7d, 0xbf,
+ 0xff, 0xd2, 0xf6, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0xff, 0xbf,
+ 0xef, 0xfb, 0xfd, 0xfd, 0xff, 0xff, 0xff, 0x7f, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0xc0, 0xff, 0xef, 0xbe, 0xf7, 0xef, 0xef, 0xff, 0xff, 0xff, 0x3f, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xfb, 0xdf, 0xbf, 0xff, 0xff, 0xff,
+ 0xff, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0xff, 0xff, 0x7f, 0xff,
+ 0xff, 0xff, 0xff, 0xff, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfc, 0xff,
+ 0xfe, 0xff, 0xfb, 0xf7, 0xff, 0xff, 0xff, 0x07, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0xf0, 0xff, 0xff, 0xff, 0xdf, 0xff, 0xfd, 0xff, 0xff, 0x03, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0xc0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+ 0xff, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xff, 0xff, 0xff, 0xff,
+ 0xff, 0xff, 0xff, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe,
+ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0xf8, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x1f, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+ 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xff, 0xff, 0xff,
+ 0xff, 0xff, 0xff, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0xfc, 0xff, 0xff, 0xff, 0xff, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0xe0, 0xff, 0xff, 0xff, 0xff, 0x1f, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x07,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0xff,
+ 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0xff, 0xff, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
+ };
diff --git a/Xserver/include/bitmaps/flagdown b/Xserver/include/bitmaps/flagdown
new file mode 100644 (file)
index 0000000..55abc51
--- /dev/null
@@ -0,0 +1,27 @@
+#define flagdown_width 48
+#define flagdown_height 48
+static char flagdown_bits[] = {
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x00,
+   0x00, 0x00, 0x80, 0x7f, 0x00, 0x00, 0x00, 0x00, 0xe0, 0xe1, 0x00, 0x00,
+   0x00, 0x00, 0x70, 0x80, 0x01, 0x00, 0x00, 0x00, 0x18, 0x00, 0x03, 0x00,
+   0x00, 0x00, 0x0c, 0x00, 0x03, 0x00, 0x00, 0x00, 0x06, 0x00, 0x06, 0x04,
+   0x00, 0x00, 0x03, 0x00, 0x06, 0x06, 0x00, 0x80, 0x01, 0x00, 0x06, 0x07,
+   0x00, 0xc0, 0x1f, 0x00, 0x87, 0x07, 0x00, 0xe0, 0x7f, 0x80, 0xc7, 0x07,
+   0x00, 0x70, 0xe0, 0xc0, 0xe5, 0x07, 0x00, 0x38, 0x80, 0xe1, 0x74, 0x07,
+   0x00, 0x18, 0x80, 0x71, 0x3c, 0x07, 0x00, 0x0c, 0x00, 0x3b, 0x1e, 0x03,
+   0x00, 0x0c, 0x00, 0x1f, 0x0f, 0x00, 0x00, 0x86, 0x1f, 0x8e, 0x07, 0x00,
+   0x00, 0x06, 0x06, 0xc6, 0x05, 0x00, 0x00, 0x06, 0x00, 0xc6, 0x05, 0x00,
+   0x00, 0x06, 0x00, 0xc6, 0x04, 0x00, 0x00, 0x06, 0x00, 0x06, 0x04, 0x00,
+   0x7f, 0x06, 0x00, 0x06, 0xe4, 0xff, 0x00, 0x06, 0x00, 0x06, 0x04, 0x00,
+   0x00, 0x06, 0x00, 0x06, 0x04, 0x00, 0x00, 0x06, 0x00, 0x06, 0x06, 0x00,
+   0x00, 0x06, 0x00, 0x06, 0x03, 0x00, 0x00, 0x06, 0x00, 0x86, 0x01, 0x00,
+   0x00, 0x06, 0x00, 0xc6, 0x00, 0x00, 0x00, 0x06, 0x00, 0x66, 0x00, 0x00,
+   0x00, 0x06, 0x00, 0x36, 0x00, 0x00, 0x00, 0x06, 0x00, 0x3e, 0x00, 0x00,
+   0x00, 0xfe, 0xff, 0x2f, 0x00, 0x00, 0x00, 0xfc, 0xff, 0x27, 0x00, 0x00,
+   0x00, 0x00, 0x88, 0x20, 0x00, 0x00, 0x00, 0x00, 0x88, 0x20, 0x00, 0x00,
+   0x00, 0x00, 0x88, 0x20, 0x00, 0x00, 0x00, 0x00, 0x88, 0x20, 0x00, 0x00,
+   0x00, 0x00, 0x88, 0x20, 0x00, 0x00, 0x00, 0x00, 0x88, 0x20, 0x00, 0x00,
+   0x00, 0x00, 0x88, 0x20, 0x00, 0x00, 0x00, 0x00, 0x88, 0x20, 0x00, 0x00,
+   0xf7, 0xbf, 0x8e, 0xfc, 0xdf, 0xf8, 0x9d, 0xeb, 0x9b, 0x76, 0xd2, 0x7a,
+   0x46, 0x30, 0xe2, 0x0f, 0xe1, 0x47, 0x55, 0x84, 0x48, 0x11, 0x84, 0x19};
diff --git a/Xserver/include/bitmaps/flagup b/Xserver/include/bitmaps/flagup
new file mode 100644 (file)
index 0000000..6eb0d84
--- /dev/null
@@ -0,0 +1,27 @@
+#define flagup_width 48
+#define flagup_height 48
+static char flagup_bits[] = {
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x7f, 0x00,
+   0x00, 0x00, 0x00, 0xe0, 0x7f, 0x00, 0x00, 0x00, 0x00, 0xef, 0x6a, 0x00,
+   0x00, 0x00, 0xc0, 0x7b, 0x75, 0x00, 0x00, 0x00, 0xe0, 0xe0, 0x6a, 0x00,
+   0x00, 0x00, 0x30, 0x60, 0x75, 0x00, 0x00, 0x00, 0x18, 0xe0, 0x7f, 0x00,
+   0x00, 0x00, 0x0c, 0xe0, 0x7f, 0x00, 0x00, 0x00, 0x06, 0xe0, 0x04, 0x00,
+   0x00, 0x00, 0x03, 0xe0, 0x04, 0x00, 0x00, 0x80, 0x01, 0xe0, 0x06, 0x00,
+   0x00, 0xc0, 0x1f, 0xe0, 0x07, 0x00, 0x00, 0xe0, 0x7f, 0xe0, 0x07, 0x00,
+   0x00, 0x70, 0xe0, 0xe0, 0x05, 0x00, 0x00, 0x38, 0x80, 0xe1, 0x04, 0x00,
+   0x00, 0x18, 0x80, 0xf1, 0x04, 0x00, 0x00, 0x0c, 0x00, 0xfb, 0x04, 0x00,
+   0x00, 0x0c, 0x00, 0xff, 0x04, 0x00, 0x00, 0x86, 0x1f, 0xee, 0x04, 0x00,
+   0x00, 0x06, 0x06, 0xe6, 0x04, 0x00, 0x00, 0x06, 0x00, 0xe6, 0x04, 0x00,
+   0x00, 0x06, 0x00, 0xe6, 0x04, 0x00, 0x00, 0x06, 0x00, 0x66, 0x04, 0x00,
+   0x7f, 0x56, 0x52, 0x06, 0xe4, 0xff, 0x00, 0x76, 0x55, 0x06, 0x04, 0x00,
+   0x00, 0x56, 0x57, 0x06, 0x04, 0x00, 0x00, 0x56, 0x55, 0x06, 0x06, 0x00,
+   0x00, 0x56, 0xd5, 0x06, 0x03, 0x00, 0x00, 0x06, 0x00, 0x86, 0x01, 0x00,
+   0x54, 0x06, 0x00, 0xc6, 0x54, 0x55, 0xaa, 0x06, 0x00, 0x66, 0xaa, 0x2a,
+   0x54, 0x06, 0x00, 0x36, 0x55, 0x55, 0xaa, 0x06, 0x00, 0xbe, 0xaa, 0x2a,
+   0x54, 0xfe, 0xff, 0x6f, 0x55, 0x55, 0xaa, 0xfc, 0xff, 0xa7, 0xaa, 0x2a,
+   0x54, 0x01, 0x88, 0x60, 0x55, 0x55, 0xaa, 0xaa, 0x8a, 0xa0, 0xaa, 0x2a,
+   0x54, 0x55, 0x8d, 0x60, 0x55, 0x55, 0xaa, 0xaa, 0x8a, 0xa0, 0xaa, 0x2a,
+   0x54, 0x55, 0x8d, 0x60, 0x55, 0x55, 0xaa, 0xaa, 0x8a, 0xa0, 0xaa, 0x2a,
+   0x54, 0x55, 0x8d, 0x50, 0x55, 0x55, 0xaa, 0xaa, 0x8a, 0xa8, 0xaa, 0x2a,
+   0x54, 0x55, 0x95, 0x54, 0x55, 0x55, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0x2a,
+   0x54, 0x55, 0x55, 0x55, 0x55, 0x15, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
diff --git a/Xserver/include/bitmaps/flipped_gray b/Xserver/include/bitmaps/flipped_gray
new file mode 100644 (file)
index 0000000..b75cacd
--- /dev/null
@@ -0,0 +1,4 @@
+#define flipped_gray_width 4
+#define flipped_gray_height 2
+static char flipped_gray_bits[] = {
+   0x07, 0x0d};
diff --git a/Xserver/include/bitmaps/gray b/Xserver/include/bitmaps/gray
new file mode 100644 (file)
index 0000000..dc7327e
--- /dev/null
@@ -0,0 +1,4 @@
+#define gray_width 2
+#define gray_height 2
+static char gray_bits[] = {
+   0x01, 0x02};
diff --git a/Xserver/include/bitmaps/gray1 b/Xserver/include/bitmaps/gray1
new file mode 100644 (file)
index 0000000..476d930
--- /dev/null
@@ -0,0 +1,4 @@
+#define gray1_width 2
+#define gray1_height 2
+static char gray1_bits[] = {
+   0x01, 0x02};
diff --git a/Xserver/include/bitmaps/gray3 b/Xserver/include/bitmaps/gray3
new file mode 100644 (file)
index 0000000..2302884
--- /dev/null
@@ -0,0 +1,4 @@
+#define gray3_width 4
+#define gray3_height 4
+static char gray3_bits[] = {
+   0x01, 0x00, 0x04, 0x00};
diff --git a/Xserver/include/bitmaps/grid16 b/Xserver/include/bitmaps/grid16
new file mode 100644 (file)
index 0000000..edc7c73
--- /dev/null
@@ -0,0 +1,6 @@
+#define grid16_width 16
+#define grid16_height 16
+static char grid16_bits[] = {
+   0x55, 0x55, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
+   0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
+   0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00};
diff --git a/Xserver/include/bitmaps/grid2 b/Xserver/include/bitmaps/grid2
new file mode 100644 (file)
index 0000000..7a02167
--- /dev/null
@@ -0,0 +1,4 @@
+#define grid2_width 2
+#define grid2_height 2
+static char grid2_bits[] = {
+   0x01, 0x00};
diff --git a/Xserver/include/bitmaps/grid4 b/Xserver/include/bitmaps/grid4
new file mode 100644 (file)
index 0000000..8062f40
--- /dev/null
@@ -0,0 +1,4 @@
+#define grid4_width 4
+#define grid4_height 4
+static char grid4_bits[] = {
+   0x05, 0x00, 0x01, 0x00};
diff --git a/Xserver/include/bitmaps/grid8 b/Xserver/include/bitmaps/grid8
new file mode 100644 (file)
index 0000000..02ce50e
--- /dev/null
@@ -0,0 +1,4 @@
+#define grid8_width 8
+#define grid8_height 8
+static char grid8_bits[] = {
+   0x55, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00};
diff --git a/Xserver/include/bitmaps/hlines2 b/Xserver/include/bitmaps/hlines2
new file mode 100644 (file)
index 0000000..5c1a396
--- /dev/null
@@ -0,0 +1,4 @@
+#define hlines2_width 1
+#define hlines2_height 2
+static char hlines2_bits[] = {
+   0x01, 0x00};
diff --git a/Xserver/include/bitmaps/hlines3 b/Xserver/include/bitmaps/hlines3
new file mode 100644 (file)
index 0000000..ed49433
--- /dev/null
@@ -0,0 +1,4 @@
+#define hlines3_width 1
+#define hlines3_height 3
+static char hlines3_bits[] = {
+   0x00, 0x01, 0x00};
diff --git a/Xserver/include/bitmaps/icon b/Xserver/include/bitmaps/icon
new file mode 100644 (file)
index 0000000..9a75a57
--- /dev/null
@@ -0,0 +1,6 @@
+#define icon_width 16
+#define icon_height 16
+static char icon_bits[] = {
+   0xff, 0xff, 0xab, 0xaa, 0x55, 0xd5, 0xab, 0xaa, 0x05, 0xd0, 0x0b, 0xa0,
+   0x05, 0xd0, 0x0b, 0xa0, 0x05, 0xd0, 0x0b, 0xa0, 0x05, 0xd0, 0x0b, 0xa0,
+   0x55, 0xd5, 0xab, 0xaa, 0x55, 0xd5, 0xff, 0xff};
diff --git a/Xserver/include/bitmaps/keyboard16 b/Xserver/include/bitmaps/keyboard16
new file mode 100644 (file)
index 0000000..c4ead32
--- /dev/null
@@ -0,0 +1,6 @@
+#define keyboard16_width 16
+#define keyboard16_height 16
+static char keyboard16_bits[] = {
+   0x00, 0x00, 0x00, 0x00, 0xf0, 0x0f, 0x08, 0x10, 0x08, 0x10, 0x08, 0x10,
+   0x08, 0x10, 0xf0, 0x0f, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x0f, 0xa8, 0x1a,
+   0x54, 0x35, 0xfc, 0x3f, 0x00, 0x00, 0x00, 0x00};
diff --git a/Xserver/include/bitmaps/left_ptr b/Xserver/include/bitmaps/left_ptr
new file mode 100644 (file)
index 0000000..8a6abb1
--- /dev/null
@@ -0,0 +1,8 @@
+#define left_ptr_width 16
+#define left_ptr_height 16
+#define left_ptr_x_hot 3
+#define left_ptr_y_hot 1
+static char left_ptr_bits[] = {
+   0x00, 0x00, 0x08, 0x00, 0x18, 0x00, 0x38, 0x00, 0x78, 0x00, 0xf8, 0x00,
+   0xf8, 0x01, 0xf8, 0x03, 0xf8, 0x07, 0xf8, 0x00, 0xd8, 0x00, 0x88, 0x01,
+   0x80, 0x01, 0x00, 0x03, 0x00, 0x03, 0x00, 0x00};
diff --git a/Xserver/include/bitmaps/left_ptrmsk b/Xserver/include/bitmaps/left_ptrmsk
new file mode 100644 (file)
index 0000000..851911d
--- /dev/null
@@ -0,0 +1,6 @@
+#define left_ptrmsk_width 16
+#define left_ptrmsk_height 16
+static char left_ptrmsk_bits[] = {
+   0x0c, 0x00, 0x1c, 0x00, 0x3c, 0x00, 0x7c, 0x00, 0xfc, 0x00, 0xfc, 0x01,
+   0xfc, 0x03, 0xfc, 0x07, 0xfc, 0x0f, 0xfc, 0x0f, 0xfc, 0x01, 0xdc, 0x03,
+   0xcc, 0x03, 0x80, 0x07, 0x80, 0x07, 0x00, 0x03};
diff --git a/Xserver/include/bitmaps/letters b/Xserver/include/bitmaps/letters
new file mode 100644 (file)
index 0000000..0f12568
--- /dev/null
@@ -0,0 +1,27 @@
+#define letters_width 48
+#define letters_height 48
+static char letters_bits[] = {
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0xfe, 0xff, 0xff, 0xff, 0x3f, 0x00, 0x02, 0x00, 0x00, 0x00, 0x20,
+   0x00, 0xfa, 0x00, 0x00, 0x00, 0x2e, 0x00, 0x02, 0x00, 0x00, 0x00, 0x2a,
+   0x00, 0x3a, 0x00, 0x00, 0x00, 0x2a, 0x00, 0x02, 0x00, 0x00, 0x00, 0x2e,
+   0xe0, 0xff, 0xff, 0xff, 0xff, 0x21, 0x20, 0x00, 0x00, 0x00, 0x00, 0x21,
+   0xa0, 0x03, 0x00, 0x00, 0x70, 0x21, 0x20, 0x00, 0x00, 0x00, 0x50, 0x21,
+   0xa0, 0x1f, 0x00, 0x00, 0x50, 0x21, 0x20, 0x00, 0x00, 0x00, 0x70, 0x21,
+   0xfe, 0xff, 0xff, 0xff, 0x0f, 0x21, 0x02, 0x00, 0x00, 0x00, 0x08, 0x21,
+   0xfa, 0x01, 0x00, 0x80, 0x0b, 0x21, 0x02, 0x00, 0x00, 0x80, 0x0a, 0x21,
+   0xba, 0x01, 0x00, 0x80, 0x0a, 0x21, 0x02, 0x00, 0x00, 0x80, 0x0b, 0x21,
+   0x3a, 0x00, 0x00, 0x00, 0x08, 0x21, 0x02, 0x00, 0x00, 0x00, 0x08, 0x21,
+   0x02, 0xc0, 0xfb, 0x03, 0x08, 0x21, 0x02, 0x00, 0x00, 0x00, 0x08, 0x3f,
+   0x02, 0xc0, 0xbd, 0x0f, 0x08, 0x01, 0x02, 0x00, 0x00, 0x00, 0x08, 0x01,
+   0x02, 0xc0, 0x7f, 0x7b, 0x08, 0x01, 0x02, 0x00, 0x00, 0x00, 0x08, 0x01,
+   0x02, 0x00, 0x00, 0x00, 0xf8, 0x01, 0x02, 0x00, 0x00, 0x00, 0x08, 0x00,
+   0x02, 0x00, 0x00, 0x00, 0x08, 0x00, 0x02, 0x00, 0x00, 0x00, 0x08, 0x00,
+   0x02, 0x00, 0x00, 0x00, 0x08, 0x00, 0x02, 0x00, 0x00, 0x00, 0x08, 0x00,
+   0xfe, 0xff, 0xff, 0xff, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
diff --git a/Xserver/include/bitmaps/light_gray b/Xserver/include/bitmaps/light_gray
new file mode 100644 (file)
index 0000000..ea62e17
--- /dev/null
@@ -0,0 +1,4 @@
+#define light_gray_width 4
+#define light_gray_height 2
+static char light_gray_bits[] = {
+   0x08, 0x02};
diff --git a/Xserver/include/bitmaps/mailempty b/Xserver/include/bitmaps/mailempty
new file mode 100644 (file)
index 0000000..0642525
--- /dev/null
@@ -0,0 +1,27 @@
+#define mailempty_width 48
+#define mailempty_height 48
+static unsigned char mailempty_bits[] = {
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0xff, 0xff, 0xff, 0xff, 0x7f, 0x80, 0xff, 0xff, 0xff, 0xff, 0x7f,
+   0xc0, 0xaf, 0xaa, 0xaa, 0xaa, 0x7a, 0xe0, 0x57, 0x55, 0x55, 0x55, 0x7d,
+   0xf0, 0xaf, 0xaa, 0xaa, 0xaa, 0x7e, 0xf8, 0x57, 0x55, 0x55, 0x55, 0x7f,
+   0xfc, 0xaf, 0xaa, 0xaa, 0xaa, 0x7f, 0xfe, 0xff, 0xff, 0xff, 0xff, 0x7f,
+   0xfe, 0xff, 0xff, 0xff, 0xff, 0x7f, 0xfe, 0xab, 0xaa, 0xaa, 0xea, 0x7f,
+   0xfe, 0x55, 0x55, 0x55, 0xf5, 0x6f, 0xfe, 0xaa, 0xaa, 0xaa, 0xea, 0x67,
+   0x7e, 0x55, 0x55, 0x55, 0xf5, 0x63, 0xbe, 0xaa, 0xaa, 0xaa, 0xea, 0x61,
+   0xfe, 0xff, 0xff, 0xff, 0xff, 0x60, 0xfe, 0xff, 0xff, 0xff, 0x7f, 0x60,
+   0x06, 0x06, 0x00, 0x00, 0x60, 0x60, 0x06, 0x06, 0x00, 0x00, 0x60, 0x60,
+   0x06, 0x06, 0x00, 0x00, 0x60, 0x60, 0x06, 0x06, 0x00, 0x00, 0x60, 0x60,
+   0x06, 0x06, 0x00, 0x00, 0x60, 0x60, 0x06, 0xfe, 0xff, 0xff, 0xff, 0x7f,
+   0x06, 0xff, 0xff, 0xff, 0xff, 0x7f, 0x86, 0xaf, 0xaa, 0xaa, 0xea, 0x7a,
+   0xc6, 0x57, 0x55, 0x55, 0x75, 0x7d, 0xe6, 0xaf, 0xaa, 0xaa, 0xea, 0x7e,
+   0xf6, 0x57, 0x55, 0x55, 0x75, 0x7f, 0xfe, 0xaf, 0xaa, 0xaa, 0xea, 0x7f,
+   0xfe, 0xff, 0xff, 0xff, 0xff, 0x7f, 0xfe, 0xff, 0xff, 0xff, 0xff, 0x7f,
+   0xfe, 0xab, 0xaa, 0xaa, 0xea, 0x7f, 0xfe, 0x55, 0x55, 0x55, 0xf5, 0x6f,
+   0xfe, 0xaa, 0xaa, 0xaa, 0xea, 0x67, 0x7e, 0x55, 0x55, 0x55, 0xf5, 0x63,
+   0xbe, 0xaa, 0xaa, 0xaa, 0xea, 0x61, 0xfe, 0xff, 0xff, 0xff, 0xff, 0x60,
+   0xfe, 0xff, 0xff, 0xff, 0x7f, 0x60, 0x06, 0x06, 0x00, 0x00, 0x60, 0x00,
+   0x06, 0x00, 0x00, 0x00, 0x60, 0x00, 0x06, 0x00, 0x00, 0x00, 0x60, 0x00,
+   0x06, 0x00, 0x00, 0x00, 0x60, 0x00, 0x06, 0x00, 0x00, 0x00, 0x60, 0x00,
+   0x06, 0x00, 0x00, 0x00, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
diff --git a/Xserver/include/bitmaps/mailemptymsk b/Xserver/include/bitmaps/mailemptymsk
new file mode 100644 (file)
index 0000000..f1204b2
--- /dev/null
@@ -0,0 +1,27 @@
+#define mailemask_width 48
+#define mailemask_height 48
+static char mailemask_bits[] = {
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff,
+   0x80, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc0, 0xff, 0xff, 0xff, 0xff, 0xff,
+   0xe0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf0, 0xff, 0xff, 0xff, 0xff, 0xff,
+   0xf8, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfc, 0xff, 0xff, 0xff, 0xff, 0xff,
+   0xfe, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+   0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+   0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+   0xff, 0xff, 0xff, 0xff, 0xff, 0xf7, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf3,
+   0xff, 0xff, 0xff, 0xff, 0xff, 0xf1, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf0,
+   0xff, 0xff, 0xff, 0xff, 0xff, 0xf0, 0x0f, 0x0f, 0x00, 0x00, 0xf0, 0xf0,
+   0x0f, 0x0f, 0x00, 0x00, 0xf0, 0xf0, 0x0f, 0x0f, 0x00, 0x00, 0xf0, 0xf0,
+   0x0f, 0xff, 0xff, 0xff, 0xff, 0xff, 0x0f, 0xff, 0xff, 0xff, 0xff, 0xff,
+   0x8f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xcf, 0xff, 0xff, 0xff, 0xff, 0xff,
+   0xef, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+   0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+   0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+   0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+   0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf7,
+   0xff, 0xff, 0xff, 0xff, 0xff, 0xf3, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf1,
+   0xff, 0xff, 0xff, 0xff, 0xff, 0xf0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf0,
+   0x0f, 0x0f, 0x00, 0x00, 0xf0, 0x00, 0x0f, 0x00, 0x00, 0x00, 0xf0, 0x00,
+   0x0f, 0x00, 0x00, 0x00, 0xf0, 0x00, 0x0f, 0x00, 0x00, 0x00, 0xf0, 0x00,
+   0x0f, 0x00, 0x00, 0x00, 0xf0, 0x00, 0x0f, 0x00, 0x00, 0x00, 0xf0, 0x00};
diff --git a/Xserver/include/bitmaps/mailfull b/Xserver/include/bitmaps/mailfull
new file mode 100644 (file)
index 0000000..cc2f6f8
--- /dev/null
@@ -0,0 +1,27 @@
+#define mailfull_width 48
+#define mailfull_height 48
+static unsigned char mailfull_bits[] = {
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0xff, 0xff, 0xff, 0x07,
+   0xc0, 0xff, 0xff, 0xff, 0x1f, 0x04, 0x40, 0x00, 0x00, 0x00, 0xd0, 0x05,
+   0x40, 0x00, 0x00, 0x00, 0x57, 0x7d, 0x40, 0x1e, 0x00, 0x00, 0x55, 0x7d,
+   0x40, 0x00, 0x00, 0x00, 0xd5, 0x7d, 0x60, 0x02, 0x00, 0x00, 0x17, 0x7c,
+   0x70, 0x00, 0x7e, 0x00, 0x10, 0x7c, 0x78, 0x00, 0x00, 0x00, 0x10, 0x7e,
+   0x7c, 0x00, 0x1e, 0x00, 0x10, 0x7f, 0x7e, 0x00, 0x00, 0x00, 0x90, 0x7f,
+   0x7e, 0x00, 0x3e, 0x07, 0xd0, 0x7f, 0x7e, 0x00, 0x00, 0x00, 0xf0, 0x7f,
+   0x7e, 0x00, 0x00, 0x00, 0xf0, 0x6f, 0x7e, 0x00, 0x00, 0x00, 0xf0, 0x67,
+   0xfe, 0xff, 0xff, 0xff, 0xff, 0x63, 0xbe, 0xaa, 0xaa, 0xaa, 0xea, 0x61,
+   0xfe, 0xff, 0xff, 0xff, 0xff, 0x60, 0xfe, 0xff, 0xff, 0xff, 0x7f, 0x60,
+   0x06, 0x06, 0x00, 0x00, 0x60, 0x60, 0x06, 0x06, 0x00, 0x00, 0x60, 0x60,
+   0x06, 0x06, 0x00, 0x00, 0x60, 0x60, 0x06, 0x06, 0x00, 0x00, 0x60, 0x60,
+   0x06, 0x06, 0x00, 0x00, 0x60, 0x60, 0x06, 0xff, 0xff, 0xff, 0xff, 0x7f,
+   0x86, 0xff, 0xff, 0xff, 0xff, 0x7f, 0xc6, 0xaf, 0xaa, 0xaa, 0xea, 0x7a,
+   0xe6, 0x57, 0x55, 0x55, 0x75, 0x7d, 0xf6, 0xaf, 0xaa, 0xaa, 0xea, 0x7e,
+   0xfe, 0x57, 0x55, 0x55, 0x75, 0x7f, 0xfe, 0xaf, 0xaa, 0xaa, 0xea, 0x7f,
+   0xfe, 0xff, 0xff, 0xff, 0xff, 0x7f, 0xfe, 0xff, 0xff, 0xff, 0xff, 0x7f,
+   0xfe, 0xab, 0xaa, 0xaa, 0xea, 0x7f, 0xfe, 0x55, 0x55, 0x55, 0xf5, 0x6f,
+   0xfe, 0xaa, 0xaa, 0xaa, 0xea, 0x67, 0x7e, 0x55, 0x55, 0x55, 0xf5, 0x63,
+   0xbe, 0xaa, 0xaa, 0xaa, 0xea, 0x61, 0xfe, 0xff, 0xff, 0xff, 0xff, 0x60,
+   0xfe, 0xff, 0xff, 0xff, 0x7f, 0x60, 0x06, 0x06, 0x00, 0x00, 0x60, 0x60,
+   0x06, 0x00, 0x00, 0x00, 0x60, 0x00, 0x06, 0xee, 0x9c, 0x37, 0x60, 0x00,
+   0x06, 0xfe, 0x36, 0x33, 0x60, 0x00, 0x06, 0xd6, 0x3e, 0x33, 0x60, 0x00,
+   0x06, 0xc6, 0xb6, 0xf7, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
diff --git a/Xserver/include/bitmaps/mailfullmsk b/Xserver/include/bitmaps/mailfullmsk
new file mode 100644 (file)
index 0000000..6dfc942
--- /dev/null
@@ -0,0 +1,27 @@
+#define mailfullmsk_width 48
+#define mailfullmsk_height 48
+static char mailfullmsk_bits[] = {
+   0x00, 0xe0, 0xff, 0xff, 0xff, 0x0f, 0xe0, 0xff, 0xff, 0xff, 0xff, 0x0f,
+   0xe0, 0xff, 0xff, 0xff, 0xff, 0x0f, 0xe0, 0xff, 0xff, 0xff, 0xff, 0xff,
+   0xe0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xe0, 0xff, 0xff, 0xff, 0xff, 0xff,
+   0xe0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf0, 0xff, 0xff, 0xff, 0xff, 0xff,
+   0xf8, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfc, 0xff, 0xff, 0xff, 0xff, 0xff,
+   0xfe, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+   0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+   0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+   0xff, 0xff, 0xff, 0xff, 0xff, 0xf7, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf3,
+   0xff, 0xff, 0xff, 0xff, 0xff, 0xf1, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf0,
+   0xff, 0xff, 0xff, 0xff, 0xff, 0xf0, 0x0f, 0x0f, 0x00, 0x00, 0xf0, 0xf0,
+   0x0f, 0x0f, 0x00, 0x00, 0xf0, 0xf0, 0x0f, 0x0f, 0x00, 0x00, 0xf0, 0xf0,
+   0x0f, 0xff, 0xff, 0xff, 0xff, 0xff, 0x8f, 0xff, 0xff, 0xff, 0xff, 0xff,
+   0xcf, 0xff, 0xff, 0xff, 0xff, 0xff, 0xef, 0xff, 0xff, 0xff, 0xff, 0xff,
+   0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+   0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+   0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+   0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+   0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf7,
+   0xff, 0xff, 0xff, 0xff, 0xff, 0xf3, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf1,
+   0xff, 0xff, 0xff, 0xff, 0xff, 0xf0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf0,
+   0x0f, 0xff, 0xff, 0xff, 0xf1, 0xf0, 0x0f, 0xff, 0xff, 0xff, 0xf1, 0x00,
+   0x0f, 0xff, 0xff, 0xff, 0xf1, 0x00, 0x0f, 0xff, 0xff, 0xff, 0xf1, 0x00,
+   0x0f, 0xff, 0xff, 0xff, 0xf1, 0x00, 0x0f, 0xff, 0xff, 0xff, 0xf1, 0x00};
diff --git a/Xserver/include/bitmaps/mensetmanus b/Xserver/include/bitmaps/mensetmanus
new file mode 100644 (file)
index 0000000..095b8ec
--- /dev/null
@@ -0,0 +1,258 @@
+#define mensetmanus_width 161
+#define mensetmanus_height 145
+
+static char mensetmanus_bits[] = {
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0xc0, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0xff,
+ 0x01, 0x00, 0x00, 0x00, 0x00, 0xfc, 0xff, 0xff, 0x7f, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0x07, 0x00, 0x00,
+ 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x3f, 0xdb, 0x0f, 0x00, 0x00, 0x00, 0x80, 0x07,
+ 0x00, 0x00, 0xe0, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0xf7, 0xff, 0x0f, 0x00, 0x00, 0x00, 0x80, 0x61, 0x00, 0x00, 0xc6,
+ 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xc3, 0xff,
+ 0x1f, 0x00, 0x00, 0x00, 0xc0, 0xe1, 0xff, 0xff, 0x87, 0x01, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xc3, 0xf6, 0x1f, 0x00, 0x00,
+ 0x00, 0xc0, 0xc0, 0xff, 0xff, 0x87, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x80, 0x9f, 0x65, 0x1f, 0x00, 0x00, 0x00, 0xc0, 0x00,
+ 0x07, 0x80, 0x87, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x80, 0x9f, 0x6d, 0x1f, 0x00, 0x00, 0x00, 0xc0, 0x00, 0xff, 0xff, 0xc7,
+ 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x89, 0x6d,
+ 0x1b, 0x00, 0x00, 0x00, 0xc0, 0xe0, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x81, 0x6d, 0x1b, 0x00, 0x00,
+ 0x00, 0xc0, 0xe1, 0x5b, 0xdb, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0xc0, 0x81, 0x6d, 0x1b, 0x00, 0x00, 0x00, 0x80, 0x83,
+ 0x5b, 0xdb, 0x1c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0xc0, 0x81, 0x6d, 0x1b, 0x00, 0x00, 0x00, 0x00, 0xcf, 0x5b, 0x1b, 0x0c,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x80, 0x6d,
+ 0x1b, 0x00, 0x00, 0x00, 0x00, 0xfe, 0x5b, 0x1b, 0x0c, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x80, 0x6d, 0x1b, 0x00, 0x00,
+ 0x00, 0x00, 0xf8, 0x5b, 0x0b, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0xe0, 0x83, 0x6d, 0x19, 0x00, 0x00, 0x00, 0x00, 0x80,
+ 0x5b, 0x0b, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0xe0, 0x83, 0x6d, 0x1b, 0x00, 0x00, 0x00, 0x00, 0x80, 0x5b, 0x0f, 0x0e,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x83, 0x6d,
+ 0x1b, 0x00, 0x00, 0x00, 0x00, 0x80, 0x4b, 0x0f, 0x07, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x83, 0x79, 0x1b, 0x00, 0x00,
+ 0x00, 0x00, 0x80, 0x6b, 0xbf, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x03, 0xfb, 0x3b, 0x00, 0x00, 0x00, 0x00, 0x80,
+ 0x6d, 0xb7, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x03, 0xff, 0x3f, 0x00, 0x00, 0x00, 0x00, 0xc0, 0xed, 0xf7, 0x07,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x07, 0xfe,
+ 0x7f, 0x00, 0x00, 0x00, 0x00, 0xc0, 0xed, 0xd7, 0x07, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfc, 0x7f, 0xf8, 0xff, 0x07, 0x00,
+ 0x00, 0x00, 0xe0, 0xfe, 0xd7, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x80, 0xff, 0x7f, 0xe0, 0xff, 0x3f, 0x00, 0x00, 0x00, 0xf0,
+ 0xff, 0xd6, 0xfe, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0,
+ 0xbf, 0x73, 0x80, 0x3b, 0x7c, 0x00, 0x00, 0x00, 0xf8, 0xe7, 0xd6, 0xef,
+ 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0xb9, 0x73, 0xc0,
+ 0x3b, 0xf0, 0x01, 0x00, 0x00, 0xff, 0xc3, 0xbf, 0xe7, 0x3f, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x78, 0xb8, 0x7f, 0xe0, 0x3b, 0xc0, 0x03,
+ 0x00, 0xc0, 0xbf, 0xc7, 0xbf, 0xe7, 0x7e, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x1c, 0xb8, 0xff, 0xf8, 0x3b, 0x80, 0x07, 0x00, 0xe0, 0x61,
+ 0x87, 0xfd, 0xe7, 0xe6, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0e,
+ 0xb8, 0xf3, 0xff, 0x3b, 0x00, 0x0f, 0x00, 0x78, 0x60, 0x8e, 0xf1, 0x67,
+ 0xc7, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0xb8, 0xc3, 0x8f,
+ 0x7b, 0x00, 0x0e, 0x00, 0x38, 0xe0, 0x8c, 0x03, 0x66, 0x87, 0x03, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x80, 0x07, 0xb8, 0x03, 0x83, 0x7b, 0x00, 0x1e,
+ 0x00, 0x1c, 0xe0, 0x1d, 0x03, 0x76, 0x07, 0x07, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0xc0, 0x07, 0xb8, 0xe3, 0x8f, 0xbb, 0x01, 0x39, 0x00, 0x1e, 0xe0,
+ 0x3b, 0x03, 0xf6, 0x87, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x0f,
+ 0xb8, 0xe3, 0x8f, 0x3b, 0xc6, 0x38, 0x00, 0x17, 0xe0, 0x73, 0x07, 0xfe,
+ 0xff, 0xff, 0x7f, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x0b, 0xb8, 0xe7, 0x8e,
+ 0x3b, 0x38, 0x78, 0x00, 0x13, 0xe0, 0x77, 0x06, 0xfe, 0xff, 0xff, 0xff,
+ 0x0f, 0x00, 0x00, 0x00, 0xe0, 0x12, 0x3c, 0xff, 0xce, 0x3b, 0x00, 0x78,
+ 0x80, 0x13, 0x60, 0xef, 0x0e, 0xfe, 0x00, 0x00, 0x60, 0x08, 0x00, 0x00,
+ 0x00, 0x70, 0x22, 0x3e, 0xfc, 0xfe, 0x39, 0x00, 0xe8, 0x80, 0x61, 0x60,
+ 0xce, 0x0f, 0xfe, 0x00, 0x00, 0x60, 0xf8, 0x00, 0x00, 0x00, 0x70, 0xc2,
+ 0x39, 0xf8, 0x7e, 0x38, 0x00, 0xc8, 0xc0, 0x81, 0x71, 0xde, 0x0f, 0xfe,
+ 0x00, 0x00, 0x60, 0x88, 0x00, 0x00, 0x00, 0x70, 0x04, 0x38, 0xe0, 0x0e,
+ 0x38, 0x00, 0xc4, 0xc0, 0x01, 0x7e, 0xbc, 0x1f, 0xfe, 0x00, 0x00, 0x60,
+ 0x88, 0x00, 0x00, 0x00, 0x78, 0x04, 0x38, 0xe0, 0x0e, 0x38, 0x00, 0xc4,
+ 0xc1, 0x01, 0x60, 0x3c, 0x1f, 0xfe, 0x00, 0x00, 0x60, 0x84, 0x0f, 0x00,
+ 0x00, 0x78, 0x08, 0x38, 0xe0, 0x0f, 0x38, 0x00, 0x82, 0xe1, 0x01, 0x60,
+ 0x74, 0x3e, 0xfe, 0x00, 0x00, 0x60, 0x44, 0x08, 0x00, 0x00, 0xb8, 0x10,
+ 0x38, 0xe0, 0x0f, 0x38, 0x00, 0x81, 0xe1, 0x00, 0x60, 0xe4, 0x3e, 0xfe,
+ 0x00, 0x00, 0x60, 0x44, 0x08, 0x00, 0x00, 0x98, 0x20, 0x38, 0xf8, 0x3f,
+ 0x38, 0x80, 0x80, 0xe1, 0x01, 0x60, 0xc4, 0x3c, 0xfe, 0x00, 0x00, 0x60,
+ 0x24, 0x0c, 0x00, 0x00, 0x1c, 0xc1, 0x39, 0x3c, 0x78, 0x38, 0x40, 0x80,
+ 0x61, 0x01, 0x60, 0xc4, 0x79, 0xfe, 0x00, 0x00, 0x60, 0x22, 0x32, 0x00,
+ 0x00, 0x1c, 0x01, 0x3e, 0x1c, 0xf0, 0x38, 0xf0, 0x9f, 0x61, 0x01, 0x60,
+ 0x84, 0x7b, 0xee, 0x00, 0x00, 0x60, 0x12, 0x21, 0x00, 0x00, 0x1c, 0x02,
+ 0x38, 0x0e, 0xe7, 0xf8, 0x3f, 0xe0, 0x61, 0x00, 0x60, 0x04, 0xf7, 0xce,
+ 0x00, 0x00, 0x60, 0x92, 0x10, 0x00, 0x00, 0x1c, 0x04, 0x38, 0x06, 0xff,
+ 0x38, 0x40, 0x80, 0x61, 0x02, 0x60, 0x04, 0xe7, 0xcf, 0x00, 0x00, 0x60,
+ 0x8a, 0x18, 0x00, 0x00, 0x1c, 0x18, 0x38, 0x07, 0xf0, 0x38, 0x00, 0x81,
+ 0x61, 0x02, 0x60, 0x04, 0xee, 0xcf, 0xff, 0x03, 0x60, 0x49, 0xe4, 0x00,
+ 0x00, 0x1c, 0x70, 0x38, 0x07, 0xe7, 0x38, 0x00, 0x82, 0x61, 0x04, 0x60,
+ 0x04, 0xdc, 0xcf, 0x01, 0x04, 0x60, 0x25, 0x42, 0x00, 0x00, 0x1c, 0xfe,
+ 0x3f, 0x03, 0xff, 0x38, 0x00, 0x84, 0x61, 0x08, 0x60, 0x04, 0xfc, 0xcf,
+ 0xf8, 0xff, 0x60, 0x95, 0x31, 0x00, 0x00, 0xfc, 0x01, 0xff, 0x03, 0xf0,
+ 0xf8, 0x1f, 0x88, 0x61, 0x10, 0xe0, 0xff, 0xff, 0xff, 0x00, 0x00, 0xe1,
+ 0x53, 0x0c, 0x00, 0x00, 0x38, 0xf0, 0xff, 0x03, 0xef, 0xf8, 0x7f, 0x90,
+ 0x61, 0x40, 0xe0, 0xff, 0xff, 0xff, 0x00, 0xff, 0xe3, 0x2b, 0xfe, 0x00,
+ 0x00, 0x18, 0xf8, 0xff, 0x03, 0xff, 0x7c, 0xf0, 0x90, 0x61, 0x00, 0x3e,
+ 0x36, 0xe3, 0xe1, 0x00, 0x00, 0xe3, 0x9f, 0x60, 0x00, 0x00, 0x38, 0x3c,
+ 0x00, 0x03, 0xf0, 0x1f, 0xe0, 0xa0, 0xe1, 0x00, 0x30, 0x22, 0xe2, 0xc0,
+ 0x00, 0xff, 0xe3, 0x7f, 0x18, 0x00, 0x00, 0x38, 0x0e, 0x00, 0x07, 0xe7,
+ 0x07, 0xc0, 0xe1, 0xc1, 0x00, 0x18, 0x22, 0xe2, 0xc0, 0x00, 0x00, 0xe1,
+ 0x1f, 0x07, 0x00, 0x00, 0x38, 0x06, 0x00, 0x07, 0xef, 0x01, 0xc0, 0xc1,
+ 0xc1, 0x01, 0x16, 0x24, 0xe2, 0xc0, 0x01, 0xff, 0xe1, 0xff, 0x00, 0x00,
+ 0x00, 0x70, 0x07, 0x00, 0x0e, 0xf8, 0x00, 0x80, 0xc3, 0xc0, 0xf1, 0x11,
+ 0x24, 0xe4, 0xc0, 0x03, 0xe0, 0xe1, 0x7f, 0x00, 0x00, 0x00, 0x70, 0x07,
+ 0x00, 0x1e, 0x3c, 0x00, 0x80, 0xe3, 0x80, 0x0f, 0x10, 0x24, 0xe4, 0xc0,
+ 0xff, 0xff, 0xff, 0xff, 0xff, 0x01, 0x00, 0xe0, 0x03, 0x00, 0xfc, 0x0f,
+ 0x00, 0x00, 0x63, 0x80, 0x01, 0x08, 0x44, 0xe4, 0xc0, 0xff, 0xff, 0xff,
+ 0xff, 0xff, 0x01, 0x00, 0xe0, 0x03, 0x00, 0xf8, 0x07, 0x00, 0x00, 0x73,
+ 0x80, 0x03, 0x08, 0x44, 0xe4, 0xc0, 0xfc, 0x00, 0x07, 0x0e, 0x00, 0x00,
+ 0x00, 0xc0, 0x03, 0x00, 0xf0, 0x01, 0x00, 0x00, 0x33, 0x00, 0x03, 0x08,
+ 0x44, 0xe4, 0xe0, 0xcc, 0x00, 0x07, 0x0e, 0x00, 0x00, 0x00, 0xc0, 0x03,
+ 0x00, 0x78, 0x00, 0x00, 0x80, 0x3f, 0x00, 0x07, 0x04, 0x44, 0xe8, 0x70,
+ 0xcc, 0x01, 0x87, 0x0f, 0x00, 0x00, 0x00, 0x80, 0x07, 0x00, 0x3e, 0x00,
+ 0x00, 0x80, 0x1f, 0x00, 0x0e, 0x04, 0x44, 0xe8, 0x38, 0xcc, 0x81, 0xe7,
+ 0x03, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x0f, 0x00, 0x00, 0x80, 0x0f,
+ 0x00, 0x1c, 0x02, 0x44, 0xf8, 0x1e, 0xcc, 0xe1, 0xff, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x0f, 0xc0, 0x23, 0x00, 0x00, 0xc0, 0x07, 0x00, 0x38, 0x01,
+ 0x42, 0xfc, 0x0f, 0xcc, 0xf1, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0e,
+ 0xf0, 0x39, 0x00, 0x00, 0xe0, 0x03, 0x00, 0xf0, 0x00, 0xc2, 0xff, 0x07,
+ 0xcc, 0x7f, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3c, 0x7c, 0x0e, 0x00,
+ 0x00, 0xf0, 0x01, 0x00, 0xe0, 0x03, 0xe2, 0xe7, 0x07, 0xcc, 0x1f, 0x07,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0xbf, 0x23, 0xe0, 0xff, 0xff, 0x00,
+ 0x00, 0xc0, 0x1f, 0xff, 0x64, 0x06, 0xcc, 0x07, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0xf0, 0xff, 0x3c, 0xf0, 0xff, 0x7f, 0x00, 0x00, 0x00, 0xff,
+ 0x7f, 0x64, 0x06, 0xcc, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x70,
+ 0xf8, 0x1f, 0x78, 0x7c, 0x7f, 0x00, 0x00, 0x00, 0xfc, 0x20, 0x64, 0x06,
+ 0xcc, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x70, 0xf8, 0x33, 0x1c,
+ 0x38, 0x66, 0x00, 0x00, 0x00, 0x0c, 0x20, 0x6c, 0x06, 0xcc, 0x03, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x78, 0x3e, 0x0e, 0x38, 0x76, 0x00,
+ 0x00, 0x00, 0x0c, 0x20, 0x68, 0x06, 0xcc, 0x03, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x38, 0xf8, 0x87, 0x0f, 0x38, 0x76, 0x00, 0x00, 0x00, 0x0c,
+ 0x20, 0x68, 0x06, 0xcc, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x38,
+ 0x78, 0xf8, 0x0f, 0x38, 0x76, 0x00, 0x00, 0x00, 0x0c, 0x10, 0x68, 0x06,
+ 0xcc, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0xf8, 0xff, 0x0f,
+ 0x38, 0x76, 0x00, 0x00, 0x00, 0x0c, 0x10, 0x68, 0x06, 0xcc, 0x07, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x1c, 0xf8, 0xff, 0x0e, 0x38, 0x76, 0x00,
+ 0x00, 0x00, 0x0c, 0x10, 0x68, 0x06, 0xcc, 0x07, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x1c, 0xf8, 0xe1, 0x0e, 0x38, 0x3e, 0x00, 0x00, 0x00, 0x0c,
+ 0x08, 0x68, 0x06, 0xcc, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c,
+ 0x38, 0xe0, 0x0e, 0x38, 0x3e, 0x00, 0x00, 0x00, 0x0c, 0x08, 0x68, 0x06,
+ 0xcc, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x38, 0xe0, 0x0e,
+ 0x38, 0x3e, 0x00, 0x00, 0x00, 0x0c, 0x04, 0x68, 0x06, 0xcc, 0x0e, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x38, 0xe0, 0x0e, 0x38, 0x3e, 0x00,
+ 0x00, 0x00, 0x1c, 0x04, 0x68, 0x06, 0xcc, 0x0e, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x06, 0x38, 0xe0, 0x0e, 0x38, 0x3e, 0x00, 0x00, 0x00, 0x1c,
+ 0x02, 0x68, 0x06, 0xcc, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06,
+ 0x38, 0xe0, 0x0e, 0x38, 0x3e, 0x00, 0x00, 0x00, 0x1c, 0x02, 0x68, 0x06,
+ 0xcc, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x38, 0xe0, 0x0e,
+ 0x38, 0x3e, 0x00, 0x00, 0x00, 0x1c, 0x01, 0x68, 0x06, 0xcc, 0x1c, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x38, 0xe0, 0x0e, 0x38, 0x3e, 0x00,
+ 0x00, 0x00, 0x18, 0x01, 0x68, 0x06, 0xcc, 0x1c, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x03, 0x38, 0xe0, 0x0e, 0x38, 0x3e, 0x00, 0x00, 0x00, 0x98,
+ 0x00, 0x68, 0x06, 0xcc, 0x1c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x03,
+ 0x38, 0xe0, 0x0e, 0x38, 0x3e, 0x00, 0x00, 0x00, 0x98, 0x00, 0x68, 0x06,
+ 0xcc, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x03, 0x38, 0xe0, 0x0e,
+ 0x38, 0x1e, 0x00, 0x00, 0x00, 0x58, 0x00, 0x6c, 0x0e, 0xcc, 0x18, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x80, 0x01, 0x30, 0xe0, 0x0e, 0x38, 0x1e, 0x00,
+ 0x00, 0x00, 0x38, 0x00, 0x64, 0x0e, 0xcc, 0x18, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0xc0, 0x01, 0x70, 0xe0, 0x0e, 0x1c, 0x1e, 0x00, 0x00, 0x00, 0x18,
+ 0x00, 0x64, 0x1e, 0xcc, 0x38, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x01,
+ 0xe0, 0xe1, 0x0e, 0x0f, 0x1e, 0x00, 0x00, 0x00, 0x18, 0x00, 0x64, 0x3e,
+ 0xcc, 0x38, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x00, 0xc0, 0xef, 0xce,
+ 0x07, 0x1e, 0x00, 0x00, 0x00, 0x18, 0x00, 0x64, 0x3e, 0xcc, 0x30, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0xe0, 0x00, 0x00, 0xff, 0xfe, 0x03, 0x1e, 0x00,
+ 0x00, 0x00, 0x18, 0x00, 0x64, 0x7e, 0xcc, 0x30, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0xe0, 0x00, 0x00, 0xfc, 0xfe, 0x00, 0x1e, 0x00, 0x00, 0x00, 0x18,
+ 0x00, 0x64, 0x66, 0xcc, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x00,
+ 0x00, 0xe0, 0x1e, 0x00, 0x1e, 0x00, 0x00, 0x00, 0x18, 0x00, 0x66, 0xe6,
+ 0xcc, 0x70, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x00, 0x00, 0xe0, 0x0e,
+ 0x00, 0x1e, 0x00, 0x00, 0x00, 0x18, 0x00, 0x62, 0xc6, 0xcd, 0x70, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0xfe, 0xff, 0x0f, 0x1e, 0x00,
+ 0x00, 0x00, 0x18, 0x00, 0x62, 0xc6, 0xcd, 0x70, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x70, 0x00, 0xc0, 0xff, 0xff, 0x0f, 0x0e, 0x00, 0x00, 0x00, 0x38,
+ 0x00, 0x62, 0x86, 0xcf, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x00,
+ 0xf0, 0xff, 0xff, 0x0f, 0x0e, 0x00, 0x00, 0x00, 0x38, 0x00, 0x61, 0x86,
+ 0xcf, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x38, 0x00, 0xfc, 0x00, 0x00,
+ 0x0e, 0x0e, 0x00, 0x00, 0x00, 0x38, 0x00, 0x61, 0x8e, 0xcf, 0xe0, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x38, 0x00, 0x78, 0x00, 0x00, 0x0e, 0x0e, 0x00,
+ 0x00, 0x00, 0xf8, 0xff, 0x7f, 0xfe, 0xdf, 0xff, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x18, 0x00, 0xf0, 0x00, 0x00, 0x0e, 0x0e, 0x00, 0x00, 0x00, 0xf0,
+ 0xff, 0x3f, 0xff, 0xdf, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1c, 0x00,
+ 0xe0, 0x01, 0x00, 0x0e, 0x0e, 0x00, 0x00, 0x00, 0xf0, 0xff, 0x8f, 0x07,
+ 0x9e, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1c, 0x00, 0xe0, 0x07, 0x00,
+ 0x0e, 0x0f, 0x00, 0x00, 0x00, 0x30, 0x00, 0xc0, 0xff, 0x3f, 0xc0, 0x01,
+ 0x00, 0x00, 0x00, 0x00, 0x1c, 0x00, 0xfe, 0xff, 0xff, 0xff, 0x0f, 0x00,
+ 0x00, 0x00, 0xf0, 0xff, 0xff, 0xff, 0xff, 0xff, 0x01, 0x00, 0x00, 0x00,
+ 0x00, 0x1c, 0x00, 0xfe, 0xff, 0xff, 0xff, 0x07, 0x00, 0x00, 0x00, 0xf0,
+ 0xff, 0xff, 0x00, 0xff, 0xff, 0x01, 0x00, 0x00, 0x00, 0x00, 0xfe, 0xff,
+ 0x3f, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x38, 0x00,
+ 0x38, 0xe0, 0x01, 0x00, 0x00, 0x00, 0x00, 0xfe, 0xff, 0x7f, 0x00, 0x00,
+ 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x06, 0x38, 0x00, 0x38, 0xe0, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0xe0, 0x00, 0x7c, 0x00, 0x00, 0x00, 0x06, 0x00,
+ 0x00, 0x00, 0x00, 0x06, 0x18, 0x00, 0x38, 0xe0, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0xe0, 0x00, 0xfc, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00,
+ 0x06, 0x18, 0x00, 0x38, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x00,
+ 0xdc, 0x01, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x06, 0x1c, 0x00,
+ 0x38, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x00, 0x9c, 0x03, 0x00,
+ 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x06, 0x1c, 0x00, 0x18, 0x70, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0xe0, 0x00, 0x1c, 0x07, 0x00, 0x00, 0x06, 0x00,
+ 0x00, 0x00, 0x00, 0x07, 0x0c, 0x00, 0x18, 0x70, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0xe0, 0x00, 0x1c, 0xfe, 0xff, 0xff, 0x07, 0x00, 0x00, 0x00, 0x00,
+ 0x07, 0x0c, 0x00, 0x18, 0x70, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x00,
+ 0x1c, 0xfc, 0xff, 0xff, 0x07, 0x00, 0x00, 0x00, 0x00, 0x07, 0x0c, 0x00,
+ 0x18, 0x70, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x00, 0x1c, 0x1c, 0x00,
+ 0x80, 0x07, 0x00, 0x00, 0x00, 0x00, 0x07, 0x0e, 0x00, 0x18, 0x70, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0xe0, 0x00, 0x1c, 0x1c, 0x00, 0x80, 0x03, 0x00,
+ 0x00, 0x00, 0x00, 0x07, 0x0e, 0x00, 0x18, 0x30, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0xe0, 0x00, 0x1c, 0x1c, 0x00, 0x80, 0x03, 0x00, 0x00, 0x00, 0x00,
+ 0x07, 0x0e, 0x00, 0x18, 0x38, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x00,
+ 0x1c, 0x1c, 0x00, 0x80, 0x03, 0x00, 0x00, 0x00, 0x00, 0x07, 0x0e, 0x00,
+ 0x18, 0x38, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x00, 0x1c, 0x1c, 0x00,
+ 0x80, 0x03, 0x00, 0x00, 0x00, 0x00, 0x07, 0x06, 0x00, 0x18, 0x38, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0xe0, 0x00, 0xfc, 0xff, 0xff, 0xff, 0x07, 0x00,
+ 0x00, 0x00, 0x00, 0x07, 0x06, 0x00, 0x18, 0x38, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0xe0, 0x00, 0xfc, 0xff, 0xff, 0xff, 0x07, 0x00, 0x00, 0x00, 0x00,
+ 0x07, 0x0e, 0x00, 0x18, 0x38, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x00,
+ 0x1c, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x07, 0x0e, 0x00,
+ 0x18, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x00, 0x1c, 0x00, 0x00,
+ 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x07, 0x0e, 0x00, 0x18, 0x30, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0xe0, 0x00, 0x1c, 0x00, 0x00, 0x00, 0x06, 0x00,
+ 0x00, 0x00, 0x00, 0x07, 0x0e, 0x00, 0x18, 0x70, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0xe0, 0x00, 0x1c, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00,
+ 0x07, 0x0e, 0x00, 0x18, 0x70, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x00,
+ 0x1e, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x06, 0x0c, 0x00,
+ 0x38, 0x70, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x00, 0x1e, 0x00, 0x00,
+ 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x06, 0x1c, 0x00, 0x38, 0x70, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0xe0, 0x00, 0x1e, 0x00, 0x00, 0x00, 0x06, 0x00,
+ 0x00, 0x00, 0x00, 0x06, 0x1c, 0x00, 0x38, 0xe0, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0xe0, 0x00, 0x1e, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00,
+ 0x06, 0x18, 0x00, 0x38, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x00,
+ 0x1e, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x18, 0x00,
+ 0x30, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x00, 0x1e, 0x00, 0x00,
+ 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x38, 0x00, 0x30, 0xe0, 0x01,
+ 0x00, 0x00, 0x00, 0x00, 0xf0, 0x01, 0x1f, 0x00, 0x00, 0x00, 0x06, 0x00,
+ 0x00, 0x00, 0x00, 0x0c, 0x3c, 0x00, 0x30, 0xf0, 0x01, 0x00, 0x00, 0x00,
+ 0x00, 0xf8, 0x03, 0x1f, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00,
+ 0x0c, 0x7e, 0x00, 0x70, 0xf8, 0x03, 0x00, 0x00, 0x00, 0x00, 0x3c, 0x0f,
+ 0x1f, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x0c, 0xe7, 0x00,
+ 0x70, 0xbc, 0x03, 0x00, 0x00, 0x00, 0x00, 0x1e, 0x1e, 0x1f, 0x00, 0x00,
+ 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0xdc, 0xe3, 0x00, 0x60, 0x1e, 0x07,
+ 0x00, 0x00, 0x00, 0x00, 0x0f, 0xfc, 0x1f, 0x00, 0x00, 0x00, 0x06, 0x00,
+ 0x00, 0x00, 0x00, 0xfc, 0xc1, 0x01, 0xe0, 0x0f, 0x0f, 0x00, 0x00, 0x00,
+ 0x80, 0x07, 0xf0, 0x1f, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00,
+ 0xf8, 0x80, 0x03, 0xe0, 0x03, 0x1e, 0x00, 0x00, 0x00, 0xc0, 0x03, 0xe0,
+ 0x1b, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x78, 0x80, 0x07,
+ 0xe0, 0x01, 0x1c, 0x00, 0x00, 0x00, 0xe0, 0x01, 0xc0, 0x1b, 0x00, 0x00,
+ 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x38, 0x00, 0x0f, 0xe0, 0x01, 0x38,
+ 0x00, 0x00, 0x00, 0xf0, 0x00, 0xc0, 0x19, 0x00, 0x00, 0x00, 0x06, 0x00,
+ 0x00, 0x00, 0x00, 0x30, 0x0e, 0x1e, 0xc0, 0x71, 0xf8, 0x00, 0x00, 0x00,
+ 0x78, 0x00, 0xdc, 0x19, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00,
+ 0x30, 0x1f, 0x1e, 0xc0, 0xf9, 0xf8, 0x00, 0x00, 0x00, 0xfc, 0xff, 0xff,
+ 0xff, 0xff, 0xff, 0xff, 0x07, 0x00, 0x00, 0x00, 0x00, 0xf0, 0xff, 0xff,
+ 0xff, 0xff, 0xff, 0x07, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+ 0xff, 0x07, 0x00, 0x00, 0x00, 0x00, 0xe0, 0xff, 0xff, 0xff, 0xff, 0xff,
+ 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
diff --git a/Xserver/include/bitmaps/menu10 b/Xserver/include/bitmaps/menu10
new file mode 100644 (file)
index 0000000..6250e8e
--- /dev/null
@@ -0,0 +1,5 @@
+#define menu10_width 10
+#define menu10_height 10
+static char menu10_bits[] = {
+   0xfe, 0x01, 0x02, 0x01, 0x02, 0x03, 0x32, 0x03, 0x02, 0x03, 0x32, 0x03,
+   0x02, 0x03, 0x02, 0x03, 0xfe, 0x03, 0xf8, 0x03};
diff --git a/Xserver/include/bitmaps/menu12 b/Xserver/include/bitmaps/menu12
new file mode 100644 (file)
index 0000000..e88ca68
--- /dev/null
@@ -0,0 +1,5 @@
+#define menu12_width 12
+#define menu12_height 12
+static unsigned char menu12_bits[] = {
+   0xfe, 0x03, 0x02, 0x02, 0x02, 0x06, 0x72, 0x06, 0x02, 0x06, 0x72, 0x06,
+   0x02, 0x06, 0x72, 0x06, 0x02, 0x06, 0x02, 0x06, 0xfe, 0x07, 0xf8, 0x07};
diff --git a/Xserver/include/bitmaps/menu16 b/Xserver/include/bitmaps/menu16
new file mode 100644 (file)
index 0000000..770deee
--- /dev/null
@@ -0,0 +1,6 @@
+#define menu16_width 16
+#define menu16_height 16
+static char menu16_bits[] = {
+   0xfc, 0x1f, 0x04, 0x10, 0x04, 0x30, 0x04, 0x30, 0xe4, 0x33, 0x04, 0x30,
+   0xe4, 0x33, 0x04, 0x30, 0xe4, 0x33, 0x04, 0x30, 0xe4, 0x33, 0x04, 0x30,
+   0x04, 0x30, 0x04, 0x30, 0xfc, 0x3f, 0xf0, 0x3f};
diff --git a/Xserver/include/bitmaps/menu6 b/Xserver/include/bitmaps/menu6
new file mode 100644 (file)
index 0000000..780b028
--- /dev/null
@@ -0,0 +1,4 @@
+#define menu6_width 6
+#define menu6_height 7
+static char menu6_bits[] = {
+   0x1f, 0x31, 0x35, 0x35, 0x31, 0x3f, 0x1e};
diff --git a/Xserver/include/bitmaps/menu8 b/Xserver/include/bitmaps/menu8
new file mode 100644 (file)
index 0000000..955c1e9
--- /dev/null
@@ -0,0 +1,4 @@
+#define menu8_width 8
+#define menu8_height 8
+static char menu8_bits[] = {
+   0x7f, 0x41, 0xdd, 0xc1, 0xdd, 0xc1, 0xff, 0xfc};
diff --git a/Xserver/include/bitmaps/noletters b/Xserver/include/bitmaps/noletters
new file mode 100644 (file)
index 0000000..5774124
--- /dev/null
@@ -0,0 +1,27 @@
+#define noletters_width 48
+#define noletters_height 48
+static char noletters_bits[] = {
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x1f, 0x00, 0x00,
+   0x00, 0x00, 0xff, 0xff, 0x01, 0x00, 0x00, 0xc0, 0xff, 0xff, 0x07, 0x00,
+   0x00, 0xf0, 0x0f, 0xe0, 0x1f, 0x00, 0x00, 0xfc, 0x01, 0x00, 0x7f, 0x00,
+   0x00, 0x3e, 0x00, 0x00, 0xf8, 0x00, 0x00, 0x1f, 0x00, 0x00, 0xf0, 0x01,
+   0x80, 0x07, 0x00, 0x00, 0xc0, 0x03, 0xc0, 0x03, 0x00, 0x00, 0xe0, 0x07,
+   0xe0, 0x01, 0x00, 0x00, 0xf0, 0x0f, 0xe0, 0x00, 0x00, 0x00, 0x78, 0x0e,
+   0xf0, 0x00, 0x00, 0x00, 0x3c, 0x1e, 0x70, 0x00, 0x00, 0x00, 0x1e, 0x1c,
+   0x38, 0x00, 0x00, 0x00, 0x0f, 0x38, 0x38, 0x00, 0x00, 0x80, 0x07, 0x38,
+   0x3c, 0xfc, 0xff, 0xff, 0x7f, 0x78, 0x1c, 0x04, 0x00, 0xe0, 0x41, 0x70,
+   0x1c, 0x04, 0x00, 0xf0, 0x40, 0x70, 0x1c, 0x74, 0x00, 0x78, 0x4e, 0x70,
+   0x0e, 0x04, 0x00, 0x3c, 0x4a, 0xe0, 0x0e, 0x74, 0x03, 0x1e, 0x4a, 0xe0,
+   0x0e, 0x04, 0x00, 0x0f, 0x4e, 0xe0, 0x0e, 0x04, 0x80, 0x07, 0x40, 0xe0,
+   0x0e, 0x04, 0xf8, 0x0f, 0x40, 0xe0, 0x0e, 0x04, 0xe0, 0x01, 0x40, 0xe0,
+   0x0e, 0x04, 0xf8, 0x00, 0x40, 0xe0, 0x0e, 0x04, 0x78, 0x00, 0x40, 0xe0,
+   0x0e, 0x04, 0xfc, 0xf3, 0x40, 0xe0, 0x1c, 0x04, 0x1e, 0x00, 0x40, 0x70,
+   0x1c, 0x04, 0x0f, 0x00, 0x40, 0x70, 0x1c, 0x84, 0x07, 0x00, 0x40, 0x70,
+   0x3c, 0xfc, 0xff, 0xff, 0x7f, 0x78, 0x38, 0xe0, 0x01, 0x00, 0x00, 0x38,
+   0x38, 0xf0, 0x00, 0x00, 0x00, 0x38, 0x70, 0x78, 0x00, 0x00, 0x00, 0x1c,
+   0xf0, 0x3c, 0x00, 0x00, 0x00, 0x1e, 0xe0, 0x1e, 0x00, 0x00, 0x00, 0x0e,
+   0xe0, 0x0f, 0x00, 0x00, 0x00, 0x0f, 0xc0, 0x07, 0x00, 0x00, 0x80, 0x07,
+   0x80, 0x07, 0x00, 0x00, 0xc0, 0x03, 0x00, 0x1f, 0x00, 0x00, 0xf0, 0x01,
+   0x00, 0x3e, 0x00, 0x00, 0xf8, 0x00, 0x00, 0xfc, 0x01, 0x00, 0x7f, 0x00,
+   0x00, 0xf0, 0x0f, 0xe0, 0x1f, 0x00, 0x00, 0xc0, 0xff, 0xff, 0x07, 0x00,
+   0x00, 0x00, 0xff, 0xff, 0x01, 0x00, 0x00, 0x00, 0xf0, 0x1f, 0x00, 0x00};
diff --git a/Xserver/include/bitmaps/opendot b/Xserver/include/bitmaps/opendot
new file mode 100644 (file)
index 0000000..a8ec421
--- /dev/null
@@ -0,0 +1,8 @@
+#define opendot_width 16
+#define opendot_height 16
+#define opendot_x_hot 7
+#define opendot_y_hot 7
+static char opendot_bits[] = {
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x01,
+   0x60, 0x03, 0x20, 0x02, 0x60, 0x03, 0xc0, 0x01, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
diff --git a/Xserver/include/bitmaps/opendotMask b/Xserver/include/bitmaps/opendotMask
new file mode 100644 (file)
index 0000000..0f83c64
--- /dev/null
@@ -0,0 +1,8 @@
+#define opendotMask_width 16
+#define opendotMask_height 16
+#define opendotMask_x_hot 7
+#define opendotMask_y_hot 7
+static char opendotMask_bits[] = {
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x03, 0xf0, 0x07,
+   0xf0, 0x07, 0xf0, 0x07, 0xf0, 0x07, 0xf0, 0x07, 0xe0, 0x03, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
diff --git a/Xserver/include/bitmaps/plaid b/Xserver/include/bitmaps/plaid
new file mode 100644 (file)
index 0000000..578e464
--- /dev/null
@@ -0,0 +1,11 @@
+#define plaid_width 22
+#define plaid_height 22
+#define plaid_x_hot -1
+#define plaid_y_hot -1
+static char plaid_bits[] = {
+   0x75, 0xfd, 0x3f, 0xaa, 0xfa, 0x3e, 0x75, 0xfd, 0x3f, 0xaa, 0xfa, 0x3e,
+   0x75, 0xfd, 0x3f, 0xff, 0x57, 0x15, 0x75, 0xfd, 0x3f, 0xaa, 0xfa, 0x3e,
+   0x75, 0xfd, 0x3f, 0xaa, 0xfa, 0x3e, 0x75, 0xfd, 0x3f, 0x20, 0xa8, 0x2b,
+   0x20, 0x50, 0x15, 0x20, 0xa8, 0x2b, 0x20, 0x50, 0x15, 0x20, 0xa8, 0x2b,
+   0xff, 0xff, 0x3f, 0x20, 0xa8, 0x2b, 0x20, 0x50, 0x15, 0x20, 0xa8, 0x2b,
+   0x20, 0x50, 0x15, 0x20, 0xa8, 0x2b};
diff --git a/Xserver/include/bitmaps/right_ptr b/Xserver/include/bitmaps/right_ptr
new file mode 100644 (file)
index 0000000..3922aa5
--- /dev/null
@@ -0,0 +1,8 @@
+#define right_ptr_width 16
+#define right_ptr_height 16
+#define right_ptr_x_hot 12
+#define right_ptr_y_hot 1
+static char right_ptr_bits[] = {
+   0x00, 0x00, 0x00, 0x10, 0x00, 0x18, 0x00, 0x1c, 0x00, 0x1e, 0x00, 0x1f,
+   0x80, 0x1f, 0xc0, 0x1f, 0xe0, 0x1f, 0x00, 0x1f, 0x00, 0x1b, 0x80, 0x11,
+   0x80, 0x01, 0xc0, 0x00, 0xc0, 0x00, 0x00, 0x00};
diff --git a/Xserver/include/bitmaps/right_ptrmsk b/Xserver/include/bitmaps/right_ptrmsk
new file mode 100644 (file)
index 0000000..96f5324
--- /dev/null
@@ -0,0 +1,6 @@
+#define right_ptrmsk_width 16
+#define right_ptrmsk_height 16
+static char right_ptrmsk_bits[] = {
+   0x00, 0x30, 0x00, 0x38, 0x00, 0x3c, 0x00, 0x3e, 0x00, 0x3f, 0x80, 0x3f,
+   0xc0, 0x3f, 0xe0, 0x3f, 0xf0, 0x3f, 0xf0, 0x3f, 0x80, 0x3f, 0xc0, 0x3b,
+   0xc0, 0x33, 0xe0, 0x01, 0xe0, 0x01, 0xc0, 0x00};
diff --git a/Xserver/include/bitmaps/root_weave b/Xserver/include/bitmaps/root_weave
new file mode 100644 (file)
index 0000000..ec41e43
--- /dev/null
@@ -0,0 +1,4 @@
+#define root_weave_width 4
+#define root_weave_height 4
+static char root_weave_bits[] = {
+   0x07, 0x0d, 0x0b, 0x0e};
diff --git a/Xserver/include/bitmaps/scales b/Xserver/include/bitmaps/scales
new file mode 100644 (file)
index 0000000..e5aac6a
--- /dev/null
@@ -0,0 +1,6 @@
+#define scales_width 16
+#define scales_height 16
+static char scales_bits[] = {
+   0x10, 0x10, 0x10, 0x10, 0x28, 0x28, 0xc7, 0xc7, 0x01, 0x01, 0x01, 0x01,
+   0x82, 0x82, 0x7c, 0x7c, 0x10, 0x10, 0x10, 0x10, 0x28, 0x28, 0xc7, 0xc7,
+   0x01, 0x01, 0x01, 0x01, 0x82, 0x82, 0x7c, 0x7c};
diff --git a/Xserver/include/bitmaps/sipb b/Xserver/include/bitmaps/sipb
new file mode 100644 (file)
index 0000000..7f3b7c1
--- /dev/null
@@ -0,0 +1,16 @@
+#define sipb_width 32
+#define sipb_height 32
+#define sipb_x_hot 12
+#define sipb_y_hot 16
+static char sipb_bits[] = {
+   0xbe, 0xdf, 0x03, 0x00, 0x22, 0x49, 0x04, 0x00, 0x04, 0x49, 0x04, 0x00,
+   0x08, 0x49, 0x04, 0x00, 0x10, 0xc9, 0x03, 0x00, 0x08, 0x49, 0x04, 0x00,
+   0x04, 0x49, 0x04, 0x00, 0x22, 0x49, 0x04, 0x00, 0x3e, 0xc9, 0x03, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0xfd, 0x1e, 0x00, 0x10, 0x49, 0x22,
+   0x00, 0x20, 0x48, 0x22, 0x00, 0x40, 0x48, 0x22, 0x00, 0x80, 0x48, 0x1e,
+   0x00, 0x40, 0x48, 0x22, 0x00, 0x20, 0x48, 0x22, 0x00, 0x10, 0x49, 0x22,
+   0x00, 0xf0, 0x49, 0x1e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
diff --git a/Xserver/include/bitmaps/star b/Xserver/include/bitmaps/star
new file mode 100644 (file)
index 0000000..c98f1a4
--- /dev/null
@@ -0,0 +1,8 @@
+#define star_width 16
+#define star_height 16
+#define star_x_hot 7
+#define star_y_hot 7
+static char star_bits[] = {
+   0x00, 0x00, 0x80, 0x00, 0x80, 0x00, 0x88, 0x08, 0x90, 0x04, 0xa0, 0x02,
+   0x40, 0x01, 0x3e, 0x3e, 0x40, 0x01, 0xa0, 0x02, 0x90, 0x04, 0x88, 0x08,
+   0x80, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00};
diff --git a/Xserver/include/bitmaps/starMask b/Xserver/include/bitmaps/starMask
new file mode 100644 (file)
index 0000000..c220bb6
--- /dev/null
@@ -0,0 +1,8 @@
+#define starMask_width 16
+#define starMask_height 16
+#define starMask_x_hot 7
+#define starMask_y_hot 7
+static char starMask_bits[] = {
+   0xc0, 0x01, 0xc0, 0x01, 0xdc, 0x1d, 0xfc, 0x1f, 0xfc, 0x1f, 0xf8, 0x0f,
+   0xff, 0x7f, 0xff, 0x7f, 0xff, 0x7f, 0xf8, 0x0f, 0xfc, 0x1f, 0xfc, 0x1f,
+   0xdc, 0x1d, 0xc0, 0x01, 0xc0, 0x01, 0x00, 0x00};
diff --git a/Xserver/include/bitmaps/stipple b/Xserver/include/bitmaps/stipple
new file mode 100644 (file)
index 0000000..63558d0
--- /dev/null
@@ -0,0 +1,4 @@
+#define stipple_width 16
+#define stipple_height 4
+static char stipple_bits[] = {
+   0x55, 0x55, 0xee, 0xee, 0x55, 0x55, 0xba, 0xbb};
diff --git a/Xserver/include/bitmaps/target b/Xserver/include/bitmaps/target
new file mode 100644 (file)
index 0000000..6d23eca
--- /dev/null
@@ -0,0 +1,6 @@
+#define target_width 16
+#define target_height 16
+static char target_bits[] = {
+   0x00, 0x00, 0x80, 0x01, 0x80, 0x01, 0xe0, 0x07, 0x90, 0x09, 0x88, 0x11,
+   0xc8, 0x13, 0x7e, 0x7e, 0x7e, 0x7e, 0xc8, 0x13, 0x88, 0x11, 0x90, 0x09,
+   0xe0, 0x07, 0x80, 0x01, 0x80, 0x01, 0x00, 0x00};
diff --git a/Xserver/include/bitmaps/terminal b/Xserver/include/bitmaps/terminal
new file mode 100644 (file)
index 0000000..b8d9204
--- /dev/null
@@ -0,0 +1,52 @@
+/*****************************************************************************/
+/**       Copyright 1988 by Evans & Sutherland Computer Corporation,        **/
+/**                          Salt Lake City, Utah                           **/
+/**                                                                         **/
+/**                           All Rights Reserved                           **/
+/**                                                                         **/
+/**    Permission to use, copy, modify, and distribute this software and    **/
+/**    its documentation  for  any  purpose  and  without  fee is hereby    **/
+/**    granted, provided that the above copyright notice appear  in  all    **/
+/**    copies and that both  that  copyright  notice  and  this  permis-    **/
+/**    sion  notice appear in supporting  documentation,  and  that  the    **/
+/**    name  of Evans & Sutherland  not be used in advertising or publi-    **/
+/**    city pertaining to distribution  of the software without  specif-    **/
+/**    ic, written prior permission.                                        **/
+/**                                                                         **/
+/**    EVANS  & SUTHERLAND  DISCLAIMS  ALL  WARRANTIES  WITH  REGARD  TO    **/
+/**    THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILI-    **/
+/**    TY AND FITNESS, IN NO EVENT SHALL EVANS &  SUTHERLAND  BE  LIABLE    **/
+/**    FOR  ANY  SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY  DAM-    **/
+/**    AGES  WHATSOEVER RESULTING FROM  LOSS OF USE,  DATA  OR  PROFITS,    **/
+/**    WHETHER   IN  AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS    **/
+/**    ACTION, ARISING OUT OF OR IN  CONNECTION  WITH  THE  USE  OR PER-    **/
+/**    FORMANCE OF THIS SOFTWARE.                                           **/
+/*****************************************************************************/
+
+#define xterm_width 48
+#define xterm_height 48
+static char xterm_bits[] = {
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0xff, 0xff, 0xff, 0xff, 0x00,
+   0x20, 0x00, 0x00, 0x00, 0x00, 0x03, 0x20, 0xfe, 0xff, 0xff, 0x1f, 0x05,
+   0x20, 0x01, 0x00, 0x00, 0x20, 0x09, 0xa0, 0x00, 0x00, 0x00, 0x40, 0x11,
+   0xa0, 0xfc, 0xff, 0x00, 0x40, 0x21, 0xa0, 0x00, 0x00, 0x00, 0x40, 0x21,
+   0xa0, 0xfc, 0x01, 0x00, 0x40, 0x21, 0xa0, 0x00, 0x00, 0x00, 0x40, 0x21,
+   0xa0, 0xfc, 0xff, 0x3f, 0x40, 0x21, 0xa0, 0x00, 0x00, 0x00, 0x40, 0x21,
+   0xa0, 0xfc, 0x03, 0x00, 0x40, 0x21, 0xa0, 0x00, 0x00, 0x00, 0x40, 0x21,
+   0xa0, 0xfc, 0xff, 0x01, 0x40, 0x21, 0xa0, 0x00, 0x00, 0x00, 0x40, 0x21,
+   0xa0, 0xfc, 0x00, 0x00, 0x40, 0x21, 0xa0, 0x00, 0x00, 0x00, 0x40, 0x21,
+   0xa0, 0x00, 0x00, 0x00, 0x40, 0x21, 0xa0, 0x00, 0x00, 0x00, 0x40, 0x21,
+   0xa0, 0x00, 0x00, 0x00, 0x40, 0x21, 0xa0, 0x00, 0x00, 0x00, 0x40, 0x21,
+   0xa0, 0x00, 0x00, 0x00, 0x40, 0x21, 0xa0, 0x00, 0x00, 0x00, 0x40, 0x21,
+   0xa0, 0x00, 0x00, 0x00, 0x40, 0x21, 0xa0, 0x00, 0x00, 0x00, 0x40, 0x11,
+   0xa0, 0x00, 0x00, 0x00, 0x40, 0x11, 0xa0, 0x00, 0x00, 0x00, 0x40, 0x09,
+   0xa0, 0x00, 0x00, 0x00, 0x40, 0x09, 0xa0, 0x00, 0x00, 0x00, 0x40, 0x05,
+   0x20, 0x01, 0x00, 0x00, 0x20, 0x05, 0x20, 0xfe, 0xff, 0xff, 0x1f, 0x03,
+   0x20, 0x00, 0x00, 0x00, 0x00, 0x03, 0xc0, 0xff, 0xff, 0xff, 0xff, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0xc0, 0xff, 0xff, 0xff, 0xff, 0x03, 0x20, 0x00, 0x00, 0x00, 0x00, 0x03,
+   0xa0, 0xaa, 0xaa, 0xaa, 0x2a, 0x03, 0x10, 0x00, 0x00, 0x00, 0x80, 0x02,
+   0x50, 0x55, 0x55, 0x55, 0x95, 0x02, 0x08, 0x00, 0x00, 0x00, 0x40, 0x02,
+   0xa8, 0xaa, 0xaa, 0xaa, 0x4a, 0x02, 0x04, 0x00, 0x00, 0x00, 0x20, 0x01,
+   0xb4, 0xff, 0xff, 0xff, 0xad, 0x00, 0x02, 0x00, 0x00, 0x00, 0x50, 0x00,
+   0xfe, 0xff, 0xff, 0xff, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
diff --git a/Xserver/include/bitmaps/tie_fighter b/Xserver/include/bitmaps/tie_fighter
new file mode 100644 (file)
index 0000000..0513db6
--- /dev/null
@@ -0,0 +1,6 @@
+#define tie_fighter_width 16
+#define tie_fighter_height 16
+static char tie_fighter_bits[] = {
+   0x00, 0x00, 0x00, 0x00, 0x08, 0x10, 0x04, 0x20, 0x02, 0x40, 0x02, 0x40,
+   0xe2, 0x47, 0x3e, 0x7c, 0x12, 0x48, 0x3e, 0x7c, 0xe2, 0x47, 0x02, 0x40,
+   0x42, 0x42, 0x64, 0x26, 0x28, 0x14, 0x00, 0x00};
diff --git a/Xserver/include/bitmaps/vlines2 b/Xserver/include/bitmaps/vlines2
new file mode 100644 (file)
index 0000000..f42ae58
--- /dev/null
@@ -0,0 +1,4 @@
+#define vlines2_width 2
+#define vlines2_height 1
+static char vlines2_bits[] = {
+   0x01};
diff --git a/Xserver/include/bitmaps/vlines3 b/Xserver/include/bitmaps/vlines3
new file mode 100644 (file)
index 0000000..55c2246
--- /dev/null
@@ -0,0 +1,4 @@
+#define vlines3_width 3
+#define vlines3_height 1
+static char vlines3_bits[] = {
+   0x02};
diff --git a/Xserver/include/bitmaps/weird_size b/Xserver/include/bitmaps/weird_size
new file mode 100644 (file)
index 0000000..e6f45d5
--- /dev/null
@@ -0,0 +1,5 @@
+#define weird_size_width 7
+#define weird_size_height 13
+static char weird_size_bits[] = {
+   0x07, 0x05, 0x07, 0x01, 0x75, 0x45, 0x74, 0x44, 0x74, 0x00, 0x10, 0x38,
+   0x10};
diff --git a/Xserver/include/bitmaps/wide_weave b/Xserver/include/bitmaps/wide_weave
new file mode 100644 (file)
index 0000000..27ba639
--- /dev/null
@@ -0,0 +1,6 @@
+#define wide_weave_width 16
+#define wide_weave_height 16
+static char wide_weave_bits[] = {
+   0x11, 0x11, 0xb8, 0xb8, 0x7c, 0x7c, 0x3a, 0x3a, 0x11, 0x11, 0xa3, 0xa3,
+   0xc7, 0xc7, 0x8b, 0x8b, 0x11, 0x11, 0xb8, 0xb8, 0x7c, 0x7c, 0x3a, 0x3a,
+   0x11, 0x11, 0xa3, 0xa3, 0xc7, 0xc7, 0x8b, 0x8b};
diff --git a/Xserver/include/bitmaps/wingdogs b/Xserver/include/bitmaps/wingdogs
new file mode 100644 (file)
index 0000000..1a4befc
--- /dev/null
@@ -0,0 +1,14 @@
+#define wingdogs_width 32
+#define wingdogs_height 32
+static char wingdogs_bits[] = {
+   0x60, 0x00, 0x00, 0x00, 0xc0, 0x00, 0x00, 0x00, 0x80, 0x03, 0x00, 0x00,
+   0x20, 0x0f, 0x00, 0x00, 0x40, 0x3e, 0x00, 0x00, 0xc0, 0x7f, 0x00, 0x80,
+   0x84, 0xff, 0x00, 0xc0, 0x86, 0xff, 0x00, 0xc0, 0x07, 0xff, 0x21, 0xe0,
+   0x0f, 0xfe, 0x23, 0xf0, 0x0f, 0xfe, 0x23, 0xfc, 0x1d, 0xfe, 0x13, 0xfe,
+   0x39, 0xfc, 0x13, 0xff, 0x3f, 0xfc, 0x83, 0xff, 0x9f, 0xfc, 0xc1, 0xff,
+   0x0f, 0xfe, 0xe0, 0xff, 0xf3, 0xff, 0xff, 0xff, 0xf9, 0xff, 0xff, 0xff,
+   0xfc, 0xff, 0xff, 0x7f, 0xf6, 0xff, 0xff, 0x1f, 0xfb, 0xff, 0xff, 0x07,
+   0xf8, 0xfd, 0xff, 0x03, 0xbc, 0xf9, 0xff, 0x01, 0x3c, 0xf9, 0xff, 0x01,
+   0x3e, 0xf0, 0xf7, 0x00, 0x1f, 0xe0, 0x77, 0x00, 0x1f, 0x80, 0x77, 0x00,
+   0x8f, 0x00, 0x6f, 0x00, 0xc7, 0x00, 0x6e, 0x80, 0x07, 0x00, 0x7c, 0x80,
+   0x0d, 0x00, 0xf8, 0x80, 0x1f, 0x00, 0xf0, 0x01};
diff --git a/Xserver/include/bitmaps/woman b/Xserver/include/bitmaps/woman
new file mode 100644 (file)
index 0000000..92e6041
--- /dev/null
@@ -0,0 +1,66 @@
+#define sorceress_width 75
+#define sorceress_height 75
+static char sorceress_bits[] = {
+   0xfc, 0x7e, 0x40, 0x20, 0x90, 0x00, 0x07, 0x80, 0x23, 0x00, 0x00, 0xc6,
+   0xc1, 0x41, 0x98, 0xb8, 0x01, 0x07, 0x66, 0x00, 0x15, 0x9f, 0x03, 0x47,
+   0x8c, 0xc6, 0xdc, 0x7b, 0xcc, 0x00, 0xb0, 0x71, 0x0e, 0x4d, 0x06, 0x66,
+   0x73, 0x8e, 0x8f, 0x01, 0x18, 0xc4, 0x39, 0x4b, 0x02, 0x23, 0x0c, 0x04,
+   0x1e, 0x03, 0x0c, 0x08, 0xc7, 0xef, 0x08, 0x30, 0x06, 0x07, 0x1c, 0x02,
+   0x06, 0x30, 0x18, 0xae, 0xc8, 0x98, 0x3f, 0x78, 0x20, 0x06, 0x02, 0x20,
+   0x60, 0xa0, 0xc4, 0x1d, 0xc0, 0xff, 0x41, 0x04, 0xfa, 0x63, 0x80, 0xa1,
+   0xa4, 0x3d, 0x00, 0x84, 0xbf, 0x04, 0x0f, 0x06, 0xfc, 0xa1, 0x34, 0x6b,
+   0x01, 0x1c, 0xc9, 0x05, 0x06, 0xc7, 0x06, 0xbe, 0x11, 0x1e, 0x43, 0x30,
+   0x91, 0x05, 0xc3, 0x61, 0x02, 0x30, 0x1b, 0x30, 0xcc, 0x20, 0x11, 0x00,
+   0xc1, 0x3c, 0x03, 0x20, 0x0a, 0x00, 0xe8, 0x60, 0x21, 0x00, 0x61, 0x1b,
+   0xc1, 0x63, 0x08, 0xf0, 0xc6, 0xc7, 0x21, 0x03, 0xf8, 0x08, 0xe1, 0xcf,
+   0x0a, 0xfc, 0x4d, 0x99, 0x43, 0x07, 0x3c, 0x0c, 0xf1, 0x9f, 0x0b, 0xfc,
+   0x5b, 0x81, 0x47, 0x02, 0x16, 0x04, 0x31, 0x1c, 0x0b, 0x1f, 0x17, 0x89,
+   0x4d, 0x06, 0x1a, 0x04, 0x31, 0x38, 0x02, 0x07, 0x56, 0x89, 0x49, 0x04,
+   0x0b, 0x04, 0xb1, 0x72, 0x82, 0xa1, 0x54, 0x9a, 0x49, 0x04, 0x1d, 0x66,
+   0x50, 0xe7, 0xc2, 0xf0, 0x54, 0x9a, 0x58, 0x04, 0x0d, 0x62, 0xc1, 0x1f,
+   0x44, 0xfc, 0x51, 0x90, 0x90, 0x04, 0x86, 0x63, 0xe0, 0x74, 0x04, 0xef,
+   0x31, 0x1a, 0x91, 0x00, 0x02, 0xe2, 0xc1, 0xfd, 0x84, 0xf9, 0x30, 0x0a,
+   0x91, 0x00, 0x82, 0xa9, 0xc0, 0xb9, 0x84, 0xf9, 0x31, 0x16, 0x81, 0x00,
+   0x42, 0xa9, 0xdb, 0x7f, 0x0c, 0xff, 0x1c, 0x16, 0x11, 0x00, 0x02, 0x28,
+   0x0b, 0x07, 0x08, 0x60, 0x1c, 0x02, 0x91, 0x00, 0x46, 0x29, 0x0e, 0x00,
+   0x00, 0x00, 0x10, 0x16, 0x11, 0x02, 0x06, 0x29, 0x04, 0x00, 0x00, 0x00,
+   0x10, 0x16, 0x91, 0x06, 0xa6, 0x2a, 0x04, 0x00, 0x00, 0x00, 0x18, 0x24,
+   0x91, 0x04, 0x86, 0x2a, 0x04, 0x00, 0x00, 0x00, 0x18, 0x27, 0x93, 0x04,
+   0x96, 0x4a, 0x04, 0x00, 0x00, 0x00, 0x04, 0x02, 0x91, 0x04, 0x86, 0x4a,
+   0x0c, 0x00, 0x00, 0x00, 0x1e, 0x23, 0x93, 0x04, 0x56, 0x88, 0x08, 0x00,
+   0x00, 0x00, 0x90, 0x21, 0x93, 0x04, 0x52, 0x0a, 0x09, 0x80, 0x01, 0x00,
+   0xd0, 0x21, 0x95, 0x04, 0x57, 0x0a, 0x0f, 0x80, 0x27, 0x00, 0xd8, 0x20,
+   0x9d, 0x04, 0x5d, 0x08, 0x1c, 0x80, 0x67, 0x00, 0xe4, 0x01, 0x85, 0x04,
+   0x79, 0x8a, 0x3f, 0x00, 0x00, 0x00, 0xf4, 0x11, 0x85, 0x06, 0x39, 0x08,
+   0x7d, 0x00, 0x00, 0x18, 0xb7, 0x10, 0x81, 0x03, 0x29, 0x12, 0xcb, 0x00,
+   0x7e, 0x30, 0x28, 0x00, 0x85, 0x03, 0x29, 0x10, 0xbe, 0x81, 0xff, 0x27,
+   0x0c, 0x10, 0x85, 0x03, 0x29, 0x32, 0xfa, 0xc1, 0xff, 0x27, 0x94, 0x11,
+   0x85, 0x03, 0x28, 0x20, 0x6c, 0xe1, 0xff, 0x07, 0x0c, 0x01, 0x85, 0x01,
+   0x28, 0x62, 0x5c, 0xe3, 0x8f, 0x03, 0x4e, 0x91, 0x80, 0x05, 0x39, 0x40,
+   0xf4, 0xc2, 0xff, 0x00, 0x9f, 0x91, 0x84, 0x05, 0x31, 0xc6, 0xe8, 0x07,
+   0x7f, 0x80, 0xcd, 0x00, 0xc4, 0x04, 0x31, 0x06, 0xc9, 0x0e, 0x00, 0xc0,
+   0x48, 0x88, 0xe0, 0x04, 0x79, 0x04, 0xdb, 0x12, 0x00, 0x30, 0x0c, 0xc8,
+   0xe4, 0x04, 0x6d, 0x06, 0xb6, 0x23, 0x00, 0x18, 0x1c, 0xc0, 0x84, 0x04,
+   0x25, 0x0c, 0xff, 0xc2, 0x00, 0x4e, 0x06, 0xb0, 0x80, 0x04, 0x3f, 0x8a,
+   0xb3, 0x83, 0xff, 0xc3, 0x03, 0x91, 0x84, 0x04, 0x2e, 0xd8, 0x0f, 0x3f,
+   0x00, 0x00, 0x5f, 0x83, 0x84, 0x04, 0x2a, 0x70, 0xfd, 0x7f, 0x00, 0x00,
+   0xc8, 0xc0, 0x84, 0x04, 0x4b, 0xe2, 0x2f, 0x01, 0x00, 0x08, 0x58, 0x60,
+   0x80, 0x04, 0x5b, 0x82, 0xff, 0x01, 0x00, 0x08, 0xd0, 0xa0, 0x84, 0x04,
+   0x72, 0x80, 0xe5, 0x00, 0x00, 0x08, 0xd2, 0x20, 0x44, 0x04, 0xca, 0x02,
+   0xff, 0x00, 0x00, 0x08, 0xde, 0xa0, 0x44, 0x04, 0x82, 0x02, 0x6d, 0x00,
+   0x00, 0x08, 0xf6, 0xb0, 0x40, 0x02, 0x82, 0x07, 0x3f, 0x00, 0x00, 0x08,
+   0x44, 0x58, 0x44, 0x02, 0x93, 0x3f, 0x1f, 0x00, 0x00, 0x30, 0x88, 0x4f,
+   0x44, 0x03, 0x83, 0x23, 0x3e, 0x00, 0x00, 0x00, 0x18, 0x60, 0xe0, 0x07,
+   0xe3, 0x0f, 0xfe, 0x00, 0x00, 0x00, 0x70, 0x70, 0xe4, 0x07, 0xc7, 0x1b,
+   0xfe, 0x01, 0x00, 0x00, 0xe0, 0x3c, 0xe4, 0x07, 0xc7, 0xe3, 0xfe, 0x1f,
+   0x00, 0x00, 0xff, 0x1f, 0xfc, 0x07, 0xc7, 0x03, 0xf8, 0x33, 0x00, 0xc0,
+   0xf0, 0x07, 0xff, 0x07, 0x87, 0x02, 0xfc, 0x43, 0x00, 0x60, 0xf0, 0xff,
+   0xff, 0x07, 0x8f, 0x06, 0xbe, 0x87, 0x00, 0x30, 0xf8, 0xff, 0xff, 0x07,
+   0x8f, 0x14, 0x9c, 0x8f, 0x00, 0x00, 0xfc, 0xff, 0xff, 0x07, 0x9f, 0x8d,
+   0x8a, 0x0f, 0x00, 0x00, 0xfe, 0xff, 0xff, 0x07, 0xbf, 0x0b, 0x80, 0x1f,
+   0x00, 0x00, 0xff, 0xff, 0xff, 0x07, 0x7f, 0x3a, 0x80, 0x3f, 0x00, 0x80,
+   0xff, 0xff, 0xff, 0x07, 0xff, 0x20, 0xc0, 0x3f, 0x00, 0x80, 0xff, 0xff,
+   0xff, 0x07, 0xff, 0x01, 0xe0, 0x7f, 0x00, 0xc0, 0xff, 0xff, 0xff, 0x07,
+   0xff, 0x0f, 0xf8, 0xff, 0x40, 0xe0, 0xff, 0xff, 0xff, 0x07, 0xff, 0xff,
+   0xff, 0xff, 0x40, 0xf0, 0xff, 0xff, 0xff, 0x07, 0xff, 0xff, 0xff, 0xff,
+   0x41, 0xf0, 0xff, 0xff, 0xff, 0x07};
diff --git a/Xserver/include/bitmaps/xfd_icon b/Xserver/include/bitmaps/xfd_icon
new file mode 100644 (file)
index 0000000..383334c
--- /dev/null
@@ -0,0 +1,27 @@
+#define xfd_icon_width 48
+#define xfd_icon_height 48
+static char xfd_icon_bits[] = {
+   0xff, 0xff, 0xff, 0xff, 0xff, 0x0f, 0x01, 0x81, 0x40, 0x20, 0x10, 0x08,
+   0x11, 0x9d, 0x5c, 0xa7, 0xd7, 0x0b, 0x29, 0xa5, 0x42, 0xa9, 0x50, 0x08,
+   0x45, 0xa5, 0x42, 0xa9, 0x50, 0x08, 0x7d, 0x9d, 0x42, 0xa9, 0xd7, 0x09,
+   0x45, 0xa5, 0x42, 0xa9, 0x50, 0x08, 0x45, 0xa5, 0x42, 0xa9, 0x50, 0x08,
+   0x45, 0x9d, 0x5c, 0xa7, 0x57, 0x08, 0x01, 0x81, 0x40, 0x20, 0x10, 0x08,
+   0xff, 0xff, 0xff, 0xff, 0xff, 0x0f, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00};
diff --git a/Xserver/include/bitmaps/xlogo11 b/Xserver/include/bitmaps/xlogo11
new file mode 100644 (file)
index 0000000..5efd2c2
--- /dev/null
@@ -0,0 +1,6 @@
+#define xlogo11_width 11
+#define xlogo11_height 11
+
+static char xlogo11_bits[] = {
+ 0x0f, 0x04, 0x0f, 0x02, 0x1e, 0x01, 0x3c, 0x01, 0xb8, 0x00, 0x58, 0x00,
+ 0xe8, 0x00, 0xe4, 0x01, 0xc4, 0x03, 0xc2, 0x03, 0x81, 0x07 };
diff --git a/Xserver/include/bitmaps/xlogo16 b/Xserver/include/bitmaps/xlogo16
new file mode 100644 (file)
index 0000000..5c23027
--- /dev/null
@@ -0,0 +1,6 @@
+#define xlogo16_width 16
+#define xlogo16_height 16
+static unsigned char xlogo16_bits[] = {
+   0x0f, 0x80, 0x1e, 0x80, 0x3c, 0x40, 0x78, 0x20, 0x78, 0x10, 0xf0, 0x08,
+   0xe0, 0x09, 0xc0, 0x05, 0xc0, 0x02, 0x40, 0x07, 0x20, 0x0f, 0x20, 0x1e,
+   0x10, 0x1e, 0x08, 0x3c, 0x04, 0x78, 0x02, 0xf0};
diff --git a/Xserver/include/bitmaps/xlogo32 b/Xserver/include/bitmaps/xlogo32
new file mode 100644 (file)
index 0000000..1ecb6ac
--- /dev/null
@@ -0,0 +1,14 @@
+#define xlogo32_width 32
+#define xlogo32_height 32
+static char xlogo32_bits[] = {
+   0xff, 0x00, 0x00, 0xc0, 0xfe, 0x01, 0x00, 0xc0, 0xfc, 0x03, 0x00, 0x60,
+   0xf8, 0x07, 0x00, 0x30, 0xf8, 0x07, 0x00, 0x18, 0xf0, 0x0f, 0x00, 0x0c,
+   0xe0, 0x1f, 0x00, 0x06, 0xc0, 0x3f, 0x00, 0x06, 0xc0, 0x3f, 0x00, 0x03,
+   0x80, 0x7f, 0x80, 0x01, 0x00, 0xff, 0xc0, 0x00, 0x00, 0xfe, 0x61, 0x00,
+   0x00, 0xfe, 0x31, 0x00, 0x00, 0xfc, 0x33, 0x00, 0x00, 0xf8, 0x1b, 0x00,
+   0x00, 0xf0, 0x0d, 0x00, 0x00, 0xf0, 0x0e, 0x00, 0x00, 0x60, 0x1f, 0x00,
+   0x00, 0xb0, 0x3f, 0x00, 0x00, 0x98, 0x7f, 0x00, 0x00, 0x98, 0x7f, 0x00,
+   0x00, 0x0c, 0xff, 0x00, 0x00, 0x06, 0xfe, 0x01, 0x00, 0x03, 0xfc, 0x03,
+   0x80, 0x01, 0xfc, 0x03, 0xc0, 0x00, 0xf8, 0x07, 0xc0, 0x00, 0xf0, 0x0f,
+   0x60, 0x00, 0xe0, 0x1f, 0x30, 0x00, 0xe0, 0x1f, 0x18, 0x00, 0xc0, 0x3f,
+   0x0c, 0x00, 0x80, 0x7f, 0x06, 0x00, 0x00, 0xff};
diff --git a/Xserver/include/bitmaps/xlogo64 b/Xserver/include/bitmaps/xlogo64
new file mode 100644 (file)
index 0000000..ad3b0db
--- /dev/null
@@ -0,0 +1,46 @@
+#define xlogo64_width 64
+#define xlogo64_height 64
+static unsigned char xlogo64_bits[] = {
+   0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0xfe, 0xff, 0x01, 0x00,
+   0x00, 0x00, 0x00, 0xf8, 0xfc, 0xff, 0x03, 0x00, 0x00, 0x00, 0x00, 0x7c,
+   0xf8, 0xff, 0x07, 0x00, 0x00, 0x00, 0x00, 0x3e, 0xf8, 0xff, 0x07, 0x00,
+   0x00, 0x00, 0x00, 0x1f, 0xf0, 0xff, 0x0f, 0x00, 0x00, 0x00, 0x80, 0x0f,
+   0xe0, 0xff, 0x1f, 0x00, 0x00, 0x00, 0x80, 0x0f, 0xc0, 0xff, 0x3f, 0x00,
+   0x00, 0x00, 0xc0, 0x07, 0xc0, 0xff, 0x3f, 0x00, 0x00, 0x00, 0xe0, 0x03,
+   0x80, 0xff, 0x7f, 0x00, 0x00, 0x00, 0xf0, 0x01, 0x00, 0xff, 0xff, 0x00,
+   0x00, 0x00, 0xf8, 0x00, 0x00, 0xfe, 0xff, 0x01, 0x00, 0x00, 0xf8, 0x00,
+   0x00, 0xfe, 0xff, 0x01, 0x00, 0x00, 0x7c, 0x00, 0x00, 0xfc, 0xff, 0x03,
+   0x00, 0x00, 0x3e, 0x00, 0x00, 0xf8, 0xff, 0x07, 0x00, 0x00, 0x1f, 0x00,
+   0x00, 0xf0, 0xff, 0x0f, 0x00, 0x80, 0x0f, 0x00, 0x00, 0xf0, 0xff, 0x0f,
+   0x00, 0xc0, 0x07, 0x00, 0x00, 0xe0, 0xff, 0x1f, 0x00, 0xc0, 0x07, 0x00,
+   0x00, 0xc0, 0xff, 0x3f, 0x00, 0xe0, 0x03, 0x00, 0x00, 0x80, 0xff, 0x7f,
+   0x00, 0xf0, 0x01, 0x00, 0x00, 0x80, 0xff, 0x7f, 0x00, 0xf8, 0x00, 0x00,
+   0x00, 0x00, 0xff, 0xff, 0x00, 0x7c, 0x00, 0x00, 0x00, 0x00, 0xfe, 0xff,
+   0x01, 0x7c, 0x00, 0x00, 0x00, 0x00, 0xfc, 0xff, 0x03, 0x3e, 0x00, 0x00,
+   0x00, 0x00, 0xfc, 0xff, 0x03, 0x1f, 0x00, 0x00, 0x00, 0x00, 0xf8, 0xff,
+   0x87, 0x0f, 0x00, 0x00, 0x00, 0x00, 0xf0, 0xff, 0xcf, 0x07, 0x00, 0x00,
+   0x00, 0x00, 0xe0, 0xff, 0xcf, 0x07, 0x00, 0x00, 0x00, 0x00, 0xe0, 0xff,
+   0xe7, 0x03, 0x00, 0x00, 0x00, 0x00, 0xc0, 0xff, 0xf3, 0x01, 0x00, 0x00,
+   0x00, 0x00, 0x80, 0xff, 0xf9, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff,
+   0xfc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7f, 0xfe, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x7e, 0xfe, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3e,
+   0xff, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x9f, 0xff, 0x07, 0x00, 0x00,
+   0x00, 0x00, 0x80, 0xcf, 0xff, 0x07, 0x00, 0x00, 0x00, 0x00, 0xc0, 0xe7,
+   0xff, 0x0f, 0x00, 0x00, 0x00, 0x00, 0xc0, 0xe7, 0xff, 0x1f, 0x00, 0x00,
+   0x00, 0x00, 0xe0, 0xc3, 0xff, 0x3f, 0x00, 0x00, 0x00, 0x00, 0xf0, 0xc1,
+   0xff, 0x3f, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x80, 0xff, 0x7f, 0x00, 0x00,
+   0x00, 0x00, 0x7c, 0x00, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x7c, 0x00,
+   0xfe, 0xff, 0x01, 0x00, 0x00, 0x00, 0x3e, 0x00, 0xfe, 0xff, 0x01, 0x00,
+   0x00, 0x00, 0x1f, 0x00, 0xfc, 0xff, 0x03, 0x00, 0x00, 0x80, 0x0f, 0x00,
+   0xf8, 0xff, 0x07, 0x00, 0x00, 0xc0, 0x07, 0x00, 0xf0, 0xff, 0x0f, 0x00,
+   0x00, 0xe0, 0x03, 0x00, 0xf0, 0xff, 0x0f, 0x00, 0x00, 0xe0, 0x03, 0x00,
+   0xe0, 0xff, 0x1f, 0x00, 0x00, 0xf0, 0x01, 0x00, 0xc0, 0xff, 0x3f, 0x00,
+   0x00, 0xf8, 0x00, 0x00, 0x80, 0xff, 0x7f, 0x00, 0x00, 0x7c, 0x00, 0x00,
+   0x80, 0xff, 0x7f, 0x00, 0x00, 0x3e, 0x00, 0x00, 0x00, 0xff, 0xff, 0x00,
+   0x00, 0x3e, 0x00, 0x00, 0x00, 0xfe, 0xff, 0x01, 0x00, 0x1f, 0x00, 0x00,
+   0x00, 0xfc, 0xff, 0x03, 0x80, 0x0f, 0x00, 0x00, 0x00, 0xfc, 0xff, 0x03,
+   0xc0, 0x07, 0x00, 0x00, 0x00, 0xf8, 0xff, 0x07, 0xe0, 0x03, 0x00, 0x00,
+   0x00, 0xf0, 0xff, 0x0f, 0xe0, 0x03, 0x00, 0x00, 0x00, 0xe0, 0xff, 0x1f,
+   0xf0, 0x01, 0x00, 0x00, 0x00, 0xe0, 0xff, 0x1f, 0xf8, 0x00, 0x00, 0x00,
+   0x00, 0xc0, 0xff, 0x3f, 0x7c, 0x00, 0x00, 0x00, 0x00, 0x80, 0xff, 0x7f,
+   0x3e, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff};
diff --git a/Xserver/include/bitmaps/xsnow b/Xserver/include/bitmaps/xsnow
new file mode 100644 (file)
index 0000000..2c1bd8b
--- /dev/null
@@ -0,0 +1,1112 @@
+#define xsnow_width 300
+#define xsnow_height 350
+static char xsnow_bits[] = {
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x00, 0x40, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x70, 0x00,
+   0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x70, 0x01, 0x68, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0xe0, 0x01, 0x38, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0xf0, 0x01, 0x78, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x99, 0x39, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x9e, 0x1f, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x98,
+   0x1b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0xc0, 0x09, 0x33, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x80, 0x01, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0xe0, 0x0f, 0x7b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x80, 0x01, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0xc0, 0xdf, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x07, 0x00, 0x00, 0x80, 0x0f, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x07, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00,
+   0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0xfe, 0x03, 0x01,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x47, 0x00,
+   0x00, 0x90, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0xce,
+   0x87, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x7f, 0x00, 0x00, 0xf0, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80,
+   0x6c, 0x0f, 0xef, 0x13, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x6a, 0x00, 0x00, 0x70, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0xf0, 0xcf, 0x07, 0x7c, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x26, 0x00, 0x00, 0x30, 0x03, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0xf0, 0xf7, 0x03, 0x1e, 0xfe, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x3f, 0x00, 0x00, 0x70, 0x0e, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xfc, 0x07, 0x7e, 0x5b, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7e, 0x60, 0x30, 0xf0,
+   0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x38, 0x07, 0xef, 0x11,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x71,
+   0xf0, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0xfe,
+   0x87, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0xf0, 0x77, 0xf0, 0x77, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0xff, 0x07, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0xb0, 0x33, 0xf0, 0x71, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0xc0, 0xff, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x18, 0x30, 0xf0, 0xe1, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0xe0, 0x0f, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x30, 0xe0, 0xe1, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x0c, 0x19, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x30, 0xe0, 0x81,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x9c, 0x11, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7e, 0x30,
+   0xe0, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x9f,
+   0x17, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0xff, 0x19, 0xe0, 0x03, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0xc0, 0x99, 0x39, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0xfc, 0x1f, 0xe0, 0xe3, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0xf0, 0x01, 0x78, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x01, 0xc0, 0x01, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0xf0, 0x3f, 0xf0, 0x7b, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0xe0, 0x01, 0x38, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x00, 0xc0, 0x01,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0xff, 0xfc, 0x1f, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x70, 0x01, 0x68, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x03,
+   0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0x07,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x70, 0x00, 0x60, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x80, 0x03, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe,
+   0xdf, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x00,
+   0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0xc0, 0x33, 0xf2, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10,
+   0x00, 0xf6, 0xff, 0x03, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x80, 0x3f, 0x6e, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x30, 0x00, 0xfe, 0xff, 0x03, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x39, 0x66, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0xf0, 0x00, 0x1e, 0xce, 0x03, 0x78, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x33, 0x66, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x01, 0x1f, 0x80, 0x07, 0x7c, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x3f,
+   0xce, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x90, 0xc3, 0x1f, 0x80, 0x1f,
+   0x7e, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x3f, 0x7e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x1c, 0xef, 0x0f,
+   0x80, 0xbf, 0xff, 0x61, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0xfc, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf1, 0x1e,
+   0xfc, 0x07, 0x80, 0xff, 0x8f, 0x7b, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x20, 0xf8, 0x0f, 0x02, 0x00, 0x00, 0x00, 0x40,
+   0xdb, 0x0f, 0xf8, 0x03, 0x00, 0xf7, 0x07, 0xff, 0x16, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0xb8, 0x0f, 0x03, 0x00, 0x00,
+   0x00, 0xe0, 0x8d, 0x07, 0xfe, 0x01, 0x00, 0xfc, 0x03, 0x8e, 0x3d, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf2, 0x3d, 0xdc, 0x23,
+   0x00, 0x00, 0x00, 0x60, 0xef, 0x03, 0x7f, 0x07, 0x00, 0xfe, 0x80, 0xcf,
+   0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x3e, 0x1f,
+   0xfc, 0xbd, 0x00, 0x00, 0x00, 0x00, 0xf9, 0x8e, 0x7f, 0x0f, 0x00, 0xff,
+   0xc1, 0xfb, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0,
+   0x1d, 0x0f, 0x58, 0xdc, 0x03, 0x00, 0x00, 0x00, 0x30, 0xfc, 0xef, 0x0f,
+   0x80, 0xbf, 0xc3, 0x61, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x80, 0xde, 0x1f, 0x7c, 0xbe, 0x01, 0x00, 0x00, 0x00, 0x10, 0xf0,
+   0xc3, 0x0f, 0xc0, 0x1f, 0x46, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0xe2, 0x1d, 0xde, 0x27, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0xf0, 0x01, 0x0f, 0xc0, 0x07, 0x1c, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x78, 0x0e, 0x03, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0xf0, 0x00, 0x9e, 0xc3, 0x03, 0x38, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0xf8, 0x0f, 0x02,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x00, 0xfe, 0xdf, 0x03, 0x60, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfc,
+   0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0xfe, 0x7f, 0x03,
+   0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x3f, 0x7e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xde,
+   0xff, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0xc0, 0x39, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0xff, 0xff, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x3b, 0x62, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0xc0, 0xff, 0xfc, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3b, 0x6a, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0xf0, 0x3f, 0xf0, 0x7f, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x3f, 0x7e, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7c, 0x1e, 0xe0, 0xff, 0x01, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x33,
+   0xf2, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0x1e, 0xe0, 0xfe,
+   0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0xc0, 0x02, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x1e,
+   0x60, 0xf8, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x80, 0x03, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x08, 0x1c, 0x60, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0xc0, 0x00, 0xc0, 0x01, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x38, 0x1c, 0x60, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x01, 0xc0, 0x01, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x38, 0x3c, 0x70, 0xc0, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x01,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x3c, 0x70, 0x62, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x3f, 0x70, 0x6f,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x39,
+   0x70, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x7e, 0x20, 0x30, 0xf0, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x02, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x80, 0x33, 0x00, 0x00, 0xf0, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x03, 0x00, 0x03, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x36, 0x00, 0x00, 0x10, 0x03, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x03, 0x00,
+   0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x76, 0x00, 0x00, 0x50, 0x02, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x0f, 0xc0, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7f, 0x00, 0x00, 0xf0,
+   0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x0b, 0xc0, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x67, 0x00,
+   0x00, 0x90, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x80, 0xcf, 0xcc, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80,
+   0x07, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0xfc, 0x01, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x07, 0x00, 0x00, 0x80, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xd6, 0xdc, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x80, 0x01, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46, 0xd8,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x01, 0x00, 0x00, 0x00, 0x0e, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x7f, 0x98, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0xfe, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0xf8, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0xf0, 0x1f, 0x08, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x70, 0x3e, 0x0c, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe4, 0x7b, 0x78,
+   0x8f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x7d,
+   0x3e, 0xf8, 0xd3, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x80, 0x33, 0x1a, 0xf0, 0xb0, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0xad, 0x3f, 0xf0, 0xf9, 0x07, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0xc4, 0x3b, 0x78, 0x9f, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0xf0, 0x39, 0x0c, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0xf0, 0x1f,
+   0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0xf8, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0xfe, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x73, 0xe8, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x66, 0x88, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xee, 0xac, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0xfc,
+   0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80,
+   0xcf, 0xcc, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x0f, 0x40, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x0f, 0xc0, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x03, 0x00, 0x03, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x03, 0x00, 0x03, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x10, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00,
+   0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x00, 0x00,
+   0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0,
+   0x02, 0x00, 0x1a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x80, 0x03, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0xc0, 0x02, 0x00, 0x1e, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x33, 0x60, 0x0e, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3d, 0xe0, 0x07, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x31, 0xe0,
+   0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x13, 0xc0, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0xc0, 0x1f, 0xc0, 0x1e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x3f, 0xe0, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfc, 0xf8, 0x01, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe8, 0xcf, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x88, 0xc1,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x0c, 0xc0, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x0c, 0xc0, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x04, 0x04, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x07, 0x00, 0x86, 0x01, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0xb6, 0x07, 0x00, 0xec, 0x13,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0xe7, 0x03, 0x00,
+   0xf8, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0xf3,
+   0x00, 0x00, 0x3c, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0xd0, 0xfe, 0x01, 0x00, 0x7e, 0x5b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x40, 0xbc, 0x03, 0x00, 0xef, 0x11, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x07, 0x00, 0x87, 0x01, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x04, 0x80, 0x01, 0x01,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1c, 0x80,
+   0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x1c, 0x80, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x18, 0x9d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0xd8, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x80, 0x03, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfc, 0xf8, 0x01, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x01, 0x00, 0x00, 0xe0,
+   0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3f, 0xe0, 0x07, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x01, 0x00,
+   0x00, 0xe0, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x19, 0x40,
+   0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0,
+   0x11, 0x00, 0x00, 0xe6, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x1b, 0x40, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0xc0, 0x1f, 0x00, 0x00, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x3b, 0x60, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0xc0, 0x1a, 0x00, 0x00, 0x6e, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x80, 0x3f, 0xe0, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x08, 0x00, 0x00, 0x4c, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x33, 0x20, 0x1e, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00,
+   0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x0b, 0x00, 0x00, 0xcc,
+   0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x03, 0x00, 0x0e, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0,
+   0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x1f, 0x08,
+   0x04, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x03, 0x00,
+   0x1e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0xc0, 0x03, 0x00, 0x1e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x7f, 0x0c, 0x9c, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0,
+   0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x80, 0x03, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0xfe, 0x0d, 0xfc, 0x1d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x40, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x23, 0x60, 0x1e, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0xe6, 0x0c, 0x7c, 0x1c, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x3f, 0xe0, 0x0f, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x0c, 0x3c, 0x1c, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x35, 0xe0,
+   0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x06, 0x38, 0x1c,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x11, 0xc0, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x06,
+   0x38, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0xc0, 0x17, 0xc0, 0x1c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80,
+   0x1f, 0x06, 0x78, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x3f, 0xe0, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0xe0, 0x7f, 0x06, 0x78, 0xe0, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfc, 0xf8, 0x01, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x80, 0xff, 0x07, 0x78, 0x7c, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0xdf, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0x0f, 0x7c, 0x1f, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc8, 0xc5,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x3f, 0xff, 0x03,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x0c, 0xc0, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0xff,
+   0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x0c, 0xc0, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0xc0, 0xff, 0x7b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x04, 0x0c, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x04, 0xc0, 0xfd, 0x7f, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x07, 0x00, 0x87, 0x01, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x0c, 0xc0, 0xff, 0xff, 0x00, 0x0c, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0xbc, 0x07, 0x00, 0xee, 0x11,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x3c, 0xc0, 0x87, 0xf9, 0x00, 0x0f, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xd0, 0xf6, 0x03, 0x00,
+   0xfc, 0x5b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x78, 0xe0, 0x07, 0xf0, 0x80,
+   0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x78, 0xe3,
+   0x01, 0x00, 0x78, 0xe6, 0x00, 0x00, 0x00, 0x00, 0x04, 0xf4, 0xf0, 0x07,
+   0xf0, 0xc3, 0x0f, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0xd8, 0xfb, 0x00, 0x00, 0x3e, 0xdf, 0x00, 0x00, 0x00, 0x00, 0x0c, 0xc7,
+   0xfb, 0x03, 0xf0, 0xf7, 0x3f, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x40, 0xbe, 0x03, 0x00, 0xef, 0x13, 0x00, 0x00, 0x00, 0x40,
+   0xbc, 0x87, 0xff, 0x00, 0xf0, 0xff, 0x73, 0x8f, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x07, 0x00, 0x87, 0x01, 0x00, 0x00,
+   0x00, 0xd0, 0xf6, 0x03, 0xff, 0x00, 0xc0, 0xff, 0xe0, 0xdf, 0x02, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x04, 0x00, 0x01, 0x01,
+   0x00, 0x00, 0x00, 0xf8, 0xe3, 0x81, 0x3f, 0x00, 0x00, 0x7f, 0xc0, 0x33,
+   0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1c, 0x80,
+   0x01, 0x00, 0x00, 0x00, 0x00, 0xd8, 0xfb, 0xc0, 0xef, 0x00, 0xc0, 0x3f,
+   0xf0, 0xf9, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x1c, 0x80, 0x01, 0x00, 0x00, 0x00, 0x00, 0x40, 0xbe, 0xf3, 0xff, 0x03,
+   0xe0, 0x3f, 0x78, 0x9f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x01, 0x80, 0x01, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x18, 0x8c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0xff,
+   0xfb, 0x03, 0xf0, 0x77, 0x38, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x01, 0x80, 0x01, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x98, 0xbf, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x04, 0xfc, 0xf0, 0x03, 0xf8, 0xc3, 0x08, 0x08, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x07, 0xe0,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfc, 0xf8, 0x01, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x7c, 0xe0, 0x03, 0xf8, 0x80, 0x03, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80,
+   0x05, 0xe0, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3f, 0xe0, 0x07, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x3c, 0xc0, 0x67, 0xf8, 0x00, 0x07, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0xc0, 0x67, 0xe6, 0x01, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x19, 0xc0,
+   0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0xc0, 0xff, 0xff, 0x00,
+   0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x7f, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x19, 0x40, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0xc0, 0xff,
+   0x6f, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x6b, 0x6e, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x3b, 0x60, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0xc0, 0xf7, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x23, 0x6c, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x3f, 0xe0, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0xe0, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x3f, 0xcc,
+   0x01, 0x00, 0x00, 0x00, 0x00, 0x80, 0x33, 0x60, 0x0e, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0xf8, 0x3f, 0xff, 0x03, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x7f, 0x7e, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x03, 0x00, 0x1e, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0x0f, 0xfc, 0x1f, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0xfc, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x03, 0x00,
+   0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x9f, 0x07, 0xf8, 0x7f,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x20, 0xf8, 0x0f, 0x04, 0x00, 0x00, 0x00, 0x00, 0xc0,
+   0x02, 0x00, 0x1a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x87, 0x07,
+   0x98, 0xff, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x38, 0x1f, 0x06, 0x00, 0x00, 0x00,
+   0x00, 0xc0, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80,
+   0x81, 0x07, 0x18, 0x7e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf2, 0x3d, 0xbc, 0x47, 0x00,
+   0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x02, 0x07, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x3e, 0x1f, 0xfc,
+   0x69, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x06, 0x07, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x19,
+   0x0d, 0x78, 0xd8, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x0f, 0x0c, 0x18, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x80, 0xd6, 0x1f, 0xf8, 0xfc, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x0f, 0xcc, 0x18,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0xe2, 0x1d, 0xbc, 0x4f, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xce, 0x0f,
+   0xec, 0x1b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0xf8, 0x1c, 0x06, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x7f, 0x0e, 0x8c, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0xf8, 0x0f, 0x04, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0xc0, 0x1f, 0x08, 0x04, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfc, 0x1f,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x60, 0x0e, 0x00, 0x00, 0xfc, 0x01, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x7f, 0x7e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x0c, 0x00, 0x00, 0x44, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x80, 0x39, 0xf4, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x1c, 0x00, 0x00, 0x56,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x33, 0x44, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x1e, 0x00,
+   0x00, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x77, 0x56, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0,
+   0x19, 0x00, 0x00, 0xe6, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7f, 0xfe, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0xe0, 0x01, 0x00, 0x00, 0xa0, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x67, 0xe6,
+   0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0xe0, 0x01, 0x00, 0x00, 0xe0, 0x01, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80,
+   0x07, 0xa0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x80, 0x03, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x80, 0x07, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x80,
+   0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0xc0, 0x01, 0x80, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x01, 0x80, 0x01, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x01, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x30, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x70, 0x00, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0xf0, 0x01, 0x80, 0x0e, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x01, 0x80, 0x07, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x00, 0x00, 0x0f,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x09,
+   0x98, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x80, 0x0e, 0x78, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0xc0, 0x08, 0x38, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0xc0, 0x09, 0x30, 0x06, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x0f, 0xf0, 0x07, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x0f, 0xf8, 0x03,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3f,
+   0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0xf6, 0x73, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x42, 0x70, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x60, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x02, 0x40, 0x40,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x84, 0x03,
+   0x80, 0x61, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20,
+   0xdb, 0x03, 0x00, 0xfb, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0xc0, 0x03, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0xfe, 0xf3, 0x01, 0x00, 0xbc, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x03, 0x00, 0x00, 0x00, 0x00,
+   0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0xfe, 0x79, 0x00, 0x00, 0x8f, 0x7f, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x23, 0x00, 0x00,
+   0x00, 0x30, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x68, 0xff, 0x00, 0x80, 0xdf, 0x16, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x3f,
+   0x00, 0x00, 0x00, 0xf0, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0xde, 0x01, 0xc0, 0x7b,
+   0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x35, 0x00, 0x00, 0x00, 0x70, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x86, 0x03,
+   0xc0, 0x61, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x13, 0x00, 0x00, 0x00, 0x60, 0x03, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x02, 0x02, 0x40, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0xc0, 0x1f, 0x00, 0x00, 0x00, 0x60, 0x0e, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x06, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3f, 0x10, 0x00, 0x20, 0xf0,
+   0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfc, 0x18, 0x00,
+   0xe0, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x8e, 0x67, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8,
+   0x1b, 0x00, 0xe0, 0x6f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xee, 0x7f, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0xd8, 0x19, 0x00, 0xe0, 0x63, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3f,
+   0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x0c, 0x18, 0x00, 0xe0, 0xe1, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0xc0, 0x0f, 0xf8, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x08, 0x00, 0xc0, 0xe1, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x60, 0x0e, 0xd0, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x08, 0x00, 0xc0, 0x81,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0xc0, 0x0c, 0x10, 0x03, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3f, 0x08, 0x00,
+   0xc0, 0x03, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x0e, 0x58, 0x03, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xff,
+   0x0c, 0x00, 0xc0, 0xc3, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x0f, 0xf8, 0x03,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0xfe, 0x0f, 0x00, 0xc0, 0xf3, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x09,
+   0x88, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0xf8, 0x1f, 0x00, 0xe0, 0x7f, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0xe0, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x7f, 0x00, 0xf8, 0x1f, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0xf0, 0x01, 0x80, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xff, 0x01, 0xfe, 0x07,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x87,
+   0xcf, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x0c, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0xf3, 0xff, 0xc3, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0xc3, 0xcf, 0xc0, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x01, 0x03, 0xc0, 0x03, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x01, 0x00, 0x80, 0x07, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x01, 0x00, 0x80, 0x07,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x01, 0x00,
+   0x80, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80,
+   0x01, 0x00, 0x80, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x80, 0x01, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x80, 0x00, 0x80, 0x00, 0x00, 0x00, 0x04, 0x00, 0x04, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x80, 0x01, 0xe0, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x06,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x07, 0xf0, 0x00, 0x00, 0x00, 0x3c,
+   0x80, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0xf8, 0x00, 0x00,
+   0x00, 0x78, 0xc0, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x1e, 0xfe,
+   0x00, 0x00, 0x00, 0xe0, 0xe1, 0x07, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xe1,
+   0x78, 0x7f, 0x00, 0x00, 0x00, 0xc0, 0xfb, 0x1f, 0x06, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x88, 0xf7, 0xf0, 0x1f, 0x00, 0x00, 0x00, 0x80, 0xff, 0xb9, 0x47, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0xda, 0x7e, 0xe0, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x7e, 0xf0,
+   0x6f, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x7f, 0x3c, 0xf0, 0x07, 0x00, 0x00, 0x00, 0x80,
+   0x3f, 0xe0, 0xb9, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7b, 0x1f, 0xf8, 0x01, 0x00, 0x00,
+   0x00, 0xc0, 0x1f, 0xf8, 0x7c, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc8, 0x77, 0xfe, 0x03,
+   0x00, 0x00, 0x00, 0xe0, 0x1f, 0xbc, 0x4f, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xe1,
+   0x7f, 0x07, 0x00, 0x00, 0x00, 0xf8, 0x7b, 0x1c, 0x06, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x80, 0x80, 0x1f, 0x0e, 0x00, 0x00, 0x00, 0xfc, 0xe1, 0x04, 0x04, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x80, 0x0f, 0x38, 0x00, 0x00, 0x00, 0x7c, 0xc0, 0x01,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x07, 0x70, 0x00, 0x00, 0x00, 0x3c,
+   0x80, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x01, 0xe0, 0x00, 0x00,
+   0x00, 0x1c, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x80,
+   0x00, 0x00, 0x00, 0x04, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x80, 0x03, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x80, 0x07, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x07, 0x00, 0x00, 0x06, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x07, 0x00, 0x00, 0x06,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x60, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x07, 0x00,
+   0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x0f, 0x80, 0x03, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x03, 0x00, 0x00, 0xc0, 0x07,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x0f, 0xec, 0x0f, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x03, 0x00, 0x00,
+   0xc0, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x0f, 0xff, 0x3f, 0x03, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x23,
+   0x00, 0x00, 0xcc, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xcf, 0xc7, 0xff, 0x03, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x80, 0x3f, 0x00, 0x00, 0xfc, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xff, 0x01, 0xff, 0x07,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x80, 0x35, 0x00, 0x00, 0xdc, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x7f, 0x00,
+   0xf8, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x80, 0x11, 0x00, 0x00, 0x98, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8,
+   0x1f, 0x00, 0xe0, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x17, 0x00, 0x00, 0x98, 0x03,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x3e, 0x0f, 0x00, 0xc0, 0xff, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x3f, 0x10, 0x08,
+   0xfc, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x80, 0x0f, 0x0f, 0x00, 0xc0, 0xfc, 0x07, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe,
+   0x18, 0x38, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x0f, 0x00, 0x60, 0xf0, 0x03, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0xfc, 0x1b, 0xf8, 0x3b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x0e, 0x00, 0x60, 0xc0,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0xcc, 0x19, 0xf8, 0x38, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1c, 0x0e, 0x00,
+   0x60, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x18, 0x78, 0x38, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1c,
+   0x1e, 0x00, 0x60, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x0c, 0x70, 0x38, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x18, 0x1e, 0x00, 0x60, 0x66, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x0c, 0x70,
+   0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x98, 0x1f, 0x00, 0x70, 0x7f, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3f,
+   0x0c, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0xfc, 0x1c, 0x00, 0x70, 0xfc, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0xc0, 0xff, 0x0c, 0xf0, 0xc0, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3f, 0x10, 0x00, 0x30, 0xf0,
+   0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0xff, 0x0f, 0xf0, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x19, 0x00, 0x00,
+   0x00, 0xe0, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0xfc, 0x1f, 0xf8, 0x3e, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1b,
+   0x00, 0x00, 0x00, 0x20, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x7f, 0xfe, 0x07, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x3b, 0x00, 0x00, 0x00, 0xb0, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0xff, 0xff,
+   0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x80, 0x3f, 0x00, 0x00, 0x00, 0xf0, 0x07, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80,
+   0xff, 0xf7, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0xc0, 0x33, 0x00, 0x00, 0x00, 0x30, 0x0f, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x08, 0x80, 0xfb, 0xff, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x03, 0x00, 0x00, 0x00, 0x00,
+   0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x18, 0x80, 0xff, 0xff, 0x01, 0x18, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x03, 0x00, 0x00,
+   0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x78, 0x80, 0x0f, 0xf3, 0x01, 0x1e, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0xc0, 0x0f, 0xe0, 0x01, 0x1f,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0xe8, 0xe1, 0x0f, 0xe0,
+   0x87, 0x1f, 0x10, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x20, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x8e, 0xf7,
+   0x07, 0xe0, 0xef, 0x7f, 0x18, 0x00, 0x00, 0x00, 0x00, 0x70, 0x00, 0x70,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x78,
+   0x0f, 0xff, 0x01, 0xe0, 0xff, 0xe7, 0x1e, 0x01, 0x00, 0x00, 0x00, 0xf0,
+   0x00, 0x38, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0xa0, 0xed, 0x07, 0xfe, 0x01, 0x80, 0xff, 0xc1, 0xbf, 0x05, 0x00, 0x00,
+   0x00, 0xe0, 0x00, 0x38, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0xf0, 0xc7, 0x03, 0x7f, 0x00, 0x00, 0xfe, 0x80, 0x67, 0x0e,
+   0x00, 0x00, 0x00, 0xe0, 0x06, 0x39, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0xb0, 0xf7, 0x81, 0xdf, 0x01, 0x80, 0x7f, 0xe0,
+   0xf3, 0x0d, 0x00, 0x00, 0x00, 0xc0, 0x07, 0x1f, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x7c, 0xe7, 0xff, 0x07, 0xc0,
+   0x7f, 0xf0, 0x3e, 0x01, 0x00, 0x00, 0x00, 0xc0, 0x06, 0x1b, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0xfe, 0xf7,
+   0x07, 0xe0, 0xef, 0x70, 0x18, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x07, 0x3f,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08,
+   0xf8, 0xe1, 0x07, 0xf0, 0x87, 0x11, 0x10, 0x00, 0x00, 0x00, 0x00, 0x80,
+   0x8f, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0xf8, 0xc0, 0x07, 0xf0, 0x01, 0x07, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0xff, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x78, 0x80, 0xcf, 0xf0, 0x01, 0x0e, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x19, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x80, 0xff, 0xff, 0x01, 0x18,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x06, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x80, 0xff, 0xdf,
+   0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x01, 0x04, 0x01, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80,
+   0xef, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xdc, 0x01, 0xdc,
+   0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0xc0, 0xff, 0xff, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0xa0, 0xff,
+   0x01, 0xf8, 0x2b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0xf0, 0x7f, 0xfe, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0xf0, 0x73, 0x00, 0x60, 0x7e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0xfc, 0x1f, 0xf8, 0x3f, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0xa0, 0x7f, 0x00, 0x78, 0x2f, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3f, 0x0f, 0xf0, 0xff, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x80, 0xde, 0x00, 0xdc, 0x0b, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x0f, 0x0f, 0x30,
+   0xff, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x01, 0x04, 0x01, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03,
+   0x0f, 0x30, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x04,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x04, 0x0e, 0x30, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x43, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x0c, 0x0e, 0x30, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0xf3, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x1e, 0x18, 0x30, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x80, 0xdf, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x18,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1c, 0x1e, 0x98, 0x31, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x07, 0x3f, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1c,
+   0x00, 0x1c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x9c, 0x1f, 0xd8,
+   0x37, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x07, 0x1b, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x38, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe,
+   0x1c, 0x18, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x07, 0x1f,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x38, 0x41, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x80, 0x3f, 0x10, 0x08, 0xfc, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0,
+   0x07, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0xc1, 0x07, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0xc0, 0x1c, 0x00, 0x00, 0xf8, 0x03, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0xe0, 0x00, 0x38, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xd0, 0xc1, 0x06, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x80, 0x19, 0x00, 0x00, 0x88, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0xf0, 0x00, 0x38, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xb8, 0xc1, 0x0d,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x39, 0x00, 0x00, 0xac, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x70, 0x00, 0x70, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0,
+   0xc1, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x3d, 0x00, 0x00,
+   0xfc, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x00, 0x60, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0xc0, 0xf7, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x33,
+   0x00, 0x00, 0xcc, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0xc0, 0x9e, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0xc0, 0x03, 0x00, 0x00, 0x40, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x80, 0x01, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0xc0, 0x03, 0x00, 0x00, 0xc0, 0x03, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x80, 0x01, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x41, 0x00, 0x41,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x07,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xa0, 0x77,
+   0x00, 0xf6, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0xfc, 0x3d, 0x00, 0xbc, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0xfc, 0x1e, 0x00, 0xde, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0xa0, 0x37, 0x00, 0xf7, 0x03, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x63, 0x00, 0x63, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc1, 0x00, 0x41,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0,
+   0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0xc0, 0xb4, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0xc0, 0xff, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0xe3, 0x07, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xd8, 0xc1, 0x0f, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xb0, 0xc1, 0x04,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0,
+   0xc1, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x38, 0xc1, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x38, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x3c, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x1c, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00};
diff --git a/Xserver/include/extensions/Imakefile b/Xserver/include/extensions/Imakefile
new file mode 100644 (file)
index 0000000..957effc
--- /dev/null
@@ -0,0 +1,42 @@
+XCOMM $XConsortium: Imakefile /main/46 1996/09/28 16:17:59 rws $
+XCOMM $XFree86: xc/include/extensions/Imakefile,v 3.13 1997/01/12 10:39:14 dawes Exp $
+
+#if BuildScreenSaverLibrary
+SCREENSAVERHEADERS = saver.h saverproto.h scrnsaver.h
+#endif
+
+#if BuildXF86MiscLibrary
+XF86MISCHEADERS = xf86misc.h xf86mscstr.h
+#endif
+#if BuildXF86VidModeLibrary
+XF86VIDMODEHEADERS = xf86vmode.h xf86vmstr.h
+#endif
+#if BuildXF86DGALibrary
+XF86DGAHEADERS = xf86dga.h xf86dgastr.h
+#endif
+#if BuildLBX
+LBXHEADERS = lbxbuf.h lbxbufstr.h lbxdeltastr.h lbximage.h lbxopts.h lbxstr.h lbxzlib.h
+#endif
+#if BuildDPMSLibrary
+DPMSHEADERS = dpms.h dpmsstr.h
+#endif
+
+EXTRAHEADERS = $(SCREENSAVERHEADERS) $(XF86VIDMODEHEADERS) $(XF86DGAHEADERS) $(XF86MISCHEADERS) $(LBXHEADERS) $(DPMSHEADERS)
+
+
+
+HEADERS = Xext.h multibuf.h shape.h XShm.h MITMisc.h XI.h XInput.h XIproto.h \
+       XTest.h xtestext1.h XIE.h XIEproto.h XIEprotost.h sync.h \
+       XKB.h XKBgeom.h XKBproto.h XKBstr.h XKBsrv.h Xdbe.h Xdbeproto.h \
+       Xag.h Xagstr.h Xagsrv.h \
+       record.h recordstr.h \
+        lbxbuf.h lbxbufstr.h lbxdeltastr.h lbximage.h \
+        lbxopts.h lbxstr.h lbxzlib.h \
+       security.h securstr.h \
+       Print.h Printstr.h $(EXTRAHEADERS)
+
+all::
+
+BuildIncludes($(HEADERS),X11/extensions,../..)
+InstallMultipleFlags($(HEADERS),$(INCDIR)/X11/extensions,$(INSTINCFLAGS))
+InstallLinkKitMultipleDestFlags($(EXTRAHEADERS),$(LINKKITDIR)/include/X11/extensions,$(INSTDATFLAGS))
diff --git a/Xserver/include/extensions/MITMisc.h b/Xserver/include/extensions/MITMisc.h
new file mode 100644 (file)
index 0000000..b9e2eb3
--- /dev/null
@@ -0,0 +1,73 @@
+/************************************************************
+
+Copyright (c) 1989  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+********************************************************/
+
+/* RANDOM CRUFT! THIS HAS NO OFFICIAL X CONSORTIUM BLESSING */
+
+/* $XConsortium: MITMisc.h,v 1.5 94/04/17 20:11:10 rws Exp $ */
+
+#ifndef _XMITMISC_H_
+#define _XMITMISC_H_
+
+#include <X11/Xfuncproto.h>
+
+#define X_MITSetBugMode                        0
+#define X_MITGetBugMode                        1
+
+#define MITMiscNumberEvents            0
+
+#define MITMiscNumberErrors            0
+
+#ifndef _MITMISC_SERVER_
+
+_XFUNCPROTOBEGIN
+
+Bool XMITMiscQueryExtension(
+#if NeedFunctionPrototypes
+    Display*           /* dpy */,
+    int*               /* event_basep */,
+    int*               /* error_basep */
+#endif
+);
+
+Status XMITMiscSetBugMode(
+#if NeedFunctionPrototypes
+    Display*           /* dpy */,
+    Bool               /* onOff */
+#endif
+);
+
+Bool XMITMiscGetBugMode(
+#if NeedFunctionPrototypes
+    Display*           /* dpy */
+#endif
+);
+
+_XFUNCPROTOEND
+
+#endif
+
+#endif
diff --git a/Xserver/include/extensions/Print.h b/Xserver/include/extensions/Print.h
new file mode 100644 (file)
index 0000000..e1f3b63
--- /dev/null
@@ -0,0 +1,596 @@
+/* $XConsortium: Print.h /main/3 1996/12/10 14:59:02 rws $ */
+/******************************************************************************
+ ******************************************************************************
+ **
+ ** File:         Print.h
+ **
+ ** Description:  Definitions needed by the server, library, and
+ **               clients.  Subportion restricted to library and
+ **               clients.
+ **
+ **               Server, Library, Client portion has:
+ **                  o All sz_* defines
+ **                  o Revision and Name defines
+ **                  o Common defines and constants (e.g. Keywords, Masks)
+ **                  o Extension version structure
+ **               
+ **               Library and client subportion has:
+ **                  o Convience Marcos
+ **                  o Client side data structures
+ **                  o Client side event structures (non wire)
+ **                  o Library function prototypes
+ **                  o some private stuff denoted with _whatever
+ **
+ **               Printstr.h for server and library, but NOT clients.
+ **
+ ******************************************************************************
+ **
+ ** (c) Copyright 1996 Hewlett-Packard Company
+ ** (c) Copyright 1996 International Business Machines Corp.
+ ** (c) Copyright 1996 Sun Microsystems, Inc.
+ ** (c) Copyright 1996 Novell, Inc.
+ ** (c) Copyright 1996 Digital Equipment Corp.
+ ** (c) Copyright 1996 Fujitsu Limited
+ ** (c) Copyright 1996 Hitachi, Ltd.
+ ** 
+ ** Permission is hereby granted, free of charge, to any person obtaining a copy
+ ** of this software and associated documentation files (the "Software"), to deal
+ ** in the Software without restriction, including without limitation the rights
+ ** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ ** copies of the Software, and to permit persons to whom the Software is
+ ** furnished to do so, subject to the following conditions:
+ **
+ ** The above copyright notice and this permission notice shall be included in
+ ** all copies or substantial portions of the Software.
+ **
+ ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ ** IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ ** FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+ ** COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
+ ** IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ ** CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ **
+ ** Except as contained in this notice, the names of the copyright holders shall
+ ** not be used in advertising or otherwise to promote the sale, use or other
+ ** dealings in this Software without prior written authorization from said
+ ** copyright holders.
+ **
+ ******************************************************************************
+ *****************************************************************************/
+
+#ifndef _XpPrint_H_
+#define _XpPrint_H_
+
+#ifndef _XP_PRINT_SERVER_
+#include <X11/Xlib.h>
+#include <X11/Xresource.h>
+#include <X11/Xauth.h>
+#endif /* _XP_PRINT_SERVER_ */
+
+#include <X11/Xfuncproto.h>
+
+_XFUNCPROTOBEGIN
+
+/******************************************************************************
+ *
+ * Definitions used by the server, library and client.
+ */
+
+/********************************************************************
+ *
+ * Naming and versioning information.
+ */
+#define XP_PRINTNAME  "XpExtension"
+
+/*
+ * Add a define below for each major extension release.
+ */
+#define XP_DONT_CHECK          0
+#define XP_INITIAL_RELEASE     1
+
+/*
+ * For each single entry above, create one major/minor pair.
+ */
+#define XP_PROTO_MAJOR         1
+#define XP_PROTO_MINOR         0
+
+/*
+ * Identify current version.
+ */
+#define XP_MAJOR_VERSION       XP_PROTO_MAJOR
+#define XP_MINOR_VERSION       XP_PROTO_MINOR
+
+/*
+ * Misc version defines.
+ */
+#define XP_ABSENT              0       /* Prior to XP Print support */
+#define XP_PRESENT             1       /* With XP Print support */
+
+/********************************************************************
+ *
+ * Xp Print Error codes.
+ */
+#define XP_ERRORS              3       /* number of error types */
+
+#define XPBadContext           0       /* Print Context invalid or missing */
+#define XPBadSequence          1       /* Illegal sequence of XP operations */
+#define XPBadResourceID                2       /* X-resource not valid */
+
+/********************************************************************
+ *
+ * Xp Print Event masks and codes.
+ *
+ */
+#define XP_EVENTS              2       /* number of event types */
+
+#define XPNoEventMask          0       /* not an event - just a null mask */
+#define XPPrintMask            (1L<<0)
+#define XPAttributeMask                (1L<<1)
+
+#define XPPrintNotify          0       /* contains "detail" - see below */
+#define XPAttributeNotify      1       /* contains "detail" - see below */
+
+#define XPStartJobNotify       0       /* value for "detail" in XPPrintNotify*/
+#define XPEndJobNotify         1
+#define XPStartDocNotify       2
+#define XPEndDocNotify         3
+#define XPStartPageNotify      4
+#define XPEndPageNotify                5
+
+/********************************************************************
+ *
+ * Xp Print Attribute Object codes (subset of ISO DPA 10175).  The
+ * Xp Server can get and set any of the values, while the Xp Library
+ * may only be able to set a subset of the attribute objects.
+ *
+ * note: the codes are also used as "detail" for XPAttributeNotify
+ *
+ * note: XPPageAttr is not defined in ISO DPA 10175.  It is unique
+ * to Xp, and its attributes are a proper subset of XPDocAttr.
+ */
+typedef unsigned char XPAttributes;    /* type of Xp*Attr codes */
+
+#define XP_ATTRIBUTES          5       /* those attrs currently supported */
+
+#define XPJobAttr              1       /* get/set */
+#define XPDocAttr              2       /* get/set */
+#define XPPageAttr             3       /* get/set - subset of XPDocAttr */
+#define XPPrinterAttr          4       /* get only (library) */
+#define XPServerAttr           5       /* get only (library), no
+                                          context needed */
+
+/*
+ * note: ISO DPA 10175 defines a number of "attribute objects", of
+ *       which POSIX 1387.4 and the SI Xp will only support a
+ *       subset.
+ */
+#define XPMediumAttr           6       /* DPA-Object Medium */
+#define XPFontAttr             7       /* DPA-Object Font */
+#define XPResAttr              8       /* DPA-Object Resource */
+#define XPTransAttr            9       /* DPA-Object Transfer method */
+#define XPDelAttr              10      /* DPA-Object Delivery method */
+#define XPAuxSPkg              11      /* DPA-Object Auxiliary sheet package */
+#define XPAuxS                 12      /* DPA-Object Auxiliary sheet */
+#define XPFinishAttr           13      /* DPA-Object Finishing */
+#define XPOutputAttr           14      /* DPA-Object Output method */
+#define XPImpAttr              15      /* DPA-Object Imposition */
+#define XPSchedAttr            16      /* DPA-Object Scheduler */
+#define XPIntJobAttr           17      /* DPA-Object Initial value job */
+#define XPIntDocAttr           18      /* DPA-Object Initial value document */
+#define XPResConAttr           19      /* DPA-Object Resource context */
+
+
+/*
+ * Replacement rules for XpSetAttributes
+ */
+typedef unsigned char XPAttrReplacement;
+#define        XPAttrReplace           1
+#define XPAttrMerge            2
+
+
+/*
+ * Return codes for XpGetDocumentData
+ */
+typedef unsigned char XPGetDocStatus;
+#define XPGetDocFinished       0       /* normal termination */
+#define XPGetDocSecondConsumer 1       /* setup error */
+#define XPGetDocError          2       /* runtime error, see generated error */
+
+
+/*
+ * Save data types for XpStartJob.
+ */
+typedef unsigned char XPSaveData;
+#define XPSpool                        1       /* Job data sent to spooler */
+#define XPGetData              2       /* Job data via XpGetDocumentData */
+
+
+/*
+ * Document types for XpStartDoc.
+ */
+typedef unsigned char XPDocumentType;
+#define        XPDocNormal             1       /* Doc data handled by Xserver */
+#define        XPDocRaw                2       /* Doc data passed through Xserver */
+
+
+/********************************************************************
+ *
+ * Xp Print Property Names
+ */
+
+
+#ifndef _XP_PRINT_SERVER_
+
+/******************************************************************************
+ *
+ * Definitions used by the library and clients only.
+ */
+
+/*******************************************************************
+ *
+ * General API defines and such.
+ */
+
+/*
+ * Print Context for XpInitContext and related calls.
+ */
+typedef XID XPContext;
+
+/*
+ * Struct for XpGetPrinterList.
+ */
+typedef struct {
+    char       *name;          /* name */
+    char       *desc;          /* localized description */
+} XPPrinterRec, *XPPrinterList;
+
+/*
+ * Typedefs for XpGetDocumentData
+ */
+typedef void (*XPSaveProc)( Display *display,
+                            XPContext context,
+                            unsigned char *data,
+                            unsigned int data_len,
+                            XPointer client_data);
+
+typedef void (*XPFinishProc)( Display *display,
+                              XPContext context,
+                              XPGetDocStatus status,
+                              XPointer client_data);
+
+/*
+ * Typedefs for XpSetLocaleHinter and XpGetLocaleHinter
+ */
+typedef char * (*XPHinterProc)();
+
+/*******************************************************************
+ *
+ * Extension version structures.
+ *
+ */
+typedef struct {
+        int     present;
+        short   major_version;
+        short   minor_version;
+} XExtensionVersion;
+
+/********************************************************************
+ *
+ * Event structs for clients.
+ *
+ * note: these events are relative to a print context, and
+ * not to a window as in core X.
+ */
+typedef struct {
+    int            type;       /* base + XPPrintNotify */
+    unsigned long  serial;     /* # of last request processed by server */
+    Bool           send_event; /* true if from a SendEvent request */
+    Display        *display;   /* Display the event was read from */
+    XPContext      context;    /* print context where operation was requested */
+    Bool           cancel;     /* was detailed event canceled */
+    int            detail;     /* XPStartJobNotify, XPEndJobNotify,
+                                  XPStartDocNotify, XPEndDocNotify,
+                                  XPStartPageNotify, XPEndPageNotify */
+} XPPrintEvent;
+
+typedef struct {
+    int            type;       /* base + XPAttributeNotify */
+    unsigned long  serial;     /* # of last request processed by server */
+    Bool           send_event; /* true if from a SendEvent request */
+    Display        *display;   /* Display the event was read from */
+    XPContext      context;    /* print context where operation was requested */
+    int            detail;     /* XPJobAttr, XPDocAttr, XPPageAttr,
+                                  XPPrinterAttr, XPSpoolerAttr,
+                                  XPMediumAttr, XPServerAttr */
+} XPAttributeEvent;
+
+typedef struct {
+    int            type;       /* base + XPDataReadyNotify */
+    unsigned long  serial;     /* # of last request processed by server */
+    Bool           send_event; /* true if from a SendEvent request */
+    Display        *display;   /* Display the event was read from */
+    XPContext      context;    /* print context where operation was requested */
+    unsigned long  available;  /* bytes available for retrieval */
+} XPDataReadyEvent;
+
+
+/**********************************************************
+ *
+ * Function prototypes for library side.
+ */
+
+#if NeedFunctionPrototypes
+
+extern XPContext XpCreateContext (
+    Display            *display,
+    char               *printer_name
+);
+
+extern void XpSetContext (
+    Display            *display,
+    XPContext          print_context
+);
+
+extern XPContext XpGetContext (
+    Display            *display
+);
+
+extern void XpDestroyContext (
+    Display            *display,
+    XPContext          print_context
+);
+
+extern Screen *XpGetScreenOfContext (
+    Display            *display,
+    XPContext          print_context
+);
+
+extern Status XpGetPageDimensions (
+    Display            *display,
+    XPContext          print_context,
+    unsigned short     *width,                 /* return value */
+    unsigned short     *height,                /* return value */
+    XRectangle         *reproducible_area      /* return value */
+);
+
+extern void XpStartJob (
+    Display            *display,
+    XPSaveData         save_data
+);
+
+extern void XpEndJob (
+    Display            *display
+);
+
+extern void XpCancelJob (
+    Display            *display,
+    Bool               discard
+);
+
+extern void XpStartDoc (
+    Display            *display,
+    XPDocumentType     type
+);
+
+extern void XpEndDoc (
+    Display            *display
+);
+
+extern void XpCancelDoc (
+    Display            *display,
+    Bool               discard
+);
+
+extern void XpPutDocumentData (
+    Display            *display,
+    Drawable           drawable,
+    unsigned char      *data,
+    int                        data_len,
+    char               *doc_fmt,
+    char               *options
+);
+
+extern Status XpGetDocumentData (
+    Display            *display,
+    XPContext          context,
+    XPSaveProc         save_proc,
+    XPFinishProc       finish_proc,
+    XPointer           client_data
+);
+
+extern void XpStartPage (
+    Display            *display,
+    Window             window
+);
+
+extern void XpEndPage (
+    Display            *display
+);
+
+extern void XpCancelPage (
+    Display            *display,
+    Bool               discard
+);
+
+extern void XpSelectInput (
+    Display            *display,
+    XPContext          print_context,
+    unsigned long      event_mask
+);
+
+extern unsigned long XpInputSelected (
+    Display            *display,
+    XPContext          print_context,
+    unsigned long      *all_events_mask
+);
+
+extern Bool XpSetImageResolution (
+    Display            *display,
+    XPContext          print_context,
+    int                        image_res,
+    int                        *prev_res
+);
+
+extern int XpGetImageResolution (
+    Display            *display,
+    XPContext          print_context
+);
+
+extern char *XpGetAttributes (
+    Display            *display,
+    XPContext          print_context,
+    XPAttributes       type
+);
+
+extern void XpSetAttributes (
+    Display            *display,
+    XPContext          print_context,
+    XPAttributes       type,
+    char               *pool,
+    XPAttrReplacement  replacement_rule
+);
+
+extern char *XpGetOneAttribute (
+    Display            *display,
+    XPContext          print_context,
+    XPAttributes       type,
+    char               *attribute_name
+);
+
+extern XPPrinterList XpGetPrinterList (
+    Display            *display,
+    char               *printer_name,
+    int                        *list_count             /* return value */
+);
+
+extern void XpFreePrinterList (
+    XPPrinterList      printer_list
+);
+
+extern void XpRehashPrinterList (
+    Display            *display
+);
+
+extern Status XpQueryVersion (
+    Display            *display,
+    short              *major_version,         /* return value */
+    short              *minor_version          /* return value */
+);
+
+extern Bool XpQueryExtension (
+    Display            *display,
+    int                        *event_base_return,     /* return value */
+    int                        *error_base_return      /* return value */
+);
+
+extern Screen **XpQueryScreens (
+    Display            *display,
+    int                        *list_count             /* return value */
+);
+
+extern Status XpGetPdmStartParams (
+    Display            *print_display,
+    Window             print_window,
+    XPContext          print_context,
+    Display            *video_display,
+    Window             video_window,
+    Display            **selection_display,    /* return value */
+    Atom               *selection,             /* return value */
+    Atom               *type,                  /* return value */
+    int                        *format,                /* return value */
+    unsigned char      **data,                 /* return value */
+    int                        *nelements              /* return value */
+);
+
+extern Status XpGetAuthParams (
+    Display            *print_display,
+    Display            *video_display,
+    Display            **selection_display,    /* return value */
+    Atom               *selection,             /* return value */
+    Atom               *target                 /* return value */
+);
+
+extern Status XpSendAuth (
+    Display            *display,
+    Window             window
+);
+
+extern Status XpSendOneTicket (
+    Display            *display,
+    Window             window,
+    Xauth              *ticket,
+    Bool               more
+);
+
+extern void XpSetLocaleHinter (
+    XPHinterProc hinter_proc,
+    char         *hinter_desc
+);
+
+extern char *XpGetLocaleHinter (
+    XPHinterProc *hinter_proc
+);
+
+
+
+
+extern char *XpGetLocaleNetString();
+
+extern char *XpNotifyPdm (
+    Display            *print_display,
+    Window             print_window,
+    XPContext          print_context,
+    Display            *video_display,
+    Window             video_window,
+    Bool               auth_flag
+);
+
+#else
+
+extern XPContext XpCreateContext ();
+extern void XpSetContext ();
+extern XPContext XpGetContext ();
+extern void XpDestroyContext ();
+extern Screen *XpGetScreenOfContext ();
+extern Status XpGetPageDimensions ();
+extern void XpStartJob ();
+extern void XpEndJob ();
+extern void XpCancelJob ();
+extern void XpStartDoc ();
+extern void XpEndDoc ();
+extern void XpCancelDoc ();
+extern void XpPutDocumentData ();
+extern Status XpGetDocumentData ();
+extern void XpStartPage ();
+extern void XpEndPage ();
+extern void XpCancelPage ();
+extern void XpSelectInput ();
+extern unsigned long XpInputSelected ();
+extern Bool XpSetImageResolution ();
+extern int XpGetImageResolution ();
+extern char *XpGetAttributes ();
+extern void XpSetAttributes ();
+extern char *XpGetOneAttribute ();
+extern XPPrinterList XpGetPrinterList ();
+extern void XpFreePrinterList ();
+extern void XpRehashPrinterList ();
+extern Status XpQueryVersion ();
+extern Bool XpQueryExtension ();
+extern Screen **XpQueryScreens ();
+extern Status XpGetPdmStartParams ();
+extern Status XpGetAuthParams ();
+extern Status XpSendAuth ();
+extern Status XpSendOneTicket ();
+extern void XpSetLocaleHinter ();
+extern char *XpGetLocaleHinter ();
+
+extern char *XpGetLocaleNetString ();
+extern char *XpNotifyPdm ();
+
+#endif /* NeedFunctionPrototypes */
+
+#endif /* _XP_PRINT_SERVER_ */
+
+_XFUNCPROTOEND
+
+#endif /* _XpPrint_H_ */
diff --git a/Xserver/include/extensions/Printstr.h b/Xserver/include/extensions/Printstr.h
new file mode 100644 (file)
index 0000000..40c67f5
--- /dev/null
@@ -0,0 +1,732 @@
+/* $XConsortium: Printstr.h /main/2 1996/11/16 15:20:15 rws $ */
+/******************************************************************************
+ ******************************************************************************
+ **
+ ** File:         Printstr.h
+ **
+ ** Description: Definitions needed by the server and library, but
+ **              not clients.
+ **
+ **              Print.h for server, library and clients.
+ **
+ ******************************************************************************
+ **
+ ** (c) Copyright 1996 Hewlett-Packard Company
+ ** (c) Copyright 1996 International Business Machines Corp.
+ ** (c) Copyright 1996 Sun Microsystems, Inc.
+ ** (c) Copyright 1996 Novell, Inc.
+ ** (c) Copyright 1996 Digital Equipment Corp.
+ ** (c) Copyright 1996 Fujitsu Limited
+ ** (c) Copyright 1996 Hitachi, Ltd.
+ ** 
+ ** Permission is hereby granted, free of charge, to any person obtaining a copy
+ ** of this software and associated documentation files (the "Software"), to deal
+ ** in the Software without restriction, including without limitation the rights
+ ** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ ** copies of the Software, and to permit persons to whom the Software is
+ ** furnished to do so, subject to the following conditions:
+ **
+ ** The above copyright notice and this permission notice shall be included in
+ ** all copies or substantial portions of the Software.
+ **
+ ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ ** IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ ** FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+ ** COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
+ ** IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ ** CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ **
+ ** Except as contained in this notice, the names of the copyright holders shall
+ ** not be used in advertising or otherwise to promote the sale, use or other
+ ** dealings in this Software without prior written authorization from said
+ ** copyright holders.
+ **
+ ******************************************************************************
+ *****************************************************************************/
+
+
+#ifndef _XpPrintstr_H_
+#define _XpPrintstr_H_
+
+/*
+ * NEED_EVENTS and NEED_REPLIES are hacks to limit the linker symbol-table
+ * size.   When function prototypes are needed from Print.h, this sets up
+ * a cascading dependency on Printstr.h and eventually Xproto.h to provide
+ * the event and reply struct definitions.
+ */
+#ifndef NEED_EVENTS
+#define NEED_EVENTS
+#endif /* NEED_EVENTS */
+
+#define NEED_REPLIES
+
+#include <X11/Xproto.h>
+#ifndef _XP_PRINT_SERVER_
+#include <X11/Xlib.h>
+#endif /* _XP_PRINT_SERVER_ */
+
+/*
+ * Pull in other definitions.  Print.h will hide some things if we're
+ * doing server side work.
+ */
+#include <X11/extensions/Print.h>
+
+#include <X11/Xfuncproto.h>
+
+_XFUNCPROTOBEGIN
+
+/******************************************************************************
+ *
+ * Protocol requests constants and alignment values
+ *
+ * Note: Xlib macro's expect X_ABC where ABC is the name of the
+ * protocol request.
+ */
+#define X_PrintQueryVersion            0
+#define X_PrintGetPrinterList          1
+#define X_PrintCreateContext           2
+#define X_PrintSetContext              3
+#define X_PrintGetContext              4
+#define X_PrintDestroyContext          5
+#define X_PrintGetContextScreen                6
+#define X_PrintStartJob                        7
+#define X_PrintEndJob                  8
+#define X_PrintStartDoc                        9
+#define X_PrintEndDoc                  10
+#define X_PrintPutDocumentData         11
+#define X_PrintGetDocumentData         12
+#define X_PrintStartPage               13
+#define X_PrintEndPage                 14
+#define X_PrintSelectInput             15
+#define X_PrintInputSelected           16
+#define X_PrintGetAttributes           17
+#define X_PrintSetAttributes           18
+#define X_PrintGetOneAttribute         19
+#define X_PrintRehashPrinterList       20
+#define X_PrintGetPageDimensions       21
+#define X_PrintQueryScreens            22
+#define X_PrintSetImageResolution      23
+#define X_PrintGetImageResolution      24
+
+/********************************************************************
+ *
+ * Protocol data types
+ */
+#define PCONTEXT CARD32
+#define WINDOW   CARD32
+#define DRAWABLE CARD32
+#define BITMASK  CARD32
+
+/******************************************************************************
+ *
+ * Event wire struct definitions
+ *
+ * Note: Xlib macro's expect xABC struct names and sz_xABC size
+ * constants where ABC is the name of the protocol request.
+ */
+
+
+/*********************************************************************
+ *
+ * Events.
+ *
+ * See Print.h for the protocol "type" values.
+ */
+typedef struct _xPrintPrintEvent {
+       BYTE type;              /* XPPrintNotify + extEntry->eventBase */
+       BYTE detail;            /* XPStartJobNotify, XPEndJobNotify,
+                                  XPStartDocNotify, XPEndDocNotify,
+                                  XPStartPageNotify, XPEndPageNotify */
+       CARD16 sequenceNumber B16;
+       PCONTEXT printContext B32; /* print context */
+       BOOL   cancel;          /* canceled flag */
+       CARD8  pad1;            /* rest is unused */
+       CARD16 pad2 B16;
+       CARD32 pad3 B32;
+       CARD32 pad4 B32;
+       CARD32 pad5 B32;
+       CARD32 pad6 B32;
+       CARD32 pad7 B32;
+} xPrintPrintEvent;
+#define sz_xPrintPrintEvent 32;
+
+typedef struct _xPrintAttributeEvent {
+       BYTE   type;            /* XPAttributeNotify + extEntry->eventBase */
+       BYTE   detail;          /* XPJobAttr, XPDocAttr, XPPageAttr,
+                                  XPPrinterAttr, XPSpoolerAttr,
+                                  XPMediumAttr, XPServerAttr */
+       CARD16 sequenceNumber B16;
+       PCONTEXT printContext B32; /* print context */
+       CARD32 pad1 B32;
+       CARD32 pad2 B32;
+       CARD32 pad3 B32;
+       CARD32 pad4 B32;
+       CARD32 pad5 B32;
+       CARD32 pad6 B32;
+} xPrintAttributeEvent;
+#define sz_xPrintAttributeEvent 32;
+
+
+/*********************************************************************
+ *
+ * Requests
+ */
+typedef struct _PrintQueryVersion {
+       CARD8   reqType;                /* always PrintReqCode */
+       CARD8   printReqType;           /* always X_PrintQueryVersion */
+       CARD16  length B16;
+} xPrintQueryVersionReq;
+#define sz_xPrintQueryVersionReq       4
+
+typedef struct {
+       BYTE    type;                   /* X_Reply */
+       CARD8   unused;                 /* not used */
+       CARD16  sequenceNumber B16;
+       CARD32  length B32;
+       CARD16  majorVersion B16;       /* major version of Xp protocol */
+       CARD16  minorVersion B16;       /* minor version of Xp protocol */
+       CARD32  pad1 B32;
+       CARD32  pad2 B32;
+       CARD32  pad3 B32;
+       CARD32  pad4 B32;
+       CARD32  pad5 B32;
+} xPrintQueryVersionReply;
+#define sz_xPrintQueryVersionReply     32
+
+
+typedef struct _PrintGetPrinterList {
+       CARD8   reqType;                /* always PrintReqCode */
+       CARD8   printReqType;           /* always X_PrintGetPrinterList */
+       CARD16  length B16;
+       CARD32  printerNameLen B32;     /* length of printer name */
+       CARD32  localeLen B32;          /* length of locale string */
+
+       /* variable portion *****************************************
+       STRING8 printerName;             * printer name *
+       BYTE    pad(printerNameLen)      * unused *
+       STRING8 locale;                  * locale *
+       BYTE    pad(localeLen)           * unused *
+       ************************************************************/
+} xPrintGetPrinterListReq;
+#define sz_xPrintGetPrinterListReq     12
+
+typedef struct {
+       BYTE    type;                   /* X_Reply */
+       CARD8   unused;                 /* not used */
+       CARD16  sequenceNumber B16;
+       CARD32  length B32;
+       CARD32  listCount B32;          /* of PRINTER recs below */
+       CARD32  pad1 B32;
+       CARD32  pad2 B32;
+       CARD32  pad3 B32;
+       CARD32  pad4 B32;
+       CARD32  pad5 B32;
+
+       /* variable portion *****************************************
+       CARD32  nameLen B32;            * length of name in bytes *
+       STRING8 name;                   * name *
+       BYTE    pad(nameLen)            * unused *
+
+       CARD32  descLen B32;            * length of desc in bytes *
+       STRING8 desc;                   * localized description *
+       BYTE    pad(descLen)            * unused *
+       ************************************************************/
+} xPrintGetPrinterListReply;
+#define sz_xPrintGetPrinterListReply   32
+
+
+typedef struct _PrintRehashPrinterList {
+       CARD8   reqType;                /* always PrintReqCode */
+       CARD8   printReqType;           /* always X_PrintRehashPrinterList */
+       CARD16  length B16;
+} xPrintRehashPrinterListReq;
+#define sz_xPrintRehashPrinterListReq  4
+
+
+typedef struct _PrintCreateContext {
+       CARD8   reqType;                /* always PrintReqCode */
+       CARD8   printReqType;           /* always X_PrintInitSetContext */
+       CARD16  length B16;
+       CARD32  contextID B32;          /* ID for context */
+       CARD32  printerNameLen B32;     /* length of printerName in bytes */
+       CARD32  localeLen B32;          /* length of locale in bytes */
+
+       /* variable portion *****************************************
+       STRING8 printerName              * printer name *
+       BYTE    pad(printerNameLen)      * unused *
+       STRING8 locale                   * locale *
+       BYTE    pad(locale)              * unused *
+       ************************************************************/
+} xPrintCreateContextReq;              
+#define sz_xPrintCreateContextReq      16
+
+
+typedef struct _PrintSetContext {
+       CARD8   reqType;                /* always PrintReqCode */
+       CARD8   printReqType;           /* always X_PrintSetContext */
+       CARD16  length B16;
+       PCONTEXT printContext B32;      /* print context */
+} xPrintSetContextReq;         
+#define sz_xPrintSetContextReq         8
+
+
+typedef struct _PrintGetContext {
+       CARD8   reqType;                /* always PrintReqCode */
+       CARD8   printReqType;           /* always X_PrintGetContext */
+       CARD16  length B16;
+} xPrintGetContextReq;         
+#define sz_xPrintGetContextReq         4
+
+typedef struct {
+       BYTE    type;                   /* X_Reply */
+       CARD8   unused;                 /* not used */
+       CARD16  sequenceNumber B16;
+       CARD32  length B32;
+       PCONTEXT printContext B32;      /* print context */
+       CARD32  pad1 B32;
+       CARD32  pad2 B32;
+       CARD32  pad3 B32;
+       CARD32  pad4 B32;
+       CARD32  pad5 B32;
+} xPrintGetContextReply;
+#define sz_xPrintGetContextReply       32
+
+
+typedef struct _PrintDestroyContext {
+       CARD8   reqType;                /* always PrintReqCode */
+       CARD8   printReqType;           /* always X_PrintDestroyContext */
+       CARD16  length B16;
+       PCONTEXT printContext B32;      /* print context */
+} xPrintDestroyContextReq;             
+#define sz_xPrintDestroyContextReq     8
+
+
+typedef struct _PrintGetContextScreen {
+       CARD8   reqType;                /* always PrintReqCode */
+       CARD8   printReqType;           /* always X_PrintGetContextScreen */
+       CARD16  length B16;
+       PCONTEXT printContext B32;      /* print context */
+} xPrintGetContextScreenReq;           
+#define sz_xPrintGetContextScreenReq   8
+
+typedef struct {
+       BYTE    type;                   /* X_Reply */
+       CARD8   unused;                 /* not used */
+       CARD16  sequenceNumber B16;
+       CARD32  length B32;
+       WINDOW  rootWindow;             /* screenPtr represented as rootWin */
+       CARD32  pad1 B32;
+       CARD32  pad2 B32;
+       CARD32  pad3 B32;
+       CARD32  pad4 B32;
+       CARD32  pad5 B32;
+} xPrintGetContextScreenReply;
+#define sz_xPrintGetContextScreenReply 32
+
+
+typedef struct _PrintStartJob {
+       CARD8   reqType;                /* always PrintReqCode */
+       CARD8   printReqType;           /* always X_PrintStartJob */
+       CARD16  length B16;
+       CARD8   saveData;               /* save data boolean */
+       CARD8   pad1;
+       CARD16  pad2 B16;
+} xPrintStartJobReq;           
+#define sz_xPrintStartJobReq           8
+
+typedef struct _PrintEndJob {
+       CARD8   reqType;                /* always PrintReqCode */
+       CARD8   printReqType;           /* always X_PrintEndJob */
+       CARD16  length B16;
+       BOOL    cancel;                 /* cancel boolean */
+       CARD8   pad1;
+       CARD16  pad2 B16;
+} xPrintEndJobReq;
+#define sz_xPrintEndJobReq             8
+
+
+typedef struct _PrintStartDoc {
+       CARD8   reqType;                /* always PrintReqCode */
+       CARD8   printReqType;           /* always X_PrintStartDoc */
+       CARD16  length B16;
+       CARD8   type;                   /* type for document */
+       CARD8   pad1;
+       CARD16  pad2 B16;
+} xPrintStartDocReq;           
+#define sz_xPrintStartDocReq           8
+
+typedef struct _PrintEndDoc {
+       CARD8   reqType;                /* always PrintReqCode */
+       CARD8   printReqType;           /* always X_PrintEndDoc */
+       CARD16  length B16;
+       BOOL    cancel;                 /* cancel boolean */
+       CARD8   pad1;
+       CARD16  pad2 B16;
+} xPrintEndDocReq;
+#define sz_xPrintEndDocReq             8
+
+
+typedef struct _PrintPutDocumentData {
+       CARD8   reqType;                /* always PrintReqCode */
+       CARD8   printReqType;           /* always X_PrintPutDocumentData */
+       CARD16  length B16;
+       DRAWABLE drawable B32;          /* target drawable */
+       CARD32  len_data B32;           /* big len in bytes */
+       CARD16  len_fmt;                /* len in bytes */
+       CARD16  len_options;            /* len in bytes */
+
+       /* variable portion *****************************************
+       LISTofBYTE      data;            * data *
+       BYTE            pad(len_data)    * unused *
+       STRING8         doc_fmt;         * ISO compliant desc of data type *
+       BYTE            pad(len_fmt)     * unused *
+       STRING8         options;         * additional device-dependent desc *
+       BYTE            pad(len_options) * unused *
+       ************************************************************/
+} xPrintPutDocumentDataReq;
+#define sz_xPrintPutDocumentDataReq    16
+
+
+typedef struct _PrintGetDocumentData {
+       CARD8   reqType;                /* always PrintReqCode */
+       CARD8   printReqType;           /* always X_PrintGetDocumentData */
+       CARD16  length B16;
+       PCONTEXT printContext B32;      /* print context */
+       CARD32  maxBufferSize B32;      /* maximum buffer size requested */
+} xPrintGetDocumentDataReq;            
+#define sz_xPrintGetDocumentDataReq    12
+
+typedef struct {
+       BYTE    type;                   /* X_Reply */
+       CARD8   unused;                 /* not used */
+       CARD16  sequenceNumber B16;
+       CARD32  length B32;
+       CARD32  statusCode B32;         /* status code for reply */
+       CARD32  finishedFlag B32;       /* is this the last reply */
+       CARD32  dataLen B32;            /* data length */
+       CARD32  pad1 B32;
+       CARD32  pad2 B32;
+       CARD32  pad3 B32;
+
+       /* variable portion *****************************************
+       LISTofBYTE      data;            * data *
+       BYTE            pad(count)       * unused *
+       ************************************************************/
+} xPrintGetDocumentDataReply;
+#define sz_xPrintGetDocumentDataReply  32
+
+
+typedef struct _PrintStartPage {
+       CARD8   reqType;                /* always PrintReqCode */
+       CARD8   printReqType;           /* always X_PrintStartPage */
+       CARD16  length B16;
+       WINDOW  window B32;             /* window */
+} xPrintStartPageReq;          
+#define sz_xPrintStartPageReq          8
+
+typedef struct _PrintEndPage {
+       CARD8   reqType;                /* always PrintReqCode */
+       CARD8   printReqType;           /* always X_PrintEndPage */
+       CARD16  length B16;
+       BOOL    cancel;                 /* cancel boolean */
+       CARD8   pad1;
+       CARD16  pad2 B16;
+} xPrintEndPageReq;
+#define sz_xPrintEndPageReq            8
+
+
+typedef struct _PrintSelectInput {
+        CARD8   reqType;               /* always PrintReqCode */
+       CARD8   printReqType;           /* always X_PrintSelectInput */
+       CARD16  length B16;
+       PCONTEXT printContext B32;      /* print context */
+       BITMASK eventMask B32;
+} xPrintSelectInputReq;
+#define sz_xPrintSelectInputReq                12
+
+
+typedef struct _PrintInputSelected {
+        CARD8   reqType;               /* always PrintReqCode */
+       CARD8   printReqType;           /* always X_PrintInputSelected */
+       CARD16  length B16;
+       PCONTEXT printContext B32;      /* print context */
+} xPrintInputSelectedReq;
+#define sz_xPrintInputSelectedReq      8
+
+typedef struct {
+       BYTE    type;                   /* X_Reply */
+       CARD8   unused;                 /* not used */
+       CARD16  sequenceNumber B16;
+       CARD32  length B32;
+       BITMASK eventMask B32;          /* your event mask */
+       BITMASK allEventsMask B32;      /* all event mask */
+       CARD32  pad1 B32;
+       CARD32  pad2 B32;
+       CARD32  pad3 B32;
+       CARD32  pad4 B32;
+} xPrintInputSelectedReply;
+#define sz_xPrintInputSelectedReply    32
+
+typedef struct _PrintGetAttributes {
+        CARD8   reqType;               /* always PrintReqCode */
+       CARD8   printReqType;           /* always X_PrintGetAttributes */
+       CARD16  length B16;
+       PCONTEXT printContext B32;      /* print context */
+        CARD8   type;                  /* type */
+        CARD8   pad1;                  /* unused */
+        CARD16  pad2 B16;              /* unused */
+} xPrintGetAttributesReq;
+#define sz_xPrintGetAttributesReq      12
+
+typedef struct {
+       BYTE    type;                   /* X_Reply */
+       CARD8   unused;                 /* not used */
+       CARD16  sequenceNumber B16;
+       CARD32  length B32;
+       CARD32  stringLen B32;          /* length of xrm db string */
+       CARD32  pad1 B32;
+       CARD32  pad2 B32;
+       CARD32  pad3 B32;
+       CARD32  pad4 B32;
+       CARD32  pad5 B32;
+
+        /* variable portion *****************************************
+       STRING8 string;                  * xrm db as a string *
+       BYTE    pad(stringLen)           * unused *
+        ************************************************************/
+} xPrintGetAttributesReply;
+#define sz_xPrintGetAttributesReply    32
+
+
+typedef struct _PrintSetAttributes {
+        CARD8   reqType;               /* always PrintReqCode */
+       CARD8   printReqType;           /* always X_PrintSetAttributes */
+       CARD16  length B16;
+       PCONTEXT printContext B32;      /* print context */
+       CARD32  stringLen B32;          /* length of xrm db string */
+        CARD8   type;                   /* type */
+       CARD8   rule;                   /* replacement rule */
+       CARD16  pad1 B16;               /* unused */
+
+        /* variable portion *****************************************
+       STRING8 string;                  * xrm db as a string *
+       BYTE    pad(stringLen)           * unused *
+        ************************************************************/
+} xPrintSetAttributesReq;
+#define sz_xPrintSetAttributesReq      16
+
+
+typedef struct _PrintGetOneAttribute {
+        CARD8   reqType;               /* always PrintReqCode */
+       CARD8   printReqType;           /* always X_PrintGetOneAttribute */
+       CARD16  length B16;
+       PCONTEXT printContext B32;      /* print context */
+       CARD32  nameLen;                /* length of name string */
+        CARD8   type;                  /* type */
+        CARD8   pad1;                  /* unused */
+        CARD16  pad2 B16;              /* unused */
+
+        /* variable portion *****************************************
+       STRING8 name;                    * name as a string *
+       BYTE    pad(name)                * unused *
+        ************************************************************/
+} xPrintGetOneAttributeReq;
+#define sz_xPrintGetOneAttributeReq    16
+
+typedef struct {
+       BYTE    type;                   /* X_Reply */
+       CARD8   unused;                 /* not used */
+       CARD16  sequenceNumber B16;
+       CARD32  length B32;
+       CARD32  valueLen B32;           /* length of value string */
+       CARD32  pad1 B32;
+       CARD32  pad2 B32;
+       CARD32  pad3 B32;
+       CARD32  pad4 B32;
+       CARD32  pad5 B32;
+
+        /* variable portion *****************************************
+       STRING8 value;                   * value as a string *
+       BYTE    pad(value)               * unused *
+        ************************************************************/
+} xPrintGetOneAttributeReply;
+#define sz_xPrintGetOneAttributeReply  32
+
+
+typedef struct _PrintGetPageDimensions {
+       CARD8   reqType;                /* always PrintReqCode */
+       CARD8   printReqType;           /* always X_PrintGetPageDimensions */
+       CARD16  length B16;
+       PCONTEXT printContext B32;      /* print context */
+} xPrintGetPageDimensionsReq;          
+#define sz_xPrintGetPageDimensionsReq  8
+
+typedef struct {
+       BYTE    type;                   /* X_Reply */
+       CARD8   unused;                 /* not used */
+       CARD16  sequenceNumber B16;
+       CARD32  length B32;
+       CARD16  width;                  /* total pixel width */
+       CARD16  height;                 /* total pixel height */
+       CARD16  rx;                     /* reproducable x pixel offset */
+       CARD16  ry;                     /* reproducable y pixel offset */
+       CARD16  rwidth;                 /* reproducable x pixel width */
+       CARD16  rheight;                /* reproducable y pixel width */
+       CARD32  pad1 B32;
+       CARD32  pad2 B32;
+       CARD32  pad3 B32;
+} xPrintGetPageDimensionsReply;
+#define sz_xPrintGetPageDimensionsReply        32
+
+
+typedef struct _PrintQueryScreens {
+       CARD8   reqType;                /* always PrintReqCode */
+       CARD8   printReqType;           /* always X_PrintQueryScreens */
+       CARD16  length B16;
+} xPrintQueryScreensReq;               
+#define sz_xPrintQueryScreensReq       4
+
+typedef struct {
+       BYTE    type;                   /* X_Reply */
+       CARD8   unused;                 /* not used */
+       CARD16  sequenceNumber B16;
+       CARD32  length B32;
+       CARD32  listCount;              /* number of screens following */
+       CARD32  pad1 B32;
+       CARD32  pad2 B32;
+       CARD32  pad3 B32;
+       CARD32  pad4 B32;
+       CARD32  pad5 B32;
+
+        /* variable portion *****************************************
+       WINDOW  rootWindow;              * root window of screen *
+        ************************************************************/
+} xPrintQueryScreensReply;
+#define sz_xPrintQueryScreensReply     32
+
+typedef struct _PrintSetImageResolution {
+       CARD8   reqType;                /* always PrintReqCode */
+       CARD8   printReqType;           /* always X_PrintSetImageResolution */
+       CARD16  length B16;
+       PCONTEXT printContext B32;      /* print context */
+       CARD16 imageRes B16;            /* image resolution */
+       CARD16 pad1 B16;
+} xPrintSetImageResolutionReq;
+#define sz_xPrintSetImageResolutionReq 12
+
+typedef struct {
+       BYTE    type;                   /* X_Reply */
+       BOOL    status;                 /* accepted or not */
+       CARD16  sequenceNumber B16;
+       CARD32  length B32;
+       CARD16  prevRes B16;            /* previous resolution */
+       CARD16  pad1 B32;
+       CARD32  pad2 B32;
+       CARD32  pad3 B32;
+       CARD32  pad4 B32;
+       CARD32  pad5 B32;
+       CARD32  pad6 B32;
+} xPrintSetImageResolutionReply;
+#define sz_xPrintSetImageResolutionReply 32
+
+typedef struct _PrintGetImageResolution {
+       CARD8   reqType;                /* always PrintReqCode */
+       CARD8   printReqType;           /* always X_PrintGetImageResolution */
+       CARD16  length B16;
+       PCONTEXT printContext B32;      /* print context */
+} xPrintGetImageResolutionReq;
+#define sz_xPrintGetImageResolutionReq 8
+
+typedef struct {
+       BYTE    type;                   /* X_Reply */
+       CARD8   unused;
+       CARD16  sequenceNumber B16;
+       CARD32  length B32;
+       CARD16  imageRes B16;           /* image resolution */
+       CARD16  pad1 B32;
+       CARD32  pad2 B32;
+       CARD32  pad3 B32;
+       CARD32  pad4 B32;
+       CARD32  pad5 B32;
+       CARD32  pad6 B32;
+} xPrintGetImageResolutionReply;
+#define sz_xPrintGetImageResolutionReply 32
+
+#ifndef _XP_PRINT_SERVER_
+/***********************************************************************
+ *
+ * Library-only definitions.
+ */
+extern XPHinterProc  _xp_hinter_proc;
+extern char         *_xp_hinter_desc;
+extern int           _xp_hinter_init;
+
+#endif /* _XP_PRINT_SERVER_ */
+
+#ifdef _XP_PRINT_SERVER_
+/***********************************************************************
+ *
+ * Server-only definitions shared between the extension and DDX layers.
+ *
+ */
+/*
+ * Internal return code used to indicate that the requesting
+ * client has been suspended.
+ */
+#define Suspended 84
+
+extern void XpRegisterPrinterScreen(
+    ScreenPtr pScreen,
+    int (*CreateContext)());
+
+typedef struct _xpprintFuncs {
+    int (*StartJob)(); /* pContext, client */
+    int (*EndJob)(); /* pContext, client */
+    int (*StartDoc)(); /* pContext, client */
+    int (*EndDoc)(); /* pContext, client */
+    int (*StartPage)(); /* pContext, pWin, client, exposures */
+    int (*EndPage)(); /* pContext, client */
+    int (*PutDocumentData)(); /* pContext,pDraw,pData,len_data,pFmt,len_fmt,pOpt,len_opt, client */
+    int (*GetDocumentData)(); /* pContext,pData,len_data,pFmt,len_fmt,pOpt,len_opt, client */
+    int (*DestroyContext)(); /* pContext, client */
+    char *(*GetAttributes)(); /* pContext, pool */
+    char *(*GetOneAttribute)(); /* pContext, pool, attr */
+    int (*SetAttributes)(); /* pContext, pool, attrs */
+    int (*AugmentAttributes)(); /* pContext, pool, attrs */
+    int (*GetMediumDimensions)(); /* pPrintContext, pWidth, pHeight */
+    int (*GetReproducibleArea)(); /* pPrintContext, pRect */
+    int (*SetImageResolution)(); /* pPrintContext, imageRes, pStatus */
+} XpDriverFuncs, *XpDriverFuncsPtr;
+
+/*
+ * Each print context is represented by one of the following structs
+ * associated with a resource ID of type RTcontext .  A pointer to
+ * the context is placed in the Xp extension's devPrivates
+ * element in each client * which establishes a context via
+ * either initContext or setContext.
+ * The context pointer is also placed in the struct indicated by the
+ * RTpage resource associated with each StartPage'd window.
+ */
+typedef struct _XpContext {
+        XID contextID;
+        char *printerName;
+        int screenNum;          /* screen containing the printer */
+        struct _XpClient *clientHead; /* list of clients */
+        CARD32 state;
+        VisualID pageWin;
+        DevUnion *devPrivates;
+        XpDriverFuncs funcs;
+       ClientPtr clientSlept;
+       int imageRes;
+} XpContextRec, *XpContextPtr;
+
+extern XpContextPtr XpGetPrintContext(
+    ClientPtr client);
+
+#endif /* _XP_PRINT_SERVER_ */
+
+_XFUNCPROTOEND
+
+#endif /* _XpPrintstr_H_ */
+
diff --git a/Xserver/include/extensions/XI.h b/Xserver/include/extensions/XI.h
new file mode 100644 (file)
index 0000000..4bff96d
--- /dev/null
@@ -0,0 +1,269 @@
+/* $XConsortium: XI.h /main/16 1995/12/05 11:17:30 dpw $ */
+
+/************************************************************
+
+Copyright (c) 1989  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+Copyright (c) 1989 by Hewlett-Packard Company, Palo Alto, California.
+
+                       All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and its
+documentation for any purpose and without fee is hereby granted,
+provided that the above copyright notice appear in all copies and that
+both that copyright notice and this permission notice appear in
+supporting documentation, and that the name of Hewlett-Packard not be
+used in advertising or publicity pertaining to distribution of the
+software without specific, written prior permission.
+
+HEWLETT-PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
+ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
+HEWLETT-PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
+ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+SOFTWARE.
+
+********************************************************/
+
+/* Definitions used by the server, library and client */
+
+#ifndef _XI_H_
+
+#define _XI_H_
+
+#define sz_xGetExtensionVersionReq             8
+#define sz_xGetExtensionVersionReply           32
+#define sz_xListInputDevicesReq                        4
+#define sz_xListInputDevicesReply              32
+#define sz_xOpenDeviceReq                      8
+#define sz_xOpenDeviceReply                    32
+#define sz_xCloseDeviceReq                     8
+#define sz_xSetDeviceModeReq                   8
+#define sz_xSetDeviceModeReply                 32
+#define sz_xSelectExtensionEventReq            12
+#define sz_xGetSelectedExtensionEventsReq      8
+#define sz_xGetSelectedExtensionEventsReply    32
+#define sz_xChangeDeviceDontPropagateListReq   12
+#define sz_xGetDeviceDontPropagateListReq      8
+#define sz_xGetDeviceDontPropagateListReply    32
+#define sz_xGetDeviceMotionEventsReq           16
+#define sz_xGetDeviceMotionEventsReply         32
+#define sz_xChangeKeyboardDeviceReq            8
+#define sz_xChangeKeyboardDeviceReply          32
+#define sz_xChangePointerDeviceReq             8
+#define sz_xChangePointerDeviceReply           32
+#define sz_xGrabDeviceReq                      20
+#define sz_xGrabDeviceReply                    32
+#define sz_xUngrabDeviceReq                    12
+#define sz_xGrabDeviceKeyReq                   20
+#define sz_xGrabDeviceKeyReply                 32
+#define sz_xUngrabDeviceKeyReq                 16
+#define sz_xGrabDeviceButtonReq                        20
+#define sz_xGrabDeviceButtonReply              32
+#define sz_xUngrabDeviceButtonReq              16
+#define sz_xAllowDeviceEventsReq               12
+#define sz_xGetDeviceFocusReq                  8
+#define sz_xGetDeviceFocusReply                        32
+#define sz_xSetDeviceFocusReq                  16
+#define sz_xGetFeedbackControlReq              8
+#define sz_xGetFeedbackControlReply            32
+#define sz_xChangeFeedbackControlReq           12
+#define sz_xGetDeviceKeyMappingReq             8
+#define sz_xGetDeviceKeyMappingReply           32
+#define sz_xChangeDeviceKeyMappingReq          8
+#define sz_xGetDeviceModifierMappingReq                8
+#define sz_xSetDeviceModifierMappingReq                8
+#define sz_xSetDeviceModifierMappingReply      32
+#define sz_xGetDeviceButtonMappingReq          8
+#define sz_xGetDeviceButtonMappingReply                32
+#define sz_xSetDeviceButtonMappingReq          8
+#define sz_xSetDeviceButtonMappingReply                32
+#define sz_xQueryDeviceStateReq                        8
+#define sz_xQueryDeviceStateReply              32
+#define sz_xSendExtensionEventReq              16
+#define sz_xDeviceBellReq                      8
+#define sz_xSetDeviceValuatorsReq              8
+#define sz_xSetDeviceValuatorsReply            32
+#define sz_xGetDeviceControlReq                        8
+#define sz_xGetDeviceControlReply              32
+#define sz_xChangeDeviceControlReq             8
+#define sz_xChangeDeviceControlReply           32
+
+#define INAME                  "XInputExtension"
+
+#define XI_KEYBOARD    "KEYBOARD"
+#define XI_MOUSE       "MOUSE"
+#define XI_TABLET      "TABLET"
+#define XI_TOUCHSCREEN "TOUCHSCREEN"
+#define XI_TOUCHPAD    "TOUCHPAD"
+#define XI_BARCODE     "BARCODE"
+#define XI_BUTTONBOX   "BUTTONBOX"
+#define XI_KNOB_BOX    "KNOB_BOX"
+#define XI_ONE_KNOB    "ONE_KNOB"
+#define XI_NINE_KNOB   "NINE_KNOB"
+#define XI_TRACKBALL   "TRACKBALL"
+#define XI_QUADRATURE  "QUADRATURE"
+#define XI_ID_MODULE   "ID_MODULE"
+#define XI_SPACEBALL   "SPACEBALL"
+#define XI_DATAGLOVE   "DATAGLOVE"
+#define XI_EYETRACKER  "EYETRACKER"
+#define XI_CURSORKEYS  "CURSORKEYS"
+#define XI_FOOTMOUSE   "FOOTMOUSE"
+
+#define Dont_Check                     0
+#define XInput_Initial_Release         1
+#define XInput_Add_XDeviceBell         2
+#define XInput_Add_XSetDeviceValuators 3
+#define XInput_Add_XChangeDeviceControl        4
+
+#define XI_Absent              0
+#define XI_Present             1
+
+#define XI_Initial_Release_Major               1
+#define XI_Initial_Release_Minor               0
+
+#define XI_Add_XDeviceBell_Major               1
+#define XI_Add_XDeviceBell_Minor               1
+
+#define XI_Add_XSetDeviceValuators_Major       1
+#define XI_Add_XSetDeviceValuators_Minor       2
+
+#define XI_Add_XChangeDeviceControl_Major      1
+#define XI_Add_XChangeDeviceControl_Minor      3
+
+#define DEVICE_RESOLUTION      1
+
+#define NoSuchExtension                1
+
+#define COUNT                  0
+#define CREATE                 1
+
+#define NewPointer             0
+#define NewKeyboard            1
+
+#define XPOINTER               0
+#define XKEYBOARD              1
+
+#define UseXKeyboard           0xFF
+
+#define IsXPointer             0
+#define IsXKeyboard            1
+#define IsXExtensionDevice     2
+
+#define AsyncThisDevice                0
+#define SyncThisDevice         1
+#define ReplayThisDevice       2
+#define AsyncOtherDevices      3
+#define AsyncAll               4
+#define SyncAll                        5
+
+#define FollowKeyboard                 3
+#ifndef RevertToFollowKeyboard
+#define RevertToFollowKeyboard         3
+#endif
+
+#define DvAccelNum              (1L << 0)
+#define DvAccelDenom            (1L << 1)
+#define DvThreshold             (1L << 2)
+
+#define DvKeyClickPercent      (1L<<0)
+#define DvPercent              (1L<<1)
+#define DvPitch                        (1L<<2)
+#define DvDuration             (1L<<3)
+#define DvLed                  (1L<<4)
+#define DvLedMode              (1L<<5)
+#define DvKey                  (1L<<6)
+#define DvAutoRepeatMode       (1L<<7)
+
+#define DvString                (1L << 0)
+
+#define DvInteger               (1L << 0)
+
+#define DeviceMode              (1L << 0)
+#define Relative                0
+#define Absolute                1
+
+#define ProximityState          (1L << 1)
+#define InProximity             (0L << 1)
+#define OutOfProximity          (1L << 1)
+
+#define AddToList               0
+#define DeleteFromList          1
+
+#define KeyClass               0
+#define ButtonClass            1
+#define ValuatorClass                  2
+#define FeedbackClass                  3
+#define ProximityClass         4
+#define FocusClass             5
+#define OtherClass             6
+
+#define KbdFeedbackClass       0
+#define PtrFeedbackClass       1
+#define StringFeedbackClass    2
+#define IntegerFeedbackClass   3
+#define LedFeedbackClass       4
+#define BellFeedbackClass      5
+
+#define _devicePointerMotionHint 0
+#define _deviceButton1Motion    1
+#define _deviceButton2Motion    2
+#define _deviceButton3Motion    3
+#define _deviceButton4Motion    4
+#define _deviceButton5Motion    5
+#define _deviceButtonMotion     6
+#define _deviceButtonGrab       7
+#define _deviceOwnerGrabButton  8
+#define _noExtensionEvent       9
+
+#define XI_BadDevice   0
+#define XI_BadEvent    1
+#define XI_BadMode     2
+#define XI_DeviceBusy  3
+#define XI_BadClass    4
+
+/* Make XEventClass be a CARD32 for 64 bit servers.  Don't affect client
+ * definition of XEventClass since that would be a library interface change.
+ * See the top of X.h for more _XSERVER64 magic.
+ */
+#ifdef _XSERVER64
+typedef        CARD32          XEventClass;
+#else
+typedef        unsigned long   XEventClass;
+#endif
+
+/*******************************************************************
+ *
+ * Extension version structure.
+ *
+ */
+
+typedef struct {
+        int    present;
+        short  major_version;
+        short  minor_version;
+} XExtensionVersion;
+
+#endif /* _XI_H_ */
diff --git a/Xserver/include/extensions/XIE.h b/Xserver/include/extensions/XIE.h
new file mode 100644 (file)
index 0000000..f426db3
--- /dev/null
@@ -0,0 +1,430 @@
+/* $XConsortium: XIE.h,v 1.5 94/04/17 20:11:11 mor Exp $ */
+/******************************************************************************
+
+
+Copyright (c) 1993, 1994  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+
+                               NOTICE
+                              
+This software is being provided by AGE Logic, Inc. under the
+following license.  By obtaining, using and/or copying this software,
+you agree that you have read, understood, and will comply with these
+terms and conditions:
+
+     Permission to use, copy, modify, distribute and sell this
+     software and its documentation for any purpose and without
+     fee or royalty and to grant others any or all rights granted
+     herein is hereby granted, provided that you agree to comply
+     with the following copyright notice and statements, including
+     the disclaimer, and that the same appears on all copies and
+     derivative works of the software and documentation you make.
+     
+     "Copyright 1993, 1994 by AGE Logic, Inc."
+     
+     THIS SOFTWARE IS PROVIDED "AS IS".  AGE LOGIC MAKES NO
+     REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED.  By way of
+     example, but not limitation, AGE LOGIC MAKE NO
+     REPRESENTATIONS OR WARRANTIES OF MERCHANTABILITY OR FITNESS
+     FOR ANY PARTICULAR PURPOSE OR THAT THE SOFTWARE DOES NOT
+     INFRINGE THIRD-PARTY PROPRIETARY RIGHTS.  AGE LOGIC 
+     SHALL BEAR NO LIABILITY FOR ANY USE OF THIS SOFTWARE.  IN NO
+     EVENT SHALL EITHER PARTY BE LIABLE FOR ANY INDIRECT,
+     INCIDENTAL, SPECIAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOSS
+     OF PROFITS, REVENUE, DATA OR USE, INCURRED BY EITHER PARTY OR
+     ANY THIRD PARTY, WHETHER IN AN ACTION IN CONTRACT OR TORT OR
+     BASED ON A WARRANTY, EVEN IF AGE LOGIC LICENSEES
+     HEREUNDER HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH
+     DAMAGES.
+    
+     The name of AGE Logic, Inc. may not be used in
+     advertising or publicity pertaining to this software without
+     specific, written prior permission from AGE Logic.
+
+     Title to this software shall at all times remain with AGE
+     Logic, Inc.
+
+******************************************************************************/
+
+#ifndef _XIE_H_
+#define _XIE_H_
+
+
+/* Extension Name and version number */
+
+#define xieExtName             "XIE"
+
+#define xieMajorVersion                5
+#define xieMinorVersion                0
+#define xieEarliestMinorVersion        0
+#define xieLatestMinorVersion  0
+
+
+/* ServiceClass */
+
+#ifdef  XIE_DIS
+#define XIE_FULL 0
+#else
+#define XIE_FULL 1
+#endif
+
+#define xieValFull             1
+#define xieValDIS              2
+
+
+/* Limits */
+
+#define xieValMaxBands         3
+
+
+/* Alignment */
+
+#define xieValAlignable                1
+#define xieValArbitrary                2
+
+
+/* ArithmeticOp */
+
+#define xieValAdd              1
+#define xieValSub              2
+#define xieValSubRev           3
+#define xieValMul              4
+#define xieValDiv              5
+#define xieValDivRev           6
+#define xieValMin              7
+#define xieValMax              8
+#define xieValGamma            9
+
+
+/* ColorAllocTechnique */
+
+#define xieValColorAllocDefault                0
+#define xieValColorAllocAll            2
+#define xieValColorAllocMatch          4
+#define xieValColorAllocRequantize     6
+
+
+/* Colorspace conversions */
+
+#define xieValRGBToCIELab      2
+#define xieValRGBToCIEXYZ      4
+#define xieValRGBToYCbCr       6
+#define xieValRGBToYCC         8
+
+#define xieValCIELabToRGB      2
+#define xieValCIEXYZToRGB      4
+#define xieValYCbCrToRGB       6
+#define xieValYCCToRGB         8
+
+
+/* CompareOp */
+
+#define xieValLT       1
+#define xieValLE       2
+#define xieValEQ       3
+#define xieValNE       4
+#define xieValGT       5
+#define xieValGE       6
+
+
+/* ConstrainTechnique */
+
+#define xieValConstrainClipScale       2
+#define xieValConstrainHardClip                4
+
+
+/* ConvolveTechnique */
+
+#define xieValConvolveDefault          0
+#define xieValConvolveConstant         2
+#define xieValConvolveReplicate                4
+
+
+/* DataClass */
+
+#define xieValSingleBand       1
+#define xieValTripleBand       2
+
+/* DataType */
+
+#define xieValConstrained      1
+#define xieValUnconstrained    2
+
+
+/* DecodeTechnique */
+
+#define xieValDecodeUncompressedSingle 2       /* bitonal & grayscale */
+#define xieValDecodeUncompressedTriple 3       /* color */
+#define xieValDecodeG31D               4       /* FAX */
+#define xieValDecodeG32D               6       /* FAX */
+#define xieValDecodeG42D               8       /* FAX */
+#define xieValDecodeJPEGBaseline       10      /* grayscale & color */
+#define xieValDecodeJPEGLossless       12      /* grayscale & color */
+#define xieValDecodeTIFF2              14      /* TIFF modified G31D */
+#define xieValDecodeTIFFPackBits       16      /* TIFF APPLE FORMAT */
+
+
+/* DitherTechnique */
+
+#define xieValDitherDefault            0
+#define xieValDitherErrorDiffusion     2
+#define xieValDitherOrdered            4
+
+
+/* EncodeTechnique */
+
+#define xieValEncodeServerChoice       1       /* (to photomaps) */
+#define xieValEncodeUncompressedSingle 2       /* bitonal & grayscale */
+#define xieValEncodeUncompressedTriple 3       /* color */
+#define xieValEncodeG31D               4       /* FAX */
+#define xieValEncodeG32D               6       /* FAX */
+#define xieValEncodeG42D               8       /* FAX */
+#define xieValEncodeJPEGBaseline       10      /* grayscale & color */
+#define xieValEncodeJPEGLossless       12      /* grayscale & color */
+#define xieValEncodeTIFF2              14      /* TIFF modified G31D */
+#define xieValEncodeTIFFPackBits       16      /* TIFF APPLE FORMAT */
+
+/* ServerChoice preference hints */
+
+#define xieValPreferDefault            0
+#define xieValPreferSpace              1
+#define xieValPreferTime               2
+
+/* JPEG-Lossless predictor */
+
+#define xieValPredictorNone    0
+#define xieValPredictorA       1
+#define xieValPredictorB       2
+#define xieValPredictorC       3
+#define xieValPredictorABC     4
+#define xieValPredictorABC2    5
+#define xieValPredictorBAC2    6
+#define xieValPredictorAB2     7
+
+
+/* ExportNotify */
+
+#define xieValDisable          1
+#define xieValFirstData                2
+#define xieValNewData          3
+
+
+/* ExportState */
+
+#define xieValExportDone       1
+#define xieValExportMore       2
+#define xieValExportEmpty      3
+#define xieValExportError      4
+
+
+/* GamutTechnique */
+
+#define xieValGamutDefault     0
+#define xieValGamutNone                1
+#define xieValGamutClipRGB     2
+
+
+/* GeometryTechnique */
+
+#define xieValGeomDefault              0
+#define xieValGeomAntialias            2
+#define xieValGeomAntialiasByArea      4
+#define xieValGeomAntialiasByLPF       6
+#define xieValGeomBilinearInterp       8
+#define xieValGeomGaussian             10
+#define xieValGeomNearestNeighbor      12
+
+
+/* NearestNeighbor modify */
+
+#define xieValFavorDown                1
+#define xieValFavorUp          2
+#define xieValRoundNW          3
+#define xieValRoundNE          4
+#define xieValRoundSE          5
+#define xieValRoundSW          6
+
+
+/* HistogramShape */
+
+#define        xieValHistogramFlat             2
+#define        xieValHistogramGaussian         4
+#define        xieValHistogramHyperbolic       6
+
+
+/* Interleave */
+
+#define xieValBandByPixel      1
+#define xieValBandByPlane      2
+
+
+/* MathOp */
+
+#define xieValExp      1
+#define xieValLn       2
+#define xieValLog2     3
+#define xieValLog10    4
+#define xieValSquare   5
+#define xieValSqrt     6
+
+
+/* Orientation */
+
+#define xieValLSFirst          1
+#define xieValMSFirst          2
+
+
+/* PhotofloOutcome */
+
+#define xieValFloSuccess       1
+#define xieValFloAbort         2
+#define xieValFloError         3
+
+
+/* PhotofloState */
+
+#define xieValInactive         1
+#define xieValActive           2
+#define xieValNonexistent      3
+
+
+/* TechniqueGroup */
+
+#define        xieValDefault           0
+#define        xieValAll               1
+#define        xieValColorAlloc        2
+#define        xieValConstrain         4
+#define        xieValConvertFromRGB    6
+#define        xieValConvertToRGB      8
+#define        xieValConvolve          10
+#define        xieValDecode            12
+#define        xieValDither            14
+#define        xieValEncode            16
+#define        xieValGamut             18
+#define        xieValGeometry          20
+#define        xieValHistogram         22
+#define        xieValWhiteAdjust       24
+
+#define xieValMaxTechGroup     24
+
+
+/* WhiteAdjustTechnique */
+
+#define        xieValWhiteAdjustDefault        0
+#define        xieValWhiteAdjustNone           1
+#define        xieValWhiteAdjustCIELabShift    2
+
+
+/* Photoflo elements */
+
+#define xieElemImportClientLUT         1
+#define xieElemImportClientPhoto       2
+#define xieElemImportClientROI         3
+#define xieElemImportDrawable          4
+#define xieElemImportDrawablePlane     5
+#define xieElemImportLUT               6
+#define xieElemImportPhotomap          7
+#define xieElemImportROI               8
+#define xieElemArithmetic              9
+#define xieElemBandCombine             10
+#define xieElemBandExtract             11
+#define xieElemBandSelect              12
+#define xieElemBlend                   13
+#define xieElemCompare                 14
+#define xieElemConstrain               15
+#define xieElemConvertFromIndex                16
+#define xieElemConvertFromRGB          17
+#define xieElemConvertToIndex          18
+#define xieElemConvertToRGB            19
+#define xieElemConvolve                        20
+#define xieElemDither                  21
+#define xieElemGeometry                        22
+#define xieElemLogical                 23
+#define xieElemMatchHistogram          24
+#define xieElemMath                    25
+#define xieElemPasteUp                 26
+#define xieElemPoint                   27
+#define xieElemUnconstrain             28
+#define xieElemExportClientHistogram   29
+#define xieElemExportClientLUT         30
+#define xieElemExportClientPhoto       31
+#define xieElemExportClientROI         32
+#define xieElemExportDrawable          33
+#define xieElemExportDrawablePlane     34
+#define xieElemExportLUT               35
+#define xieElemExportPhotomap          36
+#define xieElemExportROI               37
+
+#define xieMaxElem                     37
+
+
+/* Event Codes */
+
+#define xieEvnNoColorAlloc             0
+#define xieEvnNoDecodeNotify           1
+#define xieEvnNoExportAvailable                2
+#define xieEvnNoImportObscured         3
+#define xieEvnNoPhotofloDone           4
+
+#define xieNumEvents                   5
+
+
+/* Error Codes */
+
+#define xieErrNoColorList      0
+#define xieErrNoLUT            1
+#define xieErrNoPhotoflo       2
+#define xieErrNoPhotomap       3
+#define xieErrNoPhotospace     4
+#define xieErrNoROI            5
+#define xieErrNoFlo            6
+
+#define xieNumErrors           7
+
+
+/* Flo Error Codes */
+
+#define xieErrNoFloAccess         1
+#define xieErrNoFloAlloc          2
+#define xieErrNoFloColormap       3
+#define xieErrNoFloColorList      4
+#define xieErrNoFloDomain         5
+#define xieErrNoFloDrawable       6
+#define xieErrNoFloElement        7
+#define xieErrNoFloGC             8
+#define xieErrNoFloID             9
+#define xieErrNoFloLength        10
+#define xieErrNoFloLUT           11
+#define xieErrNoFloMatch         12
+#define xieErrNoFloOperator      13
+#define xieErrNoFloPhotomap      14
+#define xieErrNoFloROI           15
+#define xieErrNoFloSource        16
+#define xieErrNoFloTechnique     17
+#define xieErrNoFloValue         18
+#define xieErrNoFloImplementation 19
+
+#define xieNumFloErrors                  19
+
+#endif /* _XIE_H_ */
diff --git a/Xserver/include/extensions/XIEproto.h b/Xserver/include/extensions/XIEproto.h
new file mode 100644 (file)
index 0000000..b097319
--- /dev/null
@@ -0,0 +1,687 @@
+/* $XConsortium: XIEproto.h,v 1.6 94/04/17 20:11:12 mor Exp $ */
+/******************************************************************************
+Copyright (c) 1993, 1994  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be included
+in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR
+OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall
+not be used in advertising or otherwise to promote the sale, use or
+other dealings in this Software without prior written authorization
+from the X Consortium.
+
+
+                               NOTICE
+
+This software is being provided by AGE Logic, Inc. under the
+following license.  By obtaining, using and/or copying this software,
+you agree that you have read, understood, and will comply with these
+terms and conditions:
+
+     Permission to use, copy, modify, distribute and sell this
+     software and its documentation for any purpose and without
+     fee or royalty and to grant others any or all rights granted
+     herein is hereby granted, provided that you agree to comply
+     with the following copyright notice and statements, including
+     the disclaimer, and that the same appears on all copies and
+     derivative works of the software and documentation you make.
+     
+     "Copyright 1993, 1994 by AGE Logic, Inc."
+     
+     THIS SOFTWARE IS PROVIDED "AS IS".  AGE LOGIC MAKES NO
+     REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED.  By way of
+     example, but not limitation, AGE LOGIC MAKE NO
+     REPRESENTATIONS OR WARRANTIES OF MERCHANTABILITY OR FITNESS
+     FOR ANY PARTICULAR PURPOSE OR THAT THE SOFTWARE DOES NOT
+     INFRINGE THIRD-PARTY PROPRIETARY RIGHTS.  AGE LOGIC 
+     SHALL BEAR NO LIABILITY FOR ANY USE OF THIS SOFTWARE.  IN NO
+     EVENT SHALL EITHER PARTY BE LIABLE FOR ANY INDIRECT,
+     INCIDENTAL, SPECIAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOSS
+     OF PROFITS, REVENUE, DATA OR USE, INCURRED BY EITHER PARTY OR
+     ANY THIRD PARTY, WHETHER IN AN ACTION IN CONTRACT OR TORT OR
+     BASED ON A WARRANTY, EVEN IF AGE LOGIC LICENSEES
+     HEREUNDER HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH
+     DAMAGES.
+    
+     The name of AGE Logic, Inc. may not be used in
+     advertising or publicity pertaining to this software without
+     specific, written prior permission from AGE Logic.
+
+     Title to this software shall at all times remain with AGE
+     Logic, Inc.
+******************************************************************************/
+
+#ifndef _XIEPROTO_H_
+#define _XIEPROTO_H_
+
+#include <X11/extensions/XIEprotost.h>
+
+#define Drawable CARD32
+#define Colormap CARD32
+#define GContext CARD32
+
+
+typedef struct {        
+    CARD8       reqType;
+    CARD8       opcode;
+    CARD16      length B16;
+} xieReq;
+
+typedef struct {        
+    CARD8       reqType;
+    CARD8       opcode;
+    CARD16      length B16;
+    CARD16      majorVersion B16;
+    CARD16      minorVersion B16;
+} xieQueryImageExtensionReq;
+
+typedef struct {
+    CARD8               type;
+    CARD8               data;
+    CARD16              sequenceNum B16;
+    CARD32              length B32;
+    CARD16              majorVersion B16;
+    CARD16              minorVersion B16;
+    xieTypServiceClass  serviceClass;
+    xieTypAlignment     alignment;
+    CARD16             unconstrainedMantissa B16;
+    INT32              unconstrainedMaxExp B32;
+    INT32              unconstrainedMinExp B32;
+    CARD8              pad2[8];
+    /* LISTofCARD32 (constrained-levels) */
+} xieQueryImageExtensionReply;
+
+typedef struct {        
+    CARD8                       reqType;
+    CARD8                       opcode;
+    CARD16                      length B16;
+    xieTypTechniqueGroup        techniqueGroup;
+    CARD8                       pad[3];
+} xieQueryTechniquesReq;
+
+typedef struct {
+    CARD8       type;
+    CARD8       data;
+    CARD16      sequenceNum B16;
+    CARD32      length B32;
+    CARD16      numTechniques B16;
+    CARD8       pad[22];
+    /* LISTofTechniqueRec (numTechniques) */
+} xieQueryTechniquesReply;
+
+typedef struct {        
+    CARD8               reqType;
+    CARD8               opcode;
+    CARD16              length B16;
+    xieTypColorList     colorList B32;  
+} xieCreateColorListReq;
+
+typedef struct {        
+    CARD8               reqType;
+    CARD8               opcode;
+    CARD16              length B16;
+    xieTypColorList     colorList B32;  
+} xieDestroyColorListReq;
+
+typedef struct {        
+    CARD8               reqType;
+    CARD8               opcode;
+    CARD16              length B16;
+    xieTypColorList     colorList B32;  
+} xiePurgeColorListReq;
+
+typedef struct {        
+    CARD8               reqType;
+    CARD8               opcode;
+    CARD16              length B16;
+    xieTypColorList     colorList B32;  
+} xieQueryColorListReq;
+
+typedef struct {
+    CARD8       type;
+    CARD8       data;
+    CARD16      sequenceNum B16;
+    CARD32      length B32;
+    Colormap    colormap B32;
+    CARD8       pad[20];
+    /* LISTofCARD32 (length) */
+} xieQueryColorListReply;
+
+typedef struct {        
+    CARD8       reqType;
+    CARD8       opcode;
+    CARD16      length B16;
+    xieTypLUT   lut B32;
+} xieCreateLUTReq;
+
+typedef struct {        
+    CARD8       reqType;
+    CARD8       opcode;
+    CARD16      length B16;
+    xieTypLUT   lut B32;
+} xieDestroyLUTReq;
+
+typedef struct {        
+    CARD8               reqType;
+    CARD8               opcode;
+    CARD16              length B16;
+    xieTypPhotomap      photomap B32;
+} xieCreatePhotomapReq;
+
+typedef struct {        
+    CARD8               reqType;
+    CARD8               opcode;
+    CARD16              length B16;
+    xieTypPhotomap      photomap B32;
+} xieDestroyPhotomapReq;
+
+typedef struct {        
+    CARD8               reqType;
+    CARD8               opcode;
+    CARD16              length B16;
+    xieTypPhotomap      photomap B32;
+} xieQueryPhotomapReq;
+
+typedef struct {
+    CARD8                       type;
+    BOOL                        populated;
+    CARD16                      sequenceNum B16;
+    CARD32                      length B32;
+    xieTypDataClass             dataClass;
+    xieTypDataType             dataType;
+    xieTypDecodeTechnique       decodeTechnique B16;
+    CARD32                      width0 B32;
+    CARD32                      width1 B32;
+    CARD32                      width2 B32;
+    CARD32                      height0 B32;
+    CARD32                      height1 B32;
+    CARD32                      height2 B32;
+    CARD32                      levels0 B32;
+    CARD32                      levels1 B32;
+    CARD32                      levels2 B32;
+} xieQueryPhotomapReply;
+
+typedef struct {        
+    CARD8       reqType;
+    CARD8       opcode;
+    CARD16      length B16;
+    xieTypROI   roi B32;
+} xieCreateROIReq;
+
+typedef struct {        
+    CARD8       reqType;
+    CARD8       opcode;
+    CARD16      length B16;
+    xieTypROI   roi B32;
+} xieDestroyROIReq;
+
+typedef struct {
+    CARD8               reqType;
+    CARD8               opcode;
+    CARD16              length B16;
+    xieTypPhotospace    nameSpace B32;
+} xieCreatePhotospaceReq;
+
+typedef struct {
+    CARD8               reqType;
+    CARD8               opcode;
+    CARD16              length B16;
+    xieTypPhotospace    nameSpace B32;
+} xieDestroyPhotospaceReq;
+
+typedef struct {
+    CARD8              reqType;
+    CARD8              opcode;
+    CARD16             length B16;
+    xieTypPhotospace    nameSpace B32;
+    CARD32             floID B32;
+    CARD16             numElements B16;
+    BOOL               notify;
+    CARD8              pad;                    
+    /* LISTofPhotoElement (numElements) */
+} xieExecuteImmediateReq;
+typedef struct {
+    CARD8               reqType;
+    CARD8               opcode;
+    CARD16              length B16;
+    xieTypPhotoflo      floID B32;
+    CARD16              numElements B16;
+    CARD16              pad B16;                        
+    /* LISTofPhotoElement (numElements) */
+} xieCreatePhotofloReq;
+
+typedef struct {
+    CARD8               reqType;
+    CARD8               opcode;
+    CARD16              length B16;
+    xieTypPhotoflo      floID B32;
+} xieDestroyPhotofloReq;
+
+typedef struct {
+    CARD8               reqType;
+    CARD8               opcode;
+    CARD16              length B16;
+    xieTypPhotoflo      floID B32;
+    BOOL                notify;
+    CARD8               pad[3];                 
+} xieExecutePhotofloReq;
+
+typedef struct {
+    CARD8               reqType;
+    CARD8               opcode;
+    CARD16              length B16;
+    xieTypPhotoflo      floID B32;
+    xieTypPhototag      start B16;
+    CARD16              numElements B16;
+    /* LISTofPhotoElement (numElements) */
+} xieModifyPhotofloReq;
+
+typedef struct {
+    CARD8               reqType;
+    CARD8               opcode;
+    CARD16              length B16;
+    xieTypPhotoflo      floID B32;
+    CARD16              numElements B16;
+    CARD16              pad B16;
+    /* LISTofPhotoElement (numElements) */
+} xieRedefinePhotofloReq;
+
+typedef struct {
+    CARD8               reqType;
+    CARD8               opcode;
+    CARD16              length B16;
+    CARD32              nameSpace B32;
+    CARD32              floID B32;
+    xieTypPhototag      element B16;
+    BOOL                final;
+    CARD8               bandNumber;
+    CARD32              byteCount B32;
+    /* LISTofCARD8 (byteCount) */
+    /* pad (byteCount) */
+} xiePutClientDataReq;
+
+typedef struct {
+    CARD8               reqType;
+    CARD8               opcode;
+    CARD16              length B16;
+    CARD32              nameSpace B32;
+    CARD32              floID B32;
+    CARD32              maxBytes B32;
+    xieTypPhototag      element B16;
+    BOOL                terminate;
+    CARD8               bandNumber;
+} xieGetClientDataReq;
+
+typedef struct {
+    CARD8       type;
+    CARD8       newState;
+    CARD16      sequenceNum B16;
+    CARD32      length B32;
+    CARD32      byteCount B32;
+    CARD8       pad[20];
+    /* LISTofCARD8 (byteCount) */
+    /* pad (byteCount) */
+} xieGetClientDataReply;
+
+typedef struct {
+    CARD8       reqType;
+    CARD8       opcode;
+    CARD16      length B16;
+    CARD32      nameSpace B32;
+    CARD32      floID B32;
+} xieQueryPhotofloReq;
+
+typedef struct {
+    CARD8       type;
+    CARD8       state;
+    CARD16      sequenceNum B16;
+    CARD32      length B32;
+    CARD16      expectedCount B16;
+    CARD16      availableCount B16;
+    CARD8       pad[20];
+    /* LISTofPhototag (expectedCount) */
+    /* pad (expectedCount * 2) */
+    /* LISTofPhototag (availableCount) */
+    /* pad (availableCount * 2) */
+} xieQueryPhotofloReply;
+
+typedef struct {
+    CARD8       reqType;
+    CARD8       opcode;
+    CARD16      length B16;
+    CARD32      nameSpace B32;
+    CARD32      floID B32;
+} xieAwaitReq;
+
+typedef struct {
+    CARD8       reqType;
+    CARD8       opcode;
+    CARD16      length B16;
+    CARD32      nameSpace B32;
+    CARD32      floID B32;
+} xieAbortReq;
+
+
+/*
+ * Request codes
+ */
+
+#define X_ieQueryImageExtension                1
+#define X_ieQueryTechniques            2
+#define X_ieCreateColorList            3
+#define X_ieDestroyColorList           4
+#define X_iePurgeColorList             5
+#define X_ieQueryColorList             6
+#define X_ieCreateLUT                  7
+#define X_ieDestroyLUT                 8
+#define X_ieCreatePhotomap             9
+#define X_ieDestroyPhotomap            10
+#define X_ieQueryPhotomap              11
+#define X_ieCreateROI                  12
+#define X_ieDestroyROI                 13
+#define X_ieCreatePhotospace           14
+#define X_ieDestroyPhotospace          15
+#define X_ieExecuteImmediate           16
+#define X_ieCreatePhotoflo             17
+#define X_ieDestroyPhotoflo            18
+#define X_ieExecutePhotoflo            19
+#define X_ieModifyPhotoflo             20
+#define X_ieRedefinePhotoflo           21
+#define X_iePutClientData              22
+#define X_ieGetClientData              23
+#define X_ieQueryPhotoflo              24
+#define X_ieAwait                      25
+#define X_ieAbort                      26
+
+#define xieNumProtoReq                 26
+
+
+/*
+ * Events
+ */
+typedef struct {
+    CARD8                      event;
+    xieTypPhotofloOutcome      outcome;
+    CARD16                     sequenceNum B16;
+    CARD32                     time B32;
+    CARD32                     instanceNameSpace B32;
+    CARD32                     instanceFloID B32;
+    CARD8                      pad[16];
+} xiePhotofloDoneEvn;
+
+typedef struct {
+    CARD8                      event;
+    CARD8                      pad1;
+    CARD16                     sequenceNum B16;
+    CARD32                     time B32;
+    CARD32                     instanceNameSpace B32;
+    CARD32                     instanceFloID B32;
+    xieTypPhototag             src B16;
+    CARD16                     type B16;
+    CARD32                     pad2 B32;
+    CARD32                     pad3 B16;
+    CARD32                     pad4 B32;
+} xieFloEvn;
+
+typedef struct {
+    CARD8                      event;
+    CARD8                      pad1;
+    CARD16                     sequenceNum B16;
+    CARD32                     time B32;
+    CARD32                     instanceNameSpace B32;
+    CARD32                     instanceFloID B32;
+    xieTypPhototag             src B16;
+    CARD16                     type B16;
+    xieTypColorList            colorList B32;
+    xieTypColorAllocTechnique  colorAllocTechnique B16;
+    CARD16                     pad2 B16;
+    CARD32                     data B32;
+} xieColorAllocEvn;
+
+typedef struct {
+    CARD8                      event;
+    CARD8                      bandNumber;
+    CARD16                     sequenceNum B16;
+    CARD32                     time B32;
+    CARD32                     instanceNameSpace B32;
+    CARD32                     instanceFloID B32;
+    xieTypPhototag             src B16;
+    CARD16                     type B16;
+    xieTypDecodeTechnique      decodeTechnique B16;
+    BOOL                       aborted;
+    CARD8                      pad;
+    CARD32                     width B32;
+    CARD32                     height B32;
+} xieDecodeNotifyEvn;
+
+typedef struct {
+    CARD8              event;
+    CARD8              bandNumber;
+    CARD16             sequenceNum B16;
+    CARD32             time B32;
+    CARD32             instanceNameSpace B32;
+    CARD32             instanceFloID B32;
+    xieTypPhototag     src B16;
+    CARD16             type B16;
+    CARD32             data0 B32;
+    CARD32             data1 B32;
+    CARD32             data2 B32;
+} xieExportAvailableEvn;
+
+typedef struct {
+    CARD8              event;
+    CARD8              pad;
+    CARD16             sequenceNum B16;
+    CARD32             time B32;
+    CARD32             instanceNameSpace B32;
+    CARD32             instanceFloID B32;
+    xieTypPhototag     src B16;
+    CARD16             type B16;
+    Window             window B32;
+    INT16              x B16;
+    INT16              y B16;
+    CARD16             width B16;
+    CARD16             height B16;
+} xieImportObscuredEvn;
+
+
+/*
+ * Errors
+ */
+typedef struct {
+    CARD8            error;
+    CARD8             code;
+    CARD16            sequenceNum B16;
+    CARD32            resourceID B32;
+    CARD16           minorOpcode B16;
+    CARD8            majorOpcode;
+    CARD8             pad[21];
+} xieResourceErr;
+
+typedef struct {
+    CARD8             error;
+    CARD8             code;
+    CARD16            sequenceNum B16;
+    CARD32            floID B32;
+    CARD16           minorOpcode B16;
+    CARD8            majorOpcode;
+    CARD8             floErrorCode;
+    CARD32            nameSpace B32;
+    xieTypPhototag    phototag B16;
+    CARD16            type B16;
+    CARD32           resourceID B32;
+    CARD8             pad[8];
+} xieFloResourceErr;
+
+typedef struct {
+    CARD8             error;
+    CARD8             code;
+    CARD16            sequenceNum B16;
+    CARD32            floID B32;
+    CARD16           minorOpcode B16;
+    CARD8            majorOpcode;
+    CARD8             floErrorCode;
+    CARD32            nameSpace B32;
+    xieTypPhototag    phototag B16;
+    CARD16            type B16;
+    CARD8             pad[12];
+} xieFloErr, xieFloAccessErr, xieFloAllocErr, xieFloElementErr,
+  xieFloLengthErr, xieFloMatchErr, xieFloSourceErr, xieFloImplementationErr;
+
+typedef struct {
+    CARD8             error;
+    CARD8             code;
+    CARD16            sequenceNum B16;
+    CARD32            floID B32;
+    CARD16           minorOpcode B16;
+    CARD8            majorOpcode;
+    CARD8             floErrorCode;
+    CARD32            nameSpace B32;
+    xieTypPhototag    phototag B16;
+    CARD16            type B16;
+    xieTypPhototag    domainSrc B16;
+    CARD8             pad[10];
+} xieFloDomainErr;
+
+typedef struct {
+    CARD8             error;
+    CARD8             code;
+    CARD16            sequenceNum B16;
+    CARD32            floID B32;
+    CARD16           minorOpcode B16;
+    CARD8            majorOpcode;
+    CARD8             floErrorCode;
+    CARD32            nameSpace B32;
+    CARD8             pad[16];
+} xieFloIDErr;
+
+typedef struct {
+    CARD8             error;
+    CARD8             code;
+    CARD16            sequenceNum B16;
+    CARD32            floID B32;
+    CARD16           minorOpcode B16;
+    CARD8            majorOpcode;
+    CARD8             floErrorCode;
+    CARD32            nameSpace B32;
+    xieTypPhototag    phototag B16;
+    CARD16            type B16;
+    CARD8             operator;
+    CARD8             pad[11];
+} xieFloOperatorErr;
+
+typedef struct {
+    CARD8             error;
+    CARD8             code;
+    CARD16            sequenceNum B16;
+    CARD32            floID B32;
+    CARD16           minorOpcode B16;
+    CARD8            majorOpcode;
+    CARD8             floErrorCode;
+    CARD32            nameSpace B32;
+    xieTypPhototag    phototag B16;
+    CARD16            type B16;
+    CARD16            techniqueNumber B16;
+    CARD16            lenTechParams B16;
+    CARD8             techniqueGroup;
+    CARD8             pad[7];
+} xieFloTechniqueErr;
+
+typedef struct {
+    CARD8             error;
+    CARD8             code;
+    CARD16            sequenceNum B16;
+    CARD32            floID B32;
+    CARD16           minorOpcode B16;
+    CARD8            majorOpcode;
+    CARD8             floErrorCode;
+    CARD32            nameSpace B32;
+    xieTypPhototag    phototag B16;
+    CARD16            type B16;
+    CARD32            badValue B32;
+    CARD8             pad[8];
+} xieFloValueErr;
+
+
+
+/*
+ * SIZEOF values
+ */
+#define sz_xieReq                        4
+#define sz_xieQueryImageExtensionReq     8
+#define sz_xieQueryImageExtensionReply  32
+#define sz_xieQueryTechniquesReq         8
+#define sz_xieQueryTechniquesReply      32
+#define sz_xieCreateColorListReq         8
+#define sz_xieDestroyColorListReq        8
+#define sz_xiePurgeColorListReq          8
+#define sz_xieQueryColorListReq          8
+#define sz_xieQueryColorListReply       32
+#define sz_xieCreateLUTReq               8
+#define sz_xieDestroyLUTReq              8
+#define sz_xieCreatePhotomapReq          8
+#define sz_xieDestroyPhotomapReq         8
+#define sz_xieQueryPhotomapReq           8
+#define sz_xieQueryPhotomapReply        48
+#define sz_xieCreateROIReq               8
+#define sz_xieDestroyROIReq              8
+#define sz_xieCreatePhotospaceReq        8
+#define sz_xieDestroyPhotospaceReq       8
+#define sz_xieExecuteImmediateReq       16
+#define sz_xieCreatePhotofloReq         12
+#define sz_xieDestroyPhotofloReq         8
+#define sz_xieExecutePhotofloReq        12
+#define sz_xieModifyPhotofloReq         12
+#define sz_xieRedefinePhotofloReq       12
+#define sz_xiePutClientDataReq          20
+#define sz_xieGetClientDataReq          20
+#define sz_xieGetClientDataReply        32
+#define sz_xieQueryPhotofloReq          12
+#define sz_xieQueryPhotofloReply        32
+#define sz_xieAwaitReq                  12
+#define sz_xieAbortReq                  12
+
+#define sz_xiePhotofloDoneEvn          32
+#define sz_xieColorAllocEvn            32
+#define sz_xieDecodeNotifyEvn          32
+#define sz_xieExportAvailableEvn       32
+#define sz_xieImportObscuredEvn                32
+#define sz_xieFloEvn                   32
+
+#define sz_xieResourceErr              32
+#define sz_xieFloAccessErr             32
+#define sz_xieFloAllocErr              32
+#define sz_xieFloElementErr            32
+#define sz_xieFloIDErr                 32
+#define sz_xieFloLengthErr             32
+#define sz_xieFloMatchErr              32
+#define sz_xieFloSourceErr             32
+#define sz_xieFloDomainErr             32
+#define sz_xieFloOperatorErr           32
+#define sz_xieFloTechniqueErr          32
+#define sz_xieFloValueErr              32
+#define sz_xieFloImplementationErr     32
+#define sz_xieFloErr                   32
+
+#undef Drawable
+#undef Colormap
+#undef GContext
+
+#endif /* _XIEPROTO_H_ */
diff --git a/Xserver/include/extensions/XIEprotost.h b/Xserver/include/extensions/XIEprotost.h
new file mode 100644 (file)
index 0000000..2298afe
--- /dev/null
@@ -0,0 +1,1118 @@
+/* $XConsortium: XIEprotost.h,v 1.6 94/04/17 20:11:12 mor Exp $ */
+/******************************************************************************
+
+
+Copyright (c) 1993, 1994  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+
+                               NOTICE
+                              
+This software is being provided by AGE Logic, Inc. under the
+following license.  By obtaining, using and/or copying this software,
+you agree that you have read, understood, and will comply with these
+terms and conditions:
+
+     Permission to use, copy, modify, distribute and sell this
+     software and its documentation for any purpose and without
+     fee or royalty and to grant others any or all rights granted
+     herein is hereby granted, provided that you agree to comply
+     with the following copyright notice and statements, including
+     the disclaimer, and that the same appears on all copies and
+     derivative works of the software and documentation you make.
+     
+     "Copyright 1993, 1994 by AGE Logic, Inc."
+     
+     THIS SOFTWARE IS PROVIDED "AS IS".  AGE LOGIC MAKES NO
+     REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED.  By way of
+     example, but not limitation, AGE LOGIC MAKE NO
+     REPRESENTATIONS OR WARRANTIES OF MERCHANTABILITY OR FITNESS
+     FOR ANY PARTICULAR PURPOSE OR THAT THE SOFTWARE DOES NOT
+     INFRINGE THIRD-PARTY PROPRIETARY RIGHTS.  AGE LOGIC 
+     SHALL BEAR NO LIABILITY FOR ANY USE OF THIS SOFTWARE.  IN NO
+     EVENT SHALL EITHER PARTY BE LIABLE FOR ANY INDIRECT,
+     INCIDENTAL, SPECIAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOSS
+     OF PROFITS, REVENUE, DATA OR USE, INCURRED BY EITHER PARTY OR
+     ANY THIRD PARTY, WHETHER IN AN ACTION IN CONTRACT OR TORT OR
+     BASED ON A WARRANTY, EVEN IF AGE LOGIC LICENSEES
+     HEREUNDER HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH
+     DAMAGES.
+    
+     The name of AGE Logic, Inc. may not be used in
+     advertising or publicity pertaining to this software without
+     specific, written prior permission from AGE Logic.
+
+     Title to this software shall at all times remain with AGE
+     Logic, Inc.
+
+
+******************************************************************************/
+
+#ifndef _XIEPROTOST_H_
+#define _XIEPROTOST_H_
+
+#include <X11/Xmd.h>                   /* defines things like CARD32 */
+
+#define Drawable CARD32
+#define Colormap CARD32
+#define GContext CARD32
+
+typedef CARD32 xieTypFloat;
+
+#ifndef WORD64
+
+typedef xieTypFloat    xieTypConstant[3];
+
+typedef xieTypFloat    xieTypMatrix[9];
+
+#else /* WORD64 */
+
+typedef CARD8  xieTypConstant[12];
+
+typedef CARD8  xieTypMatrix[36];
+
+#endif /* WORD64 */
+
+
+typedef CARD8  xieTypAlignment;
+
+typedef CARD8  xieTypArithmeticOp;
+
+typedef CARD16  xieTypColorAllocTechnique;
+
+typedef        CARD32  xieTypColorList;
+
+typedef CARD8  xieTypCompareOp;
+
+typedef CARD16  xieTypConstrainTechnique;
+
+typedef CARD16  xieTypConvertFromRGBTechnique;
+
+typedef CARD16  xieTypConvertToRGBTechnique;
+
+typedef CARD16  xieTypConvolveTechnique;
+
+typedef CARD8  xieTypDataClass;
+
+typedef CARD8  xieTypDataType;
+
+typedef CARD16  xieTypDecodeTechnique;
+
+typedef CARD16  xieTypDitherTechnique;
+
+typedef CARD16  xieTypEncodeTechnique;
+
+typedef CARD32 xieTypPhotospace;
+
+typedef CARD32 xieTypPhotoflo;
+
+typedef struct {
+  union {
+    struct {
+      xieTypPhotospace nameSpace B32;
+      CARD32           floID B32;
+    } immed;
+    struct {
+      CARD32           nameSpace B32;
+      xieTypPhotoflo   floID B32;
+    } stored;
+  } u;
+} xieTypExecutable;
+
+typedef CARD8  xieTypExportNotify;
+
+typedef CARD8  xieTypExportState;
+
+typedef CARD16 xieTypGamutTechnique;
+
+typedef CARD16 xieTypGeometryTechnique;
+
+typedef struct {
+    CARD32     value B32;
+    CARD32     count B32;
+} xieTypHistogramData;
+
+typedef CARD16 xieTypHistogramShape;
+
+typedef CARD8  xieTypInterleave;
+
+typedef CARD32 xieTypLevels[3];
+
+typedef        CARD32  xieTypLUT;
+
+typedef CARD8  xieTypMathOp;
+
+typedef CARD8  xieTypOrientation;
+
+typedef CARD8  xieTypPhotofloOutcome;
+
+typedef CARD8  xieTypPhotofloState;
+
+typedef CARD32 xieTypPhotomap;
+
+typedef CARD16 xieTypPhototag;
+
+typedef struct {
+    INT32              offsetX B32;
+    INT32              offsetY B32;
+    xieTypPhototag     domain B16;             
+} xieTypProcessDomain;
+
+typedef struct {
+    INT32      x B32;
+    INT32      y B32;
+    CARD32     width B32;
+    CARD32     height B32;
+} xieTypRectangle;
+
+typedef CARD32 xieTypROI;
+
+typedef CARD8  xieTypServiceClass;
+
+typedef CARD8  xieTypTechniqueGroup;
+
+typedef struct {
+    BOOL                       needsParam;
+    xieTypTechniqueGroup       group;
+    CARD16                     number B16;
+    CARD8                      speed;
+    CARD8                      nameLength;
+    CARD16                     pad B16;
+    /* LISTofCARD8 (nameLength) */
+    /* pad (nameLength) */
+} xieTypTechniqueRec;
+
+typedef struct {
+    xieTypPhototag     src B16;
+    CARD16             pad B16;
+    INT32              dstX B32;
+    INT32              dstY B32;
+} xieTypTile;
+
+typedef CARD8  xieTypTripleofCARD8[3];
+
+typedef CARD16  xieTypTripleofCARD16[3];
+
+typedef CARD32 xieTypTripleofCARD32[3];
+
+typedef CARD16  xieTypWhiteAdjustTechnique;
+
+
+/*
+ * Generic Element
+ */
+
+typedef struct {
+    CARD16             elemType B16;
+    CARD16             elemLength B16;
+} xieFlo;
+
+/*
+ * Import Elements
+ */
+typedef struct {
+    CARD16             elemType B16;
+    CARD16             elemLength B16;
+    xieTypDataClass    class;
+    xieTypOrientation  bandOrder;
+    CARD16             pad B16;
+    CARD32             length0 B32;
+    CARD32             length1 B32;
+    CARD32             length2 B32;
+    CARD32             levels0 B32;
+    CARD32             levels1 B32;
+    CARD32             levels2 B32;
+} xieFloImportClientLUT;
+
+typedef struct {
+    CARD16                     elemType B16;
+    CARD16                     elemLength B16;
+    BOOL                       notify;
+    xieTypDataClass            class;
+    CARD16                     pad B16;
+    CARD32                     width0 B32;
+    CARD32                     width1 B32;
+    CARD32                     width2 B32;
+    CARD32                     height0 B32;
+    CARD32                     height1 B32;
+    CARD32                     height2 B32;
+    CARD32                     levels0 B32;
+    CARD32                     levels1 B32;
+    CARD32                     levels2 B32;
+    xieTypDecodeTechnique      decodeTechnique B16;
+    CARD16                     lenParams B16;
+    /* Technique dependent decode params */
+} xieFloImportClientPhoto;
+
+typedef struct {
+    CARD16     elemType B16;
+    CARD16     elemLength B16;
+    CARD32     rectangles B32;
+} xieFloImportClientROI;
+
+typedef struct {
+    CARD16     elemType B16;
+    CARD16     elemLength B16;
+    Drawable   drawable B32;
+    INT16      srcX B16;
+    INT16      srcY B16;
+    CARD16     width B16;
+    CARD16     height B16;
+    CARD32     fill B32;
+    BOOL       notify;
+    CARD8      pad[3];         
+} xieFloImportDrawable;
+
+typedef struct {
+    CARD16     elemType B16;
+    CARD16     elemLength B16;
+    Drawable   drawable B32;
+    INT16      srcX B16;
+    INT16      srcY B16;
+    CARD16     width B16;
+    CARD16     height B16;
+    CARD32     fill B32;
+    CARD32     bitPlane B32;
+    BOOL       notify;
+    CARD8      pad[3];         
+} xieFloImportDrawablePlane;
+
+typedef struct {
+    CARD16     elemType B16;
+    CARD16     elemLength B16;
+    xieTypLUT  lut B32;
+} xieFloImportLUT;
+typedef struct {
+    CARD16             elemType B16;
+    CARD16             elemLength B16;
+    xieTypPhotomap     photomap B32;
+    BOOL               notify;
+    CARD8              pad[3];
+} xieFloImportPhotomap;
+
+typedef struct {
+    CARD16     elemType B16;
+    CARD16     elemLength B16;
+    xieTypROI  roi B32;
+} xieFloImportROI;
+
+
+/*
+ * Process Elements
+ */
+typedef struct {
+    CARD16             elemType B16;
+    CARD16             elemLength B16;
+    xieTypPhototag     src1 B16;
+    xieTypPhototag     src2 B16;
+    INT32              domainOffsetX B32;
+    INT32              domainOffsetY B32;
+    xieTypPhototag     domainPhototag B16;             
+    xieTypArithmeticOp operator;
+    CARD8              bandMask;
+    xieTypFloat                constant0 B32;
+    xieTypFloat                constant1 B32;
+    xieTypFloat                constant2 B32;
+} xieFloArithmetic;
+
+typedef struct {
+    CARD16             elemType B16;
+    CARD16             elemLength B16;
+    xieTypPhototag     src1 B16;
+    xieTypPhototag     src2 B16;
+    xieTypPhototag     src3 B16;
+    CARD16             pad B16;
+} xieFloBandCombine;
+
+typedef struct {
+    CARD16             elemType B16;
+    CARD16             elemLength B16;
+    xieTypPhototag     src B16;
+    CARD16             pad B16;
+    CARD32             levels B32;
+    xieTypFloat                bias B32;
+    xieTypFloat                constant0 B32;
+    xieTypFloat                constant1 B32;
+    xieTypFloat                constant2 B32;
+} xieFloBandExtract;
+
+typedef struct {
+    CARD16             elemType B16;
+    CARD16             elemLength B16;
+    xieTypPhototag     src B16;
+    CARD8              bandNumber;
+    CARD8              pad;
+} xieFloBandSelect;
+
+typedef struct {
+    CARD16             elemType B16;
+    CARD16             elemLength B16;
+    xieTypPhototag     src1 B16;
+    xieTypPhototag     src2 B16;
+    xieTypPhototag     alpha B16;
+    CARD16             pad1 B16;
+    INT32              domainOffsetX B32;
+    INT32              domainOffsetY B32;
+    xieTypPhototag     domainPhototag B16;             
+    CARD8              bandMask;
+    CARD8              pad2;
+    xieTypFloat                constant0 B32;
+    xieTypFloat                constant1 B32;
+    xieTypFloat                constant2 B32;
+    xieTypFloat                alphaConst B32;
+} xieFloBlend;
+
+typedef struct {
+    CARD16             elemType B16;
+    CARD16             elemLength B16;
+    xieTypPhototag     src1 B16;
+    xieTypPhototag     src2 B16;
+    INT32              domainOffsetX B32;
+    INT32              domainOffsetY B32;
+    xieTypPhototag     domainPhototag B16;             
+    xieTypCompareOp    operator;
+    BOOL               combine;
+    xieTypFloat                constant0 B32;
+    xieTypFloat                constant1 B32;
+    xieTypFloat                constant2 B32;
+    CARD8              bandMask;
+    CARD8              pad[3];
+} xieFloCompare;
+
+typedef struct {
+    CARD16                     elemType B16;
+    CARD16                     elemLength B16;
+    xieTypPhototag             src B16;
+    CARD16                     pad B16;
+    CARD32                     levels0 B32;
+    CARD32                     levels1 B32;
+    CARD32                     levels2 B32;
+    xieTypConstrainTechnique   constrain B16;
+    CARD16                     lenParams B16;
+    /* Technique dependent constrain params */
+} xieFloConstrain;
+
+typedef struct {
+    CARD16             elemType B16;
+    CARD16             elemLength B16;
+    xieTypPhototag     src B16;
+    xieTypDataClass    class;
+    CARD8              precision;
+    Colormap           colormap B32;
+} xieFloConvertFromIndex;
+
+typedef struct {
+    CARD16                        elemType B16;
+    CARD16                        elemLength B16;
+    xieTypPhototag                src B16;
+    CARD16                        pad B16;
+    xieTypConvertFromRGBTechnique  convert B16;
+    CARD16                        lenParams B16;
+    /* Technique dependent conversion params */
+} xieFloConvertFromRGB;
+
+typedef struct {
+    CARD16                     elemType B16;
+    CARD16                     elemLength B16;
+    xieTypPhototag             src B16;
+    BOOL                       notify;
+    CARD8                      pad;
+    Colormap                   colormap B32;
+    xieTypColorList            colorList B32;
+    xieTypColorAllocTechnique  colorAlloc B16;
+    CARD16                     lenParams B16;
+    /* Technique dependent color alloc params */
+} xieFloConvertToIndex;
+
+typedef struct {
+    CARD16                     elemType B16;
+    CARD16                     elemLength B16;
+    xieTypPhototag             src B16;
+    CARD16                     pad B16;
+    xieTypConvertToRGBTechnique        convert B16;
+    CARD16                     lenParams B16;
+    /* Technique dependent conversion params */
+} xieFloConvertToRGB;
+
+typedef struct {
+    CARD16                     elemType B16;
+    CARD16                     elemLength B16;
+    xieTypPhototag             src B16;
+    CARD16                     pad B16;
+    INT32                      domainOffsetX B32;
+    INT32                      domainOffsetY B32;
+    xieTypPhototag             domainPhototag B16;             
+    CARD8                      bandMask;
+    CARD8                      kernelSize;
+    xieTypConvolveTechnique    convolve B16;
+    CARD16                     lenParams B16;
+    /* LISTofFloat (kernelSize^2) */
+    /* Technique dependent convolve params */
+} xieFloConvolve;
+
+typedef struct {
+    CARD16                     elemType B16;
+    CARD16                     elemLength B16;
+    xieTypPhototag             src B16;
+    CARD8                      bandMask;
+    CARD8                      pad;
+    CARD32                     levels0 B32;
+    CARD32                     levels1 B32;
+    CARD32                     levels2 B32;
+    xieTypDitherTechnique      dither B16;
+    CARD16                     lenParams B16;
+    /* Technique dependent dither params */
+} xieFloDither;
+
+typedef struct {
+    CARD16                     elemType B16;
+    CARD16                     elemLength B16;
+    xieTypPhototag             src B16;
+    CARD8                      bandMask;
+    CARD8                      pad;
+    CARD32                     width B32;
+    CARD32                     height B32;
+    xieTypFloat                        a B32;
+    xieTypFloat                        b B32;
+    xieTypFloat                        c B32;
+    xieTypFloat                        d B32;
+    xieTypFloat                        tx B32;
+    xieTypFloat                        ty B32;
+    xieTypFloat                        constant0 B32;
+    xieTypFloat                        constant1 B32;
+    xieTypFloat                        constant2 B32;
+    xieTypGeometryTechnique    sample B16;
+    CARD16                     lenParams B16;
+    /* Technique dependent sample params */
+} xieFloGeometry;
+
+typedef struct {
+    CARD16             elemType B16;
+    CARD16             elemLength B16;
+    xieTypPhototag     src1 B16;
+    xieTypPhototag     src2 B16;
+    INT32              domainOffsetX B32;
+    INT32              domainOffsetY B32;
+    xieTypPhototag     domainPhototag B16;             
+    CARD8              operator;
+    CARD8              bandMask;
+    xieTypFloat                constant0 B32;
+    xieTypFloat                constant1 B32;
+    xieTypFloat                constant2 B32;
+} xieFloLogical;
+
+typedef struct {
+    CARD16                     elemType B16;
+    CARD16                     elemLength B16;
+    xieTypPhototag             src B16;
+    CARD16                     pad1 B16;
+    INT32                      domainOffsetX B32;
+    INT32                      domainOffsetY B32;
+    xieTypPhototag             domainPhototag B16;             
+    CARD16                     pad2 B16;
+    xieTypHistogramShape       shape B16;
+    CARD16                     lenParams B16;
+    /* Technique dependent shape params */
+} xieFloMatchHistogram;
+
+typedef struct {
+    CARD16             elemType B16;
+    CARD16             elemLength B16;
+    xieTypPhototag     src B16;
+    CARD16             pad B16;
+    INT32              domainOffsetX B32;
+    INT32              domainOffsetY B32;
+    xieTypPhototag     domainPhototag B16;             
+    xieTypMathOp       operator;
+    CARD8              bandMask;
+} xieFloMath;
+
+typedef struct {
+    CARD16             elemType B16;
+    CARD16             elemLength B16;
+    CARD16             numTiles B16;
+    CARD16             pad B16;
+    CARD32             width B32;
+    CARD32             height B32;
+    xieTypFloat                constant0 B32;
+    xieTypFloat                constant1 B32;
+    xieTypFloat                constant2 B32;
+    /* LISTofTile (numTiles) */
+} xieFloPasteUp;
+
+typedef struct {
+    CARD16             elemType B16;
+    CARD16             elemLength B16;
+    xieTypPhototag     src B16;
+    xieTypPhototag     lut B16;
+    INT32              domainOffsetX B32;
+    INT32              domainOffsetY B32;
+    xieTypPhototag     domainPhototag B16;             
+    CARD8              bandMask;
+    CARD8              pad;
+} xieFloPoint;
+
+typedef struct {
+    CARD16                     elemType B16;
+    CARD16                     elemLength B16;
+    xieTypPhototag             src B16;
+    CARD16                     pad B16;
+} xieFloUnconstrain;
+
+
+/*
+ * Export Elements
+ */
+typedef struct {
+    CARD16             elemType B16;
+    CARD16             elemLength B16;
+    xieTypPhototag     src B16;
+    xieTypExportNotify notify;
+    CARD8              pad1;
+    INT32              domainOffsetX B32;
+    INT32              domainOffsetY B32;
+    xieTypPhototag     domainPhototag B16;             
+    CARD16             pad2 B16;
+} xieFloExportClientHistogram;
+
+typedef struct {
+    CARD16             elemType B16;
+    CARD16             elemLength B16;
+    xieTypPhototag     src B16;
+    xieTypExportNotify notify;
+    xieTypOrientation  bandOrder;
+    CARD32             start0  B32;
+    CARD32             start1  B32;
+    CARD32             start2  B32;
+    CARD32             length0 B32;
+    CARD32             length1 B32;
+    CARD32             length2 B32;
+} xieFloExportClientLUT;
+
+typedef struct {
+    CARD16                     elemType B16;
+    CARD16                     elemLength B16;
+    xieTypPhototag             src B16;
+    xieTypExportNotify         notify;
+    CARD8                      pad;
+    xieTypEncodeTechnique      encodeTechnique B16;
+    CARD16                     lenParams B16;
+    /* Technique dependent encode params */
+} xieFloExportClientPhoto;
+
+typedef struct {
+    CARD16             elemType B16;
+    CARD16             elemLength B16;
+    xieTypPhototag     src B16;
+    xieTypExportNotify notify;
+    CARD8              pad;
+} xieFloExportClientROI;
+
+typedef struct {
+    CARD16             elemType B16;
+    CARD16             elemLength B16;
+    xieTypPhototag     src B16;
+    INT16              dstX B16;
+    INT16              dstY B16;
+    CARD16             pad B16;
+    Drawable           drawable B32;
+    GContext           gc B32;
+} xieFloExportDrawable;
+
+typedef struct {
+    CARD16             elemType B16;
+    CARD16             elemLength B16;
+    xieTypPhototag     src B16;
+    INT16              dstX B16;
+    INT16              dstY B16;
+    CARD16             pad B16;
+    Drawable           drawable B32;
+    GContext           gc B32;
+} xieFloExportDrawablePlane;
+
+typedef struct {
+    CARD16             elemType B16;
+    CARD16             elemLength B16;
+    xieTypPhototag     src B16;
+    CARD8              merge;
+    CARD8              pad;
+    xieTypLUT          lut B32;
+    CARD32             start0 B32;
+    CARD32             start1 B32;
+    CARD32             start2 B32;
+} xieFloExportLUT;
+typedef struct {
+    CARD16                     elemType B16;
+    CARD16                     elemLength B16;
+    xieTypPhototag             src B16;
+    CARD16                     pad B16;
+    xieTypPhotomap             photomap B32;
+    xieTypEncodeTechnique      encodeTechnique B16;
+    CARD16                     lenParams B16;
+    /* Technique dependent encode params */
+} xieFloExportPhotomap;
+
+typedef struct {
+    CARD16             elemType B16;
+    CARD16             elemLength B16;
+    xieTypPhototag     src B16;
+    CARD16             pad B16;
+    xieTypROI          roi B32;
+} xieFloExportROI;
+
+
+/*
+ * Technique Parameters
+ */
+
+typedef struct {
+    xieTypFloat                inputLow0   B32;
+    xieTypFloat                inputLow1   B32;
+    xieTypFloat                inputLow2   B32;
+    xieTypFloat                inputHigh0  B32;
+    xieTypFloat                inputHigh1  B32;
+    xieTypFloat                inputHigh2  B32;
+    CARD32             outputLow0  B32;
+    CARD32             outputLow1  B32;
+    CARD32             outputLow2  B32;
+    CARD32             outputHigh0 B32;
+    CARD32             outputHigh1 B32;
+    CARD32             outputHigh2 B32;
+} xieTecClipScale;
+
+typedef struct {
+    CARD32             fill B32;
+} xieTecColorAllocAll;
+
+typedef struct {
+    xieTypFloat                matchLimit B32;
+    xieTypFloat                grayLimit B32;
+} xieTecColorAllocMatch;
+
+typedef struct {
+    CARD32             maxCells B32;
+} xieTecColorAllocRequantize;
+
+typedef struct {
+    xieTypFloat                        matrix00 B32;
+    xieTypFloat                        matrix01 B32;
+    xieTypFloat                        matrix02 B32;
+    xieTypFloat                        matrix10 B32;
+    xieTypFloat                        matrix11 B32;
+    xieTypFloat                        matrix12 B32;
+    xieTypFloat                        matrix20 B32;
+    xieTypFloat                        matrix21 B32;
+    xieTypFloat                        matrix22 B32;
+    xieTypWhiteAdjustTechnique whiteAdjusted B16;
+    CARD16                     lenParams B16;
+    /* Technique dependent white params */
+} xieTecRGBToCIELab, xieTecRGBToCIEXYZ;
+
+typedef struct {
+    CARD32             levels0 B32;
+    CARD32             levels1 B32;
+    CARD32             levels2 B32;
+    xieTypFloat                lumaRed B32;
+    xieTypFloat                lumaGreen B32;
+    xieTypFloat                lumaBlue B32;
+    xieTypFloat                bias0 B32;
+    xieTypFloat                bias1 B32;
+    xieTypFloat                bias2 B32;
+} xieTecRGBToYCbCr;
+
+typedef struct {
+    CARD32             levels0 B32;
+    CARD32             levels1 B32;
+    CARD32             levels2 B32;
+    xieTypFloat                lumaRed B32;
+    xieTypFloat                lumaGreen B32;
+    xieTypFloat                lumaBlue B32;
+    xieTypFloat                scale B32;
+} xieTecRGBToYCC;
+
+typedef struct {
+    xieTypFloat                        matrix00 B32;
+    xieTypFloat                        matrix01 B32;
+    xieTypFloat                        matrix02 B32;
+    xieTypFloat                        matrix10 B32;
+    xieTypFloat                        matrix11 B32;
+    xieTypFloat                        matrix12 B32;
+    xieTypFloat                        matrix20 B32;
+    xieTypFloat                        matrix21 B32;
+    xieTypFloat                        matrix22 B32;
+    xieTypWhiteAdjustTechnique whiteAdjusted B16;
+    CARD16                     lenWhiteParams B16;
+    xieTypGamutTechnique       gamutCompress B16;
+    CARD16                     lenGamutParams B16;
+    /* Technique dependent white params */
+    /* Technique dependent gamut params */
+} xieTecCIELabToRGB, xieTecCIEXYZToRGB;
+
+typedef struct {
+    CARD32                     levels0 B32;
+    CARD32                     levels1 B32;
+    CARD32                     levels2 B32;
+    xieTypFloat                        lumaRed B32;
+    xieTypFloat                        lumaGreen B32;
+    xieTypFloat                        lumaBlue B32;
+    xieTypFloat                        bias0 B32;
+    xieTypFloat                        bias1 B32;
+    xieTypFloat                        bias2 B32;
+    xieTypGamutTechnique       gamutCompress B16;
+    CARD16                     lenGamutParams B16;
+    /* Technique dependent gamut params */
+} xieTecYCbCrToRGB;
+
+typedef struct {
+    CARD32                     levels0 B32;
+    CARD32                     levels1 B32;
+    CARD32                     levels2 B32;
+    xieTypFloat                        lumaRed B32;
+    xieTypFloat                        lumaGreen B32;
+    xieTypFloat                        lumaBlue B32;
+    xieTypFloat                        scale B32;
+    xieTypGamutTechnique       gamutCompress B16;
+    CARD16                     lenGamutParams B16;
+    /* Technique dependent gamut params */
+} xieTecYCCToRGB;
+
+typedef struct {
+    xieTypFloat                constant0 B32;
+    xieTypFloat                constant1 B32;
+    xieTypFloat                constant2 B32;
+} xieTecConvolveConstant;
+
+typedef struct {
+    xieTypOrientation  fillOrder;
+    xieTypOrientation  pixelOrder;
+    CARD8              pixelStride;
+    CARD8              leftPad;
+    CARD8              scanlinePad;
+    CARD8              pad[3];
+} xieTecDecodeUncompressedSingle;
+
+typedef struct {
+    CARD8              leftPad[3];
+    xieTypOrientation  fillOrder;
+    CARD8              pixelStride[3];
+    xieTypOrientation  pixelOrder;
+    CARD8              scanlinePad[3];
+    xieTypOrientation  bandOrder;
+    xieTypInterleave   interleave;
+    CARD8              pad[3];
+} xieTecDecodeUncompressedTriple;
+
+typedef struct {
+    xieTypOrientation  encodedOrder;
+    BOOL               normal;
+    BOOL               radiometric;
+    CARD8              pad;
+} xieTecDecodeG31D, xieTecDecodeG32D, xieTecDecodeG42D,
+  xieTecDecodeTIFF2;
+
+typedef struct {
+    xieTypOrientation  encodedOrder;
+    BOOL               normal;
+    CARD16             pad B16;
+} xieTecDecodeTIFFPackBits;
+
+typedef struct {
+    xieTypInterleave   interleave;
+    xieTypOrientation  bandOrder;
+    BOOL               upSample;
+    CARD8              pad;
+} xieTecDecodeJPEGBaseline;
+
+typedef struct {
+    xieTypInterleave   interleave;
+    xieTypOrientation  bandOrder;
+    CARD16             pad B16;
+} xieTecDecodeJPEGLossless;
+
+typedef struct {
+    CARD8      thresholdOrder;
+    CARD8      pad[3];
+} xieTecDitherOrdered;
+
+typedef struct {
+    CARD8              preference;
+    CARD8              pad[3];
+} xieTecEncodeServerChoice;
+
+typedef struct {
+    xieTypOrientation  fillOrder;
+    xieTypOrientation  pixelOrder;
+    CARD8              pixelStride;
+    CARD8              scanlinePad;
+} xieTecEncodeUncompressedSingle;
+
+typedef struct {
+    CARD8              pixelStride[3];
+    xieTypOrientation  pixelOrder;
+    CARD8              scanlinePad[3];
+    xieTypOrientation  fillOrder;
+    xieTypOrientation  bandOrder;
+    xieTypInterleave   interleave;
+    CARD16             pad B16;
+} xieTecEncodeUncompressedTriple;
+
+typedef struct {
+    xieTypOrientation  encodedOrder;
+    BOOL               alignEol;
+    BOOL               radiometric;
+    CARD8              pad;
+} xieTecEncodeG31D;
+
+typedef struct {
+    xieTypOrientation  encodedOrder;
+    BOOL               alignEol;
+    BOOL               radiometric;
+    BOOL               uncompressed;
+    CARD32             kFactor B32;
+} xieTecEncodeG32D;
+
+typedef struct {
+    xieTypOrientation  encodedOrder;
+    BOOL               radiometric;
+    BOOL               uncompressed;
+    CARD8              pad;
+} xieTecEncodeG42D;
+
+typedef struct {
+    xieTypInterleave   interleave;
+    xieTypOrientation  bandOrder;
+    CARD8              horizontalSamples[3];
+    CARD8              verticalSamples[3];
+    CARD16             lenQtable  B16; /* multiple of 4 */
+    CARD16             lenACtable B16; /* multiple of 4 */
+    CARD16             lenDCtable B16; /* multiple of 4 */
+    CARD16             pad B16;
+    /* LISTofCARD8 (Qtable)  */
+    /* LISTofCARD8 (ACtable) */
+    /* LISTofCARD8 (DCtable) */
+} xieTecEncodeJPEGBaseline;
+
+typedef struct {
+    xieTypInterleave   interleave;
+    xieTypOrientation  bandOrder;
+    CARD16             lenTable B16;   /* multiple of 4 */
+    CARD8              predictor[3];
+    CARD8              pad;
+    /* LISTofCARD8 (table) */
+} xieTecEncodeJPEGLossless;
+
+typedef struct {
+    xieTypOrientation  encodedOrder;
+    BOOL               radiometric;
+    CARD16             pad B16;
+} xieTecEncodeTIFF2;
+
+typedef struct {
+    xieTypOrientation  encodedOrder;
+    CARD8              pad[3];
+} xieTecEncodeTIFFPackBits;
+
+typedef struct {
+    INT16      simple B16;
+    CARD16     pad B16;
+} xieTecGeomAntialiasByArea;
+
+typedef struct {
+    INT16      kernelSize B16;
+    CARD16     pad B16;
+} xieTecGeomAntialiasByLowpass;
+
+typedef struct {
+    CARD8      radius;
+    BOOL       simple;
+    CARD16     pad B16;
+    xieTypFloat        sigma B32;
+    xieTypFloat        normalize B32;
+} xieTecGeomGaussian;
+
+typedef struct {
+    CARD8      modify;
+    CARD8      pad[3];
+} xieTecGeomNearestNeighbor;
+
+typedef struct {
+    xieTypFloat                mean B32;
+    xieTypFloat                sigma B32;
+} xieTecHistogramGaussian;
+
+typedef struct {
+    BOOL               shapeFactor;
+    CARD8              pad[3];
+    xieTypFloat                constant B32;
+} xieTecHistogramHyperbolic;
+
+typedef struct {
+    xieTypFloat                whitePoint0 B32;
+    xieTypFloat                whitePoint1 B32;
+    xieTypFloat                whitePoint2 B32;
+} xieTecWhiteAdjustCIELabShift;
+
+
+/*
+ * SIZEOF values
+ */
+#define sz_xieTypAlignment                     1
+#define sz_xieTypArithmeticOp                  1
+#define sz_xieTypColorAllocTechnique           2
+#define sz_xieTypColorList                     4
+#define sz_xieTypCompareOp                     1
+#define sz_xieTypConstant                      12
+#define sz_xieTypConstrainTechnique            2
+#define sz_xieTypConvertFromRGBTechnique       2
+#define sz_xieTypConvertToRGBTechnique         2
+#define sz_xieTypConvolveTechnique             2
+#define sz_xieTypDataClass                     1
+#define sz_xieTypDataType                      1
+#define sz_xieTypDecodeTechnique               2
+#define sz_xieTypDitherTechnique               2
+#define sz_xieTypEncodeTechnique               2
+#define sz_xieTypPhotospace                    4
+#define sz_xieTypPhotoflo                      4
+#define sz_xieTypExecutable                    8
+#define sz_xieTypExportNotify                  1
+#define sz_xieTypExportState                   1
+#define sz_xieTypFloat                         4
+#define sz_xieTypGamutTechnique                        2
+#define sz_xieTypGeometryTechnique             2
+#define sz_xieTypHistogramData                 8
+#define sz_xieTypHistogramShape                        2
+#define sz_xieTypInterleave                    1
+#define sz_xieTypLevels                                12
+#define sz_xieTypLUT                           4
+#define sz_xieTypMathOp                                1
+#define sz_xieTypMatrix                                36
+#define sz_xieTypOrientation                   1
+#define sz_xieTypPhotofloOutcome               1
+#define sz_xieTypPhotofloState                 1
+#define sz_xieTypPhotomap                      4
+#define sz_xieTypPhototag                      2
+#define sz_xieTypProcessDomain                 12
+#define sz_xieTypRectangle                     16
+#define sz_xieTypROI                           4
+#define sz_xieTypServiceClass                  1
+#define sz_xieTypTechniqueGroup                        1
+#define sz_xieTypTechniqueRec                  8
+#define sz_xieTypTile                          12
+#define sz_xieTypTripleofCARD8                 3
+#define sz_xieTypTripleofCARD16                        6
+#define sz_xieTypTripleofCARD32                        12
+#define sz_xieTypWhiteAdjustTechnique          2
+#define sz_xieFloImportClientLUT               32
+#define sz_xieFloImportClientPhoto             48
+#define sz_xieFloImportClientROI               8
+#define sz_xieFloImportDrawable                        24
+#define sz_xieFloImportDrawablePlane           28
+#define sz_xieFloImportLUT                     8
+#define sz_xieFloImportPhotomap                        12
+#define sz_xieFloImportROI                     8
+#define sz_xieFloArithmetic                    32
+#define sz_xieFloBandCombine                   12
+#define sz_xieFloBandExtract                   28
+#define sz_xieFloBandSelect                    8
+#define sz_xieFloBlend                         40
+#define sz_xieFloCompare                       36
+#define sz_xieFloConstrain                     24
+#define sz_xieFloConvertFromIndex              12
+#define sz_xieFloConvertFromRGB                        12
+#define sz_xieFloConvertToIndex                        20
+#define sz_xieFloConvertToRGB                  12
+#define sz_xieFloConvolve                      24
+#define sz_xieFloDither                                24
+#define sz_xieFloGeometry                      56
+#define sz_xieFloLogical                       32
+#define sz_xieFloMatchHistogram                        24
+#define sz_xieFloMath                          20
+#define sz_xieFloPasteUp                       28
+#define sz_xieFloPoint                         20
+#define sz_xieFloUnconstrain                   8
+#define sz_xieFloExportClientHistogram         20
+#define sz_xieFloExportClientLUT               32
+#define sz_xieFloExportClientPhoto             12
+#define sz_xieFloExportClientROI               8
+#define sz_xieFloExportDrawable                        20
+#define sz_xieFloExportDrawablePlane           20
+#define sz_xieFloExportLUT                     24
+#define sz_xieFloExportPhotomap                        16
+#define sz_xieFloExportROI                     12
+#define sz_xieTecColorAllocAll                 4
+#define sz_xieTecColorAllocMatch               8
+#define sz_xieTecColorAllocRequantize          4
+#define sz_xieTecClipScale                     48
+#define sz_xieTecHardClip                      0
+#define sz_xieTecRGBToCIELab                   40
+#define sz_xieTecRGBToCIEXYZ                   40
+#define sz_xieTecRGBToYCbCr                    36
+#define sz_xieTecRGBToYCC                      28
+#define sz_xieTecYCbCrToRGB                    40
+#define sz_xieTecYCCToRGB                      32
+#define sz_xieTecCIELabToRGB                   44
+#define sz_xieTecCIEXYZToRGB                   44
+#define sz_xieTecConvolveConstant              12
+#define sz_xieTecConvolveReplicate             0
+#define sz_xieTecDecodeUncompressedSingle      8
+#define sz_xieTecDecodeUncompressedTriple      16
+#define sz_xieTecDecodeG31D                    4
+#define sz_xieTecDecodeG32D                    4
+#define sz_xieTecDecodeG42D                    4
+#define sz_xieTecDecodeTIFF2                   4
+#define sz_xieTecDecodeTIFFPackBits            4
+#define sz_xieTecDecodeJPEGBaseline            4
+#define sz_xieTecDecodeJPEGLossless            4
+#define sz_xieTecDitherOrdered                 4
+#define sz_xieTecDitherErrorDiffusion          4
+#define sz_xieTecEncodeServerChoice            4
+#define sz_xieTecEncodeUncompressedSingle      4
+#define sz_xieTecEncodeUncompressedTriple      12
+#define sz_xieTecEncodeG31D                    4
+#define sz_xieTecEncodeG32D                    8
+#define sz_xieTecEncodeG42D                    4
+#define sz_xieTecEncodeJPEGBaseline            16
+#define sz_xieTecEncodeJPEGLossless            8
+#define sz_xieTecEncodeTIFF2                   4
+#define sz_xieTecEncodeTIFFPackBits            4
+#define sz_xieTecGamutNone                     0
+#define sz_xieTecGamutClipRGB                  0
+#define sz_xieTecGeomAntialias                 0
+#define sz_xieTecGeomAntialiasByArea           4
+#define sz_xieTecGeomAntialiasByLowpass                4
+#define sz_xieTecGeomBilinearInterpolation     0
+#define sz_xieTecGeomGaussian                  12
+#define sz_xieTecGeomNearestNeighbor           4
+#define sz_xieTecHistogramFlat                 0
+#define sz_xieTecHistogramGaussian             8
+#define sz_xieTecHistogramHyperbolic           8
+#define sz_xieTecWhiteAdjustNone               0
+#define sz_xieTecWhiteAdjustCIELabShift                12
+
+#undef Drawable
+#undef Colormap
+#undef GContext
+
+#endif /* _XIEPROTOST_H_ */
diff --git a/Xserver/include/extensions/XInput.h b/Xserver/include/extensions/XInput.h
new file mode 100644 (file)
index 0000000..a57fe18
--- /dev/null
@@ -0,0 +1,1210 @@
+/* $XConsortium: XInput.h,v 1.22 94/04/17 20:11:13 rws Exp $ */
+
+/************************************************************
+
+Copyright (c) 1989  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+Copyright (c) 1989 by Hewlett-Packard Company, Palo Alto, California.
+
+                       All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and its
+documentation for any purpose and without fee is hereby granted,
+provided that the above copyright notice appear in all copies and that
+both that copyright notice and this permission notice appear in
+supporting documentation, and that the name of Hewlett-Packard not be
+used in advertising or publicity pertaining to distribution of the
+software without specific, written prior permission.
+
+HEWLETT-PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
+ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
+HEWLETT-PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
+ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+SOFTWARE.
+
+********************************************************/
+
+/* Definitions used by the library and client */
+
+#ifndef _XINPUT_H_
+#define _XINPUT_H_
+
+#ifndef _XLIB_H_
+#include <X11/Xlib.h>
+#endif
+
+#ifndef _XI_H_
+#include "XI.h"
+#endif
+
+#define _deviceKeyPress                0
+#define _deviceKeyRelease      1
+
+#define _deviceButtonPress     0
+#define _deviceButtonRelease   1
+
+#define _deviceMotionNotify    0
+
+#define _deviceFocusIn         0
+#define _deviceFocusOut                1
+
+#define _proximityIn           0
+#define _proximityOut          1
+
+#define _deviceStateNotify     0
+#define _deviceMappingNotify   1
+#define _changeDeviceNotify    2
+
+#define FindTypeAndClass(d,type,_class,classid,offset) \
+    { int _i; XInputClassInfo *_ip; \
+    type = 0; _class = 0; \
+    for (_i=0, _ip= ((XDevice *) d)->classes; \
+        _i< ((XDevice *) d)->num_classes; \
+        _i++, _ip++) \
+       if (_ip->input_class == classid) \
+           {type =  _ip->event_type_base + offset; \
+            _class =  ((XDevice *) d)->device_id << 8 | type;}}
+
+#define DeviceKeyPress(d,type,_class) \
+    FindTypeAndClass(d, type, _class, KeyClass, _deviceKeyPress)
+
+#define DeviceKeyRelease(d,type,_class) \
+    FindTypeAndClass(d, type, _class, KeyClass, _deviceKeyRelease)
+
+#define DeviceButtonPress(d,type,_class) \
+    FindTypeAndClass(d, type, _class, ButtonClass, _deviceButtonPress)
+
+#define DeviceButtonRelease(d,type,_class) \
+    FindTypeAndClass(d, type, _class, ButtonClass, _deviceButtonRelease)
+
+#define DeviceMotionNotify(d,type,_class) \
+    FindTypeAndClass(d, type, _class, ValuatorClass, _deviceMotionNotify)
+
+#define DeviceFocusIn(d,type,_class) \
+    FindTypeAndClass(d, type, _class, FocusClass, _deviceFocusIn)
+
+#define DeviceFocusOut(d,type,_class) \
+    FindTypeAndClass(d, type, _class, FocusClass, _deviceFocusOut)
+
+#define ProximityIn(d,type,_class) \
+    FindTypeAndClass(d, type, _class, ProximityClass, _proximityIn)
+
+#define ProximityOut(d,type,_class) \
+    FindTypeAndClass(d, type, _class, ProximityClass, _proximityOut)
+
+#define DeviceStateNotify(d,type,_class) \
+    FindTypeAndClass(d, type, _class, OtherClass, _deviceStateNotify)
+
+#define DeviceMappingNotify(d,type,_class) \
+    FindTypeAndClass(d, type, _class, OtherClass, _deviceMappingNotify)
+
+#define ChangeDeviceNotify(d,type,_class) \
+    FindTypeAndClass(d, type, _class, OtherClass, _changeDeviceNotify)
+
+#define DevicePointerMotionHint(d,type,_class) \
+    { _class =  ((XDevice *) d)->device_id << 8 | _devicePointerMotionHint;}
+
+#define DeviceButton1Motion(d,type,_class) \
+    { _class =  ((XDevice *) d)->device_id << 8 | _deviceButton1Motion;}
+
+#define DeviceButton2Motion(d,type,_class) \
+    { _class =  ((XDevice *) d)->device_id << 8 | _deviceButton2Motion;}
+
+#define DeviceButton3Motion(d,type,_class) \
+    { _class =  ((XDevice *) d)->device_id << 8 | _deviceButton3Motion;}
+
+#define DeviceButton4Motion(d,type, _class) \
+    { _class =  ((XDevice *) d)->device_id << 8 | _deviceButton4Motion;}
+
+#define DeviceButton5Motion(d,type,_class) \
+    { _class =  ((XDevice *) d)->device_id << 8 | _deviceButton5Motion;}
+
+#define DeviceButtonMotion(d,type, _class) \
+    { _class =  ((XDevice *) d)->device_id << 8 | _deviceButtonMotion;}
+
+#define DeviceOwnerGrabButton(d,type,_class) \
+    { _class =  ((XDevice *) d)->device_id << 8 | _deviceOwnerGrabButton;}
+
+#define DeviceButtonPressGrab(d,type,_class) \
+    { _class =  ((XDevice *) d)->device_id << 8 | _deviceButtonGrab;}
+
+#define NoExtensionEvent(d,type,_class) \
+    { _class =  ((XDevice *) d)->device_id << 8 | _noExtensionEvent;}
+
+#define BadDevice(dpy,error) _xibaddevice(dpy, &error)
+
+#define BadClass(dpy,error) _xibadclass(dpy, &error)
+
+#define BadEvent(dpy,error) _xibadevent(dpy, &error)
+
+#define BadMode(dpy,error) _xibadmode(dpy, &error)
+
+#define DeviceBusy(dpy,error) _xidevicebusy(dpy, &error)
+
+/***************************************************************
+ *
+ * DeviceKey events.  These events are sent by input devices that
+ * support input class Keys.
+ * The location of the X pointer is reported in the coordinate
+ * fields of the x,y and x_root,y_root fields.
+ *
+ */
+
+typedef struct 
+    {
+    int            type;         /* of event */
+    unsigned long  serial;       /* # of last request processed */
+    Bool           send_event;   /* true if from SendEvent request */
+    Display        *display;     /* Display the event was read from */
+    Window         window;       /* "event" window reported relative to */
+    XID            deviceid;
+    Window         root;         /* root window event occured on */
+    Window         subwindow;    /* child window */
+    Time           time;         /* milliseconds */
+    int            x, y;         /* x, y coordinates in event window */
+    int            x_root;       /* coordinates relative to root */
+    int            y_root;       /* coordinates relative to root */
+    unsigned int   state;        /* key or button mask */
+    unsigned int   keycode;      /* detail */
+    Bool           same_screen;  /* same screen flag */
+    unsigned int   device_state; /* device key or button mask */
+    unsigned char  axes_count;
+    unsigned char  first_axis;
+    int            axis_data[6];
+    } XDeviceKeyEvent;
+
+typedef XDeviceKeyEvent XDeviceKeyPressedEvent;
+typedef XDeviceKeyEvent XDeviceKeyReleasedEvent;
+
+/*******************************************************************
+ *
+ * DeviceButton events.  These events are sent by extension devices
+ * that support input class Buttons.
+ *
+ */
+
+typedef struct {
+    int           type;         /* of event */
+    unsigned long serial;       /* # of last request processed by server */
+    Bool          send_event;   /* true if from a SendEvent request */
+    Display       *display;     /* Display the event was read from */
+    Window        window;       /* "event" window reported relative to */
+    XID           deviceid;
+    Window        root;         /* root window that the event occured on */
+    Window        subwindow;    /* child window */
+    Time          time;         /* milliseconds */
+    int           x, y;         /* x, y coordinates in event window */
+    int           x_root;       /* coordinates relative to root */
+    int           y_root;       /* coordinates relative to root */
+    unsigned int  state;        /* key or button mask */
+    unsigned int  button;       /* detail */
+    Bool          same_screen;  /* same screen flag */
+    unsigned int  device_state; /* device key or button mask */
+    unsigned char axes_count;
+    unsigned char first_axis;
+    int           axis_data[6];
+    } XDeviceButtonEvent;
+
+typedef XDeviceButtonEvent XDeviceButtonPressedEvent;
+typedef XDeviceButtonEvent XDeviceButtonReleasedEvent;
+
+/*******************************************************************
+ *
+ * DeviceMotionNotify event.  These events are sent by extension devices
+ * that support input class Valuators.
+ *
+ */
+
+typedef struct 
+    {
+    int           type;        /* of event */
+    unsigned long serial;      /* # of last request processed by server */
+    Bool          send_event;  /* true if from a SendEvent request */
+    Display       *display;    /* Display the event was read from */
+    Window        window;      /* "event" window reported relative to */
+    XID           deviceid;
+    Window        root;        /* root window that the event occured on */
+    Window        subwindow;   /* child window */
+    Time          time;        /* milliseconds */
+    int           x, y;        /* x, y coordinates in event window */
+    int           x_root;      /* coordinates relative to root */
+    int           y_root;      /* coordinates relative to root */
+    unsigned int  state;       /* key or button mask */
+    char          is_hint;     /* detail */
+    Bool          same_screen; /* same screen flag */
+    unsigned int  device_state; /* device key or button mask */
+    unsigned char axes_count;
+    unsigned char first_axis;
+    int           axis_data[6];
+    } XDeviceMotionEvent;
+
+/*******************************************************************
+ *
+ * DeviceFocusChange events.  These events are sent when the focus
+ * of an extension device that can be focused is changed.
+ *
+ */
+
+typedef struct 
+    {
+    int           type;       /* of event */
+    unsigned long serial;     /* # of last request processed by server */
+    Bool          send_event; /* true if from a SendEvent request */
+    Display       *display;   /* Display the event was read from */
+    Window        window;     /* "event" window reported relative to */
+    XID           deviceid;
+    int           mode;       /* NotifyNormal, NotifyGrab, NotifyUngrab */
+    int           detail;
+       /*
+        * NotifyAncestor, NotifyVirtual, NotifyInferior, 
+        * NotifyNonLinear,NotifyNonLinearVirtual, NotifyPointer,
+        * NotifyPointerRoot, NotifyDetailNone 
+        */
+    Time                time;
+    } XDeviceFocusChangeEvent;
+
+typedef XDeviceFocusChangeEvent XDeviceFocusInEvent;
+typedef XDeviceFocusChangeEvent XDeviceFocusOutEvent;
+
+/*******************************************************************
+ *
+ * ProximityNotify events.  These events are sent by those absolute
+ * positioning devices that are capable of generating proximity information.
+ *
+ */
+
+typedef struct 
+    {
+    int             type;      /* ProximityIn or ProximityOut */        
+    unsigned long   serial;    /* # of last request processed by server */
+    Bool            send_event; /* true if this came from a SendEvent request */
+    Display         *display;  /* Display the event was read from */
+    Window          window;      
+    XID                    deviceid;
+    Window          root;            
+    Window          subwindow;      
+    Time            time;            
+    int             x, y;            
+    int             x_root, y_root;  
+    unsigned int    state;           
+    Bool            same_screen;     
+    unsigned int    device_state; /* device key or button mask */
+    unsigned char   axes_count;
+    unsigned char   first_axis;
+    int             axis_data[6];
+    } XProximityNotifyEvent;
+typedef XProximityNotifyEvent XProximityInEvent;
+typedef XProximityNotifyEvent XProximityOutEvent;
+
+/*******************************************************************
+ *
+ * DeviceStateNotify events are generated on EnterWindow and FocusIn 
+ * for those clients who have selected DeviceState.
+ *
+ */
+
+typedef struct
+    {
+#if defined(__cplusplus) || defined(c_plusplus)
+    unsigned char      c_class;
+#else
+    unsigned char      class;
+#endif
+    unsigned char      length;
+    } XInputClass;
+
+typedef struct {
+    int           type;
+    unsigned long serial;       /* # of last request processed by server */
+    Bool          send_event;   /* true if this came from a SendEvent request */
+    Display       *display;     /* Display the event was read from */
+    Window        window;
+    XID           deviceid;
+    Time          time;
+    int           num_classes;
+    char         data[64];
+} XDeviceStateNotifyEvent;     
+
+typedef struct {
+#if defined(__cplusplus) || defined(c_plusplus)
+    unsigned char      c_class;
+#else
+    unsigned char      class;
+#endif
+    unsigned char      length;
+    unsigned char      num_valuators;
+    unsigned char      mode;
+    int                        valuators[6];
+} XValuatorStatus;
+
+typedef struct {
+#if defined(__cplusplus) || defined(c_plusplus)
+    unsigned char      c_class;
+#else
+    unsigned char      class;
+#endif
+    unsigned char      length;
+    short              num_keys;
+    char               keys[32];
+} XKeyStatus;
+
+typedef struct {
+#if defined(__cplusplus) || defined(c_plusplus)
+    unsigned char      c_class;
+#else
+    unsigned char      class;
+#endif
+    unsigned char      length;
+    short              num_buttons;
+    char               buttons[32];
+} XButtonStatus;
+
+/*******************************************************************
+ *
+ * DeviceMappingNotify event.  This event is sent when the key mapping,
+ * modifier mapping, or button mapping of an extension device is changed.
+ *
+ */
+
+typedef struct {
+    int           type;
+    unsigned long serial;       /* # of last request processed by server */
+    Bool          send_event;   /* true if this came from a SendEvent request */
+    Display       *display;     /* Display the event was read from */
+    Window        window;       /* unused */
+    XID           deviceid;
+    Time          time;
+    int           request;      /* one of MappingModifier, MappingKeyboard,
+                                    MappingPointer */
+    int           first_keycode;/* first keycode */
+    int           count;        /* defines range of change w. first_keycode*/
+} XDeviceMappingEvent;
+
+/*******************************************************************
+ *
+ * ChangeDeviceNotify event.  This event is sent when an 
+ * XChangeKeyboard or XChangePointer request is made.
+ *
+ */
+
+typedef struct {
+    int           type;
+    unsigned long serial;       /* # of last request processed by server */
+    Bool          send_event;   /* true if this came from a SendEvent request */
+    Display       *display;     /* Display the event was read from */
+    Window        window;       /* unused */
+    XID           deviceid;
+    Time          time;
+    int           request;      /* NewPointer or NewKeyboard */
+} XChangeDeviceNotifyEvent;
+
+/*******************************************************************
+ *
+ * Control structures for input devices that support input class
+ * Feedback.  These are used by the XGetFeedbackControl and 
+ * XChangeFeedbackControl functions.
+ *
+ */
+
+typedef struct {
+#if defined(__cplusplus) || defined(c_plusplus)
+     XID            c_class;
+#else
+     XID            class;
+#endif
+     int            length;
+     XID            id;
+} XFeedbackState;
+
+typedef struct {
+#if defined(__cplusplus) || defined(c_plusplus)
+    XID     c_class;
+#else
+    XID     class;
+#endif
+    int     length;
+    XID     id;
+    int     click;
+    int     percent;
+    int     pitch;
+    int     duration;
+    int     led_mask;
+    int     global_auto_repeat;
+    char    auto_repeats[32];
+} XKbdFeedbackState;
+
+typedef struct {
+#if defined(__cplusplus) || defined(c_plusplus)
+    XID     c_class;
+#else
+    XID     class;
+#endif
+    int     length;
+    XID     id;
+    int     accelNum;
+    int     accelDenom;
+    int     threshold;
+} XPtrFeedbackState;
+
+typedef struct {
+#if defined(__cplusplus) || defined(c_plusplus)
+    XID     c_class;
+#else
+    XID     class;
+#endif
+    int     length;
+    XID     id;
+    int     resolution;
+    int     minVal;
+    int     maxVal;
+} XIntegerFeedbackState;
+
+typedef struct {
+#if defined(__cplusplus) || defined(c_plusplus)
+    XID     c_class;
+#else
+    XID     class;
+#endif
+    int     length;
+    XID     id;
+    int     max_symbols;
+    int     num_syms_supported;
+    KeySym  *syms_supported;
+} XStringFeedbackState;
+
+typedef struct {
+#if defined(__cplusplus) || defined(c_plusplus)
+    XID     c_class;
+#else
+    XID     class;
+#endif
+    int     length;
+    XID     id;
+    int     percent;
+    int     pitch;
+    int     duration;
+} XBellFeedbackState;
+
+typedef struct {
+#if defined(__cplusplus) || defined(c_plusplus)
+    XID     c_class;
+#else
+    XID     class;
+#endif
+    int     length;
+    XID     id;
+    int     led_values;
+    int     led_mask;
+} XLedFeedbackState;
+
+typedef struct {
+#if defined(__cplusplus) || defined(c_plusplus)
+     XID            c_class;
+#else
+     XID            class;
+#endif
+     int            length;
+     XID           id;
+} XFeedbackControl;
+
+typedef struct {
+#if defined(__cplusplus) || defined(c_plusplus)
+    XID     c_class;
+#else
+    XID     class;
+#endif
+    int     length;
+    XID     id;
+    int     accelNum;
+    int     accelDenom;
+    int     threshold;
+} XPtrFeedbackControl;
+
+typedef struct {
+#if defined(__cplusplus) || defined(c_plusplus)
+    XID     c_class;
+#else
+    XID     class;
+#endif
+    int     length;
+    XID     id;
+    int     click;
+    int     percent;
+    int     pitch;
+    int     duration;
+    int     led_mask;
+    int     led_value;
+    int     key;
+    int     auto_repeat_mode;
+} XKbdFeedbackControl;
+
+typedef struct {
+#if defined(__cplusplus) || defined(c_plusplus)
+    XID     c_class;
+#else
+    XID     class;
+#endif
+    int     length;
+    XID     id;
+    int     num_keysyms;
+    KeySym  *syms_to_display;
+} XStringFeedbackControl;
+
+typedef struct {
+#if defined(__cplusplus) || defined(c_plusplus)
+    XID     c_class;
+#else
+    XID     class;
+#endif
+    int     length;
+    XID     id;
+    int     int_to_display;
+} XIntegerFeedbackControl;
+
+typedef struct {
+#if defined(__cplusplus) || defined(c_plusplus)
+    XID     c_class;
+#else
+    XID     class;
+#endif
+    int     length;
+    XID     id;
+    int     percent;
+    int     pitch;
+    int     duration;
+} XBellFeedbackControl;
+
+typedef struct {
+#if defined(__cplusplus) || defined(c_plusplus)
+    XID     c_class;
+#else
+    XID     class;
+#endif
+    int     length;
+    XID     id;
+    int     led_mask;
+    int     led_values;
+} XLedFeedbackControl;
+
+/*******************************************************************
+ *
+ * Device control structures.
+ *
+ */
+
+typedef struct {
+     XID            control;
+     int            length;
+} XDeviceControl;
+
+typedef struct {
+     XID            control;
+     int            length;
+     int            first_valuator;
+     int            num_valuators;
+     int            *resolutions;
+} XDeviceResolutionControl;
+
+typedef struct {
+     XID            control;
+     int            length;
+     int            num_valuators;
+     int            *resolutions;
+     int            *min_resolutions;
+     int            *max_resolutions;
+} XDeviceResolutionState;
+
+/*******************************************************************
+ *
+ * An array of XDeviceList structures is returned by the 
+ * XListInputDevices function.  Each entry contains information
+ * about one input device.  Among that information is an array of 
+ * pointers to structures that describe the characteristics of 
+ * the input device.
+ *
+ */
+
+typedef struct _XAnyClassinfo *XAnyClassPtr;
+
+typedef struct _XAnyClassinfo {
+#if defined(__cplusplus) || defined(c_plusplus)
+    XID        c_class;
+#else
+    XID        class;
+#endif
+    int        length;
+    } XAnyClassInfo;
+
+typedef struct _XDeviceInfo *XDeviceInfoPtr;
+
+typedef struct _XDeviceInfo
+    {
+    XID                 id;        
+    Atom                type;
+    char                *name;
+    int                 num_classes;
+    int                 use;
+    XAnyClassPtr       inputclassinfo;
+    } XDeviceInfo;
+
+typedef struct _XKeyInfo *XKeyInfoPtr;
+
+typedef struct _XKeyInfo
+    {
+#if defined(__cplusplus) || defined(c_plusplus)
+    XID                        c_class;
+#else
+    XID                        class;
+#endif
+    int                        length;
+    unsigned short      min_keycode;
+    unsigned short      max_keycode;
+    unsigned short      num_keys;
+    } XKeyInfo;
+
+typedef struct _XButtonInfo *XButtonInfoPtr;
+
+typedef struct _XButtonInfo {
+#if defined(__cplusplus) || defined(c_plusplus)
+    XID                c_class;
+#else
+    XID                class;
+#endif
+    int                length;
+    short      num_buttons;
+    } XButtonInfo;
+
+typedef struct _XAxisInfo *XAxisInfoPtr;
+
+typedef struct _XAxisInfo {
+    int        resolution;
+    int        min_value;
+    int        max_value;
+    } XAxisInfo;
+
+typedef struct _XValuatorInfo *XValuatorInfoPtr;
+
+typedef struct _XValuatorInfo
+    {
+#if defined(__cplusplus) || defined(c_plusplus)
+    XID                        c_class;
+#else
+    XID                        class;
+#endif
+    int                        length;
+    unsigned char       num_axes;
+    unsigned char       mode;
+    unsigned long       motion_buffer;
+    XAxisInfoPtr        axes;
+    } XValuatorInfo;
+
+
+/*******************************************************************
+ *
+ * An XDevice structure is returned by the XOpenDevice function.  
+ * It contains an array of pointers to XInputClassInfo structures.
+ * Each contains information about a class of input supported by the
+ * device, including a pointer to an array of data for each type of event
+ * the device reports.
+ *
+ */
+
+
+typedef struct {
+        unsigned char   input_class;
+        unsigned char   event_type_base;
+} XInputClassInfo;
+
+typedef struct {
+        XID                    device_id;
+        int                    num_classes;
+        XInputClassInfo        *classes;
+} XDevice;
+
+
+/*******************************************************************
+ *
+ * The following structure is used to return information for the 
+ * XGetSelectedExtensionEvents function.
+ *
+ */
+
+typedef struct {
+        XEventClass     event_type;
+        XID             device;
+} XEventList;
+
+/*******************************************************************
+ *
+ * The following structure is used to return motion history data from 
+ * an input device that supports the input class Valuators.
+ * This information is returned by the XGetDeviceMotionEvents function.
+ *
+ */
+
+typedef struct {
+        Time   time;
+        int    *data;
+} XDeviceTimeCoord;
+
+
+/*******************************************************************
+ *
+ * Device state structure.
+ * This is returned by the XQueryDeviceState request.
+ *
+ */
+
+typedef struct {
+        XID            device_id;
+        int            num_classes;
+        XInputClass    *data;
+} XDeviceState;
+
+/*******************************************************************
+ *
+ * Note that the mode field is a bitfield that reports the Proximity
+ * status of the device as well as the mode.  The mode field should
+ * be OR'd with the mask DeviceMode and compared with the values
+ * Absolute and Relative to determine the mode, and should be OR'd
+ * with the mask ProximityState and compared with the values InProximity
+ * and OutOfProximity to determine the proximity state.
+ *
+ */
+
+typedef struct {
+#if defined(__cplusplus) || defined(c_plusplus)
+    unsigned char      c_class;
+#else
+    unsigned char      class;
+#endif
+    unsigned char      length;
+    unsigned char      num_valuators;
+    unsigned char      mode;
+    int                        *valuators;
+} XValuatorState;
+
+typedef struct {
+#if defined(__cplusplus) || defined(c_plusplus)
+    unsigned char      c_class;
+#else
+    unsigned char      class;
+#endif
+    unsigned char      length;
+    short              num_keys;
+    char               keys[32];
+} XKeyState;
+
+typedef struct {
+#if defined(__cplusplus) || defined(c_plusplus)
+    unsigned char      c_class;
+#else
+    unsigned char      class;
+#endif
+    unsigned char      length;
+    short              num_buttons;
+    char               buttons[32];
+} XButtonState;
+
+/*******************************************************************
+ *
+ * Function definitions.
+ *
+ */
+
+_XFUNCPROTOBEGIN
+
+extern int     XChangeKeyboardDevice(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    XDevice*           /* device */
+#endif
+);
+
+extern int     XChangePointerDevice(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    XDevice*           /* device */,
+    int                        /* xaxis */,
+    int                        /* yaxis */
+#endif
+);
+
+extern int     XGrabDevice(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    XDevice*           /* device */,
+    Window             /* grab_window */,
+    Bool               /* ownerEvents */,
+    int                        /* event count */,
+    XEventClass*       /* event_list */,
+    int                        /* this_device_mode */,
+    int                        /* other_devices_mode */,
+    Time               /* time */
+#endif
+);
+
+extern int     XUngrabDevice(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    XDevice*           /* device */,
+    Time               /* time */
+#endif
+);
+
+extern int     XGrabDeviceKey(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    XDevice*           /* device */,
+    unsigned int       /* key */,
+    unsigned int       /* modifiers */,
+    XDevice*           /* modifier_device */,
+    Window             /* grab_window */,
+    Bool               /* owner_events */,
+    unsigned int       /* event_count */,
+    XEventClass*       /* event_list */,
+    int                        /* this_device_mode */,
+    int                        /* other_devices_mode */
+#endif
+);
+
+extern int     XUngrabDeviceKey(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    XDevice*           /* device */,
+    unsigned int       /* key */,
+    unsigned int       /* modifiers */,
+    XDevice*           /* modifier_dev */,
+    Window             /* grab_window */
+#endif
+);
+
+extern int     XGrabDeviceButton(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    XDevice*           /* device */,
+    unsigned int       /* button */,
+    unsigned int       /* modifiers */,
+    XDevice*           /* modifier_device */,
+    Window             /* grab_window */,
+    Bool               /* owner_events */,
+    unsigned int       /* event_count */,
+    XEventClass*       /* event_list */,
+    int                        /* this_device_mode */,
+    int                        /* other_devices_mode */
+#endif
+);
+
+extern int     XUngrabDeviceButton(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    XDevice*           /* device */,
+    unsigned int       /* button */,
+    unsigned int       /* modifiers */,
+    XDevice*           /* modifier_dev */,
+    Window             /* grab_window */
+#endif
+);
+
+extern int     XAllowDeviceEvents(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    XDevice*           /* device */,
+    int                        /* event_mode */,
+    Time               /* time */
+#endif
+);
+
+extern int     XGetDeviceFocus(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    XDevice*           /* device */,
+    Window*            /* focus */,
+    int*               /* revert_to */,
+    Time*              /* time */
+#endif
+);
+
+extern int     XSetDeviceFocus(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    XDevice*           /* device */,
+    Window             /* focus */,
+    int                        /* revert_to */,
+    Time               /* time */
+#endif
+);
+
+extern XFeedbackState  *XGetFeedbackControl(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    XDevice*           /* device */,
+    int*               /* num_feedbacks */
+#endif
+);
+
+extern int     XFreeFeedbackList(
+#if NeedFunctionPrototypes
+    XFeedbackState*    /* list */
+#endif
+);
+
+extern int     XChangeFeedbackControl(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    XDevice*           /* device */,
+    unsigned long      /* mask */,
+    XFeedbackControl*  /* f */
+#endif
+);
+
+extern int     XDeviceBell(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    XDevice*           /* device */,
+    XID                        /* feedbackclass */,
+    XID                        /* feedbackid */,
+    int                        /* percent */
+#endif
+);
+
+extern KeySym  *XGetDeviceKeyMapping(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    XDevice*           /* device */,
+#if NeedWidePrototypes
+    unsigned int       /* first */,
+#else
+    KeyCode            /* first */,
+#endif
+    int                        /* keycount */,
+    int*               /* syms_per_code */
+#endif
+);
+
+extern int     XChangeDeviceKeyMapping(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    XDevice*           /* device */,
+    int                        /* first */,
+    int                        /* syms_per_code */,
+    KeySym*            /* keysyms */,
+    int                        /* count */
+#endif
+);
+
+extern XModifierKeymap *XGetDeviceModifierMapping(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    XDevice*           /* device */
+#endif
+);
+
+extern int     XSetDeviceModifierMapping(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    XDevice*           /* device */,
+    XModifierKeymap*   /* modmap */
+#endif
+);
+
+extern int     XSetDeviceButtonMapping(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    XDevice*           /* device */,
+    unsigned char*     /* map[] */,
+    int                        /* nmap */
+#endif
+);
+
+extern int     XGetDeviceButtonMapping(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    XDevice*           /* device */,
+    unsigned char*     /* map[] */,
+    unsigned int       /* nmap */
+#endif
+);
+
+extern XDeviceState    *XQueryDeviceState(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    XDevice*           /* device */
+#endif
+);
+
+extern int     XFreeDeviceState(
+#if NeedFunctionPrototypes
+    XDeviceState*      /* list */
+#endif
+);
+
+extern XExtensionVersion       *XGetExtensionVersion(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    _Xconst char*      /* name */
+#endif
+);
+
+extern XDeviceInfo     *XListInputDevices(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    int*               /* ndevices */
+#endif
+);
+
+extern int     XFreeDeviceList(
+#if NeedFunctionPrototypes
+    XDeviceInfo*       /* list */
+#endif
+);
+
+extern XDevice *XOpenDevice(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    XID                        /* id */
+#endif
+);
+
+extern int     XCloseDevice(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    XDevice*           /* device */
+#endif
+);
+
+extern int     XSetDeviceMode(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    XDevice*           /* device */,
+    int                        /* mode */
+#endif
+);
+
+extern int     XSetDeviceValuators(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    XDevice*           /* device */,
+    int*               /* valuators */,
+    int                        /* first_valuator */,
+    int                        /* num_valuators */
+#endif
+);
+
+extern XDeviceControl  *XGetDeviceControl(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    XDevice*           /* device */,
+    int                        /* control */
+#endif
+);
+
+extern int     XChangeDeviceControl(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    XDevice*           /* device */,
+    int                        /* control */,
+    XDeviceControl*    /* d */
+#endif
+);
+
+extern int     XSelectExtensionEvent(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    Window             /* w */,
+    XEventClass*       /* event_list */,
+    int                        /* count */
+#endif
+);
+
+extern int XGetSelectedExtensionEvents(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    Window             /* w */,
+    int*               /* this_client_count */,
+    XEventClass**      /* this_client_list */,
+    int*               /* all_clients_count */,
+    XEventClass**      /* all_clients_list */
+#endif
+);
+
+extern int     XChangeDeviceDontPropagateList(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    Window             /* window */,
+    int                        /* count */,
+    XEventClass*       /* events */,
+    int                        /* mode */
+#endif
+);
+
+extern XEventClass     *XGetDeviceDontPropagateList(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    Window             /* window */,
+    int*               /* count */
+#endif
+);
+
+extern Status  XSendExtensionEvent(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    XDevice*           /* device */,
+    Window             /* dest */,
+    Bool               /* prop */,
+    int                        /* count */,
+    XEventClass*       /* list */,
+    XEvent*            /* event */
+#endif
+);
+
+extern XDeviceTimeCoord        *XGetDeviceMotionEvents(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    XDevice*           /* device */,
+    Time               /* start */,
+    Time               /* stop */,
+    int*               /* nEvents */,
+    int*               /* mode */,
+    int*               /* axis_count */
+#endif
+);
+
+extern int     XFreeDeviceMotionEvents(
+#if NeedFunctionPrototypes
+    XDeviceTimeCoord*  /* events */
+#endif
+);
+
+extern int     XFreeDeviceControl(
+#if NeedFunctionPrototypes
+    XDeviceControl*    /* control */
+#endif
+);
+
+_XFUNCPROTOEND
+
+#endif /* _XINPUT_H_ */
diff --git a/Xserver/include/extensions/XIproto.h b/Xserver/include/extensions/XIproto.h
new file mode 100644 (file)
index 0000000..31adf53
--- /dev/null
@@ -0,0 +1,1426 @@
+/* $XConsortium: XIproto.h /main/26 1996/03/20 15:30:59 mor $ */
+
+/************************************************************
+
+Copyright (c) 1989  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+Copyright (c) 1989 by Hewlett-Packard Company, Palo Alto, California.
+
+                       All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and its
+documentation for any purpose and without fee is hereby granted,
+provided that the above copyright notice appear in all copies and that
+both that copyright notice and this permission notice appear in
+supporting documentation, and that the name of Hewlett-Packard not be
+used in advertising or publicity pertaining to distribution of the
+software without specific, written prior permission.
+
+HEWLETT-PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
+ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
+HEWLETT-PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
+ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+SOFTWARE.
+
+********************************************************/
+
+#ifndef _XIPROTO_H
+#define _XIPROTO_H
+
+#include <X11/Xproto.h>
+#include <X11/X.h>
+
+/* make sure types have right sizes for protocol structures. */
+#define Window CARD32
+#define Time CARD32
+#define KeyCode CARD8
+
+/*********************************************************
+ *
+ * number of events, errors, and extension name.
+ *
+ */
+
+#define MORE_EVENTS    0x80
+#define DEVICE_BITS    0x7F
+
+#define InputClassBits 0x3F    /* bits in mode field for input classes */
+#define ModeBitsShift  6       /* amount to shift the remaining bits   */
+
+#define numInputClasses 7
+
+#define IEVENTS                15
+#define IERRORS                5
+
+#define CLIENT_REQ             1
+
+typedef struct  _XExtEventInfo
+    {
+    Mask       mask;
+    BYTE       type;
+    BYTE       word;
+    } XExtEventInfo;
+
+typedef unsigned char *Pointer;
+
+struct tmask
+    {
+    Mask       mask;
+    Pointer     dev;
+    };
+
+/*********************************************************
+ *
+ * Event constants used by library.
+ *
+ */
+
+#define XI_DeviceValuator              0
+#define XI_DeviceKeyPress              1
+#define XI_DeviceKeyRelease            2
+#define XI_DeviceButtonPress           3
+#define XI_DeviceButtonRelease         4
+#define XI_DeviceMotionNotify          5
+#define XI_DeviceFocusIn               6
+#define XI_DeviceFocusOut              7
+#define XI_ProximityIn                 8
+#define XI_ProximityOut                        9
+#define XI_DeviceStateNotify           10
+#define XI_DeviceMappingNotify         11
+#define XI_ChangeDeviceNotify          12
+#define XI_DeviceKeystateNotify                13
+#define XI_DeviceButtonstateNotify     14
+
+/*********************************************************
+ *
+ * Protocol request constants
+ *
+ */
+
+#define X_GetExtensionVersion          1
+#define X_ListInputDevices             2
+#define X_OpenDevice                   3
+#define X_CloseDevice                  4
+#define X_SetDeviceMode                        5
+#define X_SelectExtensionEvent         6
+#define X_GetSelectedExtensionEvents   7
+#define X_ChangeDeviceDontPropagateList 8
+#define X_GetDeviceDontPropagateList   9
+#define X_GetDeviceMotionEvents        10
+#define X_ChangeKeyboardDevice         11
+#define X_ChangePointerDevice          12
+#define X_GrabDevice                   13
+#define X_UngrabDevice                 14
+#define X_GrabDeviceKey                        15
+#define X_UngrabDeviceKey              16
+#define X_GrabDeviceButton             17
+#define X_UngrabDeviceButton           18
+#define X_AllowDeviceEvents            19
+#define X_GetDeviceFocus               20
+#define X_SetDeviceFocus               21
+#define X_GetFeedbackControl           22
+#define X_ChangeFeedbackControl                23
+#define X_GetDeviceKeyMapping          24
+#define X_ChangeDeviceKeyMapping       25
+#define X_GetDeviceModifierMapping     26
+#define X_SetDeviceModifierMapping     27
+#define X_GetDeviceButtonMapping       28
+#define X_SetDeviceButtonMapping       29
+#define X_QueryDeviceState             30
+#define X_SendExtensionEvent           31
+#define X_DeviceBell                   32
+#define X_SetDeviceValuators           33
+#define X_GetDeviceControl             34
+#define X_ChangeDeviceControl          35
+
+/*********************************************************
+ *
+ * Protocol request and reply structures.
+ *
+ * GetExtensionVersion.
+ *
+ */
+
+typedef struct {
+    CARD8      reqType;       /* input extension major code   */
+    CARD8      ReqType;       /* always X_GetExtensionVersion */
+    CARD16     length B16;
+    CARD16     nbytes B16;
+    CARD8      pad1, pad2;
+} xGetExtensionVersionReq;
+
+typedef struct {
+    CARD8      repType;        /* X_Reply                      */
+    CARD8      RepType;        /* always X_GetExtensionVersion */
+    CARD16     sequenceNumber B16;
+    CARD32     length B32;
+    CARD16     major_version B16;
+    CARD16     minor_version B16;
+    BOOL       present;
+    CARD8      pad1, pad2, pad3;
+    CARD32     pad01 B32;
+    CARD32     pad02 B32;
+    CARD32     pad03 B32;
+    CARD32     pad04 B32;
+} xGetExtensionVersionReply;
+
+/*********************************************************
+ *
+ * ListInputDevices.
+ *
+ */
+
+typedef struct {
+    CARD8      reqType;        /* input extension major code   */
+    CARD8      ReqType;        /* always X_ListInputDevices    */
+    CARD16     length B16;
+} xListInputDevicesReq;
+
+typedef struct {
+    CARD8      repType;        /* X_Reply                      */
+    CARD8      RepType;        /* always X_ListInputDevices    */
+    CARD16     sequenceNumber B16;
+    CARD32     length B32;
+    CARD8      ndevices;
+    CARD8      pad1, pad2, pad3;
+    CARD32     pad01 B32;
+    CARD32     pad02 B32;
+    CARD32     pad03 B32;
+    CARD32     pad04 B32;
+    CARD32     pad05 B32;
+} xListInputDevicesReply;
+
+typedef struct _xDeviceInfo *xDeviceInfoPtr;
+
+typedef struct _xAnyClassinfo *xAnyClassPtr;
+
+typedef struct _xAnyClassinfo {
+    CARD8      class;
+    CARD8      length;
+    } xAnyClassInfo;
+
+typedef struct _xDeviceInfo {
+    CARD32     type B32;
+    CARD8      id;
+    CARD8      num_classes;
+    CARD8      use;
+    CARD8      pad1;
+    } xDeviceInfo;
+
+typedef struct _xKeyInfo *xKeyInfoPtr;
+
+typedef struct _xKeyInfo {
+    CARD8      class;
+    CARD8      length;
+    KeyCode    min_keycode; 
+    KeyCode    max_keycode; 
+    CARD16     num_keys B16;
+    CARD8      pad1,pad2;
+    } xKeyInfo;
+
+typedef struct _xButtonInfo *xButtonInfoPtr;
+
+typedef struct _xButtonInfo {
+    CARD8      class;
+    CARD8      length;
+    CARD16     num_buttons B16;
+    } xButtonInfo;
+
+typedef struct _xValuatorInfo *xValuatorInfoPtr;
+
+typedef struct _xValuatorInfo {
+    CARD8      class;
+    CARD8      length;
+    CARD8      num_axes;
+    CARD8      mode;
+    CARD32     motion_buffer_size B32;
+    } xValuatorInfo;
+
+typedef struct _xAxisInfo *xAxisInfoPtr;
+
+typedef struct _xAxisInfo {
+    CARD32     resolution B32;
+    CARD32     min_value B32;
+    CARD32     max_value B32;
+    } xAxisInfo;
+
+/*********************************************************
+ *
+ * OpenDevice.
+ *
+ */
+
+typedef struct {
+    CARD8      reqType;        /* input extension major code   */
+    CARD8      ReqType;        /* always X_OpenDevice          */
+    CARD16     length B16;
+    CARD8       deviceid;
+    BYTE       pad1, pad2, pad3;
+} xOpenDeviceReq;
+
+typedef struct {
+    CARD8      repType;        /* X_Reply                      */
+    CARD8      RepType;        /* always X_OpenDevice          */
+    CARD16     sequenceNumber B16;
+    CARD32     length B32;
+    CARD8      num_classes;
+    BYTE       pad1, pad2, pad3;
+    CARD32     pad00 B32;
+    CARD32     pad01 B32;
+    CARD32     pad02 B32;
+    CARD32     pad03 B32;
+    CARD32     pad04 B32;
+    } xOpenDeviceReply;
+
+typedef struct {
+    CARD8      class;
+    CARD8      event_type_base;
+    } xInputClassInfo;
+
+/*********************************************************
+ *
+ * CloseDevice.
+ *
+ */
+
+typedef struct {
+    CARD8      reqType;        /* input extension major code   */
+    CARD8      ReqType;        /* always X_CloseDevice         */
+    CARD16     length B16;
+    CARD8       deviceid;
+    BYTE       pad1, pad2, pad3;
+} xCloseDeviceReq;
+
+/*********************************************************
+ *
+ * SetDeviceMode.
+ *
+ */
+
+typedef struct {
+    CARD8      reqType;        /* input extension major code   */
+    CARD8      ReqType;        /* always X_SetDeviceMode       */
+    CARD16     length B16;
+    CARD8       deviceid;
+    CARD8       mode;
+    BYTE       pad1, pad2;
+} xSetDeviceModeReq;
+
+typedef struct {
+    CARD8      repType;        /* X_Reply                      */
+    CARD8      RepType;        /* always X_SetDeviceMode       */
+    CARD16     sequenceNumber B16;
+    CARD32     length B32;
+    CARD8      status;
+    BYTE       pad1, pad2, pad3;
+    CARD32     pad01 B32;
+    CARD32     pad02 B32;
+    CARD32     pad03 B32;
+    CARD32     pad04 B32;
+    CARD32     pad05 B32;
+} xSetDeviceModeReply;
+
+/*********************************************************
+ *
+ * SelectExtensionEvent.
+ *
+ */
+
+typedef struct {
+    CARD8      reqType;        /* input extension major code   */
+    CARD8      ReqType;        /* always X_SelectExtensionEvent */
+    CARD16     length B16;
+    Window     window B32;
+    CARD16     count B16;
+    CARD16     pad00 B16;
+} xSelectExtensionEventReq;
+
+/*********************************************************
+ *
+ * GetSelectedExtensionEvent.
+ *
+ */
+
+typedef struct {
+    CARD8      reqType;        /* input extension major code   */
+    CARD8      ReqType;        /* X_GetSelectedExtensionEvents */
+    CARD16     length B16;
+    Window     window B32;
+} xGetSelectedExtensionEventsReq;
+
+typedef struct {
+    CARD8      repType;        /* X_Reply                      */
+    CARD8      RepType;        /* GetSelectedExtensionEvents   */
+    CARD16     sequenceNumber B16;
+    CARD32     length B32;
+    CARD16     this_client_count B16;
+    CARD16     all_clients_count B16;
+    CARD32     pad01 B32;
+    CARD32     pad02 B32;
+    CARD32     pad03 B32;
+    CARD32     pad04 B32;
+    CARD32     pad05 B32;
+} xGetSelectedExtensionEventsReply;
+
+/*********************************************************
+ *
+ * ChangeDeviceDontPropagateList.
+ *
+ */
+
+typedef struct {
+    CARD8      reqType;        /* input extension major code   */
+    CARD8      ReqType;        /* X_ChangeDeviceDontPropagateList */
+    CARD16     length B16;
+    Window     window B32;
+    CARD16     count B16;
+    CARD8      mode;
+    BYTE       pad;
+} xChangeDeviceDontPropagateListReq;
+
+/*********************************************************
+ *
+ * GetDeviceDontPropagateList.
+ *
+ */
+
+typedef struct {
+    CARD8      reqType;        /* input extension major code   */
+    CARD8      ReqType;        /* X_GetDeviceDontPropagateList */
+    CARD16     length B16;
+    Window     window B32;
+} xGetDeviceDontPropagateListReq;
+
+typedef struct {
+    CARD8      repType;        /* X_Reply                      */
+    CARD8      RepType;        /* GetDeviceDontPropagateList   */
+    CARD16     sequenceNumber B16;
+    CARD32     length B32;
+    CARD16     count B16;
+    CARD16     pad00 B16;
+    CARD32     pad01 B32;
+    CARD32     pad02 B32;
+    CARD32     pad03 B32;
+    CARD32     pad04 B32;
+    CARD32     pad05 B32;
+    } xGetDeviceDontPropagateListReply;
+
+/*********************************************************
+ *
+ * GetDeviceMotionEvents.
+ *
+ */
+
+typedef struct {
+    CARD8      reqType;        /* input extension major code   */
+    CARD8      ReqType;        /* always X_GetDeviceMotionEvents*/
+    CARD16     length B16;
+    Time       start B32;
+    Time       stop B32;
+    CARD8      deviceid;
+    BYTE       pad1, pad2, pad3;
+} xGetDeviceMotionEventsReq;
+
+typedef struct {
+    CARD8      repType;        /* X_Reply */
+    CARD8      RepType;        /* always X_GetDeviceMotionEvents  */
+    CARD16     sequenceNumber B16;
+    CARD32     length B32;
+    CARD32     nEvents B32;
+    CARD8      axes;
+    CARD8      mode;
+    BYTE       pad1, pad2;
+    CARD32     pad01 B32;
+    CARD32     pad02 B32;
+    CARD32     pad03 B32;
+    CARD32     pad04 B32;
+} xGetDeviceMotionEventsReply;
+
+/*********************************************************
+ *
+ * ChangeKeyboardDevice.
+ *
+ */
+
+typedef struct {
+    CARD8      reqType;        /* input extension major code   */
+    CARD8      ReqType;        /* X_ChangeKeyboardDevice       */
+    CARD16     length B16;
+    CARD8      deviceid;
+    BYTE       pad1, pad2, pad3;
+} xChangeKeyboardDeviceReq;
+
+typedef struct {
+    CARD8      repType;        /* X_Reply                      */
+    CARD8      RepType;        /* always X_ChangeKeyboardDevice*/
+    CARD16     sequenceNumber B16;
+    CARD32     length B32;  /* 0 */
+    CARD8      status;
+    BYTE       pad1, pad2, pad3;
+    CARD32     pad01 B32;
+    CARD32     pad02 B32;
+    CARD32     pad03 B32;
+    CARD32     pad04 B32;
+    CARD32     pad05 B32;
+    } xChangeKeyboardDeviceReply;
+
+/*********************************************************
+ *
+ * ChangePointerDevice.
+ *
+ */
+
+typedef struct {
+    CARD8      reqType;        /* input extension major code   */
+    CARD8      ReqType;        /* X_ChangePointerDevice        */
+    CARD16     length B16;
+    CARD8      xaxis;
+    CARD8      yaxis;
+    CARD8      deviceid;
+    BYTE       pad1;
+} xChangePointerDeviceReq;
+
+typedef struct {
+    CARD8      repType;        /* X_Reply                      */
+    CARD8      RepType;        /* always X_ChangePointerDevice */
+    CARD16     sequenceNumber B16;
+    CARD32     length B32;  /* 0 */
+    CARD8      status;
+    BYTE       pad1, pad2, pad3;
+    CARD32     pad01 B32;
+    CARD32     pad02 B32;
+    CARD32     pad03 B32;
+    CARD32     pad04 B32;
+    CARD32     pad05 B32;
+    } xChangePointerDeviceReply;
+
+/*********************************************************
+ *
+ * GrabDevice.
+ *
+ */
+
+typedef struct {
+    CARD8      reqType;        /* input extension major code   */
+    CARD8      ReqType;        /* always X_GrabDevice */
+    CARD16     length B16;
+    Window     grabWindow B32;
+    Time       time B32;
+    CARD16     event_count B16;
+    CARD8      this_device_mode;
+    CARD8      other_devices_mode;
+    BOOL       ownerEvents;
+    CARD8      deviceid;
+    CARD16     pad01 B16;
+} xGrabDeviceReq;
+
+typedef struct {
+    CARD8      repType;        /* X_Reply                      */
+    CARD8      RepType;        /* always X_GrabDevice          */
+    CARD16     sequenceNumber B16;
+    CARD32     length B32;  /* 0 */
+    CARD8      status;
+    BYTE       pad1, pad2, pad3;
+    CARD32     pad01 B32;
+    CARD32     pad02 B32;
+    CARD32     pad03 B32;
+    CARD32     pad04 B32;
+    CARD32     pad05 B32;
+    } xGrabDeviceReply;
+
+/*********************************************************
+ *
+ * UngrabDevice.
+ *
+ */
+
+typedef struct {
+    CARD8      reqType;        /* input extension major code   */
+    CARD8      ReqType;        /* always X_UnGrabDevice        */
+    CARD16     length B16;
+    Time       time B32;
+    CARD8      deviceid;
+    BYTE       pad1, pad2, pad3;
+} xUngrabDeviceReq;
+
+/*********************************************************
+ *
+ * GrabDeviceKey.
+ *
+ */
+
+typedef struct {
+    CARD8      reqType;        /* input extension major code   */
+    CARD8      ReqType;        /* always X_GrabDeviceKey       */
+    CARD16     length B16;
+    Window     grabWindow B32;
+    CARD16     event_count B16;
+    CARD16     modifiers B16;
+    CARD8      modifier_device;
+    CARD8      grabbed_device;
+    CARD8      key;
+    BYTE       this_device_mode;  
+    BYTE       other_devices_mode;  
+    BOOL       ownerEvents;
+    BYTE       pad1, pad2;
+} xGrabDeviceKeyReq;
+
+/*********************************************************
+ *
+ * UngrabDeviceKey.
+ *
+ */
+
+typedef struct {
+    CARD8      reqType;        /* input extension major code   */
+    CARD8      ReqType;        /* always X_UngrabDeviceKey     */
+    CARD16     length B16;
+    Window     grabWindow B32;
+    CARD16     modifiers B16;
+    CARD8      modifier_device;
+    CARD8      key;
+    CARD8      grabbed_device;
+    BYTE       pad1, pad2, pad3;
+} xUngrabDeviceKeyReq;
+
+/*********************************************************
+ *
+ * GrabDeviceButton.
+ *
+ */
+
+typedef struct {
+    CARD8      reqType;        /* input extension major code   */
+    CARD8      ReqType;        /* always X_GrabDeviceButton    */
+    CARD16     length B16;
+    Window     grabWindow B32;
+    CARD8      grabbed_device;
+    CARD8      modifier_device;
+    CARD16     event_count B16;
+    CARD16     modifiers B16;
+    BYTE       this_device_mode;  
+    BYTE       other_devices_mode;  
+    CARD8      button;
+    BOOL       ownerEvents;
+    BYTE       pad1, pad2;
+} xGrabDeviceButtonReq;
+
+/*********************************************************
+ *
+ * UngrabDeviceButton.
+ *
+ */
+
+typedef struct {
+    CARD8      reqType;        /* input extension major code   */
+    CARD8      ReqType;        /* always X_UngrabDeviceButton  */
+    CARD16     length B16;
+    Window     grabWindow B32;
+    CARD16     modifiers B16;
+    CARD8      modifier_device;
+    CARD8      button;
+    CARD8      grabbed_device;
+    BYTE       pad1, pad2, pad3;
+} xUngrabDeviceButtonReq;
+
+/*********************************************************
+ *
+ * AllowDeviceEvents.
+ *
+ */
+
+typedef struct {
+    CARD8      reqType;        /* input extension major code   */
+    CARD8      ReqType;        /* always X_AllowDeviceEvents   */
+    CARD16     length B16;
+    Time       time B32;
+    CARD8      mode;
+    CARD8      deviceid;
+    BYTE       pad1, pad2;
+} xAllowDeviceEventsReq;
+
+/*********************************************************
+ *
+ * GetDeviceFocus.
+ *
+ */
+
+typedef struct {
+    CARD8      reqType;        /* input extension major code   */
+    CARD8      ReqType;        /* always X_GetDeviceFocus      */
+    CARD16     length B16;
+    CARD8      deviceid;
+    BYTE       pad1, pad2, pad3;
+} xGetDeviceFocusReq;
+
+typedef struct {
+    CARD8      repType;        /* X_Reply                      */
+    CARD8      RepType;        /* always X_GetDeviceFocus      */
+    CARD16     sequenceNumber B16;
+    CARD32     length B32;
+    CARD32     focus B32;
+    Time       time B32;
+    CARD8      revertTo;
+    BYTE       pad1, pad2, pad3;
+    CARD32     pad01 B32;
+    CARD32     pad02 B32;
+    CARD32     pad03 B32;
+    } xGetDeviceFocusReply;
+
+/*********************************************************
+ *
+ * SetDeviceFocus.
+ *
+ */
+
+typedef struct {
+    CARD8      reqType;        /* input extension major code   */
+    CARD8      ReqType;        /* always X_SetDeviceFocus      */
+    CARD16     length B16;
+    Window     focus B32;
+    Time       time B32;
+    CARD8      revertTo;
+    CARD8      device;
+    CARD16     pad01 B16;
+} xSetDeviceFocusReq;
+
+/*********************************************************
+ *
+ * GetFeedbackControl.
+ *
+ */
+
+typedef struct {
+    CARD8      reqType;        /* input extension major code   */
+    CARD8      ReqType;        /* X_GetFeedbackControl         */
+    CARD16     length B16;
+    CARD8      deviceid;
+    BYTE       pad1, pad2, pad3;
+} xGetFeedbackControlReq;
+
+typedef struct {
+    CARD8      repType;        /* X_Reply                      */
+    CARD8      RepType;        /* always X_GetFeedbackControl  */
+    CARD16     sequenceNumber B16;
+    CARD32     length B32;
+    CARD16     num_feedbacks B16;
+    CARD16     pad01 B16;
+    CARD32     pad02 B32;
+    CARD32     pad03 B32;
+    CARD32     pad04 B32;
+    CARD32     pad05 B32;
+    CARD32     pad06 B32;
+} xGetFeedbackControlReply;
+
+typedef struct {
+    CARD8      class;          /* feedback class               */
+    CARD8      id;             /* feedback id                  */
+    CARD16     length B16;     /* feedback length              */
+} xFeedbackState;
+
+typedef struct {
+    CARD8   class;
+    CARD8   id;
+    CARD16  length B16;
+    CARD16  pitch B16;
+    CARD16  duration B16;
+    CARD32  led_mask B32;
+    CARD32  led_values B32;
+    BOOL    global_auto_repeat;
+    CARD8   click;
+    CARD8   percent;
+    BYTE    pad;
+    BYTE    auto_repeats[32];
+} xKbdFeedbackState;
+
+typedef struct {
+    CARD8   class;
+    CARD8   id;
+    CARD16  length B16;
+    CARD8   pad1,pad2;
+    CARD16  accelNum B16;
+    CARD16  accelDenom B16;
+    CARD16  threshold B16;
+} xPtrFeedbackState;
+
+typedef struct {
+    CARD8      class;          /* feedback class id            */
+    CARD8      id;
+    CARD16     length B16;     /* feedback length              */
+    CARD32     resolution B32;
+    INT32      min_value B32;
+    INT32      max_value B32;
+} xIntegerFeedbackState;
+
+typedef struct {
+    CARD8      class;          /* feedback class id            */
+    CARD8      id;
+    CARD16     length B16;     /* feedback length              */
+    CARD16     max_symbols B16;
+    CARD16     num_syms_supported B16;
+} xStringFeedbackState;
+
+typedef struct {
+    CARD8      class;          /* feedback class id            */
+    CARD8      id;
+    CARD16     length B16;     /* feedback length              */
+    CARD8      percent;
+    BYTE       pad1, pad2, pad3;
+    CARD16     pitch B16;
+    CARD16     duration B16;
+} xBellFeedbackState;
+
+typedef struct {
+    CARD8      class;          /* feedback class id            */
+    CARD8      id;
+    CARD16     length B16;     /* feedback length              */
+    CARD32     led_mask B32;
+    CARD32     led_values B32;
+} xLedFeedbackState;
+
+/*********************************************************
+ *
+ * ChangeFeedbackControl.
+ *
+ */
+
+typedef struct {
+    CARD8      reqType;        /* input extension major code   */
+    CARD8      ReqType;        /* X_ChangeFeedbackControl      */
+    CARD16     length B16;
+    CARD32     mask B32;
+    CARD8      deviceid;
+    CARD8      feedbackid;
+    BYTE       pad1, pad2;
+} xChangeFeedbackControlReq;
+
+typedef struct {
+    CARD8      class;          /* feedback class id            */
+    CARD8      id;             /* feedback id                  */
+    CARD16     length B16;     /* feedback length              */
+} xFeedbackCtl;
+
+typedef struct {
+    CARD8      class;          /* feedback class id            */
+    CARD8      id;             /* feedback length              */
+    CARD16     length B16;     /* feedback length              */
+    KeyCode    key; 
+    CARD8      auto_repeat_mode;
+    INT8       click;
+    INT8       percent;
+    INT16      pitch B16;
+    INT16      duration B16;
+    CARD32     led_mask B32;
+    CARD32     led_values B32;
+} xKbdFeedbackCtl;
+
+typedef struct {
+    CARD8      class;          /* feedback class id            */
+    CARD8      id;             /* feedback id                  */
+    CARD16     length B16;     /* feedback length              */
+    CARD8      pad1,pad2;
+    INT16      num B16;
+    INT16      denom B16;
+    INT16      thresh B16;
+} xPtrFeedbackCtl;
+
+typedef struct {
+    CARD8      class;          /* feedback class id            */
+    CARD8      id;             /* feedback id                  */
+    CARD16     length B16;     /* feedback length              */
+    INT32      int_to_display B32;
+} xIntegerFeedbackCtl;
+
+typedef struct {
+    CARD8      class;          /* feedback class id            */
+    CARD8      id;             /* feedback id                  */
+    CARD16     length B16;     /* feedback length              */
+    CARD8      pad1,pad2;
+    CARD16     num_keysyms B16;
+} xStringFeedbackCtl;
+
+typedef struct {
+    CARD8      class;          /* feedback class id            */
+    CARD8      id;             /* feedback id                  */
+    CARD16     length B16;     /* feedback length              */
+    INT8       percent;
+    BYTE       pad1, pad2, pad3;
+    INT16      pitch B16;
+    INT16      duration B16;
+} xBellFeedbackCtl;
+
+typedef struct {
+    CARD8      class;          /* feedback class id            */
+    CARD8      id;             /* feedback id                  */
+    CARD16     length B16;     /* feedback length              */
+    CARD32     led_mask B32;
+    CARD32     led_values B32;
+} xLedFeedbackCtl;
+
+/*********************************************************
+ *
+ * GetDeviceKeyMapping.
+ *
+ */
+
+typedef struct {
+    CARD8      reqType;        /* input extension major code   */
+    CARD8      ReqType;        /* always X_GetDeviceKeyMapping */
+    CARD16     length B16;
+    CARD8      deviceid;
+    KeyCode    firstKeyCode; 
+    CARD8      count;
+    BYTE       pad1;
+} xGetDeviceKeyMappingReq;
+
+typedef struct {
+    CARD8      repType;        /* X_Reply                      */
+    CARD8      RepType;        /* always X_GetDeviceKeyMapping */
+    CARD16     sequenceNumber B16;
+    CARD32     length B32;
+    CARD8      keySymsPerKeyCode;
+    CARD8      pad0;
+    CARD16     pad1 B16;
+    CARD32     pad2 B32;
+    CARD32     pad3 B32;
+    CARD32     pad4 B32;
+    CARD32     pad5 B32;
+    CARD32     pad6 B32;
+} xGetDeviceKeyMappingReply;
+
+/*********************************************************
+ *
+ * ChangeDeviceKeyMapping.
+ *
+ */
+
+typedef struct {
+    CARD8      reqType;        /* input extension major code   */
+    CARD8      ReqType;        /* always X_ChangeDeviceKeyMapping */
+    CARD16     length B16;
+    CARD8      deviceid;
+    KeyCode    firstKeyCode;
+    CARD8      keySymsPerKeyCode;
+    CARD8      keyCodes;
+} xChangeDeviceKeyMappingReq;
+
+/*********************************************************
+ *
+ * GetDeviceModifierMapping.
+ *
+ */
+
+typedef struct {
+    CARD8      reqType;        /* input extension major code   */
+    CARD8      ReqType;        /* always X_GetDeviceModifierMapping */
+    CARD16     length B16;
+    CARD8      deviceid;
+    BYTE       pad1, pad2, pad3;
+} xGetDeviceModifierMappingReq;
+
+typedef struct {
+    CARD8      repType;        /* X_Reply */
+    CARD8      RepType;        /* always X_GetDeviceModifierMapping */
+    CARD16     sequenceNumber B16;
+    CARD32     length B32;
+    CARD8      numKeyPerModifier;
+    CARD8      pad0;
+    CARD16     pad1 B16;
+    CARD32     pad2 B32;
+    CARD32     pad3 B32;
+    CARD32     pad4 B32;
+    CARD32     pad5 B32;
+    CARD32     pad6 B32;
+} xGetDeviceModifierMappingReply;
+
+/*********************************************************
+ *
+ * SetDeviceModifierMapping.
+ *
+ */
+
+typedef struct {
+    CARD8      reqType;        /* input extension major code   */
+    CARD8      ReqType;        /* always X_SetDeviceModifierMapping */
+    CARD16     length B16;
+    CARD8      deviceid;
+    CARD8      numKeyPerModifier;
+    CARD16     pad1 B16;
+} xSetDeviceModifierMappingReq;
+
+typedef struct {
+    CARD8      repType;        /* X_Reply */
+    CARD8      RepType;        /* always X_SetDeviceModifierMapping */
+    CARD16     sequenceNumber B16;
+    CARD32     length B32;
+    CARD8      success;
+    CARD8      pad0;
+    CARD16     pad1 B16;
+    CARD32     pad2 B32;
+    CARD32     pad3 B32;
+    CARD32     pad4 B32;
+    CARD32     pad5 B32;
+    CARD32     pad6 B32;
+} xSetDeviceModifierMappingReply;
+
+/*********************************************************
+ *
+ * GetDeviceButtonMapping.
+ *
+ */
+
+typedef struct {
+    CARD8      reqType;        /* input extension major code   */
+    CARD8      ReqType;        /* X_GetDeviceButtonMapping     */
+    CARD16     length B16;
+    CARD8      deviceid;
+    BYTE       pad1, pad2, pad3;
+} xGetDeviceButtonMappingReq;
+
+typedef struct {
+    CARD8      repType;        /* X_Reply */
+    CARD8      RepType;        /* always X_GetDeviceButtonMapping */
+    CARD16     sequenceNumber B16;
+    CARD32     length B32;
+    CARD8      nElts;
+    BYTE       pad1, pad2, pad3;
+    CARD32     pad01 B32;
+    CARD32     pad02 B32;
+    CARD32     pad03 B32;
+    CARD32     pad04 B32;
+    CARD32     pad05 B32;
+} xGetDeviceButtonMappingReply;
+
+/*********************************************************
+ *
+ * SetDeviceButtonMapping.
+ *
+ */
+
+typedef struct {
+    CARD8      reqType;        /* input extension major code   */
+    CARD8      ReqType;        /* X_SetDeviceButtonMapping     */
+    CARD16     length B16;
+    CARD8      deviceid;
+    CARD8      map_length;
+    BYTE       pad1, pad2;
+} xSetDeviceButtonMappingReq;
+
+typedef struct {
+    CARD8      repType;                /* X_Reply */
+    CARD8      RepType;                /* always X_SetDeviceButtonMapping */
+    CARD16     sequenceNumber B16;
+    CARD32     length B32;
+    CARD8      status;
+    BYTE       pad0;
+    CARD16     pad1 B16;
+    CARD32     pad2 B32;
+    CARD32     pad3 B32;
+    CARD32     pad4 B32;
+    CARD32     pad5 B32;
+    CARD32     pad6 B32;
+} xSetDeviceButtonMappingReply;
+
+/*********************************************************
+ *
+ * QueryDeviceState.
+ *
+ */
+
+typedef struct {
+    CARD8      reqType;
+    CARD8      ReqType;        /* always X_QueryDeviceState */
+    CARD16     length B16;
+    CARD8      deviceid;
+    BYTE       pad1, pad2, pad3;
+} xQueryDeviceStateReq;
+
+typedef struct {
+    CARD8      repType;                /* X_Reply */
+    CARD8      RepType;                /* always X_QueryDeviceState    */
+    CARD16     sequenceNumber B16;
+    CARD32     length B32;
+    CARD8      num_classes;
+    BYTE       pad0;
+    CARD16     pad1 B16;
+    CARD32     pad2 B32;
+    CARD32     pad3 B32;
+    CARD32     pad4 B32;
+    CARD32     pad5 B32;
+    CARD32     pad6 B32;
+} xQueryDeviceStateReply;
+
+typedef struct {
+    CARD8      class;
+    CARD8      length;
+    CARD8      num_keys;
+    BYTE       pad1;
+    CARD8      keys[32];
+} xKeyState;
+
+typedef struct {
+    CARD8      class;
+    CARD8      length;
+    CARD8      num_buttons;
+    BYTE       pad1;
+    CARD8      buttons[32];
+} xButtonState;
+
+typedef struct {
+    CARD8      class;
+    CARD8      length;
+    CARD8      num_valuators;
+    CARD8      mode;
+} xValuatorState;
+
+/*********************************************************
+ *
+ * SendExtensionEvent.
+ * THIS REQUEST MUST BE KEPT A MULTIPLE OF 8 BYTES IN LENGTH!
+ * MORE EVENTS MAY FOLLOW AND THEY MUST BE QUAD-ALIGNED!
+ *
+ */
+
+typedef struct {
+    CARD8      reqType;
+    CARD8      ReqType;        /* always X_SendExtensionEvent */
+    CARD16     length B16;
+    Window     destination B32;
+    CARD8      deviceid;
+    BOOL       propagate;
+    CARD16     count B16;
+    CARD8      num_events;
+    BYTE       pad1,pad2,pad3;
+} xSendExtensionEventReq;
+
+/*********************************************************
+ *
+ * DeviceBell.
+ *
+ */
+
+typedef struct {
+    CARD8      reqType;
+    CARD8      ReqType;        /* always X_DeviceBell */
+    CARD16     length B16;
+    CARD8      deviceid;
+    CARD8      feedbackid;
+    CARD8      feedbackclass;
+    INT8       percent;
+} xDeviceBellReq;
+
+/*********************************************************
+ *
+ * SetDeviceValuators.
+ *
+ */
+
+typedef struct {
+    CARD8      reqType;        /* input extension major code   */
+    CARD8      ReqType;        /* always X_SetDeviceValuators  */
+    CARD16     length B16;
+    CARD8       deviceid;
+    CARD8       first_valuator;
+    CARD8       num_valuators;
+    BYTE       pad1;
+} xSetDeviceValuatorsReq;
+
+typedef struct {
+    CARD8      repType;        /* X_Reply                      */
+    CARD8      RepType;        /* always X_SetDeviceValuators  */
+    CARD16     sequenceNumber B16;
+    CARD32     length B32;
+    CARD8      status;
+    BYTE       pad1, pad2, pad3;
+    CARD32     pad01 B32;
+    CARD32     pad02 B32;
+    CARD32     pad03 B32;
+    CARD32     pad04 B32;
+    CARD32     pad05 B32;
+} xSetDeviceValuatorsReply;
+
+/*********************************************************
+ *
+ * GetDeviceControl.
+ *
+ */
+
+typedef struct {
+    CARD8      reqType;        /* input extension major code   */
+    CARD8      ReqType;        /* always X_GetDeviceControl    */
+    CARD16     length B16;
+    CARD16      control B16;
+    CARD8       deviceid;
+    BYTE       pad2;
+} xGetDeviceControlReq;
+
+typedef struct {
+    CARD8      repType;        /* X_Reply                      */
+    CARD8      RepType;        /* always X_GetDeviceControl    */
+    CARD16     sequenceNumber B16;
+    CARD32     length B32;
+    CARD8      status;
+    BYTE       pad1, pad2, pad3;
+    CARD32     pad01 B32;
+    CARD32     pad02 B32;
+    CARD32     pad03 B32;
+    CARD32     pad04 B32;
+    CARD32     pad05 B32;
+} xGetDeviceControlReply;
+
+typedef struct {
+    CARD16     control B16;    /* control type                 */
+    CARD16     length B16;     /* control length               */
+} xDeviceState;
+
+typedef struct {
+    CARD16     control B16;            /* control type                 */
+    CARD16     length B16;             /* control length               */
+    CARD32     num_valuators B32;      /* number of valuators          */
+} xDeviceResolutionState;
+
+/*********************************************************
+ *
+ * ChangeDeviceControl.
+ *
+ */
+
+typedef struct {
+    CARD8      reqType;        /* input extension major code   */
+    CARD8      ReqType;        /* always X_ChangeDeviceControl */
+    CARD16     length B16;
+    CARD16      control B16;
+    CARD8       deviceid;
+    BYTE        pad0;
+} xChangeDeviceControlReq;
+
+typedef struct {
+    CARD8      repType;        /* X_Reply                      */
+    CARD8      RepType;        /* always X_ChangeDeviceControl */
+    CARD16     sequenceNumber B16;
+    CARD32     length B32;
+    CARD8      status;
+    BYTE       pad1, pad2, pad3;
+    CARD32     pad01 B32;
+    CARD32     pad02 B32;
+    CARD32     pad03 B32;
+    CARD32     pad04 B32;
+    CARD32     pad05 B32;
+} xChangeDeviceControlReply;
+
+typedef struct {
+    CARD16     control B16;    /* control type                 */
+    CARD16     length B16;     /* control length               */
+} xDeviceCtl;
+
+typedef struct {
+    CARD16     control B16;            /* control type                 */
+    CARD16     length B16;             /* control length               */
+    CARD8      first_valuator;         /* first valuator to change     */
+    CARD8      num_valuators;          /* number of valuators to change*/
+    CARD8      pad1,pad2;
+} xDeviceResolutionCtl;
+
+/**********************************************************
+ *
+ * Input extension events.
+ *
+ * DeviceValuator
+ *
+ */
+
+typedef struct
+    {
+    BYTE       type;
+    CARD8       deviceid;
+    CARD16     sequenceNumber B16;
+    KeyButMask  device_state B16;
+    CARD8      num_valuators;
+    CARD8       first_valuator;
+    INT32      valuator0 B32;
+    INT32      valuator1 B32;
+    INT32      valuator2 B32;
+    INT32      valuator3 B32;
+    INT32      valuator4 B32;
+    INT32      valuator5 B32;
+    }  deviceValuator;
+
+/**********************************************************
+ *
+ * DeviceKeyButtonPointer.
+ *
+ * Used for: DeviceKeyPress, DeviceKeyRelease,
+ *          DeviceButtonPress, DeviceButtonRelease,
+ *          ProximityIn, ProximityOut
+ *          DeviceMotionNotify,
+ * 
+ */
+
+typedef struct
+    {
+    BYTE       type;
+    BYTE        detail;
+    CARD16     sequenceNumber B16;
+    Time        time B32;
+    Window      root B32;
+    Window      event B32;
+    Window      child B32;
+    INT16       root_x B16;
+    INT16       root_y B16;
+    INT16       event_x B16;
+    INT16       event_y B16;
+    KeyButMask  state B16;
+    BOOL        same_screen;
+    CARD8       deviceid;
+    }  deviceKeyButtonPointer;
+
+/**********************************************************
+ *
+ * DeviceFocus.
+ *
+ */
+
+typedef struct
+    {
+    BYTE       type;
+    BYTE        detail;
+    CARD16     sequenceNumber B16;
+    Time        time B32;
+    Window      window B32;
+    BYTE       mode;
+    CARD8       deviceid;
+    BYTE       pad1, pad2;
+    CARD32     pad00 B32;
+    CARD32     pad01 B32;
+    CARD32     pad02 B32;
+    CARD32     pad03 B32;
+    }  deviceFocus;
+
+/**********************************************************
+ *
+ * DeviceStateNotify.
+ *
+ * Note that the two high-order bits in the classes_reported
+ * field are the proximity state (InProximity or OutOfProximity),
+ * and the device mode (Absolute or Relative), respectively.
+ *
+ */
+
+typedef struct
+    {
+    BYTE       type;
+    BYTE        deviceid;
+    CARD16     sequenceNumber B16;
+    Time        time B32;
+    CARD8      num_keys;
+    CARD8      num_buttons;
+    CARD8      num_valuators;
+    CARD8       classes_reported;
+    CARD8       buttons[4];
+    CARD8       keys[4];
+    INT32      valuator0 B32;
+    INT32      valuator1 B32;
+    INT32      valuator2 B32;
+    }  deviceStateNotify;
+
+/**********************************************************
+ *
+ * DeviceKeyStateNotify.
+ *
+ */
+
+typedef struct
+    {
+    BYTE       type;
+    BYTE        deviceid;
+    CARD16     sequenceNumber B16;
+    CARD8       keys[28];
+    }  deviceKeyStateNotify;
+
+/**********************************************************
+ *
+ * DeviceButtonStateNotify.
+ *
+ */
+
+typedef struct
+    {
+    BYTE       type;
+    BYTE        deviceid;
+    CARD16     sequenceNumber B16;
+    CARD8       buttons[28];
+    }  deviceButtonStateNotify;
+
+/**********************************************************
+ *
+ * DeviceMappingNotify.
+ * Fields must be kept in sync with core mappingnotify event.
+ *
+ */
+
+typedef struct
+    {
+    BYTE       type;
+    BYTE        deviceid;
+    CARD16     sequenceNumber B16;
+    CARD8       request;
+    KeyCode     firstKeyCode;
+    CARD8       count;
+    BYTE        pad1;
+    Time        time B32;
+    CARD32     pad00 B32;
+    CARD32     pad01 B32;
+    CARD32     pad02 B32;
+    CARD32     pad03 B32;
+    CARD32     pad04 B32;
+    }  deviceMappingNotify;
+
+/**********************************************************
+ *
+ * ChangeDeviceNotify.
+ *
+ */
+
+typedef struct
+    {
+    BYTE       type;
+    BYTE        deviceid;
+    CARD16     sequenceNumber B16;
+    Time        time B32;
+    CARD8       request;
+    BYTE        pad1, pad2, pad3;
+    CARD32     pad00 B32;
+    CARD32     pad01 B32;
+    CARD32     pad02 B32;
+    CARD32     pad03 B32;
+    CARD32     pad04 B32;
+    }  changeDeviceNotify;
+
+#undef Window
+#undef Time
+#undef KeyCode
+
+#endif
diff --git a/Xserver/include/extensions/XKB.h b/Xserver/include/extensions/XKB.h
new file mode 100644 (file)
index 0000000..06426ed
--- /dev/null
@@ -0,0 +1,781 @@
+/* $XConsortium: XKB.h /main/14 1996/02/05 10:19:11 kaleb $ */
+/************************************************************
+Copyright (c) 1993 by Silicon Graphics Computer Systems, Inc.
+
+Permission to use, copy, modify, and distribute this
+software and its documentation for any purpose and without
+fee is hereby granted, provided that the above copyright
+notice appear in all copies and that both that copyright
+notice and this permission notice appear in supporting
+documentation, and that the name of Silicon Graphics not be 
+used in advertising or publicity pertaining to distribution 
+of the software without specific prior written permission.
+Silicon Graphics makes no representation about the suitability 
+of this software for any purpose. It is provided "as is"
+without any express or implied warranty.
+
+SILICON GRAPHICS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS 
+SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 
+AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
+GRAPHICS BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL 
+DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, 
+DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE 
+OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION  WITH
+THE USE OR PERFORMANCE OF THIS SOFTWARE.
+
+********************************************************/
+
+#ifndef _XKB_H_
+#define        _XKB_H_
+
+    /*
+     * XKB request codes, used in:
+     *  -  xkbReqType field of all requests
+     *  -  requestMinor field of some events
+     */
+#define        X_kbUseExtension                 0
+#define        X_kbSelectEvents                 1
+#define        X_kbBell                         3
+#define        X_kbGetState                     4
+#define        X_kbLatchLockState               5
+#define        X_kbGetControls                  6
+#define        X_kbSetControls                  7
+#define        X_kbGetMap                       8
+#define        X_kbSetMap                       9
+#define        X_kbGetCompatMap                10
+#define        X_kbSetCompatMap                11
+#define        X_kbGetIndicatorState           12
+#define        X_kbGetIndicatorMap             13
+#define        X_kbSetIndicatorMap             14
+#define        X_kbGetNamedIndicator           15
+#define        X_kbSetNamedIndicator           16
+#define        X_kbGetNames                    17
+#define        X_kbSetNames                    18
+#define        X_kbGetGeometry                 19
+#define        X_kbSetGeometry                 20
+#define        X_kbPerClientFlags              21
+#define        X_kbListComponents              22
+#define        X_kbGetKbdByName                23
+#define        X_kbGetDeviceInfo               24
+#define        X_kbSetDeviceInfo               25
+#define        X_kbSetDebuggingFlags           101
+
+    /*
+     * In the X sense, XKB reports only one event.
+     * The type field of all XKB events is XkbEventCode
+     */
+#define        XkbEventCode                    0
+#define        XkbNumberEvents                 (XkbEventCode+1)
+
+    /*
+     * XKB has a minor event code so it can use one X event code for 
+     * multiple purposes.  
+     *  - reported in the xkbType field of all XKB events.
+     *  - XkbSelectEventDetails: Indicates the event for which event details 
+     *    are being changed
+     */
+#define        XkbNewKeyboardNotify            0
+#define XkbMapNotify                   1
+#define        XkbStateNotify                  2
+#define XkbControlsNotify              3
+#define        XkbIndicatorStateNotify         4
+#define        XkbIndicatorMapNotify           5
+#define        XkbNamesNotify                  6
+#define XkbCompatMapNotify             7
+#define        XkbBellNotify                   8
+#define        XkbActionMessage                9
+#define        XkbAccessXNotify                10
+#define        XkbExtensionDeviceNotify        11
+
+    /*
+     * Event Mask:
+     *  - XkbSelectEvents:  Specifies event interest.
+     */
+#define        XkbNewKeyboardNotifyMask        (1L << 0)
+#define XkbMapNotifyMask               (1L << 1)
+#define        XkbStateNotifyMask              (1L << 2)
+#define XkbControlsNotifyMask          (1L << 3)
+#define        XkbIndicatorStateNotifyMask     (1L << 4)
+#define        XkbIndicatorMapNotifyMask       (1L << 5)
+#define        XkbNamesNotifyMask              (1L << 6)
+#define XkbCompatMapNotifyMask         (1L << 7)
+#define        XkbBellNotifyMask               (1L << 8)
+#define        XkbActionMessageMask            (1L << 9)
+#define        XkbAccessXNotifyMask            (1L << 10)
+#define        XkbExtensionDeviceNotifyMask    (1L << 11)
+#define        XkbAllEventsMask                (0xFFF)
+
+    /*
+     * NewKeyboardNotify event details:
+     */
+#define        XkbNKN_KeycodesMask             (1L << 0)
+#define        XkbNKN_GeometryMask             (1L << 1)
+#define        XkbNKN_DeviceIDMask             (1L << 2)
+#define        XkbAllNewKeyboardEventsMask     (0x7)
+
+    /*
+     * AccessXNotify event types:
+     *  - The 'what' field of AccessXNotify events reports the
+     *    reason that the event was generated.
+     */
+#define        XkbAXN_SKPress                  0
+#define        XkbAXN_SKAccept                 1
+#define        XkbAXN_SKReject                 2
+#define        XkbAXN_SKRelease                3
+#define        XkbAXN_BKAccept                 4
+#define        XkbAXN_BKReject                 5
+#define        XkbAXN_AXKWarning               6
+
+    /*
+     * AccessXNotify details:
+     * - Used as an event detail mask to limit the conditions under which
+     *   AccessXNotify events are reported
+     */
+#define        XkbAXN_SKPressMask              (1L << 0)
+#define        XkbAXN_SKAcceptMask             (1L << 1)
+#define        XkbAXN_SKRejectMask             (1L << 2)
+#define        XkbAXN_SKReleaseMask            (1L << 3)
+#define        XkbAXN_BKAcceptMask             (1L << 4)
+#define        XkbAXN_BKRejectMask             (1L << 5)
+#define        XkbAXN_AXKWarningMask           (1L << 6)
+#define        XkbAllAccessXEventsMask         (0xf)
+
+    /*
+     * Miscellaneous event details:
+     * - event detail masks for assorted events that don't reall
+     *   have any details.
+     */
+#define        XkbAllStateEventsMask           XkbAllStateComponentsMask
+#define        XkbAllMapEventsMask             XkbAllMapComponentsMask
+#define        XkbAllControlEventsMask         XkbAllControlsMask
+#define        XkbAllIndicatorEventsMask       XkbAllIndicatorsMask
+#define        XkbAllNameEventsMask            XkbAllNamesMask
+#define        XkbAllCompatMapEventsMask       XkbAllCompatMask
+#define        XkbAllBellEventsMask            (1L << 0)
+#define        XkbAllActionMessagesMask        (1L << 0)
+
+    /*
+     * XKB reports one error:  BadKeyboard
+     * A further reason for the error is encoded into to most significant
+     * byte of the resourceID for the error:
+     *    XkbErr_BadDevice - the device in question was not found
+     *    XkbErr_BadClass  - the device was found but it doesn't belong to 
+     *                       the appropriate class.
+     *    XkbErr_BadId     - the device was found and belongs to the right
+     *                       class, but not feedback with a matching id was
+     *                       found.
+     * The low byte of the resourceID for this error contains the device
+     * id, class specifier or feedback id that failed.
+     */
+#define        XkbKeyboard                     0
+#define        XkbNumberErrors                 1
+
+#define        XkbErr_BadDevice        0xff
+#define        XkbErr_BadClass         0xfe
+#define        XkbErr_BadId            0xfd
+
+    /*
+     * Keyboard Components Mask:
+     * - Specifies the components that follow a GetKeyboardByNameReply
+     */
+#define        XkbClientMapMask                (1L << 0)
+#define        XkbServerMapMask                (1L << 1)
+#define        XkbCompatMapMask                (1L << 2)
+#define        XkbIndicatorMapMask             (1L << 3)
+#define        XkbNamesMask                    (1L << 4)
+#define        XkbGeometryMask                 (1L << 5)
+#define        XkbControlsMask                 (1L << 6)
+#define        XkbAllComponentsMask            (0x7f)
+
+    /*
+     * State detail mask:
+     *  - The 'changed' field of StateNotify events reports which of
+     *    the keyboard state components have changed.
+     *  - Used as an event detail mask to limit the conditions under
+     *    which StateNotify events are reported.
+     */
+#define        XkbModifierStateMask            (1L << 0)
+#define        XkbModifierBaseMask             (1L << 1)
+#define        XkbModifierLatchMask            (1L << 2)
+#define        XkbModifierLockMask             (1L << 3)
+#define        XkbGroupStateMask               (1L << 4)
+#define        XkbGroupBaseMask                (1L << 5)
+#define        XkbGroupLatchMask               (1L << 6)
+#define XkbGroupLockMask               (1L << 7)
+#define        XkbCompatStateMask              (1L << 8)
+#define        XkbGrabModsMask                 (1L << 9)
+#define        XkbCompatGrabModsMask           (1L << 10)
+#define        XkbLookupModsMask               (1L << 11)
+#define        XkbCompatLookupModsMask         (1L << 12)
+#define        XkbPointerButtonMask            (1L << 13)
+#define        XkbAllStateComponentsMask       (0x3fff)
+
+    /*
+     * Controls detail masks:
+     *  The controls specified in XkbAllControlsMask:
+     *  - The 'changed' field of ControlsNotify events reports which of 
+     *    the keyboard controls have changed.
+     *  - The 'changeControls' field of the SetControls request specifies
+     *    the controls for which values are to be changed.
+     *  - Used as an event detail mask to limit the conditions under 
+     *    which ControlsNotify events are reported.
+     *
+     *  The controls specified in the XkbAllBooleanCtrlsMask:
+     *  - The 'enabledControls' field of ControlsNotify events reports the
+     *    current status of the boolean controls.
+     *  - The 'enabledControlsChanges' field of ControlsNotify events reports
+     *    any boolean controls that have been turned on or off.
+     *  - The 'affectEnabledControls' and 'enabledControls' fields of the
+     *    kbSetControls request change the set of enabled controls.
+     *  - The 'accessXTimeoutMask' and 'accessXTimeoutValues' fields of
+     *    an XkbControlsRec specify the controls to be changed if the keyboard
+     *    times out and the values to which they should be changed.
+     *  - The 'autoCtrls' and 'autoCtrlsValues' fields of the PerClientFlags 
+     *    request specifies the specify the controls to be reset when the
+     *    client exits and the values to which they should be reset.
+     *  - The 'ctrls' field of an indicator map specifies the controls
+     *    that drive the indicator.
+     *  - Specifies the boolean controls affected by the SetControls and
+     *    LockControls key actions.
+     */
+#define        XkbRepeatKeysMask        (1L << 0)
+#define        XkbSlowKeysMask          (1L << 1)
+#define        XkbBounceKeysMask        (1L << 2)
+#define        XkbStickyKeysMask        (1L << 3)
+#define        XkbMouseKeysMask         (1L << 4)
+#define        XkbMouseKeysAccelMask    (1L << 5)
+#define        XkbAccessXKeysMask       (1L << 6)
+#define        XkbAccessXTimeoutMask    (1L << 7)
+#define        XkbAccessXFeedbackMask   (1L << 8)
+#define        XkbAudibleBellMask       (1L << 9)
+#define        XkbOverlay1Mask          (1L << 10)
+#define        XkbOverlay2Mask          (1L << 11)
+#define        XkbIgnoreGroupLockMask   (1L << 12)
+#define        XkbGroupsWrapMask        (1L << 27)
+#define        XkbInternalModsMask      (1L << 28)
+#define        XkbIgnoreLockModsMask    (1L << 29)
+#define        XkbPerKeyRepeatMask      (1L << 30)
+#define        XkbControlsEnabledMask   (1L << 31)
+
+#define        XkbAllBooleanCtrlsMask   (0x00001FFF)
+#define        XkbAllControlsMask       (0xF8001FFF)
+#define        XkbAllControlEventsMask  XkbAllControlsMask
+
+    /*
+     * AccessX Options Mask
+     *  - The 'accessXOptions' field of an XkbControlsRec specifies the
+     *    AccessX options that are currently in effect.
+     *  - The 'accessXTimeoutOptionsMask' and 'accessXTimeoutOptionsValues'
+     *    fields of an XkbControlsRec specify the Access X options to be 
+     *    changed if the keyboard times out and the values to which they 
+     *    should be changed.
+     */
+#define        XkbAX_SKPressFBMask     (1L << 0)
+#define        XkbAX_SKAcceptFBMask    (1L << 1)
+#define        XkbAX_FeatureFBMask     (1L << 2)
+#define        XkbAX_SlowWarnFBMask    (1L << 3)
+#define        XkbAX_IndicatorFBMask   (1L << 4)
+#define        XkbAX_StickyKeysFBMask  (1L << 5)
+#define        XkbAX_TwoKeysMask       (1L << 6)
+#define        XkbAX_LatchToLockMask   (1L << 7)
+#define        XkbAX_SKReleaseFBMask   (1L << 8)
+#define        XkbAX_SKRejectFBMask    (1L << 9)
+#define        XkbAX_BKRejectFBMask    (1L << 10)
+#define        XkbAX_DumbBellFBMask    (1L << 11)
+#define        XkbAX_FBOptionsMask     (0xF3F)
+#define        XkbAX_SKOptionsMask     (0x0C0)
+#define        XkbAX_AllOptionsMask    (0xFFF)
+
+    /*
+     * XkbUseCoreKbd is used to specify the core keyboard without having
+     *                         to look up its X input extension identifier.
+     * XkbUseCorePtr is used to specify the core pointer without having
+     *                 to look up its X input extension identifier.
+     * XkbDfltXIClass is used to specify "don't care" any place that the
+     *                 XKB protocol is looking for an X Input Extension 
+     *                 device class.
+     * XkbDfltXIId is used to specify "don't care" any place that the
+     *                 XKB protocol is looking for an X Input Extension
+     *                 feedback identifier.
+     * XkbAllXIClasses is used to get information about all device indicators,
+     *                 whether they're part of the indicator feedback class
+     *                 or the keyboard feedback class.
+     * XkbAllXIIds is used to get information about all device indicator
+     *                 feedbacks without having to list them.
+     * XkbXINone is used to indicate that no class or id has been specified.
+     * XkbLegalXILedClass(c)  True if 'c' specifies a legal class with LEDs
+     * XkbLegalXIBellClass(c) True if 'c' specifies a legal class with bells
+     * XkbExplicitXIDevice(d) True if 'd' explicitly specifies a device
+     * XkbExplicitXIClass(c)  True if 'c' explicitly specifies a device class
+     * XkbExplicitXIId(c)     True if 'i' explicitly specifies a device id
+     * XkbSingleXIClass(c)    True if 'c' specifies exactly one device class, 
+     *                        including the default.
+     * XkbSingleXIId(i)       True if 'i' specifies exactly one device 
+     *                       identifier, including the default.
+     */
+#define        XkbUseCoreKbd           0x0100
+#define        XkbUseCorePtr           0x0200
+#define        XkbDfltXIClass          0x0300
+#define        XkbDfltXIId             0x0400
+#define        XkbAllXIClasses         0x0500
+#define        XkbAllXIIds             0x0600
+#define        XkbXINone               0xff00
+
+#define        XkbLegalXILedClass(c)   (((c)==KbdFeedbackClass)||\
+                                       ((c)==LedFeedbackClass)||\
+                                       ((c)==XkbDfltXIClass)||\
+                                       ((c)==XkbAllXIClasses))
+#define        XkbLegalXIBellClass(c)  (((c)==KbdFeedbackClass)||\
+                                       ((c)==BellFeedbackClass)||\
+                                       ((c)==XkbDfltXIClass)||\
+                                       ((c)==XkbAllXIClasses))
+#define        XkbExplicitXIDevice(c)  (((c)&(~0xff))==0)
+#define        XkbExplicitXIClass(c)   (((c)&(~0xff))==0)
+#define        XkbExplicitXIId(c)      (((c)&(~0xff))==0)
+#define        XkbSingleXIClass(c)     ((((c)&(~0xff))==0)||((c)==XkbDfltXIClass))
+#define        XkbSingleXIId(c)        ((((c)&(~0xff))==0)||((c)==XkbDfltXIId))
+
+#define        XkbNoModifier           0xff
+#define        XkbNoShiftLevel         0xff
+#define        XkbNoShape              0xff
+#define        XkbNoIndicator          0xff
+
+#define        XkbNoModifierMask       0
+#define        XkbAllModifiersMask     0xff
+#define        XkbAllVirtualModsMask   0xffff
+
+#define        XkbNumKbdGroups         4
+#define        XkbMaxKbdGroup          (XkbNumKbdGroups-1)
+
+#define        XkbMaxMouseKeysBtn      4
+
+    /*
+     * Group Index and Mask:
+     *  - Indices into the kt_index array of a key type.
+     *  - Mask specifies types to be changed for XkbChangeTypesOfKey
+     */
+#define        XkbGroup1Index          0
+#define        XkbGroup2Index          1
+#define        XkbGroup3Index          2
+#define        XkbGroup4Index          3
+#define        XkbAnyGroup             254
+#define        XkbAllGroups            255
+
+#define        XkbGroup1Mask           (1<<0)
+#define        XkbGroup2Mask           (1<<1)
+#define        XkbGroup3Mask           (1<<2)
+#define        XkbGroup4Mask           (1<<3)
+#define        XkbAnyGroupMask         (1<<7)
+#define        XkbAllGroupsMask        (0xf)
+
+    /*
+     * BuildCoreState: Given a keyboard group and a modifier state,
+     *                 construct the value to be reported an event.
+     * GroupForCoreState:  Given the state reported in an event,
+     *                 determine the keyboard group.
+     * IsLegalGroup:   Returns TRUE if 'g' is a valid group index.
+     */
+#define        XkbBuildCoreState(m,g)  ((((g)&0x3)<<13)|((m)&0xff))
+#define XkbGroupForCoreState(s)        (((s)>>13)&0x3)
+#define        XkbIsLegalGroup(g)      (((g)>=0)&&((g)<XkbNumKbdGroups))
+
+    /*
+     * GroupsWrap values:
+     *  - The 'groupsWrap' field of an XkbControlsRec specifies the
+     *    treatment of out of range groups.
+     *  - Bits 6 and 7 of the group info field of a key symbol map
+     *    specify the interpretation of out of range groups for the
+     *    corresponding key.
+     */
+#define        XkbWrapIntoRange        (0x00)
+#define        XkbClampIntoRange       (0x40)
+#define        XkbRedirectIntoRange    (0x80)
+
+    /*
+     * Action flags:  Reported in the 'flags' field of most key actions.
+     * Interpretation depends on the type of the action; not all actions
+     * accept all flags.
+     *
+     * Option                  Used for Actions
+     * ------                  ----------------
+     * ClearLocks              SetMods, LatchMods, SetGroup, LatchGroup
+     * LatchToLock             SetMods, LatchMods, SetGroup, LatchGroup
+     * LockNoLock              LockMods, ISOLock, LockPtrBtn, LockDeviceBtn
+     * LockNoUnlock            LockMods, ISOLock, LockPtrBtn, LockDeviceBtn
+     * UseModMapMods           SetMods, LatchMods, LockMods, ISOLock
+     * GroupAbsolute           SetGroup, LatchGroup, LockGroup, ISOLock
+     * UseDfltButton           PtrBtn, LockPtrBtn
+     * NoAcceleration          MovePtr
+     * MoveAbsoluteX           MovePtr
+     * MoveAbsoluteY           MovePtr
+     * ISODfltIsGroup          ISOLock
+     * ISONoAffectMods         ISOLock
+     * ISONoAffectGroup                ISOLock
+     * ISONoAffectPtr          ISOLock
+     * ISONoAffectCtrls                ISOLock
+     * MessageOnPress          ActionMessage
+     * MessageOnRelease                ActionMessage
+     * MessageGenKeyEvent      ActionMessage
+     * AffectDfltBtn           SetPtrDflt
+     * DfltBtnAbsolute         SetPtrDflt
+     * SwitchApplication       SwitchScreen
+     * SwitchAbsolute          SwitchScreen
+     */
+
+#define        XkbSA_ClearLocks        (1L << 0)
+#define        XkbSA_LatchToLock       (1L << 1)
+
+#define        XkbSA_LockNoLock        (1L << 0)
+#define        XkbSA_LockNoUnlock      (1L << 1)
+
+#define        XkbSA_UseModMapMods     (1L << 2)
+
+#define        XkbSA_GroupAbsolute     (1L << 2)
+#define        XkbSA_UseDfltButton     0
+
+#define        XkbSA_NoAcceleration    (1L << 0)
+#define        XkbSA_MoveAbsoluteX     (1L << 1)
+#define        XkbSA_MoveAbsoluteY     (1L << 2)
+
+#define        XkbSA_ISODfltIsGroup     (1L << 7)
+#define        XkbSA_ISONoAffectMods    (1L << 6)
+#define        XkbSA_ISONoAffectGroup   (1L << 5)
+#define        XkbSA_ISONoAffectPtr     (1L << 4)
+#define        XkbSA_ISONoAffectCtrls   (1L << 3)
+#define        XkbSA_ISOAffectMask      (0x78)
+
+#define        XkbSA_MessageOnPress     (1L << 0)
+#define        XkbSA_MessageOnRelease   (1L << 1)
+#define        XkbSA_MessageGenKeyEvent (1L << 2)
+
+#define        XkbSA_AffectDfltBtn     1
+#define        XkbSA_DfltBtnAbsolute   (1L << 2)
+
+#define        XkbSA_SwitchApplication (1L << 0)
+#define        XkbSA_SwitchAbsolute    (1L << 2)
+
+    /*
+     * The following values apply to the SA_DeviceValuator 
+     * action only.  Valuator operations specify the action 
+     * to be taken.   Values specified in the action are 
+     * multiplied by 2^scale before they are applied.
+     */
+#define        XkbSA_IgnoreVal         (0x00)
+#define        XkbSA_SetValMin         (0x10)
+#define        XkbSA_SetValCenter      (0x20)
+#define        XkbSA_SetValMax         (0x30)
+#define        XkbSA_SetValRelative    (0x40)
+#define        XkbSA_SetValAbsolute    (0x50)
+#define        XkbSA_ValOpMask         (0x70)
+#define        XkbSA_ValScaleMask      (0x07)
+#define        XkbSA_ValOp(a)          ((a)&XkbSA_ValOpMask)
+#define        XkbSA_ValScale(a)       ((a)&XkbSA_ValScaleMask)
+
+    /*
+     * Action types: specifies the type of a key action.  Reported in the
+     * type field of all key actions.
+     */
+#define        XkbSA_NoAction          0x00
+#define        XkbSA_SetMods           0x01
+#define        XkbSA_LatchMods         0x02
+#define        XkbSA_LockMods          0x03
+#define        XkbSA_SetGroup          0x04
+#define        XkbSA_LatchGroup        0x05
+#define        XkbSA_LockGroup         0x06
+#define        XkbSA_MovePtr           0x07
+#define        XkbSA_PtrBtn            0x08
+#define        XkbSA_LockPtrBtn        0x09
+#define        XkbSA_SetPtrDflt        0x0a
+#define        XkbSA_ISOLock           0x0b
+#define        XkbSA_Terminate         0x0c
+#define        XkbSA_SwitchScreen      0x0d
+#define        XkbSA_SetControls       0x0e
+#define        XkbSA_LockControls      0x0f
+#define        XkbSA_ActionMessage     0x10
+#define        XkbSA_RedirectKey       0x11
+#define        XkbSA_DeviceBtn         0x12
+#define        XkbSA_LockDeviceBtn     0x13
+#define        XkbSA_DeviceValuator    0x14
+#define        XkbSA_LastAction        XkbSA_DeviceValuator
+#define        XkbSA_NumActions        (XkbSA_LastAction+1)
+
+    /*
+     * Specifies the key actions that clear latched groups or modifiers.
+     */
+#define        XkbSA_BreakLatch \
+       ((1<<XkbSA_NoAction)|(1<<XkbSA_PtrBtn)|(1<<XkbSA_LockPtrBtn)|\
+       (1<<XkbSA_Terminate)|(1<<XkbSA_SwitchScreen)|(1<<XkbSA_SetControls)|\
+       (1<<XkbSA_LockControls)|(1<<XkbSA_ActionMessage)|\
+       (1<<XkbSA_RedirectKey)|(1<<XkbSA_DeviceBtn)|(1<<XkbSA_LockDeviceBtn))
+        
+    /*
+     * Macros to classify key actions
+     */
+#define        XkbIsModAction(a)       (((a)->type>=Xkb_SASetMods)&&((a)->type<=XkbSA_LockMods))
+#define        XkbIsGroupAction(a)     (((a)->type>=XkbSA_SetGroup)&&((a)->type<=XkbSA_LockGroup))
+#define        XkbIsPtrAction(a)       (((a)->type>=XkbSA_MovePtr)&&((a)->type<=XkbSA_SetPtrDflt))
+
+
+    /*
+     * Key Behavior Qualifier:
+     *    KB_Permanent indicates that the behavior describes an unalterable
+     *    characteristic of the keyboard, not an XKB software-simulation of
+     *    the listed behavior.
+     * Key Behavior Types:  
+     *    Specifies the behavior of the underlying key.
+     */
+#define        XkbKB_Permanent         0x80
+#define        XkbKB_OpMask            0x7f
+
+#define        XkbKB_Default           0x00
+#define        XkbKB_Lock              0x01
+#define        XkbKB_RadioGroup        0x02
+#define        XkbKB_Overlay1          0x03
+#define        XkbKB_Overlay2          0x04
+
+#define        XkbKB_RGAllowNone       0x80
+
+    /*
+     * Various macros which describe the range of legal keycodes.
+     */
+#define        XkbMinLegalKeyCode      8
+#define        XkbMaxLegalKeyCode      255
+#define        XkbMaxKeyCount          (XkbMaxLegalKeyCode-XkbMinLegalKeyCode+1)
+#define        XkbPerKeyBitArraySize   ((XkbMaxLegalKeyCode+1)/8)
+#define        XkbIsLegalKeycode(k)    (((k)>=XkbMinLegalKeyCode)&&((k)<=XkbMaxLegalKeyCode))
+
+    /*
+     * Assorted constants and limits.
+     */
+#define        XkbNumModifiers         8
+#define        XkbNumVirtualMods       16
+#define        XkbNumIndicators        32
+#define        XkbAllIndicatorsMask    (0xffffffff)
+#define        XkbMaxRadioGroups       32
+#define        XkbAllRadioGroupsMask   (0xffffffff)
+#define        XkbMaxShiftLevel        63
+#define        XkbMaxSymsPerKey        (XkbMaxShiftLevel*XkbNumKbdGroups)
+#define        XkbRGMaxMembers         12
+#define        XkbActionMessageLength  6
+#define        XkbKeyNameLength        4
+#define        XkbMaxRedirectCount     8
+
+#define        XkbGeomPtsPerMM         10
+#define        XkbGeomMaxColors        32
+#define        XkbGeomMaxLabelColors   3
+#define        XkbGeomMaxPriority      255
+
+    /*
+     * Key Type index and mask for the four standard key types.
+     */
+#define        XkbOneLevelIndex        0
+#define        XkbTwoLevelIndex        1
+#define        XkbAlphabeticIndex      2
+#define        XkbKeypadIndex          3
+#define        XkbLastRequiredType     XkbKeypadIndex
+#define        XkbNumRequiredTypes     (XkbLastRequiredType+1)
+#define        XkbMaxKeyTypes          255
+
+#define        XkbOneLevelMask         (1<<0)
+#define        XkbTwoLevelMask         (1<<1)
+#define        XkbAlphabeticMask       (1<<2)
+#define        XkbKeypadMask           (1<<3)
+#define        XkbAllRequiredTypes     (0xf)
+
+#define        XkbShiftLevel(n)        ((n)-1)
+#define        XkbShiftLevelMask(n)    (1<<((n)-1))
+
+    /*
+     * Extension name and version information
+     */
+#define        XkbName "XKEYBOARD"
+#define        XkbMajorVersion 1
+#define        XkbMinorVersion 0
+
+    /*
+     * Explicit map components:
+     *  - Used in the 'explicit' field of an XkbServerMap.  Specifies
+     *    the keyboard components that should _not_ be updated automatically
+     *    in response to core protocol keyboard mapping requests.
+     */
+#define        XkbExplicitKeyTypesMask   (0x0f)
+#define        XkbExplicitKeyType1Mask   (1<<0)
+#define        XkbExplicitKeyType2Mask   (1<<1)
+#define        XkbExplicitKeyType3Mask   (1<<2)
+#define        XkbExplicitKeyType4Mask   (1<<3)
+#define        XkbExplicitInterpretMask  (1<<4)
+#define        XkbExplicitAutoRepeatMask (1<<5)
+#define        XkbExplicitBehaviorMask   (1<<6)
+#define        XkbExplicitVModMapMask    (1<<7)
+#define        XkbAllExplicitMask        (0xff)
+
+    /*
+     * Map components masks:
+     * Those in AllMapComponentsMask:
+     *  - Specifies the individual fields to be loaded or changed for the
+     *    GetMap and SetMap requests.
+     * Those in ClientInfoMask:
+     *  - Specifies the components to be allocated by XkbAllocClientMap.
+     * Those in ServerInfoMask:
+     *  - Specifies the components to be allocated by XkbAllocServerMap.
+     */
+#define        XkbKeyTypesMask         (1<<0)
+#define        XkbKeySymsMask          (1<<1)
+#define        XkbModifierMapMask      (1<<2)
+#define        XkbExplicitComponentsMask (1<<3)
+#define XkbKeyActionsMask      (1<<4)
+#define        XkbKeyBehaviorsMask     (1<<5)
+#define        XkbVirtualModsMask      (1<<6)
+#define        XkbVirtualModMapMask    (1<<7)
+
+#define        XkbAllClientInfoMask    (XkbKeyTypesMask|XkbKeySymsMask|XkbModifierMapMask)
+#define        XkbAllServerInfoMask    (XkbExplicitComponentsMask|XkbKeyActionsMask|XkbKeyBehaviorsMask|XkbVirtualModsMask|XkbVirtualModMapMask)
+#define        XkbAllMapComponentsMask (XkbAllClientInfoMask|XkbAllServerInfoMask)
+
+    /*
+     * Symbol interpretations flags:
+     *  - Used in the flags field of a symbol interpretation
+     */
+#define        XkbSI_AutoRepeat        (1<<0)
+#define        XkbSI_LockingKey        (1<<1)
+
+    /*
+     * Symbol interpretations match specification:
+     *  - Used in the match field of a symbol interpretation to specify 
+     *    the conditions under which an interpretation is used.
+     */
+#define        XkbSI_LevelOneOnly      (0x80)
+#define        XkbSI_OpMask            (0x7f)
+#define        XkbSI_NoneOf            (0)
+#define        XkbSI_AnyOfOrNone       (1)
+#define        XkbSI_AnyOf             (2)
+#define        XkbSI_AllOf             (3)
+#define        XkbSI_Exactly           (4)
+
+    /*
+     * Indicator map flags:
+     *  - Used in the flags field of an indicator map to indicate the
+     *    conditions under which and indicator can be changed and the
+     *    effects of changing the indicator.
+     */
+#define        XkbIM_NoExplicit        (1L << 7)
+#define        XkbIM_NoAutomatic       (1L << 6)
+#define        XkbIM_LEDDrivesKB       (1L << 5)
+
+    /*
+     * Indicator map component specifications:
+     *  - Used by the 'which_groups' and 'which_mods' fields of an indicator
+     *    map to specify which keyboard components should be used to drive
+     *    the indicator.
+     */
+#define        XkbIM_UseBase           (1L << 0)
+#define        XkbIM_UseLatched        (1L << 1)
+#define        XkbIM_UseLocked         (1L << 2)
+#define        XkbIM_UseEffective      (1L << 3)
+#define        XkbIM_UseCompat         (1L << 4)
+
+#define        XkbIM_UseNone     0
+#define        XkbIM_UseAnyGroup (XkbIM_UseLatched|XkbIM_UseLocked|XkbIM_UseEffective)
+#define        XkbIM_UseAnyMods  (XkbIM_UseAnyGroup|XkbIM_UseCompat|XkbIM_UseBase)
+
+    /*
+     * Compatibility Map Compontents:
+     *  - Specifies the components to be allocated in XkbAllocCompatMap.
+     */
+#define        XkbSymInterpMask        (1<<0)
+#define        XkbGroupCompatMask      (1<<1)
+#define        XkbAllCompatMask        (0x3)
+
+    /*
+     * Names component mask:
+     *  - Specifies the names to be loaded or changed for the GetNames and
+     *    SetNames requests.
+     *  - Specifies the names that have changed in a NamesNotify event.
+     *  - Specifies the names components to be allocated by XkbAllocNames.
+     */
+#define        XkbKeycodesNameMask     (1<<0)
+#define        XkbGeometryNameMask     (1<<1)
+#define        XkbSymbolsNameMask      (1<<2)
+#define        XkbPhysSymbolsNameMask  (1<<3)
+#define        XkbTypesNameMask        (1<<4)
+#define        XkbCompatNameMask       (1<<5)
+#define        XkbKeyTypeNamesMask     (1<<6)
+#define        XkbKTLevelNamesMask     (1<<7)
+#define        XkbIndicatorNamesMask   (1<<8)
+#define        XkbKeyNamesMask         (1<<9)
+#define        XkbKeyAliasesMask       (1<<10)
+#define        XkbVirtualModNamesMask  (1<<11)
+#define        XkbGroupNamesMask       (1<<12)
+#define        XkbRGNamesMask          (1<<13)
+#define        XkbComponentNamesMask   (0x3f)
+#define        XkbAllNamesMask         (0x3fff)
+
+    /*
+     * GetByName components:
+     *  - Specifies desired or necessary components to GetKbdByName request.
+     *  - Reports the components that were found in a GetKbdByNameReply
+     */
+#define        XkbGBN_TypesMask                (1L << 0)
+#define        XkbGBN_CompatMapMask            (1L << 1)
+#define        XkbGBN_ClientSymbolsMask        (1L << 2)
+#define        XkbGBN_ServerSymbolsMask        (1L << 3)
+#define        XkbGBN_SymbolsMask (XkbGBN_ClientSymbolsMask|XkbGBN_ServerSymbolsMask)
+#define        XkbGBN_IndicatorMapMask         (1L << 4)
+#define        XkbGBN_KeyNamesMask             (1L << 5)
+#define        XkbGBN_GeometryMask             (1L << 6)
+#define        XkbGBN_OtherNamesMask           (1L << 7)
+#define        XkbGBN_AllComponentsMask        (0xff)
+
+     /*
+      * ListComponents flags
+      */
+#define        XkbLC_Hidden                    (1L <<  0)
+#define        XkbLC_Default                   (1L <<  1)
+#define        XkbLC_Partial                   (1L <<  2)
+
+#define        XkbLC_AlphanumericKeys          (1L <<  8)
+#define        XkbLC_ModifierKeys              (1L <<  9)
+#define        XkbLC_KeypadKeys                (1L << 10)
+#define        XkbLC_FunctionKeys              (1L << 11)
+#define        XkbLC_AlternateGroup            (1L << 12)
+
+    /*
+     * X Input Extension Interactions
+     * - Specifies the possible interactions between XKB and the X input
+     *   extension
+     * - Used to request (XkbGetDeviceInfo) or change (XKbSetDeviceInfo)
+     *   XKB information about an extension device.
+     * - Reports the list of supported optional features in the reply to
+     *   XkbGetDeviceInfo or in an XkbExtensionDeviceNotify event.
+     * XkbXI_UnsupportedFeature is reported in XkbExtensionDeviceNotify
+     * events to indicate an attempt to use an unsupported feature.
+     */
+#define        XkbXI_KeyboardsMask             (1L << 0)
+#define        XkbXI_ButtonActionsMask         (1L << 1)
+#define        XkbXI_IndicatorNamesMask        (1L << 2)
+#define        XkbXI_IndicatorMapsMask         (1L << 3)
+#define        XkbXI_IndicatorStateMask        (1L << 4)
+#define        XkbXI_UnsupportedFeatureMask    (1L << 15)
+#define        XkbXI_AllFeaturesMask           (0x001f)
+#define        XkbXI_AllDeviceFeaturesMask     (0x001e)
+
+#define        XkbXI_IndicatorsMask            (0x001c)
+#define        XkbAllExtensionDeviceEventsMask (0x801f)
+
+    /*
+     * Per-Client Flags:
+     *  - Specifies flags to be changed by the PerClientFlags request.
+     */
+#define        XkbPCF_DetectableAutoRepeatMask (1L << 0)
+#define        XkbPCF_GrabsUseXKBStateMask     (1L << 1)
+#define        XkbPCF_AutoResetControlsMask    (1L << 2)
+#define        XkbPCF_LookupStateWhenGrabbed   (1L << 3)
+#define        XkbPCF_SendEventUsesXKBState    (1L << 4)
+#define        XkbPCF_AllFlagsMask             (0x1F)
+
+    /*
+     * Debugging flags and controls
+     */
+#define        XkbDF_DisableLocks      (1<<0)
+
+#endif /* _XKB_H_ */
diff --git a/Xserver/include/extensions/XKBgeom.h b/Xserver/include/extensions/XKBgeom.h
new file mode 100644 (file)
index 0000000..7a02149
--- /dev/null
@@ -0,0 +1,745 @@
+/* $XConsortium: XKBgeom.h /main/7 1996/03/06 21:40:11 kaleb $ */
+/************************************************************
+Copyright (c) 1993 by Silicon Graphics Computer Systems, Inc.
+
+Permission to use, copy, modify, and distribute this
+software and its documentation for any purpose and without
+fee is hereby granted, provided that the above copyright
+notice appear in all copies and that both that copyright
+notice and this permission notice appear in supporting
+documentation, and that the name of Silicon Graphics not be 
+used in advertising or publicity pertaining to distribution 
+of the software without specific prior written permission.
+Silicon Graphics makes no representation about the suitability 
+of this software for any purpose. It is provided "as is"
+without any express or implied warranty.
+
+SILICON GRAPHICS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS 
+SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 
+AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
+GRAPHICS BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL 
+DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, 
+DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE 
+OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION  WITH
+THE USE OR PERFORMANCE OF THIS SOFTWARE.
+
+********************************************************/
+
+#ifndef _XKBGEOM_H_
+#define        _XKBGEOM_H_
+
+#ifdef XKB_IN_SERVER
+#define XkbAddGeomKeyAlias             SrvXkbAddGeomKeyAlias
+#define XkbAddGeomColor                SrvXkbAddGeomColor
+#define XkbAddGeomDoodad               SrvXkbAddGeomDoodad
+#define XkbAddGeomKey                  SrvXkbAddGeomKey
+#define XkbAddGeomOutline              SrvXkbAddGeomOutline
+#define XkbAddGeomOverlay              SrvXkbAddGeomOverlay
+#define XkbAddGeomOverlayRow           SrvXkbAddGeomOverlayRow
+#define        XkbAddGeomOverlayKey            SrvXkbAddGeomOverlayKey
+#define XkbAddGeomProperty             SrvXkbAddGeomProperty
+#define XkbAddGeomRow                  SrvXkbAddGeomRow
+#define XkbAddGeomSection              SrvXkbAddGeomSection
+#define XkbAddGeomShape                        SrvXkbAddGeomShape
+#define XkbAllocGeomKeyAliases         SrvXkbAllocGeomKeyAliases
+#define XkbAllocGeomColors             SrvXkbAllocGeomColors
+#define XkbAllocGeomDoodads            SrvXkbAllocGeomDoodads
+#define XkbAllocGeomKeys               SrvXkbAllocGeomKeys
+#define XkbAllocGeomOutlines           SrvXkbAllocGeomOutlines
+#define XkbAllocGeomPoints             SrvXkbAllocGeomPoints
+#define XkbAllocGeomProps              SrvXkbAllocGeomProps
+#define XkbAllocGeomRows               SrvXkbAllocGeomRows
+#define XkbAllocGeomSectionDoodads     SrvXkbAllocGeomSectionDoodads
+#define XkbAllocGeomSections           SrvXkbAllocGeomSections
+#define        XkbAllocGeomOverlays            SrvXkbAllocGeomOverlays
+#define        XkbAllocGeomOverlayRows         SrvXkbAllocGeomOverlayRows
+#define        XkbAllocGeomOverlayKeys         SrvXkbAllocGeomOverlayKeys
+#define XkbAllocGeomShapes             SrvXkbAllocGeomShapes
+#define XkbAllocGeometry               SrvXkbAllocGeometry
+#define XkbFreeGeomKeyAliases          SrvXkbFreeGeomKeyAliases
+#define XkbFreeGeomColors              SrvXkbFreeGeomColors
+#define XkbFreeGeomDoodads             SrvXkbFreeGeomDoodads
+#define XkbFreeGeomProperties          SrvXkbFreeGeomProperties
+#define        XkbFreeGeomOverlayKeys          SrvXkbFreeGeomOverlayKeys
+#define        XkbFreeGeomOverlayRows          SrvXkbFreeGeomOverlayRows
+#define        XkbFreeGeomOverlays             SrvXkbFreeGeomOverlays
+#define        XkbFreeGeomKeys                 SrvXKbFreeGeomKeys
+#define        XkbFreeGeomRows                 SrvXKbFreeGeomRows
+#define XkbFreeGeomSections            SrvXkbFreeGeomSections
+#define        XkbFreeGeomPoints               SrvXkbFreeGeomPoints
+#define        XkbFreeGeomOutlines             SrvXkbFreeGeomOutlines
+#define XkbFreeGeomShapes              SrvXkbFreeGeomShapes
+#define XkbFreeGeometry                        SrvXkbFreeGeometry
+#endif
+
+typedef        struct _XkbProperty {
+       char    *name;
+       char    *value;
+} XkbPropertyRec,*XkbPropertyPtr;
+
+typedef struct _XkbColor {
+       unsigned int    pixel;
+       char *          spec;
+} XkbColorRec,*XkbColorPtr;
+
+typedef        struct _XkbPoint {
+       short   x;
+       short   y;
+} XkbPointRec, *XkbPointPtr;
+
+typedef struct _XkbBounds {
+       short   x1,y1;
+       short   x2,y2;
+} XkbBoundsRec, *XkbBoundsPtr;
+#define        XkbBoundsWidth(b)       (((b)->x2)-((b)->x1))
+#define        XkbBoundsHeight(b)      (((b)->y2)-((b)->y1))
+
+typedef struct _XkbOutline {
+       unsigned short  num_points;
+       unsigned short  sz_points;
+       unsigned short  corner_radius;
+       XkbPointPtr     points;
+} XkbOutlineRec, *XkbOutlinePtr;
+
+typedef struct _XkbShape {
+       Atom             name;
+       unsigned short   num_outlines;
+       unsigned short   sz_outlines;
+       XkbOutlinePtr    outlines;
+       XkbOutlinePtr    approx;
+       XkbOutlinePtr    primary;
+       XkbBoundsRec     bounds;
+} XkbShapeRec, *XkbShapePtr;
+#define        XkbOutlineIndex(s,o)    ((o)-&(s)->outlines[0])
+
+typedef struct _XkbShapeDoodad {
+       Atom             name;
+       unsigned char    type;
+       unsigned char    priority;
+       short            top;
+       short            left;
+       short            angle;
+       unsigned short   color_ndx;
+       unsigned short   shape_ndx;
+} XkbShapeDoodadRec, *XkbShapeDoodadPtr;
+#define        XkbShapeDoodadColor(g,d)        (&(g)->colors[(d)->color_ndx])
+#define        XkbShapeDoodadShape(g,d)        (&(g)->shapes[(d)->shape_ndx])
+#define        XkbSetShapeDoodadColor(g,d,c)   ((d)->color_ndx= (c)-&(g)->colors[0])
+#define        XkbSetShapeDoodadShape(g,d,s)   ((d)->shape_ndx= (s)-&(g)->shapes[0])
+
+typedef struct _XkbTextDoodad {
+       Atom             name;
+       unsigned char    type;
+       unsigned char    priority;
+       short            top;
+       short            left;
+       short            angle;
+       short            width;
+       short            height;
+       unsigned short   color_ndx;
+       char *           text;
+       char *           font;
+} XkbTextDoodadRec, *XkbTextDoodadPtr;
+#define        XkbTextDoodadColor(g,d) (&(g)->colors[(d)->color_ndx])
+#define        XkbSetTextDoodadColor(g,d,c)    ((d)->color_ndx= (c)-&(g)->colors[0])
+
+typedef struct _XkbIndicatorDoodad {
+       Atom             name;
+       unsigned char    type;
+       unsigned char    priority;
+       short            top;
+       short            left;
+       short            angle;
+       unsigned short   shape_ndx;
+       unsigned short   on_color_ndx;
+       unsigned short   off_color_ndx;
+} XkbIndicatorDoodadRec, *XkbIndicatorDoodadPtr;
+#define        XkbIndicatorDoodadShape(g,d)    (&(g)->shapes[(d)->shape_ndx])
+#define        XkbIndicatorDoodadOnColor(g,d)  (&(g)->colors[(d)->on_color_ndx])
+#define        XkbIndicatorDoodadOffColor(g,d) (&(g)->colors[(d)->off_color_ndx])
+#define        XkbSetIndicatorDoodadOnColor(g,d,c) \
+                               ((d)->on_color_ndx= (c)-&(g)->colors[0])
+#define        XkbSetIndicatorDoodadOffColor(g,d,c) \
+                               ((d)->off_color_ndx= (c)-&(g)->colors[0])
+#define        XkbSetIndicatorDoodadShape(g,d,s) \
+                               ((d)->shape_ndx= (s)-&(g)->shapes[0])
+
+typedef struct _XkbLogoDoodad {
+       Atom             name;
+       unsigned char    type;
+       unsigned char    priority;
+       short            top;
+       short            left;
+       short            angle;
+       unsigned short   color_ndx;
+       unsigned short   shape_ndx;
+       char *           logo_name;
+} XkbLogoDoodadRec, *XkbLogoDoodadPtr;
+#define        XkbLogoDoodadColor(g,d)         (&(g)->colors[(d)->color_ndx])
+#define        XkbLogoDoodadShape(g,d)         (&(g)->shapes[(d)->shape_ndx])
+#define        XkbSetLogoDoodadColor(g,d,c)    ((d)->color_ndx= (c)-&(g)->colors[0])
+#define        XkbSetLogoDoodadShape(g,d,s)    ((d)->shape_ndx= (s)-&(g)->shapes[0])
+
+typedef struct _XkbAnyDoodad {
+       Atom             name;
+       unsigned char    type;
+       unsigned char    priority;
+       short            top;
+       short            left;
+       short            angle;
+} XkbAnyDoodadRec, *XkbAnyDoodadPtr;
+
+typedef union _XkbDoodad {
+       XkbAnyDoodadRec         any;
+       XkbShapeDoodadRec       shape;
+       XkbTextDoodadRec        text;
+       XkbIndicatorDoodadRec   indicator;
+       XkbLogoDoodadRec        logo;
+} XkbDoodadRec, *XkbDoodadPtr;
+
+#define        XkbUnknownDoodad        0
+#define        XkbOutlineDoodad        1
+#define        XkbSolidDoodad          2
+#define        XkbTextDoodad           3
+#define        XkbIndicatorDoodad      4
+#define        XkbLogoDoodad           5
+
+typedef struct _XkbKey {
+       XkbKeyNameRec    name;
+       short            gap;
+       unsigned char    shape_ndx;
+       unsigned char    color_ndx;
+} XkbKeyRec, *XkbKeyPtr;
+#define        XkbKeyShape(g,k)        (&(g)->shapes[(k)->shape_ndx])
+#define        XkbKeyColor(g,k)        (&(g)->colors[(k)->color_ndx])
+#define        XkbSetKeyShape(g,k,s)   ((k)->shape_ndx= (s)-&(g)->shapes[0])
+#define        XkbSetKeyColor(g,k,c)   ((k)->color_ndx= (c)-&(g)->colors[0])
+
+typedef struct _XkbRow {
+       short           top;
+       short           left;
+       unsigned short  num_keys;
+       unsigned short  sz_keys;
+       int             vertical;
+       XkbKeyPtr       keys;
+       XkbBoundsRec    bounds;
+} XkbRowRec, *XkbRowPtr;
+
+typedef struct _XkbSection {
+       Atom             name;
+       unsigned char    priority;
+       short            top;
+       short            left;
+       unsigned short   width;
+       unsigned short   height;
+       short            angle;
+       unsigned short   num_rows;
+       unsigned short   num_doodads;
+       unsigned short   num_overlays;
+       unsigned short   sz_rows;
+       unsigned short   sz_doodads;
+       unsigned short   sz_overlays;
+       XkbRowPtr        rows;
+       XkbDoodadPtr     doodads;
+       XkbBoundsRec     bounds;
+       struct _XkbOverlay *overlays;
+} XkbSectionRec, *XkbSectionPtr;
+
+typedef        struct _XkbOverlayKey {
+       XkbKeyNameRec   over;
+       XkbKeyNameRec   under;
+} XkbOverlayKeyRec,*XkbOverlayKeyPtr;
+
+typedef struct _XkbOverlayRow {
+       unsigned short          row_under;
+       unsigned short          num_keys;
+       unsigned short          sz_keys;
+       XkbOverlayKeyPtr        keys;
+} XkbOverlayRowRec,*XkbOverlayRowPtr;
+
+typedef struct _XkbOverlay {
+       Atom                    name;
+       XkbSectionPtr           section_under;
+       unsigned short          num_rows;
+       unsigned short          sz_rows;
+       XkbOverlayRowPtr        rows;
+       XkbBoundsPtr            bounds;
+} XkbOverlayRec,*XkbOverlayPtr;
+
+typedef struct _XkbGeometry {
+       Atom             name;
+       unsigned short   width_mm;
+       unsigned short   height_mm;
+       char *           label_font;
+       XkbColorPtr      label_color;
+       XkbColorPtr      base_color;
+       unsigned short   sz_properties;
+       unsigned short   sz_colors;
+       unsigned short   sz_shapes;
+       unsigned short   sz_sections;
+       unsigned short   sz_doodads;
+       unsigned short   sz_key_aliases;
+       unsigned short   num_properties;
+       unsigned short   num_colors;
+       unsigned short   num_shapes;
+       unsigned short   num_sections;
+       unsigned short   num_doodads;
+       unsigned short   num_key_aliases;
+       XkbPropertyPtr   properties;
+       XkbColorPtr      colors;
+       XkbShapePtr      shapes;
+       XkbSectionPtr    sections;
+       XkbDoodadPtr     doodads;
+       XkbKeyAliasPtr   key_aliases;
+} XkbGeometryRec;
+#define        XkbGeomColorIndex(g,c)  ((c)-&(g)->colors[0])
+
+#define        XkbGeomPropertiesMask   (1<<0)
+#define        XkbGeomColorsMask       (1<<1)
+#define        XkbGeomShapesMask       (1<<2)
+#define        XkbGeomSectionsMask     (1<<3)
+#define        XkbGeomDoodadsMask      (1<<4)
+#define        XkbGeomKeyAliasesMask   (1<<5)
+#define        XkbGeomAllMask          (0x3f)
+
+typedef struct _XkbGeometrySizes {
+       unsigned int    which;
+       unsigned short  num_properties;
+       unsigned short  num_colors;
+       unsigned short  num_shapes;
+       unsigned short  num_sections;
+       unsigned short  num_doodads;
+       unsigned short  num_key_aliases;
+} XkbGeometrySizesRec,*XkbGeometrySizesPtr;
+
+_XFUNCPROTOBEGIN
+
+extern XkbPropertyPtr
+XkbAddGeomProperty(
+#if NeedFunctionPrototypes
+    XkbGeometryPtr     /* geom */,
+    char *             /* name */,
+    char *             /* value */
+#endif
+);
+
+extern XkbKeyAliasPtr
+XkbAddGeomKeyAlias(
+#if NeedFunctionPrototypes
+    XkbGeometryPtr     /* geom */,
+    char *             /* alias */,
+    char *             /* real */
+#endif
+);
+
+extern XkbColorPtr
+XkbAddGeomColor(
+#if NeedFunctionPrototypes
+    XkbGeometryPtr     /* geom */,
+    char *             /* spec */,
+    unsigned int       /* pixel */
+#endif
+);
+
+extern XkbOutlinePtr
+XkbAddGeomOutline(
+#if NeedFunctionPrototypes
+    XkbShapePtr                /* shape */,
+    int                        /* sz_points */
+#endif
+);
+
+extern XkbShapePtr
+XkbAddGeomShape(
+#if NeedFunctionPrototypes
+    XkbGeometryPtr     /* geom */,
+    Atom               /* name */,
+    int                        /* sz_outlines */
+#endif
+);
+
+extern XkbKeyPtr
+XkbAddGeomKey(
+#if NeedFunctionPrototypes
+    XkbRowPtr          /* row */
+#endif
+);
+
+extern XkbRowPtr
+XkbAddGeomRow(
+#if NeedFunctionPrototypes
+    XkbSectionPtr      /* section */,
+    int                        /* sz_keys */
+#endif
+);
+
+extern XkbSectionPtr
+XkbAddGeomSection(
+#if NeedFunctionPrototypes
+    XkbGeometryPtr     /* geom */,
+    Atom               /* name */,
+    int                        /* sz_rows */,
+    int                        /* sz_doodads */,
+    int                        /* sz_overlays */
+#endif
+);
+
+extern XkbOverlayPtr
+XkbAddGeomOverlay(
+#if NeedFunctionPrototypes
+    XkbSectionPtr      /* section */,
+    Atom               /* name */,
+    int                        /* sz_rows */
+#endif
+);
+
+extern XkbOverlayRowPtr
+XkbAddGeomOverlayRow(
+#if NeedFunctionPrototypes
+    XkbOverlayPtr      /* overlay */,
+    int                        /* row_under */,
+    int                        /* sz_keys */
+#endif
+);
+
+extern XkbOverlayKeyPtr
+XkbAddGeomOverlayKey(
+#if NeedFunctionPrototypes
+    XkbOverlayPtr      /* overlay */,
+    XkbOverlayRowPtr   /* row */,
+    char *             /* over */,
+    char *             /* under */
+#endif
+);
+
+extern XkbDoodadPtr
+XkbAddGeomDoodad(
+#if NeedFunctionPrototypes
+    XkbGeometryPtr     /* geom */,
+    XkbSectionPtr      /* section */,
+    Atom               /* name */
+#endif
+);
+
+
+extern void
+XkbFreeGeomKeyAliases(
+#if NeedFunctionPrototypes
+    XkbGeometryPtr     /* geom */,
+    int                        /* first */,
+    int                        /* count */,
+    Bool               /* freeAll */
+#endif
+);
+
+extern void
+XkbFreeGeomColors(
+#if NeedFunctionPrototypes
+    XkbGeometryPtr     /* geom */,
+    int                        /* first */,
+    int                        /* count */,
+    Bool               /* freeAll */
+#endif
+);
+
+extern void
+XkbFreeGeomDoodads(
+#if NeedFunctionPrototypes
+    XkbDoodadPtr       /* doodads */,
+    int                        /* nDoodads */,
+    Bool               /* freeAll */
+#endif
+);
+
+
+extern void
+XkbFreeGeomProperties(
+#if NeedFunctionPrototypes
+    XkbGeometryPtr     /* geom */,
+    int                        /* first */,
+    int                        /* count */,
+    Bool               /* freeAll */
+#endif
+);
+
+extern void
+XkbFreeGeomOverlayKeys(
+#if NeedFunctionPrototypes
+    XkbOverlayRowPtr   /* row */,
+    int                        /* first */,
+    int                        /* count */,
+    Bool               /* freeAll */
+#endif
+);
+
+extern void
+XkbFreeGeomOverlayRows(
+#if NeedFunctionPrototypes
+    XkbOverlayPtr      /* overlay */,
+    int                        /* first */,
+    int                        /* count */,
+    Bool               /* freeAll */
+#endif
+);
+
+extern void
+XkbFreeGeomOverlays(
+#if NeedFunctionPrototypes
+    XkbSectionPtr      /* section */,
+    int                        /* first */,
+    int                        /* count */,
+    Bool               /* freeAll */
+#endif
+);
+
+extern void
+XkbFreeGeomKeys(
+#if NeedFunctionPrototypes
+    XkbRowPtr          /* row */,
+    int                        /* first */,
+    int                        /* count */,
+    Bool               /* freeAll */
+#endif
+);
+
+extern void
+XkbFreeGeomRows(
+#if NeedFunctionPrototypes
+    XkbSectionPtr      /* section */,
+    int                        /* first */,
+    int                        /* count */,
+    Bool               /* freeAll */
+#endif
+);
+
+extern void
+XkbFreeGeomSections(
+#if NeedFunctionPrototypes
+    XkbGeometryPtr     /* geom */,
+    int                        /* first */,
+    int                        /* count */,
+    Bool               /* freeAll */
+#endif
+);
+
+
+extern void
+XkbFreeGeomPoints(
+#if NeedFunctionPrototypes
+    XkbOutlinePtr      /* outline */,
+    int                        /* first */,
+    int                        /* count */,
+    Bool               /* freeAll */
+#endif
+);
+
+extern void
+XkbFreeGeomOutlines(
+#if NeedFunctionPrototypes
+    XkbShapePtr                /* shape */,
+    int                        /* first */,
+    int                        /* count */,
+    Bool               /* freeAll */
+#endif
+);
+
+extern void
+XkbFreeGeomShapes(
+#if NeedFunctionPrototypes
+    XkbGeometryPtr     /* geom */,
+    int                        /* first */,
+    int                        /* count */,
+    Bool               /* freeAll */
+#endif
+);
+
+extern void
+XkbFreeGeometry(
+#if NeedFunctionPrototypes
+    XkbGeometryPtr     /* geom */,
+    unsigned int       /* which */,
+    Bool               /* freeMap */
+#endif
+);
+
+extern Status
+XkbAllocGeomProps(
+#if NeedFunctionPrototypes
+    XkbGeometryPtr     /* geom */,
+    int                        /* nProps */
+#endif
+);
+
+extern Status
+XkbAllocGeomKeyAliases(
+#if NeedFunctionPrototypes
+    XkbGeometryPtr     /* geom */,
+    int                        /* nAliases */
+#endif
+);
+
+extern Status
+XkbAllocGeomColors(
+#if NeedFunctionPrototypes
+    XkbGeometryPtr     /* geom */,
+    int                        /* nColors */
+#endif
+);
+
+extern Status
+XkbAllocGeomShapes(
+#if NeedFunctionPrototypes
+    XkbGeometryPtr     /* geom */,
+    int                        /* nShapes */
+#endif
+);
+
+extern Status
+XkbAllocGeomSections(
+#if NeedFunctionPrototypes
+    XkbGeometryPtr     /* geom */,
+    int                        /* nSections */
+#endif
+);
+
+extern Status
+XkbAllocGeomOverlays(
+#if NeedFunctionPrototypes
+    XkbSectionPtr      /* section */,
+    int                        /* num_needed */
+#endif
+);
+
+extern Status
+XkbAllocGeomOverlayRows(
+#if NeedFunctionPrototypes
+    XkbOverlayPtr      /* overlay */,
+    int                        /* num_needed */
+#endif
+);
+
+extern Status
+XkbAllocGeomOverlayKeys(
+#if NeedFunctionPrototypes
+    XkbOverlayRowPtr   /* row */,
+    int                        /* num_needed */
+#endif
+);
+
+extern Status
+XkbAllocGeomDoodads(
+#if NeedFunctionPrototypes
+    XkbGeometryPtr     /* geom */,
+    int                        /* nDoodads */
+#endif
+);
+
+extern Status
+XkbAllocGeomSectionDoodads(
+#if NeedFunctionPrototypes
+    XkbSectionPtr      /* section */,
+    int                        /* nDoodads */
+#endif
+);
+
+extern Status
+XkbAllocGeomOutlines(
+#if NeedFunctionPrototypes
+    XkbShapePtr                /* shape */,
+    int                        /* nOL */
+#endif
+);
+
+extern Status
+XkbAllocGeomRows(
+#if NeedFunctionPrototypes
+    XkbSectionPtr      /* section */,
+    int                        /* nRows */
+#endif
+);
+
+extern Status
+XkbAllocGeomPoints(
+#if NeedFunctionPrototypes
+    XkbOutlinePtr      /* ol */,
+    int                        /* nPts */
+#endif
+);
+
+extern Status
+XkbAllocGeomKeys(
+#if NeedFunctionPrototypes
+    XkbRowPtr          /* row */,
+    int                        /* nKeys */
+#endif
+);
+
+extern Status
+XkbAllocGeometry(
+#if NeedFunctionPrototypes
+       XkbDescPtr              /* xkb */,
+       XkbGeometrySizesPtr     /* sizes */
+#endif
+);
+
+extern Bool
+XkbComputeShapeTop(
+#if NeedFunctionPrototypes
+       XkbShapePtr             /* shape */,
+       XkbBoundsPtr            /* bounds */
+#endif
+);
+
+extern Bool
+XkbComputeShapeBounds(
+#if NeedFunctionPrototypes
+       XkbShapePtr             /* shape */
+#endif
+);
+
+extern Bool
+XkbComputeRowBounds(
+#if NeedFunctionPrototypes
+       XkbGeometryPtr          /* geom */,
+       XkbSectionPtr           /* section */,
+       XkbRowPtr               /* row */
+#endif
+);
+
+extern Bool
+XkbComputeSectionBounds(
+#if NeedFunctionPrototypes
+       XkbGeometryPtr          /* geom */,
+       XkbSectionPtr           /* section */
+#endif
+);
+
+extern char *
+XkbFindOverlayForKey(
+#if NeedFunctionPrototypes
+       XkbGeometryPtr          /* geom */,
+       XkbSectionPtr           /* wanted */,
+       char *                  /* under */
+#endif
+);
+
+extern Status
+XkbGetGeometry(
+#if NeedFunctionPrototypes
+    Display *                  /* dpy */,
+    XkbDescPtr                 /* xkb */
+#endif
+);
+
+extern Status
+XkbGetNamedGeometry(
+#if NeedFunctionPrototypes
+    Display *                  /* dpy */,
+    XkbDescPtr                 /* xkb */,
+    Atom                       /* name */
+#endif
+);
+
+_XFUNCPROTOEND
+
+#endif /* _XKBSTR_H_ */
diff --git a/Xserver/include/extensions/XKBproto.h b/Xserver/include/extensions/XKBproto.h
new file mode 100644 (file)
index 0000000..82742bd
--- /dev/null
@@ -0,0 +1,1282 @@
+/* $XConsortium: XKBproto.h /main/22 1996/09/28 16:18:24 rws $ */
+/************************************************************
+Copyright (c) 1993 by Silicon Graphics Computer Systems, Inc.
+
+Permission to use, copy, modify, and distribute this
+software and its documentation for any purpose and without
+fee is hereby granted, provided that the above copyright
+notice appear in all copies and that both that copyright
+notice and this permission notice appear in supporting
+documentation, and that the name of Silicon Graphics not be 
+used in advertising or publicity pertaining to distribution 
+of the software without specific prior written permission.
+Silicon Graphics makes no representation about the suitability 
+of this software for any purpose. It is provided "as is"
+without any express or implied warranty.
+
+SILICON GRAPHICS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS 
+SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 
+AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
+GRAPHICS BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL 
+DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, 
+DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE 
+OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION  WITH
+THE USE OR PERFORMANCE OF THIS SOFTWARE.
+
+********************************************************/
+
+#ifndef _XKBPROTO_H_
+#define        _XKBPROTO_H_
+
+#include <X11/Xmd.h>
+#include <X11/extensions/XKB.h>
+
+#define Window CARD32
+#define Atom CARD32
+#define Time CARD32
+#define KeyCode CARD8
+#define KeySym CARD32
+
+#define        XkbPaddedSize(n)        ((((unsigned int)(n)+3) >> 2) << 2)
+
+typedef struct _xkbUseExtension {
+    CARD8      reqType;
+    CARD8      xkbReqType;     /* always X_KBUseExtension */
+    CARD16     length B16;
+    CARD16     wantedMajor B16;
+    CARD16     wantedMinor B16;
+} xkbUseExtensionReq;
+#define        sz_xkbUseExtensionReq   8
+
+typedef struct _xkbUseExtensionReply {
+    BYTE       type;           /* X_Reply */
+    BOOL       supported;
+    CARD16     sequenceNumber B16;
+    CARD32     length B32;
+    CARD16     serverMajor B16;
+    CARD16     serverMinor B16;
+    CARD32     pad1 B32;
+    CARD32     pad2 B32;
+    CARD32     pad3 B32;
+    CARD32     pad4 B32;
+    CARD32     pad5 B32;
+} xkbUseExtensionReply;
+#define        sz_xkbUseExtensionReply 32
+
+typedef        struct _xkbSelectEvents {
+    CARD8      reqType;
+    CARD8      xkbReqType;     /* X_KBSelectEvents */
+    CARD16     length B16;
+    CARD16     deviceSpec B16;
+    CARD16     affectWhich B16;
+    CARD16     clear B16;
+    CARD16     selectAll B16;
+    CARD16     affectMap B16;
+    CARD16     map B16;
+} xkbSelectEventsReq;
+#define        sz_xkbSelectEventsReq   16
+
+typedef struct _xkbBell {
+    CARD8      reqType;
+    CARD8      xkbReqType;     /* X_KBBell */
+    CARD16     length B16;
+    CARD16     deviceSpec B16;
+    CARD16     bellClass B16;
+    CARD16     bellID B16;
+    INT8       percent;
+    BOOL       forceSound;
+    BOOL       eventOnly;
+    CARD8      pad1;
+    INT16      pitch B16;
+    INT16      duration B16;
+    CARD16     pad2 B16;
+    Atom       name B32;
+    Window     window B32;
+} xkbBellReq;
+#define        sz_xkbBellReq           28
+
+typedef struct _xkbGetState {
+       CARD8           reqType;
+       CARD8           xkbReqType;     /* always X_KBGetState */
+       CARD16          length B16;
+       CARD16          deviceSpec B16;
+       CARD16          pad B16;
+} xkbGetStateReq;
+#define        sz_xkbGetStateReq       8
+
+typedef        struct _xkbGetStateReply {
+    BYTE       type;
+    BYTE       deviceID;
+    CARD16     sequenceNumber B16;
+    CARD32     length B32;
+    CARD8      mods;
+    CARD8      baseMods;
+    CARD8      latchedMods;
+    CARD8      lockedMods;
+    CARD8      group;
+    CARD8      lockedGroup;
+    INT16      baseGroup B16;
+    INT16      latchedGroup B16;
+    CARD8      compatState;
+    CARD8      grabMods;
+    CARD8      compatGrabMods;
+    CARD8      lookupMods;
+    CARD8      compatLookupMods;
+    CARD8      pad1;
+    CARD16     ptrBtnState B16;
+    CARD16     pad2 B16;
+    CARD32     pad3 B32;
+} xkbGetStateReply;
+#define        sz_xkbGetStateReply     32
+
+typedef struct _xkbLatchLockState {
+    CARD8      reqType;
+    CARD8      xkbReqType;     /* always X_KBLatchLockState */
+    CARD16     length B16;
+    CARD16     deviceSpec B16;
+    CARD8      affectModLocks;
+    CARD8      modLocks;
+    BOOL       lockGroup;
+    CARD8      groupLock;
+    CARD8      affectModLatches;
+    CARD8      modLatches;
+    CARD8      pad;
+    BOOL       latchGroup;
+    INT16      groupLatch B16;
+} xkbLatchLockStateReq;
+#define        sz_xkbLatchLockStateReq         16
+
+typedef struct _xkbGetControls {
+    CARD8      reqType;
+    CARD8      xkbReqType;     /* always X_KBGetControls */
+    CARD16     length B16;
+    CARD16     deviceSpec B16;
+    CARD16     pad B16;
+} xkbGetControlsReq;
+#define        sz_xkbGetControlsReq    8
+
+typedef struct _xkbGetControlsReply {
+    BYTE       type;           /* X_Reply */
+    CARD8      deviceID;
+    CARD16     sequenceNumber B16;
+    CARD32     length B32;
+    CARD8      mkDfltBtn;
+    CARD8      numGroups;
+    CARD8      groupsWrap;
+    CARD8      internalMods;
+    CARD8      ignoreLockMods;
+    CARD8      internalRealMods;
+    CARD8      ignoreLockRealMods;
+    CARD8      pad1;
+    CARD16     internalVMods B16;
+    CARD16     ignoreLockVMods B16;
+    CARD16     repeatDelay B16;
+    CARD16     repeatInterval B16;
+    CARD16     slowKeysDelay B16;
+    CARD16     debounceDelay B16;
+    CARD16     mkDelay B16;
+    CARD16     mkInterval B16;
+    CARD16     mkTimeToMax B16;
+    CARD16     mkMaxSpeed B16;
+    INT16      mkCurve B16;
+    CARD16     axOptions B16;
+    CARD16     axTimeout B16;
+    CARD16     axtOptsMask B16;
+    CARD16     axtOptsValues B16;
+    CARD16     pad2 B16;
+    CARD32     axtCtrlsMask B32;
+    CARD32     axtCtrlsValues B32;
+    CARD32     enabledCtrls B32;
+    BYTE       perKeyRepeat[XkbPerKeyBitArraySize];
+} xkbGetControlsReply;
+#define        sz_xkbGetControlsReply  92
+
+typedef struct _xkbSetControls {
+    CARD8      reqType;
+    CARD8      xkbReqType;     /* always X_KBSetControls */
+    CARD16     length B16;
+    CARD16     deviceSpec B16;
+    CARD8      affectInternalMods;
+    CARD8      internalMods;
+    CARD8      affectIgnoreLockMods;
+    CARD8      ignoreLockMods;
+    CARD16     affectInternalVMods B16;
+    CARD16     internalVMods B16;
+    CARD16     affectIgnoreLockVMods B16;
+    CARD16     ignoreLockVMods B16;
+    CARD8      mkDfltBtn;
+    CARD8      groupsWrap;
+    CARD16     axOptions B16;
+    CARD16     pad1 B16;
+    CARD32     affectEnabledCtrls B32;
+    CARD32     enabledCtrls B32;
+    CARD32     changeCtrls B32;
+    CARD16     repeatDelay B16;
+    CARD16     repeatInterval B16;
+    CARD16     slowKeysDelay B16;
+    CARD16     debounceDelay B16;
+    CARD16     mkDelay B16;
+    CARD16     mkInterval B16;
+    CARD16     mkTimeToMax B16;
+    CARD16     mkMaxSpeed B16;
+    INT16      mkCurve B16;
+    CARD16     axTimeout B16;
+    CARD32     axtCtrlsMask B32;
+    CARD32     axtCtrlsValues B32;
+    CARD16     axtOptsMask B16;
+    CARD16     axtOptsValues B16;
+    BYTE       perKeyRepeat[XkbPerKeyBitArraySize];
+} xkbSetControlsReq;
+#define        sz_xkbSetControlsReq    100
+
+typedef        struct _xkbKTMapEntryWireDesc {
+    BOOL       active;
+    CARD8      mask;
+    CARD8      level;
+    CARD8      realMods;
+    CARD16     virtualMods B16;
+    CARD16     pad B16;
+} xkbKTMapEntryWireDesc;
+#define sz_xkbKTMapEntryWireDesc       8
+
+typedef struct _xkbKTSetMapEntryWireDesc {
+    CARD8      level;
+    CARD8      realMods;
+    CARD16     virtualMods B16;
+} xkbKTSetMapEntryWireDesc;
+#define        sz_xkbKTSetMapEntryWireDesc     4
+
+typedef struct _xkbModsWireDesc {
+    CARD8      mask;           /* GetMap only */
+    CARD8      realMods;
+    CARD16     virtualMods B16;
+} xkbModsWireDesc;
+#define        sz_xkbModsWireDesc      4
+
+typedef struct _xkbKeyTypeWireDesc {
+    CARD8      mask;
+    CARD8      realMods;
+    CARD16     virtualMods B16;
+    CARD8      numLevels;
+    CARD8      nMapEntries;
+    BOOL       preserve;
+    CARD8      pad;
+} xkbKeyTypeWireDesc;
+#define        sz_xkbKeyTypeWireDesc   8
+
+typedef struct _xkbSymMapWireDesc {
+    CARD8      ktIndex[XkbNumKbdGroups];
+    CARD8      groupInfo;
+    CARD8      width;
+    CARD16     nSyms B16;
+} xkbSymMapWireDesc;
+#define        sz_xkbSymMapWireDesc    8
+
+typedef struct _xkbVModMapWireDesc {
+    KeyCode    key;
+    CARD8      pad;
+    CARD16     vmods B16;
+} xkbVModMapWireDesc;
+#define        sz_xkbVModMapWireDesc   4
+
+typedef struct _xkbBehaviorWireDesc {
+       CARD8   key;
+       CARD8   type;
+       CARD8   data;
+       CARD8   pad;
+} xkbBehaviorWireDesc;
+#define        sz_xkbBehaviorWireDesc  4
+
+typedef        struct _xkbActionWireDesc {
+    CARD8      type;
+    CARD8      data[7];
+} xkbActionWireDesc;
+#define        sz_xkbActionWireDesc    8
+
+typedef struct _xkbGetMap {
+    CARD8      reqType;
+    CARD8      xkbReqType;     /* always X_KBGetMap */
+    CARD16     length B16;
+    CARD16     deviceSpec B16;
+    CARD16     full B16;
+    CARD16     partial B16;
+    CARD8      firstType;
+    CARD8      nTypes;
+    KeyCode    firstKeySym;
+    CARD8      nKeySyms;
+    KeyCode    firstKeyAct;
+    CARD8      nKeyActs;
+    KeyCode    firstKeyBehavior;
+    CARD8      nKeyBehaviors;
+    CARD16     virtualMods B16;
+    KeyCode    firstKeyExplicit;
+    CARD8      nKeyExplicit;
+    KeyCode    firstModMapKey;
+    CARD8      nModMapKeys;
+    KeyCode    firstVModMapKey;
+    CARD8      nVModMapKeys;
+    CARD16     pad1 B16;
+} xkbGetMapReq;
+#define        sz_xkbGetMapReq 28
+
+typedef struct _xkbGetMapReply {
+    CARD8      type;           /* always X_Reply */
+    CARD8      deviceID;
+    CARD16     sequenceNumber B16;
+    CARD32     length B32;
+    CARD16     pad1 B16;
+    KeyCode    minKeyCode;
+    KeyCode    maxKeyCode;
+    CARD16     present B16;
+    CARD8      firstType;
+    CARD8      nTypes;
+    CARD8      totalTypes;
+    KeyCode    firstKeySym;
+    CARD16     totalSyms B16;
+    CARD8      nKeySyms;
+    KeyCode    firstKeyAct;
+    CARD16     totalActs B16;
+    CARD8      nKeyActs;
+    KeyCode    firstKeyBehavior;
+    CARD8      nKeyBehaviors;
+    CARD8      totalKeyBehaviors;
+    KeyCode    firstKeyExplicit;
+    CARD8      nKeyExplicit;
+    CARD8      totalKeyExplicit;
+    KeyCode    firstModMapKey;
+    CARD8      nModMapKeys;
+    CARD8      totalModMapKeys;
+    KeyCode    firstVModMapKey;
+    CARD8      nVModMapKeys;
+    CARD8      totalVModMapKeys;
+    CARD8      pad2;
+    CARD16     virtualMods B16;
+} xkbGetMapReply;
+#define        sz_xkbGetMapReply               40
+
+#define        XkbSetMapResizeTypes            (1L<<0)
+#define        XkbSetMapRecomputeActions       (1L<<1)
+#define        XkbSetMapAllFlags               (0x3)
+
+typedef struct _xkbSetMap {
+    CARD8      reqType;
+    CARD8      xkbReqType;     /* always X_KBSetMap */
+    CARD16     length B16;
+    CARD16     deviceSpec B16;
+    CARD16     present B16;
+    CARD16     flags B16;
+    KeyCode    minKeyCode;
+    KeyCode    maxKeyCode;
+    CARD8      firstType;
+    CARD8      nTypes;
+    KeyCode    firstKeySym;
+    CARD8      nKeySyms;
+    CARD16     totalSyms B16;
+    KeyCode    firstKeyAct;
+    CARD8      nKeyActs;
+    CARD16     totalActs B16;
+    KeyCode    firstKeyBehavior;
+    CARD8      nKeyBehaviors;
+    CARD8      totalKeyBehaviors;
+    KeyCode    firstKeyExplicit;
+    CARD8      nKeyExplicit;
+    CARD8      totalKeyExplicit;
+    KeyCode    firstModMapKey;
+    CARD8      nModMapKeys;
+    CARD8      totalModMapKeys;
+    KeyCode    firstVModMapKey;
+    CARD8      nVModMapKeys;
+    CARD8      totalVModMapKeys;
+    CARD16     virtualMods B16;
+} xkbSetMapReq;
+#define        sz_xkbSetMapReq 36
+
+typedef struct _xkbSymInterpretWireDesc {
+    CARD32             sym B32;
+    CARD8              mods;
+    CARD8              match;
+    CARD8              virtualMod;
+    CARD8              flags;
+    xkbActionWireDesc  act;
+} xkbSymInterpretWireDesc;
+#define        sz_xkbSymInterpretWireDesc      16
+
+typedef struct _xkbGetCompatMap {
+    CARD8      reqType;
+    CARD8      xkbReqType;     /* always X_KBGetCompatMap */
+    CARD16     length B16;
+    CARD16     deviceSpec B16;
+    CARD8      groups;
+    BOOL       getAllSI;
+    CARD16     firstSI B16;
+    CARD16     nSI B16;
+} xkbGetCompatMapReq;
+#define        sz_xkbGetCompatMapReq   12
+
+typedef struct _xkbGetCompatMapReply {
+    CARD8      type;           /* always X_Reply */
+    CARD8      deviceID;
+    CARD16     sequenceNumber B16;
+    CARD32     length B32;
+    CARD8      groups;
+    CARD8      pad1;
+    CARD16     firstSI B16;
+    CARD16     nSI B16;
+    CARD16     nTotalSI B16;
+    CARD32     pad2 B32;
+    CARD32     pad3 B32;
+    CARD32     pad4 B32;
+    CARD32     pad5 B32;
+} xkbGetCompatMapReply;
+#define        sz_xkbGetCompatMapReply         32
+
+typedef struct _xkbSetCompatMap {
+    CARD8      reqType;
+    CARD8      xkbReqType;     /* always X_KBSetCompatMap */
+    CARD16     length B16;
+    CARD16     deviceSpec B16;
+    CARD8      pad1;
+    BOOL       recomputeActions;
+    BOOL       truncateSI;
+    CARD8      groups;
+    CARD16     firstSI B16;
+    CARD16     nSI B16;
+    CARD16     pad2 B16;
+} xkbSetCompatMapReq;
+#define        sz_xkbSetCompatMapReq   16
+
+typedef struct _xkbGetIndicatorState {
+    CARD8      reqType;
+    CARD8      xkbReqType;     /* always X_KBGetIndicatorState */
+    CARD16     length B16;
+    CARD16     deviceSpec B16;
+    CARD16     pad1 B16;
+} xkbGetIndicatorStateReq;
+#define        sz_xkbGetIndicatorStateReq      8
+
+typedef struct _xkbGetIndicatorStateReply {
+    CARD8      type;           /* always X_Reply */
+    CARD8      deviceID;
+    CARD16     sequenceNumber B16;
+    CARD32     length B32;
+    CARD32     state B32;
+    CARD32     pad1 B32;
+    CARD32     pad2 B32;
+    CARD32     pad3 B32;
+    CARD32     pad4 B32;
+    CARD32     pad5 B32;
+} xkbGetIndicatorStateReply;
+#define        sz_xkbGetIndicatorStateReply    32
+
+typedef struct _xkbGetIndicatorMap {
+    CARD8      reqType;
+    CARD8      xkbReqType;     /* always X_KBGetIndicatorMap */
+    CARD16     length B16;
+    CARD16     deviceSpec B16;
+    CARD16     pad B16;
+    CARD32     which B32;
+} xkbGetIndicatorMapReq;
+#define        sz_xkbGetIndicatorMapReq        12
+
+typedef struct _xkbGetIndicatorMapReply {
+    CARD8      type;           /* always X_Reply */
+    CARD8      deviceID;
+    CARD16     sequenceNumber B16;
+    CARD32     length B32;
+    CARD32     which B32;
+    CARD32     realIndicators B32;
+    CARD8      nIndicators;
+    CARD8      pad1;
+    CARD16     pad2 B16;
+    CARD32     pad3 B32;
+    CARD32     pad4 B32;
+    CARD32     pad5 B32;
+} xkbGetIndicatorMapReply;
+#define        sz_xkbGetIndicatorMapReply      32
+
+typedef struct _xkbIndicatorMapWireDesc {
+    CARD8      flags;
+    CARD8      whichGroups;
+    CARD8      groups;
+    CARD8      whichMods;
+    CARD8      mods;
+    CARD8      realMods;
+    CARD16     virtualMods B16;
+    CARD32     ctrls B32;
+} xkbIndicatorMapWireDesc;
+#define        sz_xkbIndicatorMapWireDesc      12
+
+typedef struct _xkbSetIndicatorMap {
+    CARD8      reqType;
+    CARD8      xkbReqType;     /* always X_KBSetIndicatorMap */
+    CARD16     length B16;
+    CARD16     deviceSpec B16;
+    CARD16     pad1 B16;
+    CARD32     which B32;
+} xkbSetIndicatorMapReq;
+#define        sz_xkbSetIndicatorMapReq        12
+
+typedef struct _xkbGetNamedIndicator {
+    CARD8      reqType;
+    CARD8      xkbReqType;     /* X_KBGetNamedIndicator */
+    CARD16     length B16;
+    CARD16     deviceSpec B16;
+    CARD16     ledClass B16;
+    CARD16     ledID B16;
+    CARD16     pad1 B16;
+    Atom       indicator B32;
+} xkbGetNamedIndicatorReq;
+#define        sz_xkbGetNamedIndicatorReq              16
+
+typedef        struct _xkbGetNamedIndicatorReply {
+    BYTE       type;
+    BYTE       deviceID;
+    CARD16     sequenceNumber B16;
+    CARD32     length B32;
+    Atom       indicator B32;
+    BOOL       found;
+    BOOL       on;
+    BOOL       realIndicator;
+    CARD8      ndx;
+    CARD8      flags;
+    CARD8      whichGroups;
+    CARD8      groups;
+    CARD8      whichMods;
+    CARD8      mods;
+    CARD8      realMods;
+    CARD16     virtualMods B16;
+    CARD32     ctrls B32;
+    BOOL       supported;
+    CARD8      pad1;
+    CARD16     pad2 B16;
+} xkbGetNamedIndicatorReply;
+#define        sz_xkbGetNamedIndicatorReply    32
+
+typedef struct _xkbSetNamedIndicator {
+    CARD8      reqType;
+    CARD8      xkbReqType;     /* X_KBSetNamedIndicator */
+    CARD16     length B16;
+    CARD16     deviceSpec B16;
+    CARD16     ledClass B16;
+    CARD16     ledID B16;
+    CARD16     pad1 B16;
+    Atom       indicator B32;
+    BOOL       setState;
+    BOOL       on;
+    BOOL       setMap;
+    BOOL       createMap;
+    CARD8      pad2;
+    CARD8      flags;
+    CARD8      whichGroups;
+    CARD8      groups;
+    CARD8      whichMods;
+    CARD8      realMods;
+    CARD16     virtualMods B16;
+    CARD32     ctrls B32;
+} xkbSetNamedIndicatorReq;
+#define        sz_xkbSetNamedIndicatorReq      32
+
+typedef struct _xkbGetNames {
+    CARD8      reqType;
+    CARD8      xkbReqType;     /* always X_KBGetNames */
+    CARD16     length B16;
+    CARD16     deviceSpec B16;
+    CARD16     pad B16;
+    CARD32     which B32;
+} xkbGetNamesReq;
+#define        sz_xkbGetNamesReq               12
+
+typedef        struct _xkbGetNamesReply {
+    BYTE       type;
+    BYTE       deviceID;
+    CARD16     sequenceNumber B16;
+    CARD32     length B32;
+    CARD32     which B32;
+    KeyCode    minKeyCode;
+    KeyCode    maxKeyCode;
+    CARD8      nTypes;
+    CARD8      groupNames;
+    CARD16     virtualMods B16;
+    KeyCode    firstKey;
+    CARD8      nKeys;
+    CARD32     indicators B32;
+    CARD8      nRadioGroups;
+    CARD8      nKeyAliases;
+    CARD16     nKTLevels B16;
+    CARD32     pad3 B32;
+} xkbGetNamesReply;
+#define        sz_xkbGetNamesReply     32
+
+typedef struct _xkbSetNames {
+    CARD8      reqType;
+    CARD8      xkbReqType;     /* always X_KBSetNames */
+    CARD16     length B16;
+    CARD16     deviceSpec B16;
+    CARD16     virtualMods B16;
+    CARD32     which B32;
+    CARD8      firstType;
+    CARD8      nTypes;
+    CARD8      firstKTLevel;
+    CARD8      nKTLevels;
+    CARD32     indicators B32;
+    CARD8      groupNames;
+    CARD8      nRadioGroups;
+    KeyCode    firstKey;
+    CARD8      nKeys;
+    CARD8      nKeyAliases;
+    CARD8      pad1;
+    CARD16     totalKTLevelNames B16;
+} xkbSetNamesReq;
+#define        sz_xkbSetNamesReq       28
+
+typedef struct _xkbPointWireDesc {
+    INT16      x B16;
+    INT16      y B16;
+} xkbPointWireDesc;
+#define        sz_xkbPointWireDesc     4
+
+typedef struct _xkbOutlineWireDesc {
+    CARD8      nPoints;
+    CARD8      cornerRadius;
+    CARD16     pad B16;
+} xkbOutlineWireDesc;
+#define        sz_xkbOutlineWireDesc   4
+
+typedef struct _xkbShapeWireDesc {
+    Atom       name B32;
+    CARD8      nOutlines;
+    CARD8      primaryNdx;
+    CARD8      approxNdx;
+    CARD8      pad;
+} xkbShapeWireDesc;
+#define        sz_xkbShapeWireDesc     8
+
+typedef struct _xkbSectionWireDesc {
+    Atom       name B32;
+    INT16      top B16;
+    INT16      left B16;
+    CARD16     width B16;
+    CARD16     height B16;
+    INT16      angle B16;
+    CARD8      priority;
+    CARD8      nRows;
+    CARD8      nDoodads;
+    CARD8      nOverlays;
+    CARD16     pad B16;
+} xkbSectionWireDesc;
+#define        sz_xkbSectionWireDesc   20
+
+typedef struct _xkbRowWireDesc {
+    INT16      top B16;
+    INT16      left B16;
+    CARD8      nKeys;
+    BOOL       vertical;
+    CARD16     pad B16;
+} xkbRowWireDesc;
+#define        sz_xkbRowWireDesc       8
+
+typedef struct _xkbKeyWireDesc {
+    CARD8      name[XkbKeyNameLength];
+    INT16      gap B16;
+    CARD8      shapeNdx;
+    CARD8      colorNdx;
+} xkbKeyWireDesc;
+#define        sz_xkbKeyWireDesc       8
+
+typedef struct _xkbOverlayWireDesc {
+    Atom       name B32;
+    CARD8      nRows;
+    CARD8      pad1;
+    CARD16     pad2 B16;
+} xkbOverlayWireDesc;
+#define        sz_xkbOverlayWireDesc   8
+
+typedef struct _xkbOverlayRowWireDesc {
+   CARD8       rowUnder;
+   CARD8       nKeys;
+   CARD16      pad1 B16;
+} xkbOverlayRowWireDesc;
+#define        sz_xkbOverlayRowWireDesc        4
+
+typedef struct _xkbOverlayKeyWireDesc {
+   CARD8       over[XkbKeyNameLength];
+   CARD8       under[XkbKeyNameLength];
+} xkbOverlayKeyWireDesc;
+#define        sz_xkbOverlayKeyWireDesc        8
+
+typedef struct _xkbShapeDoodadWireDesc {
+    Atom       name B32;
+    CARD8      type;
+    CARD8      priority;
+    INT16      top B16;
+    INT16      left B16;
+    INT16      angle B16;
+    CARD8      colorNdx;
+    CARD8      shapeNdx;
+    CARD16     pad1 B16;
+    CARD32     pad2 B32;
+} xkbShapeDoodadWireDesc;
+#define        sz_xkbShapeDoodadWireDesc       20
+
+typedef struct _xkbTextDoodadWireDesc {
+    Atom       name B32;
+    CARD8      type;
+    CARD8      priority;
+    INT16      top B16;
+    INT16      left B16;
+    INT16      angle B16;
+    CARD16     width B16;
+    CARD16     height B16;
+    CARD8      colorNdx;
+    CARD8      pad1;
+    CARD16     pad2 B16;
+} xkbTextDoodadWireDesc;
+#define        sz_xkbTextDoodadWireDesc        20
+
+typedef struct _xkbIndicatorDoodadWireDesc {
+    Atom       name B32;
+    CARD8      type;
+    CARD8      priority;
+    INT16      top B16;
+    INT16      left B16;
+    INT16      angle B16;
+    CARD8      shapeNdx;
+    CARD8      onColorNdx;
+    CARD8      offColorNdx;
+    CARD8      pad1;
+    CARD32     pad2 B32;
+} xkbIndicatorDoodadWireDesc;
+#define        sz_xkbIndicatorDoodadWireDesc   20
+
+typedef struct _xkbLogoDoodadWireDesc {
+    Atom       name B32;
+    CARD8      type;
+    CARD8      priority;
+    INT16      top B16;
+    INT16      left B16;
+    INT16      angle B16;
+    CARD8      colorNdx;
+    CARD8      shapeNdx;
+    CARD16     pad1 B16;
+    CARD32     pad2 B32;
+} xkbLogoDoodadWireDesc;
+#define        sz_xkbLogoDoodadWireDesc        20
+
+typedef struct _xkbAnyDoodadWireDesc {
+    Atom       name B32;
+    CARD8      type;
+    CARD8      priority;
+    INT16      top B16;
+    INT16      left B16;
+    INT16      angle B16;
+    CARD32     pad2 B32;
+    CARD32     pad3 B32;
+} xkbAnyDoodadWireDesc;
+#define        sz_xkbAnyDoodadWireDesc 20
+
+typedef union _xkbDoodadWireDesc {
+    xkbAnyDoodadWireDesc       any;
+    xkbShapeDoodadWireDesc     shape;
+    xkbTextDoodadWireDesc      text;
+    xkbIndicatorDoodadWireDesc indicator;
+    xkbLogoDoodadWireDesc      logo;
+} xkbDoodadWireDesc;
+#define        sz_xkbDoodadWireDesc    20
+
+typedef struct _xkbGetGeometry {
+    CARD8      reqType;
+    CARD8      xkbReqType;     /* always X_KBGetGeometry */
+    CARD16     length B16;
+    CARD16     deviceSpec B16;
+    CARD16     pad B16;
+    Atom       name B32;
+} xkbGetGeometryReq;
+#define        sz_xkbGetGeometryReq    12
+
+typedef struct _xkbGetGeometryReply {
+    CARD8      type;           /* always X_Reply */
+    CARD8      deviceID;
+    CARD16     sequenceNumber B16;
+    CARD32     length B32;
+    Atom       name B32;
+    BOOL       found;
+    CARD8      pad;
+    CARD16     widthMM B16;
+    CARD16     heightMM B16;
+    CARD16     nProperties B16;
+    CARD16     nColors B16;
+    CARD16     nShapes B16;
+    CARD16     nSections B16;
+    CARD16     nDoodads B16;
+    CARD16     nKeyAliases B16;
+    CARD8      baseColorNdx;
+    CARD8      labelColorNdx;
+} xkbGetGeometryReply;
+#define        sz_xkbGetGeometryReply  32
+
+typedef struct _xkbSetGeometry {
+    CARD8      reqType;
+    CARD8      xkbReqType;     /* always X_KBSetGeometry */
+    CARD16     length B16;
+    CARD16     deviceSpec B16;
+    CARD8      nShapes;
+    CARD8      nSections;
+    Atom       name B32;
+    CARD16     widthMM B16;
+    CARD16     heightMM B16;
+    CARD16     nProperties B16;
+    CARD16     nColors B16;
+    CARD16     nDoodads B16;
+    CARD16     nKeyAliases B16;
+    CARD8      baseColorNdx;
+    CARD8      labelColorNdx;
+    CARD16     pad B16;
+} xkbSetGeometryReq;
+#define        sz_xkbSetGeometryReq    28
+
+typedef struct _xkbPerClientFlags {
+    CARD8      reqType;
+    CARD8      xkbReqType;/* always X_KBPerClientFlags */
+    CARD16     length B16;
+    CARD16     deviceSpec B16;
+    CARD16     pad1 B16;
+    CARD32     change B32;
+    CARD32     value B32;
+    CARD32     ctrlsToChange B32;
+    CARD32     autoCtrls B32;
+    CARD32     autoCtrlValues B32;
+} xkbPerClientFlagsReq;
+#define        sz_xkbPerClientFlagsReq 28
+
+typedef struct _xkbPerClientFlagsReply {
+    CARD8      type;           /* always X_Reply */
+    CARD8      deviceID;
+    CARD16     sequenceNumber B16;
+    CARD32     length B32;
+    CARD32     supported B32;
+    CARD32     value B32;
+    CARD32     autoCtrls B32;
+    CARD32     autoCtrlValues B32;
+    CARD32     pad1 B32;
+    CARD32     pad2 B32;
+} xkbPerClientFlagsReply;
+#define        sz_xkbPerClientFlagsReply       32
+
+typedef struct _xkbListComponents {
+    CARD8      reqType;
+    CARD8      xkbReqType;     /* always X_KBListComponents */
+    CARD16     length B16;
+    CARD16     deviceSpec B16;
+    CARD16     maxNames B16;
+} xkbListComponentsReq;
+#define        sz_xkbListComponentsReq 8
+
+typedef struct _xkbListComponentsReply {
+    CARD8      type;           /* always X_Reply */
+    CARD8      deviceID;
+    CARD16     sequenceNumber B16;
+    CARD32     length B32;
+    CARD16     nKeymaps B16;
+    CARD16     nKeycodes B16;
+    CARD16     nTypes B16;
+    CARD16     nCompatMaps B16;
+    CARD16     nSymbols B16;
+    CARD16     nGeometries B16;
+    CARD16     extra B16;
+    CARD16     pad1 B16;
+    CARD32     pad2 B32;
+    CARD32     pad3 B32;
+} xkbListComponentsReply;
+#define        sz_xkbListComponentsReply       32
+
+typedef struct _xkbGetKbdByName {
+    CARD8      reqType;
+    CARD8      xkbReqType;     /* always X_KBGetKbdByName */
+    CARD16     length B16;
+    CARD16     deviceSpec B16;
+    CARD16     need B16;       /* combination of XkbGBN_* */
+    CARD16     want B16;       /* combination of XkbGBN_* */
+    BOOL       load;
+    CARD8      pad;
+} xkbGetKbdByNameReq;
+#define        sz_xkbGetKbdByNameReq   12
+
+typedef struct _xkbGetKbdByNameReply {
+    CARD8      type;           /* always X_Reply */
+    CARD8      deviceID;
+    CARD16     sequenceNumber B16;
+    CARD32     length B32;
+    KeyCode    minKeyCode;
+    KeyCode    maxKeyCode;
+    BOOL       loaded;
+    BOOL       newKeyboard;
+    CARD16     found B16;      /* combination of XkbGBN_* */
+    CARD16     reported B16;   /* combination of XkbAllComponents */
+    CARD32     pad1 B32;
+    CARD32     pad2 B32;
+    CARD32     pad3 B32;
+    CARD32     pad4 B32;
+} xkbGetKbdByNameReply;
+#define        sz_xkbGetKbdByNameReply 32
+
+typedef        struct _xkbDeviceLedsWireDesc {
+    CARD16     ledClass B16;
+    CARD16     ledID B16;
+    CARD32     namesPresent B32;
+    CARD32     mapsPresent B32;
+    CARD32     physIndicators B32;
+    CARD32     state B32;
+} xkbDeviceLedsWireDesc;
+#define sz_xkbDeviceLedsWireDesc       20
+
+typedef struct _xkbGetDeviceInfo {
+    CARD8      reqType;
+    CARD8      xkbReqType;     /* always X_KBGetDeviceInfo */
+    CARD16     length B16;
+    CARD16     deviceSpec B16;
+    CARD16     wanted B16;
+    BOOL       allBtns;
+    CARD8      firstBtn;
+    CARD8      nBtns;
+    CARD8      pad;
+    CARD16     ledClass B16;
+    CARD16     ledID B16;
+} xkbGetDeviceInfoReq;
+#define        sz_xkbGetDeviceInfoReq  16
+
+typedef struct _xkbGetDeviceInfoReply {
+    CARD8      type;           /* always X_Reply */
+    CARD8      deviceID;
+    CARD16     sequenceNumber B16;
+    CARD32     length B32;
+    CARD16     present B16;
+    CARD16     supported B16;
+    CARD16     unsupported B16;
+    CARD16     nDeviceLedFBs B16;
+    CARD8      firstBtnWanted;
+    CARD8      nBtnsWanted;
+    CARD8      firstBtnRtrn;
+    CARD8      nBtnsRtrn;
+    CARD8      totalBtns;
+    BOOL       hasOwnState;
+    CARD16     dfltKbdFB B16;
+    CARD16     dfltLedFB B16;
+    CARD16     pad B16;
+    Atom       devType B32;
+} xkbGetDeviceInfoReply;
+#define        sz_xkbGetDeviceInfoReply        32
+
+typedef struct _xkbSetDeviceInfo {
+    CARD8      reqType;
+    CARD8      xkbReqType;     /* always X_KBSetDeviceInfo */
+    CARD16     length B16;
+    CARD16     deviceSpec B16;
+    CARD8      firstBtn;
+    CARD8      nBtns;
+    CARD16     change B16;
+    CARD16     nDeviceLedFBs B16;
+} xkbSetDeviceInfoReq;
+#define        sz_xkbSetDeviceInfoReq  12
+
+typedef struct _xkbSetDebuggingFlags {
+    CARD8      reqType;
+    CARD8      xkbReqType;     /* always X_KBSetDebuggingFlags */
+    CARD16     length B16;
+    CARD16     msgLength B16;
+    CARD16     pad B16;
+    CARD32     affectFlags B32;
+    CARD32     flags B32;
+    CARD32     affectCtrls B32;
+    CARD32     ctrls B32;
+} xkbSetDebuggingFlagsReq;
+#define        sz_xkbSetDebuggingFlagsReq      24
+
+typedef struct _xkbSetDebuggingFlagsReply {
+    BYTE       type;           /* X_Reply */
+    CARD8      pad0;
+    CARD16     sequenceNumber B16;
+    CARD32     length B32;
+    CARD32     currentFlags B32;
+    CARD32     currentCtrls B32;
+    CARD32     supportedFlags B32;
+    CARD32     supportedCtrls B32;
+    CARD32     pad1 B32;
+    CARD32     pad2 B32;
+} xkbSetDebuggingFlagsReply;
+#define        sz_xkbSetDebuggingFlagsReply    32
+
+       /*
+        * X KEYBOARD EXTENSION EVENT STRUCTURES
+        */
+
+typedef struct _xkbAnyEvent {
+    BYTE       type;
+    BYTE       xkbType;
+    CARD16     sequenceNumber B16;
+    Time       time B32;
+    CARD8      deviceID;
+    CARD8      pad1;
+    CARD16     pad2 B16;
+    CARD32     pad3 B32;
+    CARD32     pad4 B32;
+    CARD32     pad5 B32;
+    CARD32     pad6 B32;
+    CARD32     pad7 B32;
+} xkbAnyEvent;
+#define        sz_xkbAnyEvent 32
+
+typedef        struct _xkbNewKeyboardNotify {
+    BYTE       type;
+    BYTE       xkbType;
+    CARD16     sequenceNumber B16;
+    Time       time B32;
+    CARD8      deviceID;
+    CARD8      oldDeviceID;
+    KeyCode    minKeyCode;
+    KeyCode    maxKeyCode;
+    KeyCode    oldMinKeyCode;
+    KeyCode    oldMaxKeyCode;
+    CARD8      requestMajor;
+    CARD8      requestMinor;
+    CARD16     changed B16;
+    CARD8      detail;
+    CARD8      pad1;
+    CARD32     pad2 B32;
+    CARD32     pad3 B32;
+    CARD32     pad4 B32;
+} xkbNewKeyboardNotify;
+#define        sz_xkbNewKeyboardNotify 32
+
+typedef        struct _xkbMapNotify {
+    BYTE       type;
+    BYTE       xkbType;
+    CARD16     sequenceNumber B16;
+    Time       time B32;
+    CARD8      deviceID;
+    CARD8      ptrBtnActions;
+    CARD16     changed B16;
+    KeyCode    minKeyCode;
+    KeyCode    maxKeyCode;
+    CARD8      firstType;
+    CARD8      nTypes;
+    KeyCode    firstKeySym;
+    CARD8      nKeySyms;
+    KeyCode    firstKeyAct;
+    CARD8      nKeyActs;
+    KeyCode    firstKeyBehavior;
+    CARD8      nKeyBehaviors;
+    KeyCode    firstKeyExplicit;
+    CARD8      nKeyExplicit;
+    KeyCode    firstModMapKey;
+    CARD8      nModMapKeys;
+    KeyCode    firstVModMapKey;
+    CARD8      nVModMapKeys;
+    CARD16     virtualMods B16;
+    CARD16     pad1 B16;
+} xkbMapNotify;
+#define        sz_xkbMapNotify 32
+
+typedef        struct _xkbStateNotify {
+    BYTE       type;
+    BYTE       xkbType;
+    CARD16     sequenceNumber B16;
+    Time       time B32;
+    CARD8      deviceID;
+    CARD8      mods;
+    CARD8      baseMods;
+    CARD8      latchedMods;
+    CARD8      lockedMods;
+    CARD8      group;
+    INT16      baseGroup B16;
+    INT16      latchedGroup B16;
+    CARD8      lockedGroup;
+    CARD8      compatState;
+    CARD8      grabMods;
+    CARD8      compatGrabMods;
+    CARD8      lookupMods;
+    CARD8      compatLookupMods;
+    CARD16     ptrBtnState B16;
+    CARD16     changed B16;
+    KeyCode    keycode;
+    CARD8      eventType;
+    CARD8      requestMajor;
+    CARD8      requestMinor;
+} xkbStateNotify;
+#define        sz_xkbStateNotify       32
+
+typedef struct _xkbControlsNotify {
+    BYTE       type;
+    BYTE       xkbType;
+    CARD16     sequenceNumber B16;
+    Time       time B32;
+    CARD8      deviceID;
+    CARD8      numGroups;
+    CARD16     pad1 B16;
+    CARD32     changedControls B32;
+    CARD32     enabledControls B32;
+    CARD32     enabledControlChanges B32;
+    KeyCode    keycode;
+    CARD8      eventType;
+    CARD8      requestMajor;
+    CARD8      requestMinor;
+    CARD32     pad2 B32;
+} xkbControlsNotify;
+#define        sz_xkbControlsNotify    32
+
+typedef struct _xkbIndicatorNotify {
+    BYTE       type;
+    BYTE       xkbType;
+    CARD16     sequenceNumber B16;
+    Time       time B32;
+    CARD8      deviceID;
+    CARD8      pad1;
+    CARD16     pad2 B16;
+    CARD32     state B32;
+    CARD32     changed B32;
+    CARD32     pad3 B32;
+    CARD32     pad4 B32;
+    CARD32     pad5 B32;
+} xkbIndicatorNotify;
+#define        sz_xkbIndicatorNotify   32
+
+typedef struct _xkbNamesNotify {
+    BYTE       type;
+    BYTE       xkbType;
+    CARD16     sequenceNumber B16;
+    Time       time B32;
+    CARD8      deviceID;
+    CARD8      pad1;
+    CARD16     changed B16;
+    CARD8      firstType;
+    CARD8      nTypes;
+    CARD8      firstLevelName;
+    CARD8      nLevelNames;
+    CARD8      pad2;
+    CARD8      nRadioGroups;
+    CARD8      nAliases;
+    CARD8      changedGroupNames;
+    CARD16     changedVirtualMods B16;
+    CARD8      firstKey;
+    CARD8      nKeys;
+    CARD32     changedIndicators B32;
+    CARD32     pad3 B32;
+} xkbNamesNotify;
+#define        sz_xkbNamesNotify       32
+
+typedef struct _xkbCompatMapNotify {
+    BYTE       type;
+    BYTE       xkbType;
+    CARD16     sequenceNumber B16;
+    Time       time B32;
+    CARD8      deviceID;
+    CARD8      changedGroups;
+    CARD16     firstSI B16;
+    CARD16     nSI B16;
+    CARD16     nTotalSI B16;
+    CARD32     pad1 B32;
+    CARD32     pad2 B32;
+    CARD32     pad3 B32;
+    CARD32     pad4 B32;
+} xkbCompatMapNotify;
+#define sz_xkbCompatMapNotify  32
+
+typedef struct _xkbBellNotify {
+    BYTE       type;
+    BYTE       xkbType;
+    CARD16     sequenceNumber B16;
+    Time       time B32;
+    CARD8      deviceID;
+    CARD8      bellClass;
+    CARD8      bellID;
+    CARD8      percent;
+    CARD16     pitch B16;
+    CARD16     duration B16;
+    Atom       name B32;
+    Window     window B32;
+    BOOL       eventOnly;
+    CARD8      pad1;
+    CARD16     pad2 B16;
+    CARD32     pad3 B32;
+} xkbBellNotify;
+#define        sz_xkbBellNotify        32
+
+typedef struct _xkbActionMessage {
+    BYTE       type;
+    BYTE       xkbType;
+    CARD16     sequenceNumber B16;
+    Time       time B32;
+    CARD8      deviceID;
+    KeyCode    keycode;
+    BOOL       press;
+    BOOL       keyEventFollows;
+    CARD8      mods;
+    CARD8      group;
+    CARD8      message[8];
+    CARD16     pad1 B16;
+    CARD32     pad2 B32;
+    CARD32     pad3 B32;
+} xkbActionMessage;
+#define        sz_xkbActionMessage             32
+
+typedef struct _xkbAccessXNotify {
+    BYTE       type;
+    BYTE       xkbType;
+    CARD16     sequenceNumber B16;
+    Time       time B32;
+    CARD8      deviceID;
+    KeyCode    keycode;
+    CARD16     detail B16;
+    CARD16     slowKeysDelay B16;
+    CARD16     debounceDelay B16;
+    CARD32     pad1 B32;
+    CARD32     pad2 B32;
+    CARD32     pad3 B32;
+    CARD32     pad4 B32;
+} xkbAccessXNotify;
+#define        sz_xkbAccessXNotify     32
+
+typedef struct _xkbExtensionDeviceNotify {
+    BYTE       type;
+    BYTE       xkbType;
+    CARD16     sequenceNumber B16;
+    Time       time B32;
+    CARD8      deviceID;
+    CARD8      pad1;
+    CARD16     reason B16;
+    CARD16     ledClass B16;
+    CARD16     ledID B16;
+    CARD32     ledsDefined B32;
+    CARD32     ledState B32;
+    CARD8      firstBtn;
+    CARD8      nBtns;
+    CARD16     supported B16;
+    CARD16     unsupported B16;
+    CARD16     pad3 B16;
+} xkbExtensionDeviceNotify;
+#define        sz_xkbExtensionDeviceNotify             32
+
+typedef struct _xkbEvent {
+    union {
+       xkbAnyEvent             any;
+       xkbNewKeyboardNotify    new_kbd;
+       xkbMapNotify            map;
+       xkbStateNotify          state;
+       xkbControlsNotify       ctrls;
+       xkbIndicatorNotify      indicators;
+       xkbNamesNotify          names;
+       xkbCompatMapNotify      compat;
+       xkbBellNotify           bell;
+       xkbActionMessage        message;
+       xkbAccessXNotify        accessx;
+       xkbExtensionDeviceNotify device;
+    } u;
+} xkbEvent;
+#define sz_xkbEvent    32
+
+#undef Window
+#undef Atom
+#undef Time
+#undef KeyCode
+#undef KeySym
+
+#endif /* _XKBPROTO_H_ */
diff --git a/Xserver/include/extensions/XKBsrv.h b/Xserver/include/extensions/XKBsrv.h
new file mode 100644 (file)
index 0000000..5eb3f92
--- /dev/null
@@ -0,0 +1,1285 @@
+/* $XConsortium: XKBsrv.h /main/25 1996/09/28 16:32:19 rws $ */
+/************************************************************
+Copyright (c) 1993 by Silicon Graphics Computer Systems, Inc.
+
+Permission to use, copy, modify, and distribute this
+software and its documentation for any purpose and without
+fee is hereby granted, provided that the above copyright
+notice appear in all copies and that both that copyright
+notice and this permission notice appear in supporting
+documentation, and that the name of Silicon Graphics not be 
+used in advertising or publicity pertaining to distribution 
+of the software without specific prior written permission.
+Silicon Graphics makes no representation about the suitability 
+of this software for any purpose. It is provided "as is"
+without any express or implied warranty.
+
+SILICON GRAPHICS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS 
+SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 
+AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
+GRAPHICS BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL 
+DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, 
+DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE 
+OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION  WITH
+THE USE OR PERFORMANCE OF THIS SOFTWARE.
+
+********************************************************/
+
+#ifndef _XKBSRV_H_
+#define        _XKBSRV_H_
+
+#ifdef XKB_IN_SERVER
+#define XkbAllocClientMap              SrvXkbAllocClientMap
+#define XkbAllocServerMap              SrvXkbAllocServerMap
+#define XkbChangeTypesOfKey            SrvXkbChangeTypesOfKey
+#define        XkbAddKeyType                   SrvXkbAddKeyType
+#define XkbCopyKeyType                 SrvXkbCopyKeyType
+#define XkbCopyKeyTypes                        SrvXkbCopyKeyTypes
+#define XkbFreeClientMap               SrvXkbFreeClientMap
+#define XkbFreeServerMap               SrvXkbFreeServerMap
+#define XkbInitCanonicalKeyTypes       SrvXkbInitCanonicalKeyTypes
+#define        XkbKeyTypesForCoreSymbols       SrvXkbKeyTypesForCoreSymbols
+#define        XkbApplyCompatMapToKey          SrvXkbApplyCompatMapToKey
+#define        XkbUpdateMapFromCore            SrvXkbUpdateMapFromCore
+#define XkbResizeKeyActions            SrvXkbResizeKeyActions
+#define XkbResizeKeySyms               SrvXkbResizeKeySyms
+#define XkbResizeKeyType               SrvXkbResizeKeyType
+#define XkbAllocCompatMap              SrvXkbAllocCompatMap
+#define XkbAllocControls               SrvXkbAllocControls
+#define XkbAllocIndicatorMaps          SrvXkbAllocIndicatorMaps
+#define XkbAllocKeyboard               SrvXkbAllocKeyboard
+#define XkbAllocNames                  SrvXkbAllocNames
+#define XkbFreeCompatMap               SrvXkbFreeCompatMap
+#define XkbFreeControls                        SrvXkbFreeControls
+#define XkbFreeIndicatorMaps           SrvXkbFreeIndicatorMaps
+#define XkbFreeKeyboard                        SrvXkbFreeKeyboard
+#define XkbFreeNames                   SrvXkbFreeNames
+#define        XkbAddDeviceLedInfo             SrvXkbAddDeviceLedInfo
+#define        XkbAllocDeviceInfo              SrvXkbAllocDeviceInfo
+#define        XkbFreeDeviceInfo               SrvXkbFreeDeviceInfo
+#define        XkbResizeDeviceButtonActions    SrvXkbResizeDeviceButtonActions
+#define XkbLatchModifiers              SrvXkbLatchModifiers
+#define XkbLatchGroup                  SrvXkbLatchGroup
+#define XkbVirtualModsToReal           SrvXkbVirtualModsToReal
+#define        XkbChangeKeycodeRange           SrvXkbChangeKeycodeRange
+#define        XkbApplyVirtualModChanges       SrvXkbApplyVirtualModChanges
+#define        XkbUpdateActionVirtualMods      SrvXkbUpdateActionVirtualMods
+#define XkbUpdateKeyTypeVirtualMods    SrvXkbUpdateKeyTypeVirtualMods
+#endif
+
+#include <X11/extensions/XKBstr.h>
+#include <X11/extensions/XKBproto.h>
+
+typedef struct _XkbInterest {
+       DeviceIntPtr            dev;
+       ClientPtr               client;
+       XID                     resource;
+       struct _XkbInterest *   next;
+       CARD16                  extDevNotifyMask;
+       CARD16                  stateNotifyMask;
+       CARD16                  namesNotifyMask;
+       CARD32                  ctrlsNotifyMask;
+       CARD8                   compatNotifyMask;
+       BOOL                    bellNotifyMask;
+       BOOL                    actionMessageMask;
+       CARD16                  accessXNotifyMask;
+       CARD32                  iStateNotifyMask;
+       CARD32                  iMapNotifyMask;
+       CARD16                  altSymsNotifyMask;
+       CARD32                  autoCtrls;
+       CARD32                  autoCtrlValues;
+} XkbInterestRec,*XkbInterestPtr;
+
+typedef struct _XkbRadioGroup {
+       CARD8           flags;
+       CARD8           nMembers;
+       CARD8           dfltDown;
+       CARD8           currentDown;
+       CARD8           members[XkbRGMaxMembers];
+} XkbRadioGroupRec, *XkbRadioGroupPtr;
+
+typedef struct _XkbEventCause {
+       CARD8           kc;
+       CARD8           event;
+       CARD8           mjr;
+       CARD8           mnr;
+       ClientPtr       client;
+} XkbEventCauseRec,*XkbEventCausePtr;
+#define        XkbSetCauseKey(c,k,e)   { (c)->kc= (k),(c)->event= (e),\
+                                 (c)->mjr= (c)->mnr= 0; \
+                                 (c)->client= NULL; }
+#define        XkbSetCauseReq(c,j,n,cl) { (c)->kc= (c)->event= 0,\
+                                 (c)->mjr= (j),(c)->mnr= (n);\
+                                 (c)->client= (cl); }
+#define        XkbSetCauseCoreReq(c,e,cl) XkbSetCauseReq(c,e,0,cl)
+#define        XkbSetCauseXkbReq(c,e,cl)  XkbSetCauseReq(c,XkbReqCode,e,cl)
+#define        XkbSetCauseUnknown(c)      XkbSetCauseKey(c,0,0)
+
+#define        _OFF_TIMER              0
+#define        _KRG_WARN_TIMER         1
+#define        _KRG_TIMER              2
+#define        _SK_TIMEOUT_TIMER       3
+#define        _ALL_TIMEOUT_TIMER      4
+
+#define        _BEEP_NONE              0
+#define        _BEEP_FEATURE_ON        1
+#define        _BEEP_FEATURE_OFF       2
+#define        _BEEP_FEATURE_CHANGE    3
+#define        _BEEP_SLOW_WARN         4
+#define        _BEEP_SLOW_PRESS        5
+#define        _BEEP_SLOW_ACCEPT       6
+#define        _BEEP_SLOW_REJECT       7
+#define        _BEEP_SLOW_RELEASE      8
+#define        _BEEP_STICKY_LATCH      9
+#define        _BEEP_STICKY_LOCK       10
+#define        _BEEP_STICKY_UNLOCK     11
+#define        _BEEP_LED_ON            12
+#define        _BEEP_LED_OFF           13
+#define        _BEEP_LED_CHANGE        14
+#define        _BEEP_BOUNCE_REJECT     15
+
+typedef struct _XkbSrvInfo {
+       XkbStateRec      prev_state;
+       XkbStateRec      state;
+       XkbDescPtr       desc;
+
+       DeviceIntPtr     device;
+       KbdCtrlProcPtr   kbdProc;
+
+       XkbRadioGroupPtr radioGroups;
+       CARD8            nRadioGroups;
+       CARD8            clearMods;
+       CARD8            setMods;
+       INT16            groupChange;
+
+       CARD16           dfltPtrDelta;
+
+       double           mouseKeysCurve;
+       double           mouseKeysCurveFactor;
+       INT16            mouseKeysDX;
+       INT16            mouseKeysDY;
+       CARD8            mouseKeysFlags;
+       Bool             mouseKeysAccel;
+       CARD8            mouseKeysCounter;
+
+       CARD8            lockedPtrButtons;
+       CARD8            shiftKeyCount;
+       KeyCode          mouseKey;
+       KeyCode          inactiveKey;
+       KeyCode          slowKey;
+       KeyCode          repeatKey;
+       CARD8            krgTimerActive;
+       CARD8            beepType;
+       CARD8            beepCount;
+
+       CARD32           flags;
+       CARD32           lastPtrEventTime;
+       CARD32           lastShiftEventTime;
+       OsTimerPtr       beepTimer;
+       OsTimerPtr       mouseKeyTimer;
+       OsTimerPtr       slowKeysTimer;
+       OsTimerPtr       bounceKeysTimer;
+       OsTimerPtr       repeatKeyTimer;
+       OsTimerPtr       krgTimer;
+} XkbSrvInfoRec, *XkbSrvInfoPtr;
+
+#define        XkbSLI_IsDefault        (1L<<0)
+#define        XkbSLI_HasOwnState      (1L<<1)
+
+typedef struct _XkbSrvLedInfo {
+       CARD16                  flags;
+       CARD16                  class;
+       CARD16                  id;
+       union {
+           KbdFeedbackPtr      kf;
+           LedFeedbackPtr      lf;
+       }                       fb;
+
+       CARD32                  physIndicators;
+       CARD32                  autoState;
+       CARD32                  explicitState;
+       CARD32                  effectiveState;
+
+       CARD32                  mapsPresent;
+       CARD32                  namesPresent;
+       XkbIndicatorMapPtr      maps;
+       Atom *                  names;
+
+       CARD32                  usesBase;
+       CARD32                  usesLatched;
+       CARD32                  usesLocked;
+       CARD32                  usesEffective;
+       CARD32                  usesCompat;
+       CARD32                  usesControls;
+
+       CARD32                  usedComponents;
+} XkbSrvLedInfoRec, *XkbSrvLedInfoPtr;
+
+/*
+ * Settings for xkbClientFlags field (used by DIX)
+ * These flags _must_ not overlap with XkbPCF_*
+ */
+#define        _XkbClientInitialized           (1<<15)
+
+#define        _XkbWantsDetectableAutoRepeat(c)\
+       ((c)->xkbClientFlags&XkbPCF_DetectableAutoRepeatMask)
+
+/*
+ * Settings for flags field
+ */
+#define        _XkbStateNotifyInProgress       (1<<0)
+
+/***====================================================================***/
+
+#define XkbAX_KRGMask   (XkbSlowKeysMask|XkbBounceKeysMask)
+#define        XkbAllFilteredEventsMask \
+                       (XkbAccessXKeysMask|XkbRepeatKeysMask|XkbAX_KRGMask)
+
+/***====================================================================***/
+
+extern int     XkbReqCode;
+extern int     XkbEventBase;
+extern int     XkbKeyboardErrorCode;
+extern int     XkbDisableLockActions;
+extern char *  XkbBaseDirectory;
+extern char *  XkbInitialMap;
+extern int     _XkbClientMajor;
+extern int     _XkbClientMinor;
+extern unsigned        int XkbXIUnsupported;
+
+extern char *  XkbModelUsed,*XkbLayoutUsed,*XkbVariantUsed,*XkbOptionsUsed;
+extern Bool    noXkbExtension;
+extern Bool    XkbWantRulesProp;
+
+extern pointer XkbLastRepeatEvent;
+
+extern CARD32  xkbDebugFlags;
+extern CARD32  xkbDebugCtrls;
+
+#define        _XkbAlloc(s)            xalloc((s))
+#define        _XkbCalloc(n,s)         Xcalloc((n)*(s))
+#define        _XkbRealloc(o,s)        Xrealloc((o),(s))
+#define        _XkbTypedAlloc(t)       ((t *)xalloc(sizeof(t)))
+#define        _XkbTypedCalloc(n,t)    ((t *)Xcalloc((n)*sizeof(t)))
+#define        _XkbTypedRealloc(o,n,t) \
+       ((o)?(t *)Xrealloc((o),(n)*sizeof(t)):_XkbTypedCalloc(n,t))
+#define        _XkbClearElems(a,f,l,t) bzero(&(a)[f],((l)-(f)+1)*sizeof(t))
+#define        _XkbFree(p)             Xfree(p)
+
+#define        _XkbLibError(c,l,d) \
+       { _XkbErrCode= (c); _XkbErrLocation= (l); _XkbErrData= (d); }
+#define        _XkbErrCode2(a,b) ((XID)((((unsigned int)(a))<<24)|((b)&0xffffff)))
+#define        _XkbErrCode3(a,b,c)     _XkbErrCode2(a,(((unsigned int)(b))<<16)|(c))
+#define        _XkbErrCode4(a,b,c,d) _XkbErrCode3(a,b,((((unsigned int)(c))<<8)|(d)))
+
+extern int     DeviceKeyPress,DeviceKeyRelease;
+extern int     DeviceButtonPress,DeviceButtonRelease;
+
+#ifdef XINPUT
+#define        _XkbIsPressEvent(t)     (((t)==KeyPress)||((t)==DeviceKeyPress))
+#define        _XkbIsReleaseEvent(t)   (((t)==KeyRelease)||((t)==DeviceKeyRelease))
+#else
+#define        _XkbIsPressEvent(t)     ((t)==KeyPress)
+#define        _XkbIsReleaseEvent(t)   ((t)==KeyRelease)
+#endif
+
+#define        _XkbCoreKeycodeInRange(c,k)     (((k)>=(c)->curKeySyms.minKeyCode)&&\
+                                        ((k)<=(c)->curKeySyms.maxKeyCode))
+#define        _XkbCoreNumKeys(c)      ((c)->curKeySyms.maxKeyCode-\
+                                (c)->curKeySyms.minKeyCode+1)
+
+#define        XConvertCase(s,l,u)     XkbConvertCase(s,l,u)
+#define        IsKeypadKey(s)          XkbKSIsKeypad(s)
+
+#define        Status          int
+#define        XPointer        pointer
+#define        Display         struct _XDisplay
+
+#ifndef True
+#define        True    1
+#define        False   0
+#endif
+
+#ifndef PATH_MAX
+#ifdef MAXPATHLEN
+#define        PATH_MAX MAXPATHLEN
+#else
+#define        PATH_MAX 1024
+#endif
+#endif
+
+_XFUNCPROTOBEGIN
+
+extern void    XkbFreeCompatMap(
+#if NeedFunctionPrototypes
+    XkbDescPtr                 /* xkb */,
+    unsigned int               /* which */,
+    Bool                       /* freeMap */
+#endif
+);
+
+extern void XkbFreeNames(
+#if NeedFunctionPrototypes
+       XkbDescPtr              /* xkb */,
+       unsigned int            /* which */,
+       Bool                    /* freeMap */
+#endif
+);
+
+extern DeviceIntPtr _XkbLookupAnyDevice(
+#if NeedFunctionPrototypes
+    int                        /* id */,
+    int *              /* why_rtrn */
+#endif
+);
+
+extern DeviceIntPtr _XkbLookupKeyboard(
+#if NeedFunctionPrototypes
+    int                        /* id */,
+    int *              /* why_rtrn */
+#endif
+);
+
+extern DeviceIntPtr _XkbLookupBellDevice(
+#if NeedFunctionPrototypes
+    int                        /* id */,
+    int *              /* why_rtrn */
+#endif
+);
+
+extern DeviceIntPtr _XkbLookupLedDevice(
+#if NeedFunctionPrototypes
+    int                        /* id */,
+    int *              /* why_rtrn */
+#endif
+);
+
+extern DeviceIntPtr _XkbLookupButtonDevice(
+#if NeedFunctionPrototypes
+    int                        /* id */,
+    int *              /* why_rtrn */
+#endif
+);
+
+extern XkbDescPtr XkbAllocKeyboard(
+#if NeedFunctionPrototypes
+       void
+#endif
+);
+
+extern Status XkbAllocClientMap(
+#if NeedFunctionPrototypes
+       XkbDescPtr              /* xkb */,
+       unsigned int            /* which */,
+       unsigned int            /* nTypes */
+#endif
+);
+
+extern Status XkbAllocServerMap(
+#if NeedFunctionPrototypes
+       XkbDescPtr              /* xkb */,
+       unsigned int            /* which */,
+       unsigned int            /* nNewActions */
+#endif
+);
+
+extern void    XkbFreeClientMap(
+#if NeedFunctionPrototypes
+    XkbDescPtr                 /* xkb */,
+    unsigned int               /* what */,
+    Bool                       /* freeMap */
+#endif
+);
+
+extern void    XkbFreeServerMap(
+#if NeedFunctionPrototypes
+    XkbDescPtr                 /* xkb */,
+    unsigned int               /* what */,
+    Bool                       /* freeMap */
+#endif
+);
+
+extern Status XkbAllocIndicatorMaps(
+#if NeedFunctionPrototypes
+       XkbDescPtr              /* xkb */
+#endif
+);
+
+extern Status  XkbAllocCompatMap(
+#if NeedFunctionPrototypes
+    XkbDescPtr                 /* xkb */,
+    unsigned int               /* which */,
+    unsigned int               /* nInterpret */
+#endif
+);
+
+extern Status XkbAllocNames(
+#if NeedFunctionPrototypes
+       XkbDescPtr              /* xkb */,
+       unsigned int            /* which */,
+       int                     /* nTotalRG */,
+       int                     /* nTotalAliases */
+#endif
+);
+
+extern Status  XkbAllocControls(
+#if NeedFunctionPrototypes
+       XkbDescPtr              /* xkb */,
+       unsigned int            /* which*/
+#endif
+);
+
+extern Status  XkbCopyKeyType(
+#if NeedFunctionPrototypes
+    XkbKeyTypePtr              /* from */,
+    XkbKeyTypePtr              /* into */
+#endif
+);
+
+extern Status  XkbCopyKeyTypes(
+#if NeedFunctionPrototypes
+    XkbKeyTypePtr              /* from */,
+    XkbKeyTypePtr              /* into */,
+    int                                /* num_types */
+#endif
+);
+
+extern Status  XkbResizeKeyType(
+#if NeedFunctionPrototypes
+    XkbDescPtr         /* xkb */,
+    int                        /* type_ndx */,
+    int                        /* map_count */,
+    Bool               /* want_preserve */,
+    int                        /* new_num_lvls */
+#endif
+);
+
+extern void    XkbFreeKeyboard(
+#if NeedFunctionPrototypes
+       XkbDescPtr              /* xkb */,
+       unsigned int            /* which */,
+       Bool                    /* freeDesc */
+#endif
+);
+
+extern  void XkbSetActionKeyMods(
+#if NeedFunctionPrototypes
+       XkbDescPtr              /* xkb */,
+       XkbAction *             /* act */,
+       unsigned int            /* mods */
+#endif
+);
+
+extern Bool XkbCheckActionVMods(
+#if NeedFunctionPrototypes
+       XkbDescPtr              /* xkb */,
+       XkbAction *             /* act */,
+       unsigned int            /* changed */
+#endif
+);
+
+extern Bool XkbApplyVModChanges(
+#if NeedFunctionPrototypes
+    XkbSrvInfoPtr      /* xkbi */,
+    unsigned int       /* changed */,
+    XkbChangesPtr      /* pChanges */,
+    unsigned int *     /* needChecksRtrn */,
+    XkbEventCausePtr   /* cause */
+#endif
+);
+
+extern void XkbApplyVModChangesToAllDevices(
+#if NeedFunctionPrototypes
+    DeviceIntPtr       /* dev */,
+    XkbDescPtr                 /* xkb */,
+    unsigned int       /* changed */,
+    XkbEventCausePtr   /* cause */
+#endif
+);
+
+extern unsigned int XkbMaskForVMask(
+#if NeedFunctionPrototypes
+    XkbDescPtr         /* xkb */,
+    unsigned int       /* vmask */
+#endif
+);
+
+extern Bool XkbVirtualModsToReal(
+#if NeedFunctionPrototypes
+       XkbDescPtr      /* xkb */,
+       unsigned int    /* virtua_mask */,
+       unsigned int *  /* mask_rtrn */
+#endif
+);
+
+extern unsigned int    XkbAdjustGroup(
+#if NeedFunctionPrototypes
+    int                        /* group */,
+    XkbControlsPtr     /* ctrls */
+#endif
+);
+
+extern KeySym *XkbResizeKeySyms(
+#if NeedFunctionPrototypes
+    XkbDescPtr         /* xkb */,
+    int                /* key */,
+    int                /* needed */
+#endif
+);
+
+extern XkbAction *XkbResizeKeyActions(
+#if NeedFunctionPrototypes
+    XkbDescPtr         /* xkb */,
+    int                /* key */,
+    int                /* needed */
+#endif
+);
+
+extern void XkbUpdateKeyTypesFromCore(
+#if NeedFunctionPrototypes
+    DeviceIntPtr       /* pXDev */,
+    KeyCode            /* first */,
+    CARD8              /* num */,
+    XkbChangesPtr      /* pChanges */
+#endif
+);
+
+extern void XkbUpdateDescActions(      
+#if NeedFunctionPrototypes
+    XkbDescPtr         /* xkb */,
+    KeyCode            /* first */,
+    CARD8              /* num */,
+    XkbChangesPtr      /* changes */
+#endif
+);
+
+extern void XkbUpdateActions(
+#if NeedFunctionPrototypes
+    DeviceIntPtr       /* pXDev */,
+    KeyCode            /* first */,
+    CARD8              /* num */,
+    XkbChangesPtr      /* pChanges */,
+    unsigned int *     /* needChecksRtrn */,
+    XkbEventCausePtr   /* cause */
+#endif
+);
+
+extern void XkbUpdateCoreDescription(
+#if NeedFunctionPrototypes
+    DeviceIntPtr       /* keybd */,
+    Bool               /* resize */
+#endif
+);
+
+extern void XkbApplyMappingChange(
+#if NeedFunctionPrototypes
+    DeviceIntPtr       /* pXDev */,
+    CARD8              /* request */,
+    KeyCode            /* firstKey */,
+    CARD8              /* num */,
+    ClientPtr          /* client */
+#endif
+);
+
+extern void XkbSetIndicators(
+#if NeedFunctionPrototypes
+    DeviceIntPtr               /* pXDev */,
+    CARD32                     /* affect */,
+    CARD32                     /* values */,
+    XkbEventCausePtr           /* cause */
+#endif
+);
+
+extern void XkbUpdateIndicators(
+#if NeedFunctionPrototypes
+    DeviceIntPtr               /* keybd */,
+    CARD32                     /* changed */,
+    Bool                       /* check_edevs */,
+    XkbChangesPtr              /* pChanges */,
+    XkbEventCausePtr           /* cause */
+#endif
+);
+
+extern XkbSrvLedInfoPtr XkbAllocSrvLedInfo(
+#if NeedFunctionPrototypes
+    DeviceIntPtr               /* dev */,
+    KbdFeedbackPtr             /* kf */,
+    LedFeedbackPtr             /* lf */,
+    unsigned int               /* needed_parts */
+#endif
+);
+
+extern XkbSrvLedInfoPtr XkbFindSrvLedInfo(
+#if NeedFunctionPrototypes
+    DeviceIntPtr               /* dev */,
+    unsigned int               /* class */,
+    unsigned int               /* id */,
+    unsigned int               /* needed_parts */
+#endif
+);
+
+extern void XkbApplyLedNameChanges(
+#if NeedFunctionPrototypes
+    DeviceIntPtr               /* dev */,
+    XkbSrvLedInfoPtr           /* sli */,
+    unsigned int               /* changed_names */,
+    xkbExtensionDeviceNotify * /* ed */,
+    XkbChangesPtr              /* changes */,
+    XkbEventCausePtr           /* cause */
+#endif
+);
+
+extern void XkbApplyLedMapChanges(
+#if NeedFunctionPrototypes
+    DeviceIntPtr               /* dev */,
+    XkbSrvLedInfoPtr           /* sli */,
+    unsigned int               /* changed_maps */,
+    xkbExtensionDeviceNotify * /* ed */,
+    XkbChangesPtr              /* changes */,
+    XkbEventCausePtr           /* cause */
+#endif
+);
+
+extern void XkbApplyLedStateChanges(
+#if NeedFunctionPrototypes
+    DeviceIntPtr               /* dev */,
+    XkbSrvLedInfoPtr           /* sli */,
+    unsigned int               /* changed_leds */,
+    xkbExtensionDeviceNotify * /* ed */,
+    XkbChangesPtr              /* changes */,
+    XkbEventCausePtr           /* cause */
+#endif
+);
+
+extern void XkbUpdateLedAutoState(
+#if NeedFunctionPrototypes
+    DeviceIntPtr               /* dev */,
+    XkbSrvLedInfoPtr           /* sli */,
+    unsigned int               /* maps_to_check */,
+    xkbExtensionDeviceNotify * /* ed */,
+    XkbChangesPtr              /* changes */,
+    XkbEventCausePtr           /* cause */
+#endif
+);
+
+extern void XkbFlushLedEvents( 
+#if NeedFunctionPrototypes
+    DeviceIntPtr               /* dev */,
+    DeviceIntPtr               /* kbd */,
+    XkbSrvLedInfoPtr           /* sli */,
+    xkbExtensionDeviceNotify * /* ed */,
+    XkbChangesPtr              /* changes */,
+    XkbEventCausePtr           /* cause */
+#endif
+);
+
+extern void XkbUpdateAllDeviceIndicators(
+#if NeedFunctionPrototypes
+    XkbChangesPtr              /* changes */,
+    XkbEventCausePtr           /* cause */
+#endif
+);
+
+extern unsigned int XkbIndicatorsToUpdate(
+#if NeedFunctionPrototypes
+    DeviceIntPtr               /* dev */,
+    unsigned long              /* state_changes */,
+    Bool                       /* enabled_ctrl_changes */
+#endif
+);
+
+extern void XkbComputeDerivedState(
+#if NeedFunctionPrototypes
+    XkbSrvInfoPtr              /* xkbi */
+#endif
+);
+
+extern void XkbCheckSecondaryEffects(
+#if NeedFunctionPrototypes
+    XkbSrvInfoPtr              /* xkbi */,
+    unsigned int               /* which */,
+    XkbChangesPtr              /* changes */,
+    XkbEventCausePtr           /* cause */
+#endif
+);
+
+extern void XkbCheckIndicatorMaps(
+#if NeedFunctionPrototypes
+    DeviceIntPtr               /* dev */,
+    XkbSrvLedInfoPtr           /* sli */,
+    unsigned int               /* which */
+#endif
+);
+
+extern unsigned int XkbStateChangedFlags(
+#if NeedFunctionPrototypes
+    XkbStatePtr                        /* old */,
+    XkbStatePtr                        /* new */
+#endif
+);
+
+extern void XkbSendStateNotify(
+#if NeedFunctionPrototypes
+       DeviceIntPtr    /* kbd */,
+       xkbStateNotify *        /* pSN */
+#endif
+);
+
+extern void XkbSendMapNotify(
+#if NeedFunctionPrototypes
+       DeviceIntPtr    /* kbd */,
+       xkbMapNotify *  /* ev */
+#endif
+);
+
+extern int  XkbComputeControlsNotify(
+#if NeedFunctionPrototypes
+       DeviceIntPtr            /* kbd */,
+       XkbControlsPtr          /* old */,
+       XkbControlsPtr          /* new */,
+       xkbControlsNotify *     /* pCN */,
+        Bool                   /* forceCtrlProc */
+#endif
+);
+
+extern void XkbSendControlsNotify(
+#if NeedFunctionPrototypes
+       DeviceIntPtr            /* kbd */,
+       xkbControlsNotify *     /* ev */
+#endif
+);
+
+extern void XkbSendCompatMapNotify(
+#if NeedFunctionPrototypes
+       DeviceIntPtr            /* kbd */,
+       xkbCompatMapNotify *    /* ev */
+#endif
+);
+
+extern void XkbSendIndicatorNotify(
+#if NeedFunctionPrototypes
+       DeviceIntPtr            /* kbd */,
+       int                     /* xkbType */,
+       xkbIndicatorNotify *    /* ev */
+#endif
+);
+
+extern void XkbHandleBell(
+#if NeedFunctionPrototypes
+       BOOL            /* force */,
+       BOOL            /* eventOnly */,
+       DeviceIntPtr    /* kbd */,
+       CARD8           /* percent */,
+       pointer                 /* ctrl */,
+       CARD8           /* class */,
+       Atom            /* name */,
+       WindowPtr       /* pWin */,
+       ClientPtr       /* pClient */
+#endif
+);
+
+extern void XkbSendAccessXNotify(
+#if NeedFunctionPrototypes
+       DeviceIntPtr            /* kbd */,
+       xkbAccessXNotify *      /* pEv */
+#endif
+);
+
+extern void XkbSendNamesNotify(
+#if NeedFunctionPrototypes
+       DeviceIntPtr    /* kbd */,
+       xkbNamesNotify *        /* ev */
+#endif
+);
+
+extern void XkbSendCompatNotify(
+#if NeedFunctionPrototypes
+       DeviceIntPtr            /* kbd */,
+       xkbCompatMapNotify *    /* ev */
+#endif
+);
+
+extern void XkbSendActionMessage(
+#if NeedFunctionPrototypes
+       DeviceIntPtr            /* kbd */,
+       xkbActionMessage *      /* ev */
+#endif
+);
+
+extern void XkbSendExtensionDeviceNotify(
+#if NeedFunctionPrototypes
+       DeviceIntPtr                    /* kbd */,
+       ClientPtr                       /* client */,
+       xkbExtensionDeviceNotify *      /* ev */
+#endif
+);
+
+extern void XkbSendNotification(
+#if NeedFunctionPrototypes
+    DeviceIntPtr               /* kbd */,
+    XkbChangesPtr              /* pChanges */,
+    XkbEventCausePtr           /* cause */
+#endif
+);
+
+extern void XkbProcessKeyboardEvent(
+#if NeedFunctionPrototypes
+    struct _xEvent *           /* xE */,
+    DeviceIntPtr               /* keybd */,
+    int                        /* count */
+#endif
+);
+
+extern void XkbProcessOtherEvent(
+#if NeedFunctionPrototypes
+    struct _xEvent *           /* xE */,
+    DeviceIntPtr               /* keybd */,
+    int                        /* count */
+#endif
+);
+
+extern void XkbHandleActions(
+#if NeedFunctionPrototypes
+    DeviceIntPtr               /* dev */,
+    DeviceIntPtr               /* kbd */,
+    struct _xEvent *           /* xE */,
+    int                        /* count */
+#endif
+);
+
+extern Bool XkbEnableDisableControls(
+#if NeedFunctionPrototypes
+    XkbSrvInfoPtr      /* xkbi */,
+    unsigned long      /* change */,
+    unsigned long      /* newValues */,
+    XkbChangesPtr      /* changes */,
+    XkbEventCausePtr   /* cause */
+#endif
+);
+
+extern void AccessXInit(
+#if NeedFunctionPrototypes
+    DeviceIntPtr        /* dev */
+#endif
+);
+
+extern Bool AccessXFilterPressEvent(
+#if NeedFunctionPrototypes
+    register struct _xEvent *  /* xE */,
+    register DeviceIntPtr      /* keybd */,
+    int                                /* count */
+#endif
+);
+
+extern Bool AccessXFilterReleaseEvent(
+#if NeedFunctionPrototypes
+    register struct _xEvent *  /* xE */,
+    register DeviceIntPtr      /* keybd */,
+    int                                /* count */
+#endif
+);
+
+extern void AccessXCancelRepeatKey(
+#if NeedFunctionPrototypes
+    XkbSrvInfoPtr      /* xkbi */,
+    KeyCode            /* key */
+#endif
+);
+
+extern void AccessXComputeCurveFactor(
+#if NeedFunctionPrototypes
+    XkbSrvInfoPtr      /* xkbi */,
+    XkbControlsPtr     /* ctrls */
+#endif
+);
+
+extern XkbDeviceLedInfoPtr     XkbAddDeviceLedInfo(
+#if NeedFunctionPrototypes
+       XkbDeviceInfoPtr        /* devi */,
+       unsigned int            /* ledClass */,
+       unsigned int            /* ledId */
+#endif
+);
+
+extern XkbDeviceInfoPtr        XkbAllocDeviceInfo(
+#if NeedFunctionPrototypes
+       unsigned int            /* deviceSpec */,
+       unsigned int            /* nButtons */,
+       unsigned int            /* szLeds */
+#endif
+);
+
+extern void XkbFreeDeviceInfo(
+#if NeedFunctionPrototypes
+       XkbDeviceInfoPtr        /* devi */,
+       unsigned int            /* which */,
+       Bool                    /* freeDevI */
+#endif
+);
+
+extern Status XkbResizeDeviceButtonActions(
+#if NeedFunctionPrototypes
+        XkbDeviceInfoPtr        /* devi */,
+        unsigned int            /* newTotal */
+#endif
+);
+
+extern XkbInterestPtr XkbFindClientResource(
+#if NeedFunctionPrototypes
+       DevicePtr       /* inDev */,
+       ClientPtr       /* client */
+#endif
+);
+
+extern XkbInterestPtr XkbAddClientResource(
+#if NeedFunctionPrototypes
+       DevicePtr       /* inDev */,
+       ClientPtr       /* client */,
+       XID             /* id */
+#endif
+);
+
+extern int XkbRemoveClient(
+#if NeedFunctionPrototypes
+       DevicePtr       /* inDev */,
+       ClientPtr       /* client */
+#endif
+);
+
+extern int XkbRemoveResourceClient(
+#if NeedFunctionPrototypes
+       DevicePtr       /* inDev */,
+       XID             /* id */
+#endif
+);
+
+extern int XkbDDXInitDevice(
+#if NeedFunctionPrototypes
+    DeviceIntPtr        /* dev */
+#endif
+);
+
+extern int XkbDDXAccessXBeep(
+#if NeedFunctionPrototypes
+    DeviceIntPtr        /* dev */,
+    unsigned int       /* what */,
+    unsigned int       /* which */
+#endif
+);
+
+extern void XkbDDXKeyClick(
+#if NeedFunctionPrototypes
+    DeviceIntPtr       /* dev */,
+    int                        /* keycode */,
+    int                        /* synthetic */
+#endif
+);
+
+extern         int XkbDDXUsesSoftRepeat(
+#if NeedFunctionPrototypes
+    DeviceIntPtr       /* dev */
+#endif
+);
+
+extern void XkbDDXKeybdCtrlProc(
+#if NeedFunctionPrototypes
+       DeviceIntPtr    /* dev */,
+       KeybdCtrl *     /* ctrl */
+#endif
+);
+
+extern void XkbDDXChangeControls(
+#if NeedFunctionPrototypes
+       DeviceIntPtr    /* dev */,
+       XkbControlsPtr  /* old */,
+       XkbControlsPtr  /* new */
+#endif
+);
+
+extern void XkbDDXUpdateIndicators(
+#if NeedFunctionPrototypes
+       DeviceIntPtr    /* keybd */,
+       CARD32          /* newState */
+#endif
+);
+
+extern void XkbDDXUpdateDeviceIndicators(
+#if NeedFunctionPrototypes
+       DeviceIntPtr            /* dev */,
+       XkbSrvLedInfoPtr        /* sli */,
+       CARD32                  /* newState */
+#endif
+);
+
+extern void XkbDDXFakePointerButton(
+#if NeedFunctionPrototypes
+       int             /* event */,
+       int             /* button */
+#endif
+);
+
+extern void XkbDDXFakePointerMotion(
+#if NeedFunctionPrototypes
+       unsigned int    /* flags */,
+       int             /* x */,
+       int             /* y */
+#endif
+);
+
+extern void XkbDDXFakeDeviceButton(
+#if NeedFunctionPrototypes
+       DeviceIntPtr    /* dev */,
+       Bool            /* press */,
+       int             /* button */
+#endif
+);
+
+extern int XkbDDXTerminateServer(
+#if NeedFunctionPrototypes
+       DeviceIntPtr    /* dev */,
+       KeyCode         /* key */,
+       XkbAction *     /* act */
+#endif
+);
+
+extern int XkbDDXSwitchScreen(
+#if NeedFunctionPrototypes
+       DeviceIntPtr    /* dev */,
+       KeyCode         /* key */,
+       XkbAction *     /* act */
+#endif
+);
+
+extern void XkbDisableComputedAutoRepeats(
+#if NeedFunctionPrototypes
+       DeviceIntPtr    /* pXDev */,
+       unsigned int    /* key */
+#endif
+);
+
+extern void XkbSetRepeatKeys(
+#if NeedFunctionPrototypes
+       DeviceIntPtr    /* pXDev */,
+       int             /* key */,
+       int             /* onoff */
+#endif
+);
+
+extern int XkbLatchModifiers(
+#if NeedFunctionPrototypes
+       DeviceIntPtr    /* pXDev */,
+       CARD8           /* mask */,
+       CARD8           /* latches */
+#endif
+);
+
+extern int XkbLatchGroup(
+#if NeedFunctionPrototypes
+       DeviceIntPtr    /* pXDev */,
+       int             /* group */
+#endif
+);
+
+extern void XkbClearAllLatchesAndLocks(
+#if NeedFunctionPrototypes
+       DeviceIntPtr            /* dev */,
+       XkbSrvInfoPtr           /* xkbi */,
+       Bool                    /* genEv */,
+       XkbEventCausePtr        /* cause */
+#endif
+);
+
+extern void    XkbSetRulesDflts(
+#if NeedFunctionPrototypes
+       char *                  /* rulesFile */,
+       char *                  /* model */,
+       char *                  /* layout */,
+       char *                  /* variant */,
+       char *                  /* options */
+#endif
+);
+
+extern void    XkbInitDevice(
+#if NeedFunctionPrototypes
+       DeviceIntPtr    /* pXDev */
+#endif
+);
+
+extern Bool    XkbInitKeyboardDeviceStruct(
+#if NeedFunctionPrototypes
+       DeviceIntPtr            /* pXDev */,
+       XkbComponentNamesPtr    /* pNames */,
+       KeySymsPtr              /* pSyms */,
+       CARD8                   /* pMods */[],
+       BellProcPtr             /* bellProc */,
+       KbdCtrlProcPtr          /* ctrlProc */
+#endif
+);
+
+extern void    XkbInitDevice(
+#if NeedFunctionPrototypes
+       DeviceIntPtr            /* pXDev */
+#endif
+);
+
+extern int SProcXkbDispatch(
+#if NeedFunctionPrototypes
+       ClientPtr               /* client */
+#endif
+);
+
+extern XkbGeometryPtr XkbLookupNamedGeometry(
+#if NeedFunctionPrototypes
+       DeviceIntPtr            /* dev */,
+       Atom                    /* name */,
+       Bool *                  /* shouldFree */
+#endif
+);
+
+extern char *  _XkbDupString(
+#if NeedFunctionPrototypes
+       char *                  /* str */
+#endif
+);
+
+extern void    XkbConvertCase(
+#if NeedFunctionPrototypes
+       KeySym                  /* sym */,
+       KeySym *                /* lower */,
+       KeySym *                /* upper */
+#endif
+);
+
+extern Status   XkbChangeKeycodeRange( 
+#if NeedFunctionPrototypes
+       XkbDescPtr              /* xkb */,
+       int                     /* minKC */,
+       int                     /* maxKC */,
+       XkbChangesPtr           /* changes */
+#endif
+);
+
+#ifdef XKBSRV_NEED_FILE_FUNCS
+
+#include "extensions/XKMformat.h"
+#include "extensions/XKBfile.h"
+#include "extensions/XKBrules.h"
+
+#define        _XkbListKeymaps         0
+#define        _XkbListKeycodes        1
+#define        _XkbListTypes           2
+#define        _XkbListCompat          3
+#define        _XkbListSymbols         4
+#define        _XkbListGeometry        5
+#define        _XkbListNumComponents   6
+
+typedef struct _XkbSrvListInfo {
+       int             szPool;
+       int             nPool;
+       char *          pool;
+
+       int             maxRtrn;
+       int             nTotal;
+
+       char *          pattern[_XkbListNumComponents];
+       int             nFound[_XkbListNumComponents];
+} XkbSrvListInfoRec,*XkbSrvListInfoPtr;
+
+char *
+XkbGetRulesDflts(
+#if NeedFunctionPrototypes
+       XkbRF_VarDefsPtr        /* defs */
+#endif
+);
+
+extern void    XkbSetRulesUsed(
+#if NeedFunctionPrototypes
+       XkbRF_VarDefsPtr        /* defs */
+#endif
+);
+
+
+extern Status  XkbDDXList(
+#if NeedFunctionPrototypes
+       DeviceIntPtr            /* dev */,
+       XkbSrvListInfoPtr       /* listing */,
+       ClientPtr               /* client */
+#endif
+);
+
+extern unsigned int XkbDDXLoadKeymapByNames(
+#if NeedFunctionPrototypes
+       DeviceIntPtr            /* keybd */,
+       XkbComponentNamesPtr    /* names */,
+       unsigned int            /* want */,
+       unsigned int            /* need */,
+       XkbFileInfoPtr          /* finfoRtrn */,
+       char *                  /* keymapNameRtrn */,
+       int                     /* keymapNameRtrnLen */
+#endif
+);
+
+extern Bool XkbDDXNamesFromRules(
+#if NeedFunctionPrototypes
+       DeviceIntPtr            /* keybd */,
+       char *                  /* rules */,
+       XkbRF_VarDefsPtr        /* defs */,
+       XkbComponentNamesPtr    /* names */
+#endif
+);
+
+extern FILE *XkbDDXOpenConfigFile(
+#if NeedFunctionPrototypes
+       char *  /* mapName */,
+       char *  /* fileNameRtrn */,
+       int     /* fileNameRtrnLen */
+#endif
+);
+
+extern Bool XkbDDXApplyConfig(
+#if NeedFunctionPrototypes
+       XPointer        /* cfg_in */,
+       XkbSrvInfoPtr   /* xkbi */
+#endif
+);
+
+extern XPointer XkbDDXPreloadConfig(
+#if NeedFunctionPrototypes
+       char **                 /* rulesFileRtrn */,
+       XkbRF_VarDefsPtr        /* defs */,
+       XkbComponentNamesPtr    /* names */,
+       DeviceIntPtr            /* dev */
+#endif
+);
+
+extern int XkbDDXUsesSoftRepeat(
+#if NeedFunctionPrototypes
+       DeviceIntPtr    /* pXDev */
+#endif
+);
+
+extern void XkbDDXFakePointerMotion(
+#if NeedFunctionPrototypes
+       unsigned int            /* flags */,
+       int                     /* x */,
+       int                     /* y */
+#endif
+);
+
+extern int _XkbStrCaseCmp(
+#if NeedFunctionPrototypes
+       char *                  /* str1 */,
+       char *                  /* str2 */
+#endif
+);
+
+#endif /* XKBSRV_NEED_FILE_FUNCS */
+
+
+_XFUNCPROTOEND
+
+#define        XkbAtomGetString(d,s)   NameForAtom(s)
+
+#endif /* _XKBSRV_H_ */
+
+
diff --git a/Xserver/include/extensions/XKBstr.h b/Xserver/include/extensions/XKBstr.h
new file mode 100644 (file)
index 0000000..29fde0a
--- /dev/null
@@ -0,0 +1,614 @@
+/* $TOG: XKBstr.h /main/16 1997/06/10 06:53:12 kaleb $ */
+/************************************************************
+Copyright (c) 1993 by Silicon Graphics Computer Systems, Inc.
+
+Permission to use, copy, modify, and distribute this
+software and its documentation for any purpose and without
+fee is hereby granted, provided that the above copyright
+notice appear in all copies and that both that copyright
+notice and this permission notice appear in supporting
+documentation, and that the name of Silicon Graphics not be 
+used in advertising or publicity pertaining to distribution 
+of the software without specific prior written permission.
+Silicon Graphics makes no representation about the suitability 
+of this software for any purpose. It is provided "as is"
+without any express or implied warranty.
+
+SILICON GRAPHICS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS 
+SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 
+AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
+GRAPHICS BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL 
+DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, 
+DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE 
+OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION  WITH
+THE USE OR PERFORMANCE OF THIS SOFTWARE.
+
+********************************************************/
+
+#ifndef _XKBSTR_H_
+#define        _XKBSTR_H_
+
+#include <X11/extensions/XKB.h>
+
+#define        XkbCharToInt(v)         ((v)&0x80?(int)((v)|(~0xff)):(int)((v)&0x7f))
+#define        XkbIntTo2Chars(i,h,l)   (((h)=((i>>8)&0xff)),((l)=((i)&0xff)))
+
+#if defined(WORD64) && defined(UNSIGNEDBITFIELDS)
+#define        Xkb2CharsToInt(h,l)     ((h)&0x80?(int)(((h)<<8)|(l)|(~0xffff)):\
+                                         (int)(((h)<<8)|(l)&0x7fff))
+#else
+#define        Xkb2CharsToInt(h,l)     ((short)(((h)<<8)|(l)))
+#endif
+
+       /*
+        * Common data structures and access macros
+        */
+
+typedef struct _XkbStateRec {
+       unsigned char   group;
+       unsigned char   locked_group;
+       unsigned short  base_group;
+       unsigned short  latched_group;
+       unsigned char   mods;
+       unsigned char   base_mods;
+       unsigned char   latched_mods;
+       unsigned char   locked_mods;
+       unsigned char   compat_state;
+       unsigned char   grab_mods;
+       unsigned char   compat_grab_mods;
+       unsigned char   lookup_mods;
+       unsigned char   compat_lookup_mods;
+       unsigned short  ptr_buttons;
+} XkbStateRec,*XkbStatePtr;
+#define        XkbModLocks(s)   ((s)->locked_mods)
+#define        XkbStateMods(s)  ((s)->base_mods|(s)->latched_mods|XkbModLocks(s))
+#define        XkbGroupLock(s)  ((s)->locked_group)
+#define        XkbStateGroup(s) ((s)->base_group+(s)->latched_group+XkbGroupLock(s))
+#define        XkbStateFieldFromRec(s) XkbBuildCoreState((s)->lookup_mods,(s)->group)
+#define        XkbGrabStateFromRec(s)  XkbBuildCoreState((s)->grab_mods,(s)->group)
+
+typedef struct _XkbMods {
+       unsigned char   mask;   /* effective mods */
+       unsigned char   real_mods;
+       unsigned short  vmods;
+} XkbModsRec,*XkbModsPtr;
+
+typedef struct _XkbKTMapEntry {
+       Bool            active;
+       unsigned char   level;
+       XkbModsRec      mods;
+} XkbKTMapEntryRec,*XkbKTMapEntryPtr;
+
+typedef struct _XkbKeyType {
+       XkbModsRec              mods;
+       unsigned char           num_levels;
+       unsigned char           map_count;
+       XkbKTMapEntryPtr        map;
+       XkbModsPtr              preserve;
+       Atom                    name;
+       Atom *                  level_names;
+} XkbKeyTypeRec, *XkbKeyTypePtr;
+
+#define        XkbNumGroups(g)                 ((g)&0x0f)
+#define        XkbOutOfRangeGroupInfo(g)       ((g)&0xf0)
+#define        XkbOutOfRangeGroupAction(g)     ((g)&0xc0)
+#define        XkbOutOfRangeGroupNumber(g)     (((g)&0x30)>>4)
+#define        XkbSetGroupInfo(g,w,n)  (((w)&0xc0)|(((n)&3)<<4)|((g)&0x0f))
+#define        XkbSetNumGroups(g,n)    (((g)&0xf0)|((n)&0x0f))
+
+       /*
+        * Structures and access macros used primarily by the server
+        */
+
+typedef struct _XkbBehavior {
+       unsigned char   type;
+       unsigned char   data;
+} XkbBehavior;
+
+#define        XkbAnyActionDataSize 7
+typedef        struct _XkbAnyAction {
+       unsigned char   type;
+       unsigned char   data[XkbAnyActionDataSize];
+} XkbAnyAction;
+
+typedef struct _XkbModAction {
+       unsigned char   type;
+       unsigned char   flags;
+       unsigned char   mask;
+       unsigned char   real_mods;
+       unsigned char   vmods1;
+       unsigned char   vmods2;
+} XkbModAction;
+#define        XkbModActionVMods(a)      \
+       ((short)(((a)->vmods1<<8)|((a)->vmods2)))
+#define        XkbSetModActionVMods(a,v) \
+       (((a)->vmods1=(((v)>>8)&0xff)),(a)->vmods2=((v)&0xff))
+
+typedef struct _XkbGroupAction {
+       unsigned char   type;
+       unsigned char   flags;
+       char            group_XXX;
+} XkbGroupAction;
+#define        XkbSAGroup(a)           (XkbCharToInt((a)->group_XXX))
+#define        XkbSASetGroup(a,g)      ((a)->group_XXX=(g))
+
+typedef struct _XkbISOAction {
+       unsigned char   type;
+       unsigned char   flags;
+       unsigned char   mask;
+       unsigned char   real_mods;
+       char            group_XXX;
+       unsigned char   affect;
+       unsigned char   vmods1;
+       unsigned char   vmods2;
+} XkbISOAction;
+
+typedef struct _XkbPtrAction {
+       unsigned char   type;
+       unsigned char   flags;
+       unsigned char   high_XXX;
+       unsigned char   low_XXX;
+       unsigned char   high_YYY;
+       unsigned char   low_YYY;
+} XkbPtrAction;
+#define        XkbPtrActionX(a)      (Xkb2CharsToInt((a)->high_XXX,(a)->low_XXX))
+#define        XkbPtrActionY(a)      (Xkb2CharsToInt((a)->high_YYY,(a)->low_YYY))
+#define        XkbSetPtrActionX(a,x) (XkbIntTo2Chars(x,(a)->high_XXX,(a)->low_XXX))
+#define        XkbSetPtrActionY(a,y) (XkbIntTo2Chars(y,(a)->high_YYY,(a)->low_YYY))
+
+typedef struct _XkbPtrBtnAction {
+       unsigned char   type;
+       unsigned char   flags;
+       unsigned char   count;
+       unsigned char   button;
+} XkbPtrBtnAction;
+
+typedef struct _XkbPtrDfltAction {
+       unsigned char   type;
+       unsigned char   flags;
+       unsigned char   affect;
+       char            valueXXX;
+} XkbPtrDfltAction;
+#define        XkbSAPtrDfltValue(a)            (XkbCharToInt((a)->valueXXX))
+#define        XkbSASetPtrDfltValue(a,c)       ((a)->valueXXX= ((c)&0xff))
+
+typedef struct _XkbSwitchScreenAction {
+       unsigned char   type;
+       unsigned char   flags;
+       char            screenXXX;
+} XkbSwitchScreenAction;
+#define        XkbSAScreen(a)                  (XkbCharToInt((a)->screenXXX))
+#define        XkbSASetScreen(a,s)             ((a)->screenXXX= ((s)&0xff))
+
+typedef struct _XkbCtrlsAction {
+       unsigned char   type;
+       unsigned char   flags;
+       unsigned char   ctrls3;
+       unsigned char   ctrls2;
+       unsigned char   ctrls1;
+       unsigned char   ctrls0;
+} XkbCtrlsAction;
+#define        XkbActionSetCtrls(a,c)  (((a)->ctrls3=(((c)>>24)&0xff)),\
+                                       ((a)->ctrls2=(((c)>>16)&0xff)),\
+                                       ((a)->ctrls1=(((c)>>8)&0xff)),\
+                                       ((a)->ctrls0=((c)&0xff)))
+#define        XkbActionCtrls(a) ((((unsigned int)(a)->ctrls3)<<24)|\
+                          (((unsigned int)(a)->ctrls2)<<16)|\
+                          (((unsigned int)(a)->ctrls1)<<8)|\
+                          ((unsigned int)((a)->ctrls0)))
+
+typedef struct _XkbMessageAction {
+       unsigned char   type;
+       unsigned char   flags;
+       unsigned char   message[6];
+} XkbMessageAction;
+
+typedef struct _XkbRedirectKeyAction {
+       unsigned char   type;
+       unsigned char   new_key;
+       unsigned char   mods_mask;
+       unsigned char   mods;
+       unsigned char   vmods_mask0;
+       unsigned char   vmods_mask1;
+       unsigned char   vmods0;
+       unsigned char   vmods1;
+} XkbRedirectKeyAction;
+
+#define        XkbSARedirectVMods(a)           ((((unsigned int)(a)->vmods1)<<8)|\
+                                       ((unsigned int)(a)->vmods0))
+#define        XkbSARedirectSetVMods(a,m)      (((a)->vmods_mask1=(((m)>>8)&0xff)),\
+                                        ((a)->vmods_mask0=((m)&0xff)))
+#define        XkbSARedirectVModsMask(a)       ((((unsigned int)(a)->vmods_mask1)<<8)|\
+                                       ((unsigned int)(a)->vmods_mask0))
+#define        XkbSARedirectSetVModsMask(a,m)  (((a)->vmods_mask1=(((m)>>8)&0xff)),\
+                                        ((a)->vmods_mask0=((m)&0xff)))
+
+typedef struct _XkbDeviceBtnAction {
+       unsigned char   type;
+       unsigned char   flags;
+       unsigned char   count;
+       unsigned char   button;
+       unsigned char   device;
+} XkbDeviceBtnAction;
+
+typedef struct _XkbDeviceValuatorAction {
+       unsigned char   type;
+       unsigned char   device;
+       unsigned char   v1_what;
+       unsigned char   v1_ndx;
+       unsigned char   v1_value;
+       unsigned char   v2_what;
+       unsigned char   v2_ndx;
+       unsigned char   v2_value;
+} XkbDeviceValuatorAction;
+
+typedef        union _XkbAction {
+       XkbAnyAction            any;
+       XkbModAction            mods;
+       XkbGroupAction          group;
+       XkbISOAction            iso;
+       XkbPtrAction            ptr;
+       XkbPtrBtnAction         btn;
+       XkbPtrDfltAction        dflt;
+       XkbSwitchScreenAction   screen;
+       XkbCtrlsAction          ctrls;
+       XkbMessageAction        msg;
+       XkbRedirectKeyAction    redirect;
+       XkbDeviceBtnAction      devbtn;
+       XkbDeviceValuatorAction devval;
+       unsigned char           type;
+} XkbAction;
+
+typedef        struct _XkbControls {
+       unsigned char   mk_dflt_btn;
+       unsigned char   num_groups;
+       unsigned char   groups_wrap;
+       XkbModsRec      internal;
+       XkbModsRec      ignore_lock;
+       unsigned int    enabled_ctrls;
+       unsigned short  repeat_delay;
+       unsigned short  repeat_interval;
+       unsigned short  slow_keys_delay;
+       unsigned short  debounce_delay;
+       unsigned short  mk_delay;
+       unsigned short  mk_interval;
+       unsigned short  mk_time_to_max;
+       unsigned short  mk_max_speed;
+                short  mk_curve;
+       unsigned short  ax_options;
+       unsigned short  ax_timeout;
+       unsigned short  axt_opts_mask;
+       unsigned short  axt_opts_values;
+       unsigned int    axt_ctrls_mask;
+       unsigned int    axt_ctrls_values;
+       unsigned char   per_key_repeat[XkbPerKeyBitArraySize];
+} XkbControlsRec, *XkbControlsPtr;
+
+#define        XkbAX_AnyFeedback(c)    ((c)->enabled_ctrls&XkbAccessXFeedbackMask)
+#define        XkbAX_NeedOption(c,w)   ((c)->ax_options&(w))
+#define        XkbAX_NeedFeedback(c,w) (XkbAX_AnyFeedback(c)&&XkbAX_NeedOption(c,w))
+
+typedef struct _XkbServerMapRec {
+       unsigned short           num_acts;
+       unsigned short           size_acts;
+       XkbAction               *acts;
+
+       XkbBehavior             *behaviors;
+       unsigned short          *key_acts;
+#if defined(__cplusplus) || defined(c_plusplus)
+       /* explicit is a C++ reserved word */
+       unsigned char           *c_explicit;
+#else
+       unsigned char           *explicit;
+#endif
+       unsigned char            vmods[XkbNumVirtualMods];
+       unsigned short          *vmodmap;
+} XkbServerMapRec, *XkbServerMapPtr;
+
+#define        XkbSMKeyActionsPtr(m,k) (&(m)->acts[(m)->key_acts[k]])
+
+       /*
+        * Structures and access macros used primarily by clients
+        */
+
+typedef        struct _XkbSymMapRec {
+       unsigned char    kt_index[XkbNumKbdGroups];
+       unsigned char    group_info;
+       unsigned char    width;
+       unsigned short   offset;
+} XkbSymMapRec, *XkbSymMapPtr;
+
+typedef struct _XkbClientMapRec {
+       unsigned char            size_types;
+       unsigned char            num_types;
+       XkbKeyTypePtr            types;
+
+       unsigned short           size_syms;
+       unsigned short           num_syms;
+       KeySym                  *syms;
+       XkbSymMapPtr             key_sym_map;
+
+       unsigned char           *modmap;
+} XkbClientMapRec, *XkbClientMapPtr;
+
+#define        XkbCMKeyGroupInfo(m,k)  ((m)->key_sym_map[k].group_info)
+#define        XkbCMKeyNumGroups(m,k)   (XkbNumGroups((m)->key_sym_map[k].group_info))
+#define        XkbCMKeyGroupWidth(m,k,g) (XkbCMKeyType(m,k,g)->num_levels)
+#define        XkbCMKeyGroupsWidth(m,k) ((m)->key_sym_map[k].width)
+#define        XkbCMKeyTypeIndex(m,k,g) ((m)->key_sym_map[k].kt_index[g&0x3])
+#define        XkbCMKeyType(m,k,g)      (&(m)->types[XkbCMKeyTypeIndex(m,k,g)])
+#define        XkbCMKeyNumSyms(m,k) (XkbCMKeyGroupsWidth(m,k)*XkbCMKeyNumGroups(m,k))
+#define        XkbCMKeySymsOffset(m,k) ((m)->key_sym_map[k].offset)
+#define        XkbCMKeySymsPtr(m,k)    (&(m)->syms[XkbCMKeySymsOffset(m,k)])
+
+       /*
+        * Compatibility structures and access macros
+        */
+
+typedef struct _XkbSymInterpretRec {
+       KeySym          sym;
+       unsigned char   flags;
+       unsigned char   match;
+       unsigned char   mods;
+       unsigned char   virtual_mod;
+       XkbAnyAction    act;
+} XkbSymInterpretRec,*XkbSymInterpretPtr;
+
+typedef struct _XkbCompatMapRec {
+       XkbSymInterpretPtr       sym_interpret;
+       XkbModsRec               groups[XkbNumKbdGroups];
+       unsigned short           num_si;
+       unsigned short           size_si;
+} XkbCompatMapRec, *XkbCompatMapPtr;
+
+typedef struct _XkbIndicatorMapRec {
+       unsigned char   flags;
+       unsigned char   which_groups;
+       unsigned char   groups;
+       unsigned char   which_mods;
+       XkbModsRec      mods;
+       unsigned int    ctrls;
+} XkbIndicatorMapRec, *XkbIndicatorMapPtr;
+
+#define        XkbIM_IsAuto(i) ((((i)->flags&XkbIM_NoAutomatic)==0)&&\
+                           (((i)->which_groups&&(i)->groups)||\
+                            ((i)->which_mods&&(i)->mods.mask)||\
+                            ((i)->ctrls)))
+#define        XkbIM_InUse(i)  (((i)->flags)||((i)->which_groups)||\
+                                       ((i)->which_mods)||((i)->ctrls))
+       
+
+typedef struct _XkbIndicatorRec {
+       unsigned long           phys_indicators;
+       XkbIndicatorMapRec      maps[XkbNumIndicators];
+} XkbIndicatorRec,*XkbIndicatorPtr;
+
+typedef        struct _XkbKeyNameRec {
+       char    name[XkbKeyNameLength];
+} XkbKeyNameRec,*XkbKeyNamePtr;
+
+typedef struct _XkbKeyAliasRec {
+       char    real[XkbKeyNameLength];
+       char    alias[XkbKeyNameLength];
+} XkbKeyAliasRec,*XkbKeyAliasPtr;
+
+       /*
+        * Names for everything 
+        */
+typedef struct _XkbNamesRec {
+       Atom              keycodes;
+       Atom              geometry;
+       Atom              symbols;
+       Atom              types;
+       Atom              compat;
+       Atom              vmods[XkbNumVirtualMods];
+       Atom              indicators[XkbNumIndicators];
+       Atom              groups[XkbNumKbdGroups];
+       XkbKeyNamePtr     keys;
+       XkbKeyAliasPtr    key_aliases;
+       Atom             *radio_groups;
+       Atom              phys_symbols;
+
+       unsigned char     num_keys;
+       unsigned char     num_key_aliases;
+       unsigned short    num_rg;
+} XkbNamesRec,*XkbNamesPtr;
+
+typedef        struct _XkbGeometry     *XkbGeometryPtr;
+       /*
+        * Tie it all together into one big keyboard description
+        */
+typedef        struct _XkbDesc {
+       struct _XDisplay *      dpy;
+       unsigned short          flags;
+       unsigned short          device_spec;
+       KeyCode                 min_key_code;
+       KeyCode                 max_key_code;
+
+       XkbControlsPtr          ctrls;
+       XkbServerMapPtr         server;
+       XkbClientMapPtr         map;
+       XkbIndicatorPtr         indicators;
+       XkbNamesPtr             names;
+       XkbCompatMapPtr         compat;
+       XkbGeometryPtr          geom;
+} XkbDescRec, *XkbDescPtr;
+#define        XkbKeyKeyTypeIndex(d,k,g)       (XkbCMKeyTypeIndex((d)->map,k,g))
+#define        XkbKeyKeyType(d,k,g)            (XkbCMKeyType((d)->map,k,g))
+#define        XkbKeyGroupWidth(d,k,g)         (XkbCMKeyGroupWidth((d)->map,k,g))
+#define        XkbKeyGroupsWidth(d,k)          (XkbCMKeyGroupsWidth((d)->map,k))
+#define        XkbKeyGroupInfo(d,k)            (XkbCMKeyGroupInfo((d)->map,(k)))
+#define        XkbKeyNumGroups(d,k)            (XkbCMKeyNumGroups((d)->map,(k)))
+#define        XkbKeyNumSyms(d,k)              (XkbCMKeyNumSyms((d)->map,(k)))
+#define        XkbKeySymsPtr(d,k)              (XkbCMKeySymsPtr((d)->map,(k)))
+#define        XkbKeySym(d,k,n)                (XkbKeySymsPtr(d,k)[n])
+#define        XkbKeySymEntry(d,k,sl,g) \
+       (XkbKeySym(d,k,((XkbKeyGroupsWidth(d,k)*(g))+(sl))))
+#define        XkbKeyAction(d,k,n) \
+       (XkbKeyHasActions(d,k)?&XkbKeyActionsPtr(d,k)[n]:NULL)
+#define        XkbKeyActionEntry(d,k,sl,g) \
+       (XkbKeyHasActions(d,k)?\
+               XkbKeyAction(d,k,((XkbKeyGroupsWidth(d,k)*(g))+(sl))):NULL)
+
+#define        XkbKeyHasActions(d,k)   ((d)->server->key_acts[k]!=0)
+#define        XkbKeyNumActions(d,k)   (XkbKeyHasActions(d,k)?XkbKeyNumSyms(d,k):1)
+#define        XkbKeyActionsPtr(d,k)   (XkbSMKeyActionsPtr((d)->server,k))
+#define        XkbKeycodeInRange(d,k)  (((k)>=(d)->min_key_code)&&\
+                                ((k)<=(d)->max_key_code))
+#define        XkbNumKeys(d)           ((d)->max_key_code-(d)->min_key_code+1)
+
+
+       /*
+        * The following structures can be used to track changes
+        * to a keyboard device
+        */
+typedef struct _XkbMapChanges {
+       unsigned short           changed;
+       KeyCode                  min_key_code;
+       KeyCode                  max_key_code;
+       unsigned char            first_type;
+       unsigned char            num_types;
+       KeyCode                  first_key_sym;
+       unsigned char            num_key_syms;
+       KeyCode                  first_key_act;
+       unsigned char            num_key_acts;
+       KeyCode                  first_key_behavior;
+       unsigned char            num_key_behaviors;
+       KeyCode                  first_key_explicit;
+       unsigned char            num_key_explicit;
+       KeyCode                  first_modmap_key;
+       unsigned char            num_modmap_keys;
+       KeyCode                  first_vmodmap_key;
+       unsigned char            num_vmodmap_keys;
+       unsigned char            pad;
+       unsigned short           vmods;
+} XkbMapChangesRec,*XkbMapChangesPtr;
+
+typedef struct _XkbControlsChanges {
+       unsigned int             changed_ctrls;
+       unsigned int             enabled_ctrls_changes;
+       Bool                     num_groups_changed;
+} XkbControlsChangesRec,*XkbControlsChangesPtr;
+
+typedef struct _XkbIndicatorChanges {
+       unsigned int             state_changes;
+       unsigned int             map_changes;
+} XkbIndicatorChangesRec,*XkbIndicatorChangesPtr;
+
+typedef struct _XkbNameChanges {
+       unsigned int            changed;
+       unsigned char           first_type;
+       unsigned char           num_types;
+       unsigned char           first_lvl;
+       unsigned char           num_lvls;
+       unsigned char           num_aliases;
+       unsigned char           num_rg;
+       unsigned char           first_key;
+       unsigned char           num_keys;
+       unsigned short          changed_vmods;
+       unsigned long           changed_indicators;
+       unsigned char           changed_groups;
+} XkbNameChangesRec,*XkbNameChangesPtr;
+
+typedef struct _XkbCompatChanges {
+       unsigned char           changed_groups;
+       unsigned short          first_si;
+       unsigned short          num_si;
+} XkbCompatChangesRec,*XkbCompatChangesPtr;
+
+typedef struct _XkbChanges {
+       unsigned short           device_spec;
+       unsigned short           state_changes;
+       XkbMapChangesRec         map;
+       XkbControlsChangesRec    ctrls;
+       XkbIndicatorChangesRec   indicators;
+       XkbNameChangesRec        names;
+       XkbCompatChangesRec      compat;
+} XkbChangesRec, *XkbChangesPtr;
+
+       /*
+        * These data structures are used to construct a keymap from 
+        * a set of components or to list components in the server
+        * database.
+        */
+typedef struct _XkbComponentNames {
+       char *                   keymap;
+       char *                   keycodes;
+       char *                   types;
+       char *                   compat;
+       char *                   symbols;
+       char *                   geometry;
+} XkbComponentNamesRec, *XkbComponentNamesPtr;
+
+typedef struct _XkbComponentName {
+       unsigned short          flags;
+       char *                  name;
+} XkbComponentNameRec,*XkbComponentNamePtr;
+
+typedef struct _XkbComponentList {
+       int                     num_keymaps;
+       int                     num_keycodes;
+       int                     num_types;
+       int                     num_compat;
+       int                     num_symbols;
+       int                     num_geometry;
+       XkbComponentNamePtr     keymaps;
+       XkbComponentNamePtr     keycodes;
+       XkbComponentNamePtr     types;
+       XkbComponentNamePtr     compat;
+       XkbComponentNamePtr     symbols;
+       XkbComponentNamePtr     geometry;
+} XkbComponentListRec, *XkbComponentListPtr;
+
+       /*
+        * The following data structures describe and track changes to a 
+        * non-keyboard extension device 
+        */
+typedef struct _XkbDeviceLedInfo {
+       unsigned short                  led_class;
+       unsigned short                  led_id;
+       unsigned int                    phys_indicators;
+       unsigned int                    maps_present;
+       unsigned int                    names_present;
+       unsigned int                    state;
+       Atom                            names[XkbNumIndicators];
+       XkbIndicatorMapRec              maps[XkbNumIndicators];
+} XkbDeviceLedInfoRec,*XkbDeviceLedInfoPtr;
+
+typedef struct _XkbDeviceInfo {
+       char *                  name;
+       Atom                    type;
+       unsigned short          device_spec;
+       Bool                    has_own_state;
+       unsigned short          supported;
+       unsigned short          unsupported;
+
+       unsigned short          num_btns;
+       XkbAction *             btn_acts;
+
+       unsigned short          sz_leds;
+       unsigned short          num_leds;
+       unsigned short          dflt_kbd_fb;
+       unsigned short          dflt_led_fb;
+       XkbDeviceLedInfoPtr     leds;
+} XkbDeviceInfoRec,*XkbDeviceInfoPtr;
+
+#define        XkbXI_DevHasBtnActs(d)  (((d)->num_btns>0)&&((d)->btn_acts!=NULL))
+#define        XkbXI_LegalDevBtn(d,b)  (XkbXI_DevHasBtnActs(d)&&((b)<(d)->num_btns))
+#define        XkbXI_DevHasLeds(d)     (((d)->num_leds>0)&&((d)->leds!=NULL))
+
+typedef struct _XkbDeviceLedChanges {
+       unsigned short          led_class;
+       unsigned short          led_id;
+       unsigned int            defined; /* names or maps changed */
+       struct _XkbDeviceLedChanges *next;
+} XkbDeviceLedChangesRec,*XkbDeviceLedChangesPtr;
+
+typedef struct _XkbDeviceChanges {
+       unsigned int            changed;
+       unsigned short          first_btn;
+       unsigned short          num_btns;
+       XkbDeviceLedChangesRec  leds;
+} XkbDeviceChangesRec,*XkbDeviceChangesPtr;
+
+#endif /* _XKBSTR_H_ */
diff --git a/Xserver/include/extensions/XLbx.h b/Xserver/include/extensions/XLbx.h
new file mode 100644 (file)
index 0000000..1514721
--- /dev/null
@@ -0,0 +1,144 @@
+/* $XConsortium: XLbx.h /main/21 1996/12/15 21:23:54 rws $ */
+/*
+ * Copyright 1992 Network Computing Devices
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the name of NCD. not be used in advertising or
+ * publicity pertaining to distribution of the software without specific,
+ * written prior permission.  NCD. makes no representations about the
+ * suitability of this software for any purpose.  It is provided "as is"
+ * without express or implied warranty.
+ *
+ * NCD. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL NCD.
+ * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
+ * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN 
+ * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ */
+#ifndef _XLBX_H_
+#define _XLBX_H_
+
+#include <X11/Xfuncproto.h>
+
+/*
+ * NOTE:  any changes or additions to the opcodes needs to be reflected
+ * in the lbxCacheable array in Xserver/lbx/lbxmain.c
+ */
+#define X_LbxQueryVersion              0
+#define X_LbxStartProxy                        1
+#define X_LbxStopProxy                 2
+#define X_LbxSwitch                    3
+#define X_LbxNewClient                 4
+#define X_LbxCloseClient               5
+#define X_LbxModifySequence            6
+#define X_LbxAllowMotion               7
+#define X_LbxIncrementPixel            8
+#define X_LbxDelta                     9
+#define        X_LbxGetModifierMapping         10
+#define        X_LbxInvalidateTag              12
+#define X_LbxPolyPoint                 13
+#define X_LbxPolyLine                  14
+#define X_LbxPolySegment               15
+#define X_LbxPolyRectangle             16
+#define X_LbxPolyArc                   17
+#define X_LbxFillPoly                  18
+#define X_LbxPolyFillRectangle         19
+#define X_LbxPolyFillArc               20
+#define        X_LbxGetKeyboardMapping         21
+#define        X_LbxQueryFont                  22
+#define        X_LbxChangeProperty             23
+#define        X_LbxGetProperty                24
+#define        X_LbxTagData                    25
+
+#define X_LbxCopyArea                  26
+#define X_LbxCopyPlane                 27
+#define X_LbxPolyText8                 28
+#define X_LbxPolyText16                        29
+#define X_LbxImageText8                        30
+#define X_LbxImageText16               31
+
+#define X_LbxQueryExtension            32
+#define X_LbxPutImage                  33
+#define X_LbxGetImage                  34
+
+#define X_LbxBeginLargeRequest         35
+#define X_LbxLargeRequestData          36
+#define X_LbxEndLargeRequest           37
+
+#define X_LbxInternAtoms               38
+#define X_LbxGetWinAttrAndGeom         39
+
+#define X_LbxGrabCmap                  40
+#define X_LbxReleaseCmap               41
+#define X_LbxAllocColor                        42
+
+#define X_LbxSync                      43
+
+#define LbxNumberReqs                  44
+
+
+#define LbxEvent                       0
+#define LbxQuickMotionDeltaEvent       1
+#define LbxNumberEvents                        2
+
+/* This is always the master client */
+#define LbxMasterClientIndex           0
+
+/* LbxEvent lbxType sub-fields */
+#define LbxSwitchEvent                 0
+#define LbxCloseEvent                  1
+#define LbxDeltaEvent                  2
+#define LbxInvalidateTagEvent          3
+#define LbxSendTagDataEvent            4
+#define LbxListenToOne                 5
+#define LbxListenToAll                 6
+#define LbxMotionDeltaEvent            7
+#define LbxReleaseCmapEvent            8
+#define LbxFreeCellsEvent              9
+
+/*
+ * Lbx image compression methods
+ *
+ * No compression is always assigned the value of 0.
+ *
+ * The rest of the compression method opcodes are assigned dynamically
+ * at option negotiation time.
+ */
+
+#define LbxImageCompressNone           0
+
+
+#define BadLbxClient                   0
+#define LbxNumberErrors                        (BadLbxClient + 1)
+
+/* tagged data types */
+#define        LbxTagTypeModmap                1
+#define        LbxTagTypeKeymap                2
+#define        LbxTagTypeProperty              3
+#define        LbxTagTypeFont                  4
+#define        LbxTagTypeConnInfo              5
+
+#ifndef _XLBX_SERVER_
+
+_XFUNCPROTOBEGIN
+
+Bool XLbxQueryVersion(
+#if NeedFunctionPrototypes
+    Display*           /* dpy */,
+    int*               /* majorVersion */,
+    int*               /* minorVersion */
+#endif
+);
+
+_XFUNCPROTOEND
+
+#endif
+
+#endif
diff --git a/Xserver/include/extensions/XShm.h b/Xserver/include/extensions/XShm.h
new file mode 100644 (file)
index 0000000..f037921
--- /dev/null
@@ -0,0 +1,170 @@
+/************************************************************
+
+Copyright (c) 1989  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+********************************************************/
+
+/* THIS IS NOT AN X CONSORTIUM STANDARD */
+
+/* $XConsortium: XShm.h,v 1.7 94/09/22 21:25:20 dpw Exp $ */
+
+
+
+
+/* $XFree86: xc/include/extensions/XShm.h,v 1.2.2.1 1997/08/04 02:10:32 dawes Exp $ */
+
+#ifndef _XSHM_H_
+#define _XSHM_H_
+
+#include <X11/Xfuncproto.h>
+
+#define X_ShmQueryVersion              0
+#define X_ShmAttach                    1
+#define X_ShmDetach                    2
+#define X_ShmPutImage                  3
+#define X_ShmGetImage                  4
+#define X_ShmCreatePixmap              5
+
+#define ShmCompletion                  0
+#define ShmNumberEvents                        (ShmCompletion + 1)
+
+#define BadShmSeg                      0
+#define ShmNumberErrors                        (BadShmSeg + 1)
+
+typedef unsigned long ShmSeg;
+
+#ifndef _XSHM_SERVER_
+typedef struct {
+    int        type;               /* of event */
+    unsigned long serial;   /* # of last request processed by server */
+    Bool send_event;       /* true if this came frome a SendEvent request */
+    Display *display;      /* Display the event was read from */
+    Drawable drawable;     /* drawable of request */
+    int major_code;        /* ShmReqCode */
+    int minor_code;        /* X_ShmPutImage */
+    ShmSeg shmseg;         /* the ShmSeg used in the request */
+    unsigned long offset;   /* the offset into ShmSeg used in the request */
+} XShmCompletionEvent;
+
+typedef struct {
+    ShmSeg shmseg;     /* resource id */
+    int shmid;         /* kernel id */
+    char *shmaddr;     /* address in client */
+    Bool readOnly;     /* how the server should attach it */
+} XShmSegmentInfo;
+
+_XFUNCPROTOBEGIN
+
+Bool XShmQueryExtension(
+#if NeedFunctionPrototypes
+    Display*            /* dpy */
+#endif
+);
+
+Bool XShmQueryVersion(
+#if NeedFunctionPrototypes
+    Display*           /* dpy */,
+    int*               /* majorVersion */,
+    int*               /* minorVersion */,
+    Bool*              /* sharedPixmaps */
+#endif
+);
+
+int XShmPixmapFormat(
+#if NeedFunctionPrototypes
+    Display*           /* dpy */
+#endif
+);
+
+Status XShmAttach(
+#if NeedFunctionPrototypes
+    Display*           /* dpy */,
+    XShmSegmentInfo*   /* shminfo */
+#endif
+);
+
+Status XShmDetach(
+#if NeedFunctionPrototypes
+    Display*           /* dpy */,
+    XShmSegmentInfo*   /* shminfo */
+#endif
+);
+
+Status XShmPutImage(
+#if NeedFunctionPrototypes
+    Display*           /* dpy */,
+    Drawable           /* d */,
+    GC                 /* gc */,
+    XImage*            /* image */,
+    int                        /* src_x */,
+    int                        /* src_y */,
+    int                        /* dst_x */,
+    int                        /* dst_y */,
+    unsigned int       /* src_width */,
+    unsigned int       /* src_height */,
+    Bool               /* send_event */
+#endif
+);
+
+Status XShmGetImage(
+#if NeedFunctionPrototypes
+    Display*           /* dpy */,
+    Drawable           /* d */,
+    XImage*            /* image */,
+    int                        /* x */,
+    int                        /* y */,
+    unsigned long      /* plane_mask */
+#endif
+);
+
+XImage *XShmCreateImage(
+#if NeedFunctionPrototypes
+    Display*           /* dpy */,
+    Visual*            /* visual */,
+    unsigned int       /* depth */,
+    int                        /* format */,
+    char*              /* data */,
+    XShmSegmentInfo*   /* shminfo */,
+    unsigned int       /* width */,
+    unsigned int       /* height */
+#endif
+);
+
+Pixmap XShmCreatePixmap(
+#if NeedFunctionPrototypes
+    Display*           /* dpy */,
+    Drawable           /* d */,
+    char*              /* data */,
+    XShmSegmentInfo*   /* shminfo */,
+    unsigned int       /* width */,
+    unsigned int       /* height */,
+    unsigned int       /* depth */
+#endif
+);
+
+_XFUNCPROTOEND
+
+#endif
+
+#endif
diff --git a/Xserver/include/extensions/XTest.h b/Xserver/include/extensions/XTest.h
new file mode 100644 (file)
index 0000000..2b525fb
--- /dev/null
@@ -0,0 +1,195 @@
+/* $XConsortium: XTest.h,v 1.9 94/04/17 20:11:18 rws Exp $ */
+/* $XFree86: xc/include/extensions/XTest.h,v 3.0 1996/12/12 09:12:53 dawes Exp $ */
+/*
+
+Copyright (c) 1992  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+*/
+
+#ifndef _XTEST_H_
+#define _XTEST_H_
+
+#include <X11/Xfuncproto.h>
+
+#define X_XTestGetVersion      0
+#define X_XTestCompareCursor   1
+#define X_XTestFakeInput       2
+#define X_XTestGrabControl     3
+
+#define XTestNumberEvents      0
+
+#define XTestNumberErrors      0
+
+#define XTestMajorVersion      2
+#define XTestMinorVersion      2
+
+#define XTestExtensionName     "XTEST"
+
+#ifndef _XTEST_SERVER_
+
+#include <X11/extensions/XInput.h>
+
+_XFUNCPROTOBEGIN
+
+Bool XTestQueryExtension(
+#if NeedFunctionPrototypes
+    Display*           /* dpy */,
+    int*               /* event_basep */,
+    int*               /* error_basep */,
+    int*               /* majorp */,
+    int*               /* minorp */
+#endif
+);
+
+Bool XTestCompareCursorWithWindow(
+#if NeedFunctionPrototypes
+    Display*           /* dpy */,
+    Window             /* window */,
+    Cursor             /* cursor */
+#endif
+);
+
+Bool XTestCompareCurrentCursorWithWindow(
+#if NeedFunctionPrototypes
+    Display*           /* dpy */,
+    Window             /* window */
+#endif
+);
+
+extern int XTestFakeKeyEvent(
+#if NeedFunctionPrototypes
+    Display*           /* dpy */,
+    unsigned int       /* keycode */,
+    Bool               /* is_press */,
+    unsigned long      /* delay */
+#endif
+);
+
+extern int XTestFakeButtonEvent(
+#if NeedFunctionPrototypes
+    Display*           /* dpy */,
+    unsigned int       /* button */,
+    Bool               /* is_press */,
+    unsigned long      /* delay */
+#endif
+);
+
+extern int XTestFakeMotionEvent(
+#if NeedFunctionPrototypes
+    Display*           /* dpy */,
+    int                        /* screen */,
+    int                        /* x */,
+    int                        /* y */,
+    unsigned long      /* delay */
+#endif
+);
+
+extern int XTestFakeRelativeMotionEvent(
+#if NeedFunctionPrototypes
+    Display*           /* dpy */,
+    int                        /* x */,
+    int                        /* y */,
+    unsigned long      /* delay */
+#endif
+);
+
+extern int XTestFakeDeviceKeyEvent(
+#if NeedFunctionPrototypes
+    Display*           /* dpy */,
+    XDevice*           /* dev */,
+    unsigned int       /* keycode */,
+    Bool               /* is_press */,
+    int*               /* axes */,
+    int                        /* n_axes */,
+    unsigned long      /* delay */
+#endif
+);
+
+extern int XTestFakeDeviceButtonEvent(
+#if NeedFunctionPrototypes
+    Display*           /* dpy */,
+    XDevice*           /* dev */,
+    unsigned int       /* button */,
+    Bool               /* is_press */,
+    int*               /* axes */,
+    int                        /* n_axes */,
+    unsigned long      /* delay */
+#endif
+);
+
+extern int XTestFakeProximityEvent(
+#if NeedFunctionPrototypes
+    Display*           /* dpy */,
+    XDevice*           /* dev */,
+    Bool               /* in_prox */,
+    int*               /* axes */,
+    int                        /* n_axes */,
+    unsigned long      /* delay */
+#endif
+);
+
+extern int XTestFakeDeviceMotionEvent(
+#if NeedFunctionPrototypes
+    Display*           /* dpy */,
+    XDevice*           /* dev */,
+    Bool               /* is_relative */,
+    int                        /* first_axis */,
+    int*               /* axes */,
+    int                        /* n_axes */,
+    unsigned long      /* delay */
+#endif
+);
+
+extern int XTestGrabControl(
+#if NeedFunctionPrototypes
+    Display*           /* dpy */,
+    Bool               /* impervious */
+#endif
+);
+
+void XTestSetGContextOfGC(
+#if NeedFunctionPrototypes
+    GC                 /* gc */,
+    GContext           /* gid */
+#endif
+);
+
+void XTestSetVisualIDOfVisual(
+#if NeedFunctionPrototypes
+    Visual*            /* visual */,
+    VisualID           /* visualid */
+#endif
+);
+
+Status XTestDiscard(
+#if NeedFunctionPrototypes
+    Display*           /* dpy */
+#endif
+);
+
+_XFUNCPROTOEND
+
+#endif /* _XTEST_SERVER_ */
+
+#endif
diff --git a/Xserver/include/extensions/Xag.h b/Xserver/include/extensions/Xag.h
new file mode 100644 (file)
index 0000000..4db6c22
--- /dev/null
@@ -0,0 +1,135 @@
+/*
+Copyright (c) 1996  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be included
+in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR
+OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall
+not be used in advertising or otherwise to promote the sale, use or
+other dealings in this Software without prior written authorization
+from the X Consortium.
+*/
+/* $XConsortium: Xag.h /main/2 1996/11/12 12:18:22 swick $ */
+
+#ifndef _XAG_H_
+#define _XAG_H_
+
+#include <X11/Xfuncproto.h>
+
+#define X_XagQueryVersion              0
+#define X_XagCreate                    1
+#define X_XagDestroy                   2
+#define X_XagGetAttr                   3
+#define X_XagQuery                     4
+#define X_XagCreateAssoc               5
+#define X_XagDestroyAssoc              6
+
+#define XagBadAppGroup                 0
+#define XagNumberErrors                        (XagBadAppGroup + 1)
+
+#define XagNsingleScreen               0
+#define XagNdefaultRoot                        1
+#define XagNrootVisual                 2
+#define XagNdefaultColormap            3
+#define XagNblackPixel                 4
+#define XagNwhitePixel                 5
+#define XagNappGroupLeader             6
+
+#ifndef _XAG_SERVER_
+
+#if NeedVarargsPrototypes
+#include <stdarg.h>
+#else
+#include <varargs.h>
+#endif
+
+_XFUNCPROTOBEGIN
+
+typedef XID XAppGroup;
+
+Bool XagQueryVersion(
+#if NeedFunctionPrototypes
+    Display*                   /* dpy */,
+    int*                       /* major_version */,
+    int*                       /* minor_version */
+#endif
+);
+
+Status XagCreateEmbeddedApplicationGroup(
+#if NeedFunctionPrototypes
+    Display*                   /* dpy */,
+    VisualID                   /* root_visual */,
+    Colormap                   /* default_colormap */,
+    unsigned long              /* black_pixel */,
+    unsigned long              /* white_pixel */,
+    XAppGroup*                 /* app_group_return */
+#endif
+);
+
+Status XagCreateNonembeddedApplicationGroup(
+#if NeedFunctionPrototypes
+    Display*                   /* dpy */,
+    XAppGroup*                 /* app_group_return */
+#endif
+);
+
+Status XagDestroyApplicationGroup(
+#if NeedFunctionPrototypes
+    Display*                   /* dpy */,
+    XAppGroup                  /* app_group */
+#endif
+);
+
+Status XagGetApplicationGroupAttributes(
+#if NeedVarargsPrototypes
+    Display*                   /* dpy */,
+    XAppGroup                  /* app_group */,
+    ...
+#endif
+);
+
+Status XagQueryApplicationGroup(
+#if NeedFunctionPrototypes
+    Display*                   /* dpy */,
+    XID                                /* resource_base */,
+    XAppGroup*                 /* app_group_ret */
+#endif
+);
+
+Status XagCreateAssociation(
+#if NeedFunctionPrototypes
+    Display*                   /* dpy */,
+    Window*                    /* window_ret */,
+    void*                      /* system_window */
+#endif
+);
+
+Status XagDestroyAssociation(
+#if NeedFunctionPrototypes
+    Display*                   /* dpy */,
+    Window                     /* window */
+#endif
+);
+
+_XFUNCPROTOEND
+
+#endif /* _XAG_SERVER_ */
+
+#endif /* _XAG_H_ */
+
diff --git a/Xserver/include/extensions/Xagsrv.h b/Xserver/include/extensions/Xagsrv.h
new file mode 100644 (file)
index 0000000..1ebed78
--- /dev/null
@@ -0,0 +1,93 @@
+/*
+Copyright (c) 1996  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be included
+in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR
+OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall
+not be used in advertising or otherwise to promote the sale, use or
+other dealings in this Software without prior written authorization
+from the X Consortium.
+*/
+/* $XConsortium: Xagsrv.h /main/7 1996/11/22 14:48:37 kaleb $ */
+
+#ifndef _XAGSRV_H_
+#define _XAGSRV_H_
+
+extern void XagExtensionInit(
+#if NeedFunctionPrototypes
+    void
+#endif
+);
+
+extern void XagConnectionInfo(
+#if NeedFunctionPrototypes
+    ClientPtr                  /* client */,
+    xConnSetupPrefix**         /* conn_prefix */,
+    char**                     /* conn_info */,
+    int*                       /* num_screens */
+#endif
+);
+
+extern VisualID XagRootVisual(
+#if NeedFunctionPrototypes
+    ClientPtr                  /* client */
+#endif
+);
+
+extern Colormap XagDefaultColormap(
+#if NeedFunctionPrototypes
+    ClientPtr                  /* client */
+#endif
+);
+
+extern ClientPtr XagLeader(
+#if NeedFunctionPrototypes
+    ClientPtr                  /* client */
+#endif
+);
+
+extern void XagCallClientStateChange(
+#if NeedFunctionPrototypes
+    ClientPtr                  /* client */
+#endif
+);
+
+extern Bool XagIsControlledRoot (
+#if NeedFunctionPrototypes
+    ClientPtr                  /* client */,
+    WindowPtr                  /* pParent */
+#endif
+);
+
+extern XID XagId (
+#if NeedFunctionPrototypes
+    ClientPtr                  /* client */
+#endif
+);
+
+extern void XagGetDeltaInfo (
+#if NeedFunctionPrototypes
+    ClientPtr                  /* client */,
+    CARD32*                    /* buf */
+#endif
+);
+
+#endif /* _XAGSRV_H_ */
+
diff --git a/Xserver/include/extensions/Xagstr.h b/Xserver/include/extensions/Xagstr.h
new file mode 100644 (file)
index 0000000..f739158
--- /dev/null
@@ -0,0 +1,164 @@
+/*
+Copyright (c) 1996  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be included
+in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR
+OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall
+not be used in advertising or otherwise to promote the sale, use or
+other dealings in this Software without prior written authorization
+from the X Consortium.
+*/
+/* $XConsortium: Xagstr.h /main/3 1996/11/12 12:19:03 swick $ */
+
+#ifndef _XAGSTR_H_ /* { */
+#define _XAGSTR_H_
+
+#include "Xag.h"
+
+#define XAppGroup CARD32
+
+#define XAGNAME "XC-APPGROUP"
+
+#define XAG_MAJOR_VERSION      1       /* current version numbers */
+#define XAG_MINOR_VERSION      0
+
+#define XagWindowTypeX11       0
+#define XagWindowTypeMacintosh 1
+#define XagWindowTypeWin32     2
+#define XagWindowTypeWin16     3
+
+typedef struct _XagQueryVersion {
+    CARD8      reqType;        /* always XagReqCode */
+    CARD8      xagReqType;     /* always X_XagQueryVersion */
+    CARD16     length B16;
+    CARD16     client_major_version B16;
+    CARD16     client_minor_version B16;
+} xXagQueryVersionReq;
+#define sz_xXagQueryVersionReq         8
+
+typedef struct {
+    BYTE       type;           /* X_Reply */
+    BOOL       pad1;
+    CARD16     sequence_number B16;
+    CARD32     length B32;
+    CARD16     server_major_version B16;
+    CARD16     server_minor_version B16;
+    CARD32     pad2 B32;
+    CARD32     pad3 B32;
+    CARD32     pad4 B32;
+    CARD32     pad5 B32;
+    CARD32     pad6 B32;
+} xXagQueryVersionReply;
+#define sz_xXagQueryVersionReply       32
+
+/* Set AppGroup Attributes masks */
+#define XagSingleScreenMask            1 << XagNsingleScreen
+#define XagDefaultRootMask             1 << XagNdefaultRoot
+#define XagRootVisualMask              1 << XagNrootVisual
+#define XagDefaultColormapMask         1 << XagNdefaultColormap
+#define XagBlackPixelMask              1 << XagNblackPixel
+#define XagWhitePixelMask              1 << XagNwhitePixel
+#define XagAppGroupLeaderMask          1 << XagNappGroupLeader
+
+typedef struct _XagCreate {
+    CARD8      reqType;        /* always XagReqCode */
+    CARD8      xagReqType;     /* always X_XagCreate */
+    CARD16     length B16;
+    XAppGroup  app_group B32;
+    CARD32     attrib_mask B32; /* LISTofVALUE follows */
+} xXagCreateReq;
+#define sz_xXagCreateReq               12
+
+typedef struct _XagDestroy {
+    CARD8      reqType;        /* always XagReqCode */
+    CARD8      xagReqType;     /* always X_XagDestroy */
+    CARD16     length B16;
+    XAppGroup  app_group  B32;
+} xXagDestroyReq;
+#define sz_xXagDestroyReq              8
+
+typedef struct _XagGetAttr {
+    CARD8      reqType;        /* always XagReqCode */
+    CARD8      xagReqType;     /* always X_XagGetAttr */
+    CARD16     length B16;
+    XAppGroup  app_group B32;
+} xXagGetAttrReq;
+#define sz_xXagGetAttrReq              8
+
+typedef struct {
+    BYTE       type;           /* X_Reply */
+    BOOL       pad1;
+    CARD16     sequence_number B16;
+    CARD32     length B32;
+    Window     default_root B32;
+    VisualID   root_visual B32;
+    Colormap   default_colormap B32;
+    CARD32     black_pixel B32;
+    CARD32     white_pixel B32;
+    BOOL       single_screen;
+    BOOL       app_group_leader;
+    CARD16     pad2 B16;
+} xXagGetAttrReply;
+#define sz_xXagGetAttrReply            32
+
+typedef struct _XagQuery {
+    CARD8      reqType;        /* always XagReqCode */
+    CARD8      xagReqType;     /* always X_XagQuery */
+    CARD16     length B16;
+    CARD32     resource B32;
+} xXagQueryReq;
+#define sz_xXagQueryReq                        8
+
+typedef struct {
+    BYTE       type;           /* X_Reply */
+    BOOL       pad1;
+    CARD16     sequence_number B16;
+    CARD32     length B32;
+    XAppGroup  app_group B32;
+    CARD32     pad2 B32;
+    CARD32     pad3 B32;
+    CARD32     pad4 B32;
+    CARD32     pad5 B32;
+    CARD32     pad6 B32;
+} xXagQueryReply;
+#define sz_xXagQueryReply              32
+
+typedef struct _XagCreateAssoc {
+    CARD8      reqType;        /* always XagReqCode */
+    CARD8      xagReqType;     /* always X_XagCreateAssoc */
+    CARD16     length B16;
+    Window     window B32;
+    CARD16     window_type B16;
+    CARD16     system_window_len B16; /* LISTofCARD8 follows */
+} xXagCreateAssocReq;
+#define sz_xXagCreateAssocReq          12
+
+typedef struct _XagDestroyAssoc {
+    CARD8      reqType;        /* always XagReqCode */
+    CARD8      xagReqType;     /* always X_XagDestroyAssoc */
+    CARD16     length B16;
+    Window     window B32;
+} xXagDestroyAssocReq;
+#define sz_xXagDestroyAssocReq         8
+
+#undef XAppGroup
+
+#endif /* } _XAGSTR_H_ */
+
diff --git a/Xserver/include/extensions/Xdbe.h b/Xserver/include/extensions/Xdbe.h
new file mode 100644 (file)
index 0000000..ef38fd3
--- /dev/null
@@ -0,0 +1,154 @@
+/* $XConsortium: Xdbe.h /main/3 1995/09/22 10:20:01 dpw $ */
+/******************************************************************************
+ * 
+ * Copyright (c) 1994, 1995  Hewlett-Packard Company
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ * 
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ * 
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL HEWLETT-PACKARD COMPANY BE LIABLE FOR ANY CLAIM,
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
+ * THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ * 
+ * Except as contained in this notice, the name of the Hewlett-Packard
+ * Company shall not be used in advertising or otherwise to promote the
+ * sale, use or other dealings in this Software without prior written
+ * authorization from the Hewlett-Packard Company.
+ * 
+ *     Header file for Xlib-related DBE
+ *
+ *****************************************************************************/
+
+
+#ifndef XDBE_H
+#define XDBE_H
+
+
+/* INCLUDES */
+
+#include <X11/Xfuncproto.h>
+#include "Xdbeproto.h"
+
+
+/* DEFINES */
+
+/* Errors */
+#define XdbeBadBuffer    0
+
+
+/* TYPEDEFS */
+
+typedef Drawable XdbeBackBuffer;
+
+typedef unsigned char XdbeSwapAction;
+
+typedef struct
+{
+    Window             swap_window;    /* window for which to swap buffers   */
+    XdbeSwapAction     swap_action;    /* swap action to use for swap_window */
+}
+XdbeSwapInfo;
+
+typedef struct
+{
+    Window     window;                 /* window that buffer belongs to */
+}
+XdbeBackBufferAttributes;
+
+typedef struct
+{
+    int                        type;
+    Display            *display;       /* display the event was read from */
+    XdbeBackBuffer     buffer;         /* resource id                     */
+    unsigned long      serial;         /* serial number of failed request */
+    unsigned char      error_code;     /* error base + XdbeBadBuffer      */
+    unsigned char      request_code;   /* major opcode of failed request  */
+    unsigned char      minor_code;     /* minor opcode of failed request  */
+}
+XdbeBufferError;
+
+/* _XFUNCPROTOBEGIN and _XFUNCPROTOEND are defined as noops
+ * (for non-C++ builds) in X11/Xfuncproto.h.
+ */
+_XFUNCPROTOBEGIN
+
+extern Status XdbeQueryExtension(
+#if NeedFunctionPrototypes
+    Display*           /* dpy                  */,
+    int*               /* major_version_return */,
+    int*               /* minor_version_return */
+#endif
+);
+
+extern XdbeBackBuffer XdbeAllocateBackBufferName(
+#if NeedFunctionPrototypes
+    Display*           /* dpy         */,
+    Window             /* window      */,
+    XdbeSwapAction     /* swap_action */
+#endif
+);
+
+extern Status XdbeDeallocateBackBufferName(
+#if NeedFunctionPrototypes
+    Display*           /* dpy    */,
+    XdbeBackBuffer     /* buffer */
+#endif
+);
+
+extern Status XdbeSwapBuffers(
+#if NeedFunctionPrototypes
+    Display*           /* dpy         */,
+    XdbeSwapInfo*      /* swap_info   */,
+    int                        /* num_windows */
+#endif
+);
+
+extern Status XdbeBeginIdiom(
+#if NeedFunctionPrototypes
+    Display*           /* dpy */
+#endif
+);
+
+extern Status XdbeEndIdiom(
+#if NeedFunctionPrototypes
+    Display*           /* dpy */
+#endif
+);
+
+extern XdbeScreenVisualInfo *XdbeGetVisualInfo(
+#if NeedFunctionPrototypes
+    Display*           /* dpy               */,
+    Drawable*          /* screen_specifiers */,
+    int*               /* num_screens       */
+#endif
+);
+
+extern void XdbeFreeVisualInfo(
+#if NeedFunctionPrototypes
+    XdbeScreenVisualInfo*      /* visual_info */
+#endif
+);
+
+extern XdbeBackBufferAttributes *XdbeGetBackBufferAttributes(
+#if NeedFunctionPrototypes
+    Display*           /* dpy    */,
+    XdbeBackBuffer     /* buffer */
+#endif
+);
+
+_XFUNCPROTOEND
+
+#endif /* XDBE_H */
+
diff --git a/Xserver/include/extensions/Xdbeproto.h b/Xserver/include/extensions/Xdbeproto.h
new file mode 100644 (file)
index 0000000..e347373
--- /dev/null
@@ -0,0 +1,277 @@
+/* $XConsortium: Xdbeproto.h /main/3 1995/09/22 10:20:16 dpw $ */
+/******************************************************************************
+ * 
+ * Copyright (c) 1994, 1995  Hewlett-Packard Company
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ * 
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ * 
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL HEWLETT-PACKARD COMPANY BE LIABLE FOR ANY CLAIM,
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
+ * THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ * 
+ * Except as contained in this notice, the name of the Hewlett-Packard
+ * Company shall not be used in advertising or otherwise to promote the
+ * sale, use or other dealings in this Software without prior written
+ * authorization from the Hewlett-Packard Company.
+ * 
+ *     Header file for Xlib-related DBE
+ *
+ *****************************************************************************/
+
+
+#ifndef XDBE_PROTO_H
+#define XDBE_PROTO_H
+
+/* INCLUDES */
+
+
+/* DEFINES */
+
+/* Values for swap_action field of XdbeSwapInfo structure */
+#define XdbeUndefined    0
+#define XdbeBackground   1
+#define XdbeUntouched    2
+#define XdbeCopied       3
+
+#ifdef NEED_DBE_PROTOCOL
+
+#define DBE_PROTOCOL_NAME "DOUBLE-BUFFER"
+
+/* Current version numbers */
+#define DBE_MAJOR_VERSION       1
+#define DBE_MINOR_VERSION       0
+
+/* Used when adding extension; also used in Xdbe macros */
+#define DbeNumberEvents                        0
+#define DbeBadBuffer                   0
+#define DbeNumberErrors                        (DbeBadBuffer + 1)
+
+/* Request values used in (S)ProcDbeDispatch() */
+#define X_DbeGetVersion                 0
+#define X_DbeAllocateBackBufferName     1
+#define X_DbeDeallocateBackBufferName   2
+#define X_DbeSwapBuffers                3
+#define X_DbeBeginIdiom                 4
+#define X_DbeEndIdiom                   5
+#define X_DbeGetVisualInfo              6
+#define X_DbeGetBackBufferAttributes    7
+
+typedef CARD8  xDbeSwapAction;
+typedef CARD32 xDbeBackBuffer;
+
+#endif /* NEED_DBE_PROTOCOL */
+
+
+/* TYPEDEFS */
+
+/* Client data types */
+
+/* XdbeVisualInfo and XdbeScreenVisualInfo are defined in this file,
+ * "Xdbeproto.h", rather than "Xdbe.h" because the server uses these data
+ * types.
+ */
+
+typedef struct
+{
+    VisualID    visual;    /* one visual ID that supports double-buffering */
+    int         depth;     /* depth of visual in bits                      */
+    int         perflevel; /* performance level of visual                  */
+}
+XdbeVisualInfo;
+
+typedef struct
+{
+    int                 count;          /* number of items in visual_depth   */
+    XdbeVisualInfo      *visinfo;       /* list of visuals & depths for scrn */
+}
+XdbeScreenVisualInfo;
+
+/* Protocol data types */
+
+#ifdef NEED_DBE_PROTOCOL
+
+typedef struct
+{
+    CARD32             window B32;     /* window      */
+    xDbeSwapAction     swapAction;     /* swap action */
+    CARD8              pad1;           /* unused      */
+    CARD16             pad2 B16;
+
+} xDbeSwapInfo;
+
+typedef struct
+{
+    CARD32     visualID B32;   /* associated visual      */
+    CARD8      depth;          /* depth of visual        */
+    CARD8      perfLevel;      /* performance level hint */
+    CARD16     pad1 B16;
+
+} xDbeVisInfo;
+#define sz_xDbeVisInfo 8
+
+typedef struct
+{
+    CARD32     n B32;  /* number of visual info items in list  */
+
+} xDbeScreenVisInfo;   /* followed by n xDbeVisInfo items */
+
+typedef struct
+{
+    CARD32     window B32;     /* window */
+
+} xDbeBufferAttributes;
+
+
+/* Requests and replies */
+
+typedef struct
+{
+    CARD8      reqType;        /* major-opcode: always codes->major_opcode */
+    CARD8      dbeReqType;     /* minor-opcode: always X_DbeGetVersion (0) */
+    CARD16     length B16;     /* request length: (2)                      */
+    CARD8      majorVersion;   /* client-major-version                     */
+    CARD8      minorVersion;   /* client-minor-version                     */
+    CARD16     unused B16;     /* unused                                   */
+
+} xDbeGetVersionReq;
+#define sz_xDbeGetVersionReq   8
+
+typedef struct
+{
+    BYTE       type;                   /* Reply: X_Reply (1)   */
+    CARD8      unused;                 /* unused               */
+    CARD16     sequenceNumber B16;     /* sequence number      */
+    CARD32     length B32;             /* reply length: (0)    */
+    CARD8      majorVersion;           /* server-major-version */
+    CARD8      minorVersion;           /* server-minor-version */
+    CARD16     pad1 B16;               /* unused               */
+    CARD32     pad2 B32;
+    CARD32     pad3 B32;
+    CARD32     pad4 B32;
+    CARD32     pad5 B32;
+    CARD32     pad6 B32;
+
+} xDbeGetVersionReply;
+#define sz_xDbeGetVersionReply 32
+
+typedef struct
+{
+    CARD8              reqType;        /* major-opcode: codes->major_opcode */
+    CARD8              dbeReqType;     /* X_DbeAllocateBackBufferName (1)   */
+    CARD16             length B16;     /* request length: (4)               */
+    CARD32             window B32;     /* window                            */
+    xDbeBackBuffer     buffer B32;     /* back buffer name                  */
+    xDbeSwapAction     swapAction;     /* swap action hint                  */
+    CARD8              pad1;           /* unused                            */
+    CARD16             pad2 B16;
+
+} xDbeAllocateBackBufferNameReq;
+#define sz_xDbeAllocateBackBufferNameReq       16
+
+typedef struct
+{
+    CARD8              reqType;        /* major-opcode: codes->major_opcode */
+    CARD8              dbeReqType;     /* X_DbeDeallocateBackBufferName (2) */
+    CARD16             length B16;     /* request length: (2)               */
+    xDbeBackBuffer     buffer B32;     /* back buffer name                  */
+
+} xDbeDeallocateBackBufferNameReq;
+#define sz_xDbeDeallocateBackBufferNameReq     8
+
+typedef struct
+{
+    CARD8      reqType;        /* major-opcode: always codes->major_opcode  */
+    CARD8      dbeReqType;     /* minor-opcode: always X_DbeSwapBuffers (3) */
+    CARD16     length B16;     /* request length: (2+2n)                    */
+    CARD32     n B32;          /* n, number of window/swap action pairs     */
+
+} xDbeSwapBuffersReq;          /* followed by n window/swap action pairs    */
+#define sz_xDbeSwapBuffersReq  8
+
+typedef struct
+{
+    CARD8      reqType;        /* major-opcode: always codes->major_opcode */
+    CARD8      dbeReqType;     /* minor-opcode: always X_DbeBeginIdom (4)  */
+    CARD16     length B16;     /* request length: (1)                      */
+
+} xDbeBeginIdiomReq;
+#define sz_xDbeBeginIdiomReq   4
+
+typedef struct
+{
+    CARD8      reqType;        /* major-opcode: always codes->major_opcode */
+    CARD8      dbeReqType;     /* minor-opcode: always X_DbeEndIdom (5)    */
+    CARD16     length B16;     /* request length: (1)                      */
+
+} xDbeEndIdiomReq;
+#define sz_xDbeEndIdiomReq     4
+
+typedef struct
+{
+    CARD8      reqType;        /* always codes->major_opcode     */
+    CARD8      dbeReqType;     /* always X_DbeGetVisualInfo (6)  */
+    CARD16     length B16;     /* request length: (2+n)          */
+    CARD32     n B32;          /* n, number of drawables in list */
+
+} xDbeGetVisualInfoReq;                /* followed by n drawables        */
+#define sz_xDbeGetVisualInfoReq        8
+
+typedef struct
+{
+    BYTE       type;                   /* Reply: X_Reply (1)                */
+    CARD8      unused;                 /* unused                            */
+    CARD16     sequenceNumber B16;     /* sequence number                   */
+    CARD32     length B32;             /* reply length                      */
+    CARD32     m;                      /* m, number of visual infos in list */
+    CARD32     pad1 B32;               /* unused                            */
+    CARD32     pad2 B32;
+    CARD32     pad3 B32;
+    CARD32     pad4 B32;
+    CARD32     pad5 B32;
+
+} xDbeGetVisualInfoReply;              /* followed by m visual infos        */
+#define sz_xDbeGetVisualInfoReply      32
+
+typedef struct
+{
+    CARD8              reqType;        /* always codes->major_opcode       */
+    CARD8              dbeReqType;     /* X_DbeGetBackBufferAttributes (7) */
+    CARD16             length B16;     /* request length: (2)              */
+    xDbeBackBuffer     buffer B32;     /* back buffer name                 */
+
+} xDbeGetBackBufferAttributesReq;
+#define sz_xDbeGetBackBufferAttributesReq      8
+
+typedef struct
+{
+    BYTE       type;                   /* Reply: X_Reply (1) */
+    CARD8      unused;                 /* unused             */
+    CARD16     sequenceNumber B16;     /* sequence number    */
+    CARD32     length B32;             /* reply length: (0)  */
+    CARD32     attributes;             /* attributes         */
+    CARD32     pad1 B32;               /* unused             */
+    CARD32     pad2 B32;
+    CARD32     pad3 B32;
+    CARD32     pad4 B32;
+    CARD32     pad5 B32;
+
+} xDbeGetBackBufferAttributesReply;
+#define sz_xDbeGetBackBufferAttributesReply    32
+
+#endif /* NEED_DBE_PROTOCOL */
+
+#endif /* XDBE_PROTO_H */
+
diff --git a/Xserver/include/extensions/Xext.h b/Xserver/include/extensions/Xext.h
new file mode 100644 (file)
index 0000000..7546cd8
--- /dev/null
@@ -0,0 +1,59 @@
+/*
+ * $XConsortium: Xext.h,v 1.4 94/04/17 20:11:18 keith Exp $
+ *
+Copyright (c) 1989  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+ */
+
+#ifndef _XEXT_H_
+#define _XEXT_H_
+
+#include <X11/Xfuncproto.h>
+
+_XFUNCPROTOBEGIN
+
+extern int (*XSetExtensionErrorHandler(
+#if NeedFunctionPrototypes
+    int (*handler)(
+#if NeedNestedPrototypes
+                  Display *,
+                  char *,
+                  char *
+#endif
+                  )
+#endif
+))();
+
+extern int XMissingExtension(
+#if NeedFunctionPrototypes
+    Display*           /* dpy */,
+    _Xconst char*      /* ext_name */
+#endif
+);
+
+_XFUNCPROTOEND
+
+#define X_EXTENSION_UNKNOWN "unknown"
+#define X_EXTENSION_MISSING "missing"
+
+#endif /* _XEXT_H_ */
diff --git a/Xserver/include/extensions/bigreqstr.h b/Xserver/include/extensions/bigreqstr.h
new file mode 100644 (file)
index 0000000..e9396fb
--- /dev/null
@@ -0,0 +1,64 @@
+/* $XConsortium: bigreqstr.h /main/5 1995/10/30 15:53:46 mor $ */
+/*
+
+Copyright (c) 1992  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+*/
+
+#define X_BigReqEnable         0
+
+#define XBigReqNumberEvents    0
+
+#define XBigReqNumberErrors    0
+
+#define XBigReqExtensionName   "BIG-REQUESTS"
+
+typedef struct {
+    CARD8      reqType;        /* always XBigReqCode */
+    CARD8      brReqType;      /* always X_BigReqEnable */
+    CARD16     length B16;
+} xBigReqEnableReq;
+#define sz_xBigReqEnableReq 4
+
+typedef struct {
+    BYTE       type;                   /* X_Reply */
+    CARD8      pad0;
+    CARD16     sequenceNumber B16;
+    CARD32     length B32;
+    CARD32     max_request_size B32;
+    CARD32     pad1 B32;
+    CARD32     pad2 B32;
+    CARD32     pad3 B32;
+    CARD32     pad4 B32;
+    CARD32     pad5 B32;
+} xBigReqEnableReply;
+#define sz_xBigReqEnableReply 32
+
+
+typedef struct {
+       CARD8 reqType;
+       CARD8 data;
+       CARD16 zero B16;
+        CARD32 length B32;
+} xBigReq;
diff --git a/Xserver/include/extensions/dpms.h b/Xserver/include/extensions/dpms.h
new file mode 100644 (file)
index 0000000..340c703
--- /dev/null
@@ -0,0 +1,43 @@
+/*****************************************************************
+
+Copyright (c) 1996 Digital Equipment Corporation, Maynard, Massachusetts.
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software.
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+DIGITAL EQUIPMENT CORPORATION BE LIABLE FOR ANY CLAIM, DAMAGES, INCLUDING, 
+BUT NOT LIMITED TO CONSEQUENTIAL OR INCIDENTAL DAMAGES, OR OTHER LIABILITY, 
+WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR 
+IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of Digital Equipment Corporation 
+shall not be used in advertising or otherwise to promote the sale, use or other
+dealings in this Software without prior written authorization from Digital 
+Equipment Corporation.
+
+******************************************************************/
+
+/*
+ * HISTORY
+ */
+/*
+ * @(#)RCSfile: dpms.h,v Revision: 1.1.4.2  (DEC) Date: 1995/11/21 19:34:17
+ */
+
+
+#define DPMSModeOn     0
+#define DPMSModeStandby        1
+#define DPMSModeSuspend        2
+#define DPMSModeOff    3
+
+
+
diff --git a/Xserver/include/extensions/dpmsstr.h b/Xserver/include/extensions/dpmsstr.h
new file mode 100644 (file)
index 0000000..2b776d2
--- /dev/null
@@ -0,0 +1,185 @@
+/*****************************************************************
+
+Copyright (c) 1996 Digital Equipment Corporation, Maynard, Massachusetts.
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software.
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+DIGITAL EQUIPMENT CORPORATION BE LIABLE FOR ANY CLAIM, DAMAGES, INCLUDING, 
+BUT NOT LIMITED TO CONSEQUENTIAL OR INCIDENTAL DAMAGES, OR OTHER LIABILITY, 
+WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR 
+IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of Digital Equipment Corporation 
+shall not be used in advertising or otherwise to promote the sale, use or other
+dealings in this Software without prior written authorization from Digital 
+Equipment Corporation.
+
+******************************************************************/
+
+/*
+ * HISTORY
+ */
+/*
+ * @(#)RCSfile: dpmsstr.h,v Revision: 1.1.4.2  (DEC) Date: 1995/11/21 19:34:19
+ */
+
+
+#define X_DPMSGetVersion       0
+#define X_DPMSCapable          1
+#define X_DPMSGetTimeouts      2
+#define X_DPMSSetTimeouts      3
+#define X_DPMSEnable           4
+#define X_DPMSDisable          5
+#define X_DPMSForceLevel               6
+#define X_DPMSInfo             7
+
+#define DPMSNumberEvents       0
+
+#define DPMSNumberErrors       0
+
+#define DPMSMajorVersion       1
+#define DPMSMinorVersion       1
+
+#define DPMSExtensionName      "DPMS"
+
+typedef struct {
+    CARD8      reqType;        /* always DPMSCode */
+    CARD8      dpmsReqType;    /* always X_DPMSGetVersion */
+    CARD16     length B16;
+    CARD16     majorVersion B16;
+    CARD16     minorVersion B16;
+} xDPMSGetVersionReq;
+#define sz_xDPMSGetVersionReq 8
+
+typedef struct {
+    BYTE       type;                   /* X_Reply */
+    CARD8      pad0;
+    CARD16     sequenceNumber B16;
+    CARD32     length B32;
+    CARD16     majorVersion B16;
+    CARD16     minorVersion B16;
+    CARD32     pad1 B32;
+    CARD32     pad2 B32;
+    CARD32     pad3 B32;
+    CARD32     pad4 B32;
+    CARD32     pad5 B32;
+} xDPMSGetVersionReply;
+#define sz_xDPMSGetVersionReply 32
+
+typedef struct {
+    CARD8      reqType;        /* always DPMSCode */
+    CARD8      dpmsReqType;    /* always X_DPMSCapable */
+    CARD16     length B16;
+} xDPMSCapableReq;
+#define sz_xDPMSCapableReq 4
+
+typedef struct {
+    BYTE       type;                   /* X_Reply */
+    CARD8      pad0;
+    CARD16     sequenceNumber B16;
+    CARD32     length B32;
+    BOOL       capable;
+    CARD8      pad1;
+    CARD16     pad2 B16;
+    CARD32     pad3 B32;
+    CARD32     pad4 B32;
+    CARD32     pad5 B32;
+    CARD32     pad6 B32;
+    CARD32     pad7 B32;
+} xDPMSCapableReply;
+#define sz_xDPMSCapableReply 32
+
+typedef struct {
+    CARD8      reqType;        /* always DPMSCode */
+    CARD8      dpmsReqType;    /* always X_DPMSGetTimeouts */
+    CARD16     length B16;
+} xDPMSGetTimeoutsReq;
+#define sz_xDPMSGetTimeoutsReq 4
+
+typedef struct {
+    BYTE       type;                   /* X_Reply */
+    CARD8      pad0;
+    CARD16     sequenceNumber B16;
+    CARD32     length B32;
+    CARD16     standby B16;
+    CARD16     suspend B16;
+    CARD16     off B16;
+    CARD16     pad1 B16;
+    CARD32     pad2 B32;
+    CARD32     pad3 B32;
+    CARD32     pad4 B32;
+    CARD32     pad5 B32;
+} xDPMSGetTimeoutsReply;
+#define sz_xDPMSGetTimeoutsReply 32
+
+typedef struct {
+    CARD8      reqType;        /* always DPMSCode */
+    CARD8      dpmsReqType;    /* always X_DPMSSetTimeouts */
+    CARD16     length B16;
+    CARD16     standby B16;
+    CARD16     suspend B16;
+    CARD16     off B16;
+    CARD16     pad0 B16;
+} xDPMSSetTimeoutsReq;
+#define sz_xDPMSSetTimeoutsReq 12
+
+typedef struct {
+    CARD8      reqType;        /* always DPMSCode */
+    CARD8      dpmsReqType;    /* always X_DPMSEnable */
+    CARD16     length B16;
+} xDPMSEnableReq;
+#define sz_xDPMSEnableReq 4
+
+typedef struct {
+    CARD8      reqType;        /* always DPMSCode */
+    CARD8      dpmsReqType;    /* always X_DPMSDisable */
+    CARD16     length B16;
+} xDPMSDisableReq;
+#define sz_xDPMSDisableReq 4
+
+typedef struct {
+    CARD8      reqType;        /* always DPMSCode */
+    CARD8      dpmsReqType;    /* always X_DPMSForceLevel */
+    CARD16     length B16;
+    CARD16     level B16;      /* power level requested */
+    CARD16     pad0 B16;
+} xDPMSForceLevelReq;
+#define sz_xDPMSForceLevelReq 8
+
+typedef struct {
+    CARD8      reqType;        /* always DPMSCode */
+    CARD8      dpmsReqType;    /* always X_DPMSInfo */
+    CARD16     length B16;
+} xDPMSInfoReq;
+#define sz_xDPMSInfoReq 4
+
+typedef struct {
+    BYTE       type;                   /* X_Reply */
+    CARD8      pad0;
+    CARD16     sequenceNumber B16;
+    CARD32     length B32;
+    CARD16     power_level B16;
+    BOOL       state;
+    CARD8      pad1;
+    CARD32     pad2 B32;
+    CARD32     pad3 B32;
+    CARD32     pad4 B32;
+    CARD32     pad5 B32;
+    CARD32     pad6 B32;
+} xDPMSInfoReply;
+#define sz_xDPMSInfoReply 32
+
+
+
+
+
diff --git a/Xserver/include/extensions/extutil.h b/Xserver/include/extensions/extutil.h
new file mode 100644 (file)
index 0000000..6f3425e
--- /dev/null
@@ -0,0 +1,222 @@
+/*
+ * $XConsortium: extutil.h,v 1.15 94/10/07 15:36:33 kaleb Exp $
+ *
+Copyright (c) 1989  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+ *
+ * Author:  Jim Fulton, MIT X Consortium
+ * 
+ *                     Xlib Extension-Writing Utilities
+ *
+ * This package contains utilities for writing the client API for various
+ * protocol extensions.  THESE INTERFACES ARE NOT PART OF THE X STANDARD AND
+ * ARE SUBJECT TO CHANGE!
+ */
+
+#ifndef _EXTUTIL_H_
+#define _EXTUTIL_H_
+
+/*
+ * We need to keep a list of open displays since the Xlib display list isn't
+ * public.  We also have to per-display info in a separate block since it isn't
+ * stored directly in the Display structure.
+ */
+typedef struct _XExtDisplayInfo {
+    struct _XExtDisplayInfo *next;     /* keep a linked list */
+    Display *display;                  /* which display this is */
+    XExtCodes *codes;                  /* the extension protocol codes */
+    XPointer data;                     /* extra data for extension to use */
+} XExtDisplayInfo;
+
+typedef struct _XExtensionInfo {
+    XExtDisplayInfo *head;             /* start of list */
+    XExtDisplayInfo *cur;              /* most recently used */
+    int ndisplays;                     /* number of displays */
+} XExtensionInfo;
+
+typedef struct _XExtensionHooks {
+    int (*create_gc)(
+#if NeedNestedPrototypes
+             Display*                  /* display */,
+             GC                        /* gc */,
+             XExtCodes*                /* codes */
+#endif
+);
+    int (*copy_gc)(
+#if NeedNestedPrototypes
+             Display*                  /* display */,
+              GC                       /* gc */,
+              XExtCodes*               /* codes */
+#endif
+);
+    int (*flush_gc)(
+#if NeedNestedPrototypes
+             Display*                  /* display */,
+              GC                       /* gc */,
+              XExtCodes*               /* codes */
+#endif
+);
+    int (*free_gc)(
+#if NeedNestedPrototypes
+             Display*                  /* display */,
+              GC                       /* gc */,
+              XExtCodes*               /* codes */
+#endif
+);
+    int (*create_font)(
+#if NeedNestedPrototypes
+             Display*                  /* display */,
+              XFontStruct*             /* fs */,
+              XExtCodes*               /* codes */
+#endif
+);
+    int (*free_font)(
+#if NeedNestedPrototypes
+             Display*                  /* display */,
+              XFontStruct*             /* fs */,
+              XExtCodes*               /* codes */
+#endif
+);
+    int (*close_display)(
+#if NeedNestedPrototypes
+             Display*                  /* display */,
+              XExtCodes*               /* codes */
+#endif
+);
+    Bool (*wire_to_event)(
+#if NeedNestedPrototypes
+              Display*                 /* display */,
+               XEvent*                 /* re */,
+               xEvent*                 /* event */
+#endif
+);
+    Status (*event_to_wire)(
+#if NeedNestedPrototypes
+             Display*                  /* display */,
+              XEvent*                  /* re */,
+              xEvent*                  /* event */
+#endif
+);
+    int (*error)(
+#if NeedNestedPrototypes
+             Display*                  /* display */,
+              xError*                  /* err */,
+              XExtCodes*               /* codes */,
+              int*                     /* ret_code */
+#endif
+);
+    char *(*error_string)(
+#if NeedNestedPrototypes
+               Display*                /* display */,
+                int                    /* code */,
+                XExtCodes*             /* codes */,
+                char*                  /* buffer */,
+                int                    /* nbytes */
+#endif
+);
+} XExtensionHooks;
+
+extern XExtensionInfo *XextCreateExtension(
+#if NeedFunctionPrototypes
+    void
+#endif
+);
+extern void XextDestroyExtension(
+#if NeedFunctionPrototypes
+    XExtensionInfo*    /* info */
+#endif
+);
+extern XExtDisplayInfo *XextAddDisplay(
+#if NeedFunctionPrototypes
+    XExtensionInfo*    /* extinfo */,
+    Display*           /* dpy */,
+    char*              /* ext_name */,
+    XExtensionHooks*   /* hooks */,
+    int                        /* nevents */,
+    XPointer           /* data */
+#endif
+);
+extern int XextRemoveDisplay(
+#if NeedFunctionPrototypes
+    XExtensionInfo*    /* extinfo */,
+    Display*           /* dpy */
+#endif
+);
+extern XExtDisplayInfo *XextFindDisplay(
+#if NeedFunctionPrototypes
+    XExtensionInfo*    /* extinfo */,
+    Display*           /* dpy */
+#endif
+);
+
+#define XextHasExtension(i) ((i) && ((i)->codes))
+#define XextCheckExtension(dpy,i,name,val) \
+  if (!XextHasExtension(i)) { XMissingExtension (dpy, name); return val; }
+#define XextSimpleCheckExtension(dpy,i,name) \
+  if (!XextHasExtension(i)) { XMissingExtension (dpy, name); return; }
+
+
+/*
+ * helper macros to generate code that is common to all extensions; caller
+ * should prefix it with static if extension source is in one file; this
+ * could be a utility function, but have to stack 6 unused arguments for 
+ * something that is called many, many times would be bad.
+ */
+#define XEXT_GENERATE_FIND_DISPLAY(proc,extinfo,extname,hooks,nev,data) \
+XExtDisplayInfo *proc (dpy) \
+    register Display *dpy; \
+{ \
+    XExtDisplayInfo *dpyinfo; \
+    if (!extinfo) { if (!(extinfo = XextCreateExtension())) return NULL; } \
+    if (!(dpyinfo = XextFindDisplay (extinfo, dpy))) \
+      dpyinfo = XextAddDisplay (extinfo,dpy,extname,hooks,nev,data); \
+    return dpyinfo; \
+}
+
+#define XEXT_GENERATE_CLOSE_DISPLAY(proc,extinfo) \
+int proc (dpy, codes) \
+    Display *dpy; \
+    XExtCodes *codes; \
+{ \
+    return XextRemoveDisplay (extinfo, dpy); \
+}
+
+#define XEXT_GENERATE_ERROR_STRING(proc,extname,nerr,errl) \
+char *proc (dpy, code, codes, buf, n) \
+    Display  *dpy; \
+    int code; \
+    XExtCodes *codes; \
+    char *buf; \
+    int n; \
+{  \
+    code -= codes->first_error;  \
+    if (code >= 0 && code < nerr) { \
+       char tmp[256]; \
+       sprintf (tmp, "%s.%d", extname, code); \
+       XGetErrorDatabaseText (dpy, "XProtoError", tmp, errl[code], buf, n); \
+       return buf; \
+    } \
+    return (char *)0; \
+}
+
+#endif
diff --git a/Xserver/include/extensions/lbxbuf.h b/Xserver/include/extensions/lbxbuf.h
new file mode 100644 (file)
index 0000000..d732493
--- /dev/null
@@ -0,0 +1,45 @@
+/* $XConsortium: lbxbuf.h /main/7 1996/11/15 21:33:12 rws $ */
+/*
+ * Copyright 1988, 1989, 1990, 1994 Network Computing Devices, Inc.
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and
+ * its documentation for any purpose is hereby granted without fee, provided
+ * that the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the name Network Computing Devices, Inc. not be
+ * used in advertising or publicity pertaining to distribution of this 
+ * software without specific, written prior permission.
+ * 
+ * THIS SOFTWARE IS PROVIDED `AS-IS'.  NETWORK COMPUTING DEVICES, INC.,
+ * DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING WITHOUT
+ * LIMITATION ALL IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
+ * PARTICULAR PURPOSE, OR NONINFRINGEMENT.  IN NO EVENT SHALL NETWORK
+ * COMPUTING DEVICES, INC., BE LIABLE FOR ANY DAMAGES WHATSOEVER, INCLUDING
+ * SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES, INCLUDING LOSS OF USE,
+ * DATA, OR PROFITS, EVEN IF ADVISED OF THE POSSIBILITY THEREOF, AND
+ * REGARDLESS OF WHETHER IN AN ACTION IN CONTRACT, TORT OR NEGLIGENCE,
+ * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+ * 
+ */
+
+#ifndef _BUFFER_H_
+#define _BUFFER_H_
+
+#define INBUFFER_SIZE          (1 << 13)       /* 8K */
+#define OUTBUFFER_SIZE         (1 << 12)       /* 4K */
+
+#ifndef TRUE
+#define TRUE    1
+#endif
+#ifndef FALSE
+#define FALSE   0
+#endif
+
+typedef struct _zlibbuffer  *ZlibBufferPtr;
+
+extern int  InitZlibBuffer();
+extern void FreeZlibBuffer();
+extern char *ReserveOutBuf();
+
+#endif /* _BUFFER_H_ */
diff --git a/Xserver/include/extensions/lbxbufstr.h b/Xserver/include/extensions/lbxbufstr.h
new file mode 100644 (file)
index 0000000..97f07a6
--- /dev/null
@@ -0,0 +1,43 @@
+/* $XConsortium: lbxbufstr.h /main/8 1996/11/15 21:33:20 rws $ */
+/*
+ * Copyright 1988, 1989, 1990, 1994 Network Computing Devices, Inc.
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and
+ * its documentation for any purpose is hereby granted without fee, provided
+ * that the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the name Network Computing Devices, Inc. not be
+ * used in advertising or publicity pertaining to distribution of this 
+ * software without specific, written prior permission.
+ * 
+ * THIS SOFTWARE IS PROVIDED `AS-IS'.  NETWORK COMPUTING DEVICES, INC.,
+ * DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING WITHOUT
+ * LIMITATION ALL IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
+ * PARTICULAR PURPOSE, OR NONINFRINGEMENT.  IN NO EVENT SHALL NETWORK
+ * COMPUTING DEVICES, INC., BE LIABLE FOR ANY DAMAGES WHATSOEVER, INCLUDING
+ * SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES, INCLUDING LOSS OF USE,
+ * DATA, OR PROFITS, EVEN IF ADVISED OF THE POSSIBILITY THEREOF, AND
+ * REGARDLESS OF WHETHER IN AN ACTION IN CONTRACT, TORT OR NEGLIGENCE,
+ * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+ * 
+ */
+#ifndef _BUFFERSTR_H_
+#define _BUFFERSTR_H_
+
+#include       "lbxbuf.h"
+
+/*
+ * ZLIB Input/Output buffer
+ */
+typedef struct _zlibbuffer {
+       char    *bufbase;
+       char    *bufend;
+       char    *bufptr;
+       int     bufcnt;
+} ZlibBuffer;
+
+#define BYTES_AVAIL(inbuf, len)        \
+       (((inbuf)->bufcnt >= (len)) ? (inbuf)->bufptr : NULL)
+
+#endif /* _BUFFERSTR_H_ */
diff --git a/Xserver/include/extensions/lbxdeltastr.h b/Xserver/include/extensions/lbxdeltastr.h
new file mode 100644 (file)
index 0000000..af7577c
--- /dev/null
@@ -0,0 +1,91 @@
+/* $XConsortium: lbxdeltastr.h /main/7 1996/12/15 21:24:04 rws $ */
+/*
+ * Copyright 1993 Network Computing Devices
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the name of NCD. not be used in advertising or
+ * publicity pertaining to distribution of the software without specific,
+ * written prior permission.  NCD. makes no representations about the
+ * suitability of this software for any purpose.  It is provided "as is"
+ * without express or implied warranty.
+ *
+ * NCD. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL NCD.
+ * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
+ * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN 
+ * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ */
+
+#ifndef LBX_DELTA_STRUCT_H
+#define LBX_DELTA_STRUCT_H
+
+#define MIN_CACHEABLE_LEN              8
+
+#define DELTA_CACHEABLE(pcache, len)   \
+       ((len) > MIN_CACHEABLE_LEN && (len) <= (pcache)->maxDeltasize)
+
+/*
+ * An entry in the delta compactor cache
+ */
+typedef struct _LBXDeltaElem {
+    int                        length;
+    unsigned char      *buf;
+} LBXDeltaElemRec, *LBXDeltaElemPtr;
+
+
+/*
+ * Delta compactor cache
+ */
+typedef struct _LBXDeltas {
+    unsigned short     nDeltas;
+    unsigned short     maxDeltasize;
+    LBXDeltaElemPtr    deltas;
+    unsigned short     nextDelta;
+    unsigned short     activeDeltas;   /* only needed for outgoing */
+} LBXDeltasRec, *LBXDeltasPtr;
+
+
+/*
+ * Motion delta cache
+ */
+
+typedef struct {
+    BYTE swapped;
+    BYTE detail;
+    CARD16 sequenceNumber B16;
+    Time time B32;
+    Window root B32, event B32, child B32;
+    INT16 rootX B16, rootY B16, eventX B16, eventY B16;
+    KeyButMask state B16;
+    BOOL sameScreen;           
+} lbxMotionCache;
+
+
+/*
+ * Motion delta events
+ */
+
+typedef struct {
+    BYTE type;         /* always eventBase + LbxQuickMotionDeltaEvent */
+    CARD8 deltaTime;
+    INT8 deltaX;
+    INT8 deltaY;
+} lbxQuickMotionDeltaEvent;
+#define sz_lbxQuickMotionDeltaEvent 4
+
+typedef struct {
+    BYTE type;         /* always eventBase + LbxEvent */
+    BYTE lbxType;      /* LbxMotionDeltaEvent */
+    INT8 deltaX;
+    INT8 deltaY;
+    CARD16 deltaTime B16;
+    CARD16 deltaSequence B16;
+} lbxMotionDeltaEvent;
+#define sz_lbxMotionDeltaEvent 8
+
+#endif /* LBX_DELTA_STRUCT_H */
diff --git a/Xserver/include/extensions/lbximage.h b/Xserver/include/extensions/lbximage.h
new file mode 100644 (file)
index 0000000..74edafb
--- /dev/null
@@ -0,0 +1,167 @@
+/* $XConsortium: lbximage.h /main/6 1996/11/04 16:48:27 rws $ */
+
+/******************************************************************************
+
+Copyright (c) 1994  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+******************************************************************************/
+
+#ifndef _LBX_IMAGE_H_
+#define _LBX_IMAGE_H_
+
+typedef struct _LbxBitmapCompMethod {
+
+    char *methodName;
+    int inited;
+    int methodOpCode;  /* to be filled on reply from server */
+
+    int (*compInit)(
+#if NeedFunctionPrototypes
+       void
+#endif
+    );
+
+    int (*compFunc)(
+#if NeedFunctionPrototypes
+       unsigned char *         /* inbuf */,
+       unsigned char *         /* outbuf */,
+       int                     /* outbufSize */,
+       int                     /* image_bytes */,
+       int                     /* pixels_per_line */,
+       int                     /* padded_bytes_per_scanline */,
+       int                     /* reverse_bits */,
+       int *                   /* bytesCompressed */
+#endif
+    );
+
+    int (*decompFunc)(
+#if NeedFunctionPrototypes
+       unsigned char *         /* inbuf */,
+       unsigned char *         /* outbuf */,
+       int                     /* image_bytes */,
+       int                     /* pixels_per_line */,
+       int                     /* padded_bytes_per_scanline */,
+       int                     /* reverse_bits */
+#endif
+    );
+
+} LbxBitmapCompMethod;
+
+
+#define LBX_MAX_DEPTHS 5
+
+typedef struct _LbxPixmapCompMethod {
+
+    char *methodName;
+    unsigned formatMask;
+    int depthCount;
+    int depths[LBX_MAX_DEPTHS];
+    int inited;
+    int methodOpCode;  /* to be filled on reply from server */
+
+    int (*compInit)(
+#if NeedFunctionPrototypes
+       void
+#endif
+    );
+
+    int (*compFunc)(
+#if NeedFunctionPrototypes
+       char *                  /* inbuf */,
+       char *                  /* outbuf */,
+       int                     /* outbufSize */,
+       int                     /* format */,
+       int                     /* depth */,
+       int                     /* num_scan_lines */,
+       int                     /* scan_line_size */,
+       int *                   /* bytesCompressed */
+#endif
+    );
+
+    int (*decompFunc)(
+#if NeedFunctionPrototypes
+       char *                  /* inbuf */,
+       char *                  /* outbuf */,
+       int                     /* num_scan_lines */,
+       int                     /* scan_line_size */
+#endif
+    );
+
+} LbxPixmapCompMethod;
+
+
+
+extern int LbxImageEncodePackBits (
+#if NeedFunctionPrototypes
+char *                 /* inbuf */,
+char *                 /* outbuf */,
+int                    /* outbufSize */,
+int                    /* format */,
+int                    /* depth */,
+int                    /* num_scan_lines */,
+int                    /* scan_line_size */,
+int *                  /* bytesCompressed */
+#endif
+);
+
+extern int LbxImageEncodeFaxG42D (
+#if NeedFunctionPrototypes
+unsigned char *                /* inbuf */,
+unsigned char *                /* outbuf */,
+int                    /* outbufSize */,
+int                    /* image_bytes */,
+int                    /* pixels_per_line */,
+int                    /* padded_bytes_per_scanline */,
+int                    /* reverse_bits */,
+int *                  /* bytesCompressed */
+#endif
+);
+
+extern int LbxImageDecodePackBits (
+#if NeedFunctionPrototypes
+char *                 /* inbuf */,
+char *                 /* outbuf */,
+int                    /* num_scan_lines */,
+int                    /* scan_line_size */
+#endif
+);
+
+extern int LbxImageDecodeFaxG42D (
+#if NeedFunctionPrototypes
+unsigned char *                /* inbuf */,
+unsigned char *                /* outbuf */,
+int                    /* image_bytes */,
+int                    /* pixels_per_line */,
+int                    /* padded_bytes_per_scanline */,
+int                    /* reverse_bits */
+#endif
+);
+
+
+#define LBX_IMAGE_COMPRESS_SUCCESS             0
+#define LBX_IMAGE_COMPRESS_NO_SUPPORT          1
+#define LBX_IMAGE_COMPRESS_BAD_MALLOC          2
+#define LBX_IMAGE_COMPRESS_NOT_WORTH_IT                3
+
+#endif /* _LBX_IMAGE_H_ */
diff --git a/Xserver/include/extensions/lbxopts.h b/Xserver/include/extensions/lbxopts.h
new file mode 100644 (file)
index 0000000..7da54cd
--- /dev/null
@@ -0,0 +1,133 @@
+/* $XConsortium: lbxopts.h /main/9 1996/11/15 21:33:35 rws $ */
+/*
+ * Copyright 1994 Network Computing Devices, Inc.
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and
+ * its documentation for any purpose is hereby granted without fee, provided
+ * that the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the name Network Computing Devices, Inc. not be
+ * used in advertising or publicity pertaining to distribution of this
+ * software without specific, written prior permission.
+ *
+ * THIS SOFTWARE IS PROVIDED `AS-IS'.  NETWORK COMPUTING DEVICES, INC.,
+ * DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING WITHOUT
+ * LIMITATION ALL IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
+ * PARTICULAR PURPOSE, OR NONINFRINGEMENT.  IN NO EVENT SHALL NETWORK
+ * COMPUTING DEVICES, INC., BE LIABLE FOR ANY DAMAGES WHATSOEVER, INCLUDING
+ * SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES, INCLUDING LOSS OF USE, DATA,
+ * OR PROFITS, EVEN IF ADVISED OF THE POSSIBILITY THEREOF, AND REGARDLESS OF
+ * WHETHER IN AN ACTION IN CONTRACT, TORT OR NEGLIGENCE, ARISING OUT OF OR IN
+ * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ */
+/* $XFree86: xc/include/extensions/lbxopts.h,v 1.3 1997/01/18 07:17:15 dawes Exp $ */
+
+#ifndef _LBX_OPTS_H_
+#define _LBX_OPTS_H_
+
+/*
+ * Negotiable configuration options
+ */
+#define LBX_OPT_DELTA_PROXY            0
+#define LBX_OPT_DELTA_SERVER           1
+#define LBX_OPT_STREAM_COMP            2
+#define LBX_OPT_BITMAP_COMP            3
+#define LBX_OPT_PIXMAP_COMP            4
+#define LBX_OPT_MSG_COMP               5       /* aka "squishing" */
+#define LBX_OPT_USE_TAGS               6
+#define LBX_OPT_CMAP_ALL               7
+#define LBX_OPT_EXTENSION              255
+
+/*
+ * Length fields are encoded in 1 or 3 bytes
+ */
+#define LBX_OPT_SMALLLEN_SIZE          1
+#define LBX_OPT_BIGLEN_SIZE            3
+#define LBX_OPT_BIGLEN_MIN             256
+
+#define LBX_OPT_DECODE_LEN(p, len, size) \
+    if ((p)[0]) { \
+       (len) = (p)[0]; \
+       (size) = LBX_OPT_SMALLLEN_SIZE; \
+    } \
+    else { \
+       (len) = LBX_OPT_BIGLEN_MIN + (p)[1] << 8 | (p)[2]; \
+       (size) = LBX_OPT_BIGLEN_SIZE; \
+    }
+
+/*
+ * Option header lengths
+ */
+#define LBX_OPT_SMALLHDR_LEN           (1 + LBX_OPT_SMALLLEN_SIZE)
+#define LBX_OPT_BIGHDR_LEN             (1 + LBX_OPT_BIGLEN_SIZE)
+
+/*
+ * Delta compression parameters
+ */
+#define LBX_OPT_DELTA_REQLEN           6
+#define LBX_OPT_DELTA_REPLYLEN         2
+#define LBX_OPT_DELTA_NCACHE_DFLT      16
+#define LBX_OPT_DELTA_MSGLEN_MIN       32
+#define LBX_OPT_DELTA_MSGLEN_DFLT      64
+
+
+/*
+ * Stream compression opts
+ */
+
+#include <sys/types.h>
+
+#if defined(WIN32) || (defined(USG) && !defined(CRAY) && !defined(umips) && !defined(MOTOROLA) && !defined(uniosu) && !defined(__sxg__))
+
+struct iovec {
+    caddr_t iov_base;
+    int iov_len;
+};
+
+#else
+#ifndef Lynx
+#include <sys/uio.h>
+#else
+#include <uio.h>
+#endif
+#endif
+
+typedef void *LbxStreamCompHandle;
+
+typedef struct _LbxStreamOpts {
+    LbxStreamCompHandle        (*streamCompInit)();
+    pointer            streamCompArg;
+    int                        (*streamCompStuffInput)(
+                           int fd,
+                           unsigned char *buf,
+                           int buflen
+                       );
+    int                        (*streamCompInputAvail)(
+                           int fd
+                       );
+    int                        (*streamCompFlush)(
+                           int fd
+                       );
+    int                        (*streamCompRead)(
+                           int fd,
+                           unsigned char *buf,
+                           int buflen
+                       );
+    int                (*streamCompWriteV)(
+                           int fd,
+                           struct iovec *iov,
+                           int iovcnt
+                       );
+    void               (*streamCompOn)(
+                           int fd
+                       );
+    void               (*streamCompOff)(
+                           int fd
+                       );
+    void               (*streamCompFreeHandle)(
+                           LbxStreamCompHandle handle
+                       );
+} LbxStreamOpts;
+
+#endif /* _LBX_OPTS_H_ */
diff --git a/Xserver/include/extensions/lbxstr.h b/Xserver/include/extensions/lbxstr.h
new file mode 100644 (file)
index 0000000..b5858ad
--- /dev/null
@@ -0,0 +1,909 @@
+/* $XConsortium: lbxstr.h /main/27 1996/12/15 21:24:11 rws $ */
+/*
+ * Copyright 1992 Network Computing Devices
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the name of NCD. not be used in advertising or
+ * publicity pertaining to distribution of the software without specific,
+ * written prior permission.  NCD. makes no representations about the
+ * suitability of this software for any purpose.  It is provided "as is"
+ * without express or implied warranty.
+ *
+ * NCD. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL NCD.
+ * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
+ * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN 
+ * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ */
+#ifndef _LBXSTR_H_
+#define _LBXSTR_H_
+
+#include "XLbx.h"
+
+#define LBXNAME "LBX"
+
+#define LBX_MAJOR_VERSION      1
+#define LBX_MINOR_VERSION      0
+
+typedef struct {
+    BOOL       success;                /* TRUE */
+    BOOL       changeType;
+    CARD16     majorVersion B16,
+               minorVersion B16;
+    CARD16     length B16;             /* 1/4 additional bytes in setup info */
+    CARD32     tag B32;
+} xLbxConnSetupPrefix;
+
+typedef struct _LbxQueryVersion {
+    CARD8      reqType;                /* always LbxReqCode */
+    CARD8      lbxReqType;             /* always X_LbxQueryVersion */
+    CARD16     length B16;
+} xLbxQueryVersionReq;
+#define sz_xLbxQueryVersionReq 4
+
+typedef struct {
+    BYTE       type;                   /* X_Reply */
+    CARD8      unused;
+    CARD16     sequenceNumber B16;
+    CARD32     length B32;
+    CARD16     majorVersion B16;       /* major version of LBX protocol */
+    CARD16     minorVersion B16;       /* minor version of LBX protocol */
+    CARD32     pad0 B32;
+    CARD32     pad1 B32;
+    CARD32     pad2 B32;
+    CARD32     pad3 B32;
+    CARD32     pad4 B32;
+} xLbxQueryVersionReply;
+#define sz_xLbxQueryVersionReply       32
+
+typedef struct _LbxStartProxy {
+    CARD8      reqType;        /* always LbxReqCode */
+    CARD8      lbxReqType;     /* always X_LbxStartProxy */
+    CARD16     length B16;
+} xLbxStartProxyReq;
+#define sz_xLbxStartProxyReq       4
+
+typedef struct _LbxStopProxy {
+    CARD8      reqType;        /* always LbxReqCode */
+    CARD8      lbxReqType;     /* always X_LbxStopProxy */
+    CARD16     length B16;
+} xLbxStopProxyReq;
+#define sz_xLbxStopProxyReq        4
+
+typedef struct _LbxSwitch {
+    CARD8      reqType;        /* always LbxReqCode */
+    CARD8      lbxReqType;     /* always X_LbxSwitch */
+    CARD16     length B16;
+    CARD32     client B32;     /* new client */
+} xLbxSwitchReq;
+#define sz_xLbxSwitchReq       8
+
+typedef struct _LbxNewClient {
+    CARD8      reqType;        /* always LbxReqCode */
+    CARD8      lbxReqType;     /* always X_LbxNewClient */
+    CARD16     length B16;
+    CARD32     client B32;     /* new client */
+} xLbxNewClientReq;
+#define sz_xLbxNewClientReq    8
+
+typedef struct _LbxCloseClient {
+    CARD8      reqType;        /* always LbxReqCode */
+    CARD8      lbxReqType;     /* always X_LbxCloseClient */
+    CARD16     length B16;
+    CARD32     client B32;     /* new client */
+} xLbxCloseClientReq;
+#define sz_xLbxCloseClientReq  8
+
+typedef struct _LbxModifySequence {
+    CARD8      reqType;        /* always LbxReqCode */
+    CARD8      lbxReqType;     /* always X_LbxModifySequence */
+    CARD16     length B16;
+    CARD32     adjust B32;
+} xLbxModifySequenceReq;
+#define sz_xLbxModifySequenceReq    8
+    
+typedef struct _LbxAllowMotion {
+    CARD8      reqType;        /* always LbxReqCode */
+    CARD8      lbxReqType;     /* always X_LbxAllowMotion */
+    CARD16     length B16;
+    CARD32     num B32;
+} xLbxAllowMotionReq;
+#define sz_xLbxAllowMotionReq    8
+    
+typedef struct {
+    CARD8      reqType;        /* always LbxReqCode */
+    CARD8      lbxReqType;     /* always X_LbxGrabCmap */
+    CARD16     length B16;
+    Colormap   cmap B32;
+} xLbxGrabCmapReq;    
+#define sz_xLbxGrabCmapReq     8
+
+#define LBX_SMART_GRAB         0x80
+#define LBX_AUTO_RELEASE       0x40
+#define LBX_3CHANNELS          0x20
+#define LBX_2BYTE_PIXELS       0x10
+#define LBX_RGB_BITS_MASK      0x0f
+
+#define LBX_LIST_END           0
+#define LBX_PIXEL_PRIVATE      1
+#define LBX_PIXEL_SHARED       2
+#define LBX_PIXEL_RANGE_PRIVATE        3
+#define LBX_PIXEL_RANGE_SHARED 4
+#define LBX_NEXT_CHANNEL       5
+
+typedef struct {
+    BYTE       type;                   /* X_Reply */
+    CARD8      flags;
+    CARD16     sequenceNumber B16;
+    CARD32     length B32;
+    CARD32     pad0 B16;
+    CARD32     pad1 B32;
+    CARD32     pad2 B32;
+    CARD32     pad3 B32;
+    CARD32     pad4 B32;
+    CARD32     pad5 B16;
+} xLbxGrabCmapReply;
+#define sz_xLbxGrabCmapReply   32
+#define sz_xLbxGrabCmapReplyHdr        8
+
+
+typedef struct {
+    CARD8      reqType;        /* always LbxReqCode */
+    CARD8      lbxReqType;     /* always X_LbxReleaseCmap */
+    CARD16     length B16;
+    Colormap   cmap B32;
+} xLbxReleaseCmapReq;    
+#define sz_xLbxReleaseCmapReq  8
+
+typedef struct {
+    CARD8      reqType;        /* always LbxReqCode */
+    CARD8      lbxReqType;     /* always X_LbxAllocColor */
+    CARD16     length B16;
+    Colormap   cmap B32;
+    CARD32     pixel B32;
+    CARD16     red B16, green B16, blue B16;
+    CARD16     pad B16;
+} xLbxAllocColorReq;    
+#define sz_xLbxAllocColorReq   20
+
+typedef struct _LbxIncrementPixel {
+    CARD8      reqType;        /* always LbxReqCode */
+    CARD8      lbxReqType;     /* always X_LbxIncrementPixel */
+    CARD16     length B16;
+    CARD32     cmap B32;
+    CARD32     pixel B32;
+} xLbxIncrementPixelReq;
+#define sz_xLbxIncrementPixelReq    12
+
+typedef struct _LbxDelta {
+    CARD8      reqType;        /* always LbxReqCode */
+    CARD8      lbxReqType;     /* always X_LbxDelta */
+    CARD16     length B16;
+    CARD8      diffs;          /* number of diffs */
+    CARD8      cindex;         /* cache index */
+                               /* list of diffs follows */
+} xLbxDeltaReq;
+#define sz_xLbxDeltaReq    6
+
+typedef struct _LbxGetModifierMapping {
+    CARD8      reqType;        /* always LbxReqCode */
+    CARD8      lbxReqType;     /* always X_LbxGetModifierMapping */
+    CARD16     length B16;
+} xLbxGetModifierMappingReq;
+#define        sz_xLbxGetModifierMappingReq    4
+
+typedef struct {
+    BYTE       type;                   /* X_Reply */
+    CARD8      keyspermod;
+    CARD16     sequenceNumber B16;
+    CARD32     length B32;
+    CARD32     tag B32;
+    CARD32     pad0 B32;
+    CARD32     pad1 B32;
+    CARD32     pad2 B32;
+    CARD32     pad3 B32;
+    CARD32     pad4 B32;
+} xLbxGetModifierMappingReply;
+#define sz_xLbxGetModifierMappingReply 32
+
+typedef struct _LbxGetKeyboardMapping {
+    CARD8      reqType;        /* always LbxReqCode */
+    CARD8      lbxReqType;     /* always X_LbxGetKeyboardMapping */
+    CARD16     length B16;
+    KeyCode    firstKeyCode;
+    CARD8      count;
+    CARD16     pad1 B16;
+} xLbxGetKeyboardMappingReq;
+#define        sz_xLbxGetKeyboardMappingReq    8
+
+typedef struct {
+    BYTE       type;                   /* X_Reply */
+    CARD8      keysperkeycode;
+    CARD16     sequenceNumber B16;
+    CARD32     length B32;
+    CARD32     tag B32;
+    CARD32     pad0 B32;
+    CARD32     pad1 B32;
+    CARD32     pad2 B32;
+    CARD32     pad3 B32;
+    CARD32     pad4 B32;
+} xLbxGetKeyboardMappingReply;
+#define sz_xLbxGetKeyboardMappingReply 32
+
+typedef struct _LbxQueryFont {
+    CARD8      reqType;        /* always LbxReqCode */
+    CARD8      lbxReqType;     /* always X_LbxQueryFont */
+    CARD16     length B16;
+    CARD32     fid B32;
+} xLbxQueryFontReq;
+#define        sz_xLbxQueryFontReq     8
+
+typedef struct _LbxInternAtoms {
+    CARD8      reqType;        /* always LbxReqCode */
+    CARD8      lbxReqType;     /* always X_LbxInternAtoms */
+    CARD16     length B16;
+    CARD16     num B16;
+} xLbxInternAtomsReq;
+#define sz_xLbxInternAtomsReq  6  
+
+typedef struct {
+    BYTE       type;           /* X_Reply */
+    CARD8      unused;
+    CARD16     sequenceNumber B16;
+    CARD32     length B32;
+    CARD32     atomsStart B32;
+    CARD32     pad0 B32;
+    CARD32     pad1 B32;
+    CARD32     pad2 B32;
+    CARD32     pad3 B32;
+    CARD32     pad4 B32;
+} xLbxInternAtomsReply;
+#define sz_xLbxInternAtomsReply                32
+#define sz_xLbxInternAtomsReplyHdr     8
+
+
+typedef struct _LbxGetWinAttrAndGeom {
+    CARD8      reqType;        /* always LbxReqCode */
+    CARD8      lbxReqType;     /* always X_LbxGetWinAttrAndGeom */
+    CARD16     length B16;
+    CARD32     id B32;         /* window id */
+} xLbxGetWinAttrAndGeomReq;
+#define sz_xLbxGetWinAttrAndGeomReq 8
+
+typedef struct {
+    BYTE type;  /* X_Reply */
+    CARD8 backingStore;
+    CARD16 sequenceNumber B16;
+    CARD32 length B32; /* NOT 0; this is an extra-large reply */
+    VisualID visualID B32;
+#if defined(__cplusplus) || defined(c_plusplus)
+    CARD16 c_class B16;
+#else
+    CARD16 class B16;
+#endif
+    CARD8 bitGravity;
+    CARD8 winGravity;
+    CARD32 backingBitPlanes B32;
+    CARD32 backingPixel B32;
+    BOOL saveUnder;
+    BOOL mapInstalled;
+    CARD8 mapState;
+    BOOL override;
+    Colormap colormap B32;
+    CARD32 allEventMasks B32;
+    CARD32 yourEventMask B32;
+    CARD16 doNotPropagateMask B16;
+    CARD16 pad1 B16;
+    Window root B32;
+    INT16 x B16, y B16;
+    CARD16 width B16, height B16;
+    CARD16 borderWidth B16;
+    CARD8 depth;
+    CARD8 pad2;
+} xLbxGetWinAttrAndGeomReply;
+#define sz_xLbxGetWinAttrAndGeomReply 60
+
+
+typedef struct {
+    CARD8      reqType;        /* always LbxReqCode */
+    CARD8      lbxReqType;     /* always X_LbxSync */
+    CARD16     length B16;
+} xLbxSyncReq;
+#define sz_xLbxSyncReq 4
+
+typedef struct {
+    BYTE       type;                   /* X_Reply */
+    CARD8      pad0;
+    CARD16     sequenceNumber B16;
+    CARD32     length B32;
+    CARD32     pad1 B32;
+    CARD32     pad2 B32;
+    CARD32     pad3 B32;
+    CARD32     pad4 B32;
+    CARD32     pad5 B32;
+    CARD32     pad6 B32;
+} xLbxSyncReply;
+#define sz_xLbxSyncReply 32
+
+
+/* an LBX squished charinfo packs the data in a CARD32 as follows */
+#define        LBX_WIDTH_SHIFT         26
+#define        LBX_LEFT_SHIFT          20
+#define        LBX_RIGHT_SHIFT         13
+#define        LBX_ASCENT_SHIFT        7
+#define        LBX_DESCENT_SHIFT       0
+
+#define        LBX_WIDTH_BITS          6
+#define        LBX_LEFT_BITS           6
+#define        LBX_RIGHT_BITS          7
+#define        LBX_ASCENT_BITS         6
+#define        LBX_DESCENT_BITS        7
+
+#define        LBX_WIDTH_MASK          0xfc000000
+#define        LBX_LEFT_MASK           0x03f00000
+#define        LBX_RIGHT_MASK          0x000fe000
+#define        LBX_ASCENT_MASK         0x00001f80
+#define        LBX_DESCENT_MASK        0x0000007f
+
+#define        LBX_MASK_BITS(val, n)   ((unsigned int) ((val) & ((1 << (n)) - 1)))
+
+typedef struct {
+    CARD32     metrics B32;
+} xLbxCharInfo;
+
+/* note that this is identical to xQueryFontReply except for missing 
+ * first 2 words
+ */
+typedef struct {
+    xCharInfo minBounds; 
+/* XXX do we need to leave this gunk? */
+#ifndef WORD64
+    CARD32 walign1 B32;
+#endif
+    xCharInfo maxBounds; 
+#ifndef WORD64
+    CARD32 walign2 B32;
+#endif
+    CARD16 minCharOrByte2 B16, maxCharOrByte2 B16;
+    CARD16 defaultChar B16;
+    CARD16 nFontProps B16;  /* followed by this many xFontProp structures */
+    CARD8 drawDirection;
+    CARD8 minByte1, maxByte1;
+    BOOL allCharsExist;
+    INT16 fontAscent B16, fontDescent B16;
+    CARD32 nCharInfos B32; /* followed by this many xLbxCharInfo structures */
+} xLbxFontInfo;
+
+typedef struct {
+    BYTE       type;                   /* X_Reply */
+    CARD8      compression;
+    CARD16     sequenceNumber B16;
+    CARD32     length B32;
+    CARD32     tag B32;
+    CARD32     pad0 B32;
+    CARD32     pad1 B32;
+    CARD32     pad2 B32;
+    CARD32     pad3 B32;
+    CARD32     pad4 B32;
+    /* X_QueryFont sticks much of the data in the base reply packet,
+     * but we hope that it won't be needed, (and it won't fit in 32 bytes
+     * with the tag anyways)
+     *
+     * if any additional data is needed, its sent in a xLbxFontInfo
+     */
+} xLbxQueryFontReply;
+#define sz_xLbxQueryFontReply  32
+
+typedef struct _LbxChangeProperty {
+    CARD8      reqType;        /* always LbxReqCode */
+    CARD8      lbxReqType;     /* always X_LbxChangeProperty */
+    CARD16     length B16;
+    Window     window B32;
+    Atom       property B32;
+    Atom       type B32;
+    CARD8      format;
+    CARD8      mode;
+    BYTE       pad[2];
+    CARD32     nUnits B32;
+} xLbxChangePropertyReq;
+#define        sz_xLbxChangePropertyReq        24
+
+typedef struct {
+    BYTE       type;                   /* X_Reply */
+    CARD8      pad;
+    CARD16     sequenceNumber B16;
+    CARD32     length B32;
+    CARD32     tag B32;
+    CARD32     pad0 B32;
+    CARD32     pad1 B32;
+    CARD32     pad2 B32;
+    CARD32     pad3 B32;
+    CARD32     pad4 B32;
+} xLbxChangePropertyReply;
+#define sz_xLbxChangePropertyReply     32
+
+typedef struct _LbxGetProperty {
+    CARD8      reqType;        /* always LbxReqCode */
+    CARD8      lbxReqType;     /* always X_LbxGetProperty */
+    CARD16     length B16;
+    Window     window B32;
+    Atom       property B32;
+    Atom       type B32;
+    CARD8      delete;
+    BYTE       pad[3];
+    CARD32     longOffset B32;
+    CARD32     longLength B32;
+} xLbxGetPropertyReq;
+#define        sz_xLbxGetPropertyReq   28
+
+typedef struct {
+    BYTE       type;                   /* X_Reply */
+    CARD8      format;
+    CARD16     sequenceNumber B16;
+    CARD32     length B32;
+    Atom       propertyType B32;
+    CARD32     bytesAfter B32;
+    CARD32     nItems B32;
+    CARD32     tag B32;
+    CARD32     pad1 B32;
+    CARD32     pad2 B32;
+} xLbxGetPropertyReply;
+#define sz_xLbxGetPropertyReply        32
+
+typedef struct _LbxTagData {
+    CARD8      reqType;        /* always LbxReqCode */
+    CARD8      lbxReqType;     /* always X_LbxTagData */
+    CARD16     length B16;
+    XID                tag B32;
+    CARD32     real_length B32;
+    /* data */
+} xLbxTagDataReq;
+#define        sz_xLbxTagDataReq       12
+
+typedef struct _LbxInvalidateTag {
+    CARD8      reqType;        /* always LbxReqCode */
+    CARD8      lbxReqType;     /* always X_LbxInvalidateTag */
+    CARD16     length B16;
+    CARD32     tag B32;
+} xLbxInvalidateTagReq;
+#define        sz_xLbxInvalidateTagReq 8
+
+typedef struct _LbxPutImage {
+    CARD8      reqType;        /* always LbxReqCode */
+    CARD8      lbxReqType;     /* always X_LbxPutImage */
+    CARD16     length B16;
+    CARD8      compressionMethod;
+    CARD8      cacheEnts;
+    CARD8      bitPacked;
+    /* rest is variable */
+} xLbxPutImageReq;
+#define sz_xLbxPutImageReq     7
+
+typedef struct {
+    CARD8      reqType;        /* always LbxReqCode */
+    CARD8      lbxReqType;     /* always X_LbxGetImage */
+    CARD16     length B16;
+    Drawable   drawable B32;
+    INT16      x B16, y B16;
+    CARD16     width B16, height B16;
+    CARD32     planeMask B32;
+    CARD8      format;
+    CARD8      pad1;
+    CARD16     pad2 B16;
+} xLbxGetImageReq;    
+
+#define sz_xLbxGetImageReq 24
+
+typedef struct {
+    BYTE type;                 /* X_Reply */
+    CARD8 depth;
+    CARD16 sequenceNumber B16;
+    CARD32 lbxLength B32;
+    CARD32 xLength B32;
+    VisualID visual B32;
+    CARD8 compressionMethod;
+    CARD8 pad1;
+    CARD16 pad2 B16;
+    CARD32 pad3 B32;
+    CARD32 pad4 B32;
+    CARD32 pad5 B32;
+} xLbxGetImageReply;
+
+#define sz_xLbxGetImageReply 32
+  
+/* Following used for LbxPolyPoint, LbxPolyLine, LbxPolySegment,
+   LbxPolyRectangle, LbxPolyArc, LbxPolyFillRectangle and LbxPolyFillArc */
+
+#define GFX_CACHE_SIZE  15
+
+#define GFXdCacheEnt(e)            ((e) & 0xf)
+#define GFXgCacheEnt(e)            (((e) >> 4) & 0xf)
+#define GFXCacheEnts(d,g)   (((d) & 0xf) | (((g) & 0xf) << 4))
+
+#define GFXCacheNone   0xf
+
+typedef struct _LbxPolyPoint {
+    CARD8      reqType;        /* always LbxReqCode */
+    CARD8      lbxReqType;
+    CARD16     length B16;
+    CARD8      cacheEnts;
+    CARD8      padBytes;
+} xLbxPolyPointReq;
+
+#define sz_xLbxPolyPointReq    6
+
+typedef xLbxPolyPointReq xLbxPolyLineReq;
+typedef xLbxPolyPointReq xLbxPolySegmentReq;
+typedef xLbxPolyPointReq xLbxPolyRectangleReq;
+typedef xLbxPolyPointReq xLbxPolyArcReq;
+typedef xLbxPolyPointReq xLbxPolyFillRectangleReq;
+typedef xLbxPolyPointReq xLbxPolyFillArcReq;
+
+#define sz_xLbxPolyLineReq             sz_xLbxPolyPointReq
+#define sz_xLbxPolySegmentReq          sz_xLbxPolyPointReq
+#define sz_xLbxPolyRectangleReq                sz_xLbxPolyPointReq
+#define sz_xLbxPolyArcReq              sz_xLbxPolyPointReq
+#define sz_xLbxPolyFillRectangleReq    sz_xLbxPolyPointReq
+#define sz_xLbxPolyFillArc             sz_xLbxPolyPointReq
+
+typedef struct _LbxFillPoly {
+    CARD8      reqType;        /* always LbxReqCode */
+    CARD8      lbxReqType;
+    CARD16     length B16;
+    CARD8      cacheEnts;
+    BYTE       shape;
+    CARD8      padBytes;
+} xLbxFillPolyReq;
+#define sz_xLbxFillPolyReq     7
+
+typedef struct _LbxCopyArea {
+    CARD8      reqType;        /* always LbxReqCode */
+    CARD8      lbxReqType;
+    CARD16     length B16;
+    CARD8      srcCache;       /* source drawable */
+    CARD8      cacheEnts;      /* dest drawable and gc */
+    /* followed by encoded src x, src y, dst x, dst y, width, height */
+} xLbxCopyAreaReq;
+    
+#define sz_xLbxCopyAreaReq  6
+
+typedef struct _LbxCopyPlane {
+    CARD8      reqType;        /* always LbxReqCode */
+    CARD8      lbxReqType;
+    CARD16     length B16;
+    CARD32     bitPlane B32;
+    CARD8      srcCache;       /* source drawable */
+    CARD8      cacheEnts;      /* dest drawable and gc */
+    /* followed by encoded src x, src y, dst x, dst y, width, height */
+} xLbxCopyPlaneReq;
+    
+#define sz_xLbxCopyPlaneReq  10
+
+typedef struct _LbxPolyText {
+    CARD8      reqType;        /* always LbxReqCode */
+    CARD8      lbxReqType;
+    CARD16     length B16;
+    CARD8      cacheEnts;
+    /* followed by encoded src x, src y coordinates and text elts */
+} xLbxPolyTextReq;
+
+#define sz_xLbxPolyTextReq  5
+
+typedef xLbxPolyTextReq xLbxPolyText8Req;
+typedef xLbxPolyTextReq xLbxPolyText16Req;
+    
+#define sz_xLbxPolyTextReq     5
+#define sz_xLbxPolyText8Req    5
+#define sz_xLbxPolyText16Req   5
+
+typedef struct _LbxImageText {
+    CARD8      reqType;        /* always LbxReqCode */
+    CARD8      lbxReqType;
+    CARD16     length B16;
+    CARD8      cacheEnts;
+    CARD8      nChars;
+    /* followed by encoded src x, src y coordinates and string */
+} xLbxImageTextReq;
+    
+typedef xLbxImageTextReq xLbxImageText8Req;
+typedef xLbxImageTextReq xLbxImageText16Req;
+    
+#define sz_xLbxImageTextReq    6
+#define sz_xLbxImageText8Req   6
+#define sz_xLbxImageText16Req  6
+
+typedef struct {
+    CARD8       offset;
+    CARD8       diff;
+} xLbxDiffItem;
+#define sz_xLbxDiffItem    2
+
+typedef struct {
+    BYTE       type;           /* X_Reply */
+    CARD8      nOpts;
+    CARD16     sequenceNumber B16;
+    CARD32     length B32;
+    CARD32     optDataStart B32;
+    CARD32     pad0 B32;
+    CARD32     pad1 B32;
+    CARD32     pad2 B32;
+    CARD32     pad3 B32;
+    CARD32     pad4 B32;
+} xLbxStartReply;
+#define sz_xLbxStartReply      32
+#define sz_xLbxStartReplyHdr   8
+
+typedef struct _LbxQueryExtension {
+    CARD8      reqType;        /* always LbxReqCode */
+    CARD8      lbxReqType;     /* always X_LbxQueryExtension */
+    CARD16     length B16;
+    CARD32     nbytes B32;
+} xLbxQueryExtensionReq;
+#define        sz_xLbxQueryExtensionReq        8
+
+typedef struct _LbxQueryExtensionReply {
+    BYTE       type;                   /* X_Reply */
+    CARD8      numReqs;
+    CARD16     sequenceNumber B16;
+    CARD32     length B32;
+    BOOL       present;
+    CARD8      major_opcode;
+    CARD8      first_event;
+    CARD8      first_error;
+    CARD32     pad0 B32;
+    CARD32     pad1 B32;
+    CARD32     pad2 B32;
+    CARD32     pad3 B32;
+    CARD32     pad4 B32;
+
+    /* reply & event generating requests */
+} xLbxQueryExtensionReply;
+#define sz_xLbxQueryExtensionReply     32
+
+
+typedef struct _LbxBeginLargeRequest {
+    CARD8      reqType;        /* always LbxReqCode */
+    CARD8      lbxReqType;     /* always X_LbxBeginLargeRequest */
+    CARD16     length B16;
+    CARD32     largeReqLength B32;
+} xLbxBeginLargeRequestReq;
+#define        sz_BeginLargeRequestReq 8
+
+typedef struct _LbxLargeRequestData {
+    CARD8      reqType;        /* always LbxReqCode */
+    CARD8      lbxReqType;     /* always X_LbxLargeRequestData */
+    CARD16     length B16;
+    /* followed by LISTofCARD8 data */
+} xLbxLargeRequestDataReq;
+#define        sz_LargeRequestDataReq 4
+
+typedef struct _LbxEndLargeRequest {
+    CARD8      reqType;        /* always LbxReqCode */
+    CARD8      lbxReqType;     /* always X_LbxEndLargeRequest */
+    CARD16     length B16;
+} xLbxEndLargeRequestReq;
+#define        sz_EndLargeRequestReq 4
+
+
+
+typedef struct _LbxSwitchEvent {
+    BYTE       type;           /* always eventBase + LbxEvent */
+    BYTE       lbxType;        /* LbxSwitchEvent */
+    CARD16     pad B16;
+    CARD32     client B32;
+} xLbxSwitchEvent;
+#define sz_xLbxSwitchEvent     8
+
+typedef struct _LbxCloseEvent {
+    BYTE       type;           /* always eventBase + LbxEvent */
+    BYTE       lbxType;        /* LbxCloseEvent */
+    CARD16     sequenceNumber B16;
+    CARD32     client B32;
+    CARD32     pad1 B32;
+    CARD32     pad2 B32;
+    CARD32     pad3 B32;
+    CARD32     pad4 B32;
+    CARD32     pad5 B32;
+    CARD32     pad6 B32;
+} xLbxCloseEvent;
+#define sz_xLbxCloseEvent      32
+
+typedef struct _LbxInvalidateTagEvent {
+    BYTE       type;           /* always eventBase + LbxEvent */
+    BYTE       lbxType;        /* LbxInvalidateTagEvent */
+    CARD16     sequenceNumber B16;
+    CARD32     tag B32;
+    CARD32     tagType B32;
+    CARD32     pad1 B32;
+    CARD32     pad2 B32;
+    CARD32     pad3 B32;
+    CARD32     pad4 B32;
+    CARD32     pad5 B32;
+} xLbxInvalidateTagEvent;
+#define sz_xLbxInvalidateTagEvent 32
+
+typedef struct _LbxSendTagDataEvent {
+    BYTE       type;           /* always eventBase + LbxEvent */
+    BYTE       lbxType;        /* LbxSendTagDataEvent */
+    CARD16     sequenceNumber B16;
+    CARD32     tag B32;
+    CARD32     tagType B32;
+    CARD32     pad1 B32;
+    CARD32     pad2 B32;
+    CARD32     pad3 B32;
+    CARD32     pad4 B32;
+    CARD32     pad5 B32;
+} xLbxSendTagDataEvent;
+#define sz_xLbxSendTagDataEvent 32
+
+typedef struct _LbxListenToOneEvent {
+    BYTE       type;           /* always eventBase + LbxEvent */
+    BYTE       lbxType;        /* LbxListenToOneEvent */
+    CARD16     sequenceNumber B16;
+    CARD32     client B32;
+    CARD32     pad1 B32;
+    CARD32     pad2 B32;
+    CARD32     pad3 B32;
+    CARD32     pad4 B32;
+    CARD32     pad5 B32;
+    CARD32     pad6 B32;
+} xLbxListenToOneEvent;
+#define sz_xLbxListenToOneEvent 32
+
+typedef struct _LbxListenToAllEvent {
+    BYTE       type;           /* always eventBase + LbxEvent */
+    BYTE       lbxType;        /* LbxListenToAllEvent */
+    CARD16     sequenceNumber B16;
+    CARD32     pad1 B32;
+    CARD32     pad2 B32;
+    CARD32     pad3 B32;
+    CARD32     pad4 B32;
+    CARD32     pad5 B32;
+    CARD32     pad6 B32;
+    CARD32     pad7 B32;
+} xLbxListenToAllEvent;
+#define sz_xLbxListenToOneEvent 32
+
+typedef struct _LbxReleaseCmapEvent {
+    BYTE       type;           /* always eventBase + LbxEvent */
+    BYTE       lbxType;        /* LbxReleaseCmapEvent */
+    CARD16     sequenceNumber B16;
+    Colormap   colormap B32;
+    CARD32     pad1 B32;
+    CARD32     pad2 B32;
+    CARD32     pad3 B32;
+    CARD32     pad4 B32;
+    CARD32     pad5 B32;
+    CARD32     pad6 B32;
+} xLbxReleaseCmapEvent;
+#define sz_xLbxReleaseCmapEvent        32
+
+
+typedef struct _LbxFreeCellsEvent {
+    BYTE       type;           /* always eventBase + LbxEvent */
+    BYTE       lbxType;        /* LbxFreeCellsEvent */
+    CARD16     sequenceNumber B16;
+    Colormap   colormap B32;
+    CARD32     pixelStart B32;
+    CARD32     pixelEnd B32;
+    CARD32     pad1 B32;
+    CARD32     pad2 B32;
+    CARD32     pad3 B32;
+    CARD32     pad4 B32;
+} xLbxFreeCellsEvent;
+#define sz_xLbxFreeCellsEvent  32
+
+
+/*
+ * squished X event sizes.  If these change, be sure to update lbxquish.c
+ * and unsquish.c appropriately
+ *
+ * lbxsz_* is the padded squished length
+ * lbxupsz_* is the unpadded squished length
+ */
+
+#define          lbxsz_KeyButtonEvent          32
+#define        lbxupsz_KeyButtonEvent          31
+
+#define          lbxsz_EnterLeaveEvent         32
+#define        lbxupsz_EnterLeaveEvent         32
+
+#define          lbxsz_FocusEvent              12
+#define        lbxupsz_FocusEvent              9
+
+#define          lbxsz_KeymapEvent             32
+#define        lbxupsz_KeymapEvent             32
+
+#define          lbxsz_ExposeEvent             20
+#define        lbxupsz_ExposeEvent             18
+
+#define          lbxsz_GfxExposeEvent          24
+#define        lbxupsz_GfxExposeEvent          21
+
+#define          lbxsz_NoExposeEvent           12
+#define        lbxupsz_NoExposeEvent           11
+
+#define          lbxsz_VisibilityEvent         12
+#define        lbxupsz_VisibilityEvent         9
+
+#define          lbxsz_CreateNotifyEvent       24
+#define        lbxupsz_CreateNotifyEvent       23
+
+#define          lbxsz_DestroyNotifyEvent      12
+#define        lbxupsz_DestroyNotifyEvent      12
+
+#define          lbxsz_UnmapNotifyEvent        16
+#define        lbxupsz_UnmapNotifyEvent        13
+
+#define          lbxsz_MapNotifyEvent          16
+#define        lbxupsz_MapNotifyEvent          13
+
+#define          lbxsz_MapRequestEvent         12
+#define        lbxupsz_MapRequestEvent         12
+
+#define          lbxsz_ReparentEvent           24
+#define        lbxupsz_ReparentEvent           21
+
+#define          lbxsz_ConfigureNotifyEvent    28
+#define        lbxupsz_ConfigureNotifyEvent    27
+
+#define          lbxsz_ConfigureRequestEvent   28
+#define        lbxupsz_ConfigureRequestEvent   28
+
+#define          lbxsz_GravityEvent            16
+#define        lbxupsz_GravityEvent            16
+
+#define          lbxsz_ResizeRequestEvent      12
+#define        lbxupsz_ResizeRequestEvent      12
+
+#define          lbxsz_CirculateEvent          20
+#define        lbxupsz_CirculateEvent          17
+
+#define          lbxsz_PropertyEvent           20
+#define        lbxupsz_PropertyEvent           17
+
+#define          lbxsz_SelectionClearEvent     16
+#define        lbxupsz_SelectionClearEvent     16
+
+#define          lbxsz_SelectionRequestEvent   28
+#define        lbxupsz_SelectionRequestEvent   28
+
+#define          lbxsz_SelectionNotifyEvent    24
+#define        lbxupsz_SelectionNotifyEvent    24
+
+#define          lbxsz_ColormapEvent           16
+#define        lbxupsz_ColormapEvent           14
+
+#define          lbxsz_MappingNotifyEvent      8
+#define        lbxupsz_MappingNotifyEvent      7
+
+#define          lbxsz_ClientMessageEvent      32
+#define        lbxupsz_ClientMessageEvent      32
+
+#define        lbxsz_UnknownEvent              32
+
+#ifdef DEBUG
+
+#define DBG_SWITCH     0x00000001
+#define DBG_CLOSE      0x00000002
+#define DBG_IO         0x00000004
+#define DBG_READ_REQ   0x00000008
+#define DBG_LEN                0x00000010
+#define DBG_BLOCK      0x00000020
+#define DBG_CLIENT     0x00000040
+#define DBG_DELTA      0x00000080
+
+extern int lbxDebug;
+
+#define DBG(n,m)    if (lbxDebug & (n)) { fprintf m; } else
+#else
+#define DBG(n,m)
+#endif
+
+#endif /* _LBXSTR_H_ */
diff --git a/Xserver/include/extensions/lbxzlib.h b/Xserver/include/extensions/lbxzlib.h
new file mode 100644 (file)
index 0000000..3dff78f
--- /dev/null
@@ -0,0 +1,50 @@
+/* $XConsortium: lbxzlib.h /main/2 1996/10/27 15:39:45 rws $ */
+/*
+ * Copyright 1993 Network Computing Devices
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the name of NCD. not be used in advertising or
+ * publicity pertaining to distribution of the software without specific,
+ * written prior permission.  NCD. makes no representations about the
+ * suitability of this software for any purpose.  It is provided "as is"
+ * without express or implied warranty.
+ *
+ * NCD. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL NCD.
+ * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
+ * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN 
+ * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ * Author:  Dale Tonogai, Network Computing Devices
+ */
+
+#ifndef _ZLIB_H_
+#define _ZLIB_H_
+
+#define ZLIB_STRCOMP_OPT       "XC-ZLIB"
+#define ZLIB_STRCOMP_OPT_LEN   7
+
+#define ZLIB_PACKET_HDRLEN     2
+#define ZLIB_MAX_DATALEN       0xfff
+#define ZLIB_MAX_PLAIN         270
+#define ZLIB_MAX_OUTLEN                (ZLIB_MAX_PLAIN << 1)
+
+#define ZLIB_COMPRESS_FLAG     0x80
+#define ZLIB_DATALEN_MASK      0x0f
+
+#define ZLIB_PUT_PKTHDR(p, len, compflag) \
+    { \
+       (p)[0] = ((unsigned)(len)) >> 8 | ((compflag) ? ZLIB_COMPRESS_FLAG : 0);\
+       (p)[1] = (len) & 0xff; \
+    }
+
+#define ZLIB_GET_DATALEN(p) \
+       ((((unsigned)((p)[0] & ZLIB_DATALEN_MASK)) << 8) | (unsigned)(p)[1])
+
+#define ZLIB_COMPRESSED(p) ((p)[0] & ZLIB_COMPRESS_FLAG)
+
+#endif /* _ZLIB_H_ */
diff --git a/Xserver/include/extensions/mitmiscstr.h b/Xserver/include/extensions/mitmiscstr.h
new file mode 100644 (file)
index 0000000..8d8ae30
--- /dev/null
@@ -0,0 +1,66 @@
+/************************************************************
+
+Copyright (c) 1989  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+********************************************************/
+
+/* RANDOM CRUFT! THIS HAS NO OFFICIAL X CONSORTIUM BLESSING */
+
+/* $XConsortium: mitmiscstr.h,v 1.4 94/04/17 20:11:20 keith Exp $ */
+
+#include "MITMisc.h"
+
+#define MITMISCNAME "MIT-SUNDRY-NONSTANDARD"
+
+typedef struct _SetBugMode {
+    CARD8      reqType;        /* always MITReqCode */
+    CARD8      mitReqType;     /* always X_MITSetBugMode */
+    CARD16     length B16;
+    BOOL       onOff;
+    BYTE       pad0;
+    CARD16     pad1;
+} xMITSetBugModeReq;
+#define sz_xMITSetBugModeReq   8
+
+typedef struct _GetBugMode {
+    CARD8      reqType;        /* always MITReqCode */
+    CARD8      mitReqType;     /* always X_MITGetBugMode */
+    CARD16     length B16;
+} xMITGetBugModeReq;
+#define sz_xMITGetBugModeReq   4
+
+typedef struct {
+    BYTE       type;                   /* X_Reply */
+    BOOL       onOff;
+    CARD16     sequenceNumber B16;
+    CARD32     length B32;
+    CARD32     pad0 B32;
+    CARD32     pad1 B32;
+    CARD32     pad2 B32;
+    CARD32     pad3 B32;
+    CARD32     pad4 B32;
+    CARD32     pad5 B32;
+} xMITGetBugModeReply;
+#define sz_xMITGetBugModeReply 32
+
diff --git a/Xserver/include/extensions/multibuf.h b/Xserver/include/extensions/multibuf.h
new file mode 100644 (file)
index 0000000..2c8889a
--- /dev/null
@@ -0,0 +1,351 @@
+/*
+ * $XConsortium: multibuf.h,v 1.18 94/04/17 20:11:21 dpw Exp $
+ * $XFree86: xc/include/extensions/multibuf.h,v 3.0 1996/05/06 05:52:38 dawes Exp $
+ *
+Copyright (c) 1989  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+ */
+
+#ifndef _MULTIBUF_H_
+#define _MULTIBUF_H_
+
+#include <X11/Xfuncproto.h>
+
+#define MULTIBUFFER_PROTOCOL_NAME "Multi-Buffering"
+
+#define MULTIBUFFER_MAJOR_VERSION      1       /* current version numbers */
+#define MULTIBUFFER_MINOR_VERSION      1       /* has ClearImageBufferArea */
+
+#define X_MbufGetBufferVersion         0
+#define X_MbufCreateImageBuffers       1
+#define X_MbufDestroyImageBuffers      2
+#define X_MbufDisplayImageBuffers      3
+#define X_MbufSetMBufferAttributes     4
+#define X_MbufGetMBufferAttributes     5
+#define X_MbufSetBufferAttributes      6
+#define X_MbufGetBufferAttributes      7
+#define X_MbufGetBufferInfo            8
+#define X_MbufCreateStereoWindow       9
+#define X_MbufClearImageBufferArea     10
+
+/*
+ * update_action field
+ */
+#define MultibufferUpdateActionUndefined       0
+#define MultibufferUpdateActionBackground      1
+#define MultibufferUpdateActionUntouched       2
+#define MultibufferUpdateActionCopied          3
+
+/*
+ * update_hint field
+ */
+#define MultibufferUpdateHintFrequent          0
+#define MultibufferUpdateHintIntermittent      1
+#define MultibufferUpdateHintStatic            2
+
+/*
+ * valuemask fields
+ */
+#define MultibufferWindowUpdateHint    (1L << 0)
+#define MultibufferBufferEventMask     (1L << 0)
+
+/*
+ * mono vs. stereo and left vs. right
+ */
+#define MultibufferModeMono            0
+#define MultibufferModeStereo          1
+#define MultibufferSideMono            0
+#define MultibufferSideLeft            1
+#define MultibufferSideRight           2
+
+/*
+ * clobber state
+ */
+#define MultibufferUnclobbered         0
+#define MultibufferPartiallyClobbered  1
+#define MultibufferFullyClobbered      2
+
+/*
+ * event stuff
+ */
+#define MultibufferClobberNotifyMask   0x02000000
+#define MultibufferUpdateNotifyMask    0x04000000
+
+#define MultibufferClobberNotify       0
+#define MultibufferUpdateNotify                1
+#define MultibufferNumberEvents                (MultibufferUpdateNotify + 1)
+
+#define MultibufferBadBuffer           0
+#define MultibufferNumberErrors                (MultibufferBadBuffer + 1)
+
+
+#ifndef _MULTIBUF_SERVER_
+/*
+ * Extra definitions that will only be needed in the client
+ */
+typedef XID Multibuffer;
+
+typedef struct {
+    int        type;               /* of event */
+    unsigned long serial;   /* # of last request processed by server */
+    int send_event;        /* true if this came frome a SendEvent request */
+    Display *display;      /* Display the event was read from */
+    Multibuffer buffer;            /* buffer of event */
+    int        state;              /* see Clobbered constants above */
+} XmbufClobberNotifyEvent;
+
+typedef struct {
+    int        type;               /* of event */
+    unsigned long serial;   /* # of last request processed by server */
+    int send_event;        /* true if this came frome a SendEvent request */
+    Display *display;      /* Display the event was read from */
+    Multibuffer buffer;            /* buffer of event */
+} XmbufUpdateNotifyEvent;
+
+
+/*
+ * per-window attributes that can be got
+ */
+typedef struct {
+    int displayed_index;       /* which buffer is being displayed */
+    int update_action;         /* Undefined, Background, Untouched, Copied */
+    int update_hint;           /* Frequent, Intermittent, Static */
+    int window_mode;           /* Mono, Stereo */
+    int nbuffers;              /* Number of buffers */
+    Multibuffer *buffers;      /* Buffers */
+} XmbufWindowAttributes;
+
+/*
+ * per-window attributes that can be set
+ */
+typedef struct {
+    int update_hint;           /* Frequent, Intermittent, Static */
+} XmbufSetWindowAttributes;
+
+
+/*
+ * per-buffer attributes that can be got
+ */
+typedef struct {
+    Window window;             /* which window this belongs to */
+    unsigned long event_mask;  /* events that have been selected */
+    int buffer_index;          /* which buffer is this */
+    int side;                  /* Mono, Left, Right */
+} XmbufBufferAttributes;
+
+/*
+ * per-buffer attributes that can be set
+ */
+typedef struct {
+    unsigned long event_mask;  /* events that have been selected */
+} XmbufSetBufferAttributes;
+
+
+/*
+ * per-screen buffer info (there will be lists of them)
+ */
+typedef struct {
+    VisualID visualid;         /* visual usuable at this depth */
+    int max_buffers;           /* most buffers for this visual */
+    int depth;                 /* depth of buffers to be created */
+} XmbufBufferInfo;
+
+_XFUNCPROTOBEGIN
+
+extern Bool XmbufQueryExtension(
+#if NeedFunctionPrototypes
+    Display*           /* dpy */,
+    int*               /* event_base_return */,
+    int*               /* error_base_return */
+#endif
+);
+
+extern Status XmbufGetVersion(
+#if NeedFunctionPrototypes
+    Display*           /* dpy */,
+    int*               /* major_version_return */,
+    int*               /* minor_version_return */
+#endif
+);
+
+extern int XmbufCreateBuffers(
+#if NeedFunctionPrototypes
+    Display*           /* dpy */,
+    Window             /* w */,
+    int                        /* count */,
+    int                        /* update_action */,
+    int                        /* update_hint */,
+    Multibuffer*       /* buffers */
+#endif
+);
+
+extern void XmbufDestroyBuffers(
+#if NeedFunctionPrototypes
+    Display*           /* dpy */,
+    Window             /* window */
+#endif
+);
+
+extern void XmbufDisplayBuffers(
+#if NeedFunctionPrototypes
+    Display*           /* dpy */,
+    int                        /* count */,
+    Multibuffer*       /* buffers */,
+    int                        /* min_delay */,
+    int                        /* max_delay */
+#endif
+);
+
+extern Status XmbufGetWindowAttributes(
+#if NeedFunctionPrototypes
+    Display*                   /* dpy */,
+    Window                     /* w */,
+    XmbufWindowAttributes*     /* attr */
+#endif
+);
+
+extern void XmbufChangeWindowAttributes(
+#if NeedFunctionPrototypes
+    Display*                   /* dpy */,
+    Window                     /* w */,
+    unsigned long              /* valuemask */,
+    XmbufSetWindowAttributes*  /* attr */
+#endif
+);
+
+extern Status XmbufGetBufferAttributes(
+#if NeedFunctionPrototypes
+    Display*                   /* dpy */,
+    Multibuffer                        /* b */,
+    XmbufBufferAttributes*     /* attr */
+#endif
+);
+
+extern void XmbufChangeBufferAttributes(
+#if NeedFunctionPrototypes
+    Display*                   /* dpy */,
+    Multibuffer                        /* b */,
+    unsigned long              /* valuemask */,
+    XmbufSetBufferAttributes*  /* attr */
+#endif
+);
+
+extern Status XmbufGetScreenInfo(
+#if NeedFunctionPrototypes
+    Display*                   /* dpy */,
+    Drawable                   /* d */,
+    int*                       /* nmono_return */,
+    XmbufBufferInfo**          /* mono_info_return */,
+    int*                       /* nstereo_return */,
+    XmbufBufferInfo**          /* stereo_info_return */
+#endif
+);
+
+extern Window XmbufCreateStereoWindow(
+#if NeedFunctionPrototypes
+    Display*                   /* dpy */,
+    Window                     /* parent */,
+    int                                /* x */,
+    int                                /* y */,
+    unsigned int               /* width */,
+    unsigned int               /* height */,
+    unsigned int               /* border_width */,
+    int                                /* depth */,
+    unsigned int               /* class */,
+    Visual*                    /* visual */,
+    unsigned long              /* valuemask */,
+    XSetWindowAttributes*      /* attr */,
+    Multibuffer*               /* leftp */,
+    Multibuffer*               /* rightp */
+#endif
+);
+
+extern void XmbufClearBufferArea(
+#if NeedFunctionPrototypes
+    Display*                   /* dpy */,
+    Multibuffer                        /* buffer */,
+    int                                /* x */,
+    int                                /* y */,
+    unsigned int               /* width */,
+    unsigned int               /* height */,
+    Bool                       /* exposures */
+#endif
+);
+
+_XFUNCPROTOEND
+
+#else
+
+typedef Bool   (* mbInitFunc)();
+
+struct _mbufScreen;            /* declared in multibufst.h */
+
+extern void    RegisterMultibufferInit(
+#if NeedFunctionPrototypes
+    ScreenPtr                  /* pScreen */,
+    Bool (* /* bufMultibufferInit */)(
+#if NeedNestedPrototypes
+       ScreenPtr               /* pScreen */,
+       struct _mbufScreen *    /* pMBScreen */
+#endif
+    )
+#endif
+);
+
+struct xMbufBufferInfo;                /* declared in multibufst.h */
+
+extern void    RegisterDoubleBufferHardware(
+#if NeedFunctionPrototypes
+    ScreenPtr                  /* pScreen */,
+    int                                /* nInfo */,
+    struct xMbufBufferInfo *   /* pInfo */,
+    DevUnion *                 /* frameBuffer */,
+    DevUnion                   /* selectPlane */,
+    void (* /* CopyBufferBitsFunc */ )(),
+    void (* /* DrawSelectPlaneFunc */ )()
+#endif
+);
+
+extern int     CreateImageBuffers (
+#if NeedFunctionPrototypes
+    WindowPtr                  /* pWin */,
+    int                                /* nbuf */,
+    XID *                      /* ids */,
+    int                                /* action */,
+    int                                /* hint */
+#endif
+);
+extern void    DestroyImageBuffers (
+#if NeedFunctionPrototypes
+    WindowPtr                  /* pWin */
+#endif
+);
+extern int     DisplayImageBuffers (
+#if NeedFunctionPrototypes
+    XID *                      /* ids */,
+    int                                /* nbuf */
+#endif
+);
+
+#endif /* _MULTIBUF_SERVER_ */
+#endif /* _MULTIBUF_H_ */
diff --git a/Xserver/include/extensions/multibufst.h b/Xserver/include/extensions/multibufst.h
new file mode 100644 (file)
index 0000000..abf8a07
--- /dev/null
@@ -0,0 +1,629 @@
+/*
+ * $XConsortium: multibufst.h,v 1.16 95/06/08 23:20:39 gildea Exp $
+ * $XFree86: xc/include/extensions/multibufst.h,v 3.1 1996/05/06 05:52:39 dawes Exp $
+ *
+Copyright (c) 1989  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+ */
+
+#ifndef _MULTIBUFST_H_
+#define _MULTIBUFST_H_
+
+/*
+ * Protocol requests constants and alignment values
+ */
+
+#include "multibuf.h"
+#ifdef _MULTIBUF_SERVER_
+#include "input.h"
+#endif
+
+#if (defined(__STDC__) && !defined(UNIXCPP)) || defined(ANSICPP)
+#define MbufGetReq(name,req,info) GetReq (name, req); \
+       req->reqType = info->codes->major_opcode; \
+       req->mbufReqType = X_##name;
+#else
+#define MbufGetReq(name,req,info) GetReq (name, req); \
+       req->reqType = info->codes->major_opcode; \
+       req->mbufReqType = X_/**/name;
+#endif
+
+#define Window CARD32
+#define Drawable CARD32
+#define VisualID CARD32
+#define Multibuffer CARD32
+
+typedef struct xMbufBufferInfo {
+       CARD32  visualID B32;           /* associated visual */
+       CARD16  maxBuffers B16;         /* maximum supported buffers */
+       CARD8   depth;                  /* depth of visual (redundant) */
+       CARD8   unused;
+} xMbufBufferInfo;
+#define sz_xMbufBufferInfo 8
+
+typedef struct {
+    BYTE    type;
+    BYTE    unused;
+    CARD16  sequenceNumber B16;
+    CARD32  buffer B32;                        /* affected buffer */
+    BYTE    state;                     /* current status */
+    CARD8   unused1;
+    CARD16  unused2 B16;
+    CARD32  unused3 B32;
+    CARD32  unused4 B32;
+    CARD32  unused5 B32;
+    CARD32  unused6 B32;
+    CARD32  unused7 B32;
+} xMbufClobberNotifyEvent;
+
+typedef struct {
+    BYTE    type;
+    BYTE    unused;
+    CARD16  sequenceNumber B16;
+    CARD32  buffer B32;                        /* affected buffer */
+    CARD32  timeStamp B32;             /* update time */
+    CARD32  unused1 B32;
+    CARD32  unused2 B32;
+    CARD32  unused3 B32;
+    CARD32  unused4 B32;
+    CARD32  unused5 B32;
+    CARD32  unused6 B32;
+} xMbufUpdateNotifyEvent;
+
+typedef struct {
+    CARD8      reqType;                /* always codes->major_opcode */
+    CARD8      mbufReqType;            /* always X_MbufGetBufferVersion */
+    CARD16     length B16;
+} xMbufGetBufferVersionReq;
+#define sz_xMbufGetBufferVersionReq    4
+
+typedef struct {
+    BYTE       type;                   /* X_Reply */
+    CARD8      unused;                 /* not used */
+    CARD16     sequenceNumber B16;
+    CARD32     length B32;
+    CARD8      majorVersion;   /* major version of Multi-Buffering protocol */
+    CARD8      minorVersion;   /* minor version of Multi-Buffering protocol */
+    CARD16     pad1 B16;
+    CARD32     pad2 B32;
+    CARD32     pad3 B32;
+    CARD32     pad4 B32;
+    CARD32     pad5 B32;
+    CARD32     pad6 B32;
+} xMbufGetBufferVersionReply;
+#define sz_xMbufGetBufferVersionReply  32
+
+typedef struct {
+    CARD8      reqType;        /* always codes->major_opcode */
+    CARD8      mbufReqType;    /* always X_MbufCreateImageBuffers */
+    CARD16     length B16;
+    CARD32     window B32;     /* associated window */
+    CARD8      updateAction;   /* action at update */
+    CARD8      updateHint;     /* hint as to frequency of updates */
+    CARD16     unused;
+} xMbufCreateImageBuffersReq;  /* followed by buffer ids */
+#define sz_xMbufCreateImageBuffersReq  12
+
+typedef struct {
+    BYTE       type;                   /* X_Reply */
+    CARD8      unused;                 /* not used */
+    CARD16     sequenceNumber B16;
+    CARD32     length B32;
+    CARD16     numberBuffer B16;       /* number successfully allocated */
+    CARD16     unused1 B16;
+    CARD32     unused2 B32;
+    CARD32     unused3 B32;
+    CARD32     unused4 B32;
+    CARD32     unused5 B32;
+    CARD32     unused6 B32;
+} xMbufCreateImageBuffersReply;
+#define sz_xMbufCreateImageBuffersReply 32
+
+typedef struct {
+    CARD8      reqType;        /* always codes->major_opcode */
+    CARD8      mbufReqType;    /* always X_MbufDestroyImageBuffers */
+    CARD16     length B16;
+    CARD32     window B32;     /* associated window */
+} xMbufDestroyImageBuffersReq;
+#define sz_xMbufDestroyImageBuffersReq 8
+
+typedef struct {
+    CARD8      reqType;        /* always codes->major_opcode */
+    CARD8      mbufReqType;    /* always X_MbufDisplayImageBuffers */
+    CARD16     length B16;
+    CARD16     minDelay B16;   /* minimum time between last update and now */
+    CARD16     maxDelay B16;   /* maximum time between last update and now */
+} xMbufDisplayImageBuffersReq; /* followed by list of buffers */
+#define sz_xMbufDisplayImageBuffersReq 8
+
+typedef struct {
+    CARD8      reqType;        /* always codes->major_opcode */
+    CARD8      mbufReqType;    /* always X_MbufSetMBufferAttributes */
+    CARD16     length B16;
+    CARD32     window B32;     /* associated window */
+    CARD32     valueMask B32;  /* modified entries */
+} xMbufSetMBufferAttributesReq;        /* followed by values */
+#define sz_xMbufSetMBufferAttributesReq 12
+
+typedef struct {
+    CARD8      reqType;        /* always codes->major_opcode */
+    CARD8      mbufReqType;    /* always X_MbufGetMBufferAttributes */
+    CARD16     length B16;
+    CARD32     window B32;     /* associated window */
+} xMbufGetMBufferAttributesReq;
+#define sz_xMbufGetMBufferAttributesReq 8
+
+typedef struct {
+    BYTE       type;                   /* X_Reply */
+    CARD8      unused;                 /* not used */
+    CARD16     sequenceNumber B16;
+    CARD32     length B32;
+    CARD16     displayedBuffer B16;    /* currently visible buffer */
+    CARD8      updateAction;
+    CARD8      updateHint;
+    CARD8      windowMode;
+    CARD8      unused0;
+    CARD16     unused1 B16;
+    CARD32     unused2 B32;
+    CARD32     unused3 B32;
+    CARD32     unused4 B32;
+    CARD32     unused5 B32;
+} xMbufGetMBufferAttributesReply;
+#define sz_xMbufGetMBufferAttributesReply 32
+
+typedef struct {
+    CARD8      reqType;        /* always codes->major_opcode */
+    CARD8      mbufReqType;    /* always X_MbufSetBufferAttributes */
+    CARD16     length B16;
+    CARD32     buffer B32;
+    CARD32     valueMask B32;
+} xMbufSetBufferAttributesReq; /* followed by values */
+#define sz_xMbufSetBufferAttributesReq 12
+
+typedef struct {
+    CARD8      reqType;        /* always codes->major_opcode */
+    CARD8      mbufReqType;    /* always X_MbufGetBufferAttributes */
+    CARD16     length B16;
+    CARD32     buffer B32;
+} xMbufGetBufferAttributesReq;
+#define sz_xMbufGetBufferAttributesReq 8
+
+typedef struct {
+    BYTE       type;                   /* X_Reply */
+    CARD8      unused;                 /* not used */
+    CARD16     sequenceNumber B16;
+    CARD32     length B32;
+    CARD32     window B32;
+    CARD32     eventMask B32;
+    CARD16     bufferIndex B16;
+    CARD8      side;
+    CARD8      unused0;
+    CARD32     unused1 B32;
+    CARD32     unused2 B32;
+    CARD32     unused3 B32;
+} xMbufGetBufferAttributesReply;
+#define sz_xMbufGetBufferAttributesReply 32
+
+typedef struct {
+    CARD8      reqType;        /* always codes->major_opcode */
+    CARD8      mbufReqType;    /* always X_MbufGetBufferInfo */
+    CARD16     length B16;
+    Drawable   drawable B32;
+} xMbufGetBufferInfoReq;
+#define sz_xMbufGetBufferInfoReq 8
+
+typedef struct {
+    BYTE       type;                   /* X_Reply */
+    CARD8      unused;                 /* not used */
+    CARD16     sequenceNumber B16;
+    CARD32     length B32;
+    CARD16     normalInfo B16;
+    CARD16     stereoInfo B16;
+    CARD32     unused1 B32;
+    CARD32     unused2 B32;
+    CARD32     unused3 B32;
+    CARD32     unused4 B32;
+    CARD32     unused5 B32;
+} xMbufGetBufferInfoReply;                     /* followed by buffer infos */
+#define sz_xMbufGetBufferInfoReply 32
+
+
+typedef struct {
+    CARD8      reqType;        /* always codes->major_opcode */
+    CARD8      mbufReqType;    /* always X_MbufCreateStereoWindow */
+    CARD16     length B16;
+    CARD8      unused0;
+    CARD8      unused1;
+    CARD8      unused2;
+    CARD8      depth;
+    Window     wid B32;
+    Window     parent B32;
+    Multibuffer        left B32;       /* associated buffers */
+    Multibuffer        right B32;
+    INT16      x B16;
+    INT16      y B16;
+    CARD16     width B16;
+    CARD16     height B16;
+    CARD16     borderWidth B16;  
+    CARD16     class B16;
+    VisualID   visual B32;
+    CARD32     mask B32;
+} xMbufCreateStereoWindowReq;          /* followed by value list */
+#define sz_xMbufCreateStereoWindowReq 44
+
+typedef struct {
+    CARD8     reqType;        /* always codes->major_opcode */
+    CARD8     mbufReqType;    /* always X_MbufClearImageBufferArea */
+    CARD16    length B16;
+    Multibuffer       buffer B32;
+    INT16     x B16;
+    INT16     y B16;
+    CARD16    width B16;
+    CARD16    height B16;
+    CARD8     unused0;
+    CARD8     unused1;
+    CARD8     unused2;
+    BOOL      exposures;
+} xMbufClearImageBufferAreaReq;
+#define sz_xMbufClearImageBufferAreaReq 20
+
+#undef Window
+#undef Drawable
+#undef VisualID
+#undef Multibuffer
+
+
+#ifdef _MULTIBUF_SERVER_
+/* Macros for wrapping and unwrapping functions */
+
+#define SWAP_FUNC_VECTOR(pSTRUCT1,pSTRUCT2,DATA_TYPE,FUNC_NAME)                \
+{                                                                      \
+    DATA_TYPE (* tmpFn)();                                             \
+                                                                       \
+    tmpFn = pSTRUCT1->FUNC_NAME;                                       \
+    pSTRUCT1->FUNC_NAME = pSTRUCT2->FUNC_NAME;                         \
+    pSTRUCT2->FUNC_NAME = tmpFn;                                       \
+}
+
+#if (defined(__STDC__) && !defined(UNIXCPP)) || defined(ANSICPP)
+#define WRAP_SCREEN_FUNC(pSCREEN,pPRIV,FUNC_NAME, PRIV_FUNC_NAME)      \
+{                                                                      \
+    if ((pPRIV->funcsWrapped & FUNC_NAME##Mask) == 0)                  \
+    {                                                                  \
+       pPRIV->FUNC_NAME   = pSCREEN->FUNC_NAME;                        \
+       pSCREEN->FUNC_NAME = PRIV_FUNC_NAME;                            \
+       pPRIV->funcsWrapped |= FUNC_NAME##Mask;                         \
+    }                                                                  \
+}
+
+#define UNWRAP_SCREEN_FUNC(pSCREEN,pPRIV,DATA_TYPE,FUNC_NAME)          \
+{                                                                      \
+    SWAP_FUNC_VECTOR(pSCREEN,pPRIV,DATA_TYPE,FUNC_NAME);               \
+    pPRIV->funcsWrapped &= ~(FUNC_NAME##Mask);                         \
+}
+
+#define REWRAP_SCREEN_FUNC(pSCREEN,pPRIV,DATA_TYPE,FUNC_NAME)          \
+{                                                                      \
+    if (MB_SCREEN_PRIV(pSCREEN)->mbufWindowCount)                      \
+    {                                                                  \
+       SWAP_FUNC_VECTOR(pSCREEN,pPRIV,DATA_TYPE,FUNC_NAME);            \
+       pPRIV->funcsWrapped |= FUNC_NAME##Mask;                         \
+    }                                                                  \
+}
+#else
+#define WRAP_SCREEN_FUNC(pSCREEN,pPRIV,FUNC_NAME, PRIV_FUNC_NAME)      \
+{                                                                      \
+    if ((pPRIV->funcsWrapped & FUNC_NAME/**/Mask) == 0)                        \
+    {                                                                  \
+       pPRIV->FUNC_NAME   = pSCREEN->FUNC_NAME;                        \
+       pSCREEN->FUNC_NAME = PRIV_FUNC_NAME;                            \
+       pPRIV->funcsWrapped |= FUNC_NAME/**/Mask;                       \
+    }                                                                  \
+}
+
+#define UNWRAP_SCREEN_FUNC(pSCREEN,pPRIV,DATA_TYPE,FUNC_NAME)          \
+{                                                                      \
+    SWAP_FUNC_VECTOR(pSCREEN,pPRIV,DATA_TYPE,FUNC_NAME);               \
+    pPRIV->funcsWrapped &= ~(FUNC_NAME/**/Mask);                       \
+}
+
+#define REWRAP_SCREEN_FUNC(pSCREEN,pPRIV,DATA_TYPE,FUNC_NAME)          \
+{                                                                      \
+    if (MB_SCREEN_PRIV(pSCREEN)->mbufWindowCount)                      \
+    {                                                                  \
+       SWAP_FUNC_VECTOR(pSCREEN,pPRIV,DATA_TYPE,FUNC_NAME);            \
+       pPRIV->funcsWrapped |= FUNC_NAME/**/Mask;                       \
+    }                                                                  \
+}
+#endif
+
+/* The _Multibuffer and _Multibuffers structures below refer to each other,
+ * so we need this forward declaration
+ */
+typedef struct _Multibuffers   *MultibuffersPtr;
+
+/*
+ * per-Multibuffer data
+ */
+typedef struct _Multibuffer {
+    MultibuffersPtr pMultibuffers;  /* associated window data */
+    Mask           eventMask;      /* MultibufferClobberNotifyMask|ExposureMask|MultibufferUpdateNotifyMask */
+    Mask           otherEventMask; /* mask of all other clients event masks */
+    OtherClients    *otherClients;  /* other clients that want events */
+    int                    number;         /* index of this buffer into array */
+    int                    side;           /* always Mono */
+    int                    clobber;        /* Unclobbered, PartiallyClobbered, FullClobbered */
+    PixmapPtr      pPixmap;        /* associated pixmap */
+} MultibufferRec, *MultibufferPtr;
+
+/*
+ * per-window data
+ */
+
+typedef struct _Multibuffers {
+    WindowPtr  pWindow;                /* associated window */
+    int                numMultibuffer;         /* count of buffers */
+    int                refcnt;                 /* ref count for delete */
+    int                displayedMultibuffer;   /* currently active buffer */
+    int                updateAction;           /* Undefined, Background, Untouched, Copied */
+    int                updateHint;             /* Frequent, Intermittent, Static */
+    int                windowMode;             /* always Mono */
+
+    TimeStamp  lastUpdate;             /* time of last update */
+
+    unsigned short     width, height;  /* last known window size */
+    short              x, y;           /* for static gravity */
+
+    MultibufferPtr     buffers;        /* array of numMultibuffer buffers */
+} MultibuffersRec;
+
+/*
+ * per-screen data
+ */
+typedef struct _MultibufferScreen {
+    PositionWindowProcPtr PositionWindow;              /* pWin, x,y */
+} MultibufferScreenRec, *MultibufferScreenPtr;
+
+/*
+ * per display-image-buffers request data.
+ */
+
+typedef struct _DisplayRequest {
+    struct _DisplayRequest     *next;
+    TimeStamp                  activateTime;
+    ClientPtr                  pClient;
+    XID                                id;
+} DisplayRequestRec, *DisplayRequestPtr;
+
+#define DestroyWindowMask              (1L<<0)
+#define PositionWindowMask             (1L<<1)
+#define PostValidateTreeMask           (1L<<2)
+#define ClipNotifyMask                 (1L<<3)
+#define WindowExposuresMask            (1L<<4)
+#define CopyWindowMask                 (1L<<5)
+#define ClearToBackgroundMask          (1L<<6)
+#define ChangeWindowAttributesMask     (1L<<7)    
+
+extern int             MultibufferScreenIndex;
+extern int             MultibufferWindowIndex;
+
+extern RESTYPE         MultibufferDrawableResType;
+
+extern void            MultibufferUpdate(      /* pMbuffer, time */
+#if NeedFunctionPrototypes
+                               MultibufferPtr /* pMultibuffer */,
+                               CARD32 /* time */
+#endif
+                               );
+extern void            MultibufferExpose(      /* pMbuffer, pRegion */
+#if NeedFunctionPrototypes
+                               MultibufferPtr /* pMultibuffer */,
+                               RegionPtr /* pRegion */
+#endif
+                               );
+extern void            MultibufferClobber(     /* pMbuffer */
+#if NeedFunctionPrototypes
+                               MultibufferPtr /* pMultibuffer */
+#endif
+                               );
+
+typedef struct _mbufWindow     *mbufWindowPtr;
+
+/*
+ * per-buffer data
+ */
+
+#define MB_DISPLAYED_BUFFER(pMBWindow) \
+    ((pMBWindow)->buffers + (pMBWindow)->displayedMultibuffer)
+typedef struct _mbufBuffer {
+    mbufWindowPtr   pMBWindow;     /* associated window data */
+    Mask           eventMask;      /* client event mask */
+    Mask           otherEventMask; /* union of other clients' event masks */
+    OtherClientsPtr otherClients;   /* other clients that want events */
+    int                    number;         /* index of this buffer into array */
+    int                    side;           /* stero side: always Mono */
+    int                    clobber;        /* clober state */
+    DrawablePtr            pDrawable;      /* associated drawable */
+} mbufBufferRec, *mbufBufferPtr;
+
+
+/*
+ * per-window data
+ */
+
+#define MB_WINDOW_PRIV(pWin) \
+    ((mbufWindowPtr)((pWin)->devPrivates[MultibufferWindowIndex].ptr))
+
+typedef struct _mbufWindow {
+    WindowPtr  pWindow;                /* associated window */
+    int                numMultibuffer;         /* count of buffers */
+    mbufBufferPtr buffers;             /* array of (numMultibuffer) buffers */
+    int                displayedMultibuffer;   /* currently active buffer */
+    int                updateAction;           /* Undefined, Background,
+                                          Untouched, Copied */
+    int                updateHint;             /* Frequent, Intermittent, Static */
+    int                windowMode;             /* always Mono */
+    TimeStamp  lastUpdate;             /* time of last update */
+    short              x, y;           /* for static gravity */
+    unsigned short     width, height;  /* last known window size */
+    DevUnion           devPrivate;
+} mbufWindowRec;
+
+
+/*
+ * per-screen data
+ */
+
+#define MB_SCREEN_PRIV(pScreen) \
+    ((mbufScreenPtr)((pScreen)->devPrivates[MultibufferScreenIndex].ptr))
+
+typedef struct _mbufScreen {
+    long mbufWindowCount;              /* count of multibuffered windows */
+
+    /* Wrap pScreen->DestroyWindow */
+    DestroyWindowProcPtr DestroyWindow;
+    long funcsWrapped;                 /* flags which functions are wrapped */
+
+    /* Initialized by device-dependent section */
+    int  nInfo;                                /* number of buffer info rec's */
+    xMbufBufferInfo *pInfo;            /* buffer info (for Normal buffers) */
+
+    int  (* CreateImageBuffers)(
+#if NeedNestedPrototypes
+               WindowPtr               /* pWin */,
+               int                     /* nbuf */,
+               XID *                   /* ids */,
+               int                     /* action */,
+               int                     /* hint */
+#endif
+               );
+    void (* DestroyImageBuffers)(
+#if NeedNestedPrototypes
+               WindowPtr               /* pWin */
+#endif
+               );
+    void (* DisplayImageBuffers)(
+#if NeedNestedPrototypes
+               ScreenPtr               /* pScreen */,
+               mbufBufferPtr *         /* ppMBBuffer */,
+               mbufWindowPtr *         /* ppMBWindow */,
+               int                     /* nbuf */
+#endif
+               );
+    void (* ClearImageBufferArea)(
+#if NeedNestedPrototypes
+               mbufBufferPtr           /* pMBBuffer */,
+               short                   /* x */,
+               short                   /* y */,
+               unsigned short          /* width */,
+               unsigned short          /* height */,
+               Bool                    /* exposures */
+#endif
+               );
+    Bool (* ChangeMBufferAttributes)(  /* pMBWindow, vmask */ 
+#if NeedNestedPrototypes
+               /* FIXME */
+#endif
+               );
+    Bool (* ChangeBufferAttributes)(   /* pMBBuffer, vmask */
+#if NeedNestedPrototypes
+               /* FIXME */
+#endif
+               );
+    void (* DeleteBufferDrawable)(
+#if NeedNestedPrototypes
+               DrawablePtr             /* pDrawable */
+#endif
+               );
+    void (* WrapScreenFuncs)(
+#if NeedNestedPrototypes
+               ScreenPtr               /* pScreen */
+#endif
+               );
+    void (* ResetProc)(
+#if NeedNestedPrototypes
+               ScreenPtr               /* pScreen */
+#endif
+               );
+    DevUnion   devPrivate;
+} mbufScreenRec, *mbufScreenPtr;
+
+
+/* Privates to mbufScreenRec */
+
+#ifdef _MULTIBUF_PIXMAP_
+#define MB_SCREEN_PRIV_PIXMAP(pScreen) \
+    ((mbufPixmapPrivPtr) MB_SCREEN_PRIV((pScreen))->devPrivate.ptr)
+
+typedef struct _mbufPixmapPriv
+{
+    /* Pointers to wrapped functions */
+    PositionWindowProcPtr PositionWindow;              /* pWin, x,y */
+    long funcsWrapped;                 /* flags which functions are wrapped */
+} mbufPixmapPrivRec, *mbufPixmapPrivPtr;
+#endif /* _MULTIBUF_PIXMAP_ */
+
+
+#ifdef _MULTIBUF_BUFFER_
+
+extern int frameWindowPrivateIndex;
+
+#define MB_SCREEN_PRIV_BUFFER(pScreen) \
+    ((mbufBufferPrivPtr) MB_SCREEN_PRIV((pScreen))->devPrivate.ptr)
+
+typedef struct _mbufBufferPriv
+{
+    DevUnion   *frameBuffer;   /* Array of screen framebuffers */
+    DevUnion   selectPlane;    /* Plane(s) that select displayed buffer */
+
+    /* 
+     * Note: subtractRgn and unionRgn may overlap. subtractRgn is a union
+     * of all the old clipLists of the windows that are displaying
+     * the backbuffer. unionRgn is the union of all the new clipLists
+     * of the same windows.
+     */
+
+    RegionRec  backBuffer;     /* Area of screen displaying back buffer */
+    RegionRec   subtractRgn;   /* Regions lost to backBuffer   */
+    RegionRec   unionRgn;      /* Regions gained by backBuffer */
+    Bool       rgnChanged;     /* TRUE if "backBuffer" needs to be updated */
+
+    void (* CopyBufferBits)(); /* pMBWindow, srcBufferNum, dstBufferNum */
+    void (* DrawSelectPlane)();        /* pScreen, selectPlane, pRegion, bufferNum */
+
+    /* Pointers to wrapped functions */
+    PostValidateTreeProcPtr    PostValidateTree; /* pParent, pChild, kind */
+    ClipNotifyProcPtr          ClipNotify;       /* pWin, dx, dy */
+    WindowExposuresProcPtr     WindowExposures;  /* pWin, pRegion */
+    CopyWindowProcPtr          CopyWindow;       /* pWin, oldPt, pOldRegion */
+    ClearToBackgroundProcPtr   ClearToBackground; /* pWin, x,y,w,h, sendExpose */
+    ChangeWindowAttributesProcPtr ChangeWindowAttributes; /* pWin, vmask */
+    long funcsWrapped;                 /* flags which functions are wrapped */
+    unsigned  inClearToBackground:1;   /* used by WindowExposure */
+} mbufBufferPrivRec, *mbufBufferPrivPtr;
+#endif /* _MULTIBUF_BUFFER_ */
+
+#endif /* _MULTIBUF_SERVER_ */
+#endif /* _MULTIBUFST_H_ */
diff --git a/Xserver/include/extensions/record.h b/Xserver/include/extensions/record.h
new file mode 100644 (file)
index 0000000..05c7d6e
--- /dev/null
@@ -0,0 +1,239 @@
+/* 
+$XConsortium: record.h /main/4 1996/01/31 20:28:22 dpw $
+*/
+
+/***************************************************************************
+ * Copyright 1995 Network Computing Devices
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and
+ * its documentation for any purpose is hereby granted without fee, provided
+ * that the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the name of Network Computing Devices 
+ * not be used in advertising or publicity pertaining to distribution
+ * of the software without specific, written prior permission.
+ *
+ * NETWORK COMPUTING DEVICES DISCLAIMs ALL WARRANTIES WITH REGARD TO 
+ * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 
+ * AND FITNESS, IN NO EVENT SHALL NETWORK COMPUTING DEVICES BE LIABLE 
+ * FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN 
+ * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING 
+ * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ **************************************************************************/
+#ifndef _RECORD_H_
+#define _RECORD_H_
+
+#define XRecordBadContext       0      /* Not a valid RC */
+
+/*
+ * Constants for arguments of various requests
+ */
+#define        XRecordFromServerTime           0x01
+#define        XRecordFromClientTime           0x02
+#define        XRecordFromClientSequence       0x04
+
+#define XRecordCurrentClients          1
+#define XRecordFutureClients           2
+#define XRecordAllClients              3
+
+#define XRecordFromServer              0
+#define XRecordFromClient               1
+#define XRecordClientStarted                   2
+#define XRecordClientDied               3
+#define XRecordStartOfData             4
+#define XRecordEndOfData               5
+
+typedef unsigned long   XRecordClientSpec;
+
+#ifndef _XRECORD_SERVER_
+
+typedef unsigned long  XRecordContext;
+
+typedef struct
+{
+    unsigned char      first;
+    unsigned char      last;
+} XRecordRange8;
+
+typedef struct
+{
+    unsigned short     first;
+    unsigned short     last;
+} XRecordRange16; 
+
+typedef struct
+{
+    XRecordRange8      ext_major;
+    XRecordRange16     ext_minor; 
+} XRecordExtRange; 
+
+typedef struct
+{
+    XRecordRange8     core_requests;   /* core X requests */
+    XRecordRange8     core_replies;    /* core X replies */
+    XRecordExtRange   ext_requests;    /* extension requests */
+    XRecordExtRange   ext_replies;     /* extension replies */
+    XRecordRange8     delivered_events;        /* delivered core and ext events */
+    XRecordRange8     device_events;   /* all core and ext device events */
+    XRecordRange8     errors;          /* core X and ext errors */
+    Bool             client_started;   /* connection setup reply */
+    Bool              client_died;     /* notice of client disconnect */    
+} XRecordRange;
+
+typedef struct
+{
+    XRecordClientSpec  client;
+    unsigned long      nranges; 
+    XRecordRange       **ranges;
+} XRecordClientInfo;
+
+typedef struct
+{
+    Bool               enabled;
+    int                        datum_flags; 
+    unsigned long      nclients; 
+    XRecordClientInfo  **client_info;
+} XRecordState;
+
+typedef struct
+{
+    XID                id_base;
+    Time               server_time; 
+    unsigned long      client_seq;
+    int                        category; 
+    Bool               client_swapped;
+    unsigned char      *data;
+    unsigned long      data_len;       /* in 4-byte units */
+} XRecordInterceptData;
+
+_XFUNCPROTOBEGIN
+
+/*********************************************************
+ *
+ * Prototypes 
+ *
+ */
+
+XID XRecordIdBaseMask(
+#if NeedFunctionPrototypes
+    Display *dpy
+#endif
+);
+
+extern Status XRecordQueryVersion(
+#if NeedFunctionPrototypes
+    Display*                   /* dpy */,
+    int*                       /* cmajor_return */, 
+    int*                       /* cminor_return */  
+#endif
+);
+
+extern XRecordContext XRecordCreateContext(
+#if NeedFunctionPrototypes
+    Display*                   /* dpy */, 
+    int                                /* datum_flags */, 
+    XRecordClientSpec*         /* clients */,
+    int                                /* nclients */,     
+    XRecordRange**              /* ranges */,
+    int                                /* nranges */
+#endif
+);
+
+extern XRecordRange *XRecordAllocRange(
+#if NeedFunctionPrototypes
+    void
+#endif
+);
+
+extern Status XRecordRegisterClients(
+#if NeedFunctionPrototypes
+    Display*                   /* dpy */, 
+    XRecordContext             /* context */, 
+    int                                /* datum_flags */,
+    XRecordClientSpec*         /* clients */,
+    int                                /* nclients */, 
+    XRecordRange**             /* ranges */,  
+    int                                /* nranges */
+#endif
+);
+
+extern Status XRecordUnregisterClients(
+#if NeedFunctionPrototypes
+    Display*                   /* dpy */, 
+    XRecordContext             /* context */, 
+    XRecordClientSpec*         /* clients */,
+    int                                /* nclients */ 
+#endif
+);
+
+extern Status XRecordGetContext(
+#if NeedFunctionPrototypes
+    Display*                   /* dpy */,
+    XRecordContext             /* context */, 
+    XRecordState**             /* state_return */ 
+#endif
+);
+
+extern void XRecordFreeState(
+#if NeedFunctionPrototypes
+XRecordState*                  /* state */
+#endif
+); 
+
+typedef void (*XRecordInterceptProc) (
+#if NeedFunctionPrototypes
+    XPointer                   /* closure */, 
+    XRecordInterceptData*      /* recorded_data */
+#endif
+);
+
+extern Status XRecordEnableContext(
+#if NeedFunctionPrototypes
+    Display*                   /* dpy */,
+    XRecordContext             /* context */, 
+    XRecordInterceptProc       /* callback */,
+    XPointer                   /* closure */
+#endif
+); 
+
+extern Status XRecordEnableContextAsync(
+#if NeedFunctionPrototypes
+    Display*                   /* dpy */,
+    XRecordContext             /* context */, 
+    XRecordInterceptProc       /* callback */,
+    XPointer                   /* closure */
+#endif
+); 
+
+extern void XRecordProcessReplies(
+#if NeedFunctionPrototypes
+    Display*                   /* dpy */
+#endif
+); 
+
+extern void XRecordFreeData(
+#if NeedFunctionPrototypes
+XRecordInterceptData*  /* data */
+#endif
+); 
+
+extern Status XRecordDisableContext(
+#if NeedFunctionPrototypes
+    Display*                   /* dpy */,
+    XRecordContext             /* context */
+#endif
+); 
+
+extern Status XRecordFreeContext(
+#if NeedFunctionPrototypes
+    Display*                   /* dpy */, 
+    XRecordContext             /* context */
+#endif
+);
+
+_XFUNCPROTOEND
+
+#endif /* _XRECORD_SERVER_ */
+
+#endif /* _RECORD_H_ */
diff --git a/Xserver/include/extensions/recordstr.h b/Xserver/include/extensions/recordstr.h
new file mode 100644 (file)
index 0000000..fe1dd19
--- /dev/null
@@ -0,0 +1,318 @@
+/*
+#ifndef lint
+$XConsortium: recordstr.h /main/2 1996/01/09 18:15:19 gildea $
+static char sccsid[ ] = "@(#) recordstr.h 1.5 6/5/95 12:37:44";
+#endif
+*/
+
+/***************************************************************************
+ * Copyright 1995 Network Computing Devices
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and
+ * its documentation for any purpose is hereby granted without fee, provided
+ * that the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the name of Network Computing Devices
+ * not be used in advertising or publicity pertaining to distribution
+ * of the software without specific, written prior permission.
+ *
+ * NETWORK COMPUTING DEVICES DISCLAIMs ALL WARRANTIES WITH REGARD TO
+ * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS, IN NO EVENT SHALL NETWORK COMPUTING DEVICES BE LIABLE
+ * FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
+ * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
+ * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ **************************************************************************/
+
+#include "record.h"
+
+#define RECORD_NAME                    "RECORD"
+#define RECORD_MAJOR_VERSION           1
+#define RECORD_MINOR_VERSION           13
+#define RECORD_LOWEST_MAJOR_VERSION    1
+#define RECORD_LOWEST_MINOR_VERSION    12
+/* only difference between 1.12 and 1.13 is byte order of device events,
+   which the library doesn't deal with. */
+
+/*********************************************************
+ *
+ * Protocol request constants
+ *
+ */
+#define X_RecordQueryVersion    0     /* First request from client */
+#define X_RecordCreateContext   1     /* Create client RC */
+#define X_RecordRegisterClients 2     /* Add to client RC */
+#define X_RecordUnregisterClients 3   /* Delete from client RC */
+#define X_RecordGetContext      4     /* Query client RC */
+#define X_RecordEnableContext   5     /* Enable interception and reporting */
+#define X_RecordDisableContext  6     /* Disable interception and reporting */
+#define X_RecordFreeContext     7     /* Free client RC */
+
+#define RecordNumErrors         (XRecordBadContext + 1) 
+#define RecordNumEvents        0L
+
+#define sz_XRecordRange                32
+#define sz_XRecordClientInfo   12
+#define sz_XRecordState        16
+#define sz_XRecordDatum        32
+
+
+#define XRecordGlobaldef
+#define XRecordGlobalref extern
+
+#define RecordMaxEvent         (128L-1L)
+#define RecordMinDeviceEvent   (2L)
+#define RecordMaxDeviceEvent   (6L)
+#define RecordMaxError          (256L-1L)
+#define RecordMaxCoreRequest    (128L-1L)
+#define RecordMaxExtRequest     (256L-1L)
+#define RecordMinExtRequest     (129L-1L)
+
+#define RECORD_RC              CARD32
+#define RECORD_XIDBASE         CARD32
+#define RECORD_CLIENTSPEC      CARD32
+#define RECORD_ELEMENT_HEADER  CARD8
+
+typedef RECORD_CLIENTSPEC RecordClientSpec, *RecordClientSpecPtr;
+
+typedef struct
+{
+    CARD8      first;
+    CARD8      last;
+} RECORD_RANGE8;
+
+typedef struct
+{
+    CARD16     first B16;
+    CARD16     last B16;
+} RECORD_RANGE16;
+
+typedef struct
+{
+    RECORD_RANGE8      majorCode;
+    RECORD_RANGE16     minorCode;
+} RECORD_EXTRANGE;
+
+typedef struct
+{
+    RECORD_RANGE8      coreRequests;
+    RECORD_RANGE8      coreReplies;
+    RECORD_EXTRANGE    extRequests;
+    RECORD_EXTRANGE    extReplies;
+    RECORD_RANGE8      deliveredEvents;
+    RECORD_RANGE8      deviceEvents;
+    RECORD_RANGE8      errors;
+    BOOL               clientStarted;
+    BOOL               clientDied;
+} RECORDRANGE;
+#define sz_RECORDRANGE         24
+
+/* typedef RECORDRANGE xRecordRange, *xRecordRangePtr;
+#define sz_xRecordRange 24 */
+
+/* Cannot have structures within structures going over the wire */
+typedef struct
+{
+    CARD8              coreRequestsFirst;
+    CARD8              coreRequestsLast;
+    CARD8              coreRepliesFirst;
+    CARD8              coreRepliesLast;
+    CARD8              extRequestsMajorFirst;
+    CARD8              extRequestsMajorLast;
+    CARD16             extRequestsMinorFirst B16;
+    CARD16             extRequestsMinorLast B16;
+    CARD8              extRepliesMajorFirst;
+    CARD8              extRepliesMajorLast;
+    CARD16             extRepliesMinorFirst B16;
+    CARD16             extRepliesMinorLast B16;
+    CARD8              deliveredEventsFirst;
+    CARD8              deliveredEventsLast;
+    CARD8              deviceEventsFirst;
+    CARD8              deviceEventsLast;
+    CARD8              errorsFirst;
+    CARD8              errorsLast;
+    BOOL                clientStarted;
+    BOOL               clientDied;
+} xRecordRange;
+#define sz_xRecordRange 24
+
+typedef struct
+{
+    RECORD_CLIENTSPEC  clientResource B32;
+    CARD32             nRanges B32;
+/* LISTofRECORDRANGE */
+} RECORD_CLIENT_INFO;
+
+typedef RECORD_CLIENT_INFO xRecordClientInfo;
+
+/*
+ * Initialize
+ */
+typedef struct {
+    CARD8       reqType;
+    CARD8       recordReqType;
+    CARD16      length B16;
+    CARD16      majorVersion B16;
+    CARD16      minorVersion B16;
+} xRecordQueryVersionReq;
+#define sz_xRecordQueryVersionReq      8
+
+typedef struct
+{
+    CARD8   type;
+    CARD8   pad0;
+    CARD16  sequenceNumber B16;
+    CARD32  length      B32;
+    CARD16  majorVersion B16;
+    CARD16  minorVersion B16;
+    CARD32  pad1        B32;
+    CARD32  pad2        B32;
+    CARD32  pad3        B32;
+    CARD32  pad4        B32;
+    CARD32  pad5        B32;
+ } xRecordQueryVersionReply;
+#define sz_xRecordQueryVersionReply    32
+
+/*
+ * Create RC
+ */
+typedef struct
+{
+    CARD8              reqType;
+    CARD8              recordReqType;
+    CARD16             length B16;
+    RECORD_RC          context B32;
+    RECORD_ELEMENT_HEADER elementHeader;
+    CARD8              pad;
+    CARD16             pad0 B16;
+    CARD32             nClients B32;
+    CARD32              nRanges B32;
+/* LISTofRECORD_CLIENTSPEC */
+/* LISTofRECORDRANGE */
+} xRecordCreateContextReq;
+#define sz_xRecordCreateContextReq     20
+
+/*
+ * Add to  RC
+ */
+typedef struct
+{
+    CARD8              reqType;
+    CARD8              recordReqType;
+    CARD16             length B16;
+    RECORD_RC          context B32;
+    RECORD_ELEMENT_HEADER elementHeader;
+    CARD8              pad;
+    CARD16             pad0 B16;
+    CARD32             nClients B32;
+    CARD32              nRanges B32;
+/* LISTofRECORD_CLIENTSPEC */
+/* LISTofRECORDRANGE */
+} xRecordRegisterClientsReq;
+#define sz_xRecordRegisterClientsReq   20
+
+/*
+ * Delete from RC
+ */
+typedef struct
+{
+    CARD8              reqType;
+    CARD8              recordReqType;
+    CARD16             length B16;
+    RECORD_RC          context B32;
+    CARD32             nClients B32;
+/* LISTofRECORD_CLIENTSPEC */
+} xRecordUnregisterClientsReq;
+#define sz_xRecordUnregisterClientsReq         12
+
+/*
+ * Query RC
+ */
+typedef struct
+{
+    CARD8      reqType;
+    CARD8      recordReqType;
+    CARD16     length B16;
+    RECORD_RC  context B32;
+} xRecordGetContextReq;
+#define sz_xRecordGetContextReq                8
+
+typedef struct
+{
+    CARD8      type;
+    BOOL       enabled;
+    CARD16     sequenceNumber B16;
+    CARD32     length   B32;
+    RECORD_ELEMENT_HEADER  elementHeader;
+    CARD8      pad;
+    CARD16     pad0 B16;
+    CARD32     nClients B32;
+    CARD32     pad1 B32;
+    CARD32     pad2 B32;
+    CARD32     pad3 B32;
+    CARD32     pad4 B32;
+/* LISTofCLIENT_INFO */                /* intercepted-clients */
+} xRecordGetContextReply;
+#define sz_xRecordGetContextReply      32
+
+/*
+ * Enable data interception
+ */
+typedef struct
+{
+    CARD8      reqType;
+    CARD8      recordReqType;
+    CARD16     length B16;
+    RECORD_RC  context B32;
+} xRecordEnableContextReq;
+#define sz_xRecordEnableContextReq     8
+
+typedef struct
+{
+    CARD8              type;
+    CARD8              category;
+    CARD16             sequenceNumber B16;
+    CARD32             length B32;
+    RECORD_ELEMENT_HEADER  elementHeader;
+    BOOL               clientSwapped;
+    CARD16             pad1 B16;
+    RECORD_XIDBASE     idBase B32;
+    CARD32             serverTime B32;
+    CARD32             recordedSequenceNumber B32;
+    CARD32             pad3 B32;
+    CARD32             pad4 B32;
+    /* BYTE            data; */
+} xRecordEnableContextReply;
+#define sz_xRecordEnableContextReply   32
+
+/*
+ * Disable data interception
+ */
+typedef struct
+{
+    CARD8      reqType;
+    CARD8      recordReqType;
+    CARD16     length B16;
+    RECORD_RC  context B32;
+} xRecordDisableContextReq;
+#define sz_xRecordDisableContextReq    8
+
+/*
+ * Free RC
+ */
+typedef struct
+{
+    CARD8      reqType;
+    CARD8      recordReqType;
+    CARD16     length B16;
+    RECORD_RC  context B32;
+} xRecordFreeContextReq;
+#define sz_xRecordFreeContextReq       8
+
+#undef RECORD_RC
+#undef RECORD_XIDBASE
+#undef RECORD_ELEMENT_HEADER
+#undef RECORD_CLIENTSPEC
+
+
diff --git a/Xserver/include/extensions/saver.h b/Xserver/include/extensions/saver.h
new file mode 100644 (file)
index 0000000..ea35454
--- /dev/null
@@ -0,0 +1,54 @@
+/*
+ * $XConsortium: saver.h,v 1.5 94/04/17 20:59:33 rws Exp $
+ *
+Copyright (c) 1992  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+ *
+ * Author:  Keith Packard, MIT X Consortium
+ */
+
+#ifndef _SAVER_H_
+#define _SAVER_H_
+
+#define ScreenSaverName        "MIT-SCREEN-SAVER"
+#define ScreenSaverPropertyName "_MIT_SCREEN_SAVER_ID"
+
+#define ScreenSaverNotifyMask  0x00000001
+#define ScreenSaverCycleMask   0x00000002
+
+#define ScreenSaverMajorVersion        1
+#define ScreenSaverMinorVersion        0
+
+#define ScreenSaverOff         0
+#define ScreenSaverOn          1
+#define ScreenSaverCycle       2
+#define ScreenSaverDisabled    3
+
+#define ScreenSaverBlanked     0
+#define ScreenSaverInternal    1
+#define ScreenSaverExternal    2
+
+#define ScreenSaverNotify      0
+#define ScreenSaverNumberEvents        1
+
+#endif /* _SAVER_H_ */
diff --git a/Xserver/include/extensions/saverproto.h b/Xserver/include/extensions/saverproto.h
new file mode 100644 (file)
index 0000000..3760de3
--- /dev/null
@@ -0,0 +1,140 @@
+/*
+ * $XConsortium: saverproto.h,v 1.5 94/04/17 20:59:33 keith Exp $
+ *
+Copyright (c) 1992  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+ *
+ * Author:  Keith Packard, MIT X Consortium
+ */
+
+#ifndef _SAVERPROTO_H_
+#define _SAVERPROTO_H_
+#include "saver.h"
+
+#define X_ScreenSaverQueryVersion   0
+
+typedef struct _ScreenSaverQueryVersion {
+    CARD8 reqType;             /* always ScreenSaverReqCode */
+    CARD8 saverReqType;                /* always X_ScreenSaverQueryVersion */
+    CARD16 length B16;
+    CARD8 clientMajor;
+    CARD8 clientMinor;
+    CARD16 unused B16; 
+} xScreenSaverQueryVersionReq;
+#define sz_xScreenSaverQueryVersionReq 8
+
+typedef struct {
+    CARD8 type;                        /* X_Reply */
+    CARD8 unused;                      /* not used */
+    CARD16 sequenceNumber B16;
+    CARD32 length B32;
+    CARD16 majorVersion B16;   /* major version of protocol */
+    CARD16 minorVersion B16;   /* minor version of protocol */
+    CARD32 pad0 B32;
+    CARD32 pad1 B32;
+    CARD32 pad2 B32;
+    CARD32 pad3 B32;
+    CARD32 pad4 B32;
+} xScreenSaverQueryVersionReply;
+#define sz_xScreenSaverQueryVersionReply       32
+
+#define X_ScreenSaverQueryInfo   1
+
+typedef struct _ScreenSaverQueryInfo {
+    CARD8 reqType;             /* always ScreenSaverReqCode */
+    CARD8 saverReqType;                /* always X_ScreenSaverQueryInfo */
+    CARD16 length B16;
+    Drawable drawable B32;
+} xScreenSaverQueryInfoReq;
+#define sz_xScreenSaverQueryInfoReq    8
+
+typedef struct {
+    CARD8 type;                        /* X_Reply */
+    BYTE state;                        /* Off, On */
+    CARD16 sequenceNumber B16;
+    CARD32 length B32;
+    Window window B32;
+    CARD32 tilOrSince B32;
+    CARD32 idle B32;
+    CARD32 eventMask B32;
+    BYTE kind;                 /* Blanked, Internal, External */
+    CARD8 pad0;
+    CARD16 pad1 B16;
+    CARD32 pad2 B32;
+} xScreenSaverQueryInfoReply;
+#define sz_xScreenSaverQueryInfoReply  32
+
+#define X_ScreenSaverSelectInput   2
+
+typedef struct _ScreenSaverSelectInput {
+    CARD8 reqType;             /* always ScreenSaverReqCode */
+    CARD8 saverReqType;                /* always X_ScreenSaverSelectInput */
+    CARD16 length B16;
+    Drawable drawable B32;
+    CARD32 eventMask B32;
+} xScreenSaverSelectInputReq;
+#define sz_xScreenSaverSelectInputReq  12
+
+#define X_ScreenSaverSetAttributes   3
+
+typedef struct _ScreenSaverSetAttributes {
+    CARD8 reqType;             /* always ScreenSaverReqCode */
+    CARD8 saverReqType;                /* always X_ScreenSaverSetAttributes */
+    CARD16 length B16;
+    Drawable drawable B32;
+    INT16 x B16, y B16;
+    CARD16 width B16, height B16, borderWidth B16;
+    BYTE c_class;
+    CARD8 depth;
+    VisualID visualID B32;
+    CARD32 mask B32;
+} xScreenSaverSetAttributesReq;
+#define sz_xScreenSaverSetAttributesReq        28
+
+#define X_ScreenSaverUnsetAttributes   4
+
+typedef struct _ScreenSaverUnsetAttributes {
+    CARD8 reqType;             /* always ScreenSaverReqCode */
+    CARD8 saverReqType;                /* always X_ScreenSaverUnsetAttributes */
+    CARD16 length B16;
+    Drawable drawable B32;
+} xScreenSaverUnsetAttributesReq;
+#define sz_xScreenSaverUnsetAttributesReq      8
+
+typedef struct _ScreenSaverNotify {
+    CARD8 type;                        /* always eventBase + ScreenSaverNotify */
+    BYTE state;                        /* off, on, cycle */
+    CARD16 sequenceNumber B16;
+    Time timestamp B32;
+    Window root B32;
+    Window window B32;         /* screen saver window */
+    BYTE kind;                 /* blanked, internal, external */
+    BYTE forced;
+    CARD16 pad0 B16;
+    CARD32 pad1 B32;
+    CARD32 pad2 B32;
+    CARD32 pad3 B32;
+} xScreenSaverNotifyEvent;
+#define sz_xScreenSaverNotifyEvent     32
+
+#endif /* _SAVERPROTO_H_ */
diff --git a/Xserver/include/extensions/scrnsaver.h b/Xserver/include/extensions/scrnsaver.h
new file mode 100644 (file)
index 0000000..b20a648
--- /dev/null
@@ -0,0 +1,149 @@
+/*
+ * $XConsortium: scrnsaver.h,v 1.6 94/04/17 20:59:34 keith Exp $
+ *
+Copyright (c) 1992  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+ *
+ * Author:  Keith Packard, MIT X Consortium
+ */
+
+#ifndef _SCRNSAVER_H_
+#define _SCRNSAVER_H_
+
+#include <X11/Xfuncproto.h>
+#include <X11/extensions/saver.h>
+
+typedef struct {
+    int        type;               /* of event */
+    unsigned long serial;   /* # of last request processed by server */
+    Bool send_event;       /* true if this came frome a SendEvent request */
+    Display *display;      /* Display the event was read from */
+    Window window;         /* screen saver window */
+    Window root;           /* root window of event screen */
+    int state;             /* ScreenSaverOff, ScreenSaverOn, ScreenSaverCycle*/
+    int kind;              /* ScreenSaverBlanked, ...Internal, ...External */
+    Bool forced;           /* extents of new region */
+    Time time;             /* event timestamp */
+} XScreenSaverNotifyEvent;
+
+typedef struct {
+    Window  window;        /* screen saver window - may not exist */
+    int            state;          /* ScreenSaverOff, ScreenSaverOn, ScreenSaverDisabled*/
+    int            kind;           /* ScreenSaverBlanked, ...Internal, ...External */
+    unsigned long    til_or_since;   /* time til or since screen saver */
+    unsigned long    idle;         /* total time since last user input */
+    unsigned long   eventMask; /* currently selected events for this client */
+} XScreenSaverInfo;
+
+_XFUNCPROTOBEGIN
+
+extern Bool XScreenSaverQueryExtension (
+#if NeedFunctionPrototypes
+    Display*   /* display */,
+    int*       /* event_base */,
+    int*       /* error_base */
+#endif
+);
+
+extern Status XScreenSaverQueryVersion (
+#if NeedFunctionPrototypes
+    Display*   /* display */,
+    int*       /* major_version */,
+    int*       /* minor_version */
+#endif
+);
+
+extern XScreenSaverInfo *XScreenSaverAllocInfo (
+#if NeedFunctionPrototypes
+    void
+#endif
+);
+
+extern Status XScreenSaverQueryInfo (
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    Drawable           /* drawable */,
+    XScreenSaverInfo*  /* info */
+#endif
+);
+
+extern void XScreenSaverSelectInput (
+#if NeedFunctionPrototypes
+    Display*   /* display */,
+    Drawable   /* drawable */,
+    unsigned long   /* eventMask */
+#endif
+);
+
+extern void XScreenSaverSetAttributes (
+#if NeedFunctionPrototypes
+    Display*               /* display */,
+    Drawable               /* drawable */,
+    int                            /* x */,
+    int                            /* y */,
+    unsigned int           /* width */,
+    unsigned int           /* height */,
+    unsigned int           /* border_width */,
+    int                            /* depth */,
+    unsigned int           /* class */,
+    Visual *               /* visual */,
+    unsigned long          /* valuemask */,
+    XSetWindowAttributes *  /* attributes */
+#endif
+);
+
+extern void XScreenSaverUnsetAttributes (
+#if NeedFunctionPrototypes
+    Display*   /* display */,
+    Drawable   /* drawable */
+#endif
+);
+
+extern Status XScreenSaverRegister (
+#if NeedFunctionPrototypes
+    Display*   /* display */,
+    int                /* screen */,
+    XID                /* xid */,
+    Atom       /* type */
+#endif
+);
+
+extern Status XScreenSaverUnregister (
+#if NeedFunctionPrototypes
+    Display*   /* display */,
+    int                /* screen */
+#endif
+);
+
+extern Status XScreenSaverGetRegistered (
+#if NeedFunctionPrototypes
+    Display*   /* display */,
+    int                /* screen */,
+    XID*       /* xid */,
+    Atom*      /* type */
+#endif
+);
+
+_XFUNCPROTOEND
+
+#endif /* _SCRNSAVER_H_ */
diff --git a/Xserver/include/extensions/security.h b/Xserver/include/extensions/security.h
new file mode 100644 (file)
index 0000000..92af519
--- /dev/null
@@ -0,0 +1,188 @@
+/* $XConsortium: security.h /main/6 1996/11/12 12:17:11 swick $ */
+/*
+Copyright (c) 1996  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be included
+in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR
+OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall
+not be used in advertising or otherwise to promote the sale, use or
+other dealings in this Software without prior written authorization
+from the X Consortium.
+*/
+
+#ifndef _SECURITY_H
+#define _SECURITY_H
+
+#define _XAUTH_STRUCT_ONLY
+#include <X11/Xauth.h>
+
+/* constants that server, library, and application all need */
+
+#define XSecurityNumberEvents          1
+#define XSecurityNumberErrors          2
+#define XSecurityBadAuthorization      0
+#define XSecurityBadAuthorizationProtocol 1
+
+/* trust levels */
+#define XSecurityClientTrusted         0
+#define XSecurityClientUntrusted       1
+
+/* authorization attribute masks */
+#define XSecurityTimeout               (1<<0)
+#define XSecurityTrustLevel            (1<<1)
+#define XSecurityGroup                 (1<<2)
+#define XSecurityEventMask             (1<<3)
+#define XSecurityAllAuthorizationAttributes \
+ (XSecurityTimeout | XSecurityTrustLevel | XSecurityGroup | XSecurityEventMask)
+
+/* event masks */
+#define XSecurityAuthorizationRevokedMask (1<<0)
+#define XSecurityAllEventMasks XSecurityAuthorizationRevokedMask
+
+/* event offsets */
+#define XSecurityAuthorizationRevoked 0
+    
+#define XSecurityAuthorizationName     "XC-QUERY-SECURITY-1"
+#define XSecurityAuthorizationNameLen  19
+
+
+#ifndef _SECURITY_SERVER
+
+_XFUNCPROTOBEGIN
+
+Status XSecurityQueryExtension (
+    Display *dpy,
+    int *major_version_return,
+    int *minor_version_return);
+
+Xauth *XSecurityAllocXauth(void);
+
+void XSecurityFreeXauth(Xauth *auth);
+
+/* type for returned auth ids */
+typedef unsigned long XSecurityAuthorization;
+
+typedef struct {
+    unsigned int timeout;
+    unsigned int trust_level;
+    XID          group;
+    long        event_mask;
+} XSecurityAuthorizationAttributes;
+
+Xauth *XSecurityGenerateAuthorization(
+    Display *dpy,
+    Xauth *auth_in,
+    unsigned long valuemask,
+    XSecurityAuthorizationAttributes *attributes,
+    XSecurityAuthorization *auth_id_return);
+
+Status XSecurityRevokeAuthorization(
+    Display *dpy,
+    XSecurityAuthorization auth_id);
+
+_XFUNCPROTOEND
+
+typedef struct {
+    int type;                /* event base + XSecurityAuthorizationRevoked */
+    unsigned long serial;     /* # of last request processed by server */
+    Bool send_event;         /* true if this came from a SendEvent request */
+    Display *display;        /* Display the event was read from */
+    XSecurityAuthorization auth_id; /* revoked authorization id */
+} XSecurityAuthorizationRevokedEvent;
+
+#else /* _SECURITY_SERVER */
+
+#include "input.h"    /* for DeviceIntPtr */
+#include "property.h" /* for PropertyPtr */
+
+/* resource type to pass in LookupIDByType for authorizations */
+extern RESTYPE SecurityAuthorizationResType;
+
+/* this is what we store for an authorization */
+typedef struct {
+    XID id;                    /* resource ID */
+    CARD32 timeout;    /* how long to live in seconds after refcnt == 0 */
+    unsigned int trustLevel;   /* trusted/untrusted */
+    XID group;                 /* see embedding extension */
+    unsigned int refcnt;       /* how many clients connected with this auth */
+    unsigned int secondsRemaining; /* overflow time amount for >49 days */
+    OsTimerPtr timer;          /* timer for this auth */
+    struct _OtherClients *eventClients; /* clients wanting events */
+} SecurityAuthorizationRec, *SecurityAuthorizationPtr;
+
+/* The following callback is called when a GenerateAuthorization request
+ * is processed to sanity check the group argument.  The call data will
+ * be a pointer to a SecurityValidateGroupInfoRec (below).  
+ * Functions registered on this callback are expected to examine the
+ * group and set the valid field to TRUE if they recognize the group as a
+ * legitimate group.  If they don't recognize it, they should not change the
+ * valid field.
+ */
+extern CallbackListPtr SecurityValidateGroupCallback;
+typedef struct {
+    XID group; /* the group that was sent in GenerateAuthorization */
+    Bool valid; /* did anyone recognize it? if so, set to TRUE */
+} SecurityValidateGroupInfoRec;
+
+/* Proc vectors for untrusted clients, swapped and unswapped versions.
+ * These are the same as the normal proc vectors except that extensions
+ * that haven't declared themselves secure will have ProcBadRequest plugged
+ * in for their major opcode dispatcher.  This prevents untrusted clients
+ * from guessing extension major opcodes and using the extension even though
+ * the extension can't be listed or queried.
+ */
+extern int (*UntrustedProcVector[256])(ClientPtr client);
+extern int (*SwappedUntrustedProcVector[256])(ClientPtr client);
+
+extern Bool SecurityCheckDeviceAccess(ClientPtr client, DeviceIntPtr dev,
+                              Bool fromRequest);
+
+extern void SecurityAudit(char *format, ...);
+
+/* Give this value or higher to the -audit option to get security messages */
+#define SECURITY_AUDIT_LEVEL 4
+
+extern void SecurityCensorImage(
+    ClientPtr client,
+    RegionPtr pVisibleRegion,
+    long widthBytesLine,
+    DrawablePtr pDraw,
+    int x, int y, int w, int h,
+    unsigned int format,
+    char * pBuf);
+
+#define SecurityAllowOperation  0
+#define SecurityIgnoreOperation 1
+#define SecurityErrorOperation  2
+
+char
+SecurityCheckPropertyAccess(
+    ClientPtr client,
+    WindowPtr pWin,
+    ATOM  propertyName,
+    Mask access_mode);
+
+#define SECURITY_POLICY_FILE_VERSION "version-1"
+
+char **SecurityGetSitePolicyStrings(int *n);
+
+#endif /* _SECURITY_SERVER */
+
+#endif /* _SECURITY_H */
diff --git a/Xserver/include/extensions/securstr.h b/Xserver/include/extensions/securstr.h
new file mode 100644 (file)
index 0000000..3df2d22
--- /dev/null
@@ -0,0 +1,117 @@
+/* $XConsortium: securstr.h /main/4 1996/11/12 12:17:47 swick $ */
+/*
+Copyright (c) 1996  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be included
+in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR
+OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall
+not be used in advertising or otherwise to promote the sale, use or
+other dealings in this Software without prior written authorization
+from the X Consortium.
+*/
+
+#ifndef _SECURSTR_H
+#define _SECURSTR_H
+
+#include "security.h"
+
+#define SECURITY_EXTENSION_NAME                "SECURITY"
+#define SECURITY_MAJOR_VERSION         1
+#define SECURITY_MINOR_VERSION         0
+
+#define X_SecurityQueryVersion         0
+#define X_SecurityGenerateAuthorization 1
+#define X_SecurityRevokeAuthorization   2
+
+typedef struct {
+    CARD8       reqType;
+    CARD8       securityReqType;
+    CARD16      length B16;
+    CARD16      majorVersion B16;
+    CARD16      minorVersion B16;
+} xSecurityQueryVersionReq;
+#define sz_xSecurityQueryVersionReq    8
+
+typedef struct {
+    CARD8   type;
+    CARD8   pad0;
+    CARD16  sequenceNumber B16;
+    CARD32  length      B32;
+    CARD16  majorVersion B16;
+    CARD16  minorVersion B16;
+    CARD32  pad1        B32;
+    CARD32  pad2        B32;
+    CARD32  pad3        B32;
+    CARD32  pad4        B32;
+    CARD32  pad5        B32;
+ } xSecurityQueryVersionReply;
+#define sz_xSecurityQueryVersionReply          32
+
+typedef struct {
+    CARD8       reqType;
+    CARD8       securityReqType;
+    CARD16      length B16;
+    CARD16     nbytesAuthProto B16;
+    CARD16     nbytesAuthData B16;
+    CARD32     valueMask B32; 
+    /* auth protocol name padded to 4 bytes */
+    /* auth protocol data padded to 4 bytes */
+    /* list of CARD32 values, if any */
+} xSecurityGenerateAuthorizationReq;
+#define sz_xSecurityGenerateAuthorizationReq 12
+
+typedef struct {
+    CARD8   type;
+    CARD8   pad0;
+    CARD16  sequenceNumber B16;
+    CARD32  length      B32;
+    CARD32  authId      B32;
+    CARD16  dataLength   B16;
+    CARD16  pad1        B16;
+    CARD32  pad2        B32;
+    CARD32  pad3        B32;
+    CARD32  pad4        B32;
+    CARD32  pad5        B32;
+ } xSecurityGenerateAuthorizationReply;
+#define sz_xSecurityGenerateAuthorizationReply         32
+
+typedef struct {
+    CARD8       reqType;
+    CARD8       securityReqType;
+    CARD16      length B16;
+    CARD32     authId B32;
+} xSecurityRevokeAuthorizationReq;
+#define sz_xSecurityRevokeAuthorizationReq 8
+
+typedef struct _xSecurityAuthorizationRevokedEvent {
+    BYTE       type;
+    BYTE       detail;
+    CARD16     sequenceNumber B16;
+    CARD32     authId B32;
+    CARD32     pad0     B32;
+    CARD32     pad1     B32;
+    CARD32     pad2     B32;
+    CARD32     pad3     B32;
+    CARD32     pad4     B32;
+    CARD32     pad5     B32;
+} xSecurityAuthorizationRevokedEvent;
+#define sz_xSecurityAuthorizationRevokedEvent 32
+
+#endif /* _SECURSTR_H */
diff --git a/Xserver/include/extensions/shape.h b/Xserver/include/extensions/shape.h
new file mode 100644 (file)
index 0000000..9fc1249
--- /dev/null
@@ -0,0 +1,198 @@
+/************************************************************
+
+Copyright (c) 1989  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+********************************************************/
+
+/* $XConsortium: shape.h,v 1.17 94/04/17 20:11:23 rws Exp $ */
+
+#ifndef _SHAPE_H_
+#define _SHAPE_H_
+
+#include <X11/Xfuncproto.h>
+
+#define X_ShapeQueryVersion            0
+#define X_ShapeRectangles              1
+#define X_ShapeMask                    2
+#define X_ShapeCombine                 3
+#define X_ShapeOffset                  4
+#define X_ShapeQueryExtents            5
+#define X_ShapeSelectInput             6
+#define X_ShapeInputSelected           7
+#define X_ShapeGetRectangles           8
+
+#define ShapeSet                       0
+#define ShapeUnion                     1
+#define ShapeIntersect                 2
+#define ShapeSubtract                  3
+#define ShapeInvert                    4
+
+#define ShapeBounding                  0
+#define ShapeClip                      1
+
+#define ShapeNotifyMask                        (1L << 0)
+#define ShapeNotify                    0
+
+#define ShapeNumberEvents              (ShapeNotify + 1)
+
+#ifndef _SHAPE_SERVER_
+typedef struct {
+    int        type;               /* of event */
+    unsigned long serial;   /* # of last request processed by server */
+    Bool send_event;       /* true if this came frome a SendEvent request */
+    Display *display;      /* Display the event was read from */
+    Window window;         /* window of event */
+    int kind;              /* ShapeBounding or ShapeClip */
+    int x, y;              /* extents of new region */
+    unsigned width, height;
+    Time time;             /* server timestamp when region changed */
+    Bool shaped;           /* true if the region exists */
+} XShapeEvent;
+
+_XFUNCPROTOBEGIN
+
+extern Bool XShapeQueryExtension (
+#if NeedFunctionPrototypes
+    Display*   /* display */,
+    int*       /* event_base */,
+    int*       /* error_base */
+#endif
+);
+
+extern Status XShapeQueryVersion (
+#if NeedFunctionPrototypes
+    Display*   /* display */,
+    int*       /* major_version */,
+    int*       /* minor_version */
+#endif
+);
+
+extern void XShapeCombineRegion (
+#if NeedFunctionPrototypes
+    Display*   /* display */,
+    Window     /* dest */,
+    int                /* dest_kind */,
+    int                /* x_off */,
+    int                /* y_off */,
+    Region     /* region */,
+    int                /* op */
+#endif
+);
+
+extern void XShapeCombineRectangles (
+#if NeedFunctionPrototypes
+    Display*   /* display */,
+    Window     /* dest */,
+    int                /* dest_kind */,
+    int                /* x_off */,
+    int                /* y_off */,
+    XRectangle*        /* rectangles */,
+    int                /* n_rects */,
+    int                /* op */,
+    int                /* ordering */
+#endif
+);
+
+extern void XShapeCombineMask (
+#if NeedFunctionPrototypes
+    Display*   /* display */,
+    Window     /* dest */,
+    int                /* dest_kind */,
+    int                /* x_off */,
+    int                /* y_off */,
+    Pixmap     /* src */,
+    int                /* op */
+#endif
+);
+
+extern void XShapeCombineShape (
+#if NeedFunctionPrototypes
+    Display*   /* display */,
+    Window     /* dest */,
+    int                /* dest_kind */,
+    int                /* x_off */,
+    int                /* y_off */,
+    Window     /* src */,
+    int                /* src_kind */,
+    int                /* op */
+#endif
+);
+
+extern void XShapeOffsetShape (
+#if NeedFunctionPrototypes
+    Display*   /* display */,
+    Window     /* dest */,
+    int                /* dest_kind */,
+    int                /* x_off */,
+    int                /* y_off */
+#endif
+);
+
+extern Status XShapeQueryExtents (
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    Window             /* window */,
+    Bool*              /* bounding_shaped */,
+    int*               /* x_bounding */,
+    int*               /* y_bounding */,
+    unsigned int*      /* w_bounding */,
+    unsigned int*      /* h_bounding */,
+    Bool*              /* clip_shaped */,
+    int*               /* x_clip */,
+    int*               /* y_clip */,
+    unsigned int*      /* w_clip */,
+    unsigned int*      /* h_clip */
+#endif
+);
+
+extern void XShapeSelectInput (
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    Window             /* window */,
+    unsigned long      /* mask */
+#endif
+);
+
+extern unsigned long XShapeInputSelected (
+#if NeedFunctionPrototypes
+    Display*   /* display */,
+    Window     /* window */
+#endif
+);
+
+extern XRectangle *XShapeGetRectangles (
+#if NeedFunctionPrototypes
+    Display*   /* display */,
+    Window     /* window */,
+    int                /* kind */,
+    int*       /* count */,
+    int*       /* ordering */
+#endif
+);
+
+_XFUNCPROTOEND
+
+#endif /* _SHAPE_SERVER_ */
+
+#endif /* _SHAPE_H_ */
diff --git a/Xserver/include/extensions/shapestr.h b/Xserver/include/extensions/shapestr.h
new file mode 100644 (file)
index 0000000..e4ff168
--- /dev/null
@@ -0,0 +1,235 @@
+/************************************************************
+
+Copyright (c) 1989  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+********************************************************/
+
+/* $XConsortium: shapestr.h,v 1.13 94/04/17 20:11:24 rws Exp $ */
+
+#ifndef _SHAPESTR_H_
+#define _SHAPESTR_H_
+
+/*
+ * Protocol requests constants and alignment values
+ * These would really be in SHAPE's X.h and Xproto.h equivalents
+ */
+
+#include "shape.h"
+
+#define Window CARD32
+#define Time CARD32
+
+#define SHAPENAME "SHAPE"
+
+#define SHAPE_MAJOR_VERSION    1       /* current version numbers */
+#define SHAPE_MINOR_VERSION    0
+
+typedef struct _ShapeQueryVersion {
+       CARD8   reqType;                /* always ShapeReqCode */
+       CARD8   shapeReqType;           /* always X_ShapeQueryVersion */
+       CARD16  length B16;
+} xShapeQueryVersionReq;
+#define sz_xShapeQueryVersionReq       4
+
+typedef struct {
+       BYTE    type;                   /* X_Reply */
+       CARD8   unused;                 /* not used */
+       CARD16  sequenceNumber B16;
+       CARD32  length B32;
+       CARD16  majorVersion B16;       /* major version of SHAPE protocol */
+       CARD16  minorVersion B16;       /* minor version of SHAPE protocol */
+       CARD32  pad0 B32;
+       CARD32  pad1 B32;
+       CARD32  pad2 B32;
+       CARD32  pad3 B32;
+       CARD32  pad4 B32;
+} xShapeQueryVersionReply;
+#define sz_xShapeQueryVersionReply     32
+
+typedef struct _ShapeRectangles {
+       CARD8   reqType;        /* always ShapeReqCode */
+       CARD8   shapeReqType;   /* always X_ShapeRectangles */
+       CARD16  length B16;
+       CARD8   op;             /* Set, ... */
+       CARD8   destKind;       /* ShapeBounding or ShapeClip */
+       CARD8   ordering;       /* UnSorted, YSorted, YXSorted, YXBanded */
+       CARD8   pad0;           /* not used */
+       Window  dest B32;
+       INT16   xOff B16;
+       INT16   yOff B16;
+} xShapeRectanglesReq;         /* followed by xRects */
+#define sz_xShapeRectanglesReq 16
+
+typedef struct _ShapeMask {
+       CARD8   reqType;        /* always ShapeReqCode */
+       CARD8   shapeReqType;   /* always X_ShapeMask */
+       CARD16  length B16;
+
+       CARD8   op;             /* Set, ... */
+       CARD8   destKind;       /* ShapeBounding or ShapeClip */
+       CARD16  junk B16;       /* not used */
+
+       Window  dest B32;
+       INT16   xOff B16;
+       INT16   yOff B16;
+       CARD32  src B32;        /* 1 bit pixmap */
+} xShapeMaskReq;
+#define sz_xShapeMaskReq       20
+       
+typedef struct _ShapeCombine {
+       CARD8   reqType;        /* always ShapeReqCode */
+       CARD8   shapeReqType;   /* always X_ShapeCombine */
+       CARD16  length B16;
+       CARD8   op;             /* Set, ... */
+       CARD8   destKind;       /* ShapeBounding or ShapeClip */
+       CARD8   srcKind;        /* ShapeBounding or ShapeClip */
+       CARD8   junk;           /* not used */
+       Window  dest B32;
+       INT16   xOff B16;
+       INT16   yOff B16;
+       Window  src B32;
+} xShapeCombineReq;
+#define sz_xShapeCombineReq    20
+       
+typedef struct _ShapeOffset {
+       CARD8   reqType;        /* always ShapeReqCode */
+       CARD8   shapeReqType;   /* always X_ShapeOffset */
+       CARD16  length B16;
+       CARD8   destKind;       /* ShapeBounding or ShapeClip */
+       CARD8   junk1;          /* not used */
+       CARD16  junk2 B16;      /* not used */
+       Window  dest B32;
+       INT16   xOff B16;
+       INT16   yOff B16;
+} xShapeOffsetReq;
+#define sz_xShapeOffsetReq     16
+
+typedef struct _ShapeQueryExtents {
+       CARD8   reqType;        /* always ShapeReqCode */
+       CARD8   shapeReqType;   /* always X_ShapeQueryExtents */
+       CARD16  length B16;
+       Window  window B32;
+} xShapeQueryExtentsReq;
+#define sz_xShapeQueryExtentsReq       8
+
+typedef struct {
+       BYTE    type;                   /* X_Reply */
+       CARD8   unused;                 /* not used */
+       CARD16  sequenceNumber B16;
+       CARD32  length B32;             /* 0 */
+       CARD8   boundingShaped;         /* window has bounding shape */
+       CARD8   clipShaped;             /* window has clip shape */
+       CARD16  unused1 B16;
+       INT16   xBoundingShape B16;     /* extents of bounding shape */
+       INT16   yBoundingShape B16;
+       CARD16  widthBoundingShape B16;
+       CARD16  heightBoundingShape B16;
+       INT16   xClipShape B16;         /* extents of clip shape */
+       INT16   yClipShape B16;
+       CARD16  widthClipShape B16;
+       CARD16  heightClipShape B16;
+       CARD32  pad1 B32;
+} xShapeQueryExtentsReply;
+#define sz_xShapeQueryExtentsReply     32
+
+typedef struct _ShapeSelectInput {
+       CARD8   reqType;        /* always ShapeReqCode */
+       CARD8   shapeReqType;   /* always X_ShapeSelectInput */
+       CARD16  length B16;
+       Window  window B32;
+       BYTE    enable;         /* xTrue -> send events */
+       BYTE    pad1;
+       CARD16  pad2 B16;
+} xShapeSelectInputReq;
+#define sz_xShapeSelectInputReq        12
+
+typedef struct _ShapeNotify {
+       BYTE    type;           /* always eventBase + ShapeNotify */
+       BYTE    kind;           /* either ShapeBounding or ShapeClip */
+       CARD16  sequenceNumber B16;
+       Window  window B32;
+       INT16   x B16;
+       INT16   y B16;          /* extents of new shape */
+       CARD16  width B16;
+       CARD16  height B16;
+       Time    time B32;       /* time of change */
+       BYTE    shaped;         /* set when a shape actual exists */
+       BYTE    pad0;
+       CARD16  pad1 B16;
+       CARD32  pad2 B32;
+       CARD32  pad3 B32;
+} xShapeNotifyEvent;
+#define sz_xShapeNotifyEvent   32
+
+typedef struct _ShapeInputSelected {
+       CARD8   reqType;        /* always ShapeReqCode */
+       CARD8   shapeReqType;   /* always X_ShapeInputSelected */
+       CARD16  length B16;
+       Window  window B32;
+} xShapeInputSelectedReq;
+#define sz_xShapeInputSelectedReq 8
+
+typedef struct {
+       BYTE    type;                   /* X_Reply */
+       CARD8   enabled;                /* current status */
+       CARD16  sequenceNumber B16;
+       CARD32  length B32;             /* 0 */
+       CARD32  pad1 B32;               /* unused */
+       CARD32  pad2 B32;
+       CARD32  pad3 B32;
+       CARD32  pad4 B32;
+       CARD32  pad5 B32;
+       CARD32  pad6 B32;
+} xShapeInputSelectedReply;
+#define sz_xShapeInputSelectedReply    32
+
+typedef struct _ShapeGetRectangles {
+    CARD8   reqType;           /* always ShapeReqCode */
+    CARD8   shapeReqType;      /* always X_ShapeGetRectangles */
+    CARD16  length B16;
+    Window  window B32;
+    CARD8   kind;              /* ShapeBounding or ShapeClip */
+    CARD8   junk1;
+    CARD16  junk2 B16;
+} xShapeGetRectanglesReq;
+#define sz_xShapeGetRectanglesReq      12
+
+typedef struct {
+       BYTE    type;                   /* X_Reply */
+       CARD8   ordering;       /* UnSorted, YSorted, YXSorted, YXBanded */
+       CARD16  sequenceNumber B16;
+       CARD32  length B32;             /* not zero */
+       CARD32  nrects B32;             /* number of rectangles */
+       CARD32 pad1 B32;
+       CARD32 pad2 B32;
+       CARD32 pad3 B32;
+       CARD32 pad4 B32;
+       CARD32 pad5 B32;
+} xShapeGetRectanglesReply;            /* followed by xRectangles */
+#define sz_xShapeGetRectanglesReply 32
+
+#undef Window
+#undef Time
+
+#endif /* _SHAPESTR_H_ */
diff --git a/Xserver/include/extensions/shmstr.h b/Xserver/include/extensions/shmstr.h
new file mode 100644 (file)
index 0000000..70a90f8
--- /dev/null
@@ -0,0 +1,226 @@
+/************************************************************
+
+Copyright (c) 1989  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+********************************************************/
+
+/* THIS IS NOT AN X CONSORTIUM STANDARD */
+
+#ifndef _SHMSTR_H_
+#define _SHMSTR_H_
+
+/* $XConsortium: shmstr.h,v 1.9 94/04/17 20:11:25 rws Exp $ */
+/* $XFree86: xc/include/extensions/shmstr.h,v 3.0 1996/05/06 05:52:42 dawes Exp $ */
+
+#include "XShm.h"
+
+#define ShmSeg CARD32
+#define Drawable CARD32
+#define VisualID CARD32
+#define GContext CARD32
+#define Pixmap CARD32
+
+#define SHMNAME "MIT-SHM"
+
+#define SHM_MAJOR_VERSION      1       /* current version numbers */
+#define SHM_MINOR_VERSION      1
+
+#ifdef _XSHM_SERVER_
+#if NeedFunctionPrototypes
+#define XSHM_PUT_IMAGE_ARGS \
+    DrawablePtr                /* dst */, \
+    GCPtr              /* pGC */, \
+    int                        /* depth */, \
+    unsigned int       /* format */, \
+    int                        /* w */, \
+    int                        /* h */, \
+    int                        /* sx */, \
+    int                        /* sy */, \
+    int                        /* sw */, \
+    int                        /* sh */, \
+    int                        /* dx */, \
+    int                        /* dy */, \
+    char *             /* data */
+#else
+#define XSHM_PUT_IMAGE_ARGS /* nothing */
+#endif
+
+#if NeedFunctionPrototypes
+#define XSHM_CREATE_PIXMAP_ARGS \
+    ScreenPtr  /* pScreen */, \
+    int                /* width */, \
+    int                /* height */, \
+    int                /* depth */, \
+    char *     /* addr */
+#else
+#define XSHM_CREATE_PIXMAP_ARGS /* nothing */
+#endif
+
+typedef struct _ShmFuncs {
+    PixmapPtr  (* CreatePixmap)(XSHM_CREATE_PIXMAP_ARGS);
+    void       (* PutImage)(XSHM_PUT_IMAGE_ARGS);
+} ShmFuncs, *ShmFuncsPtr;
+#endif
+
+typedef struct _ShmQueryVersion {
+    CARD8      reqType;                /* always ShmReqCode */
+    CARD8      shmReqType;             /* always X_ShmQueryVersion */
+    CARD16     length B16;
+} xShmQueryVersionReq;
+#define sz_xShmQueryVersionReq 4
+
+typedef struct {
+    BYTE       type;                   /* X_Reply */
+    BOOL       sharedPixmaps;
+    CARD16     sequenceNumber B16;
+    CARD32     length B32;
+    CARD16     majorVersion B16;       /* major version of SHM protocol */
+    CARD16     minorVersion B16;       /* minor version of SHM protocol */
+    CARD16     uid B16;
+    CARD16     gid B16;
+    CARD8      pixmapFormat;
+    CARD8      pad0;
+    CARD16     pad1 B16;
+    CARD32     pad2 B32;
+    CARD32     pad3 B32;
+    CARD32     pad4 B32;
+} xShmQueryVersionReply;
+#define sz_xShmQueryVersionReply       32
+
+typedef struct _ShmAttach {
+    CARD8      reqType;        /* always ShmReqCode */
+    CARD8      shmReqType;     /* always X_ShmAttach */
+    CARD16     length B16;
+    ShmSeg     shmseg B32;
+    CARD32     shmid B32;
+    BOOL       readOnly;
+    BYTE       pad0;
+    CARD16     pad1 B16;
+} xShmAttachReq;
+#define sz_xShmAttachReq       16
+
+typedef struct _ShmDetach {
+    CARD8      reqType;        /* always ShmReqCode */
+    CARD8      shmReqType;     /* always X_ShmDetach */
+    CARD16     length B16;
+    ShmSeg     shmseg B32;
+} xShmDetachReq;
+#define sz_xShmDetachReq       8
+
+typedef struct _ShmPutImage {
+    CARD8      reqType;        /* always ShmReqCode */
+    CARD8      shmReqType;     /* always X_ShmPutImage */
+    CARD16     length B16;
+    Drawable   drawable B32;
+    GContext   gc B32;
+    CARD16     totalWidth B16;
+    CARD16     totalHeight B16;
+    CARD16     srcX B16;
+    CARD16     srcY B16;
+    CARD16     srcWidth B16;
+    CARD16     srcHeight B16;
+    INT16      dstX B16;
+    INT16      dstY B16;
+    CARD8      depth;
+    CARD8      format;
+    CARD8      sendEvent;
+    CARD8      bpad;
+    ShmSeg     shmseg B32;
+    CARD32     offset B32;
+} xShmPutImageReq;    
+#define sz_xShmPutImageReq     40
+
+typedef struct _ShmGetImage {
+    CARD8      reqType;        /* always ShmReqCode */
+    CARD8      shmReqType;     /* always X_ShmGetImage */
+    CARD16     length B16;
+    Drawable   drawable B32;
+    INT16      x B16;
+    INT16      y B16;
+    CARD16     width B16;
+    CARD16     height B16;
+    CARD32     planeMask B32;
+    CARD8      format;
+    CARD8      pad0;
+    CARD8      pad1;
+    CARD8      pad2;
+    ShmSeg     shmseg B32;
+    CARD32     offset B32;
+} xShmGetImageReq;    
+#define sz_xShmGetImageReq     32
+
+typedef struct _ShmGetImageReply {
+    BYTE       type;  /* X_Reply */
+    CARD8      depth;
+    CARD16     sequenceNumber B16;
+    CARD32     length B32;
+    VisualID   visual B32;
+    CARD32     size B32;
+    CARD32     pad0 B32;
+    CARD32     pad1 B32;
+    CARD32     pad2 B32;
+    CARD32     pad3 B32;
+} xShmGetImageReply;
+#define sz_xShmGetImageReply   32
+
+typedef struct _ShmCreatePixmap {
+    CARD8      reqType;        /* always ShmReqCode */
+    CARD8      shmReqType;     /* always X_ShmCreatePixmap */
+    CARD16     length B16;
+    Pixmap     pid B32;
+    Drawable   drawable B32;
+    CARD16     width B16;
+    CARD16     height B16;
+    CARD8      depth;
+    CARD8      pad0;
+    CARD8      pad1;
+    CARD8      pad2;
+    ShmSeg     shmseg B32;
+    CARD32     offset B32;
+} xShmCreatePixmapReq;
+#define sz_xShmCreatePixmapReq 28
+
+typedef struct _ShmCompletion {
+    BYTE       type;           /* always eventBase + ShmCompletion */
+    BYTE       bpad0;
+    CARD16     sequenceNumber B16;
+    Drawable   drawable B32;
+    CARD16     minorEvent B16;
+    BYTE       majorEvent;
+    BYTE       bpad1;
+    ShmSeg     shmseg B32;
+    CARD32     offset B32;
+    CARD32     pad0 B32;
+    CARD32     pad1 B32;
+    CARD32     pad2 B32;
+} xShmCompletionEvent;
+#define sz_xShmCompletionEvent 32
+
+#undef ShmSeg
+#undef Drawable
+#undef VisualID
+#undef GContext
+#undef Pixmap
+
+#endif /* _SHMSTR_H_ */
diff --git a/Xserver/include/extensions/sync.h b/Xserver/include/extensions/sync.h
new file mode 100644 (file)
index 0000000..cbe3850
--- /dev/null
@@ -0,0 +1,523 @@
+/* $XConsortium: sync.h,v 1.6 94/04/17 20:11:26 dpw Exp $ */
+/*
+
+Copyright (c) 1991, 1993, 1994  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+*/
+
+/***********************************************************
+Copyright 1991,1993 by Digital Equipment Corporation, Maynard, Massachusetts,
+and Olivetti Research Limited, Cambridge, England.
+
+                        All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and its 
+documentation for any purpose and without fee is hereby granted, 
+provided that the above copyright notice appear in all copies and that
+both that copyright notice and this permission notice appear in 
+supporting documentation, and that the names of Digital or Olivetti
+not be used in advertising or publicity pertaining to distribution of the
+software without specific, written prior permission.  
+
+DIGITAL AND OLIVETTI DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
+SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
+FITNESS, IN NO EVENT SHALL THEY BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
+USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
+OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+PERFORMANCE OF THIS SOFTWARE.
+
+******************************************************************/
+
+#ifndef _SYNC_H_
+#define _SYNC_H_
+
+#define SYNC_NAME "SYNC"
+
+#define SYNC_MAJOR_VERSION     3
+#define SYNC_MINOR_VERSION     0
+
+#define X_SyncInitialize               0
+#define X_SyncListSystemCounters       1
+#define X_SyncCreateCounter            2
+#define X_SyncSetCounter               3
+#define X_SyncChangeCounter            4
+#define X_SyncQueryCounter              5
+#define X_SyncDestroyCounter           6
+#define X_SyncAwait                    7
+#define X_SyncCreateAlarm               8
+#define X_SyncChangeAlarm              9
+#define X_SyncQueryAlarm              10
+#define X_SyncDestroyAlarm            11
+#define X_SyncSetPriority             12
+#define X_SyncGetPriority             13
+
+#define XSyncCounterNotify              0
+#define XSyncAlarmNotify               1
+#define XSyncAlarmNotifyMask           (1L << XSyncAlarmNotify)
+
+#define XSyncNumberEvents              2L
+
+#define XSyncBadCounter                        0L
+#define XSyncBadAlarm                  1L
+#define XSyncNumberErrors              (XSyncBadAlarm + 1)
+
+/*
+ * Flags for Alarm Attributes
+ */
+#define XSyncCACounter                 (1L<<0)
+#define XSyncCAValueType               (1L<<1)
+#define XSyncCAValue                   (1L<<2)
+#define XSyncCATestType                        (1L<<3)
+#define XSyncCADelta                   (1L<<4)
+#define XSyncCAEvents                  (1L<<5)
+
+/*
+ * Constants for the value_type argument of various requests
+ */
+typedef enum {
+    XSyncAbsolute,
+    XSyncRelative
+} XSyncValueType;
+
+/*
+ * Alarm Test types
+ */
+typedef enum {
+    XSyncPositiveTransition,
+    XSyncNegativeTransition,
+    XSyncPositiveComparison,
+    XSyncNegativeComparison
+} XSyncTestType;
+
+/*
+ * Alarm state constants
+ */
+typedef enum {
+    XSyncAlarmActive,
+    XSyncAlarmInactive,
+    XSyncAlarmDestroyed
+} XSyncAlarmState;
+
+
+typedef XID XSyncCounter;
+typedef XID XSyncAlarm;
+typedef struct _XSyncValue {
+    int hi;
+    unsigned int lo;
+} XSyncValue;
+
+/*
+ *   Macros/functions for manipulating 64 bit values
+ */
+
+/* have to put these prototypes before the corresponding macro definitions */
+
+extern void XSyncIntToValue(
+#if NeedFunctionPrototypes
+    XSyncValue* /*pv*/,
+    int /*i*/
+#endif
+);
+
+extern void XSyncIntsToValue(
+#if NeedFunctionPrototypes
+    XSyncValue* /*pv*/,
+    unsigned int /*l*/,
+    int /*h*/
+#endif
+);
+
+extern Bool XSyncValueGreaterThan(
+#if NeedFunctionPrototypes
+    XSyncValue /*a*/,
+    XSyncValue /*b*/
+#endif
+);
+
+extern Bool XSyncValueLessThan(
+#if NeedFunctionPrototypes
+    XSyncValue /*a*/,
+    XSyncValue /*b*/
+#endif
+);
+
+extern Bool XSyncValueGreaterOrEqual(
+#if NeedFunctionPrototypes
+    XSyncValue /*a*/,
+    XSyncValue /*b*/
+#endif
+);
+
+extern Bool XSyncValueLessOrEqual(
+#if NeedFunctionPrototypes
+    XSyncValue /*a*/,
+    XSyncValue /*b*/
+#endif
+);
+
+extern Bool XSyncValueEqual(
+#if NeedFunctionPrototypes
+    XSyncValue /*a*/,
+    XSyncValue /*b*/
+#endif
+);
+
+extern Bool XSyncValueIsNegative(
+#if NeedFunctionPrototypes
+    XSyncValue /*v*/
+#endif
+);
+
+extern Bool XSyncValueIsZero(
+#if NeedFunctionPrototypes
+    XSyncValue /*a*/
+#endif
+);
+
+extern Bool XSyncValueIsPositive(
+#if NeedFunctionPrototypes
+    XSyncValue /*v*/
+#endif
+);
+
+extern unsigned int XSyncValueLow32(
+#if NeedFunctionPrototypes
+    XSyncValue /*v*/
+#endif
+);
+
+extern int XSyncValueHigh32(
+#if NeedFunctionPrototypes
+    XSyncValue /*v*/
+#endif
+);
+
+extern void XSyncValueAdd(
+#if NeedFunctionPrototypes
+    XSyncValue* /*presult*/,
+    XSyncValue /*a*/,
+    XSyncValue /*b*/,
+    int* /*poverflow*/
+#endif
+);
+
+extern void XSyncValueSubtract(
+#if NeedFunctionPrototypes
+    XSyncValue* /*presult*/,
+    XSyncValue /*a*/,
+    XSyncValue /*b*/,
+    int* /*poverflow*/
+#endif
+);
+
+extern void XSyncMaxValue(
+#if NeedFunctionPrototypes
+    XSyncValue* /*pv*/
+#endif
+);
+
+extern void XSyncMinValue(
+#if NeedFunctionPrototypes
+    XSyncValue* /*pv*/
+#endif
+);
+
+/*  The _XSync macros below are for library internal use only.  They exist 
+ *  so that if we have to make a fix, we can change it in this one place
+ *  and have both the macro and function variants inherit the fix.
+ */
+
+#define _XSyncIntToValue(pv, i)     ((pv)->hi=((i<0)?~0:0),(pv)->lo=(i))
+#define _XSyncIntsToValue(pv, l, h) ((pv)->lo = (l), (pv)->hi = (h))
+#define _XSyncValueGreaterThan(a, b)\
+    ((a).hi>(b).hi || ((a).hi==(b).hi && (a).lo>(b).lo))
+#define _XSyncValueLessThan(a, b)\
+    ((a).hi<(b).hi || ((a).hi==(b).hi && (a).lo<(b).lo))
+#define _XSyncValueGreaterOrEqual(a, b)\
+    ((a).hi>(b).hi || ((a).hi==(b).hi && (a).lo>=(b).lo))
+#define _XSyncValueLessOrEqual(a, b)\
+    ((a).hi<(b).hi || ((a).hi==(b).hi && (a).lo<=(b).lo))
+#define _XSyncValueEqual(a, b) ((a).lo==(b).lo && (a).hi==(b).hi)
+#define _XSyncValueIsNegative(v) (((v).hi & 0x80000000) ? 1 : 0)
+#define _XSyncValueIsZero(a)   ((a).lo==0 && (a).hi==0)
+#define _XSyncValueIsPositive(v) (((v).hi & 0x80000000) ? 0 : 1)
+#define _XSyncValueLow32(v)    ((v).lo)
+#define _XSyncValueHigh32(v)   ((v).hi)
+#define _XSyncValueAdd(presult,a,b,poverflow) {\
+       int t = (a).lo;\
+       Bool signa = XSyncValueIsNegative(a);\
+       Bool signb = XSyncValueIsNegative(b);\
+       ((presult)->lo = (a).lo + (b).lo);\
+       ((presult)->hi = (a).hi + (b).hi);\
+       if (t>(presult)->lo) (presult)->hi++;\
+       *poverflow = ((signa == signb) && !(signa == XSyncValueIsNegative(*presult)));\
+     }
+#define _XSyncValueSubtract(presult,a,b,poverflow) {\
+       int t = (a).lo;\
+       Bool signa = XSyncValueIsNegative(a);\
+       Bool signb = XSyncValueIsNegative(b);\
+       ((presult)->lo = (a).lo - (b).lo);\
+       ((presult)->hi = (a).hi - (b).hi);\
+       if (t>(presult)->lo) (presult)->hi--;\
+       *poverflow = ((signa == signb) && !(signa == XSyncValueIsNegative(*presult)));\
+     }
+#define _XSyncMaxValue(pv) ((pv)->hi = 0x7fffffff, (pv)->lo = 0xffffffff)
+#define _XSyncMinValue(pv) ((pv)->hi = 0x80000000, (pv)->lo = 0)
+
+/*
+ *  These are the publically usable macros.  If you want the function version
+ *  of one of these, just #undef the macro to uncover the function.
+ *  (This is the same convention that the ANSI C library uses.)
+ */
+
+#define XSyncIntToValue(pv, i) _XSyncIntToValue(pv, i)
+#define XSyncIntsToValue(pv, l, h) _XSyncIntsToValue(pv, l, h)
+#define XSyncValueGreaterThan(a, b) _XSyncValueGreaterThan(a, b)
+#define XSyncValueLessThan(a, b) _XSyncValueLessThan(a, b)
+#define XSyncValueGreaterOrEqual(a, b) _XSyncValueGreaterOrEqual(a, b)
+#define XSyncValueLessOrEqual(a, b) _XSyncValueLessOrEqual(a, b)
+#define XSyncValueEqual(a, b) _XSyncValueEqual(a, b)
+#define XSyncValueIsNegative(v) _XSyncValueIsNegative(v)
+#define XSyncValueIsZero(a) _XSyncValueIsZero(a)
+#define XSyncValueIsPositive(v) _XSyncValueIsPositive(v)
+#define XSyncValueLow32(v) _XSyncValueLow32(v)
+#define XSyncValueHigh32(v) _XSyncValueHigh32(v)
+#define XSyncValueAdd(presult,a,b,poverflow) _XSyncValueAdd(presult,a,b,poverflow)
+#define XSyncValueSubtract(presult,a,b,poverflow) _XSyncValueSubtract(presult,a,b,poverflow)
+#define XSyncMaxValue(pv) _XSyncMaxValue(pv)
+#define XSyncMinValue(pv) _XSyncMinValue(pv)
+
+#ifndef _SYNC_SERVER
+
+typedef struct _XSyncSystemCounter {
+    char *name;                        /* null-terminated name of system counter */
+    XSyncCounter counter;      /* counter id of this system counter */
+    XSyncValue resolution;     /* resolution of this system counter */
+} XSyncSystemCounter;
+
+
+typedef struct {
+    XSyncCounter counter;      /* counter to trigger on */
+    XSyncValueType value_type; /* absolute/relative */
+    XSyncValue wait_value;     /* value to compare counter to */
+    XSyncTestType test_type;   /* pos/neg comparison/transtion */
+} XSyncTrigger;
+
+typedef struct {
+    XSyncTrigger trigger;      /* trigger for await */
+    XSyncValue event_threshold; /* send event if past threshold */
+} XSyncWaitCondition;
+
+
+typedef struct {
+    XSyncTrigger trigger;
+    XSyncValue  delta;
+    Bool events;
+    XSyncAlarmState state;
+} XSyncAlarmAttributes;
+
+/*
+ *  Events
+ */
+
+typedef struct {
+    int type;                  /* event base + XSyncCounterNotify */
+    unsigned long serial;      /* # of last request processed by server */
+    Bool send_event;           /* true if this came from a SendEvent request */
+    Display *display;          /* Display the event was read from */
+    XSyncCounter counter;      /* counter involved in await */
+    XSyncValue wait_value;     /* value being waited for */
+    XSyncValue counter_value;  /* counter value when this event was sent */
+    Time time;                 /* milliseconds */
+    int count;                 /* how many more events to come */
+    Bool destroyed;            /* True if counter was destroyed */
+} XSyncCounterNotifyEvent;
+
+typedef struct {
+    int type;                  /* event base + XSyncCounterNotify */
+    unsigned long serial;      /* # of last request processed by server */
+    Bool send_event;           /* true if this came from a SendEvent request */
+    Display *display;          /* Display the event was read from */
+    XSyncAlarm alarm;          /* alarm that triggered */
+    XSyncValue counter_value;  /* value that triggered the alarm */
+    XSyncValue alarm_value;    /* test  value of trigger in alarm */
+    Time time;                 /* milliseconds */
+    XSyncAlarmState state;     /* new state of alarm */
+} XSyncAlarmNotifyEvent;
+
+/*
+ *  Errors 
+ */
+
+typedef struct {
+    int type;                  
+    Display *display;          /* Display the event was read from */
+    XSyncAlarm alarm;          /* resource id */
+    unsigned long serial;      /* serial number of failed request */
+    unsigned char error_code;  /* error base + XSyncBadAlarm */
+    unsigned char request_code;        /* Major op-code of failed request */
+    unsigned char minor_code;  /* Minor op-code of failed request */
+} XSyncAlarmError;
+
+typedef struct {
+    int type;                  
+    Display *display;          /* Display the event was read from */
+    XSyncCounter counter;      /* resource id */
+    unsigned long serial;      /* serial number of failed request */
+    unsigned char error_code;  /* error base + XSyncBadCounter */
+    unsigned char request_code;        /* Major op-code of failed request */
+    unsigned char minor_code;  /* Minor op-code of failed request */
+} XSyncCounterError;
+
+/* 
+ *  Prototypes
+ */
+
+extern Status XSyncQueryExtension(
+#if NeedFunctionPrototypes
+    Display* /*dpy*/,
+    int* /*event_base_return*/,
+    int* /*error_base_return*/
+#endif
+);
+
+extern Status XSyncInitialize(
+#if NeedFunctionPrototypes
+    Display* /*dpy*/,
+    int* /*major_version_return*/,
+    int* /*minor_version_return*/
+#endif
+);
+
+extern XSyncSystemCounter *XSyncListSystemCounters(
+#if NeedFunctionPrototypes
+    Display* /*dpy*/,
+    int* /*n_counters_return*/
+#endif
+);
+
+extern void XSyncFreeSystemCounterList(
+#if NeedFunctionPrototypes
+    XSyncSystemCounter* /*list*/
+#endif
+);
+
+extern XSyncCounter XSyncCreateCounter(
+#if NeedFunctionPrototypes
+    Display* /*dpy*/,
+    XSyncValue /*initial_value*/
+#endif
+);
+
+extern Status XSyncSetCounter(
+#if NeedFunctionPrototypes
+    Display* /*dpy*/,
+    XSyncCounter /*counter*/,
+    XSyncValue /*value*/
+#endif
+);
+
+extern Status XSyncChangeCounter(
+#if NeedFunctionPrototypes
+    Display* /*dpy*/,
+    XSyncCounter /*counter*/,
+    XSyncValue /*value*/
+#endif
+);
+
+extern Status XSyncDestroyCounter(
+#if NeedFunctionPrototypes
+    Display* /*dpy*/,
+    XSyncCounter /*counter*/
+#endif
+);
+
+extern Status XSyncQueryCounter(
+#if NeedFunctionPrototypes
+    Display* /*dpy*/,
+    XSyncCounter /*counter*/,
+    XSyncValue* /*value_return*/
+#endif
+);
+
+extern Status XSyncAwait(
+#if NeedFunctionPrototypes
+    Display* /*dpy*/,
+    XSyncWaitCondition* /*wait_list*/,
+    int /*n_conditions*/
+#endif
+);
+
+extern XSyncAlarm XSyncCreateAlarm(
+#if NeedFunctionPrototypes
+    Display* /*dpy*/,
+    unsigned long /*values_mask*/,
+    XSyncAlarmAttributes* /*values*/
+#endif
+);
+
+extern Status XSyncDestroyAlarm(
+#if NeedFunctionPrototypes
+    Display* /*dpy*/,
+    XSyncAlarm /*alarm*/
+#endif
+);
+
+extern Status XSyncQueryAlarm(
+#if NeedFunctionPrototypes
+    Display* /*dpy*/,
+    XSyncAlarm /*alarm*/,
+    XSyncAlarmAttributes* /*values_return*/
+#endif
+);
+
+extern Status XSyncChangeAlarm(
+#if NeedFunctionPrototypes
+    Display* /*dpy*/,
+    XSyncAlarm /*alarm*/,
+    unsigned long /*values_mask*/,
+    XSyncAlarmAttributes* /*values*/
+#endif
+);
+
+extern Status XSyncSetPriority(
+#if NeedFunctionPrototypes
+    Display* /*dpy*/,
+    XID /*client_resource_id*/,
+    int /*priority*/
+#endif
+);
+
+extern Status XSyncGetPriority(
+#if NeedFunctionPrototypes
+    Display* /*dpy*/,
+    XID /*client_resource_id*/,
+    int* /*return_priority*/
+#endif
+);
+
+#endif /* _SYNC_SERVER */
+
+#endif /* _SYNC_H_ */
diff --git a/Xserver/include/extensions/syncstr.h b/Xserver/include/extensions/syncstr.h
new file mode 100644 (file)
index 0000000..fa0223e
--- /dev/null
@@ -0,0 +1,500 @@
+/* $XConsortium: syncstr.h,v 1.4 94/04/17 20:11:27 rws Exp $ */
+/*
+
+Copyright (c) 1991, 1993, 1994  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+*/
+
+/***********************************************************
+Copyright 1991,1993 by Digital Equipment Corporation, Maynard, Massachusetts,
+and Olivetti Research Limited, Cambridge, England.
+
+                        All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and its 
+documentation for any purpose and without fee is hereby granted, 
+provided that the above copyright notice appear in all copies and that
+both that copyright notice and this permission notice appear in 
+supporting documentation, and that the names of Digital or Olivetti
+not be used in advertising or publicity pertaining to distribution of the
+software without specific, written prior permission.  
+
+DIGITAL AND OLIVETTI DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
+SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
+FITNESS, IN NO EVENT SHALL THEY BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
+USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
+OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+PERFORMANCE OF THIS SOFTWARE.
+
+******************************************************************/
+
+#include "sync.h"
+
+#ifndef _SYNC_OS
+
+/* cover up types from sync.h to make sure they're the right size for
+ * protocol packaging.  These will be undef'ed after all the protocol
+ * structures are defined.
+ */
+#define XSyncCounter CARD32
+#define XSyncAlarm   CARD32
+
+/*
+ * Initialize
+ */
+typedef struct _xSyncInitialize {
+    CARD8      reqType;
+    CARD8      syncReqType;
+    CARD16     length B16;
+    CARD8      majorVersion;
+    CARD8      minorVersion;
+    CARD16     pad B16;
+} xSyncInitializeReq;
+#define sz_xSyncInitializeReq          8
+
+typedef struct {
+    BYTE       type;
+    CARD8      unused;
+    CARD16     sequenceNumber B16;
+    CARD32     length B32;
+    CARD8      majorVersion;
+    CARD8      minorVersion;
+    CARD16     pad B16;
+    CARD32     pad0 B32;
+    CARD32     pad1 B32;
+    CARD32     pad2 B32;
+    CARD32     pad3 B32;
+    CARD32     pad4 B32;
+} xSyncInitializeReply;
+#define sz_xSyncInitializeReply        32
+
+/*
+ * ListSystemCounters
+ */
+typedef struct _xSyncListSystemCounters
+{
+    CARD8      reqType;
+    CARD8      syncReqType;
+    CARD16     length B16;
+} xSyncListSystemCountersReq;
+#define sz_xSyncListSystemCountersReq  4
+
+typedef struct {
+    BYTE       type;
+    CARD8      unused;
+    CARD16     sequenceNumber B16;
+    CARD32     length B32;
+    INT32      nCounters B32;
+    CARD32     pad0 B32;
+    CARD32     pad1 B32;
+    CARD32     pad2 B32;
+    CARD32     pad3 B32;
+    CARD32     pad4 B32;
+} xSyncListSystemCountersReply;
+#define sz_xSyncListSystemCountersReply        32
+
+typedef struct {
+    XSyncCounter counter B32;
+    INT32      resolution_hi B32;
+    CARD32     resolution_lo B32;
+    CARD16     name_length B16;
+} xSyncSystemCounter;
+#define sz_xSyncSystemCounter 14
+
+/*
+ * Create Counter
+ */
+typedef struct _xSyncCreateCounterReq {
+    CARD8      reqType;
+    CARD8      syncReqType;
+    CARD16     length B16;
+    XSyncCounter cid B32;
+    INT32       initial_value_hi B32;
+    CARD32     initial_value_lo B32;
+} xSyncCreateCounterReq;
+#define sz_xSyncCreateCounterReq       16
+
+/*
+ * Change Counter
+ */
+typedef struct _xSyncChangeCounterReq {
+    CARD8      reqType;
+    CARD8      syncReqType;
+    CARD16     length B16;
+    XSyncCounter cid B32;
+    INT32       value_hi B32;
+    CARD32     value_lo B32;
+} xSyncChangeCounterReq;
+#define sz_xSyncChangeCounterReq       16
+
+/*
+ * Set Counter
+ */
+typedef struct _xSyncSetCounterReq {
+    CARD8      reqType;
+    CARD8      syncReqType;
+    CARD16     length B16;
+    XSyncCounter cid B32;
+    INT32       value_hi B32;
+    CARD32     value_lo B32;
+} xSyncSetCounterReq;
+#define sz_xSyncSetCounterReq  16
+
+/*
+ * Destroy Counter
+ */
+typedef struct _xSyncDestroyCounterReq {
+    CARD8      reqType;
+    CARD8      syncReqType;
+    CARD16     length B16;
+    XSyncCounter counter B32;
+} xSyncDestroyCounterReq;
+#define sz_xSyncDestroyCounterReq      8
+
+/*
+ * Query Counter
+ */
+typedef struct _xSyncQueryCounterReq {
+    CARD8      reqType;
+    CARD8      syncReqType;
+    CARD16     length B16;
+    XSyncCounter counter B32;
+} xSyncQueryCounterReq;
+#define sz_xSyncQueryCounterReq                8
+
+
+typedef struct {
+    BYTE       type;
+    CARD8      unused;
+    CARD16     sequenceNumber B16;
+    CARD32     length B32;
+    INT32      value_hi B32;
+    CARD32     value_lo B32;
+    CARD32     pad0 B32;
+    CARD32     pad1 B32;
+    CARD32     pad2 B32;
+    CARD32     pad3 B32;
+} xSyncQueryCounterReply;
+#define sz_xSyncQueryCounterReply      32
+
+/*
+ * Await
+ */
+typedef struct _xSyncAwaitReq {
+    CARD8      reqType;
+    CARD8      syncReqType;
+    CARD16     length B16;
+} xSyncAwaitReq;
+#define sz_xSyncAwaitReq               4
+
+typedef struct _xSyncWaitCondition {
+    XSyncCounter counter B32;
+    CARD32     value_type B32;
+    INT32       wait_value_hi B32;
+    CARD32      wait_value_lo B32;
+    CARD32     test_type B32;
+    INT32      event_threshold_hi B32;
+    CARD32     event_threshold_lo B32;
+} xSyncWaitCondition;
+#define sz_xSyncWaitCondition          28
+
+/*
+ * Create Alarm
+ */
+typedef struct _xSyncCreateAlarmReq {
+    CARD8      reqType;
+    CARD8      syncReqType;
+    CARD16     length B16;
+    XSyncAlarm id B32;
+    CARD32      valueMask B32;
+} xSyncCreateAlarmReq;
+#define sz_xSyncCreateAlarmReq         12
+
+/*
+ * Destroy Alarm
+ */
+typedef struct _xSyncDestroyAlarmReq {
+    CARD8      reqType;
+    CARD8      syncReqType;
+    CARD16     length B16;
+    XSyncAlarm alarm B32;
+} xSyncDestroyAlarmReq;
+#define sz_xSyncDestroyAlarmReq                8
+
+/*
+ * Query Alarm
+ */
+typedef struct _xSyncQueryAlarmReq {
+    CARD8      reqType;
+    CARD8      syncReqType;
+    CARD16     length B16;
+    XSyncAlarm alarm B32;
+} xSyncQueryAlarmReq;
+#define sz_xSyncQueryAlarmReq          8
+
+typedef struct {
+    BYTE       type;
+    CARD8      unused;
+    CARD16     sequenceNumber B16;
+    CARD32     length B32;
+    XSyncCounter counter B32;
+    CARD32     value_type B32;
+    INT32      wait_value_hi B32;
+    CARD32     wait_value_lo B32;
+    CARD32     test_type      B32;
+    INT32      delta_hi B32;
+    CARD32     delta_lo B32;
+    BOOL        events;
+    BYTE        state;
+    BYTE       pad0;
+    BYTE       pad1;
+} xSyncQueryAlarmReply;
+#define sz_xSyncQueryAlarmReply                40
+
+/*
+ * Change Alarm
+ */
+typedef struct _xSyncChangeAlarmReq {
+    CARD8      reqType;
+    CARD8      syncReqType;
+    CARD16     length B16;
+    XSyncAlarm alarm B32;
+    CARD32     valueMask B32;
+} xSyncChangeAlarmReq;
+#define sz_xSyncChangeAlarmReq         12
+
+/*
+ * SetPriority
+ */
+typedef struct _xSyncSetPriority{
+    CARD8      reqType;
+    CARD8      syncReqType;
+    CARD16     length B16;
+    CARD32     id B32;
+    INT32      priority B32;
+} xSyncSetPriorityReq;
+#define sz_xSyncSetPriorityReq         12
+
+/*
+ * Get Priority
+ */
+typedef struct _xSyncGetPriority{
+    CARD8      reqType;
+    CARD8      syncReqType;
+    CARD16     length B16;
+    CARD32     id B32; /*XXX XID? */
+} xSyncGetPriorityReq;
+#define sz_xSyncGetPriorityReq          8
+
+typedef struct {
+    BYTE       type;
+    CARD8      unused;
+    CARD16     sequenceNumber B16;
+    CARD32     length B32;
+    INT32      priority B32;
+    CARD32     pad0 B32;
+    CARD32     pad1 B32;
+    CARD32     pad2 B32;
+    CARD32     pad3 B32;
+    CARD32     pad4 B32;
+} xSyncGetPriorityReply;
+#define sz_xSyncGetPriorityReply       32
+
+/*
+ * Events
+ */
+
+typedef struct _xSyncCounterNotifyEvent {
+    BYTE       type;
+    BYTE       kind;
+    CARD16     sequenceNumber B16;
+    XSyncCounter counter B32;
+    INT32      wait_value_hi B32;
+    CARD32     wait_value_lo B32;
+    INT32      counter_value_hi B32;
+    CARD32     counter_value_lo B32;
+    CARD32     time B32;
+    CARD16     count B16;
+    BOOL       destroyed;
+    BYTE        pad0;
+} xSyncCounterNotifyEvent;
+
+typedef struct _xSyncAlarmNotifyEvent {
+    BYTE       type;
+    BYTE       kind;
+    CARD16     sequenceNumber B16;
+    XSyncAlarm alarm B32;
+    INT32      counter_value_hi B32;
+    CARD32     counter_value_lo B32;
+    INT32      alarm_value_hi B32;
+    CARD32     alarm_value_lo B32;
+    CARD32     time B32;
+    CARD8       state;
+    BYTE        pad0;
+    BYTE        pad1;
+    BYTE        pad2;
+} xSyncAlarmNotifyEvent;
+
+#undef XSyncCounter
+#undef XSyncAlarm
+
+#endif /* _SYNC_OS */
+
+#ifdef _SYNC_SERVER
+
+#define CARD64 XSyncValue /* XXX temporary! need real 64 bit values for Alpha */
+
+typedef struct _SyncCounter {
+    ClientPtr          client; /* Owning client. 0 for system counters */
+    XSyncCounter       id;             /* resource ID */
+    CARD64             value;          /* counter value */
+    struct _SyncTriggerList *pTriglist;        /* list of triggers */
+    Bool               beingDestroyed; /* in process of going away */
+    struct _SysCounterInfo *pSysCounterInfo; /* NULL if not a system counter */
+} SyncCounter;
+
+/*
+ * The System Counter interface
+ */
+
+typedef enum {
+    XSyncCounterNeverChanges,
+    XSyncCounterNeverIncreases,
+    XSyncCounterNeverDecreases,
+    XSyncCounterUnrestricted
+} SyncCounterType;
+
+typedef struct _SysCounterInfo {
+    char       *name;
+    CARD64     resolution;
+    CARD64     bracket_greater;
+    CARD64     bracket_less;
+    SyncCounterType counterType;  /* how can this counter change */
+    void        (*QueryValue)(
+#if NeedNestedPrototypes
+                             pointer /*pCounter*/,
+                             CARD64 * /*freshvalue*/
+#endif
+);
+    void       (*BracketValues)(
+#if NeedNestedPrototypes
+                                pointer /*pCounter*/,
+                                CARD64 * /*lessthan*/,
+                                CARD64 * /*greaterthan*/
+#endif
+);
+} SysCounterInfo;
+
+
+
+typedef struct _SyncTrigger {
+    SyncCounter *pCounter;
+    CARD64     wait_value;     /* wait value */
+    unsigned int value_type;     /* Absolute or Relative */
+    unsigned int test_type;    /* transition or Comparision type */
+    CARD64     test_value;     /* trigger event threshold value */
+    Bool       (*CheckTrigger)(
+#if NeedNestedPrototypes
+                               struct _SyncTrigger * /*pTrigger*/,
+                               CARD64 /*newval*/
+#endif
+                               );
+    void       (*TriggerFired)(
+#if NeedNestedPrototypes
+                               struct _SyncTrigger * /*pTrigger*/
+#endif
+                               );
+    void       (*CounterDestroyed)(
+#if NeedNestedPrototypes
+                               struct _SyncTrigger * /*pTrigger*/
+#endif
+                                   );
+} SyncTrigger;
+
+typedef struct _SyncTriggerList {
+    SyncTrigger *pTrigger;
+    struct _SyncTriggerList *next;
+} SyncTriggerList;
+
+typedef struct _SyncAlarmClientList {
+    ClientPtr  client;
+    XID                delete_id;
+    struct _SyncAlarmClientList *next;
+} SyncAlarmClientList;
+
+typedef struct _SyncAlarm {
+    SyncTrigger trigger;
+    ClientPtr  client;
+    XSyncAlarm         alarm_id;
+    CARD64     delta;
+    int                events;
+    int                state;
+    SyncAlarmClientList *pEventClients;
+} SyncAlarm;
+
+typedef struct {
+    ClientPtr  client;
+    CARD32     delete_id;
+    int                num_waitconditions;
+} SyncAwaitHeader;
+
+typedef struct {
+    SyncTrigger trigger;
+    CARD64     event_threshold;
+    SyncAwaitHeader *pHeader;
+} SyncAwait;
+
+typedef union {
+    SyncAwaitHeader header;
+    SyncAwait      await;
+} SyncAwaitUnion;
+
+
+extern pointer SyncCreateSystemCounter(
+#if NeedFunctionPrototypes
+    char *     /* name */,
+    CARD64     /* inital_value */,
+    CARD64     /* resolution */,
+    SyncCounterType /* change characterization */,
+    void        (* /*QueryValue*/ ) (), /* XXX prototype */
+    void        (* /*BracketValues*/) ()
+#endif
+);
+
+extern void SyncChangeCounter(
+#if NeedFunctionPrototypes
+    SyncCounter *      /* pCounter*/,
+    CARD64             /* new_value */
+#endif
+);
+
+extern void SyncDestroySystemCounter(
+#if NeedFunctionPrototypes
+    pointer pCounter
+#endif
+);
+extern void InitServertime();
+
+#endif /* _SYNC_SERVER */
diff --git a/Xserver/include/extensions/xcmiscstr.h b/Xserver/include/extensions/xcmiscstr.h
new file mode 100644 (file)
index 0000000..fbb8ffe
--- /dev/null
@@ -0,0 +1,108 @@
+/* $XConsortium: xcmiscstr.h,v 1.4 94/04/17 20:11:28 dpw Exp $ */
+/*
+
+Copyright (c) 1993, 1994  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+*/
+
+#define X_XCMiscGetVersion     0
+#define X_XCMiscGetXIDRange    1
+#define X_XCMiscGetXIDList     2
+
+#define XCMiscNumberEvents     0
+
+#define XCMiscNumberErrors     0
+
+#define XCMiscMajorVersion     1
+#define XCMiscMinorVersion     1
+
+#define XCMiscExtensionName    "XC-MISC"
+
+typedef struct {
+    CARD8      reqType;        /* always XCMiscCode */
+    CARD8      miscReqType;    /* always X_XCMiscGetVersion */
+    CARD16     length B16;
+    CARD16     majorVersion B16;
+    CARD16     minorVersion B16;
+} xXCMiscGetVersionReq;
+#define sz_xXCMiscGetVersionReq 8
+
+typedef struct {
+    BYTE       type;                   /* X_Reply */
+    CARD8      pad0;
+    CARD16     sequenceNumber B16;
+    CARD32     length B32;
+    CARD16     majorVersion B16;
+    CARD16     minorVersion B16;
+    CARD32     pad1 B32;
+    CARD32     pad2 B32;
+    CARD32     pad3 B32;
+    CARD32     pad4 B32;
+    CARD32     pad5 B32;
+} xXCMiscGetVersionReply;
+#define sz_xXCMiscGetVersionReply 32
+
+typedef struct {
+    CARD8      reqType;        /* always XCMiscCode */
+    CARD8      miscReqType;    /* always X_XCMiscGetXIDRange */
+    CARD16     length B16;
+} xXCMiscGetXIDRangeReq;
+#define sz_xXCMiscGetXIDRangeReq 4
+
+typedef struct {
+    BYTE       type;                   /* X_Reply */
+    CARD8      pad0;
+    CARD16     sequenceNumber B16;
+    CARD32     length B32;
+    CARD32     start_id B32;
+    CARD32     count B32;
+    CARD32     pad1 B32;
+    CARD32     pad2 B32;
+    CARD32     pad3 B32;
+    CARD32     pad4 B32;
+} xXCMiscGetXIDRangeReply;
+#define sz_xXCMiscGetXIDRangeReply 32
+
+typedef struct {
+    CARD8      reqType;        /* always XCMiscCode */
+    CARD8      miscReqType;    /* always X_XCMiscGetXIDList */
+    CARD16     length B16;
+    CARD32     count B32;      /* number of IDs requested */
+} xXCMiscGetXIDListReq;
+#define sz_xXCMiscGetXIDListReq 8
+
+typedef struct {
+    BYTE       type;                   /* X_Reply */
+    CARD8      pad0;
+    CARD16     sequenceNumber B16;
+    CARD32     length B32;
+    CARD32     count B32;      /* number of IDs requested */
+    CARD32     pad1 B32;
+    CARD32     pad2 B32;
+    CARD32     pad3 B32;
+    CARD32     pad4 B32;
+    CARD32     pad5 B32;
+} xXCMiscGetXIDListReply;
+#define sz_xXCMiscGetXIDListReply 32
+
diff --git a/Xserver/include/extensions/xf86dga.h b/Xserver/include/extensions/xf86dga.h
new file mode 100644 (file)
index 0000000..afcf544
--- /dev/null
@@ -0,0 +1,167 @@
+/* $XFree86: xc/include/extensions/xf86dga.h,v 3.5 1996/10/18 14:57:24 dawes Exp $ */
+/*
+
+Copyright (c) 1995  Jon Tombs
+Copyright (c) 1995  XFree86 Inc
+
+*/
+
+#ifndef _XF86DGA_H_
+#define _XF86DGA_H_
+
+#include <X11/Xfuncproto.h>
+
+#define X_XF86DGAQueryVersion          0
+#define X_XF86DGAGetVideoLL            1
+#define X_XF86DGADirectVideo           2
+#define X_XF86DGAGetViewPortSize       3
+#define X_XF86DGASetViewPort           4
+#define X_XF86DGAGetVidPage            5
+#define X_XF86DGASetVidPage            6
+#define X_XF86DGAInstallColormap       7
+#define X_XF86DGAQueryDirectVideo      8
+#define X_XF86DGAViewPortChanged       9
+
+#define XF86DGADirectPresent           0x0001
+#define XF86DGADirectGraphics          0x0002
+#define XF86DGADirectMouse             0x0004
+#define XF86DGADirectKeyb              0x0008
+#define XF86DGAHasColormap             0x0100
+#define XF86DGADirectColormap          0x0200
+
+#define XF86DGANumberEvents            0
+
+#define XF86DGAClientNotLocal          0
+#define XF86DGANoDirectVideoMode       1
+#define XF86DGAScreenNotActive         2
+#define XF86DGADirectNotActivated      3
+#define XF86DGANumberErrors            (XF86DGADirectNotActivated + 1)
+
+#ifndef _XF86DGA_SERVER_
+
+_XFUNCPROTOBEGIN
+
+Bool XF86DGAQueryVersion(
+#if NeedFunctionPrototypes
+    Display*           /* dpy */,
+    int*               /* majorVersion */,
+    int*               /* minorVersion */
+#endif
+);
+
+Bool XF86DGAQueryExtension(
+#if NeedFunctionPrototypes
+    Display*           /* dpy */,
+    int*               /* event_base */,
+    int*               /* error_base */
+#endif
+);
+
+Status XF86DGAGetVideoLL(
+#if NeedFunctionPrototypes
+    Display*                   /* dpy */,
+    int                                /* screen */,
+    int *                      /* base addr */,
+    int *                      /* width */,
+    int *                      /* bank_size */,
+    int *                      /* ram_size */ 
+#endif
+);
+
+Status XF86DGAGetVideo(
+#if NeedFunctionPrototypes
+    Display*                   /* dpy */,
+    int                                /* screen */,
+    char **                    /* base addr */,
+    int *                      /* width */,
+    int *                      /* bank_size */,
+    int *                      /* ram_size */
+#endif
+);
+
+Status XF86DGADirectVideo(
+#if NeedFunctionPrototypes
+    Display*                   /* dpy */,
+    int                                /* screen */,
+    int                        /* enable */
+#endif
+);
+
+Status XF86DGADirectVideoLL(
+#if NeedFunctionPrototypes
+    Display*                   /* dpy */,
+    int                                /* screen */,
+    int                        /* enable */
+#endif
+);
+
+Status XF86DGAGetViewPortSize(
+#if NeedFunctionPrototypes
+    Display*                   /* dpy */,
+    int                                /* screen */,
+    int *                      /* width */,
+    int *                      /* height */
+#endif
+);
+
+Status XF86DGASetViewPort(
+#if NeedFunctionPrototypes
+    Display*                   /* dpy */,
+    int                                /* screen */,
+    int x                      /* X */,
+    int y                      /* Y */
+#endif
+);
+
+Status XF86DGAGetVidPage(
+#if NeedFunctionPrototypes
+    Display*                   /* dpy */,
+    int                                /* screen */,
+    int *                      /* vid page */
+#endif
+);
+
+Status XF86DGASetVidPage(
+#if NeedFunctionPrototypes
+    Display*                   /* dpy */,
+    int                                /* screen */,
+    int                                /* vid page */
+#endif
+);
+
+Status XF86DGAInstallColormap(
+#if NeedFunctionPrototypes
+    Display*                   /* dpy */,
+    int                                /* screen */,
+    Colormap                   /*Colormap */
+#endif
+);
+
+int XF86DGAForkApp(
+#if NeedFunctionPrototypes
+    int screen
+#endif
+);
+
+Status XF86DGAQueryDirectVideo(
+#if NeedFunctionPrototypes
+    Display *          /* dpy */,
+    int                        /* screen */,
+    int *              /* flags */
+#endif
+);
+
+Bool XF86DGAViewPortChanged(
+#if NeedFunctionPrototypes
+    Display *          /* dpy */,
+    int                        /* screen */,
+    int                        /* n */
+#endif
+);
+
+
+_XFUNCPROTOEND
+
+#endif /* _XF86DGA_SERVER_ */
+
+#endif /* _XF86DGA_H_ */
diff --git a/Xserver/include/extensions/xf86dgastr.h b/Xserver/include/extensions/xf86dgastr.h
new file mode 100644 (file)
index 0000000..0300df6
--- /dev/null
@@ -0,0 +1,201 @@
+/* $XFree86: xc/include/extensions/xf86dgastr.h,v 3.3 1996/10/18 14:57:25 dawes Exp $ */
+/*
+
+Copyright (c) 1995  Jon Tombs
+Copyright (c) 1995  XFree86 Inc.
+
+*/
+
+#ifndef _XF86DGASTR_H_
+#define _XF86DGASTR_H_
+
+#include "xf86dga.h"
+
+#define XF86DGANAME "XFree86-DGA"
+
+#define XF86DGA_MAJOR_VERSION  1       /* current version numbers */
+#define XF86DGA_MINOR_VERSION  0
+
+typedef struct _XF86DGAQueryVersion {
+    CARD8      reqType;                /* always DGAReqCode */
+    CARD8      dgaReqType;             /* always X_DGAQueryVersion */
+    CARD16     length B16;
+} xXF86DGAQueryVersionReq;
+#define sz_xXF86DGAQueryVersionReq     4
+
+typedef struct {
+    BYTE       type;                   /* X_Reply */
+    BOOL       pad1;
+    CARD16     sequenceNumber B16;
+    CARD32     length B32;
+    CARD16     majorVersion B16;       /* major version of DGA protocol */
+    CARD16     minorVersion B16;       /* minor version of DGA protocol */
+    CARD32     pad2 B32;
+    CARD32     pad3 B32;
+    CARD32     pad4 B32;
+    CARD32     pad5 B32;
+    CARD32     pad6 B32;
+} xXF86DGAQueryVersionReply;
+#define sz_xXF86DGAQueryVersionReply   32
+
+typedef struct _XF86DGAGetVideoLL {
+    CARD8      reqType;                /* always DGAReqCode */
+    CARD8      dgaReqType;             /* always X_XF86DGAGetVideoLL */
+    CARD16     length B16;
+    CARD16     screen B16;
+    CARD16      pad B16;
+} xXF86DGAGetVideoLLReq;
+#define sz_xXF86DGAGetVideoLLReq       8
+
+typedef struct _XF86DGAInstallColormap{
+    CARD8      reqType;
+    CARD8      dgaReqType;
+    CARD16     length B16;
+    CARD16     screen B16;
+    CARD16     pad2; 
+    CARD32     id B32;  /* colormap. */
+} xXF86DGAInstallColormapReq;
+#define sz_xXF86DGAInstallColormapReq        12
+
+
+typedef struct {
+    BYTE       type;
+    BOOL       pad1;
+    CARD16     sequenceNumber B16;
+    CARD32     length B32;
+    CARD32     offset B32;
+    CARD32     width B32;
+    CARD32     bank_size B32;
+    CARD32     ram_size B32;
+    CARD32     pad4 B32;
+    CARD32     pad5 B32;
+} xXF86DGAGetVideoLLReply;
+#define sz_xXF86DGAGetVideoLLReply     32
+
+typedef struct _XF86DGADirectVideo {
+    CARD8      reqType;                /* always DGAReqCode */
+    CARD8      dgaReqType;             /* always X_XF86DGADirectVideo */
+    CARD16     length B16;
+    CARD16     screen B16;
+    CARD16     enable B16;
+} xXF86DGADirectVideoReq;
+#define sz_xXF86DGADirectVideoReq      8
+
+
+typedef struct _XF86DGAGetViewPortSize {
+    CARD8      reqType;                /* always DGAReqCode */
+    CARD8      dgaReqType;             /* always X_XF86DGAGetViewPort */
+    CARD16     length B16;
+    CARD16     screen B16;
+    CARD16      pad B16;
+} xXF86DGAGetViewPortSizeReq;
+#define sz_xXF86DGAGetViewPortSizeReq  8
+
+typedef struct {
+    BYTE       type;
+    BOOL       pad1;
+    CARD16     sequenceNumber B16;
+    CARD32     length B32;
+    CARD32     width B32;
+    CARD32     height B32;
+    CARD32     pad2 B32;
+    CARD32     pad3 B32;
+    CARD32     pad4 B32;
+    CARD32     pad5 B32;
+} xXF86DGAGetViewPortSizeReply;
+#define sz_xXF86DGAGetViewPortSizeReply        32
+
+typedef struct _XF86DGASetViewPort {
+    CARD8      reqType;                /* always DGAReqCode */
+    CARD8      dgaReqType;             /* always X_XF86DGASetViewPort */
+    CARD16     length B16;
+    CARD16     screen B16;
+    CARD16     pad B16;
+    CARD32      x B32;
+    CARD32     y B32;
+} xXF86DGASetViewPortReq;
+#define sz_xXF86DGASetViewPortReq      16
+
+typedef struct _XF86DGAGetVidPage {
+    CARD8      reqType;                /* always DGAReqCode */
+    CARD8      dgaReqType;             /* always X_XF86DGAGetVidPage */
+    CARD16     length B16;
+    CARD16     screen B16;
+    CARD16      pad B16;
+} xXF86DGAGetVidPageReq;
+#define sz_xXF86DGAGetVidPageReq       8
+
+typedef struct {
+    BYTE       type;
+    BOOL       pad1;
+    CARD16     sequenceNumber B16;
+    CARD32     length B32;
+    CARD32     vpage B32;
+    CARD32     pad B32;
+    CARD32     pad2 B32;
+    CARD32     pad3 B32;
+    CARD32     pad4 B32;
+    CARD32     pad5 B32;
+} xXF86DGAGetVidPageReply;
+#define sz_xXF86DGAGetVidPageReply     32
+
+
+typedef struct _XF86DGASetVidPage {
+    CARD8      reqType;                /* always DGAReqCode */
+    CARD8      dgaReqType;             /* always X_XF86DGASetVidPage */
+    CARD16     length B16;
+    CARD16     screen B16;
+    CARD16      vpage B16;
+} xXF86DGASetVidPageReq;
+#define sz_xXF86DGASetVidPageReq       8
+
+
+typedef struct _XF86DGAQueryDirectVideo {
+    CARD8      reqType;                /* always DGAReqCode */
+    CARD8      dgaReqType;             /* always X_DGAQueryVersion */
+    CARD16     length B16;
+    CARD16     screen B16;
+    CARD16      pad B16;
+} xXF86DGAQueryDirectVideoReq;
+#define sz_xXF86DGAQueryDirectVideoReq 8
+
+typedef struct {
+    BYTE       type;
+    BOOL       pad1;
+    CARD16     sequenceNumber B16;
+    CARD32     length B32;
+    CARD32     flags B32;
+    CARD32     pad B32;
+    CARD32     pad2 B32;
+    CARD32     pad3 B32;
+    CARD32     pad4 B32;
+    CARD32     pad5 B32;
+} xXF86DGAQueryDirectVideoReply;
+#define sz_xXF86DGAQueryDirectVideoReply 32
+
+
+typedef struct _XF86DGAViewPortChanged {
+    CARD8      reqType;                /* always DGAReqCode */
+    CARD8      dgaReqType;             /* always X_DGAQueryVersion */
+    CARD16     length B16;
+    CARD16     screen B16;
+    CARD16      n B16;
+} xXF86DGAViewPortChangedReq;
+#define sz_xXF86DGAViewPortChangedReq  8
+
+typedef struct {
+    BYTE       type;
+    BOOL       pad1;
+    CARD16     sequenceNumber B16;
+    CARD32     length B32;
+    CARD32     result B32;
+    CARD32     pad B32;
+    CARD32     pad2 B32;
+    CARD32     pad3 B32;
+    CARD32     pad4 B32;
+    CARD32     pad5 B32;
+} xXF86DGAViewPortChangedReply;
+#define sz_xXF86DGAViewPortChangedReply 32
+
+#endif /* _XF86DGASTR_H_ */
+
diff --git a/Xserver/include/extensions/xf86misc.h b/Xserver/include/extensions/xf86misc.h
new file mode 100644 (file)
index 0000000..ca36f11
--- /dev/null
@@ -0,0 +1,141 @@
+/* $XFree86: xc/include/extensions/xf86misc.h,v 3.6.2.4 1998/02/24 19:05:44 hohndel Exp $ */
+
+/*
+ * Copyright (c) 1995, 1996  The XFree86 Project, Inc
+ */
+
+/* THIS IS NOT AN X CONSORTIUM STANDARD */
+
+#ifndef _XF86MISC_H_
+#define _XF86MISC_H_
+
+#include <X11/Xfuncproto.h>
+
+#define X_XF86MiscQueryVersion         0
+#ifdef _XF86MISC_SAVER_COMPAT_
+#define X_XF86MiscGetSaver             1
+#define X_XF86MiscSetSaver             2
+#endif
+#define X_XF86MiscGetMouseSettings     3
+#define X_XF86MiscGetKbdSettings       4
+#define X_XF86MiscSetMouseSettings     5
+#define X_XF86MiscSetKbdSettings       6
+
+#define XF86MiscNumberEvents           0
+
+#define XF86MiscBadMouseProtocol       0
+#define XF86MiscBadMouseBaudRate       1
+#define XF86MiscBadMouseFlags          2
+#define XF86MiscBadMouseCombo          3
+#define XF86MiscBadKbdType             4
+#define XF86MiscModInDevDisabled       5
+#define XF86MiscModInDevClientNotLocal 6
+#define XF86MiscNumberErrors           (XF86MiscModInDevClientNotLocal + 1)
+
+/* Never renumber these */
+#define MTYPE_MICROSOFT                0
+#define MTYPE_MOUSESYS         1
+#define MTYPE_MMSERIES         2
+#define MTYPE_LOGITECH         3
+#define MTYPE_BUSMOUSE         4
+#define MTYPE_LOGIMAN          5
+#define MTYPE_PS_2             6
+#define MTYPE_MMHIT            7
+#define MTYPE_GLIDEPOINT       8
+#define MTYPE_IMSERIAL         9
+#define MTYPE_THINKING         10
+#define MTYPE_IMPS2            11
+#define MTYPE_THINKINGPS2      12
+#define MTYPE_MMANPLUSPS2      13
+#define MTYPE_GLIDEPOINTPS2    14
+#define MTYPE_NETPS2           15
+#define MTYPE_NETSCROLLPS2     16
+#define MTYPE_SYSMOUSE         17
+#define MTYPE_AUTOMOUSE                18
+
+#define MTYPE_XQUEUE           127
+#define MTYPE_OSMOUSE          126
+
+#define KTYPE_UNKNOWN          0
+#define KTYPE_84KEY            1
+#define KTYPE_101KEY           2
+#define KTYPE_OTHER            3
+#define KTYPE_XQUEUE           4
+
+#define MF_CLEAR_DTR           1
+#define MF_CLEAR_RTS           2
+#define MF_REOPEN              128
+
+#ifndef _XF86MISC_SERVER_
+
+_XFUNCPROTOBEGIN
+
+typedef struct {
+    char*      device;
+    int                type;
+    int                baudrate;
+    int                samplerate;
+    int                resolution;
+    int                buttons;
+    Bool       emulate3buttons;
+    int                emulate3timeout;
+    Bool       chordmiddle;
+    int                flags;
+} XF86MiscMouseSettings;
+
+typedef struct {
+    int                type;
+    int                rate;
+    int                delay;
+    Bool       servnumlock;
+} XF86MiscKbdSettings;
+
+Bool XF86MiscQueryVersion(
+#if NeedFunctionPrototypes
+    Display*           /* dpy */,
+    int*               /* majorVersion */,
+    int*               /* minorVersion */
+#endif
+);
+
+Bool XF86MiscQueryExtension(
+#if NeedFunctionPrototypes
+    Display*           /* dpy */,
+    int*               /* event_base */,
+    int*               /* error_base */
+#endif
+);
+
+Status XF86MiscGetMouseSettings(
+#if NeedFunctionPrototypes
+    Display*                   /* dpy */,
+    XF86MiscMouseSettings*     /* mouse info */
+#endif
+);
+
+Status XF86MiscGetKbdSettings(
+#if NeedFunctionPrototypes
+    Display*                   /* dpy */,
+    XF86MiscKbdSettings*       /* keyboard info */
+#endif
+);
+
+Status XF86MiscSetMouseSettings(
+#if NeedFunctionPrototypes
+    Display*                   /* dpy */,
+    XF86MiscMouseSettings*     /* mouse info */
+#endif
+);
+
+Status XF86MiscSetKbdSettings(
+#if NeedFunctionPrototypes
+    Display*                   /* dpy */,
+    XF86MiscKbdSettings*       /* keyboard info */
+#endif
+);
+
+_XFUNCPROTOEND
+
+#endif
+
+#endif
diff --git a/Xserver/include/extensions/xf86mscstr.h b/Xserver/include/extensions/xf86mscstr.h
new file mode 100644 (file)
index 0000000..da48b94
--- /dev/null
@@ -0,0 +1,156 @@
+/* $XFree86: xc/include/extensions/xf86mscstr.h,v 3.5.2.3 1998/02/24 19:05:45 hohndel Exp $ */
+
+/*
+ * Copyright (c) 1995, 1996  The XFree86 Project, Inc
+ */
+
+/* THIS IS NOT AN X CONSORTIUM STANDARD */
+
+#ifndef _XF86MISCSTR_H_
+#define _XF86MISCSTR_H_
+
+#include "xf86misc.h"
+
+#define XF86MISCNAME           "XFree86-Misc"
+
+#define XF86MISC_MAJOR_VERSION 0       /* current version numbers */
+#define XF86MISC_MINOR_VERSION 4
+
+typedef struct _XF86MiscQueryVersion {
+    CARD8      reqType;                /* always XF86MiscReqCode */
+    CARD8      xf86miscReqType;        /* always X_XF86MiscQueryVersion */
+    CARD16     length B16;
+} xXF86MiscQueryVersionReq;
+#define sz_xXF86MiscQueryVersionReq    4
+
+typedef struct {
+    BYTE       type;                   /* X_Reply */
+    BOOL       pad1;
+    CARD16     sequenceNumber B16;
+    CARD32     length B32;
+    CARD16     majorVersion B16;       /* major version of XFree86-Misc */
+    CARD16     minorVersion B16;       /* minor version of XFree86-Misc */
+    CARD32     pad2 B32;
+    CARD32     pad3 B32;
+    CARD32     pad4 B32;
+    CARD32     pad5 B32;
+    CARD32     pad6 B32;
+} xXF86MiscQueryVersionReply;
+#define sz_xXF86MiscQueryVersionReply  32
+
+#ifdef _XF86MISC_SAVER_COMPAT_
+typedef struct _XF86MiscGetSaver {
+    CARD8       reqType;                /* always XF86MiscReqCode */
+    CARD8       xf86miscReqType;     /* always X_XF86MiscGetSaver */
+    CARD16      length B16; 
+    CARD16      screen B16;
+    CARD16      pad B16;
+} xXF86MiscGetSaverReq;
+#define sz_xXF86MiscGetSaverReq        8
+
+typedef struct _XF86MiscSetSaver {
+    CARD8      reqType;                /* always XF86MiscReqCode */
+    CARD8      xf86miscReqType;        /* always X_XF86MiscSetSaver */
+    CARD16     length B16;
+    CARD16     screen B16;
+    CARD16     pad B16;
+    CARD32     suspendTime B32;
+    CARD32     offTime B32;
+} xXF86MiscSetSaverReq;
+#define sz_xXF86MiscSetSaverReq        16
+
+typedef struct {
+    BYTE       type;
+    BOOL       pad1;
+    CARD16     sequenceNumber B16;
+    CARD32     length B32;
+    CARD32     suspendTime B32;
+    CARD32     offTime B32;
+    CARD32     pad2 B32;
+    CARD32     pad3 B32;
+    CARD32     pad4 B32;
+    CARD32     pad5 B32;
+} xXF86MiscGetSaverReply;
+#define sz_xXF86MiscGetSaverReply      32
+#endif
+
+typedef struct _XF86MiscGetMouseSettings {
+    CARD8      reqType;                /* always XF86MiscReqCode */
+    CARD8      xf86miscReqType;        /* always X_XF86MiscGetMouseSettings */
+    CARD16     length B16;
+} xXF86MiscGetMouseSettingsReq;
+#define sz_xXF86MiscGetMouseSettingsReq        4
+
+typedef struct {
+    BYTE       type;                   /* X_Reply */
+    BOOL       pad1;
+    CARD16     sequenceNumber B16;
+    CARD32     length B32;
+    CARD32     mousetype B32;
+    CARD32     baudrate B32;
+    CARD32     samplerate B32;
+    CARD32     resolution B32;
+    CARD32     buttons B32;
+    BOOL       emulate3buttons;
+    BOOL       chordmiddle;
+    CARD16     pad2 B16;
+    CARD32     emulate3timeout B32;
+    CARD32     flags B32;
+    CARD32     devnamelen B32;         /* strlen(device)+1 */
+} xXF86MiscGetMouseSettingsReply;
+#define sz_xXF86MiscGetMouseSettingsReply      44
+
+typedef struct _XF86MiscGetKbdSettings {
+    CARD8      reqType;                /* always XF86MiscReqCode */
+    CARD8      xf86miscReqType;        /* always X_XF86MiscGetKbdSettings */
+    CARD16     length B16;
+} xXF86MiscGetKbdSettingsReq;
+#define sz_xXF86MiscGetKbdSettingsReq  4
+
+typedef struct {
+    BYTE       type;                   /* X_Reply */
+    BOOL       pad1;
+    CARD16     sequenceNumber B16;
+    CARD32     length B32;
+    CARD32     kbdtype B32;
+    CARD32     rate B32;
+    CARD32     delay B32;
+    BOOL       servnumlock;
+    BOOL       pad2;
+    CARD16     pad3 B16;
+    CARD32     pad4 B32;
+    CARD32     pad5 B32;
+} xXF86MiscGetKbdSettingsReply;
+#define sz_xXF86MiscGetKbdSettingsReply        32
+
+typedef struct _XF86MiscSetMouseSettings {
+    CARD8      reqType;                /* always XF86MiscReqCode */
+    CARD8      xf86miscReqType;        /* always X_XF86MiscSetMouseSettings */
+    CARD16     length B16;
+    CARD32     mousetype B32;
+    CARD32     baudrate B32;
+    CARD32     samplerate B32;
+    CARD32     resolution B32;
+    CARD32     buttons B32;
+    BOOL       emulate3buttons;
+    BOOL       chordmiddle;
+    CARD16     pad2 B16;
+    CARD32     emulate3timeout B32;
+    CARD32     flags B32;
+} xXF86MiscSetMouseSettingsReq;
+#define sz_xXF86MiscSetMouseSettingsReq        36
+
+typedef struct _XF86MiscSetKbdSettings {
+    CARD8      reqType;                /* always XF86MiscReqCode */
+    CARD8      xf86miscReqType;        /* always X_XF86MiscSetKbdSettings */
+    CARD16     length B16;
+    CARD32     kbdtype B32;
+    CARD32     rate B32;
+    CARD32     delay B32;
+    BOOL       servnumlock;
+    BOOL       pad1;
+    CARD16     pad2 B16;
+} xXF86MiscSetKbdSettingsReq;
+#define sz_xXF86MiscSetKbdSettingsReq  20
+
+#endif /* _XF86MISCSTR_H_ */
diff --git a/Xserver/include/extensions/xf86vmode.h b/Xserver/include/extensions/xf86vmode.h
new file mode 100644 (file)
index 0000000..18fe871
--- /dev/null
@@ -0,0 +1,272 @@
+/* $XFree86: xc/include/extensions/xf86vmode.h,v 3.20.2.1 1997/07/13 14:44:57 dawes Exp $ */
+/*
+
+Copyright (c) 1995  Kaleb S. KEITHLEY
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL Kaleb S. KEITHLEY BE LIABLE FOR ANY CLAIM, DAMAGES 
+OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of Kaleb S. KEITHLEY 
+shall not be used in advertising or otherwise to promote the sale, use 
+or other dealings in this Software without prior written authorization
+from Kaleb S. KEITHLEY
+
+*/
+/* $XConsortium: xf86vmode.h /main/9 1996/10/26 21:38:11 kaleb $ */
+
+/* THIS IS NOT AN X CONSORTIUM STANDARD */
+
+#ifndef _XF86VIDMODE_H_
+#define _XF86VIDMODE_H_
+
+#include <X11/Xfuncproto.h>
+#include <X11/Xmd.h>
+
+#define X_XF86VidModeQueryVersion      0
+#define X_XF86VidModeGetModeLine       1
+#define X_XF86VidModeModModeLine       2
+#define X_XF86VidModeSwitchMode                3
+#define X_XF86VidModeGetMonitor                4
+#define X_XF86VidModeLockModeSwitch    5
+#define X_XF86VidModeGetAllModeLines   6
+#define X_XF86VidModeAddModeLine       7
+#define X_XF86VidModeDeleteModeLine    8
+#define X_XF86VidModeValidateModeLine  9
+#define X_XF86VidModeSwitchToMode      10
+#define X_XF86VidModeGetViewPort       11
+#define X_XF86VidModeSetViewPort       12
+
+#ifdef XF86VIDMODE_EVENTS
+#define XF86VidModeNotify              0
+#define XF86VidModeNumberEvents                (XF86VidModeNotify + 1)
+
+#define XF86VidModeNotifyMask          0x00000001
+
+#define XF86VidModeNonEvent            0
+#define XF86VidModeModeChange          1
+#else
+#define XF86VidModeNumberEvents                0
+#endif
+
+#define XF86VidModeBadClock            0
+#define XF86VidModeBadHTimings         1
+#define XF86VidModeBadVTimings         2
+#define XF86VidModeModeUnsuitable      3
+#define XF86VidModeExtensionDisabled   4
+#define XF86VidModeClientNotLocal      5
+#define XF86VidModeZoomLocked          6
+#define XF86VidModeNumberErrors                (XF86VidModeZoomLocked + 1)
+
+#ifndef _XF86VIDMODE_SERVER_
+
+typedef struct {
+    unsigned short     hdisplay;
+    unsigned short     hsyncstart;
+    unsigned short     hsyncend;
+    unsigned short     htotal;
+    unsigned short     vdisplay;
+    unsigned short     vsyncstart;
+    unsigned short     vsyncend;
+    unsigned short     vtotal;
+    unsigned int       flags;
+    int                        privsize;
+#if defined(__cplusplus) || defined(c_plusplus)
+    /* private is a C++ reserved word */
+    INT32              *c_private;
+#else
+    INT32              *private;
+#endif
+} XF86VidModeModeLine;
+
+typedef struct {
+    unsigned int       dotclock;
+    unsigned short     hdisplay;
+    unsigned short     hsyncstart;
+    unsigned short     hsyncend;
+    unsigned short     htotal;
+    unsigned short     vdisplay;
+    unsigned short     vsyncstart;
+    unsigned short     vsyncend;
+    unsigned short     vtotal;
+    unsigned int       flags;
+    int                        privsize;
+#if defined(__cplusplus) || defined(c_plusplus)
+    /* private is a C++ reserved word */
+    INT32              *c_private;
+#else
+    INT32              *private;
+#endif
+} XF86VidModeModeInfo;
+
+typedef struct {
+    float              hi;
+    float              lo;
+} XF86VidModeSyncRange;
+
+typedef struct {
+    char*                      vendor;
+    char*                      model;
+    float                      EMPTY;
+    unsigned char              nhsync;
+    XF86VidModeSyncRange*      hsync;
+    unsigned char              nvsync;
+    XF86VidModeSyncRange*      vsync;
+} XF86VidModeMonitor;
+    
+typedef struct {
+    int type;                  /* of event */
+    unsigned long serial;      /* # of last request processed by server */
+    Bool send_event;           /* true if this came from a SendEvent req */
+    Display *display;          /* Display the event was read from */
+    Window root;               /* root window of event screen */
+    int state;                 /* What happened */
+    int kind;                  /* What happened */
+    Bool forced;               /* extents of new region */
+    Time time;                 /* event timestamp */
+} XF86VidModeNotifyEvent;
+
+#define XF86VidModeSelectNextMode(disp, scr) \
+       XF86VidModeSwitchMode(disp, scr, 1)
+#define XF86VidModeSelectPrevMode(disp, scr) \
+       XF86VidModeSwitchMode(disp, scr, -1)
+
+_XFUNCPROTOBEGIN
+
+Bool XF86VidModeQueryVersion(
+#if NeedFunctionPrototypes
+    Display*           /* dpy */,
+    int*               /* majorVersion */,
+    int*               /* minorVersion */
+#endif
+);
+
+Bool XF86VidModeQueryExtension(
+#if NeedFunctionPrototypes
+    Display*           /* dpy */,
+    int*               /* event_base */,
+    int*               /* error_base */
+#endif
+);
+
+Bool XF86VidModeGetModeLine(
+#if NeedFunctionPrototypes
+    Display*                   /* dpy */,
+    int                                /* screen */,
+    int*                       /* dotclock */,
+    XF86VidModeModeLine*       /* modeline */
+#endif
+);
+
+Bool XF86VidModeGetAllModeLines(
+#if NeedFunctionPrototypes
+    Display*                   /* dpy */,
+    int                                /* screen */,
+    int*                       /* modecount */,
+    XF86VidModeModeInfo***     /* modelinesPtr */
+#endif
+);
+
+Bool XF86VidModeAddModeLine(
+#if NeedFunctionPrototypes
+    Display*                   /* dpy */,
+    int                                /* screen */,
+    XF86VidModeModeInfo*       /* new modeline */,
+    XF86VidModeModeInfo*       /* after modeline */
+#endif
+);
+
+Bool XF86VidModeDeleteModeLine(
+#if NeedFunctionPrototypes
+    Display*                   /* dpy */,
+    int                                /* screen */,
+    XF86VidModeModeInfo*       /* modeline */
+#endif
+);
+
+Bool XF86VidModeModModeLine(
+#if NeedFunctionPrototypes
+    Display*                   /* dpy */,
+    int                                /* screen */,
+    XF86VidModeModeLine*       /* modeline */
+#endif
+);
+
+Status XF86VidModeValidateModeLine(
+#if NeedFunctionPrototypes
+    Display*                   /* dpy */,
+    int                                /* screen */,
+    XF86VidModeModeInfo*       /* modeline */
+#endif
+);
+
+Bool XF86VidModeSwitchMode(
+#if NeedFunctionPrototypes
+    Display*           /* dpy */,
+    int                        /* screen */,
+    int                        /* zoom */
+#endif
+);
+
+Bool XF86VidModeSwitchToMode(
+#if NeedFunctionPrototypes
+    Display*                   /* dpy */,
+    int                                /* screen */,
+    XF86VidModeModeInfo*       /* modeline */
+#endif
+);
+
+Bool XF86VidModeLockModeSwitch(
+#if NeedFunctionPrototypes
+    Display*           /* dpy */,
+    int                        /* screen */,
+    int                        /* lock */
+#endif
+);
+
+Bool XF86VidModeGetMonitor(
+#if NeedFunctionPrototypes
+    Display*           /* dpy */,
+    int                        /* screen */,
+    XF86VidModeMonitor*        /* monitor */
+#endif
+);
+
+Bool XF86VidModeGetViewPort(
+#if NeedFunctionPrototypes
+    Display*           /* dpy */,
+    int                        /* screen */,
+    int*               /* x return */,
+    int*               /* y return */
+#endif
+);
+
+Bool XF86VidModeSetViewPort(
+#if NeedFunctionPrototypes
+    Display*           /* dpy */,
+    int                        /* screen */,
+    int                        /* x */,
+    int                        /* y */
+#endif
+);
+
+_XFUNCPROTOEND
+
+#endif
+
+#endif
diff --git a/Xserver/include/extensions/xf86vmstr.h b/Xserver/include/extensions/xf86vmstr.h
new file mode 100644 (file)
index 0000000..bfc05f3
--- /dev/null
@@ -0,0 +1,278 @@
+/* $XFree86: xc/include/extensions/xf86vmstr.h,v 3.18.2.1 1997/05/25 14:13:37 dawes Exp $ */
+/*
+
+Copyright (c) 1995  Kaleb S. KEITHLEY
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL Kaleb S. KEITHLEY BE LIABLE FOR ANY CLAIM, DAMAGES 
+OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of Kaleb S. KEITHLEY 
+shall not be used in advertising or otherwise to promote the sale, use 
+or other dealings in this Software without prior written authorization
+from Kaleb S. KEITHLEY
+
+*/
+/* $XConsortium: xf86vmstr.h /main/10 1996/10/26 21:38:17 kaleb $ */
+
+/* THIS IS NOT AN X CONSORTIUM STANDARD */
+
+#ifndef _XF86VIDMODESTR_H_
+#define _XF86VIDMODESTR_H_
+
+#include "xf86vmode.h"
+
+#define XF86VIDMODENAME "XFree86-VidModeExtension"
+
+#define XF86VIDMODE_MAJOR_VERSION      0       /* current version numbers */
+#define XF86VIDMODE_MINOR_VERSION      8
+/*
+ * major version 0 == uses parameter-to-wire functions in XFree86 libXxf86vm.
+ * major version 1 == uses parameter-to-wire functions hard-coded in xvidtune
+ *                    client.
+ */
+
+typedef struct _XF86VidModeQueryVersion {
+    CARD8      reqType;                /* always XF86VidModeReqCode */
+    CARD8      xf86vidmodeReqType;     /* always X_XF86VidModeQueryVersion */
+    CARD16     length B16;
+} xXF86VidModeQueryVersionReq;
+#define sz_xXF86VidModeQueryVersionReq 4
+
+typedef struct {
+    BYTE       type;                   /* X_Reply */
+    BOOL       pad1;
+    CARD16     sequenceNumber B16;
+    CARD32     length B32;
+    CARD16     majorVersion B16;       /* major version of XF86VidMode */
+    CARD16     minorVersion B16;       /* minor version of XF86VidMode */
+    CARD32     pad2 B32;
+    CARD32     pad3 B32;
+    CARD32     pad4 B32;
+    CARD32     pad5 B32;
+    CARD32     pad6 B32;
+} xXF86VidModeQueryVersionReply;
+#define sz_xXF86VidModeQueryVersionReply       32
+
+typedef struct _XF86VidModeGetModeLine {
+    CARD8      reqType;                /* always XF86VidModeReqCode */
+    CARD8      xf86vidmodeReqType;
+    CARD16     length B16;
+    CARD16     screen B16;
+    CARD16     pad B16;
+} xXF86VidModeGetModeLineReq,
+  xXF86VidModeGetAllModeLinesReq,
+  xXF86VidModeGetMonitorReq,
+  xXF86VidModeGetViewPortReq;
+#define sz_xXF86VidModeGetModeLineReq          8
+#define sz_xXF86VidModeGetAllModeLinesReq      8
+#define sz_xXF86VidModeGetMonitorReq           8
+#define sz_xXF86VidModeGetViewPortReq          8
+
+typedef struct {
+    BYTE       type;                   /* X_Reply */
+    BOOL       pad1;
+    CARD16     sequenceNumber B16;
+    CARD32     length B32;
+    CARD32     dotclock B32;
+    CARD16     hdisplay B16;
+    CARD16     hsyncstart B16;
+    CARD16     hsyncend B16;
+    CARD16     htotal B16;
+    CARD16     vdisplay B16;
+    CARD16     vsyncstart B16;
+    CARD16     vsyncend B16;
+    CARD16     vtotal B16;
+    CARD32     flags B32;
+    CARD32     privsize B32;
+} xXF86VidModeGetModeLineReply;
+#define sz_xXF86VidModeGetModeLineReply        36
+
+typedef struct {
+    CARD32     dotclock B32;
+    CARD16     hdisplay B16;
+    CARD16     hsyncstart B16;
+    CARD16     hsyncend B16;
+    CARD16     htotal B16;
+    CARD16     vdisplay B16;
+    CARD16     vsyncstart B16;
+    CARD16     vsyncend B16;
+    CARD16     vtotal B16;
+    CARD32     flags B32;
+    CARD32     privsize B32;
+} xXF86VidModeModeInfo;
+
+typedef struct {
+    BYTE       type;                   /* X_Reply */
+    BOOL       pad1;
+    CARD16     sequenceNumber B16;
+    CARD32     length B32;
+    CARD32     modecount B32;
+    CARD32     pad2 B32;
+    CARD32     pad3 B32;
+    CARD32     pad4 B32;
+    CARD32     pad5 B32;
+    CARD32     pad6 B32;
+} xXF86VidModeGetAllModeLinesReply;
+#define sz_xXF86VidModeGetAllModeLinesReply    32
+
+typedef struct _XF86VidModeAddModeLine {
+    CARD8      reqType;                /* always XF86VidModeReqCode */
+    CARD8      xf86vidmodeReqType;     /* always X_XF86VidModeAddMode */
+    CARD16     length B16;
+    CARD32     screen B32;             /* could be CARD16 but need the pad */
+    CARD32     dotclock B32;
+    CARD16     hdisplay B16;
+    CARD16     hsyncstart B16;
+    CARD16     hsyncend B16;
+    CARD16     htotal B16;
+    CARD16     vdisplay B16;
+    CARD16     vsyncstart B16;
+    CARD16     vsyncend B16;
+    CARD16     vtotal B16;
+    CARD32     flags B32;
+    CARD32     privsize B32;
+    CARD32     after_dotclock B32;
+    CARD16     after_hdisplay B16;
+    CARD16     after_hsyncstart B16;
+    CARD16     after_hsyncend B16;
+    CARD16     after_htotal B16;
+    CARD16     after_vdisplay B16;
+    CARD16     after_vsyncstart B16;
+    CARD16     after_vsyncend B16;
+    CARD16     after_vtotal B16;
+    CARD32     after_flags B32;
+} xXF86VidModeAddModeLineReq;
+#define sz_xXF86VidModeAddModeLineReq  60
+
+typedef struct _XF86VidModeModModeLine {
+    CARD8      reqType;                /* always XF86VidModeReqCode */
+    CARD8      xf86vidmodeReqType;     /* always X_XF86VidModeModModeLine */
+    CARD16     length B16;
+    CARD32     screen B32;             /* could be CARD16 but need the pad */
+    CARD16     hdisplay B16;
+    CARD16     hsyncstart B16;
+    CARD16     hsyncend B16;
+    CARD16     htotal B16;
+    CARD16     vdisplay B16;
+    CARD16     vsyncstart B16;
+    CARD16     vsyncend B16;
+    CARD16     vtotal B16;
+    CARD32     flags B32;
+    CARD32     privsize B32;
+} xXF86VidModeModModeLineReq;
+#define sz_xXF86VidModeModModeLineReq  32
+
+typedef struct _XF86VidModeValidateModeLine {
+    CARD8      reqType;                /* always XF86VidModeReqCode */
+    CARD8      xf86vidmodeReqType;
+    CARD16     length B16;
+    CARD32     screen B32;             /* could be CARD16 but need the pad */
+    CARD32     dotclock B32;
+    CARD16     hdisplay B16;
+    CARD16     hsyncstart B16;
+    CARD16     hsyncend B16;
+    CARD16     htotal B16;
+    CARD16     vdisplay B16;
+    CARD16     vsyncstart B16;
+    CARD16     vsyncend B16;
+    CARD16     vtotal B16;
+    CARD32     flags B32;
+    CARD32     privsize B32;
+} xXF86VidModeDeleteModeLineReq,
+  xXF86VidModeValidateModeLineReq,
+  xXF86VidModeSwitchToModeReq;
+#define sz_xXF86VidModeDeleteModeLineReq       36
+#define sz_xXF86VidModeValidateModeLineReq     36
+#define sz_xXF86VidModeSwitchToModeReq         36
+
+typedef struct _XF86VidModeSwitchMode {
+    CARD8      reqType;                /* always XF86VidModeReqCode */
+    CARD8      xf86vidmodeReqType;     /* always X_XF86VidModeSwitchMode */
+    CARD16     length B16;
+    CARD16     screen B16;
+    CARD16     zoom B16;
+} xXF86VidModeSwitchModeReq;
+#define sz_xXF86VidModeSwitchModeReq   8
+
+typedef struct _XF86VidModeLockModeSwitch {
+    CARD8      reqType;                /* always XF86VidModeReqCode */
+    CARD8      xf86vidmodeReqType;     /* always X_XF86VidModeLockModeSwitch */
+    CARD16     length B16;
+    CARD16     screen B16;
+    CARD16     lock B16;
+} xXF86VidModeLockModeSwitchReq;
+#define sz_xXF86VidModeLockModeSwitchReq       8
+
+typedef struct {
+    BYTE       type;                   /* X_Reply */
+    BOOL       pad1;
+    CARD16     sequenceNumber B16;
+    CARD32     length B32;
+    CARD32     status B32;
+    CARD32     pad2 B32;
+    CARD32     pad3 B32;
+    CARD32     pad4 B32;
+    CARD32     pad5 B32;
+    CARD32     pad6 B32;
+} xXF86VidModeValidateModeLineReply;
+#define sz_xXF86VidModeValidateModeLineReply   32
+
+typedef struct {
+    BYTE       type;                   /* X_Reply */
+    BOOL       pad1;
+    CARD16     sequenceNumber B16;
+    CARD32     length B32;
+    CARD8      vendorLength;
+    CARD8      modelLength;
+    CARD8      nhsync;
+    CARD8      nvsync;
+    CARD32     pad2 B32;
+    CARD32     pad3 B32;
+    CARD32     pad4 B32;
+    CARD32     pad5 B32;
+    CARD32     pad6 B32;
+} xXF86VidModeGetMonitorReply;
+#define sz_xXF86VidModeGetMonitorReply 32
+
+typedef struct {
+    BYTE       type;
+    BOOL       pad1;
+    CARD16     sequenceNumber B16;
+    CARD32     length B32;
+    CARD32     x B32;
+    CARD32     y B32;
+    CARD32     pad2 B32;
+    CARD32     pad3 B32;
+    CARD32     pad4 B32;
+    CARD32     pad5 B32;
+} xXF86VidModeGetViewPortReply;
+#define sz_xXF86VidModeGetViewPortReply        32
+
+typedef struct _XF86VidModeSetViewPort {
+    CARD8      reqType;                /* always VidModeReqCode */
+    CARD8      xf86vidmodeReqType;     /* always X_XF86VidModeSetViewPort */
+    CARD16     length B16;
+    CARD16     screen B16;
+    CARD16     pad B16;
+    CARD32      x B32;
+    CARD32     y B32;
+} xXF86VidModeSetViewPortReq;
+#define sz_xXF86VidModeSetViewPortReq  16
+
+#endif /* _XF86VIDMODESTR_H_ */
diff --git a/Xserver/include/extensions/xtestext1.h b/Xserver/include/extensions/xtestext1.h
new file mode 100644 (file)
index 0000000..0b7e08b
--- /dev/null
@@ -0,0 +1,326 @@
+/*
+ * xtestext1.h
+ *
+ * X11 Input Synthesis Extension include file
+ */
+
+/*
+
+
+Copyright (c) 1986, 1987, 1988   X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+
+Copyright 1986, 1987, 1988 by Hewlett-Packard Corporation
+
+Permission to use, copy, modify, and distribute this
+software and its documentation for any purpose and without
+fee is hereby granted, provided that the above copyright
+notice appear in all copies and that both that copyright
+notice and this permission notice appear in supporting
+documentation, and that the name of Hewlett-Packard not be used in
+advertising or publicity pertaining to distribution of the
+software without specific, written prior permission.
+
+Hewlett-Packard makes no representations about the 
+suitability of this software for any purpose.  It is provided 
+"as is" without express or implied warranty.
+
+This software is not subject to any license of the American
+Telephone and Telegraph Company or of the Regents of the
+University of California.
+
+*/
+
+/*
+ * the typedefs for CARD8, CARD16, and CARD32 are defined in Xmd.h
+ */
+
+/*
+ * used in the XTestPressButton and XTestPressKey functions
+ */
+#define XTestPRESS                      1 << 0
+#define XTestRELEASE                    1 << 1
+#define XTestSTROKE                     1 << 2
+
+/*
+ * When doing a key or button stroke, the number of milliseconds
+ * to delay between the press and the release of a key or button
+ * in the XTestPressButton and XTestPressKey functions.
+ */
+
+#define XTestSTROKE_DELAY_TIME         10
+
+/*
+ * used in the XTestGetInput function
+ */
+#define XTestEXCLUSIVE                  1 << 0
+#define XTestPACKED_ACTIONS             1 << 1
+#define XTestPACKED_MOTION              1 << 2
+
+/*
+ * used in the XTestFakeInput function
+ */
+#define XTestFAKE_ACK_NOT_NEEDED        0
+#define XTestFAKE_ACK_REQUEST           1
+
+/*
+ * used in the XTest extension initialization routine
+ */
+#define XTestEXTENSION_NAME             "XTestExtension1"
+#define XTestEVENT_COUNT                2
+
+/*
+ * XTest request type values 
+ *
+ * used in the XTest extension protocol requests
+ */
+#define X_TestFakeInput                  1
+#define X_TestGetInput                   2
+#define X_TestStopInput                  3
+#define X_TestReset                      4
+#define X_TestQueryInputSize             5
+
+/*
+ * This defines the maximum size of a list of input actions
+ * to be sent to the server.  It should always be a multiple of
+ * 4 so that the entire xTestFakeInputReq structure size is a
+ * multiple of 4.
+ */
+#define XTestMAX_ACTION_LIST_SIZE       64
+
+typedef struct {
+        CARD8   reqType;        /* always XTestReqCode             */
+        CARD8   XTestReqType;   /* always X_TestFakeInput           */
+        CARD16  length B16;     /* 2 + XTestMAX_ACTION_LIST_SIZE/4 */
+        CARD32  ack B32;
+        CARD8   action_list[XTestMAX_ACTION_LIST_SIZE];
+} xTestFakeInputReq;
+#define sz_xTestFakeInputReq (XTestMAX_ACTION_LIST_SIZE + 8)
+
+typedef struct {
+        CARD8   reqType;        /* always XTestReqCode  */
+        CARD8   XTestReqType;   /* always X_TestGetInput */
+        CARD16  length B16;     /* 2                    */
+        CARD32  mode B32;
+} xTestGetInputReq;
+#define sz_xTestGetInputReq 8
+
+typedef struct {
+        CARD8   reqType;        /* always XTestReqCode   */
+        CARD8   XTestReqType;   /* always X_TestStopInput */
+        CARD16  length B32;     /* 1                     */
+} xTestStopInputReq;
+#define sz_xTestStopInputReq 4
+
+typedef struct {
+        CARD8   reqType;        /* always XTestReqCode */
+        CARD8   XTestReqType;   /* always X_TestReset   */
+        CARD16  length B16;     /* 1                   */
+} xTestResetReq;
+#define sz_xTestResetReq 4
+
+typedef struct {
+        CARD8   reqType;        /* always XTestReqCode        */
+        CARD8   XTestReqType;   /* always X_TestQueryInputSize */
+        CARD16  length B16;     /* 1                          */
+} xTestQueryInputSizeReq;
+#define sz_xTestQueryInputSizeReq 4
+
+/*
+ * This is the definition of the reply for the xTestQueryInputSize
+ * request.  It should remain the same minimum size as other replies
+ * (32 bytes).
+ */
+typedef struct {
+        CARD8   type;           /* always X_Reply  */
+        CARD8   pad1;
+        CARD16  sequenceNumber B16;
+        CARD32  length B32;     /* always 0 */
+        CARD32  size_return B32;
+        CARD32  pad2 B32;
+        CARD32  pad3 B32;
+        CARD32  pad4 B32;
+        CARD32  pad5 B32;
+        CARD32  pad6 B32;
+} xTestQueryInputSizeReply;
+
+/*
+ * This is the definition for the input action wire event structure.
+ * This event is sent to the client when the server has one or
+ * more user input actions to report to the client.  It must
+ * remain the same size as all other wire events (32 bytes).
+ */
+#define XTestACTIONS_SIZE      28
+
+typedef struct {
+        CARD8   type;           /* always XTestInputActionType */
+        CARD8   pad00;
+        CARD16  sequenceNumber B16;
+        CARD8   actions[XTestACTIONS_SIZE];
+} xTestInputActionEvent;
+
+/*
+ * This is the definition for the xTestFakeAck wire event structure.
+ * This event is sent to the client when the server has completely
+ * processed its input action buffer, and is ready for more.
+ * It must remain the same size as all other wire events (32 bytes).
+ */
+typedef struct {
+        CARD8   type;           /* always XTestFakeAckType */
+        CARD8   pad00;
+        CARD16  sequenceNumber B16;
+        CARD32  pad02 B32;
+        CARD32  pad03 B32;
+        CARD32  pad04 B32;
+        CARD32  pad05 B32;
+        CARD32  pad06 B32;
+        CARD32  pad07 B32;
+        CARD32  pad08 B32;
+} xTestFakeAckEvent;
+
+/*
+ * The server side of this extension does not (and should not) have
+ * definitions for Display and Window.  The ifndef allows the server
+ * side of the extension to ignore the following typedefs.
+ */
+#ifndef XTestSERVER_SIDE
+/*
+ * This is the definition for the input action host format event structure.
+ * This is the form that a client using this extension will see when
+ * it receives an input action event.
+ */
+typedef struct {
+        int     type;           /* always XTestInputActionType */
+       Display *display;
+       Window  window;
+        CARD8   actions[XTestACTIONS_SIZE];
+} XTestInputActionEvent;
+
+/*
+ * This is the definition for the xTestFakeAck host format event structure.
+ * This is the form that a client using this extension will see when
+ * it receives an XTestFakeAck event.
+ */
+typedef struct {
+        int     type;           /* always XTestFakeAckType */
+       Display *display;
+       Window  window;
+} XTestFakeAckEvent;
+#endif
+
+/*
+ * This is the definition for the format of the header byte
+ * in the input action structures.
+ */
+#define XTestACTION_TYPE_MASK   0x03    /* bits 0 and 1          */
+#define XTestKEY_STATE_MASK     0x04    /* bit 2 (key action)    */
+#define XTestX_SIGN_BIT_MASK    0x04    /* bit 2 (motion action) */
+#define XTestY_SIGN_BIT_MASK    0x08    /* bit 3 (motion action) */
+#define XTestDEVICE_ID_MASK     0xf0    /* bits 4 through 7      */
+
+#define XTestMAX_DEVICE_ID     0x0f
+#define XTestPackDeviceID(x)   (((x) & XTestMAX_DEVICE_ID) << 4)
+#define XTestUnpackDeviceID(x) (((x) & XTestDEVICE_ID_MASK) >> 4)
+
+/*
+ * These are the possible action types.
+ */
+#define XTestDELAY_ACTION       0
+#define XTestKEY_ACTION         1
+#define XTestMOTION_ACTION      2
+#define XTestJUMP_ACTION        3
+
+/*
+ * These are the definitions for key/button motion input actions.
+ */
+#define XTestKEY_UP             0x04
+#define XTestKEY_DOWN           0x00
+
+typedef struct {
+        CARD8   header;         /* which device, key up/down */
+        CARD8   keycode;        /* which key/button to move  */
+        CARD16  delay_time B16; /* how long to delay (in ms) */
+} XTestKeyInfo;
+
+/*
+ * This is the definition for pointer jump input actions.
+ */
+typedef struct {
+        CARD8   header;         /* which pointer             */
+        CARD8   pad1;           /* unused padding byte       */
+        CARD16  jumpx B16;      /* x coord to jump to        */
+        CARD16  jumpy B16;      /* y coord to jump to        */
+        CARD16  delay_time B16; /* how long to delay (in ms) */
+} XTestJumpInfo;
+
+/*
+ * These are the definitions for pointer relative motion input
+ * actions.
+ *
+ * The sign bits for the x and y relative motions are contained
+ * in the header byte.  The x and y relative motions are packed
+ * into one byte to make things fit in 32 bits.  If the relative
+ * motion range is larger than +/-15, use the pointer jump action.
+ */
+#define XTestMOTION_MAX            15
+#define XTestMOTION_MIN            -15
+
+#define XTestX_NEGATIVE            0x04
+#define XTestY_NEGATIVE            0x08
+
+#define XTestX_MOTION_MASK         0x0f
+#define XTestY_MOTION_MASK         0xf0
+
+#define XTestPackXMotionValue(x)   ((x) & XTestX_MOTION_MASK)
+#define XTestPackYMotionValue(x)   (((x) << 4) & XTestY_MOTION_MASK)
+
+#define XTestUnpackXMotionValue(x) ((x) & XTestX_MOTION_MASK)
+#define XTestUnpackYMotionValue(x) (((x) & XTestY_MOTION_MASK) >> 4)
+
+typedef struct {
+        CARD8   header;         /* which pointer             */
+        CARD8   motion_data;    /* x,y relative motion       */
+        CARD16  delay_time B16; /* how long to delay (in ms) */
+} XTestMotionInfo;
+
+/*
+ * These are the definitions for a long delay input action.  It is 
+ * used when more than XTestSHORT_DELAY_TIME milliseconds of delay
+ * (approximately one minute) is needed.
+ *
+ * The device ID for a delay is always set to XTestDELAY_DEVICE_ID.
+ * This guarantees that a header byte with a value of 0 is not
+ * a valid header, so it can be used as a flag to indicate that
+ * there are no more input actions in an XTestInputAction event.
+ */
+
+#define XTestSHORT_DELAY_TIME  0xffff
+#define XTestDELAY_DEVICE_ID    0x0f   
+
+typedef struct {
+        CARD8   header;         /* always XTestDELAY_DEVICE_ID */
+        CARD8   pad1;           /* unused padding byte         */
+        CARD16  pad2 B16;       /* unused padding word         */
+        CARD32  delay_time B32; /* how long to delay (in ms)   */
+} XTestDelayInfo;
diff --git a/Xserver/include/extensions/xteststr.h b/Xserver/include/extensions/xteststr.h
new file mode 100644 (file)
index 0000000..25aaad0
--- /dev/null
@@ -0,0 +1,121 @@
+/* $XConsortium: xteststr.h,v 1.9 94/04/17 20:11:30 rws Exp $ */
+/*
+
+Copyright (c) 1992  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+*/
+
+#ifndef _XTESTSTR_H_
+#define _XTESTSTR_H_
+
+#define Window CARD32
+#define Time CARD32
+#define Cursor CARD32
+
+#define XTestCurrentCursor ((Cursor)1)
+
+typedef struct {
+    CARD8      reqType;        /* always XTestReqCode */
+    CARD8      xtReqType;      /* always X_XTestGetVersion */
+    CARD16     length B16;
+    CARD8      majorVersion;
+    CARD8      pad;
+    CARD16     minorVersion B16;
+} xXTestGetVersionReq;
+#define sz_xXTestGetVersionReq 8
+
+typedef struct {
+    BYTE       type;                   /* X_Reply */
+    CARD8      majorVersion;
+    CARD16     sequenceNumber B16;
+    CARD32     length B32;
+    CARD16     minorVersion B16;
+    CARD16     pad0 B16;
+    CARD32     pad1 B32;
+    CARD32     pad2 B32;
+    CARD32     pad3 B32;
+    CARD32     pad4 B32;
+    CARD32     pad5 B32;
+} xXTestGetVersionReply;
+#define sz_xXTestGetVersionReply 32
+
+typedef struct {
+    CARD8      reqType;        /* always XTestReqCode */
+    CARD8      xtReqType;      /* always X_XTestCompareCursor */
+    CARD16     length B16;
+    Window     window B32;
+    Cursor     cursor B32;
+} xXTestCompareCursorReq;
+#define sz_xXTestCompareCursorReq 12
+
+typedef struct {
+    BYTE       type;                   /* X_Reply */
+    BOOL       same;
+    CARD16     sequenceNumber B16;
+    CARD32     length B32;
+    CARD32     pad0 B32;
+    CARD32     pad1 B32;
+    CARD32     pad2 B32;
+    CARD32     pad3 B32;
+    CARD32     pad4 B32;
+    CARD32     pad5 B32;
+} xXTestCompareCursorReply;
+#define sz_xXTestCompareCursorReply 32
+
+/* used only on the client side */
+typedef struct {
+    CARD8      reqType;        /* always XTestReqCode */
+    CARD8      xtReqType;      /* always X_XTestFakeInput */
+    CARD16     length B16;
+    BYTE       type;
+    BYTE       detail;
+    CARD16     pad0 B16;
+    Time       time B32;
+    Window     root B32;
+    CARD32     pad1 B32;
+    CARD32     pad2 B32;
+    INT16      rootX B16, rootY B16;
+    CARD32     pad3 B32;
+    CARD16     pad4 B16;
+    CARD8      pad5;
+    CARD8      deviceid;
+} xXTestFakeInputReq;
+#define sz_xXTestFakeInputReq 36
+
+typedef struct {
+    CARD8      reqType;        /* always XTestReqCode */
+    CARD8      xtReqType;      /* always X_XTestGrabControl */
+    CARD16     length B16;
+    BOOL       impervious;
+    CARD8      pad0;
+    CARD8      pad1;
+    CARD8      pad2;
+} xXTestGrabControlReq;
+#define sz_xXTestGrabControlReq 8
+
+#undef Window
+#undef Time
+#undef Cursor
+
+#endif /* _XTESTSTR_H_ */
diff --git a/Xserver/include/fonts/FS.h b/Xserver/include/fonts/FS.h
new file mode 100644 (file)
index 0000000..23d83c4
--- /dev/null
@@ -0,0 +1,136 @@
+/* $TOG: FS.h /main/9 1997/06/13 13:01:10 barstow $ */
+
+/*
+ * Copyright 1990, 1991 Network Computing Devices;
+ * Portions Copyright 1987 by Digital Equipment Corporation 
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and
+ * its documentation for any purpose is hereby granted without fee, provided
+ * that the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the names of Network Computing Devices or Digital
+ * not be used in advertising or publicity pertaining to distribution
+ * of the software without specific, written prior permission.
+ * Network Computing Devices and Digital make no representations 
+ * about the suitability of this software for any purpose.  It is provided 
+ * "as is" without express or implied warranty.
+ *
+ * NETWORK COMPUTING DEVICES AND DIGITAL DISCLAIM ALL WARRANTIES WITH
+ * REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL NETWORK COMPUTING DEVICES
+ * OR DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
+ * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
+ * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
+ * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
+ * THIS SOFTWARE.
+ */
+
+/*
+
+Portions Copyright (c) 1987, 1994  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+*/
+
+#ifndef _FS_H_
+#define        _FS_H_
+
+#include "fsmasks.h"
+
+#define        FS_PROTOCOL             2
+#define        FS_PROTOCOL_MINOR       0
+
+typedef unsigned long FSID;
+
+#ifndef X_PROTOCOL
+/* protocol familes */
+#define FamilyInternet          0
+#define FamilyDECnet            1
+#define FamilyChaos             2
+
+typedef unsigned long Mask;
+
+typedef FSID   Font;
+typedef FSID   AccContext;
+
+typedef unsigned int    FSDrawDirection;
+#endif
+
+#ifndef None
+#define        None            0L
+#endif
+
+#define        LeftToRightDrawDirection        0
+#define        RightToLeftDrawDirection        1
+
+/* font info flags */
+#define        FontInfoAllCharsExist           (1L << 0)
+#define        FontInfoInkInside               (1L << 1)
+#define        FontInfoHorizontalOverlap       (1L << 2)
+
+/* auth status flags */
+#define        AuthSuccess     0
+#define        AuthContinue    1
+#define        AuthBusy        2
+#define        AuthDenied      3
+
+/* property types */
+#define        PropTypeString          0
+#define        PropTypeUnsigned        1
+#define        PropTypeSigned          2
+
+#ifndef LSBFirst
+/* byte order */
+#define LSBFirst                0
+#define MSBFirst                1
+#endif
+
+/* event masks */
+#define        CatalogueChangeNotifyMask       (1L << 0)
+#define        FontChangeNotifyMask            (1L << 1)
+
+/* errors */
+#define        FSSuccess               -1
+#define        FSBadRequest            0
+#define        FSBadFormat             1
+#define        FSBadFont               2
+#define        FSBadRange              3
+#define        FSBadEventMask          4
+#define        FSBadAccessContext      5
+#define        FSBadIDChoice           6
+#define        FSBadName               7
+#define        FSBadResolution         8
+#define        FSBadAlloc              9
+#define        FSBadLength             10
+#define        FSBadImplementation     11
+
+#define        FirstExtensionError     128
+#define        LastExtensionError      255
+
+/* events */
+#define        KeepAlive               0
+#define        CatalogueChangeNotify   1
+#define        FontChangeNotify        2
+#define FSLASTEvent            3
+
+#endif                         /* _FS_H_ */
diff --git a/Xserver/include/fonts/FSproto.h b/Xserver/include/fonts/FSproto.h
new file mode 100644 (file)
index 0000000..02e9130
--- /dev/null
@@ -0,0 +1,816 @@
+/* $XConsortium: FSproto.h,v 1.11 94/04/17 20:11:05 gildea Exp $ */
+/*
+Copyright (c) 1990, 1991  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+ * Copyright 1990, 1991 Network Computing Devices;
+ * Portions Copyright 1987 by Digital Equipment Corporation 
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and
+ * its documentation for any purpose is hereby granted without fee, provided
+ * that the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the names of Network Computing Devices, or Digital
+ * not be used in advertising or publicity pertaining to distribution
+ * of the software without specific, written prior permission.
+ *
+ * NETWORK COMPUTING DEVICES, AND DIGITAL DISCLAIM ALL WARRANTIES WITH
+ * REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL NETWORK COMPUTING DEVICES,
+ * OR DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
+ * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
+ * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
+ * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
+ * THIS SOFTWARE.
+ */
+
+#ifndef _FS_PROTO_H_
+#define _FS_PROTO_H_
+
+#include       "FS.h"
+
+#define sz_fsPropOffset 20
+#define sz_fsPropInfo 8
+#define sz_fsResolution 6
+
+#define sz_fsChar2b 2
+#define sz_fsChar2b_version1 2
+#define sz_fsOffset32 8
+#define sz_fsRange             4
+
+#define        sz_fsXCharInfo          12
+#define        sz_fsXFontInfoHeader            40
+
+#define        sz_fsConnClientPrefix   8
+#define        sz_fsConnSetup          12
+#define        sz_fsConnSetupExtra     8
+#define        sz_fsConnSetupAccept    12
+
+/* request sizes */
+#define        sz_fsReq                4
+#define        sz_fsListExtensionsReq  4
+#define        sz_fsResourceReq        8
+
+#define        sz_fsNoopReq                    4
+#define        sz_fsListExtensionReq           4
+#define        sz_fsQueryExtensionReq          4
+#define        sz_fsListCataloguesReq          12
+#define        sz_fsSetCataloguesReq           4
+#define        sz_fsGetCataloguesReq           4
+#define        sz_fsSetEventMaskReq            8
+#define        sz_fsGetEventMaskReq            4
+#define        sz_fsCreateACReq                8
+#define        sz_fsFreeACReq                  8
+#define        sz_fsSetAuthorizationReq        8
+#define        sz_fsSetResolutionReq           4
+#define        sz_fsGetResolutionReq           4
+#define        sz_fsListFontsReq               12
+#define        sz_fsListFontsWithXInfoReq      12
+#define        sz_fsOpenBitmapFontReq          16
+#define        sz_fsQueryXInfoReq              8
+#define        sz_fsQueryXExtents8Req          12
+#define        sz_fsQueryXExtents16Req         12
+#define        sz_fsQueryXBitmaps8Req          16
+#define        sz_fsQueryXBitmaps16Req         16
+#define        sz_fsCloseReq                   8
+
+/* reply sizes */
+#define        sz_fsReply                      8
+#define        sz_fsGenericReply               8
+
+#define        sz_fsListExtensionsReply        8
+#define        sz_fsQueryExtensionReply        20
+#define        sz_fsListCataloguesReply        16
+#define        sz_fsGetCataloguesReply         8
+#define        sz_fsGetEventMaskReply          12
+#define        sz_fsCreateACReply              12
+#define        sz_fsGetResolutionReply         8
+#define        sz_fsListFontsReply             16
+#define        sz_fsListFontsWithXInfoReply    (12 + sz_fsXFontInfoHeader)
+#define        sz_fsOpenBitmapFontReply        16
+#define        sz_fsQueryXInfoReply            (8 + sz_fsXFontInfoHeader)
+#define        sz_fsQueryXExtents8Reply        12
+#define        sz_fsQueryXExtents16Reply       12
+#define        sz_fsQueryXBitmaps8Reply        20
+#define        sz_fsQueryXBitmaps16Reply       20
+
+#define        sz_fsError              16
+#define        sz_fsEvent              12
+#define sz_fsKeepAliveEvent    12
+
+#define        fsTrue  1
+#define        fsFalse 0
+
+/* temp decls */
+#define        Mask            CARD32
+#define        Font            CARD32
+#define        AccContext      CARD32
+
+typedef CARD32 fsTimestamp;
+
+#ifdef NOTDEF /* in fsmasks.h */
+typedef CARD32 fsBitmapFormat;
+typedef CARD32 fsBitmapFormatMask;
+#endif
+#define sz_fsBitmapFormat      4
+
+typedef struct {
+    INT16      left B16,
+                right B16;
+    INT16      width B16;
+    INT16      ascent B16,
+                descent B16;
+    CARD16     attributes B16;
+}           fsXCharInfo;
+
+typedef struct {
+    CARD8       high;
+    CARD8       low;
+}           fsChar2b;
+
+typedef struct {
+    CARD8       low;
+    CARD8       high;
+}           fsChar2b_version1;
+
+typedef struct {
+    CARD8      min_char_high;
+    CARD8      min_char_low;
+    CARD8      max_char_high;
+    CARD8      max_char_low;
+}           fsRange;
+
+typedef struct {
+    CARD32     position B32;
+    CARD32     length B32;
+}          fsOffset32;
+
+typedef struct {
+    fsOffset32 name;
+    fsOffset32 value;
+    CARD8      type;
+    BYTE        pad0;
+    CARD16     pad1 B16;
+}           fsPropOffset;
+
+typedef struct {
+    CARD32     num_offsets B32;
+    CARD32     data_len B32;
+    /* offsets */
+    /* data */
+}          fsPropInfo;
+
+typedef struct {
+    CARD16     x_resolution B16;
+    CARD16     y_resolution B16;
+    CARD16     point_size B16;
+}          fsResolution;
+
+  
+typedef struct {
+    CARD32     flags B32;
+    CARD8      char_range_min_char_high;
+    CARD8      char_range_min_char_low;
+    CARD8      char_range_max_char_high;
+    CARD8      char_range_max_char_low;
+
+    CARD8      draw_direction;
+    CARD8      pad;
+    CARD8      default_char_high;
+    CARD8      default_char_low;
+    INT16      min_bounds_left B16;
+    INT16      min_bounds_right B16;
+
+    INT16      min_bounds_width B16;
+    INT16      min_bounds_ascent B16;
+    INT16      min_bounds_descent B16;
+    CARD16     min_bounds_attributes B16;
+
+    INT16      max_bounds_left B16;
+    INT16      max_bounds_right B16;
+    INT16      max_bounds_width B16;
+    INT16      max_bounds_ascent B16;
+
+    INT16      max_bounds_descent B16;
+    CARD16     max_bounds_attributes B16;
+    INT16      font_ascent B16;
+    INT16      font_descent B16;
+    /* propinfo */
+}           fsXFontInfoHeader;
+
+
+/* requests */
+
+typedef struct {
+    BYTE        byteOrder;
+    CARD8       num_auths;
+    CARD16     major_version B16;
+    CARD16     minor_version B16;
+    CARD16     auth_len B16;
+    /* auth data */
+}           fsConnClientPrefix;
+
+typedef struct {
+    CARD16      status B16;
+    CARD16     major_version B16;
+    CARD16     minor_version B16;
+    CARD8      num_alternates;
+    CARD8      auth_index;
+    CARD16     alternate_len B16;
+    CARD16     auth_len B16;
+    /* alternates */
+    /* auth data */
+}           fsConnSetup;
+
+typedef struct {
+    CARD32     length B32;
+    CARD16      status B16;
+    CARD16     pad B16;
+    /* more auth data */
+}           fsConnSetupExtra;
+
+typedef struct {
+    CARD32     length B32;
+    CARD16     max_request_len B16;
+    CARD16     vendor_len B16;
+    CARD32     release_number B32;
+    /* vendor string */
+}          fsConnSetupAccept;
+
+typedef struct {
+    CARD8       reqType;
+    CARD8       data;
+    CARD16     length B16;
+}           fsReq;
+
+/*
+ * The fsFakeReq structure is never used in the protocol; it is prepended
+ * to incoming packets when setting up a connection so we can index
+ * through InitialVector.  To avoid alignment problems, it is padded
+ * to the size of a word on the largest machine this code runs on.
+ * Hence no sz_fsFakeReq constant is necessary.
+ */
+typedef struct {
+    CARD8       reqType;
+    CARD8       data;
+    CARD16     length B16;
+    CARD32     pad B32;        /* to fill out to multiple of 64 bits */
+}           fsFakeReq;
+
+typedef struct {
+    CARD8       reqType;
+    BYTE        pad;
+    CARD16      length B16;
+    Font        id B32;
+}           fsResourceReq;
+
+typedef fsReq  fsNoopReq;
+typedef fsReq  fsListExtensionsReq;
+
+typedef struct {
+    CARD8       reqType;
+    BYTE        nbytes;
+    CARD16     length B16;
+    /* name */
+}           fsQueryExtensionReq;
+
+typedef struct {
+    CARD8       reqType;
+    CARD8       data;
+    CARD16     length B16;
+    CARD32     maxNames B32;
+    CARD16     nbytes B16;
+    CARD16     pad2 B16;
+    /* pattern */
+}          fsListCataloguesReq;
+
+typedef struct {
+    CARD8       reqType;
+    BYTE        num_catalogues;
+    CARD16     length B16;
+    /* catalogues */
+}           fsSetCataloguesReq;
+
+typedef fsReq  fsGetCataloguesReq;
+
+typedef struct {
+    CARD8       reqType;
+    CARD8       ext_opcode;
+    CARD16     length B16;
+    Mask       event_mask;
+}           fsSetEventMaskReq;
+
+typedef struct {
+    CARD8       reqType;
+    CARD8       ext_opcode;
+    CARD16     length B16;
+}           fsGetEventMaskReq;
+
+typedef struct {
+    CARD8       reqType;
+    BYTE        num_auths;
+    CARD16      length B16;
+    AccContext  acid B32;
+    /* auth protocols */
+}           fsCreateACReq;
+
+typedef fsResourceReq  fsFreeACReq;
+typedef fsResourceReq  fsSetAuthorizationReq;
+
+typedef struct {
+    CARD8      reqType;
+    BYTE       num_resolutions;
+    CARD16     length B16;
+    /* resolutions */
+}          fsSetResolutionReq;
+
+typedef fsReq  fsGetResolutionReq;
+
+typedef struct {
+    CARD8       reqType;
+    BYTE        pad;
+    CARD16     length B16;
+    CARD32     maxNames B32;
+    CARD16     nbytes B16;
+    CARD16     pad2 B16;
+    /* pattern */
+}           fsListFontsReq;
+
+typedef fsListFontsReq fsListFontsWithXInfoReq;
+
+typedef struct {
+    CARD8       reqType;
+    BYTE        pad;
+    CARD16     length B16;
+    Font       fid B32;
+    fsBitmapFormatMask format_mask B32;
+    fsBitmapFormat format_hint B32;
+    /* pattern */
+}           fsOpenBitmapFontReq;
+
+typedef fsResourceReq fsQueryXInfoReq;
+
+typedef struct {
+    CARD8       reqType;
+    BOOL        range;
+    CARD16     length B16;
+    Font       fid B32;
+    CARD32     num_ranges B32;
+    /* list of chars */
+}           fsQueryXExtents8Req;
+
+typedef fsQueryXExtents8Req    fsQueryXExtents16Req;
+
+typedef struct {
+    CARD8       reqType;
+    BOOL       range;
+    CARD16     length B16;
+    Font       fid B32;
+    fsBitmapFormat format B32;
+    CARD32     num_ranges B32;
+    /* list of chars */
+}           fsQueryXBitmaps8Req;
+
+typedef fsQueryXBitmaps8Req    fsQueryXBitmaps16Req;
+
+typedef fsResourceReq fsCloseReq;
+
+
+/* replies */
+typedef struct {
+    BYTE        type;
+    BYTE        data1;
+    CARD16     sequenceNumber B16;
+    CARD32     length B32;
+}           fsGenericReply;
+
+typedef struct {
+    BYTE        type;
+    CARD8       nExtensions;
+    CARD16     sequenceNumber B16;
+    CARD32     length B32;
+    /* extension names */
+}           fsListExtensionsReply;
+
+typedef struct {
+    BYTE        type;
+    CARD8       present;
+    CARD16     sequenceNumber B16;
+    CARD32     length B32;
+    CARD16     major_version B16;
+    CARD16     minor_version B16;
+    CARD8       major_opcode;
+    CARD8       first_event;
+    CARD8       num_events;
+    CARD8       first_error;
+    CARD8       num_errors;
+    CARD8      pad1;
+    CARD16     pad2 B16;
+}           fsQueryExtensionReply;
+
+typedef struct {
+    BYTE        type;
+    BYTE        pad;
+    CARD16     sequenceNumber B16;
+    CARD32     length B32;
+    CARD32     num_replies B32;
+    CARD32     num_catalogues B32;
+    /* catalog names */
+}          fsListCataloguesReply;
+
+typedef struct {
+    BYTE        type;
+    CARD8       num_catalogues;
+    CARD16     sequenceNumber B16;
+    CARD32     length B32;
+    /* catalogue names */
+}           fsGetCataloguesReply;
+
+typedef struct {
+    BYTE        type;
+    BYTE        pad1;
+    CARD16     sequenceNumber B16;
+    CARD32     length B32;
+    CARD32     event_mask B32;
+}          fsGetEventMaskReply;
+
+typedef struct {
+    BYTE       type;
+    CARD8      auth_index;
+    CARD16     sequenceNumber B16;
+    CARD32     length B32;
+    CARD16     status B16;
+    CARD16     pad B16;
+    /* auth data */
+}          fsCreateACReply;
+
+typedef struct {
+    CARD32     length B32;
+    CARD16     status B16;
+    CARD16     pad B16;
+    /* auth data */
+}          fsCreateACExtraReply;
+
+typedef struct {
+    BYTE       type;
+    CARD8      num_resolutions;
+    CARD16     sequenceNumber B16;
+    CARD32     length B32;
+    /* resolutions */
+}          fsGetResolutionReply;
+
+typedef struct {
+    BYTE        type;
+    BYTE        pad1;
+    CARD16     sequenceNumber B16;
+    CARD32     length B32;
+    CARD32     following B32;
+    CARD32     nFonts B32;
+    /* font names */
+}           fsListFontsReply;
+
+/*
+ * this one is messy.  the reply itself is variable length (unknown
+ * number of replies) and the contents of each is variable (unknown
+ * number of properties)
+ *
+ */
+
+typedef struct {
+    BYTE        type;
+    CARD8       nameLength;    /* 0 is end-of-reply */
+    CARD16     sequenceNumber B16;
+    CARD32     length B32;
+    CARD32     nReplies B32;
+    CARD32     font_header_flags B32;
+    CARD8      font_hdr_char_range_min_char_high;
+    CARD8      font_hdr_char_range_min_char_low;
+    CARD8      font_hdr_char_range_max_char_high;
+    CARD8      font_hdr_char_range_max_char_low;
+    CARD8      font_header_draw_direction;
+    CARD8      font_header_pad;
+    CARD8      font_header_default_char_high;
+    CARD8      font_header_default_char_low;
+    INT16      font_header_min_bounds_left B16;
+    INT16      font_header_min_bounds_right B16;
+    INT16      font_header_min_bounds_width B16;
+    INT16      font_header_min_bounds_ascent B16;
+    INT16      font_header_min_bounds_descent B16;
+    CARD16     font_header_min_bounds_attributes B16;
+    INT16      font_header_max_bounds_left B16;
+    INT16      font_header_max_bounds_right B16;
+    INT16      font_header_max_bounds_width B16;
+    INT16      font_header_max_bounds_ascent B16;
+    INT16      font_header_max_bounds_descent B16;
+    CARD16     font_header_max_bounds_attributes B16;
+    INT16      font_header_font_ascent B16;
+    INT16      font_header_font_descent B16;
+    /* propinfo */
+    /* name */
+}           fsListFontsWithXInfoReply;
+    
+typedef struct {
+    BYTE        type;
+    CARD8       otherid_valid;
+    CARD16     sequenceNumber B16;
+    CARD32     length B32;
+    CARD32     otherid B32;
+    BYTE       cachable;
+    BYTE       pad1;
+    CARD16     pad2 B16;
+}           fsOpenBitmapFontReply;
+
+typedef struct {
+    BYTE        type;
+    CARD8       pad0;
+    CARD16     sequenceNumber B16;
+    CARD32     length B32;
+    CARD32     font_header_flags B32;
+    CARD8      font_hdr_char_range_min_char_high;
+    CARD8      font_hdr_char_range_min_char_low;
+    CARD8      font_hdr_char_range_max_char_high;
+    CARD8      font_hdr_char_range_max_char_low;
+    CARD8      font_header_draw_direction;
+    CARD8      font_header_pad;
+    CARD8      font_header_default_char_high;
+    CARD8      font_header_default_char_low;
+    INT16      font_header_min_bounds_left B16;
+    INT16      font_header_min_bounds_right B16;
+    INT16      font_header_min_bounds_width B16;
+    INT16      font_header_min_bounds_ascent B16;
+    INT16      font_header_min_bounds_descent B16;
+    CARD16     font_header_min_bounds_attributes B16;
+    INT16      font_header_max_bounds_left B16;
+    INT16      font_header_max_bounds_right B16;
+    INT16      font_header_max_bounds_width B16;
+    INT16      font_header_max_bounds_ascent B16;
+    INT16      font_header_max_bounds_descent B16;
+    CARD16     font_header_max_bounds_attributes B16;
+    INT16      font_header_font_ascent B16;
+    INT16      font_header_font_descent B16;
+    /* propinfo */
+}           fsQueryXInfoReply;
+
+typedef struct {
+    BYTE        type;
+    CARD8       pad0;
+    CARD16     sequenceNumber B16;
+    CARD32     length B32;
+    CARD32      num_extents B32;
+    /* extents */
+}           fsQueryXExtents8Reply;
+
+typedef fsQueryXExtents8Reply  fsQueryXExtents16Reply;
+
+typedef struct {
+    BYTE        type;
+    CARD8       pad0;
+    CARD16     sequenceNumber B16;
+    CARD32     length B32;
+    CARD32     replies_hint B32;
+    CARD32     num_chars B32;
+    CARD32     nbytes B32;
+    /* offsets */
+    /* glyphs */
+}           fsQueryXBitmaps8Reply;
+
+typedef fsQueryXBitmaps8Reply  fsQueryXBitmaps16Reply;
+
+typedef union {
+    fsGenericReply generic;
+    fsListExtensionsReply extensions;
+    fsGetResolutionReply getres;
+}           fsReply;
+
+/* errors */
+typedef struct {
+    BYTE        type;
+    BYTE        request;
+    CARD16     sequenceNumber B16;
+    CARD32     length B32;
+    fsTimestamp        timestamp;
+    CARD8      major_opcode;
+    CARD8      minor_opcode;
+    CARD16     pad B16;
+}          fsError;
+
+typedef struct {
+    BYTE        type;
+    BYTE        request;
+    CARD16     sequenceNumber B16;
+    CARD32     length B32;
+    fsTimestamp        timestamp;
+    CARD8      major_opcode;
+    CARD8      minor_opcode;
+    CARD16     pad B16;
+}          fsRequestError;
+
+typedef struct {
+    BYTE        type;
+    BYTE        request;
+    CARD16     sequenceNumber B16;
+    CARD32     length B32;
+    fsTimestamp        timestamp;
+    CARD8      major_opcode;
+    CARD8      minor_opcode;
+    CARD16     pad B16;
+    fsBitmapFormat     format B32;
+}          fsFormatError;
+
+typedef struct {
+    BYTE        type;
+    BYTE        request;
+    CARD16     sequenceNumber B16;
+    CARD32     length B32;
+    fsTimestamp        timestamp;
+    CARD8      major_opcode;
+    CARD8      minor_opcode;
+    CARD16     pad B16;
+    Font       fontid;
+}          fsFontError;
+
+typedef struct {
+    BYTE        type;
+    BYTE        request;
+    CARD16     sequenceNumber B16;
+    CARD32     length B32;
+    fsTimestamp        timestamp;
+    CARD8      major_opcode;
+    CARD8      minor_opcode;
+    CARD16     pad B16;
+    fsRange    range;
+}          fsRangeError;
+
+typedef struct {
+    BYTE        type;
+    BYTE        request;
+    CARD16     sequenceNumber B16;
+    CARD32     length B32;
+    fsTimestamp        timestamp;
+    CARD8      major_opcode;
+    CARD8      minor_opcode;
+    CARD16     pad B16;
+    Mask       event_mask;
+}          fsEventMaskError;
+
+typedef struct {
+    BYTE        type;
+    BYTE        request;
+    CARD16     sequenceNumber B16;
+    CARD32     length B32;
+    fsTimestamp        timestamp;
+    CARD8      major_opcode;
+    CARD8      minor_opcode;
+    CARD16     pad B16;
+    AccContext acid;
+}          fsAccessContextError;
+
+typedef struct {
+    BYTE        type;
+    BYTE        request;
+    CARD16     sequenceNumber B16;
+    CARD32     length B32;
+    fsTimestamp        timestamp;
+    CARD8      major_opcode;
+    CARD8      minor_opcode;
+    CARD16     pad B16;
+    Font       fontid;
+}          fsIDChoiceError;
+
+typedef struct {
+    BYTE        type;
+    BYTE        request;
+    CARD16     sequenceNumber B16;
+    CARD32     length B32;
+    fsTimestamp        timestamp;
+    CARD8      major_opcode;
+    CARD8      minor_opcode;
+    CARD16     pad B16;
+}          fsNameError;
+
+typedef struct {
+    BYTE        type;
+    BYTE        request;
+    CARD16     sequenceNumber B16;
+    CARD32     length B32;
+    fsTimestamp        timestamp;
+    CARD8      major_opcode;
+    CARD8      minor_opcode;
+    fsResolution resolution;
+}          fsResolutionError;
+
+typedef struct {
+    BYTE        type;
+    BYTE        request;
+    CARD16     sequenceNumber B16;
+    CARD32     length B32;
+    fsTimestamp        timestamp;
+    CARD8      major_opcode;
+    CARD8      minor_opcode;
+    CARD16     pad B16;
+}          fsAllocError;
+
+typedef struct {
+    BYTE        type;
+    BYTE        request;
+    CARD16     sequenceNumber B16;
+    CARD32     length B32;
+    fsTimestamp        timestamp;
+    CARD8      major_opcode;
+    CARD8      minor_opcode;
+    CARD16     pad B16;
+    CARD32     bad_length B32;
+}          fsLengthError;
+
+typedef struct {
+    BYTE        type;
+    BYTE        request;
+    CARD16     sequenceNumber B16;
+    CARD32     length B32;
+    fsTimestamp        timestamp;
+    CARD8      major_opcode;
+    CARD8      minor_opcode;
+    CARD16     pad B16;
+}          fsImplementationError;
+
+/* events */
+typedef struct {
+    BYTE        type;
+    BYTE        event_code;
+    CARD16     sequenceNumber B16;
+    CARD32     length B32;
+    fsTimestamp        timestamp;
+}          fsKeepAliveEvent;
+
+typedef struct {
+    BYTE        type;
+    BYTE        event_code;
+    CARD16     sequenceNumber B16;
+    CARD32     length B32;
+    fsTimestamp        timestamp;
+    BOOL       added;
+    BOOL       deleted;
+    CARD16     pad B16;
+}          fsCatalogueChangeNotifyEvent;
+
+typedef fsCatalogueChangeNotifyEvent   fsFontChangeNotifyEvent;
+
+typedef fsCatalogueChangeNotifyEvent   fsEvent;
+
+/* reply codes */
+#define        FS_Reply                0       /* normal reply */
+#define        FS_Error                1       /* error */
+#define        FS_Event                2
+
+/* request codes */
+#define                FS_Noop                 0
+#define                FS_ListExtensions       1
+#define                FS_QueryExtension       2
+#define                FS_ListCatalogues       3
+#define                FS_SetCatalogues        4
+#define                FS_GetCatalogues        5
+#define                FS_SetEventMask         6
+#define                FS_GetEventMask         7
+#define                FS_CreateAC             8
+#define                FS_FreeAC               9
+#define                FS_SetAuthorization     10
+#define                FS_SetResolution        11
+#define                FS_GetResolution        12
+#define                FS_ListFonts            13
+#define                FS_ListFontsWithXInfo   14
+#define                FS_OpenBitmapFont       15
+#define                FS_QueryXInfo           16
+#define                FS_QueryXExtents8       17
+#define                FS_QueryXExtents16      18
+#define                FS_QueryXBitmaps8       19
+#define                FS_QueryXBitmaps16      20
+#define                FS_CloseFont            21
+
+/* restore decls */
+#undef Mask
+#undef Font
+#undef  AccContext
+
+#endif                         /* _FS_PROTO_H_ */
diff --git a/Xserver/include/fonts/Imakefile b/Xserver/include/fonts/Imakefile
new file mode 100644 (file)
index 0000000..26f27b0
--- /dev/null
@@ -0,0 +1,14 @@
+XCOMM $XConsortium: Imakefile /main/6 1996/09/28 16:32:27 rws $
+XCOMM $XFree86: xc/include/fonts/Imakefile,v 3.3 1996/12/23 05:58:37 dawes Exp $
+
+    HEADERS = FS.h FSproto.h fsmasks.h
+
+all::
+    
+BuildIncludes($(HEADERS),X11/fonts,../..)
+InstallMultipleFlags($(HEADERS),$(INCDIR)/X11/fonts,$(INSTINCFLAGS))
+
+InstallLinkKitNonExecFile(fontstruct.h,$(LINKKITDIR)/include)
+InstallLinkKitNonExecFile(font.h,$(LINKKITDIR)/include)
+InstallLinkKitNonExecFile(fsmasks.h,$(LINKKITDIR)/include)
+
diff --git a/Xserver/include/fonts/font.h b/Xserver/include/fonts/font.h
new file mode 100644 (file)
index 0000000..f1ab484
--- /dev/null
@@ -0,0 +1,189 @@
+/* $XConsortium: font.h /main/14 1996/09/28 16:32:33 rws $ */
+/* $XFree86: xc/include/fonts/font.h,v 3.2 1997/01/14 22:13:06 dawes Exp $ */
+/***********************************************************
+Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
+
+                        All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and its
+documentation for any purpose and without fee is hereby granted,
+provided that the above copyright notice appear in all copies and that
+both that copyright notice and this permission notice appear in
+supporting documentation, and that the name of Digital not be
+used in advertising or publicity pertaining to distribution of the
+software without specific, written prior permission.
+
+DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
+ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
+DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
+ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+SOFTWARE.
+
+******************************************************************/
+/* $NCDId: @(#)font.h,v 1.7 1991/06/24 17:00:23 lemke Exp $ */
+
+#ifndef FONT_H
+#define FONT_H
+
+#ifndef BitmapFormatByteOrderMask
+#include       "fsmasks.h"
+#endif
+
+/* data structures */
+#ifndef _XTYPEDEF_FONTPTR
+typedef struct _Font *FontPtr;
+#define _XTYPEDEF_FONTPTR
+#endif
+
+typedef struct _FontInfo *FontInfoPtr;
+typedef struct _FontProp *FontPropPtr;
+typedef struct _ExtentInfo *ExtentInfoPtr;
+typedef struct _FontPathElement *FontPathElementPtr;
+
+#ifndef _XTYPEDEF_CHARINFOPTR
+typedef struct _CharInfo *CharInfoPtr;
+#define _XTYPEDEF_CHARINFOPTR
+#endif
+
+typedef struct _FontNames *FontNamesPtr;
+typedef struct _FontResolution *FontResolutionPtr;
+
+#define NullCharInfo   ((CharInfoPtr) 0)
+#define NullFont       ((FontPtr) 0)
+#define NullFontInfo   ((FontInfoPtr) 0)
+
+ /* draw direction */
+#define LeftToRight 0
+#define RightToLeft 1
+#define BottomToTop 2
+#define TopToBottom 3
+typedef int DrawDirection;
+
+#define NO_SUCH_CHAR   -1
+
+
+#define        FontAliasType   0x1000
+
+#define        AllocError      80
+#define        StillWorking    81
+#define        FontNameAlias   82
+#define        BadFontName     83
+#define        Suspended       84
+#define        Successful      85
+#define        BadFontPath     86
+#define        BadCharRange    87
+#define        BadFontFormat   88
+#define        FPEResetFailed  89      /* for when an FPE reset won't work */
+
+/* OpenFont flags */
+#define FontLoadInfo   0x0001
+#define FontLoadProps  0x0002
+#define FontLoadMetrics        0x0004
+#define FontLoadBitmaps        0x0008
+#define FontLoadAll    0x000f
+#define        FontOpenSync    0x0010
+#define FontReopen     0x0020
+
+/* Query flags */
+#define        LoadAll         0x1
+#define        FinishRamge     0x2
+#define       EightBitFont    0x4
+#define       SixteenBitFont  0x8
+
+/* Glyph Caching Modes */
+#define CACHING_OFF 0
+#define CACHE_16_BIT_GLYPHS 1
+#define CACHE_ALL_GLYPHS 2
+#define DEFAULT_GLYPH_CACHING_MODE CACHING_OFF
+extern int glyphCachingMode;
+
+extern int StartListFontsWithInfo(
+#if NeedFunctionPrototypes
+    ClientPtr /*client*/,
+    int /*length*/,
+    unsigned char */*pattern*/,
+    int /*max_names*/
+#endif
+);
+
+extern FontNamesPtr MakeFontNamesRecord(
+#if NeedFunctionPrototypes
+    unsigned /* size */
+#endif
+);
+
+extern void FreeFontNames(
+#if NeedFunctionPrototypes
+    FontNamesPtr /* pFN*/
+#endif
+);
+
+extern int  AddFontNamesName(
+#if NeedFunctionPrototypes
+    FontNamesPtr /* names */,
+    char * /* name */,
+    int /* length */
+#endif
+);
+
+#if 0 /* unused */
+extern int  FontToFSError();
+extern FontResolutionPtr GetClientResolution();
+#endif
+
+typedef struct _FontPatternCache    *FontPatternCachePtr;
+
+extern FontPatternCachePtr  MakeFontPatternCache (
+#if NeedFunctionPrototypes
+    void
+#endif
+);
+
+extern void                FreeFontPatternCache (
+#if NeedFunctionPrototypes
+    FontPatternCachePtr /* cache */
+#endif
+);
+
+extern void                EmptyFontPatternCache (
+#if NeedFunctionPrototypes
+    FontPatternCachePtr /* cache */
+#endif
+);
+
+extern void                CacheFontPattern (
+#if NeedFunctionPrototypes
+    FontPatternCachePtr /* cache */,
+    char * /* pattern */,
+    int /* patlen */,
+    FontPtr /* pFont */
+#endif
+);
+extern FontResolutionPtr GetClientResolutions(
+#if NeedFunctionPrototypes
+    int * /* num */
+#endif
+);
+
+extern FontPtr             FindCachedFontPattern (
+#if NeedFunctionPrototypes
+    FontPatternCachePtr /* cache */,
+    char * /* pattern */,
+    int /* patlen */
+#endif
+);
+
+extern void                RemoveCachedFontPattern (
+#if NeedFunctionPrototypes
+    FontPatternCachePtr /* cache */,
+    FontPtr /* pFont */
+#endif
+);
+
+typedef enum {
+    Linear8Bit, TwoD8Bit, Linear16Bit, TwoD16Bit
+}           FontEncoding;
+
+#endif                         /* FONT_H */
diff --git a/Xserver/include/fonts/fontstruct.h b/Xserver/include/fonts/fontstruct.h
new file mode 100644 (file)
index 0000000..231948e
--- /dev/null
@@ -0,0 +1,364 @@
+/* $XConsortium: fontstruct.h /main/17 1996/08/09 16:23:54 kaleb $ */
+/* $XFree86: xc/include/fonts/fontstruct.h,v 3.1 1996/12/23 05:58:39 dawes Exp $ */
+/***********************************************************
+Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
+
+                        All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and its
+documentation for any purpose and without fee is hereby granted,
+provided that the above copyright notice appear in all copies and that
+both that copyright notice and this permission notice appear in
+supporting documentation, and that the name of Digital not be
+used in advertising or publicity pertaining to distribution of the
+software without specific, written prior permission.
+
+DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
+ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
+DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
+ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+SOFTWARE.
+
+******************************************************************/
+
+#ifndef FONTSTR_H
+#define FONTSTR_H
+
+#include <X11/Xproto.h>
+#include "font.h"
+#include <X11/Xfuncproto.h>
+
+/*
+ * This version of the server font data strucutre is only for describing
+ * the in memory data structure. The file structure is not necessarily a
+ * copy of this. That is up to the compiler and the OS layer font loading
+ * machinery.
+ */
+
+#define GLYPHPADOPTIONS 4      /* 1, 2, 4, or 8 */
+
+typedef struct _FontProp {
+    long        name;
+    long        value;         /* assumes ATOM is not larger than INT32 */
+}           FontPropRec;
+
+typedef struct _FontResolution {
+    unsigned short x_resolution;
+    unsigned short y_resolution;
+    unsigned short point_size;
+}           FontResolutionRec;
+
+typedef struct _ExtentInfo {
+    DrawDirection drawDirection;
+    int         fontAscent;
+    int         fontDescent;
+    int         overallAscent;
+    int         overallDescent;
+    int         overallWidth;
+    int         overallLeft;
+    int         overallRight;
+}           ExtentInfoRec;
+
+typedef struct _CharInfo {
+    xCharInfo   metrics;       /* info preformatted for Queries */
+    char       *bits;          /* pointer to glyph image */
+}           CharInfoRec;
+
+/*
+ * Font is created at font load time. It is specific to a single encoding.
+ * e.g. not all of the glyphs in a font may be part of a single encoding.
+ */
+
+typedef struct _FontInfo {
+    unsigned short firstCol;
+    unsigned short lastCol;
+    unsigned short firstRow;
+    unsigned short lastRow;
+    unsigned short defaultCh;
+    unsigned int noOverlap:1;
+    unsigned int terminalFont:1;
+    unsigned int constantMetrics:1;
+    unsigned int constantWidth:1;
+    unsigned int inkInside:1;
+    unsigned int inkMetrics:1;
+    unsigned int allExist:1;
+    unsigned int drawDirection:2;
+    unsigned int cachable:1;
+    unsigned int anamorphic:1;
+    short       maxOverlap;
+    short       pad;
+    xCharInfo   maxbounds;
+    xCharInfo   minbounds;
+    xCharInfo   ink_maxbounds;
+    xCharInfo   ink_minbounds;
+    short       fontAscent;
+    short       fontDescent;
+    int         nprops;
+    FontPropPtr props;
+    char       *isStringProp;
+}           FontInfoRec;
+
+typedef struct _Font {
+    int         refcnt;
+    FontInfoRec info;
+    char        bit;
+    char        byte;
+    char        glyph;
+    char        scan;
+    fsBitmapFormat format;
+    int         (*get_glyphs) (
+#if NeedNestedPrototypes
+       FontPtr         /* font */,
+       unsigned long   /* count */,
+       unsigned char * /* chars */,
+       FontEncoding    /* encoding */,
+       unsigned long * /* count */,
+       CharInfoPtr *   /* glyphs */
+#endif
+);
+    int         (*get_metrics) ( 
+#if NeedNestedPrototypes
+       FontPtr         /* font */,
+       unsigned long   /* count */,
+       unsigned char * /* chars */,
+       FontEncoding    /* encoding */,
+       unsigned long * /* count */,
+       xCharInfo **    /* glyphs */
+#endif
+);
+    void        (*unload_font) ( 
+#if NeedNestedPrototypes
+       FontPtr         /* font */
+#endif
+);
+    void        (*unload_glyphs) ( 
+#if NeedNestedPrototypes
+       FontPtr         /* font */
+#endif
+);
+    FontPathElementPtr fpe;
+    pointer     svrPrivate;
+    pointer     fontPrivate;
+    pointer     fpePrivate;
+    int                maxPrivate;
+    pointer    *devPrivates;
+}           FontRec;
+
+extern Bool     _FontSetNewPrivate (
+#if NeedFunctionPrototypes
+                FontPtr        /* pFont */,
+                int            /* n */,
+                pointer        /* ptr */
+#endif
+                );
+extern int      AllocateFontPrivateIndex (
+#if NeedFunctionPrototypes
+                void
+#endif
+                );
+
+#define FontGetPrivate(pFont,n) ((n) > (pFont)->maxPrivate ? (pointer) 0 : \
+                            (pFont)->devPrivates[n])
+
+#define FontSetPrivate(pFont,n,ptr) ((n) > (pFont)->maxPrivate ? \
+                       _FontSetNewPrivate (pFont, n, ptr) : \
+                       ((((pFont)->devPrivates[n] = (ptr)) != 0) || TRUE))
+
+typedef struct _FontNames {
+    int         nnames;
+    int         size;
+    int        *length;
+    char      **names;
+}           FontNamesRec;
+
+/* External view of font paths */
+typedef struct _FontPathElement {
+    int         name_length;
+    char       *name;
+    int         type;
+    int         refcount;
+    pointer     private;
+}           FontPathElementRec;
+
+typedef struct _FPEFunctions {
+    int         (*name_check) (
+#if NeedFunctionPrototypes
+                              char* /* name */
+#endif
+                              );
+    int         (*init_fpe) (
+#if NeedNestedPrototypes
+                            FontPathElementPtr /* fpe */
+#endif
+                            );
+    int         (*reset_fpe) (
+#if NeedNestedPrototypes
+                            FontPathElementPtr /* fpe */
+#endif
+                            );
+    int         (*free_fpe) (
+#if NeedNestedPrototypes
+                            FontPathElementPtr /* fpe */
+#endif
+                            );
+    int         (*open_font) (
+#if NeedNestedPrototypes
+                             pointer /* client */,
+                             FontPathElementPtr /* fpe */,
+                             int /* flags */,
+                             char* /* name */,
+                             int /* namelen */,
+                             fsBitmapFormat /* format */,
+                             fsBitmapFormatMask /* fmask */,
+                             unsigned long /* id (type XID or FSID) */,
+                             FontPtr* /* pFont */,
+                             char** /* aliasName */,
+                             FontPtr /* non_cachable_font */
+#endif
+                             );
+
+    int         (*close_font) (
+#if NeedNestedPrototypes
+                              FontPathElementPtr /* fpe */,
+                              FontPtr /* pFont */
+#endif
+                              );
+    int         (*list_fonts) (
+#if NeedNestedPrototypes
+                              pointer /* client */,
+                              FontPathElementPtr /* fpe */,
+                              char* /* pat */,
+                              int /* len */,
+                              int /* max */,
+                              FontNamesPtr /* names */
+#endif
+                              );
+    int         (*start_list_fonts_and_aliases) (
+#if NeedNestedPrototypes
+                                                pointer /* client */,
+                                                FontPathElementPtr /* fpe */,
+                                                char* /* pat */,
+                                                int /* len */,
+                                                int /* max */,
+                                                pointer* /* privatep */
+#endif
+                                                );
+    int         (*list_next_font_or_alias) (
+#if NeedNestedPrototypes
+                                           pointer /* client */,
+                                           FontPathElementPtr /* fpe */,
+                                           char** /* namep */,
+                                           int* /* namelenp */,
+                                           char** /* resolvedp */,
+                                           int* /* resolvedlenp */,
+                                           pointer /* private */
+#endif
+                                           );
+    int         (*start_list_fonts_with_info) (
+#if NeedNestedPrototypes
+                                              pointer /* client */,
+                                              FontPathElementPtr /* fpe */,
+                                              char* /* pat */,
+                                              int /* patlen */,
+                                              int /* maxnames */,
+                                              pointer* /* privatep */
+#endif
+                                              );
+    int         (*list_next_font_with_info) (  /* client, fpe, name, namelen,
+                                                info, num, data */
+#if NeedNestedPrototypes
+                                            pointer /* client */,
+                                            FontPathElementPtr /* fpe */,
+                                            char** /* name */,
+                                            int* /* namelen */,
+                                            FontInfoPtr* /* info */,
+                                            int* /* numFonts */,
+                                            pointer /* private */
+#endif
+                                            );
+    int         (*wakeup_fpe) (
+#if NeedNestedPrototypes
+                              FontPathElementPtr /* fpe */,
+                              unsigned long* /* LastSelectMask */
+#endif
+                              );
+    int                (*client_died) (
+#if NeedNestedPrototypes
+                               pointer /* client */,
+                               FontPathElementPtr /* fpe */
+#endif
+                               );
+               /* for load_glyphs, range_flag = 0 ->
+                       nchars = # of characters in data
+                       item_size = bytes/char
+                       data = list of characters
+                  range_flag = 1 ->
+                       nchars = # of fsChar2b's in data
+                       item_size is ignored
+                       data = list of fsChar2b's */
+    int                (*load_glyphs) (
+#if NeedNestedPrototypes
+                               pointer /* client */,
+                               FontPtr /* pfont */,
+                               Bool /* range_flag */,
+                               unsigned int /* nchars */,
+                               int /* item_size */,
+                               unsigned char* /* data */
+#endif
+                               );
+    void       (*set_path_hook)(
+#if NeedFunctionPrototypes
+                                void
+#endif
+                                );
+}           FPEFunctionsRec, FPEFunctions;
+
+#if 0  /* unused */
+extern int  InitFPETypes();
+#endif
+
+/*
+ * Various macros for computing values based on contents of
+ * the above structures
+ */
+
+#define        GLYPHWIDTHPIXELS(pci) \
+       ((pci)->metrics.rightSideBearing - (pci)->metrics.leftSideBearing)
+
+#define        GLYPHHEIGHTPIXELS(pci) \
+       ((pci)->metrics.ascent + (pci)->metrics.descent)
+
+#define        GLYPHWIDTHBYTES(pci)    (((GLYPHWIDTHPIXELS(pci))+7) >> 3)
+
+#define GLYPHWIDTHPADDED(bc)   (((bc)+7) & ~0x7)
+
+#define BYTES_PER_ROW(bits, nbytes) \
+       ((nbytes) == 1 ? (((bits)+7)>>3)        /* pad to 1 byte */ \
+       :(nbytes) == 2 ? ((((bits)+15)>>3)&~1)  /* pad to 2 bytes */ \
+       :(nbytes) == 4 ? ((((bits)+31)>>3)&~3)  /* pad to 4 bytes */ \
+       :(nbytes) == 8 ? ((((bits)+63)>>3)&~7)  /* pad to 8 bytes */ \
+       : 0)
+
+#define BYTES_FOR_GLYPH(ci,pad)        (GLYPHHEIGHTPIXELS(ci) * \
+                                BYTES_PER_ROW(GLYPHWIDTHPIXELS(ci),pad))
+/*
+ * Macros for computing different bounding boxes for fonts; from
+ * the font protocol
+ */
+
+#define FONT_MAX_ASCENT(pi)    ((pi)->fontAscent > (pi)->ink_maxbounds.ascent ? \
+                           (pi)->fontAscent : (pi)->ink_maxbounds.ascent)
+#define FONT_MAX_DESCENT(pi)   ((pi)->fontDescent > (pi)->ink_maxbounds.descent ? \
+                           (pi)->fontDescent : (pi)->ink_maxbounds.descent)
+#define FONT_MAX_HEIGHT(pi)    (FONT_MAX_ASCENT(pi) + FONT_MAX_DESCENT(pi))
+#define FONT_MIN_LEFT(pi)      ((pi)->ink_minbounds.leftSideBearing < 0 ? \
+                           (pi)->ink_minbounds.leftSideBearing : 0)
+#define FONT_MAX_RIGHT(pi)     ((pi)->ink_maxbounds.rightSideBearing > \
+                               (pi)->ink_maxbounds.characterWidth ? \
+                           (pi)->ink_maxbounds.rightSideBearing : \
+                               (pi)->ink_maxbounds.characterWidth)
+#define FONT_MAX_WIDTH(pi)     (FONT_MAX_RIGHT(pi) - FONT_MIN_LEFT(pi))
+
+#endif                         /* FONTSTR_H */
diff --git a/Xserver/include/fonts/fsmasks.h b/Xserver/include/fonts/fsmasks.h
new file mode 100644 (file)
index 0000000..6693b9e
--- /dev/null
@@ -0,0 +1,99 @@
+/* $XConsortium: fsmasks.h,v 1.5 94/04/17 20:11:08 dpw Exp $ */
+/*
+ * Copyright 1990, 1991 Network Computing Devices;
+ * Portions Copyright 1987 by Digital Equipment Corporation 
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and
+ * its documentation for any purpose is hereby granted without fee, provided
+ * that the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the names of Network Computing Devices or Digital
+ * not be used in advertising or publicity pertaining to distribution
+ * of the software without specific, written prior permission.
+ * Network Computing Devices and Digital make no representations 
+ * about the suitability of this software for any purpose.  It is provided 
+ * "as is" without express or implied warranty.
+ *
+ * NETWORK COMPUTING DEVICES AND DIGITAL DISCLAIM ALL WARRANTIES WITH
+ * REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL NETWORK COMPUTING DEVICES
+ * OR DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
+ * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
+ * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
+ * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
+ * THIS SOFTWARE.
+ */
+
+/*
+
+Portions Copyright (c) 1987, 1994  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+*/
+
+
+/*
+ * masks & values used by the font lib and the font server
+ */
+
+#ifndef _FSMASKS_H_
+#define _FSMASKS_H_
+
+#include <X11/Xmd.h>
+
+/* font format macros */
+#define BitmapFormatByteOrderMask       (1L << 0)
+#define BitmapFormatBitOrderMask        (1L << 1)
+#define BitmapFormatImageRectMask       (3L << 2)
+#define BitmapFormatScanlinePadMask     (3L << 8)
+#define BitmapFormatScanlineUnitMask    (3L << 12)
+
+#define BitmapFormatByteOrderLSB        (0)
+#define BitmapFormatByteOrderMSB        (1L << 0)
+#define BitmapFormatBitOrderLSB         (0)
+#define BitmapFormatBitOrderMSB         (1L << 1)
+
+#define BitmapFormatImageRectMin        (0L << 2)
+#define BitmapFormatImageRectMaxWidth   (1L << 2)
+#define BitmapFormatImageRectMax        (2L << 2)
+
+#define BitmapFormatScanlinePad8        (0L << 8)
+#define BitmapFormatScanlinePad16       (1L << 8)
+#define BitmapFormatScanlinePad32       (2L << 8)
+#define BitmapFormatScanlinePad64       (3L << 8)
+
+#define BitmapFormatScanlineUnit8       (0L << 12)
+#define BitmapFormatScanlineUnit16      (1L << 12)
+#define BitmapFormatScanlineUnit32      (2L << 12)
+#define BitmapFormatScanlineUnit64      (3L << 12)
+
+#define BitmapFormatMaskByte            (1L << 0)
+#define BitmapFormatMaskBit             (1L << 1)
+#define BitmapFormatMaskImageRectangle  (1L << 2)
+#define BitmapFormatMaskScanLinePad     (1L << 3)
+#define BitmapFormatMaskScanLineUnit    (1L << 4)
+
+typedef CARD32 fsBitmapFormat;
+typedef CARD32 fsBitmapFormatMask;
+
+#endif /* _FSMASKS_H_ */
diff --git a/Xserver/include/keysym.h b/Xserver/include/keysym.h
new file mode 100644 (file)
index 0000000..b034dfe
--- /dev/null
@@ -0,0 +1,60 @@
+/* $XConsortium: keysym.h,v 1.15 94/04/17 20:10:55 rws Exp $ */
+
+/***********************************************************
+
+Copyright (c) 1987  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+
+Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
+
+                        All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and its 
+documentation for any purpose and without fee is hereby granted, 
+provided that the above copyright notice appear in all copies and that
+both that copyright notice and this permission notice appear in 
+supporting documentation, and that the name of Digital not be
+used in advertising or publicity pertaining to distribution of the
+software without specific, written prior permission.  
+
+DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
+ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
+DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
+ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+SOFTWARE.
+
+******************************************************************/
+
+/* default keysyms */
+#define XK_MISCELLANY
+#define XK_XKB_KEYS
+#define XK_LATIN1
+#define XK_LATIN2
+#define XK_LATIN3
+#define XK_LATIN4
+#define XK_GREEK
+
+#include <X11/keysymdef.h>
diff --git a/Xserver/include/keysymdef.h b/Xserver/include/keysymdef.h
new file mode 100644 (file)
index 0000000..dbb7746
--- /dev/null
@@ -0,0 +1,1572 @@
+/* $TOG: keysymdef.h /main/25 1997/06/21 10:54:51 kaleb $ */
+
+/***********************************************************
+Copyright (c) 1987, 1994  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be included
+in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR
+OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall
+not be used in advertising or otherwise to promote the sale, use or
+other dealings in this Software without prior written authorization
+from the X Consortium.
+
+
+Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts
+
+                        All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and its
+documentation for any purpose and without fee is hereby granted,
+provided that the above copyright notice appear in all copies and that
+both that copyright notice and this permission notice appear in
+supporting documentation, and that the name of Digital not be
+used in advertising or publicity pertaining to distribution of the
+software without specific, written prior permission.
+
+DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
+ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
+DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
+ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+SOFTWARE.
+
+******************************************************************/
+
+#define XK_VoidSymbol          0xFFFFFF        /* void symbol */
+
+#ifdef XK_MISCELLANY
+/*
+ * TTY Functions, cleverly chosen to map to ascii, for convenience of
+ * programming, but could have been arbitrary (at the cost of lookup
+ * tables in client code.
+ */
+
+#define XK_BackSpace           0xFF08  /* back space, back char */
+#define XK_Tab                 0xFF09
+#define XK_Linefeed            0xFF0A  /* Linefeed, LF */
+#define XK_Clear               0xFF0B
+#define XK_Return              0xFF0D  /* Return, enter */
+#define XK_Pause               0xFF13  /* Pause, hold */
+#define XK_Scroll_Lock         0xFF14
+#define XK_Sys_Req             0xFF15
+#define XK_Escape              0xFF1B
+#define XK_Delete              0xFFFF  /* Delete, rubout */
+
+
+
+/* International & multi-key character composition */
+
+#define XK_Multi_key           0xFF20  /* Multi-key character compose */
+#define XK_SingleCandidate     0xFF3C
+#define XK_MultipleCandidate   0xFF3D
+#define XK_PreviousCandidate   0xFF3E
+
+/* Japanese keyboard support */
+
+#define XK_Kanji               0xFF21  /* Kanji, Kanji convert */
+#define XK_Muhenkan            0xFF22  /* Cancel Conversion */
+#define XK_Henkan_Mode         0xFF23  /* Start/Stop Conversion */
+#define XK_Henkan              0xFF23  /* Alias for Henkan_Mode */
+#define XK_Romaji              0xFF24  /* to Romaji */
+#define XK_Hiragana            0xFF25  /* to Hiragana */
+#define XK_Katakana            0xFF26  /* to Katakana */
+#define XK_Hiragana_Katakana   0xFF27  /* Hiragana/Katakana toggle */
+#define XK_Zenkaku             0xFF28  /* to Zenkaku */
+#define XK_Hankaku             0xFF29  /* to Hankaku */
+#define XK_Zenkaku_Hankaku     0xFF2A  /* Zenkaku/Hankaku toggle */
+#define XK_Touroku             0xFF2B  /* Add to Dictionary */
+#define XK_Massyo              0xFF2C  /* Delete from Dictionary */
+#define XK_Kana_Lock           0xFF2D  /* Kana Lock */
+#define XK_Kana_Shift          0xFF2E  /* Kana Shift */
+#define XK_Eisu_Shift          0xFF2F  /* Alphanumeric Shift */
+#define XK_Eisu_toggle         0xFF30  /* Alphanumeric toggle */
+#define XK_Zen_Koho            0xFF3D  /* Multiple/All Candidate(s) */
+#define XK_Mae_Koho            0xFF3E  /* Previous Candidate */
+
+/* 0xFF31 thru 0xFF3F are under XK_KOREAN */
+
+/* Cursor control & motion */
+
+#define XK_Home                        0xFF50
+#define XK_Left                        0xFF51  /* Move left, left arrow */
+#define XK_Up                  0xFF52  /* Move up, up arrow */
+#define XK_Right               0xFF53  /* Move right, right arrow */
+#define XK_Down                        0xFF54  /* Move down, down arrow */
+#define XK_Prior               0xFF55  /* Prior, previous */
+#define XK_Page_Up             0xFF55
+#define XK_Next                        0xFF56  /* Next */
+#define XK_Page_Down           0xFF56
+#define XK_End                 0xFF57  /* EOL */
+#define XK_Begin               0xFF58  /* BOL */
+
+
+/* Misc Functions */
+
+#define XK_Select              0xFF60  /* Select, mark */
+#define XK_Print               0xFF61
+#define XK_Execute             0xFF62  /* Execute, run, do */
+#define XK_Insert              0xFF63  /* Insert, insert here */
+#define XK_Undo                        0xFF65  /* Undo, oops */
+#define XK_Redo                        0xFF66  /* redo, again */
+#define XK_Menu                        0xFF67
+#define XK_Find                        0xFF68  /* Find, search */
+#define XK_Cancel              0xFF69  /* Cancel, stop, abort, exit */
+#define XK_Help                        0xFF6A  /* Help */
+#define XK_Break               0xFF6B
+#define XK_Mode_switch         0xFF7E  /* Character set switch */
+#define XK_script_switch        0xFF7E  /* Alias for mode_switch */
+#define XK_Num_Lock            0xFF7F
+
+/* Keypad Functions, keypad numbers cleverly chosen to map to ascii */
+
+#define XK_KP_Space            0xFF80  /* space */
+#define XK_KP_Tab              0xFF89
+#define XK_KP_Enter            0xFF8D  /* enter */
+#define XK_KP_F1               0xFF91  /* PF1, KP_A, ... */
+#define XK_KP_F2               0xFF92
+#define XK_KP_F3               0xFF93
+#define XK_KP_F4               0xFF94
+#define XK_KP_Home             0xFF95
+#define XK_KP_Left             0xFF96
+#define XK_KP_Up               0xFF97
+#define XK_KP_Right            0xFF98
+#define XK_KP_Down             0xFF99
+#define XK_KP_Prior            0xFF9A
+#define XK_KP_Page_Up          0xFF9A
+#define XK_KP_Next             0xFF9B
+#define XK_KP_Page_Down                0xFF9B
+#define XK_KP_End              0xFF9C
+#define XK_KP_Begin            0xFF9D
+#define XK_KP_Insert           0xFF9E
+#define XK_KP_Delete           0xFF9F
+#define XK_KP_Equal            0xFFBD  /* equals */
+#define XK_KP_Multiply         0xFFAA
+#define XK_KP_Add              0xFFAB
+#define XK_KP_Separator                0xFFAC  /* separator, often comma */
+#define XK_KP_Subtract         0xFFAD
+#define XK_KP_Decimal          0xFFAE
+#define XK_KP_Divide           0xFFAF
+
+#define XK_KP_0                        0xFFB0
+#define XK_KP_1                        0xFFB1
+#define XK_KP_2                        0xFFB2
+#define XK_KP_3                        0xFFB3
+#define XK_KP_4                        0xFFB4
+#define XK_KP_5                        0xFFB5
+#define XK_KP_6                        0xFFB6
+#define XK_KP_7                        0xFFB7
+#define XK_KP_8                        0xFFB8
+#define XK_KP_9                        0xFFB9
+
+
+
+/*
+ * Auxilliary Functions; note the duplicate definitions for left and right
+ * function keys;  Sun keyboards and a few other manufactures have such
+ * function key groups on the left and/or right sides of the keyboard.
+ * We've not found a keyboard with more than 35 function keys total.
+ */
+
+#define XK_F1                  0xFFBE
+#define XK_F2                  0xFFBF
+#define XK_F3                  0xFFC0
+#define XK_F4                  0xFFC1
+#define XK_F5                  0xFFC2
+#define XK_F6                  0xFFC3
+#define XK_F7                  0xFFC4
+#define XK_F8                  0xFFC5
+#define XK_F9                  0xFFC6
+#define XK_F10                 0xFFC7
+#define XK_F11                 0xFFC8
+#define XK_L1                  0xFFC8
+#define XK_F12                 0xFFC9
+#define XK_L2                  0xFFC9
+#define XK_F13                 0xFFCA
+#define XK_L3                  0xFFCA
+#define XK_F14                 0xFFCB
+#define XK_L4                  0xFFCB
+#define XK_F15                 0xFFCC
+#define XK_L5                  0xFFCC
+#define XK_F16                 0xFFCD
+#define XK_L6                  0xFFCD
+#define XK_F17                 0xFFCE
+#define XK_L7                  0xFFCE
+#define XK_F18                 0xFFCF
+#define XK_L8                  0xFFCF
+#define XK_F19                 0xFFD0
+#define XK_L9                  0xFFD0
+#define XK_F20                 0xFFD1
+#define XK_L10                 0xFFD1
+#define XK_F21                 0xFFD2
+#define XK_R1                  0xFFD2
+#define XK_F22                 0xFFD3
+#define XK_R2                  0xFFD3
+#define XK_F23                 0xFFD4
+#define XK_R3                  0xFFD4
+#define XK_F24                 0xFFD5
+#define XK_R4                  0xFFD5
+#define XK_F25                 0xFFD6
+#define XK_R5                  0xFFD6
+#define XK_F26                 0xFFD7
+#define XK_R6                  0xFFD7
+#define XK_F27                 0xFFD8
+#define XK_R7                  0xFFD8
+#define XK_F28                 0xFFD9
+#define XK_R8                  0xFFD9
+#define XK_F29                 0xFFDA
+#define XK_R9                  0xFFDA
+#define XK_F30                 0xFFDB
+#define XK_R10                 0xFFDB
+#define XK_F31                 0xFFDC
+#define XK_R11                 0xFFDC
+#define XK_F32                 0xFFDD
+#define XK_R12                 0xFFDD
+#define XK_F33                 0xFFDE
+#define XK_R13                 0xFFDE
+#define XK_F34                 0xFFDF
+#define XK_R14                 0xFFDF
+#define XK_F35                 0xFFE0
+#define XK_R15                 0xFFE0
+
+/* Modifiers */
+
+#define XK_Shift_L             0xFFE1  /* Left shift */
+#define XK_Shift_R             0xFFE2  /* Right shift */
+#define XK_Control_L           0xFFE3  /* Left control */
+#define XK_Control_R           0xFFE4  /* Right control */
+#define XK_Caps_Lock           0xFFE5  /* Caps lock */
+#define XK_Shift_Lock          0xFFE6  /* Shift lock */
+
+#define XK_Meta_L              0xFFE7  /* Left meta */
+#define XK_Meta_R              0xFFE8  /* Right meta */
+#define XK_Alt_L               0xFFE9  /* Left alt */
+#define XK_Alt_R               0xFFEA  /* Right alt */
+#define XK_Super_L             0xFFEB  /* Left super */
+#define XK_Super_R             0xFFEC  /* Right super */
+#define XK_Hyper_L             0xFFED  /* Left hyper */
+#define XK_Hyper_R             0xFFEE  /* Right hyper */
+#endif /* XK_MISCELLANY */
+
+/*
+ * ISO 9995 Function and Modifier Keys
+ * Byte 3 = 0xFE
+ */
+
+#ifdef XK_XKB_KEYS
+#define        XK_ISO_Lock                                     0xFE01
+#define        XK_ISO_Level2_Latch                             0xFE02
+#define        XK_ISO_Level3_Shift                             0xFE03
+#define        XK_ISO_Level3_Latch                             0xFE04
+#define        XK_ISO_Level3_Lock                              0xFE05
+#define        XK_ISO_Group_Shift              0xFF7E  /* Alias for mode_switch */
+#define        XK_ISO_Group_Latch                              0xFE06
+#define        XK_ISO_Group_Lock                               0xFE07
+#define        XK_ISO_Next_Group                               0xFE08
+#define        XK_ISO_Next_Group_Lock                          0xFE09
+#define        XK_ISO_Prev_Group                               0xFE0A
+#define        XK_ISO_Prev_Group_Lock                          0xFE0B
+#define        XK_ISO_First_Group                              0xFE0C
+#define        XK_ISO_First_Group_Lock                         0xFE0D
+#define        XK_ISO_Last_Group                               0xFE0E
+#define        XK_ISO_Last_Group_Lock                          0xFE0F
+
+#define        XK_ISO_Left_Tab                                 0xFE20
+#define        XK_ISO_Move_Line_Up                             0xFE21
+#define        XK_ISO_Move_Line_Down                           0xFE22
+#define        XK_ISO_Partial_Line_Up                          0xFE23
+#define        XK_ISO_Partial_Line_Down                        0xFE24
+#define        XK_ISO_Partial_Space_Left                       0xFE25
+#define        XK_ISO_Partial_Space_Right                      0xFE26
+#define        XK_ISO_Set_Margin_Left                          0xFE27
+#define        XK_ISO_Set_Margin_Right                         0xFE28
+#define        XK_ISO_Release_Margin_Left                      0xFE29
+#define        XK_ISO_Release_Margin_Right                     0xFE2A
+#define        XK_ISO_Release_Both_Margins                     0xFE2B
+#define        XK_ISO_Fast_Cursor_Left                         0xFE2C
+#define        XK_ISO_Fast_Cursor_Right                        0xFE2D
+#define        XK_ISO_Fast_Cursor_Up                           0xFE2E
+#define        XK_ISO_Fast_Cursor_Down                         0xFE2F
+#define        XK_ISO_Continuous_Underline                     0xFE30
+#define        XK_ISO_Discontinuous_Underline                  0xFE31
+#define        XK_ISO_Emphasize                                0xFE32
+#define        XK_ISO_Center_Object                            0xFE33
+#define        XK_ISO_Enter                                    0xFE34
+
+#define        XK_dead_grave                                   0xFE50
+#define        XK_dead_acute                                   0xFE51
+#define        XK_dead_circumflex                              0xFE52
+#define        XK_dead_tilde                                   0xFE53
+#define        XK_dead_macron                                  0xFE54
+#define        XK_dead_breve                                   0xFE55
+#define        XK_dead_abovedot                                0xFE56
+#define        XK_dead_diaeresis                               0xFE57
+#define        XK_dead_abovering                               0xFE58
+#define        XK_dead_doubleacute                             0xFE59
+#define        XK_dead_caron                                   0xFE5A
+#define        XK_dead_cedilla                                 0xFE5B
+#define        XK_dead_ogonek                                  0xFE5C
+#define        XK_dead_iota                                    0xFE5D
+#define        XK_dead_voiced_sound                            0xFE5E
+#define        XK_dead_semivoiced_sound                        0xFE5F
+#define        XK_dead_belowdot                                0xFE60
+
+#define        XK_First_Virtual_Screen                         0xFED0
+#define        XK_Prev_Virtual_Screen                          0xFED1
+#define        XK_Next_Virtual_Screen                          0xFED2
+#define        XK_Last_Virtual_Screen                          0xFED4
+#define        XK_Terminate_Server                             0xFED5
+
+#define        XK_AccessX_Enable                               0xFE70
+#define        XK_AccessX_Feedback_Enable                      0xFE71
+#define        XK_RepeatKeys_Enable                            0xFE72
+#define        XK_SlowKeys_Enable                              0xFE73
+#define        XK_BounceKeys_Enable                            0xFE74
+#define        XK_StickyKeys_Enable                            0xFE75
+#define        XK_MouseKeys_Enable                             0xFE76
+#define        XK_MouseKeys_Accel_Enable                       0xFE77
+#define        XK_Overlay1_Enable                              0xFE78
+#define        XK_Overlay2_Enable                              0xFE79
+#define        XK_AudibleBell_Enable                           0xFE7A
+
+#define        XK_Pointer_Left                                 0xFEE0
+#define        XK_Pointer_Right                                0xFEE1
+#define        XK_Pointer_Up                                   0xFEE2
+#define        XK_Pointer_Down                                 0xFEE3
+#define        XK_Pointer_UpLeft                               0xFEE4
+#define        XK_Pointer_UpRight                              0xFEE5
+#define        XK_Pointer_DownLeft                             0xFEE6
+#define        XK_Pointer_DownRight                            0xFEE7
+#define        XK_Pointer_Button_Dflt                          0xFEE8
+#define        XK_Pointer_Button1                              0xFEE9
+#define        XK_Pointer_Button2                              0xFEEA
+#define        XK_Pointer_Button3                              0xFEEB
+#define        XK_Pointer_Button4                              0xFEEC
+#define        XK_Pointer_Button5                              0xFEED
+#define        XK_Pointer_DblClick_Dflt                        0xFEEE
+#define        XK_Pointer_DblClick1                            0xFEEF
+#define        XK_Pointer_DblClick2                            0xFEF0
+#define        XK_Pointer_DblClick3                            0xFEF1
+#define        XK_Pointer_DblClick4                            0xFEF2
+#define        XK_Pointer_DblClick5                            0xFEF3
+#define        XK_Pointer_Drag_Dflt                            0xFEF4
+#define        XK_Pointer_Drag1                                0xFEF5
+#define        XK_Pointer_Drag2                                0xFEF6
+#define        XK_Pointer_Drag3                                0xFEF7
+#define        XK_Pointer_Drag4                                0xFEF8
+#define        XK_Pointer_Drag5                                0xFEFD
+
+#define        XK_Pointer_EnableKeys                           0xFEF9
+#define        XK_Pointer_Accelerate                           0xFEFA
+#define        XK_Pointer_DfltBtnNext                          0xFEFB
+#define        XK_Pointer_DfltBtnPrev                          0xFEFC
+
+#endif
+
+/*
+ * 3270 Terminal Keys
+ * Byte 3 = 0xFD
+ */
+
+#ifdef XK_3270
+#define XK_3270_Duplicate      0xFD01
+#define XK_3270_FieldMark      0xFD02
+#define XK_3270_Right2         0xFD03
+#define XK_3270_Left2          0xFD04
+#define XK_3270_BackTab        0xFD05
+#define XK_3270_EraseEOF       0xFD06
+#define XK_3270_EraseInput     0xFD07
+#define XK_3270_Reset          0xFD08
+#define XK_3270_Quit           0xFD09
+#define XK_3270_PA1            0xFD0A
+#define XK_3270_PA2            0xFD0B
+#define XK_3270_PA3            0xFD0C
+#define XK_3270_Test           0xFD0D
+#define XK_3270_Attn           0xFD0E
+#define XK_3270_CursorBlink    0xFD0F
+#define XK_3270_AltCursor      0xFD10
+#define XK_3270_KeyClick       0xFD11
+#define XK_3270_Jump           0xFD12
+#define XK_3270_Ident          0xFD13
+#define XK_3270_Rule           0xFD14
+#define XK_3270_Copy           0xFD15
+#define XK_3270_Play           0xFD16
+#define XK_3270_Setup          0xFD17
+#define XK_3270_Record         0xFD18
+#define XK_3270_ChangeScreen   0xFD19
+#define XK_3270_DeleteWord     0xFD1A
+#define XK_3270_ExSelect       0xFD1B
+#define XK_3270_CursorSelect   0xFD1C
+#define XK_3270_PrintScreen    0xFD1D
+#define XK_3270_Enter          0xFD1E
+#endif
+
+/*
+ *  Latin 1
+ *  Byte 3 = 0
+ */
+#ifdef XK_LATIN1
+#define XK_space               0x020
+#define XK_exclam              0x021
+#define XK_quotedbl            0x022
+#define XK_numbersign          0x023
+#define XK_dollar              0x024
+#define XK_percent             0x025
+#define XK_ampersand           0x026
+#define XK_apostrophe          0x027
+#define XK_quoteright          0x027   /* deprecated */
+#define XK_parenleft           0x028
+#define XK_parenright          0x029
+#define XK_asterisk            0x02a
+#define XK_plus                0x02b
+#define XK_comma               0x02c
+#define XK_minus               0x02d
+#define XK_period              0x02e
+#define XK_slash               0x02f
+#define XK_0                   0x030
+#define XK_1                   0x031
+#define XK_2                   0x032
+#define XK_3                   0x033
+#define XK_4                   0x034
+#define XK_5                   0x035
+#define XK_6                   0x036
+#define XK_7                   0x037
+#define XK_8                   0x038
+#define XK_9                   0x039
+#define XK_colon               0x03a
+#define XK_semicolon           0x03b
+#define XK_less                0x03c
+#define XK_equal               0x03d
+#define XK_greater             0x03e
+#define XK_question            0x03f
+#define XK_at                  0x040
+#define XK_A                   0x041
+#define XK_B                   0x042
+#define XK_C                   0x043
+#define XK_D                   0x044
+#define XK_E                   0x045
+#define XK_F                   0x046
+#define XK_G                   0x047
+#define XK_H                   0x048
+#define XK_I                   0x049
+#define XK_J                   0x04a
+#define XK_K                   0x04b
+#define XK_L                   0x04c
+#define XK_M                   0x04d
+#define XK_N                   0x04e
+#define XK_O                   0x04f
+#define XK_P                   0x050
+#define XK_Q                   0x051
+#define XK_R                   0x052
+#define XK_S                   0x053
+#define XK_T                   0x054
+#define XK_U                   0x055
+#define XK_V                   0x056
+#define XK_W                   0x057
+#define XK_X                   0x058
+#define XK_Y                   0x059
+#define XK_Z                   0x05a
+#define XK_bracketleft         0x05b
+#define XK_backslash           0x05c
+#define XK_bracketright        0x05d
+#define XK_asciicircum         0x05e
+#define XK_underscore          0x05f
+#define XK_grave               0x060
+#define XK_quoteleft           0x060   /* deprecated */
+#define XK_a                   0x061
+#define XK_b                   0x062
+#define XK_c                   0x063
+#define XK_d                   0x064
+#define XK_e                   0x065
+#define XK_f                   0x066
+#define XK_g                   0x067
+#define XK_h                   0x068
+#define XK_i                   0x069
+#define XK_j                   0x06a
+#define XK_k                   0x06b
+#define XK_l                   0x06c
+#define XK_m                   0x06d
+#define XK_n                   0x06e
+#define XK_o                   0x06f
+#define XK_p                   0x070
+#define XK_q                   0x071
+#define XK_r                   0x072
+#define XK_s                   0x073
+#define XK_t                   0x074
+#define XK_u                   0x075
+#define XK_v                   0x076
+#define XK_w                   0x077
+#define XK_x                   0x078
+#define XK_y                   0x079
+#define XK_z                   0x07a
+#define XK_braceleft           0x07b
+#define XK_bar                 0x07c
+#define XK_braceright          0x07d
+#define XK_asciitilde          0x07e
+
+#define XK_nobreakspace        0x0a0
+#define XK_exclamdown          0x0a1
+#define XK_cent                       0x0a2
+#define XK_sterling            0x0a3
+#define XK_currency            0x0a4
+#define XK_yen                 0x0a5
+#define XK_brokenbar           0x0a6
+#define XK_section             0x0a7
+#define XK_diaeresis           0x0a8
+#define XK_copyright           0x0a9
+#define XK_ordfeminine         0x0aa
+#define XK_guillemotleft       0x0ab   /* left angle quotation mark */
+#define XK_notsign             0x0ac
+#define XK_hyphen              0x0ad
+#define XK_registered          0x0ae
+#define XK_macron              0x0af
+#define XK_degree              0x0b0
+#define XK_plusminus           0x0b1
+#define XK_twosuperior         0x0b2
+#define XK_threesuperior       0x0b3
+#define XK_acute               0x0b4
+#define XK_mu                  0x0b5
+#define XK_paragraph           0x0b6
+#define XK_periodcentered      0x0b7
+#define XK_cedilla             0x0b8
+#define XK_onesuperior         0x0b9
+#define XK_masculine           0x0ba
+#define XK_guillemotright      0x0bb   /* right angle quotation mark */
+#define XK_onequarter          0x0bc
+#define XK_onehalf             0x0bd
+#define XK_threequarters       0x0be
+#define XK_questiondown        0x0bf
+#define XK_Agrave              0x0c0
+#define XK_Aacute              0x0c1
+#define XK_Acircumflex         0x0c2
+#define XK_Atilde              0x0c3
+#define XK_Adiaeresis          0x0c4
+#define XK_Aring               0x0c5
+#define XK_AE                  0x0c6
+#define XK_Ccedilla            0x0c7
+#define XK_Egrave              0x0c8
+#define XK_Eacute              0x0c9
+#define XK_Ecircumflex         0x0ca
+#define XK_Ediaeresis          0x0cb
+#define XK_Igrave              0x0cc
+#define XK_Iacute              0x0cd
+#define XK_Icircumflex         0x0ce
+#define XK_Idiaeresis          0x0cf
+#define XK_ETH                 0x0d0
+#define XK_Eth                 0x0d0   /* deprecated */
+#define XK_Ntilde              0x0d1
+#define XK_Ograve              0x0d2
+#define XK_Oacute              0x0d3
+#define XK_Ocircumflex         0x0d4
+#define XK_Otilde              0x0d5
+#define XK_Odiaeresis          0x0d6
+#define XK_multiply            0x0d7
+#define XK_Ooblique            0x0d8
+#define XK_Ugrave              0x0d9
+#define XK_Uacute              0x0da
+#define XK_Ucircumflex         0x0db
+#define XK_Udiaeresis          0x0dc
+#define XK_Yacute              0x0dd
+#define XK_THORN               0x0de
+#define XK_Thorn               0x0de   /* deprecated */
+#define XK_ssharp              0x0df
+#define XK_agrave              0x0e0
+#define XK_aacute              0x0e1
+#define XK_acircumflex         0x0e2
+#define XK_atilde              0x0e3
+#define XK_adiaeresis          0x0e4
+#define XK_aring               0x0e5
+#define XK_ae                  0x0e6
+#define XK_ccedilla            0x0e7
+#define XK_egrave              0x0e8
+#define XK_eacute              0x0e9
+#define XK_ecircumflex         0x0ea
+#define XK_ediaeresis          0x0eb
+#define XK_igrave              0x0ec
+#define XK_iacute              0x0ed
+#define XK_icircumflex         0x0ee
+#define XK_idiaeresis          0x0ef
+#define XK_eth                 0x0f0
+#define XK_ntilde              0x0f1
+#define XK_ograve              0x0f2
+#define XK_oacute              0x0f3
+#define XK_ocircumflex         0x0f4
+#define XK_otilde              0x0f5
+#define XK_odiaeresis          0x0f6
+#define XK_division            0x0f7
+#define XK_oslash              0x0f8
+#define XK_ugrave              0x0f9
+#define XK_uacute              0x0fa
+#define XK_ucircumflex         0x0fb
+#define XK_udiaeresis          0x0fc
+#define XK_yacute              0x0fd
+#define XK_thorn               0x0fe
+#define XK_ydiaeresis          0x0ff
+#endif /* XK_LATIN1 */
+
+/*
+ *   Latin 2
+ *   Byte 3 = 1
+ */
+
+#ifdef XK_LATIN2
+#define XK_Aogonek             0x1a1
+#define XK_breve               0x1a2
+#define XK_Lstroke             0x1a3
+#define XK_Lcaron              0x1a5
+#define XK_Sacute              0x1a6
+#define XK_Scaron              0x1a9
+#define XK_Scedilla            0x1aa
+#define XK_Tcaron              0x1ab
+#define XK_Zacute              0x1ac
+#define XK_Zcaron              0x1ae
+#define XK_Zabovedot           0x1af
+#define XK_aogonek             0x1b1
+#define XK_ogonek              0x1b2
+#define XK_lstroke             0x1b3
+#define XK_lcaron              0x1b5
+#define XK_sacute              0x1b6
+#define XK_caron               0x1b7
+#define XK_scaron              0x1b9
+#define XK_scedilla            0x1ba
+#define XK_tcaron              0x1bb
+#define XK_zacute              0x1bc
+#define XK_doubleacute         0x1bd
+#define XK_zcaron              0x1be
+#define XK_zabovedot           0x1bf
+#define XK_Racute              0x1c0
+#define XK_Abreve              0x1c3
+#define XK_Lacute              0x1c5
+#define XK_Cacute              0x1c6
+#define XK_Ccaron              0x1c8
+#define XK_Eogonek             0x1ca
+#define XK_Ecaron              0x1cc
+#define XK_Dcaron              0x1cf
+#define XK_Dstroke             0x1d0
+#define XK_Nacute              0x1d1
+#define XK_Ncaron              0x1d2
+#define XK_Odoubleacute        0x1d5
+#define XK_Rcaron              0x1d8
+#define XK_Uring               0x1d9
+#define XK_Udoubleacute        0x1db
+#define XK_Tcedilla            0x1de
+#define XK_racute              0x1e0
+#define XK_abreve              0x1e3
+#define XK_lacute              0x1e5
+#define XK_cacute              0x1e6
+#define XK_ccaron              0x1e8
+#define XK_eogonek             0x1ea
+#define XK_ecaron              0x1ec
+#define XK_dcaron              0x1ef
+#define XK_dstroke             0x1f0
+#define XK_nacute              0x1f1
+#define XK_ncaron              0x1f2
+#define XK_odoubleacute        0x1f5
+#define XK_udoubleacute        0x1fb
+#define XK_rcaron              0x1f8
+#define XK_uring               0x1f9
+#define XK_tcedilla            0x1fe
+#define XK_abovedot            0x1ff
+#endif /* XK_LATIN2 */
+
+/*
+ *   Latin 3
+ *   Byte 3 = 2
+ */
+
+#ifdef XK_LATIN3
+#define XK_Hstroke             0x2a1
+#define XK_Hcircumflex         0x2a6
+#define XK_Iabovedot           0x2a9
+#define XK_Gbreve              0x2ab
+#define XK_Jcircumflex         0x2ac
+#define XK_hstroke             0x2b1
+#define XK_hcircumflex         0x2b6
+#define XK_idotless            0x2b9
+#define XK_gbreve              0x2bb
+#define XK_jcircumflex         0x2bc
+#define XK_Cabovedot           0x2c5
+#define XK_Ccircumflex         0x2c6
+#define XK_Gabovedot           0x2d5
+#define XK_Gcircumflex         0x2d8
+#define XK_Ubreve              0x2dd
+#define XK_Scircumflex         0x2de
+#define XK_cabovedot           0x2e5
+#define XK_ccircumflex         0x2e6
+#define XK_gabovedot           0x2f5
+#define XK_gcircumflex         0x2f8
+#define XK_ubreve              0x2fd
+#define XK_scircumflex         0x2fe
+#endif /* XK_LATIN3 */
+
+
+/*
+ *   Latin 4
+ *   Byte 3 = 3
+ */
+
+#ifdef XK_LATIN4
+#define XK_kra                 0x3a2
+#define XK_kappa               0x3a2   /* deprecated */
+#define XK_Rcedilla            0x3a3
+#define XK_Itilde              0x3a5
+#define XK_Lcedilla            0x3a6
+#define XK_Emacron             0x3aa
+#define XK_Gcedilla            0x3ab
+#define XK_Tslash              0x3ac
+#define XK_rcedilla            0x3b3
+#define XK_itilde              0x3b5
+#define XK_lcedilla            0x3b6
+#define XK_emacron             0x3ba
+#define XK_gcedilla            0x3bb
+#define XK_tslash              0x3bc
+#define XK_ENG                 0x3bd
+#define XK_eng                 0x3bf
+#define XK_Amacron             0x3c0
+#define XK_Iogonek             0x3c7
+#define XK_Eabovedot           0x3cc
+#define XK_Imacron             0x3cf
+#define XK_Ncedilla            0x3d1
+#define XK_Omacron             0x3d2
+#define XK_Kcedilla            0x3d3
+#define XK_Uogonek             0x3d9
+#define XK_Utilde              0x3dd
+#define XK_Umacron             0x3de
+#define XK_amacron             0x3e0
+#define XK_iogonek             0x3e7
+#define XK_eabovedot           0x3ec
+#define XK_imacron             0x3ef
+#define XK_ncedilla            0x3f1
+#define XK_omacron             0x3f2
+#define XK_kcedilla            0x3f3
+#define XK_uogonek             0x3f9
+#define XK_utilde              0x3fd
+#define XK_umacron             0x3fe
+#endif /* XK_LATIN4 */
+
+/*
+ * Katakana
+ * Byte 3 = 4
+ */
+
+#ifdef XK_KATAKANA
+#define XK_overline                                   0x47e
+#define XK_kana_fullstop                               0x4a1
+#define XK_kana_openingbracket                         0x4a2
+#define XK_kana_closingbracket                         0x4a3
+#define XK_kana_comma                                  0x4a4
+#define XK_kana_conjunctive                            0x4a5
+#define XK_kana_middledot                              0x4a5  /* deprecated */
+#define XK_kana_WO                                     0x4a6
+#define XK_kana_a                                      0x4a7
+#define XK_kana_i                                      0x4a8
+#define XK_kana_u                                      0x4a9
+#define XK_kana_e                                      0x4aa
+#define XK_kana_o                                      0x4ab
+#define XK_kana_ya                                     0x4ac
+#define XK_kana_yu                                     0x4ad
+#define XK_kana_yo                                     0x4ae
+#define XK_kana_tsu                                    0x4af
+#define XK_kana_tu                                     0x4af  /* deprecated */
+#define XK_prolongedsound                              0x4b0
+#define XK_kana_A                                      0x4b1
+#define XK_kana_I                                      0x4b2
+#define XK_kana_U                                      0x4b3
+#define XK_kana_E                                      0x4b4
+#define XK_kana_O                                      0x4b5
+#define XK_kana_KA                                     0x4b6
+#define XK_kana_KI                                     0x4b7
+#define XK_kana_KU                                     0x4b8
+#define XK_kana_KE                                     0x4b9
+#define XK_kana_KO                                     0x4ba
+#define XK_kana_SA                                     0x4bb
+#define XK_kana_SHI                                    0x4bc
+#define XK_kana_SU                                     0x4bd
+#define XK_kana_SE                                     0x4be
+#define XK_kana_SO                                     0x4bf
+#define XK_kana_TA                                     0x4c0
+#define XK_kana_CHI                                    0x4c1
+#define XK_kana_TI                                     0x4c1  /* deprecated */
+#define XK_kana_TSU                                    0x4c2
+#define XK_kana_TU                                     0x4c2  /* deprecated */
+#define XK_kana_TE                                     0x4c3
+#define XK_kana_TO                                     0x4c4
+#define XK_kana_NA                                     0x4c5
+#define XK_kana_NI                                     0x4c6
+#define XK_kana_NU                                     0x4c7
+#define XK_kana_NE                                     0x4c8
+#define XK_kana_NO                                     0x4c9
+#define XK_kana_HA                                     0x4ca
+#define XK_kana_HI                                     0x4cb
+#define XK_kana_FU                                     0x4cc
+#define XK_kana_HU                                     0x4cc  /* deprecated */
+#define XK_kana_HE                                     0x4cd
+#define XK_kana_HO                                     0x4ce
+#define XK_kana_MA                                     0x4cf
+#define XK_kana_MI                                     0x4d0
+#define XK_kana_MU                                     0x4d1
+#define XK_kana_ME                                     0x4d2
+#define XK_kana_MO                                     0x4d3
+#define XK_kana_YA                                     0x4d4
+#define XK_kana_YU                                     0x4d5
+#define XK_kana_YO                                     0x4d6
+#define XK_kana_RA                                     0x4d7
+#define XK_kana_RI                                     0x4d8
+#define XK_kana_RU                                     0x4d9
+#define XK_kana_RE                                     0x4da
+#define XK_kana_RO                                     0x4db
+#define XK_kana_WA                                     0x4dc
+#define XK_kana_N                                      0x4dd
+#define XK_voicedsound                                 0x4de
+#define XK_semivoicedsound                             0x4df
+#define XK_kana_switch          0xFF7E  /* Alias for mode_switch */
+#endif /* XK_KATAKANA */
+
+/*
+ *  Arabic
+ *  Byte 3 = 5
+ */
+
+#ifdef XK_ARABIC
+#define XK_Arabic_comma                                0x5ac
+#define XK_Arabic_semicolon                            0x5bb
+#define XK_Arabic_question_mark                        0x5bf
+#define XK_Arabic_hamza                                0x5c1
+#define XK_Arabic_maddaonalef                          0x5c2
+#define XK_Arabic_hamzaonalef                          0x5c3
+#define XK_Arabic_hamzaonwaw                           0x5c4
+#define XK_Arabic_hamzaunderalef                       0x5c5
+#define XK_Arabic_hamzaonyeh                           0x5c6
+#define XK_Arabic_alef                                 0x5c7
+#define XK_Arabic_beh                                  0x5c8
+#define XK_Arabic_tehmarbuta                           0x5c9
+#define XK_Arabic_teh                                  0x5ca
+#define XK_Arabic_theh                                 0x5cb
+#define XK_Arabic_jeem                                 0x5cc
+#define XK_Arabic_hah                                  0x5cd
+#define XK_Arabic_khah                                 0x5ce
+#define XK_Arabic_dal                                  0x5cf
+#define XK_Arabic_thal                                 0x5d0
+#define XK_Arabic_ra                                   0x5d1
+#define XK_Arabic_zain                                 0x5d2
+#define XK_Arabic_seen                                 0x5d3
+#define XK_Arabic_sheen                                0x5d4
+#define XK_Arabic_sad                                  0x5d5
+#define XK_Arabic_dad                                  0x5d6
+#define XK_Arabic_tah                                  0x5d7
+#define XK_Arabic_zah                                  0x5d8
+#define XK_Arabic_ain                                  0x5d9
+#define XK_Arabic_ghain                                0x5da
+#define XK_Arabic_tatweel                              0x5e0
+#define XK_Arabic_feh                                  0x5e1
+#define XK_Arabic_qaf                                  0x5e2
+#define XK_Arabic_kaf                                  0x5e3
+#define XK_Arabic_lam                                  0x5e4
+#define XK_Arabic_meem                                 0x5e5
+#define XK_Arabic_noon                                 0x5e6
+#define XK_Arabic_ha                                   0x5e7
+#define XK_Arabic_heh                                  0x5e7  /* deprecated */
+#define XK_Arabic_waw                                  0x5e8
+#define XK_Arabic_alefmaksura                          0x5e9
+#define XK_Arabic_yeh                                  0x5ea
+#define XK_Arabic_fathatan                             0x5eb
+#define XK_Arabic_dammatan                             0x5ec
+#define XK_Arabic_kasratan                             0x5ed
+#define XK_Arabic_fatha                                0x5ee
+#define XK_Arabic_damma                                0x5ef
+#define XK_Arabic_kasra                                0x5f0
+#define XK_Arabic_shadda                               0x5f1
+#define XK_Arabic_sukun                                0x5f2
+#define XK_Arabic_switch        0xFF7E  /* Alias for mode_switch */
+#endif /* XK_ARABIC */
+
+/*
+ * Cyrillic
+ * Byte 3 = 6
+ */
+#ifdef XK_CYRILLIC
+#define XK_Serbian_dje                                 0x6a1
+#define XK_Macedonia_gje                               0x6a2
+#define XK_Cyrillic_io                                 0x6a3
+#define XK_Ukrainian_ie                                0x6a4
+#define XK_Ukranian_je                                 0x6a4  /* deprecated */
+#define XK_Macedonia_dse                               0x6a5
+#define XK_Ukrainian_i                                 0x6a6
+#define XK_Ukranian_i                                  0x6a6  /* deprecated */
+#define XK_Ukrainian_yi                                0x6a7
+#define XK_Ukranian_yi                                 0x6a7  /* deprecated */
+#define XK_Cyrillic_je                                 0x6a8
+#define XK_Serbian_je                                  0x6a8  /* deprecated */
+#define XK_Cyrillic_lje                                0x6a9
+#define XK_Serbian_lje                                 0x6a9  /* deprecated */
+#define XK_Cyrillic_nje                                0x6aa
+#define XK_Serbian_nje                                 0x6aa  /* deprecated */
+#define XK_Serbian_tshe                                0x6ab
+#define XK_Macedonia_kje                               0x6ac
+#define XK_Byelorussian_shortu                         0x6ae
+#define XK_Cyrillic_dzhe                               0x6af
+#define XK_Serbian_dze                                 0x6af  /* deprecated */
+#define XK_numerosign                                  0x6b0
+#define XK_Serbian_DJE                                 0x6b1
+#define XK_Macedonia_GJE                               0x6b2
+#define XK_Cyrillic_IO                                 0x6b3
+#define XK_Ukrainian_IE                                0x6b4
+#define XK_Ukranian_JE                                 0x6b4  /* deprecated */
+#define XK_Macedonia_DSE                               0x6b5
+#define XK_Ukrainian_I                                 0x6b6
+#define XK_Ukranian_I                                  0x6b6  /* deprecated */
+#define XK_Ukrainian_YI                                0x6b7
+#define XK_Ukranian_YI                                 0x6b7  /* deprecated */
+#define XK_Cyrillic_JE                                 0x6b8
+#define XK_Serbian_JE                                  0x6b8  /* deprecated */
+#define XK_Cyrillic_LJE                                0x6b9
+#define XK_Serbian_LJE                                 0x6b9  /* deprecated */
+#define XK_Cyrillic_NJE                                0x6ba
+#define XK_Serbian_NJE                                 0x6ba  /* deprecated */
+#define XK_Serbian_TSHE                                0x6bb
+#define XK_Macedonia_KJE                               0x6bc
+#define XK_Byelorussian_SHORTU                         0x6be
+#define XK_Cyrillic_DZHE                               0x6bf
+#define XK_Serbian_DZE                                 0x6bf  /* deprecated */
+#define XK_Cyrillic_yu                                 0x6c0
+#define XK_Cyrillic_a                                  0x6c1
+#define XK_Cyrillic_be                                 0x6c2
+#define XK_Cyrillic_tse                                0x6c3
+#define XK_Cyrillic_de                                 0x6c4
+#define XK_Cyrillic_ie                                 0x6c5
+#define XK_Cyrillic_ef                                 0x6c6
+#define XK_Cyrillic_ghe                                0x6c7
+#define XK_Cyrillic_ha                                 0x6c8
+#define XK_Cyrillic_i                                  0x6c9
+#define XK_Cyrillic_shorti                             0x6ca
+#define XK_Cyrillic_ka                                 0x6cb
+#define XK_Cyrillic_el                                 0x6cc
+#define XK_Cyrillic_em                                 0x6cd
+#define XK_Cyrillic_en                                 0x6ce
+#define XK_Cyrillic_o                                  0x6cf
+#define XK_Cyrillic_pe                                 0x6d0
+#define XK_Cyrillic_ya                                 0x6d1
+#define XK_Cyrillic_er                                 0x6d2
+#define XK_Cyrillic_es                                 0x6d3
+#define XK_Cyrillic_te                                 0x6d4
+#define XK_Cyrillic_u                                  0x6d5
+#define XK_Cyrillic_zhe                                0x6d6
+#define XK_Cyrillic_ve                                 0x6d7
+#define XK_Cyrillic_softsign                           0x6d8
+#define XK_Cyrillic_yeru                               0x6d9
+#define XK_Cyrillic_ze                                 0x6da
+#define XK_Cyrillic_sha                                0x6db
+#define XK_Cyrillic_e                                  0x6dc
+#define XK_Cyrillic_shcha                              0x6dd
+#define XK_Cyrillic_che                                0x6de
+#define XK_Cyrillic_hardsign                           0x6df
+#define XK_Cyrillic_YU                                 0x6e0
+#define XK_Cyrillic_A                                  0x6e1
+#define XK_Cyrillic_BE                                 0x6e2
+#define XK_Cyrillic_TSE                                0x6e3
+#define XK_Cyrillic_DE                                 0x6e4
+#define XK_Cyrillic_IE                                 0x6e5
+#define XK_Cyrillic_EF                                 0x6e6
+#define XK_Cyrillic_GHE                                0x6e7
+#define XK_Cyrillic_HA                                 0x6e8
+#define XK_Cyrillic_I                                  0x6e9
+#define XK_Cyrillic_SHORTI                             0x6ea
+#define XK_Cyrillic_KA                                 0x6eb
+#define XK_Cyrillic_EL                                 0x6ec
+#define XK_Cyrillic_EM                                 0x6ed
+#define XK_Cyrillic_EN                                 0x6ee
+#define XK_Cyrillic_O                                  0x6ef
+#define XK_Cyrillic_PE                                 0x6f0
+#define XK_Cyrillic_YA                                 0x6f1
+#define XK_Cyrillic_ER                                 0x6f2
+#define XK_Cyrillic_ES                                 0x6f3
+#define XK_Cyrillic_TE                                 0x6f4
+#define XK_Cyrillic_U                                  0x6f5
+#define XK_Cyrillic_ZHE                                0x6f6
+#define XK_Cyrillic_VE                                 0x6f7
+#define XK_Cyrillic_SOFTSIGN                           0x6f8
+#define XK_Cyrillic_YERU                               0x6f9
+#define XK_Cyrillic_ZE                                 0x6fa
+#define XK_Cyrillic_SHA                                0x6fb
+#define XK_Cyrillic_E                                  0x6fc
+#define XK_Cyrillic_SHCHA                              0x6fd
+#define XK_Cyrillic_CHE                                0x6fe
+#define XK_Cyrillic_HARDSIGN                           0x6ff
+#endif /* XK_CYRILLIC */
+
+/*
+ * Greek
+ * Byte 3 = 7
+ */
+
+#ifdef XK_GREEK
+#define XK_Greek_ALPHAaccent                           0x7a1
+#define XK_Greek_EPSILONaccent                         0x7a2
+#define XK_Greek_ETAaccent                             0x7a3
+#define XK_Greek_IOTAaccent                            0x7a4
+#define XK_Greek_IOTAdiaeresis                         0x7a5
+#define XK_Greek_OMICRONaccent                         0x7a7
+#define XK_Greek_UPSILONaccent                         0x7a8
+#define XK_Greek_UPSILONdieresis                       0x7a9
+#define XK_Greek_OMEGAaccent                           0x7ab
+#define XK_Greek_accentdieresis                        0x7ae
+#define XK_Greek_horizbar                              0x7af
+#define XK_Greek_alphaaccent                           0x7b1
+#define XK_Greek_epsilonaccent                         0x7b2
+#define XK_Greek_etaaccent                             0x7b3
+#define XK_Greek_iotaaccent                            0x7b4
+#define XK_Greek_iotadieresis                          0x7b5
+#define XK_Greek_iotaaccentdieresis                    0x7b6
+#define XK_Greek_omicronaccent                         0x7b7
+#define XK_Greek_upsilonaccent                         0x7b8
+#define XK_Greek_upsilondieresis                       0x7b9
+#define XK_Greek_upsilonaccentdieresis                 0x7ba
+#define XK_Greek_omegaaccent                           0x7bb
+#define XK_Greek_ALPHA                                 0x7c1
+#define XK_Greek_BETA                                  0x7c2
+#define XK_Greek_GAMMA                                 0x7c3
+#define XK_Greek_DELTA                                 0x7c4
+#define XK_Greek_EPSILON                               0x7c5
+#define XK_Greek_ZETA                                  0x7c6
+#define XK_Greek_ETA                                   0x7c7
+#define XK_Greek_THETA                                 0x7c8
+#define XK_Greek_IOTA                                  0x7c9
+#define XK_Greek_KAPPA                                 0x7ca
+#define XK_Greek_LAMDA                                 0x7cb
+#define XK_Greek_LAMBDA                                0x7cb
+#define XK_Greek_MU                                    0x7cc
+#define XK_Greek_NU                                    0x7cd
+#define XK_Greek_XI                                    0x7ce
+#define XK_Greek_OMICRON                               0x7cf
+#define XK_Greek_PI                                    0x7d0
+#define XK_Greek_RHO                                   0x7d1
+#define XK_Greek_SIGMA                                 0x7d2
+#define XK_Greek_TAU                                   0x7d4
+#define XK_Greek_UPSILON                               0x7d5
+#define XK_Greek_PHI                                   0x7d6
+#define XK_Greek_CHI                                   0x7d7
+#define XK_Greek_PSI                                   0x7d8
+#define XK_Greek_OMEGA                                 0x7d9
+#define XK_Greek_alpha                                 0x7e1
+#define XK_Greek_beta                                  0x7e2
+#define XK_Greek_gamma                                 0x7e3
+#define XK_Greek_delta                                 0x7e4
+#define XK_Greek_epsilon                               0x7e5
+#define XK_Greek_zeta                                  0x7e6
+#define XK_Greek_eta                                   0x7e7
+#define XK_Greek_theta                                 0x7e8
+#define XK_Greek_iota                                  0x7e9
+#define XK_Greek_kappa                                 0x7ea
+#define XK_Greek_lamda                                 0x7eb
+#define XK_Greek_lambda                                0x7eb
+#define XK_Greek_mu                                    0x7ec
+#define XK_Greek_nu                                    0x7ed
+#define XK_Greek_xi                                    0x7ee
+#define XK_Greek_omicron                               0x7ef
+#define XK_Greek_pi                                    0x7f0
+#define XK_Greek_rho                                   0x7f1
+#define XK_Greek_sigma                                 0x7f2
+#define XK_Greek_finalsmallsigma                       0x7f3
+#define XK_Greek_tau                                   0x7f4
+#define XK_Greek_upsilon                               0x7f5
+#define XK_Greek_phi                                   0x7f6
+#define XK_Greek_chi                                   0x7f7
+#define XK_Greek_psi                                   0x7f8
+#define XK_Greek_omega                                 0x7f9
+#define XK_Greek_switch         0xFF7E  /* Alias for mode_switch */
+#endif /* XK_GREEK */
+
+/*
+ * Technical
+ * Byte 3 = 8
+ */
+
+#ifdef XK_TECHNICAL
+#define XK_leftradical                                 0x8a1
+#define XK_topleftradical                              0x8a2
+#define XK_horizconnector                              0x8a3
+#define XK_topintegral                                 0x8a4
+#define XK_botintegral                                 0x8a5
+#define XK_vertconnector                               0x8a6
+#define XK_topleftsqbracket                            0x8a7
+#define XK_botleftsqbracket                            0x8a8
+#define XK_toprightsqbracket                           0x8a9
+#define XK_botrightsqbracket                           0x8aa
+#define XK_topleftparens                               0x8ab
+#define XK_botleftparens                               0x8ac
+#define XK_toprightparens                              0x8ad
+#define XK_botrightparens                              0x8ae
+#define XK_leftmiddlecurlybrace                        0x8af
+#define XK_rightmiddlecurlybrace                       0x8b0
+#define XK_topleftsummation                            0x8b1
+#define XK_botleftsummation                            0x8b2
+#define XK_topvertsummationconnector                   0x8b3
+#define XK_botvertsummationconnector                   0x8b4
+#define XK_toprightsummation                           0x8b5
+#define XK_botrightsummation                           0x8b6
+#define XK_rightmiddlesummation                        0x8b7
+#define XK_lessthanequal                               0x8bc
+#define XK_notequal                                    0x8bd
+#define XK_greaterthanequal                            0x8be
+#define XK_integral                                    0x8bf
+#define XK_therefore                                   0x8c0
+#define XK_variation                                   0x8c1
+#define XK_infinity                                    0x8c2
+#define XK_nabla                                       0x8c5
+#define XK_approximate                                 0x8c8
+#define XK_similarequal                                0x8c9
+#define XK_ifonlyif                                    0x8cd
+#define XK_implies                                     0x8ce
+#define XK_identical                                   0x8cf
+#define XK_radical                                     0x8d6
+#define XK_includedin                                  0x8da
+#define XK_includes                                    0x8db
+#define XK_intersection                                0x8dc
+#define XK_union                                       0x8dd
+#define XK_logicaland                                  0x8de
+#define XK_logicalor                                   0x8df
+#define XK_partialderivative                           0x8ef
+#define XK_function                                    0x8f6
+#define XK_leftarrow                                   0x8fb
+#define XK_uparrow                                     0x8fc
+#define XK_rightarrow                                  0x8fd
+#define XK_downarrow                                   0x8fe
+#endif /* XK_TECHNICAL */
+
+/*
+ *  Special
+ *  Byte 3 = 9
+ */
+
+#ifdef XK_SPECIAL
+#define XK_blank                                       0x9df
+#define XK_soliddiamond                                0x9e0
+#define XK_checkerboard                                0x9e1
+#define XK_ht                                          0x9e2
+#define XK_ff                                          0x9e3
+#define XK_cr                                          0x9e4
+#define XK_lf                                          0x9e5
+#define XK_nl                                          0x9e8
+#define XK_vt                                          0x9e9
+#define XK_lowrightcorner                              0x9ea
+#define XK_uprightcorner                               0x9eb
+#define XK_upleftcorner                                0x9ec
+#define XK_lowleftcorner                               0x9ed
+#define XK_crossinglines                               0x9ee
+#define XK_horizlinescan1                              0x9ef
+#define XK_horizlinescan3                              0x9f0
+#define XK_horizlinescan5                              0x9f1
+#define XK_horizlinescan7                              0x9f2
+#define XK_horizlinescan9                              0x9f3
+#define XK_leftt                                       0x9f4
+#define XK_rightt                                      0x9f5
+#define XK_bott                                        0x9f6
+#define XK_topt                                        0x9f7
+#define XK_vertbar                                     0x9f8
+#endif /* XK_SPECIAL */
+
+/*
+ *  Publishing
+ *  Byte 3 = a
+ */
+
+#ifdef XK_PUBLISHING
+#define XK_emspace                                     0xaa1
+#define XK_enspace                                     0xaa2
+#define XK_em3space                                    0xaa3
+#define XK_em4space                                    0xaa4
+#define XK_digitspace                                  0xaa5
+#define XK_punctspace                                  0xaa6
+#define XK_thinspace                                   0xaa7
+#define XK_hairspace                                   0xaa8
+#define XK_emdash                                      0xaa9
+#define XK_endash                                      0xaaa
+#define XK_signifblank                                 0xaac
+#define XK_ellipsis                                    0xaae
+#define XK_doubbaselinedot                             0xaaf
+#define XK_onethird                                    0xab0
+#define XK_twothirds                                   0xab1
+#define XK_onefifth                                    0xab2
+#define XK_twofifths                                   0xab3
+#define XK_threefifths                                 0xab4
+#define XK_fourfifths                                  0xab5
+#define XK_onesixth                                    0xab6
+#define XK_fivesixths                                  0xab7
+#define XK_careof                                      0xab8
+#define XK_figdash                                     0xabb
+#define XK_leftanglebracket                            0xabc
+#define XK_decimalpoint                                0xabd
+#define XK_rightanglebracket                           0xabe
+#define XK_marker                                      0xabf
+#define XK_oneeighth                                   0xac3
+#define XK_threeeighths                                0xac4
+#define XK_fiveeighths                                 0xac5
+#define XK_seveneighths                                0xac6
+#define XK_trademark                                   0xac9
+#define XK_signaturemark                               0xaca
+#define XK_trademarkincircle                           0xacb
+#define XK_leftopentriangle                            0xacc
+#define XK_rightopentriangle                           0xacd
+#define XK_emopencircle                                0xace
+#define XK_emopenrectangle                             0xacf
+#define XK_leftsinglequotemark                         0xad0
+#define XK_rightsinglequotemark                        0xad1
+#define XK_leftdoublequotemark                         0xad2
+#define XK_rightdoublequotemark                        0xad3
+#define XK_prescription                                0xad4
+#define XK_minutes                                     0xad6
+#define XK_seconds                                     0xad7
+#define XK_latincross                                  0xad9
+#define XK_hexagram                                    0xada
+#define XK_filledrectbullet                            0xadb
+#define XK_filledlefttribullet                         0xadc
+#define XK_filledrighttribullet                        0xadd
+#define XK_emfilledcircle                              0xade
+#define XK_emfilledrect                                0xadf
+#define XK_enopencircbullet                            0xae0
+#define XK_enopensquarebullet                          0xae1
+#define XK_openrectbullet                              0xae2
+#define XK_opentribulletup                             0xae3
+#define XK_opentribulletdown                           0xae4
+#define XK_openstar                                    0xae5
+#define XK_enfilledcircbullet                          0xae6
+#define XK_enfilledsqbullet                            0xae7
+#define XK_filledtribulletup                           0xae8
+#define XK_filledtribulletdown                         0xae9
+#define XK_leftpointer                                 0xaea
+#define XK_rightpointer                                0xaeb
+#define XK_club                                        0xaec
+#define XK_diamond                                     0xaed
+#define XK_heart                                       0xaee
+#define XK_maltesecross                                0xaf0
+#define XK_dagger                                      0xaf1
+#define XK_doubledagger                                0xaf2
+#define XK_checkmark                                   0xaf3
+#define XK_ballotcross                                 0xaf4
+#define XK_musicalsharp                                0xaf5
+#define XK_musicalflat                                 0xaf6
+#define XK_malesymbol                                  0xaf7
+#define XK_femalesymbol                                0xaf8
+#define XK_telephone                                   0xaf9
+#define XK_telephonerecorder                           0xafa
+#define XK_phonographcopyright                         0xafb
+#define XK_caret                                       0xafc
+#define XK_singlelowquotemark                          0xafd
+#define XK_doublelowquotemark                          0xafe
+#define XK_cursor                                      0xaff
+#endif /* XK_PUBLISHING */
+
+/*
+ *  APL
+ *  Byte 3 = b
+ */
+
+#ifdef XK_APL
+#define XK_leftcaret                                   0xba3
+#define XK_rightcaret                                  0xba6
+#define XK_downcaret                                   0xba8
+#define XK_upcaret                                     0xba9
+#define XK_overbar                                     0xbc0
+#define XK_downtack                                    0xbc2
+#define XK_upshoe                                      0xbc3
+#define XK_downstile                                   0xbc4
+#define XK_underbar                                    0xbc6
+#define XK_jot                                         0xbca
+#define XK_quad                                        0xbcc
+#define XK_uptack                                      0xbce
+#define XK_circle                                      0xbcf
+#define XK_upstile                                     0xbd3
+#define XK_downshoe                                    0xbd6
+#define XK_rightshoe                                   0xbd8
+#define XK_leftshoe                                    0xbda
+#define XK_lefttack                                    0xbdc
+#define XK_righttack                                   0xbfc
+#endif /* XK_APL */
+
+/*
+ * Hebrew
+ * Byte 3 = c
+ */
+
+#ifdef XK_HEBREW
+#define XK_hebrew_doublelowline                        0xcdf
+#define XK_hebrew_aleph                                0xce0
+#define XK_hebrew_bet                                  0xce1
+#define XK_hebrew_beth                                 0xce1  /* deprecated */
+#define XK_hebrew_gimel                                0xce2
+#define XK_hebrew_gimmel                               0xce2  /* deprecated */
+#define XK_hebrew_dalet                                0xce3
+#define XK_hebrew_daleth                               0xce3  /* deprecated */
+#define XK_hebrew_he                                   0xce4
+#define XK_hebrew_waw                                  0xce5
+#define XK_hebrew_zain                                 0xce6
+#define XK_hebrew_zayin                                0xce6  /* deprecated */
+#define XK_hebrew_chet                                 0xce7
+#define XK_hebrew_het                                  0xce7  /* deprecated */
+#define XK_hebrew_tet                                  0xce8
+#define XK_hebrew_teth                                 0xce8  /* deprecated */
+#define XK_hebrew_yod                                  0xce9
+#define XK_hebrew_finalkaph                            0xcea
+#define XK_hebrew_kaph                                 0xceb
+#define XK_hebrew_lamed                                0xcec
+#define XK_hebrew_finalmem                             0xced
+#define XK_hebrew_mem                                  0xcee
+#define XK_hebrew_finalnun                             0xcef
+#define XK_hebrew_nun                                  0xcf0
+#define XK_hebrew_samech                               0xcf1
+#define XK_hebrew_samekh                               0xcf1  /* deprecated */
+#define XK_hebrew_ayin                                 0xcf2
+#define XK_hebrew_finalpe                              0xcf3
+#define XK_hebrew_pe                                   0xcf4
+#define XK_hebrew_finalzade                            0xcf5
+#define XK_hebrew_finalzadi                            0xcf5  /* deprecated */
+#define XK_hebrew_zade                                 0xcf6
+#define XK_hebrew_zadi                                 0xcf6  /* deprecated */
+#define XK_hebrew_qoph                                 0xcf7
+#define XK_hebrew_kuf                                  0xcf7  /* deprecated */
+#define XK_hebrew_resh                                 0xcf8
+#define XK_hebrew_shin                                 0xcf9
+#define XK_hebrew_taw                                  0xcfa
+#define XK_hebrew_taf                                  0xcfa  /* deprecated */
+#define XK_Hebrew_switch        0xFF7E  /* Alias for mode_switch */
+#endif /* XK_HEBREW */
+
+/*
+ * Thai
+ * Byte 3 = d
+ */
+
+#ifdef XK_THAI
+#define XK_Thai_kokai                                  0xda1
+#define XK_Thai_khokhai                                        0xda2
+#define XK_Thai_khokhuat                               0xda3
+#define XK_Thai_khokhwai                               0xda4
+#define XK_Thai_khokhon                                        0xda5
+#define XK_Thai_khorakhang                             0xda6  
+#define XK_Thai_ngongu                                 0xda7  
+#define XK_Thai_chochan                                        0xda8  
+#define XK_Thai_choching                               0xda9   
+#define XK_Thai_chochang                               0xdaa  
+#define XK_Thai_soso                                   0xdab
+#define XK_Thai_chochoe                                        0xdac
+#define XK_Thai_yoying                                 0xdad
+#define XK_Thai_dochada                                        0xdae
+#define XK_Thai_topatak                                        0xdaf
+#define XK_Thai_thothan                                        0xdb0
+#define XK_Thai_thonangmontho                          0xdb1
+#define XK_Thai_thophuthao                             0xdb2
+#define XK_Thai_nonen                                  0xdb3
+#define XK_Thai_dodek                                  0xdb4
+#define XK_Thai_totao                                  0xdb5
+#define XK_Thai_thothung                               0xdb6
+#define XK_Thai_thothahan                              0xdb7
+#define XK_Thai_thothong                               0xdb8
+#define XK_Thai_nonu                                   0xdb9
+#define XK_Thai_bobaimai                               0xdba
+#define XK_Thai_popla                                  0xdbb
+#define XK_Thai_phophung                               0xdbc
+#define XK_Thai_fofa                                   0xdbd
+#define XK_Thai_phophan                                        0xdbe
+#define XK_Thai_fofan                                  0xdbf
+#define XK_Thai_phosamphao                             0xdc0
+#define XK_Thai_moma                                   0xdc1
+#define XK_Thai_yoyak                                  0xdc2
+#define XK_Thai_rorua                                  0xdc3
+#define XK_Thai_ru                                     0xdc4
+#define XK_Thai_loling                                 0xdc5
+#define XK_Thai_lu                                     0xdc6
+#define XK_Thai_wowaen                                 0xdc7
+#define XK_Thai_sosala                                 0xdc8
+#define XK_Thai_sorusi                                 0xdc9
+#define XK_Thai_sosua                                  0xdca
+#define XK_Thai_hohip                                  0xdcb
+#define XK_Thai_lochula                                        0xdcc
+#define XK_Thai_oang                                   0xdcd
+#define XK_Thai_honokhuk                               0xdce
+#define XK_Thai_paiyannoi                              0xdcf
+#define XK_Thai_saraa                                  0xdd0
+#define XK_Thai_maihanakat                             0xdd1
+#define XK_Thai_saraaa                                 0xdd2
+#define XK_Thai_saraam                                 0xdd3
+#define XK_Thai_sarai                                  0xdd4   
+#define XK_Thai_saraii                                 0xdd5   
+#define XK_Thai_saraue                                 0xdd6    
+#define XK_Thai_sarauee                                        0xdd7    
+#define XK_Thai_sarau                                  0xdd8    
+#define XK_Thai_sarauu                                 0xdd9   
+#define XK_Thai_phinthu                                        0xdda
+#define XK_Thai_maihanakat_maitho                      0xdde
+#define XK_Thai_baht                                   0xddf
+#define XK_Thai_sarae                                  0xde0    
+#define XK_Thai_saraae                                 0xde1
+#define XK_Thai_sarao                                  0xde2
+#define XK_Thai_saraaimaimuan                          0xde3   
+#define XK_Thai_saraaimaimalai                         0xde4  
+#define XK_Thai_lakkhangyao                            0xde5
+#define XK_Thai_maiyamok                               0xde6
+#define XK_Thai_maitaikhu                              0xde7
+#define XK_Thai_maiek                                  0xde8   
+#define XK_Thai_maitho                                 0xde9
+#define XK_Thai_maitri                                 0xdea
+#define XK_Thai_maichattawa                            0xdeb
+#define XK_Thai_thanthakhat                            0xdec
+#define XK_Thai_nikhahit                               0xded
+#define XK_Thai_leksun                                 0xdf0 
+#define XK_Thai_leknung                                        0xdf1  
+#define XK_Thai_leksong                                        0xdf2 
+#define XK_Thai_leksam                                 0xdf3
+#define XK_Thai_leksi                                  0xdf4  
+#define XK_Thai_lekha                                  0xdf5  
+#define XK_Thai_lekhok                                 0xdf6  
+#define XK_Thai_lekchet                                        0xdf7  
+#define XK_Thai_lekpaet                                        0xdf8  
+#define XK_Thai_lekkao                                 0xdf9 
+#endif /* XK_THAI */
+
+/*
+ *   Korean
+ *   Byte 3 = e
+ */
+
+#ifdef XK_KOREAN
+
+#define XK_Hangul              0xff31    /* Hangul start/stop(toggle) */
+#define XK_Hangul_Start                0xff32    /* Hangul start */
+#define XK_Hangul_End          0xff33    /* Hangul end, English start */
+#define XK_Hangul_Hanja                0xff34    /* Start Hangul->Hanja Conversion */
+#define XK_Hangul_Jamo         0xff35    /* Hangul Jamo mode */
+#define XK_Hangul_Romaja       0xff36    /* Hangul Romaja mode */
+#define XK_Hangul_Codeinput    0xff37    /* Hangul code input mode */
+#define XK_Hangul_Jeonja       0xff38    /* Jeonja mode */
+#define XK_Hangul_Banja                0xff39    /* Banja mode */
+#define XK_Hangul_PreHanja     0xff3a    /* Pre Hanja conversion */
+#define XK_Hangul_PostHanja    0xff3b    /* Post Hanja conversion */
+#define XK_Hangul_SingleCandidate      0xff3c    /* Single candidate */
+#define XK_Hangul_MultipleCandidate    0xff3d    /* Multiple candidate */
+#define XK_Hangul_PreviousCandidate    0xff3e    /* Previous candidate */
+#define XK_Hangul_Special      0xff3f    /* Special symbols */
+#define XK_Hangul_switch       0xFF7E    /* Alias for mode_switch */
+
+/* Hangul Consonant Characters */
+#define XK_Hangul_Kiyeog                               0xea1
+#define XK_Hangul_SsangKiyeog                          0xea2
+#define XK_Hangul_KiyeogSios                           0xea3
+#define XK_Hangul_Nieun                                        0xea4
+#define XK_Hangul_NieunJieuj                           0xea5
+#define XK_Hangul_NieunHieuh                           0xea6
+#define XK_Hangul_Dikeud                               0xea7
+#define XK_Hangul_SsangDikeud                          0xea8
+#define XK_Hangul_Rieul                                        0xea9
+#define XK_Hangul_RieulKiyeog                          0xeaa
+#define XK_Hangul_RieulMieum                           0xeab
+#define XK_Hangul_RieulPieub                           0xeac
+#define XK_Hangul_RieulSios                            0xead
+#define XK_Hangul_RieulTieut                           0xeae
+#define XK_Hangul_RieulPhieuf                          0xeaf
+#define XK_Hangul_RieulHieuh                           0xeb0
+#define XK_Hangul_Mieum                                        0xeb1
+#define XK_Hangul_Pieub                                        0xeb2
+#define XK_Hangul_SsangPieub                           0xeb3
+#define XK_Hangul_PieubSios                            0xeb4
+#define XK_Hangul_Sios                                 0xeb5
+#define XK_Hangul_SsangSios                            0xeb6
+#define XK_Hangul_Ieung                                        0xeb7
+#define XK_Hangul_Jieuj                                        0xeb8
+#define XK_Hangul_SsangJieuj                           0xeb9
+#define XK_Hangul_Cieuc                                        0xeba
+#define XK_Hangul_Khieuq                               0xebb
+#define XK_Hangul_Tieut                                        0xebc
+#define XK_Hangul_Phieuf                               0xebd
+#define XK_Hangul_Hieuh                                        0xebe
+
+/* Hangul Vowel Characters */
+#define XK_Hangul_A                                    0xebf
+#define XK_Hangul_AE                                   0xec0
+#define XK_Hangul_YA                                   0xec1
+#define XK_Hangul_YAE                                  0xec2
+#define XK_Hangul_EO                                   0xec3
+#define XK_Hangul_E                                    0xec4
+#define XK_Hangul_YEO                                  0xec5
+#define XK_Hangul_YE                                   0xec6
+#define XK_Hangul_O                                    0xec7
+#define XK_Hangul_WA                                   0xec8
+#define XK_Hangul_WAE                                  0xec9
+#define XK_Hangul_OE                                   0xeca
+#define XK_Hangul_YO                                   0xecb
+#define XK_Hangul_U                                    0xecc
+#define XK_Hangul_WEO                                  0xecd
+#define XK_Hangul_WE                                   0xece
+#define XK_Hangul_WI                                   0xecf
+#define XK_Hangul_YU                                   0xed0
+#define XK_Hangul_EU                                   0xed1
+#define XK_Hangul_YI                                   0xed2
+#define XK_Hangul_I                                    0xed3
+
+/* Hangul syllable-final (JongSeong) Characters */
+#define XK_Hangul_J_Kiyeog                             0xed4
+#define XK_Hangul_J_SsangKiyeog                                0xed5
+#define XK_Hangul_J_KiyeogSios                         0xed6
+#define XK_Hangul_J_Nieun                              0xed7
+#define XK_Hangul_J_NieunJieuj                         0xed8
+#define XK_Hangul_J_NieunHieuh                         0xed9
+#define XK_Hangul_J_Dikeud                             0xeda
+#define XK_Hangul_J_Rieul                              0xedb
+#define XK_Hangul_J_RieulKiyeog                                0xedc
+#define XK_Hangul_J_RieulMieum                         0xedd
+#define XK_Hangul_J_RieulPieub                         0xede
+#define XK_Hangul_J_RieulSios                          0xedf
+#define XK_Hangul_J_RieulTieut                         0xee0
+#define XK_Hangul_J_RieulPhieuf                                0xee1
+#define XK_Hangul_J_RieulHieuh                         0xee2
+#define XK_Hangul_J_Mieum                              0xee3
+#define XK_Hangul_J_Pieub                              0xee4
+#define XK_Hangul_J_PieubSios                          0xee5
+#define XK_Hangul_J_Sios                               0xee6
+#define XK_Hangul_J_SsangSios                          0xee7
+#define XK_Hangul_J_Ieung                              0xee8
+#define XK_Hangul_J_Jieuj                              0xee9
+#define XK_Hangul_J_Cieuc                              0xeea
+#define XK_Hangul_J_Khieuq                             0xeeb
+#define XK_Hangul_J_Tieut                              0xeec
+#define XK_Hangul_J_Phieuf                             0xeed
+#define XK_Hangul_J_Hieuh                              0xeee
+
+/* Ancient Hangul Consonant Characters */
+#define XK_Hangul_RieulYeorinHieuh                     0xeef
+#define XK_Hangul_SunkyeongeumMieum                    0xef0
+#define XK_Hangul_SunkyeongeumPieub                    0xef1
+#define XK_Hangul_PanSios                              0xef2
+#define XK_Hangul_KkogjiDalrinIeung                    0xef3
+#define XK_Hangul_SunkyeongeumPhieuf                   0xef4
+#define XK_Hangul_YeorinHieuh                          0xef5
+
+/* Ancient Hangul Vowel Characters */
+#define XK_Hangul_AraeA                                        0xef6
+#define XK_Hangul_AraeAE                               0xef7
+
+/* Ancient Hangul syllable-final (JongSeong) Characters */
+#define XK_Hangul_J_PanSios                            0xef8
+#define XK_Hangul_J_KkogjiDalrinIeung                  0xef9
+#define XK_Hangul_J_YeorinHieuh                                0xefa
+
+/* Korean currency symbol */
+#define XK_Korean_Won                                  0xeff
+
+#endif /* XK_KOREAN */
diff --git a/Xserver/lib/Imakefile b/Xserver/lib/Imakefile
new file mode 100644 (file)
index 0000000..b0e5fb6
--- /dev/null
@@ -0,0 +1,84 @@
+XCOMM $TOG: Imakefile /main/39 1997/02/26 18:09:44 kaleb $
+XCOMM $XFree86: xc/lib/Imakefile,v 3.17.2.2 1997/07/05 15:55:33 dawes Exp $
+#define IHaveSubdirs
+#define PassCDebugFlags
+
+#ifndef NeedBerklib
+#define NeedBerklib NO
+#endif
+
+#if NeedBerklib
+BERKDIR = Xbsd
+#endif
+
+#if BuildXKBlib
+XKBLIBDIR = xkbfile
+#endif
+
+#if BuildXKBuilib
+XKBUILIBDIR = xkbui
+#endif
+
+#if BuildThreadStubLibrary
+THRSTUBLIB = XThrStub
+#endif
+
+#if BuildScreenSaverLibrary
+SSLIB = Xss
+#endif
+
+#if BuildXF86MiscLibrary
+XF86MISCLIB = Xxf86misc
+#endif
+
+#if BuildXF86VidModeLibrary
+XF86VMLIB = Xxf86vm
+#endif
+
+#if BuildXF86DGALibrary
+XF86DGALIB = Xxf86dga
+#endif
+
+XF86EXTLIBS = $(XF86MISCLIB) $(XF86VMLIB) $(XF86DGALIB)
+
+#if BuildDPMSLibrary
+XDPMSLIBDIR = Xdpms
+#endif
+
+#if BuildLBX
+LBXUTILDIR = lbxutil
+#endif
+
+#if (BuildLBX || GzipFontCompression) && !HasZlib
+XCOMM ZLIBDIR = zlib
+#endif
+
+#if BuildXAudio
+XALIBDIR = Xa
+#endif
+
+FONTSUBDIR = font
+
+#if !BuildServersOnly
+LINTSUBDIRS = Xau Xdmcp $(THRSTUBLIB) X11 oldX ICE SM Xext Xt \
+            $(SSLIB) $(XF86MISCLIB) $(XF86VMLIB) $(XF86DGALIB) \
+            Xmu Xaw XIE Xi Xtst FS \
+            PEX5 $(XKBLIBDIR) $(XKBUILIBDIR) $(LBXUTILDIR) $(XALIBDIR) \
+            $(XDPMSLIBDIR) \
+            Xp $(ZLIBDIR)
+#else
+#if XnestServer
+XEXTDIR = Xext
+#endif
+
+LINTSUBDIRS = Xau Xdmcp X11 $(XEXTDIR) $(XKBLIBDIR) $(XKBUILIBDIR) \
+             $(LBXUTILDIR) $(XF86EXTLIBS) $(ZLIBDIR)
+#endif
+
+SUBDIRS = $(BERKDIR) xtrans $(LINTSUBDIRS) $(FONTSUBDIR)
+
+MakeSubdirs($(SUBDIRS))
+DependSubdirs($(SUBDIRS))
+MakeLintLibSubdirs($(LINTSUBDIRS))
+MakeLintSubdirs($(LINTSUBDIRS),install.ln,install.ln)
+
diff --git a/Xserver/lib/X11/Imakefile b/Xserver/lib/X11/Imakefile
new file mode 100644 (file)
index 0000000..a257971
--- /dev/null
@@ -0,0 +1,989 @@
+XCOMM $TOG: Imakefile /main/196 1997/05/20 10:06:09 kaleb $
+
+
+
+
+XCOMM $XFree86: xc/lib/X11/Imakefile,v 3.19.2.2 1997/05/21 15:02:16 dawes Exp $
+#define DoNormalLib NormalLibX11
+#define DoSharedLib SharedLibX11
+#define DoDebugLib DebugLibX11
+#define DoProfileLib ProfileLibX11
+#define LibName X11
+#define SoRev SOXLIBREV
+#define HugeLibrary YES
+#define IncSubdir X11
+
+#include <Threads.tmpl>
+
+#ifndef MotifBC
+#define MotifBC NO
+#endif
+
+#ifdef SharedX11Reqs
+REQUIREDLIBS = SharedX11Reqs
+#endif
+#if defined(MacIIArchitecture) || defined(SequentArchitecture) || defined(i386ScoArchitecture)
+XBSDLIB = /**/
+#endif
+#if defined(LunaArchitecture) && defined(Mc88000Architecture)
+EXTRA_LIBRARIES = /**/
+#endif
+#if Malloc0ReturnsNull
+     MALLOC_DEFINES = XMalloc0ReturnsNullDefines
+#endif
+#if HasXdmAuth
+        XDMAUTHDEFS = -DHASXDMAUTH
+        XDMAUTHOBJS = Wrap.o Wraphelp.o
+        XDMAUTHSRCS = Wrap.c Wraphelp.c
+#endif
+#if BuildXKBlib
+    XKB_DEFINES = -DXKB 
+        XKBSRCS = XKB.c XKBBind.c XKBCompat.c XKBCtrls.c XKBCvt.c XKBGetMap.c \
+                 XKBGetByName.c XKBNames.c XKBRdBuf.c XKBSetMap.c XKBUse.c \
+                 XKBleds.c XKBBell.c XKBGeom.c XKBSetGeom.c XKBExtDev.c \
+                 XKBList.c XKBMisc.c \
+                 XKBMAlloc.c XKBGAlloc.c XKBAlloc.c
+        XKBOBJS = XKB.o XKBBind.o XKBCompat.o XKBCtrls.o XKBCvt.o XKBGetMap.o \
+                 XKBGetByName.o XKBNames.o XKBRdBuf.o XKBSetMap.o XKBUse.o \
+                 XKBleds.o XKBBell.o XKBGeom.o XKBSetGeom.o XKBExtDev.o \
+                 XKBList.o XKBMisc.o \
+                 XKBMAlloc.o XKBGAlloc.o XKBAlloc.o
+#endif
+#if HasSecureRPC
+        RPCDEFS = -DSECURE_RPC
+#endif
+#if HasPoll
+   POLL_DEFINES = -DUSE_POLL
+#endif
+   CONN_DEFINES = ConnectionFlags
+   XTRANS_X_DEFINES = -DX11_t -DTRANS_CLIENT
+   XTRANS_XIM_DEFINES = -DXIM_t -DTRANS_CLIENT
+#if HasBSD44Sockets
+   SOCK_DEFINES = -DBSD44SOCKETS
+#endif
+     EDB_DEFINES = -DERRORDB=\"$(LIBDIR)/XErrorDB\"
+     KDB_DEFINES = -DKEYSYMDB=\"$(LIBDIR)/XKeysymDB\"
+     CMS_DEFINES = -DXCMSDB=\"$(LIBDIR)/Xcms.txt\"
+#if HasSnprintf
+    MISC_DEFINES = -DHAS_SNPRINTF -DLIBX11
+#endif
+#if MotifBC
+      BC_DEFINES = -DMOTIFBC
+#endif
+#if NoRConst
+ RCONST_DEFINES = -DNORCONST
+#endif
+    XLC_DEFINES = -DXLOCALEDIR=\"$(XLOCALEDIR)\"
+#if HasKrb5
+         K5OBJS = k5encode.o
+         K5SRCS = k5encode.c
+         K5INCL = Krb5Includes
+         K5DEFS = Krb5Defines
+#endif
+#if !HasSnprintf
+       MISCSRCS = snprintf.c
+       MISCOBJS = snprintf.o
+#endif
+#if NeedLibInsideFlag
+    LIB_DEFINES = -D_XLIBINT_
+#endif
+        DEFINES = $(MALLOC_DEFINES) $(LIB_DEFINES)
+   OPEN_DEFINES = -I$(EXTINCSRC) $(K5INCL) $(K5DEFS)
+ DEPEND_DEFINES = $(OPEN_DEFINES) $(TRANS_INCLUDES) $(CONN_DEFINES) $(THREADS_DEFINES)
+       AUTHOBJS = AuDispose.o AuGetBest.o AuFileName.o AuRead.o
+       AUTHSRCS = AuDispose.c AuGetBest.c AuFileName.c AuRead.c
+           SRCS = $(SRCS1) $(SRCS2) $(SRCS3) /* try *.c if you have trouble */
+        HEADERS = Xlib.h Xresource.h Xutil.h cursorfont.h Xlibint.h \
+                       Xcms.h Xlocale.h XKBlib.h
+       LINTLIBS =
+
+SRCS1 = \
+       Context.c \
+       Depths.c \
+       ParseCmd.c \
+       Quarks.c \
+       AllCells.c \
+       AllPlanes.c \
+       AllowEv.c \
+       AutoRep.c \
+       Backgnd.c \
+       BdrWidth.c \
+       Bell.c \
+       Border.c \
+       ChAccCon.c \
+       ChClMode.c \
+       ChActPGb.c \
+       ChCmap.c \
+       ChGC.c \
+       ChKeyCon.c \
+       ChPntCon.c \
+       ChProp.c \
+       ChSaveSet.c \
+       ChWAttrs.c \
+       ChWindow.c \
+       ChkIfEv.c \
+       ChkMaskEv.c \
+       ChkWinEv.c \
+       ChkTypEv.c \
+       ChkTypWEv.c \
+       CirWin.c \
+       CirWinDn.c \
+       CirWinUp.c \
+       ClDisplay.c \
+       Clear.c \
+       ClearArea.c \
+       ConfWind.c \
+       ConnDis.c \
+       ConvSel.c \
+       CopyArea.c \
+       CopyCmap.c \
+       CopyGC.c \
+       CopyPlane.c \
+       CrBFData.c \
+       CrCmap.c \
+       CrCursor.c \
+       CrGC.c \
+       CrGlCur.c \
+       CrPFBData.c \
+       CrPixmap.c \
+       CrWindow.c \
+       Cursor.c \
+       DefCursor.c \
+       DelProp.c \
+       DestSubs.c \
+       DestWind.c \
+       DisName.c \
+       DrArc.c \
+       DrArcs.c \
+       DrLine.c \
+       DrLines.c \
+       DrPoint.c \
+       DrPoints.c \
+       DrRect.c \
+       DrRects.c \
+       DrSegs.c \
+       ErrDes.c \
+       ErrHndlr.c \
+       EvToWire.c \
+       FetchName.c \
+       FillArc.c \
+       FillArcs.c \
+       FillPoly.c \
+       FillRct.c \
+       FillRcts.c \
+       Flush.c \
+       Font.c \
+       FontNames.c \
+       FontInfo.c \
+       FreeCmap.c \
+       FreeCols.c \
+       FreeCurs.c \
+       FreeEData.c \
+       FreeGC.c \
+       FreePix.c \
+       FSSaver.c \
+       GCMisc.c \
+       Geom.c \
+       GetAtomNm.c \
+       GetColor.c \
+       GetDflt.c \
+       GetFPath.c \
+       GetFProp.c \
+       GetGeom.c \
+       GetHColor.c \
+       GetHints.c \
+       GetIFocus.c \
+       GetImage.c \
+       GetKCnt.c \
+       GetMoEv.c \
+       GetPCnt.c \
+       GetPntMap.c \
+       GetProp.c \
+       GetSOwner.c \
+       GetSSaver.c \
+       GetStCmap.c \
+       GetWAttrs.c \
+       GrButton.c \
+       GrKey.c \
+       GrKeybd.c \
+       GrPointer.c \
+       GrServer.c \
+       Host.c \
+       IfEvent.c \
+       ImUtil.c \
+       ImText.c \
+       ImText16.c \
+       InitExt.c \
+       InsCmap.c \
+       IntAtom.c \
+       KeyBind.c \
+       KeysymStr.c \
+       KillCl.c \
+       LiHosts.c \
+       LiICmaps.c \
+       LiProps.c \
+       ListExt.c \
+       LoadFont.c \
+       LookupCol.c \
+       LowerWin.c 
+
+OBJS1 = \
+       Context.o \
+       Depths.o \
+       ParseCmd.o \
+       Quarks.o \
+       AllCells.o \
+       AllPlanes.o \
+       AllowEv.o \
+       AutoRep.o \
+       Backgnd.o \
+       BdrWidth.o \
+       Bell.o \
+       Border.o \
+       ChAccCon.o \
+       ChClMode.o \
+       ChActPGb.o \
+       ChCmap.o \
+       ChGC.o \
+       ChKeyCon.o \
+       ChPntCon.o \
+       ChProp.o \
+       ChSaveSet.o \
+       ChWAttrs.o \
+       ChWindow.o \
+       ChkIfEv.o \
+       ChkMaskEv.o \
+       ChkWinEv.o \
+       ChkTypEv.o \
+       ChkTypWEv.o \
+       CirWin.o \
+       CirWinDn.o \
+       CirWinUp.o \
+       ClDisplay.o \
+       Clear.o \
+       ClearArea.o \
+       ConfWind.o \
+       ConnDis.o \
+       ConvSel.o \
+       CopyArea.o \
+       CopyCmap.o \
+       CopyGC.o \
+       CopyPlane.o \
+       CrBFData.o \
+       CrCmap.o \
+       CrCursor.o \
+       CrGC.o \
+       CrGlCur.o \
+       CrPFBData.o \
+       CrPixmap.o \
+       CrWindow.o \
+       Cursor.o \
+       DefCursor.o \
+       DelProp.o \
+       DestSubs.o \
+       DestWind.o \
+       DisName.o \
+       DrArc.o \
+       DrArcs.o \
+       DrLine.o \
+       DrLines.o \
+       DrPoint.o \
+       DrPoints.o \
+       DrRect.o \
+       DrRects.o \
+       DrSegs.o \
+       ErrDes.o \
+       ErrHndlr.o \
+       EvToWire.o \
+       FetchName.o \
+       FillArc.o \
+       FillArcs.o \
+       FillPoly.o \
+       FillRct.o \
+       FillRcts.o \
+       Flush.o \
+       Font.o \
+       FontNames.o \
+       FontInfo.o \
+       FreeCmap.o \
+       FreeCols.o \
+       FreeCurs.o \
+       FreeEData.o \
+       FreeGC.o \
+       FreePix.o \
+       FSSaver.o \
+       GCMisc.o \
+       Geom.o \
+       GetAtomNm.o \
+       GetColor.o \
+       GetDflt.o \
+       GetFPath.o \
+       GetFProp.o \
+       GetGeom.o \
+       GetHColor.o \
+       GetHints.o \
+       GetIFocus.o \
+       GetImage.o \
+       GetKCnt.o \
+       GetMoEv.o \
+       GetPCnt.o \
+       GetPntMap.o \
+       GetProp.o \
+       GetSOwner.o \
+       GetSSaver.o \
+       GetStCmap.o \
+       GetWAttrs.o \
+       GrButton.o \
+       GrKey.o \
+       GrKeybd.o \
+       GrPointer.o \
+       GrServer.o \
+       Host.o \
+       IfEvent.o \
+       ImUtil.o \
+       ImText.o \
+       ImText16.o \
+       InitExt.o \
+       InsCmap.o \
+       IntAtom.o \
+       KeyBind.o \
+       KeysymStr.o \
+       KillCl.o \
+       LiHosts.o \
+       LiICmaps.o \
+       LiProps.o \
+       ListExt.o \
+       LoadFont.o \
+       LookupCol.o \
+       LowerWin.o 
+
+SRCS2 = \
+       Macros.c \
+       MapRaised.c \
+       MapSubs.c \
+       MapWindow.c \
+       MaskEvent.c \
+       Misc.c \
+       ModMap.c \
+       MoveWin.c \
+       NextEvent.c \
+       OpenDis.c \
+       ParseCol.c \
+       ParseGeom.c \
+       PeekEvent.c \
+       PeekIfEv.c \
+       Pending.c \
+       PmapBgnd.c \
+       PmapBord.c \
+       PolyReg.c \
+       PolyTxt.c \
+       PolyTxt16.c \
+       PutBEvent.c \
+       PutImage.c \
+       QuBest.c \
+       QuColor.c \
+       QuColors.c \
+       QuCurShp.c \
+       QuExt.c \
+       QuKeybd.c \
+       QuPntr.c \
+       QuStipShp.c \
+       QuTextE16.c \
+       QuTextExt.c \
+       QuTileShp.c \
+       QuTree.c \
+       RaiseWin.c \
+       RdBitF.c \
+       RecolorC.c \
+       ReconfWin.c \
+       Region.c \
+       RepWindow.c \
+       RestackWs.c \
+       RotProp.c \
+       ScrResStr.c \
+       SelInput.c \
+       SendEvent.c \
+       SetBack.c \
+       SetCRects.c \
+       SetClMask.c \
+       SetClOrig.c \
+       SetDashes.c \
+       SetFPath.c \
+       SetFont.c \
+       SetFore.c \
+       SetFunc.c \
+       SetHints.c \
+       SetIFocus.c \
+       SetLStyle.c \
+       SetPMask.c \
+       SetPntMap.c \
+       SetSOwner.c \
+       SetSSaver.c \
+       SetState.c \
+       SetStip.c \
+       SetStCmap.c \
+       SetTile.c \
+       SetTSOrig.c \
+       StBytes.c \
+       StColor.c \
+       StColors.c \
+       StNColor.c \
+       StName.c \
+       StrKeysym.c \
+       Sync.c \
+       Synchro.c \
+       Text.c \
+       Text16.c \
+       TextExt.c \
+       TextExt16.c \
+       TrCoords.c \
+       UndefCurs.c \
+       UngrabBut.c \
+       UngrabKbd.c \
+       UngrabKey.c \
+       UngrabPtr.c \
+       UngrabSvr.c \
+       UninsCmap.c \
+       UnldFont.c \
+       UnmapSubs.c \
+       UnmapWin.c \
+       VisUtil.c \
+       WarpPtr.c \
+       WinEvent.c \
+       Window.c \
+       WrBitF.c \
+       XlibAsync.c \
+       XlibInt.c \
+       Xrm.c \
+       evtomask.c \
+       globals.c \
+       GetGCVals.c \
+       GetNrmHint.c \
+       GetRGBCMap.c \
+       GetTxtProp.c \
+       GetWMCMapW.c \
+       GetWMProto.c \
+       Iconify.c \
+       PixFormats.c \
+       PropAlloc.c \
+       ReconfWM.c \
+       SetNrmHint.c \
+       SetRGBCMap.c \
+       SetTxtProp.c \
+       SetWMCMapW.c \
+       SetWMProto.c \
+       StrToText.c \
+       TextToStr.c \
+       Withdraw.c \
+       WMGeom.c \
+       WMProps.c \
+       $(AUTHSRCS) $(XDMAUTHSRCS) $(K5SRCS)
+
+OBJS2 = \
+       Macros.o \
+       MapRaised.o \
+       MapSubs.o \
+       MapWindow.o \
+       MaskEvent.o \
+       Misc.o \
+       ModMap.o \
+       MoveWin.o \
+       NextEvent.o \
+       OpenDis.o \
+       ParseCol.o \
+       ParseGeom.o \
+       PeekEvent.o \
+       PeekIfEv.o \
+       Pending.o \
+       PmapBgnd.o \
+       PmapBord.o \
+       PolyReg.o \
+       PolyTxt.o \
+       PolyTxt16.o \
+       PutBEvent.o \
+       PutImage.o \
+       QuBest.o \
+       QuColor.o \
+       QuColors.o \
+       QuCurShp.o \
+       QuExt.o \
+       QuKeybd.o \
+       QuPntr.o \
+       QuStipShp.o \
+       QuTextE16.o \
+       QuTextExt.o \
+       QuTileShp.o \
+       QuTree.o \
+       RaiseWin.o \
+       RdBitF.o \
+       RecolorC.o \
+       ReconfWin.o \
+       Region.o \
+       RepWindow.o \
+       RestackWs.o \
+       RotProp.o \
+       ScrResStr.o \
+       SelInput.o \
+       SendEvent.o \
+       SetBack.o \
+       SetCRects.o \
+       SetClMask.o \
+       SetClOrig.o \
+       SetDashes.o \
+       SetFPath.o \
+       SetFont.o \
+       SetFore.o \
+       SetFunc.o \
+       SetHints.o \
+       SetIFocus.o \
+       SetLStyle.o \
+       SetPMask.o \
+       SetPntMap.o \
+       SetSOwner.o \
+       SetSSaver.o \
+       SetState.o \
+       SetStip.o \
+       SetStCmap.o \
+       SetTile.o \
+       SetTSOrig.o \
+       StBytes.o \
+       StColor.o \
+       StColors.o \
+       StNColor.o \
+       StName.o \
+       StrKeysym.o \
+       Sync.o \
+       Synchro.o \
+       Text.o \
+       Text16.o \
+       TextExt.o \
+       TextExt16.o \
+       TrCoords.o \
+       UndefCurs.o \
+       UngrabBut.o \
+       UngrabKbd.o \
+       UngrabKey.o \
+       UngrabPtr.o \
+       UngrabSvr.o \
+       UninsCmap.o \
+       UnldFont.o \
+       UnmapSubs.o \
+       UnmapWin.o \
+       VisUtil.o \
+       WarpPtr.o \
+       WinEvent.o \
+       Window.o \
+       WrBitF.o \
+       XlibAsync.o \
+       XlibInt.o \
+       Xrm.o \
+       evtomask.o \
+       globals.o \
+       GetGCVals.o \
+       GetNrmHint.o \
+       GetRGBCMap.o \
+       GetTxtProp.o \
+       GetWMCMapW.o \
+       GetWMProto.o \
+       Iconify.o \
+       PixFormats.o \
+       PropAlloc.o \
+       ReconfWM.o \
+       SetNrmHint.o \
+       SetRGBCMap.o \
+       SetTxtProp.o \
+       SetWMCMapW.o \
+       SetWMProto.o \
+       StrToText.o \
+       TextToStr.o \
+       Withdraw.o \
+       WMGeom.o \
+       WMProps.o \
+       $(AUTHOBJS) \
+       $(XDMAUTHOBJS) \
+       $(K5OBJS)
+
+SRCS3 = \
+       Lab.c \
+       LabGcC.c \
+       LabGcL.c \
+       LabGcLC.c \
+       LabMnL.c \
+       LabMxC.c \
+       LabMxL.c \
+       LabMxLC.c \
+       LabWpAj.c \
+       Luv.c \
+       LuvGcC.c \
+       LuvGcL.c \
+       LuvGcLC.c \
+       LuvMnL.c \
+       LuvMxC.c \
+       LuvMxL.c \
+       LuvMxLC.c \
+       LuvWpAj.c \
+       XYZ.c \
+       uvY.c \
+       xyY.c \
+       HVC.c \
+       HVCGcC.c \
+       HVCGcV.c \
+       HVCGcVC.c \
+       HVCMnV.c \
+       HVCMxC.c \
+       HVCMxV.c \
+       HVCMxVC.c \
+       HVCMxVs.c \
+       HVCWpAj.c \
+       UNDEFINED.c \
+       AddDIC.c \
+       AddSF.c \
+       cmsAllNCol.c \
+       cmsAllCol.c \
+       CCC.c \
+       cmsCmap.c \
+       cmsColNm.c \
+       CvColW.c \
+       CvCols.c \
+       cmsGlobls.c \
+       IdOfPr.c \
+       cmsInt.c \
+       LRGB.c \
+       cmsLkCol.c \
+       cmsMath.c \
+       OfCCC.c \
+       PrOfId.c \
+       cmsProp.c \
+       QBlack.c \
+       QBlue.c \
+       QGreen.c \
+       QRed.c \
+       QWhite.c \
+       QuCol.c \
+       QuCols.c \
+       SetCCC.c \
+       SetGetCols.c \
+       StCol.c \
+       StCols.c \
+       cmsTrig.c \
+       XRGB.c \
+       FSWrap.c \
+       ICWrap.c \
+       IMWrap.c \
+       OCWrap.c \
+       OMWrap.c \
+       lcWrap.c \
+       mbWMProps.c \
+       mbWrap.c \
+       wcWrap.c \
+       FilterEv.c \
+       RegstFlt.c \
+       locking.c \
+       LockDis.c \
+       x11trans.c \
+       ximtrans.c \
+       $(XKBSRCS) $(LCSRCS) $(MISCSRCS)
+
+OBJS3 = \
+       Lab.o \
+       LabGcC.o \
+       LabGcL.o \
+       LabGcLC.o \
+       LabMnL.o \
+       LabMxC.o \
+       LabMxL.o \
+       LabMxLC.o \
+       LabWpAj.o \
+       Luv.o \
+       LuvGcC.o \
+       LuvGcL.o \
+       LuvGcLC.o \
+       LuvMnL.o \
+       LuvMxC.o \
+       LuvMxL.o \
+       LuvMxLC.o \
+       LuvWpAj.o \
+       XYZ.o \
+       uvY.o \
+       xyY.o \
+       HVC.o \
+       HVCGcC.o \
+       HVCGcV.o \
+       HVCGcVC.o \
+       HVCMnV.o \
+       HVCMxC.o \
+       HVCMxV.o \
+       HVCMxVC.o \
+       HVCMxVs.o \
+       HVCWpAj.o \
+       UNDEFINED.o \
+       AddDIC.o \
+       AddSF.o \
+       cmsAllNCol.o \
+       cmsAllCol.o \
+       CCC.o \
+       cmsCmap.o \
+       cmsColNm.o \
+       CvColW.o \
+       CvCols.o \
+       cmsGlobls.o \
+       IdOfPr.o \
+       cmsInt.o \
+       LRGB.o \
+       cmsLkCol.o \
+       cmsMath.o \
+       OfCCC.o \
+       PrOfId.o \
+       cmsProp.o \
+       QBlack.o \
+       QBlue.o \
+       QGreen.o \
+       QRed.o \
+       QWhite.o \
+       QuCol.o \
+       QuCols.o \
+       SetCCC.o \
+       SetGetCols.o \
+       StCol.o \
+       StCols.o \
+       cmsTrig.o \
+       XRGB.o \
+       FSWrap.o \
+       ICWrap.o \
+       IMWrap.o \
+       OCWrap.o \
+       OMWrap.o \
+       lcWrap.o \
+       mbWMProps.o \
+       mbWrap.o \
+       wcWrap.o \
+       FilterEv.o \
+       RegstFlt.o \
+       locking.o \
+       LockDis.o \
+       x11trans.o \
+       ximtrans.o \
+       $(XKBOBJS) $(LCOBJS) $(MISCOBJS)
+
+#ifdef RsArchitecture
+LCDEPSYMSRCS = aixlcLoad.c
+#endif
+#ifdef OS2Architecture
+LCDEPSYMSRCS = os2Stubs.c
+#endif
+
+LCSRCS = \
+       SetLocale.c \
+       $(LCDEPSYMSRCS) \
+       imCallbk.c \
+       imConv.c \
+       imDefFlt.c \
+       imDefIc.c \
+       imDefIm.c \
+       imDefLkup.c \
+       imDispch.c \
+       imEvToWire.c \
+       imExten.c \
+       imImSw.c \
+       imInsClbk.c \
+       imInt.c \
+       imLcFlt.c \
+       imLcGIc.c \
+       imLcIc.c \
+       imLcIm.c \
+       imLcLkup.c \
+       imLcPrs.c \
+       imLcSIc.c \
+       imRm.c \
+       imRmAttr.c \
+       imThaiFlt.c \
+       imThaiIc.c \
+       imThaiIm.c \
+       imTrX.c \
+       imTransR.c \
+       imTrans.c \
+       lcCT.c \
+       lcCharSet.c \
+       lcConv.c \
+       lcDB.c \
+       lcDefConv.c \
+       lcEuc.c \
+       lcFile.c \
+       lcGenConv.c \
+       lcGeneric.c \
+       lcInit.c \
+       lcJis.c \
+       lcPrTxt.c \
+       lcPubWrap.c \
+       lcPublic.c \
+       lcRM.c \
+       lcSjis.c \
+       lcStd.c \
+       lcTxtPr.c \
+       lcUTF.c \
+       lcUtil.c \
+       omDefault.c \
+       omGeneric.c \
+       omImText.c \
+       omText.c \
+       omTextEsc.c \
+       omTextExt.c \
+       omTextPer.c \
+       omXChar.c
+
+/*
+#if defined(SunArchitecture) && defined(HasSharedLibraries)
+LCDEPOBJS = XsunDL.o
+#endif
+*/
+#ifdef RsArchitecture
+LCDEPOBJS = aixlcLoad.o
+#endif
+#ifdef OS2Architecture
+LCDEPOBJS = os2Stubs.o
+#endif
+
+LCOBJS = \
+       SetLocale.o \
+       $(LCDEPOBJS) \
+       imCallbk.o \
+       imConv.o \
+       imDefFlt.o \
+       imDefIc.o \
+       imDefIm.o \
+       imDefLkup.o \
+       imDispch.o \
+       imEvToWire.o \
+       imExten.o \
+       imImSw.o \
+       imInsClbk.o \
+       imInt.o \
+       imLcFlt.o \
+       imLcGIc.o \
+       imLcIc.o \
+       imLcIm.o \
+       imLcLkup.o \
+       imLcPrs.o \
+       imLcSIc.o \
+       imRm.o \
+       imRmAttr.o \
+       imThaiFlt.o \
+       imThaiIc.o \
+       imThaiIm.o \
+       imTrX.o \
+       imTransR.o \
+       imTrans.o \
+       lcCT.o \
+       lcCharSet.o \
+       lcConv.o \
+       lcDB.o \
+       lcDefConv.o \
+       lcEuc.o \
+       lcFile.o \
+       lcGenConv.o \
+       lcGeneric.o \
+       lcInit.o \
+       lcJis.o \
+       lcPrTxt.o \
+       lcPubWrap.o \
+       lcPublic.o \
+       lcRM.o \
+       lcSjis.o \
+       lcStd.o \
+       lcTxtPr.o \
+       lcUTF.o \
+       lcUtil.o \
+       omDefault.o \
+       omGeneric.o \
+       omImText.o \
+       omText.o \
+       omTextEsc.o \
+       omTextExt.o \
+       omTextPer.o \
+       omXChar.o
+
+OBJS = $(OBJS1) $(OBJS2) $(OBJS3)
+
+#if !BuildServersOnly || XnestServer
+#include <Library.tmpl>
+
+SpecialCLibObjectRule(ErrDes,$(ICONFIGFILES),$(EDB_DEFINES))
+SpecialCLibObjectRule(StrKeysym,$(ICONFIGFILES),$(KDB_DEFINES))
+SpecialCLibObjectRule(ConnDis,$(ICONFIGFILES),$(XDMAUTHDEFS) $(RPCDEFS) $(CONN_DEFINES) $(SOCK_DEFINES) $(POLL_DEFINES) $(XTRANS_X_DEFINES) $(K5INCL) $(K5DEFS))
+SpecialCLibObjectRule(x11trans,$(ICONFIGFILES),$(TRANS_INCLUDES) $(CONN_DEFINES) $(SOCK_DEFINES) $(XTRANS_X_DEFINES) $(POLL_DEFINES))
+LinkFile(x11trans.c,$(TRANSCOMMSRC)/transport.c)
+SpecialCLibObjectRule(ximtrans,$(ICONFIGFILES),$(TRANS_INCLUDES) $(CONN_DEFINES) $(SOCK_DEFINES) $(XTRANS_XIM_DEFINES) $(POLL_DEFINES))
+LinkFile(ximtrans.c,$(TRANSCOMMSRC)/transport.c)
+SpecialCLibObjectRule(OpenDis,$(ICONFIGFILES),$(BC_DEFINES) $(OPEN_DEFINES) $(XTRANS_X_DEFINES) $(XKB_DEFINES))
+SpecialCLibObjectRule(Wrap,$(ICONFIGFILES),$(XDMAUTHDEFS))
+SpecialCLibObjectRule(XlibInt,$(ICONFIGFILES),-I$(EXTINCSRC) $(CONN_DEFINES) $(POLL_DEFINES) $(XTRANS_X_DEFINES))
+SpecialCLibObjectRule(cmsColNm,$(ICONFIGFILES),$(CMS_DEFINES))
+SpecialCLibObjectRule(globals,$(ICONFIGFILES),$(CONN_DEFINES))
+SpecialCLibObjectRule(Context,$(ICONFIGFILES),$(BC_DEFINES))
+SpecialCLibObjectRule(Xrm,$(_NOOP_),$(RCONST_DEFINES))
+SpecialCLibObjectRule(imTransR,$(ICONFIGFILES),$(CONN_DEFINES) $(XTRANS_XIM_DEFINES))
+SpecialCLibObjectRule(imTrans,$(ICONFIGFILES),$(CONN_DEFINES) $(XTRANS_XIM_DEFINES))
+SpecialCLibObjectRule(lcFile,$(ICONFIGFILES),$(XLC_DEFINES))
+#if BuildXKBlib
+SpecialCLibObjectRule(XKBCvt,$(_NOOP_),$(RCONST_DEFINES))
+SpecialCLibObjectRule(KeyBind,$(ICONFIGFILES),$(XKB_DEFINES))
+SpecialCLibObjectRule(XKBBind,$(ICONFIGFILES),$(XKB_DEFINES))
+SpecialCLibObjectRule(imConv,$(ICONFIGFILES),$(XKB_DEFINES))
+#endif
+#if HasKrb5
+SpecialCLibObjectRule(k5encode,$(_NOOP_),$(K5INCL))
+#endif
+#ifdef MinixArchitecture
+SpecialCLibObjectRule(IMWrap,$(ICONFIGFILES),-DX11_TINY_IM)
+SpecialCLibObjectRule(lcInit,$(ICONFIGFILES),-DX11_TINY_LC)
+#endif
+
+#if InstallXcmsTxt
+InstallNonExecFile(Xcms.txt,$(LIBDIR))
+#endif
+InstallNonExecFile(XErrorDB,$(LIBDIR))
+InstallNonExecFile(XKeysymDB,$(LIBDIR))
+InstallLintLibrary(X11,$(LINTLIBDIR))
+
+
+LinkSourceFile(AuDispose.c,$(XAUTHSRC))
+LinkSourceFile(AuGetBest.c,$(XAUTHSRC))
+LinkSourceFile(AuFileName.c,$(XAUTHSRC))
+LinkSourceFile(AuRead.c,$(XAUTHSRC))
+#if HasKrb5
+LinkSourceFile(k5encode.c,$(XAUTHSRC))
+#endif
+#if HasXdmAuth
+LinkSourceFile(Wrap.h,$(XDMCPLIBSRC))
+LinkSourceFile(Wrap.c,$(XDMCPLIBSRC))
+LinkSourceFile(Wraphelp.c,$(XDMCPLIBSRC))
+#endif
+
+#if !HasSnprintf
+LinkSourceFile(snprintf.c,../misc)
+SpecialCLibObjectRule(snprintf,$(ICONFIGFILES),-DLIBX11)
+#endif
+LinkSourceFile(snprintf.h,../misc)
+
+MAKEKEYS = ./makekeys
+
+ks_tables.h: $(XINCLUDESRC)/keysymdef.h util/makekeys.c
+       RemoveFiles($@ ProgramTargetName(makekeys) makekeys.Osuf)
+       -HostLinkRule(ProgramTargetName(makekeys),$(CFLAGS) $(LOCAL_LDFLAGS),util/makekeys.c,$(LDLIBS))
+       RunProgram(MAKEKEYS,< $(XINCLUDESRC)/keysymdef.h > ks_tables_h)
+       $(MV) ks_tables_h $@
+       RemoveFiles(ProgramTargetName(makekeys) makekeys.Osuf ks_tables_h)
+
+includes:: ks_tables.h
+
+depend:: ks_tables.h
+
+clean::
+       RemoveFiles(ks_tables_h ks_tables.h ProgramTargetName(makekeys))
+
+DependTarget3($(SRCS1),$(SRCS2),$(SRCS3))
+#else
+all::
+
+BuildIncludes($(HEADERS),IncSubdir,..)
+#endif
diff --git a/Xserver/lib/X11/XKBlib.h b/Xserver/lib/X11/XKBlib.h
new file mode 100644 (file)
index 0000000..ac354d1
--- /dev/null
@@ -0,0 +1,1335 @@
+/* $XConsortium: XKBlib.h /main/17 1996/03/01 14:30:14 kaleb $ */
+/************************************************************
+Copyright (c) 1993 by Silicon Graphics Computer Systems, Inc.
+
+Permission to use, copy, modify, and distribute this
+software and its documentation for any purpose and without
+fee is hereby granted, provided that the above copyright
+notice appear in all copies and that both that copyright
+notice and this permission notice appear in supporting
+documentation, and that the name of Silicon Graphics not be 
+used in advertising or publicity pertaining to distribution 
+of the software without specific prior written permission.
+Silicon Graphics makes no representation about the suitability 
+of this software for any purpose. It is provided "as is"
+without any express or implied warranty.
+
+SILICON GRAPHICS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS 
+SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 
+AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
+GRAPHICS BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL 
+DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, 
+DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE 
+OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION  WITH
+THE USE OR PERFORMANCE OF THIS SOFTWARE.
+
+********************************************************/
+
+#ifndef _XKBLIB_H_
+#define _XKBLIB_H_
+
+#include <X11/extensions/XKBstr.h>
+
+typedef struct _XkbAnyEvent {
+       int             type;           /* XkbAnyEvent */
+       unsigned long   serial;         /* # of last req processed by server */
+       Bool            send_event;     /* is this from a SendEvent request? */
+       Display *       display;        /* Display the event was read from */
+       Time            time;           /* milliseconds */
+       int             xkb_type;       /* XKB event minor code */
+       unsigned int    device;         /* device ID */
+} XkbAnyEvent;
+
+typedef struct _XkbNewKeyboardNotify {
+       int             type;           /* XkbAnyEvent */
+       unsigned long   serial;         /* of last req processed by server */
+       Bool            send_event;     /* is this from a SendEvent request? */
+       Display *       display;        /* Display the event was read from */
+       Time            time;           /* milliseconds */
+       int             xkb_type;       /* XkbNewKeyboardNotify */
+       int             device;         /* device ID */
+       int             old_device;     /* device ID of previous keyboard */
+       int             min_key_code;   /* minimum key code */
+       int             max_key_code;   /* maximum key code */
+       int             old_min_key_code;/* min key code of previous kbd */
+       int             old_max_key_code;/* max key code of previous kbd */
+       unsigned int    changed;        /* changed aspects of the keyboard */
+       char            req_major;      /* major and minor opcode of req */
+       char            req_minor;      /* that caused change, if applicable */
+} XkbNewKeyboardNotifyEvent;
+
+typedef struct _XkbMapNotifyEvent {
+       int             type;           /* XkbAnyEvent */
+       unsigned long   serial;         /* of last req processed by server */
+       Bool            send_event;     /* is this from a SendEvent request */
+       Display *       display;        /* Display the event was read from */
+       Time            time;           /* milliseconds */
+       int             xkb_type;       /* XkbMapNotify */
+       int             device;         /* device ID */
+       unsigned int    changed;        /* fields which have been changed */
+       unsigned int    flags;          /* reserved */
+       int             first_type;     /* first changed key type */
+       int             num_types;      /* number of changed key types */
+       KeyCode         min_key_code;
+       KeyCode         max_key_code;
+       KeyCode         first_key_sym;
+       KeyCode         first_key_act;
+       KeyCode         first_key_behavior;
+       KeyCode         first_key_explicit;
+       KeyCode         first_modmap_key;  
+       KeyCode         first_vmodmap_key;
+       int             num_key_syms;
+       int             num_key_acts;
+       int             num_key_behaviors;
+       int             num_key_explicit;
+       int             num_modmap_keys;
+       int             num_vmodmap_keys;
+       unsigned int    vmods;          /* mask of changed virtual mods */
+} XkbMapNotifyEvent;
+
+typedef struct _XkbStateNotifyEvent {
+       int             type;           /* XkbAnyEvent */
+       unsigned long   serial;         /* # of last req processed by server */
+       Bool            send_event;     /* is this from a SendEvent request? */
+       Display *       display;        /* Display the event was read from */
+       Time            time;           /* milliseconds */
+       int             xkb_type;       /* XkbStateNotify */
+       int             device;         /* device ID */
+       unsigned int    changed;        /* mask of changed state components */
+       int             group;          /* keyboard group */
+       int             base_group;     /* base keyboard group */
+       int             latched_group;  /* latched keyboard group */
+       int             locked_group;   /* locked keyboard group */
+       unsigned int    mods;           /* modifier state */
+       unsigned int    base_mods;      /* base modifier state */
+       unsigned int    latched_mods;   /* latched modifiers */
+       unsigned int    locked_mods;    /* locked modifiers */
+       int             compat_state;   /* compatibility state */
+       unsigned char   grab_mods;      /* mods used for grabs */
+       unsigned char   compat_grab_mods;/* grab mods for non-XKB clients */
+       unsigned char   lookup_mods;    /* mods sent to clients */
+       unsigned char   compat_lookup_mods; /* mods sent to non-XKB clients */
+       int             ptr_buttons;    /* pointer button state */
+       KeyCode         keycode;        /* keycode that caused the change */
+       char            event_type;     /* KeyPress or KeyRelease */
+       char            req_major;      /* Major opcode of request */
+       char            req_minor;      /* Minor opcode of request */
+} XkbStateNotifyEvent;
+
+typedef struct _XkbControlsNotify {
+       int             type;           /* XkbAnyEvent */
+       unsigned long   serial;         /* of last req processed by server */
+       Bool            send_event;     /* is this from a SendEvent request? */
+       Display *       display;        /* Display the event was read from */
+       Time            time;           /* milliseconds */
+       int             xkb_type;       /* XkbControlsNotify */
+       int             device;         /* device ID */
+       unsigned int    changed_ctrls;  /* controls with changed sub-values */
+       unsigned int    enabled_ctrls;  /* controls currently enabled */
+       unsigned int    enabled_ctrl_changes;/* controls just {en,dis}abled */
+       int             num_groups;     /* total groups on keyboard */
+       KeyCode         keycode;        /* key that caused change or 0 */
+       char            event_type;     /* type of event that caused change */
+       char            req_major;      /* if keycode==0, major and minor */
+       char            req_minor;      /* opcode of req that caused change */
+} XkbControlsNotifyEvent;
+
+typedef struct _XkbIndicatorNotify {
+       int             type;           /* XkbAnyEvent */
+       unsigned long   serial;         /* of last req processed by server */
+       Bool            send_event;     /* is this from a SendEvent request? */
+       Display *       display;        /* Display the event was read from */
+       Time            time;           /* milliseconds */
+       int             xkb_type;       /* XkbIndicatorNotify */
+       int             device;         /* device ID */
+       unsigned int    changed;        /* indicators with new state or map */
+       unsigned int    state;          /* current state of all indicators */
+} XkbIndicatorNotifyEvent;
+
+typedef struct _XkbNamesNotify {
+       int             type;           /* XkbAnyEvent */
+       unsigned long   serial;         /* of last req processed by server */
+       Bool            send_event;     /* is this from a SendEvent request? */
+       Display *       display;        /* Display the event was read from */
+       Time            time;           /* milliseconds */
+       int             xkb_type;       /* XkbNamesNotify */
+       int             device;         /* device ID */
+       unsigned int    changed;        /* names that have changed */
+       int             first_type;     /* first key type with new name */
+       int             num_types;      /* number of key types with new names */
+       int             first_lvl;      /* first key type new new level names */
+       int             num_lvls;       /* # of key types w/new level names */
+       int             num_aliases;    /* total number of key aliases*/
+       int             num_radio_groups;/* total number of radio groups */
+       unsigned int    changed_vmods;  /* virtual modifiers with new names */
+       unsigned int    changed_groups; /* groups with new names */
+       unsigned int    changed_indicators;/* indicators with new names */
+       int             first_key;      /* first key with new name */
+       int             num_keys;       /* number of keys with new names */
+} XkbNamesNotifyEvent;
+
+typedef struct _XkbCompatMapNotify {
+       int             type;           /* XkbAnyEvent */
+       unsigned long   serial;         /* of last req processed by server */
+       Bool            send_event;     /* is this from a SendEvent request? */
+       Display *       display;        /* Display the event was read from */
+       Time            time;           /* milliseconds */
+       int             xkb_type;       /* XkbCompatMapNotify */
+       int             device;         /* device ID */
+       unsigned int    changed_groups; /* groups with new compat maps */
+       int             first_si;       /* first new symbol interp */
+       int             num_si;         /* number of new symbol interps */
+       int             num_total_si;   /* total # of symbol interps */
+} XkbCompatMapNotifyEvent;
+
+typedef struct _XkbBellNotify {
+       int             type;           /* XkbAnyEvent */
+       unsigned long   serial;         /* of last req processed by server */
+       Bool            send_event;     /* is this from a SendEvent request? */
+       Display *       display;        /* Display the event was read from */
+       Time            time;           /* milliseconds */
+       int             xkb_type;       /* XkbBellNotify */
+       int             device;         /* device ID */
+       int             percent;        /* requested volume as a % of maximum */
+       int             pitch;          /* requested pitch in Hz */
+       int             duration;       /* requested duration in useconds */
+       int             bell_class;     /* (input extension) feedback class */
+       int             bell_id;        /* (input extension) ID of feedback */
+       Atom            name;           /* "name" of requested bell */
+       Window          window;         /* window associated with event */
+       Bool            event_only;     /* "event only" requested */
+} XkbBellNotifyEvent;
+
+typedef struct _XkbActionMessage {
+       int             type;           /* XkbAnyEvent */
+       unsigned long   serial;         /* of last req processed by server */
+       Bool            send_event;     /* is this from a SendEvent request? */
+       Display *       display;        /* Display the event was read from */
+       Time            time;           /* milliseconds */
+       int             xkb_type;       /* XkbActionMessage */
+       int             device;         /* device ID */
+       KeyCode         keycode;        /* key that generated the event */
+       Bool            press;          /* true if act caused by key press */
+       Bool            key_event_follows;/* true if key event also generated */
+       int             group;          /* effective group */
+       unsigned int    mods;           /* effective mods */
+       char            message[XkbActionMessageLength+1]; 
+                                       /* message -- leave space for NUL */
+} XkbActionMessageEvent;
+
+typedef struct _XkbAccessXNotify {
+       int             type;           /* XkbAnyEvent */
+       unsigned long   serial;         /* of last req processed by server */
+       Bool            send_event;     /* is this from a SendEvent request? */
+       Display *       display;        /* Display the event was read from */
+       Time            time;           /* milliseconds */
+       int             xkb_type;       /* XkbAccessXNotify */
+       int             device;         /* device ID */
+       int             detail;         /* XkbAXN_* */
+       int             keycode;        /* key of event */
+       int             sk_delay;       /* current slow keys delay */
+       int             debounce_delay; /* current debounce delay */
+} XkbAccessXNotifyEvent;
+
+typedef struct _XkbExtensionDeviceNotify {
+       int             type;           /* XkbAnyEvent */
+       unsigned long   serial;         /* of last req processed by server */
+       Bool            send_event;     /* is this from a SendEvent request? */
+       Display *       display;        /* Display the event was read from */
+       Time            time;           /* milliseconds */
+       int             xkb_type;       /* XkbExtensionDeviceNotify */
+       int             device;         /* device ID */
+       unsigned int    reason;         /* reason for the event */      
+       unsigned int    supported;      /* mask of supported features */        
+       unsigned int    unsupported;    /* mask of unsupported features */
+                                       /* that some app tried to use */
+       int             first_btn;      /* first button that changed */
+       int             num_btns;       /* range of buttons changed */
+       unsigned int    leds_defined;   /* indicators with names or maps */
+       unsigned int    led_state;      /* current state of the indicators */
+       int             led_class;      /* feedback class for led changes */
+       int             led_id;         /* feedback id for led changes */
+} XkbExtensionDeviceNotifyEvent;
+
+typedef union _XkbEvent {
+       int                             type;
+       XkbAnyEvent                     any;
+       XkbNewKeyboardNotifyEvent       new_kbd;
+       XkbMapNotifyEvent               map;
+       XkbStateNotifyEvent             state;
+       XkbControlsNotifyEvent          ctrls;
+       XkbIndicatorNotifyEvent         indicators;
+       XkbNamesNotifyEvent             names;
+       XkbCompatMapNotifyEvent         compat;
+       XkbBellNotifyEvent              bell;
+       XkbActionMessageEvent           message;
+       XkbAccessXNotifyEvent           accessx;
+       XkbExtensionDeviceNotifyEvent   device;
+       XEvent                          core;
+} XkbEvent;
+
+typedef struct _XkbKbdDpyState XkbKbdDpyStateRec,*XkbKbdDpyStatePtr;
+
+       /* XkbOpenDisplay error codes */
+#define        XkbOD_Success           0
+#define        XkbOD_BadLibraryVersion 1
+#define        XkbOD_ConnectionRefused 2
+#define        XkbOD_NonXkbServer      3
+#define        XkbOD_BadServerVersion  4
+
+       /* Values for XlibFlags */
+#define        XkbLC_ForceLatin1Lookup         (1<<0)
+#define        XkbLC_ConsumeLookupMods         (1<<1)
+#define        XkbLC_AlwaysConsumeShiftAndLock (1<<2)
+#define        XkbLC_IgnoreNewKeyboards        (1<<3)
+#define        XkbLC_ControlFallback           (1<<4)
+#define        XkbLC_ConsumeKeysOnComposeFail  (1<<29)
+#define        XkbLC_ComposeLED                (1<<30)
+#define        XkbLC_BeepOnComposeFail         (1<<31)
+
+#define        XkbLC_AllComposeControls        (0xc0000000)
+#define        XkbLC_AllControls               (0xc000001f)
+
+_XFUNCPROTOBEGIN
+
+extern Bool    XkbIgnoreExtension(
+#if NeedFunctionPrototypes
+       Bool                    /* ignore */
+#endif
+);
+
+extern Display *XkbOpenDisplay(
+#if NeedFunctionPrototypes
+       char *                  /* name */,
+       int *                   /* ev_rtrn */,
+       int *                   /* err_rtrn */,
+       int *                   /* major_rtrn */,
+       int *                   /* minor_rtrn */,
+       int *                   /* reason */
+#endif
+);
+
+extern Bool    XkbQueryExtension(
+#if NeedFunctionPrototypes
+       Display *               /* dpy */,
+       int *                   /* opcodeReturn */,
+       int *                   /* eventBaseReturn */,
+       int *                   /* errorBaseReturn */,
+       int *                   /* majorRtrn */,
+       int *                   /* minorRtrn */
+#endif
+);
+
+extern Bool    XkbUseExtension(
+#if NeedFunctionPrototypes
+       Display *               /* dpy */,
+       int *                   /* major_rtrn */,
+       int *                   /* minor_rtrn */
+#endif
+);
+
+extern Bool    XkbLibraryVersion(
+#if NeedFunctionPrototypes
+       int *                   /* libMajorRtrn */,
+       int *                   /* libMinorRtrn */
+#endif
+);
+
+extern unsigned int    XkbSetXlibControls(
+#if NeedFunctionPrototypes
+       Display*                /* dpy */,
+       unsigned int            /* affect */,
+       unsigned int            /* values */
+#endif
+);
+
+extern unsigned int    XkbGetXlibControls(
+#if NeedFunctionPrototypes
+       Display*                /* dpy */
+#endif
+);
+
+typedef        Atom    (*XkbInternAtomFunc)(
+#if NeedFunctionPrototypes
+       Display *               /* dpy */,
+       _Xconst char *          /* name */,
+       Bool                    /* only_if_exists */
+#endif
+);
+
+typedef char * (*XkbGetAtomNameFunc)(
+#if NeedFunctionPrototypes
+       Display *               /* dpy */,
+       Atom                    /* atom */
+#endif
+);
+
+extern void            XkbSetAtomFuncs(
+#if NeedFunctionPrototypes
+       XkbInternAtomFunc       /* getAtom */,
+       XkbGetAtomNameFunc      /* getName */
+#endif
+);
+
+extern KeySym XkbKeycodeToKeysym(
+#if NeedFunctionPrototypes
+               Display *       /* dpy */,
+#if NeedWidePrototypes
+                unsigned int   /* kc */,
+#else
+                KeyCode        /* kc */,
+#endif
+                int            /* group */,
+                int            /* level */
+#endif
+);
+
+extern unsigned int    XkbKeysymToModifiers(
+#if NeedFunctionPrototypes
+    Display *                  /* dpy */,
+    KeySym                     /* ks */
+#endif
+);
+
+extern Bool            XkbLookupKeySym(
+#if NeedFunctionPrototypes
+    Display *                  /* dpy */,
+    KeyCode                    /* keycode */,
+    unsigned int               /* modifiers */,
+    unsigned int *             /* modifiers_return */,
+    KeySym *                   /* keysym_return */
+#endif
+);
+
+extern int             XkbLookupKeyBinding(
+#if NeedFunctionPrototypes
+    Display *                  /* dpy */,
+    KeySym                     /* sym_rtrn */,
+    unsigned int               /* mods */,
+    char *                     /* buffer */,
+    int                        /* nbytes */,
+    int *                      /* extra_rtrn */
+#endif
+);
+
+extern Bool            XkbTranslateKeyCode(
+#if NeedFunctionPrototypes
+    XkbDescPtr                 /* xkb */,
+    KeyCode                    /* keycode */,
+    unsigned int               /* modifiers */,
+    unsigned int *             /* modifiers_return */,
+    KeySym *                   /* keysym_return */
+#endif
+);
+
+extern int             XkbTranslateKeySym(
+#if NeedFunctionPrototypes
+    Display *                  /* dpy */,
+    register KeySym *          /* sym_return */,
+    unsigned int               /* modifiers */,
+    char *                     /* buffer */,
+    int                        /* nbytes */,
+    int *                      /* extra_rtrn */
+#endif
+);
+
+extern Bool    XkbSetAutoRepeatRate(
+#if NeedFunctionPrototypes
+       Display *               /* dpy */,
+       unsigned int            /* deviceSpec */,
+       unsigned int            /* delay */,
+       unsigned int            /* interval */
+#endif
+);
+
+extern Bool    XkbGetAutoRepeatRate(
+#if NeedFunctionPrototypes
+       Display *               /* dpy */,
+       unsigned int            /* deviceSpec */,
+       unsigned int *          /* delayRtrn */,
+       unsigned int *          /* intervalRtrn */
+#endif
+);
+
+extern Bool    XkbChangeEnabledControls(
+#if NeedFunctionPrototypes
+       Display *               /* dpy */,
+       unsigned int            /* deviceSpec */,
+       unsigned int            /* affect */,
+       unsigned int            /* values */
+#endif
+);
+
+extern Bool    XkbDeviceBell(
+#if NeedFunctionPrototypes
+       Display *               /* dpy */,
+       Window                  /* win */,
+       int                     /* deviceSpec */,
+       int                     /* bellClass */,
+       int                     /* bellID */,
+       int                     /* percent */,
+       Atom                    /* name */
+#endif
+);
+
+extern Bool    XkbForceDeviceBell(
+#if NeedFunctionPrototypes
+       Display *               /* dpy */,
+       int                     /* deviceSpec */,
+       int                     /* bellClass */,
+       int                     /* bellID */,
+       int                     /* percent */
+#endif
+);
+
+extern Bool    XkbDeviceBellEvent(
+#if NeedFunctionPrototypes
+       Display *               /* dpy */,
+       Window                  /* win */,
+       int                     /* deviceSpec */,
+       int                     /* bellClass */,
+       int                     /* bellID */,
+       int                     /* percent */,
+       Atom                    /* name */
+#endif
+);
+
+extern Bool    XkbBell(
+#if NeedFunctionPrototypes
+       Display *               /* dpy */,
+       Window                  /* win */,
+       int                     /* percent */,
+       Atom                    /* name */
+#endif
+);
+
+extern Bool    XkbForceBell(
+#if NeedFunctionPrototypes
+       Display *               /* dpy */,
+       int                     /* percent */
+#endif
+);
+
+extern Bool    XkbBellEvent(
+#if NeedFunctionPrototypes
+       Display *               /* dpy */,
+       Window                  /* win */,
+       int                     /* percent */,
+       Atom                    /* name */
+#endif
+);
+
+extern Bool    XkbSelectEvents(
+#if NeedFunctionPrototypes
+       Display *               /* dpy */,
+       unsigned int            /* deviceID */,
+       unsigned int            /* affect */,
+       unsigned int            /* values */
+#endif
+);
+
+extern Bool    XkbSelectEventDetails(
+#if NeedFunctionPrototypes
+       Display *               /* dpy */,
+       unsigned int            /* deviceID */,
+       unsigned int            /* eventType */,
+       unsigned long           /* affect */,
+       unsigned long           /* details */
+#endif
+);
+
+extern void    XkbNoteMapChanges(
+#if NeedFunctionPrototypes
+    XkbMapChangesPtr           /* old */,
+    XkbMapNotifyEvent  *       /* new */,
+    unsigned int               /* wanted */
+#endif
+);
+
+extern void    XkbNoteNameChanges(
+#if NeedFunctionPrototypes
+    XkbNameChangesPtr          /* old */,
+    XkbNamesNotifyEvent        *       /* new */,
+    unsigned int               /* wanted */
+#endif
+);
+
+extern Status  XkbGetIndicatorState(
+#if NeedFunctionPrototypes
+       Display *               /* dpy */,
+       unsigned int            /* deviceSpec */,
+       unsigned int *          /* pStateRtrn */
+#endif
+);
+
+extern Status  XkbGetDeviceIndicatorState(
+#if NeedFunctionPrototypes
+       Display *               /* dpy */,
+       unsigned int            /* deviceSpec */,
+       unsigned int            /* ledClass */,
+       unsigned int            /* ledID */,
+       unsigned int *          /* pStateRtrn */
+#endif
+);
+
+extern Status   XkbGetIndicatorMap(
+#if NeedFunctionPrototypes
+       Display *               /* dpy */,
+       unsigned long           /* which */,
+       XkbDescPtr              /* desc */
+#endif
+);
+
+extern Bool     XkbSetIndicatorMap(
+#if NeedFunctionPrototypes
+       Display *               /* dpy */,
+       unsigned long           /* which */,
+       XkbDescPtr              /* desc */
+#endif
+);
+
+#define        XkbNoteIndicatorMapChanges(o,n,w) \
+                               ((o)->map_changes|=((n)->map_changes&(w)))
+#define        XkbNoteIndicatorStateChanges(o,n,w)\
+                               ((o)->state_changes|=((n)->state_changes&(w)))
+#define        XkbGetIndicatorMapChanges(d,x,c) \
+                               (XkbGetIndicatorMap((d),(c)->map_changes,x)
+#define        XkbChangeIndicatorMaps(d,x,c) \
+                               (XkbSetIndicatorMap((d),(c)->map_changes,x))
+
+extern Bool    XkbGetNamedIndicator(
+#if NeedFunctionPrototypes
+       Display *               /* dpy */,
+       Atom                    /* name */,
+       int *                   /* pNdxRtrn */,
+       Bool *                  /* pStateRtrn */,
+       XkbIndicatorMapPtr      /* pMapRtrn */,
+       Bool *                  /* pRealRtrn */
+#endif
+);
+
+extern Bool    XkbGetNamedDeviceIndicator(
+#if NeedFunctionPrototypes
+       Display *               /* dpy */,
+       unsigned int            /* deviceSpec */,
+       unsigned int            /* ledClass */,
+       unsigned int            /* ledID */,
+       Atom                    /* name */,
+       int *                   /* pNdxRtrn */,
+       Bool *                  /* pStateRtrn */,
+       XkbIndicatorMapPtr      /* pMapRtrn */,
+       Bool *                  /* pRealRtrn */
+#endif
+);
+
+extern Bool    XkbSetNamedIndicator(
+#if NeedFunctionPrototypes
+       Display *               /* dpy */,
+       Atom                    /* name */,
+       Bool                    /* changeState */,
+       Bool                    /* state */,
+       Bool                    /* createNewMap */,
+       XkbIndicatorMapPtr      /* pMap */
+#endif
+);
+
+extern Bool    XkbSetNamedDeviceIndicator(
+#if NeedFunctionPrototypes
+       Display *               /* dpy */,
+       unsigned int            /* deviceSpec */,
+       unsigned int            /* ledClass */,
+       unsigned int            /* ledID */,
+       Atom                    /* name */,
+       Bool                    /* changeState */,
+       Bool                    /* state */,
+       Bool                    /* createNewMap */,
+       XkbIndicatorMapPtr      /* pMap */
+#endif
+);
+
+extern Bool    XkbLockModifiers(
+#if NeedFunctionPrototypes
+       Display *               /* dpy */,
+       unsigned int            /* deviceSpec */,
+       unsigned int            /* affect */,
+       unsigned int            /* values */
+#endif
+);
+
+extern Bool    XkbLatchModifiers(
+#if NeedFunctionPrototypes
+       Display *               /* dpy */,
+       unsigned int            /* deviceSpec */,
+       unsigned int            /* affect */,
+       unsigned int            /* values */
+#endif
+);
+
+extern Bool    XkbLockGroup(
+#if NeedFunctionPrototypes
+       Display *               /* dpy */,
+       unsigned int            /* deviceSpec */,
+       unsigned int            /* group */
+#endif
+);
+
+extern Bool    XkbLatchGroup(
+#if NeedFunctionPrototypes
+       Display *               /* dpy */,
+       unsigned int            /* deviceSpec */,
+       unsigned int            /* group */
+#endif
+);
+
+extern Bool    XkbSetServerInternalMods(
+#if NeedFunctionPrototypes
+       Display *               /* dpy */,
+       unsigned int            /* deviceSpec */,
+       unsigned int            /* affectReal */,
+       unsigned int            /* realValues */,
+       unsigned int            /* affectVirtual */,
+       unsigned int            /* virtualValues */
+#endif
+);
+
+extern Bool    XkbSetIgnoreLockMods(
+#if NeedFunctionPrototypes
+       Display *               /* dpy */,
+       unsigned int            /* deviceSpec */,
+       unsigned int            /* affectReal */,
+       unsigned int            /* realValues */,
+       unsigned int            /* affectVirtual */,
+       unsigned int            /* virtualValues */
+#endif
+);
+
+
+extern Bool    XkbVirtualModsToReal(
+#if NeedFunctionPrototypes
+       XkbDescPtr              /* xkb */,
+       unsigned int            /* virtual_mask */,
+       unsigned int *          /* mask_rtrn */
+#endif
+);
+
+extern Bool    XkbComputeEffectiveMap(
+#if NeedFunctionPrototypes
+       XkbDescPtr              /* xkb */,
+       XkbKeyTypePtr           /* type */,
+       unsigned char *         /* map_rtrn */
+#endif
+);
+
+extern Status XkbInitCanonicalKeyTypes(
+#if NeedFunctionPrototypes
+    XkbDescPtr                 /* xkb */,
+    unsigned int               /* which */,
+    int                                /* keypadVMod */
+#endif
+);
+
+extern XkbDescPtr XkbAllocKeyboard(
+#if NeedFunctionPrototypes
+       void
+#endif
+);
+
+extern void    XkbFreeKeyboard(
+#if NeedFunctionPrototypes
+       XkbDescPtr              /* xkb */,
+       unsigned int            /* which */,
+       Bool                    /* freeDesc */
+#endif
+);
+
+extern Status XkbAllocClientMap(
+#if NeedFunctionPrototypes
+       XkbDescPtr              /* xkb */,
+       unsigned int            /* which */,
+       unsigned int            /* nTypes */
+#endif
+);
+
+extern Status XkbAllocServerMap(
+#if NeedFunctionPrototypes
+       XkbDescPtr              /* xkb */,
+       unsigned int            /* which */,
+       unsigned int            /* nActions */
+#endif
+);
+
+extern void    XkbFreeClientMap(
+#if NeedFunctionPrototypes
+    XkbDescPtr                 /* xkb */,
+    unsigned int               /* what */,
+    Bool                       /* freeMap */
+#endif
+);
+
+extern void    XkbFreeServerMap(
+#if NeedFunctionPrototypes
+    XkbDescPtr                 /* xkb */,
+    unsigned int               /* what */,
+    Bool                       /* freeMap */
+#endif
+);
+
+extern XkbKeyTypePtr   XkbAddKeyType(
+#if NeedFunctionPrototypes
+    XkbDescPtr                 /* xkb */,
+    Atom                       /* name */,
+    int                                /* map_count */,
+    Bool                       /* want_preserve */,
+    int                                /* num_lvls */
+#endif
+);
+
+extern Status XkbAllocIndicatorMaps(
+#if NeedFunctionPrototypes
+       XkbDescPtr              /* xkb */
+#endif
+);
+
+extern void XkbFreeIndicatorMaps(
+#if NeedFunctionPrototypes
+    XkbDescPtr                 /* xkb */
+#endif
+);
+
+extern XkbDescPtr XkbGetMap(
+#if NeedFunctionPrototypes
+       Display *               /* dpy */,
+       unsigned int            /* which */,
+       unsigned int            /* deviceSpec */
+#endif
+);
+
+extern Status  XkbGetUpdatedMap(
+#if NeedFunctionPrototypes
+       Display *               /* dpy */,
+       unsigned int            /* which */,
+       XkbDescPtr              /* desc */
+#endif
+);
+
+extern Status  XkbGetMapChanges(
+#if NeedFunctionPrototypes
+    Display *                  /* dpy */,
+    XkbDescPtr                 /* xkb */,
+    XkbMapChangesPtr           /* changes */
+#endif
+);
+
+
+extern Status  XkbRefreshKeyboardMapping(
+#if NeedFunctionPrototypes
+    XkbMapNotifyEvent *                /* event */
+#endif
+);
+
+extern Status  XkbGetKeyTypes(
+#if NeedFunctionPrototypes
+    Display *                  /* dpy */,
+    unsigned int               /* first */,
+    unsigned int               /* num */,
+    XkbDescPtr                 /* xkb */
+#endif
+);
+
+extern Status  XkbGetKeySyms(
+#if NeedFunctionPrototypes
+    Display *                  /* dpy */,
+    unsigned int               /* first */,
+    unsigned int               /* num */,
+    XkbDescPtr                 /* xkb */
+#endif
+);
+
+extern Status  XkbGetKeyActions(
+#if NeedFunctionPrototypes
+    Display *                  /* dpy */,
+    unsigned int               /* first */,
+    unsigned int               /* num */,
+    XkbDescPtr                 /* xkb */
+#endif
+);
+
+extern Status  XkbGetKeyBehaviors(
+#if NeedFunctionPrototypes
+       Display *               /* dpy */,
+       unsigned int            /* firstKey */,
+       unsigned int            /* nKeys */,
+       XkbDescPtr              /* desc */
+#endif
+);
+
+extern Status  XkbGetVirtualMods(
+#if NeedFunctionPrototypes
+       Display *               /* dpy */,
+       unsigned int            /* which */,
+       XkbDescPtr              /* desc */
+#endif
+);
+
+extern Status  XkbGetKeyExplicitComponents(
+#if NeedFunctionPrototypes
+       Display *               /* dpy */,
+       unsigned int            /* firstKey */,
+       unsigned int            /* nKeys */,
+       XkbDescPtr              /* desc */
+#endif
+);
+
+extern Status  XkbGetKeyModifierMap(
+#if NeedFunctionPrototypes
+       Display *               /* dpy */,
+       unsigned int            /* firstKey */,
+       unsigned int            /* nKeys */,
+       XkbDescPtr              /* desc */
+#endif
+);
+
+extern Status  XkbAllocControls(
+#if NeedFunctionPrototypes
+       XkbDescPtr              /* xkb */,
+       unsigned int            /* which*/
+#endif
+);
+
+extern void    XkbFreeControls(
+#if NeedFunctionPrototypes
+       XkbDescPtr              /* xkb */,
+       unsigned int            /* which */,
+       Bool                    /* freeMap */
+#endif
+);
+
+extern Status  XkbGetControls(
+#if NeedFunctionPrototypes
+       Display *               /* dpy */,
+       unsigned long           /* which */,
+       XkbDescPtr              /* desc */
+#endif
+);
+
+extern Bool    XkbSetControls(
+#if NeedFunctionPrototypes
+       Display *               /* dpy */,
+       unsigned long           /* which */,
+       XkbDescPtr              /* desc */
+#endif
+);
+
+extern void    XkbNoteControlsChanges(
+#if NeedFunctionPrototypes
+    XkbControlsChangesPtr      /* old */,
+    XkbControlsNotifyEvent *   /* new */,
+    unsigned int               /* wanted */
+#endif
+);
+
+#define        XkbGetControlsChanges(d,x,c)    XkbGetControls(d,(c)->changed_ctrls,x)
+#define        XkbChangeControls(d,x,c)        XkbSetControls(d,(c)->changed_ctrls,x)
+
+extern Status  XkbAllocCompatMap(
+#if NeedFunctionPrototypes
+    XkbDescPtr                 /* xkb */,
+    unsigned int               /* which */,
+    unsigned int               /* nInterpret */
+#endif
+);
+
+extern void    XkbFreeCompatMap(
+#if NeedFunctionPrototypes
+    XkbDescPtr                 /* xkb */,
+    unsigned int               /* which */,
+    Bool                       /* freeMap */
+#endif
+);
+
+extern Status XkbGetCompatMap(
+#if NeedFunctionPrototypes
+       Display *               /* dpy */,
+       unsigned int            /* which */,
+       XkbDescPtr              /* xkb */
+#endif
+);
+
+extern Bool XkbSetCompatMap(
+#if NeedFunctionPrototypes
+       Display *               /* dpy */,
+       unsigned int            /* which */,
+       XkbDescPtr              /* xkb */,
+       Bool                    /* updateActions */
+#endif
+);
+
+extern XkbSymInterpretPtr XkbAddSymInterpret(
+#if NeedFunctionPrototypes
+       XkbDescPtr              /* xkb */,
+       XkbSymInterpretPtr      /* si */,
+       Bool                    /* updateMap */,
+       XkbChangesPtr           /* changes */
+#endif
+);
+
+extern Status XkbAllocNames(
+#if NeedFunctionPrototypes
+       XkbDescPtr              /* xkb */,
+       unsigned int            /* which */,
+       int                     /* nTotalRG */,
+       int                     /* nTotalAliases */
+#endif
+);
+
+extern Status  XkbGetNames(
+#if NeedFunctionPrototypes
+       Display *               /* dpy */,
+       unsigned int            /* which */,
+       XkbDescPtr              /* desc */
+#endif
+);
+
+extern Bool    XkbSetNames(
+#if NeedFunctionPrototypes
+       Display *               /* dpy */,
+       unsigned int            /* which */,
+       unsigned int            /* firstType */,
+       unsigned int            /* nTypes */,
+       XkbDescPtr              /* desc */
+#endif
+);
+
+extern Bool    XkbChangeNames(
+#if NeedFunctionPrototypes
+       Display *               /* dpy */,
+       XkbDescPtr              /* xkb */,
+       XkbNameChangesPtr       /* changes */
+#endif
+);
+
+extern void XkbFreeNames(
+#if NeedFunctionPrototypes
+       XkbDescPtr              /* xkb */,
+       unsigned int            /* which */,
+       Bool                    /* freeMap */
+#endif
+);
+
+
+extern Status  XkbGetState(
+#if NeedFunctionPrototypes
+       Display *               /* dpy */,
+       unsigned int            /* deviceSpec */,
+       XkbStatePtr             /* rtrnState */
+#endif
+);
+
+extern Bool    XkbSetMap(
+#if NeedFunctionPrototypes
+       Display *               /* dpy */,
+       unsigned int            /* which */,
+       XkbDescPtr              /* desc */
+#endif
+);
+
+extern Bool    XkbChangeMap(
+#if NeedFunctionPrototypes
+       Display*                /* dpy */,
+       XkbDescPtr              /* desc */,
+       XkbMapChangesPtr        /* changes */
+#endif
+);
+
+extern Bool    XkbSetDetectableAutoRepeat(
+#if NeedFunctionPrototypes
+       Display *               /* dpy */,
+       Bool                    /* detectable */,
+       Bool *                  /* supported */
+#endif
+);
+
+extern Bool    XkbGetDetectableAutoRepeat(
+#if NeedFunctionPrototypes
+       Display *               /* dpy */,
+       Bool *                  /* supported */
+#endif
+);
+
+extern Bool    XkbSetAutoResetControls(
+#if NeedFunctionPrototypes
+    Display *                  /* dpy */,
+    unsigned int               /* changes */,
+    unsigned int *             /* auto_ctrls */,
+    unsigned int *             /* auto_values */
+#endif
+);
+
+extern Bool    XkbGetAutoResetControls(
+#if NeedFunctionPrototypes
+    Display *                  /* dpy */,
+    unsigned int *             /* auto_ctrls */,
+    unsigned int *             /* auto_ctrl_values */
+#endif
+);
+
+extern Status XkbCopyKeyType(
+#if NeedFunctionPrototypes
+    XkbKeyTypePtr      /* from */,
+    XkbKeyTypePtr      /* into */
+#endif
+);
+
+extern Status XkbCopyKeyTypes(
+#if NeedFunctionPrototypes
+    XkbKeyTypePtr      /* from */,
+    XkbKeyTypePtr      /* into */,
+    int                        /* num_types */
+#endif
+);
+
+extern Status  XkbResizeKeyType(
+#if NeedFunctionPrototypes
+    XkbDescPtr         /* xkb */,
+    int                        /* type_ndx */,
+    int                        /* map_count */,
+    Bool               /* want_preserve */,
+    int                        /* new_num_lvls */
+#endif
+);
+
+extern KeySym *XkbResizeKeySyms(
+#if NeedFunctionPrototypes
+       XkbDescPtr              /* desc */,
+       int                     /* forKey */,
+       int                     /* symsNeeded */
+#endif
+);
+
+extern XkbAction *XkbResizeKeyActions(
+#if NeedFunctionPrototypes
+       XkbDescPtr              /* desc */,
+       int                     /* forKey */,
+       int                     /* actsNeeded */
+#endif
+);
+
+extern Status XkbChangeTypesOfKey(
+#if NeedFunctionPrototypes
+       XkbDescPtr              /* xkb */,
+       int                     /* key */,
+       int                     /* num_groups */,
+       unsigned int            /* groups */,
+       int *                   /* newTypes */,
+       XkbMapChangesPtr        /* pChanges */
+#endif
+);
+
+/***====================================================================***/
+
+extern XkbComponentListPtr     XkbListComponents(
+#if NeedFunctionPrototypes
+       Display *               /* dpy */,
+       unsigned int            /* deviceSpec */,
+       XkbComponentNamesPtr    /* ptrns */,
+       int *                   /* max_inout */
+#endif
+);
+
+extern void XkbFreeComponentList(
+#if NeedFunctionPrototypes
+       XkbComponentListPtr     /* list */
+#endif
+);
+
+extern XkbDescPtr XkbGetKeyboard(
+#if NeedFunctionPrototypes
+       Display *               /* dpy */,
+       unsigned int            /* which */,
+       unsigned int            /* deviceSpec */
+#endif
+);
+
+extern XkbDescPtr XkbGetKeyboardByName(
+#if NeedFunctionPrototypes
+    Display *                  /* dpy */,
+    unsigned int               /* deviceSpec */,
+    XkbComponentNamesPtr       /* names */,
+    unsigned int               /* want */,
+    unsigned int               /* need */,
+    Bool                       /* load */
+#endif
+);
+
+/***====================================================================***/
+
+extern int     XkbKeyTypesForCoreSymbols(      /* returns # of groups */
+#if NeedFunctionPrototypes
+    XkbDescPtr /* xkb */,                      /* keyboard device */
+    int                /* map_width */,                /* width of core KeySym array */
+    KeySym *   /* core_syms */,                /* always mapWidth symbols */
+    unsigned int       /* protected */,        /* explicit key types */
+    int *      /* types_inout */,              /* always four type indices */
+    KeySym *   /* xkb_syms_rtrn */             /* must have enough space */
+#endif
+);
+
+extern Bool    XkbApplyCompatMapToKey( /* False only on error */
+#if NeedFunctionPrototypes
+    XkbDescPtr         /* xkb */,              /* keymap to be edited */
+    KeyCode            /* key */,              /* key to be updated */
+    XkbChangesPtr      /* changes */           /* resulting changes to map */
+#endif
+);
+
+extern Bool    XkbUpdateMapFromCore( /* False only on error */
+#if NeedFunctionPrototypes
+    XkbDescPtr         /* xkb */,              /* XKB keyboard to be edited */
+    KeyCode            /* first_key */,        /* first changed key */
+    int                        /* num_keys */,         /* number of changed keys */
+    int                        /* map_width */,        /* width of core keymap */
+    KeySym *           /* core_keysyms */,     /* symbols from core keymap */
+    XkbChangesPtr      /* changes */           /* resulting changes */
+#endif
+);
+
+/***====================================================================***/
+
+extern XkbDeviceLedInfoPtr     XkbAddDeviceLedInfo(
+#if NeedFunctionPrototypes
+       XkbDeviceInfoPtr        /* devi */,
+       unsigned int            /* ledClass */,
+       unsigned int            /* ledId */
+#endif
+);
+
+extern Status                  XkbResizeDeviceButtonActions(
+#if NeedFunctionPrototypes
+       XkbDeviceInfoPtr        /* devi */,
+       unsigned int            /* newTotal */
+#endif
+);
+
+extern XkbDeviceInfoPtr        XkbAllocDeviceInfo(
+#if NeedFunctionPrototypes
+       unsigned int            /* deviceSpec */,
+       unsigned int            /* nButtons */,
+       unsigned int            /* szLeds */
+#endif
+);
+
+extern void XkbFreeDeviceInfo(
+#if NeedFunctionPrototypes
+       XkbDeviceInfoPtr        /* devi */,
+       unsigned int            /* which */,
+       Bool                    /* freeDevI */
+#endif
+);
+
+extern void    XkbNoteDeviceChanges(
+#if NeedFunctionPrototypes
+    XkbDeviceChangesPtr                        /* old */,
+    XkbExtensionDeviceNotifyEvent *    /* new */,
+    unsigned int                       /* wanted */
+#endif
+);
+
+extern XkbDeviceInfoPtr XkbGetDeviceInfo(
+#if NeedFunctionPrototypes
+       Display *               /* dpy */,
+       unsigned int            /* which */,
+       unsigned int            /* deviceSpec */,
+       unsigned int            /* ledClass */,
+       unsigned int            /* ledID */
+#endif
+);
+
+extern Status  XkbGetDeviceInfoChanges(
+#if NeedFunctionPrototypes
+       Display *               /* dpy */,
+       XkbDeviceInfoPtr        /* devi */,
+       XkbDeviceChangesPtr     /* changes */
+#endif
+);
+
+extern Status  XkbGetDeviceButtonActions(
+#if NeedFunctionPrototypes
+       Display *               /* dpy */,
+       XkbDeviceInfoPtr        /* devi */,
+       Bool                    /* all */,
+       unsigned int            /* first */,
+       unsigned int            /* nBtns */
+#endif
+);
+
+extern Status  XkbGetDeviceLedInfo(
+#if NeedFunctionPrototypes
+       Display *               /* dpy */,
+       XkbDeviceInfoPtr        /* devi */,
+       unsigned int            /* ledClass (class, XIDflt, XIAll) */,
+       unsigned int            /* ledId (id, XIDflt, XIAll) */,
+       unsigned int            /* which (XkbXI_Indicator{Names,Map}Mask */
+#endif
+);
+
+extern Bool    XkbSetDeviceInfo(
+#if NeedFunctionPrototypes
+       Display *               /* dpy */,
+       unsigned int            /* which */,
+       XkbDeviceInfoPtr        /* devi */
+#endif
+);
+
+extern Bool    XkbChangeDeviceInfo(
+#if NeedFunctionPrototypes
+       Display*                /* dpy */,
+       XkbDeviceInfoPtr        /* desc */,
+       XkbDeviceChangesPtr     /* changes */
+#endif
+);
+
+extern  Bool XkbSetDeviceLedInfo(
+#if NeedFunctionPrototypes
+       Display *               /* dpy */,
+       XkbDeviceInfoPtr        /* devi */,
+       unsigned int            /* ledClass */,
+       unsigned int            /* ledID */,
+       unsigned int            /* which */
+#endif
+);
+
+extern Bool XkbSetDeviceButtonActions(
+#if NeedFunctionPrototypes
+       Display *               /* dpy */,
+       XkbDeviceInfoPtr        /* devi */,
+       unsigned int            /* first */,
+       unsigned int            /* nBtns */
+#endif
+);
+
+/***====================================================================***/
+
+extern char    XkbToControl(
+#if NeedFunctionPrototypes
+       char            /* c */
+#endif
+);
+
+/***====================================================================***/
+
+extern Bool XkbSetDebuggingFlags(
+#if NeedFunctionPrototypes
+    Display *          /* dpy */,
+    unsigned int       /* mask */,
+    unsigned int       /* flags */,
+    char *             /* msg */,
+    unsigned int       /* ctrls_mask */,
+    unsigned int       /* ctrls */,
+    unsigned int *     /* rtrn_flags */,
+    unsigned int *     /* rtrn_ctrls */
+#endif
+);
+
+_XFUNCPROTOEND
+
+#endif /* _XKBLIB_H_ */
diff --git a/Xserver/lib/X11/Xcms.h b/Xserver/lib/X11/Xcms.h
new file mode 100644 (file)
index 0000000..164e7f8
--- /dev/null
@@ -0,0 +1,921 @@
+/* $XConsortium: Xcms.h,v 1.15 92/11/19 16:43:04 rws Exp $ */
+
+/*
+ * Code and supporting documentation (c) Copyright 1990 1991 Tektronix, Inc.
+ *     All Rights Reserved
+ * 
+ * This file is a component of an X Window System-specific implementation
+ * of Xcms based on the TekColor Color Management System.  Permission is
+ * hereby granted to use, copy, modify, sell, and otherwise distribute this
+ * software and its documentation for any purpose and without fee, provided
+ * that this copyright, permission, and disclaimer notice is reproduced in
+ * all copies of this software and in supporting documentation.  TekColor
+ * is a trademark of Tektronix, Inc.
+ * 
+ * Tektronix makes no representation about the suitability of this software
+ * for any purpose.  It is provided "as is" and with all faults.
+ * 
+ * TEKTRONIX DISCLAIMS ALL WARRANTIES APPLICABLE TO THIS SOFTWARE,
+ * INCLUDING THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ * PARTICULAR PURPOSE.  IN NO EVENT SHALL TEKTRONIX BE LIABLE FOR ANY
+ * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
+ * RESULTING FROM LOSS OF USE, DATA, OR PROFITS, WHETHER IN AN ACTION OF
+ * CONTRACT, NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
+ * CONNECTION WITH THE USE OR THE PERFORMANCE OF THIS SOFTWARE.
+ *
+ *
+ *     DESCRIPTION
+ *             Public include file for X Color Management System
+ */
+#ifndef _XCMS_H_
+#define _XCMS_H_
+
+    /*
+     * XCMS Status Values
+     */
+#define XcmsFailure                    0
+#define XcmsSuccess                    1
+#define XcmsSuccessWithCompression     2
+
+    /*
+     * Color Space Format ID's
+     *    Color Space ID's are of XcmsColorFormat type.
+     *
+     *    bit 31
+     *     0 == Device-Independent
+     *     1 == Device-Dependent
+     *
+     *    bit 30:
+     *     0 == Registered with X Consortium
+     *     1 == Unregistered
+     */
+#define XcmsUndefinedFormat    (XcmsColorFormat)0x00000000
+#define XcmsCIEXYZFormat       (XcmsColorFormat)0x00000001
+#define XcmsCIEuvYFormat       (XcmsColorFormat)0x00000002
+#define XcmsCIExyYFormat       (XcmsColorFormat)0x00000003
+#define XcmsCIELabFormat       (XcmsColorFormat)0x00000004
+#define XcmsCIELuvFormat       (XcmsColorFormat)0x00000005
+#define XcmsTekHVCFormat       (XcmsColorFormat)0x00000006
+#define XcmsRGBFormat          (XcmsColorFormat)0x80000000
+#define XcmsRGBiFormat         (XcmsColorFormat)0x80000001
+
+    /*
+     * State of XcmsPerScrnInfo
+     */
+#define XcmsInitNone           0x00    /* no initialization attempted */
+#define XcmsInitSuccess                0x01    /* initialization successful */
+#define XcmsInitFailure                0xff    /* failure, use defaults */
+
+#define DisplayOfCCC(ccc)              ((ccc)->dpy)
+#define ScreenNumberOfCCC(ccc)         ((ccc)->screenNumber)
+#define VisualOfCCC(ccc)               ((ccc)->visual)
+#define ClientWhitePointOfCCC(ccc)     (&(ccc)->clientWhitePt)
+#define ScreenWhitePointOfCCC(ccc)     (&(ccc)->pPerScrnInfo->screenWhitePt)
+#define FunctionSetOfCCC(ccc)          ((ccc)->pPerScrnInfo->functionSet)
+
+typedef unsigned long XcmsColorFormat; /* Color Space Format ID */
+
+typedef double XcmsFloat;
+
+    /*
+     * Device RGB
+     */
+typedef struct {
+    unsigned short red;                /* scaled from 0x0000 to 0xffff */
+    unsigned short green;      /* scaled from 0x0000 to 0xffff */
+    unsigned short blue;       /* scaled from 0x0000 to 0xffff */
+} XcmsRGB;
+
+    /*
+     * RGB Intensity
+     */
+typedef struct {
+    XcmsFloat red;     /* 0.0 - 1.0 */
+    XcmsFloat green;   /* 0.0 - 1.0 */
+    XcmsFloat blue;    /* 0.0 - 1.0 */
+} XcmsRGBi;
+
+    /*
+     * CIE XYZ
+     */
+typedef struct {
+    XcmsFloat X;
+    XcmsFloat Y;
+    XcmsFloat Z;
+} XcmsCIEXYZ;
+
+    /*
+     * CIE u'v'Y
+     */
+typedef struct {
+    XcmsFloat u_prime;         /* 0.0 - 1.0 */
+    XcmsFloat v_prime;         /* 0.0 - 1.0 */
+    XcmsFloat Y;               /* 0.0 - 1.0 */
+} XcmsCIEuvY;
+
+    /*
+     * CIE xyY
+     */
+typedef struct {
+    XcmsFloat x;               /* 0.0 - 1.0 */
+    XcmsFloat y;               /* 0.0 - 1.0 */
+    XcmsFloat Y;               /* 0.0 - 1.0 */
+} XcmsCIExyY;
+
+    /*
+     * CIE L*a*b*
+     */
+typedef struct {
+    XcmsFloat L_star;          /* 0.0 - 100.0 */
+    XcmsFloat a_star;
+    XcmsFloat b_star;
+} XcmsCIELab;
+
+    /*
+     * CIE L*u*v*
+     */
+typedef struct {
+    XcmsFloat L_star;          /* 0.0 - 100.0 */
+    XcmsFloat u_star;
+    XcmsFloat v_star;
+} XcmsCIELuv;
+
+    /*
+     * TekHVC
+     */
+typedef struct {
+    XcmsFloat H;               /* 0.0 - 360.0 */
+    XcmsFloat V;               /* 0.0 - 100.0 */
+    XcmsFloat C;               /* 0.0 - 100.0 */
+} XcmsTekHVC;
+
+    /*
+     * PAD
+     */
+typedef struct {
+    XcmsFloat pad0;
+    XcmsFloat pad1;
+    XcmsFloat pad2;
+    XcmsFloat pad3;
+} XcmsPad;
+
+
+    /*
+     * XCMS Color Structure
+     */
+typedef struct {
+    union {
+       XcmsRGB RGB;
+       XcmsRGBi RGBi;
+       XcmsCIEXYZ CIEXYZ;
+       XcmsCIEuvY CIEuvY;
+       XcmsCIExyY CIExyY;
+       XcmsCIELab CIELab;
+       XcmsCIELuv CIELuv;
+       XcmsTekHVC TekHVC;
+       XcmsPad Pad;
+    } spec;                    /* the color specification      */
+    unsigned long pixel;       /* pixel value (as needed)      */
+    XcmsColorFormat    format;         /* the specification format     */
+} XcmsColor;
+
+
+    /*
+     * XCMS Per Screen related data
+     */
+
+typedef struct _XcmsPerScrnInfo {
+    XcmsColor  screenWhitePt;  /* Screen White point */
+    XPointer   functionSet;    /* pointer to Screen Color Characterization */
+                               /*      Function Set structure          */
+    XPointer   screenData;     /* pointer to corresponding Screen Color*/
+                               /*      Characterization Data           */
+    unsigned char state;   /* XcmsInitNone, XcmsInitSuccess, XcmsInitFailure */
+    char       pad[3];
+} XcmsPerScrnInfo;
+
+typedef struct _XcmsCCC *XcmsCCC;
+
+typedef Status (*XcmsCompressionProc)(         /* Gamut Compression Proc */
+#if NeedFunctionPrototypes
+    XcmsCCC            /* ccc */,
+    XcmsColor*         /* colors_in_out */,
+    unsigned int       /* ncolors */,
+    unsigned int       /* index */,
+    Bool*              /* compression_flags_return */
+#endif
+);
+
+typedef Status (*XcmsWhiteAdjustProc)(         /* White Point Adjust Proc */
+#if NeedFunctionPrototypes
+    XcmsCCC            /* ccc */,
+    XcmsColor*         /* initial_white_point*/,
+    XcmsColor*         /* target_white_point*/,
+    XcmsColorFormat    /* target_format */,
+    XcmsColor*         /* colors_in_out */,
+    unsigned int       /* ncolors */,
+    Bool*              /* compression_flags_return */
+#endif
+);
+
+    /*
+     * XCMS Color Conversion Context
+     */
+typedef struct _XcmsCCC {
+    Display    *dpy;                   /* X Display */
+    int                screenNumber;           /* X screen number */
+    Visual     *visual;                /* X Visual */
+    XcmsColor  clientWhitePt;          /* Client White Point */
+    XcmsCompressionProc        gamutCompProc;  /* Gamut Compression Function */
+    XPointer   gamutCompClientData;    /* Gamut Comp Func Client Data */
+    XcmsWhiteAdjustProc        whitePtAdjProc; /* White Point Adjustment Function */
+    XPointer   whitePtAdjClientData;   /* White Pt Adj Func Client Data */
+    XcmsPerScrnInfo *pPerScrnInfo;     /* pointer to per screen information */
+                                       /*  associated with the above display */
+                                       /*  screenNumber */
+} XcmsCCCRec;
+
+typedef Status (*XcmsScreenInitProc)(  /* Screen Initialization Proc */
+#if NeedFunctionPrototypes
+    Display*           /* dpy */,
+    int                        /* screen_number */,
+    XcmsPerScrnInfo*   /* screen_info */
+#endif
+);
+
+typedef void (*XcmsScreenFreeProc)(
+#if NeedFunctionPrototypes
+    XPointer           /* screenData */
+#endif
+);
+
+    /*
+     * Function List Pointer -- pointer to an array of function pointers.
+     *    The end of list is indicated by a NULL pointer.
+     */
+typedef Status (*XcmsConversionProc)();
+typedef XcmsConversionProc *XcmsFuncListPtr;
+
+typedef int (*XcmsParseStringProc)(    /* Color String Parsing Proc */
+#if NeedFunctionPrototypes
+    char*              /* color_string */,
+    XcmsColor*         /* color_return */
+#endif
+);
+
+    /*
+     * Color Space -- per Color Space related data (Device-Independent
+     *    or Device-Dependent)
+     */
+typedef struct _XcmsColorSpace {
+    char *prefix;              /* Prefix of string format.             */
+    XcmsColorFormat id;                /* Format ID number.                    */
+    XcmsParseStringProc parseString;
+                               /* String format parsing function       */
+    XcmsFuncListPtr to_CIEXYZ; /* Pointer to an array of function      */
+                               /*   pointers such that when the        */
+                               /*   functions are executed in sequence */
+                               /*   will convert a XcmsColor structure */
+                               /*   from this color space to CIEXYZ    */
+                               /*   space.                             */
+    XcmsFuncListPtr from_CIEXYZ;/* Pointer to an array of function     */
+                               /*   pointers such that when the        */
+                               /*   functions are executed in sequence */
+                               /*   will convert a XcmsColor structure */
+                               /*   from CIEXYZ space to this color    */
+                               /*   space.                             */
+    int inverse_flag;          /* If 1, indicates that for 0 <= i < n  */
+                               /*   where n is the number of function  */
+                               /*   pointers in the lists to_CIEXYZ    */
+                               /*   and from_CIEXYZ; for each function */
+                               /*   to_CIEXYZ[i] its inverse function  */
+                               /*   is from_CIEXYZ[n - i].             */
+
+} XcmsColorSpace;
+
+    /*
+     * Screen Color Characterization Function Set -- per device class
+     *    color space conversion functions.
+     */
+typedef struct _XcmsFunctionSet {
+    XcmsColorSpace **DDColorSpaces;
+                               /* Pointer to an array of pointers to   */
+                               /*   Device-DEPENDENT color spaces      */
+                               /*   understood by this SCCFuncSet.     */
+    XcmsScreenInitProc screenInitProc;
+                               /* Screen initialization function that  */
+                               /*   reads Screen Color Characterization*/
+                               /*   Data off properties on the screen's*/
+                               /*   root window.                       */
+    XcmsScreenFreeProc screenFreeProc;
+                               /* Function that frees the SCCData      */
+                               /*   structures.                        */
+} XcmsFunctionSet;
+
+_XFUNCPROTOBEGIN
+
+extern Status XcmsAddColorSpace (
+#if NeedFunctionPrototypes
+    XcmsColorSpace*    /* pColorSpace */
+#endif
+);
+
+extern Status XcmsAddFunctionSet (
+#if NeedFunctionPrototypes
+    XcmsFunctionSet*   /* functionSet */
+#endif
+);
+
+extern Status XcmsAllocColor (
+#if NeedFunctionPrototypes
+    Display*           /* dpy */,
+    Colormap           /* colormap */,
+    XcmsColor*         /* color_in_out */,
+    XcmsColorFormat            /* result_format */
+#endif
+);
+
+extern Status XcmsAllocNamedColor (
+#if NeedFunctionPrototypes
+    Display*           /* dpy */,
+    Colormap           /* colormap */,
+    _Xconst char*      /* color_string */,
+    XcmsColor*         /* color_scrn_return */,
+    XcmsColor*         /* color_exact_return */,
+    XcmsColorFormat            /* result_format */
+#endif
+);
+
+extern XcmsCCC XcmsCCCOfColormap (
+#if NeedFunctionPrototypes
+    Display*           /* dpy */,
+    Colormap           /* colormap */
+#endif
+);
+
+extern Status XcmsCIELabClipab(
+#if NeedFunctionPrototypes
+    XcmsCCC            /* ccc */,
+    XcmsColor*         /* colors_in_out */,
+    unsigned int       /* ncolors */,
+    unsigned int       /* index */,
+    Bool*              /* compression_flags_return */
+#endif
+);
+
+extern Status XcmsCIELabClipL(
+#if NeedFunctionPrototypes
+    XcmsCCC            /* ccc */,
+    XcmsColor*         /* colors_in_out */,
+    unsigned int       /* ncolors */,
+    unsigned int       /* index */,
+    Bool*              /* compression_flags_return */
+#endif
+);
+
+extern Status XcmsCIELabClipLab(
+#if NeedFunctionPrototypes
+    XcmsCCC            /* ccc */,
+    XcmsColor*         /* colors_in_out */,
+    unsigned int       /* ncolors */,
+    unsigned int       /* index */,
+    Bool*              /* compression_flags_return */
+#endif
+);
+
+extern Status XcmsCIELabQueryMaxC (
+#if NeedFunctionPrototypes
+    XcmsCCC            /* ccc */,
+    XcmsFloat          /* hue_angle */,
+    XcmsFloat          /* L_star */,
+    XcmsColor*         /* color_return */
+#endif
+);
+
+extern Status XcmsCIELabQueryMaxL (
+#if NeedFunctionPrototypes
+    XcmsCCC            /* ccc */,
+    XcmsFloat          /* hue_angle */,
+    XcmsFloat          /* chroma */,
+    XcmsColor*         /* color_return */
+#endif
+);
+
+extern Status XcmsCIELabQueryMaxLC (
+#if NeedFunctionPrototypes
+    XcmsCCC            /* ccc */,
+    XcmsFloat          /* hue_angle */,
+    XcmsColor*         /* color_return */
+#endif
+);
+
+extern Status XcmsCIELabQueryMinL (
+#if NeedFunctionPrototypes
+    XcmsCCC            /* ccc */,
+    XcmsFloat          /* hue_angle */,
+    XcmsFloat          /* chroma */,
+    XcmsColor*         /* color_return */
+#endif
+);
+
+extern Status XcmsCIELabToCIEXYZ (
+#if NeedFunctionPrototypes
+    XcmsCCC            /* ccc */,
+    XcmsColor*         /* white_point */,
+    XcmsColor*         /* colors */,
+    unsigned int       /* ncolors */
+#endif
+);
+
+extern Status XcmsCIELabWhiteShiftColors(
+#if NeedFunctionPrototypes
+    XcmsCCC            /* ccc */,
+    XcmsColor*         /* initial_white_point*/,
+    XcmsColor*         /* target_white_point*/,
+    XcmsColorFormat    /* target_format */,
+    XcmsColor*         /* colors_in_out */,
+    unsigned int       /* ncolors */,
+    Bool*              /* compression_flags_return */
+#endif
+);
+
+extern Status XcmsCIELuvClipL(
+#if NeedFunctionPrototypes
+    XcmsCCC            /* ccc */,
+    XcmsColor*         /* colors_in_out */,
+    unsigned int       /* ncolors */,
+    unsigned int       /* index */,
+    Bool*              /* compression_flags_return */
+#endif
+);
+
+extern Status XcmsCIELuvClipLuv(
+#if NeedFunctionPrototypes
+    XcmsCCC            /* ccc */,
+    XcmsColor*         /* colors_in_out */,
+    unsigned int       /* ncolors */,
+    unsigned int       /* index */,
+    Bool*              /* compression_flags_return */
+#endif
+);
+
+extern Status XcmsCIELuvClipuv(
+#if NeedFunctionPrototypes
+    XcmsCCC            /* ccc */,
+    XcmsColor*         /* colors_in_out */,
+    unsigned int       /* ncolors */,
+    unsigned int       /* index */,
+    Bool*              /* compression_flags_return */
+#endif
+);
+
+extern Status XcmsCIELuvQueryMaxC (
+#if NeedFunctionPrototypes
+    XcmsCCC            /* ccc */,
+    XcmsFloat          /* hue_angle */,
+    XcmsFloat          /* L_star */,
+    XcmsColor*         /* color_return */
+#endif
+);
+
+extern Status XcmsCIELuvQueryMaxL (
+#if NeedFunctionPrototypes
+    XcmsCCC            /* ccc */,
+    XcmsFloat          /* hue_angle */,
+    XcmsFloat          /* chroma */,
+    XcmsColor*         /* color_return */
+#endif
+);
+
+extern Status XcmsCIELuvQueryMaxLC (
+#if NeedFunctionPrototypes
+    XcmsCCC            /* ccc */,
+    XcmsFloat          /* hue_angle */,
+    XcmsColor*         /* color_return */
+#endif
+);
+
+extern Status XcmsCIELuvQueryMinL (
+#if NeedFunctionPrototypes
+    XcmsCCC            /* ccc */,
+    XcmsFloat          /* hue_angle */,
+    XcmsFloat          /* chroma */,
+    XcmsColor*         /* color_return */
+#endif
+);
+
+extern Status XcmsCIELuvToCIEuvY (
+#if NeedFunctionPrototypes
+    XcmsCCC            /* ccc */,
+    XcmsColor*         /* white_point */,
+    XcmsColor*         /* colors */,
+    unsigned int       /* ncolors */
+#endif
+);
+
+extern Status XcmsCIELuvWhiteShiftColors(
+#if NeedFunctionPrototypes
+    XcmsCCC            /* ccc */,
+    XcmsColor*         /* initial_white_point*/,
+    XcmsColor*         /* target_white_point*/,
+    XcmsColorFormat    /* target_format */,
+    XcmsColor*         /* colors_in_out */,
+    unsigned int       /* ncolors */,
+    Bool*              /* compression_flags_return */
+#endif
+);
+
+extern Status XcmsCIEXYZToCIELab (
+#if NeedFunctionPrototypes
+    XcmsCCC            /* ccc */,
+    XcmsColor*         /* white_point */,
+    XcmsColor*         /* colors */,
+    unsigned int       /* ncolors */
+#endif
+);
+
+extern Status XcmsCIEXYZToCIEuvY (
+#if NeedFunctionPrototypes
+    XcmsCCC            /* ccc */,
+    XcmsColor*         /* white_point */,
+    XcmsColor*         /* colors */,
+    unsigned int       /* ncolors */
+#endif
+);
+
+extern Status XcmsCIEXYZToCIExyY (
+#if NeedFunctionPrototypes
+    XcmsCCC            /* ccc */,
+    XcmsColor*         /* white_point */,
+    XcmsColor*         /* colors */,
+    unsigned int       /* ncolors */
+#endif
+);
+
+extern Status XcmsCIEXYZToRGBi (
+#if NeedFunctionPrototypes
+    XcmsCCC            /* ccc */,
+    XcmsColor*         /* colors */,
+    unsigned int       /* ncolors */,
+    Bool*              /* compression_flags_return */
+#endif
+);
+
+extern Status XcmsCIEuvYToCIELuv (
+#if NeedFunctionPrototypes
+    XcmsCCC            /* ccc */,
+    XcmsColor*         /* white_point */,
+    XcmsColor*         /* colors */,
+    unsigned int       /* ncolors */
+#endif
+);
+
+extern Status XcmsCIEuvYToCIEXYZ (
+#if NeedFunctionPrototypes
+    XcmsCCC            /* ccc */,
+    XcmsColor*         /* white_point */,
+    XcmsColor*         /* colors */,
+    unsigned int       /* ncolors */
+#endif
+);
+
+extern Status XcmsCIEuvYToTekHVC (
+#if NeedFunctionPrototypes
+    XcmsCCC            /* ccc */,
+    XcmsColor*         /* white_point */,
+    XcmsColor*         /* colors */,
+    unsigned int       /* ncolors */
+#endif
+);
+
+extern Status XcmsCIExyYToCIEXYZ (
+#if NeedFunctionPrototypes
+    XcmsCCC            /* ccc */,
+    XcmsColor*         /* white_point */,
+    XcmsColor*         /* colors */,
+    unsigned int       /* ncolors */
+#endif
+);
+
+extern XcmsColor *XcmsClientWhitePointOfCCC (
+#if NeedFunctionPrototypes
+    XcmsCCC            /* ccc */
+#endif
+);
+
+extern Status XcmsConvertColors (
+#if NeedFunctionPrototypes
+    XcmsCCC            /* ccc */,
+    XcmsColor*         /* colorArry_in_out */,
+    unsigned int       /* nColors */,
+    XcmsColorFormat            /* targetFormat */,
+    Bool*              /* compArry_return */
+#endif
+);
+
+extern XcmsCCC XcmsCreateCCC (
+#if NeedFunctionPrototypes
+    Display*           /* dpy */,
+    int                        /* screenNumber */,
+    Visual*            /* visual */,
+    XcmsColor*         /* clientWhitePt */,
+    XcmsCompressionProc /* gamutCompProc */,
+    XPointer           /* gamutCompClientData */,
+    XcmsWhiteAdjustProc        /* whitePtAdjProc */,
+    XPointer           /* whitePtAdjClientData */
+#endif
+);
+
+extern XcmsCCC XcmsDefaultCCC (
+#if NeedFunctionPrototypes
+    Display*           /* dpy */,
+    int                        /* screenNumber */
+#endif
+);
+
+extern Display *XcmsDisplayOfCCC (
+#if NeedFunctionPrototypes
+    XcmsCCC            /* ccc */
+#endif
+);
+
+extern XcmsColorFormat XcmsFormatOfPrefix (
+#if NeedFunctionPrototypes
+    char*              /* prefix */
+#endif
+);
+
+extern void XcmsFreeCCC (
+#if NeedFunctionPrototypes
+    XcmsCCC            /* ccc */
+#endif
+);
+
+extern Status XcmsLookupColor (
+#if NeedFunctionPrototypes
+    Display*           /* dpy */,
+    Colormap           /* colormap */,
+    _Xconst char*      /* color_string */,
+    XcmsColor*         /* pColor_exact_in_out */,
+    XcmsColor*         /* pColor_scrn_in_out */,
+    XcmsColorFormat            /* result_format */
+#endif
+);
+
+extern char *XcmsPrefixOfFormat (
+#if NeedFunctionPrototypes
+    XcmsColorFormat            /* id */
+#endif
+);
+
+extern Status XcmsQueryBlack (
+#if NeedFunctionPrototypes
+    XcmsCCC            /* ccc */,
+    XcmsColorFormat    /* target_format */,
+    XcmsColor*         /* color_return */
+#endif
+);
+
+extern Status XcmsQueryBlue (
+#if NeedFunctionPrototypes
+    XcmsCCC            /* ccc */,
+    XcmsColorFormat    /* target_format */,
+    XcmsColor*         /* color_return */
+#endif
+);
+
+extern Status XcmsQueryColor (
+#if NeedFunctionPrototypes
+    Display*           /* dpy */,
+    Colormap           /* colormap */,
+    XcmsColor*         /* pColor_in_out */,
+    XcmsColorFormat            /* result_format */
+#endif
+);
+
+extern Status XcmsQueryColors (
+#if NeedFunctionPrototypes
+    Display*           /* dpy */,
+    Colormap           /* colormap */,
+    XcmsColor*         /* colorArry_in_out */,
+    unsigned int       /* nColors */,
+    XcmsColorFormat    /* result_format */
+#endif
+);
+
+extern Status XcmsQueryGreen (
+#if NeedFunctionPrototypes
+    XcmsCCC            /* ccc */,
+    XcmsColorFormat    /* target_format */,
+    XcmsColor*         /* color_return */
+#endif
+);
+
+extern Status XcmsQueryRed (
+#if NeedFunctionPrototypes
+    XcmsCCC            /* ccc */,
+    XcmsColorFormat    /* target_format */,
+    XcmsColor*         /* color_return */
+#endif
+);
+
+extern Status XcmsQueryWhite (
+#if NeedFunctionPrototypes
+    XcmsCCC            /* ccc */,
+    XcmsColorFormat    /* target_format */,
+    XcmsColor*         /* color_return */
+#endif
+);
+
+extern Status XcmsRGBiToCIEXYZ (
+#if NeedFunctionPrototypes
+    XcmsCCC            /* ccc */,
+    XcmsColor*         /* colors */,
+    unsigned int       /* ncolors */,
+    Bool*              /* compression_flags_return */
+#endif
+);
+
+extern Status XcmsRGBiToRGB (
+#if NeedFunctionPrototypes
+    XcmsCCC            /* ccc */,
+    XcmsColor*         /* colors */,
+    unsigned int       /* ncolors */,
+    Bool*              /* compression_flags_return */
+#endif
+);
+
+extern Status XcmsRGBToRGBi (
+#if NeedFunctionPrototypes
+    XcmsCCC            /* ccc */,
+    XcmsColor*         /* colors */,
+    unsigned int       /* ncolors */,
+    Bool*              /* compression_flags_return */
+#endif
+);
+
+extern int XcmsScreenNumberOfCCC (
+#if NeedFunctionPrototypes
+    XcmsCCC            /* ccc */
+#endif
+);
+
+extern XcmsColor *XcmsScreenWhitePointOfCCC (
+#if NeedFunctionPrototypes
+    XcmsCCC            /* ccc */
+#endif
+);
+
+extern XcmsCCC XcmsSetCCCOfColormap(
+#if NeedFunctionPrototypes
+    Display*           /* dpy */,
+    Colormap           /* colormap */,
+    XcmsCCC            /* ccc */
+#endif
+);
+
+extern XcmsCompressionProc XcmsSetCompressionProc (
+#if NeedFunctionPrototypes
+    XcmsCCC            /* ccc */,
+    XcmsCompressionProc        /* compression_proc */,
+    XPointer           /* client_data */
+#endif
+);
+
+extern XcmsWhiteAdjustProc XcmsSetWhiteAdjustProc (
+#if NeedFunctionPrototypes
+    XcmsCCC            /* ccc */,
+    XcmsWhiteAdjustProc        /* white_adjust_proc */,
+    XPointer           /* client_data */
+#endif
+);
+
+extern Status XcmsSetWhitePoint (
+#if NeedFunctionPrototypes
+    XcmsCCC            /* ccc */,
+    XcmsColor*         /* color */
+#endif
+);
+
+extern Status XcmsStoreColor (
+#if NeedFunctionPrototypes
+    Display*           /* dpy */,
+    Colormap           /* colormap */,
+    XcmsColor*         /* pColor_in */
+#endif
+);
+
+extern Status XcmsStoreColors (
+#if NeedFunctionPrototypes
+    Display*           /* dpy */,
+    Colormap           /* colormap */,
+    XcmsColor*         /* colorArry_in */,
+    unsigned int       /* nColors */,
+    Bool*              /* compArry_return */
+#endif
+);
+
+extern Status XcmsTekHVCClipC(
+#if NeedFunctionPrototypes
+    XcmsCCC            /* ccc */,
+    XcmsColor*         /* colors_in_out */,
+    unsigned int       /* ncolors */,
+    unsigned int       /* index */,
+    Bool*              /* compression_flags_return */
+#endif
+);
+
+extern Status XcmsTekHVCClipV(
+#if NeedFunctionPrototypes
+    XcmsCCC            /* ccc */,
+    XcmsColor*         /* colors_in_out */,
+    unsigned int       /* ncolors */,
+    unsigned int       /* index */,
+    Bool*              /* compression_flags_return */
+#endif
+);
+
+extern Status XcmsTekHVCClipVC(
+#if NeedFunctionPrototypes
+    XcmsCCC            /* ccc */,
+    XcmsColor*         /* colors_in_out */,
+    unsigned int       /* ncolors */,
+    unsigned int       /* index */,
+    Bool*              /* compression_flags_return */
+#endif
+);
+
+extern Status XcmsTekHVCQueryMaxC (
+#if NeedFunctionPrototypes
+    XcmsCCC            /* ccc */,
+    XcmsFloat          /* hue */,
+    XcmsFloat          /* value */,
+    XcmsColor*         /* color_return */
+#endif
+);
+
+extern Status XcmsTekHVCQueryMaxV (
+#if NeedFunctionPrototypes
+    XcmsCCC            /* ccc */,
+    XcmsFloat          /* hue */,
+    XcmsFloat          /* chroma */,
+    XcmsColor*         /* color_return */
+#endif
+);
+
+extern Status XcmsTekHVCQueryMaxVC (
+#if NeedFunctionPrototypes
+    XcmsCCC            /* ccc */,
+    XcmsFloat          /* hue */,
+    XcmsColor*         /* color_return */
+#endif
+);
+
+extern Status XcmsTekHVCQueryMaxVSamples (
+#if NeedFunctionPrototypes
+    XcmsCCC            /* ccc */,
+    XcmsFloat          /* hue */,
+    XcmsColor*         /* colors_return */,
+    unsigned int       /* nsamples */
+#endif
+);
+
+extern Status XcmsTekHVCQueryMinV (
+#if NeedFunctionPrototypes
+    XcmsCCC            /* ccc */,
+    XcmsFloat          /* hue */,
+    XcmsFloat          /* chroma */,
+    XcmsColor*         /* color_return */
+#endif
+);
+
+extern Status XcmsTekHVCToCIEuvY (
+#if NeedFunctionPrototypes
+    XcmsCCC            /* ccc */,
+    XcmsColor*         /* white_point */,
+    XcmsColor*         /* colors */,
+    unsigned int       /* ncolors */
+#endif
+);
+
+extern Status XcmsTekHVCWhiteShiftColors(
+#if NeedFunctionPrototypes
+    XcmsCCC            /* ccc */,
+    XcmsColor*         /* initial_white_point*/,
+    XcmsColor*         /* target_white_point*/,
+    XcmsColorFormat    /* target_format */,
+    XcmsColor*         /* colors_in_out */,
+    unsigned int       /* ncolors */,
+    Bool*              /* compression_flags_return */
+#endif
+);
+
+extern Visual *XcmsVisualOfCCC (
+#if NeedFunctionPrototypes
+    XcmsCCC            /* ccc */
+#endif
+);
+
+_XFUNCPROTOEND
+
+#endif /* _XCMS_H_ */
diff --git a/Xserver/lib/X11/Xlib.h b/Xserver/lib/X11/Xlib.h
new file mode 100644 (file)
index 0000000..641352c
--- /dev/null
@@ -0,0 +1,4724 @@
+/* $XConsortium: Xlib.h /main/119 1996/09/28 16:35:29 rws $ */
+/* $XFree86: xc/lib/X11/Xlib.h,v 3.10.2.1 1998/02/15 16:08:37 hohndel Exp $ */
+/* 
+
+Copyright (c) 1985, 1986, 1987, 1991  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+*/
+
+
+/*
+ *     Xlib.h - Header definition and support file for the C subroutine
+ *     interface library (Xlib) to the X Window System Protocol (V11).
+ *     Structures and symbols starting with "_" are private to the library.
+ */
+#ifndef _XLIB_H_
+#define _XLIB_H_
+
+#define XlibSpecificationRelease 6
+
+#ifdef USG
+#ifndef __TYPES__
+#include <sys/types.h>                 /* forgot to protect it... */
+#define __TYPES__
+#endif /* __TYPES__ */
+#else
+#if defined(_POSIX_SOURCE) && defined(MOTOROLA)
+#undef _POSIX_SOURCE
+#include <sys/types.h>
+#define _POSIX_SOURCE
+#else
+#include <sys/types.h>
+#endif
+#endif /* USG */
+
+#include <X11/X.h>
+
+/* applications should not depend on these two headers being included! */
+#include <X11/Xfuncproto.h>
+#include <X11/Xosdefs.h>
+
+#ifndef X_WCHAR
+#ifdef X_NOT_STDC_ENV
+#ifndef SCO324
+#ifndef ISC
+#define X_WCHAR
+#endif
+#endif
+#endif
+#endif
+
+#ifndef X_WCHAR
+#include <stddef.h>
+#else
+#ifdef __EMX__
+#include <stdlib.h>
+#else
+/* replace this with #include or typedef appropriate for your system */
+typedef unsigned long wchar_t;
+#endif
+#endif
+
+#if defined(ISC) && defined(USE_XMBTOWC)
+#define wctomb(a,b)    _Xwctomb(a,b)
+#define mblen(a,b)     _Xmblen(a,b) 
+#ifndef USE_XWCHAR_STRING
+#define mbtowc(a,b,c)  _Xmbtowc(a,b,c)
+#endif
+#endif
+
+typedef char *XPointer;
+
+#define Bool int
+#define Status int
+#define True 1
+#define False 0
+
+#define QueuedAlready 0
+#define QueuedAfterReading 1
+#define QueuedAfterFlush 2
+
+#define ConnectionNumber(dpy)  (((_XPrivDisplay)dpy)->fd)
+#define RootWindow(dpy, scr)   (ScreenOfDisplay(dpy,scr)->root)
+#define DefaultScreen(dpy)     (((_XPrivDisplay)dpy)->default_screen)
+#define DefaultRootWindow(dpy)         (ScreenOfDisplay(dpy,DefaultScreen(dpy))->root)
+#define DefaultVisual(dpy, scr) (ScreenOfDisplay(dpy,scr)->root_visual)
+#define DefaultGC(dpy, scr)    (ScreenOfDisplay(dpy,scr)->default_gc)
+#define BlackPixel(dpy, scr)   (ScreenOfDisplay(dpy,scr)->black_pixel)
+#define WhitePixel(dpy, scr)   (ScreenOfDisplay(dpy,scr)->white_pixel)
+#define AllPlanes              ((unsigned long)~0L)
+#define QLength(dpy)           (((_XPrivDisplay)dpy)->qlen)
+#define DisplayWidth(dpy, scr)         (ScreenOfDisplay(dpy,scr)->width)
+#define DisplayHeight(dpy, scr) (ScreenOfDisplay(dpy,scr)->height)
+#define DisplayWidthMM(dpy, scr)(ScreenOfDisplay(dpy,scr)->mwidth)
+#define DisplayHeightMM(dpy, scr)(ScreenOfDisplay(dpy,scr)->mheight)
+#define DisplayPlanes(dpy, scr) (ScreenOfDisplay(dpy,scr)->root_depth)
+#define DisplayCells(dpy, scr)         (DefaultVisual(dpy,scr)->map_entries)
+#define ScreenCount(dpy)       (((_XPrivDisplay)dpy)->nscreens)
+#define ServerVendor(dpy)      (((_XPrivDisplay)dpy)->vendor)
+#define ProtocolVersion(dpy)   (((_XPrivDisplay)dpy)->proto_major_version)
+#define ProtocolRevision(dpy)  (((_XPrivDisplay)dpy)->proto_minor_version)
+#define VendorRelease(dpy)     (((_XPrivDisplay)dpy)->release)
+#define DisplayString(dpy)     (((_XPrivDisplay)dpy)->display_name)
+#define DefaultDepth(dpy, scr)         (ScreenOfDisplay(dpy,scr)->root_depth)
+#define DefaultColormap(dpy, scr)(ScreenOfDisplay(dpy,scr)->cmap)
+#define BitmapUnit(dpy)        (((_XPrivDisplay)dpy)->bitmap_unit)
+#define BitmapBitOrder(dpy)    (((_XPrivDisplay)dpy)->bitmap_bit_order)
+#define BitmapPad(dpy)                 (((_XPrivDisplay)dpy)->bitmap_pad)
+#define ImageByteOrder(dpy)    (((_XPrivDisplay)dpy)->byte_order)
+#ifdef CRAY /* unable to get WORD64 without pulling in other symbols */
+#define NextRequest(dpy)       XNextRequest(dpy)
+#else
+#define NextRequest(dpy)       (((_XPrivDisplay)dpy)->request + 1)
+#endif
+#define LastKnownRequestProcessed(dpy) (((_XPrivDisplay)dpy)->last_request_read)
+
+/* macros for screen oriented applications (toolkit) */
+#define ScreenOfDisplay(dpy, scr)(&((_XPrivDisplay)dpy)->screens[scr])
+#define DefaultScreenOfDisplay(dpy) ScreenOfDisplay(dpy,DefaultScreen(dpy))
+#define DisplayOfScreen(s)     ((s)->display)
+#define RootWindowOfScreen(s)  ((s)->root)
+#define BlackPixelOfScreen(s)  ((s)->black_pixel)
+#define WhitePixelOfScreen(s)  ((s)->white_pixel)
+#define DefaultColormapOfScreen(s)((s)->cmap)
+#define DefaultDepthOfScreen(s)        ((s)->root_depth)
+#define DefaultGCOfScreen(s)   ((s)->default_gc)
+#define DefaultVisualOfScreen(s)((s)->root_visual)
+#define WidthOfScreen(s)       ((s)->width)
+#define HeightOfScreen(s)      ((s)->height)
+#define WidthMMOfScreen(s)     ((s)->mwidth)
+#define HeightMMOfScreen(s)    ((s)->mheight)
+#define PlanesOfScreen(s)      ((s)->root_depth)
+#define CellsOfScreen(s)       (DefaultVisualOfScreen((s))->map_entries)
+#define MinCmapsOfScreen(s)    ((s)->min_maps)
+#define MaxCmapsOfScreen(s)    ((s)->max_maps)
+#define DoesSaveUnders(s)      ((s)->save_unders)
+#define DoesBackingStore(s)    ((s)->backing_store)
+#define EventMaskOfScreen(s)   ((s)->root_input_mask)
+
+/*
+ * Extensions need a way to hang private data on some structures.
+ */
+typedef struct _XExtData {
+       int number;             /* number returned by XRegisterExtension */
+       struct _XExtData *next; /* next item on list of data for structure */
+       int (*free_private)(    /* called to free private storage */
+#if NeedFunctionPrototypes
+       struct _XExtData *extension
+#endif
+       );
+       XPointer private_data;  /* data private to this extension. */
+} XExtData;
+
+/*
+ * This file contains structures used by the extension mechanism.
+ */
+typedef struct {               /* public to extension, cannot be changed */
+       int extension;          /* extension number */
+       int major_opcode;       /* major op-code assigned by server */
+       int first_event;        /* first event number for the extension */
+       int first_error;        /* first error number for the extension */
+} XExtCodes;
+
+/*
+ * Data structure for retrieving info about pixmap formats.
+ */
+
+typedef struct {
+    int depth;
+    int bits_per_pixel;
+    int scanline_pad;
+} XPixmapFormatValues;
+
+
+/*
+ * Data structure for setting graphics context.
+ */
+typedef struct {
+       int function;           /* logical operation */
+       unsigned long plane_mask;/* plane mask */
+       unsigned long foreground;/* foreground pixel */
+       unsigned long background;/* background pixel */
+       int line_width;         /* line width */
+       int line_style;         /* LineSolid, LineOnOffDash, LineDoubleDash */
+       int cap_style;          /* CapNotLast, CapButt, 
+                                  CapRound, CapProjecting */
+       int join_style;         /* JoinMiter, JoinRound, JoinBevel */
+       int fill_style;         /* FillSolid, FillTiled, 
+                                  FillStippled, FillOpaeueStippled */
+       int fill_rule;          /* EvenOddRule, WindingRule */
+       int arc_mode;           /* ArcChord, ArcPieSlice */
+       Pixmap tile;            /* tile pixmap for tiling operations */
+       Pixmap stipple;         /* stipple 1 plane pixmap for stipping */
+       int ts_x_origin;        /* offset for tile or stipple operations */
+       int ts_y_origin;
+        Font font;             /* default text font for text operations */
+       int subwindow_mode;     /* ClipByChildren, IncludeInferiors */
+       Bool graphics_exposures;/* boolean, should exposures be generated */
+       int clip_x_origin;      /* origin for clipping */
+       int clip_y_origin;
+       Pixmap clip_mask;       /* bitmap clipping; other calls for rects */
+       int dash_offset;        /* patterned/dashed line information */
+       char dashes;
+} XGCValues;
+
+/*
+ * Graphics context.  The contents of this structure are implementation
+ * dependent.  A GC should be treated as opaque by application code.
+ */
+
+typedef struct _XGC
+#ifdef XLIB_ILLEGAL_ACCESS
+{
+    XExtData *ext_data;        /* hook for extension to hang data */
+    GContext gid;      /* protocol ID for graphics context */
+    /* there is more to this structure, but it is private to Xlib */
+}
+#endif
+*GC;
+
+/*
+ * Visual structure; contains information about colormapping possible.
+ */
+typedef struct {
+       XExtData *ext_data;     /* hook for extension to hang data */
+       VisualID visualid;      /* visual id of this visual */
+#if defined(__cplusplus) || defined(c_plusplus)
+       int c_class;            /* C++ class of screen (monochrome, etc.) */
+#else
+       int class;              /* class of screen (monochrome, etc.) */
+#endif
+       unsigned long red_mask, green_mask, blue_mask;  /* mask values */
+       int bits_per_rgb;       /* log base 2 of distinct color values */
+       int map_entries;        /* color map entries */
+} Visual;
+
+/*
+ * Depth structure; contains information for each possible depth.
+ */    
+typedef struct {
+       int depth;              /* this depth (Z) of the depth */
+       int nvisuals;           /* number of Visual types at this depth */
+       Visual *visuals;        /* list of visuals possible at this depth */
+} Depth;
+
+/*
+ * Information about the screen.  The contents of this structure are
+ * implementation dependent.  A Screen should be treated as opaque
+ * by application code.
+ */
+
+struct _XDisplay;              /* Forward declare before use for C++ */
+
+typedef struct {
+       XExtData *ext_data;     /* hook for extension to hang data */
+       struct _XDisplay *display;/* back pointer to display structure */
+       Window root;            /* Root window id. */
+       int width, height;      /* width and height of screen */
+       int mwidth, mheight;    /* width and height of  in millimeters */
+       int ndepths;            /* number of depths possible */
+       Depth *depths;          /* list of allowable depths on the screen */
+       int root_depth;         /* bits per pixel */
+       Visual *root_visual;    /* root visual */
+       GC default_gc;          /* GC for the root root visual */
+       Colormap cmap;          /* default color map */
+       unsigned long white_pixel;
+       unsigned long black_pixel;      /* White and Black pixel values */
+       int max_maps, min_maps; /* max and min color maps */
+       int backing_store;      /* Never, WhenMapped, Always */
+       Bool save_unders;       
+       long root_input_mask;   /* initial root input mask */
+} Screen;
+
+/*
+ * Format structure; describes ZFormat data the screen will understand.
+ */
+typedef struct {
+       XExtData *ext_data;     /* hook for extension to hang data */
+       int depth;              /* depth of this image format */
+       int bits_per_pixel;     /* bits/pixel at this depth */
+       int scanline_pad;       /* scanline must padded to this multiple */
+} ScreenFormat;
+
+/*
+ * Data structure for setting window attributes.
+ */
+typedef struct {
+    Pixmap background_pixmap;  /* background or None or ParentRelative */
+    unsigned long background_pixel;    /* background pixel */
+    Pixmap border_pixmap;      /* border of the window */
+    unsigned long border_pixel;        /* border pixel value */
+    int bit_gravity;           /* one of bit gravity values */
+    int win_gravity;           /* one of the window gravity values */
+    int backing_store;         /* NotUseful, WhenMapped, Always */
+    unsigned long backing_planes;/* planes to be preseved if possible */
+    unsigned long backing_pixel;/* value to use in restoring planes */
+    Bool save_under;           /* should bits under be saved? (popups) */
+    long event_mask;           /* set of events that should be saved */
+    long do_not_propagate_mask;        /* set of events that should not propagate */
+    Bool override_redirect;    /* boolean value for override-redirect */
+    Colormap colormap;         /* color map to be associated with window */
+    Cursor cursor;             /* cursor to be displayed (or None) */
+} XSetWindowAttributes;
+
+typedef struct {
+    int x, y;                  /* location of window */
+    int width, height;         /* width and height of window */
+    int border_width;          /* border width of window */
+    int depth;                 /* depth of window */
+    Visual *visual;            /* the associated visual structure */
+    Window root;               /* root of screen containing window */
+#if defined(__cplusplus) || defined(c_plusplus)
+    int c_class;               /* C++ InputOutput, InputOnly*/
+#else
+    int class;                 /* InputOutput, InputOnly*/
+#endif
+    int bit_gravity;           /* one of bit gravity values */
+    int win_gravity;           /* one of the window gravity values */
+    int backing_store;         /* NotUseful, WhenMapped, Always */
+    unsigned long backing_planes;/* planes to be preserved if possible */
+    unsigned long backing_pixel;/* value to be used when restoring planes */
+    Bool save_under;           /* boolean, should bits under be saved? */
+    Colormap colormap;         /* color map to be associated with window */
+    Bool map_installed;                /* boolean, is color map currently installed*/
+    int map_state;             /* IsUnmapped, IsUnviewable, IsViewable */
+    long all_event_masks;      /* set of events all people have interest in*/
+    long your_event_mask;      /* my event mask */
+    long do_not_propagate_mask; /* set of events that should not propagate */
+    Bool override_redirect;    /* boolean value for override-redirect */
+    Screen *screen;            /* back pointer to correct screen */
+} XWindowAttributes;
+
+/*
+ * Data structure for host setting; getting routines.
+ *
+ */
+
+typedef struct {
+       int family;             /* for example FamilyInternet */
+       int length;             /* length of address, in bytes */
+       char *address;          /* pointer to where to find the bytes */
+} XHostAddress;
+
+/*
+ * Data structure for "image" data, used by image manipulation routines.
+ */
+typedef struct _XImage {
+    int width, height;         /* size of image */
+    int xoffset;               /* number of pixels offset in X direction */
+    int format;                        /* XYBitmap, XYPixmap, ZPixmap */
+    char *data;                        /* pointer to image data */
+    int byte_order;            /* data byte order, LSBFirst, MSBFirst */
+    int bitmap_unit;           /* quant. of scanline 8, 16, 32 */
+    int bitmap_bit_order;      /* LSBFirst, MSBFirst */
+    int bitmap_pad;            /* 8, 16, 32 either XY or ZPixmap */
+    int depth;                 /* depth of image */
+    int bytes_per_line;                /* accelarator to next line */
+    int bits_per_pixel;                /* bits per pixel (ZPixmap) */
+    unsigned long red_mask;    /* bits in z arrangment */
+    unsigned long green_mask;
+    unsigned long blue_mask;
+    XPointer obdata;           /* hook for the object routines to hang on */
+    struct funcs {             /* image manipulation routines */
+#if NeedFunctionPrototypes
+       struct _XImage *(*create_image)(
+               struct _XDisplay* /* display */,
+               Visual*         /* visual */,
+               unsigned int    /* depth */,
+               int             /* format */,
+               int             /* offset */,
+               char*           /* data */,
+               unsigned int    /* width */,
+               unsigned int    /* height */,
+               int             /* bitmap_pad */,
+               int             /* bytes_per_line */);
+       int (*destroy_image)        (struct _XImage *);
+       unsigned long (*get_pixel)  (struct _XImage *, int, int);
+       int (*put_pixel)            (struct _XImage *, int, int, unsigned long);
+       struct _XImage *(*sub_image)(struct _XImage *, int, int, unsigned int, unsigned int);
+       int (*add_pixel)            (struct _XImage *, long);
+#else
+       struct _XImage *(*create_image)();
+       int (*destroy_image)();
+       unsigned long (*get_pixel)();
+       int (*put_pixel)();
+       struct _XImage *(*sub_image)();
+       int (*add_pixel)();
+#endif
+       } f;
+} XImage;
+
+/* 
+ * Data structure for XReconfigureWindow
+ */
+typedef struct {
+    int x, y;
+    int width, height;
+    int border_width;
+    Window sibling;
+    int stack_mode;
+} XWindowChanges;
+
+/*
+ * Data structure used by color operations
+ */
+typedef struct {
+       unsigned long pixel;
+       unsigned short red, green, blue;
+       char flags;  /* do_red, do_green, do_blue */
+       char pad;
+} XColor;
+
+/* 
+ * Data structures for graphics operations.  On most machines, these are
+ * congruent with the wire protocol structures, so reformatting the data
+ * can be avoided on these architectures.
+ */
+typedef struct {
+    short x1, y1, x2, y2;
+} XSegment;
+
+typedef struct {
+    short x, y;
+} XPoint;
+    
+typedef struct {
+    short x, y;
+    unsigned short width, height;
+} XRectangle;
+    
+typedef struct {
+    short x, y;
+    unsigned short width, height;
+    short angle1, angle2;
+} XArc;
+
+
+/* Data structure for XChangeKeyboardControl */
+
+typedef struct {
+        int key_click_percent;
+        int bell_percent;
+        int bell_pitch;
+        int bell_duration;
+        int led;
+        int led_mode;
+        int key;
+        int auto_repeat_mode;   /* On, Off, Default */
+} XKeyboardControl;
+
+/* Data structure for XGetKeyboardControl */
+
+typedef struct {
+        int key_click_percent;
+       int bell_percent;
+       unsigned int bell_pitch, bell_duration;
+       unsigned long led_mask;
+       int global_auto_repeat;
+       char auto_repeats[32];
+} XKeyboardState;
+
+/* Data structure for XGetMotionEvents.  */
+
+typedef struct {
+        Time time;
+       short x, y;
+} XTimeCoord;
+
+/* Data structure for X{Set,Get}ModifierMapping */
+
+typedef struct {
+       int max_keypermod;      /* The server's max # of keys per modifier */
+       KeyCode *modifiermap;   /* An 8 by max_keypermod array of modifiers */
+} XModifierKeymap;
+
+
+/*
+ * Display datatype maintaining display specific data.
+ * The contents of this structure are implementation dependent.
+ * A Display should be treated as opaque by application code.
+ */
+#ifndef XLIB_ILLEGAL_ACCESS
+typedef struct _XDisplay Display;
+#endif
+
+struct _XPrivate;              /* Forward declare before use for C++ */
+struct _XrmHashBucketRec;
+
+typedef struct 
+#ifdef XLIB_ILLEGAL_ACCESS
+_XDisplay
+#endif
+{
+       XExtData *ext_data;     /* hook for extension to hang data */
+       struct _XPrivate *private1;
+       int fd;                 /* Network socket. */
+       int private2;
+       int proto_major_version;/* major version of server's X protocol */
+       int proto_minor_version;/* minor version of servers X protocol */
+       char *vendor;           /* vendor of the server hardware */
+        XID private3;
+       XID private4;
+       XID private5;
+       int private6;
+       XID (*resource_alloc)(  /* allocator function */
+#if NeedFunctionPrototypes
+               struct _XDisplay*
+#endif
+       );
+       int byte_order;         /* screen byte order, LSBFirst, MSBFirst */
+       int bitmap_unit;        /* padding and data requirements */
+       int bitmap_pad;         /* padding requirements on bitmaps */
+       int bitmap_bit_order;   /* LeastSignificant or MostSignificant */
+       int nformats;           /* number of pixmap formats in list */
+       ScreenFormat *pixmap_format;    /* pixmap format list */
+       int private8;
+       int release;            /* release of the server */
+       struct _XPrivate *private9, *private10;
+       int qlen;               /* Length of input event queue */
+       unsigned long last_request_read; /* seq number of last event read */
+       unsigned long request;  /* sequence number of last request. */
+       XPointer private11;
+       XPointer private12;
+       XPointer private13;
+       XPointer private14;
+       unsigned max_request_size; /* maximum number 32 bit words in request*/
+       struct _XrmHashBucketRec *db;
+       int (*private15)(
+#if NeedFunctionPrototypes
+               struct _XDisplay*
+#endif
+               );
+       char *display_name;     /* "host:display" string used on this connect*/
+       int default_screen;     /* default screen for operations */
+       int nscreens;           /* number of screens on this server*/
+       Screen *screens;        /* pointer to list of screens */
+       unsigned long motion_buffer;    /* size of motion buffer */
+       unsigned long private16;
+       int min_keycode;        /* minimum defined keycode */
+       int max_keycode;        /* maximum defined keycode */
+       XPointer private17;
+       XPointer private18;
+       int private19;
+       char *xdefaults;        /* contents of defaults from server */
+       /* there is more to this structure, but it is private to Xlib */
+}
+#ifdef XLIB_ILLEGAL_ACCESS
+Display, 
+#endif
+*_XPrivDisplay;
+
+#if NeedFunctionPrototypes     /* prototypes require event type definitions */
+#undef _XEVENT_
+#endif
+#ifndef _XEVENT_
+/*
+ * Definitions of specific events.
+ */
+typedef struct {
+       int type;               /* of event */
+       unsigned long serial;   /* # of last request processed by server */
+       Bool send_event;        /* true if this came from a SendEvent request */
+       Display *display;       /* Display the event was read from */
+       Window window;          /* "event" window it is reported relative to */
+       Window root;            /* root window that the event occured on */
+       Window subwindow;       /* child window */
+       Time time;              /* milliseconds */
+       int x, y;               /* pointer x, y coordinates in event window */
+       int x_root, y_root;     /* coordinates relative to root */
+       unsigned int state;     /* key or button mask */
+       unsigned int keycode;   /* detail */
+       Bool same_screen;       /* same screen flag */
+} XKeyEvent;
+typedef XKeyEvent XKeyPressedEvent;
+typedef XKeyEvent XKeyReleasedEvent;
+
+typedef struct {
+       int type;               /* of event */
+       unsigned long serial;   /* # of last request processed by server */
+       Bool send_event;        /* true if this came from a SendEvent request */
+       Display *display;       /* Display the event was read from */
+       Window window;          /* "event" window it is reported relative to */
+       Window root;            /* root window that the event occured on */
+       Window subwindow;       /* child window */
+       Time time;              /* milliseconds */
+       int x, y;               /* pointer x, y coordinates in event window */
+       int x_root, y_root;     /* coordinates relative to root */
+       unsigned int state;     /* key or button mask */
+       unsigned int button;    /* detail */
+       Bool same_screen;       /* same screen flag */
+} XButtonEvent;
+typedef XButtonEvent XButtonPressedEvent;
+typedef XButtonEvent XButtonReleasedEvent;
+
+typedef struct {
+       int type;               /* of event */
+       unsigned long serial;   /* # of last request processed by server */
+       Bool send_event;        /* true if this came from a SendEvent request */
+       Display *display;       /* Display the event was read from */
+       Window window;          /* "event" window reported relative to */
+       Window root;            /* root window that the event occured on */
+       Window subwindow;       /* child window */
+       Time time;              /* milliseconds */
+       int x, y;               /* pointer x, y coordinates in event window */
+       int x_root, y_root;     /* coordinates relative to root */
+       unsigned int state;     /* key or button mask */
+       char is_hint;           /* detail */
+       Bool same_screen;       /* same screen flag */
+} XMotionEvent;
+typedef XMotionEvent XPointerMovedEvent;
+
+typedef struct {
+       int type;               /* of event */
+       unsigned long serial;   /* # of last request processed by server */
+       Bool send_event;        /* true if this came from a SendEvent request */
+       Display *display;       /* Display the event was read from */
+       Window window;          /* "event" window reported relative to */
+       Window root;            /* root window that the event occured on */
+       Window subwindow;       /* child window */
+       Time time;              /* milliseconds */
+       int x, y;               /* pointer x, y coordinates in event window */
+       int x_root, y_root;     /* coordinates relative to root */
+       int mode;               /* NotifyNormal, NotifyGrab, NotifyUngrab */
+       int detail;
+       /*
+        * NotifyAncestor, NotifyVirtual, NotifyInferior, 
+        * NotifyNonlinear,NotifyNonlinearVirtual
+        */
+       Bool same_screen;       /* same screen flag */
+       Bool focus;             /* boolean focus */
+       unsigned int state;     /* key or button mask */
+} XCrossingEvent;
+typedef XCrossingEvent XEnterWindowEvent;
+typedef XCrossingEvent XLeaveWindowEvent;
+
+typedef struct {
+       int type;               /* FocusIn or FocusOut */
+       unsigned long serial;   /* # of last request processed by server */
+       Bool send_event;        /* true if this came from a SendEvent request */
+       Display *display;       /* Display the event was read from */
+       Window window;          /* window of event */
+       int mode;               /* NotifyNormal, NotifyGrab, NotifyUngrab */
+       int detail;
+       /*
+        * NotifyAncestor, NotifyVirtual, NotifyInferior, 
+        * NotifyNonlinear,NotifyNonlinearVirtual, NotifyPointer,
+        * NotifyPointerRoot, NotifyDetailNone 
+        */
+} XFocusChangeEvent;
+typedef XFocusChangeEvent XFocusInEvent;
+typedef XFocusChangeEvent XFocusOutEvent;
+
+/* generated on EnterWindow and FocusIn  when KeyMapState selected */
+typedef struct {
+       int type;
+       unsigned long serial;   /* # of last request processed by server */
+       Bool send_event;        /* true if this came from a SendEvent request */
+       Display *display;       /* Display the event was read from */
+       Window window;
+       char key_vector[32];
+} XKeymapEvent;        
+
+typedef struct {
+       int type;
+       unsigned long serial;   /* # of last request processed by server */
+       Bool send_event;        /* true if this came from a SendEvent request */
+       Display *display;       /* Display the event was read from */
+       Window window;
+       int x, y;
+       int width, height;
+       int count;              /* if non-zero, at least this many more */
+} XExposeEvent;
+
+typedef struct {
+       int type;
+       unsigned long serial;   /* # of last request processed by server */
+       Bool send_event;        /* true if this came from a SendEvent request */
+       Display *display;       /* Display the event was read from */
+       Drawable drawable;
+       int x, y;
+       int width, height;
+       int count;              /* if non-zero, at least this many more */
+       int major_code;         /* core is CopyArea or CopyPlane */
+       int minor_code;         /* not defined in the core */
+} XGraphicsExposeEvent;
+
+typedef struct {
+       int type;
+       unsigned long serial;   /* # of last request processed by server */
+       Bool send_event;        /* true if this came from a SendEvent request */
+       Display *display;       /* Display the event was read from */
+       Drawable drawable;
+       int major_code;         /* core is CopyArea or CopyPlane */
+       int minor_code;         /* not defined in the core */
+} XNoExposeEvent;
+
+typedef struct {
+       int type;
+       unsigned long serial;   /* # of last request processed by server */
+       Bool send_event;        /* true if this came from a SendEvent request */
+       Display *display;       /* Display the event was read from */
+       Window window;
+       int state;              /* Visibility state */
+} XVisibilityEvent;
+
+typedef struct {
+       int type;
+       unsigned long serial;   /* # of last request processed by server */
+       Bool send_event;        /* true if this came from a SendEvent request */
+       Display *display;       /* Display the event was read from */
+       Window parent;          /* parent of the window */
+       Window window;          /* window id of window created */
+       int x, y;               /* window location */
+       int width, height;      /* size of window */
+       int border_width;       /* border width */
+       Bool override_redirect; /* creation should be overridden */
+} XCreateWindowEvent;
+
+typedef struct {
+       int type;
+       unsigned long serial;   /* # of last request processed by server */
+       Bool send_event;        /* true if this came from a SendEvent request */
+       Display *display;       /* Display the event was read from */
+       Window event;
+       Window window;
+} XDestroyWindowEvent;
+
+typedef struct {
+       int type;
+       unsigned long serial;   /* # of last request processed by server */
+       Bool send_event;        /* true if this came from a SendEvent request */
+       Display *display;       /* Display the event was read from */
+       Window event;
+       Window window;
+       Bool from_configure;
+} XUnmapEvent;
+
+typedef struct {
+       int type;
+       unsigned long serial;   /* # of last request processed by server */
+       Bool send_event;        /* true if this came from a SendEvent request */
+       Display *display;       /* Display the event was read from */
+       Window event;
+       Window window;
+       Bool override_redirect; /* boolean, is override set... */
+} XMapEvent;
+
+typedef struct {
+       int type;
+       unsigned long serial;   /* # of last request processed by server */
+       Bool send_event;        /* true if this came from a SendEvent request */
+       Display *display;       /* Display the event was read from */
+       Window parent;
+       Window window;
+} XMapRequestEvent;
+
+typedef struct {
+       int type;
+       unsigned long serial;   /* # of last request processed by server */
+       Bool send_event;        /* true if this came from a SendEvent request */
+       Display *display;       /* Display the event was read from */
+       Window event;
+       Window window;
+       Window parent;
+       int x, y;
+       Bool override_redirect;
+} XReparentEvent;
+
+typedef struct {
+       int type;
+       unsigned long serial;   /* # of last request processed by server */
+       Bool send_event;        /* true if this came from a SendEvent request */
+       Display *display;       /* Display the event was read from */
+       Window event;
+       Window window;
+       int x, y;
+       int width, height;
+       int border_width;
+       Window above;
+       Bool override_redirect;
+} XConfigureEvent;
+
+typedef struct {
+       int type;
+       unsigned long serial;   /* # of last request processed by server */
+       Bool send_event;        /* true if this came from a SendEvent request */
+       Display *display;       /* Display the event was read from */
+       Window event;
+       Window window;
+       int x, y;
+} XGravityEvent;
+
+typedef struct {
+       int type;
+       unsigned long serial;   /* # of last request processed by server */
+       Bool send_event;        /* true if this came from a SendEvent request */
+       Display *display;       /* Display the event was read from */
+       Window window;
+       int width, height;
+} XResizeRequestEvent;
+
+typedef struct {
+       int type;
+       unsigned long serial;   /* # of last request processed by server */
+       Bool send_event;        /* true if this came from a SendEvent request */
+       Display *display;       /* Display the event was read from */
+       Window parent;
+       Window window;
+       int x, y;
+       int width, height;
+       int border_width;
+       Window above;
+       int detail;             /* Above, Below, TopIf, BottomIf, Opposite */
+       unsigned long value_mask;
+} XConfigureRequestEvent;
+
+typedef struct {
+       int type;
+       unsigned long serial;   /* # of last request processed by server */
+       Bool send_event;        /* true if this came from a SendEvent request */
+       Display *display;       /* Display the event was read from */
+       Window event;
+       Window window;
+       int place;              /* PlaceOnTop, PlaceOnBottom */
+} XCirculateEvent;
+
+typedef struct {
+       int type;
+       unsigned long serial;   /* # of last request processed by server */
+       Bool send_event;        /* true if this came from a SendEvent request */
+       Display *display;       /* Display the event was read from */
+       Window parent;
+       Window window;
+       int place;              /* PlaceOnTop, PlaceOnBottom */
+} XCirculateRequestEvent;
+
+typedef struct {
+       int type;
+       unsigned long serial;   /* # of last request processed by server */
+       Bool send_event;        /* true if this came from a SendEvent request */
+       Display *display;       /* Display the event was read from */
+       Window window;
+       Atom atom;
+       Time time;
+       int state;              /* NewValue, Deleted */
+} XPropertyEvent;
+
+typedef struct {
+       int type;
+       unsigned long serial;   /* # of last request processed by server */
+       Bool send_event;        /* true if this came from a SendEvent request */
+       Display *display;       /* Display the event was read from */
+       Window window;
+       Atom selection;
+       Time time;
+} XSelectionClearEvent;
+
+typedef struct {
+       int type;
+       unsigned long serial;   /* # of last request processed by server */
+       Bool send_event;        /* true if this came from a SendEvent request */
+       Display *display;       /* Display the event was read from */
+       Window owner;
+       Window requestor;
+       Atom selection;
+       Atom target;
+       Atom property;
+       Time time;
+} XSelectionRequestEvent;
+
+typedef struct {
+       int type;
+       unsigned long serial;   /* # of last request processed by server */
+       Bool send_event;        /* true if this came from a SendEvent request */
+       Display *display;       /* Display the event was read from */
+       Window requestor;
+       Atom selection;
+       Atom target;
+       Atom property;          /* ATOM or None */
+       Time time;
+} XSelectionEvent;
+
+typedef struct {
+       int type;
+       unsigned long serial;   /* # of last request processed by server */
+       Bool send_event;        /* true if this came from a SendEvent request */
+       Display *display;       /* Display the event was read from */
+       Window window;
+       Colormap colormap;      /* COLORMAP or None */
+#if defined(__cplusplus) || defined(c_plusplus)
+       Bool c_new;             /* C++ */
+#else
+       Bool new;
+#endif
+       int state;              /* ColormapInstalled, ColormapUninstalled */
+} XColormapEvent;
+
+typedef struct {
+       int type;
+       unsigned long serial;   /* # of last request processed by server */
+       Bool send_event;        /* true if this came from a SendEvent request */
+       Display *display;       /* Display the event was read from */
+       Window window;
+       Atom message_type;
+       int format;
+       union {
+               char b[20];
+               short s[10];
+               long l[5];
+               } data;
+} XClientMessageEvent;
+
+typedef struct {
+       int type;
+       unsigned long serial;   /* # of last request processed by server */
+       Bool send_event;        /* true if this came from a SendEvent request */
+       Display *display;       /* Display the event was read from */
+       Window window;          /* unused */
+       int request;            /* one of MappingModifier, MappingKeyboard,
+                                  MappingPointer */
+       int first_keycode;      /* first keycode */
+       int count;              /* defines range of change w. first_keycode*/
+} XMappingEvent;
+
+typedef struct {
+       int type;
+       Display *display;       /* Display the event was read from */
+       XID resourceid;         /* resource id */
+       unsigned long serial;   /* serial number of failed request */
+       unsigned char error_code;       /* error code of failed request */
+       unsigned char request_code;     /* Major op-code of failed request */
+       unsigned char minor_code;       /* Minor op-code of failed request */
+} XErrorEvent;
+
+typedef struct {
+       int type;
+       unsigned long serial;   /* # of last request processed by server */
+       Bool send_event;        /* true if this came from a SendEvent request */
+       Display *display;/* Display the event was read from */
+       Window window;  /* window on which event was requested in event mask */
+} XAnyEvent;
+
+/*
+ * this union is defined so Xlib can always use the same sized
+ * event structure internally, to avoid memory fragmentation.
+ */
+typedef union _XEvent {
+        int type;              /* must not be changed; first element */
+       XAnyEvent xany;
+       XKeyEvent xkey;
+       XButtonEvent xbutton;
+       XMotionEvent xmotion;
+       XCrossingEvent xcrossing;
+       XFocusChangeEvent xfocus;
+       XExposeEvent xexpose;
+       XGraphicsExposeEvent xgraphicsexpose;
+       XNoExposeEvent xnoexpose;
+       XVisibilityEvent xvisibility;
+       XCreateWindowEvent xcreatewindow;
+       XDestroyWindowEvent xdestroywindow;
+       XUnmapEvent xunmap;
+       XMapEvent xmap;
+       XMapRequestEvent xmaprequest;
+       XReparentEvent xreparent;
+       XConfigureEvent xconfigure;
+       XGravityEvent xgravity;
+       XResizeRequestEvent xresizerequest;
+       XConfigureRequestEvent xconfigurerequest;
+       XCirculateEvent xcirculate;
+       XCirculateRequestEvent xcirculaterequest;
+       XPropertyEvent xproperty;
+       XSelectionClearEvent xselectionclear;
+       XSelectionRequestEvent xselectionrequest;
+       XSelectionEvent xselection;
+       XColormapEvent xcolormap;
+       XClientMessageEvent xclient;
+       XMappingEvent xmapping;
+       XErrorEvent xerror;
+       XKeymapEvent xkeymap;
+       long pad[24];
+} XEvent;
+#endif
+
+#define XAllocID(dpy) ((*((_XPrivDisplay)dpy)->resource_alloc)((dpy)))
+
+/*
+ * per character font metric information.
+ */
+typedef struct {
+    short      lbearing;       /* origin to left edge of raster */
+    short      rbearing;       /* origin to right edge of raster */
+    short      width;          /* advance to next char's origin */
+    short      ascent;         /* baseline to top edge of raster */
+    short      descent;        /* baseline to bottom edge of raster */
+    unsigned short attributes; /* per char flags (not predefined) */
+} XCharStruct;
+
+/*
+ * To allow arbitrary information with fonts, there are additional properties
+ * returned.
+ */
+typedef struct {
+    Atom name;
+    unsigned long card32;
+} XFontProp;
+
+typedef struct {
+    XExtData   *ext_data;      /* hook for extension to hang data */
+    Font        fid;            /* Font id for this font */
+    unsigned   direction;      /* hint about direction the font is painted */
+    unsigned   min_char_or_byte2;/* first character */
+    unsigned   max_char_or_byte2;/* last character */
+    unsigned   min_byte1;      /* first row that exists */
+    unsigned   max_byte1;      /* last row that exists */
+    Bool       all_chars_exist;/* flag if all characters have non-zero size*/
+    unsigned   default_char;   /* char to print for undefined character */
+    int         n_properties;   /* how many properties there are */
+    XFontProp  *properties;    /* pointer to array of additional properties*/
+    XCharStruct        min_bounds;     /* minimum bounds over all existing char*/
+    XCharStruct        max_bounds;     /* maximum bounds over all existing char*/
+    XCharStruct        *per_char;      /* first_char to last_char information */
+    int                ascent;         /* log. extent above baseline for spacing */
+    int                descent;        /* log. descent below baseline for spacing */
+} XFontStruct;
+
+/*
+ * PolyText routines take these as arguments.
+ */
+typedef struct {
+    char *chars;               /* pointer to string */
+    int nchars;                        /* number of characters */
+    int delta;                 /* delta between strings */
+    Font font;                 /* font to print it in, None don't change */
+} XTextItem;
+
+typedef struct {               /* normal 16 bit characters are two bytes */
+    unsigned char byte1;
+    unsigned char byte2;
+} XChar2b;
+
+typedef struct {
+    XChar2b *chars;            /* two byte characters */
+    int nchars;                        /* number of characters */
+    int delta;                 /* delta between strings */
+    Font font;                 /* font to print it in, None don't change */
+} XTextItem16;
+
+
+typedef union { Display *display;
+               GC gc;
+               Visual *visual;
+               Screen *screen;
+               ScreenFormat *pixmap_format;
+               XFontStruct *font; } XEDataObject;
+
+typedef struct {
+    XRectangle      max_ink_extent;
+    XRectangle      max_logical_extent;
+} XFontSetExtents;
+
+/* unused:
+typedef void (*XOMProc)();
+ */
+
+typedef struct _XOM *XOM;
+typedef struct _XOC *XOC, *XFontSet;
+
+typedef struct {
+    char           *chars;
+    int             nchars;
+    int             delta;
+    XFontSet        font_set;
+} XmbTextItem;
+
+typedef struct {
+    wchar_t        *chars;
+    int             nchars;
+    int             delta;
+    XFontSet        font_set;
+} XwcTextItem;
+
+#define XNRequiredCharSet "requiredCharSet"
+#define XNQueryOrientation "queryOrientation"
+#define XNBaseFontName "baseFontName"
+#define XNOMAutomatic "omAutomatic"
+#define XNMissingCharSet "missingCharSet"
+#define XNDefaultString "defaultString"
+#define XNOrientation "orientation"
+#define XNDirectionalDependentDrawing "directionalDependentDrawing"
+#define XNContextualDrawing "contextualDrawing"
+#define XNFontInfo "fontInfo"
+
+typedef struct {
+    int charset_count;
+    char **charset_list;
+} XOMCharSetList;
+
+typedef enum {
+    XOMOrientation_LTR_TTB,
+    XOMOrientation_RTL_TTB,
+    XOMOrientation_TTB_LTR,
+    XOMOrientation_TTB_RTL,
+    XOMOrientation_Context
+} XOrientation;
+
+typedef struct {
+    int num_orientation;
+    XOrientation *orientation; /* Input Text description */
+} XOMOrientation;
+
+typedef struct {
+    int num_font;
+    XFontStruct **font_struct_list;
+    char **font_name_list;
+} XOMFontInfo;
+
+typedef struct _XIM *XIM;
+typedef struct _XIC *XIC;
+
+typedef void (*XIMProc)(
+#if NeedFunctionPrototypes
+    XIM,
+    XPointer,
+    XPointer
+#endif
+);
+
+typedef Bool (*XICProc)(
+#if NeedFunctionPrototypes
+    XIC,
+    XPointer,
+    XPointer
+#endif
+);
+
+typedef void (*XIDProc)(
+#if NeedFunctionPrototypes
+    Display*,
+    XPointer,
+    XPointer
+#endif
+);
+
+typedef unsigned long XIMStyle;
+
+typedef struct {
+    unsigned short count_styles;
+    XIMStyle *supported_styles;
+} XIMStyles;
+
+#define XIMPreeditArea         0x0001L
+#define XIMPreeditCallbacks    0x0002L
+#define XIMPreeditPosition     0x0004L
+#define XIMPreeditNothing      0x0008L
+#define XIMPreeditNone         0x0010L
+#define XIMStatusArea          0x0100L
+#define XIMStatusCallbacks     0x0200L
+#define XIMStatusNothing       0x0400L
+#define XIMStatusNone          0x0800L
+
+#define XNVaNestedList "XNVaNestedList"
+#define XNQueryInputStyle "queryInputStyle"
+#define XNClientWindow "clientWindow"
+#define XNInputStyle "inputStyle"
+#define XNFocusWindow "focusWindow"
+#define XNResourceName "resourceName"
+#define XNResourceClass "resourceClass"
+#define XNGeometryCallback "geometryCallback"
+#define XNDestroyCallback "destroyCallback"
+#define XNFilterEvents "filterEvents"
+#define XNPreeditStartCallback "preeditStartCallback"
+#define XNPreeditDoneCallback "preeditDoneCallback"
+#define XNPreeditDrawCallback "preeditDrawCallback"
+#define XNPreeditCaretCallback "preeditCaretCallback"
+#define XNPreeditStateNotifyCallback "preeditStateNotifyCallback"
+#define XNPreeditAttributes "preeditAttributes"
+#define XNStatusStartCallback "statusStartCallback"
+#define XNStatusDoneCallback "statusDoneCallback"
+#define XNStatusDrawCallback "statusDrawCallback"
+#define XNStatusAttributes "statusAttributes"
+#define XNArea "area"
+#define XNAreaNeeded "areaNeeded"
+#define XNSpotLocation "spotLocation"
+#define XNColormap "colorMap"
+#define XNStdColormap "stdColorMap"
+#define XNForeground "foreground"
+#define XNBackground "background"
+#define XNBackgroundPixmap "backgroundPixmap"
+#define XNFontSet "fontSet"
+#define XNLineSpace "lineSpace"
+#define XNCursor "cursor"
+
+#define XNQueryIMValuesList "queryIMValuesList"
+#define XNQueryICValuesList "queryICValuesList"
+#define XNVisiblePosition "visiblePosition"
+#define XNR6PreeditCallback "r6PreeditCallback"
+#define XNStringConversionCallback "stringConversionCallback"
+#define XNStringConversion "stringConversion"
+#define XNResetState "resetState"
+#define XNHotKey "hotKey"
+#define XNHotKeyState "hotKeyState"
+#define XNPreeditState "preeditState"
+#define XNSeparatorofNestedList "separatorofNestedList"
+
+#define XBufferOverflow                -1
+#define XLookupNone            1
+#define XLookupChars           2
+#define XLookupKeySym          3
+#define XLookupBoth            4
+
+#if NeedFunctionPrototypes
+typedef void *XVaNestedList;
+#else
+typedef XPointer XVaNestedList;
+#endif
+
+typedef struct {
+    XPointer client_data;
+    XIMProc callback;
+} XIMCallback;
+
+typedef struct {
+    XPointer client_data;
+    XICProc callback;
+} XICCallback;
+
+typedef unsigned long XIMFeedback;
+
+#define XIMReverse             1L
+#define XIMUnderline           (1L<<1) 
+#define XIMHighlight           (1L<<2)
+#define XIMPrimary             (1L<<5)
+#define XIMSecondary           (1L<<6)
+#define XIMTertiary            (1L<<7)
+#define XIMVisibleToForward    (1L<<8)
+#define XIMVisibleToBackword   (1L<<9)
+#define XIMVisibleToCenter     (1L<<10)
+
+typedef struct _XIMText {
+    unsigned short length;
+    XIMFeedback *feedback;
+    Bool encoding_is_wchar; 
+    union {
+       char *multi_byte;
+       wchar_t *wide_char;
+    } string; 
+} XIMText;
+
+typedef        unsigned long    XIMPreeditState;
+
+#define        XIMPreeditUnKnown       0L
+#define        XIMPreeditEnable        1L
+#define        XIMPreeditDisable       (1L<<1)
+
+typedef        struct  _XIMPreeditStateNotifyCallbackStruct {
+    XIMPreeditState state;
+} XIMPreeditStateNotifyCallbackStruct;
+
+typedef        unsigned long    XIMResetState;
+
+#define        XIMInitialState         1L
+#define        XIMPreserveState        (1L<<1)
+
+typedef unsigned long XIMStringConversionFeedback;
+
+#define        XIMStringConversionLeftEdge     (0x00000001)
+#define        XIMStringConversionRightEdge    (0x00000002)
+#define        XIMStringConversionTopEdge      (0x00000004)
+#define        XIMStringConversionBottomEdge   (0x00000008)
+#define        XIMStringConversionConcealed    (0x00000010)
+#define        XIMStringConversionWrapped      (0x00000020)
+
+typedef struct _XIMStringConversionText {
+    unsigned short length;
+    XIMStringConversionFeedback *feedback;
+    Bool encoding_is_wchar; 
+    union {
+       char *mbs;
+       wchar_t *wcs;
+    } string; 
+} XIMStringConversionText;
+
+typedef        unsigned short  XIMStringConversionPosition;
+
+typedef        unsigned short  XIMStringConversionType;
+
+#define        XIMStringConversionBuffer       (0x0001)
+#define        XIMStringConversionLine         (0x0002)
+#define        XIMStringConversionWord         (0x0003)
+#define        XIMStringConversionChar         (0x0004)
+
+typedef        unsigned short  XIMStringConversionOperation;
+
+#define        XIMStringConversionSubstitution (0x0001)
+#define        XIMStringConversionRetrival     (0x0002)
+
+typedef enum {
+    XIMForwardChar, XIMBackwardChar,
+    XIMForwardWord, XIMBackwardWord,
+    XIMCaretUp, XIMCaretDown,
+    XIMNextLine, XIMPreviousLine,
+    XIMLineStart, XIMLineEnd, 
+    XIMAbsolutePosition,
+    XIMDontChange
+} XIMCaretDirection;
+
+typedef struct _XIMStringConversionCallbackStruct {
+    XIMStringConversionPosition position;
+    XIMCaretDirection direction;
+    XIMStringConversionOperation operation;
+    unsigned short factor;
+    XIMStringConversionText *text;
+} XIMStringConversionCallbackStruct;
+
+typedef struct _XIMPreeditDrawCallbackStruct {
+    int caret;         /* Cursor offset within pre-edit string */
+    int chg_first;     /* Starting change position */
+    int chg_length;    /* Length of the change in character count */
+    XIMText *text;
+} XIMPreeditDrawCallbackStruct;
+
+typedef enum {
+    XIMIsInvisible,    /* Disable caret feedback */ 
+    XIMIsPrimary,      /* UI defined caret feedback */
+    XIMIsSecondary     /* UI defined caret feedback */
+} XIMCaretStyle;
+
+typedef struct _XIMPreeditCaretCallbackStruct {
+    int position;               /* Caret offset within pre-edit string */
+    XIMCaretDirection direction; /* Caret moves direction */
+    XIMCaretStyle style;        /* Feedback of the caret */
+} XIMPreeditCaretCallbackStruct;
+
+typedef enum {
+    XIMTextType,
+    XIMBitmapType
+} XIMStatusDataType;
+       
+typedef struct _XIMStatusDrawCallbackStruct {
+    XIMStatusDataType type;
+    union {
+       XIMText *text;
+       Pixmap  bitmap;
+    } data;
+} XIMStatusDrawCallbackStruct;
+
+typedef struct _XIMHotKeyTrigger {
+    KeySym      keysym;
+    int                 modifier;
+    int                 modifier_mask;
+} XIMHotKeyTrigger;
+
+typedef struct _XIMHotKeyTriggers {
+    int                         num_hot_key;
+    XIMHotKeyTrigger   *key;
+} XIMHotKeyTriggers;
+
+typedef        unsigned long    XIMHotKeyState;
+
+#define        XIMHotKeyStateON        (0x0001L)
+#define        XIMHotKeyStateOFF       (0x0002L)
+
+typedef struct {
+    unsigned short count_values;
+    char **supported_values;
+} XIMValuesList;
+
+_XFUNCPROTOBEGIN
+
+#if defined(WIN32) && !defined(_XLIBINT_)
+#define _Xdebug (*_Xdebug_p)
+#endif
+
+extern int _Xdebug;
+
+extern XFontStruct *XLoadQueryFont(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    _Xconst char*      /* name */
+#endif
+);
+
+extern XFontStruct *XQueryFont(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    XID                        /* font_ID */
+#endif
+);
+
+
+extern XTimeCoord *XGetMotionEvents(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    Window             /* w */,
+    Time               /* start */,
+    Time               /* stop */,
+    int*               /* nevents_return */
+#endif
+);
+
+extern XModifierKeymap *XDeleteModifiermapEntry(
+#if NeedFunctionPrototypes
+    XModifierKeymap*   /* modmap */,
+#if NeedWidePrototypes
+    unsigned int       /* keycode_entry */,
+#else
+    KeyCode            /* keycode_entry */,
+#endif
+    int                        /* modifier */
+#endif
+);
+
+extern XModifierKeymap *XGetModifierMapping(
+#if NeedFunctionPrototypes
+    Display*           /* display */
+#endif
+);
+
+extern XModifierKeymap *XInsertModifiermapEntry(
+#if NeedFunctionPrototypes
+    XModifierKeymap*   /* modmap */,
+#if NeedWidePrototypes
+    unsigned int       /* keycode_entry */,
+#else
+    KeyCode            /* keycode_entry */,
+#endif
+    int                        /* modifier */    
+#endif
+);
+
+extern XModifierKeymap *XNewModifiermap(
+#if NeedFunctionPrototypes
+    int                        /* max_keys_per_mod */
+#endif
+);
+
+extern XImage *XCreateImage(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    Visual*            /* visual */,
+    unsigned int       /* depth */,
+    int                        /* format */,
+    int                        /* offset */,
+    char*              /* data */,
+    unsigned int       /* width */,
+    unsigned int       /* height */,
+    int                        /* bitmap_pad */,
+    int                        /* bytes_per_line */
+#endif
+);
+extern Status XInitImage(
+#if NeedFunctionPrototypes
+    XImage*            /* image */
+#endif
+);
+extern XImage *XGetImage(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    Drawable           /* d */,
+    int                        /* x */,
+    int                        /* y */,
+    unsigned int       /* width */,
+    unsigned int       /* height */,
+    unsigned long      /* plane_mask */,
+    int                        /* format */
+#endif
+);
+extern XImage *XGetSubImage(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    Drawable           /* d */,
+    int                        /* x */,
+    int                        /* y */,
+    unsigned int       /* width */,
+    unsigned int       /* height */,
+    unsigned long      /* plane_mask */,
+    int                        /* format */,
+    XImage*            /* dest_image */,
+    int                        /* dest_x */,
+    int                        /* dest_y */
+#endif
+);
+
+/* 
+ * X function declarations.
+ */
+extern Display *XOpenDisplay(
+#if NeedFunctionPrototypes
+    _Xconst char*      /* display_name */
+#endif
+);
+
+extern void XrmInitialize(
+#if NeedFunctionPrototypes
+    void
+#endif
+);
+
+extern char *XFetchBytes(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    int*               /* nbytes_return */
+#endif
+);
+extern char *XFetchBuffer(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    int*               /* nbytes_return */,
+    int                        /* buffer */
+#endif
+);
+extern char *XGetAtomName(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    Atom               /* atom */
+#endif
+);
+extern Status XGetAtomNames(
+#if NeedFunctionPrototypes
+    Display*           /* dpy */,
+    Atom*              /* atoms */,
+    int                        /* count */,
+    char**             /* names_return */
+#endif
+);
+extern char *XGetDefault(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    _Xconst char*      /* program */,
+    _Xconst char*      /* option */              
+#endif
+);
+extern char *XDisplayName(
+#if NeedFunctionPrototypes
+    _Xconst char*      /* string */
+#endif
+);
+extern char *XKeysymToString(
+#if NeedFunctionPrototypes
+    KeySym             /* keysym */
+#endif
+);
+
+extern int (*XSynchronize(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    Bool               /* onoff */
+#endif
+))(
+#if NeedNestedPrototypes
+    Display*           /* display */
+#endif
+);
+extern int (*XSetAfterFunction(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    int (*) (
+#if NeedNestedPrototypes
+            Display*   /* display */
+#endif
+            )          /* procedure */
+#endif
+))(
+#if NeedNestedPrototypes
+    Display*           /* display */
+#endif
+);
+extern Atom XInternAtom(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    _Xconst char*      /* atom_name */,
+    Bool               /* only_if_exists */             
+#endif
+);
+extern Status XInternAtoms(
+#if NeedFunctionPrototypes
+    Display*           /* dpy */,
+    char**             /* names */,
+    int                        /* count */,
+    Bool               /* onlyIfExists */,
+    Atom*              /* atoms_return */
+#endif
+);
+extern Colormap XCopyColormapAndFree(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    Colormap           /* colormap */
+#endif
+);
+extern Colormap XCreateColormap(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    Window             /* w */,
+    Visual*            /* visual */,
+    int                        /* alloc */                      
+#endif
+);
+extern Cursor XCreatePixmapCursor(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    Pixmap             /* source */,
+    Pixmap             /* mask */,
+    XColor*            /* foreground_color */,
+    XColor*            /* background_color */,
+    unsigned int       /* x */,
+    unsigned int       /* y */                    
+#endif
+);
+extern Cursor XCreateGlyphCursor(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    Font               /* source_font */,
+    Font               /* mask_font */,
+    unsigned int       /* source_char */,
+    unsigned int       /* mask_char */,
+    XColor*            /* foreground_color */,
+    XColor*            /* background_color */
+#endif
+);
+extern Cursor XCreateFontCursor(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    unsigned int       /* shape */
+#endif
+);
+extern Font XLoadFont(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    _Xconst char*      /* name */
+#endif
+);
+extern GC XCreateGC(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    Drawable           /* d */,
+    unsigned long      /* valuemask */,
+    XGCValues*         /* values */
+#endif
+);
+extern GContext XGContextFromGC(
+#if NeedFunctionPrototypes
+    GC                 /* gc */
+#endif
+);
+extern void XFlushGC(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    GC                 /* gc */
+#endif
+);
+extern Pixmap XCreatePixmap(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    Drawable           /* d */,
+    unsigned int       /* width */,
+    unsigned int       /* height */,
+    unsigned int       /* depth */                     
+#endif
+);
+extern Pixmap XCreateBitmapFromData(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    Drawable           /* d */,
+    _Xconst char*      /* data */,
+    unsigned int       /* width */,
+    unsigned int       /* height */
+#endif
+);
+extern Pixmap XCreatePixmapFromBitmapData(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    Drawable           /* d */,
+    char*              /* data */,
+    unsigned int       /* width */,
+    unsigned int       /* height */,
+    unsigned long      /* fg */,
+    unsigned long      /* bg */,
+    unsigned int       /* depth */
+#endif
+);
+extern Window XCreateSimpleWindow(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    Window             /* parent */,
+    int                        /* x */,
+    int                        /* y */,
+    unsigned int       /* width */,
+    unsigned int       /* height */,
+    unsigned int       /* border_width */,
+    unsigned long      /* border */,
+    unsigned long      /* background */
+#endif
+);
+extern Window XGetSelectionOwner(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    Atom               /* selection */
+#endif
+);
+extern Window XCreateWindow(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    Window             /* parent */,
+    int                        /* x */,
+    int                        /* y */,
+    unsigned int       /* width */,
+    unsigned int       /* height */,
+    unsigned int       /* border_width */,
+    int                        /* depth */,
+    unsigned int       /* class */,
+    Visual*            /* visual */,
+    unsigned long      /* valuemask */,
+    XSetWindowAttributes*      /* attributes */
+#endif
+); 
+extern Colormap *XListInstalledColormaps(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    Window             /* w */,
+    int*               /* num_return */
+#endif
+);
+extern char **XListFonts(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    _Xconst char*      /* pattern */,
+    int                        /* maxnames */,
+    int*               /* actual_count_return */
+#endif
+);
+extern char **XListFontsWithInfo(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    _Xconst char*      /* pattern */,
+    int                        /* maxnames */,
+    int*               /* count_return */,
+    XFontStruct**      /* info_return */
+#endif
+);
+extern char **XGetFontPath(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    int*               /* npaths_return */
+#endif
+);
+extern char **XListExtensions(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    int*               /* nextensions_return */
+#endif
+);
+extern Atom *XListProperties(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    Window             /* w */,
+    int*               /* num_prop_return */
+#endif
+);
+extern XHostAddress *XListHosts(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    int*               /* nhosts_return */,
+    Bool*              /* state_return */
+#endif
+);
+extern KeySym XKeycodeToKeysym(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+#if NeedWidePrototypes
+    unsigned int       /* keycode */,
+#else
+    KeyCode            /* keycode */,
+#endif
+    int                        /* index */
+#endif
+);
+extern KeySym XLookupKeysym(
+#if NeedFunctionPrototypes
+    XKeyEvent*         /* key_event */,
+    int                        /* index */
+#endif
+);
+extern KeySym *XGetKeyboardMapping(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+#if NeedWidePrototypes
+    unsigned int       /* first_keycode */,
+#else
+    KeyCode            /* first_keycode */,
+#endif
+    int                        /* keycode_count */,
+    int*               /* keysyms_per_keycode_return */
+#endif
+);
+extern KeySym XStringToKeysym(
+#if NeedFunctionPrototypes
+    _Xconst char*      /* string */
+#endif
+);
+extern long XMaxRequestSize(
+#if NeedFunctionPrototypes
+    Display*           /* display */
+#endif
+);
+extern long XExtendedMaxRequestSize(
+#if NeedFunctionPrototypes
+    Display*           /* display */
+#endif
+);
+extern char *XResourceManagerString(
+#if NeedFunctionPrototypes
+    Display*           /* display */
+#endif
+);
+extern char *XScreenResourceString(
+#if NeedFunctionPrototypes
+       Screen*         /* screen */
+#endif
+);
+extern unsigned long XDisplayMotionBufferSize(
+#if NeedFunctionPrototypes
+    Display*           /* display */
+#endif
+);
+extern VisualID XVisualIDFromVisual(
+#if NeedFunctionPrototypes
+    Visual*            /* visual */
+#endif
+);
+
+/* multithread routines */
+
+extern Status XInitThreads(
+#if NeedFunctionPrototypes
+    void
+#endif
+);
+
+extern void XLockDisplay(
+#if NeedFunctionPrototypes
+    Display*           /* display */
+#endif
+);
+
+extern void XUnlockDisplay(
+#if NeedFunctionPrototypes
+    Display*           /* display */
+#endif
+);
+
+/* routines for dealing with extensions */
+
+extern XExtCodes *XInitExtension(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    _Xconst char*      /* name */
+#endif
+);
+
+extern XExtCodes *XAddExtension(
+#if NeedFunctionPrototypes
+    Display*           /* display */
+#endif
+);
+extern XExtData *XFindOnExtensionList(
+#if NeedFunctionPrototypes
+    XExtData**         /* structure */,
+    int                        /* number */
+#endif
+);
+extern XExtData **XEHeadOfExtensionList(
+#if NeedFunctionPrototypes
+    XEDataObject       /* object */
+#endif
+);
+
+/* these are routines for which there are also macros */
+extern Window XRootWindow(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    int                        /* screen_number */
+#endif
+);
+extern Window XDefaultRootWindow(
+#if NeedFunctionPrototypes
+    Display*           /* display */
+#endif
+);
+extern Window XRootWindowOfScreen(
+#if NeedFunctionPrototypes
+    Screen*            /* screen */
+#endif
+);
+extern Visual *XDefaultVisual(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    int                        /* screen_number */
+#endif
+);
+extern Visual *XDefaultVisualOfScreen(
+#if NeedFunctionPrototypes
+    Screen*            /* screen */
+#endif
+);
+extern GC XDefaultGC(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    int                        /* screen_number */
+#endif
+);
+extern GC XDefaultGCOfScreen(
+#if NeedFunctionPrototypes
+    Screen*            /* screen */
+#endif
+);
+extern unsigned long XBlackPixel(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    int                        /* screen_number */
+#endif
+);
+extern unsigned long XWhitePixel(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    int                        /* screen_number */
+#endif
+);
+extern unsigned long XAllPlanes(
+#if NeedFunctionPrototypes
+    void
+#endif
+);
+extern unsigned long XBlackPixelOfScreen(
+#if NeedFunctionPrototypes
+    Screen*            /* screen */
+#endif
+);
+extern unsigned long XWhitePixelOfScreen(
+#if NeedFunctionPrototypes
+    Screen*            /* screen */
+#endif
+);
+extern unsigned long XNextRequest(
+#if NeedFunctionPrototypes
+    Display*           /* display */
+#endif
+);
+extern unsigned long XLastKnownRequestProcessed(
+#if NeedFunctionPrototypes
+    Display*           /* display */
+#endif
+);
+extern char *XServerVendor(
+#if NeedFunctionPrototypes
+    Display*           /* display */
+#endif
+);
+extern char *XDisplayString(
+#if NeedFunctionPrototypes
+    Display*           /* display */
+#endif
+);
+extern Colormap XDefaultColormap(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    int                        /* screen_number */
+#endif
+);
+extern Colormap XDefaultColormapOfScreen(
+#if NeedFunctionPrototypes
+    Screen*            /* screen */
+#endif
+);
+extern Display *XDisplayOfScreen(
+#if NeedFunctionPrototypes
+    Screen*            /* screen */
+#endif
+);
+extern Screen *XScreenOfDisplay(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    int                        /* screen_number */
+#endif
+);
+extern Screen *XDefaultScreenOfDisplay(
+#if NeedFunctionPrototypes
+    Display*           /* display */
+#endif
+);
+extern long XEventMaskOfScreen(
+#if NeedFunctionPrototypes
+    Screen*            /* screen */
+#endif
+);
+
+extern int XScreenNumberOfScreen(
+#if NeedFunctionPrototypes
+    Screen*            /* screen */
+#endif
+);
+
+typedef int (*XErrorHandler) (     /* WARNING, this type not in Xlib spec */
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    XErrorEvent*       /* error_event */
+#endif
+);
+
+extern XErrorHandler XSetErrorHandler (
+#if NeedFunctionPrototypes
+    XErrorHandler      /* handler */
+#endif
+);
+
+
+typedef int (*XIOErrorHandler) (    /* WARNING, this type not in Xlib spec */
+#if NeedFunctionPrototypes
+    Display*           /* display */
+#endif
+);
+
+extern XIOErrorHandler XSetIOErrorHandler (
+#if NeedFunctionPrototypes
+    XIOErrorHandler    /* handler */
+#endif
+);
+
+
+extern XPixmapFormatValues *XListPixmapFormats(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    int*               /* count_return */
+#endif
+);
+extern int *XListDepths(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    int                        /* screen_number */,
+    int*               /* count_return */
+#endif
+);
+
+/* ICCCM routines for things that don't require special include files; */
+/* other declarations are given in Xutil.h                             */
+extern Status XReconfigureWMWindow(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    Window             /* w */,
+    int                        /* screen_number */,
+    unsigned int       /* mask */,
+    XWindowChanges*    /* changes */
+#endif
+);
+
+extern Status XGetWMProtocols(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    Window             /* w */,
+    Atom**             /* protocols_return */,
+    int*               /* count_return */
+#endif
+);
+extern Status XSetWMProtocols(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    Window             /* w */,
+    Atom*              /* protocols */,
+    int                        /* count */
+#endif
+);
+extern Status XIconifyWindow(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    Window             /* w */,
+    int                        /* screen_number */
+#endif
+);
+extern Status XWithdrawWindow(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    Window             /* w */,
+    int                        /* screen_number */
+#endif
+);
+extern Status XGetCommand(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    Window             /* w */,
+    char***            /* argv_return */,
+    int*               /* argc_return */
+#endif
+);
+extern Status XGetWMColormapWindows(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    Window             /* w */,
+    Window**           /* windows_return */,
+    int*               /* count_return */
+#endif
+);
+extern Status XSetWMColormapWindows(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    Window             /* w */,
+    Window*            /* colormap_windows */,
+    int                        /* count */
+#endif
+);
+extern void XFreeStringList(
+#if NeedFunctionPrototypes
+    char**             /* list */
+#endif
+);
+extern int XSetTransientForHint(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    Window             /* w */,
+    Window             /* prop_window */
+#endif
+);
+
+/* The following are given in alphabetical order */
+
+extern int XActivateScreenSaver(
+#if NeedFunctionPrototypes
+    Display*           /* display */
+#endif
+);
+
+extern int XAddHost(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    XHostAddress*      /* host */
+#endif
+);
+
+extern int XAddHosts(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    XHostAddress*      /* hosts */,
+    int                        /* num_hosts */    
+#endif
+);
+
+extern int XAddToExtensionList(
+#if NeedFunctionPrototypes
+    struct _XExtData** /* structure */,
+    XExtData*          /* ext_data */
+#endif
+);
+
+extern int XAddToSaveSet(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    Window             /* w */
+#endif
+);
+
+extern Status XAllocColor(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    Colormap           /* colormap */,
+    XColor*            /* screen_in_out */
+#endif
+);
+
+extern Status XAllocColorCells(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    Colormap           /* colormap */,
+    Bool               /* contig */,
+    unsigned long*     /* plane_masks_return */,
+    unsigned int       /* nplanes */,
+    unsigned long*     /* pixels_return */,
+    unsigned int       /* npixels */
+#endif
+);
+
+extern Status XAllocColorPlanes(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    Colormap           /* colormap */,
+    Bool               /* contig */,
+    unsigned long*     /* pixels_return */,
+    int                        /* ncolors */,
+    int                        /* nreds */,
+    int                        /* ngreens */,
+    int                        /* nblues */,
+    unsigned long*     /* rmask_return */,
+    unsigned long*     /* gmask_return */,
+    unsigned long*     /* bmask_return */
+#endif
+);
+
+extern Status XAllocNamedColor(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    Colormap           /* colormap */,
+    _Xconst char*      /* color_name */,
+    XColor*            /* screen_def_return */,
+    XColor*            /* exact_def_return */
+#endif
+);
+
+extern int XAllowEvents(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    int                        /* event_mode */,
+    Time               /* time */
+#endif
+);
+
+extern int XAutoRepeatOff(
+#if NeedFunctionPrototypes
+    Display*           /* display */
+#endif
+);
+
+extern int XAutoRepeatOn(
+#if NeedFunctionPrototypes
+    Display*           /* display */
+#endif
+);
+
+extern int XBell(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    int                        /* percent */
+#endif
+);
+
+extern int XBitmapBitOrder(
+#if NeedFunctionPrototypes
+    Display*           /* display */
+#endif
+);
+
+extern int XBitmapPad(
+#if NeedFunctionPrototypes
+    Display*           /* display */
+#endif
+);
+
+extern int XBitmapUnit(
+#if NeedFunctionPrototypes
+    Display*           /* display */
+#endif
+);
+
+extern int XCellsOfScreen(
+#if NeedFunctionPrototypes
+    Screen*            /* screen */
+#endif
+);
+
+extern int XChangeActivePointerGrab(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    unsigned int       /* event_mask */,
+    Cursor             /* cursor */,
+    Time               /* time */
+#endif
+);
+
+extern int XChangeGC(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    GC                 /* gc */,
+    unsigned long      /* valuemask */,
+    XGCValues*         /* values */
+#endif
+);
+
+extern int XChangeKeyboardControl(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    unsigned long      /* value_mask */,
+    XKeyboardControl*  /* values */
+#endif
+);
+
+extern int XChangeKeyboardMapping(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    int                        /* first_keycode */,
+    int                        /* keysyms_per_keycode */,
+    KeySym*            /* keysyms */,
+    int                        /* num_codes */
+#endif
+);
+
+extern int XChangePointerControl(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    Bool               /* do_accel */,
+    Bool               /* do_threshold */,
+    int                        /* accel_numerator */,
+    int                        /* accel_denominator */,
+    int                        /* threshold */
+#endif
+);
+
+extern int XChangeProperty(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    Window             /* w */,
+    Atom               /* property */,
+    Atom               /* type */,
+    int                        /* format */,
+    int                        /* mode */,
+    _Xconst unsigned char*     /* data */,
+    int                        /* nelements */
+#endif
+);
+
+extern int XChangeSaveSet(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    Window             /* w */,
+    int                        /* change_mode */
+#endif
+);
+
+extern int XChangeWindowAttributes(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    Window             /* w */,
+    unsigned long      /* valuemask */,
+    XSetWindowAttributes* /* attributes */
+#endif
+);
+
+extern Bool XCheckIfEvent(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    XEvent*            /* event_return */,
+    Bool (*) (
+#if NeedNestedPrototypes
+              Display*                 /* display */,
+               XEvent*                 /* event */,
+               XPointer                        /* arg */
+#endif
+             )         /* predicate */,
+    XPointer           /* arg */
+#endif
+);
+
+extern Bool XCheckMaskEvent(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    long               /* event_mask */,
+    XEvent*            /* event_return */
+#endif
+);
+
+extern Bool XCheckTypedEvent(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    int                        /* event_type */,
+    XEvent*            /* event_return */
+#endif
+);
+
+extern Bool XCheckTypedWindowEvent(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    Window             /* w */,
+    int                        /* event_type */,
+    XEvent*            /* event_return */
+#endif
+);
+
+extern Bool XCheckWindowEvent(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    Window             /* w */,
+    long               /* event_mask */,
+    XEvent*            /* event_return */
+#endif
+);
+
+extern int XCirculateSubwindows(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    Window             /* w */,
+    int                        /* direction */
+#endif
+);
+
+extern int XCirculateSubwindowsDown(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    Window             /* w */
+#endif
+);
+
+extern int XCirculateSubwindowsUp(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    Window             /* w */
+#endif
+);
+
+extern int XClearArea(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    Window             /* w */,
+    int                        /* x */,
+    int                        /* y */,
+    unsigned int       /* width */,
+    unsigned int       /* height */,
+    Bool               /* exposures */
+#endif
+);
+
+extern int XClearWindow(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    Window             /* w */
+#endif
+);
+
+extern int XCloseDisplay(
+#if NeedFunctionPrototypes
+    Display*           /* display */
+#endif
+);
+
+extern int XConfigureWindow(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    Window             /* w */,
+    unsigned int       /* value_mask */,
+    XWindowChanges*    /* values */             
+#endif
+);
+
+extern int XConnectionNumber(
+#if NeedFunctionPrototypes
+    Display*           /* display */
+#endif
+);
+
+extern int XConvertSelection(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    Atom               /* selection */,
+    Atom               /* target */,
+    Atom               /* property */,
+    Window             /* requestor */,
+    Time               /* time */
+#endif
+);
+
+extern int XCopyArea(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    Drawable           /* src */,
+    Drawable           /* dest */,
+    GC                 /* gc */,
+    int                        /* src_x */,
+    int                        /* src_y */,
+    unsigned int       /* width */,
+    unsigned int       /* height */,
+    int                        /* dest_x */,
+    int                        /* dest_y */
+#endif
+);
+
+extern int XCopyGC(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    GC                 /* src */,
+    unsigned long      /* valuemask */,
+    GC                 /* dest */
+#endif
+);
+
+extern int XCopyPlane(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    Drawable           /* src */,
+    Drawable           /* dest */,
+    GC                 /* gc */,
+    int                        /* src_x */,
+    int                        /* src_y */,
+    unsigned int       /* width */,
+    unsigned int       /* height */,
+    int                        /* dest_x */,
+    int                        /* dest_y */,
+    unsigned long      /* plane */
+#endif
+);
+
+extern int XDefaultDepth(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    int                        /* screen_number */
+#endif
+);
+
+extern int XDefaultDepthOfScreen(
+#if NeedFunctionPrototypes
+    Screen*            /* screen */
+#endif
+);
+
+extern int XDefaultScreen(
+#if NeedFunctionPrototypes
+    Display*           /* display */
+#endif
+);
+
+extern int XDefineCursor(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    Window             /* w */,
+    Cursor             /* cursor */
+#endif
+);
+
+extern int XDeleteProperty(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    Window             /* w */,
+    Atom               /* property */
+#endif
+);
+
+extern int XDestroyWindow(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    Window             /* w */
+#endif
+);
+
+extern int XDestroySubwindows(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    Window             /* w */
+#endif
+);
+
+extern int XDoesBackingStore(
+#if NeedFunctionPrototypes
+    Screen*            /* screen */    
+#endif
+);
+
+extern Bool XDoesSaveUnders(
+#if NeedFunctionPrototypes
+    Screen*            /* screen */
+#endif
+);
+
+extern int XDisableAccessControl(
+#if NeedFunctionPrototypes
+    Display*           /* display */
+#endif
+);
+
+
+extern int XDisplayCells(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    int                        /* screen_number */
+#endif
+);
+
+extern int XDisplayHeight(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    int                        /* screen_number */
+#endif
+);
+
+extern int XDisplayHeightMM(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    int                        /* screen_number */
+#endif
+);
+
+extern int XDisplayKeycodes(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    int*               /* min_keycodes_return */,
+    int*               /* max_keycodes_return */
+#endif
+);
+
+extern int XDisplayPlanes(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    int                        /* screen_number */
+#endif
+);
+
+extern int XDisplayWidth(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    int                        /* screen_number */
+#endif
+);
+
+extern int XDisplayWidthMM(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    int                        /* screen_number */
+#endif
+);
+
+extern int XDrawArc(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    Drawable           /* d */,
+    GC                 /* gc */,
+    int                        /* x */,
+    int                        /* y */,
+    unsigned int       /* width */,
+    unsigned int       /* height */,
+    int                        /* angle1 */,
+    int                        /* angle2 */
+#endif
+);
+
+extern int XDrawArcs(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    Drawable           /* d */,
+    GC                 /* gc */,
+    XArc*              /* arcs */,
+    int                        /* narcs */
+#endif
+);
+
+extern int XDrawImageString(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    Drawable           /* d */,
+    GC                 /* gc */,
+    int                        /* x */,
+    int                        /* y */,
+    _Xconst char*      /* string */,
+    int                        /* length */
+#endif
+);
+
+extern int XDrawImageString16(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    Drawable           /* d */,
+    GC                 /* gc */,
+    int                        /* x */,
+    int                        /* y */,
+    _Xconst XChar2b*   /* string */,
+    int                        /* length */
+#endif
+);
+
+extern int XDrawLine(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    Drawable           /* d */,
+    GC                 /* gc */,
+    int                        /* x1 */,
+    int                        /* x2 */,
+    int                        /* y1 */,
+    int                        /* y2 */
+#endif
+);
+
+extern int XDrawLines(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    Drawable           /* d */,
+    GC                 /* gc */,
+    XPoint*            /* points */,
+    int                        /* npoints */,
+    int                        /* mode */
+#endif
+);
+
+extern int XDrawPoint(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    Drawable           /* d */,
+    GC                 /* gc */,
+    int                        /* x */,
+    int                        /* y */
+#endif
+);
+
+extern int XDrawPoints(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    Drawable           /* d */,
+    GC                 /* gc */,
+    XPoint*            /* points */,
+    int                        /* npoints */,
+    int                        /* mode */
+#endif
+);
+
+extern int XDrawRectangle(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    Drawable           /* d */,
+    GC                 /* gc */,
+    int                        /* x */,
+    int                        /* y */,
+    unsigned int       /* width */,
+    unsigned int       /* height */
+#endif
+);
+
+extern int XDrawRectangles(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    Drawable           /* d */,
+    GC                 /* gc */,
+    XRectangle*                /* rectangles */,
+    int                        /* nrectangles */
+#endif
+);
+
+extern int XDrawSegments(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    Drawable           /* d */,
+    GC                 /* gc */,
+    XSegment*          /* segments */,
+    int                        /* nsegments */
+#endif
+);
+
+extern int XDrawString(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    Drawable           /* d */,
+    GC                 /* gc */,
+    int                        /* x */,
+    int                        /* y */,
+    _Xconst char*      /* string */,
+    int                        /* length */
+#endif
+);
+
+extern int XDrawString16(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    Drawable           /* d */,
+    GC                 /* gc */,
+    int                        /* x */,
+    int                        /* y */,
+    _Xconst XChar2b*   /* string */,
+    int                        /* length */
+#endif
+);
+
+extern int XDrawText(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    Drawable           /* d */,
+    GC                 /* gc */,
+    int                        /* x */,
+    int                        /* y */,
+    XTextItem*         /* items */,
+    int                        /* nitems */
+#endif
+);
+
+extern int XDrawText16(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    Drawable           /* d */,
+    GC                 /* gc */,
+    int                        /* x */,
+    int                        /* y */,
+    XTextItem16*       /* items */,
+    int                        /* nitems */
+#endif
+);
+
+extern int XEnableAccessControl(
+#if NeedFunctionPrototypes
+    Display*           /* display */
+#endif
+);
+
+extern int XEventsQueued(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    int                        /* mode */
+#endif
+);
+
+extern Status XFetchName(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    Window             /* w */,
+    char**             /* window_name_return */
+#endif
+);
+
+extern int XFillArc(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    Drawable           /* d */,
+    GC                 /* gc */,
+    int                        /* x */,
+    int                        /* y */,
+    unsigned int       /* width */,
+    unsigned int       /* height */,
+    int                        /* angle1 */,
+    int                        /* angle2 */
+#endif
+);
+
+extern int XFillArcs(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    Drawable           /* d */,
+    GC                 /* gc */,
+    XArc*              /* arcs */,
+    int                        /* narcs */
+#endif
+);
+
+extern int XFillPolygon(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    Drawable           /* d */,
+    GC                 /* gc */,
+    XPoint*            /* points */,
+    int                        /* npoints */,
+    int                        /* shape */,
+    int                        /* mode */
+#endif
+);
+
+extern int XFillRectangle(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    Drawable           /* d */,
+    GC                 /* gc */,
+    int                        /* x */,
+    int                        /* y */,
+    unsigned int       /* width */,
+    unsigned int       /* height */
+#endif
+);
+
+extern int XFillRectangles(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    Drawable           /* d */,
+    GC                 /* gc */,
+    XRectangle*                /* rectangles */,
+    int                        /* nrectangles */
+#endif
+);
+
+extern int XFlush(
+#if NeedFunctionPrototypes
+    Display*           /* display */
+#endif
+);
+
+extern int XForceScreenSaver(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    int                        /* mode */
+#endif
+);
+
+extern int XFree(
+#if NeedFunctionPrototypes
+    void*              /* data */
+#endif
+);
+
+extern int XFreeColormap(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    Colormap           /* colormap */
+#endif
+);
+
+extern int XFreeColors(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    Colormap           /* colormap */,
+    unsigned long*     /* pixels */,
+    int                        /* npixels */,
+    unsigned long      /* planes */
+#endif
+);
+
+extern int XFreeCursor(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    Cursor             /* cursor */
+#endif
+);
+
+extern int XFreeExtensionList(
+#if NeedFunctionPrototypes
+    char**             /* list */    
+#endif
+);
+
+extern int XFreeFont(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    XFontStruct*       /* font_struct */
+#endif
+);
+
+extern int XFreeFontInfo(
+#if NeedFunctionPrototypes
+    char**             /* names */,
+    XFontStruct*       /* free_info */,
+    int                        /* actual_count */
+#endif
+);
+
+extern int XFreeFontNames(
+#if NeedFunctionPrototypes
+    char**             /* list */
+#endif
+);
+
+extern int XFreeFontPath(
+#if NeedFunctionPrototypes
+    char**             /* list */
+#endif
+);
+
+extern int XFreeGC(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    GC                 /* gc */
+#endif
+);
+
+extern int XFreeModifiermap(
+#if NeedFunctionPrototypes
+    XModifierKeymap*   /* modmap */
+#endif
+);
+
+extern int XFreePixmap(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    Pixmap             /* pixmap */
+#endif
+);
+
+extern int XGeometry(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    int                        /* screen */,
+    _Xconst char*      /* position */,
+    _Xconst char*      /* default_position */,
+    unsigned int       /* bwidth */,
+    unsigned int       /* fwidth */,
+    unsigned int       /* fheight */,
+    int                        /* xadder */,
+    int                        /* yadder */,
+    int*               /* x_return */,
+    int*               /* y_return */,
+    int*               /* width_return */,
+    int*               /* height_return */
+#endif
+);
+
+extern int XGetErrorDatabaseText(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    _Xconst char*      /* name */,
+    _Xconst char*      /* message */,
+    _Xconst char*      /* default_string */,
+    char*              /* buffer_return */,
+    int                        /* length */
+#endif
+);
+
+extern int XGetErrorText(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    int                        /* code */,
+    char*              /* buffer_return */,
+    int                        /* length */
+#endif
+);
+
+extern Bool XGetFontProperty(
+#if NeedFunctionPrototypes
+    XFontStruct*       /* font_struct */,
+    Atom               /* atom */,
+    unsigned long*     /* value_return */
+#endif
+);
+
+extern Status XGetGCValues(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    GC                 /* gc */,
+    unsigned long      /* valuemask */,
+    XGCValues*         /* values_return */
+#endif
+);
+
+extern Status XGetGeometry(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    Drawable           /* d */,
+    Window*            /* root_return */,
+    int*               /* x_return */,
+    int*               /* y_return */,
+    unsigned int*      /* width_return */,
+    unsigned int*      /* height_return */,
+    unsigned int*      /* border_width_return */,
+    unsigned int*      /* depth_return */
+#endif
+);
+
+extern Status XGetIconName(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    Window             /* w */,
+    char**             /* icon_name_return */
+#endif
+);
+
+extern int XGetInputFocus(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    Window*            /* focus_return */,
+    int*               /* revert_to_return */
+#endif
+);
+
+extern int XGetKeyboardControl(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    XKeyboardState*    /* values_return */
+#endif
+);
+
+extern int XGetPointerControl(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    int*               /* accel_numerator_return */,
+    int*               /* accel_denominator_return */,
+    int*               /* threshold_return */
+#endif
+);
+
+extern int XGetPointerMapping(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    unsigned char*     /* map_return */,
+    int                        /* nmap */
+#endif
+);
+
+extern int XGetScreenSaver(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    int*               /* timeout_return */,
+    int*               /* interval_return */,
+    int*               /* prefer_blanking_return */,
+    int*               /* allow_exposures_return */
+#endif
+);
+
+extern Status XGetTransientForHint(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    Window             /* w */,
+    Window*            /* prop_window_return */
+#endif
+);
+
+extern int XGetWindowProperty(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    Window             /* w */,
+    Atom               /* property */,
+    long               /* long_offset */,
+    long               /* long_length */,
+    Bool               /* delete */,
+    Atom               /* req_type */,
+    Atom*              /* actual_type_return */,
+    int*               /* actual_format_return */,
+    unsigned long*     /* nitems_return */,
+    unsigned long*     /* bytes_after_return */,
+    unsigned char**    /* prop_return */
+#endif
+);
+
+extern Status XGetWindowAttributes(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    Window             /* w */,
+    XWindowAttributes* /* window_attributes_return */
+#endif
+);
+
+extern int XGrabButton(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    unsigned int       /* button */,
+    unsigned int       /* modifiers */,
+    Window             /* grab_window */,
+    Bool               /* owner_events */,
+    unsigned int       /* event_mask */,
+    int                        /* pointer_mode */,
+    int                        /* keyboard_mode */,
+    Window             /* confine_to */,
+    Cursor             /* cursor */
+#endif
+);
+
+extern int XGrabKey(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    int                        /* keycode */,
+    unsigned int       /* modifiers */,
+    Window             /* grab_window */,
+    Bool               /* owner_events */,
+    int                        /* pointer_mode */,
+    int                        /* keyboard_mode */
+#endif
+);
+
+extern int XGrabKeyboard(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    Window             /* grab_window */,
+    Bool               /* owner_events */,
+    int                        /* pointer_mode */,
+    int                        /* keyboard_mode */,
+    Time               /* time */
+#endif
+);
+
+extern int XGrabPointer(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    Window             /* grab_window */,
+    Bool               /* owner_events */,
+    unsigned int       /* event_mask */,
+    int                        /* pointer_mode */,
+    int                        /* keyboard_mode */,
+    Window             /* confine_to */,
+    Cursor             /* cursor */,
+    Time               /* time */
+#endif
+);
+
+extern int XGrabServer(
+#if NeedFunctionPrototypes
+    Display*           /* display */
+#endif
+);
+
+extern int XHeightMMOfScreen(
+#if NeedFunctionPrototypes
+    Screen*            /* screen */
+#endif
+);
+
+extern int XHeightOfScreen(
+#if NeedFunctionPrototypes
+    Screen*            /* screen */
+#endif
+);
+
+extern int XIfEvent(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    XEvent*            /* event_return */,
+    Bool (*) (
+#if NeedNestedPrototypes
+              Display*                 /* display */,
+               XEvent*                 /* event */,
+               XPointer                        /* arg */
+#endif
+             )         /* predicate */,
+    XPointer           /* arg */
+#endif
+);
+
+extern int XImageByteOrder(
+#if NeedFunctionPrototypes
+    Display*           /* display */
+#endif
+);
+
+extern int XInstallColormap(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    Colormap           /* colormap */
+#endif
+);
+
+extern KeyCode XKeysymToKeycode(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    KeySym             /* keysym */
+#endif
+);
+
+extern int XKillClient(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    XID                        /* resource */
+#endif
+);
+
+extern Status XLookupColor(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    Colormap           /* colormap */,
+    _Xconst char*      /* color_name */,
+    XColor*            /* exact_def_return */,
+    XColor*            /* screen_def_return */
+#endif
+);
+
+extern int XLowerWindow(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    Window             /* w */
+#endif
+);
+
+extern int XMapRaised(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    Window             /* w */
+#endif
+);
+
+extern int XMapSubwindows(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    Window             /* w */
+#endif
+);
+
+extern int XMapWindow(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    Window             /* w */
+#endif
+);
+
+extern int XMaskEvent(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    long               /* event_mask */,
+    XEvent*            /* event_return */
+#endif
+);
+
+extern int XMaxCmapsOfScreen(
+#if NeedFunctionPrototypes
+    Screen*            /* screen */
+#endif
+);
+
+extern int XMinCmapsOfScreen(
+#if NeedFunctionPrototypes
+    Screen*            /* screen */
+#endif
+);
+
+extern int XMoveResizeWindow(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    Window             /* w */,
+    int                        /* x */,
+    int                        /* y */,
+    unsigned int       /* width */,
+    unsigned int       /* height */
+#endif
+);
+
+extern int XMoveWindow(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    Window             /* w */,
+    int                        /* x */,
+    int                        /* y */
+#endif
+);
+
+extern int XNextEvent(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    XEvent*            /* event_return */
+#endif
+);
+
+extern int XNoOp(
+#if NeedFunctionPrototypes
+    Display*           /* display */
+#endif
+);
+
+extern Status XParseColor(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    Colormap           /* colormap */,
+    _Xconst char*      /* spec */,
+    XColor*            /* exact_def_return */
+#endif
+);
+
+extern int XParseGeometry(
+#if NeedFunctionPrototypes
+    _Xconst char*      /* parsestring */,
+    int*               /* x_return */,
+    int*               /* y_return */,
+    unsigned int*      /* width_return */,
+    unsigned int*      /* height_return */
+#endif
+);
+
+extern int XPeekEvent(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    XEvent*            /* event_return */
+#endif
+);
+
+extern int XPeekIfEvent(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    XEvent*            /* event_return */,
+    Bool (*) (
+#if NeedNestedPrototypes
+              Display*         /* display */,
+               XEvent*         /* event */,
+               XPointer                /* arg */
+#endif
+             )         /* predicate */,
+    XPointer           /* arg */
+#endif
+);
+
+extern int XPending(
+#if NeedFunctionPrototypes
+    Display*           /* display */
+#endif
+);
+
+extern int XPlanesOfScreen(
+#if NeedFunctionPrototypes
+    Screen*            /* screen */
+    
+#endif
+);
+
+extern int XProtocolRevision(
+#if NeedFunctionPrototypes
+    Display*           /* display */
+#endif
+);
+
+extern int XProtocolVersion(
+#if NeedFunctionPrototypes
+    Display*           /* display */
+#endif
+);
+
+
+extern int XPutBackEvent(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    XEvent*            /* event */
+#endif
+);
+
+extern int XPutImage(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    Drawable           /* d */,
+    GC                 /* gc */,
+    XImage*            /* image */,
+    int                        /* src_x */,
+    int                        /* src_y */,
+    int                        /* dest_x */,
+    int                        /* dest_y */,
+    unsigned int       /* width */,
+    unsigned int       /* height */      
+#endif
+);
+
+extern int XQLength(
+#if NeedFunctionPrototypes
+    Display*           /* display */
+#endif
+);
+
+extern Status XQueryBestCursor(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    Drawable           /* d */,
+    unsigned int        /* width */,
+    unsigned int       /* height */,
+    unsigned int*      /* width_return */,
+    unsigned int*      /* height_return */
+#endif
+);
+
+extern Status XQueryBestSize(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    int                        /* class */,
+    Drawable           /* which_screen */,
+    unsigned int       /* width */,
+    unsigned int       /* height */,
+    unsigned int*      /* width_return */,
+    unsigned int*      /* height_return */
+#endif
+);
+
+extern Status XQueryBestStipple(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    Drawable           /* which_screen */,
+    unsigned int       /* width */,
+    unsigned int       /* height */,
+    unsigned int*      /* width_return */,
+    unsigned int*      /* height_return */
+#endif
+);
+
+extern Status XQueryBestTile(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    Drawable           /* which_screen */,
+    unsigned int       /* width */,
+    unsigned int       /* height */,
+    unsigned int*      /* width_return */,
+    unsigned int*      /* height_return */
+#endif
+);
+
+extern int XQueryColor(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    Colormap           /* colormap */,
+    XColor*            /* def_in_out */
+#endif
+);
+
+extern int XQueryColors(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    Colormap           /* colormap */,
+    XColor*            /* defs_in_out */,
+    int                        /* ncolors */
+#endif
+);
+
+extern Bool XQueryExtension(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    _Xconst char*      /* name */,
+    int*               /* major_opcode_return */,
+    int*               /* first_event_return */,
+    int*               /* first_error_return */
+#endif
+);
+
+extern int XQueryKeymap(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    char [32]          /* keys_return */
+#endif
+);
+
+extern Bool XQueryPointer(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    Window             /* w */,
+    Window*            /* root_return */,
+    Window*            /* child_return */,
+    int*               /* root_x_return */,
+    int*               /* root_y_return */,
+    int*               /* win_x_return */,
+    int*               /* win_y_return */,
+    unsigned int*       /* mask_return */
+#endif
+);
+
+extern int XQueryTextExtents(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    XID                        /* font_ID */,
+    _Xconst char*      /* string */,
+    int                        /* nchars */,
+    int*               /* direction_return */,
+    int*               /* font_ascent_return */,
+    int*               /* font_descent_return */,
+    XCharStruct*       /* overall_return */    
+#endif
+);
+
+extern int XQueryTextExtents16(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    XID                        /* font_ID */,
+    _Xconst XChar2b*   /* string */,
+    int                        /* nchars */,
+    int*               /* direction_return */,
+    int*               /* font_ascent_return */,
+    int*               /* font_descent_return */,
+    XCharStruct*       /* overall_return */
+#endif
+);
+
+extern Status XQueryTree(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    Window             /* w */,
+    Window*            /* root_return */,
+    Window*            /* parent_return */,
+    Window**           /* children_return */,
+    unsigned int*      /* nchildren_return */
+#endif
+);
+
+extern int XRaiseWindow(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    Window             /* w */
+#endif
+);
+
+extern int XReadBitmapFile(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    Drawable           /* d */,
+    _Xconst char*      /* filename */,
+    unsigned int*      /* width_return */,
+    unsigned int*      /* height_return */,
+    Pixmap*            /* bitmap_return */,
+    int*               /* x_hot_return */,
+    int*               /* y_hot_return */
+#endif
+);
+
+extern int XReadBitmapFileData(
+#if NeedFunctionPrototypes
+    _Xconst char*      /* filename */,
+    unsigned int*      /* width_return */,
+    unsigned int*      /* height_return */,
+    unsigned char**    /* data_return */,
+    int*               /* x_hot_return */,
+    int*               /* y_hot_return */
+#endif
+);
+
+extern int XRebindKeysym(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    KeySym             /* keysym */,
+    KeySym*            /* list */,
+    int                        /* mod_count */,
+    _Xconst unsigned char*     /* string */,
+    int                        /* bytes_string */
+#endif
+);
+
+extern int XRecolorCursor(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    Cursor             /* cursor */,
+    XColor*            /* foreground_color */,
+    XColor*            /* background_color */
+#endif
+);
+
+extern int XRefreshKeyboardMapping(
+#if NeedFunctionPrototypes
+    XMappingEvent*     /* event_map */    
+#endif
+);
+
+extern int XRemoveFromSaveSet(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    Window             /* w */
+#endif
+);
+
+extern int XRemoveHost(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    XHostAddress*      /* host */
+#endif
+);
+
+extern int XRemoveHosts(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    XHostAddress*      /* hosts */,
+    int                        /* num_hosts */
+#endif
+);
+
+extern int XReparentWindow(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    Window             /* w */,
+    Window             /* parent */,
+    int                        /* x */,
+    int                        /* y */
+#endif
+);
+
+extern int XResetScreenSaver(
+#if NeedFunctionPrototypes
+    Display*           /* display */
+#endif
+);
+
+extern int XResizeWindow(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    Window             /* w */,
+    unsigned int       /* width */,
+    unsigned int       /* height */
+#endif
+);
+
+extern int XRestackWindows(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    Window*            /* windows */,
+    int                        /* nwindows */
+#endif
+);
+
+extern int XRotateBuffers(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    int                        /* rotate */
+#endif
+);
+
+extern int XRotateWindowProperties(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    Window             /* w */,
+    Atom*              /* properties */,
+    int                        /* num_prop */,
+    int                        /* npositions */
+#endif
+);
+
+extern int XScreenCount(
+#if NeedFunctionPrototypes
+    Display*           /* display */
+#endif
+);
+
+extern int XSelectInput(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    Window             /* w */,
+    long               /* event_mask */
+#endif
+);
+
+extern Status XSendEvent(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    Window             /* w */,
+    Bool               /* propagate */,
+    long               /* event_mask */,
+    XEvent*            /* event_send */
+#endif
+);
+
+extern int XSetAccessControl(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    int                        /* mode */
+#endif
+);
+
+extern int XSetArcMode(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    GC                 /* gc */,
+    int                        /* arc_mode */
+#endif
+);
+
+extern int XSetBackground(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    GC                 /* gc */,
+    unsigned long      /* background */
+#endif
+);
+
+extern int XSetClipMask(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    GC                 /* gc */,
+    Pixmap             /* pixmap */
+#endif
+);
+
+extern int XSetClipOrigin(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    GC                 /* gc */,
+    int                        /* clip_x_origin */,
+    int                        /* clip_y_origin */
+#endif
+);
+
+extern int XSetClipRectangles(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    GC                 /* gc */,
+    int                        /* clip_x_origin */,
+    int                        /* clip_y_origin */,
+    XRectangle*                /* rectangles */,
+    int                        /* n */,
+    int                        /* ordering */
+#endif
+);
+
+extern int XSetCloseDownMode(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    int                        /* close_mode */
+#endif
+);
+
+extern int XSetCommand(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    Window             /* w */,
+    char**             /* argv */,
+    int                        /* argc */
+#endif
+);
+
+extern int XSetDashes(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    GC                 /* gc */,
+    int                        /* dash_offset */,
+    _Xconst char*      /* dash_list */,
+    int                        /* n */
+#endif
+);
+
+extern int XSetFillRule(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    GC                 /* gc */,
+    int                        /* fill_rule */
+#endif
+);
+
+extern int XSetFillStyle(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    GC                 /* gc */,
+    int                        /* fill_style */
+#endif
+);
+
+extern int XSetFont(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    GC                 /* gc */,
+    Font               /* font */
+#endif
+);
+
+extern int XSetFontPath(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    char**             /* directories */,
+    int                        /* ndirs */          
+#endif
+);
+
+extern int XSetForeground(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    GC                 /* gc */,
+    unsigned long      /* foreground */
+#endif
+);
+
+extern int XSetFunction(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    GC                 /* gc */,
+    int                        /* function */
+#endif
+);
+
+extern int XSetGraphicsExposures(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    GC                 /* gc */,
+    Bool               /* graphics_exposures */
+#endif
+);
+
+extern int XSetIconName(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    Window             /* w */,
+    _Xconst char*      /* icon_name */
+#endif
+);
+
+extern int XSetInputFocus(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    Window             /* focus */,
+    int                        /* revert_to */,
+    Time               /* time */
+#endif
+);
+
+extern int XSetLineAttributes(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    GC                 /* gc */,
+    unsigned int       /* line_width */,
+    int                        /* line_style */,
+    int                        /* cap_style */,
+    int                        /* join_style */
+#endif
+);
+
+extern int XSetModifierMapping(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    XModifierKeymap*   /* modmap */
+#endif
+);
+
+extern int XSetPlaneMask(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    GC                 /* gc */,
+    unsigned long      /* plane_mask */
+#endif
+);
+
+extern int XSetPointerMapping(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    _Xconst unsigned char*     /* map */,
+    int                        /* nmap */
+#endif
+);
+
+extern int XSetScreenSaver(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    int                        /* timeout */,
+    int                        /* interval */,
+    int                        /* prefer_blanking */,
+    int                        /* allow_exposures */
+#endif
+);
+
+extern int XSetSelectionOwner(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    Atom               /* selection */,
+    Window             /* owner */,
+    Time               /* time */
+#endif
+);
+
+extern int XSetState(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    GC                 /* gc */,
+    unsigned long      /* foreground */,
+    unsigned long      /* background */,
+    int                        /* function */,
+    unsigned long      /* plane_mask */
+#endif
+);
+
+extern int XSetStipple(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    GC                 /* gc */,
+    Pixmap             /* stipple */
+#endif
+);
+
+extern int XSetSubwindowMode(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    GC                 /* gc */,
+    int                        /* subwindow_mode */
+#endif
+);
+
+extern int XSetTSOrigin(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    GC                 /* gc */,
+    int                        /* ts_x_origin */,
+    int                        /* ts_y_origin */
+#endif
+);
+
+extern int XSetTile(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    GC                 /* gc */,
+    Pixmap             /* tile */
+#endif
+);
+
+extern int XSetWindowBackground(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    Window             /* w */,
+    unsigned long      /* background_pixel */
+#endif
+);
+
+extern int XSetWindowBackgroundPixmap(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    Window             /* w */,
+    Pixmap             /* background_pixmap */
+#endif
+);
+
+extern int XSetWindowBorder(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    Window             /* w */,
+    unsigned long      /* border_pixel */
+#endif
+);
+
+extern int XSetWindowBorderPixmap(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    Window             /* w */,
+    Pixmap             /* border_pixmap */
+#endif
+);
+
+extern int XSetWindowBorderWidth(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    Window             /* w */,
+    unsigned int       /* width */
+#endif
+);
+
+extern int XSetWindowColormap(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    Window             /* w */,
+    Colormap           /* colormap */
+#endif
+);
+
+extern int XStoreBuffer(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    _Xconst char*      /* bytes */,
+    int                        /* nbytes */,
+    int                        /* buffer */
+#endif
+);
+
+extern int XStoreBytes(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    _Xconst char*      /* bytes */,
+    int                        /* nbytes */
+#endif
+);
+
+extern int XStoreColor(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    Colormap           /* colormap */,
+    XColor*            /* color */
+#endif
+);
+
+extern int XStoreColors(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    Colormap           /* colormap */,
+    XColor*            /* color */,
+    int                        /* ncolors */
+#endif
+);
+
+extern int XStoreName(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    Window             /* w */,
+    _Xconst char*      /* window_name */
+#endif
+);
+
+extern int XStoreNamedColor(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    Colormap           /* colormap */,
+    _Xconst char*      /* color */,
+    unsigned long      /* pixel */,
+    int                        /* flags */
+#endif
+);
+
+extern int XSync(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    Bool               /* discard */
+#endif
+);
+
+extern int XTextExtents(
+#if NeedFunctionPrototypes
+    XFontStruct*       /* font_struct */,
+    _Xconst char*      /* string */,
+    int                        /* nchars */,
+    int*               /* direction_return */,
+    int*               /* font_ascent_return */,
+    int*               /* font_descent_return */,
+    XCharStruct*       /* overall_return */
+#endif
+);
+
+extern int XTextExtents16(
+#if NeedFunctionPrototypes
+    XFontStruct*       /* font_struct */,
+    _Xconst XChar2b*   /* string */,
+    int                        /* nchars */,
+    int*               /* direction_return */,
+    int*               /* font_ascent_return */,
+    int*               /* font_descent_return */,
+    XCharStruct*       /* overall_return */
+#endif
+);
+
+extern int XTextWidth(
+#if NeedFunctionPrototypes
+    XFontStruct*       /* font_struct */,
+    _Xconst char*      /* string */,
+    int                        /* count */
+#endif
+);
+
+extern int XTextWidth16(
+#if NeedFunctionPrototypes
+    XFontStruct*       /* font_struct */,
+    _Xconst XChar2b*   /* string */,
+    int                        /* count */
+#endif
+);
+
+extern Bool XTranslateCoordinates(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    Window             /* src_w */,
+    Window             /* dest_w */,
+    int                        /* src_x */,
+    int                        /* src_y */,
+    int*               /* dest_x_return */,
+    int*               /* dest_y_return */,
+    Window*            /* child_return */
+#endif
+);
+
+extern int XUndefineCursor(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    Window             /* w */
+#endif
+);
+
+extern int XUngrabButton(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    unsigned int       /* button */,
+    unsigned int       /* modifiers */,
+    Window             /* grab_window */
+#endif
+);
+
+extern int XUngrabKey(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    int                        /* keycode */,
+    unsigned int       /* modifiers */,
+    Window             /* grab_window */
+#endif
+);
+
+extern int XUngrabKeyboard(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    Time               /* time */
+#endif
+);
+
+extern int XUngrabPointer(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    Time               /* time */
+#endif
+);
+
+extern int XUngrabServer(
+#if NeedFunctionPrototypes
+    Display*           /* display */
+#endif
+);
+
+extern int XUninstallColormap(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    Colormap           /* colormap */
+#endif
+);
+
+extern int XUnloadFont(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    Font               /* font */
+#endif
+);
+
+extern int XUnmapSubwindows(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    Window             /* w */
+#endif
+);
+
+extern int XUnmapWindow(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    Window             /* w */
+#endif
+);
+
+extern int XVendorRelease(
+#if NeedFunctionPrototypes
+    Display*           /* display */
+#endif
+);
+
+extern int XWarpPointer(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    Window             /* src_w */,
+    Window             /* dest_w */,
+    int                        /* src_x */,
+    int                        /* src_y */,
+    unsigned int       /* src_width */,
+    unsigned int       /* src_height */,
+    int                        /* dest_x */,
+    int                        /* dest_y */         
+#endif
+);
+
+extern int XWidthMMOfScreen(
+#if NeedFunctionPrototypes
+    Screen*            /* screen */
+#endif
+);
+
+extern int XWidthOfScreen(
+#if NeedFunctionPrototypes
+    Screen*            /* screen */
+#endif
+);
+
+extern int XWindowEvent(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    Window             /* w */,
+    long               /* event_mask */,
+    XEvent*            /* event_return */
+#endif
+);
+
+extern int XWriteBitmapFile(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    _Xconst char*      /* filename */,
+    Pixmap             /* bitmap */,
+    unsigned int       /* width */,
+    unsigned int       /* height */,
+    int                        /* x_hot */,
+    int                        /* y_hot */                  
+#endif
+);
+
+extern Bool XSupportsLocale(
+#if NeedFunctionPrototypes
+    void
+#endif
+);
+
+extern char *XSetLocaleModifiers(
+#if NeedFunctionPrototypes
+    _Xconst char*      /* modifier_list */
+#endif
+);
+
+extern XOM XOpenOM(
+#if NeedFunctionPrototypes
+    Display*                   /* display */,
+    struct _XrmHashBucketRec*  /* rdb */,
+    _Xconst char*              /* res_name */,
+    _Xconst char*              /* res_class */
+#endif
+);
+
+extern Status XCloseOM(
+#if NeedFunctionPrototypes
+    XOM                        /* om */
+#endif
+);
+
+extern char *XSetOMValues(
+#if NeedVarargsPrototypes
+    XOM                        /* om */,
+    ...
+#endif
+);
+
+extern char *XGetOMValues(
+#if NeedVarargsPrototypes
+    XOM                        /* om */,
+    ...
+#endif
+);
+
+extern Display *XDisplayOfOM(
+#if NeedFunctionPrototypes
+    XOM                        /* om */
+#endif
+);
+
+extern char *XLocaleOfOM(
+#if NeedFunctionPrototypes
+    XOM                        /* om */
+#endif
+);
+
+extern XOC XCreateOC(
+#if NeedVarargsPrototypes
+    XOM                        /* om */,
+    ...
+#endif
+);
+
+extern void XDestroyOC(
+#if NeedFunctionPrototypes
+    XOC                        /* oc */
+#endif
+);
+
+extern XOM XOMOfOC(
+#if NeedFunctionPrototypes
+    XOC                        /* oc */
+#endif
+);
+
+extern char *XSetOCValues(
+#if NeedVarargsPrototypes
+    XOC                        /* oc */,
+    ...
+#endif
+);
+
+extern char *XGetOCValues(
+#if NeedVarargsPrototypes
+    XOC                        /* oc */,
+    ...
+#endif
+);
+
+extern XFontSet XCreateFontSet(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    _Xconst char*      /* base_font_name_list */,
+    char***            /* missing_charset_list */,
+    int*               /* missing_charset_count */,
+    char**             /* def_string */
+#endif
+);
+
+extern void XFreeFontSet(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    XFontSet           /* font_set */
+#endif
+);
+
+extern int XFontsOfFontSet(
+#if NeedFunctionPrototypes
+    XFontSet           /* font_set */,
+    XFontStruct***     /* font_struct_list */,
+    char***            /* font_name_list */
+#endif
+);
+
+extern char *XBaseFontNameListOfFontSet(
+#if NeedFunctionPrototypes
+    XFontSet           /* font_set */
+#endif
+);
+
+extern char *XLocaleOfFontSet(
+#if NeedFunctionPrototypes
+    XFontSet           /* font_set */
+#endif
+);
+
+extern Bool XContextDependentDrawing(
+#if NeedFunctionPrototypes
+    XFontSet           /* font_set */
+#endif
+);
+
+extern Bool XDirectionalDependentDrawing(
+#if NeedFunctionPrototypes
+    XFontSet           /* font_set */
+#endif
+);
+
+extern Bool XContextualDrawing(
+#if NeedFunctionPrototypes
+    XFontSet           /* font_set */
+#endif
+);
+
+extern XFontSetExtents *XExtentsOfFontSet(
+#if NeedFunctionPrototypes
+    XFontSet           /* font_set */
+#endif
+);
+
+extern int XmbTextEscapement(
+#if NeedFunctionPrototypes
+    XFontSet           /* font_set */,
+    _Xconst char*      /* text */,
+    int                        /* bytes_text */
+#endif
+);
+
+extern int XwcTextEscapement(
+#if NeedFunctionPrototypes
+    XFontSet           /* font_set */,
+    _Xconst wchar_t*   /* text */,
+    int                        /* num_wchars */
+#endif
+);
+
+extern int XmbTextExtents(
+#if NeedFunctionPrototypes
+    XFontSet           /* font_set */,
+    _Xconst char*      /* text */,
+    int                        /* bytes_text */,
+    XRectangle*                /* overall_ink_return */,
+    XRectangle*                /* overall_logical_return */
+#endif
+);
+
+extern int XwcTextExtents(
+#if NeedFunctionPrototypes
+    XFontSet           /* font_set */,
+    _Xconst wchar_t*   /* text */,
+    int                        /* num_wchars */,
+    XRectangle*                /* overall_ink_return */,
+    XRectangle*                /* overall_logical_return */
+#endif
+);
+
+extern Status XmbTextPerCharExtents(
+#if NeedFunctionPrototypes
+    XFontSet           /* font_set */,
+    _Xconst char*      /* text */,
+    int                        /* bytes_text */,
+    XRectangle*                /* ink_extents_buffer */,
+    XRectangle*                /* logical_extents_buffer */,
+    int                        /* buffer_size */,
+    int*               /* num_chars */,
+    XRectangle*                /* overall_ink_return */,
+    XRectangle*                /* overall_logical_return */
+#endif
+);
+
+extern Status XwcTextPerCharExtents(
+#if NeedFunctionPrototypes
+    XFontSet           /* font_set */,
+    _Xconst wchar_t*   /* text */,
+    int                        /* num_wchars */,
+    XRectangle*                /* ink_extents_buffer */,
+    XRectangle*                /* logical_extents_buffer */,
+    int                        /* buffer_size */,
+    int*               /* num_chars */,
+    XRectangle*                /* overall_ink_return */,
+    XRectangle*                /* overall_logical_return */
+#endif
+);
+
+extern void XmbDrawText(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    Drawable           /* d */,
+    GC                 /* gc */,
+    int                        /* x */,
+    int                        /* y */,
+    XmbTextItem*       /* text_items */,
+    int                        /* nitems */
+#endif
+);
+
+extern void XwcDrawText(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    Drawable           /* d */,
+    GC                 /* gc */,
+    int                        /* x */,
+    int                        /* y */,
+    XwcTextItem*       /* text_items */,
+    int                        /* nitems */
+#endif
+);
+
+extern void XmbDrawString(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    Drawable           /* d */,
+    XFontSet           /* font_set */,
+    GC                 /* gc */,
+    int                        /* x */,
+    int                        /* y */,
+    _Xconst char*      /* text */,
+    int                        /* bytes_text */
+#endif
+);
+
+extern void XwcDrawString(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    Drawable           /* d */,
+    XFontSet           /* font_set */,
+    GC                 /* gc */,
+    int                        /* x */,
+    int                        /* y */,
+    _Xconst wchar_t*   /* text */,
+    int                        /* num_wchars */
+#endif
+);
+
+extern void XmbDrawImageString(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    Drawable           /* d */,
+    XFontSet           /* font_set */,
+    GC                 /* gc */,
+    int                        /* x */,
+    int                        /* y */,
+    _Xconst char*      /* text */,
+    int                        /* bytes_text */
+#endif
+);
+
+extern void XwcDrawImageString(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    Drawable           /* d */,
+    XFontSet           /* font_set */,
+    GC                 /* gc */,
+    int                        /* x */,
+    int                        /* y */,
+    _Xconst wchar_t*   /* text */,
+    int                        /* num_wchars */
+#endif
+);
+
+extern XIM XOpenIM(
+#if NeedFunctionPrototypes
+    Display*                   /* dpy */,
+    struct _XrmHashBucketRec*  /* rdb */,
+    char*                      /* res_name */,
+    char*                      /* res_class */
+#endif
+);
+
+extern Status XCloseIM(
+#if NeedFunctionPrototypes
+    XIM /* im */
+#endif
+);
+
+extern char *XGetIMValues(
+#if NeedVarargsPrototypes
+    XIM /* im */, ...
+#endif
+);
+
+extern Display *XDisplayOfIM(
+#if NeedFunctionPrototypes
+    XIM /* im */
+#endif
+);
+
+extern char *XLocaleOfIM(
+#if NeedFunctionPrototypes
+    XIM /* im*/
+#endif
+);
+
+extern XIC XCreateIC(
+#if NeedVarargsPrototypes
+    XIM /* im */, ...
+#endif
+);
+
+extern void XDestroyIC(
+#if NeedFunctionPrototypes
+    XIC /* ic */
+#endif
+);
+
+extern void XSetICFocus(
+#if NeedFunctionPrototypes
+    XIC /* ic */
+#endif
+);
+
+extern void XUnsetICFocus(
+#if NeedFunctionPrototypes
+    XIC /* ic */
+#endif
+);
+
+extern wchar_t *XwcResetIC(
+#if NeedFunctionPrototypes
+    XIC /* ic */
+#endif
+);
+
+extern char *XmbResetIC(
+#if NeedFunctionPrototypes
+    XIC /* ic */
+#endif
+);
+
+extern char *XSetICValues(
+#if NeedVarargsPrototypes
+    XIC /* ic */, ...
+#endif
+);
+
+extern char *XGetICValues(
+#if NeedVarargsPrototypes
+    XIC /* ic */, ...
+#endif
+);
+
+extern XIM XIMOfIC(
+#if NeedFunctionPrototypes
+    XIC /* ic */
+#endif
+);
+
+extern Bool XFilterEvent(
+#if NeedFunctionPrototypes
+    XEvent*    /* event */,
+    Window     /* window */
+#endif
+);
+
+extern int XmbLookupString(
+#if NeedFunctionPrototypes
+    XIC                        /* ic */,
+    XKeyPressedEvent*  /* event */,
+    char*              /* buffer_return */,
+    int                        /* bytes_buffer */,
+    KeySym*            /* keysym_return */,
+    Status*            /* status_return */
+#endif
+);
+
+extern int XwcLookupString(
+#if NeedFunctionPrototypes
+    XIC                        /* ic */,
+    XKeyPressedEvent*  /* event */,
+    wchar_t*           /* buffer_return */,
+    int                        /* wchars_buffer */,
+    KeySym*            /* keysym_return */,
+    Status*            /* status_return */
+#endif
+);
+
+extern XVaNestedList XVaCreateNestedList(
+#if NeedVarargsPrototypes
+    int /*unused*/, ...
+#endif
+);
+
+/* internal connections for IMs */
+
+extern Bool XRegisterIMInstantiateCallback(
+#if NeedFunctionPrototypes
+    Display*                   /* dpy */,
+    struct _XrmHashBucketRec*  /* rdb */,
+    char*                      /* res_name */,
+    char*                      /* res_class */,
+    XIDProc                    /* callback */,
+    XPointer                   /* client_data */
+#endif
+);
+
+extern Bool XUnregisterIMInstantiateCallback(
+#if NeedFunctionPrototypes
+    Display*                   /* dpy */,
+    struct _XrmHashBucketRec*  /* rdb */,
+    char*                      /* res_name */,
+    char*                      /* res_class */,
+    XIDProc                    /* callback */,
+    XPointer                   /* client_data */
+#endif
+);
+
+typedef void (*XConnectionWatchProc)(
+#if NeedFunctionPrototypes
+    Display*                   /* dpy */,
+    XPointer                   /* client_data */,
+    int                                /* fd */,
+    Bool                       /* opening */,   /* open or close flag */
+    XPointer*                  /* watch_data */ /* open sets, close uses */
+#endif
+);
+    
+
+extern Status XInternalConnectionNumbers(
+#if NeedFunctionPrototypes
+    Display*                   /* dpy */,
+    int**                      /* fd_return */,
+    int*                       /* count_return */
+#endif
+);
+
+extern void XProcessInternalConnection(
+#if NeedFunctionPrototypes
+    Display*                   /* dpy */,
+    int                                /* fd */
+#endif
+);
+
+extern Status XAddConnectionWatch(
+#if NeedFunctionPrototypes
+    Display*                   /* dpy */,
+    XConnectionWatchProc       /* callback */,
+    XPointer                   /* client_data */
+#endif
+);
+
+extern void XRemoveConnectionWatch(
+#if NeedFunctionPrototypes
+    Display*                   /* dpy */,
+    XConnectionWatchProc       /* callback */,
+    XPointer                   /* client_data */
+#endif
+);
+
+_XFUNCPROTOEND
+
+#endif /* _XLIB_H_ */
diff --git a/Xserver/lib/X11/Xlibint.h b/Xserver/lib/X11/Xlibint.h
new file mode 100644 (file)
index 0000000..614bd03
--- /dev/null
@@ -0,0 +1,1254 @@
+/* $XFree86: xc/lib/X11/Xlibint.h,v 3.7 1996/12/23 05:59:50 dawes Exp $ */
+/* $XConsortium: Xlibint.h /main/114 1996/10/22 14:24:29 kaleb $ */
+
+/*
+
+Copyright (c) 1984, 1985, 1987, 1989  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be included
+in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR
+OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall
+not be used in advertising or otherwise to promote the sale, use or
+other dealings in this Software without prior written authorization
+from the X Consortium.
+
+*/
+
+/*
+ *     Xlibint.h - Header definition and support file for the internal
+ *     support routines used by the C subroutine interface
+ *     library (Xlib) to the X Window System.
+ *
+ *     Warning, there be dragons here....
+ */
+
+#include <X11/Xlib.h>
+
+#ifdef WIN32
+#define _XFlush _XFlushIt
+#endif
+
+/*
+ * If your BytesReadable correctly detects broken connections, then
+ * you should NOT define XCONN_CHECK_FREQ.
+ */
+#ifndef XCONN_CHECK_FREQ
+#define XCONN_CHECK_FREQ 256
+#endif
+
+struct _XGC
+{
+    XExtData *ext_data;        /* hook for extension to hang data */
+    GContext gid;      /* protocol ID for graphics context */
+    Bool rects;                /* boolean: TRUE if clipmask is list of rectangles */
+    Bool dashes;       /* boolean: TRUE if dash-list is really a list */
+    unsigned long dirty;/* cache dirty bits */
+    XGCValues values;  /* shadow structure of values */
+};
+
+struct _XDisplay
+{
+       XExtData *ext_data;     /* hook for extension to hang data */
+       struct _XFreeFuncs *free_funcs; /* internal free functions */
+       int fd;                 /* Network socket. */
+       int conn_checker;         /* ugly thing used by _XEventsQueued */
+       int proto_major_version;/* maj. version of server's X protocol */
+       int proto_minor_version;/* minor version of server's X protocol */
+       char *vendor;           /* vendor of the server hardware */
+        XID resource_base;     /* resource ID base */
+       XID resource_mask;      /* resource ID mask bits */
+       XID resource_id;        /* allocator current ID */
+       int resource_shift;     /* allocator shift to correct bits */
+       XID (*resource_alloc)(  /* allocator function */
+#if NeedFunctionPrototypes
+               struct _XDisplay*
+#endif
+               );
+       int byte_order;         /* screen byte order, LSBFirst, MSBFirst */
+       int bitmap_unit;        /* padding and data requirements */
+       int bitmap_pad;         /* padding requirements on bitmaps */
+       int bitmap_bit_order;   /* LeastSignificant or MostSignificant */
+       int nformats;           /* number of pixmap formats in list */
+       ScreenFormat *pixmap_format;    /* pixmap format list */
+       int vnumber;            /* Xlib's X protocol version number. */
+       int release;            /* release of the server */
+       struct _XSQEvent *head, *tail;  /* Input event queue. */
+       int qlen;               /* Length of input event queue */
+       unsigned long last_request_read; /* seq number of last event read */
+       unsigned long request;  /* sequence number of last request. */
+       char *last_req;         /* beginning of last request, or dummy */
+       char *buffer;           /* Output buffer starting address. */
+       char *bufptr;           /* Output buffer index pointer. */
+       char *bufmax;           /* Output buffer maximum+1 address. */
+       unsigned max_request_size; /* maximum number 32 bit words in request*/
+       struct _XrmHashBucketRec *db;
+       int (*synchandler)(     /* Synchronization handler */
+#if NeedFunctionPrototypes
+               struct _XDisplay*
+#endif
+               );
+       char *display_name;     /* "host:display" string used on this connect*/
+       int default_screen;     /* default screen for operations */
+       int nscreens;           /* number of screens on this server*/
+       Screen *screens;        /* pointer to list of screens */
+       unsigned long motion_buffer;    /* size of motion buffer */
+       unsigned long flags;       /* internal connection flags */
+       int min_keycode;        /* minimum defined keycode */
+       int max_keycode;        /* maximum defined keycode */
+       KeySym *keysyms;        /* This server's keysyms */
+       XModifierKeymap *modifiermap;   /* This server's modifier keymap */
+       int keysyms_per_keycode;/* number of rows */
+       char *xdefaults;        /* contents of defaults from server */
+       char *scratch_buffer;   /* place to hang scratch buffer */
+       unsigned long scratch_length;   /* length of scratch buffer */
+       int ext_number;         /* extension number on this display */
+       struct _XExten *ext_procs; /* extensions initialized on this display */
+       /*
+        * the following can be fixed size, as the protocol defines how
+        * much address space is available. 
+        * While this could be done using the extension vector, there
+        * may be MANY events processed, so a search through the extension
+        * list to find the right procedure for each event might be
+        * expensive if many extensions are being used.
+        */
+       Bool (*event_vec[128])();  /* vector for wire to event */
+       Status (*wire_vec[128])(); /* vector for event to wire */
+       KeySym lock_meaning;       /* for XLookupString */
+       struct _XLockInfo *lock;   /* multi-thread state, display lock */
+       struct _XInternalAsync *async_handlers; /* for internal async */
+       unsigned long bigreq_size; /* max size of big requests */
+       struct _XLockPtrs *lock_fns; /* pointers to threads functions */
+       void (*idlist_alloc)();    /* XID list allocator function */
+       /* things above this line should not move, for binary compatibility */
+       struct _XKeytrans *key_bindings; /* for XLookupString */
+       Font cursor_font;          /* for XCreateFontCursor */
+       struct _XDisplayAtoms *atoms; /* for XInternAtom */
+       unsigned int mode_switch;  /* keyboard group modifiers */
+       unsigned int num_lock;  /* keyboard numlock modifiers */
+       struct _XContextDB *context_db; /* context database */
+       Bool (**error_vec)();      /* vector for wire to error */
+       /*
+        * Xcms information
+        */
+       struct {
+          XPointer defaultCCCs;  /* pointer to an array of default XcmsCCC */
+          XPointer clientCmaps;  /* pointer to linked list of XcmsCmapRec */
+          XPointer perVisualIntensityMaps;
+                                 /* linked list of XcmsIntensityMap */
+       } cms;
+       struct _XIMFilter *im_filters;
+       struct _XSQEvent *qfree; /* unallocated event queue elements */
+       unsigned long next_event_serial_num; /* inserted into next queue elt */
+       struct _XExten *flushes; /* Flush hooks */
+       struct _XConnectionInfo *im_fd_info; /* _XRegisterInternalConnection */
+       int im_fd_length;       /* number of im_fd_info */
+       struct _XConnWatchInfo *conn_watchers; /* XAddConnectionWatch */
+       int watcher_count;      /* number of conn_watchers */
+       XPointer filedes;       /* struct pollfd cache for _XWaitForReadable */
+       int (*savedsynchandler)(); /* user synchandler when Xlib usurps */
+       XID resource_max;       /* allocator max ID */
+       int xcmisc_opcode;      /* major opcode for XC-MISC */
+       struct _XkbInfoRec *xkb_info; /* XKB info */
+       struct _XtransConnInfo *trans_conn; /* transport connection object */
+};
+
+#define XAllocIDs(dpy,ids,n) (*(dpy)->idlist_alloc)(dpy,ids,n)
+
+/*
+ * define the following if you want the Data macro to be a procedure instead
+ */
+#ifdef CRAY
+#define DataRoutineIsProcedure
+#endif /* CRAY */
+
+#ifndef _XEVENT_
+/*
+ * _QEvent datatype for use in input queueing.
+ */
+typedef struct _XSQEvent
+{
+    struct _XSQEvent *next;
+    XEvent event;
+    unsigned long qserial_num; /* so multi-threaded code can find new ones */
+} _XQEvent;
+#endif
+
+#ifdef XTHREADS                        /* for xReply */
+#define NEED_REPLIES
+#endif
+
+#if NeedFunctionPrototypes     /* prototypes require event type definitions */
+#define NEED_EVENTS
+#define NEED_REPLIES
+#endif
+#include <X11/Xproto.h>
+#ifdef __sgi
+#define _SGI_MP_SOURCE  /* turn this on to get MP safe errno */
+#endif
+#include <errno.h>
+#define _XBCOPYFUNC _Xbcopy
+#include <X11/Xfuncs.h>
+#include <X11/Xosdefs.h>
+
+/* Utek leaves kernel macros around in include files (bleah) */
+#ifdef dirty
+#undef dirty
+#endif
+
+#ifndef X_NOT_STDC_ENV
+#include <stdlib.h>
+#include <string.h>
+#else
+char *malloc(), *realloc(), *calloc();
+void exit();
+#ifdef SYSV
+#include <string.h>
+#else
+#include <strings.h>
+#endif
+#endif
+
+/*
+ * The following definitions can be used for locking requests in multi-threaded
+ * address spaces.
+ */
+#ifdef XTHREADS
+/* Author: Stephen Gildea, MIT X Consortium
+ *
+ * declarations for C Threads locking
+ */
+
+#include <X11/Xfuncproto.h>
+
+struct _XLockPtrs {
+    /* used by all, including extensions; do not move */
+    void (*lock_display)();
+    void (*unlock_display)();
+};
+
+typedef struct _LockInfoRec *LockInfoPtr;
+
+#if defined(WIN32) && !defined(_XLIBINT_)
+#define _XCreateMutex_fn (*_XCreateMutex_fn_p)
+#define _XFreeMutex_fn (*_XFreeMutex_fn_p)
+#define _XLockMutex_fn (*_XLockMutex_fn_p)
+#define _XUnlockMutex_fn (*_XUnlockMutex_fn_p)
+#define _Xglobal_lock (*_Xglobal_lock_p)
+#endif
+
+/* in XlibInt.c */
+extern void (*_XCreateMutex_fn)(
+#if NeedFunctionPrototypes
+    LockInfoPtr /* lock */
+#endif
+);
+extern void (*_XFreeMutex_fn)(
+#if NeedFunctionPrototypes
+    LockInfoPtr /* lock */
+#endif
+);
+extern void (*_XLockMutex_fn)(
+#if NeedFunctionPrototypes
+    LockInfoPtr        /* lock */
+#if defined(XTHREADS_WARN) || defined(XTHREADS_FILE_LINE)
+    , char * /* file */
+    , int /* line */
+#endif
+#endif
+);
+extern void (*_XUnlockMutex_fn)(
+#if NeedFunctionPrototypes
+    LockInfoPtr        /* lock */
+#if defined(XTHREADS_WARN) || defined(XTHREADS_FILE_LINE)
+    , char * /* file */
+    , int /* line */
+#endif
+#endif
+);
+
+extern LockInfoPtr _Xglobal_lock;
+
+#if defined(XTHREADS_WARN) || defined(XTHREADS_FILE_LINE)
+#define LockDisplay(d)      if ((d)->lock_fns) (*(d)->lock_fns->lock_display)((d),__FILE__,__LINE__)
+#define UnlockDisplay(d)     if ((d)->lock_fns) (*(d)->lock_fns->unlock_display)((d),__FILE__,__LINE__)
+#define _XLockMutex(lock)              if (_XLockMutex_fn) (*_XLockMutex_fn)(lock,__FILE__,__LINE__)
+#define _XUnlockMutex(lock)    if (_XUnlockMutex_fn) (*_XUnlockMutex_fn)(lock,__FILE__,__LINE__)
+#else
+/* used everywhere, so must be fast if not using threads */
+#define LockDisplay(d)      if ((d)->lock_fns) (*(d)->lock_fns->lock_display)(d)
+#define UnlockDisplay(d)     if ((d)->lock_fns) (*(d)->lock_fns->unlock_display)(d)
+#define _XLockMutex(lock)              if (_XLockMutex_fn) (*_XLockMutex_fn)(lock)
+#define _XUnlockMutex(lock)    if (_XUnlockMutex_fn) (*_XUnlockMutex_fn)(lock)
+#endif
+#define _XCreateMutex(lock)    if (_XCreateMutex_fn) (*_XCreateMutex_fn)(lock);
+#define _XFreeMutex(lock)      if (_XFreeMutex_fn) (*_XFreeMutex_fn)(lock);
+
+#else /* XTHREADS */
+#define LockDisplay(dis)
+#define _XLockMutex(lock)
+#define _XUnlockMutex(lock)
+#define UnlockDisplay(dis)
+#define _XCreateMutex(lock)
+#define _XFreeMutex(lock)
+#endif
+
+#define Xfree(ptr) free((ptr))
+
+/*
+ * Note that some machines do not return a valid pointer for malloc(0), in
+ * which case we provide an alternate under the control of the
+ * define MALLOC_0_RETURNS_NULL.  This is necessary because some
+ * Xlib code expects malloc(0) to return a valid pointer to storage.
+ */
+#ifdef MALLOC_0_RETURNS_NULL
+
+# define Xmalloc(size) malloc(((size) == 0 ? 1 : (size)))
+# define Xrealloc(ptr, size) realloc((ptr), ((size) == 0 ? 1 : (size)))
+# define Xcalloc(nelem, elsize) calloc(((nelem) == 0 ? 1 : (nelem)), (elsize))
+
+#else
+
+# define Xmalloc(size) malloc((size))
+# define Xrealloc(ptr, size) realloc((ptr), (size))
+# define Xcalloc(nelem, elsize) calloc((nelem), (elsize))
+
+#endif
+
+#ifndef NULL
+#define NULL 0
+#endif
+#define LOCKED 1
+#define UNLOCKED 0
+
+#ifdef X_NOT_STDC_ENV
+extern int errno;                      /* Internal system error number. */
+#endif
+
+#ifndef BUFSIZE
+#define BUFSIZE 2048                   /* X output buffer size. */
+#endif
+#ifndef PTSPERBATCH
+#define PTSPERBATCH 1024               /* point batching */
+#endif
+#ifndef WLNSPERBATCH
+#define WLNSPERBATCH 50                        /* wide line batching */
+#endif
+#ifndef ZLNSPERBATCH
+#define ZLNSPERBATCH 1024              /* thin line batching */
+#endif
+#ifndef WRCTSPERBATCH
+#define WRCTSPERBATCH 10               /* wide line rectangle batching */
+#endif
+#ifndef ZRCTSPERBATCH
+#define ZRCTSPERBATCH 256              /* thin line rectangle batching */
+#endif
+#ifndef FRCTSPERBATCH
+#define FRCTSPERBATCH 256              /* filled rectangle batching */
+#endif
+#ifndef FARCSPERBATCH
+#define FARCSPERBATCH 256              /* filled arc batching */
+#endif
+#ifndef CURSORFONT
+#define CURSORFONT "cursor"            /* standard cursor fonts */
+#endif
+
+/*
+ * Display flags
+ */
+#define XlibDisplayIOError     (1L << 0)
+#define XlibDisplayClosing     (1L << 1)
+#define XlibDisplayNoXkb       (1L << 2)
+#define XlibDisplayPrivSync    (1L << 3)
+#define XlibDisplayProcConni   (1L << 4) /* in _XProcessInternalConnection */
+#define XlibDisplayReadEvents  (1L << 5) /* in _XReadEvents */
+#define XlibDisplayReply       (1L << 5) /* in _XReply */
+#define XlibDisplayWriting     (1L << 6) /* in _XFlushInt, _XSend */
+
+/*
+ * X Protocol packetizing macros.
+ */
+
+/*   Need to start requests on 64 bit word boundaries
+ *   on a CRAY computer so add a NoOp (127) if needed.
+ *   A character pointer on a CRAY computer will be non-zero
+ *   after shifting right 61 bits of it is not pointing to
+ *   a word boundary.
+ */
+#ifdef WORD64
+#define WORD64ALIGN if ((long)dpy->bufptr >> 61) {\
+           dpy->last_req = dpy->bufptr;\
+           *(dpy->bufptr)   = X_NoOperation;\
+           *(dpy->bufptr+1) =  0;\
+           *(dpy->bufptr+2) =  0;\
+           *(dpy->bufptr+3) =  1;\
+             dpy->request++;\
+             dpy->bufptr += 4;\
+         }
+#else /* else does not require alignment on 64-bit boundaries */
+#define WORD64ALIGN
+#endif /* WORD64 */
+
+
+/*
+ * GetReq - Get the next available X request packet in the buffer and
+ * return it. 
+ *
+ * "name" is the name of the request, e.g. CreatePixmap, OpenFont, etc.
+ * "req" is the name of the request pointer.
+ *
+ */
+
+#if (defined(__STDC__) && !defined(UNIXCPP)) || defined(ANSICPP)
+#define GetReq(name, req) \
+        WORD64ALIGN\
+       if ((dpy->bufptr + SIZEOF(x##name##Req)) > dpy->bufmax)\
+               _XFlush(dpy);\
+       req = (x##name##Req *)(dpy->last_req = dpy->bufptr);\
+       req->reqType = X_##name;\
+       req->length = (SIZEOF(x##name##Req))>>2;\
+       dpy->bufptr += SIZEOF(x##name##Req);\
+       dpy->request++
+
+#else  /* non-ANSI C uses empty comment instead of "##" for token concatenation */
+#define GetReq(name, req) \
+        WORD64ALIGN\
+       if ((dpy->bufptr + SIZEOF(x/**/name/**/Req)) > dpy->bufmax)\
+               _XFlush(dpy);\
+       req = (x/**/name/**/Req *)(dpy->last_req = dpy->bufptr);\
+       req->reqType = X_/**/name;\
+       req->length = (SIZEOF(x/**/name/**/Req))>>2;\
+       dpy->bufptr += SIZEOF(x/**/name/**/Req);\
+       dpy->request++
+#endif
+
+/* GetReqExtra is the same as GetReq, but allocates "n" additional
+   bytes after the request. "n" must be a multiple of 4!  */
+
+#if (defined(__STDC__) && !defined(UNIXCPP)) || defined(ANSICPP)
+#define GetReqExtra(name, n, req) \
+        WORD64ALIGN\
+       if ((dpy->bufptr + SIZEOF(x##name##Req) + n) > dpy->bufmax)\
+               _XFlush(dpy);\
+       req = (x##name##Req *)(dpy->last_req = dpy->bufptr);\
+       req->reqType = X_##name;\
+       req->length = (SIZEOF(x##name##Req) + n)>>2;\
+       dpy->bufptr += SIZEOF(x##name##Req) + n;\
+       dpy->request++
+#else
+#define GetReqExtra(name, n, req) \
+        WORD64ALIGN\
+       if ((dpy->bufptr + SIZEOF(x/**/name/**/Req) + n) > dpy->bufmax)\
+               _XFlush(dpy);\
+       req = (x/**/name/**/Req *)(dpy->last_req = dpy->bufptr);\
+       req->reqType = X_/**/name;\
+       req->length = (SIZEOF(x/**/name/**/Req) + n)>>2;\
+       dpy->bufptr += SIZEOF(x/**/name/**/Req) + n;\
+       dpy->request++
+#endif
+
+
+/*
+ * GetResReq is for those requests that have a resource ID 
+ * (Window, Pixmap, GContext, etc.) as their single argument.
+ * "rid" is the name of the resource. 
+ */
+
+#if (defined(__STDC__) && !defined(UNIXCPP)) || defined(ANSICPP)
+#define GetResReq(name, rid, req) \
+        WORD64ALIGN\
+       if ((dpy->bufptr + SIZEOF(xResourceReq)) > dpy->bufmax)\
+           _XFlush(dpy);\
+       req = (xResourceReq *) (dpy->last_req = dpy->bufptr);\
+       req->reqType = X_##name;\
+       req->length = 2;\
+       req->id = (rid);\
+       dpy->bufptr += SIZEOF(xResourceReq);\
+       dpy->request++
+#else
+#define GetResReq(name, rid, req) \
+        WORD64ALIGN\
+       if ((dpy->bufptr + SIZEOF(xResourceReq)) > dpy->bufmax)\
+           _XFlush(dpy);\
+       req = (xResourceReq *) (dpy->last_req = dpy->bufptr);\
+       req->reqType = X_/**/name;\
+       req->length = 2;\
+       req->id = (rid);\
+       dpy->bufptr += SIZEOF(xResourceReq);\
+       dpy->request++
+#endif
+
+/*
+ * GetEmptyReq is for those requests that have no arguments
+ * at all. 
+ */
+#if (defined(__STDC__) && !defined(UNIXCPP)) || defined(ANSICPP)
+#define GetEmptyReq(name, req) \
+        WORD64ALIGN\
+       if ((dpy->bufptr + SIZEOF(xReq)) > dpy->bufmax)\
+           _XFlush(dpy);\
+       req = (xReq *) (dpy->last_req = dpy->bufptr);\
+       req->reqType = X_##name;\
+       req->length = 1;\
+       dpy->bufptr += SIZEOF(xReq);\
+       dpy->request++
+#else
+#define GetEmptyReq(name, req) \
+        WORD64ALIGN\
+       if ((dpy->bufptr + SIZEOF(xReq)) > dpy->bufmax)\
+           _XFlush(dpy);\
+       req = (xReq *) (dpy->last_req = dpy->bufptr);\
+       req->reqType = X_/**/name;\
+       req->length = 1;\
+       dpy->bufptr += SIZEOF(xReq);\
+       dpy->request++
+#endif
+
+#ifdef WORD64
+#define MakeBigReq(req,n) \
+    { \
+    char _BRdat[4]; \
+    unsigned long _BRlen = req->length - 1; \
+    req->length = 0; \
+    memcpy(_BRdat, ((char *)req) + (_BRlen << 2), 4); \
+    memmove(((char *)req) + 8, ((char *)req) + 4, _BRlen << 2); \
+    memcpy(((char *)req) + 4, _BRdat, 4); \
+    Data32(dpy, (long *)&_BRdat, 4); \
+    }
+#else
+#define MakeBigReq(req,n) \
+    { \
+    CARD32 _BRdat; \
+    CARD32 _BRlen = req->length - 1; \
+    req->length = 0; \
+    _BRdat = ((CARD32 *)req)[_BRlen]; \
+    memmove(((char *)req) + 8, ((char *)req) + 4, _BRlen << 2); \
+    ((CARD32 *)req)[1] = _BRlen + n + 2; \
+    Data32(dpy, &_BRdat, 4); \
+    }
+#endif
+
+#define SetReqLen(req,n,badlen) \
+    if ((req->length + n) > (unsigned)65535) { \
+       if (dpy->bigreq_size) { \
+           MakeBigReq(req,n) \
+       } else { \
+           n = badlen; \
+           req->length += n; \
+       } \
+    } else \
+       req->length += n
+
+#define SyncHandle() \
+       if (dpy->synchandler) (*dpy->synchandler)(dpy)
+
+extern void _XFlushGCCache();
+#define FlushGC(dpy, gc) \
+       if ((gc)->dirty) _XFlushGCCache((dpy), (gc))
+/*
+ * Data - Place data in the buffer and pad the end to provide
+ * 32 bit word alignment.  Transmit if the buffer fills.
+ *
+ * "dpy" is a pointer to a Display.
+ * "data" is a pinter to a data buffer.
+ * "len" is the length of the data buffer.
+ */
+#ifndef DataRoutineIsProcedure
+#define Data(dpy, data, len) \
+       if (dpy->bufptr + (len) <= dpy->bufmax) {\
+               memcpy(dpy->bufptr, data, (int)len);\
+               dpy->bufptr += ((len) + 3) & ~3;\
+       } else\
+               _XSend(dpy, data, len)
+#endif /* DataRoutineIsProcedure */
+
+
+/* Allocate bytes from the buffer.  No padding is done, so if
+ * the length is not a multiple of 4, the caller must be
+ * careful to leave the buffer aligned after sending the
+ * current request.
+ *
+ * "type" is the type of the pointer being assigned to.
+ * "ptr" is the pointer being assigned to.
+ * "n" is the number of bytes to allocate.
+ *
+ * Example: 
+ *    xTextElt *elt;
+ *    BufAlloc (xTextElt *, elt, nbytes)
+ */
+
+#define BufAlloc(type, ptr, n) \
+    if (dpy->bufptr + (n) > dpy->bufmax) \
+        _XFlush (dpy); \
+    ptr = (type) dpy->bufptr; \
+    dpy->bufptr += (n);
+
+#ifdef WORD64
+#define Data16(dpy, data, len) _XData16(dpy, (short *)data, len)
+#define Data32(dpy, data, len) _XData32(dpy, (long *)data, len)
+#else
+#define Data16(dpy, data, len) Data((dpy), (char *)(data), (len))
+#define _XRead16Pad(dpy, data, len) _XReadPad((dpy), (char *)(data), (len))
+#define _XRead16(dpy, data, len) _XRead((dpy), (char *)(data), (len))
+#ifdef LONG64
+#define Data32(dpy, data, len) _XData32(dpy, (long *)data, len)
+#else
+#define Data32(dpy, data, len) Data((dpy), (char *)(data), (len))
+#define _XRead32(dpy, data, len) _XRead((dpy), (char *)(data), (len))
+#endif
+#endif /* not WORD64 */
+
+#define PackData16(dpy,data,len) Data16 (dpy, data, len)
+#define PackData32(dpy,data,len) Data32 (dpy, data, len)
+
+/* Xlib manual is bogus */
+#define PackData(dpy,data,len) PackData16 (dpy, data, len)
+
+#define min(a,b) (((a) < (b)) ? (a) : (b))
+#define max(a,b) (((a) > (b)) ? (a) : (b))
+
+#define CI_NONEXISTCHAR(cs) (((cs)->width == 0) && \
+                            (((cs)->rbearing|(cs)->lbearing| \
+                              (cs)->ascent|(cs)->descent) == 0))
+
+/* 
+ * CI_GET_CHAR_INFO_1D - return the charinfo struct for the indicated 8bit
+ * character.  If the character is in the column and exists, then return the
+ * appropriate metrics (note that fonts with common per-character metrics will
+ * return min_bounds).  If none of these hold true, try again with the default
+ * char.
+ */
+#define CI_GET_CHAR_INFO_1D(fs,col,def,cs) \
+{ \
+    cs = def; \
+    if (col >= fs->min_char_or_byte2 && col <= fs->max_char_or_byte2) { \
+       if (fs->per_char == NULL) { \
+           cs = &fs->min_bounds; \
+       } else { \
+           cs = &fs->per_char[(col - fs->min_char_or_byte2)]; \
+           if (CI_NONEXISTCHAR(cs)) cs = def; \
+       } \
+    } \
+}
+
+#define CI_GET_DEFAULT_INFO_1D(fs,cs) \
+  CI_GET_CHAR_INFO_1D (fs, fs->default_char, NULL, cs)
+
+
+
+/*
+ * CI_GET_CHAR_INFO_2D - return the charinfo struct for the indicated row and 
+ * column.  This is used for fonts that have more than row zero.
+ */
+#define CI_GET_CHAR_INFO_2D(fs,row,col,def,cs) \
+{ \
+    cs = def; \
+    if (row >= fs->min_byte1 && row <= fs->max_byte1 && \
+       col >= fs->min_char_or_byte2 && col <= fs->max_char_or_byte2) { \
+       if (fs->per_char == NULL) { \
+           cs = &fs->min_bounds; \
+       } else { \
+           cs = &fs->per_char[((row - fs->min_byte1) * \
+                               (fs->max_char_or_byte2 - \
+                                fs->min_char_or_byte2 + 1)) + \
+                              (col - fs->min_char_or_byte2)]; \
+           if (CI_NONEXISTCHAR(cs)) cs = def; \
+        } \
+    } \
+}
+
+#define CI_GET_DEFAULT_INFO_2D(fs,cs) \
+{ \
+    unsigned int r = (fs->default_char >> 8); \
+    unsigned int c = (fs->default_char & 0xff); \
+    CI_GET_CHAR_INFO_2D (fs, r, c, NULL, cs); \
+}
+
+
+#ifdef MUSTCOPY
+
+/* for when 32-bit alignment is not good enough */
+#define OneDataCard32(dpy,dstaddr,srcvar) \
+  { dpy->bufptr -= 4; Data32 (dpy, (char *) &(srcvar), 4); }
+
+#else
+
+/* srcvar must be a variable for large architecture version */
+#define OneDataCard32(dpy,dstaddr,srcvar) \
+  { *(CARD32 *)(dstaddr) = (srcvar); }
+
+#endif /* MUSTCOPY */
+
+typedef struct _XInternalAsync {
+    struct _XInternalAsync *next;
+    /*
+     * handler arguments:
+     * rep is the generic reply that caused this handler
+     * to be invoked.  It must also be passed to _XGetAsyncReply.
+     * buf and len are opaque values that must be passed to
+     * _XGetAsyncReply or _XGetAsyncData.
+     * data is the closure stored in this struct.
+     * The handler returns True iff it handled this reply.
+     */
+    Bool (*handler)(
+#if NeedNestedPrototypes
+                   Display*    /* dpy */,
+                   xReply*     /* rep */,
+                   char*       /* buf */,
+                   int         /* len */,
+                   XPointer    /* data */
+#endif
+                   );
+    XPointer data;
+} _XAsyncHandler;
+
+typedef struct _XAsyncEState {
+    unsigned long min_sequence_number;
+    unsigned long max_sequence_number;
+    unsigned char error_code;
+    unsigned char major_opcode;
+    unsigned short minor_opcode;
+    unsigned char last_error_received;
+    int error_count;
+} _XAsyncErrorState;
+
+extern void _XDeqAsyncHandler();
+#define DeqAsyncHandler(dpy,handler) { \
+    if (dpy->async_handlers == (handler)) \
+       dpy->async_handlers = (handler)->next; \
+    else \
+       _XDeqAsyncHandler(dpy, handler); \
+    }
+
+/*
+ * This structure is private to the library.
+ */
+typedef struct _XFreeFuncs {
+    void (*atoms)();           /* _XFreeAtomTable */
+    int (*modifiermap)();      /* XFreeModifierMap */
+    void (*key_bindings)();    /* _XFreeKeyBindings */
+    void (*context_db)();      /* _XFreeContextDB */
+    void (*defaultCCCs)();     /* _XcmsFreeDefaultCCCs */
+    void (*clientCmaps)();     /* _XcmsFreeClientCmaps */
+    void (*intensityMaps)();   /* _XcmsFreeIntensityMaps */
+    void (*im_filters)();      /* _XFreeIMFilters */
+    void (*xkb)();             /* _XkbFreeInfo */
+} _XFreeFuncRec;
+
+/*
+ * This structure is private to the library.
+ */
+typedef struct _XExten {       /* private to extension mechanism */
+       struct _XExten *next;   /* next in list */
+       XExtCodes codes;        /* public information, all extension told */
+       int (*create_GC)();     /* routine to call when GC created */
+       int (*copy_GC)();       /* routine to call when GC copied */
+       int (*flush_GC)();      /* routine to call when GC flushed */
+       int (*free_GC)();       /* routine to call when GC freed */
+       int (*create_Font)();   /* routine to call when Font created */
+       int (*free_Font)();     /* routine to call when Font freed */
+       int (*close_display)(); /* routine to call when connection closed */
+       int (*error)();         /* who to call when an error occurs */
+        char *(*error_string)();  /* routine to supply error string */
+       char *name;             /* name of this extension */
+       void (*error_values)(); /* routine to supply error values */
+       void (*before_flush)(); /* routine to call when sending data */
+       struct _XExten *next_flush; /* next in list of those with flushes */
+} _XExtension;
+
+/* extension hooks */
+
+_XFUNCPROTOBEGIN
+
+#ifdef DataRoutineIsProcedure
+extern void Data();
+#endif
+extern int _XError(
+#if NeedFunctionPrototypes
+    Display*   /* dpy */,
+    xError*    /* rep */
+#endif
+);
+extern int _XIOError(
+#if NeedFunctionPrototypes
+    Display*   /* dpy */
+#endif
+);
+extern int (*_XIOErrorFunction)(
+#if NeedNestedPrototypes
+    Display*   /* dpy */
+#endif
+);
+extern int (*_XErrorFunction)(
+#if NeedNestedPrototypes
+    Display*           /* dpy */,
+    XErrorEvent*       /* error_event */
+#endif
+);
+extern void _XEatData(
+#if NeedFunctionPrototypes
+    Display*           /* dpy */,
+    unsigned long      /* n */
+#endif
+);
+extern char *_XAllocScratch(
+#if NeedFunctionPrototypes
+    Display*           /* dpy */,
+    unsigned long      /* nbytes */
+#endif
+);
+extern char *_XAllocTemp(
+#if NeedFunctionPrototypes
+    Display*           /* dpy */,
+    unsigned long      /* nbytes */
+#endif
+);
+extern void _XFreeTemp(
+#if NeedFunctionPrototypes
+    Display*           /* dpy */,
+    char*              /* buf */,
+    unsigned long      /* nbytes */
+#endif
+);
+extern Visual *_XVIDtoVisual(
+#if NeedFunctionPrototypes
+    Display*   /* dpy */,
+    VisualID   /* id */
+#endif
+);
+extern unsigned long _XSetLastRequestRead(
+#if NeedFunctionPrototypes
+    Display*           /* dpy */,
+    xGenericReply*     /* rep */
+#endif
+);
+extern int _XGetHostname(
+#if NeedFunctionPrototypes
+    char*      /* buf */,
+    int                /* maxlen */
+#endif
+);
+extern Screen *_XScreenOfWindow(
+#if NeedFunctionPrototypes
+    Display*   /* dpy */,
+    Window     /* w */
+#endif
+);
+extern Bool _XAsyncErrorHandler(
+#if NeedFunctionPrototypes
+    Display*   /* dpy */,
+    xReply*    /* rep */,
+    char*      /* buf */,
+    int                /* len */,
+    XPointer   /* data */
+#endif
+);
+extern char *_XGetAsyncReply(
+#if NeedFunctionPrototypes
+    Display*   /* dpy */,
+    char*      /* replbuf */,
+    xReply*    /* rep */,
+    char*      /* buf */,
+    int                /* len */,
+    int                /* extra */,
+    Bool       /* discard */
+#endif
+);
+extern void _XFlush(
+#if NeedFunctionPrototypes
+    Display*   /* dpy */
+#endif
+);
+extern int _XEventsQueued(
+#if NeedFunctionPrototypes
+    Display*   /* dpy */,
+    int        /* mode */
+#endif
+);
+extern void _XReadEvents(
+#if NeedFunctionPrototypes
+    Display*   /* dpy */
+#endif
+);
+extern int _XRead(
+#if NeedFunctionPrototypes
+    Display*   /* dpy */,
+    char*      /* data */,
+    long       /* size */
+#endif
+);
+extern void _XReadPad(
+#if NeedFunctionPrototypes
+    Display*   /* dpy */,
+    char*      /* data */,
+    long       /* size */
+#endif
+);
+extern void _XSend(
+#if NeedFunctionPrototypes
+    Display*           /* dpy */,
+    _Xconst char*      /* data */,
+    long               /* size */
+#endif
+);
+extern Status _XReply(
+#if NeedFunctionPrototypes
+    Display*   /* dpy */,
+    xReply*    /* rep */,
+    int                /* extra */,
+    Bool       /* discard */
+#endif
+);
+extern void _XEnq(
+#if NeedFunctionPrototypes
+    Display*   /* dpy */,
+    xEvent*    /* event */
+#endif
+);
+extern void _XDeq(
+#if NeedFunctionPrototypes
+    Display*   /* dpy */,
+    _XQEvent*  /* prev */,
+    _XQEvent*  /* qelt */
+#endif
+);
+
+extern int (*XESetCreateGC(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    int                        /* extension */,
+    int (*) (
+#if NeedNestedPrototypes
+             Display*                  /* display */,
+             GC                        /* gc */,
+             XExtCodes*                /* codes */
+#endif
+           )           /* proc */
+#endif
+))(
+#if NeedNestedPrototypes
+    Display*, GC, XExtCodes*
+#endif
+);
+
+extern int (*XESetCopyGC(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    int                        /* extension */,
+    int (*) (
+#if NeedNestedPrototypes
+             Display*                  /* display */,
+              GC                       /* gc */,
+              XExtCodes*               /* codes */
+#endif
+            )          /* proc */            
+#endif
+))(
+#if NeedNestedPrototypes
+    Display*, GC, XExtCodes*
+#endif
+);
+
+extern int (*XESetFlushGC(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    int                        /* extension */,
+    int (*) (
+#if NeedNestedPrototypes
+             Display*                  /* display */,
+              GC                       /* gc */,
+              XExtCodes*               /* codes */
+#endif
+            )          /* proc */           
+#endif
+))(
+#if NeedNestedPrototypes
+    Display*, GC, XExtCodes*
+#endif
+);
+
+extern int (*XESetFreeGC(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    int                        /* extension */,
+    int (*) (
+#if NeedNestedPrototypes
+             Display*                  /* display */,
+              GC                       /* gc */,
+              XExtCodes*               /* codes */
+#endif
+            )          /* proc */           
+#endif
+))(
+#if NeedNestedPrototypes
+    Display*, GC, XExtCodes*
+#endif
+);
+
+extern int (*XESetCreateFont(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    int                        /* extension */,
+    int (*) (
+#if NeedNestedPrototypes
+             Display*                  /* display */,
+              XFontStruct*             /* fs */,
+              XExtCodes*               /* codes */
+#endif
+            )          /* proc */    
+#endif
+))(
+#if NeedNestedPrototypes
+    Display*, XFontStruct*, XExtCodes*
+#endif
+);
+
+extern int (*XESetFreeFont(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    int                        /* extension */,
+    int (*) (
+#if NeedNestedPrototypes
+             Display*                  /* display */,
+              XFontStruct*             /* fs */,
+              XExtCodes*               /* codes */
+#endif
+            )          /* proc */    
+#endif
+))(
+#if NeedNestedPrototypes
+    Display*, XFontStruct*, XExtCodes*
+#endif
+); 
+
+extern int (*XESetCloseDisplay(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    int                        /* extension */,
+    int (*) (
+#if NeedNestedPrototypes
+             Display*                  /* display */,
+              XExtCodes*               /* codes */
+#endif
+            )          /* proc */    
+#endif
+))(
+#if NeedNestedPrototypes
+    Display*, XExtCodes*
+#endif
+);
+
+extern int (*XESetError(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    int                        /* extension */,
+    int (*) (
+#if NeedNestedPrototypes
+             Display*                  /* display */,
+              xError*                  /* err */,
+              XExtCodes*               /* codes */,
+              int*                     /* ret_code */
+#endif
+            )          /* proc */    
+#endif
+))(
+#if NeedNestedPrototypes
+    Display*, xError*, XExtCodes*, int*
+#endif
+);
+
+extern char* (*XESetErrorString(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    int                        /* extension */,
+    char* (*) (
+#if NeedNestedPrototypes
+               Display*                /* display */,
+                int                    /* code */,
+                XExtCodes*             /* codes */,
+                char*                  /* buffer */,
+                int                    /* nbytes */
+#endif
+              )                /* proc */             
+#endif
+))(
+#if NeedNestedPrototypes
+    Display*, int, XExtCodes*, char*, int
+#endif
+);
+
+extern void (*XESetPrintErrorValues (
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    int                        /* extension */,
+    void (*)(
+#if NeedNestedPrototypes
+             Display*                  /* display */,
+             XErrorEvent*              /* ev */,
+             void*                     /* fp */
+#endif
+            )          /* proc */
+#endif
+))(
+#if NeedNestedPrototypes
+    Display*, XErrorEvent*, void*
+#endif
+);
+
+extern Bool (*XESetWireToEvent(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    int                        /* event_number */,
+    Bool (*) (
+#if NeedNestedPrototypes
+              Display*                 /* display */,
+               XEvent*                 /* re */,
+               xEvent*                 /* event */
+#endif
+             )         /* proc */    
+#endif
+))(
+#if NeedNestedPrototypes
+    Display*, XEvent*, xEvent*
+#endif
+);
+
+extern Status (*XESetEventToWire(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    int                        /* event_number */,
+    Status (*) (
+#if NeedNestedPrototypes
+             Display*                  /* display */,
+              XEvent*                  /* re */,
+              xEvent*                  /* event */
+#endif
+            )          /* proc */   
+#endif
+))(
+#if NeedNestedPrototypes
+    Display*, XEvent*, xEvent*
+#endif
+);
+
+extern Bool (*XESetWireToError(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    int                        /* error_number */,
+    Bool (*) (
+#if NeedNestedPrototypes
+              Display*                 /* display */,
+              XErrorEvent*             /* he */,
+              xError*                  /* we */
+#endif
+            )          /* proc */   
+#endif
+))(
+#if NeedNestedPrototypes
+    Display*, XErrorEvent*, xError*
+#endif
+);
+
+extern void (*XESetBeforeFlush(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    int                        /* error_number */,
+    void (*) (
+#if NeedNestedPrototypes
+              Display*                 /* display */,
+              XExtCodes*               /* codes */,
+              char*                    /* data */,
+              long                     /* len */
+#endif
+            )          /* proc */   
+#endif
+))(
+#if NeedNestedPrototypes
+    Display*, XExtCodes*, char*, long
+#endif
+);
+
+/* internal connections for IMs */
+
+typedef void (*_XInternalConnectionProc)(
+#if NeedFunctionPrototypes
+    Display*                   /* dpy */,
+    int                                /* fd */,
+    XPointer                   /* call_data */
+#endif
+);
+
+
+extern Status _XRegisterInternalConnection(
+#if NeedFunctionPrototypes
+    Display*                   /* dpy */,
+    int                                /* fd */,
+    _XInternalConnectionProc   /* callback */,
+    XPointer                   /* call_data */
+#endif
+);
+
+extern void _XUnregisterInternalConnection(
+#if NeedFunctionPrototypes
+    Display*                   /* dpy */,
+    int                                /* fd */
+#endif
+);
+
+/* Display structure has pointers to these */
+
+struct _XConnectionInfo {      /* info from _XRegisterInternalConnection */
+    int fd;
+    _XInternalConnectionProc read_callback;
+    XPointer call_data;
+    XPointer *watch_data;      /* set/used by XConnectionWatchProc */
+    struct _XConnectionInfo *next;
+};
+
+struct _XConnWatchInfo {       /* info from XAddConnectionWatch */
+    XConnectionWatchProc fn;
+    XPointer client_data;
+    struct _XConnWatchInfo *next;
+};
+
+#ifdef __EMX__
+extern char* __XOS2RedirRoot(
+#if NeedFunctionPrototypes
+    char*
+#endif
+);
+#endif
+
+extern int _XTextHeight(
+#if NeedFunctionPrototypes
+    XFontStruct*       /* font_struct */,
+    _Xconst char*      /* string */,
+    int                        /* count */
+#endif
+);
+
+extern int _XTextHeight16(
+#if NeedFunctionPrototypes
+    XFontStruct*       /* font_struct */,
+    _Xconst XChar2b*   /* string */,
+    int                        /* count */
+#endif
+);
+
+_XFUNCPROTOEND
diff --git a/Xserver/lib/X11/Xlocale.h b/Xserver/lib/X11/Xlocale.h
new file mode 100644 (file)
index 0000000..8ce59a3
--- /dev/null
@@ -0,0 +1,72 @@
+/* $XConsortium: Xlocale.h,v 1.10 94/04/17 20:21:51 rws Exp $ */
+/*
+
+Copyright (c) 1991  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be included
+in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR
+OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall
+not be used in advertising or otherwise to promote the sale, use or
+other dealings in this Software without prior written authorization
+from the X Consortium.
+
+*/
+
+#ifndef _XLOCALE_H_
+#define _XLOCALE_H_
+
+#include <X11/Xfuncproto.h>
+#include <X11/Xosdefs.h>
+
+#ifndef X_LOCALE
+#ifdef X_NOT_STDC_ENV
+#define X_LOCALE
+#endif
+#endif
+
+#ifndef X_LOCALE
+#include <locale.h>
+#else
+
+#define LC_ALL      0
+#define LC_COLLATE  1
+#define LC_CTYPE    2
+#define LC_MONETARY 3
+#define LC_NUMERIC  4
+#define LC_TIME     5
+
+_XFUNCPROTOBEGIN
+extern char *_Xsetlocale(
+#if NeedFunctionPrototypes
+    int /* category */,
+    _Xconst char* /* name */
+#endif
+);
+_XFUNCPROTOEND
+
+#define setlocale _Xsetlocale
+
+#ifndef NULL
+#define NULL 0
+#endif
+
+#endif /* X_LOCALE */
+
+#endif /* _XLOCALE_H_ */
diff --git a/Xserver/lib/X11/Xresource.h b/Xserver/lib/X11/Xresource.h
new file mode 100644 (file)
index 0000000..3138a24
--- /dev/null
@@ -0,0 +1,413 @@
+/* $XConsortium: Xresource.h /main/38 1996/10/22 14:24:34 kaleb $ */
+/* $XFree86: xc/lib/X11/Xresource.h,v 3.1 1996/12/23 05:59:51 dawes Exp $ */
+
+/***********************************************************
+
+Copyright (c) 1987, 1988  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+
+Copyright 1987, 1988 by Digital Equipment Corporation, Maynard, Massachusetts.
+
+                        All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and its 
+documentation for any purpose and without fee is hereby granted, 
+provided that the above copyright notice appear in all copies and that
+both that copyright notice and this permission notice appear in 
+supporting documentation, and that the name of Digital not be
+used in advertising or publicity pertaining to distribution of the
+software without specific, written prior permission.  
+
+DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
+ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
+DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
+ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+SOFTWARE.
+
+******************************************************************/
+
+#ifndef _XRESOURCE_H_
+#define _XRESOURCE_H_
+
+/* You must include <X11/Xlib.h> before including this file */
+
+/****************************************************************
+ ****************************************************************
+ ***                                                          ***
+ ***                                                          ***
+ ***          X Resource Manager Intrinsics                   ***
+ ***                                                          ***
+ ***                                                          ***
+ ****************************************************************
+ ****************************************************************/
+
+_XFUNCPROTOBEGIN
+
+/****************************************************************
+ *
+ * Memory Management
+ *
+ ****************************************************************/
+
+extern char *Xpermalloc(
+#if NeedFunctionPrototypes
+    unsigned int       /* size */
+#endif
+);
+
+/****************************************************************
+ *
+ * Quark Management
+ *
+ ****************************************************************/
+
+typedef int     XrmQuark, *XrmQuarkList;
+#define NULLQUARK ((XrmQuark) 0)
+
+typedef char *XrmString;
+#define NULLSTRING ((XrmString) 0)
+
+/* find quark for string, create new quark if none already exists */
+extern XrmQuark XrmStringToQuark(
+#if NeedFunctionPrototypes
+    _Xconst char*      /* string */
+#endif
+);
+
+extern XrmQuark XrmPermStringToQuark(
+#if NeedFunctionPrototypes
+    _Xconst char*      /* string */
+#endif
+);
+
+/* find string for quark */
+extern XrmString XrmQuarkToString(
+#if NeedFunctionPrototypes
+    XrmQuark           /* quark */
+#endif
+);
+
+extern XrmQuark XrmUniqueQuark(
+#if NeedFunctionPrototypes
+    void
+#endif
+);
+
+#define XrmStringsEqual(a1, a2) (strcmp(a1, a2) == 0)
+
+
+/****************************************************************
+ *
+ * Conversion of Strings to Lists
+ *
+ ****************************************************************/
+
+typedef enum {XrmBindTightly, XrmBindLoosely} XrmBinding, *XrmBindingList;
+
+extern void XrmStringToQuarkList(
+#if NeedFunctionPrototypes
+    _Xconst char*      /* string */,
+    XrmQuarkList       /* quarks_return */
+#endif
+);
+
+extern void XrmStringToBindingQuarkList(
+#if NeedFunctionPrototypes
+    _Xconst char*      /* string */,
+    XrmBindingList     /* bindings_return */,
+    XrmQuarkList       /* quarks_return */
+#endif
+);
+
+/****************************************************************
+ *
+ * Name and Class lists.
+ *
+ ****************************************************************/
+
+typedef XrmQuark     XrmName;
+typedef XrmQuarkList XrmNameList;
+#define XrmNameToString(name)          XrmQuarkToString(name)
+#define XrmStringToName(string)                XrmStringToQuark(string)
+#define XrmStringToNameList(str, name) XrmStringToQuarkList(str, name)
+
+typedef XrmQuark     XrmClass;
+typedef XrmQuarkList XrmClassList;
+#define XrmClassToString(c_class)      XrmQuarkToString(c_class)
+#define XrmStringToClass(c_class)      XrmStringToQuark(c_class)
+#define XrmStringToClassList(str,c_class) XrmStringToQuarkList(str, c_class)
+
+
+
+/****************************************************************
+ *
+ * Resource Representation Types and Values
+ *
+ ****************************************************************/
+
+typedef XrmQuark     XrmRepresentation;
+#define XrmStringToRepresentation(string)   XrmStringToQuark(string)
+#define        XrmRepresentationToString(type)   XrmQuarkToString(type)
+
+typedef struct {
+    unsigned int    size;
+    XPointer       addr;
+} XrmValue, *XrmValuePtr;
+
+
+/****************************************************************
+ *
+ * Resource Manager Functions
+ *
+ ****************************************************************/
+
+typedef struct _XrmHashBucketRec *XrmHashBucket;
+typedef XrmHashBucket *XrmHashTable;
+typedef XrmHashTable XrmSearchList[];
+typedef struct _XrmHashBucketRec *XrmDatabase;
+
+
+extern void XrmDestroyDatabase(
+#if NeedFunctionPrototypes
+    XrmDatabase                /* database */    
+#endif
+);
+
+extern void XrmQPutResource(
+#if NeedFunctionPrototypes
+    XrmDatabase*       /* database */,
+    XrmBindingList     /* bindings */,
+    XrmQuarkList       /* quarks */,
+    XrmRepresentation  /* type */,
+    XrmValue*          /* value */
+#endif
+);
+
+extern void XrmPutResource(
+#if NeedFunctionPrototypes
+    XrmDatabase*       /* database */,
+    _Xconst char*      /* specifier */,
+    _Xconst char*      /* type */,
+    XrmValue*          /* value */
+#endif
+);
+
+extern void XrmQPutStringResource(
+#if NeedFunctionPrototypes
+    XrmDatabase*       /* database */,
+    XrmBindingList      /* bindings */,
+    XrmQuarkList       /* quarks */,
+    _Xconst char*      /* value */
+#endif
+);
+
+extern void XrmPutStringResource(
+#if NeedFunctionPrototypes
+    XrmDatabase*       /* database */,
+    _Xconst char*      /* specifier */,
+    _Xconst char*      /* value */
+#endif
+);
+
+extern void XrmPutLineResource(
+#if NeedFunctionPrototypes
+    XrmDatabase*       /* database */,
+    _Xconst char*      /* line */
+#endif
+);
+
+extern Bool XrmQGetResource(
+#if NeedFunctionPrototypes
+    XrmDatabase                /* database */,
+    XrmNameList                /* quark_name */,
+    XrmClassList       /* quark_class */,
+    XrmRepresentation* /* quark_type_return */,
+    XrmValue*          /* value_return */
+#endif
+);
+
+extern Bool XrmGetResource(
+#if NeedFunctionPrototypes
+    XrmDatabase                /* database */,
+    _Xconst char*      /* str_name */,
+    _Xconst char*      /* str_class */,
+    char**             /* str_type_return */,
+    XrmValue*          /* value_return */
+#endif
+);
+
+extern Bool XrmQGetSearchList(
+#if NeedFunctionPrototypes
+    XrmDatabase                /* database */,
+    XrmNameList                /* names */,
+    XrmClassList       /* classes */,
+    XrmSearchList      /* list_return */,
+    int                        /* list_length */
+#endif
+);
+
+extern Bool XrmQGetSearchResource(
+#if NeedFunctionPrototypes
+    XrmSearchList      /* list */,
+    XrmName            /* name */,
+    XrmClass           /* class */,
+    XrmRepresentation* /* type_return */,
+    XrmValue*          /* value_return */
+#endif
+);
+
+/****************************************************************
+ *
+ * Resource Database Management
+ *
+ ****************************************************************/
+
+extern void XrmSetDatabase(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    XrmDatabase                /* database */
+#endif
+);
+
+extern XrmDatabase XrmGetDatabase(
+#if NeedFunctionPrototypes
+    Display*           /* display */
+#endif
+);
+
+extern XrmDatabase XrmGetFileDatabase(
+#if NeedFunctionPrototypes
+    _Xconst char*      /* filename */
+#endif
+);
+
+extern Status XrmCombineFileDatabase(
+#if NeedFunctionPrototypes
+    _Xconst char*      /* filename */,
+    XrmDatabase*       /* target */,
+    Bool               /* override */
+#endif
+);
+
+extern XrmDatabase XrmGetStringDatabase(
+#if NeedFunctionPrototypes
+    _Xconst char*      /* data */  /*  null terminated string */
+#endif
+);
+
+extern void XrmPutFileDatabase(
+#if NeedFunctionPrototypes
+    XrmDatabase                /* database */,
+    _Xconst char*      /* filename */
+#endif
+);
+
+extern void XrmMergeDatabases(
+#if NeedFunctionPrototypes
+    XrmDatabase                /* source_db */,
+    XrmDatabase*       /* target_db */
+#endif
+);
+
+extern void XrmCombineDatabase(
+#if NeedFunctionPrototypes
+    XrmDatabase                /* source_db */,
+    XrmDatabase*       /* target_db */,
+    Bool               /* override */
+#endif
+);
+
+#define XrmEnumAllLevels 0
+#define XrmEnumOneLevel  1
+
+extern Bool XrmEnumerateDatabase(
+#if NeedFunctionPrototypes
+    XrmDatabase                /* db */,
+    XrmNameList                /* name_prefix */,
+    XrmClassList       /* class_prefix */,
+    int                        /* mode */,
+    Bool (*)(
+#if NeedNestedPrototypes
+            XrmDatabase*       /* db */,
+            XrmBindingList     /* bindings */,
+            XrmQuarkList       /* quarks */,
+            XrmRepresentation* /* type */,
+            XrmValue*          /* value */,
+            XPointer           /* closure */
+#endif
+            )          /* proc */,
+    XPointer           /* closure */
+#endif
+);
+
+extern char *XrmLocaleOfDatabase(
+#if NeedFunctionPrototypes
+    XrmDatabase        /* database */
+#endif
+);
+
+
+/****************************************************************
+ *
+ * Command line option mapping to resource entries
+ *
+ ****************************************************************/
+
+typedef enum {
+    XrmoptionNoArg,    /* Value is specified in OptionDescRec.value        */
+    XrmoptionIsArg,     /* Value is the option string itself               */
+    XrmoptionStickyArg, /* Value is characters immediately following option */
+    XrmoptionSepArg,    /* Value is next argument in argv                  */
+    XrmoptionResArg,   /* Resource and value in next argument in argv      */
+    XrmoptionSkipArg,   /* Ignore this option and the next argument in argv */
+    XrmoptionSkipLine,  /* Ignore this option and the rest of argv         */
+    XrmoptionSkipNArgs /* Ignore this option and the next 
+                          OptionDescRes.value arguments in argv */
+} XrmOptionKind;
+
+typedef struct {
+    char           *option;        /* Option abbreviation in argv          */
+    char           *specifier;     /* Resource specifier                   */
+    XrmOptionKind   argKind;       /* Which style of option it is          */
+    XPointer       value;          /* Value to provide if XrmoptionNoArg   */
+} XrmOptionDescRec, *XrmOptionDescList;
+
+
+extern void XrmParseCommand(
+#if NeedFunctionPrototypes
+    XrmDatabase*       /* database */,
+    XrmOptionDescList  /* table */,
+    int                        /* table_count */,
+    _Xconst char*      /* name */,
+    int*               /* argc_in_out */,
+    char**             /* argv_in_out */                    
+#endif
+);
+
+_XFUNCPROTOEND
+
+#endif /* _XRESOURCE_H_ */
+/* DON'T ADD STUFF AFTER THIS #endif */
diff --git a/Xserver/lib/X11/Xutil.h b/Xserver/lib/X11/Xutil.h
new file mode 100644 (file)
index 0000000..0ad1e84
--- /dev/null
@@ -0,0 +1,908 @@
+/* $XConsortium: Xutil.h,v 11.78 94/04/17 20:21:56 rws Exp $ */
+/* $XFree86: xc/lib/X11/Xutil.h,v 3.0 1996/12/09 11:49:36 dawes Exp $ */
+
+/***********************************************************
+
+Copyright (c) 1987  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+
+Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
+
+                        All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and its 
+documentation for any purpose and without fee is hereby granted, 
+provided that the above copyright notice appear in all copies and that
+both that copyright notice and this permission notice appear in 
+supporting documentation, and that the name of Digital not be
+used in advertising or publicity pertaining to distribution of the
+software without specific, written prior permission.  
+
+DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
+ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
+DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
+ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+SOFTWARE.
+
+******************************************************************/
+
+#ifndef _XUTIL_H_
+#define _XUTIL_H_
+
+/* You must include <X11/Xlib.h> before including this file */
+
+/* 
+ * Bitmask returned by XParseGeometry().  Each bit tells if the corresponding
+ * value (x, y, width, height) was found in the parsed string.
+ */
+#define NoValue                0x0000
+#define XValue         0x0001
+#define YValue         0x0002
+#define WidthValue     0x0004
+#define HeightValue    0x0008
+#define AllValues      0x000F
+#define XNegative      0x0010
+#define YNegative      0x0020
+
+/*
+ * new version containing base_width, base_height, and win_gravity fields;
+ * used with WM_NORMAL_HINTS.
+ */
+typedef struct {
+       long flags;     /* marks which fields in this structure are defined */
+       int x, y;               /* obsolete for new window mgrs, but clients */
+       int width, height;      /* should set so old wm's don't mess up */
+       int min_width, min_height;
+       int max_width, max_height;
+       int width_inc, height_inc;
+       struct {
+               int x;  /* numerator */
+               int y;  /* denominator */
+       } min_aspect, max_aspect;
+       int base_width, base_height;            /* added by ICCCM version 1 */
+       int win_gravity;                        /* added by ICCCM version 1 */
+} XSizeHints;
+
+/*
+ * The next block of definitions are for window manager properties that
+ * clients and applications use for communication.
+ */
+
+/* flags argument in size hints */
+#define USPosition     (1L << 0) /* user specified x, y */
+#define USSize         (1L << 1) /* user specified width, height */
+
+#define PPosition      (1L << 2) /* program specified position */
+#define PSize          (1L << 3) /* program specified size */
+#define PMinSize       (1L << 4) /* program specified minimum size */
+#define PMaxSize       (1L << 5) /* program specified maximum size */
+#define PResizeInc     (1L << 6) /* program specified resize increments */
+#define PAspect                (1L << 7) /* program specified min and max aspect ratios */
+#define PBaseSize      (1L << 8) /* program specified base for incrementing */
+#define PWinGravity    (1L << 9) /* program specified window gravity */
+
+/* obsolete */
+#define PAllHints (PPosition|PSize|PMinSize|PMaxSize|PResizeInc|PAspect)
+
+
+
+typedef struct {
+       long flags;     /* marks which fields in this structure are defined */
+       Bool input;     /* does this application rely on the window manager to
+                       get keyboard input? */
+       int initial_state;      /* see below */
+       Pixmap icon_pixmap;     /* pixmap to be used as icon */
+       Window icon_window;     /* window to be used as icon */
+       int icon_x, icon_y;     /* initial position of icon */
+       Pixmap icon_mask;       /* icon mask bitmap */
+       XID window_group;       /* id of related window group */
+       /* this structure may be extended in the future */
+} XWMHints;
+
+/* definition for flags of XWMHints */
+
+#define InputHint              (1L << 0)
+#define StateHint              (1L << 1)
+#define IconPixmapHint         (1L << 2)
+#define IconWindowHint         (1L << 3)
+#define IconPositionHint       (1L << 4)
+#define IconMaskHint           (1L << 5)
+#define WindowGroupHint                (1L << 6)
+#define AllHints (InputHint|StateHint|IconPixmapHint|IconWindowHint| \
+IconPositionHint|IconMaskHint|WindowGroupHint)
+#define XUrgencyHint           (1L << 8)
+
+/* definitions for initial window state */
+#define WithdrawnState 0       /* for windows that are not mapped */
+#define NormalState 1  /* most applications want to start this way */
+#define IconicState 3  /* application wants to start as an icon */
+
+/*
+ * Obsolete states no longer defined by ICCCM
+ */
+#define DontCareState 0        /* don't know or care */
+#define ZoomState 2    /* application wants to start zoomed */
+#define InactiveState 4        /* application believes it is seldom used; */
+                       /* some wm's may put it on inactive menu */
+
+
+/*
+ * new structure for manipulating TEXT properties; used with WM_NAME, 
+ * WM_ICON_NAME, WM_CLIENT_MACHINE, and WM_COMMAND.
+ */
+typedef struct {
+    unsigned char *value;              /* same as Property routines */
+    Atom encoding;                     /* prop type */
+    int format;                                /* prop data format: 8, 16, or 32 */
+    unsigned long nitems;              /* number of data items in value */
+} XTextProperty;
+
+#define XNoMemory -1
+#define XLocaleNotSupported -2
+#define XConverterNotFound -3
+
+typedef enum {
+    XStringStyle,              /* STRING */
+    XCompoundTextStyle,                /* COMPOUND_TEXT */
+    XTextStyle,                        /* text in owner's encoding (current locale)*/
+    XStdICCTextStyle           /* STRING, else COMPOUND_TEXT */
+} XICCEncodingStyle;
+
+typedef struct {
+       int min_width, min_height;
+       int max_width, max_height;
+       int width_inc, height_inc;
+} XIconSize;
+
+typedef struct {
+       char *res_name;
+       char *res_class;
+} XClassHint;
+
+/*
+ * These macros are used to give some sugar to the image routines so that
+ * naive people are more comfortable with them.
+ */
+#define XDestroyImage(ximage) \
+       ((*((ximage)->f.destroy_image))((ximage)))
+#define XGetPixel(ximage, x, y) \
+       ((*((ximage)->f.get_pixel))((ximage), (x), (y)))
+#define XPutPixel(ximage, x, y, pixel) \
+       ((*((ximage)->f.put_pixel))((ximage), (x), (y), (pixel)))
+#define XSubImage(ximage, x, y, width, height)  \
+       ((*((ximage)->f.sub_image))((ximage), (x), (y), (width), (height)))
+#define XAddPixel(ximage, value) \
+       ((*((ximage)->f.add_pixel))((ximage), (value)))
+
+/*
+ * Compose sequence status structure, used in calling XLookupString.
+ */
+typedef struct _XComposeStatus {
+    XPointer compose_ptr;      /* state table pointer */
+    int chars_matched;         /* match state */
+} XComposeStatus;
+
+/*
+ * Keysym macros, used on Keysyms to test for classes of symbols
+ */
+#define IsKeypadKey(keysym) \
+  (((KeySym)(keysym) >= XK_KP_Space) && ((KeySym)(keysym) <= XK_KP_Equal))
+
+#define IsPrivateKeypadKey(keysym) \
+  (((KeySym)(keysym) >= 0x11000000) && ((KeySym)(keysym) <= 0x1100FFFF))
+
+#define IsCursorKey(keysym) \
+  (((KeySym)(keysym) >= XK_Home)     && ((KeySym)(keysym) <  XK_Select))
+
+#define IsPFKey(keysym) \
+  (((KeySym)(keysym) >= XK_KP_F1)     && ((KeySym)(keysym) <= XK_KP_F4))
+
+#define IsFunctionKey(keysym) \
+  (((KeySym)(keysym) >= XK_F1)       && ((KeySym)(keysym) <= XK_F35))
+
+#define IsMiscFunctionKey(keysym) \
+  (((KeySym)(keysym) >= XK_Select)   && ((KeySym)(keysym) <= XK_Break))
+
+#define IsModifierKey(keysym) \
+  ((((KeySym)(keysym) >= XK_Shift_L) && ((KeySym)(keysym) <= XK_Hyper_R)) \
+   || ((KeySym)(keysym) == XK_Mode_switch) \
+   || ((KeySym)(keysym) == XK_Num_Lock))
+/*
+ * opaque reference to Region data type 
+ */
+typedef struct _XRegion *Region; 
+
+/* Return values from XRectInRegion() */
+#define RectangleOut 0
+#define RectangleIn  1
+#define RectanglePart 2
+
+/*
+ * Information used by the visual utility routines to find desired visual
+ * type from the many visuals a display may support.
+ */
+
+typedef struct {
+  Visual *visual;
+  VisualID visualid;
+  int screen;
+  int depth;
+#if defined(__cplusplus) || defined(c_plusplus)
+  int c_class;                                 /* C++ */
+#else
+  int class;
+#endif
+  unsigned long red_mask;
+  unsigned long green_mask;
+  unsigned long blue_mask;
+  int colormap_size;
+  int bits_per_rgb;
+} XVisualInfo;
+
+#define VisualNoMask           0x0
+#define VisualIDMask           0x1
+#define VisualScreenMask       0x2
+#define VisualDepthMask                0x4
+#define VisualClassMask                0x8
+#define VisualRedMaskMask      0x10
+#define VisualGreenMaskMask    0x20
+#define VisualBlueMaskMask     0x40
+#define VisualColormapSizeMask 0x80
+#define VisualBitsPerRGBMask   0x100
+#define VisualAllMask          0x1FF
+
+/*
+ * This defines a window manager property that clients may use to
+ * share standard color maps of type RGB_COLOR_MAP:
+ */
+typedef struct {
+       Colormap colormap;
+       unsigned long red_max;
+       unsigned long red_mult;
+       unsigned long green_max;
+       unsigned long green_mult;
+       unsigned long blue_max;
+       unsigned long blue_mult;
+       unsigned long base_pixel;
+       VisualID visualid;              /* added by ICCCM version 1 */
+       XID killid;                     /* added by ICCCM version 1 */
+} XStandardColormap;
+
+#define ReleaseByFreeingColormap ((XID) 1L)  /* for killid field above */
+
+
+/*
+ * return codes for XReadBitmapFile and XWriteBitmapFile
+ */
+#define BitmapSuccess          0
+#define BitmapOpenFailed       1
+#define BitmapFileInvalid      2
+#define BitmapNoMemory         3
+
+/****************************************************************
+ *
+ * Context Management
+ *
+ ****************************************************************/
+
+
+/* Associative lookup table return codes */
+
+#define XCSUCCESS 0    /* No error. */
+#define XCNOMEM   1    /* Out of memory */
+#define XCNOENT   2    /* No entry in table */
+
+typedef int XContext;
+
+#define XUniqueContext()       ((XContext) XrmUniqueQuark())
+#define XStringToContext(string)   ((XContext) XrmStringToQuark(string))
+
+_XFUNCPROTOBEGIN
+
+/* The following declarations are alphabetized. */
+
+extern XClassHint *XAllocClassHint (
+#if NeedFunctionPrototypes
+    void
+#endif
+);
+
+extern XIconSize *XAllocIconSize (
+#if NeedFunctionPrototypes
+    void
+#endif
+);
+
+extern XSizeHints *XAllocSizeHints (
+#if NeedFunctionPrototypes
+    void
+#endif
+);
+
+extern XStandardColormap *XAllocStandardColormap (
+#if NeedFunctionPrototypes
+    void
+#endif
+);
+
+extern XWMHints *XAllocWMHints (
+#if NeedFunctionPrototypes
+    void
+#endif
+);
+
+extern int XClipBox(
+#if NeedFunctionPrototypes
+    Region             /* r */,
+    XRectangle*                /* rect_return */
+#endif
+);
+
+extern Region XCreateRegion(
+#if NeedFunctionPrototypes
+    void
+#endif
+);
+
+extern char *XDefaultString(
+#if NeedFunctionPrototypes
+    void
+#endif
+);
+
+extern int XDeleteContext(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    XID                        /* rid */,
+    XContext           /* context */
+#endif
+);
+
+extern int XDestroyRegion(
+#if NeedFunctionPrototypes
+    Region             /* r */
+#endif
+);
+
+extern int XEmptyRegion(
+#if NeedFunctionPrototypes
+    Region             /* r */
+#endif
+);
+
+extern int XEqualRegion(
+#if NeedFunctionPrototypes
+    Region             /* r1 */,
+    Region             /* r2 */
+#endif
+);
+
+extern int XFindContext(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    XID                        /* rid */,
+    XContext           /* context */,
+    XPointer*          /* data_return */
+#endif
+);
+
+extern Status XGetClassHint(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    Window             /* w */,
+    XClassHint*                /* class_hints_return */
+#endif
+);
+
+extern Status XGetIconSizes(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    Window             /* w */,
+    XIconSize**                /* size_list_return */,
+    int*               /* count_return */
+#endif
+);
+
+extern Status XGetNormalHints(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    Window             /* w */,
+    XSizeHints*                /* hints_return */
+#endif
+);
+
+extern Status XGetRGBColormaps(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    Window             /* w */,
+    XStandardColormap** /* stdcmap_return */,
+    int*               /* count_return */,
+    Atom               /* property */
+#endif
+);
+
+extern Status XGetSizeHints(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    Window             /* w */,
+    XSizeHints*                /* hints_return */,
+    Atom               /* property */
+#endif
+);
+
+extern Status XGetStandardColormap(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    Window             /* w */,
+    XStandardColormap* /* colormap_return */,
+    Atom               /* property */                      
+#endif
+);
+
+extern Status XGetTextProperty(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    Window             /* window */,
+    XTextProperty*     /* text_prop_return */,
+    Atom               /* property */
+#endif
+);
+
+extern XVisualInfo *XGetVisualInfo(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    long               /* vinfo_mask */,
+    XVisualInfo*       /* vinfo_template */,
+    int*               /* nitems_return */
+#endif
+);
+
+extern Status XGetWMClientMachine(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    Window             /* w */,
+    XTextProperty*     /* text_prop_return */
+#endif
+);
+
+extern XWMHints *XGetWMHints(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    Window             /* w */               
+#endif
+);
+
+extern Status XGetWMIconName(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    Window             /* w */,
+    XTextProperty*     /* text_prop_return */
+#endif
+);
+
+extern Status XGetWMName(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    Window             /* w */,
+    XTextProperty*     /* text_prop_return */
+#endif
+);
+
+extern Status XGetWMNormalHints(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    Window             /* w */,
+    XSizeHints*                /* hints_return */,
+    long*              /* supplied_return */ 
+#endif
+);
+
+extern Status XGetWMSizeHints(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    Window             /* w */,
+    XSizeHints*                /* hints_return */,
+    long*              /* supplied_return */,
+    Atom               /* property */
+#endif
+);
+
+extern Status XGetZoomHints(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    Window             /* w */,
+    XSizeHints*                /* zhints_return */
+#endif
+);
+
+extern int XIntersectRegion(
+#if NeedFunctionPrototypes
+    Region             /* sra */,
+    Region             /* srb */,
+    Region             /* dr_return */
+#endif
+);
+
+extern void XConvertCase(
+#if NeedFunctionPrototypes
+    KeySym             /* sym */,
+    KeySym*            /* lower */,
+    KeySym*            /* upper */
+#endif
+);
+
+extern int XLookupString(
+#if NeedFunctionPrototypes
+    XKeyEvent*         /* event_struct */,
+    char*              /* buffer_return */,
+    int                        /* bytes_buffer */,
+    KeySym*            /* keysym_return */,
+    XComposeStatus*    /* status_in_out */
+#endif
+);
+
+extern Status XMatchVisualInfo(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    int                        /* screen */,
+    int                        /* depth */,
+    int                        /* class */,
+    XVisualInfo*       /* vinfo_return */
+#endif
+);
+
+extern int XOffsetRegion(
+#if NeedFunctionPrototypes
+    Region             /* r */,
+    int                        /* dx */,
+    int                        /* dy */
+#endif
+);
+
+extern Bool XPointInRegion(
+#if NeedFunctionPrototypes
+    Region             /* r */,
+    int                        /* x */,
+    int                        /* y */
+#endif
+);
+
+extern Region XPolygonRegion(
+#if NeedFunctionPrototypes
+    XPoint*            /* points */,
+    int                        /* n */,
+    int                        /* fill_rule */
+#endif
+);
+
+extern int XRectInRegion(
+#if NeedFunctionPrototypes
+    Region             /* r */,
+    int                        /* x */,
+    int                        /* y */,
+    unsigned int       /* width */,
+    unsigned int       /* height */
+#endif
+);
+
+extern int XSaveContext(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    XID                        /* rid */,
+    XContext           /* context */,
+    _Xconst char*      /* data */
+#endif
+);
+
+extern int XSetClassHint(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    Window             /* w */,
+    XClassHint*                /* class_hints */
+#endif
+);
+
+extern int XSetIconSizes(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    Window             /* w */,
+    XIconSize*         /* size_list */,
+    int                        /* count */    
+#endif
+);
+
+extern int XSetNormalHints(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    Window             /* w */,
+    XSizeHints*                /* hints */
+#endif
+);
+
+extern void XSetRGBColormaps(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    Window             /* w */,
+    XStandardColormap* /* stdcmaps */,
+    int                        /* count */,
+    Atom               /* property */
+#endif
+);
+
+extern int XSetSizeHints(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    Window             /* w */,
+    XSizeHints*                /* hints */,
+    Atom               /* property */
+#endif
+);
+
+extern int XSetStandardProperties(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    Window             /* w */,
+    _Xconst char*      /* window_name */,
+    _Xconst char*      /* icon_name */,
+    Pixmap             /* icon_pixmap */,
+    char**             /* argv */,
+    int                        /* argc */,
+    XSizeHints*                /* hints */
+#endif
+);
+
+extern void XSetTextProperty(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    Window             /* w */,
+    XTextProperty*     /* text_prop */,
+    Atom               /* property */
+#endif
+);
+
+extern void XSetWMClientMachine(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    Window             /* w */,
+    XTextProperty*     /* text_prop */
+#endif
+);
+
+extern int XSetWMHints(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    Window             /* w */,
+    XWMHints*          /* wm_hints */
+#endif
+);
+
+extern void XSetWMIconName(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    Window             /* w */,
+    XTextProperty*     /* text_prop */
+#endif
+);
+
+extern void XSetWMName(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    Window             /* w */,
+    XTextProperty*     /* text_prop */
+#endif
+);
+
+extern void XSetWMNormalHints(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    Window             /* w */,
+    XSizeHints*                /* hints */
+#endif
+);
+
+extern void XSetWMProperties(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    Window             /* w */,
+    XTextProperty*     /* window_name */,
+    XTextProperty*     /* icon_name */,
+    char**             /* argv */,
+    int                        /* argc */,
+    XSizeHints*                /* normal_hints */,
+    XWMHints*          /* wm_hints */,
+    XClassHint*                /* class_hints */
+#endif
+);
+
+extern void XmbSetWMProperties(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    Window             /* w */,
+    _Xconst char*      /* window_name */,
+    _Xconst char*      /* icon_name */,
+    char**             /* argv */,
+    int                        /* argc */,
+    XSizeHints*                /* normal_hints */,
+    XWMHints*          /* wm_hints */,
+    XClassHint*                /* class_hints */
+#endif
+);
+
+extern void XSetWMSizeHints(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    Window             /* w */,
+    XSizeHints*                /* hints */,
+    Atom               /* property */
+#endif
+);
+
+extern int XSetRegion(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    GC                 /* gc */,
+    Region             /* r */
+#endif
+);
+
+extern void XSetStandardColormap(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    Window             /* w */,
+    XStandardColormap* /* colormap */,
+    Atom               /* property */
+#endif
+);
+
+extern int XSetZoomHints(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    Window             /* w */,
+    XSizeHints*                /* zhints */
+#endif
+);
+
+extern int XShrinkRegion(
+#if NeedFunctionPrototypes
+    Region             /* r */,
+    int                        /* dx */,
+    int                        /* dy */
+#endif
+);
+
+extern Status XStringListToTextProperty(
+#if NeedFunctionPrototypes
+    char**             /* list */,
+    int                        /* count */,
+    XTextProperty*     /* text_prop_return */
+#endif
+);
+
+extern int XSubtractRegion(
+#if NeedFunctionPrototypes
+    Region             /* sra */,
+    Region             /* srb */,
+    Region             /* dr_return */
+#endif
+);
+
+extern int XmbTextListToTextProperty(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    char**             /* list */,
+    int                        /* count */,
+    XICCEncodingStyle  /* style */,
+    XTextProperty*     /* text_prop_return */
+#endif
+);
+
+extern int XwcTextListToTextProperty(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    wchar_t**          /* list */,
+    int                        /* count */,
+    XICCEncodingStyle  /* style */,
+    XTextProperty*     /* text_prop_return */
+#endif
+);
+
+extern void XwcFreeStringList(
+#if NeedFunctionPrototypes
+    wchar_t**          /* list */
+#endif
+);
+
+extern Status XTextPropertyToStringList(
+#if NeedFunctionPrototypes
+    XTextProperty*     /* text_prop */,
+    char***            /* list_return */,
+    int*               /* count_return */
+#endif
+);
+
+extern int XmbTextPropertyToTextList(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    XTextProperty*     /* text_prop */,
+    char***            /* list_return */,
+    int*               /* count_return */
+#endif
+);
+
+extern int XwcTextPropertyToTextList(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    XTextProperty*     /* text_prop */,
+    wchar_t***         /* list_return */,
+    int*               /* count_return */
+#endif
+);
+
+extern int XUnionRectWithRegion(
+#if NeedFunctionPrototypes
+    XRectangle*                /* rectangle */,
+    Region             /* src_region */,
+    Region             /* dest_region_return */
+#endif
+);
+
+extern int XUnionRegion(
+#if NeedFunctionPrototypes
+    Region             /* sra */,
+    Region             /* srb */,
+    Region             /* dr_return */
+#endif
+);
+
+extern int XWMGeometry(
+#if NeedFunctionPrototypes
+    Display*           /* display */,
+    int                        /* screen_number */,
+    _Xconst char*      /* user_geometry */,
+    _Xconst char*      /* default_geometry */,
+    unsigned int       /* border_width */,
+    XSizeHints*                /* hints */,
+    int*               /* x_return */,
+    int*               /* y_return */,
+    int*               /* width_return */,
+    int*               /* height_return */,
+    int*               /* gravity_return */
+#endif
+);
+
+extern int XXorRegion(
+#if NeedFunctionPrototypes
+    Region             /* sra */,
+    Region             /* srb */,
+    Region             /* dr_return */
+#endif
+);
+
+_XFUNCPROTOEND
+
+#endif /* _XUTIL_H_ */
diff --git a/Xserver/lib/X11/cursorfont.h b/Xserver/lib/X11/cursorfont.h
new file mode 100644 (file)
index 0000000..9143efc
--- /dev/null
@@ -0,0 +1,109 @@
+/* $XConsortium: cursorfont.h,v 1.4 94/04/17 20:22:00 rws Exp $ */
+/*
+
+Copyright (c) 1987  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be included
+in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR
+OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall
+not be used in advertising or otherwise to promote the sale, use or
+other dealings in this Software without prior written authorization
+from the X Consortium.
+
+*/
+
+#define XC_num_glyphs 154
+#define XC_X_cursor 0
+#define XC_arrow 2
+#define XC_based_arrow_down 4
+#define XC_based_arrow_up 6
+#define XC_boat 8
+#define XC_bogosity 10
+#define XC_bottom_left_corner 12
+#define XC_bottom_right_corner 14
+#define XC_bottom_side 16
+#define XC_bottom_tee 18
+#define XC_box_spiral 20
+#define XC_center_ptr 22
+#define XC_circle 24
+#define XC_clock 26
+#define XC_coffee_mug 28
+#define XC_cross 30
+#define XC_cross_reverse 32
+#define XC_crosshair 34
+#define XC_diamond_cross 36
+#define XC_dot 38
+#define XC_dotbox 40
+#define XC_double_arrow 42
+#define XC_draft_large 44
+#define XC_draft_small 46
+#define XC_draped_box 48
+#define XC_exchange 50
+#define XC_fleur 52
+#define XC_gobbler 54
+#define XC_gumby 56
+#define XC_hand1 58
+#define XC_hand2 60
+#define XC_heart 62
+#define XC_icon 64
+#define XC_iron_cross 66
+#define XC_left_ptr 68
+#define XC_left_side 70
+#define XC_left_tee 72
+#define XC_leftbutton 74
+#define XC_ll_angle 76
+#define XC_lr_angle 78
+#define XC_man 80
+#define XC_middlebutton 82
+#define XC_mouse 84
+#define XC_pencil 86
+#define XC_pirate 88
+#define XC_plus 90
+#define XC_question_arrow 92
+#define XC_right_ptr 94
+#define XC_right_side 96
+#define XC_right_tee 98
+#define XC_rightbutton 100
+#define XC_rtl_logo 102
+#define XC_sailboat 104
+#define XC_sb_down_arrow 106
+#define XC_sb_h_double_arrow 108
+#define XC_sb_left_arrow 110
+#define XC_sb_right_arrow 112
+#define XC_sb_up_arrow 114
+#define XC_sb_v_double_arrow 116
+#define XC_shuttle 118
+#define XC_sizing 120
+#define XC_spider 122
+#define XC_spraycan 124
+#define XC_star 126
+#define XC_target 128
+#define XC_tcross 130
+#define XC_top_left_arrow 132
+#define XC_top_left_corner 134
+#define XC_top_right_corner 136
+#define XC_top_side 138
+#define XC_top_tee 140
+#define XC_trek 142
+#define XC_ul_angle 144
+#define XC_umbrella 146
+#define XC_ur_angle 148
+#define XC_watch 150
+#define XC_xterm 152
diff --git a/Xserver/lib/Xau/AuDispose.c b/Xserver/lib/Xau/AuDispose.c
new file mode 100644 (file)
index 0000000..23b4525
--- /dev/null
@@ -0,0 +1,47 @@
+/* $XConsortium: AuDispose.c,v 1.5 95/07/10 21:18:07 gildea Exp $ */
+
+/*
+
+Copyright (c) 1988  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+*/
+
+#include <X11/Xauth.h>
+
+void
+XauDisposeAuth (auth)
+Xauth  *auth;
+{
+    if (auth) {
+       if (auth->address) (void) free (auth->address);
+       if (auth->number) (void) free (auth->number);
+       if (auth->name) (void) free (auth->name);
+       if (auth->data) {
+           (void) bzero (auth->data, auth->data_length);
+           (void) free (auth->data);
+       }
+       free ((char *) auth);
+    }
+    return;
+}
diff --git a/Xserver/lib/Xau/AuFileName.c b/Xserver/lib/Xau/AuFileName.c
new file mode 100644 (file)
index 0000000..08cc697
--- /dev/null
@@ -0,0 +1,78 @@
+/* $XConsortium: AuFileName.c /main/8 1996/09/28 16:43:20 rws $ */
+/* $XFree86: xc/lib/Xau/AuFileName.c,v 3.2 1996/12/24 08:46:53 dawes Exp $ */
+
+/*
+
+Copyright (c) 1988  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+*/
+
+#include <X11/Xauth.h>
+#include <X11/Xos.h>
+
+#ifdef X_NOT_STDC_ENV
+char *malloc (), *getenv ();
+#else
+#include <stdlib.h>
+#endif
+
+char *
+XauFileName ()
+{
+    char *slashDotXauthority = "/.Xauthority";
+    char    *name;
+    static char        *buf;
+    static int bsize;
+#ifdef WIN32
+    char    dir[128];
+#endif
+    int            size;
+
+    if (name = getenv ("XAUTHORITY"))
+       return name;
+    name = getenv ("HOME");
+    if (!name) {
+#ifdef WIN32
+       (void) strcpy (dir, "/users/");
+       if (name = getenv("USERNAME")) {
+           (void) strcat (dir, name);
+           name = dir;
+       }
+       if (!name)
+#endif
+       return 0;
+    }
+    size = strlen (name) + strlen(&slashDotXauthority[1]) + 2;
+    if (size > bsize) {
+       if (buf)
+           free (buf);
+       buf = malloc ((unsigned) size);
+       if (!buf)
+           return 0;
+       bsize = size;
+    }
+    strcpy (buf, name);
+    strcat (buf, slashDotXauthority + (name[1] == '\0' ? 1 : 0));
+    return buf;
+}
diff --git a/Xserver/lib/Xau/AuGetAddr.c b/Xserver/lib/Xau/AuGetAddr.c
new file mode 100644 (file)
index 0000000..ae0ad53
--- /dev/null
@@ -0,0 +1,127 @@
+/* $XConsortium: AuGetAddr.c,v 1.13 94/04/17 20:15:43 rws Exp $ */
+
+/*
+
+Copyright (c) 1988  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+*/
+
+#include <X11/Xauth.h>
+#include <X11/Xos.h>
+
+static
+binaryEqual (a, b, len)
+register char  *a, *b;
+register int   len;
+{
+    while (len--)
+       if (*a++ != *b++)
+           return 0;
+    return 1;
+}
+
+#if NeedFunctionPrototypes
+Xauth *
+XauGetAuthByAddr (
+#if NeedWidePrototypes
+unsigned int   family,
+unsigned int   address_length,
+#else
+unsigned short family,
+unsigned short address_length,
+#endif
+_Xconst char*  address,
+#if NeedWidePrototypes
+unsigned int   number_length,
+#else
+unsigned short number_length,
+#endif
+_Xconst char*  number,
+#if NeedWidePrototypes
+unsigned int   name_length,
+#else
+unsigned short name_length,
+#endif
+_Xconst char*  name)
+#else
+Xauth *
+XauGetAuthByAddr (family, address_length, address,
+                         number_length, number,
+                         name_length, name)
+unsigned short family;
+unsigned short address_length;
+char   *address;
+unsigned short number_length;
+char   *number;
+unsigned short name_length;
+char   *name;
+#endif
+{
+    FILE    *auth_file;
+    char    *auth_name;
+    Xauth   *entry;
+
+    auth_name = XauFileName ();
+    if (!auth_name)
+       return 0;
+    if (access (auth_name, R_OK) != 0)         /* checks REAL id */
+       return 0;
+    auth_file = fopen (auth_name, "rb");
+    if (!auth_file)
+       return 0;
+    for (;;) {
+       entry = XauReadAuth (auth_file);
+       if (!entry)
+           break;
+       /*
+        * Match when:
+        *   either family or entry->family are FamilyWild or
+        *    family and entry->family are the same
+        *  and
+        *   either address or entry->address are empty or
+        *    address and entry->address are the same
+        *  and
+        *   either number or entry->number are empty or
+        *    number and entry->number are the same
+        *  and
+        *   either name or entry->name are empty or
+        *    name and entry->name are the same
+        */
+
+       if ((family == FamilyWild || entry->family == FamilyWild ||
+            (entry->family == family &&
+             address_length == entry->address_length &&
+             binaryEqual (entry->address, address, (int)address_length))) &&
+           (number_length == 0 || entry->number_length == 0 ||
+            (number_length == entry->number_length &&
+             binaryEqual (entry->number, number, (int)number_length))) &&
+           (name_length == 0 || entry->name_length == 0 ||
+            (entry->name_length == name_length &&
+             binaryEqual (entry->name, name, (int)name_length))))
+           break;
+       XauDisposeAuth (entry);
+    }
+    (void) fclose (auth_file);
+    return entry;
+}
diff --git a/Xserver/lib/Xau/AuGetBest.c b/Xserver/lib/Xau/AuGetBest.c
new file mode 100644 (file)
index 0000000..cddad46
--- /dev/null
@@ -0,0 +1,187 @@
+/* $XConsortium: AuGetBest.c /main/23 1996/12/04 11:04:55 lehors $ */
+
+/*
+
+Copyright (c) 1988  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+*/
+
+#include <X11/Xauth.h>
+#include <X11/Xos.h>
+#ifdef XTHREADS
+#include <X11/Xthreads.h>
+#endif
+#ifdef hpux
+#define X_INCLUDE_NETDB_H
+#define XOS_USE_NO_LOCKING
+#include <X11/Xos_r.h>
+#endif
+
+static
+binaryEqual (a, b, len)
+register char  *a, *b;
+register int   len;
+{
+    while (len--)
+       if (*a++ != *b++)
+           return 0;
+    return 1;
+}
+
+#if NeedFunctionPrototypes
+Xauth *
+XauGetBestAuthByAddr (
+#if NeedWidePrototypes
+    unsigned int       family,
+    unsigned int       address_length,
+#else
+    unsigned short     family,
+    unsigned short     address_length,
+#endif
+    _Xconst char*      address,
+#if NeedWidePrototypes
+    unsigned int       number_length,
+#else
+    unsigned short     number_length,
+#endif
+    _Xconst char*      number,
+    int                        types_length,
+    char**             types,
+    _Xconst int*       type_lengths)
+#else
+Xauth *
+XauGetBestAuthByAddr (family, address_length, address,
+                         number_length, number,
+                         types_length, types, type_lengths)
+    unsigned short     family;
+    unsigned short     address_length;
+    char               *address;
+    unsigned short     number_length;
+    char               *number;
+    int                        types_length;
+    char               **types;
+    int                        *type_lengths;
+#endif
+{
+    FILE    *auth_file;
+    char    *auth_name;
+    Xauth   *entry;
+    Xauth   *best;
+    int            best_type;
+    int            type;
+#ifdef hpux
+    char               *fully_qual_address;
+    unsigned short     fully_qual_address_length;
+#endif
+
+    auth_name = XauFileName ();
+    if (!auth_name)
+       return 0;
+    if (access (auth_name, R_OK) != 0)         /* checks REAL id */
+       return 0;
+    auth_file = fopen (auth_name, "rb");
+    if (!auth_file)
+       return 0;
+
+#ifdef hpux
+    if (family == FamilyLocal) {
+       _Xgethostbynameparams hparams;
+       struct hostent *hostp;
+
+       /* make sure we try fully-qualified hostname */
+       if ((hostp = _XGethostbyname(address,hparams)) != NULL) {
+           fully_qual_address = hostp->h_name;
+           fully_qual_address_length = strlen(fully_qual_address);
+       }
+       else
+       {
+           fully_qual_address = NULL;
+           fully_qual_address_length = 0;
+       }
+    }
+#endif /* hpux */
+
+    best = 0;
+    best_type = types_length;
+    for (;;) {
+       entry = XauReadAuth (auth_file);
+       if (!entry)
+           break;
+       /*
+        * Match when:
+        *   either family or entry->family are FamilyWild or
+        *    family and entry->family are the same
+        *  and
+        *   either address or entry->address are empty or
+        *    address and entry->address are the same
+        *  and
+        *   either number or entry->number are empty or
+        *    number and entry->number are the same
+        *  and
+        *   name matches one of the specified names, or no names
+        *    were specified
+        */
+
+       if ((family == FamilyWild || entry->family == FamilyWild ||
+            (entry->family == family &&
+            ((address_length == entry->address_length &&
+             binaryEqual (entry->address, address, (int)address_length))
+#ifdef hpux
+            || (family == FamilyLocal &&
+               fully_qual_address_length == entry->address_length &&
+               binaryEqual (entry->address, fully_qual_address,
+                   (int) fully_qual_address_length))
+#endif
+           ))) &&
+           (number_length == 0 || entry->number_length == 0 ||
+            (number_length == entry->number_length &&
+             binaryEqual (entry->number, number, (int)number_length))))
+       {
+           if (best_type == 0)
+           {
+               best = entry;
+               break;
+           }
+           for (type = 0; type < best_type; type++)
+               if (type_lengths[type] == entry->name_length &&
+                   !(strncmp (types[type], entry->name, entry->name_length)))
+               {
+                   break;
+               }
+           if (type < best_type)
+           {
+               if (best)
+                   XauDisposeAuth (best);
+               best = entry;
+               best_type = type;
+               if (type == 0)
+                   break;
+               continue;
+           }
+       }
+       XauDisposeAuth (entry);
+    }
+    (void) fclose (auth_file);
+    return best;
+}
diff --git a/Xserver/lib/Xau/AuLock.c b/Xserver/lib/Xau/AuLock.c
new file mode 100644 (file)
index 0000000..3c2669e
--- /dev/null
@@ -0,0 +1,118 @@
+/* $XConsortium: AuLock.c,v 1.15 94/04/17 20:15:43 rws Exp $ */
+/* $XFree86: xc/lib/Xau/AuLock.c,v 3.0 1994/10/20 06:04:31 dawes Exp $ */
+
+/*
+
+Copyright (c) 1988  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+*/
+
+#include <X11/Xauth.h>
+#include <X11/Xos.h>
+#include <sys/stat.h>
+#include <errno.h>
+#if defined(X_NOT_STDC_ENV)
+extern int errno;
+#define Time_t long
+extern Time_t time ();
+#else
+#include <time.h>
+#define Time_t time_t
+#endif
+#ifndef X_NOT_POSIX
+#include <unistd.h>
+#else
+#ifndef WIN32
+extern unsigned        sleep ();
+#else
+#define link rename
+#endif
+#endif
+#ifdef __EMX__
+#define link rename
+#endif
+
+#if NeedFunctionPrototypes
+int
+XauLockAuth (
+_Xconst char *file_name,
+int    retries,
+int    timeout,
+long   dead)
+#else
+int
+XauLockAuth (file_name, retries, timeout, dead)
+char   *file_name;
+int    retries;
+int    timeout;
+long   dead;
+#endif
+{
+    char       creat_name[1025], link_name[1025];
+    struct stat        statb;
+    Time_t     now;
+    int                creat_fd = -1;
+
+    if (strlen (file_name) > 1022)
+       return LOCK_ERROR;
+    (void) strcpy (creat_name, file_name);
+    (void) strcat (creat_name, "-c");
+    (void) strcpy (link_name, file_name);
+    (void) strcat (link_name, "-l");
+    if (stat (creat_name, &statb) != -1) {
+       now = time ((Time_t *) 0);
+       /*
+        * NFS may cause ctime to be before now, special
+        * case a 0 deadtime to force lock removal
+        */
+       if (dead == 0 || now - statb.st_ctime > dead) {
+           (void) unlink (creat_name);
+           (void) unlink (link_name);
+       }
+    }
+    
+    while (retries > 0) {
+       if (creat_fd == -1) {
+           creat_fd = creat (creat_name, 0666);
+           if (creat_fd == -1) {
+               if (errno != EACCES)
+                   return LOCK_ERROR;
+           } else
+               (void) close (creat_fd);
+       }
+       if (creat_fd != -1) {
+           if (link (creat_name, link_name) != -1)
+               return LOCK_SUCCESS;
+           if (errno == ENOENT) {
+               creat_fd = -1;  /* force re-creat next time around */
+               continue;
+           }
+           if (errno != EEXIST)
+               return LOCK_ERROR;
+       }
+       (void) sleep ((unsigned) timeout);
+       --retries;
+    }
+    return LOCK_TIMEOUT;
+}
diff --git a/Xserver/lib/Xau/AuRead.c b/Xserver/lib/Xau/AuRead.c
new file mode 100644 (file)
index 0000000..ac4ee8a
--- /dev/null
@@ -0,0 +1,112 @@
+/* $XConsortium: AuRead.c,v 1.7 95/07/10 21:18:07 gildea Exp $ */
+
+/*
+
+Copyright (c) 1988  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+*/
+
+#include <X11/Xauth.h>
+
+static
+read_short (shortp, file)
+unsigned short *shortp;
+FILE           *file;
+{
+    unsigned char   file_short[2];
+
+    if (fread ((char *) file_short, (int) sizeof (file_short), 1, file) != 1)
+       return 0;
+    *shortp = file_short[0] * 256 + file_short[1];
+    return 1;
+}
+
+static
+read_counted_string (countp, stringp, file)
+unsigned short *countp;
+char   **stringp;
+FILE   *file;
+{
+    unsigned short  len;
+    char           *data;
+
+    if (read_short (&len, file) == 0)
+       return 0;
+    if (len == 0) {
+       data = 0;
+    } else {
+       data = malloc ((unsigned) len);
+       if (!data)
+           return 0;
+       if (fread (data, (int) sizeof (char), (int) len, file) != len) {
+           bzero (data, len);
+           free (data);
+           return 0;
+       }
+    }
+    *stringp = data;
+    *countp = len;
+    return 1;
+}
+
+Xauth *
+XauReadAuth (auth_file)
+FILE   *auth_file;
+{
+    Xauth   local;
+    Xauth   *ret;
+
+    if (read_short (&local.family, auth_file) == 0)
+       return 0;
+    if (read_counted_string (&local.address_length, &local.address, auth_file) == 0)
+       return 0;
+    if (read_counted_string (&local.number_length, &local.number, auth_file) == 0) {
+       if (local.address) free (local.address);
+       return 0;
+    }
+    if (read_counted_string (&local.name_length, &local.name, auth_file) == 0) {
+       if (local.address) free (local.address);
+       if (local.number) free (local.number);
+       return 0;
+    }
+    if (read_counted_string (&local.data_length, &local.data, auth_file) == 0) {
+       if (local.address) free (local.address);
+       if (local.number) free (local.number);
+       if (local.name) free (local.name);
+       return 0;
+    }
+    ret = (Xauth *) malloc (sizeof (Xauth));
+    if (!ret) {
+       if (local.address) free (local.address);
+       if (local.number) free (local.number);
+       if (local.name) free (local.name);
+       if (local.data) {
+           bzero (local.data, local.data_length);
+           free (local.data);
+       }
+       return 0;
+    }
+    *ret = local;
+    return ret;
+}
diff --git a/Xserver/lib/Xau/AuUnlock.c b/Xserver/lib/Xau/AuUnlock.c
new file mode 100644 (file)
index 0000000..78f0c85
--- /dev/null
@@ -0,0 +1,61 @@
+/* $XConsortium: AuUnlock.c,v 1.10 94/04/17 20:15:44 rws Exp $ */
+
+/*
+
+Copyright (c) 1988  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+*/
+
+#include <X11/Xauth.h>
+#include <X11/Xos.h>
+
+#if NeedFunctionPrototypes
+XauUnlockAuth (
+_Xconst char *file_name)
+#else
+XauUnlockAuth (file_name)
+char   *file_name;
+#endif
+{
+#ifndef WIN32
+    char       creat_name[1025];
+#endif
+    char       link_name[1025];
+
+    if (strlen (file_name) > 1022)
+       return;
+#ifndef WIN32
+    (void) strcpy (creat_name, file_name);
+    (void) strcat (creat_name, "-c");
+#endif
+    (void) strcpy (link_name, file_name);
+    (void) strcat (link_name, "-l");
+    /*
+     * I think this is the correct order
+     */
+#ifndef WIN32
+    (void) unlink (creat_name);
+#endif
+    (void) unlink (link_name);
+}
diff --git a/Xserver/lib/Xau/AuWrite.c b/Xserver/lib/Xau/AuWrite.c
new file mode 100644 (file)
index 0000000..97faf03
--- /dev/null
@@ -0,0 +1,75 @@
+/* $XConsortium: AuWrite.c,v 1.6 94/04/17 20:15:45 gildea Exp $ */
+
+/*
+
+Copyright (c) 1988  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+*/
+
+#include <X11/Xauth.h>
+
+static
+write_short (s, file)
+unsigned short s;
+FILE           *file;
+{
+    unsigned char   file_short[2];
+
+    file_short[0] = (s & (unsigned)0xff00) >> 8;
+    file_short[1] = s & 0xff;
+    if (fwrite ((char *) file_short, (int) sizeof (file_short), 1, file) != 1)
+       return 0;
+    return 1;
+}
+
+static
+write_counted_string (count, string, file)
+unsigned short count;
+char   *string;
+FILE   *file;
+{
+    if (write_short (count, file) == 0)
+       return 0;
+    if (fwrite (string, (int) sizeof (char), (int) count, file) != count)
+       return 0;
+    return 1;
+}
+
+int
+XauWriteAuth (auth_file, auth)
+FILE   *auth_file;
+Xauth  *auth;
+{
+    if (write_short (auth->family, auth_file) == 0)
+       return 0;
+    if (write_counted_string (auth->address_length, auth->address, auth_file) == 0)
+       return 0;
+    if (write_counted_string (auth->number_length, auth->number, auth_file) == 0)
+       return 0;
+    if (write_counted_string (auth->name_length, auth->name, auth_file) == 0)
+       return 0;
+    if (write_counted_string (auth->data_length, auth->data, auth_file) == 0)
+       return 0;
+    return 1;
+}
diff --git a/Xserver/lib/Xau/Autest.c b/Xserver/lib/Xau/Autest.c
new file mode 100644 (file)
index 0000000..d45dbf6
--- /dev/null
@@ -0,0 +1,69 @@
+/* $XConsortium: Autest.c,v 1.4 94/04/17 20:15:46 dpw Exp $ */
+
+/*
+
+Copyright (c) 1988  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+*/
+
+#include <X11/Xauth.h>
+
+main (argc, argv)
+char   **argv;
+{
+    Xauth   test_data;
+    char    *name, *data, *file;
+    int            state = 0;
+    FILE    *output;
+
+    while (*++argv) {
+       if (!strcmp (*argv, "-file"))
+           file = *++argv;
+       else if (state == 0) {
+           name = *argv;
+           ++state;
+       } else if (state == 1) {
+           data = *argv;
+           ++state;
+       }
+    }
+    if(!file) {
+       fprintf (stderr, "No file\n");
+       exit (1);
+    }
+    test_data.family = 0;
+    test_data.address_length = 0;
+    test_data.address = "";
+    test_data.number_length = 0;
+    test_data.number = "";
+    test_data.name_length = strlen (name);
+    test_data.name = name;
+    test_data.data_length = strlen (data);
+    test_data.data = data;
+    output = fopen (file, "w");
+    if (output) {
+       XauWriteAuth (output, &test_data);
+       fclose (output);
+    }
+}
diff --git a/Xserver/lib/Xau/Imakefile b/Xserver/lib/Xau/Imakefile
new file mode 100644 (file)
index 0000000..6d448a6
--- /dev/null
@@ -0,0 +1,38 @@
+XCOMM $XConsortium: Imakefile /main/27 1996/09/28 16:43:28 rws $
+XCOMM $XFree86: xc/lib/Xau/Imakefile,v 3.3 1996/12/23 06:00:28 dawes Exp $
+#define DoNormalLib NormalLibXau
+#define DoSharedLib SharedLibXau
+#define DoDebugLib DebugLibXau
+#define DoProfileLib ProfileLibXau
+#define LibName Xau
+#define SoRev SOXAUTHREV
+#define IncSubdir X11
+
+#include <Threads.tmpl>
+
+       LINTLIBS = $(LINTXLIB)
+
+#if HasKrb5
+K5ENCSRC = k5encode.c
+K5ENCOBJ = k5encode.o
+INCLUDES = Krb5Includes
+#else
+K5ENCSRC =
+K5ENCOBJ =
+INCLUDES =
+#endif
+
+HEADERS = \
+       Xauth.h
+
+SRCS = AuDispose.c AuFileName.c AuGetAddr.c AuGetBest.c AuLock.c \
+       AuRead.c AuUnlock.c AuWrite.c $(K5ENCSRC)
+
+OBJS = AuDispose.o AuFileName.o AuGetAddr.o AuGetBest.o AuLock.o \
+       AuRead.o AuUnlock.o AuWrite.o $(K5ENCOBJ)
+
+#include <Library.tmpl>
+
+InstallLinkKitLibrary(Xau,$(LINKKITDIR)/lib)
+
+DependTarget()
diff --git a/Xserver/lib/Xau/README b/Xserver/lib/Xau/README
new file mode 100644 (file)
index 0000000..404eef0
--- /dev/null
@@ -0,0 +1,184 @@
+
+
+                    A Sample Authorization Protocol for X
+
+
+Overview
+
+The following note describes a very simple mechanism for providing individual
+access to an X Window System display.  It uses existing core protocol and
+library hooks for specifying authorization data in the connection setup block
+to restrict use of the display to only those clients that show that they
+know a server-specific key called a "magic cookie".  This mechanism is *not*
+being proposed as an addition to the Xlib standard; among other reasons, a
+protocol extension is needed to support more flexible mechanisms.  We have
+implemented this mechanism already; if you have comments, please send them
+to us.
+
+This scheme involves changes to the following parts of the sample release:
+
+    o  xdm
+       -  generate random magic cookie and store in protected file
+       -  pass name of magic cookie file to server
+       -  when user logs in, add magic cookie to user's auth file
+       -  when user logs out, generate a new cookie for server
+
+    o  server
+       -  a new command line option to specify cookie file
+       -  check client authorization data against magic cookie
+       -  read in cookie whenever the server resets
+       -  do not add local machine to host list if magic cookie given
+
+    o  Xlib
+       -  read in authorization data from file
+       -  find data for appropriate server
+       -  send authorization data if found
+
+    o  xauth [new program to manage user auth file]
+       -  add entries to user's auth file
+       -  remove entries from user's auth file
+
+This mechanism assumes that the superuser and the transport layer between 
+the client and the server is secure.  Organizations that desire stricter
+security are encouraged to look at systems such as Kerberos (at Project
+Athena).
+
+
+Description
+
+The sample implementation will use the xdm Display Manager to set up and
+control the server's authorization file.  Sites that do not run xdm will
+need to build their own mechanisms.  
+
+Xdm uses a random key (seeded by the system time and check sum of /dev/kmem)
+to generate a unique sequence of characters at 16 bytes long.  This sequence
+will be written to a file which is made readable only by the server.  The
+server will then be started with a command line option instructing it to use
+the contents of the file as the magic cookie for connections that include
+authorization data.  This will also disable the server from adding the local
+machine's address to the initial host list.  Note that the actual cookie must
+not be stored on the command line or in an environment variable, to prevent
+it from being publicly obtainable by the "ps" command.
+
+If a client presents an authorization name of "MIT-MAGIC-COOKIE-1" and
+authorization data that matches the magic cookie, that client is allowed
+access.  If the name or data does not match and the host list is empty,
+that client will be denied access.  Otherwise, the existing host-based access
+control will be used.  Since any client that is making a connection from a
+machine on the host list will be granted access even if their authorization
+data is incorrect, sites are strongly urged not to set up any default hosts
+using the /etc/X*.hosts files.  Granting access to other machines should be
+done by the user's session manager instead.
+
+Assuming the server is configured with an empty host list, the existence of the
+cookie is sufficient to ensure there will be no unauthorized access to the
+display.  However, xdm will (continue to) work to minimize the chances of
+spoofing on servers that do not support this authorization mechanism.  This
+will be done by grabbing the server and the keyboard after opening the display.
+This action will be surrounded by a timer which will kill the server if the
+grabs cannot be done within several seconds.  [This level of security is now
+implemented in patches already sent out.]
+
+After the user logs in, xdm will add authorization entries for each of the
+server machine's network addresses to the user's authorization file (the format
+of which is described below).  This file will usually be named .Xauthority in
+the users's home directory; will be owned by the user (as specified by the
+pw_uid and pw_gid fields in the user's password entry), and will be accessible
+only to the user (no group access).  This file will contain authorization data
+for all of the displays opened by the user.
+
+When the session terminates, xdm will generate and store a new magic cookie
+for the server.  Then, xdm will shutdown its own connection and send a
+SIGHUP to the server process, which should cause the server to reset.  The
+server will then read in the new magic cookie.
+
+To support accesses (both read and write) from multiple machines (for use in
+environments that use distributed file systems), file locking is done using
+hard links.  This is done by creat'ing (sic) a lock file and then linking it
+to another name in the same directory.  If the link-target already exists,
+the link will fail, indicating failure to obtain the lock.  Linking is used
+instead of just creating the file read-only since link will fail even for
+the superuser.
+
+Problems and Solutions
+
+There are a few problems with .Xauthority as described.  If no home directory
+exists, or if xdm cannot create a file there (disk full), xdm stores the
+cookie in a file in a resource-specified back-up directory, and sets an
+environment variable in the user's session (called XAUTHORITY) naming this
+file.  There is also the problem that the locking attempts will need to be
+timed out, due to a leftover lock.  Xdm, again, creates a file and set an
+environment variable.  Finally, the back-up directory might be full.  Xdm,
+as a last resort, provides a function key binding that allows a user to log
+in without having the authorization data stored, and with host-based access
+control disabled.
+
+Xlib
+
+XOpenDisplay in Xlib was enhanced to allow specification of authorization
+information.  As implied above, Xlib looks for the data in the
+.Xauthority file of the home directory, or in the file pointed at by the
+XAUTHORITY environment variable instead if that is defined.  This required
+no programmatic interface change to Xlib.  In addition, a new Xlib routine
+is provided to explicitly specify authorization.
+
+       XSetAuthorization(name, namelen, data, datalen)
+               int namelen, datalen;
+               char *name, *data;
+
+There are three types of input:
+
+       name NULL, data don't care      - use default authorization mechanism.
+       name non-NULL, data NULL        - use the named authorization; get
+                                         data from that mechanism's default.
+       name non-NULL, data non-NULL    - use the given authorization and data.
+                                       
+This interface is used by xdm and might also be used by any other
+applications that wish to explicitly set the authorization information.
+
+Authorization File
+
+The .Xauthority file is a binary file consisting of a sequence of entries
+in the following format:
+
+       2 bytes         Family value (second byte is as in protocol HOST)
+       2 bytes         address length (always MSB first)
+       A bytes         host address (as in protocol HOST)
+       2 bytes         display "number" length (always MSB first)
+       S bytes         display "number" string
+       2 bytes         name length (always MSB first)
+       N bytes         authorization name string
+       2 bytes         data length (always MSB first)
+       D bytes         authorization data string
+
+The format is binary for easy processing, since authorization information
+usually consists of arbitrary data.  Host addresses are used instead of
+names to eliminate potentially time-consuming name resolutions in
+XOpenDisplay.  Programs, such as xdm, that initialize the user's
+authorization file will have to do the same work as the server in finding
+addresses for all network interfaces.  If more than one entry matches the
+desired address, the entry that is chosen is implementation-dependent.  In
+our implementation, it is always the first in the file.
+
+The Family is specified in two bytes to allow out-of-band values
+(i.e. values not in the Protocol) to be used.  In particular,
+two new values "FamilyLocal" and "FamilyWild" are defined.  FamilyLocal
+refers to any connections using a non-network method of connetion from the
+local machine (Unix domain sockets, shared memory, loopback serial line).
+In this case the host address is specified by the data returned from
+gethostname() and better be unique in a collection of machines
+which share NFS directories.  FamilyWild is currently used only
+by xdm to communicate authorization data to the server.  It matches
+any family/host address pair.
+
+For FamilyInternet, the host address is the 4 byte internet address, for
+FamilyDecnet, the host address is the byte decnet address, for FamilyChaos
+the address is also two bytes.
+
+The Display Number is the ascii representation of the display number
+portion of the display name.  It is in ascii to allow future expansion
+to PseudoRoots or anything else that might happen.
+
+A utility called "xauth" will be provided for editing and viewing the
+contents of authorization files.  Note that the user's authorization file is
+not the same as the server's magic cookie file.
diff --git a/Xserver/lib/Xau/Xauth.h b/Xserver/lib/Xau/Xauth.h
new file mode 100644 (file)
index 0000000..7d474ec
--- /dev/null
@@ -0,0 +1,181 @@
+/* $XConsortium: Xauth.h /main/18 1996/07/31 16:08:18 dpw $ */
+
+/*
+
+Copyright (c) 1988  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+*/
+
+#ifndef _Xauth_h
+#define _Xauth_h
+
+typedef struct xauth {
+    unsigned short   family;
+    unsigned short   address_length;
+    char           *address;
+    unsigned short   number_length;
+    char           *number;
+    unsigned short   name_length;
+    char           *name;
+    unsigned short   data_length;
+    char           *data;
+} Xauth;
+
+#ifndef _XAUTH_STRUCT_ONLY
+
+# include   <X11/Xfuncproto.h>
+# include   <X11/Xfuncs.h>
+
+# include   <stdio.h>
+
+# define FamilyLocal (256)     /* not part of X standard (i.e. X.h) */
+# define FamilyWild  (65535)
+# define FamilyNetname    (254)   /* not part of X standard */
+# define FamilyKrb5Principal (253) /* Kerberos 5 principal name */
+# define FamilyLocalHost (252) /* for local non-net authentication */
+
+
+_XFUNCPROTOBEGIN
+
+char *XauFileName();
+
+Xauth *XauReadAuth(
+#if NeedFunctionPrototypes
+FILE*  /* auth_file */
+#endif
+);
+
+int XauLockAuth(
+#if NeedFunctionPrototypes
+_Xconst char*  /* file_name */,
+int            /* retries */,
+int            /* timeout */,
+long           /* dead */
+#endif
+);
+
+int XauUnlockAuth(
+#if NeedFunctionPrototypes
+_Xconst char*  /* file_name */
+#endif
+);
+
+int XauWriteAuth(
+#if NeedFunctionPrototypes
+FILE*          /* auth_file */,
+Xauth*         /* auth */
+#endif
+);
+
+Xauth *XauGetAuthByName(
+#if NeedFunctionPrototypes
+_Xconst char*  /* display_name */
+#endif
+);
+
+Xauth *XauGetAuthByAddr(
+#if NeedFunctionPrototypes
+#if NeedWidePrototypes
+unsigned int   /* family */,
+unsigned int   /* address_length */,
+#else
+unsigned short /* family */,
+unsigned short /* address_length */,
+#endif
+_Xconst char*  /* address */,
+#if NeedWidePrototypes
+unsigned int   /* number_length */,
+#else
+unsigned short /* number_length */,
+#endif
+_Xconst char*  /* number */,
+#if NeedWidePrototypes
+unsigned int   /* name_length */,
+#else
+unsigned short /* name_length */,
+#endif
+_Xconst char*  /* name */
+#endif
+);
+
+Xauth *XauGetBestAuthByAddr(
+#if NeedFunctionPrototypes
+#if NeedWidePrototypes
+unsigned int   /* family */,
+unsigned int   /* address_length */,
+#else
+unsigned short /* family */,
+unsigned short /* address_length */,
+#endif
+_Xconst char*  /* address */,
+#if NeedWidePrototypes
+unsigned int   /* number_length */,
+#else
+unsigned short /* number_length */,
+#endif
+_Xconst char*  /* number */,
+int            /* types_length */,
+char**         /* type_names */,
+_Xconst int*   /* type_lengths */
+#endif
+);
+
+void XauDisposeAuth(
+#if NeedFunctionPrototypes
+Xauth*         /* auth */
+#endif
+);
+
+#ifdef K5AUTH
+#include <krb5/krb5.h>
+/* 9/93: krb5.h leaks some symbols */
+#undef BITS32
+#undef xfree
+
+int XauKrb5Encode(
+#if NeedFunctionPrototypes
+     krb5_principal    /* princ */,
+     krb5_data *       /* outbuf */
+#endif
+);
+
+int XauKrb5Decode(
+#if NeedFunctionPrototypes
+     krb5_data         /* inbuf */,
+     krb5_principal *  /* princ */
+#endif
+);
+#endif /* K5AUTH */
+
+_XFUNCPROTOEND
+
+/* Return values from XauLockAuth */
+
+# define LOCK_SUCCESS  0       /* lock succeeded */
+# define LOCK_ERROR    1       /* lock unexpectely failed, check errno */
+# define LOCK_TIMEOUT  2       /* lock failed, timeouts expired */
+
+#endif /* _XAUTH_STRUCT_ONLY */
+
+#endif /* _Xauth_h */
diff --git a/Xserver/lib/Xau/k5encode.c b/Xserver/lib/Xau/k5encode.c
new file mode 100644 (file)
index 0000000..01fbe8d
--- /dev/null
@@ -0,0 +1,184 @@
+/* $XConsortium: k5encode.c,v 1.6 94/09/01 19:20:38 gildea Exp $ */
+
+/*
+
+Copyright (c) 1993, 1994  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+*/
+
+/*
+ * functions to encode/decode Kerberos V5 principals
+ * into something that can be reasonable spewed over
+ * the wire
+ *
+ * Author: Tom Yu <tlyu@MIT.EDU>
+ *
+ * Still needs to be fixed up wrt signed/unsigned lengths, but we'll worry
+ * about that later.
+ */
+
+#include <krb5/krb5.h>
+/* 9/93: krb5.h leaks some symbols */
+#undef BITS32
+#undef xfree
+
+#include <X11/X.h>
+#include <X11/Xos.h>
+#include <X11/Xmd.h>
+#include <X11/Xfuncs.h>
+
+/*
+ * XauKrb5Encode
+ *
+ * this function encodes the principal passed to it in a format that can
+ * easily be dealt with by stuffing it into an X packet.  Encoding is as
+ * follows:
+ *   length count of the realm name
+ *   realm
+ *   component count
+ *   length of component
+ *   actual principal component
+ *   etc....
+ *
+ * Note that this function allocates a hunk of memory, which must be
+ * freed to avoid nasty memory leak type things.  All counts are
+ * byte-swapped if needed. (except for the total length returned)
+ *
+ * nevermind.... stuffing the encoded packet in net byte order just to
+ * always do the right thing.  Don't have to frob with alignment that way.
+ */
+int
+XauKrb5Encode(princ, outbuf)
+    krb5_principal princ;      /* principal to encode */
+    krb5_data *outbuf;         /* output buffer */
+{
+    CARD16 i, numparts, totlen = 0, plen, rlen;
+    char *cp, *pdata;
+
+    rlen = krb5_princ_realm(princ)->length;
+    numparts = krb5_princ_size(princ);
+    totlen = 2 + rlen + 2;     /* include room for realm length
+                                  and component count */
+    for (i = 0; i < numparts; i++)
+       totlen += krb5_princ_component(princ, i)->length + 2;
+    /* add 2 bytes each time for length */
+    if ((outbuf->data = (char *)malloc(totlen)) == NULL)
+       return -1;
+    cp = outbuf->data;
+    *cp++ = (char)((int)(0xff00 & rlen) >> 8);
+    *cp++ = (char)(0x00ff & rlen);
+    memcpy(cp, krb5_princ_realm(princ)->data, rlen);
+    cp += rlen;
+    *cp++ = (char)((int)(0xff00 & numparts) >> 8);
+    *cp++ = (char)(0x00ff & numparts);
+    for (i = 0; i < numparts; i++)
+    {
+       plen = krb5_princ_component(princ, i)->length;
+       pdata = krb5_princ_component(princ, i)->data;
+       *cp++ = (char)((int)(0xff00 & plen) >> 8);
+       *cp++ = (char)(0x00ff & plen);
+       memcpy(cp, pdata, plen);
+       cp += plen;
+    }
+    outbuf->length = totlen;
+    return 0;
+}
+
+/*
+ * XauKrb5Decode
+ *
+ * This function essentially reverses what XauKrb5Encode does.
+ * return value: 0 if okay, -1 if malloc fails, -2 if inbuf format bad
+ */
+int
+XauKrb5Decode(inbuf, princ)
+    krb5_data inbuf;
+    krb5_principal *princ;
+{
+    CARD16 i, numparts, plen, rlen;
+    CARD8 *cp, *pdata;
+    
+    if (inbuf.length < 4)
+    {
+       return -2;
+    }
+    *princ = (krb5_principal)malloc(sizeof (krb5_principal_data));
+    if (*princ == NULL)
+       return -1;
+    bzero(*princ, sizeof (krb5_principal_data));
+    cp = (CARD8 *)inbuf.data;
+    rlen = *cp++ << 8;
+    rlen |= *cp++;
+    if (inbuf.length < 4 + (int)rlen + 2)
+    {
+       krb5_free_principal(*princ);
+       return -2;
+    }
+    krb5_princ_realm(*princ)->data = (char *)malloc(rlen);
+    if (krb5_princ_realm(*princ)->data == NULL)
+    {
+       krb5_free_principal(*princ);
+       return -1;
+    }
+    krb5_princ_realm(*princ)->length = rlen;
+    memcpy(krb5_princ_realm(*princ)->data, cp, rlen);
+    cp += rlen;
+    numparts = *cp++ << 8;
+    numparts |= *cp++;
+    krb5_princ_name(*princ) =
+       (krb5_data *)malloc(numparts * sizeof (krb5_data));
+    if (krb5_princ_name(*princ) == NULL)
+    {
+       krb5_free_principal(*princ);
+       return -1;
+    }
+    krb5_princ_size(*princ) = 0;
+    for (i = 0; i < numparts; i++)
+    {
+       if (cp + 2 > (CARD8 *)inbuf.data + inbuf.length)
+       {
+           krb5_free_principal(*princ);
+           return -2;
+       }
+       plen = *cp++ << 8;
+       plen |= *cp++;
+       if (cp + plen > (CARD8 *)inbuf.data + inbuf.length)
+       {
+           krb5_free_principal(*princ);
+           return -2;
+       }
+       pdata = (CARD8 *)malloc(plen);
+       if (pdata == NULL)
+       {
+           krb5_free_principal(*princ);
+           return -1;
+       }
+       krb5_princ_component(*princ, i)->data = (char *)pdata;
+       krb5_princ_component(*princ, i)->length = plen;
+       memcpy(pdata, cp, plen);
+       cp += plen;
+       krb5_princ_size(*princ)++;
+    }
+    return 0;
+}
diff --git a/Xserver/lib/Xdmcp/A8Eq.c b/Xserver/lib/Xdmcp/A8Eq.c
new file mode 100644 (file)
index 0000000..3b948d1
--- /dev/null
@@ -0,0 +1,48 @@
+/*
+ * $XConsortium: A8Eq.c,v 1.4 94/04/17 20:16:28 gildea Exp $
+ *
+ * 
+Copyright (c) 1989  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+ * *
+ * Author:  Keith Packard, MIT X Consortium
+ */
+
+#include <X11/Xos.h>
+#include <X11/X.h>
+#include <X11/Xmd.h>
+#include <X11/Xdmcp.h>
+
+int
+XdmcpARRAY8Equal (array1, array2)
+    ARRAY8Ptr  array1, array2;
+{
+    int        i;
+
+    if (array1->length != array2->length)
+       return FALSE;
+    for (i = 0; i < (int)array1->length; i++)
+       if (array1->data[i] != array2->data[i])
+           return FALSE;
+    return TRUE;
+}
diff --git a/Xserver/lib/Xdmcp/AA16.c b/Xserver/lib/Xdmcp/AA16.c
new file mode 100644 (file)
index 0000000..5785d6f
--- /dev/null
@@ -0,0 +1,49 @@
+/*
+ * $XConsortium: AA16.c,v 1.3 94/04/17 20:16:28 gildea Exp $
+ *
+ * 
+Copyright (c) 1989  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+ * *
+ * Author:  Keith Packard, MIT X Consortium
+ */
+
+#include <X11/Xos.h>
+#include <X11/X.h>
+#include <X11/Xmd.h>
+#include <X11/Xdmcp.h>
+
+int
+XdmcpAllocARRAY16 (array, length)
+    ARRAY16Ptr array;
+    int                length;
+{
+    CARD16Ptr  newData;
+
+    newData = (CARD16Ptr) Xalloc (length * sizeof (CARD16));
+    if (!newData)
+       return FALSE;
+    array->length = length;
+    array->data = newData;
+    return TRUE;
+}
diff --git a/Xserver/lib/Xdmcp/AA32.c b/Xserver/lib/Xdmcp/AA32.c
new file mode 100644 (file)
index 0000000..ceb5472
--- /dev/null
@@ -0,0 +1,49 @@
+/*
+ * $XConsortium: AA32.c,v 1.3 94/04/17 20:16:28 gildea Exp $
+ *
+ * 
+Copyright (c) 1989  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+ * *
+ * Author:  Keith Packard, MIT X Consortium
+ */
+
+#include <X11/Xos.h>
+#include <X11/X.h>
+#include <X11/Xmd.h>
+#include <X11/Xdmcp.h>
+
+int
+XdmcpAllocARRAY32 (array, length)
+    ARRAY32Ptr array;
+    int                length;
+{
+    CARD32Ptr  newData;
+
+    newData = (CARD32Ptr) Xalloc (length * sizeof (CARD32));
+    if (!newData)
+       return FALSE;
+    array->length = length;
+    array->data = newData;
+    return TRUE;
+}
diff --git a/Xserver/lib/Xdmcp/AA8.c b/Xserver/lib/Xdmcp/AA8.c
new file mode 100644 (file)
index 0000000..1c51c6c
--- /dev/null
@@ -0,0 +1,49 @@
+/*
+ * $XConsortium: AA8.c,v 1.3 94/04/17 20:16:29 gildea Exp $
+ *
+ * 
+Copyright (c) 1989  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+ * *
+ * Author:  Keith Packard, MIT X Consortium
+ */
+
+#include <X11/Xos.h>
+#include <X11/X.h>
+#include <X11/Xmd.h>
+#include <X11/Xdmcp.h>
+
+int
+XdmcpAllocARRAY8 (array, length)
+    ARRAY8Ptr  array;
+    int                length;
+{
+    CARD8Ptr   newData;
+
+    newData = (CARD8Ptr) Xalloc (length * sizeof (CARD8));
+    if (!newData)
+       return FALSE;
+    array->length = length;
+    array->data = newData;
+    return TRUE;
+}
diff --git a/Xserver/lib/Xdmcp/Alloc.c b/Xserver/lib/Xdmcp/Alloc.c
new file mode 100644 (file)
index 0000000..758e1c6
--- /dev/null
@@ -0,0 +1,63 @@
+/*
+ * $XConsortium: Alloc.c,v 1.2 94/04/17 20:16:29 keith Exp $
+ * $XFree86: xc/lib/Xdmcp/Alloc.c,v 3.0 1995/07/07 15:32:19 dawes Exp $
+ *
+ * 
+Copyright (c) 1989  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+ * *
+ * Author:  Keith Packard, MIT X Consortium
+ */
+
+/* stubs for use when Xalloc, Xrealloc and Xfree are not defined */
+
+extern char    *malloc (), *realloc ();
+
+unsigned long *
+Xalloc (amount)
+    unsigned   amount;
+{
+    if (amount == 0)
+       amount = 1;
+    return (unsigned long *) malloc (amount);
+}
+
+unsigned long *
+Xrealloc (old, amount)
+    unsigned long      *old;
+    unsigned           amount;
+{
+    if (amount == 0)
+       amount = 1;
+    if (!old)
+       return (unsigned long *) malloc (amount);
+    return (unsigned long *) realloc ((char *) old, amount);
+}
+
+void
+Xfree (old)
+    unsigned long    *old;
+{
+    if (old)
+       free ((char *) old);
+}
diff --git a/Xserver/lib/Xdmcp/AofA8.c b/Xserver/lib/Xdmcp/AofA8.c
new file mode 100644 (file)
index 0000000..36dce56
--- /dev/null
@@ -0,0 +1,49 @@
+/*
+ * $XConsortium: AofA8.c,v 1.4 94/04/17 20:16:30 rws Exp $
+ *
+ * 
+Copyright (c) 1989  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+ * *
+ * Author:  Keith Packard, MIT X Consortium
+ */
+
+#include <X11/Xos.h>
+#include <X11/X.h>
+#include <X11/Xmd.h>
+#include <X11/Xdmcp.h>
+
+int
+XdmcpAllocARRAYofARRAY8 (array, length)
+    ARRAYofARRAY8Ptr   array;
+    int                        length;
+{
+    ARRAY8Ptr  newData;
+
+    newData = (ARRAY8Ptr) Xalloc (length * sizeof (ARRAY8));
+    if (!newData)
+       return FALSE;
+    array->length = length;
+    array->data = newData;
+    return TRUE;
+}
diff --git a/Xserver/lib/Xdmcp/CA8.c b/Xserver/lib/Xdmcp/CA8.c
new file mode 100644 (file)
index 0000000..9cfcec8
--- /dev/null
@@ -0,0 +1,47 @@
+/*
+ * $XConsortium: CA8.c,v 1.5 94/04/17 20:16:31 rws Exp $
+ *
+ * 
+Copyright (c) 1989  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+ * *
+ * Author:  Keith Packard, MIT X Consortium
+ */
+
+#include <X11/Xos.h>
+#include <X11/X.h>
+#include <X11/Xmd.h>
+#include <X11/Xdmcp.h>
+#include <X11/Xfuncs.h>
+
+int
+XdmcpCopyARRAY8 (src, dst)
+    ARRAY8Ptr  src, dst;
+{
+    dst->length = src->length;
+    dst->data = (CARD8 *) Xalloc (dst->length * sizeof (CARD8));
+    if (!dst->data)
+       return FALSE;
+    memmove (dst->data, src->data, src->length * sizeof (CARD8));
+    return TRUE;
+}
diff --git a/Xserver/lib/Xdmcp/CmpKey.c b/Xserver/lib/Xdmcp/CmpKey.c
new file mode 100644 (file)
index 0000000..fb82734
--- /dev/null
@@ -0,0 +1,45 @@
+/*
+ * $XConsortium: CmpKey.c,v 1.3 94/04/17 20:16:32 gildea Exp $
+ *
+ * 
+Copyright (c) 1989  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+ * *
+ * Author:  Keith Packard, MIT X Consortium
+ */
+
+#include <X11/Xos.h>
+#include <X11/X.h>
+#include <X11/Xmd.h>
+#include <X11/Xdmcp.h>
+
+XdmcpCompareKeys (a, b)
+    XdmAuthKeyPtr   a, b;
+{
+    int        i;
+
+    for (i = 0; i < 8; i++)
+       if (a->data[i] != b->data[i])
+           return FALSE;
+    return TRUE;
+}
diff --git a/Xserver/lib/Xdmcp/DA16.c b/Xserver/lib/Xdmcp/DA16.c
new file mode 100644 (file)
index 0000000..6fc9d01
--- /dev/null
@@ -0,0 +1,43 @@
+/*
+ * $XConsortium: DA16.c,v 1.3 94/04/17 20:16:33 gildea Exp $
+ *
+ * 
+Copyright (c) 1989  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+ * *
+ * Author:  Keith Packard, MIT X Consortium
+ */
+
+#include <X11/Xos.h>
+#include <X11/X.h>
+#include <X11/Xmd.h>
+#include <X11/Xdmcp.h>
+
+void
+XdmcpDisposeARRAY16 (array)
+    ARRAY16Ptr array;
+{
+    Xfree (array->data);
+    array->length = 0;
+    array->data = 0;
+}
diff --git a/Xserver/lib/Xdmcp/DA32.c b/Xserver/lib/Xdmcp/DA32.c
new file mode 100644 (file)
index 0000000..6d8fa48
--- /dev/null
@@ -0,0 +1,43 @@
+/*
+ * $XConsortium: DA32.c,v 1.3 94/04/17 20:16:33 gildea Exp $
+ *
+ * 
+Copyright (c) 1989  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+ * *
+ * Author:  Keith Packard, MIT X Consortium
+ */
+
+#include <X11/Xos.h>
+#include <X11/X.h>
+#include <X11/Xmd.h>
+#include <X11/Xdmcp.h>
+
+void
+XdmcpDisposeARRAY32 (array)
+    ARRAY32Ptr array;
+{
+    Xfree (array->data);
+    array->length = 0;
+    array->data = 0;
+}
diff --git a/Xserver/lib/Xdmcp/DA8.c b/Xserver/lib/Xdmcp/DA8.c
new file mode 100644 (file)
index 0000000..b722967
--- /dev/null
@@ -0,0 +1,43 @@
+/*
+ * $XConsortium: DA8.c,v 1.3 94/04/17 20:16:34 gildea Exp $
+ *
+ * 
+Copyright (c) 1989  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+ * *
+ * Author:  Keith Packard, MIT X Consortium
+ */
+
+#include <X11/Xos.h>
+#include <X11/X.h>
+#include <X11/Xmd.h>
+#include <X11/Xdmcp.h>
+
+void
+XdmcpDisposeARRAY8 (array)
+    ARRAY8Ptr  array;
+{
+    Xfree (array->data);
+    array->length = 0;
+    array->data = 0;
+}
diff --git a/Xserver/lib/Xdmcp/DAofA8.c b/Xserver/lib/Xdmcp/DAofA8.c
new file mode 100644 (file)
index 0000000..5f07230
--- /dev/null
@@ -0,0 +1,47 @@
+/*
+ * $XConsortium: DAofA8.c,v 1.4 94/04/17 20:16:34 gildea Exp $
+ *
+ * 
+Copyright (c) 1989  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+ * *
+ * Author:  Keith Packard, MIT X Consortium
+ */
+
+#include <X11/Xos.h>
+#include <X11/X.h>
+#include <X11/Xmd.h>
+#include <X11/Xdmcp.h>
+
+void
+XdmcpDisposeARRAYofARRAY8 (array)
+    ARRAYofARRAY8Ptr   array;
+{
+    int        i;
+
+    for (i = 0; i < (int)array->length; i++)
+       XdmcpDisposeARRAY8 (&array->data[i]);
+    Xfree (array->data);
+    array->length = 0;
+    array->data = 0;
+}
diff --git a/Xserver/lib/Xdmcp/DecKey.c b/Xserver/lib/Xdmcp/DecKey.c
new file mode 100644 (file)
index 0000000..e25668f
--- /dev/null
@@ -0,0 +1,46 @@
+/*
+ * $XConsortium: DecKey.c,v 1.3 94/04/17 20:16:35 gildea Exp $
+ *
+ * 
+Copyright (c) 1989  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+ * *
+ * Author:  Keith Packard, MIT X Consortium
+ */
+
+#include <X11/Xos.h>
+#include <X11/X.h>
+#include <X11/Xmd.h>
+#include <X11/Xdmcp.h>
+
+void
+XdmcpDecrementKey (key)
+    XdmAuthKeyPtr   key;
+{
+    int        i;
+
+    i = 7;
+    while (key->data[i]-- == 0)
+       if (--i < 0)
+           break;
+}
diff --git a/Xserver/lib/Xdmcp/Fill.c b/Xserver/lib/Xdmcp/Fill.c
new file mode 100644 (file)
index 0000000..71a044e
--- /dev/null
@@ -0,0 +1,148 @@
+/*
+ * $XConsortium: Fill.c /main/11 1996/11/13 14:44:18 lehors $
+ * $XFree86: xc/lib/Xdmcp/Fill.c,v 3.4 1997/01/18 06:52:06 dawes Exp $
+ *
+ * 
+Copyright (c) 1989  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+ * *
+ * Author:  Keith Packard, MIT X Consortium
+ */
+
+#ifdef WIN32
+#define _WILLWINSOCK_
+#endif
+#include <X11/Xos.h>
+#include <X11/X.h>
+#include <X11/Xmd.h>
+#include <X11/Xdmcp.h>
+
+#ifdef STREAMSCONN
+#include <tiuser.h>
+#else
+#ifdef WIN32
+#include <X11/Xwinsock.h>
+#else
+#ifndef MINIX
+#ifndef Lynx
+#include <sys/socket.h>
+#else
+#include <socket.h>
+#endif /* !Lynx */
+#endif /* !MINIX */
+#endif
+#endif
+
+#ifndef MINIX
+int
+XdmcpFill (fd, buffer, from, fromlen)
+    int                    fd;
+    XdmcpBufferPtr  buffer;
+    XdmcpNetaddr    from;      /* return */
+    int                    *fromlen;   /* return */
+{
+    BYTE    *newBuf;
+#ifdef STREAMSCONN
+    struct t_unitdata dataunit;
+    int gotallflag, result;
+#endif
+
+    if (buffer->size < XDM_MAX_MSGLEN)
+    {
+       newBuf = (BYTE *) Xalloc (XDM_MAX_MSGLEN);
+       if (newBuf)
+       {
+           Xfree (buffer->data);
+           buffer->data = newBuf;
+           buffer->size = XDM_MAX_MSGLEN;
+       }
+    }
+    buffer->pointer = 0;
+#ifdef STREAMSCONN
+    dataunit.addr.buf = from;
+    dataunit.addr.maxlen = *fromlen;
+    dataunit.opt.maxlen = 0;   /* don't care to know about options */
+    dataunit.udata.buf = (char *)buffer->data;
+    dataunit.udata.maxlen = buffer->size;
+    result = t_rcvudata (fd, &dataunit, &gotallflag);
+    if (result < 0) {
+       return FALSE;
+    }
+    buffer->count = dataunit.udata.len;
+    *fromlen = dataunit.addr.len;
+#else
+    buffer->count = recvfrom (fd, (char*)buffer->data, buffer->size, 0,
+                             (struct sockaddr *)from, fromlen);
+#endif
+    if (buffer->count < 6) {
+       buffer->count = 0;
+       return FALSE;
+    }
+    return TRUE;
+}
+#else /* MINIX */
+int
+MNX_XdmcpFill (fd, buffer, from, fromlen, data, datalen)
+    int                    fd;
+    XdmcpBufferPtr  buffer;
+    XdmcpNetaddr    from;      /* return */
+    int                    *fromlen;   /* return */
+    char           *data;
+    int                    datalen;
+{
+    BYTE    *newBuf;
+    struct sockaddr_in *from_addr;
+    udp_io_hdr_t *udp_io_hdr;
+
+    if (buffer->size < XDM_MAX_MSGLEN)
+    {
+       newBuf = (BYTE *) Xalloc (XDM_MAX_MSGLEN);
+       if (newBuf)
+       {
+           Xfree (buffer->data);
+           buffer->data = newBuf;
+           buffer->size = XDM_MAX_MSGLEN;
+       }
+    }
+    buffer->pointer = 0;
+    udp_io_hdr= (udp_io_hdr_t *)data;
+    data += sizeof(udp_io_hdr_t) + udp_io_hdr->uih_ip_opt_len;
+    datalen -= sizeof(udp_io_hdr_t) + udp_io_hdr->uih_ip_opt_len;
+    buffer->count= udp_io_hdr->uih_data_len;
+    if (buffer->count > datalen)
+    {
+       buffer->count= 0;
+       return FALSE;
+    }
+    bcopy(data, (char *)buffer->data, buffer->count);
+    from_addr= (struct sockaddr_in *)from;
+    from_addr->sin_family= AF_INET;
+    from_addr->sin_addr.s_addr= udp_io_hdr->uih_src_addr;
+    from_addr->sin_port= udp_io_hdr->uih_src_port;
+    if (buffer->count < 6) {
+       buffer->count = 0;
+       return FALSE;
+    }
+    return TRUE;
+}
+#endif /* !MINIX */
diff --git a/Xserver/lib/Xdmcp/Flush.c b/Xserver/lib/Xdmcp/Flush.c
new file mode 100644 (file)
index 0000000..e529be8
--- /dev/null
@@ -0,0 +1,112 @@
+/*
+ * $XConsortium: Flush.c /main/11 1996/11/13 14:44:22 lehors $
+ * $XFree86: xc/lib/Xdmcp/Flush.c,v 3.4 1997/01/18 06:52:07 dawes Exp $
+ *
+ * 
+Copyright (c) 1989  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+ * *
+ * Author:  Keith Packard, MIT X Consortium
+ */
+
+#ifdef WIN32
+#define _WILLWINSOCK_
+#endif
+#include <X11/Xos.h>
+#include <X11/X.h>
+#include <X11/Xmd.h>
+#include <X11/Xdmcp.h>
+
+#ifdef STREAMSCONN
+#include <tiuser.h>
+#else
+#ifdef WIN32
+#include <X11/Xwinsock.h>
+#else
+#ifndef MINIX
+#ifndef Lynx
+#include <sys/socket.h>
+#else
+#include <socket.h>
+#endif /* !Lynx */
+#endif /* !MINIX */
+#endif
+#endif
+
+int
+XdmcpFlush (fd, buffer, to, tolen)
+    int                    fd;
+    XdmcpBufferPtr  buffer;
+    XdmcpNetaddr    to;
+    int                    tolen;
+{
+    int result;
+#ifdef MINIX
+    struct sockaddr_in *to_addr;
+    char *b;
+    udp_io_hdr_t *udp_io_hdr;
+    int flags, s_errno;
+#endif /* MINIX */
+
+#ifdef STREAMSCONN
+    struct t_unitdata dataunit;
+
+    dataunit.addr.buf = to;
+    dataunit.addr.len = tolen;
+    dataunit.opt.len = 0;      /* default options */
+    dataunit.udata.buf = (char *)buffer->data;
+    dataunit.udata.len = buffer->pointer;
+    result = t_sndudata(fd, &dataunit);
+    if (result < 0)
+       return FALSE;
+#else
+#ifndef MINIX
+    result = sendto (fd, (char *)buffer->data, buffer->pointer, 0,
+                    (struct sockaddr *)to, tolen);
+    if (result != buffer->pointer)
+       return FALSE;
+#else /* MINIX */
+    to_addr= (struct sockaddr_in *)to;
+    b= (char *)Xalloc(buffer->pointer + sizeof(udp_io_hdr_t));
+    if (b == NULL)
+       return FALSE;
+    udp_io_hdr= (udp_io_hdr_t *)b;
+    bcopy((char *)buffer->data, b+sizeof(udp_io_hdr_t), buffer->pointer);
+    udp_io_hdr->uih_dst_addr= to_addr->sin_addr.s_addr;
+    udp_io_hdr->uih_dst_port= to_addr->sin_port;
+    udp_io_hdr->uih_ip_opt_len= 0;
+    udp_io_hdr->uih_data_len= buffer->pointer;
+
+    /* Make the write synchronous by turning of asynch I/O */
+    flags= fcntl(fd, F_GETFD);
+    fcntl(fd, F_SETFD, flags & ~FD_ASYNCHIO);
+    result= write(fd, b, buffer->pointer + sizeof(udp_io_hdr_t));
+    s_errno= errno;
+    Xfree(b);
+    fcntl(fd, F_SETFD, flags);
+    if (result != buffer->pointer + sizeof(udp_io_hdr_t))
+       return FALSE;
+#endif /* MINIX */
+#endif
+    return TRUE;
+}
diff --git a/Xserver/lib/Xdmcp/GenKey.c b/Xserver/lib/Xdmcp/GenKey.c
new file mode 100644 (file)
index 0000000..002af42
--- /dev/null
@@ -0,0 +1,77 @@
+/*
+ * $XConsortium: GenKey.c,v 1.6 94/04/17 20:16:36 rws Exp $
+ * $XFree86: xc/lib/Xdmcp/GenKey.c,v 3.1 1996/10/23 13:08:39 dawes Exp $
+ *
+ * 
+Copyright (c) 1989  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+ * *
+ * Author:  Keith Packard, MIT X Consortium
+ */
+
+#include <X11/Xos.h>
+#include <X11/X.h>
+#include <X11/Xmd.h>
+#include <X11/Xdmcp.h>
+
+static getbits (data, dst)
+    long           data;
+    unsigned char   *dst;
+{
+    dst[0] = (data      ) & 0xff;
+    dst[1] = (data >>  8) & 0xff;
+    dst[2] = (data >> 16) & 0xff;
+    dst[3] = (data >> 24) & 0xff;
+}
+
+/* EMX is not STDC, but sometimes it is */
+#if defined(X_NOT_STDC_ENV) && !defined(__EMX__)
+#define Time_t long
+extern Time_t time ();
+#else
+#define Time_t time_t
+#endif
+
+#if defined(SYSV) || defined(SVR4)
+#define srandom srand48
+#define random lrand48
+#endif
+
+#ifdef linux
+#include <stdlib.h>
+#else
+long random();
+#endif
+
+void
+XdmcpGenerateKey (key)
+    XdmAuthKeyPtr   key;
+{
+    long    lowbits, highbits;
+
+    srandom ((int)getpid() ^ time((Time_t *)0));
+    lowbits = random ();
+    highbits = random ();
+    getbits (lowbits, key->data);
+    getbits (highbits, key->data + 4);
+}
diff --git a/Xserver/lib/Xdmcp/Imakefile b/Xserver/lib/Xdmcp/Imakefile
new file mode 100644 (file)
index 0000000..46236a2
--- /dev/null
@@ -0,0 +1,113 @@
+XCOMM $XConsortium: Imakefile /main/25 1996/09/28 16:43:40 rws $
+XCOMM $XFree86: xc/lib/Xdmcp/Imakefile,v 3.2 1996/12/23 06:00:48 dawes Exp $
+#define DoNormalLib NormalLibXdmcp
+#define DoSharedLib SharedLibXdmcp
+#define DoDebugLib DebugLibXdmcp
+#define DoProfileLib ProfileLibXdmcp
+#define LibName Xdmcp
+#define SoRev SOXDMCPREV
+#define IncSubdir X11
+
+#if HasXdmAuth
+AUTHDEFS = -DHASXDMAUTH
+AUTHSRCS = Wrap.c Unwrap.c Wraphelp.c
+AUTHOBJS = Wrap.o Unwrap.o Wraphelp.o
+#endif
+
+DEFINES = $(AUTHDEFS)
+
+HEADERS = Xdmcp.h
+
+SRCS = \
+       A8Eq.c \
+       AA8.c \
+       AA16.c \
+       AA32.c \
+       AofA8.c \
+       CA8.c \
+       DA8.c \
+       DA16.c \
+       DA32.c \
+       DAofA8.c \
+       Fill.c \
+       Flush.c \
+       RA8.c \
+       RA16.c \
+       RA32.c \
+       RAofA8.c \
+       RC8.c \
+       RC16.c \
+       RC32.c \
+       RHead.c \
+       RR.c \
+       RaA8.c \
+       RaA16.c \
+       RaA32.c \
+       RaAoA8.c \
+       WA8.c \
+       WA16.c \
+       WA32.c \
+       WAofA8.c \
+       WC8.c \
+       WC16.c \
+       WC32.c \
+       Whead.c \
+       Alloc.c \
+       CmpKey.c \
+       DecKey.c \
+       GenKey.c \
+       IncKey.c \
+       $(AUTHSRCS)
+
+OBJS = \
+       A8Eq.o \
+       AA8.o \
+       AA16.o \
+       AA32.o \
+       AofA8.o \
+       CA8.o \
+       DA8.o \
+       DA16.o \
+       DA32.o \
+       DAofA8.o \
+       Fill.o \
+       Flush.o \
+       RA8.o \
+       RA16.o \
+       RA32.o \
+       RAofA8.o \
+       RC8.o \
+       RC16.o \
+       RC32.o \
+       RHead.o \
+       RR.o \
+       RaA8.o \
+       RaA16.o \
+       RaA32.o \
+       RaAoA8.o \
+       WA8.o \
+       WA16.o \
+       WA32.o \
+       WAofA8.o \
+       WC8.o \
+       WC16.o \
+       WC32.o \
+       Whead.o \
+       Alloc.o \
+       CmpKey.o \
+       DecKey.o \
+       GenKey.o \
+       IncKey.o \
+       $(AUTHOBJS)
+
+#include <Library.tmpl>
+
+#ifdef WraphelpSourceRule
+WraphelpSourceRule()
+#endif
+SpecialCLibObjectRule(Fill,$(ICONFIGFILES),ConnectionFlags)
+SpecialCLibObjectRule(Flush,$(ICONFIGFILES),ConnectionFlags)
+
+InstallLinkKitLibrary(Xdmcp,$(LINKKITDIR)/lib)
+
+DependTarget()
diff --git a/Xserver/lib/Xdmcp/IncKey.c b/Xserver/lib/Xdmcp/IncKey.c
new file mode 100644 (file)
index 0000000..953ed4e
--- /dev/null
@@ -0,0 +1,46 @@
+/*
+ * $XConsortium: IncKey.c,v 1.3 94/04/17 20:16:37 gildea Exp $
+ *
+ * 
+Copyright (c) 1989  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+ * *
+ * Author:  Keith Packard, MIT X Consortium
+ */
+
+#include <X11/Xos.h>
+#include <X11/X.h>
+#include <X11/Xmd.h>
+#include <X11/Xdmcp.h>
+
+void
+XdmcpIncrementKey (key)
+    XdmAuthKeyPtr   key;
+{
+    int        i;
+
+    i = 7;
+    while (++key->data[i] == 0)
+       if (--i < 0)
+           break;
+}
diff --git a/Xserver/lib/Xdmcp/RA16.c b/Xserver/lib/Xdmcp/RA16.c
new file mode 100644 (file)
index 0000000..9253e3a
--- /dev/null
@@ -0,0 +1,62 @@
+/*
+ * $XConsortium: RA16.c,v 1.4 94/04/17 20:16:37 gildea Exp $
+ *
+ * 
+Copyright (c) 1989  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+ * *
+ * Author:  Keith Packard, MIT X Consortium
+ */
+
+#include <X11/Xos.h>
+#include <X11/X.h>
+#include <X11/Xmd.h>
+#include <X11/Xdmcp.h>
+
+int
+XdmcpReadARRAY16 (buffer, array)
+    XdmcpBufferPtr  buffer;
+    ARRAY16Ptr     array;
+{
+    int            i;
+
+    if (!XdmcpReadCARD8 (buffer, &array->length))
+       return FALSE;
+    if (!array->length)
+    {
+       array->data = 0;
+       return TRUE;
+    }
+    array->data = (CARD16 *) Xalloc (array->length * sizeof (CARD16));
+    if (!array->data)
+       return FALSE;
+    for (i = 0; i < (int)array->length; i++)
+    {
+       if (!XdmcpReadCARD16 (buffer, &array->data[i]))
+       {
+           Xfree (array->data);
+           return FALSE;
+       }
+    }
+    return TRUE;
+}
diff --git a/Xserver/lib/Xdmcp/RA32.c b/Xserver/lib/Xdmcp/RA32.c
new file mode 100644 (file)
index 0000000..31988e1
--- /dev/null
@@ -0,0 +1,62 @@
+/*
+ * $XConsortium: RA32.c,v 1.4 94/04/17 20:16:37 gildea Exp $
+ *
+ * 
+Copyright (c) 1989  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+ * *
+ * Author:  Keith Packard, MIT X Consortium
+ */
+
+#include <X11/Xos.h>
+#include <X11/X.h>
+#include <X11/Xmd.h>
+#include <X11/Xdmcp.h>
+
+int
+XdmcpReadARRAY32 (buffer, array)
+    XdmcpBufferPtr  buffer;
+    ARRAY32Ptr     array;
+{
+    int            i;
+
+    if (!XdmcpReadCARD8 (buffer, &array->length))
+       return FALSE;
+    if (!array->length)
+    {
+       array->data = 0;
+       return TRUE;
+    }
+    array->data = (CARD32 *) Xalloc (array->length * sizeof (CARD32));
+    if (!array->data)
+       return FALSE;
+    for (i = 0; i < (int)array->length; i++)
+    {
+       if (!XdmcpReadCARD32 (buffer, &array->data[i]))
+       {
+           Xfree (array->data);
+           return FALSE;
+       }
+    }
+    return TRUE;
+}
diff --git a/Xserver/lib/Xdmcp/RA8.c b/Xserver/lib/Xdmcp/RA8.c
new file mode 100644 (file)
index 0000000..def6c78
--- /dev/null
@@ -0,0 +1,62 @@
+/*
+ * $XConsortium: RA8.c,v 1.4 94/04/17 20:16:38 gildea Exp $
+ *
+ * 
+Copyright (c) 1989  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+ * *
+ * Author:  Keith Packard, MIT X Consortium
+ */
+
+#include <X11/Xos.h>
+#include <X11/X.h>
+#include <X11/Xmd.h>
+#include <X11/Xdmcp.h>
+
+int
+XdmcpReadARRAY8 (buffer, array)
+    XdmcpBufferPtr  buffer;
+    ARRAY8Ptr      array;
+{
+    int            i;
+
+    if (!XdmcpReadCARD16 (buffer, &array->length))
+       return FALSE;
+    if (!array->length)
+    {
+       array->data = 0;
+       return TRUE;
+    }
+    array->data = (CARD8 *) Xalloc (array->length * sizeof (CARD8));
+    if (!array->data)
+       return FALSE;
+    for (i = 0; i < (int)array->length; i++)
+    {
+       if (!XdmcpReadCARD8 (buffer, &array->data[i]))
+       {
+           Xfree (array->data);
+           return FALSE;
+       }
+    }
+    return TRUE;
+}
diff --git a/Xserver/lib/Xdmcp/RAofA8.c b/Xserver/lib/Xdmcp/RAofA8.c
new file mode 100644 (file)
index 0000000..9e054e8
--- /dev/null
@@ -0,0 +1,62 @@
+/*
+ * $XConsortium: RAofA8.c,v 1.4 94/04/17 20:16:38 gildea Exp $
+ *
+ * 
+Copyright (c) 1989  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+ * *
+ * Author:  Keith Packard, MIT X Consortium
+ */
+
+#include <X11/Xos.h>
+#include <X11/X.h>
+#include <X11/Xmd.h>
+#include <X11/Xdmcp.h>
+
+int
+XdmcpReadARRAYofARRAY8 (buffer, array)
+    XdmcpBufferPtr     buffer;
+    ARRAYofARRAY8Ptr   array;
+{
+    int            i;
+
+    if (!XdmcpReadCARD8 (buffer, &array->length))
+       return FALSE;
+    if (!array->length)
+    {
+       array->data = 0;
+       return TRUE;
+    }
+    array->data = (ARRAY8 *) Xalloc (array->length * sizeof (ARRAY8));
+    if (!array->data)
+       return FALSE;
+    for (i = 0; i < (int)array->length; i++)
+    {
+       if (!XdmcpReadARRAY8 (buffer, &array->data[i]))
+       {
+           Xfree (array->data);
+           return FALSE;
+       }
+    }
+    return TRUE;
+}
diff --git a/Xserver/lib/Xdmcp/RC16.c b/Xserver/lib/Xdmcp/RC16.c
new file mode 100644 (file)
index 0000000..ca4d404
--- /dev/null
@@ -0,0 +1,50 @@
+/*
+ * $XConsortium: RC16.c,v 1.3 94/04/17 20:16:39 gildea Exp $
+ *
+ * 
+Copyright (c) 1989  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+ * *
+ * Author:  Keith Packard, MIT X Consortium
+ */
+
+#include <X11/Xos.h>
+#include <X11/X.h>
+#include <X11/Xmd.h>
+#include <X11/Xdmcp.h>
+
+int
+XdmcpReadCARD16 (buffer, valuep)
+    XdmcpBufferPtr  buffer;
+    CARD16Ptr      valuep;
+{
+    CARD8   high, low;
+
+    if (XdmcpReadCARD8 (buffer, &high) &&
+        XdmcpReadCARD8 (buffer, &low))
+    {
+       *valuep = (((CARD16) high) << 8) | ((CARD16) low);
+       return TRUE;
+    }
+    return FALSE;
+}
diff --git a/Xserver/lib/Xdmcp/RC32.c b/Xserver/lib/Xdmcp/RC32.c
new file mode 100644 (file)
index 0000000..6494008
--- /dev/null
@@ -0,0 +1,54 @@
+/*
+ * $XConsortium: RC32.c,v 1.3 94/04/17 20:16:39 gildea Exp $
+ *
+ * 
+Copyright (c) 1989  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+ * *
+ * Author:  Keith Packard, MIT X Consortium
+ */
+
+#include <X11/Xos.h>
+#include <X11/X.h>
+#include <X11/Xmd.h>
+#include <X11/Xdmcp.h>
+
+int
+XdmcpReadCARD32 (buffer, valuep)
+    XdmcpBufferPtr  buffer;
+    CARD32Ptr      valuep;
+{
+    CARD8   byte0, byte1, byte2, byte3;
+    if (XdmcpReadCARD8 (buffer, &byte0) &&
+        XdmcpReadCARD8 (buffer, &byte1) &&
+       XdmcpReadCARD8 (buffer, &byte2) &&
+       XdmcpReadCARD8 (buffer, &byte3))
+    {
+       *valuep = (((CARD32) byte0) << 24) |
+                 (((CARD32) byte1) << 16) |
+                 (((CARD32) byte2) << 8) |
+                 (((CARD32) byte3));
+       return TRUE;
+    }
+    return FALSE;
+}
diff --git a/Xserver/lib/Xdmcp/RC8.c b/Xserver/lib/Xdmcp/RC8.c
new file mode 100644 (file)
index 0000000..c543e8f
--- /dev/null
@@ -0,0 +1,45 @@
+/*
+ * $XConsortium: RC8.c,v 1.4 94/04/17 20:16:40 gildea Exp $
+ *
+ * 
+Copyright (c) 1989  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+ * *
+ * Author:  Keith Packard, MIT X Consortium
+ */
+
+#include <X11/Xos.h>
+#include <X11/X.h>
+#include <X11/Xmd.h>
+#include <X11/Xdmcp.h>
+
+int
+XdmcpReadCARD8 (buffer, valuep)
+    XdmcpBufferPtr  buffer;
+    CARD8Ptr       valuep;
+{
+    if (buffer->pointer >= buffer->count)
+       return FALSE;
+    *valuep = (CARD8) buffer->data[buffer->pointer++];
+    return TRUE;
+}
diff --git a/Xserver/lib/Xdmcp/RHead.c b/Xserver/lib/Xdmcp/RHead.c
new file mode 100644 (file)
index 0000000..3676bb1
--- /dev/null
@@ -0,0 +1,46 @@
+/*
+ * $XConsortium: RHead.c,v 1.3 94/04/17 20:16:40 gildea Exp $
+ *
+ * 
+Copyright (c) 1989  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+ * *
+ * Author:  Keith Packard, MIT X Consortium
+ */
+
+#include <X11/Xos.h>
+#include <X11/X.h>
+#include <X11/Xmd.h>
+#include <X11/Xdmcp.h>
+
+int
+XdmcpReadHeader (buffer, header)
+    XdmcpBufferPtr  buffer;
+    XdmcpHeaderPtr  header;
+{
+    if (XdmcpReadCARD16 (buffer, &header->version) &&
+        XdmcpReadCARD16 (buffer, &header->opcode) &&
+       XdmcpReadCARD16 (buffer, &header->length))
+       return TRUE;
+    return FALSE;
+}
diff --git a/Xserver/lib/Xdmcp/RR.c b/Xserver/lib/Xdmcp/RR.c
new file mode 100644 (file)
index 0000000..babfe6e
--- /dev/null
@@ -0,0 +1,41 @@
+/*
+ * $XConsortium: RR.c,v 1.3 94/04/17 20:16:41 gildea Exp $
+ *
+ * 
+Copyright (c) 1989  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+ * *
+ * Author:  Keith Packard, MIT X Consortium
+ */
+
+#include <X11/Xos.h>
+#include <X11/X.h>
+#include <X11/Xmd.h>
+#include <X11/Xdmcp.h>
+
+int
+XdmcpReadRemaining (buffer)
+    XdmcpBufferPtr  buffer;
+{
+    return buffer->count - buffer->pointer;
+}
diff --git a/Xserver/lib/Xdmcp/RaA16.c b/Xserver/lib/Xdmcp/RaA16.c
new file mode 100644 (file)
index 0000000..fbb4e82
--- /dev/null
@@ -0,0 +1,49 @@
+/*
+ * $XConsortium: RaA16.c,v 1.3 94/04/17 20:16:41 gildea Exp $
+ *
+ * 
+Copyright (c) 1989  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+ * *
+ * Author:  Keith Packard, MIT X Consortium
+ */
+
+#include <X11/Xos.h>
+#include <X11/X.h>
+#include <X11/Xmd.h>
+#include <X11/Xdmcp.h>
+
+int
+XdmcpReallocARRAY16 (array, length)
+    ARRAY16Ptr array;
+    int                length;
+{
+    CARD16Ptr  newData;
+
+    newData = (CARD16Ptr) Xrealloc (array->data, length * sizeof (CARD16));
+    if (!newData)
+       return FALSE;
+    array->length = length;
+    array->data = newData;
+    return TRUE;
+}
diff --git a/Xserver/lib/Xdmcp/RaA32.c b/Xserver/lib/Xdmcp/RaA32.c
new file mode 100644 (file)
index 0000000..67dcc3e
--- /dev/null
@@ -0,0 +1,49 @@
+/*
+ * $XConsortium: RaA32.c,v 1.3 94/04/17 20:16:42 gildea Exp $
+ *
+ * 
+Copyright (c) 1989  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+ * *
+ * Author:  Keith Packard, MIT X Consortium
+ */
+
+#include <X11/Xos.h>
+#include <X11/X.h>
+#include <X11/Xmd.h>
+#include <X11/Xdmcp.h>
+
+int
+XdmcpReallocARRAY32 (array, length)
+    ARRAY32Ptr array;
+    int                length;
+{
+    CARD32Ptr  newData;
+
+    newData = (CARD32Ptr) Xrealloc (array->data, length * sizeof (CARD32));
+    if (!newData)
+       return FALSE;
+    array->length = length;
+    array->data = newData;
+    return TRUE;
+}
diff --git a/Xserver/lib/Xdmcp/RaA8.c b/Xserver/lib/Xdmcp/RaA8.c
new file mode 100644 (file)
index 0000000..93c2d2b
--- /dev/null
@@ -0,0 +1,49 @@
+/*
+ * $XConsortium: RaA8.c,v 1.3 94/04/17 20:16:42 gildea Exp $
+ *
+ * 
+Copyright (c) 1989  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+ * *
+ * Author:  Keith Packard, MIT X Consortium
+ */
+
+#include <X11/Xos.h>
+#include <X11/X.h>
+#include <X11/Xmd.h>
+#include <X11/Xdmcp.h>
+
+int
+XdmcpReallocARRAY8 (array, length)
+    ARRAY8Ptr  array;
+    int                length;
+{
+    CARD8Ptr   newData;
+
+    newData = (CARD8Ptr) Xrealloc (array->data, length * sizeof (CARD8));
+    if (!newData)
+       return FALSE;
+    array->length = length;
+    array->data = newData;
+    return TRUE;
+}
diff --git a/Xserver/lib/Xdmcp/RaAoA8.c b/Xserver/lib/Xdmcp/RaAoA8.c
new file mode 100644 (file)
index 0000000..765eac1
--- /dev/null
@@ -0,0 +1,49 @@
+/*
+ * $XConsortium: RaAoA8.c,v 1.3 94/04/17 20:16:43 gildea Exp $
+ *
+ * 
+Copyright (c) 1989  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+ * *
+ * Author:  Keith Packard, MIT X Consortium
+ */
+
+#include <X11/Xos.h>
+#include <X11/X.h>
+#include <X11/Xmd.h>
+#include <X11/Xdmcp.h>
+
+int
+XdmcpReallocARRAYofARRAY8 (array, length)
+    ARRAYofARRAY8Ptr   array;
+    int                        length;
+{
+    ARRAY8Ptr  newData;
+
+    newData = (ARRAY8Ptr) Xrealloc (array->data, length * sizeof (ARRAY8));
+    if (!newData)
+       return FALSE;
+    array->length = length;
+    array->data = newData;
+    return TRUE;
+}
diff --git a/Xserver/lib/Xdmcp/Unwrap.c b/Xserver/lib/Xdmcp/Unwrap.c
new file mode 100644 (file)
index 0000000..ea6ebb8
--- /dev/null
@@ -0,0 +1,90 @@
+/*
+ * $XConsortium: Unwrap.c,v 1.9 94/04/17 20:16:43 keith Exp $
+ *
+ * 
+Copyright (c) 1989  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+ * *
+ * Author:  Keith Packard, MIT X Consortium
+ */
+
+#include <X11/Xos.h>
+#include <X11/X.h>
+#include <X11/Xmd.h>
+#include <X11/Xdmcp.h>
+
+#ifdef HASXDMAUTH
+
+/*
+ * The following function exists only to demonstrate the
+ * desired functional interface for this routine.  You will
+ * need to add the appropriate algorithm if you wish to
+ * use XDM-AUTHENTICATION-1/XDM-AUTHORIZATION-1.
+ *
+ * The interface for this routine is quite simple.  All three
+ * arguments are arrays of 8 unsigned characters, the first two
+ * are 64 bits of useful data, the last is 56 bits of useful
+ * data packed into 8 bytes, using the low 7 bits of each
+ * byte, filling the high bit with odd parity.
+ *
+ * Examine the XDMCP specification for the correct algorithm
+ */
+
+#include "Wrap.h"
+
+void
+XdmcpUnwrap (input, wrapper, output, bytes)
+    unsigned char      *input, *output;
+    unsigned char      *wrapper;
+    int                        bytes;
+{
+    int                        i, j, k;
+    unsigned char      tmp[8];
+    unsigned char      blocks[2][8];
+    unsigned char      expand_wrapper[8];
+    auth_wrapper_schedule      schedule;
+
+    _XdmcpWrapperToOddParity (wrapper, expand_wrapper);
+    _XdmcpAuthSetup (expand_wrapper, schedule);
+
+    k = 0;
+    for (j = 0; j < bytes; j += 8)
+    {
+       if (bytes - j < 8)
+           return; /* bad input length */
+       for (i = 0; i < 8; i++)
+           blocks[k][i] = input[j + i];
+       _XdmcpAuthDoIt ((unsigned char *) (input + j), (unsigned char *) tmp, schedule, 0);
+       /* block chaining */
+       k = (k == 0) ? 1 : 0;
+       for (i = 0; i < 8; i++)
+       {
+           if (j == 0)
+               output[j + i] = tmp[i];
+           else
+               output[j + i] = tmp[i] ^ blocks[k][i];
+       }
+    }
+}
+
+#endif /* HASXDMAUTH */
diff --git a/Xserver/lib/Xdmcp/WA16.c b/Xserver/lib/Xdmcp/WA16.c
new file mode 100644 (file)
index 0000000..d172450
--- /dev/null
@@ -0,0 +1,49 @@
+/*
+ * $XConsortium: WA16.c,v 1.4 94/04/17 20:16:44 gildea Exp $
+ *
+ * 
+Copyright (c) 1989  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+ * *
+ * Author:  Keith Packard, MIT X Consortium
+ */
+
+#include <X11/Xos.h>
+#include <X11/X.h>
+#include <X11/Xmd.h>
+#include <X11/Xdmcp.h>
+
+int
+XdmcpWriteARRAY16 (buffer, array)
+    XdmcpBufferPtr  buffer;
+    ARRAY16Ptr     array;
+{
+    int        i;
+
+    if (!XdmcpWriteCARD8 (buffer, array->length))
+       return FALSE;
+    for (i = 0; i < (int)array->length; i++)
+       if (!XdmcpWriteCARD16 (buffer, array->data[i]))
+           return FALSE;
+    return TRUE;
+}
diff --git a/Xserver/lib/Xdmcp/WA32.c b/Xserver/lib/Xdmcp/WA32.c
new file mode 100644 (file)
index 0000000..2b27342
--- /dev/null
@@ -0,0 +1,49 @@
+/*
+ * $XConsortium: WA32.c,v 1.4 94/04/17 20:16:44 gildea Exp $
+ *
+ * 
+Copyright (c) 1989  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+ * *
+ * Author:  Keith Packard, MIT X Consortium
+ */
+
+#include <X11/Xos.h>
+#include <X11/X.h>
+#include <X11/Xmd.h>
+#include <X11/Xdmcp.h>
+
+int
+XdmcpWriteARRAY32 (buffer, array)
+    XdmcpBufferPtr  buffer;
+    ARRAY32Ptr     array;
+{
+    int        i;
+
+    if (!XdmcpWriteCARD8 (buffer, array->length))
+       return FALSE;
+    for (i = 0; i < (int)array->length; i++)
+       if (!XdmcpWriteCARD32 (buffer, array->data[i]))
+           return FALSE;
+    return TRUE;
+}
diff --git a/Xserver/lib/Xdmcp/WA8.c b/Xserver/lib/Xdmcp/WA8.c
new file mode 100644 (file)
index 0000000..0a76663
--- /dev/null
@@ -0,0 +1,49 @@
+/*
+ * $XConsortium: WA8.c,v 1.4 94/04/17 20:16:45 gildea Exp $
+ *
+ * 
+Copyright (c) 1989  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+ * *
+ * Author:  Keith Packard, MIT X Consortium
+ */
+
+#include <X11/Xos.h>
+#include <X11/X.h>
+#include <X11/Xmd.h>
+#include <X11/Xdmcp.h>
+
+int
+XdmcpWriteARRAY8 (buffer, array)
+    XdmcpBufferPtr  buffer;
+    ARRAY8Ptr      array;
+{
+    int        i;
+
+    if (!XdmcpWriteCARD16 (buffer, array->length))
+       return FALSE;
+    for (i = 0; i < (int)array->length; i++)
+       if (!XdmcpWriteCARD8 (buffer, array->data[i]))
+           return FALSE;
+    return TRUE;
+}
diff --git a/Xserver/lib/Xdmcp/WAofA8.c b/Xserver/lib/Xdmcp/WAofA8.c
new file mode 100644 (file)
index 0000000..9618179
--- /dev/null
@@ -0,0 +1,49 @@
+/*
+ * $XConsortium: WAofA8.c,v 1.5 94/04/17 20:16:45 gildea Exp $
+ *
+ * 
+Copyright (c) 1989  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+ * *
+ * Author:  Keith Packard, MIT X Consortium
+ */
+
+#include <X11/Xos.h>
+#include <X11/X.h>
+#include <X11/Xmd.h>
+#include <X11/Xdmcp.h>
+
+int
+XdmcpWriteARRAYofARRAY8 (buffer, array)
+    XdmcpBufferPtr     buffer;
+    ARRAYofARRAY8Ptr   array;
+{
+    int        i;
+
+    if (!XdmcpWriteCARD8 (buffer, array->length))
+       return FALSE;
+    for (i = 0; i < (int)array->length; i++)
+       if (!XdmcpWriteARRAY8 (buffer, &array->data[i]))
+           return FALSE;
+    return TRUE;
+}
diff --git a/Xserver/lib/Xdmcp/WC16.c b/Xserver/lib/Xdmcp/WC16.c
new file mode 100644 (file)
index 0000000..4e52206
--- /dev/null
@@ -0,0 +1,46 @@
+/*
+ * $XConsortium: WC16.c,v 1.3 94/04/17 20:16:46 gildea Exp $
+ *
+ * 
+Copyright (c) 1989  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+ * *
+ * Author:  Keith Packard, MIT X Consortium
+ */
+
+#include <X11/Xos.h>
+#include <X11/X.h>
+#include <X11/Xmd.h>
+#include <X11/Xdmcp.h>
+
+int
+XdmcpWriteCARD16 (buffer, value)
+    XdmcpBufferPtr  buffer;
+    CARD16         value;
+{
+    if (!XdmcpWriteCARD8 (buffer, value >> 8))
+       return FALSE;
+    if (!XdmcpWriteCARD8 (buffer, value & 0xff))
+       return FALSE;
+    return TRUE;
+}
diff --git a/Xserver/lib/Xdmcp/WC32.c b/Xserver/lib/Xdmcp/WC32.c
new file mode 100644 (file)
index 0000000..6631867
--- /dev/null
@@ -0,0 +1,50 @@
+/*
+ * $XConsortium: WC32.c,v 1.3 94/04/17 20:16:46 gildea Exp $
+ *
+ * 
+Copyright (c) 1989  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+ * *
+ * Author:  Keith Packard, MIT X Consortium
+ */
+
+#include <X11/Xos.h>
+#include <X11/X.h>
+#include <X11/Xmd.h>
+#include <X11/Xdmcp.h>
+
+int
+XdmcpWriteCARD32 (buffer, value)
+    XdmcpBufferPtr  buffer;
+    CARD32         value;
+{
+    if (!XdmcpWriteCARD8 (buffer, value >> 24))
+       return FALSE;
+    if (!XdmcpWriteCARD8 (buffer, (value >> 16) & 0xff))
+       return FALSE;
+    if (!XdmcpWriteCARD8 (buffer, (value >> 8) & 0xff))
+       return FALSE;
+    if (!XdmcpWriteCARD8 (buffer, value & 0xff))
+       return FALSE;
+    return TRUE;
+}
diff --git a/Xserver/lib/Xdmcp/WC8.c b/Xserver/lib/Xdmcp/WC8.c
new file mode 100644 (file)
index 0000000..168a718
--- /dev/null
@@ -0,0 +1,45 @@
+/*
+ * $XConsortium: WC8.c,v 1.3 94/04/17 20:16:47 gildea Exp $
+ *
+ * 
+Copyright (c) 1989  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+ * *
+ * Author:  Keith Packard, MIT X Consortium
+ */
+
+#include <X11/Xos.h>
+#include <X11/X.h>
+#include <X11/Xmd.h>
+#include <X11/Xdmcp.h>
+
+int
+XdmcpWriteCARD8 (buffer, value)
+    XdmcpBufferPtr  buffer;
+    CARD8          value;
+{
+    if (buffer->pointer >= buffer->size)
+       return FALSE;
+    buffer->data[buffer->pointer++] = (BYTE) value;
+    return TRUE;
+}
diff --git a/Xserver/lib/Xdmcp/Whead.c b/Xserver/lib/Xdmcp/Whead.c
new file mode 100644 (file)
index 0000000..e864546
--- /dev/null
@@ -0,0 +1,60 @@
+/*
+ * $XConsortium: Whead.c,v 1.4 94/04/17 20:16:47 gildea Exp $
+ *
+ * 
+Copyright (c) 1989  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+ * *
+ * Author:  Keith Packard, MIT X Consortium
+ */
+
+#include <X11/Xos.h>
+#include <X11/X.h>
+#include <X11/Xmd.h>
+#include <X11/Xdmcp.h>
+
+int
+XdmcpWriteHeader (buffer, header)
+    XdmcpBufferPtr  buffer;
+    XdmcpHeaderPtr  header;
+{
+    BYTE    *newData;
+
+    if ((int)buffer->size < 6 + (int)header->length)
+    {
+       newData = (BYTE *) Xalloc (XDM_MAX_MSGLEN * sizeof (BYTE));
+       if (!newData)
+           return FALSE;
+       Xfree (buffer->data);
+       buffer->data = newData;
+       buffer->size = XDM_MAX_MSGLEN;
+    }
+    buffer->pointer = 0;
+    if (!XdmcpWriteCARD16 (buffer, header->version))
+       return FALSE;
+    if (!XdmcpWriteCARD16 (buffer, header->opcode))
+       return FALSE;
+    if (!XdmcpWriteCARD16 (buffer, header->length))
+       return FALSE;
+    return TRUE;
+}
diff --git a/Xserver/lib/Xdmcp/Wrap.c b/Xserver/lib/Xdmcp/Wrap.c
new file mode 100644 (file)
index 0000000..9cecc34
--- /dev/null
@@ -0,0 +1,128 @@
+/*
+ * $XConsortium: Wrap.c,v 1.9 94/04/17 20:16:48 keith Exp $
+ *
+ * 
+Copyright (c) 1989  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+ * *
+ * Author:  Keith Packard, MIT X Consortium
+ */
+
+#include <X11/Xos.h>
+#include <X11/X.h>
+#include <X11/Xmd.h>
+#include <X11/Xdmcp.h>
+
+#ifdef HASXDMAUTH
+
+/*
+ * The following function exists only to demonstrate the
+ * desired functional interface for this routine.  You will
+ * need to add the appropriate algorithm if you wish to
+ * use XDM-AUTHENTICATION-1/XDM-AUTHORIZATION-1.
+ *
+ * Examine the XDMCP specification for the correct algorithm
+ */
+
+#include "Wrap.h"
+
+void
+XdmcpWrap (input, wrapper, output, bytes)
+    unsigned char      *input, *output;
+    unsigned char      *wrapper;
+    int                        bytes;
+{
+    int                        i, j;
+    int                        len;
+    unsigned char      tmp[8];
+    unsigned char      expand_wrapper[8];
+    auth_wrapper_schedule      schedule;
+
+    _XdmcpWrapperToOddParity (wrapper, expand_wrapper);
+    _XdmcpAuthSetup (expand_wrapper, schedule);
+    for (j = 0; j < bytes; j += 8)
+    {
+       len = 8;
+       if (bytes - j < len)
+           len = bytes - j;
+       /* block chaining */
+       for (i = 0; i < len; i++)
+       {
+           if (j == 0)
+               tmp[i] = input[i];
+           else
+               tmp[i] = input[j + i] ^ output[j - 8 + i];
+       }
+       for (; i < 8; i++)
+       {
+           if (j == 0)
+               tmp[i] = 0;
+           else
+               tmp[i] = 0 ^ output[j - 8 + i];
+       }
+       _XdmcpAuthDoIt (tmp, (output + j), schedule, 1);
+    }
+}
+
+/*
+ * Given a 56 bit wrapper in XDMCP format, create a 56
+ * bit wrapper in 7-bits + odd parity format
+ */
+
+static int
+OddParity (c)
+    unsigned char   c;
+{
+    c = c ^ (c >> 4);
+    c = c ^ (c >> 2);
+    c = c ^ (c >> 1);
+    return ~c & 0x1;
+}
+
+/*
+ * Spread the 56 bit wrapper among 8 bytes, using the upper 7 bits
+ * of each byte, and storing an odd parity bit in the low bit
+ */
+
+void
+_XdmcpWrapperToOddParity (in, out)
+    unsigned char   *in, *out;
+{
+    int                    ashift, bshift;
+    int                    i;
+    unsigned char   c;
+
+    ashift = 7;
+    bshift = 1;
+    for (i = 0; i < 7; i++)
+    {
+       c = ((in[i] << ashift) | (in[i+1] >> bshift)) & 0x7f;
+       out[i] = (c << 1) | OddParity (c);
+       ashift--;
+       bshift++;
+    }
+    c = in[i];
+    out[i] = (c << 1) | OddParity(c);
+}
+
+#endif
diff --git a/Xserver/lib/Xdmcp/Wrap.h b/Xserver/lib/Xdmcp/Wrap.h
new file mode 100644 (file)
index 0000000..7f4a0a3
--- /dev/null
@@ -0,0 +1,10 @@
+/* $XConsortium: Wrap.h,v 1.3 94/02/06 20:09:49 rws Exp $ */
+/*
+ * header file for compatibility with something useful
+ */
+
+typedef unsigned char auth_cblock[8];  /* block size */
+
+typedef struct auth_ks_struct { auth_cblock _; } auth_wrapper_schedule[16];
+
+extern void _XdmcpWrapperToOddParity();
diff --git a/Xserver/lib/Xdmcp/Wraphelp.c b/Xserver/lib/Xdmcp/Wraphelp.c
new file mode 100644 (file)
index 0000000..4e2b2ec
--- /dev/null
@@ -0,0 +1,401 @@
+/*
+ * This program implements the
+ * Proposed Federal Information Processing
+ *  Data Encryption Standard.
+ * See Federal Register, March 17, 1975 (40FR12134)
+ */
+
+/*
+ * Initial permutation,
+ */
+static char    IP[] = {
+       58,50,42,34,26,18,10, 2,
+       60,52,44,36,28,20,12, 4,
+       62,54,46,38,30,22,14, 6,
+       64,56,48,40,32,24,16, 8,
+       57,49,41,33,25,17, 9, 1,
+       59,51,43,35,27,19,11, 3,
+       61,53,45,37,29,21,13, 5,
+       63,55,47,39,31,23,15, 7,
+};
+
+/*
+ * Final permutation, FP = IP^(-1)
+ */
+static char    FP[] = {
+       40, 8,48,16,56,24,64,32,
+       39, 7,47,15,55,23,63,31,
+       38, 6,46,14,54,22,62,30,
+       37, 5,45,13,53,21,61,29,
+       36, 4,44,12,52,20,60,28,
+       35, 3,43,11,51,19,59,27,
+       34, 2,42,10,50,18,58,26,
+       33, 1,41, 9,49,17,57,25,
+};
+
+/*
+ * Permuted-choice 1 from the key bits
+ * to yield C and D.
+ * Note that bits 8,16... are left out:
+ * They are intended for a parity check.
+ */
+static char    PC1_C[] = {
+       57,49,41,33,25,17, 9,
+        1,58,50,42,34,26,18,
+       10, 2,59,51,43,35,27,
+       19,11, 3,60,52,44,36,
+};
+
+static char    PC1_D[] = {
+       63,55,47,39,31,23,15,
+        7,62,54,46,38,30,22,
+       14, 6,61,53,45,37,29,
+       21,13, 5,28,20,12, 4,
+};
+
+/*
+ * Sequence of shifts used for the key schedule.
+*/
+static char    shifts[] = {
+       1,1,2,2,2,2,2,2,1,2,2,2,2,2,2,1,
+};
+
+/*
+ * Permuted-choice 2, to pick out the bits from
+ * the CD array that generate the key schedule.
+ */
+static char    PC2_C[] = {
+       14,17,11,24, 1, 5,
+        3,28,15, 6,21,10,
+       23,19,12, 4,26, 8,
+       16, 7,27,20,13, 2,
+};
+
+static char    PC2_D[] = {
+       41,52,31,37,47,55,
+       30,40,51,45,33,48,
+       44,49,39,56,34,53,
+       46,42,50,36,29,32,
+};
+
+/*
+ * The C and D arrays used to calculate the key schedule.
+ */
+
+static char    C[28];
+static char    D[28];
+
+/*
+ * The key schedule.
+ * Generated from the key.
+ */
+static char    KS[16][48];
+
+/*
+ * The E bit-selection table.
+ */
+static char    E[48];
+static char    e[] = {
+       32, 1, 2, 3, 4, 5,
+        4, 5, 6, 7, 8, 9,
+        8, 9,10,11,12,13,
+       12,13,14,15,16,17,
+       16,17,18,19,20,21,
+       20,21,22,23,24,25,
+       24,25,26,27,28,29,
+       28,29,30,31,32, 1,
+};
+
+/*
+ * Set up the key schedule from the key.
+ */
+
+static
+setkey(key)
+char *key;
+{
+       int     i, j, k;
+       int     t;
+       char    *ptr;
+
+       /*
+        * First, generate C and D by permuting
+        * the key.  The low order bit of each
+        * 8-bit char is not used, so C and D are only 28
+        * bits apiece.
+        */
+       for (i=0; i<28; i++) {
+               C[i] = key[PC1_C[i]-1];
+               D[i] = key[PC1_D[i]-1];
+       }
+       /*
+        * To generate Ki, rotate C and D according
+        * to schedule and pick up a permutation
+        * using PC2.
+        */
+       for (i=0; i<16; i++) {
+               /*
+                * rotate.
+                */
+               for (k=0; k<shifts[i]; k++) {
+                       t = C[0];
+                       ptr = C;
+                       for (j=0; j<28-1; j++)
+                       {
+                               *ptr = ptr[1];
+                               ptr++;
+                       }
+                       C[27] = t;
+                       t = D[0];
+                       ptr = D;
+                       for (j=0; j<28-1; j++)
+                       {
+                               *ptr = ptr[1];
+                               ptr++;
+                       }
+                       D[27] = t;
+               }
+               /*
+                * get Ki. Note C and D are concatenated.
+                */
+               ptr = &KS[i][0];
+               for (j=0; j<24; j++) {
+                       ptr[j] = C[PC2_C[j]-1];
+                       ptr[j+24] = D[PC2_D[j]-28-1];
+               }
+       }
+
+       for(i=0;i<48;i++)
+               E[i] = e[i];
+}
+
+/*
+ * The 8 selection functions.
+ * For some reason, they give a 0-origin
+ * index, unlike everything else.
+ */
+static char    S[8][64] = {
+       14, 4,13, 1, 2,15,11, 8, 3,10, 6,12, 5, 9, 0, 7,
+        0,15, 7, 4,14, 2,13, 1,10, 6,12,11, 9, 5, 3, 8,
+        4, 1,14, 8,13, 6, 2,11,15,12, 9, 7, 3,10, 5, 0,
+       15,12, 8, 2, 4, 9, 1, 7, 5,11, 3,14,10, 0, 6,13,
+
+       15, 1, 8,14, 6,11, 3, 4, 9, 7, 2,13,12, 0, 5,10,
+        3,13, 4, 7,15, 2, 8,14,12, 0, 1,10, 6, 9,11, 5,
+        0,14, 7,11,10, 4,13, 1, 5, 8,12, 6, 9, 3, 2,15,
+       13, 8,10, 1, 3,15, 4, 2,11, 6, 7,12, 0, 5,14, 9,
+
+       10, 0, 9,14, 6, 3,15, 5, 1,13,12, 7,11, 4, 2, 8,
+       13, 7, 0, 9, 3, 4, 6,10, 2, 8, 5,14,12,11,15, 1,
+       13, 6, 4, 9, 8,15, 3, 0,11, 1, 2,12, 5,10,14, 7,
+        1,10,13, 0, 6, 9, 8, 7, 4,15,14, 3,11, 5, 2,12,
+
+        7,13,14, 3, 0, 6, 9,10, 1, 2, 8, 5,11,12, 4,15,
+       13, 8,11, 5, 6,15, 0, 3, 4, 7, 2,12, 1,10,14, 9,
+       10, 6, 9, 0,12,11, 7,13,15, 1, 3,14, 5, 2, 8, 4,
+        3,15, 0, 6,10, 1,13, 8, 9, 4, 5,11,12, 7, 2,14,
+
+        2,12, 4, 1, 7,10,11, 6, 8, 5, 3,15,13, 0,14, 9,
+       14,11, 2,12, 4, 7,13, 1, 5, 0,15,10, 3, 9, 8, 6,
+        4, 2, 1,11,10,13, 7, 8,15, 9,12, 5, 6, 3, 0,14,
+       11, 8,12, 7, 1,14, 2,13, 6,15, 0, 9,10, 4, 5, 3,
+
+       12, 1,10,15, 9, 2, 6, 8, 0,13, 3, 4,14, 7, 5,11,
+       10,15, 4, 2, 7,12, 9, 5, 6, 1,13,14, 0,11, 3, 8,
+        9,14,15, 5, 2, 8,12, 3, 7, 0, 4,10, 1,13,11, 6,
+        4, 3, 2,12, 9, 5,15,10,11,14, 1, 7, 6, 0, 8,13,
+
+        4,11, 2,14,15, 0, 8,13, 3,12, 9, 7, 5,10, 6, 1,
+       13, 0,11, 7, 4, 9, 1,10,14, 3, 5,12, 2,15, 8, 6,
+        1, 4,11,13,12, 3, 7,14,10,15, 6, 8, 0, 5, 9, 2,
+        6,11,13, 8, 1, 4,10, 7, 9, 5, 0,15,14, 2, 3,12,
+
+       13, 2, 8, 4, 6,15,11, 1,10, 9, 3,14, 5, 0,12, 7,
+        1,15,13, 8,10, 3, 7, 4,12, 5, 6,11, 0,14, 9, 2,
+        7,11, 4, 1, 9,12,14, 2, 0, 6,10,13,15, 3, 5, 8,
+        2, 1,14, 7, 4,10, 8,13,15,12, 9, 0, 3, 5, 6,11,
+};
+
+/*
+ * P is a permutation on the selected combination
+ * of the current L and key.
+ */
+static char    P[] = {
+       16, 7,20,21,
+       29,12,28,17,
+        1,15,23,26,
+        5,18,31,10,
+        2, 8,24,14,
+       32,27, 3, 9,
+       19,13,30, 6,
+       22,11, 4,25,
+};
+
+/*
+ * The current block, divided into 2 halves.
+ */
+
+static char    L[64];
+#define R   (L + 32)
+static char    tempL[32];
+static char    f[32];
+
+/*
+ * The combination of the key and the input, before selection.
+ */
+static char    preS[48];
+
+/*
+ * The payoff: encrypt a block.
+ */
+
+static
+encrypt (block, edflag)
+char *block;
+{
+       int i, ii;
+       register t, j, k;
+
+       /*
+        * First, permute the bits in the input
+        */
+       for (j=0; j<64; j++)
+               L[j] = block[IP[j]-1];
+       /*
+        * Perform an encryption operation 16 times.
+        */
+       for (ii=0; ii<16; ii++) {
+/*             print_bits ("L R", L); */
+               /*
+                * Set direction
+                */
+               if (edflag)
+                       i = 15-ii;
+               else
+                       i = ii;
+               /*
+                * Save the R array,
+                * which will be the new L.
+                */
+               for (j=0; j<32; j++)
+                       tempL[j] = R[j];
+               /*
+                * Expand R to 48 bits using the E selector;
+                * exclusive-or with the current key bits.
+                */
+               for (j=0; j<48; j++)
+                       preS[j] = R[E[j]-1] ^ KS[i][j];
+               /*
+                * The pre-select bits are now considered
+                * in 8 groups of 6 bits each.
+                * The 8 selection functions map these
+                * 6-bit quantities into 4-bit quantities
+                * and the results permuted
+                * to make an f(R, K).
+                * The indexing into the selection functions
+                * is peculiar; it could be simplified by
+                * rewriting the tables.
+                */
+               for (j=0; j<8; j++) {
+                       t = 6*j;
+                       k = S[j][(preS[t+0]<<5)+
+                               (preS[t+1]<<3)+
+                               (preS[t+2]<<2)+
+                               (preS[t+3]<<1)+
+                               (preS[t+4]<<0)+
+                               (preS[t+5]<<4)];
+                       t = 4*j;
+                       f[t+0] = (k>>3)&01;
+                       f[t+1] = (k>>2)&01;
+                       f[t+2] = (k>>1)&01;
+                       f[t+3] = (k>>0)&01;
+               }
+               /*
+                * The new R is L ^ f(R, K).
+                * The f here has to be permuted first, though.
+                */
+               for (j=0; j<32; j++)
+                       R[j] = L[j] ^ f[P[j]-1];
+               /*
+                * Finally, the new L (the original R)
+                * is copied back.
+                */
+               for (j=0; j<32; j++)
+                       L[j] = tempL[j];
+       }
+       /*
+        * The output L and R are reversed.
+        */
+       for (j=0; j<32; j++) {
+               t = L[j];
+               L[j] = R[j];
+               R[j] = t;
+       }
+       /*
+        * The final output
+        * gets the inverse permutation of the very original.
+        */
+       for (j=0; j<64; j++)
+               block[j] = L[FP[j]-1];
+}
+
+static
+bytes_to_bits (bytes, bits)
+    unsigned char   *bytes;
+    char           *bits;
+{
+    int            bit, byte, value;
+
+    for (byte = 0; byte < 8; byte++)
+    {
+       value = *bytes++;
+       for (bit = 0; bit < 8; bit++)
+           *bits++ = (value >> (7-bit)) & 1;
+    }
+}
+
+static
+bits_to_bytes (bits, bytes)
+    char           *bits;
+    unsigned char   *bytes;
+{
+    int            bit, byte, value;
+
+    for (byte = 0; byte < 8; byte++)
+    {
+       value = 0;
+       for (bit = 0; bit < 8; bit++)
+           value |= *bits++ << (7-bit);
+       *bytes++ = value;
+    }
+}
+
+/*
+ * Interface compatible with Kerberos DES implementation
+ */
+
+# include   "Wrap.h"
+
+/*ARGSUSED*/
+_XdmcpAuthSetup (key, schedule)
+    auth_cblock                key;
+    auth_wrapper_schedule      schedule;
+{
+    char    expand_key[64];
+
+    bytes_to_bits ((unsigned char *) key, expand_key);
+    setkey (expand_key);
+}
+
+/*ARGSUSED*/
+_XdmcpAuthDoIt (input, output, schedule, edflag)
+    auth_cblock                input, output;
+    auth_wrapper_schedule      schedule;
+    int                        edflag;
+{
+    char    expand_input[64];
+
+    bytes_to_bits ((unsigned char *) input, expand_input);
+    encrypt (expand_input, !edflag);
+    bits_to_bytes (expand_input, (unsigned char *) output);
+}
diff --git a/Xserver/lib/Xdmcp/Xdmcp.h b/Xserver/lib/Xdmcp/Xdmcp.h
new file mode 100644 (file)
index 0000000..ae9d476
--- /dev/null
@@ -0,0 +1,141 @@
+/* $XConsortium: Xdmcp.h,v 1.9 95/06/07 18:30:59 gildea Exp $ */
+/* $XFree86: xc/lib/Xdmcp/Xdmcp.h,v 3.1 1996/01/05 13:12:04 dawes Exp $ */
+/*
+ * Copyright 1989 Network Computing Devices, Inc., Mountain View, California.
+ *
+ * Permission to use, copy, modify, and distribute this software and its
+ * documentation for any purpose and without fee is hereby granted, provided
+ * that the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the name of N.C.D. not be used in advertising or
+ * publicity pertaining to distribution of the software without specific,
+ * written prior permission.  N.C.D. makes no representations about the
+ * suitability of this software for any purpose.  It is provided "as is"
+ * without express or implied warranty.
+ *
+ */
+
+#ifndef _XDMCP_H_
+#define _XDMCP_H_
+#define XDM_PROTOCOL_VERSION   1
+#define XDM_UDP_PORT           177
+#define XDM_MAX_MSGLEN         8192
+#define XDM_MIN_RTX            2
+#define XDM_MAX_RTX            32
+#define XDM_RTX_LIMIT          7
+#define XDM_KA_RTX_LIMIT       4
+#define XDM_DEF_DORMANCY       (3 * 60)        /* 3 minutes */
+#define XDM_MAX_DORMANCY       (24 * 60 * 60)  /* 24 hours */
+
+typedef enum {
+    BROADCAST_QUERY = 1, QUERY, INDIRECT_QUERY, FORWARD_QUERY,
+    WILLING, UNWILLING, REQUEST, ACCEPT, DECLINE, MANAGE, REFUSE, 
+    FAILED, KEEPALIVE, ALIVE 
+} xdmOpCode;
+
+typedef enum {
+    XDM_QUERY, XDM_BROADCAST, XDM_INDIRECT, XDM_COLLECT_QUERY,
+    XDM_COLLECT_BROADCAST_QUERY, XDM_COLLECT_INDIRECT_QUERY,
+    XDM_START_CONNECTION, XDM_AWAIT_REQUEST_RESPONSE,
+    XDM_AWAIT_MANAGE_RESPONSE, XDM_MANAGE, XDM_RUN_SESSION, XDM_OFF,
+    XDM_AWAIT_USER_INPUT, XDM_KEEPALIVE, XDM_AWAIT_ALIVE_RESPONSE
+} xdmcp_states;
+
+#ifdef NOTDEF
+/* table of hosts */
+
+#define XDM_MAX_STR_LEN 21
+#define XDM_MAX_HOSTS 20
+struct xdm_host_table {
+  struct sockaddr_in sockaddr;
+  char name[XDM_MAX_STR_LEN];
+  char status[XDM_MAX_STR_LEN];
+};
+#endif /* NOTDEF */
+
+typedef CARD8  *CARD8Ptr;
+typedef CARD16 *CARD16Ptr;
+typedef CARD32 *CARD32Ptr;
+
+typedef struct _ARRAY8 {
+    CARD16     length;
+    CARD8Ptr   data;
+} ARRAY8, *ARRAY8Ptr;
+
+typedef struct _ARRAY16 {
+    CARD8      length;
+    CARD16Ptr  data;
+} ARRAY16, *ARRAY16Ptr;
+
+typedef struct _ARRAY32 {
+    CARD8      length;
+    CARD32Ptr  data;
+} ARRAY32, *ARRAY32Ptr;
+
+typedef struct _ARRAYofARRAY8 {
+    CARD8      length;
+    ARRAY8Ptr  data;
+} ARRAYofARRAY8, *ARRAYofARRAY8Ptr;
+
+typedef struct _XdmcpHeader {
+    CARD16  version, opcode, length;
+} XdmcpHeader, *XdmcpHeaderPtr;
+
+typedef struct _XdmcpBuffer {
+    BYTE    *data;
+    int            size;               /* size of buffer pointed by to data */
+    int            pointer;            /* current index into data */
+    int            count;              /* bytes read from network into data */
+} XdmcpBuffer, *XdmcpBufferPtr;
+
+typedef struct _XdmAuthKey {
+    BYTE    data[8];
+} XdmAuthKeyRec, *XdmAuthKeyPtr;
+
+
+/* implementation-independent network address structure.
+   Equiv to sockaddr* for sockets and netbuf* for STREAMS. */
+
+typedef char *XdmcpNetaddr;
+
+
+extern int XdmcpWriteCARD8(),          XdmcpWriteCARD16();
+extern int XdmcpWriteCARD32();
+extern int XdmcpWriteARRAY8(),         XdmcpWriteARRAY16();
+extern int XdmcpWriteARRAY32(),                XdmcpWriteARRAYofARRAY8();
+extern int XdmcpWriteHeader(),         XdmcpFlush();
+
+extern int XdmcpReadCARD8(),           XdmcpReadCARD16();
+extern int XdmcpReadCARD32();
+extern int XdmcpReadARRAY8(),          XdmcpReadARRAY16();
+extern int XdmcpReadARRAY32(),         XdmcpReadARRAYofARRAY8();
+extern int XdmcpReadHeader(),          XdmcpFill();
+
+extern int  XdmcpReadRemaining();
+
+extern void XdmcpDisposeARRAY8(),      XdmcpDisposeARRAY16();
+extern void XdmcpDisposeARRAY32(),     XdmcpDisposeARRAYofARRAY8();
+
+extern int XdmcpCopyARRAY8();
+
+extern int XdmcpARRAY8Equal();
+
+#ifdef HASXDMAUTH
+extern void XdmcpGenerateKey();
+extern void XdmcpIncrementKey();
+extern void XdmcpDecrementKey();
+extern void XdmcpWrap();
+extern void XdmcpUnwrap();
+#endif
+
+#ifndef TRUE
+#define TRUE   1
+#define FALSE  0
+#endif
+
+#if !defined(Xalloc) && !defined(xalloc) && !defined(Xrealloc)
+extern long *Xalloc (), *Xrealloc ();
+extern void Xfree();
+#endif
+
+#endif /* _XDMCP_H_ */
diff --git a/Xserver/lib/font/Imakefile b/Xserver/lib/font/Imakefile
new file mode 100644 (file)
index 0000000..3599260
--- /dev/null
@@ -0,0 +1,35 @@
+XCOMM $XConsortium: Imakefile /main/12 1995/12/07 21:15:22 gildea $
+XCOMM $XFree86: xc/lib/font/Imakefile,v 3.5.4.2 1997/05/11 05:04:09 dawes Exp $
+#include <Server.tmpl>
+
+#define        IHaveSubdirs
+
+SUBDIRS = bitmap fontfile fc Speedo Type1 util
+OBJS = bitmap/?*.o fontfile/?*.o fc/?*.o Speedo/?*.o Type1/?*.o util/?*.o
+DONES = bitmap/DONE fontfile/DONE fc/DONE Speedo/DONE Type1/DONE util/DONE
+
+#if HasParallelMake
+MakeMutex($(SUBDIRS) $(DONES))
+#endif
+
+#if HasGnuMake || HasBsdMake
+$(DONES): $(SUBDIRS)
+#endif
+
+#undef _LinkBuildLibrary
+#define _LinkBuildLibrary(lib) LinkBuildLibrary(lib)
+
+#ifndef OS2Architecture
+NormalDepLibraryTarget(font,$(SUBDIRS) $(DONES),$(OBJS))
+#else
+all:: DONE
+       cp $(OBJS) .
+
+NormalDepLibraryTarget(font,$(DONES),?*.o)
+#endif
+
+InstallLinkKitLibrary(font,$(LINKKITDIR)/lib)
+
+ForceSubdirs($(SUBDIRS))
+
+DependSubdirs($(SUBDIRS))
diff --git a/Xserver/lib/font/Speedo/Imakefile b/Xserver/lib/font/Speedo/Imakefile
new file mode 100644 (file)
index 0000000..1b66f3d
--- /dev/null
@@ -0,0 +1,22 @@
+XCOMM $XConsortium: Imakefile,v 1.10 93/09/04 16:42:59 rws Exp $
+#include <Server.tmpl>
+
+        INCLUDES = -I$(FONTINCSRC) -I../include -I$(SERVERSRC)/include
+         HEADERS = 
+      SPEEDOSRCS = do_char.c do_trns.c out_bl2d.c out_blk.c \
+                  out_scrn.c out_util.c reset.c set_spcs.c set_trns.c 
+      SPEEDOOBJS = do_char.o do_trns.o out_bl2d.o out_blk.o \
+                  out_scrn.o out_util.o reset.o set_spcs.o set_trns.o
+
+            SRCS = spfuncs.c spfile.c spinfo.c sperr.c spfont.c spglyph.c \
+               spencode.c \
+               $(SPEEDOSRCS)
+            OBJS = spfuncs.o spfile.o spinfo.o sperr.o spfont.o spglyph.o \
+               spencode.o \
+               $(SPEEDOOBJS)
+
+SubdirLibraryRule($(OBJS))
+NormalLibraryObjectRule()
+NormalLintTarget($(SRCS))
+
+DependTarget()
diff --git a/Xserver/lib/font/Speedo/adobe-iso.h b/Xserver/lib/font/Speedo/adobe-iso.h
new file mode 100644 (file)
index 0000000..23fc24f
--- /dev/null
@@ -0,0 +1,200 @@
+/* $XConsortium: adobe-iso.h,v 1.2 91/05/11 09:39:04 rws Exp $ */
+
+/*
+ * Latin 1 format from masterset format 11 (ps)
+ * 0 implies no valid mapping
+ */
+
+int         adobe_map[] = {
+    32, 32,
+    33, 33,
+    34, 34,
+    35, 35,
+    36, 36,
+    37, 37,
+    38, 38,
+    39, 169,
+    40, 40,
+    41, 41,
+    42, 42,
+    43, 43,
+    44, 44,
+    45, 45,
+    46, 46,
+    47, 47,
+    48, 48,
+    49, 49,
+    50, 50,
+    51, 51,
+    52, 52,
+    53, 53,
+    54, 54,
+    55, 55,
+    56, 56,
+    57, 57,
+    58, 58,
+    59, 59,
+    60, 60,
+    61, 61,
+    62, 62,
+    63, 63,
+    64, 64,
+    65, 65,
+    66, 66,
+    67, 67,
+    68, 68,
+    69, 69,
+    70, 70,
+    71, 71,
+    72, 72,
+    73, 73,
+    74, 74,
+    75, 75,
+    76, 76,
+    77, 77,
+    78, 78,
+    79, 79,
+    80, 80,
+    81, 81,
+    82, 82,
+    83, 83,
+    84, 84,
+    85, 85,
+    86, 86,
+    87, 87,
+    88, 88,
+    89, 89,
+    90, 90,
+    91, 91,
+    92, 92,
+    93, 93,
+    94, 195,
+    95, 95,
+    96, 193,
+    97, 97,
+    98, 98,
+    99, 99,
+    100, 100,
+    101, 101,
+    102, 102,
+    103, 103,
+    104, 104,
+    105, 105,
+    106, 106,
+    107, 107,
+    108, 108,
+    109, 109,
+    110, 110,
+    111, 111,
+    112, 112,
+    113, 113,
+    114, 114,
+    115, 115,
+    116, 116,
+    117, 117,
+    118, 118,
+    119, 119,
+    120, 120,
+    121, 121,
+    122, 122,
+    123, 123,
+    124, 124,
+    125, 125,
+    126, 196,                  /* lc tilde */
+    127, 0,                    /* */
+    161, 161,                  /* invert exclamation */
+    162, 162,                  /* cent */
+    163, 163,                  /* pound sterling */
+    164, 168,                  /* intl currency */
+    165, 165,                  /* yen */
+    166, 320,                  /* split vert bar */
+    167, 167,                  /* section mark */
+    168, 200,                  /* dierisis */
+    169, 0,                    /* superior copyright */
+    170, 0,                    /* feminine ordinal */
+    171, 171,                  /* dbl left guillemot */
+    172, 314,                  /* math not */
+    173, 0,                    /* hyphen ? */
+    174, 0,                    /* superior registered */
+    175, 0,                    /* overscore */
+    176, 321,                  /* degree */
+    177, 329,                  /* math +- */
+    178, 333,                  /* superior 2 */
+    179, 332,                  /* superior 3 */
+    180, 194,                  /* lc acute */
+    181, 324,                  /* greek lc mu */
+    182, 182,                  /* Paragraph */
+    183, 180,                  /* center dot */
+    184, 203,                  /* cedilla lc */
+    185, 328,                  /* superior 1 */
+    186, 0,                    /* masculine ordinal(using superior o) */
+    187, 187,                  /* right dbl guillemot */
+    188, 327,                  /* 1/4 */
+    189, 326,                  /* 1/2 */
+    190, 331,                  /* 3/4 */
+    191, 191,                  /* invert question */
+    192, 259,                  /* A grave */
+    193, 256,                  /* A acute */
+    194, 257,                  /* A circumflex */
+    195, 261,                  /* A tilde */
+    196, 258,                  /* A dierisis */
+    197, 260,                  /* A angstrom */
+    198, 225,                  /* AE ligature */
+    199, 262,                  /* C cedilla */
+    200, 266,                  /* E grave */
+    201, 263,                  /* E acute */
+    202, 264,                  /* E circumflex */
+    203, 265,                  /* E dierisis */
+    204, 270,                  /* I grave */
+    205, 267,                  /* I acute */
+    206, 268,                  /* I circumflex */
+    207, 269,                  /* I dierisis */
+    208, 317,                  /* D bar */
+    209, 271,                  /* N tilde */
+    210, 275,                  /* O grave */
+    211, 272,                  /* O acute */
+    212, 273,                  /* O circumflex */
+    213, 276,                  /* O tilde */
+    214, 274,                  /* O dierisis */
+    215, 325,                  /* math multiply */
+    216, 233,                  /* O bar */
+    217, 281,                  /* U grave */
+    218, 278,                  /* U acute */
+    219, 279,                  /* U circumflex */
+    220, 280,                  /* U dierisis */
+    221, 319,                  /* Y acute */
+    222, 318,                  /* icelandic thorn lc */
+    223, 251,                  /* German dbl s */
+    224, 287,                  /* a grave */
+    225, 284,                  /* a acute */
+    226, 285,                  /* a circumflex */
+    227, 289,                  /* a tilde */
+    228, 286,                  /* a dierisis */
+    229, 288,                  /* a angstrom */
+    230, 241,                  /* ae ligature */
+    231, 290,                  /* c cedilla */
+    232, 294,                  /* e grave */
+    233, 291,                  /* e acute */
+    234, 292,                  /* e circumflex */
+    235, 293,                  /* e dierisis */
+    236, 298,                  /* i grave */
+    237, 295,                  /* i acute */
+    238, 296,                  /* i circumflex */
+    239, 297,                  /* i dierisis */
+    240, 323,                  /* icelandic eth lc */
+    241, 299,                  /* n tilde */
+    242, 303,                  /* o grave */
+    243, 300,                  /* o acute */
+    244, 301,                  /* o circumflex */
+    245, 304,                  /* o tilde */
+    246, 302,                  /* o dierisis */
+    247, 322,                  /* math divide */
+    248, 249,                  /* o bar */
+    249, 309,                  /* u grave */
+    250, 306,                  /* u acute */
+    251, 307,                  /* u circumflex */
+    252, 308,                  /* u dierisis */
+    253, 334,                  /* y acute */
+    254, 330,                  /* icelandic thorn uc */
+    255, 310,                  /* y dierisis */
+};
diff --git a/Xserver/lib/font/Speedo/bics-iso.h b/Xserver/lib/font/Speedo/bics-iso.h
new file mode 100644 (file)
index 0000000..c96017b
--- /dev/null
@@ -0,0 +1,225 @@
+/* $XConsortium: bics-iso.h,v 1.5 94/04/17 20:17:42 gildea Exp $ */
+/*
+
+Copyright (c) 1993  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be included
+in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR
+OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall
+not be used in advertising or otherwise to promote the sale, use or
+other dealings in this Software without prior written authorization
+from the X Consortium.
+
+*/
+
+int  sp_bics_map[] = {
+    32, 0,
+    33, 1,
+    34, 2,
+    35, 3,
+    36, 4,
+    37, 5,
+    38, 6,
+    39, 264,
+    40, 8,
+    41, 9,
+    42, 10,
+    43, 11,
+    44, 12,
+    45, 13,
+    46, 14,
+    47, 15,
+    48, 16,
+    49, 17,
+    50, 18,
+    51, 19,
+    52, 20,
+    53, 21,
+    54, 22,
+    55, 23,
+    56, 24,
+    57, 25,
+    58, 26,
+    59, 27,
+    60, 28,
+    61, 29,
+    62, 30,
+    63, 31,
+    64, 32,
+    65, 33,
+    66, 34,
+    67, 35,
+    68, 36,
+    69, 37,
+    70, 38,
+    71, 39,
+    72, 40,
+    73, 41,
+    74, 42,
+    75, 43,
+    76, 44,
+    77, 45,
+    78, 46,
+    79, 47,
+    80, 48,
+    81, 49,
+    82, 50,
+    83, 51,
+    84, 52,
+    85, 53,
+    86, 54,
+    87, 55,
+    88, 56,
+    89, 57,
+    90, 58,
+    91, 59,
+    92, 60,
+    93, 61,
+    94, 133,
+    95, 63,
+    96, 131,
+    97, 65,
+    98, 66,
+    99, 67,
+    100, 68,
+    101, 69,
+    102, 70,
+    103, 71,
+    104, 72,
+    105, 73,
+    106, 74,
+    107, 75,
+    108, 76,
+    109, 77,
+    110, 78,
+    111, 79,
+    112, 80,
+    113, 81,
+    114, 82,
+    115, 83,
+    116, 84,
+    117, 85,
+    118, 86,
+    119, 87,
+    120, 88,
+    121, 89,
+    122, 90,
+    123, 91,
+    124, 92,
+    125, 93,
+    126, 137,
+    127, 358,
+    161, 128,
+    162, 98,
+    163, 97,
+    164, 278,
+    165, 274,
+    166, 277,
+    167, 110,
+    168, 135,
+    169, 503,
+    170, 538,
+    171, 125,
+    172, 309,
+    173, 191,
+    174, 504,
+    175, 230,
+    176, 339,
+    177, 286,
+    178, 160,
+    179, 161,
+    180, 129,
+    181, 325,
+    182, 279,
+    183, 102,
+    184, 141,
+    185, 159,
+    186, 544,
+    187, 126,
+    188, 151,
+    189, 153,
+    190, 155,
+    191, 127,
+    192, 259,
+    193, 261,
+    194, 257,
+    195, 253,
+    196, 255,
+    197, 113,
+    198, 114,
+    199, 148,
+    200, 249,
+    201, 251,
+    202, 247,
+    203, 245,
+    204, 239,
+    205, 241,
+    206, 237,
+    207, 235,
+    208, 169,
+    209, 196,
+    210, 202,
+    211, 200,
+    212, 204,
+    213, 208,
+    214, 206,
+    215, 284,
+    216, 115,
+    217, 212,
+    218, 210,
+    219, 214,
+    220, 216,
+    221, 224,
+    222, 271,
+    223, 121,
+    224, 260,
+    225, 262,
+    226, 258,
+    227, 254,
+    228, 256,
+    229, 117,
+    230, 118,
+    231, 149,
+    232, 250,
+    233, 252,
+    234, 248,
+    235, 246,
+    236, 240,
+    237, 242,
+    238, 238,
+    239, 236,
+    240, 273,
+    241, 195,
+    242, 201,
+    243, 199,
+    244, 203,
+    245, 207,
+    246, 205,
+    247, 285,
+    248, 119,
+    249, 211,
+    250, 209,
+    251, 213,
+    252, 215,
+    253, 223,
+    254, 272,
+    255, 221,
+};
+
diff --git a/Xserver/lib/font/Speedo/do_char.c b/Xserver/lib/font/Speedo/do_char.c
new file mode 100644 (file)
index 0000000..22ac5a9
--- /dev/null
@@ -0,0 +1,1022 @@
+/* $XConsortium: do_char.c /main/5 1995/10/24 11:22:28 gildea $ */
+
+/*
+
+Copyright 1989-1991, Bitstream Inc., Cambridge, MA.
+You are hereby granted permission under all Bitstream propriety rights to
+use, copy, modify, sublicense, sell, and redistribute the Bitstream Speedo
+software and the Bitstream Charter outline font for any purpose and without
+restrictions; provided, that this notice is left intact on all copies of such
+software or font and that Bitstream's trademark is acknowledged as shown below
+on all unmodified copies of such font.
+
+BITSTREAM CHARTER is a registered trademark of Bitstream Inc.
+
+
+BITSTREAM INC. DISCLAIMS ANY AND ALL WARRANTIES, EXPRESS OR IMPLIED, INCLUDING
+WITHOUT LIMITATION THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+PARTICULAR PURPOSE.  BITSTREAM SHALL NOT BE LIABLE FOR ANY DIRECT OR INDIRECT
+DAMAGES, INCLUDING BUT NOT LIMITED TO LOST PROFITS, LOST DATA, OR ANY OTHER
+INCIDENTAL OR CONSEQUENTIAL DAMAGES, ARISING OUT OF OR IN ANY WAY CONNECTED
+WITH THE SPEEDO SOFTWARE OR THE BITSTREAM CHARTER OUTLINE FONT.
+
+*/
+
+/***************************** D O - C H A R . C *****************************
+ *                                                                           *
+ * This is the top level module for processing one simple or composite       *
+ * character.
+ *                                                                           *
+ ****************************************************************************/
+
+#include "spdo_prv.h"               /* General definitions for Speedo    */
+
+#define   DEBUG   0
+
+#if DEBUG
+#include <stdio.h>
+#define SHOW(X) printf("X = %d\n", X)
+#else
+#define SHOW(X)
+#endif
+
+/***** GLOBAL VARIABLES *****/
+
+/*****  GLOBAL FUNCTIONS *****/
+
+/***** EXTERNAL VARIABLES *****/
+
+/***** EXTERNAL FUNCTIONS *****/
+
+/***** STATIC VARIABLES *****/
+
+/***** STATIC FUNCTIONS *****/
+
+#if PROTOS_AVAIL
+static boolean sp_make_simp_char(PROTO_DECL2 ufix8 FONTFAR *pointer,ufix8 format);
+static boolean sp_make_comp_char(PROTO_DECL2 ufix8 FONTFAR *pointer);
+static ufix8 FONTFAR *sp_get_char_org(PROTO_DECL2 ufix16 char_index,boolean top_level);
+static fix15 sp_get_posn_arg(PROTO_DECL2 ufix8 FONTFAR *STACKFAR *ppointer,ufix8 format);
+static fix15 sp_get_scale_arg(PROTO_DECL2 ufix8 FONTFAR *STACKFAR *ppointer,ufix8 format);
+#else
+static boolean sp_make_simp_char(); /* Process simple character data */
+static boolean sp_make_comp_char(); /* Process compound character data */
+static ufix8 FONTFAR *sp_get_char_org();   /* Look up char in character directory */
+static fix15   sp_get_posn_arg();   /* Read Xpos Ypos args in DOCH instruction */
+static fix15   sp_get_scale_arg();  /* read Xscale Yscale args in DOCH instruction */
+#endif
+
+\f
+FUNCTION ufix16 get_char_id(char_index)
+GDECL
+ufix16 char_index;     /* Index to character in char directory */
+/*
+ * Returns character id for specified character index in currently
+ * selected font.
+ * Reports Error 10 and returns 0 if no font selected.
+ * Reports Error 12 and returns 0 if character data not available.
+ */
+{
+ufix8 FONTFAR  *pointer;      /* Pointer to character data */
+
+if (!sp_globals.specs_valid)     /* Font specs not defined? */
+    {
+    report_error(10);            /* Report font not specified */
+    return (ufix16)0;            /* Return zero character id */
+    }
+
+pointer = sp_get_char_org(char_index, TRUE); /* Get pointer to character data */
+if (pointer == NULL)             /* Character data not available? */
+    {
+    report_error(12);            /* Report character data not avail */
+    return (ufix16)0;            /* Return zero character id */
+    }
+
+return 0xffff & NEXT_WORD(pointer); /* Return character id */
+}
+
+\f
+#if INCL_METRICS
+FUNCTION fix31 get_char_width(char_index)
+GDECL
+ufix16 char_index;     /* Index to character in char directory */
+/*
+ * Returns character set width for specified character index in currently
+ * selected font in units of 1/65536 em.
+ * Reports Error 10 and returns 0 if no font selected.
+ * Reports Error 12 and returns 0 if character data not available.
+ */
+{
+ufix8 FONTFAR  *pointer;      /* Pointer to character data */
+fix31    set_width;    /* Set width of character */
+
+if (!sp_globals.specs_valid)                /* Font specs not defined? */
+    {
+    report_error(10);            /* Report font not specified */
+    return (fix31)0;             /* Return zero character width */
+    }
+
+pointer = sp_get_char_org(char_index, TRUE); /* Get pointer to character data */
+if (pointer == NULL)             /* Character data not available? */
+    {
+    report_error(12);            /* Report character data not avail */
+    return (fix31)0;             /* Return zero character width */
+    }
+
+pointer += 2;                    /* Skip over character id */
+set_width = (fix31)NEXT_WORD(pointer); /* Read set width  and Convert units */
+set_width = ((set_width << 16) + (sp_globals.metric_resolution >> 1)) / sp_globals.metric_resolution;
+return set_width;                /* Return in 1/65536 em units */
+}
+#endif
+\f
+#if INCL_METRICS
+FUNCTION fix15 get_track_kern(track, point_size)
+GDECL
+fix15  track;          /* Track required (0 - 3) */
+fix15  point_size;     /* Point size (units of whole points) */
+/*
+ * Returns inter-character spacing adjustment in units of 1/256
+ * points for the specified kerning track and point size.
+ * If the specified point size is larger than the maximum point
+ * size for the specified track, the adjustment for the maximum
+ * point size is used.
+ * If the specified point size is smaller than the minimum point
+ * size for the specified track, the adjustment for the minimum
+ * point size is used.
+ * If the specified point size is between the minimum point size
+ * and the maximum point size for the specified track, the 
+ * adjustment is interpolated linearly between the minimum and
+ * maximum adjustments.
+ * Reports Error 10 and returns 0 if no font selected.
+ * Reports Error 13 and returns 0 if track kerning data not in font.
+ */
+{
+ufix8 FONTFAR   *pointer;      /* Pointer to character data */
+fix15    no_tracks;    /* Number of kerning tracks in font */
+ufix8    format;       /* Track kerning format byte */
+fix15    i;            /* Track counter */
+fix15    min_pt_size;  /* Minimum point size for track */
+fix15    max_pt_size;  /* Maximum point size for track */
+fix15    min_adj;      /* Adjustment for min point size */
+fix15    max_adj;      /* Adjustment for max point size */
+fix31    delta_pt_size;/* Max point size - min point size */
+fix31    delta_adj;    /* Min adjustment - max adjustment */
+fix15    adj = 0;      /* Interpolated adjustment */
+
+if (track == 0)                  /* Track zero selected? */
+    {
+    return adj;                  /* Return zero track kerning adjustment */
+    }
+
+if (!sp_globals.specs_valid)                /* Font specs not defined? */
+    {
+    report_error(10);            /* Report font not specified */
+    return adj;                  /* Return zero track kerning adjustment */
+    }
+
+no_tracks = sp_globals.kern.no_tracks;      /* Number of kerning tracks */
+if (track > no_tracks)           /* Required track not available? */
+    {
+    report_error(13);            /* Report track kerning data not avail */
+    return adj;                  /* Return zero track kerning adjustment */
+    }
+
+pointer =  sp_globals.kern.tkorg;            /* Point to start of track kern data */
+for (i = 0; i < track; i++)      /* Read until track required is read */
+    {
+    format = NEXT_BYTE(pointer); /* Read track kerning format byte */
+    min_pt_size = (format & BIT0)? 
+        NEXT_WORD(pointer):
+        (fix15)NEXT_BYTE(pointer);
+    min_adj = (format & BIT1)? 
+        NEXT_WORD(pointer):
+        (fix15)NEXT_BYTE(pointer);
+    max_pt_size = (format & BIT2)? 
+        NEXT_WORD(pointer):
+        (fix15)NEXT_BYTE(pointer);
+    max_adj = (format & BIT3)? 
+        NEXT_WORD(pointer):
+        (fix15)NEXT_BYTE(pointer);
+    }
+
+if (point_size <= min_pt_size)   /* Smaller than minimum point size? */
+    {
+    return min_adj;              /* Return minimum adjustment (1/256 points) */
+    }
+
+if (point_size >= max_pt_size)   /* Larger than maximum point size? */
+    {
+    return max_adj;              /* Return maximum adjustment (1/256 points) */
+    }
+
+delta_pt_size = (fix31)(max_pt_size - min_pt_size);
+delta_adj = (fix31)(min_adj - max_adj);
+adj = (fix15)(min_adj - 
+       (((fix31)(point_size - min_pt_size) * delta_adj + 
+         (delta_pt_size >> 1)) / delta_pt_size));
+return adj;                      /* Return interpolated adjustment (1/256 points) */
+}
+#endif
+\f
+#if INCL_METRICS
+FUNCTION fix31 get_pair_kern(char_index1, char_index2)
+GDECL
+ufix16 char_index1;    /* Index to first character in char directory */
+ufix16 char_index2;    /* Index to second character in char directory */
+/*
+ * Returns inter-character spacing adjustment in units of 1/65536 em
+ * for the specified pair of characters.
+ * Reports Error 10 and returns 0 if no font selected.
+ * Reports Error 14 and returns 0 if pair kerning data not in font.
+ */
+{
+ufix8 FONTFAR  *origin;       /* Pointer to first kerning pair record */
+ufix8 FONTFAR  *pointer;      /* Pointer to character data */
+ufix16   tmpufix16;    /* Temporary workspace */
+fix15    no_pairs;     /* Number of kerning pairs in font */
+ufix8    format;       /* Track kerning format byte */
+boolean  long_id;      /* TRUE if 2-byte character ids */
+fix15    rec_size;     /* Number of bytes in kern pair record */
+fix15    n;            /* Number of remaining kern pairs */
+fix15    nn;           /* Number of kern pairs in first partition */
+fix15    base;         /* Index to first record in rem kern pairs */
+fix15    i;            /* Index to kern pair being tested */
+fix31    adj = 0;      /* Returned value of adjustment */
+fix15    adj_base;     /* Adjustment base for relative adjustments */
+
+if (!sp_globals.specs_valid)                /* Font specs not defined? */
+    {
+    report_error(10);            /* Report font not specified */
+    return adj;                  /* Return zero pair kerning adjustment */
+    }
+
+no_pairs = sp_globals.kern.no_pairs;        /* Number of kerning pairs */
+if (no_pairs == 0)               /* Pair kerning data not available? */
+    {
+    report_error(14);            /* Report pair kerning data not avail */
+    return adj;                  /* Return zero pair kerning adjustment */
+    }
+
+pointer = sp_globals.kern.pkorg;            /* Point to start of pair kern data */
+format = NEXT_BYTE(pointer);     /* Read pair kerning format byte */
+if (!(format & BIT0))            /* One-byte adjustment values? */
+    adj_base = NEXT_WORD(pointer); /* Read base adjustment */
+origin = pointer;                /* First byte of kerning pair data */
+rec_size = format + 3;           /* Compute kerning pair record size */
+long_id = format & BIT1;         /* Set flag for 2-byte char index */
+
+n = no_pairs;                    /* Consider all kerning pairs */
+base = 0;                        /* Set base at first kern pair record */
+while (n != 0)                   /* While 1 or more kern pairs remain ... */
+    {
+    nn = n >> 1;                 /* Size of first partition */
+    i = base + nn;               /* Index to record to be tested */
+    pointer = origin + (i * rec_size);
+    tmpufix16 = NEXT_CHNDX(pointer, long_id);
+    if (char_index1 < tmpufix16)
+        {
+        n = nn;                  /* Number remaining in first partition */
+        continue;
+        }
+    if (char_index1 > tmpufix16)
+        {
+        n -= nn + 1;             /* Number remaining in second partition */
+        base = i + 1;            /* Base index for second partition */
+        continue;
+        }
+    tmpufix16 = NEXT_CHNDX(pointer, long_id);
+    if (char_index2 < tmpufix16)
+        {
+        n = nn;                  /* Number remaining in first partition */
+        continue;
+        }
+    if (char_index2 > tmpufix16)
+        {
+        n -= nn + 1;             /* Number remaining in second partition */
+        base = i + 1;            /* Base index for second partition */
+        continue;
+        }
+    adj = (format & BIT0)? 
+        (fix31)NEXT_WORD(pointer):
+        (fix31)(adj_base + (fix15)NEXT_BYTE(pointer));
+    adj = ((adj << 16) + (sp_globals.orus_per_em >> 1)) / sp_globals.orus_per_em; /* Convert units */
+    n = 0;                       /* No more to consider */
+    }
+return adj;                      /* Return pair kerning adjustment */
+}
+#endif
+\f
+
+#if INCL_METRICS
+#ifdef old
+FUNCTION boolean get_char_bbox(char_index, bbox)
+GDECL
+ufix16 char_index;
+bbox_t *bbox;
+{
+/*
+ *     returns true if character exists, false if it doesn't
+ *     provides transformed character bounding box in 1/65536 pixels
+ *     in the provided bbox_t structure.  Bounding box may be
+ *     conservative in the event that the transformation is not
+ *     normal or the character is compound.
+ */
+
+ufix8 FONTFAR *pointer;
+fix15 tmp;
+point_t Pmin, Pmax;
+
+#if REENTRANT_ALLOC
+plaid_t plaid;
+sp_globals.plaid = &plaid;
+#endif
+
+if (!sp_globals.specs_valid)                /* Font specs not defined? */
+    {
+    report_error(10);            /* Report font not specified */
+    return FALSE;                /* Error return */
+    }
+
+init_tcb();                      /* Initialize transformation control block */
+
+pointer = sp_get_char_org(char_index, TRUE); /* Point to start of character data */
+if (pointer == NULL)             /* Character data not available? */
+    {
+    report_error(12);            /* Report character data not avail */
+    return FALSE;                /* Error return */
+    }
+
+pointer += 2;                    /* Skip over character id */
+tmp = NEXT_WORD(pointer); /* Read set width */
+               
+tmp = NEXT_BYTE(pointer);
+if (tmp & BIT1)               /* Optional data in header? */
+    {
+    tmp = (ufix8)NEXT_BYTE(pointer); /* Read size of optional data */
+    pointer += tmp;         /* Skip optional data */
+    }
+
+pointer = plaid_tcb(pointer, tmp);              /* Process plaid data */
+pointer = read_bbox(pointer, &Pmin, &Pmax,(boolean)FALSE);        /* Read bounding box */
+bbox->xmin  = (fix31)Pmin.x << sp_globals.poshift;
+bbox->xmax  = (fix31)Pmax.x << sp_globals.poshift;
+bbox->ymin  = (fix31)Pmin.y << sp_globals.poshift;
+bbox->ymax  = (fix31)Pmax.y << sp_globals.poshift;
+return TRUE;
+}
+
+#else /* new code, 4/25/91 */
+
+FUNCTION boolean get_char_bbox(char_index, bbox)
+GDECL
+ufix16 char_index;
+bbox_t *bbox;
+{
+/*
+ *     returns true if character exists, false if it doesn't
+ *     provides transformed character bounding box in 1/65536 pixels
+ *     in the provided bbox_t structure.  Bounding box may be
+ *     conservative in the event that the transformation is not
+ *     normal or the character is compound.
+ */
+
+ufix8 FONTFAR *pointer;
+fix15 tmp;
+fix15 format;
+ufix16 pix_adj;
+point_t Pmin, Pmax;
+
+#if REENTRANT_ALLOC
+plaid_t plaid;
+sp_globals.plaid = &plaid;
+#endif
+
+if (!sp_globals.specs_valid)                /* Font specs not defined? */
+    {
+    report_error(10);            /* Report font not specified */
+    return FALSE;                /* Error return */
+    }
+
+init_tcb();                      /* Initialize transformation control block */
+
+pointer = sp_get_char_org(char_index, TRUE); /* Point to start of character data */
+if (pointer == NULL)             /* Character data not available? */
+    {
+    report_error(12);            /* Report character data not avail */
+    return FALSE;                /* Error return */
+    }
+
+pointer += 2;                    /* Skip over character id */
+tmp = NEXT_WORD(pointer); /* Read set width */
+               
+format = NEXT_BYTE(pointer);
+if (format & BIT1)               /* Optional data in header? */
+    {
+    tmp = (ufix8)NEXT_BYTE(pointer); /* Read size of optional data */
+    pointer += tmp;         /* Skip optional data */
+    }
+
+if (format & BIT0)
+    {
+    pix_adj = sp_globals.onepix << 1;          /* Allow 2 pixel expansion ... */
+    }
+else
+    {
+    pix_adj = 0;
+    }
+
+pointer = plaid_tcb(pointer, format);              /* Process plaid data */
+pointer = read_bbox(pointer, &Pmin, &Pmax,(boolean)FALSE);        /* Read bounding box */
+
+Pmin.x -= pix_adj;                         /* ... of components of ... */
+Pmin.y -= pix_adj;                         /* ... compound ... */
+Pmax.x += pix_adj;                         /* ... character ... */
+Pmax.y += pix_adj;                         /* ... bounding box. */
+
+
+bbox->xmin  = (fix31)Pmin.x << sp_globals.poshift;
+bbox->xmax  = (fix31)Pmax.x << sp_globals.poshift;
+bbox->ymin  = (fix31)Pmin.y << sp_globals.poshift;
+bbox->ymax  = (fix31)Pmax.y << sp_globals.poshift;
+return TRUE;
+}
+#endif /* new code */
+
+#endif
+
+\f
+#if INCL_ISW
+FUNCTION boolean make_char_isw(char_index,imported_setwidth)
+GDECL
+ufix16 char_index;
+ufix32 imported_setwidth;
+{
+fix15   xmin;          /* Minimum X ORU value in font */
+fix15   xmax;          /* Maximum X ORU value in font */
+fix15   ymin;          /* Minimum Y ORU value in font */
+fix15   ymax;          /* Maximum Y ORU value in font */
+ufix16  return_value;
+
+sp_globals.import_setwidth_act = TRUE;
+/* convert imported width to orus */
+sp_globals.imported_width = (sp_globals.metric_resolution * 
+                           imported_setwidth) >> 16;
+return_value = do_make_char(char_index);
+
+if (sp_globals.isw_modified_constants)
+    {
+    /* reset fixed point constants */
+    xmin = read_word_u(sp_globals.font_org + FH_FXMIN);
+    ymin = read_word_u(sp_globals.font_org + FH_FYMIN);
+    ymax = read_word_u(sp_globals.font_org + FH_FYMAX);
+    sp_globals.constr.data_valid = FALSE;
+    xmax = read_word_u(sp_globals.font_org + FH_FXMAX);
+    if (!setup_consts(xmin,xmax,ymin,ymax))
+        {
+        report_error(3);           /* Requested specs out of range */
+        return FALSE;
+        }
+    }    
+return (return_value);
+}
+
+FUNCTION boolean make_char(char_index)
+GDECL
+ufix16 char_index;     /* Index to character in char directory */
+{
+sp_globals.import_setwidth_act = FALSE;
+return (do_make_char(char_index));
+}
+
+FUNCTION static boolean do_make_char(char_index)
+#else
+FUNCTION boolean make_char(char_index)
+#endif
+/*
+ * Outputs specified character using the currently selected font and
+ * scaling and output specifications.
+ * Reports Error 10 and returns FALSE if no font specifications 
+ * previously set.
+ * Reports Error 12 and returns FALSE if character data not available.
+ */
+GDECL
+ufix16 char_index;
+{
+ufix8 FONTFAR  *pointer;      /* Pointer to character data */
+fix15    x_orus;
+fix15    tmpfix15;
+ufix8    format;
+
+#if INCL_ISW
+sp_globals.isw_modified_constants = FALSE;
+#endif
+
+#if REENTRANT_ALLOC
+
+plaid_t plaid;
+
+#if INCL_BLACK || INCL_SCREEN || INCL_2D
+intercepts_t intercepts;
+sp_globals.intercepts = &intercepts;
+#endif
+
+sp_globals.plaid = &plaid;
+#endif
+
+if (!sp_globals.specs_valid)                /* Font specs not defined? */
+    {
+    report_error(10);            /* Report font not specified */
+    return FALSE;                /* Error return */
+    }
+
+#if INCL_MULTIDEV
+#if INCL_OUTLINE
+if (sp_globals.output_mode == MODE_OUTLINE && !sp_globals.outline_device_set)
+       {
+       report_error(2);
+       return FALSE;
+       }
+else
+#endif
+       if (!sp_globals.bitmap_device_set)
+               {
+               report_error(2);
+               return FALSE;
+               }
+#endif
+
+
+init_tcb();                      /* Initialize transformation control block */
+
+pointer = sp_get_char_org(char_index, TRUE); /* Point to start of character data */
+SHOW(pointer);
+if (pointer == NULL)             /* Character data not available? */
+    {
+    report_error(12);            /* Report character data not avail */
+    return FALSE;                /* Error return */
+    }
+
+pointer += 2;                    /* Skip over character id */
+x_orus = NEXT_WORD(pointer); /* Read set width */
+#if INCL_SQUEEZING || INCL_ISW
+sp_globals.setwidth_orus = x_orus;
+#endif
+
+#if INCL_ISW
+if (sp_globals.import_setwidth_act)
+    x_orus = sp_globals.imported_width;
+#endif
+sp_globals.Psw.x = (fix15)((fix31)
+                   (((fix31)x_orus * (sp_globals.specs.xxmult>>16) + 
+                  ( ((fix31)x_orus * (sp_globals.specs.xxmult&0xffffL) )>>16) 
+                  ) << sp_globals.pixshift) / sp_globals.metric_resolution);
+
+sp_globals.Psw.y = (fix15)(   
+                 (fix31)( 
+                 ((fix31)x_orus * (sp_globals.specs.yxmult>>16) + 
+                ( ((fix31)x_orus * (sp_globals.specs.yxmult&0xffffL) )>>16) 
+                  ) << sp_globals.pixshift) / sp_globals.metric_resolution);
+               
+format = NEXT_BYTE(pointer);
+if (format & BIT1)               /* Optional data in header? */
+    {
+    tmpfix15 = (ufix8)NEXT_BYTE(pointer); /* Read size of optional data */
+    pointer += tmpfix15;         /* Skip optional data */
+    }
+if (format & BIT0)
+    {
+    return sp_make_comp_char(pointer); /* Output compound character */
+    }
+else
+    {
+    return sp_make_simp_char(pointer, format); /* Output simple character */
+    }
+}
+\f
+FUNCTION static boolean sp_make_simp_char(pointer, format)
+GDECL
+ufix8 FONTFAR  *pointer;      /* Pointer to first byte of position argument */
+ufix8    format;       /* Character format byte */
+/*
+ * Called by sp_make_char() to output a simple (non-compound) character.
+ * Returns TRUE on completion.
+ */
+{
+point_t Pmin, Pmax;    /* Transformed corners of bounding box */
+#if INCL_SQUEEZING || INCL_ISW
+ufix8 FONTFAR *save_pointer;
+#endif
+#if INCL_ISW
+fix31   char_width;
+fix31   isw_scale;
+#endif
+
+#if INCL_SQUEEZING
+sp_globals.squeezing_compound = FALSE;
+if ((sp_globals.pspecs->flags & SQUEEZE_LEFT) ||
+    (sp_globals.pspecs->flags & SQUEEZE_RIGHT) ||
+    (sp_globals.pspecs->flags & SQUEEZE_TOP) ||
+    (sp_globals.pspecs->flags & SQUEEZE_BOTTOM) )
+    {
+       /* get the bounding box data before processing the character */
+    save_pointer = pointer;
+    preview_bounding_box (pointer, format);
+    pointer = save_pointer;
+    }
+#endif
+#if (INCL_ISW)
+if (sp_globals.import_setwidth_act)
+    {
+    save_pointer = pointer;
+    preview_bounding_box (pointer, format);
+    pointer = save_pointer;
+        /* make sure I'm not going to get fixed point overflow */
+    isw_scale = compute_isw_scale();
+    if (sp_globals.bbox_xmin_orus < 0)
+        char_width = SQUEEZE_MULT((sp_globals.bbox_xmax_orus - sp_globals.bbox_xmin_orus), isw_scale);
+    else
+       char_width = SQUEEZE_MULT(sp_globals.bbox_xmax_orus, isw_scale);
+    if (char_width >= sp_globals.isw_xmax)
+        if (!reset_xmax(char_width))
+              return FALSE;
+    }
+#endif
+pointer = plaid_tcb(pointer, format);              /* Process plaid data */
+pointer = read_bbox(pointer, &Pmin, &Pmax, FALSE);      /* Read bounding box */
+if (fn_begin_char(sp_globals.Psw, Pmin, Pmax))     /* Signal start of character output */
+       {
+       do
+       {
+           proc_outl_data(pointer);              /* Process outline data */
+       }
+       while (!fn_end_char());                      /* Repeat if not done */
+       }
+return TRUE;
+}
+\f
+FUNCTION static boolean sp_make_comp_char(pointer)
+GDECL
+ufix8 FONTFAR  *pointer;      /* Pointer to first byte of position argument */
+/*
+ * Called by sp_make_char() to output a compound character.
+ * Returns FALSE if data for any sub-character is not available.
+ * Returns TRUE if output completed with no error.
+ */
+{
+point_t  Pmin, Pmax;   /* Transformed corners of bounding box */
+point_t  Pssw;         /* Transformed escapement vector */
+ufix8 FONTFAR  *pointer_sav;  /* Saved pointer to compound character data */
+ufix8 FONTFAR  *sub_pointer;  /* Pointer to sub-character data */
+ufix8    format;       /* Format of DOCH instruction */
+ufix16   sub_char_index; /* Index to sub-character in character directory */
+fix15    x_posn;       /* X position of sub-character (outline res units) */
+fix15    y_posn;       /* Y position of sub-character (outline res units) */
+fix15    x_scale;      /* X scale factor of sub-character (scale units) */
+fix15    y_scale;      /* Y scale factor of sub-character (scale units) */
+fix15    tmpfix15;     /* Temporary workspace */
+fix15    x_orus;       /* Set width in outline resolution units */
+fix15    pix_adj;      /* Pixel adjustment to compound char bounding box */
+#if INCL_SQUEEZING
+fix31    x_factor, x_offset, top_scale, bottom_scale;
+boolean  squeezed_x, squeezed_y;
+#endif
+#if INCL_SQUEEZING || INCL_ISW
+fix15    x_offset_pix;
+#endif
+#if INCL_ISW
+fix31   char_width;
+fix31   isw_scale;
+#endif
+
+
+#if INCL_SQUEEZING
+sp_globals.squeezing_compound = TRUE;
+#endif
+pointer = read_bbox(pointer, &Pmin, &Pmax, TRUE); /* Read bounding box data */
+pix_adj = sp_globals.onepix << 1;          /* Allow 2 pixel expansion ... */
+Pmin.x -= pix_adj;                         /* ... of components of ... */
+Pmin.y -= pix_adj;                         /* ... compound ... */
+Pmax.x += pix_adj;                         /* ... character ... */
+Pmax.y += pix_adj;                         /* ... bounding box. */
+
+#if INCL_SQUEEZING
+/* scale the bounding box if necessary before calling begin_char */
+squeezed_x = calculate_x_scale(&x_factor, &x_offset, 0);
+squeezed_y = calculate_y_scale(&top_scale, &bottom_scale,0,0);
+
+if (squeezed_x)
+    { /* scale the x coordinates of the bbox */
+    x_offset_pix = (fix15)(((x_offset >> 16) * sp_globals.tcb0.xppo)
+                    >> sp_globals.mpshift);
+    if ((x_offset_pix >0) && (x_offset_pix < sp_globals.onepix))
+        x_offset_pix = sp_globals.onepix;
+    Pmin.x = SQUEEZE_MULT (x_factor, Pmin.x) + x_offset_pix - pix_adj;
+    Pmax.x = SQUEEZE_MULT (x_factor, Pmax.x) + x_offset_pix + pix_adj;
+    }
+if (squeezed_y)
+    { /* scale the y coordinates of the bbox */
+    if ((Pmin.y) < 0)
+        Pmin.y = SQUEEZE_MULT (bottom_scale, Pmin.y) - pix_adj;
+    else
+        Pmin.y = SQUEEZE_MULT (top_scale, Pmin.y) - pix_adj;
+    if ((Pmax.y) < 0)
+        Pmax.y = SQUEEZE_MULT (bottom_scale, Pmax.y) + pix_adj;
+    else
+        Pmax.y = SQUEEZE_MULT (top_scale, Pmax.y) + pix_adj;
+    }
+#endif
+#if (INCL_ISW)
+if (sp_globals.import_setwidth_act)
+    {
+        /* make sure I'm not going to get fixed point overflow */
+    isw_scale = ((fix31)sp_globals.imported_width << 16)/
+                 (fix31)sp_globals.setwidth_orus;
+    char_width = SQUEEZE_MULT((sp_globals.bbox_xmax_orus - 
+                               sp_globals.bbox_xmin_orus),
+isw_scale);
+    if (char_width >= sp_globals.isw_xmax)
+        if (!reset_xmax(char_width))
+              return FALSE;
+    }
+#endif
+
+if (fn_begin_char(sp_globals.Psw, Pmin, Pmax)) /* Signal start of character data */
+       {
+       pointer_sav = pointer;
+       do
+           {
+           pointer = pointer_sav;                 /* Point to next DOCH or END instruction */
+           while (format = NEXT_BYTE(pointer))    /* DOCH instruction? */
+               {
+               init_tcb();                        /* Initialize transformation control block */
+               x_posn = sp_get_posn_arg(&pointer, format);
+               y_posn = sp_get_posn_arg(&pointer, (ufix8)(format >> 2));
+               x_scale = sp_get_scale_arg(&pointer, (ufix8)(format & BIT4));
+               y_scale = sp_get_scale_arg(&pointer, (ufix8)(format & BIT5));
+               scale_tcb(&sp_globals.tcb, x_posn, y_posn, x_scale, y_scale); /* Scale for sub-char */
+               sub_char_index = (format & BIT6)?  /* Read sub-char index */
+                   0xffff & NEXT_WORD(pointer):
+                   0xffff & NEXT_BYTE(pointer);
+               sub_pointer = sp_get_char_org(sub_char_index, FALSE); /* Point to start of sub-char */
+               if (sub_pointer == NULL)           /* Character data not available? */
+                   {
+                   return FALSE;                  /* Abort character output */
+                   }
+               sub_pointer += 2;                  /* Skip over character id */
+               x_orus = NEXT_WORD(sub_pointer);   /* Read set_width of sub-character */
+
+                       Pssw.x = (fix15)(   
+                                         (fix31)( 
+                              ((fix31)x_orus * (sp_globals.specs.xxmult>>16) + 
+                              ( ((fix31)x_orus * (sp_globals.specs.xxmult&0xffffL) )>>16) 
+                             ) << sp_globals.pixshift) / sp_globals.metric_resolution);
+                       Pssw.y = (fix15)(   
+                                         (fix31)( 
+                              ((fix31)x_orus * (sp_globals.specs.yxmult>>16) + 
+                              ( ((fix31)x_orus * (sp_globals.specs.yxmult&0xffffL) )>>16) 
+                             ) << sp_globals.pixshift) / sp_globals.metric_resolution);
+               
+               format = NEXT_BYTE(sub_pointer);   /* Read sub-character format */
+               if (format & BIT1)                 /* Optional data in header? */
+                   {
+                   tmpfix15 = (ufix8)NEXT_BYTE(sub_pointer); /* Read size of optional data */
+                   sub_pointer += tmpfix15;           /* Skip optional data */
+                   }
+               sub_pointer = plaid_tcb(sub_pointer, format);   /* Process sub-character plaid data */
+               sub_pointer = read_bbox(sub_pointer, &Pmin, &Pmax, FALSE); /* Read bounding box */
+               fn_begin_sub_char(Pssw, Pmin, Pmax);  /* Signal start of sub-character data */
+               proc_outl_data(sub_pointer);       /* Process sub-character data */
+               fn_end_sub_char();                    /* Signal end of sub-character data */
+               }
+           }
+       while (!fn_end_char());                       /* Signal end of character; repeat if required */
+       }
+return TRUE;
+}
+\f
+#if INCL_LCD           /* Dynamic load character data supported? */
+FUNCTION static ufix8 FONTFAR *sp_get_char_org(char_index, top_level)
+GDECL
+ufix16   char_index;   /* Index of character to be accessed */
+boolean  top_level;    /* Not a compound character element */
+/*
+ * Called by sp_get_char_id(), sp_get_char_width(), sp_make_char() and
+ * sp_make_comp_char() to get a pointer to the start of the character data
+ * for the specified character index.
+ * Version for configuration supporting dynamic character data loading.
+ * Calls load_char_data() to load character data if not already loaded
+ * as part of the original font buffer.
+ * Returns NULL if character data not available
+ */
+{
+buff_t  *pchar_data;   /* Buffer descriptor requested */
+ufix8 FONTFAR  *pointer;      /* Pointer into character directory */
+ufix8    format;       /* Character directory format byte */
+fix31    char_offset;  /* Offset of char data from start of font file */
+fix31    next_char_offset; /* Offset of char data from start of font file */
+fix15    no_bytes;     /* Number of bytes required for char data */
+
+if (top_level)                        /* Not element of compound char? */
+    {
+    if (char_index < sp_globals.first_char_idx)  /* Before start of character set? */
+        return NULL;
+    char_index -= sp_globals.first_char_idx;
+    if (char_index >= sp_globals.no_chars_avail) /* Beyond end of character set? */
+        return NULL;
+    sp_globals.cb_offset = 0;                    /* Reset char buffer offset */
+    }
+
+pointer = sp_globals.pchar_dir;
+format = NEXT_BYTE(pointer);          /* Read character directory format byte */
+pointer += char_index << 1;           /* Point to indexed character entry */
+if (format)                           /* 3-byte entries in char directory? */
+    {
+    pointer += char_index;            /* Adjust for 3-byte entries */
+    char_offset = read_long(pointer); /* Read file offset to char data */
+    next_char_offset = read_long(pointer + 3); /* Read offset to next char */
+    }
+else
+    {
+    char_offset = (fix31)(0xffff & NEXT_WORD(pointer)); /* Read file offset to char data */
+    next_char_offset = (fix31)(0xffff & NEXT_WORD(pointer)); /* Read offset to next char */
+    }
+
+no_bytes = next_char_offset - char_offset;
+if (no_bytes == 0)                    /* Character not in directory? */
+    return NULL;
+
+if (next_char_offset <= sp_globals.font_buff_size)/* Character data already in font buffer? */
+    return sp_globals.pfont->org + char_offset;  /* Return pointer into font buffer */
+
+pchar_data = load_char_data(char_offset, no_bytes, sp_globals.cb_offset); /* Request char data load */
+if (pchar_data->no_bytes < no_bytes)  /* Correct number of bytes loaded? */
+    return NULL;
+
+if (top_level)                        /* Not element of compound char? */
+    {
+    sp_globals.cb_offset = no_bytes;
+    }
+
+return pchar_data->org;               /* Return pointer into character data buffer */
+}
+#endif
+\f
+#if INCL_LCD
+#else                  /* Dynamic load character data not supported? */
+FUNCTION static ufix8 FONTFAR *sp_get_char_org(char_index, top_level)
+GDECL
+ufix16   char_index;   /* Index of character to be accessed */
+boolean  top_level;    /* Not a compound character element */
+/*
+ * Called by sp_get_char_id(), sp_get_char_width(), sp_make_char() and
+ * sp_make_comp_char() to get a pointer to the start of the character data
+ * for the specified character index.
+ * Version for configuration not supporting dynamic character data loading.
+ * Returns NULL if character data not available
+ */
+{
+ufix8   FONTFAR *pointer;      /* Pointer into character directory */
+ufix8    format;       /* Character directory format byte */
+fix31    char_offset;  /* Offset of char data from start of font file */
+fix31    next_char_offset; /* Offset of char data from start of font file */
+fix15    no_bytes;     /* Number of bytes required for char data */
+
+if (top_level)                        /* Not element of compound char? */
+    {
+    if (char_index < sp_globals.first_char_idx)  /* Before start of character set? */
+        return NULL;
+    char_index -= sp_globals.first_char_idx;
+    if (char_index >= sp_globals.no_chars_avail) /* Beyond end of character set? */
+        return NULL;
+    }
+
+pointer = sp_globals.pchar_dir;
+format = NEXT_BYTE(pointer);          /* Read character directory format byte */
+pointer += char_index << 1;           /* Point to indexed character entry */
+if (format)                           /* 3-byte entries in char directory? */
+    {
+    pointer += char_index;            /* Adjust for 3-byte entries */
+    char_offset = read_long(pointer); /* Read file offset to char data */
+    next_char_offset = read_long(pointer + 3); /* Read offset to next char */
+    }
+else
+    {
+    char_offset = (fix31)(0xffff & NEXT_WORD(pointer)); /* Read file offset to char data */
+    next_char_offset = (fix31)(0xffff & NEXT_WORD(pointer)); /* Read offset to next char */
+    }
+
+no_bytes = next_char_offset - char_offset;
+if (no_bytes == 0)                    /* Character not in directory? */
+    return NULL;
+
+return sp_globals.pfont->org + char_offset;      /* Return pointer into font buffer */
+}
+#endif
+
+\f
+FUNCTION static fix15 sp_get_posn_arg(ppointer, format)
+GDECL
+ufix8 FONTFAR * STACKFAR *ppointer;     /* Pointer to first byte of position argument */
+ufix8    format;       /* Format of DOCH arguments */
+/*
+ * Called by sp_make_comp_char() to read a position argument from the
+ * specified point in the font/char buffer.
+ * Updates pointer to byte following position argument.
+ * Returns value of position argument in outline resolution units
+ */
+{
+switch (format & 0x03)
+    {
+case 1:
+    return NEXT_WORD(*ppointer);
+
+case 2:
+    return (fix15)((fix7)NEXT_BYTE(*ppointer));
+
+default:
+    return (fix15)0;
+    }
+}
+\f
+FUNCTION static fix15 sp_get_scale_arg(ppointer, format)
+GDECL
+ufix8 FONTFAR *STACKFAR *ppointer;     /* Pointer to first byte of position argument */
+ufix8    format;       /* Format of DOCH arguments */
+/*
+ * Called by sp_make_comp_char() to read a scale argument from the
+ * specified point in the font/char buffer.
+ * Updates pointer to byte following scale argument.
+ * Returns value of scale argument in scale units (normally 1/4096)
+ */
+{
+if (format)
+    return NEXT_WORD(*ppointer);
+else
+    return (fix15)ONE_SCALE;
+}
+#if INCL_ISW || INCL_SQUEEZING
+FUNCTION static void preview_bounding_box(pointer,format)
+GDECL
+ufix8 FONTFAR  *pointer;      /* Pointer to first byte of position argument */
+ufix8    format;       /* Character format byte */
+{
+point_t  Pmin, Pmax;   /* Transformed corners of bounding box */
+
+    sp_globals.no_X_orus = (format & BIT2)?
+        (fix15)NEXT_BYTE(pointer):
+        0;
+    sp_globals.no_Y_orus = (format & BIT3)?
+        (fix15)NEXT_BYTE(pointer):
+        0;
+    pointer = read_oru_table(pointer);
+
+    /* Skip over control zone table */
+    pointer = skip_control_zone(pointer,format);
+
+    /* Skip over interpolation table */
+    pointer = skip_interpolation_table(pointer,format);
+    /* get_args has a pathological need for this value to be set */
+    sp_globals.Y_edge_org = sp_globals.no_X_orus;
+    pointer = read_bbox(pointer, &Pmin, &Pmax, TRUE);        /* Read bounding bo
+x */
+
+}
+#endif
+#if INCL_ISW
+FUNCTION static boolean reset_xmax(xmax)
+GDECL
+fix31   xmax;
+
+{
+fix15   xmin;          /* Minimum X ORU value in font */
+fix15   ymin;          /* Minimum Y ORU value in font */
+fix15   ymax;          /* Maximum Y ORU value in font */
+
+
+sp_globals.isw_modified_constants = TRUE;
+xmin = read_word_u(sp_globals.font_org + FH_FXMIN);
+ymin = read_word_u(sp_globals.font_org + FH_FYMIN);
+ymax = read_word_u(sp_globals.font_org + FH_FYMAX);
+
+if (!setup_consts(xmin,xmax,ymin,ymax))
+    {
+    report_error(3);           /* Requested specs out of range */
+    return FALSE;
+    }
+sp_globals.constr.data_valid = FALSE;
+/* recompute setwidth */
+sp_globals.Psw.x = (fix15)((fix31)(
+     ((fix31)sp_globals.imported_width * (sp_globals.specs.xxmult>>16) +
+     ( ((fix31)sp_globals.imported_width *
+          (sp_globals.specs.xxmult&0xffffL) )>>16)
+     ) << sp_globals.pixshift) / sp_globals.metric_resolution);
+sp_globals.Psw.y = (fix15)(   
+                 (fix31)( 
+                 ((fix31)sp_globals.imported_width * (sp_globals.specs.yxmult>>16) + 
+                ( ((fix31)sp_globals.imported_width * (sp_globals.specs.yxmult&0xffffL) )>>16) 
+                  ) << sp_globals.pixshift) / sp_globals.metric_resolution);
+               
+return TRUE;
+}
+#endif
diff --git a/Xserver/lib/font/Speedo/do_trns.c b/Xserver/lib/font/Speedo/do_trns.c
new file mode 100644 (file)
index 0000000..b9a7c33
--- /dev/null
@@ -0,0 +1,513 @@
+/* $XConsortium: do_trns.c,v 1.4 94/04/17 20:17:43 gildea Exp $ */
+
+/*
+
+Copyright 1989-1991, Bitstream Inc., Cambridge, MA.
+You are hereby granted permission under all Bitstream propriety rights to
+use, copy, modify, sublicense, sell, and redistribute the Bitstream Speedo
+software and the Bitstream Charter outline font for any purpose and without
+restrictions; provided, that this notice is left intact on all copies of such
+software or font and that Bitstream's trademark is acknowledged as shown below
+on all unmodified copies of such font.
+
+BITSTREAM CHARTER is a registered trademark of Bitstream Inc.
+
+
+BITSTREAM INC. DISCLAIMS ANY AND ALL WARRANTIES, EXPRESS OR IMPLIED, INCLUDING
+WITHOUT LIMITATION THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+PARTICULAR PURPOSE.  BITSTREAM SHALL NOT BE LIABLE FOR ANY DIRECT OR INDIRECT
+DAMAGES, INCLUDING BUT NOT LIMITED TO LOST PROFITS, LOST DATA, OR ANY OTHER
+INCIDENTAL OR CONSEQUENTIAL DAMAGES, ARISING OUT OF OR IN ANY WAY CONNECTED
+WITH THE SPEEDO SOFTWARE OR THE BITSTREAM CHARTER OUTLINE FONT.
+
+*/
+
+/**************************** D O _ T R N S . C ******************************
+ *                                                                           *
+ * This module is responsible for executing all intelligent transformation   *
+ * for bounding box and outline data                                         *
+ *                                                                           *
+ ****************************************************************************/
+
+
+#include "spdo_prv.h"               /* General definitions for Speedo    */
+
+#define   DEBUG      0
+
+#if DEBUG
+#include <stdio.h>
+#define SHOW(X) printf("X = %d\n", X)
+#else
+#define SHOW(X)
+#endif
+
+/***** GLOBAL VARIABLES *****/
+
+/***** GLOBAL FUNCTIONS *****/
+
+/***** EXTERNAL VARIABLES *****/
+
+/***** EXTERNAL FUNCTIONS *****/
+
+/***** STATIC VARIABLES *****/
+
+/***** STATIC FUNCTIONS *****/
+
+#if PROTOS_AVAIL
+static void sp_split_curve(PROTO_DECL2 point_t P1,point_t P2,point_t P3,fix15 depth);
+static ufix8 FONTFAR *sp_get_args(PROTO_DECL2 ufix8 FONTFAR *pointer,ufix8  format,point_t STACKFAR *pP);
+#else
+static void   sp_split_curve();            /* Split Bezier curve into vectors */
+static ufix8 FONTFAR *sp_get_args();      /* Read X Y argument pair */
+#endif
+
+
+FUNCTION ufix8 FONTFAR *read_bbox(pointer, pPmin, pPmax, set_flag)
+GDECL
+ufix8 FONTFAR *pointer;    /* Pointer to next byte in char data */
+point_t STACKFAR *pPmin;      /* Lower left corner of bounding box */
+point_t STACKFAR *pPmax;      /* Upper right corner of bounding box */
+boolean set_flag; /* flag to indicate whether global oru bbox should be saved */
+/*
+ * Called by make_simp_char() and make_comp_char() to read the 
+ * bounding box data from the font.
+ * Sets Pmin and Pmax to the bottom left and top right corners
+ * of the bounding box after transformation into device space.
+ * The units of Pmin and Pmax are sub-pixels.
+ * Updates *ppointer to point to the byte following the
+ * bounding box data.
+ */
+{
+ufix8    format1;
+ufix8    format;
+fix15    i;
+point_t  P;
+
+sp_globals.x_int = 0;
+sp_globals.y_int = sp_globals.Y_int_org;
+sp_globals.x_orus = sp_globals.y_orus = 0;
+format1 = NEXT_BYTE(pointer);
+pointer = sp_get_args(pointer, format1, pPmin);
+#if INCL_SQUEEZING || INCL_ISW
+if (set_flag)
+    {
+    sp_globals.bbox_xmin_orus = sp_globals.x_orus;
+    sp_globals.bbox_ymin_orus = sp_globals.y_orus;
+    }
+#endif
+*pPmax = *pPmin;
+for (i = 1; i < 4; i++)
+    {
+    switch(i)
+        {
+    case 1:
+        if (format1 & BIT6)            /* Xmax requires X int zone 1? */
+            sp_globals.x_int++;
+        format = (format1 >> 4) | 0x0c;
+        break;
+
+    case 2:
+        if (format1 & BIT7)            /* Ymax requires Y int zone 1? */
+            sp_globals.y_int++;
+        format = NEXT_BYTE(pointer);
+        break;
+
+    case 3:
+        sp_globals.x_int = 0; 
+        format >>= 4;
+        break;
+
+    default:
+               break;
+        }
+
+    pointer = sp_get_args(pointer, format, &P);
+#if INCL_SQUEEZING || INCL_ISW
+    if (set_flag && (i==2))
+       {
+       sp_globals.bbox_xmax_orus = sp_globals.x_orus;
+       sp_globals.bbox_ymax_orus = sp_globals.y_orus;
+       }
+#endif
+    if ((i == 2) || (!sp_globals.normal)) 
+        {
+        if (P.x < pPmin->x)
+            pPmin->x = P.x;
+        if (P.y < pPmin->y)
+            pPmin->y = P.y;
+        if (P.x > pPmax->x)
+            pPmax->x = P.x;
+        if (P.y > pPmax->y)
+            pPmax->y = P.y;
+        }
+    }
+
+#if DEBUG
+printf("BBOX %6.1f(Xint 0), %6.1f(Yint 0), %6.1f(Xint %d), %6.1f(Yint %d)\n",
+    (real)pPmin->x / (real)sp_globals.onepix, 
+    (real)pPmin->y / (real)sp_globals.onepix, 
+    (real)pPmax->x / (real)sp_globals.onepix, 
+    (format1 >> 6) & 0x01,
+    (real)pPmax->y / (real)sp_globals.onepix,
+    (format1 >> 7) & 0x01);
+
+#endif
+return pointer;
+}
+\f
+FUNCTION void proc_outl_data(pointer)
+GDECL
+ufix8 FONTFAR *pointer;      /* Pointer to next byte in char data */
+/*
+ * Called by make_simp_char() and make_comp_char() to read the 
+ * outline data from the font.
+ * The outline data is parsed, transformed into device coordinates
+ * and passed to an output module for further processing.
+ * Note that pointer is not updated to facilitate repeated
+ * processing of the outline data when banding mode is in effect.
+ */
+{
+ufix8    format1, format2;
+point_t  P0, P1, P2, P3;
+fix15    depth;
+fix15    curve_count;
+
+sp_globals.x_int = 0;
+sp_globals.y_int = sp_globals.Y_int_org;
+#if INCL_PLAID_OUT                 /* Plaid data monitoring included? */
+record_xint((fix15)sp_globals.x_int);         /* Record xint data */
+record_yint((fix15)(sp_globals.y_int - sp_globals.Y_int_org)); /* Record yint data */
+#endif
+
+sp_globals.x_orus = sp_globals.y_orus = 0;
+curve_count = 0;
+while(TRUE)
+    {
+    format1 = NEXT_BYTE(pointer);
+    switch(format1 >> 4)
+        {
+    case 0:                        /* LINE */
+        pointer = sp_get_args(pointer, format1, &P1);
+#if DEBUG
+        printf("LINE %6.1f, %6.1f\n",
+            (real)P1.x / (real)sp_globals.onepix, (real)P1.y / (real)sp_globals.onepix);
+#endif
+        fn_line(P1);
+        sp_globals.P0 = P1;
+        continue;
+
+    case 1:                        /* Short XINT */
+        sp_globals.x_int = format1 & 0x0f;
+#if DEBUG
+        printf("XINT %d\n", sp_globals.x_int);
+#endif
+#if INCL_PLAID_OUT                 /* Plaid data monitoring included? */
+record_xint((fix15)sp_globals.x_int);         /* Record xint data */
+#endif
+        continue;
+
+    case 2:                        /* Short YINT */
+        sp_globals.y_int = sp_globals.Y_int_org + (format1 & 0x0f);
+#if DEBUG
+        printf("YINT %d\n", sp_globals.y_int - sp_globals.Y_int_org);
+#endif
+#if INCL_PLAID_OUT                 /* Plaid data monitoring included? */
+record_yint((fix15)(sp_globals.y_int - sp_globals.Y_int_org)); /* Record yint data */
+#endif
+        continue;
+         
+    case 3:                        /* Miscellaneous */
+        switch(format1 & 0x0f)
+            {
+        case 0:                    /* END */
+            if (curve_count)
+                {
+                fn_end_contour();
+                }
+            return;
+
+        case 1:                     /* Long XINT */
+            sp_globals.x_int = NEXT_BYTE(pointer);
+#if DEBUG
+            printf("XINT %d\n", sp_globals.x_int);
+#endif
+#if INCL_PLAID_OUT                 /* Plaid data monitoring included? */
+record_xint((fix15)sp_globals.x_int);         /* Record xint data */
+#endif
+            continue;
+
+        case 2:                     /* Long YINT */
+            sp_globals.y_int = sp_globals.Y_int_org + NEXT_BYTE(pointer);
+#if DEBUG
+            printf("YINT %d\n", sp_globals.y_int - sp_globals.Y_int_org);
+#endif
+#if INCL_PLAID_OUT                 /* Plaid data monitoring included? */
+record_yint((fix15)(sp_globals.y_int - sp_globals.Y_int_org)); /* Record yint data */
+#endif
+            continue;
+
+        default:                    /* Not used */
+            continue;
+            }    
+
+    case 4:                         /* MOVE Inside */
+    case 5:                         /* MOVE Outside */
+        if (curve_count++)
+            {
+            fn_end_contour();
+            }                                
+               
+        pointer = sp_get_args(pointer, format1, &P0);
+               sp_globals.P0 = P0;
+#if DEBUG
+        printf("MOVE %6.1f, %6.1f\n",
+            (real)sp_globals.P0.x / (real)sp_globals.onepix, (real)sp_globals.P0.y / (real)sp_globals.onepix);
+#endif
+        fn_begin_contour(sp_globals.P0, (boolean)(format1 & BIT4));
+        continue;
+
+    case 6:                         /* Undefined */
+#if DEBUG
+        printf("*** Undefined instruction (Hex %4x)\n", format1);
+#endif
+        continue;
+
+    case 7:                         /* Undefined */
+#if DEBUG
+        printf("*** Undefined instruction (Hex %4x)\n", format1);
+#endif
+        continue;
+
+    default:                        /* CRVE */
+        format2 = NEXT_BYTE(pointer);
+        pointer = sp_get_args(pointer, format1, &P1);
+        pointer = sp_get_args(pointer, format2, &P2);
+        pointer = sp_get_args(pointer, (ufix8)(format2 >> 4), &P3);
+        depth = (format1 >> 4) & 0x07;
+#if DEBUG
+        printf("CRVE %6.1f, %6.1f, %6.1f, %6.1f, %6.1f, %6.1f, %d\n",
+            (real)P1.x / (real)sp_globals.onepix, (real)P1.y / (real)sp_globals.onepix, 
+            (real)P2.x / (real)sp_globals.onepix, (real)P2.y / (real)sp_globals.onepix,
+            (real)P3.x / (real)sp_globals.onepix, (real)P3.y / (real)sp_globals.onepix,
+            depth);
+#endif
+        depth += sp_globals.depth_adj;
+        if (sp_globals.curves_out)
+            {
+            fn_curve(P1, P2, P3, depth);
+            sp_globals.P0 = P3;
+            continue;
+            }
+        if (depth <= 0)
+            {
+            fn_line(P3);
+            sp_globals.P0 = P3;
+            continue;
+            }   
+        sp_split_curve(P1, P2, P3, depth);
+        continue;
+        }
+    }
+}
+\f
+FUNCTION static void sp_split_curve(P1, P2, P3, depth)
+GDECL
+point_t P1;    /* First control point of Bezier curve */
+point_t P2;    /* Second  control point of Bezier curve */
+point_t P3;    /* End point of Bezier curve */
+fix15   depth; /* Levels of recursive subdivision required */
+/*
+ * Called by proc_outl_data() to subdivide Bezier curves into an
+ * appropriate number of vectors, whenever curves are not enabled
+ * for output to the currently selected output module.
+ * sp_split_curve() calls itself recursively to the depth specified
+ * at which point it calls line() to deliver each vector resulting
+ * from the spliting process.
+ */
+{
+fix31   X0 = (fix31)sp_globals.P0.x;
+fix31   Y0 = (fix31)sp_globals.P0.y;
+fix31   X1 = (fix31)P1.x;
+fix31   Y1 = (fix31)P1.y;
+fix31   X2 = (fix31)P2.x;
+fix31   Y2 = (fix31)P2.y;
+fix31   X3 = (fix31)P3.x;
+fix31   Y3 = (fix31)P3.y;
+point_t Pmid;
+point_t Pctrl1;
+point_t Pctrl2;
+
+#if DEBUG
+printf("CRVE(%3.1f, %3.1f, %3.1f, %3.1f, %3.1f, %3.1f)\n",
+    (real)P1.x / (real)sp_globals.onepix, (real)P1.y / (real)sp_globals.onepix,
+    (real)P2.x / (real)sp_globals.onepix, (real)P2.y / (real)sp_globals.onepix,
+    (real)P3.x / (real)sp_globals.onepix, (real)P3.y / (real)sp_globals.onepix);
+#endif
+
+
+Pmid.x = (X0 + (X1 + X2) * 3 + X3 + 4) >> 3;
+Pmid.y = (Y0 + (Y1 + Y2) * 3 + Y3 + 4) >> 3;
+if ((--depth) <= 0)
+    {
+    fn_line(Pmid);
+    sp_globals.P0 = Pmid;
+    fn_line(P3);
+    sp_globals.P0 = P3;
+    }
+else
+    {
+    Pctrl1.x = (X0 + X1 + 1) >> 1;
+    Pctrl1.y = (Y0 + Y1 + 1) >> 1;
+    Pctrl2.x = (X0 + (X1 << 1) + X2 + 2) >> 2;
+    Pctrl2.y = (Y0 + (Y1 << 1) + Y2 + 2) >> 2;
+    sp_split_curve(Pctrl1, Pctrl2, Pmid, depth);
+    Pctrl1.x = (X1 + (X2 << 1) + X3 + 2) >> 2;
+    Pctrl1.y = (Y1 + (Y2 << 1) + Y3 + 2) >> 2;
+    Pctrl2.x = (X2 + X3 + 1) >> 1;
+    Pctrl2.y = (Y2 + Y3 + 1) >> 1;
+    sp_split_curve(Pctrl1, Pctrl2, P3, depth);
+    }
+}
+\f
+FUNCTION static ufix8 FONTFAR *sp_get_args(pointer, format, pP)
+GDECL
+ufix8 FONTFAR  *pointer;  /* Pointer to next byte in char data */
+ufix8     format;    /* Format specifiaction of argument pair */
+point_t STACKFAR *pP;        /* Resulting transformed point */
+/*
+ * Called by read_bbox() and proc_outl_data() to read an X Y argument
+ * pair from the font.
+ * The format is specified as follows:
+ *     Bits 0-1: Type of X argument.
+ *     Bits 2-3: Type of Y argument.
+ * where the 4 possible argument types are:
+ *     Type 0:   Controlled coordinate represented by one byte
+ *               index into the X or Y controlled coordinate table.
+ *     Type 1:   Interpolated coordinate represented by a two-byte
+ *               signed integer.
+ *     Type 2:   Interpolated coordinate represented by a one-byte
+ *               signed increment/decrement relative to the 
+ *               proceding X or Y coordinate.
+ *     Type 3:   Repeat of preceding X or Y argument value and type.
+ * The units of P are sub-pixels.
+ * Updates *ppointer to point to the byte following the
+ * argument pair.
+ */
+{
+ufix8   edge;
+
+/* Read X argument */
+switch(format & 0x03)
+    {
+case 0:                           /* Index to controlled oru */
+    edge = NEXT_BYTE(pointer);
+    sp_globals.x_orus = sp_plaid.orus[edge];
+#if INCL_RULES
+    sp_globals.x_pix = sp_plaid.pix[edge];
+#endif
+    break;
+
+case 1:                           /* 2 byte interpolated oru value */
+    sp_globals.x_orus = NEXT_WORD(pointer);
+    goto L1;
+
+case 2:                           /* 1 byte signed oru increment */
+    sp_globals.x_orus += (fix15)((fix7)NEXT_BYTE(pointer));
+L1: 
+#if INCL_RULES
+    sp_globals.x_pix = TRANS(sp_globals.x_orus, sp_plaid.mult[sp_globals.x_int], sp_plaid.offset[sp_globals.x_int], sp_globals.mpshift);
+#endif
+    break;
+
+default:                          /* No change in X value */
+    break;
+    }
+
+/* Read Y argument */
+switch((format >> 2) & 0x03)
+    {
+case 0:                           /* Index to controlled oru */
+    edge = sp_globals.Y_edge_org + NEXT_BYTE(pointer);
+    sp_globals.y_orus = sp_plaid.orus[edge];
+#if INCL_RULES
+    sp_globals.y_pix = sp_plaid.pix[edge];
+#endif
+    break;
+
+case 1:                           /* 2 byte interpolated oru value */
+    sp_globals.y_orus = NEXT_WORD(pointer);
+    goto L2;
+
+case 2:                           /* 1 byte signed oru increment */
+    sp_globals.y_orus += (fix15)((fix7)NEXT_BYTE(pointer));
+L2: 
+#if INCL_RULES
+    sp_globals.y_pix = TRANS(sp_globals.y_orus, sp_plaid.mult[sp_globals.y_int], sp_plaid.offset[sp_globals.y_int], sp_globals.mpshift);
+#endif
+    break;
+
+default:                          /* No change in X value */
+    break;
+    }
+
+#if INCL_RULES
+switch(sp_globals.tcb.xmode)
+    {
+case 0:                           /* X mode 0 */
+    pP->x = sp_globals.x_pix;
+    break;
+
+case 1:                           /* X mode 1 */
+    pP->x = -sp_globals.x_pix;
+    break;
+
+case 2:                           /* X mode 2 */
+    pP->x = sp_globals.y_pix;
+    break;
+
+case 3:                           /* X mode 3 */
+    pP->x = -sp_globals.y_pix;
+    break;
+
+default:                          /* X mode 4 */
+#endif
+    pP->x = (MULT16(sp_globals.x_orus, sp_globals.tcb.xxmult) + 
+             MULT16(sp_globals.y_orus, sp_globals.tcb.xymult) + 
+             sp_globals.tcb.xoffset) >> sp_globals.mpshift;
+#if INCL_RULES
+    break;
+    }
+
+switch(sp_globals.tcb.ymode)
+    {
+case 0:                           /* Y mode 0 */
+    pP->y = sp_globals.y_pix;
+    break;
+
+case 1:                           /* Y mode 1 */
+    pP->y = -sp_globals.y_pix;
+    break;
+
+case 2:                           /* Y mode 2 */
+    pP->y = sp_globals.x_pix;
+    break;
+
+case 3:                           /* Y mode 3 */
+    pP->y = -sp_globals.x_pix;
+    break;
+
+default:                          /* Y mode 4 */
+#endif
+    pP->y = (MULT16(sp_globals.x_orus, sp_globals.tcb.yxmult) + 
+             MULT16(sp_globals.y_orus, sp_globals.tcb.yymult) + 
+             sp_globals.tcb.yoffset) >> sp_globals.mpshift;
+#if INCL_RULES
+    break;
+    }
+#endif
+
+return pointer;
+}
+
+
+
diff --git a/Xserver/lib/font/Speedo/htest.c b/Xserver/lib/font/Speedo/htest.c
new file mode 100644 (file)
index 0000000..a5366a2
--- /dev/null
@@ -0,0 +1,361 @@
+/* $XConsortium: htest.c,v 1.2 91/05/11 09:48:58 rws Exp $ */
+
+/*
+
+Copyright 1989-1991, Bitstream Inc., Cambridge, MA.
+You are hereby granted permission under all Bitstream propriety rights to
+use, copy, modify, sublicense, sell, and redistribute the Bitstream Speedo
+software and the Bitstream Charter outline font for any purpose and without
+restrictions; provided, that this notice is left intact on all copies of such
+software or font and that Bitstream's trademark is acknowledged as shown below
+on all unmodified copies of such font.
+
+BITSTREAM CHARTER is a registered trademark of Bitstream Inc.
+
+
+BITSTREAM INC. DISCLAIMS ANY AND ALL WARRANTIES, EXPRESS OR IMPLIED, INCLUDING
+WITHOUT LIMITATION THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+PARTICULAR PURPOSE.  BITSTREAM SHALL NOT BE LIABLE FOR ANY DIRECT OR INDIRECT
+DAMAGES, INCLUDING BUT NOT LIMITED TO LOST PROFITS, LOST DATA, OR ANY OTHER
+INCIDENTAL OR CONSEQUENTIAL DAMAGES, ARISING OUT OF OR IN ANY WAY CONNECTED
+WITH THE SPEEDO SOFTWARE OR THE BITSTREAM CHARTER OUTLINE FONT.
+
+*/
+
+/****************************** H T E S T . C ********************************
+ *                                                                           *
+ *              SPEEDO FONT HEADER TEST MODULE                               *
+ *                                                                           *
+ ****************************************************************************/
+
+
+#include "speedo.h"                 /* General definition for make_bmap */
+#include <stdio.h>
+
+#define DEBUG  0
+
+#if DEBUG
+#define SHOW(X) printf("X = %d\n", X)
+#else
+#define SHOW(X)
+#endif
+
+#define FONT_BUFFER_SIZE  1000
+
+/***** EXTERNAL FUNCTIONS *****/
+
+/***** STATIC VARIABLES *****/
+static  char   pathname[100]; /* Name of font file to be output */
+static  ufix8  font_buffer[FONT_BUFFER_SIZE]; /* Font buffer */
+static  FILE  *fdescr;             /* Speedo outline file descriptor */
+
+
+\f
+FUNCTION main(argc,argv)
+int argc;
+char *argv[];
+{
+int     bytes_read;           /* Number of bytes read from font file */
+ufix8   tmpufix8;             /* Temporary workspace */
+fix15   tmpfix15;             /* Temporary workspace */
+ufix16  tmpufix16;            /* Temporary workspace */
+ufix32  tmpufix32;            /* Temporary workspace */
+ufix8  *pvt_header_org;       /* Origin of provate header data */
+
+ufix8   read_1b();            /* Read 1 byte field from font header */
+fix15   read_2b();            /* Read 2 byte field from font header */
+fix31   read_4b();            /* Read 4 byte field from font header */
+
+if (argc != 2) 
+    {
+    fprintf(stderr,"Usage: htest {fontfile}\n\n"); 
+    exit (1);
+    }
+
+sprintf(pathname, argv[1]);
+
+/* Initialization */
+printf("\n      SPEEDO FONT FILE HEADER DATA\n");
+printf("      -------------------------\n\n");
+/* Load Speedo outline file */
+fdescr = fopen (pathname, "rb");
+if (fdescr == NULL)
+    {
+    printf("****** Cannot open file %s\n", pathname);
+    return;                  
+    }
+
+bytes_read = fread(font_buffer, sizeof(ufix8), sizeof(font_buffer), fdescr);
+if (bytes_read == 0)
+    {
+    printf("****** Error on reading %s: %x\n", pathname, bytes_read);
+    fclose(fdescr);     
+    return;
+    }
+
+printf("Format Identifier ...................... %.4s\n", font_buffer + FH_FMVER);
+
+tmpufix32 = (ufix32)read_4b(font_buffer + FH_FMVER + 4);
+printf("CR-LF-NULL-NULL data ............... %8.8lx %s\n", tmpufix32, (tmpufix32 != 0x0d0a0000)? "(incorrect)": " ");
+
+printf("Font Size .............................. %4ld\n", (ufix32)read_4b(font_buffer + FH_FNTSZ));
+
+printf("Minimum Font Buffer Size ............... %4ld\n", (ufix32)read_4b(font_buffer + FH_FBFSZ));
+
+printf("Minimum Character Buffer Size .......... %4d\n", (ufix16)read_2b(font_buffer + FH_CBFSZ));
+
+printf("Header Size ............................ %4d\n", (ufix16)read_2b(font_buffer + FH_HEDSZ));
+
+printf("Font ID ................................ %4.4d\n", (ufix16)read_2b(font_buffer + FH_FNTID));
+
+printf("Font Version Number .................... %4d\n", (ufix16)read_1b(font_buffer + FH_SFVNR));
+
+printf("Font Full Name:\n    %.70s\n", font_buffer + FH_FNTNM);
+
+printf("Manufacturing Date ................ %10.10s\n", font_buffer + FH_MDATE);
+
+printf("Character Set Name:\n    %s\n", font_buffer + FH_LAYNM);
+
+printf("Character Set ID: ...................... %.4s\n", font_buffer + FH_LAYNM + 66);
+
+printf("Copyright Notice:\n    %.70s\n", font_buffer + FH_CPYRT);
+
+printf("Number of Char. Indexes in Char. Set ... %4d\n", (ufix16)read_2b(font_buffer + FH_NCHRL));
+
+printf("Total number of Char. Indexes in Font .. %4d\n", (ufix16)read_2b(font_buffer + FH_NCHRF));
+
+printf("Index of First Character ............... %4d\n", (ufix16)read_2b(font_buffer + FH_FCHRF));
+
+printf("Number of Kerning Tracks ............... %4d\n", (ufix16)read_2b(font_buffer + FH_NKTKS));
+
+printf("Number of Kerning Pairs ................ %4d\n", (ufix16)read_2b(font_buffer + FH_NKPRS));
+
+printf("Font Flags:\n");
+tmpufix8 = read_1b(font_buffer + FH_FLAGS);
+printf("    Extended font ...................... %s\n", (tmpufix8 & BIT0)? " Yes": "  No");
+
+printf("Classification Flags:\n");
+tmpufix8 = read_1b(font_buffer + FH_CLFGS);
+printf("    Italic ............................. %s\n", (tmpufix8 & BIT0)? " Yes": "  No");
+printf("    Monospace .......................... %s\n", (tmpufix8 & BIT1)? " Yes": "  No");
+printf("    Serif .............................. %s\n", (tmpufix8 & BIT2)? " Yes": "  No");
+printf("    Display ............................ %s\n", (tmpufix8 & BIT3)? " Yes": "  No");
+
+tmpufix8 = read_1b(font_buffer + FH_FAMCL);
+printf("Family Classification .................. %4d ", tmpufix8);
+switch (tmpufix8)
+    {
+case 0:
+    printf("(Don't care)\n");
+    break;
+case 1:
+    printf("(Serif)\n");
+    break;
+case 2:
+    printf("(Sans serif)\n");
+    break;
+case 3:
+    printf("(Monospace)\n");
+    break;
+case 4:
+    printf("(Script or calligraphic)\n");
+    break;
+case 5:
+    printf("(Decorative)\n");
+    break;
+default:
+    printf("\n");
+    break;
+    }
+
+printf("Font Form Classification:\n");
+tmpufix8 = read_1b(font_buffer + FH_FRMCL);
+printf("    Width Type ......................... %4d ", (tmpufix8 & 0x0f));
+switch (tmpufix8 & 0x0f)
+    {
+case 4:
+    printf("(Condensed)\n");
+    break;
+case 6:
+    printf("(Semi-condensed)\n");
+    break;
+case 8:
+    printf("(Normal)\n");
+    break;
+case 10:
+    printf("(Semi-expanded)\n");
+    break;
+case 12:
+    printf("(Expanded)\n");
+    break;
+default:
+    printf("\n");
+    break;
+    }
+printf("    Weight ............................. %4d ", (tmpufix8 >> 4));
+switch (tmpufix8 >> 4)
+    {
+case 1:
+    printf("(Thin)\n");
+    break;
+case 2:
+    printf("(Ultralight)\n");
+    break;
+case 3:
+    printf("(Extra light)\n");
+    break;
+case 4:
+    printf("(Light)\n");
+    break;
+case 5:
+    printf("(Book)\n");
+    break;
+case 6:
+    printf("(Normal)\n");
+    break;
+case 7:
+    printf("(Medium)\n");
+    break;
+case 8:
+    printf("(Semibold)\n");
+    break;
+case 9:
+    printf("(Demibold)\n");
+    break;
+case 10:
+    printf("(Bold)\n");
+    break;
+case 11:
+    printf("(Extrabold)\n");
+    break;
+case 12:
+    printf("(Ultrabold)\n");
+    break;
+case 13:
+    printf("(Heavy)\n");
+    break;
+case 14:
+    printf("(Black)\n");
+    break;
+default:
+    printf("\n");
+    break;
+    }
+
+printf("Short Font Name ........................ %.16s\n", font_buffer + FH_SFNTN);
+
+printf("Short Face Name ........................ %.16s\n", font_buffer + FH_SFACN);
+
+printf("Font Form .............................. %.14s\n", font_buffer + FH_FNTFM);
+
+printf("Italic Angle ........................... %7.2f\n", ((real)read_2b(font_buffer + FH_ITANG) / 256.0));
+
+printf("ORUs per Em ............................ %4d\n", (ufix16)read_2b(font_buffer + FH_ORUPM));
+
+printf("Width of Word Space .................... %4d\n", (ufix16)read_2b(font_buffer + FH_WDWTH));
+
+printf("Width of Em Space ...................... %4d\n", (ufix16)read_2b(font_buffer + FH_EMWTH));
+
+printf("Width of En Space ...................... %4d\n", (ufix16)read_2b(font_buffer + FH_ENWTH));
+
+printf("Width of Thin Space .................... %4d\n", (ufix16)read_2b(font_buffer + FH_TNWTH));
+
+printf("Width of Figure Space .................. %4d\n", (ufix16)read_2b(font_buffer + FH_FGWTH));
+
+printf("Min X coordinate in font ............... %4d\n", (fix15)read_2b(font_buffer + FH_FXMIN));
+
+printf("Min Y coordinate in font ............... %4d\n", (fix15)read_2b(font_buffer + FH_FYMIN));
+
+printf("Max X coordinate in font ............... %4d\n", (fix15)read_2b(font_buffer + FH_FXMAX));
+
+printf("Max Y coordinate in font ............... %4d\n", (fix15)read_2b(font_buffer + FH_FYMAX));
+
+printf("Underline Position ..................... %4d\n", (fix15)read_2b(font_buffer + FH_ULPOS));
+
+printf("Underline Thickness .................... %4d\n", (fix15)read_2b(font_buffer + FH_ULTHK));
+
+printf("Small Caps Y position .................. %4d\n", (fix15)read_2b(font_buffer + FH_SMCTR));
+printf("Small Caps X scale ..................... %7.2f\n", ((real)read_2b(font_buffer + FH_SMCTR + 2) / 4096.0));
+printf("Small Caps Y scale ..................... %7.2f\n", ((real)(fix15)read_2b(font_buffer + FH_SMCTR + 4) / 4096.0));
+
+printf("Display Superiors Y position ........... %4d\n", (fix15)read_2b(font_buffer + FH_SMCTR));
+printf("Display Superiors X scale .............. %7.2f\n", ((real)read_2b(font_buffer + FH_SMCTR + 2) / 4096.0));
+printf("Display Superiors Y scale .............. %7.2f\n", ((real)read_2b(font_buffer + FH_SMCTR + 4) / 4096.0));
+
+printf("Footnote Superiors Y position .......... %4d\n", (fix15)read_2b(font_buffer + FH_FNSTR));
+printf("Footnote Superiors X scale ............. %7.2f\n", ((real)read_2b(font_buffer + FH_FNSTR + 2) / 4096.0));
+printf("Footnote Superiors Y scale ............. %7.2f\n", ((real)read_2b(font_buffer + FH_FNSTR + 4) / 4096.0));
+
+printf("Alpha Superiors Y position ............. %4d\n", (fix15)read_2b(font_buffer + FH_ALSTR));
+printf("Alpha Superiors X scale ................ %7.2f\n", ((real)read_2b(font_buffer + FH_ALSTR + 2) / 4096.0));
+printf("Alpha Superiors Y scale ................ %7.2f\n", ((real)read_2b(font_buffer + FH_ALSTR + 4) / 4096.0));
+
+printf("Chemical Inferiors Y position .......... %4d\n", (fix15)read_2b(font_buffer + FH_CMITR));
+printf("Chemical Inferiors X scale ............. %7.2f\n", ((real)read_2b(font_buffer + FH_CMITR + 2) / 4096.0));
+printf("Chemical Inferiors Y scale ............. %7.2f\n", ((real)read_2b(font_buffer + FH_CMITR + 4) / 4096.0));
+
+printf("Small Numerators Y position ............ %4d\n", (fix15)read_2b(font_buffer + FH_SNMTR));
+printf("Small Numerators X scale ............... %7.2f\n", ((real)read_2b(font_buffer + FH_SNMTR + 2) / 4096.0));
+printf("Small Numerators Y scale ............... %7.2f\n", ((real)read_2b(font_buffer + FH_SNMTR + 4) / 4096.0));
+
+printf("Small Denominators Y position .......... %4d\n", (fix15)read_2b(font_buffer + FH_SDNTR));
+printf("Small Denominators X scale ............. %7.2f\n", ((real)read_2b(font_buffer + FH_SDNTR + 2) / 4096.0));
+printf("Small Denominators Y scale ............. %7.2f\n", ((real)read_2b(font_buffer + FH_SDNTR + 4) / 4096.0));
+
+printf("Medium Numerators Y position ........... %4d\n", (fix15)read_2b(font_buffer + FH_MNMTR));
+printf("Medium Numerators X scale .............. %7.2f\n", ((real)read_2b(font_buffer + FH_MNMTR + 2) / 4096.0));
+printf("Medium Numerators Y scale .............. %7.2f\n", ((real)read_2b(font_buffer + FH_MNMTR + 4) / 4096.0));
+
+printf("Medium Denominators Y position ......... %4d\n", (fix15)read_2b(font_buffer + FH_MDNTR));
+printf("Medium Denominators X scale ............ %7.2f\n", ((real)read_2b(font_buffer + FH_MDNTR + 2) / 4096.0));
+printf("Medium Denominators Y scale ............ %7.2f\n", ((real)read_2b(font_buffer + FH_MDNTR + 4) / 4096.0));
+
+printf("Large Numerators Y position ............ %4d\n", (fix15)read_2b(font_buffer + FH_LNMTR));
+printf("Large Numerators X scale ............... %7.2f\n", ((real)read_2b(font_buffer + FH_LNMTR + 2) / 4096.0));
+printf("Large Numerators Y scale ............... %7.2f\n", ((real)read_2b(font_buffer + FH_LNMTR + 4) / 4096.0));
+
+printf("Large Denominators Y position .......... %4d\n", (fix15)read_2b(font_buffer + FH_LDNTR));
+printf("Large Denominators X scale ............. %7.2f\n", ((real)read_2b(font_buffer + FH_LDNTR + 2) / 4096.0));
+printf("Large Denominators Y scale ............. %7.2f\n", ((real)read_2b(font_buffer + FH_LDNTR + 4) / 4096.0));
+
+fclose(fdescr);     
+}
+
+\f
+FUNCTION ufix8 read_1b(pointer)
+ufix8 *pointer;
+/*
+ * Reads 1-byte field from font buffer 
+ */
+{
+return *pointer;
+}
+\f
+FUNCTION fix15 read_2b(pointer)
+ufix8 *pointer;
+/*
+ * Reads 2-byte field from font buffer 
+ */
+{
+fix31 temp;
+
+temp = *pointer++;
+temp = (temp << 8) + *(pointer);
+return temp;
+}
+\f
+FUNCTION fix31 read_4b(pointer)
+ufix8 *pointer;
+/*
+ * Reads 4-byte field from font buffer 
+ */
+{
+fix31 temp;
+
+temp = *pointer++;
+temp = (temp << 8) + *(pointer++);
+temp = (temp << 8) + *(pointer++);
+temp = (temp << 8) + *(pointer);
+return temp;
+}
+
diff --git a/Xserver/lib/font/Speedo/iface.c b/Xserver/lib/font/Speedo/iface.c
new file mode 100644 (file)
index 0000000..a5e1c69
--- /dev/null
@@ -0,0 +1,645 @@
+/* $XConsortium: iface.c,v 1.3 94/04/17 20:17:44 rws Exp $ */
+
+/*
+
+Copyright 1989-1991, Bitstream Inc., Cambridge, MA.
+You are hereby granted permission under all Bitstream propriety rights to
+use, copy, modify, sublicense, sell, and redistribute the Bitstream Speedo
+software and the Bitstream Charter outline font for any purpose and without
+restrictions; provided, that this notice is left intact on all copies of such
+software or font and that Bitstream's trademark is acknowledged as shown below
+on all unmodified copies of such font.
+
+BITSTREAM CHARTER is a registered trademark of Bitstream Inc.
+
+
+BITSTREAM INC. DISCLAIMS ANY AND ALL WARRANTIES, EXPRESS OR IMPLIED, INCLUDING
+WITHOUT LIMITATION THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+PARTICULAR PURPOSE.  BITSTREAM SHALL NOT BE LIABLE FOR ANY DIRECT OR INDIRECT
+DAMAGES, INCLUDING BUT NOT LIMITED TO LOST PROFITS, LOST DATA, OR ANY OTHER
+INCIDENTAL OR CONSEQUENTIAL DAMAGES, ARISING OUT OF OR IN ANY WAY CONNECTED
+WITH THE SPEEDO SOFTWARE OR THE BITSTREAM CHARTER OUTLINE FONT.
+
+*/
+
+/***************************** I F A C E . C *********************************
+ *                                                                           *
+ * This module provides a layer to make Speedo function calls to and         *
+ * from it compatible with Fontware 2.X function calls.                      *
+ *                                                                           *
+ ****************************************************************************/
+
+#include "speedo.h"               /* General definitions for Speedo */
+#include <math.h>
+
+#define   DEBUG      0
+
+#if DEBUG
+#include <stdio.h>
+#define SHOW(X) printf("X = %d\n", X)
+#else
+#define SHOW(X)
+#endif
+
+#define  PI     3.1415926536       /* pi */
+#define  PTPERINCH   72.2892       /* nbr points per inch, exactly! */
+
+#define  BIT8           0x0100
+#define  BIT9           0x0200
+#define  BIT10          0x0400
+#define  BIT11          0x0800
+#define  BIT12          0x1000
+#define  BIT13          0x2000
+#define  BIT14          0x4000
+#define  BIT15          0x8000
+
+#define   READ      0
+
+typedef   short     bool16;
+typedef   int       bool;
+
+typedef
+struct
+    {
+    bool16  left;
+    bool16  right;
+    bool16  top;
+    bool16  bottom;
+    }   lrtb;
+
+
+typedef
+struct
+    {
+    buff_t *pfont;              /* Pointer to font data                    */
+    ufix16  mode;               /* what mode is the font generator in      */
+    real    point_size_x;       /* Point size in X dimension               */
+    real    point_size_y;       /* Point size in Y dimension               */
+    real    res_hor;            /* Horizontal resolution of output device  */
+    real    res_ver;            /* Vertical resolution of output device    */
+    real    rot_angle;          /* Rotation angle in degrees (clockwise)   */
+    real    obl_angle;          /* Obliquing angle in degrees (clockwise)  */
+    bool16  whitewrite;         /* if T, generate bitmaps for whitewriters */
+    fix15   thresh;             /* Scan conversion threshold               *
+                                 * Thickens characters on each edge by     *
+                                 * <thresh> sub-pixels                     */  
+    bool16  import_widths;      /* Use imported width table                */
+    lrtb    clip;               /* Clip to standard character cell         */
+    lrtb    squeeze;            /* Squeeze to standard character cell      */
+    bool16  bogus_mode;         /* if T, ignore plaid data                 */
+    }   comp_char_desc;         /* character attributes for scan conv      */
+
+/***** GLOBAL VARIABLES *****/
+
+/*****  GLOBAL FUNCTIONS *****/
+     fw_reset();                /* Fontware 2.X reset call                 */
+     fw_set_specs();            /* Fontware 2.X set specs call             */
+bool fw_make_char();            /* Fontware 2.X make character call        */
+       
+/***** EXTERNAL VARIABLES *****/
+
+/***** EXTERNAL FUNCTIONS *****/
+void    _open_bitmap();
+void    _close_bitmap();
+void    _set_bitmap_bits();
+void    _open_outline();
+void    _open_outline();
+void    _start_new_char();
+void    _start_curve();
+void    _line_to();
+void    _close_curve();
+void    _close_outline();
+
+/***** STATIC VARIABLES *****/
+static specs_t *pspecs;
+static buff_t  *pfont;
+static buff_t   char_data;
+static fix15    set_width_x;
+static specs_t  specsarg;
+
+/***** STATIC FUNCTIONS *****/
+static fix31 make_mult();
+
+\f
+FUNCTION fw_reset()
+{
+sp_reset();
+}
+\f
+FUNCTION fw_set_specs(pspecs)
+comp_char_desc  *pspecs;  /* Pointer to scan conversion parameters structure */
+
+/*  Fontware 2.X character generator call to set font specifications
+ *  compc -- pointer to structure containing scan conversion parameters.
+ *   ->compf -- compressed font data structure
+ *   ->point_size_x -- x pointsize
+ *   ->point_size_y -- y pointsize
+ *   ->res_hor -- horizontal pixels per inch
+ *   ->res_ver -- vertical pixels per inch
+ *   ->rot_angle -- rotation angle in degrees (clockwise)
+ *   ->obl_angle -- obliquing angle in degrees (clockwise)
+ *   ->whitewrite -- if true, generate bitmaps for whitewriters
+ *   ->thresh -- scan-conversion threshold
+ *   ->import_widths -- if true, use external width table
+ *   ->clip.left -- clips min x at left of emsquare
+ *   ->clip.right -- clips max x at right of emsquare
+ *   ->clip.bottom -- clips min x at bottom of emsquare
+ *   ->clip.top -- clips max x at top of emsquare
+ *   ->squeeze.left -- squeezes min x at left of emsquare
+ *   ->squeeze.right, .top, .bottom  &c
+ *   ->sw_fixed -- if TRUE, match pixel widths to scaled outline widths
+ *   ->bogus_mode -- ignore plaid data if TRUE
+ */
+
+{
+fix15   irot;
+fix15   iobl;
+fix15   x_trans_type;
+fix15   y_trans_type;
+fix31   xx_mult;
+fix31   xy_mult;
+fix31   yx_mult;
+fix31   yy_mult;
+real    sinrot, cosrot, tanobl;
+real    x_distortion;
+real    pixperem_h;
+real    pixperem_v;
+real    point_size_x;
+real    point_size_y;
+real    res_hor;
+real    res_ver;
+fix15   mode;
+
+specsarg.pfont = pspecs->pfont;
+
+irot = floor(pspecs->rot_angle + 0.5);
+iobl = floor(pspecs->obl_angle + 0.5);
+if (iobl > 85)
+    iobl = 85;
+if (iobl < -85)
+    iobl = -85;
+if ((irot % 90) == 0)
+    {
+    x_trans_type = y_trans_type = irot / 90 & 0x0003;
+    if (iobl != 0)
+        {
+        if (x_trans_type & 0x01)
+            y_trans_type = 4;
+        else
+            x_trans_type = 4;
+        }
+    }
+else if (((irot + iobl) % 90) == 0)
+    {
+    x_trans_type = y_trans_type = (irot + iobl) / 90 & 0x0003;
+    if (iobl != 0)
+        {
+        if (x_trans_type & 0x01)
+            x_trans_type = 4;
+        else
+            y_trans_type = 4;
+        }
+    }
+else
+    {
+    x_trans_type = y_trans_type = 4;
+    }
+
+point_size_x = pspecs->point_size_x;
+point_size_y = pspecs->point_size_y;
+res_hor = pspecs->res_hor;
+res_ver = pspecs->res_ver;
+
+switch (x_trans_type)
+    {
+case 0: 
+    xx_mult = make_mult(point_size_x, res_hor);
+    xy_mult = 0;
+    break;
+
+case 1:
+    xx_mult = 0;
+    xy_mult = make_mult(point_size_y, res_hor);
+    break;
+
+case 2: 
+    xx_mult = -make_mult(point_size_x, res_hor);
+    xy_mult = 0;
+    break;
+
+case 3:
+    xx_mult = 0;
+    xy_mult = -make_mult(point_size_y, res_hor);
+    break;
+
+default:
+    sinrot = sin((real)irot * PI / 180.);
+    cosrot = cos((real)irot * PI / 180.);
+    tanobl = tan((real)iobl * PI / 180.);
+    x_distortion = point_size_x / point_size_y;
+    pixperem_h = point_size_y * res_hor / (real)PTPERINCH;   /* this is NOT a bug */
+    xx_mult = floor(cosrot * x_distortion * pixperem_h * 65536.0 + 0.5);
+    xy_mult = floor((sinrot + cosrot * tanobl) * pixperem_h * 65536.0 + 0.5);
+    break;
+    }
+
+switch (y_trans_type)
+    {
+case 0: 
+    yx_mult = 0;
+    yy_mult = make_mult(point_size_y, res_ver);
+    break;
+
+case 1:
+    yx_mult = -make_mult(point_size_x, res_hor);
+    yy_mult = 0;
+    break;
+
+case 2: 
+    yx_mult = 0;
+    yy_mult = -make_mult(point_size_y, res_ver);
+    break;
+
+case 3:
+    yx_mult = make_mult(point_size_x, res_ver);
+    yy_mult = 0;
+    break;
+
+default:
+    sinrot = sin((real)irot * PI / 180.);
+    cosrot = cos((real)irot * PI / 180.);
+    tanobl = tan((real)iobl * PI / 180.);
+    x_distortion = point_size_x / point_size_y;
+    pixperem_v = point_size_y * res_ver / (real)PTPERINCH;
+    yx_mult = floor(-sinrot * x_distortion * pixperem_v * 65536.0 + 0.5);
+    yy_mult = floor((cosrot - sinrot * tanobl) * pixperem_v * 65536.0 + 0.5);
+    break;
+    }
+
+specsarg.xxmult = xx_mult;
+specsarg.xymult = xy_mult;
+specsarg.xoffset = 0;
+specsarg.yxmult = yx_mult;
+specsarg.yymult = yy_mult;
+specsarg.yoffset = 0;
+specsarg.out_info = 0;
+
+/* Select processing mode */
+switch (pspecs->mode)
+    {
+case 1:
+    if (pspecs->whitewrite)           /* White-write requested? */
+        {
+        mode = 1;
+        }
+    else
+        {
+        mode = 0;
+        }
+    break;
+    
+case 2:
+    mode = 2;
+    break;
+
+default:
+    mode = pspecs->mode;
+    break;
+    }
+
+if (pspecs->bogus_mode)        /* Linear transformation requested? */
+    {
+    mode |= BIT4;              /* Set linear tranformation flag */
+    }
+
+if (pspecs->import_widths)     /* Imported widths requested? */
+    {
+    mode |= BIT6;              /* Set imported width flag */
+    }
+
+if (pspecs->clip.left)         /* Clip left requested? */
+    {
+    mode |= BIT8;              /* Set clip left flag */
+    }
+
+if (pspecs->clip.right)        /* Clip right requested? */
+    {
+    mode |= BIT9;              /* Set clip right flag */
+    }
+
+if (pspecs->clip.top)          /* Clip top requested? */
+    {
+    mode |= BIT10;             /* Set clip top flag */
+    }
+
+if (pspecs->clip.bottom)       /* Clip bottom requested? */
+    {
+    mode |= BIT11;             /* Set clip bottom flag */
+    }
+
+if (pspecs->squeeze.left)      /* Squeeze left requested? */
+    {
+    mode |= BIT12;             /* Set squeeze left flag */
+    }
+
+if (pspecs->squeeze.right)     /* Squeeze right requested? */
+    {
+    mode |= BIT13;             /* Set squeeze right flag */
+    }
+
+if (pspecs->squeeze.top)       /* Squeeze top requested? */
+    {
+    mode |= BIT14;             /* Set squeeze top flag */
+    }
+
+if (pspecs->squeeze.bottom)    /* Squeeze bottom requested? */
+    {
+    mode |= BIT15;             /* Set squeeze bottom flag */
+    }
+
+specsarg.flags = mode;
+
+sp_set_specs(&specsarg);
+}
+\f
+FUNCTION static fix31 make_mult(point_size, resolution)
+real point_size;
+real resolution;
+{
+real ms_factor;
+
+return (fix31)floor((point_size * resolution * 65536.0) / (real)PTPERINCH + 0.5);
+}
+\f
+FUNCTION bool fw_make_char(char_index)
+ufix16 char_index;
+{
+return sp_make_char(char_index);
+}
+\f
+FUNCTION buff_t *sp_load_char_data(file_offset, no_bytes, cb_offset)
+fix31    file_offset;
+fix15    no_bytes;
+fix15    cb_offset;
+/* 
+ * Called by Speedo character generator to request that character
+ * data be loaded from the font file.
+ * This is a dummy function that assumes that the entire font has
+ * been loaded.
+ */
+{
+#if DEBUG
+printf("load_char_data(%d, %d, %d)\n", file_offset, no_bytes, char_offset);
+#endif
+char_data.org = pfont->org + file_offset;
+char_data.no_bytes = no_bytes;
+return &char_data;
+}
+\f
+FUNCTION void sp_report_error(n)
+fix15 n;        /* Error identification number */
+/*
+ * Called by Speedo character generator to report an error.
+ */
+{
+switch(n)
+    {
+case 1:
+    printf("Insufficient font data loaded\n");
+    break;
+
+case 3:
+    printf("Transformation matrix out of range\n");
+    break;
+
+case 4:
+    printf("Font format error\n");
+    break;
+                 
+case 5:
+    printf("Requested specs not compatible with output module\n");
+    break;
+
+case 7:
+    printf("Intelligent transformation requested but not supported\n");
+    break;
+
+case 8:
+    printf("Unsupported output mode requested\n");
+    break;
+
+case 9:
+    printf("Extended font loaded but only compact fonts supported\n");
+    break;
+
+case 10:
+    printf("Font specs not set prior to use of font\n");
+    break;
+
+case 12:
+    printf("Character data not available()\n");
+    break;
+
+case 13:
+    printf("Track kerning data not available()\n");
+    break;
+
+case 14:
+    printf("Pair kerning data not available()\n");
+    break;
+
+default:
+    printf("report_error(%d)\n", n);
+    break;
+    }
+}
+\f
+
+\f
+FUNCTION void sp_open_bitmap(sw_x, sw_y, xorg, yorg, xsize, ysize)
+fix31  sw_x;                           /* X component of escapement vector */
+fix31  sw_y;                           /* Y component of escapement vector */
+fix31  xorg;                           /* X origin */
+fix31  yorg;                           /* Y origin */
+fix15 xsize;                           /* width of bitmap */
+fix15 ysize;                           /* height of bitmap */
+/* 
+ * Called by Speedo character generator to initialize a buffer prior
+ * to receiving bitmap data.
+ */
+{
+
+fix15 xmin,xmax,ymin,ymax;
+
+#if DEBUG
+printf("sp_open_bitmap:\n");
+printf("    X component of set width vector = %3.1f\n", (real)sw_x / 65536.0);
+printf("    Y component of set width vector = %3.1f\n", (real)sw_y / 65536.0);
+printf("    Bounding box is (%d, %d, %d, %d)\n", xmin, ymin, xmax, ymax);
+#endif
+
+xmin = xorg >> 16;
+ymin = yorg >> 16;
+xmax = xmin + xsize;
+ymax = ymin + ysize;
+
+set_width_x = ((sw_x >> 15) + 1) >> 1;
+open_bitmap(set_width_x, xmin, xmax, ymin, ymax);
+}
+\f
+FUNCTION void sp_set_bitmap_bits(y, x1, x2)
+fix15 y, x1, x2;
+/* 
+ * Called by Speedo character generator to write one row of pixels 
+ * into the generated bitmap character.                               
+ */
+{
+#if DEBUG
+printf("set_bitmap_bits(%d, %d, %d)\n", y, x1, x2);
+#endif
+
+set_bitmap_bits(y, x1, x2);
+}
+\f
+FUNCTION void sp_close_bitmap()
+/* 
+ * Called by Speedo character generator to indicate all bitmap data
+ * has been generated.
+ */
+{
+#if DEBUG
+printf("close_bitmap()\n");
+#endif
+
+close_bitmap();
+}
+\f
+FUNCTION void sp_open_outline(sw_x, sw_y, xmin, xmax, ymin, ymax)
+fix31  sw_x;                           /* X component of escapement vector */
+fix31  sw_y;                           /* Y component of escapement vector */
+fix31  xmin;                           /* Minimum X value in outline */
+fix31  xmax;                           /* Maximum X value in outline */
+fix31  ymin;                           /* Minimum Y value in outline */
+fix31  ymax;                           /* Maximum Y value in outline */
+/*
+ * Called by Speedo character generator to initialize prior to
+ * outputting scaled outline data.
+ */
+{
+#if DEBUG
+printf("open_outline(%3.1f, %3.1f, %3.1f, %3.1f, %3.1f, %3.1f)\n",
+    (real)sw_x / 65536.0, (real)sw_y / 65536.0,
+    (real)xmin / 65536.0, (real)xmax / 65536.0, (real)ymin / 65536.0, (real)ymax / 65536.0);
+#endif
+
+set_width_x = ((sw_x >> 15) + 1) >> 1;
+open_outline(set_width_x);
+}
+\f
+FUNCTION void sp_start_new_char()
+/*
+ * Called by Speedo character generator to initialize prior to
+ * outputting scaled outline data for a sub-character in a compound
+ * character.
+ */
+{
+#if DEBUG
+printf("start_new_char()\n");
+#endif
+
+start_new_char();
+}
+\f
+FUNCTION void sp_start_contour(x, y, outside)
+fix31    x;       /* X coordinate of start point in 1/65536 pixels */
+fix31    y;       /* Y coordinate of start point in 1/65536 pixels */
+boolean outside;  /* TRUE if curve encloses ink (Counter-clockwise) */
+/*
+ * Called by Speedo character generator at the start of each contour
+ * in the outline data of the character.
+ */
+{
+real realx, realy;
+
+realx = (real)x / 65536.0;
+realy = (real)y / 65536.0;
+
+#if DEBUG
+printf("start_curve(%3.1f, %3.1f, %s)\n", 
+    realx, realy, 
+    outside? "outside": "inside");
+#endif
+
+start_curve(realx, realy, outside);
+}
+\f
+FUNCTION void sp_curve_to(x1, y1, x2, y2, x3, y3)
+fix31 x1;               /* X coordinate of first control point in 1/65536 pixels */
+fix31 y1;               /* Y coordinate of first control  point in 1/65536 pixels */
+fix31 x2;               /* X coordinate of second control point in 1/65536 pixels */
+fix31 y2;               /* Y coordinate of second control point in 1/65536 pixels */
+fix31 x3;               /* X coordinate of curve end point in 1/65536 pixels */
+fix31 y3;               /* Y coordinate of curve end point in 1/65536 pixels */
+/*
+ * Called by Speedo character generator once for each curve in the
+ * scaled outline data of the character. This function is only called if curve
+ * output is enabled in the set_specs() call.
+ */
+{
+#if DEBUG
+printf("curve_to(%3.1f, %3.1f, %3.1f, %3.1f, %3.1f, %3.1f)\n", 
+    (real)x1 / 65536.0, (real)y1 / 65536.0,
+    (real)x2 / 65536.0, (real)y2 / 65536.0,
+    (real)x3 / 65536.0, (real)y3 / 65536.0);
+#endif
+}
+\f
+FUNCTION void sp_line_to(x, y)
+fix31 x;               /* X coordinate of vector end point in 1/65536 pixels */
+fix31 y;               /* Y coordinate of vector end point in 1/65536 pixels */
+/*
+ * Called by Speedo character generator onece for each vector in the
+ * scaled outline data for the character. This include curve data that has
+ * been sub-divided into vectors if curve output has not been enabled
+ * in the set_specs() call.
+ */
+{
+real realx, realy;
+
+realx = (real)x / 65536.0;
+realy = (real)y / 65536.0;
+
+#if DEBUG
+printf("line_to(%3.1f, %3.1f)\n", 
+    realx, realy); 
+#endif            
+
+line_to(realx, realy);
+}
+\f
+FUNCTION void sp_close_contour()
+/*
+ * Called by Speedo character generator at the end of each contour
+ * in the outline data of the character.
+ */
+{
+#if DEBUG
+printf("close_curve()\n");
+#endif
+
+close_curve();
+}
+\f
+FUNCTION void sp_close_outline()
+/*
+ * Called by Speedo character generator at the end of output of the
+ * scaled outline of the character.
+ */
+{
+#if DEBUG
+printf("close_outline()\n");
+#endif
+
+close_outline(set_width_x);
+}
+
diff --git a/Xserver/lib/font/Speedo/keys.h b/Xserver/lib/font/Speedo/keys.h
new file mode 100644 (file)
index 0000000..c373491
--- /dev/null
@@ -0,0 +1,56 @@
+/* $XConsortium: keys.h,v 1.3 93/10/28 15:27:11 gildea Exp $ */
+
+/*
+
+Copyright 1989-1991, Bitstream Inc., Cambridge, MA.
+You are hereby granted permission under all Bitstream propriety rights to
+use, copy, modify, sublicense, sell, and redistribute the Bitstream Speedo
+software and the Bitstream Charter outline font for any purpose and without
+restrictions; provided, that this notice is left intact on all copies of such
+software or font and that Bitstream's trademark is acknowledged as shown below
+on all unmodified copies of such font.
+
+BITSTREAM CHARTER is a registered trademark of Bitstream Inc.
+
+
+BITSTREAM INC. DISCLAIMS ANY AND ALL WARRANTIES, EXPRESS OR IMPLIED, INCLUDING
+WITHOUT LIMITATION THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+PARTICULAR PURPOSE.  BITSTREAM SHALL NOT BE LIABLE FOR ANY DIRECT OR INDIRECT
+DAMAGES, INCLUDING BUT NOT LIMITED TO LOST PROFITS, LOST DATA, OR ANY OTHER
+INCIDENTAL OR CONSEQUENTIAL DAMAGES, ARISING OUT OF OR IN ANY WAY CONNECTED
+WITH THE SPEEDO SOFTWARE OR THE BITSTREAM CHARTER OUTLINE FONT.
+
+*/
+
+
+/***** DECRYPTION KEY CONSTANTS (PC Platform) *****/
+
+#define CUS0  432                  /* Customer number */
+
+#define KEY0    0                  /* Decryption key 0 */
+#define KEY1   72                  /* Decryption key 1 */
+#define KEY2  123                  /* Decryption key 2 */
+#define KEY3    1                  /* Decryption key 3 */
+#define KEY4  222                  /* Decryption key 4 */
+#define KEY5  194                  /* Decryption key 5 */
+#define KEY6  113                  /* Decryption key 6 */
+#define KEY7  119                  /* Decryption key 7 */
+#define KEY8   52                  /* Decryption key 8 */
+
+/***** DECRYPTION KEY CONSTANTS (Sample) *****/
+
+#define XSAMPLEFONTS
+
+#define XCUS0    0                 /* Customer number */
+
+#define XKEY0    0                  /* Decryption key 0 */
+#define XKEY1    0                  /* Decryption key 1 */
+#define XKEY2    0                  /* Decryption key 2 */
+#define XKEY3    0                  /* Decryption key 3 */
+#define XKEY4    0                  /* Decryption key 4 */
+#define XKEY5    0                  /* Decryption key 5 */
+#define XKEY6    0                  /* Decryption key 6 */
+#define XKEY7    0                  /* Decryption key 7 */
+#define XKEY8    0                  /* Decryption key 8 */
+
+
diff --git a/Xserver/lib/font/Speedo/nsample.c b/Xserver/lib/font/Speedo/nsample.c
new file mode 100644 (file)
index 0000000..489dbed
--- /dev/null
@@ -0,0 +1,745 @@
+/* $XConsortium: nsample.c,v 1.3 93/10/28 15:27:12 gildea Exp $ */
+
+/*
+
+Copyright 1989-1991, Bitstream Inc., Cambridge, MA.
+You are hereby granted permission under all Bitstream propriety rights to
+use, copy, modify, sublicense, sell, and redistribute the Bitstream Speedo
+software and the Bitstream Charter outline font for any purpose and without
+restrictions; provided, that this notice is left intact on all copies of such
+software or font and that Bitstream's trademark is acknowledged as shown below
+on all unmodified copies of such font.
+
+BITSTREAM CHARTER is a registered trademark of Bitstream Inc.
+
+
+BITSTREAM INC. DISCLAIMS ANY AND ALL WARRANTIES, EXPRESS OR IMPLIED, INCLUDING
+WITHOUT LIMITATION THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+PARTICULAR PURPOSE.  BITSTREAM SHALL NOT BE LIABLE FOR ANY DIRECT OR INDIRECT
+DAMAGES, INCLUDING BUT NOT LIMITED TO LOST PROFITS, LOST DATA, OR ANY OTHER
+INCIDENTAL OR CONSEQUENTIAL DAMAGES, ARISING OUT OF OR IN ANY WAY CONNECTED
+WITH THE SPEEDO SOFTWARE OR THE BITSTREAM CHARTER OUTLINE FONT.
+
+*/
+
+
+/*************************** N S A M P L E . C *******************************
+ *                                                                           *
+ *                 SPEEDO CHARACTER GENERATOR TEST MODULE                    *
+ *                                                                           *
+ * This is an illustration of what external resources are required to        *
+ * load a Speedo outline and use the Speedo character generator to generate  *
+ * bitmaps or scaled outlines according to the desired specification.        *                                                    *
+ *                                                                           *
+ * This program loads a Speedo outline, defines a set of character           *
+ * generation specifications, generates bitmap (or outline) data for each    *
+ * character in the font and prints them on the standard output.             *
+ *                                                                           *
+ * If the font buffer is too small to hold the entire font, the first        *
+ * part of the font is loaded. Character data is then loaded dynamically     *
+ * as required.                                                              *
+ *                                                                           *
+ ****************************************************************************/
+
+#include <stdio.h>
+#if PROTOS_AVAIL
+#include <stddef.h>
+#include <malloc.h>
+#include <stdlib.h>
+void main(int argc,char *argv[]);
+#else
+void* malloc();
+#endif
+
+#include "speedo.h"                 /* General definition for make_bmap */
+#include "keys.h"                  /* Font decryption keys */
+
+#define DEBUG  0
+
+#if DEBUG
+#define SHOW(X) printf("X = %d\n", X)
+#else
+#define SHOW(X)
+#endif
+
+#define MAX_BITS  256              /* Max line length of generated bitmap */
+
+/***** GLOBAL FUNCTIONS *****/
+
+/***** EXTERNAL FUNCTIONS *****/
+
+/***** STATIC FUNCTIONS *****/
+
+#if PROTOS_AVAIL
+fix31 read_4b(ufix8 FONTFAR *ptr);
+fix15 read_2b(ufix8 FONTFAR *ptr);
+#else
+fix31 read_4b();
+fix15 read_2b();
+#endif
+/***** STATIC VARIABLES *****/
+static  char   pathname[100];      /* Name of font file to be output */
+static  ufix8 FONTFAR *font_buffer;       /* Pointer to allocated Font buffer */
+static  ufix8 FONTFAR *char_buffer;       /* Pointer to allocate Character buffer */
+static  buff_t font;               /* Buffer descriptor for font data */
+#if INCL_LCD
+static  buff_t char_data;          /* Buffer descriptor for character data */
+#endif
+static  FILE  *fdescr;             /* Speedo outline file descriptor */
+static  ufix16 char_index;         /* Index of character to be generated */
+static  ufix16 char_id;            /* Character ID */
+static  ufix16 minchrsz;              /* minimum character buffer size */
+
+static  ufix8  key[] = 
+    {
+    KEY0, 
+    KEY1, 
+    KEY2, 
+    KEY3, 
+    KEY4, 
+    KEY5, 
+    KEY6, 
+    KEY7, 
+    KEY8
+    };                             /* Font decryption key */
+
+static  fix15  raswid;             /* raster width  */
+static  fix15  rashgt;             /* raster height */
+static  fix15  offhor;             /* horizontal offset from left edge of emsquare */
+static  fix15  offver;             /* vertical offset from baseline */
+static  fix15  set_width;          /* character set width */
+static  fix15  y_cur;              /* Current y value being generated and printed */
+static  char   line_of_bits[2 * MAX_BITS + 1]; /* Buffer for row of generated bits */
+
+#if INCL_MULTIDEV
+#if INCL_BLACK || INCL_SCREEN || INCL_2D
+bitmap_t bfuncs = { sp_open_bitmap, sp_set_bitmap_bits, sp_close_bitmap };
+#endif
+#if INCL_OUTLINE
+outline_t ofuncs = { sp_open_outline, sp_start_new_char, sp_start_contour, sp_curve_to,
+                     sp_line_to, sp_close_contour, sp_close_outline };
+#endif
+#endif
+
+
+ufix8   temp[16];             /* temp buffer for first 16 bytes of font */
+
+\f
+FUNCTION void main(argc,argv)
+int argc;
+char *argv[];
+{
+ufix16     bytes_read;           /* Number of bytes read from font file */
+specs_t specs;                /* Bundle of character generation specs  */
+int     first_char_index;     /* Index of first character in font */
+int     no_layout_chars;        /* number of characters in layout */
+ufix32  i;
+ufix32  minbufsz;             /* minimum font buffer size to allocate */
+ufix16 cust_no;
+ufix8  FONTFAR *byte_ptr;
+
+#if REENTRANT_ALLOC
+SPEEDO_GLOBALS* sp_global_ptr;
+#endif
+
+
+if (argc != 2) 
+    {
+    fprintf(stderr,"Usage: nsample {fontfile}\n\n"); 
+    exit (1);
+    }
+
+sprintf(pathname, argv[1]);
+
+/* Load Speedo outline file */
+fdescr = fopen (pathname, "rb");
+if (fdescr == NULL)
+    {
+    printf("****** Cannot open file %s\n", pathname);
+    return;                  
+    }
+
+/* get minimum font buffer size - read first 16 bytes to get the minimum
+   size field from the header, then allocate buffer dynamically  */
+
+bytes_read = fread(temp, sizeof(ufix8), 16, fdescr);
+
+if (bytes_read != 16)
+       {
+       printf("****** Error on reading %s: %x\n", pathname, bytes_read);
+       fclose(fdescr);
+       return;
+       }
+#if INCL_LCD
+minbufsz = (ufix32)read_4b(temp+FH_FBFSZ);
+#else
+minbufsz = (ufix32)read_4b(temp+FH_FNTSZ);
+if (minbufsz >= 0x10000)
+       {
+       printf("****** Cannot process fonts greater than 64K - use dynamic character loading configuration option\n");
+       fclose(fdescr);
+       return;
+       }
+#endif
+
+#if (defined(M_I86SM) || defined(M_I86MM))
+font_buffer = (ufix8 FONTFAR *)_fmalloc((ufix16)minbufsz);
+#else
+font_buffer = (ufix8 *)malloc((ufix16)minbufsz);
+#endif
+      
+if (font_buffer == NULL)
+       {
+       printf("****** Unable to allocate memory for font buffer\n");
+    fclose(fdescr);
+       return;
+       }
+
+#if DEBUG
+printf("Loading font file %s\n", pathname);
+#endif
+
+fseek(fdescr, (ufix32)0, 0);
+#if (defined(M_I86SM) || (defined(M_I86MM)))
+byte_ptr = font_buffer;
+for (i=0; i< minbufsz; i++){
+    int ch;
+    ch = getc(fdescr);
+    if (ch == EOF)
+       {printf ("Premature EOF in reading font buffer, %ld bytes read\n",i);
+        exit(2);}
+    *byte_ptr=(ufix8)ch;
+    byte_ptr++;
+    }
+bytes_read = i;
+#else
+bytes_read = fread((ufix8 *)font_buffer, sizeof(ufix8), (ufix16)minbufsz, fdescr);
+if (bytes_read == 0)
+    {
+    printf("****** Error on reading %s: %x\n", pathname, bytes_read);
+    fclose(fdescr);     
+    return;
+    }
+#endif
+
+#if INCL_LCD
+/* now allocate minimum character buffer */
+
+minchrsz = read_2b(font_buffer+FH_CBFSZ);
+#if (defined(M_I86SM) || (defined(M_I86MM)))
+char_buffer = (ufix8 FONTFAR *)_fmalloc(minchrsz);
+#else
+char_buffer = (ufix8*)malloc(minchrsz);
+#endif
+
+if (char_buffer == NULL)
+       {
+       printf("****** Unable to allocate memory for character buffer\n");
+    fclose(fdescr);     
+       return;
+       }
+#endif
+
+#if DYNAMIC_ALLOC || REENTRANT_ALLOC
+       sp_global_ptr = (SPEEDO_GLOBALS *)malloc(sizeof(SPEEDO_GLOBALS));
+       memset(sp_global_ptr,(ufix8)0,sizeof(SPEEDO_GLOBALS));
+#endif
+
+
+/* Initialization */
+#if REENTRANT_ALLOC
+sp_reset(sp_global_ptr);                   /* Reset Speedo character generator */
+#else
+sp_reset();                   /* Reset Speedo character generator */
+#endif
+
+font.org = font_buffer;
+font.no_bytes = bytes_read;
+
+#if REENTRANT_ALLOC
+if ((cust_no=sp_get_cust_no(sp_global_ptr,font)) != CUS0 && /* NOT STANDARD ENCRYPTION */
+#else
+if ((cust_no=sp_get_cust_no(font)) != CUS0 && /* NOT STANDARD ENCRYPTION */
+#endif
+                               cust_no != 0)
+       {
+#if REENTRANT_ALLOC
+       printf("Unable to use fonts for customer number %d\n",
+                               sp_get_cust_no(sp_global_ptr(font)));
+#else
+       printf("Unable to use fonts for customer number %d\n",
+                               sp_get_cust_no(font));
+#endif
+    fclose(fdescr);
+       return;
+       }
+
+#if INCL_KEYS
+#if REENTRANT_ALLOC
+sp_set_key(sp_global_ptr,key);              /* Set decryption key */
+#else
+sp_set_key(key);              /* Set decryption key */
+#endif
+#endif
+
+#if INCL_MULTIDEV
+#if INCL_BLACK || INCL_SCREEN || INCL_2D
+#if REENTRANT_ALLOC
+sp_set_bitmap_device(sp_global_ptr,&bfuncs,sizeof(bfuncs));              /* Set decryption key */
+#else
+sp_set_bitmap_device(&bfuncs,sizeof(bfuncs));              /* Set decryption key */
+#endif
+#endif
+#if INCL_OUTLINE
+#if REENTRANT_ALLOC
+sp_set_outline_device(sp_global_ptr,&ofuncs,sizeof(ofuncs));              /* Set decryption key */
+#else
+sp_set_outline_device(&ofuncs,sizeof(ofuncs));              /* Set decryption key */
+#endif
+#endif
+#endif
+
+first_char_index = read_2b(font_buffer + FH_FCHRF);
+no_layout_chars = read_2b(font_buffer + FH_NCHRL);
+
+/* Set specifications for character to be generated */
+specs.pfont = &font;          /* Pointer to Speedo outline structure */
+specs.xxmult = 25L << 16;     /* Coeff of X to calculate X pixels */
+specs.xymult = 0L << 16;      /* Coeff of Y to calculate X pixels */
+specs.xoffset = 0L << 16;     /* Position of X origin */
+specs.yxmult = 0L << 16;      /* Coeff of X to calculate Y pixels */
+specs.yymult = 25L << 16;     /* Coeff of Y to calculate Y pixels */
+specs.yoffset = 0L << 16;     /* Position of Y origin */
+specs.flags = 0;         /* Mode flags */
+specs.out_info = NULL;   
+
+
+#if REENTRANT_ALLOC
+if (!sp_set_specs(sp_global_ptr,&specs))    /* Set character generation specifications */
+#else
+if (!sp_set_specs(&specs))    /* Set character generation specifications */
+#endif
+    {
+    printf("****** Cannot set requested specs\n");
+    }
+else
+    {
+    for (i = 0; i < no_layout_chars; i++)   /* For each character in font */
+        {
+        char_index = i + first_char_index;
+#if REENTRANT_ALLOC
+        char_id = sp_get_char_id(sp_global_ptr,char_index);
+#else
+        char_id = sp_get_char_id(char_index);
+#endif
+               if (char_id != 0)
+                       {
+#if REENTRANT_ALLOC
+               if (!sp_make_char(sp_global_ptr,char_index))
+#else
+               if (!sp_make_char(char_index))
+#endif
+                   {
+               printf("****** Cannot generate character %d\n", char_index);
+                   }
+                       }
+        }
+    }
+
+fclose(fdescr);     
+}
+\f
+#if INCL_LCD
+#if REENTRANT_ALLOC
+FUNCTION buff_t *sp_load_char_data(sp_global_ptr, file_offset, no_bytes, cb_offset)
+SPEEDO_GLOBALS *sp_global_ptr;
+#else
+FUNCTION buff_t *sp_load_char_data(file_offset, no_bytes, cb_offset)
+#endif
+fix31    file_offset;  /* Offset in bytes from the start of the font file */
+fix15    no_bytes;     /* Number of bytes to be loaded */
+fix15    cb_offset;    /* Offset in bytes from start of char buffer */
+/*
+ * Called by Speedo character generator to request that character
+ * data be loaded from the font file into a character data buffer.
+ * The character buffer offset is zero for all characters except elements
+ * of compound characters. If a single buffer is allocated for character
+ * data, cb_offset ensures that sub-character data is loaded after the
+ * top-level compound character.
+ * Returns a pointer to a buffer descriptor.
+ */
+{
+int     bytes_read;
+
+#if DEBUG
+printf("\nCharacter data(%d, %d, %d) requested\n", file_offset, no_bytes, cb_offset);
+#endif
+if (fseek(fdescr, (long)file_offset, (int)0) != 0)
+    {
+    printf("****** Error in seeking character\n");
+    fclose(fdescr);     
+    exit(1);
+    }
+
+if ((no_bytes + cb_offset) > minchrsz)
+    {
+    printf("****** Character buffer overflow\n");
+    fclose(fdescr);     
+    exit(3);
+    }
+
+bytes_read = fread((char_buffer + cb_offset), sizeof(ufix8), no_bytes, fdescr);
+if (bytes_read != no_bytes)
+    {
+    printf("****** Error on reading character data\n");
+    fclose(fdescr);     
+    exit(2);
+    }
+
+#if DEBUG
+printf("Character data loaded\n");
+#endif
+
+char_data.org = (ufix8 FONTFAR *)char_buffer + cb_offset;
+char_data.no_bytes = no_bytes;
+return &char_data;
+}
+#endif
+
+\f
+#if REENTRANT_ALLOC
+FUNCTION void sp_report_error(sp_global_ptr,n)
+SPEEDO_GLOBALS *sp_global_ptr;
+#else
+FUNCTION void sp_report_error(n)
+#endif
+fix15 n;        /* Error identification number */
+/*
+ * Called by Speedo character generator to report an error.
+ *
+ *  Since character data not available is one of those errors
+ *  that happens many times, don't report it to user
+ */
+{
+
+switch(n)
+    {
+case 1:
+    printf("Insufficient font data loaded\n");
+    break;
+
+case 3:
+    printf("Transformation matrix out of range\n");
+    break;
+
+case 4:
+    printf("Font format error\n");
+    break;
+                 
+case 5:
+    printf("Requested specs not compatible with output module\n");
+    break;
+
+case 7:
+    printf("Intelligent transformation requested but not supported\n");
+    break;
+
+case 8:
+    printf("Unsupported output mode requested\n");
+    break;
+
+case 9:
+    printf("Extended font loaded but only compact fonts supported\n");
+    break;
+
+case 10:
+    printf("Font specs not set prior to use of font\n");
+    break;
+
+case 12:
+    break;
+
+case 13:
+    printf("Track kerning data not available()\n");
+    break;
+
+case 14:
+    printf("Pair kerning data not available()\n");
+    break;
+
+default:
+    printf("report_error(%d)\n", n);
+    break;
+    }
+}
+\f
+#if REENTRANT_ALLOC
+FUNCTION void sp_open_bitmap(sp_global_ptr, x_set_width, y_set_width, xorg, yorg, xsize, ysize)
+SPEEDO_GLOBALS *sp_global_ptr;
+#else
+FUNCTION void sp_open_bitmap(x_set_width, y_set_width, xorg, yorg, xsize, ysize)
+#endif
+fix31 x_set_width;
+fix31 y_set_width;   /* Set width vector */
+fix31 xorg;    /* Pixel boundary at left extent of bitmap character */
+fix31 yorg;    /* Pixel boundary at right extent of bitmap character */
+fix15 xsize;    /* Pixel boundary of bottom extent of bitmap character */
+fix15 ysize;    /* Pixel boundary of top extent of bitmap character */
+/* 
+ * Called by Speedo character generator to initialize a buffer prior
+ * to receiving bitmap data.
+ */
+{
+fix15 i;
+
+#if DEBUG
+printf("open_bitmap(%3.1f, %3.1f, %3.1f, %3.1f, %d, %d)\n",
+    (real)x_set_width / 65536.0, (real)y_set_width / 65536.0,
+    (real)xorg / 65536.0, (real)yorg / 65536.0, (int)xsize, (int)ysize);
+#endif
+raswid = xsize;
+rashgt = ysize;
+offhor = (fix15)(xorg >> 16);
+offver = (fix15)(yorg >> 16);
+
+if (raswid > MAX_BITS)
+    raswid = MAX_BITS;
+
+printf("\nCharacter index = %d, ID = %d\n", char_index, char_id);
+printf("set width = %3.1f, %3.1f\n", (real)x_set_width / 65536.0, (real)y_set_width / 65536.0);
+printf("X offset  = %d\n", offhor);
+printf("Y offset  = %d\n\n", offver);
+for (i = 0; i < raswid; i++)
+    {
+    line_of_bits[i << 1] = '.';
+    line_of_bits[(i << 1) + 1] = ' ';
+    }
+line_of_bits[raswid << 1] = '\0';
+y_cur = 0;
+}
+\f
+#if REENTRANT_ALLOC
+FUNCTION void sp_set_bitmap_bits (sp_global_ptr, y, xbit1, xbit2)
+SPEEDO_GLOBALS *sp_global_ptr;
+#else
+FUNCTION void sp_set_bitmap_bits (y, xbit1, xbit2)
+#endif
+  fix15     y;     /* Scan line (0 = first row above baseline) */
+  fix15     xbit1; /* Pixel boundary where run starts */
+  fix15     xbit2; /* Pixel boundary where run ends */
+
+/* 
+ * Called by Speedo character generator to write one row of pixels 
+ * into the generated bitmap character.                               
+ */
+
+{
+fix15 i;
+
+#if DEBUG
+printf("set_bitmap_bits(%d, %d, %d)\n", (int)y, (int)xbit1, (int)xbit2);
+#endif
+/* Clip runs beyond end of buffer */
+if (xbit1 > MAX_BITS)
+    xbit1 = MAX_BITS;
+
+if (xbit2 > MAX_BITS)
+    xbit2 = MAX_BITS;
+
+/* Output backlog lines if any */
+while (y_cur != y)
+    {
+    printf("    %s\n", line_of_bits);
+    for (i = 0; i < raswid; i++)
+        {
+        line_of_bits[i << 1] = '.';
+        }
+    y_cur++;
+    }
+
+/* Add bits to current line */
+for (i = xbit1; i < xbit2; i++)
+    {
+    line_of_bits[i << 1] = 'X';
+    }
+}
+\f
+#if REENTRANT_ALLOC
+FUNCTION void sp_close_bitmap(sp_global_ptr)
+SPEEDO_GLOBALS *sp_global_ptr;
+#else
+FUNCTION void sp_close_bitmap()
+#endif
+/* 
+ * Called by Speedo character generator to indicate all bitmap data
+ * has been generated.
+ */
+{
+#if DEBUG
+printf("close_bitmap()\n");
+#endif
+printf("    %s\n", line_of_bits);
+}
+\f
+#if INCL_OUTLINE
+#if REENTRANT_ALLOC
+FUNCTION void sp_open_outline(sp_global_ptr, x_set_width, y_set_width, xmin, xmax, ymin, ymax)
+SPEEDO_GLOBALS *sp_global_ptr;
+#else
+FUNCTION void sp_open_outline(x_set_width, y_set_width, xmin, xmax, ymin, ymax)
+#endif
+fix31 x_set_width;
+fix31 y_set_width;  /* Transformed escapement vector */
+fix31  xmin;                           /* Minimum X value in outline */
+fix31  xmax;                           /* Maximum X value in outline */
+fix31  ymin;                           /* Minimum Y value in outline */
+fix31  ymax;                           /* Maximum Y value in outline */
+/*
+ * Called by Speedo character generator to initialize prior to
+ * outputting scaled outline data.
+ */
+{
+printf("\nopen_outline(%3.1f, %3.1f, %3.1f, %3.1f, %3.1f, %3.1f)\n",
+    (real)x_set_width / 65536.0, (real)y_set_width / 65536.0,
+    (real)xmin / 65536.0, (real)xmax / 65536.0, (real)ymin / 65536.0, (real)ymax / 65536.0);
+}
+
+\f
+#if REENTRANT_ALLOC
+FUNCTION void sp_start_new_char(sp_global_ptr)
+SPEEDO_GLOBALS *sp_global_ptr;
+#else
+FUNCTION void sp_start_new_char()
+#endif
+/*
+ * Called by Speedo character generator to initialize prior to
+ * outputting scaled outline data for a sub-character in a compound
+ * character.
+ */
+{
+printf("start_new_char()\n");
+}
+\f
+#if REENTRANT_ALLOC
+FUNCTION void sp_start_contour(sp_global_ptr, x, y, outside)
+SPEEDO_GLOBALS *sp_global_ptr;
+#else
+FUNCTION void sp_start_contour(x, y, outside)
+#endif
+fix31    x;       /* X coordinate of start point in 1/65536 pixels */
+fix31    y;       /* Y coordinate of start point in 1/65536 pixels */
+boolean outside;  /* TRUE if curve encloses ink (Counter-clockwise) */
+/*
+ * Called by Speedo character generator at the start of each contour
+ * in the outline data of the character.
+ */
+{
+printf("start_contour(%3.1f, %3.1f, %s)\n", 
+    (real)x / 65536.0, (real)y / 65536.0, 
+    outside? "outside": "inside");
+}
+\f
+#if REENTRANT_ALLOC
+FUNCTION void sp_curve_to(sp_global_ptr, x1, y1, x2, y2, x3, y3)
+SPEEDO_GLOBALS *sp_global_ptr;
+#else
+FUNCTION void sp_curve_to(x1, y1, x2, y2, x3, y3)
+#endif
+fix31 x1;               /* X coordinate of first control point in 1/65536 pixels */
+fix31 y1;               /* Y coordinate of first control  point in 1/65536 pixels */
+fix31 x2;               /* X coordinate of second control point in 1/65536 pixels */
+fix31 y2;               /* Y coordinate of second control point in 1/65536 pixels */
+fix31 x3;               /* X coordinate of curve end point in 1/65536 pixels */
+fix31 y3;               /* Y coordinate of curve end point in 1/65536 pixels */
+/*
+ * Called by Speedo character generator onece for each curve in the
+ * scaled outline data of the character. This function is only called if curve
+ * output is enabled in the set_specs() call.
+ */
+{
+printf("curve_to(%3.1f, %3.1f, %3.1f, %3.1f, %3.1f, %3.1f)\n", 
+    (real)x1 / 65536.0, (real)y1 / 65536.0,
+    (real)x2 / 65536.0, (real)y2 / 65536.0,
+    (real)x3 / 65536.0, (real)y3 / 65536.0);
+}
+\f
+#if REENTRANT_ALLOC
+FUNCTION void sp_line_to(sp_global_ptr, x, y)
+SPEEDO_GLOBALS *sp_global_ptr;
+#else
+FUNCTION void sp_line_to(x, y)
+#endif
+fix31 x;               /* X coordinate of vector end point in 1/65536 pixels */
+fix31 y;               /* Y coordinate of vector end point in 1/65536 pixels */
+/*
+ * Called by Speedo character generator onece for each vector in the
+ * scaled outline data for the character. This include curve data that has
+ * been sub-divided into vectors if curve output has not been enabled
+ * in the set_specs() call.
+ */
+{
+printf("line_to(%3.1f, %3.1f)\n", 
+    (real)x / 65536.0, (real)y / 65536.0);
+}
+
+\f
+#if REENTRANT_ALLOC
+FUNCTION void sp_close_contour(sp_global_ptr)
+SPEEDO_GLOBALS *sp_global_ptr;
+#else
+FUNCTION void sp_close_contour()
+#endif
+/*
+ * Called by Speedo character generator at the end of each contour
+ * in the outline data of the character.
+ */
+{
+printf("close_contour()\n");
+}
+\f
+#if REENTRANT_ALLOC
+FUNCTION void sp_close_outline(sp_global_ptr)
+SPEEDO_GLOBALS *sp_global_ptr;
+#else
+FUNCTION void sp_close_outline()
+#endif
+/*
+ * Called by Speedo character generator at the end of output of the
+ * scaled outline of the character.
+ */
+{
+printf("close_outline()\n");
+}
+
+#endif
+\f
+FUNCTION fix15 read_2b(pointer)
+ufix8 FONTFAR *pointer;
+/*
+ * Reads 2-byte field from font buffer 
+ */
+{
+fix15 temp;
+
+temp = *pointer++;
+temp = (temp << 8) + *(pointer);
+return temp;
+}
+
+
+\fFUNCTION fix31 read_4b(pointer)
+ufix8 FONTFAR *pointer;
+/*
+ * Reads 4-byte field from font buffer 
+ */
+{
+fix31 temp;
+
+temp = *pointer++;
+temp = (temp << 8) + *(pointer++);
+temp = (temp << 8) + *(pointer++);
+temp = (temp << 8) + *(pointer);
+return temp;
+}
+
+
diff --git a/Xserver/lib/font/Speedo/out_bl2d.c b/Xserver/lib/font/Speedo/out_bl2d.c
new file mode 100644 (file)
index 0000000..d2a6151
--- /dev/null
@@ -0,0 +1,778 @@
+/* $XConsortium: out_bl2d.c,v 1.5 94/02/07 10:01:15 gildea Exp $ */
+
+/*
+
+Copyright 1989-1991, Bitstream Inc., Cambridge, MA.
+You are hereby granted permission under all Bitstream propriety rights to
+use, copy, modify, sublicense, sell, and redistribute the Bitstream Speedo
+software and the Bitstream Charter outline font for any purpose and without
+restrictions; provided, that this notice is left intact on all copies of such
+software or font and that Bitstream's trademark is acknowledged as shown below
+on all unmodified copies of such font.
+
+BITSTREAM CHARTER is a registered trademark of Bitstream Inc.
+
+
+BITSTREAM INC. DISCLAIMS ANY AND ALL WARRANTIES, EXPRESS OR IMPLIED, INCLUDING
+WITHOUT LIMITATION THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+PARTICULAR PURPOSE.  BITSTREAM SHALL NOT BE LIABLE FOR ANY DIRECT OR INDIRECT
+DAMAGES, INCLUDING BUT NOT LIMITED TO LOST PROFITS, LOST DATA, OR ANY OTHER
+INCIDENTAL OR CONSEQUENTIAL DAMAGES, ARISING OUT OF OR IN ANY WAY CONNECTED
+WITH THE SPEEDO SOFTWARE OR THE BITSTREAM CHARTER OUTLINE FONT.
+
+*/
+
+/*************************** O U T _ B L 2 D . C *****************************
+ *                                                                           *
+ * This is an output module for screen writer using two dimensional scanning *
+ ****************************************************************************/
+
+
+#include "spdo_prv.h"              /* General definitions for speedo */
+
+#define   CLOCKWISE  1
+#define   DEBUG      0
+#define   ABS(X)     ( (X < 0) ? -X : X)
+
+#if DEBUG
+#include <stdio.h>
+#define SHOW(X) printf("X = %d\n", X)
+#else
+#define SHOW(X)
+#endif
+
+/***** GLOBAL VARIABLES *****/
+
+/***** GLOBAL FUNCTIONS *****/
+
+/***** EXTERNAL VARIABLES *****/
+
+/***** EXTERNAL FUNCTIONS *****/
+
+/***** STATIC VARIABLES *****/
+
+/***** STATIC FUNCTIONS *****/
+
+#if INCL_2D
+#if PROTOS_AVAIL
+static void sp_draw_vector_to_2d(PROTO_DECL2 fix15 x0,fix15 y0,fix15 x1,fix15 y1,band_t GLOBALFAR *band);
+static void sp_add_intercept_2d(PROTO_DECL2 fix15 y,fix15 x);
+static void sp_proc_intercepts_2d(PROTO_DECL1);
+#else
+static void    sp_add_intercept_2d();
+static void    sp_proc_intercepts_2d();
+static void    sp_draw_vector_to_2d();
+#endif
+#endif
+
+#if INCL_2D
+FUNCTION boolean init_2d(specsarg)
+GDECL
+specs_t GLOBALFAR *specsarg;
+/*
+ * init_out_2d() is called by sp_set_specs() to initialize the output module.
+ * Returns TRUE if output module can accept requested specifications.
+ * Returns FALSE otherwise.
+ */
+{
+
+if (specsarg->flags & CURVES_OUT)
+    return FALSE;           /* Curves out, clipping not supported */
+
+#if DEBUG
+printf("INIT_OUT__2d()\n");
+#endif
+return TRUE;
+}
+#endif
+\f
+#if INCL_2D
+FUNCTION boolean begin_char_2d(Psw, Pmin, Pmax)
+GDECL
+point_t Psw;                   
+point_t Pmin;                   
+point_t Pmax;                   
+/* Called once at the start of the character generation process
+ * Initializes intercept table, either calculates pixel maxima or
+ * decides that they need to be collected
+ */
+{
+#if DEBUG
+printf("BEGIN_CHAR__2d(%3.1f, %3.1f, %3.1f, %3.1f, %3.1f, %3.1f\n", 
+                    (real)Psw.x / (real)sp_globals.onepix, (real)Psw.y / (real)sp_globals.onepix,
+                    (real)Pmin.x / (real)sp_globals.onepix, (real)Pmin.y / (real)sp_globals.onepix,
+                    (real)Pmax.x / (real)sp_globals.onepix, (real)Pmax.y / (real)sp_globals.onepix);
+#endif
+/* Convert PIX.FRAC to 16.16 form */
+sp_globals.x_scan_active = TRUE;  /* Assume x-scanning from the start */
+
+init_char_out(Psw,Pmin,Pmax);
+return TRUE;
+}
+#endif
+
+\f
+#if INCL_2D
+FUNCTION void begin_contour_2d(P1, outside)
+GDECL
+point_t P1;                   
+boolean outside;
+/* Called at the start of each contour
+ */
+{
+
+#if DEBUG
+printf("BEGIN_CONTOUR__2d(%3.4f, %3.4f, %s)\n", 
+    (real)P1.x / (real)sp_globals.onepix, 
+    (real)P1.y / (real)sp_globals.onepix, 
+    outside? "outside": "inside");
+#endif
+sp_globals.x0_spxl = P1.x;
+sp_globals.y0_spxl = P1.y;
+}
+#endif
+\f
+#if INCL_2D
+FUNCTION void line_2d(P1)
+GDECL
+point_t P1;
+/*
+ * Called for each vector in the transformed character
+ *     "draws" vector into intercept table
+ */
+{
+
+#if DEBUG
+printf("LINE_0(%3.4f, %3.4f)\n", 
+       (real)P1.x / (real)sp_globals.onepix, 
+       (real)P1.y / (real)sp_globals.onepix);
+#endif
+
+if (sp_globals.extents_running)
+    {
+    if (sp_globals.x0_spxl > sp_globals.bmap_xmax)         
+        sp_globals.bmap_xmax = sp_globals.x0_spxl;
+    if (sp_globals.x0_spxl < sp_globals.bmap_xmin)
+        sp_globals.bmap_xmin = sp_globals.x0_spxl;
+    if (sp_globals.y0_spxl > sp_globals.bmap_ymax)
+        sp_globals.bmap_ymax = sp_globals.y0_spxl;
+    if (sp_globals.y0_spxl < sp_globals.bmap_ymin)
+        sp_globals.bmap_ymin = sp_globals.y0_spxl;
+    }
+
+if (!sp_globals.intercept_oflo)
+    {
+    sp_draw_vector_to_2d(sp_globals.x0_spxl,
+                  sp_globals.y0_spxl,
+                  P1.x,
+                  P1.y,
+                  &sp_globals.y_band); /* y-scan */
+
+    if (sp_globals.x_scan_active)
+        sp_draw_vector_to_2d(sp_globals.y0_spxl,
+                      sp_globals.x0_spxl,
+                      P1.y,
+                      P1.x,
+                      &sp_globals.x_band); /* x-scan if selected */
+    }
+
+sp_globals.x0_spxl = P1.x; 
+sp_globals.y0_spxl = P1.y; /* update endpoint */
+}
+\f
+FUNCTION static void sp_draw_vector_to_2d(x0, y0, x1, y1, band)
+GDECL
+fix15 x0;                /* X coordinate */
+fix15 y0;                /* Y coordinate */
+fix15 x1;
+fix15 y1;
+band_t GLOBALFAR *band;
+{
+register fix15     how_many_y;       /* # of intercepts at y = n + 1/2  */
+register fix15     yc;               /* Current scan-line */
+         fix15     temp1;            /* various uses */
+         fix15     temp2;            /* various uses */
+register fix31     dx_dy;            /* slope of line in 16.16 form */
+register fix31     xc;               /* high-precision (16.16) x coordinate */
+         fix15     y_pxl;
+
+yc = (y0 + sp_globals.pixrnd) >> sp_globals.pixshift;      /* current scan line = end of last line */
+y_pxl = (y1 + sp_globals.pixrnd) >> sp_globals.pixshift;   /* calculate new end-scan line */
+
+if ((how_many_y = y_pxl - yc) == 0) return; /* Don't draw a null line */
+
+if (how_many_y < 0) yc--; /* Predecrment downward lines */
+
+if (yc > band->band_max) /* Is start point above band? */
+    {
+    if (y_pxl > band->band_max) return; /* line has to go down! */
+    how_many_y = y_pxl - (yc = band->band_max) - 1; /* Yes, limit it */
+    }
+
+if (yc < band->band_min)   /* Is start point below band? */
+    {
+    if (y_pxl < band->band_min) return; /* line has to go up! */
+    how_many_y = y_pxl - (yc = band->band_min);   /* Yes, limit it */
+    }
+
+xc = (fix31)(x0 + sp_globals.pixrnd) << 16; /* Original x coordinate with built in  */
+                                 /* rounding. int.16 + pixshift form */
+
+if ( (temp1 = (x1 - x0)) == 0)  /* check for vertical line */
+    {
+    dx_dy = 0L; /* Zero slope, leave xc alone */
+    goto skip_calc;
+    }
+          
+/* calculate dx_dy at 16.16 fixed point */
+
+dx_dy = ( (fix31)temp1 << 16 )/(fix31)(y1 - y0);
+
+/* We have to check for a @#$%@# possible multiply overflow  */
+/* by doing another @#$*& multiply.  In assembly language,   */
+/* the program could just check the OVerflow flag or whatever*/
+/* works on the particular processor.  This C code is meant  */
+/* to be processor independent.                              */
+
+temp1 = (yc << sp_globals.pixshift) - y0 + sp_globals.pixrnd;
+/* This sees if the sign bits start at bit 15 */
+/* if they do, no overflow has occurred       */
+
+temp2 = (fix15)(MULT16(temp1,(fix15)(dx_dy >> 16)) >> 15);
+
+if (  (temp2 != (fix15)0xFFFF) &&
+      (temp2 != 0x0000)   )
+    {  /* Overflow. Pick point closest to yc + .5 */
+    if (ABS(temp1) < ABS((yc << sp_globals.pixshift) - y1 + sp_globals.pixrnd))
+        { /* use x1 instead of x0 */
+        xc = (fix31)(x1 + sp_globals.pixrnd) << (16 - sp_globals.pixshift);
+        }
+    goto skip_calc;
+    }
+/* calculate new xc at the center of the *current* scan line */
+/* due to banding, yc may be several lines away from y0      */
+/*  xc += (yc + .5 - y0) * dx_dy */
+/* This multiply generates a subpixel delta. */
+/* So we leave it as an int.pixshift + 16 delta */
+
+xc += (fix31)temp1 * dx_dy;
+dx_dy <<= sp_globals.pixshift;
+skip_calc:
+
+yc -= band->band_array_offset; /* yc is now an offset relative to the band */
+
+if (how_many_y < 0)
+    {   /* Vector down */
+    if ((how_many_y += yc + 1) < band->band_floor) 
+        how_many_y = band->band_floor; /* can't go below floor */
+    while(yc >= how_many_y)
+        {
+        temp1 = (fix15)(xc >> 16); 
+        sp_add_intercept_2d(yc--,temp1); 
+        xc -= dx_dy;
+        }
+    }
+    else
+    {   /* Vector up */
+     /* check to see that line doesn't extend beyond top of band */
+    if ((how_many_y += yc) > band->band_ceiling) 
+        how_many_y = band->band_ceiling;
+    while(yc < how_many_y)
+        {
+        temp1 = (fix15)(xc >> 16);
+        sp_add_intercept_2d(yc++,temp1); 
+        xc += dx_dy;
+        }
+    }
+}
+
+#endif
+\f
+#if INCL_2D
+FUNCTION boolean end_char_2d()
+GDECL
+/* Called when all character data has been output
+ * Return TRUE if output process is complete
+ * Return FALSE to repeat output of the transformed data beginning
+ * with the first contour
+ */
+{
+
+fix31 xorg;
+fix31 yorg;
+#if INCL_CLIPPING
+fix31 em_max, em_min, bmap_max, bmap_min;
+#endif
+
+#if DEBUG
+printf("END_CHAR__2d()\n");
+#endif
+
+if (sp_globals.first_pass)
+    {
+    if (sp_globals.bmap_xmax >= sp_globals.bmap_xmin)
+        {
+        sp_globals.xmin = (sp_globals.bmap_xmin + sp_globals.pixrnd + 1) >> sp_globals.pixshift;
+        sp_globals.xmax = (sp_globals.bmap_xmax + sp_globals.pixrnd) >> sp_globals.pixshift;
+        }
+    else
+        {
+        sp_globals.xmin = sp_globals.xmax = 0;
+        }
+    if (sp_globals.bmap_ymax >= sp_globals.bmap_ymin)
+        {
+
+#if INCL_CLIPPING
+    switch(sp_globals.tcb0.xtype)
+       {
+       case 1: /* 180 degree rotation */
+            if (sp_globals.specs.flags & CLIP_TOP)
+               {
+               sp_globals.clip_ymin = (fix31)((fix31)EM_TOP * sp_globals.tcb0.yppo + ((1<<sp_globals.multshift)/2));
+               sp_globals.clip_ymin = sp_globals.clip_ymin >> sp_globals.multshift;
+               bmap_min = (sp_globals.bmap_ymin + sp_globals.pixrnd + 1) >> sp_globals.pixshift;
+              sp_globals.clip_ymin = -1 * sp_globals.clip_ymin;
+              if (bmap_min < sp_globals.clip_ymin)
+                   sp_globals.ymin = sp_globals.clip_ymin;
+               else
+                    sp_globals.ymin = bmap_min;
+               }
+            if (sp_globals.specs.flags & CLIP_BOTTOM)
+               {
+               sp_globals.clip_ymax = (fix31)((fix31)(-1 * EM_BOT) * sp_globals.tcb0.yppo + ((1<<sp_globals.multshift)/2));
+               sp_globals.clip_ymax = sp_globals.clip_ymax >> sp_globals.multshift;
+               bmap_max = (sp_globals.bmap_ymax + sp_globals.pixrnd) >> sp_globals.pixshift;
+              if (bmap_max < sp_globals.clip_ymax)
+                    sp_globals.ymax = bmap_max;
+               else
+                   sp_globals.ymax = sp_globals.clip_ymax;
+               }
+               sp_globals.clip_xmax =  -sp_globals.xmin;
+               sp_globals.clip_xmin = ((sp_globals.set_width.x+32768L) >> 16) -
+                                      sp_globals.xmin;
+               break;
+       case 2: /* 90 degree rotation */
+            if (sp_globals.specs.flags & CLIP_TOP)
+               {
+               sp_globals.clip_xmin = (fix31)((fix31)(-1 * EM_BOT) * sp_globals.tcb0.yppo + ((1<<sp_globals.multshift)/2));
+               sp_globals.clip_xmin = sp_globals.clip_xmin >> sp_globals.multshift;
+               sp_globals.clip_xmin = -1 * sp_globals.clip_xmin;
+               bmap_min = (sp_globals.bmap_xmin + sp_globals.pixrnd + 1) >> sp_globals.pixshift;
+              if (bmap_min > sp_globals.clip_xmin)
+                    sp_globals.clip_xmin = bmap_min;
+
+              /* normalize to x origin */
+               sp_globals.clip_xmin -= sp_globals.xmin;
+               }
+            if (sp_globals.specs.flags & CLIP_BOTTOM)
+               {
+               sp_globals.clip_xmax = (fix31)((fix31)EM_TOP * sp_globals.tcb0.yppo + ((1<<sp_globals.multshift)/2));
+               sp_globals.clip_xmax = sp_globals.clip_xmax >> sp_globals.multshift;
+               bmap_max = (sp_globals.bmap_xmax + sp_globals.pixrnd) >> sp_globals.pixshift;
+              if (bmap_max < sp_globals.clip_xmax)
+                    sp_globals.xmax = bmap_max;
+               else
+                   sp_globals.xmax = sp_globals.clip_xmax;
+              sp_globals.clip_ymax = 0;
+              if ((sp_globals.specs.flags & CLIP_TOP) && 
+                   (sp_globals.ymax > sp_globals.clip_ymax))
+                   sp_globals.ymax = sp_globals.clip_ymax;
+              sp_globals.clip_ymin = ((sp_globals.set_width.y+32768L) >> 16);
+               if ((sp_globals.specs.flags & CLIP_BOTTOM) && 
+                   (sp_globals.ymin < sp_globals.clip_ymin))
+                    sp_globals.ymin = sp_globals.clip_ymin;
+              /* normalize to x origin */
+               sp_globals.clip_xmax -= sp_globals.xmin;
+               }
+               break;
+       case 3: /* 270 degree rotation */
+            if (sp_globals.specs.flags & CLIP_TOP)
+               {
+               sp_globals.clip_xmin = (fix31)((fix31)EM_TOP * sp_globals.tcb0.yppo + ((1<<sp_globals.multshift)/2));
+               sp_globals.clip_xmin = sp_globals.clip_xmin >> sp_globals.multshift;
+              sp_globals.clip_xmin = -1 * sp_globals.clip_xmin;
+               bmap_min = (sp_globals.bmap_xmin + sp_globals.pixrnd + 1) >> sp_globals.pixshift;
+
+               /* let the minimum be the larger of these two values */
+              if (bmap_min > sp_globals.clip_xmin)
+                   sp_globals.clip_xmin = bmap_min;
+
+              /* normalize the x value to new xorgin */
+               sp_globals.clip_xmin -= sp_globals.xmin;
+               }
+            if (sp_globals.specs.flags & CLIP_BOTTOM)
+               {
+               sp_globals.clip_xmax = (fix31)((fix31)(-1 * EM_BOT) * sp_globals.tcb0.yppo + ((1<<sp_globals.multshift)/2));
+               sp_globals.clip_xmax = sp_globals.clip_xmax >> sp_globals.multshift;
+               bmap_max = (sp_globals.bmap_xmax + sp_globals.pixrnd) >> sp_globals.pixshift;
+
+              /* let the max be the lesser of these two values */
+              if (bmap_max < sp_globals.clip_xmax)
+                   {
+                   sp_globals.xmax = bmap_max; 
+                   sp_globals.clip_xmax = bmap_max;
+                   }
+               else
+                    sp_globals.xmax = sp_globals.clip_xmax;
+
+              /* normalize the x value to new x origin */
+              sp_globals.clip_xmax -= sp_globals.xmin;
+               }
+               /* compute y clip values */
+              sp_globals.clip_ymax = ((sp_globals.set_width.y+32768L) >> 16);
+              if ((sp_globals.specs.flags & CLIP_TOP) && 
+                   (sp_globals.ymax > sp_globals.clip_ymax))
+                   sp_globals.ymax = sp_globals.clip_ymax;
+              sp_globals.clip_ymin = 0;
+               if ((sp_globals.specs.flags & CLIP_BOTTOM) && 
+                   (sp_globals.ymin < sp_globals.clip_ymin))
+                    sp_globals.ymin = sp_globals.clip_ymin;
+               break;
+       default: /* this is for zero degree rotation and arbitrary rotation */
+            if (sp_globals.specs.flags & CLIP_TOP)
+               {
+              sp_globals.clip_ymax = (fix31)((fix31)EM_TOP * sp_globals.tcb0.yppo + ((1<<sp_globals.multshift)/2));
+               sp_globals.clip_ymax = sp_globals.clip_ymax >> sp_globals.multshift;
+               bmap_max = (sp_globals.bmap_ymax + sp_globals.pixrnd) >> sp_globals.pixshift;
+              if (bmap_max > sp_globals.clip_ymax)
+                    sp_globals.ymax = bmap_max;
+               else
+                   sp_globals.ymax = sp_globals.clip_ymax;
+               }
+            if (sp_globals.specs.flags & CLIP_BOTTOM)
+               {
+              sp_globals.clip_ymin = (fix31)((fix31)(-1 * EM_BOT) * sp_globals.tcb0.yppo +  ((1<<sp_globals.multshift)/2));
+               sp_globals.clip_ymin = sp_globals.clip_ymin >> sp_globals.multshift;
+              sp_globals.clip_ymin = - sp_globals.clip_ymin;
+               bmap_min = (sp_globals.bmap_ymin + sp_globals.pixrnd + 1) >> sp_globals.pixshift;
+              if (bmap_min < sp_globals.clip_ymin)
+                   sp_globals.ymin = sp_globals.clip_ymin;
+               else
+                    sp_globals.ymin = bmap_min;
+               }
+               sp_globals.clip_xmin = -sp_globals.xmin;
+               sp_globals.clip_xmax = ((sp_globals.set_width.x+32768L) >> 16) -
+                                      sp_globals.xmin;
+               break;
+       }
+if ( !(sp_globals.specs.flags & CLIP_TOP))
+#endif
+            sp_globals.ymax = (sp_globals.bmap_ymax + sp_globals.pixrnd) >> sp_globals.pixshift;
+
+#if INCL_CLIPPING
+if ( !(sp_globals.specs.flags & CLIP_BOTTOM))
+#endif
+        sp_globals.ymin = (sp_globals.bmap_ymin + sp_globals.pixrnd + 1) >> sp_globals.pixshift;
+        }
+    else
+        {
+        sp_globals.ymin = sp_globals.ymax = 0;
+        }
+
+    /* add in the rounded out part (from xform.) of the left edge */
+    if (sp_globals.tcb.xmode == 0)    /* for X pix is function of X orus only add the round */
+       xorg = (((fix31)sp_globals.xmin << 16) + (sp_globals.rnd_xmin << sp_globals.poshift));
+    else
+        if (sp_globals.tcb.xmode == 1) /* for X pix is function of -X orus only, subtr. round */
+               xorg = (((fix31)sp_globals.xmin << 16) - (sp_globals.rnd_xmin << sp_globals.poshift)) ;
+        else
+               xorg = (fix31)sp_globals.xmin << 16;   /* for other cases don't use round on x */
+           
+    if (sp_globals.tcb.ymode == 2)   /* for Y pix is function of X orus only, add round error */ 
+       yorg = (((fix31)sp_globals.ymin << 16) + (sp_globals.rnd_xmin << sp_globals.poshift));
+    else
+        if (sp_globals.tcb.ymode == 3) /* for Y pix is function of -X orus only, sub round */
+               yorg = (((fix31)sp_globals.ymin << 16) - (sp_globals.rnd_xmin << sp_globals.poshift));
+        else                          /* all other cases have no round error on yorg */
+               yorg = (fix31)sp_globals.ymin << 16;
+
+    open_bitmap(sp_globals.set_width.x, sp_globals.set_width.y, xorg, yorg,
+                                sp_globals.xmax - sp_globals.xmin, sp_globals.ymax -  sp_globals.ymin);
+    if (sp_globals.intercept_oflo)
+        {
+        sp_globals.y_band.band_min = sp_globals.ymin;
+        sp_globals.y_band.band_max = sp_globals.ymax;
+        sp_globals.x_scan_active = FALSE;
+        sp_globals.no_x_lists = 0;
+        init_intercepts_out();
+        sp_globals.first_pass = FALSE;
+        sp_globals.extents_running = FALSE;
+        return FALSE;
+        }
+    else
+        {
+        sp_proc_intercepts_2d();
+        close_bitmap();
+        return TRUE;
+        }
+    }
+else
+    {
+    if (sp_globals.intercept_oflo)
+        {
+        reduce_band_size_out();
+        init_intercepts_out();
+        return FALSE;
+        }
+    else
+        {
+        sp_proc_intercepts_2d();
+        if (next_band_out())
+            {
+            init_intercepts_out();
+            return FALSE;
+            }
+        close_bitmap();
+        return TRUE;
+        }
+    }
+}
+#endif
+\f
+#if INCL_2D
+FUNCTION static  void sp_add_intercept_2d(y, x)
+GDECL
+fix15 y;                 /* Y coordinate in relative pixel units */
+                         /* (0 is lowest sample in band) */
+fix15 x;                 /* X coordinate of intercept in subpixel units */
+
+/*  Called by line() to add an intercept to the intercept list structure
+ */
+
+{
+register fix15 from;   /* Insertion pointers for the linked list sort */
+register fix15 to;
+
+#if DEBUG
+/* Bounds checking IS done in debug mode */
+if ((y >= MAX_INTERCEPTS) || (y < 0))
+    {
+    printf("Intercept out of table!!!!! (%d)\n",y);
+    return;
+    }
+
+if (y >= sp_globals.no_y_lists)
+    {
+    printf("    Add x intercept(%2d, %f)\n", 
+        y + sp_globals.x_band.band_min - sp_globals.no_y_lists,
+        (real)x/(real)sp_globals.onepix);
+    if (y > (sp_globals.no_x_lists + sp_globals.no_y_lists))
+        {
+        printf(" Intercept too big for band!!!!!\007\n");
+        return;
+        }
+    }
+    else
+    {
+    printf("    Add y intercept(%2d, %f)\n", y + sp_globals.y_band.band_min,(real)x/(real)sp_globals.onepix);
+    }
+
+if (y < 0)       /* Y value below bottom of current band? */
+    {
+    printf(" Intecerpt less than 0!!!\007\n");
+    return;
+    }
+#endif
+
+/* Store new values */
+
+sp_intercepts.car[sp_globals.next_offset] = x;
+
+/* Find slot to insert new element (between from and to) */
+
+from = y; /* Start at list head */
+
+while( (to = sp_intercepts.cdr[from]) >= sp_globals.first_offset) /* Until to == end of list */
+    {
+    if (x <= sp_intercepts.car[to]) /* If next item is larger than or same as this one... */
+        goto insert_element; /* ... drop out and insert here */
+    from = to; /* move forward in list */
+    }
+
+insert_element: /* insert element "next_offset" between elements "from" */
+                /* and "to" */
+
+sp_intercepts.cdr[from] = sp_globals.next_offset;
+sp_intercepts.cdr[sp_globals.next_offset] = to;
+
+if (++sp_globals.next_offset >= MAX_INTERCEPTS) /* Intercept buffer full? */
+    {
+    sp_globals.intercept_oflo = TRUE;
+/* There may be a few more calls to "add_intercept" from the current line */
+/* To avoid problems, we set next_offset to a safe value. We don't care   */
+/* if the intercept table gets trashed at this point                      */
+    sp_globals.next_offset = sp_globals.first_offset;
+    }
+}
+
+#endif
+\f
+#if INCL_2D
+FUNCTION static  void sp_proc_intercepts_2d()
+GDECL
+/*  Called by sp_make_char to output accumulated intercept lists
+ *  Clips output to xmin, xmax, sp_globals.ymin, ymax boundaries
+ */
+{
+register fix15 i;
+register fix15 from, to;          /* Start and end of run in pixel units   
+                            relative to left extent of character  */
+register fix15 y;
+register fix15 scan_line;
+         fix15 local_bmap_xmin;
+         fix15 local_bmap_xmax;
+         fix15 first_y, last_y;
+         fix15 j,k;
+         fix15 xmin, xmax;
+         boolean clipleft, clipright;
+
+#if INCL_CLIPPING
+if ((sp_globals.specs.flags & CLIP_LEFT) != 0)
+    clipleft = TRUE;
+else
+    clipleft = FALSE;
+if ((sp_globals.specs.flags & CLIP_RIGHT) != 0)
+    clipright = TRUE;
+else
+    clipright = FALSE;
+if (clipleft || clipright)
+        {
+        xmax = sp_globals.clip_xmax << sp_globals.pixshift;
+        xmin = sp_globals.clip_xmin << sp_globals.pixshift;
+        }
+if (!clipright)
+        xmax = ((sp_globals.set_width.x+32768L) >> 16);
+#endif
+
+if (sp_globals.x_scan_active)      /* If xscanning, we need to make sure we don't miss any important pixels */
+    {
+    first_y = sp_globals.x_band.band_floor;        /* start of x lists */
+    last_y = sp_globals.x_band.band_ceiling;                          /* end of x lists   */
+    for (y = first_y; y != last_y; y++)             /* scan all xlists  */
+        {
+        i = sp_intercepts.cdr[y];                            /* Index head of intercept list */
+        while (i != 0)         /* Link to next intercept if present */
+            {
+            from = sp_intercepts.car[i];
+            j = i;
+            i = sp_intercepts.cdr[i];                   /* Link to next intercept */
+            if (i == 0)                   /* End of list? */
+                {
+#if DEBUG
+                printf("****** proc_intercepts: odd number of intercepts in x list\n");
+#endif
+                break;
+                }
+            to = sp_intercepts.car[i];
+            k = sp_intercepts.cdr[i];
+            if (((to >> sp_globals.pixshift) >=  (from >> sp_globals.pixshift)) &&
+                 ((to - from) < (sp_globals.onepix + 1)))
+                {
+                from = ((fix31)to + (fix31)from - (fix31)sp_globals.onepix) >> (sp_globals.pixshift + 1);
+                if (from > sp_globals.y_band.band_max) 
+                                       from = sp_globals.y_band.band_max;
+                if ((from -= sp_globals.y_band.band_min) < 0) 
+                                       from = 0;
+                to = ((y - sp_globals.x_band.band_floor + sp_globals.x_band.band_min) 
+                           << sp_globals.pixshift) 
+                           + sp_globals.pixrnd;
+                sp_intercepts.car[j] = to;
+                sp_intercepts.car[i] = to + sp_globals.onepix;
+                sp_intercepts.cdr[i] = sp_intercepts.cdr[from];
+                sp_intercepts.cdr[from] = j;
+                }
+skip_xint:  i = k;
+            }
+        }
+    }
+#if DEBUG
+printf("\nIntercept lists:\n");
+#endif
+
+if ((first_y = sp_globals.y_band.band_max) >= sp_globals.ymax)    
+    first_y = sp_globals.ymax - 1;               /* Clip to ymax boundary */
+
+if ((last_y = sp_globals.y_band.band_min) < sp_globals.ymin)      
+    last_y = sp_globals.ymin;                    /* Clip to sp_globals.ymin boundary */
+
+last_y  -= sp_globals.y_band.band_array_offset;
+
+local_bmap_xmin = sp_globals.xmin << sp_globals.pixshift;
+local_bmap_xmax = (sp_globals.xmax << sp_globals.pixshift) + sp_globals.pixrnd;
+
+#if DEBUG
+/* Print out all of the intercept info */
+scan_line = sp_globals.ymax - first_y - 1;
+
+for (y = first_y - sp_globals.y_band.band_min; y >= last_y; y--, scan_line++)
+    {
+    i = y;                            /* Index head of intercept list */
+    while ((i = sp_intercepts.cdr[i]) != 0)         /* Link to next intercept if present */
+        {
+        if ((from = sp_intercepts.car[i] - local_bmap_xmin) < 0)
+            from = 0;                 /* Clip to xmin boundary */
+        i = sp_intercepts.cdr[i];                   /* Link to next intercept */
+        if (i == 0)                   /* End of list? */
+            {
+            printf("****** proc_intercepts: odd number of intercepts\n");
+            break;
+            }
+        if ((to = sp_intercepts.car[i]) > sp_globals.bmap_xmax)
+            to = sp_globals.bmap_xmax - local_bmap_xmin;         /* Clip to xmax boundary */
+        else
+            to -= local_bmap_xmin;
+        printf("    Y = %2d (scanline %2d): %3.4f %3.4f:\n", 
+            y + sp_globals.y_band.band_min, 
+            scan_line, 
+            (real)from / (real)sp_globals.onepix, 
+            (real)to / (real)sp_globals.onepix);
+        }
+    }
+#endif
+
+/* Draw the image */
+scan_line = sp_globals.ymax - first_y - 1;
+
+for (y = first_y - sp_globals.y_band.band_min; y >= last_y; y--, scan_line++)
+    {
+    i = y;                            /* Index head of intercept list */
+    while ((i = sp_intercepts.cdr[i]) != 0)         /* Link to next intercept if present */
+        {
+        if ((from = sp_intercepts.car[i] - local_bmap_xmin) < 0)
+            from = 0;                 /* Clip to xmin boundary */
+        i = sp_intercepts.cdr[i];                   /* Link to next intercept */
+
+        if ((to = sp_intercepts.car[i]) > local_bmap_xmax)
+            to = sp_globals.bmap_xmax - local_bmap_xmin;         /* Clip to xmax boundary */
+        else
+            to -= local_bmap_xmin;
+#if INCL_CLIPPING
+                if (clipleft)
+                        {
+                        if (to <= xmin)
+                                continue;
+                        if (from < xmin)
+                                from = xmin;
+                        }
+        if (clipright)
+                        {
+                        if (from >= xmax)
+                                continue;
+                        if (to > xmax)
+                                to = xmax;
+                        }
+#endif
+        if ( (to - from) <= sp_globals.onepix)
+            {
+            from = (to + from - sp_globals.onepix) >> (sp_globals.pixshift + 1);
+            set_bitmap_bits(scan_line, from, from + 1);
+            }
+            else
+            {
+            set_bitmap_bits(scan_line, from >> sp_globals.pixshift, to >> sp_globals.pixshift);
+            }
+        }
+    }
+}
+
+#endif
diff --git a/Xserver/lib/font/Speedo/out_blk.c b/Xserver/lib/font/Speedo/out_blk.c
new file mode 100644 (file)
index 0000000..57773da
--- /dev/null
@@ -0,0 +1,710 @@
+/* $XConsortium: out_blk.c,v 1.4 94/02/07 10:01:11 gildea Exp $ */
+
+/*
+
+Copyright 1989-1991, Bitstream Inc., Cambridge, MA.
+You are hereby granted permission under all Bitstream propriety rights to
+use, copy, modify, sublicense, sell, and redistribute the Bitstream Speedo
+software and the Bitstream Charter outline font for any purpose and without
+restrictions; provided, that this notice is left intact on all copies of such
+software or font and that Bitstream's trademark is acknowledged as shown below
+on all unmodified copies of such font.
+
+BITSTREAM CHARTER is a registered trademark of Bitstream Inc.
+
+
+BITSTREAM INC. DISCLAIMS ANY AND ALL WARRANTIES, EXPRESS OR IMPLIED, INCLUDING
+WITHOUT LIMITATION THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+PARTICULAR PURPOSE.  BITSTREAM SHALL NOT BE LIABLE FOR ANY DIRECT OR INDIRECT
+DAMAGES, INCLUDING BUT NOT LIMITED TO LOST PROFITS, LOST DATA, OR ANY OTHER
+INCIDENTAL OR CONSEQUENTIAL DAMAGES, ARISING OUT OF OR IN ANY WAY CONNECTED
+WITH THE SPEEDO SOFTWARE OR THE BITSTREAM CHARTER OUTLINE FONT.
+
+*/
+
+
+
+/*************************** O U T _ B L K . C *********************************
+ *                                                                           *
+ * This is an output module for black-writer mode.                           *
+ *                                                                           *
+ *****************************************************************************/
+
+
+#include "spdo_prv.h"               /* General definitions for Speedo   */
+
+#define   DEBUG      0
+#define   LOCAL      static
+#define   ABS(X)     ( (X < 0) ? -X : X)
+
+#if DEBUG
+#include <stdio.h>
+#define SHOW(X) printf("X = %d\n", X)
+#else
+#define SHOW(X)
+#endif
+
+
+/***** GLOBAL VARIABLES *****/
+
+/***** GLOBAL FUNCTIONS *****/
+
+/***** EXTERNAL VARIABLES *****/
+
+/***** EXTERNAL FUNCTIONS *****/
+
+/***** STATIC VARIABLES *****/
+
+/***** STATIC FUNCTIONS *****/
+
+#if INCL_BLACK
+#if PROTOS_AVAIL
+static void sp_add_intercept_black(PROTO_DECL2 fix15 y, fix15 x);
+static void sp_proc_intercepts_black(PROTO_DECL1);
+#else
+static void    sp_add_intercept_black();
+static void    sp_proc_intercepts_black();
+#endif
+#endif
+
+\f
+#if INCL_BLACK
+FUNCTION boolean init_black(specsarg)
+GDECL
+specs_t GLOBALFAR *specsarg;
+/*
+ * init_out0() is called by sp_set_specs() to initialize the output module.
+ * Returns TRUE if output module can accept requested specifications.
+ * Returns FALSE otherwise.
+ */
+{
+#if DEBUG
+printf("INIT_BLK()\n");
+#endif
+if (specsarg->flags & CURVES_OUT)
+    return FALSE;           /* Curves out not supported */
+return (TRUE);
+}
+#endif
+
+
+#if INCL_BLACK
+FUNCTION boolean begin_char_black(Psw, Pmin, Pmax)
+GDECL
+point_t Psw;                   
+point_t Pmin;                   
+point_t Pmax;                   
+/* Called once at the start of the character generation process
+ */
+{
+#if DEBUG
+printf("BEGIN_CHAR_BLACK(%3.1f, %3.1f, %3.1f, %3.1f, %3.1f, %3.1f\n", 
+                    (real)Psw.x / (real)sp_globals.onepix, (real)Psw.y / (real)sp_globals.onepix,
+                    (real)Pmin.x / (real)sp_globals.onepix, (real)Pmin.y / (real)sp_globals.onepix,
+                    (real)Pmax.x / (real)sp_globals.onepix, (real)Pmax.y / (real)sp_globals.onepix);
+#endif
+init_char_out(Psw,Pmin,Pmax);
+return TRUE;
+}
+#endif
+
+\f
+#if INCL_BLACK
+FUNCTION void begin_contour_black(P1, outside)
+GDECL
+point_t P1;                   
+boolean outside;
+/* Called at the start of each contour
+ */
+{
+
+#if DEBUG
+printf("BEGIN_CONTOUR_BLACK(%3.1f, %3.1f, %s)\n", 
+    (real)P1.x / (real)sp_globals.onepix, (real)P1.y / (real)sp_globals.onepix, outside? "outside": "inside");
+#endif
+sp_globals.x0_spxl = P1.x;
+sp_globals.y0_spxl = P1.y;
+sp_globals.y_pxl = (sp_globals.y0_spxl + sp_globals.pixrnd) >> sp_globals.pixshift;
+}
+#endif
+\f
+#if INCL_BLACK
+FUNCTION void line_black(P1)
+GDECL
+point_t P1;                   
+/* Called for each vector in the transformed character
+ */
+{
+register fix15     how_many_y;       /* # of intercepts at y = n + 1/2  */
+register fix15     yc, i;            /* Current scan-line */
+         fix15     temp1;            /* various uses */
+         fix15     temp2;            /* various uses */
+register fix31     dx_dy;            /* slope of line in 16.16 form */
+register fix31     xc;               /* high-precision (16.16) x coordinate */
+         fix15     x0,y0,x1,y1;      /* PIX.FRAC start and endpoints */
+
+x0 = sp_globals.x0_spxl;                 /* get start of line (== current point) */
+y0 = sp_globals.y0_spxl;
+sp_globals.x0_spxl = x1 = P1.x; /* end of line */
+sp_globals.y0_spxl = y1 = P1.y; /*  (also update current point to end of line) */
+
+yc = sp_globals.y_pxl;                   /* current scan line = end of last line */
+sp_globals.y_pxl = (y1 + sp_globals.pixrnd) >> sp_globals.pixshift;   /* calculate new end-scan sp_globals.line */
+
+
+#if DEBUG
+printf("LINE_BLACK(%3.4f, %3.4f)\n", 
+       (real)P1.x/(real)sp_globals.onepix, 
+       (real)P1.y/(real)sp_globals.onepix);
+#endif
+
+if (sp_globals.extents_running)
+    {
+    if (sp_globals.x0_spxl > sp_globals.bmap_xmax)         
+        sp_globals.bmap_xmax = sp_globals.x0_spxl;
+    if (sp_globals.x0_spxl < sp_globals.bmap_xmin)
+        sp_globals.bmap_xmin = sp_globals.x0_spxl;
+    if (sp_globals.y0_spxl > sp_globals.bmap_ymax)
+        sp_globals.bmap_ymax = sp_globals.y0_spxl;
+    if (sp_globals.y0_spxl < sp_globals.bmap_ymin)
+        sp_globals.bmap_ymin = sp_globals.y0_spxl;
+    }
+
+if (sp_globals.intercept_oflo) return;
+
+if ((how_many_y = sp_globals.y_pxl - yc) == 0) return; /* Don't draw a null line */
+
+if (how_many_y < 0) yc--; /* Predecrment downward lines */
+
+if (yc > sp_globals.y_band.band_max) /* Is start point above band? */
+    {
+    if (sp_globals.y_pxl > sp_globals.y_band.band_max) return; /* line has to go down! */
+    how_many_y = sp_globals.y_pxl - (yc = sp_globals.y_band.band_max) - 1; /* Yes, limit it */
+    }
+
+if (yc < sp_globals.y_band.band_min)   /* Is start point below band? */
+    {
+    if (sp_globals.y_pxl < sp_globals.y_band.band_min) return; /* line has to go up! */
+    how_many_y = sp_globals.y_pxl - (yc = sp_globals.y_band.band_min);   /* Yes, limit it */
+    }
+
+xc = (fix31)(x0 + sp_globals.pixrnd) << (16 - sp_globals.pixshift); /* Original x coordinate with built in  */
+                                            /* rounding. 16.16 form */
+
+
+if ( (temp1 = (x1 - x0)) == 0)  /* check for vertical line */
+    {
+    yc -= sp_globals.y_band.band_min; /* yc is now an offset relative to the band */
+    temp1 = (fix15)(xc >> 16); 
+    if (how_many_y < 0)
+        {   /* Vector down */
+        if ((how_many_y += yc + 1) < 0) how_many_y = 0; /* can't go below 0 */
+        for (i = yc; i >= how_many_y; i--)
+            sp_add_intercept_black(i,temp1); 
+        }
+    else
+        {   /* Vector up */
+     /* check to see that line doesn't extend beyond top of band */
+        if ((how_many_y += yc) > sp_globals.no_y_lists) how_many_y = sp_globals.no_y_lists;
+        for (i = yc; i != how_many_y; i++)
+            sp_add_intercept_black(i,temp1); 
+        }
+    return;
+    }
+          
+/* calculate dx_dy at 16.16 fixed point */
+
+dx_dy = ( (fix31)temp1 << 16 )/(fix31)(y1 - y0);
+
+/* We have to check for a @#$%@# possible multiply overflow  */
+/* by doing another @#$*& multiply.  In assembly language,   */
+/* the program could just check the OVerflow flag or whatever*/
+/* works on the particular processor.  This C code is meant  */
+/* to be processor independant.                              */
+
+temp1 = (yc << sp_globals.pixshift) - y0 + sp_globals.pixrnd;
+/* This sees if the sign bits start at bit 15 */
+/* if they do, no overflow has occurred       */
+
+temp2 = (fix15)(MULT16(temp1,(fix15)(dx_dy >> 16)) >> 15);
+
+if (  (temp2 != (fix15)0xFFFF) &&
+      (temp2 != 0x0000) &&
+      /* Overflow. Pick point closest to yc + .5 */
+    (ABS(temp1) < ABS((yc << sp_globals.pixshift) - y1 + sp_globals.pixrnd)) )
+    { /* use x1 instead of x0 */
+    xc = (fix31)(x1 + sp_globals.pixrnd) << (16 - sp_globals.pixshift);
+    }
+else
+    {
+/* calculate new xc at the center of the *current* scan line */
+/* due to banding, yc may be several lines away from y0      */
+/*  xc += (yc + .5 - y0) * dx_dy */
+/* This multiply generates a subpixel delta. */
+/* So we shift it to be a 16.16 delta */
+
+    xc += ((fix31)temp1 * dx_dy) >> sp_globals.pixshift;
+    }
+
+yc -= sp_globals.y_band.band_min; /* yc is now an offset relative to the band */
+
+if (how_many_y < 0)
+    {   /* Vector down */
+    if (how_many_y == -1)
+        sp_add_intercept_black(yc, (fix15) (xc >> 16));
+    else
+        {
+        if ((how_many_y += yc + 1) < 0) how_many_y = 0; /* can't go below 0 */
+        for (i = yc; i >= how_many_y; i--)
+            {
+            temp1 = (fix15)(xc >> 16); 
+            sp_add_intercept_black(i,temp1); 
+            xc -= dx_dy;
+            }
+        }
+    }
+    else
+    {   /* Vector up */
+     /* check to see that line doesn't extend beyond top of band */
+    if (how_many_y == 1)
+        sp_add_intercept_black(yc, (fix15) (xc >> 16));
+    else
+        {
+        if ((how_many_y += yc) > sp_globals.no_y_lists) how_many_y = sp_globals.no_y_lists;
+        for (i = yc; i != how_many_y; i++)
+            {
+            temp1 = (fix15)(xc >> 16);
+            sp_add_intercept_black(i,temp1); 
+            xc += dx_dy;
+            }
+        }
+    }
+}
+#endif
+#if INCL_BLACK
+FUNCTION boolean end_char_black()
+GDECL
+/* Called when all character data has been output
+ * Return TRUE if output process is complete
+ * Return FALSE to repeat output of the transformed data beginning
+ * with the first contour
+ */
+{
+
+fix31 xorg;
+fix31 yorg;
+#if INCL_CLIPPING
+fix31 bmap_max, bmap_min;
+#endif
+
+#if DEBUG
+printf("END_CHAR_BLACK()\n");
+#endif
+
+if (sp_globals.first_pass)
+    {
+    if (sp_globals.bmap_xmax >= sp_globals.bmap_xmin)
+        {
+        sp_globals.xmin = (sp_globals.bmap_xmin + sp_globals.pixrnd + 1) >> sp_globals.pixshift;
+        sp_globals.xmax = (sp_globals.bmap_xmax + sp_globals.pixrnd) >> sp_globals.pixshift;
+        }
+    else
+        {
+        sp_globals.xmin = sp_globals.xmax = 0;
+        }
+    if (sp_globals.bmap_ymax >= sp_globals.bmap_ymin)
+        {
+
+#if INCL_CLIPPING
+    switch(sp_globals.tcb0.xtype)
+       {
+       case 1: /* 180 degree rotation */
+            if (sp_globals.specs.flags & CLIP_TOP)
+               {
+               sp_globals.clip_ymin = (fix31)((fix31)EM_TOP * sp_globals.tcb0.yppo + ((1<<sp_globals.multshift)/2));
+               sp_globals.clip_ymin = sp_globals.clip_ymin >> sp_globals.multshift;
+               bmap_min = (sp_globals.bmap_ymin + sp_globals.pixrnd + 1) >> sp_globals.pixshift;
+              sp_globals.clip_ymin = -1 * sp_globals.clip_ymin;
+              if (bmap_min < sp_globals.clip_ymin)
+                   sp_globals.ymin = sp_globals.clip_ymin;
+               else
+                    sp_globals.ymin = bmap_min;
+               }
+            if (sp_globals.specs.flags & CLIP_BOTTOM)
+               {
+               sp_globals.clip_ymax = (fix31)((fix31)(-1 * EM_BOT) * sp_globals.tcb0.yppo + ((1<<sp_globals.multshift)/2));
+               sp_globals.clip_ymax = sp_globals.clip_ymax >> sp_globals.multshift;
+               bmap_max = (sp_globals.bmap_ymax + sp_globals.pixrnd) >> sp_globals.pixshift;
+              if (bmap_max < sp_globals.clip_ymax)
+                    sp_globals.ymax = bmap_max;
+               else
+                   sp_globals.ymax = sp_globals.clip_ymax;
+               }
+               sp_globals.clip_xmax =  -sp_globals.xmin;
+               sp_globals.clip_xmin = ((sp_globals.set_width.x+32768L) >> 16) -
+                                      sp_globals.xmin;
+               break;
+       case 2: /* 90 degree rotation */
+            if (sp_globals.specs.flags & CLIP_TOP)
+               {
+               sp_globals.clip_xmin = (fix31)((fix31)(-1 * EM_BOT) * sp_globals.tcb0.yppo + ((1<<sp_globals.multshift)/2));
+               sp_globals.clip_xmin = sp_globals.clip_xmin >> sp_globals.multshift;
+               sp_globals.clip_xmin = -1 * sp_globals.clip_xmin;
+               bmap_min = (sp_globals.bmap_xmin + sp_globals.pixrnd + 1) >> sp_globals.pixshift;
+              if (bmap_min > sp_globals.clip_xmin)
+                    sp_globals.clip_xmin = bmap_min;
+
+              /* normalize to x origin */
+               sp_globals.clip_xmin -= sp_globals.xmin;
+               }
+            if (sp_globals.specs.flags & CLIP_BOTTOM)
+               {
+               sp_globals.clip_xmax = (fix31)((fix31)EM_TOP * sp_globals.tcb0.yppo + ((1<<sp_globals.multshift)/2));
+               sp_globals.clip_xmax = sp_globals.clip_xmax >> sp_globals.multshift;
+               bmap_max = (sp_globals.bmap_xmax + sp_globals.pixrnd) >> sp_globals.pixshift;
+              if (bmap_max < sp_globals.clip_xmax)
+                    sp_globals.xmax = bmap_max;
+               else
+                   sp_globals.xmax = sp_globals.clip_xmax;
+              sp_globals.clip_ymax = 0;
+              if ((sp_globals.specs.flags & CLIP_TOP) && 
+                   (sp_globals.ymax > sp_globals.clip_ymax))
+                   sp_globals.ymax = sp_globals.clip_ymax;
+              sp_globals.clip_ymin = ((sp_globals.set_width.y+32768L) >> 16);
+               if ((sp_globals.specs.flags & CLIP_BOTTOM) && 
+                   (sp_globals.ymin < sp_globals.clip_ymin))
+                    sp_globals.ymin = sp_globals.clip_ymin;
+              /* normalize to x origin */
+               sp_globals.clip_xmax -= sp_globals.xmin;
+               }
+               break;
+       case 3: /* 270 degree rotation */
+            if (sp_globals.specs.flags & CLIP_TOP)
+               {
+               sp_globals.clip_xmin = (fix31)((fix31)EM_TOP * sp_globals.tcb0.yppo + ((1<<sp_globals.multshift)/2));
+               sp_globals.clip_xmin = sp_globals.clip_xmin >> sp_globals.multshift;
+              sp_globals.clip_xmin = -1 * sp_globals.clip_xmin;
+               bmap_min = (sp_globals.bmap_xmin + sp_globals.pixrnd + 1) >> sp_globals.pixshift;
+
+               /* let the minimum be the larger of these two values */
+              if (bmap_min > sp_globals.clip_xmin)
+                   sp_globals.clip_xmin = bmap_min;
+
+              /* normalize the x value to new xorgin */
+               sp_globals.clip_xmin -= sp_globals.xmin;
+               }
+            if (sp_globals.specs.flags & CLIP_BOTTOM)
+               {
+               sp_globals.clip_xmax = (fix31)((fix31)(-1 * EM_BOT) * sp_globals.tcb0.yppo + ((1<<sp_globals.multshift)/2));
+               sp_globals.clip_xmax = sp_globals.clip_xmax >> sp_globals.multshift;
+               bmap_max = (sp_globals.bmap_xmax + sp_globals.pixrnd) >> sp_globals.pixshift;
+
+              /* let the max be the lesser of these two values */
+              if (bmap_max < sp_globals.clip_xmax)
+                   {
+                   sp_globals.xmax = bmap_max; 
+                   sp_globals.clip_xmax = bmap_max;
+                   }
+               else
+                    sp_globals.xmax = sp_globals.clip_xmax;
+
+              /* normalize the x value to new x origin */
+              sp_globals.clip_xmax -= sp_globals.xmin;
+               }
+               /* compute y clip values */
+              sp_globals.clip_ymax = ((sp_globals.set_width.y+32768L) >> 16);
+              if ((sp_globals.specs.flags & CLIP_TOP) && 
+                   (sp_globals.ymax > sp_globals.clip_ymax))
+                   sp_globals.ymax = sp_globals.clip_ymax;
+              sp_globals.clip_ymin = 0;
+               if ((sp_globals.specs.flags & CLIP_BOTTOM) && 
+                   (sp_globals.ymin < sp_globals.clip_ymin))
+                    sp_globals.ymin = sp_globals.clip_ymin;
+               break;
+       default: /* this is for zero degree rotation and arbitrary rotation */
+            if (sp_globals.specs.flags & CLIP_TOP)
+               {
+              sp_globals.clip_ymax = (fix31)((fix31)EM_TOP * sp_globals.tcb0.yppo + ((1<<sp_globals.multshift)/2));
+               sp_globals.clip_ymax = sp_globals.clip_ymax >> sp_globals.multshift;
+               bmap_max = (sp_globals.bmap_ymax + sp_globals.pixrnd) >> sp_globals.pixshift;
+              if (bmap_max > sp_globals.clip_ymax)
+                    sp_globals.ymax = bmap_max;
+               else
+                   sp_globals.ymax = sp_globals.clip_ymax;
+               }
+            if (sp_globals.specs.flags & CLIP_BOTTOM)
+               {
+              sp_globals.clip_ymin = (fix31)((fix31)(-1 * EM_BOT) * sp_globals.tcb0.yppo +  ((1<<sp_globals.multshift)/2));
+               sp_globals.clip_ymin = sp_globals.clip_ymin >> sp_globals.multshift;
+              sp_globals.clip_ymin = - sp_globals.clip_ymin;
+               bmap_min = (sp_globals.bmap_ymin + sp_globals.pixrnd + 1) >> sp_globals.pixshift;
+              if (bmap_min < sp_globals.clip_ymin)
+                   sp_globals.ymin = sp_globals.clip_ymin;
+               else
+                    sp_globals.ymin = bmap_min;
+               }
+               sp_globals.clip_xmin = -sp_globals.xmin;
+               sp_globals.clip_xmax = ((sp_globals.set_width.x+32768L) >> 16) -
+                                      sp_globals.xmin;
+               break;
+       }
+if ( !(sp_globals.specs.flags & CLIP_TOP))
+#endif
+            sp_globals.ymax = (sp_globals.bmap_ymax + sp_globals.pixrnd) >> sp_globals.pixshift;
+
+#if INCL_CLIPPING
+if ( !(sp_globals.specs.flags & CLIP_BOTTOM))
+#endif
+
+        sp_globals.ymin = (sp_globals.bmap_ymin + sp_globals.pixrnd + 1) >> sp_globals.pixshift;
+        }
+    else
+        {
+        sp_globals.ymin = sp_globals.ymax = 0;
+        }
+
+    /* add in the rounded out part (from xform.) of the left edge */
+    if (sp_globals.tcb.xmode == 0)    /* for X pix is function of X orus only add the round */
+       xorg = (((fix31)sp_globals.xmin << 16) + (sp_globals.rnd_xmin << sp_globals.poshift));
+    else
+        if (sp_globals.tcb.xmode == 1) /* for X pix is function of -X orus only, subtr. round */
+               xorg = (((fix31)sp_globals.xmin << 16) - (sp_globals.rnd_xmin << sp_globals.poshift)) ;
+        else
+               xorg = (fix31)sp_globals.xmin << 16;   /* for other cases don't use round on x */
+           
+    if (sp_globals.tcb.ymode == 2)   /* for Y pix is function of X orus only, add round error */ 
+       yorg = (((fix31)sp_globals.ymin << 16) + (sp_globals.rnd_xmin << sp_globals.poshift));
+    else
+        if (sp_globals.tcb.ymode == 3) /* for Y pix is function of -X orus only, sub round */
+               yorg = (((fix31)sp_globals.ymin << 16) - (sp_globals.rnd_xmin << sp_globals.poshift));
+        else                          /* all other cases have no round error on yorg */
+               yorg = (fix31)sp_globals.ymin << 16;
+
+    open_bitmap(sp_globals.set_width.x, sp_globals.set_width.y, xorg, yorg,
+                                sp_globals.xmax - sp_globals.xmin, sp_globals.ymax -  sp_globals.ymin);
+    if (sp_globals.intercept_oflo)
+        {
+        sp_globals.y_band.band_min = sp_globals.ymin;
+        sp_globals.y_band.band_max = sp_globals.ymax;
+        init_intercepts_out();
+        sp_globals.first_pass = FALSE;
+        sp_globals.extents_running = FALSE;
+        return FALSE;
+        }
+    else
+        {
+        sp_proc_intercepts_black();
+        close_bitmap();
+        return TRUE;
+        }
+    }
+else
+    {
+    if (sp_globals.intercept_oflo)
+        {
+        reduce_band_size_out();
+        init_intercepts_out();
+        return FALSE;
+        }
+    else
+        {
+        sp_proc_intercepts_black();
+        if (next_band_out())
+            {
+            init_intercepts_out();
+            return FALSE;
+            }
+        close_bitmap();
+        return TRUE;
+        }
+    }
+}
+#endif
+\f
+#if INCL_BLACK
+FUNCTION LOCAL  void sp_add_intercept_black(y, x)
+GDECL
+fix15 y;                 /* Y coordinate in relative pixel units */
+                         /* (0 is lowest sample in band) */
+fix15 x;                 /* X coordinate of intercept in subpixel units */
+
+/*  Called by line() to add an intercept to the intercept list structure
+ */
+
+{
+register fix15 from;   /* Insertion pointers for the linked list sort */
+register fix15 to;
+
+#if DEBUG
+printf("    Add intercept(%2d, %d)\n", y + sp_globals.y_band.band_min,x);
+
+/* Bounds checking IS done in debug mode */
+if (y < 0)       /* Y value below bottom of current band? */
+    {
+    printf(" Intecerpt less than 0!!!\007\n");
+    return;
+    }
+
+if (y > (sp_globals.no_y_lists - 1))              /* Y value above top of current band? */
+    {
+    printf(" Intercept too big for band!!!!!\007\n");
+    return;
+    }
+#endif
+
+/* Store new values */
+
+sp_intercepts.car[sp_globals.next_offset] = x;
+
+/* Find slot to insert new element (between from and to) */
+
+from = y; /* Start at list head */
+
+while( (to = sp_intercepts.cdr[from]) >= sp_globals.first_offset) /* Until to == end of list */
+    {
+    if (x <= sp_intercepts.car[to]) /* If next item is larger than or same as this one... */
+        goto insert_element; /* ... drop out and insert here */
+    from = to; /* move forward in list */
+    }
+
+insert_element: /* insert element "sp_globals.next_offset" between elements "from" */
+                /* and "to" */
+
+sp_intercepts.cdr[from] = sp_globals.next_offset;
+sp_intercepts.cdr[sp_globals.next_offset] = to;
+
+if (++sp_globals.next_offset >= MAX_INTERCEPTS) /* Intercept buffer full? */
+    {
+    sp_globals.intercept_oflo = TRUE;
+/* There may be a few more calls to "add_intercept" from the current line */
+/* To avoid problems, we set next_offset to a safe value. We don't care   */
+/* if the intercept table gets trashed at this point                      */
+    sp_globals.next_offset = sp_globals.first_offset;
+    }
+}
+
+#endif
+\f
+#if INCL_BLACK
+FUNCTION LOCAL  void sp_proc_intercepts_black()
+GDECL
+
+/*  Called by sp_make_char to output accumulated intercept lists
+ *  Clips output to sp_globals.xmin, sp_globals.xmax, sp_globals.ymin, sp_globals.ymax boundaries
+ */
+{
+register fix15 i;
+register fix15 from, to;          /* Start and end of run in pixel units   
+                            relative to left extent of character  */
+register fix15 y;
+register fix15 scan_line;
+         fix15 first_y, last_y;
+         fix15 xmin, xmax;
+         boolean clipleft, clipright;
+
+#if DEBUG
+printf("\nIntercept lists:\n");
+#endif
+
+#if INCL_CLIPPING
+if ((sp_globals.specs.flags & CLIP_LEFT) != 0)
+    clipleft = TRUE;
+else
+    clipleft = FALSE;
+if ((sp_globals.specs.flags & CLIP_RIGHT) != 0)
+    clipright = TRUE;
+else
+    clipright = FALSE;
+if (clipleft || clipright)
+       {
+       xmax = sp_globals.clip_xmax;
+       xmin = sp_globals.clip_xmin;
+       }
+if (!clipright)
+        xmax = ((sp_globals.set_width.x+32768L) >> 16);
+#endif
+
+if ((first_y = sp_globals.y_band.band_max) >= sp_globals.ymax)    
+    first_y = sp_globals.ymax - 1;               /* Clip to sp_globals.ymax boundary */
+
+if ((last_y = sp_globals.y_band.band_min) < sp_globals.ymin)      
+    last_y = sp_globals.ymin;                    /* Clip to sp_globals.ymin boundary */
+
+last_y  -= sp_globals.y_band.band_min;
+#if DEBUG
+/* Print out all of the intercept info */
+scan_line = sp_globals.ymax - first_y - 1;
+
+for (y = first_y - sp_globals.y_band.band_min; y >= last_y; y--, scan_line++)
+    {
+    i = y;                            /* Index head of intercept list */
+    while ((i = sp_intercepts.cdr[i]) != 0)         /* Link to next intercept if present */
+        {
+        if ((from = sp_intercepts.car[i] - sp_globals.xmin) < 0)
+            from = 0;                 /* Clip to sp_globals.xmin boundary */
+        i = sp_intercepts.cdr[i];                   /* Link to next intercept */
+        if (i == 0)                   /* End of list? */
+            {
+            printf("****** proc_intercepts: odd number of intercepts\n");
+            break;
+            }
+        if ((to = sp_intercepts.car[i]) > sp_globals.xmax)
+            to = sp_globals.xmax - sp_globals.xmin;         /* Clip to sp_globals.xmax boundary */
+        else
+            to -= sp_globals.xmin;
+        printf("    Y = %2d (scanline %2d): %d %d:\n", 
+            y + sp_globals.y_band.band_min, scan_line, from, to);
+        }
+    }
+#endif
+
+/* Draw the image */
+scan_line = sp_globals.ymax - first_y - 1;
+
+for (y = first_y - sp_globals.y_band.band_min; y >= last_y; y--, scan_line++)
+    {
+    i = y;                            /* Index head of intercept list */
+    while ((i = sp_intercepts.cdr[i]) != 0)         /* Link to next intercept if present */
+        {
+        if ((from = sp_intercepts.car[i] - sp_globals.xmin) < 0)
+            from = 0;                 /* Clip to sp_globals.xmin boundary */
+        i = sp_intercepts.cdr[i];                   /* Link to next intercept */
+
+        if ((to = sp_intercepts.car[i]) > sp_globals.xmax)
+            to = sp_globals.xmax - sp_globals.xmin;         /* Clip to sp_globals.xmax boundary */
+        else
+            to -= sp_globals.xmin;
+        if (from >= to)
+                       {
+                       if (from >= sp_globals.xmax - sp_globals.xmin)
+                               {
+                               --from ;
+                               }
+                       to = from+1;
+                       }
+#if INCL_CLIPPING
+               if (clipleft)
+                       {
+                       if (to <= xmin)
+                               continue;
+                       if (from < xmin)
+                               from = xmin;
+                       }
+       if (clipright)
+                       {
+                       if (from >= xmax)
+                               continue;
+                       if (to > xmax)
+                               to = xmax;
+                       }
+#endif
+        set_bitmap_bits(scan_line, from, to);
+        }
+    }
+}
+
+#endif
+
+\f
+
+
diff --git a/Xserver/lib/font/Speedo/out_outl.c b/Xserver/lib/font/Speedo/out_outl.c
new file mode 100644 (file)
index 0000000..e9ff194
--- /dev/null
@@ -0,0 +1,287 @@
+/* $XConsortium: out_outl.c,v 1.2 91/05/11 09:52:48 rws Exp $ */
+
+/*
+
+Copyright 1989-1991, Bitstream Inc., Cambridge, MA.
+You are hereby granted permission under all Bitstream propriety rights to
+use, copy, modify, sublicense, sell, and redistribute the Bitstream Speedo
+software and the Bitstream Charter outline font for any purpose and without
+restrictions; provided, that this notice is left intact on all copies of such
+software or font and that Bitstream's trademark is acknowledged as shown below
+on all unmodified copies of such font.
+
+BITSTREAM CHARTER is a registered trademark of Bitstream Inc.
+
+
+BITSTREAM INC. DISCLAIMS ANY AND ALL WARRANTIES, EXPRESS OR IMPLIED, INCLUDING
+WITHOUT LIMITATION THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+PARTICULAR PURPOSE.  BITSTREAM SHALL NOT BE LIABLE FOR ANY DIRECT OR INDIRECT
+DAMAGES, INCLUDING BUT NOT LIMITED TO LOST PROFITS, LOST DATA, OR ANY OTHER
+INCIDENTAL OR CONSEQUENTIAL DAMAGES, ARISING OUT OF OR IN ANY WAY CONNECTED
+WITH THE SPEEDO SOFTWARE OR THE BITSTREAM CHARTER OUTLINE FONT.
+
+*/
+
+
+/**************************** O U T _ 2 _ 1 . C ******************************
+ *                                                                           *
+ * This is the standard output module for vector output mode.                *
+ *                                                                           *
+ ****************************************************************************/
+
+
+#include "spdo_prv.h"               /* General definitions for Speedo     */
+
+
+#define   DEBUG      0
+
+#if DEBUG
+#include <stdio.h>
+#define SHOW(X) printf("X = %d\n", X)
+#else
+#define SHOW(X)
+#endif
+
+/* the following macro is used to limit points on the outline to the bounding box */
+
+#define RANGECHECK(value,min,max) (((value) >= (min) ? (value) : (min)) < (max) ? (value) : (max))
+/***** GLOBAL VARIABLES *****/
+
+/***** GLOBAL FUNCTIONS *****/
+
+/***** EXTERNAL VARIABLES *****/
+
+/***** EXTERNAL FUNCTIONS *****/
+
+/***** STATIC VARIABLES *****/
+
+/***** STATIC FUNCTIONS *****/
+
+\f
+#if INCL_OUTLINE
+FUNCTION boolean init_outline(specsarg)
+GDECL
+specs_t GLOBALFAR *specsarg;
+/*
+ * init_out2() is called by sp_set_specs() to initialize the output module.
+ * Returns TRUE if output module can accept requested specifications.
+ * Returns FALSE otherwise.
+ */
+{
+#if DEBUG
+printf("INIT_OUT_2()\n");
+#endif
+if (specsarg->flags & (CLIP_LEFT + CLIP_RIGHT + CLIP_TOP + CLIP_BOTTOM))
+    return FALSE;           /* Clipping not supported */
+return (TRUE); 
+}
+#endif
+\f
+#if INCL_OUTLINE
+FUNCTION boolean begin_char_outline(Psw, Pmin, Pmax)
+GDECL
+point_t Psw;       /* End of escapement vector (sub-pixels) */            
+point_t Pmin;      /* Bottom left corner of bounding box */             
+point_t Pmax;      /* Top right corner of bounding box */
+/*
+ * If two or more output modules are included in the configuration, begin_char2()
+ * is called by begin_char() to signal the start of character output data.
+ * If only one output module is included in the configuration, begin_char() is 
+ * called by make_simp_char() and make_comp_char().
+ */
+{
+fix31 set_width_x;
+fix31 set_width_y;
+fix31  xmin;
+fix31  xmax;
+fix31  ymin;
+fix31  ymax;
+
+#if DEBUG
+printf("BEGIN_CHAR_2(%3.1f, %3.1f, %3.1f, %3.1f, %3.1f, %3.1f\n", 
+                    (real)Psw.x / (real)onepix, (real)Psw.y / (real)onepix,
+                    (real)Pmin.x / (real)onepix, (real)Pmin.y / (real)onepix,
+                    (real)Pmax.x / (real)onepix, (real)Pmax.y / (real)onepix);
+#endif
+sp_globals.poshift = 16 - sp_globals.pixshift;
+set_width_x = (fix31)Psw.x << sp_globals.poshift;
+set_width_y = (fix31)Psw.y << sp_globals.poshift;
+xmin = (fix31)Pmin.x << sp_globals.poshift;
+xmax = (fix31)Pmax.x << sp_globals.poshift;
+ymin = (fix31)Pmin.y << sp_globals.poshift;
+ymax = (fix31)Pmax.y << sp_globals.poshift;
+sp_globals.xmin = Pmin.x;
+sp_globals.xmax = Pmax.x;
+sp_globals.ymin = Pmin.y;
+sp_globals.ymax = Pmax.y;
+open_outline(set_width_x, set_width_y, xmin, xmax, ymin, ymax);
+return TRUE;
+}
+#endif
+\f
+#if INCL_OUTLINE
+FUNCTION void begin_sub_char_outline(Psw, Pmin, Pmax)
+GDECL
+point_t Psw;       /* End of sub-char escapement vector */            
+point_t Pmin;      /* Bottom left corner of sub-char bounding box */             
+point_t Pmax;      /* Top right corner of sub-char bounding box */
+/*
+ * If two or more output modules are included in the configuration, begin_sub_char2()
+ * is called by begin_sub_char() to signal the start of sub-character output data.
+ * If only one output module is included in the configuration, begin_sub_char() is 
+ * called by make_comp_char().
+ */
+{
+#if DEBUG
+printf("BEGIN_SUB_CHAR_2(%3.1f, %3.1f, %3.1f, %3.1f, %3.1f, %3.1f\n", 
+                    (real)Psw.x / (real)onepix, (real)Psw.y / (real)onepix,
+                    (real)Pmin.x / (real)onepix, (real)Pmin.y / (real)onepix,
+                    (real)Pmax.x / (real)onepix, (real)Pmax.y / (real)onepix);
+#endif
+start_new_char();
+}
+#endif
+
+\f
+#if INCL_OUTLINE
+FUNCTION void begin_contour_outline(P1, outside)
+GDECL
+point_t P1;       /* Start point of contour */            
+boolean outside;  /* TRUE if outside (counter-clockwise) contour */
+/*
+ * If two or more output modules are included in the configuration, begin_contour2()
+ * is called by begin_contour() to define the start point of a new contour
+ * and to indicate whether it is an outside (counter-clockwise) contour
+ * or an inside (clockwise) contour.
+ * If only one output module is included in the configuration, begin_sub_char() is 
+ * called by proc_outl_data().
+ */
+{
+fix15 x,y;
+#if DEBUG
+printf("BEGIN_CONTOUR_2(%3.1f, %3.1f, %s)\n", 
+    (real)P1.x / (real)onepix, (real)P1.y / (real)onepix, outside? "outside": "inside");
+#endif
+x = RANGECHECK(P1.x,sp_globals.xmin,sp_globals.xmax);
+y = RANGECHECK(P1.y,sp_globals.ymin,sp_globals.ymax);
+
+start_contour((fix31)x << sp_globals.poshift, (fix31)y << sp_globals.poshift, outside);
+}
+#endif
+\f
+#if INCL_OUTLINE
+FUNCTION void curve_outline(P1, P2, P3,depth)
+GDECL
+point_t P1;      /* First control point of Bezier curve */
+point_t P2;      /* Second control point of Bezier curve */
+point_t P3;      /* End point of Bezier curve */
+fix15 depth;
+/*
+ * If two or more output modules are included in the configuration, curve2()
+ * is called by curve() to output one curve segment.
+ * If only one output module is included in the configuration, curve() is 
+ * called by proc_outl_data().
+ * This function is only called when curve output is enabled.
+ */
+{
+fix15 x1,y1,x2,y2,x3,y3;
+#if DEBUG
+printf("CURVE_2(%3.1f, %3.1f, %3.1f, %3.1f, %3.1f, %3.1f)\n", 
+    (real)P1.x / (real)onepix, (real)P1.y / (real)onepix,
+    (real)P2.x / (real)onepix, (real)P2.y / (real)onepix,
+    (real)P3.x / (real)onepix, (real)P3.y / (real)onepix);
+#endif
+x1= RANGECHECK(P1.x,sp_globals.xmin,sp_globals.xmax);
+y1= RANGECHECK(P1.y,sp_globals.ymin,sp_globals.ymax);
+
+x2= RANGECHECK(P2.x,sp_globals.xmin,sp_globals.xmax);
+y2= RANGECHECK(P2.y,sp_globals.ymin,sp_globals.ymax);
+
+x3= RANGECHECK(P3.x,sp_globals.xmin,sp_globals.xmax);
+y3= RANGECHECK(P3.y,sp_globals.ymin,sp_globals.ymax);
+
+curve_to((fix31)x1 << sp_globals.poshift, (fix31)y1 << sp_globals.poshift,
+         (fix31)x2<< sp_globals.poshift, (fix31)y2 << sp_globals.poshift,
+         (fix31)x3 << sp_globals.poshift, (fix31)y3 << sp_globals.poshift);
+}
+#endif
+\f
+#if INCL_OUTLINE
+FUNCTION void line_outline(P1)
+GDECL
+point_t P1;      /* End point of vector */             
+/*
+ * If two or more output modules are included in the configuration, line2()
+ * is called by line() to output one vector.
+ * If only one output module is included in the configuration, line() is 
+ * called by proc_outl_data(). If curve output is enabled, line() is also
+ * called by split_curve().
+ */
+{
+fix15 x1,y1;
+#if DEBUG
+printf("LINE_2(%3.1f, %3.1f)\n", (real)P1.x / (real)onepix, (real)P1.y / (real)onepix);
+#endif
+x1= RANGECHECK(P1.x,sp_globals.xmin,sp_globals.xmax);
+y1= RANGECHECK(P1.y,sp_globals.ymin,sp_globals.ymax);
+
+line_to((fix31)x1 << sp_globals.poshift, (fix31)y1 << sp_globals.poshift);
+}
+#endif
+\f
+#if INCL_OUTLINE
+FUNCTION void end_contour_outline()
+GDECL
+/*
+ * If two or more output modules are included in the configuration, end_contour2()
+ * is called by end_contour() to signal the end of a contour.
+ * If only one output module is included in the configuration, end_contour() is 
+ * called by proc_outl_data().
+ */
+{
+#if DEBUG
+printf("END_CONTOUR_2()\n");
+#endif
+close_contour();
+}
+#endif
+
+\f
+#if INCL_OUTLINE
+FUNCTION void end_sub_char_outline()
+GDECL
+/*
+ * If two or more output modules are included in the configuration, end_sub_char2()
+ * is called by end_sub_char() to signal the end of sub-character data.
+ * If only one output module is included in the configuration, end_sub_char() is 
+ * called by make_comp_char().
+ */
+{
+#if DEBUG
+printf("END_SUB_CHAR_2()\n");
+#endif
+}
+#endif
+
+\f
+#if INCL_OUTLINE
+FUNCTION boolean end_char_outline()
+GDECL
+/*
+ * If two or more output modules are included in the configuration, end_char2()
+ * is called by end_char() to signal the end of the character data.
+ * If only one output module is included in the configuration, end_char() is 
+ * called by make_simp_char() and make_comp_char().
+ * Returns TRUE if output process is complete
+ * Returns FALSE to repeat output of the transformed data beginning
+ * with the first contour (of the first sub-char if compound).
+ */
+{
+#if DEBUG
+printf("END_CHAR_2()\n");
+#endif
+close_outline();
+return TRUE;
+}
+#endif
+
diff --git a/Xserver/lib/font/Speedo/out_scrn.c b/Xserver/lib/font/Speedo/out_scrn.c
new file mode 100644 (file)
index 0000000..c879dae
--- /dev/null
@@ -0,0 +1,1093 @@
+/* $XConsortium: out_scrn.c,v 1.5 94/02/10 14:15:39 gildea Exp $ */
+
+/*
+
+Copyright 1989-1991, Bitstream Inc., Cambridge, MA.
+You are hereby granted permission under all Bitstream propriety rights to
+use, copy, modify, sublicense, sell, and redistribute the Bitstream Speedo
+software and the Bitstream Charter outline font for any purpose and without
+restrictions; provided, that this notice is left intact on all copies of such
+software or font and that Bitstream's trademark is acknowledged as shown below
+on all unmodified copies of such font.
+
+BITSTREAM CHARTER is a registered trademark of Bitstream Inc.
+
+
+BITSTREAM INC. DISCLAIMS ANY AND ALL WARRANTIES, EXPRESS OR IMPLIED, INCLUDING
+WITHOUT LIMITATION THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+PARTICULAR PURPOSE.  BITSTREAM SHALL NOT BE LIABLE FOR ANY DIRECT OR INDIRECT
+DAMAGES, INCLUDING BUT NOT LIMITED TO LOST PROFITS, LOST DATA, OR ANY OTHER
+INCIDENTAL OR CONSEQUENTIAL DAMAGES, ARISING OUT OF OR IN ANY WAY CONNECTED
+WITH THE SPEEDO SOFTWARE OR THE BITSTREAM CHARTER OUTLINE FONT.
+
+*/
+
+
+/*************************** O U T _ S C R N . C *****************************
+ *                                                                           *
+ * This is an output module for screen-writer mode.                          *
+ *                                                                           *
+ *****************************************************************************/
+
+
+#include "spdo_prv.h"               /* General definitions for Speedo   */
+
+#define   DEBUG      0
+#define   LOCAL      static
+#define   ABS(X)     ( (X < 0) ? -X : X)
+
+#if DEBUG
+#include <stdio.h>
+#define SHOW(X) printf("X = %d\n", X)
+#else
+#define SHOW(X)
+#endif
+
+
+/***** GLOBAL VARIABLES *****/
+
+/***** GLOBAL FUNCTIONS *****/
+
+/***** EXTERNAL VARIABLES *****/
+
+/***** EXTERNAL FUNCTIONS *****/
+
+/***** STATIC VARIABLES *****/
+
+/***** STATIC FUNCTIONS *****/
+
+#if PROTOS_AVAIL
+static void sp_add_intercept_screen(PROTO_DECL2 fix15 y,fix31 x);
+static void sp_proc_intercepts_screen(PROTO_DECL1);
+#else
+static void    sp_add_intercept_screen();
+static void    sp_proc_intercepts_screen();
+#endif
+
+\f
+#if INCL_SCREEN
+FUNCTION boolean init_screen(specsarg)
+GDECL
+specs_t FONTFAR *specsarg;
+/*
+ * init_out0() is called by sp_set_specs() to initialize the output module.
+ * Returns TRUE if output module can accept requested specifications.
+ * Returns FALSE otherwise.
+ */
+{
+#if DEBUG
+printf("INIT_SCREEN()\n");
+#endif
+return (TRUE);
+}
+#endif
+
+
+#if INCL_SCREEN
+FUNCTION boolean begin_char_screen(Psw, Pmin, Pmax)
+GDECL
+point_t Psw;                   
+point_t Pmin;                   
+point_t Pmax;                   
+/* Called once at the start of the character generation process
+ */
+{
+#if DEBUG
+printf("BEGIN_CHAR_SCREEN(%3.1f, %3.1f, %3.1f, %3.1f, %3.1f, %3.1f\n", 
+                    (real)Psw.x / (real)sp_globals.onepix, (real)Psw.y / (real)sp_globals.onepix,
+                    (real)Pmin.x / (real)sp_globals.onepix, (real)Pmin.y / (real)sp_globals.onepix,
+                    (real)Pmax.x / (real)sp_globals.onepix, (real)Pmax.y / (real)sp_globals.onepix);
+#endif
+if (sp_globals.pixshift > 8)
+       sp_intercepts.fracpix = sp_globals.onepix << (8 - sp_globals.pixshift);
+else
+       sp_intercepts.fracpix = sp_globals.onepix >> (sp_globals.pixshift - 8);
+
+init_char_out(Psw,Pmin,Pmax);
+
+return TRUE;
+}
+#endif
+
+\f
+#if INCL_SCREEN
+FUNCTION void begin_contour_screen(P1, outside)
+GDECL
+point_t P1;                   
+boolean outside;
+/* Called at the start of each contour
+ */
+{
+
+#if DEBUG
+printf("BEGIN_CONTOUR_SCREEN(%3.1f, %3.1f, %s)\n", 
+    (real)P1.x / (real)sp_globals.onepix, (real)P1.y / (real)sp_globals.onepix, outside? "outside": "inside");
+#endif
+sp_globals.x0_spxl = P1.x;
+sp_globals.y0_spxl = P1.y;
+sp_globals.y_pxl = (sp_globals.y0_spxl + sp_globals.pixrnd) >> sp_globals.pixshift;
+}
+#endif
+\f
+#if INCL_SCREEN
+FUNCTION void curve_screen(P1, P2, P3, depth)
+GDECL
+point_t P1, P2, P3;
+fix15 depth;
+{
+fix31   X0;
+fix31   Y0;
+fix31   X1;
+fix31   Y1;
+fix31   X2;
+fix31   Y2;
+fix31   X3;
+fix31   Y3;
+#if DEBUG
+printf("CURVE_SCREEN(%6.4f, %6.4f, %6.4f, %6.4f, %6.4f, %6.4f)\n", 
+    (real)P1.x / (real)sp_globals.onepix, (real)P1.y / (real)sp_globals.onepix,
+    (real)P2.x / (real)sp_globals.onepix, (real)P2.y / (real)sp_globals.onepix,
+    (real)P3.x / (real)sp_globals.onepix, (real)P3.y / (real)sp_globals.onepix);
+#endif
+
+
+if (sp_globals.extents_running) /* Accumulate actual character extents if required */
+    {
+    if (P3.x > sp_globals.bmap_xmax)         
+        sp_globals.bmap_xmax = P3.x;
+    if (P3.x < sp_globals.bmap_xmin)
+        sp_globals.bmap_xmin = P3.x;
+    if (P3.y > sp_globals.bmap_ymax)
+        sp_globals.bmap_ymax = P3.y;
+    if (P3.y < sp_globals.bmap_ymin)
+        sp_globals.bmap_ymin = P3.y;
+    }
+
+X0 = ((fix31)sp_globals.x0_spxl << sp_globals.poshift) + (fix31)32768;
+Y0 = ((fix31)sp_globals.y0_spxl << sp_globals.poshift) + (fix31)32768;
+X1 = ((fix31)P1.x << sp_globals.poshift) + (fix31)32768;
+Y1 = ((fix31)P1.y << sp_globals.poshift) + (fix31)32768;
+X2 = ((fix31)P2.x << sp_globals.poshift) + (fix31)32768;
+Y2 = ((fix31)P2.y << sp_globals.poshift) + (fix31)32768;
+X3 = ((fix31)P3.x << sp_globals.poshift) + (fix31)32768;
+Y3 = ((fix31)P3.y << sp_globals.poshift) + (fix31)32768;
+
+if (((Y0 - Y3) * sp_globals.tcb.mirror) > 0)
+       {
+       sp_intercepts.leftedge = LEFT_INT;
+       }
+else
+       {
+       sp_intercepts.leftedge = 0;
+       }
+
+scan_curve_screen(X0,Y0,X1,Y1,X2,Y2,X3,Y3);
+sp_globals.x0_spxl = P3.x;
+sp_globals.y0_spxl = P3.y;
+sp_globals.y_pxl = (P3.y + sp_globals.pixrnd) >> sp_globals.pixshift;   /* calculate new end-scan sp_globals.line */
+}
+
+FUNCTION void scan_curve_screen(X0,Y0,X1,Y1,X2,Y2,X3,Y3)\f
+GDECL
+fix31 X0,Y0,X1,Y1,X2,Y2,X3,Y3;
+/* Called for each curve in the transformed character if curves out enabled
+ */
+{
+fix31 Pmidx;
+fix31 Pmidy;
+fix31 Pctrl1x;
+fix31 Pctrl1y;
+fix31 Pctrl2x;
+fix31 Pctrl2y;
+
+#if DBGCRV
+printf("SCAN_CURVE_SCREEN(%6.4f, %6.4f, %6.4f, %6.4f, %6.4f, %6.4f, %6.4f, %6.4f)\n", 
+    (real)(X0-32768) / 65536.0, (real)(Y0-32768) / 65536.0,
+    (real)(X1-32768) / 65536.0, (real)(Y1-32768) / 65536.0,
+    (real)(X2-32768) / 65536.0, (real)(Y2-32768) / 65536.0,
+    (real)(X3-32768) / 65536.0, (real)(Y3-32768) / 65536.0);
+#endif
+
+if (((Y3 >> 16)) == (Y0 >> 16) || (Y3+1) == Y0 || Y3 == (Y0+1))
+    {
+       return;
+    }
+if ((X3 >> 16) == (X0 >> 16))
+    {
+    vert_line_screen(X3,(Y0>>16),(Y3>>16));
+       return;
+    }
+Pmidx = (X0 + (X1 + X2) * 3 + X3 + 4 ) >> 3;
+Pmidy = (Y0 + (Y1 + Y2) * 3 + Y3 + 4 ) >> 3;
+
+Pctrl1x = (X0 + X1 + 1 ) >> 1;
+Pctrl1y = (Y0 + Y1 + 1) >> 1;
+Pctrl2x = (X0 + (X1 << 1) + X2 + 2 ) >> 2;
+Pctrl2y = (Y0 + (Y1 << 1) + Y2 + 2 ) >> 2;
+scan_curve_screen(X0,Y0, Pctrl1x, Pctrl1y, Pctrl2x,Pctrl2y, Pmidx,Pmidy);
+
+Pctrl1x = (X1 + (X2 << 1) + X3 + 2 ) >> 2;
+Pctrl1y = (Y1 + (Y2 << 1) + Y3 + 2 ) >> 2;
+Pctrl2x = (X2 + X3 + 1 ) >> 1;
+Pctrl2y = (Y2 + Y3 + 1 ) >> 1;
+scan_curve_screen(Pmidx,Pmidy, Pctrl1x,Pctrl1y, Pctrl2x,Pctrl2y, X3,Y3);
+}             
+\f
+FUNCTION void vert_line_screen(x,y1,y2)
+GDECL
+fix31 x;
+fix15 y1, y2;
+{                                                 
+
+#if DBGCRV
+printf("VERT_LINE_SCREEN(%6.4f, %6.4f, %6.4f)\n",
+    (real)(x - 32768) / 65536.0, 
+    (real)(y1 - 32768) / 65536.0,
+    (real)(y2 - 32768) / 65536.0);
+#endif
+
+if (sp_globals.intercept_oflo) 
+    return;
+
+if (y1 > y2)                                   /* Line goes downwards ? */
+       {
+    if (y1 > (sp_globals.y_band.band_max + 1)) /* Start point above top of band? */
+        y1 = sp_globals.y_band.band_max + 1;   /* Adjust start point to top of band */
+    if (y2 < sp_globals.y_band.band_min)       /* End point below bottom of band? */
+        y2 = sp_globals.y_band.band_min;       /* Adjust end point bottom of band */
+
+       y1 -= sp_globals.y_band.band_min;          /* Translate start point to band origin */
+       y2 -= sp_globals.y_band.band_min;          /* Translate end point to band origin */
+
+       while (y2 < y1)                            /* At least one intercept left? */
+               {
+               sp_add_intercept_screen(--y1, x);           /* Add intercept */
+               }
+       }
+else if (y2 > y1)                              /* Line goes upwards ? */
+       {
+    if (y1 < sp_globals.y_band.band_min)       /* Start point below bottom of band? */
+        y1 = sp_globals.y_band.band_min;       /* Adjust start point to bottom of band */
+    if (y2 > (sp_globals.y_band.band_max + 1)) /* End point above top of band? */
+        y2 = sp_globals.y_band.band_max + 1;   /* Adjust end point to top of band */
+
+       y1 -= sp_globals.y_band.band_min;          /* Translate start point to band origin */
+       y2 -= sp_globals.y_band.band_min;          /* Translate end point to band origin */
+
+       while (y1 < y2)                            /* At least one intercept left? */
+               {
+               sp_add_intercept_screen(y1++, x);           /* Add intercept */
+               }
+       }
+
+
+}
+       
+#endif
+\f
+
+#if INCL_SCREEN
+FUNCTION void line_screen(P1)
+GDECL
+point_t P1;                   
+/* Called for each vector in the transformed character
+ */
+{
+register fix15     how_many_y;       /* # of intercepts at y = n + 1/2  */
+register fix15     yc;               /* Current scan-line */
+         fix15     temp1;            /* various uses */
+         fix15     temp2;            /* various uses */
+register fix31     dx_dy;            /* slope of line in 16.16 form */
+register fix31     xc;               /* high-precision (16.16) x coordinate */
+         fix15     x0,y0,x1,y1;      /* PIX.FRAC start and endpoints */
+
+x0 = sp_globals.x0_spxl;                 /* get start of line (== current point) */
+y0 = sp_globals.y0_spxl;
+sp_globals.x0_spxl = x1 = P1.x; /* end of line */
+sp_globals.y0_spxl = y1 = P1.y; /*  (also update current point to end of line) */
+
+yc = sp_globals.y_pxl;                   /* current scan line = end of last line */
+sp_globals.y_pxl = (y1 + sp_globals.pixrnd) >> sp_globals.pixshift;   /* calculate new end-scan sp_globals.line */
+
+
+#if DEBUG
+printf("LINE_SCREEN(%3.4f, %3.4f)\n", 
+       (real)P1.x/(real)sp_globals.onepix, 
+       (real)P1.y/(real)sp_globals.onepix);
+#endif
+
+if (sp_globals.extents_running)
+    {
+    if (sp_globals.x0_spxl > sp_globals.bmap_xmax)         
+        sp_globals.bmap_xmax = sp_globals.x0_spxl;
+    if (sp_globals.x0_spxl < sp_globals.bmap_xmin)
+        sp_globals.bmap_xmin = sp_globals.x0_spxl;
+    if (sp_globals.y0_spxl > sp_globals.bmap_ymax)
+        sp_globals.bmap_ymax = sp_globals.y0_spxl;
+    if (sp_globals.y0_spxl < sp_globals.bmap_ymin)
+        sp_globals.bmap_ymin = sp_globals.y0_spxl;
+    }
+
+if (sp_globals.intercept_oflo) return;
+
+if ((how_many_y = sp_globals.y_pxl - yc) == 0) return; /* Don't draw a null line */
+
+xc = (fix31)(x0 + sp_globals.pixrnd) << (16 - sp_globals.pixshift); /* Original x coordinate with built in  */
+                                            /* rounding. 16.16 form */
+
+if (how_many_y < 0)
+       {
+       yc--; /* Predecrment downward lines */
+       }
+
+if ((how_many_y * sp_globals.tcb.mirror) < 0)
+       {
+       sp_intercepts.leftedge = LEFT_INT;
+       }
+else
+       {
+       sp_intercepts.leftedge = 0;
+       }
+
+if (yc > sp_globals.y_band.band_max) /* Is start point above band? */
+    {
+    if (sp_globals.y_pxl > sp_globals.y_band.band_max) return; /* line has to go down! */
+    how_many_y = sp_globals.y_pxl - (yc = sp_globals.y_band.band_max) - 1; /* Yes, limit it */
+    }
+
+if (yc < sp_globals.y_band.band_min)   /* Is start point below band? */
+    {
+    if (sp_globals.y_pxl < sp_globals.y_band.band_min) return; /* line has to go up! */
+    how_many_y = sp_globals.y_pxl - (yc = sp_globals.y_band.band_min);   /* Yes, limit it */
+    }
+
+if ( (temp1 = (x1 - x0)) == 0)  /* check for vertical line */
+    {
+    dx_dy = 0L; /* Zero slope, leave xc alone */
+    goto skip_calc;
+    }
+          
+/* calculate dx_dy at 16.16 fixed point */
+
+dx_dy = ( (fix31)temp1 << 16 )/(fix31)(y1 - y0);
+
+/* We have to check for a @#$%@# possible multiply overflow  */
+/* by doing another @#$*& multiply.  In assembly language,   */
+/* the program could just check the OVerflow flag or whatever*/
+/* works on the particular processor.  This C code is meant  */
+/* to be processor independant.                              */
+
+temp1 = (yc << sp_globals.pixshift) - y0 + sp_globals.pixrnd;
+/* This sees if the sign bits start at bit 15 */
+/* if they do, no overflow has occurred       */
+
+temp2 = (fix15)(MULT16(temp1,(fix15)(dx_dy >> 16)) >> 15);
+
+if (  (temp2 != (fix15)-1) &&
+      (temp2 != 0x0000)   )
+    {  /* Overflow. Pick point closest to yc + .5 */
+    if (ABS(temp1) < ABS((yc << sp_globals.pixshift) - y1 + sp_globals.pixrnd))
+        { /* use x1 instead of x0 */
+        xc = (fix31)(x1 + sp_globals.pixrnd) << (16 - sp_globals.pixshift);
+        }
+    goto skip_calc;
+    }
+/* calculate new xc at the center of the *current* scan line */
+/* due to banding, yc may be several lines away from y0      */
+/*  xc += (yc + .5 - y0) * dx_dy */
+/* This multiply generates a subpixel delta. */
+/* So we shift it to be a 16.16 delta */
+
+xc += ((fix31)temp1 * dx_dy) >> sp_globals.pixshift;
+
+skip_calc:
+
+yc -= sp_globals.y_band.band_min; /* yc is now an offset relative to the band */
+
+if (how_many_y < 0)
+    {   /* Vector down */
+    if ((how_many_y += yc + 1) < 0) how_many_y = 0; /* can't go below 0 */
+    while(yc >= how_many_y)
+        {
+        sp_add_intercept_screen(yc--,xc); 
+        xc -= dx_dy;
+        }
+    }
+    else
+    {   /* Vector up */
+     /* check to see that line doesn't extend beyond top of band */
+    if ((how_many_y += yc) > sp_globals.no_y_lists) how_many_y = sp_globals.no_y_lists;
+    while(yc != how_many_y)
+        {
+        sp_add_intercept_screen(yc++,xc); 
+        xc += dx_dy;
+        }
+    }
+}
+#endif
+\f
+#if INCL_SCREEN
+FUNCTION void end_contour_screen()
+GDECL
+/* Called after the last vector in each contour
+ */
+{
+#if DEBUG
+printf("END_CONTOUR_SCREEN()\n");
+#endif
+sp_intercepts.inttype[sp_globals.next_offset-1] |= END_INT;
+}
+#endif
+
+
+\f
+#if INCL_SCREEN
+FUNCTION boolean end_char_screen()
+GDECL
+/* Called when all character data has been output
+ * Return TRUE if output process is complete
+ * Return FALSE to repeat output of the transformed data beginning
+ * with the first contour
+ */
+{
+
+fix31 xorg;
+fix31 yorg;
+
+#if INCL_CLIPPING
+fix31 em_max, em_min, bmap_max, bmap_min;
+#endif
+
+#if DEBUG
+printf("END_CHAR_SCREEN()\n");
+#endif
+
+if (sp_globals.first_pass)
+    {
+    if (sp_globals.bmap_xmax >= sp_globals.bmap_xmin)
+        {
+        sp_globals.xmin = (sp_globals.bmap_xmin + sp_globals.pixrnd + 1) >> sp_globals.pixshift;
+        sp_globals.xmax = (sp_globals.bmap_xmax + sp_globals.pixrnd) >> sp_globals.pixshift;
+        }
+    else
+        {
+        sp_globals.xmin = sp_globals.xmax = 0;
+        }
+    if (sp_globals.bmap_ymax >= sp_globals.bmap_ymin)
+        {
+
+#if INCL_CLIPPING
+    switch(sp_globals.tcb0.xtype)
+       {
+       case 1: /* 180 degree rotation */
+            if (sp_globals.specs.flags & CLIP_TOP)
+               {
+               sp_globals.clip_ymin = (fix31)((fix31)EM_TOP * sp_globals.tcb0.yppo + ((1<<sp_globals.multshift)/2));
+               sp_globals.clip_ymin = sp_globals.clip_ymin >> sp_globals.multshift;
+               bmap_min = (sp_globals.bmap_ymin + sp_globals.pixrnd + 1) >> sp_globals.pixshift;
+              sp_globals.clip_ymin = -1 * sp_globals.clip_ymin;
+              if (bmap_min < sp_globals.clip_ymin)
+                   sp_globals.ymin = sp_globals.clip_ymin;
+               else
+                    sp_globals.ymin = bmap_min;
+               }
+            if (sp_globals.specs.flags & CLIP_BOTTOM)
+               {
+               sp_globals.clip_ymax = (fix31)((fix31)(-1 * EM_BOT) * sp_globals.tcb0.yppo + ((1<<sp_globals.multshift)/2));
+               sp_globals.clip_ymax = sp_globals.clip_ymax >> sp_globals.multshift;
+               bmap_max = (sp_globals.bmap_ymax + sp_globals.pixrnd) >> sp_globals.pixshift;
+              if (bmap_max < sp_globals.clip_ymax)
+                    sp_globals.ymax = bmap_max;
+               else
+                   sp_globals.ymax = sp_globals.clip_ymax;
+               }
+               sp_globals.clip_xmax =  -sp_globals.xmin;
+               sp_globals.clip_xmin = ((sp_globals.set_width.x+32768L) >> 16) -
+                                      sp_globals.xmin;
+               break;
+       case 2: /* 90 degree rotation */
+            if (sp_globals.specs.flags & CLIP_TOP)
+               {
+               sp_globals.clip_xmin = (fix31)((fix31)(-1 * EM_BOT) * sp_globals.tcb0.yppo + ((1<<sp_globals.multshift)/2));
+               sp_globals.clip_xmin = sp_globals.clip_xmin >> sp_globals.multshift;
+               sp_globals.clip_xmin = -1 * sp_globals.clip_xmin;
+               bmap_min = (sp_globals.bmap_xmin + sp_globals.pixrnd + 1) >> sp_globals.pixshift;
+              if (bmap_min > sp_globals.clip_xmin)
+                    sp_globals.clip_xmin = bmap_min;
+
+              /* normalize to x origin */
+               sp_globals.clip_xmin -= sp_globals.xmin;
+               }
+            if (sp_globals.specs.flags & CLIP_BOTTOM)
+               {
+               sp_globals.clip_xmax = (fix31)((fix31)EM_TOP * sp_globals.tcb0.yppo + ((1<<sp_globals.multshift)/2));
+               sp_globals.clip_xmax = sp_globals.clip_xmax >> sp_globals.multshift;
+               bmap_max = (sp_globals.bmap_xmax + sp_globals.pixrnd) >> sp_globals.pixshift;
+              if (bmap_max < sp_globals.clip_xmax)
+                    sp_globals.xmax = bmap_max;
+               else
+                   sp_globals.xmax = sp_globals.clip_xmax;
+              sp_globals.clip_ymax = 0;
+              if ((sp_globals.specs.flags & CLIP_TOP) && 
+                   (sp_globals.ymax > sp_globals.clip_ymax))
+                   sp_globals.ymax = sp_globals.clip_ymax;
+              sp_globals.clip_ymin = ((sp_globals.set_width.y+32768L) >> 16);
+               if ((sp_globals.specs.flags & CLIP_BOTTOM) && 
+                   (sp_globals.ymin < sp_globals.clip_ymin))
+                    sp_globals.ymin = sp_globals.clip_ymin;
+              /* normalize to x origin */
+               sp_globals.clip_xmax -= sp_globals.xmin;
+               }
+               break;
+       case 3: /* 270 degree rotation */
+            if (sp_globals.specs.flags & CLIP_TOP)
+               {
+               sp_globals.clip_xmin = (fix31)((fix31)EM_TOP * sp_globals.tcb0.yppo + ((1<<sp_globals.multshift)/2));
+               sp_globals.clip_xmin = sp_globals.clip_xmin >> sp_globals.multshift;
+              sp_globals.clip_xmin = -1 * sp_globals.clip_xmin;
+               bmap_min = (sp_globals.bmap_xmin + sp_globals.pixrnd + 1) >> sp_globals.pixshift;
+
+               /* let the minimum be the larger of these two values */
+              if (bmap_min > sp_globals.clip_xmin)
+                   sp_globals.clip_xmin = bmap_min;
+
+              /* normalize the x value to new xorgin */
+               sp_globals.clip_xmin -= sp_globals.xmin;
+               }
+            if (sp_globals.specs.flags & CLIP_BOTTOM)
+               {
+               sp_globals.clip_xmax = (fix31)((fix31)(-1 * EM_BOT) * sp_globals.tcb0.yppo + ((1<<sp_globals.multshift)/2));
+               sp_globals.clip_xmax = sp_globals.clip_xmax >> sp_globals.multshift;
+               bmap_max = (sp_globals.bmap_xmax + sp_globals.pixrnd) >> sp_globals.pixshift;
+
+              /* let the max be the lesser of these two values */
+              if (bmap_max < sp_globals.clip_xmax)
+                   {
+                   sp_globals.xmax = bmap_max; 
+                   sp_globals.clip_xmax = bmap_max;
+                   }
+               else
+                    sp_globals.xmax = sp_globals.clip_xmax;
+
+              /* normalize the x value to new x origin */
+              sp_globals.clip_xmax -= sp_globals.xmin;
+               }
+               /* compute y clip values */
+              sp_globals.clip_ymax = ((sp_globals.set_width.y+32768L) >> 16);
+              if ((sp_globals.specs.flags & CLIP_TOP) && 
+                   (sp_globals.ymax > sp_globals.clip_ymax))
+                   sp_globals.ymax = sp_globals.clip_ymax;
+              sp_globals.clip_ymin = 0;
+               if ((sp_globals.specs.flags & CLIP_BOTTOM) && 
+                   (sp_globals.ymin < sp_globals.clip_ymin))
+                    sp_globals.ymin = sp_globals.clip_ymin;
+               break;
+       default: /* this is for zero degree rotation and arbitrary rotation */
+            if (sp_globals.specs.flags & CLIP_TOP)
+               {
+              sp_globals.clip_ymax = (fix31)((fix31)EM_TOP * sp_globals.tcb0.yppo + ((1<<sp_globals.multshift)/2));
+               sp_globals.clip_ymax = sp_globals.clip_ymax >> sp_globals.multshift;
+               bmap_max = (sp_globals.bmap_ymax + sp_globals.pixrnd) >> sp_globals.pixshift;
+              if (bmap_max > sp_globals.clip_ymax)
+                    sp_globals.ymax = bmap_max;
+               else
+                   sp_globals.ymax = sp_globals.clip_ymax;
+               }
+            if (sp_globals.specs.flags & CLIP_BOTTOM)
+               {
+              sp_globals.clip_ymin = (fix31)((fix31)(-1 * EM_BOT) * sp_globals.tcb0.yppo +  ((1<<sp_globals.multshift)/2));
+               sp_globals.clip_ymin = sp_globals.clip_ymin >> sp_globals.multshift;
+              sp_globals.clip_ymin = - sp_globals.clip_ymin;
+               bmap_min = (sp_globals.bmap_ymin + sp_globals.pixrnd + 1) >> sp_globals.pixshift;
+              if (bmap_min < sp_globals.clip_ymin)
+                   sp_globals.ymin = sp_globals.clip_ymin;
+               else
+                    sp_globals.ymin = bmap_min;
+               }
+               sp_globals.clip_xmin = -sp_globals.xmin;
+               sp_globals.clip_xmax = ((sp_globals.set_width.x+32768L) >> 16) -
+                                      sp_globals.xmin;
+               break;
+       }
+if ( !(sp_globals.specs.flags & CLIP_TOP))
+#endif
+            sp_globals.ymax = (sp_globals.bmap_ymax + sp_globals.pixrnd) >> sp_globals.pixshift;
+
+#if INCL_CLIPPING
+if ( !(sp_globals.specs.flags & CLIP_BOTTOM))
+#endif
+
+        sp_globals.ymin = (sp_globals.bmap_ymin + sp_globals.pixrnd + 1) >> sp_globals.pixshift;
+        }
+    else
+        {
+        sp_globals.ymin = sp_globals.ymax = 0;
+        }
+
+    /* add in the rounded out part (from xform.) of the left edge */
+    if (sp_globals.tcb.xmode == 0)    /* for X pix is function of X orus only add the round */
+       xorg = (((fix31)sp_globals.xmin << 16) + (sp_globals.rnd_xmin << sp_globals.poshift));
+    else
+        if (sp_globals.tcb.xmode == 1) /* for X pix is function of -X orus only, subtr. round */
+               xorg = (((fix31)sp_globals.xmin << 16) - (sp_globals.rnd_xmin << sp_globals.poshift)) ;
+        else
+               xorg = (fix31)sp_globals.xmin << 16;   /* for other cases don't use round on x */
+           
+    if (sp_globals.tcb.ymode == 2)   /* for Y pix is function of X orus only, add round error */ 
+       yorg = (((fix31)sp_globals.ymin << 16) + (sp_globals.rnd_xmin << sp_globals.poshift));
+    else
+        if (sp_globals.tcb.ymode == 3) /* for Y pix is function of -X orus only, sub round */
+               yorg = (((fix31)sp_globals.ymin << 16) - (sp_globals.rnd_xmin << sp_globals.poshift));
+        else                          /* all other cases have no round error on yorg */
+               yorg = (fix31)sp_globals.ymin << 16;
+
+    open_bitmap(sp_globals.set_width.x, sp_globals.set_width.y, xorg, yorg,
+                                sp_globals.xmax - sp_globals.xmin, sp_globals.ymax -  sp_globals.ymin);
+    if (sp_globals.intercept_oflo)
+        {
+        sp_globals.y_band.band_min = sp_globals.ymin;
+        sp_globals.y_band.band_max = sp_globals.ymax;
+        init_intercepts_out();
+        sp_globals.first_pass = FALSE;
+        sp_globals.extents_running = FALSE;
+        return FALSE;
+        }
+    else
+        {
+        sp_proc_intercepts_screen();
+        close_bitmap();
+        return TRUE;
+        }
+    }
+else
+    {
+    if (sp_globals.intercept_oflo)
+        {
+        reduce_band_size_out();
+        init_intercepts_out();
+        return FALSE;
+        }
+    else
+        {
+        sp_proc_intercepts_screen();
+        if (next_band_out())
+            {
+            init_intercepts_out();
+            return FALSE;
+            }
+        close_bitmap();
+        return TRUE;
+        }
+    }
+}
+#endif
+\f
+#if INCL_SCREEN
+FUNCTION LOCAL  void sp_add_intercept_screen(y, x)
+GDECL
+fix15 y;                 /* Y coordinate in relative pixel units */
+                         /* (0 is lowest sample in band) */
+fix31 x;                 /* X coordinate of intercept in subpixel units */
+
+/*  Called by line() to add an intercept to the intercept list structure
+ */
+
+{
+register fix15 from;   /* Insertion pointers for the linked list sort */
+register fix15 to;
+register fix15 xloc;
+register fix15 xfrac;
+
+#if DEBUG
+printf("    Add intercept(%2d, %x)\n", y + sp_globals.y_band.band_min, x);
+
+/* Bounds checking IS done in debug mode */
+if (y < 0)       /* Y value below bottom of current band? */
+    {
+    printf(" Intecerpt less than 0!!!\007\n");
+    return;
+    }
+
+if (y > (sp_globals.no_y_lists - 1))              /* Y value above top of current band? */
+    {
+    printf(" Intercept too big for band!!!!!\007\n");
+    return;
+    }
+#endif
+
+/* Store new values */
+
+sp_intercepts.car[sp_globals.next_offset] = xloc = (fix15)(x >> 16);
+sp_intercepts.inttype[sp_globals.next_offset] = sp_intercepts.leftedge | (xfrac = ((x >> 8) & FRACTION));
+
+/* Find slot to insert new element (between from and to) */
+
+from = y; /* Start at list head */
+
+while( (to = sp_intercepts.cdr[from]) != 0) /* Until to == end of list */
+    {
+    if (xloc < sp_intercepts.car[to]) /* If next item is larger than or same as this one... */
+        goto insert_element; /* ... drop out and insert here */
+       else if (xloc == sp_intercepts.car[to] && xfrac < (sp_intercepts.inttype[to] & FRACTION))
+        goto insert_element; /* ... drop out and insert here */
+    from = to; /* move forward in list */
+    }
+
+insert_element: /* insert element "sp_globals.next_offset" between elements "from" */
+                /* and "to" */
+
+sp_intercepts.cdr[from] = sp_globals.next_offset;
+sp_intercepts.cdr[sp_globals.next_offset] = to;
+
+if (++sp_globals.next_offset >= MAX_INTERCEPTS) /* Intercept buffer full? */
+    {
+    sp_globals.intercept_oflo = TRUE;
+/* There may be a few more calls to "add_intercept" from the current line */
+/* To avoid problems, we set next_offset to a safe value. We don't care   */
+/* if the intercept table gets trashed at this point                      */
+    sp_globals.next_offset = sp_globals.first_offset;
+    }
+}
+
+#endif
+\f
+#if INCL_SCREEN
+FUNCTION LOCAL  void sp_proc_intercepts_screen()
+GDECL
+
+/*  Called by sp_make_char to output accumulated intercept lists
+ *  Clips output to sp_globals.xmin, sp_globals.xmax, sp_globals.ymin, sp_globals.ymax boundaries
+ */
+{
+register fix15 i,j, jplus1, iminus1;
+fix15 k,nextk, previ;
+register fix15 from, to;          /* Start and end of run in pixel units   
+                            relative to left extent of character  */
+register fix15 y;
+register fix15 scan_line;
+         fix15 first_y, last_y;
+         fix15 xsave;
+         fix15 xmin, xmax;
+         boolean clipleft, clipright;
+
+
+fix15 diff;
+
+#if DEBUG
+printf("\nPROC_INTERCEPTS_SCREEN: Intercept lists before:\n");
+#endif
+
+#if INCL_CLIPPING
+if ((sp_globals.specs.flags & CLIP_LEFT) != 0)
+    clipleft = TRUE;
+else
+    clipleft = FALSE;
+if ((sp_globals.specs.flags & CLIP_RIGHT) != 0)
+    clipright = TRUE;
+else
+    clipright = FALSE;
+if (clipleft || clipright)
+        {
+        xmax = sp_globals.clip_xmax + sp_globals.xmin;
+        xmin = sp_globals.clip_xmin + sp_globals.xmin;
+        }
+if (!clipright)
+        xmax = ((sp_globals.set_width.x+32768L) >> 16);
+#endif
+
+if ((first_y = sp_globals.y_band.band_max) >= sp_globals.ymax)    
+    first_y = sp_globals.ymax - 1;               /* Clip to sp_globals.ymax boundary */
+
+if ((last_y = sp_globals.y_band.band_min) < sp_globals.ymin)      
+    last_y = sp_globals.ymin;                    /* Clip to sp_globals.ymin boundary */
+
+last_y  -= sp_globals.y_band.band_min;
+
+#if DEBUG
+/* Print out all of the intercept info */
+scan_line = sp_globals.ymax - first_y - 1;
+
+for (y = first_y - sp_globals.y_band.band_min; y >= last_y; y--, scan_line++)
+    {
+    i = y;                            /* Index head of intercept list */
+    while ((i = sp_intercepts.cdr[i]) != 0)         /* Link to next intercept if present */
+        {
+        if ((from = sp_intercepts.car[i] - sp_globals.xmin) < 0)
+            from = 0;                 /* Clip to sp_globals.xmin boundary */
+        i = sp_intercepts.cdr[i];                   /* Link to next intercept */
+        if (i == 0)                   /* End of list? */
+            {
+            printf("****** proc_intercepts: odd number of intercepts\n");
+            break;
+            }
+        if ((to = sp_intercepts.car[i]) > sp_globals.xmax)
+            to = sp_globals.xmax - sp_globals.xmin;         /* Clip to sp_globals.xmax boundary */
+        else
+            to -= sp_globals.xmin;
+        printf("    Y = %2d (scanline %2d): %d %d:\n", 
+            y + sp_globals.y_band.band_min, scan_line, from, to);
+        }
+    }
+#endif
+
+/* CHECK INTERCEPT LIST FOR DROPOUT AND WINDING, FIX IF NECESSARY  */
+
+for (y = first_y - sp_globals.y_band.band_min; y >= last_y; y--)
+    {
+       previ = y;
+    i = sp_intercepts.cdr[y];                            /* Index head of intercept list */
+    while (i  != 0)         /* Link to next intercept if present */
+        {
+               j = i;
+        i = sp_intercepts.cdr[i];                   /* Link to next intercept */
+               if (sp_intercepts.inttype[i] & LEFT_INT)
+                       {
+                       if (sp_intercepts.inttype[j] & LEFT_INT)
+                               {
+                               do { i = sp_intercepts.cdr[i]; } while (sp_intercepts.inttype[i] & LEFT_INT);
+                               do { i = sp_intercepts.cdr[i]; } while (sp_intercepts.cdr[i] && !(sp_intercepts.inttype[sp_intercepts.cdr[i]] & LEFT_INT));
+                               sp_intercepts.cdr[j] = i;
+                               }
+                       else
+                               {
+                               xsave = sp_intercepts.car[j];
+                               sp_intercepts.car[j] = sp_intercepts.car[i];
+                               sp_intercepts.car[i] = xsave;
+
+                               xsave = sp_intercepts.inttype[j];
+                               sp_intercepts.inttype[j] = sp_intercepts.inttype[i] & FRACTION;
+                               sp_intercepts.inttype[i] = xsave | LEFT_INT;
+
+                               sp_intercepts.cdr[previ] = i;
+                               sp_intercepts.cdr[j] = sp_intercepts.cdr[i];
+                               sp_intercepts.cdr[i] = j;
+                               i = j;
+                               j = sp_intercepts.cdr[previ];
+                               }
+                       }
+
+        if (sp_intercepts.car[j] < sp_globals.xmin)
+            sp_intercepts.car[j] = sp_globals.xmin;                 /* Clip to sp_globals.xmin boundary */
+
+        if (sp_intercepts.car[i] > sp_globals.xmax)
+            sp_intercepts.car[i] = sp_globals.xmax;
+
+        if (sp_intercepts.car[j] >= sp_intercepts.car[i])
+                       {
+                       if ((ufix16)(sp_intercepts.inttype[j] & FRACTION) + (ufix16)(sp_intercepts.inttype[i] & FRACTION) > sp_intercepts.fracpix)
+                               ++sp_intercepts.car[i];
+                       else
+                               --sp_intercepts.car[j];
+                       }
+               if (sp_globals.first_pass)
+                       {
+                       if (sp_intercepts.inttype[i-1] & END_INT)
+                               {
+                               for (iminus1 = i+1; !(sp_intercepts.inttype[iminus1] & END_INT); iminus1++)
+                                       ;
+                               }
+                       else
+                               iminus1 = i-1;
+       
+                       if (sp_intercepts.inttype[j] & END_INT)
+                               {
+                               for (jplus1 = j-1; !(sp_intercepts.inttype[jplus1] & END_INT); jplus1--)
+                                       ;
+                               jplus1++;
+                               }
+                       else
+                               jplus1 = j+1;
+
+                       if ((sp_intercepts.inttype[iminus1] & LEFT_INT)) 
+                               {
+                               if ( sp_intercepts.car[jplus1] > sp_intercepts.car[i])
+                                       {
+                                       diff = sp_intercepts.car[jplus1] - sp_intercepts.car[i];
+                                       sp_intercepts.car[i] += diff/2;
+                       sp_intercepts.car[jplus1] -= diff/2;
+                                       if (diff & 1)
+                                               {
+                                               if ((ufix16)(sp_intercepts.inttype[i] & FRACTION) + (ufix16)(sp_intercepts.inttype[jplus1] & FRACTION) > sp_intercepts.fracpix)
+                                                       sp_intercepts.car[i] ++;
+                                               else
+                                                       sp_intercepts.car[jplus1]--;
+                                               }
+                                       }
+                               }
+                       else if (!(sp_intercepts.inttype[jplus1] & LEFT_INT))
+                               {
+                               if (sp_intercepts.car[iminus1] < sp_intercepts.car[j])
+                                       {
+                                       diff = sp_intercepts.car[j] - sp_intercepts.car[iminus1];
+                                       sp_intercepts.car[j] -= diff/2;
+                       sp_intercepts.car[iminus1] += diff/2;
+                                       if (diff & 1)
+                                               {
+                                               if ((ufix16)(sp_intercepts.inttype[j] & FRACTION) + 
+                                              (ufix16)(sp_intercepts.inttype[iminus1] & FRACTION) > sp_intercepts.fracpix)
+                                                       sp_intercepts.car[iminus1]++;
+                                               else
+                                                       sp_intercepts.car[j]--;
+                                               }
+                                       }
+                               }
+                       if (sp_globals.tcb.mirror == -1) 
+                               {
+                               if (sp_intercepts.inttype[j-1] & END_INT)
+                                       {
+                                       for (jplus1 = j+1; !(sp_intercepts.inttype[jplus1] & END_INT); jplus1++)
+                                               ;
+                                       }
+                               else
+                                       {
+                                       jplus1 = j-1;
+                                       }
+                               }
+
+                       if (!(sp_intercepts.inttype[jplus1] & LEFT_INT) && 
+                           sp_intercepts.car[j] > sp_intercepts.car[jplus1])
+                               {
+                               k = sp_intercepts.cdr[y - 1];
+                               while (k > 0)
+                                       {
+                                       nextk = sp_intercepts.cdr[k];
+                                       if (!(sp_intercepts.inttype[k] & LEFT_INT) && 
+                               (sp_intercepts.inttype[nextk] & LEFT_INT) && 
+                                                        sp_intercepts.car[nextk] > sp_intercepts.car[jplus1])
+                                               {
+                                               if ((diff=sp_intercepts.car[j] - sp_intercepts.car[k]) > 0)
+                                                       {
+                                                       if (diff <= (sp_intercepts.car[nextk] - sp_intercepts.car[jplus1]))
+                                                               {
+                                                               sp_intercepts.car[j] -= diff/2;
+                                           sp_intercepts.car[k] += diff/2;
+                                                               if (diff & 1)
+                                                                       {
+                                                                       if ((ufix16)(sp_intercepts.inttype[j] & FRACTION) + 
+                                                      (ufix16)(sp_intercepts.inttype[k] & FRACTION) > sp_intercepts.fracpix)
+                                                                               sp_intercepts.car[j]--;
+                                                                       else
+                                                                               sp_intercepts.car[k]++;
+                                                                       }
+                                                               }
+                                                       else
+                                                               {
+                                                               diff = sp_intercepts.car[nextk] - sp_intercepts.car[jplus1];
+                                                               sp_intercepts.car[nextk] -= diff/2;
+                                           sp_intercepts.car[jplus1] += diff/2;
+                                                               if (diff & 1)
+                                                                       {
+                                                                       if ((ufix16)(sp_intercepts.inttype[jplus1] & FRACTION) + 
+                                                      (ufix16)(sp_intercepts.inttype[nextk] & FRACTION) > sp_intercepts.fracpix)
+                                                                               sp_intercepts.car[nextk]--;
+                                                                       else
+                                                                               sp_intercepts.car[jplus1]++;
+                                                                       }
+                                                               }
+                                                       }
+                                               break;
+                                               }
+                                       k = nextk;
+                                       }
+                               }
+                       if (j > 0 && sp_intercepts.car[j-1] > sp_intercepts.car[i] && !(sp_intercepts.inttype[j-1] & END_INT))
+                               {
+                               diff = sp_intercepts.car[j-1] - sp_intercepts.car[i];
+                               sp_intercepts.car[i] += diff/2;
+                   sp_intercepts.car[j-1] -= diff/2;
+                               if (diff & 1)
+                                       {
+                                       if ((ufix16)(sp_intercepts.inttype[i] & FRACTION) + (ufix16)(sp_intercepts.inttype[j-1] & FRACTION) > sp_intercepts.fracpix)
+                                               sp_intercepts.car[i]++;
+                                       else
+                                               sp_intercepts.car[j-1]--;
+                                       }
+                               }
+                       if (sp_intercepts.car[i+1] < sp_intercepts.car[j] && !(sp_intercepts.inttype[i] & END_INT))
+                               {
+                               diff = sp_intercepts.car[j] - sp_intercepts.car[i+1];
+                               sp_intercepts.car[j] -= diff/2;
+                   sp_intercepts.car[i+1] += diff/2;
+                               if (diff & 1)
+                                       {
+                                       if ((ufix16)(sp_intercepts.inttype[j] & FRACTION) + (ufix16)(sp_intercepts.inttype[i+1] & FRACTION) > sp_intercepts.fracpix)
+                                               sp_intercepts.car[i+1]++;
+                                       else
+                                               sp_intercepts.car[j]--;
+                                       }
+       
+                               }
+                       previ = i;
+               }
+               i = sp_intercepts.cdr[i];
+           }
+       }
+
+#if DEBUG
+printf("\nPROC_INTERCEPTS_SCREEN: Intercept lists after:\n");
+/* Print out all of the intercept info */
+scan_line = sp_globals.ymax - first_y - 1;
+
+for (y = first_y - sp_globals.y_band.band_min; y >= last_y; y--, scan_line++)
+    {
+    i = y;                            /* Index head of intercept list */
+    while ((i = sp_intercepts.cdr[i]) != 0)         /* Link to next intercept if present */
+        {
+        if ((from = sp_intercepts.car[i] - sp_globals.xmin) < 0)
+            from = 0;                 /* Clip to sp_globals.xmin boundary */
+        i = sp_intercepts.cdr[i];                   /* Link to next intercept */
+        if (i == 0)                   /* End of list? */
+            {
+            printf("****** proc_intercepts: odd number of intercepts\n");
+            break;
+            }
+        if ((to = sp_intercepts.car[i]) > sp_globals.xmax)
+            to = sp_globals.xmax - sp_globals.xmin;         /* Clip to sp_globals.xmax boundary */
+        else
+            to -= sp_globals.xmin;
+        printf("    Y = %2d (scanline %2d): %d %d:\n", 
+            y + sp_globals.y_band.band_min, scan_line, from, to);
+        }
+    }
+#endif                                                            
+
+/*  INTERCEPTS ALL PATCHED, NOW DRAW THE IMAGE */
+scan_line = sp_globals.ymax - first_y - 1;
+
+for (y = first_y - sp_globals.y_band.band_min; y >= last_y; y--, scan_line++)
+    {
+    i = sp_intercepts.cdr[y];                            /* Index head of intercept list */
+    while (i  != 0)         /* Link to next intercept if present */
+        {
+        from = sp_intercepts.car[i];
+        i = sp_intercepts.cdr[i];                   /* Link to next intercept */
+        to = sp_intercepts.car[i];
+#if INCL_CLIPPING
+        if (clipleft)
+                        {
+                        if (to <= xmin)
+                               {
+                               i = sp_intercepts.cdr[i];
+                                continue;
+                               }
+                        if (from < xmin)
+                                from = xmin;
+                        }
+        if (clipright)
+                        {
+                        if (from >= xmax)
+                               {
+                               i = sp_intercepts.cdr[i];
+                                continue;
+                               }
+                        if (to > xmax)
+                                to = xmax;
+                        }
+#endif
+        set_bitmap_bits(scan_line, from-sp_globals.xmin, to-sp_globals.xmin);
+       i = sp_intercepts.cdr[i];
+        }
+    }
+}
+
+#endif
diff --git a/Xserver/lib/font/Speedo/out_util.c b/Xserver/lib/font/Speedo/out_util.c
new file mode 100644 (file)
index 0000000..f377ac7
--- /dev/null
@@ -0,0 +1,337 @@
+/* $XConsortium: out_util.c,v 1.2 91/05/11 09:53:35 rws Exp $ */
+
+/*
+
+Copyright 1989-1991, Bitstream Inc., Cambridge, MA.
+You are hereby granted permission under all Bitstream propriety rights to
+use, copy, modify, sublicense, sell, and redistribute the Bitstream Speedo
+software and the Bitstream Charter outline font for any purpose and without
+restrictions; provided, that this notice is left intact on all copies of such
+software or font and that Bitstream's trademark is acknowledged as shown below
+on all unmodified copies of such font.
+
+BITSTREAM CHARTER is a registered trademark of Bitstream Inc.
+
+
+BITSTREAM INC. DISCLAIMS ANY AND ALL WARRANTIES, EXPRESS OR IMPLIED, INCLUDING
+WITHOUT LIMITATION THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+PARTICULAR PURPOSE.  BITSTREAM SHALL NOT BE LIABLE FOR ANY DIRECT OR INDIRECT
+DAMAGES, INCLUDING BUT NOT LIMITED TO LOST PROFITS, LOST DATA, OR ANY OTHER
+INCIDENTAL OR CONSEQUENTIAL DAMAGES, ARISING OUT OF OR IN ANY WAY CONNECTED
+WITH THE SPEEDO SOFTWARE OR THE BITSTREAM CHARTER OUTLINE FONT.
+
+*/
+
+
+#define        DEBUG   0
+
+/*************************** O U T _ U T I L . C *****************************
+ *                                                                           *
+ * This is a utility module share by all bitmap output modules               *
+ *                                                                           *
+ *****************************************************************************/
+
+
+#include "spdo_prv.h"               /* General definitions for Speedo   */
+/* absolute value function */
+#define   ABS(X)     ( (X < 0) ? -X : X)
+#if INCL_BLACK || INCL_2D || INCL_SCREEN
+\f
+FUNCTION  void init_char_out(Psw,Pmin,Pmax)
+GDECL
+point_t Psw, Pmin, Pmax;
+{
+sp_globals.set_width.x = (fix31)Psw.x << sp_globals.poshift;
+sp_globals.set_width.y = (fix31)Psw.y << sp_globals.poshift;
+set_first_band_out(Pmin, Pmax);
+init_intercepts_out();
+if (sp_globals.normal)
+    {
+    sp_globals.bmap_xmin = Pmin.x;
+    sp_globals.bmap_xmax = Pmax.x;
+    sp_globals.bmap_ymin = Pmin.y;
+    sp_globals.bmap_ymax = Pmax.y;
+    sp_globals.extents_running = FALSE;
+    }
+else
+    {
+    sp_globals.bmap_xmin = 32000;
+    sp_globals.bmap_xmax = -32000;
+    sp_globals.bmap_ymin = 32000;
+    sp_globals.bmap_ymax = -32000;
+    sp_globals.extents_running = TRUE;
+    }
+sp_globals.first_pass = TRUE;
+}
+\f
+FUNCTION void begin_sub_char_out(Psw, Pmin, Pmax)
+GDECL
+point_t Psw;                   
+point_t Pmin;                   
+point_t Pmax;                   
+/* Called at the start of each sub-character in a composite character
+ */
+{
+#if DEBUG
+printf("BEGIN_SUB_CHAR_out(%3.1f, %3.1f, %3.1f, %3.1f, %3.1f, %3.1f\n", 
+                    (real)Psw.x / (real)sp_globals.onepix, (real)Psw.y / (real)sp_globals.onepix,
+                    (real)Pmin.x / (real)sp_globals.onepix, (real)Pmin.y / (real)sp_globals.onepix,
+                    (real)Pmax.x / (real)sp_globals.onepix, (real)Pmax.y / (real)sp_globals.onepix);
+#endif
+restart_intercepts_out();
+if (!sp_globals.extents_running)
+       {
+    sp_globals.bmap_xmin = 32000;
+    sp_globals.bmap_xmax = -32000;
+    sp_globals.bmap_ymin = 32000;
+    sp_globals.bmap_ymax = -32000;
+    sp_globals.extents_running = TRUE;
+       }
+}
+\f
+FUNCTION void curve_out(P1, P2, P3,depth)
+GDECL
+point_t P1, P2, P3;                   
+fix15 depth;
+/* Called for each curve in the transformed character if curves out enabled
+ */
+{
+#if DEBUG
+printf("CURVE_OUT(%3.1f, %3.1f, %3.1f, %3.1f, %3.1f, %3.1f)\n", 
+    (real)P1.x / (real)sp_globals.onepix, (real)P1.y / (real)sp_globals.onepix,
+    (real)P2.x / (real)sp_globals.onepix, (real)P2.y / (real)sp_globals.onepix,
+    (real)P3.x / (real)sp_globals.onepix, (real)P3.y / (real)sp_globals.onepix);
+#endif
+}
+\f
+
+
+FUNCTION void end_contour_out()
+GDECL
+/* Called after the last vector in each contour
+ */
+{
+#if DEBUG
+printf("END_CONTOUR_OUT()\n");
+#endif
+}
+\f
+
+FUNCTION void end_sub_char_out()
+GDECL
+/* Called after the last contour in each sub-character in a compound character
+ */
+{
+#if DEBUG
+printf("END_SUB_CHAR_OUT()\n");
+#endif
+}
+\f
+
+FUNCTION void init_intercepts_out()
+GDECL
+/*  Called to initialize intercept storage data structure
+ */
+
+{
+fix15 i;
+fix15 no_lists;
+
+#if DEBUG
+printf("    Init intercepts (Y band from %d to %d)\n", sp_globals.y_band.band_min, sp_globals.y_band.band_max);
+if (sp_globals.x_scan_active)
+    printf("                    (X band from %d to %d)\n", sp_globals.x_band.band_min, sp_globals.x_band.band_max);
+#endif 
+
+sp_globals.intercept_oflo = FALSE;
+
+sp_globals.no_y_lists = sp_globals.y_band.band_max - sp_globals.y_band.band_min + 1;
+#if INCL_2D
+if (sp_globals.output_mode == MODE_2D)
+       {
+       sp_globals.no_x_lists = sp_globals.x_scan_active ? 
+               sp_globals.x_band.band_max - sp_globals.x_band.band_min + 1 : 0;
+       no_lists = sp_globals.no_y_lists + sp_globals.no_x_lists;
+       } 
+else
+#endif
+       no_lists = sp_globals.no_y_lists;
+
+#if INCL_2D
+sp_globals.y_band.band_floor = 0;
+sp_globals.y_band.band_ceiling = sp_globals.no_y_lists;
+#endif
+                                        
+if (no_lists >= MAX_INTERCEPTS)  /* Not enough room for list table? */
+    {
+    no_lists = sp_globals.no_y_lists = MAX_INTERCEPTS;
+    sp_globals.intercept_oflo = TRUE;
+       sp_globals.y_band.band_min = sp_globals.y_band.band_max - sp_globals.no_y_lists + 1;
+#if INCL_2D
+    sp_globals.y_band.band_array_offset = sp_globals.y_band.band_min;
+    sp_globals.y_band.band_ceiling = sp_globals.no_y_lists;
+    sp_globals.no_x_lists = 0;
+    sp_globals.x_scan_active = FALSE;
+#endif
+    }
+
+for (i = 0; i < no_lists; i++)   /* For each active value... */
+    {
+#if INCL_SCREEN
+       if (sp_globals.output_mode == MODE_SCREEN)
+               sp_intercepts.inttype[i]=0;
+#endif
+    sp_intercepts.cdr[i] = 0;                    /* Mark each intercept list empty */
+    }
+
+sp_globals.first_offset = sp_globals.next_offset = no_lists;
+
+#if INCL_2D
+sp_globals.y_band.band_array_offset = sp_globals.y_band.band_min;
+sp_globals.x_band.band_array_offset = sp_globals.x_band.band_min - sp_globals.no_y_lists;
+sp_globals.x_band.band_floor = sp_globals.no_y_lists;
+sp_globals.x_band.band_ceiling = no_lists;
+#endif
+#if INCL_SCREEN
+sp_intercepts.inttype[sp_globals.no_y_lists-1] = END_INT;
+#endif
+
+}
+\f
+
+FUNCTION void restart_intercepts_out()
+GDECL
+
+/*  Called by sp_make_char when a new sub character is started
+ *  Freezes current sorted lists
+ */
+
+{
+
+#if DEBUG
+printf("    Restart intercepts:\n");
+#endif
+sp_globals.first_offset = sp_globals.next_offset;
+}
+\f
+
+
+FUNCTION void set_first_band_out(Pmin, Pmax)
+GDECL
+point_t Pmin;
+point_t Pmax;
+{
+
+sp_globals.ymin = Pmin.y;
+sp_globals.ymax = Pmax.y;
+
+sp_globals.ymin = (sp_globals.ymin - sp_globals.onepix + 1) >> sp_globals.pixshift;
+sp_globals.ymax = (sp_globals.ymax + sp_globals.onepix - 1) >> sp_globals.pixshift;
+
+#if INCL_CLIPPING
+    switch(sp_globals.tcb0.xtype)
+       {
+       case 1: /* 180 degree rotation */
+           if (sp_globals.specs.flags & CLIP_TOP)
+               {
+               sp_globals.clip_ymin = (fix31)((fix31)EM_TOP * sp_globals.tcb0.yppo + ((1<<sp_globals.multshift)/2));
+               sp_globals.clip_ymin = sp_globals.clip_ymin >> sp_globals.multshift;
+              sp_globals.clip_ymin = -1* sp_globals.clip_ymin;
+              if (sp_globals.ymin < sp_globals.clip_ymin)
+                   sp_globals.ymin = sp_globals.clip_ymin;
+              }
+            if (sp_globals.specs.flags & CLIP_BOTTOM)
+              {
+               sp_globals.clip_ymax = (fix31)((fix31)(-1 * EM_BOT) * sp_globals.tcb0.yppo + ((1<<sp_globals.multshift)/2));
+               sp_globals.clip_ymax = sp_globals.clip_ymax >> sp_globals.multshift;
+              if (sp_globals.ymax > sp_globals.clip_ymax)
+                   sp_globals.ymax = sp_globals.clip_ymax;
+               }
+               break;
+       case 2: /* 90 degree rotation */
+            sp_globals.clip_ymax = 0;
+            if ((sp_globals.specs.flags & CLIP_TOP) &&
+                (sp_globals.ymax > sp_globals.clip_ymax))
+                 sp_globals.ymax = sp_globals.clip_ymax;
+            sp_globals.clip_ymin = ((sp_globals.set_width.y+32768L) >> 16);
+            if ((sp_globals.specs.flags & CLIP_BOTTOM) &&
+                (sp_globals.ymin < sp_globals.clip_ymin))
+                 sp_globals.ymin = sp_globals.clip_ymin;
+            break;
+       case 3: /* 270 degree rotation */
+               sp_globals.clip_ymax = ((sp_globals.set_width.y+32768L) >> 16);
+               if ((sp_globals.specs.flags & CLIP_TOP) &&
+                   (sp_globals.ymax > sp_globals.clip_ymax))
+                    sp_globals.ymax = sp_globals.clip_ymax;
+               sp_globals.clip_ymin = 0;
+               if ((sp_globals.specs.flags & CLIP_BOTTOM) &&
+                   (sp_globals.ymin < sp_globals.clip_ymin))
+                    sp_globals.ymin = sp_globals.clip_ymin;
+               break;
+       default: /* this is for zero degree rotation and arbitrary rotation */
+           if (sp_globals.specs.flags & CLIP_TOP)
+               {
+              sp_globals.clip_ymax = (fix31)((fix31)EM_TOP * sp_globals.tcb0.yppo +  ((1<<sp_globals.multshift)/2));
+               sp_globals.clip_ymax = sp_globals.clip_ymax >> sp_globals.multshift;
+              if (sp_globals.ymax > sp_globals.clip_ymax)
+                   sp_globals.ymax = sp_globals.clip_ymax;
+              }
+            if (sp_globals.specs.flags & CLIP_BOTTOM)
+              {
+              sp_globals.clip_ymin = (fix31)((fix31)(-1 * EM_BOT) * sp_globals.tcb0.yppo +  ((1<<sp_globals.multshift)/2));
+               sp_globals.clip_ymin = sp_globals.clip_ymin >> sp_globals.multshift;
+              sp_globals.clip_ymin = - sp_globals.clip_ymin;
+              if (sp_globals.ymin < sp_globals.clip_ymin)
+                   sp_globals.ymin = sp_globals.clip_ymin;
+               }
+               break;
+       }
+#endif
+sp_globals.y_band.band_min = sp_globals.ymin;
+sp_globals.y_band.band_max = sp_globals.ymax - 1; 
+
+sp_globals.xmin = (Pmin.x + sp_globals.pixrnd) >> sp_globals.pixshift;
+sp_globals.xmax = (Pmax.x + sp_globals.pixrnd) >> sp_globals.pixshift;
+
+
+#if INCL_2D
+sp_globals.x_band.band_min = sp_globals.xmin - 1; /* subtract one pixel of "safety margin" */
+sp_globals.x_band.band_max = sp_globals.xmax /* - 1 + 1 */; /* Add one pixel of "safety margin" */
+#endif
+}
+
+
+
+
+                                  
+\f
+
+FUNCTION void reduce_band_size_out()
+GDECL
+{
+sp_globals.y_band.band_min = sp_globals.y_band.band_max - ((sp_globals.y_band.band_max - sp_globals.y_band.band_min) >> 1);
+#if INCL_2D
+sp_globals.y_band.band_array_offset = sp_globals.y_band.band_min;
+#endif
+}
+\f
+
+FUNCTION boolean next_band_out()
+GDECL
+{
+fix15  tmpfix15;
+
+if (sp_globals.y_band.band_min <= sp_globals.ymin)
+    return FALSE;
+tmpfix15 = sp_globals.y_band.band_max - sp_globals.y_band.band_min;
+sp_globals.y_band.band_max = sp_globals.y_band.band_min - 1;
+sp_globals.y_band.band_min = sp_globals.y_band.band_max - tmpfix15;
+if (sp_globals.y_band.band_min < sp_globals.ymin)
+    sp_globals.y_band.band_min = sp_globals.ymin;
+#if INCL_2D
+sp_globals.y_band.band_array_offset = sp_globals.y_band.band_min;
+#endif
+return TRUE;
+}
+#endif
+
diff --git a/Xserver/lib/font/Speedo/reset.c b/Xserver/lib/font/Speedo/reset.c
new file mode 100644 (file)
index 0000000..428bbd0
--- /dev/null
@@ -0,0 +1,127 @@
+/* $XConsortium: reset.c,v 1.2 91/05/11 09:53:59 rws Exp $ */
+
+/*
+
+Copyright 1989-1991, Bitstream Inc., Cambridge, MA.
+You are hereby granted permission under all Bitstream propriety rights to
+use, copy, modify, sublicense, sell, and redistribute the Bitstream Speedo
+software and the Bitstream Charter outline font for any purpose and without
+restrictions; provided, that this notice is left intact on all copies of such
+software or font and that Bitstream's trademark is acknowledged as shown below
+on all unmodified copies of such font.
+
+BITSTREAM CHARTER is a registered trademark of Bitstream Inc.
+
+
+BITSTREAM INC. DISCLAIMS ANY AND ALL WARRANTIES, EXPRESS OR IMPLIED, INCLUDING
+WITHOUT LIMITATION THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+PARTICULAR PURPOSE.  BITSTREAM SHALL NOT BE LIABLE FOR ANY DIRECT OR INDIRECT
+DAMAGES, INCLUDING BUT NOT LIMITED TO LOST PROFITS, LOST DATA, OR ANY OTHER
+INCIDENTAL OR CONSEQUENTIAL DAMAGES, ARISING OUT OF OR IN ANY WAY CONNECTED
+WITH THE SPEEDO SOFTWARE OR THE BITSTREAM CHARTER OUTLINE FONT.
+
+*/
+
+
+
+/******************************* R E S E T . C *******************************
+ *                                                                           *
+ * This module provides initialization functions.                            *
+ *                                                                           *
+ ****************************************************************************/
+
+#include "spdo_prv.h"               /* General definitions for Speedo     */
+#include "keys.h"                /* Font decryption keys */
+
+#define   DEBUG      0
+
+#if DEBUG
+#include <stdio.h>
+#define SHOW(X) printf("X = %d\n", X)
+#else
+#define SHOW(X)
+#endif
+
+/***** GLOBAL VARIABLES *****/
+
+/*****  GLOBAL FUNCTIONS *****/
+
+/***** EXTERNAL VARIABLES *****/
+
+/***** EXTERNAL FUNCTIONS *****/
+
+/***** STATIC VARIABLES *****/
+
+/***** STATIC FUNCTIONS *****/
+
+\f
+FUNCTION void reset()
+GDECL
+/*
+ * Called by the host software to intialize the Speedo mechanism
+ */
+{
+sp_globals.specs_valid = FALSE;            /* Flag specs not valid */
+
+/* Reset decryption key */
+sp_globals.key32 = (KEY3 << 8) | KEY2;
+sp_globals.key4 = KEY4;
+sp_globals.key6 = KEY6;
+sp_globals.key7 = KEY7;
+sp_globals.key8 = KEY8;
+
+#if INCL_RULES
+sp_globals.constr.font_id_valid = FALSE;
+#endif
+
+#if INCL_MULTIDEV
+#if INCL_BLACK || INCL_SCREEN || INCL_2D
+sp_globals.bitmap_device_set = FALSE;
+#endif
+#if INCL_OUTLINE
+sp_globals.outline_device_set = FALSE;
+#endif
+#endif
+}
+\f
+#if INCL_KEYS
+FUNCTION void set_key(key)
+GDECL
+ufix8 key[];         /* Specified decryption key */
+/*
+ * Dynamically sets font decryption key.
+ */
+{
+sp_globals.key32 = ((ufix16)key[3] << 8) | key[2];
+sp_globals.key4 = key[4];
+sp_globals.key6 = key[6];
+sp_globals.key7 = key[7];
+sp_globals.key8 = key[8];
+}
+#endif
+
+
+\f\f
+FUNCTION ufix16 get_cust_no(font_buff)
+GDECL
+buff_t font_buff;
+/*
+       returns customer number from font 
+*/
+{ 
+ufix8 FONTFAR *hdr2_org;
+ufix16 private_off;
+
+private_off = read_word_u(font_buff.org + FH_HEDSZ);
+if (private_off + FH_CUSNR > font_buff.no_bytes)
+       {
+       report_error(1);           /* Insufficient font data loaded */
+    return FALSE;
+    }
+
+hdr2_org = font_buff.org + private_off;
+
+return (read_word_u(hdr2_org + FH_CUSNR));
+}
+
+
diff --git a/Xserver/lib/font/Speedo/set_spcs.c b/Xserver/lib/font/Speedo/set_spcs.c
new file mode 100644 (file)
index 0000000..0bbc667
--- /dev/null
@@ -0,0 +1,770 @@
+/* $XConsortium: set_spcs.c,v 1.6 94/02/10 10:18:23 gildea Exp $ */
+
+/*
+
+Copyright 1989-1991, Bitstream Inc., Cambridge, MA.
+You are hereby granted permission under all Bitstream propriety rights to
+use, copy, modify, sublicense, sell, and redistribute the Bitstream Speedo
+software and the Bitstream Charter outline font for any purpose and without
+restrictions; provided, that this notice is left intact on all copies of such
+software or font and that Bitstream's trademark is acknowledged as shown below
+on all unmodified copies of such font.
+
+BITSTREAM CHARTER is a registered trademark of Bitstream Inc.
+
+
+BITSTREAM INC. DISCLAIMS ANY AND ALL WARRANTIES, EXPRESS OR IMPLIED, INCLUDING
+WITHOUT LIMITATION THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+PARTICULAR PURPOSE.  BITSTREAM SHALL NOT BE LIABLE FOR ANY DIRECT OR INDIRECT
+DAMAGES, INCLUDING BUT NOT LIMITED TO LOST PROFITS, LOST DATA, OR ANY OTHER
+INCIDENTAL OR CONSEQUENTIAL DAMAGES, ARISING OUT OF OR IN ANY WAY CONNECTED
+WITH THE SPEEDO SOFTWARE OR THE BITSTREAM CHARTER OUTLINE FONT.
+
+*/
+
+
+/*************************** S E T _ S P C S . C *****************************
+ *                                                                           *
+ * This module implements all sp_set_specs() functionality.                  *
+ *                                                                           *
+ ****************************************************************************/
+#define SET_SPCS
+#include "spdo_prv.h"               /* General definitions for Speedo    */
+#include "keys.h"
+
+#define   DEBUG      0
+
+#if DEBUG
+#include <stdio.h>
+#define SHOW(X) printf("X = %d\n", X)
+#else
+#define SHOW(X)
+#endif
+
+/***** GLOBAL VARIABLES *****/
+
+/***** GLOBAL FUNCTIONS *****/
+
+/****** EXTERNAL VARIABLES *****/
+
+/***** STATIC VARIABLES *****/
+
+
+/****** STATIC FUNCTIONS *****/
+
+#if PROTOS_AVAIL
+static boolean sp_setup_consts(PROTO_DECL2 fix15 xmin, fix15 xmax,
+       fix15 ymin, fix15 ymax);
+static void sp_setup_tcb(PROTO_DECL2 tcb_t GLOBALFAR *ptcb);
+static fix15 sp_setup_mult(PROTO_DECL2 fix31 input_mult);
+static fix31 sp_setup_offset(PROTO_DECL2 fix31 input_offset);
+#else
+static void    sp_setup_tcb();      /* Set up transformation control block */
+static fix15 sp_setup_mult();       /* Convert mult to internal form */
+static fix31 sp_setup_offset();     /* Convert offset to internal form */
+static boolean sp_setup_consts();   /* Set up scaling constants */
+#endif
+
+
+\f
+FUNCTION boolean set_specs(specsarg)
+GDECL
+specs_t STACKFAR *specsarg;     /* Bundle of conversion specifications */
+/* 
+ * Called by host software to set character generation specifications
+ */
+{
+ufix8 FONTFAR  *pointer;       /* Pointer to font data */
+fix31   offcd;         /* Offset to start of character directory */
+fix31   ofcns;         /* Offset to start of constraint data */ 
+fix31   cd_size;       /* Size of character directory */
+fix31   no_bytes_min;  /* Min number of bytes in font buffer */
+ufix16  font_id;       /* Font ID */
+ufix16  private_off;   /* offset to private header */
+fix15   xmin;          /* Minimum X ORU value in font */
+fix15   xmax;          /* Maximum X ORU value in font */
+fix15   ymin;          /* Minimum Y ORU value in font */
+fix15   ymax;          /* Maximum Y ORU value in font */
+
+sp_globals.specs_valid = FALSE;           /* Flag specs not valid */
+
+sp_globals.specs = *specsarg;   /* copy specs structure into sp_globals */
+sp_globals.pspecs = &sp_globals.specs;
+sp_globals.font = *sp_globals.pspecs->pfont;
+sp_globals.pfont = &sp_globals.font;
+sp_globals.font_org = sp_globals.font.org;
+
+if (read_word_u(sp_globals.font_org + FH_FMVER + 4) != 0x0d0a)
+    {
+    report_error(4);           /* Font format error */
+    return FALSE;
+    }
+if (read_word_u(sp_globals.font_org + FH_FMVER + 6) != 0x0000)
+    {
+    report_error(4);           /* Font format error */
+    return FALSE;
+    }
+
+if (get_cust_no(*specsarg->pfont) == 0)
+       {
+       sp_globals.key32 = 0;
+       sp_globals.key4 = 0;
+       sp_globals.key6 = 0;
+       sp_globals.key7 = 0;
+       sp_globals.key8 = 0;
+       }
+else
+       {
+       sp_globals.key32 = (KEY3 << 8) | KEY2;
+       sp_globals.key4 = KEY4;
+       sp_globals.key6 = KEY6;
+       sp_globals.key7 = KEY7;
+       sp_globals.key8 = KEY8;
+       }
+       
+
+sp_globals.no_chars_avail = read_word_u(sp_globals.font_org + FH_NCHRF);
+
+/* Read sp_globals.orus per em from font header */
+sp_globals.orus_per_em = read_word_u(sp_globals.font_org + FH_ORUPM);
+
+/* compute address of private header */
+private_off = read_word_u(sp_globals.font_org + FH_HEDSZ);
+sp_globals.hdr2_org = sp_globals.font_org + private_off;
+
+/* set metric resolution if specified, default to outline res otherwise */
+if (private_off > EXP_FH_METRES)
+       {
+       sp_globals.metric_resolution = read_word_u(sp_globals.font_org + EXP_FH_METRES);
+       }
+else
+       {
+       sp_globals.metric_resolution = sp_globals.orus_per_em;
+       }
+
+#if INCL_METRICS
+sp_globals.kern.tkorg = sp_globals.font_org + read_long(sp_globals.hdr2_org + FH_OFFTK);
+sp_globals.kern.pkorg = sp_globals.font_org + read_long(sp_globals.hdr2_org + FH_OFFPK); 
+sp_globals.kern.no_tracks = read_word_u(sp_globals.font_org + FH_NKTKS);
+sp_globals.kern.no_pairs = read_word_u(sp_globals.font_org + FH_NKPRS);
+#endif
+
+offcd = read_long(sp_globals.hdr2_org + FH_OFFCD); /* Read offset to character directory */
+ofcns = read_long(sp_globals.hdr2_org + FH_OFCNS); /* Read offset to constraint data */
+cd_size = ofcns - offcd;
+if ((((sp_globals.no_chars_avail << 1) + 3) != cd_size) &&
+    (((sp_globals.no_chars_avail * 3) + 4) != cd_size))
+    {
+    report_error(4);           /* Font format error */
+    return FALSE;
+    }
+
+#if INCL_LCD                   /* Dynamic character data load suppoorted? */
+#if INCL_METRICS
+no_bytes_min = read_long(sp_globals.hdr2_org + FH_OCHRD); /* Offset to character data */
+#else                          /* Dynamic character data load not supported? */
+no_bytes_min = read_long(sp_globals.hdr2_org + FH_OFFTK); /* Offset to track kerning data */
+#endif
+#else                          /* Dynamic character data load not supported? */
+no_bytes_min = read_long(sp_globals.hdr2_org + FH_NBYTE); /* Offset to EOF + 1 */
+#endif
+
+sp_globals.font_buff_size = sp_globals.pfont->no_bytes;
+if (sp_globals.font_buff_size < no_bytes_min)  /* Minimum data not loaded? */
+    {
+    report_error(1);           /* Insufficient font data loaded */
+    return FALSE;
+    }
+
+sp_globals.pchar_dir = sp_globals.font_org + offcd;
+sp_globals.first_char_idx = read_word_u(sp_globals.font_org + FH_FCHRF);
+
+/* Register font name with sp_globals.constraint mechanism */
+#if INCL_RULES
+font_id = read_word_u(sp_globals.font_org + FH_FNTID);
+if (!(sp_globals.constr.font_id_valid) || (sp_globals.constr.font_id != font_id))
+    {
+    sp_globals.constr.font_id = font_id;
+    sp_globals.constr.font_id_valid = TRUE;
+    sp_globals.constr.data_valid = FALSE;
+    }
+sp_globals.constr.org = sp_globals.font_org + ofcns;
+sp_globals.constr.active = ((sp_globals.pspecs->flags & CONSTR_OFF) == 0);
+#endif
+
+/* Set up sliding point constants */
+/* Set pixel shift to accomodate largest transformed pixel value */
+xmin = read_word_u(sp_globals.font_org + FH_FXMIN);
+xmax = read_word_u(sp_globals.font_org + FH_FXMAX);
+ymin = read_word_u(sp_globals.font_org + FH_FYMIN);
+ymax = read_word_u(sp_globals.font_org + FH_FYMAX);
+
+if (!sp_setup_consts(xmin,xmax,ymin,ymax))
+    {
+    report_error(3);           /* Requested specs out of range */
+    return FALSE;
+    }
+#if INCL_ISW
+/* save the value of the max x oru that the fixed point constants are based on*/
+sp_globals.isw_xmax = xmax; 
+#endif
+
+/* Setup transformation control block */
+sp_setup_tcb(&sp_globals.tcb0);
+
+
+/* Select output module */
+sp_globals.output_mode = sp_globals.pspecs->flags & 0x0007;
+
+#if INCL_USEROUT
+if (!init_userout(sp_globals.pspecs))
+#endif
+
+switch (sp_globals.output_mode)
+    {
+#if INCL_BLACK
+case MODE_BLACK:                        /* Output mode 0 (Black writer) */
+       sp_globals.init_out = sp_init_black;
+    sp_globals.begin_char              = sp_begin_char_black;
+    sp_globals.begin_sub_char  = sp_begin_sub_char_out;
+       sp_globals.begin_contour        = sp_begin_contour_black;
+    sp_globals.curve                   = sp_curve_out;
+       sp_globals.line                 = sp_line_black;
+    sp_globals.end_contour             = sp_end_contour_out;
+       sp_globals.end_sub_char = sp_end_sub_char_out;
+    sp_globals.end_char                = sp_end_char_black;
+    break;
+#endif
+
+#if INCL_SCREEN
+case MODE_SCREEN:                        /* Output mode 1 (Screen writer) */
+       sp_globals.init_out = sp_init_screen;
+    sp_globals.begin_char              = sp_begin_char_screen;
+    sp_globals.begin_sub_char  = sp_begin_sub_char_out;
+       sp_globals.begin_contour        = sp_begin_contour_screen;
+    sp_globals.curve                   = sp_curve_screen;
+       sp_globals.line                 = sp_line_screen;
+    sp_globals.end_contour             = sp_end_contour_screen;
+       sp_globals.end_sub_char = sp_end_sub_char_out;
+    sp_globals.end_char                = sp_end_char_screen;
+       break;
+#endif
+
+#if INCL_OUTLINE
+case MODE_OUTLINE:                        /* Output mode 2 (Vector) */
+       sp_globals.init_out = sp_init_outline;
+    sp_globals.begin_char              = sp_begin_char_outline;
+    sp_globals.begin_sub_char  = sp_begin_sub_char_outline;
+       sp_globals.begin_contour        = sp_begin_contour_outline;
+    sp_globals.curve                   = sp_curve_outline;
+       sp_globals.line                 = sp_line_outline;
+    sp_globals.end_contour             = sp_end_contour_outline;
+       sp_globals.end_sub_char = sp_end_sub_char_outline;
+    sp_globals.end_char                = sp_end_char_outline;
+       break;
+#endif
+
+#if INCL_2D
+case MODE_2D:                        /* Output mode 3 */
+       sp_globals.init_out = sp_init_2d;
+    sp_globals.begin_char              = sp_begin_char_2d;
+    sp_globals.begin_sub_char  = sp_begin_sub_char_out;
+       sp_globals.begin_contour        = sp_begin_contour_2d;
+    sp_globals.curve                   = sp_curve_out;
+       sp_globals.line                 = sp_line_2d;
+    sp_globals.end_contour             = sp_end_contour_out;
+       sp_globals.end_sub_char = sp_end_sub_char_out;
+    sp_globals.end_char                = sp_end_char_2d;
+    break;
+#endif
+
+default:
+    report_error(8);           /* Unsupported mode requested */
+    return FALSE;
+    }
+
+       if (!fn_init_out(sp_globals.pspecs))
+               {
+               report_error(5);
+               return FALSE;
+               }
+               
+
+sp_globals.curves_out = sp_globals.pspecs->flags & CURVES_OUT;
+
+if (sp_globals.pspecs->flags & BOGUS_MODE) /* Linear transformation requested? */
+    {
+    sp_globals.tcb0.xtype = sp_globals.tcb0.ytype = 4;
+    }
+else                           /* Intelligent transformation requested? */
+    {
+#if INCL_RULES
+#else
+    report_error(7);           /* Rules requested; not supported */
+    return FALSE;
+#endif
+    }
+
+if ((sp_globals.pspecs->flags & SQUEEZE_LEFT) ||
+    (sp_globals.pspecs->flags & SQUEEZE_RIGHT) ||
+    (sp_globals.pspecs->flags & SQUEEZE_TOP) ||
+    (sp_globals.pspecs->flags & SQUEEZE_BOTTOM) )
+    {
+#if (INCL_SQUEEZING)
+#else
+     report_error(11);
+     return FALSE;
+#endif
+    }
+
+if ((sp_globals.pspecs->flags & CLIP_LEFT) ||
+    (sp_globals.pspecs->flags & CLIP_RIGHT) ||
+    (sp_globals.pspecs->flags & CLIP_TOP) ||
+    (sp_globals.pspecs->flags & CLIP_BOTTOM) )
+    {
+#if (INCL_CLIPPING)
+#else
+     report_error(11);
+     return FALSE;
+#endif
+    }
+
+sp_globals.specs_valid = TRUE;
+return TRUE;
+}
+
+\f
+
+#if INCL_MULTIDEV
+#if INCL_BLACK || INCL_SCREEN || INCL_2D
+FUNCTION boolean set_bitmap_device(bfuncs,size)
+GDECL
+bitmap_t *bfuncs;
+ufix16 size;
+{
+
+if (size != sizeof(sp_globals.bitmap_device))
+       return FALSE;
+
+sp_globals.bitmap_device = *bfuncs;
+sp_globals.bitmap_device_set = TRUE;
+}
+#endif
+
+#if INCL_OUTLINE
+FUNCTION boolean set_outline_device(ofuncs,size)
+GDECL
+outline_t *ofuncs;
+ufix16 size;
+{
+
+if (size != sizeof(sp_globals.outline_device))
+       return FALSE;
+
+sp_globals.outline_device = *ofuncs;
+sp_globals.outline_device_set = TRUE;
+}
+#endif
+#endif
+
+\f
+#ifdef old
+FUNCTION boolean sp_setup_consts(xmin, xmax, ymin, ymax)
+#else
+static FUNCTION boolean sp_setup_consts(xmin, xmax, ymin, ymax)
+#endif
+GDECL
+fix15   xmin;          /* Minimum X ORU value in font */
+fix15   xmax;          /* Maximum X ORU value in font */
+fix15   ymin;          /* Minimum Y ORU value in font */
+fix15   ymax;          /* Maximum Y ORU value in font */
+/*
+ * Sets the following constants used for fixed point arithmetic:
+ *      sp_globals.multshift    multipliers and products; range is 14 to 8
+ *      sp_globals.pixshift     pixels: range is 0 to 8
+ *      sp_globals.mpshift      shift from product to sub-pixels (sp_globals.multshift - sp_globals.pixshift)
+ *      sp_globals.multrnd      rounding for products
+ *      sp_globals.pixrnd       rounding for pixels
+ *      sp_globals.mprnd        rounding for sub-pixels
+ *      sp_globals.onepix       1 pixel in shifted pixel units
+ *      sp_globals.pixfix       mask to eliminate fractional bits of shifted pixels
+ *      sp_globals.depth_adj    curve splitting depth adjustment
+ * Returns FALSE if specs are out of range
+ */
+{
+fix31   mult;          /* Successive multiplier values */
+ufix32  num;           /* Numerator of largest multiplier value */
+ufix32  numcopy;       /* Copy of numerator */
+ufix32  denom;         /* Denominator of largest multiplier value */
+ufix32  denomcopy;     /* Copy of denominator */
+ufix32  pix_max;       /* Maximum pixel rounding error */
+fix31   xmult;         /* Coefficient of X oru value in transformation */
+fix31   ymult;         /* Coefficient of Y oru value in transformation */
+fix31   offset;        /* Constant in transformation */
+fix15   i;             /* Loop counter */
+fix15   x, y;          /* Successive corners of bounding box in ORUs */
+fix31   pixval;        /* Successive pixel values multiplied by orus per em */
+fix15   xx, yy;        /* Bounding box corner that produces max pixel value */
+
+/* Determine numerator and denominator of largest multiplier value */
+mult = sp_globals.pspecs->xxmult >> 16;
+if (mult < 0)
+    mult = -mult;
+num = mult;
+
+mult = sp_globals.pspecs->xymult >> 16;
+if (mult < 0)
+    mult = -mult;
+if (mult > num)
+    num = mult;
+
+mult = sp_globals.pspecs->yxmult >> 16;
+if (mult < 0)
+    mult = -mult;
+if (mult > num)
+    num = mult;
+
+mult = sp_globals.pspecs->yymult >> 16;
+if (mult < 0)
+    mult = -mult;
+if (mult > num)
+    num = mult;
+num++;                 /* Max absolute pixels per em (rounded up) */
+denom = (ufix32)sp_globals.orus_per_em;
+
+/* Set curve splitting depth adjustment to accomodate largest multiplier value */
+sp_globals.depth_adj = 0;   /* 0 = 0.5 pel, 1 = 0.13 pel, 2 = 0.04 pel accuracy */
+denomcopy = denom;
+/*  The following two occurances of a strange method of shifting twice by 1 
+    are intentional and should not be changed to a single shift by 2.  
+    It prevents MicroSoft C 5.1 from generating functions calls to do the shift.  
+    Worse, using the REENTRANT_ALLOC option in conjunction with the /AC compiler 
+    option, the function appears to be called incorrectly, causing depth_adj to always
+       be set to -7, causing very angular characters. */
+
+while ((num > denomcopy) && (sp_globals.depth_adj < 5)) /* > 1, 4, 16, ...  pixels per oru? */
+    {
+    denomcopy <<= 1;
+    denomcopy <<= 1;
+    sp_globals.depth_adj++; /* Add 1, 2, 3, ... to depth adjustment */
+    }
+numcopy = num << 2;
+while ((numcopy <= denom) && (sp_globals.depth_adj > -4))  /* <= 1/4, 1/16, 1/64 pix per oru? */
+    {
+    numcopy <<= 1;
+    numcopy <<= 1;
+    sp_globals.depth_adj--; /* Subtract 1, 2, 3, ... from depth adjustment */
+    }
+SHOW(sp_globals.depth_adj);
+
+/* Set multiplier shift to accomodate largest multiplier value */
+sp_globals.multshift = 14;            
+numcopy = num;
+while (numcopy >= denom)     /* More than 1, 2, 4, ... pix per oru? */
+    {
+    numcopy >>= 1;
+    sp_globals.multshift--; /* sp_globals.multshift is 13, 12, 11, ... */
+    }
+
+sp_globals.multrnd = ((fix31)1 << sp_globals.multshift) >> 1;
+SHOW(sp_globals.multshift);
+
+
+pix_max = (ufix32)( 0xffff & read_word_u(sp_globals.hdr2_org + FH_PIXMX));
+
+num = 0;
+xmult = ((sp_globals.pspecs->xxmult >> 16) + 1) >> 1;
+ymult = ((sp_globals.pspecs->xymult >> 16) + 1) >> 1;
+offset = ((sp_globals.pspecs->xoffset >> 16) + 1) >> 1;
+for (i = 0; i < 8; i++)
+    {
+    if (i == 4)
+        {
+        xmult = ((sp_globals.pspecs->yxmult >> 16) + 1) >> 1;
+        ymult = ((sp_globals.pspecs->yymult >> 16) + 1) >> 1;
+        offset = ((sp_globals.pspecs->yoffset >> 16) + 1) >> 1;
+        }
+    x = (i & BIT1)? xmin: xmax;
+    y = (i & BIT0)? ymin: ymax;
+    pixval = (fix31)x * xmult + (fix31)y * ymult + offset * denom;
+    if (pixval < 0)
+        pixval = -pixval;
+    if (pixval > num)
+        {
+        num = pixval;
+        xx = x;
+        yy = y;
+        }
+    }
+if (xx < 0)
+    xx = -xx;
+if (yy < 0)
+    yy = -yy;
+num += xx + yy + ((pix_max + 2) * denom); 
+                                  /* Allow (with 2:1 safety margin) for 1 pixel rounding errors in */
+                                  /* xmult, ymult and offset values, pix_max pixel expansion */
+                                  /* due to intelligent scaling, and */
+                                  /* 1 pixel rounding of overall character position */
+denom = denom << 14;              /* Note num is in units of half pixels times orus per em */
+
+sp_globals.pixshift = -1;
+while ((num <= denom) && (sp_globals.pixshift < 8))  /* Max pixels <= 32768, 16384, 8192, ... pixels? */
+    {
+    num <<= 1;
+    sp_globals.pixshift++;        /* sp_globals.pixshift = 0, 1, 2, ... */
+    }
+if (sp_globals.pixshift < 0)
+    return FALSE;
+
+SHOW(sp_globals.pixshift);
+sp_globals.poshift = 16 - sp_globals.pixshift;
+
+sp_globals.onepix = (fix15)1 << sp_globals.pixshift;
+sp_globals.pixrnd = sp_globals.onepix >> 1;
+sp_globals.pixfix = ~0 << sp_globals.pixshift;
+
+sp_globals.mpshift = sp_globals.multshift - sp_globals.pixshift;
+if (sp_globals.mpshift < 0)
+    return FALSE;
+sp_globals.mprnd = ((fix31)1 << sp_globals.mpshift) >> 1;
+
+return TRUE;
+}
+\f
+#ifdef old
+FUNCTION void sp_setup_tcb(ptcb)
+#else
+static FUNCTION void sp_setup_tcb(ptcb)
+#endif
+GDECL
+tcb_t GLOBALFAR *ptcb;           /* Pointer to transformation control bloxk */
+/* 
+ * Convert transformation coeffs to internal form 
+ */
+{
+
+ptcb->xxmult = sp_setup_mult(sp_globals.pspecs->xxmult);
+ptcb->xymult = sp_setup_mult(sp_globals.pspecs->xymult);
+ptcb->xoffset = sp_setup_offset(sp_globals.pspecs->xoffset);
+ptcb->yxmult = sp_setup_mult(sp_globals.pspecs->yxmult);
+ptcb->yymult = sp_setup_mult(sp_globals.pspecs->yymult);
+ptcb->yoffset = sp_setup_offset(sp_globals.pspecs->yoffset);
+
+SHOW(ptcb->xxmult);
+SHOW(ptcb->xymult);
+SHOW(ptcb->xoffset);
+SHOW(ptcb->yxmult);
+SHOW(ptcb->yymult);
+SHOW(ptcb->yoffset);
+
+type_tcb(ptcb); /* Classify transformation type */
+}
+\f
+FUNCTION static fix15 sp_setup_mult(input_mult)
+GDECL
+fix31   input_mult;    /* Multiplier in input format */
+/*
+ * Called by sp_setup_tcb() to convert multiplier in transformation
+ * matrix from external to internal form.
+ */
+{
+fix15   imshift;       /* Right shift to internal format */
+fix31   imdenom;       /* Divisor to internal format */
+fix31   imrnd;         /* Rounding for division operation */
+
+imshift = 15 - sp_globals.multshift;
+imdenom = (fix31)sp_globals.orus_per_em << imshift;
+imrnd = imdenom >> 1;
+
+input_mult >>= 1;
+if (input_mult >= 0)
+    return (fix15)((input_mult + imrnd) / imdenom);
+else
+    return -(fix15)((-input_mult + imrnd) / imdenom);
+}
+\f
+FUNCTION static fix31 sp_setup_offset(input_offset)
+GDECL
+fix31   input_offset;   /* Multiplier in input format */
+/*
+ * Called by sp_setup_tcb() to convert offset in transformation
+ * matrix from external to internal form.
+ */
+{
+fix15   imshift;       /* Right shift to internal format */
+fix31   imrnd;         /* Rounding for right shift operation */
+
+imshift = 15 - sp_globals.multshift;
+imrnd = ((fix31)1 << imshift) >> 1;
+
+return (((input_offset >> 1) + imrnd) >> imshift) + sp_globals.mprnd;
+}
+\f
+FUNCTION void type_tcb(ptcb)
+GDECL
+tcb_t GLOBALFAR *ptcb;           /* Pointer to transformation control bloxk */
+{
+fix15   x_trans_type;
+fix15   y_trans_type;
+fix15   xx_mult;
+fix15   xy_mult;
+fix15   yx_mult;
+fix15   yy_mult;
+fix15   h_pos;
+fix15   v_pos;
+fix15   x_ppo;
+fix15   y_ppo;
+fix15   x_pos;
+fix15   y_pos;
+
+/* check for mirror image transformations */
+xx_mult = ptcb->xxmult;
+xy_mult = ptcb->xymult;
+yx_mult = ptcb->yxmult;
+yy_mult = ptcb->yymult;
+
+ptcb->mirror = ((((fix31)xx_mult*(fix31)yy_mult)-
+                     ((fix31)xy_mult*(fix31)yx_mult)) < 0) ? -1 : 1;
+
+if (sp_globals.pspecs->flags & BOGUS_MODE) /* Linear transformation requested? */
+    {
+    ptcb->xtype = 4;
+    ptcb->ytype = 4;
+
+    ptcb->xppo = 0;
+    ptcb->yppo = 0;
+    ptcb->xpos = 0;
+    ptcb->ypos = 0;
+    }
+else                            /* Intelligent tranformation requested? */
+    {
+    h_pos = ((ptcb->xoffset >> sp_globals.mpshift) + sp_globals.pixrnd) & sp_globals.pixfix;
+    v_pos = ((ptcb->yoffset >> sp_globals.mpshift) + sp_globals.pixrnd) & sp_globals.pixfix;
+
+    x_trans_type = 4;
+    x_ppo = 0;
+    x_pos = 0;
+
+    y_trans_type = 4;
+    y_ppo = 0;
+    y_pos = 0;
+
+    if (xy_mult == 0)
+        {
+        if (xx_mult >= 0)
+            {
+            x_trans_type = 0;   /* X pix is function of X orus only */
+            x_ppo = xx_mult;
+            x_pos = h_pos;
+            }
+        else 
+            {
+            x_trans_type = 1;   /* X pix is function of -X orus only */
+            x_ppo = -xx_mult;
+            x_pos = -h_pos;
+            }
+        }
+
+    else if (xx_mult == 0)
+        {
+        if (xy_mult >= 0)
+            {
+            x_trans_type = 2;   /* X pix is function of Y orus only */
+            y_ppo = xy_mult;
+            y_pos = h_pos;
+            }
+        else 
+            {
+            x_trans_type = 3;   /* X pix is function of -Y orus only */
+            y_ppo = -xy_mult;
+            y_pos = -h_pos;
+            }
+        }
+
+    if (yx_mult == 0)
+        {
+        if (yy_mult >= 0)
+            {
+            y_trans_type = 0;   /* Y pix is function of Y orus only */
+            y_ppo = yy_mult;
+            y_pos = v_pos;
+            }
+        else 
+            {
+            y_trans_type = 1;   /* Y pix is function of -Y orus only */
+            y_ppo = -yy_mult;
+            y_pos = -v_pos;
+            }
+        }
+    else if (yy_mult == 0)
+        {
+        if (yx_mult >= 0)
+            {
+            y_trans_type = 2;   /* Y pix is function of X orus only */
+            x_ppo = yx_mult;
+            x_pos = v_pos;
+            }
+        else 
+            {
+            y_trans_type = 3;   /* Y pix is function of -X orus only */
+            x_ppo = -yx_mult;
+            x_pos = -v_pos;
+            }
+        }
+
+    ptcb->xtype = x_trans_type;
+    ptcb->ytype = y_trans_type;
+
+    ptcb->xppo = x_ppo;
+    ptcb->yppo = y_ppo;
+    ptcb->xpos = x_pos;
+    ptcb->ypos = y_pos;
+    }
+
+sp_globals.normal = (ptcb->xtype != 4) && (ptcb->ytype != 4);
+
+ptcb->xmode = 4;
+ptcb->ymode = 4;   
+
+SHOW(ptcb->xtype);
+SHOW(ptcb->ytype);
+SHOW(ptcb->xppo);
+SHOW(ptcb->yppo);
+SHOW(ptcb->xpos);
+SHOW(ptcb->ypos);
+}
+\f
+FUNCTION fix31 read_long(pointer)
+GDECL
+ufix8 FONTFAR *pointer;    /* Pointer to first byte of encrypted 3-byte integer */
+/*
+ * Reads a 3-byte encrypted integer from the byte string starting at 
+ * the specified point.
+ * Returns the decrypted value read as a signed integer.
+ */
+{
+fix31 tmpfix31;
+
+tmpfix31 = (fix31)((*pointer++) ^ sp_globals.key4) << 8;            /* Read middle byte */
+tmpfix31 += (fix31)(*pointer++) << 16;                              /* Read most significant byte */
+tmpfix31 += (fix31)((*pointer) ^ sp_globals.key6);                    /* Read least significant byte */
+return tmpfix31;
+}
+\f
+FUNCTION fix15 read_word_u(pointer)
+GDECL
+ufix8 FONTFAR *pointer;    /* Pointer to first byte of unencrypted 2-byte integer */
+/*
+ * Reads a 2-byte unencrypted integer from the byte string starting at 
+ * the specified point.
+ * Returns the decrypted value read as a signed integer.
+ */
+{
+fix15 tmpfix15;
+
+tmpfix15 = (fix15)(*pointer++) << 8;                                /* Read most significant byte */
+tmpfix15 += (fix15)(*pointer);                                        /* Add least significant byte */
+return tmpfix15;
+}
+
+
diff --git a/Xserver/lib/font/Speedo/set_trns.c b/Xserver/lib/font/Speedo/set_trns.c
new file mode 100644 (file)
index 0000000..c3378cb
--- /dev/null
@@ -0,0 +1,1329 @@
+/* $XConsortium: set_trns.c,v 1.6 94/02/10 11:05:59 gildea Exp $ */
+
+/*
+
+Copyright 1989-1991, Bitstream Inc., Cambridge, MA.
+You are hereby granted permission under all Bitstream propriety rights to
+use, copy, modify, sublicense, sell, and redistribute the Bitstream Speedo
+software and the Bitstream Charter outline font for any purpose and without
+restrictions; provided, that this notice is left intact on all copies of such
+software or font and that Bitstream's trademark is acknowledged as shown below
+on all unmodified copies of such font.
+
+BITSTREAM CHARTER is a registered trademark of Bitstream Inc.
+
+
+BITSTREAM INC. DISCLAIMS ANY AND ALL WARRANTIES, EXPRESS OR IMPLIED, INCLUDING
+WITHOUT LIMITATION THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+PARTICULAR PURPOSE.  BITSTREAM SHALL NOT BE LIABLE FOR ANY DIRECT OR INDIRECT
+DAMAGES, INCLUDING BUT NOT LIMITED TO LOST PROFITS, LOST DATA, OR ANY OTHER
+INCIDENTAL OR CONSEQUENTIAL DAMAGES, ARISING OUT OF OR IN ANY WAY CONNECTED
+WITH THE SPEEDO SOFTWARE OR THE BITSTREAM CHARTER OUTLINE FONT.
+
+*/
+
+
+
+/*************************** S E T _ T R N S . C *****************************
+ *                                                                           *
+ * This module is called from do_char.c to set up the intelligent            *
+ * transformation for one character (or sub-character of a composite         *
+ * character.
+ *                                                                           *
+ ****************************************************************************/
+
+
+#include "spdo_prv.h"               /* General definitions for Speedo   */
+
+#define   DEBUG      0
+
+#if DEBUG
+#include <stdio.h>
+#define SHOW(X) printf("X = %d\n", X)
+#else
+#define SHOW(X)
+#endif
+/***** LOCAL MACROS     *****/
+
+#define SQUEEZE_X_ORU(A,B,C) ((((fix31)A * (fix31)B) + C) >> 16)
+#define ABS(A) ((A < 0)? -A:A) /* absolute value */
+#define IMPORT_FACTOR    \
+       shift = 16;\
+       while (*x_factor > (0x7fffffffL / (isw_scale >> (16 - shift))))\
+               shift--;\
+       *x_factor = (*x_factor * (isw_scale>>(16-shift))) >> shift;
+
+/***** GLOBAL VARIABLES *****/
+
+/*****  GLOBAL FUNCTIONS *****/
+
+/***** EXTERNAL VARIABLES *****/
+
+/***** EXTERNAL FUNCTIONS *****/
+
+/***** STATIC VARIABLES *****/
+
+/***** STATIC FUNCTIONS *****/
+
+#if PROTOS_AVAIL
+static void sp_constr_update(PROTO_DECL1);
+static ufix8 FONTFAR *sp_setup_pix_table(PROTO_DECL2 ufix8 FONTFAR *pointer,boolean short_form,fix15 no_X_ctrl_zones,fix15 no_Y_ctrl_zones);
+static ufix8 FONTFAR *sp_setup_int_table(PROTO_DECL2 ufix8 FONTFAR *pointer,fix15 no_X_int_zones,fix15 no_Y_int_zones);
+#else
+static void sp_constr_update();     /* Update constraint table */
+static ufix8 FONTFAR *sp_setup_pix_table();   /* Read control zone table */
+static ufix8 FONTFAR *sp_setup_int_table();   /* Read interpolation zone table */
+#endif
+
+\f
+FUNCTION void init_tcb()
+GDECL
+/*
+ * Called by sp_make_char() and make_comp_char() to initialize the current
+ * transformation control block to the top level transformation.
+ */
+{
+sp_globals.tcb = sp_globals.tcb0;
+}
+\f
+FUNCTION void scale_tcb(ptcb, x_pos, y_pos, x_scale, y_scale)
+GDECL
+tcb_t GLOBALFAR *ptcb;    /* Transformation control block */
+fix15  x_pos;   /* X position (outline res units) */
+fix15  y_pos;   /* Y position (outline res units) */
+fix15  x_scale; /* X scale factor * ONE_SCALE */
+fix15  y_scale; /* Y scale factor * ONE_SCALE */
+/*
+ * Called by make_comp_char() to apply position and scale for each of the
+ * components of a compound character.
+ */
+{     
+fix15 xx_mult = ptcb->xxmult;
+fix15 xy_mult = ptcb->xymult;
+fix31 x_offset = ptcb->xoffset;
+fix15 yx_mult = ptcb->yxmult;
+fix15 yy_mult = ptcb->yymult;
+fix31 y_offset = ptcb->yoffset;
+
+ptcb->xxmult = TRANS(xx_mult, x_scale, (fix31)SCALE_RND, SCALE_SHIFT);
+ptcb->xymult = TRANS(xy_mult, y_scale, (fix31)SCALE_RND, SCALE_SHIFT);
+ptcb->xoffset = MULT16(xx_mult, x_pos) + MULT16(xy_mult, y_pos) + x_offset;
+ptcb->yxmult = TRANS(yx_mult, x_scale, (fix31)SCALE_RND, SCALE_SHIFT);
+ptcb->yymult = TRANS(yy_mult, y_scale, (fix31)SCALE_RND, SCALE_SHIFT);
+ptcb->yoffset = MULT16(yx_mult, x_pos) + MULT16(yy_mult, y_pos) + y_offset;
+
+type_tcb(ptcb); /* Reclassify transformation types */
+}
+\f
+FUNCTION ufix8 FONTFAR *skip_interpolation_table(pointer,format)
+GDECL
+ufix8 FONTFAR *pointer;  /* Pointer to next byte in char data */
+ufix8    format;    /* Character format byte */
+{
+fix15 i,n;
+ufix8 intsize[9];
+
+intsize[0] = 1;
+intsize[1] = 2;
+intsize[2] = 3;
+intsize[3] = 1;
+intsize[4] = 2;
+intsize[5] = 1;
+intsize[6] = 2;
+intsize[7] = 0;
+intsize[8] = 0;
+
+n = ((format & BIT6)? (fix15)NEXT_BYTE(pointer): 0) +
+    ((format & BIT7)? (fix15)NEXT_BYTE(pointer): 0);
+for (i = 0; i < n; i++)          /* For each entry in int table ... */
+    {
+    format = NEXT_BYTE(pointer); /* Read format byte */
+    if (format & BIT7)           /* Short Start/End point spec? */
+        {
+        pointer++;               /* Skip Start/End point byte */
+        }
+    else
+        {
+        pointer += intsize[format & 0x7];  /* Skip Start point spec */
+        pointer += intsize[(format >> 3) & 0x7]; /* Skip End point spec */
+        }
+    }
+return pointer;
+}
+FUNCTION ufix8 FONTFAR *skip_control_zone(pointer,format)
+GDECL
+ufix8 FONTFAR *pointer;  /* Pointer to next byte in char data */
+ufix8    format;    /* Character format byte */
+{
+fix15    i,n;
+ufix16   tmpufix16;
+fix15    constr;
+
+n = sp_globals.no_X_orus + sp_globals.no_Y_orus - 2;
+for (i = 0; i < n; i++)          /* For each entry in control table ... */
+    {
+    if (format & BIT4)
+        pointer++;               /* Skip short form From/To fields */
+    else
+        pointer += 2;            /* Skip FROM and TO fields */
+    /* skip constraints field */
+    constr = NEXT_BYTES (pointer, tmpufix16);
+
+    }
+return pointer;
+}
+\f
+#if INCL_RULES
+#else
+FUNCTION ufix8 FONTFAR *plaid_tcb(pointer, format)
+GDECL
+ufix8 FONTFAR *pointer;  /* Pointer to next byte in char data */
+ufix8    format;    /* Character format byte */
+/* 
+ * Called by make_simp_char() and make_comp_char() to set up the controlled
+ * coordinate table and skip all other intelligent scaling rules embedded
+ * in the character data.
+ * Updates pointer to first byte after plaid data.
+ * This is used only if intelligent scaling is not supported in the
+ * configuration definitions.
+ */
+{
+fix15  i, n;
+
+
+
+sp_globals.no_X_orus = (format & BIT2)?
+    (fix15)NEXT_BYTE(pointer):
+    0;
+sp_globals.no_Y_orus = (format & BIT3)?
+    (fix15)NEXT_BYTE(pointer):
+    0;
+pointer = read_oru_table(pointer);        /* Updates no_X/Y/orus */
+sp_globals.Y_edge_org = sp_globals.no_X_orus;
+
+/* Skip over control zone table */
+pointer = skip_control_zone(pointer,format);
+
+/* Skip over interpolation table */
+pointer = skip_interpolation_table(pointer,format);
+return pointer;
+}
+#endif
+\f
+#if INCL_RULES
+FUNCTION ufix8 FONTFAR *plaid_tcb(pointer, format)
+GDECL
+ufix8 FONTFAR *pointer;  /* Pointer to next byte in char data */
+ufix8    format;    /* Character format byte */
+/* 
+ * Called by make_simp_char() and make_comp_char() to set up the controlled
+ * coordinate table and process all intelligent scaling rules embedded
+ * in the character data.
+ * Updates pointer to first byte after plaid data.
+ * This is used only if intelligent scaling is enabled in the
+ * configuration definitions.
+ */
+{
+fix15 no_X_ctrl_zones;
+fix15 no_Y_ctrl_zones;
+fix15 no_X_int_zones;
+fix15 no_Y_int_zones;
+
+#if INCL_PLAID_OUT         /* Plaid data monitoring included? */
+begin_plaid_data();
+#endif
+
+sp_constr_update();           /* Update constraint table if required */
+
+sp_globals.no_X_orus = (format & BIT2)?  
+    (fix15)NEXT_BYTE(pointer):
+    0;
+sp_globals.no_Y_orus = (format & BIT3)?
+    (fix15)NEXT_BYTE(pointer):
+    0;
+pointer = read_oru_table(pointer);  /* Updates no_X/Y/orus to include zero values */
+sp_globals.Y_edge_org = sp_globals.no_X_orus;                                                  
+if (sp_globals.no_X_orus > 1)         /* 2 or more controlled X coordinates? */
+    sp_globals.tcb.xmode = sp_globals.tcb.xtype; /* Enable intelligent scaling in X */
+
+if (sp_globals.no_Y_orus > 1)         /* 2 or more controlled Y coordinates? */
+    sp_globals.tcb.ymode = sp_globals.tcb.ytype; /* Enable intelligent scaling in Y */
+
+no_X_ctrl_zones = sp_globals.no_X_orus - 1;
+no_Y_ctrl_zones = sp_globals.no_Y_orus - 1;
+pointer = sp_setup_pix_table(pointer, (boolean)(format & BIT4), 
+    no_X_ctrl_zones, no_Y_ctrl_zones);
+
+no_X_int_zones = (format & BIT6)?
+    (fix15)NEXT_BYTE(pointer):
+    0;
+no_Y_int_zones = (format & BIT7)?
+    (fix15)NEXT_BYTE(pointer):
+    0;
+sp_globals.Y_int_org = no_X_int_zones;
+pointer = sp_setup_int_table(pointer, no_X_int_zones, no_Y_int_zones);
+
+#if INCL_PLAID_OUT         /* Plaid data monitoring included? */
+end_plaid_data();
+#endif
+
+return pointer;
+}
+#endif
+\f
+#if INCL_RULES
+FUNCTION static void sp_constr_update()
+GDECL
+/*
+ * Called by plaid_tcb() to update the constraint table for the current
+ * transformation.
+ * This is always carried out whenever a character is generated following
+ * a change of font or scale factor or after initialization.     
+ */
+{
+fix31    ppo;
+fix15    xppo;
+fix15    yppo;
+ufix8 FONTFAR  *pointer;
+fix15    no_X_constr;
+fix15    no_Y_constr;
+fix15    i, j, k, l, n;
+fix15    ppm;
+ufix8    format;
+ufix8    format1;
+fix15    limit;
+ufix16   constr_org;
+fix15    constr_nr;
+fix15    size;
+fix31    off;
+fix15    min;     
+fix15    orus;
+fix15    pix; 
+ufix16   tmpufix16;  /* in extended mode, macro uses secnd term */
+
+if (sp_globals.constr.data_valid &&         /* Constr table already done and ... */
+    (sp_globals.tcb.xppo == sp_globals.constr.xppo) && /* ... X pix per oru unchanged and ... */
+    (sp_globals.tcb.yppo == sp_globals.constr.yppo))   /* ... Y pix per oru unchanged? */
+    {
+    return;                      /* No need to update constraint table */
+    }
+
+sp_globals.constr.xppo = xppo = sp_globals.tcb.xppo;   /* Update X pixels per oru indicator */
+sp_globals.constr.yppo = yppo = sp_globals.tcb.yppo;   /* Update Y pixels per oru indicator */
+sp_globals.constr.data_valid = TRUE;        /* Mark constraint table valid */
+
+pointer = sp_globals.constr.org;            /* Point to first byte of constraint data */
+no_X_constr = NEXT_BYTES(pointer, tmpufix16); /* Read nmbr of X constraints */
+no_Y_constr = NEXT_BYTES(pointer, tmpufix16); /* Read nmbr of Y constraints */
+
+i = 0;
+constr_org = 0;
+n = no_X_constr;
+ppo = xppo;
+for (j = 0; ; j++)
+    {
+    sp_globals.c_act[i] = FALSE;            /* Flag constraint 0 not active */
+    sp_globals.c_pix[i++] = 0;              /* Constraint 0 implies no minimum */
+    sp_globals.c_act[i] = FALSE;            /* Flag constraint 1 not active */
+    sp_globals.c_pix[i++] = sp_globals.onepix; /* Constraint 1 implies min 1 pixel*/
+    ppm = (ppo * (fix31)sp_globals.orus_per_em) >> sp_globals.multshift;
+    for (k = 0; k < n; k++)
+        {
+        format = NEXT_BYTE(pointer);        /* Read format byte */
+        limit = (fix15)NEXT_BYTE(pointer);  /* Read limit field */
+        sp_globals.c_act[i] = 
+            ((ppm < limit) || (limit == 255)) &&
+            sp_globals.constr.active;
+        if (sp_globals.c_act[i])            /* Constraint active? */
+            {
+            if ((format & BIT1) &&          /* Constraint specified and ... */
+                (constr_nr = constr_org +
+                    ((format & BIT0)?       /* Read unsigned constraint value */
+                    NEXT_WORD(pointer): 
+                    (fix15)NEXT_BYTE(pointer)),
+                 sp_globals.c_act[constr_nr])) /* ... and specified constraint active? */ 
+                {
+                pix = sp_globals.c_pix[constr_nr]; /* Use constrained pixel value */
+                format1 = format;
+                for (l = 2; l > 0; l--)     /* Skip 2 arguments */
+                    {
+                    format1 >>= 2;
+                    if (size = format1 & 0x03)
+                        pointer += size - 1;
+                    }
+                }
+            else                 /* Constraint absent or inactive? */
+                {
+                orus = (format & BIT2)? /* Read unsigned oru value */
+                    NEXT_WORD(pointer):
+                    (fix15)NEXT_BYTE(pointer);
+
+                if (format & BIT5) /* Specified offset value? */
+                    {
+                    off = (fix31)((format & BIT4)? /* Read offset value */
+                        NEXT_WORD(pointer):
+                        (fix7)NEXT_BYTE(pointer));
+                    off = (off << (sp_globals.multshift - 6)) + sp_globals.multrnd;
+                    }
+                else             /* Unspecified (zero) offset value? */
+                    {
+                    off = sp_globals.multrnd;
+                    }
+
+                pix = (fix15)(((fix31)orus * ppo + off) / (1 << sp_globals.mpshift)) & sp_globals.pixfix;
+                }
+            }
+        else                     /* Constraint inactive? */
+            {
+            format1 = format;
+            for (l = 3; l > 0; l--) /* Skip over 3 arguments */
+                {
+                if (size = format1 & 0x03)
+                    pointer += size - 1;
+                format1 >>= 2;
+                }
+            pix = 0;
+            }
+
+        if (format & 0xc0) /* Specified minimum value? */
+            {
+            min = (format & BIT7)? /* Read unsigned minimum value */
+                (fix15)NEXT_BYTE(pointer) << sp_globals.pixshift:
+                sp_globals.onepix;
+            }
+        else             /* Unspecified (zero) minimum value? */
+            {
+            min = 0;
+            }
+
+        sp_globals.c_pix[i] = (pix < min)? min: pix;
+        i++;
+        }
+    if (j) break;                /* Finished if second time around loop */
+    constr_org = sp_globals.Y_constr_org = i;
+    n = no_Y_constr;
+    ppo = yppo;
+    }
+
+#if DEBUG
+printf("\nCONSTRAINT TABLE\n");
+n = no_X_constr + 2;
+for (i = 0; i < n; i++)
+    {
+    printf("%3d   ", i);
+    if (sp_globals.c_act[i])
+        {
+        printf("T ");
+        }
+    else
+        {
+        printf("F ");
+        }
+    printf("%5.1f\n", ((real)sp_globals.c_pix[i] / (real)sp_globals.onepix));
+    }
+printf("--------------\n");
+n = no_Y_constr + 2;
+for (i = 0; i < n; i++)
+    {
+    j = i + sp_globals.Y_constr_org;
+    printf("%3d   ", i);
+    if (sp_globals.c_act[j])
+        {
+        printf("T ");
+        }
+    else
+        {
+        printf("F ");
+        }
+    printf("%5.1f\n", ((real)sp_globals.c_pix[j] / (real)sp_globals.onepix));
+    }
+#endif
+
+}
+#endif
+\f
+FUNCTION ufix8 FONTFAR *read_oru_table(pointer)
+GDECL
+ufix8 FONTFAR *pointer;   /* Pointer to first byte in controlled coord table */
+/*
+ * Called by plaid_tcb() to read the controlled coordinate table from the
+ * character data in the font. 
+ * Updates the pointer to the byte following the controlled coordinate
+ * data.
+ */
+{
+fix15    i, j, k, n;
+boolean  zero_not_in;
+boolean  zero_added;
+fix15    oru;
+
+#if INCL_RULES
+fix15    pos;
+#endif
+
+i = 0;
+n = sp_globals.no_X_orus;
+#if INCL_RULES
+pos = sp_globals.tcb.xpos;
+#endif
+for (j = 0; ; j++)
+    {
+    zero_not_in = TRUE;
+    zero_added = FALSE;
+    for (k = 0; k < n; k++)
+        {
+        oru = NEXT_WORD(pointer);
+        if (zero_not_in && (oru >= 0)) /* First positive oru value? */
+            {
+#if INCL_RULES
+            sp_plaid.pix[i] = pos;        /* Insert position in pix array */
+#endif
+            if (oru != 0)        /* Zero oru value omitted? */
+                {
+                sp_plaid.orus[i++] = 0;   /* Insert zero value in oru array */
+                zero_added = TRUE; /* Remember to increment size of array */
+                }
+            zero_not_in = FALSE; /* Inhibit further testing for zero ins */
+            }
+        sp_plaid.orus[i++] = oru;         /* Add specified oru value to array */
+        }
+    if (zero_not_in)             /* All specified oru values negative? */
+        {
+#if INCL_RULES
+        sp_plaid.pix[i] = pos;            /* Insert position in pix array */
+#endif
+        sp_plaid.orus[i++] = 0;           /* Add zero oru value */
+        zero_added = TRUE;       /* Remember to increment size of array */
+        }
+    if (j)                       /* Both X and Y orus read? */
+        break;
+    if (zero_added)                                 
+        sp_globals.no_X_orus++;             /* Increment X array size */
+    n = sp_globals.no_Y_orus;               /* Prepare to read Y oru values */
+#if INCL_RULES
+    pos = sp_globals.tcb.ypos;
+#endif
+    }
+if (zero_added)                  /* Zero Y oru value added to array? */
+    sp_globals.no_Y_orus++;                 /* Increment Y array size */
+
+#if DEBUG
+printf("\nX ORUS\n");
+n = sp_globals.no_X_orus;
+for (i = 0; i < n; i++)
+    {
+    printf("%2d %4d\n", i, sp_plaid.orus[i]);
+    }
+printf("\nY ORUS\n");
+n = sp_globals.no_Y_orus;
+for (i = 0; i < n; i++)
+    {
+    printf("%2d %4d\n", i, sp_plaid.orus[i + sp_globals.no_X_orus]);
+    }
+#endif
+
+return pointer;             /* Update pointer */
+}
+#if INCL_SQUEEZING || INCL_ISW
+FUNCTION static void calculate_x_pix(start_edge, end_edge, constr_nr,
+        x_scale, x_offset, ppo, setwidth_pix)
+GDECL
+ufix8 start_edge, end_edge;
+ufix16 constr_nr;
+fix31 x_scale;
+fix31 x_offset;
+fix31 ppo;
+fix15    setwidth_pix;
+/*
+ * Called by sp_setup_pix_table() when X squeezing is necessary
+ * to insert the correct edge in the global pix array
+ */
+{
+fix15 zone_pix;
+fix15 start_oru, end_oru;
+
+/* compute scaled oru coordinates */
+start_oru= (fix15)(SQUEEZE_X_ORU(sp_plaid.orus[start_edge], x_scale, x_offset));
+end_oru   = (fix15)(SQUEEZE_X_ORU(sp_plaid.orus[end_edge], x_scale, x_offset));
+
+if (!sp_globals.c_act[constr_nr]) /* constraint inactive */
+    {
+    /* calculate zone width */
+    zone_pix = (fix15)(((((fix31)end_oru - (fix31)start_oru) * ppo) /
+       (1<<sp_globals.mpshift)) + sp_globals.pixrnd) & sp_globals.pixfix;
+    /* check for overflow */
+    if (((end_oru-start_oru) > 0) && (zone_pix < 0))
+       zone_pix = 0x7ffff;
+    /* check for minimum */
+    if ((ABS(zone_pix)) >= sp_globals.c_pix[constr_nr])
+       goto Lx;
+    }
+/* use the zone size from the constr table - scale it */
+zone_pix = (fix15)(((SQUEEZE_MULT(x_scale,sp_globals.c_pix[constr_nr]))
+            + sp_globals.pixrnd) & sp_globals.pixfix);
+
+/* look for overflow */
+if ((sp_globals.c_pix[constr_nr] > 0) && (zone_pix < 0))
+       zone_pix = 0x7fff;
+
+if (start_edge > end_edge)
+    {
+    zone_pix = -zone_pix;
+    }
+Lx:
+/* assign pixel value to global pix array */
+sp_plaid.pix[end_edge]=sp_plaid.pix[start_edge] + zone_pix;
+
+/* check for overflow */
+if (((sp_plaid.pix[start_edge] >0) && (zone_pix >0)) &&
+    (sp_plaid.pix[end_edge] < 0))
+       sp_plaid.pix[end_edge] = 0x7fff; /* set it to the max */
+
+/* be sure to be in the setwidth !*/
+#if INCL_ISW
+if (!sp_globals.import_setwidth_act) /* only check left edge if not isw only */
+#endif
+if ((sp_globals.pspecs->flags & SQUEEZE_LEFT) && (sp_plaid.pix[end_edge] < 0))
+    sp_plaid.pix[end_edge] = 0;
+if ((sp_globals.pspecs->flags & SQUEEZE_RIGHT) && 
+    (sp_plaid.pix[end_edge] > setwidth_pix))
+    sp_plaid.pix[end_edge] = setwidth_pix;
+
+}
+#endif
+\f
+#if INCL_SQUEEZING
+FUNCTION static void calculate_y_pix(start_edge, end_edge,constr_nr,
+               top_scale, bottom_scale,ppo,em_top_pix, em_bot_pix)
+GDECL
+ufix8 start_edge, end_edge;
+ufix16 constr_nr;
+fix31 top_scale, bottom_scale; 
+fix31 ppo;
+fix15 em_top_pix, em_bot_pix;
+
+/*
+ * Called by sp_setup_pix_table() when Y squeezing is necessary
+ * to insert the correct edge in the global pix array
+ */
+{
+fix15 zone_pix;
+fix15 start_oru, end_oru;
+fix31 zone_width, above_base, below_base;
+
+/* check whether edge is above or below the baseline                */
+/* and apply appropriate scale factor to get scaled oru coordinates */
+if (sp_plaid.orus[start_edge] < 0)
+    start_oru =(fix15)(SQUEEZE_MULT(sp_plaid.orus[start_edge], bottom_scale));
+else
+    start_oru =(fix15)(SQUEEZE_MULT(sp_plaid.orus[start_edge], top_scale));
+
+if (sp_plaid.orus[end_edge] < 0)
+    end_oru =(fix15)(SQUEEZE_MULT(sp_plaid.orus[end_edge], bottom_scale));
+else
+    end_oru =(fix15)(SQUEEZE_MULT(sp_plaid.orus[end_edge], top_scale));
+
+if (!sp_globals.c_act[constr_nr])   /* Constraint inactive? */
+   {
+   /* calculate zone width */
+    zone_pix = (fix15)(((((fix31)end_oru - (fix31)start_oru) * ppo)
+               >> sp_globals.mpshift)+ sp_globals.pixrnd) & sp_globals.pixfix;
+   /* check minimum */
+    if ((ABS(zone_pix)) >= sp_globals.c_pix[constr_nr])
+                    goto Ly;
+    }
+
+/* Use zone size from constr table */
+if ((end_oru >= 0) && (start_oru >=0))
+    /* all above baseline */
+    zone_pix = (fix15)(SQUEEZE_MULT(top_scale, sp_globals.c_pix[constr_nr]));
+else if ((end_oru <= 0) && (start_oru <=0))
+    /* all below baseline */
+    zone_pix = (fix15)(SQUEEZE_MULT(bottom_scale, sp_globals.c_pix[constr_nr]));
+else
+    {
+    /* mixture */
+    if (start_oru > 0)
+        {
+       zone_width = start_oru - end_oru;
+        /* get % above baseline in 16.16 fixed point */
+        above_base = (((fix31)start_oru) << 16) /
+                    ((fix31)zone_width) ;
+        /* get % below baseline in 16.16 fixed point */
+        below_base = (((fix31)-end_oru) << 16) /
+                    ((fix31)zone_width) ;
+       }
+    else
+        {
+        zone_width = end_oru - start_oru;
+        /* get % above baseline in 16.16 fixed point */
+        above_base = (((fix31)-start_oru) << 16) /
+                    ((fix31)zone_width) ;
+        /* get % below baseline in 16.16 fixed point */
+        below_base = (((fix31)end_oru) << 16) /
+                    ((fix31)zone_width) ;
+       }
+    /* % above baseline * total zone * top_scale +  */
+    /* % below baseline * total zone * bottom_scale */
+    zone_pix = ((((above_base * (fix31)sp_globals.c_pix[constr_nr]) >> 16) *
+                top_scale) +
+              (((below_base * (fix31)sp_globals.c_pix[constr_nr]) >> 16) *
+               bottom_scale)) >> 16;
+    }
+
+/* make this zone pix fall on a pixel boundary */
+zone_pix = (zone_pix + sp_globals.pixrnd) & sp_globals.pixfix;
+
+/* if minimum is in effect make the zone one pixel */
+if ((sp_globals.c_pix[constr_nr] != 0) && (zone_pix < sp_globals.onepix)) 
+    zone_pix = sp_globals.onepix; 
+    
+if (start_edge > end_edge) 
+       {
+        zone_pix = -zone_pix; /* Use negatve zone size */
+        }
+Ly:
+/* assign global pix value */
+sp_plaid.pix[end_edge] = sp_plaid.pix[start_edge] + zone_pix; /* Insert end pixels */
+
+/* make sure it is in the EM !*/
+if ((sp_globals.pspecs->flags & SQUEEZE_TOP) && 
+    (sp_plaid.pix[end_edge] > em_top_pix))
+    sp_plaid.pix[end_edge] = em_top_pix;
+if ((sp_globals.pspecs->flags & SQUEEZE_BOTTOM) &&
+    (sp_plaid.pix[end_edge] < em_bot_pix))
+    sp_plaid.pix[end_edge] = em_bot_pix;
+}
+\f
+FUNCTION boolean calculate_x_scale(x_factor, x_offset, no_X_ctrl_zones)
+GDECL
+fix31 *x_factor;
+fix31 *x_offset;
+fix15   no_X_ctrl_zones; /* Number of X control zones */
+/*
+ * Called by sp_setup_pix_table() when squeezing is included
+ * to determine whether X scaling is necessary.  If it is, the
+ * scale factor and offset are computed.  This function returns
+ * a boolean value TRUE = X squeezind is necessary, FALSE = no
+ * X squeezing is necessary.
+ */
+{
+boolean squeeze_left, squeeze_right;
+boolean out_on_right, out_on_left;
+fix15 bbox_width,set_width;
+fix15 bbox_xmin, bbox_xmax;
+fix15 x_offset_pix;
+fix15 i;
+#if INCL_ISW
+fix31 isw_scale;
+fix15 shift;
+#endif
+
+
+/* set up some flags and common calculations */
+squeeze_left = (sp_globals.pspecs->flags & SQUEEZE_LEFT)? TRUE:FALSE;
+squeeze_right = (sp_globals.pspecs->flags & SQUEEZE_RIGHT)? TRUE:FALSE;
+bbox_xmin = sp_globals.bbox_xmin_orus;
+bbox_xmax = sp_globals.bbox_xmax_orus;
+set_width = sp_globals.setwidth_orus;
+
+if (bbox_xmax > set_width)
+    out_on_right = TRUE;
+else
+    out_on_right = FALSE;
+if (bbox_xmin < 0)
+    out_on_left = TRUE;
+else
+    out_on_left = FALSE;
+bbox_width =bbox_xmax - bbox_xmin;
+
+/*
+ * don't need X squeezing if:
+ *     - X squeezing not enabled
+ *     - bbox doesn't violate on left or right
+ *     - left squeezing only is enabled and char isn't out on left
+ *     - right squeezing only is enabled and char isn't out on right
+ */
+
+if ((!squeeze_left && !squeeze_right) || 
+   (!out_on_right && !out_on_left) ||     
+   (squeeze_left && !squeeze_right && !out_on_left) ||
+   (squeeze_right && !squeeze_left && !out_on_right))
+    return FALSE;
+
+#if INCL_ISW
+if (sp_globals.import_setwidth_act)
+    {
+    /* if both isw and squeezing is going on - let the imported */
+    /* setwidth factor be factored in with the squeeze          */
+    isw_scale = compute_isw_scale();
+    /*sp_globals.setwidth_orus = sp_globals.imported_width;*/
+    }
+else
+    isw_scale = 0x10000L; /* 1 in 16.16 notation */
+#endif
+
+/* squeezing on left and right ?  */
+if (squeeze_left && squeeze_right)
+    {
+    /* calculate scale factor */
+    if (bbox_width < set_width)
+       *x_factor = 0x10000L; /* 1 in 16.16 notation */
+    else
+       *x_factor = ((fix31)set_width<<16)/(fix31)bbox_width;
+#if INCL_ISW
+    IMPORT_FACTOR
+#endif
+    /* calculate offset */
+    if (out_on_left) /* fall out on left ? */
+       *x_offset = -(fix31)*x_factor * (fix31)bbox_xmin;
+    /* fall out on right and I am shifting only ? */
+    else if (out_on_right && (*x_factor == 0x10000L))
+        *x_offset = -(fix31)*x_factor * (fix31)(bbox_xmax - set_width);
+    else
+       *x_offset = 0x0L; /* 0 in 16.16 notation */
+    }
+/* squeezing on left only and violates left */
+else if (squeeze_left)
+    {
+    if (bbox_width < set_width) /* will it fit if I shift it ? */
+       *x_factor = 0x10000L; /* 1 in 16.16 notation */
+    else if (out_on_right)
+       *x_factor = ((fix31)set_width<<16)/(fix31)bbox_width;
+    else
+       *x_factor = ((fix31)set_width<<16)/
+                   (fix31)(bbox_width - (bbox_xmax-set_width));
+#if INCL_ISW
+    IMPORT_FACTOR
+#endif
+    *x_offset = (fix31)-*x_factor * (fix31)bbox_xmin;
+    }
+
+/* I must be squeezing on right, and violates right */
+else 
+    {
+    if (bbox_width < set_width) /* will it fit if I shift it ? */
+       {  /* just shift it left - it will fit in the bbox */
+        *x_factor = 0x10000L; /* 1 in 16.16 notation */
+#if INCL_ISW
+    IMPORT_FACTOR
+#endif
+        *x_offset = (fix31)-*x_factor * (fix31)bbox_xmin;
+       }
+    else if (out_on_left)
+       {
+        *x_factor = ((fix31)set_width<<16)/(fix31)bbox_width;
+#if INCL_ISW
+    IMPORT_FACTOR
+#endif
+       *x_offset = 0x0L; /* 0 in 16.16 notation */
+       }
+    else
+       {
+        *x_factor = ((fix31)set_width<<16)/(fix31)bbox_xmax;
+#if INCL_ISW
+    IMPORT_FACTOR
+#endif
+       *x_offset = 0x0L; /* 0 in 16.16 notation */
+       }
+    }
+
+x_offset_pix = (fix15)(((*x_offset >> 16) * sp_globals.tcb0.xppo)
+               / (1<<sp_globals.mpshift)); 
+
+if ((x_offset_pix >0) && (x_offset_pix < sp_globals.onepix))
+    x_offset_pix = sp_globals.onepix; 
+
+/* look for the first non-negative oru value, scale and add the offset    */
+/* to the corresponding pixel value - note that the pixel value           */
+/* is set in read_oru_table.                                              */
+
+/* look at all the X edges */
+for (i=0; i < (no_X_ctrl_zones+1); i++)
+    if (sp_plaid.orus[i] >= 0)
+        {
+        sp_plaid.pix[i] = (SQUEEZE_MULT(sp_plaid.pix[i], *x_factor) 
+                 +sp_globals.pixrnd + x_offset_pix) & sp_globals.pixfix;
+        break;
+        }
+
+return TRUE;
+}
+\f
+FUNCTION boolean calculate_y_scale(top_scale, bottom_scale, 
+                                            first_Y_zone, no_Y_ctrl_zones)
+GDECL
+fix31   *top_scale, *bottom_scale;
+fix15  first_Y_zone;
+fix15  no_Y_ctrl_zones;
+/*
+ * Called by sp_setup_pix_table() when squeezing is included
+ * to determine whether Y scaling is necessary.  If it is, 
+ * two scale factors are computed, one for above the baseline,
+ * and one for below the basline.
+ * This function returns a boolean value TRUE = Y squeezind is necessary, 
+ * FALSE = no Y squeezing is necessary.
+ */
+{
+boolean squeeze_top, squeeze_bottom;
+boolean out_on_top, out_on_bottom;
+fix15  bbox_top, bbox_bottom;
+fix15  bbox_height;
+fix15   i;
+
+/* set up some flags and common calculations */
+squeeze_top = (sp_globals.pspecs->flags & SQUEEZE_TOP)? TRUE:FALSE;
+squeeze_bottom = (sp_globals.pspecs->flags & SQUEEZE_BOTTOM)? TRUE:FALSE;
+bbox_top = sp_globals.bbox_ymax_orus;
+bbox_bottom = sp_globals.bbox_ymin_orus;
+bbox_height = bbox_top - bbox_bottom;
+
+if (bbox_top > EM_TOP)
+    out_on_top = TRUE;
+else
+    out_on_top = FALSE;
+
+if (bbox_bottom < EM_BOT)
+    out_on_bottom = TRUE;
+else
+    out_on_bottom = FALSE;
+
+/*
+ * don't need Y squeezing if:
+ *     - Y squeezing not enabled
+ *     - bbox doesn't violate on top or bottom
+ *     - top squeezing only is enabled and char isn't out on top
+ *     - bottom squeezing only is enabled and char isn't out on bottom
+ */
+if ((!squeeze_top && !squeeze_bottom) || 
+    (!out_on_top && !out_on_bottom) ||
+    (squeeze_top && !squeeze_bottom && !out_on_top) || 
+    (squeeze_bottom && !squeeze_top && !out_on_bottom)) 
+    return FALSE;
+
+if (squeeze_top && (bbox_top > EM_TOP))
+    *top_scale = ((fix31)EM_TOP << 16)/(fix31)(bbox_top);
+else
+    *top_scale = 0x10000L;  /* 1 in 16.16 fixed point */
+
+if (squeeze_bottom && (bbox_bottom < EM_BOT))
+    *bottom_scale = ((fix31)-(EM_BOT) << 16)/(fix31)-bbox_bottom;
+else
+    *bottom_scale = 0x10000L;
+
+if (sp_globals.squeezing_compound)
+    {
+    for (i=first_Y_zone; i < (first_Y_zone + no_Y_ctrl_zones + 1); i++)
+        {
+        if (sp_plaid.orus[i] >= 0)
+            sp_plaid.pix[i] = (SQUEEZE_MULT(sp_plaid.pix[i], *top_scale)
+                              +sp_globals.pixrnd) & sp_globals.pixfix;
+        else
+            sp_plaid.pix[i] = (SQUEEZE_MULT(sp_plaid.pix[i], *bottom_scale)
+                              +sp_globals.pixrnd) & sp_globals.pixfix;
+        }
+    }
+return TRUE;
+}
+#endif
+\f
+#if INCL_RULES
+FUNCTION static ufix8 FONTFAR *sp_setup_pix_table(
+    pointer, short_form, no_X_ctrl_zones, no_Y_ctrl_zones)
+GDECL
+ufix8 FONTFAR *pointer;   /* Pointer to first byte in control zone table */
+boolean short_form; /* TRUE if 1 byte from/to specification */
+fix15   no_X_ctrl_zones; /* Number of X control zones */
+fix15   no_Y_ctrl_zones; /* Number of Y control zones */
+/*
+ * Called by plaid_tcb() to read the control zone table from the
+ * character data in the font.
+ * Sets up a table of pixel values for all controlled coordinates. 
+ * Updates the pointer to the byte following the control zone
+ * data.
+ */
+{
+fix15    i, j, n;
+fix31    ppo;  
+fix31    xppo0; /* top level pixels per oru */
+fix31    yppo0; /* top level pixels per oru */
+ufix8    edge_org;
+ufix8    edge;
+ufix8    start_edge;
+ufix8    end_edge;
+ufix16   constr_org;
+fix15    constr_nr;
+fix15    zone_pix;
+fix31    whole_zone; /* non-transformed value of the first X zone */
+ufix16   tmpufix16;  /* in extended mode, macro uses secnd term */
+#if INCL_SQUEEZING
+fix31    x_scale;
+fix31   y_top_scale, y_bottom_scale;
+fix31    x_offset;
+boolean  squeezed_y;
+fix15    setwidth_pix, em_top_pix, em_bot_pix;
+#endif
+
+#if INCL_ISW
+boolean  imported_width;
+fix31   isw_scale;
+fix15    isw_setwidth_pix;
+#endif
+
+#if INCL_ISW || INCL_SQUEEZING
+boolean squeezed_x;
+#endif
+
+#if INCL_PLAID_OUT               /* Plaid data monitoring included? */
+begin_ctrl_zones(no_X_ctrl_zones, no_Y_ctrl_zones);
+#endif                                                    
+
+
+edge_org = 0;
+constr_org = 0;
+sp_globals.rnd_xmin = 0;  /* initialize the error for chars with no zone */
+n = no_X_ctrl_zones;
+ppo = sp_globals.tcb.xppo;
+xppo0 = sp_globals.tcb0.xppo;
+yppo0 = sp_globals.tcb0.yppo;
+#if INCL_SQUEEZING || INCL_ISW
+squeezed_x = FALSE;
+#endif
+
+#if INCL_SQUEEZING
+squeezed_x = calculate_x_scale (&x_scale, &x_offset, no_X_ctrl_zones);
+squeezed_y = calculate_y_scale(&y_top_scale,&y_bottom_scale,(n+1),
+            no_Y_ctrl_zones);
+#if INCL_ISW
+if (sp_globals.import_setwidth_act == TRUE)
+setwidth_pix = ((fix15)(((fix31)sp_globals.imported_width * xppo0) >> 
+            sp_globals.mpshift) + sp_globals.pixrnd) & sp_globals.pixfix;
+
+else
+#endif
+setwidth_pix = ((fix15)(((fix31)sp_globals.setwidth_orus * xppo0) >> 
+            sp_globals.mpshift) + sp_globals.pixrnd) & sp_globals.pixfix;
+/* check for overflow */
+if (setwidth_pix < 0)
+       setwidth_pix = 0x7fff; /* set to maximum */
+em_bot_pix = ((fix15)(((fix31)EM_BOT * yppo0) >> 
+            sp_globals.mpshift) + sp_globals.pixrnd) & sp_globals.pixfix;
+em_top_pix = ((fix15)(((fix31)EM_TOP * yppo0) >> 
+            sp_globals.mpshift) + sp_globals.pixrnd) & sp_globals.pixfix;
+#endif
+
+#if INCL_ISW
+/* convert to pixels */
+isw_setwidth_pix = ((fix15)(((fix31)sp_globals.imported_width * xppo0) >> 
+            sp_globals.mpshift) + sp_globals.pixrnd) & sp_globals.pixfix;
+/* check for overflow */
+if (isw_setwidth_pix < 0)
+       isw_setwidth_pix = 0x7fff; /* set to maximum */
+if (!squeezed_x && ((imported_width = sp_globals.import_setwidth_act) == TRUE))
+    {
+    isw_scale = compute_isw_scale();
+
+    /* look for the first non-negative oru value, scale and add the offset    */
+    /* to the corresponding pixel value - note that the pixel value           */
+    /* is set in read_oru_table.                                              */
+    
+    /* look at all the X edges */
+        for (i=0; i < (no_X_ctrl_zones+1); i++)
+        if (sp_plaid.orus[i] >= 0)
+           {
+           sp_plaid.pix[i] = (SQUEEZE_MULT(sp_plaid.pix[i], isw_scale)
+                  +sp_globals.pixrnd) & sp_globals.pixfix;
+           break;
+           }
+
+    }
+#endif
+
+for (i = 0; ; i++)               /* For X and Y control zones... */
+    {
+    for (j = 0; j < n; j++)      /* For each zone in X or Y... */
+        {
+        if (short_form)          /* 1 byte from/to specification? */
+            {
+            edge = NEXT_BYTE(pointer); /* Read packed from/to spec */
+            start_edge = edge_org + (edge & 0x0f); /* Extract start edge */
+            end_edge = edge_org + (edge >> 4); /* Extract end edge */
+            }
+        else                     /* 2 byte from/to specification? */
+            {
+            start_edge = edge_org + NEXT_BYTE(pointer); /* Read start edge */
+            end_edge = edge_org + NEXT_BYTE(pointer); /* read end edge */
+            }
+        constr_nr = constr_org +
+            NEXT_BYTES(pointer, tmpufix16); /* Read constraint number */ 
+#if INCL_SQUEEZING
+        if (i == 0 && squeezed_x)
+           calculate_x_pix(start_edge, end_edge, constr_nr,
+                            x_scale, x_offset, ppo, setwidth_pix);
+       else if (i == 1 && squeezed_y)
+           calculate_y_pix(start_edge, end_edge,constr_nr,
+               y_top_scale, y_bottom_scale, ppo, em_top_pix, em_bot_pix);
+       else
+       {
+#endif
+#if INCL_ISW
+       if (i==0 && imported_width)
+            calculate_x_pix(start_edge, end_edge, constr_nr,
+                            isw_scale, 0,  ppo, isw_setwidth_pix);
+       else
+       {
+#endif
+        if (!sp_globals.c_act[constr_nr])   /* Constraint inactive? */
+            {
+            zone_pix = ((fix15)((((fix31)sp_plaid.orus[end_edge] -
+                       (fix31)sp_plaid.orus[start_edge]) * ppo) /
+                       (1<<sp_globals.mpshift)) + sp_globals.pixrnd) &
+                       sp_globals.pixfix;
+            if ((ABS(zone_pix)) >= sp_globals.c_pix[constr_nr])
+                goto L1;
+            }
+        zone_pix = sp_globals.c_pix[constr_nr]; /* Use zone size from constr table */
+        if (start_edge > end_edge) /* sp_plaid.orus[start_edge] > sp_plaid.orus[end_edge]? */
+            {
+            zone_pix = -zone_pix; /* Use negatve zone size */
+            }
+    L1:
+                        /* inter-character spacing fix */
+        if ((j == 0) && (i == 0))      /* if this is the 1st X zone, save rounding error */
+            {                          /*  get the non-xformed - xformed zone, in right direction */
+            whole_zone = (((fix31)sp_plaid.orus[end_edge] -
+                       (fix31)sp_plaid.orus[start_edge]) *
+                       ppo) / (1<<sp_globals.mpshift);
+            sp_globals.rnd_xmin = whole_zone - zone_pix;
+            }
+        sp_plaid.pix[end_edge] = sp_plaid.pix[start_edge] + zone_pix; /* Insert end pixels */
+#if INCL_SQUEEZING
+        if (i == 0)  /* in the x direction */
+            { /* brute force squeeze */
+            if ((sp_globals.pspecs->flags & SQUEEZE_LEFT) && 
+                (sp_plaid.pix[end_edge] < 0))
+                sp_plaid.pix[end_edge] = 0;
+            if ((sp_globals.pspecs->flags & SQUEEZE_RIGHT) && 
+                (sp_plaid.pix[end_edge] > setwidth_pix))
+                sp_plaid.pix[end_edge] = setwidth_pix;
+            }
+        if (i == 1) /* in the y direction */
+            {  /* brute force squeeze */
+            if ((sp_globals.pspecs->flags & SQUEEZE_TOP) && 
+                (sp_plaid.pix[end_edge] > em_top_pix))
+                sp_plaid.pix[end_edge] = em_top_pix;
+            if ((sp_globals.pspecs->flags & SQUEEZE_BOTTOM) &&
+                (sp_plaid.pix[end_edge] < em_bot_pix))
+                sp_plaid.pix[end_edge] = em_bot_pix;
+            }
+#endif
+#if INCL_SQUEEZING
+       }
+#endif
+#if INCL_ISW
+       }
+#endif
+#if INCL_PLAID_OUT               /* Plaid data monitoring included? */
+        record_ctrl_zone(
+            (fix31)sp_plaid.pix[start_edge] << (16 - sp_globals.pixshift), 
+            (fix31)sp_plaid.pix[end_edge] << (16 - sp_globals.pixshift), 
+            (fix15)(constr_nr - constr_org));
+#endif
+        }
+    if (i)                       /* Y pixels done? */
+        break;                                          
+    edge_org = sp_globals.Y_edge_org;       /* Prepare to process Y ctrl zones */
+    constr_org = sp_globals.Y_constr_org;
+    n = no_Y_ctrl_zones;                      
+    ppo = sp_globals.tcb.yppo;                            
+    }
+
+#if DEBUG
+printf("\nX PIX TABLE\n");
+n = no_X_ctrl_zones + 1;
+for (i = 0; i < n; i++)
+    printf("%2d %6.1f\n", i, (real)sp_plaid.pix[i] / (real)sp_globals.onepix);
+printf("\nY PIX TABLE\n");
+n = no_Y_ctrl_zones + 1;
+for (i = 0; i < n; i++)
+    {
+    j = i + no_X_ctrl_zones + 1;
+    printf("%2d %6.1f\n", i, (real)sp_plaid.pix[j] / (real)sp_globals.onepix);
+    }
+#endif
+
+return pointer;
+}
+#endif
+
+\f
+#if INCL_RULES
+FUNCTION static ufix8 FONTFAR *sp_setup_int_table(pointer, no_X_int_zones, no_Y_int_zones)
+GDECL
+ufix8 FONTFAR *pointer;   /* Pointer to first byte in interpolation zone table */
+fix15  no_X_int_zones; /* Number of X interpolation zones */
+fix15  no_Y_int_zones; /* Number of X interpolation zones */
+/*
+ * Called by plaid_tcb() to read the interpolation zone table from the
+ * character data in the font. 
+ * Sets up a table of interpolation coefficients with one entry for
+ * every X or Y interpolation zone.
+ * Updates the pointer to the byte following the interpolation zone
+ * data.
+ */
+{
+fix15    i, j, k, l, n;
+ufix8    format;
+ufix8    format_copy;
+ufix8    tmpufix8;
+fix15    start_orus;
+ufix8    edge_org;
+ufix8    edge;
+ufix16   adj_factor;
+fix15    adj_orus;
+fix15    end_orus;
+fix31    zone_orus;
+fix15    start_pix;
+fix15    end_pix;
+
+
+#if INCL_PLAID_OUT               /* Plaid data monitoring included? */
+begin_int_zones(no_X_int_zones, no_Y_int_zones);
+#endif
+
+i = 0;
+edge_org = 0;
+n = no_X_int_zones;
+for (j = 0; ; j++)
+    {
+    for (k = 0; k < n; k++)
+        {
+        format = NEXT_BYTE(pointer);
+        if (format & BIT7)       /* Short start/end point spec? */
+            {
+            tmpufix8 = NEXT_BYTE(pointer);
+            edge = edge_org + (tmpufix8 & 0xf);
+            start_orus = sp_plaid.orus[edge];
+            start_pix = sp_plaid.pix[edge];
+            edge = edge_org + (tmpufix8 >> 4);
+            end_orus = sp_plaid.orus[edge];
+            end_pix = sp_plaid.pix[edge];
+            }
+        else                     /* Standard start and end point spec? */
+            {
+            format_copy = format;
+            for (l = 0; ; l++)   /* Loop for start and end point */
+                {
+                switch (format_copy & 0x7) /* Decode start/end point format */
+                    {
+
+                case 0:          /* Index to control edge */
+                    edge = edge_org + NEXT_BYTE(pointer);
+                    end_orus = sp_plaid.orus[edge];
+                    end_pix = sp_plaid.pix[edge];
+                    break;
+
+                case 1:          /* 1 byte fractional distance to next edge */
+                    adj_factor =  0xffff & NEXT_BYTE(pointer) << 8;
+                    goto L1;
+
+
+                case 2:          /* 2 byte fractional distance to next edge */
+                   adj_factor = 0xffff & NEXT_WORD(pointer);
+                L1: edge = edge_org + NEXT_BYTE(pointer);
+                    end_orus = sp_plaid.orus[edge] +
+                        ((((fix31)sp_plaid.orus[edge + 1] - (fix31)sp_plaid.orus[edge]) * 
+                        (ufix32)adj_factor + (fix31)32768) >> 16);
+                    end_pix = sp_plaid.pix[edge] +
+                        ((((fix31)sp_plaid.pix[edge + 1] - (fix31)sp_plaid.pix[edge]) * 
+                        (ufix32)adj_factor + (fix31)32768) >> 16);
+                    break;
+
+                case 3:          /* 1 byte delta orus before first edge */
+                    adj_orus = -(fix15)NEXT_BYTE(pointer); 
+                    goto L2;
+
+                case 4:          /* 2 byte delta orus before first edge */
+                    adj_orus = -NEXT_WORD(pointer);
+                L2: edge = edge_org;
+                    goto L4;
+
+                case 5:          /* 1 byte delta orus after last edge */
+                    adj_orus = (fix15)NEXT_BYTE(pointer);
+                    goto L3;
+
+                case 6:          /* 2 byte delta orus after last edge */
+                    adj_orus = NEXT_WORD(pointer);
+                L3: edge = j? sp_globals.Y_edge_org + sp_globals.no_Y_orus - 1: sp_globals.no_X_orus - 1;
+                L4: end_orus = sp_plaid.orus[edge] + adj_orus;
+                    end_pix = sp_plaid.pix[edge] + 
+                        (((fix31)adj_orus * (fix31)(j? sp_globals.tcb.yppo: sp_globals.tcb.xppo) + 
+                          sp_globals.mprnd) / (1<<sp_globals.mpshift));
+                    break;
+
+                    }
+
+                if (l)           /* Second time round loop? */
+                    break;
+                format_copy >>= 3; /* Adj format to decode end point format */
+                start_orus = end_orus; /* Save start point oru value */
+                start_pix = end_pix; /* Save start point pixel value */
+                }
+            }
+#if INCL_PLAID_OUT               /* Plaid data monitoring included? */
+        record_int_zone(
+            (fix31)start_pix << (16 - sp_globals.pixshift), 
+            (fix31)end_pix << (16 - sp_globals.pixshift));
+#endif
+        zone_orus = (fix31)end_orus - (fix31)start_orus;
+        sp_plaid.mult[i] = ((((fix31)end_pix - (fix31)start_pix) << sp_globals.mpshift) + 
+                   (zone_orus / 2)) / zone_orus;
+        sp_plaid.offset[i] = 
+            (((((fix31)start_pix + (fix31)end_pix) << sp_globals.mpshift) - 
+              ((fix31)sp_plaid.mult[i] * ((fix31)start_orus + (fix31)end_orus))) / 2) + 
+            sp_globals.mprnd;
+        i++;
+        }
+    if (j)                       /* Finished? */
+        break;
+    edge_org = sp_globals.Y_edge_org;       /* Prepare to process Y ctrl zones */
+    n = no_Y_int_zones;
+    }
+
+#if DEBUG
+printf("\nX INT TABLE\n");
+n = no_X_int_zones;
+for (i = 0; i < n; i++)
+    {
+    printf("%2d %7.4f %7.4f\n", i, 
+        (real)sp_plaid.mult[i] / (real)(1 << sp_globals.multshift), 
+        (real)sp_plaid.offset[i] / (real)(1 << sp_globals.multshift));
+    }
+printf("\nY INT TABLE\n");
+n = no_Y_int_zones;
+for (i = 0; i < n; i++)
+    {
+    j = i + no_X_int_zones;
+    printf("%2d %7.4f %7.4f\n", i, 
+        (real)sp_plaid.mult[j] / (real)(1 << sp_globals.multshift), 
+        (real)sp_plaid.offset[j] / (real)(1 << sp_globals.multshift));
+    }
+#endif
+
+return pointer;
+}
+#endif
+#if INCL_ISW
+FUNCTION fix31 compute_isw_scale()
+GDECL
+{
+fix31 isw_scale;
+       
+if (sp_globals.setwidth_orus == 0)
+    isw_scale = 0x00010000;
+else
+    isw_scale = ((fix31)sp_globals.imported_width << 16)/
+                 (fix31)sp_globals.setwidth_orus;
+return isw_scale;
+}
+#endif
diff --git a/Xserver/lib/font/Speedo/spdo_prv.h b/Xserver/lib/font/Speedo/spdo_prv.h
new file mode 100644 (file)
index 0000000..cda0191
--- /dev/null
@@ -0,0 +1,425 @@
+/* $XConsortium: spdo_prv.h,v 1.4 94/02/10 11:06:01 gildea Exp $ */
+
+/*
+
+Copyright 1989-1991, Bitstream Inc., Cambridge, MA.
+You are hereby granted permission under all Bitstream propriety rights to
+use, copy, modify, sublicense, sell, and redistribute the Bitstream Speedo
+software and the Bitstream Charter outline font for any purpose and without
+restrictions; provided, that this notice is left intact on all copies of such
+software or font and that Bitstream's trademark is acknowledged as shown below
+on all unmodified copies of such font.
+
+BITSTREAM CHARTER is a registered trademark of Bitstream Inc.
+
+
+BITSTREAM INC. DISCLAIMS ANY AND ALL WARRANTIES, EXPRESS OR IMPLIED, INCLUDING
+WITHOUT LIMITATION THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+PARTICULAR PURPOSE.  BITSTREAM SHALL NOT BE LIABLE FOR ANY DIRECT OR INDIRECT
+DAMAGES, INCLUDING BUT NOT LIMITED TO LOST PROFITS, LOST DATA, OR ANY OTHER
+INCIDENTAL OR CONSEQUENTIAL DAMAGES, ARISING OUT OF OR IN ANY WAY CONNECTED
+WITH THE SPEEDO SOFTWARE OR THE BITSTREAM CHARTER OUTLINE FONT.
+
+*/
+
+
+
+/***************************** S P D O _ P R V . H *******************************/
+#include "speedo.h"  /* include public definitions */
+
+/*****  CONFIGURATION DEFINITIONS *****/
+
+
+#ifndef INCL_PLAID_OUT
+#define  INCL_PLAID_OUT 0          /* 1 to include plaid data monitoring */
+#endif                             /* 0 to omit plaid data monitoring */
+
+
+/***** PRIVATE FONT HEADER OFFSET CONSTANTS  *****/
+#define  FH_ORUMX    0      /* U   Max ORU value  2 bytes                   */
+#define  FH_PIXMX    2      /* U   Max Pixel value  2 bytes                 */
+#define  FH_CUSNR    4      /* U   Customer Number  2 bytes                 */
+#define  FH_OFFCD    6      /* E   Offset to Char Directory  3 bytes        */
+#define  FH_OFCNS    9      /* E   Offset to Constraint Data  3 bytes       */
+#define  FH_OFFTK   12      /* E   Offset to Track Kerning  3 bytes         */
+#define  FH_OFFPK   15      /* E   Offset to Pair Kerning  3 bytes          */
+#define  FH_OCHRD   18      /* E   Offset to Character Data  3 bytes        */
+#define  FH_NBYTE   21      /* E   Number of Bytes in File  3 bytes         */
+
+
+/***** MODE FLAGS CONSTANTS *****/
+#define CURVES_OUT     0X0008  /* Output module accepts curves              */
+#define BOGUS_MODE     0X0010  /* Linear scaling mode                       */
+#define CONSTR_OFF     0X0020  /* Inhibit constraint table                  */
+#define IMPORT_WIDTHS  0X0040  /* Imported width mode                       */
+#define SQUEEZE_LEFT   0X0100  /* Squeeze left mode                         */
+#define SQUEEZE_RIGHT  0X0200  /* Squeeze right mode                        */
+#define SQUEEZE_TOP    0X0400  /* Squeeze top mode                          */
+#define SQUEEZE_BOTTOM 0X0800  /* Squeeze bottom mode                       */
+#define CLIP_LEFT      0X1000  /* Clip left mode                            */
+#define CLIP_RIGHT     0X2000  /* Clip right mode                           */
+#define CLIP_TOP       0X4000  /* Clip top mode                             */
+#define CLIP_BOTTOM    0X8000  /* Clip bottom mode                          */
+
+
+/***** MACRO DEFINITIONS *****/
+
+#define SQUEEZE_MULT(A,B) (((fix31)A * (fix31)B) / (1 << 16))
+
+#define NEXT_BYTE(A) (*(A)++)
+
+#define NEXT_WORD(A) \
+    ((fix15)(sp_globals.key32 ^ ((A) += 2, \
+                                ((fix15)((A)[-1]) << 8) | (fix15)((A)[-2]) | \
+                                ((A)[-1] & 0x80? ~0xFFFF : 0))))
+
+#if INCL_EXT                       /* Extended fonts supported? */
+
+#define NEXT_BYTES(A, B) \
+    (((B = (ufix16)(*(A)++) ^ sp_globals.key7) >= 248)? \
+     ((ufix16)(B & 0x07) << 8) + ((*(A)++) ^ sp_globals.key8) + 248: \
+     B)
+
+#else                              /* Compact fonts only supported? */
+
+#define NEXT_BYTES(A, B) ((*(A)++) ^ sp_globals.key7)
+
+#endif
+
+
+#define NEXT_BYTE_U(A) (*(A)++) 
+
+#define NEXT_WORD_U(A, B) \
+    (fix15)(B = (*(A)++) << 8, (fix15)(*(A)++) + B)
+
+#define NEXT_CHNDX(A, B) \
+    ((B)? (ufix16)NEXT_WORD(A): (ufix16)NEXT_BYTE(A))
+
+/* Multiply (fix15)X by (fix15)Y to produce (fix31)product */
+#define MULT16(X, Y) \
+    ((fix31)X * (fix31)Y)
+
+/* Multiply (fix15)X by (fix15)MULT, add (fix31)OFFSET, 
+ * shift right SHIFT bits to produce (fix15)result */
+#define TRANS(X, MULT, OFFSET, SHIFT) \
+    ((fix15)((((fix31)X * (fix31)MULT) + OFFSET) / (1 << SHIFT)))
+
+/******************************************************************************
+ *
+ *      the following block of definitions redefines every function
+ *      reference to be prefixed with an "sp_".  In addition, if this 
+ *      is a reentrant version, the parameter sp_globals will be added
+ *      as the first parameter.
+ *
+ *****************************************************************************/
+
+#if STATIC_ALLOC || DYNAMIC_ALLOC
+
+#define GDECL
+
+#define get_char_id(char_index) sp_get_char_id(char_index)
+#define get_char_width(char_index) sp_get_char_width(char_index)
+#define get_track_kern(track,point_size) sp_get_track_kern(track,point_size)
+#define get_pair_kern(char_index1,char_index2) sp_get_pair_kern(char_index1,char_index2)
+#define get_char_bbox(char_index,bbox) sp_get_char_bbox(char_index,bbox)
+#define make_char(char_index) sp_make_char(char_index)
+#if INCL_ISW
+#define compute_isw_scale() sp_compute_isw_scale()
+#define do_make_char(char_index) sp_do_make_char(char_index)
+#define make_char_isw(char_index,imported_width) sp_make_char_isw(char_index,imported_width)
+#define reset_xmax(xmax) sp_reset_xmax(xmax)
+#endif
+#if INCL_ISW || INCL_SQUEEZING
+#define preview_bounding_box(pointer,format) sp_preview_bounding_box(pointer,format)
+#endif
+#define make_simp_char(pointer,format) sp_make_simp_char(pointer,format)
+#define make_comp_char(pointer) sp_make_comp_char(pointer)
+#define get_char_org(char_index,top_level) sp_get_char_org(char_index,top_level)
+#define get_posn_arg(ppointer,format) sp_get_posn_arg(ppointer,format)
+#define get_scale_arg(ppointer,format) sp_get_scale_arg(ppointer,format)
+#define read_bbox(ppointer,pPmin,pPmax,set_flag) sp_read_bbox(ppointer,pPmin,pPmax,set_flag)
+#define proc_outl_data(pointer) sp_proc_outl_data(pointer)
+#define split_curve(P1,P2,P3,depth) sp_split_curve(P1,P2,P3,depth)
+#define get_args(ppointer,format,pP) sp_get_args(ppointer,format,pP)
+
+#define init_black(specsarg) sp_init_black(specsarg)
+#define begin_char_black(Psw,Pmin,Pmax) sp_begin_char_black(Psw,Pmin,Pmax)
+#define begin_contour_black(P1,outside) sp_begin_contour_black(P1,outside)
+#define line_black(P1) sp_line_black(P1)
+#define end_char_black() sp_end_char_black()
+#define add_intercept_black(y,x) sp_add_intercept_black(y,x)
+#define proc_intercepts_black() sp_proc_intercepts_black()
+
+#define init_screen(specsarg) sp_init_screen(specsarg)
+#define begin_char_screen(Psw,Pmin,Pmax) sp_begin_char_screen(Psw,Pmin,Pmax)
+#define begin_contour_screen(P1,outside) sp_begin_contour_screen(P1,outside)
+#define curve_screen(P1,P2,P3,depth) sp_curve_screen(P1,P2,P3,depth)
+#define scan_curve_screen(X0,Y0,X1,Y1,X2,Y2,X3,Y3) sp_scan_curve_screen(X0,Y0,X1,Y1,X2,Y2,X3,Y3) 
+#define vert_line_screen(x,y1,y2) sp_vert_line_screen(x,y1,y2)
+#define line_screen(P1) sp_line_screen(P1)
+#define end_contour_screen() sp_end_contour_screen()
+#define end_char_screen() sp_end_char_screen()
+#define add_intercept_screen(y,x) sp_add_intercept_screen(y,x)
+#define proc_intercepts_screen() sp_proc_intercepts_screen()
+
+#define init_outline(specsarg) sp_init_outline(specsarg)
+#define begin_char_outline(Psw,Pmin,Pmax) sp_begin_char_outline(Psw,Pmin,Pmax)
+#define begin_sub_char_outline(Psw,Pmin,Pmax) sp_begin_sub_char_outline(Psw,Pmin,Pmax)
+#define begin_contour_outline(P1,outside) sp_begin_contour_outline(P1,outside)
+#define curve_outline(P1,P2,P3,depth) sp_curve_outline(P1,P2,P3,depth)
+#define line_outline(P1) sp_line_outline(P1)
+#define end_contour_outline() sp_end_contour_outline()
+#define end_sub_char_outline() sp_end_sub_char_outline()
+#define end_char_outline() sp_end_char_outline()
+
+#define init_2d(specsarg) sp_init_2d(specsarg)
+#define begin_char_2d(Psw, Pmin, Pmax) sp_begin_char_2d(Psw, Pmin, Pmax)
+#define begin_contour_2d(P1, outside) sp_begin_contour_2d(P1, outside)
+#define line_2d(P1) sp_line_2d(P1)
+#define end_char_2d() sp_end_char_2d()
+#define add_intercept_2d(y, x) sp_add_intercept_2d(y, x)
+#define proc_intercepts_2d() sp_proc_intercepts_2d()
+#define draw_vector_to_2d(x0, y0, x1, y1, band) sp_draw_vector_to_2d(x0, y0, x1, y1, band)
+
+#define init_char_out(Psw,Pmin,Pmax) sp_init_char_out(Psw,Pmin,Pmax)
+#define begin_sub_char_out(Psw,Pmin,Pmax) sp_begin_sub_char_out(Psw,Pmin,Pmax)
+#define curve_out(P1,P2,P3,depth) sp_curve_out(P1,P2,P3,depth)
+#define end_contour_out() sp_end_contour_out()
+#define end_sub_char_out() sp_end_sub_char_out()
+#define init_intercepts_out() sp_init_intercepts_out()
+#define restart_intercepts_out() sp_restart_intercepts_out()
+#define set_first_band_out(Pmin,Pmax) sp_set_first_band_out(Pmin,Pmax)
+#define reduce_band_size_out() sp_reduce_band_size_out()
+#define next_band_out() sp_next_band_out()
+
+#define init_userout(specsarg) sp_init_userout(specsarg)
+
+#define reset() sp_reset()
+#define set_key(key) sp_set_key(key)
+#define get_cust_no(font_buff) sp_get_cust_no(font_buff)
+#define set_specs(specsarg) sp_set_specs(specsarg)
+#define setup_consts(xmin,xmax,ymin,ymax) sp_setup_consts(xmin,xmax,ymin,ymax)
+#define setup_tcb(ptcb) sp_setup_tcb(ptcb)
+#define setup_mult(input_mult) sp_setup_mult(input_mult)
+#define setup_offset(input_offset) sp_setup_offset(input_offset)
+#define type_tcb(ptcb) sp_type_tcb(ptcb)
+#define read_long(pointer) sp_read_long(pointer)
+#define read_word_u(pointer) sp_read_word_u(pointer)
+#define init_tcb() sp_init_tcb()
+#define scale_tcb(ptcb,x_pos,y_pos,x_scale,y_scale) sp_scale_tcb(ptcb,x_pos,y_pos,x_scale,y_scale)
+#define plaid_tcb(ppointer,format) sp_plaid_tcb(ppointer,format)
+#define skip_orus(ppointer,short_form,no_ctrl_zones) sp_skip_orus(ppointer,short_form,no_ctrl_zones)
+#define skip_interpolation_table(ppointer,format) sp_skip_interpolation_table(ppointer,format)
+#define skip_control_zone(ppointer,format) sp_skip_control_zone(ppointer,format)
+#define constr_update() sp_constr_update()
+#define read_oru_table(ppointer) sp_read_oru_table(ppointer)
+#define calculate_x_pix(start_edge,end_edge,constr_nr,x_scale,x_offset,ppo,setwidth_pix) sp_calculate_x_pix(start_edge,end_edge,constr_nr,x_scale,x_offset,ppo,setwidth_pix)
+#define calculate_y_pix(start_edge,end_edge,constr_nr,top_scale,bottom_scale,ppo,emtop_pix,embot_pix) sp_calculate_y_pix(start_edge,end_edge,constr_nr,top_scale,bottom_scale,ppo,emtop_pix,embot_pix)
+#define calculate_x_scale(x_factor,x_offset,no_x_ctrl_zones) sp_calculate_x_scale(x_factor,x_offset,no_x_ctrl_zones)
+#define calculate_y_scale(top_scale,bottom_scale,first_y_zone,no_Y_ctrl_zones) sp_calculate_y_scale(top_scale,bottom_scale,first_y_zone,no_Y_ctrl_zones) 
+#define setup_pix_table(ppointer,short_form,no_X_ctrl_zones,no_Y_ctrl_zones) sp_setup_pix_table(ppointer,short_form,no_X_ctrl_zones,no_Y_ctrl_zones)
+#define setup_int_table(ppointer,no_X_int_zones, no_Y_int_zones) sp_setup_int_table(ppointer,no_X_int_zones, no_Y_int_zones)
+
+#define fn_init_out(specsarg) (*sp_globals.init_out)(specsarg)  
+#define fn_begin_char(Psw,Pmin,Pmax) (*sp_globals.begin_char)(Psw,Pmin,Pmax)
+#define fn_begin_sub_char(Psw,Pmin,Pmax) (*sp_globals.begin_sub_char)(Psw,Pmin,Pmax)
+#define fn_end_sub_char() (*sp_globals.end_sub_char)()
+#define fn_end_char() (*sp_globals.end_char)()
+#define fn_line(P1) (*sp_globals.line)(P1)
+#define fn_end_contour() (*sp_globals.end_contour)()
+#define fn_begin_contour(P0,fmt) (*sp_globals.begin_contour)(P0,fmt)
+#define fn_curve(P1,P2,P3,depth) (*sp_globals.curve)(P1,P2,P3,depth)
+
+#define load_char_data(offset, no_bytes, buff_off) sp_load_char_data(offset, no_bytes, buff_off)
+#define report_error(n) sp_report_error(n)
+
+#if INCL_MULTIDEV
+
+#define set_bitmap_device(bfuncs,size) sp_set_bitmap_device(bfuncs,size)
+#define set_outline_device(ofuncs,size) sp_set_outline_device(ofuncs,size)
+
+#define open_bitmap(x_set_width, y_set_width, xmin, xmax, ymin, ymax) (*sp_globals.bitmap_device.p_open_bitmap)(x_set_width, y_set_width, xmin, xmax, ymin, ymax)
+#define set_bitmap_bits(y, xbit1, xbit2) (*sp_globals.bitmap_device.p_set_bits)(y, xbit1, xbit2)
+#define close_bitmap() (*sp_globals.bitmap_device.p_close_bitmap)()
+
+#define open_outline(x_set_width, y_set_width, xmin, xmax, ymin, ymax) (*sp_globals.outline_device.p_open_outline)(x_set_width, y_set_width, xmin, xmax, ymin, ymax)
+#define start_new_char() (*sp_globals.outline_device.p_start_char)()
+#define start_contour(x,y,outside) (*sp_globals.outline_device.p_start_contour)(x,y,outside)
+#define curve_to(x1,y1,x2,y2,x3,y3) (*sp_globals.outline_device.p_curve)(x1,y1,x2,y2,x3,y3)
+#define line_to(x,y) (*sp_globals.outline_device.p_line)(x,y)
+#define close_contour() (*sp_globals.outline_device.p_close_contour)()
+#define close_outline() (*sp_globals.outline_device.p_close_outline)()
+
+#else
+
+#define open_bitmap(x_set_width, y_set_width, xmin, xmax, ymin, ymax) sp_open_bitmap(x_set_width, y_set_width, xmin, xmax, ymin, ymax)
+#define set_bitmap_bits(y, xbit1, xbit2) sp_set_bitmap_bits(y, xbit1, xbit2)
+#define close_bitmap() sp_close_bitmap()
+
+#define open_outline(x_set_width, y_set_width, xmin, xmax, ymin, ymax) sp_open_outline(x_set_width, y_set_width, xmin, xmax, ymin, ymax)
+#define start_new_char() sp_start_new_char()
+#define start_contour(x,y,outside) sp_start_contour(x,y,outside)
+#define curve_to(x1,y1,x2,y2,x3,y3) sp_curve_to(x1,y1,x2,y2,x3,y3)
+#define line_to(x,y) sp_line_to(x,y)
+#define close_contour() sp_close_contour()
+#define close_outline() sp_close_outline()
+
+#endif
+
+#else
+
+#define GDECL SPEEDO_GLOBALS* sp_global_ptr;
+
+#define get_char_id(char_index) sp_get_char_id(sp_global_ptr,char_index)
+#define get_char_width(char_index) sp_get_char_width(sp_global_ptr,char_index)
+#define get_track_kern(track,point_size) sp_get_track_kern(sp_global_ptr,track,point_size)
+#define get_pair_kern(char_index1,char_index2) sp_get_pair_kern(sp_global_ptr,char_index1,char_index2)
+#define get_char_bbox(char_index,bbox) sp_get_char_bbox(sp_global_ptr,char_index,bbox)
+#define make_char(char_index) sp_make_char(sp_global_ptr,char_index)
+#if INCL_ISW
+#define compute_isw_scale() sp_compute_isw_scale(sp_global_ptr)
+#define do_make_char(char_index) sp_do_make_char(sp_global_ptr,char_index)
+#define make_char_isw(char_index,imported_width) sp_make_char_isw(sp_global_ptr,char_index,imported_width)
+#define reset_xmax(xmax) sp_reset_xmax(sp_global_ptr,xmax)
+#endif
+#if INCL_ISW || INCL_SQUEEZING
+#define preview_bounding_box(pointer,format) sp_preview_bounding_box(sp_global_ptr,pointer,format)
+#endif
+#define make_simp_char(pointer,format) sp_make_simp_char(sp_global_ptr,pointer,format)
+#define make_comp_char(pointer) sp_make_comp_char(sp_global_ptr,pointer)
+#define get_char_org(char_index,top_level) sp_get_char_org(sp_global_ptr,char_index,top_level)
+#define get_posn_arg(ppointer,format) sp_get_posn_arg(sp_global_ptr,ppointer,format)
+#define get_scale_arg(ppointer,format) sp_get_scale_arg(sp_global_ptr,ppointer,format)
+#define read_bbox(ppointer,pPmin,pPmax,set_flag) sp_read_bbox(sp_global_ptr,ppointer,pPmin,pPmax,set_flag)
+#define proc_outl_data(pointer) sp_proc_outl_data(sp_global_ptr,pointer)
+#define split_curve(P1,P2,P3,depth) sp_split_curve(sp_global_ptr,P1,P2,P3,depth)
+#define get_args(ppointer,format,pP) sp_get_args(sp_global_ptr,ppointer,format,pP)
+
+#define init_black(specsarg) sp_init_black(sp_global_ptr,specsarg)
+#define begin_char_black(Psw,Pmin,Pmax) sp_begin_char_black(sp_global_ptr,Psw,Pmin,Pmax)
+#define begin_contour_black(P1,outside) sp_begin_contour_black(sp_global_ptr,P1,outside)
+#define line_black(P1) sp_line_black(sp_global_ptr,P1)
+#define end_char_black() sp_end_char_black(sp_global_ptr)
+#define add_intercept_black(y,x) sp_add_intercept_black(sp_global_ptr,y,x)
+#define proc_intercepts_black() sp_proc_intercepts_black(sp_global_ptr)
+
+#define init_screen(specsarg) sp_init_screen(sp_global_ptr,specsarg)
+#define begin_char_screen(Psw,Pmin,Pmax) sp_begin_char_screen(sp_global_ptr,Psw,Pmin,Pmax)
+#define begin_contour_screen(P1,outside) sp_begin_contour_screen(sp_global_ptr,P1,outside)
+#define curve_screen(P1,P2,P3,depth) sp_curve_screen(sp_global_ptr,P1,P2,P3,depth)
+#define scan_curve_screen(X0,Y0,X1,Y1,X2,Y2,X3,Y3) sp_scan_curve_screen(sp_global_ptr,X0,Y0,X1,Y1,X2,Y2,X3,Y3) 
+#define vert_line_screen(x,y1,y2) sp_vert_line_screen(sp_global_ptr,x,y1,y2)
+#define line_screen(P1) sp_line_screen(sp_global_ptr,P1)
+#define end_char_screen() sp_end_char_screen(sp_global_ptr)
+#define end_contour_screen() sp_end_contour_screen(sp_global_ptr)
+#define add_intercept_screen(y,x) sp_add_intercept_screen(sp_global_ptr,y,x)
+#define proc_intercepts_screen() sp_proc_intercepts_screen(sp_global_ptr)
+
+#define init_outline(specsarg) sp_init_outline(sp_global_ptr,specsarg)
+#define begin_char_outline(Psw,Pmin,Pmax) sp_begin_char_outline(sp_global_ptr,Psw,Pmin,Pmax)
+#define begin_sub_char_outline(Psw,Pmin,Pmax) sp_begin_sub_char_outline(sp_global_ptr,Psw,Pmin,Pmax)
+#define begin_contour_outline(P1,outside) sp_begin_contour_outline(sp_global_ptr,P1,outside)
+#define curve_outline(P1,P2,P3,depth) sp_curve_outline(sp_global_ptr,P1,P2,P3,depth)
+#define line_outline(P1) sp_line_outline(sp_global_ptr,P1)
+#define end_contour_outline() sp_end_contour_outline(sp_global_ptr)
+#define end_sub_char_outline() sp_end_sub_char_outline(sp_global_ptr)
+#define end_char_outline() sp_end_char_outline(sp_global_ptr)
+
+#define init_2d(specsarg) sp_init_2d(sp_global_ptr,specsarg)
+#define begin_char_2d(Psw, Pmin, Pmax) sp_begin_char_2d(sp_global_ptr,Psw, Pmin, Pmax)
+#define begin_contour_2d(P1, outside) sp_begin_contour_2d(sp_global_ptr,P1, outside)
+#define line_2d(P1) sp_line_2d(sp_global_ptr,P1)
+#define end_char_2d() sp_end_char_2d(sp_global_ptr)
+#define add_intercept_2d(y, x) sp_add_intercept_2d(sp_global_ptr,y, x)
+#define proc_intercepts_2d() sp_proc_intercepts_2d(sp_global_ptr)
+#define draw_vector_to_2d(x0, y0, x1, y1, band) sp_draw_vector_to_2d(sp_global_ptr,x0, y0, x1, y1, band)
+
+#define init_char_out(Psw,Pmin,Pmax) sp_init_char_out(sp_global_ptr,Psw,Pmin,Pmax)
+#define begin_sub_char_out(Psw,Pmin,Pmax) sp_begin_sub_char_out(sp_global_ptr,Psw,Pmin,Pmax)
+#define curve_out(P1,P2,P3,depth) sp_curve_out(sp_global_ptr,P1,P2,P3,depth)
+#define end_contour_out() sp_end_contour_out(sp_global_ptr)
+#define end_sub_char_out() sp_end_sub_char_out(sp_global_ptr)
+#define init_intercepts_out() sp_init_intercepts_out(sp_global_ptr)
+#define restart_intercepts_out() sp_restart_intercepts_out(sp_global_ptr)
+#define set_first_band_out(Pmin,Pmax) sp_set_first_band_out(sp_global_ptr,Pmin,Pmax)
+#define reduce_band_size_out() sp_reduce_band_size_out(sp_global_ptr)
+#define next_band_out() sp_next_band_out(sp_global_ptr)
+
+#define init_userout(specsarg) sp_init_userout(sp_global_ptr,specsarg)
+
+#define reset() sp_reset(sp_global_ptr)
+#define set_key(key) sp_set_key(sp_global_ptr,key)
+#define get_cust_no(font_buff) sp_get_cust_no(sp_global_ptr,font_buff)
+#define set_specs(specsarg) sp_set_specs(sp_global_ptr,specsarg)
+#define setup_consts(xmin,xmax,ymin,ymax) sp_setup_consts(sp_global_ptr,xmin,xmax,ymin,ymax)
+#define setup_tcb(ptcb) sp_setup_tcb(sp_global_ptr,ptcb)
+#define setup_mult(input_mult) sp_setup_mult(sp_global_ptr,input_mult)
+#define setup_offset(input_offset) sp_setup_offset(sp_global_ptr,input_offset)
+#define type_tcb(ptcb) sp_type_tcb(sp_global_ptr,ptcb)
+#define read_long(pointer) sp_read_long(sp_global_ptr,pointer)
+#define read_word_u(pointer) sp_read_word_u(sp_global_ptr,pointer)
+#define init_tcb() sp_init_tcb(sp_global_ptr)
+#define scale_tcb(ptcb,x_pos,y_pos,x_scale,y_scale) sp_scale_tcb(sp_global_ptr,ptcb,x_pos,y_pos,x_scale,y_scale)
+#define plaid_tcb(ppointer,format) sp_plaid_tcb(sp_global_ptr,ppointer,format)
+#define skip_orus(ppointer,short_form,no_ctrl_zones) sp_skip_orus(sp_global_ptr,ppointer,short_form,no_ctrl_zones)
+#define skip_interpolation_table(ppointer,format) sp_skip_interpolation_table(sp_global_ptr,ppointer,format)
+#define skip_control_zone(ppointer,format) sp_skip_control_zone(sp_global_ptr,ppointer,format)
+#define constr_update() sp_constr_update(sp_global_ptr)
+#define read_oru_table(ppointer) sp_read_oru_table(sp_global_ptr,ppointer)
+#define calculate_x_pix(start_edge,end_edge,constr_nr,x_scale,x_offset,ppo,setwidth_pix) sp_calculate_x_pix(sp_global_ptr,start_edge,end_edge,constr_nr,x_scale,x_offset,ppo,setwidth_pix)
+#define calculate_y_pix(start_edge,end_edge,constr_nr,top_scale,bottom_scale,ppo,emtop_pix,embot_pix) sp_calculate_y_pix(sp_global_ptr,start_edge,end_edge,constr_nr,top_scale,bottom_scale,ppo,emtop_pix,embot_pix)
+#define calculate_x_scale(x_factor,x_offset,no_x_ctrl_zones) sp_calculate_x_scale(sp_global_ptr,x_factor,x_offset,no_x_ctrl_zones)
+#define calculate_y_scale(top_scale,bottom_scale,first_y_zone,no_Y_ctrl_zones) sp_calculate_y_scale(sp_global_ptr,top_scale,bottom_scale,first_y_zone,no_Y_ctrl_zones) 
+#define setup_pix_table(ppointer,short_form,no_X_ctrl_zones,no_Y_ctrl_zones) sp_setup_pix_table(sp_global_ptr,ppointer,short_form,no_X_ctrl_zones,no_Y_ctrl_zones)
+#define setup_int_table(ppointer,no_X_int_zones, no_Y_int_zones) sp_setup_int_table(sp_global_ptr,ppointer,no_X_int_zones, no_Y_int_zones)
+
+#define fn_init_out(specsarg) (*sp_globals.init_out)(sp_global_ptr,specsarg)  
+#define fn_begin_char(Psw,Pmin,Pmax) (*sp_globals.begin_char)(sp_global_ptr,Psw,Pmin,Pmax)
+#define fn_begin_sub_char(Psw,Pmin,Pmax) (*sp_globals.begin_sub_char)(sp_global_ptr,Psw,Pmin,Pmax)
+#define fn_end_sub_char() (*sp_globals.end_sub_char)(sp_global_ptr)
+#define fn_end_char() (*sp_globals.end_char)(sp_global_ptr)
+#define fn_line(P1) (*sp_globals.line)(sp_global_ptr,P1)
+#define fn_end_contour() (*sp_globals.end_contour)(sp_global_ptr)
+#define fn_begin_contour(P0,fmt) (*sp_globals.begin_contour)(sp_global_ptr,P0,fmt)
+#define fn_curve(P1,P2,P3,depth) (*sp_globals.curve)(sp_global_ptr,P1,P2,P3,depth)
+
+
+#define load_char_data(offset, no_bytes, buff_off) sp_load_char_data(sp_global_ptr, offset, no_bytes, buff_off)
+#define report_error(n) sp_report_error(sp_global_ptr, n)
+
+#if INCL_MULTIDEV
+
+#define set_bitmap_device(bfuncs,size) sp_set_bitmap_device(sp_global_ptr,bfuncs,size)
+#define set_outline_device(ofuncs,size) sp_set_outline_device(sp_global_ptr,ofuncs,size)
+
+#define open_bitmap(x_set_width, y_set_width, xmin, xmax, ymin, ymax)(*sp_globals.bitmap_device.p_open_bitmap)(sp_global_ptr,x_set_width, y_set_width, xmin, xmax, ymin, ymax)
+#define set_bitmap_bits(y, xbit1, xbit2)(*sp_globals.bitmap_device.p_set_bits)(sp_global_ptr,y, xbit1, xbit2)
+#define close_bitmap()(*sp_globals.bitmap_device.p_close_bitmap)(sp_global_ptr)
+
+#define open_outline(x_set_width, y_set_width, xmin, xmax, ymin, ymax)(*sp_globals.outline_device.p_open_outline)(sp_global_ptr,x_set_width, y_set_width, xmin, xmax, ymin, ymax)
+#define start_new_char()(*sp_globals.outline_device.p_start_char)(sp_global_ptr)
+#define start_contour(x,y,outside)(*sp_globals.outline_device.p_start_contour)(sp_global_ptr,x,y,outside)
+#define curve_to(x1,y1,x2,y2,x3,y3)(*sp_globals.outline_device.p_curve)(sp_global_ptr,x1,y1,x2,y2,x3,y3)
+#define line_to(x,y)(*sp_globals.outline_device.p_line)(sp_global_ptr,x,y)
+#define close_contour()(*sp_globals.outline_device.p_close_contour)(sp_global_ptr)
+#define close_outline()(*sp_globals.outline_device.p_close_outline)(sp_global_ptr)
+
+#else
+
+#define open_bitmap(x_set_width, y_set_width, xmin, xmax, ymin, ymax) sp_open_bitmap(sp_global_ptr, x_set_width, y_set_width, xmin, xmax, ymin, ymax)
+#define set_bitmap_bits(y, xbit1, xbit2) sp_set_bitmap_bits(sp_global_ptr, y, xbit1, xbit2)
+#define close_bitmap() sp_close_bitmap(sp_global_ptr)
+
+#define open_outline(x_set_width, y_set_width, xmin, xmax, ymin, ymax) sp_open_outline(sp_global_ptr, x_set_width, y_set_width, xmin, xmax, ymin, ymax)
+#define start_new_char() sp_start_new_char(sp_global_ptr )
+#define start_contour(x,y,outside) sp_start_contour(sp_global_ptr, x,y,outside)
+#define curve_to(x1,y1,x2,y2,x3,y3) sp_curve_to(sp_global_ptr, x1,y1,x2,y2,x3,y3)
+#define line_to(x,y) sp_line_to(sp_global_ptr, x,y)
+#define close_contour() sp_close_contour(sp_global_ptr)
+#define close_outline() sp_close_outline(sp_global_ptr)
+
+#endif
+#endif
+
+
diff --git a/Xserver/lib/font/Speedo/speedo.h b/Xserver/lib/font/Speedo/speedo.h
new file mode 100644 (file)
index 0000000..8c93afa
--- /dev/null
@@ -0,0 +1,1081 @@
+/* $XConsortium: speedo.h,v 1.7 95/06/08 23:20:39 gildea Exp $ */
+
+/*
+
+Copyright 1989-1991, Bitstream Inc., Cambridge, MA.
+You are hereby granted permission under all Bitstream propriety rights to
+use, copy, modify, sublicense, sell, and redistribute the Bitstream Speedo
+software and the Bitstream Charter outline font for any purpose and without
+restrictions; provided, that this notice is left intact on all copies of such
+software or font and that Bitstream's trademark is acknowledged as shown below
+on all unmodified copies of such font.
+
+BITSTREAM CHARTER is a registered trademark of Bitstream Inc.
+
+
+BITSTREAM INC. DISCLAIMS ANY AND ALL WARRANTIES, EXPRESS OR IMPLIED, INCLUDING
+WITHOUT LIMITATION THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+PARTICULAR PURPOSE.  BITSTREAM SHALL NOT BE LIABLE FOR ANY DIRECT OR INDIRECT
+DAMAGES, INCLUDING BUT NOT LIMITED TO LOST PROFITS, LOST DATA, OR ANY OTHER
+INCIDENTAL OR CONSEQUENTIAL DAMAGES, ARISING OUT OF OR IN ANY WAY CONNECTED
+WITH THE SPEEDO SOFTWARE OR THE BITSTREAM CHARTER OUTLINE FONT.
+
+*/
+
+#ifndef _SPEEDO_H_
+#define _SPEEDO_H_
+
+#include <X11/Xmd.h>
+
+/***************************** S P E E D O . H *******************************
+ ****************************************************************************/
+
+/*****  USER OPTIONS OVERRIDE DEFAULTS ******/
+#include "useropt.h"
+
+/*****  CONFIGURATION DEFINITIONS *****/
+
+#ifndef INCL_CLIPPING
+#define INCL_CLIPPING 0                /* 0 indicates CLIPPING code is not compiled in*/
+#endif
+
+#ifndef INCL_SQUEEZING
+#define INCL_SQUEEZING 0               /* 0 indicates SQUEEZE code is not compiled in*/
+#endif
+
+#ifndef INCL_EXT
+#define  INCL_EXT       1          /* 1 to include extended font support */
+#endif                             /* 0 to omit extended font support */
+
+#ifndef INCL_RULES
+#define  INCL_RULES     1          /* 1 to include intelligent scaling support */
+#endif                             /* 0 to omit intelligent scaling support */
+
+#ifndef INCL_BLACK                                                    
+#define  INCL_BLACK     1          /* 1 to include blackwriter output support */
+#endif                             /* 0 to omit output mode 0 support */
+
+#ifndef INCL_SCREEN
+#define  INCL_SCREEN     0          /* 1 to include screen writeroutput support */
+#endif                             /* 0 to omit support */
+
+#ifndef INCL_OUTLINE
+#define  INCL_OUTLINE     0          /* 1 to include outline output support */
+#endif                             /* 0 to omit output mode 2 support */
+
+#ifndef INCL_2D
+#define  INCL_2D          0          /* 1 to include 2d blackwriter output support */
+#endif                             /* 0 to omit output mode 3 support */
+
+#ifndef INCL_USEROUT
+#define INCL_USEROUT      0          /* 1 to include user defined output module support */
+#endif                               /* 0 to omit user defined output module support */
+
+#ifndef INCL_LCD
+#define  INCL_LCD       1          /* 1 to include load char data support*/
+#endif                             /* 0 to omit load char data support */
+#ifndef INCL_ISW
+#define  INCL_ISW       0          /* 1 to include imported width support */
+#endif                             /* 0 to omit imported width support */
+
+#ifndef INCL_METRICS
+#define  INCL_METRICS   1          /* 1 to include metrics support */
+#endif                             /* 0 to omit metrics support */
+
+#ifndef INCL_KEYS
+#define  INCL_KEYS      0          /* 1 to include multi key support */
+#endif                             /* 0 to omit multi key support */
+
+#ifndef INCL_MULTIDEV
+#define  INCL_MULTIDEV  0          /* 1 to include multiple output device support */
+#endif                             /* 0 to omit multi device support */
+
+#ifndef SHORT_LISTS
+#define SHORT_LISTS 1                  /* 1 to allocate small intercept lists */
+#endif
+
+#ifndef PROTOS_AVAIL                /* 1 to use function prototyping */
+#define PROTOS_AVAIL 0                         /* 0 to suppress it */
+#endif
+
+#ifndef FONTFAR                                                /* if Intel mixed memory model implementation */
+#define FONTFAR                                                /* pointer type modifier for font buffer */
+#endif
+
+#ifndef STACKFAR                                       /* if Intel mixed memory model implementation */
+#define STACKFAR                                       /* pointer type modifier for font buffer */
+#endif
+
+#ifndef GLOBALFAR
+#define GLOBALFAR
+#endif
+#define MODE_BLACK 0
+#define MODE_SCREEN MODE_BLACK + INCL_BLACK
+#define MODE_OUTLINE MODE_SCREEN + INCL_SCREEN
+#define MODE_2D MODE_OUTLINE + INCL_OUTLINE
+
+#ifdef DYNAMIC_ALLOC
+#if DYNAMIC_ALLOC 
+#define STATIC_ALLOC 0
+#endif
+#endif
+
+#ifdef REENTRANT_ALLOC
+#if REENTRANT_ALLOC 
+#define STATIC_ALLOC 0
+#endif
+#endif
+
+#ifndef STATIC_ALLOC
+#define STATIC_ALLOC 1
+#endif
+
+#ifndef DYNAMIC_ALLOC
+#define DYNAMIC_ALLOC 0
+#endif
+
+#ifndef REENTRANT_ALLOC
+#define REENTRANT_ALLOC 0
+#endif
+
+/*****  TYPE  DEFINITIONS *****/
+
+#ifndef STDEF
+#ifndef SPD_BMAP
+
+typedef INT8 fix7;
+
+typedef   double   real;
+
+typedef   CARD8    ufix8;
+#ifndef VFONT
+typedef   CARD8    boolean;
+#endif
+#endif
+
+typedef   INT16    fix15;
+
+typedef   CARD16   ufix16;
+
+typedef   INT32    fix31;
+
+typedef   CARD32   ufix32;
+#endif
+
+/***** GENERAL CONSTANTS *****/
+
+#ifndef FALSE
+#define  FALSE     0
+#define  TRUE      1
+#endif
+
+#ifndef NULL
+#define NULL       0
+#endif
+
+#define  FUNCTION
+
+#define  BIT0           0x01
+#define  BIT1           0x02
+#define  BIT2           0x04
+#define  BIT3           0x08
+#define  BIT4           0x10
+#define  BIT5           0x20
+#define  BIT6           0x40
+#define  BIT7           0x80
+
+#if INCL_EXT                       /* Extended fonts supported? */
+
+#define  MAX_CONSTR     750       /* Max constraints (incl 4 dummies) */
+#define  MAX_CTRL_ZONES  256       /* Max number of controlled orus */
+#define  MAX_INT_ZONES   256       /* Max number of interpolation zones */
+
+#else                              /* Compact fonts only supported */
+
+#define  MAX_CONSTR      512       /* Max constraints (incl 4 dummies) */
+#define  MAX_CTRL_ZONES   64       /* Max number of controlled orus */
+#define  MAX_INT_ZONES    64       /* Max number of interpolation zones */
+
+#endif
+
+#define  SCALE_SHIFT   12   /* Binary point positiion for scale values */
+#define  SCALE_RND   2048   /* Rounding bit for scaling transformation */
+#define  ONE_SCALE   4096   /* Unity scale value */
+    
+#ifdef INCL_SCREEN   /* constants used by Screenwriter module */
+#define LEFT_INT 1   /* left intercept */
+#define END_INT 2    /* last intercept */
+#define FRACTION 0xFC  /* fractional portion of intercept type list */
+#endif
+
+#if INCL_SQUEEZING || INCL_CLIPPING          /* constants used by SQUEEZEing code */
+#define EM_TOP 764
+#define EM_BOT -236
+#endif
+
+/*****  STRUCTURE DEFINITIONS *****/
+#if PROTOS_AVAIL
+
+#if REENTRANT_ALLOC
+#define PROTO_DECL1 struct speedo_global_data GLOBALFAR *sp_global_ptr
+#define PROTO_DECL2 PROTO_DECL1 ,
+#else
+#define PROTO_DECL1 void
+#define PROTO_DECL2
+#endif
+#endif
+
+typedef
+struct buff_tag
+    {
+    ufix8 FONTFAR *org;                   /* Pointer to start of buffer */
+    ufix32  no_bytes;              /* Size of buffer in bytes */
+    } 
+buff_t;                            /* Buffer descriptor */
+
+typedef  struct constr_tag
+    {
+    ufix8 FONTFAR *org;                   /* Pointer to first byte in constr data  */
+    ufix16  font_id;               /* Font id for calculated data           */
+    fix15   xppo;                  /* X pixels per oru for calculated data  */
+    fix15   yppo;                  /* Y pixels per oru for calculated data  */
+    boolean font_id_valid;         /* TRUE if font id valid                 */
+    boolean data_valid;            /* TRUE if calculated data valid         */
+    boolean active;                /* TRUE if constraints enabled           */
+    }                  
+constr_t;                          /* Constraint data state                 */
+
+typedef  struct kern_tag
+    {
+    ufix8 FONTFAR *tkorg;                 /* First byte of track kerning data      */
+    ufix8 FONTFAR *pkorg;                 /* First byte of pair kerning data       */
+    fix15   no_tracks;             /* Number of kerning tracks              */
+    fix15   no_pairs;              /* Number of kerning pairs               */
+    }                  
+kern_t;                            /* Kerning control block                 */
+
+typedef struct specs_tag
+    {
+    buff_t STACKFAR *pfont;                 /* Pointer to font data                  */
+    fix31   xxmult;                /* Coeff of X orus to compute X pix      */
+    fix31   xymult;                /* Coeff of Y orus to compute X pix      */
+    fix31   xoffset;               /* Constant to compute X pix             */
+    fix31   yxmult;                /* Coeff of X orus to compute Y pix      */
+    fix31   yymult;                /* Coeff of Y orus to compute Y pix      */
+    fix31   yoffset;               /* Constant to compute Y pix             */
+    ufix32  flags;                 /* Mode flags:                           */
+                                   /*   Bit  0 - 2: Output module selector: */
+                                   /*   Bit  3: Send curves to output module*/
+                                   /*   Bit  4: Use linear scaling if set   */
+                                   /*   Bit  5: Inhibit constraint table    */
+                                   /*   Bit  6: Import set width if set     */
+                                   /*   Bit  7:   not used                  */
+                                   /*   Bit  8: Squeeze left if set         */
+                                   /*   Bit  9: Squeeze right if set        */
+                                   /*   Bit 10: Squeeze top if set          */
+                                   /*   Bit 11: Squeeze bottom if set       */
+                                   /*   Bit 12: Clip left if set            */
+                                   /*   Bit 13: Clip right if set           */
+                                   /*   Bit 14: Clip top if set             */
+                                   /*   Bit 15: Clip bottom if set          */
+                                   /*   Bits 16-31   not used               */
+#ifdef __STDC__
+    void *out_info;                /* information for output module         */
+#else
+    char *out_info;
+#endif
+    }
+specs_t;                           /* Specs structure for fw_set_specs      */
+
+typedef struct tcb_tag
+    {
+    fix15   xxmult;                /* Linear coeff of Xorus to compute Xpix */
+    fix15   xymult;                /* Linear coeff of Yorus to compute Xpix */
+    fix31   xoffset;               /* Linear constant to compute Xpix       */
+    fix15   yxmult;                /* Linear coeff of Xorus to compute Ypix */
+    fix15   yymult;                /* Linear coeff of Yorus to compute Ypix */
+    fix31   yoffset;               /* Linear constant to compute Ypix       */
+    fix15   xppo;                  /* Pixels per oru in X dimension of char */
+    fix15   yppo;                  /* Pixels per oru in Y dimension of char */
+    fix15   xpos;                  /* Origin in X dimension of character    */
+    fix15   ypos;                  /* Origin in Y dimension of character    */
+    ufix16  xtype;                 /* Transformation type for X oru coords  */
+    ufix16  ytype;                 /* Transformation type for Y oru coords  */
+    ufix16  xmode;                 /* Transformation mode for X oru coords  */
+    ufix16  ymode;                 /* Transformation mode for Y oru coords  */
+       fix15  mirror;                /* Transformation creates mirror image   */
+    }
+tcb_t;                             /* Transformation control block          */
+
+typedef struct point_tag
+    {
+    fix15   x;                     /* X coord of point (shifted pixels)     */
+    fix15   y;                     /* Y coord of point (shifted pixels)     */
+    }
+point_t;                           /* Point in device space                 */
+
+typedef struct band_tag
+    {
+    fix15   band_max;
+    fix15   band_min;
+    fix15   band_array_offset;
+    fix15   band_floor;
+    fix15   band_ceiling;
+    } band_t;
+
+typedef struct bbox_tag
+    {
+    fix31   xmin;
+    fix31   xmax;
+    fix31   ymin;
+    fix31   ymax;
+    } bbox_t;
+
+#if SHORT_LISTS 
+#define  MAX_INTERCEPTS  256      /* Max storage for intercepts */
+typedef  ufix8   cdr_t;           /* 8 bit links in intercept chains */
+#else
+#define  MAX_INTERCEPTS 1000      /* Max storage for intercepts */
+typedef  ufix16   cdr_t;          /* 16 bit links in intercept chains */
+#endif
+
+#if REENTRANT_ALLOC
+
+typedef struct intercepts_tag
+    {
+       fix15 car[MAX_INTERCEPTS];
+       fix15 cdr[MAX_INTERCEPTS];
+#if INCL_SCREEN
+       ufix8 inttype[MAX_INTERCEPTS];
+       ufix8 leftedge;
+       ufix16 fracpix;
+#endif
+       } intercepts_t;
+
+typedef struct plaid_tag
+       {
+       fix15    orus[MAX_CTRL_ZONES];   /* Controlled coordinate table (orus) */
+#if INCL_RULES
+       fix15    pix[MAX_CTRL_ZONES];    /* Controlled coordinate table (sub-pixels) */
+       fix15    mult[MAX_INT_ZONES];    /* Interpolation multiplier table */
+       fix31    offset[MAX_INT_ZONES];  /* Interpolation offset table */
+#endif
+       } plaid_t;
+#endif
+
+#if INCL_MULTIDEV
+#if PROTOS_AVAIL
+typedef struct bitmap_tag 
+       {
+       void (*p_open_bitmap)(PROTO_DECL2 fix31 x_set_width, fix31 y_set_width, fix31 xorg, fix31 yorg, fix15 xsize,fix15 ysize);
+       void (*p_set_bits)(PROTO_DECL2 fix15 y, fix15 xbit1, fix15 xbit2);
+       void (*p_close_bitmap)(PROTO_DECL1);
+       } bitmap_t;
+
+typedef struct outline_tag 
+       {
+       void (*p_open_outline)(PROTO_DECL2 fix31 x_set_width, fix31 y_set_width, fix31 xmin, fix31 xmax, fix31 ymin,fix31 ymax);
+       void (*p_start_char)(PROTO_DECL1);
+       void (*p_start_contour)(PROTO_DECL2 fix31 x,fix31 y,boolean outside);
+       void (*p_curve)(PROTO_DECL2 fix31 x1, fix31 y1, fix31 x2, fix31 y2, fix31 x3, fix31 y3);
+       void (*p_line)(PROTO_DECL2 fix31 x, fix31 y);
+       void (*p_close_contour)(PROTO_DECL1);
+       void (*p_close_outline)(PROTO_DECL1);
+       } outline_t;
+#else
+typedef struct bitmap_tag 
+       {
+       void (*p_open_bitmap)();
+       void (*p_set_bits)();
+       void (*p_close_bitmap)();
+       } bitmap_t;
+
+typedef struct outline_tag 
+       {
+       void (*p_open_outline)();
+       void (*p_start_char)();
+       void (*p_start_contour)();
+       void (*p_curve)();
+       void (*p_line)();
+       void (*p_close_contour)();
+       void (*p_close_outline)();
+       } outline_t;
+#endif
+#endif
+
+/* ---------------------------------------------------*/
+/****  MAIN GLOBAL DATA STRUCTURE, SPEEDO_GLOBALS *****/
+
+typedef struct speedo_global_data 
+       {
+/*  do_char.c data definitions */
+#if INCL_METRICS                    /* Metrics functions supported? */
+         kern_t  kern;              /* Kerning control block */
+#endif                                                               /* endif incl_metrics */
+        point_t   Psw;             /* End of escapement vector (1/65536 pixel units) */
+
+#if INCL_LCD                        /* Dynamic load character data supported? */
+         fix15  cb_offset;          /* Offset to sub-char data in char buffer */
+#endif                                                               /* endif incl_lcd */
+
+/* do_trns.c data definitions */
+        point_t  P0;               /* Current point (sub-pixels) */
+        fix15    x_orus;           /* Current X argument (orus) */
+        fix15    y_orus;           /* Current Y argument (orus) */
+        fix15    x_pix;            /* Current X argument (sub-pixels) */
+        fix15    y_pix;            /* Current Y argument (sub-pixels) */
+        ufix8    x_int;            /* Current X interpolation zone */
+        ufix8    y_int;            /* Current Y interpolation zone */
+
+#if INCL_MULTIDEV && INCL_OUTLINE
+     outline_t outline_device;
+     boolean   outline_device_set;
+#endif
+
+#if INCL_BLACK || INCL_SCREEN || INCL_2D
+#if INCL_MULTIDEV
+     bitmap_t bitmap_device;
+     boolean  bitmap_device_set;
+#endif
+     band_t   y_band;           /* Y current band(whole pixels) */
+
+        struct set_width_tag
+        {
+        fix31 x;
+        fix31 y;
+        } set_width; /* Character escapement vector */
+
+        boolean  first_pass;       /* TRUE during first pass thru outline data */
+        boolean  extents_running;  /* T if extent accumulation for each vector */
+        fix15    x0_spxl;          /* X coord of current point (sub pixels) */
+        fix15    y0_spxl;          /* Y coord of current point (sub pixels) */
+        fix15    y_pxl;            /* Y coord of current point (whole pixels) */
+#if REENTRANT_ALLOC
+     intercepts_t STACKFAR *intercepts;
+#else                                                                /* else if not reentrant */
+        fix15    car[MAX_INTERCEPTS]; /* Data field of intercept storage */
+        cdr_t    cdr[MAX_INTERCEPTS]; /* Link field of intercept storage */
+#if INCL_SCREEN
+         ufix8    inttype[MAX_INTERCEPTS];
+         ufix8    leftedge;
+         ufix16   fracpix;
+#endif                                                               /* endif incl_screen */
+#endif                                                               /* endif reentrant */
+        fix15    bmap_xmin;        /* Min X value (sub-pixel units) */
+        fix15    bmap_xmax;        /* Max X value (sub-pixel units) */
+        fix15    bmap_ymin;        /* Min Y value (sub-pixel units) */
+        fix15    bmap_ymax;        /* Max Y value (sub-pixel units) */
+        fix15    no_y_lists;       /* Number of active intercept lists */
+        fix15    first_offset;     /* Index of first active list cell */
+        fix15    next_offset;      /* Index of next free list cell */
+        boolean  intercept_oflo;   /* TRUE if intercepts data lost */
+#endif                                                               /* endif incl_black, incl_screen, incl_2d */
+
+/* bounding box now used by all output modules, including outline */
+        fix15    xmin;             /* Min X value in whole character */
+        fix15    xmax;             /* Max X value in whole character */
+        fix15    ymin;             /* Min Y value in whole character */
+        fix15    ymax;             /* Max Y value in whole character */
+
+#if INCL_2D
+         fix15    no_x_lists;       /* Number of active x intercept lists */
+         band_t   x_band;           /* X current band(whole pixels) */
+         boolean  x_scan_active;    /* X scan flag during scan conversion */
+#endif
+
+/* reset.c data definitions */
+         ufix16   key32;            /* Decryption keys 3,2 combined */
+         ufix8    key4;             /* Decryption key 4 */
+         ufix8    key6;             /* Decryption key 6 */
+         ufix8    key7;             /* Decryption key 7 */
+         ufix8    key8;             /* Decryption key 8 */
+
+/* set_spcs.c data definitions */
+         buff_t   font;
+         buff_t GLOBALFAR *pfont; /* Pointer to font buffer structure */
+         fix31    font_buff_size; /* Number of bytes loaded in font buffer */
+         ufix8 FONTFAR *pchar_dir; /* Pointer to character directory */
+         fix15    first_char_idx; /* Index to first character in font */
+         fix15    no_chars_avail; /* Total characters in font layout */
+         fix15    orus_per_em;    /* Outline resolution */
+         fix15    metric_resolution; /* metric resolution for setwidths, kerning pairs
+                                                       (defaults to orus_per_em) */
+         tcb_t    tcb0;           /* Top level transformation control block */
+       
+         boolean  specs_valid;    /* TRUE if fw_set_specs() successful */
+       
+         fix15    depth_adj;      /* Curve splitting depth adjustment */
+         boolean  curves_out;     /* Allow curves to output module */
+         fix15    output_mode;    /* Output module selector */
+         fix15    thresh;         /* Scan conversion threshold (sub-pixels) */
+         boolean  normal;         /* TRUE if 0 obl and mult of 90 deg rot  */
+       
+         fix15    multshift;      /* Fixed point shift for multipliers */
+         fix15    pixshift;       /* Fixed point shift for sub-pixels */
+         fix15    poshift;        /* Left shift from pixel to output format */
+         fix15    mpshift;        /* Fixed point shift for mult to sub-pixels */
+         fix31    multrnd;        /* 0.5 in multiplier units */
+         fix15    pixrnd;         /* 0.5 in sub-pixel units */
+         fix31    mprnd;          /* 0.5 sub-pixels in multiplier units */
+         fix15    pixfix;         /* Mask to remove fractional pixels */
+         fix15    onepix;         /* 1.0 pixels in sub-pixel units */
+
+#if PROTOS_AVAIL
+         boolean (*init_out)(PROTO_DECL2 specs_t GLOBALFAR *specsarg);
+         boolean (*begin_char)(PROTO_DECL2 point_t Psw,point_t Pmin,point_t Pmax); 
+         void    (*begin_sub_char)(PROTO_DECL2 point_t Psw,point_t Pmin,point_t Pmax);
+         void    (*begin_contour)(PROTO_DECL2 point_t P1,boolean outside); 
+         void    (*curve)(PROTO_DECL2 point_t P1, point_t P2, point_t P3, fix15 depth);  
+         void    (*line)(PROTO_DECL2 point_t P1);               
+         void    (*end_contour)(PROTO_DECL1); 
+         void    (*end_sub_char)(PROTO_DECL1);
+         boolean (*end_char)(PROTO_DECL1);    
+#else                                                                /* if not protos */
+         boolean (*init_out)();
+         boolean (*begin_char)(); 
+         void    (*begin_sub_char)();
+         void    (*begin_contour)(); 
+         void    (*curve)();         
+         void    (*line)();               
+         void    (*end_contour)(); 
+         void    (*end_sub_char)();
+         boolean (*end_char)();
+#endif                                                               /* end not protos */
+
+         specs_t GLOBALFAR *pspecs;    /* Pointer to specifications bundle */
+         specs_t specs;                /* copy specs onto stack */
+         ufix8 FONTFAR  *font_org;     /* Pointer to start of font data */
+         ufix8 FONTFAR  *hdr2_org;     /* Pointer to start of private header data */
+
+/* set_trns.c data definitions */
+         tcb_t    tcb;                 /* Current transformation control block */
+         ufix8    Y_edge_org;          /* Index to first Y controlled coordinate */
+         ufix8    Y_int_org;           /* Index to first Y interpolation zone */
+         fix31    rnd_xmin;            /* rounded out value of xmin for int-char spac. fix */
+
+#if REENTRANT_ALLOC
+         plaid_t STACKFAR  *plaid;
+#else                                                                /* if not reentrant */
+         fix15    orus[MAX_CTRL_ZONES];   /* Controlled coordinate table (orus) */
+#if INCL_RULES
+         fix15    pix[MAX_CTRL_ZONES];    /* Controlled coordinate table (sub-pixels) */
+         fix15    mult[MAX_INT_ZONES];    /* Interpolation multiplier table */
+         fix31    offset[MAX_INT_ZONES];  /* Interpolation offset table */
+#endif                                                               /* endif incl_rules */
+#endif                                                               /* endif not reentrant */
+
+         fix15    no_X_orus;              /* Number of X controlled coordinates */
+         fix15    no_Y_orus;              /* Number of Y controlled coordinates */
+         ufix16   Y_constr_org;           /* Origin of constraint table in font data */
+
+#if INCL_RULES
+         constr_t constr;                 /* Constraint data state */
+         boolean  c_act[MAX_CONSTR];      /* TRUE if constraint currently active */
+         fix15    c_pix[MAX_CONSTR];      /* Size of constrained zone if active */
+#endif                                                            
+#if  INCL_ISW       
+         boolean import_setwidth_act;     /* boolean to indicate imported setwidth */
+        boolean isw_modified_constants;
+         ufix32 imported_width;                  /* value of imported setwidth */      
+        fix15 isw_xmax;                  /* maximum oru value for constants*/
+#endif
+#if INCL_SQUEEZING || INCL_ISW
+         fix15 setwidth_orus;             /* setwidth value in orus */
+       /* bounding box in orus for squeezing */
+         fix15 bbox_xmin_orus;           /* X minimum in orus */
+         fix15 bbox_xmax_orus;            /* X maximum in orus */
+         fix15 bbox_ymin_orus;            /* Y minimum in orus */
+         fix15 bbox_ymax_orus;            /* Y maximum in orus */
+#endif
+#ifdef INCL_SQUEEZING
+         boolean squeezing_compound;       /* flag to indicate a compound character*/
+#endif
+#ifdef INCL_CLIPPING
+       fix31 clip_xmax;
+       fix31 clip_ymax;
+       fix31 clip_xmin;
+       fix31 clip_ymin;
+#endif
+       } SPEEDO_GLOBALS;
+
+/***********************************************************************************
+ *
+ *  Speedo global data structure allocation 
+ *
+ ***********************************************************************************/
+
+#ifdef SET_SPCS
+#define EXTERN 
+#else
+#define EXTERN extern
+#endif
+#if STATIC_ALLOC
+EXTERN SPEEDO_GLOBALS GLOBALFAR sp_globals;
+#define sp_intercepts sp_globals
+#define sp_plaid sp_globals
+#else
+#if DYNAMIC_ALLOC
+EXTERN SPEEDO_GLOBALS GLOBALFAR *sp_global_ptr;
+#define sp_globals (*sp_global_ptr)
+#define sp_intercepts (*sp_global_ptr)
+#define sp_plaid (*sp_global_ptr)
+#else
+#if REENTRANT_ALLOC
+#define sp_globals (*sp_global_ptr)
+#define sp_intercepts (*(*sp_global_ptr).intercepts)
+#define sp_plaid (*(*sp_global_ptr).plaid)
+#endif
+#endif
+#endif
+#ifdef EXTERN
+#undef EXTERN
+#endif
+
+
+/***** PUBLIC FONT HEADER OFFSET CONSTANTS  *****/
+#define  FH_FMVER    0      /* U   D4.0 CR LF NULL NULL  8 bytes            */
+#define  FH_FNTSZ    8      /* U   Font size (bytes) 4 bytes                */
+#define  FH_FBFSZ   12      /* U   Min font buffer size (bytes) 4 bytes     */
+#define  FH_CBFSZ   16      /* U   Min char buffer size (bytes) 2 bytes     */
+#define  FH_HEDSZ   18      /* U   Header size (bytes) 2 bytes              */
+#define  FH_FNTID   20      /* U   Source Font ID  2 bytes                  */
+#define  FH_SFVNR   22      /* U   Source Font Version Number  2 bytes      */
+#define  FH_FNTNM   24      /* U   Source Font Name  70 bytes               */
+#define  FH_MDATE   94      /* U   Manufacturing Date  10 bytes             */
+#define  FH_LAYNM  104      /* U   Layout Name  70 bytes                    */
+#define  FH_CPYRT  174      /* U   Copyright Notice  78 bytes               */
+#define  FH_NCHRL  252      /* U   Number of Chars in Layout  2 bytes       */
+#define  FH_NCHRF  254      /* U   Total Number of Chars in Font  2 bytes   */
+#define  FH_FCHRF  256      /* U   Index of first char in Font  2 bytes     */
+#define  FH_NKTKS  258      /* U   Number of kerning tracks in font 2 bytes */
+#define  FH_NKPRS  260      /* U   Number of kerning pairs in font 2 bytes  */
+#define  FH_FLAGS  262      /* U   Font flags 1 byte:                       */
+                            /*       Bit 0: Extended font                   */
+                            /*       Bit 1: not used                        */
+                            /*       Bit 2: not used                        */
+                            /*       Bit 3: not used                        */
+                            /*       Bit 4: not used                        */
+                            /*       Bit 5: not used                        */
+                            /*       Bit 6: not used                        */
+                            /*       Bit 7: not used                        */
+#define  FH_CLFGS  263      /* U   Classification flags 1 byte:             */
+                            /*       Bit 0: Italic                          */
+                            /*       Bit 1: Monospace                       */
+                            /*       Bit 2: Serif                           */
+                            /*       Bit 3: Display                         */
+                            /*       Bit 4: not used                        */
+                            /*       Bit 5: not used                        */
+                            /*       Bit 6: not used                        */
+                            /*       Bit 7: not used                        */
+#define  FH_FAMCL  264      /* U   Family Classification 1 byte:            */
+                            /*       0:  Don't care                         */
+                            /*       1:  Serif                              */
+                            /*       2:  Sans serif                         */
+                            /*       3:  Monospace                          */
+                            /*       4:  Script or calligraphic             */
+                            /*       5:  Decorative                         */
+                            /*       6-255: not used                        */
+#define  FH_FRMCL  265      /* U   Font form Classification 1 byte:         */
+                            /*       Bits 0-3 (width type):                 */
+                            /*         0-3:   not used                      */
+                            /*         4:     Condensed                     */
+                            /*         5:     not used                      */
+                            /*         6:     Semi-condensed                */
+                            /*         7:     not used                      */
+                            /*         8:     Normal                        */
+                            /*         9:     not used                      */
+                            /*        10:     Semi-expanded                 */
+                            /*        11:     not used                      */
+                            /*        12:     Expanded                      */
+                            /*        13-15:  not used                      */
+                            /*       Bits 4-7 (Weight):                     */
+                            /*         0:   not used                        */
+                            /*         1:   Thin                            */
+                            /*         2:   Ultralight                      */
+                            /*         3:   Extralight                      */
+                            /*         4:   Light                           */
+                            /*         5:   Book                            */
+                            /*         6:   Normal                          */
+                            /*         7:   Medium                          */
+                            /*         8:   Semibold                        */
+                            /*         9:   Demibold                        */
+                            /*         10:  Bold                            */
+                            /*         11:  Extrabold                       */
+                            /*         12:  Ultrabold                       */
+                            /*         13:  Heavy                           */
+                            /*         14:  Black                           */
+                            /*         15-16: not used                      */
+#define  FH_SFNTN  266      /* U   Short Font Name  32 bytes                */
+#define  FH_SFACN  298      /* U   Short Face Name  16 bytes                */
+#define  FH_FNTFM  314      /* U   Font form 14 bytes                       */
+#define  FH_ITANG  328      /* U   Italic angle 2 bytes (1/256th deg)       */
+#define  FH_ORUPM  330      /* U   Number of ORUs per em  2 bytes           */
+#define  FH_WDWTH  332      /* U   Width of Wordspace  2 bytes              */
+#define  FH_EMWTH  334      /* U   Width of Emspace  2 bytes                */
+#define  FH_ENWTH  336      /* U   Width of Enspace  2 bytes                */
+#define  FH_TNWTH  338      /* U   Width of Thinspace  2 bytes              */
+#define  FH_FGWTH  340      /* U   Width of Figspace  2 bytes               */
+#define  FH_FXMIN  342      /* U   Font-wide min X value  2 bytes           */
+#define  FH_FYMIN  344      /* U   Font-wide min Y value  2 bytes           */
+#define  FH_FXMAX  346      /* U   Font-wide max X value  2 bytes           */
+#define  FH_FYMAX  348      /* U   Font-wide max Y value  2 bytes           */
+#define  FH_ULPOS  350      /* U   Underline position 2 bytes               */
+#define  FH_ULTHK  352      /* U   Underline thickness 2 bytes              */
+#define  FH_SMCTR  354      /* U   Small caps transformation 6 bytes        */
+#define  FH_DPSTR  360      /* U   Display sups transformation 6 bytes      */
+#define  FH_FNSTR  366      /* U   Footnote sups transformation 6 bytes     */
+#define  FH_ALSTR  372      /* U   Alpha sups transformation 6 bytes        */
+#define  FH_CMITR  378      /* U   Chemical infs transformation 6 bytes     */
+#define  FH_SNMTR  384      /* U   Small nums transformation 6 bytes        */
+#define  FH_SDNTR  390      /* U   Small denoms transformation 6 bytes      */
+#define  FH_MNMTR  396      /* U   Medium nums transformation 6 bytes       */
+#define  FH_MDNTR  402      /* U   Medium denoms transformation 6 bytes     */
+#define  FH_LNMTR  408      /* U   Large nums transformation 6 bytes        */
+#define  FH_LDNTR  414      /* U   Large denoms transformation 6 bytes      */
+                            /*     Transformation data format:              */
+                            /*       Y position 2 bytes                     */
+                            /*       X scale 2 bytes (1/4096ths)            */
+                            /*       Y scale 2 bytes (1/4096ths)            */
+#define  SIZE_FW FH_LDNTR + 6  /* size of nominal font header */
+#define  EXP_FH_METRES SIZE_FW /* offset to expansion field metric resolution (optional) */
+
+
+
+/***** MODE FLAGS CONSTANTS *****/
+#define CURVES_OUT     0X0008  /* Output module accepts curves              */
+#define BOGUS_MODE     0X0010  /* Linear scaling mode                       */
+#define CONSTR_OFF     0X0020  /* Inhibit constraint table                  */
+#define IMPORT_WIDTHS  0X0040  /* Imported width mode                       */
+#define SQUEEZE_LEFT   0X0100  /* Squeeze left mode                         */
+#define SQUEEZE_RIGHT  0X0200  /* Squeeze right mode                        */
+#define SQUEEZE_TOP    0X0400  /* Squeeze top mode                          */
+#define SQUEEZE_BOTTOM 0X0800  /* Squeeze bottom mode                       */
+#define CLIP_LEFT      0X1000  /* Clip left mode                            */
+#define CLIP_RIGHT     0X2000  /* Clip right mode                           */
+#define CLIP_TOP       0X4000  /* Clip top mode                             */
+#define CLIP_BOTTOM    0X8000  /* Clip bottom mode                          */
+
+/***********************************************************************************
+ *
+ *  Speedo function declarations - use prototypes if available
+ *
+ ***********************************************************************************/
+
+#if PROTOS_AVAIL
+/*  do_char.c functions */
+ufix16 sp_get_char_id(PROTO_DECL2 ufix16 char_index);
+boolean sp_make_char(PROTO_DECL2 ufix16 char_index);
+#if  INCL_ISW       
+fix31 sp_compute_isw_scale(PROTO_DECL2);
+static boolean sp_do_make_char(PROTO_DECL2 ufix16 char_index);
+boolean sp_make_char_isw(PROTO_DECL2 ufix16 char_index, ufix32 imported_width);
+static boolean sp_reset_xmax(PROTO_DECL2 fix31 xmax);
+#endif
+#if INCL_ISW || INCL_SQUEEZING
+static void sp_preview_bounding_box(PROTO_DECL2 ufix8 FONTFAR  *pointer,ufix8    format);
+#endif
+
+#if INCL_METRICS                 /* Metrics functions supported? */
+fix31 sp_get_char_width(PROTO_DECL2 ufix16 char_index);
+fix15 sp_get_track_kern(PROTO_DECL2 fix15 track,fix15 point_size);
+fix31 sp_get_pair_kern(PROTO_DECL2 ufix16 char_index1,ufix16 char_index2);
+boolean sp_get_char_bbox(PROTO_DECL2 ufix16 char_index, bbox_t *bbox);
+#endif
+
+/* do_trns.c functions */
+ufix8 FONTFAR *sp_read_bbox(PROTO_DECL2 ufix8 FONTFAR *pointer,point_t STACKFAR *pPmin,point_t STACKFAR *pPmax,boolean set_flag);
+void sp_proc_outl_data(PROTO_DECL2 ufix8 FONTFAR *pointer);
+
+/* out_blk.c functions */
+#if INCL_BLACK
+boolean sp_init_black(PROTO_DECL2 specs_t GLOBALFAR *specsarg);
+boolean sp_begin_char_black(PROTO_DECL2 point_t Psw,point_t Pmin,point_t Pmax);
+void sp_begin_contour_black(PROTO_DECL2 point_t P1,boolean outside);
+void sp_line_black(PROTO_DECL2 point_t P1);
+boolean sp_end_char_black(PROTO_DECL1);
+#endif
+
+/* out_scrn.c functions */
+#if INCL_SCREEN
+boolean sp_init_screen(PROTO_DECL2 specs_t GLOBALFAR *specsarg);
+boolean sp_begin_char_screen(PROTO_DECL2 point_t Psw,point_t Pmin,point_t Pmax);
+void sp_begin_contour_screen(PROTO_DECL2 point_t P1,boolean outside);
+void sp_curve_screen(PROTO_DECL2 point_t P1,point_t P2,point_t P3, fix15 depth);
+void sp_scan_curve_screen(PROTO_DECL2 fix31 X0,fix31 Y0,fix31 X1,fix31 Y1,fix31 X2,fix31 Y2,fix31 X3,fix31 Y3);
+void sp_vert_line_screen(PROTO_DECL2   fix31 x, fix15 y1, fix15 y2);
+void sp_line_screen(PROTO_DECL2 point_t P1);
+void sp_end_contour_screen(PROTO_DECL1);
+boolean sp_end_char_screen(PROTO_DECL1);
+#endif
+
+/* out_outl.c functions */
+#if INCL_OUTLINE
+#if INCL_MULTIDEV
+boolean sp_set_outline_device(PROTO_DECL2 outline_t *ofuncs, ufix16 size);
+#endif
+
+
+boolean sp_init_outline(PROTO_DECL2 specs_t GLOBALFAR *specsarg);
+boolean sp_begin_char_outline(PROTO_DECL2 point_t Psw,point_t Pmin,point_t Pmax);
+void sp_begin_sub_char_outline(PROTO_DECL2 point_t Psw,point_t Pmin,point_t Pmax);
+void sp_begin_contour_outline(PROTO_DECL2 point_t P1,boolean outside);
+void sp_curve_outline(PROTO_DECL2 point_t P1,point_t P2,point_t P3, fix15 depth);
+void sp_line_outline(PROTO_DECL2 point_t P1);
+void sp_end_contour_outline(PROTO_DECL1);
+void sp_end_sub_char_outline(PROTO_DECL1);
+boolean sp_end_char_outline(PROTO_DECL1);
+#endif
+
+/* out_bl2d.c functions */
+#if INCL_2D
+boolean sp_init_2d(PROTO_DECL2 specs_t GLOBALFAR *specsarg);
+boolean sp_begin_char_2d(PROTO_DECL2 point_t Psw,point_t Pmin,point_t Pmax);
+void sp_begin_contour_2d(PROTO_DECL2 point_t P1,boolean outside);
+void sp_line_2d(PROTO_DECL2 point_t P1);
+boolean sp_end_char_2d(PROTO_DECL1);
+#endif
+
+/* out_util.c functions */
+#if INCL_BLACK || INCL_SCREEN || INCL_2D
+        
+#if INCL_MULTIDEV
+boolean sp_set_bitmap_device(PROTO_DECL2 bitmap_t *bfuncs, ufix16 size);
+#endif
+
+void sp_init_char_out(PROTO_DECL2 point_t Psw, point_t Pmin, point_t Pmax);
+void sp_begin_sub_char_out(PROTO_DECL2 point_t Psw, point_t Pmin, point_t Pmax);
+void sp_curve_out(PROTO_DECL2 point_t P1, point_t P2, point_t P3, fix15 depth);
+void sp_end_contour_out(PROTO_DECL1);
+void sp_end_sub_char_out(PROTO_DECL1);
+void sp_init_intercepts_out(PROTO_DECL1);
+void sp_restart_intercepts_out(PROTO_DECL1);
+void sp_set_first_band_out(PROTO_DECL2 point_t Pmin, point_t Pmax);
+void sp_reduce_band_size_out(PROTO_DECL1);
+boolean sp_next_band_out(PROTO_DECL1);
+#endif
+
+#if INCL_USEROUT
+boolean sp_init_userout(specs_t *specsarg);
+#endif
+
+
+/* reset.c functions */
+void sp_reset(PROTO_DECL1);
+#if INCL_KEYS
+void sp_set_key(PROTO_DECL2 ufix8 key[]);
+#endif
+ufix16 sp_get_cust_no(PROTO_DECL2 buff_t font_buff);
+
+/* set_spcs.c functions */
+boolean sp_set_specs(PROTO_DECL2 specs_t STACKFAR *specsarg);
+void sp_type_tcb(PROTO_DECL2 tcb_t GLOBALFAR *ptcb);
+
+fix31 sp_read_long(PROTO_DECL2 ufix8 FONTFAR *pointer);
+fix15 sp_read_word_u(PROTO_DECL2 ufix8 FONTFAR *pointer);
+
+/* set_trns.c functions */
+void sp_init_tcb(PROTO_DECL1);
+void sp_scale_tcb(PROTO_DECL2 tcb_t GLOBALFAR *ptcb,fix15 x_pos,fix15 y_pos,fix15 x_scale,fix15 y_scale);
+ufix8 FONTFAR *sp_plaid_tcb(PROTO_DECL2 ufix8 FONTFAR *pointer,ufix8 format);
+ufix8 FONTFAR *sp_skip_interpolation_table(PROTO_DECL2 ufix8 FONTFAR *pointer, ufix8 format);
+ufix8 FONTFAR *sp_skip_control_zone(PROTO_DECL2 ufix8 FONTFAR *pointer, ufix8 format);
+
+ufix8 FONTFAR *sp_read_oru_table(PROTO_DECL2 ufix8 FONTFAR *pointer);
+#if INCL_SQUEEZING || INCL_ISW
+static void sp_calculate_x_pix(PROTO_DECL2 ufix8 start_edge,ufix8 end_edge,ufix16 constr_nr,fix31 x_scale,fix31 x_offset,fix31 ppo,fix15 setwidth_pix);
+#endif
+#if INCL_SQUEEZING
+static void sp_calculate_y_pix(PROTO_DECL2 ufix8 start_edge,ufix8 end_edge,ufix16 constr_nr,fix31 top_scale,fix31 bottom_scale,fix31 ppo,fix15 emtop_pix,fix15 embot_pix);
+boolean sp_calculate_x_scale(PROTO_DECL2 fix31 *x_factor,fix31 *x_offset,fix15 no_x_ctrl_zones);
+boolean sp_calculate_y_scale(PROTO_DECL2 fix31 *top_scale,fix31 *bottom_scale,fix15 first_y_zone, fix15 no_Y_ctrl_zones);
+#endif
+                  
+
+/* user defined functions */
+
+void sp_report_error(PROTO_DECL2 fix15 n);
+
+#if INCL_BLACK || INCL_SCREEN || INCL_2D
+void sp_open_bitmap(PROTO_DECL2 fix31 x_set_width, fix31 y_set_width, fix31 xorg, fix31 yorg, fix15 xsize,fix15 ysize);
+void sp_set_bitmap_bits(PROTO_DECL2 fix15 y, fix15 xbit1, fix15 xbit2);
+void sp_close_bitmap(PROTO_DECL1);
+#endif
+
+#if INCL_OUTLINE
+void sp_open_outline(PROTO_DECL2 fix31 x_set_width, fix31 y_set_width, fix31 xmin, fix31 xmax, fix31 ymin,fix31 ymax);
+void sp_start_new_char(PROTO_DECL1);
+void sp_start_contour(PROTO_DECL2 fix31 x,fix31 y,boolean outside);
+void sp_curve_to(PROTO_DECL2 fix31 x1, fix31 y1, fix31 x2, fix31 y2, fix31 x3, fix31 y3);
+void sp_line_to(PROTO_DECL2 fix31 x, fix31 y);
+void sp_close_contour(PROTO_DECL1);
+void sp_close_outline(PROTO_DECL1);
+#endif
+
+#if INCL_LCD                     /* Dynamic load character data supported? */
+buff_t *sp_load_char_data(PROTO_DECL2 fix31 file_offset,fix15 no_bytes,fix15 cb_offset);        /* Load character data from font file */
+#endif
+
+#if INCL_PLAID_OUT               /* Plaid data monitoring included? */
+void   sp_record_xint(PROTO_DECL2 fix15 int_num);            /* Record xint data */
+void   sp_record_yint(PROTO_DECL2 fix15 int_num);            /* Record yint data */
+void sp_begin_plaid_data(PROTO_DECL1);         /* Signal start of plaid data */
+void sp_begin_ctrl_zones(PROTO_DECL2 fix15, no_X_zones, fix15 no_Y_zones);         /* Signal start of control zones */
+void sp_record_ctrl_zone(PROTO_DECL2 fix31 start, fix31 end, fix15 constr);         /* Record control zone data */
+void sp_begin_int_zones(PROTO_DECL2 fix15 no_X_int_zones, fix15 no_Y_int_zones);          /* Signal start of interpolation zones */
+void sp_record_int_zone(PROTO_DECL2 fix31 start, fix31 end);          /* Record interpolation zone data */
+void sp_end_plaid_data(PROTO_DECL1);           /* Signal end of plaid data */
+#endif
+
+#else   /* NO PROTOTYPES AVAILABLE */
+
+
+
+/*  do_char.c functions */
+boolean sp_make_char();          /* Make specified character */
+#if  INCL_ISW       
+fix31 sp_compute_isw_scale();
+static boolean sp_do_make_char();
+boolean sp_make_char_isw();     /* Make specified character with */
+                                /* imported set widths.*/
+static boolean sp_reset_xmax();
+#endif
+#if INCL_ISW || INCL_SQUEEZING
+static void sp_preview_bounding_box();
+#endif
+ufix16  sp_get_char_id();        /* Get character id for specified char */
+
+#if INCL_METRICS                 /* Metrics functions supported? */
+fix31   sp_get_char_width();     /* Get character width for specified char */
+fix15   sp_get_track_kern();     /* Get track kerning for specified size */
+fix31   sp_get_pair_kern();      /* Get kerning for specified char pair */
+boolean sp_get_char_bbox();
+#endif
+
+/* do_trns.c functions */
+ufix8 FONTFAR *sp_read_bbox();              /* Read bounding box */
+void   sp_proc_outl_data();         /* Process outline data */
+
+/* out_0c.c functions */
+boolean sp_init_black();
+boolean sp_begin_char_black();
+void sp_begin_contour_black();
+void sp_line_black();
+boolean sp_end_char_black();
+
+/* out_util.c functions */
+#if INCL_BLACK || INCL_SCREEN || INCL_2D
+
+void sp_init_char_out();
+void sp_begin_sub_char_out();
+void sp_curve_out();
+void sp_end_contour_out();
+void sp_end_sub_char_out();
+void sp_init_intercepts_out();
+void sp_restart_intercepts_out();
+void sp_set_first_band_out();
+void sp_reduce_band_size_out();
+boolean sp_next_band_out();
+#endif
+
+#if INCL_USEROUT
+boolean sp_init_userout();
+#endif
+
+/* reset.c functions */
+void sp_reset();                 /* Initialize Fontware mechanism */
+
+#if INCL_KEYS
+void sp_set_key();
+#endif
+ufix16 sp_get_cust_no();
+
+/* set_spcs.c functions */
+boolean    sp_set_specs();       /* Set specifications */
+void       sp_type_tcb();           /* Update transformation class in tcb */
+
+fix31   sp_read_long();      /* Read long as 3 bytes encrypted */
+fix15   sp_read_word_u();    /* Read word as 2 bytes unencrypted */
+
+/* set_trns.c functions */
+void    sp_init_tcb();              /* Initialize current trans control block */
+void    sp_scale_tcb();             /* Transform trans control block */
+ufix8 FONTFAR *sp_plaid_tcb();             /* Enable intelligent transformation */
+ufix8 FONTFAR *sp_skip_interpolation_table();
+ufix8 FONTFAR *sp_skip_control_zone();
+
+ufix8 FONTFAR *sp_read_oru_table();    /* Read controlled coord table */
+#if INCL_SQUEEZING || INCL_ISW
+static void sp_calculate_x_pix();
+#endif
+#if INCL_SQUEEZING
+static void sp_calculate_y_pix();
+boolean sp_calculate_x_scale();
+boolean sp_calculate_y_scale() ;
+#endif
+
+/* user defined functions */
+
+#if INCL_BLACK || INCL_SCREEN || INCL_2D
+void sp_open_bitmap();
+void sp_set_bitmap_bits();
+void sp_close_bitmap();
+#endif
+
+#if INCL_OUTLINE
+void sp_open_outline();
+void sp_start_new_char();
+void sp_start_contour();
+void sp_curve_to();
+void sp_line_to();
+void sp_close_contour();
+void sp_close_outline();
+#endif
+
+#if INCL_LCD                     /* Dynamic load character data supported? */
+buff_t *sp_load_char_data();        /* Load character data from font file */
+#endif
+
+#if INCL_PLAID_OUT               /* Plaid data monitoring included? */
+void   sp_record_xint();            /* Record xint data */
+void   sp_record_yint();            /* Record yint data */
+void sp_begin_plaid_data();         /* Signal start of plaid data */
+void sp_begin_ctrl_zones();         /* Signal start of control zones */
+void sp_record_ctrl_zone();         /* Record control zone data */
+void sp_begin_int_zones();          /* Signal start of interpolation zones */
+void sp_record_int_zone();          /* Record interpolation zone data */
+void sp_end_plaid_data();           /* Signal end of plaid data */
+#endif
+
+boolean sp_init_screen();        /* If only screen-writer mode supported */
+boolean sp_begin_char_screen();      /* If screenwriter mode supported */
+void    sp_begin_contour_screen();   /* If screenwriter mode supported */
+void    sp_line_screen();            /* If screenwriter mode supported */
+void    sp_curve_screen();           /* If screenwriter mode supported */
+void sp_scan_curve_screen();
+void sp_vert_line_screen();
+void sp_end_contour_screen();
+boolean sp_end_char_screen();        /* If screenwriter mode supported */
+
+
+boolean sp_init_outline();        /* If only vector output mode supported */
+boolean sp_begin_char_outline();      /* If only vector output mode supported */
+void    sp_begin_sub_char_outline();  /* If only vector output mode supported */
+void    sp_begin_contour_outline();   /* If only vector output mode supported */
+void    sp_curve_outline();           /* If only vector output mode supported */
+void    sp_line_outline();            /* If only vector output mode supported */
+void    sp_end_contour_outline();     /* If only vector output mode supported */
+void    sp_end_sub_char_outline();    /* If only vector output mode supported */
+boolean sp_end_char_outline();        /* If only vector output mode supported */
+
+boolean sp_init_2d();       /* If screen-writer and other modes supported */
+boolean sp_begin_char_2d();     /* If screen-writer and other modes supported */
+void    sp_begin_contour_2d();  /* If screen-writer and other modes supported */
+void    sp_line_2d();           /* If screen-writer and other modes supported */
+boolean sp_end_char_2d();       /* If screen-writer and other modes supported */
+
+#endif
+
+
+
+#endif /* _SPEEDO_H_ */
diff --git a/Xserver/lib/font/Speedo/spencode.c b/Xserver/lib/font/Speedo/spencode.c
new file mode 100644 (file)
index 0000000..017fa8a
--- /dev/null
@@ -0,0 +1,64 @@
+/* $XConsortium: spencode.c,v 1.6 94/04/17 20:17:46 gildea Exp $ */
+/*
+ * Copyright 1990, 1991 Network Computing Devices;
+ * Portions Copyright 1987 by Digital Equipment Corporation
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and
+ * its documentation for any purpose is hereby granted without fee, provided
+ * that the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the names of Network Computing Devices or Digital
+ * not be used in advertising or publicity pertaining to distribution of
+ * the software without specific, written prior permission.
+ *
+ * NETWORK COMPUTING DEVICES AND DIGITAL DISCLAIM ALL WARRANTIES WITH
+ * REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS, IN NO EVENT SHALL NETWORK COMPUTING DEVICES OR DIGITAL BE
+ * LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
+ * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
+ * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+/*
+
+Copyright (c) 1987  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be included
+in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR
+OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall
+not be used in advertising or otherwise to promote the sale, use or
+other dealings in this Software without prior written authorization
+from the X Consortium.
+
+*/
+
+#include       "spint.h"
+
+#include       "bics-iso.h"
+
+int sp_bics_map_size = (sizeof(sp_bics_map) / (sizeof(int) * 2));
+
+#ifdef EXTRAFONTS
+#include       "adobe-iso.h"
+
+int adobe_map_size = (sizeof(adobe_map) / (sizeof(int) * 2));
+
+#endif /* EXTRAFONTS */
diff --git a/Xserver/lib/font/Speedo/sperr.c b/Xserver/lib/font/Speedo/sperr.c
new file mode 100644 (file)
index 0000000..32e8d0c
--- /dev/null
@@ -0,0 +1,136 @@
+/* $XConsortium: sperr.c,v 1.6 94/04/17 20:17:47 dpw Exp $ */
+/*
+ * Copyright 1990, 1991 Network Computing Devices;
+ * Portions Copyright 1987 by Digital Equipment Corporation
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the names of M.I.T., Network Computing Devices,
+ * or Digital not be used in advertising or
+ * publicity pertaining to distribution of the software without specific,
+ * written prior permission.  M.I.T. Network Computing Devices, or Digital
+ * make no representations about the
+ * suitability of this software for any purpose.  It is provided "as is"
+ * without express or implied warranty.
+ *
+ * NETWORK COMPUTING DEVICES, DIGITAL AND MIT DISCLAIM ALL WARRANTIES WITH
+ * REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS, IN NO EVENT SHALL NETWORK COMPUTING DEVICES, DIGITAL OR MIT BE
+ * LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
+ * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
+ * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ */
+
+/*
+
+Copyright (c) 1994  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be included
+in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR
+OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall
+not be used in advertising or otherwise to promote the sale, use or
+other dealings in this Software without prior written authorization
+from the X Consortium.
+
+*/
+#include       "spint.h"
+
+#if NeedVarargsPrototypes
+#include <stdarg.h>
+
+void
+SpeedoErr(char *str, ...)
+{
+    va_list v;
+    int a1;
+
+    va_start(v, str);
+    ErrorF("Speedo: ");
+    a1 = va_arg(v, int);
+    ErrorF(str, a1);
+    va_end(v);
+}
+
+#else
+
+/* VARARGS1 */
+void
+SpeedoErr(str, a1)
+    char       *str;
+    char       *a1;
+{
+    ErrorF("Speedo: ");
+    ErrorF(str, a1);
+}
+#endif /* NeedVarargsPrototypes else */
+
+
+/*
+ * Called by Speedo character generator to report an error.
+ *
+ *  Since character data not available is one of those errors
+ *  that happens many times, don't report it to user
+ */
+void
+sp_report_error(n)
+    fix15       n;
+{
+    switch (n) {
+    case 1:
+       SpeedoErr("Insufficient font data loaded\n");
+       break;
+    case 3:
+       SpeedoErr("Transformation matrix out of range\n");
+       break;
+    case 4:
+       SpeedoErr("Font format error\n");
+       break;
+    case 5:
+       SpeedoErr("Requested specs not compatible with output module\n");
+       break;
+    case 7:
+       SpeedoErr("Intelligent transformation requested but not supported\n");
+       break;
+    case 8:
+       SpeedoErr("Unsupported output mode requested\n");
+       break;
+    case 9:
+       SpeedoErr("Extended font loaded but only compact fonts supported\n");
+       break;
+    case 10:
+       SpeedoErr("Font specs not set prior to use of font\n");
+       break;
+    case 12:
+       break;
+    case 13:
+       SpeedoErr("Track kerning data not available()\n");
+       break;
+    case 14:
+       SpeedoErr("Pair kerning data not available()\n");
+       break;
+    default:
+       SpeedoErr("report_error(%d)\n", n);
+       break;
+    }
+}
diff --git a/Xserver/lib/font/Speedo/spfile.c b/Xserver/lib/font/Speedo/spfile.c
new file mode 100644 (file)
index 0000000..acb45b0
--- /dev/null
@@ -0,0 +1,351 @@
+/* $TOG: spfile.c /main/13 1997/06/09 09:38:27 barstow $ */
+/*
+ * Copyright 1990, 1991 Network Computing Devices;
+ * Portions Copyright 1987 by Digital Equipment Corporation
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and
+ * its documentation for any purpose is hereby granted without fee, provided
+ * that the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the names of Network Computing Devices or Digital
+ * not be used in advertising or publicity pertaining to distribution of
+ * the software without specific, written prior permission.
+ *
+ * NETWORK COMPUTING DEVICES AND DIGITAL DISCLAIM ALL WARRANTIES WITH
+ * REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS, IN NO EVENT SHALL NETWORK COMPUTING DEVICES OR DIGITAL 
+ * LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
+ * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
+ * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ * Author: Dave Lemke, Network Computing Devices Inc
+ */
+
+/*
+
+Copyright (c) 1987  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be included
+in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR
+OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall
+not be used in advertising or otherwise to promote the sale, use or
+other dealings in this Software without prior written authorization
+from the X Consortium.
+
+*/
+
+#include <stdio.h>
+#include "fntfilst.h"
+
+#include "spint.h"
+
+SpeedoFontPtr sp_fp_cur = (SpeedoFontPtr) 0;
+
+#ifdef EXTRAFONTS
+#include "ncdkeys.h"
+#endif
+
+#include "keys.h"
+
+#ifdef EXTRAFONTS
+static ufix8 skey[] =
+{
+    SKEY0,
+    SKEY1,
+    SKEY2,
+    SKEY3,
+    SKEY4,
+    SKEY5,
+    SKEY6,
+    SKEY7,
+    SKEY8
+};                             /* Sample Font decryption key */
+
+static ufix8 rkey[] =
+{
+    RKEY0,
+    RKEY1,
+    RKEY2,
+    RKEY3,
+    RKEY4,
+    RKEY5,
+    RKEY6,
+    RKEY7,
+    RKEY8
+};                             /* Retail Font decryption key */
+
+#endif                         /* EXTRAFONTS */
+
+#ifdef XSAMPLEFONTS
+static ufix8 xkey[] =
+{
+    XKEY0,
+    XKEY1,
+    XKEY2,
+    XKEY3,
+    XKEY4,
+    XKEY5,
+    XKEY6,
+    XKEY7,
+    XKEY8
+};                             /* Sample Font decryption key */
+#endif
+
+static ufix8 mkey[] =
+{
+    KEY0,
+    KEY1,
+    KEY2,
+    KEY3,
+    KEY4,
+    KEY5,
+    KEY6,
+    KEY7,
+    KEY8
+};                             /* Font decryption key */
+
+
+static      fix15
+read_2b(ptr)
+    ufix8      *ptr;
+{
+    fix15       tmp;
+
+    tmp = *ptr++;
+    tmp = (tmp << 8) + *ptr;
+    return tmp;
+}
+
+static      fix31
+read_4b(ptr)
+    ufix8      *ptr;
+{
+    fix31       tmp;
+
+    tmp = *ptr++;
+    tmp = (tmp << 8) + *ptr++;
+    tmp = (tmp << 8) + *ptr++;
+    tmp = (tmp << 8) + *ptr;
+    return tmp;
+}
+
+/*
+ * loads the specified char's data
+ */
+buff_t     *
+sp_load_char_data(file_offset, num, cb_offset)
+    fix31       file_offset;
+    fix15       num;
+    fix15       cb_offset;
+{
+    SpeedoMasterFontPtr master = sp_fp_cur->master;
+
+    if (fseek(master->fp, (long) file_offset, (int) 0)) {
+       SpeedoErr("can't seek to char\n");
+    }
+    if ((num + cb_offset) > master->mincharsize) {
+       SpeedoErr("char buf overflow\n");
+    }
+    if (fread((master->c_buffer + cb_offset), sizeof(ufix8), num,
+             master->fp) != num) {
+       SpeedoErr("can't get char data\n");
+    }
+    master->char_data.org = (ufix8 *) master->c_buffer + cb_offset;
+    master->char_data.no_bytes = num;
+
+    return &master->char_data;
+}
+
+int
+sp_open_master(filename, master)
+    char       *filename;
+    SpeedoMasterFontPtr *master;
+{
+    SpeedoMasterFontPtr spmf;
+    ufix8       tmp[16];
+    ufix16      cust_no;
+    FILE       *fp;
+    ufix32      minbufsize;
+    ufix16      mincharsize;
+    ufix8      *f_buffer;
+    ufix8      *c_buffer;
+    int         ret;
+    ufix8      *key;
+
+    spmf = (SpeedoMasterFontPtr) xalloc(sizeof(SpeedoMasterFontRec));
+    if (!spmf)
+       return AllocError;
+    bzero(spmf, sizeof(SpeedoMasterFontRec));
+    spmf->entry = NULL;
+    spmf->f_buffer = NULL;
+    spmf->c_buffer = NULL;
+
+    /* open font */
+    spmf->fname = (char *) xalloc(strlen(filename) + 1);
+    if (!spmf->fname)
+       return AllocError;
+    fp = fopen(filename, "r");
+    if (!fp) {
+       ret = BadFontName;
+       goto cleanup;
+    }
+    strcpy(spmf->fname, filename);
+    spmf->fp = fp;
+    spmf->state |= MasterFileOpen;
+
+    if (fread(tmp, sizeof(ufix8), 16, fp) != 16) {
+       ret = BadFontName;
+       goto cleanup;
+    }
+    minbufsize = (ufix32) read_4b(tmp + FH_FBFSZ);
+    f_buffer = (ufix8 *) xalloc(minbufsize);
+    if (!f_buffer) {
+       ret = AllocError;
+       goto cleanup;
+    }
+    spmf->f_buffer = f_buffer;
+
+    fseek(fp, (ufix32) 0, 0);
+
+    /* read in the font */
+    if (fread(f_buffer, sizeof(ufix8), (ufix16) minbufsize, fp) != minbufsize) {
+       ret = BadFontName;
+       goto cleanup;
+    }
+    spmf->copyright = (char *) (f_buffer + FH_CPYRT);
+    spmf->mincharsize = mincharsize = read_2b(f_buffer + FH_CBFSZ);
+
+    c_buffer = (ufix8 *) xalloc(mincharsize);
+    if (!c_buffer) {
+       ret = AllocError;
+       goto cleanup;
+    }
+    spmf->c_buffer = c_buffer;
+
+    spmf->font.org = spmf->f_buffer;
+    spmf->font.no_bytes = minbufsize;
+
+    cust_no = sp_get_cust_no(spmf->font);
+
+    /* XXX add custom encryption stuff here */
+
+#ifdef EXTRAFONTS
+    if (cust_no == SCUS0) {
+       key = skey;
+    } else if (cust_no == RCUS0) {
+       key = rkey;
+    } else
+#endif
+
+#ifdef XSAMPLEFONTS
+    if (cust_no == XCUS0) {
+       key = xkey;
+    } else
+#endif
+
+    if (cust_no == CUS0) {
+       key = mkey;
+    } else {
+       SpeedoErr("Non - standard encryption for \"%s\"\n", filename);
+       ret = BadFontName;
+       goto cleanup;
+    }
+    spmf->key = key;
+    sp_set_key(key);
+
+    spmf->first_char_id = read_2b(f_buffer + FH_FCHRF);
+    spmf->num_chars = read_2b(f_buffer + FH_NCHRL);
+
+
+    spmf->enc = sp_bics_map;
+    spmf->enc_size = sp_bics_map_size;
+
+#ifdef EXTRAFONTS
+    {                          /* choose the proper encoding */
+       char       *f;
+
+       f = strrchr(filename, '/');
+       if (f) {
+           f++;
+           if (strncmp(f, "bx113", 5) == 0) {
+               spmf->enc = adobe_map;
+               spmf->enc_size = adobe_map_size;
+           }
+       }
+    }
+#endif
+
+    /* XXX slam back to ISO Latin1 */
+    spmf->first_char_id = spmf->enc[0];
+    /* size of extents array */
+    spmf->max_id = spmf->enc[(spmf->enc_size - 1) * 2];
+    spmf->num_chars = spmf->enc_size;
+
+    *master = spmf;
+
+    return Successful;
+
+cleanup:
+    *master = (SpeedoMasterFontPtr) 0;
+    sp_close_master_font(spmf);
+    return ret;
+}
+
+void
+sp_close_master_font(spmf)
+    SpeedoMasterFontPtr spmf;
+{
+    if (!spmf)
+       return;
+    if (spmf->state & MasterFileOpen)
+       fclose(spmf->fp);
+    if (spmf->entry)
+       spmf->entry->u.scalable.extra->private = NULL;
+    xfree(spmf->fname);
+    xfree(spmf->f_buffer);
+    xfree(spmf->c_buffer);
+    xfree(spmf);
+}
+
+void
+sp_close_master_file(spmf)
+    SpeedoMasterFontPtr spmf;
+{
+    (void) fclose(spmf->fp);
+    spmf->state &= ~MasterFileOpen;
+}
+
+
+/*
+ * reset the encryption key, and make sure the file is opened
+ */
+void
+sp_reset_master(spmf)
+    SpeedoMasterFontPtr spmf;
+{
+    sp_set_key(spmf->key);
+    if (!(spmf->state & MasterFileOpen)) {
+       spmf->fp = fopen(spmf->fname, "r");
+       /* XXX -- what to do if we can't open the file? */
+       spmf->state |= MasterFileOpen;
+    }
+    fseek(spmf->fp, 0, 0);
+}
diff --git a/Xserver/lib/font/Speedo/spfont.c b/Xserver/lib/font/Speedo/spfont.c
new file mode 100644 (file)
index 0000000..f6c5dfe
--- /dev/null
@@ -0,0 +1,456 @@
+/* $TOG: spfont.c /main/24 1997/06/09 09:38:19 barstow $ */
+/*
+ * Copyright 1990, 1991 Network Computing Devices;
+ * Portions Copyright 1987 by Digital Equipment Corporation
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and
+ * its documentation for any purpose is hereby granted without fee, provided
+ * that the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the names of Network Computing Devices or Digital
+ * not be used in advertising or publicity pertaining to distribution of
+ * the software without specific, written prior permission.
+ *
+ * NETWORK COMPUTING DEVICES AND DIGITAL DISCLAIM ALL WARRANTIES WITH
+ * REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS, IN NO EVENT SHALL NETWORK COMPUTING DEVICES OR DIGITAL BE
+ * LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
+ * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
+ * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ * Author: Dave Lemke, Network Computing Devices Inc
+ */
+/* $XFree86: xc/lib/font/Speedo/spfont.c,v 3.1.8.1 1997/06/11 12:08:38 dawes Exp $ */
+
+/*
+
+Copyright (c) 1987  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be included
+in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR
+OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall
+not be used in advertising or otherwise to promote the sale, use or
+other dealings in this Software without prior written authorization
+from the X Consortium.
+
+*/
+
+/*
+ * Speedo font loading
+ */
+
+#include       "FSproto.h"
+#include       "spint.h"
+#include       <servermd.h>
+#ifdef _XOPEN_SOURCE
+#include <math.h>
+#else
+#define _XOPEN_SOURCE  /* to get prototype for hypot on some systems */
+#include <math.h>
+#undef _XOPEN_SOURCE
+#endif
+
+#ifndef M_PI
+#define M_PI 3.14159
+#endif /* M_PI */
+#ifndef DEFAULT_BIT_ORDER
+
+#ifdef BITMAP_BIT_ORDER
+#define DEFAULT_BIT_ORDER BITMAP_BIT_ORDER
+#else
+#define DEFAULT_BIT_ORDER UNKNOWN_BIT_ORDER
+#endif
+
+#endif
+
+extern void SpeedoCloseFont();
+static int sp_get_glyphs();
+static int sp_get_metrics();
+static int sp_load_font();
+
+static CharInfoRec junkDefault;
+
+static int
+sp_get_glyphs(pFont, count, chars, charEncoding, glyphCount, glyphs)
+    FontPtr     pFont;
+    unsigned long count;
+    register unsigned char *chars;
+    FontEncoding charEncoding;
+    unsigned long *glyphCount; /* RETURN */
+    CharInfoPtr *glyphs;       /* RETURN */
+{
+    SpeedoFontPtr spf;
+    unsigned int firstCol;
+    register unsigned int numCols;
+    unsigned int firstRow;
+    unsigned int numRows;
+    CharInfoPtr *glyphsBase;
+    register unsigned int c;
+    register CharInfoPtr pci;
+    unsigned int r;
+    CharInfoPtr encoding;
+    CharInfoPtr pDefault;
+    int         itemSize;
+    int         err = Successful;
+
+    spf = (SpeedoFontPtr) pFont->fontPrivate;
+    encoding = spf->encoding;
+    pDefault = spf->pDefault;
+    firstCol = pFont->info.firstCol;
+    numCols = pFont->info.lastCol - firstCol + 1;
+    glyphsBase = glyphs;
+
+
+    /* XXX - this should be much smarter */
+    /* make sure the glyphs are there */
+    if (charEncoding == Linear8Bit || charEncoding == TwoD8Bit)
+       itemSize = 1;
+    else
+       itemSize = 2;
+
+#ifdef notyet
+    if (!fsd->complete)
+       err = fs_load_glyphs(NULL, pFont, count, itemSize, chars);
+#endif
+
+    if (err != Successful)
+       return err;
+
+    switch (charEncoding) {
+
+    case Linear8Bit:
+    case TwoD8Bit:
+       if (pFont->info.firstRow > 0)
+           break;
+       if (pFont->info.allExist && pDefault) {
+           while (count--) {
+               c = (*chars++) - firstCol;
+               if (c < numCols)
+                   *glyphs++ = &encoding[c];
+               else
+                   *glyphs++ = pDefault;
+           }
+       } else {
+           while (count--) {
+               c = (*chars++) - firstCol;
+               if (c < numCols && (pci = &encoding[c])->bits)
+                   *glyphs++ = pci;
+               else if (pDefault)
+                   *glyphs++ = pDefault;
+           }
+       }
+       break;
+    case Linear16Bit:
+       if (pFont->info.allExist && pDefault) {
+           while (count--) {
+               c = *chars++ << 8;
+               c = (c | *chars++) - firstCol;
+               if (c < numCols)
+                   *glyphs++ = &encoding[c];
+               else
+                   *glyphs++ = pDefault;
+           }
+       } else {
+           while (count--) {
+               c = *chars++ << 8;
+               c = (c | *chars++) - firstCol;
+               if (c < numCols && (pci = &encoding[c])->bits)
+                   *glyphs++ = pci;
+               else if (pDefault)
+                   *glyphs++ = pDefault;
+           }
+       }
+       break;
+
+    case TwoD16Bit:
+       firstRow = pFont->info.firstRow;
+       numRows = pFont->info.lastRow - firstRow + 1;
+       while (count--) {
+           r = (*chars++) - firstRow;
+           c = (*chars++) - firstCol;
+           if (r < numRows && c < numCols &&
+                   (pci = &encoding[r * numCols + c])->bits)
+               *glyphs++ = pci;
+           else if (pDefault)
+               *glyphs++ = pDefault;
+       }
+       break;
+    }
+    *glyphCount = glyphs - glyphsBase;
+    return Successful;
+}
+
+static CharInfoRec nonExistantChar;
+
+static int
+sp_get_metrics(pFont, count, chars, charEncoding, glyphCount, glyphs)
+    FontPtr     pFont;
+    unsigned long count;
+    register unsigned char *chars;
+    FontEncoding charEncoding;
+    unsigned long *glyphCount; /* RETURN */
+    xCharInfo **glyphs;                /* RETURN */
+{
+    int         ret;
+    SpeedoFontPtr spf;
+    CharInfoPtr        oldDefault;
+
+    spf = (SpeedoFontPtr) pFont->fontPrivate;
+    oldDefault = spf->pDefault;
+    spf->pDefault = &nonExistantChar;
+    ret = sp_get_glyphs(pFont, count, chars, charEncoding,
+                       glyphCount, (CharInfoPtr *) glyphs);
+
+    spf->pDefault = oldDefault;
+    return ret;
+}
+
+int
+sp_open_font(fontname, filename, entry, vals, format, fmask, flags, spfont)
+    char       *fontname,
+               *filename;
+    FontEntryPtr entry;
+    FontScalablePtr vals;
+    fsBitmapFormat format;
+    fsBitmapFormatMask fmask;
+    Mask        flags;
+    SpeedoFontPtr *spfont;
+{
+    SpeedoFontPtr spf;
+    SpeedoMasterFontPtr spmf;
+    int         ret;
+    specs_t     specs;
+    int                xx8, xy8, yx8, yy8;
+    double     sxmult;
+
+    /* find a master (create it if necessary) */
+    spmf = (SpeedoMasterFontPtr) entry->u.scalable.extra->private;
+    if (!spmf)
+    {
+       ret = sp_open_master(filename, &spmf);
+       if (ret != Successful)
+           return ret;
+       entry->u.scalable.extra->private = (pointer) spmf;
+       spmf->entry = entry;
+    }
+
+    spf = (SpeedoFontPtr) xalloc(sizeof(SpeedoFontRec));
+    if (!spf)
+       return AllocError;
+    bzero((char *) spf, sizeof(SpeedoFontRec));
+
+    *spfont = spf;
+
+    /* clobber everything -- this may be leaking, but other wise evil
+     * stuff is left behind -- succesive transformed fonts get mangled */
+    bzero((char *)&sp_globals, sizeof(sp_globals));
+
+    spf->master = spmf;
+    spf->entry = entry;
+    spmf->refcount++;
+    sp_reset_master(spmf);
+    /* now we've done enough that if we bail out we must call sp_close_font */
+
+    spf->vals = *vals;
+
+    /* set up specs */
+
+    specs.pfont = &spmf->font;
+
+    specs.xxmult = (int)(vals->pixel_matrix[0] * (double)(1L << 16));
+    specs.xymult = (int)(vals->pixel_matrix[2] * (double)(1L << 16));
+    specs.yxmult = (int)(vals->pixel_matrix[1] * (double)(1L << 16));
+    specs.yymult = (int)(vals->pixel_matrix[3] * (double)(1L << 16));
+
+    specs.xoffset = 0L << 16; /* XXX tweak? */
+    specs.yoffset = 0L << 16; /* XXX tweak? */
+
+    specs.flags = MODE_SCREEN;
+    specs.out_info = NULL;
+
+    /* When Speedo tries to generate a very small font bitmap, it
+       often crashes or goes into an infinite loop.
+       Don't know why this is so, but until we can fix it properly,
+       return BadFontName for anything smaller than 4 pixels.
+       */
+#define TINY_FACTOR (16 << 16)
+    xx8 = specs.xxmult >> 8;
+    xy8 = specs.xymult >> 8;
+    yx8 = specs.yxmult >> 8;
+    yy8 = specs.yymult >> 8;
+    if (xx8 * xx8 + xy8 * xy8 < TINY_FACTOR ||
+       yx8 * yx8 + yy8 * yy8 < TINY_FACTOR)
+    {
+       sp_close_font(spf);
+       return BadFontName;
+    }
+
+    /* clobber global state to avoid wrecking future transformed fonts */
+    bzero ((char *) &sp_globals, sizeof(sp_globals));
+
+    if (!sp_set_specs(&specs))
+    {
+       sp_close_font(spf);
+       return BadFontName;
+    }
+
+    spf->specs = specs;
+    spf->master = spmf;
+
+    *spfont = spf;
+    return Successful;
+}
+
+static int
+sp_load_font(fontname, filename, entry, vals, format, fmask, pfont, flags)
+    char       *fontname,
+               *filename;
+    FontEntryPtr    entry;
+    FontScalablePtr vals;
+    fsBitmapFormat format;
+    fsBitmapFormatMask fmask;
+    FontPtr     pfont;
+    Mask        flags;
+{
+    SpeedoFontPtr spf;
+    SpeedoMasterFontPtr spmf;
+    int         esize;
+    int         ret;
+    long       sWidth;
+
+    ret = sp_open_font(fontname, filename, entry, vals, format, fmask,
+                      flags, &spf);
+
+    if (ret != Successful)
+       return ret;
+
+    spmf = spf->master;
+    sp_reset_master(spmf);
+    esize = sizeof(CharInfoRec) * (spmf->max_id - spmf->first_char_id + 1);
+
+    spf->encoding = (CharInfoPtr) xalloc(esize);
+    if (!spf->encoding) {
+       sp_close_font(spf);
+       return AllocError;
+    }
+    bzero((char *) spf->encoding, esize);
+
+    sp_fp_cur = spf;
+
+    sp_make_header(spf, &pfont->info);
+
+    sp_compute_bounds(spf, &pfont->info, SaveMetrics, &sWidth);
+
+    sp_compute_props(spf, fontname, &pfont->info, sWidth);
+
+    pfont->fontPrivate = (pointer) spf;
+
+/* XXX */
+    flags |= FontLoadBitmaps;
+
+    if (flags & FontLoadBitmaps) {
+       sp_fp_cur = spf;
+       ret = sp_build_all_bitmaps(pfont, format, fmask);
+    }
+    if (ret != Successful)
+       return ret;
+
+    /* compute remaining accelerators */
+    FontComputeInfoAccelerators(&pfont->info);
+
+    pfont->format = format;
+
+    pfont->get_metrics = sp_get_metrics;
+    pfont->get_glyphs = sp_get_glyphs;
+    pfont->unload_font = SpeedoCloseFont;
+    pfont->unload_glyphs = NULL;
+    pfont->refcnt = 0;
+    pfont->maxPrivate = -1;
+    pfont->devPrivates = (pointer *) 0;
+
+    /* have to hold on to master for min/max id */
+    sp_close_master_file(spmf);
+
+    return ret;
+}
+
+int
+SpeedoFontLoad(ppfont, fontname, filename, entry, vals, format, fmask, flags)
+    FontPtr    *ppfont;
+    char       *fontname;
+    char       *filename;
+    FontEntryPtr    entry;
+    FontScalablePtr vals;
+    fsBitmapFormat format;
+    fsBitmapFormatMask fmask;
+    Mask        flags;
+{
+    FontPtr     pfont;
+    int         ret;
+
+    /* Reject ridiculously small sizes that will blow up the math */
+    if (hypot(vals->pixel_matrix[0], vals->pixel_matrix[1]) < 1.0 ||
+       hypot(vals->pixel_matrix[2], vals->pixel_matrix[3]) < 1.0)
+       return BadFontName;
+
+    pfont = (FontPtr) xalloc(sizeof(FontRec));
+    if (!pfont) {
+       return AllocError;
+    }
+    ret = sp_load_font(fontname, filename, entry, vals, format, fmask,
+                      pfont, flags);
+
+    if (ret == Successful)
+       *ppfont = pfont;
+    else
+       xfree (pfont);
+    
+    return ret;
+}
+
+void
+sp_close_font(spf)
+    SpeedoFontPtr spf;
+{
+    SpeedoMasterFontPtr spmf;
+
+    spmf = spf->master;
+    --spmf->refcount;
+    if (spmf->refcount == 0)
+       sp_close_master_font (spmf);
+    xfree(spf->encoding);
+    xfree(spf->bitmaps);
+    xfree(spf);
+}
+
+void
+SpeedoCloseFont(pfont)
+    FontPtr     pfont;
+{
+    SpeedoFontPtr spf;
+
+    spf = (SpeedoFontPtr) pfont->fontPrivate;
+    sp_close_font(spf);
+    xfree(pfont->info.isStringProp);
+    xfree(pfont->info.props);
+    xfree(pfont->devPrivates);
+    xfree(pfont);
+}
diff --git a/Xserver/lib/font/Speedo/spfuncs.c b/Xserver/lib/font/Speedo/spfuncs.c
new file mode 100644 (file)
index 0000000..d368dc7
--- /dev/null
@@ -0,0 +1,160 @@
+/* $XConsortium: spfuncs.c,v 1.13 94/06/06 17:42:26 gildea Exp $ */
+/*
+ * Copyright 1990, 1991 Network Computing Devices;
+ * Portions Copyright 1987 by Digital Equipment Corporation
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and
+ * its documentation for any purpose is hereby granted without fee, provided
+ * that the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the names of Network Computing Devices or Digital
+ * not be used in advertising or publicity pertaining to distribution of
+ * the software without specific, written prior permission.
+ *
+ * NETWORK COMPUTING DEVICES AND DIGITAL DISCLAIM ALL WARRANTIES WITH
+ * REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS, IN NO EVENT SHALL NETWORK COMPUTING DEVICES OR DIGITAL BE
+ * LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
+ * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
+ * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ * Author: Dave Lemke, Network Computing Devices, Inc
+ */
+
+/*
+
+Copyright (c) 1987  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be included
+in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR
+OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall
+not be used in advertising or otherwise to promote the sale, use or
+other dealings in this Software without prior written authorization
+from the X Consortium.
+
+*/
+
+#include <X11/Xos.h>
+#include "fntfilst.h"
+#include "spint.h"
+
+/* ARGSUSED */
+SpeedoOpenScalable (fpe, pFont, flags, entry, fileName, vals, format, fmask,
+                   non_cachable_font)
+    FontPathElementPtr fpe;
+    FontPtr            *pFont;
+    int                        flags;
+    FontEntryPtr       entry;
+    char               *fileName;
+    FontScalablePtr    vals;
+    fsBitmapFormat     format;
+    fsBitmapFormatMask fmask;
+    FontPtr            non_cachable_font;      /* We don't do licensing */
+{
+    char       fullName[MAXFONTNAMELEN];
+
+    strcpy (fullName, entry->name.name);
+    return SpeedoFontLoad (pFont, fullName, fileName, entry, vals,
+                           format, fmask, flags);
+}
+
+/*
+ * XXX
+ *
+ * this does a lot more then i'd like, but it has to get the bitmaps
+ * in order to get accurate metrics (which it *must* have).
+ *
+ * a possible optimization is to avoid allocating the glyph memory
+ * and to simply save the values without doing the work.
+ */
+static int
+get_font_info(pinfo, fontname, filename, entry, vals, spfont)
+    FontInfoPtr pinfo;
+    char       *fontname;
+    char       *filename;
+    FontEntryPtr       entry;
+    FontScalablePtr    vals;
+    SpeedoFontPtr *spfont;
+{
+    SpeedoFontPtr spf;
+    int         err;
+    long       sWidth;
+
+    err = sp_open_font(fontname, filename, entry, vals,
+              (fsBitmapFormat) 0, (fsBitmapFormatMask) 0, (unsigned long) 0,
+                      &spf);
+
+    if (err != Successful)
+       return err;
+
+    sp_fp_cur = spf;
+    sp_reset_master(spf->master);
+
+    sp_make_header(spf, pinfo);
+
+    sp_compute_bounds(spf, pinfo, (unsigned long) 0, &sWidth);
+
+    sp_compute_props(spf, fontname, pinfo, sWidth);
+
+    /* compute remaining accelerators */
+    FontComputeInfoAccelerators (pinfo);
+
+    *spfont = spf;
+
+    return Successful;
+}
+
+/* ARGSUSED */
+SpeedoGetInfoScaleable(fpe, pFontInfo, entry, fontName, fileName, vals)
+    FontPathElementPtr fpe;
+    FontInfoPtr                pFontInfo;
+    FontEntryPtr       entry;
+    FontNamePtr                fontName;
+    char               *fileName;
+    FontScalablePtr    vals;
+{
+    SpeedoFontPtr spf = NULL;
+    char        fullName[MAXFONTNAMELEN];
+    int         err;
+
+    strcpy(fullName, entry->name.name);
+    FontParseXLFDName(fullName, vals, FONT_XLFD_REPLACE_VALUE);
+
+    err = get_font_info(pFontInfo, fullName, fileName, entry, vals, &spf);
+
+    if (spf)
+       sp_close_font(spf);
+
+    return err;
+}
+
+static FontRendererRec renderer = {
+    ".spd", 4, (int (*)()) 0, SpeedoOpenScalable,
+       (int (*)()) 0, SpeedoGetInfoScaleable, 0
+    , CAP_MATRIX | CAP_CHARSUBSETTING
+};
+    
+SpeedoRegisterFontFileFunctions()
+{
+    sp_make_standard_props();
+    sp_reset();
+    FontFileRegisterRenderer(&renderer);
+}
diff --git a/Xserver/lib/font/Speedo/spglyph.c b/Xserver/lib/font/Speedo/spglyph.c
new file mode 100644 (file)
index 0000000..4fb45cc
--- /dev/null
@@ -0,0 +1,405 @@
+/* $XConsortium: spglyph.c,v 1.17 94/04/17 20:17:49 gildea Exp $ */
+/*
+ * Copyright 1990, 1991 Network Computing Devices;
+ * Portions Copyright 1987 by Digital Equipment Corporation
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and
+ * its documentation for any purpose is hereby granted without fee, provided
+ * that the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the names of Network Computing Devices or Digital
+ * not be used in advertising or publicity pertaining to distribution of
+ * the software without specific, written prior permission.
+ *
+ * NETWORK COMPUTING DEVICES AND DIGITAL DISCLAIM ALL WARRANTIES WITH
+ * REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS, IN NO EVENT SHALL NETWORK COMPUTING DEVICES OR DIGITAL BE
+ * LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
+ * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
+ * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ * Author: Dave Lemke, Network Computing Devices Inc
+ */
+
+/*
+
+Copyright (c) 1987  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be included
+in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR
+OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall
+not be used in advertising or otherwise to promote the sale, use or
+other dealings in this Software without prior written authorization
+from the X Consortium.
+
+*/
+
+#include       <X11/X.h>       /* for bit order #defines */
+#include       "spint.h"
+
+#undef CLIP_BBOX_NOISE
+
+static CurrentFontValuesRec current_font_values;
+static CurrentFontValuesPtr cfv = &current_font_values;
+static int  bit_order,
+            byte_order,
+            scan;
+
+unsigned long
+sp_compute_data_size(pfont, mappad, scanlinepad, start, end)
+    FontPtr     pfont;
+    int         mappad,
+                scanlinepad;
+    unsigned long start,
+                end;
+{
+    unsigned long ch;
+    unsigned long size = 0;
+    int         bpr;
+    SpeedoFontPtr spf = (SpeedoFontPtr) pfont->fontPrivate;
+    FontInfoPtr pinfo = &pfont->info;
+    int         firstChar;
+
+    firstChar = spf->master->first_char_id;
+
+    /* allocate the space */
+    switch (mappad) {
+       int         charsize;
+       CharInfoPtr ci;
+       xCharInfo  *cim;
+
+    case BitmapFormatImageRectMin:
+       cfv->bpr = 0;
+       for (ch = start; ch <= end; ch++) {
+           ci = &spf->encoding[ch - firstChar];
+           if (!ci)
+               ci = spf->pDefault;
+           cim = &ci->metrics;
+           charsize = GLYPH_SIZE(ci, scanlinepad);
+           charsize *= cim->ascent + cim->descent;
+           size += charsize;
+       }
+       break;
+    case BitmapFormatImageRectMaxWidth:
+       bpr = GLWIDTHBYTESPADDED(FONT_MAX_WIDTH(pinfo), scanlinepad);
+       cfv->bpr = bpr;
+       for (ch = start; ch <= end; ch++) {
+           ci = &spf->encoding[ch - firstChar];
+           if (!ci)
+               ci = spf->pDefault;
+           cim = &ci->metrics;
+           charsize = bpr * (cim->ascent + cim->descent);
+           size += charsize;
+       }
+       break;
+    case BitmapFormatImageRectMax:
+       bpr = GLWIDTHBYTESPADDED(FONT_MAX_WIDTH(pinfo), scanlinepad);
+       cfv->bpr = bpr;
+       size = (end - start + 1) * bpr * FONT_MAX_HEIGHT(pinfo);
+       break;
+    default:
+       assert(0);
+    }
+
+    return size;
+}
+
+static void
+finish_line(spf)
+    SpeedoFontPtr spf;
+{
+    int         bpr = cfv->bpr;
+    CharInfoPtr ci = &spf->encoding[cfv->char_id - spf->master->first_char_id];
+
+    if (bpr == 0) {
+       bpr = GLYPH_SIZE(ci, cfv->scanpad);
+    }
+    if (bpr) {                 /* char may not have any metrics... */
+       cfv->bp += bpr;
+    }
+    assert(cfv->bp - sp_fp_cur->bitmaps <= sp_fp_cur->bitmap_size);
+}
+
+
+void
+sp_set_bitmap_bits(y, xbit1, xbit2)
+    fix15       y;
+    fix15       xbit1,
+                xbit2;
+{
+    int         nmiddle;
+    CARD8      startmask,
+                endmask;
+    CARD8      *dst;
+
+    if (xbit1 > cfv->bit_width) {
+
+#ifdef CLIP_BBOX_NOISE
+       SpeedoErr("Run wider than bitmap width -- truncated\n");
+#endif
+
+       xbit1 = cfv->bit_width;
+    }
+    if (xbit2 > cfv->bit_width) {
+
+#ifdef CLIP_BBOX_NOISE
+       SpeedoErr("Run wider than bitmap width -- truncated\n");
+#endif
+
+       xbit2 = cfv->bit_width;
+    }
+
+    if (xbit2 < xbit1) {
+       xbit2 = xbit1;
+    }
+
+    while (cfv->cur_y != y) {
+       finish_line(sp_fp_cur);
+       cfv->cur_y++;
+    }
+
+    cfv->last_y = y;
+    if (y >= cfv->bit_height) {
+
+#ifdef CLIP_BBOX_NOISE
+       SpeedoErr("Y larger than bitmap height -- truncated\n");
+#endif
+
+       cfv->trunc = 1;
+       return;
+    }
+    if (xbit1 < 0)             /* XXX this is more than a little bit rude... */
+       xbit1 = 0;
+
+    nmiddle = (xbit1 >> 3);
+    dst = (CARD8 *) (cfv->bp + nmiddle);
+    xbit2 -= (xbit1 & ~7);
+    nmiddle = (xbit2 >> 3);
+    xbit1 &= 7;
+    xbit2 &= 7;
+    if (bit_order == MSBFirst) {
+       startmask = ((CARD8) ~0) >> xbit1;
+       endmask = ~(((CARD8) ~0) >> xbit2);
+    } else {
+       startmask = ((CARD8) ~0) << xbit1;
+       endmask = ~(((CARD8) ~0) << xbit2);
+    }
+    if (nmiddle == 0)
+       *dst |= endmask & startmask;
+    else {
+       *dst++ |= startmask;
+       while (--nmiddle)
+           *dst++ = (CARD8)~0;
+       *dst |= endmask;
+    }
+}
+
+/* ARGSUSED */
+void
+sp_open_bitmap(x_set_width, y_set_width, xorg, yorg, xsize, ysize)
+    fix31       x_set_width;
+    fix31       y_set_width;
+    fix31       xorg;
+    fix31       yorg;
+    fix15       xsize;
+    fix15       ysize;
+{
+    CharInfoPtr ci = &sp_fp_cur->encoding[cfv->char_id - sp_fp_cur->master->first_char_id];
+
+/*-
+ * this is set to provide better quality bitmaps.  since the Speedo
+ * sp_get_bbox() function returns an approximate (but guarenteed to contain)
+ * set of metrics, some of the bitmaps can be place poorly inside and
+ * look bad.
+ *
+ * with this set, the actual bitmap values are used instead of the bboxes.
+ * it makes things look better, but causes two possible problems:
+ *
+ * 1 - the reported min & max bounds may not correspond to the extents
+ *     reported
+ * 2 - if the extents are reported before the character is generated,
+ *     a client could see them change.  this currently never happens,
+ *     but will when a desired enhancement (don't reneder till needed)
+ *     is made.
+ */
+
+#define        BBOX_FIXUP 1
+
+#ifdef BBOX_FIXUP
+    int         off_horz;
+    int         off_vert;
+
+    if (xorg < 0)
+       off_horz = (fix15) ((xorg - 32768L) / 65536);
+    else
+       off_horz = (fix15) ((xorg + 32768L) / 65536);
+    if (yorg < 0)
+       off_vert = (fix15) ((yorg - 32768L) / 65536);
+    else
+       off_vert = (fix15) ((yorg + 32768L) / 65536);
+    if (xsize != 0 || ysize != 0 || ci->metrics.characterWidth)
+    {
+       ci->metrics.leftSideBearing = off_horz;
+       ci->metrics.descent = -off_vert;
+       ci->metrics.rightSideBearing = xsize + off_horz;
+       ci->metrics.ascent = ysize + off_vert;
+    }
+    else
+    {
+    /* If setting the proper size would cause the character to appear to
+       be non-existent, fudge things by giving it a pixel to occupy.  */
+       xsize = ysize = 1;
+       ci->metrics.leftSideBearing = ci->metrics.descent = 0;
+       ci->metrics.rightSideBearing = ci->metrics.ascent = 1;
+    }
+
+    cfv->bit_width = xsize;
+    cfv->bit_height = ysize;
+#else
+    cfv->bit_width = ci->metrics.rightSideBearing -
+       ci->metrics.leftSideBearing;
+    cfv->bit_height = ci->metrics.ascent + ci->metrics.descent;
+#endif
+
+    assert(cfv->bp - sp_fp_cur->bitmaps <= sp_fp_cur->bitmap_size);
+    ci->bits = (char *) cfv->bp;
+
+    cfv->cur_y = 0;
+}
+
+void
+sp_close_bitmap()
+{
+    CharInfoPtr ci = &sp_fp_cur->encoding[cfv->char_id - sp_fp_cur->master->first_char_id];
+    int         bpr = cfv->bpr;
+
+    if (bpr == 0)
+       bpr = GLYPH_SIZE(ci, cfv->scanpad);
+    if (!cfv->trunc)
+       finish_line(sp_fp_cur);
+    cfv->trunc = 0;
+    cfv->last_y++;
+    while (cfv->last_y < cfv->bit_height) {
+       finish_line(sp_fp_cur);
+       cfv->last_y++;
+    }
+    if (byte_order != bit_order) {
+       switch (scan) {
+       case 1:
+           break;
+       case 2:
+           TwoByteSwap(cfv->bp, bpr * cfv->bit_height);
+           break;
+       case 4:
+           FourByteSwap(cfv->bp, bpr * cfv->bit_height);
+           break;
+       }
+    }
+}
+
+int
+sp_build_all_bitmaps(pfont, format, fmask)
+    FontPtr     pfont;
+    fsBitmapFormat format;
+    fsBitmapFormatMask fmask;
+{
+    int         ret,
+                glyph = 1,
+                image = BitmapFormatImageRectMin;
+    unsigned long glyph_size;
+    SpeedoFontPtr spf = (SpeedoFontPtr) pfont->fontPrivate;
+    SpeedoMasterFontPtr spmf = spf->master;
+    pointer     bitmaps;
+    int         start,
+                end,
+                i;
+
+    scan = 1;
+    ret = CheckFSFormat(format, fmask,
+                       &bit_order, &byte_order, &scan, &glyph, &image);
+
+    pfont->bit = bit_order;
+    pfont->byte = byte_order;
+    pfont->glyph = glyph;
+    pfont->scan = scan;
+    if (ret != Successful)
+       return BadFontFormat;
+
+    start = spmf->first_char_id;
+    end = spmf->max_id;
+    glyph_size = sp_compute_data_size(pfont, image, glyph, start, end);
+
+    /* XXX -- MONDO KLUDGE -- add some slop */
+    /*
+     * not sure why this is wanted, but it keeps the packer from going off the
+     * end and toasting us down the line
+     */
+    glyph_size += 20;
+
+#ifdef DEBUG
+    spf->bitmap_size = glyph_size;
+#endif
+
+    bitmaps = (pointer) xalloc(glyph_size);
+    if (!bitmaps)
+       return AllocError;
+    bzero((char *) bitmaps, glyph_size);
+
+    /* set up some state */
+    sp_fp_cur = spf;
+    spf->bitmaps = bitmaps;
+    cfv->format = format;
+    cfv->scanpad = glyph;
+    cfv->bp = bitmaps;
+
+    for (i = 0; i < spmf->num_chars; i++) {
+       int j;
+       cfv->char_index = spmf->enc[i * 2 + 1];
+       cfv->char_id = spmf->enc[i * 2];
+#if DEBUG
+fprintf(stderr, "build_all_sp_bitmaps:i = %d, Char ID = %d\n", i, cfv->char_id);
+#endif
+       if (!cfv->char_id)
+           continue;
+
+       /*
+        * See if this character is in the list of ranges specified in the
+        * XLFD name
+        */
+       for (j = 0; j < spf->vals.nranges; j++)
+           if (cfv->char_id >= mincharno(spf->vals.ranges[j]) &&
+                   cfv->char_id <= maxcharno(spf->vals.ranges[j]))
+               break;
+
+         /* If not, don't realize it. */
+       if (spf->vals.nranges && j == spf->vals.nranges)
+           continue;
+
+       if (!sp_make_char(cfv->char_index)) {
+
+#ifdef DEBUG                   /* can be very common with some encodings */
+           SpeedoErr("Can't make char %d\n", cfv->char_index);
+#endif
+       }
+    }
+
+    return Successful;
+}
diff --git a/Xserver/lib/font/Speedo/spinfo.c b/Xserver/lib/font/Speedo/spinfo.c
new file mode 100644 (file)
index 0000000..d061aa7
--- /dev/null
@@ -0,0 +1,441 @@
+/* $TOG: spinfo.c /main/17 1997/06/09 14:19:24 barstow $ */
+/*
+ * Copyright 1990, 1991 Network Computing Devices;
+ * Portions Copyright 1987 by Digital Equipment Corporation
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and
+ * its documentation for any purpose is hereby granted without fee, provided
+ * that the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the names of Network Computing Devices or Digital
+ * not be used in advertising or publicity pertaining to distribution of
+ * the software without specific, written prior permission.
+ *
+ * NETWORK COMPUTING DEVICES AND DIGITAL DISCLAIM ALL WARRANTIES WITH
+ * REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS, IN NO EVENT SHALL NETWORK COMPUTING DEVICES OR DIGITAL BE
+ * LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
+ * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
+ * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ * Author: Dave Lemke, Network Computing Devices, Inc
+ */
+
+/*
+
+Copyright (c) 1987  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be included
+in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR
+OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall
+not be used in advertising or otherwise to promote the sale, use or
+other dealings in this Software without prior written authorization
+from the X Consortium.
+
+*/
+
+#include "fntfilst.h"
+#include "spint.h"
+#include <math.h>
+
+/* percentage of pointsize used to specify ascent & descent */
+#define        STRETCH_FACTOR  120
+
+enum scaleType {
+    atom, truncate_atom, pixel_size, point_size, resolution_x,
+    resolution_y, average_width
+};
+
+typedef struct _fontProp {
+    char       *name;
+    long        atom;
+    enum scaleType type;
+}           fontProp;
+
+static fontProp fontNamePropTable[] = {
+    "FOUNDRY", 0, atom,
+    "FAMILY_NAME", 0, atom,
+    "WEIGHT_NAME", 0, atom,
+    "SLANT", 0, atom,
+    "SETWIDTH_NAME", 0, atom,
+    "ADD_STYLE_NAME", 0, atom,
+    "PIXEL_SIZE", 0, pixel_size,
+    "POINT_SIZE", 0, point_size,
+    "RESOLUTION_X", 0, resolution_x,
+    "RESOLUTION_Y", 0, resolution_y,
+    "SPACING", 0, atom,
+    "AVERAGE_WIDTH", 0, average_width,
+    "CHARSET_REGISTRY", 0, atom,
+    "CHARSET_ENCODING", 0, truncate_atom,
+};
+
+/* Warning: following array is closely related to the sequence of
+   defines after it. */
+
+static fontProp extraProps[] = {
+    "FONT", 0, 0,
+    "COPYRIGHT", 0, 0,
+    "RAW_PIXEL_SIZE", 0, 0,
+    "RAW_POINT_SIZE", 0, 0,
+    "RAW_ASCENT", 0, 0,
+    "RAW_DESCENT", 0, 0,
+    "RAW_AVERAGE_WIDTH", 0, 0,
+};
+
+/* this is a bit kludgy */
+#define        FONTPROP        0
+#define        COPYRIGHTPROP   1
+#define RAWPIXELPROP   2
+#define RAWPOINTPROP   3
+#define RAWASCENTPROP  4
+#define RAWDESCENTPROP 5
+#define RAWWIDTHPROP   6
+
+
+#define NNAMEPROPS (sizeof(fontNamePropTable) / sizeof(fontProp))
+#define NEXTRAPROPS (sizeof(extraProps) / sizeof(fontProp))
+
+#define        NPROPS  (NNAMEPROPS + NEXTRAPROPS)
+
+void
+sp_make_standard_props()
+{
+    int         i;
+    fontProp   *t;
+
+    i = sizeof(fontNamePropTable) / sizeof(fontProp);
+    for (t = fontNamePropTable; i; i--, t++)
+       t->atom = MakeAtom(t->name, (unsigned) strlen(t->name), TRUE);
+    i = sizeof(extraProps) / sizeof(fontProp);
+    for (t = extraProps; i; i--, t++)
+       t->atom = MakeAtom(t->name, (unsigned) strlen(t->name), TRUE);
+}
+
+void
+sp_make_header(spf, pinfo)
+    SpeedoFontPtr spf;
+    FontInfoPtr pinfo;
+{
+    int         pixel_size;
+    SpeedoMasterFontPtr spmf = spf->master;
+
+    pinfo->firstCol = spmf->first_char_id & 0xff;
+    pinfo->firstRow = spmf->first_char_id >> 8;
+    pinfo->lastCol = spmf->max_id & 0xff;
+    pinfo->lastRow = spmf->max_id >> 8;
+
+    /* XXX -- hackery here */
+    pinfo->defaultCh = 0;
+/* computed by FontComputeInfoAccelerators:
+ *  noOverlap
+ *  constantMetrics
+ *  terminalFont
+ *  constantWidth
+ *  inkInside
+ */
+    pinfo->inkMetrics = 0;
+    pinfo->allExist = 0;
+    pinfo->drawDirection = LeftToRight;
+    pinfo->cachable = 1;
+    if (spf->specs.xxmult != spf->specs.yymult)
+       pinfo->anamorphic = TRUE;
+    else
+       pinfo->anamorphic = FALSE;
+/* computed by sp_compute_bounds:
+ *  maxOverlap
+ *  maxbounds
+ *  minbounds
+ *  ink_maxbounds
+ *  ink_minbounds
+ */
+    pixel_size = spf->vals.pixel_matrix[3] * STRETCH_FACTOR / 100;
+    pinfo->fontAscent = pixel_size * 764 / 1000;       /* 764 == EM_TOP */
+    pinfo->fontDescent = pixel_size - pinfo->fontAscent;
+}
+
+static void
+adjust_min_max(minc, maxc, tmp)
+    xCharInfo  *minc,
+               *maxc,
+               *tmp;
+{
+#define MINMAX(field,ci) \
+       if (minc->field > (ci)->field) \
+            minc->field = (ci)->field; \
+       if (maxc->field < (ci)->field) \
+           maxc->field = (ci)->field;
+
+    MINMAX(ascent, tmp);
+    MINMAX(descent, tmp);
+    MINMAX(leftSideBearing, tmp);
+    MINMAX(rightSideBearing, tmp);
+    MINMAX(characterWidth, tmp);
+
+    if ((INT16)minc->attributes > (INT16)tmp->attributes)
+       minc->attributes = tmp->attributes;
+    if ((INT16)maxc->attributes < (INT16)tmp->attributes)
+       maxc->attributes = tmp->attributes;
+
+#undef MINMAX
+}
+
+
+void
+sp_compute_bounds(spf, pinfo, flags, sWidth)
+    SpeedoFontPtr spf;
+    FontInfoPtr pinfo;
+    unsigned long flags;
+    long *sWidth;
+{
+    int         i,
+                id,
+                index,
+               maxOverlap,
+               overlap,
+               total_width = 0;
+    xCharInfo   minchar,
+                maxchar,
+                tmpchar;
+    bbox_t      bbox;
+    fix31       width;
+    double      pix_width;
+    SpeedoMasterFontPtr spmf = spf->master;
+    int        firstChar;
+    int num_chars = 0;
+
+    firstChar = spmf->first_char_id;
+    minchar.ascent = minchar.descent =
+       minchar.leftSideBearing = minchar.rightSideBearing =
+       minchar.characterWidth = minchar.attributes = 32767;
+    maxchar.ascent = maxchar.descent =
+       maxchar.leftSideBearing = maxchar.rightSideBearing =
+       maxchar.characterWidth = maxchar.attributes = -32767;
+    maxOverlap = -32767;
+    *sWidth = 0;
+    for (i = 0; i < spmf->num_chars; i++) {
+       int j;
+       int char_id;
+
+       index = spmf->enc[i * 2 + 1];
+       char_id = spmf->enc[i * 2];
+      /*
+       * See if this character is in the list of ranges specified in the
+       * XLFD name
+       */
+       for (j = 0; j < spf->vals.nranges; j++)
+           if (char_id >= mincharno(spf->vals.ranges[j]) &&
+                   char_id <= maxcharno(spf->vals.ranges[j]))
+               break;
+       if (spf->vals.nranges && j == spf->vals.nranges)
+           continue;
+       num_chars++;
+
+       if (!(flags & ComputeBoundsOnly)) {
+
+           width = sp_get_char_width(index);
+
+           /* convert to pixel coords */
+           pix_width = (int)width * (spf->specs.xxmult / 65536L) +
+               ((int) width * (spf->specs.xxmult % 65536L))
+               / 65536L;
+           pix_width /= 65536L;
+
+           (void) sp_get_char_bbox(index, &bbox);
+           bbox.ymax = (bbox.ymax + 32768L) >> 16;
+           bbox.ymin = (bbox.ymin + 32768L) >> 16;
+           bbox.xmin = (bbox.xmin + 32768L) >> 16;
+           bbox.xmax = (bbox.xmax + 32768L) >> 16;
+           tmpchar.ascent = bbox.ymax;
+           tmpchar.descent = -bbox.ymin;
+           tmpchar.characterWidth = (int)(pix_width +          /* round */
+                                          (pix_width > 0 ? 0.5 : -0.5));
+           tmpchar.rightSideBearing = bbox.xmax;
+           tmpchar.leftSideBearing = bbox.xmin;
+
+           if (!tmpchar.characterWidth &&
+               tmpchar.ascent == -tmpchar.descent &&
+               tmpchar.rightSideBearing == tmpchar.leftSideBearing)
+           {
+               /* Character appears non-existent, probably as a result
+                  of the transformation.  Let's give it one pixel in
+                  the universe so it's not mistaken for non-existent. */
+               tmpchar.leftSideBearing = tmpchar.descent = 0;
+               tmpchar.rightSideBearing = tmpchar.ascent = 1;
+           }
+
+           tmpchar.attributes = (int)((double)(int)width / 65.536 + .5);
+       }
+       else
+           tmpchar = spf->encoding[char_id - firstChar].metrics;
+
+       adjust_min_max(&minchar, &maxchar, &tmpchar);
+       overlap = tmpchar.rightSideBearing - tmpchar.characterWidth;
+       if (maxOverlap < overlap)
+           maxOverlap = overlap;
+
+       total_width += ((int)(INT16)tmpchar.attributes);
+       *sWidth += abs((int)(INT16)tmpchar.attributes);
+
+       if (flags & SaveMetrics) {
+           id = spmf->enc[i * 2] - firstChar;
+           assert(id <= spmf->max_id - firstChar);
+           spf->encoding[id].metrics = tmpchar;
+       }
+    }
+
+
+    if (num_chars > 0)
+    {
+       *sWidth = (int)(((double)*sWidth * 10.0 + (double)num_chars / 2.0) /
+                         num_chars);
+       if (total_width < 0)
+       {
+           /* Predominant direction is R->L */
+           *sWidth = -*sWidth;
+       }
+       spf->vals.width = (int)((double)*sWidth * spf->vals.pixel_matrix[0] /
+                               1000.0 +
+                               (spf->vals.pixel_matrix[0] > 0 ? .5 : -.5));
+    }
+    else
+    {
+       spf->vals.width = 0;
+    }
+    pinfo->maxbounds = maxchar;
+    pinfo->minbounds = minchar;
+    pinfo->ink_maxbounds = maxchar;
+    pinfo->ink_minbounds = minchar;
+    pinfo->maxOverlap = maxOverlap;
+}
+
+void
+sp_compute_props(spf, fontname, pinfo, sWidth)
+    SpeedoFontPtr spf;
+    char       *fontname;
+    FontInfoPtr pinfo;
+    long       sWidth;
+{
+    FontPropPtr pp;
+    int         i,
+                nprops;
+    fontProp   *fpt;
+    char       *is_str;
+    char       *ptr1,
+               *ptr2;
+    char       *ptr3;
+    char       tmpname[1024];
+    FontScalableRec tmpvals;
+
+    nprops = pinfo->nprops = NPROPS;
+    pinfo->isStringProp = (char *) xalloc(sizeof(char) * nprops);
+    pinfo->props = (FontPropPtr) xalloc(sizeof(FontPropRec) * nprops);
+    if (!pinfo->isStringProp || !pinfo->props) {
+       xfree(pinfo->isStringProp);
+       pinfo->isStringProp = (char *) 0;
+       xfree(pinfo->props);
+       pinfo->props = (FontPropPtr) 0;
+       return;
+    }
+    bzero(pinfo->isStringProp, (sizeof(char) * nprops));
+
+    ptr2 = fontname;
+    for (i = NNAMEPROPS, pp = pinfo->props, fpt = fontNamePropTable,
+           is_str = pinfo->isStringProp;
+           i;
+           i--, pp++, fpt++, is_str++) {
+
+        if (*ptr2)
+        {
+            ptr1 = ptr2 + 1;
+            if (!(ptr2 = strchr(ptr1, '-'))) ptr2 = strchr(ptr1, '\0');
+        }
+
+       pp->name = fpt->atom;
+       switch (fpt->type) {
+       case atom:
+           *is_str = TRUE;
+           pp->value = MakeAtom(ptr1, ptr2 - ptr1, TRUE);
+           break;
+       case truncate_atom:
+           *is_str = TRUE;
+           for (ptr3 = ptr1; *ptr3; ptr3++)
+               if (*ptr3 == '[')
+                   break;
+           pp->value = MakeAtom(ptr1, ptr3 - ptr1, TRUE);
+           break;
+       case pixel_size:
+           pp->value = (int)(spf->vals.pixel_matrix[3] +
+                             (spf->vals.pixel_matrix[3] > 0 ? .5 : -.5));
+           break;
+       case point_size:
+           pp->value = (int)(spf->vals.point_matrix[3] * 10.0 +
+                             (spf->vals.point_matrix[3] > 0 ? .5 : -.5));
+           break;
+       case resolution_x:
+           pp->value = spf->vals.x;
+           break;
+       case resolution_y:
+           pp->value = spf->vals.y;
+           break;
+       case average_width:
+           pp->value = spf->vals.width;
+           break;
+       }
+    }
+
+    for (i = 0, fpt = extraProps; i < NEXTRAPROPS; i++, is_str++, pp++, fpt++) {
+       pp->name = fpt->atom;
+       switch (i) {
+       case FONTPROP:
+           *is_str = TRUE;
+           strcpy(tmpname, fontname);
+           FontParseXLFDName(tmpname, &tmpvals, FONT_XLFD_REPLACE_ZERO);
+           FontParseXLFDName(tmpname, &spf->vals, FONT_XLFD_REPLACE_VALUE);
+           pp->value = MakeAtom(tmpname, strlen(tmpname), TRUE);
+           break;
+       case COPYRIGHTPROP:
+           *is_str = TRUE;
+           pp->value = MakeAtom(spf->master->copyright,
+                                strlen(spf->master->copyright), TRUE);
+           break;
+         case RAWPIXELPROP:
+            *is_str = FALSE;
+            pp->value = 1000;
+           break;
+         case RAWPOINTPROP:
+            *is_str = FALSE;
+            pp->value = (long)(72270.0 / (double)spf->vals.y + .5);
+           break;
+         case RAWASCENTPROP:
+            *is_str = FALSE;
+            pp->value = STRETCH_FACTOR * 764 / 100;
+           break;
+         case RAWDESCENTPROP:
+            *is_str = FALSE;
+            pp->value = STRETCH_FACTOR * 236 / 100;
+           break;
+         case RAWWIDTHPROP:
+            *is_str = FALSE;
+            pp->value = sWidth;
+           break;
+       }
+    }
+}
diff --git a/Xserver/lib/font/Speedo/spint.h b/Xserver/lib/font/Speedo/spint.h
new file mode 100644 (file)
index 0000000..949b030
--- /dev/null
@@ -0,0 +1,174 @@
+/* $XConsortium: spint.h /main/12 1996/09/28 16:47:40 rws $ */
+/*
+ * Copyright 1990, 1991 Network Computing Devices;
+ * Portions Copyright 1987 by Digital Equipment Corporation
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and
+ * its documentation for any purpose is hereby granted without fee, provided
+ * that the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the names of Network Computing Devices or Digital
+ * not be used in advertising or publicity pertaining to distribution of
+ * the software without specific, written prior permission.
+ *
+ * NETWORK COMPUTING DEVICES AND DIGITAL DISCLAIM ALL WARRANTIES WITH
+ * REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS, IN NO EVENT SHALL NETWORK COMPUTING DEVICES OR DIGITAL BE
+ * LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
+ * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
+ * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+/*
+
+Copyright (c) 1987  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be included
+in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR
+OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall
+not be used in advertising or otherwise to promote the sale, use or
+other dealings in this Software without prior written authorization
+from the X Consortium.
+
+*/
+
+#ifndef _SPINT_H_
+#define _SPINT_H_
+
+#include <stdio.h>
+#include "fntfilst.h"
+#include <X11/Xfuncproto.h>
+#include "speedo.h"
+
+#define        SaveMetrics     0x1
+#define ComputeBoundsOnly      0x2
+
+#define GLWIDTHBYTESPADDED(bits,nbytes) \
+        ((nbytes) == 1 ? (((bits)+7)>>3)        /* pad to 1 byte */ \
+        :(nbytes) == 2 ? ((((bits)+15)>>3)&~1)  /* pad to 2 bytes */ \
+        :(nbytes) == 4 ? ((((bits)+31)>>3)&~3)  /* pad to 4 bytes */ \
+        :(nbytes) == 8 ? ((((bits)+63)>>3)&~7)  /* pad to 8 bytes */ \
+        : 0)
+
+#define GLYPH_SIZE(ch, nbytes)          \
+        GLWIDTHBYTESPADDED((ch)->metrics.rightSideBearing - \
+                        (ch)->metrics.leftSideBearing, (nbytes))
+
+#define mincharno(p) ((p).min_char_low + ((p).min_char_high << 8))
+#define maxcharno(p) ((p).max_char_low + ((p).max_char_high << 8))
+
+#define        MasterFileOpen  0x1
+
+typedef struct _sp_master {
+    FontEntryPtr    entry;     /* back pointer */
+    FILE       *fp;
+    char       *fname;
+    ufix8      *f_buffer;
+    ufix8      *c_buffer;
+    char       *copyright;
+    ufix8      *key;
+    buff_t      font;
+    buff_t      char_data;
+    ufix16      mincharsize;
+    int         first_char_id;
+    int         num_chars;
+    int         max_id;
+    int         state;         /* open, closed */
+    int         refcount;      /* number of instances */
+    int        *enc;
+    int         enc_size;
+}           SpeedoMasterFontRec, *SpeedoMasterFontPtr;
+
+typedef struct _cur_font_stats {
+    fsBitmapFormat format;
+    /* current glyph info */
+    ufix16      char_index;
+    ufix16      char_id;
+
+    fix15       bit_width,
+                bit_height;
+    fix15       cur_y;
+    int         bpr;
+
+    /*
+     * since Speedo returns extents that are not identical to what it feeds to
+     * the bitmap builder, and we want to be able to use the extents for
+     * preformance reasons, some of the bitmaps require padding out.  the next
+     * two flags keep track of this.
+     */
+    fix15       last_y;
+    int         trunc;
+
+    pointer     bp;
+    int         scanpad;
+}           CurrentFontValuesRec, *CurrentFontValuesPtr;
+
+
+typedef struct _sp_font {
+    struct _sp_master *master;
+    specs_t     specs;
+
+    FontEntryPtr    entry;
+
+    FontScalableRec vals;
+
+    /* char & metric data */
+    CharInfoPtr encoding;
+    CharInfoPtr pDefault;
+    pointer     bitmaps;
+
+#ifdef DEBUG
+    unsigned long bitmap_size;
+#endif
+
+}           SpeedoFontRec, *SpeedoFontPtr;
+
+extern SpeedoFontPtr sp_fp_cur;
+
+extern int  sp_open_font();
+extern int  sp_open_master();
+extern void sp_close_font();
+extern void sp_close_master_font();
+extern void sp_close_master_file();
+extern void sp_reset_master();
+#if NeedVarargsPrototypes
+extern void SpeedoErr(char *fmt, ...);
+#else
+extern void SpeedoErr();
+#endif
+
+extern void sp_make_standard_props();
+extern void sp_make_header();
+extern void sp_compute_bounds();
+extern void sp_compute_props();
+extern int  sp_build_all_bitmaps();
+extern unsigned long sp_compute_data_size();
+
+extern int  sp_bics_map[];
+extern int  sp_bics_map_size;
+
+#ifdef EXTRAFONTS
+extern int  adobe_map[];
+extern int  adobe_map_size;
+
+#endif
+
+#endif                         /* _SPINT_H_ */
diff --git a/Xserver/lib/font/Speedo/sptobdf.c b/Xserver/lib/font/Speedo/sptobdf.c
new file mode 100644 (file)
index 0000000..bc52bad
--- /dev/null
@@ -0,0 +1,680 @@
+/* $XConsortium: sptobdf.c,v 1.5 94/04/17 20:17:51 dpw Exp $ */
+/*
+ * Copyright 1990, 1991 Network Computing Devices;
+ * Portions Copyright 1987 by Digital Equipment Corporation
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the names of Network Computing Devices and 
+ * Digital not be used in advertising or publicity pertaining to 
+ * distribution of the software without specific, written prior permission.  
+ * Network Computing Devices and Digital make no representations about the
+ * suitability of this software for any purpose.  It is provided "as is"
+ * without express or implied warranty.
+ *
+ * NETWORK COMPUTING DEVICES AND DIGITAL DISCLAIM ALL WARRANTIES WITH
+ * REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS, IN NO EVENT SHALL NETWORK COMPUTING DEVICES OR DIGITAL BE
+ * LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
+ * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
+ * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ * Dave Lemke
+ */
+
+/*
+
+Copyright (c) 1987, 1994  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be included
+in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR
+OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall
+not be used in advertising or otherwise to promote the sale, use or
+other dealings in this Software without prior written authorization
+from the X Consortium.
+
+*/
+
+/*
+ * Speedo outline to BFD format converter
+ */
+
+#include       <stdio.h>
+#include       "speedo.h"
+
+#ifdef EXTRAFONTS
+#include       "ncdkeys.h"
+#else
+#include       "keys.h"
+#endif
+
+#include       "iso8859.h"
+
+#define        MAX_BITS        1024
+
+#define        BBOX_CLIP
+
+static char line_of_bits[MAX_BITS + 1];
+
+static FILE *fp;
+static ufix16 char_index,
+            char_id;
+static buff_t font;
+static buff_t char_data;
+static ufix8 *f_buffer,
+           *c_buffer;
+static ufix16 mincharsize;
+static fix15 cur_y;
+static fix15 bit_width,
+            bit_height;
+
+static ufix8 key[] =
+{
+    KEY0,
+    KEY1,
+    KEY2,
+    KEY3,
+    KEY4,
+    KEY5,
+    KEY6,
+    KEY7,
+    KEY8
+};                             /* Font decryption key */
+
+
+static char *progname;
+static char *fontname = NULL;
+static char *fontfile = NULL;
+
+static int  point_size = 120;
+static int  x_res = 72;
+static int  y_res = 72;
+static int  quality = 0;
+static int  iso_encoding = 1;
+
+static int  num_props = 7;
+static int  stretch = 120;
+
+static specs_t specs;
+
+static void dump_header();
+
+static void
+usage()
+{
+    fprintf(stderr, "Usage: %s [-xres x resolution] [-yres y resolution]\n\t[-ptsize pointsize] [-fn fontname] [-q quality (0-1)] fontfile\n", progname);
+    fprintf(stderr, "Where:\n");
+    fprintf(stderr, "-xres specifies the X resolution (72)\n");
+    fprintf(stderr, "-yres specifies the Y resolution (72)\n");
+    fprintf(stderr, "-pts specifies the pointsize in decipoints (120)\n");
+    fprintf(stderr, "-fn specifies the font name (full Bitstream name)\n");
+    fprintf(stderr, "-q specifies the font quality [0-1] (0)\n");
+    fprintf(stderr, "\n");
+    exit(0);
+}
+
+static      fix15
+read_2b(ptr)
+    ufix8      *ptr;
+{
+    fix15       tmp;
+
+    tmp = *ptr++;
+    tmp = (tmp << 8) + *ptr;
+    return tmp;
+}
+
+static      fix31
+read_4b(ptr)
+    ufix8      *ptr;
+{
+    fix31       tmp;
+
+    tmp = *ptr++;
+    tmp = (tmp << 8) + *ptr++;
+    tmp = (tmp << 8) + *ptr++;
+    tmp = (tmp << 8) + *ptr;
+    return tmp;
+}
+
+static void
+process_args(ac, av)
+    int         ac;
+    char      **av;
+{
+    int         i;
+
+    for (i = 1; i < ac; i++) {
+       if (!strncmp(av[i], "-xr", 3)) {
+           if (av[i + 1]) {
+               x_res = atoi(av[++i]);
+           } else
+               usage();
+       } else if (!strncmp(av[i], "-yr", 3)) {
+           if (av[i + 1]) {
+               y_res = atoi(av[++i]);
+           } else
+               usage();
+       } else if (!strncmp(av[i], "-pt", 3)) {
+           if (av[i + 1]) {
+               point_size = atoi(av[++i]);
+           } else
+               usage();
+       } else if (!strncmp(av[i], "-fn", 3)) {
+           if (av[i + 1]) {
+               fontname = av[++i];
+           } else
+               usage();
+       } else if (!strncmp(av[i], "-q", 2)) {
+           if (av[i + 1]) {
+               quality = atoi(av[++i]);
+           } else
+               usage();
+       } else if (!strncmp(av[i], "-st", 3)) {
+           if (av[i + 1]) {
+               stretch = atoi(av[++i]);
+           } else
+               usage();
+       } else if (!strncmp(av[i], "-noni", 5)) {
+           iso_encoding = 0;
+       } else if (*av[i] == '-') {
+           usage();
+       } else
+           fontfile = av[i];
+    }
+    if (!fontfile)
+       usage();
+}
+
+void
+main(argc, argv)
+    int         argc;
+    char      **argv;
+{
+    ufix32      i;
+    ufix8       tmp[16];
+    ufix32      minbufsize;
+    ufix16      cust_no;
+    int         first_char_index,
+                num_chars;
+
+    progname = argv[0];
+    process_args(argc, argv);
+    fp = fopen(fontfile, "r");
+    if (!fp) {
+       fprintf(stderr, "No such font file, \"%s\"\n", fontfile);
+       exit(-1);
+    }
+    if (fread(tmp, sizeof(ufix8), 16, fp) != 16) {
+       fprintf(stderr, "error reading \"%s\"\n", fontfile);
+       exit(-1);
+    }
+    minbufsize = (ufix32) read_4b(tmp + FH_FBFSZ);
+    f_buffer = (ufix8 *) malloc(minbufsize);
+    if (!f_buffer) {
+       fprintf(stderr, "can't get %x bytes of memory\n", minbufsize);
+       exit(-1);
+    }
+    fseek(fp, (ufix32) 0, 0);
+
+    if (fread(f_buffer, sizeof(ufix8), (ufix16) minbufsize, fp) != minbufsize) {
+       fprintf(stderr, "error reading file \"%s\"\n", fontfile);
+       exit(-1);
+    }
+    mincharsize = read_2b(f_buffer + FH_CBFSZ);
+
+    c_buffer = (ufix8 *) malloc(mincharsize);
+    if (!c_buffer) {
+       fprintf(stderr, "can't get %x bytes for char buffer\n", mincharsize);
+       exit(-1);
+    }
+    /* init */
+    sp_reset();
+
+    font.org = f_buffer;
+    font.no_bytes = minbufsize;
+
+    if ((cust_no = sp_get_cust_no(font)) != CUS0) {
+       fprintf(stderr, "Non-standard encryption for \"%s\"\n", fontfile);
+       exit(-1);
+    }
+    sp_set_key(key);
+
+    first_char_index = read_2b(f_buffer + FH_FCHRF);
+    num_chars = read_2b(f_buffer + FH_NCHRL);
+
+    /* set up specs */
+    /* Note that point size is in decipoints */
+    specs.pfont = &font;
+    /* XXX beware of overflow */
+    specs.xxmult = point_size * x_res / 720 * (1 << 16);
+    specs.xymult = 0L << 16;
+    specs.xoffset = 0L << 16;
+    specs.yxmult = 0L << 16;
+    specs.yymult = point_size * y_res / 720 * (1 << 16);
+    specs.yoffset = 0L << 16;
+    switch (quality) {
+    case 0:
+       specs.flags = 0;
+       break;
+    case 1:
+       specs.flags = MODE_SCREEN;
+       break;
+    case 2:
+       specs.flags = MODE_2D;
+       break;
+    default:
+       fprintf(stderr, "bogus quality value %d\n", quality);
+       break;
+    }
+    specs.out_info = NULL;
+
+    if (!fontname) {
+       fontname = (char *) (f_buffer + FH_FNTNM);
+    }
+    if (iso_encoding)
+       num_chars = num_iso_chars;
+    dump_header(num_chars);
+
+    if (!sp_set_specs(&specs)) {
+       fprintf(stderr, "can't set specs\n");
+    } else {
+       if (iso_encoding) {
+           for (i = 0; i < num_iso_chars * 2; i += 2) {
+               char_index = iso_map[i + 1];
+               char_id = iso_map[i];
+               if (!sp_make_char(char_index)) {
+                   fprintf(stderr, "can't make char %x\n", char_index);
+               }
+           }
+       } else {
+           for (i = 0; i < num_chars; i++) {
+               char_index = i + first_char_index;
+               char_id = sp_get_char_id(char_index);
+               if (char_id) {
+                   if (!sp_make_char(char_index)) {
+                       fprintf(stderr, "can't make char %x\n", char_index);
+                   }
+               }
+           }
+       }
+    }
+
+    (void) fclose(fp);
+
+    printf("ENDFONT\n");
+    exit(0);
+}
+
+static void
+dump_header(num_chars)
+    ufix32      num_chars;
+{
+    fix15       xmin,
+                ymin,
+                xmax,
+                ymax;
+    fix15       ascent,
+                descent;
+    fix15       pixel_size;
+
+    xmin = read_2b(f_buffer + FH_FXMIN);
+    ymin = read_2b(f_buffer + FH_FYMIN);
+    xmax = read_2b(f_buffer + FH_FXMAX);
+    ymax = read_2b(f_buffer + FH_FYMAX);
+    pixel_size = point_size * x_res / 720;
+
+    printf("STARTFONT 2.1\n");
+    printf("COMMENT\n");
+    printf("COMMENT Generated from Bitstream Speedo outlines via sptobdf\n");
+    printf("COMMENT\n");
+    printf("FONT %s\n", fontname);
+    printf("SIZE %d %d %d\n", pixel_size, x_res, y_res);
+    printf("FONTBOUNDINGBOX %d %d %d %d\n", xmin, ymin, xmax, ymax);
+    printf("STARTPROPERTIES %d\n", num_props);
+
+    printf("RESOLUTION_X %d\n", x_res);
+    printf("RESOLUTION_Y %d\n", y_res);
+    printf("POINT_SIZE %d\n", point_size);
+    printf("PIXEL_SIZE %d\n", pixel_size);
+    printf("COPYRIGHT \"%s\"\n", f_buffer + FH_CPYRT);
+
+    /* do some stretching here so that its isn't too tight */
+    pixel_size = pixel_size * stretch / 100;
+    ascent = pixel_size * 764 / 1000;  /* 764 == EM_TOP */
+    descent = pixel_size - ascent;
+    printf("FONT_ASCENT %d\n", ascent);
+    printf("FONT_DESCENT %d\n", descent);
+
+    printf("ENDPROPERTIES\n");
+    printf("CHARS %d\n", num_chars);
+}
+
+buff_t     *
+sp_load_char_data(file_offset, num, cb_offset)
+    fix31       file_offset;
+    fix15       num;
+    fix15       cb_offset;
+{
+    if (fseek(fp, (long) file_offset, (int) 0)) {
+       fprintf(stderr, "can't seek to char\n");
+       (void) fclose(fp);
+       exit(-1);
+    }
+    if ((num + cb_offset) > mincharsize) {
+       fprintf(stderr, "char buf overflow\n");
+       (void) fclose(fp);
+       exit(-2);
+    }
+    if (fread((c_buffer + cb_offset), sizeof(ufix8), num, fp) != num) {
+       fprintf(stderr, "can't get char data\n");
+       exit(-1);
+    }
+    char_data.org = (ufix8 *) c_buffer + cb_offset;
+    char_data.no_bytes = num;
+
+    return &char_data;
+}
+
+/*
+ * Called by Speedo character generator to report an error.
+ *
+ *  Since character data not available is one of those errors
+ *  that happens many times, don't report it to user
+ */
+void
+sp_report_error(n)
+    fix15       n;
+{
+    switch (n) {
+    case 1:
+       fprintf(stderr, "Insufficient font data loaded\n");
+       break;
+    case 3:
+       fprintf(stderr, "Transformation matrix out of range\n");
+       break;
+    case 4:
+       fprintf(stderr, "Font format error\n");
+       break;
+    case 5:
+       fprintf(stderr, "Requested specs not compatible with output module\n");
+       break;
+    case 7:
+       fprintf(stderr, "Intelligent transformation requested but not supported\n");
+       break;
+    case 8:
+       fprintf(stderr, "Unsupported output mode requested\n");
+       break;
+    case 9:
+       fprintf(stderr, "Extended font loaded but only compact fonts supported\n");
+       break;
+    case 10:
+       fprintf(stderr, "Font specs not set prior to use of font\n");
+       break;
+    case 12:
+       break;
+    case 13:
+       fprintf(stderr, "Track kerning data not available()\n");
+       break;
+    case 14:
+       fprintf(stderr, "Pair kerning data not available()\n");
+       break;
+    default:
+       fprintf(stderr, "report_error(%d)\n", n);
+       break;
+    }
+}
+
+void
+sp_open_bitmap(x_set_width, y_set_width, xorg, yorg, xsize, ysize)
+    fix31       x_set_width;
+    fix31       y_set_width;
+    fix31       xorg;
+    fix31       yorg;
+    fix15       xsize;
+    fix15       ysize;
+{
+    fix15       i;
+    fix15       off_horz;
+    fix15       off_vert;
+    fix31       width,
+                pix_width;
+    bbox_t      bb;
+
+    bit_width = xsize;
+
+    bit_height = ysize;
+    off_horz = (fix15) ((xorg + 32768L) >> 16);
+    off_vert = (fix15) ((yorg + 32768L) >> 16);
+
+    if (bit_width > MAX_BITS) {
+
+#ifdef DEBUG
+       fprintf(stderr, "char wider than max bits -- truncated\n");
+#endif
+
+       bit_width = MAX_BITS;
+    }
+    width = sp_get_char_width(char_index);
+    pix_width = width * (specs.xxmult / 65536L) +
+       ((ufix32) width * ((ufix32) specs.xxmult & 0xffff)) / 65536L;
+    pix_width /= 65536L;
+
+    width = (pix_width * 7200L) / (point_size * y_res);
+
+    (void) sp_get_char_bbox(char_index, &bb);
+    bb.xmin >>= 16;
+    bb.ymin >>= 16;
+    bb.xmax >>= 16;
+    bb.ymax >>= 16;
+
+#ifdef DEBUG
+    if ((bb.xmax - bb.xmin) != bit_width)
+       fprintf(stderr, "bbox & width mismatch 0x%x (%d) (%d vs %d)\n",
+               char_index, char_id, (bb.xmax - bb.xmin), bit_width);
+    if ((bb.ymax - bb.ymin) != bit_height)
+       fprintf(stderr, "bbox & height mismatch 0x%x (%d) (%d vs %d)\n",
+               char_index, char_id, (bb.ymax - bb.ymin), bit_height);
+    if (bb.xmin != off_horz)
+       fprintf(stderr, "x min mismatch 0x%x (%d) (%d vs %d)\n",
+               char_index, char_id, bb.xmin, off_horz);
+    if (bb.ymin != off_vert)
+       fprintf(stderr, "y min mismatch 0x%x (%d) (%d vs %d)\n",
+               char_index, char_id, bb.ymin, off_vert);
+#endif
+
+#ifdef BBOX_CLIP
+    bit_width = bb.xmax - bb.xmin;
+    bit_height = bb.ymax - bb.ymin;
+    off_horz = bb.xmin;
+    off_vert = bb.ymin;
+#endif
+
+    /* XXX kludge to handle space */
+    if (bb.xmin == 0 && bb.ymin == 0 && bb.xmax == 0 && bb.ymax == 0 &&
+           width) {
+       bit_width = 1;
+       bit_height = 1;
+    }
+    printf("STARTCHAR %d\n", char_id);
+    printf("ENCODING %d\n", char_id);
+    printf("SWIDTH %d 0\n", width);
+    printf("DWIDTH %d 0\n", pix_width);
+    printf("BBX %d %d %d %d\n", bit_width, bit_height, off_horz, off_vert);
+    printf("BITMAP\n");
+
+    for (i = 0; i < bit_width; i++) {
+       line_of_bits[i] = '.';
+    }
+    line_of_bits[bit_width] = '\0';
+    cur_y = 0;
+}
+
+static void
+dump_line(line)
+    ufix8      *line;
+{
+    int         bit;
+    unsigned    byte;
+
+    byte = 0;
+    for (bit = 0; bit < bit_width; bit++) {
+       if (line[bit] == 'X')
+           byte |= (1 << (7 - (bit & 7)));
+       if ((bit & 7) == 7) {
+           printf("%02X", byte);
+           byte = 0;
+       }
+    }
+    if ((bit & 7) != 0)
+       printf("%02X", byte);
+    printf("\n");
+}
+
+#ifdef BBOX_CLIP
+static fix15 last_y;
+static int  trunc = 0;
+
+#endif
+
+void
+sp_set_bitmap_bits(y, xbit1, xbit2)
+    fix15       y;
+    fix15       xbit1;
+    fix15       xbit2;
+{
+    fix15       i;
+
+    if (xbit1 > MAX_BITS) {
+
+#ifdef DEBUG
+       fprintf(stderr, "run wider than max bits -- truncated\n");
+#endif
+
+       xbit1 = MAX_BITS;
+    }
+    if (xbit2 > MAX_BITS) {
+
+#ifdef DEBUG
+       fprintf(stderr, "run wider than max bits -- truncated\n");
+#endif
+
+       xbit2 = MAX_BITS;
+    }
+    while (cur_y != y) {
+       dump_line(line_of_bits);
+       for (i = 0; i < bit_width; i++) {
+           line_of_bits[i] = '.';
+       }
+       cur_y++;
+    }
+
+#ifdef BBOX_CLIP
+    last_y = y;
+    if (y >= bit_height) {
+
+#ifdef DEBUG
+       fprintf(stderr,
+               "y value is larger than height 0x%x (%d) -- truncated\n",
+               char_index, char_id);
+#endif
+
+       trunc = 1;
+       return;
+    }
+#endif                         /* BBOX_CLIP */
+
+    for (i = xbit1; i < xbit2; i++) {
+       line_of_bits[i] = 'X';
+    }
+}
+
+void
+sp_close_bitmap()
+{
+
+#ifdef BBOX_CLIP
+    int         i;
+
+    if (!trunc)
+       dump_line(line_of_bits);
+    trunc = 0;
+
+
+    last_y++;
+    while (last_y < bit_height) {
+
+#ifdef DEBUG
+       fprintf(stderr, "padding out height for 0x%x (%d)\n",
+               char_index, char_id);
+#endif
+
+       for (i = 0; i < bit_width; i++) {
+           line_of_bits[i] = '.';
+       }
+       dump_line(line_of_bits);
+       last_y++;
+    }
+
+#else
+    dump_line(line_of_bits);
+#endif
+
+    printf("ENDCHAR\n");
+}
+
+/* outline stubs */
+void
+sp_open_outline()
+{
+}
+
+void
+sp_start_new_char()
+{
+}
+
+void
+sp_start_contour()
+{
+}
+
+void
+sp_curve_to()
+{
+}
+
+void
+sp_line_to()
+{
+}
+
+void
+sp_close_contour()
+{
+}
+
+void
+sp_close_outline()
+{
+}
diff --git a/Xserver/lib/font/Speedo/useropt.h b/Xserver/lib/font/Speedo/useropt.h
new file mode 100644 (file)
index 0000000..33b404f
--- /dev/null
@@ -0,0 +1,43 @@
+/* $XConsortium: useropt.h,v 1.4 94/04/17 20:17:52 gildea Exp $ */
+/*
+
+Copyright (c) 1993, 1994  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be included
+in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR
+OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall
+not be used in advertising or otherwise to promote the sale, use or
+other dealings in this Software without prior written authorization
+from the X Consortium.
+
+*/
+
+#define        INCL_LCD        1
+#define        STATIC_ALLOC    1
+
+#define        INCL_BLACK      1
+#define        INCL_SCREEN     1
+#define        INCL_2D         1
+#define        SHORT_LISTS     0
+
+#define        INCL_RULES      1
+#define        INCL_METRICS    1
+
+#define        INCL_KEYS       1
diff --git a/Xserver/lib/font/Type1/Imakefile b/Xserver/lib/font/Type1/Imakefile
new file mode 100644 (file)
index 0000000..a716ab5
--- /dev/null
@@ -0,0 +1,53 @@
+XCOMM $XConsortium: Imakefile,v 1.5 93/09/04 16:43:32 rws Exp $
+
+#include <Server.tmpl>
+
+INCLUDES = -I$(FONTINCSRC) -I../include
+
+SRCS =          \
+       arith.c         \
+       curves.c        \
+       fontfcn.c       \
+       hints.c         \
+       lines.c         \
+       objects.c       \
+       paths.c         \
+       regions.c       \
+       scanfont.c      \
+       spaces.c        \
+       t1funcs.c       \
+       t1info.c        \
+       t1io.c          \
+       t1malloc.c      \
+       t1snap.c        \
+       t1stub.c       \
+       token.c         \
+       type1.c         \
+       util.c
+
+OBJS =          \
+       arith.o         \
+       curves.o        \
+       fontfcn.o       \
+       hints.o         \
+       lines.o         \
+       objects.o       \
+       paths.o         \
+       regions.o       \
+       scanfont.o      \
+       spaces.o        \
+       t1funcs.o       \
+       t1info.o        \
+       t1io.o          \
+       t1malloc.o      \
+       t1snap.o        \
+       t1stub.o       \
+       token.o         \
+       type1.o         \
+       util.o
+
+SubdirLibraryRule($(OBJS))
+NormalLibraryObjectRule()
+NormalLintTarget($(SRCS))
+
+DependTarget()
diff --git a/Xserver/lib/font/Type1/arith.c b/Xserver/lib/font/Type1/arith.c
new file mode 100644 (file)
index 0000000..55e648f
--- /dev/null
@@ -0,0 +1,484 @@
+/* $XConsortium: arith.c,v 1.4 94/03/22 19:08:54 gildea Exp $ */
+/* Copyright International Business Machines, Corp. 1991
+ * All Rights Reserved
+ * Copyright Lexmark International, Inc. 1991
+ * All Rights Reserved
+ *
+ * License to use, copy, modify, and distribute this software and its
+ * documentation for any purpose and without fee is hereby granted,
+ * provided that the above copyright notice appear in all copies and that
+ * both that copyright notice and this permission notice appear in
+ * supporting documentation, and that the name of IBM or Lexmark not be
+ * used in advertising or publicity pertaining to distribution of the
+ * software without specific, written prior permission.
+ *
+ * IBM AND LEXMARK PROVIDE THIS SOFTWARE "AS IS", WITHOUT ANY WARRANTIES OF
+ * ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING, BUT NOT LIMITED TO ANY
+ * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE,
+ * AND NONINFRINGEMENT OF THIRD PARTY RIGHTS.  THE ENTIRE RISK AS TO THE
+ * QUALITY AND PERFORMANCE OF THE SOFTWARE, INCLUDING ANY DUTY TO SUPPORT
+ * OR MAINTAIN, BELONGS TO THE LICENSEE.  SHOULD ANY PORTION OF THE
+ * SOFTWARE PROVE DEFECTIVE, THE LICENSEE (NOT IBM OR LEXMARK) ASSUMES THE
+ * ENTIRE COST OF ALL SERVICING, REPAIR AND CORRECTION.  IN NO EVENT SHALL
+ * IBM OR LEXMARK BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
+ * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
+ * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
+ * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
+ * THIS SOFTWARE.
+ */
+ /* ARITH    CWEB         V0006 ********                             */
+/*
+:h1.ARITH Module - Portable Module for Multiple Precision Fixed Point Arithmetic
+This module provides division and multiplication of 64-bit fixed point
+numbers.  (To be more precise, the module works on numbers that take
+two 'longs' to store.  That is almost always equivalent to saying 64-bit
+numbers.)
+Note: it is frequently easy and desirable to recode these functions in
+assembly language for the particular processor being used, because
+assembly language, unlike C, will have 64-bit multiply products and
+64-bit dividends.  This module is offered as a portable version.
+&author. Jeffrey B. Lotspiech (lotspiech@almaden.ibm.com) and Sten F. Andler
+:h3.Include Files
+The included files are:
+*/
+#include "objects.h"
+#include "spaces.h"
+#include "arith.h"
+/*
+:h3.
+*/
+/*SHARED LINE(S) ORIGINATED HERE*/
+/*
+Reference for all algorithms:  Donald E. Knuth, "The Art of Computer
+Programming, Volume 2, Semi-Numerical Algorithms," Addison-Wesley Co.,
+Massachusetts, 1969, pp. 229-279.
+Knuth talks about a 'digit' being an arbitrary sized unit and a number
+being a sequence of digits.  We'll take a digit to be a 'short'.
+The following assumption must be valid for these algorithms to work:
+:ol.
+:li.A 'long' is two 'short's.
+:eol.
+The following code is INDEPENDENT of:
+:ol.
+:li.The actual size of a short.
+:li.Whether shorts and longs are stored most significant byte
+first or least significant byte first.
+:eol.
+SHORTSIZE is the number of bits in a short; LONGSIZE is the number of
+bits in a long; MAXSHORT is the maximum unsigned short:
+*/
+/*SHARED LINE(S) ORIGINATED HERE*/
+/*
+ASSEMBLE concatenates two shorts to form a long:
+*/
+#define     ASSEMBLE(hi,lo)   ((((unsigned long)hi)<<SHORTSIZE)+(lo))
+/*
+HIGHDIGIT extracts the most significant short from a long; LOWDIGIT
+extracts the least significant short from a long:
+*/
+#define     HIGHDIGIT(u)      ((u)>>SHORTSIZE)
+#define     LOWDIGIT(u)       ((u)&MAXSHORT)
+/*
+SIGNBITON tests the high order bit of a long 'w':
+*/
+#define    SIGNBITON(w)   (((long)w)<0)
+/*SHARED LINE(S) ORIGINATED HERE*/
+/*
+:h2.Double Long Arithmetic
+:h3.DLmult() - Multiply Two Longs to Yield a Double Long
+The two multiplicands must be positive.
+*/
+void DLmult(product, u, v)
+  register doublelong *product;
+  register unsigned long u;
+  register unsigned long v;
+{
+#ifdef LONG64
+/* printf("DLmult(? ?, %lx, %lx)\n", u, v); */
+    *product = u*v;
+/* printf("DLmult returns %lx\n", *product); */
+#else
+  register unsigned long u1, u2; /* the digits of u */
+  register unsigned long v1, v2; /* the digits of v */
+  register unsigned int w1, w2, w3, w4; /* the digits of w */
+  register unsigned long t; /* temporary variable */
+/* printf("DLmult(? ?, %x, %x)\n", u, v); */
+  u1 = HIGHDIGIT(u);
+  u2 = LOWDIGIT(u);
+  v1 = HIGHDIGIT(v);
+  v2 = LOWDIGIT(v);
+  if (v2 == 0) w4 = w3 = w2 = 0;
+  else
+    {
+    t = u2 * v2;
+    w4 = LOWDIGIT(t);
+    t = u1 * v2 + HIGHDIGIT(t);
+    w3 = LOWDIGIT(t);
+    w2 = HIGHDIGIT(t);
+    }
+  if (v1 == 0) w1 = 0;
+  else
+    {
+    t = u2 * v1 + w3;
+    w3 = LOWDIGIT(t);
+    t = u1 * v1 + w2 + HIGHDIGIT(t);
+    w2 = LOWDIGIT(t);
+    w1 = HIGHDIGIT(t);
+    }
+  product->high = ASSEMBLE(w1, w2);
+  product->low  = ASSEMBLE(w3, w4);
+#endif /* LONG64 else */
+}
+/*
+:h2.DLdiv() - Divide Two Longs by One Long, Yielding Two Longs
+Both the dividend and the divisor must be positive.
+*/
+void DLdiv(quotient, divisor)
+       doublelong *quotient;       /* also where dividend is, originally     */
+       unsigned long divisor;
+{
+#ifdef LONG64
+/* printf("DLdiv(%lx %lx)\n", quotient, divisor); */
+       *quotient /= divisor;
+/* printf("DLdiv returns %lx\n", *quotient); */
+#else
+       register unsigned long u1u2 = quotient->high;
+       register unsigned long u3u4 = quotient->low;
+       register long u3;     /* single digit of dividend                     */
+       register int v1,v2;   /* divisor in registers                         */
+       register long t;      /* signed copy of u1u2                          */
+       register int qhat;    /* guess at the quotient digit                  */
+       register unsigned long q3q4;  /* low two digits of quotient           */
+       register int shift;   /* holds the shift value for normalizing        */
+       register int j;       /* loop variable                                */
+/* printf("DLdiv(%x %x, %x)\n", quotient->high, quotient->low, divisor); */
+       /*
+       * Knuth's algorithm works if the dividend is smaller than the
+       * divisor.  We can get to that state quickly:
+       */
+       if (u1u2 >= divisor) {
+               quotient->high = u1u2 / divisor;
+               u1u2 %= divisor;
+       }
+       else
+               quotient->high = 0;
+       if (divisor <= MAXSHORT) {
+               /*
+               * This is the case where the divisor is contained in one
+               * 'short'.  It is worthwhile making this fast:
+               */
+               u1u2 = ASSEMBLE(u1u2, HIGHDIGIT(u3u4));
+               q3q4 = u1u2 / divisor;
+               u1u2 %= divisor;
+               u1u2 = ASSEMBLE(u1u2, LOWDIGIT(u3u4));
+               quotient->low = ASSEMBLE(q3q4, u1u2 / divisor);
+               return;
+       }
+       /*
+       * At this point the divisor is a true 'long' so we must use
+       * Knuth's algorithm.
+       *
+       * Step D1: Normalize divisor and dividend (this makes our 'qhat'
+       *        guesses more accurate):
+       */
+       for (shift=0; !SIGNBITON(divisor); shift++, divisor <<= 1) { ; }
+       shift--;
+       divisor >>= 1;
+       if ((u1u2 >> (LONGSIZE - shift)) != 0 && shift != 0)
+               abort("DLdiv:  dividend too large");
+       u1u2 = (u1u2 << shift) + ((shift == 0) ? 0 : u3u4 >> (LONGSIZE - shift));
+       u3u4 <<= shift;
+       /*
+       * Step D2:  Begin Loop through digits, dividing u1,u2,u3 by v1,v2,
+       *           then shifting U left by 1 digit:
+       */
+       v1 = HIGHDIGIT(divisor);
+       v2 = LOWDIGIT(divisor);
+       q3q4 = 0;
+       u3 = HIGHDIGIT(u3u4);
+       for (j=0; j < 2; j++) {
+               /*
+               * Step D3:  make a guess (qhat) at the next quotient denominator:
+               */
+               qhat = (HIGHDIGIT(u1u2) == v1) ? MAXSHORT : u1u2 / v1;
+               /*
+               * At this point Knuth would have us further refine our
+               * guess, since we know qhat is too big if
+               *
+               *      v2 * qhat > ASSEMBLE(u1u2 % v, u3)
+               *
+               * That would make sense if u1u2 % v was easy to find, as it
+               * would be in assembly language.  I ignore this step, and
+               * repeat step D6 if qhat is too big.
+               */
+               /*
+               * Step D4: Multiply v1,v2 times qhat and subtract it from
+               * u1,u2,u3:
+               */
+               u3 -= qhat * v2;
+               /*
+               * The high digit of u3 now contains the "borrow" for the
+               * rest of the substraction from u1,u2.
+               * Sometimes we can lose the sign bit with the above.
+               * If so, we have to force the high digit negative:
+               */
+               t = HIGHDIGIT(u3);
+               if (t > 0)
+                       t |= -1 << SHORTSIZE;
+               t += u1u2 - qhat * v1;
+/* printf("..>divide step qhat=%x t=%x u3=%x u1u2=%x v1=%x v2=%x\n",
+                             qhat, t, u3, u1u2, v1, v2); */
+               while (t < 0) {  /* Test is Step D5.                          */
+                       /*
+                       * D6: Oops, qhat was too big.  Add back in v1,v2 and
+                       * decrease qhat by 1:
+                       */
+                       u3 = LOWDIGIT(u3) + v2;
+                       t += HIGHDIGIT(u3) + v1;
+                       qhat--;
+/* printf("..>>qhat correction t=%x u3=%x qhat=%x\n", t, u3, qhat); */
+               }
+               /*
+               * Step D7:  shift U left one digit and loop:
+               */
+               u1u2 = t;
+               if (HIGHDIGIT(u1u2) != 0)
+                       abort("divide algorithm error");
+               u1u2 = ASSEMBLE(u1u2, LOWDIGIT(u3));
+               u3 = LOWDIGIT(u3u4);
+               q3q4 = ASSEMBLE(q3q4, qhat);
+       }
+       quotient->low = q3q4;
+/* printf("DLdiv returns %x %x\n", quotient->high, quotient->low); */
+#endif /* !LONG64 */
+       return;
+}
+/*
+:h3.DLadd() - Add Two Double Longs
+In this case, the doublelongs may be signed.  The algorithm takes the
+piecewise sum of the high and low longs, with the possibility that the
+high should be incremented if there is a carry out of the low.  How to
+tell if there is a carry?  Alex Harbury suggested that if the sum of
+the lows is less than the max of the lows, there must have been a
+carry.  Conversely, if there was a carry, the sum of the lows must be
+less than the max of the lows.  So, the test is "if and only if".
+*/
+void DLadd(u, v)
+       doublelong *u;        /* u = u + v                                    */
+       doublelong *v;
+{
+#ifdef LONG64
+/* printf("DLadd(%lx %lx)\n", *u, *v); */
+       *u = *u + *v;
+/* printf("DLadd returns %lx\n", *u); */
+#else
+       register unsigned long lowmax = MAX(u->low, v->low);
+/* printf("DLadd(%x %x, %x %x)\n", u->high, u->low, v->high, v->low); */
+       u->high += v->high;
+       u->low += v->low;
+       if (lowmax > u->low)
+               u->high++;
+#endif
+}
+/*
+:h3.DLsub() - Subtract Two Double Longs
+Testing for a borrow is even easier.  If the v.low is greater than
+u.low, there must be a borrow.
+*/
+void DLsub(u, v)
+       doublelong *u;        /* u = u - v                                    */
+       doublelong *v;
+{
+#ifdef LONG64
+/* printf("DLsub(%lx %lx)\n", *u, *v); */
+       *u = *u - *v;
+/* printf("DLsub returns %lx\n", *u); */
+#else
+/* printf("DLsub(%x %x, %x %x)\n", u->high, u->low, v->high, v->low);*/
+       u->high -= v->high;
+       if (v->low > u->low)
+               u->high--;
+       u->low -= v->low;
+#endif
+}
+/*
+:h3.DLrightshift() - Macro to Shift Double Long Right by N
+*/
+/*SHARED LINE(S) ORIGINATED HERE*/
+/*
+:h2.Fractional Pel Arithmetic
+*/
+/*
+:h3.FPmult() - Multiply Two Fractional Pel Values
+This funtion first calculates w = u * v to "doublelong" precision.
+It then shifts w right by FRACTBITS bits, and checks that no
+overflow will occur when the resulting value is passed back as
+a fractpel.
+*/
+fractpel FPmult(u, v)
+  register fractpel u,v;
+{
+  doublelong w;
+  register int negative = FALSE; /* sign flag */
+#ifdef LONG64
+  register fractpel ret;
+#endif
+  if ((u == 0) || (v == 0)) return (0);
+  if (u < 0) {u = -u; negative = TRUE;}
+  if (v < 0) {v = -v; negative = !negative;}
+  if (u == TOFRACTPEL(1)) return ((negative) ? -v : v);
+  if (v == TOFRACTPEL(1)) return ((negative) ? -u : u);
+  DLmult(&w, u, v);
+  DLrightshift(w, FRACTBITS);
+#ifndef LONG64
+  if (w.high != 0 || SIGNBITON(w.low)) {
+        IfTrace2(TRUE,"FPmult: overflow, %px%p\n", u, v);
+        w.low = TOFRACTPEL(MAXSHORT);
+  }
+  return ((negative) ? -w.low : w.low);
+#else
+  if (w & 0xffffffff80000000L ) {
+        IfTrace2(TRUE,"FPmult: overflow, %px%p\n", u, v);
+        ret = TOFRACTPEL(MAXSHORT);
+  }
+  else
+        ret = (fractpel)w;
+  return ((negative) ? -ret : ret);
+#endif
+}
+/*
+:h3.FPdiv() - Divide Two Fractional Pel Values
+These values may be signed.  The function returns the quotient.
+*/
+fractpel FPdiv(dividend, divisor)
+       register fractpel dividend;
+       register fractpel divisor;
+{
+       doublelong w;         /* result will be built here                    */
+       int negative = FALSE; /* flag for sign bit                            */
+#ifdef LONG64
+       register fractpel ret;
+#endif
+       if (dividend < 0) {
+               dividend = -dividend;
+               negative = TRUE;
+       }
+       if (divisor < 0) {
+               divisor = -divisor;
+               negative = !negative;
+       }
+#ifndef LONG64
+       w.low = dividend << FRACTBITS;
+       w.high = dividend >> (LONGSIZE - FRACTBITS);
+       DLdiv(&w, divisor);
+       if (w.high != 0 || SIGNBITON(w.low)) {
+               IfTrace2(TRUE,"FPdiv: overflow, %p/%p\n", dividend, divisor);
+               w.low = TOFRACTPEL(MAXSHORT);
+       }
+       return( (negative) ? -w.low : w.low);
+#else
+       w = ((long)dividend) << FRACTBITS;
+       DLdiv(&w, divisor);
+       if (w & 0xffffffff80000000L ) {
+               IfTrace2(TRUE,"FPdiv: overflow, %p/%p\n", dividend, divisor);
+               ret = TOFRACTPEL(MAXSHORT);
+       }
+       else
+               ret = (fractpel)w;
+       return( (negative) ? -ret : ret);
+#endif
+}
+/*
+:h3.FPstarslash() - Multiply then Divide
+Borrowing a chapter from the language Forth, it is useful to define
+an operator that first multiplies by one constant then divides by
+another, keeping the intermediate result in extended precision.
+*/
+fractpel FPstarslash(a, b, c)
+       register fractpel a,b,c;  /* result = a * b / c                       */
+{
+       doublelong w;         /* result will be built here                    */
+       int negative = FALSE;
+#ifdef LONG64
+       register fractpel ret;
+#endif
+       if (a < 0) { a = -a; negative = TRUE; }
+       if (b < 0) { b = -b; negative = !negative; }
+       if (c < 0) { c = -c; negative = !negative; }
+       DLmult(&w, a, b);
+       DLdiv(&w, c);
+#ifndef LONG64
+       if (w.high != 0 || SIGNBITON(w.low)) {
+               IfTrace3(TRUE,"FPstarslash: overflow, %p*%p/%p\n", a, b, c);
+               w.low = TOFRACTPEL(MAXSHORT);
+       }
+       return((negative) ? -w.low : w.low);
+#else
+       if (w & 0xffffffff80000000L ) {
+               IfTrace3(TRUE,"FPstarslash: overflow, %p*%p/%p\n", a, b, c);
+               ret = TOFRACTPEL(MAXSHORT);
+       }
+       else
+               ret = (fractpel)w;
+       return( (negative) ? -ret : ret);
+#endif
+}
diff --git a/Xserver/lib/font/Type1/arith.h b/Xserver/lib/font/Type1/arith.h
new file mode 100644 (file)
index 0000000..9853ade
--- /dev/null
@@ -0,0 +1,70 @@
+/* $XConsortium: arith.h,v 1.3 94/03/22 19:08:56 gildea Exp $ */
+/* Copyright International Business Machines, Corp. 1991
+ * All Rights Reserved
+ * Copyright Lexmark International, Inc. 1991
+ * All Rights Reserved
+ *
+ * License to use, copy, modify, and distribute this software and its
+ * documentation for any purpose and without fee is hereby granted,
+ * provided that the above copyright notice appear in all copies and that
+ * both that copyright notice and this permission notice appear in
+ * supporting documentation, and that the name of IBM or Lexmark not be
+ * used in advertising or publicity pertaining to distribution of the
+ * software without specific, written prior permission.
+ *
+ * IBM AND LEXMARK PROVIDE THIS SOFTWARE "AS IS", WITHOUT ANY WARRANTIES OF
+ * ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING, BUT NOT LIMITED TO ANY
+ * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE,
+ * AND NONINFRINGEMENT OF THIRD PARTY RIGHTS.  THE ENTIRE RISK AS TO THE
+ * QUALITY AND PERFORMANCE OF THE SOFTWARE, INCLUDING ANY DUTY TO SUPPORT
+ * OR MAINTAIN, BELONGS TO THE LICENSEE.  SHOULD ANY PORTION OF THE
+ * SOFTWARE PROVE DEFECTIVE, THE LICENSEE (NOT IBM OR LEXMARK) ASSUMES THE
+ * ENTIRE COST OF ALL SERVICING, REPAIR AND CORRECTION.  IN NO EVENT SHALL
+ * IBM OR LEXMARK BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
+ * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
+ * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
+ * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
+ * THIS SOFTWARE.
+ */
+/*SHARED*/
+
+#include <X11/Xmd.h>           /* LONG64 */
+
+void DLmult(),DLdiv(),DLadd(),DLsub();
+fractpel FPmult();
+fractpel FPdiv();
+fractpel FPstarslash();
+/*END SHARED*/
+/*SHARED*/
+#define     SHORTSIZE         (sizeof(short)*8)
+#define     LONGSIZE          (SHORTSIZE*2)
+#define     MAXSHORT          ((1<<SHORTSIZE)-1)
+/*END SHARED*/
+/*SHARED*/
+#ifdef LONG64
+typedef long doublelong;
+#else
+typedef struct {
+       long high;
+       unsigned long low;
+} doublelong;
+#endif /* LONG64 else */
+
+/*END SHARED*/
+/*SHARED*/
+#ifdef LONG64
+#define  DLrightshift(dl,N)  ((dl) >>= (N))
+#else
+#define  DLrightshift(dl,N)  { \
+       dl.low = (dl.low >> N) + (((unsigned long) dl.high) << (LONGSIZE - N)); \
+       dl.high >>= N; \
+}
+#endif
+
+/*END SHARED*/
diff --git a/Xserver/lib/font/Type1/blues.h b/Xserver/lib/font/Type1/blues.h
new file mode 100644 (file)
index 0000000..fce5893
--- /dev/null
@@ -0,0 +1,93 @@
+/* $XConsortium: blues.h,v 1.2 91/10/10 11:17:52 rws Exp $ */
+/* Copyright International Business Machines, Corp. 1991
+ * All Rights Reserved
+ * Copyright Lexmark International, Inc. 1991
+ * All Rights Reserved
+ * Portions Copyright (c) 1990 Adobe Systems Incorporated.
+ * All Rights Reserved
+ *
+ * License to use, copy, modify, and distribute this software and its
+ * documentation for any purpose and without fee is hereby granted,
+ * provided that the above copyright notice appear in all copies and that
+ * both that copyright notice and this permission notice appear in
+ * supporting documentation, and that the name of IBM or Lexmark or Adobe
+ * not be used in advertising or publicity pertaining to distribution of
+ * the software without specific, written prior permission.
+ *
+ * IBM, LEXMARK, AND ADOBE PROVIDE THIS SOFTWARE "AS IS", WITHOUT ANY
+ * WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING, BUT NOT
+ * LIMITED TO ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
+ * PARTICULAR PURPOSE, AND NONINFRINGEMENT OF THIRD PARTY RIGHTS.  THE
+ * ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE SOFTWARE, INCLUDING
+ * ANY DUTY TO SUPPORT OR MAINTAIN, BELONGS TO THE LICENSEE.  SHOULD ANY
+ * PORTION OF THE SOFTWARE PROVE DEFECTIVE, THE LICENSEE (NOT IBM,
+ * LEXMARK, OR ADOBE) ASSUMES THE ENTIRE COST OF ALL SERVICING, REPAIR AND
+ * CORRECTION.  IN NO EVENT SHALL IBM, LEXMARK, OR ADOBE BE LIABLE FOR ANY
+ * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
+ * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
+ * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
+ * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+extern psobj *GetType1CharString();
+#define TOPLEFT 1
+#define BOTTOMRIGHT 2
+#define NUMBLUEVALUES 14
+#define NUMOTHERBLUES 10
+#define NUMFAMILYBLUES 14
+#define NUMFAMILYOTHERBLUES 10
+#define NUMSTEMSNAPH 12
+#define NUMSTEMSNAPV 12
+#define NUMSTDHW 1
+#define NUMSTDVW 1
+#define DEFAULTBOLDSTEMWIDTH 2.0
+#define MAXALIGNMENTZONES ((NUMBLUEVALUES+NUMOTHERBLUES)/2)
+#define DEFAULTBLUESCALE 0.039625
+#define DEFAULTBLUESHIFT 7
+#define DEFAULTBLUEFUZZ 1
+#define DEFAULTSTDHW 0
+#define DEFAULTSTDVW 0
+#define DEFAULTFORCEBOLD FALSE
+#define DEFAULTLANGUAGEGROUP 0
+#define DEFAULTRNDSTEMUP FALSE
+#define DEFAULTLENIV 4
+#define DEFAULTEXPANSIONFACTOR 0.06
+/* see Type 1 Font Format book for explanations of these values */
+/* Note that we're currently doing nothing for minfeature and password. */
+struct blues_struct {
+        struct blues_struct *next;   /* ptr to next Blues structure in list */
+        int numBlueValues;   /* # of BlueValues in following array */
+        int BlueValues[NUMBLUEVALUES];
+        int numOtherBlues;   /* # of OtherBlues values in following array */
+        int OtherBlues[NUMOTHERBLUES];
+        int numFamilyBlues;   /* # of FamilyBlues values in following array */
+        int FamilyBlues[NUMFAMILYBLUES];
+        int numFamilyOtherBlues; /* # of FamilyOtherBlues values in  */
+        int FamilyOtherBlues[NUMFAMILYOTHERBLUES]; /* this array */
+        double BlueScale;
+        int BlueShift;
+        int BlueFuzz;
+        double StdHW;
+        double StdVW;
+        int numStemSnapH;   /* # of StemSnapH values in following array */
+        double StemSnapH[NUMSTEMSNAPH];
+        int numStemSnapV;   /* # of StemSnapV values in following array */
+        double StemSnapV[NUMSTEMSNAPV];
+        int ForceBold;
+        int LanguageGroup;
+        int RndStemUp;
+        int lenIV;
+        double ExpansionFactor;
+};
+/* the alignment zone structure -- somewhat similar to the stem structure */
+/* see Adobe Type1 Font Format book about the terms used in this structure */
+struct alignmentzone {
+        int topzone;        /* TRUE if a topzone, FALSE if a bottom zone */
+        double bottomy, topy;       /* interval of this alignment zone */
+};
diff --git a/Xserver/lib/font/Type1/cluts.h b/Xserver/lib/font/Type1/cluts.h
new file mode 100644 (file)
index 0000000..fe51e02
--- /dev/null
@@ -0,0 +1,35 @@
+/* $XConsortium: cluts.h,v 1.2 91/10/10 11:17:54 rws Exp $ */
+/* Copyright International Business Machines,Corp. 1991
+ * All Rights Reserved
+ *
+ * License to use, copy, modify, and distribute this software
+ * and its documentation for any purpose and without fee is
+ * hereby granted, provided that the above copyright notice
+ * appear in all copies and that both that copyright notice and
+ * this permission notice appear in supporting documentation,
+ * and that the name of IBM not be used in advertising or
+ * publicity pertaining to distribution of the software without
+ * specific, written prior permission.
+ *
+ * IBM PROVIDES THIS SOFTWARE "AS IS", WITHOUT ANY WARRANTIES
+ * OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING, BUT NOT
+ * LIMITED TO ANY IMPLIED WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, AND NONINFRINGEMENT OF
+ * THIRD PARTY RIGHTS.  THE ENTIRE RISK AS TO THE QUALITY AND
+ * PERFORMANCE OF THE SOFTWARE, INCLUDING ANY DUTY TO SUPPORT
+ * OR MAINTAIN, BELONGS TO THE LICENSEE.  SHOULD ANY PORTION OF
+ * THE SOFTWARE PROVE DEFECTIVE, THE LICENSEE (NOT IBM) ASSUMES
+ * THE ENTIRE COST OF ALL SERVICING, REPAIR AND CORRECTION.  IN
+ * NO EVENT SHALL IBM BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
+ * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
+ * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
+ * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+ */
+/* STUB */
+#define   KillCLUT(T)
+#define   CopyCLUT(T)                T
+#define   UniqueCLUT(T)
diff --git a/Xserver/lib/font/Type1/curves.c b/Xserver/lib/font/Type1/curves.c
new file mode 100644 (file)
index 0000000..c5b7d5b
--- /dev/null
@@ -0,0 +1,217 @@
+/* $XConsortium: curves.c,v 1.4 92/07/07 17:14:55 gildea Exp $ */
+/* Copyright International Business Machines,Corp. 1991              */
+/* All Rights Reserved                                               */
+/* License to use, copy, modify, and distribute this software        */
+/* and its documentation for any purpose and without fee is          */
+/* hereby granted, provided that licensee provides a license to      */
+/* IBM, Corp. to use, copy, modify, and distribute derivative        */
+/* works and their documentation for any purpose and without         */
+/* fee, that the above copyright notice appear in all copies         */
+/* and that both that copyright notice and this permission           */
+/* notice appear in supporting documentation, and that the name      */
+/* of IBM not be used in advertising or publicity pertaining to      */
+/* distribution of the software without specific, written prior      */
+/* permission.                                                       */
+/* IBM PROVIDES THIS SOFTWARE "AS IS", WITHOUT ANY WARRANTIES        */
+/* OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING, BUT NOT        */
+/* LIMITED TO ANY IMPLIED WARRANTIES OF MERCHANTABILITY,             */
+/* FITNESS FOR A PARTICULAR PURPOSE, AND NONINFRINGEMENT OF          */
+/* THIRD PARTY RIGHTS.  THE ENTIRE RISK AS TO THE QUALITY AND        */
+/* PERFORMANCE OF THE SOFTWARE, INCLUDING ANY DUTY TO SUPPORT        */
+/* OR MAINTAIN, BELONGS TO THE LICENSEE.  SHOULD ANY PORTION OF      */
+/* THE SOFTWARE PROVE DEFECTIVE, THE LICENSEE (NOT IBM) ASSUMES      */
+/* THE ENTIRE COST OF ALL SERVICING, REPAIR AND CORRECTION.  IN      */
+/* NO EVENT SHALL IBM BE LIABLE FOR ANY SPECIAL, INDIRECT OR         */
+/* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING         */
+/* FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF        */
+/* CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT        */
+/* OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS           */
+/* SOFTWARE.                                                         */
+/*
+:h1.CURVES Module - Stepping Beziers
+This module is responsible for "rasterizing"
+third order curves.  That is, it changes the high level curve
+specification into a list of pels that that curve travels
+through.
+:h3.Include Files
+Include files needed:
+*/
+#include "objects.h"
+#include "spaces.h"
+#include "paths.h"
+#include "regions.h"
+#include "curves.h"
+#include "lines.h"
+#include "arith.h"
+/*
+:h3.Functions Provided to Other Modules
+External entry points:
+*/
+/*SHARED LINE(S) ORIGINATED HERE*/
+/*
+Note that "stepping" and "flattening" are so similiar that they use the
+same routine.  When the "region" parameter is NULL, that is a flag that
+we are flattening instead of stepping.
+*/
+/*
+:h2.Bezier Third Order Curves
+*/
+/*
+:h3.The "bezierinfo" Structure
+This structure is used to store information used when we subdivide
+Bezier curves.
+*/
+struct bezierinfo {
+       struct region *region;  /* the region being built or NULL             */
+       struct fractpoint last;  /* not used yet; maybe could save some work  */
+       struct fractpoint origin;  /* the origin of the bezier                */
+} ;
+/*
+   Checking for termination of the subdivision process:
+   This is the stupidest test in the world, just check if the coordinatewise
+   distance from an end control point to the next control point is less than
+   one half pel.   If so, we must be done.
+   This returns 1 if the subdivision is terminated and 0 if you still need
+   to subdivide.
+*/
+static int BezierTerminationTest(xa,ya,xb,yb,xc,yc,xd,yd)
+fractpel xa,ya,xb,yb,xc,yc,xd,yd;
+{
+  fractpel dmax;
+  dmax =          ABS(xa - xb);
+  dmax = MAX(dmax,ABS(ya - yb));
+  dmax = MAX(dmax,ABS(xd - xc));
+  dmax = MAX(dmax,ABS(yd - yc));
+  if(dmax > FPHALF)
+    return(0); /* not done yet */
+  else
+    return(1); /* done */
+}
+/*
+:h3.StepBezierRecurse() - The Recursive Logic in StepBezier()
+The recursion involves dividing the control polygon into two smaller
+control polygons by finding the midpoints of the lines.  This idea is
+described in any graphics text book and its simplicity is what caused
+Bezier to define his curves as he did.  If the input region 'R' is NULL,
+the result is a path that is the 'flattened' curve; otherwise StepBezier
+returns nothing special.
+*/
+static struct segment *StepBezierRecurse(I,xA,yA,xB,yB,xC,yC,xD,yD)
+       struct bezierinfo *I; /* Region under construction or NULL            */
+       fractpel xA,yA;       /* A control point                              */
+       fractpel xB,yB;       /* B control point                              */
+       fractpel xC,yC;       /* C control point                              */
+       fractpel xD,yD;       /* D control point                              */
+{
+ if (BezierTerminationTest(xA,yA,xB,yB,xC,yC,xD,yD))
+ {
+  if (I->region == NULL)
+   return(PathSegment(LINETYPE, xD - xA, yD - yA));
+  else
+   StepLine(I->region, I->origin.x + xA, I->origin.y + yA,
+                       I->origin.x + xD, I->origin.y + yD);
+ }
+ else
+ {
+  fractpel xAB,yAB;
+  fractpel xBC,yBC;
+  fractpel xCD,yCD;
+  fractpel xABC,yABC;
+  fractpel xBCD,yBCD;
+  fractpel xABCD,yABCD;
+  xAB = xA + xB;  yAB = yA + yB;
+  xBC = xB + xC;  yBC = yB + yC;
+  xCD = xC + xD;  yCD = yC + yD;
+  xABC = xAB + xBC;  yABC = yAB + yBC;
+  xBCD = xBC + xCD;  yBCD = yBC + yCD;
+  xABCD = xABC + xBCD;  yABCD = yABC + yBCD;
+  xAB >>= 1;   yAB >>= 1;
+  xBC >>= 1;   yBC >>= 1;
+  xCD >>= 1;   yCD >>= 1;
+  xABC >>= 2;   yABC >>= 2;
+  xBCD >>= 2;   yBCD >>= 2;
+  xABCD >>= 3;   yABCD >>= 3;
+  if (I->region == NULL)
+  {
+   return( Join(
+    StepBezierRecurse(I, xA, yA, xAB, yAB, xABC, yABC, xABCD, yABCD),
+    StepBezierRecurse(I, xABCD, yABCD, xBCD, yBCD, xCD, yCD, xD, yD)
+                )
+         );
+  }
+  else
+  {
+   StepBezierRecurse(I, xA, yA, xAB, yAB, xABC, yABC, xABCD, yABCD);
+   StepBezierRecurse(I, xABCD, yABCD, xBCD, yBCD, xCD, yCD, xD, yD);
+  }
+ }
+ /*NOTREACHED*/
+}
+/*
+:h3.TOOBIG() - Macro to Test if a Coordinate is Too Big to Bezier SubDivide Normally
+Intermediate values in the Bezier subdivision are 8 times bigger than
+the starting values.  If this overflows, a 'long', we are in trouble:
+*/
+#define  BITS         (sizeof(long)*8)
+#define  HIGHTEST(p)  (((p)>>(BITS-4)) != 0)  /* includes sign bit */
+#define  TOOBIG(xy)   ((xy < 0) ? HIGHTEST(-xy) : HIGHTEST(xy))
+/*
+:h3.StepBezier() - Produce Run Ends for a Bezier Curve
+This is the entry point called from outside the module.
+*/
+struct segment *StepBezier(R, xA, yA, xB, yB, xC, yC, xD, yD)
+       struct region *R;     /* Region under construction or NULL            */
+       fractpel xA,yA;       /* A control point                              */
+       fractpel xB,yB;       /* B control point                              */
+       fractpel xC,yC;       /* C control point                              */
+       fractpel xD,yD;       /* D control point                              */
+{
+       struct bezierinfo Info;
+       Info.region = R;
+       Info.origin.x = xA;
+       Info.origin.y = yA;
+       xB -= xA;
+       xC -= xA;
+       xD -= xA;
+       yB -= yA;
+       yC -= yA;
+       yD -= yA;
+       if ( TOOBIG(xB) || TOOBIG(yB) || TOOBIG(xC) || TOOBIG(yC)
+            || TOOBIG(xD) || TOOBIG(yD) )
+               abort("Beziers this big not yet supported");
+       return(StepBezierRecurse(&Info,
+                                (fractpel) 0, (fractpel) 0, xB, yB, xC, yC, xD, yD));
+}
diff --git a/Xserver/lib/font/Type1/curves.h b/Xserver/lib/font/Type1/curves.h
new file mode 100644 (file)
index 0000000..80a73be
--- /dev/null
@@ -0,0 +1,40 @@
+/* $XConsortium: curves.h,v 1.2 91/10/10 11:17:59 rws Exp $ */
+/* Copyright International Business Machines, Corp. 1991
+ * All Rights Reserved
+ * Copyright Lexmark International, Inc. 1991
+ * All Rights Reserved
+ *
+ * License to use, copy, modify, and distribute this software and its
+ * documentation for any purpose and without fee is hereby granted,
+ * provided that the above copyright notice appear in all copies and that
+ * both that copyright notice and this permission notice appear in
+ * supporting documentation, and that the name of IBM or Lexmark not be
+ * used in advertising or publicity pertaining to distribution of the
+ * software without specific, written prior permission.
+ *
+ * IBM AND LEXMARK PROVIDE THIS SOFTWARE "AS IS", WITHOUT ANY WARRANTIES OF
+ * ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING, BUT NOT LIMITED TO ANY
+ * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE,
+ * AND NONINFRINGEMENT OF THIRD PARTY RIGHTS.  THE ENTIRE RISK AS TO THE
+ * QUALITY AND PERFORMANCE OF THE SOFTWARE, INCLUDING ANY DUTY TO SUPPORT
+ * OR MAINTAIN, BELONGS TO THE LICENSEE.  SHOULD ANY PORTION OF THE
+ * SOFTWARE PROVE DEFECTIVE, THE LICENSEE (NOT IBM OR LEXMARK) ASSUMES THE
+ * ENTIRE COST OF ALL SERVICING, REPAIR AND CORRECTION.  IN NO EVENT SHALL
+ * IBM OR LEXMARK BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
+ * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
+ * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
+ * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
+ * THIS SOFTWARE.
+ */
+/*SHARED*/
+#define   StepConic(R,xA,yA,xB,yB,xC,yC,r)      t1_StepConic(R,xA,yA,xB,yB,xC,yC,r)
+#define   StepBezier(R,xA,yA,xB,yB,xC,yC,xD,yD) t1_StepBezier(R,xA,yA,xB,yB,xC,yC,xD,yD)
+#define   FlattenConic(xM,yM,xC,yC,r)        t1_StepConic(NULL,(fractpel)0,(fractpel)0,xM,yM,xC,yC,r)
+#define   FlattenBezier(xB,yB,xC,yC,xD,yD)   t1_StepBezier(NULL,(fractpel)0,(fractpel)0,xB,yB,xC,yC,xD,yD)
+struct segment *t1_StepConic();
+struct segment *t1_StepBezier();
+/*END SHARED*/
diff --git a/Xserver/lib/font/Type1/digit.h b/Xserver/lib/font/Type1/digit.h
new file mode 100644 (file)
index 0000000..4ed89c7
--- /dev/null
@@ -0,0 +1,64 @@
+/* $XConsortium: digit.h,v 1.2 91/10/10 11:18:01 rws Exp $ */
+/* Copyright International Business Machines,Corp. 1991
+ * All Rights Reserved
+ *
+ * License to use, copy, modify, and distribute this software
+ * and its documentation for any purpose and without fee is
+ * hereby granted, provided that the above copyright notice
+ * appear in all copies and that both that copyright notice and
+ * this permission notice appear in supporting documentation,
+ * and that the name of IBM not be used in advertising or
+ * publicity pertaining to distribution of the software without
+ * specific, written prior permission.
+ *
+ * IBM PROVIDES THIS SOFTWARE "AS IS", WITHOUT ANY WARRANTIES
+ * OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING, BUT NOT
+ * LIMITED TO ANY IMPLIED WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, AND NONINFRINGEMENT OF
+ * THIRD PARTY RIGHTS.  THE ENTIRE RISK AS TO THE QUALITY AND
+ * PERFORMANCE OF THE SOFTWARE, INCLUDING ANY DUTY TO SUPPORT
+ * OR MAINTAIN, BELONGS TO THE LICENSEE.  SHOULD ANY PORTION OF
+ * THE SOFTWARE PROVE DEFECTIVE, THE LICENSEE (NOT IBM) ASSUMES
+ * THE ENTIRE COST OF ALL SERVICING, REPAIR AND CORRECTION.  IN
+ * NO EVENT SHALL IBM BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
+ * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
+ * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
+ * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+ */
+/* -------------------------------------- */
+/* --- MACHINE GENERATED, DO NOT EDIT --- */
+/* -------------------------------------- */
+#ifndef DIGIT
+#define DIGIT 1
+/*
+ * Digit Value Table --
+ *
+ *   The entries in the Digit Value Table map character
+ *   codes in the set {0-9,a-z,A-Z} to their numeric
+ *   values as part of numbers of radix 2-36.
+ *
+ */
+unsigned char digit_value[256] = {
+0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
+ 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
+ 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
+ 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
+ 0xFF,0x0A,0x0B,0x0C,0x0D,0x0E,0x0F,0x10,0x11,0x12,0x13,0x14,0x15,0x16,0x17,0x18,
+ 0x19,0x1A,0x1B,0x1C,0x1D,0x1E,0x1F,0x20,0x21,0x22,0x23,0xFF,0xFF,0xFF,0xFF,0xFF,
+ 0xFF,0x0A,0x0B,0x0C,0x0D,0x0E,0x0F,0x10,0x11,0x12,0x13,0x14,0x15,0x16,0x17,0x18,
+ 0x19,0x1A,0x1B,0x1C,0x1D,0x1E,0x1F,0x20,0x21,0x22,0x23,0xFF,0xFF,0xFF,0xFF,0xFF,
+ 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
+ 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
+ 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
+ 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
+ 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
+ 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
+ 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
+ 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF
+};
+#endif
diff --git a/Xserver/lib/font/Type1/fontfcn.c b/Xserver/lib/font/Type1/fontfcn.c
new file mode 100644 (file)
index 0000000..39fb510
--- /dev/null
@@ -0,0 +1,309 @@
+/* $XConsortium: fontfcn.c,v 1.10 94/02/06 16:07:23 gildea Exp $ */
+/* Copyright International Business Machines,Corp. 1991
+ * All Rights Reserved
+ *
+ * License to use, copy, modify, and distribute this software
+ * and its documentation for any purpose and without fee is
+ * hereby granted, provided that the above copyright notice
+ * appear in all copies and that both that copyright notice and
+ * this permission notice appear in supporting documentation,
+ * and that the name of IBM not be used in advertising or
+ * publicity pertaining to distribution of the software without
+ * specific, written prior permission.
+ *
+ * IBM PROVIDES THIS SOFTWARE "AS IS", WITHOUT ANY WARRANTIES
+ * OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING, BUT NOT
+ * LIMITED TO ANY IMPLIED WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, AND NONINFRINGEMENT OF
+ * THIRD PARTY RIGHTS.  THE ENTIRE RISK AS TO THE QUALITY AND
+ * PERFORMANCE OF THE SOFTWARE, INCLUDING ANY DUTY TO SUPPORT
+ * OR MAINTAIN, BELONGS TO THE LICENSEE.  SHOULD ANY PORTION OF
+ * THE SOFTWARE PROVE DEFECTIVE, THE LICENSEE (NOT IBM) ASSUMES
+ * THE ENTIRE COST OF ALL SERVICING, REPAIR AND CORRECTION.  IN
+ * NO EVENT SHALL IBM BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
+ * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
+ * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
+ * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+ */
+/* Author: Katherine A. Hitchcock    IBM Almaden Research Laboratory */
+#include <stdio.h>
+#include <string.h>
+#include "t1imager.h"
+#include "util.h"
+#include "fontfcn.h"
+#include "fontmisc.h"
+extern xobject Type1Char();
+/***================================================================***/
+/*   GLOBALS                                                          */
+/***================================================================***/
+char CurFontName[120];
+char *CurFontEnv;
+char *vm_base = NULL;
+psfont *FontP = NULL;
+psfont TheCurrentFont;
+/***================================================================***/
+/*   SearchDict - look for  name                                      */
+/*              - compare for match on len and string                 */
+/*                return 0 - not found.                               */
+/*                return n - nth element in dictionary.               */
+/***================================================================***/
+int SearchDictName(dictP,keyP)
+ psdict *dictP;
+ psobj  *keyP;
+{
+  int i,n;
+  n =  dictP[0].key.len;
+  for (i=1;i<=n;i++) {          /* scan the intire dictionary */
+    if (
+        (dictP[i].key.len  == keyP->len )
+        &&
+        (strncmp(dictP[i].key.data.valueP,
+                 keyP->data.valueP,
+                 keyP->len) == 0
+        )
+       ) return(i);
+  }
+  return(0);
+}
+/***================================================================***/
+boolean initFont(cnt)
+int cnt;
+{
+
+  if (!(vm_init(cnt))) return(FALSE);
+  vm_base = vm_next_byte();
+  if (!(Init_BuiltInEncoding())) return(FALSE);
+  strcpy(CurFontName, "");    /* iniitialize to none */
+  FontP = &TheCurrentFont;
+  FontP->vm_start = vm_next_byte();
+  FontP->FontFileName.len = 0;
+  FontP->FontFileName.data.valueP = CurFontName;
+  return(TRUE);
+}
+/***================================================================***/
+static void resetFont(env)
+    char *env;
+{
+  vm_next =  FontP->vm_start;
+  vm_free = vm_size - ( vm_next - vm_base);
+  FontP->Subrs.len = 0;
+  FontP->Subrs.data.stringP = NULL;
+  FontP->CharStringsP = NULL;
+  FontP->Private = NULL;
+  FontP->fontInfoP = NULL;
+  FontP->BluesP = NULL;
+  /* This will load the font into the FontP */
+  strcpy(CurFontName,env);
+  FontP->FontFileName.len = strlen(CurFontName);
+  FontP->FontFileName.data.valueP = CurFontName;
+}
+/***================================================================***/
+int readFont(env)
+char *env;
+{
+  int rcode;
+  /* restore the virtual memory and eliminate old font */
+  resetFont(env);
+  /* This will load the font into the FontP */
+  rcode = scan_font(FontP);
+  if (rcode == SCAN_OUT_OF_MEMORY) {
+    /* free the memory and start again */
+    xfree(vm_base);
+    if (!(initFont(vm_size * 2))) {
+      /* we are really out of memory */
+      return(SCAN_OUT_OF_MEMORY);
+      }
+    resetFont(env);
+    rcode = scan_font(FontP);
+    /* only double the memory once, then report error */
+  }
+  return(rcode);
+}
+/***================================================================***/
+xobject fontfcnB(S,code,lenP,mode)
+XYspace S;
+unsigned char *code;
+int  *lenP;
+int  *mode;
+{
+  path updateWidth();
+  psobj *charnameP; /* points to psobj that is name of character*/
+  int   N;
+  unsigned char *s;          /* used to search the name for '|' */
+  psdict *CharStringsDictP; /* dictionary with char strings     */
+  psobj   CodeName;   /* used to store the translation of the name*/
+  psobj  *SubrsArrayP;
+  psobj  *theStringP;
+  path  charpath;   /* the path for this character              */
+  charnameP = &CodeName;
+  charnameP->len = *lenP;
+  charnameP->data.stringP = code;
+
+  CharStringsDictP =  FontP->CharStringsP;
+  /* search the chars string for this charname as key */
+  N = SearchDictName(CharStringsDictP,charnameP);
+  if (N<=0) {
+    *mode = FF_PARSE_ERROR;
+    return(NULL);
+  }
+  /* ok, the nth item is the psobj that is the string for this char */
+  theStringP = &(CharStringsDictP[N].value);
+  /* get the dictionary pointers to the Subrs  */
+  SubrsArrayP = &(FontP->Subrs);
+  /* scale the Adobe fonts to 1 unit high */
+  /* call the type 1 routine to rasterize the character     */
+  charpath = Type1Char(FontP,S,theStringP,SubrsArrayP,NULL,
+               FontP->BluesP , mode);
+  /* if Type1Char reported an error, then return */
+  if ( *mode == FF_PARSE_ERROR)  return(NULL);
+  /* fill with winding rule unless path was requested */
+  if (*mode != FF_PATH) {
+    charpath =  Interior(charpath,WINDINGRULE+CONTINUITY);
+  }
+  return(charpath);
+}
+/***================================================================***/
+/*   fontfcnA(env, mode)                                              */
+/*                                                                    */
+/*          env is a pointer to a string that contains the fontname.  */
+/*                                                                    */
+/*     1) initialize the font     - global indicates it has been done */
+/*     2) load the font                                               */
+/***================================================================***/
+Bool fontfcnA(env,mode)
+char *env;
+int  *mode;
+{
+  int rc;
+  /* Has the FontP initialized?  If not, then   */
+  /* Initialize  */
+  if (FontP == NULL) {
+    InitImager();
+    if (!(initFont(VM_SIZE))) {
+      /* we are really out of memory */
+      *mode = SCAN_OUT_OF_MEMORY;
+      return(FALSE);
+    }
+  }
+  /* if the env is null, then use font already loaded */
+  /* if the not same font name */
+  if ( (env) && (strcmp(env,CurFontName) != 0 ) ) {
+    /* restore the virtual memory and eliminate old font, read new one */
+    rc = readFont(env);
+    if (rc != 0 ) {
+      strcpy(CurFontName, "");    /* no font loaded */
+      *mode = rc;
+      return(FALSE);
+    }
+  }
+  return(TRUE);
+}
+/***================================================================***/
+/*   QueryFontLib(env, infoName,infoValue,rcodeP)                     */
+/*                                                                    */
+/*          env is a pointer to a string that contains the fontname.  */
+/*                                                                    */
+/*     1) initialize the font     - global indicates it has been done */
+/*     2) load the font                                               */
+/*     3) use the font to call getInfo for that value.                */
+/***================================================================***/
+
+void QueryFontLib(env,infoName,infoValue,rcodeP)
+char *env;
+char *infoName;
+pointer infoValue;    /* parameter returned here    */
+int  *rcodeP;
+{
+  int rc,N,i;
+  psdict *dictP;
+  psobj  nameObj;
+  psobj  *valueP;
+  /* Has the FontP initialized?  If not, then   */
+  /* Initialize  */
+  if (FontP == NULL) {
+    InitImager();
+    if (!(initFont(VM_SIZE))) {
+      *rcodeP = 1;
+      return;
+    }
+  }
+  /* if the env is null, then use font already loaded */
+  /* if the not same font name, reset and load next font */
+  if ( (env) && (strcmp(env,CurFontName) != 0 ) ) {
+    /* restore the virtual memory and eliminate old font */
+    rc = readFont(env);
+    if (rc != 0 ) {
+      strcpy(CurFontName, "");    /* no font loaded */
+      *rcodeP = 1;
+      return;
+    }
+  }
+  dictP = FontP->fontInfoP;
+  objFormatName(&nameObj,strlen(infoName),infoName);
+  N = SearchDictName(dictP,&nameObj);
+  /* if found */
+  if ( N > 0 ) {
+    *rcodeP = 0;
+    switch (dictP[N].value.type) {
+       case OBJ_ARRAY:
+         valueP = dictP[N].value.data.arrayP;
+        /* Just double check valueP. H.J. */
+        if (valueP == NULL) break;
+         if (strcmp(infoName,"FontMatrix") == 0) {
+           /* 6 elments, return them as floats      */
+           for (i=0;i<6;i++) {
+             if (valueP->type == OBJ_INTEGER )
+               ((float *)infoValue)[i] = valueP->data.integer;
+             else
+               ((float *)infoValue)[i] = valueP->data.real;
+            valueP++;
+           }
+         }
+         if (strcmp(infoName,"FontBBox") == 0) {
+           /* 4 elments for Bounding Box.  all integers   */
+           for (i=0;i<4;i++) {
+             ((int *)infoValue)[i] = valueP->data.integer;
+             valueP++;
+           }
+         break;
+       case OBJ_INTEGER:
+       case OBJ_BOOLEAN:
+         *((int *)infoValue) = dictP[N].value.data.integer;
+         break;
+       case OBJ_REAL:
+         *((float *)infoValue) = dictP[N].value.data.real;
+         break;
+       case OBJ_NAME:
+       case OBJ_STRING:
+         *((char **)infoValue) =  dictP[N].value.data.valueP;
+         break;
+       default:
+         *rcodeP = 1;
+         break;
+     }
+   }
+  }
+  else *rcodeP = 1;
+}
diff --git a/Xserver/lib/font/Type1/fontfcn.h b/Xserver/lib/font/Type1/fontfcn.h
new file mode 100644 (file)
index 0000000..0c2fda1
--- /dev/null
@@ -0,0 +1,98 @@
+/* $XConsortium: fontfcn.h,v 1.3 92/03/26 16:42:23 eswu Exp $ */
+/* Copyright International Business Machines,Corp. 1991
+ * All Rights Reserved
+ *
+ * License to use, copy, modify, and distribute this software
+ * and its documentation for any purpose and without fee is
+ * hereby granted, provided that the above copyright notice
+ * appear in all copies and that both that copyright notice and
+ * this permission notice appear in supporting documentation,
+ * and that the name of IBM not be used in advertising or
+ * publicity pertaining to distribution of the software without
+ * specific, written prior permission.
+ *
+ * IBM PROVIDES THIS SOFTWARE "AS IS", WITHOUT ANY WARRANTIES
+ * OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING, BUT NOT
+ * LIMITED TO ANY IMPLIED WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, AND NONINFRINGEMENT OF
+ * THIRD PARTY RIGHTS.  THE ENTIRE RISK AS TO THE QUALITY AND
+ * PERFORMANCE OF THE SOFTWARE, INCLUDING ANY DUTY TO SUPPORT
+ * OR MAINTAIN, BELONGS TO THE LICENSEE.  SHOULD ANY PORTION OF
+ * THE SOFTWARE PROVE DEFECTIVE, THE LICENSEE (NOT IBM) ASSUMES
+ * THE ENTIRE COST OF ALL SERVICING, REPAIR AND CORRECTION.  IN
+ * NO EVENT SHALL IBM BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
+ * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
+ * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
+ * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+ */
+/*     Definition of a PostScript FONT             */
+typedef struct ps_font {
+            char    *vm_start;
+            psobj   FontFileName;
+            psobj   Subrs;
+            psdict  *CharStringsP;
+            psdict  *Private;
+            psdict  *fontInfoP;
+struct blues_struct *BluesP;
+} psfont;
+/***================================================================***/
+/*  Routines in scan_font                                             */
+/***================================================================***/
+extern boolean Init_StdEnc();
+extern int scan_font();
+extern int GetFontInfo();
+/***================================================================***/
+/*  Return codes from scan_font                                       */
+/***================================================================***/
+#define SCAN_OK               0
+#define SCAN_FILE_EOF        -1
+#define SCAN_ERROR           -2
+#define SCAN_OUT_OF_MEMORY   -3
+#define SCAN_FILE_OPEN_ERROR -4
+#define SCAN_TRUE            -5
+#define SCAN_FALSE           -6
+#define SCAN_END             -7
+/***================================================================***/
+/*  Name of FontInfo fields                                           */
+/***================================================================***/
+#define FONTNAME 1
+#define PAINTTYPE 2
+#define FONTTYPENUM 3
+#define FONTMATRIX 4
+#define FONTBBOX   5
+#define UNIQUEID  6
+#define STROKEWIDTH  7
+#define VERSION     8
+#define NOTICE     9
+#define FULLNAME 10
+#define FAMILYNAME 11
+#define WEIGHT 12
+#define ITALICANGLE 13
+#define ISFIXEDPITCH  14
+#define UNDERLINEPOSITION 15
+#define UNDERLINETHICKNESS 16
+#define ENCODING 17
+/***================================================================***/
+/*  Name of Private values                                            */
+/***================================================================***/
+#define BLUEVALUES 1
+#define OTHERBLUES 2
+#define FAMILYBLUES 3
+#define FAMILYOTHERBLUES 4
+#define BLUESCALE 5
+#define BLUESHIFT 6
+#define BLUEFUZZ  7
+#define STDHW     8
+#define STDVW     9
+#define STEMSNAPH 10
+#define STEMSNAPV 11
+#define FORCEBOLD 12
+#define LANGUAGEGROUP 13
+#define LENIV     14
+#define RNDSTEMUP 15
+#define EXPANSIONFACTOR 16
diff --git a/Xserver/lib/font/Type1/fonts.h b/Xserver/lib/font/Type1/fonts.h
new file mode 100644 (file)
index 0000000..619b5fd
--- /dev/null
@@ -0,0 +1,49 @@
+/* $XConsortium: fonts.h,v 1.3 94/04/17 20:17:19 rws Exp $ */
+/* Copyright International Business Machines,Corp. 1991
+ * All Rights Reserved
+ *
+ * License to use, copy, modify, and distribute this software
+ * and its documentation for any purpose and without fee is
+ * hereby granted, provided that the above copyright notice
+ * appear in all copies and that both that copyright notice and
+ * this permission notice appear in supporting documentation,
+ * and that the name of IBM not be used in advertising or
+ * publicity pertaining to distribution of the software without
+ * specific, written prior permission.
+ *
+ * IBM PROVIDES THIS SOFTWARE "AS IS", WITHOUT ANY WARRANTIES
+ * OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING, BUT NOT
+ * LIMITED TO ANY IMPLIED WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, AND NONINFRINGEMENT OF
+ * THIRD PARTY RIGHTS.  THE ENTIRE RISK AS TO THE QUALITY AND
+ * PERFORMANCE OF THE SOFTWARE, INCLUDING ANY DUTY TO SUPPORT
+ * OR MAINTAIN, BELONGS TO THE LICENSEE.  SHOULD ANY PORTION OF
+ * THE SOFTWARE PROVE DEFECTIVE, THE LICENSEE (NOT IBM) ASSUMES
+ * THE ENTIRE COST OF ALL SERVICING, REPAIR AND CORRECTION.  IN
+ * NO EVENT SHALL IBM BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
+ * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
+ * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
+ * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+ */
+
+/* STUB */
+#define   CopyFont(f)     f
+#define   UniqueFont(f)   f
+#define   KillFont(f)
+#define   KillText(t)
+#define   CopyText(t)     t
+#define   I_DumpText(t)
+#define   CoerceText(t)   t
+#define   TextDelta(t,pt)
+#define   XformText(p,s)
+#define   GimeSpace()     FALSE
+#define   LibInit()
+#define   InitFonts()
+#define   InitFiles()
+#define   TraceClose()
+#define   FF_PARSE_ERROR  -1
diff --git a/Xserver/lib/font/Type1/hdigit.h b/Xserver/lib/font/Type1/hdigit.h
new file mode 100644 (file)
index 0000000..adee64d
--- /dev/null
@@ -0,0 +1,94 @@
+/* $XConsortium: hdigit.h,v 1.2 91/10/10 11:18:11 rws Exp $ */
+/* Copyright International Business Machines,Corp. 1991
+ * All Rights Reserved
+ *
+ * License to use, copy, modify, and distribute this software
+ * and its documentation for any purpose and without fee is
+ * hereby granted, provided that the above copyright notice
+ * appear in all copies and that both that copyright notice and
+ * this permission notice appear in supporting documentation,
+ * and that the name of IBM not be used in advertising or
+ * publicity pertaining to distribution of the software without
+ * specific, written prior permission.
+ *
+ * IBM PROVIDES THIS SOFTWARE "AS IS", WITHOUT ANY WARRANTIES
+ * OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING, BUT NOT
+ * LIMITED TO ANY IMPLIED WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, AND NONINFRINGEMENT OF
+ * THIRD PARTY RIGHTS.  THE ENTIRE RISK AS TO THE QUALITY AND
+ * PERFORMANCE OF THE SOFTWARE, INCLUDING ANY DUTY TO SUPPORT
+ * OR MAINTAIN, BELONGS TO THE LICENSEE.  SHOULD ANY PORTION OF
+ * THE SOFTWARE PROVE DEFECTIVE, THE LICENSEE (NOT IBM) ASSUMES
+ * THE ENTIRE COST OF ALL SERVICING, REPAIR AND CORRECTION.  IN
+ * NO EVENT SHALL IBM BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
+ * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
+ * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
+ * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+ */
+/* -------------------------------------- */
+/* --- MACHINE GENERATED, DO NOT EDIT --- */
+/* -------------------------------------- */
+#ifndef HDIGIT
+#define HDIGIT 1
+/*
+ * Hex Digit Value Table --
+ *
+ *   The entries in the Digit Value Table map character codes in the set
+ *   {0-9,a-f,A-F} to their numeric values for readhexstring
+ *   (00 10...F0 for the high hex digit and 00 01...0F for the low).
+ *   The white-space and hex string termination characters are.
+ *   mapped to codes > 0xf0 to enable usage by several modules.
+ *   2 tables are build  HighHex and LowHex.
+ *
+ */
+/* Indicators for special characters in these tables */
+#define HERROR       (0xfe)
+#define HWHITE_SPACE (0xfd)
+#define HRIGHT_ANGLE (0xfc)
+#define LAST_HDIGIT  (0xf0)
+#define HighHexP (HighHex+1)
+unsigned char HighHex[257] = { 0xFF,
+ 0xFD,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFD,0xFD,0xFE,0xFE,0xFE,0xFE,0xFE,
+ 0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,
+ 0xFD,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,
+ 0x00,0x10,0x20,0x30,0x40,0x50,0x60,0x70,0x80,0x90,0xFE,0xFE,0xFE,0xFE,0xFC,0xFE,
+ 0xFE,0xA0,0xB0,0xC0,0xD0,0xE0,0xF0,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,
+ 0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,
+ 0xFE,0xA0,0xB0,0xC0,0xD0,0xE0,0xF0,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,
+ 0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,
+ 0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,
+ 0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,
+ 0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,
+ 0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,
+ 0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,
+ 0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,
+ 0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,
+ 0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE
+};
+#define LowHexP (LowHex+1)
+unsigned char LowHex[257] = { 0xFF,
+ 0xFD,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFD,0xFD,0xFE,0xFE,0xFE,0xFE,0xFE,
+ 0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,
+ 0xFD,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,
+ 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0xFE,0xFE,0xFE,0xFE,0xFC,0xFE,
+ 0xFE,0x0A,0x0B,0x0C,0x0D,0x0E,0x0F,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,
+ 0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,
+ 0xFE,0x0A,0x0B,0x0C,0x0D,0x0E,0x0F,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,
+ 0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,
+ 0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,
+ 0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,
+ 0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,
+ 0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,
+ 0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,
+ 0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,
+ 0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,
+ 0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE
+};
+#endif
diff --git a/Xserver/lib/font/Type1/hints.c b/Xserver/lib/font/Type1/hints.c
new file mode 100644 (file)
index 0000000..fe3499e
--- /dev/null
@@ -0,0 +1,919 @@
+/* $XConsortium: hints.c,v 1.4 91/10/10 11:18:13 rws Exp $ */
+/* Copyright International Business Machines, Corp. 1991
+ * All Rights Reserved
+ * Copyright Lexmark International, Inc. 1991
+ * All Rights Reserved
+ *
+ * License to use, copy, modify, and distribute this software and its
+ * documentation for any purpose and without fee is hereby granted,
+ * provided that the above copyright notice appear in all copies and that
+ * both that copyright notice and this permission notice appear in
+ * supporting documentation, and that the name of IBM or Lexmark not be
+ * used in advertising or publicity pertaining to distribution of the
+ * software without specific, written prior permission.
+ *
+ * IBM AND LEXMARK PROVIDE THIS SOFTWARE "AS IS", WITHOUT ANY WARRANTIES OF
+ * ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING, BUT NOT LIMITED TO ANY
+ * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE,
+ * AND NONINFRINGEMENT OF THIRD PARTY RIGHTS.  THE ENTIRE RISK AS TO THE
+ * QUALITY AND PERFORMANCE OF THE SOFTWARE, INCLUDING ANY DUTY TO SUPPORT
+ * OR MAINTAIN, BELONGS TO THE LICENSEE.  SHOULD ANY PORTION OF THE
+ * SOFTWARE PROVE DEFECTIVE, THE LICENSEE (NOT IBM OR LEXMARK) ASSUMES THE
+ * ENTIRE COST OF ALL SERVICING, REPAIR AND CORRECTION.  IN NO EVENT SHALL
+ * IBM OR LEXMARK BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
+ * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
+ * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
+ * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
+ * THIS SOFTWARE.
+ */
+ /* HINTS    CWEB         V0006 ********                             */
+/*
+:h1.HINTS Module - Processing Rasterization Hints
+&author. Sten F. Andler; continuity by Jeffrey B. Lotspiech (lotspiech@almaden.ibm.com) and Duaine
+W. Pryor, Jr.
+:h3.Include Files
+The included files are:
+*/
+#include "objects.h"
+#include "spaces.h"
+#include "paths.h"
+#include "regions.h"
+#include "hints.h"
+/*
+:h3.Functions Provided to the TYPE1IMAGER User
+None.
+*/
+/*
+:h3.Functions Provided to Other Modules
+This module provides the following entry point to other modules:
+*/
+/*SHARED LINE(S) ORIGINATED HERE*/
+/*
+:h3.Macros Provided to Other Modules
+None.
+*/
+/*
+:h2.InitHints() - Initialize hint data structure
+*/
+#define MAXLABEL 20
+static struct {
+  int inuse;
+  int computed;
+  struct fractpoint hint;
+} oldHint[MAXLABEL];
+#define ODD(x) (((int)(x)) & 01)
+#define FPFLOOR(fp) TOFRACTPEL((fp) >> FRACTBITS)
+#define FPROUND(fp) FPFLOOR((fp) + FPHALF)
+void InitHints()
+{
+  int i;
+  for (i = 0; i < MAXLABEL; i++)
+    {
+    oldHint[i].inuse    = FALSE;
+    oldHint[i].computed = FALSE;
+    }
+}
+/*
+:h3.CloseHints(hintP) - Reverse hints that are still open
+*/
+void CloseHints(hintP)
+  struct fractpoint *hintP;
+{
+  int i;
+  for (i = 0; i < MAXLABEL; i++)
+    {
+    if (oldHint[i].inuse)
+      {
+      hintP->x -= oldHint[i].hint.x;
+      hintP->y -= oldHint[i].hint.y;
+      oldHint[i].inuse = FALSE;
+      IfTrace3((HintDebug > 1),"  Hint %d was open, hint=(%p,%p)\n",
+                i, hintP->x, hintP->y);
+      }
+    }
+}
+/*
+:h3.ComputeHint(hP, currX, currY, hintP) - Compute the value of a hint
+*/
+static void ComputeHint(hP, currX, currY, hintP)
+  struct hintsegment *hP;
+  fractpel currX, currY;
+  struct fractpoint *hintP;
+{
+  fractpel currRef, currWidth;
+  int idealWidth;
+  fractpel hintValue;
+  char orientation;
+/*
+By construction, width is never zero.  Therefore we can use the
+width value to determine if the hint has been rotated by a
+multiple of 90 degrees.
+*/
+  if (hP->width.y == 0)
+    {
+    orientation = 'v';  /* vertical */
+    IfTrace0((HintDebug > 0),"  vertical hint\n");
+    }
+  else if (hP->width.x == 0)
+    {
+    orientation = 'h';  /* horizontal */
+    IfTrace0((HintDebug > 0),"  horizontal hint\n");
+    }
+  else
+    {
+    IfTrace0((HintDebug > 0),"  hint not vertical or horizontal\n");
+    hintP->x = hintP->y = 0;
+    return;
+    }
+  /* Compute currRef and currWidth with a unit of 1 pel */
+  if (orientation == 'v')      /* vertical */
+    {
+    currRef = hP->ref.x + currX;
+    currWidth = ABS(hP->width.x);
+    }
+  else if (orientation == 'h') /* horizontal */
+    {
+    currRef = hP->ref.y + currY;
+    currWidth = ABS(hP->width.y);
+    }
+  else                             /* error */
+    {
+    abort("ComputeHint: invalid orientation");
+    }
+  IfTrace4((HintDebug > 1),
+    "  currX=%p, currY=%p, currRef=%p, currWidth=%p\n",
+    currX, currY,
+    currRef, currWidth);
+  if ((hP->hinttype == 'b')      /* Bar or stem */
+    || (hP->hinttype == 's'))    /* Serif */
+    {
+    idealWidth = NEARESTPEL(currWidth);
+    if (idealWidth == 0) idealWidth = 1;
+    if (ODD(idealWidth))         /* Is ideal width odd? */
+      {
+      /* center "ref" over pel */
+      hintValue = FPFLOOR(currRef) + FPHALF - currRef;
+      }
+    else
+      {
+      /* align "ref" on pel boundary */
+      hintValue = FPROUND(currRef) - currRef;
+      }
+    if (HintDebug > 2) {
+          IfTrace1(TRUE,"  idealWidth=%d, ", idealWidth);
+      }
+    }
+  else if (hP->hinttype == 'c')  /* Curve extrema */
+    {
+    /* align "ref" on pel boundary */
+    hintValue = FPROUND(currRef) - currRef;
+    }
+  else                           /* error */
+    {
+    abort("ComputeHint: invalid hinttype");
+    }
+  IfTrace1((HintDebug > 1),"  hintValue=%p", hintValue);
+  if (orientation == 'v')      /* vertical */
+    {
+    hintP->x = hintValue;
+    hintP->y = 0;
+    }
+  else if (orientation == 'h') /* horizontal */
+    {
+    hintP->x = 0;
+    hintP->y = hintValue;
+    }
+  else                             /* error */
+    {
+    abort("ComputeHint: invalid orientation");
+    }
+}
+/*
+:h3.ProcessHint(hP, currX, currY, hintP) - Process a rasterization hint
+*/
+void ProcessHint(hP, currX, currY, hintP)
+  struct hintsegment *hP;
+  fractpel currX, currY;
+  struct fractpoint *hintP;
+{
+  struct fractpoint thisHint;
+  IfTrace4((HintDebug > 1),"  ref=(%p,%p), width=(%p,%p)",
+      hP->ref.x, hP->ref.y,
+      hP->width.x, hP->width.y);
+  IfTrace4((HintDebug > 1),", %c %c %c %c",
+      hP->orientation, hP->hinttype,
+      hP->adjusttype, hP->direction);
+  IfTrace1((HintDebug > 1),", label=%d\n", hP->label);
+  if ((hP->adjusttype == 'm')      /* Move */
+    || (hP->adjusttype == 'a'))    /* Adjust */
+    {
+    /* Look up hint in oldHint table */
+    if ((hP->label >= 0) && (hP->label < MAXLABEL))
+      {
+      if (oldHint[hP->label].computed)
+        /* Use old hint value if already computed */
+        {
+        thisHint.x = oldHint[hP->label].hint.x;
+        thisHint.y = oldHint[hP->label].hint.y;
+        oldHint[hP->label].inuse    = TRUE;
+        }
+      else
+        /* Compute new value for hint and store it for future use */
+        {
+        ComputeHint(hP, currX, currY, &thisHint);
+        oldHint[hP->label].hint.x = thisHint.x;
+        oldHint[hP->label].hint.y = thisHint.y;
+        oldHint[hP->label].inuse    = TRUE;
+        oldHint[hP->label].computed = TRUE;
+        }
+      }
+    else                             /* error */
+      {
+      abort("ProcessHint: invalid label");
+      }
+    }
+  else if (hP->adjusttype == 'r')  /* Reverse */
+    {
+    /* Use the inverse of the existing hint value to reverse hint */
+    if ((hP->label >= 0) && (hP->label < MAXLABEL))
+      {
+      if (oldHint[hP->label].inuse)
+        {
+        thisHint.x = -oldHint[hP->label].hint.x;
+        thisHint.y = -oldHint[hP->label].hint.y;
+        oldHint[hP->label].inuse = FALSE;
+        }
+      else                           /* error */
+        {
+        abort("ProcessHint: label is not in use");
+        }
+      }
+    else                           /* error */
+      {
+      abort("ProcessHint: invalid label");
+      }
+    }
+  else                           /* error */
+    {
+    abort("ProcessHint: invalid adjusttype");
+    }
+  IfTrace3((HintDebug > 1),"  label=%d, thisHint=(%p,%p)\n",
+    hP->label, thisHint.x, thisHint.y);
+  hintP->x += thisHint.x;
+  hintP->y += thisHint.y;
+  IfTrace2((HintDebug > 1),"  hint=(%p,%p)\n",
+    hintP->x, hintP->y);
+}
+/*
+:h2 id=subpath.Navigation Through Edge Lists
+For continuity checking purposes, we need to navigate through edge
+lists by the "subpath" chains and answer questions about edges.  The
+subpath chain links together edges that were part of the same subpath
+(no intervening move segments) when the interior of the path was
+calculated.  Here we use the term "edge" to mean every edge list
+that was created in between changes of direction.
+The subpath chains are singly-linked circular chains.  For the convenience
+of building them, they direction of the list (from edge to edge) is the
+reverse of the order in which they were built.  Within any single edge,
+the subpath chain goes from top-to-bottom.  (There might be a violation
+of this because of the way the user started the first chain; see
+:hdref refid=fixsubp..).
+:h3.ISTOP() and ISBOTTOM() - Flag Bits for Edge Lists at the Top and
+Bottom of Their SubPaths
+*/
+#define   ISTOP(flag)     ((flag)&0x20)
+#define   ISBOTTOM(flag)  ((flag)&0x10)
+/*
+:h3.ISLEFT() - Flag Bit for Left Edges
+*/
+#define   ISLEFT(flag)    ((flag)&0x08)
+/*
+:h3.XofY() - Macro to Find X Value at Given Y
+This macro can only be used if it is known that the Y is within the
+given edgelist's ymin and ymax.
+*/
+#define   XofY(edge, y)   edge->xvalues[y - edge->ymin]
+/*
+:h3.findXofY() - Like XofY(), Except not Restricted
+If the Y is out of bounds of the given edgelist, this macro will
+call SearchXofY to search the edge's subpath chain for the correct
+Y range.  If the Y value is off the edge, MINPEL is returned.
+*/
+#define   findXofY(edge, y)  ((y < edge->ymin || y >= edge->ymax) ? SearchXofY(edge, y) : XofY(edge, y))
+/*
+:h4.SearchXofY() - Routine Called by FindXofY() for Difficult Cases
+The concept of this routine is to follow the subpath chain to find the
+edge just below (i.e., next in chain) or just above (i.e., immediately
+before in chain.  It is assumed that the Y value is no more than one
+off of the edge's range; XofY() could be replace by FindXofY() to
+call ourselves recursively if this were not true.
+*/
+static pel SearchXofY(edge, y)
+       register struct edgelist *edge;  /* represents edge                   */
+       register pel y;       /* 'y' value to find edge for                   */
+{
+       register struct edgelist *e;  /* loop variable                        */
+       if (y < edge->ymin) {
+               if (ISTOP(edge->flag))
+                       return(MINPEL);
+               for (e = edge->subpath; e->subpath != edge; e = e->subpath) { ; }
+               if (e->ymax == edge->ymin)
+                        return(XofY(e, y));
+       }
+       else if (y >= edge->ymax) {
+               if (ISBOTTOM(edge->flag))
+                       return(MINPEL);
+               e = edge->subpath;
+               if (e->ymin == edge->ymax)
+                         return(XofY(e, y));
+       }
+       else
+               return(XofY(edge, y));
+       abort("bad subpath chain");
+       /*NOTREACHED*/
+}
+/*
+:h3.ISBREAK() Macro - Tests if an Edge List is at a "Break"
+The subpath chains are organized top to bottom.  When the bottom of
+a given edge is reached, the subpath chain points to the top of the
+next edge.  We call this a "break" in the chain.  The following macro
+is the simple test for the break condition:
+*/
+#define  ISBREAK(top,bot) (top->ymax != bot->ymin)
+/*
+:h3.ImpliedHorizontalLine() - Tests for Horizontal Connectivity
+This function returns true if two edges are connected horizontally.
+They are connected horizontally if they are consecutive in the subpath,
+and either we are at the bottom and the first edge is going down or we
+are at the top and the first edge is going up.
+*/
+#define  BLACKABOVE  -1
+#define  BLACKBELOW  +1
+#define  NONE         0
+static int ImpliedHorizontalLine(e1, e2, y)
+       register struct edgelist *e1,*e2;  /* two edges to check              */
+       register int y;       /* y where they might be connected              */
+{
+       register struct edgelist *e3,*e4;
+       if (ISDOWN(e1->flag) == ISDOWN(e2->flag))
+               return(NONE);  /* can't be consecutive unless different directions */
+/*
+Now we check for consecutiveness:  Can we get from 'e1' to 'e2' with
+only one intervening break?  Can we get from 'e2' to 'e1' with only one
+intervening break?  'e3' will be as far as we can get after 'e1'; 'e4'
+will be has far as we can get after 'e2':
+*/
+       for (e3 = e1; !ISBREAK(e3, e3->subpath); e3 = e3->subpath) { ; }
+       for (e3 = e3->subpath; e3 != e2; e3 = e3->subpath)
+               if (ISBREAK(e3, e3->subpath))
+                       break;
+       for (e4 = e2; !ISBREAK(e4, e4->subpath); e4 = e4->subpath) { ; }
+       for (e4 = e4->subpath; e4 != e1; e4 = e4->subpath)
+               if (ISBREAK(e4, e4->subpath))
+                       break;
+/*
+If the edges are mutually consecutive, we must have horizontal lines
+both top and bottom:
+*/
+       if (e3 == e2 && e4 == e1)
+               return(TRUE);
+/*
+If the edges are not consecutive either way, no horizontal lines are
+possible:
+*/
+       if (e3 != e2 && e4 != e1)
+               return(NONE);
+/*
+Now let's swap 'e1' and 'e2' if necessary to enforce the rule that 'e2'
+follows 'e1'.  Remember that subpath chains go in the opposite direction
+from the way the subpaths were built; this led to the simplest way
+do build them.
+*/
+       if (e4 != e1) {
+               e2 = e1;
+               e1 = e3;  /* remember e3 == e2, this just swaps 'e1' and 'e2' */
+       }
+/*
+Now we have everything to return the answer:
+*/
+       if (ISTOP(e1->flag) && y == e1->ymin)
+               return(ISDOWN(e2->flag));
+       else if (ISBOTTOM(e1->flag) && y == e1->ymax)
+               return(!ISDOWN(e2->flag));
+       else
+               abort("ImpliedHorizontalLine:  why ask?");
+       /*NOTREACHED*/
+}
+/*
+:h3 id=fixsubp.FixSubPaths() - Must be Called to Organize Subpath Chains
+The region-building code in Interior(), in particular splitedge(),
+maintains the rule that sub-paths are linked top-to-bottom except
+at breaks.  However, it is possible that there may be a "false break"
+because the user started the subpath in the middle of an edge (and
+went in the "wrong" direction from there, up instead of down).  This
+routine finds and fixes false breaks.
+Also, this routine sets the ISTOP and ISBOTTOM flags in the edge lists.
+*/
+static void FixSubPaths(R)
+       register struct region *R;       /* anchor of region                */
+{
+       register struct edgelist *e;     /* fast loop variable                */
+       register struct edgelist *edge;  /* current edge in region            */
+       register struct edgelist *next;  /* next in subpath after 'edge'      */
+       register struct edgelist *break1;  /* first break after 'next'        */
+       register struct edgelist *break2;  /* last break before 'edge'        */
+       register struct edgelist *prev;    /* previous edge for fixing links  */
+       int left = TRUE;
+       for (edge = R->anchor; edge != NULL; edge = edge->link) {
+               if (left)
+                       edge->flag |= ISLEFT(ON);
+               left = !left;
+               next = edge->subpath;
+               if (!ISBREAK(edge, next))
+                       continue;
+               if (edge->ymax < next->ymin)
+                       abort("disjoint subpath?");
+/*
+'edge' now contains an edgelist at the bottom of an edge, and 'next'
+contains the next subsequent edgelist in the subpath, which must be at
+the top.  We refer to this a "break" in the subpath.
+*/
+               next->flag |= ISTOP(ON);
+               edge->flag |= ISBOTTOM(ON);
+               if (ISDOWN(edge->flag) != ISDOWN(next->flag))
+                       continue;
+/*
+We are now in the unusual case; both edges are going in the same
+direction so this must be a "false break" due to the way that the user
+created the path.  We'll have to fix it.
+*/
+               for (break1 = next; !ISBREAK(break1, break1->subpath); break1 = break1->subpath) { ; }
+               for (e = break1->subpath; e != edge; e = e->subpath)
+                       if (ISBREAK(e, e->subpath))
+                               break2 = e;
+/*
+Now we've set up 'break1' and 'break2'.  I've found the following
+diagram invaluable.  'break1' is the first break after 'next'.  'break2'
+is the LAST break before 'edge'.
+&drawing.
+         next
+        +------+     +---->+------+
+   +--->|    >-----+ |     |    >-----+
+   |    |      |   | |     |      |   |
+   | +-------------+ |  +-------------+
+   | |  |break1|     |  |  |      |
+   | +->|    >-------+  +->|    >-----+
+   |    |      |           |      |   |
+   |    |      |        +-------------+
+   |    +------+        |  |      |
+   | +----------------+ |  |      |
+   | |  +------+      | +->|    >-----+
+   | +->|    >-----+  |    |      |   |
+   |    |      |   |  | +-------------+
+   | +-------------+  | |  |      |
+   | |  |edge  |      | |  |break2|
+   | +->|    >-----+  | +->|    >-----+
+   |    |      |   |  |    |      |   |
+   |    |      |   |  |    |      |   |
+   |    |      |   |  |    |      |   |
+   |    +------+   |  |    +------+   |
+   |               |  |               |
+   +---------------+  +---------------+
+&edrawing.
+We want to fix this situation by having 'edge' point to where 'break1'
+now points, and having 'break1' point to where 'break2' now points.
+Finally, 'break2' should point to 'next'.  Also, we observe that
+'break1' can't be a bottom, and is also not a top unless it is the same
+as 'next':
+*/
+               edge->subpath = break1->subpath;
+               break1->subpath = break2->subpath;
+               if (ISBREAK(break1, break1->subpath))
+                       abort("unable to fix subpath break?");
+               break2->subpath = next;
+               break1->flag &= ~ISBOTTOM(ON);
+               if (break1 != next)
+                       break1->flag &= ~ISTOP(ON);
+       }
+/*
+This region might contain "ambiguous" edges; edges exactly equal to
+edge->link.  Due to the random dynamics of where they get sorted into
+the list, they can yield false crossings, where the edges appear
+to cross.  This confuses our continuity logic no end.  Since we can
+swap them without changing the region, we do.
+*/
+       for (edge = R->anchor, prev = NULL; VALIDEDGE(edge); prev = edge, edge = prev->link) {
+               if (! ISAMBIGUOUS(edge->flag))
+                       continue;
+               next = edge->subpath;
+               while (ISAMBIGUOUS(next->flag) && next != edge)
+                       next = next->subpath;
+/*
+We've finally found a non-ambiguous edge; we make sure it is left/right
+compatible with 'edge':
+*/
+               if ( (ISLEFT(edge->flag) == ISLEFT(next->flag) && ISDOWN(edge->flag) == ISDOWN(next->flag) )
+                    || (ISLEFT(edge->flag) != ISLEFT(next->flag) && ISDOWN(edge->flag) != ISDOWN(next->flag) ) )
+                       continue;
+/*
+Incompatible, we will swap 'edge' and the following edge in the list.
+You may think that there must be a next edge in this swath.  So did I.
+No!  If there is a totally ambiguous inner loop, for example, we could
+get all the way to the outside without resolving ambiguity.
+*/
+               next = edge->link;  /* note new meaning of 'next' */
+               if (next == NULL || edge->ymin != next->ymin)
+                       continue;
+               if (prev == NULL)
+                       R->anchor = next;
+               else
+                       prev->link = next;
+               edge->link = next->link;
+               next->link = edge;
+               edge->flag ^= ISLEFT(ON);
+               edge->flag &= ~ISAMBIGUOUS(ON);
+               next->flag ^= ISLEFT(ON);
+               next->flag &= ~ISAMBIGUOUS(ON);
+               edge = next;
+       }
+}
+/*
+:h3.DumpSubPaths()
+A debug tool.
+*/
+static struct edgelist *before();  /* subroutine of DumpSubPaths             */
+static void DumpSubPaths(anchor)
+       struct edgelist *anchor;
+{
+       register struct edgelist *edge,*e,*e2;
+       pel y;
+       for (edge = anchor; VALIDEDGE(edge); edge = edge->link) {
+               if (ISPERMANENT(edge->flag))
+                       continue;
+               IfTrace0(TRUE, "BEGIN Subpath\n");
+               for (e2 = edge; !ISPERMANENT(e2->flag);) {
+                       if (ISDOWN(e2->flag)) {
+                               IfTrace1(TRUE, ". Downgoing edge's top at %x\n", e2);
+                               for (e = e2;; e = e->subpath) {
+                                       IfTrace4(TRUE, ". . [%5d] %5d    @ %x[%x]\n",
+                                                e->ymin, *e->xvalues, e, e->flag);
+                                       for (y=e->ymin+1; y < e->ymax; y++)
+                                               IfTrace2(TRUE, ". . [%5d] %5d     \"\n", y, e->xvalues[y-e->ymin]);
+                                       e->flag |= ISPERMANENT(ON);
+                                       if (ISBREAK(e, e->subpath))
+                                               break;
+                               }
+                       }
+                       else {
+                               IfTrace1(TRUE, ". Upgoing edge's top at %x\n", e2);
+                               for (e = e2; !ISBREAK(e, e->subpath); e = e->subpath) { ; }
+                               for (;; e=before(e)) {
+                                       IfTrace4(TRUE, ". . [%5d] %5d    @ %x[%x]\n",
+                                                e->ymax-1, e->xvalues[e->ymax-1-e->ymin], e, e->flag);
+                                       for (y=e->ymax-2; y >= e->ymin; y--)
+                                               IfTrace2(TRUE, ". . [%5d] %5d      \"\n", y, e->xvalues[y-e->ymin]);
+                                       e->flag |= ISPERMANENT(ON);
+                                       if (e == e2)
+                                               break;
+                               }
+                       }
+                       do {
+                               e2 = before(e2);
+                       } while (!ISBREAK(before(e2), e2));
+               }
+       }
+}
+static struct edgelist *before(e)
+       struct edgelist *e;
+{
+       struct edgelist *r;
+       for (r = e->subpath; r->subpath != e; r = r->subpath) { ; }
+       return(r);
+}
+/*
+:h2.Fixing Region Continuity Problems
+Small regions may become disconnected when their connecting segments are
+less than a pel wide.  This may be correct in some applications, but in
+many (especially small font characters), it is more pleasing to keep
+connectivity.  ApplyContinuity() (invoked by +CONTINUITY on the
+Interior() fill rule) fixes connection breaks.  The resulting region
+is geometrically less accurate, but may be more pleasing to the eye.
+*/
+/*
+Here are some macros which we will need:
+*/
+#define IsValidPel(j) (j!=MINPEL)
+/*
+:h3.writeXofY() - Stuffs an X Value Into an "edgelist"
+writeXofY writes an x value into an edge at position 'y'.  It must
+update the edge's xmin and xmax.  If there is a possibility that this
+new x might exceed the region's bounds, updating those are the
+responsibility of the caller.
+*/
+static void writeXofY(e, y, x)
+       struct edgelist *e;   /* relevant edgelist                            */
+       int y;                /* y value                                      */
+       int x;                /* new x value                                  */
+{
+       if (e->xmin > x)  e->xmin = x;
+       if (e->xmax < x)  e->xmax = x;
+       e->xvalues[y - e->ymin] = x;
+}
+/*-------------------------------------------------------------------------*/
+/* the following three macros tell us whether we are at a birth point, a    */
+/* death point, or simply in the middle of the character                */
+/*-------------------------------------------------------------------------*/
+#define WeAreAtTop(e,i) (ISTOP(e->flag) && e->ymin == i)
+#define WeAreAtBottom(e,i) (ISBOTTOM(e->flag) && e->ymax-1 == i)
+#define WeAreInMiddle(e,i) \
+      ((!ISTOP(e->flag) && !ISBOTTOM(e->flag))||(i < e->ymax-1 && i > e->ymin))
+/*
+The following macro tests if two "edgelist" structures are in the same
+swath:
+*/
+#define SAMESWATH(e1,e2)  (e1->ymin == e2->ymin)
+/*
+:h3.CollapseWhiteRun() - Subroutine of ApplyContinuity()
+When we have a white run with an implied horizontal line above or
+below it, we better have black on the other side of this line.  This
+function both tests to see if black is there, and adjusts the end
+points (collapses) the white run as necessary if it is not.  The
+goal is to collapse the white run as little as possible.
+*/
+static void CollapseWhiteRun(anchor, yblack, left, right, ywhite)
+        struct edgelist *anchor;  /* anchor of edge list                     */
+        pel yblack;          /* y of (hopefully) black run above or below    */
+        struct edgelist *left;  /* edgelist at left of WHITE run             */
+        struct edgelist *right;  /* edgelist at right of WHITE run           */
+        pel ywhite;          /* y location of white run                      */
+{
+       struct edgelist *edge;
+       struct edgelist *swathstart = anchor;
+       register pel x;
+       if (XofY(left, ywhite) >= XofY(right, ywhite))
+               return;
+/*
+Find the swath with 'yblack'.  If we don't find it, completely collapse
+the white run and return:
+*/
+       while (VALIDEDGE(swathstart)) {
+               if (yblack < swathstart->ymin)  {
+                      writeXofY(left, ywhite, XofY(right, ywhite));
+                      return;
+               }
+               if (yblack < swathstart->ymax) break;
+               swathstart = swathstart->link->link;
+       }
+       if(!VALIDEDGE(swathstart)) {
+               writeXofY(left, ywhite, XofY(right, ywhite));
+               return;
+       }
+/*
+Now we are in the swath that contains 'y', the reference line above
+or below that we are trying to maintain continuity with.  If black
+in this line begins in the middle of our white run, we must collapse
+the white run from the left to that point.  If black ends in the
+middle of our white run, we must collapse the white run from the right
+to that point.
+*/
+       for (edge = swathstart; VALIDEDGE(edge); edge = edge->link) {
+               if (!SAMESWATH(swathstart,edge))
+                       break;
+               if( XofY(edge, yblack) > XofY(left, ywhite)) {
+                       if (ISLEFT(edge->flag)) {
+                                x = XofY(edge, yblack);
+                                if (XofY(right, ywhite) < x)
+                                       x = XofY(right, ywhite);
+                                writeXofY(left, ywhite, x);
+                       }
+                       else {
+                                x = XofY(edge, yblack);
+                                while (edge->link != NULL && SAMESWATH(edge, edge->link)
+                                       && x >= XofY(edge->link, yblack) ) {
+                                       edge = edge->link->link;
+                                       x = XofY(edge, yblack);
+                                }
+                                if (x < XofY(right, ywhite))
+                                       writeXofY(right, ywhite, x);
+                                return;
+                       }
+               }
+       }
+       writeXofY(left, ywhite, XofY(right, ywhite));
+}
+/*
+:h3.ApplyContinuity() - Fix False Breaks in a Region
+This is the externally visible routine called from the REGIONS module
+when the +CONTINUITY flag is on the Interior() fill rule.
+*/
+void ApplyContinuity(R)
+struct region *R;
+{
+ struct edgelist *left;
+ struct edgelist *right;
+ struct edgelist *edge,*e2;
+ pel rightXabove,rightXbelow,leftXabove,leftXbelow;
+ pel leftX,rightX;
+ int i;
+ long newcenter,abovecenter,belowcenter;
+ FixSubPaths(R);
+ if (RegionDebug >= 3)
+        DumpSubPaths(R->anchor);
+ left = R->anchor;
+/* loop through and do all of the easy checking. ( no tops or bottoms) */
+ while(VALIDEDGE(left))
+ {
+  right = left->link;
+  for(i=left->ymin;i<left->ymax;++i)
+  {
+   leftX       = findXofY(left,i);
+   rightX      = findXofY(right,i);
+   leftXbelow  = findXofY(left,i+1);
+   rightXbelow = findXofY(right,i+1);
+   if(rightX <= leftX)
+   {
+/* then, we have a break in a near vertical line */
+     leftXabove  = findXofY(left,i-1);
+     rightXabove = findXofY(right,i-1);
+     if( IsValidPel(leftXabove) && IsValidPel(rightXabove) )
+     {
+      abovecenter = leftXabove + rightXabove;
+     }
+     else
+     {
+      abovecenter = leftX + rightX;
+     }
+     if( IsValidPel(leftXbelow) && IsValidPel(rightXbelow) )
+     {
+      belowcenter = leftXbelow + rightXbelow;
+     }
+     else
+     {
+      belowcenter = leftX + rightX;
+     }
+     newcenter = abovecenter + belowcenter;
+     if( newcenter > 4*leftX )
+     {
+      rightX = rightX + 1;
+     }
+     else if( newcenter < 4*leftX)
+     {
+      leftX = leftX - 1;
+     }
+     else
+     {
+      rightX = rightX + 1;
+     }
+     writeXofY(right,i,rightX);
+     writeXofY(left,i,leftX);
+     if(rightX > R->xmax) {R->xmax = rightX;}
+     if(leftX < R->xmin) {R->xmin = leftX;}
+   }
+   if( !WeAreAtBottom(left,i) && (leftXbelow>=rightX))
+   {
+/* then we have a break in a near horizontal line in the middle */
+    writeXofY(right,i,leftXbelow);
+   }
+   if( !WeAreAtBottom(right,i) && (leftX >=rightXbelow))
+   {
+/* then we have a break in a near horizontal line in the middle */
+    writeXofY(left,i,rightXbelow);
+   }
+  }
+  left = right->link;
+ }
+/*
+There may be "implied horizontal lines" between edges that have
+implications for continuity.  This loop looks for white runs that
+have implied horizontal lines on the top or bottom, and calls
+CollapseWhiteRuns to check and fix any continuity problems from
+them.
+*/
+      for (edge = R->anchor; VALIDEDGE(edge); edge = edge->link) {
+              if ((!ISTOP(edge->flag) && !ISBOTTOM(edge->flag)) || ISLEFT(edge->flag))
+                      continue;  /* at some future date we may want left edge logic here too */
+              for (e2 = edge->link; VALIDEDGE(e2) && SAMESWATH(edge,e2); e2 = e2->link) {
+                      if (ISTOP(e2->flag) && ISTOP(edge->flag)
+                          && NONE != ImpliedHorizontalLine(edge,e2,edge->ymin)) {
+                              if (ISLEFT(e2->flag))
+                                      CollapseWhiteRun(R->anchor, edge->ymin-1,
+                                                       edge, e2, edge->ymin);
+                      }
+                      if (ISBOTTOM(e2->flag) && ISBOTTOM(edge->flag)
+                          && NONE != ImpliedHorizontalLine(edge,e2, edge->ymax)) {
+                              if (ISLEFT(e2->flag))
+                                      CollapseWhiteRun(R->anchor, edge->ymax,
+                                                       edge, e2, edge->ymax-1);
+                      }
+              }
+      }
+}
diff --git a/Xserver/lib/font/Type1/hints.h b/Xserver/lib/font/Type1/hints.h
new file mode 100644 (file)
index 0000000..79a96b4
--- /dev/null
@@ -0,0 +1,42 @@
+/* $XConsortium: hints.h,v 1.2 91/10/10 11:18:19 rws Exp $ */
+/* Copyright International Business Machines, Corp. 1991
+ * All Rights Reserved
+ * Copyright Lexmark International, Inc. 1991
+ * All Rights Reserved
+ *
+ * License to use, copy, modify, and distribute this software and its
+ * documentation for any purpose and without fee is hereby granted,
+ * provided that the above copyright notice appear in all copies and that
+ * both that copyright notice and this permission notice appear in
+ * supporting documentation, and that the name of IBM or Lexmark not be
+ * used in advertising or publicity pertaining to distribution of the
+ * software without specific, written prior permission.
+ *
+ * IBM AND LEXMARK PROVIDE THIS SOFTWARE "AS IS", WITHOUT ANY WARRANTIES OF
+ * ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING, BUT NOT LIMITED TO ANY
+ * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE,
+ * AND NONINFRINGEMENT OF THIRD PARTY RIGHTS.  THE ENTIRE RISK AS TO THE
+ * QUALITY AND PERFORMANCE OF THE SOFTWARE, INCLUDING ANY DUTY TO SUPPORT
+ * OR MAINTAIN, BELONGS TO THE LICENSEE.  SHOULD ANY PORTION OF THE
+ * SOFTWARE PROVE DEFECTIVE, THE LICENSEE (NOT IBM OR LEXMARK) ASSUMES THE
+ * ENTIRE COST OF ALL SERVICING, REPAIR AND CORRECTION.  IN NO EVENT SHALL
+ * IBM OR LEXMARK BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
+ * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
+ * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
+ * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
+ * THIS SOFTWARE.
+ */
+/*SHARED*/
+#define   InitHints()   t1_InitHints()
+void t1_InitHints();   /* Initialize hint data structure */
+#define   CloseHints(hintP)   t1_CloseHints(hintP)
+void t1_CloseHints();   /* Reverse hints that are still open */
+#define   ProcessHint(hP, currX, currY, hintP)   t1_ProcessHint(hP, currX, currY, hintP)
+void t1_ProcessHint();   /* Process a rasterization hint */
+#define   ApplyContinuity(R)  t1_ApplyContinuity(R)
+void t1_ApplyContinuity();    /* fix false connection breaks in a region      */
+/*END SHARED*/
diff --git a/Xserver/lib/font/Type1/lines.c b/Xserver/lib/font/Type1/lines.c
new file mode 100644 (file)
index 0000000..ebbad56
--- /dev/null
@@ -0,0 +1,186 @@
+/* $XConsortium: lines.c,v 1.2 91/10/10 11:18:21 rws Exp $ */
+/* Copyright International Business Machines, Corp. 1991
+ * All Rights Reserved
+ * Copyright Lexmark International, Inc. 1991
+ * All Rights Reserved
+ *
+ * License to use, copy, modify, and distribute this software and its
+ * documentation for any purpose and without fee is hereby granted,
+ * provided that the above copyright notice appear in all copies and that
+ * both that copyright notice and this permission notice appear in
+ * supporting documentation, and that the name of IBM or Lexmark not be
+ * used in advertising or publicity pertaining to distribution of the
+ * software without specific, written prior permission.
+ *
+ * IBM AND LEXMARK PROVIDE THIS SOFTWARE "AS IS", WITHOUT ANY WARRANTIES OF
+ * ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING, BUT NOT LIMITED TO ANY
+ * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE,
+ * AND NONINFRINGEMENT OF THIRD PARTY RIGHTS.  THE ENTIRE RISK AS TO THE
+ * QUALITY AND PERFORMANCE OF THE SOFTWARE, INCLUDING ANY DUTY TO SUPPORT
+ * OR MAINTAIN, BELONGS TO THE LICENSEE.  SHOULD ANY PORTION OF THE
+ * SOFTWARE PROVE DEFECTIVE, THE LICENSEE (NOT IBM OR LEXMARK) ASSUMES THE
+ * ENTIRE COST OF ALL SERVICING, REPAIR AND CORRECTION.  IN NO EVENT SHALL
+ * IBM OR LEXMARK BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
+ * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
+ * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
+ * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
+ * THIS SOFTWARE.
+ */
+ /* LINES    CWEB         V0003 ********                             */
+/*
+:h1.LINES Module - Rasterizing Lines
+&author. Duaine W. Pryor, Jr. and Jeffrey B. Lotspiech (lotspiech@almaden.ibm.com)
+:h3.Include Files
+The included files are:
+*/
+#include "objects.h"
+#include "spaces.h"
+#include "regions.h"
+#include "lines.h"
+/*
+:h3.Functions Provided to the TYPE1IMAGER User
+None.
+*/
+/*
+:h3.Functions Provided to Other Modules
+This module provides the following entry point to other modules:
+*/
+/*SHARED LINE(S) ORIGINATED HERE*/
+/*
+:h3.Macros Provided to Other Modules
+None.
+*/
+/*
+:h2.StepLine() - Produces Run Ends for a Line After Checks
+The main work is done by Bresenham(); here we just perform checks and
+get the line so that its Y direction is always increasing:
+*/
+void StepLine(R, x1, y1, x2, y2)
+       register struct region *R;  /* region being built                     */
+       register fractpel x1,y1;  /* starting point                           */
+       register fractpel x2,y2;  /* ending point                             */
+{
+       register fractpel dy;
+       IfTrace4((LineDebug > 0), ".....StepLine: (%p,%p) to (%p,%p)\n",
+                                            x1, y1, x2, y2);
+       dy = y2 - y1;
+/*
+We execute the "GOING_TO" macro to call back the REGIONS module, if
+necessary (like if the Y direction of the edge has changed):
+*/
+       GOING_TO(R, x1, y1, x2, y2, dy);
+       if (dy == 0)
+               return;
+       if (dy < 0)
+               Bresenham(R->edge, x2, y2, x1, y1);
+       else
+               Bresenham(R->edge, x1, y1, x2, y2);
+       return;
+}
+/*
+:h3.Bresenham() - Actually Produces Run Ends
+This routine runs a Bresenham line-stepping
+algorithm.  See, for example, Newman and Sproul, :hp1/Principles
+of Interactive Computer Graphics/, pp. 25-27.
+When we enter this, we
+are guaranteed that dy is positive.
+We'd like to work in 8 bit precision, so we'll define some macros and
+constants to let us do that:
+*/
+#define PREC 8               /* we'll keep fraction pels in 8 bit precision  */
+/*
+RoundFP() rounds down by 'b' bits:
+*/
+#define  RoundFP(xy,b)   (((xy)+(1<<((b)-1)))>>(b))
+/*
+TruncFP() truncates down by 'b' bits:
+*/
+#define  TruncFP(xy,b)   ((xy)>>(b))
+void Bresenham(edgeP,x1,y1,x2,y2)
+       register pel *edgeP;               /* pointer to top of list (y == 0) */
+       register fractpel x1,y1;           /* starting point on line          */
+       register fractpel x2,y2;           /* ending point on the line (down) */
+{
+       register long dx,dy;  /* change in x and y, in my own precision       */
+       register long x,y;    /* integer pel starting point                   */
+       register int count;   /* integer pel delta y                          */
+       register long d;      /* the Bresenham algorithm error term           */
+       x1 = TruncFP(x1, FRACTBITS-PREC);
+       y1 = TruncFP(y1, FRACTBITS-PREC);
+       x2 = TruncFP(x2, FRACTBITS-PREC);
+       y2 = TruncFP(y2, FRACTBITS-PREC);
+       dx = x2 - x1;
+       dy = y2 - y1;
+/*
+Find the starting x and y integer pel coordinates:
+*/
+ x = RoundFP(x1,PREC);
+ y = RoundFP(y1,PREC);
+ edgeP += y;
+ count = RoundFP(y2,PREC) - y;
+/*------------------------------------------------------------------*/
+/* Force dx to be positive so that dfy will be negative             */
+/*       this means that vertical moves will decrease d             */
+/*------------------------------------------------------------------*/
+ if (dx<0)
+ {
+  dx = -dx;
+#define P PREC
+  d=(dy*(x1-(x<<P)+(1<<(P-1)))-dx*((y<<P)-y1+(1<<(P-1))))>>P;
+#undef P
+  while(--count >= 0 )
+  {
+   while(d<0)
+   {
+    --x;
+    d += dy;
+   }
+   *(edgeP++) = x;
+   d -= dx;
+  }
+ }
+ else  /* positive dx */
+ {
+#define P PREC
+  d = (dy*((x<<P)-x1+(1<<(P-1)))-dx*((y<<P)-y1+(1<<(P-1))))>>P;
+#undef P
+  while(--count >= 0 )
+  {
+   while(d<0)
+   {
+    ++x;
+    d += dy;
+   }
+   *(edgeP++) = x;
+   d -= dx;
+  }
+ }
+}
diff --git a/Xserver/lib/font/Type1/lines.h b/Xserver/lib/font/Type1/lines.h
new file mode 100644 (file)
index 0000000..44b0da1
--- /dev/null
@@ -0,0 +1,37 @@
+/* $XConsortium: lines.h,v 1.2 91/10/10 11:18:23 rws Exp $ */
+/* Copyright International Business Machines, Corp. 1991
+ * All Rights Reserved
+ * Copyright Lexmark International, Inc. 1991
+ * All Rights Reserved
+ *
+ * License to use, copy, modify, and distribute this software and its
+ * documentation for any purpose and without fee is hereby granted,
+ * provided that the above copyright notice appear in all copies and that
+ * both that copyright notice and this permission notice appear in
+ * supporting documentation, and that the name of IBM or Lexmark not be
+ * used in advertising or publicity pertaining to distribution of the
+ * software without specific, written prior permission.
+ *
+ * IBM AND LEXMARK PROVIDE THIS SOFTWARE "AS IS", WITHOUT ANY WARRANTIES OF
+ * ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING, BUT NOT LIMITED TO ANY
+ * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE,
+ * AND NONINFRINGEMENT OF THIRD PARTY RIGHTS.  THE ENTIRE RISK AS TO THE
+ * QUALITY AND PERFORMANCE OF THE SOFTWARE, INCLUDING ANY DUTY TO SUPPORT
+ * OR MAINTAIN, BELONGS TO THE LICENSEE.  SHOULD ANY PORTION OF THE
+ * SOFTWARE PROVE DEFECTIVE, THE LICENSEE (NOT IBM OR LEXMARK) ASSUMES THE
+ * ENTIRE COST OF ALL SERVICING, REPAIR AND CORRECTION.  IN NO EVENT SHALL
+ * IBM OR LEXMARK BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
+ * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
+ * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
+ * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
+ * THIS SOFTWARE.
+ */
+/*SHARED*/
+#define   StepLine(R,x1,y1,x2,y2)   t1_StepLine(R,x1,y1,x2,y2)
+#define   Bresenham(e,x1,y1,x2,y2)  t1_Bresenham(e,x1,y1,x2,y2)
+void t1_StepLine();           /* check for special conditions, call Bresenham */
+void t1_Bresenham();          /* produce run ends for lines                   */
+/*END SHARED*/
diff --git a/Xserver/lib/font/Type1/minimain.c b/Xserver/lib/font/Type1/minimain.c
new file mode 100644 (file)
index 0000000..c128b15
--- /dev/null
@@ -0,0 +1,50 @@
+/* $XConsortium: minimain.c,v 1.4 94/04/17 20:17:20 gildea Exp $ */
+
+/*
+
+Copyright (c) 1993, 1994  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be included
+in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR
+OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall
+not be used in advertising or otherwise to promote the sale, use or
+other dealings in this Software without prior written authorization
+from the X Consortium.
+
+*/
+#include "ximager5.h"
+main()
+{
+       XYspace S;
+       path p;
+       InitImager();
+       S = Scale(IDENTITY, 300.0, -300.0);
+       p = Join(Line(Loc(S, 0.0, 1.0)), Line(Loc(S, 1.0, 0.0)));
+       Interior(ClosePath(p), EVENODDRULE);
+}
+void Trace()
+{
+}
+void *DEFAULTDEVICE;
diff --git a/Xserver/lib/font/Type1/objects.c b/Xserver/lib/font/Type1/objects.c
new file mode 100644 (file)
index 0000000..9fffa62
--- /dev/null
@@ -0,0 +1,1119 @@
+/* $XConsortium: objects.c,v 1.11 94/03/23 14:28:05 gildea Exp $ */
+/* Copyright International Business Machines, Corp. 1991
+ * All Rights Reserved
+ * Copyright Lexmark International, Inc. 1991
+ * All Rights Reserved
+ *
+ * License to use, copy, modify, and distribute this software and its
+ * documentation for any purpose and without fee is hereby granted,
+ * provided that the above copyright notice appear in all copies and that
+ * both that copyright notice and this permission notice appear in
+ * supporting documentation, and that the name of IBM or Lexmark not be
+ * used in advertising or publicity pertaining to distribution of the
+ * software without specific, written prior permission.
+ *
+ * IBM AND LEXMARK PROVIDE THIS SOFTWARE "AS IS", WITHOUT ANY WARRANTIES OF
+ * ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING, BUT NOT LIMITED TO ANY
+ * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE,
+ * AND NONINFRINGEMENT OF THIRD PARTY RIGHTS.  THE ENTIRE RISK AS TO THE
+ * QUALITY AND PERFORMANCE OF THE SOFTWARE, INCLUDING ANY DUTY TO SUPPORT
+ * OR MAINTAIN, BELONGS TO THE LICENSEE.  SHOULD ANY PORTION OF THE
+ * SOFTWARE PROVE DEFECTIVE, THE LICENSEE (NOT IBM OR LEXMARK) ASSUMES THE
+ * ENTIRE COST OF ALL SERVICING, REPAIR AND CORRECTION.  IN NO EVENT SHALL
+ * IBM OR LEXMARK BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
+ * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
+ * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
+ * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
+ * THIS SOFTWARE.
+ */
+ /* OBJECTS  CWEB         V0025 ********                             */
+/*
+:h1.OBJECTS Module - TYPE1IMAGER Objects Common Routines
+This module defines and implements the C structures that represent
+objects in the TYPE1IMAGER.  All common routines for manipulating these
+objects are defined in this module.  Specific routines for
+specific objects are defined in the modules that deal with that
+object type.
+&author. Jeffrey B. Lotspiech (lotspiech@almaden.ibm.com)
+:h3.Include Files
+The included files are:
+*/
+#define   GLOBALS  1         /* see :hdref refid=debugvar.                   */
+/*
+The following two includes are C standards; we include them because we
+use 'toupper' and the 'str'-type functions in this module.  Potentially
+these may be defined as macros; if these ".h" files do not exist on your
+system it is a pretty safe bet that these are external entry points and
+you do do not need to include these header files.
+*/
+#include  <string.h>
+#include  <ctype.h>
+/*
+override incorrect system functions; for example you might define
+a macro for "strcpy" that diverts it to "my_strcpy".
+*/
+                               /* moved these includes from above the    */
+                               /*   was included first (it contains com- */
+                               /*   piler defines).  dsr 081291          */
+#include  "objects.h"
+#include  "spaces.h"
+#include  "paths.h"
+#include  "regions.h"
+#include  "fonts.h"
+#include  "pictures.h"
+#include  "strokes.h"
+#include  "cluts.h"
+static char *TypeFmt();
+static ObjectPostMortem();
+
+/*
+:h3.The "pointer" Macro - Define a Generic Pointer
+Sadly, many compilers will give a warning message when a pointer to
+one structure is assigned to a pointer to another.  We've even seen
+some that give severe errors (when the wrong pointer type is used as
+an initializer or returned from a function).  TYPE1IMAGER has routines
+like Dup and Allocate that are perfectly willing to duplicate or
+allocate any of a number of different types of structures.  How to
+declare them in a truely portable way?
+Well, there is no single good answer that I've found.  You can always
+beg the question and "cast" everything.  I find this distracting and the
+resulting code ugly.  On the other hand, we have found at least one
+compiler that will accept "void *" as a generic pointer that can
+assigned to any other pointer type without error or warning (apparently
+this is also the ANSI standard).  So, we define "void *" to be a generic
+pointer.  (You might have to change this for your compiler; the "ifndef"
+allows the change to be made on the command line if you want.)
+:i1/portability assumptions/
+*/
+/*SHARED LINE(S) ORIGINATED HERE*/
+/*
+:h3.Functions Provided to the TYPE1IMAGER User
+This module provides the following TYPE1IMAGER entry points:
+*/
+/*SHARED LINE(S) ORIGINATED HERE*/
+/*
+Note that entry points that are intended for use external to TYPE1IMAGER
+begin with the characters :q/xi/.  Macros are used to make the names
+more mnemonic.
+*/
+/*
+:h3.Functions Provided to Other Modules
+This module provides the following functions for other modules:
+*/
+/*SHARED LINE(S) ORIGINATED HERE*/
+/*
+Note that entry points that intended for use within TYPE1IMAGER, but
+which must be global because they are used across module boundaries,
+begin with the characters :q/I_/.  Macros are used to make the names
+more mnemonic.
+Entry points totally within a module use mnemonic names and are
+declared :hp2/static/.  One of the compilers I used had a bug when
+static functions were passed as addresses.  Thus, some functions
+which are logically "static" are not so declared.
+Note also the trick of declaring routines, like Consume(), with a
+variable number of arguments.  To avoid the restrictions on variable
+numbers of arguments in the macro processor, we just replace the
+text 'Consume' with 'I_Consume'.
+*/
+/*
+:h3.Macros Provided to Other Modules
+This is the module where we define all the useful constants like
+TRUE, FALSE, and NULL, and simple expressions like MIN(), MAX(), and ABS().
+We might as well get to it right here:
+*/
+/*SHARED LINE(S) ORIGINATED HERE*/
+/*
+Notice that upper case is used for constant values and macro
+definitions.  I generally follow that convention.
+Many more global macros are defined later in this module.
+*/
+/*
+:h2.Basic TYPE1IMAGER Object Structure
+All TYPE1IMAGER objects which are available to the user have a common
+header.  This header is defined below:
+*/
+/*SHARED LINE(S) ORIGINATED HERE*/
+/*
+The following define is an attempt to centralize the definition of the
+common xobject data shared by structures that are derived from the
+generic xobject structure. For example, the structure font, defined in
+fonts.shr :
+&code.
+    struct font {
+           char type;
+           char flag;
+           int references;
+           ... other data types & structs ...
+           }
+&ecode.
+would now be defined as:
+&code.
+    struct font {
+           XOBJ_COMMON
+           ... other data types & structs ...
+           }
+&ecode.
+Thus we have a better-structured inheritance mechanism. 3-26-91 PNM
+*/
+/*SHARED LINE(S) ORIGINATED HERE*/
+/*
+:h3.Object Type Definitions
+These constants define the values which go in the 'type' field of
+an TYPE1IMAGER object structure:
+*/
+/*SHARED LINE(S) ORIGINATED HERE*/
+/*
+:h3.Flag Byte Definitions
+Many programmers define flag bits as a mask (for example, 0x04), and
+test, set, and reset them as follows:
+&code.
+        if ((flag & PERMANENT) != 0)
+        flag |= PERMANENT;
+        flag &= &inv.PERMANENT;
+:exmp.
+I favor a style where the 'if' statement can ask a question:
+&code.
+        if (ISPERMANENT(flag))
+        flag |= ISPERMANENT(ON);
+        flag &= &inv.ISPERMANENT(ON);
+:exmp.
+This said, we now define two bit settings of the flag byte of the
+object.  "ISPERMANENT" will be set by the user, when he calls
+Permanent().  "ISIMMORTAL" will be used for compiled-in objects
+that we don't want the user to ever destroy.
+*/
+/*SHARED LINE(S) ORIGINATED HERE*/
+/*
+Flag bit definitions that apply to all objects are assigned
+starting with the least significant (0x01) bit.  Flag bit definitions
+specific to a certain object type are assigned starting with the
+most significant (0x80) bit.  We hope they never meet.
+*/
+/*
+:h3 id=preserve.PRESERVE() Macro
+Occasionally an TYPE1IMAGER operator is implemented by calling other
+TYPE1IMAGER operators.  For example, Arc2() calls Conic().  When we
+call more than one operator as a subroutine, we have to be careful
+of temporary objects.  A temporary object will be consumed by the
+subroutine operator and then is no longer available for the caller.
+This can be prevented simply by bumping a temporary object's reference
+count.
+*/
+/*SHARED LINE(S) ORIGINATED HERE*/
+/*
+:h3.RefRoll() Macro to Detect References Count Rollover
+The following macro is designed to check for reference count rollover.
+A return value of TRUE means rollover has not occurred; a return value
+of FALSE means we cannot increment the reference count.  Note also that
+those functions that use this macro must decrement the reference count
+afterwards.  3-26-91 PNM
+*/
+#define RefRoll(obj)  (++(obj)->references > 0)
+/*
+:h2.TYPE1IMAGER Object Functions
+:h3.LONGCOPY() - Macro to Copy "long" Aligned Data
+Copying arbitrary bytes in C is a bit of a problem.  "strcpy" can't be
+used, because 0 bytes are special-cased.  Most environments have a
+routine "memcopy" or "bcopy" or "bytecopy" that copies memory containing
+zero bytes.  Sadly, there is no standard on the name of such a routine,
+which makes it impossible to write truely portable code to use it.
+It turns out that TYPE1IMAGER, when it wants to copy data, frequently
+knows that both the source and destination are aligned on "long"
+boundaries.  This allows us to copy by using "long *" pointers.  This
+is usually very efficient on almost all processors.  Frequently, it
+is more efficient than using general-purpose assembly language routines.
+So, we define a macro to do this in a portable way.  "dest" and "source"
+must be long-aligned, and "bytes" must be a multiple of "sizeof(long)":
+*/
+/*SHARED LINE(S) ORIGINATED HERE*/
+/*
+:h3.Allocate() - Allocating a Memory Block
+Allocate returns a pointer to memory object that is a copy of
+the template passed (if any).  In addition, extra bytes may be
+allocated contiguously with the object.  (This may be useful for
+variable size objects such as edge lists.  See :hdref refid=regions..)
+Allocate() always returns a non-immortal object, even if the template is
+immortal.  Therefore a non-NULL template must have a "flag" byte.
+If the template is NULL, then 'size' bytes are cleared to all NULLs.
+If the template is non-NULL, a new object is allocated in memory.
+It therefore seems logical that its reference count field should be
+set to 1. So, a nun-NULL template must also have a "references" field.
+PNM 3-26-91
+*/
+struct xobject *t1_Allocate(size, template, extra)  /* non-ANSI; type checking was too strict */
+       register int size;    /* number of bytes to allocate & initialize     */
+       register struct xobject *template;  /* example structure to allocate  */
+       register int extra;   /* any extra uninitialized bytes needed contiguously */
+{
+       extern char *xiMalloc();  /* standard C routine                         */
+       register struct xobject *r;
+       /*
+       * round up 'size' and 'extra' to be an integer number of 'long's:
+       */
+       size = (size + sizeof(long) - 1) & -(int)sizeof(long);
+       extra = (extra + sizeof(long) - 1) & -(int)sizeof(long);
+       if (size + extra <= 0)
+               abort("Non-positive allocate?");
+       r = (struct xobject *) xiMalloc(size + extra);
+       while (r == NULL) {
+               if (!GimeSpace()) {
+                       IfTrace1(TRUE, "malloc attempted %d bytes.\n",
+                                           size + extra);
+                       abort("We have REALLY run out of memory");
+               }
+               r = (struct xobject *) xiMalloc(size + extra);
+       }
+       /*
+       * copy the template into the new memory:
+       */
+       if (template != NULL) {
+       /* Added references count decrement if template is not permanent.
+          This is for the case where Allocate is called by a Dupxxxx
+          function, which was in turn called by Unique(). (PNM)        */
+               if (!ISPERMANENT(template->flag))
+                   --template->references;
+               LONGCOPY(r, template, size);
+               r->flag &= ~(ISPERMANENT(ON) | ISIMMORTAL(ON));
+       /* added reference field 3-2-6-91 PNM */
+               r->references = 1;
+       }
+       else {
+               register char **p1;
+               for (p1=(char **)r; size > 0; size -= sizeof(char *))
+                       *p1++ = NULL;
+       }
+       if (MemoryDebug > 1) {
+               register long *L;
+               L = (long *) r;
+               IfTrace4(TRUE, "Allocating at %x: %x %x %x\n",
+                                           L, L[-1], L[0], L[1]);
+       }
+       return(r);
+}
+/*
+:h3.Free() - Frees an Allocated Object
+This routine makes a sanity check to make sure the "type" field of the
+standard object structure has not been cleared.  If the object is
+not a standard structure, then the macro "NonObjectFree" is available
+that does not perform this check.
+In either case, the object must not be the NULL pointer.  This preserves
+portability, as the C system xiFree() will not always accept NULL.
+*/
+void Free(obj)              /* non-ANSI to avoid overly strict type checking */
+       register struct xobject *obj;  /* structure to free                   */
+{
+       if (obj->type == INVALIDTYPE)
+               abort("Free of already freed object?");
+       obj->type = INVALIDTYPE;
+       if (MemoryDebug > 1) {
+               register long *L;
+               L = (long *) obj;
+               IfTrace4(TRUE,"Freeing at %x: %x %x %x\n", L, L[-1], L[0], L[1]);
+       }
+       xiFree(obj);
+}
+/*
+:h3.Permanent() - Makes an Object Permanent
+Real simple--just set a flag.  Every routine that consumes its objects
+(which is almost every user entry) must check this flag, and not consume
+the object if it is set.
+If a temporary object is made permanent, and there is more than one
+reference to it, we must first Copy() it, then set the ISPERMANENT
+flag. Note also that the reference count must be incremented when an
+object is changed from temporary to permanent (see the ISUNIQUE macro).
+Note that the purpose of this function is to convert an object into a
+permanent object:
+  If it was permanent to begin with, we do nothing;
+  If it was temporary and unique, we set the PERMANENT flag and increment
+the reference count;
+  If it was temporary and nonunique, we must make a unique Copy(), set
+the PERMANENT flag, and set the reference count to 2. We must also
+decrement the original object's reference count, because what we have
+done is to change one of the old temporary handles to a permanent one.
+3-26-91 PNM
+*/
+struct xobject *t1_Permanent(obj) /* non-ANSI to avoid overly strict type checking */
+       register struct xobject *obj;  /* object to be made permanent         */
+{
+       IfTrace1((MustTraceCalls),"Permanent(%z)\n", obj);
+       if ( (obj != NULL) && ( !(ISPERMANENT(obj->flag)) ) )
+       {
+       /* there is a non-NULL, temporary object to be made permanent.
+          If there are multiple references to this object, first get
+          a new COPY().
+          Note also that we have to decrement the reference count if
+          we do a Copy() here, because we are consuming the temporary
+          argument passed, and returning a unique, permanent one.
+       */
+           if ( obj->references > 1)
+           {
+               obj = Copy(obj);
+           }
+           /* now set the permanent flag, and increment the reference
+              count, since a temporary object has now become permanent. */
+           obj->references++;
+           obj->flag |= ISPERMANENT(ON);
+       }
+       return(obj);
+}
+/*
+:h3.Temporary() - Undoes the Effect of "Permanent()"
+This simply resets the "ISPERMANENT" flag.
+If a permanent object is made temporary, and there is more than one reference
+to it, we must first Copy() it, then reset the ISPERMANENT flag. However,
+if the permanent object has obly one reference, we need only decrement the
+reference count ( and reset the flag).
+Note that this function, in the case of a PERMANENT argument, basically
+converts the PERMANENT handle to a TEMPORARY one. Thus, in the case of
+a nonunique, permanent argument passed, we not only make a Copy(),
+we also decrement the reference count, to reflect the fact that we have
+lost a permanent handle and gained a temporary one.
+PNM 3-2-6-91
+*/
+struct xobject *xiTemporary(obj) /* non-ANSI to avoid overly strict type checking */
+       register struct xobject *obj;  /* object to be made permanent         */
+{
+       IfTrace1((MustTraceCalls),"Temporary(%z)\n", obj);
+       if (obj != NULL) {
+               /* if it's already temporary, there's nothing to do. */
+               if ISPERMANENT(obj->flag)
+               {
+               /* if there are multiple references to this object, get a
+                  Copy we can safely alter. Recall that the reference count
+                  is incremented for permanent objects.
+                  Recall further that Copy returns an object with the
+                  same flag state and a reference count of 2 (for PERMANENT
+                  objects).
+                  Thus, regardless of whether or not we need to copy a
+                  permanent object, we still decrement its reference
+                  count and reset the flag.
+               */
+                   if (obj->references != 2 || ISIMMORTAL(obj->flag))
+                   {
+               /* not unique; consume handle, get a temporary Copy! */
+                       obj = Copy(obj);
+                   }
+               /* else decrement the reference count (since it's going from
+                  permanent to temporary) and clear the flag. */
+                   else {
+                       obj->references--;
+                       obj->flag &= ~ISPERMANENT(ON);
+                   }
+               }
+       }
+       return(obj);
+}
+/*
+:h3.Dup() - Duplicate an Object
+Dup will increment the reference count of an object, only making a
+Copy() if needed.
+Note that Dup() retains the state of the permanent flag.
+3-26-91 PNM
+*/
+struct xobject *t1_Dup(obj)   /* non-ANSI avoids overly strict type checking  */
+       register struct xobject *obj;  /* object to be duplicated             */
+{
+       register char oldflag;   /* copy of original object's flag byte */
+       IfTrace1((MustTraceCalls),"Dup(%z)\n", obj);
+       if (obj == NULL)
+               return(NULL);
+       /* An immortal object must be Copy'ed, so that we get a mortal
+          copy of it, since we try not to destroy immortal objects. */
+       if (ISIMMORTAL(obj->flag))
+           return(Copy(obj));
+       /* if incrementing the reference count doesn't cause the count
+          to wrap, simply return the object with the count bumped. Note
+          that the RefRoll macro increments the count to perform the
+          rollover check, so we must decrement the count. */
+       if (RefRoll(obj))
+           return(obj);
+       /* that didn't work out, so put the count back and call Copy(). */
+       --obj->references;
+       oldflag = obj->flag;
+       obj = Copy(obj);
+       if (ISPERMANENT(oldflag))
+               obj = Permanent(obj);
+       return(obj);
+}
+/*
+:h3.Copy() - Make a New Copy of an Object
+This is the generic Copy() where the object type is unknown.  There
+are specific Copyxxx functions for known object types.
+Copy will create a NEW temporary object, and WILL NOT simply bump the
+reference count.
+Sometimes duplicating an object is just as simple as Allocating with it
+as a template.  But other objects are complicated linked lists.  So, we
+let each module provide us a routine (or macro) that duplicates the
+objects it knows about.
+*/
+struct xobject *t1_Copy(obj)
+       register struct xobject *obj;  /* object to be  Copy'ed              */
+{
+       if (obj == NULL)
+               return(NULL);
+       if (ISPATHTYPE(obj->type))
+               obj = (struct xobject *) CopyPath(obj);
+       else
+               switch (obj->type) {
+                   case SPACETYPE:
+                       obj = (struct xobject *) CopySpace(obj); break;
+                   case FONTTYPE:
+                       obj = (struct xobject *) CopyFont(obj); break;
+                   case REGIONTYPE:
+                       obj = (struct xobject *) CopyRegion(obj); break;
+                   case PICTURETYPE:
+                       obj = (struct xobject *) CopyPicture(obj); break;
+                   case LINESTYLETYPE:
+                       obj = (struct xobject *) CopyLineStyle(obj); break;
+                   case STROKEPATHTYPE:
+                       obj = (struct xobject *) CopyStrokePath(obj); break;
+                   case CLUTTYPE:
+                       obj = (struct xobject *) CopyCLUT(obj); break;
+                   default:
+                       return(ArgErr("Copy: invalid object", obj, NULL));
+               }
+        return(obj);
+}
+/*
+:h3.Destroy() - Destroys an Object
+This can get complicated.  Just like with Copy(), we let the experts
+handle it.
+*/
+struct xobject *Destroy(obj) /* non-ANSI avoids overly strict type checking  */
+       register struct xobject *obj;  /* object to be destroyed              */
+{
+       IfTrace1((MustTraceCalls),"Destroy(%z)\n", obj);
+       if (obj == NULL)
+               return(NULL);
+       if (ISIMMORTAL(obj->flag)) {
+               IfTrace1(TRUE,"Destroy of immortal object %z ignored\n", obj);
+               return(NULL);
+       }
+       if (ISPATHTYPE(obj->type))
+               KillPath(obj);
+       else {
+               switch (obj->type) {
+                   case REGIONTYPE:
+                       KillRegion(obj);
+                       break;
+                   case SPACETYPE:
+                       KillSpace(obj);
+                       break;
+                   case LINESTYLETYPE:
+                       KillLineStyle(obj);
+                       break;
+                   case FONTTYPE:
+                       KillFont(obj);
+                       break;
+                   case PICTURETYPE:
+                       KillPicture(obj);
+                       break;
+                   case STROKEPATHTYPE:
+                       KillStrokePath(obj);
+                       break;
+                   case CLUTTYPE:
+                       KillCLUT(obj);
+                       break;
+                   default:
+                       return(ArgErr("Destroy: invalid object", obj, NULL));
+               }
+       }
+       return(NULL);
+}
+/*
+:h2.Generally Useful Macros
+:h3.FOLLOWING() - Macro to Point to the Data Following a Structure
+There are several places in TYPE1IMAGER where we will allocate variable
+data that belongs to a structure immediately after that structure.
+This is a performance technique, because it reduces the number of
+trips we have to take through xiMalloc() and xiFree().  It turns out C has
+a very convenient way to point past a structure--if 'p' is a pointer
+to a structure, 'p+1' is a pointer to the data after it.  This
+behavior of C is somewhat startling and somewhat hard to follow, if
+you are not used to it, so we define a macro to point to the data
+following a structure:
+*/
+/*SHARED LINE(S) ORIGINATED HERE*/
+/*
+:h3.TYPECHECK() - Verify the Type of an Argument
+This macro tests the type of an argument.  If the test fails, it consumes
+any other arguments as necessary and causes the imbedding routine to
+return the value 'whenBAD'.
+Note that the consumeables list should be an argument list itself, for
+example (0) or (2,A,B).  See :hdref refid=consume. below.
+*/
+/*SHARED LINE(S) ORIGINATED HERE*/
+/*
+:h3.ARGCHECK() - Perform an Arbitrary Check on an Argument
+This macro is a generalization of TYPECHECK to take an arbitrary
+predicate.  If the error occurs (i.e., the predicate is true), the
+arbitrary message 'msg' is returned.
+*/
+/*SHARED LINE(S) ORIGINATED HERE*/
+/*
+:h3.TYPENULLCHECK() - Extension of TYPECHECK() for NULL arguments
+Many routines allow NULLs to be passed as arguments.  'whenBAD' will
+be returned in this case, too.
+*/
+/*SHARED LINE(S) ORIGINATED HERE*/
+/*
+:h3.MAKECONSUME() - Create a "Consume"-type Macro
+Consuming an object means destroying it if it is not permanent.  This
+logic is so common to all the routines, that it is immortalized in this
+macro.  For example, ConsumePath(p) can be simply defined as
+MAKECONSUME(p,KillPath(p)).  In effect, this macro operates on a
+meta-level.
+:i1/consuming objects/
+*/
+/*SHARED LINE(S) ORIGINATED HERE*/
+/*
+:h3.MAKEUNIQUE() - Create a "Unique"-type Macro
+Many routines are written to modify their arguments in place.  Thus,
+they want to insure that they duplicate an object if it is permanent.
+This is called making an object "unique".  For example, UniquePath(p)
+can be simply defined as MAKEUNIQUE(p,DupPath(p)).
+:i1/unique objects/
+*/
+/*SHARED LINE(S) ORIGINATED HERE*/
+/*
+An object is unique (and directly alterable) if there is only one
+reference to it, and it is not permanent (in which case we increment
+the reference count, so we don't have to check the permanent bit).
+3-26-91 PNM
+Note the rules for making a unique object:
+&drawing.
+   IF  (obj->references = 1)    return(obj);
+   ELSE (references > 1)
+       IF (ISPERMANENT(obj->flag))    return(Dupxxx(obj));
+       ELSE (nonunique, temporary object!)
+           obj->references--; return(Dupxxx(obj));
+&edrawing.
+If we must make a Copy of a nonunique, temporary object, we decrement
+reference count of the original object!
+*/
+/*
+:h3.Unique() - Make a Unique Object
+Here is a generic 'Unique' function if the object type is not known.
+Why didn't we build it with the MAKEUNIQUE macro, you ask?  Well, we
+used to, but there is at least one damn compiler in the world that
+raises errors if the types of an "(a) ? b : c" expression do not match.
+Also, when we changed Dup() to retain the permanent/temporary flag, we
+wanted to make sure "Unique" always returned a temporary object.
+Note that we cannot use Dup() to create a copy of the object in question,
+because Dup() may simply bump the reference count, and not return a
+unique copy to us. That is why we use t1_Copy().
+The purpose of this function is to make sure we have a copy of an object
+that we can safely alter:
+:ol.
+:li.If we have a unique, temporary object, we simply return the argument.
+:li.If we have a nonunique, temporary object, we have to make a new copy
+of it, and decrement the reference count of the original object, to reflect
+the fact that we traded temporary handles.
+:li.If we have a permanent object, we make a temporary copy of it, but
+we do not decrement the reference count of the original permanent object,
+because permanent objects, by definition, are persistent. 3-2-6-91 PNM
+:eol.
+*/
+struct xobject *t1_Unique(obj)
+       struct xobject *obj;
+{
+    /* if the original object is not already unique, make a unique
+       copy...Note also that if the object was not permanent, we must
+       consume the old handle! 3-26-91 PNM
+       NOTE : consumption of the old handle moved to Allocate. 4-18-91 */
+    if (!obj || obj->references == 1)
+        return(obj);
+    obj = Copy(obj);
+    /* and make sure we return a temporary object ! */
+    if (ISPERMANENT(obj->flag))
+    {
+        obj->flag &= ~ISPERMANENT(ON);
+        obj->references--;
+    }
+    return(obj);
+}
+/*
+:h2.Initialization, Error, and Debug Routines
+:h3 id=debugvar.Declarations for Debug Purposes
+We declare all the debug flags here.  Some link editors make the not
+unreasonable restriction that only one module may declare and
+initialize global variables; all the rest must declare the variable
+'extern'.  This is logical, but is somewhat awkward to implement with
+C include files.  We solve the problem by temporarily making the name
+'extern' a null name if GLOBALS is defined.  (GLOBALS is only defined
+in this OBJECTS module.)  Since 'externs' can't be initialized, we
+have to handle that with #defines too.
+:i1/GLOBALS (&#define.)/
+*/
+/*SHARED LINE(S) ORIGINATED HERE*/
+static char *ErrorMessage = NULL;
+/*
+:h3.Pragmatics() - Set/Reset Debug Flags
+We provide a controlled way for the TYPE1IMAGER user to set and reset
+our debugging and tracing:
+*/
+void Pragmatics(username, value)
+       char *username;       /* name of the flag                             */
+       int value;            /* value to set it to                           */
+{
+       register char *p;     /* temporary loop variable                      */
+#define    NAMESIZE   40
+       char name[NAMESIZE];  /* buffer to store my copy of 'username'        */
+       if (strlen(username) >= (unsigned)NAMESIZE)
+               abort("Pragmatics name too large");
+       strcpy(name, username);
+       for (p = name; *p != '\0'; p++)
+               *p = toupper(*p);
+       if (!strcmp(name, "ALL"))
+               MustTraceCalls = InternalTrace = /* MustCrash = */
+                    LineIOTrace = value;
+       else if (!strcmp(name, "LINEIOTRACE"))
+               LineIOTrace = value;
+       else if (!strcmp(name, "TRACECALLS"))
+               MustTraceCalls = value;
+       else if (!strcmp(name, "CHECKARGS"))
+               MustCheckArgs = value;
+       else if (!strcmp(name, "PROCESSHINTS"))
+               ProcessHints = value;
+       else if (!strcmp(name, "SAVEFONTPATHS"))
+               SaveFontPaths = value;
+       else if (!strcmp(name, "CRASTERCOMPRESSIONTYPE"))
+               CRASTERCompressionType = value;
+       else if (!strcmp(name, "CRASHONUSERERROR"))
+               MustCrash = value;
+       else if (!strcmp(name, "DEBUG"))
+               StrokeDebug = SpaceDebug = PathDebug = ConicDebug = LineDebug =
+                          RegionDebug = MemoryDebug = FontDebug =
+                          HintDebug = ImageDebug = OffPageDebug = value;
+       else if (!strcmp(name, "CONICDEBUG"))
+               ConicDebug = value;
+       else if (!strcmp(name, "LINEDEBUG"))
+               LineDebug = value;
+       else if (!strcmp(name, "REGIONDEBUG"))
+               RegionDebug = value;
+       else if (!strcmp(name, "PATHDEBUG"))
+               PathDebug = value;
+       else if (!strcmp(name, "SPACEDEBUG"))
+               SpaceDebug = value;
+       else if (!strcmp(name, "STROKEDEBUG"))
+               StrokeDebug = value;
+       else if (!strcmp(name, "MEMORYDEBUG"))
+               MemoryDebug = value;
+       else if (!strcmp(name, "FONTDEBUG"))
+               FontDebug = value;
+       else if (!strcmp(name, "HINTDEBUG"))
+               HintDebug = value;
+       else if (!strcmp(name, "IMAGEDEBUG"))
+               ImageDebug = value;
+       else if (!strcmp(name, "OFFPAGEDEBUG"))
+               OffPageDebug = value;
+#ifdef  MC68000
+/*
+The following pragmatics flag turns on or off instruction histograming
+for performance analysis.  It is only defined in the Delta card
+environment.
+*/
+       else if (!strcmp(name, "PROFILE")) {
+               if (value)
+                       StartProfile();
+               else
+                       StopProfile();
+       }
+#endif
+       else if (!strcmp(name, "FLUSHCACHE")) {
+#ifdef notdef
+               while (GimeSpace()) { ; }
+#endif
+       }
+       else if (!strcmp(name, "CACHEDCHARS"))
+               CachedChars = (value <= 0) ? 1 : value;
+       else if (!strcmp(name, "CACHEDFONTS"))
+               CachedFonts = (value <= 0) ? 1 : value;
+       else if (!strcmp(name, "CACHEBLIMIT"))
+               CacheBLimit = value;
+       else if (!strcmp(name, "CONTINUITY"))
+               Continuity = value;
+       else {
+               printf("Pragmatics flag = '%s'\n", name);
+               ArgErr("Pragmatics:  flag not known", NULL, NULL);
+       }
+       return;
+}
+/*
+:h3.Consume() - Consume a List of Arguments
+This general purpose routine is provided in the case where the object
+type(s) to be consumed are unknown or not yet verified, and/or it is
+not known whether the object is permanent.
+If the type of the argument is known, it is faster to directly consume
+that type, for example, ConsumeRegion() or ConsumePath().  Furthermore,
+if it is already known that the object is temporary, it is faster to
+just kill it rather than consume it, for example, KillSpace().
+*/
+void Consume(n, obj1, obj2, obj3) /* non-ANSI avoids overly strict type checking */
+       int n;
+       struct xobject *obj1,*obj2,*obj3;
+{
+       switch(n) {
+           case 0:
+               return;
+           case 1:
+               if (obj1 != NULL && !ISPERMANENT(obj1->flag))
+                       Destroy(obj1);
+               return;
+           case 2:
+               if (obj1 != NULL && !ISPERMANENT(obj1->flag))
+                       Destroy(obj1);
+               if (obj2 != NULL && !ISPERMANENT(obj2->flag))
+                       Destroy(obj2);
+               return;
+           case 3:
+               if (obj1 != NULL && !ISPERMANENT(obj1->flag))
+                       Destroy(obj1);
+               if (obj2 != NULL && !ISPERMANENT(obj2->flag))
+                       Destroy(obj2);
+               if (obj3 != NULL && !ISPERMANENT(obj3->flag))
+                       Destroy(obj3);
+               return;
+           default:
+               abort("Consume:  too many objects");
+       }
+}
+/*
+:h3.TypeErr() - Handles "Invalid Object Type" Errors
+*/
+struct xobject *TypeErr(name, obj, expect, ret) /* non-ANSI avoids overly strict type checking */
+       char *name;           /* Name of routine (for error message)          */
+       struct xobject *obj;  /* Object in error                              */
+       int expect;           /* type expected                                */
+       struct xobject *ret;  /* object to return to caller                   */
+{
+       static char typemsg[80];
+       if (MustCrash)
+               LineIOTrace = TRUE;
+       sprintf(typemsg, "Wrong object type in %s; expected %s.\n",
+                  name, TypeFmt(expect), TypeFmt(obj->type));
+       IfTrace0(TRUE,typemsg);
+       ObjectPostMortem(obj);
+       if (MustCrash)
+               abort("Terminating because of CrashOnUserError...");
+       else
+               ErrorMessage = typemsg;
+/* changed ISPERMANENT to ret->references > 1 3-26-91 PNM */
+       if (ret != NULL && (ret->references > 1))
+               ret = Dup(ret);
+       return(ret);
+}
+/*
+:h4.TypeFmt() - Returns Pointer to English Name of Object Type
+This is a subroutine of TypeErr().
+*/
+static char *TypeFmt(type)
+       int type;             /* type field                                   */
+{
+       char *r;
+       if (ISPATHTYPE(type))
+               if (type == TEXTTYPE)
+                       r = "path or region (from TextPath)";
+               else
+                       r = "path";
+       else {
+               switch (type) {
+                   case INVALIDTYPE:
+                       r = "INVALID (previously consumed?)";
+                       break;
+                   case REGIONTYPE:
+                       r = "region";
+                       break;
+                   case SPACETYPE:
+                       r = "XYspace";
+                       break;
+                   case LINESTYLETYPE:
+                       r = "linestyle";
+                       break;
+                   case FONTTYPE:
+                       r = "font";
+                       break;
+                   case PICTURETYPE:
+                       r = "picture";
+                       break;
+                   case STROKEPATHTYPE:
+                       r = "path (from StrokePath)";
+                       break;
+                   default:
+                       r = "UNKNOWN";
+                       break;
+               }
+       }
+       return(r);
+}
+/*
+:h4.ObjectPostMortem() - Prints as Much as We Can About a Bad Object
+This is a subroutine of TypeErr() and ArgErr().
+*/
+/*ARGSUSED*/
+static ObjectPostMortem(obj) /* non-ANSI avoids overly strict type checking  */
+       register struct xobject *obj;
+{
+       extern struct XYspace *USER;
+       Pragmatics("Debug", 10);
+       IfTrace2(TRUE,"Bad object is of %s type %z\n", TypeFmt(obj->type), obj);
+       IfTrace0((obj == (struct xobject *) USER),
+                  "Suspect that InitImager() was omitted.\n");
+       Pragmatics("Debug", 0);
+}
+/*
+:h3.ArgErr() - Invalid Argument Passed to a Routine
+A common routine to report argument errors.  It is usually called
+is returned to the caller in case MustCrash is FALSE and ArgErr
+returns to its caller.
+*/
+struct xobject *ArgErr(string, obj, ret) /* non-ANSI avoids overly strict type checking */
+       char *string;         /* description of error                         */
+       struct xobject *obj;  /* object, if any, that was in error            */
+       struct xobject *ret;  /* object returned to caller or NULL            */
+{
+       if (MustCrash)
+               LineIOTrace = TRUE;
+       IfTrace1(TRUE,"ARGUMENT ERROR-- %s.\n", string);
+       if (obj != NULL)
+               ObjectPostMortem(obj);
+       if (MustCrash)
+               abort("Terminating because of CrashOnUserError...");
+       else
+               ErrorMessage = string;
+       return(ret);
+}
+/*
+:h3.abort() - Crash Due to Error
+Defined in objects.h to be FatalError(), the server's abort routine.
+*/
+/*
+:h3.REAL Miscellaneous Stuff
+:h4.ErrorMsg() - Return the User an Error Message
+*/
+char *ErrorMsg()
+{
+       register char *r;
+       r = ErrorMessage;
+       ErrorMessage = NULL;
+       return(r);
+}
+/*
+:h4.InitImager() - Initialize TYPE1IMAGER
+We check that a short is 16 bits and a long 32 bits; we have made
+those assumptions elsewhere in the code.  (This is almost a C standard,
+anyway.)  Note that TYPE1IMAGER makes no assumptions about the size of an
+'int'!
+:i1/portability assumptions/
+*/
+void InitImager()
+{
+/* Check to see if we have been using our own malloc.  If so,*/
+/* Undef malloc so that we can get to the system call. */
+/* All other calls to malloc are defined to xiMalloc.  */
+/*       if (sizeof(short) != 2 || sizeof(INT32) != 4)
+               abort("Fundamental TYPE1IMAGER assumptions invalid in this port");
+*/
+       InitSpaces();
+       InitFonts();
+       InitFiles();
+/*
+In some environments, constants and/or exception handling need to be
+*/
+       LibInit();
+}
+/*
+:h4.TermImager() - Terminate TYPE1IMAGER
+This only makes sense in a server environment; true TYPE1IMAGER needs do
+nothing.
+*/
+void TermImager()
+{
+       return;
+}
+/*
+:h4.reportusage() - A Stub to Get a Clean Link with Portable PMP
+*/
+void reportusage()
+{
+       return;
+}
diff --git a/Xserver/lib/font/Type1/objects.h b/Xserver/lib/font/Type1/objects.h
new file mode 100644 (file)
index 0000000..f191710
--- /dev/null
@@ -0,0 +1,291 @@
+/* $XConsortium: objects.h,v 1.8 94/03/22 19:08:58 gildea Exp $ */
+/* Copyright International Business Machines, Corp. 1991
+ * All Rights Reserved
+ * Copyright Lexmark International, Inc. 1991
+ * All Rights Reserved
+ *
+ * License to use, copy, modify, and distribute this software and its
+ * documentation for any purpose and without fee is hereby granted,
+ * provided that the above copyright notice appear in all copies and that
+ * both that copyright notice and this permission notice appear in
+ * supporting documentation, and that the name of IBM or Lexmark not be
+ * used in advertising or publicity pertaining to distribution of the
+ * software without specific, written prior permission.
+ *
+ * IBM AND LEXMARK PROVIDE THIS SOFTWARE "AS IS", WITHOUT ANY WARRANTIES OF
+ * ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING, BUT NOT LIMITED TO ANY
+ * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE,
+ * AND NONINFRINGEMENT OF THIRD PARTY RIGHTS.  THE ENTIRE RISK AS TO THE
+ * QUALITY AND PERFORMANCE OF THE SOFTWARE, INCLUDING ANY DUTY TO SUPPORT
+ * OR MAINTAIN, BELONGS TO THE LICENSEE.  SHOULD ANY PORTION OF THE
+ * SOFTWARE PROVE DEFECTIVE, THE LICENSEE (NOT IBM OR LEXMARK) ASSUMES THE
+ * ENTIRE COST OF ALL SERVICING, REPAIR AND CORRECTION.  IN NO EVENT SHALL
+ * IBM OR LEXMARK BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
+ * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
+ * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
+ * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
+ * THIS SOFTWARE.
+ */
+/*SHARED*/
+/*END SHARED*/
+/*SHARED*/
+
+#define   Permanent(obj)    t1_Permanent(obj)
+#define   Temporary(obj)    t1_Temporary(obj)
+#define   Destroy(obj)      t1_Destroy(obj)
+#define   Dup(obj)          t1_Dup(obj)
+#define   InitImager()      t1_InitImager()
+#define   TermImager()      t1_TermImager()
+#define   Pragmatics(f,v)   t1_Pragmatics(f,v)
+#define   ErrorMsg()        t1_ErrorMsg()
+struct xobject *t1_Permanent();  /* make an object permanent                 */
+struct xobject *t1_Temporary();  /* make an object temporary                 */
+struct xobject *t1_Destroy();    /* destroy an object                        */
+struct xobject *t1_Dup();     /* duplicate an object                         */
+void t1_InitImager();         /* initialize TYPE1IMAGER                      */
+void t1_TermImager();         /* terminate TYPE1IMAGER                       */
+void t1_Pragmatics();         /* set debug flags, etc.                       */
+char *t1_ErrorMsg();          /* return last TYPE1IMAGER error message       */
+/*END SHARED*/
+/*SHARED*/
+#define   abort(line)       FatalError(line)
+#define   Allocate(n,t,s)   t1_Allocate(n,t,s)
+#define   Free(obj)         t1_Free(obj)
+#define   NonObjectFree(a)  xiFree(a)
+#define   Consume           t1_Consume
+#define   ArgErr(s,o,r)     t1_ArgErr(s,o,r)
+#define   TypeErr(n,o,e,r)  t1_TypeErr(n,o,e,r)
+#define   Copy(obj)         t1_Copy(obj)
+#define   Unique(obj)       t1_Unique(obj)
+struct xobject *t1_Allocate();    /* allocate memory                         */
+void t1_Free();               /* free memory                                 */
+struct xobject *t1_Unique();  /* make a unique temporary copy of an object   */
+struct xobject *t1_ArgErr();  /* handle argument errors                      */
+struct xobject *t1_TypeErr(); /* handle 'bad type' argument errors           */
+void t1_Consume();            /* consume a variable number of arguments      */
+struct xobject *t1_Copy();    /* make a new copy, not reference bump PNM     */
+/*END SHARED*/
+/*SHARED*/
+#define   ON          (~0)   /* all bits on                                  */
+#ifndef FALSE
+#define   FALSE       0      /* handy zero value                             */
+#endif
+#ifndef TRUE
+#define   TRUE        1      /* handy non-zero value                         */
+#endif
+#ifndef   NULL
+#define   NULL        0
+/*
+The NULL pointer is system specific.  (Most systems, however, use 0.)
+TYPE1IMAGER could have its own NULL, independent of the rest of the system,
+were it not for malloc().  The system call malloc() returns NULL when
+out of memory.
+:i1/portibility assumptions/
+*/
+#endif
+#ifndef MIN
+#define   MIN(a,b)    (((a)<(b)) ? a : b)
+#endif
+#ifndef MAX
+#define   MAX(a,b)    (((a)>(b)) ? a : b)
+#endif
+#ifndef ABS
+#define   ABS(a)      (((a)>=0)?(a):-(a))
+#endif
+
+/*END SHARED*/
+/*SHARED*/
+struct xobject {
+       char type;           /* encoded type of object                        */
+       unsigned char flag;  /* flag byte for temporary object characteristics*/
+       short references;    /* count of pointers to this object
+                               (plus 1 for permanent objects) PNM            */
+} ;
+/*END SHARED*/
+/*SHARED*/
+#define XOBJ_COMMON      char type; unsigned char flag; short references;
+/*END SHARED*/
+/*SHARED*/
+#define   INVALIDTYPE    0
+#define   FONTTYPE       1
+#define   REGIONTYPE     3
+#define   PICTURETYPE    4
+#define   SPACETYPE      5
+#define   LINESTYLETYPE  6
+#define   EDGETYPE       7
+#define   STROKEPATHTYPE 8
+#define   CLUTTYPE       9
+#define   ISPATHTYPE(type)    ((type)&0x10)  /* all path segments have this bit on */
+#define   LINETYPE    (0+ISPATHTYPE(ON))
+#define   CONICTYPE   (1+ISPATHTYPE(ON))
+#define   BEZIERTYPE  (2+ISPATHTYPE(ON))
+#define   HINTTYPE    (3+ISPATHTYPE(ON))
+#define   MOVETYPE    (5+ISPATHTYPE(ON))
+#define   TEXTTYPE    (6+ISPATHTYPE(ON))
+/*END SHARED*/
+/*SHARED*/
+#define   ISPERMANENT(flag)   ((flag)&0x01)
+#define   ISIMMORTAL(flag)    ((flag)&0x02)
+/*END SHARED*/
+/*SHARED*/
+#define   PRESERVE(obj)   if (!ISPERMANENT((obj)->flag)) \
+   (obj)->references++;
+/*END SHARED*/
+/*SHARED*/
+#define  LONGCOPY(dest,source,bytes) { \
+    register long *p1 = (long *)dest;  register long *p2 = (long *)source; \
+    register int count = (bytes) / sizeof(long); \
+    while (--count >= 0) *p1++ = *p2++; }
+/*END SHARED*/
+/*SHARED*/
+#define   FOLLOWING(p)  ((p)+1)
+/*END SHARED*/
+/*SHARED*/
+#define  TYPECHECK(name, obj, expect, whenBAD, consumables, rettype) { \
+    if (obj->type != expect) { \
+         (Consume)consumables; \
+         return((rettype)TypeErr(name, obj, expect, whenBAD)); \
+    } \
+}
+/*END SHARED*/
+/*SHARED*/
+#define  ARGCHECK(test,msg,obj,whenBAD,consumables,rettype) { \
+    if (test) { \
+        (Consume)consumables; \
+        return((rettype)ArgErr(msg, obj, whenBAD)); \
+    } \
+}
+/*END SHARED*/
+/*SHARED*/
+/* Changed use of Dup() below to Temporary(Copy()) because Dup() does not
+   necessarily return a Unique Copy anymore! 3-26-91 */
+#define  TYPENULLCHECK(name, obj, expect, whenBAD, consumables,rettype) \
+    if (obj == NULL) { \
+        (Consume)consumables; \
+        if (whenBAD != NULL && ISPERMANENT(whenBAD->flag)) \
+              return((rettype)Temporary(Copy(whenBAD))); \
+        else  return((rettype)whenBAD); \
+    } else { \
+        if (obj->type != expect) { \
+             (Consume)consumables; \
+             return((rettype)TypeErr(name, obj, expect, whenBAD)); \
+        } \
+    }
+/*END SHARED*/
+/*SHARED*/
+#define  MAKECONSUME(obj,stmt)  { if (!ISPERMANENT(obj->flag)) stmt; }
+/*END SHARED*/
+/*SHARED*/
+#define MAKEUNIQUE(obj,stmt) ( ( (obj)->references > 1 ) ? stmt : obj )
+/*END SHARED*/
+/*SHARED*/
+#define IfTrace0(condition,model)
+#define IfTrace1(condition,model,arg0)
+#define IfTrace2(condition,model,arg0,arg1)
+#define IfTrace3(condition,model,arg0,arg1,arg2)
+#define IfTrace4(condition,model,arg0,arg1,arg2,arg3)
+#define IfTrace5(condition,model,arg0,arg1,arg2,arg3,arg4)
+#define IfTrace6(condition,model,arg0,arg1,arg2,arg3,arg4,arg5)
+void Trace0();
+char *Trace1(),*Trace2(),*Trace3(),*Trace4(),*Trace5(),*Trace6();
+#ifdef GLOBALS
+#define   extern
+#define   INITIALIZED(value)      = value
+#else
+#define   INITIALIZED(value)
+#endif
+extern char MustCheckArgs  INITIALIZED(TRUE);
+extern char MustTraceCalls INITIALIZED(FALSE);
+extern char MustCrash      INITIALIZED(TRUE);
+extern char InternalTrace  INITIALIZED(TRUE);
+extern char LineIOTrace    INITIALIZED(TRUE);
+extern char ProcessHints   INITIALIZED(TRUE);
+extern char SaveFontPaths  INITIALIZED(TRUE);
+extern short CRASTERCompressionType   INITIALIZED(1);
+extern char ConicDebug     INITIALIZED(0);
+extern char LineDebug      INITIALIZED(0);
+extern char RegionDebug    INITIALIZED(0);
+extern char PathDebug      INITIALIZED(0);
+extern char FontDebug      INITIALIZED(0);
+extern char SpaceDebug     INITIALIZED(0);
+extern char StrokeDebug    INITIALIZED(0);
+extern char MemoryDebug    INITIALIZED(0);
+extern char HintDebug      INITIALIZED(0);
+extern char ImageDebug     INITIALIZED(0);
+extern char OffPageDebug   INITIALIZED(0);
+extern short CachedChars   INITIALIZED(0x7FFF);
+extern short CachedFonts   INITIALIZED(0x7FFF);
+extern int   CacheBLimit   INITIALIZED(12500);
+extern char  Continuity    INITIALIZED(2);
+#ifdef extern
+#undef extern
+#endif
+/*
+We define other routines formatting parameters
+*/
+#define    DumpArea(area)    t1_DumpArea(area)
+#define    DumpText(text)    t1_DumpText(text)
+#define    DumpPath(path)    t1_DumpPath(path)
+#define    DumpSpace(space)  t1_DumpSpace(space)
+#define    DumpEdges(e)      t1_DumpEdges(e)
+#define    FormatFP(s,p)     t1_FormatFP(s,p)
+void t1_DumpArea();           /* dump a region structure                     */
+void t1_DumpText();           /* dump a textpath structure                   */
+void t1_DumpPath();           /* dump a path list                            */
+void t1_DumpSpace();          /* dump a coordinate space structure           */
+void t1_DumpEdges();          /* dump a region's edge list                   */
+void t1_FormatFP();           /* dump a format a "fractpel" coordinate       */
+/*END SHARED*/
diff --git a/Xserver/lib/font/Type1/paths.c b/Xserver/lib/font/Type1/paths.c
new file mode 100644 (file)
index 0000000..efd3f10
--- /dev/null
@@ -0,0 +1,1507 @@
+/* $XConsortium: paths.c,v 1.4 91/10/10 11:18:40 rws Exp $ */
+/* Copyright International Business Machines, Corp. 1991
+ * All Rights Reserved
+ * Copyright Lexmark International, Inc. 1991
+ * All Rights Reserved
+ *
+ * License to use, copy, modify, and distribute this software and its
+ * documentation for any purpose and without fee is hereby granted,
+ * provided that the above copyright notice appear in all copies and that
+ * both that copyright notice and this permission notice appear in
+ * supporting documentation, and that the name of IBM or Lexmark not be
+ * used in advertising or publicity pertaining to distribution of the
+ * software without specific, written prior permission.
+ *
+ * IBM AND LEXMARK PROVIDE THIS SOFTWARE "AS IS", WITHOUT ANY WARRANTIES OF
+ * ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING, BUT NOT LIMITED TO ANY
+ * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE,
+ * AND NONINFRINGEMENT OF THIRD PARTY RIGHTS.  THE ENTIRE RISK AS TO THE
+ * QUALITY AND PERFORMANCE OF THE SOFTWARE, INCLUDING ANY DUTY TO SUPPORT
+ * OR MAINTAIN, BELONGS TO THE LICENSEE.  SHOULD ANY PORTION OF THE
+ * SOFTWARE PROVE DEFECTIVE, THE LICENSEE (NOT IBM OR LEXMARK) ASSUMES THE
+ * ENTIRE COST OF ALL SERVICING, REPAIR AND CORRECTION.  IN NO EVENT SHALL
+ * IBM OR LEXMARK BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
+ * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
+ * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
+ * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
+ * THIS SOFTWARE.
+ */
+ /* PATHS    CWEB         V0021 ********                             */
+/*
+:h1 id=paths.PATHS Module - Path Operator Handler
+This is the module that is responsible for building and transforming
+path lists.
+&author. Jeffrey B. Lotspiech (lotspiech@almaden.ibm.com)
+:h3.Include Files
+The included files are:
+*/
+                             /*   after the system includes  (dsr)           */
+#include  "objects.h"
+#include  "spaces.h"
+#include  "paths.h"
+#include  "regions.h"      /* understands about Union                      */
+#include  "fonts.h"        /* understands about TEXTTYPEs                  */
+#include  "pictures.h"     /* understands about handles                    */
+#include  "strokes.h"      /* understands how to coerce stroke paths       */
+#include  "trig.h"
+static UnClose();
+
+/*
+:h3.Routines Available to the TYPE1IMAGER User
+The PATHS routines that are made available to the outside user are:
+*/
+/*SHARED LINE(S) ORIGINATED HERE*/
+/*
+:h3.Functions Provided to Other Modules
+The path routines that are made available to other TYPE1IMAGER modules
+are defined here:
+*/
+/*SHARED LINE(S) ORIGINATED HERE*/
+/*
+NOTE:  because of the casts put in the macros for Loc, ArcCA, Conic,
+RoundConic, PathSegment, and JoinSegment, we cannot use the macro names
+when the functions are actually defined.  We have to use the unique
+names with their unique first two characters.  Thus, if anyone in the
+future ever decided to change the first two characters, it would not be
+enough just to change the macro (as it would for most other functions).
+He would have to also change the function definition.
+*/
+/*
+:h3.Macros Provided to Other Modules
+The CONCAT macro is defined here and used in the STROKES module.  See
+:hdref refid=pathmac..
+*/
+/*SHARED LINE(S) ORIGINATED HERE*/
+/*
+:h2.Path Segment Structures
+A path is represented as a linked list of the following structure:
+*/
+/*SHARED LINE(S) ORIGINATED HERE*/
+/*
+When 'link' is NULL, we are at the last segment in the path (surprise!).
+'last' is only non-NULL on the first segment of a path,
+for all the other segments 'last' == NULL.  We test for a non-NULL
+'last' (ISPATHANCHOR predicate) when we are given an alleged path
+to make sure the user is not trying to pull a fast one on us.
+A path may be a collection of disjoint paths.  Every break in the
+disjoint path is represented by a MOVETYPE segment.
+Closed paths are discussed in :hdref refid=close..
+:h3.CopyPath() - Physically Duplicating a Path
+This simple function illustrates moving through the path linked list.
+Duplicating a segment just involves making a copy of it, except for
+text, which has some auxilliary things involved.  We don't feel
+competent to duplicate text in this module, so we call someone who
+knows how (in the FONTS module).
+*/
+struct segment *CopyPath(p0)
+       register struct segment *p0;  /* path to duplicate                    */
+{
+       register struct segment *p,*n,*last,*anchor;
+       for (p = p0, anchor = NULL; p != NULL; p = p->link) {
+               ARGCHECK((!ISPATHTYPE(p->type) || (p != p0 && p->last != NULL)),
+                       "CopyPath: invalid segment", p, NULL, (0), struct segment *);
+               if (p->type == TEXTTYPE)
+                       n = (struct segment *) CopyText(p);
+               else
+                       n = (struct segment *)Allocate(p->size, p, 0);
+               n->last = NULL;
+               if (anchor == NULL)
+                       anchor = n;
+               else
+                       last->link = n;
+               last = n;
+       }
+/*
+At this point we have a chain of newly allocated segments hanging off
+'anchor'.  We need to make sure the first segment points to the last:
+*/
+       if (anchor != NULL) {
+               n->link = NULL;
+               anchor->last = n;
+       }
+       return(anchor);
+}
+/*
+:h3.KillPath() - Destroying a Path
+Destroying a path is simply a matter of freeing each segment in the
+linked list.  Again, we let the experts handle text.
+*/
+void KillPath(p)
+       register struct segment *p;  /* path to destroy                       */
+{
+       register struct segment *linkp;  /* temp register holding next segment*/
+       /* return conditional based on reference count 3-26-91 PNM */
+       if ( (--(p->references) > 1) ||
+          ( (p->references == 1) && !ISPERMANENT(p->flag) ) )
+           return;
+       while (p != NULL) {
+               if (!ISPATHTYPE(p->type)) {
+                       ArgErr("KillPath: bad segment", p, NULL);
+                       return;
+               }
+               linkp = p->link;
+               if (p->type == TEXTTYPE)
+                       KillText(p);
+               else
+                       Free(p);
+               p = linkp;
+       }
+}
+/*
+:h2 id=location."location" Objects
+The TYPE1IMAGER user creates and destroys objects of type "location".  These
+objects locate points for the primitive path operators.  We play a trick
+here and store these objects in the same "segment" structure used for
+paths, with a type field == MOVETYPE.
+This allows the Line() operator, for example, to be very trivial:
+It merely stamps its input structure as a LINETYPE and returns it to the
+caller--assuming, of course, the input structure was not permanent (as
+it usually isn't).
+:h3.The "movesegment" Template Structure
+This template is used as a generic segment structure for Allocate:
+*/
+/* added reference field 1 to temporary template below 3-26-91 PNM */
+static struct segment movetemplate = { MOVETYPE, 0, 1, sizeof(struct segment), 0,
+                NULL, NULL, 0, 0 };
+/*
+:h3.Loc() - Create an "Invisible Line" Between (0,0) and a Point
+*/
+struct segment *t1_Loc(S, x, y)
+       register struct XYspace *S;  /* coordinate space to interpret X,Y     */
+       double x,y;           /* destination point                            */
+{
+       register struct segment *r;
+       IfTrace3((MustTraceCalls),"..Loc(S=%z, x=%f, y=%f)\n", S, &x, &y);
+       r = (struct segment *)Allocate(sizeof(struct segment), &movetemplate, 0);
+       TYPECHECK("Loc", S, SPACETYPE, r, (0), struct segment *);
+       r->last = r;
+       r->context = S->context;
+       (*S->convert)(&r->dest, S, x, y);
+       ConsumeSpace(S);
+       return(r);
+}
+/*
+:h3.ILoc() - Loc() With Integer Arguments
+*/
+struct segment *ILoc(S, x, y)
+       register struct XYspace *S;  /* coordinate space to interpret X,Y     */
+       register int x,y;        /* destination point                         */
+{
+       register struct segment *r;
+       IfTrace3((MustTraceCalls),"..ILoc(S=%z, x=%d, y=%d)\n",
+                                    S, (long) x, (long) y);
+       r = (struct segment *)Allocate(sizeof(struct segment), &movetemplate, 0);
+       TYPECHECK("Loc", S, SPACETYPE, r, (0), struct segment *);
+       r->last = r;
+       r->context = S->context;
+       (*S->iconvert)(&r->dest, S, (long) x, (long) y);
+       ConsumeSpace(S);
+       return(r);
+}
+/*
+:h3.SubLoc() - Vector Subtraction of Two Locition Objects
+This user operator subtracts two location objects, yielding a new
+location object that is the result.
+The symmetrical function AddLoc() is totally redundent with Join(),
+so it is not provided.
+*/
+struct segment *SubLoc(p1, p2)
+       register struct segment *p1;
+       register struct segment *p2;
+{
+       IfTrace2((MustTraceCalls),"SubLoc(%z, %z)\n", p1, p2);
+       ARGCHECK(!ISLOCATION(p1), "SubLoc: bad first arg", p1, NULL, (0), struct segment *);
+       ARGCHECK(!ISLOCATION(p2), "SubLoc: bad second arg", p2, NULL, (0), struct segment *);
+       p1 = UniquePath(p1);
+       p1->dest.x -= p2->dest.x;
+       p1->dest.y -= p2->dest.y;
+       ConsumePath(p2);
+       return(p1);
+}
+/*
+:h2.Straight Line Segments
+:h3.PathSegment() - Create a Generic Path Segment
+Many routines need a LINETYPE or MOVETYPE path segment, but do not
+want to go through the external user's interface, because, for example,
+they already know the "fractpel" destination of the segment and the
+conversion is unnecessary.  PathSegment() is an internal routine
+provided to the rest of TYPE1IMAGER for handling these cases.
+*/
+struct segment *t1_PathSegment(type, x, y)
+       int type;             /* LINETYPE or MOVETYPE                         */
+       fractpel x,y;         /* where to go to, if known                     */
+{
+       register struct segment *r;  /* newly created segment                 */
+       r = (struct segment *)Allocate(sizeof(struct segment), &movetemplate, 0);
+       r->type = type;
+       r->last = r;          /* last points to itself for singleton          */
+       r->dest.x = x;
+       r->dest.y = y;
+       return(r);
+}
+/*
+:h3.Line() - Create a Line Segment Between (0,0) and a Point P
+This involves just creating and filling out a segment structure:
+*/
+struct segment *Line(P)
+       register struct segment *P;  /* relevant coordinate space             */
+{
+       IfTrace1((MustTraceCalls),"..Line(%z)\n", P);
+       ARGCHECK(!ISLOCATION(P), "Line: arg not a location", P, NULL, (0), struct segment *);
+       P = UniquePath(P);
+       P->type = LINETYPE;
+       return(P);
+}
+/*
+:h2.Curved Path Segments
+We need more points to describe curves.  So, the structures for curved
+path segments are slightly different.  The first part is identical;
+the curved structures are larger with the extra points on the end.
+:h3.Bezier Segment Structure
+We support third order Bezier curves.  They are specified with four
+control points A, B, C, and D.  The curve starts at A with slope AB
+and ends at D with slope CD.  The curvature at the point A is inversely
+related to the length |AB|, and the curvature at the point D is
+inversely related to the length |CD|.  Point A is always point (0,0).
+*/
+/*SHARED LINE(S) ORIGINATED HERE*/
+/*
+:h3.Bezier() - Generate a Bezier Segment
+This is just a simple matter of filling out a 'beziersegment' structure:
+*/
+struct beziersegment *Bezier(B, C, D)
+       register struct segment *B;  /* second control point                  */
+       register struct segment *C;  /* third control point                   */
+       register struct segment *D;  /* fourth control point (ending point)   */
+{
+/* added reference field of 1 to temporary template below 3-26-91  PNM */
+       static struct beziersegment template =
+                    { BEZIERTYPE, 0, 1, sizeof(struct beziersegment), 0,
+                      NULL, NULL, { 0, 0 }, { 0, 0 }, { 0, 0 } };
+       register struct beziersegment *r;  /* output segment                  */
+       IfTrace3((MustTraceCalls),"..Bezier(%z, %z, %z)\n", B, C, D);
+       ARGCHECK(!ISLOCATION(B), "Bezier: bad B", B, NULL, (2,C,D), struct beziersegment *);
+       ARGCHECK(!ISLOCATION(C), "Bezier: bad C", C, NULL, (2,B,D), struct beziersegment *);
+       ARGCHECK(!ISLOCATION(D), "Bezier: bad D", D, NULL, (2,B,C), struct beziersegment *);
+       r = (struct beziersegment *)Allocate(sizeof(struct beziersegment), &template, 0);
+       r->last = (struct segment *) r;
+       r->dest.x = D->dest.x;
+       r->dest.y = D->dest.y;
+       r->B.x = B->dest.x;
+       r->B.y = B->dest.y;
+       r->C.x = C->dest.x;
+       r->C.y = C->dest.y;
+       ConsumePath(B);
+       ConsumePath(C);
+       ConsumePath(D);
+       return(r);
+}
+/*
+:h2.Font "Hint" Segments
+:h3.Hint() - A Font 'Hint' Segment
+This is temporary code while we experiment with hints.
+*/
+/*SHARED LINE(S) ORIGINATED HERE*/
+struct hintsegment *Hint(S, ref, width, orientation, hinttype, adjusttype, direction, label)
+       struct XYspace *S;
+       float ref;
+       float width;
+       char orientation;
+       char hinttype;
+       char adjusttype;
+       char direction;
+       int label;
+{
+/* added reference field of 1 to hintsegment template below 3-26-91 PNM */
+       static struct hintsegment template = { HINTTYPE, 0, 1, sizeof(struct hintsegment), 0,
+                                          NULL, NULL, { 0, 0 }, { 0, 0 }, { 0, 0 },
+                                          ' ', ' ', ' ', ' ', 0};
+       register struct hintsegment *r;
+       r = (struct hintsegment *)Allocate(sizeof(struct hintsegment), &template, 0);
+       r->orientation = orientation;
+       if (width == 0.0)  width = 1.0;
+       if (orientation == 'h') {
+               (*S->convert)(&r->ref, S, 0.0, ref);
+               (*S->convert)(&r->width, S, 0.0, width);
+       }
+       else if (orientation == 'v') {
+               (*S->convert)(&r->ref, S, ref, 0.0);
+               (*S->convert)(&r->width, S, width, 0.0);
+       }
+       else
+               return((struct hintsegment *)ArgErr("Hint: orient not 'h' or 'v'", NULL, NULL));
+       if (r->width.x < 0)  r->width.x = - r->width.x;
+       if (r->width.y < 0)  r->width.y = - r->width.y;
+       r->hinttype = hinttype;
+       r->adjusttype = adjusttype;
+       r->direction = direction;
+       r->label = label;
+       r->last = (struct segment *) r;
+       ConsumeSpace(S);
+       return(r);
+}
+/*
+*/
+/*SHARED LINE(S) ORIGINATED HERE*/
+/*
+POP removes the first segment in a path 'p' and Frees it.  'p' is left
+pointing to the end of the path:
+*/
+#define POP(p) \
+     { register struct segment *linkp; \
+       linkp = p->link; \
+       if (linkp != NULL) \
+               linkp->last = p->last; \
+       Free(p); \
+       p = linkp; }
+/*
+INSERT inserts a single segment in the middle of a chain.  'b' is
+the segment before, 'p' the segment to be inserted, and 'a' the
+segment after.
+*/
+#define INSERT(b,p,a)  b->link=p; p->link=a; p->last=NULL
+/*
+:h3.Join() - Join Two Objects Together
+If these are paths, this operator simply invokes the CONCAT macro.
+Why so much code then, you ask?  Well we have to check for object
+types other than paths, and also check for certain path consistency
+rules.
+*/
+struct segment *Join(p1, p2)
+       register struct segment *p1,*p2;
+{
+       IfTrace2((MustTraceCalls && PathDebug > 1),"..Join(%z, %z)\n", p1, p2);
+       IfTrace2((MustTraceCalls && PathDebug <=1),"..Join(%x, %x)\n", p1, p2);
+/*
+We start with a whole bunch of very straightforward argument tests:
+*/
+       if (p2 != NULL) {
+               if (!ISPATHTYPE(p2->type)) {
+                       if (p1 == NULL)
+                               return((struct segment *)Unique(p2));
+                       switch (p1->type) {
+                           case REGIONTYPE:
+                           case STROKEPATHTYPE:
+                               p1 = CoercePath(p1);
+                               break;
+                           default:
+                               return((struct segment *)BegHandle(p1, p2));
+                       }
+               }
+               ARGCHECK((p2->last == NULL), "Join: right arg not anchor", p2, NULL, (1,p1), struct segment *);
+               p2 = UniquePath(p2);
+/*
+In certain circumstances, we don't have to duplicate a permanent
+location.  (We would just end up destroying it anyway).  These cases
+are when 'p2' begins with a move-type segment:
+*/
+               if (p2->type == TEXTTYPE || p2->type == MOVETYPE) {
+                       if (p1 == NULL)
+                               return(p2);
+                       if (ISLOCATION(p1)) {
+                               p2->dest.x += p1->dest.x;
+                               p2->dest.y += p1->dest.y;
+                               ConsumePath(p1);
+                               return(p2);
+                       }
+               }
+       }
+       else
+               return((struct segment *)Unique(p1));
+       if (p1 != NULL) {
+               if (!ISPATHTYPE(p1->type))
+                       switch (p2->type) {
+                           case REGIONTYPE:
+                           case STROKEPATHTYPE:
+                               p2 = CoercePath(p2);
+                               break;
+                           default:
+                               return((struct segment *)EndHandle(p1, p2));
+                       }
+               ARGCHECK((p1->last == NULL), "Join: left arg not anchor", p1, NULL, (1,p2), struct segment *);
+               p1 = UniquePath(p1);
+       }
+       else
+               return(p2);
+/*
+At this point all the checking is done.  We have two temporary non-null
+path types in 'p1' and 'p2'.  If p1 ends with a MOVE, and p2 begins with
+a MOVE, we collapse the two MOVEs into one.  We enforce the rule that
+there may not be two MOVEs in a row:
+*/
+       if (p1->last->type == MOVETYPE && p2->type == MOVETYPE) {
+               p1->last->flag |= p2->flag;
+               p1->last->dest.x += p2->dest.x;
+               p1->last->dest.y += p2->dest.y;
+               POP(p2);
+               if (p2 == NULL)
+                       return(p1);
+       }
+/*
+Now we check for another silly rule.  If a path has any TEXTTYPEs,
+then it must have only TEXTTYPEs and MOVETYPEs, and furthermore,
+it must begin with a TEXTTYPE.  This rule makes it easy to check
+for the special case of text.  If necessary, we will coerce
+TEXTTYPEs into paths so we don't mix TEXTTYPEs with normal paths.
+*/
+       if (p1->type == TEXTTYPE) {
+               if (p2->type != TEXTTYPE && !ISLOCATION(p2))
+                       p1 = CoerceText(p1);
+       }
+       else {
+               if (p2->type == TEXTTYPE) {
+                       if (ISLOCATION(p1)) {
+                               p2->dest.x += p1->dest.x;
+                               p2->dest.y += p1->dest.y;
+                               Free(p1);
+                               return(p2);
+                       }
+                       else
+                               p2 = CoerceText(p2);
+               }
+       }
+/*
+Thank God!  Finally!  It's hard to believe, but we are now able to
+actually do the join.  This is just invoking the CONCAT macro:
+*/
+       CONCAT(p1, p2);
+       return(p1);
+}
+/*
+:h3.JoinSegment() - Create a Path Segment and Join It to a Known Path
+This internal function is quicker than a full-fledged join because
+it can do much less checking.
+*/
+struct segment *t1_JoinSegment(before, type, x, y, after)
+       register struct segment *before;  /* path to join before new segment  */
+       int type;             /* type of new segment (MOVETYPE or LINETYPE)   */
+       fractpel x,y;         /* x,y of new segment                           */
+       register struct segment *after;  /* path to join after new segment    */
+{
+       register struct segment *r;  /* returned path built here              */
+       r = PathSegment(type, x, y);
+       if (before != NULL) {
+               CONCAT(before, r);
+               r = before;
+       }
+       else
+               r->context = after->context;
+       if (after != NULL)
+               CONCAT(r, after);
+       return(r);
+}
+/*
+:h2.Other Path Functions
+*/
+struct segment *t1_ClosePath(p0,lastonly)
+       register struct segment *p0;  /* path to close                        */
+       register int lastonly;  /*  flag deciding to close all subpaths or... */
+{
+       register struct segment *p,*last,*start;  /* used in looping through path */
+       register fractpel x,y;  /* current position in path                   */
+       register fractpel firstx,firsty;  /* start position of sub path       */
+       register struct segment *lastnonhint;  /* last non-hint segment in path */
+       IfTrace1((MustTraceCalls),"ClosePath(%z)\n", p0);
+       if (p0 != NULL && p0->type == TEXTTYPE)
+               return(UniquePath(p0));
+       if (p0->type == STROKEPATHTYPE)
+               return((struct segment *)Unique(p0));
+       /*
+       * NOTE: a null closed path is different from a null open path
+       * and is denoted by a closed (0,0) move segment.  We make
+       * sure this path begins and ends with a MOVETYPE:
+       */
+       if (p0 == NULL || p0->type != MOVETYPE)
+               p0 = JoinSegment(NULL, MOVETYPE, 0, 0, p0);
+       TYPECHECK("ClosePath", p0, MOVETYPE, NULL, (0), struct segment *);
+       if (p0->last->type != MOVETYPE)
+               p0 = JoinSegment(p0, MOVETYPE, 0, 0, NULL);
+       p0 = UniquePath(p0);
+/*
+We now begin a loop through the path,
+incrementing current 'x' and 'y'.  We are searching
+for MOVETYPE segments (breaks in the path) that are not already closed.
+At each break, we insert a close segment.
+*/
+       for (p = p0, x = y = 0, start = NULL;
+            p != NULL;
+            x += p->dest.x, y += p->dest.y, last = p, p = p->link)
+       {
+               if (p->type == MOVETYPE) {
+                       if (start != NULL && (lastonly?p->link==NULL:TRUE) &&
+                             !(ISCLOSED(start->flag) && LASTCLOSED(last->flag))) {
+                               register struct segment *r;  /* newly created */
+                               start->flag |= ISCLOSED(ON);
+                               r = PathSegment(LINETYPE, firstx - x,
+                                                         firsty - y);
+                               INSERT(last, r, p);
+                               r->flag |= LASTCLOSED(ON);
+                               /*< adjust 'last' if possible for a 0,0 close >*/
+{
+#define   CLOSEFUDGE    3    /* if we are this close, let's change last segment */
+       if (r->dest.x != 0 || r->dest.y != 0) {
+               if (r->dest.x <= CLOSEFUDGE && r->dest.x >= -CLOSEFUDGE
+                    && r->dest.y <= CLOSEFUDGE && r->dest.y >= -CLOSEFUDGE) {
+                       IfTrace2((PathDebug),
+                               "ClosePath forced closed by (%p,%p)\n",
+                                      r->dest.x, r->dest.y);
+                       lastnonhint->dest.x += r->dest.x;
+                       lastnonhint->dest.y += r->dest.y;
+                       r->dest.x = r->dest.y = 0;
+               }
+       }
+}
+                               if (p->link != NULL) {
+                                       p->dest.x += x - firstx;
+                                       p->dest.y += y - firsty;
+                                       x = firstx;
+                                       y = firsty;
+                               }
+                       }
+                       start = p;
+                       firstx = x + p->dest.x;
+                       firsty = y + p->dest.y;
+               }
+               else if (p->type != HINTTYPE)
+                       lastnonhint = p;
+       }
+       return(p0);
+}
+/*
+*/
+/*
+:h2.Reversing the Direction of a Path
+This turned out to be more difficult than I thought at first.  The
+trickiness was due to the fact that closed paths must remain closed,
+etc.
+We need three subroutines:
+*/
+static struct segment *SplitPath(); /* break a path at any point             */
+static struct segment *DropSubPath();  /* breaks a path after first sub-path */
+static struct segment *ReverseSubPath();  /* reverses a single sub-path      */
+/*
+:h3.Reverse() - User Operator to Reverse a Path
+This operator reverses the entire path.
+*/
+struct segment *Reverse(p)
+       register struct segment *p;    /* full path to reverse                */
+{
+       register struct segment *r;    /* output path built here              */
+       register struct segment *nextp;  /* contains next sub-path            */
+       IfTrace1((MustTraceCalls),"Reverse(%z)\n", p);
+       if (p == NULL)
+               return(NULL);
+       ARGCHECK(!ISPATHANCHOR(p), "Reverse: invalid path", p, NULL, (0), struct segment *);
+       if (p->type == TEXTTYPE)
+               p = CoerceText(p);
+       p = UniquePath(p);
+       r = NULL;
+       do {
+               nextp = DropSubPath(p);
+               p = ReverseSubPath(p);
+               r = Join(p, r);
+               p = nextp;
+       } while (p != NULL);
+       return(r);
+}
+/*
+:h4.ReverseSubPath() - Subroutine to Reverse a Single Sub-Path
+*/
+static struct segment *ReverseSubPath(p)
+       register struct segment *p;  /* input path                            */
+{
+       register struct segment *r;  /* reversed path will be created here    */
+       register struct segment *nextp;  /* temporary variable used in loop   */
+       register int wasclosed;  /* flag, path was closed                     */
+       if (p == NULL)
+               return(NULL);
+       wasclosed = ISCLOSED(p->flag);
+       r = NULL;
+       do {
+/*
+First we reverse the direction of this segment and clean up its flags:
+*/
+               p->dest.x = - p->dest.x;  p->dest.y = - p->dest.y;
+               p->flag &= ~(ISCLOSED(ON) | LASTCLOSED(ON));
+               switch (p->type) {
+                   case LINETYPE:
+                   case MOVETYPE:
+                       break;
+                   case CONICTYPE:
+                   {
+/*
+The logic of this is that the new M point (stored relative to the new
+beginning) is (M - C).  However, C ("dest") has already been reversed
+So, we add "dest" instead of subtracting it:
+*/
+                       register struct conicsegment *cp = (struct conicsegment *) p;
+                       cp->M.x += cp->dest.x;  cp->M.y += cp->dest.y;
+                   }
+                       break;
+                   case BEZIERTYPE:
+                   {
+                       register struct beziersegment *bp = (struct beziersegment *) p;
+                       bp->B.x += bp->dest.x;  bp->B.y += bp->dest.y;
+                       bp->C.x += bp->dest.x;  bp->C.y += bp->dest.y;
+                   }
+                       break;
+                   case HINTTYPE:
+                   {
+                       register struct hintsegment *hp = (struct hintsegment *) p;
+                       hp->ref.x = -hp->ref.x;  hp->ref.y = -hp->ref.y;
+                   }
+                       break;
+                   default:
+                       abort("Reverse: bad path segment");
+               }
+/*
+We need to reverse the order of segments too, so we break this segment
+off of the input path, and tack it on the front of the growing path
+in 'r':
+*/
+               nextp = p->link;
+               p->link = NULL;
+               p->last = p;
+               if (r != NULL)
+                       CONCAT(p,r);  /* leaves result in 'p'... not what we want */
+               r = p;
+               p = nextp;    /* advance to next segment in input path        */
+       } while (p != NULL);
+       if (wasclosed)
+               r = ClosePath(r);
+       return(r);
+}
+/*
+:h4.DropSubPath() - Drops the First Sub-Path Off a Path
+This subroutine returns the remaining sub-path(s).  While doing so, it
+breaks the input path after the first sub-path so that a pointer to
+the original path now contains the first sub-path only.
+*/
+static struct segment *DropSubPath(p0)
+       register struct segment *p0;  /* original path                        */
+{
+       register struct segment *p;  /* returned remainder here               */
+       for (p = p0; p->link != NULL; p = p->link) {
+               if (p->link->type == MOVETYPE)
+                       break;
+       }
+       return(SplitPath(p0, p));
+}
+static struct segment *SplitPath(anchor, before)
+       register struct segment *anchor;
+       register struct segment *before;
+{
+       register struct segment *r;
+       if (before == anchor->last)
+               return(NULL);
+       r = before->link;
+       r->last = anchor->last;
+       anchor->last = before;
+       before->link = NULL;
+       return(r);
+}
+/*
+:h3.ReverseSubPaths() - Reverse the Direction of Sub-paths Within a Path
+This user operator reverses the sub-paths in a path, but leaves the
+'move' segments unchanged.  It builds on top of the subroutines
+already established.
+*/
+struct segment *ReverseSubPaths(p)
+       register struct segment *p;  /* input path                            */
+{
+       register struct segment *r;  /* reversed path will be created here    */
+       register struct segment *nextp;  /* temporary variable used in loop   */
+       int wasclosed;        /* flag; subpath was closed                     */
+       register struct segment *nomove;  /* the part of sub-path without move segment */
+       struct fractpoint delta;
+       IfTrace1((MustTraceCalls),"ReverseSubPaths(%z)\n", p);
+       if (p == NULL)
+               return(NULL);
+       ARGCHECK(!ISPATHANCHOR(p), "ReverseSubPaths: invalid path", p, NULL, (0), struct segment *);
+       if (p->type == TEXTTYPE)
+               p = CoerceText(p);
+       if (p->type != MOVETYPE)
+               p = JoinSegment(NULL, MOVETYPE, 0, 0, p);
+       p = UniquePath(p);
+       r = NULL;
+       for (; p != NULL;) {
+               nextp = DropSubPath(p);
+               wasclosed = ISCLOSED(p->flag);
+               if (wasclosed)
+                       UnClose(p);
+               nomove = SplitPath(p, p);
+               r = Join(r, p);
+               PathDelta(nomove, &delta);
+               nomove = ReverseSubPath(nomove);
+               p->dest.x += delta.x;
+               p->dest.y += delta.y;
+               if (nextp != NULL) {
+                       nextp->dest.x += delta.x;
+                       nextp->dest.y += delta.y;
+               }
+               if (wasclosed) {
+                       nomove = ClosePath(nomove);
+                       nextp->dest.x -= delta.x;
+                       nextp->dest.y -= delta.y;
+               }
+               r = Join(r, nomove);
+               p = nextp;
+       }
+       return(r);
+}
+static UnClose(p0)
+       register struct segment *p0;
+{
+       register struct segment *p;
+       for (p=p0; p->link->link != NULL; p=p->link) { ; }
+       if (!LASTCLOSED(p->link->flag))
+               abort("UnClose:  no LASTCLOSED");
+       Free(SplitPath(p0, p));
+       p0->flag &= ~ISCLOSED(ON);
+}
+/*
+:h2.Transforming and Putting Handles on Paths
+:h3.PathTransform() - Transform a Path
+Transforming a path involves transforming all the points.  In order
+that closed paths do not become "unclosed" when their relative
+positions are slightly changed due to loss of arithmetic precision,
+all point transformations are in absolute coordinates.
+(It might be better to reset the "absolute" coordinates every time a
+move segment is encountered.  This would mean that we could accumulate
+error from subpath to subpath, but we would be less likely to make
+the "big error" where our fixed point arithmetic "wraps".  However, I
+think I'll keep it this way until something happens to convince me
+otherwise.)
+The transform is described as a "space", that way we can use our
+old friend the "iconvert" function, which should be very efficient.
+*/
+struct segment *PathTransform(p0, S)
+       register struct segment *p0;    /* path to transform                  */
+       register struct XYspace *S;     /* pseudo space to transform in       */
+{
+       register struct segment *p;   /* to loop through path with            */
+       register fractpel newx,newy;  /* current transformed position in path */
+       register fractpel oldx,oldy;  /* current untransformed position in path */
+       register fractpel savex,savey;  /* save path delta x,y                */
+       p0 = UniquePath(p0);
+       newx = newy = oldx = oldy = 0;
+       for (p=p0; p != NULL; p=p->link) {
+               savex = p->dest.x;   savey = p->dest.y;
+               (*S->iconvert)(&p->dest, S, p->dest.x + oldx, p->dest.y + oldy);
+               p->dest.x -= newx;
+               p->dest.y -= newy;
+               switch (p->type) {
+                   case LINETYPE:
+                   case MOVETYPE:
+                       break;
+                   case CONICTYPE:
+                   {
+                       register struct conicsegment *cp = (struct conicsegment *) p;
+                       (*S->iconvert)(&cp->M, S, cp->M.x + oldx, cp->M.y + oldy);
+                       cp->M.x -= newx;
+                       cp->M.y -= newy;
+                       /*
+                       * Note roundness doesn't change... linear transform
+                       */
+                       break;
+                   }
+                   case BEZIERTYPE:
+                   {
+                       register struct beziersegment *bp = (struct beziersegment *) p;
+                       (*S->iconvert)(&bp->B, S, bp->B.x + oldx, bp->B.y + oldy);
+                       bp->B.x -= newx;
+                       bp->B.y -= newy;
+                       (*S->iconvert)(&bp->C, S, bp->C.x + oldx, bp->C.y + oldy);
+                       bp->C.x -= newx;
+                       bp->C.y -= newy;
+                       break;
+                   }
+                   case HINTTYPE:
+                   {
+                       register struct hintsegment *hp = (struct hintsegment *) p;
+                       (*S->iconvert)(&hp->ref, S, hp->ref.x + oldx, hp->ref.y + oldy);
+                       hp->ref.x -= newx;
+                       hp->ref.y -= newy;
+                       (*S->iconvert)(&hp->width, S, hp->width.x, hp->width.y);
+                       /* Note: width is not relative to origin */
+                       break;
+                   }
+                   case TEXTTYPE:
+                   {
+                        XformText(p,S);
+                        break;
+                   }
+                   default:
+                       IfTrace1(TRUE,"path = %z\n", p);
+                       abort("PathTransform:  invalid segment");
+               }
+               oldx += savex;
+               oldy += savey;
+               newx += p->dest.x;
+               newy += p->dest.y;
+       }
+       return(p0);
+}
+/*
+:h3.PathDelta() - Return a Path's Ending Point
+*/
+void PathDelta(p, pt)
+       register struct segment *p; /* input path                             */
+       register struct fractpoint *pt; /* pointer to x,y to set              */
+{
+       struct fractpoint mypoint;  /* I pass this to TextDelta               */
+       register fractpel x,y;  /* working variables for path current point   */
+       for (x=y=0; p != NULL; p=p->link) {
+               x += p->dest.x;
+               y += p->dest.y;
+               if (p->type == TEXTTYPE) {
+                       TextDelta(p, &mypoint);
+                       x += mypoint.x;
+                       y += mypoint.y;
+               }
+       }
+       pt->x = x;
+       pt->y = y;
+}
+/*
+:h3.BoundingBox() - Produce a Bounding Box Path
+This function is called by image code, when we know the size of the
+image in pels, and need to get a bounding box path that surrounds it.
+The starting/ending handle is in the lower right hand corner.
+*/
+struct segment *BoundingBox(h, w)
+       register pel h,w;     /* size of box                                  */
+{
+       register struct segment *path;
+       path = PathSegment(LINETYPE, -TOFRACTPEL(w), 0);
+       path = JoinSegment(NULL, LINETYPE, 0, -TOFRACTPEL(h), path);
+       path = JoinSegment(NULL, LINETYPE, TOFRACTPEL(w), 0, path);
+       path = ClosePath(path);
+       return(path);
+}
+/*
+:h2.Querying Locations and Paths
+:h3.QueryLoc() - Return the X,Y of a Locition
+*/
+void QueryLoc(P, S, xP, yP)
+       register struct segment *P;  /* location to query, not consumed       */
+       register struct XYspace *S;  /* XY space to return coordinates in     */
+       register double *xP,*yP;  /* coordinates returned here                */
+{
+       IfTrace4((MustTraceCalls),"QueryLoc(P=%z, S=%z, (%x, %x))\n",
+                                            P, S, xP, yP);
+       if (!ISLOCATION(P)) {
+               ArgErr("QueryLoc: first arg not a location", P, NULL);
+               return;
+       }
+       if (S->type != SPACETYPE) {
+               ArgErr("QueryLoc: second arg not a space", S, NULL);
+               return;
+       }
+       UnConvert(S, &P->dest, xP, yP);
+}
+/*
+:h3.QueryPath() - Find Out the Type of Segment at the Head of a Path
+This is a very simple routine that looks at the first segment of a
+path and tells the caller what it is, as well as returning the control
+point(s) of the path segment.  Different path segments have different
+number of control points.  If the caller knows that the segment is
+a move segment, for example, he only needs to pass pointers to return
+one control point.
+*/
+void QueryPath(path, typeP, Bp, Cp, Dp, fP)
+       register struct segment *path;  /* path to check                      */
+       register int *typeP;  /* return the type of path here                 */
+       register struct segment **Bp;  /* return location of first point      */
+       register struct segment **Cp;  /* return location of second point     */
+       register struct segment **Dp;  /* return location of third point      */
+       register double *fP;  /* return Conic sharpness                       */
+{
+       register int coerced = FALSE;  /* did I coerce a text path?           */
+       IfTrace3((MustTraceCalls), "QueryPath(%z, %x, %x, ...)\n",
+                                             path, typeP, Bp);
+       if (path == NULL) {
+               *typeP = -1;
+               return;
+       }
+       if (!ISPATHANCHOR(path)) {
+               ArgErr("QueryPath: arg not a valid path", path, NULL);
+       }
+       if (path->type == TEXTTYPE) {
+               path = CoerceText(path);
+               coerced = TRUE;
+       }
+       switch (path->type) {
+           case MOVETYPE:
+               *typeP = 0;
+               *Bp = PathSegment(MOVETYPE, path->dest.x, path->dest.y);
+               break;
+           case LINETYPE:
+               *typeP = (LASTCLOSED(path->flag)) ? 4 : 1;
+               *Bp = PathSegment(MOVETYPE, path->dest.x, path->dest.y);
+               break;
+           case CONICTYPE:
+           {
+               register struct conicsegment *cp = (struct conicsegment *) path;
+               *typeP = 2;
+               *Bp = PathSegment(MOVETYPE, cp->M.x, cp->M.y);
+               *Cp = PathSegment(MOVETYPE, cp->dest.x, cp->dest.y);
+               *fP = cp->roundness;
+           }
+               break;
+           case BEZIERTYPE:
+           {
+               register struct beziersegment *bp = (struct beziersegment *) path;
+               *typeP = 3;
+               *Bp = PathSegment(MOVETYPE, bp->B.x, bp->B.y);
+               *Cp = PathSegment(MOVETYPE, bp->C.x, bp->C.y);
+               *Dp = PathSegment(MOVETYPE, bp->dest.x, bp->dest.y);
+           }
+               break;
+           case HINTTYPE:
+               *typeP = 5;
+               break;
+           default:
+               abort("QueryPath: unknown segment");
+       }
+       if (coerced)
+               KillPath(path);
+}
+/*
+:h3.QueryBounds() - Return the Bounding Box of a Path
+Returns the bounding box by setting the user's variables.
+*/
+void QueryBounds(p0, S, xminP, yminP, xmaxP, ymaxP)
+       register struct segment *p0;  /* object to check for bound            */
+       struct XYspace *S;    /* coordinate space of returned values          */
+       double *xminP,*yminP; /* lower left hand corner (set by routine)      */
+       double *xmaxP,*ymaxP; /* upper right hand corner (set by routine)     */
+{
+       register struct segment *path;  /* loop variable for path segments    */
+       register fractpel lastx,lasty;  /* loop variables:  previous endingpoint */
+       register fractpel x,y;  /* loop variables:  current ending point      */
+       struct fractpoint min;  /* registers to keep lower left hand corner   */
+       struct fractpoint max;  /* registers to keep upper right hand corner  */
+       int coerced = FALSE;  /* we have coerced the path from another object */
+       double x1,y1,x2,y2,x3,y3,x4,y4;  /* corners of rectangle in space X   */
+       IfTrace2((MustTraceCalls), "QueryBounds(%z, %z,", p0, S);
+       IfTrace4((MustTraceCalls), " %x, %x, %x, %x)\n",
+                                  xminP, yminP, xmaxP, ymaxP);
+       if (S->type != SPACETYPE) {
+               ArgErr("QueryBounds:  bad XYspace", S, NULL);
+               return;
+       }
+       min.x = min.y = max.x = max.y = 0;
+       if (p0 != NULL) {
+               if (!ISPATHANCHOR(p0)) {
+                       switch(p0->type) {
+                           case STROKEPATHTYPE:
+      /* replaced DupStrokePath() with Dup() 3-26-91 PNM */
+                               p0 = (struct segment *) DoStroke(Dup(p0));
+                               /* no break here, we have a region in p0 */
+                           case REGIONTYPE:
+                               p0 = RegionBounds(p0);
+                               break;
+                           case PICTURETYPE:
+                               p0 = PictureBounds(p0);
+                               break;
+                           default:
+                               ArgErr("QueryBounds:  bad object", p0, NULL);
+                               return;
+                       }
+                       coerced = TRUE;
+               }
+               if (p0->type == TEXTTYPE) {
+    /* replaced CopyPath() with Dup() 3-26-91 PNM */
+                       p0 = (struct segment *)CoerceText(Dup(p0));  /* there are faster ways */
+                       coerced = TRUE;
+               }
+               if (p0->type == MOVETYPE) {
+                       min.x = max.x = p0->dest.x;
+                       min.y = max.y = p0->dest.y;
+               }
+       }
+       lastx = lasty = 0;
+       for (path = p0; path != NULL; path = path->link) {
+               x = lastx + path->dest.x;
+               y = lasty + path->dest.y;
+               switch (path->type) {
+                   case LINETYPE:
+                       break;
+                   case CONICTYPE:
+                   {
+                       register struct conicsegment *cp = (struct conicsegment *) path;
+                       register fractpel Mx = lastx + cp->M.x;
+                       register fractpel My = lasty + cp->M.y;
+                       register fractpel deltax = 0.5 * cp->roundness * cp->dest.x;
+                       register fractpel deltay = 0.5 * cp->roundness * cp->dest.y;
+                       register fractpel Px = Mx - deltax;
+                       register fractpel Py = My - deltay;
+                       register fractpel Qx = Mx + deltax;
+                       register fractpel Qy = My + deltay;
+                       if (Mx < min.x) min.x = Mx;
+                       else if (Mx > max.x) max.x = Mx;
+                       if (My < min.y) min.y = My;
+                       else if (My > max.y) max.y = My;
+                       if (Px < min.x) min.x = Px;
+                       else if (Px > max.x) max.x = Px;
+                       if (Py < min.y) min.y = Py;
+                       else if (Py > max.y) max.y = Py;
+                       if (Qx < min.x) min.x = Qx;
+                       else if (Qx > max.x) max.x = Qx;
+                       if (Qy < min.y) min.y = Qy;
+                       else if (Qy > max.y) max.y = Qy;
+                   }
+                       break;
+                   case MOVETYPE:
+                       /*
+                       * We can't risk adding trailing Moves to the
+                       * bounding box:
+                       */
+                       if (path->link == NULL)
+                               goto done;  /* God forgive me                 */
+                       break;
+                   case BEZIERTYPE:
+                   {
+                       register struct beziersegment *bp = (struct beziersegment *) path;
+                       register fractpel Bx = lastx + bp->B.x;
+                       register fractpel By = lasty + bp->B.y;
+                       register fractpel Cx = lastx + bp->C.x;
+                       register fractpel Cy = lasty + bp->C.y;
+                       if (Bx < min.x) min.x = Bx;
+                       else if (Bx > max.x) max.x = Bx;
+                       if (By < min.y) min.y = By;
+                       else if (By > max.y) max.y = By;
+                       if (Cx < min.x) min.x = Cx;
+                       else if (Cx > max.x) max.x = Cx;
+                       if (Cy < min.y) min.y = Cy;
+                       else if (Cy > max.y) max.y = Cy;
+                   }
+                       break;
+                   case HINTTYPE:
+                       break;
+                   default:
+                       abort("QueryBounds: unknown type");
+               }
+               if (x < min.x) min.x = x;
+               else if (x > max.x) max.x = x;
+               if (y < min.y) min.y = y;
+               else if (y > max.y) max.y = y;
+               lastx = x;   lasty = y;
+       }
+done:
+       UnConvert(S, &min, &x1, &y1);
+       UnConvert(S, &max, &x4, &y4);
+       x = min.x;  min.x = max.x; max.x = x;
+       UnConvert(S, &min, &x2, &y2);
+       UnConvert(S, &max, &x3, &y3);
+       *xminP = *xmaxP = x1;
+       if (x2 < *xminP)  *xminP = x2;
+       else if (x2 > *xmaxP)  *xmaxP = x2;
+       if (x3 < *xminP)  *xminP = x3;
+       else if (x3 > *xmaxP)  *xmaxP = x3;
+       if (x4 < *xminP)  *xminP = x4;
+       else if (x4 > *xmaxP)  *xmaxP = x4;
+       *yminP = *ymaxP = y1;
+       if (y2 < *yminP)  *yminP = y2;
+       else if (y2 > *ymaxP)  *ymaxP = y2;
+       if (y3 < *yminP)  *yminP = y3;
+       else if (y3 > *ymaxP)  *ymaxP = y3;
+       if (y4 < *yminP)  *yminP = y4;
+       else if (y4 > *ymaxP)  *ymaxP = y4;
+       if (coerced)
+               Destroy(p0);
+}
+/*
+:h3.BoxPath()
+*/
+struct segment *BoxPath(S, h, w)
+       struct XYspace *S;
+       int h,w;
+{
+       struct segment *path;
+       path = Join( Line(ILoc(S, w, 0)), Line(ILoc(S, 0, h)) );
+       path = JoinSegment(path, LINETYPE, -path->dest.x, -path->dest.y, NULL);
+       return(ClosePath(path));
+}
+/*
+:h3.DropSegment() - Drop the First Segment in a Path
+This routine takes the path and returns a new path that is one segment
+shorter.  It can be used in conjunction with QueryPath(), for example,
+to ask about an entire path.
+*/
+struct segment *DropSegment(path)
+       register struct segment *path;
+{
+       IfTrace1((MustTraceCalls),"DropSegment(%z)\n", path);
+       if (path != NULL && path->type == STROKEPATHTYPE)
+               path = CoercePath(path);
+       ARGCHECK((path == NULL || !ISPATHANCHOR(path)),
+                 "DropSegment: arg not a non-null path", path, path, (0), struct segment *);
+       if (path->type == TEXTTYPE)
+               path = CoerceText(path);
+       path = UniquePath(path);
+       POP(path);
+       return(path);
+}
+/*
+:h3.HeadSegment() - Return the First Segment in a Path
+This routine takes the path and returns a new path consists of the
+first segment only.
+*/
+struct segment *HeadSegment(path)
+       register struct segment *path;  /* input path                         */
+{
+       IfTrace1((MustTraceCalls),"HeadSegment(%z)\n", path);
+       if (path == NULL)
+               return(NULL);
+       if (path->type == STROKEPATHTYPE)
+               path = CoercePath(path);
+       ARGCHECK(!ISPATHANCHOR(path), "HeadSegment: arg not a path", path, path, (0), struct segment *);
+       if (path->type == TEXTTYPE)
+               path = CoerceText(path);
+       path = UniquePath(path);
+       if (path->link != NULL)
+               KillPath(path->link);
+       path->link = NULL;
+       path->last = path;
+       return(path);
+}
+/*
+:h2.Path Debug Routines
+:h3.DumpPath() - Display a Path on the Trace File
+*/
+void DumpPath(p)
+       register struct segment *p;
+{
+       register fractpel x,y;
+       register fractpel lastx,lasty;
+       double roundness;
+       IfTrace1(TRUE,"Dumping path, anchor=%x:\n", p);
+       lastx = lasty = 0;
+       for (;p != NULL; p=p->link) {
+               IfTrace0(TRUE,". ");
+               x = p->dest.x;
+               y = p->dest.y;
+               switch (p->type) {
+                   case LINETYPE:
+                       IfTrace1(TRUE,". line<%x> to", (long) p->flag);
+                       IfTrace4(TRUE," (%p,%p), delta=(%p,%p)",
+                                 x + lastx, y + lasty, x, y);
+                       break;
+                   case MOVETYPE:
+                       IfTrace1(TRUE,"MOVE<%x> to", (long) p->flag);
+                       IfTrace4(TRUE,"(%p,%p), delta=(%p,%p)",
+                                 x + lastx, y + lasty, x, y);
+                       break;
+                   case CONICTYPE:
+                   {
+                       register struct conicsegment *cp = (struct conicsegment *) p;
+                       roundness = cp->roundness;
+                       IfTrace2(TRUE, ". conic to (%p,%p),",
+                                                  x + lastx, y + lasty);
+                       IfTrace3(TRUE," M=(%p,%p), r=%f", cp->M.x + lastx,
+                                                   cp->M.y + lasty, &roundness);
+                   }
+                       break;
+                   case BEZIERTYPE:
+                   {
+                       register struct beziersegment *bp = (struct beziersegment *) p;
+                       IfTrace4(TRUE,". bezier to (%p,%p), B=(%p,%p)",
+                                       x + lastx, y + lasty,
+                                       bp->B.x + lastx, bp->B.y + lasty);
+                       IfTrace2(TRUE, ", C=(%p,%p)",
+                                       bp->C.x + lastx, bp->C.y + lasty);
+                   }
+                       break;
+                   case HINTTYPE:
+                   {
+                       register struct hintsegment *hp = (struct hintsegment *) p;
+                       IfTrace4(TRUE,". hint ref=(%p,%p), width=(%p,%p)",
+                                       hp->ref.x + lastx, hp->ref.y + lasty,
+                                       hp->width.x, hp->width.y);
+                       IfTrace4(TRUE, ", %c %c %c %c",
+                                       hp->orientation, hp->hinttype,
+                                       hp->adjusttype, hp->direction);
+                       IfTrace1(TRUE, ", %ld", (long) hp->label);
+                   }
+                       break;
+                   case TEXTTYPE:
+                       DumpText(p);
+                       break;
+                   default:
+                       IfTrace0(TRUE, "bad path segment?");
+               }
+               IfTrace1(TRUE," at %x\n", p);
+               lastx += x;
+               lasty += y;
+       }
+}
diff --git a/Xserver/lib/font/Type1/paths.h b/Xserver/lib/font/Type1/paths.h
new file mode 100644 (file)
index 0000000..e1af719
--- /dev/null
@@ -0,0 +1,197 @@
+/* $XConsortium: paths.h,v 1.2 91/10/10 11:18:50 rws Exp $ */
+/* Copyright International Business Machines, Corp. 1991
+ * All Rights Reserved
+ * Copyright Lexmark International, Inc. 1991
+ * All Rights Reserved
+ *
+ * License to use, copy, modify, and distribute this software and its
+ * documentation for any purpose and without fee is hereby granted,
+ * provided that the above copyright notice appear in all copies and that
+ * both that copyright notice and this permission notice appear in
+ * supporting documentation, and that the name of IBM or Lexmark not be
+ * used in advertising or publicity pertaining to distribution of the
+ * software without specific, written prior permission.
+ *
+ * IBM AND LEXMARK PROVIDE THIS SOFTWARE "AS IS", WITHOUT ANY WARRANTIES OF
+ * ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING, BUT NOT LIMITED TO ANY
+ * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE,
+ * AND NONINFRINGEMENT OF THIRD PARTY RIGHTS.  THE ENTIRE RISK AS TO THE
+ * QUALITY AND PERFORMANCE OF THE SOFTWARE, INCLUDING ANY DUTY TO SUPPORT
+ * OR MAINTAIN, BELONGS TO THE LICENSEE.  SHOULD ANY PORTION OF THE
+ * SOFTWARE PROVE DEFECTIVE, THE LICENSEE (NOT IBM OR LEXMARK) ASSUMES THE
+ * ENTIRE COST OF ALL SERVICING, REPAIR AND CORRECTION.  IN NO EVENT SHALL
+ * IBM OR LEXMARK BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
+ * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
+ * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
+ * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
+ * THIS SOFTWARE.
+ */
+/*SHARED*/
+#define   Loc(S,x,y)                   t1_Loc(S,(double)x,(double)y)
+#define   ILoc(S,x,y)                  t1_ILoc(S,x,y)
+#define   Line(P)                      t1_Line(P)
+#define   Join(p1,p2)                  t1_Join(p1,p2)
+#define   ClosePath(p)                 t1_ClosePath(p,0)
+#define   CloseLastSubPath(p)          t1_ClosePath(p,1)
+#define   Conic(B,C,s)                 t1_Conic(B,C,(double)s)
+#define   RoundConic(M,C,r)            t1_RoundConic(M,C,(double)r)
+#define   ArcP3(S,P2,P3)               t1_ArcP3(S,P2,P3)
+#define   ArcCA(S,C,d)                 t1_ArcCA(S,C,(double)d)
+#define   Bezier(B,C,D)                t1_Bezier(B,C,D)
+#define   Hint(S,r,w,o,h,a,d,l)        t1_Hint(S,r,w,o,h,a,d,l)
+#define   Reverse(p)                   t1_Reverse(p)
+#define   ReverseSubPaths(p)           t1_ReverseSubPaths(p)
+#define   AddLoc(p1,p2)                t1_Join(p1,p2)
+#define   SubLoc(p1,p2)                t1_SubLoc(p1,p2)
+#define   DropSegment(p)               t1_DropSegment(p)
+#define   HeadSegment(p)               t1_HeadSegment(p)
+#define   QueryLoc(P,S,x,y)            t1_QueryLoc(P,S,x,y)
+#define   QueryPath(p,t,B,C,D,r)       t1_QueryPath(p,t,B,C,D,r)
+#define   QueryBounds(p,S,x1,y1,x2,y2)  t1_QueryBounds(p,S,x1,y1,x2,y2)
+struct segment *t1_Loc();     /* create a location object (or "move" segment) */
+struct segment *t1_ILoc();    /* integer argument version of same             */
+struct segment *t1_Line();    /* straight line path segment                   */
+struct segment *t1_Join();    /* join two paths or regions together           */
+struct segment *t1_ClosePath();  /* close a path or path set                  */
+struct conicsegment *t1_Conic();  /* conic curve path segment                 */
+struct conicsegment *t1_RoundConic();  /* ditto, specified another way        */
+struct conicsegment *t1_ArcP3(); /* circular path segment with three points   */
+struct conicsegment *t1_ArcCA(); /* ditto, with center point and angle        */
+struct beziersegment *t1_Bezier();  /* Bezier third order curve path segment  */
+struct hintsegment *t1_Hint();  /* produce a font 'hint' path segment         */
+struct segment *t1_Reverse(); /* reverse the complete order of paths          */
+struct segment *t1_ReverseSubPaths();  /* reverse only sub-paths; moves unchanged */
+struct segment *t1_SubLoc();  /* subtract two location objects                */
+struct segment *t1_DropSegment();  /* Drop the first segment in a path        */
+struct segment *t1_HeadSegment();  /* return the first segment in a path      */
+void t1_QueryLoc();           /* Query location; return its (x,y)             */
+void t1_QueryPath();          /* Query segment at head of a path              */
+void t1_QueryBounds();        /* Query the bounding box of a path             */
+/*END SHARED*/
+/*SHARED*/
+#define   CopyPath(p)             t1_CopyPath(p)
+#define   KillPath(p)             t1_KillPath(p)
+#define   PathTransform(p,m)      t1_PathXform(p,m)
+#define   PathDelta(p,pt)         t1_PathDelta(p,pt)
+#define   BoundingBox(h,w)        t1_BoundingBox(h,w)
+#define   PathSegment(t,x,y)      t1_PathSegment(t,(fractpel)x,(fractpel)y)
+#define   JoinSegment(b,t,x,y,a)  t1_JoinSegment(b,t,(fractpel)x,(fractpel)y,a)
+#define   Hypoteneuse(dx,dy)      t1_Hypoteneuse(dx,dy)
+#define   BoxPath(S,h,w)          t1_BoxPath(S,h,w)
+struct segment *t1_CopyPath(); /* duplicate a path                            */
+void t1_KillPath();           /* destroy a path                               */
+struct segment *t1_PathXform();  /* transform a path arbitrarily              */
+void t1_PathDelta();          /* calculate the ending point of a path         */
+struct segment *t1_PathSegment(); /* produce a MOVE or LINE segment           */
+struct segment *t1_JoinSegment(); /* join a MOVE or LINE segment to a path    */
+double t1_Hypoteneuse();      /* returns the length of a line                 */
+struct segment *t1_BoxPath();   /* returns a rectangular path                 */
+/*END SHARED*/
+/*SHARED*/
+#define    ConsumePath(p)    MAKECONSUME(p,KillPath(p))
+#define    UniquePath(p)     MAKEUNIQUE(p,CopyPath(p))
+/*END SHARED*/
+/*SHARED*/
+struct segment {
+       XOBJ_COMMON     /* xobject common data define 3-26-91 PNM             */
+       unsigned char size;   /* size of the structure                        */
+       unsigned char context;  /* index to device context                    */
+       struct segment *link; /* pointer to next structure in linked list     */
+       struct segment *last; /* pointer to last structure in list            */
+       struct fractpoint dest; /* relative ending location of path segment   */
+} ;
+#define   ISCLOSED(flag)   ((flag)&0x80)  /* subpath is closed               */
+#define   LASTCLOSED(flag) ((flag)&0x40)  /* last segment in closed subpath  */
+/*
+NOTE: The ISCLOSED flag is set on the MOVETYPE segment before the
+subpath proper; the LASTCLOSED flag is set on the last segment (LINETYPE)
+in the subpath
+We define the ISPATHANCHOR predicate to test that a path handle
+passed by the user is valid:
+*/
+#define   ISPATHANCHOR(p)  (ISPATHTYPE(p->type)&&p->last!=NULL)
+/*
+For performance reasons, a user's "location" object is identical to
+a path whose only segment is a move segment.  We define a predicate
+to test for this case.  See also :hdref refid=location..
+*/
+#define   ISLOCATION(p)    ((p)->type == MOVETYPE && (p)->link == NULL)
+/*END SHARED*/
+/*SHARED*/
+struct conicsegment {
+       XOBJ_COMMON          /* xobject common data define 3-26-91 PNM        */
+                            /* type = CONICTYPE                                     */
+       unsigned char size;   /* as with any 'segment' type                   */
+       unsigned char context;  /* as with any 'segment' type                 */
+       struct segment *link; /* as with any 'segment' type                   */
+       struct segment *last; /* as with any 'segment' type                   */
+       struct fractpoint dest;  /* Ending point (C point)                    */
+       struct fractpoint M;  /* "midpoint" of conic explained above          */
+       float roundness;      /* explained above                              */
+} ;
+/*END SHARED*/
+/*SHARED*/
+struct beziersegment {
+       XOBJ_COMMON           /* xobject common data define 3-26-91 PNM       */
+                            /* type = BEZIERTYPE                            */
+       unsigned char size;   /* as with any 'segment' type                   */
+       unsigned char context;  /* as with any 'segment' type                 */
+       struct segment *link; /* as with any 'segment' type                   */
+       struct segment *last; /* as with any 'segment' type                   */
+       struct fractpoint dest;  /* ending point (D)                          */
+       struct fractpoint B;  /* control point B                              */
+       struct fractpoint C;  /* control point C                              */
+} ;
+/*END SHARED*/
+/*SHARED*/
+struct hintsegment {
+       XOBJ_COMMON            /* xobject common data define 3-26-91 PNM      */
+                              /* type = HINTTYPE                            */
+       unsigned char size;   /* size of the structure                        */
+       unsigned char context;  /* device context                             */
+       struct segment *link; /* pointer to next structure in linked list     */
+       struct segment *last; /* pointer to last structure in list            */
+       struct fractpoint dest; /* ALWAYS 0,0                                 */
+       struct fractpoint ref;
+       struct fractpoint width;
+       char orientation;
+       char hinttype;
+       char adjusttype;
+       char direction;
+       int label;
+} ;
+/*END SHARED*/
+/*SHARED*/
+/*
+CONCAT links the 'p2' path chain on the end of the 'p1' chain.  (This macro
+is also used by the STROKES module.)
+*/
+#define  CONCAT(p1, p2)  { \
+       p1->last->link = p2;     /* link p2 on end of p1                      */ \
+       p1->last = p2->last;    /* last of new is last of p2                  */ \
+       p2->last = NULL; }    /* only first segment has non-NULL "last"       */
+/*END SHARED*/
diff --git a/Xserver/lib/font/Type1/pictures.h b/Xserver/lib/font/Type1/pictures.h
new file mode 100644 (file)
index 0000000..69ecf0a
--- /dev/null
@@ -0,0 +1,48 @@
+/* $XConsortium: pictures.h,v 1.2 91/10/10 11:18:53 rws Exp $ */
+/* Copyright International Business Machines,Corp. 1991
+ * All Rights Reserved
+ *
+ * License to use, copy, modify, and distribute this software
+ * and its documentation for any purpose and without fee is
+ * hereby granted, provided that the above copyright notice
+ * appear in all copies and that both that copyright notice and
+ * this permission notice appear in supporting documentation,
+ * and that the name of IBM not be used in advertising or
+ * publicity pertaining to distribution of the software without
+ * specific, written prior permission.
+ *
+ * IBM PROVIDES THIS SOFTWARE "AS IS", WITHOUT ANY WARRANTIES
+ * OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING, BUT NOT
+ * LIMITED TO ANY IMPLIED WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, AND NONINFRINGEMENT OF
+ * THIRD PARTY RIGHTS.  THE ENTIRE RISK AS TO THE QUALITY AND
+ * PERFORMANCE OF THE SOFTWARE, INCLUDING ANY DUTY TO SUPPORT
+ * OR MAINTAIN, BELONGS TO THE LICENSEE.  SHOULD ANY PORTION OF
+ * THE SOFTWARE PROVE DEFECTIVE, THE LICENSEE (NOT IBM) ASSUMES
+ * THE ENTIRE COST OF ALL SERVICING, REPAIR AND CORRECTION.  IN
+ * NO EVENT SHALL IBM BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
+ * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
+ * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
+ * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+ */
+/* STUB */
+#define    CopyPicture(p)         p
+#define    UniquePicture(p)       p
+#define    KillPicture(p)
+#define    BegHandle(o,m)         o
+#define    EndHandle(o,m)         o
+#define    PictureBounds(P)       P
+struct picture {
+       struct fractpoint origin;
+       struct fractpoint ending;
+};
+#define    Phantom(o)             t1_Phantom(o)
+#define    Snap(o)                t1_Snap(o)
+struct segment *t1_Phantom();
+struct segment *t1_Snap();
diff --git a/Xserver/lib/font/Type1/regions.c b/Xserver/lib/font/Type1/regions.c
new file mode 100644 (file)
index 0000000..c9b0038
--- /dev/null
@@ -0,0 +1,1746 @@
+/* $XConsortium: regions.c,v 1.6 94/02/06 16:22:21 gildea Exp $ */
+/* $XFree86: xc/lib/font/Type1/regions.c,v 3.0 1996/08/25 13:58:26 dawes Exp $ */
+/* Copyright International Business Machines, Corp. 1991
+ * All Rights Reserved
+ * Copyright Lexmark International, Inc. 1991
+ * All Rights Reserved
+ *
+ * License to use, copy, modify, and distribute this software and its
+ * documentation for any purpose and without fee is hereby granted,
+ * provided that the above copyright notice appear in all copies and that
+ * both that copyright notice and this permission notice appear in
+ * supporting documentation, and that the name of IBM or Lexmark not be
+ * used in advertising or publicity pertaining to distribution of the
+ * software without specific, written prior permission.
+ *
+ * IBM AND LEXMARK PROVIDE THIS SOFTWARE "AS IS", WITHOUT ANY WARRANTIES OF
+ * ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING, BUT NOT LIMITED TO ANY
+ * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE,
+ * AND NONINFRINGEMENT OF THIRD PARTY RIGHTS.  THE ENTIRE RISK AS TO THE
+ * QUALITY AND PERFORMANCE OF THE SOFTWARE, INCLUDING ANY DUTY TO SUPPORT
+ * OR MAINTAIN, BELONGS TO THE LICENSEE.  SHOULD ANY PORTION OF THE
+ * SOFTWARE PROVE DEFECTIVE, THE LICENSEE (NOT IBM OR LEXMARK) ASSUMES THE
+ * ENTIRE COST OF ALL SERVICING, REPAIR AND CORRECTION.  IN NO EVENT SHALL
+ * IBM OR LEXMARK BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
+ * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
+ * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
+ * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
+ * THIS SOFTWARE.
+ */
+ /* REGIONS  CWEB         V0023 LOTS                                 */
+/*
+:h1 id=regions.REGIONS Module - Regions Operator Handler
+This module is responsible for creating and manipulating regions.
+&author. Jeffrey B. Lotspiech (lotspiech@almaden.ibm.com)
+:h3.Include Files
+The included files are:
+*/
+#include  "objects.h"
+#include  "spaces.h"
+#include  "regions.h"
+#include  "paths.h"
+#include  "curves.h"
+#include  "lines.h"
+#include  "pictures.h"
+#include  "fonts.h"
+#include  "hints.h"
+#include  "strokes.h"      /* to pick up 'DoStroke'                        */
+static Unwind();
+static void newfilledge();
+static struct edgelist *splitedge();
+static void vertjoin();
+static int touches();
+static int crosses();
+static void edgemin();
+static void edgemax();
+static discard();
+static edgecheck();
+static struct edgelist *NewEdge();
+static struct edgelist *swathxsort();  /* 'SortSwath' function               */
+/*
+:h3.Functions Provided to the TYPE1IMAGER User
+This module provides the following TYPE1IMAGER entry points:
+*/
+/*SHARED LINE(S) ORIGINATED HERE*/
+/*
+:h3.Functions Provided to Other Modules
+This module provides the following entry points to other modules:
+*/
+/*SHARED LINE(S) ORIGINATED HERE*/
+/*
+:h3.Macros Provided to Other Modules
+:h4.GOING_TO() - Macro Predicate Needed for Changing Direction, Etc.
+The actual generation of run end lists (edge boundaries) is left
+to the low level rasterizing modules, LINES and CURVES.  There
+are some global region-type
+questions that occur when doing a low-level
+rasterization:
+:ol.
+:li.Did we just change direction in Y and therefore need to start
+a new edge?
+:li.Did we run out of allocated edge space?
+:li.Do the minimum or maximum X values for the current edge need
+updating?
+:eol.
+In general the REGIONS is not smart enough to answer those questions
+itself.  (For example, determining if and when a curve changes direction
+may need detailed curve knowledge.)  Yet, this must be done efficiently.
+We provide a macro "GOING_TO" where the invoker tells us where it is
+heading for (x2,y2), plus where it is now (x1,y1), plus the current
+region under construction, and the macro answers the questions above.
+*/
+/*SHARED LINE(S) ORIGINATED HERE*/
+/*
+:h2.Data Structures Used to Represent Regions
+:h3.The "region" Structure
+The region structure is an anchor for a linked list of "edgelist"
+structures (see :hdref refid=edgelist..).  It also summarizes the
+information in the edgelist structures (for example, the bounding
+box of the region).  And, it contains scratch areas used during
+the creation of a region.
+*/
+/*SHARED LINE(S) ORIGINATED HERE*/
+/*
+The ISOPTIMIZED flag tells us if we've put a permanent region in
+'optimal' form.
+*/
+#define   ISOPTIMIZED(flag)    ((flag)&0x10)
+/*
+The ISRECTANGULAR flag tells us if a region is a rectangle.  We don't
+always notice rectangles--if this flag is set, the region definitely
+is a rectangle, but some rectangular regions will not have the flag
+set.  The flag is used to optimize some paths.
+*/
+/*SHARED LINE(S) ORIGINATED HERE*/
+/*
+:h4."INFINITY" - A Constant Region Structure of Infinite Extent
+Infinity is the complement of a null area:
+Note - removed the refcount = 1 init, replaced with references = 2 3-26-91 PNM
+*/
+static struct region infinity = { REGIONTYPE,
+                           ISCOMPLEMENT(ON)+ISINFINITE(ON)+ISPERMANENT(ON)+ISIMMORTAL(ON), 2,
+                           0, 0, 0, 0,
+                           0, 0, 0, 0,
+                           NULL, NULL,
+                           0, 0, 0, 0, 0, NULL, NULL,
+                           NULL, 0, NULL, NULL };
+struct region *INFINITY = &infinity;
+/*
+:h4."EmptyRegion" - A Region Structure with Zero Area
+This structure is used to initialize the region to be built in
+Interior():
+Note - replaced refcount = 1 init with references = 2 3-26-91 PNM
+*/
+/*SHARED LINE(S) ORIGINATED HERE*/
+struct region EmptyRegion = { REGIONTYPE,
+                           ISPERMANENT(ON)+ISIMMORTAL(ON), 2,
+                           0, 0, 0, 0,
+                           MAXPEL, MAXPEL, MINPEL, MINPEL,
+                           NULL, NULL,
+                           0, 0, 0, 0, 0, NULL, NULL,
+                           NULL, 0, NULL, NULL };
+/*
+:h3 id=edgelist.The "edgelist" Structure
+Regions are represented by a linked list of 'edgelist' structures.
+When a region is complete, the structures are paired, one for the
+left and one for the right edge.  While a region is being built,
+this rule may be violated temporarily.
+An 'edgelist' structure contains the X values for a given span
+of Y values.  The (X,Y) pairs define an edge.  We use the crack
+and edge coordinate system, so that integer values of X and Y
+go between pels.  The edge is defined between the minimum Y and
+maximum Y.
+The linked list is kept sorted from top to bottom, that is, in
+increasing y.  Also, if 'e1' is an edgelist structure and 'e2' is the
+next one in the list, they must have exactly the same ymin,ymax values
+or be totally disjoint.  These two requirements mean that if e2's ymin
+is less than e1's ymax, it must be exactly equal to e1's ymin.  A
+sublist of structures with identical ymin and ymax values is called a
+'swath'.
+In addition, edgelist structures are separately linked together based
+on what subpath originally created them; each subpath is kept as a
+separate circular linked list.  This information is ignored unless
+continuity checking is invoked.  See :hdref refid=subpath. for a
+complete description of this.
+*/
+/*SHARED LINE(S) ORIGINATED HERE*/
+/*
+The "edgelist" structure follows the convention of TYPE1IMAGER user
+objects, having a type field and a flag field as the first two
+elements.  However, the user never sees "edgelist" structures
+directly; he is given handles to "region" structures only.
+By having a type field, we can use the "copy" feature of Allocate()
+to duplicate edge lists quickly.
+We also define two flag bits for this structure.  The ISDOWN bit is set
+if the edge is going in the direction of increasing Y. The ISAMBIGUOUS
+bit is set if the edge is identical to its neighbor (edge->link); such
+edges may be "left" when they should be "right", or vice versa,
+unnecessarily confusing the continuity checking logic.  The FixSubPaths()
+routine in HINTS will swap ambiguous edges if that avoids crossing edges;
+see :hdref refid=fixsubp..
+*/
+/*SHARED LINE(S) ORIGINATED HERE*/
+/*
+:h3.KillRegion() - Destroys a Region
+KillRegion nominally just decrements the reference count to that region.
+If the reference count becomes 0, all memory associated with it is
+freed.  We just follow the linked list, freeing as we go, then kill any
+associated (thresholded) picture.
+Note - added conditional return based on references 3-26-91 PNM
+*/
+void KillRegion(area)
+        register struct region *area;  /* area to free                       */
+{
+        register struct edgelist *p;  /* loop variable                       */
+        register struct edgelist *next;  /* loop variable                    */
+        if (area->references < 0)
+               abort("KillRegion:  negative reference count");
+        if ( (--(area->references) > 1) ||
+           ( (area->references == 1) && !ISPERMANENT(area->flag) ) )
+            return;
+        for (p=area->anchor; p != NULL; p=next) {
+               next = p->link;
+               Free(p);
+        }
+        if (area->thresholded != NULL)
+                 KillPicture(area->thresholded);
+        Free(area);
+}
+/*
+:h3.CopyRegion() - Makes a Copy of a Region
+*/
+struct region *CopyRegion(area)
+        register struct region *area;  /* region to duplicate                */
+{
+        register struct region *r;  /* output region built here              */
+        register struct edgelist *last;  /* loop variable                    */
+        register struct edgelist *p,*newp;  /* loop variables                */
+        r = (struct region *)Allocate(sizeof(struct region), area, 0);
+        r->anchor = NULL;
+        for (p=area->anchor; VALIDEDGE(p); p=p->link) {
+               newp = NewEdge(p->xmin, p->xmax, p->ymin, p->ymax, p->xvalues, ISDOWN(p->flag));
+               if (r->anchor == NULL)
+                       r->anchor = last = newp;
+               else
+                       last->link = newp;
+               last = newp;
+        }
+        if (area->thresholded != NULL)
+    /* replaced DupPicture with Dup() 3-26-91 PNM */
+               r->thresholded = (struct picture *)Dup(area->thresholded);
+        return(r);
+}
+/*
+:h4.NewEdge() - Allocates and Returns a New "edgelist" Structure
+We allocate space for the X values contiguously with the 'edgelist'
+structure that locates them.  That way, we only have to free the
+edgelist structure to free all memory associated with it.  Damn
+clever, huh?
+*/
+static struct edgelist *NewEdge(xmin, xmax, ymin, ymax, xvalues, isdown)
+       pel xmin,xmax;        /* X extent of edge                             */
+       pel ymin,ymax;        /* Y extent of edge                             */
+       pel *xvalues;         /* list of X values for entire edge             */
+       int isdown;           /* flag:  TRUE means edge progresses downward   */
+{
+       static struct edgelist template = {
+                 EDGETYPE, 0, 1, NULL, NULL,
+                 0, 0, 0, 0, NULL };
+       register struct edgelist *r;  /* returned structure                   */
+       register int iy;      /* ymin adjusted for 'long' alignment purposes  */
+       IfTrace2((RegionDebug),"....new edge: ymin=%d, ymax=%d ",
+                                              (long)ymin, (long) ymax);
+       if (ymin >= ymax)
+               abort("newedge: height not positive");
+/*
+We are going to copy the xvalues into a newly allocated area.  It
+helps performance if the values are all "long" aligned.  We can test
+if the xvalues are long aligned by ANDing the address with the
+(sizeof(long) - 1)--if non zero, the xvalues are not aligned well.  We
+set 'iy' to the ymin value that would give us good alignment:
+*/
+       iy = ymin - (((unsigned long)xvalues) & (sizeof(long)-1)) / sizeof(pel);
+       r = (struct edgelist *)Allocate(sizeof(struct edgelist), &template,
+                             (ymax - iy) * sizeof(pel));
+       if (isdown) r->flag = ISDOWN(ON);
+       r->xmin = xmin;
+       r->xmax = xmax;
+       r->ymin = ymin;
+       r->ymax = ymax;
+       r->xvalues = (pel *) FOLLOWING(r);
+       if (ymin != iy) {
+               r->xvalues += ymin - iy;
+               xvalues -= ymin - iy;
+       }
+/*
+We must round up (ymax - iy) so we get the ceiling of the number of
+longs.  The destination must be able to hold these extra bytes because
+Allocate() makes everything it allocates be in multiples of longs.
+*/
+       LONGCOPY(&r[1], xvalues, (ymax - iy) * sizeof(pel) + sizeof(long) - 1);
+       IfTrace1((RegionDebug),"result=%x\n", r);
+       return(r);
+}
+/*
+:h2.Building Regions
+:h3.Interior() - Iterate Through a Path, Building a Region
+This routine is the workhorse driver routine that iterates through a
+path, calling the appropriate stepping routines to actually produce the
+run end "edgelist" structures.
+:ol.
+:li."Interior" calls StepLine or StepConic or StepBezier as appropriate
+to produce run ends.
+:li.Occasionally these routines will notice a change in Y direction
+and will call ChangeDirection (through the GOING_TO macro); this is
+a call back to the REGIONS module.
+:li.ChangeDirection will call whatever function is in the region
+structure; for Interior, this function is 'newfilledge'.
+:li.Newfilledge will call NewEdge to create a new edgelist structure,
+then, call SortSwath to sort it onto the linked list being built at
+the region "anchor".
+:eol.
+By making the function called by ChangeDirection be a parameter of the
+region, we allow the same ChangeDirection logic to be used by stroking.
+*/
+/*SHARED LINE(S) ORIGINATED HERE*/
+struct region *Interior(p, fillrule)
+       register struct segment *p;    /* take interior of this path          */
+       register int fillrule;         /* rule to follow if path crosses itself */
+{
+       register fractpel x,y;  /* keeps ending point of path segment         */
+       fractpel lastx,lasty; /* previous x,y from path segment before        */
+       register struct region *R;  /* region I will build                    */
+       register struct segment *nextP; /* next segment of path */
+       struct fractpoint hint; /* accumulated hint value */
+       char tempflag;        /* flag; is path temporary?                     */
+       char Cflag;           /* flag; should we apply continuity?            */
+       IfTrace2((MustTraceCalls),".  INTERIOR(%z, %d)\n", p, (long) fillrule);
+       if (p == NULL)
+               return(NULL);
+/*
+Establish the 'Cflag' continuity flag based on user's fill rule and
+our own 'Continuity' pragmatic (0: never do continuity, 1: do what
+user asked, >1: do it regardless).
+*/
+       if (fillrule > 0) {
+               Cflag = Continuity > 0;
+               fillrule -= CONTINUITY;
+       }
+       else
+               Cflag = Continuity > 1;
+       ARGCHECK((fillrule != WINDINGRULE && fillrule != EVENODDRULE),
+                       "Interior: bad fill rule", NULL, NULL, (1,p), struct region *);
+       if (p->type == TEXTTYPE)
+/*             if (fillrule != EVENODDRULE)
+               else */
+                       return((struct region *)UniquePath(p));
+       if (p->type == STROKEPATHTYPE)
+               if (fillrule == WINDINGRULE)
+                       return((struct region *)DoStroke(p));
+               else
+                       p = CoercePath(p);
+       R = (struct region *)Allocate(sizeof(struct region), &EmptyRegion, 0);
+       ARGCHECK(!ISPATHANCHOR(p), "Interior:  bad path", p, R, (0), struct region *);
+       ARGCHECK((p->type != MOVETYPE), "Interior:  path not closed", p, R, (0), struct region *);
+/* changed definition from !ISPERMANENT to references <= 1 3-26-91 PNM */
+       tempflag =  (p->references <= 1); /* only first segment in path is so marked */
+       if (!ISPERMANENT(p->flag)) p->references -= 1;
+       R->newedgefcn = newfilledge;
+/*
+Believe it or not, "R" is now completely initialized.  We are counting
+on the copy of template to get other fields the way we want them,
+namely
+:ol.
+:li.anchor = NULL
+:li.xmin, ymin, xmax, ymax, to minimum and maximum values respectively.
+:eol.
+Anchor = NULL is very
+important to ChangeDirection.
+See :hdref refid=CD..
+To minimize problems of "wrapping" in our pel arithmetic, we keep an
+origin of the region which is the first move.  Hopefully, that keeps
+numbers within plus or minus 32K pels.
+*/
+       R->origin.x = 0/*TOFRACTPEL(NEARESTPEL(p->dest.x))*/;
+       R->origin.y = 0/*TOFRACTPEL(NEARESTPEL(p->dest.y))*/;
+       lastx = - R->origin.x;
+       lasty = - R->origin.y;
+/*
+ChangeDirection initializes other important fields in R, such as
+lastdy, edge, edgeYstop, edgexmin, and edgexmax.  The first segment
+is a MOVETYPE, so it will be called first.
+*/
+/*
+The hints data structure must be initialized once for each path.
+*/
+       if (ProcessHints)
+               InitHints(); /* initialize hint data structure */
+       while (p != NULL)  {
+               x = lastx + p->dest.x;
+               y = lasty + p->dest.y;
+               IfTrace2((HintDebug > 0),"Ending point = (%p,%p)\n", x, y);
+               nextP = p->link;
+/*
+Here we start the hints processing by initializing the hint value to
+zero.  If ProcessHints is FALSE, the value will remain zero.
+Otherwise, hint accumulates the computed hint values.
+*/
+               hint.x = hint.y = 0;
+/*
+If we are processing hints, and this is a MOVE segment (other than
+the first on the path), we need to close (reverse) any open hints.
+*/
+               if (ProcessHints)
+                       if ((p->type == MOVETYPE) && (p->last == NULL)) {
+                               CloseHints(&hint);
+                               IfTrace2((HintDebug>0),"Closed point= (%p,%p)\n",
+                                               x+hint.x, y+hint.y);
+                       }
+/*
+Next we run through all the hint segments (if any) attached to this
+segment.  If ProcessHints is TRUE, we will accumulate computed hint
+values.  In either case, nextP will be advanced to the first non-HINT
+segment (or NULL), and each hint segment will be freed if necessary.
+*/
+               while ((nextP != NULL) && (nextP->type == HINTTYPE))  {
+                       if (ProcessHints)
+                               ProcessHint(nextP, x + hint.x, y + hint.y, &hint);
+                       {
+                               register struct segment *saveP = nextP;
+                               nextP = nextP->link;
+                               if (tempflag)
+                                       Free(saveP);
+                       }
+               }
+/*
+We now apply the full hint value to the ending point of the path segment.
+*/
+               x += hint.x;
+               y += hint.y;
+               IfTrace2((HintDebug>0),"Hinted ending point = (%p,%p)\n", x, y);
+               switch(p->type) {
+                   case LINETYPE:
+                       StepLine(R, lastx, lasty, x, y);
+                       break;
+                   case CONICTYPE:
+                   {
+/*
+For a conic curve, we apply half the hint value to the conic midpoint.
+*/
+                   }
+                       break;
+                   case BEZIERTYPE:
+                   {
+                       register struct beziersegment *bp = (struct beziersegment *) p;
+/*
+For a Bezier curve, we apply the full hint value to the Bezier C point.
+*/
+                       StepBezier(R, lastx, lasty,
+                                 lastx + bp->B.x, lasty + bp->B.y,
+                                 lastx + bp->C.x + hint.x,
+                                 lasty + bp->C.y + hint.y,
+                                 x, y);
+                   }
+                       break;
+                   case MOVETYPE:
+/*
+At this point we have encountered a MOVE segment.  This breaks the
+path, making it disjoint.
+*/
+                       if (p->last == NULL) /* i.e., not first in path */
+                               ChangeDirection(CD_LAST, R, lastx, lasty, (fractpel) 0);
+                       ChangeDirection(CD_FIRST, R, x, y, (fractpel) 0);
+/*
+We'll just double check for closure here.  We forgive an appended
+MOVETYPE at the end of the path, if it isn't closed:
+*/
+                       if (!ISCLOSED(p->flag) && p->link != NULL)
+                               return((struct region *)ArgErr("Fill: sub-path not closed", p, NULL));
+                       break;
+                   default:
+                       abort("Interior: path type error");
+               }
+/*
+We're done with this segment.  Advance to the next path segment in
+the list, freeing this one if necessary:
+*/
+               lastx = x;  lasty = y;
+               if (tempflag)
+                       Free(p);
+               p = nextP;
+       }
+       ChangeDirection(CD_LAST, R, lastx, lasty, (fractpel) 0);
+       R->ending.x = lastx;
+       R->ending.y = lasty;
+/*
+Finally, clean up the region's based on the user's 'fillrule' request:
+*/
+       if (Cflag)
+             ApplyContinuity(R);
+       if (fillrule == WINDINGRULE)
+             Unwind(R->anchor);
+       return(R);
+}
+/*
+:h4.Unwind() - Discards Edges That Fail the Winding Rule Test
+The winding rule says that upward going edges should be paired with
+downward going edges only, and vice versa.  So, if two upward edges
+or two downward edges are nominally left/right pairs, Unwind() should
+discard the second one.  Everything should balance; we should discard
+an even number of edges; of course, we abort if we don't.
+*/
+static Unwind(area)
+       register struct edgelist *area;  /* input area modified in place      */
+{
+       register struct edgelist *last,*next;  /* struct before and after current one */
+       register int y;       /* ymin of current swath                        */
+       register int count,newcount;  /* winding count registers              */
+       IfTrace1((RegionDebug>0),"...Unwind(%z)\n", area);
+       while (VALIDEDGE(area)) {
+               count = 0;
+               y = area->ymin;
+               do {
+                       next = area->link;
+                       if (ISDOWN(area->flag))
+                               newcount = count + 1;
+                       else
+                               newcount = count - 1;
+                       if (count == 0 || newcount == 0)
+                               last = area;
+                       else
+                               discard(last, next);
+                       count = newcount;
+                       area = next;
+               } while (area != NULL && area->ymin == y);
+               if (count != 0)
+                       abort("Unwind:  uneven edges");
+       }
+}
+/*
+:h3."workedge" Array
+This is a statically allocated array where edges are built
+before being copied into more permanent storage by NewEdge().
+*/
+#ifndef   MAXEDGE
+#define   MAXEDGE     1000
+#endif
+static pel workedge[MAXEDGE];
+static pel *currentworkarea = workedge;
+static pel currentsize = MAXEDGE;
+/*
+:h3 id=cd.ChangeDirection() - Called When Y Direction Changes
+The rasterizing routines call this entry point when they detect
+a change in Y.  We then build the current edge and sort it into
+emerging edgelist at 'anchor' by calling whatever "newedgefcn"
+is appropriate.
+*/
+void ChangeDirection(type, R, x, y, dy)
+       int type;             /* CD_FIRST, CD_CONTINUE, or CD_LAST            */
+       register struct region *R;  /* region in which we are changing direction */
+       fractpel x,y;         /* current beginning x,y                        */
+       fractpel dy;          /* direction and magnitude of change in y       */
+{
+       register fractpel ymin,ymax;  /* minimum and maximum Y since last call */
+       register fractpel x_at_ymin,x_at_ymax;  /* their respective X's       */
+       register pel iy;      /* nearest integer pel to 'y'                   */
+       register pel idy;     /* nearest integer pel to 'dy'                  */
+       register int ydiff;   /* allowed Y difference in 'currentworkarea'    */
+       IfTrace4((RegionDebug>0),"Change Y direction (%d) from (%p,%p), dy=%p\n",
+                                         (long) type, x, y, dy);
+       if (type != CD_FIRST) {
+               if (R->lastdy > 0) {
+                       ymin = R->firsty;
+                       x_at_ymin = R->firstx;
+                       ymax = y;
+                       x_at_ymax = x;
+               }
+               else {
+                       ymin = y;
+                       x_at_ymin = x;
+                       ymax = R->firsty;
+                       x_at_ymax = R->firstx;
+               }
+               if (ymax < ymin)
+                       abort("negative sized edge?");
+               (*R->newedgefcn)(R, R->edgexmin, R->edgexmax, ymin, ymax,
+                                   R->lastdy > 0, x_at_ymin, x_at_ymax);
+       }
+       R->firsty = y;
+       R->firstx = x;
+       R->lastdy = dy;
+       iy = NEARESTPEL(y);
+       idy = NEARESTPEL(dy);
+       if (currentworkarea != workedge && idy < MAXEDGE && idy > -MAXEDGE) {
+               NonObjectFree(currentworkarea);
+               currentworkarea = workedge;
+               currentsize = MAXEDGE;
+       }
+       ydiff = currentsize - 1;
+       if (dy > 0) {
+               R->edge = &currentworkarea[-iy];
+               R->edgeYstop = TOFRACTPEL(ydiff + iy) + FPHALF;
+       }
+       else {
+               R->edge = &currentworkarea[ydiff - iy];
+               R->edgeYstop = TOFRACTPEL(iy - ydiff) - FPHALF;
+       }
+       R->edgexmax = R->edgexmin = x;
+/*
+If this is the end of a subpath, we complete the subpath circular
+chain:
+*/
+       if (type == CD_LAST && R->lastedge != NULL) {
+               register struct edgelist *e = R->firstedge;
+               while (e->subpath != NULL)
+                       e = e->subpath;
+               e->subpath = R->lastedge;
+               R->lastedge = R->firstedge = NULL;
+       }
+}
+/*
+:h3 id=newfill.newfilledge() - Called When We Have a New Edge While Filling
+This is the prototypical "newedge" function passed to "Rasterize" and
+stored in "newedgefcn" in the region being built.
+If the edge is non-null, we sort it onto the list of edges we are
+building at "anchor".
+This function also has to keep the bounding box of the region
+up to date.
+*/
+static void newfilledge(R, xmin, xmax, ymin, ymax, isdown)
+       register struct region *R;  /* region being built                     */
+       fractpel xmin,xmax;   /* X range of this edge                         */
+       fractpel ymin,ymax;   /* Y range of this edge                         */
+       int isdown;           /* flag:  TRUE means edge goes down, else up    */
+{
+       register pel pelxmin,pelymin,pelxmax,pelymax;  /* pel versions of bounds */
+       register struct edgelist *edge;  /* newly created edge                */
+       pelymin = NEARESTPEL(ymin);
+       pelymax = NEARESTPEL(ymax);
+       if (pelymin == pelymax)
+               return;
+       pelxmin = NEARESTPEL(xmin);
+       pelxmax = NEARESTPEL(xmax);
+       if (pelxmin < R->xmin)  R->xmin = pelxmin;
+       if (pelxmax > R->xmax)  R->xmax = pelxmax;
+       if (pelymin < R->ymin)  R->ymin = pelymin;
+       if (pelymax > R->ymax)  R->ymax = pelymax;
+       edge = NewEdge(pelxmin, pelxmax, pelymin, pelymax, &R->edge[pelymin], isdown);
+       edge->subpath = R->lastedge;
+       R->lastedge = edge;
+       if (R->firstedge == NULL)
+               R->firstedge = edge;
+       R->anchor = SortSwath(R->anchor, edge, swathxsort);
+}
+/*
+:h2.Sorting Edges
+:h3.SortSwath() - Vertically Sort an Edge into a Region
+This routine sorts an edge or a pair of edges into a growing region,
+so that the region maintains its top-to-bottom, left-to-right form.
+The rules for sorting horizontally may vary depending on what you
+are doing, but the rules for vertical sorting are always the same.
+This routine is passed an argument that is a function that will
+perform the horizontal sort on demand (for example, swathxsort() or
+SwathUnion()).
+This is a recursive routine.  A new edge (or edge pair) may overlap
+the list I am building in strange and wonderful ways.  Edges may
+cross.  When this happens, my strategy is to split the incoming edge
+(or the growing list) in two at that point, execute the actual sort on
+the top part of the split, and recursively call myself to figure out
+exactly where the bottom part belongs.
+*/
+#define   TOP(e)      ((e)->ymin)  /* the top of an edge (for readability    */
+#define   BOTTOM(e)   ((e)->ymax)  /* the bottom of an edge (for readability */
+struct edgelist *SortSwath(anchor, edge, swathfcn)
+       struct edgelist *anchor;  /* list being built                         */
+       register struct edgelist *edge;  /* incoming edge or pair of edges    */
+       struct edgelist *(*swathfcn)();  /* horizontal sorter                 */
+{
+       register struct edgelist *before,*after;
+       struct edgelist base;
+       if (RegionDebug > 0) {
+               if (RegionDebug > 2)  {
+                       IfTrace3(TRUE,"SortSwath(anchor=%z, edge=%z, fcn=%x)\n",
+                            anchor, edge, swathfcn);
+               }
+               else  {
+                       IfTrace3(TRUE,"SortSwath(anchor=%x, edge=%x, fcn=%x)\n",
+                            anchor, edge, swathfcn);
+               }
+       }
+       if (anchor == NULL)
+               return(edge);
+       before = &base;
+       before->ymin = before->ymax = MINPEL;
+       before->link = after = anchor;
+/*
+If the incoming edge is above the current list, we connect the current
+list to the bottom of the incoming edge.  One slight complication is
+if the incoming edge overlaps into the current list.  Then, we
+first split the incoming edge in two at the point of overlap and recursively
+call ourselves to sort the bottom of the split into the current list:
+*/
+       if (TOP(edge) < TOP(after)) {
+               if (BOTTOM(edge) > TOP(after)) {
+                       after = SortSwath(after, splitedge(edge, TOP(after)), swathfcn);
+               }
+               vertjoin(edge, after);
+               return(edge);
+       }
+/*
+At this point the top of edge is not higher than the top of the list,
+which we keep in 'after'.  We move the 'after' point down the list,
+until the top of the edge occurs in the swath beginning with 'after'.
+If the bottom of 'after' is below the bottom of the edge, we have to
+split the 'after' swath into two parts, at the bottom of the edge.
+If the bottom of 'after' is above the bottom of the swath,
+*/
+       while (VALIDEDGE(after)) {
+               if (TOP(after) == TOP(edge)) {
+                       if (BOTTOM(after) > BOTTOM(edge))
+                               vertjoin(after, splitedge(after, BOTTOM(edge)));
+                       else if (BOTTOM(after) < BOTTOM(edge)) {
+                               after = SortSwath(after,
+                                     splitedge(edge, BOTTOM(after)), swathfcn);
+                       }
+                       break;
+               }
+               else if (TOP(after) > TOP(edge)) {
+                       IfTrace0((BOTTOM(edge) < TOP(after) && RegionDebug > 0),
+                                                "SortSwath:  disjoint edges\n");
+                       if (BOTTOM(edge) > TOP(after)) {
+                               after = SortSwath(after,
+                                         splitedge(edge, TOP(after)), swathfcn);
+                       }
+                       break;
+               }
+               else if (BOTTOM(after) > TOP(edge))
+                       vertjoin(after, splitedge(after, TOP(edge)));
+               before = after;
+               after = after->link;
+       }
+/*
+At this point 'edge' exactly corresponds in height to the current
+swath pointed to by 'after'.
+*/
+       if (after != NULL && TOP(after) == TOP(edge)) {
+               before = (*swathfcn)(before, edge);
+               after = before->link;
+       }
+/*
+At this point 'after' contains all the edges after 'edge', and 'before'
+contains all the edges before.  Whew!  A simple matter now of adding
+'edge' to the linked list in its rightful place:
+*/
+       before->link = edge;
+       if (RegionDebug > 1) {
+               IfTrace3(TRUE,"SortSwath:  in between %x and %x are %x",
+                                                before, after, edge);
+               while (edge->link != NULL) {
+                       edge = edge->link;
+                       IfTrace1(TRUE," and %x", edge);
+               }
+               IfTrace0(TRUE,"\n");
+       }
+       else
+               for (; edge->link != NULL; edge = edge->link) { ; }
+       edge->link = after;
+       return(base.link);
+}
+/*
+:h3.splitedge() - Split an Edge or Swath in Two at a Given Y Value
+This function returns the edge or swath beginning at the Y value, and
+is guaranteed not to change the address of the old swath while splitting
+it.
+*/
+static struct edgelist *splitedge(list, y)
+       struct edgelist *list;  /* area to split                              */
+       register pel y;       /* Y value to split list at                     */
+{
+       register struct edgelist *new;  /* anchor for newly built list        */
+       register struct edgelist *last;  /* end of newly built list           */
+       register struct edgelist *r;  /* temp pointer to new structure        */
+       register struct edgelist *lastlist;  /* temp pointer to last 'list' value */
+       IfTrace2((RegionDebug > 1),"splitedge of %x at %d ", list, (long) y);
+       lastlist = new = NULL;
+       while (list != NULL) {
+               if (y < list->ymin)
+                       break;
+               if (y >= list->ymax)
+                       abort("splitedge: above top of list");
+               if (y == list->ymin)
+                       abort("splitedge: would be null");
+               r = (struct edgelist *)Allocate(sizeof(struct edgelist), list, 0);
+/*
+At this point 'r' points to a copy of the single structure at 'list'.
+We will make 'r' be the new split 'edgelist'--the lower half.
+We don't bother to correct 'xmin' and 'xmax', we'll take the
+the pessimistic answer that results from using the old values.
+*/
+               r->ymin = y;
+               r->xvalues = list->xvalues + (y - list->ymin);
+/*
+Note that we do not need to allocate new memory for the X values,
+they can remain with the old "edgelist" structure.  We do have to
+update that old structure so it is not as high:
+*/
+               list->ymax = y;
+/*
+Insert 'r' in the subpath chain:
+*/
+               r->subpath = list->subpath;
+               list->subpath = r;
+/*
+Now attach 'r' to the list we are building at 'new', and advance
+'list' to point to the next element in the old list:
+*/
+               if (new == NULL)
+                       new = r;
+               else
+                       last->link = r;
+               last = r;
+               lastlist = list;
+               list = list->link;
+       }
+/*
+At this point we have a new list built at 'new'.  We break the old
+list at 'lastlist', and add the broken off part to the end of 'new'.
+Then, we return the caller a pointer to 'new':
+*/
+       if (new == NULL)
+               abort("null splitedge");
+       lastlist->link = NULL;
+       last->link = list;
+       IfTrace1((RegionDebug > 1),"yields %x\n", new);
+       return(new);
+}
+/*
+:h3.vertjoin() - Join Two Disjoint Edge Lists Vertically
+The two edges must be disjoint vertically.
+*/
+static void vertjoin(top, bottom)
+       register struct edgelist *top;  /* uppermost region                   */
+       register struct edgelist *bottom;  /* bottommost region               */
+{
+       if (BOTTOM(top) > TOP(bottom))
+               abort("vertjoin not disjoint");
+       for (; top->link != NULL; top=top->link) { ; }
+       top->link = bottom;
+       return;
+}
+/*
+:h3.swathxsort() - Sorting by X Values
+We need to sort 'edge' into its rightful
+place in the swath by X value, taking care that we do not accidentally
+advance to the next swath while searching for the correct X value.  Like
+all swath functions, this function returns a pointer to the edge
+BEFORE the given edge in the sort.
+*/
+static struct edgelist *swathxsort(before0, edge)
+       register struct edgelist *before0;  /* edge before this swath         */
+       register struct edgelist *edge;  /* input edge                        */
+{
+       register struct edgelist *before;
+       register struct edgelist *after;
+       register pel y;
+       before = before0;
+       after = before->link;
+       while (after != NULL && TOP(after) == TOP(edge)) {
+               register pel *x1,*x2;
+               y = TOP(edge);
+               x1 = after->xvalues;
+               x2 = edge->xvalues;
+               while (y < BOTTOM(edge) && *x1 == *x2) {
+                       x1++; x2++; y++;
+               }
+               if (y >= BOTTOM(edge)) {
+                       edge->flag |= ISAMBIGUOUS(ON);
+                       after->flag |= ISAMBIGUOUS(ON);
+                       break;
+               }
+               if (*x1 >= *x2)
+                       break;
+               before = after;
+               after = after->link;
+       }
+/*
+At this point, 'edge' is between 'before' and 'after'.  If 'edge' didn't
+cross either of those other edges, we would be done.  We check for
+crossing.  If it does cross, we split the problem up by calling SortSwath
+recursively with the part of the edge that is below the crossing point:
+*/
+{
+       register int h0,h;    /* height of edge--number of scans              */
+       h0 = h = BOTTOM(edge) - y;
+       y -= TOP(edge);
+       if (h0 <= 0) {
+               IfTrace0((RegionDebug>0),"swathxsort: exactly equal edges\n");
+               return(before);
+       }
+       if (TOP(before) == TOP(edge))
+               h -= crosses(h, &before->xvalues[y], &edge->xvalues[y]);
+       if (after != NULL && TOP(after) == TOP(edge))
+               h -= crosses(h, &edge->xvalues[y], &after->xvalues[y]);
+       if (h < h0) {
+               SortSwath(before0->link,
+                         splitedge(edge, TOP(edge) + y + h),
+                         swathxsort);
+       }
+}
+       return(before);
+}
+/*
+:h3.SwathUnion() - Union Two Edges by X Value
+We have a left and right edge that must be unioned into a growing
+swath.  If they are totally disjoint, they are just added in.  The
+fun comes in they overlap the existing edges.  Then some edges
+will disappear.
+*/
+struct edgelist *SwathUnion(before0, edge)
+       register struct edgelist *before0;  /* edge before the swath          */
+       register struct edgelist *edge;  /* list of two edges to be unioned   */
+{
+       register int h;       /* saves height of edge                         */
+       register struct edgelist *rightedge;  /* saves right edge of 'edge'   */
+       register struct edgelist *before,*after;  /* edge before and after    */
+       int h0;               /* saves initial height                         */
+       IfTrace2((RegionDebug > 1),"SwathUnion entered, before=%x, edge=%x\n",
+                      before0, edge);
+       h0 = h = edge->ymax - edge->ymin;
+       if (h <= 0)
+               abort("SwathUnion:  0 height swath?");
+       before = before0;
+       after = before->link;
+       while (after != NULL && TOP(after) == TOP(edge)) {
+               register struct edgelist *right;
+               right = after->link;
+               if (right->xvalues[0] >= edge->xvalues[0])
+                       break;
+               before = right;
+               after = before->link;
+       }
+/*
+This is the picture at this point.  'L' indicates a left hand edge,
+'R' indicates the right hand edge.
+'<--->' indicates the degree of uncertainty as to its placement
+relative to other edges:
+:xmp atomic.
+   before           after
+     R            <---L---->  R             L   R    L   R
+              <---L--->  <------R-------------------------->
+                 edge
+:exmp.
+In case the left of 'edge' touches 'before', we need to reduce
+the height by that amount.
+*/
+       if (TOP(before) == TOP(edge))
+               h -= touches(h, before->xvalues, edge->xvalues);
+       rightedge = edge->link;
+       if (after == NULL || TOP(after) != TOP(edge) ||
+                   after->xvalues[0] > rightedge->xvalues[0]) {
+              IfTrace2((RegionDebug > 1),
+                       "SwathUnion starts disjoint: before=%x after=%x\n",
+                                     before, after);
+/*
+On this side of the the above 'if', the new edge is disjoint from the
+existing edges in the swath.  This is the picture:
+:xmp atomic.
+   before           after
+     R                L    R     L   R    L   R
+              L    R
+             edge
+:exmp.
+We will verify it remains disjoint for the entire height.  If the
+situation changes somewhere down the edge, we split the edge at that
+point and recursively call ourselves (through 'SortSwath') to figure
+out the new situation:
+*/
+               if (after != NULL && TOP(after) == TOP(edge))
+                       h -= touches(h, rightedge->xvalues, after->xvalues);
+               if (h < h0)
+                       SortSwath(before0->link, splitedge(edge, edge->ymin + h), t1_SwathUnion);
+               /* go to "return" this edge pair; it is totally disjoint */
+       }
+       else {
+/*
+At this point, at the 'else', we know that the
+new edge overlaps one or more pairs in the existing swath.  Here is
+a picture of our knowledge and uncertainties:
+:xmp atomic.
+   before       after
+     R            L        R     L   R    L   R
+            <---L--->   <---R------------------->
+               edge
+:exmp.
+We need to move 'after' along until it is to the right of the
+right of 'edge'.  ('After' should always point to a left edge of a pair:)
+*/
+               register struct edgelist *left;  /* variable to keep left edge in */
+               do {
+                        left = after;
+                        after = (after->link)->link;
+               } while  (after != NULL && TOP(after) == TOP(edge)
+                               && after->xvalues[0] <= rightedge->xvalues[0]);
+/*
+At this point this is the picture:
+:xmp atomic.
+   before                 left        after
+     R            L    R   L      R     L   R
+            <---L--->        <---R--->
+               edge
+:exmp.
+We need to verify that the situation stays like this all the way
+down the edge.  Again, if the
+situation changes somewhere down the edge, we split the edge at that
+point and recursively call ourselves (through 'SortSwath') to figure
+out the new situation:
+*/
+               h -= crosses(h, left->xvalues, rightedge->xvalues);
+               h -= crosses(h, edge->xvalues, ((before->link)->link)->xvalues);
+               if (after != NULL && TOP(after) == TOP(edge))
+                       h -= touches(h, rightedge->xvalues, after->xvalues);
+               IfTrace3((RegionDebug > 1),
+                      "SwathUnion is overlapped until %d: before=%x after=%x\n",
+                                          (long) TOP(edge) + h, before, after);
+/*
+OK, if we touched either of our neighbors we need to split at that point
+and recursively sort the split edge onto the list.  One tricky part
+is that when we recursively sort, 'after' will change if it was not
+in our current swath:
+*/
+               if (h < h0) {
+                       SortSwath(before0->link,
+                                 splitedge(edge, edge->ymin + h),
+                                 t1_SwathUnion);
+                       if (after == NULL || TOP(after) != TOP(edge))
+                                 for (after = before0->link;
+                                      TOP(after) == TOP(edge);
+                                      after = after->link) { ; }
+               }
+/*
+Now we need to augment 'edge' by the left and right of the overlapped
+swath, and to discard all edges between before and after, because they
+were overlapped and have been combined with the new incoming 'edge':
+*/
+               edge->xmin = MIN(edge->xmin, (before->link)->xmin);
+               edge->xmax = MIN(edge->xmax, (before->link)->xmax);
+               edgemin(h, edge->xvalues, (before->link)->xvalues);
+               rightedge->xmin = MAX(rightedge->xmin, (left->link)->xmin);
+               rightedge->xmax = MAX(rightedge->xmax, (left->link)->xmax);
+               edgemax(h, rightedge->xvalues, (left->link)->xvalues);
+               discard(before, after);
+       }
+       return(before);
+}
+/*
+:h3.swathrightmost() - Simply Sorts New Edge to Rightmost of Swath
+Like all swath functions, this function returns a pointer to the edge
+BEFORE the given edge in the sort.
+*/
+static struct edgelist *swathrightmost(before, edge)
+       register struct edgelist *before;  /* edge before this swath         */
+       register struct edgelist *edge;  /* input edge                        */
+{
+       register struct edgelist *after;
+       after = before->link;
+       while (after != NULL && TOP(after) == TOP(edge)) {
+               before = after;
+               after = after->link;
+       }
+       return(before);
+}
+/*
+:h3.touches() - Returns the Remaining Height When Two Edges Touch
+So, it will return 0 if they never touch.  Allows incredibly(?) mnemonic
+if (touches(...)) construct.
+*/
+static int touches(h, left, right)
+       register int h;
+       register pel *left,*right;
+{
+       for (; h > 0; h--)
+               if (*left++ >= *right++)
+                       break;
+       return(h);
+}
+/*
+:h3.crosses() - Returns the Remaining Height When Two Edges Cross
+So, it will return 0 if they never cross.
+*/
+static int crosses(h, left, right)
+       register int h;
+       register pel *left,*right;
+{
+       for (; h > 0; h--)
+               if (*left++ > *right++)
+                       break;
+       return(h);
+}
+/*
+:h3.cedgemin() - Stores the Mininum of an Edge and an X Value
+*/
+static void cedgemin(h, e1, x)
+       register int h;
+       register pel *e1;
+       register pel x;
+{
+       for (; --h >= 0; e1++)
+               if (*e1 > x)
+                       *e1 = x;
+}
+/*
+:h3.cedgemax() - Stores the Maximum of an Edge and an X Value
+*/
+static void cedgemax(h, e1, x)
+       register int h;
+       register pel *e1;
+       register pel x;
+{
+       for (; --h >= 0; e1++)
+               if (*e1 < x)
+                       *e1 = x;
+}
+/*
+:h3.edgemin() - Stores the Mininum of Two Edges in First Edge
+*/
+static void edgemin(h, e1, e2)
+       register int h;
+       register pel *e1,*e2;
+{
+       for (; --h >= 0; e1++,e2++)
+               if (*e1 > *e2)
+                       *e1 = *e2;
+}
+/*
+:h3.edgemax() - Stores the Maximum of Two Edges in First Edge
+*/
+static void edgemax(h, e1, e2)
+       register int h;
+       register pel *e1,*e2;
+{
+       for (; --h >= 0; e1++,e2++)
+               if (*e1 < *e2)
+                       *e1 = *e2;
+}
+/*
+:h3 id=discard.discard() - Discard All Edges Between Two Edges
+At first glance it would seem that we could discard an edgelist
+structure merely by unlinking it from the list and freeing it.  You are
+wrong, region-breath!  For performance, the X values associated with an
+edge are allocated contiguously with it.  So, we free the X values when
+we free a structure.  However, once an edge has been split, we are no
+longer sure which control block actually is part of the memory block
+that contains the edges.  Rather than trying to decide, we play it safe
+and never free part of a region.
+So, to mark a 'edgelist' structure as discarded, we move it to the end
+of the list and set ymin=ymax.
+*/
+static discard(left, right)
+       register struct edgelist *left,*right;  /* all edges between here exclusive */
+                                       /* should be discarded */
+{
+       register struct edgelist *beg,*end,*p;
+       IfTrace2((RegionDebug > 0),"discard:  l=%x, r=%x\n", left, right);
+       beg = left->link;
+       if (beg == right)
+               return;
+       for (p = beg; p != right; p = p->link) {
+               if (p->link == NULL && right != NULL)
+                       abort("discard():  ran off end");
+               IfTrace1((RegionDebug > 0),"discarding %x\n", p);
+               p->ymin = p->ymax = 32767;
+               end = p;
+       }
+       /*
+       * now put the chain beg/end at the end of right, if it is not
+       * already there:
+       */
+       if (right != NULL) {
+               left->link = right;
+               while (right->link != NULL)
+                       right = right->link;
+               right->link = beg;
+       }
+       end->link = NULL;
+}
+/*
+:h2.Changing the Representation of Regions
+For convenience and/or performance, we sometimes like to change the way
+regions are represented.  This does not change the object itself, just
+the representation, so these transformations can be made on a permanent
+region.
+*/
+void MoveEdges(R, dx, dy)
+       register struct region *R; /* region to modify                        */
+       register fractpel dx,dy;  /* delta X and Y to move edge list by       */
+{
+       register struct edgelist *edge;  /* for looping through edges         */
+       R->origin.x += dx;
+       R->origin.y += dy;
+       R->ending.x += dx;
+       R->ending.y += dy;
+       if (R->thresholded != NULL) {
+               R->thresholded->origin.x -= dx;
+               R->thresholded->origin.y -= dy;
+       }
+/*
+From now on we will deal with dx and dy as integer pel values:
+*/
+       dx = NEARESTPEL(dx);
+       dy = NEARESTPEL(dy);
+       if (dx == 0 && dy == 0)
+               return;
+       R->xmin += dx;
+       R->xmax += dx;
+       R->ymin += dy;
+       R->ymax += dy;
+       for (edge = R->anchor; VALIDEDGE(edge); edge = edge->link) {
+               edge->ymin += dy;
+               edge->ymax += dy;
+               if (dx != 0) {
+                       register int h;  /* loop index; height of edge        */
+                       register pel *Xp;  /* loop pointer to X values        */
+                       edge->xmin += dx;
+                       edge->xmax += dx;
+                       for (Xp = edge->xvalues, h = edge->ymax - edge->ymin;
+                                     --h >= 0; )
+                               *Xp++ += dx;
+               }
+       }
+}
+/*
+:h3.UnJumble() - Sort a Region Top to Bottom
+It is an open question whether it pays in general to do this.
+*/
+void UnJumble(region)
+       struct region *region;  /* region to sort                             */
+{
+       register struct edgelist *anchor;  /* new lists built here            */
+       register struct edgelist *edge;  /* edge pointer for loop             */
+       register struct edgelist *next;  /* ditto                             */
+       anchor = NULL;
+       for (edge=region->anchor; VALIDEDGE(edge); edge=next) {
+               if (edge->link == NULL)
+                       abort("UnJumble:  unpaired edge?");
+               next = edge->link->link;
+               edge->link->link = NULL;
+               anchor = SortSwath(anchor, edge, t1_SwathUnion);
+       }
+       if (edge != NULL)
+               vertjoin(anchor, edge);
+       region->anchor = anchor;
+       region->flag &= ~ISJUMBLED(ON);
+}
+/*
+*/
+static OptimizeRegion(R)
+       struct region *R;     /* region to optimize                           */
+{
+       register pel *xP;     /* pel pointer for inner loop                   */
+       register int x;       /* holds X value                                */
+       register int xmin,xmax;  /* holds X range                             */
+       register int h;       /* loop counter                                 */
+       register struct edgelist *e;  /* edgelist pointer for loop            */
+       R->flag |= ISRECTANGULAR(ON);
+       for (e = R->anchor; VALIDEDGE(e); e=e->link) {
+               xmin = MAXPEL;
+               xmax = MINPEL;
+               for (h = e->ymax - e->ymin, xP = e->xvalues; --h >= 0;) {
+                         x = *xP++;
+                         if (x < xmin)  xmin = x;
+                         if (x > xmax)  xmax = x;
+               }
+               if (xmin != xmax || (xmin != R->xmin && xmax != R->xmax))
+                       R->flag &= ~ISRECTANGULAR(ON);
+               if (xmin < e->xmin || xmax > e->xmax)
+                       abort("Tighten: existing edge bound was bad");
+               if (xmin < R->xmin || xmax > R->xmax)
+                       abort("Tighten: existing region bound was bad");
+               e->xmin = xmin;
+               e->xmax = xmax;
+       }
+       R->flag |= ISOPTIMIZED(ON);
+}
+/*
+:h2.Miscelaneous Routines
+:h3.MoreWorkArea() - Allocate New Space for "edge"
+Our strategy is to temporarily allocate an array to hold this
+unexpectedly large edge.  ChangeDirection frees this array any time
+it gets a shorter 'dy'.
+*/
+/*ARGSUSED*/
+void MoreWorkArea(R, x1, y1, x2, y2)
+       struct region *R;     /* region we are generating                     */
+       fractpel x1,y1;       /* starting point of line                       */
+       fractpel x2,y2;       /* ending point of line                         */
+{
+       register int idy;     /* integer dy of line                           */
+       idy = NEARESTPEL(y1) - NEARESTPEL(y2);
+       if (idy < 0)  idy = - idy;
+       /*
+       * we must add one to the delta for the number of run ends we
+       * need to store:
+       */
+       if (++idy > currentsize) {
+               IfTrace1((RegionDebug > 0),"Allocating edge of %d pels\n", idy);
+               if (currentworkarea != workedge)
+                       NonObjectFree(currentworkarea);
+               currentworkarea = (pel *)Allocate(0, NULL, idy * sizeof(pel));
+               currentsize = idy;
+       }
+       ChangeDirection(CD_CONTINUE, R, x1, y1, y2 - y1);
+}
+/*
+:h3.BoxClip() - Clip a Region to a Rectangle
+BoxClip also duplicates the region if it is permanent.  Note the
+clipping box is specified in REGION coordinates, that is, in
+coordinates relative to the region (0,0) point
+*/
+struct region *BoxClip(R, xmin, ymin, xmax, ymax)
+       register struct region *R;  /* region to clip                         */
+       register pel xmin,ymin;  /* upper left hand corner of rectangle       */
+       register pel xmax,ymax;  /* lower right hand corner                   */
+{
+       struct edgelist anchor;  /* pretend edgelist to facilitate discards   */
+       register struct edgelist *e,*laste;
+       IfTrace1((OffPageDebug),"BoxClip of %z:\n", R);
+       R = UniqueRegion(R);
+       if (xmin > R->xmin) {
+               IfTrace2((OffPageDebug),"BoxClip:  left clip old %d new %d\n",
+                                            (long) R->xmin, (long) xmin);
+               R->xmin = xmin;
+       }
+       if (xmax < R->xmax) {
+               IfTrace2((OffPageDebug),"BoxClip:  right clip old %d new %d\n",
+                                            (long) R->xmax, (long) xmax);
+               R->xmax = xmax;
+       }
+       if (ymin > R->ymin) {
+               IfTrace2((OffPageDebug),"BoxClip:  top clip old %d new %d\n",
+                                            (long) R->ymin, (long) ymin);
+               R->ymin = ymin;
+       }
+       if (ymax < R->ymax) {
+               IfTrace2((OffPageDebug),"BoxClip:  bottom clip old %d new %d\n",
+                                            (long) R->ymax, (long) ymax);
+               R->ymax = ymax;
+       }
+       laste = &anchor;
+       anchor.link = R->anchor;
+       for (e = R->anchor; VALIDEDGE(e); e = e->link) {
+               if (TOP(e) < ymin) {
+                       e->xvalues += ymin - e->ymin;
+                       e->ymin = ymin;
+               }
+               if (BOTTOM(e) > ymax)
+                       e->ymax = ymax;
+               if (TOP(e) >= BOTTOM(e)) {
+                       discard(laste, e->link->link);
+                       e = laste;
+                       continue;
+               }
+               if (e->xmin < xmin) {
+                       cedgemax(BOTTOM(e) - TOP(e), e->xvalues, xmin);
+                       e->xmin = xmin;
+                       e->xmax = MAX(e->xmax, xmin);
+               }
+               if (e->xmax > xmax) {
+                       cedgemin(BOTTOM(e) - TOP(e), e->xvalues, xmax);
+                       e->xmin = MIN(e->xmin, xmax);
+                       e->xmax = xmax;
+               }
+               laste = e;
+       }
+       R->anchor = anchor.link;
+       return(R);
+}
+#ifdef notdef
+/*
+:h3.CoerceRegion() - Force a TextPath Structure to Become a Region
+We also save the newly created region in the textpath structure, if the
+structure was permanent.  Then we don't have to do this again.  Why not
+save it all the time?  Well, we certainly could, but I suspect it
+wouldn't pay.  We would have to make this region permanent (because we
+couldn't have it be consumed) and this would probably require
+unnecessary CopyRegions in most cases.
+*/
+struct region *CoerceRegion(tp)
+       register struct textpath *tp;  /* input TEXTTYPE                     */
+{
+       struct segment *path; /* temporary character path                     */
+       struct region *R;     /* returned region                              */
+       R = Interior(path, EVENODDRULE);
+       return(R);
+}
+#endif
+/*
+:h3.RegionBounds() - Returns Bounding Box of a Region
+*/
+struct segment *RegionBounds(R)
+       register struct region *R;
+{
+       extern struct XYspace *IDENTITY;
+       register struct segment *path;  /* returned path                      */
+       path = BoxPath(IDENTITY, R->ymax - R->ymin, R->xmax - R->xmin);
+       path = Join(PathSegment(MOVETYPE, R->origin.x + TOFRACTPEL(R->xmin),
+                                         R->origin.y + TOFRACTPEL(R->ymin) ),
+                   path);
+       return(path);
+}
+/*
+:h2.Formatting/Dump Routines for Debug
+:h3.DumpArea() - Display a Region
+*/
+void DumpArea(area)
+       register struct region *area;
+{
+       IfTrace1(TRUE,"Dumping area %x,", area);
+       IfTrace4(TRUE," X %d:%d Y %d:%d;", (long) area->xmin,
+                      (long) area->xmax, (long) area->ymin,(long) area->ymax);
+       IfTrace4(TRUE," origin=(%p,%p), ending=(%p,%p)\n",
+               area->origin.x, area->origin.y, area->ending.x, area->ending.y);
+       DumpEdges(area->anchor);
+}
+#define  INSWATH(p, y0, y1)  (p != NULL && p->ymin == y0 && p->ymax == y1)
+/*
+:h3.DumpEdges() - Display Run End Lists (Edge Lists)
+*/
+static pel RegionDebugYMin = MINPEL;
+static pel RegionDebugYMax = MAXPEL;
+void DumpEdges(edges)
+       register struct edgelist *edges;
+{
+       register struct edgelist *p,*p2;
+       register pel ymin = MINPEL;
+       register pel ymax = MINPEL;
+       register int y;
+       if (edges == NULL) {
+               IfTrace0(TRUE,"    NULL area.\n");
+               return;
+       }
+       if (RegionDebug <= 1) {
+               for (p=edges; p != NULL; p = p->link) {
+                       edgecheck(p, ymin, ymax);
+                       ymin = p->ymin;  ymax = p->ymax;
+                       IfTrace3(TRUE,". at %x type=%d flag=%x",
+                                        p, (long) p->type,(long) p->flag);
+                       IfTrace4(TRUE," bounding box HxW is %dx%d at (%d,%d)\n",
+                               (long) ymax - ymin, (long) p->xmax - p->xmin,
+                               (long) p->xmin, (long) ymin);
+               }
+       }
+       else {
+               for (p2=edges; p2 != NULL; ) {
+                       edgecheck(p2, ymin, ymax);
+                       ymin = p2->ymin;
+                       ymax = p2->ymax;
+                       if (RegionDebug > 3 || (ymax > RegionDebugYMin
+                                   && ymin < RegionDebugYMax)) {
+                               IfTrace2 (TRUE,". Swath from %d to %d:\n",
+                                                              ymin, ymax);
+                               for (p=p2; INSWATH(p,ymin,ymax); p = p->link) {
+                                       IfTrace4(TRUE,". . at %x[%x] range %d:%d, ",
+                                                 p, (long) p->flag,
+                                                 (long) p->xmin, (long)p->xmax);
+                                       IfTrace1(TRUE, "subpath=%x,\n", p->subpath);
+                               }
+                       }
+                       for (y=MAX(ymin,RegionDebugYMin); y < MIN(ymax, RegionDebugYMax); y++) {
+                               IfTrace1(TRUE,". . . Y[%5d] ", (long) y);
+                               for (p=p2; INSWATH(p,ymin,ymax); p = p->link)
+                                       IfTrace1(TRUE,"%5d ",
+                                                (long) p->xvalues[y - ymin]);
+                               IfTrace0(TRUE,"\n");
+                       }
+                       while (INSWATH(p2, ymin, ymax))
+                               p2 = p2->link;
+               }
+       }
+}
+/*
+:h3.edgecheck() - For Debug, Verify that an Edge Obeys the Rules
+*/
+/*ARGSUSED*/
+static edgecheck(edge, oldmin, oldmax)
+       struct edgelist *edge;
+       int oldmin,oldmax;
+{
+       if (edge->type != EDGETYPE)
+               abort("EDGE ERROR: non EDGETYPE in list");
+/*
+The following check is not valid if the region is jumbled so I took it
+out:
+*/
+/*     if (edge->ymin < oldmax && edge->ymin != oldmin)
+               abort("EDGE ERROR: overlapping swaths"); */
+}
diff --git a/Xserver/lib/font/Type1/regions.h b/Xserver/lib/font/Type1/regions.h
new file mode 100644 (file)
index 0000000..4cfa5e8
--- /dev/null
@@ -0,0 +1,213 @@
+/* $XConsortium: regions.h,v 1.6 94/04/02 15:49:51 rws Exp $ */
+/* Copyright International Business Machines, Corp. 1991
+ * All Rights Reserved
+ * Copyright Lexmark International, Inc. 1991
+ * All Rights Reserved
+ *
+ * License to use, copy, modify, and distribute this software and its
+ * documentation for any purpose and without fee is hereby granted,
+ * provided that the above copyright notice appear in all copies and that
+ * both that copyright notice and this permission notice appear in
+ * supporting documentation, and that the name of IBM or Lexmark not be
+ * used in advertising or publicity pertaining to distribution of the
+ * software without specific, written prior permission.
+ *
+ * IBM AND LEXMARK PROVIDE THIS SOFTWARE "AS IS", WITHOUT ANY WARRANTIES OF
+ * ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING, BUT NOT LIMITED TO ANY
+ * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE,
+ * AND NONINFRINGEMENT OF THIRD PARTY RIGHTS.  THE ENTIRE RISK AS TO THE
+ * QUALITY AND PERFORMANCE OF THE SOFTWARE, INCLUDING ANY DUTY TO SUPPORT
+ * OR MAINTAIN, BELONGS TO THE LICENSEE.  SHOULD ANY PORTION OF THE
+ * SOFTWARE PROVE DEFECTIVE, THE LICENSEE (NOT IBM OR LEXMARK) ASSUMES THE
+ * ENTIRE COST OF ALL SERVICING, REPAIR AND CORRECTION.  IN NO EVENT SHALL
+ * IBM OR LEXMARK BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
+ * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
+ * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
+ * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
+ * THIS SOFTWARE.
+ */
+/*SHARED*/
+#define   Interior(p,rule)        t1_Interior(p,rule)
+#define   Union(a1,a2)            t1_Union(a1,a2)
+#define   Intersect(a1,a2)        t1_Intersect(a1,a2)
+#define   Complement(area)        t1_Complement(area)
+#define   Overlap(a1,a2)          t1_OverLap(a1,a2)
+struct region *t1_Interior(); /* returns the interior of a closed path        */
+struct region *t1_Union();   /* set union of paths or regions                */
+struct region *t1_Intersect();  /* set intersection of regions                */
+struct region *t1_Complement();  /* complement of a region                    */
+int t1_Overlap();             /* returns a Boolean; TRUE if regions overlap   */
+#define   INFINITY    t1_Infinity
+/*END SHARED*/
+/*SHARED*/
+#define   ChangeDirection(type,R,x,y,dy)  t1_ChangeDirection(type,R,x,y,dy)
+void t1_ChangeDirection();    /* called when we change direction in Y         */
+#define   CD_FIRST         -1  /* enumeration of ChangeDirection type       */
+#define   CD_CONTINUE       0  /* enumeration of ChangeDirection type        */
+#define   CD_LAST           1  /* enumeration of ChangeDirection type        */
+#define    MoreWorkArea(R,x1,y1,x2,y2)     t1_MoreWorkArea(R,x1,y1,x2,y2)
+#define    KillRegion(area)   t1_KillRegion(area)
+#define    CopyRegion(area)   t1_CopyRegion(area)
+#define    BoxClip(R,xmin,ymin,xmax,ymax)  t1_BoxClip(R,xmin,ymin,xmax,ymax)
+#define    SortSwath(a,p,f)   t1_SortSwath(a,p,f)
+#define    SwathUnion(b,e)    t1_SwathUnion(b,e)
+#define    RegionBounds(r)    t1_RegionBounds(r)
+#define    CoerceRegion(p)    t1_CoerceRegion(p)
+#define    MoveEdges(R,dx,dy) t1_MoveEdges(R,dx,dy)
+#define    UnJumble(R)        t1_UnJumble(R)
+void t1_MoreWorkArea();       /* get longer edge list for stepping            */
+struct region *t1_CopyRegion();  /* duplicate a region                       */
+void t1_KillRegion();         /* destroy a region                             */
+struct region *t1_BoxClip();  /* clip a region to a rectangle                 */
+struct edgelist *t1_SortSwath();  /* sort edges onto growing edge list        */
+struct edgelist *t1_SwathUnion();  /* 'union' two edges into a swath          */
+struct segment *t1_RegionBounds();  /* returns bounding box of a region       */
+struct region *t1_CoerceRegion();  /* force text to become a true region      */
+void t1_MoveEdges();          /* moves the edge values in a region            */
+void t1_UnJumble();           /* sort the edges and reset the jumbled flag    */
+/*END SHARED*/
+/*SHARED*/
+#define GOING_TO(R, x1, y1, x2, y2, dy) { \
+   if (dy < 0) { \
+      if (R->lastdy >= 0) \
+          ChangeDirection(CD_CONTINUE, R, x1, y1, dy); \
+      if (y2 < R->edgeYstop) \
+          MoreWorkArea(R, x1, y1, x2, y2); \
+   } \
+   else if (dy > 0) { \
+      if (R->lastdy <= 0) \
+          ChangeDirection(CD_CONTINUE, R, x1, y1, dy); \
+      if (y2 > R->edgeYstop) \
+          MoreWorkArea(R, x1, y1, x2, y2); \
+   } \
+   else /* dy == 0 */ ChangeDirection(CD_CONTINUE, R, x1, y1, dy); \
+   if (x2 < R->edgexmin) R->edgexmin = x2; \
+   else if (x2 > R->edgexmax) R->edgexmax = x2; \
+}
+#ifndef __sxg__
+#include <limits.h>
+#endif
+#ifdef SHRT_MIN
+#define MINPEL SHRT_MIN
+#else
+#define MINPEL ((pel)(-1<<(8*sizeof(pel)-1)))  /* smallest value fitting in a pel */
+#endif
+#ifdef SHRT_MAX
+#define MAXPEL SHRT_MAX
+#else
+#define MAXPEL ((pel)((1<<(8*sizeof(pel)-1))-1))/* largest value fitting in a pel */
+#endif
+/*
+The "Unique"-type macro is different (unique?) for regions, because some
+regions structures are shared among several objects, and might have
+to be made unique for that reason (i.e., references > 1).
+*/
+#define    ConsumeRegion(R)   MAKECONSUME(R,KillRegion(R))
+#define    UniqueRegion(R)    MAKEUNIQUE(R,CopyRegion(R))
+/*END SHARED*/
+/*SHARED*/
+struct region {
+       XOBJ_COMMON           /* xobject common data define 3-26-91 PNM    */
+                             /* type = REGIONTYPE                         */
+       struct fractpoint origin;    /* beginning handle:  X,Y origin of region      */
+       struct fractpoint ending;    /* ending handle:  X,Y change after painting region */
+       pel xmin,ymin;        /* minimum X,Y of region                        */
+       pel xmax,ymax;        /* mat1_mum X,Y of region                        */
+       struct edgelist *anchor;  /* list of edges that bound the region      */
+       struct picture *thresholded;  /* region defined by thresholded picture*/
+/*
+Note that the ending handle and the bounding box values are stored
+relative to 'origin'.
+The above elements describe a region.  The following elements are
+scratchpad areas used while the region is being built:
+*/
+       fractpel lastdy;      /* direction of last segment                    */
+       fractpel firstx,firsty;    /* starting point of current edge          */
+       fractpel edgexmin,edgexmax;  /* x extent of current edge              */
+       struct edgelist *lastedge,*firstedge;  /* last and first edges in subpath */
+       pel *edge;            /* pointer to array of X values for edge        */
+       fractpel edgeYstop;   /* Y value where 'edges' array ends             */
+       void (*newedgefcn)();  /* function to use when building a new edge    */
+       struct strokeinfo *strokeinfo;  /* scratchpad info during stroking only */
+} ;
+/*
+The ISCOMPLEMENT flag indicates the region is reversed--it is the
+"outside" of the nominal region.
+*/
+#define   ISCOMPLEMENT(flag)   ((flag)&0x80)
+/*
+The ISJUMBLED flag indicates the region is not sorted top-to-bottom.
+*/
+#define   ISJUMBLED(flag)      ((flag)&0x40)
+/*
+The ISINFINITE flag allows a quick check for an INFINITE region, which
+is frequently intersected.
+*/
+#define   ISINFINITE(flag)     ((flag)&0x20)
+/*END SHARED*/
+/*SHARED*/
+#define   ISRECTANGULAR(flag)  ((flag)&0x08)
+/*END SHARED*/
+/*SHARED*/
+#define  EmptyRegion   t1_EmptyRegion
+/*END SHARED*/
+/*SHARED*/
+struct edgelist {
+       XOBJ_COMMON          /* xobject common data define 3-26-91 PNM        */
+                            /* type = EDGETYPE                               */
+       struct edgelist *link;  /* pointer to next in linked list             */
+       struct edgelist *subpath;  /* informational link for "same subpath"   */
+       pel xmin,xmax;        /* range of edge in X                           */
+       pel ymin,ymax;        /* range of edge in Y                           */
+       pel *xvalues;         /* pointer to ymax-ymin X values                */
+} ;
+/*
+The end of the list is marked by either "link" being NULL, or by
+ymin == ymax.  See :hdref refid=discard..  We define the VALIDEDGE
+predicate to test for the opposite of these conditions:
+*/
+#define   VALIDEDGE(p)    ((p)!=NULL&&(p)->ymin<(p)->ymax)
+/*END SHARED*/
+/*SHARED*/
+#define   ISDOWN(f)       ((f)&0x80)
+#define   ISAMBIGUOUS(f)  ((f)&0x40)
+/*END SHARED*/
+/*SHARED*/
+/*
+Interior() rule enumerations:
+*/
+#define   WINDINGRULE -2
+#define   EVENODDRULE -3
+#define   CONTINUITY  0x80   /* can be added to above rules; e.g. WINDINGRULE+CONTINUITY */
+/*END SHARED*/
diff --git a/Xserver/lib/font/Type1/scanfont.c b/Xserver/lib/font/Type1/scanfont.c
new file mode 100644 (file)
index 0000000..8692ad5
--- /dev/null
@@ -0,0 +1,1514 @@
+/* $TOG: scanfont.c /main/11 1997/06/09 13:27:16 barstow $ */
+/* Copyright International Business Machines,Corp. 1991
+ * All Rights Reserved
+ *
+ * License to use, copy, modify, and distribute this software
+ * and its documentation for any purpose and without fee is
+ * hereby granted, provided that the above copyright notice
+ * appear in all copies and that both that copyright notice and
+ * this permission notice appear in supporting documentation,
+ * and that the name of IBM not be used in advertising or
+ * publicity pertaining to distribution of the software without
+ * specific, written prior permission.
+ *
+ * IBM PROVIDES THIS SOFTWARE "AS IS", WITHOUT ANY WARRANTIES
+ * OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING, BUT NOT
+ * LIMITED TO ANY IMPLIED WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, AND NONINFRINGEMENT OF
+ * THIRD PARTY RIGHTS.  THE ENTIRE RISK AS TO THE QUALITY AND
+ * PERFORMANCE OF THE SOFTWARE, INCLUDING ANY DUTY TO SUPPORT
+ * OR MAINTAIN, BELONGS TO THE LICENSEE.  SHOULD ANY PORTION OF
+ * THE SOFTWARE PROVE DEFECTIVE, THE LICENSEE (NOT IBM) ASSUMES
+ * THE ENTIRE COST OF ALL SERVICING, REPAIR AND CORRECTION.  IN
+ * NO EVENT SHALL IBM BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
+ * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
+ * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
+ * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+ */
+/* Author: Katherine A. Hitchcock    IBM Almaden Research Laboratory */
+#include <string.h>
+#include "t1stdio.h"
+#include "util.h"
+#include "token.h"
+#include "fontfcn.h"
+#include "blues.h"
+static int rc;
+static boolean InPrivateDict;
+static boolean WantFontInfo;
+static boolean TwoSubrs;
+static psobj inputFile;
+static psobj filterFile;
+static psobj *inputP;
+/**********************************************************************/
+/*   Init_BuiltInEncoding()                                           */
+/*                                                                    */
+/*     Initializes the StandardEncoding and ISOLatin1Encoding vector. */
+/*                                                                    */
+/**********************************************************************/
+typedef struct                         /* Builtin Standard Encoding */
+{
+   int  index;
+   char *name;
+} EncodingTable;
+
+static EncodingTable StdEnc[] = {
+   040 , "space",
+   041 , "exclam",
+   042 , "quotedbl",
+   043 , "numbersign",
+   044 , "dollar",
+   045 , "percent",
+   046 , "ampersand",
+   047 , "quoteright",
+   050 , "parenleft",
+   051 , "parenright",
+   052 , "asterisk",
+   053 , "plus",
+   054 , "comma",
+   055 , "hyphen",
+   056 , "period",
+   057 , "slash",
+   060 , "zero",
+   061 , "one",
+   062 , "two",
+   063 , "three",
+   064 , "four",
+   065 , "five",
+   066 , "six",
+   067 , "seven",
+   070 , "eight",
+   071 , "nine",
+   072 , "colon",
+   073 , "semicolon",
+   074 , "less",
+   075 , "equal",
+   076 , "greater",
+   077 , "question",
+  0100 , "at",
+  0101 , "A",
+  0102 , "B",
+  0103 , "C",
+  0104 , "D",
+  0105 , "E",
+  0106 , "F",
+  0107 , "G",
+  0110 , "H",
+  0111 , "I",
+  0112 , "J",
+  0113 , "K",
+  0114 , "L",
+  0115 , "M",
+  0116 , "N",
+  0117 , "O",
+  0120 , "P",
+  0121 , "Q",
+  0122 , "R",
+  0123 , "S",
+  0124 , "T",
+  0125 , "U",
+  0126 , "V",
+  0127 , "W",
+  0130 , "X",
+  0131 , "Y",
+  0132 , "Z",
+  0133 , "bracketleft",
+  0134 , "backslash",
+  0135 , "bracketright",
+  0136 , "asciicircum",
+  0137 , "underscore",
+  0140 , "quoteleft",
+  0141 , "a",
+  0142 , "b",
+  0143 , "c",
+  0144 , "d",
+  0145 , "e",
+  0146 , "f",
+  0147 , "g",
+  0150 , "h",
+  0151 , "i",
+  0152 , "j",
+  0153 , "k",
+  0154 , "l",
+  0155 , "m",
+  0156 , "n",
+  0157 , "o",
+  0160 , "p",
+  0161 , "q",
+  0162 , "r",
+  0163 , "s",
+  0164 , "t",
+  0165 , "u",
+  0166 , "v",
+  0167 , "w",
+  0170 , "x",
+  0171 , "y",
+  0172 , "z",
+  0173 , "braceleft",
+  0174 , "bar",
+  0175 , "braceright",
+  0176 , "asciitilde",
+  0241 , "exclamdown",
+  0242 , "cent",
+  0243 , "sterling",
+  0244 , "fraction",
+  0245 , "yen",
+  0246 , "florin",
+  0247 , "section",
+  0250 , "currency",
+  0251 , "quotesingle",
+  0252 , "quotedblleft",
+  0253 , "guillemotleft",
+  0254 , "guilsinglleft",
+  0255 , "guilsinglright",
+  0256 , "fi",
+  0257 , "fl",
+  0261 , "endash",
+  0262 , "dagger",
+  0263 , "daggerdbl",
+  0264 , "periodcentered",
+  0266 , "paragraph",
+  0267 , "bullet",
+  0270 , "quotesinglbase",
+  0271 , "quotedblbase",
+  0272 , "quotedblright",
+  0273 , "guillemotright",
+  0274 , "ellipsis",
+  0275 , "perthousand",
+  0277 , "questiondown",
+  0301 , "grave",
+  0302 , "acute",
+  0303 , "circumflex",
+  0304 , "tilde",
+  0305 , "macron",
+  0306 , "breve",
+  0307 , "dotaccent",
+  0310 , "dieresis",
+  0312 , "ring",
+  0313 , "cedilla",
+  0315 , "hungarumlaut",
+  0316 , "ogonek",
+  0317 , "caron",
+  0320 , "emdash",
+  0341 , "AE",
+  0343 , "ordfeminine",
+  0350 , "Lslash",
+  0351 , "Oslash",
+  0352 , "OE",
+  0353 , "ordmasculine",
+  0361 , "ae",
+  0365 , "dotlessi",
+  0370 , "lslash",
+  0371 , "oslash",
+  0372 , "oe",
+  0373 , "germandbls",
+    0,      0
+};
+
+static EncodingTable ISO8859Enc[] = {
+  32, "space",
+  33, "exclam",
+  34, "quotedbl",
+  35, "numbersign",
+  36, "dollar",
+  37, "percent",
+  38, "ampersand",
+  39, "quoteright",
+  40, "parenleft",
+  41, "parenright",
+  42, "asterisk",
+  43, "plus",
+  44, "comma",
+  45, "minus",
+  46, "period",
+  47, "slash",
+  48, "zero",
+  49, "one",
+  50, "two",
+  51, "three",
+  52, "four",
+  53, "five",
+  54, "six",
+  55, "seven",
+  56, "eight",
+  57, "nine",
+  58, "colon",
+  59, "semicolon",
+  60, "less",
+  61, "equal",
+  62, "greater",
+  63, "question",
+  64, "at",
+  65, "A",
+  66, "B",
+  67, "C",
+  68, "D",
+  69, "E",
+  70, "F",
+  71, "G",
+  72, "H",
+  73, "I",
+  74, "J",
+  75, "K",
+  76, "L",
+  77, "M",
+  78, "N",
+  79, "O",
+  80, "P",
+  81, "Q",
+  82, "R",
+  83, "S",
+  84, "T",
+  85, "U",
+  86, "V",
+  87, "W",
+  88, "X",
+  89, "Y",
+  90, "Z",
+  91, "bracketleft",
+  92, "backslash",
+  93, "bracketright",
+  94, "asciicircum",
+  95, "underscore",
+  96, "quoteleft",
+  97, "a",
+  98, "b",
+  99, "c",
+ 100, "d",
+ 101, "e",
+ 102, "f",
+ 103, "g",
+ 104, "h",
+ 105, "i",
+ 106, "j",
+ 107, "k",
+ 108, "l",
+ 109, "m",
+ 110, "n",
+ 111, "o",
+ 112, "p",
+ 113, "q",
+ 114, "r",
+ 115, "s",
+ 116, "t",
+ 117, "u",
+ 118, "v",
+ 119, "w",
+ 120, "x",
+ 121, "y",
+ 122, "z",
+ 123, "braceleft",
+ 124, "bar",
+ 125, "braceright",
+ 126, "asciitilde",
+ 161, "exclamdown",
+ 162, "cent",
+ 163, "sterling",
+ 164, "currency",
+ 165, "yen",
+ 166, "brokenbar",
+ 167, "section",
+ 168, "dieresis",
+ 169, "copyright",
+ 170, "ordfeminine",
+ 171, "guillemotleft",
+ 172, "logicalnot",
+ 173, "hyphen",
+ 174, "registered",
+ 175, "macron",
+ 176, "degree",
+ 177, "plusminus",
+ 178, "twosuperior",
+ 179, "threesuperior",
+ 180, "acute",
+ 181, "mu",
+ 182, "paragraph",
+ 183, "periodcentered",
+ 184, "cedilla",
+ 185, "onesuperior",
+ 186, "ordmasculine",
+ 187, "guillemotright",
+ 188, "onequarter",
+ 189, "onehalf",
+ 190, "threequarters",
+ 191, "questiondown",
+ 192, "Agrave",
+ 193, "Aacute",
+ 194, "Acircumflex",
+ 195, "Atilde",
+ 196, "Adieresis",
+ 197, "Aring",
+ 198, "AE",
+ 199, "Ccedilla",
+ 200, "Egrave",
+ 201, "Eacute",
+ 202, "Ecircumflex",
+ 203, "Edieresis",
+ 204, "Igrave",
+ 205, "Iacute",
+ 206, "Icircumflex",
+ 207, "Idieresis",
+ 208, "Eth",
+ 209, "Ntilde",
+ 210, "Ograve",
+ 211, "Oacute",
+ 212, "Ocircumflex",
+ 213, "Otilde",
+ 214, "Odieresis",
+ 215, "multiply",
+ 216, "Oslash",
+ 217, "Ugrave",
+ 218, "Uacute",
+ 219, "Ucircumflex",
+ 220, "Udieresis",
+ 221, "Yacute",
+ 222, "Thorn",
+ 223, "germandbls",
+ 224, "agrave",
+ 225, "aacute",
+ 226, "acircumflex",
+ 227, "atilde",
+ 228, "adieresis",
+ 229, "aring",
+ 230, "ae",
+ 231, "ccedilla",
+ 232, "egrave",
+ 233, "eacute",
+ 234, "ecircumflex",
+ 235, "edieresis",
+ 236, "igrave",
+ 237, "iacute",
+ 238, "icircumflex",
+ 239, "idieresis",
+ 240, "eth",
+ 241, "ntilde",
+ 242, "ograve",
+ 243, "oacute",
+ 244, "ocircumflex",
+ 245, "otilde",
+ 246, "odieresis",
+ 247, "divide",
+ 248, "oslash",
+ 249, "ugrave",
+ 250, "uacute",
+ 251, "ucircumflex",
+ 252, "udieresis",
+ 253, "yacute",
+ 254, "thorn",
+ 255, "ydieresis",
+    0,      0
+};
+
+static psobj *StdEncArrayP = NULL;
+psobj *ISOLatin1EncArrayP = NULL; 
+static psobj *MakeEncodingArrayP(encodingTable)
+    EncodingTable *encodingTable;
+{
+  int i;
+  psobj *encodingArrayP;
+  encodingArrayP = (psobj *)vm_alloc(256*(sizeof(psobj)));
+  if (!encodingArrayP)
+      return NULL;
+
+  /* initialize everything to .notdef */
+  for (i=0; i<256;i++)
+      objFormatName(&(encodingArrayP[i]),7, ".notdef");
+
+  for (i=0; encodingTable[i].name; i++)
+  {
+      objFormatName(&(encodingArrayP[encodingTable[i].index]),
+                   strlen(encodingTable[i].name),
+                   encodingTable[i].name);
+  }
+
+  return(encodingArrayP);
+}
+boolean Init_BuiltInEncoding()
+{
+    StdEncArrayP = MakeEncodingArrayP(StdEnc);
+    ISOLatin1EncArrayP = MakeEncodingArrayP(ISO8859Enc);
+    return (StdEncArrayP && ISOLatin1EncArrayP);
+}
+/********************************************************************/
+/***================================================================***/
+static int getNextValue(valueType)
+    int valueType;
+{
+  scan_token(inputP);
+  if (tokenType != valueType) {
+    return(SCAN_ERROR);
+  }
+  return(SCAN_OK);
+}
+/***================================================================***/
+/*  This routine will set the global rc if there is an error          */
+/***================================================================***/
+static int getInt()
+{
+  scan_token(inputP);
+  if (tokenType != TOKEN_INTEGER) {
+    rc = SCAN_ERROR;
+    return(0);
+  }
+  else {
+    return( tokenValue.integer);
+  }
+}
+/***================================================================***/
+/*
+ * See Sec 10.3 of ``Adobe Type 1 Font Format'' v1.1,
+ * for parsing Encoding.
+ */
+static int getEncoding(arrayP)
+    psobj *arrayP;
+{
+
+  scan_token(inputP);
+  if ((tokenType == TOKEN_NAME)
+                &&
+     (((tokenLength==16) && (!strncmp(tokenStartP,"StandardEncoding",16))) ||
+      (((tokenLength==17) && (!strncmp(tokenStartP,"ISOLatin1Encoding",17))))))
+  {
+      /* Adobe Standard Encoding */
+
+      if (tokenLength == 16)
+         arrayP->data.valueP = (char *) StdEncArrayP;
+      else
+         arrayP->data.valueP = (char *) ISOLatin1EncArrayP;
+
+      arrayP->len = 256;
+      return(SCAN_OK);
+  }
+  else if ( (tokenType == TOKEN_LEFT_BRACE) ||
+       (tokenType == TOKEN_LEFT_BRACKET) )
+  {
+      /* Array of literal names */
+
+      psobj *objP;
+      int i;
+
+      objP = (psobj *)vm_alloc(256*(sizeof(psobj)));
+      if (!(objP)) return(SCAN_OUT_OF_MEMORY);
+
+      arrayP->data.valueP = (char *) objP;
+      arrayP->len = 256;
+
+      for (i=0; i<256; i++, objP++)
+      {
+         scan_token(inputP);
+         
+         if (tokenType != TOKEN_LITERAL_NAME)
+             return(SCAN_ERROR);
+
+         if (!(vm_alloc(tokenLength)) ) return(SCAN_OUT_OF_MEMORY);
+         objFormatName(objP,tokenLength,tokenStartP);
+      }
+
+      scan_token(inputP);
+      if ( (tokenType == TOKEN_RIGHT_BRACE) ||
+         (tokenType == TOKEN_RIGHT_BRACKET) )
+         return(SCAN_OK);
+  }
+  else
+  {
+      /* Must be sequences of ``dup <index> <charactername> put" */
+
+      psobj *objP;
+      int i;
+
+      objP = (psobj *)vm_alloc(256*(sizeof(psobj)));
+      if (!(objP)) return(SCAN_OUT_OF_MEMORY);
+
+      arrayP->data.valueP = (char *) objP;
+      arrayP->len = 256;
+
+      for (i=0; i<256; i++)
+         objFormatName(objP + i, 7, ".notdef");
+
+      while (TRUE)
+      {
+         scan_token(inputP);
+
+         switch (tokenType)
+         {
+         case TOKEN_NAME:
+             if (tokenLength == 3)
+             {
+                 if (strncmp(tokenStartP,"dup",3) == 0)
+                 {
+                     /* get <index> */
+                     scan_token(inputP);
+                     if (tokenType != TOKEN_INTEGER ||
+                         tokenValue.integer < 0 ||
+                         tokenValue.integer > 255)
+                         return (SCAN_ERROR);
+                     i = tokenValue.integer;
+
+                     /* get <characer_name> */
+                     scan_token(inputP);
+                     if (tokenType != TOKEN_LITERAL_NAME)
+                         return(SCAN_ERROR);
+
+                     if (!(vm_alloc(tokenLength)) )
+                         return(SCAN_OUT_OF_MEMORY);
+                     objFormatName(objP + i,tokenLength,tokenStartP);
+
+                     /* get "put" */
+                     scan_token(inputP);
+                     if (tokenType != TOKEN_NAME)
+                         return(SCAN_ERROR);
+                 }
+                 else if (strncmp(tokenStartP,"def",3) == 0)
+                     return (SCAN_OK);
+             }
+             break;
+         case TOKEN_EOF:
+         case TOKEN_NONE:
+         case TOKEN_INVALID:
+             return (SCAN_ERROR);
+         }
+      }
+  }
+
+  return (SCAN_ERROR);
+}
+/***================================================================***/
+static int getArray(arrayP)
+    psobj *arrayP;
+{
+  int N;   /* count the items in the array */
+  psobj *objP;
+
+  /* That is totally a kludge. If some stupid font file has
+   *   /foo/foo        # ftp://ftp.cdrom.com/pub/os2/fonts/future.zip
+   * we will treat it as /foo.
+   *  H.J. */
+  char tmp [1024];
+
+  strncpy (tmp, tokenStartP, sizeof (tmp));
+  tmp [sizeof (tmp) - 1] = '\0';
+
+restart: 
+  scan_token(inputP);
+  switch (tokenType)
+  {
+  case TOKEN_LEFT_BRACE:
+  case TOKEN_LEFT_BRACKET:
+    break;
+
+  case TOKEN_LITERAL_NAME:
+    tokenStartP[tokenLength] = '\0';
+    if (strcmp (tokenStartP, tmp) == 0)
+    {
+      /* Ok, We see /foo/foo. Let's restart. */
+      goto restart;
+    }
+
+  default:
+    return(SCAN_ERROR);
+  }
+  /* format the array in memory, save pointer to the beginning */
+  arrayP->data.valueP = tokenStartP;
+  /* loop, picking up next object, until right BRACE or BRACKET */
+  N = 0;
+  do {
+    scan_token(inputP);
+    if ( (tokenType == TOKEN_RIGHT_BRACE) ||
+         (tokenType == TOKEN_RIGHT_BRACKET) ) {
+      /* save then number of items in the array */
+      arrayP->len = N;
+      return(SCAN_OK);
+    }
+     /* allocate the space for the object */
+    objP = (psobj *)vm_alloc(sizeof(psobj));
+    if (!(objP)) return(SCAN_OUT_OF_MEMORY);
+    /* array is an array of numbers, (real or integer)  */
+    if (tokenType == TOKEN_REAL) {
+      objFormatReal(objP, tokenValue.real);
+    }
+    else
+      if (tokenType == TOKEN_INTEGER) {
+        objFormatInteger(objP, tokenValue.integer);
+      }
+      else return(SCAN_ERROR);
+    N++;
+  }  while ( 1>0 );
+  /* NOTREACHED*/
+}
+/***================================================================***/
+static int getName(nameP)
+    char *nameP;
+{
+  do {
+    scan_token(inputP);
+    if (tokenType <= TOKEN_NONE) {
+      if (tokenTooLong) return(SCAN_OUT_OF_MEMORY);
+      return(SCAN_ERROR);
+    }
+  } while ((tokenType != TOKEN_NAME) ||
+    (0 != strncmp(tokenStartP,nameP,strlen(nameP))) );
+  /* found */
+  return(SCAN_OK);
+}
+/***================================================================***/
+static int getNbytes(N)
+    int N;
+{
+  int I;
+  tokenStartP = vm_next_byte();
+  tokenMaxP = tokenStartP + MIN(vm_free_bytes(), MAX_STRING_LEN);
+  if (N > vm_free_bytes()) {
+    return(SCAN_OUT_OF_MEMORY);
+  }
+  I = fread(tokenStartP,1,N,inputP->data.fileP);
+  if ( I != N )     return(SCAN_FILE_EOF);
+  return(SCAN_OK);
+}
+/***================================================================***/
+/*  getLiteralName(nameObjP)                                          */
+/*     scan for next literal.                                         */
+/*  if we encounter the name 'end' then terminate and say ok.         */
+/*    It means that the CharStrings does not have as many characters  */
+/*    as the dictionary said it would and that is ok.                 */
+/***================================================================***/
+static int getLiteralName(nameObjP)
+    psobj *nameObjP;
+{
+  do {
+    scan_token(inputP);
+    if (tokenType <= TOKEN_NONE) {
+      if (tokenTooLong) return(SCAN_OUT_OF_MEMORY);
+      return(SCAN_ERROR);
+    }
+    if (tokenType == TOKEN_NAME) {
+      if (0 == strncmp(tokenStartP,"end",3) ) {
+        return(SCAN_END);
+      }
+    }
+  } while  (tokenType != TOKEN_LITERAL_NAME) ;
+  nameObjP->len = tokenLength;
+  /* allocate all the names in the CharStrings Structure */
+  if (!(vm_alloc(tokenLength)) ) return(SCAN_OUT_OF_MEMORY);
+  nameObjP->data.valueP =  tokenStartP;
+  /* found */
+  return(SCAN_OK);
+}
+/***================================================================***/
+/*
+ *   BuildSubrs routine
+ */
+/***================================================================***/
+static int BuildSubrs(FontP)
+    psfont *FontP;
+{
+   int N;   /* number of values in Subrs */
+   int I;   /* index into Subrs */
+   int i;   /* loop thru  Subrs */
+   int J;   /* length of Subrs entry */
+   psobj *arrayP;
+   /* next token should be a positive int */
+   /* note: rc is set by getInt. */
+   N = getInt();
+   if (rc) return(rc);
+   if (N < 0 ) return(SCAN_ERROR);
+   /* if we already have a Subrs, then skip the second one */
+   /* The second one is for hiresolution devices.          */
+   if (FontP->Subrs.data.arrayP != NULL) {
+     TwoSubrs = TRUE;
+     /* process all the Subrs, but do not update anything */
+     /* can not just skip them because of the binary data */
+     for (i=0;i<N;i++) {
+       /* look for dup */
+       rc = getName("dup");
+       if (rc) return(rc);
+       /* get 2 integers */
+       I = getInt();
+       if (rc) return(rc);
+       J = getInt();
+       if (rc) return(rc);
+       if ( (I < 0) || (J < 0 ) ) return (SCAN_ERROR);
+       /* get the next token, it should be RD or -|, either is ok */
+       rc = getNextValue(TOKEN_NAME);
+       if ( rc != SCAN_OK ) return(rc);
+       rc = getNbytes(J);
+       if (rc) return(rc);
+     }
+     return(SCAN_OK);
+   }
+   arrayP = (psobj *)vm_alloc(N*sizeof(psobj));
+   if (!(arrayP) ) return(SCAN_OUT_OF_MEMORY);
+   FontP->Subrs.len = N;
+   FontP->Subrs.data.arrayP =  arrayP;
+   /* get N values for Subrs */
+   for (i=0;i<N;i++) {
+     /* look for dup */
+     rc = getName("dup");
+     if (rc) return(rc);
+     /* get 2 integers */
+     I = getInt();
+     if (rc) return(rc);
+     J = getInt();
+     if (rc) return(rc);
+     if ( (I < 0) || (J < 0 ) ) return (SCAN_ERROR);
+     arrayP[I].len = J;
+     /* get the next token, it should be RD or -|, either is ok */
+     rc = getNextValue(TOKEN_NAME);
+     if ( rc != SCAN_OK ) return(rc);
+     rc = getNbytes(J);
+     if (rc == SCAN_OK) {
+       arrayP[I].data.valueP = tokenStartP;
+       if ( !(vm_alloc(J)) ) return(SCAN_OUT_OF_MEMORY);
+     }
+     else return(rc);
+   }
+   return(SCAN_OK);
+}
+/***================================================================***/
+/***================================================================***/
+/*
+ *   BuildCharStrings routine
+ */
+/***================================================================***/
+static int BuildCharStrings(FontP)
+    psfont   *FontP;
+{
+   int N;   /* number of values in CharStrings */
+   int i;   /* loop thru  Subrs */
+   int J;   /* length of Subrs entry */
+   psdict  *dictP;
+   /* next token should be a positive int */
+   N = getInt();
+   if (rc) {
+     /* check if file had TwoSubrs, hi resolution stuff is in file*/
+     if (TwoSubrs) {
+       do {
+         scan_token(inputP);
+         if (tokenType <= TOKEN_NONE) {
+           if (tokenTooLong) return(SCAN_OUT_OF_MEMORY);
+           return(SCAN_ERROR);
+         }
+       } while (tokenType != TOKEN_INTEGER);
+       N = tokenValue.integer;
+     }
+     else return(rc);  /* if next token was not an Int */
+   }
+   if (N<=0) return(SCAN_ERROR);
+   /* save number of entries in the dictionary */
+   dictP = (psdict *)vm_alloc((N+1)*sizeof(psdict));
+   if (!(dictP)) return(SCAN_OUT_OF_MEMORY);
+   FontP->CharStringsP = dictP;
+   dictP[0].key.len = N;
+   /* get N values for CharStrings */
+   for (i=1;i<=N;i++) {
+     /* look for next literal name  */
+     rc = getLiteralName(&(dictP[i].key));
+     if (rc) return(rc);
+     /* get 1 integer */
+     J = getInt();
+     if (rc) return(rc);  /* if next token was not an Int */
+     if (J<0) return (SCAN_ERROR);
+     dictP[i].value.len = J;
+     /* get the next token, it should be RD or -|, either is ok */
+     rc = getNextValue(TOKEN_NAME);
+     if ( rc != SCAN_OK ) return(rc);
+     rc = getNbytes(J);
+     if (rc == SCAN_OK) {
+       dictP[i].value.data.valueP = tokenStartP;
+       if ( !(vm_alloc(J)) ) return(SCAN_OUT_OF_MEMORY);
+     }
+     else return(rc);
+   }
+   return(SCAN_OK);
+}
+/***================================================================***/
+/***================================================================***/
+/*
+ *   BuildFontInfo Dictionary
+ */
+/***================================================================***/
+static int BuildFontInfo(fontP)
+    psfont *fontP;
+{
+  psdict *dictP;
+  /* allocate the private dictionary */
+  dictP = (psdict *)vm_alloc(20*sizeof(psdict));
+  if (!(dictP)) return(SCAN_OUT_OF_MEMORY);
+  fontP->fontInfoP = dictP;
+  fontP->fontInfoP[0].key.len = 17;  /* number of actual entries */
+  objFormatName(&(dictP[FONTNAME].key),8,"FontName");
+  objFormatName(&(dictP[FONTNAME].value),0,NULL);
+  objFormatName(&(dictP[PAINTTYPE].key),9,"PaintType");
+  objFormatInteger(&(dictP[PAINTTYPE].value),0);
+  objFormatName(&(dictP[FONTTYPENUM].key),8,"FontType");
+  objFormatInteger(&(dictP[FONTTYPENUM].value),0);
+  objFormatName(&(dictP[FONTMATRIX].key),10,"FontMatrix");
+  objFormatArray(&(dictP[FONTMATRIX].value),0,NULL);
+  objFormatName(&(dictP[FONTBBOX].key),8,"FontBBox");
+  objFormatArray(&(dictP[FONTBBOX].value),0,NULL);
+  objFormatName(&(dictP[ENCODING].key),8,"Encoding");
+  objFormatEncoding(&(dictP[ENCODING].value),0,NULL);
+  objFormatName(&(dictP[UNIQUEID].key),8,"UniqueID");
+  objFormatInteger(&(dictP[UNIQUEID].value),0);
+  objFormatName(&(dictP[STROKEWIDTH].key),11,"StrokeWidth");
+  objFormatReal(&(dictP[STROKEWIDTH].value),0.0);
+  objFormatName(&(dictP[VERSION].key),7,"version");
+  objFormatString(&(dictP[VERSION].value),0,NULL);
+  objFormatName(&(dictP[NOTICE].key),6,"Notice");
+  objFormatString(&(dictP[NOTICE].value),0,NULL);
+  objFormatName(&(dictP[FULLNAME].key),8,"FullName");
+  objFormatString(&(dictP[FULLNAME].value),0,NULL);
+  objFormatName(&(dictP[FAMILYNAME].key),10,"FamilyName");
+  objFormatString(&(dictP[FAMILYNAME].value),0,NULL);
+  objFormatName(&(dictP[WEIGHT].key),6,"Weight");
+  objFormatString(&(dictP[WEIGHT].value),0,NULL);
+  objFormatName(&(dictP[ITALICANGLE].key),11,"ItalicAngle");
+  objFormatReal(&(dictP[ITALICANGLE].value),0.0);
+  objFormatName(&(dictP[ISFIXEDPITCH].key),12,"isFixedPitch");
+  objFormatBoolean(&(dictP[ISFIXEDPITCH].value),FALSE);
+  objFormatName(&(dictP[UNDERLINEPOSITION].key),17,"UnderlinePosition");
+  objFormatReal(&(dictP[UNDERLINEPOSITION].value),0.0);
+  objFormatName(&(dictP[UNDERLINETHICKNESS].key),18,"UnderlineThickness");
+  objFormatReal(&(dictP[UNDERLINETHICKNESS].value),0.0);
+  return(SCAN_OK);
+}
+/***================================================================***/
+/*
+ *   BuildPrivate Dictionary
+ */
+/***================================================================***/
+static int BuildPrivate(fontP)
+    psfont *fontP;
+{
+  psdict *Private;
+  /* allocate the private dictionary */
+  Private = (psdict *)vm_alloc(20*sizeof(psdict));
+  if (!(Private)) return(SCAN_OUT_OF_MEMORY);
+  fontP->Private = Private;
+  fontP->Private[0].key.len = 16;  /* number of actual entries */
+  objFormatName(&(Private[BLUEVALUES].key),10,"BlueValues");
+  objFormatArray(&(Private[BLUEVALUES].value),0,NULL);
+  objFormatName(&(Private[OTHERBLUES].key),10,"OtherBlues");
+  objFormatArray(&(Private[OTHERBLUES].value),0,NULL);
+  objFormatName(&(Private[FAMILYBLUES].key),11,"FamilyBlues");
+  objFormatArray(&(Private[FAMILYBLUES].value),0,NULL);
+  objFormatName(&(Private[FAMILYOTHERBLUES].key),16,"FamilyOtherBlues");
+  objFormatArray(&(Private[FAMILYOTHERBLUES].value),0,NULL);
+  objFormatName(&(Private[BLUESCALE].key),9,"BlueScale");
+  objFormatReal(&(Private[BLUESCALE].value),DEFAULTBLUESCALE);
+  objFormatName(&(Private[BLUESHIFT].key),9,"BlueShift");
+  objFormatInteger(&(Private[BLUESHIFT].value),DEFAULTBLUESHIFT);
+  objFormatName(&(Private[BLUEFUZZ].key),8,"BlueFuzz");
+  objFormatInteger(&(Private[BLUEFUZZ].value),DEFAULTBLUEFUZZ);
+  objFormatName(&(Private[STDHW].key),5,"StdHW");
+  objFormatArray(&(Private[STDHW].value),0,NULL);
+  objFormatName(&(Private[STDVW].key),5,"StdVW");
+  objFormatArray(&(Private[STDVW].value),0,NULL);
+  objFormatName(&(Private[STEMSNAPH].key),9,"StemSnapH");
+  objFormatArray(&(Private[STEMSNAPH].value),0,NULL);
+  objFormatName(&(Private[STEMSNAPV].key),9,"StemSnapV");
+  objFormatArray(&(Private[STEMSNAPV].value),0,NULL);
+  objFormatName(&(Private[FORCEBOLD].key),9,"ForceBold");
+  objFormatBoolean(&(Private[FORCEBOLD].value),DEFAULTFORCEBOLD);
+  objFormatName(&(Private[LANGUAGEGROUP].key),13,"LanguageGroup");
+  objFormatInteger(&(Private[LANGUAGEGROUP].value),DEFAULTLANGUAGEGROUP);
+  objFormatName(&(Private[LENIV].key),5,"lenIV");
+  objFormatInteger(&(Private[LENIV].value),DEFAULTLENIV);
+  objFormatName(&(Private[RNDSTEMUP].key),9,"RndStemUp");
+  objFormatBoolean(&(Private[RNDSTEMUP].value),DEFAULTRNDSTEMUP);
+  objFormatName(&(Private[EXPANSIONFACTOR].key),9,"ExpansionFactor");
+  objFormatReal(&(Private[EXPANSIONFACTOR].value),
+                          DEFAULTEXPANSIONFACTOR);
+  return(SCAN_OK);
+}
+/***================================================================***/
+/**********************************************************************/
+/*     GetType1Blues(fontP)                                           */
+/*                                                                    */
+/*   Routine to support font-level hints.                             */
+/*                                                                    */
+/*         Gets all the Blues information from the Private dictionary */
+/*         for the font.                                              */
+/*                                                                    */
+/*                                                                    */
+/**********************************************************************/
+static int GetType1Blues(fontP)
+    psfont *fontP;
+{
+  psdict *PrivateDictP;   /* the Private dict relating to hints */
+  struct blues_struct *blues;  /* ptr for the blues struct we will allocate */
+  int i;
+  psobj *HintEntryP;
+  /* get the Private dictionary pointer */
+  PrivateDictP = fontP->Private;
+  /* allocate the memory for the blues structure */
+  blues = (struct blues_struct *) vm_alloc(sizeof(struct blues_struct));
+  if (!blues)  return(SCAN_OUT_OF_MEMORY);
+  /* Make fontP's blues ptr point to this newly allocated structure. */
+  fontP->BluesP = blues;
+  /* fill in the BlueValues array */
+  HintEntryP = &(PrivateDictP[BLUEVALUES].value);
+  /* check to see if the entry exists and if it's an array */
+  if ( !objPIsArray(HintEntryP) || (HintEntryP->len == 0 ))
+      blues->numBlueValues = 0;
+  else {
+      /* get the number of values in the array */
+      if (HintEntryP->len > NUMBLUEVALUES) {
+          blues->numBlueValues = NUMBLUEVALUES;
+      } else
+          blues->numBlueValues = HintEntryP->len;
+      for (i = 0; i<= blues->numBlueValues-1; ++i) {
+          if (objPIsInteger(&HintEntryP->data.arrayP[i]))
+              blues->BlueValues[i] =
+                  HintEntryP->data.arrayP[i].data.integer;
+          else if (objPIsReal(&HintEntryP->data.arrayP[i]))
+              blues->BlueValues[i] =
+                  HintEntryP->data.arrayP[i].data.real;
+          else
+              blues->BlueValues[i] = 0;
+      }
+  }
+  /* fill in the OtherBlues array */
+  HintEntryP =  &(PrivateDictP[OTHERBLUES].value);
+  /* check to see if the entry exists and if it's an array */
+  if ( !objPIsArray(HintEntryP) || (HintEntryP->len == 0 ))
+      blues->numOtherBlues = 0;
+  else {
+      /* get the number of values in the array */
+      if (HintEntryP->len > NUMOTHERBLUES) {
+          blues->numOtherBlues = NUMOTHERBLUES;
+      } else
+          blues->numOtherBlues = HintEntryP->len;
+      for (i = 0; i<= blues->numOtherBlues-1; ++i) {
+          if (objPIsInteger(&HintEntryP->data.arrayP[i]))
+              blues->OtherBlues[i] =
+                  HintEntryP->data.arrayP[i].data.integer;
+          else if (objPIsReal(&HintEntryP->data.arrayP[i]))
+              blues->OtherBlues[i] =
+                  HintEntryP->data.arrayP[i].data.real;
+          else
+              blues->OtherBlues[i] = 0;
+      }
+  }
+  /* fill in the FamilyBlues array */
+  HintEntryP =  &(PrivateDictP[FAMILYBLUES].value);
+  /* check to see if the entry exists and if it's an array */
+  if ( !objPIsArray(HintEntryP) || (HintEntryP->len == 0 ))
+      blues->numFamilyBlues = 0;
+  else {
+      /* get the number of values in the array */
+      if (HintEntryP->len > NUMFAMILYBLUES) {
+          blues->numFamilyBlues = NUMFAMILYBLUES;
+      } else
+          blues->numFamilyBlues = HintEntryP->len;
+      for (i = 0; i<= blues->numFamilyBlues-1; ++i) {
+          if (objPIsInteger(&HintEntryP->data.arrayP[i]))
+              blues->FamilyBlues[i] =
+                  HintEntryP->data.arrayP[i].data.integer;
+          else if (objPIsReal(&HintEntryP->data.arrayP[i]))
+              blues->FamilyBlues[i] =
+                  HintEntryP->data.arrayP[i].data.real;
+          else
+              blues->FamilyBlues[i] = 0;
+      }
+  }
+  /* fill in the FamilyOtherBlues array */
+  HintEntryP =  &(PrivateDictP[FAMILYOTHERBLUES].value);
+  /* check to see if the entry exists and if it's an array */
+  if ( !objPIsArray(HintEntryP) || (HintEntryP->len == 0 ))
+      blues->numFamilyOtherBlues = 0;
+  else {
+      /* get the number of values in the array */
+      if (HintEntryP->len > NUMFAMILYOTHERBLUES) {
+          blues->numFamilyOtherBlues = NUMFAMILYOTHERBLUES;
+      } else
+          blues->numFamilyOtherBlues = HintEntryP->len;
+      for (i = 0; i<= blues->numFamilyOtherBlues-1; ++i) {
+          if (objPIsInteger(&HintEntryP->data.arrayP[i]))
+              blues->FamilyOtherBlues[i] =
+                  HintEntryP->data.arrayP[i].data.integer;
+          else if (objPIsReal(&HintEntryP->data.arrayP[i]))
+              blues->FamilyOtherBlues[i] =
+                  HintEntryP->data.arrayP[i].data.real;
+          else
+              blues->FamilyOtherBlues[i] = 0;
+      }
+  }
+  /* fill in the StemSnapH array */
+  HintEntryP =  &(PrivateDictP[STEMSNAPH].value);
+  /* check to see if the entry exists and if it's an array */
+  if ( !objPIsArray(HintEntryP) || (HintEntryP->len == 0 ))
+      blues->numStemSnapH = 0;
+  else {
+      /* get the number of values in the array */
+      if (HintEntryP->len > NUMSTEMSNAPH) {
+          blues->numStemSnapH = NUMSTEMSNAPH;
+      } else
+          blues->numStemSnapH = HintEntryP->len;
+      for (i = 0; i<= blues->numStemSnapH-1; ++i) {
+          if (objPIsInteger(&HintEntryP->data.arrayP[i]))
+              blues->StemSnapH[i] =
+                  HintEntryP->data.arrayP[i].data.integer;
+          else if (objPIsReal(&HintEntryP->data.arrayP[i]))
+              blues->StemSnapH[i] =
+                  HintEntryP->data.arrayP[i].data.real;
+          else
+              blues->StemSnapH[i] = 0;
+      }
+  }
+  /* fill in the StemSnapV array */
+  HintEntryP =  &(PrivateDictP[STEMSNAPV].value);
+  /* check to see if the entry exists and if it's an array */
+  if ( !objPIsArray(HintEntryP) || (HintEntryP->len == 0 ))
+      blues->numStemSnapV = 0;
+  else {
+      /* get the number of values in the array */
+      if (HintEntryP->len > NUMSTEMSNAPV) {
+          blues->numStemSnapV = NUMSTEMSNAPV;
+      } else
+          blues->numStemSnapV = HintEntryP->len;
+      for (i = 0; i<= blues->numStemSnapV-1; ++i) {
+          if (objPIsInteger(&HintEntryP->data.arrayP[i]))
+              blues->StemSnapV[i] =
+                  HintEntryP->data.arrayP[i].data.integer;
+          else if (objPIsReal(&HintEntryP->data.arrayP[i]))
+              blues->StemSnapV[i] =
+                  HintEntryP->data.arrayP[i].data.real;
+          else
+              blues->StemSnapV[i] = 0;
+      }
+  }
+  /* fill in the StdVW array */
+  HintEntryP =  &(PrivateDictP[STDVW].value);
+  /* check to see if the entry exists and if it's an array */
+  if ( !objPIsArray(HintEntryP) || (HintEntryP->len == 0 ))
+      /* a value of zero signifies no entry */
+      blues->StdVW = 0;
+  else {
+      if (HintEntryP->len > NUMSTDVW) {
+      }
+      if (objPIsInteger(&HintEntryP->data.arrayP[0]))
+          blues->StdVW = HintEntryP->data.arrayP[0].data.integer;
+      else if (objPIsReal(&HintEntryP->data.arrayP[0]))
+          blues->StdVW = HintEntryP->data.arrayP[0].data.real;
+      else
+          blues->StdVW = 0;
+  }
+  /* fill in the StdHW array */
+  HintEntryP =  &(PrivateDictP[STDHW].value);
+  /* check to see if the entry exists and if it's an array */
+  if ( !objPIsArray(HintEntryP) || (HintEntryP->len == 0 ))
+      /* a value of zero signifies no entry */
+      blues->StdHW = 0;
+  else {
+      if (HintEntryP->len > NUMSTDHW) {
+      }
+          if (objPIsInteger(&HintEntryP->data.arrayP[0]))
+             blues->StdHW = HintEntryP->data.arrayP[0].data.integer;
+          else if (objPIsReal(&HintEntryP->data.arrayP[0]))
+             blues->StdHW = HintEntryP->data.arrayP[0].data.real;
+          else
+             blues->StdHW = 0;
+  }
+  /* get the ptr to the BlueScale entry */
+  HintEntryP =  &(PrivateDictP[BLUESCALE].value);
+  /* put the BlueScale in the blues structure */
+  if (objPIsInteger(HintEntryP)) /* Must be integer! */
+      blues->BlueScale = HintEntryP->data.integer;
+  else if (objPIsReal(HintEntryP)) /* Error? */
+      blues->BlueScale = HintEntryP->data.real;
+  else
+      blues->BlueScale = DEFAULTBLUESCALE;
+  /* get the ptr to the BlueShift entry */
+  HintEntryP =  &(PrivateDictP[BLUESHIFT].value);
+  if (objPIsInteger(HintEntryP)) /* Must be integer! */
+      blues->BlueShift = HintEntryP->data.integer;
+  else if (objPIsReal(HintEntryP)) /* Error? */
+      blues->BlueShift = HintEntryP->data.real;
+  else
+      blues->BlueShift = DEFAULTBLUESHIFT;
+  /* get the ptr to the BlueFuzz entry */
+  HintEntryP =  &(PrivateDictP[BLUEFUZZ].value);
+  if (objPIsInteger(HintEntryP)) /* Must be integer! */
+      blues->BlueFuzz = HintEntryP->data.integer;
+  else if (objPIsReal(HintEntryP)) /* Error? */
+      blues->BlueFuzz = HintEntryP->data.real;
+  else
+      blues->BlueFuzz = DEFAULTBLUEFUZZ;
+  /* get the ptr to the ForceBold entry */
+  HintEntryP =  &(PrivateDictP[FORCEBOLD].value);
+  if (objPIsBoolean(HintEntryP))  /* Must be integer! */
+      blues->ForceBold = HintEntryP->data.boolean;
+  else
+      blues->ForceBold = DEFAULTFORCEBOLD;
+  /* get the ptr to the LanguageGroup entry */
+  HintEntryP =  &(PrivateDictP[LANGUAGEGROUP].value);
+  if (objPIsInteger(HintEntryP)) /* Must be integer! */
+      blues->LanguageGroup = HintEntryP->data.integer;
+  else
+      blues->LanguageGroup = DEFAULTLANGUAGEGROUP;
+  /* get the ptr to the RndStemUp entry */
+  HintEntryP =  &(PrivateDictP[RNDSTEMUP].value);
+  if (objPIsBoolean(HintEntryP)) /* Must be integer! */
+      blues->RndStemUp = HintEntryP->data.boolean;
+  else
+      blues->RndStemUp = DEFAULTRNDSTEMUP;
+  /* get the ptr to the lenIV entry */
+  HintEntryP =  &(PrivateDictP[LENIV].value);
+  if (objPIsInteger(HintEntryP)) /* Must be integer! */
+      blues->lenIV = HintEntryP->data.integer;
+  else
+      blues->lenIV = DEFAULTLENIV;
+  /* get the ptr to the ExpansionFactor entry */
+  HintEntryP =  &(PrivateDictP[EXPANSIONFACTOR].value);
+  if (objPIsInteger(HintEntryP))
+      blues->ExpansionFactor = HintEntryP->data.integer;
+  else if (objPIsReal(HintEntryP))
+      blues->ExpansionFactor = HintEntryP->data.real;
+  else
+      blues->ExpansionFactor = DEFAULTEXPANSIONFACTOR;
+  return(SCAN_OK);
+}
+/**********************************************************************/
+/*   GetType1CharString(fontP,code)                                   */
+/*                                                                    */
+/*          Look up code in the standard encoding vector and return   */
+/*          the charstring associated with the character name.        */
+/*                                                                    */
+/*   fontP  is the psfont structure.                                  */
+/*                                                                    */
+/*   Returns a psobj (string)                                         */
+/**********************************************************************/
+psobj *GetType1CharString(fontP, code)
+psfont *fontP;
+unsigned char code;
+{
+  int  N;           /* the 'Nth' entry in the CharStrings       */
+  psobj *charnameP; /* points to psobj that is name of character*/
+  psdict *CharStringsDictP; /* dictionary with char strings     */
+  psobj  *theStringP;  /* the definition for the code */
+  if (StdEncArrayP == NULL) {
+    return(NULL);
+  }
+  /* use the code to index into the standard encoding vector  */
+  charnameP = &(StdEncArrayP[code]);
+  /* test if the encoding array points to a name */
+  if (!(objPIsName(charnameP)) ) {
+    return(NULL);
+  }
+  /* Now that we have the character name out of the standardencoding */
+  /* get the character definition out of the current font */
+  CharStringsDictP =  fontP->CharStringsP;
+  /* search the chars string for this charname as key */
+  N = SearchDictName(CharStringsDictP,charnameP);
+  if (N<=0) {
+    return(NULL);
+  }
+  /* OK, the nth item is the psobj that is the string for this char */
+  theStringP = &(CharStringsDictP[N].value);
+  return(theStringP);
+}
+/***================================================================***/
+/*
+ *   FindDictValue
+ */
+/***================================================================***/
+static int FindDictValue(dictP)
+    psdict    *dictP;
+{
+   psobj LitName;
+   int   N;
+   int   V;
+   /* we have just scanned a token and it is a literal name */
+   /* need to check if that name is in Private dictionary */
+   objFormatName(&LitName,tokenLength,tokenStartP);
+   /* is it in the dictP */
+   N = SearchDictName(dictP,&LitName);
+   /* if found */
+   if ( N > 0 ) {
+     /* what type */
+     switch (dictP[N].value.type) {
+       case OBJ_ENCODING:
+         V = getEncoding(&(dictP[N].value));
+         if ( V != SCAN_OK ) return(V);
+         break;
+       case OBJ_ARRAY:
+         V = getArray(&(dictP[N].value));
+         if ( V != SCAN_OK ) return(V);
+         break;
+       case OBJ_INTEGER:
+         /* next value in integer */
+         dictP[N].value.data.integer = getInt();
+         if (rc) return(rc);  /* if next token was not an Int */
+         break;
+       case OBJ_REAL:
+         /* next value must be real or int, store as a real */
+         scan_token(inputP);
+         if (tokenType == TOKEN_REAL) {
+           dictP[N].value.data.real = tokenValue.real;
+         }
+         else
+           if (tokenType == TOKEN_INTEGER) {
+             dictP[N].value.data.real = tokenValue.integer;
+           }
+         else return(SCAN_ERROR);
+         break;
+       case OBJ_NAME:
+         V = getNextValue(TOKEN_LITERAL_NAME);
+         if ( V != SCAN_OK ) return(V);
+         if (!(vm_alloc(tokenLength)) ) return(SCAN_OUT_OF_MEMORY);
+         objFormatName(&(dictP[N].value),tokenLength,tokenStartP);
+         break;
+       case OBJ_STRING:
+         V = getNextValue(TOKEN_STRING);
+         if ( V != SCAN_OK ) return(V);
+         if (!(vm_alloc(tokenLength)) ) return(SCAN_OUT_OF_MEMORY);
+         objFormatString(&(dictP[N].value),tokenLength,tokenStartP);
+         break;
+       case OBJ_BOOLEAN:
+         scan_token(inputP);
+         if (tokenType != TOKEN_NAME) {
+           return(SCAN_ERROR);
+         }
+         if (0 == strncmp(tokenStartP,"true",4) ) {
+           dictP[N].value.data.boolean =TRUE;
+         }
+         else
+           if (0 == strncmp(tokenStartP,"false",5) ) {
+             dictP[N].value.data.boolean =FALSE;
+           }
+           else return(SCAN_ERROR);
+         break;
+       default:
+         return(SCAN_ERROR);
+     }
+   }
+   /* Name is not in dictionary.  That is ok. */
+   return(SCAN_OK);
+}
+/***================================================================***/
+/*
+ * -------------------------------------------------------------------
+ *  Scan the next token and convert it into an object
+ *  Result is placed on the Operand Stack as next object
+ * -------------------------------------------------------------------
+ */
+int scan_font(FontP)
+  psfont *FontP;
+{
+  char   filename[128];
+  char   filetype[3];
+  FILE   *fileP;
+  char   *nameP;
+  int    namelen;
+  int    V;
+  int    i;
+  boolean starthex80;
+    starthex80 = FALSE;
+    filetype[0] = 'r';
+    filetype[1] = 'b';
+    filetype[2] = '\0';
+    /* copy the filename and remove leading or trailing blanks */
+    /* point to name and search for leading blanks */
+    nameP= FontP->FontFileName.data.nameP;
+    namelen  = FontP->FontFileName.len;
+    while (nameP[0] == ' ') {
+        nameP++;
+        namelen--;
+    }
+    /* now remove any trailing blanks */
+    while ((namelen>0) && ( nameP[namelen-1] == ' ')) {
+      namelen--;
+    }
+    strncpy(filename,nameP,namelen);
+    filename[namelen] = '\0';
+    /* file name is now constructed */
+    inputFile.data.fileP = NULL;
+    filterFile.data.fileP = NULL;
+    inputP = &inputFile;
+    if (fileP = fopen(filename,filetype)) {
+      /* get the first byte of file */
+      V = getc(fileP);
+      /* if file starts with x'80' then skip next 5 bytes */
+      if ( V == 0X80 ) {
+        for (i=0;i<5;i++) V = getc(fileP);
+        starthex80 = TRUE;
+      }
+      else ungetc(V,fileP);
+      objFormatFile(inputP,fileP);
+    }
+    else {
+      return(SCAN_FILE_OPEN_ERROR);
+    };
+  WantFontInfo  = TRUE;
+  InPrivateDict = FALSE;
+  TwoSubrs      = FALSE;
+  rc = BuildFontInfo(FontP);
+  if (rc != 0) return(rc);
+  /* Assume everything will be OK */
+  rc       = 0;
+  /* Loop until complete font is read  */
+  do {
+    /* Scan the next token */
+    scan_token(inputP);
+    /* ==> tokenLength, tokenTooLong, tokenType, and tokenValue are */
+    /* now set */
+    switch (tokenType) {
+      case TOKEN_EOF:
+      case TOKEN_NONE:
+      case TOKEN_INVALID:
+        /* in this case we are done */
+        if (tokenTooLong) return(SCAN_OUT_OF_MEMORY);
+        rc = SCAN_ERROR;
+        break;
+      case TOKEN_LITERAL_NAME:
+            /* Look up the name */
+            tokenStartP[tokenLength] = '\0';
+            if (InPrivateDict ) {
+              if (0== strncmp(tokenStartP,"Subrs",5) ) {
+                rc = BuildSubrs(FontP);
+                break;
+              }
+              if (0== strncmp(tokenStartP,"CharStrings",11) ) {
+                rc = BuildCharStrings(FontP);
+                if ( (rc == SCAN_OK) ||(rc == SCAN_END) ) {
+                  fclose(inputP->data.fileP);
+                  /* Build the Blues Structure */
+                  rc = GetType1Blues(FontP);
+                  /* whatever the return code, return it */
+                  /* all the work is done. This is the normal exit.*/
+                  return(rc);
+                }
+                break;
+              }
+              rc = FindDictValue(FontP->Private);
+              /* we are not going to report errors */
+              /* Sometimes the font file may test a value such as */
+              /* testing to see if the font is alreadly loaded with */
+              /* same UniqueID.  We would faile on /UniqueID get  */
+              /* because we are expecting a int to follow UniqueID*/
+              /* If the correct object type does not follow a Name*/
+              /* then we will skip over it without reporting error*/
+              rc = SCAN_OK;
+              break;
+            }   /* end of reading Private dictionary */
+            else
+              if (0== strncmp(tokenStartP,"Private",7) ) {
+                InPrivateDict = TRUE;
+                rc = BuildPrivate(FontP);
+                break;
+              }
+              else
+                if (WantFontInfo) {
+                  rc = FindDictValue(FontP->fontInfoP);
+                  /* we are not going to report errors */
+                  rc = SCAN_OK;
+                  break;
+                }
+        break;
+      case TOKEN_NAME:
+            if (0 == strncmp(tokenStartP,"eexec",5) ) {
+               /* if file started with x'80', check next 5 bytes */
+               if (starthex80) {
+                 V = getc(fileP);
+                 if ( V == 0X80 ) {
+                   for (i=0;i<5;i++) V = getc(fileP);
+                 }
+                 else ungetc(V,fileP);
+               }
+               filterFile.data.fileP = T1eexec(inputP->data.fileP);
+               if (filterFile.data.fileP == NULL) {
+                 fclose(inputFile.data.fileP);
+                 return(SCAN_FILE_OPEN_ERROR);
+               }
+               inputP = &filterFile;
+               WantFontInfo = FALSE;
+            }
+        break;
+    }
+  }
+  while (rc ==0);
+  fclose(inputP->data.fileP);
+  if (tokenTooLong) return(SCAN_OUT_OF_MEMORY);
+  return(rc);
+}
diff --git a/Xserver/lib/font/Type1/spaces.c b/Xserver/lib/font/Type1/spaces.c
new file mode 100644 (file)
index 0000000..f026420
--- /dev/null
@@ -0,0 +1,1000 @@
+/* $XConsortium: spaces.c,v 1.8 95/06/08 23:20:39 gildea Exp $ */
+/* Copyright International Business Machines, Corp. 1991
+ * All Rights Reserved
+ * Copyright Lexmark International, Inc. 1991
+ * All Rights Reserved
+ *
+ * License to use, copy, modify, and distribute this software and its
+ * documentation for any purpose and without fee is hereby granted,
+ * provided that the above copyright notice appear in all copies and that
+ * both that copyright notice and this permission notice appear in
+ * supporting documentation, and that the name of IBM or Lexmark not be
+ * used in advertising or publicity pertaining to distribution of the
+ * software without specific, written prior permission.
+ *
+ * IBM AND LEXMARK PROVIDE THIS SOFTWARE "AS IS", WITHOUT ANY WARRANTIES OF
+ * ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING, BUT NOT LIMITED TO ANY
+ * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE,
+ * AND NONINFRINGEMENT OF THIRD PARTY RIGHTS.  THE ENTIRE RISK AS TO THE
+ * QUALITY AND PERFORMANCE OF THE SOFTWARE, INCLUDING ANY DUTY TO SUPPORT
+ * OR MAINTAIN, BELONGS TO THE LICENSEE.  SHOULD ANY PORTION OF THE
+ * SOFTWARE PROVE DEFECTIVE, THE LICENSEE (NOT IBM OR LEXMARK) ASSUMES THE
+ * ENTIRE COST OF ALL SERVICING, REPAIR AND CORRECTION.  IN NO EVENT SHALL
+ * IBM OR LEXMARK BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
+ * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
+ * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
+ * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
+ * THIS SOFTWARE.
+ */
+ /* SPACES   CWEB         V0021 ********                             */
+/*
+:h1 id=spaces.SPACES Module - Handles Coordinate Spaces
+This module is responsible for handling the TYPE1IMAGER "XYspace" object.
+&author. Jeffrey B. Lotspiech (lotspiech@almaden.ibm.com)
+:h3.Include Files
+*/
+#include "objects.h"
+#include "spaces.h"
+#include "paths.h"
+#include "pictures.h"
+#include "fonts.h"
+#include "arith.h"
+#include "trig.h"
+
+static void FindFfcn();
+static void FindIfcn();
+/*
+:h3.Entry Points Provided to the TYPE1IMAGER User
+*/
+/*SHARED LINE(S) ORIGINATED HERE*/
+/*
+:h3.Entry Points Provided to Other Modules
+*/
+/*
+In addition, other modules call the SPACES module through function
+vectors in the "XYspace" structure.  The entry points accessed that
+way are "FConvert()", "IConvert()", and "ForceFloat()".
+*/
+/*SHARED LINE(S) ORIGINATED HERE*/
+/*
+:h3.Macros and Typedefs Provided to Other Modules
+:h4.Duplicating and Killing Spaces
+Destroying XYspaces is so simple we can do it with a
+macro:
+*/
+/*SHARED LINE(S) ORIGINATED HERE*/
+/*
+On the other hand, duplicating XYspaces is slightly more difficult
+because of the need to keep a unique ID in the space, see
+:hdref refid=dupspace..
+:h4.Fixed Point Pel Representation
+We represent pel positions with fixed point numbers.  This does NOT
+mean integer, but truly means fixed point, with a certain number
+of binary digits (FRACTBITS) representing the fractional part of the
+pel.
+*/
+/*SHARED LINE(S) ORIGINATED HERE*/
+/*
+:h2.Data Structures for Coordinate Spaces and Points
+*/
+/*
+:h3 id=matrix.Matrices
+TYPE1IMAGER uses 2x2 transformation matrices.  We'll use C notation for
+such a matrix (M[2][2]), the first index being rows, the second columns.
+*/
+/*
+:h3.The "doublematrix" Structure
+We frequently find it desirable to store both a matrix and its
+inverse.  We store these in a "doublematrix" structure.
+*/
+/*SHARED LINE(S) ORIGINATED HERE*/
+/*
+:h3.The "XYspace" Structure
+The XYspace structure represents the XYspace object.
+*/
+/*SHARED LINE(S) ORIGINATED HERE*/
+#define    RESERVED  10      /* 'n' IDs are reserved for invalid & immortal spaces */
+/*
+*/
+#define    NEXTID    ((SpaceID < RESERVED) ? (SpaceID = RESERVED) : ++SpaceID)
+static unsigned int SpaceID = 1;
+struct XYspace *CopySpace(S)
+       register struct XYspace *S;
+{
+       S = (struct XYspace *)Allocate(sizeof(struct XYspace), S, 0);
+       S->ID = NEXTID;
+       return(S);
+}
+/*
+:h3.The "fractpoint" Structure
+A fractional point is just a "fractpel" x and y:
+*/
+/*SHARED LINE(S) ORIGINATED HERE*/
+/*
+:h3.Lazy Evaluation of Matrix Inverses
+Calculating the inverse of a matrix is somewhat involved, and we usually
+do not need them.  So, we flag whether or not the space has the inverse
+already calculated:
+*/
+#define    HASINVERSE(flag)   ((flag)&0x80)
+/*
+The following macro forces a space to have an inverse:
+*/
+#define    CoerceInverse(S)   if (!HASINVERSE((S)->flag)) { \
+    MatrixInvert((S)->tofract.normal, (S)->tofract.inverse); (S)->flag |= HASINVERSE(ON); }
+/*
+:h3.IDENTITY Space
+IDENTITY space is (logically) the space corresponding to the identity
+transformation matrix.  However, since all our transformation matrices
+have a common FRACTFLOAT scale factor to convert to 'fractpel's, that
+is actually what we store in 'tofract' matrix of IDENTITY:
+*/
+static struct XYspace identity = { SPACETYPE, ISPERMANENT(ON) + ISIMMORTAL(ON)
+                        + HASINVERSE(ON), 2, /* added 3-26-91 PNM */
+                        NULL, NULL,
+                        NULL, NULL, NULL, NULL,
+                        INVALIDID + 1, 0,
+                        FRACTFLOAT, 0.0, 0.0, FRACTFLOAT,
+                        1.0/FRACTFLOAT, 0.0, 0.0, 1.0/FRACTFLOAT,
+                        0, 0, 0, 0 };
+struct XYspace *IDENTITY = &identity;
+/*
+*/
+#define  MAXCONTEXTS   16
+static struct doublematrix contexts[MAXCONTEXTS];
+#ifdef notdef
+
+static int nextcontext = 1;
+/*SHARED LINE(S) ORIGINATED HERE*/
+
+#ifdef __STDC__
+#define   pointer          void *
+#else
+#define   pointer          char *
+#endif
+/*
+:h3.FindDeviceContext() - Find the Context Given a Device
+This routine, given a device, returns the index of the device's
+transformation matrix in the context array.  If it cannot find it,
+it will allocate a new array entry and fill it out.
+*/
+static int FindDeviceContext(device)
+       pointer device;       /* device token                                 */
+{
+       double M[2][2];       /* temporary matrix                             */
+       float Xres,Yres;      /* device  resolution                           */
+       int orient = -1;      /* device orientation                           */
+       int rc = -1;          /* return code for QueryDeviceState             */
+       if (rc != 0)          /* we only bother with this check once          */
+               abort("Context:  QueryDeviceState didn't work");
+       M[0][0] = M[1][0] = M[0][1] = M[1][1] = 0.0;
+       switch (orient) {
+           case 0:
+               M[0][0] = Xres;  M[1][1] = -Yres;
+               break;
+           case 1:
+               M[1][0] = Yres;  M[0][1] = Xres;
+               break;
+           case 2:
+               M[0][0] = -Xres;  M[1][1] = Yres;
+               break;
+           case 3:
+               M[1][0] = -Yres;  M[0][1] = -Xres;
+               break;
+           default:
+               abort("QueryDeviceState returned invalid orientation");
+       }
+       return(FindContext(M));
+}
+/*
+:h3.FindContext() - Find the Context Given a Matrix
+This routine, given a matrix, returns the index of that matrix matrix in
+the context array.  If it cannot find it, it will allocate a new array
+entry and fill it out.
+*/
+int FindContext(M)
+       double M[2][2];       /* array to search for                          */
+{
+       register int i;       /* loop variable for search                     */
+       for (i=0; i < nextcontext; i++)
+               if (M[0][0] == contexts[i].normal[0][0] && M[1][0] == contexts[i].normal[1][0]
+                   && M[0][1] == contexts[i].normal[0][1] && M[1][1] == contexts[i].normal[1][1])
+                       break;
+       if (i >= nextcontext) {
+               if (i >= MAXCONTEXTS)
+                       abort("Context:  out of them");
+               LONGCOPY(contexts[i].normal, M, sizeof(contexts[i].normal));
+               MatrixInvert(M, contexts[i].inverse);
+               nextcontext++;
+       }
+       return(i);
+}
+/*
+:h3.Context() - Create a Coordinate Space for a Device
+This user operator is implemented by first finding the device context
+array index, then transforming IDENTITY space to create an appropriate
+cooridnate space.
+*/
+struct XYspace *Context(device, units)
+       pointer device;       /* device token                                 */
+       double units;         /* multiples of one inch                        */
+{
+       double M[2][2];       /* device transformation matrix                 */
+       register int n;       /* will hold device context number              */
+       register struct XYspace *S;  /* XYspace constructed                   */
+       IfTrace2((MustTraceCalls),"Context(%x, %f)\n", device, &units);
+       ARGCHECK((device == NULL), "Context of NULLDEVICE not allowed",
+                    NULL, IDENTITY, (0), struct XYspace *);
+       ARGCHECK((units == 0.0), "Context: bad units", NULL, IDENTITY, (0), struct XYspace *);
+       n = FindDeviceContext(device);
+       LONGCOPY(M, contexts[n].normal, sizeof(M));
+       M[0][0] *= units;
+       M[0][1] *= units;
+       M[1][0] *= units;
+       M[1][1] *= units;
+       S = (struct XYspace *)Xform(IDENTITY, M);
+       S->context = n;
+       return(S);
+}
+#endif
+/*
+:h3.ConsiderContext() - Adjust a Matrix to Take Out Device Transform
+Remember, we have :f/x times U times D/ and :f/M/ and and we want :f/x
+times U times M times D/.  An easy way to do this is to calculate
+:f/D sup <-1> times M times D/, because:
+:formula.
+x times U times D times D sup <-1> times M times D = x times U times M times D
+:formula.
+So this subroutine, given an :f/M/and an object, finds the :f/D/ for that
+object and modifies :f/M/ so it is :f/D sup <-1> times M times D/.
+*/
+static void ConsiderContext(obj, M)
+       register struct xobject *obj;  /* object to be transformed            */
+       register double M[2][2];    /* matrix (may be changed)                */
+{
+       register int context; /* index in contexts array                      */
+       if (obj == NULL) return;
+       if (ISPATHTYPE(obj->type)) {
+               struct segment *path = (struct segment *) obj;
+               context = path->context;
+       }
+       else if (obj->type == SPACETYPE) {
+               struct XYspace *S = (struct XYspace *) obj;
+               context = S->context;
+       }
+       else if (obj->type == PICTURETYPE) {
+
+       }
+       else
+               context = NULLCONTEXT;
+       if (context != NULLCONTEXT) {
+               MatrixMultiply(contexts[context].inverse, M, M);
+               MatrixMultiply(M, contexts[context].normal, M);
+       }
+}
+/*
+:h2.Conversion from User's X,Y to "fractpel" X,Y
+When the user is building paths (lines, moves, curves, etc.) he passes
+the control points (x,y) for the paths together with an XYspace.  We
+must convert from the user's (x,y) to our internal representation
+which is in pels (fractpels, actually).  This involves transforming
+the user's (x,y) under the coordinate space transformation.  It is
+important that we do this quickly.  So, we store pointers to different
+conversion functions right in the XYspace structure.  This allows us
+to have simpler special case functions for the more commonly
+encountered types of transformations.
+:h3.Convert(), IConvert(), and ForceFloat() - Called Through "XYspace" Structure
+These are functions that fit in the "convert" and "iconvert" function
+pointers in the XYspace structure.  They call the "xconvert", "yconvert",
+"ixconvert", and "iyconvert" as appropriate to actually do the work.
+These secondary routines come in many flavors to handle different
+special cases as quickly as possible.
+*/
+static void FXYConvert(pt, S, x, y)
+       register struct fractpoint *pt;  /* point to set                      */
+       register struct XYspace *S;  /* relevant coordinate space             */
+       register double x,y;  /* user's coordinates of point                  */
+{
+       pt->x = (*S->xconvert)(S->tofract.normal[0][0], S->tofract.normal[1][0], x, y);
+       pt->y = (*S->yconvert)(S->tofract.normal[0][1], S->tofract.normal[1][1], x, y);
+}
+static void IXYConvert(pt, S, x, y)
+       register struct fractpoint *pt;  /* point to set                      */
+       register struct XYspace *S;  /* relevant coordinate space             */
+       register long x,y;    /* user's coordinates of point                  */
+{
+       pt->x = (*S->ixconvert)(S->itofract[0][0], S->itofract[1][0], x, y);
+       pt->y = (*S->iyconvert)(S->itofract[0][1], S->itofract[1][1], x, y);
+}
+/*
+ForceFloat is a substitute for IConvert(), when we just do not have
+enough significant digits in the coefficients to get high enough
+precision in the answer with fixed point arithmetic.  So, we force the
+integers to floats, and do the arithmetic all with floats:
+*/
+static void ForceFloat(pt, S, x, y)
+       register struct fractpoint *pt;  /* point to set                      */
+       register struct XYspace *S;  /* relevant coordinate space             */
+       register long x,y;    /* user's coordinates of point                  */
+{
+       (*S->convert)(pt, S, (double) x, (double) y);
+}
+/*
+:h3.FXYboth(), FXonly(), FYonly() - Floating Point Conversion
+These are the routines we use when the user has given us floating
+point numbers for x and y. FXYboth() is the general purpose routine;
+FXonly() and FYonly() are special cases when one of the coefficients
+is 0.0.
+*/
+static fractpel FXYboth(cx, cy, x, y)
+       register double cx,cy;  /* x and y coefficients                       */
+       register double x,y;  /* user x,y                                     */
+{
+       register double r;    /* temporary float                              */
+       r = x * cx + y * cy;
+       return((fractpel) r);
+}
+/*ARGSUSED*/
+static fractpel FXonly(cx, cy, x, y)
+       register double cx,cy;  /* x and y coefficients                       */
+       register double x,y;  /* user x,y                                     */
+{
+       register double r;    /* temporary float                              */
+       r = x * cx;
+       return((fractpel) r);
+}
+/*ARGSUSED*/
+static fractpel FYonly(cx, cy, x, y)
+       register double cx,cy;  /* x and y coefficients                       */
+       register double x,y;  /* user x,y                                     */
+{
+       register double r;    /* temporary float                              */
+       r = y * cy;
+       return((fractpel) r);
+}
+/*
+:h3.IXYboth(), IXonly(), IYonly() - Simple Integer Conversion
+These are the routines we use when the user has given us integers for
+x and y, and the coefficients have enough significant digits to
+provide precise answers with only "long" (32 bit?) multiplication.
+IXYboth() is the general purpose routine; IXonly() and IYonly() are
+special cases when one of the coefficients is 0.
+*/
+static fractpel IXYboth(cx, cy, x, y)
+       register fractpel cx,cy;  /* x and y coefficients                     */
+       register long x,y;    /* user x,y                                     */
+{
+       return(x * cx + y * cy);
+}
+/*ARGSUSED*/
+static fractpel IXonly(cx, cy, x, y)
+       register fractpel cx,cy;  /* x and y coefficients                     */
+       register long x,y;    /* user x,y                                     */
+{
+       return(x * cx);
+}
+/*ARGSUSED*/
+static fractpel IYonly(cx, cy, x, y)
+       register fractpel cx,cy;  /* x and y coefficients                     */
+       register long x,y;    /* user x,y                                     */
+{
+       return(y * cy);
+}
+/*
+:h3.FPXYboth(), FPXonly(), FPYonly() - More Involved Integer Conversion
+These are the routines we use when the user has given us integers for
+x and y, but the coefficients do not have enough significant digits to
+provide precise answers with only "long" (32 bit?)  multiplication.
+We have increased the number of significant bits in the coefficients
+by FRACTBITS; therefore we must use "double long" (64 bit?)
+multiplication by calling FPmult().  FPXYboth() is the general purpose
+routine; FPXonly() and FPYonly() are special cases when one of the
+coefficients is 0.
+Note that it is perfectly possible for us to calculate X with the
+"FP" method and Y with the "I" method, or vice versa.  It all depends
+on how the functions in the XYspace structure are filled out.
+*/
+static fractpel FPXYboth(cx, cy, x, y)
+       register fractpel cx,cy;  /* x and y coefficients                     */
+       register long x,y;    /* user x,y                                     */
+{
+       return( FPmult(x, cx) + FPmult(y, cy) );
+}
+/*ARGSUSED*/
+static fractpel FPXonly(cx, cy, x, y)
+       register fractpel cx,cy;  /* x and y coefficients                     */
+       register long x,y;    /* user x,y                                     */
+{
+       return( FPmult(x, cx) );
+}
+/*ARGSUSED*/
+static fractpel FPYonly(cx, cy, x, y)
+       register fractpel cx,cy;  /* x and y coefficients                     */
+       register long x,y;    /* user x,y                                     */
+{
+       return( FPmult(y, cy) );
+}
+/*
+:h3.FillOutFcns() - Determine the Appropriate Functions to Use for Conversion
+This function fills out the "convert" and "iconvert" function pointers
+in an XYspace structure, and also fills the "helper"
+functions that actually do the work.
+*/
+static void FillOutFcns(S)
+       register struct XYspace *S;  /* functions will be set in this structure */
+{
+       S->convert = FXYConvert;
+       S->iconvert = IXYConvert;
+       FindFfcn(S->tofract.normal[0][0], S->tofract.normal[1][0], &S->xconvert);
+       FindFfcn(S->tofract.normal[0][1], S->tofract.normal[1][1], &S->yconvert);
+       FindIfcn(S->tofract.normal[0][0], S->tofract.normal[1][0],
+                &S->itofract[0][0], &S->itofract[1][0], &S->ixconvert);
+       FindIfcn(S->tofract.normal[0][1], S->tofract.normal[1][1],
+                &S->itofract[0][1], &S->itofract[1][1], &S->iyconvert);
+       if (S->ixconvert == NULL || S->iyconvert == NULL)
+                S->iconvert = ForceFloat;
+}
+/*
+:h4.FindFfcn() - Subroutine of FillOutFcns() to Fill Out Floating Functions
+This function tests for the special case of one of the coefficients
+being zero:
+*/
+static void FindFfcn(cx, cy, fcnP)
+       register double cx,cy;  /* x and y coefficients                       */
+       register fractpel (**fcnP)();  /* pointer to function to set          */
+{
+       if (cx == 0.0)
+               *fcnP = FYonly;
+       else if (cy == 0.0)
+               *fcnP = FXonly;
+       else
+               *fcnP = FXYboth;
+}
+/*
+:h4.FindIfcn() - Subroutine of FillOutFcns() to Fill Out Integer Functions
+There are two types of integer functions, the 'I' type and the 'FP' type.
+We use the I type functions when we are satisfied with simple integer
+arithmetic.  We used the FP functions when we feel we need higher
+precision (but still fixed point) arithmetic.  If all else fails,
+we store a NULL indicating that this we should do the conversion in
+floating point.
+*/
+static void FindIfcn(cx, cy, icxP, icyP, fcnP)
+       register double cx,cy;  /* x and y coefficients                       */
+       register fractpel *icxP,*icyP;  /* fixed point coefficients to set    */
+       register fractpel (**fcnP)();  /* pointer to function to set          */
+{
+       register fractpel imax;  /* maximum of cx and cy                      */
+       *icxP = cx;
+       *icyP = cy;
+       if (cx != (float) (*icxP) || cy != (float) (*icyP)) {
+/*
+At this point we know our integer approximations of the coefficients
+are not exact.  However, we will still use them if the maximum
+coefficient will not fit in a 'fractpel'.   Of course, we have little
+choice at that point, but we haven't lost that much precision by
+staying with integer arithmetic.  We have enough significant digits
+so that
+any error we introduce is less than one part in 2:sup/16/.
+*/
+               imax = MAX(ABS(*icxP), ABS(*icyP));
+               if (imax < (fractpel) (1<<(FRACTBITS-1)) ) {
+/*
+At this point we know our integer approximations just do not have
+enough significant digits for accuracy.  We will add FRACTBITS
+significant digits to the coefficients (by multiplying them by
+1<<FRACTBITS) and go to the "FP" form of the functions.  First, we
+check to see if we have ANY significant digits at all (that is, if
+imax == 0).  If we don't, we suspect that adding FRACTBITS digits
+won't help, so we punt the whole thing.
+*/
+                       if (imax == 0) {
+                               *fcnP = NULL;
+                               return;
+                       }
+                       cx *= FRACTFLOAT;
+                       cy *= FRACTFLOAT;
+                       *icxP = cx;
+                       *icyP = cy;
+                       *fcnP = FPXYboth;
+               }
+               else
+                       *fcnP = IXYboth;
+       }
+       else
+               *fcnP = IXYboth;
+/*
+Now we check for special cases where one coefficient is zero (after
+integer conversion):
+*/
+       if (*icxP == 0)
+               *fcnP = (*fcnP == FPXYboth) ? FPYonly : IYonly;
+       else if (*icyP == 0)
+               *fcnP = (*fcnP == FPXYboth) ? FPXonly : IXonly;
+}
+/*
+:h3.UnConvert() - Find User Coordinates From FractPoints
+The interesting thing with this routine is that we avoid calculating
+the matrix inverse of the device transformation until we really need
+it, which is to say, until this routine is called for the first time
+with a given coordinate space.
+We also only calculate it only once.  If the inverted matrix is valid,
+we don't calculate it; if not, we do.  We never expect matrices with
+zero determinants, so by convention, we mark the matrix is invalid by
+marking both X terms zero.
+*/
+void UnConvert(S, pt, xp, yp)
+       register struct XYspace *S;  /* relevant coordinate space             */
+       register struct fractpoint *pt;  /* device coordinates                */
+       double *xp,*yp;       /* where to store resulting x,y                 */
+{
+       double x,y;
+       CoerceInverse(S);
+       x = pt->x;
+       y = pt->y;
+       *xp = S->tofract.inverse[0][0] * x + S->tofract.inverse[1][0] * y;
+       *yp = S->tofract.inverse[0][1] * x + S->tofract.inverse[1][1] * y;
+}
+/*
+:h2.Transformations
+*/
+/*
+:h3 id=xform.Xform() - Transform Object in X and Y
+TYPE1IMAGER wants transformations of objects like paths to be identical
+to transformations of spaces.  For example, if you scale a line(1,1)
+by 10 it should yield the same result as generating the line(1,1) in
+a coordinate space that has been scaled by 10.
+We handle fonts by storing the accumulated transform, for example, SR
+(accumulating on the right).  Then when we map the font through space TD,
+for example, we multiply the accumulated font transform on the left by
+the space transform on the right, yielding SRTD in this case.  We will
+get the same result if we did S, then R, then T on the space and mapping
+an unmodified font through that space.
+*/
+struct xobject *t1_Xform(obj, M)
+       register struct xobject *obj;  /* object to transform                 */
+       register double M[2][2];    /* transformation matrix                  */
+{
+       if (obj == NULL)
+               return(NULL);
+       if (obj->type == FONTTYPE) {
+               register struct font *F = (struct font *) obj;
+               F = UniqueFont(F);
+               return((struct xobject*)F);
+       }
+       if (obj->type == PICTURETYPE) {
+/*
+In the case of a picture, we choose both to update the picture's
+transformation matrix and keep the handles up to date.
+*/
+               register struct picture *P = (struct picture *) obj;
+               register struct segment *handles;  /* temporary path to transform handles */
+               P = UniquePicture(P);
+               handles = PathSegment(LINETYPE, P->origin.x, P->origin.y);
+               handles = Join(handles,
+                              PathSegment(LINETYPE, P->ending.x, P->ending.y) );
+               handles = (struct segment *)Xform((struct xobject *) handles, M);
+               P->origin = handles->dest;
+               P->ending = handles->link->dest;
+               KillPath(handles);
+               return((struct xobject *)P);
+       }
+       if (ISPATHTYPE(obj->type)) {
+               struct XYspace pseudo;  /* local temporary space              */
+               PseudoSpace(&pseudo, M);
+               return((struct xobject *) PathTransform(obj, &pseudo));
+       }
+       if (obj->type == SPACETYPE) {
+               register struct XYspace *S = (struct XYspace *) obj;
+/* replaced ISPERMANENT(S->flag) with S->references > 1 3-26-91 PNM */
+               if (S->references > 1)
+                       S = CopySpace(S);
+               else
+                       S->ID = NEXTID;
+               MatrixMultiply(S->tofract.normal, M, S->tofract.normal);
+               /*
+               * mark inverted matrix invalid:
+               */
+               S->flag &= ~HASINVERSE(ON);
+               FillOutFcns(S);
+               return((struct xobject *) S);
+       }
+       return(ArgErr("Untransformable object", obj, obj));
+}
+/*
+:h3.Transform() - Transform an Object
+This is the external user's entry point.
+*/
+struct xobject *t1_Transform(obj, cxx, cyx, cxy, cyy)
+       struct xobject *obj;
+       double cxx,cyx,cxy,cyy;  /* 2x2 transform matrix elements in row order */
+{
+       double M[2][2];
+       IfTrace1((MustTraceCalls),"Transform(%z,", obj);
+       IfTrace4((MustTraceCalls)," %f %f %f %f)\n", &cxx, &cyx, &cxy, &cyy);
+       M[0][0] = cxx;
+       M[0][1] = cyx;
+       M[1][0] = cxy;
+       M[1][1] = cyy;
+       ConsiderContext(obj, M);
+       return(Xform(obj, M));
+}
+/*
+:h3.Scale() - Special Case of Transform()
+This is a user operator.
+*/
+struct xobject *t1_Scale(obj, sx, sy)
+       struct xobject *obj;  /* object to scale                              */
+       double sx,sy;         /* scale factors in x and y                     */
+{
+       double M[2][2];
+       IfTrace3((MustTraceCalls),"Scale(%z, %f, %f)\n", obj, &sx, &sy);
+       M[0][0] = sx;
+       M[1][1] = sy;
+       M[1][0] = M[0][1] = 0.0;
+       ConsiderContext(obj, M);
+       return(Xform(obj, M));
+}
+/*
+:h3 id=rotate.Rotate() - Special Case of Transform()
+We special-case different settings of 'degrees' for performance
+and accuracy within the DegreeSin() and DegreeCos() routines themselves.
+*/
+#ifdef notdef
+struct xobject *xiRotate(obj, degrees)
+       struct xobject *obj;  /* object to be transformed                     */
+       double degrees;       /* degrees of COUNTER-clockwise rotation        */
+{
+       double M[2][2];
+       IfTrace2((MustTraceCalls),"Rotate(%z, %f)\n", obj, &degrees);
+       M[0][0] = M[1][1] = DegreeCos(degrees);
+       M[1][0] = - (M[0][1] = DegreeSin(degrees));
+       ConsiderContext(obj, M);
+       return(Xform(obj, M));
+}
+#endif
+/*
+:h3.PseudoSpace() - Build a Coordinate Space from a Matrix
+Since we have built all this optimized code that, given an (x,y) and
+a coordinate space, yield transformed (x,y), it seems a shame not to
+use the same logic when we need to multiply an (x,y) by an arbitrary
+matrix that is not (initially) part of a coordinate space.  This
+subroutine takes the arbitrary matrix and builds a coordinate
+space, with all its nifty function pointers.
+*/
+void PseudoSpace(S, M)
+       struct XYspace *S;    /* coordinate space structure to fill out       */
+       double M[2][2];       /* matrix that will become 'tofract.normal'     */
+{
+       S->type = SPACETYPE;
+       S->flag = ISPERMANENT(ON) + ISIMMORTAL(ON);
+       S->references = 2;   /* 3-26-91 added PNM  */
+       S->tofract.normal[0][0] = M[0][0];
+       S->tofract.normal[1][0] = M[1][0];
+       S->tofract.normal[0][1] = M[0][1];
+       S->tofract.normal[1][1] = M[1][1];
+       FillOutFcns(S);
+}
+/*
+:h2 id=matrixa.Matrix Arithmetic
+Following the convention in Newman and Sproull, :hp1/Interactive
+Computer Graphics/,
+matrices are organized:
+:xmp.
+       | cxx   cyx |
+       | cxy   cyy |
+:exmp.
+A point is horizontal, for example:
+:xmp.
+       [ x y ]
+:exmp.
+This means that:
+:formula/x prime = cxx times x + cxy times y/
+:formula/y prime = cyx times x + cyy times y/
+I've seen the other convention, where transform matrices are
+transposed, equally often in the literature.
+*/
+/*
+:h3.MatrixMultiply() - Implements Multiplication of Two Matrices
+Implements matrix multiplication, A * B = C.
+To remind myself, matrix multiplication goes rows of A times columns
+of B.
+The output matrix may be the same as one of the input matrices.
+*/
+void MatrixMultiply(A, B, C)
+       register double A[2][2],B[2][2];  /* input matrices                   */
+       register double C[2][2];    /* output matrix                          */
+{
+       register double txx,txy,tyx,tyy;
+       txx = A[0][0] * B[0][0] + A[0][1] * B[1][0];
+       txy = A[1][0] * B[0][0] + A[1][1] * B[1][0];
+       tyx = A[0][0] * B[0][1] + A[0][1] * B[1][1];
+       tyy = A[1][0] * B[0][1] + A[1][1] * B[1][1];
+       C[0][0] = txx;
+       C[1][0] = txy;
+       C[0][1] = tyx;
+       C[1][1] = tyy;
+}
+/*
+:h3.MatrixInvert() - Invert a Matrix
+My reference for matrix inversion was :hp1/Elementary Linear Algebra/
+by Paul C. Shields, Worth Publishers, Inc., 1968.
+*/
+void MatrixInvert(M, Mprime)
+       double M[2][2];       /* input matrix                                 */
+       double Mprime[2][2];    /* output inverted matrix                     */
+{
+       register double D;    /* determinant of matrix M                      */
+       register double txx,txy,tyx,tyy;
+       txx = M[0][0];
+       txy = M[1][0];
+       tyx = M[0][1];
+       tyy = M[1][1];
+       D = M[1][1] * M[0][0] - M[1][0] * M[0][1];
+       if (D == 0.0)
+               abort("MatrixInvert:  can't");
+       Mprime[0][0] = tyy / D;
+       Mprime[1][0] = -txy / D;
+       Mprime[0][1] = -tyx / D;
+       Mprime[1][1] = txx / D;
+}
+/*
+:h2.Initialization, Queries, and Debug
+*/
+/*
+:h3.InitSpaces() - Initialize Constant Spaces
+For compatibility, we initialize a coordinate space called USER which
+maps 72nds of an inch to pels on the default device.
+*/
+struct XYspace *USER = &identity;
+void InitSpaces()
+{
+       extern char *DEFAULTDEVICE;
+       IDENTITY->type = SPACETYPE;
+       FillOutFcns(IDENTITY);
+       contexts[NULLCONTEXT].normal[1][0]
+             = contexts[NULLCONTEXT].normal[0][1]
+             = contexts[NULLCONTEXT].inverse[1][0]
+             = contexts[NULLCONTEXT].inverse[0][1] = 0.0;
+       contexts[NULLCONTEXT].normal[0][0]
+             = contexts[NULLCONTEXT].normal[1][1]
+             = contexts[NULLCONTEXT].inverse[0][0]
+             = contexts[NULLCONTEXT].inverse[1][1] = 1.0;
+       USER->flag |= ISIMMORTAL(ON);
+       CoerceInverse(USER);
+}
+/*
+:h3.QuerySpace() - Returns the Transformation Matrix of a Space
+Since the tofract matrix of an XYspace includes the scale factor
+necessary to produce fractpel results (i.e., FRACTFLOAT), this
+must be taken out before we return the matrix to the user.  Fortunately,
+this is simple:  just multiply by the inverse of IDENTITY!
+*/
+void QuerySpace(S, cxxP, cyxP, cxyP, cyyP)
+       register struct XYspace *S;  /* space asked about                     */
+       register double *cxxP,*cyxP,*cxyP,*cyyP;  /* where to put answer      */
+{
+       double M[2][2];       /* temp matrix to build user's answer           */
+       if (S->type != SPACETYPE) {
+               ArgErr("QuerySpace: not a space", S, NULL);
+               return;
+       }
+       MatrixMultiply(S->tofract.normal, IDENTITY->tofract.inverse, M);
+       *cxxP = M[0][0];
+       *cxyP = M[1][0];
+       *cyxP = M[0][1];
+       *cyyP = M[1][1];
+}
+/*
+:h3.FormatFP() - Format a Fixed Point Pel
+We format the pel as "dddd.XXXX", where XX's are hexidecimal digits,
+and the dd's are decimal digits.  This might be a little confusing
+mixing hexidecimal and decimal like that, but it is convenient
+to use for debug.
+We make sure we have N (FRACTBITS/4) digits past the decimal point.
+*/
+#define  FRACTMASK   ((1<<FRACTBITS)-1)  /* mask for fractional part         */
+void FormatFP(string, fpel)
+       register char *string;  /* output string                              */
+       register fractpel fpel; /* fractional pel input                       */
+{
+       char temp[8];
+       register char *s;
+       register char *sign;
+       if (fpel < 0) {
+               sign = "-";
+               fpel = -fpel;
+       }
+       else
+               sign = "";
+       sprintf(temp, "000%x", fpel & FRACTMASK);
+       s = temp + strlen(temp) - (FRACTBITS/4);
+       sprintf(string, "%s%d.%sx", sign, fpel >> FRACTBITS, s);
+}
+/*
+:h3.DumpSpace() - Display a Coordinate Space
+*/
+/*ARGSUSED*/
+void DumpSpace(S)
+       register struct XYspace *S;
+{
+       IfTrace4(TRUE,"--Coordinate space at %x,ID=%d,convert=%x,iconvert=%x\n",
+                   S, S->ID, S->convert, S->iconvert);
+       IfTrace2(TRUE,"             |  %12.3f  %12.3f  |",
+                   &S->tofract.normal[0][0], &S->tofract.normal[0][1]);
+       IfTrace2(TRUE,"   [  %p  %p ]\n", S->itofract[0][0], S->itofract[0][1]);
+       IfTrace2(TRUE,"             |  %12.3f  %12.3f  |",
+                   &S->tofract.normal[1][0], &S->tofract.normal[1][1]);
+       IfTrace2(TRUE,"   [  %p  %p ]\n", S->itofract[1][0], S->itofract[1][1]);
+}
diff --git a/Xserver/lib/font/Type1/spaces.h b/Xserver/lib/font/Type1/spaces.h
new file mode 100644 (file)
index 0000000..d19d9b3
--- /dev/null
@@ -0,0 +1,140 @@
+/* $XConsortium: spaces.h,v 1.4 94/02/06 16:27:06 gildea Exp $ */
+/* Copyright International Business Machines, Corp. 1991
+ * All Rights Reserved
+ * Copyright Lexmark International, Inc. 1991
+ * All Rights Reserved
+ *
+ * License to use, copy, modify, and distribute this software and its
+ * documentation for any purpose and without fee is hereby granted,
+ * provided that the above copyright notice appear in all copies and that
+ * both that copyright notice and this permission notice appear in
+ * supporting documentation, and that the name of IBM or Lexmark not be
+ * used in advertising or publicity pertaining to distribution of the
+ * software without specific, written prior permission.
+ *
+ * IBM AND LEXMARK PROVIDE THIS SOFTWARE "AS IS", WITHOUT ANY WARRANTIES OF
+ * ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING, BUT NOT LIMITED TO ANY
+ * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE,
+ * AND NONINFRINGEMENT OF THIRD PARTY RIGHTS.  THE ENTIRE RISK AS TO THE
+ * QUALITY AND PERFORMANCE OF THE SOFTWARE, INCLUDING ANY DUTY TO SUPPORT
+ * OR MAINTAIN, BELONGS TO THE LICENSEE.  SHOULD ANY PORTION OF THE
+ * SOFTWARE PROVE DEFECTIVE, THE LICENSEE (NOT IBM OR LEXMARK) ASSUMES THE
+ * ENTIRE COST OF ALL SERVICING, REPAIR AND CORRECTION.  IN NO EVENT SHALL
+ * IBM OR LEXMARK BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
+ * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
+ * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
+ * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
+ * THIS SOFTWARE.
+ */
+/*SHARED*/
+#define   USER                       t1_User
+#define   IDENTITY                   t1_Identity
+#define   Context(d,u)               t1_Context(d,u)
+#define   Transform(o,f1,f2,f3,f4)   t1_Transform(o,f1,f2,f3,f4)
+#define   Rotate(o,d)                t1_Rotate(o,d)
+#define   Scale(o,sx,sy)             t1_Scale(o,sx,sy)
+#define   QuerySpace(S,f1,f2,f3,f4)  t1_QuerySpace(S,f1,f2,f3,f4)
+#define   Warp(s1,o,s2)              t1_Warp(s1,o,s2)
+struct XYspace *t1_Context(); /* creates a coordinate space for a device      */
+struct xobject *t1_Transform();  /* transform an object                       */
+struct xobject *t1_Rotate();  /* rotate an object                             */
+struct xobject *t1_Scale();   /* scale an object                              */
+struct xobject *t1_Warp();    /* transform like delta of two spaces           */
+void t1_QuerySpace();         /* returns coordinate space matrix              */
+/*END SHARED*/
+/*SHARED*/
+#define   DeviceResolution   t1_DeviceResolution
+#define   InitSpaces()       t1_InitSpaces()
+#define   CopySpace(s)       t1_CopySpace(s)
+#define   Xform(o,M)         t1_Xform(o,M)
+#define   UnConvert(S,pt,xp,yp)    t1_UnConvert(S,pt,xp,yp)
+#define   MatrixMultiply(A,B,C)    t1_MMultiply(A,B,C)
+#define   MatrixInvert(A,B)        t1_MInvert(A,B)
+#define   PseudoSpace(S,M)   t1_PseudoSpace(S,M)
+#define   FindContext(M)     t1_FindContext(M)
+void t1_InitSpaces();         /* initialize pre-defined coordinate spaces     */
+struct XYspace *t1_CopySpace(); /* duplicate a coordinate space               */
+struct xobject *t1_Xform();   /* transform object by matrix                   */
+void t1_UnConvert();          /* return user coordinates from device coordinates */
+void t1_MMultiply();          /* multiply two matrices                        */
+void t1_MInvert();            /* invert a matrix                              */
+void t1_PseudoSpace();        /* force a coordinate space from a matrix       */
+int t1_FindContext();         /* return the "context" represented by a matrix */
+/*END SHARED*/
+/*SHARED*/
+/* #define    KillSpace(s)     Free(s)
+Note - redefined KillSpace() to check references !
+3-26-91 PNM */
+#define KillSpace(s)      if ( (--(s->references) == 0) ||\
+                      ( (s->references == 1) && ISPERMANENT(s->flag) ) )\
+                        Free(s)
+#define    ConsumeSpace(s)  MAKECONSUME(s,KillSpace(s))
+#define    UniqueSpace(s)   MAKEUNIQUE(s,CopySpace(s))
+/*END SHARED*/
+/*SHARED*/
+typedef short pel;           /* integer pel locations                        */
+typedef long fractpel;       /* fractional pel locations                     */
+#define   FRACTBITS     16   /* number of fractional bits in 'fractpel'      */
+/*
+We define the following macros to convert from 'fractpel' to 'pel' and
+vice versa:
+*/
+#define   TOFRACTPEL(p)   (((fractpel)p)<<FRACTBITS)
+#define   FPHALF          (1<<(FRACTBITS-1))
+#define   NEARESTPEL(fp)  (((fp)+FPHALF)>>FRACTBITS)
+#define   FRACTFLOAT   (double)(1L<<FRACTBITS)
+/*END SHARED*/
+/*SHARED*/
+struct doublematrix {
+       double normal[2][2];
+       double inverse[2][2];
+} ;
+/*END SHARED*/
+/*SHARED*/
+struct XYspace {
+       XOBJ_COMMON           /* xobject common data define 3-26-91 PNM       */
+                            /* type = SPACETYPE                             */
+       void (*convert)();     /* calculate "fractpoint" X,Y from float X,Y   */
+       void (*iconvert)();    /* calculate "fractpoint" X,Y from int X,Y     */
+       fractpel (*xconvert)();  /* subroutine of convert                     */
+       fractpel (*yconvert)();  /* subroutine of convert                     */
+       fractpel (*ixconvert)();  /* subroutine of iconvert                   */
+       fractpel (*iyconvert)();  /* subroutine of iconvert                   */
+       int ID;               /* unique identifier (used in font caching)     */
+       unsigned char context;  /* device context of coordinate space         */
+       struct doublematrix tofract;  /* xform to get to fractional pels      */
+       fractpel itofract[2][2];  /* integer version of "tofract.normal"      */
+} ;
+#define    INVALIDID  0      /* no valid space will have this ID             */
+/*END SHARED*/
+/*SHARED*/
+struct fractpoint {
+       fractpel x,y;
+} ;
+/*END SHARED*/
+/*SHARED*/
+#define  NULLCONTEXT   0
+/*END SHARED*/
diff --git a/Xserver/lib/font/Type1/strokes.h b/Xserver/lib/font/Type1/strokes.h
new file mode 100644 (file)
index 0000000..5907632
--- /dev/null
@@ -0,0 +1,38 @@
+/* $XConsortium: strokes.h,v 1.2 91/10/10 11:19:25 rws Exp $ */
+/* Copyright International Business Machines,Corp. 1991
+ * All Rights Reserved
+ *
+ * License to use, copy, modify, and distribute this software
+ * and its documentation for any purpose and without fee is
+ * hereby granted, provided that the above copyright notice
+ * appear in all copies and that both that copyright notice and
+ * this permission notice appear in supporting documentation,
+ * and that the name of IBM not be used in advertising or
+ * publicity pertaining to distribution of the software without
+ * specific, written prior permission.
+ *
+ * IBM PROVIDES THIS SOFTWARE "AS IS", WITHOUT ANY WARRANTIES
+ * OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING, BUT NOT
+ * LIMITED TO ANY IMPLIED WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, AND NONINFRINGEMENT OF
+ * THIRD PARTY RIGHTS.  THE ENTIRE RISK AS TO THE QUALITY AND
+ * PERFORMANCE OF THE SOFTWARE, INCLUDING ANY DUTY TO SUPPORT
+ * OR MAINTAIN, BELONGS TO THE LICENSEE.  SHOULD ANY PORTION OF
+ * THE SOFTWARE PROVE DEFECTIVE, THE LICENSEE (NOT IBM) ASSUMES
+ * THE ENTIRE COST OF ALL SERVICING, REPAIR AND CORRECTION.  IN
+ * NO EVENT SHALL IBM BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
+ * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
+ * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
+ * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+ */
+/*STUB*/
+#define   CopyLineStyle(s)    s
+#define   CopyStrokePath(p)   p
+#define   KillStrokePath(p)
+#define   KillLineStyle(s)
+#define   CoercePath(sp)      sp
+#define   DoStroke(sp)        sp
diff --git a/Xserver/lib/font/Type1/t1funcs.c b/Xserver/lib/font/Type1/t1funcs.c
new file mode 100644 (file)
index 0000000..0b01922
--- /dev/null
@@ -0,0 +1,697 @@
+/* $TOG: t1funcs.c /main/23 1997/06/09 14:55:44 barstow $ */
+/* Copyright International Business Machines,Corp. 1991
+ * All Rights Reserved
+ *
+ * License, subject to the license given below, to use,
+ * copy, modify, and distribute this software * and its
+ * documentation for any purpose and without fee is hereby
+ * granted, provided that the above copyright notice appear
+ * in all copies and that both that copyright notice and
+ * this permission notice appear in supporting documentation,
+ * and that the name of IBM not be used in advertising or
+ * publicity pertaining to distribution of the software
+ * without specific, written prior permission.
+ *
+ * IBM PROVIDES THIS SOFTWARE "AS IS", WITHOUT ANY WARRANTIES
+ * OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING, BUT NOT
+ * LIMITED TO ANY IMPLIED WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, AND NONINFRINGEMENT OF
+ * THIRD PARTY RIGHTS.  THE ENTIRE RISK AS TO THE QUALITY AND
+ * PERFORMANCE OF THE SOFTWARE, INCLUDING ANY DUTY TO SUPPORT
+ * OR MAINTAIN, BELONGS TO THE LICENSEE.  SHOULD ANY PORTION OF
+ * THE SOFTWARE PROVE DEFECTIVE, THE LICENSEE (NOT IBM) ASSUMES
+ * THE ENTIRE COST OF ALL SERVICING, REPAIR AND CORRECTION.  IN
+ * NO EVENT SHALL IBM BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
+ * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
+ * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
+ * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+ *
+ * Author: Jeffrey B. Lotspiech, IBM Almaden Research Center
+ *   Modeled on spfuncs.c by Dave Lemke, Network Computing Devices, Inc
+ *   which contains the following copyright and permission notices:
+ *
+ * Copyright 1990, 1991 Network Computing Devices;
+ * Portions Copyright 1987 by Digital Equipment Corporation
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the names of Network Computing Devices
+ * or Digital not be used in advertising or publicity pertaining to 
+ * distribution of the software without specific, written prior permission.  
+ * Network Computing Devices or Digital make no representations about the
+ * suitability of this software for any purpose.  It is provided "as is"
+ * without express or implied warranty.
+ *
+ * NETWORK COMPUTING DEVICES AND DIGITAL DISCLAIM ALL WARRANTIES WITH
+ * REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS, IN NO EVENT SHALL NETWORK COMPUTING DEVICES OR DIGITAL BE
+ * LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
+ * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
+ * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+/* $XFree86: xc/lib/font/Type1/t1funcs.c,v 3.4.2.1 1997/07/05 15:55:35 dawes Exp $ */
+
+/*
+
+Copyright (c) 1987, 1994  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be included
+in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR
+OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall
+not be used in advertising or otherwise to promote the sale, use or
+other dealings in this Software without prior written authorization
+from the X Consortium.
+
+*/
+#include <string.h>
+#ifdef _XOPEN_SOURCE
+#include <math.h>
+#else
+#define _XOPEN_SOURCE  /* to get prototype for hypot on some systems */
+#include <math.h>
+#undef _XOPEN_SOURCE
+#endif
+#include "X11/Xfuncs.h"
+#include "fntfilst.h"
+#include "FSproto.h"
+#include "t1intf.h"
+#include "objects.h"
+#include "spaces.h"
+#include "regions.h"
+#include "t1stdio.h"
+#include "util.h"
+#include "fontfcn.h"
+int         Type1OpenScalable ();
+static int  Type1GetGlyphs();
+void        Type1CloseFont();
+extern int  Type1GetInfoScalable ();
+static int  Type1GetMetrics ();
+#define minchar(p) ((p).min_char_low + ((p).min_char_high << 8))
+#define maxchar(p) ((p).max_char_low + ((p).max_char_high << 8))
+
+static void fillrun();
+extern psfont *FontP;
+extern psobj *ISOLatin1EncArrayP;
+
+extern unsigned long *Xalloc();
+static void fill();
+/*ARGSUSED*/
+int Type1OpenScalable (fpe, ppFont, flags, entry, fileName, vals, format,
+                      fmask, non_cachable_font)
+    FontPathElementPtr  fpe;
+    FontPtr             *ppFont;
+    int                 flags;
+    FontEntryPtr        entry;
+    char                *fileName;
+    FontScalablePtr     vals;
+    fsBitmapFormat      format;
+    fsBitmapFormatMask  fmask;
+    FontPtr            non_cachable_font;      /* We don't do licensing */
+{
+       extern struct XYspace *IDENTITY;
+       extern Bool fontfcnA();
+       extern struct region *fontfcnB();
+       FontPtr     pFont;
+       int         bit,
+                   byte,
+                   glyph,
+                   scan,
+                   image;
+       int pad,wordsize;     /* scan & image in bits                         */
+       unsigned long *pool;  /* memory pool for ximager objects              */
+       int size;             /* for memory size calculations                 */
+       struct XYspace *S;    /* coordinate space for character               */
+       struct region *area;
+       CharInfoRec *glyphs;
+       register int i;
+       int len, rc, count = 0;
+       struct type1font *type1;
+       char *p;
+       psobj *fontencoding = NULL;
+       fsRange char_range;
+       psobj *fontmatrix;
+       long x0, total_width = 0, total_raw_width = 0;
+       double x1, y1, t1 = .001, t2 = 0.0, t3 = 0.0, t4 = .001;
+       double sxmult;
+
+       /* Reject ridiculously small font sizes that will blow up the math */
+       if (hypot(vals->pixel_matrix[0], vals->pixel_matrix[1]) < 1.0 ||
+          hypot(vals->pixel_matrix[2], vals->pixel_matrix[3]) < 1.0)
+          return BadFontName;
+
+       /* set up default values */
+       FontDefaultFormat(&bit, &byte, &glyph, &scan);
+       /* get any changes made from above */
+       rc = CheckFSFormat(format, fmask, &bit, &byte, &scan, &glyph, &image);
+       if (rc != Successful)
+               return rc;
+       pad                = glyph * 8;
+       wordsize           = scan * 8;
+#define  PAD(bits, pad)  (((bits)+(pad)-1)&-(pad))
+       pFont = (FontPtr) xalloc(sizeof(FontRec));
+       if (pFont == NULL)
+           return AllocError;
+       type1 = (struct type1font *)xalloc(sizeof(struct type1font));
+       if (type1 == NULL) {
+               xfree(pFont);
+               return AllocError;
+       }
+       bzero(type1, sizeof(struct type1font));
+       /* heuristic for "maximum" size of pool we'll need: */
+       size = 200000 + 120 *
+             (int)hypot(vals->pixel_matrix[2], vals->pixel_matrix[3])
+             * sizeof(short);
+       if (size < 0 || NULL == (pool = (unsigned long *) xalloc(size))) {
+               xfree(type1);
+               xfree(pFont);
+               return AllocError;
+       }
+       addmemory(pool, size);
+       glyphs = type1->glyphs;
+       /* load font if not already loaded */
+       if (!fontfcnA(fileName, &rc)) {
+         delmemory();
+        xfree(type1);
+        xfree(pFont);
+         xfree(pool);
+         return Type1ReturnCodeToXReturnCode(rc);
+       }
+
+       fontmatrix = &FontP->fontInfoP[FONTMATRIX].value;
+       if (objPIsArray(fontmatrix) && fontmatrix->len == 6)
+       {
+#define assign(n,d,f) if (objPIsInteger(fontmatrix->data.arrayP + n)) \
+                         d = fontmatrix->data.arrayP[n].data.integer; \
+                     else if (objPIsReal(fontmatrix->data.arrayP + n)) \
+                         d = fontmatrix->data.arrayP[n].data.real; \
+                     else d = f;
+
+          assign(0, t1, .001);
+          assign(1, t2, 0.0);
+          assign(2, t3, 0.0);
+          assign(3, t4, .001);
+       }
+
+       S = (struct XYspace *) t1_Transform(IDENTITY, t1, t2, t3, t4);
+
+       S = (struct XYspace *) Permanent(t1_Transform(S, vals->pixel_matrix[0],
+                                                      -vals->pixel_matrix[1],
+                                                       vals->pixel_matrix[2],
+                                                      -vals->pixel_matrix[3]));
+
+
+       /* multiplier for computation of raw values */
+       sxmult = hypot(vals->pixel_matrix[0], vals->pixel_matrix[1]);
+       if (sxmult > EPS) sxmult = 1000.0 / sxmult;
+
+       p = entry->name.name + entry->name.length - 19;
+       if (entry->name.ndashes == 14 &&
+          p >= entry->name.name &&
+          !strcmp (p, "-adobe-fontspecific"))
+       {
+          fontencoding = FontP->fontInfoP[ENCODING].value.data.arrayP;
+       }
+
+       if (!fontencoding)
+          fontencoding = ISOLatin1EncArrayP;
+
+       pFont->info.firstCol = 255;
+       pFont->info.lastCol  = FIRSTCOL;
+
+       for (i=0; i < 256-FIRSTCOL; i++) {
+               long h,w;
+               long paddedW;
+              int j;
+              char *codename;
+
+              codename = fontencoding[i + FIRSTCOL].data.valueP;
+              len = fontencoding[i + FIRSTCOL].len;
+              if (len == 7 && strcmp(codename,".notdef")==0)
+                  continue;
+              /* See if this character is in the list of ranges specified
+                 in the XLFD name */
+              for (j = 0; j < vals->nranges; j++)
+                  if (i + FIRSTCOL >= minchar(vals->ranges[j]) &&
+                      i + FIRSTCOL <= maxchar(vals->ranges[j]))
+                      break;
+
+              /* If not, don't realize it. */
+              if (vals->nranges && j == vals->nranges)
+                  continue;
+
+              if (pFont->info.firstCol > i + FIRSTCOL)
+                  pFont->info.firstCol = i + FIRSTCOL;
+              if (pFont->info.lastCol < i + FIRSTCOL)
+                  pFont->info.lastCol = i + FIRSTCOL;
+
+               rc = 0;
+               area = fontfcnB(S, codename, &len, &rc);
+               if (rc < 0) {
+                       rc = Type1ReturnCodeToXReturnCode(rc);
+                       break;
+               }
+               else if (rc > 0)
+                       continue;
+               if (area == NULL)
+                       continue;
+               h       = area->ymax - area->ymin;
+               w       = area->xmax - area->xmin;
+               paddedW = PAD(w, pad);
+               if (h > 0 && w > 0) {
+                       size = h * paddedW / 8;
+                       glyphs[i].bits = (char *)xalloc(size);
+                       if (glyphs[i].bits == NULL) {
+                               rc = AllocError;
+                               break;
+                       }
+               }
+               else {
+                      size = 0;
+                       h = w = 0;
+                       area->xmin = area->xmax = 0;
+                       area->ymax = area->ymax = 0;
+               }
+               glyphs[i].metrics.leftSideBearing  = area->xmin;
+              x1 = (double)(x0 = area->ending.x - area->origin.x);
+              y1 = (double)(area->ending.y - area->origin.y);
+               glyphs[i].metrics.characterWidth   =
+                  (x0 + (x0 > 0 ? FPHALF : -FPHALF)) / (1 << FRACTBITS);
+               if (!glyphs[i].metrics.characterWidth && size == 0)
+              {
+                  /* Zero size and zero extents: presumably caused by
+                     the choice of transformation.  Let's create a
+                     small bitmap so we're not mistaken for an undefined
+                     character. */
+                  h = w = 1;
+                  size = paddedW = PAD(w, pad);
+                  glyphs[i].bits = (char *)xalloc(size);
+                   if (glyphs[i].bits == NULL) {
+                       rc = AllocError;
+                       break;
+                   }
+              }
+               glyphs[i].metrics.attributes =
+                  NEARESTPEL((long)(hypot(x1, y1) * sxmult));
+              total_width += glyphs[i].metrics.attributes;
+              total_raw_width += abs((int)(INT16)glyphs[i].metrics.attributes);
+              count++;
+               glyphs[i].metrics.rightSideBearing = w + area->xmin;
+               glyphs[i].metrics.descent          = area->ymax - NEARESTPEL(area->origin.y);
+               glyphs[i].metrics.ascent           = h - glyphs[i].metrics.descent;
+               bzero(glyphs[i].bits, size);
+               if (h > 0 && w > 0) {
+                   fill(glyphs[i].bits, h, paddedW, area, byte, bit, wordsize );
+               }
+               Destroy(area);
+       }
+       delmemory();
+       xfree(pool);
+       if (pFont->info.firstCol > pFont->info.lastCol)
+       {
+               xfree(type1);
+               xfree(pFont);
+               return BadFontName;
+       }
+       if (i != 256 - FIRSTCOL) {
+               for (i--; i >= 0; i--)
+                       if (glyphs[i].bits != NULL)
+                               xfree(glyphs[i].bits);
+               xfree(type1);
+               xfree(pFont);
+               return rc;
+       }
+       type1->pDefault    = NULL;
+       pFont->format      = format;
+       pFont->bit         = bit;
+       pFont->byte        = byte;
+       pFont->glyph       = glyph;
+       pFont->scan        = scan;
+       pFont->info.firstRow = 0;
+       pFont->info.lastRow  = 0;
+       pFont->get_metrics = Type1GetMetrics;
+       pFont->get_glyphs  = Type1GetGlyphs;
+       pFont->unload_font = Type1CloseFont;
+       pFont->unload_glyphs = NULL;
+       pFont->refcnt = 0;
+       pFont->maxPrivate = -1;
+       pFont->devPrivates = 0;
+       pFont->fontPrivate = (unsigned char *) type1;
+
+       if (count)
+       {
+          total_raw_width = (total_raw_width * 10 + count / 2) / count;
+          if (total_width < 0)
+          {
+              /* Predominant direction is R->L */
+              total_raw_width = -total_raw_width;
+          }
+          vals->width = (int)((double)total_raw_width *
+                              vals->pixel_matrix[0] / 1000.0 +
+                              (vals->pixel_matrix[0] > 0 ? .5 : -.5));
+       }
+
+       T1FillFontInfo(pFont, vals, fileName, entry->name.name, total_raw_width);
+       *ppFont = pFont;
+       return Successful;
+}
+static int
+Type1GetGlyphs(pFont, count, chars, charEncoding, glyphCount, glyphs)
+    FontPtr     pFont;
+    unsigned long count;
+    register unsigned char *chars;
+    FontEncoding charEncoding;
+    unsigned long *glyphCount;  /* RETURN */
+    CharInfoPtr *glyphs;        /* RETURN */
+{
+    unsigned int firstRow;
+    unsigned int numRows;
+    CharInfoPtr *glyphsBase;
+    register unsigned int c;
+    register CharInfoPtr pci;
+    unsigned int r;
+    CharInfoPtr pDefault;
+    register struct type1font *type1Font;
+    register int firstCol;
+    type1Font  = (struct type1font *) pFont->fontPrivate;
+    firstCol   = pFont->info.firstCol;
+    pDefault   = type1Font->pDefault;
+    glyphsBase = glyphs;
+    switch (charEncoding) {
+
+#define EXIST(pci) \
+    ((pci)->metrics.attributes || \
+     (pci)->metrics.ascent != -(pci)->metrics.descent || \
+     (pci)->metrics.leftSideBearing != (pci)->metrics.rightSideBearing)
+    case Linear8Bit:
+    case TwoD8Bit:
+        if (pFont->info.firstRow > 0)
+            break;
+        while (count--) {
+                c = (*chars++);
+                if (c >= firstCol &&
+                       (pci = &type1Font->glyphs[c-FIRSTCOL]) &&
+                      EXIST(pci))
+                    *glyphs++ = pci;
+                else if (pDefault)
+                    *glyphs++ = pDefault;
+        }
+        break;
+    case Linear16Bit:
+        while (count--) {
+                c = *chars++ << 8;
+                c = (c | *chars++);
+                if (c < 256 && c >= firstCol &&
+                        (pci = &type1Font->glyphs[c-FIRSTCOL]) &&
+                       EXIST(pci))
+                    *glyphs++ = pci;
+                else if (pDefault)
+                    *glyphs++ = pDefault;
+        }
+        break;
+    case TwoD16Bit:
+        firstRow = pFont->info.firstRow;
+        numRows = pFont->info.lastRow - firstRow + 1;
+        while (count--) {
+            r = (*chars++) - firstRow;
+            c = (*chars++);
+            if (r < numRows && c < 256 && c >= firstCol &&
+                    (pci = &type1Font->glyphs[(r << 8) + c - FIRSTCOL]) &&
+                   EXIST(pci))
+                *glyphs++ = pci;
+            else if (pDefault)
+                *glyphs++ = pDefault;
+        }
+        break;
+    }
+    *glyphCount = glyphs - glyphsBase;
+    return Successful;
+
+#undef EXIST
+}
+static int
+Type1GetMetrics(pFont, count, chars, charEncoding, glyphCount, glyphs)
+    FontPtr     pFont;
+    unsigned long count;
+    register unsigned char *chars;
+    FontEncoding charEncoding;
+    unsigned long *glyphCount;  /* RETURN */
+    xCharInfo **glyphs;         /* RETURN */
+{
+    static CharInfoRec nonExistantChar;
+    int         ret;
+    struct type1font *type1Font;
+    CharInfoPtr oldDefault;
+    type1Font = (struct type1font *) pFont->fontPrivate;
+    oldDefault = type1Font->pDefault;
+    type1Font->pDefault = &nonExistantChar;
+    ret = Type1GetGlyphs(pFont, count, chars, charEncoding, glyphCount, (CharInfoPtr *) glyphs);
+    type1Font->pDefault = oldDefault;
+    return ret;
+}
+void Type1CloseFont(pFont)
+       FontPtr pFont;
+{
+       register int i;
+       struct type1font *type1;
+       type1 = (struct type1font *) pFont->fontPrivate;
+       for (i=0; i < 256 - FIRSTCOL; i++)
+               if (type1->glyphs[i].bits != NULL)
+                        xfree(type1->glyphs[i].bits);
+       xfree(type1);
+
+       if (pFont->info.props)
+          xfree(pFont->info.props);
+
+       if (pFont->info.isStringProp)
+          xfree(pFont->info.isStringProp);
+
+       if (pFont->devPrivates)
+          xfree(pFont->devPrivates);
+
+       xfree(pFont);
+}
+static void fill(dest, h, w, area, byte, bit, wordsize)
+       register char *dest;  /* destination bitmap                           */
+       int h,w;              /* dimensions of 'dest', w padded               */
+       register struct region *area;  /* region to write to 'dest'           */
+       int byte,bit;         /* flags; LSBFirst or MSBFirst                  */
+       int wordsize;         /* number of bits per word for LSB/MSB purposes */
+{
+       register struct edgelist *edge;  /* for looping through edges         */
+       register char *p;     /* current scan line in 'dest'                  */
+       register int y;       /* for looping through scans                    */
+       register int wbytes = w / 8;  /* number of bytes in width             */
+       register pel *leftP,*rightP;  /* pointers to X values, left and right */
+       int xmin = area->xmin;  /* upper left X                               */
+       int ymin = area->ymin;  /* upper left Y                               */
+       for (edge = area->anchor; VALIDEDGE(edge); edge = edge->link->link) {
+               p = dest + (edge->ymin - ymin) * wbytes;
+               leftP = edge->xvalues;
+               rightP = edge->link->xvalues;
+               for (y = edge->ymin; y < edge->ymax; y++) {
+                       fillrun(p, *leftP++ - xmin, *rightP++ - xmin, bit);
+                       p += wbytes;
+               }
+       }
+/*
+Now, as an afterthought, we'll go reorganize if odd byte order requires
+it:
+*/
+       if (byte == LSBFirst && wordsize != 8) {
+               register int i;
+               switch (wordsize) {
+                   case 16:
+                   {
+                       register unsigned short data,*p;
+                       p = (unsigned short *) dest;
+                       for (i = h * w /16; --i >= 0;) {
+                               data = *p;
+                               *p++ = (data << 8) + (data >> 8);
+                       }
+                       break;
+                   }
+                   case 64:
+                   case 32:
+                   {
+                       register unsigned long data,*p;
+                       p = (unsigned long *) dest;
+                       for (i = h * w / 32; --i >= 0;) {
+                               data = *p;
+                               *p++ = (data << 24) + (data >> 24)
+                                      + (0xFF00 & (data >> 8))
+                                      + (0xFF0000 & (data << 8));
+                       }
+                       if (wordsize == 64) {
+                               p = (unsigned long *) dest;
+                               for (i = h * w / 64; --i >= 0;) {
+                                       data = *p++;
+                                       p[-1] = p[0];
+                                       *p++ = data;
+                               }
+                       }
+                       break;
+                   }
+                   default:
+                       abort("xiFill: unknown format");
+               }
+       }
+}
+#define  ALLONES  0xFF
+static void fillrun(p, x0, x1, bit)
+       register char *p;     /* address of this scan line                    */
+       pel x0,x1;            /* left and right X                             */
+       int bit;              /* format:  LSBFirst or MSBFirst                */
+{
+       register int startmask,endmask;  /* bits to set in first and last char*/
+       register int middle;  /* number of chars between start and end + 1    */
+       if (x1 <= x0)
+               return;
+       middle = x1/8 - x0/8;
+       p += x0/8;
+       x0 &= 7;  x1 &= 7;
+       if (bit == LSBFirst) {
+               startmask = ALLONES << x0;
+               endmask = ~(ALLONES << x1);
+       }
+       else {
+               startmask = ALLONES >> x0;
+               endmask = ~(ALLONES >> x1);
+       }
+       if (middle == 0)
+               *p++ |= startmask & endmask;
+       else {
+               *p++ |= startmask;
+               while (--middle > 0)
+                       *p++ = (char)ALLONES;
+               *p |= endmask;
+       }
+}
+#define CAPABILITIES (CAP_MATRIX | CAP_CHARSUBSETTING)
+static FontRendererRec renderers[] = {
+  { ".pfa", 4, (int (*)()) 0, Type1OpenScalable,
+        (int (*)()) 0, Type1GetInfoScalable, 0, CAPABILITIES },
+  { ".pfb", 4, (int (*)()) 0, Type1OpenScalable,
+        (int (*)()) 0, Type1GetInfoScalable, 0, CAPABILITIES }
+};
+
+Type1RegisterFontFileFunctions()
+{
+    int i;
+    T1InitStdProps();
+    for (i=0; i < sizeof(renderers) / sizeof(FontRendererRec); i++)
+            FontFileRegisterRenderer(&renderers[i]);
+}
+
+int Type1ReturnCodeToXReturnCode(rc)
+    int rc;
+{
+    switch(rc) {
+    case SCAN_OK:
+       return Successful;
+    case SCAN_FILE_EOF:
+       /* fall through to BadFontFormat */
+    case SCAN_ERROR:
+       return BadFontFormat;
+    case SCAN_OUT_OF_MEMORY:
+       return AllocError;
+    case SCAN_FILE_OPEN_ERROR:
+       return BadFontName;
+    case SCAN_TRUE:
+    case SCAN_FALSE:
+    case SCAN_END:
+       /* fall through */
+    default:
+       /* this should not happen */
+       ErrorF("Type1 return code not convertable to X return code: %d\n", rc);
+       return rc;
+    }
+}
diff --git a/Xserver/lib/font/Type1/t1hdigit.h b/Xserver/lib/font/Type1/t1hdigit.h
new file mode 100644 (file)
index 0000000..9979ef5
--- /dev/null
@@ -0,0 +1,40 @@
+/* $XConsortium: t1hdigit.h,v 1.2 91/10/10 11:19:31 rws Exp $ */
+/* Copyright International Business Machines,Corp. 1991
+ * All Rights Reserved
+ *
+ * License to use, copy, modify, and distribute this software
+ * and its documentation for any purpose and without fee is
+ * hereby granted, provided that the above copyright notice
+ * appear in all copies and that both that copyright notice and
+ * this permission notice appear in supporting documentation,
+ * and that the name of IBM not be used in advertising or
+ * publicity pertaining to distribution of the software without
+ * specific, written prior permission.
+ *
+ * IBM PROVIDES THIS SOFTWARE "AS IS", WITHOUT ANY WARRANTIES
+ * OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING, BUT NOT
+ * LIMITED TO ANY IMPLIED WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, AND NONINFRINGEMENT OF
+ * THIRD PARTY RIGHTS.  THE ENTIRE RISK AS TO THE QUALITY AND
+ * PERFORMANCE OF THE SOFTWARE, INCLUDING ANY DUTY TO SUPPORT
+ * OR MAINTAIN, BELONGS TO THE LICENSEE.  SHOULD ANY PORTION OF
+ * THE SOFTWARE PROVE DEFECTIVE, THE LICENSEE (NOT IBM) ASSUMES
+ * THE ENTIRE COST OF ALL SERVICING, REPAIR AND CORRECTION.  IN
+ * NO EVENT SHALL IBM BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
+ * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
+ * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
+ * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+ */
+/* Indicators for special characters in the p_hdigit.h tables */
+#define HERROR       (0xfe)
+#define HWHITE_SPACE (0xfd)
+#define HRIGHT_ANGLE (0xfc)
+#define LAST_HDIGIT  (0xf0)
+/* Declarations for the tables */
+#define HighHexP (HighHex+1)
+extern unsigned char HighHex[];
+#define LowHexP (LowHex+1)
+extern unsigned char LowHex[];
diff --git a/Xserver/lib/font/Type1/t1imager.h b/Xserver/lib/font/Type1/t1imager.h
new file mode 100644 (file)
index 0000000..b4cdc9a
--- /dev/null
@@ -0,0 +1,148 @@
+/* $XConsortium: t1imager.h,v 1.5 92/03/20 14:36:05 keith Exp $ */
+/* Copyright International Business Machines,Corp. 1991
+ * All Rights Reserved
+ *
+ * License to use, copy, modify, and distribute this software
+ * and its documentation for any purpose and without fee is
+ * hereby granted, provided that the above copyright notice
+ * appear in all copies and that both that copyright notice and
+ * this permission notice appear in supporting documentation,
+ * and that the name of IBM not be used in advertising or
+ * publicity pertaining to distribution of the software without
+ * specific, written prior permission.
+ *
+ * IBM PROVIDES THIS SOFTWARE "AS IS", WITHOUT ANY WARRANTIES
+ * OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING, BUT NOT
+ * LIMITED TO ANY IMPLIED WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, AND NONINFRINGEMENT OF
+ * THIRD PARTY RIGHTS.  THE ENTIRE RISK AS TO THE QUALITY AND
+ * PERFORMANCE OF THE SOFTWARE, INCLUDING ANY DUTY TO SUPPORT
+ * OR MAINTAIN, BELONGS TO THE LICENSEE.  SHOULD ANY PORTION OF
+ * THE SOFTWARE PROVE DEFECTIVE, THE LICENSEE (NOT IBM) ASSUMES
+ * THE ENTIRE COST OF ALL SERVICING, REPAIR AND CORRECTION.  IN
+ * NO EVENT SHALL IBM BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
+ * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
+ * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
+ * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+ */
+
+#include "fontmisc.h"
+typedef  pointer xobject;
+typedef  pointer location;
+typedef  pointer path;
+typedef  pointer region;
+typedef  pointer XYspace;
+#ifndef NOEXTERNS
+/*
+The following are the user entry locations to TYPE1IMAGER
+*/
+extern path    t1_Bezier();
+extern path    t1_ClosePath();
+extern xobject t1_Destroy();
+extern xobject t1_Dup();
+extern char   *t1_ErrorMsg();
+extern void    t1_InitImager();
+extern region  t1_Interior();
+extern location  t1_ILoc();
+extern xobject t1_Join();
+extern path    t1_Line();
+extern xobject t1_Permanent();
+extern path    t1_Phantom();
+extern location   t1_Loc();
+extern xobject t1_Scale();
+extern xobject t1_Snap();
+extern location  t1_SubLoc();
+extern xobject t1_Temporary();
+#endif
+#ifndef   NULL
+#define   NULL         0
+#endif
+#ifndef   TRUE
+#define   TRUE          1
+#endif
+#ifndef   FALSE
+#define   FALSE         0
+#endif
+/*
+Here are some TYPE1IMAGER functions that are defined in terms of others:
+*/
+#define   t1_AddLoc(p1,p2)    t1_Join(p1,p2)
+#ifndef   NONAMES
+/*
+Define the simple form of all the subroutine names:
+*/
+#define   AddLoc(p1,p2)          t1_AddLoc(p1,p2)
+#define   Bezier(B,C,D)      t1_Bezier(B,C,D)
+#define   ClosePath(p)       t1_ClosePath(p,0)
+#define   Complement(area)   t1_Complement(area)
+#define   Destroy(o)         t1_Destroy(o)
+#define   Dup(o)             t1_Dup(o)
+#define   ErrorMsg()         t1_ErrorMsg()
+#define   HeadSegment(p)     t1_HeadSegment(p)
+#define   InitImager()       t1_InitImager()
+#define   Interior(p,rule)   t1_Interior(p,rule)
+#define   ILoc(S,x,y)        t1_ILoc(S,x,y)
+#define   Join(p1,p2)        t1_Join(p1,p2)
+#define   Line(P)            t1_Line(P)
+#define   Permanent(o)       t1_Permanent(o)
+#define   Phantom(o)         t1_Phantom(o)
+#define   Loc(S,x,y)         t1_Loc(S,(double)x,(double)y)
+#define   Scale(o,sx,sy)     t1_Scale(o,(double)sx,(double)sy)
+#define   Snap(o)            t1_Snap(o)
+#define   SubLoc(a,b)        t1_SubLoc(a,b)
+#define   Temporary(o)       t1_Temporary(o)
+#define   TermImager()       t1_TermImager()
+#define   Transform(o,cxx,cyx,cxy,cyy)  t1_Transform(o,(double)cxx,(double)cyx,\
+    (double)cxy,(double)cyy)
+#endif
+#define   WINDINGRULE -2
+#define   EVENODDRULE -3
+#define   CONTINUITY  0x80   /* can be added to above rules; e.g. WINDINGRULE+CONTINUITY */
+/*
+Stroke() line style constants:
+*/
+/*
+Coordinate space constants:
+*/
+#define   IDENTITY      t1_Identity
+extern XYspace *IDENTITY;
+/*
+Generic null object definition:
+*/
+#define    NULLOBJECT   ((xobject)NULL)
+/*
+Null path definition:
+*/
+#define    NULLPATH     NULLOBJECT
+/*
+Full page and null region definition:
+*/
+#define    INFINITY     t1_Infinity
+#ifndef NOEXTERNS
+extern     region       *INFINITY;
+#endif
+#define    NULLREGION   NULLOBJECT
+#define    FF_PARSE_ERROR  5
+#define    FF_PATH         1
+extern pointer xiStub();
diff --git a/Xserver/lib/font/Type1/t1info.c b/Xserver/lib/font/Type1/t1info.c
new file mode 100644 (file)
index 0000000..0d49b67
--- /dev/null
@@ -0,0 +1,490 @@
+/* $TOG: t1info.c /main/20 1997/06/09 11:21:53 barstow $ */
+/* Copyright International Business Machines,Corp. 1991
+ * All Rights Reserved
+ *
+ * License, subject to the license given below, to use,
+ * copy, modify, and distribute this software * and its
+ * documentation for any purpose and without fee is hereby
+ * granted, provided that the above copyright notice appear
+ * in all copies and that both that copyright notice and
+ * this permission notice appear in supporting documentation,
+ * and that the name of IBM not be used in advertising or
+ * publicity pertaining to distribution of the software
+ * without specific, written prior permission.
+ *
+ * IBM PROVIDES THIS SOFTWARE "AS IS", WITHOUT ANY WARRANTIES
+ * OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING, BUT NOT
+ * LIMITED TO ANY IMPLIED WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, AND NONINFRINGEMENT OF
+ * THIRD PARTY RIGHTS.  THE ENTIRE RISK AS TO THE QUALITY AND
+ * PERFORMANCE OF THE SOFTWARE, INCLUDING ANY DUTY TO SUPPORT
+ * OR MAINTAIN, BELONGS TO THE LICENSEE.  SHOULD ANY PORTION OF
+ * THE SOFTWARE PROVE DEFECTIVE, THE LICENSEE (NOT IBM) ASSUMES
+ * THE ENTIRE COST OF ALL SERVICING, REPAIR AND CORRECTION.  IN
+ * NO EVENT SHALL IBM BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
+ * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
+ * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
+ * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+ *
+ * Author: Carol H. Thompson  IBM Almaden Research Center
+ *   Modeled on spinfo.c by Dave Lemke, Network Computing Devices, Inc
+ *   which contains the following copyright and permission notices:
+ *
+ * Copyright 1990, 1991 Network Computing Devices;
+ * Portions Copyright 1987 by Digital Equipment Corporation
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the names of Network Computing Devices or Digital 
+ * not be used in advertising or publicity pertaining to distribution of the 
+ * software without specific, written prior permission. Network Computing 
+ * Devices and Digital make no representations about the suitability of this 
+ * software for any purpose.  It is provided "as is" without express or 
+ * implied warranty.
+ *
+ * NETWORK COMPUTING DEVICES AND DIGITAL DISCLAIM ALL WARRANTIES WITH
+ * REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS, IN NO EVENT SHALL NETWORK COMPUTING DEVICES OR DIGITAL BE
+ * LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
+ * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
+ * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+/*
+
+Copyright (c) 1987  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be included
+in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR
+OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall
+not be used in advertising or otherwise to promote the sale, use or
+other dealings in this Software without prior written authorization
+from the X Consortium.
+
+*/
+
+#include <stdio.h> 
+#include "fntfilst.h"
+#include "FSproto.h"
+#include "t1intf.h"
+#include <math.h>
+#define DECIPOINTSPERINCH 722.7
+#define DEFAULTRES 75
+#define DEFAULTPOINTSIZE 120
+enum scaleType {
+    atom, truncate_atom, pixel_size, point_size, resolution_x,
+    resolution_y, average_width
+};
+typedef struct _fontProp {
+    char       *name;
+    long        atom;
+    enum scaleType type;
+}           fontProp;
+static fontProp fontNamePropTable[] = {  /* Example: */
+    "FOUNDRY", 0, atom,                  /* adobe */
+    "FAMILY_NAME", 0, atom,              /* times roman */
+    "WEIGHT_NAME", 0, atom,             /* bold */
+    "SLANT", 0, atom,                   /* i */
+    "SETWIDTH_NAME", 0, atom,            /* normal */
+    "ADD_STYLE_NAME", 0, atom,          /* */
+    "PIXEL_SIZE", 0, pixel_size,         /* 18 */
+    "POINT_SIZE", 0, point_size,         /* 180 */
+    "RESOLUTION_X", 0, resolution_x,     /* 72 */
+    "RESOLUTION_Y", 0, resolution_y,     /* 72 */
+    "SPACING", 0, atom,                  /* p */
+    "AVERAGE_WIDTH", 0, average_width,   /* 0 */
+    "CHARSET_REGISTRY", 0, atom,         /* ISO8859 */
+    "CHARSET_ENCODING", 0, truncate_atom, /* 1 */
+};
+/* NOTICE: Following array is closely related to the sequence of defines
+   following it. */
+static fontProp extraProps[] = {
+    "FONT", 0, 0,
+    "COPYRIGHT", 0, 0,
+    "RAW_PIXEL_SIZE", 0, 0,
+    "RAW_POINT_SIZE", 0, 0,
+    "RAW_ASCENT", 0, 0,
+    "RAW_DESCENT", 0, 0,
+    "RAW_AVERAGE_WIDTH", 0, 0,
+    "FACE_NAME", 0, 0,
+};
+/* this is a bit kludgy */
+#define FONTPROP        0
+#define COPYRIGHTPROP   1
+#define RAWPIXELPROP   2
+#define RAWPOINTPROP   3
+#define RAWASCENTPROP  4
+#define RAWDESCENTPROP 5
+#define RAWWIDTHPROP   6
+#define FACE_NAMEPROP  7
+
+#define NNAMEPROPS (sizeof(fontNamePropTable) / sizeof(fontProp))
+#define NEXTRAPROPS (sizeof(extraProps) / sizeof(fontProp))
+#define NPROPS  (NNAMEPROPS + NEXTRAPROPS)
+/*ARGSUSED*/
+static void
+FillHeader(pInfo, Vals)
+    FontInfoPtr         pInfo;
+    FontScalablePtr     Vals;
+{
+    /* OpenScalable in T1FUNCS sets the following:
+    pInfo->firstCol,
+    pInfo->firstRow,
+    pInfo->lastCol, and
+    pInfo->lastRow. */
+    /* the following are ununsed
+    pInfo->pad. */
+    /* Items we should handle better someday +++ */
+    pInfo->defaultCh = 0;
+    pInfo->drawDirection = LeftToRight;
+    if (Vals->point_matrix[0] == Vals->point_matrix[3])
+       pInfo->anamorphic = 0;
+    else
+       pInfo->anamorphic = 1;
+    pInfo->inkMetrics = 0;  /* no ink metrics here */
+    pInfo->cachable = 1;    /* no licensing (yet) */
+}
+static void
+adjust_min_max(minc, maxc, tmp)
+    xCharInfo  *minc,
+               *maxc,
+               *tmp;
+{
+#define MINMAX(field,ci) \
+        if (minc->field > (ci)->field) \
+             minc->field = (ci)->field; \
+        if (maxc->field < (ci)->field) \
+            maxc->field = (ci)->field;
+    MINMAX(ascent, tmp);
+    MINMAX(descent, tmp);
+    MINMAX(leftSideBearing, tmp);
+    MINMAX(rightSideBearing, tmp);
+    MINMAX(characterWidth, tmp);
+
+    /* Do MINMAX for attributes field.  Since that field is CARD16,
+       we'll cast to a signed integer */
+    if ((INT16)minc->attributes > (INT16)tmp->attributes)
+         minc->attributes = tmp->attributes;
+    if ((INT16)maxc->attributes < (INT16)tmp->attributes)
+        maxc->attributes = tmp->attributes;
+#undef  MINMAX
+}
+static void
+ComputeBounds(pInfo, pChars, Vals)
+    FontInfoPtr         pInfo;
+    CharInfoPtr         pChars;
+    FontScalablePtr     Vals;
+{
+    int i;
+    xCharInfo minchar, maxchar;
+    int numchars = 0;
+    int totchars;
+    int overlap;
+    int maxlap;
+    minchar.ascent = minchar.descent =
+        minchar.leftSideBearing = minchar.rightSideBearing =
+        minchar.characterWidth = minchar.attributes = 32767;
+    maxchar.ascent = maxchar.descent =
+        maxchar.leftSideBearing = maxchar.rightSideBearing =
+        maxchar.characterWidth = maxchar.attributes = -32767;
+    maxlap = -32767;
+    totchars = pInfo->lastCol - pInfo->firstCol + 1;
+    pChars += pInfo->firstCol - FIRSTCOL;
+    pInfo->allExist = 1;
+    for (i = 0; i < totchars; i++,pChars++) {
+        xCharInfo *pmetrics = &pChars->metrics;
+        if (pmetrics->attributes ||
+           pmetrics->ascent != -pmetrics->descent ||
+           pmetrics->leftSideBearing != pmetrics->rightSideBearing) {
+            numchars++;
+            adjust_min_max(&minchar, &maxchar, pmetrics);
+            overlap = pmetrics->rightSideBearing - pmetrics->characterWidth;
+            if (overlap > maxlap) maxlap = overlap;
+        }
+        else pInfo->allExist = 0;
+    }
+
+    /* If we're monospaced, round the average width field to the
+       nearest pixel */
+    if (minchar.characterWidth == maxchar.characterWidth)
+       Vals->width = minchar.characterWidth * 10;
+    pInfo->maxbounds = maxchar;
+    pInfo->minbounds = minchar;
+    pInfo->ink_maxbounds = maxchar;
+    pInfo->ink_minbounds = minchar;
+    pInfo->maxOverlap = maxlap + -(minchar.leftSideBearing);
+    /* Set the pInfo flags */
+    /* Properties set by FontComputeInfoAccelerators:
+        pInfo->noOverlap;
+        pInfo->terminalFont;
+        pInfo->constantMetrics;
+        pInfo->constantWidth;
+        pInfo->inkInside;
+    */
+    FontComputeInfoAccelerators (pInfo);
+}
+static void
+ComputeProps(pInfo, Vals, Filename, sAscent, sDescent)
+    FontInfoPtr         pInfo;
+    FontScalablePtr     Vals;
+    char                *Filename;
+    long               *sAscent;
+    long               *sDescent;
+{
+    int infoint;
+    int infoBBox[4];
+    int rc;
+    QueryFontLib(Filename, "isFixedPitch", &infoint, &rc);
+    if (!rc) {
+        pInfo->constantWidth = infoint;
+    }
+    QueryFontLib((char *)0, "FontBBox", infoBBox, &rc);
+    if (!rc) {
+       pInfo->fontAscent =
+           (int)((double)infoBBox[3] * Vals->pixel_matrix[3] +
+                 (infoBBox[3] > 0 ? 500 : -500)) / 1000;
+       pInfo->fontDescent =
+           -(int)((double)infoBBox[1] * Vals->pixel_matrix[3] +
+                  (infoBBox[1] > 0 ? 500 : -500)) / 1000;
+       *sAscent = infoBBox[3];
+       *sDescent = -infoBBox[1];
+    }
+}
+static void
+ComputeStdProps(pInfo, Vals, Filename, Fontname, sAscent, sDescent, sWidth)
+    FontInfoPtr         pInfo;
+    FontScalablePtr     Vals;
+    char                *Filename;
+    char                *Fontname;
+    long               sAscent;
+    long               sDescent;
+    long               sWidth;
+{
+    FontPropPtr pp;
+    int         i,
+                nprops;
+    fontProp   *fpt;
+    char       *is_str;
+    char       *ptr1,
+               *ptr2;
+    char       *ptr3;
+    char *infostrP;
+    long rc;
+    char      scaledName[MAXFONTNAMELEN];
+    strcpy (scaledName, Fontname);
+    /* Fill in our copy of the fontname from the Vals structure */
+    FontParseXLFDName (scaledName, Vals, FONT_XLFD_REPLACE_VALUE);
+    /* This form of the properties is used by the X-client; the X-server
+       doesn't care what they are. */
+    nprops = pInfo->nprops = NPROPS;
+    pInfo->isStringProp = (char *) xalloc(sizeof(char) * nprops);
+    pInfo->props = (FontPropPtr) xalloc(sizeof(FontPropRec) * nprops);
+    if (!pInfo->isStringProp || !pInfo->props) {
+        xfree(pInfo->isStringProp);
+        pInfo->isStringProp = (char *) 0;
+        xfree(pInfo->props);
+        pInfo->props = (FontPropPtr) 0;
+        return;
+    }
+    bzero(pInfo->isStringProp, (sizeof(char) * nprops));
+    ptr2 = scaledName;
+    for (i = NNAMEPROPS, pp = pInfo->props, fpt = fontNamePropTable, is_str = pInfo->isStringProp;
+            i;
+            i--, pp++, fpt++, is_str++) {
+
+       if (*ptr2)
+       {
+           ptr1 = ptr2 + 1;
+           if (!(ptr2 = strchr(ptr1, '-'))) ptr2 = strchr(ptr1, '\0');
+       }
+
+        pp->name = fpt->atom;
+        switch (fpt->type) {
+         case atom:  /* Just copy info from scaledName */
+            *is_str = TRUE;
+            pp->value = MakeAtom(ptr1, ptr2 - ptr1, TRUE);
+            break;
+       case truncate_atom:
+            *is_str = TRUE;
+           for (ptr3 = ptr1; *ptr3; ptr3++)
+               if (*ptr3 == '[')
+                   break;
+           pp->value = MakeAtom(ptr1, ptr3 - ptr1, TRUE);
+           break;
+         case pixel_size:
+            pp->value = (int)(fabs(Vals->pixel_matrix[3]) + .5);
+            break;
+         case point_size:
+            pp->value = (int)(fabs(Vals->point_matrix[3]) * 10.0 + .5);
+            break;
+         case resolution_x:
+            pp->value = Vals->x;
+            break;
+         case resolution_y:
+            pp->value = Vals->y;
+            break;
+         case average_width:
+            pp->value = Vals->width;
+            break;
+        }
+    }
+    for (i = 0, fpt = extraProps;
+          i < NEXTRAPROPS;
+          i++, is_str++, pp++, fpt++) {
+        pp->name = fpt->atom;
+        switch (i) {
+         case FONTPROP:
+            *is_str = TRUE;
+            pp->value = MakeAtom(scaledName, strlen(scaledName), TRUE);
+            break;
+         case COPYRIGHTPROP:
+            *is_str = TRUE;
+            QueryFontLib(Filename, "Notice", &infostrP, &rc);
+            if (rc || !infostrP) {
+                infostrP = "Copyright Notice not available";
+            }
+            pp->value = MakeAtom(infostrP, strlen(infostrP), TRUE);
+            break;
+         case FACE_NAMEPROP:
+            *is_str = TRUE;
+            QueryFontLib(Filename, "FontName", &infostrP, &rc);
+            if (rc || !infostrP) {
+                infostrP = "(unknown)"; 
+            }
+            pp->value = MakeAtom(infostrP, strlen(infostrP), TRUE);
+            break;
+         case RAWPIXELPROP:
+            *is_str = FALSE;
+            pp->value = 1000;
+           break;
+         case RAWPOINTPROP:
+            *is_str = FALSE;
+            pp->value = (long)(72270.0 / (double)Vals->y + .5);
+           break;
+         case RAWASCENTPROP:
+            *is_str = FALSE;
+            pp->value = sAscent;
+           break;
+         case RAWDESCENTPROP:
+            *is_str = FALSE;
+            pp->value = sDescent;
+           break;
+         case RAWWIDTHPROP:
+            *is_str = FALSE;
+            pp->value = sWidth;
+           break;
+        }
+    }
+}
+/*ARGSUSED*/
+int
+Type1GetInfoScalable(fpe, pInfo, entry, fontName, fileName, Vals)
+    FontPathElementPtr  fpe;
+    FontInfoPtr         pInfo;
+    FontEntryPtr        entry;
+    FontNamePtr         fontName;
+    char                *fileName;
+    FontScalablePtr     Vals;
+{
+    FontPtr pfont;
+    int flags = 0;
+    long format = 0;  /* It doesn't matter what format for just info */
+    long fmask = 0;
+    int ret;
+    ret = Type1OpenScalable(fpe, &pfont, flags, entry, fileName, Vals, format, fmask);
+    if (ret != Successful)
+       return ret;
+    *pInfo = pfont->info;
+
+    /* XXX - Set pointers in pfont->info to NULL so they are not freed. */
+    pfont->info.props = NULL;
+    pfont->info.isStringProp = NULL;
+
+    Type1CloseFont(pfont);
+    return Successful;
+}
+void
+T1FillFontInfo(pFont, Vals, Filename, Fontname, sWidth)
+    FontPtr             pFont;
+    FontScalablePtr     Vals;
+    char                *Filename;
+    char                *Fontname;
+    long               sWidth;
+{
+    FontInfoPtr         pInfo = &pFont->info;
+    struct type1font *p = (struct type1font *)pFont->fontPrivate;
+    long sAscent, sDescent;    /* Scalable 1000-pixel values */
+    FillHeader(pInfo, Vals);
+    ComputeBounds(pInfo, p->glyphs, Vals);
+    ComputeProps(pInfo, Vals, Filename, &sAscent, &sDescent);
+    ComputeStdProps(pInfo, Vals, Filename, Fontname, sAscent, sDescent, sWidth);
+}
+/* Called once, at renderer registration time */
+void
+T1InitStdProps()
+{
+    int         i;
+    fontProp   *t;
+    i = sizeof(fontNamePropTable) / sizeof(fontProp);
+    for (t = fontNamePropTable; i; i--, t++)
+        t->atom = MakeAtom(t->name, (unsigned) strlen(t->name), TRUE);
+    i = sizeof(extraProps) / sizeof(fontProp);
+    for (t = extraProps; i; i--, t++)
+        t->atom = MakeAtom(t->name, (unsigned) strlen(t->name), TRUE);
+}
diff --git a/Xserver/lib/font/Type1/t1intf.h b/Xserver/lib/font/Type1/t1intf.h
new file mode 100644 (file)
index 0000000..bb2d258
--- /dev/null
@@ -0,0 +1,36 @@
+/* $XConsortium: t1intf.h,v 1.2 91/10/10 11:19:39 rws Exp $ */
+/* Copyright International Business Machines,Corp. 1991
+ * All Rights Reserved
+ *
+ * License to use, copy, modify, and distribute this software
+ * and its documentation for any purpose and without fee is
+ * hereby granted, provided that the above copyright notice
+ * appear in all copies and that both that copyright notice and
+ * this permission notice appear in supporting documentation,
+ * and that the name of IBM not be used in advertising or
+ * publicity pertaining to distribution of the software without
+ * specific, written prior permission.
+ *
+ * IBM PROVIDES THIS SOFTWARE "AS IS", WITHOUT ANY WARRANTIES
+ * OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING, BUT NOT
+ * LIMITED TO ANY IMPLIED WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, AND NONINFRINGEMENT OF
+ * THIRD PARTY RIGHTS.  THE ENTIRE RISK AS TO THE QUALITY AND
+ * PERFORMANCE OF THE SOFTWARE, INCLUDING ANY DUTY TO SUPPORT
+ * OR MAINTAIN, BELONGS TO THE LICENSEE.  SHOULD ANY PORTION OF
+ * THE SOFTWARE PROVE DEFECTIVE, THE LICENSEE (NOT IBM) ASSUMES
+ * THE ENTIRE COST OF ALL SERVICING, REPAIR AND CORRECTION.  IN
+ * NO EVENT SHALL IBM BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
+ * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
+ * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
+ * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+ */
+#define FIRSTCOL  32
+struct type1font {
+       CharInfoPtr  pDefault;
+       CharInfoRec  glyphs[256-FIRSTCOL];
+};
diff --git a/Xserver/lib/font/Type1/t1io.c b/Xserver/lib/font/Type1/t1io.c
new file mode 100644 (file)
index 0000000..0b649e5
--- /dev/null
@@ -0,0 +1,294 @@
+/* $XConsortium: t1io.c,v 1.10 95/06/09 22:29:35 gildea Exp $ */
+/* Copyright International Business Machines,Corp. 1991
+ * All Rights Reserved
+ *
+ * License to use, copy, modify, and distribute this software
+ * and its documentation for any purpose and without fee is
+ * hereby granted, provided that the above copyright notice
+ * appear in all copies and that both that copyright notice and
+ * this permission notice appear in supporting documentation,
+ * and that the name of IBM not be used in advertising or
+ * publicity pertaining to distribution of the software without
+ * specific, written prior permission.
+ *
+ * IBM PROVIDES THIS SOFTWARE "AS IS", WITHOUT ANY WARRANTIES
+ * OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING, BUT NOT
+ * LIMITED TO ANY IMPLIED WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, AND NONINFRINGEMENT OF
+ * THIRD PARTY RIGHTS.  THE ENTIRE RISK AS TO THE QUALITY AND
+ * PERFORMANCE OF THE SOFTWARE, INCLUDING ANY DUTY TO SUPPORT
+ * OR MAINTAIN, BELONGS TO THE LICENSEE.  SHOULD ANY PORTION OF
+ * THE SOFTWARE PROVE DEFECTIVE, THE LICENSEE (NOT IBM) ASSUMES
+ * THE ENTIRE COST OF ALL SERVICING, REPAIR AND CORRECTION.  IN
+ * NO EVENT SHALL IBM BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
+ * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
+ * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
+ * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+ * Author: Carol H. Thompson  IBM Almaden Research Center
+ */
+/*******************************************************************
+*  I/O package for Type 1 font reading
+********************************************************************/
+#ifndef STATIC
+#define STATIC static
+#endif
+#include <fcntl.h>
+#include "t1stdio.h"
+#include "t1hdigit.h"
+#ifdef WIN32
+#include <X11/Xw32defs.h>
+#endif
+/* Constants and variables used in the decryption */
+#define c1 ((unsigned short)52845)
+#define c2 ((unsigned short)22719)
+static unsigned short r;
+static int asc, Decrypt;
+static int extrach;
+static int haveextrach;
+/* Our single FILE structure and buffer for this package */
+STATIC F_FILE TheFile;
+STATIC unsigned char TheBuffer[F_BUFSIZ];
+/* Our routines */
+F_FILE *T1Open(), *T1Eexec();
+int T1Close();
+int T1Read(), T1Getc(), T1Ungetc();
+STATIC int T1Decrypt(), T1Fill();
+/* -------------------------------------------------------------- */
+/*ARGSUSED*/
+F_FILE *T1Open(fn, mode)
+  char *fn;    /* Pointer to filename */
+  char *mode;  /* Pointer to open mode string */
+{
+  F_FILE *of = &TheFile;
+  int oflags = O_RDONLY;       /* We know we are only reading */
+
+  Decrypt = 0;
+#ifdef O_BINARY                        /* VMS or DOS */
+  oflags |= O_BINARY;
+#endif
+  of->fd = open(fn, oflags);
+  if (of->fd < 0)
+      return NULL;
+  /* Initialize the buffer information of our file descriptor */
+  of->b_base = TheBuffer;
+  of->b_size = F_BUFSIZ;
+  of->b_ptr = NULL;
+  of->b_cnt = 0;
+  of->flags = 0;
+  of->error = 0;
+  haveextrach = 0;
+  return &TheFile;
+} /* end Open */
+/* -------------------------------------------------------------- */
+int T1Getc(f)        /* Read one character */
+  F_FILE *f;         /* Stream descriptor */
+{
+  if (f->b_base == NULL) return EOF;  /* already closed */
+  if (f->flags & UNGOTTENC) { /* there is an ungotten c */
+    f->flags &= ~UNGOTTENC;
+    return (int) f->ungotc;
+  }
+  if (f->b_cnt == 0)  /* Buffer needs to be (re)filled */
+    f->b_cnt = T1Fill(f);
+  if (f->b_cnt > 0) return (f->b_cnt--, (int) *(f->b_ptr++));
+  else {
+    f->flags |= FIOEOF;
+    return EOF;
+  }
+} /* end Getc */
+/* -------------------------------------------------------------- */
+int T1Ungetc(c, f)   /* Put back one character */
+  int c;
+  F_FILE *f;         /* Stream descriptor */
+{
+  if (c != EOF) {
+    f->ungotc = c;
+    f->flags |= UNGOTTENC;  /* set flag */
+    f->flags &= ~FIOEOF;    /* reset EOF */
+  }
+  return c;
+} /* end Ungetc */
+/* -------------------------------------------------------------- */
+int T1Read(buffP, size, n, f)  /* Read n items into caller's buffer */
+  char *buffP;       /* Buffer to be filled */
+  int   size;        /* Size of each item */
+  int   n;           /* Number of items to read */
+  F_FILE *f;         /* Stream descriptor */
+{
+  int bytelen, cnt, i;
+  F_char *p = (F_char *)buffP;
+  int  icnt;         /* Number of characters to read */
+  if (f->b_base == NULL) return 0;  /* closed */
+  icnt = (size!=1)?n*size:n;  /* Number of bytes we want */
+  if (f->flags & UNGOTTENC) { /* there is an ungotten c */
+    f->flags &= ~UNGOTTENC;
+    *(p++) = f->ungotc;
+    icnt--; bytelen = 1;
+  }
+  else bytelen = 0;
+  while (icnt > 0) {
+    /* First use any bytes we have buffered in the stream buffer */
+    if ((cnt=f->b_cnt) > 0) {
+      if (cnt > icnt) cnt = icnt;
+      for (i=0; i<cnt; i++) *(p++) = *(f->b_ptr++);
+      f->b_cnt -= cnt;
+      icnt -= cnt;
+      bytelen += cnt;
+    }
+    if ((icnt == 0) || (f->flags & FIOEOF)) break;
+    f->b_cnt = T1Fill(f);
+  }
+  return ((size!=1)?bytelen/size:bytelen);
+} /* end Read */
+/* -------------------------------------------------------------- */
+int T1Close(f)       /* Close the file */
+  F_FILE *f;         /* Stream descriptor */
+{
+  if (f->b_base == NULL) return 0;  /* already closed */
+  f->b_base = NULL;  /* no valid stream */
+  return close(f->fd);
+} /* end Close */
+
+#ifdef __STDC__
+#define   pointer          void *
+#else
+#define   pointer          char *
+#endif
+/* -------------------------------------------------------------- */
+F_FILE *T1eexec(f)   /* Initialization */
+  F_FILE *f;         /* Stream descriptor */
+{
+  int i, c;
+  int H;
+  unsigned char *p;
+  unsigned char randomP[8];
+  r = 55665;  /* initial key */
+  asc = 1;    /* indicate ASCII form */
+  /* Consume the 4 random bytes, determining if we are also to
+     ASCIIDecodeHex as we process our input.  (See pages 63-64
+     of the Adobe Type 1 Font Format book.)  */
+  /* Skip over any initial white space chars */
+  while (HighHexP[c=getc(f)] == HWHITE_SPACE) ;
+  /* If ASCII, the next 7 chars are guaranteed consecutive */
+  randomP[0] = c;  /* store first non white space char */
+  fread((pointer)(randomP+1), 1, 3, f);  /* read 3 more, for a total of 4 */
+  /* store first four chars */
+  for (i=0,p=randomP; i<4; i++) {  /* Check 4 valid ASCIIEncode chars */
+    if (HighHexP[*p++] > LAST_HDIGIT) {  /* non-ASCII byte */
+      asc = 0;
+      break;
+    }
+  }
+  if (asc) {  /* ASCII form, convert first eight bytes to binary */
+    fread((pointer)(randomP+4), 1, 4, f);  /* Need four more */
+    for (i=0,p=randomP; i<4; i++) {  /* Convert */
+      H = HighHexP[*p++];
+      randomP[i] = H | LowHexP[*p++];
+    }
+  }
+  /* Adjust our key */
+  for (i=0,p=randomP; i<4; i++) {
+    r = (*p++ + r) * c1 + c2;
+  }
+  /* Decrypt the remaining buffered bytes */
+  f->b_cnt = T1Decrypt(f->b_ptr, f->b_cnt);
+  Decrypt = 1;
+  return (feof(f))?NULL:f;
+} /* end eexec */
+/* -------------------------------------------------------------- */
+STATIC int T1Decrypt(p, len)
+  unsigned char *p;
+  int len;
+{
+  int n;
+  int H, L;
+  unsigned char *inp = p;
+  unsigned char *tblP;
+  if (asc) {
+    if (haveextrach) {
+      H = extrach;
+      tblP = LowHexP;
+    }
+    else tblP = HighHexP;
+    for (n=0; len>0; len--) {
+      L = tblP[*inp++];
+      if (L == HWHITE_SPACE) continue;
+      if (L > LAST_HDIGIT) break;
+      if (tblP == HighHexP) { /* Got first hexit value */
+        H = L;
+        tblP = LowHexP;
+      } else { /* Got second hexit value; compute value and store it */
+        n++;
+        tblP = HighHexP;
+        H |= L;
+        /* H is an int, 0 <= H <= 255, so all of this will work */
+        *p++ = H ^ (r >> 8);
+        r = (H + r) * c1 + c2;
+      }
+    }
+    if (tblP != HighHexP) {  /* We had an odd number of hexits */
+      extrach = H;
+      haveextrach = 1;
+    } else haveextrach = 0;
+    return n;
+  } else {
+    for (n = len; n>0; n--) {
+      H = *inp++;
+      *p++ = H ^ (r >> 8);
+      r = (H + r) * c1 + c2;
+    }
+    return len;
+  }
+} /* end Decrypt */
+/* -------------------------------------------------------------- */
+STATIC int T1Fill(f) /* Refill stream buffer */
+  F_FILE *f;         /* Stream descriptor */
+{
+  int rc;
+  rc = read(f->fd, f->b_base, F_BUFSIZ);
+  /* propagate any error or eof to current file */
+  if (rc <= 0) {
+    if (rc == 0)    /* means EOF */
+      f->flags |= FIOEOF;
+    else {
+      f->error = (short)-rc;
+      f->flags |= FIOERROR;
+      rc = 0;
+    }
+  }
+  f->b_ptr = f->b_base;
+  if (Decrypt) rc = T1Decrypt(f->b_base, rc);
+  return rc;
+} /* end Fill */
diff --git a/Xserver/lib/font/Type1/t1malloc.c b/Xserver/lib/font/Type1/t1malloc.c
new file mode 100644 (file)
index 0000000..be93bda
--- /dev/null
@@ -0,0 +1,729 @@
+/* $XConsortium: t1malloc.c,v 1.5 93/09/10 10:48:21 rws Exp $ */
+/* Copyright International Business Machines, Corp. 1991
+ * All Rights Reserved
+ * Copyright Lexmark International, Inc. 1991
+ * All Rights Reserved
+ *
+ * License to use, copy, modify, and distribute this software and its
+ * documentation for any purpose and without fee is hereby granted,
+ * provided that the above copyright notice appear in all copies and that
+ * both that copyright notice and this permission notice appear in
+ * supporting documentation, and that the name of IBM or Lexmark not be
+ * used in advertising or publicity pertaining to distribution of the
+ * software without specific, written prior permission.
+ *
+ * IBM AND LEXMARK PROVIDE THIS SOFTWARE "AS IS", WITHOUT ANY WARRANTIES OF
+ * ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING, BUT NOT LIMITED TO ANY
+ * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE,
+ * AND NONINFRINGEMENT OF THIRD PARTY RIGHTS.  THE ENTIRE RISK AS TO THE
+ * QUALITY AND PERFORMANCE OF THE SOFTWARE, INCLUDING ANY DUTY TO SUPPORT
+ * OR MAINTAIN, BELONGS TO THE LICENSEE.  SHOULD ANY PORTION OF THE
+ * SOFTWARE PROVE DEFECTIVE, THE LICENSEE (NOT IBM OR LEXMARK) ASSUMES THE
+ * ENTIRE COST OF ALL SERVICING, REPAIR AND CORRECTION.  IN NO EVENT SHALL
+ * IBM OR LEXMARK BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
+ * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
+ * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
+ * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
+ * THIS SOFTWARE.
+ */
+ /* MALLOC   CWEB         V0004 LOTS                                 */
+/*
+:h1.MALLOC - Fast Memory Allocation
+This module is meant to provide portable C-style memory allocation
+routines (malloc/free).
+&author. Jeffrey B. Lotspiech (lotspiech@almaden.ibm.com)
+*/
+
+#include "objects.h"   /* get #define for abort() */
+
+static combine();
+static freeuncombinable();
+static unhook();
+static dumpchain();
+/*
+:h3.Define NULL
+In the beginning, C compilers made no assumptions about NULL.  It was
+even theoretically possible that NULL would not be 0.  ANSI has tied
+this down a bit.  The following definition seems to be the most
+popular (in terms of reducing compiler complaints), however, if your
+compiler is unhappy about it, you can redefine it on the command line:
+*/
+#ifndef   NULL
+#define   NULL   0
+#endif
+/*
+Of course, NULL is important because xiMalloc() is defined to return
+NULL when out of memory.
+:h2.Data Structures Used to Manage Free Memory
+:h3.The "freeblock" Structure
+The list of available memory blocks is a doubly-linked list.  Each
+block begins with the following structure:
+*/
+struct freeblock {
+        long size;                      /* number of 'longs' in block,
+                                           including this header */
+        struct freeblock *fore;        /* forward in doubly-linked list */
+        struct freeblock *back;        /* backward in doubly-linked list */
+} ;
+/*
+In addition, each free block has a TRAILER that is simply the 'size'
+repeated.  Thus 'size' is found at the beginning of the block and at the
+end of the block (size-1 longs away).  'size' includes both the header
+and the trailer.
+When a block is allocated, its 'size' is turned negative (both at the
+beginning and at the end).  Thus, checking whether two blocks may be
+combined is very simple.  We merely examine both neighboring blocks'
+size to see if they are positive (and hence available for combination).
+The memory address returned to the user is therefore one "long" below the
+size, and one extra "long" is added to the end of the block (beyond what
+the user requested) to store the trailing size.
+:h3."firstfree" and "lastfree", the Anchors to the Free List
+"firstfree" points to the first available free block; "lastfree" points
+to the end of the chain of available blocks.  These are linked together
+by initialization code; see :hdref refid=addmem..
+*/
+static struct freeblock firstfree = { 0L, NULL, NULL };
+static struct freeblock lastfree = { 0L, NULL, NULL };
+/*
+:h3."firstcombined" and "uncombined", Keeping Track of Uncombined Blocks
+This module is designed to make the combining of adjacent free memory
+blocks be very fast.  Nonetheless, combining blocks is naturally the
+most expensive part of any memory system.  In an X system,
+it is worthwhile to defer the combination for a while, because
+frequently we will end up asking for a block of exactly the same
+size that we recently returned and we can save ourselves some work.
+"MAXUNCOMBINED" is the maximum number of uncombined blocks that we will
+allow at any time:
+*/
+#define   MAXUNCOMBINED  3
+/*
+"firstcombined" is a pointer into the free list.  The uncombined blocks
+are always at the front of the list.  "firstcombined" points to the
+first block that has been combined.
+*/
+static struct freeblock *firstcombined = &lastfree;
+static short uncombined = 0; /* current number of uncombined blocks          */
+/*
+Uncombined blocks have a negative 'size'; in this they are like
+allocated blocks.
+We store a distinctive hex pattern in 'size' when we combine a block
+to help us debug:
+*/
+#define   COMBINED   0xBADBAD
+/*
+:h3.DEBUGWORDS - Extra Memory Saved With Each Block for Debug
+We add 'DEBUGWORDS' words to each allocated block to put interesting
+debug information:
+*/
+#ifndef   DEBUGWORDS
+#define   DEBUGWORDS   0
+#endif
+/*
+:h3.MINEXCESS - Amount of "Excess" We Would be Willing to Ignore
+When we search the free list to find memory for a user request, we
+frequently find an area that is bigger than what the user has asked for.
+Normally we put the remaining words (the excess) back on the free list.
+However, if the area is just slightly bigger than what the user needs,
+it is counter-productive to do this, as the small amount recovered tends
+to hurt by increasing memory fragmentation rather than help by providing
+more available memory.  "MINEXCESS" is the number of words that must be
+recovered before we would bother to put the excess back on the free
+list.  If there is not enough excess, we just give the user more than he
+asked for.
+*/
+#define   MINEXCESS      (7 + DEBUGWORDS)
+/*
+:h3.Some Flags for Debug
+*/
+long AvailableWords = 0;     /* number of words available in memory          */
+char mallocdebug = 0;        /* a flag that enables some chatty printf's     */
+/*
+:h3.whocalledme() - Debug for Memory Leaks
+This routine is 68000-specific; it copies the value of the application's
+curOper variable (which is often a pointer to a character string), and
+the first part of the stack at the time malloc was called into the
+DEBUGWORDS area reserved with each block.
+We use it to see who is malloc-ing memory without free-ing it.
+*/
+#if DEBUGWORDS
+static whocalledme(addr, stack)
+       long *addr;           /* address of memory block                      */
+       long *stack;          /* address of malloc's parameter on stack       */
+{
+       register long size;   /* size of memory block                         */
+       register int i;       /* loop index                                   */
+       extern char *curOper; /* ptr to last operator (kept by appl.) */
+       stack--;
+       size = - *addr;
+       addr += size - 1 - DEBUGWORDS;
+       *addr++ = (long) curOper;
+       for (i=0; i < DEBUGWORDS-1; i++)
+               *addr++ = *stack++;
+}
+#else
+#define whocalledme(addr, stack)
+#endif
+/*
+:h2.xiFree() - User-Callable "Return Memory" Routine
+The actual beginning of the block is one 'long' before the address we
+gave to the user.  The block begins and ends with '-size' in words.
+*/
+void xiFree(addr)
+        register long *addr;           /* user's memory to be returned   */
+{
+        register long size;            /* amount of memory in this block */
+        register struct freeblock *p;  /* identical to 'addr'            */
+        if (addr == NULL) {  /* common "mistake", so allow it (CHT) */
+            printf("\nxiFree(NULL)?\n");
+            return;
+        }
+        size = *--addr;
+/*
+Make sure this address looks OK; 'size' must be less than zero (meaning
+the block is allocated) and should be repeated at the end of the block.
+*/
+        if (size >= 0)
+                abort("free: bad size");
+        if (addr[-1 - size] != size)
+                abort("free: mismatched size");
+/*
+Now make this a 'freeblock' structure and tack it on the FRONT of the
+free list (where uncombined blocks go):
+*/
+        AvailableWords -= size;  /* actually INCREASES AvailableWords */
+        p = (struct freeblock *) addr;
+        p->back = &firstfree;
+        (p->fore = firstfree.fore)->back = p;
+        firstfree.fore = p;
+/*
+If we have too many uncombined blocks, call combine() to combine one.
+*/
+        if (++uncombined > MAXUNCOMBINED) {
+                combine();
+                if (mallocdebug) {
+                        printf("xiFree(%08x) with combine, ", addr);
+                        dumpchain();
+                }
+        }
+        else {
+                if (mallocdebug) {
+                        printf("xiFree(%08x), ", addr);
+                        dumpchain();
+                }
+        }
+        return;
+}
+/*
+:h3.combine() - Subroutine of xiFree() to Combine Blocks
+This routine tries to combine the block just before 'firstcombined'.
+In any event, that block will be moved to the end of the list (after
+'firstcombined').
+*/
+static combine()
+{
+        register struct freeblock *p;   /* block we will try to combine */
+        register long *addr;            /* identical to 'p' for 'long' access */
+        register long size;             /* size of this block  */
+        register long size2;            /* size of potential combinee */
+        p = firstcombined->back;
+        if (p == &firstfree)
+               abort("why are we combining?");
+        addr = (long *) p;
+        size = - p->size;
+        if (--uncombined < 0)
+                abort("too many combine()s");
+        if (addr[-1] < 0 && addr[size] < 0) {
+/*
+We special case the situation where no combining can be done.  Then, we
+just mark the chain "combined" (i.e., positive size), move the
+'firstcombined' pointer back in the chain, and return.
+*/
+                addr[0] = addr[size - 1] = size;
+                firstcombined = (struct freeblock *) addr;
+                return;
+        }
+/*
+Otherwise, we unhook this pointer from the chain:
+*/
+        unhook(p);
+/*
+First we attempt to combine this with the block immediately above:
+*/
+        size2 = addr[-1];
+        if (size2 > 0) {     /* i.e., block above is free */
+                *addr = COMBINED;  /* might help debug */
+                addr -= size2;
+                if (addr[0] != size2)
+                        abort("bad block above");
+                unhook(addr);
+                size += size2;
+        }
+/*
+At this point 'addr' and 'size' may be the original block, or it may be
+the newly combined block.  Now we attempt to combine it with the block
+below:
+*/
+        p = (struct freeblock *) (addr + size);
+        size2 = p->size;
+        if (size2 > 0) {     /* i.e., block below is free                    */
+                p->size = COMBINED;
+                if (size2 != ((long *) p)[size2 - 1])
+                        abort("bad block below");
+                unhook(p);
+                size += size2;
+        }
+/*
+Finally we take the newly combined block and put it on the end of the
+chain by calling the "freeuncombinable" subroutine:
+*/
+        freeuncombinable(addr, size);
+}
+/*
+:h3.freeuncombinable() - Free a Block That Need Not be Combined
+This block is "uncombinable" either because we have already combined
+it with its eligible neighbors, or perhaps because we know it has
+no neighbors.
+*/
+static freeuncombinable(addr, size)
+        register long *addr;  /* address of the block to be freed            */
+        register long size;   /* size of block in words                      */
+{
+        register struct freeblock *p;  /* a convenient synonym for 'addr'    */
+/*
+Mark block allocated and combined by setting its 'size' positive:
+*/
+        addr[size - 1] = addr[0] = size;
+/*
+Now tack the block on the end of the doubly-linked free list:
+*/
+        p = (struct freeblock *) addr;
+        p->fore = &lastfree;
+        (p->back = lastfree.back)->fore = p;
+        lastfree.back = p;
+/*
+If we have previously had no combined blocks, we must update
+'firstcombined' to point to this block:
+*/
+        if (firstcombined->fore == NULL)
+                firstcombined = p;
+}
+/*
+:h3.unhook() - Unhook a Block from the Doubly-linked List
+The only tricky thing here is to make sure that 'firstcombined' is
+updated if this block happened to be the old 'firstcombined'.  (We
+would never be unhooking 'firstfree' or 'lastfree', so we do not
+have to worry about the end cases.)
+*/
+static unhook(p)
+        register struct freeblock *p;  /* block to unhook                    */
+{
+        p->back->fore = p->fore;
+        p->fore->back = p->back;
+        if (firstcombined == p)
+                firstcombined = p->fore;
+}
+/*
+:h2.xiMalloc() - Main User Entry Point for Getting Memory
+We have two slightly different versions of xiMalloc().  In the case
+where we have TYPE1IMAGER and a font cache, we are prepared, when nominally
+out of memory, to loop calling TYPE1IMAGER's GimeSpace() to release font
+cache.
+*/
+/* The following code put in by MDC on 11/10/90 */
+#ifdef TYPE1IMAGER
+static char *malloc_local();
+char *xiMalloc(size)
+        register unsigned size;
+{
+  char *memaddr;
+  while ( (memaddr = malloc_local(size)) == NULL ) {
+    /* Ask TYPE1IMAGER to give us some of its cache back */
+    if ( I_GimeSpace() == 0 ) break; /* We are really, really, out of memory */
+  }
+  return(memaddr);
+}
+#endif
+/*
+Now begins the real workhorse xiMalloc() (called 'malloc_local' if
+we are taking advantage of TYPE1IMAGER).  Its argument is an unsigned;
+at least that lets users with 16-bit integers get a 64K chunk of
+memory, and it is also compatible with the definition of a "size_t"
+in most systems.
+*/
+#ifdef TYPE1IMAGER
+static char *malloc_local(Size)
+#else
+char *xiMalloc(Size)
+#endif
+        unsigned Size;       /* number of bytes the user requested           */
+{
+        register long size = (long)Size;  /* a working register for size     */
+        register struct freeblock *p;  /* tentative block to be returned     */
+        register long excess; /* words in excess of user request             */
+        register long *area; /* a convenient synonym for 'p'                 */
+/*
+First, we increase 'size' to allow for the two size fields we will
+save with the block, plus any information for debug purposes.
+Then we ensure that the block will be large enough to hold our
+'freeblock' information.  Finally we convert it to be in words
+(longs), not bytes, increased to span an integral number of double
+words, so that all memory blocks dispensed with be properly aligned.
+*/
+        size += 2*sizeof(long) + DEBUGWORDS*sizeof(long);
+        if (size < sizeof(struct freeblock) + sizeof(long))
+               size = sizeof(struct freeblock) + sizeof(long);
+        size = ((unsigned) (size + sizeof(double) - 1) / sizeof(double)) * (sizeof(double)/sizeof(long));
+/*
+For speed, we will try first to give the user back a very recently
+returned block--one that is on the front of the chain before
+'firstcombined'.  These blocks still have negative sizes, and need
+only to be "unhook"ed:
+*/
+        size = -size;
+        for (p=firstfree.fore; p != firstcombined; p=p->fore) {
+                if (p->size == size) {
+                        unhook(p);
+                        uncombined--;
+                        if (mallocdebug) {
+                               printf("fast xiMalloc(%d) = %08x, ", size, p);
+                               dumpchain();
+                        }
+                        AvailableWords += size;  /* decreases AvailableWords */
+                        whocalledme(p, &Size);
+                        return((char *)&p->fore);
+                }
+        }
+/*
+Well, if we get here, there are no uncombined blocks matching the user's
+request.  So, we search the rest of the chain for a block that is big
+enough.  ('size' becomes positive again):
+*/
+        size = -size;
+        for (;; p = p->fore) {
+/*
+If we hit the end of the chain (p->size == 0), we are probably out of
+memory.  However, we should first try to combine any memory that has
+not yet been combined before we give that pessimistic answer.  If
+we succeed in combining, we can call ourselves recursively to try to
+allocate the requested amount:
+*/
+               if (p->size == 0) {
+                       if (uncombined <= 0)
+                              return(NULL);
+                       while (firstfree.fore != firstcombined)
+                              combine();
+                       return(xiMalloc(sizeof(long) * (size - 2 - DEBUGWORDS)));
+               }
+/*
+Otherwise, we keep searching until we find a big enough block:
+*/
+               if (p->size >= size)
+                       break;
+        }
+/*
+At this point, 'p' contains a block at least as big as what the user
+requested, so we take it off the free chain.  If it is excessively big,
+we return the excess to the free chain:
+*/
+        unhook(p);
+        excess = p->size - size;
+        area = (long *) p;
+        if (excess > MINEXCESS)
+                freeuncombinable(area + size, excess);
+        else
+                size = p->size;
+        AvailableWords -= size;
+/*
+Mark first and last word of block with the negative of the size, to
+flag that this block is allocated:
+*/
+        area[size - 1] = area[0] = - size;
+        if (mallocdebug) {
+                printf("slow xiMalloc(%d) @ %08x, ", size, area);
+                dumpchain();
+        }
+        whocalledme(area, &Size);
+/*
+The address we return to the user is one 'long' BELOW the address of
+the block.  This protects our 'size' field, so we can tell the size
+of the block when he returns it to us with xiFree().  Also, he better not
+touch the 'size' field at the end of the block either.  (That would be
+nasty of him, as he would be touching memory outside of the bytes he
+requested).
+*/
+        return((char *) (area + 1));
+}
+/*
+:h2 id=addmem.addmemory() - Initialize Free Memory
+This routine should be called at initialization to initialize the
+free chain.  There is no standard way to do this in C.
+We want the memory dispensed by malloc to be aligned on a double word
+boundary (because some machines either require alignment, or are
+more efficient if accesses are aligned).  Since the total size of
+any block created by malloc is an integral number of double words,
+all we have to do to ensure alignment is to adjust each large block
+added to the free chain to start on an odd long-word boundary.
+(Malloc's size field will occupy the odd long and the user's memory
+will then begin on an even boundary.)  Since we fill in additional
+size fields at the beginning and end of each of the large freeblocks,
+we need only adjust the address passed to addmemory to a double word
+boundary.
+*/
+#define   MAXAREAS   10      /* there can be this many calls to addmemory()  */
+static long *freearea[MAXAREAS] = { NULL };  /* so we can report later       */
+void addmemory(addr, size)
+        register long *addr; /* beginning of free area                       */
+        register long size;  /* number of bytes of free area                 */
+{
+        register int i;      /* loop index variable                          */
+        register long *aaddr;  /* aligned beginning of free area             */
+#if DEBUGWORDS
+        printf("malloc has DEBUGWORDS=%d\n", DEBUGWORDS);
+#endif
+/*
+First link together firstfree and lastfree if necessary:
+*/
+        if (firstfree.fore == NULL) {
+                firstfree.fore = &lastfree;
+                lastfree.back = &firstfree;
+        }
+/*
+We'll record where the area was that was given to us for later reports:
+*/
+        for (i=0; i < MAXAREAS; i++)
+                if (freearea[i] == NULL) break;
+        if (i >= MAXAREAS)
+                abort("too many addmemory()s");
+        aaddr = (long *) ( ((long) addr + sizeof(double) - 1) & - (long)sizeof(double) );
+        size -= (char *) aaddr - (char *) addr;
+        freearea[i] = aaddr;
+/*
+Convert 'size' to number of longs, and store '-size' guards at the
+beginning and end of this area so we will not accidentally recombine the
+first or last block:
+*/
+        size /= sizeof(long);
+        AvailableWords += size - 2;
+        aaddr[size - 1] = aaddr[0] = -size;
+/*
+Finally, call 'freeuncombinable' to put the remaining memory on the
+free list:
+*/
+        freeuncombinable(aaddr + 1, size - 2);
+}
+/*
+:h3.delmemory() - Delete Memory Pool
+*/
+void delmemory()
+{
+       register int i;
+       AvailableWords = 0;
+       firstfree.fore = &lastfree;
+       lastfree.back  = &firstfree;
+       firstcombined  = &lastfree;
+       uncombined     = 0;
+       for (i=0; i<MAXAREAS; i++)
+               freearea[i] = NULL;
+}
+/*
+:h2.Debug Routines
+:h3.dumpchain() - Print the Chain of Free Blocks
+*/
+static dumpchain()
+{
+        register struct freeblock *p;  /* current free block                 */
+        register long size;  /* size of block                                */
+        register struct freeblock *back;  /* block before 'p'                */
+        register int i;      /* temp variable for counting                   */
+        printf("DUMPING FAST FREE LIST:\n");
+        back = &firstfree;
+        for (p = firstfree.fore, i=uncombined; p != firstcombined;
+                                 p = p->fore) {
+                if (--i < 0)
+                        abort("too many uncombined areas");
+                size = p->size;
+                printf(". . . area @ %08x, size = %ld\n", p, -size);
+                if (size >= 0 || size != ((int *) p)[-1 - size])
+                        abort("dumpchain: bad size");
+                if (p->back != back)
+                        abort("dumpchain: bad back");
+                back = p;
+        }
+        printf("DUMPING COMBINED FREE LIST:\n");
+        for (; p != &lastfree; p = p->fore)  {
+                size = p->size;
+                printf(". . . area @ %08x, size = %d\n", p, size);
+                if (size <= 0 || size != ((int *) p)[size - 1])
+                        abort("dumpchain: bad size");
+                if (p->back != back)
+                        abort("dumpchain: bad back");
+                back = p;
+        }
+        if (back != lastfree.back)
+                abort("dumpchain: bad lastfree");
+}
+/*
+:h3.reportarea() - Display a Contiguous Set of Memory Blocks
+*/
+static reportarea(area)
+       register long *area;   /* start of blocks (from addmemory)            */
+{
+       register long size;    /* size of current block                       */
+       register long wholesize;  /* size of original area                    */
+       register struct freeblock *p;  /* pointer to block                    */
+       if (area == NULL)
+               return;
+       wholesize = - *area++;
+       wholesize -= 2;
+       while (wholesize > 0) {
+               size = *area;
+               if (size < 0) {
+                       register int i,j;
+                       size = -size;
+                       printf("Allocated %5d bytes at %08x, first words=%08x %08x\n",
+                               size * sizeof(long), area + 1, area[1], area[2]);
+#if DEBUGWORDS
+                       printf("  ...Last operator: %s\n",
+                               (char *)area[size-DEBUGWORDS-1]);
+#endif
+                       for (i = size - DEBUGWORDS; i < size - 2; i += 8) {
+                               printf("  ...");
+                               for (j=0; j<8; j++)
+                                       printf(" %08x", area[i+j]);
+                               printf("\n");
+                       }
+               }
+               else {
+                       printf("Free %d bytes at %x\n", size * sizeof(long),
+                               area);
+                       if (size == 0)
+                               abort("zero sized memory block");
+                       for (p = firstfree.fore; p != NULL; p = p->fore)
+                               if ((long *) p == area) break;
+                       if ((long *) p != area)
+                               abort("not found on forward chain");
+                       for (p = lastfree.back; p != NULL; p = p->back)
+                               if ((long *) p == area) break;
+                       if ((long *) p != area)
+                               abort("not found on backward chain");
+               }
+               if (area[0] != area[size - 1])
+                       abort("unmatched check sizes");
+               area += size;
+               wholesize -= size;
+       }
+}
+/*
+:h3.MemReport() - Display All of Memory
+*/
+MemReport()
+{
+       register int i;
+       dumpchain();
+       for (i=0; i<MAXAREAS; i++)
+               reportarea(freearea[i]);
+}
+/*
+:h3.MemBytesAvail - Display Number of Bytes Now Available
+*/
+MemBytesAvail()
+{
+       printf("There are now %d bytes available\n", AvailableWords *
+                                                    sizeof(long) );
+}
diff --git a/Xserver/lib/font/Type1/t1snap.c b/Xserver/lib/font/Type1/t1snap.c
new file mode 100644 (file)
index 0000000..988539b
--- /dev/null
@@ -0,0 +1,79 @@
+/* $XConsortium: t1snap.c,v 1.3 91/10/10 11:19:47 rws Exp $ */
+/* Copyright International Business Machines,Corp. 1991
+ * All Rights Reserved
+ *
+ * License to use, copy, modify, and distribute this software
+ * and its documentation for any purpose and without fee is
+ * hereby granted, provided that the above copyright notice
+ * appear in all copies and that both that copyright notice and
+ * this permission notice appear in supporting documentation,
+ * and that the name of IBM not be used in advertising or
+ * publicity pertaining to distribution of the software without
+ * specific, written prior permission.
+ *
+ * IBM PROVIDES THIS SOFTWARE "AS IS", WITHOUT ANY WARRANTIES
+ * OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING, BUT NOT
+ * LIMITED TO ANY IMPLIED WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, AND NONINFRINGEMENT OF
+ * THIRD PARTY RIGHTS.  THE ENTIRE RISK AS TO THE QUALITY AND
+ * PERFORMANCE OF THE SOFTWARE, INCLUDING ANY DUTY TO SUPPORT
+ * OR MAINTAIN, BELONGS TO THE LICENSEE.  SHOULD ANY PORTION OF
+ * THE SOFTWARE PROVE DEFECTIVE, THE LICENSEE (NOT IBM) ASSUMES
+ * THE ENTIRE COST OF ALL SERVICING, REPAIR AND CORRECTION.  IN
+ * NO EVENT SHALL IBM BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
+ * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
+ * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
+ * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+ */
+#include "objects.h"
+#include "spaces.h"
+#include "paths.h"
+/*
+:h2.Handle Functions
+:h3.Phantom() - Returns a Move Segment Equivalent to Handles
+This is a user operator.  Its new name is QueryHandle.
+*/
+struct segment *t1_Phantom(obj)
+       register struct xobject *obj;  /* object to take the Phantom of       */
+{
+       struct fractpoint pt; /* handle size will built here                  */
+       if (obj == NULL)
+               pt.x = pt.y = 0;
+       else
+               PathDelta(obj, &pt);
+       return(PathSegment(MOVETYPE, pt.x, pt.y));
+}
+/*
+:h3.Snap() - Force Ending Handle of Object to Origin
+This is a user operator.
+*/
+struct xobject *t1_Snap(p)
+       register struct segment *p;  /* path to snap                          */
+{
+       struct fractpoint pt; /* for finding length of path                   */
+       if (p == NULL)
+               return(NULL);
+       p = UniquePath(p);
+       PathDelta(p, &pt);
+       if (p->last->type == MOVETYPE) {
+               p->last->dest.x -= pt.x;
+               p->last->dest.y -= pt.y;
+       }
+       else
+               p = JoinSegment(p, MOVETYPE, -pt.x, -pt.y, NULL);
+       return((struct xobject *)p);
+}
diff --git a/Xserver/lib/font/Type1/t1stdio.h b/Xserver/lib/font/Type1/t1stdio.h
new file mode 100644 (file)
index 0000000..2906171
--- /dev/null
@@ -0,0 +1,73 @@
+/* $XConsortium: t1stdio.h,v 1.4 91/10/10 11:19:49 rws Exp $ */
+/* Copyright International Business Machines,Corp. 1991
+ * All Rights Reserved
+ *
+ * License to use, copy, modify, and distribute this software
+ * and its documentation for any purpose and without fee is
+ * hereby granted, provided that the above copyright notice
+ * appear in all copies and that both that copyright notice and
+ * this permission notice appear in supporting documentation,
+ * and that the name of IBM not be used in advertising or
+ * publicity pertaining to distribution of the software without
+ * specific, written prior permission.
+ *
+ * IBM PROVIDES THIS SOFTWARE "AS IS", WITHOUT ANY WARRANTIES
+ * OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING, BUT NOT
+ * LIMITED TO ANY IMPLIED WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, AND NONINFRINGEMENT OF
+ * THIRD PARTY RIGHTS.  THE ENTIRE RISK AS TO THE QUALITY AND
+ * PERFORMANCE OF THE SOFTWARE, INCLUDING ANY DUTY TO SUPPORT
+ * OR MAINTAIN, BELONGS TO THE LICENSEE.  SHOULD ANY PORTION OF
+ * THE SOFTWARE PROVE DEFECTIVE, THE LICENSEE (NOT IBM) ASSUMES
+ * THE ENTIRE COST OF ALL SERVICING, REPAIR AND CORRECTION.  IN
+ * NO EVENT SHALL IBM BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
+ * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
+ * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
+ * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+ */
+/* T1IO FILE structure and related stuff */
+#define FILE F_FILE
+typedef unsigned char F_char;
+typedef struct F_FILE {
+  F_char  *b_base;    /* Pointer to beginning of buffer */
+  long    b_size;     /* Size of the buffer */
+  F_char  *b_ptr;     /* Pointer to next char in buffer */
+  long    b_cnt;      /* Number of chars remaining in buffer */
+  F_char  flags;      /* other flags; != 0 means getc must call fgetc */
+  F_char  ungotc;     /* Place for ungotten char; flag set if present */
+  short   error;      /* error status */
+  int     fd;         /* underlying file descriptor */
+} F_FILE;
+/* defines for flags */
+#define UNGOTTENC (0x01)
+#define FIOEOF    (0x80)
+#define FIOERROR  (0x40)
+#ifndef NULL
+#define NULL 0       /* null pointer */
+#endif
+#define EOF (-1)     /* end of file */
+#define F_BUFSIZ (512)
+#define getc(f) \
+  ( \
+   ( ((f)->b_cnt > 0) && ((f)->flags == 0) ) ? \
+   ( (f)->b_cnt--, (unsigned int)*( (f)->b_ptr++ ) ) : \
+   T1Getc(f) \
+  )
+extern FILE *T1Open(), *T1eexec();
+extern int T1Close(), T1ungetc(), T1Read();
+#define  fclose(f)          T1Close(f)
+#define  fopen(name,mode)   T1Open(name,mode)
+#define  ungetc(c,f)        T1Ungetc(c,f)
+#define  fgetc(f)           T1Getc(f)
+#define  fread(bufP,size,n,f) T1Read(bufP,size,n,f)
+#define  feof(f)            (((f)->flags & FIOEOF) && ((f)->b_cnt==0))
+#define  ferror(f)          (((f)->flags & FIOERROR)?(f)->error:0)
diff --git a/Xserver/lib/font/Type1/t1stub.c b/Xserver/lib/font/Type1/t1stub.c
new file mode 100644 (file)
index 0000000..f2d8af4
--- /dev/null
@@ -0,0 +1,42 @@
+/* $XConsortium: t1stub.c,v 1.3 92/03/20 15:58:40 eswu Exp $ */
+/* Copyright International Business Machines,Corp. 1991
+ * All Rights Reserved
+ *
+ * License to use, copy, modify, and distribute this software
+ * and its documentation for any purpose and without fee is
+ * hereby granted, provided that the above copyright notice
+ * appear in all copies and that both that copyright notice and
+ * this permission notice appear in supporting documentation,
+ * and that the name of IBM not be used in advertising or
+ * publicity pertaining to distribution of the software without
+ * specific, written prior permission.
+ *
+ * IBM PROVIDES THIS SOFTWARE "AS IS", WITHOUT ANY WARRANTIES
+ * OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING, BUT NOT
+ * LIMITED TO ANY IMPLIED WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, AND NONINFRINGEMENT OF
+ * THIRD PARTY RIGHTS.  THE ENTIRE RISK AS TO THE QUALITY AND
+ * PERFORMANCE OF THE SOFTWARE, INCLUDING ANY DUTY TO SUPPORT
+ * OR MAINTAIN, BELONGS TO THE LICENSEE.  SHOULD ANY PORTION OF
+ * THE SOFTWARE PROVE DEFECTIVE, THE LICENSEE (NOT IBM) ASSUMES
+ * THE ENTIRE COST OF ALL SERVICING, REPAIR AND CORRECTION.  IN
+ * NO EVENT SHALL IBM BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
+ * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
+ * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
+ * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+ */
+
+#include "objects.h"   /* get #define for abort() */
+xiStub()
+{
+       printf("xiStub called\n");
+       abort("xiStub called");
+}
+void t1_DumpText()
+{
+       xiStub();
+}
diff --git a/Xserver/lib/font/Type1/t1test.c b/Xserver/lib/font/Type1/t1test.c
new file mode 100644 (file)
index 0000000..672da50
--- /dev/null
@@ -0,0 +1,248 @@
+/* $XConsortium: t1test.c /main/4 1996/09/28 16:47:53 rws $ */
+/* Copyright International Business Machines,Corp. 1991
+ * All Rights Reserved
+ *
+ * License to use, copy, modify, and distribute this software
+ * and its documentation for any purpose and without fee is
+ * hereby granted, provided that the above copyright notice
+ * appear in all copies and that both that copyright notice and
+ * this permission notice appear in supporting documentation,
+ * and that the name of IBM not be used in advertising or
+ * publicity pertaining to distribution of the software without
+ * specific, written prior permission.
+ *
+ * IBM PROVIDES THIS SOFTWARE "AS IS", WITHOUT ANY WARRANTIES
+ * OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING, BUT NOT
+ * LIMITED TO ANY IMPLIED WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, AND NONINFRINGEMENT OF
+ * THIRD PARTY RIGHTS.  THE ENTIRE RISK AS TO THE QUALITY AND
+ * PERFORMANCE OF THE SOFTWARE, INCLUDING ANY DUTY TO SUPPORT
+ * OR MAINTAIN, BELONGS TO THE LICENSEE.  SHOULD ANY PORTION OF
+ * THE SOFTWARE PROVE DEFECTIVE, THE LICENSEE (NOT IBM) ASSUMES
+ * THE ENTIRE COST OF ALL SERVICING, REPAIR AND CORRECTION.  IN
+ * NO EVENT SHALL IBM BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
+ * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
+ * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
+ * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+ */
+#include "fntfilst.h"
+#include "FSproto.h"
+void Display();
+#define DECIPOINTSPERINCH 722.7
+#define DEFAULTRES 75
+#define DEFAULTPOINTSIZE 120
+FontScalableRec vals;
+FontEntryRec entry;
+int main(argc, argv)
+       int argc;
+       char *argv[];
+{
+       int h;
+       char temp[80];
+       char file[80];
+       char glyphcode[1];
+       FontPtr fontptr;
+       CharInfoRec *glyphs[1];
+       int count;
+       int code;
+       int rc = -1;
+       T1FillVals(&vals);
+       Type1RegisterFontFileFunctions();
+       entry.name.name = "-adobe-utopia-medium-r-normal--0-0-0-0-p-0-iso8859-1";
+       for (;;) {
+               printf("T1TEST: ");
+               gets(temp);
+               glyphcode[0] = '\0';
+               switch(temp[0]) {
+                   case 'c':
+                       if (1 != sscanf(&temp[2], "%c", glyphcode))
+                               printf("glyph code?\n");
+                       break;
+                   case 'x':
+                       if (1 != sscanf(&temp[2], "%x", &code))
+                               printf("glyph code?\n");
+                       else
+                               glyphcode[0] = code;
+                       break;
+                   case 'd':
+                       if (1 != sscanf(&temp[2], "%d", &code))
+                               printf("glyph code?\n");
+                       else
+                               glyphcode[0] = code;
+                       break;
+                   case 'h':
+                       if (1 != sscanf(&temp[2], "%d", &h))
+                               printf("height?\n");
+                       vals.pixel = h;
+                       rc = Type1OpenScalable(NULL, &fontptr, 0, &entry, file, &vals, 0, 0);
+                       break;
+                   case 'f':
+                       if (1 != sscanf(&temp[2], "%s", file))
+                               printf("file name?\n");
+                       rc = Type1OpenScalable(NULL, &fontptr, 0, &entry, file, &vals, 0, 0);
+                       break;
+                   case 't':
+                       if (1 != sscanf(&temp[2], "%s", file))
+                               printf("file name?\n");
+                       vals.pixel = 8;
+                       rc = Type1OpenScalable(NULL, &fontptr, 0, &entry, file, &vals, 0, 0);
+                       if (rc != Successful) break;
+                       vals.pixel = 20;
+                       rc = Type1OpenScalable(NULL, &fontptr, 0, &entry, file, &vals, 0, 0);
+                       if (rc != Successful) break;
+                       vals.pixel = 50;
+                       rc = Type1OpenScalable(NULL, &fontptr, 0, &entry, file, &vals, 0, 0);
+                       glyphcode[0] = 'A';
+                       printf("From font '%s':\n", file);
+                       break;
+                   case 'q':
+                       return 0;
+                   default:
+                       printf("unknown command '%c', must one of 'qfchdxt'\n", temp[0]);
+               }
+               if (rc == Successful) {
+                      if (glyphcode[0] != '\0') {
+                              (*fontptr->get_glyphs)(fontptr, 1, glyphcode, 0, &count, glyphs);
+                              if (count > 0)
+                                      Display(glyphs[0]);
+                              else
+                                      printf("Code %x not valid in this font\n", glyphcode[0]);
+                      }
+               }
+               else
+                      printf("Bad font (rc = %d, file='%s')\n", rc, file);
+       }
+}
+static void Display(glyph)
+       CharInfoRec *glyph;
+{
+       int h,w;
+       unsigned char *p;
+       int data;
+       int i;
+       p = glyph->bits;
+       printf("Metrics: left=%d, right=%d, w=%d, above=%d, below=%d\n",
+               glyph->metrics.leftSideBearing,
+               glyph->metrics.rightSideBearing,
+               glyph->metrics.characterWidth,
+               glyph->metrics.ascent,
+               glyph->metrics.descent);
+       for (h=glyph->metrics.ascent + glyph->metrics.descent; --h >= 0;) {
+               w = glyph->metrics.rightSideBearing - glyph->metrics.leftSideBearing;
+               while (w > 0) {
+                       data = *p++;
+                       for (i=0; i<8; i++) {
+                               if (--w < 0)
+                                       break;
+                               if (data & 0x80)
+                                       printf("X");
+                               else
+                                       printf(".");
+                               data <<= 1;
+                       }
+               }
+               printf("\n");
+       }
+}
+T1FillVals(vals)
+    FontScalablePtr vals;
+{
+    FontResolutionPtr res;
+    int         x_res = DEFAULTRES;
+    int         y_res = DEFAULTRES;
+    int         pointsize = DEFAULTPOINTSIZE;  /* decipoints */
+    int         num_res;
+    /* Must have x, y, and pixel */
+    if (!vals->x || !vals->y || !vals->pixel) {
+        res = GetClientResolutions(&num_res);
+        if (num_res) {
+            if (res->x_resolution)
+                x_res = res->x_resolution;
+            if (res->y_resolution)
+                y_res = res->y_resolution;
+            if (res->point_size)
+                pointsize = res->point_size;
+        }
+        if (!vals->x)
+            vals->x = x_res;
+        if (!vals->y)
+            vals->y = y_res;
+        if (!vals->point) {
+            if (!vals->pixel) vals->point = pointsize;
+            else vals->point = (vals->pixel * DECIPOINTSPERINCH) / vals->y;
+        }
+        if (!vals->pixel)
+            vals->pixel = (vals->point * vals->y) / DECIPOINTSPERINCH;
+        /* Make sure above arithmetic is normally in range and will
+           round properly. +++ */
+    }
+}
+int CheckFSFormat(format, fmask, bit, byte, scan, glyph, image)
+       int format,fmask,*bit,*byte,*scan,*glyph,*image;
+{
+       *bit = *byte = 1;
+       *glyph = *scan = *image = 1;
+       return Successful;
+}
+char *MakeAtom(p)
+       char *p;
+{
+       return p;
+}
+
+
+FontResolutionPtr GetClientResolutions(resP)
+       int *resP;
+{
+       *resP = 0;
+};
+char *Xalloc(size)
+       int size;
+{
+       extern char *malloc();
+       return(malloc(size));
+}
+void Xfree()
+{
+       free();
+}
+FontDefaultFormat() { ; }
+FontFileRegisterRenderer() { ; }
+GenericGetBitmaps() { ; }
+GenericGetExtents() { ; }
+FontParseXLFDName() { ; }
+FontComputeInfoAccelerators() { ; }
diff --git a/Xserver/lib/font/Type1/token.c b/Xserver/lib/font/Type1/token.c
new file mode 100644 (file)
index 0000000..da1c291
--- /dev/null
@@ -0,0 +1,1211 @@
+/* $XConsortium: token.c,v 1.3 94/02/04 17:07:17 gildea Exp $ */
+/* Copyright International Business Machines,Corp. 1991
+ * All Rights Reserved
+ *
+ * License to use, copy, modify, and distribute this software
+ * and its documentation for any purpose and without fee is
+ * hereby granted, provided that the above copyright notice
+ * appear in all copies and that both that copyright notice and
+ * this permission notice appear in supporting documentation,
+ * and that the name of IBM not be used in advertising or
+ * publicity pertaining to distribution of the software without
+ * specific, written prior permission.
+ *
+ * IBM PROVIDES THIS SOFTWARE "AS IS", WITHOUT ANY WARRANTIES
+ * OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING, BUT NOT
+ * LIMITED TO ANY IMPLIED WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, AND NONINFRINGEMENT OF
+ * THIRD PARTY RIGHTS.  THE ENTIRE RISK AS TO THE QUALITY AND
+ * PERFORMANCE OF THE SOFTWARE, INCLUDING ANY DUTY TO SUPPORT
+ * OR MAINTAIN, BELONGS TO THE LICENSEE.  SHOULD ANY PORTION OF
+ * THE SOFTWARE PROVE DEFECTIVE, THE LICENSEE (NOT IBM) ASSUMES
+ * THE ENTIRE COST OF ALL SERVICING, REPAIR AND CORRECTION.  IN
+ * NO EVENT SHALL IBM BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
+ * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
+ * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
+ * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+ */
+/* Authors: Sig Nin & Carol Thompson IBM Almaden Research Laboratory */
+#include "t1stdio.h"
+#include "util.h"
+#include "digit.h"
+#include "token.h"
+#include "tokst.h"
+#include "hdigit.h"
+/*
+ * -------------------------------------------------------------------
+ * Globals
+ * -------------------------------------------------------------------
+ */
+/* These variables are set by the caller */
+char           *tokenStartP;   /* Pointer to token buffer in VM */
+char           *tokenMaxP;     /* Pointer to last byte in buffer + 1 */
+/* These variables are set by TOKEN */
+int             tokenLength;   /* Characters in token */
+boolean         tokenTooLong;  /* Token too long for buffer */
+int             tokenType;     /* Type of token identified */
+psvalue         tokenValue;    /* Token value */
+/*
+ * -------------------------------------------------------------------
+ * Private variables
+ * -------------------------------------------------------------------
+ */
+static FILE    *inputFileP;    /* Current input file */
+/* Token */
+static char    *tokenCharP;    /* Pointer to next character in token */
+/*
+ * -------------------------------------------------------------------
+ * Private routines for manipulating numbers
+ * -------------------------------------------------------------------
+ */
+#define Exp10(e) \
+((e) == 0\
+ ? (double)(1.0)\
+ : (-64 <= (e) && (e) <= 63\
+    ? Exp10T[(e)+64]\
+    : P10(e)\
+   )\
+)
+static double Exp10T[128] = {
+  1e-64, 1e-63, 1e-62, 1e-61, 1e-60, 1e-59, 1e-58, 1e-57,
+  1e-56, 1e-55, 1e-54, 1e-53, 1e-52, 1e-51, 1e-50, 1e-49,
+  1e-48, 1e-47, 1e-46, 1e-45, 1e-44, 1e-43, 1e-42, 1e-41,
+  1e-40, 1e-39, 1e-38, 1e-37, 1e-36, 1e-35, 1e-34, 1e-33,
+  1e-32, 1e-31, 1e-30, 1e-29, 1e-28, 1e-27, 1e-26, 1e-25,
+  1e-24, 1e-23, 1e-22, 1e-21, 1e-20, 1e-19, 1e-18, 1e-17,
+  1e-16, 1e-15, 1e-14, 1e-13, 1e-12, 1e-11, 1e-10, 1e-9,
+  1e-8, 1e-7, 1e-6, 1e-5, 1e-4, 1e-3, 1e-2, 1e-1,
+  1e0, 1e1, 1e2, 1e3, 1e4, 1e5, 1e6, 1e7,
+  1e8, 1e9, 1e10, 1e11, 1e12, 1e13, 1e14, 1e15,
+  1e16, 1e17, 1e18, 1e19, 1e20, 1e21, 1e22, 1e23,
+  1e24, 1e25, 1e26, 1e27, 1e28, 1e29, 1e30, 1e31,
+  1e32, 1e33, 1e34, 1e35, 1e36, 1e37, 1e38, 1e39,
+  1e40, 1e41, 1e42, 1e43, 1e44, 1e45, 1e46, 1e47,
+  1e48, 1e49, 1e50, 1e51, 1e52, 1e53, 1e54, 1e55,
+  1e56, 1e57, 1e58, 1e59, 1e60, 1e61, 1e62, 1e63
+};
+static double P10(exponent)
+  long exponent;
+{
+  double value, power;
+  if (exponent < 0) {
+    power = 0.1;
+    value = (exponent & 1 ? power : 1.0);
+    exponent = -(++exponent >> 1); /* portable C for -(exponent/2) */
+  }
+  else {
+    power = 10.0;
+    value = (exponent & 1 ? power : 1.0);
+    exponent = exponent >> 1;
+  }
+  while(exponent > 0) {
+    power *= power;
+    if (exponent & 1)
+      value *= power;
+    exponent >>= 1;
+  }
+  return(value);
+}
+/*
+ * -------------------------------------------------------------------
+ * Private routines and macros for manipulating the input
+ * -------------------------------------------------------------------
+ */
+/* Get next character from the input --
+ *
+ */
+#define next_ch()    (getc(inputFileP))
+/* Push a character back into the input --
+ *
+ * Ungetc of EOF will fail, but that's ok: the next getc will
+ * return EOF.
+ *
+ * NOTE:  These macros are presently written to return the character
+ * pushed, or EOF if none was pushed.  However, they are not
+ * required to return anything in particular, and callers should
+ * not rely on the returned value.
+ */
+#define back_ch(ch)   (ungetc(ch, inputFileP))
+/* Push a character back into the input if it was not white space.
+ * If it is a carriage return (\r) then check next char for
+ * linefeed and consume them both, otherwise put next char back.
+ *
+ */
+#define back_ch_not_white(ch) \
+(\
+isWHITE_SPACE(ch)\
+ ? ((ch == '\r')\
+   ? (((ch = next_ch()) == '\n')\
+     ? EOF\
+     : back_ch(ch)\
+     )\
+   : EOF\
+   )\
+ : back_ch(ch)\
+)
+/*
+ * -------------------------------------------------------------------
+ * Private routines and macros for manipulating the token buffer
+ * -------------------------------------------------------------------
+ */
+/* Add a character to the token
+ * ---- use ONLY when you KNOW that this character will
+ *      be stored within the token buffer.
+ */
+#define save_unsafe_ch(ch) (*tokenCharP++ = ch)
+/* Add a character to the token, if not too long to fit */
+#define save_ch(ch) \
+((tokenCharP < tokenMaxP)\
+ ? save_unsafe_ch(ch)\
+ : (tokenTooLong = TRUE)\
+)
+
+#define save_ch_no_inc(ch) \
+((tokenCharP < tokenMaxP) && (*tokenCharP = ch))
+/*
+ * -------------------------------------------------------------------
+ * Action Routines
+ *
+ *  These routines all
+ *    -- take int ch as a parameter
+ *    -- return int ch if no token was recognized, DONE otherwise
+ *    -- leave the next character in the input, if returning DONE
+ * -------------------------------------------------------------------
+ */
+#define DONE  (256)
+/* Get the next input character */
+static int next_char(ch)
+  int ch;
+{
+  return(next_ch());
+}
+/* Add character to token */
+static int add_char(ch)
+  int ch;
+{
+  save_ch(ch);
+  return(next_ch());
+}
+/* -------------------------------------------------------------------
+ * Skip white space and comments
+ */
+/* Skip white space */
+static int skip_space(ch)
+  int ch;
+{
+  do {
+    ch = next_ch();
+  } while(isWHITE_SPACE(ch));
+  return(ch);
+}
+/* Skip comments */
+static int skip_comment(ch)
+  int ch;
+{
+  do {
+    ch = next_ch();
+  } while(isCOMMENT(ch));
+  return(ch);
+}
+/* -------------------------------------------------------------------
+ * Collect value elements for a number
+ */
+/* decimal integer or real number mantissa */
+static int m_sign;
+static long m_value;
+static long m_scale;
+/* real number exponent */
+static int e_sign;
+static long e_value;
+static long e_scale;
+/* radix number */
+static long r_base;
+static long r_value;
+static long r_scale;
+static int add_sign(ch)
+  int ch;
+{
+  m_sign = ch;
+  save_unsafe_ch(ch);
+  return(next_ch());
+}
+static int add_1st_digits(ch)
+  int ch;
+{
+  m_sign = '+';
+  return(add_digits(ch));
+}
+static int add_digits(ch)
+  int ch;
+{
+  long value, p_value, scale;
+  int digit;
+  /* On entry, expect m_sign to be set to '+' or '-';
+   *  ch is a decimal digit.
+   * Expect at most one character saved at this point,
+   *  a sign.  This routine will save up to 10 more
+   *  characters without checking the buffer boundary.
+   */
+  value = ch - '0';
+  save_unsafe_ch(ch);
+  ch = next_ch();
+  while(isDECIMAL_DIGIT(ch) && value < (MAX_INTEGER/10)) {
+    value = (value << 3) + (value << 1) + (ch - '0');
+    save_unsafe_ch(ch);
+    ch = next_ch();
+  }
+  /* Quick exit for small integers --
+   *    |x| <= 10*((MAX_INTEGER/10)-1)+9
+   *    |x| <= 2,147,483,639 for 32 bit integers
+   */
+  if (isNUMBER_ENDER(ch)) {
+    back_ch_not_white(ch);
+    tokenValue.integer = (m_sign == '-' ? -value : value);
+    tokenType = TOKEN_INTEGER;
+    return(DONE);
+  }
+  /* Handle additional digits.  Beyond the boundary case,
+   *   10*(MAX_INTEGER/10) <= |number| <= MAX_INTEGER
+   * just count the digits: the number is too large to
+   * represent as an integer and will be returned as a real.
+   * The mantissa of a real holds fewer bits than an integer.
+   */
+  p_value = value;
+  value = (m_sign == '-' ? -value : value);
+  scale = 0;
+  if (isDECIMAL_DIGIT(ch)) {
+    /* Handle the boundary case */
+    if (p_value == (MAX_INTEGER/10)) {
+      digit = ch - '0';
+      /* Must handle positive and negative values separately  */
+      /* for 2's complement arithmetic */
+      if (value > 0) {
+        if (digit <= MAX_INTEGER%10)
+          value = (value << 3) + (value << 1) + digit;
+        else
+          ++scale;  /* Too big, just count it */
+      }
+      else {
+        /* Use positive % operands for portability */
+        if (digit <= -(MIN_INTEGER+10)%10)
+          value = (value << 3) + (value << 1) - digit;
+        else
+          ++scale;  /* Too big, just count it */
+      }
+    }
+    else
+      ++scale;  /* Not boundary case, just count digit */
+    save_unsafe_ch(ch);
+    ch = next_ch();
+    /* Continue scanning digits, but can't store them */
+    while(isDECIMAL_DIGIT(ch)) {
+      ++scale;
+      save_ch(ch);
+      ch = next_ch();
+    }
+  }
+  /* Continue from here scanning radix integer or real */
+  m_value = value;
+  m_scale = scale;
+  /* Initialize for possible real */
+  e_sign = '+';
+  e_value = 0;
+  e_scale = 0;
+  return(ch);
+}
+static int add_1st_decpt(ch)
+  int ch;
+{
+  m_sign = '+';
+  return(add_decpt(ch));
+}
+static int add_decpt(ch)
+  int ch;
+{
+  /* On entry, expect m_sign to be set to '+' or '-' */
+  m_value = 0;
+  m_scale = 0;
+  save_unsafe_ch(ch);
+  return(next_ch());
+}
+static int add_fraction(ch)
+  int ch;
+{
+  long value, scale;
+  int digit;
+  /* On entry, expect m_value and m_scale to be initialized,
+   * and m_sign to be set to '+' or '-'.  Expect m_value and m_sign
+   * to be consistent (this is not checked).
+   */
+  value = m_value;
+  scale = m_scale;
+  /* Scan leading zeroes */
+  if (value == 0) {
+    while(ch == '0') {
+      --scale;
+      save_ch(ch);
+      ch = next_ch();
+    }
+    /* Scan first significant digit */
+    if (isDECIMAL_DIGIT(ch)) {
+      --scale;
+      value = ch - '0';
+      value = (m_sign == '-' ? -value : value);
+      save_ch(ch);
+      ch = next_ch();
+    }
+    else
+      /* no significant digits -- number is zero */
+      scale = 0;
+  }
+  /* value != 0 || value == 0 && !isDECIMAL_DIGIT(ch) */
+  /* Scan additional significant digits */
+  if (isDECIMAL_DIGIT(ch)) {
+    if (value > 0) {
+      while(isDECIMAL_DIGIT(ch) && value < (MAX_INTEGER/10)) {
+        --scale;
+        value = (value << 3) + (value << 1) + (ch - '0');
+        save_ch(ch);
+        ch = next_ch();
+      }
+      /* Check boundary case */
+      if (isDECIMAL_DIGIT(ch) && value == (MAX_INTEGER/10)) {
+        digit = ch - '0';
+        if (digit <= MAX_INTEGER%10) {
+          --scale;
+          value = (value << 3) + (value << 1) + digit;
+          save_ch(ch);
+          ch = next_ch();
+        }
+      }
+    }
+    else {
+      /* value < 0 */
+      while(isDECIMAL_DIGIT(ch) && value > -(-(MIN_INTEGER+10)/10+1)) {
+        /* Use positive / operands for portability */
+        --scale;
+        value = (value << 3) + (value << 1) - (ch - '0');
+        save_ch(ch);
+        ch = next_ch();
+      }
+      /* Check boundary case */
+      if (isDECIMAL_DIGIT(ch)
+          && value == -(-(MIN_INTEGER+10)/10+1)) {
+        digit = ch - '0';
+        if (digit <= -(MIN_INTEGER+10)%10) {
+        /* Use positive % operands for portability */
+          --scale;
+          value = (value << 3) + (value << 1) - digit;
+          save_ch(ch);
+          ch = next_ch();
+        }
+      }
+    }
+    /* Additional digits can be discarded */
+    while(isDECIMAL_DIGIT(ch)) {
+      save_ch(ch);
+      ch = next_ch();
+    }
+  }
+  /* Store results */
+  m_value = value;
+  m_scale = scale;
+  /* Initialize for possible real */
+  e_sign = '+';
+  e_value = 0;
+  e_scale = 0;
+  return(ch);
+}
+static int add_e_sign(ch)
+  int ch;
+{
+  e_sign = ch;
+  save_ch(ch);
+  return(next_ch());
+}
+static int add_exponent(ch)
+  int ch;
+{
+  long value, p_value;
+  long scale = 0;
+  int digit;
+  /* On entry, expect e_sign to be set to '+' or '-' */
+  value = ch - '0';
+  save_ch(ch);
+  ch = next_ch();
+  while(isDECIMAL_DIGIT(ch) && value < (MAX_INTEGER/10)) {
+    value = (value << 3) + (value << 1) + (ch - '0');
+    save_ch(ch);
+    ch = next_ch();
+  }
+  p_value = value;
+  value = (e_sign == '-' ? -value : value);
+  /* Handle additional digits.  Beyond the boundary case,
+   *   10*(MAX_INTEGER/10) <= |number| <= MAX_INTEGER
+   * just count the digits: the number is too large to
+   * represent as an integer.
+   */
+  if (isDECIMAL_DIGIT(ch)) {
+    /* Examine boundary case */
+    if (p_value == (MAX_INTEGER/10)) {
+      digit = ch - '0';
+      /* Must handle positive and negative values separately */
+      /*  for 2's complement arithmetic */
+      if (value > 0) {
+        if (digit <= MAX_INTEGER%10)
+          value = (value << 3) + (value << 1) + digit;
+        else
+          ++scale; /* Too big, just count it */
+      }
+      else {
+        /* Use positive % operands for portability */
+        if (digit <= -(MIN_INTEGER+10)%10)
+          value = (value << 3) + (value << 1) - digit;
+        else
+          ++scale; /* Too big, just count it */
+      }
+    }
+    else
+      ++scale;  /* Not boundary case, just count digit */
+    save_ch(ch);
+    ch = next_ch();
+    /* Continue scanning digits, but can't store any more */
+    while(isDECIMAL_DIGIT(ch)) {
+      ++scale;
+      save_ch(ch);
+      ch = next_ch();
+    }
+  }
+  /* Store results */
+  e_value = value;
+  e_scale = scale;
+  return(ch);
+}
+static int add_radix(ch)
+  int ch;
+{
+  if (2 <= m_value && m_value <= 36 && m_scale == 0) {
+    r_base = m_value;
+    save_ch(ch);
+    return(next_ch());
+  }
+  else {
+    /* Radix invalid, complete a name token */
+    return(AAH_NAME(ch));
+  }
+}
+static int add_r_digits(ch)
+  int ch;
+{
+  unsigned long value;
+  long radix, scale;
+  int digit;
+  /* NOTE:  The syntax of a radix number allows only for
+   * values of zero or more.  The value will be stored as
+   * a 32 bit integer, which PostScript then interprets
+   * as signed.  This means, for example, that the numbers:
+   *
+   *     8#37777777777
+   *    10#4294967295
+   *    16#FFFFFFFF
+   *    36#1Z141Z3
+   *
+   * are all interpreted as -1.  This routine implements this
+   * idea explicitly:  it accumulates the number's value
+   * as unsigned, then casts it to signed when done.
+   */
+  /* Expect r_base to be initialized */
+  radix = r_base;
+  value = 0;
+  scale = 0;
+  /* Scan leading zeroes */
+  while(ch == '0') {
+    save_ch(ch);
+    ch = next_ch();
+  }
+  /* Handle first non-zero digit */
+  if ((digit=digit_value[ch]) < radix) {
+    value = digit;
+    save_ch(ch);
+    ch = next_ch();
+    /* Add digits until boundary case reached */
+    while((digit=digit_value[ch]) < radix
+            && value < (MAX_ULONG / radix)) {
+      value = value * radix + digit;
+      save_ch(ch);
+      ch = next_ch();
+    };
+    /* Scan remaining digits */
+    if ((digit=digit_value[ch]) < radix) {
+      /* Examine boundary case ---
+       *   radix*(MAX_ULONG/radix) <= number <= MAX_ULONG
+       */
+      if (value == (MAX_ULONG/radix) && digit <= MAX_ULONG%radix)
+        value = value * radix + digit;
+      else
+        ++scale;
+      /* Continue scanning digits, but can't store them */
+      save_ch(ch);
+      ch = next_ch();
+      while(digit_value[ch] < radix) {
+        ++scale;
+        save_ch(ch);
+        ch = next_ch();
+      }
+    }
+  }
+  /* Store result */
+  r_value = (long) value; /* result is signed */
+  r_scale = scale;
+  return(ch);
+}
+/* -------------------------------------------------------------------
+ * Complete a number; set token type and done flag.
+ * Put current input character back, if it is not white space.
+ */
+/* Done: Radix Number */
+static int RADIX_NUMBER(ch)
+  int ch;
+{
+  back_ch_not_white(ch);
+  if (r_scale == 0) {
+    tokenValue.integer = r_value;
+    tokenType = TOKEN_INTEGER;
+  }
+  else {
+    tokenType = TOKEN_NAME;
+  }
+  return(DONE);
+}
+/* Done: Integer */
+static int INTEGER(ch)
+  int ch;
+{
+  back_ch_not_white(ch);
+  if (m_scale == 0) {
+    tokenValue.integer = m_value;
+    tokenType = TOKEN_INTEGER;
+  }
+  else {
+    tokenValue.real = (double)(m_value) * Exp10(m_scale);
+    tokenType = TOKEN_REAL;
+  }
+  return(DONE);
+}
+/* Done: Real */
+static int REAL(ch)
+  int ch;
+{
+  double temp;
+  back_ch_not_white(ch);
+  /* NOTE: ignore e_scale, since e_value alone will cause
+   *   exponent overflow if e_scale > 0.
+   */
+  /* HAZARD: exponent overflow of intermediate result
+   * (e.g., in 370 floating point); this should not be a problem
+   * with IEEE floating point.  Reduce exponent overflow hazard by
+   * combining m_scale and e_value first, if they have different signs,
+   * or multiplying m_value and one of the other factors, if both
+   * m_scale and e_value are negative.
+   */
+  if ((m_scale >= 0 && e_value <= 0)
+      || (m_scale <= 0 && e_value >= 0)) {
+    tokenValue.real = (double)(m_value) * Exp10(m_scale + e_value);
+  }
+  else {
+    temp = (double)(m_value) * Exp10(m_scale);
+    tokenValue.real = temp * Exp10(e_value);
+  }
+  tokenType = TOKEN_REAL;
+  return(DONE);
+}
+/* -------------------------------------------------------------------
+ * Assemble a hex string; set token type and done flag.
+ */
+/* Done: Hex String */
+static int HEX_STRING(ch)
+  int ch;
+{
+  int value;
+  while(TRUE) {
+    /* Process odd digit */
+    ch = next_ch();
+    if (!isHEX_DIGIT(ch)) {
+      /* Skip white space */
+      while(isWHITE_SPACE(ch))
+        ch = next_ch();
+      /* Check for terminator */
+      if (!isHEX_DIGIT(ch)) {
+        break;
+      }
+    }
+    value = digit_value[ch] << 4;
+    /* Process even digit */
+    ch = next_ch();
+    if (!isHEX_DIGIT(ch)) {
+      /* Skip white space */
+      while(isWHITE_SPACE(ch))
+        ch = next_ch();
+      /* Check for terminator */
+      if (!isHEX_DIGIT(ch)) {
+        save_ch(value);
+        break;
+      }
+    }
+    save_ch(value + digit_value[ch]);
+  }
+  /* Classify result, based on why loop ended */
+  if (ch == '>')
+    tokenType = TOKEN_HEX_STRING;
+  else {
+    /* save the invalid character for error reporting */
+    save_ch(ch);
+    tokenType = TOKEN_INVALID;
+  }
+  return(DONE);
+}
+/* -------------------------------------------------------------------
+ * Assemble a string; set token type and done flag
+ */
+/* Save a backslash-coded character in a string --
+ *
+ *   Store the proper character for special cases
+ *   "\b", "\f", "\n", "\r", and "\t".
+ *
+ *   Decode and store octal-coded character, up to
+ *   three octal digits, "\o", "\oo", and "\ooo".
+ *
+ *   The sequence "\<newline>" is a line continuation,
+ *   so consume both without storing anything.
+ *
+ *   The sequence "\<EOF>" is an error; exit without
+ *   storing anything and let the caller handle it.
+ *
+ *   For other characters, including the sequences
+ *   "\\", "\(", and "\)", simply store the second
+ *   character.
+ */
+static void save_digraph(ch)
+  int ch;
+{
+  int value;
+  switch (ch) {
+    case 'b':   /* backspace */
+      ch = '\b';
+      break;
+    case 'f':   /* formfeed */
+      ch = '\f';
+      break;
+    case 'n':   /* newline */
+      ch = '\n';
+      break;
+    case 'r':   /* carriage return */
+      ch = '\r';
+      break;
+    case 't':   /* horizontal tab */
+      ch = '\t';
+      break;
+    case '\n':  /* line continuation -- consume it */
+      return;
+    case '\r':  /* carriage return   -- consume it */
+      ch = next_ch();   /* look at next character, is it \n?  */
+      if (ch == '\n')  return;
+      back_ch(ch);      /* if not a line feed, then return it */
+      return;
+    case EOF:   /* end of file -- forget it */
+      return;
+  default:
+    /* scan up to three octal digits to get value */
+    if (isOCTAL_DIGIT(ch)) {
+      value = digit_value[ch];
+      ch = next_ch();
+      if (isOCTAL_DIGIT(ch)) {
+        value = (value << 3) + digit_value[ch];
+        ch = next_ch();
+        if (isOCTAL_DIGIT(ch))
+          value = (value << 3) + digit_value[ch];
+        else
+          back_ch(ch);
+      }
+      else
+        back_ch(ch);
+      ch = value;
+    }
+  }
+  /* Found a character to save */
+  save_ch(ch);
+}
+/* Done: String */
+static int STRING(ch)
+  int ch;
+{
+  int nest_level = 1;
+  tokenType = TOKEN_STRING;
+  do {
+    ch = next_ch();
+    while(!isSTRING_SPECIAL(ch)) {
+      save_ch(ch);
+      ch = next_ch();
+    };
+    switch (ch) {
+     case '(':
+       ++nest_level;
+       save_ch(ch);
+       break;
+     case ')':
+       if (--nest_level > 0)
+         save_ch(ch);
+       break;
+     case '\\':
+          save_digraph(next_ch());
+        break;
+     case '\r':
+        /* All carriage returns (\r) are turned into linefeeds (\n)*/
+          ch = next_ch();       /* get the next one, is it \n? */
+          if (ch != '\n') {     /* if not, then put it back.   */
+            back_ch(ch);
+          }
+          save_ch('\n');        /* in either case, save a linefeed */
+        break;
+     case EOF:
+       tokenType = TOKEN_INVALID;  /* Unterminated string */
+       nest_level = 0;
+       break;
+    }
+  } while(nest_level > 0);
+  /* If there's room, add a 0-byte termination without increasing string
+     length.  This fixes certain dependencies on 0-terminated strings */
+  save_ch_no_inc(0);
+
+  return(DONE);
+}
+/* -------------------------------------------------------------------
+ * Assemble a name; set token type and done flag.
+ * Put current input character back, if it is not white space.
+ */
+/* Done: Name
+ *  (Safe version used to complete name tokens that
+ *   start out looking like something else).
+ */
+static int AAH_NAME(ch)
+  int ch;
+{
+  do {
+    save_ch(ch);
+    ch = next_ch();
+  } while(isNAME(ch));
+  back_ch_not_white(ch);
+  tokenType = TOKEN_NAME;
+  return(DONE);
+}
+/* Done: Name */
+static int NAME(ch)
+  int ch;
+{
+  save_unsafe_ch(ch);
+  ch = next_ch();
+  if (isNAME(ch)) {
+    save_unsafe_ch(ch);
+    ch = next_ch();
+    if (isNAME(ch)) {
+      save_unsafe_ch(ch);
+      ch = next_ch();
+      if (isNAME(ch)) {
+        save_unsafe_ch(ch);
+        ch = next_ch();
+        if (isNAME(ch)) {
+          save_unsafe_ch(ch);
+          ch = next_ch();
+          if (isNAME(ch)) {
+            save_unsafe_ch(ch);
+            ch = next_ch();
+            if (isNAME(ch)) {
+              save_unsafe_ch(ch);
+              ch = next_ch();
+              while(isNAME(ch)) {
+                save_ch(ch);
+                ch = next_ch();
+              }
+            }
+          }
+        }
+      }
+    }
+  }
+  back_ch_not_white(ch);
+  tokenType = TOKEN_NAME;
+  return(DONE);
+}
+/* Done: Literal Name */
+static int LITERAL_NAME(ch)
+  int ch;
+{
+  if (isNAME(ch)) {
+    save_unsafe_ch(ch);
+    ch = next_ch();
+    if (isNAME(ch)) {
+      save_unsafe_ch(ch);
+      ch = next_ch();
+      if (isNAME(ch)) {
+        save_unsafe_ch(ch);
+        ch = next_ch();
+        if (isNAME(ch)) {
+          save_unsafe_ch(ch);
+          ch = next_ch();
+          if (isNAME(ch)) {
+            save_unsafe_ch(ch);
+            ch = next_ch();
+            if (isNAME(ch)) {
+              save_unsafe_ch(ch);
+              ch = next_ch();
+              while(isNAME(ch)) {
+                save_ch(ch);
+                ch = next_ch();
+              }
+            }
+          }
+        }
+      }
+    }
+  }
+  back_ch_not_white(ch);
+  tokenType = TOKEN_LITERAL_NAME;
+  return(DONE);
+}
+/* Done: immediate Name */
+static int IMMED_NAME(ch)
+  int ch;
+{
+  ch = next_ch();
+  if (isNAME(ch)) {
+    save_unsafe_ch(ch);
+    ch = next_ch();
+    if (isNAME(ch)) {
+      save_unsafe_ch(ch);
+      ch = next_ch();
+      if (isNAME(ch)) {
+        save_unsafe_ch(ch);
+        ch = next_ch();
+        if (isNAME(ch)) {
+          save_unsafe_ch(ch);
+          ch = next_ch();
+          if (isNAME(ch)) {
+            save_unsafe_ch(ch);
+            ch = next_ch();
+            if (isNAME(ch)) {
+              save_unsafe_ch(ch);
+              ch = next_ch();
+              while(isNAME(ch)) {
+                save_ch(ch);
+                ch = next_ch();
+              }
+            }
+          }
+        }
+      }
+    }
+  }
+  back_ch_not_white(ch);
+  tokenType = TOKEN_IMMED_NAME;
+  return(DONE);
+}
+/* Done: Name found while looking for something else */
+static int OOPS_NAME(ch)
+  int ch;
+{
+  back_ch_not_white(ch);
+  tokenType = TOKEN_NAME;
+  return(DONE);
+}
+/* -------------------------------------------------------------------
+ * Complete a miscellaneous token; set token type and done flag.
+ */
+/* Done: Unmatched Right Angle-Bracket */
+static int RIGHT_ANGLE(ch)
+  int ch;
+{
+  tokenType = TOKEN_RIGHT_ANGLE;
+  return(DONE);
+}
+/* Done: Unmatched Right Parenthesis */
+static int RIGHT_PAREN(ch)
+  int ch;
+{
+  tokenType = TOKEN_RIGHT_PAREN;
+  return(DONE);
+}
+/* Done: Left Brace */
+static int LEFT_BRACE(ch)
+  int ch;
+{
+  tokenType = TOKEN_LEFT_BRACE;
+  return(DONE);
+}
+/* Done: Right Brace */
+static int RIGHT_BRACE(ch)
+  int ch;
+{
+  tokenType = TOKEN_RIGHT_BRACE;
+  return(DONE);
+}
+/* Done: Left Bracket */
+static int LEFT_BRACKET(ch)
+  int ch;
+{
+  save_unsafe_ch(ch);
+  tokenType = TOKEN_LEFT_BRACKET;
+  return(DONE);
+}
+/* Done: Right Bracket */
+static int RIGHT_BRACKET(ch)
+  int ch;
+{
+  save_unsafe_ch(ch);
+  tokenType = TOKEN_RIGHT_BRACKET;
+  return(DONE);
+}
+/* Done: Break */
+static int BREAK_SIGNAL(ch)
+  int ch;
+{
+  tokenType = TOKEN_BREAK;
+  return(DONE);
+}
+/* Done: No Token Found */
+static int NO_TOKEN(ch)
+  int ch;
+{
+  tokenType = TOKEN_EOF;
+  return(DONE);
+}
+/*
+ * -------------------------------------------------------------------
+ *  scan_token -- scan one token from the input.  It uses a simple
+ *    finite state machine to recognize token classes.
+ *
+ *  The input is from a file.
+ *
+ *  On entry --
+ *
+ *    inputP -> input PostScript object, a file.
+ *    tokenStartP -> buffer in VM for accumulating the token.
+ *    tokenMaxP -> last character in the token buffer
+ *
+ *  On exit --
+ *
+ *    tokenLength = number of characters in the token
+ *    tokenTooLong = TRUE if the token did not fit in the buffer
+ *    tokenType = code for the type of token parsed.
+ *    tokenValue = converted value of a numeric token.
+ *
+ *
+ * -------------------------------------------------------------------
+ */
+void scan_token(inputP)
+  psobj *inputP;
+{
+  int ch;
+  unsigned char *stateP = s0;
+  unsigned char entry;
+  int (*actionP)();
+  /* Define input source */
+  inputFileP = inputP->data.fileP;
+  if (inputFileP == NULL)  {
+    tokenType = TOKEN_EOF;
+    return;
+  }
+  /* Ensure enough space for most cases
+   * (so we don't have to keep checking)
+   * The length needs to cover the maximum number
+   * of save_unsafe_ch() calls that might be executed.
+   * That number is 11 (a sign and 10 decimal digits, e.g.,
+   * when scanning -2147483648), but use MAX_NAME_LEN
+   * in case someone changes that without checking.
+   */
+  tokenStartP = vm_next_byte();
+  tokenMaxP = tokenStartP + MIN(vm_free_bytes(), MAX_STRING_LEN);
+  if ((tokenMaxP-tokenStartP) < (MAX_NAME_LEN)) {
+    tokenLength = 0;
+    tokenTooLong = TRUE;
+    tokenType = TOKEN_NONE;
+    tokenValue.integer = 0;
+    return;
+  }
+  /* Reset token */
+  tokenCharP = tokenStartP;
+  tokenTooLong = FALSE;
+  /* Scan one token */
+  ch = next_ch();
+  do {
+    entry = stateP[ch];
+    stateP = classActionTable[entry].nextStateP;
+    actionP = classActionTable[entry].actionRoutineP;
+    ch = (*actionP)(ch);
+  } while(ch != DONE);
+  /* Return results */
+  tokenLength = tokenCharP - tokenStartP;
+}
diff --git a/Xserver/lib/font/Type1/token.h b/Xserver/lib/font/Type1/token.h
new file mode 100644 (file)
index 0000000..6fcfa0e
--- /dev/null
@@ -0,0 +1,77 @@
+/* $XConsortium: token.h,v 1.2 91/10/10 11:19:58 rws Exp $ */
+/* Copyright International Business Machines,Corp. 1991
+ * All Rights Reserved
+ *
+ * License to use, copy, modify, and distribute this software
+ * and its documentation for any purpose and without fee is
+ * hereby granted, provided that the above copyright notice
+ * appear in all copies and that both that copyright notice and
+ * this permission notice appear in supporting documentation,
+ * and that the name of IBM not be used in advertising or
+ * publicity pertaining to distribution of the software without
+ * specific, written prior permission.
+ *
+ * IBM PROVIDES THIS SOFTWARE "AS IS", WITHOUT ANY WARRANTIES
+ * OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING, BUT NOT
+ * LIMITED TO ANY IMPLIED WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, AND NONINFRINGEMENT OF
+ * THIRD PARTY RIGHTS.  THE ENTIRE RISK AS TO THE QUALITY AND
+ * PERFORMANCE OF THE SOFTWARE, INCLUDING ANY DUTY TO SUPPORT
+ * OR MAINTAIN, BELONGS TO THE LICENSEE.  SHOULD ANY PORTION OF
+ * THE SOFTWARE PROVE DEFECTIVE, THE LICENSEE (NOT IBM) ASSUMES
+ * THE ENTIRE COST OF ALL SERVICING, REPAIR AND CORRECTION.  IN
+ * NO EVENT SHALL IBM BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
+ * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
+ * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
+ * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+ */
+#ifndef TOKEN_H
+#define TOKEN_H
+/* Special characters */
+#define CONTROL_C           (3)
+/* Token type codes */
+#define TOKEN_INVALID       (-3)
+#define TOKEN_BREAK         (-2)
+#define TOKEN_EOF           (-1)
+#define TOKEN_NONE          (0)
+#define TOKEN_LEFT_PAREN    (1)
+#define TOKEN_RIGHT_PAREN   (2)
+#define TOKEN_LEFT_ANGLE    (3)
+#define TOKEN_RIGHT_ANGLE   (4)
+#define TOKEN_LEFT_BRACE    (5)
+#define TOKEN_RIGHT_BRACE   (6)
+#define TOKEN_LEFT_BRACKET  (7)
+#define TOKEN_RIGHT_BRACKET (8)
+#define TOKEN_NAME          (9)
+#define TOKEN_LITERAL_NAME  (10)
+#define TOKEN_INTEGER       (11)
+#define TOKEN_REAL          (12)
+#define TOKEN_RADIX_NUMBER  (13)
+#define TOKEN_HEX_STRING    (14)
+#define TOKEN_STRING        (15)
+#define TOKEN_IMMED_NAME    (16)
+/* Token routines */
+extern void scan_token();
+/*
+ * -------------------------------------------------------------------------
+ * Globals shared  -- (everyone else KEEP YOUR MITTS OFF THEM!)
+ * -------------------------------------------------------------------------
+ */
+/* These variables are set by the caller */
+extern char     *tokenStartP; /* Pointer to token buffer in VM */
+extern char     *tokenMaxP;   /* Pointer to end of VM we may use + 1 */
+/* These variables are set by P_TOKEN */
+extern int      tokenLength;  /* Characters in token */
+extern boolean  tokenTooLong; /* Token too long for space available */
+extern int      tokenType;    /* Type of token identified */
+extern psvalue  tokenValue;   /* Token value */
+#endif /* TOKEN_H */
diff --git a/Xserver/lib/font/Type1/tokst.h b/Xserver/lib/font/Type1/tokst.h
new file mode 100644 (file)
index 0000000..31a9fd0
--- /dev/null
@@ -0,0 +1,508 @@
+/* $XConsortium: tokst.h,v 1.2 91/10/10 11:20:00 rws Exp $ */
+/* Copyright International Business Machines,Corp. 1991
+ * All Rights Reserved
+ *
+ * License to use, copy, modify, and distribute this software
+ * and its documentation for any purpose and without fee is
+ * hereby granted, provided that the above copyright notice
+ * appear in all copies and that both that copyright notice and
+ * this permission notice appear in supporting documentation,
+ * and that the name of IBM not be used in advertising or
+ * publicity pertaining to distribution of the software without
+ * specific, written prior permission.
+ *
+ * IBM PROVIDES THIS SOFTWARE "AS IS", WITHOUT ANY WARRANTIES
+ * OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING, BUT NOT
+ * LIMITED TO ANY IMPLIED WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, AND NONINFRINGEMENT OF
+ * THIRD PARTY RIGHTS.  THE ENTIRE RISK AS TO THE QUALITY AND
+ * PERFORMANCE OF THE SOFTWARE, INCLUDING ANY DUTY TO SUPPORT
+ * OR MAINTAIN, BELONGS TO THE LICENSEE.  SHOULD ANY PORTION OF
+ * THE SOFTWARE PROVE DEFECTIVE, THE LICENSEE (NOT IBM) ASSUMES
+ * THE ENTIRE COST OF ALL SERVICING, REPAIR AND CORRECTION.  IN
+ * NO EVENT SHALL IBM BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
+ * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
+ * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
+ * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+ */
+/* -------------------------------------- */
+/* --- MACHINE GENERATED, DO NOT EDIT --- */
+/* -------------------------------------- */
+#ifndef TOKST
+#define TOKST 1
+/*
+ * State Index Tables --
+ *
+ *   These tables map the input character to the
+ *   proper entry in the Class Action Table.
+ *   There is one table for each state.
+ *
+ */
+#define s0 (si0+2)
+static unsigned char si0[258] = { 0x10,0x11,
+ 0x02,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x02,0x02,0x0F,0x0F,0x02,0x0F,0x0F,
+ 0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,
+ 0x02,0x0F,0x0F,0x0F,0x0F,0x03,0x0F,0x0F,0x05,0x0B,0x0F,0x0D,0x0F,0x0D,0x0E,0x04,
+ 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x0F,0x0F,0x08,0x0F,0x0C,0x0F,
+ 0x0F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x07,0x0F,0x0A,0x0F,0x0F,
+ 0x0F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x06,0x0F,0x09,0x0F,0x0F,
+ 0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,
+ 0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,
+ 0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,
+ 0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,
+ 0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,
+ 0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,
+ 0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,
+ 0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F
+};
+#define s1 (si1+2)
+static unsigned char si1[258] = { 0x14,0x15,
+ 0x13,0x13,0x13,0x13,0x13,0x13,0x13,0x13,0x13,0x13,0x13,0x13,0x13,0x13,0x13,0x13,
+ 0x13,0x13,0x13,0x13,0x13,0x13,0x13,0x13,0x13,0x13,0x13,0x13,0x13,0x13,0x13,0x13,
+ 0x13,0x13,0x13,0x13,0x13,0x13,0x13,0x13,0x13,0x13,0x13,0x13,0x13,0x13,0x13,0x12,
+ 0x13,0x13,0x13,0x13,0x13,0x13,0x13,0x13,0x13,0x13,0x13,0x13,0x13,0x13,0x13,0x13,
+ 0x13,0x13,0x13,0x13,0x13,0x13,0x13,0x13,0x13,0x13,0x13,0x13,0x13,0x13,0x13,0x13,
+ 0x13,0x13,0x13,0x13,0x13,0x13,0x13,0x13,0x13,0x13,0x13,0x13,0x13,0x13,0x13,0x13,
+ 0x13,0x13,0x13,0x13,0x13,0x13,0x13,0x13,0x13,0x13,0x13,0x13,0x13,0x13,0x13,0x13,
+ 0x13,0x13,0x13,0x13,0x13,0x13,0x13,0x13,0x13,0x13,0x13,0x13,0x13,0x13,0x13,0x13,
+ 0x13,0x13,0x13,0x13,0x13,0x13,0x13,0x13,0x13,0x13,0x13,0x13,0x13,0x13,0x13,0x13,
+ 0x13,0x13,0x13,0x13,0x13,0x13,0x13,0x13,0x13,0x13,0x13,0x13,0x13,0x13,0x13,0x13,
+ 0x13,0x13,0x13,0x13,0x13,0x13,0x13,0x13,0x13,0x13,0x13,0x13,0x13,0x13,0x13,0x13,
+ 0x13,0x13,0x13,0x13,0x13,0x13,0x13,0x13,0x13,0x13,0x13,0x13,0x13,0x13,0x13,0x13,
+ 0x13,0x13,0x13,0x13,0x13,0x13,0x13,0x13,0x13,0x13,0x13,0x13,0x13,0x13,0x13,0x13,
+ 0x13,0x13,0x13,0x13,0x13,0x13,0x13,0x13,0x13,0x13,0x13,0x13,0x13,0x13,0x13,0x13,
+ 0x13,0x13,0x13,0x13,0x13,0x13,0x13,0x13,0x13,0x13,0x13,0x13,0x13,0x13,0x13,0x13,
+ 0x13,0x13,0x13,0x13,0x13,0x13,0x13,0x13,0x13,0x13,0x13,0x13,0x13,0x13,0x13,0x13
+};
+#define s2 (si2+2)
+static unsigned char si2[258] = { 0x1B,0x1C,
+ 0x16,0x1A,0x1A,0x1A,0x1A,0x1A,0x1A,0x1A,0x1A,0x16,0x16,0x1A,0x1A,0x16,0x1A,0x1A,
+ 0x1A,0x1A,0x1A,0x1A,0x1A,0x1A,0x1A,0x1A,0x1A,0x1A,0x1A,0x1A,0x1A,0x1A,0x1A,0x1A,
+ 0x16,0x1A,0x1A,0x1A,0x1A,0x17,0x1A,0x1A,0x17,0x17,0x1A,0x1A,0x1A,0x1A,0x19,0x17,
+ 0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x1A,0x1A,0x17,0x1A,0x17,0x1A,
+ 0x1A,0x1A,0x1A,0x1A,0x1A,0x1A,0x1A,0x1A,0x1A,0x1A,0x1A,0x1A,0x1A,0x1A,0x1A,0x1A,
+ 0x1A,0x1A,0x1A,0x1A,0x1A,0x1A,0x1A,0x1A,0x1A,0x1A,0x1A,0x17,0x1A,0x17,0x1A,0x1A,
+ 0x1A,0x1A,0x1A,0x1A,0x1A,0x1A,0x1A,0x1A,0x1A,0x1A,0x1A,0x1A,0x1A,0x1A,0x1A,0x1A,
+ 0x1A,0x1A,0x1A,0x1A,0x1A,0x1A,0x1A,0x1A,0x1A,0x1A,0x1A,0x17,0x1A,0x17,0x1A,0x1A,
+ 0x1A,0x1A,0x1A,0x1A,0x1A,0x1A,0x1A,0x1A,0x1A,0x1A,0x1A,0x1A,0x1A,0x1A,0x1A,0x1A,
+ 0x1A,0x1A,0x1A,0x1A,0x1A,0x1A,0x1A,0x1A,0x1A,0x1A,0x1A,0x1A,0x1A,0x1A,0x1A,0x1A,
+ 0x1A,0x1A,0x1A,0x1A,0x1A,0x1A,0x1A,0x1A,0x1A,0x1A,0x1A,0x1A,0x1A,0x1A,0x1A,0x1A,
+ 0x1A,0x1A,0x1A,0x1A,0x1A,0x1A,0x1A,0x1A,0x1A,0x1A,0x1A,0x1A,0x1A,0x1A,0x1A,0x1A,
+ 0x1A,0x1A,0x1A,0x1A,0x1A,0x1A,0x1A,0x1A,0x1A,0x1A,0x1A,0x1A,0x1A,0x1A,0x1A,0x1A,
+ 0x1A,0x1A,0x1A,0x1A,0x1A,0x1A,0x1A,0x1A,0x1A,0x1A,0x1A,0x1A,0x1A,0x1A,0x1A,0x1A,
+ 0x1A,0x1A,0x1A,0x1A,0x1A,0x1A,0x1A,0x1A,0x1A,0x1A,0x1A,0x1A,0x1A,0x1A,0x1A,0x1A,
+ 0x1A,0x1A,0x1A,0x1A,0x1A,0x1A,0x1A,0x1A,0x1A,0x1A,0x1A,0x1A,0x1A,0x1A,0x1A,0x1A
+};
+#define s3 (si3+2)
+static unsigned char si3[258] = { 0x23,0x24,
+ 0x1D,0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x1D,0x1D,0x22,0x22,0x1D,0x22,0x22,
+ 0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22,
+ 0x1D,0x22,0x22,0x20,0x22,0x1E,0x22,0x22,0x1E,0x1E,0x22,0x22,0x22,0x22,0x1F,0x1E,
+ 0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x1E,0x22,0x1E,0x22,
+ 0x22,0x22,0x22,0x22,0x22,0x21,0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22,
+ 0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x1E,0x22,0x1E,0x22,0x22,
+ 0x22,0x22,0x22,0x22,0x22,0x21,0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22,
+ 0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x1E,0x22,0x1E,0x22,0x22,
+ 0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22,
+ 0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22,
+ 0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22,
+ 0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22,
+ 0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22,
+ 0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22,
+ 0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22,
+ 0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22
+};
+#define s4 (si4+2)
+static unsigned char si4[258] = { 0x29,0x2A,
+ 0x25,0x28,0x28,0x28,0x28,0x28,0x28,0x28,0x28,0x25,0x25,0x28,0x28,0x25,0x28,0x28,
+ 0x28,0x28,0x28,0x28,0x28,0x28,0x28,0x28,0x28,0x28,0x28,0x28,0x28,0x28,0x28,0x28,
+ 0x25,0x28,0x28,0x28,0x28,0x26,0x28,0x28,0x26,0x26,0x28,0x28,0x28,0x28,0x28,0x26,
+ 0x27,0x27,0x27,0x27,0x27,0x27,0x27,0x27,0x27,0x27,0x28,0x28,0x26,0x28,0x26,0x28,
+ 0x28,0x28,0x28,0x28,0x28,0x28,0x28,0x28,0x28,0x28,0x28,0x28,0x28,0x28,0x28,0x28,
+ 0x28,0x28,0x28,0x28,0x28,0x28,0x28,0x28,0x28,0x28,0x28,0x26,0x28,0x26,0x28,0x28,
+ 0x28,0x28,0x28,0x28,0x28,0x28,0x28,0x28,0x28,0x28,0x28,0x28,0x28,0x28,0x28,0x28,
+ 0x28,0x28,0x28,0x28,0x28,0x28,0x28,0x28,0x28,0x28,0x28,0x26,0x28,0x26,0x28,0x28,
+ 0x28,0x28,0x28,0x28,0x28,0x28,0x28,0x28,0x28,0x28,0x28,0x28,0x28,0x28,0x28,0x28,
+ 0x28,0x28,0x28,0x28,0x28,0x28,0x28,0x28,0x28,0x28,0x28,0x28,0x28,0x28,0x28,0x28,
+ 0x28,0x28,0x28,0x28,0x28,0x28,0x28,0x28,0x28,0x28,0x28,0x28,0x28,0x28,0x28,0x28,
+ 0x28,0x28,0x28,0x28,0x28,0x28,0x28,0x28,0x28,0x28,0x28,0x28,0x28,0x28,0x28,0x28,
+ 0x28,0x28,0x28,0x28,0x28,0x28,0x28,0x28,0x28,0x28,0x28,0x28,0x28,0x28,0x28,0x28,
+ 0x28,0x28,0x28,0x28,0x28,0x28,0x28,0x28,0x28,0x28,0x28,0x28,0x28,0x28,0x28,0x28,
+ 0x28,0x28,0x28,0x28,0x28,0x28,0x28,0x28,0x28,0x28,0x28,0x28,0x28,0x28,0x28,0x28,
+ 0x28,0x28,0x28,0x28,0x28,0x28,0x28,0x28,0x28,0x28,0x28,0x28,0x28,0x28,0x28,0x28
+};
+#define s5 (si5+2)
+static unsigned char si5[258] = { 0x30,0x31,
+ 0x2B,0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,0x2B,0x2B,0x2F,0x2F,0x2B,0x2F,0x2F,
+ 0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,
+ 0x2B,0x2F,0x2F,0x2F,0x2F,0x2C,0x2F,0x2F,0x2C,0x2C,0x2F,0x2F,0x2F,0x2F,0x2F,0x2C,
+ 0x2E,0x2E,0x2E,0x2E,0x2E,0x2E,0x2E,0x2E,0x2E,0x2E,0x2F,0x2F,0x2C,0x2F,0x2C,0x2F,
+ 0x2F,0x2F,0x2F,0x2F,0x2F,0x2D,0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,
+ 0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,0x2C,0x2F,0x2C,0x2F,0x2F,
+ 0x2F,0x2F,0x2F,0x2F,0x2F,0x2D,0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,
+ 0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,0x2C,0x2F,0x2C,0x2F,0x2F,
+ 0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,
+ 0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,
+ 0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,
+ 0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,
+ 0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,
+ 0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,
+ 0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,
+ 0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,0x2F
+};
+#define s6 (si6+2)
+static unsigned char si6[258] = { 0x36,0x37,
+ 0x32,0x35,0x35,0x35,0x35,0x35,0x35,0x35,0x35,0x32,0x32,0x35,0x35,0x32,0x35,0x35,
+ 0x35,0x35,0x35,0x35,0x35,0x35,0x35,0x35,0x35,0x35,0x35,0x35,0x35,0x35,0x35,0x35,
+ 0x32,0x35,0x35,0x35,0x35,0x33,0x35,0x35,0x33,0x33,0x35,0x35,0x35,0x35,0x35,0x33,
+ 0x35,0x35,0x35,0x35,0x35,0x35,0x35,0x35,0x35,0x35,0x35,0x35,0x33,0x35,0x33,0x35,
+ 0x35,0x35,0x35,0x35,0x35,0x34,0x35,0x35,0x35,0x35,0x35,0x35,0x35,0x35,0x35,0x35,
+ 0x35,0x35,0x35,0x35,0x35,0x35,0x35,0x35,0x35,0x35,0x35,0x33,0x35,0x33,0x35,0x35,
+ 0x35,0x35,0x35,0x35,0x35,0x34,0x35,0x35,0x35,0x35,0x35,0x35,0x35,0x35,0x35,0x35,
+ 0x35,0x35,0x35,0x35,0x35,0x35,0x35,0x35,0x35,0x35,0x35,0x33,0x35,0x33,0x35,0x35,
+ 0x35,0x35,0x35,0x35,0x35,0x35,0x35,0x35,0x35,0x35,0x35,0x35,0x35,0x35,0x35,0x35,
+ 0x35,0x35,0x35,0x35,0x35,0x35,0x35,0x35,0x35,0x35,0x35,0x35,0x35,0x35,0x35,0x35,
+ 0x35,0x35,0x35,0x35,0x35,0x35,0x35,0x35,0x35,0x35,0x35,0x35,0x35,0x35,0x35,0x35,
+ 0x35,0x35,0x35,0x35,0x35,0x35,0x35,0x35,0x35,0x35,0x35,0x35,0x35,0x35,0x35,0x35,
+ 0x35,0x35,0x35,0x35,0x35,0x35,0x35,0x35,0x35,0x35,0x35,0x35,0x35,0x35,0x35,0x35,
+ 0x35,0x35,0x35,0x35,0x35,0x35,0x35,0x35,0x35,0x35,0x35,0x35,0x35,0x35,0x35,0x35,
+ 0x35,0x35,0x35,0x35,0x35,0x35,0x35,0x35,0x35,0x35,0x35,0x35,0x35,0x35,0x35,0x35,
+ 0x35,0x35,0x35,0x35,0x35,0x35,0x35,0x35,0x35,0x35,0x35,0x35,0x35,0x35,0x35,0x35
+};
+#define s7 (si7+2)
+static unsigned char si7[258] = { 0x3D,0x3E,
+ 0x38,0x3C,0x3C,0x3C,0x3C,0x3C,0x3C,0x3C,0x3C,0x38,0x38,0x3C,0x3C,0x38,0x3C,0x3C,
+ 0x3C,0x3C,0x3C,0x3C,0x3C,0x3C,0x3C,0x3C,0x3C,0x3C,0x3C,0x3C,0x3C,0x3C,0x3C,0x3C,
+ 0x38,0x3C,0x3C,0x3C,0x3C,0x39,0x3C,0x3C,0x39,0x39,0x3C,0x3A,0x3C,0x3A,0x3C,0x39,
+ 0x3B,0x3B,0x3B,0x3B,0x3B,0x3B,0x3B,0x3B,0x3B,0x3B,0x3C,0x3C,0x39,0x3C,0x39,0x3C,
+ 0x3C,0x3C,0x3C,0x3C,0x3C,0x3C,0x3C,0x3C,0x3C,0x3C,0x3C,0x3C,0x3C,0x3C,0x3C,0x3C,
+ 0x3C,0x3C,0x3C,0x3C,0x3C,0x3C,0x3C,0x3C,0x3C,0x3C,0x3C,0x39,0x3C,0x39,0x3C,0x3C,
+ 0x3C,0x3C,0x3C,0x3C,0x3C,0x3C,0x3C,0x3C,0x3C,0x3C,0x3C,0x3C,0x3C,0x3C,0x3C,0x3C,
+ 0x3C,0x3C,0x3C,0x3C,0x3C,0x3C,0x3C,0x3C,0x3C,0x3C,0x3C,0x39,0x3C,0x39,0x3C,0x3C,
+ 0x3C,0x3C,0x3C,0x3C,0x3C,0x3C,0x3C,0x3C,0x3C,0x3C,0x3C,0x3C,0x3C,0x3C,0x3C,0x3C,
+ 0x3C,0x3C,0x3C,0x3C,0x3C,0x3C,0x3C,0x3C,0x3C,0x3C,0x3C,0x3C,0x3C,0x3C,0x3C,0x3C,
+ 0x3C,0x3C,0x3C,0x3C,0x3C,0x3C,0x3C,0x3C,0x3C,0x3C,0x3C,0x3C,0x3C,0x3C,0x3C,0x3C,
+ 0x3C,0x3C,0x3C,0x3C,0x3C,0x3C,0x3C,0x3C,0x3C,0x3C,0x3C,0x3C,0x3C,0x3C,0x3C,0x3C,
+ 0x3C,0x3C,0x3C,0x3C,0x3C,0x3C,0x3C,0x3C,0x3C,0x3C,0x3C,0x3C,0x3C,0x3C,0x3C,0x3C,
+ 0x3C,0x3C,0x3C,0x3C,0x3C,0x3C,0x3C,0x3C,0x3C,0x3C,0x3C,0x3C,0x3C,0x3C,0x3C,0x3C,
+ 0x3C,0x3C,0x3C,0x3C,0x3C,0x3C,0x3C,0x3C,0x3C,0x3C,0x3C,0x3C,0x3C,0x3C,0x3C,0x3C,
+ 0x3C,0x3C,0x3C,0x3C,0x3C,0x3C,0x3C,0x3C,0x3C,0x3C,0x3C,0x3C,0x3C,0x3C,0x3C,0x3C
+};
+#define s8 (si8+2)
+static unsigned char si8[258] = { 0x43,0x44,
+ 0x3F,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x3F,0x3F,0x42,0x42,0x3F,0x42,0x42,
+ 0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x42,
+ 0x3F,0x42,0x42,0x42,0x42,0x40,0x42,0x42,0x40,0x40,0x42,0x42,0x42,0x42,0x42,0x40,
+ 0x41,0x41,0x41,0x41,0x41,0x41,0x41,0x41,0x41,0x41,0x42,0x42,0x40,0x42,0x40,0x42,
+ 0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x42,
+ 0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x40,0x42,0x40,0x42,0x42,
+ 0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x42,
+ 0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x40,0x42,0x40,0x42,0x42,
+ 0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x42,
+ 0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x42,
+ 0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x42,
+ 0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x42,
+ 0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x42,
+ 0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x42,
+ 0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x42,
+ 0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x42
+};
+#define s9 (si9+2)
+static unsigned char si9[258] = { 0x48,0x49,
+ 0x45,0x47,0x47,0x47,0x47,0x47,0x47,0x47,0x47,0x45,0x45,0x47,0x47,0x45,0x47,0x47,
+ 0x47,0x47,0x47,0x47,0x47,0x47,0x47,0x47,0x47,0x47,0x47,0x47,0x47,0x47,0x47,0x47,
+ 0x45,0x47,0x47,0x47,0x47,0x46,0x47,0x47,0x46,0x46,0x47,0x47,0x47,0x47,0x47,0x46,
+ 0x47,0x47,0x47,0x47,0x47,0x47,0x47,0x47,0x47,0x47,0x47,0x47,0x46,0x47,0x46,0x47,
+ 0x47,0x47,0x47,0x47,0x47,0x47,0x47,0x47,0x47,0x47,0x47,0x47,0x47,0x47,0x47,0x47,
+ 0x47,0x47,0x47,0x47,0x47,0x47,0x47,0x47,0x47,0x47,0x47,0x46,0x47,0x46,0x47,0x47,
+ 0x47,0x47,0x47,0x47,0x47,0x47,0x47,0x47,0x47,0x47,0x47,0x47,0x47,0x47,0x47,0x47,
+ 0x47,0x47,0x47,0x47,0x47,0x47,0x47,0x47,0x47,0x47,0x47,0x46,0x47,0x46,0x47,0x47,
+ 0x47,0x47,0x47,0x47,0x47,0x47,0x47,0x47,0x47,0x47,0x47,0x47,0x47,0x47,0x47,0x47,
+ 0x47,0x47,0x47,0x47,0x47,0x47,0x47,0x47,0x47,0x47,0x47,0x47,0x47,0x47,0x47,0x47,
+ 0x47,0x47,0x47,0x47,0x47,0x47,0x47,0x47,0x47,0x47,0x47,0x47,0x47,0x47,0x47,0x47,
+ 0x47,0x47,0x47,0x47,0x47,0x47,0x47,0x47,0x47,0x47,0x47,0x47,0x47,0x47,0x47,0x47,
+ 0x47,0x47,0x47,0x47,0x47,0x47,0x47,0x47,0x47,0x47,0x47,0x47,0x47,0x47,0x47,0x47,
+ 0x47,0x47,0x47,0x47,0x47,0x47,0x47,0x47,0x47,0x47,0x47,0x47,0x47,0x47,0x47,0x47,
+ 0x47,0x47,0x47,0x47,0x47,0x47,0x47,0x47,0x47,0x47,0x47,0x47,0x47,0x47,0x47,0x47,
+ 0x47,0x47,0x47,0x47,0x47,0x47,0x47,0x47,0x47,0x47,0x47,0x47,0x47,0x47,0x47,0x47
+};
+#define s10 (si10+2)
+static unsigned char si10[258] = { 0x4E,0x4F,
+ 0x4A,0x4D,0x4D,0x4D,0x4D,0x4D,0x4D,0x4D,0x4D,0x4A,0x4A,0x4D,0x4D,0x4A,0x4D,0x4D,
+ 0x4D,0x4D,0x4D,0x4D,0x4D,0x4D,0x4D,0x4D,0x4D,0x4D,0x4D,0x4D,0x4D,0x4D,0x4D,0x4D,
+ 0x4A,0x4D,0x4D,0x4D,0x4D,0x4B,0x4D,0x4D,0x4B,0x4B,0x4D,0x4D,0x4D,0x4D,0x4D,0x4B,
+ 0x4C,0x4C,0x4C,0x4C,0x4C,0x4C,0x4C,0x4C,0x4C,0x4C,0x4D,0x4D,0x4B,0x4D,0x4B,0x4D,
+ 0x4D,0x4C,0x4C,0x4C,0x4C,0x4C,0x4C,0x4C,0x4C,0x4C,0x4C,0x4C,0x4C,0x4C,0x4C,0x4C,
+ 0x4C,0x4C,0x4C,0x4C,0x4C,0x4C,0x4C,0x4C,0x4C,0x4C,0x4C,0x4B,0x4D,0x4B,0x4D,0x4D,
+ 0x4D,0x4C,0x4C,0x4C,0x4C,0x4C,0x4C,0x4C,0x4C,0x4C,0x4C,0x4C,0x4C,0x4C,0x4C,0x4C,
+ 0x4C,0x4C,0x4C,0x4C,0x4C,0x4C,0x4C,0x4C,0x4C,0x4C,0x4C,0x4B,0x4D,0x4B,0x4D,0x4D,
+ 0x4D,0x4D,0x4D,0x4D,0x4D,0x4D,0x4D,0x4D,0x4D,0x4D,0x4D,0x4D,0x4D,0x4D,0x4D,0x4D,
+ 0x4D,0x4D,0x4D,0x4D,0x4D,0x4D,0x4D,0x4D,0x4D,0x4D,0x4D,0x4D,0x4D,0x4D,0x4D,0x4D,
+ 0x4D,0x4D,0x4D,0x4D,0x4D,0x4D,0x4D,0x4D,0x4D,0x4D,0x4D,0x4D,0x4D,0x4D,0x4D,0x4D,
+ 0x4D,0x4D,0x4D,0x4D,0x4D,0x4D,0x4D,0x4D,0x4D,0x4D,0x4D,0x4D,0x4D,0x4D,0x4D,0x4D,
+ 0x4D,0x4D,0x4D,0x4D,0x4D,0x4D,0x4D,0x4D,0x4D,0x4D,0x4D,0x4D,0x4D,0x4D,0x4D,0x4D,
+ 0x4D,0x4D,0x4D,0x4D,0x4D,0x4D,0x4D,0x4D,0x4D,0x4D,0x4D,0x4D,0x4D,0x4D,0x4D,0x4D,
+ 0x4D,0x4D,0x4D,0x4D,0x4D,0x4D,0x4D,0x4D,0x4D,0x4D,0x4D,0x4D,0x4D,0x4D,0x4D,0x4D,
+ 0x4D,0x4D,0x4D,0x4D,0x4D,0x4D,0x4D,0x4D,0x4D,0x4D,0x4D,0x4D,0x4D,0x4D,0x4D,0x4D
+};
+#define s11 (si11+2)
+static unsigned char si11[258] = { 0x53,0x54,
+ 0x50,0x52,0x52,0x52,0x52,0x52,0x52,0x52,0x52,0x50,0x50,0x52,0x52,0x50,0x52,0x52,
+ 0x52,0x52,0x52,0x52,0x52,0x52,0x52,0x52,0x52,0x52,0x52,0x52,0x52,0x52,0x52,0x52,
+ 0x50,0x52,0x52,0x52,0x52,0x51,0x52,0x52,0x51,0x51,0x52,0x52,0x52,0x52,0x52,0x51,
+ 0x52,0x52,0x52,0x52,0x52,0x52,0x52,0x52,0x52,0x52,0x52,0x52,0x51,0x52,0x51,0x52,
+ 0x52,0x52,0x52,0x52,0x52,0x52,0x52,0x52,0x52,0x52,0x52,0x52,0x52,0x52,0x52,0x52,
+ 0x52,0x52,0x52,0x52,0x52,0x52,0x52,0x52,0x52,0x52,0x52,0x51,0x52,0x51,0x52,0x52,
+ 0x52,0x52,0x52,0x52,0x52,0x52,0x52,0x52,0x52,0x52,0x52,0x52,0x52,0x52,0x52,0x52,
+ 0x52,0x52,0x52,0x52,0x52,0x52,0x52,0x52,0x52,0x52,0x52,0x51,0x52,0x51,0x52,0x52,
+ 0x52,0x52,0x52,0x52,0x52,0x52,0x52,0x52,0x52,0x52,0x52,0x52,0x52,0x52,0x52,0x52,
+ 0x52,0x52,0x52,0x52,0x52,0x52,0x52,0x52,0x52,0x52,0x52,0x52,0x52,0x52,0x52,0x52,
+ 0x52,0x52,0x52,0x52,0x52,0x52,0x52,0x52,0x52,0x52,0x52,0x52,0x52,0x52,0x52,0x52,
+ 0x52,0x52,0x52,0x52,0x52,0x52,0x52,0x52,0x52,0x52,0x52,0x52,0x52,0x52,0x52,0x52,
+ 0x52,0x52,0x52,0x52,0x52,0x52,0x52,0x52,0x52,0x52,0x52,0x52,0x52,0x52,0x52,0x52,
+ 0x52,0x52,0x52,0x52,0x52,0x52,0x52,0x52,0x52,0x52,0x52,0x52,0x52,0x52,0x52,0x52,
+ 0x52,0x52,0x52,0x52,0x52,0x52,0x52,0x52,0x52,0x52,0x52,0x52,0x52,0x52,0x52,0x52,
+ 0x52,0x52,0x52,0x52,0x52,0x52,0x52,0x52,0x52,0x52,0x52,0x52,0x52,0x52,0x52,0x52
+};
+/*
+ * Class Action Table --
+ *
+ *   The entries in the Class Action Table indicate the
+ *   action routine to be called, and the next state to
+ *   enter, for each relevant character class in each.
+ *   state. There are several entries for each state.
+ *
+ */
+static int AAH_NAME();
+static int BREAK_SIGNAL();
+static int HEX_STRING();
+static int IMMED_NAME();
+static int INTEGER();
+static int LEFT_BRACE();
+static int LEFT_BRACKET();
+static int LITERAL_NAME();
+static int NAME();
+static int NO_TOKEN();
+static int OOPS_NAME();
+static int RADIX_NUMBER();
+static int REAL();
+static int RIGHT_ANGLE();
+static int RIGHT_BRACE();
+static int RIGHT_BRACKET();
+static int RIGHT_PAREN();
+static int STRING();
+static int add_1st_decpt();
+static int add_1st_digits();
+static int add_char();
+static int add_decpt();
+static int add_digits();
+static int add_e_sign();
+static int add_exponent();
+static int add_fraction();
+static int add_r_digits();
+static int add_radix();
+static int add_sign();
+static int next_char();
+static int skip_comment();
+static int skip_space();
+static struct cat {
+  int (*actionRoutineP)();
+  unsigned char *nextStateP;
+} classActionTable[] = {
+  /* s0:  Classify initial character */
+  /* 00 ALPHA          */ {NAME,           s0},  /* executable name */
+  /* 01 DIGIT          */ {add_1st_digits, s3},  /* number? */
+  /* 02 WHITE_SPACE    */ {skip_space,     s0},  /* skip white space */
+  /* 03 PERCENT        */ {skip_comment,   s0},  /* comment? */
+  /* 04 SLASH          */ {next_char,      s1},  /* literal or imm name */
+  /* 05 LEFT_PAREN     */ {STRING,         s0},  /* string */
+  /* 06 LEFT_BRACE     */ {LEFT_BRACE,     s0},  /* begin procedure body */
+  /* 07 LEFT_BRACKET   */ {LEFT_BRACKET,   s0},  /* begin array */
+  /* 08 LEFT_ANGLE     */ {HEX_STRING,     s0},  /* hex string? */
+  /* 09 RIGHT_BRACE    */ {RIGHT_BRACE,    s0},  /* end procedure body */
+  /* 0A RIGHT_BRACKET  */ {RIGHT_BRACKET,  s0},  /* end array */
+  /* 0B RIGHT_PAREN    */ {RIGHT_PAREN,    s0},  /* unmatched right paren */
+  /* 0C RIGHT_ANGLE    */ {RIGHT_ANGLE,    s0},  /* unmatched right angle */
+  /* 0D SIGN           */ {add_sign,       s2},  /* signed number? */
+  /* 0E DECIMAL_POINT  */ {add_1st_decpt,  s4},  /* real number? */
+  /* 0F ANY            */ {NAME,           s0},  /* executable name */
+  /* 10 BREAK          */ {BREAK_SIGNAL,   s0},  /* break signalled */
+  /* 11 EOF            */ {NO_TOKEN,       s0},  /* no token found */
+  /* s1:  Further classify a '/' */
+  /* 12 SLASH          */ {IMMED_NAME,     s0},  /* immediate name */
+  /* 13 ANY            */ {LITERAL_NAME,   s0},  /* literal name */
+  /* 14 BREAK          */ {BREAK_SIGNAL,   s0},  /* break signalled */
+  /* 15 EOF            */ {OOPS_NAME,      s0},  /* isolated sign */
+  /* s2:  sign */
+  /* 16 WHITE_SPACE    */ {OOPS_NAME,      s0},  /* isolated sign */
+  /* 17 SPECIAL        */ {OOPS_NAME,      s0},  /* isolated sign */
+  /* 18 DIGIT          */ {add_digits,     s3},  /* number? */
+  /* 19 DECIMAL_POINT  */ {add_decpt,      s4},  /* real number? */
+  /* 1A ANY            */ {NAME,           s0},  /* executable name */
+  /* 1B BREAK          */ {BREAK_SIGNAL,   s0},  /* break signalled */
+  /* 1C EOF            */ {OOPS_NAME,      s0},  /* isolated sign */
+  /* s3:  sign? digit+ */
+  /* 1D WHITE_SPACE    */ {INTEGER,        s0},  /* n-digit integer */
+  /* 1E SPECIAL        */ {INTEGER,        s0},  /* n-digit integer */
+  /* 1F DECIMAL_POINT  */ {add_char,       s5},  /* real number? */
+  /* 20 POUND          */ {add_radix,      s10}, /* radix number? */
+  /* 21 eE             */ {add_char,       s7},  /* real with exponent? */
+  /* 22 ANY            */ {AAH_NAME,       s0},  /* executable name */
+  /* 23 BREAK          */ {BREAK_SIGNAL,   s0},  /* break signalled */
+  /* 24 EOF            */ {INTEGER,        s0},  /* n-digit integer */
+  /* s4:  sign? . */
+  /* 25 WHITE_SPACE    */ {OOPS_NAME,      s0},  /* isolated +. or -. */
+  /* 26 SPECIAL        */ {OOPS_NAME,      s0},  /* isolated +. or -. */
+  /* 27 DIGIT          */ {add_fraction,   s6},  /* number? */
+  /* 28 ANY            */ {NAME,           s0},  /* executable name */
+  /* 29 BREAK          */ {BREAK_SIGNAL,   s0},  /* break signalled */
+  /* 2A EOF            */ {OOPS_NAME,      s0},  /* isolated +. or -. */
+  /* s5:  sign? digit+ . */
+  /* 2B WHITE_SPACE    */ {REAL,           s0},  /* real with fraction */
+  /* 2C SPECIAL        */ {REAL,           s0},  /* real with fraction */
+  /* 2D eE             */ {add_char,       s7},  /* real with exponent? */
+  /* 2E DIGIT          */ {add_fraction,   s6},  /* number? */
+  /* 2F ANY            */ {AAH_NAME,       s0},  /* executable name */
+  /* 30 BREAK          */ {BREAK_SIGNAL,   s0},  /* break signalled */
+  /* 31 EOF            */ {REAL,           s0},  /* real with fraction */
+  /* s6:  sign? (digit+ . digit+) | (. digit+) */
+  /* 32 WHITE_SPACE    */ {REAL,           s0},  /* real with fraction */
+  /* 33 SPECIAL        */ {REAL,           s0},  /* real with fraction */
+  /* 34 eE             */ {add_char,       s7},  /* real with exponent? */
+  /* 35 ANY            */ {AAH_NAME,       s0},  /* executable name */
+  /* 36 BREAK          */ {BREAK_SIGNAL,   s0},  /* break signalled */
+  /* 37 EOF            */ {REAL,           s0},  /* real with fraction */
+  /* s7:  sign? ((digit+ (. digit*)?) | (. digit+)) Ee */
+  /* 38 WHITE_SPACE    */ {OOPS_NAME,      s0},  /* invalid real number */
+  /* 39 SPECIAL        */ {OOPS_NAME,      s0},  /* invalid real number */
+  /* 3A SIGN           */ {add_e_sign,     s8},  /* real w signed exponent? */
+  /* 3B DIGIT          */ {add_exponent,   s9},  /* real w exponent ? */
+  /* 3C ANY            */ {AAH_NAME,       s0},  /* executable name */
+  /* 3D BREAK          */ {BREAK_SIGNAL,   s0},  /* break signalled */
+  /* 3E EOF            */ {OOPS_NAME,      s0},  /* invalid real number */
+  /* s8:  sign? (digit+ (. digit*)? | (digit* . digit+) Ee sign */
+  /* 3F WHITE_SPACE    */ {OOPS_NAME,      s0},  /* invalid real number */
+  /* 40 SPECIAL        */ {OOPS_NAME,      s0},  /* invalid real number */
+  /* 41 DIGIT          */ {add_exponent,   s9},  /* real w exponent? */
+  /* 42 ANY            */ {AAH_NAME,       s0},  /* executable name */
+  /* 43 BREAK          */ {BREAK_SIGNAL,   s0},  /* break signalled */
+  /* 44 EOF            */ {OOPS_NAME,      s0},  /* invalid real number */
+  /* s9:  sign? (digit+ (. digit*)? | (digit* . digit+) Ee sign? digit+ */
+  /* 45 WHITE_SPACE    */ {REAL,           s0},  /* real w exponent */
+  /* 46 SPECIAL        */ {REAL,           s0},  /* real w exponent */
+  /* 47 ANY            */ {AAH_NAME,       s0},  /* executable name */
+  /* 48 BREAK          */ {BREAK_SIGNAL,   s0},  /* break signalled */
+  /* 49 EOF            */ {REAL,           s0},  /* real w exponent */
+  /* s10: digit+ # */
+  /* 4A WHITE_SPACE    */ {OOPS_NAME,      s0},  /* invalid radix number */
+  /* 4B SPECIAL        */ {OOPS_NAME,      s0},  /* invalid radix number */
+  /* 4C R_DIGIT        */ {add_r_digits,   s11}, /* radix number? */
+  /* 4D ANY            */ {AAH_NAME,       s0},  /* executable name */
+  /* 4E BREAK          */ {BREAK_SIGNAL,   s0},  /* break signalled */
+  /* 4F EOF            */ {OOPS_NAME,      s0},  /* invalid radix number */
+  /* s11: digit+ # r_digit+ */
+  /* 50 WHITE_SPACE    */ {RADIX_NUMBER,   s0},  /* radix number */
+  /* 51 SPECIAL        */ {RADIX_NUMBER,   s0},  /* radix number */
+  /* 52 ANY            */ {AAH_NAME,       s0},  /* executable name */
+  /* 53 BREAK          */ {BREAK_SIGNAL,   s0},  /* break signalled */
+  /* 54 EOF            */ {RADIX_NUMBER,   s0}   /* radix number */
+};
+/*
+ * Character Classification Tables --
+ *
+ *   The entries in the Character Classification Tables
+ *   map character codes to character classes.  The
+ *   tables contains one entry per code.  The bits in
+ *   each entry indicate which classes the character
+ *   code belongs to.
+ *
+ *   The macros 'isInCLASS(ch)' generate code to test
+ *   whether 'ch' is a character in 'CLASS'.
+ *
+ */
+/* Membership macros for classes defined in table 1 ... */
+#define isRADIX_DIGIT(c)    ((isInP1[c] & 0x80) != 0)
+#define isHEX_DIGIT(c)      ((isInP1[c] & 0x40) != 0)
+#define isDECIMAL_DIGIT(c)  ((isInP1[c] & 0x10) != 0)
+#define isOCTAL_DIGIT(c)    ((isInP1[c] & 0x20) != 0)
+/* Membership macros for classes defined in table 2 ... */
+#define isWHITE_SPACE(c)    ((isInP2[c] & 0x80) != 0)
+#define isCOMMENT(c)        ((isInP2[c] & 0x40) != 0)
+#define isNAME(c)           ((isInP2[c] & 0x20) != 0)
+#define isSTRING_SPECIAL(c) ((isInP2[c] & 0x10) != 0)
+#define isNUMBER_ENDER(c)   ((isInP2[c] & 0x08) != 0)
+#define isInP1 (isInT1+2)
+static unsigned char isInT1[258] = { 0x00,0x00,
+ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+ 0xF0,0xF0,0xF0,0xF0,0xF0,0xF0,0xF0,0xF0,0xD0,0xD0,0x00,0x00,0x00,0x00,0x00,0x00,
+ 0x00,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,
+ 0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x00,0x00,
+ 0x00,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,
+ 0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x00,0x00,
+ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
+};
+#define isInP2 (isInT2+2)
+static unsigned char isInT2[258] = { 0x18,0x18,
+ 0xC8,0x60,0x60,0x60,0x60,0x60,0x60,0x60,0x60,0xC8,0x88,0x60,0x60,0x98,0x60,0x60,
+ 0x60,0x60,0x60,0x60,0x60,0x60,0x60,0x60,0x60,0x60,0x60,0x60,0x60,0x60,0x60,0x60,
+ 0xC8,0x60,0x60,0x60,0x60,0x48,0x60,0x60,0x58,0x58,0x60,0x60,0x60,0x60,0x60,0x48,
+ 0x60,0x60,0x60,0x60,0x60,0x60,0x60,0x60,0x60,0x60,0x60,0x60,0x48,0x60,0x48,0x60,
+ 0x60,0x60,0x60,0x60,0x60,0x60,0x60,0x60,0x60,0x60,0x60,0x60,0x60,0x60,0x60,0x60,
+ 0x60,0x60,0x60,0x60,0x60,0x60,0x60,0x60,0x60,0x60,0x60,0x48,0x70,0x48,0x60,0x60,
+ 0x60,0x60,0x60,0x60,0x60,0x60,0x60,0x60,0x60,0x60,0x60,0x60,0x60,0x60,0x60,0x60,
+ 0x60,0x60,0x60,0x60,0x60,0x60,0x60,0x60,0x60,0x60,0x60,0x48,0x60,0x48,0x60,0x60,
+ 0x60,0x60,0x60,0x60,0x60,0x60,0x60,0x60,0x60,0x60,0x60,0x60,0x60,0x60,0x60,0x60,
+ 0x60,0x60,0x60,0x60,0x60,0x60,0x60,0x60,0x60,0x60,0x60,0x60,0x60,0x60,0x60,0x60,
+ 0x60,0x60,0x60,0x60,0x60,0x60,0x60,0x60,0x60,0x60,0x60,0x60,0x60,0x60,0x60,0x60,
+ 0x60,0x60,0x60,0x60,0x60,0x60,0x60,0x60,0x60,0x60,0x60,0x60,0x60,0x60,0x60,0x60,
+ 0x60,0x60,0x60,0x60,0x60,0x60,0x60,0x60,0x60,0x60,0x60,0x60,0x60,0x60,0x60,0x60,
+ 0x60,0x60,0x60,0x60,0x60,0x60,0x60,0x60,0x60,0x60,0x60,0x60,0x60,0x60,0x60,0x60,
+ 0x60,0x60,0x60,0x60,0x60,0x60,0x60,0x60,0x60,0x60,0x60,0x60,0x60,0x60,0x60,0x60,
+ 0x60,0x60,0x60,0x60,0x60,0x60,0x60,0x60,0x60,0x60,0x60,0x60,0x60,0x60,0x60,0x60
+};
+#endif
diff --git a/Xserver/lib/font/Type1/trig.h b/Xserver/lib/font/Type1/trig.h
new file mode 100644 (file)
index 0000000..3b0577c
--- /dev/null
@@ -0,0 +1,35 @@
+/* $XConsortium: trig.h,v 1.2 91/10/10 11:20:04 rws Exp $ */
+/* Copyright International Business Machines,Corp. 1991
+ * All Rights Reserved
+ *
+ * License to use, copy, modify, and distribute this software
+ * and its documentation for any purpose and without fee is
+ * hereby granted, provided that the above copyright notice
+ * appear in all copies and that both that copyright notice and
+ * this permission notice appear in supporting documentation,
+ * and that the name of IBM not be used in advertising or
+ * publicity pertaining to distribution of the software without
+ * specific, written prior permission.
+ *
+ * IBM PROVIDES THIS SOFTWARE "AS IS", WITHOUT ANY WARRANTIES
+ * OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING, BUT NOT
+ * LIMITED TO ANY IMPLIED WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, AND NONINFRINGEMENT OF
+ * THIRD PARTY RIGHTS.  THE ENTIRE RISK AS TO THE QUALITY AND
+ * PERFORMANCE OF THE SOFTWARE, INCLUDING ANY DUTY TO SUPPORT
+ * OR MAINTAIN, BELONGS TO THE LICENSEE.  SHOULD ANY PORTION OF
+ * THE SOFTWARE PROVE DEFECTIVE, THE LICENSEE (NOT IBM) ASSUMES
+ * THE ENTIRE COST OF ALL SERVICING, REPAIR AND CORRECTION.  IN
+ * NO EVENT SHALL IBM BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
+ * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
+ * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
+ * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+ */
+/*SHARED*/
+#define   DegreeCos(d)    xiStub()
+#define   DegreeSin(d)    xiStub()
+#define   sqrt(d)         xiStub()
diff --git a/Xserver/lib/font/Type1/type1.c b/Xserver/lib/font/Type1/type1.c
new file mode 100644 (file)
index 0000000..92d6d8c
--- /dev/null
@@ -0,0 +1,1776 @@
+/* $XConsortium: type1.c,v 1.7 94/02/07 15:30:22 gildea Exp $ */
+/* Copyright International Business Machines, Corp. 1991
+ * All Rights Reserved
+ * Copyright Lexmark International, Inc. 1991
+ * All Rights Reserved
+ * Portions Copyright (c) 1990 Adobe Systems Incorporated.
+ * All Rights Reserved
+ *
+ * License to use, copy, modify, and distribute this software and its
+ * documentation for any purpose and without fee is hereby granted,
+ * provided that the above copyright notice appear in all copies and that
+ * both that copyright notice and this permission notice appear in
+ * supporting documentation, and that the name of IBM or Lexmark or Adobe
+ * not be used in advertising or publicity pertaining to distribution of
+ * the software without specific, written prior permission.
+ *
+ * IBM, LEXMARK, AND ADOBE PROVIDE THIS SOFTWARE "AS IS", WITHOUT ANY
+ * WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING, BUT NOT
+ * LIMITED TO ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
+ * PARTICULAR PURPOSE, AND NONINFRINGEMENT OF THIRD PARTY RIGHTS.  THE
+ * ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE SOFTWARE, INCLUDING
+ * ANY DUTY TO SUPPORT OR MAINTAIN, BELONGS TO THE LICENSEE.  SHOULD ANY
+ * PORTION OF THE SOFTWARE PROVE DEFECTIVE, THE LICENSEE (NOT IBM,
+ * LEXMARK, OR ADOBE) ASSUMES THE ENTIRE COST OF ALL SERVICING, REPAIR AND
+ * CORRECTION.  IN NO EVENT SHALL IBM, LEXMARK, OR ADOBE BE LIABLE FOR ANY
+ * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
+ * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
+ * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
+ * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+/*********************************************************************/
+/*                                                                   */
+/* Type 1 module - Converting fonts in Adobe Type 1 Font Format      */
+/*                 to scaled and hinted paths for rasterization.     */
+/*                 Files: type1.c, type1.h, and blues.h.             */
+/*                                                                   */
+/* Authors:   Sten F. Andler, IBM Almaden Research Center            */
+/*                 (Type 1 interpreter, stem & flex hints)           */
+/*                                                                   */
+/*            Patrick A. Casey, Lexmark International, Inc.          */
+/*                 (Font level hints & stem hints)                   */
+/*                                                                   */
+/*********************************************************************/
+/******************/
+/* Include Files: */
+/******************/
+#include  <stdio.h>          /* a system-dependent include, usually */
+#include  "objects.h"
+#include  "spaces.h"
+#include  "paths.h"
+#include  "fonts.h"        /* understands about TEXTTYPEs */
+#include  "pictures.h"     /* understands about handles */
+typedef struct xobject xobject;
+#include  "util.h"       /* PostScript objects */
+#include  "blues.h"          /* Blues structure for font-level hints */
+/**********************************/
+/* Type1 Constants and Structures */
+/**********************************/
+#define MAXSTACK 24        /* Adobe Type1 limit */
+#define MAXCALLSTACK 10    /* Adobe Type1 limit */
+#define MAXPSFAKESTACK 32  /* Max depth of fake PostScript stack (local) */
+#define MAXSTRLEN 512      /* Max length of a Type 1 string (local) */
+#define MAXLABEL 256       /* Maximum number of new hints */
+#define MAXSTEMS 128       /* Maximum number of VSTEM and HSTEM hints */
+#define EPS 0.001          /* Small number for comparisons */
+/************************************/
+/* Adobe Type 1 CharString commands */
+/************************************/
+#define HSTEM        1
+#define VSTEM        3
+#define VMOVETO      4
+#define RLINETO      5
+#define HLINETO      6
+#define VLINETO      7
+#define RRCURVETO    8
+#define CLOSEPATH    9
+#define CALLSUBR    10
+#define RETURN      11
+#define ESCAPE      12
+#define HSBW        13
+#define ENDCHAR     14
+#define RMOVETO     21
+#define HMOVETO     22
+#define VHCURVETO   30
+#define HVCURVETO   31
+/*******************************************/
+/* Adobe Type 1 CharString Escape commands */
+/*******************************************/
+#define DOTSECTION       0
+#define VSTEM3           1
+#define HSTEM3           2
+#define SEAC             6
+#define SBW              7
+#define DIV             12
+#define CALLOTHERSUBR   16
+#define POP             17
+#define SETCURRENTPOINT 33
+/*****************/
+/* Useful macros */
+/*****************/
+static double tmpx;  /* Store macro argument in tmpx to avoid re-evaluation */
+static long tmpi;    /* Store converted value in tmpi to avoid re-evaluation */
+#define FABS(x) (((tmpx = (x)) < 0.0) ? -tmpx : tmpx)
+#define CEIL(x) (((tmpi = (long) (tmpx = (x))) < tmpx) ? ++tmpi : tmpi)
+#define FLOOR(x) (((tmpi = (long) (tmpx = (x))) > tmpx) ? --tmpi : tmpi)
+#define ROUND(x) FLOOR((x) + 0.5)
+#define ODD(x) (((int)(x)) & 01)
+#define Error {errflag = TRUE; return;}
+#define ErrorRet(ret) {errflag = TRUE; return (ret);}
+#define Error0(errmsg) {IfTrace0(TRUE, errmsg); Error;}
+#define Error0Ret(errmsg, ret) {IfTrace0(TRUE, errmsg); ErrorRet(ret);}
+#define Error1(errmsg,arg) {IfTrace1(TRUE, errmsg, arg); Error;}
+/********************/
+/* global variables */
+/********************/
+struct stem {                     /* representation of a STEM hint */
+    int vertical;                 /* TRUE if vertical, FALSE otherwise */
+    double x, dx;                 /* interval of vertical stem */
+    double y, dy;                 /* interval of horizontal stem */
+    struct segment *lbhint, *lbrevhint;   /* left  or bottom hint adjustment */
+    struct segment *rthint, *rtrevhint;   /* right or top    hint adjustment */
+};
+extern struct XYspace *IDENTITY;
+static double escapementX, escapementY;
+static double sidebearingX, sidebearingY;
+static double accentoffsetX, accentoffsetY;
+static struct segment *path;
+static int errflag;
+/*************************************************/
+/* Global variables to hold Type1Char parameters */
+/*************************************************/
+static char *Environment;
+static struct XYspace *CharSpace;
+static psobj *CharStringP, *SubrsP, *OtherSubrsP;
+static int *ModeP;
+/************************/
+/* Forward declarations */
+/************************/
+static double Div();
+static double PSFakePop();
+static DoCommand();
+static Escape();
+static HStem();
+static VStem();
+static RLineTo();
+static RRCurveTo();
+static DoClosePath();
+static CallSubr();
+static Return();
+static EndChar();
+static RMoveTo();
+static DotSection();
+static Seac();
+static Sbw();
+static CallOtherSubr();
+static SetCurrentPoint();
+
+/*****************************************/
+/* statics for Flex procedures (FlxProc) */
+/*****************************************/
+static struct segment *FlxOldPath; /* save path before Flex feature */
+/******************************************************/
+/* statics for Font level hints (Blues) (see blues.h) */
+/******************************************************/
+static struct blues_struct *blues; /* the blues structure */
+static struct alignmentzone alignmentzones[MAXALIGNMENTZONES];
+static int numalignmentzones;     /* total number of alignment zones */
+/****************************************************************/
+/* Subroutines for the Font level hints (Alignment zones, etc.) */
+/****************************************************************/
+/******************************************/
+/* Fill in the alignment zone structures. */
+/******************************************/
+static ComputeAlignmentZones()
+{
+  int i;
+  double dummy, bluezonepixels, familyzonepixels;
+  struct segment *p;
+  numalignmentzones = 0;     /* initialize total # of zones */
+  /* do the BlueValues zones */
+  for (i = 0; i < blues->numBlueValues; i +=2, ++numalignmentzones) {
+    /* the 0th & 1st numbers in BlueValues are for a bottom zone */
+    /* the rest are topzones */
+    if (i == 0)           /* bottom zone */
+      alignmentzones[numalignmentzones].topzone = FALSE;
+    else                  /* top zone */
+      alignmentzones[numalignmentzones].topzone = TRUE;
+    if (i < blues->numFamilyBlues) {    /* we must consider FamilyBlues */
+      p = ILoc(CharSpace,0,blues->BlueValues[i] - blues->BlueValues[i+1]);
+      QueryLoc(p, IDENTITY, &dummy, &bluezonepixels);
+      Destroy(p);
+      p = ILoc(CharSpace,0,blues->FamilyBlues[i]-blues->FamilyBlues[i+1]);
+      QueryLoc(p, IDENTITY, &dummy, &familyzonepixels);
+      Destroy(p);
+      /* is the difference in size of the zones less than 1 pixel? */
+      if (FABS(bluezonepixels - familyzonepixels) < 1.0) {
+        /* use the Family zones */
+        alignmentzones[numalignmentzones].bottomy =
+          blues->FamilyBlues[i];
+        alignmentzones[numalignmentzones].topy =
+          blues->FamilyBlues[i+1];
+        continue;
+      }
+    }
+    /* use this font's Blue zones */
+    alignmentzones[numalignmentzones].bottomy = blues->BlueValues[i];
+    alignmentzones[numalignmentzones].topy = blues->BlueValues[i+1];
+  }
+  /* do the OtherBlues zones */
+  for (i = 0; i < blues->numOtherBlues; i +=2, ++numalignmentzones) {
+    /* all of the OtherBlues zones are bottom zones */
+    alignmentzones[numalignmentzones].topzone = FALSE;
+    if (i < blues->numFamilyOtherBlues) {/* consider FamilyOtherBlues  */
+      p = ILoc(CharSpace,0,blues->OtherBlues[i] - blues->OtherBlues[i+1]);
+      QueryLoc(p, IDENTITY, &dummy, &bluezonepixels);
+      Destroy(p);
+      p = ILoc(CharSpace,0,blues->FamilyOtherBlues[i] -
+        blues->FamilyOtherBlues[i+1]);
+      QueryLoc(p, IDENTITY, &dummy, &familyzonepixels);
+      Destroy(p);
+      /* is the difference in size of the zones less than 1 pixel? */
+      if (FABS(bluezonepixels - familyzonepixels) < 1.0) {
+        /* use the Family zones */
+        alignmentzones[numalignmentzones].bottomy =
+          blues->FamilyOtherBlues[i];
+        alignmentzones[numalignmentzones].topy =
+          blues->FamilyOtherBlues[i+1];
+        continue;
+      }
+    }
+    /* use this font's Blue zones (as opposed to the Family Blues */
+    alignmentzones[numalignmentzones].bottomy = blues->OtherBlues[i];
+    alignmentzones[numalignmentzones].topy = blues->OtherBlues[i+1];
+  }
+}
+/**********************************************************************/
+/* Subroutines and statics for handling of the VSTEM and HSTEM hints. */
+/**********************************************************************/
+static int InDotSection;             /* DotSection flag */
+static struct stem stems[MAXSTEMS];  /* All STEM hints */
+static int numstems;                 /* Number of STEM hints */
+static int currstartstem;            /* The current starting stem. */
+static int oldvert, oldhor;          /* Remember hint in effect */
+static int oldhorhalf, oldverthalf;  /* Remember which half of the stem */
+static double wsoffsetX, wsoffsetY;  /* White space offset - for VSTEM3,HSTEM3 */
+static int wsset;                    /* Flag for whether we've set wsoffsetX,Y */
+static InitStems()  /* Initialize the STEM hint data structures */
+{
+  InDotSection = FALSE;
+  currstartstem = numstems = 0;
+  oldvert = oldhor = -1;
+}
+static FinitStems()  /* Terminate the STEM hint data structures */
+{
+  int i;
+  for (i = 0; i < numstems; i++) {
+    Destroy(stems[i].lbhint);
+    Destroy(stems[i].lbrevhint);
+    Destroy(stems[i].rthint);
+    Destroy(stems[i].rtrevhint);
+  }
+}
+/*******************************************************************/
+/* Compute the dislocation that a stemhint should cause for points */
+/* inside the stem.                                                */
+/*******************************************************************/
+static ComputeStem(stemno)
+int stemno;
+{
+  int verticalondevice, idealwidth;
+  double stemstart, stemwidth;
+  struct segment *p;
+  int i;
+  double stembottom, stemtop, flatposition;
+  double Xpixels, Ypixels;
+  double unitpixels, onepixel;
+  int suppressovershoot, enforceovershoot;
+  double stemshift, flatpospixels, overshoot;
+  double widthdiff; /* Number of character space units to adjust width */
+  double lbhintvalue, rthintvalue;
+  double cxx, cyx, cxy, cyy; /* Transformation matrix */
+  int rotated; /* TRUE if character is on the side, FALSE if upright */
+  /************************************************/
+  /* DETERMINE ORIENTATION OF CHARACTER ON DEVICE */
+  /************************************************/
+  QuerySpace(CharSpace, &cxx, &cyx, &cxy, &cyy); /* Transformation matrix */
+  if (FABS(cxx) < 0.00001 || FABS(cyy) < 0.00001)
+    rotated = TRUE; /* Char is on side (90 or 270 degrees), possibly oblique. */
+  else if (FABS(cyx) < 0.00001 || FABS(cxy) < 0.00001)
+    rotated = FALSE; /* Char is upright (0 or 180 degrees), possibly oblique. */
+  else {
+    stems[stemno].lbhint = NULL; /* Char is at non-axial angle, ignore hints. */
+    stems[stemno].lbrevhint = NULL;
+    stems[stemno].rthint = NULL;
+    stems[stemno].rtrevhint = NULL;
+    return;
+  }
+  /* Determine orientation of stem */
+  if (stems[stemno].vertical) {
+    verticalondevice = !rotated;
+    stemstart = stems[stemno].x;
+    stemwidth = stems[stemno].dx;
+  } else {
+    verticalondevice = rotated;
+    stemstart = stems[stemno].y;
+    stemwidth = stems[stemno].dy;
+  }
+  /* Determine how many pixels (non-negative) correspond to 1 character space
+     unit (unitpixels), and how many character space units (non-negative)
+     correspond to one pixel (onepixel). */
+  if (stems[stemno].vertical)
+    p = ILoc(CharSpace, 1, 0);
+  else
+    p = ILoc(CharSpace, 0, 1);
+  QueryLoc(p, IDENTITY, &Xpixels, &Ypixels);
+  Destroy(p);
+  if (verticalondevice)
+    unitpixels = FABS(Xpixels);
+  else
+    unitpixels = FABS(Ypixels);
+  onepixel = 1.0 / unitpixels;
+  /**********************/
+  /* ADJUST STEM WIDTHS */
+  /**********************/
+  widthdiff = 0.0;
+  /* Find standard stem with smallest width difference from this stem */
+  if (stems[stemno].vertical) { /* vertical stem */
+    if (blues->StdVW != 0)      /* there is an entry for StdVW */
+      widthdiff = blues->StdVW - stemwidth;
+    for (i = 0; i < blues->numStemSnapV; ++i) { /* now look at StemSnapV */
+      if (blues->StemSnapV[i] - stemwidth < widthdiff)
+        /* this standard width is the best match so far for this stem */
+        widthdiff = blues->StemSnapV[i] - stemwidth;
+    }
+  } else {                      /* horizontal stem */
+    if (blues->StdHW != 0)      /* there is an entry for StdHW */
+      widthdiff = blues->StdHW - stemwidth;
+    for (i = 0; i < blues->numStemSnapH; ++i) { /* now look at StemSnapH */
+      if (blues->StemSnapH[i] - stemwidth < widthdiff)
+        /* this standard width is the best match so far for this stem */
+        widthdiff = blues->StemSnapH[i] - stemwidth;
+    }
+  }
+  /* Only expand or contract stems if they differ by less than 1 pixel from
+     the closest standard width, otherwise make the width difference = 0. */
+  if (FABS(widthdiff) > onepixel)
+    widthdiff = 0.0;
+  /* Expand or contract stem to the nearest integral number of pixels. */
+  idealwidth = ROUND((stemwidth + widthdiff) * unitpixels);
+  /* Ensure that all stems are at least one pixel wide. */
+  if (idealwidth == 0)
+    idealwidth = 1;
+  /* Apply ForceBold to vertical stems. */
+  if (blues->ForceBold && stems[stemno].vertical)
+    /* Force this vertical stem to be at least DEFAULTBOLDSTEMWIDTH wide. */
+    if (idealwidth < DEFAULTBOLDSTEMWIDTH)
+      idealwidth = DEFAULTBOLDSTEMWIDTH;
+  /* Now compute the number of character space units necessary */
+  widthdiff = idealwidth * onepixel - stemwidth;
+  /*********************************************************************/
+  /* ALIGNMENT ZONES AND OVERSHOOT SUPPRESSION - HORIZONTAL STEMS ONLY */
+  /*********************************************************************/
+  stemshift = 0.0;
+  if (!stems[stemno].vertical) {
+    /* Get bottom and top boundaries of the stem. */
+    stembottom = stemstart;
+    stemtop = stemstart + stemwidth;
+    /* Find out if this stem intersects an alignment zone (the BlueFuzz  */
+    /* entry in the Private dictionary specifies the number of character */
+    /* units to extend (in both directions) the effect of an alignment   */
+    /* zone on a horizontal stem.  The default value of BlueFuzz is 1.   */
+    for (i = 0; i < numalignmentzones; ++i) {
+      if (alignmentzones[i].topzone) {
+        if (stemtop >= alignmentzones[i].bottomy &&
+            stemtop <= alignmentzones[i].topy + blues->BlueFuzz) {
+          break; /* We found a top-zone */
+        }
+      } else {
+        if (stembottom <= alignmentzones[i].topy &&
+            stembottom >= alignmentzones[i].bottomy - blues->BlueFuzz) {
+          break; /* We found a bottom-zone */
+        }
+      }
+    }
+    if (i < numalignmentzones) { /* We found an intersecting zone (number i). */
+      suppressovershoot = FALSE;
+      enforceovershoot = FALSE;
+      /* When 1 character space unit is rendered smaller than BlueScale
+         device units (pixels), we must SUPPRESS overshoots.  Otherwise,
+         if the top (or bottom) of this stem is more than BlueShift character
+         space units away from the flat position, we must ENFORCE overshoot. */
+      if (unitpixels < blues->BlueScale)
+        suppressovershoot = TRUE;
+      else
+        if (alignmentzones[i].topzone)
+          if (stemtop >= alignmentzones[i].bottomy + blues->BlueShift)
+            enforceovershoot = TRUE;
+        else
+          if (stembottom <= alignmentzones[i].topy - blues->BlueShift)
+            enforceovershoot = TRUE;
+      /*************************************************/
+      /* ALIGN THE FLAT POSITION OF THE ALIGNMENT ZONE */
+      /*************************************************/
+      /* Compute the position of the alignment zone's flat position in
+         device space and the amount of shift needed to align it on a
+         pixel boundary. Move all stems this amount. */
+      if (alignmentzones[i].topzone)
+        flatposition = alignmentzones[i].bottomy;
+      else
+        flatposition = alignmentzones[i].topy;
+      /* Find the flat position in pixels */
+      flatpospixels = flatposition * unitpixels;
+      /* Find the stem shift necessary to align the flat
+         position on a pixel boundary, and use this shift for all stems */
+      stemshift = (ROUND(flatpospixels) - flatpospixels) * onepixel;
+      /************************************************/
+      /* HANDLE OVERSHOOT ENFORCEMENT AND SUPPRESSION */
+      /************************************************/
+      /* Compute overshoot amount (non-negative) */
+      if (alignmentzones[i].topzone)
+        overshoot = stemtop - flatposition;
+      else
+        overshoot = flatposition - stembottom;
+      if (overshoot > 0.0) {
+        /* ENFORCE overshoot by shifting the entire stem (if necessary) so that
+           it falls at least one pixel beyond the flat position. */
+        if (enforceovershoot)
+          if (overshoot < onepixel)
+            if (alignmentzones[i].topzone)
+              stemshift += onepixel - overshoot;
+            else
+              stemshift -= onepixel - overshoot;
+        /* SUPPRESS overshoot by aligning the stem to the alignment zone's
+           flat position. */
+        if (suppressovershoot)
+          if (alignmentzones[i].topzone)
+            stemshift -= overshoot;
+          else
+            stemshift += overshoot;
+      }
+      /************************************************************/
+      /* COMPUTE HINT VALUES FOR EACH SIDE OF THE HORIZONTAL STEM */
+      /************************************************************/
+      /* If the stem was aligned by a topzone, we expand or contract the stem
+         only at the bottom - since the stem top was aligned by the zone.
+         If the stem was aligned by a bottomzone, we expand or contract the stem
+         only at the top - since the stem bottom was aligned by the zone. */
+      if (alignmentzones[i].topzone) {
+        lbhintvalue = stemshift - widthdiff; /* bottom */
+        rthintvalue = stemshift;             /* top    */
+      } else {
+        lbhintvalue = stemshift;             /* bottom */
+        rthintvalue = stemshift + widthdiff; /* top    */
+      }
+      stems[stemno].lbhint    = (struct segment *)Permanent(Loc(CharSpace, 0.0,  lbhintvalue));
+      stems[stemno].lbrevhint = (struct segment *)Permanent(Loc(CharSpace, 0.0, -lbhintvalue));
+      stems[stemno].rthint    = (struct segment *)Permanent(Loc(CharSpace, 0.0,  rthintvalue));
+      stems[stemno].rtrevhint = (struct segment *)Permanent(Loc(CharSpace, 0.0, -rthintvalue));
+      return;
+    } /* endif (i < numalignmentzones) */
+    /* We didn't find any alignment zones intersecting this stem, so
+       proceed with normal stem alignment below. */
+  } /* endif (!stems[stemno].vertical) */
+  /* Align stem with pixel boundaries on device */
+  stemstart = stemstart - widthdiff / 2;
+  stemshift = ROUND(stemstart * unitpixels) * onepixel - stemstart;
+  /* Adjust the boundaries of the stem */
+  lbhintvalue = stemshift - widthdiff / 2; /* left  or bottom */
+  rthintvalue = stemshift + widthdiff / 2; /* right or top    */
+  if (stems[stemno].vertical) {
+    stems[stemno].lbhint    = (struct segment *)Permanent(Loc(CharSpace,  lbhintvalue, 0.0));
+    stems[stemno].lbrevhint = (struct segment *)Permanent(Loc(CharSpace, -lbhintvalue, 0.0));
+    stems[stemno].rthint    = (struct segment *)Permanent(Loc(CharSpace,  rthintvalue, 0.0));
+    stems[stemno].rtrevhint = (struct segment *)Permanent(Loc(CharSpace, -rthintvalue, 0.0));
+  } else {
+    stems[stemno].lbhint    = (struct segment *)Permanent(Loc(CharSpace, 0.0,  lbhintvalue));
+    stems[stemno].lbrevhint = (struct segment *)Permanent(Loc(CharSpace, 0.0, -lbhintvalue));
+    stems[stemno].rthint    = (struct segment *)Permanent(Loc(CharSpace, 0.0,  rthintvalue));
+    stems[stemno].rtrevhint = (struct segment *)Permanent(Loc(CharSpace, 0.0, -rthintvalue));
+  }
+}
+#define LEFT   1
+#define RIGHT  2
+#define BOTTOM 3
+#define TOP    4
+/*********************************************************************/
+/* Adjust a point using the given stem hint.  Use the left/bottom    */
+/* hint value or the right/top hint value depending on where the     */
+/* point lies in the stem.                                           */
+/*********************************************************************/
+static struct segment *Applyhint(p, stemnumber, half)
+struct segment *p;
+int stemnumber, half;
+{
+  if (half == LEFT || half == BOTTOM)
+    return Join(p, stems[stemnumber].lbhint); /* left  or bottom hint */
+  else
+    return Join(p, stems[stemnumber].rthint); /* right or top    hint */
+}
+/*********************************************************************/
+/* Adjust a point using the given reverse hint.  Use the left/bottom */
+/* hint value or the right/top hint value depending on where the     */
+/* point lies in the stem.                                           */
+/*********************************************************************/
+static struct segment *Applyrevhint(p, stemnumber, half)
+struct segment *p;
+int stemnumber, half;
+{
+  if (half == LEFT || half == BOTTOM)
+    return Join(p, stems[stemnumber].lbrevhint); /* left  or bottom hint */
+  else
+    return Join(p, stems[stemnumber].rtrevhint); /* right or top    hint */
+}
+/***********************************************************************/
+/* Find the vertical and horizontal stems that the current point       */
+/* (x, y) may be involved in.  At most one horizontal and one vertical */
+/* stem can apply to a single point, since there are no overlaps       */
+/* allowed.                                                            */
+/*   The actual hintvalue is returned as a location.                   */
+/* Hints are ignored inside a DotSection.                              */
+/***********************************************************************/
+static struct segment *FindStems(x, y, dx, dy)
+double x, y, dx, dy;
+{
+  int i;
+  int newvert, newhor;
+  struct segment *p;
+  int newhorhalf, newverthalf;
+  if (InDotSection) return(NULL);
+  newvert = newhor = -1;
+  newhorhalf = newverthalf = -1;
+  for (i = currstartstem; i < numstems; i++) {
+    if (stems[i].vertical) { /* VSTEM hint */
+      if ((x >= stems[i].x - EPS) &&
+          (x <= stems[i].x+stems[i].dx + EPS)) {
+        newvert = i;
+        if (dy != 0.0) {
+          if (dy < 0) newverthalf = LEFT;
+          else        newverthalf = RIGHT;
+        } else {
+          if (x < stems[i].x+stems[i].dx / 2) newverthalf = LEFT;
+          else                                newverthalf = RIGHT;
+        }
+      }
+    } else {                 /* HSTEM hint */
+      if ((y >= stems[i].y - EPS) &&
+          (y <= stems[i].y+stems[i].dy + EPS)) {
+        newhor = i;
+        if (dx != 0.0) {
+          if (dx < 0) newhorhalf = TOP;
+          else        newhorhalf = BOTTOM;
+        } else {
+          if (y < stems[i].y+stems[i].dy / 2) newhorhalf = BOTTOM;
+          else                                newhorhalf = TOP;
+        }
+      }
+    }
+  }
+  p = NULL;
+  if (newvert == -1 && oldvert == -1) ; /* Outside of any hints */
+  else if (newvert == oldvert &&
+    newverthalf == oldverthalf); /* No hint change */
+  else if (oldvert == -1) { /* New vertical hint in effect */
+    p = Applyhint(p, newvert, newverthalf);
+  } else if (newvert == -1) { /* Old vertical hint no longer in effect */
+    p = Applyrevhint(p, oldvert, oldverthalf);
+  } else { /* New vertical hint in effect, old hint no longer in effect */
+    p = Applyrevhint(p, oldvert, oldverthalf);
+    p = Applyhint(p, newvert, newverthalf);
+  }
+  if (newhor == -1 && oldhor == -1) ; /* Outside of any hints */
+  else if (newhor == oldhor &&
+    newhorhalf == oldhorhalf) ; /* No hint change */
+  else if (oldhor == -1) { /* New horizontal hint in effect */
+    p = Applyhint(p, newhor, newhorhalf);
+  } else if (newhor == -1) { /* Old horizontal hint no longer in effect */
+    p = Applyrevhint(p, oldhor, oldhorhalf);
+  }
+  else { /* New horizontal hint in effect, old hint no longer in effect */
+    p = Applyrevhint(p, oldhor, oldhorhalf);
+    p = Applyhint(p, newhor, newhorhalf);
+  }
+  oldvert = newvert; oldverthalf = newverthalf;
+  oldhor  = newhor;  oldhorhalf  = newhorhalf;
+  return p;
+}
+/******************************************************/
+/* Subroutines and statics for the Type1Char routines */
+/******************************************************/
+static int strindex; /* index into PostScript string being interpreted */
+static double currx, curry; /* accumulated x and y values for hints */
+struct callstackentry {
+  psobj *currstrP;        /* current CharStringP */
+  int currindex;          /* current strindex */
+  unsigned short currkey; /* current decryption key */
+  };
+static double Stack[MAXSTACK];
+static int Top;
+static struct callstackentry CallStack[MAXCALLSTACK];
+static int CallTop;
+static double PSFakeStack[MAXPSFAKESTACK];
+static int PSFakeTop;
+static ClearStack()
+{
+  Top = -1;
+}
+static Push(Num)
+        double Num;
+{
+  if (++Top < MAXSTACK) Stack[Top] = Num;
+  else Error0("Push: Stack full\n");
+}
+static ClearCallStack()
+{
+  CallTop = -1;
+}
+static PushCall(CurrStrP, CurrIndex, CurrKey)
+  psobj *CurrStrP;
+  int CurrIndex;
+  unsigned short CurrKey;
+{
+  if (++CallTop < MAXCALLSTACK) {
+    CallStack[CallTop].currstrP = CurrStrP;   /* save CharString pointer */
+    CallStack[CallTop].currindex = CurrIndex; /* save CharString index */
+    CallStack[CallTop].currkey = CurrKey;     /* save decryption key */
+  }
+  else Error0("PushCall: Stack full\n");
+}
+static PopCall(CurrStrPP, CurrIndexP, CurrKeyP)
+  psobj **CurrStrPP;
+  int *CurrIndexP;
+  unsigned short *CurrKeyP;
+{
+  if (CallTop >= 0) {
+    *CurrStrPP = CallStack[CallTop].currstrP; /* restore CharString pointer */
+    *CurrIndexP = CallStack[CallTop].currindex; /* restore CharString index */
+    *CurrKeyP = CallStack[CallTop--].currkey;   /* restore decryption key */
+  }
+  else Error0("PopCall: Stack empty\n");
+}
+static ClearPSFakeStack()
+{
+  PSFakeTop = -1;
+}
+/* PSFakePush: Pushes a number onto the fake PostScript stack */
+static PSFakePush(Num)
+  double Num;
+{
+  if (++PSFakeTop < MAXPSFAKESTACK) PSFakeStack[PSFakeTop] = Num;
+  else Error0("PSFakePush: Stack full\n");
+}
+/* PSFakePop: Removes a number from the top of the fake PostScript stack */
+static double PSFakePop ()
+{
+  if (PSFakeTop >= 0) return(PSFakeStack[PSFakeTop--]);
+  else Error0Ret("PSFakePop : Stack empty\n", 0.0);
+  /*NOTREACHED*/
+}
+/***********************************************************************/
+/* Center a stem on the pixel grid -- used by HStem3 and VStem3        */
+/***********************************************************************/
+static struct segment *CenterStem(edge1, edge2)
+    double edge1;
+    double edge2;
+{
+  int idealwidth, verticalondevice;
+  double leftx, lefty, rightx, righty, center, width;
+  double widthx, widthy;
+  double shift, shiftx, shifty;
+  double Xpixels, Ypixels;
+  struct segment *p;
+  p = Loc(CharSpace, edge1, 0.0);
+  QueryLoc(p, IDENTITY, &leftx, &lefty);
+  p = Join(p, Loc(CharSpace, edge2, 0.0));
+  QueryLoc(p, IDENTITY, &rightx, &righty);
+  Destroy(p);
+  widthx = FABS(rightx - leftx);
+  widthy = FABS(righty - lefty);
+  if (widthy <= EPS) { /* verticalondevice hint */
+    verticalondevice = TRUE;
+    center = (rightx + leftx) / 2.0;
+    width = widthx;
+  }
+  else if (widthx <= EPS) { /* horizontal hint */
+    verticalondevice = FALSE;
+    center = (righty + lefty) / 2.0;
+    width = widthy;
+  }
+  else { /* neither horizontal nor verticalondevice and not oblique */
+    return (NULL);
+  }
+  idealwidth = ROUND(width);
+  if (idealwidth == 0) idealwidth = 1;
+  if (ODD(idealwidth)) {       /* is ideal width odd? */
+    /* center stem over pixel */
+    shift = FLOOR(center) + 0.5 - center;
+  }
+  else {
+    /* align stem on pixel boundary */
+    shift = ROUND(center) - center;
+  }
+  if (verticalondevice) {
+    shiftx = shift;
+    shifty = 0.0;
+  } else {
+    shifty = shift;
+    shiftx = 0.0;
+  }
+  p = Loc(IDENTITY, shiftx, shifty);
+  QueryLoc(p, CharSpace, &Xpixels, &Ypixels);
+  wsoffsetX = Xpixels; wsoffsetY = Ypixels;
+  currx += wsoffsetX; curry += wsoffsetY;
+  return (p);
+}
+/*-----------------------------------------------------------------------
+  Decrypt - From Adobe Type 1 book page 63, with some modifications
+-----------------------------------------------------------------------*/
+#define KEY 4330 /* Initial key (seed) for CharStrings decryption */
+#define C1 52845 /* Multiplier for pseudo-random number generator */
+#define C2 22719 /* Constant for pseudo-random number generator */
+static unsigned short r; /* Pseudo-random sequence of keys */
+static unsigned char Decrypt(cipher)
+unsigned char cipher;
+{
+  unsigned char plain;
+  plain = cipher ^ (r >> 8);
+  r = (cipher + r) * C1 + C2;
+  return plain;
+}
+/* Get the next byte from the codestring being interpreted */
+static int DoRead(CodeP)
+  int *CodeP;
+{
+  if (strindex >= CharStringP->len) return(FALSE); /* end of string */
+  *CodeP = Decrypt((unsigned char) CharStringP->data.stringP[strindex++]);
+  return(TRUE);
+}
+/* Strip blues->lenIV bytes from CharString and update encryption key */
+/* (the lenIV entry in the Private dictionary specifies the number of */
+/* random bytes at the beginning of each CharString; default is 4)    */
+static void StartDecrypt()
+{
+  int Code;
+  r = KEY; /* Initial key (seed) for CharStrings decryption */
+  for (strindex = 0; strindex < blues->lenIV;)
+    if (!DoRead(&Code)) /* Read a byte and update decryption key */
+      Error0("StartDecrypt: Premature end of CharString\n");
+}
+static Decode(Code)
+  int Code;
+{
+  int Code1, Code2, Code3, Code4;
+  if (Code <= 31)                           /* Code is [0,31]    */
+    DoCommand(Code);
+  else if (Code <= 246)                     /* Code is [32,246]  */
+    Push((double)(Code - 139));
+  else if (Code <= 250) {                   /* Code is [247,250] */
+    if (!DoRead(&Code2)) goto ended;
+    Push((double)(((Code - 247) << 8) + Code2 + 108));
+  }
+  else if (Code <= 254) {                   /* Code is [251,254] */
+    if (!DoRead(&Code2)) goto ended;
+    Push((double)( -((Code - 251) << 8) - Code2 - 108));
+  }
+  else {                                    /* Code is 255 */
+    if (!DoRead(&Code1)) goto ended;
+    if (!DoRead(&Code2)) goto ended;
+    if (!DoRead(&Code3)) goto ended;
+    if (!DoRead(&Code4)) goto ended;
+    Push((double)((((((Code1<<8) + Code2)<<8) + Code3)<<8) + Code4));
+  }
+  return;
+ended: Error0("Decode: Premature end of Type 1 CharString");
+}
+/* Interpret a command code */
+static DoCommand(Code)
+  int Code;
+{
+  switch(Code) {
+    case HSTEM: /* |- y dy HSTEM |- */
+      /* Vertical range of a horizontal stem zone */
+      if (Top < 1) Error0("DoCommand: Stack low\n");
+      HStem(Stack[0], Stack[1]);
+      ClearStack();
+      break;
+    case VSTEM: /* |- x dx VSTEM |- */
+      /* Horizontal range of a vertical stem zone */
+      if (Top < 1) Error0("DoCommand: Stack low\n");
+      VStem(Stack[0], Stack[1]);
+      ClearStack();
+      break;
+    case VMOVETO: /* |- dy VMOVETO |- */
+      /* Vertical MOVETO, equivalent to 0 dy RMOVETO */
+      if (Top < 0) Error0("DoCommand: Stack low\n");
+      RMoveTo(0.0, Stack[0]);
+      ClearStack();
+      break;
+    case RLINETO: /* |- dx dy RLINETO |- */
+      /* Like RLINETO in PostScript */
+      if (Top < 1) Error0("DoCommand: Stack low\n");
+      RLineTo(Stack[0], Stack[1]);
+      ClearStack();
+      break;
+    case HLINETO: /* |- dx HLINETO |- */
+      /* Horizontal LINETO, equivalent to dx 0 RLINETO */
+      if (Top < 0) Error0("DoCommand: Stack low\n");
+      RLineTo(Stack[0], 0.0);
+      ClearStack();
+      break;
+    case VLINETO: /* |- dy VLINETO |- */
+      /* Vertical LINETO, equivalent to 0 dy RLINETO */
+      if (Top < 0) Error0("DoCommand: Stack low\n");
+      RLineTo(0.0, Stack[0]);
+      ClearStack();
+      break;
+    case RRCURVETO:
+      /* |- dx1 dy1 dx2 dy2 dx3 dy3 RRCURVETO |- */
+      /* Relative RCURVETO, equivalent to dx1 dy1 */
+      /* (dx1+dx2) (dy1+dy2) (dx1+dx2+dx3) */
+      /* (dy1+dy2+dy3) RCURVETO in PostScript */
+      if (Top < 5) Error0("DoCommand: Stack low\n");
+      RRCurveTo(Stack[0], Stack[1], Stack[2], Stack[3],
+        Stack[4], Stack[5]);
+      ClearStack();
+      break;
+    case CLOSEPATH: /* - CLOSEPATH |- */
+      /* Closes a subpath without repositioning the */
+      /* current point */
+      DoClosePath();
+      ClearStack();
+      break;
+    case CALLSUBR: /* subr# CALLSUBR - */
+      /* Calls a CharString subroutine with index */
+      /* subr# from the Subrs array */
+      if (Top < 0) Error0("DoCommand: Stack low\n");
+      CallSubr((int)Stack[Top--]);
+      break;
+    case RETURN: /* - RETURN - */
+      /* Returns from a Subrs array CharString */
+      /* subroutine called with CALLSUBR */
+      Return();
+      break;
+    case ESCAPE: /* ESCAPE to two-byte command code */
+      if (!DoRead(&Code)) Error0("DoCommand: ESCAPE is last byte\n");
+      Escape(Code);
+      break;
+    case HSBW: /* |- sbx wx HSBW |- */
+      /* Set the left sidebearing point to (sbx,0), */
+      /* set the character width vector to (wx,0). */
+      /* Equivalent to sbx 0 wx 0 SBW.  Space */
+      /* character should have sbx = 0 */
+      if (Top < 1) Error0("DoCommand: Stack low\n");
+      Sbw(Stack[0], 0.0, Stack[1], 0.0);
+      ClearStack();
+      break;
+    case ENDCHAR: /* - ENDCHAR |- */
+      /* Finishes a CharString outline */
+      EndChar();
+      ClearStack();
+      break;
+    case RMOVETO: /* |- dx dy RMOVETO |- */
+      /* Behaves like RMOVETO in PostScript */
+      if (Top < 1) Error0("DoCommand: Stack low\n");
+      RMoveTo(Stack[0], Stack[1]);
+      ClearStack();
+      break;
+    case HMOVETO: /* |- dx HMOVETO |- */
+      /* Horizontal MOVETO. Equivalent to dx 0 RMOVETO */
+      if (Top < 0) Error0("DoCommand: Stack low\n");
+      RMoveTo(Stack[0], 0.0);
+      ClearStack();
+      break;
+    case VHCURVETO: /* |- dy1 dx2 dy2 dx3 VHCURVETO |- */
+      /* Vertical-Horizontal CURVETO, equivalent to */
+      /* 0 dy1 dx2 dy2 dx3 0 RRCURVETO */
+      if (Top < 3) Error0("DoCommand: Stack low\n");
+      RRCurveTo(0.0, Stack[0], Stack[1], Stack[2],
+              Stack[3], 0.0);
+      ClearStack();
+      break;
+    case HVCURVETO: /* |- dx1 dx2 dy2 dy3 HVCURVETO |- */
+      /* Horizontal-Vertical CURVETO, equivalent to */
+      /* dx1 0 dx2 dy2 0 dy3 RRCURVETO */
+      if (Top < 3) Error0("DoCommand: Stack low\n");
+      RRCurveTo(Stack[0], 0.0, Stack[1], Stack[2], 0.0, Stack[3]);
+      ClearStack();
+      break;
+    default: /* Unassigned command code */
+      ClearStack();
+      Error1("DoCommand: Unassigned code %d\n", Code);
+  }
+}
+static Escape(Code)
+  int Code;
+{
+  int i, Num;
+  struct segment *p;
+  switch(Code) {
+    case DOTSECTION: /* - DOTSECTION |- */
+      /* Brackets an outline section for the dots in */
+      /* letters such as "i", "j", and "!". */
+      DotSection();
+      ClearStack();
+      break;
+    case VSTEM3: /* |- x0 dx0 x1 dx1 x2 dx2 VSTEM3 |- */
+      /* Declares the horizontal ranges of three */
+      /* vertical stem zones between x0 and x0+dx0, */
+      /* x1 and x1+dx1, and x2 and x2+dx2. */
+      if (Top < 5) Error0("DoCommand: Stack low\n");
+      if (!wsset && ProcessHints) {
+        /* Shift the whole character so that the middle stem is centered. */
+        p = CenterStem(Stack[2] + sidebearingX, Stack[3]);
+        path = Join(path, p);
+        wsset = 1;
+      }
+      VStem(Stack[0], Stack[1]);
+      VStem(Stack[2], Stack[3]);
+      VStem(Stack[4], Stack[5]);
+      ClearStack();
+      break;
+    case HSTEM3: /* |- y0 dy0 y1 dy1 y2 dy2 HSTEM3 |- */
+      /* Declares the vertical ranges of three hori- */
+      /* zontal stem zones between y0 and y0+dy0, */
+      /* y1 and y1+dy1, and y2 and y2+dy2. */
+      if (Top < 5) Error0("DoCommand: Stack low\n");
+      HStem(Stack[0], Stack[1]);
+      HStem(Stack[2], Stack[3]);
+      HStem(Stack[4], Stack[5]);
+      ClearStack();
+      break;
+    case SEAC: /* |- asb adx ady bchar achar SEAC |- */
+      /* Standard Encoding Accented Character. */
+      if (Top < 4) Error0("DoCommand: Stack low\n");
+      Seac(Stack[0], Stack[1], Stack[2],
+        (unsigned char) Stack[3],
+        (unsigned char) Stack[4]);
+      ClearStack();
+      break;
+    case SBW: /* |- sbx sby wx wy SBW |- */
+      /* Set the left sidebearing point to (sbx,sby), */
+      /* set the character width vector to (wx,wy). */
+      if (Top < 3) Error0("DoCommand: Stack low\n");
+      Sbw(Stack[0], Stack[1], Stack[2], Stack[3]);
+      ClearStack();
+      break;
+    case DIV: /* num1 num2 DIV quotient */
+      /* Behaves like DIV in the PostScript language */
+      if (Top < 1) Error0("DoCommand: Stack low\n");
+      Stack[Top-1] = Div(Stack[Top-1], Stack[Top]);
+      Top--;
+      break;
+    case CALLOTHERSUBR:
+      /* arg1 ... argn n othersubr# CALLOTHERSUBR - */
+      /* Make calls on the PostScript interpreter */
+      if (Top < 1) Error0("DoCommand: Stack low\n");
+      Num = Stack[Top-1];
+      if (Top < Num+1) Error0("DoCommand: Stack low\n");
+      for (i = 0; i < Num; i++) PSFakePush(Stack[Top - i - 2]);
+      Top -= Num + 2;
+      CallOtherSubr((int)Stack[Top + Num + 2]);
+      break;
+    case POP: /* - POP number */
+      /* Removes a number from the top of the */
+      /* PostScript interpreter stack and pushes it */
+      /* onto the Type 1 BuildChar operand stack */
+      Push(PSFakePop());
+      break;
+    case SETCURRENTPOINT: /* |- x y SETCURRENTPOINT |- */
+      /* Sets the current point to (x,y) in absolute */
+      /* character space coordinates without per- */
+      /* forming a CharString MOVETO command */
+      if (Top < 1) Error0("DoCommand: Stack low\n");
+      SetCurrentPoint(Stack[0], Stack[1]);
+      ClearStack();
+      break;
+    default: /* Unassigned escape code command */
+      ClearStack();
+      Error1("Escape: Unassigned code %d\n", Code);
+  }
+}
+/* |- y dy HSTEM |- */
+/* Declares the vertical range of a horizontal stem zone */
+/* between coordinates y and y + dy */
+/* y is relative to the left sidebearing point */
+static HStem(y, dy)
+  double y, dy;
+{
+  IfTrace2((FontDebug), "Hstem %f %f\n", &y, &dy);
+  if (ProcessHints) {
+    if (numstems >= MAXSTEMS) Error0("HStem: Too many hints\n");
+    if (dy < 0.0) {y += dy; dy = -dy;}
+    stems[numstems].vertical = FALSE;
+    stems[numstems].x = 0.0;
+    stems[numstems].y = sidebearingY + y + wsoffsetY;
+    stems[numstems].dx = 0.0;
+    stems[numstems].dy = dy;
+    ComputeStem(numstems);
+    numstems++;
+  }
+}
+/* |- x dx VSTEM |- */
+/* Declares the horizontal range of a vertical stem zone */
+/* between coordinates x and x + dx */
+/* x is relative to the left sidebearing point */
+static VStem(x, dx)
+  double x, dx;
+{
+  IfTrace2((FontDebug), "Vstem %f %f\n", &x, &dx);
+  if (ProcessHints) {
+    if (numstems >= MAXSTEMS) Error0("VStem: Too many hints\n");
+    if (dx < 0.0) {x += dx; dx = -dx;}
+    stems[numstems].vertical = TRUE;
+    stems[numstems].x = sidebearingX + x + wsoffsetX;
+    stems[numstems].y = 0.0;
+    stems[numstems].dx = dx;
+    stems[numstems].dy = 0.0;
+    ComputeStem(numstems);
+    numstems++;
+  }
+}
+/* |- dx dy RLINETO |- */
+/* Behaves like RLINETO in PostScript */
+static RLineTo(dx, dy)
+  double dx, dy;
+{
+  struct segment *B;
+  IfTrace2((FontDebug), "RLineTo %f %f\n", &dx, &dy);
+  B = Loc(CharSpace, dx, dy);
+  if (ProcessHints) {
+    currx += dx;
+    curry += dy;
+    /* B = Join(B, FindStems(currx, curry)); */
+    B = Join(B, FindStems(currx, curry, dx, dy));
+  }
+  path = Join(path, Line(B));
+}
+/* |- dx1 dy1 dx2 dy2 dx3 dy3 RRCURVETO |- */
+/* Relative RCURVETO, equivalent to dx1 dy1 */
+/* (dx1+dx2) (dy1+dy2) (dx1+dx2+dx3) */
+/* (dy1+dy2+dy3) RCURVETO in PostScript */
+static RRCurveTo(dx1, dy1, dx2, dy2, dx3, dy3)
+  double dx1, dy1, dx2, dy2, dx3, dy3;
+{
+  struct segment *B, *C, *D;
+  IfTrace4((FontDebug), "RRCurveTo %f %f %f %f ", &dx1, &dy1, &dx2, &dy2);
+  IfTrace2((FontDebug), "%f %f\n", &dx3, &dy3);
+  B = Loc(CharSpace, dx1, dy1);
+  C = Loc(CharSpace, dx2, dy2);
+  D = Loc(CharSpace, dx3, dy3);
+  if (ProcessHints) {
+    /* For a Bezier curve, we apply the full hint value to
+       the Bezier C point (and thereby D point). */
+    currx += dx1 + dx2 + dx3;
+    curry += dy1 + dy2 + dy3;
+    /* C = Join(C, FindStems(currx, curry)); */
+    C = Join(C, FindStems(currx, curry, dx3, dy3));
+  }
+  /* Since XIMAGER is not completely relative, */
+  /* we need to add up the delta values */
+  C = Join(C, Dup(B));
+  D = Join(D, Dup(C));
+  path = Join(path, Bezier(B, C, D));
+}
+/* - CLOSEPATH |- */
+/* Closes a subpath WITHOUT repositioning the */
+/* current point */
+static DoClosePath()
+{
+  struct segment *CurrentPoint;
+  IfTrace0((FontDebug), "DoClosePath\n");
+  CurrentPoint = Phantom(path);
+  path = ClosePath(path);
+  path = Join(Snap(path), CurrentPoint);
+}
+/* subr# CALLSUBR - */
+/* Calls a CharString subroutine with index */
+/* subr# from the Subrs array */
+static CallSubr(subrno)
+  int subrno;
+{
+  IfTrace1((FontDebug), "CallSubr %d\n", subrno);
+  if ((subrno < 0) || (subrno >= SubrsP->len))
+    Error0("CallSubr: subrno out of range\n");
+  PushCall(CharStringP, strindex, r);
+  CharStringP = &SubrsP->data.arrayP[subrno];
+  StartDecrypt();
+}
+/* - RETURN - */
+/* Returns from a Subrs array CharString */
+/* subroutine called with CALLSUBR */
+static Return()
+{
+  IfTrace0((FontDebug), "Return\n");
+  PopCall(&CharStringP, &strindex, &r);
+}
+/* - ENDCHAR |- */
+/* Finishes a CharString outline */
+/* Executes SETCHACHEDEVICE using a bounding box */
+/* it computes directly from the character outline */
+/* and using the width information acquired from a previous */
+/* HSBW or SBW.  It then calls a special version of FILL */
+/* or STROKE depending on the value of PaintType in the */
+/* font dictionary */
+static EndChar()
+{
+  IfTrace0((FontDebug), "EndChar\n");
+  /* There is no need to compute and set bounding box for
+     the cache, since XIMAGER does that on the fly. */
+  /* Perform a Closepath just in case the command was left out */
+  path = ClosePath(path);
+  /* Set character width */
+  path = Join(Snap(path), Loc(CharSpace, escapementX, escapementY));
+}
+/* |- dx dy RMOVETO |- */
+/* Behaves like RMOVETO in PostScript */
+static RMoveTo(dx,dy)
+  double dx,dy;
+{
+  struct segment *B;
+  IfTrace2((FontDebug), "RMoveTo %f %f\n", &dx, &dy);
+  B = Loc(CharSpace, dx, dy);
+  if (ProcessHints) {
+    currx += dx;
+    curry += dy;
+    /* B = Join(B, FindStems(currx, curry)); */
+    B = Join(B, FindStems(currx, curry, 0.0, 0.0));
+  }
+  path = Join(path, B);
+}
+/* - DOTSECTION |- */
+/* Brackets an outline section for the dots in */
+/* letters such as "i", "j", and "!". */
+static DotSection()
+{
+  IfTrace0((FontDebug), "DotSection\n");
+  InDotSection = !InDotSection;
+}
+/* |- asb adx ady bchar achar SEAC |- */
+/* Standard Encoding Accented Character. */
+static Seac(asb, adx, ady, bchar, achar)
+  double asb, adx, ady;
+  unsigned char bchar, achar;
+{
+  int Code;
+  struct segment *mypath;
+  IfTrace4((FontDebug), "SEAC %f %f %f %d ", &asb, &adx, &ady, bchar);
+  IfTrace1((FontDebug), "%d\n", achar);
+  /* Move adx - asb, ady over and up from base char's sbpoint. */
+  /* (We use adx - asb to counteract the accents sb shift.) */
+  /* The variables accentoffsetX/Y modify sidebearingX/Y in Sbw(). */
+  /* Note that these incorporate the base character's sidebearing shift by */
+  /* using the current sidebearingX, Y values. */
+  accentoffsetX = sidebearingX + adx - asb;
+  accentoffsetY = sidebearingY + ady;
+  /* Set path = NULL to avoid complaints from Sbw(). */
+  path = NULL;
+  /* Go find the CharString for the accent's code via an upcall */
+  CharStringP = GetType1CharString(Environment, achar);
+  StartDecrypt();
+  ClearStack();
+  ClearPSFakeStack();
+  ClearCallStack();
+  for (;;) {
+    if (!DoRead(&Code)) break;
+    Decode(Code);
+    if (errflag) return;
+  }
+  /* Copy snapped path to mypath and set path to NULL as above. */
+  mypath = Snap(path);
+  path = NULL;
+  /* We must reset these to null now. */
+  accentoffsetX = accentoffsetY = 0;
+  /* go find the CharString for the base char's code via an upcall */
+  CharStringP = GetType1CharString(Environment, bchar);
+  StartDecrypt();
+  ClearStack();
+  ClearPSFakeStack();
+  ClearCallStack();
+  FinitStems();
+  InitStems();
+  for (;;) {
+    if (!DoRead(&Code)) break;
+    Decode(Code);
+    if (errflag) return;
+  }
+  path = Join(mypath, path);
+}
+/* |- sbx sby wx wy SBW |- */
+/* Set the left sidebearing point to (sbx,sby), */
+/* set the character width vector to (wx,wy). */
+static Sbw(sbx, sby, wx, wy)
+  double sbx, sby, wx, wy;
+{
+  IfTrace4((FontDebug), "SBW %f %f %f %f\n", &sbx, &sby, &wx, &wy);
+  escapementX = wx; /* Character width vector */
+  escapementY = wy;
+  /* Sidebearing values are sbx, sby args, plus accent offset from Seac(). */
+  sidebearingX = sbx + accentoffsetX;
+  sidebearingY = sby + accentoffsetY;
+  path = Join(path, Loc(CharSpace, sidebearingX, sidebearingY));
+  if (ProcessHints) {currx = sidebearingX; curry = sidebearingY;}
+}
+ /* num1 num2 DIV quotient */
+/* Behaves like DIV in the PostScript language */
+static double Div(num1, num2)
+  double num1, num2;
+{
+  IfTrace2((FontDebug), "Div %f %f\n", &num1, &num2);
+  return(num1 / num2);
+}
+/*
+  The following four subroutines (FlxProc, FlxProc1, FlxProc2, and
+  HintReplace) are C versions of the OtherSubrs Programs, which were
+  were published in the Adobe Type 1 Font Format book.
+  The Flex outline fragment is described by
+    c1: (x0, y0) = c3: (x0, yshrink(y0)) or (xshrink(x0), y0)
+     "  (x1, y1) =  "  (x1, yshrink(y1)) or (xshrink(x1), y1)
+     "  (x2, y2) - reference point
+    c2: (x0, y0) = c4: (x0, yshrink(y0)) or (xshrink(x0), y0)
+     "  (x1, y1) =  "  (x1, yshrink(y1)) or (xshrink(x1), y1)
+     "  (x2, y2) =  "  (x2, y2), rightmost endpoint
+    c3: (x0, y0) - control point, 1st Bezier curve
+     "  (x1, y1) - control point,      -"-
+     "  (x2, y2) - end point,          -"-
+    c4: (x0, y0) - control point, 2nd Bezier curve
+     "  (x1, y1) - control point,      -"-
+     "  (x2, y2) - end point,          -"-
+    ep: (epY, epX) - final endpoint (should be same as c4: (x2, y2))
+    idmin - minimum Flex height (1/100 pixel) at which to render curves
+*/
+#define dtransform(dxusr,dyusr,dxdev,dydev) { \
+  register struct segment *point = Loc(CharSpace, dxusr, dyusr); \
+  QueryLoc(point, IDENTITY, dxdev, dydev); \
+  Destroy(point); \
+}
+#define itransform(xdev,ydev,xusr,yusr) { \
+  register struct segment *point = Loc(IDENTITY, xdev, ydev); \
+  QueryLoc(point, CharSpace, xusr, yusr); \
+  Destroy(point); \
+}
+#define transform(xusr,yusr,xdev,ydev) dtransform(xusr,yusr,xdev,ydev)
+#define PaintType (0)
+#define lineto(x,y) { \
+  struct segment *CurrentPoint; \
+  double CurrentX, CurrentY; \
+  CurrentPoint = Phantom(path); \
+  QueryLoc(CurrentPoint, CharSpace, &CurrentX, &CurrentY); \
+  Destroy(CurrentPoint); \
+  RLineTo(x - CurrentX, y - CurrentY); \
+}
+#define curveto(x0,y0,x1,y1,x2,y2) { \
+  struct segment *CurrentPoint; \
+  double CurrentX, CurrentY; \
+  CurrentPoint = Phantom(path); \
+  QueryLoc(CurrentPoint, CharSpace, &CurrentX, &CurrentY); \
+  Destroy(CurrentPoint); \
+  RRCurveTo(x0 - CurrentX, y0 - CurrentY, x1 - x0, y1 - y0, x2 - x1, y2 - y1); \
+}
+#define xshrink(x) ((x - c4x2) * shrink +c4x2)
+#define yshrink(y) ((y - c4y2) * shrink +c4y2)
+#define PickCoords(flag) \
+  if (flag) { /* Pick "shrunk" coordinates */ \
+    x0 = c1x0; y0 = c1y0; \
+    x1 = c1x1; y1 = c1y1; \
+    x2 = c1x2; y2 = c1y2; \
+    x3 = c2x0; y3 = c2y0; \
+    x4 = c2x1; y4 = c2y1; \
+    x5 = c2x2; y5 = c2y2; \
+  } else { /* Pick original coordinates */ \
+    x0 = c3x0; y0 = c3y0; \
+    x1 = c3x1; y1 = c3y1; \
+    x2 = c3x2; y2 = c3y2; \
+    x3 = c4x0; y3 = c4y0; \
+    x4 = c4x1; y4 = c4y1; \
+    x5 = c4x2; y5 = c4y2; \
+  }
+/* FlxProc() = OtherSubrs[0]; Main part of Flex          */
+/*   Calling sequence: 'idmin epX epY 3 0 callothersubr' */
+/*   Computes Flex values, and renders the Flex path,    */
+/*   and returns (leaves) ending coordinates on stack    */
+static void FlxProc(c1x2, c1y2, c3x0, c3y0, c3x1, c3y1, c3x2, c3y2,
+             c4x0, c4y0, c4x1, c4y1, c4x2, c4y2, epY, epX, idmin)
+  double c1x2, c1y2;
+  double c3x0, c3y0, c3x1, c3y1, c3x2, c3y2;
+  double c4x0, c4y0, c4x1, c4y1, c4x2, c4y2;
+  double epX, epY;
+  int idmin;
+{
+  double dmin;
+  double c1x0, c1y0, c1x1, c1y1;
+  double c2x0, c2y0, c2x1, c2y1, c2x2, c2y2;
+  char yflag;
+  double x0, y0, x1, y1, x2, y2, x3, y3, x4, y4, x5, y5;
+  double cxx, cyx, cxy, cyy; /* Transformation matrix */
+  int flipXY;
+  double x, y;
+  double erosion = 1; /* Device parameter */
+    /* Erosion may have different value specified in 'internaldict' */
+  double shrink;
+  double dX, dY;
+  char erode;
+  double eShift;
+  double cx, cy;
+  double ex, ey;
+  Destroy(path);
+  path = FlxOldPath; /* Restore previous path (stored in FlxProc1) */
+  if (ProcessHints) {
+    dmin = ABS(idmin) / 100.0; /* Minimum Flex height in pixels */
+    c2x2 = c4x2; c2y2 = c4y2; /* Point c2 = c4 */
+    yflag = FABS(c1y2 - c3y2) > FABS(c1x2 - c3x2); /* Flex horizontal? */
+    QuerySpace(CharSpace, &cxx, &cyx, &cxy, &cyy); /* Transformation matrix */
+    if (FABS(cxx) < 0.00001 || FABS(cyy) < 0.00001)
+      flipXY = -1; /* Char on side */
+    else if (FABS(cyx) < 0.00001 || FABS(cxy) < 0.00001)
+      flipXY = 1; /* Char upright */
+    else
+      flipXY = 0; /* Char at angle */
+    if (yflag) { /* Flex horizontal */
+      if (flipXY == 0 || c3y2 == c4y2) { /* Char at angle or Flex height = 0 */
+        PickCoords(FALSE); /* Pick original control points */
+      } else {
+        shrink = FABS((c1y2 - c4y2) / (c3y2 - c4y2)); /* Slope */
+        c1x0 = c3x0; c1y0 = yshrink(c3y0);
+        c1x1 = c3x1; c1y1 = yshrink(c3y1);
+        c2x0 = c4x0; c2y0 = yshrink(c4y0);
+        c2x1 = c4x1; c2y1 = yshrink(c4y1);
+        dtransform(0.0, ROUND(c3y2-c1y2), &x, &y); /* Flex height in pixels */
+        dY = FABS((flipXY == 1) ? y : x);
+        PickCoords(dY < dmin); /* If Flex small, pick 'shrunk' control points */
+        if (FABS(y2 - c1y2) > 0.001) { /* Flex 'non-zero'? */
+          transform(c1x2, c1y2, &x, &y);
+          if (flipXY == 1) {
+            cx = x; cy = y;
+          } else {
+            cx = y; cy = x;
+          }
+          dtransform(0.0, ROUND(y2-c1y2), &x, &y);
+          dY = (flipXY == 1) ? y : x;
+          if (ROUND(dY) != 0)
+            dY = ROUND(dY);
+          else
+            dY = (dY < 0) ? -1 : 1;
+          erode = PaintType != 2 && erosion >= 0.5;
+          if (erode)
+            cy -= 0.5;
+          ey = cy + dY;
+          ey = CEIL(ey) - ey + FLOOR(ey);
+          if (erode)
+            ey += 0.5;
+          if (flipXY == 1) {
+            itransform(cx, ey, &x, &y);
+          } else {
+            itransform(ey, cx, &x, &y);
+          }
+          eShift = y - y2;
+          y1 += eShift;
+          y2 += eShift;
+          y3 += eShift;
+        }
+      }
+    } else { /* Flex vertical */
+      if (flipXY == 0 || c3x2 == c4x2) { /* Char at angle or Flex height = 0 */
+        PickCoords(FALSE); /* Pick original control points */
+      } else {
+        shrink = FABS((c1x2 - c4x2) / (c3x2 - c4x2)); /* Slope */
+        c1x0 = xshrink(c3x0); c1y0 = c3y0;
+        c1x1 = xshrink(c3x1); c1y1 = c3y1;
+        c2x0 = xshrink(c4x0); c2y0 = c4y0;
+        c2x1 = xshrink(c4x1); c2y1 = c4y1;
+        dtransform(ROUND(c3x2 - c1x2), 0.0, &x, &y); /* Flex height in pixels */
+        dX = FABS((flipXY == -1) ? y : x);
+        PickCoords(dX < dmin); /* If Flex small, pick 'shrunk' control points */
+        if (FABS(x2 - c1x2) > 0.001) {
+          transform(c1x2, c1y2, &x, &y);
+          if (flipXY == -1) {
+            cx = y; cy = x;
+          } else {
+            cx = x; cy = y;
+          }
+          dtransform(ROUND(x2-c1x2), 0.0, &x, &y);
+          dX = (flipXY == -1) ? y : x;
+          if (ROUND(dX) != 0)
+            dX = ROUND(dX);
+          else
+            dX = (dX < 0) ? -1 : 1;
+          erode = PaintType != 2 && erosion >= 0.5;
+          if (erode)
+            cx -= 0.5;
+          ex = cx + dX;
+          ex = CEIL(ex) - ex + FLOOR(ex);
+          if (erode)
+            ex += 0.5;
+          if (flipXY == -1) {
+            itransform(cy, ex, &x, &y);
+          } else {
+            itransform(ex, cy, &x, &y);
+          }
+          eShift = x - x2;
+          x1 += eShift;
+          x2 += eShift;
+          x3 += eShift;
+        }
+      }
+    }
+    if (x2 == x5 || y2 == y5) {
+      lineto(x5, y5);
+    } else {
+      curveto(x0, y0, x1, y1, x2, y2);
+      curveto(x3, y3, x4, y4, x5, y5);
+    }
+  } else { /* ProcessHints is off */
+    PickCoords(FALSE); /* Pick original control points */
+    curveto(x0, y0, x1, y1, x2, y2);
+    curveto(x3, y3, x4, y4, x5, y5);
+  }
+  PSFakePush(epY);
+  PSFakePush(epX);
+}
+/* FlxProc1() = OtherSubrs[1]; Part of Flex            */
+/*   Calling sequence: '0 1 callothersubr'             */
+/*   Saves and clears path, then restores currentpoint */
+static void FlxProc1()
+{
+  struct segment *CurrentPoint;
+  CurrentPoint = Phantom(path);
+  FlxOldPath = path;
+  path = CurrentPoint;
+}
+/* FlxProc2() = OtherSubrs[2]; Part of Flex */
+/*   Calling sequence: '0 2 callothersubr'  */
+/*   Returns currentpoint on stack          */
+static void FlxProc2()
+{
+  struct segment *CurrentPoint;
+  double CurrentX, CurrentY;
+  CurrentPoint = Phantom(path);
+  QueryLoc(CurrentPoint, CharSpace, &CurrentX, &CurrentY);
+  Destroy(CurrentPoint);
+  /* Push CurrentPoint on fake PostScript stack */
+  PSFakePush(CurrentX);
+  PSFakePush(CurrentY);
+}
+/* HintReplace() = OtherSubrs[3]; Hint Replacement            */
+/*   Calling sequence: 'subr# 1 3 callothersubr pop callsubr' */
+/*   Reinitializes stem hint structure                        */
+static void HintReplace()
+{
+  /* Effectively retire the current stems, but keep them around for */
+  /* revhint use in case we are in a stem when we replace hints. */
+  currstartstem = numstems;
+  /* 'subr#' is left on PostScript stack (for 'pop callsubr') */
+}
+/* arg1 ... argn n othersubr# CALLOTHERSUBR - */
+/* Make calls on the PostScript interpreter (or call equivalent C code) */
+/* NOTE: The n arguments have been pushed on the fake PostScript stack */
+static CallOtherSubr(othersubrno)
+  int othersubrno;
+{
+  IfTrace1((FontDebug), "CallOtherSubr %d\n", othersubrno);
+  switch(othersubrno) {
+    case 0: /* OtherSubrs[0]; Main part of Flex */
+      if (PSFakeTop < 16) Error0("CallOtherSubr: PSFakeStack low");
+      ClearPSFakeStack();
+      FlxProc(
+        PSFakeStack[0],  PSFakeStack[1],  PSFakeStack[2],  PSFakeStack[3],
+        PSFakeStack[4],  PSFakeStack[5],  PSFakeStack[6],  PSFakeStack[7],
+        PSFakeStack[8],  PSFakeStack[9],  PSFakeStack[10], PSFakeStack[11],
+        PSFakeStack[12], PSFakeStack[13], PSFakeStack[14], PSFakeStack[15],
+        (int) PSFakeStack[16]
+      );
+      break;
+    case 1: /* OtherSubrs[1]; Part of Flex */
+      FlxProc1();
+      break;
+    case 2: /* OtherSubrs[2]; Part of Flex */
+      FlxProc2();
+      break;
+    case 3: /* OtherSubrs[3]; Hint Replacement */
+      HintReplace();
+      break;
+    default: { /* call OtherSubrs[4] or higher if PostScript is present */
+    }
+  }
+}
+/* |- x y SETCURRENTPOINT |- */
+/* Sets the current point to (x,y) in absolute */
+/* character space coordinates without per- */
+/* forming a CharString MOVETO command */
+static SetCurrentPoint(x, y)
+  double x, y;
+{
+  IfTrace2((FontDebug), "SetCurrentPoint %f %f\n", &x, &y);
+  currx = x;
+  curry = y;
+}
+/* The Type1Char routine for use by PostScript. */
+/************************************************/
+struct xobject *Type1Char(env, S, charstrP, subrsP, osubrsP, bluesP, modeP)
+  char *env;
+  struct XYspace *S;
+  psobj *charstrP;
+  psobj *subrsP;
+  psobj *osubrsP;
+  struct blues_struct *bluesP;  /* FontID's ptr to the blues struct */
+  int *modeP;
+{
+  int Code;
+  path = NULL;
+  errflag = FALSE;
+  /* Make parameters available to all Type1 routines */
+  Environment = env;
+  CharSpace = S; /* used when creating path elements */
+  CharStringP = charstrP;
+  SubrsP = subrsP;
+  OtherSubrsP = osubrsP;
+  ModeP = modeP;
+    blues = bluesP;
+  /* compute the alignment zones */
+  ComputeAlignmentZones();
+  StartDecrypt();
+  ClearStack();
+  ClearPSFakeStack();
+  ClearCallStack();
+  InitStems();
+  currx = curry = 0;
+  escapementX = escapementY = 0;
+  sidebearingX = sidebearingY = 0;
+  accentoffsetX = accentoffsetY = 0;
+  wsoffsetX = wsoffsetY = 0;           /* No shift to preserve whitspace. */
+  wsset = 0;                           /* wsoffsetX,Y haven't been set yet. */
+  for (;;) {
+    if (!DoRead(&Code)) break;
+    Decode(Code);
+    if (errflag) break;
+  }
+  FinitStems();
+  /* Clean up if an error has occurred */
+  if (errflag) {
+    if (path != NULL) {
+      Destroy(path); /* Reclaim storage */
+      path = NULL;   /* Indicate that character could not be built */
+    }
+  }
+  return((struct xobject *) path);
+}
diff --git a/Xserver/lib/font/Type1/util.c b/Xserver/lib/font/Type1/util.c
new file mode 100644 (file)
index 0000000..fc4c1ca
--- /dev/null
@@ -0,0 +1,195 @@
+/* $XConsortium: util.c,v 1.7 94/01/27 15:21:15 gildea Exp $ */
+/* Copyright International Business Machines,Corp. 1991
+ * All Rights Reserved
+ *
+ * License to use, copy, modify, and distribute this software
+ * and its documentation for any purpose and without fee is
+ * hereby granted, provided that the above copyright notice
+ * appear in all copies and that both that copyright notice and
+ * this permission notice appear in supporting documentation,
+ * and that the name of IBM not be used in advertising or
+ * publicity pertaining to distribution of the software without
+ * specific, written prior permission.
+ *
+ * IBM PROVIDES THIS SOFTWARE "AS IS", WITHOUT ANY WARRANTIES
+ * OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING, BUT NOT
+ * LIMITED TO ANY IMPLIED WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, AND NONINFRINGEMENT OF
+ * THIRD PARTY RIGHTS.  THE ENTIRE RISK AS TO THE QUALITY AND
+ * PERFORMANCE OF THE SOFTWARE, INCLUDING ANY DUTY TO SUPPORT
+ * OR MAINTAIN, BELONGS TO THE LICENSEE.  SHOULD ANY PORTION OF
+ * THE SOFTWARE PROVE DEFECTIVE, THE LICENSEE (NOT IBM) ASSUMES
+ * THE ENTIRE COST OF ALL SERVICING, REPAIR AND CORRECTION.  IN
+ * NO EVENT SHALL IBM BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
+ * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
+ * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
+ * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+ */
+/* Author: Katherine A. Hitchcock    IBM Almaden Research Laboratory */
+#include <stdio.h>
+#include "util.h"
+#include "fontmisc.h"
+static char *vm_base = NULL;  /* Start of virtual memory area */
+       char *vm_next = NULL;  /* Pointer to first free byte */
+       long  vm_free = 0;     /* Count of free bytes */
+       long  vm_size = 0;     /* Total size of memory */
+/*
+ * Initialize memory.
+ */
+boolean vm_init(cnt)
+int cnt;
+{
+  vm_next = vm_base = (char *)xalloc (cnt);
+  if (vm_base != NULL) {
+    vm_free = cnt;
+    vm_size = cnt;
+    return(TRUE);
+  }
+  else
+    return(FALSE);
+}
+char *vm_alloc(bytes)
+  int bytes;
+{
+  char *answer;
+  /* Round to next word multiple */
+  bytes = (bytes + 7) & ~7;
+  /* Allocate the space, if it is available */
+  if (bytes <= vm_free) {
+    answer = vm_next;
+    vm_free -= bytes;
+    vm_next += bytes;
+  }
+  else
+    answer = NULL;
+  return(answer);
+}
+/*
+ * Format an Integer object
+ */
+void objFormatInteger(objP,value)
+  psobj *objP;
+  int value;
+{
+  if (objP != NULL) {
+    objP->type         = OBJ_INTEGER;
+    objP->len          = 0;
+    objP->data.integer = value;
+  }
+}
+/*
+ * Format a Real object
+ */
+void objFormatReal(objP,value)
+  psobj *objP;
+  float value;
+{
+  if (objP != NULL) {
+    objP->type       = OBJ_REAL;
+    objP->len        = 0;
+    objP->data.real  = value;
+  }
+}
+/*
+ * Format a Boolean object
+ */
+void objFormatBoolean(objP,value)
+  psobj *objP;
+  boolean value;
+{
+  if (objP != NULL) {
+    objP->type         = OBJ_BOOLEAN;
+    objP->len          = 0;
+    objP->data.boolean = value;
+  }
+}
+/*
+ * Format an Encoding object
+ */
+void objFormatEncoding(objP,length,valueP)
+  psobj *objP;
+  int length;
+  psobj *valueP;
+{
+  if (objP != NULL) {
+    objP->type        = OBJ_ENCODING;
+    objP->len         = length;
+    objP->data.arrayP = valueP;
+  }
+}
+/*
+ * Format an Array object
+ */
+void objFormatArray(objP,length,valueP)
+  psobj *objP;
+  int length;
+  psobj *valueP;
+{
+  if (objP != NULL) {
+    objP->type        = OBJ_ARRAY;
+    objP->len         = length;
+    objP->data.arrayP = valueP;
+  }
+}
+/*
+ * Format a String object
+ */
+void objFormatString(objP,length,valueP)
+  psobj *objP;
+  int length;
+  char *valueP;
+{
+  if (objP != NULL) {
+    objP->type         = OBJ_STRING;
+    objP->len          = length;
+    objP->data.valueP  = valueP;
+  }
+}
+/*
+ * Format a Name object
+ */
+void objFormatName(objP,length,valueP)
+  psobj *objP;
+  int length;
+  char *valueP;
+{
+  if (objP != NULL) {
+    objP->type         = OBJ_NAME;
+    objP->len          = length;
+    objP->data.nameP   = valueP;
+  }
+}
+/*
+ * Format a File object
+ */
+void objFormatFile(objP,valueP)
+  psobj *objP;
+  FILE *valueP;
+{
+  if (objP != NULL) {
+    objP->type         = OBJ_FILE;
+    objP->len          = 0;
+    objP->data.fileP   = valueP;
+  }
+}
diff --git a/Xserver/lib/font/Type1/util.h b/Xserver/lib/font/Type1/util.h
new file mode 100644 (file)
index 0000000..4f727b0
--- /dev/null
@@ -0,0 +1,182 @@
+/* $XConsortium: util.h,v 1.3 92/03/26 16:42:29 eswu Exp $ */
+/* Copyright International Business Machines,Corp. 1991
+ * All Rights Reserved
+ *
+ * License to use, copy, modify, and distribute this software
+ * and its documentation for any purpose and without fee is
+ * hereby granted, provided that the above copyright notice
+ * appear in all copies and that both that copyright notice and
+ * this permission notice appear in supporting documentation,
+ * and that the name of IBM not be used in advertising or
+ * publicity pertaining to distribution of the software without
+ * specific, written prior permission.
+ *
+ * IBM PROVIDES THIS SOFTWARE "AS IS", WITHOUT ANY WARRANTIES
+ * OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING, BUT NOT
+ * LIMITED TO ANY IMPLIED WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, AND NONINFRINGEMENT OF
+ * THIRD PARTY RIGHTS.  THE ENTIRE RISK AS TO THE QUALITY AND
+ * PERFORMANCE OF THE SOFTWARE, INCLUDING ANY DUTY TO SUPPORT
+ * OR MAINTAIN, BELONGS TO THE LICENSEE.  SHOULD ANY PORTION OF
+ * THE SOFTWARE PROVE DEFECTIVE, THE LICENSEE (NOT IBM) ASSUMES
+ * THE ENTIRE COST OF ALL SERVICING, REPAIR AND CORRECTION.  IN
+ * NO EVENT SHALL IBM BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
+ * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
+ * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
+ * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+ */
+#ifndef UTIL_H
+#define UTIL_H
+#ifndef boolean
+typedef int boolean;
+#endif
+#ifndef TRUE
+#define TRUE (1)
+#endif
+#ifndef FALSE
+#define FALSE (0)
+#endif
+/***================================================================***/
+/* Portable definitions for 2's complement machines.
+ * NOTE: These really should be based on PostScript types,
+ * for example, sizeof(ps_integer), or sizeof(ps_unsigned)
+ */
+#define MAX_ULONG             (~(unsigned long)(0))
+/* This code is portable, assuming K&R C and 2's complement arithmetic */
+#define MAX_INTEGER      \
+     ((long)((((unsigned long) 1)<<(sizeof(unsigned long)*8-1))-1))
+#define MIN_INTEGER           ((-MAX_INTEGER)-1)
+#define MAX_ARRAY_CNT         (65535)
+#define MAX_DICT_CNT          (65535)
+#define MAX_STRING_LEN        (65535)
+#define MAX_NAME_LEN          (128)
+/* this is the size of memory allocated for reading fonts */
+#define VM_SIZE               (50*1024)
+/***================================================================***/
+#ifndef MIN
+#define   MIN(a,b)   (((a)<(b)) ? a : b )
+#endif
+/***================================================================***/
+/*  Routines for managing virtual memory                              */
+/***================================================================***/
+extern boolean  vm_init();
+extern long     vm_free;
+extern long     vm_size;
+extern char    *vm_next;
+extern char    *vm_alloc();
+/***================================================================***/
+/*  Macros for managing virtual memory                                */
+/***================================================================***/
+#define vm_next_byte()  (vm_next)
+#define vm_free_bytes()  (vm_free)
+#define vm_avail(B)     (B <= vm_free)
+/***================================================================***/
+/* Types of PostScript objects */
+/***================================================================***/
+#define OBJ_INTEGER    (0)
+#define OBJ_REAL       (1)
+#define OBJ_BOOLEAN    (2)
+#define OBJ_ARRAY      (3)
+#define OBJ_STRING     (4)
+#define OBJ_NAME       (5)
+#define OBJ_FILE       (6)
+#define OBJ_ENCODING   (7)
+/***================================================================***/
+/* Value of PostScript objects */
+/***================================================================***/
+typedef union ps_value {
+  char            *valueP;     /* value pointer for unspecified type */
+  int              value;      /* value for unspecified type         */
+  int              integer;    /* when type is OBJ_INTEGER           */
+  float            real;       /* when type is OBJ_REAL              */
+  int              boolean;    /* when type is OBJ_BOOLEAN           */
+  struct ps_obj   *arrayP;     /* when type is OBJ_ARRAY             */
+  unsigned char   *stringP;    /* when type is OBJ_STRING            */
+  char            *nameP;      /* when type is OBJ_NAME              */
+  FILE            *fileP;      /* when type is OBJ_FILE              */
+} psvalue;
+/***================================================================***/
+/* Definition of a PostScript object */
+/***================================================================***/
+typedef struct ps_obj {
+  char type;
+  char unused;
+  unsigned short len;
+  union ps_value data;
+} psobj;
+/***================================================================***/
+/*     Definition of a PostScript Dictionary Entry */
+/***================================================================***/
+typedef struct ps_dict {
+  psobj   key;
+  psobj   value;
+} psdict;
+/***================================================================***/
+/* Macros for testing type of PostScript objects */
+/***================================================================***/
+#define objIsInteger(o)          ((o).type == OBJ_INTEGER)
+#define objIsReal(o)             ((o).type == OBJ_REAL)
+#define objIsBoolean(o)          ((o).type == OBJ_BOOLEAN)
+#define objIsArray(o)            ((o).type == OBJ_ARRAY)
+#define objIsString(o)           ((o).type == OBJ_STRING)
+#define objIsName(o)             ((o).type == OBJ_NAME)
+#define objIsFile(o)             ((o).type == OBJ_FILE)
+/***================================================================***/
+/* Macros for setting type of PostScript objects */
+/***================================================================***/
+#define objSetInteger(o)         ((o).type = OBJ_INTEGER)
+#define objSetReal(o)            ((o).type = OBJ_REAL)
+#define objSetBoolean(o)         ((o).type = OBJ_BOOLEAN)
+#define objSetArray(o)           ((o).type = OBJ_ARRAY)
+#define objSetString(o)          ((o).type = OBJ_STRING)
+#define objSetName(o)            ((o).type = OBJ_NAME)
+#define objSetFile(o)            ((o).type = OBJ_FILE)
+/***================================================================***/
+/* Macros for testing type of PostScript objects (pointer access) */
+/***================================================================***/
+#define objPIsInteger(o)         ((o)->type == OBJ_INTEGER)
+#define objPIsReal(o)            ((o)->type == OBJ_REAL)
+#define objPIsBoolean(o)         ((o)->type == OBJ_BOOLEAN)
+#define objPIsArray(o)           ((o)->type == OBJ_ARRAY)
+#define objPIsString(o)          ((o)->type == OBJ_STRING)
+#define objPIsName(o)            ((o)->type == OBJ_NAME)
+#define objPIsFile(o)            ((o)->type == OBJ_FILE)
+/***================================================================***/
+/* Macros for setting type of PostScript objects (pointer access) */
+/***================================================================***/
+#define objPSetInteger(o)        ((o)->type = OBJ_INTEGER)
+#define objPSetReal(o)           ((o)->type = OBJ_REAL)
+#define objPSetBoolean(o)        ((o)->type = OBJ_BOOLEAN)
+#define objPSetArray(o)          ((o)->type = OBJ_ARRAY)
+#define objPSetString(o)         ((o)->type = OBJ_STRING)
+#define objPSetName(o)           ((o)->type = OBJ_NAME)
+#define objPSetFile(o)           ((o)->type = OBJ_FILE)
+/***================================================================***/
+/* Entry point for Type1Char to get entry from CharStrings            */
+/***================================================================***/
+extern psobj *GetType1CharString();
+#endif
diff --git a/Xserver/lib/font/bitmap/Imakefile b/Xserver/lib/font/bitmap/Imakefile
new file mode 100644 (file)
index 0000000..e865cfe
--- /dev/null
@@ -0,0 +1,28 @@
+XCOMM $XConsortium: Imakefile /main/9 1996/11/03 19:31:58 kaleb $
+#include <Server.tmpl>
+
+        INCLUDES = -I$(FONTINCSRC) -I../include
+         HEADERS = 
+#ifdef FontFormatDefines
+     FORMAT_DEFS = FontFormatDefines
+#endif
+#if GzipFontCompression
+       GZIP_DEFS = -DX_GZIP_FONT_COMPRESSION
+#endif
+
+            SRCS = bdfread.c bdfutils.c bitmap.c bitmaputil.c bitscale.c \
+                  bitmapfunc.c pcfread.c pcfwrite.c snfread.c \
+                  fontink.c
+
+            OBJS = bdfread.o bdfutils.o bitmap.o bitmaputil.o bitscale.o \
+                  bitmapfunc.o pcfread.o pcfwrite.o snfread.o \
+                  fontink.o
+
+SpecialCObjectRule(bitmapfunc,$(ICONFIGFILES),$(GZIP_DEFS))
+
+SubdirLibraryRule($(OBJS))
+NormalLibraryObjectRule()
+NormalLintTarget($(SRCS))
+
+DependTarget()
+
diff --git a/Xserver/lib/font/bitmap/bdfint.h b/Xserver/lib/font/bitmap/bdfint.h
new file mode 100644 (file)
index 0000000..afeffc2
--- /dev/null
@@ -0,0 +1,80 @@
+/* $XConsortium: bdfint.h,v 1.3 94/04/17 20:17:09 rws Exp $ */
+
+/*
+
+Copyright (c) 1990  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be included
+in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR
+OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall
+not be used in advertising or otherwise to promote the sale, use or
+other dealings in this Software without prior written authorization
+from the X Consortium.
+
+*/
+
+#ifndef BDFINT_H
+#define BDFINT_H
+
+#define bdfIsPrefix(buf,str)   (!strncmp((char *)buf,str,strlen(str)))
+#define        bdfStrEqual(s1,s2)      (!strcmp(s1,s2))
+
+#define        BDF_GENPROPS    6
+#define NullProperty   ((FontPropPtr)0)
+
+/*
+ * This structure holds some properties we need to generate if they aren't
+ * specified in the BDF file and some other values read from the file
+ * that we'll need to calculate them.  We need to keep track of whether
+ * or not we've read them.
+ */
+typedef struct BDFSTAT {
+    int         linenum;
+    char       *fileName;
+    char        fontName[MAXFONTNAMELEN];
+    float       pointSize;
+    int         resolution_x;
+    int         resolution_y;
+    int         digitCount;
+    int         digitWidths;
+    int         exHeight;
+
+    FontPropPtr fontProp;
+    FontPropPtr pointSizeProp;
+    FontPropPtr resolutionXProp;
+    FontPropPtr resolutionYProp;
+    FontPropPtr resolutionProp;
+    FontPropPtr xHeightProp;
+    FontPropPtr weightProp;
+    FontPropPtr quadWidthProp;
+    BOOL        haveFontAscent;
+    BOOL        haveFontDescent;
+    BOOL        haveDefaultCh;
+}           bdfFileState;
+
+extern unsigned char *bdfGetLine();
+
+extern void bdfError();
+extern void bdfWarning();
+extern Atom bdfForceMakeAtom();
+extern Atom bdfGetPropertyValue();
+extern unsigned char bdfHexByte();
+
+#endif                         /* BDFINT_H */
diff --git a/Xserver/lib/font/bitmap/bdfread.c b/Xserver/lib/font/bitmap/bdfread.c
new file mode 100644 (file)
index 0000000..9f8f260
--- /dev/null
@@ -0,0 +1,943 @@
+/* $XConsortium: bdfread.c,v 1.22 94/04/17 20:17:10 gildea Exp $ */
+
+/************************************************************************
+Copyright 1989 by Digital Equipment Corporation, Maynard, Massachusetts.
+
+                        All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and its
+documentation for any purpose and without fee is hereby granted,
+provided that the above copyright notice appear in all copies and that
+both that copyright notice and this permission notice appear in
+supporting documentation, and that the name of Digital not be
+used in advertising or publicity pertaining to distribution of the
+software without specific, written prior permission.
+
+DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
+ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
+DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
+ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+SOFTWARE.
+
+************************************************************************/
+
+/*
+
+Copyright (c) 1994  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be included
+in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR
+OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall
+not be used in advertising or otherwise to promote the sale, use or
+other dealings in this Software without prior written authorization
+from the X Consortium.
+
+*/
+
+#include <ctype.h>
+#include "fntfilst.h"
+/* use bitmap structure */
+#include "bitmap.h"
+#include "bdfint.h"
+
+#define INDICES 256
+#define MAXENCODING 0xFFFF
+#define BDFLINELEN  1024
+
+extern int  bitmapGetGlyphs(), bitmapGetMetrics();
+extern int  bitmapGetBitmaps(), bitmapGetExtents();
+void        bdfUnloadFont();
+static Bool bdfPadToTerminal();
+extern int  bdfFileLineNum;
+
+/***====================================================================***/
+
+static Bool
+bdfReadBitmap(pCI, file, bit, byte, glyph, scan, sizes)
+    CharInfoPtr pCI;
+    FontFilePtr file;
+    int         bit,
+                byte,
+                glyph,
+                scan;
+    int         sizes[GLYPHPADOPTIONS];
+{
+    int         widthBits,
+                widthBytes,
+                widthHexChars;
+    int         height,
+                row;
+    int         i,
+                inLineLen,
+                nextByte;
+    Bool        badbits;
+    unsigned char *pInBits,
+               *picture,
+               *line = NULL;
+    char        lineBuf[BDFLINELEN];
+
+    widthBits = GLYPHWIDTHPIXELS(pCI);
+    height = GLYPHHEIGHTPIXELS(pCI);
+
+    widthBytes = BYTES_PER_ROW(widthBits, glyph);
+    if (widthBytes * height > 0) {
+       picture = (unsigned char *) xalloc(widthBytes * height);
+       if (!picture)
+           goto BAILOUT;
+    } else
+       picture = NULL;
+    pCI->bits = (char *) picture;
+
+    if (sizes) {
+       for (i = 0; i < GLYPHPADOPTIONS; i++)
+           sizes[i] += BYTES_PER_ROW(widthBits, (1 << i)) * height;
+    }
+    badbits = FALSE;
+    nextByte = 0;
+    widthHexChars = BYTES_PER_ROW(widthBits, 1);
+
+/* 5/31/89 (ef) -- hack, hack, hack.  what *am* I supposed to do with */
+/*             0 width characters? */
+
+    for (row = 0; row < height; row++) {
+       line = bdfGetLine(file, lineBuf, BDFLINELEN);
+       if (!line)
+           break;
+
+       if (widthBits == 0) {
+           if ((!line) || (bdfIsPrefix(line, "ENDCHAR")))
+               break;
+           else
+               continue;
+       }
+       pInBits = line;
+       inLineLen = strlen((char *) pInBits);
+
+       if (inLineLen & 1) {
+           bdfError("odd number of characters in hex encoding\n");
+           line[inLineLen++] = '0';
+           line[inLineLen] = '\0';
+       }
+       inLineLen >>= 1;
+       i = inLineLen;
+       if (i > widthHexChars)
+           i = widthHexChars;
+       for (; i > 0; i--, pInBits += 2)
+           picture[nextByte++] = bdfHexByte(pInBits);
+
+       /* pad if line is too short */
+       if (inLineLen < widthHexChars) {
+           for (i = widthHexChars - inLineLen; i > 0; i--)
+               picture[nextByte++] = 0;
+       } else {
+           unsigned char mask;
+
+           mask = 0xff << (8 - (widthBits & 0x7));
+           if (mask && picture[nextByte - 1] & ~mask) {
+               picture[nextByte - 1] &= mask;
+               badbits = TRUE;
+           } else if (inLineLen > widthHexChars)
+               badbits = TRUE;
+       }
+
+       if (widthBytes > widthHexChars) {
+           i = widthBytes - widthHexChars;
+           while (i-- > 0)
+               picture[nextByte++] = 0;
+       }
+    }
+
+    if ((line && (!bdfIsPrefix(line, "ENDCHAR"))) || (height == 0))
+       line = bdfGetLine(file, lineBuf, BDFLINELEN);
+
+    if ((!line) || (!bdfIsPrefix(line, "ENDCHAR"))) {
+       bdfError("missing 'ENDCHAR'\n");
+       goto BAILOUT;
+    }
+    if (nextByte != height * widthBytes) {
+       bdfError("bytes != rows * bytes_per_row (%d != %d * %d)\n",
+                nextByte, height, widthBytes);
+       goto BAILOUT;
+    }
+    if (picture != NULL) {
+       if (bit == LSBFirst)
+           BitOrderInvert(picture, nextByte);
+       if (bit != byte) {
+           if (scan == 2)
+               TwoByteSwap(picture, nextByte);
+           else if (scan == 4)
+               FourByteSwap(picture, nextByte);
+       }
+    }
+    return (TRUE);
+BAILOUT:
+    if (picture)
+       xfree(picture);
+    pCI->bits = NULL;
+    return (FALSE);
+}
+
+/***====================================================================***/
+
+static Bool
+bdfSkipBitmap(file, height)
+    FontFilePtr file;
+    int         height;
+{
+    unsigned char *line;
+    int         i = 0;
+    char        lineBuf[BDFLINELEN];
+
+    do {
+       line = bdfGetLine(file, lineBuf, BDFLINELEN);
+       i++;
+    } while (line && !bdfIsPrefix(line, "ENDCHAR") && i <= height);
+
+    if (i > 1 && line && !bdfIsPrefix(line, "ENDCHAR")) {
+       bdfError("Error in bitmap, missing 'ENDCHAR'\n");
+       return (FALSE);
+    }
+    return (TRUE);
+}
+
+/***====================================================================***/
+
+
+static Bool
+bdfReadCharacters(file, pFont, pState, bit, byte, glyph, scan)
+    FontFilePtr file;
+    FontPtr     pFont;
+    bdfFileState *pState;
+    int         bit,
+                byte,
+                glyph,
+                scan;
+{
+    unsigned char *line;
+    register CharInfoPtr ci;
+    int         i,
+                ndx,
+                nchars,
+                nignored;
+    unsigned int char_row, char_col;
+    int         numEncodedGlyphs = 0;
+    CharInfoPtr *bdfEncoding[256];
+    BitmapFontPtr  bitmapFont;
+    BitmapExtraPtr bitmapExtra;
+    CARD32     *bitmapsSizes;
+    char        lineBuf[BDFLINELEN];
+    int         nencoding;
+
+    bitmapFont = (BitmapFontPtr) pFont->fontPrivate;
+    bitmapExtra = (BitmapExtraPtr) bitmapFont->bitmapExtra;
+
+    if (bitmapExtra) {
+       bitmapsSizes = bitmapExtra->bitmapsSizes;
+       for (i = 0; i < GLYPHPADOPTIONS; i++)
+           bitmapsSizes[i] = 0;
+    } else
+       bitmapsSizes = NULL;
+
+    bzero(bdfEncoding, sizeof(bdfEncoding));
+    bitmapFont->metrics = NULL;
+    ndx = 0;
+
+    line = bdfGetLine(file, lineBuf, BDFLINELEN);
+
+    if ((!line) || (sscanf((char *) line, "CHARS %d", &nchars) != 1)) {
+       bdfError("bad 'CHARS' in bdf file\n");
+       return (FALSE);
+    }
+    if (nchars < 1) {
+       bdfError("invalid number of CHARS in BDF file\n");
+       return (FALSE);
+    }
+    ci = (CharInfoPtr) xalloc(nchars * sizeof(CharInfoRec));
+    if (!ci) {
+       bdfError("Couldn't allocate pCI (%d*%d)\n", nchars,
+                sizeof(CharInfoRec));
+       goto BAILOUT;
+    }
+    bitmapFont->metrics = ci;
+
+    if (bitmapExtra) {
+       bitmapExtra->glyphNames = (Atom *) xalloc(nchars * sizeof(Atom));
+       if (!bitmapExtra->glyphNames) {
+           bdfError("Couldn't allocate glyphNames (%d*%d)\n",
+                    nchars, sizeof(Atom));
+           goto BAILOUT;
+       }
+    }
+    if (bitmapExtra) {
+       bitmapExtra->sWidths = (int *) xalloc(nchars * sizeof(int));
+       if (!bitmapExtra->sWidths) {
+           bdfError("Couldn't allocate sWidth (%d *%d)\n",
+                    nchars, sizeof(int));
+           return FALSE;
+       }
+    }
+    line = bdfGetLine(file, lineBuf, BDFLINELEN);
+    pFont->info.firstRow = 256;
+    pFont->info.lastRow = 0;
+    pFont->info.firstCol = 256;
+    pFont->info.lastCol = 0;
+    nignored = 0;
+    for (ndx = 0; (ndx < nchars) && (line) && (bdfIsPrefix(line, "STARTCHAR"));) {
+       int         t;
+       int         wx;         /* x component of width */
+       int         wy;         /* y component of width */
+       int         bw;         /* bounding-box width */
+       int         bh;         /* bounding-box height */
+       int         bl;         /* bounding-box left */
+       int         bb;         /* bounding-box bottom */
+       int         enc,
+                   enc2;       /* encoding */
+       unsigned char *p;       /* temp pointer into line */
+       char        charName[100];
+       int         ignore;
+
+       if (sscanf((char *) line, "STARTCHAR %s", charName) != 1) {
+           bdfError("bad character name in BDF file\n");
+           goto BAILOUT;       /* bottom of function, free and return error */
+       }
+       if (bitmapExtra)
+           bitmapExtra->glyphNames[ndx] = bdfForceMakeAtom(charName, NULL);
+
+       line = bdfGetLine(file, lineBuf, BDFLINELEN);
+       if (!line || (t = sscanf((char *) line, "ENCODING %d %d", &enc, &enc2)) < 1) {
+           bdfError("bad 'ENCODING' in BDF file\n");
+           goto BAILOUT;
+       }
+       if (enc < -1 || t == 2 && enc2 < -1) {
+           bdfError("bad ENCODING value");
+           goto BAILOUT;
+       }
+       if (t == 2 && enc == -1)
+           enc = enc2;
+       ignore = 0;
+       if (enc == -1) {
+           if (!bitmapExtra) {
+               nignored++;
+               ignore = 1;
+           }
+       } else if (enc > MAXENCODING) {
+           bdfError("char '%s' has encoding too large (%d)\n",
+                    charName, enc);
+       } else {
+           char_row = (enc >> 8) & 0xFF;
+           char_col = enc & 0xFF;
+           if (char_row < pFont->info.firstRow)
+               pFont->info.firstRow = char_row;
+           if (char_row > pFont->info.lastRow)
+               pFont->info.lastRow = char_row;
+           if (char_col < pFont->info.firstCol)
+               pFont->info.firstCol = char_col;
+           if (char_col > pFont->info.lastCol)
+               pFont->info.lastCol = char_col;
+           if (bdfEncoding[char_row] == (CharInfoPtr *) NULL) {
+               bdfEncoding[char_row] =
+                   (CharInfoPtr *) xalloc(256 * sizeof(CharInfoPtr));
+               if (!bdfEncoding[char_row]) {
+                   bdfError("Couldn't allocate row %d of encoding (%d*%d)\n",
+                            char_row, INDICES, sizeof(CharInfoPtr));
+                   goto BAILOUT;
+               }
+               for (i = 0; i < 256; i++)
+                   bdfEncoding[char_row][i] = (CharInfoPtr) NULL;
+           }
+           if (bdfEncoding[char_row] != NULL) {
+               bdfEncoding[char_row][char_col] = ci;
+               numEncodedGlyphs++;
+           }
+       }
+
+       line = bdfGetLine(file, lineBuf, BDFLINELEN);
+       if ((!line) || (sscanf((char *) line, "SWIDTH %d %d", &wx, &wy) != 2)) {
+           bdfError("bad 'SWIDTH'\n");
+           goto BAILOUT;
+       }
+       if (wy != 0) {
+           bdfError("SWIDTH y value must be zero\n");
+           goto BAILOUT;
+       }
+       if (bitmapExtra)
+           bitmapExtra->sWidths[ndx] = wx;
+
+/* 5/31/89 (ef) -- we should be able to ditch the character and recover */
+/*             from all of these.                                      */
+
+       line = bdfGetLine(file, lineBuf, BDFLINELEN);
+       if ((!line) || (sscanf((char *) line, "DWIDTH %d %d", &wx, &wy) != 2)) {
+           bdfError("bad 'DWIDTH'\n");
+           goto BAILOUT;
+       }
+       if (wy != 0) {
+           bdfError("DWIDTH y value must be zero\n");
+           goto BAILOUT;
+       }
+       line = bdfGetLine(file, lineBuf, BDFLINELEN);
+       if ((!line) || (sscanf((char *) line, "BBX %d %d %d %d", &bw, &bh, &bl, &bb) != 4)) {
+           bdfError("bad 'BBX'\n");
+           goto BAILOUT;
+       }
+       if ((bh < 0) || (bw < 0)) {
+           bdfError("character '%s' has a negative sized bitmap, %dx%d\n",
+                    charName, bw, bh);
+           goto BAILOUT;
+       }
+       line = bdfGetLine(file, lineBuf, BDFLINELEN);
+       if ((line) && (bdfIsPrefix(line, "ATTRIBUTES"))) {
+           for (p = line + strlen("ATTRIBUTES ");
+                   (*p == ' ') || (*p == '\t');
+                   p++)
+                /* empty for loop */ ;
+           ci->metrics.attributes = bdfHexByte(p) << 8 + bdfHexByte(p + 2);
+           line = bdfGetLine(file, lineBuf, BDFLINELEN);
+       } else
+           ci->metrics.attributes = 0;
+
+       if (!line || !bdfIsPrefix(line, "BITMAP")) {
+           bdfError("missing 'BITMAP'\n");
+           goto BAILOUT;
+       }
+       /* collect data for generated properties */
+       if ((strlen(charName) == 1)) {
+           if ((charName[0] >= '0') && (charName[0] <= '9')) {
+               pState->digitWidths += wx;
+               pState->digitCount++;
+           } else if (charName[0] == 'x') {
+               pState->exHeight = (bh + bb) <= 0 ? bh : bh + bb;
+           }
+       }
+       if (!ignore) {
+           ci->metrics.leftSideBearing = bl;
+           ci->metrics.rightSideBearing = bl + bw;
+           ci->metrics.ascent = bh + bb;
+           ci->metrics.descent = -bb;
+           ci->metrics.characterWidth = wx;
+           ci->bits = NULL;
+           bdfReadBitmap(ci, file, bit, byte, glyph, scan, bitmapsSizes);
+           ci++;
+           ndx++;
+       } else
+           bdfSkipBitmap(file, bh);
+
+       line = bdfGetLine(file, lineBuf, BDFLINELEN);   /* get STARTCHAR or
+                                                        * ENDFONT */
+    }
+
+    if (ndx + nignored != nchars) {
+       bdfError("%d too few characters\n", nchars - (ndx + nignored));
+       goto BAILOUT;
+    }
+    nchars = ndx;
+    bitmapFont->num_chars = nchars;
+    if ((line) && (bdfIsPrefix(line, "STARTCHAR"))) {
+       bdfError("more characters than specified\n");
+       goto BAILOUT;
+    }
+    if ((!line) || (!bdfIsPrefix(line, "ENDFONT"))) {
+       bdfError("missing 'ENDFONT'\n");
+       goto BAILOUT;
+    }
+    if (numEncodedGlyphs == 0)
+       bdfWarning("No characters with valid encodings\n");
+
+    nencoding = (pFont->info.lastRow - pFont->info.firstRow + 1) *
+       (pFont->info.lastCol - pFont->info.firstCol + 1);
+    bitmapFont->encoding = (CharInfoPtr *) xalloc(nencoding * sizeof(CharInfoPtr));
+    if (!bitmapFont->encoding) {
+       bdfError("Couldn't allocate ppCI (%d,%d)\n",
+                nencoding,
+                sizeof(CharInfoPtr));
+       goto BAILOUT;
+    }
+    pFont->info.allExist = TRUE;
+    i = 0;
+    for (char_row = pFont->info.firstRow;
+           char_row <= pFont->info.lastRow;
+           char_row++) {
+       if (bdfEncoding[char_row] == (CharInfoPtr *) NULL) {
+           pFont->info.allExist = FALSE;
+           for (char_col = pFont->info.firstCol;
+                   char_col <= pFont->info.lastCol;
+                   char_col++) {
+               bitmapFont->encoding[i++] = NullCharInfo;
+           }
+       } else {
+           for (char_col = pFont->info.firstCol;
+                   char_col <= pFont->info.lastCol;
+                   char_col++) {
+               if (!bdfEncoding[char_row][char_col])
+                   pFont->info.allExist = FALSE;
+               bitmapFont->encoding[i++] = bdfEncoding[char_row][char_col];
+           }
+       }
+    }
+    for (i = 0; i < 256; i++)
+       if (bdfEncoding[i])
+           xfree(bdfEncoding[i]);
+    return (TRUE);
+BAILOUT:
+    for (i = 0; i < 256; i++)
+       if (bdfEncoding[i])
+           xfree(bdfEncoding[i]);
+    /* bdfFreeFontBits will clean up the rest */
+    return (FALSE);
+}
+
+/***====================================================================***/
+
+static Bool
+bdfReadHeader(file, pState)
+    FontFilePtr file;
+    bdfFileState *pState;
+{
+    unsigned char *line;
+    char        namebuf[BDFLINELEN];
+    char        lineBuf[BDFLINELEN];
+
+    line = bdfGetLine(file, lineBuf, BDFLINELEN);
+    if (!line || sscanf((char *) line, "STARTFONT %s", namebuf) != 1 ||
+           !bdfStrEqual(namebuf, "2.1")) {
+       bdfError("bad 'STARTFONT'\n");
+       return (FALSE);
+    }
+    line = bdfGetLine(file, lineBuf, BDFLINELEN);
+    if (!line || sscanf((char *) line, "FONT %[^\n]", pState->fontName) != 1) {
+       bdfError("bad 'FONT'\n");
+       return (FALSE);
+    }
+    line = bdfGetLine(file, lineBuf, BDFLINELEN);
+    if (!line || !bdfIsPrefix(line, "SIZE")) {
+       bdfError("missing 'SIZE'\n");
+       return (FALSE);
+    }
+    if (sscanf((char *) line, "SIZE %f%d%d", &pState->pointSize,
+              &pState->resolution_x, &pState->resolution_y) != 3) {
+       bdfError("bad 'SIZE'\n");
+       return (FALSE);
+    }
+    if (pState->pointSize < 1 ||
+       pState->resolution_x < 1 || pState->resolution_y < 1) {
+       bdfError("SIZE values must be > 0\n");
+       return (FALSE);
+    }
+    line = bdfGetLine(file, lineBuf, BDFLINELEN);
+    if (!line || !bdfIsPrefix(line, "FONTBOUNDINGBOX")) {
+       bdfError("missing 'FONTBOUNDINGBOX'\n");
+       return (FALSE);
+    }
+    return (TRUE);
+}
+
+/***====================================================================***/
+
+static Bool
+bdfReadProperties(file, pFont, pState)
+    FontFilePtr file;
+    FontPtr     pFont;
+    bdfFileState *pState;
+{
+    int         nProps, props_left,
+                nextProp;
+    char       *stringProps;
+    FontPropPtr props;
+    char        namebuf[BDFLINELEN],
+                secondbuf[BDFLINELEN],
+                thirdbuf[BDFLINELEN];
+    unsigned char *line;
+    char        lineBuf[BDFLINELEN];
+    BitmapFontPtr  bitmapFont = (BitmapFontPtr) pFont->fontPrivate;
+
+    line = bdfGetLine(file, lineBuf, BDFLINELEN);
+    if (!line || !bdfIsPrefix(line, "STARTPROPERTIES")) {
+       bdfError(file, "missing 'STARTPROPERTIES'\n");
+       return (FALSE);
+    }
+    if (sscanf((char *) line, "STARTPROPERTIES %d", &nProps) != 1) {
+       bdfError("bad 'STARTPROPERTIES'\n");
+       return (FALSE);
+    }
+    pFont->info.isStringProp = NULL;
+    pFont->info.props = NULL;
+
+    stringProps = (char *) xalloc((nProps + BDF_GENPROPS) * sizeof(char));
+    pFont->info.isStringProp = stringProps;
+    if (stringProps == NULL) {
+       bdfError("Couldn't allocate stringProps (%d*%d)\n",
+                (nProps + BDF_GENPROPS), sizeof(Bool));
+       goto BAILOUT;
+    }
+    pFont->info.props = props = (FontPropPtr) xalloc((nProps + BDF_GENPROPS) *
+                                                    sizeof(FontPropRec));
+    if (props == NULL) {
+       bdfError("Couldn't allocate props (%d*%d)\n", nProps + BDF_GENPROPS,
+                                                     sizeof(FontPropRec));
+       goto BAILOUT;
+    }
+    nextProp = 0;
+    props_left = nProps;
+    while (props_left-- > 0) {
+       line = bdfGetLine(file, lineBuf, BDFLINELEN);
+       if (line == NULL || bdfIsPrefix(line, "ENDPROPERTIES")) {
+           bdfError("\"STARTPROPERTIES %d\" followed by only %d properties\n",
+                    nProps, nProps - props_left - 1);
+           goto BAILOUT;
+       }
+       while (*line && isspace(*line))
+           line++;
+
+       switch (sscanf((char *) line, "%s%s%s", namebuf, secondbuf, thirdbuf)) {
+       default:
+           bdfError("missing '%s' parameter value\n", namebuf);
+           goto BAILOUT;
+
+       case 2:
+           /*
+            * Possibilites include: valid quoted string with no white space
+            * valid integer value invalid value
+            */
+           if (secondbuf[0] == '"') {
+               stringProps[nextProp] = TRUE;
+               props[nextProp].value =
+                   bdfGetPropertyValue(line + strlen(namebuf) + 1);
+               if (!props[nextProp].value)
+                   goto BAILOUT;
+               break;
+           } else if (bdfIsInteger(secondbuf)) {
+               stringProps[nextProp] = FALSE;
+               props[nextProp].value = atoi(secondbuf);
+               break;
+           } else {
+               bdfError("invalid '%s' parameter value\n", namebuf);
+               goto BAILOUT;
+           }
+
+       case 3:
+           /*
+            * Possibilites include: valid quoted string with some white space
+            * invalid value (reject even if second string is integer)
+            */
+           if (secondbuf[0] == '"') {
+               stringProps[nextProp] = TRUE;
+               props[nextProp].value =
+                   bdfGetPropertyValue(line + strlen(namebuf) + 1);
+               if (!props[nextProp].value)
+                   goto BAILOUT;
+               break;
+           } else {
+               bdfError("invalid '%s' parameter value\n", namebuf);
+               goto BAILOUT;
+           }
+       }
+       props[nextProp].name = bdfForceMakeAtom(namebuf, NULL);
+       if (props[nextProp].name == None) {
+           bdfError("Empty property name.\n");
+           goto BAILOUT;
+       }
+       if (!bdfSpecialProperty(pFont, &props[nextProp],
+                               stringProps[nextProp], pState))
+           nextProp++;
+    }
+
+    line = bdfGetLine(file, lineBuf, BDFLINELEN);
+    if (!line || !bdfIsPrefix(line, "ENDPROPERTIES")) {
+       bdfError("missing 'ENDPROPERTIES'\n");
+       goto BAILOUT;
+    }
+    if (!pState->haveFontAscent || !pState->haveFontDescent) {
+       bdfError("missing 'FONT_ASCENT' or 'FONT_DESCENT' properties\n");
+       goto BAILOUT;
+    }
+    if (bitmapFont->bitmapExtra) {
+       bitmapFont->bitmapExtra->info.fontAscent = pFont->info.fontAscent;
+       bitmapFont->bitmapExtra->info.fontDescent = pFont->info.fontDescent;
+    }
+    if (!pState->pointSizeProp) {
+       props[nextProp].name = bdfForceMakeAtom("POINT_SIZE", NULL);
+       props[nextProp].value = (INT32) (pState->pointSize * 10.0);
+       stringProps[nextProp] = FALSE;
+       pState->pointSizeProp = &props[nextProp];
+       nextProp++;
+    }
+    if (!pState->fontProp) {
+       props[nextProp].name = bdfForceMakeAtom("FONT", NULL);
+       props[nextProp].value = (INT32) bdfForceMakeAtom(pState->fontName, NULL);
+       stringProps[nextProp] = TRUE;
+       pState->fontProp = &props[nextProp];
+       nextProp++;
+    }
+    if (!pState->weightProp) {
+       props[nextProp].name = bdfForceMakeAtom("WEIGHT", NULL);
+       props[nextProp].value = -1;     /* computed later */
+       stringProps[nextProp] = FALSE;
+       pState->weightProp = &props[nextProp];
+       nextProp++;
+    }
+    if (!pState->resolutionProp &&
+       pState->resolution_x == pState->resolution_y) {
+       props[nextProp].name = bdfForceMakeAtom("RESOLUTION", NULL);
+       props[nextProp].value = (INT32) ((pState->resolution_x * 100.0) / 72.27);
+       stringProps[nextProp] = FALSE;
+       pState->resolutionProp = &props[nextProp];
+       nextProp++;
+    }
+    if (!pState->resolutionXProp) {
+       props[nextProp].name = bdfForceMakeAtom("RESOLUTION_X", NULL);
+       props[nextProp].value = (INT32) pState->resolution_x;
+       stringProps[nextProp] = FALSE;
+       pState->resolutionProp = &props[nextProp];
+       nextProp++;
+    }
+    if (!pState->resolutionYProp) {
+       props[nextProp].name = bdfForceMakeAtom("RESOLUTION_Y", NULL);
+       props[nextProp].value = (INT32) pState->resolution_y;
+       stringProps[nextProp] = FALSE;
+       pState->resolutionProp = &props[nextProp];
+       nextProp++;
+    }
+    if (!pState->xHeightProp) {
+       props[nextProp].name = bdfForceMakeAtom("X_HEIGHT", NULL);
+       props[nextProp].value = -1;     /* computed later */
+       stringProps[nextProp] = FALSE;
+       pState->xHeightProp = &props[nextProp];
+       nextProp++;
+    }
+    if (!pState->quadWidthProp) {
+       props[nextProp].name = bdfForceMakeAtom("QUAD_WIDTH", NULL);
+       props[nextProp].value = -1;     /* computed later */
+       stringProps[nextProp] = FALSE;
+       pState->quadWidthProp = &props[nextProp];
+       nextProp++;
+    }
+    pFont->info.nprops = nextProp;
+    return (TRUE);
+BAILOUT:
+    if (pFont->info.isStringProp) {
+       xfree(pFont->info.isStringProp);
+       pFont->info.isStringProp = NULL;
+    }
+    if (pFont->info.props) {
+       xfree(pFont->info.props);
+       pFont->info.props = NULL;
+    }
+    while (line && bdfIsPrefix(line, "ENDPROPERTIES"))
+       line = bdfGetLine(file, lineBuf, BDFLINELEN);
+    return (FALSE);
+}
+
+/***====================================================================***/
+
+int
+bdfReadFont(pFont, file, bit, byte, glyph, scan)
+    FontPtr     pFont;
+    FontFilePtr file;
+    int         bit,
+                byte,
+                glyph,
+                scan;
+{
+    bdfFileState state;
+    xCharInfo  *min,
+               *max;
+    BitmapFontPtr  bitmapFont;
+
+    pFont->fontPrivate = 0;
+
+    bzero(&state, sizeof(bdfFileState));
+    bdfFileLineNum = 0;
+
+    if (!bdfReadHeader(file, &state))
+       goto BAILOUT;
+
+    bitmapFont = (BitmapFontPtr) xalloc(sizeof(BitmapFontRec));
+    if (!bitmapFont)
+       goto BAILOUT;
+
+    pFont->fontPrivate = (pointer) bitmapFont;
+    bitmapFont->metrics = 0;
+    bitmapFont->ink_metrics = 0;
+    bitmapFont->bitmaps = 0;
+    bitmapFont->encoding = 0;
+    bitmapFont->pDefault = NULL;
+    bitmapFont->bitmapExtra = (BitmapExtraPtr) xalloc(sizeof(BitmapExtraRec));
+    bitmapFont->bitmapExtra->glyphNames = 0;
+    bitmapFont->bitmapExtra->sWidths = 0;
+
+    if (!bdfReadProperties(file, pFont, &state))
+       goto BAILOUT;
+
+    if (!bdfReadCharacters(file, pFont, &state, bit, byte, glyph, scan))
+       goto BAILOUT;
+
+    if (state.haveDefaultCh) {
+       unsigned int r, c, cols;
+
+       r = pFont->info.defaultCh >> 8;
+       c = pFont->info.defaultCh & 0xFF;
+       if (pFont->info.firstRow <= r && r <= pFont->info.lastRow &&
+               pFont->info.firstCol <= c && c <= pFont->info.lastCol) {
+           cols = pFont->info.lastCol - pFont->info.firstCol + 1;
+           r = r - pFont->info.firstRow;
+           c = c - pFont->info.firstCol;
+           bitmapFont->pDefault = bitmapFont->encoding[r * cols + c];
+       }
+    }
+    pFont->bit = bit;
+    pFont->byte = byte;
+    pFont->glyph = glyph;
+    pFont->scan = scan;
+    pFont->info.anamorphic = FALSE;
+    pFont->info.cachable = TRUE;
+    bitmapComputeFontBounds(pFont);
+    if (FontCouldBeTerminal(&pFont->info)) {
+       bdfPadToTerminal(pFont);
+       bitmapComputeFontBounds(pFont);
+    }
+    FontComputeInfoAccelerators(&pFont->info);
+    if (bitmapFont->bitmapExtra)
+       FontComputeInfoAccelerators(&bitmapFont->bitmapExtra->info);
+    if (pFont->info.constantMetrics)
+       bitmapAddInkMetrics(pFont);
+    if (bitmapFont->bitmapExtra)
+       bitmapFont->bitmapExtra->info.inkMetrics = pFont->info.inkMetrics;
+
+    bitmapComputeFontInkBounds(pFont);
+/*    ComputeFontAccelerators (pFont); */
+
+    /* generate properties */
+    min = &pFont->info.ink_minbounds;
+    max = &pFont->info.ink_maxbounds;
+    if (state.xHeightProp && (state.xHeightProp->value == -1))
+       state.xHeightProp->value = state.exHeight ?
+           state.exHeight : min->ascent;
+
+    if (state.quadWidthProp && (state.quadWidthProp->value == -1))
+       state.quadWidthProp->value = state.digitCount ?
+           (INT32) (state.digitWidths / state.digitCount) :
+           (min->characterWidth + max->characterWidth) / 2;
+
+    if (state.weightProp && (state.weightProp->value == -1))
+       state.weightProp->value = bitmapComputeWeight(pFont);
+
+    pFont->get_glyphs = bitmapGetGlyphs;
+    pFont->get_metrics = bitmapGetMetrics;
+    pFont->unload_font = bdfUnloadFont;
+    pFont->unload_glyphs = NULL;
+    return Successful;
+BAILOUT:
+    if (pFont->fontPrivate)
+       bdfFreeFontBits (pFont);
+    return AllocError;
+}
+
+bdfFreeFontBits(pFont)
+    FontPtr pFont;
+{
+    BitmapFontPtr  bitmapFont;
+    BitmapExtraPtr bitmapExtra;
+    int         i;
+
+    bitmapFont = (BitmapFontPtr) pFont->fontPrivate;
+    bitmapExtra = (BitmapExtraPtr) bitmapFont->bitmapExtra;
+    xfree(bitmapFont->ink_metrics);
+    xfree(bitmapFont->encoding);
+    for (i = 0; i < bitmapFont->num_chars; i++)
+       xfree(bitmapFont->metrics[i].bits);
+    xfree(bitmapFont->metrics);
+    if (bitmapExtra)
+    {
+       xfree (bitmapExtra->glyphNames);
+       xfree (bitmapExtra->sWidths);
+       xfree (bitmapExtra);
+    }
+    xfree(pFont->info.props);
+    xfree(bitmapFont);
+}
+
+int
+bdfReadFontInfo(pFontInfo, file)
+    FontInfoPtr pFontInfo;
+    FontFilePtr file;
+{
+    FontRec     font;
+    int         ret;
+
+    ret = bdfReadFont(&font, file, MSBFirst, LSBFirst, 1, 1);
+    if (ret == Successful) {
+       *pFontInfo = font.info;
+       font.info.props = 0;
+       font.info.isStringProp = 0;
+       font.info.nprops = 0;
+       bdfFreeFontBits (&font);
+    }
+    return ret;
+}
+
+void
+bdfUnloadFont(pFont)
+    FontPtr     pFont;
+{
+    bdfFreeFontBits (pFont);
+    xfree (pFont->devPrivates);
+    xfree(pFont);
+}
+
+static Bool
+bdfPadToTerminal(pFont)
+    FontPtr     pFont;
+{
+    BitmapFontPtr  bitmapFont;
+    BitmapExtraPtr bitmapExtra;
+    int         i;
+    int         new_size;
+    CharInfoRec new;
+    int         w,
+                h;
+
+    bitmapFont = (BitmapFontPtr) pFont->fontPrivate;
+    new.metrics.ascent = pFont->info.fontAscent;
+    new.metrics.descent = pFont->info.fontDescent;
+    new.metrics.leftSideBearing = 0;
+    new.metrics.rightSideBearing = pFont->info.minbounds.characterWidth;
+    new.metrics.characterWidth = new.metrics.rightSideBearing;
+    new_size = BYTES_FOR_GLYPH(&new, pFont->glyph);
+    for (i = 0; i < bitmapFont->num_chars; i++) {
+       new.bits = (char *) xalloc(new_size);
+       if (!new.bits)
+           return FALSE;
+       FontCharReshape(pFont, &bitmapFont->metrics[i], &new);
+        new.metrics.attributes = bitmapFont->metrics[i].metrics.attributes;
+       xfree(bitmapFont->metrics[i].bits);
+       bitmapFont->metrics[i] = new;
+    }
+    bitmapExtra = bitmapFont->bitmapExtra;
+    if (bitmapExtra) {
+       w = GLYPHWIDTHPIXELS(&new);
+       h = GLYPHHEIGHTPIXELS(&new);
+       for (i = 0; i < GLYPHPADOPTIONS; i++)
+           bitmapExtra->bitmapsSizes[i] = bitmapFont->num_chars *
+               (BYTES_PER_ROW(w, 1 << i) * h);
+    }
+    return TRUE;
+}
diff --git a/Xserver/lib/font/bitmap/bdfutils.c b/Xserver/lib/font/bitmap/bdfutils.c
new file mode 100644 (file)
index 0000000..a04169a
--- /dev/null
@@ -0,0 +1,346 @@
+/* $XConsortium: bdfutils.c,v 1.11 94/04/17 20:17:10 gildea Exp $ */
+/************************************************************************
+Copyright 1989 by Digital Equipment Corporation, Maynard, Massachusetts.
+
+                        All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and its
+documentation for any purpose and without fee is hereby granted,
+provided that the above copyright notice appear in all copies and that
+both that copyright notice and this permission notice appear in
+supporting documentation, and that the name of Digital not be
+used in advertising or publicity pertaining to distribution of the
+software without specific, written prior permission.
+
+DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
+ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
+DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
+ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+SOFTWARE.
+
+************************************************************************/
+
+/*
+
+Copyright (c) 1994  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be included
+in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR
+OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall
+not be used in advertising or otherwise to promote the sale, use or
+other dealings in this Software without prior written authorization
+from the X Consortium.
+
+*/
+
+#include <ctype.h>
+
+#include <stdio.h>
+#include "fntfilst.h"
+#include "fontstruct.h"
+/* use bitmap structure */
+#include "bitmap.h"
+#include "bdfint.h"
+
+int bdfFileLineNum;
+
+/***====================================================================***/
+
+/* VARARGS1 */
+void
+bdfError(message, a0, a1, a2, a3, a4, a5)
+    char       *message;
+    pointer     a0,
+                a1,
+                a2,
+                a3,
+                a4,
+                a5;
+{
+    fprintf(stderr, "BDF Error on line %d: ", bdfFileLineNum);
+    fprintf(stderr, message, a0, a1, a2, a3, a4, a5);
+}
+
+/***====================================================================***/
+
+/* VARARGS1 */
+void
+bdfWarning(message, a0, a1, a2, a3, a4, a5)
+    char       *message;
+    pointer     a0,
+                a1,
+                a2,
+                a3,
+                a4,
+                a5;
+{
+    fprintf(stderr, "BDF Warning on line %d: ", bdfFileLineNum);
+    fprintf(stderr, message, a0, a1, a2, a3, a4, a5);
+}
+
+/*
+ * read the next (non-comment) line and keep a count for error messages.
+ * Returns buf, or NULL if EOF.
+ */
+
+unsigned char *
+bdfGetLine(file, buf, len)
+    FontFilePtr file;
+    unsigned char *buf;
+    int         len;
+{
+    int         c;
+    unsigned char *b;
+
+    for (;;) {
+       b = buf;
+       while ((c = FontFileGetc(file)) != FontFileEOF) {
+           if (c == '\r')
+               continue;
+           if (c == '\n') {
+               bdfFileLineNum++;
+               break;
+           }
+           if (b - buf >= (len - 1))
+               break;
+           *b++ = c;
+       }
+       *b = '\0';
+       if (c == FontFileEOF)
+           return NULL;
+       if (b != buf && !bdfIsPrefix(buf, "COMMENT"))
+           break;
+    }
+    return buf;
+}
+
+/***====================================================================***/
+
+Atom
+bdfForceMakeAtom(str, size)
+    register char *str;
+    register int *size;
+{
+    register int len = strlen(str);
+    extern Atom        MakeAtom();
+
+    if (size != NULL)
+       *size += len + 1;
+    return MakeAtom(str, len, TRUE);
+}
+
+/***====================================================================***/
+
+/*
+ * Handle quoted strings.
+ */
+
+Atom
+bdfGetPropertyValue(s)
+    char       *s;
+{
+    register char *p,
+               *pp;
+    char *orig_s = s;
+    Atom        atom;
+
+    /* strip leading white space */
+    while (*s && (*s == ' ' || *s == '\t'))
+       s++;
+    if (*s == 0) {
+       return bdfForceMakeAtom(s, NULL);
+    }
+    if (*s != '"') {
+       pp = s;
+       /* no white space in value */
+       for (pp = s; *pp; pp++)
+           if (*pp == ' ' || *pp == '\t' || *pp == '\015' || *pp == '\n') {
+               *pp = 0;
+               break;
+           }
+       return bdfForceMakeAtom(s, NULL);
+    }
+    /* quoted string: strip outer quotes and undouble inner quotes */
+    s++;
+    pp = p = (char *) xalloc((unsigned) strlen(s) + 1);
+    while (*s) {
+       if (*s == '"') {
+           if (*(s + 1) != '"') {
+               *p++ = 0;
+               atom = bdfForceMakeAtom(pp, NULL);
+               xfree(pp);
+               return atom;
+           } else {
+               s++;
+           }
+       }
+       *p++ = *s++;
+    }
+    xfree (pp);
+    bdfError("unterminated quoted string property: %s\n", (pointer) orig_s);
+    return None;
+}
+
+/***====================================================================***/
+
+/*
+ * return TRUE if string is a valid integer
+ */
+int
+bdfIsInteger(str)
+    char       *str;
+{
+    char        c;
+
+    c = *str++;
+    if (!(isdigit(c) || c == '-' || c == '+'))
+       return (FALSE);
+
+    while (c = *str++)
+       if (!isdigit(c))
+           return (FALSE);
+
+    return (TRUE);
+}
+
+/***====================================================================***/
+
+/*
+ * make a byte from the first two hex characters in glyph picture
+ */
+
+unsigned char
+bdfHexByte(s)
+    char       *s;
+{
+    unsigned char b = 0;
+    register char c;
+    int         i;
+
+    for (i = 2; i; i--) {
+       c = *s++;
+       if ((c >= '0') && (c <= '9'))
+           b = (b << 4) + (c - '0');
+       else if ((c >= 'A') && (c <= 'F'))
+           b = (b << 4) + 10 + (c - 'A');
+       else if ((c >= 'a') && (c <= 'f'))
+           b = (b << 4) + 10 + (c - 'a');
+       else
+           bdfError("bad hex char '%c'", c);
+    }
+    return b;
+}
+
+/***====================================================================***/
+
+/*
+ * check for known special property values
+ */
+
+static char *SpecialAtoms[] = {
+    "FONT_ASCENT",
+#define BDF_FONT_ASCENT        0
+    "FONT_DESCENT",
+#define BDF_FONT_DESCENT 1
+    "DEFAULT_CHAR",
+#define BDF_DEFAULT_CHAR 2
+    "POINT_SIZE",
+#define BDF_POINT_SIZE 3
+    "RESOLUTION",
+#define BDF_RESOLUTION 4
+    "X_HEIGHT",
+#define BDF_X_HEIGHT 5
+    "WEIGHT",
+#define BDF_WEIGHT 6
+    "QUAD_WIDTH",
+#define BDF_QUAD_WIDTH 7
+    "FONT",
+#define BDF_FONT 8
+    "RESOLUTION_X",
+#define BDF_RESOLUTION_X 9
+    "RESOLUTION_Y",
+#define BDF_RESOLUTION_Y 10
+    0,
+};
+
+Bool
+bdfSpecialProperty(pFont, prop, isString, bdfState)
+    FontPtr     pFont;
+    FontPropPtr prop;
+    char        isString;
+    bdfFileState *bdfState;
+{
+    char      **special;
+    char       *name;
+
+    name = NameForAtom(prop->name);
+    for (special = SpecialAtoms; *special; special++)
+       if (!strcmp(name, *special))
+           break;
+
+    switch (special - SpecialAtoms) {
+    case BDF_FONT_ASCENT:
+       if (!isString) {
+           pFont->info.fontAscent = prop->value;
+           bdfState->haveFontAscent = TRUE;
+       }
+       return TRUE;
+    case BDF_FONT_DESCENT:
+       if (!isString) {
+           pFont->info.fontDescent = prop->value;
+           bdfState->haveFontDescent = TRUE;
+       }
+       return TRUE;
+    case BDF_DEFAULT_CHAR:
+       if (!isString) {
+           pFont->info.defaultCh = prop->value;
+           bdfState->haveDefaultCh = TRUE;
+       }
+       return TRUE;
+    case BDF_POINT_SIZE:
+       bdfState->pointSizeProp = prop;
+       return FALSE;
+    case BDF_RESOLUTION:
+       bdfState->resolutionProp = prop;
+       return FALSE;
+    case BDF_X_HEIGHT:
+       bdfState->xHeightProp = prop;
+       return FALSE;
+    case BDF_WEIGHT:
+       bdfState->weightProp = prop;
+       return FALSE;
+    case BDF_QUAD_WIDTH:
+       bdfState->quadWidthProp = prop;
+       return FALSE;
+    case BDF_FONT:
+       bdfState->fontProp = prop;
+       return FALSE;
+    case BDF_RESOLUTION_X:
+       bdfState->resolutionXProp = prop;
+       return FALSE;
+    case BDF_RESOLUTION_Y:
+       bdfState->resolutionYProp = prop;
+       return FALSE;
+    default:
+       return FALSE;
+    }
+}
diff --git a/Xserver/lib/font/bitmap/bitmap.c b/Xserver/lib/font/bitmap/bitmap.c
new file mode 100644 (file)
index 0000000..3c80e41
--- /dev/null
@@ -0,0 +1,167 @@
+/* $XConsortium: bitmap.c,v 1.5 94/04/17 20:17:11 gildea Exp $ */
+
+/*
+
+Copyright (c) 1991  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+*/
+
+/*
+ * Author:  Keith Packard, MIT X Consortium
+ */
+
+#include "fntfilst.h"
+#include "bitmap.h"
+
+int         bitmapGetGlyphs(), bitmapGetMetrics();
+int         bitmapGetBitmaps(), bitmapGetExtents();
+void       bitmapComputeFontBounds ();
+void       bitmapComputeFontInkBounds ();
+
+int
+bitmapGetGlyphs(pFont, count, chars, charEncoding, glyphCount, glyphs)
+    FontPtr     pFont;
+    unsigned long count;
+    register unsigned char *chars;
+    FontEncoding charEncoding;
+    unsigned long *glyphCount; /* RETURN */
+    CharInfoPtr *glyphs;       /* RETURN */
+{
+    BitmapFontPtr  bitmapFont;
+    unsigned int firstCol;
+    register unsigned int numCols;
+    unsigned int firstRow;
+    unsigned int numRows;
+    CharInfoPtr *glyphsBase;
+    register unsigned int c;
+    register CharInfoPtr pci;
+    unsigned int r;
+    CharInfoPtr *encoding;
+    CharInfoPtr pDefault;
+
+    bitmapFont = (BitmapFontPtr) pFont->fontPrivate;
+    encoding = bitmapFont->encoding;
+    pDefault = bitmapFont->pDefault;
+    firstCol = pFont->info.firstCol;
+    numCols = pFont->info.lastCol - firstCol + 1;
+    glyphsBase = glyphs;
+    switch (charEncoding) {
+
+    case Linear8Bit:
+    case TwoD8Bit:
+       if (pFont->info.firstRow > 0)
+           break;
+       if (pFont->info.allExist && pDefault) {
+           while (count--) {
+               c = (*chars++) - firstCol;
+               if (c < numCols)
+                   *glyphs++ = encoding[c];
+               else
+                   *glyphs++ = pDefault;
+           }
+       } else {
+           while (count--) {
+               c = (*chars++) - firstCol;
+               if (c < numCols && (pci = encoding[c]))
+                   *glyphs++ = pci;
+               else if (pDefault)
+                   *glyphs++ = pDefault;
+           }
+       }
+       break;
+    case Linear16Bit:
+       if (pFont->info.allExist && pDefault) {
+           while (count--) {
+               c = *chars++ << 8;
+               c = (c | *chars++) - firstCol;
+               if (c < numCols)
+                   *glyphs++ = encoding[c];
+               else
+                   *glyphs++ = pDefault;
+           }
+       } else {
+           while (count--) {
+               c = *chars++ << 8;
+               c = (c | *chars++) - firstCol;
+               if (c < numCols && (pci = encoding[c]))
+                   *glyphs++ = pci;
+               else if (pDefault)
+                   *glyphs++ = pDefault;
+           }
+       }
+       break;
+
+    case TwoD16Bit:
+       firstRow = pFont->info.firstRow;
+       numRows = pFont->info.lastRow - firstRow + 1;
+       while (count--) {
+           r = (*chars++) - firstRow;
+           c = (*chars++) - firstCol;
+           if (r < numRows && c < numCols &&
+                   (pci = encoding[r * numCols + c]))
+               *glyphs++ = pci;
+           else if (pDefault)
+               *glyphs++ = pDefault;
+       }
+       break;
+    }
+    *glyphCount = glyphs - glyphsBase;
+    return Successful;
+}
+
+static CharInfoRec nonExistantChar;
+
+int
+bitmapGetMetrics(pFont, count, chars, charEncoding, glyphCount, glyphs)
+    FontPtr     pFont;
+    unsigned long count;
+    register unsigned char *chars;
+    FontEncoding charEncoding;
+    unsigned long *glyphCount; /* RETURN */
+    xCharInfo **glyphs;                /* RETURN */
+{
+    int         ret;
+    xCharInfo  *ink_metrics;
+    CharInfoPtr metrics;
+    BitmapFontPtr  bitmapFont;
+    CharInfoPtr        oldDefault;
+    int         i;
+
+    bitmapFont = (BitmapFontPtr) pFont->fontPrivate;
+    oldDefault = bitmapFont->pDefault;
+    bitmapFont->pDefault = &nonExistantChar;
+    ret = bitmapGetGlyphs(pFont, count, chars, charEncoding, glyphCount, (CharInfoPtr *) glyphs);
+    if (ret == Successful) {
+       if (bitmapFont->ink_metrics) {
+           metrics = bitmapFont->metrics;
+           ink_metrics = bitmapFont->ink_metrics;
+           for (i = 0; i < *glyphCount; i++) {
+               if (glyphs[i] != (xCharInfo *) & nonExistantChar)
+                   glyphs[i] = ink_metrics + (((CharInfoPtr) glyphs[i]) - metrics);
+           }
+       }
+    }
+    bitmapFont->pDefault = oldDefault;
+    return ret;
+}
diff --git a/Xserver/lib/font/bitmap/bitmapfunc.c b/Xserver/lib/font/bitmap/bitmapfunc.c
new file mode 100644 (file)
index 0000000..74d2493
--- /dev/null
@@ -0,0 +1,228 @@
+/* $XConsortium: bitmapfunc.c /main/10 1996/11/03 19:31:55 kaleb $ */
+/* $XFree86: xc/lib/font/bitmap/bitmapfunc.c,v 3.4 1996/12/23 06:01:49 dawes Exp $ */
+
+/*
+
+Copyright (c) 1991  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+*/
+
+/*
+ * Author:  Keith Packard, MIT X Consortium
+ */
+
+#include "fntfilst.h"
+#include "bitmap.h"
+
+typedef struct _BitmapFileFunctions {
+    int         (*ReadFont) ( /* pFont, file, bit, byte, glyph, scan */ );
+    int         (*ReadInfo) ( /* pFontInfo, file */ );
+}           BitmapFileFunctionsRec, *BitmapFileFunctionsPtr;
+
+extern int  pcfReadFont(), pcfReadFontInfo();
+extern int  snfReadFont(), snfReadFontInfo();
+extern int  bdfReadFont(), bdfReadFontInfo();
+extern int  pmfReadFont();
+int        BitmapOpenBitmap ();
+extern int  BitmapOpenScalable ();
+int        BitmapGetInfoBitmap ();
+extern int  BitmapGetInfoScalable ();
+int        BitmapGetRenderIndex ();
+
+/*
+ * these two arrays must be in the same order
+ */
+static BitmapFileFunctionsRec readers[] = {
+    pcfReadFont, pcfReadFontInfo,
+    pcfReadFont, pcfReadFontInfo,
+#ifdef X_GZIP_FONT_COMPRESSION
+    pcfReadFont, pcfReadFontInfo,
+#endif
+#ifdef __EMX__
+    pcfReadFont, pcfReadFontInfo,
+#endif
+    snfReadFont, snfReadFontInfo,
+    snfReadFont, snfReadFontInfo,
+#ifdef X_GZIP_FONT_COMPRESSION
+    snfReadFont, snfReadFontInfo,
+#endif
+    bdfReadFont, bdfReadFontInfo,
+    bdfReadFont, bdfReadFontInfo,
+#ifdef X_GZIP_FONT_COMPRESSION
+    bdfReadFont, bdfReadFontInfo,
+#endif
+    pmfReadFont, pcfReadFontInfo,
+};
+
+
+#define CAPABILITIES (CAP_MATRIX | CAP_CHARSUBSETTING)
+
+static FontRendererRec renderers[] = {
+    ".pcf", 4,
+    BitmapOpenBitmap, BitmapOpenScalable,
+       BitmapGetInfoBitmap, BitmapGetInfoScalable, 0,
+       CAPABILITIES,
+    ".pcf.Z", 6,
+    BitmapOpenBitmap, BitmapOpenScalable,
+       BitmapGetInfoBitmap, BitmapGetInfoScalable, 0,
+       CAPABILITIES,
+#ifdef X_GZIP_FONT_COMPRESSION
+    ".pcf.gz", 7,
+    BitmapOpenBitmap, BitmapOpenScalable,
+       BitmapGetInfoBitmap, BitmapGetInfoScalable, 0,
+       CAPABILITIES,
+#endif
+#ifdef __EMX__
+    ".pcz", 4,
+    BitmapOpenBitmap, BitmapOpenScalable,
+       BitmapGetInfoBitmap, BitmapGetInfoScalable, 0,
+       CAPABILITIES,
+#endif
+    ".snf", 4,
+    BitmapOpenBitmap, BitmapOpenScalable,
+       BitmapGetInfoBitmap, BitmapGetInfoScalable, 0,
+       CAPABILITIES,
+    ".snf.Z", 6,
+    BitmapOpenBitmap, BitmapOpenScalable,
+       BitmapGetInfoBitmap, BitmapGetInfoScalable, 0,
+       CAPABILITIES,
+#ifdef X_GZIP_FONT_COMPRESSION
+    ".snf.gz", 7,
+    BitmapOpenBitmap, BitmapOpenScalable,
+       BitmapGetInfoBitmap, BitmapGetInfoScalable, 0,
+       CAPABILITIES,
+#endif
+    ".bdf", 4,
+    BitmapOpenBitmap, BitmapOpenScalable,
+       BitmapGetInfoBitmap, BitmapGetInfoScalable, 0,
+       CAPABILITIES,
+    ".bdf.Z", 6,
+    BitmapOpenBitmap, BitmapOpenScalable,
+       BitmapGetInfoBitmap, BitmapGetInfoScalable, 0,
+       CAPABILITIES,
+#ifdef X_GZIP_FONT_COMPRESSION
+    ".bdf.gz", 7,
+    BitmapOpenBitmap, BitmapOpenScalable,
+       BitmapGetInfoBitmap, BitmapGetInfoScalable, 0,
+       CAPABILITIES,
+#endif
+    ".pmf", 4,
+      BitmapOpenBitmap, BitmapOpenScalable,
+       BitmapGetInfoBitmap, BitmapGetInfoScalable, 0,
+       CAPABILITIES 
+};
+
+BitmapOpenBitmap (fpe, ppFont, flags, entry, fileName, format, fmask,
+                 non_cachable_font)
+    FontPathElementPtr fpe;
+    FontPtr            *ppFont;
+    int                        flags;
+    FontEntryPtr       entry;
+    char               *fileName;
+    fsBitmapFormat     format;
+    fsBitmapFormatMask fmask;
+    FontPtr            non_cachable_font;      /* We don't do licensing */
+{
+    FontFilePtr        file;
+    FontPtr     pFont;
+    int         i;
+    int         ret;
+    int         bit,
+                byte,
+                glyph,
+                scan,
+               image;
+
+    i = BitmapGetRenderIndex(entry->u.bitmap.renderer);
+    file = FontFileOpen (fileName);
+    if (!file)
+       return BadFontName;
+    pFont = (FontPtr) xalloc(sizeof(FontRec));
+    if (!pFont) {
+       FontFileClose (file);
+       return AllocError;
+    }
+    /* set up default values */
+    FontDefaultFormat(&bit, &byte, &glyph, &scan);
+    /* get any changes made from above */
+    ret = CheckFSFormat(format, fmask, &bit, &byte, &scan, &glyph, &image);
+
+    /* Fill in font record. Data format filled in by reader. */
+    pFont->refcnt = 0;
+    pFont->maxPrivate = -1;
+    pFont->devPrivates = (pointer *) 0;
+
+    ret = (*readers[i].ReadFont) (pFont, file, bit, byte, glyph, scan);
+
+    FontFileClose (file);
+    if (ret != Successful)
+       xfree(pFont);
+    else
+       *ppFont = pFont;
+    return ret;
+}
+
+BitmapGetInfoBitmap (fpe, pFontInfo, entry, fileName)
+    FontPathElementPtr fpe;
+    FontInfoPtr                pFontInfo;
+    FontEntryPtr       entry;
+    char               *fileName;
+{
+    FontFilePtr file;
+    int                i;
+    int                ret;
+    FontRendererPtr renderer;
+
+    renderer = FontFileMatchRenderer (fileName);
+    if (!renderer)
+       return BadFontName;
+    i = BitmapGetRenderIndex(renderer);
+    file = FontFileOpen (fileName);
+    if (!file)
+       return BadFontName;
+    ret = (*readers[i].ReadInfo) (pFontInfo, file);
+    FontFileClose (file);
+    return ret;
+}
+
+#define numRenderers   (sizeof renderers / sizeof renderers[0])
+
+BitmapRegisterFontFileFunctions ()
+{
+    int            i;
+
+    for (i = 0; i < numRenderers; i++)
+       FontFileRegisterRenderer (&renderers[i]);
+}
+
+/*
+ * compute offset into renderers array - used to find the font reader,
+ * the font info reader, and the bitmap scaling routine.  All users
+ * of this routine must be kept in step with the renderer array.
+ */
+BitmapGetRenderIndex(renderer)
+    FontRendererPtr renderer;
+{
+    return renderer - renderers;
+}
diff --git a/Xserver/lib/font/bitmap/bitmaputil.c b/Xserver/lib/font/bitmap/bitmaputil.c
new file mode 100644 (file)
index 0000000..e4abb39
--- /dev/null
@@ -0,0 +1,229 @@
+/* $XConsortium: bitmaputil.c,v 1.6 94/04/17 20:17:12 gildea Exp $ */
+
+/*
+
+Copyright (c) 1990, 1994  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be included
+in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR
+OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall
+not be used in advertising or otherwise to promote the sale, use or
+other dealings in this Software without prior written authorization
+from the X Consortium.
+
+*/
+
+#include "fntfilst.h"
+#include "bitmap.h"
+
+#ifndef MAXSHORT
+#define MAXSHORT    32767
+#endif
+
+#ifndef MINSHORT
+#define MINSHORT    -32768
+#endif
+
+static xCharInfo initMinMetrics = {
+MAXSHORT, MAXSHORT, MAXSHORT, MAXSHORT, MAXSHORT, 0xFFFF};
+static xCharInfo initMaxMetrics = {
+MINSHORT, MINSHORT, MINSHORT, MINSHORT, MINSHORT, 0x0000};
+
+#define MINMAX(field,ci) \
+       if (minbounds->field > (ci)->field) \
+            minbounds->field = (ci)->field; \
+       if (maxbounds->field < (ci)->field) \
+            maxbounds->field = (ci)->field;
+
+#define COMPUTE_MINMAX(ci) \
+    if ((ci)->ascent != -(ci)->descent || \
+       (ci)->leftSideBearing != (ci)->rightSideBearing || \
+       (ci)->characterWidth) \
+    { \
+       MINMAX(ascent, (ci)); \
+       MINMAX(descent, (ci)); \
+       MINMAX(leftSideBearing, (ci)); \
+       MINMAX(rightSideBearing, (ci)); \
+       MINMAX(characterWidth, (ci)); \
+    }
+
+void
+bitmapComputeFontBounds(pFont)
+    FontPtr     pFont;
+{
+    BitmapFontPtr  bitmapFont = (BitmapFontPtr) pFont->fontPrivate;
+    int         nchars;
+    int         r,
+                c;
+    CharInfoPtr ci,
+               *pci;
+    int         maxOverlap;
+    int         overlap;
+    xCharInfo  *minbounds,
+               *maxbounds;
+    int         i;
+    int                numneg = 0, numpos = 0;
+
+    if (bitmapFont->bitmapExtra) {
+       minbounds = &bitmapFont->bitmapExtra->info.minbounds;
+       maxbounds = &bitmapFont->bitmapExtra->info.maxbounds;
+    } else {
+       minbounds = &pFont->info.minbounds;
+       maxbounds = &pFont->info.maxbounds;
+    }
+    *minbounds = initMinMetrics;
+    *maxbounds = initMaxMetrics;
+    maxOverlap = MINSHORT;
+    nchars = bitmapFont->num_chars;
+    for (i = 0, ci = bitmapFont->metrics; i < nchars; i++, ci++) {
+       COMPUTE_MINMAX(&ci->metrics);
+       if (ci->metrics.characterWidth < 0)
+           numneg++;
+       else
+           numpos++;
+       minbounds->attributes &= ci->metrics.attributes;
+       maxbounds->attributes |= ci->metrics.attributes;
+       overlap = ci->metrics.rightSideBearing - ci->metrics.characterWidth;
+       if (maxOverlap < overlap)
+           maxOverlap = overlap;
+    }
+    if (bitmapFont->bitmapExtra) {
+       if (numneg > numpos)
+           bitmapFont->bitmapExtra->info.drawDirection = RightToLeft;
+       else
+           bitmapFont->bitmapExtra->info.drawDirection = LeftToRight;
+       bitmapFont->bitmapExtra->info.maxOverlap = maxOverlap;
+       minbounds = &pFont->info.minbounds;
+       maxbounds = &pFont->info.maxbounds;
+       *minbounds = initMinMetrics;
+       *maxbounds = initMaxMetrics;
+       pci = bitmapFont->encoding;
+       maxOverlap = MINSHORT;
+       for (r = pFont->info.firstRow; r <= pFont->info.lastRow; r++) {
+           for (c = pFont->info.firstCol; c <= pFont->info.lastCol; c++) {
+               ci = *pci++;
+               if (ci) {
+                   COMPUTE_MINMAX(&ci->metrics);
+                   if (ci->metrics.characterWidth < 0)
+                       numneg++;
+                   else
+                       numpos++;
+                   minbounds->attributes &= ci->metrics.attributes;
+                   maxbounds->attributes |= ci->metrics.attributes;
+                   overlap = ci->metrics.rightSideBearing -
+                       ci->metrics.characterWidth;
+                   if (maxOverlap < overlap)
+                       maxOverlap = overlap;
+               }
+           }
+       }
+    }
+    if (numneg > numpos)
+       pFont->info.drawDirection = RightToLeft;
+    else
+       pFont->info.drawDirection = LeftToRight;
+    pFont->info.maxOverlap = maxOverlap;
+}
+
+void
+bitmapComputeFontInkBounds(pFont)
+    FontPtr     pFont;
+{
+    BitmapFontPtr  bitmapFont = (BitmapFontPtr) pFont->fontPrivate;
+    int         nchars;
+    int         r,
+                c;
+    CharInfoPtr *pci,
+                cit;
+    xCharInfo  *ci;
+    int         offset;
+    xCharInfo  *minbounds,
+               *maxbounds;
+    int         i;
+
+    if (!bitmapFont->ink_metrics) {
+       if (bitmapFont->bitmapExtra) {
+           bitmapFont->bitmapExtra->info.ink_minbounds = bitmapFont->bitmapExtra->info.minbounds;
+           bitmapFont->bitmapExtra->info.ink_maxbounds = bitmapFont->bitmapExtra->info.maxbounds;
+       }
+       pFont->info.ink_minbounds = pFont->info.minbounds;
+       pFont->info.ink_maxbounds = pFont->info.maxbounds;
+    } else {
+       if (bitmapFont->bitmapExtra) {
+           minbounds = &bitmapFont->bitmapExtra->info.ink_minbounds;
+           maxbounds = &bitmapFont->bitmapExtra->info.ink_maxbounds;
+       } else {
+           minbounds = &pFont->info.ink_minbounds;
+           maxbounds = &pFont->info.ink_maxbounds;
+       }
+       *minbounds = initMinMetrics;
+       *maxbounds = initMaxMetrics;
+       nchars = bitmapFont->num_chars;
+       for (i = 0, ci = bitmapFont->ink_metrics; i < nchars; i++, ci++) {
+           COMPUTE_MINMAX(ci);
+           minbounds->attributes &= ci->attributes;
+           maxbounds->attributes |= ci->attributes;
+       }
+       if (bitmapFont->bitmapExtra) {
+           minbounds = &pFont->info.ink_minbounds;
+           maxbounds = &pFont->info.ink_maxbounds;
+           *minbounds = initMinMetrics;
+           *maxbounds = initMaxMetrics;
+           pci = bitmapFont->encoding;
+           for (r = pFont->info.firstRow; r <= pFont->info.lastRow; r++) {
+               for (c = pFont->info.firstCol; c <= pFont->info.lastCol; c++) {
+                   cit = *pci++;
+                   if (cit) {
+                       offset = cit - bitmapFont->metrics;
+                       ci = &bitmapFont->ink_metrics[offset];
+                       COMPUTE_MINMAX(ci);
+                       minbounds->attributes &= ci->attributes;
+                       maxbounds->attributes |= ci->attributes;
+                   }
+               }
+           }
+       }
+    }
+}
+
+Bool
+bitmapAddInkMetrics(pFont)
+    FontPtr     pFont;
+{
+    BitmapFontPtr  bitmapFont;
+    int         i;
+
+    bitmapFont = (BitmapFontPtr) pFont->fontPrivate;
+    bitmapFont->ink_metrics = (xCharInfo *) xalloc(bitmapFont->num_chars * sizeof(xCharInfo));
+    if (!bitmapFont->ink_metrics)
+       return FALSE;
+    for (i = 0; i < bitmapFont->num_chars; i++)
+       FontCharInkMetrics(pFont, &bitmapFont->metrics[i], &bitmapFont->ink_metrics[i]);
+    pFont->info.inkMetrics = TRUE;
+    return TRUE;
+}
+
+/* ARGSUSED */
+int
+bitmapComputeWeight(pFont)
+    FontPtr     pFont;
+{
+    return 10;
+}
diff --git a/Xserver/lib/font/bitmap/bitscale.c b/Xserver/lib/font/bitmap/bitscale.c
new file mode 100644 (file)
index 0000000..ce407e2
--- /dev/null
@@ -0,0 +1,1914 @@
+/* $TOG: bitscale.c /main/31 1997/06/09 11:21:46 barstow $ */
+
+/*
+
+Copyright (c) 1991, 1994  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be included
+in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR
+OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall
+not be used in advertising or otherwise to promote the sale, use or
+other dealings in this Software without prior written authorization
+from the X Consortium.
+
+*/
+/* $XFree86: xc/lib/font/bitmap/bitscale.c,v 3.4.2.1 1997/06/11 12:08:40 dawes Exp $ */
+
+/*
+ * Author:  Keith Packard, MIT X Consortium
+ */
+
+#include "fntfilst.h"
+#include "bitmap.h"
+#ifdef _XOPEN_SOURCE
+#include <math.h>
+#else
+#define _XOPEN_SOURCE  /* to get prototype for hypot on some systems */
+#include <math.h>
+#undef _XOPEN_SOURCE
+#endif
+
+#ifndef MAX
+#define   MAX(a,b)    (((a)>(b)) ? a : b)
+#endif
+
+extern Atom MakeAtom();
+
+void bitmapUnloadScalable();
+
+enum scaleType {
+    atom, truncate_atom, pixel_size, point_size, resolution_x,
+    resolution_y, average_width, scaledX, scaledY, unscaled, fontname,
+    raw_ascent, raw_descent, raw_pixelsize, raw_pointsize,
+    raw_average_width, uncomputed
+};
+
+typedef struct _fontProp {
+    char       *name;
+    Atom        atom;
+    enum scaleType type;
+} fontProp;
+
+static FontPtr BitmapScaleBitmaps();
+static FontPtr PrinterScaleBitmaps();
+
+typedef FontPtr (*ScaleFunc) ();
+/* These next two arrays must be kept in step with the renderer array */
+ScaleFunc scale[] =
+{
+    BitmapScaleBitmaps,
+    BitmapScaleBitmaps,
+    BitmapScaleBitmaps,
+    BitmapScaleBitmaps,
+    BitmapScaleBitmaps,
+    BitmapScaleBitmaps,
+    PrinterScaleBitmaps,
+};
+
+static FontEntryPtr FindBestToScale();
+static FontEntryPtr FindPmfToScale();
+
+typedef FontEntryPtr (*FindToScale) ();
+FindToScale find_scale[] =
+{
+    FindBestToScale,
+    FindBestToScale,
+    FindBestToScale,
+    FindBestToScale,
+    FindBestToScale,
+    FindBestToScale,
+    FindPmfToScale,
+};
+
+static unsigned long fontGeneration = 0;       /* initialization flag */
+
+static fontProp fontNamePropTable[] = {
+    "FOUNDRY", 0, atom,
+    "FAMILY_NAME", 0, atom,
+    "WEIGHT_NAME", 0, atom,
+    "SLANT", 0, atom,
+    "SETWIDTH_NAME", 0, atom,
+    "ADD_STYLE_NAME", 0, atom,
+    "PIXEL_SIZE", 0, pixel_size,
+    "POINT_SIZE", 0, point_size,
+    "RESOLUTION_X", 0, resolution_x,
+    "RESOLUTION_Y", 0, resolution_y,
+    "SPACING", 0, atom,
+    "AVERAGE_WIDTH", 0, average_width,
+    "CHARSET_REGISTRY", 0, atom,
+    "CHARSET_ENCODING", 0, truncate_atom,
+    "FONT", 0, fontname,
+    "RAW_ASCENT", 0, raw_ascent,
+    "RAW_DESCENT", 0, raw_descent,
+    "RAW_PIXEL_SIZE", 0, raw_pixelsize,
+    "RAW_POINT_SIZE", 0, raw_pointsize,
+    "RAW_AVERAGE_WIDTH", 0, raw_average_width
+};
+
+#define TRANSFORM_POINT(matrix, x, y, dest) \
+       ((dest)[0] = (matrix)[0] * (x) + (matrix)[2] * (y), \
+        (dest)[1] = (matrix)[1] * (x) + (matrix)[3] * (y))
+
+#define CHECK_EXTENT(lsb, rsb, desc, asc, data) \
+       ((lsb) > (data)[0] ? (lsb) = (data)[0] : 0 , \
+        (rsb) < (data)[0] ? (rsb) = (data)[0] : 0, \
+        (-desc) > (data)[1] ? (desc) = -(data)[1] : 0 , \
+        (asc) < (data)[1] ? (asc) = (data)[1] : 0)
+
+#define NPROPS (sizeof(fontNamePropTable) / sizeof(fontProp))
+
+/* Warning: order of the next two tables is critically interdependent.
+   Location of "unscaled" properties at the end of fontPropTable[]
+   is important. */
+
+static fontProp fontPropTable[] = {
+    "MIN_SPACE", 0, scaledX,
+    "NORM_SPACE", 0, scaledX,
+    "MAX_SPACE", 0, scaledX,
+    "END_SPACE", 0, scaledX,
+    "AVG_CAPITAL_WIDTH", 0, scaledX,
+    "AVG_LOWERCASE_WIDTH", 0, scaledX,
+    "QUAD_WIDTH", 0, scaledX,
+    "FIGURE_WIDTH", 0, scaledX,
+    "SUPERSCRIPT_X", 0, scaledX,
+    "SUPERSCRIPT_Y", 0, scaledY,
+    "SUBSCRIPT_X", 0, scaledX,
+    "SUBSCRIPT_Y", 0, scaledY,
+    "SUPERSCRIPT_SIZE", 0, scaledY,
+    "SUBSCRIPT_SIZE", 0, scaledY,
+    "SMALL_CAP_SIZE", 0, scaledY,
+    "UNDERLINE_POSITION", 0, scaledY,
+    "UNDERLINE_THICKNESS", 0, scaledY,
+    "STRIKEOUT_ASCENT", 0, scaledY,
+    "STRIKEOUT_DESCENT", 0, scaledY,
+    "CAP_HEIGHT", 0, scaledY,
+    "X_HEIGHT", 0, scaledY,
+    "ITALIC_ANGLE", 0, unscaled,
+    "RELATIVE_SETWIDTH", 0, unscaled,
+    "RELATIVE_WEIGHT", 0, unscaled,
+    "WEIGHT", 0, unscaled,
+    "DESTINATION", 0, unscaled,
+    "PCL_FONT_NAME", 0, unscaled,
+    "_ADOBE_POSTSCRIPT_FONTNAME", 0, unscaled
+};
+
+static fontProp rawFontPropTable[] = {
+    "RAW_MIN_SPACE", 0, 0,
+    "RAW_NORM_SPACE", 0, 0,
+    "RAW_MAX_SPACE", 0, 0,
+    "RAW_END_SPACE", 0, 0,
+    "RAW_AVG_CAPITAL_WIDTH", 0, 0,
+    "RAW_AVG_LOWERCASE_WIDTH", 0, 0,
+    "RAW_QUAD_WIDTH", 0, 0,
+    "RAW_FIGURE_WIDTH", 0, 0,
+    "RAW_SUPERSCRIPT_X", 0, 0,
+    "RAW_SUPERSCRIPT_Y", 0, 0,
+    "RAW_SUBSCRIPT_X", 0, 0,
+    "RAW_SUBSCRIPT_Y", 0, 0,
+    "RAW_SUPERSCRIPT_SIZE", 0, 0,
+    "RAW_SUBSCRIPT_SIZE", 0, 0,
+    "RAW_SMALL_CAP_SIZE", 0, 0,
+    "RAW_UNDERLINE_POSITION", 0, 0,
+    "RAW_UNDERLINE_THICKNESS", 0, 0,
+    "RAW_STRIKEOUT_ASCENT", 0, 0,
+    "RAW_STRIKEOUT_DESCENT", 0, 0,
+    "RAW_CAP_HEIGHT", 0, 0,
+    "RAW_X_HEIGHT", 0, 0,
+};
+
+static void
+initFontPropTable()
+{
+    int         i;
+    fontProp   *t;
+
+    i = sizeof(fontNamePropTable) / sizeof(fontProp);
+    for (t = fontNamePropTable; i; i--, t++)
+       t->atom = MakeAtom(t->name, (unsigned) strlen(t->name), TRUE);
+
+    i = sizeof(fontPropTable) / sizeof(fontProp);
+    for (t = fontPropTable; i; i--, t++)
+       t->atom = MakeAtom(t->name, (unsigned) strlen(t->name), TRUE);
+
+    i = sizeof(rawFontPropTable) / sizeof(fontProp);
+    for (t = rawFontPropTable; i; i--, t++)
+       t->atom = MakeAtom(t->name, (unsigned) strlen(t->name), TRUE);
+}
+
+static FontEntryPtr
+GetScalableEntry (fpe, name)
+    FontPathElementPtr fpe;
+    FontNamePtr                name;
+{
+    FontDirectoryPtr   dir;
+
+    dir = (FontDirectoryPtr) fpe->private;
+    return FontFileFindNameInDir (&dir->scalable, name);
+}
+
+static double
+get_matrix_horizontal_component(matrix)
+    double *matrix;
+{
+    return hypot(matrix[0], matrix[1]);
+}
+
+static double
+get_matrix_vertical_component(matrix)
+    double *matrix;
+{
+    return hypot(matrix[2], matrix[3]);
+}
+
+
+static Bool
+ComputeScaleFactors(from, to, dx, dy, sdx, sdy, rescale_x)
+    FontScalablePtr from,
+                to;
+    double     *dx, *sdx,
+               *dy, *sdy,
+              *rescale_x;
+{
+    double srcpixelset, destpixelset, srcpixel, destpixel;
+
+    srcpixelset = get_matrix_horizontal_component(from->pixel_matrix);
+    destpixelset = get_matrix_horizontal_component(to->pixel_matrix);
+    srcpixel = get_matrix_vertical_component(from->pixel_matrix);
+    destpixel = get_matrix_vertical_component(to->pixel_matrix);
+
+    if (srcpixelset >= EPS)
+    {
+       *dx = destpixelset / srcpixelset;
+       *sdx = 1000.0 / srcpixelset;
+    }
+    else
+       *sdx = *dx = 0;
+
+    *rescale_x = 1.0;
+
+    /* If client specified a width, it overrides setsize; in this
+       context, we interpret width as applying to the font before any
+       rotation, even though that's not what is ultimately returned in
+       the width field. */
+    if (from->width > 0 && to->width > 0 && fabs(*dx) > EPS)
+    {
+       double rescale = (double)to->width / (double)from->width;
+
+       /* If the client specified a transformation matrix, the rescaling
+          for width does *not* override the setsize.  Instead, just check
+          for consistency between the setsize from the matrix and the
+          setsize that would result from rescaling according to the width.
+          This assumes (perhaps naively) that the width is correctly
+          reported in the name.  As an interesting side effect, this test
+          may result in choosing a different source bitmap (one that
+          scales consistently between the setsize *and* the width) than it
+          would choose if a width were not specified.  Sort of a hidden
+          multiple-master functionality. */
+       if ((to->values_supplied & PIXELSIZE_MASK) == PIXELSIZE_ARRAY ||
+           (to->values_supplied & POINTSIZE_MASK) == POINTSIZE_ARRAY)
+       {
+           /* Reject if resulting width difference is >= 1 pixel */
+           if (fabs(rescale * from->width - *dx * from->width) >= 10)
+               return FALSE;
+       }
+       else
+       {
+           *rescale_x = rescale/(*dx);
+           *dx = rescale;
+       }
+    }
+
+    if (srcpixel >= EPS)
+    {
+       *dy = destpixel / srcpixel;
+       *sdy = 1000.0 / srcpixel;
+    }
+    else
+       *sdy = *dy = 0;
+
+    return TRUE;
+}
+
+/* favor enlargement over reduction because of aliasing resulting
+   from reduction */
+#define SCORE(m,s) \
+if (m >= 1.0) { \
+    if (m == 1.0) \
+        score += (16 * s); \
+    else if (m == 2.0) \
+        score += (4 * s); \
+    else \
+        score += (int)(((double)(3 * s)) / m); \
+} else { \
+        score += (int)(((double)(2 * s)) * m); \
+}
+
+/* don't need to favor enlargement when looking for bitmap that can
+   be used unscalable */
+#define SCORE2(m,s) \
+if (m >= 1.0) \
+    score += (int)(((double)(8 * s)) / m); \
+else \
+    score += (int)(((double)(8 * s)) * m);
+
+static FontEntryPtr
+FindBestToScale(fpe, entry, vals, best, dxp, dyp, sdxp, sdyp, fpep)
+    FontPathElementPtr fpe;
+    FontEntryPtr       entry;
+    FontScalablePtr    vals,
+                       best;
+    double             *dxp, *sdxp,
+                       *dyp, *sdyp;
+    FontPathElementPtr *fpep;
+{
+    FontScalableRec temp;
+    int                    source, i;
+    int                    best_score, best_unscaled_score,
+                   score;
+    double         dx, sdx, dx_amount,
+                   dy, sdy, dy_amount,
+                   best_dx, best_sdx, best_dx_amount,
+                   best_dy, best_sdy, best_dy_amount,
+                   best_unscaled_sdx, best_unscaled_sdy,
+                   rescale_x, best_rescale_x,
+                   best_unscaled_rescale_x;
+    FontEntryPtr    zero;
+    FontNameRec            zeroName;
+    char           zeroChars[MAXFONTNAMELEN];
+    FontDirectoryPtr   dir;
+    FontScaledPtr   scaled;
+    FontScalableExtraPtr   extra;
+    FontScaledPtr   best_scaled, best_unscaled;
+    FontPathElementPtr best_fpe, best_unscaled_fpe;
+    FontEntryPtr    bitmap = NULL;
+    FontEntryPtr    result;
+    int                    aliascount = 20;
+    FontPathElementPtr bitmap_fpe;
+    FontNameRec            xlfdName;
+
+    /* find the best match */
+    rescale_x = 1.0;
+    best_scaled = 0;
+    best_score = 0;
+    best_unscaled = 0;
+    best_unscaled_score = -1;
+    memcpy (zeroChars, entry->name.name, entry->name.length);
+    zeroChars[entry->name.length] = '\0';
+    zeroName.name = zeroChars;
+    FontParseXLFDName (zeroChars, &temp, FONT_XLFD_REPLACE_ZERO);
+    zeroName.length = strlen (zeroChars);
+    zeroName.ndashes = entry->name.ndashes;
+    xlfdName.name = vals->xlfdName;
+    xlfdName.length = strlen(xlfdName.name);
+    xlfdName.ndashes = FontFileCountDashes(xlfdName.name, xlfdName.length);
+    restart_bestscale_loop: ;
+    /*
+     * Look through all the registered bitmap sources for
+     * the same zero name as ours; entries along that one
+     * can be scaled as desired.
+     */
+    for (source = 0; source < FontFileBitmapSources.count; source++)
+    {
+       /* There might already be a bitmap that satisfies the request
+          but didn't have a zero name that was found by the scalable
+          font matching logic.  Keep track if there is.  */
+       if (bitmap == NULL && vals->xlfdName != NULL)
+       {
+           bitmap_fpe = FontFileBitmapSources.fpe[source];
+           dir = (FontDirectoryPtr) bitmap_fpe->private;
+           bitmap = FontFileFindNameInDir (&dir->nonScalable, &xlfdName);
+           if (bitmap && bitmap->type != FONT_ENTRY_BITMAP)
+           {
+               if (bitmap->type == FONT_ENTRY_ALIAS && aliascount > 0)
+               {
+                   aliascount--;
+                   xlfdName.name = bitmap->u.alias.resolved;
+                   xlfdName.length = strlen(xlfdName.name);
+                   xlfdName.ndashes = FontFileCountDashes(xlfdName.name,
+                                                          xlfdName.length);
+                   bitmap = NULL;
+                   goto restart_bestscale_loop;
+               }
+               else
+                   bitmap = NULL;
+           }
+       }
+
+       if (FontFileBitmapSources.fpe[source] == fpe)
+           zero = entry;
+       else
+       {
+           dir = (FontDirectoryPtr) FontFileBitmapSources.fpe[source]->private;
+           zero = FontFileFindNameInDir (&dir->scalable, &zeroName);
+           if (!zero)
+               continue;
+       }
+       extra = zero->u.scalable.extra;
+       for (i = 0; i < extra->numScaled; i++)
+       {
+           FontScalableRec tmpvals;
+           scaled = &extra->scaled[i];
+           if (!scaled->bitmap)
+               continue;
+           if (!ComputeScaleFactors(&scaled->vals, vals, &dx, &dy, &sdx, &sdy,
+                                    &rescale_x))
+               continue;
+           score = 0;
+           dx_amount = dx;
+           dy_amount = dy;
+           SCORE(dy_amount, 10);
+           SCORE(dx_amount, 1);
+           if ((score > best_score) ||
+                   ((score == best_score) &&
+                    ((dy_amount < best_dy_amount) ||
+                     ((dy_amount == best_dy_amount) &&
+                      (dx_amount < best_dx_amount))))) 
+           {
+               best_fpe = FontFileBitmapSources.fpe[source];
+               best_scaled = scaled;
+               best_score = score;
+               best_dx = dx;
+               best_dy = dy;
+               best_sdx = sdx;
+               best_sdy = sdy;
+               best_dx_amount = dx_amount;
+               best_dy_amount = dy_amount;
+               best_rescale_x = rescale_x;
+           }
+           /* Is this font a candidate for use without ugly rescaling? */
+           if (fabs(dx) > EPS && fabs(dy) > EPS &&
+               fabs(vals->pixel_matrix[0] * rescale_x -
+                    scaled->vals.pixel_matrix[0]) < 1 &&
+               fabs(vals->pixel_matrix[1] * rescale_x -
+                    scaled->vals.pixel_matrix[1]) < EPS &&
+               fabs(vals->pixel_matrix[2] -
+                    scaled->vals.pixel_matrix[2]) < EPS &&
+               fabs(vals->pixel_matrix[3] -
+                    scaled->vals.pixel_matrix[3]) < 1)
+           {
+               /* Yes.  The pixel sizes are close on the diagonal and
+                  extremely close off the diagonal. */
+               score = 0;
+               SCORE2(vals->pixel_matrix[3] /
+                      scaled->vals.pixel_matrix[3], 10);
+               SCORE2(vals->pixel_matrix[0] * rescale_x /
+                      scaled->vals.pixel_matrix[0], 1);
+               if (score > best_unscaled_score)
+               {
+                   best_unscaled_fpe = FontFileBitmapSources.fpe[source];
+                   best_unscaled = scaled;
+                   best_unscaled_sdx = sdx / dx;
+                   best_unscaled_sdy = sdy / dy;
+                   best_unscaled_score = score;
+                   best_unscaled_rescale_x = rescale_x;
+               }
+           }
+       }
+    }
+    if (best_unscaled)
+    {
+       *best = best_unscaled->vals;
+       *fpep = best_unscaled_fpe;
+       *dxp = 1.0;
+       *dyp = 1.0;
+       *sdxp = best_unscaled_sdx;
+       *sdyp = best_unscaled_sdy;
+       rescale_x = best_unscaled_rescale_x;
+       result = best_unscaled->bitmap;
+    }
+    else if (best_scaled)
+    {
+       *best = best_scaled->vals;
+       *fpep = best_fpe;
+       *dxp = best_dx;
+       *dyp = best_dy;
+       *sdxp = best_sdx;
+       *sdyp = best_sdy;
+       rescale_x = best_rescale_x;
+       result = best_scaled->bitmap;
+    }
+    else
+       result = NULL;
+
+    if (bitmap != NULL && (result == NULL || *dxp != 1.0 || *dyp != 1.0))
+    {
+       *fpep = bitmap_fpe;
+       FontParseXLFDName (bitmap->name.name, best, FONT_XLFD_REPLACE_NONE);
+       if (ComputeScaleFactors(best, best, dxp, dyp, sdxp, sdyp, &rescale_x))
+           result = bitmap;
+       else
+           result = NULL;
+    }
+
+    if (result && rescale_x != 1.0)
+    {
+       /* We have rescaled horizontally due to an XLFD width field.  Change
+          the matrix appropriately */
+       vals->pixel_matrix[0] *= rescale_x;
+       vals->pixel_matrix[1] *= rescale_x;
+#ifdef NOTDEF
+       /* This would force the pointsize and pixelsize fields in the
+          FONT property to display as matrices to more accurately
+          report the font being supplied.  It might also break existing
+          applications that expect a single number in that field. */
+       vals->values_supplied =
+           vals->values_supplied & ~(PIXELSIZE_MASK | POINTSIZE_MASK) |
+           PIXELSIZE_ARRAY;
+#else /* NOTDEF */
+       vals->values_supplied = vals->values_supplied & ~POINTSIZE_MASK;
+#endif /* NOTDEF */
+       /* Recompute and reround the FontScalablePtr values after
+          rescaling for the new width. */
+       FontFileCompleteXLFD(vals, vals);
+    }
+
+    return result;
+}
+
+static FontEntryPtr
+FindPmfToScale(fpe, entry, vals, best, dxp, dyp, sdxp, sdyp, fpep)
+    FontPathElementPtr fpe;
+    FontEntryPtr       entry;
+    FontScalablePtr    vals,
+                       best;
+    double             *dxp, *sdxp,
+                       *dyp, *sdyp;
+    FontPathElementPtr *fpep;
+{
+    FontEntryPtr    result = NULL;
+    FontScaledPtr   scaled;
+    FontScalableExtraPtr   extra;
+    int i;
+
+    extra = entry->u.scalable.extra;
+    for (i = 0; i < extra->numScaled; i++)
+    {
+       double rescale_x;
+
+       scaled = &extra->scaled[i];
+       if (!scaled->bitmap)
+           continue;
+       if (!ComputeScaleFactors(&scaled->vals, vals, dxp, dyp, sdxp, sdyp,
+                                &rescale_x))
+           continue;
+       *best = scaled->vals;
+       *fpep = fpe;
+       result = scaled->bitmap;
+       if (rescale_x != 1.0)
+       {
+           /* We have rescaled horizontally due to an XLFD width field.  Change
+              the matrix appropriately */
+           vals->pixel_matrix[0] *= rescale_x;
+           vals->pixel_matrix[1] *= rescale_x;
+#ifdef NOTDEF
+           /* This would force the pointsize and pixelsize fields in the
+              FONT property to display as matrices to more accurately
+              report the font being supplied.  It might also break existing
+              applications that expect a single number in that field. */
+           vals->values_supplied =
+               vals->values_supplied & ~(PIXELSIZE_MASK | POINTSIZE_MASK) |
+               PIXELSIZE_ARRAY;
+#else /* NOTDEF */
+           vals->values_supplied = vals->values_supplied & ~POINTSIZE_MASK;
+#endif /* NOTDEF */
+           /* Recompute and reround the FontScalablePtr values after
+              rescaling for the new width. */
+           FontFileCompleteXLFD(vals, vals);
+       }
+       break;
+    }
+    return result;
+}
+
+static long
+doround(x)
+double x;
+{
+    return (x >= 0) ? (long)(x + .5) : (long)(x - .5);
+}
+
+static int
+computeProps(pf, wasStringProp, npf, isStringProp, nprops, xfactor, yfactor,
+            sXfactor, sYfactor)
+    FontPropPtr pf;
+    char       *wasStringProp;
+    FontPropPtr npf;
+    char       *isStringProp;
+    unsigned int nprops;
+    double      xfactor, sXfactor,
+                yfactor, sYfactor;
+{
+    int         n;
+    int         count;
+    fontProp   *t;
+    double      rawfactor;
+
+    for (count = 0; nprops > 0; nprops--, pf++, wasStringProp++) {
+       n = sizeof(fontPropTable) / sizeof(fontProp);
+       for (t = fontPropTable; n && (t->atom != pf->name); n--, t++);
+       if (!n)
+           continue;
+
+       switch (t->type) {
+       case scaledX:
+           npf->value = doround(xfactor * (double)pf->value);
+           rawfactor = sXfactor;
+           break;
+       case scaledY:
+           npf->value = doround(yfactor * (double)pf->value);
+           rawfactor = sYfactor;
+           break;
+       case unscaled:
+           npf->value = pf->value;
+           npf->name = pf->name;
+           npf++;
+           count++;
+           *isStringProp++ = *wasStringProp;
+           break;
+       }
+       if (t->type != unscaled)
+       {
+           npf->name = pf->name;
+           npf++;
+           count++;
+           npf->value = doround(rawfactor * (double)pf->value);
+           npf->name = rawFontPropTable[t - fontPropTable].atom;
+           npf++;
+           count++;
+           *isStringProp++ = *wasStringProp;
+           *isStringProp++ = *wasStringProp;
+       }
+    }
+    return count;
+}
+
+
+static int
+ComputeScaledProperties(sourceFontInfo, name, vals, dx, dy, sdx, sdy,
+                       sWidth, pProps, pIsStringProp)
+    FontInfoPtr     sourceFontInfo;    /* the font to be scaled */
+    char           *name;              /* name of resulting font */
+    FontScalablePtr vals;
+    double         dx, sdx,
+                   dy, sdy;    /* scale factors in x and y directions */
+    long           sWidth;     /* 1000-pixel average width */
+    FontPropPtr            *pProps;    /* returns properties; preallocated */
+    char           **pIsStringProp;  /* return booleans; preallocated */
+{
+    int         n;
+    char       *ptr1,
+               *ptr2;
+    char       *ptr3;
+    FontPropPtr fp;
+    fontProp   *fpt;
+    extern int  serverGeneration;
+    char       *isStringProp;
+    int                nProps;
+
+    if (fontGeneration != serverGeneration) {
+       initFontPropTable();
+       fontGeneration = serverGeneration;
+    }
+    nProps = NPROPS + 1 + sizeof(fontPropTable) / sizeof(fontProp) +
+                         sizeof(rawFontPropTable) / sizeof(fontProp);
+    fp = (FontPropPtr) xalloc(sizeof(FontPropRec) * nProps);
+    *pProps = fp;
+    if (!fp)
+       return 1;
+    isStringProp = (char *) xalloc (nProps);
+    *pIsStringProp = isStringProp;
+    if (!isStringProp)
+    {
+       xfree (fp);
+       return 1;
+    }
+    ptr2 = name;
+    for (fpt = fontNamePropTable, n = NPROPS;
+        n;
+        fp++, fpt++, n--, isStringProp++)
+    {
+
+       if (*ptr2)
+       {
+           ptr1 = ptr2 + 1;
+           if (!(ptr2 = strchr(ptr1, '-'))) ptr2 = strchr(ptr1, '\0');
+       }
+
+       *isStringProp = 0;
+       switch (fpt->type) {
+       case atom:
+           fp->value = MakeAtom(ptr1, ptr2 - ptr1, TRUE);
+           *isStringProp = 1;
+           break;
+       case truncate_atom:
+           for (ptr3 = ptr1; *ptr3; ptr3++)
+               if (*ptr3 == '[')
+                   break;
+           if (!*ptr3) ptr3 = ptr2;
+           fp->value = MakeAtom(ptr1, ptr3 - ptr1, TRUE);
+           *isStringProp = 1;
+           break;
+       case pixel_size:
+           fp->value = doround(vals->pixel_matrix[3]);
+           break;
+       case point_size:
+           fp->value = doround(vals->point_matrix[3] * 10.0);
+           break;
+       case resolution_x:
+           fp->value = vals->x;
+           break;
+       case resolution_y:
+           fp->value = vals->y;
+           break;
+       case average_width:
+           fp->value = vals->width;
+           break;
+       case fontname:
+           fp->value = MakeAtom(name, strlen(name), TRUE);
+           *isStringProp = 1;
+           break;
+       case raw_ascent:
+           fp->value = sourceFontInfo->fontAscent * sdy;
+           break;
+       case raw_descent:
+           fp->value = sourceFontInfo->fontDescent * sdy;
+           break;
+       case raw_pointsize:
+           fp->value = (long)(72270.0 / (double)vals->y + .5);
+           break;
+       case raw_pixelsize:
+           fp->value = 1000;
+           break;
+       case raw_average_width:
+           fp->value = sWidth;
+           break;
+       }
+       fp->name = fpt->atom;
+    }
+    n = NPROPS;
+    n += computeProps(sourceFontInfo->props, sourceFontInfo->isStringProp,
+                     fp, isStringProp, sourceFontInfo->nprops, dx, dy,
+                     sdx, sdy);
+    return n;
+}
+
+static void ScaleBitmap();
+
+static int
+compute_xform_matrix(vals, dx, dy, xform, inv_xform, xmult, ymult)
+    FontScalablePtr    vals;
+    double             dx, dy, *inv_xform, *xmult, *ymult;
+    register double    *xform;
+{
+    double det, sintheta, costheta, tanphi;
+    double pixel = get_matrix_vertical_component(vals->pixel_matrix);
+    double pixelset = get_matrix_horizontal_component(vals->pixel_matrix);
+
+    if (pixel < EPS || pixelset < EPS) return 0;
+
+    /* Initialize the transformation matrix to the scaling factors */
+    xform[0] = dx / pixelset;
+    xform[1] = xform[2] = 0.0;
+    xform[3] = dy / pixel;
+
+/* Inline matrix multiply -- somewhat ugly to minimize register usage */
+#define MULTIPLY_XFORM(a,b,c,d) \
+{ \
+  register double aa = (a), bb = (b), cc = (c), dd = (d); \
+  register double temp; \
+  temp =     aa * xform[0] + cc * xform[1]; \
+  aa =       aa * xform[2] + cc * xform[3]; \
+  xform[1] = bb * xform[0] + dd * xform[1]; \
+  xform[3] = bb * xform[2] + dd * xform[3]; \
+  xform[0] = temp; \
+  xform[2] = aa; \
+}
+
+    /* Rescale the transformation matrix for size of source font */
+    MULTIPLY_XFORM(vals->pixel_matrix[0],
+                  vals->pixel_matrix[1],
+                  vals->pixel_matrix[2],
+                  vals->pixel_matrix[3]);
+
+    *xmult = xform[0];
+    *ymult = xform[3];
+
+
+    if (inv_xform == NULL) return 1;
+
+    /* Compute the determinant for use in inverting the matrix. */
+    det = xform[0] * xform[3] - xform[1] * xform[2];
+
+    /* If the determinant is tiny or zero, give up */
+    if (fabs(det) < EPS) return 0;
+
+    /* Compute the inverse */
+    inv_xform[0] = xform[3] / det;
+    inv_xform[1] = -xform[1] / det;
+    inv_xform[2] = -xform[2] / det;
+    inv_xform[3] = xform[0] / det;
+
+    return 1;
+}
+
+/*
+ *  ScaleFont
+ *  returns a pointer to the new scaled font, or NULL (due to AllocError).
+ */
+static FontPtr
+ScaleFont(opf, widthMult, heightMult, sWidthMult, sHeightMult, vals,
+         newWidthMult, newHeightMult, sWidth)
+    FontPtr     opf;           /* originating font */
+    double      widthMult;     /* glyphs width scale factor */
+    double      heightMult;    /* glyphs height scale factor */
+    double      sWidthMult;    /* scalable glyphs width scale factor */
+    double      sHeightMult;   /* scalable glyphs height scale factor */
+    FontScalablePtr    vals;
+    double      *newWidthMult; /* return: X component of glyphs width
+                                  scale factor */
+    double      *newHeightMult;        /* return: Y component of glyphs height
+                                  scale factor */
+    long       *sWidth;        /* return: average 1000-pixel width */
+{
+    FontPtr     pf;
+    FontInfoPtr pfi,
+                opfi;
+    BitmapFontPtr  bitmapFont,
+                obitmapFont;
+    CharInfoPtr pci,
+                opci;
+    int         nchars;                /* how many characters in the font */
+    int        *scratch;
+    int         i;
+    int         glyph;
+    int                firstCol, lastCol, firstRow, lastRow;
+    double     xform[4], inv_xform[4];
+    double     xmult, ymult;
+    int                totalwidth = 0, totalchars = 0;
+    int                inkindex1, inkindex2;
+#define OLDINDEX(i) (((i)/(lastCol - firstCol + 1) + \
+                     firstRow - opf->info.firstRow) * \
+                    (opf->info.lastCol - opf->info.firstCol + 1) + \
+                    (i)%(lastCol - firstCol + 1) + \
+                    firstCol - opf->info.firstCol)
+
+    extern int  bitmapGetBitmaps();
+    extern int  bitmapGetExtents();
+    extern int  bitmapGetGlyphs();
+    extern int  bitmapGetMetrics();
+
+    *sWidth = 0;
+
+    opfi = &opf->info;
+    glyph = opf->glyph;
+    obitmapFont = (BitmapFontPtr) opf->fontPrivate;
+
+    bitmapFont = 0;
+    pf = (FontPtr) xalloc(sizeof(FontRec));
+    if (!pf)
+       goto bail;
+    pf->refcnt = 0;
+    pf->maxPrivate = -1;
+    pf->devPrivates = (pointer *) 0;
+    pf->bit = opf->bit;
+    pf->byte = opf->byte;
+    pf->glyph = opf->glyph;
+    pf->scan = opf->scan;
+
+    pf->get_glyphs = bitmapGetGlyphs;
+    pf->get_metrics = bitmapGetMetrics;
+    pf->unload_font = bitmapUnloadScalable;
+    pf->unload_glyphs = NULL;
+
+    pfi = &pf->info;
+    *pfi = *opfi;
+    /* If charset subsetting specified in vals, determine what our range
+       needs to be for the output font */
+    if (vals->nranges)
+    {
+       int i;
+
+       pfi->allExist = 0;
+       firstCol = 255;
+       lastCol = 0;
+       firstRow = 255;
+       lastRow = 0;
+
+       for (i = 0; i < vals->nranges; i++)
+       {
+           if (vals->ranges[i].min_char_high != vals->ranges[i].max_char_high)
+           {
+               firstCol = opfi->firstCol;
+               lastCol = opfi->lastCol;
+           }
+           if (firstCol > vals->ranges[i].min_char_low)
+               firstCol = vals->ranges[i].min_char_low;
+           if (lastCol < vals->ranges[i].max_char_low)
+               lastCol = vals->ranges[i].max_char_low;
+           if (firstRow > vals->ranges[i].min_char_high)
+               firstRow = vals->ranges[i].min_char_high;
+           if (lastRow < vals->ranges[i].max_char_high)
+               lastRow = vals->ranges[i].max_char_high;
+       }
+
+       if (firstCol > lastCol || firstRow > lastRow)
+           goto bail;
+
+       if (firstCol < opfi->firstCol)
+           firstCol = opfi->firstCol;
+       if (lastCol > opfi->lastCol)
+           lastCol = opfi->lastCol;
+       if (firstRow < opfi->firstRow)
+           firstRow = opfi->firstRow;
+       if (lastRow > opfi->lastRow)
+           lastRow = opfi->lastRow;
+    }
+    else
+    {
+       firstCol = opfi->firstCol;
+       lastCol = opfi->lastCol;
+       firstRow = opfi->firstRow;
+       lastRow = opfi->lastRow;
+    }
+
+    bitmapFont = (BitmapFontPtr) xalloc(sizeof(BitmapFontRec));
+    if (!bitmapFont)
+       goto bail;
+    nchars = (lastRow - firstRow + 1) * (lastCol - firstCol + 1);
+    pfi->firstRow = firstRow;
+    pfi->lastRow = lastRow;
+    pfi->firstCol = firstCol;
+    pfi->lastCol = lastCol;
+    pf->fontPrivate = (pointer) bitmapFont;
+    bitmapFont->version_num = obitmapFont->version_num;
+    bitmapFont->num_chars = nchars;
+    bitmapFont->num_tables = obitmapFont->num_tables;
+    bitmapFont->metrics = 0;
+    bitmapFont->ink_metrics = 0;
+    bitmapFont->bitmaps = 0;
+    bitmapFont->encoding = 0;
+    bitmapFont->bitmapExtra = 0;
+    bitmapFont->pDefault = 0;
+    bitmapFont->metrics = (CharInfoPtr) xalloc(nchars * sizeof(CharInfoRec));
+    if (!bitmapFont->metrics)
+       goto bail;
+    bitmapFont->encoding = (CharInfoPtr *) xalloc(nchars * sizeof(CharInfoPtr));
+    if (!bitmapFont->encoding)
+       goto bail;
+
+#undef MAXSHORT
+#define MAXSHORT    32767
+#undef MINSHORT
+#define MINSHORT    -32768
+
+    pfi->anamorphic = FALSE;
+    if (heightMult != widthMult)
+       pfi->anamorphic = TRUE;
+    pfi->cachable = TRUE;
+
+    if (!compute_xform_matrix(vals, widthMult, heightMult, xform,
+                             inv_xform, &xmult, &ymult))
+       goto bail;
+
+    pfi->fontAscent = opfi->fontAscent * ymult;
+    pfi->fontDescent = opfi->fontDescent * ymult;
+
+    pfi->minbounds.leftSideBearing = MAXSHORT;
+    pfi->minbounds.rightSideBearing = MAXSHORT;
+    pfi->minbounds.ascent = MAXSHORT;
+    pfi->minbounds.descent = MAXSHORT;
+    pfi->minbounds.characterWidth = MAXSHORT;
+    pfi->minbounds.attributes = MAXSHORT;
+
+    pfi->maxbounds.leftSideBearing = MINSHORT;
+    pfi->maxbounds.rightSideBearing = MINSHORT;
+    pfi->maxbounds.ascent = MINSHORT;
+    pfi->maxbounds.descent = MINSHORT;
+    pfi->maxbounds.characterWidth = MINSHORT;
+    pfi->maxbounds.attributes = MINSHORT;
+
+    /* Compute the transformation and inverse transformation matrices.
+       Can fail if the determinant is zero. */
+
+    inkindex1 = 0;
+    pci = bitmapFont->metrics;
+    for (i = 0; i < nchars; i++)
+    {
+       if (opci = obitmapFont->encoding[inkindex2 = OLDINDEX(i)])
+       {
+           double newlsb, newrsb, newdesc, newasc, point[2];
+
+#define minchar(p) ((p).min_char_low + ((p).min_char_high << 8))
+#define maxchar(p) ((p).max_char_low + ((p).max_char_high << 8))
+
+           if (vals->nranges)
+           {
+               int row = i / (lastCol - firstCol + 1) + firstRow;
+               int col = i % (lastCol - firstCol + 1) + firstCol;
+               int ch = (row << 8) + col;
+               int j;
+               for (j = 0; j < vals->nranges; j++)
+                   if (ch >= minchar(vals->ranges[j]) &&
+                       ch <= maxchar(vals->ranges[j]))
+                       break;
+               if (j == vals->nranges)
+               {
+                   bitmapFont->encoding[i] = 0;
+                   continue;
+               }
+           }
+
+           if (opci->metrics.leftSideBearing == 0 &&
+               opci->metrics.rightSideBearing == 0 &&
+               opci->metrics.ascent == 0 &&
+               opci->metrics.descent == 0 &&
+               opci->metrics.characterWidth == 0)
+           {
+               bitmapFont->encoding[i] = 0;
+               continue;
+           }
+
+           bitmapFont->encoding[i] = pci;
+
+           /* Compute new extents for this glyph */
+           TRANSFORM_POINT(xform,
+                           opci->metrics.leftSideBearing,
+                           -opci->metrics.descent,
+                           point);
+           newlsb = point[0];
+           newrsb = newlsb;
+           newdesc = -point[1];
+           newasc = -newdesc;
+           TRANSFORM_POINT(xform,
+                           opci->metrics.leftSideBearing,
+                           opci->metrics.ascent,
+                           point);
+           CHECK_EXTENT(newlsb, newrsb, newdesc, newasc, point);
+           TRANSFORM_POINT(xform,
+                           opci->metrics.rightSideBearing,
+                           -opci->metrics.descent,
+                           point);
+           CHECK_EXTENT(newlsb, newrsb, newdesc, newasc, point);
+           TRANSFORM_POINT(xform,
+                           opci->metrics.rightSideBearing,
+                           opci->metrics.ascent,
+                           point);
+           CHECK_EXTENT(newlsb, newrsb, newdesc, newasc, point);
+
+           pci->metrics.leftSideBearing = (int)floor(newlsb);
+           pci->metrics.rightSideBearing = (int)floor(newrsb + .5);
+           pci->metrics.descent = (int)ceil(newdesc);
+           pci->metrics.ascent = (int)floor(newasc + .5);
+           /* Accumulate total width of characters before transformation,
+              to ascertain predominant direction of font. */
+           totalwidth += opci->metrics.characterWidth;
+           pci->metrics.characterWidth =
+               doround((double)opci->metrics.characterWidth * xmult);
+           pci->metrics.attributes =
+               doround((double)opci->metrics.characterWidth * sWidthMult);
+           if (!pci->metrics.characterWidth)
+           {
+               /* Since transformation may shrink width, height, and
+                  escapement to zero, make sure existing characters
+                  are not mistaken for undefined characters. */
+
+               if (pci->metrics.rightSideBearing ==
+                   pci->metrics.leftSideBearing)
+                   pci->metrics.rightSideBearing++;
+               if (pci->metrics.ascent == -pci->metrics.descent)
+                   pci->metrics.ascent++;
+           }
+    
+           pci++;
+       }
+       else
+           bitmapFont->encoding[i] = 0;
+    }
+
+
+    /*
+     * For each character, set the per-character metrics, scale the glyph, and
+     * check per-font minbounds and maxbounds character information.
+     */
+
+    pci = bitmapFont->metrics;
+    for (i = 0; i < nchars; i++)
+    {
+       CharInfoRec temppci;
+       if ((pci = bitmapFont->encoding[i]) &&
+           (opci = obitmapFont->encoding[OLDINDEX(i)]))
+       {
+           pci = bitmapFont->encoding[i];
+           totalchars++;
+           *sWidth += abs((int)(INT16)pci->metrics.attributes);
+#define MINMAX(field) \
+           if (pfi->minbounds.field > pci->metrics.field) \
+               pfi->minbounds.field = pci->metrics.field; \
+           if (pfi->maxbounds.field < pci->metrics.field) \
+               pfi->maxbounds.field = pci->metrics.field
+    
+           MINMAX(leftSideBearing);
+           MINMAX(rightSideBearing);
+           MINMAX(ascent);
+           MINMAX(descent);
+           MINMAX(characterWidth);
+
+           /* Hack: Cast attributes into a signed quantity.  Tread lightly
+              for now and don't go changing the global Xproto.h file */
+           if ((INT16)pfi->minbounds.attributes >
+               (INT16)pci->metrics.attributes)
+               pfi->minbounds.attributes = pci->metrics.attributes;
+           if ((INT16)pfi->maxbounds.attributes <
+               (INT16)pci->metrics.attributes)
+               pfi->maxbounds.attributes = pci->metrics.attributes;
+#undef MINMAX
+       }
+    }
+    pfi->ink_minbounds = pfi->minbounds;
+    pfi->ink_maxbounds = pfi->maxbounds;
+    if (totalchars)
+    {
+       *sWidth = (*sWidth * 10 + totalchars / 2) / totalchars;
+       if (totalwidth < 0)
+       {
+           /* Dominant direction is R->L */
+           *sWidth = -*sWidth;
+       }
+
+       if (pfi->minbounds.characterWidth == pfi->maxbounds.characterWidth)
+           vals->width = pfi->minbounds.characterWidth * 10;
+       else
+           vals->width = doround((double)*sWidth * vals->pixel_matrix[0] /
+                                 1000.0);
+    }
+    else
+    {
+       vals->width = 0;
+       *sWidth = 0;
+    }
+    FontComputeInfoAccelerators (pfi);
+
+    if (pfi->defaultCh != (unsigned short) NO_SUCH_CHAR) {
+       unsigned int r,
+                   c,
+                   cols;
+
+       r = pfi->defaultCh >> 8;
+       c = pfi->defaultCh & 0xFF;
+       if (pfi->firstRow <= r && r <= pfi->lastRow &&
+               pfi->firstCol <= c && c <= pfi->lastCol) {
+           cols = pfi->lastCol - pfi->firstCol + 1;
+           r = r - pfi->firstRow;
+           c = c - pfi->firstCol;
+           bitmapFont->pDefault = bitmapFont->encoding[r * cols + c];
+       }
+    }
+
+    *newWidthMult = xmult;
+    *newHeightMult = ymult;
+    return pf;
+bail:
+    if (pf)
+       xfree(pf);
+    if (bitmapFont) {
+       xfree(bitmapFont->metrics);
+       xfree(bitmapFont->ink_metrics);
+       xfree(bitmapFont->bitmaps);
+       xfree(bitmapFont->encoding);
+    }
+    return NULL;
+}
+
+static int
+lcm(a, b)                      /* least common multiple */
+    int         a,
+                b;
+{
+    register int m;
+    register int larger,
+                smaller;
+
+    if (a > b) {
+       m = larger = a;
+       smaller = b;
+    } else {
+       m = larger = b;
+       smaller = a;
+    }
+
+    while (m % smaller)
+       m += larger;
+    return m;
+}
+
+static void
+ScaleBitmap(pFont, opci, pci, inv_xform, widthMult, heightMult)
+    FontPtr     pFont;
+    CharInfoPtr opci;
+    CharInfoPtr pci;
+    double     *inv_xform;
+    double     widthMult;
+    double     heightMult;
+{
+    register char  *bitmap,            /* The bits */
+               *newBitmap;
+    register int   bpr,                        /* Padding information */
+               newBpr;
+    int         width,                 /* Extents information */
+                height,
+                newWidth,
+                newHeight;
+    register int row,                  /* Loop variables */
+               col;
+    INT32      deltaX,                 /* Increments for resampling loop */
+               deltaY;
+    INT32      xValue,                 /* Subscripts for resampling loop */
+               yValue;
+    double     point[2];
+    unsigned char *char_grayscale = 0;
+    INT32      *diffusion_workspace, *thisrow, *nextrow, pixmult;
+    int                box_x, box_y;
+
+    static unsigned char masklsb[] =
+       { 0x1, 0x2, 0x4, 0x8, 0x10, 0x20, 0x40, 0x80 };
+    static unsigned char maskmsb[] =
+       { 0x80, 0x40, 0x20, 0x10, 0x8, 0x4, 0x2, 0x1 };
+    unsigned char      *mask = (pFont->bit == LSBFirst ? masklsb : maskmsb);
+
+
+    bitmap = opci->bits;
+    newBitmap = pci->bits;
+    width = GLYPHWIDTHPIXELS(opci);
+    height = GLYPHHEIGHTPIXELS(opci);
+    newWidth = GLYPHWIDTHPIXELS(pci);
+    newHeight = GLYPHHEIGHTPIXELS(pci);
+    if (!newWidth || !newHeight || !width || !height)
+       return;
+
+    bpr = BYTES_PER_ROW(width, pFont->glyph);
+    newBpr = BYTES_PER_ROW(newWidth, pFont->glyph);
+
+    if (widthMult > 0.0 && heightMult > 0.0 &&
+       (widthMult < 1.0 || heightMult < 1.0))
+    {
+       /* We are reducing in one or both dimensions.  In an attempt to
+          reduce aliasing, we'll antialias by passing the original
+          glyph through a low-pass box filter (which results in a
+          grayscale image), then use error diffusion to create bitonal
+          output in the resampling loop.  */
+
+       /* First compute the sizes of the box filter */
+       widthMult = ceil(1.0 / widthMult);
+       heightMult = ceil(1.0 / heightMult);
+       box_x = width / 2;
+       box_y = height / 2;
+       if (widthMult < (double)box_x) box_x = (int)widthMult;
+       if (heightMult < (double)box_y) box_y = (int)heightMult;
+       /* The pixmult value (below) is used to darken the image before
+          we perform error diffusion: a necessary concession to the
+          fact that it's very difficult to generate readable halftoned
+          glyphs.  The degree of darkening is proportional to the size
+          of the blurring filter, hence inversely proportional to the
+          darkness of the lightest gray that results from antialiasing.
+          The result is that characters that exercise this logic (those
+          generated by reducing from a larger source font) tend to err
+          on the side of being too bold instead of being too light to
+          be readable. */
+       pixmult = box_x * box_y * 192;
+
+       if (box_x > 1 || box_y > 1)
+       {
+           /* Looks like we need to anti-alias.  Create a workspace to
+              contain the grayscale character plus an additional row and
+              column for scratch */
+           char_grayscale =
+               (unsigned char *)xalloc((width + 1) * (height + 1));
+           if (char_grayscale)
+           {
+               diffusion_workspace =
+                   (INT32 *)xalloc((newWidth + 2) * 2 * sizeof(int));
+               if (!diffusion_workspace)
+               {
+                   xfree(char_grayscale);
+                   char_grayscale = (unsigned char *)0;
+               }
+               /* Initialize our error diffusion workspace for later use */
+               bzero((char *)diffusion_workspace + sizeof(INT32),
+                     (newWidth + 3) * sizeof(int));
+               thisrow = diffusion_workspace + 1;
+               nextrow = diffusion_workspace + newWidth + 3;
+           }
+       }
+    }
+
+    if (char_grayscale)
+    {
+       /* We will be doing antialiasing.  First copy the bitmap into
+          our buffer, mapping input range [0,1] to output range
+          [0,255].  */
+       register unsigned char *srcptr, *dstptr;
+       srcptr = (unsigned char *)bitmap;
+       dstptr = char_grayscale;
+       for (row = 0; row < height; row++)
+       {
+           for (col = 0; col < width; col++)
+               *dstptr++ = (srcptr[col >> 3] & mask[col & 0x7]) ? 255 : 0;
+           srcptr += bpr;      /* On to next row of source */
+           dstptr++;           /* Skip scratch column in dest */
+       }
+       if (box_x > 1)
+       {
+           /* Our box filter has a width > 1... let's filter the rows */
+
+           int right_width = box_x / 2;
+           int left_width = box_x - right_width - 1;
+
+           for (row = 0; row < height; row++)
+           {
+               int sum = 0;
+               int left_size = 0, right_size = 0;
+
+               srcptr = char_grayscale + (width + 1) * row;
+               dstptr = char_grayscale + (width + 1) * height; /* scratch */
+
+               /* We've computed the shape of our full box filter.  Now
+                  compute the right-hand part of the moving sum */
+               for (right_size = 0; right_size < right_width; right_size++)
+                   sum += srcptr[right_size];
+
+               /* Now start moving the sum, growing the box filter, and
+                  dropping averages into our scratch buffer */
+               for (left_size = 0; left_size < left_width; left_size++)
+               {
+                   sum += srcptr[right_width];
+                   *dstptr++ = sum / (left_size + right_width + 1);
+                   srcptr++;
+               }
+
+               /* The box filter has reached full width... continue
+                  computation of moving average until the right side
+                  hits the wall. */
+               for (col = left_size; col + right_size < width; col++)
+               {
+                   sum += srcptr[right_width];
+                   *dstptr++ = sum / box_x;
+                   sum -= srcptr[-left_width];
+                   srcptr++;
+               }
+
+               /* Collapse the right side of the box filter */
+               for (; right_size > 0; right_size--)
+               {
+                   *dstptr++ = sum / (left_width + right_size);
+                   sum -= srcptr[-left_width];
+                   srcptr++;
+               }
+
+               /* Done with the row... copy dest back over source */
+               memmove(char_grayscale + (width + 1) * row,
+                       char_grayscale + (width + 1) * height,
+                       width);
+           }
+       }
+       if (box_y > 1)
+       {
+           /* Our box filter has a height > 1... let's filter the columns */
+
+           int bottom_height = box_y / 2;
+           int top_height = box_y - bottom_height - 1;
+
+           for (col = 0; col < width; col++)
+           {
+               int sum = 0;
+               int top_size = 0, bottom_size = 0;
+
+               srcptr = char_grayscale + col;
+               dstptr = char_grayscale + width;         /* scratch */
+
+               /* We've computed the shape of our full box filter.  Now
+                  compute the bottom part of the moving sum */
+               for (bottom_size = 0;
+                    bottom_size < bottom_height;
+                    bottom_size++)
+                   sum += srcptr[bottom_size * (width + 1)];
+
+               /* Now start moving the sum, growing the box filter, and
+                  dropping averages into our scratch buffer */
+               for (top_size = 0; top_size < top_height; top_size++)
+               {
+                   sum += srcptr[bottom_height * (width + 1)];
+                   *dstptr = sum / (top_size + bottom_height + 1);
+                   dstptr += width + 1;
+                   srcptr += width + 1;
+               }
+
+               /* The box filter has reached full height... continue
+                  computation of moving average until the bottom
+                  hits the wall. */
+               for (row = top_size; row + bottom_size < height; row++)
+               {
+                   sum += srcptr[bottom_height * (width + 1)];
+                   *dstptr = sum / box_y;
+                   dstptr += width + 1;
+                   sum -= srcptr[-top_height * (width + 1)];
+                   srcptr += width + 1;
+               }
+
+               /* Collapse the bottom of the box filter */
+               for (; bottom_size > 0; bottom_size--)
+               {
+                   *dstptr = sum / (top_height + bottom_size);
+                   dstptr += width + 1;
+                   sum -= srcptr[-top_height * (width + 1)];
+                   srcptr += width + 1;
+               }
+
+               /* Done with the column... copy dest back over source */
+
+               dstptr = char_grayscale + col;
+               srcptr = char_grayscale + width;         /* scratch */
+               for (row = 0; row < height; row++)
+               {
+                   *dstptr = *srcptr;
+                   dstptr += width + 1;
+                   srcptr += width + 1;
+               }
+           }
+       }
+
+       /* Increase the grayvalue to increase ink a bit */
+       srcptr = char_grayscale;
+       for (row = 0; row < height; row++)
+       {
+           for (col = 0; col < width; col++)
+           {
+               register int pixvalue = (int)*srcptr * pixmult / 256;
+               if (pixvalue > 255) pixvalue = 255;
+               *srcptr = pixvalue;
+               srcptr++;
+           }
+           srcptr++;
+       }
+    }
+
+    /* Compute the increment values for the resampling loop */
+    TRANSFORM_POINT(inv_xform, 1, 0, point);
+    deltaX = (INT32)(point[0] * 65536.0);
+    deltaY = (INT32)(-point[1] * 65536.0);
+
+    /* Resampling loop:  resamples original glyph for generation of new
+       glyph in transformed coordinate system. */
+
+    for (row = 0; row < newHeight; row++)
+    {
+       /* Compute inverse transformation for start of this row */
+       TRANSFORM_POINT(inv_xform,
+                       (double)(pci->metrics.leftSideBearing) + .5,
+                       (double)(pci->metrics.ascent - row) - .5,
+                       point);
+
+       /* Adjust for coordinate system to get resampling point */
+       point[0] -= opci->metrics.leftSideBearing;
+       point[1] = opci->metrics.ascent - point[1];
+
+       /* Convert to integer coordinates */
+       xValue = (INT32)(point[0] * 65536.0);
+       yValue = (INT32)(point[1] * 65536.0);
+
+       if (char_grayscale)
+       {
+           INT32 *temp;
+           for (col = 0; col < newWidth; col++)
+           {
+               register int x = xValue >> 16, y = yValue >> 16;
+               int pixvalue, error;
+    
+               pixvalue = ((x >= 0 && x < width && y >= 0 && y < height) ?
+                           char_grayscale[x + y * (width + 1)] : 0) +
+                          thisrow[col] / 16;
+               if (pixvalue > 255) pixvalue = 255;
+               else if (pixvalue < 0) pixvalue = 0;
+
+               /* Choose the bit value and set resulting error value */
+               if (pixvalue >= 128)
+               {
+                   newBitmap[(col >> 3) + row * newBpr] |= mask[col & 0x7];
+                   error = pixvalue - 255;
+               }
+               else
+                   error = -pixvalue;
+
+               /* Diffuse the error */
+               thisrow[col + 1] += error * 7;
+               nextrow[col - 1] += error * 3;
+               nextrow[col] += error * 5;
+               nextrow[col + 1] = error;
+
+               xValue += deltaX;
+               yValue += deltaY;
+           }
+
+           /* Add in error values that fell off either end */
+           nextrow[0] += nextrow[-1];
+           nextrow[newWidth - 2] += thisrow[newWidth];
+           nextrow[newWidth - 1] += nextrow[newWidth];
+           nextrow[newWidth] = 0;
+
+           temp = nextrow;
+           nextrow = thisrow;
+           thisrow = temp;
+           nextrow[-1] = nextrow[0] = 0;
+       }
+       else
+       {
+           for (col = 0; col < newWidth; col++)
+           {
+               register int x = xValue >> 16, y = yValue >> 16;
+    
+               if (x >= 0 && x < width && y >= 0 && y < height)
+               {
+                   /* Use point-sampling for rescaling. */
+
+                   if (bitmap[(x >> 3) + y * bpr] & mask[x & 0x7])
+                       newBitmap[(col >> 3) + row * newBpr] |= mask[col & 0x7];
+               }
+
+               xValue += deltaX;
+               yValue += deltaY;
+           }
+       }
+    }
+
+
+    if (char_grayscale)
+    {
+       xfree(char_grayscale);
+       xfree(diffusion_workspace);
+    }
+}
+
+static FontPtr
+BitmapScaleBitmaps(pf, opf, widthMult, heightMult, vals)
+    FontPtr     pf;            /* scaled font */
+    FontPtr     opf;           /* originating font */
+    double      widthMult;     /* glyphs width scale factor */
+    double      heightMult;    /* glyphs height scale factor */
+    FontScalablePtr    vals;
+{
+    register int i;
+    int                nchars;
+    char       *glyphBytes;
+    BitmapFontPtr  bitmapFont,
+                  obitmapFont;
+    CharInfoPtr pci,
+               opci;
+    FontInfoPtr pfi;
+    int         glyph;
+    unsigned    bytestoalloc = 0;
+    int                firstCol, lastCol, firstRow, lastRow;
+
+    double     xform[4], inv_xform[4];
+    double     xmult, ymult;
+
+    bitmapFont = (BitmapFontPtr) pf->fontPrivate;
+    obitmapFont = (BitmapFontPtr) opf->fontPrivate;
+
+    if (!compute_xform_matrix(vals, widthMult, heightMult, xform,
+                             inv_xform, &xmult, &ymult))
+       goto bail;
+
+    pfi = &pf->info;
+    firstCol = pfi->firstCol;
+    lastCol = pfi->lastCol;
+    firstRow = pfi->firstRow;
+    lastRow = pfi->lastRow;
+
+    nchars = (lastRow - firstRow + 1) * (lastCol - firstCol + 1);
+    glyph = pf->glyph;
+    for (i = 0; i < nchars; i++)
+    {
+       if (pci = bitmapFont->encoding[i])
+           bytestoalloc += BYTES_FOR_GLYPH(pci, glyph);
+    }
+
+    /* Do we add the font malloc stuff for VALUE ADDED ? */
+    /* Will need to remember to free in the Unload routine */
+
+
+    bitmapFont->bitmaps = (char *) xalloc(bytestoalloc);
+    if (!bitmapFont->bitmaps)
+       goto bail;
+    bzero(bitmapFont->bitmaps, bytestoalloc);
+
+    glyphBytes = bitmapFont->bitmaps;
+    for (i = 0; i < nchars; i++)
+    {
+       if ((pci = bitmapFont->encoding[i]) &&
+           (opci = obitmapFont->encoding[OLDINDEX(i)]))
+       {
+           pci->bits = glyphBytes;
+           ScaleBitmap (pf, opci, pci, inv_xform,
+                        widthMult, heightMult);
+           glyphBytes += BYTES_FOR_GLYPH(pci, glyph);
+       }
+    }
+    return pf;
+
+bail:
+    if (pf)
+       xfree(pf);
+    if (bitmapFont) {
+       xfree(bitmapFont->metrics);
+       xfree(bitmapFont->ink_metrics);
+       xfree(bitmapFont->bitmaps);
+       xfree(bitmapFont->encoding);
+    }
+    return NULL;
+}
+
+static FontPtr
+PrinterScaleBitmaps(pf, opf, widthMult, heightMult, vals)
+    FontPtr     pf;            /* scaled font */
+    FontPtr     opf;           /* originating font */
+    double      widthMult;     /* glyphs width scale factor */
+    double      heightMult;    /* glyphs height scale factor */
+    FontScalablePtr    vals;
+{
+    register int i;
+    int                nchars;
+    char       *glyphBytes;
+    BitmapFontPtr  bitmapFont,
+                  obitmapFont;
+    CharInfoPtr pci,
+               opci;
+    FontInfoPtr pfi;
+    int         glyph;
+    unsigned    bytestoalloc = 0;
+    int                firstCol, lastCol, firstRow, lastRow;
+
+    double     xform[4], inv_xform[4];
+    double     xmult, ymult;
+
+    bitmapFont = (BitmapFontPtr) pf->fontPrivate;
+    obitmapFont = (BitmapFontPtr) opf->fontPrivate;
+
+    if (!compute_xform_matrix(vals, widthMult, heightMult, xform,
+                             inv_xform, &xmult, &ymult))
+       goto bail;
+
+    pfi = &pf->info;
+    firstCol = pfi->firstCol;
+    lastCol = pfi->lastCol;
+    firstRow = pfi->firstRow;
+    lastRow = pfi->lastRow;
+
+    nchars = (lastRow - firstRow + 1) * (lastCol - firstCol + 1);
+    glyph = pf->glyph;
+    for (i = 0; i < nchars; i++)
+    {
+       if (pci = bitmapFont->encoding[i])
+           bytestoalloc = MAX(bytestoalloc,BYTES_FOR_GLYPH(pci, glyph));
+    }
+
+    /* Do we add the font malloc stuff for VALUE ADDED ? */
+    /* Will need to remember to free in the Unload routine */
+
+
+    bitmapFont->bitmaps = (char *) xalloc(bytestoalloc);
+    if (!bitmapFont->bitmaps)
+       goto bail;
+    bzero(bitmapFont->bitmaps, bytestoalloc);
+
+    glyphBytes = bitmapFont->bitmaps;
+    for (i = 0; i < nchars; i++)
+    {
+       if ((pci = bitmapFont->encoding[i]) &&
+           (opci = obitmapFont->encoding[OLDINDEX(i)]))
+       {
+           pci->bits = glyphBytes;
+       }
+    }
+    return pf;
+
+bail:
+    if (pf)
+       xfree(pf);
+    if (bitmapFont) {
+       xfree(bitmapFont->metrics);
+       xfree(bitmapFont->ink_metrics);
+       xfree(bitmapFont->bitmaps);
+       xfree(bitmapFont->encoding);
+    }
+    return NULL;
+}
+
+#ifdef NOTDEF
+/*
+ *     exported interfaces
+ */
+
+FontFileLoadName(dirs, ndirs, name, pfont, format, fmask)
+    FontFileDirPtr *dirs;
+    int         ndirs;
+    char       *name;
+    FontPtr    *pfont;
+    fsBitmapFormat format;
+    fsBitmapFormatMask fmask;
+{
+    FontFileNamePtr fname;
+    char        full_name[1024];
+    int         ret = BadFontName;
+    int         i;
+
+    i = 0;
+    while (i < ndirs) {
+       if (fname = FontFileFindNameInDir(dirs[i], name)) {
+           if (!fname->alias) {
+               if (!fname->font) {
+                   strcpy(full_name, dirs[i]->dir);
+                   strcat(full_name, fname->file);
+                   ret = FontFileLoad(pfont, full_name, format, fmask);
+                   if (ret == Successful) {
+                       fname->font = *pfont;
+                       (*pfont)->fpePrivate = (pointer) fname;
+                   }
+                   return ret;
+               }
+               *pfont = fname->font;
+               return Successful;
+           }
+           name = fname->file;
+           i = 0;
+       } else
+           i++;
+    }
+    return BadFontName;
+}
+#endif
+
+/* ARGSUSED */
+BitmapOpenScalable (fpe, pFont, flags, entry, fileName, vals, format, fmask,
+                   non_cachable_font)
+    FontPathElementPtr fpe;
+    FontPtr            *pFont;
+    int                        flags;
+    FontEntryPtr       entry;
+    char               *fileName;  /* unused */
+    FontScalablePtr    vals;
+    fsBitmapFormat     format;
+    fsBitmapFormatMask fmask;
+    FontPtr            non_cachable_font;      /* We don't do licensing */
+{
+    FontScalableRec    best;
+    FontPtr            font = NullFont;
+    double             dx, sdx,
+                       dy, sdy,
+                       savedX, savedY;
+    FontPropPtr                props;
+    char               *isStringProp;
+    int                        propCount;
+    int                        status;
+    long               sWidth;
+
+    FontEntryPtr       scaleFrom;
+    FontPathElementPtr scaleFPE;
+    FontPtr            sourceFont;
+    char               fontName[MAXFONTNAMELEN];
+
+    /* Can't deal with mix-endian fonts yet */
+
+#ifdef NOTDEF /* XXX need better test */
+    if ((format & BitmapFormatByteOrderMask) !=
+           (format & BitmapFormatBitOrderMask))
+       return NullFontFileName;
+#endif
+
+    /* Reject outrageously small font sizes to keep the math from
+       blowing up. */
+    if (get_matrix_vertical_component(vals->pixel_matrix) < 1.0 ||
+       get_matrix_horizontal_component(vals->pixel_matrix) < 1.0)
+       return BadFontName;
+
+    scaleFrom = (*find_scale[BitmapGetRenderIndex(entry->u.bitmap.renderer)]) 
+                   (fpe, entry, vals, &best, &dx, &dy, &sdx, &sdy, &scaleFPE);
+
+    if (!scaleFrom)
+       return BadFontName;
+
+    status = FontFileOpenBitmap(scaleFPE, &sourceFont, LoadAll, scaleFrom,
+                               format, fmask);
+
+    if (status != Successful)
+       return BadFontName;
+
+    if (!vals->width)
+       vals->width = best.width * dx;
+
+    /* Compute the scaled font */
+
+    savedX = dx;
+    savedY = dy;
+    font = ScaleFont(sourceFont, dx, dy, sdx, sdy, vals, &dx, &dy, &sWidth);
+    if (font)
+       font = (*scale[ BitmapGetRenderIndex(entry->u.bitmap.renderer) ]) 
+                       (font, sourceFont, savedX, savedY, vals);
+
+    if (!font)
+    {
+       if (!sourceFont->refcnt)
+           FontFileCloseFont((FontPathElementPtr) 0, sourceFont);
+       return AllocError;
+    }
+
+    /* Prepare font properties for the new font */
+
+    strcpy (fontName, scaleFrom->name.name);
+    FontParseXLFDName (fontName, vals, FONT_XLFD_REPLACE_VALUE);
+
+    propCount = ComputeScaledProperties(&sourceFont->info, fontName, vals,
+                                       dx, dy, sdx, sdy, sWidth, &props,
+                                       &isStringProp);
+
+    if (!sourceFont->refcnt)
+       FontFileCloseFont((FontPathElementPtr) 0, sourceFont);
+
+    if (propCount && (!props || !isStringProp))
+    {
+       font->info.nprops = 0;
+       font->info.props = (FontPropPtr)0;
+       font->info.isStringProp = (char *)0;
+       bitmapUnloadScalable(font);
+       return AllocError;
+    }
+
+    font->info.props = props;
+    font->info.nprops = propCount;
+    font->info.isStringProp = isStringProp;
+
+    *pFont = font;
+    return Successful;
+}
+
+BitmapGetInfoScalable (fpe, pFontInfo, entry, fontName, fileName, vals)
+    FontPathElementPtr fpe;
+    FontInfoPtr                pFontInfo;
+    FontEntryPtr       entry;
+    FontNamePtr                fontName;
+    char               *fileName;
+    FontScalablePtr    vals;
+{
+    FontPtr pfont;
+    int flags = 0;
+    long format = 0;  /* It doesn't matter what format for just info */
+    long fmask = 0;
+    int ret;
+
+    ret = BitmapOpenScalable(fpe, &pfont, flags, entry, fileName, vals,
+                            format, fmask, NULL);
+    if (ret != Successful)
+        return ret;
+    *pFontInfo = pfont->info;
+
+    pfont->info.props = NULL;
+    pfont->info.isStringProp = NULL;
+
+    (*pfont->unload_font)(pfont);
+    return Successful;
+}
+
+void
+bitmapUnloadScalable (pFont)
+    FontPtr        pFont;
+{
+    BitmapFontPtr   bitmapFont;
+    FontInfoPtr            pfi;
+
+    bitmapFont = (BitmapFontPtr) pFont->fontPrivate;
+    pfi = &pFont->info;
+    xfree (pfi->props);
+    xfree (pfi->isStringProp);
+    xfree (bitmapFont->encoding);
+    xfree (bitmapFont->bitmaps);
+    xfree (bitmapFont->ink_metrics);
+    xfree (bitmapFont->metrics);
+    xfree (pFont->fontPrivate);
+    xfree (pFont->devPrivates);
+    xfree (pFont);
+}
diff --git a/Xserver/lib/font/bitmap/fontink.c b/Xserver/lib/font/bitmap/fontink.c
new file mode 100644 (file)
index 0000000..44928a4
--- /dev/null
@@ -0,0 +1,219 @@
+/* $XConsortium: fontink.c,v 1.4 94/04/17 20:17:14 gildea Exp $ */
+
+/*
+
+Copyright (c) 1990  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be included
+in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR
+OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall
+not be used in advertising or otherwise to promote the sale, use or
+other dealings in this Software without prior written authorization
+from the X Consortium.
+
+*/
+
+/*
+ * Author:  Keith Packard, MIT X Consortium
+ */
+
+#include "fntfilst.h"
+
+static unsigned char ink_mask_msb[8] = {
+    0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01,
+};
+
+static unsigned char ink_mask_lsb[8] = {
+    0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80,
+};
+
+FontCharInkMetrics(pFont, pCI, pInk)
+    FontPtr     pFont;
+    CharInfoPtr pCI;
+    xCharInfo  *pInk;
+{
+    int         leftBearing,
+                ascent,
+                descent;
+    register int vpos,
+                hpos,
+                bpos;
+    int         bitmapByteWidth,
+                bitmapByteWidthPadded;
+    int         bitmapBitWidth;
+    int         span;
+    register unsigned char *p;
+    unsigned char *ink_mask;
+    register int bmax;
+    register unsigned char charbits;
+
+    if (pFont->bit == MSBFirst)
+       ink_mask = ink_mask_msb;
+    else if (pFont->bit == LSBFirst)
+       ink_mask = ink_mask_lsb;
+    pInk->characterWidth = pCI->metrics.characterWidth;
+    pInk->attributes = pCI->metrics.attributes;
+
+    leftBearing = pCI->metrics.leftSideBearing;
+    ascent = pCI->metrics.ascent;
+    descent = pCI->metrics.descent;
+    bitmapBitWidth = GLYPHWIDTHPIXELS(pCI);
+    bitmapByteWidth = GLYPHWIDTHBYTES(pCI);
+    bitmapByteWidthPadded = BYTES_PER_ROW(bitmapBitWidth, pFont->glyph);
+    span = bitmapByteWidthPadded - bitmapByteWidth;
+
+    p = (unsigned char *) pCI->bits;
+    for (vpos = descent + ascent; --vpos >= 0;) {
+       for (hpos = bitmapByteWidth; --hpos >= 0;) {
+           if (*p++ != 0)
+               goto found_ascent;
+       }
+       p += span;
+    }
+    /*
+     * special case -- font with no bits gets all zeros
+     */
+    pInk->leftSideBearing = leftBearing;
+    pInk->rightSideBearing = leftBearing;
+    pInk->ascent = 0;
+    pInk->descent = 0;
+    return;
+found_ascent:
+    pInk->ascent = vpos - descent + 1;
+
+    p = ((unsigned char *) pCI->bits) + bitmapByteWidthPadded * 
+       (descent + ascent - 1) + bitmapByteWidth;
+
+    for (vpos = descent + ascent; --vpos >= 0;) {
+       for (hpos = bitmapByteWidth; --hpos >= 0;) {
+           if (*--p != 0)
+               goto found_descent;
+       }
+       p -= span;
+    }
+found_descent:
+    pInk->descent = vpos - ascent + 1;
+
+    bmax = 8;
+    for (hpos = 0; hpos < bitmapByteWidth; hpos++) {
+       charbits = 0;
+       p = (unsigned char *) pCI->bits + hpos;
+       for (vpos = descent + ascent; --vpos >= 0; p += bitmapByteWidthPadded)
+           charbits |= *p;
+       if (charbits) {
+           if (hpos == bitmapByteWidth - 1)
+               bmax = bitmapBitWidth - (hpos << 3);
+           p = ink_mask;
+           for (bpos = bmax; --bpos >= 0;) {
+               if (charbits & *p++)
+                   goto found_left;
+           }
+       }
+    }
+found_left:
+    pInk->leftSideBearing = leftBearing + (hpos << 3) + bmax - bpos - 1;
+
+    bmax = bitmapBitWidth - ((bitmapByteWidth - 1) << 3);
+    for (hpos = bitmapByteWidth; --hpos >= 0;) {
+       charbits = 0;
+       p = (unsigned char *) pCI->bits + hpos;
+       for (vpos = descent + ascent; --vpos >= 0; p += bitmapByteWidthPadded)
+           charbits |= *p;
+       if (charbits) {
+           p = ink_mask + bmax;
+           for (bpos = bmax; --bpos >= 0;) {
+               if (charbits & *--p)
+                   goto found_right;
+           }
+       }
+       bmax = 8;
+    }
+found_right:
+    pInk->rightSideBearing = leftBearing + (hpos << 3) + bpos + 1;
+}
+
+#define        ISBITONMSB(x, line)     ((line)[(x)/8] & (1 << (7-((x)%8))))
+#define        SETBITMSB(x, line)      ((line)[(x)/8] |= (1 << (7-((x)%8))))
+#define        ISBITONLSB(x, line)     ((line)[(x)/8] & (1 << ((x)%8)))
+#define        SETBITLSB(x, line)      ((line)[(x)/8] |= (1 << ((x)%8)))
+
+#define Min(a,b)    ((a)<(b)?(a):(b))
+#define Max(a,b)    ((a)>(b)?(a):(b))
+
+FontCharReshape(pFont, pSrc, pDst)
+    FontPtr     pFont;
+    CharInfoPtr pSrc,
+                pDst;
+{
+    int         x,
+                y;
+    unsigned char *in_line,
+               *out_line;
+    unsigned char *oldglyph,
+               *newglyph;
+    int         inwidth;
+    int         outwidth,
+                outheight;
+    int         out_bytes,
+                in_bytes;
+    int         y_min,
+                y_max,
+                x_min,
+                x_max;
+
+    newglyph = (unsigned char *) pDst->bits;
+    outwidth = pDst->metrics.rightSideBearing - pDst->metrics.leftSideBearing;
+    outheight = pDst->metrics.descent + pDst->metrics.ascent;
+    out_bytes = BYTES_PER_ROW(outwidth, pFont->glyph);
+
+    oldglyph = (unsigned char *) pSrc->bits;
+    inwidth = pSrc->metrics.rightSideBearing - pSrc->metrics.leftSideBearing;
+    in_bytes = BYTES_PER_ROW(inwidth, pFont->glyph);
+
+    bzero(newglyph, out_bytes * outheight);
+    in_line = oldglyph;
+    out_line = newglyph;
+    y_min = Max(-pSrc->metrics.ascent, -pDst->metrics.ascent);
+    y_max = Min(pSrc->metrics.descent, pDst->metrics.descent);
+    x_min = Max(pSrc->metrics.leftSideBearing, pDst->metrics.leftSideBearing);
+    x_max = Min(pSrc->metrics.rightSideBearing, pDst->metrics.rightSideBearing);
+    in_line += (y_min + pSrc->metrics.ascent) * in_bytes;
+    out_line += (y_min + pDst->metrics.ascent) * out_bytes;
+    if (pFont->bit == MSBFirst) {
+       for (y = y_min; y < y_max; y++) {
+           for (x = x_min; x < x_max; x++) {
+               if (ISBITONMSB(x - pSrc->metrics.leftSideBearing, in_line))
+                   SETBITMSB(x - pDst->metrics.leftSideBearing, out_line);
+           }
+           in_line += in_bytes;
+           out_line += out_bytes;
+       }
+    } else {
+       for (y = y_min; y < y_max; y++) {
+           for (x = x_min; x < x_max; x++) {
+               if (ISBITONLSB(x - pSrc->metrics.leftSideBearing, in_line))
+                   SETBITLSB(x - pDst->metrics.leftSideBearing, out_line);
+           }
+           in_line += in_bytes;
+           out_line += out_bytes;
+       }
+    }
+    return;
+}
diff --git a/Xserver/lib/font/bitmap/pcf.h b/Xserver/lib/font/bitmap/pcf.h
new file mode 100644 (file)
index 0000000..752c841
--- /dev/null
@@ -0,0 +1,93 @@
+/* $XConsortium: pcf.h,v 1.2 94/04/17 20:17:15 keith Exp $ */
+
+/*
+
+Copyright (c) 1991  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be included
+in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR
+OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall
+not be used in advertising or otherwise to promote the sale, use or
+other dealings in this Software without prior written authorization
+from the X Consortium.
+
+*/
+
+/*
+ * Author:  Keith Packard, MIT X Consortium
+ */
+
+#ifndef _PCF_H_
+#define _PCF_H_
+
+/*
+ * Information used to read/write PCF fonts
+ */
+
+typedef struct _PCFTable {
+    CARD32      type;
+    CARD32      format;
+    CARD32      size;
+    CARD32      offset;
+}           PCFTableRec, *PCFTablePtr;
+
+#define PCF_FILE_VERSION       (('p'<<24)|('c'<<16)|('f'<<8)|1)
+#define        PCF_FORMAT_MASK         0xffffff00
+
+#define PCF_DEFAULT_FORMAT     0x00000000
+#define PCF_INKBOUNDS          0x00000200
+#define PCF_ACCEL_W_INKBOUNDS  0x00000100
+#define PCF_COMPRESSED_METRICS 0x00000100
+
+#define PCF_FORMAT_MATCH(a,b) (((a)&PCF_FORMAT_MASK) == ((b)&PCF_FORMAT_MASK))
+
+#define PCF_GLYPH_PAD_MASK     (3<<0)
+#define PCF_BYTE_MASK          (1<<2)
+#define PCF_BIT_MASK           (1<<3)
+#define PCF_SCAN_UNIT_MASK     (3<<4)
+
+#define PCF_BYTE_ORDER(f)      (((f) & PCF_BYTE_MASK)?MSBFirst:LSBFirst)
+#define PCF_BIT_ORDER(f)       (((f) & PCF_BIT_MASK)?MSBFirst:LSBFirst)
+#define PCF_GLYPH_PAD_INDEX(f) ((f) & PCF_GLYPH_PAD_MASK)
+#define PCF_GLYPH_PAD(f)       (1<<PCF_GLYPH_PAD_INDEX(f))
+#define PCF_SCAN_UNIT_INDEX(f) (((f) & PCF_SCAN_UNIT_MASK) >> 4)
+#define PCF_SCAN_UNIT(f)       (1<<PCF_SCAN_UNIT_INDEX(f))
+#define PCF_FORMAT_BITS(f)     ((f) & (PCF_GLYPH_PAD_MASK|PCF_BYTE_MASK|PCF_BIT_MASK|PCF_SCAN_UNIT_MASK))
+
+#define PCF_SIZE_TO_INDEX(s)   ((s) == 4 ? 2 : (s) == 2 ? 1 : 0)
+#define PCF_INDEX_TO_SIZE(b)   (1<<b)
+
+#define PCF_FORMAT(bit,byte,glyph,scan) (\
+    (PCF_SIZE_TO_INDEX(scan) << 4) | \
+    (((bit) == MSBFirst ? 1 : 0) << 3) | \
+    (((byte) == MSBFirst ? 1 : 0) << 2) | \
+    (PCF_SIZE_TO_INDEX(glyph) << 0))
+
+#define PCF_PROPERTIES             (1<<0)
+#define PCF_ACCELERATORS           (1<<1)
+#define PCF_METRICS                (1<<2)
+#define PCF_BITMAPS                (1<<3)
+#define PCF_INK_METRICS                    (1<<4)
+#define        PCF_BDF_ENCODINGS           (1<<5)
+#define PCF_SWIDTHS                (1<<6)
+#define PCF_GLYPH_NAMES                    (1<<7)
+#define PCF_BDF_ACCELERATORS       (1<<8)
+
+#endif                         /* _PCF_H_ */
diff --git a/Xserver/lib/font/bitmap/pcfread.c b/Xserver/lib/font/bitmap/pcfread.c
new file mode 100644 (file)
index 0000000..596ba4a
--- /dev/null
@@ -0,0 +1,887 @@
+/* $XConsortium: pcfread.c /main/18 1996/09/28 16:48:33 rws $ */
+
+/*
+
+Copyright (c) 1990  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be included
+in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR
+OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall
+not be used in advertising or otherwise to promote the sale, use or
+other dealings in this Software without prior written authorization
+from the X Consortium.
+
+*/
+
+/*
+ * Author:  Keith Packard, MIT X Consortium
+ */
+
+#include "fntfilst.h"
+#include "bitmap.h"
+#include "pcf.h"
+#ifndef MAX
+#define   MAX(a,b)    (((a)>(b)) ? a : b)
+#endif
+
+/* Read PCF font files */
+
+void        pcfUnloadFont();
+static int  position;
+
+static int
+pcfGetLSB32(file)
+    FontFilePtr file;
+{
+    int         c;
+
+    c = FontFileGetc(file);
+    c |= FontFileGetc(file) << 8;
+    c |= FontFileGetc(file) << 16;
+    c |= FontFileGetc(file) << 24;
+    position += 4;
+    return c;
+}
+
+static int
+pcfGetINT32(file, format)
+    FontFilePtr file;
+    CARD32      format;
+{
+    int         c;
+
+    if (PCF_BYTE_ORDER(format) == MSBFirst) {
+       c = FontFileGetc(file) << 24;
+       c |= FontFileGetc(file) << 16;
+       c |= FontFileGetc(file) << 8;
+       c |= FontFileGetc(file);
+    } else {
+       c = FontFileGetc(file);
+       c |= FontFileGetc(file) << 8;
+       c |= FontFileGetc(file) << 16;
+       c |= FontFileGetc(file) << 24;
+    }
+    position += 4;
+    return c;
+}
+
+static int
+pcfGetINT16(file, format)
+    FontFilePtr file;
+    CARD32      format;
+{
+    int         c;
+
+    if (PCF_BYTE_ORDER(format) == MSBFirst) {
+       c = FontFileGetc(file) << 8;
+       c |= FontFileGetc(file);
+    } else {
+       c = FontFileGetc(file);
+       c |= FontFileGetc(file) << 8;
+    }
+    position += 2;
+    return c;
+}
+
+#define pcfGetINT8(file, format) (position++, FontFileGetc(file))
+
+static      PCFTablePtr
+pcfReadTOC(file, countp)
+    FontFilePtr file;
+    int        *countp;
+{
+    CARD32      version;
+    PCFTablePtr tables;
+    int         count;
+    int         i;
+
+    position = 0;
+    version = pcfGetLSB32(file);
+    if (version != PCF_FILE_VERSION)
+       return (PCFTablePtr) NULL;
+    count = pcfGetLSB32(file);
+    tables = (PCFTablePtr) xalloc(count * sizeof(PCFTableRec));
+    if (!tables)
+       return (PCFTablePtr) NULL;
+    for (i = 0; i < count; i++) {
+       tables[i].type = pcfGetLSB32(file);
+       tables[i].format = pcfGetLSB32(file);
+       tables[i].size = pcfGetLSB32(file);
+       tables[i].offset = pcfGetLSB32(file);
+    }
+    *countp = count;
+    return tables;
+}
+
+/*
+ * PCF supports two formats for metrics, both the regular
+ * jumbo size, and 'lite' metrics, which are useful
+ * for most fonts which have even vaguely reasonable
+ * metrics
+ */
+
+static
+pcfGetMetric(file, format, metric)
+    FontFilePtr file;
+    CARD32      format;
+    xCharInfo  *metric;
+{
+    metric->leftSideBearing = pcfGetINT16(file, format);
+    metric->rightSideBearing = pcfGetINT16(file, format);
+    metric->characterWidth = pcfGetINT16(file, format);
+    metric->ascent = pcfGetINT16(file, format);
+    metric->descent = pcfGetINT16(file, format);
+    metric->attributes = pcfGetINT16(file, format);
+}
+
+static
+pcfGetCompressedMetric(file, format, metric)
+    FontFilePtr file;
+    CARD32      format;
+    xCharInfo  *metric;
+{
+    metric->leftSideBearing = pcfGetINT8(file, format) - 0x80;
+    metric->rightSideBearing = pcfGetINT8(file, format) - 0x80;
+    metric->characterWidth = pcfGetINT8(file, format) - 0x80;
+    metric->ascent = pcfGetINT8(file, format) - 0x80;
+    metric->descent = pcfGetINT8(file, format) - 0x80;
+    metric->attributes = 0;
+}
+
+/*
+ * Position the file to the begining of the specified table
+ * in the font file
+ */
+static Bool
+pcfSeekToType(file, tables, ntables, type, formatp, sizep)
+    FontFilePtr file;
+    PCFTablePtr tables;
+    int         ntables;
+    CARD32      type;
+    CARD32     *formatp;
+    CARD32     *sizep;
+{
+    int         i;
+
+    for (i = 0; i < ntables; i++)
+       if (tables[i].type == type) {
+           if (position > tables[i].offset)
+               return FALSE;
+           if (!FontFileSkip(file, tables[i].offset - position))
+               return FALSE;
+           position = tables[i].offset;
+           *sizep = tables[i].size;
+           *formatp = tables[i].format;
+           return TRUE;
+       }
+    return FALSE;
+}
+
+static Bool
+pcfHasType (tables, ntables, type)
+    PCFTablePtr tables;
+    int         ntables;
+    CARD32      type;
+{
+    int         i;
+
+    for (i = 0; i < ntables; i++)
+       if (tables[i].type == type)
+           return TRUE;
+    return FALSE;
+}
+
+/*
+ * pcfGetProperties 
+ *
+ * Reads the font properties from the font file, filling in the FontInfo rec
+ * supplied.  Used by by both ReadFont and ReadFontInfo routines.
+ */
+
+static Bool
+pcfGetProperties(pFontInfo, file, tables, ntables)
+    FontInfoPtr pFontInfo;
+    FontFilePtr file;
+    PCFTablePtr tables;
+    int         ntables;
+{
+    FontPropPtr props = 0;
+    int         nprops;
+    char       *isStringProp = 0;
+    CARD32      format;
+    int         i;
+    int         size;
+    int         string_size;
+    char       *strings;
+
+    /* font properties */
+
+    if (!pcfSeekToType(file, tables, ntables, PCF_PROPERTIES, &format, &size))
+       goto Bail;
+    format = pcfGetLSB32(file);
+    if (!PCF_FORMAT_MATCH(format, PCF_DEFAULT_FORMAT))
+       goto Bail;
+    nprops = pcfGetINT32(file, format);
+    props = (FontPropPtr) xalloc(nprops * sizeof(FontPropRec));
+    if (!props)
+       goto Bail;
+    isStringProp = (char *) xalloc(nprops * sizeof(char));
+    if (!isStringProp)
+       goto Bail;
+    for (i = 0; i < nprops; i++) {
+       props[i].name = pcfGetINT32(file, format);
+       isStringProp[i] = pcfGetINT8(file, format);
+       props[i].value = pcfGetINT32(file, format);
+    }
+    /* pad the property array */
+    /*
+     * clever here - nprops is the same as the number of odd-units read, as
+     * only isStringProp are odd length
+     */
+    if (nprops & 3)
+    {
+       i = 4 - (nprops & 3);
+       FontFileSkip(file, i);
+       position += i;
+    }
+    string_size = pcfGetINT32(file, format);
+    strings = (char *) xalloc(string_size);
+    if (!strings) {
+       goto Bail;
+    }
+    FontFileRead(file, strings, string_size);
+    position += string_size;
+    for (i = 0; i < nprops; i++) {
+       props[i].name = MakeAtom(strings + props[i].name,
+                                strlen(strings + props[i].name), TRUE);
+       if (isStringProp[i]) {
+           props[i].value = MakeAtom(strings + props[i].value,
+                                     strlen(strings + props[i].value), TRUE);
+       }
+    }
+    xfree(strings);
+    pFontInfo->isStringProp = isStringProp;
+    pFontInfo->props = props;
+    pFontInfo->nprops = nprops;
+    return TRUE;
+Bail:
+    xfree(isStringProp);
+    xfree(props);
+    return FALSE;
+}
+
+
+/*
+ * pcfReadAccel
+ *
+ * Fill in the accelerator information from the font file; used
+ * to read both BDF_ACCELERATORS and old style ACCELERATORS
+ */
+
+static Bool
+pcfGetAccel(pFontInfo, file, tables, ntables, type)
+    FontInfoPtr pFontInfo;
+    FontFilePtr file;
+    PCFTablePtr        tables;
+    int                ntables;
+    CARD32     type;
+{
+    CARD32      format;
+    int                size;
+
+    if (!pcfSeekToType(file, tables, ntables, type, &format, &size))
+       goto Bail;
+    format = pcfGetLSB32(file);
+    if (!PCF_FORMAT_MATCH(format, PCF_DEFAULT_FORMAT) &&
+       !PCF_FORMAT_MATCH(format, PCF_ACCEL_W_INKBOUNDS)) 
+    {
+       goto Bail;
+    }
+    pFontInfo->noOverlap = pcfGetINT8(file, format);
+    pFontInfo->constantMetrics = pcfGetINT8(file, format);
+    pFontInfo->terminalFont = pcfGetINT8(file, format);
+    pFontInfo->constantWidth = pcfGetINT8(file, format);
+    pFontInfo->inkInside = pcfGetINT8(file, format);
+    pFontInfo->inkMetrics = pcfGetINT8(file, format);
+    pFontInfo->drawDirection = pcfGetINT8(file, format);
+    pFontInfo->anamorphic = FALSE;
+    pFontInfo->cachable = TRUE;
+     /* natural alignment */ pcfGetINT8(file, format);
+    pFontInfo->fontAscent = pcfGetINT32(file, format);
+    pFontInfo->fontDescent = pcfGetINT32(file, format);
+    pFontInfo->maxOverlap = pcfGetINT32(file, format);
+    pcfGetMetric(file, format, &pFontInfo->minbounds);
+    pcfGetMetric(file, format, &pFontInfo->maxbounds);
+    if (PCF_FORMAT_MATCH(format, PCF_ACCEL_W_INKBOUNDS)) {
+       pcfGetMetric(file, format, &pFontInfo->ink_minbounds);
+       pcfGetMetric(file, format, &pFontInfo->ink_maxbounds);
+    } else {
+       pFontInfo->ink_minbounds = pFontInfo->minbounds;
+       pFontInfo->ink_maxbounds = pFontInfo->maxbounds;
+    }
+    return TRUE;
+Bail:
+    return FALSE;
+}
+
+int
+pcfReadFont(pFont, file, bit, byte, glyph, scan)
+    FontPtr     pFont;
+    FontFilePtr file;
+    int         bit,
+                byte,
+                glyph,
+                scan;
+{
+    CARD32      format;
+    CARD32      size;
+    BitmapFontPtr  bitmapFont = 0;
+    int         i;
+    PCFTablePtr tables = 0;
+    int         ntables;
+    int         nmetrics;
+    int         nbitmaps;
+    int         sizebitmaps;
+    int         nink_metrics;
+    CharInfoPtr metrics = 0;
+    xCharInfo  *ink_metrics = 0;
+    char       *bitmaps = 0;
+    CharInfoPtr *encoding = 0;
+    int         nencoding;
+    int         encodingOffset;
+    CARD32      bitmapSizes[GLYPHPADOPTIONS];
+    CARD32     *offsets = 0;
+    Bool       hasBDFAccelerators;
+
+    pFont->info.props = 0;
+    if (!(tables = pcfReadTOC(file, &ntables)))
+       goto Bail;
+
+    /* properties */
+
+    if (!pcfGetProperties(&pFont->info, file, tables, ntables))
+       goto Bail;
+
+    /* Use the old accelerators if no BDF accelerators are in the file */
+
+    hasBDFAccelerators = pcfHasType (tables, ntables, PCF_BDF_ACCELERATORS);
+    if (!hasBDFAccelerators)
+       if (!pcfGetAccel (&pFont->info, file, tables, ntables, PCF_ACCELERATORS))
+           goto Bail;
+
+    /* metrics */
+
+    if (!pcfSeekToType(file, tables, ntables, PCF_METRICS, &format, &size)) {
+       goto Bail;
+    }
+    format = pcfGetLSB32(file);
+    if (!PCF_FORMAT_MATCH(format, PCF_DEFAULT_FORMAT) &&
+           !PCF_FORMAT_MATCH(format, PCF_COMPRESSED_METRICS)) {
+       goto Bail;
+    }
+    if (PCF_FORMAT_MATCH(format, PCF_DEFAULT_FORMAT))
+       nmetrics = pcfGetINT32(file, format);
+    else
+       nmetrics = pcfGetINT16(file, format);
+    metrics = (CharInfoPtr) xalloc(nmetrics * sizeof(CharInfoRec));
+    if (!metrics) {
+       goto Bail;
+    }
+    for (i = 0; i < nmetrics; i++)
+       if (PCF_FORMAT_MATCH(format, PCF_DEFAULT_FORMAT))
+           pcfGetMetric(file, format, &(metrics + i)->metrics);
+       else
+           pcfGetCompressedMetric(file, format, &(metrics + i)->metrics);
+
+    /* bitmaps */
+
+    if (!pcfSeekToType(file, tables, ntables, PCF_BITMAPS, &format, &size))
+       goto Bail;
+    format = pcfGetLSB32(file);
+    if (!PCF_FORMAT_MATCH(format, PCF_DEFAULT_FORMAT))
+       goto Bail;
+
+    nbitmaps = pcfGetINT32(file, format);
+    if (nbitmaps != nmetrics)
+       goto Bail;
+
+    offsets = (CARD32 *) xalloc(nbitmaps * sizeof(CARD32));
+    if (!offsets)
+       goto Bail;
+
+    for (i = 0; i < nbitmaps; i++)
+       offsets[i] = pcfGetINT32(file, format);
+
+    for (i = 0; i < GLYPHPADOPTIONS; i++)
+       bitmapSizes[i] = pcfGetINT32(file, format);
+    sizebitmaps = bitmapSizes[PCF_GLYPH_PAD_INDEX(format)];
+    /* guard against completely empty font */
+    bitmaps = (char *) xalloc(sizebitmaps ? sizebitmaps : 1);
+    if (!bitmaps)
+       goto Bail;
+    FontFileRead(file, bitmaps, sizebitmaps);
+    position += sizebitmaps;
+
+    if (PCF_BIT_ORDER(format) != bit)
+       BitOrderInvert(bitmaps, sizebitmaps);
+    if ((PCF_BYTE_ORDER(format) == PCF_BIT_ORDER(format)) != (bit == byte)) {
+       switch (bit == byte ? PCF_SCAN_UNIT(format) : scan) {
+       case 1:
+           break;
+       case 2:
+           TwoByteSwap(bitmaps, sizebitmaps);
+           break;
+       case 4:
+           FourByteSwap(bitmaps, sizebitmaps);
+           break;
+       }
+    }
+    if (PCF_GLYPH_PAD(format) != glyph) {
+       char       *padbitmaps;
+       int         sizepadbitmaps;
+       int         old,
+                   new;
+       xCharInfo  *metric;
+
+       sizepadbitmaps = bitmapSizes[PCF_SIZE_TO_INDEX(glyph)];
+       padbitmaps = (char *) xalloc(sizepadbitmaps);
+       if (!padbitmaps) {
+           goto Bail;
+       }
+       new = 0;
+       for (i = 0; i < nbitmaps; i++) {
+           old = offsets[i];
+           metric = &metrics[i].metrics;
+           offsets[i] = new;
+           new += RepadBitmap(bitmaps + old, padbitmaps + new,
+                              PCF_GLYPH_PAD(format), glyph,
+                         metric->rightSideBearing - metric->leftSideBearing,
+                              metric->ascent + metric->descent);
+       }
+       xfree(bitmaps);
+       bitmaps = padbitmaps;
+    }
+    for (i = 0; i < nbitmaps; i++)
+       metrics[i].bits = bitmaps + offsets[i];
+
+    xfree(offsets);
+    offsets = NULL;
+
+    /* ink metrics ? */
+
+    ink_metrics = NULL;
+    if (pcfSeekToType(file, tables, ntables, PCF_INK_METRICS, &format, &size)) {
+       format = pcfGetLSB32(file);
+       if (!PCF_FORMAT_MATCH(format, PCF_DEFAULT_FORMAT) &&
+               !PCF_FORMAT_MATCH(format, PCF_COMPRESSED_METRICS)) {
+           goto Bail;
+       }
+       if (PCF_FORMAT_MATCH(format, PCF_DEFAULT_FORMAT))
+           nink_metrics = pcfGetINT32(file, format);
+       else
+           nink_metrics = pcfGetINT16(file, format);
+       if (nink_metrics != nmetrics)
+           goto Bail;
+       ink_metrics = (xCharInfo *) xalloc(nink_metrics * sizeof(xCharInfo));
+       if (!ink_metrics)
+           goto Bail;
+       for (i = 0; i < nink_metrics; i++)
+           if (PCF_FORMAT_MATCH(format, PCF_DEFAULT_FORMAT))
+               pcfGetMetric(file, format, ink_metrics + i);
+           else
+               pcfGetCompressedMetric(file, format, ink_metrics + i);
+    }
+
+    /* encoding */
+
+    if (!pcfSeekToType(file, tables, ntables, PCF_BDF_ENCODINGS, &format, &size))
+       goto Bail;
+    format = pcfGetLSB32(file);
+    if (!PCF_FORMAT_MATCH(format, PCF_DEFAULT_FORMAT))
+       goto Bail;
+
+    pFont->info.firstCol = pcfGetINT16(file, format);
+    pFont->info.lastCol = pcfGetINT16(file, format);
+    pFont->info.firstRow = pcfGetINT16(file, format);
+    pFont->info.lastRow = pcfGetINT16(file, format);
+    pFont->info.defaultCh = pcfGetINT16(file, format);
+
+    nencoding = (pFont->info.lastCol - pFont->info.firstCol + 1) *
+       (pFont->info.lastRow - pFont->info.firstRow + 1);
+
+    encoding = (CharInfoPtr *) xalloc(nencoding * sizeof(CharInfoPtr));
+    if (!encoding)
+       goto Bail;
+
+    pFont->info.allExist = TRUE;
+    for (i = 0; i < nencoding; i++) {
+       encodingOffset = pcfGetINT16(file, format);
+       if (encodingOffset == 0xFFFF) {
+           pFont->info.allExist = FALSE;
+           encoding[i] = 0;
+       } else
+           encoding[i] = metrics + encodingOffset;
+    }
+
+    /* BDF style accelerators (i.e. bounds based on encoded glyphs) */
+
+    if (hasBDFAccelerators)
+       if (!pcfGetAccel (&pFont->info, file, tables, ntables, PCF_BDF_ACCELERATORS))
+           goto Bail;
+
+    bitmapFont = (BitmapFontPtr) xalloc(sizeof *bitmapFont);
+    if (!bitmapFont)
+       goto Bail;
+
+    bitmapFont->version_num = PCF_FILE_VERSION;
+    bitmapFont->num_chars = nmetrics;
+    bitmapFont->num_tables = ntables;
+    bitmapFont->metrics = metrics;
+    bitmapFont->ink_metrics = ink_metrics;
+    bitmapFont->bitmaps = bitmaps;
+    bitmapFont->encoding = encoding;
+    bitmapFont->pDefault = (CharInfoPtr) 0;
+    if (pFont->info.defaultCh != (unsigned short) NO_SUCH_CHAR) {
+       unsigned int r,
+                   c,
+                   cols;
+
+       r = pFont->info.defaultCh >> 8;
+       c = pFont->info.defaultCh & 0xFF;
+       if (pFont->info.firstRow <= r && r <= pFont->info.lastRow &&
+               pFont->info.firstCol <= c && c <= pFont->info.lastCol) {
+           cols = pFont->info.lastCol - pFont->info.firstCol + 1;
+           r = r - pFont->info.firstRow;
+           c = c - pFont->info.firstCol;
+           bitmapFont->pDefault = encoding[r * cols + c];
+       }
+    }
+    bitmapFont->bitmapExtra = (BitmapExtraPtr) 0;
+    pFont->fontPrivate = (pointer) bitmapFont;
+    pFont->get_glyphs = bitmapGetGlyphs;
+    pFont->get_metrics = bitmapGetMetrics;
+    pFont->unload_font = pcfUnloadFont;
+    pFont->unload_glyphs = NULL;
+    pFont->bit = bit;
+    pFont->byte = byte;
+    pFont->glyph = glyph;
+    pFont->scan = scan;
+    xfree(tables);
+    return Successful;
+Bail:
+    xfree(ink_metrics);
+    xfree(encoding);
+    xfree(bitmaps);
+    xfree(offsets);
+    xfree(metrics);
+    xfree(pFont->info.props);
+    pFont->info.props = 0;
+    xfree(bitmapFont);
+    xfree(tables);
+    return AllocError;
+}
+
+int
+pcfReadFontInfo(pFontInfo, file)
+    FontInfoPtr pFontInfo;
+    FontFilePtr file;
+{
+    PCFTablePtr tables;
+    int         ntables;
+    CARD32      format;
+    CARD32      size;
+    int         nencoding;
+    Bool       hasBDFAccelerators;
+
+    pFontInfo->isStringProp = NULL;
+    pFontInfo->props = NULL;
+
+    if (!(tables = pcfReadTOC(file, &ntables)))
+       goto Bail;
+
+    /* properties */
+
+    if (!pcfGetProperties(pFontInfo, file, tables, ntables))
+       goto Bail;
+
+    /* Use the old accelerators if no BDF accelerators are in the file */
+
+    hasBDFAccelerators = pcfHasType (tables, ntables, PCF_BDF_ACCELERATORS);
+    if (!hasBDFAccelerators)
+       if (!pcfGetAccel (pFontInfo, file, tables, ntables, PCF_ACCELERATORS))
+           goto Bail;
+
+    /* encoding */
+
+    if (!pcfSeekToType(file, tables, ntables, PCF_BDF_ENCODINGS, &format, &size))
+       goto Bail;
+    format = pcfGetLSB32(file);
+    if (!PCF_FORMAT_MATCH(format, PCF_DEFAULT_FORMAT))
+       goto Bail;
+
+    pFontInfo->firstCol = pcfGetINT16(file, format);
+    pFontInfo->lastCol = pcfGetINT16(file, format);
+    pFontInfo->firstRow = pcfGetINT16(file, format);
+    pFontInfo->lastRow = pcfGetINT16(file, format);
+    pFontInfo->defaultCh = pcfGetINT16(file, format);
+
+    nencoding = (pFontInfo->lastCol - pFontInfo->firstCol + 1) *
+       (pFontInfo->lastRow - pFontInfo->firstRow + 1);
+
+    pFontInfo->allExist = TRUE;
+    while (nencoding--) {
+       if (pcfGetINT16(file, format) == 0xFFFF)
+           pFontInfo->allExist = FALSE;
+    }
+
+    /* BDF style accelerators (i.e. bounds based on encoded glyphs) */
+
+    if (hasBDFAccelerators)
+       if (!pcfGetAccel (pFontInfo, file, tables, ntables, PCF_BDF_ACCELERATORS))
+           goto Bail;
+
+    xfree(tables);
+    return Successful;
+Bail:
+    xfree (pFontInfo->props);
+    xfree (pFontInfo->isStringProp);
+    xfree(tables);
+    return AllocError;
+}
+
+void
+pcfUnloadFont(pFont)
+    FontPtr     pFont;
+{
+    BitmapFontPtr  bitmapFont;
+
+    bitmapFont = (BitmapFontPtr) pFont->fontPrivate;
+    xfree(bitmapFont->ink_metrics);
+    xfree(bitmapFont->encoding);
+    xfree(bitmapFont->bitmaps);
+    xfree(bitmapFont->metrics);
+    xfree(pFont->info.isStringProp);
+    xfree(pFont->info.props);
+    xfree(bitmapFont);
+    xfree(pFont->devPrivates);
+    xfree(pFont);
+}
+
+int
+pmfReadFont(pFont, file, bit, byte, glyph, scan)
+    FontPtr     pFont;
+    FontFilePtr file;
+    int         bit,
+                byte,
+                glyph,
+                scan;
+{
+    CARD32      format;
+    CARD32      size;
+    BitmapFontPtr  bitmapFont = 0;
+    int         i;
+    PCFTablePtr tables = 0;
+    int         ntables;
+    int         nmetrics;
+    int         sizebitmaps;
+    int         nink_metrics;
+    CharInfoPtr metrics = 0;
+    xCharInfo  *ink_metrics = 0;
+    char       *bitmaps = 0;
+    CharInfoPtr *encoding = 0;
+    int         nencoding;
+    int         encodingOffset;
+    CARD32      bitmapSizes[GLYPHPADOPTIONS];
+    Bool       hasBDFAccelerators;
+    CharInfoPtr pci;
+
+    pFont->info.props = 0;
+    if (!(tables = pcfReadTOC(file, &ntables)))
+       goto Bail;
+
+    /* properties */
+
+    if (!pcfGetProperties(&pFont->info, file, tables, ntables))
+       goto Bail;
+
+    /* Use the old accelerators if no BDF accelerators are in the file */
+
+    hasBDFAccelerators = pcfHasType (tables, ntables, PCF_BDF_ACCELERATORS);
+    if (!hasBDFAccelerators)
+       if (!pcfGetAccel (&pFont->info, file, tables, ntables, PCF_ACCELERATORS))
+           goto Bail;
+
+    /* metrics */
+
+    if (!pcfSeekToType(file, tables, ntables, PCF_METRICS, &format, &size)) {
+       goto Bail;
+    }
+    format = pcfGetLSB32(file);
+    if (!PCF_FORMAT_MATCH(format, PCF_DEFAULT_FORMAT) &&
+           !PCF_FORMAT_MATCH(format, PCF_COMPRESSED_METRICS)) {
+       goto Bail;
+    }
+    if (PCF_FORMAT_MATCH(format, PCF_DEFAULT_FORMAT))
+       nmetrics = pcfGetINT32(file, format);
+    else
+       nmetrics = pcfGetINT16(file, format);
+    metrics = (CharInfoPtr) xalloc(nmetrics * sizeof(CharInfoRec));
+    if (!metrics) {
+       goto Bail;
+    }
+    for (i = 0; i < nmetrics; i++)
+       if (PCF_FORMAT_MATCH(format, PCF_DEFAULT_FORMAT))
+           pcfGetMetric(file, format, &(metrics + i)->metrics);
+       else
+           pcfGetCompressedMetric(file, format, &(metrics + i)->metrics);
+
+    /* Set the bitmaps to all point to the same zero filled array 
+     * that is the size of the largest bitmap.
+     */
+
+    pci = metrics;
+    sizebitmaps = 0;
+    for (i = 0; i < nmetrics; i++)
+    {
+       sizebitmaps = MAX(sizebitmaps,BYTES_FOR_GLYPH(pci, glyph));
+       pci++;
+    }
+
+    sizebitmaps = BUFSIZ;
+    /* guard against completely empty font */
+    bitmaps = (char *) xalloc(sizebitmaps);
+    if (!bitmaps)
+       goto Bail;
+
+    memset(bitmaps,0,sizebitmaps);
+    for (i = 0; i < nmetrics; i++)
+       metrics[i].bits = bitmaps;
+
+    /* ink metrics ? */
+
+    ink_metrics = NULL;
+    if (pcfSeekToType(file, tables, ntables, PCF_INK_METRICS, &format, &size)) {
+       format = pcfGetLSB32(file);
+       if (!PCF_FORMAT_MATCH(format, PCF_DEFAULT_FORMAT) &&
+               !PCF_FORMAT_MATCH(format, PCF_COMPRESSED_METRICS)) {
+           goto Bail;
+       }
+       if (PCF_FORMAT_MATCH(format, PCF_DEFAULT_FORMAT))
+           nink_metrics = pcfGetINT32(file, format);
+       else
+           nink_metrics = pcfGetINT16(file, format);
+       if (nink_metrics != nmetrics)
+           goto Bail;
+       ink_metrics = (xCharInfo *) xalloc(nink_metrics * sizeof(xCharInfo));
+       if (!ink_metrics)
+           goto Bail;
+       for (i = 0; i < nink_metrics; i++)
+           if (PCF_FORMAT_MATCH(format, PCF_DEFAULT_FORMAT))
+               pcfGetMetric(file, format, ink_metrics + i);
+           else
+               pcfGetCompressedMetric(file, format, ink_metrics + i);
+    }
+
+    /* encoding */
+
+    if (!pcfSeekToType(file, tables, ntables, PCF_BDF_ENCODINGS, &format, &size))
+       goto Bail;
+    format = pcfGetLSB32(file);
+    if (!PCF_FORMAT_MATCH(format, PCF_DEFAULT_FORMAT))
+       goto Bail;
+
+    pFont->info.firstCol = pcfGetINT16(file, format);
+    pFont->info.lastCol = pcfGetINT16(file, format);
+    pFont->info.firstRow = pcfGetINT16(file, format);
+    pFont->info.lastRow = pcfGetINT16(file, format);
+    pFont->info.defaultCh = pcfGetINT16(file, format);
+
+    nencoding = (pFont->info.lastCol - pFont->info.firstCol + 1) *
+       (pFont->info.lastRow - pFont->info.firstRow + 1);
+
+    encoding = (CharInfoPtr *) xalloc(nencoding * sizeof(CharInfoPtr));
+    if (!encoding)
+       goto Bail;
+
+    pFont->info.allExist = TRUE;
+    for (i = 0; i < nencoding; i++) {
+       encodingOffset = pcfGetINT16(file, format);
+       if (encodingOffset == 0xFFFF) {
+           pFont->info.allExist = FALSE;
+           encoding[i] = 0;
+       } else
+           encoding[i] = metrics + encodingOffset;
+    }
+
+    /* BDF style accelerators (i.e. bounds based on encoded glyphs) */
+
+    if (hasBDFAccelerators)
+       if (!pcfGetAccel (&pFont->info, file, tables, ntables, PCF_BDF_ACCELERATORS))
+           goto Bail;
+
+    bitmapFont = (BitmapFontPtr) xalloc(sizeof *bitmapFont);
+    if (!bitmapFont)
+       goto Bail;
+
+    bitmapFont->version_num = PCF_FILE_VERSION;
+    bitmapFont->num_chars = nmetrics;
+    bitmapFont->num_tables = ntables;
+    bitmapFont->metrics = metrics;
+    bitmapFont->ink_metrics = ink_metrics;
+    bitmapFont->bitmaps = bitmaps;
+    bitmapFont->encoding = encoding;
+    bitmapFont->pDefault = (CharInfoPtr) 0;
+    if (pFont->info.defaultCh != (unsigned short) NO_SUCH_CHAR) {
+       unsigned int r,
+                   c,
+                   cols;
+
+       r = pFont->info.defaultCh >> 8;
+       c = pFont->info.defaultCh & 0xFF;
+       if (pFont->info.firstRow <= r && r <= pFont->info.lastRow &&
+               pFont->info.firstCol <= c && c <= pFont->info.lastCol) {
+           cols = pFont->info.lastCol - pFont->info.firstCol + 1;
+           r = r - pFont->info.firstRow;
+           c = c - pFont->info.firstCol;
+           bitmapFont->pDefault = encoding[r * cols + c];
+       }
+    }
+    bitmapFont->bitmapExtra = (BitmapExtraPtr) 0;
+    pFont->fontPrivate = (pointer) bitmapFont;
+    pFont->get_glyphs = bitmapGetGlyphs;
+    pFont->get_metrics = bitmapGetMetrics;
+    pFont->unload_font = pcfUnloadFont;
+    pFont->unload_glyphs = NULL;
+    pFont->bit = bit;
+    pFont->byte = byte;
+    pFont->glyph = glyph;
+    pFont->scan = scan;
+    xfree(tables);
+    return Successful;
+Bail:
+    xfree(ink_metrics);
+    xfree(encoding);
+    xfree(metrics);
+    xfree(pFont->info.props);
+    xfree(bitmapFont);
+    pFont->info.props = 0;
+    xfree(tables);
+    return AllocError;
+}
diff --git a/Xserver/lib/font/bitmap/pcfwrite.c b/Xserver/lib/font/bitmap/pcfwrite.c
new file mode 100644 (file)
index 0000000..b6dada7
--- /dev/null
@@ -0,0 +1,487 @@
+/* $XConsortium: pcfwrite.c,v 1.6 94/04/17 20:17:16 gildea Exp $ */
+
+/*
+
+Copyright (c) 1990, 1994  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be included
+in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR
+OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall
+not be used in advertising or otherwise to promote the sale, use or
+other dealings in this Software without prior written authorization
+from the X Consortium.
+
+*/
+
+/*
+ * Author:  Keith Packard, MIT X Consortium
+ */
+
+
+#include "fntfilst.h"
+#include "bitmap.h"
+#include "pcf.h"
+
+/* Write PCF font files */
+
+static int  current_position;
+
+static int
+pcfWrite(file, b, c)
+    FontFilePtr file;
+    char       *b;
+    int         c;
+{
+    current_position += c;
+    return FontFileWrite(file, b, c);
+}
+
+static int
+pcfPutLSB32(file, c)
+    FontFilePtr file;
+{
+    current_position += 4;
+    (void) FontFilePutc(c, file);
+    (void) FontFilePutc(c >> 8, file);
+    (void) FontFilePutc(c >> 16, file);
+    return FontFilePutc(c >> 24, file);
+}
+
+static int
+pcfPutINT32(file, format, c)
+    FontFilePtr file;
+    CARD32      format;
+{
+    current_position += 4;
+    if (PCF_BYTE_ORDER(format) == MSBFirst) {
+       (void) FontFilePutc(c >> 24, file);
+       (void) FontFilePutc(c >> 16, file);
+       (void) FontFilePutc(c >> 8, file);
+       return FontFilePutc(c, file);
+    } else {
+       (void) FontFilePutc(c, file);
+       (void) FontFilePutc(c >> 8, file);
+       (void) FontFilePutc(c >> 16, file);
+       return FontFilePutc(c >> 24, file);
+    }
+}
+
+static int
+pcfPutINT16(file, format, c)
+    FontFilePtr file;
+    CARD32      format;
+{
+    current_position += 2;
+    if (PCF_BYTE_ORDER(format) == MSBFirst) {
+       (void) FontFilePutc(c >> 8, file);
+       return FontFilePutc(c, file);
+    } else {
+       (void) FontFilePutc(c, file);
+       return FontFilePutc(c >> 8, file);
+    }
+}
+
+/*ARGSUSED*/
+static int
+pcfPutINT8(file, format, c)
+    FontFilePtr file;
+    CARD32      format;
+{
+    current_position += 1;
+    return FontFilePutc(c, file);
+}
+
+static
+pcfWriteTOC(file, table, count)
+    FontFilePtr file;
+    PCFTablePtr table;
+    int         count;
+{
+    CARD32      version;
+    int         i;
+
+    version = PCF_FILE_VERSION;
+    pcfPutLSB32(file, version);
+    pcfPutLSB32(file, count);
+    for (i = 0; i < count; i++) {
+       pcfPutLSB32(file, table->type);
+       pcfPutLSB32(file, table->format);
+       pcfPutLSB32(file, table->size);
+       pcfPutLSB32(file, table->offset);
+       table++;
+    }
+}
+
+static
+pcfPutCompressedMetric(file, format, metric)
+    FontFilePtr file;
+    CARD32      format;
+    xCharInfo  *metric;
+{
+    pcfPutINT8(file, format, metric->leftSideBearing + 0x80);
+    pcfPutINT8(file, format, metric->rightSideBearing + 0x80);
+    pcfPutINT8(file, format, metric->characterWidth + 0x80);
+    pcfPutINT8(file, format, metric->ascent + 0x80);
+    pcfPutINT8(file, format, metric->descent + 0x80);
+}
+
+static
+pcfPutMetric(file, format, metric)
+    FontFilePtr file;
+    CARD32      format;
+    xCharInfo  *metric;
+{
+    pcfPutINT16(file, format, metric->leftSideBearing);
+    pcfPutINT16(file, format, metric->rightSideBearing);
+    pcfPutINT16(file, format, metric->characterWidth);
+    pcfPutINT16(file, format, metric->ascent);
+    pcfPutINT16(file, format, metric->descent);
+    pcfPutINT16(file, format, metric->attributes);
+}
+
+static
+pcfPutBitmap(file, format, pCI)
+    FontFilePtr file;
+    CARD32      format;
+    CharInfoPtr pCI;
+{
+    int         count;
+    unsigned char *bits;
+
+    count = BYTES_FOR_GLYPH(pCI, PCF_GLYPH_PAD(format));
+    bits = (unsigned char *) pCI->bits;
+    current_position += count;
+    while (count--)
+       FontFilePutc(*bits++, file);
+}
+
+static
+pcfPutAccel(file, format, pFontInfo)
+    FontFilePtr file;
+    CARD32      format;
+    FontInfoPtr pFontInfo;
+{
+    pcfPutINT8(file, format, pFontInfo->noOverlap);
+    pcfPutINT8(file, format, pFontInfo->constantMetrics);
+    pcfPutINT8(file, format, pFontInfo->terminalFont);
+    pcfPutINT8(file, format, pFontInfo->constantWidth);
+    pcfPutINT8(file, format, pFontInfo->inkInside);
+    pcfPutINT8(file, format, pFontInfo->inkMetrics);
+    pcfPutINT8(file, format, pFontInfo->drawDirection);
+    pcfPutINT8(file, format, 0);
+    pcfPutINT32(file, format, pFontInfo->fontAscent);
+    pcfPutINT32(file, format, pFontInfo->fontDescent);
+    pcfPutINT32(file, format, pFontInfo->maxOverlap);
+    pcfPutMetric(file, format, &pFontInfo->minbounds);
+    pcfPutMetric(file, format, &pFontInfo->maxbounds);
+    if (PCF_FORMAT_MATCH(format, PCF_ACCEL_W_INKBOUNDS)) {
+       pcfPutMetric(file, format, &pFontInfo->ink_minbounds);
+       pcfPutMetric(file, format, &pFontInfo->ink_maxbounds);
+    }
+}
+
+#define S32 4
+#define S16 2
+#define S8 1
+
+#define Pad(s)     (RoundUp(s) - (s))
+#define RoundUp(s)  (((s) + 3) & ~3)
+
+#define Compressable(i)        (-128 <= (i) && (i) <= 127)
+
+#define CanCompressMetric(m)   (Compressable((m)->leftSideBearing) && \
+                                Compressable((m)->rightSideBearing) && \
+                                Compressable((m)->characterWidth) && \
+                                Compressable((m)->ascent) && \
+                                Compressable((m)->descent) && \
+                                (m)->attributes == 0)
+
+#define CanCompressMetrics(min,max) (CanCompressMetric(min) && CanCompressMetric(max))
+
+static char *
+pcfNameForAtom(a)
+    Atom        a;
+{
+    return NameForAtom(a);
+}
+
+pcfWriteFont(pFont, file)
+    FontPtr     pFont;
+    FontFilePtr file;
+{
+    PCFTableRec tables[32],
+               *table;
+    CARD32      mask,
+                bit;
+    int         ntables;
+    int         size;
+    CARD32      format;
+    int         i;
+    int         cur_table;
+    int         prop_string_size;
+    int         glyph_string_size;
+    xCharInfo  *minbounds,
+               *maxbounds;
+    xCharInfo  *ink_minbounds,
+               *ink_maxbounds;
+    BitmapFontPtr  bitmapFont;
+    int         nencodings;
+    int         header_size;
+    FontPropPtr offsetProps;
+    int         prop_pad;
+    char       *atom_name;
+    int         glyph;
+    int         offset;
+
+    bitmapFont = (BitmapFontPtr) pFont->fontPrivate;
+    if (bitmapFont->bitmapExtra) {
+       minbounds = &bitmapFont->bitmapExtra->info.minbounds;
+       maxbounds = &bitmapFont->bitmapExtra->info.maxbounds;
+       ink_minbounds = &bitmapFont->bitmapExtra->info.ink_minbounds;
+       ink_maxbounds = &bitmapFont->bitmapExtra->info.ink_maxbounds;
+    } else {
+       minbounds = &pFont->info.minbounds;
+       maxbounds = &pFont->info.maxbounds;
+       ink_minbounds = &pFont->info.ink_minbounds;
+       ink_maxbounds = &pFont->info.ink_maxbounds;
+    }
+    offsetProps = (FontPropPtr) xalloc(pFont->info.nprops * sizeof(FontPropRec));
+    if (!offsetProps)
+       return AllocError;
+    prop_string_size = 0;
+    for (i = 0; i < pFont->info.nprops; i++) {
+       offsetProps[i].name = prop_string_size;
+       prop_string_size += strlen(pcfNameForAtom(pFont->info.props[i].name)) + 1;
+       if (pFont->info.isStringProp[i]) {
+           offsetProps[i].value = prop_string_size;
+           prop_string_size += strlen(pcfNameForAtom(pFont->info.props[i].value)) + 1;
+       } else
+           offsetProps[i].value = pFont->info.props[i].value;
+    }
+    format = PCF_FORMAT(pFont->bit, pFont->byte, pFont->glyph, pFont->scan);
+    mask = 0xFFFFFFF;
+    ntables = 0;
+    table = tables;
+    while (mask) {
+       bit = lowbit(mask);
+       mask &= ~bit;
+       table->type = bit;
+       switch (bit) {
+       case PCF_PROPERTIES:
+           table->format = PCF_DEFAULT_FORMAT | format;
+           size = S32 + S32 + (S32 + S8 + S32) * pFont->info.nprops;
+           prop_pad = Pad(size);
+           table->size = RoundUp(size) + S32 +
+               RoundUp(prop_string_size);
+           table++;
+           break;
+       case PCF_ACCELERATORS:
+           if (bitmapFont->bitmapExtra->info.inkMetrics)
+               table->format = PCF_ACCEL_W_INKBOUNDS | format;
+           else
+               table->format = PCF_DEFAULT_FORMAT | format;
+           table->size = 100;
+           table++;
+           break;
+       case PCF_METRICS:
+           if (CanCompressMetrics(minbounds, maxbounds)) {
+               table->format = PCF_COMPRESSED_METRICS | format;
+               size = S32 + S16 + bitmapFont->num_chars * (5 * S8);
+               table->size = RoundUp(size);
+           } else {
+               table->format = PCF_DEFAULT_FORMAT | format;
+               table->size = S32 + S32 + bitmapFont->num_chars * (6 * S16);
+           }
+           table++;
+           break;
+       case PCF_BITMAPS:
+           table->format = PCF_DEFAULT_FORMAT | format;
+           size = S32 + S32 + bitmapFont->num_chars * S32 +
+               GLYPHPADOPTIONS * S32 +
+               bitmapFont->bitmapExtra->bitmapsSizes[PCF_GLYPH_PAD_INDEX(format)];
+           table->size = RoundUp(size);
+           table++;
+           break;
+       case PCF_INK_METRICS:
+           if (bitmapFont->ink_metrics) {
+               if (CanCompressMetrics(ink_minbounds, ink_maxbounds)) {
+                   table->format = PCF_COMPRESSED_METRICS | format;
+                   size = S32 + S16 + bitmapFont->num_chars * (5 * S8);
+                   table->size = RoundUp(size);
+               } else {
+                   table->format = PCF_DEFAULT_FORMAT | format;
+                   table->size = S32 + S32 + bitmapFont->num_chars * (6 * S16);
+               }
+               table++;
+           }
+           break;
+       case PCF_BDF_ENCODINGS:
+           table->format = PCF_DEFAULT_FORMAT | format;
+           nencodings = (pFont->info.lastRow - pFont->info.firstRow + 1) *
+               (pFont->info.lastCol - pFont->info.firstCol + 1);
+           size = S32 + 5 * S16 + nencodings * S16;
+           table->size = RoundUp(size);
+           table++;
+           break;
+       case PCF_SWIDTHS:
+           table->format = PCF_DEFAULT_FORMAT | format;
+           table->size = S32 + S32 + bitmapFont->num_chars * S32;
+           table++;
+           break;
+       case PCF_GLYPH_NAMES:
+           table->format = PCF_DEFAULT_FORMAT | format;
+           glyph_string_size = 0;
+           for (i = 0; i < bitmapFont->num_chars; i++)
+               glyph_string_size += strlen(pcfNameForAtom(bitmapFont->bitmapExtra->glyphNames[i])) + 1;
+           table->size = S32 + S32 + bitmapFont->num_chars * S32 +
+               S32 + RoundUp(glyph_string_size);
+           table++;
+           break;
+       case PCF_BDF_ACCELERATORS:
+           if (pFont->info.inkMetrics)
+               table->format = PCF_ACCEL_W_INKBOUNDS | format;
+           else
+               table->format = PCF_DEFAULT_FORMAT | format;
+           table->size = 100;
+           table++;
+           break;
+       }
+    }
+    ntables = table - tables;
+    offset = 0;
+    header_size = S32 + S32 + ntables * (4 * S32);
+    offset = header_size;
+    for (cur_table = 0, table = tables;
+           cur_table < ntables;
+           cur_table++, table++) {
+       table->offset = offset;
+       offset += table->size;
+    }
+    current_position = 0;
+    pcfWriteTOC(file, tables, ntables);
+    for (cur_table = 0, table = tables;
+           cur_table < ntables;
+           cur_table++, table++) {
+       if (current_position > table->offset) {
+           printf("can't go backwards... %d > %d\n",
+                  current_position, table->offset);
+           return BadFontName;
+       }
+       while (current_position < table->offset)
+           pcfPutINT8(file, format, '\0');
+       pcfPutLSB32(file, table->format);
+       switch (table->type) {
+       case PCF_PROPERTIES:
+           pcfPutINT32(file, format, pFont->info.nprops);
+           for (i = 0; i < pFont->info.nprops; i++) {
+               pcfPutINT32(file, format, offsetProps[i].name);
+               pcfPutINT8(file, format, pFont->info.isStringProp[i]);
+               pcfPutINT32(file, format, offsetProps[i].value);
+           }
+           for (i = 0; i < prop_pad; i++)
+               pcfPutINT8(file, format, 0);
+           pcfPutINT32(file, format, prop_string_size);
+           for (i = 0; i < pFont->info.nprops; i++) {
+               atom_name = pcfNameForAtom(pFont->info.props[i].name);
+               pcfWrite(file, atom_name, strlen(atom_name) + 1);
+               if (pFont->info.isStringProp[i]) {
+                   atom_name = pcfNameForAtom(pFont->info.props[i].value);
+                   pcfWrite(file, atom_name, strlen(atom_name) + 1);
+               }
+           }
+           break;
+       case PCF_ACCELERATORS:
+           pcfPutAccel(file, table->format, &bitmapFont->bitmapExtra->info);
+           break;
+       case PCF_METRICS:
+           if (PCF_FORMAT_MATCH(table->format, PCF_COMPRESSED_METRICS)) {
+               pcfPutINT16(file, format, bitmapFont->num_chars);
+               for (i = 0; i < bitmapFont->num_chars; i++)
+                   pcfPutCompressedMetric(file, format, &bitmapFont->metrics[i].metrics);
+           } else {
+               pcfPutINT32(file, format, bitmapFont->num_chars);
+               for (i = 0; i < bitmapFont->num_chars; i++)
+                   pcfPutMetric(file, format, &bitmapFont->metrics[i].metrics);
+           }
+           break;
+       case PCF_BITMAPS:
+           pcfPutINT32(file, format, bitmapFont->num_chars);
+           glyph = PCF_GLYPH_PAD(format);
+           offset = 0;
+           for (i = 0; i < bitmapFont->num_chars; i++) {
+               pcfPutINT32(file, format, offset);
+               offset += BYTES_FOR_GLYPH(&bitmapFont->metrics[i], glyph);
+           }
+           for (i = 0; i < GLYPHPADOPTIONS; i++) {
+               pcfPutINT32(file, format,
+                           bitmapFont->bitmapExtra->bitmapsSizes[i]);
+           }
+           for (i = 0; i < bitmapFont->num_chars; i++)
+               pcfPutBitmap(file, format, &bitmapFont->metrics[i]);
+           break;
+       case PCF_INK_METRICS:
+           if (PCF_FORMAT_MATCH(table->format, PCF_COMPRESSED_METRICS)) {
+               pcfPutINT16(file, format, bitmapFont->num_chars);
+               for (i = 0; i < bitmapFont->num_chars; i++)
+                   pcfPutCompressedMetric(file, format, &bitmapFont->ink_metrics[i]);
+           } else {
+               pcfPutINT32(file, format, bitmapFont->num_chars);
+               for (i = 0; i < bitmapFont->num_chars; i++)
+                   pcfPutMetric(file, format, &bitmapFont->ink_metrics[i]);
+           }
+           break;
+       case PCF_BDF_ENCODINGS:
+           pcfPutINT16(file, format, pFont->info.firstCol);
+           pcfPutINT16(file, format, pFont->info.lastCol);
+           pcfPutINT16(file, format, pFont->info.firstRow);
+           pcfPutINT16(file, format, pFont->info.lastRow);
+           pcfPutINT16(file, format, pFont->info.defaultCh);
+           for (i = 0; i < nencodings; i++) {
+               if (bitmapFont->encoding[i])
+                   pcfPutINT16(file, format, bitmapFont->encoding[i] - bitmapFont->metrics);
+               else
+                   pcfPutINT16(file, format, 0xFFFF);
+           }
+           break;
+       case PCF_SWIDTHS:
+           pcfPutINT32(file, format, bitmapFont->num_chars);
+           for (i = 0; i < bitmapFont->num_chars; i++)
+               pcfPutINT32(file, format, bitmapFont->bitmapExtra->sWidths[i]);
+           break;
+       case PCF_GLYPH_NAMES:
+           pcfPutINT32(file, format, bitmapFont->num_chars);
+           offset = 0;
+           for (i = 0; i < bitmapFont->num_chars; i++) {
+               pcfPutINT32(file, format, offset);
+               offset += strlen(pcfNameForAtom(bitmapFont->bitmapExtra->glyphNames[i])) + 1;
+           }
+           pcfPutINT32(file, format, offset);
+           for (i = 0; i < bitmapFont->num_chars; i++) {
+               atom_name = pcfNameForAtom(bitmapFont->bitmapExtra->glyphNames[i]);
+               pcfWrite(file, atom_name, strlen(atom_name) + 1);
+           }
+           break;
+       case PCF_BDF_ACCELERATORS:
+           pcfPutAccel(file, table->format, &pFont->info);
+           break;
+       }
+    }
+    return Successful;
+}
diff --git a/Xserver/lib/font/bitmap/snfread.c b/Xserver/lib/font/bitmap/snfread.c
new file mode 100644 (file)
index 0000000..e6d99f8
--- /dev/null
@@ -0,0 +1,491 @@
+/* $XConsortium: snfread.c,v 1.17 94/04/17 20:17:16 gildea Exp $ */
+/************************************************************************
+Copyright 1989 by Digital Equipment Corporation, Maynard, Massachusetts.
+
+                        All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and its
+documentation for any purpose and without fee is hereby granted,
+provided that the above copyright notice appear in all copies and that
+both that copyright notice and this permission notice appear in
+supporting documentation, and that the name of Digital not be
+used in advertising or publicity pertaining to distribution of the
+software without specific, written prior permission.
+
+DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
+ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
+DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
+ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+SOFTWARE.
+
+************************************************************************/
+
+/*
+
+Copyright (c) 1994  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be included
+in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR
+OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall
+not be used in advertising or otherwise to promote the sale, use or
+other dealings in this Software without prior written authorization
+from the X Consortium.
+
+*/
+
+#include <ctype.h>
+#include "fntfilst.h"
+#include "bitmap.h"
+#include "snfstr.h"
+
+static void snfUnloadFont();
+
+static int
+snfReadCharInfo(file, charInfo, base)
+    FontFilePtr file;
+    CharInfoPtr charInfo;
+    char       *base;
+{
+    snfCharInfoRec snfCharInfo;
+
+#define Width(m)    ((m).rightSideBearing - (m).leftSideBearing)
+#define Height(m)   ((m).ascent + (m).descent)
+
+    if (FontFileRead(file, (char *) &snfCharInfo, sizeof snfCharInfo) !=
+           sizeof(snfCharInfo)) {
+       return BadFontName;
+    }
+    charInfo->metrics = snfCharInfo.metrics;
+    if (snfCharInfo.exists)
+       charInfo->bits = base + snfCharInfo.byteOffset;
+    else
+       charInfo->bits = 0;
+    return Successful;
+}
+
+static int
+snfReadxCharInfo(file, charInfo)
+    FontFilePtr file;
+    xCharInfo  *charInfo;
+{
+    snfCharInfoRec snfCharInfo;
+
+    if (FontFileRead(file, (char *) &snfCharInfo, sizeof snfCharInfo) !=
+           sizeof(snfCharInfo)) {
+       return BadFontName;
+    }
+    *charInfo = snfCharInfo.metrics;
+    return Successful;
+}
+
+static
+snfCopyInfo(snfInfo, pFontInfo)
+    snfFontInfoPtr snfInfo;
+    FontInfoPtr pFontInfo;
+{
+    pFontInfo->firstCol = snfInfo->firstCol;
+    pFontInfo->lastCol = snfInfo->lastCol;
+    pFontInfo->firstRow = snfInfo->firstRow;
+    pFontInfo->lastRow = snfInfo->lastRow;
+    pFontInfo->defaultCh = snfInfo->chDefault;
+    pFontInfo->noOverlap = snfInfo->noOverlap;
+    pFontInfo->terminalFont = snfInfo->terminalFont;
+    pFontInfo->constantMetrics = snfInfo->constantMetrics;
+    pFontInfo->constantWidth = snfInfo->constantWidth;
+    pFontInfo->inkInside = snfInfo->inkInside;
+    pFontInfo->inkMetrics = snfInfo->inkMetrics;
+    pFontInfo->allExist = snfInfo->allExist;
+    pFontInfo->drawDirection = snfInfo->drawDirection;
+    pFontInfo->anamorphic = FALSE;
+    pFontInfo->cachable = TRUE;
+    pFontInfo->maxOverlap = 0;
+    pFontInfo->minbounds = snfInfo->minbounds.metrics;
+    pFontInfo->maxbounds = snfInfo->maxbounds.metrics;
+    pFontInfo->fontAscent = snfInfo->fontAscent;
+    pFontInfo->fontDescent = snfInfo->fontDescent;
+    pFontInfo->nprops = snfInfo->nProps;
+}
+
+static int
+snfReadProps(snfInfo, pFontInfo, file)
+    snfFontInfoPtr snfInfo;
+    FontInfoPtr pFontInfo;
+    FontFilePtr file;
+{
+    char       *strings;
+    FontPropPtr pfp;
+    snfFontPropPtr psnfp;
+    char       *propspace;
+    int         bytestoalloc;
+    int         i;
+
+    bytestoalloc = snfInfo->nProps * sizeof(snfFontPropRec) +
+       BYTESOFSTRINGINFO(snfInfo);
+    propspace = (char *) xalloc(bytestoalloc);
+    if (!propspace)
+       return AllocError;
+
+    if (FontFileRead(file, propspace, bytestoalloc) != bytestoalloc) {
+       xfree(propspace);
+       return BadFontName;
+    }
+    psnfp = (snfFontPropPtr) propspace;
+
+    strings = propspace + BYTESOFPROPINFO(snfInfo);
+
+    for (i = 0, pfp = pFontInfo->props; i < snfInfo->nProps; i++, pfp++, psnfp++) {
+       pfp->name = MakeAtom(&strings[psnfp->name],
+                            (unsigned) strlen(&strings[psnfp->name]), 1);
+       pFontInfo->isStringProp[i] = psnfp->indirect;
+       if (psnfp->indirect)
+           pfp->value = (INT32) MakeAtom(&strings[psnfp->value],
+                              (unsigned) strlen(&strings[psnfp->value]), 1);
+       else
+           pfp->value = psnfp->value;
+    }
+
+    xfree(propspace);
+    return Successful;
+}
+
+int
+snfReadHeader(snfInfo, file)
+    snfFontInfoPtr snfInfo;
+    FontFilePtr file;
+{
+    if (FontFileRead(file, (char *) snfInfo, sizeof *snfInfo) != sizeof *snfInfo)
+       return BadFontName;
+
+    if (snfInfo->version1 != FONT_FILE_VERSION ||
+           snfInfo->version2 != FONT_FILE_VERSION)
+       return BadFontName;
+    return Successful;
+}
+
+int
+snfReadFont(pFont, file, bit, byte, glyph, scan)
+    FontPtr     pFont;
+    FontFilePtr file;
+    int         bit,
+                byte,
+                glyph,
+                scan;
+{
+    snfFontInfoRec fi;
+    unsigned    bytestoalloc;
+    int         i;
+    char       *fontspace;
+    BitmapFontPtr  bitmapFont;
+    int         num_chars;
+    int         bitmapsSize;
+    int         ret;
+    int         metrics_off;
+    int         encoding_off;
+    int         props_off;
+    int         isStringProp_off;
+    int         ink_off;
+    char       *bitmaps;
+    int                def_bit, def_byte, def_glyph, def_scan;
+
+    ret = snfReadHeader(&fi, file);
+    if (ret != Successful)
+       return ret;
+
+    SnfGetFormat (&def_bit, &def_byte, &def_glyph, &def_scan);
+
+    /*
+     * we'll allocate one chunk of memory and split it among the various parts
+     * of the font:
+     * 
+     * BitmapFontRec CharInfoRec's Glyphs Encoding DIX Properties Ink CharInfoRec's
+     *
+     * If the glyphpad is not the same as the font file, then the glyphs
+     * are allocated separately, to be later realloc'ed when we know
+     * how big to make them.
+     */
+
+    bitmapsSize = BYTESOFGLYPHINFO(&fi);
+    num_chars = n2dChars(&fi);
+    bytestoalloc = sizeof(BitmapFontRec);      /* bitmapFont */
+    metrics_off = bytestoalloc;
+    bytestoalloc += num_chars * sizeof(CharInfoRec);   /* metrics */
+    encoding_off = bytestoalloc;
+    bytestoalloc += num_chars * sizeof(CharInfoPtr);   /* encoding */
+    props_off = bytestoalloc;
+    bytestoalloc += fi.nProps * sizeof(FontPropRec);   /* props */
+    isStringProp_off = bytestoalloc;
+    bytestoalloc += fi.nProps * sizeof(char);  /* isStringProp */
+    bytestoalloc = (bytestoalloc + 3) & ~3;
+    ink_off = bytestoalloc;
+    if (fi.inkMetrics)
+       bytestoalloc += num_chars * sizeof(xCharInfo);  /* ink_metrics */
+
+    fontspace = (char *) xalloc(bytestoalloc);
+    if (!fontspace)
+       return AllocError;
+
+    bitmaps = (char *) xalloc (bitmapsSize);
+    if (!bitmaps)
+    {
+       xfree (fontspace);
+       return AllocError;
+    }
+    /*
+     * now fix up pointers
+     */
+
+    bitmapFont = (BitmapFontPtr) fontspace;
+    bitmapFont->num_chars = num_chars;
+    bitmapFont->metrics = (CharInfoPtr) (fontspace + metrics_off);
+    bitmapFont->encoding = (CharInfoPtr *) (fontspace + encoding_off);
+    bitmapFont->bitmaps = bitmaps;
+    bitmapFont->pDefault = NULL;
+    bitmapFont->bitmapExtra = NULL;
+    pFont->info.props = (FontPropPtr) (fontspace + props_off);
+    pFont->info.isStringProp = (char *) (fontspace + isStringProp_off);
+    if (fi.inkMetrics)
+       bitmapFont->ink_metrics = (xCharInfo *) (fontspace + ink_off);
+    else
+       bitmapFont->ink_metrics = 0;
+
+    /*
+     * read the CharInfo
+     */
+
+    ret = Successful;
+    for (i = 0; ret == Successful && i < num_chars; i++) {
+       ret = snfReadCharInfo(file, &bitmapFont->metrics[i], bitmaps);
+       if (bitmapFont->metrics[i].bits)
+           bitmapFont->encoding[i] = &bitmapFont->metrics[i];
+       else
+           bitmapFont->encoding[i] = 0;
+    }
+
+    if (ret != Successful) {
+       xfree(bitmaps);
+       xfree(fontspace);
+       return ret;
+    }
+    /*
+     * read the glyphs
+     */
+
+    if (FontFileRead(file, (char *) bitmaps, bitmapsSize) != bitmapsSize) {
+       xfree(bitmaps);
+       xfree(fontspace);
+       return BadFontName;
+    }
+
+    if (def_bit != bit)
+       BitOrderInvert(bitmaps, bitmapsSize);
+    if ((def_byte == def_bit) != (bit == byte)) {
+       switch (bit == byte ? def_scan : scan) {
+       case 1:
+           break;
+       case 2:
+           TwoByteSwap(bitmaps, bitmapsSize);
+           break;
+       case 4:
+           FourByteSwap(bitmaps, bitmapsSize);
+           break;
+       }
+    }
+    if (def_glyph != glyph) {
+       char        *padbitmaps;
+       int         sizepadbitmaps;
+       int         sizechar;
+       CharInfoPtr metric;
+
+       sizepadbitmaps = 0;
+       metric = bitmapFont->metrics;
+       for (i = 0; i < num_chars; i++)
+       {
+           if (metric->bits)
+               sizepadbitmaps += BYTES_FOR_GLYPH(metric,glyph);
+           metric++;
+       }
+       padbitmaps = (char *) xalloc(sizepadbitmaps);
+       if (!padbitmaps) {
+           xfree (bitmaps);
+           xfree (fontspace);
+           return AllocError;
+       }
+       metric = bitmapFont->metrics;
+       bitmapFont->bitmaps = padbitmaps;
+       for (i = 0; i < num_chars; i++) {
+           sizechar = RepadBitmap(metric->bits, padbitmaps,
+                              def_glyph, glyph,
+                              metric->metrics.rightSideBearing -
+                              metric->metrics.leftSideBearing,
+                              metric->metrics.ascent + metric->metrics.descent);
+           metric->bits = padbitmaps;
+           padbitmaps += sizechar;
+           metric++;
+       }
+       xfree(bitmaps);
+    }
+
+    /* now read and atom'ize properties */
+
+    ret = snfReadProps(&fi, &pFont->info, file);
+    if (ret != Successful) {
+       xfree(fontspace);
+       return ret;
+    }
+    snfCopyInfo(&fi, &pFont->info);
+
+    /* finally, read the ink metrics if the exist */
+
+    if (fi.inkMetrics) {
+       ret = Successful;
+       ret = snfReadxCharInfo(file, &pFont->info.ink_minbounds);
+       ret = snfReadxCharInfo(file, &pFont->info.ink_maxbounds);
+       for (i = 0; ret == Successful && i < num_chars; i++)
+           ret = snfReadxCharInfo(file, &bitmapFont->ink_metrics[i]);
+       if (ret != Successful) {
+           xfree(fontspace);
+           return ret;
+       }
+    } else {
+       pFont->info.ink_minbounds = pFont->info.minbounds;
+       pFont->info.ink_maxbounds = pFont->info.maxbounds;
+    }
+
+    if (pFont->info.defaultCh != (unsigned short) NO_SUCH_CHAR) {
+       unsigned int r,
+                   c,
+                   cols;
+
+       r = pFont->info.defaultCh >> 8;
+       c = pFont->info.defaultCh & 0xFF;
+       if (pFont->info.firstRow <= r && r <= pFont->info.lastRow &&
+               pFont->info.firstCol <= c && c <= pFont->info.lastCol) {
+           cols = pFont->info.lastCol - pFont->info.firstCol + 1;
+           r = r - pFont->info.firstRow;
+           c = c - pFont->info.firstCol;
+           bitmapFont->pDefault = &bitmapFont->metrics[r * cols + c];
+       }
+    }
+    bitmapFont->bitmapExtra = (BitmapExtraPtr) 0;
+    pFont->fontPrivate = (pointer) bitmapFont;
+    pFont->get_glyphs = bitmapGetGlyphs;
+    pFont->get_metrics = bitmapGetMetrics;
+    pFont->unload_font = snfUnloadFont;
+    pFont->unload_glyphs = NULL;
+    pFont->bit = bit;
+    pFont->byte = byte;
+    pFont->glyph = glyph;
+    pFont->scan = scan;
+    return Successful;
+}
+
+int
+snfReadFontInfo(pFontInfo, file)
+    FontInfoPtr pFontInfo;
+    FontFilePtr file;
+{
+    int         ret;
+    snfFontInfoRec fi;
+    int         bytestoskip;
+    int         num_chars;
+
+    ret = snfReadHeader(&fi, file);
+    if (ret != Successful)
+       return ret;
+    snfCopyInfo(&fi, pFontInfo);
+
+    pFontInfo->props = (FontPropPtr) xalloc(fi.nProps * sizeof(FontPropRec));
+    if (!pFontInfo->props)
+       return AllocError;
+    pFontInfo->isStringProp = (char *) xalloc(fi.nProps * sizeof(char));
+    if (!pFontInfo->isStringProp) {
+       xfree(pFontInfo->props);
+       return AllocError;
+    }
+    num_chars = n2dChars(&fi);
+    bytestoskip = num_chars * sizeof(snfCharInfoRec);  /* charinfos */
+    bytestoskip += BYTESOFGLYPHINFO(&fi);
+    FontFileSkip(file, bytestoskip);
+
+    ret = snfReadProps(&fi, pFontInfo, file);
+    if (ret != Successful) {
+       xfree(pFontInfo->props);
+       xfree(pFontInfo->isStringProp);
+       return ret;
+    }
+    if (fi.inkMetrics) {
+       ret = snfReadxCharInfo(file, &pFontInfo->ink_minbounds);
+       if (ret != Successful) {
+           xfree(pFontInfo->props);
+           xfree(pFontInfo->isStringProp);
+           return ret;
+       }
+       ret = snfReadxCharInfo(file, &pFontInfo->ink_maxbounds);
+       if (ret != Successful) {
+           xfree(pFontInfo->props);
+           xfree(pFontInfo->isStringProp);
+           return ret;
+       }
+    } else {
+       pFontInfo->ink_minbounds = pFontInfo->minbounds;
+       pFontInfo->ink_maxbounds = pFontInfo->maxbounds;
+    }
+    return Successful;
+
+}
+
+static void
+snfUnloadFont(pFont)
+    FontPtr        pFont;
+{
+    BitmapFontPtr   bitmapFont;
+
+    bitmapFont = (BitmapFontPtr) pFont->fontPrivate;
+    xfree (bitmapFont->bitmaps);
+    xfree (bitmapFont);
+    xfree (pFont->devPrivates);
+    xfree (pFont);
+}
+
+static int  snf_set;
+static int  snf_bit, snf_byte, snf_glyph, snf_scan;
+
+SnfSetFormat (bit, byte, glyph, scan)
+    int        bit, byte, glyph, scan;
+{
+    snf_bit = bit;
+    snf_byte = byte;
+    snf_glyph = glyph;
+    snf_scan = scan;
+    snf_set = 1;
+}
+
+SnfGetFormat (bit, byte, glyph, scan)
+    int        *bit, *byte, *glyph, *scan;
+{
+    if (!snf_set)
+       FontDefaultFormat (&snf_bit, &snf_byte, &snf_glyph, &snf_scan);
+    *bit = snf_bit;
+    *byte = snf_byte;
+    *glyph = snf_glyph;
+    *scan = snf_scan;
+}
diff --git a/Xserver/lib/font/bitmap/snfstr.h b/Xserver/lib/font/bitmap/snfstr.h
new file mode 100644 (file)
index 0000000..8d59cd4
--- /dev/null
@@ -0,0 +1,178 @@
+/* $XConsortium: snfstr.h,v 1.5 94/04/17 20:17:17 rws Exp $ */
+/***********************************************************
+Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
+
+                        All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and its
+documentation for any purpose and without fee is hereby granted,
+provided that the above copyright notice appear in all copies and that
+both that copyright notice and this permission notice appear in
+supporting documentation, and that the name of Digital not be
+used in advertising or publicity pertaining to distribution of the
+software without specific, written prior permission.
+
+DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
+ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
+DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
+ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+SOFTWARE.
+
+******************************************************************/
+
+/*
+
+Copyright (c) 1994  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be included
+in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR
+OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall
+not be used in advertising or otherwise to promote the sale, use or
+other dealings in this Software without prior written authorization
+from the X Consortium.
+
+*/
+
+#ifndef SNFSTR_H
+#define SNFSTR_H 1
+
+/*-
+ * This file describes the Server Natural Font format.
+ * SNF fonts are both CPU-dependent and frame buffer bit order dependent.
+ * This file is used by:
+ *     1)  the server, to hold font information read out of font files.
+ *     2)  font converters
+ *
+ * Each font file contains the following
+ * data structures, with no padding in-between.
+ *
+ *     1)  The XFONTINFO structure
+ *             hand-padded to a two-short boundary.
+ *             maxbounds.byteoffset is the total number of bytes in the
+ *                     glpyh array
+ *             maxbounds.bitOffset is thetotal width of the unpadded font
+ *
+ *     2)  The XCHARINFO array
+ *             indexed directly with character codes, both on disk
+ *             and in memory.
+ *
+ *     3)  Character glyphs
+ *             padded in the server-natural way, and
+ *             ordered in the device-natural way.
+ *             End of glyphs padded to 32-bit boundary.
+ *
+ *     4)  nProps font properties
+ *
+ *     5)  a sequence of null-terminated strings, for font properties
+ */
+
+#define FONT_FILE_VERSION      4
+
+typedef struct _snfFontProp {
+    CARD32      name;          /* offset of string */
+    INT32       value;         /* number or offset of string */
+    Bool        indirect;      /* value is a string offset */
+}           snfFontPropRec;
+
+/*
+ * the following macro definitions describe a font file image in memory
+ */
+#define ADDRCharInfoRec( pfi)  \
+       ((snfCharInfoRec *) &(pfi)[1])
+
+#define ADDRCHARGLYPHS( pfi)   \
+       (((char *) &(pfi)[1]) + BYTESOFCHARINFO(pfi))
+
+/*
+ * pad out glyphs to a CARD32 boundary
+ */
+#define ADDRXFONTPROPS( pfi)  \
+       ((snfFontPropRec *) ((char *)ADDRCHARGLYPHS( pfi) + BYTESOFGLYPHINFO(pfi)))
+
+#define ADDRSTRINGTAB( pfi)  \
+       ((char *)ADDRXFONTPROPS( pfi) + BYTESOFPROPINFO(pfi))
+
+#define n2dChars(pfi)  (((pfi)->lastRow - (pfi)->firstRow + 1) * \
+                        ((pfi)->lastCol - (pfi)->firstCol + 1))
+#define        BYTESOFFONTINFO(pfi)    (sizeof(snfFontInfoRec))
+#define BYTESOFCHARINFO(pfi)   (sizeof(snfCharInfoRec) * n2dChars(pfi))
+#define        BYTESOFPROPINFO(pfi)    (sizeof(snfFontPropRec) * (pfi)->nProps)
+#define        BYTESOFSTRINGINFO(pfi)  ((pfi)->lenStrings)
+#define        BYTESOFGLYPHINFO(pfi)   (((pfi)->maxbounds.byteOffset+3) & ~0x3)
+#define BYTESOFINKINFO(pfi)    (sizeof(snfCharInfoRec) * n2dChars(pfi))
+
+typedef struct _snfFontProp *snfFontPropPtr;
+typedef struct _snfCharInfo *snfCharInfoPtr;
+typedef struct _snfFontInfo *snfFontInfoPtr;
+
+typedef struct _snfCharInfo {
+    xCharInfo   metrics;       /* info preformatted for Queries */
+    unsigned    byteOffset:24; /* byte offset of the raster from pGlyphs */
+    unsigned    exists:1;      /* true iff glyph exists for this char */
+    unsigned    pad:7;         /* must be zero for now */
+}           snfCharInfoRec;
+
+typedef struct _snfFontInfo {
+    unsigned int version1;     /* version stamp */
+    unsigned int allExist;
+    unsigned int drawDirection;
+    unsigned int noOverlap;    /* true if:
+                                * max(rightSideBearing-characterWidth) <=
+                                * minbounds->metrics.leftSideBearing */
+    unsigned int constantMetrics;
+    unsigned int terminalFont; /* Should be deprecated!  true if: constant
+                                * metrics && leftSideBearing == 0 &&
+                                * rightSideBearing == characterWidth &&
+                                * ascent == fontAscent && descent ==
+                                * fontDescent */
+    unsigned int linear:1;     /* true if firstRow == lastRow */
+    unsigned int constantWidth:1;      /* true if
+                                        * minbounds->metrics.characterWidth
+                                        * ==
+                                        * maxbounds->metrics.characterWidth */
+    unsigned int inkInside:1;  /* true if for all defined glyphs:
+                                * leftSideBearing >= 0 && rightSideBearing <=
+                                * characterWidth && -fontDescent <= ascent <=
+                                * fontAscent && -fontAscent <= descent <=
+                                * fontDescent */
+    unsigned int inkMetrics:1; /* ink metrics != bitmap metrics */
+    /* used with terminalFont */
+    /* see font's pInk{CI,Min,Max} */
+    unsigned int padding:28;
+    unsigned int firstCol;
+    unsigned int lastCol;
+    unsigned int firstRow;
+    unsigned int lastRow;
+    unsigned int nProps;
+    unsigned int lenStrings;   /* length in bytes of string table */
+    unsigned int chDefault;    /* default character */
+    int         fontDescent;   /* minimum for quality typography */
+    int         fontAscent;    /* minimum for quality typography */
+    snfCharInfoRec minbounds;  /* MIN of glyph metrics over all chars */
+    snfCharInfoRec maxbounds;  /* MAX of glyph metrics over all chars */
+    unsigned int pixDepth;     /* intensity bits per pixel */
+    unsigned int glyphSets;    /* number of sets of glyphs, for sub-pixel
+                                * positioning */
+    unsigned int version2;     /* version stamp double-check */
+}           snfFontInfoRec;
+
+#endif                         /* SNFSTR_H */
diff --git a/Xserver/lib/font/fc/Imakefile b/Xserver/lib/font/fc/Imakefile
new file mode 100644 (file)
index 0000000..a5ec735
--- /dev/null
@@ -0,0 +1,26 @@
+XCOMM $XConsortium: Imakefile /main/20 1995/12/13 18:07:57 kaleb $
+XCOMM
+XCOMM Make file for font handling routines
+XCOMM
+#include <Server.tmpl>
+
+        INCLUDES = -I$(FONTINCSRC) -I../include
+         HEADERS = 
+            SRCS = fsconvert.c fserve.c fsio.c transport.c
+            OBJS = fsconvert.o fserve.o fsio.o transport.o
+         DEFINES = $(SIGNAL_DEFINES)
+    CONN_DEFINES = ConnectionFlags -DFONT_t -DTRANS_CLIENT -DTRANS_SERVER -DTRANS_REOPEN
+#if HasBSD44Sockets
+    SOCK_DEFINES = -DBSD44SOCKETS
+#endif
+  DEPEND_DEFINES = $(TRANS_INCLUDES) $(CONN_DEFINES)
+
+SubdirLibraryRule($(OBJS))
+NormalLibraryObjectRule()
+SpecialCObjectRule(fsio,$(ICONFIGFILES),$(CONN_DEFINES) $(SOCK_DEFINES))
+SpecialCObjectRule(transport,$(ICONFIGFILES),$(TRANS_INCLUDES) $(CONN_DEFINES) $(SOCK_DEFINES))
+LinkSourceFile(transport.c,$(TRANSCOMMSRC))
+
+NormalLintTarget($(SRCS))
+
+DependTarget()
diff --git a/Xserver/lib/font/fc/fsconvert.c b/Xserver/lib/font/fc/fsconvert.c
new file mode 100644 (file)
index 0000000..346b0b4
--- /dev/null
@@ -0,0 +1,703 @@
+/* $XConsortium: fsconvert.c,v 1.17 94/02/14 17:47:35 gildea Exp $ */
+/*
+ * Copyright 1990 Network Computing Devices
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and
+ * its documentation for any purpose is hereby granted without fee, provided
+ * that the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the name of Network Computing Devices not be used
+ * in advertising or publicity pertaining to distribution of the software
+ * without specific, written prior permission.  Network Computing Devices
+ * makes no representations about the suitability of this software for any
+ * purpose.  It is provided "as is" without express or implied warranty.
+ *
+ * NETWORK COMPUTING DEVICES DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
+ * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS,
+ * IN NO EVENT SHALL NETWORK COMPUTING DEVICES BE LIABLE FOR ANY SPECIAL,
+ * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
+ * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
+ * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE
+ * OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ * Author:     Dave Lemke, Network Computing Devices, Inc
+ */
+/*
+ * FS data conversion
+ */
+
+#include        <X11/X.h>
+#include       "FS.h"
+#include       "FSproto.h"
+#include       "fontmisc.h"
+#include       "fontstruct.h"
+#include       "fservestr.h"
+
+extern char _fs_glyph_undefined;
+extern char _fs_glyph_requested;
+extern char _fs_glyph_zero_length;
+
+extern int _fs_load_glyphs();
+
+/*
+ * converts data from font server form to X server form
+ */
+
+void
+_fs_convert_char_info(src, dst)
+    fsXCharInfo *src;
+    xCharInfo *dst;
+{
+    dst->ascent = src->ascent;
+    dst->descent = src->descent;
+    dst->leftSideBearing = src->left;
+    dst->rightSideBearing = src->right;
+    dst->characterWidth = src->width;
+    dst->attributes = src->attributes;
+}
+
+void
+_fs_init_fontinfo(conn, pfi)
+    FSFpePtr    conn;
+    FontInfoPtr pfi;
+{
+    if (conn->fsMajorVersion == 1) {
+       unsigned short n;
+       n = pfi->firstCol;
+       pfi->firstCol = pfi->firstRow;
+       pfi->firstRow = n;
+       n = pfi->lastCol;
+       pfi->lastCol = pfi->lastRow;
+       pfi->lastRow = n;
+       pfi->defaultCh = (pfi->defaultCh >> 8) & 0xff
+                          + (pfi->defaultCh & 0xff) << 8;
+    }
+
+    if (FontCouldBeTerminal (pfi))
+    {
+       pfi->terminalFont = TRUE;
+       pfi->minbounds.ascent = pfi->fontAscent;
+       pfi->minbounds.descent = pfi->fontDescent;
+       pfi->minbounds.leftSideBearing = 0;
+       pfi->minbounds.rightSideBearing = pfi->minbounds.characterWidth;
+       pfi->maxbounds = pfi->minbounds;
+    }
+
+    FontComputeInfoAccelerators (pfi);
+}
+
+int
+_fs_convert_props(pi, po, pd, pfi)
+    fsPropInfo *pi;
+    fsPropOffset *po;
+    pointer     pd;
+    FontInfoPtr pfi;
+{
+    FontPropPtr dprop;
+    int         i,
+                nprops;
+    char       *is_str;
+    fsPropOffset local_off;
+    char *off_adr;
+
+/* stolen from server/include/resource.h */
+#define BAD_RESOURCE 0xe0000000
+
+    nprops = pfi->nprops = pi->num_offsets;
+
+    dprop = (FontPropPtr) xalloc(sizeof(FontPropRec) * nprops);
+    is_str = (char *) xalloc(sizeof(char) * nprops);
+    if (!dprop || !is_str) {
+       xfree(is_str);
+       xfree(dprop);
+       return -1;
+    }
+    pfi->props = dprop;
+    pfi->isStringProp = is_str;
+
+    off_adr = (char *)po;
+    for (i = 0; i < nprops; i++, dprop++, is_str++) {
+       memcpy(&local_off, off_adr, SIZEOF(fsPropOffset));
+       dprop->name = MakeAtom(&pd[local_off.name.position],
+                              local_off.name.length, 1);
+       if (local_off.type != PropTypeString) {
+           *is_str = FALSE;
+           dprop->value = local_off.value.position;
+       } else {
+           *is_str = TRUE;
+           dprop->value = (INT32) MakeAtom(&pd[local_off.value.position],
+                                           local_off.value.length, 1);
+           if (dprop->value == BAD_RESOURCE)
+           {
+               xfree (pfi->props);
+               xfree (pfi->isStringProp);
+               pfi->props = 0;
+               pfi->isStringProp = 0;
+               return -1;
+           }
+       }
+       off_adr += SIZEOF(fsPropOffset);
+    }
+
+    return nprops;
+}
+
+int
+_fs_convert_lfwi_reply(conn, pfi, fsrep, pi, po, pd)
+    FSFpePtr    conn;
+    FontInfoPtr pfi;
+    fsListFontsWithXInfoReply *fsrep;
+    fsPropInfo *pi;
+    fsPropOffset *po;
+    pointer     pd;
+{
+    fsUnpack_XFontInfoHeader(fsrep, pfi);
+    _fs_init_fontinfo(conn, pfi);
+
+    if (_fs_convert_props(pi, po, pd, pfi) == -1)
+       return AllocError;
+
+    return Successful;
+}
+
+
+#define ENCODING_UNDEFINED(enc) \
+       ((enc)->bits == &_fs_glyph_undefined ? \
+        TRUE : \
+        (access_done = access_done && (enc)->bits != &_fs_glyph_requested, \
+         FALSE))
+
+#define GLYPH_UNDEFINED(loc) ENCODING_UNDEFINED(encoding + (loc))
+
+/*
+ * figures out what glyphs to request
+ *
+ * Includes logic to attempt to reduce number of round trips to the font
+ * server:  when a glyph is requested, fs_build_range() requests a
+ * 16-glyph range of glyphs that contains the requested glyph.  This is
+ * predicated on the belief that using a glyph increases the chances
+ * that nearby glyphs will be used: a good assumption for phonetic
+ * alphabets, but a questionable one for ideographic/pictographic ones.
+ */
+/* ARGSUSED */
+int
+fs_build_range(pfont, range_flag, count, item_size, data, nranges, ranges)
+    FontPtr     pfont;
+    Bool       range_flag;
+    register unsigned int count;
+    int         item_size;
+    register unsigned char *data;
+    int               *nranges;
+    fsRange   **ranges;
+{
+    FSFontDataPtr fsd = (FSFontDataPtr) (pfont->fpePrivate);
+    FSFontPtr fsfont = (FSFontPtr) (pfont->fontPrivate);
+    register CharInfoPtr encoding = fsfont->encoding;
+    FontInfoPtr pfi = &(pfont->info);
+    fsRange    range;
+    int                access_done = TRUE;
+    int                err;
+    register unsigned long firstrow, lastrow, firstcol, lastcol;
+    register unsigned long row;
+    register unsigned long col;
+    register unsigned long loc;
+
+    if (!fsd->glyphs_to_get)
+       return AccessDone;
+
+    firstrow = pfi->firstRow;
+    lastrow = pfi->lastRow;
+    firstcol = pfi->firstCol;
+    lastcol = pfi->lastCol;
+
+    /* Make sure we have default char */
+    if (fsfont->pDefault && ENCODING_UNDEFINED(fsfont->pDefault))
+    {
+       loc = fsfont->pDefault - encoding;
+       row = loc / (lastcol - firstcol + 1) + firstrow;
+       col = loc % (lastcol - firstcol + 1) + firstcol;
+
+       range.min_char_low = range.max_char_low = col;
+       range.min_char_high = range.max_char_high = row;
+
+       if ((err = add_range(&range, nranges, ranges, FALSE)) !=
+           Successful) return err;
+       encoding[loc].bits = &_fs_glyph_requested;
+       access_done = FALSE;
+    }
+
+    if (!range_flag && item_size == 1)
+    {
+       if (firstrow != 0) return AccessDone;
+       while (count--)
+       {
+           col = *data++;
+           if (col >= firstcol && col <= lastcol &&
+               GLYPH_UNDEFINED(col - firstcol))
+           {
+               int col1, col2;
+               col1 = col & 0xf0;
+               col2 = col1 + 15;
+               if (col1 < firstcol) col1 = firstcol;
+               if (col2 > lastcol) col2 = lastcol;
+               /* Collect a 16-glyph neighborhood containing the requested
+                  glyph... should in most cases reduce the number of round
+                  trips to the font server. */
+               for (col = col1; col <= col2; col++)
+               {
+                   if (!GLYPH_UNDEFINED(col - firstcol)) continue;
+                   range.min_char_low = range.max_char_low = col;
+                   range.min_char_high = range.max_char_high = 0;
+                   if ((err = add_range(&range, nranges, ranges, FALSE)) !=
+                       Successful) return err;
+                   encoding[col - firstcol].bits = &_fs_glyph_requested;
+                   access_done = FALSE;
+               }
+           }
+       }
+    }
+    else
+    {
+       fsRange fullrange[1];
+
+       if (range_flag && count == 0)
+       {
+           count = 2;
+           data = (unsigned char *)fullrange;
+           fullrange[0].min_char_high = firstrow;
+           fullrange[0].min_char_low = firstcol;
+           fullrange[0].max_char_high = lastrow;
+           fullrange[0].max_char_low = lastcol;
+       }
+
+       while (count--)
+       {
+           int row1, col1, row2, col2;
+           row1 = row2 = *data++;
+           col1 = col2 = *data++;
+           if (range_flag)
+           {
+               if (count)
+               {
+                   row2 = *data++;
+                   col2 = *data++;
+                   count--;
+               }
+               else
+               {
+                   row2 = lastrow;
+                   col2 = lastcol;
+               }
+               if (row1 < firstrow) row1 = firstrow;
+               if (row2 > lastrow) row2 = lastrow;
+               if (col1 < firstcol) col1 = firstcol;
+               if (col2 > lastcol) col2 = lastcol;
+           }
+           else
+           {
+               if (row1 < firstrow || row1 > lastrow ||
+                   col1 < firstcol || col1 > lastcol)
+                   continue;
+           }
+           for (row = row1; row <= row2; row++)
+           {
+           expand_glyph_range: ;
+               loc = (row - firstrow) * (lastcol + 1 - firstcol) +
+                     (col1 - firstcol);
+               for (col = col1; col <= col2; col++, loc++)
+               {
+                   if (GLYPH_UNDEFINED(loc))
+                   {
+                       if (row1 == row2 &&
+                           ((col1 & 0xf) && col1 > firstcol ||
+                            (col2 & 0xf) != 0xf) && col2 < lastcol)
+                       {
+                           /* If we're loading from a single row, expand
+                              range of glyphs loaded to a multiple of
+                              a 16-glyph range -- attempt to reduce number
+                              of round trips to the font server. */
+                           col1 &= 0xf0;
+                           col2 = (col2 & 0xf0) + 15;
+                           if (col1 < firstcol) col1 = firstcol;
+                           if (col2 > lastcol) col2 = lastcol;
+                           goto expand_glyph_range;
+                       }
+                       range.min_char_low = range.max_char_low = col;
+                       range.min_char_high = range.max_char_high = row;
+                       if ((err = add_range(&range, nranges, ranges, FALSE)) !=
+                           Successful) return err;
+                       encoding[loc].bits = &_fs_glyph_requested;
+                       access_done = FALSE;
+                   }
+               }
+           }
+       }
+    }
+
+    return access_done ?
+          AccessDone :
+          Successful;
+}
+
+#undef GLYPH_UNDEFINED
+#undef ENCODING_UNDEFINED
+
+
+/* _fs_clean_aborted_loadglyphs(): Undoes the changes to the encoding array
+   performed by fs_build_range(); for use if the associated LoadGlyphs
+   requests needs to be cancelled. */
+
+_fs_clean_aborted_loadglyphs(pfont, num_expected_ranges, expected_ranges)
+    FontPtr pfont;
+    int num_expected_ranges;
+    fsRange *expected_ranges;
+{
+    register FSFontPtr fsfont;
+    register FSFontDataRec *fsd;
+    register int i;
+
+    fsfont = (FSFontPtr) pfont->fontPrivate;
+    fsd = (FSFontDataRec *) pfont->fpePrivate;
+    if (fsfont->encoding)
+    {
+       fsRange full_range[1];
+       if (!num_expected_ranges)
+       {
+           full_range[0].min_char_low = pfont->info.firstCol;
+           full_range[0].min_char_high = pfont->info.firstRow;
+           full_range[0].max_char_low = pfont->info.lastCol;
+           full_range[0].max_char_high = pfont->info.lastRow;
+           num_expected_ranges = 1;
+           expected_ranges = full_range;
+       }
+
+       for (i = 0; i < num_expected_ranges; i++)
+       {
+           int row, col;
+           for (row = expected_ranges[i].min_char_high;
+                row <= expected_ranges[i].max_char_high;
+                row++)
+           {
+               register CharInfoPtr encoding = fsfont->encoding +
+                   ((row - pfont->info.firstRow) *
+                    (pfont->info.lastCol -
+                     pfont->info.firstCol + 1) +
+                    expected_ranges[i].min_char_low -
+                    pfont->info.firstCol);
+               for (col = expected_ranges[i].min_char_low;
+                    col <= expected_ranges[i].max_char_low;
+                    encoding++, col++)
+               {
+                   if (encoding->bits == &_fs_glyph_requested)
+                       encoding->bits = &_fs_glyph_undefined;
+               }
+           }
+       }
+    }
+}
+
+
+/*
+ * figures out what extents to request
+ * this is where lots of extra
+ * smarts wants to live
+ */
+/* ARGSUSED */
+int
+_fs_check_extents(pfont, flags, nranges, range, blockrec)
+    FontPtr     pfont;
+    Mask        flags;
+    int         nranges;
+    fsRange    *range;
+    FSBlockDataPtr blockrec;
+{
+/* XXX -- either fill in the requested info if we have it somewhere
+ * and return AccessDone, or else return Successful
+ */
+    return Successful;
+}
+
+/*
+ * figures out what glyphs to request
+ * this is where lots of extra
+ * smarts wants to live
+ */
+/* ARGSUSED */
+int
+_fs_check_bitmaps(pfont, format, flags, nranges, range, blockrec)
+    FontPtr     pfont;
+    fsBitmapFormat format;
+    Mask        flags;
+    int         nranges;
+    fsRange    *range;
+    FSBlockDataPtr blockrec;
+{
+/* XXX -- either fill in the requested info if we have it somewhere
+ * and return AccessDone, or else return Successful
+ */
+    return Successful;
+}
+
+int
+_fs_get_glyphs(pFont, count, chars, charEncoding, glyphCount, glyphs)
+    FontPtr     pFont;
+    unsigned long count;
+    register unsigned char *chars;
+    FontEncoding charEncoding;
+    unsigned long *glyphCount; /* RETURN */
+    CharInfoPtr *glyphs;       /* RETURN */
+{
+    FSFontPtr   fsdata;
+    unsigned int firstCol;
+    register unsigned int numCols;
+    unsigned int firstRow;
+    unsigned int numRows;
+    CharInfoPtr *glyphsBase;
+    register unsigned int c;
+    register CharInfoPtr pci;
+    unsigned int r;
+    CharInfoPtr encoding;
+    CharInfoPtr pDefault;
+    FSFontDataPtr fsd = (FSFontDataPtr) pFont->fpePrivate;
+    int         itemSize;
+    int         err = Successful;
+
+    fsdata = (FSFontPtr) pFont->fontPrivate;
+    encoding = fsdata->encoding;
+    pDefault = fsdata->pDefault;
+    firstCol = pFont->info.firstCol;
+    numCols = pFont->info.lastCol - firstCol + 1;
+    glyphsBase = glyphs;
+
+
+    if (charEncoding == Linear8Bit || charEncoding == TwoD8Bit)
+       itemSize = 1;
+    else
+       itemSize = 2;
+
+    /* In this age of glyph caching, any glyphs gotten through this
+       procedure should already be loaded.  If they are not, we are
+       dealing with someone (perhaps a ddx driver optimizing a font)
+       that doesn't understand the finer points of glyph caching.  The
+       CHECK_ENCODING macro checks for this condition...  if found, it
+       calls fs_load_all_glyphs(), which corrects it.  Since the caller
+       of this code will not know how to handle a return value of
+       Suspended, the fs_load_all_glyphs() procedure will block and
+       freeze the server until the load operation is done.  Moral: the
+       glyphCachingMode flag really must indicate the capabilities of
+       the ddx drivers.  */
+
+#define CHECK_ENCODING(cnum) \
+    ( pci = encoding + (cnum), \
+      fsd->glyphs_to_get ? \
+      ( pci->bits == &_fs_glyph_undefined || pci->bits == &_fs_glyph_requested ? \
+       ((err = fs_load_all_glyphs(pFont)), pci) : \
+       pci ) : \
+      pci )
+
+    switch (charEncoding) {
+
+    case Linear8Bit:
+    case TwoD8Bit:
+       if (pFont->info.firstRow > 0)
+           break;
+       if (pFont->info.allExist && pDefault) {
+           while (err == Successful && count--) {
+               c = (*chars++) - firstCol;
+               if (c < numCols)
+                   *glyphs++ = CHECK_ENCODING(c);
+               else
+                   *glyphs++ = pDefault;
+           }
+       } else {
+           while (err == Successful && count--) {
+               c = (*chars++) - firstCol;
+               if (c < numCols && CHECK_ENCODING(c)->bits)
+                   *glyphs++ = pci;
+               else if (pDefault)
+                   *glyphs++ = pDefault;
+           }
+       }
+       break;
+    case Linear16Bit:
+       if (pFont->info.allExist && pDefault) {
+           while (err == Successful && count--) {
+               c = *chars++ << 8;
+               c = (c | *chars++) - firstCol;
+               if (c < numCols)
+                   *glyphs++ = CHECK_ENCODING(c);
+               else
+                   *glyphs++ = pDefault;
+           }
+       } else {
+           while (err == Successful && count--) {
+               c = *chars++ << 8;
+               c = (c | *chars++) - firstCol;
+               if (c < numCols && CHECK_ENCODING(c)->bits)
+                   *glyphs++ = pci;
+               else if (pDefault)
+                   *glyphs++ = pDefault;
+           }
+       }
+       break;
+
+    case TwoD16Bit:
+       firstRow = pFont->info.firstRow;
+       numRows = pFont->info.lastRow - firstRow + 1;
+       while (err == Successful && count--) {
+           r = (*chars++) - firstRow;
+           c = (*chars++) - firstCol;
+           if (r < numRows && c < numCols &&
+                   CHECK_ENCODING(r * numCols + c)->bits)
+               *glyphs++ = pci;
+           else if (pDefault)
+               *glyphs++ = pDefault;
+       }
+       break;
+    }
+    *glyphCount = glyphs - glyphsBase;
+    return err;
+}
+
+
+static int
+_fs_get_metrics(pFont, count, chars, charEncoding, glyphCount, glyphs)
+    FontPtr     pFont;
+    unsigned long count;
+    register unsigned char *chars;
+    FontEncoding charEncoding;
+    unsigned long *glyphCount; /* RETURN */
+    xCharInfo **glyphs;                /* RETURN */
+{
+    FSFontPtr   fsdata;
+    unsigned int firstCol;
+    register unsigned int numCols;
+    unsigned int firstRow;
+    unsigned int numRows;
+    xCharInfo **glyphsBase;
+    register unsigned int c;
+    unsigned int r;
+    CharInfoPtr encoding;
+    CharInfoPtr pDefault;
+    FSFontDataPtr fsd = (FSFontDataPtr) pFont->fpePrivate;
+    int         itemSize;
+    int         err = Successful;
+
+    fsdata = (FSFontPtr) pFont->fontPrivate;
+    encoding = fsdata->inkMetrics;
+    pDefault = fsdata->pDefault;
+    firstCol = pFont->info.firstCol;
+    numCols = pFont->info.lastCol - firstCol + 1;
+    glyphsBase = glyphs;
+
+
+    /* XXX - this should be much smarter */
+    /* make sure the glyphs are there */
+    if (charEncoding == Linear8Bit || charEncoding == TwoD8Bit)
+       itemSize = 1;
+    else
+       itemSize = 2;
+
+    switch (charEncoding) {
+
+    case Linear8Bit:
+    case TwoD8Bit:
+       if (pFont->info.firstRow > 0)
+           break;
+       if (pFont->info.allExist && pDefault) {
+           while (count--) {
+               c = (*chars++) - firstCol;
+               if (c < numCols)
+                   *glyphs++ = (xCharInfo *)&encoding[c];
+               else
+                   *glyphs++ = (xCharInfo *)pDefault;
+           }
+       } else {
+           while (count--) {
+               c = (*chars++) - firstCol;
+               if (c < numCols)
+                   *glyphs++ = (xCharInfo *)(encoding + c);
+               else if (pDefault)
+                   *glyphs++ = (xCharInfo *)pDefault;
+           }
+       }
+       break;
+    case Linear16Bit:
+       if (pFont->info.allExist && pDefault) {
+           while (count--) {
+               c = *chars++ << 8;
+               c = (c | *chars++) - firstCol;
+               if (c < numCols)
+                   *glyphs++ = (xCharInfo *)(encoding + c);
+               else
+                   *glyphs++ = (xCharInfo *)pDefault;
+           }
+       } else {
+           while (count--) {
+               c = *chars++ << 8;
+               c = (c | *chars++) - firstCol;
+               if (c < numCols)
+                   *glyphs++ = (xCharInfo *)(encoding + c);
+               else if (pDefault)
+                   *glyphs++ = (xCharInfo *)pDefault;
+           }
+       }
+       break;
+
+    case TwoD16Bit:
+       firstRow = pFont->info.firstRow;
+       numRows = pFont->info.lastRow - firstRow + 1;
+       while (count--) {
+           r = (*chars++) - firstRow;
+           c = (*chars++) - firstCol;
+           if (r < numRows && c < numCols)
+               *glyphs++ = (xCharInfo *)(encoding + (r * numCols + c));
+           else if (pDefault)
+               *glyphs++ = (xCharInfo *)pDefault;
+       }
+       break;
+    }
+    *glyphCount = glyphs - glyphsBase;
+    return Successful;
+}
+
+
+void
+_fs_unload_font(pfont)
+    FontPtr     pfont;
+{
+    FSFontPtr   fsdata = (FSFontPtr) pfont->fontPrivate;
+
+    if (fsdata->encoding)
+    {
+       register int i;
+       register CharInfoPtr encoding = fsdata->encoding;
+       FontInfoPtr pfi = &pfont->info;
+       for (i = (pfi->lastCol - pfi->firstCol + 1) *
+                (pfi->lastRow - pfi->firstRow + 1);
+            i > 0;
+            encoding++, i--)
+       {
+           if (encoding->bits &&
+               encoding->bits != &_fs_glyph_undefined &&
+               encoding->bits != &_fs_glyph_requested &&
+               encoding->bits != &_fs_glyph_zero_length)
+               xfree(encoding->bits);
+       }
+    }
+    xfree(fsdata->encoding);
+    xfree(fsdata);
+
+    pfont->fontPrivate = 0;
+}
+
+void
+_fs_init_font(pfont)
+    FontPtr     pfont;
+{
+    /* set font function pointers */
+    pfont->get_glyphs = _fs_get_glyphs;
+    pfont->get_metrics = _fs_get_metrics;
+    pfont->unload_font = _fs_unload_font;
+    pfont->unload_glyphs = (void (*)())0;
+}
diff --git a/Xserver/lib/font/fc/fserve.c b/Xserver/lib/font/fc/fserve.c
new file mode 100644 (file)
index 0000000..ef9955c
--- /dev/null
@@ -0,0 +1,2824 @@
+/* $TOG: fserve.c /main/49 1997/06/10 11:23:56 barstow $ */
+/*
+
+Copyright (c) 1990  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+*/
+/* $XFree86: xc/lib/font/fc/fserve.c,v 3.4.2.2 1997/06/11 12:08:41 dawes Exp $ */
+
+/*
+ * Copyright 1990 Network Computing Devices
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and
+ * its documentation for any purpose is hereby granted without fee, provided
+ * that the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the names of Network Computing Devices, or Digital
+ * not be used in advertising or publicity pertaining to distribution
+ * of the software without specific, written prior permission.
+ *
+ * NETWORK COMPUTING DEVICES, AND DIGITAL AND DISCLAIM ALL WARRANTIES WITH
+ * REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL NETWORK COMPUTING DEVICES,
+ * OR DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
+ * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
+ * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
+ * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
+ * THIS SOFTWARE.
+ *
+ * Author:     Dave Lemke, Network Computing Devices, Inc
+ */
+/*
+ * font server specific font access
+ */
+
+#ifdef WIN32
+#define _WILLWINSOCK_
+#endif
+#include       <X11/X.h>
+#include       <X11/Xos.h>
+#include       "X11/Xpoll.h"
+#include       "FS.h"
+#include       "FSproto.h"
+#include       "fontmisc.h"
+#include       "fontstruct.h"
+#include       "fservestr.h"
+#include       <errno.h>
+#if defined(X_NOT_STDC_ENV) && !defined(__EMX__)
+extern int errno;
+#define Time_t long
+extern Time_t time ();
+#else
+#include       <time.h>
+#define Time_t time_t
+#endif
+
+#ifdef NCD
+#include       <ncd/nvram.h>
+#endif
+
+#ifndef NULL
+#define NULL 0
+#endif
+
+#ifndef MIN
+#define MIN(a,b)    ((a)<(b)?(a):(b))
+#endif
+
+#define NONZEROMETRICS(pci) ((pci)->leftSideBearing || \
+                            (pci)->rightSideBearing || \
+                            (pci)->ascent || \
+                            (pci)->descent || \
+                            (pci)->characterWidth)
+
+
+extern FontPtr find_old_font();
+
+extern int  _fs_build_range();
+
+static int  fs_read_glyphs();
+static int  fs_read_list();
+static int  fs_read_list_info();
+
+static int  fs_font_type;
+extern fd_set _fs_fd_mask;
+
+static void fs_block_handler();
+static int  fs_wakeup();
+
+static FSFpePtr awaiting_reconnect;
+
+void        _fs_connection_died();
+static int  _fs_restart_connection();
+static void _fs_try_reconnect();
+static int  fs_send_query_info();
+static int  fs_send_query_extents();
+static int  fs_send_query_bitmaps();
+static int  fs_send_close_font();
+static void fs_client_died();
+static void _fs_client_access();
+static void _fs_client_resolution();
+
+char _fs_glyph_undefined;
+char _fs_glyph_requested;
+char _fs_glyph_zero_length;
+
+/*
+ * Font server access
+ *
+ * the basic idea for the non-blocking access is to have the function
+ * called multiple times until the actual data is returned, instead
+ * of ClientBlocked.
+ *
+ * the first call to the function will cause the request to be sent to
+ * the font server, and a block record to be stored in the fpe's list
+ * of outstanding requests.  the FS block handler also sticks the
+ * proper set of fd's into the select mask.  when data is ready to be
+ * read in, the FS wakup handler will be hit.  this will read the
+ * data off the wire into the proper block record, and then signal the
+ * client that caused the block so that it can restart.  it will then
+ * call the access function again, which will realize that the data has
+ * arrived and return it.
+ */
+
+
+/* XXX this should probably be a macro once its fully debugged */
+/* ARGSUSED */
+static void
+_fs_add_req_log(conn, opcode)
+    FSFpePtr    conn;
+    int         opcode;
+{
+
+#ifdef DEBUG
+    conn->reqbuffer[conn->reqindex++] = opcode;
+    if (conn->reqindex == REQUEST_LOG_SIZE)
+       conn->reqindex = 0;
+#endif
+
+    conn->current_seq++;
+}
+
+static Bool
+fs_name_check(name)
+    char       *name;
+{
+#ifdef __EMX__
+    /* OS/2 uses D:/XFree86/.... as fontfile pathnames, so check that
+     * there is not only a protocol/ prefix, but also that the first chars
+     * are not a drive letter
+     */
+    if (name && isalpha(*name) && name[1] == ':')
+      return FALSE;
+#endif
+    /* Just make sure there is a protocol/ prefix */
+    return (name && *name != '/' && strchr(name, '/'));
+}
+
+static void
+_fs_client_resolution(conn)
+    FSFpePtr    conn;
+{
+    fsSetResolutionReq srreq;
+    int         num_res;
+    FontResolutionPtr res;
+
+    res = GetClientResolutions(&num_res);
+
+    if (num_res) {
+       srreq.reqType = FS_SetResolution;
+       srreq.num_resolutions = num_res;
+       srreq.length = (SIZEOF(fsSetResolutionReq) +
+                       (num_res * SIZEOF(fsResolution)) + 3) >> 2;
+
+       _fs_add_req_log(conn, FS_SetResolution);
+       if (_fs_write(conn, (char *) &srreq, SIZEOF(fsSetResolutionReq)) != -1)
+           (void)_fs_write_pad(conn, (char *) res,
+                               (num_res * SIZEOF(fsResolution)));
+    }
+}
+
+/*
+ * sends the stuff that's meaningful to a newly opened or reset FS
+ */
+static int
+fs_send_init_packets(conn)
+    FSFpePtr    conn;
+{
+    fsSetResolutionReq srreq;
+    fsSetCataloguesReq screq;
+    fsListCataloguesReq lcreq;
+    fsListCataloguesReply lcreply;
+    int         num_cats,
+                clen,
+                len;
+    char       *client_cat = (char *) 0,
+               *cp,
+               *sp,
+               *end;
+    int         num_res;
+    FontResolutionPtr res;
+    int         err = Successful;
+
+#define        CATALOGUE_SEP   '+'
+
+    res = GetClientResolutions(&num_res);
+    if (num_res) {
+       srreq.reqType = FS_SetResolution;
+       srreq.num_resolutions = num_res;
+       srreq.length = (SIZEOF(fsSetResolutionReq) +
+                       (num_res * SIZEOF(fsResolution)) + 3) >> 2;
+
+       _fs_add_req_log(conn, FS_SetResolution);
+       if (_fs_write(conn, (char *) &srreq, SIZEOF(fsSetResolutionReq)) == -1)
+       {
+           err = BadFontPath;
+           goto fail;
+       }
+       if (_fs_write_pad(conn, (char *) res, (num_res * SIZEOF(fsResolution))) == -1)
+       {
+           err = BadFontPath;
+           goto fail;
+       }
+    }
+    sp = strrchr(conn->servername, '/');
+
+    /* don't get tricked by a non-existant catalogue list */
+    if (sp == strchr(conn->servername, '/')) {
+       /*
+        * try original name -- this might be an alternate with no catalogues
+        */
+       sp = strrchr(conn->requestedname, '/');
+       if (sp == strchr(conn->requestedname, '/'))
+               sp = (char *) 0;
+    }
+    if (sp) {                  /* turn cats into counted list */
+       sp++;
+       /* allocate more than enough room */
+       cp = client_cat = (char *) xalloc(strlen(conn->servername));
+       if (!cp) {
+           err = BadAlloc;
+           goto fail;
+       }
+       num_cats = 0;
+       while (*sp) {
+           end = strchr(sp, CATALOGUE_SEP);
+           if (!end)
+               end = sp + strlen(sp);
+           *cp++ = len = end - sp;
+           num_cats++;
+           memmove(cp, sp, len);
+           sp += len;
+           if (*sp == CATALOGUE_SEP)
+               sp++;
+           cp += len;
+       }
+       clen = cp - client_cat;
+       /* our list checked out, so send it */
+       screq.reqType = FS_SetCatalogues;
+       screq.num_catalogues = num_cats;
+       screq.length = (SIZEOF(fsSetCataloguesReq) + clen + 3) >> 2;
+
+       _fs_add_req_log(conn, FS_SetCatalogues);
+       if (_fs_write(conn, (char *) &screq, SIZEOF(fsSetCataloguesReq)) == -1)
+       {
+           err = BadFontPath;
+           goto fail;
+       }
+       if (_fs_write_pad(conn, (char *) client_cat, clen) == -1)
+       {
+           err = BadFontPath;
+           goto fail;
+       }
+
+       /*
+        * now sync up with the font server, to see if an error was generated
+        * by a bogus catalogue
+        */
+       lcreq.reqType = FS_ListCatalogues;
+       lcreq.length = (SIZEOF(fsListCataloguesReq)) >> 2;
+       lcreq.maxNames = 0;
+       lcreq.nbytes = 0;
+       _fs_add_req_log(conn, FS_SetCatalogues);
+       if (_fs_write(conn, (char *) &lcreq, SIZEOF(fsListCataloguesReq)) == -1)
+       {
+           err = BadFontPath;
+           goto fail;
+       }
+
+       /*
+        * next bit will either by the ListCats reply, or an error followed by
+        * the reply
+        */
+       if (_fs_read(conn, (char *) &lcreply, SIZEOF(fsGenericReply)) == -1) {
+           err = BadFontPath;
+           goto fail;
+       }
+       if (lcreply.type == FS_Error &&
+               ((fsError *) & lcreply)->major_opcode == FS_SetCatalogues) {
+           _fs_eat_rest_of_error(conn, (fsError *) & lcreply);
+           /* get ListCats response */
+           (void) _fs_read(conn, (char *) &lcreply,
+                           SIZEOF(fsListCataloguesReply));
+           err = BadFontPath;
+           goto fail;
+       }
+       /* must be reply, swallow the rest of it */
+       _fs_eat_rest_of_error(conn, (fsError *) & lcreply);
+    }
+fail:
+    xfree(client_cat);
+    return err;
+}
+
+/* 
+ * close font server and remove any state associated with
+ * this connection - this includes any client records.
+ */
+
+static void
+fs_close_conn(conn)
+    FSFpePtr   conn;
+{
+    FSClientPtr        client, nclient;
+
+    /* XXX - hack.  The right fix is to remember that the font server
+       has gone away when we first discovered it. */
+    if (conn->trans_conn)
+        (void) _FontTransClose (conn->trans_conn);
+
+    if (conn->fs_fd != -1)
+      FD_CLR(conn->fs_fd, &_fs_fd_mask);
+
+    for (client = conn->clients; client; client = nclient) 
+    {
+       nclient = client->next;
+       xfree (client);
+    }
+    conn->clients = NULL;
+}
+
+/*
+ * the wakeup handlers have to be set when the FPE is open, and not
+ * removed until it is freed, in order to handle unexpected data, like
+ * events
+ */
+/* ARGSUSED */
+static int
+fs_init_fpe(fpe)
+    FontPathElementPtr fpe;
+{
+    FSFpePtr    conn;
+    char       *name;
+    int         err;
+
+    /* open font server */
+    /* create FS specific fpe info */
+    errno = 0;
+
+    name = fpe->name;
+
+    /* hack for old style names */
+    if (*name == ':')
+       name++;                 /* skip ':' */
+
+    conn = _fs_open_server(name);
+    if (conn) {
+       conn->requestedname = fpe->name; /* stash this for later init use */
+       fpe->private = (pointer) conn;
+       err = fs_send_init_packets(conn);
+       if (err != Successful) {
+           fs_close_conn(conn);
+           xfree(conn->servername);
+           xfree(conn->alts);
+           xfree(conn);
+           return err;
+       }
+       if (init_fs_handlers(fpe, fs_block_handler) != Successful)
+           return AllocError;
+       FD_SET(conn->fs_fd, &_fs_fd_mask);
+       conn->attemptReconnect = TRUE;
+
+#ifdef NCD
+       if (configData.ExtendedFontDiags)
+           printf("Connected to font server \"%s\"\n", name);
+#endif
+
+       return err;
+    }
+
+#ifdef DEBUG
+    fprintf(stderr, "failed to connect to FS \"%s\"\n", name);
+#endif
+
+#ifdef NCD
+    if (configData.ExtendedFontDiags)
+       printf("Failed to connect to font server \"%s\"\n", name);
+#endif
+
+    return (errno == ENOMEM) ? AllocError : BadFontPath;
+}
+
+static int
+fs_reset_fpe(fpe)
+    FontPathElementPtr fpe;
+{
+    (void) fs_send_init_packets((FSFpePtr) fpe->private);
+    return Successful;
+}
+
+/*
+ * this shouldn't be called till all refs to the FPE are gone
+ */
+
+static int
+fs_free_fpe(fpe)
+    FontPathElementPtr fpe;
+{
+    FSFpePtr    conn = (FSFpePtr) fpe->private;
+    FSFpePtr    recon,
+               *prev;
+    prev = &awaiting_reconnect;
+    while (*prev) {
+       recon = *prev;
+       if (conn == recon) {
+           *prev = recon->next_reconnect;
+           break;
+       }
+       prev = &recon->next_reconnect;
+    }
+
+    fs_close_conn(conn);
+
+    remove_fs_handlers(fpe, fs_block_handler,
+                      !XFD_ANYSET(&_fs_fd_mask) && !awaiting_reconnect);
+
+    xfree(conn->alts);
+    xfree(conn->servername);
+    xfree(conn);
+    fpe->private = (pointer) 0;
+
+#ifdef NCD
+    if (configData.ExtendedFontDiags)
+       printf("Disconnected from font server \"%s\"\n", fpe->name);
+#endif
+
+    return Successful;
+}
+
+static      FSBlockDataPtr
+fs_new_block_rec(fpe, client, type)
+    FontPathElementPtr fpe;
+    pointer     client;
+    int         type;
+{
+    FSBlockDataPtr blockrec,
+                br;
+    FSFpePtr    fsfpe = (FSFpePtr) fpe->private;
+    int         size;
+
+    blockrec = (FSBlockDataPtr) xalloc(sizeof(FSBlockDataRec));
+    if (!blockrec)
+       return (FSBlockDataPtr) 0;
+    switch (type) {
+    case FS_OPEN_FONT:
+       size = sizeof(FSBlockedFontRec);
+       break;
+    case FS_LOAD_GLYPHS:
+       size = sizeof(FSBlockedGlyphRec);
+       break;
+    case FS_LIST_FONTS:
+       size = sizeof(FSBlockedListRec);
+       break;
+    case FS_LIST_WITH_INFO:
+       size = sizeof(FSBlockedListInfoRec);
+       break;
+    default:
+       break;
+    }
+    blockrec->data = (pointer) xalloc(size);
+    if (!blockrec->data) {
+       xfree(blockrec);
+       return (FSBlockDataPtr) 0;
+    }
+    blockrec->client = client;
+    blockrec->sequence_number = fsfpe->current_seq;
+    blockrec->type = type;
+    blockrec->depending = 0;
+    blockrec->next = (FSBlockDataPtr) 0;
+
+    /* stick it on the end of the list (since its expected last) */
+    br = (FSBlockDataPtr) fsfpe->blocked_requests;
+    if (!br) {
+       fsfpe->blocked_requests = (pointer) blockrec;
+    } else {
+       while (br->next)
+           br = br->next;
+       br->next = blockrec;
+    }
+
+    return blockrec;
+}
+
+static void
+_fs_remove_block_rec(conn, blockrec)
+    FSFpePtr    conn;
+    FSBlockDataPtr blockrec;
+{
+    FSBlockDataPtr br,
+                last;
+
+    last = (FSBlockDataPtr) 0;
+    br = (FSBlockDataPtr) conn->blocked_requests;
+    while (br) {
+       if (br == blockrec) {
+           if (last)
+               last->next = br->next;
+           else
+               conn->blocked_requests = (pointer) br->next;
+           if (br->type == FS_LOAD_GLYPHS)
+           {
+               FSBlockedGlyphPtr bglyph = (FSBlockedGlyphPtr)br->data;
+               if (bglyph->num_expected_ranges)
+                   xfree(bglyph->expected_ranges);
+           }
+           xfree(br->data);
+           xfree(br);
+           return;
+       }
+       last = br;
+       br = br->next;
+    }
+}
+
+static void
+signal_clients_depending(clients_depending)
+FSClientsDependingPtr *clients_depending;
+{
+    FSClientsDependingPtr p = *clients_depending, p2;
+    *clients_depending = (FSClientsDependingPtr)0;
+
+    while (p != (FSClientsDependingPtr)0)
+    {
+       p2 = p;
+       ClientSignal(p->client);
+       p = p->next;
+       xfree(p2);
+    }
+}
+
+static int
+add_clients_depending(clients_depending, client)
+FSClientsDependingPtr *clients_depending;
+pointer client;
+{
+    while (*clients_depending != (FSClientsDependingPtr)0)
+    {
+       if ((*clients_depending)->client == client) return Suspended;
+       clients_depending = &(*clients_depending)->next;
+    }
+    *clients_depending = (FSClientsDependingPtr)xalloc(
+                            sizeof(FSClientsDependingRec));
+    if (!*clients_depending)
+       return BadAlloc;
+
+    (*clients_depending)->client = client;
+    (*clients_depending)->next = 0;
+    return Suspended;
+}
+
+static void
+clean_aborted_blockrec(blockrec)
+    FSBlockDataPtr blockrec;
+{
+
+    switch(blockrec->type)
+    {
+       case FS_LOAD_GLYPHS:
+       {
+           FSBlockedGlyphPtr bglyph = (FSBlockedGlyphPtr)blockrec->data;
+           FontPtr pfont = bglyph->pfont;
+           int num_expected_ranges = bglyph->num_expected_ranges;
+           fsRange *expected_ranges = bglyph->expected_ranges;
+           _fs_clean_aborted_loadglyphs(pfont,
+                                    num_expected_ranges,
+                                    expected_ranges);
+           signal_clients_depending(&bglyph->clients_depending);
+           break;
+       }
+       case FS_OPEN_FONT:
+       {
+           FSBlockedFontPtr bfont = (FSBlockedFontPtr)blockrec->data;
+           signal_clients_depending(&bfont->clients_depending);
+           break;
+       }
+       default:
+           break;
+    }
+}
+
+static void
+fs_abort_blockrec(conn, blockrec)
+    FSFpePtr    conn;
+    FSBlockDataPtr blockrec;
+{
+    clean_aborted_blockrec(blockrec);
+    _fs_remove_block_rec(conn, blockrec);
+}
+
+
+static void
+fs_free_font(bfont)
+    FSBlockedFontPtr bfont;
+{
+    FontPtr     pfont;
+    FSFontDataRec *fsd;
+
+    pfont = bfont->pfont;
+    fsd = (FSFontDataRec *) pfont->fpePrivate;
+
+    /* xfree better be able to handle NULL */
+    (*pfont->unload_font)(pfont);
+    DeleteFontClientID(fsd->fontid);
+    xfree(fsd->name);
+    xfree(pfont->info.isStringProp);
+    xfree(pfont->info.props);
+
+    xfree(pfont);
+    xfree(fsd);
+
+    bfont->pfont = (FontPtr) 0;
+}
+
+static void
+_fs_cleanup_font(bfont)
+    FSBlockedFontPtr bfont;
+{
+    FSFontDataRec *fsd;
+
+    if (bfont->pfont)
+    {
+       fsd = (FSFontDataRec *) bfont->pfont->fpePrivate;
+    
+       /* make sure the FS knows we choked on it */
+       fs_send_close_font(fsd->fpe, bfont->fontid);
+    
+       fs_free_font(bfont);
+    }
+    bfont->errcode = AllocError;
+}
+
+
+static int
+fs_read_open_font(fpe, blockrec)
+    FontPathElementPtr fpe;
+    FSBlockDataPtr blockrec;
+{
+    FSBlockedFontPtr bfont = (FSBlockedFontPtr) blockrec->data;
+    FSFpePtr    conn = (FSFpePtr) fpe->private;
+    fsOpenBitmapFontReply rep;
+    FSBlockDataPtr blockOrig;
+    FSBlockedFontPtr origBfont;
+
+    /* pull out the OpenFont reply */
+    memcpy(&rep, &blockrec->header, SIZEOF(fsGenericReply));
+
+    if (rep.type == FS_Error) {
+       _fs_eat_rest_of_error(conn, (fsError *) & rep);
+       return BadFontName;
+    } else {                   /* get rest of reply */
+       if (_fs_read(conn, (char *) &rep + SIZEOF(fsGenericReply),
+             SIZEOF(fsOpenBitmapFontReply) - SIZEOF(fsGenericReply)) == -1) {
+           /* If we're not reopening a font, we'll allocate the
+              structures again after connection is reestablished.  */
+           if (!(bfont->flags & FontReopen)) fs_free_font(bfont);
+           return StillWorking;
+       }
+    }
+
+    /* If we're not reopening a font and FS detected a duplicate font
+       open request, replace our reference to the new font with a
+       reference to an existing font (possibly one not finished
+       opening).  If this is a reopen, keep the new font reference...
+       it's got the metrics and extents we read when the font was opened
+       before.  This also gives us the freedom to easily close the font
+       if we we decide (in fs_read_query_info()) that we don't like what
+       we got. */
+
+    if (rep.otherid && !(bfont->flags & FontReopen)) {
+       (void) fs_send_close_font(fpe, bfont->fontid);
+
+       /* Find old font if we're completely done getting it from server. */
+       fs_free_font(bfont);
+       bfont->pfont = find_old_font(rep.otherid);
+       bfont->fontid = rep.otherid;
+       bfont->state = FS_DONE_REPLY;
+       /*
+        * look for a blocked request to open the same font
+        */
+       for (blockOrig = (FSBlockDataPtr) conn->blocked_requests;
+               blockOrig;
+               blockOrig = blockOrig->next) {
+           if (blockOrig != blockrec && blockOrig->type == FS_OPEN_FONT) {
+               origBfont = (FSBlockedFontPtr) blockOrig->data;
+               if (origBfont->fontid == rep.otherid) {
+                   blockrec->depending = blockOrig->depending;
+                   blockOrig->depending = blockrec;
+                   bfont->state = FS_DEPENDING;
+                   bfont->pfont = origBfont->pfont;
+                   break;
+               }
+           }
+       }
+       if (bfont->pfont == NULL)
+       {
+           /* XXX - something nasty happened */
+           return BadFontName;
+       }
+       return AccessDone;
+    }
+
+    bfont->pfont->info.cachable = rep.cachable != 0;
+    bfont->state = FS_INFO_REPLY;
+    /* ask for the next stage */
+    (void) fs_send_query_info(fpe, blockrec);
+    return StillWorking;
+}
+
+
+static int
+fs_read_query_info(fpe, blockrec)
+    FontPathElementPtr fpe;
+    FSBlockDataPtr blockrec;
+{
+    FSBlockedFontPtr bfont = (FSBlockedFontPtr) blockrec->data;
+    FSFpePtr    conn = (FSFpePtr) fpe->private;
+    fsQueryXInfoReply rep;
+    fsPropInfo  pi;
+    fsPropOffset *po;
+    pointer     pd;
+    unsigned long prop_len;
+    FSBlockedFontRec newbfont, *oldbfont;
+    FontRec newpfont, *oldpfont;
+    int err;
+
+    /* If this is a reopen, accumulate the query info into a dummy
+       font and compare to our original data. */
+    if (bfont->flags & FontReopen)
+    {
+       newbfont = *(oldbfont = bfont);
+       bfont = &newbfont;
+       newpfont = *(oldpfont = oldbfont->pfont);
+       newpfont.info.isStringProp = NULL;
+       newpfont.info.props = NULL;
+       newbfont.pfont = &newpfont;
+       err = StillWorking;
+    }
+
+    /* pull out the QueryXInfo reply */
+    memcpy(&rep, &blockrec->header, SIZEOF(fsGenericReply));
+    if (_fs_read(conn, (char *) &rep + SIZEOF(fsGenericReply),
+                SIZEOF(fsQueryXInfoReply) - SIZEOF(fsGenericReply)) == -1) {
+       if (bfont->flags & FontReopen) goto bail;
+       fs_free_font(bfont);
+       return StillWorking;
+    }
+    /* move the data over */
+    fsUnpack_XFontInfoHeader(&rep, &bfont->pfont->info);
+    _fs_init_fontinfo(conn, &bfont->pfont->info);
+
+    if (bfont->pfont->info.terminalFont)
+    {
+       bfont->format =
+           (bfont->format & ~ (BitmapFormatImageRectMask)) |
+           BitmapFormatImageRectMax;
+    }
+
+    if (_fs_read(conn, (char *) &pi, SIZEOF(fsPropInfo)) == -1) {
+       if (bfont->flags & FontReopen) goto bail;
+       fs_free_font(bfont);
+       return StillWorking;
+    }
+    prop_len = pi.num_offsets * SIZEOF(fsPropOffset);
+    po = (fsPropOffset *) xalloc(prop_len);
+    pd = (pointer) xalloc(pi.data_len);
+    if (!po || !pd) {
+       xfree(pd);
+       xfree(po);
+       /* clear the wire */
+       (void) _fs_drain_bytes(conn, prop_len + pi.data_len);
+       /* clean up the font */
+       if (bfont->flags & FontReopen) { err = AllocError ; goto bail; }
+       (void) _fs_cleanup_font(bfont);
+       return AllocError;
+    }
+    if (_fs_read_pad(conn, (char *) po, prop_len) == -1 ||
+           _fs_read_pad(conn, (char *) pd, pi.data_len) == -1) {
+       xfree(pd);
+       xfree(po);
+       if (bfont->flags & FontReopen) goto bail;
+       fs_free_font(bfont);
+       return StillWorking;
+    }
+    if (_fs_convert_props(&pi, po, pd, &bfont->pfont->info) == -1)
+    {
+       xfree(po);
+       xfree(pd);
+       if (bfont->flags & FontReopen) { err = AllocError ; goto bail; }
+       (void) _fs_cleanup_font(bfont);
+       return AllocError;
+    }
+    xfree(po);
+    xfree(pd);
+
+    if (bfont->flags & FontReopen)
+    {
+       int i;
+
+       err = BadFontName;
+
+       /* We're reopening a font that we lost because of a downed
+          connection.  In the interest of avoiding corruption from
+          opening a different font than the old one (we already have
+          its metrics, extents, and probably some of its glyphs),
+          verify that the metrics and properties all match.  */
+
+       if (newpfont.info.firstCol != oldpfont->info.firstCol ||
+           newpfont.info.lastCol != oldpfont->info.lastCol ||
+           newpfont.info.firstRow != oldpfont->info.firstRow ||
+           newpfont.info.lastRow != oldpfont->info.lastRow ||
+           newpfont.info.defaultCh != oldpfont->info.defaultCh ||
+           newpfont.info.noOverlap != oldpfont->info.noOverlap ||
+           newpfont.info.terminalFont != oldpfont->info.terminalFont ||
+           newpfont.info.constantMetrics != oldpfont->info.constantMetrics ||
+           newpfont.info.constantWidth != oldpfont->info.constantWidth ||
+           newpfont.info.inkInside != oldpfont->info.inkInside ||
+           newpfont.info.inkMetrics != oldpfont->info.inkMetrics ||
+           newpfont.info.allExist != oldpfont->info.allExist ||
+           newpfont.info.drawDirection != oldpfont->info.drawDirection ||
+           newpfont.info.cachable != oldpfont->info.cachable ||
+           newpfont.info.anamorphic != oldpfont->info.anamorphic ||
+           newpfont.info.maxOverlap != oldpfont->info.maxOverlap ||
+           newpfont.info.fontAscent != oldpfont->info.fontAscent ||
+           newpfont.info.fontDescent != oldpfont->info.fontDescent ||
+           newpfont.info.nprops != oldpfont->info.nprops)
+           goto bail;
+
+#define MATCH(xci1, xci2) \
+       (((xci1).leftSideBearing == (xci2).leftSideBearing) && \
+        ((xci1).rightSideBearing == (xci2).rightSideBearing) && \
+        ((xci1).characterWidth == (xci2).characterWidth) && \
+        ((xci1).ascent == (xci2).ascent) && \
+        ((xci1).descent == (xci2).descent) && \
+        ((xci1).attributes == (xci2).attributes))
+
+       if (!MATCH(newpfont.info.maxbounds, oldpfont->info.maxbounds) ||
+           !MATCH(newpfont.info.minbounds, oldpfont->info.minbounds) ||
+           !MATCH(newpfont.info.ink_maxbounds, oldpfont->info.ink_maxbounds) ||
+           !MATCH(newpfont.info.ink_minbounds, oldpfont->info.ink_minbounds))
+           goto bail;
+
+#undef MATCH
+
+       for (i = 0; i < newpfont.info.nprops; i++)
+           if (newpfont.info.isStringProp[i] !=
+                   oldpfont->info.isStringProp[i] ||
+               newpfont.info.props[i].name !=
+                   oldpfont->info.props[i].name ||
+               newpfont.info.props[i].value !=
+                   oldpfont->info.props[i].value)
+               goto bail;
+
+       err = Successful;
+    bail:
+       if (err != Successful && err != StillWorking)
+       {
+           /* Failure.  Close the font. */
+           fs_send_close_font(((FSFontDataPtr)oldpfont->fpePrivate)->fpe,
+                              bfont->fontid);
+           ((FSFontDataPtr)oldpfont->fpePrivate)->generation  = -1;
+       }
+       xfree(newpfont.info.isStringProp);
+       xfree(newpfont.info.props);
+
+       if (err == Successful) oldbfont->state = FS_DONE_REPLY;
+       return err;
+    }
+
+    if (glyphCachingMode == CACHING_OFF ||
+       glyphCachingMode == CACHE_16_BIT_GLYPHS && !bfont->pfont->info.lastRow)
+       bfont->flags |= FontLoadAll;
+
+    bfont->state = FS_EXTENT_REPLY;
+
+    fs_send_query_extents(fpe, blockrec);
+    return StillWorking;
+}
+
+static int
+fs_read_extent_info(fpe, blockrec)
+    FontPathElementPtr fpe;
+    FSBlockDataPtr blockrec;
+{
+    FSBlockedFontPtr bfont = (FSBlockedFontPtr) blockrec->data;
+    FSFontDataPtr fsd = (FSFontDataPtr) bfont->pfont->fpePrivate;
+    FSFpePtr    conn = (FSFpePtr) fpe->private;
+    fsQueryXExtents16Reply rep;
+    int         i;
+    int                numInfos;
+    Bool       haveInk = FALSE; /* need separate ink metrics? */
+    CharInfoPtr ci,
+                pCI;
+    FSFontPtr   fsfont = (FSFontPtr) bfont->pfont->fontPrivate;
+    fsXCharInfo *fsci;
+    fsXCharInfo fscilocal;
+    pointer fscip;
+
+    /* read the QueryXExtents reply */
+    memcpy(&rep, &blockrec->header, SIZEOF(fsGenericReply));
+    if (_fs_read(conn, (char *) &rep + SIZEOF(fsGenericReply),
+             SIZEOF(fsQueryXExtents16Reply) - SIZEOF(fsGenericReply)) == -1) {
+       fs_free_font(bfont);
+       return StillWorking;
+    }
+    /* move the data over */
+    /* need separate inkMetrics for fixed font server protocol version */
+    numInfos =  rep.num_extents;
+    if (bfont->pfont->info.terminalFont && conn->fsMajorVersion > 1)
+    {
+       numInfos *= 2;
+       haveInk = TRUE;
+    }
+    ci = pCI = (CharInfoPtr) xalloc(sizeof(CharInfoRec) * numInfos);
+/* XXX this could be done with an ALLOCATE_LOCAL */
+    fsci = (fsXCharInfo *) xalloc(SIZEOF(fsXCharInfo) * rep.num_extents);
+    if (!pCI || !fsci) {
+       xfree(pCI);
+       xfree(fsci);
+       /* clear the unusable data */
+       _fs_drain_bytes(conn, SIZEOF(fsXCharInfo) * rep.num_extents);
+       _fs_cleanup_font(bfont);
+       return AllocError;
+    }
+    fsfont->encoding = pCI;
+    if (haveInk)
+       fsfont->inkMetrics = pCI + rep.num_extents;
+    else
+        fsfont->inkMetrics = pCI;
+
+    if (_fs_read_pad(conn, (char *) fsci,
+                    SIZEOF(fsXCharInfo) * rep.num_extents) == -1) {
+       fs_free_font(bfont);
+       xfree(fsci);
+       return StillWorking;
+    }
+    fsd->glyphs_to_get = 0;
+    fscip = (pointer) fsci;
+    ci = fsfont->inkMetrics;
+    for (i = 0; i < rep.num_extents; i++) {
+       memcpy(&fscilocal, fscip, SIZEOF(fsXCharInfo)); /* align it */
+       _fs_convert_char_info(&fscilocal, &ci->metrics);
+       fscip += SIZEOF(fsXCharInfo);
+       /* Initialize the bits field for later glyph-caching use */
+       if (NONZEROMETRICS(&ci->metrics))
+       {
+           if (!haveInk &&
+               (ci->metrics.leftSideBearing == ci->metrics.rightSideBearing ||
+                ci->metrics.ascent == -ci->metrics.descent))
+               pCI[i].bits = &_fs_glyph_zero_length;
+           else
+           {
+               pCI[i].bits = &_fs_glyph_undefined;
+               fsd->glyphs_to_get++;
+           }
+       }
+       else
+           pCI[i].bits = (char *)0;
+       ci++;
+    }
+
+    xfree(fsci);
+
+    /* build bitmap metrics, ImageRectMax style */
+    if (haveInk)
+    {
+       FontInfoRec *fi = &bfont->pfont->info;
+       CharInfoPtr ii;
+
+       ci = fsfont->encoding;
+       ii = fsfont->inkMetrics;
+       for (i = 0; i < rep.num_extents; i++, ci++, ii++)
+       {
+           if (NONZEROMETRICS(&ii->metrics))
+           {
+               ci->metrics.leftSideBearing = FONT_MIN_LEFT(fi);
+               ci->metrics.rightSideBearing = FONT_MAX_RIGHT(fi);
+               ci->metrics.ascent = FONT_MAX_ASCENT(fi);
+               ci->metrics.descent = FONT_MAX_DESCENT(fi);
+               ci->metrics.characterWidth = FONT_MAX_WIDTH(fi);
+               ci->metrics.attributes = ii->metrics.attributes;
+           }
+           else
+           {
+               ci->metrics = ii->metrics;
+           }
+       }
+    }
+    {
+       unsigned int r, c, numCols, firstCol;
+
+       firstCol = bfont->pfont->info.firstCol;
+       numCols = bfont->pfont->info.lastCol - firstCol + 1;
+       c = bfont->pfont->info.defaultCh;
+       fsfont->pDefault = 0;
+       if (bfont->pfont->info.lastRow)
+       {
+           r = c >> 8;
+           r -= bfont->pfont->info.firstRow;
+           c &= 0xff;
+           c -= firstCol;
+           if (r < bfont->pfont->info.lastRow-bfont->pfont->info.firstRow+1 &&
+               c < numCols)
+               fsfont->pDefault = &pCI[r * numCols + c];
+       }
+       else
+       {
+           c -= firstCol;
+           if (c < numCols)
+               fsfont->pDefault = &pCI[c];
+       }
+    }
+    bfont->state = FS_GLYPHS_REPLY;
+
+    if (bfont->flags & FontLoadBitmaps) {
+       fs_send_query_bitmaps(fpe, blockrec);
+       return StillWorking;
+    }
+    return Successful;
+}
+
+/*
+ * XXX should probably continue to read here if we can, but must be sure
+ * it's our packet waiting, rather than another interspersed
+ */
+static int
+fs_do_open_font(fpe, blockrec, readheader)
+    FontPathElementPtr fpe;
+    FSBlockDataPtr blockrec;
+    Bool        readheader;
+{
+    FSBlockedFontPtr bfont = (FSBlockedFontPtr) blockrec->data;
+    FSFpePtr    conn = (FSFpePtr) fpe->private;
+    int         err;
+
+    switch (bfont->state) {
+    case FS_OPEN_REPLY:
+       if (readheader) {
+           /* get the next header */
+           if (_fs_read(conn, (char *) &blockrec->header,
+                        SIZEOF(fsGenericReply)) == -1) {
+               fs_free_font(bfont);
+               err = StillWorking;
+               break;
+           }
+       }
+       bfont->errcode = fs_read_open_font(fpe, blockrec);
+       if (bfont->errcode != StillWorking) {   /* already loaded, or error */
+           /* if font's already loaded, massage error code */
+           switch (bfont->state) {
+           case FS_DONE_REPLY:
+               bfont->errcode = Successful;
+               break;
+           case FS_DEPENDING:
+               bfont->errcode = StillWorking;
+               break;
+           }
+           err = bfont->errcode;
+           break;
+       }
+       /* if more data to read or Sync, fall thru, else return */
+       if (!(bfont->flags & FontOpenSync)) {
+           err = bfont->errcode;
+           break;
+       } else {
+           if (_fs_read(conn, (char *) &blockrec->header,
+                        SIZEOF(fsGenericReply)) == -1) {
+               fs_free_font(bfont);
+               err = StillWorking;
+               break;
+           }
+       }
+       /* fall through */
+    case FS_INFO_REPLY:
+       bfont->errcode = fs_read_query_info(fpe, blockrec);
+       if (bfont->errcode != StillWorking) {
+           err = bfont->errcode;
+           break;
+       }
+       if (!(bfont->flags & FontOpenSync)) {
+           err = bfont->errcode;
+           break;
+           /* if more data to read, fall thru, else return */
+       } else {
+           if (_fs_read(conn, (char *) &blockrec->header,
+                        SIZEOF(fsGenericReply))) {
+               fs_free_font(bfont);
+               err = StillWorking;
+               break;
+           }
+       }
+       /* fall through */
+    case FS_EXTENT_REPLY:
+       bfont->errcode = fs_read_extent_info(fpe, blockrec);
+       if (bfont->errcode != StillWorking) {
+           err = bfont->errcode;
+           break;
+       }
+       if (!(bfont->flags & FontOpenSync)) {
+           err = bfont->errcode;
+           break;
+       } else if (bfont->flags & FontLoadBitmaps) {
+           if (_fs_read(conn, (char *) &blockrec->header,
+                        SIZEOF(fsGenericReply))) {
+               fs_free_font(bfont);
+               err = StillWorking;
+               break;
+           }
+       }
+       /* fall through */
+    case FS_GLYPHS_REPLY:
+       if (bfont->flags & FontLoadBitmaps) {
+           bfont->errcode = fs_read_glyphs(fpe, blockrec);
+       }
+       err = bfont->errcode;
+       break;
+    case FS_DEPENDING:         /* can't happen */
+       err = bfont->errcode;
+    default:
+       err = bfont->errcode;
+       break;
+    }
+    if (err != StillWorking) {
+       bfont->state = FS_DONE_REPLY;   /* for _fs_load_glyphs() */
+       while (blockrec = blockrec->depending) {
+           bfont = (FSBlockedFontPtr) blockrec->data;
+           bfont->errcode = err;
+           bfont->state = FS_DONE_REPLY;       /* for _fs_load_glyphs() */
+       }
+    }
+    return err;
+}
+
+/* ARGSUSED */
+static void
+fs_block_handler(data, wt, LastSelectMask)
+    pointer     data;
+    struct timeval **wt;
+    fd_set*      LastSelectMask;
+{
+    static struct timeval recon_timeout;
+    Time_t      now,
+                soonest;
+    FSFpePtr    recon;
+
+    XFD_ORSET(LastSelectMask, LastSelectMask, &_fs_fd_mask);
+    if (recon = awaiting_reconnect) {
+       now = time((Time_t *) 0);
+       soonest = recon->time_to_try;
+       while (recon = recon->next_reconnect) {
+           if (recon->time_to_try < soonest)
+               soonest = recon->time_to_try;
+       }
+       if (soonest < now)
+           soonest = now;
+       soonest = soonest - now;
+       recon_timeout.tv_sec = soonest;
+       recon_timeout.tv_usec = 0;
+       if (*wt == (struct timeval *) 0) {
+           *wt = &recon_timeout;
+       } else if ((*wt)->tv_sec > soonest) {
+           **wt = recon_timeout;
+       }
+    }
+}
+
+static void
+fs_handle_unexpected(conn, rep)
+    FSFpePtr    conn;
+    fsGenericReply *rep;
+{
+    if (rep->type == FS_Event && rep->data1 == KeepAlive) {
+       fsNoopReq   req;
+
+       /* ping it back */
+       req.reqType = FS_Noop;
+       req.length = SIZEOF(fsNoopReq) >> 2;
+       _fs_add_req_log(conn, FS_Noop);
+       _fs_write(conn, (char *) &req, SIZEOF(fsNoopReq));
+    }
+    /* this should suck up unexpected replies and events */
+    _fs_eat_rest_of_error(conn, (fsError *) rep);
+}
+
+static int
+fs_wakeup(fpe, LastSelectMask)
+    FontPathElementPtr fpe;
+    fd_set* LastSelectMask;
+{
+    FSBlockDataPtr blockrec,
+                br;
+    FSFpePtr    conn = (FSFpePtr) fpe->private;
+    int         err;
+    fsGenericReply rep;
+
+    if (awaiting_reconnect) {
+       _fs_try_reconnect();
+    }
+    /* see if there's any data to be read */
+
+    /* 
+     * Don't continue if the fd is -1 (which will be true when the
+     * font server terminates
+     */
+    if (conn->fs_fd == -1)
+       return FALSE;
+
+    if (FD_ISSET(conn->fs_fd, LastSelectMask)) {
+
+#if defined(NOTDEF) || defined(__EMX__)                /* bogus - doesn't deal with EOF very well,
+                                * now does it ... */
+       /*
+        * make sure it isn't spurious - mouse events seem to trigger extra
+        * problems. Under OS/2, this is especially true ...
+        */
+       if (_fs_data_ready(conn) <= 0) {
+           return FALSE;
+       }
+#endif
+
+       /* get the header */
+       if (_fs_read(conn, (char *) &rep, SIZEOF(fsGenericReply)) == -1)
+           return FALSE;
+
+       /* find the matching block record */
+
+       for (br = (FSBlockDataPtr) conn->blocked_requests; br; br = br->next) {
+           if ((CARD16)(br->sequence_number & 0xffff) ==
+               (CARD16)(rep.sequenceNumber - 1))
+               break;
+       }
+       if (!br) {
+           fs_handle_unexpected(conn, &rep);
+           return FALSE;
+       }
+       blockrec = br;
+
+       memcpy(&blockrec->header, &rep, SIZEOF(fsGenericReply));
+
+       /* go read it, and if we're done, wake up the appropriate client */
+       switch (blockrec->type) {
+       case FS_OPEN_FONT:
+           err = fs_do_open_font(fpe, blockrec, FALSE);
+           break;
+       case FS_LOAD_GLYPHS:
+           err = fs_read_glyphs(fpe, blockrec);
+           break;
+       case FS_LIST_FONTS:
+           err = fs_read_list(fpe, blockrec);
+           break;
+       case FS_LIST_WITH_INFO:
+           err = fs_read_list_info(fpe, blockrec);
+           break;
+       default:
+           break;
+       }
+
+       if (err != StillWorking) {
+           while (blockrec) {
+               ClientSignal(blockrec->client);
+               blockrec = blockrec->depending;
+           }
+       }
+       /*
+        * Xx we could loop here and eat any additional replies, but it should
+        * feel more responsive for other clients if we come back later
+        */
+    } else if (awaiting_reconnect) {
+       _fs_try_reconnect();
+    }
+    return FALSE;
+}
+
+/*
+ * Reconnection code
+ */
+
+void
+_fs_connection_died(conn)
+    FSFpePtr    conn;
+{
+    if (!conn->attemptReconnect)
+       return;
+    conn->attemptReconnect = FALSE;
+    fs_close_conn(conn);
+    conn->time_to_try = time((Time_t *) 0) + FS_RECONNECT_WAIT;
+    conn->reconnect_delay = FS_RECONNECT_WAIT;
+    conn->fs_fd = -1;
+    conn->trans_conn = NULL;
+    conn->next_reconnect = awaiting_reconnect;
+    awaiting_reconnect = conn;
+}
+
+static int
+_fs_restart_connection(conn)
+    FSFpePtr    conn;
+{
+    FSBlockDataPtr block;
+
+    conn->current_seq = 0;
+    FD_SET(conn->fs_fd, &_fs_fd_mask);
+    if (!fs_send_init_packets(conn))
+       return FALSE;
+    while (block = (FSBlockDataPtr) conn->blocked_requests) {
+       ClientSignal(block->client);
+       fs_abort_blockrec(conn, block);
+    }
+    return TRUE;
+}
+
+static void
+_fs_try_reconnect()
+{
+    FSFpePtr    conn,
+               *prev;
+    Time_t      now;
+
+    prev = &awaiting_reconnect;
+    now = time((Time_t *) 0);
+    while (conn = *prev) {
+       if (now - conn->time_to_try > 0) {
+           if (_fs_reopen_server(conn) && _fs_restart_connection(conn)) {
+               conn->attemptReconnect = TRUE;
+               *prev = conn->next_reconnect;
+               if (prev == &awaiting_reconnect) continue;
+           } else {
+               if (conn->reconnect_delay < FS_MAX_RECONNECT_WAIT)
+                   conn->reconnect_delay *= 2;
+               now = time((Time_t *) 0);
+               conn->time_to_try = now + conn->reconnect_delay;
+           }
+       }
+       prev = &conn->next_reconnect;
+    }
+}
+
+/*
+ * sends the actual request out
+ */
+/* ARGSUSED */
+static int
+fs_send_open_font(client, fpe, flags, name, namelen, format, fmask, id, ppfont)
+    pointer     client;
+    FontPathElementPtr fpe;
+    Mask        flags;
+    char       *name;
+    int         namelen;
+    fsBitmapFormat format;
+    fsBitmapFormatMask fmask;
+    XID         id;
+    FontPtr    *ppfont;
+{
+    FontPtr     newfont;
+    FSBlockDataPtr blockrec = NULL;
+    FSBlockedFontPtr blockedfont;
+    FSFontDataPtr fsd;
+    FSFontPtr   fsfont;
+    FSFpePtr    conn;
+    fsOpenBitmapFontReq openreq;
+    int         err = Suspended;
+    XID         newid;
+    unsigned char buf[1024];
+    char       *fontname;
+
+    if (flags & FontReopen)
+    {
+       Atom nameatom, fn = None;
+       int i;
+
+       newfont = *ppfont;
+       fsd = (FSFontDataPtr)newfont->fpePrivate;
+       fsfont = (FSFontPtr)newfont->fontPrivate;
+       fpe = newfont->fpe;
+       format = fsd->format;
+       fmask = fsd->fmask;
+       newid = fsd->fontid;
+       /* This is an attempt to reopen a font.  Did the font have a
+          NAME property? */
+       if ((nameatom = MakeAtom("FONT", 4, 0)) != None)
+       {
+           for (i = 0; i < newfont->info.nprops; i++)
+               if (newfont->info.props[i].name == nameatom &&
+                   newfont->info.isStringProp[i])
+               {
+                   fn = newfont->info.props[i].value;
+                   break;
+               }
+       }
+       if (fn == None || !(name = NameForAtom(fn)))
+       {
+           name = fsd->name;
+           namelen = fsd->namelen;
+       }
+       else
+           namelen = strlen(name);
+    }
+
+    conn = (FSFpePtr) fpe->private;
+    if (namelen > sizeof (buf) - 1)
+       return BadFontName;
+    _fs_client_access (conn, client, (flags & FontOpenSync) != 0);
+    _fs_client_resolution(conn);
+
+
+    if (!(flags & FontReopen))
+    {
+
+       newid = GetNewFontClientID();
+
+       /* make the font */
+       newfont = (FontPtr) xalloc(sizeof(FontRec));
+
+       /* and the FS data */
+       fsd = (FSFontDataPtr) xalloc(sizeof(FSFontDataRec));
+
+       fsfont = (FSFontPtr) xalloc(sizeof(FSFontRec));
+
+       fontname = (char *)xalloc(namelen);
+
+       if (!newfont || !fsd || !fsfont || !fontname) {
+lowmem:
+           if (!(flags & FontReopen))
+           {
+               xfree((char *) newfont);
+               xfree((char *) fsd);
+               xfree((char *) fsfont);
+               xfree((char *) fontname);
+           }
+           if (blockrec) fs_abort_blockrec(conn, blockrec);
+           return AllocError;
+       }
+       bzero((char *) newfont, sizeof(FontRec));
+       bzero((char *) fsfont, sizeof(FSFontRec));
+       bzero((char *) fsd, sizeof(FSFontDataRec));
+    }
+
+    /* make a new block record, and add it to the end of the list */
+    blockrec = fs_new_block_rec(fpe, client, FS_OPEN_FONT);
+    if (!blockrec) {
+       goto lowmem;
+    }
+
+    if (!(flags & FontReopen))
+    {
+       int bit, byte, scan, glyph;
+
+       newfont->refcnt = 0;
+       newfont->maxPrivate = -1;
+       newfont->devPrivates = (pointer *) 0;
+       newfont->format = format;
+
+       /* These font components will be needed in packGlyphs */
+       CheckFSFormat(format, BitmapFormatMaskBit |
+                             BitmapFormatMaskByte |
+                             BitmapFormatMaskScanLineUnit |
+                             BitmapFormatMaskScanLinePad,
+                     &bit,
+                     &byte,
+                     &scan,
+                     &glyph,
+                     NULL);
+       newfont->bit = bit;
+       newfont->byte = byte;
+       newfont->scan = scan;
+       newfont->glyph = glyph;
+
+       newfont->fpe = fpe;
+       newfont->fpePrivate = (pointer) fsd;
+       newfont->fontPrivate = (pointer) fsfont;
+       _fs_init_font(newfont);
+
+       fsd->fpe = fpe;
+       fsd->name = fontname;
+       fsd->namelen = namelen;
+       memcpy(fontname, name, namelen);
+       fsd->format = format;
+       fsd->fmask = fmask;
+    }
+    fsd->fontid = newid;
+    fsd->generation = conn->generation;
+
+    blockedfont = (FSBlockedFontPtr) blockrec->data;
+    blockedfont->fontid = newid;
+    blockedfont->pfont = newfont;
+    blockedfont->state = FS_OPEN_REPLY;
+    blockedfont->flags = flags;
+    blockedfont->format = format;
+    blockedfont->clients_depending = (FSClientsDependingPtr)0;
+
+    /* save the ID */
+    if (!StoreFontClientFont(blockedfont->pfont, blockedfont->fontid)) {
+       goto lowmem;
+    }
+    /* do an FS_OpenFont, FS_QueryXInfo and FS_QueryXExtents */
+    buf[0] = (unsigned char) namelen;
+    memcpy(&buf[1], name, namelen);
+    namelen++;
+    openreq.reqType = FS_OpenBitmapFont;
+    openreq.fid = newid;
+    openreq.format_hint = format;
+    openreq.format_mask = fmask;
+    openreq.length = (SIZEOF(fsOpenBitmapFontReq) + namelen + 3) >> 2;
+
+    _fs_add_req_log(conn, FS_OpenBitmapFont);
+    _fs_write(conn, (char *) &openreq, SIZEOF(fsOpenBitmapFontReq));
+    _fs_write_pad(conn, (char *) buf, namelen);
+
+#ifdef NCD
+    if (configData.ExtendedFontDiags) {
+       memcpy(buf, name, MIN(256, namelen));
+       buf[MIN(256, namelen)] = '\0';
+       printf("Requesting font \"%s\" from font server \"%s\"\n",
+              buf, fpe->name);
+    }
+#endif
+
+    if (flags & FontOpenSync) {
+       err = fs_do_open_font(fpe, blockrec, TRUE);
+       if (blockedfont->errcode == Successful) {
+           *ppfont = blockedfont->pfont;
+       } else {
+           _fs_cleanup_font(blockedfont);
+       }
+       _fs_remove_block_rec(conn, blockrec);
+    }
+    return err;
+}
+
+static int
+fs_send_query_info(fpe, blockrec)
+    FontPathElementPtr fpe;
+    FSBlockDataPtr blockrec;
+{
+    FSBlockedFontPtr bfont;
+    FSFpePtr    conn = (FSFpePtr) fpe->private;
+    fsQueryXInfoReq inforeq;
+
+    bfont = (FSBlockedFontPtr) blockrec->data;
+
+    inforeq.reqType = FS_QueryXInfo;
+    inforeq.id = bfont->fontid;
+    inforeq.length = SIZEOF(fsQueryXInfoReq) >> 2;
+
+    blockrec->sequence_number = conn->current_seq;
+    _fs_add_req_log(conn, FS_QueryXInfo);
+    _fs_write(conn, (char *) &inforeq, SIZEOF(fsQueryXInfoReq));
+
+    return Successful;
+}
+
+static int
+fs_send_query_extents(fpe, blockrec)
+    FontPathElementPtr fpe;
+    FSBlockDataPtr blockrec;
+{
+    FSBlockedFontPtr bfont;
+    FSFpePtr    conn = (FSFpePtr) fpe->private;
+    fsQueryXExtents16Req extreq;
+
+    bfont = (FSBlockedFontPtr) blockrec->data;
+
+    extreq.reqType = FS_QueryXExtents16;
+    extreq.range = fsTrue;
+    extreq.fid = bfont->fontid;
+    extreq.num_ranges = 0;
+    extreq.length = SIZEOF(fsQueryXExtents16Req) >> 2;
+
+    blockrec->sequence_number = conn->current_seq;
+    _fs_add_req_log(conn, FS_QueryXExtents16);
+    _fs_write(conn, (char *) &extreq, SIZEOF(fsQueryXExtents16Req));
+
+    return Successful;
+}
+
+static int
+fs_send_query_bitmaps(fpe, blockrec)
+    FontPathElementPtr fpe;
+    FSBlockDataPtr blockrec;
+{
+    FSBlockedFontPtr bfont;
+    FSFpePtr    conn = (FSFpePtr) fpe->private;
+    fsQueryXBitmaps16Req bitreq;
+
+
+    bfont = (FSBlockedFontPtr) blockrec->data;
+
+    /* send the request */
+    bitreq.reqType = FS_QueryXBitmaps16;
+    bitreq.fid = bfont->fontid;
+    bitreq.format = bfont->format;
+    bitreq.range = TRUE;
+    bitreq.length = SIZEOF(fsQueryXBitmaps16Req) >> 2;
+    bitreq.num_ranges = 0;
+
+    blockrec->sequence_number = conn->current_seq;
+    _fs_add_req_log(conn, FS_QueryXBitmaps16);
+    _fs_write(conn, (char *) &bitreq, SIZEOF(fsQueryXBitmaps16Req));
+
+    return Successful;
+}
+
+/* ARGSUSED */
+static int
+fs_open_font(client, fpe, flags, name, namelen, format, fmask, id, ppfont,
+            alias, non_cachable_font)
+    pointer     client;
+    FontPathElementPtr fpe;
+    Mask        flags;
+    char       *name;
+    fsBitmapFormat format;
+    fsBitmapFormatMask fmask;
+    int         namelen;
+    XID         id;
+    FontPtr    *ppfont;
+    char      **alias;
+    FontPtr     non_cachable_font;     /* Not used in this FPE */
+{
+    FSFpePtr    conn = (FSFpePtr) fpe->private;
+    FSBlockDataPtr blockrec;
+    FSBlockedFontPtr blockedfont;
+    int         err;
+
+    /* libfont interface expects ImageRectMin glyphs */
+    format = format & ~BitmapFormatImageRectMask | BitmapFormatImageRectMin;
+
+    *alias = (char *) 0;
+    /* XX if we find the blockrec for the font */
+    blockrec = (FSBlockDataPtr) conn->blocked_requests;
+    while (blockrec != (FSBlockDataPtr) 0) {
+       if (blockrec->type == FS_OPEN_FONT &&
+               blockrec->client == client) {
+           blockedfont = (FSBlockedFontPtr) blockrec->data;
+           err = blockedfont->errcode;
+           if (err == Successful) {
+               *ppfont = blockedfont->pfont;
+           } else {
+               _fs_cleanup_font(blockedfont);
+           }
+           /* cleanup */
+           _fs_remove_block_rec(conn, blockrec);
+           return err;
+       }
+       blockrec = blockrec->next;
+    }
+    return fs_send_open_font(client, fpe, flags, name, namelen, format, fmask,
+                            id, ppfont);
+}
+
+/* ARGSUSED */
+static int
+fs_send_close_font(fpe, id)
+    FontPathElementPtr fpe;
+    Font        id;
+{
+    FSFpePtr    conn = (FSFpePtr) fpe->private;
+    fsCloseReq  req;
+
+    /* tell the font server to close the font */
+    req.reqType = FS_CloseFont;
+    req.length = SIZEOF(fsCloseReq) >> 2;
+    req.id = id;
+    _fs_add_req_log(conn, FS_CloseFont);
+    _fs_write(conn, (char *) &req, SIZEOF(fsCloseReq));
+
+    return Successful;
+}
+
+/* ARGSUSED */
+static int
+fs_close_font(fpe, pfont)
+    FontPathElementPtr fpe;
+    FontPtr     pfont;
+{
+    FSFontDataPtr fsd = (FSFontDataPtr) pfont->fpePrivate;
+    FSFpePtr    conn = (FSFpePtr) fpe->private;
+
+    /* XXX we may get called after the resource DB has been cleaned out */
+    if (find_old_font(fsd->fontid))
+       DeleteFontClientID(fsd->fontid);
+    if (conn->generation == fsd->generation)
+       fs_send_close_font(fpe, fsd->fontid);
+    (*pfont->unload_font) (pfont);
+
+
+    xfree(fsd->name);
+    xfree(fsd);
+    xfree(pfont->info.isStringProp);
+    xfree(pfont->info.props);
+    xfree(pfont->devPrivates);
+    xfree(pfont);
+
+
+    return Successful;
+}
+
+static int
+fs_read_glyphs(fpe, blockrec)
+    FontPathElementPtr fpe;
+    FSBlockDataPtr blockrec;
+{
+    FSBlockedGlyphPtr bglyph = (FSBlockedGlyphPtr) blockrec->data;
+    FSBlockedFontPtr bfont = (FSBlockedFontPtr) blockrec->data;
+    FSFpePtr    conn = (FSFpePtr) fpe->private;
+    FontPtr pfont = bglyph->pfont;      /* works for either blocked font
+                                          or glyph rec...  pfont is at
+                                          the very beginning of both
+                                          blockrec->data structures */
+    FSFontDataPtr fsd = (FSFontDataPtr) (pfont->fpePrivate);
+    FSFontPtr   fsdata = (FSFontPtr) pfont->fontPrivate;
+    FontInfoPtr        pfi = &pfont->info;
+    fsQueryXBitmaps16Reply rep;
+    fsOffset32   *ppbits;
+    fsOffset32 local_off;
+    char       *off_adr;
+    pointer     pbitmaps;
+    char       *bits;
+    int         glyph_size,
+                offset_size,
+                i,
+               err;
+    int                nranges = 0;
+    fsRange    *ranges, *nextrange;
+    unsigned long minchar, maxchar;
+
+    /* get reply header */
+    memcpy(&rep, &blockrec->header, SIZEOF(fsGenericReply));
+    if (rep.type == FS_Error) {
+/* XXX -- translate FS error */
+       _fs_eat_rest_of_error(conn, (fsError *) & rep);
+       err = AllocError;
+       goto bail;
+    }
+    if (_fs_read(conn, (char *) &rep + SIZEOF(fsGenericReply),
+             SIZEOF(fsQueryXBitmaps16Reply) - SIZEOF(fsGenericReply)) == -1) {
+       if (blockrec->type == FS_OPEN_FONT)
+           fs_free_font(bfont);
+       return StillWorking;
+    }
+    /* allocate space for glyphs */
+    offset_size = SIZEOF(fsOffset32) * (rep.num_chars);
+    glyph_size = (rep.length << 2) - SIZEOF(fsQueryXBitmaps16Reply)
+       - offset_size;
+    ppbits = (fsOffset32 *) xalloc(offset_size);
+    pbitmaps = (pointer) xalloc(glyph_size);
+    if (glyph_size && !pbitmaps || !ppbits)
+    {
+       xfree(pbitmaps);
+       xfree(ppbits);
+
+       /* clear wire */
+       (void) _fs_drain_bytes_pad(conn, offset_size);
+       (void) _fs_drain_bytes_pad(conn, glyph_size);
+
+       if (blockrec->type == FS_OPEN_FONT)
+           _fs_cleanup_font(bfont);
+       err = AllocError;
+       goto bail;
+    }
+
+    /* read offsets */
+    if (_fs_read_pad(conn, (char *) ppbits, offset_size) == -1) {
+       if (blockrec->type == FS_OPEN_FONT)
+           fs_free_font(bfont);
+       return StillWorking;
+    }
+
+    /* read glyphs */
+    if (_fs_read_pad(conn, (char *) pbitmaps, glyph_size) == -1) {
+       if (blockrec->type == FS_OPEN_FONT)
+           fs_free_font(bfont);
+       return StillWorking;
+    }
+
+    if (blockrec->type == FS_LOAD_GLYPHS)
+    {
+       nranges = bglyph->num_expected_ranges;
+       nextrange = ranges = bglyph->expected_ranges;
+    }
+
+    /* place the incoming glyphs */
+    if (nranges)
+    {
+       /* We're operating under the assumption that the ranges
+          requested in the LoadGlyphs call were all legal for this
+          font, and that individual ranges do not cover multiple
+          rows...  fs_build_range() is designed to ensure this. */
+       minchar = (nextrange->min_char_high - pfi->firstRow) *
+                 (pfi->lastCol - pfi->firstCol + 1) +
+                 nextrange->min_char_low - pfi->firstCol;
+       maxchar = (nextrange->max_char_high - pfi->firstRow) *
+                 (pfi->lastCol - pfi->firstCol + 1) +
+                 nextrange->max_char_low - pfi->firstCol;
+       nextrange++;
+    }
+    else
+    {
+       minchar = 0;
+       maxchar = rep.num_chars;
+    }
+
+    off_adr = (char *)ppbits;
+    for (i = 0; i < rep.num_chars; i++)
+    {
+       memcpy(&local_off, off_adr, SIZEOF(fsOffset32));        /* align it */
+       if (blockrec->type == FS_OPEN_FONT ||
+           fsdata->encoding[minchar].bits == &_fs_glyph_requested)
+       {
+           if (local_off.length)
+           {
+               bits = (char *)xalloc(local_off.length);
+               if (bits == NULL)
+               {
+                   xfree(ppbits);
+                   xfree(pbitmaps);
+                   err = AllocError;
+                   goto bail;
+               }
+               memcpy(bits, pbitmaps + local_off.position,
+                      local_off.length);
+           }
+           else if (NONZEROMETRICS(&fsdata->encoding[minchar].metrics))
+               bits = &_fs_glyph_zero_length;
+           else
+               bits = 0;
+           if (fsdata->encoding[minchar].bits == &_fs_glyph_requested)
+               fsd->glyphs_to_get--;
+           fsdata->encoding[minchar].bits = bits;
+       }
+       if (minchar++ == maxchar)
+       {
+           if (!--nranges) break;
+           minchar = (nextrange->min_char_high - pfi->firstRow) *
+                     (pfi->lastCol - pfi->firstCol + 1) +
+                     nextrange->min_char_low - pfi->firstCol;
+           maxchar = (nextrange->max_char_high - pfi->firstRow) *
+                     (pfi->lastCol - pfi->firstCol + 1) +
+                     nextrange->max_char_low - pfi->firstCol;
+           nextrange++;
+       }
+       off_adr += SIZEOF(fsOffset32);
+    }
+
+    xfree(ppbits);
+    xfree(pbitmaps);
+
+    if (blockrec->type == FS_OPEN_FONT)
+    {
+       fsd->glyphs_to_get = 0;
+       bfont->state = FS_DONE_REPLY;
+    }
+    err = Successful;
+
+bail:
+    if (blockrec->type == FS_LOAD_GLYPHS)
+    {
+       bglyph->done = TRUE;
+       bglyph->errcode = err;
+    }
+
+    return err;
+}
+
+
+
+static int
+fs_send_load_glyphs(client, pfont, nranges, ranges)
+    pointer     client;
+    FontPtr     pfont;
+    int                nranges;
+    fsRange    *ranges;
+{
+    FSBlockedGlyphPtr blockedglyph;
+    fsQueryXBitmaps16Req req;
+    FSFontDataPtr fsd = (FSFontDataPtr) (pfont->fpePrivate);
+    FontPathElementPtr fpe = fsd->fpe;
+    FSFpePtr    conn = (FSFpePtr) fpe->private;
+    FSBlockDataPtr blockrec;
+
+    /* make a new block record, and add it to the end of the list */
+    blockrec = fs_new_block_rec(fpe, client, FS_LOAD_GLYPHS);
+    if (!blockrec)
+       return AllocError;
+    blockedglyph = (FSBlockedGlyphPtr) blockrec->data;
+    blockedglyph->pfont = pfont;
+    blockedglyph->num_expected_ranges = nranges;
+    /* Assumption: it's our job to free ranges */
+    blockedglyph->expected_ranges = ranges;
+    blockedglyph->done = FALSE;
+    blockedglyph->clients_depending = (FSClientsDependingPtr)0;
+
+    blockrec->sequence_number = conn->current_seq;
+
+    /* send the request */
+    req.reqType = FS_QueryXBitmaps16;
+    req.fid = ((FSFontDataPtr) pfont->fpePrivate)->fontid;
+    req.format = pfont->format;
+    if (pfont->info.terminalFont)
+       req.format = req.format & ~(BitmapFormatImageRectMask) |
+                    BitmapFormatImageRectMax;
+    req.range = TRUE;
+    /* each range takes up 4 bytes */
+    req.length = (SIZEOF(fsQueryXBitmaps16Req) >> 2) + nranges;
+    req.num_ranges = nranges * 2;      /* protocol wants count of fsChar2bs */
+    _fs_add_req_log(conn, FS_QueryXBitmaps16);
+    _fs_write(conn, (char *) &req, SIZEOF(fsQueryXBitmaps16Req));
+
+    /* Send ranges to the server... pack into a char array by hand
+       to avoid structure-packing portability problems and to
+       handle swapping for version1 protocol */
+    if (nranges)
+    {
+#define RANGE_BUFFER_SIZE 64
+#define RANGE_BUFFER_SIZE_MASK 63
+       int i;
+       char range_buffer[RANGE_BUFFER_SIZE * 4];
+       char *range_buffer_p;
+
+       range_buffer_p = range_buffer;
+       for (i = 0; i < nranges;)
+       {
+           if (conn->fsMajorVersion > 1)
+           {
+               *range_buffer_p++ = ranges[i].min_char_high;
+               *range_buffer_p++ = ranges[i].min_char_low;
+               *range_buffer_p++ = ranges[i].max_char_high;
+               *range_buffer_p++ = ranges[i].max_char_low;
+           }
+           else
+           {
+               *range_buffer_p++ = ranges[i].min_char_low;
+               *range_buffer_p++ = ranges[i].min_char_high;
+               *range_buffer_p++ = ranges[i].max_char_low;
+               *range_buffer_p++ = ranges[i].max_char_high;
+           }
+
+           if (!(++i & RANGE_BUFFER_SIZE_MASK))
+           {
+               _fs_write(conn, range_buffer, RANGE_BUFFER_SIZE * 4);
+               range_buffer_p = range_buffer;
+           }
+       }
+       if (i &= RANGE_BUFFER_SIZE_MASK)
+           _fs_write(conn, range_buffer, i * 4);
+    }
+
+    return Suspended;
+}
+
+
+int
+fs_load_all_glyphs(pfont)
+    FontPtr    pfont;
+{
+    extern pointer serverClient;       /* This could be any number that
+                                          doesn't conflict with existing
+                                          client values. */
+    int err;
+    FSFpePtr conn = (FSFpePtr) pfont->fpe->private;
+
+    /*
+     * The purpose of this procedure is to load all glyphs in the event
+     * that we're dealing with someone who doesn't understand the finer
+     * points of glyph caching...  it is called from _fs_get_glyphs() if
+     * the latter is called to get glyphs that have not yet been loaded.
+     * We assume that the caller will not know how to handle a return
+     * value of Suspended (usually the case for a GetGlyphs() caller),
+     * so this procedure hangs around, freezing the server, for the
+     * request to complete.  This is an unpleasant kluge called to
+     * perform an unpleasant job that, we hope, will never be required.
+     */
+
+    while ((err = _fs_load_glyphs(serverClient, pfont, TRUE, 0, 0, NULL)) ==
+          Suspended)
+    {
+       fd_set TempSelectMask;
+       if (_fs_wait_for_readable(conn) == -1)
+       {
+           /* We lost our connection.  Don't wait to reestablish it;
+              just give up. */
+           _fs_connection_died(conn);
+
+           /* Get rid of blockrec */
+           fs_client_died(serverClient, pfont->fpe);
+
+           return BadCharRange;        /* As good an error as any other */
+       }
+       FD_SET(conn->fs_fd, &TempSelectMask);
+       fs_wakeup(pfont->fpe, &TempSelectMask);
+    }
+
+    return err;
+}
+
+
+int
+_fs_load_glyphs(client, pfont, range_flag, nchars, item_size, data)
+    pointer     client;
+    FontPtr     pfont;
+    Bool       range_flag;
+    unsigned int nchars;
+    int         item_size;
+    unsigned char *data;
+{
+
+    int                nranges = 0;
+    fsRange     *ranges = NULL;
+    int         res;
+    FSBlockDataPtr blockrec;
+    FSBlockedGlyphPtr blockedglyph;
+    FSFpePtr    conn = (FSFpePtr) pfont->fpe->private;
+    FSClientsDependingPtr *clients_depending = NULL;
+
+    /* see if the result is already there */
+
+    blockrec = (FSBlockDataPtr) conn->blocked_requests;
+    while (blockrec) {
+       if (blockrec->type == FS_LOAD_GLYPHS)
+       {
+           blockedglyph = (FSBlockedGlyphPtr) blockrec->data;
+           if (blockedglyph->pfont == pfont)
+           {
+               if (blockrec->client == client)
+               {
+                   if (blockedglyph->done)
+                   {
+                       int errcode = blockedglyph->errcode;
+                       signal_clients_depending(&blockedglyph->
+                                                clients_depending);
+                       _fs_remove_block_rec(conn, blockrec);
+                       return errcode;
+                   }
+                   else return Suspended;
+               }
+               /* We've found an existing LoadGlyphs blockrec for this
+                  font but for another client.  Rather than build a
+                  blockrec for it now (which entails some complex
+                  maintenance), we'll add it to a queue of clients to
+                  be signalled when the existing LoadGlyphs is
+                  completed.  */
+               clients_depending = &blockedglyph->clients_depending;
+               break;
+           }
+       }
+       else if (blockrec->type == FS_OPEN_FONT)
+       {
+           FSBlockedFontPtr bfont;
+           bfont = (FSBlockedFontPtr) blockrec->data;
+           if (bfont->pfont == pfont)
+           {
+               if (blockrec->client == client)
+               {
+                   if (bfont->state == FS_DONE_REPLY)
+                   {
+                       int errcode = bfont->errcode;
+                       signal_clients_depending(&bfont->clients_depending);
+                       _fs_remove_block_rec(conn, blockrec);
+                       if (errcode == Successful) break;
+                       else return errcode;
+                   }
+                   else return Suspended;
+               }
+               /* We've found an existing OpenFont blockrec for this
+                  font but for another client.  Rather than build a
+                  blockrec for it now (which entails some complex
+                  maintenance), we'll add it to a queue of clients to
+                  be signalled when the existing OpenFont is
+                  completed.  */
+               if (bfont->state != FS_DONE_REPLY)
+               {
+                   clients_depending = &bfont->clients_depending;
+                   break;
+               }
+           }
+       }
+                
+       blockrec = blockrec->next;
+    }
+
+    /*
+     * see if the desired glyphs already exist, and return Successful if they
+     * do, otherwise build up character range/character string
+     */
+    res = fs_build_range(pfont, range_flag, nchars, item_size, data,
+                        &nranges, &ranges);
+
+    switch (res)
+    {
+       case AccessDone:
+           return Successful;
+
+       case Successful:
+           break;
+
+       default:
+           return res;
+    }
+
+    /*
+     * If clients_depending is not null, this request must wait for
+     * some prior request(s) to complete.
+     */
+    if (clients_depending)
+    {
+       /* Since we're not ready to send the load_glyphs request yet,
+          clean up the damage (if any) caused by the fs_build_range()
+          call. */
+       if (nranges)
+       {
+           _fs_clean_aborted_loadglyphs(pfont, nranges, ranges);
+           xfree(ranges);
+       }
+       return add_clients_depending(clients_depending, client);
+    }
+
+    /*
+     * If fsd->generation != conn->generation, the font has been closed
+     * due to a lost connection.  We will reopen it, which will result
+     * in one of three things happening:
+     *  1) The open will succeed and obtain the same font.  Life
+     *     is wonderful.
+     *  2) The open will fail.  There is code above to recognize this
+     *     and flunk the LoadGlyphs request.  The client might not be
+     *     thrilled.
+     *  3) Worst case: the open will succeed but the font we open will
+     *     be different.  The fs_read_query_info() procedure attempts
+     *     to detect this by comparing the existing metrics and
+     *     properties against those of the reopened font... if they
+     *     don't match, we flunk the reopen, which eventually results
+     *     in flunking the LoadGlyphs request.  We could go a step
+     *     further and compare the extents, but this should be
+     *     sufficient.
+     */
+    if (((FSFontDataPtr)pfont->fpePrivate)->generation != conn->generation)
+    {
+       /* Since we're not ready to send the load_glyphs request yet,
+          clean up the damage caused by the fs_build_range() call. */
+       _fs_clean_aborted_loadglyphs(pfont, nranges, ranges);
+       xfree(ranges);
+
+       /* Now try to reopen the font. */
+       return fs_send_open_font(client, (FontPathElementPtr)0,
+                                (Mask)FontReopen, (char *)0, 0,
+                                (fsBitmapFormat)0, (fsBitmapFormatMask)0,
+                                (XID)0, &pfont);
+    }
+
+    return fs_send_load_glyphs(client, pfont, nranges, ranges);
+}
+
+
+
+static int
+fs_read_list(fpe, blockrec)
+    FontPathElementPtr fpe;
+    FSBlockDataPtr blockrec;
+{
+    FSBlockedListPtr blist = (FSBlockedListPtr) blockrec->data;
+    FSFpePtr    conn = (FSFpePtr) fpe->private;
+    fsListFontsReply rep;
+    char       *data,
+               *dp;
+    int         length,
+                i;
+
+    blist->done = TRUE;
+
+    /* read reply header */
+    memcpy(&rep, &blockrec->header, SIZEOF(fsGenericReply));
+    if (rep.type == FS_Error) {
+/* XXX -- translate FS error */
+       _fs_eat_rest_of_error(conn, (fsError *) & rep);
+       return AllocError;
+    }
+    if (_fs_read(conn, (char *) &rep + SIZEOF(fsGenericReply),
+                SIZEOF(fsListFontsReply) - SIZEOF(fsGenericReply)) == -1) {
+       /* nothing to free (i think) */
+       return StillWorking;
+    }
+    length = (rep.length << 2) - SIZEOF(fsListFontsReply);
+    data = (char *) xalloc(length);
+    if (!data) {
+       _fs_drain_bytes_pad(conn, length);
+       return AllocError;
+    }
+    /* read the list */
+    if (_fs_read_pad(conn, data, length) == -1) {
+       /* nothing to free (i think) */
+       return StillWorking;
+    }
+    /* copy data into FontPathRecord */
+    dp = data;
+    for (i = 0; i < rep.nFonts; i++) {
+       length = *(unsigned char *)dp++;
+       if (AddFontNamesName(blist->names, dp, length) != Successful) {
+           blist->errcode = AllocError;
+           break;
+       }
+       dp += length;
+    }
+
+    xfree(data);
+    return Successful;
+}
+
+static int
+fs_send_list_fonts(client, fpe, pattern, patlen, maxnames, newnames)
+    pointer     client;
+    FontPathElementPtr fpe;
+    char       *pattern;
+    int         patlen;
+    int         maxnames;
+    FontNamesPtr newnames;
+{
+    FSBlockDataPtr blockrec;
+    FSBlockedListPtr blockedlist;
+    FSFpePtr    conn = (FSFpePtr) fpe->private;
+    fsListFontsReq req;
+
+    _fs_client_access (conn, client, FALSE);
+    _fs_client_resolution(conn);
+
+    /* make a new block record, and add it to the end of the list */
+    blockrec = fs_new_block_rec(fpe, client, FS_LIST_FONTS);
+    if (!blockrec)
+       return AllocError;
+    blockedlist = (FSBlockedListPtr) blockrec->data;
+    blockedlist->patlen = patlen;
+    blockedlist->errcode = Successful;
+    blockedlist->names = newnames;
+    blockedlist->done = FALSE;
+
+    /* send the request */
+    req.reqType = FS_ListFonts;
+    req.maxNames = maxnames;
+    req.nbytes = patlen;
+    req.length = (SIZEOF(fsListFontsReq) + patlen + 3) >> 2;
+    _fs_add_req_log(conn, FS_ListFonts);
+    _fs_write(conn, (char *) &req, SIZEOF(fsListFontsReq));
+    _fs_write_pad(conn, (char *) pattern, patlen);
+
+#ifdef NCD
+    if (configData.ExtendedFontDiags) {
+       char        buf[256];
+
+       memcpy(buf, pattern, MIN(256, patlen));
+       buf[MIN(256, patlen)] = '\0';
+       printf("Listing fonts on pattern \"%s\" from font server \"%s\"\n",
+              buf, fpe->name);
+    }
+#endif
+
+    return Suspended;
+}
+
+static int
+fs_list_fonts(client, fpe, pattern, patlen, maxnames, newnames)
+    pointer     client;
+    FontPathElementPtr fpe;
+    char       *pattern;
+    int         patlen;
+    int         maxnames;
+    FontNamesPtr newnames;
+{
+    FSBlockDataPtr blockrec;
+    FSBlockedListPtr blockedlist;
+    FSFpePtr    conn = (FSFpePtr) fpe->private;
+    int         err;
+
+    /* see if the result is already there */
+    blockrec = (FSBlockDataPtr) conn->blocked_requests;
+    while (blockrec) {
+       if (blockrec->type == FS_LIST_FONTS && blockrec->client == client) {
+           blockedlist = (FSBlockedListPtr) blockrec->data;
+           if (blockedlist->patlen == patlen && blockedlist->done) {
+               err = blockedlist->errcode;
+               _fs_remove_block_rec(conn, blockrec);
+               return err;
+           }
+       }
+       blockrec = blockrec->next;
+    }
+
+    /* didn't find waiting record, so send a new one */
+    return fs_send_list_fonts(client, fpe, pattern, patlen, maxnames, newnames);
+}
+
+static int  padlength[4] = {0, 3, 2, 1};
+
+static int
+fs_read_list_info(fpe, blockrec)
+    FontPathElementPtr fpe;
+    FSBlockDataPtr blockrec;
+{
+    FSBlockedListInfoPtr binfo = (FSBlockedListInfoPtr) blockrec->data;
+    fsListFontsWithXInfoReply rep;
+    FSFpePtr    conn = (FSFpePtr) fpe->private;
+    fsPropInfo  pi;
+    fsPropOffset *po;
+    char       *name;
+    pointer     pd;
+    int                err;
+
+    /* clean up anything from the last trip */
+    if (binfo->name)
+    {
+       xfree(binfo->name);
+       binfo->name = NULL;
+    }
+    if (binfo->pfi) {
+       xfree(binfo->pfi->isStringProp);
+       xfree(binfo->pfi->props);
+       xfree(binfo->pfi);
+       binfo->pfi = NULL;
+    }
+    /* get reply header */
+    memcpy(&rep, &blockrec->header, SIZEOF(fsGenericReply));
+    if (rep.type == FS_Error) {
+/* XXX -- translate FS error */
+       _fs_eat_rest_of_error(conn, (fsError *) & rep);
+       binfo->errcode = AllocError;
+       return AllocError;
+    }
+    if (conn->fsMajorVersion > 1)
+       if (rep.nameLength == 0)
+           goto done;
+    /* old protocol sent a full-length reply even for the last one */
+    if (_fs_read(conn, (char *) &rep + SIZEOF(fsGenericReply),
+         SIZEOF(fsListFontsWithXInfoReply) - SIZEOF(fsGenericReply)) == -1) {
+       goto done;
+    }
+    if (rep.nameLength == 0)
+       goto done;
+
+    /* read the data */
+    name = (char *) xalloc(rep.nameLength);
+    binfo->pfi = (FontInfoPtr) xalloc(sizeof(FontInfoRec));
+    if (!name || !binfo->pfi) {
+       xfree(name);
+       xfree(binfo->pfi);
+       binfo->pfi = NULL;
+       _fs_drain_bytes(conn,
+                       rep.length - (SIZEOF(fsListFontsWithXInfoReply) -
+                                     SIZEOF(fsGenericReply)));
+       binfo->errcode = AllocError;
+       return AllocError;
+    }
+    if (conn->fsMajorVersion == 1)
+       if (_fs_read_pad(conn, name, rep.nameLength) == -1)
+           goto done;
+    if (_fs_read_pad(conn, (char *) &pi, SIZEOF(fsPropInfo)) == -1)
+           goto done;
+
+    po = (fsPropOffset *) xalloc(SIZEOF(fsPropOffset) * pi.num_offsets);
+    pd = (pointer) xalloc(pi.data_len);
+    if (!po || !pd) {
+       xfree(name);
+       xfree(po);
+       xfree(pd);
+       xfree (binfo->pfi);
+       binfo->pfi = NULL;
+       binfo->errcode = AllocError;
+       return AllocError;
+    }
+    err = _fs_read_pad(conn, (char *) po,
+                      (pi.num_offsets * SIZEOF(fsPropOffset)));
+    if (err != -1)
+    {
+       if (conn->fsMajorVersion > 1)
+           err = _fs_read(conn, (char *) pd, pi.data_len);
+       else
+           err = _fs_read_pad(conn, (char *) pd, pi.data_len);
+    }
+    if (err != -1  &&  conn->fsMajorVersion != 1)
+    {
+       err = _fs_read(conn, name, rep.nameLength);
+       if (err != -1)
+           err = _fs_drain_bytes(conn, padlength[(pi.data_len+rep.nameLength)&3]);
+    }
+
+    if (err == -1) {
+       xfree(name);
+       xfree(po);
+       xfree(pd);
+       xfree (binfo->pfi);
+       binfo->pfi = NULL;
+       goto done;
+    }
+
+    if (_fs_convert_lfwi_reply(conn, binfo->pfi, &rep, &pi, po, pd) != Successful)
+    {
+       xfree(name);
+       xfree(po);
+       xfree(pd);
+       xfree (binfo->pfi);
+       binfo->pfi = NULL;
+       goto done;
+    }
+    xfree(po);
+    xfree(pd);
+    binfo->name = name;
+    binfo->namelen = rep.nameLength;
+    binfo->remaining = rep.nReplies;
+
+    binfo->status = FS_LFWI_REPLY;
+    binfo->errcode = Suspended;
+    /* disable this font server until we've processed this response */
+    FD_CLR(conn->fs_fd, &_fs_fd_mask);
+
+    return Successful;
+
+done:
+    binfo->status = FS_LFWI_FINISHED;
+    binfo->errcode = BadFontName;
+    binfo->name = (char *) 0;
+    return Successful;
+}
+
+/* ARGSUSED */
+static int
+fs_start_list_with_info(client, fpe, pattern, len, maxnames, pdata)
+    pointer     client;
+    FontPathElementPtr fpe;
+    char       *pattern;
+    int         len;
+    int         maxnames;
+    pointer    *pdata;
+{
+    FSBlockDataPtr blockrec;
+    FSBlockedListInfoPtr blockedinfo;
+    fsListFontsWithXInfoReq req;
+    FSFpePtr    conn = (FSFpePtr) fpe->private;
+
+    _fs_client_access (conn, client, FALSE);
+    _fs_client_resolution(conn);
+
+    /* make a new block record, and add it to the end of the list */
+    blockrec = fs_new_block_rec(fpe, client, FS_LIST_WITH_INFO);
+    if (!blockrec)
+       return AllocError;
+    blockedinfo = (FSBlockedListInfoPtr) blockrec->data;
+    bzero((char *) blockedinfo, sizeof(FSBlockedListInfoRec));
+    blockedinfo->status = FS_LFWI_WAITING;
+    blockedinfo->errcode = Suspended;
+
+    /* send the request */
+    req.reqType = FS_ListFontsWithXInfo;
+    req.maxNames = maxnames;
+    req.nbytes = len;
+    req.length = (SIZEOF(fsListFontsWithXInfoReq) + len + 3) >> 2;
+    _fs_add_req_log(conn, FS_ListFontsWithXInfo);
+    (void) _fs_write(conn, (char *) &req, SIZEOF(fsListFontsWithXInfoReq));
+    (void) _fs_write_pad(conn, pattern, len);
+
+#ifdef NCD
+    if (configData.ExtendedFontDiags) {
+       char        buf[256];
+
+       memcpy(buf, pattern, MIN(256, len));
+       buf[MIN(256, len)] = '\0';
+       printf("Listing fonts with info on pattern \"%s\" from font server \"%s\"\n",
+              buf, fpe->name);
+    }
+#endif
+
+    return Successful;
+}
+
+/* ARGSUSED */
+static int
+fs_next_list_with_info(client, fpe, namep, namelenp, pFontInfo, numFonts,
+                      private)
+    pointer     client;
+    FontPathElementPtr fpe;
+    char      **namep;
+    int        *namelenp;
+    FontInfoPtr *pFontInfo;
+    int        *numFonts;
+    pointer     private;
+{
+    FSBlockDataPtr blockrec;
+    FSBlockedListInfoPtr blockedinfo;
+    FSFpePtr    conn = (FSFpePtr) fpe->private;
+
+    /* see if the result is already there */
+    blockrec = (FSBlockDataPtr) conn->blocked_requests;
+    while (blockrec) {
+       if (blockrec->type == FS_LIST_WITH_INFO &&
+               blockrec->client == client) {
+           blockedinfo = (FSBlockedListInfoPtr) blockrec->data;
+           break;
+       }
+       blockrec = blockrec->next;
+    }
+
+    if (!blockrec)
+    {
+       /* The only good reason for not finding a blockrec would be if
+          disconnect/reconnect to the font server wiped it out and the
+          code that called us didn't do the right thing to create
+          another one.  Under those circumstances, we need to return an
+          error to prevent that code from attempting to interpret the
+          information we don't return.  */
+       return BadFontName;
+    }
+
+    if (blockedinfo->status == FS_LFWI_WAITING)
+       return Suspended;
+
+    *namep = blockedinfo->name;
+    *namelenp = blockedinfo->namelen;
+    *pFontInfo = blockedinfo->pfi;
+    *numFonts = blockedinfo->remaining;
+    FD_SET(conn->fs_fd, &_fs_fd_mask);
+    if (blockedinfo->status == FS_LFWI_FINISHED) {
+       int         err = blockedinfo->errcode;
+
+       _fs_remove_block_rec(conn, blockrec);
+       return err;
+    }
+    if (blockedinfo->status == FS_LFWI_REPLY) {
+       blockedinfo->status = FS_LFWI_WAITING;
+       return Successful;
+    } else {
+       return blockedinfo->errcode;
+    }
+}
+
+/*
+ * Called when client exits
+ */
+
+static void
+fs_client_died(client, fpe)
+    pointer     client;
+    FontPathElementPtr fpe;
+{
+    FSFpePtr    conn = (FSFpePtr) fpe->private;
+    FSBlockDataPtr blockrec,
+                depending;
+    FSClientPtr        *prev, cur;
+    fsFreeACReq        freeac;
+
+    for (prev = &conn->clients; cur = *prev; prev = &cur->next)
+    {
+       if (cur->client == client) {
+           freeac.reqType = FS_FreeAC;
+           freeac.id = cur->acid;
+           freeac.length = sizeof (fsFreeACReq) >> 2;
+           _fs_add_req_log(conn, FS_FreeAC);
+           _fs_write (conn, (char *) &freeac, sizeof (fsFreeACReq));
+           *prev = cur->next;
+           xfree (cur);
+           break;
+       }
+    }
+    /* see if the result is already there */
+    blockrec = (FSBlockDataPtr) conn->blocked_requests;
+    while (blockrec) {
+       if (blockrec->client == client)
+           break;
+       blockrec = blockrec->next;
+    }
+    if (!blockrec)
+       return;
+    if (blockrec->type == FS_LIST_WITH_INFO)
+    {
+       FSBlockedListInfoPtr binfo;
+       binfo = (FSBlockedListInfoPtr) blockrec->data;
+       if (binfo->status == FS_LFWI_REPLY)
+           FD_SET(conn->fs_fd, &_fs_fd_mask);
+       if (binfo->name)
+       {
+           xfree(binfo->name);
+           binfo->name = NULL;
+       }
+       if (binfo->pfi) 
+       {
+           xfree(binfo->pfi->isStringProp);
+           xfree(binfo->pfi->props);
+           xfree(binfo->pfi);
+           binfo->pfi = NULL;
+       }
+    }
+    /* replace the client pointers in this block rec with the chained one */
+    if (depending = blockrec->depending) {
+       blockrec->client = depending->client;
+       blockrec->depending = depending->depending;
+       blockrec = depending;
+    }
+    fs_abort_blockrec(conn, blockrec);
+}
+
+static void
+_fs_client_access (conn, client, sync)
+    FSFpePtr   conn;
+    pointer    client;
+    Bool       sync;
+{
+    FSClientPtr        *prev,      cur;
+    fsCreateACReq          crac;
+    fsSetAuthorizationReq   setac;
+    fsGenericReply         rep;
+    char                   *authorizations;
+    int                            authlen;
+    Bool                   new_cur = FALSE;
+
+    for (prev = &conn->clients; cur = *prev; prev = &cur->next)
+    {
+       if (cur->client == client)
+       {
+           if (prev != &conn->clients)
+           {
+               *prev = cur->next;
+               cur->next = conn->clients;
+               conn->clients = cur;
+           }
+           break;
+       }
+    }
+    if (!cur)
+    {
+       cur = (FSClientPtr) xalloc (sizeof (FSClientRec));
+       if (!cur)
+           return;
+       cur->client = client;
+       cur->next = conn->clients;
+       conn->clients = cur;
+       cur->acid = GetNewFontClientID ();
+       new_cur = TRUE;
+    }
+    if (new_cur || cur->auth_generation != client_auth_generation(client))
+    {
+       if (!new_cur)
+       {
+           fsFreeACReq freeac;
+           freeac.reqType = FS_FreeAC;
+           freeac.id = cur->acid;
+           freeac.length = sizeof (fsFreeACReq) >> 2;
+           _fs_add_req_log(conn, FS_FreeAC);
+           _fs_write (conn, (char *) &freeac, sizeof (fsFreeACReq));
+       }
+       crac.reqType = FS_CreateAC;
+       crac.num_auths = set_font_authorizations(&authorizations, &authlen,
+                                                client);
+       authlen = crac.num_auths ? (authlen + 3) & ~0x3 : 0;
+       crac.length = (sizeof (fsCreateACReq) + authlen) >> 2;
+       crac.acid = cur->acid;
+       _fs_add_req_log(conn, FS_CreateAC);
+       _fs_write(conn, (char *) &crac, sizeof (fsCreateACReq));
+       _fs_write(conn, authorizations, authlen);
+       /* if we're synchronous, open_font will be confused by
+        * the reply; eat it and continue
+        */
+       if (sync)
+       {
+           if (_fs_read(conn, (char *) &rep, sizeof (fsGenericReply)) == -1)
+               return;
+           fs_handle_unexpected(conn, &rep);
+       }
+       /* ignore reply; we don't even care about it */
+       conn->curacid = 0;
+       cur->auth_generation = client_auth_generation(client);
+    }
+    if (conn->curacid != cur->acid)
+    {
+       setac.reqType = FS_SetAuthorization;
+       setac.length = sizeof (fsSetAuthorizationReq) >> 2;
+       setac.id = cur->acid;
+       _fs_add_req_log(conn, FS_SetAuthorization);
+       _fs_write(conn, (char *) &setac, sizeof (fsSetAuthorizationReq));
+       conn->curacid = cur->acid;
+    }
+}
+
+/*
+ * called at server init time
+ */
+
+void
+fs_register_fpe_functions()
+{
+    fs_font_type = RegisterFPEFunctions(fs_name_check,
+                                       fs_init_fpe,
+                                       fs_free_fpe,
+                                       fs_reset_fpe,
+                                       fs_open_font,
+                                       fs_close_font,
+                                       fs_list_fonts,
+                                       fs_start_list_with_info,
+                                       fs_next_list_with_info,
+                                       fs_wakeup,
+                                       fs_client_died,
+                                       _fs_load_glyphs,
+                                       (int (*))0,
+                                       (int (*))0,
+                                       (void (*))0);
+}
+
+static int
+check_fs_open_font(client, fpe, flags, name, namelen, format, fmask, id, ppfont,
+            alias, non_cachable_font)
+    pointer     client;
+    FontPathElementPtr fpe;
+    Mask        flags;
+    char       *name;
+    fsBitmapFormat format;
+    fsBitmapFormatMask fmask;
+    int         namelen;
+    XID         id;
+    FontPtr    *ppfont;
+    char      **alias;
+    FontPtr     non_cachable_font;     /* Not used in this FPE */
+{
+    if (XpClientIsBitmapClient(client))
+       return (fs_open_font(client, fpe, flags, name, namelen, format, 
+                       fmask, id, ppfont, alias, non_cachable_font) );
+    return BadFontName;
+}
+
+static int
+check_fs_list_fonts(client, fpe, pattern, patlen, maxnames, newnames)
+    pointer     client;
+    FontPathElementPtr fpe;
+    char       *pattern;
+    int         patlen;
+    int         maxnames;
+    FontNamesPtr newnames;
+{
+    if (XpClientIsBitmapClient(client))
+       return (fs_list_fonts(client, fpe, pattern, patlen, maxnames, 
+               newnames));
+    return BadFontName;
+}
+
+static int
+check_fs_start_list_with_info(client, fpe, pattern, len, maxnames, pdata)
+    pointer     client;
+    FontPathElementPtr fpe;
+    char       *pattern;
+    int         len;
+    int         maxnames;
+    pointer    *pdata;
+{
+    if (XpClientIsBitmapClient(client))
+       return (fs_start_list_with_info(client, fpe, pattern, len, maxnames,
+               pdata));
+    return BadFontName;
+}
+
+static int
+check_fs_next_list_with_info(client, fpe, namep, namelenp, pFontInfo, numFonts,
+                      private)
+    pointer     client;
+    FontPathElementPtr fpe;
+    char      **namep;
+    int        *namelenp;
+    FontInfoPtr *pFontInfo;
+    int        *numFonts;
+    pointer     private;
+{
+    if (XpClientIsBitmapClient(client))
+       return (fs_next_list_with_info(client, fpe, namep, namelenp, pFontInfo, 
+               numFonts,private));
+    return BadFontName;
+}
+
+void
+check_fs_register_fpe_functions()
+{
+    fs_font_type = RegisterFPEFunctions(fs_name_check,
+                                       fs_init_fpe,
+                                       fs_free_fpe,
+                                       fs_reset_fpe,
+                                       check_fs_open_font,
+                                       fs_close_font,
+                                       check_fs_list_fonts,
+                                       check_fs_start_list_with_info,
+                                       check_fs_next_list_with_info,
+                                       fs_wakeup,
+                                       fs_client_died,
+                                       _fs_load_glyphs,
+                                       (int (*))0,
+                                       (int (*))0,
+                                       (void (*))0);
+}
diff --git a/Xserver/lib/font/fc/fserve.h b/Xserver/lib/font/fc/fserve.h
new file mode 100644 (file)
index 0000000..6bab522
--- /dev/null
@@ -0,0 +1,68 @@
+/* $XConsortium: fserve.h,v 1.7 93/08/24 18:49:12 gildea Exp $ */
+/*
+ * Copyright 1990 Network Computing Devices
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the name of Network Computing Devices not be
+ * used in advertising or publicity pertaining to distribution of the
+ * software without specific, written prior permission.  Network Computing
+ * Devices makes no representations about the suitability of this software
+ * for any purpose.  It is provided "as is" without express or implied
+ * warranty.
+ *
+ * NETWORK COMPUTING DEVICES DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
+ * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS,
+ * IN NO EVENT SHALL NETWORK COMPUTING DEVICES BE LIABLE FOR ANY SPECIAL,
+ * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
+ * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
+ * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE
+ * OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ * Author:     Dave Lemke, Network Computing Devices, Inc
+ *
+ */
+
+#ifndef _FSERVE_H_
+#define _FSERVE_H_
+/*
+ * font server data structures
+ */
+
+/* types of block records */
+#define        FS_OPEN_FONT            1
+#define        FS_LOAD_GLYPHS          2
+#define        FS_LIST_FONTS           3
+#define        FS_LIST_WITH_INFO       4
+
+/* states of OpenFont */
+#define        FS_OPEN_REPLY           0
+#define        FS_INFO_REPLY           1
+#define        FS_EXTENT_REPLY         2
+#define        FS_GLYPHS_REPLY         3
+#define        FS_DONE_REPLY           4
+#define FS_DEPENDING           5
+
+/* status of ListFontsWithInfo */
+#define        FS_LFWI_WAITING         0
+#define        FS_LFWI_REPLY           1
+#define        FS_LFWI_FINISHED        2
+
+#define        AccessDone      0x400
+
+typedef struct _fs_font_data *FSFontDataPtr;
+typedef struct _fs_blocked_font *FSBlockedFontPtr;
+typedef struct _fs_blocked_glyphs *FSBlockedGlyphPtr;
+typedef struct _fs_blocked_list *FSBlockedListPtr;
+typedef struct _fs_blocked_list_info *FSBlockedListInfoPtr;
+typedef struct _fs_block_data *FSBlockDataPtr;
+typedef struct _fs_font_table *FSFontTablePtr;
+
+typedef struct _fs_blocked_bitmaps *FSBlockedBitmapPtr;
+typedef struct _fs_blocked_extents *FSBlockedExtentPtr;
+
+extern void fs_convert_char_info();
+
+#endif                         /* _FSERVE_H_ */
diff --git a/Xserver/lib/font/fc/fservestr.h b/Xserver/lib/font/fc/fservestr.h
new file mode 100644 (file)
index 0000000..7f5ed85
--- /dev/null
@@ -0,0 +1,188 @@
+/* $XConsortium: fservestr.h,v 1.13 95/06/09 22:16:29 gildea Exp $ */
+/*
+ * Copyright 1990 Network Computing Devices
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and
+ * its documentation for any purpose is hereby granted without fee, provided
+ * that the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the name of Network Computing Devices not be
+ * used in advertising or publicity pertaining to distribution of the
+ * software without specific, written prior permission.  Network Computing
+ * Devices makes no representations about the suitability of this software
+ * for any purpose.  It is provided "as is" without express or implied
+ * warranty.
+ *
+ * NETWORK COMPUTING DEVICES DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
+ * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS,
+ * IN NO EVENT SHALL NETWORK COMPUTING DEVICES BE LIABLE FOR ANY SPECIAL,
+ * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
+ * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
+ * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE
+ * OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ * Author:     Dave Lemke, Network Computing Devices, Inc
+ */
+
+#ifndef _FSERVESTR_H_
+#define _FSERVESTR_H_
+
+#include       "fserve.h"
+#include       "fsio.h"
+
+/*
+ * font server data structures
+ */
+/*
+ * font server private storage
+ */
+
+
+typedef struct _fs_font {
+    CharInfoPtr pDefault;
+    CharInfoPtr encoding;
+    CharInfoPtr inkMetrics;
+}           FSFontRec, *FSFontPtr;
+
+/* FS special data for the font */
+typedef struct _fs_font_data {
+    long        fontid;
+    int                generation;     /* FS generation when opened */
+    FontPathElementPtr fpe;
+    unsigned long glyphs_to_get;       /* # glyphs remaining to be gotten */
+
+    /* Following data needed in case font needs to be reopened. */
+    int                namelen;
+    char       *name;
+    fsBitmapFormat     format;
+    fsBitmapFormatMask fmask;
+}           FSFontDataRec;
+
+typedef struct fs_clients_depending {
+    pointer    client;
+    struct fs_clients_depending *next;
+}      FSClientsDependingRec, *FSClientsDependingPtr;
+
+/* OpenFont specific data for blocked request */
+typedef struct _fs_blocked_font {
+    FontPtr     pfont;
+    long        fontid;
+    int         state;         /* how many of the replies have landed */
+    int         errcode;
+    int         flags;
+    fsBitmapFormat format;
+    FSClientsDependingPtr      clients_depending;
+}           FSBlockedFontRec;
+
+/* LoadGlyphs data for blocked request */
+typedef struct _fs_blocked_glyphs {
+    FontPtr     pfont;
+    int                num_expected_ranges;
+    fsRange     *expected_ranges;
+    int         errcode;
+    Bool        done;
+    FSClientsDependingPtr      clients_depending;
+}           FSBlockedGlyphRec;
+
+/* LoadExtents data for blocked request */
+typedef struct _fs_blocked_extents {
+    FontPtr     pfont;
+    fsRange    *expected_ranges;
+    int         nranges;
+    Bool        done;
+    unsigned long nextents;
+    fsXCharInfo *extents;
+}           FSBlockedExtentRec;
+
+/* LoadBitmaps data for blocked request */
+typedef struct _fs_blocked_bitmaps {
+    FontPtr     pfont;
+    fsRange    *expected_ranges;
+    int         nranges;
+    Bool        done;
+    unsigned long size;
+    unsigned long nglyphs;
+    fsOffset32   *offsets;
+    pointer     gdata;
+}           FSBlockedBitmapRec;
+
+/* state for blocked ListFonts */
+typedef struct _fs_blocked_list {
+    FontNamesPtr names;
+    int         patlen;
+    int         errcode;
+    Bool        done;
+}           FSBlockedListRec;
+
+/* state for blocked ListFontsWithInfo */
+typedef struct _fs_blocked_list_info {
+    int         status;
+    char       *name;
+    int         namelen;
+    FontInfoPtr pfi;
+    int         remaining;
+    int         errcode;
+}           FSBlockedListInfoRec;
+
+/* state for blocked request */
+typedef struct _fs_block_data {
+    int                            type;       /* Open Font, LoadGlyphs, ListFonts,
+                                        * ListWithInfo */
+    pointer                client;         /* who wants it */
+    int                            sequence_number;/* expected */
+    fsGenericReply         header;
+    pointer                data;           /* type specific data */
+    struct _fs_block_data   *depending;            /* clients depending on this one */
+    struct _fs_block_data   *next;
+}           FSBlockDataRec;
+
+/* state for reconnected to dead font server */
+typedef struct _fs_reconnect {
+    int            i;
+} FSReconnectRec, *FSReconnectPtr;
+
+
+#if (defined(__STDC__) && !defined(UNIXCPP)) || defined(ANSICPP)
+#define fsCat(x,y) x##_##y
+#else
+#define fsCat(x,y) x/**/_/**/y
+#endif
+
+
+/* copy XCharInfo parts of a protocol reply into a xCharInfo */
+
+#define fsUnpack_XCharInfo(packet, structure) \
+    (structure)->leftSideBearing = fsCat(packet,left); \
+    (structure)->rightSideBearing = fsCat(packet,right); \
+    (structure)->characterWidth = fsCat(packet,width); \
+    (structure)->ascent = fsCat(packet,ascent); \
+    (structure)->descent = fsCat(packet,descent); \
+    (structure)->attributes = fsCat(packet,attributes)
+
+
+/* copy XFontInfoHeader parts of a protocol reply into a FontInfoRec */
+
+#define fsUnpack_XFontInfoHeader(packet, structure) \
+    (structure)->allExist = ((packet)->font_header_flags & FontInfoAllCharsExist) != 0; \
+    (structure)->drawDirection = \
+        ((packet)->font_header_draw_direction == LeftToRightDrawDirection) ? \
+       LeftToRight : RightToLeft; \
+    (structure)->inkInside = ((packet)->font_header_flags & FontInfoInkInside) != 0; \
+ \
+    (structure)->firstRow = (packet)->font_hdr_char_range_min_char_high; \
+    (structure)->firstCol = (packet)->font_hdr_char_range_min_char_low; \
+    (structure)->lastRow = (packet)->font_hdr_char_range_max_char_high; \
+    (structure)->lastCol = (packet)->font_hdr_char_range_max_char_low; \
+    (structure)->defaultCh = (packet)->font_header_default_char_low \
+                           + ((packet)->font_header_default_char_high << 8); \
+ \
+    (structure)->fontDescent = (packet)->font_header_font_descent; \
+    (structure)->fontAscent = (packet)->font_header_font_ascent; \
+ \
+    fsUnpack_XCharInfo((packet)->font_header_min_bounds, &(structure)->minbounds); \
+    fsUnpack_XCharInfo((packet)->font_header_min_bounds, &(structure)->ink_minbounds); \
+    fsUnpack_XCharInfo((packet)->font_header_max_bounds, &(structure)->maxbounds); \
+    fsUnpack_XCharInfo((packet)->font_header_max_bounds, &(structure)->ink_maxbounds)
+
+
+#endif                         /* _FSERVESTR_H_ */
diff --git a/Xserver/lib/font/fc/fsio.c b/Xserver/lib/font/fc/fsio.c
new file mode 100644 (file)
index 0000000..586e6ad
--- /dev/null
@@ -0,0 +1,652 @@
+/* $XConsortium: fsio.c,v 1.37 95/04/05 19:58:13 kaleb Exp $ */
+/* $XFree86: xc/lib/font/fc/fsio.c,v 3.5.2.1 1998/02/15 16:08:40 hohndel Exp $ */
+/*
+ * Copyright 1990 Network Computing Devices
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the name of Network Computing Devices not be
+ * used in advertising or publicity pertaining to distribution of the
+ * software without specific, written prior permission.  Network Computing
+ * Devices makes no representations about the suitability of this software
+ * for any purpose.  It is provided "as is" without express or implied
+ * warranty.
+ *
+ * NETWORK COMPUTING DEVICES DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
+ * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS,
+ * IN NO EVENT SHALL NETWORK COMPUTING DEVICES BE LIABLE FOR ANY SPECIAL,
+ * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
+ * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
+ * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE
+ * OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ * Author:     Dave Lemke, Network Computing Devices, Inc
+ */
+/*
+ * font server i/o routines
+ */
+
+#ifdef WIN32
+#define _WILLWINSOCK_
+#endif
+
+#include       "FS.h"
+#include       "FSproto.h"
+
+#include       "X11/Xtrans.h"
+#include       "X11/Xpoll.h"
+#include       "fontmisc.h"
+#include       "fsio.h"
+
+#include       <stdio.h>
+#include       <signal.h>
+#include       <sys/types.h>
+#if !defined(WIN32) && !defined(AMOEBA) && !defined(_MINIX)
+#ifndef Lynx
+#include       <sys/socket.h>
+#else
+#include       <socket.h>
+#endif
+#endif
+#include       <errno.h>
+#ifdef X_NOT_STDC_ENV
+extern int errno;
+#endif 
+#ifdef WIN32
+#define EWOULDBLOCK WSAEWOULDBLOCK
+#undef EINTR
+#define EINTR WSAEINTR
+#endif
+
+#ifdef MINIX
+#include <sys/nbio.h>
+#define select(n,r,w,x,t) nbio_select(n,r,w,x,t)
+#endif
+
+#ifdef __EMX__
+#define select(n,r,w,x,t) os2PseudoSelect(n,r,w,x,t)
+#endif
+
+/* check for both EAGAIN and EWOULDBLOCK, because some supposedly POSIX
+ * systems are broken and return EWOULDBLOCK when they should return EAGAIN
+ */
+#ifdef WIN32
+#define ETEST() (WSAGetLastError() == WSAEWOULDBLOCK)
+#else
+#if defined(EAGAIN) && defined(EWOULDBLOCK)
+#define ETEST() (errno == EAGAIN || errno == EWOULDBLOCK)
+#else
+#ifdef EAGAIN
+#define ETEST() (errno == EAGAIN)
+#else
+#define ETEST() (errno == EWOULDBLOCK)
+#endif
+#endif
+#endif
+#ifdef WIN32
+#define ECHECK(err) (WSAGetLastError() == err)
+#define ESET(val) WSASetLastError(val)
+#else
+#ifdef ISC
+#define ECHECK(err) ((errno == err) || ETEST())
+#else
+#define ECHECK(err) (errno == err)
+#endif
+#define ESET(val) errno = val
+#endif
+
+static int  padlength[4] = {0, 3, 2, 1};
+fd_set _fs_fd_mask;
+
+int  _fs_wait_for_readable();
+
+#ifdef SIGNALRETURNSINT
+#define SIGNAL_T int
+#else
+#define SIGNAL_T void
+#endif
+
+/* ARGSUSED */
+static      SIGNAL_T
+_fs_alarm(foo)
+    int         foo;
+{
+    return;
+}
+
+static XtransConnInfo
+_fs_connect(servername, timeout)
+    char       *servername;
+    int         timeout;
+{
+    XtransConnInfo trans_conn;         /* transport connection object */
+    int         ret = -1;
+#ifdef SIGALRM
+    unsigned    oldTime;
+
+    SIGNAL_T(*oldAlarm) ();
+#endif
+
+    /*
+     * Open the network connection.
+     */
+    if( (trans_conn=_FontTransOpenCOTSClient(servername)) == NULL )
+       {
+       return (NULL);
+       }
+
+#ifdef SIGALRM
+    oldTime = alarm((unsigned) 0);
+    oldAlarm = signal(SIGALRM, _fs_alarm);
+    alarm((unsigned) timeout);
+#endif
+
+    ret = _FontTransConnect(trans_conn,servername);
+
+#ifdef SIGALRM
+    alarm((unsigned) 0);
+    signal(SIGALRM, oldAlarm);
+    alarm(oldTime);
+#endif
+
+    if (ret < 0)
+       {
+       _FontTransClose(trans_conn);
+       return (NULL);
+       }
+
+    /*
+     * Set the connection non-blocking since we use select() to block.
+     */
+
+    _FontTransSetOption(trans_conn, TRANS_NONBLOCKING, 1);
+
+    return trans_conn;
+}
+
+static int  generationCount;
+
+/* ARGSUSED */
+static Bool
+_fs_setup_connection(conn, servername, timeout, copy_name_p)
+    FSFpePtr    conn;
+    char       *servername;
+    int         timeout;
+    Bool       copy_name_p;
+{
+    fsConnClientPrefix prefix;
+    fsConnSetup rep;
+    int         setuplength;
+    fsConnSetupAccept conn_accept;
+    int         endian;
+    int         i;
+    int         alt_len;
+    char       *auth_data = NULL,
+               *vendor_string = NULL,
+               *alt_data = NULL,
+               *alt_dst;
+    FSFpeAltPtr alts;
+    int         nalts;
+
+    if ((conn->trans_conn = _fs_connect(servername, 5)) == NULL)
+       return FALSE;
+
+    conn->fs_fd = _FontTransGetConnectionNumber (conn->trans_conn);
+
+    conn->generation = ++generationCount;
+
+    /* send setup prefix */
+    endian = 1;
+    if (*(char *) &endian)
+       prefix.byteOrder = 'l';
+    else
+       prefix.byteOrder = 'B';
+
+    prefix.major_version = FS_PROTOCOL;
+    prefix.minor_version = FS_PROTOCOL_MINOR;
+
+/* XXX add some auth info here */
+    prefix.num_auths = 0;
+    prefix.auth_len = 0;
+
+    if (_fs_write(conn, (char *) &prefix, SIZEOF(fsConnClientPrefix)) == -1)
+       return FALSE;
+
+    /* read setup info */
+    if (_fs_read(conn, (char *) &rep, SIZEOF(fsConnSetup)) == -1)
+       return FALSE;
+
+    conn->fsMajorVersion = rep.major_version;
+    if (rep.major_version > FS_PROTOCOL)
+       return FALSE;
+
+    alts = 0;
+    /* parse alternate list */
+    if (nalts = rep.num_alternates) {
+       setuplength = rep.alternate_len << 2;
+       alts = (FSFpeAltPtr) xalloc(nalts * sizeof(FSFpeAltRec) +
+                                   setuplength);
+       if (!alts) {
+           _FontTransClose(conn->trans_conn);
+           errno = ENOMEM;
+           return FALSE;
+       }
+       alt_data = (char *) (alts + nalts);
+       if (_fs_read(conn, (char *) alt_data, setuplength) == -1) {
+           xfree(alts);
+           return FALSE;
+       }
+       alt_dst = alt_data;
+       for (i = 0; i < nalts; i++) {
+           alts[i].subset = alt_data[0];
+           alt_len = alt_data[1];
+           alts[i].name = alt_dst;
+           memmove(alt_dst, alt_data + 2, alt_len);
+           alt_dst[alt_len] = '\0';
+           alt_dst += (alt_len + 1);
+           alt_data += (2 + alt_len + padlength[(2 + alt_len) & 3]);
+       }
+    }
+    if (conn->alts)
+       xfree(conn->alts);
+    conn->alts = alts;
+    conn->numAlts = nalts;
+
+    setuplength = rep.auth_len << 2;
+    if (setuplength &&
+           !(auth_data = (char *) xalloc((unsigned int) setuplength))) {
+       _FontTransClose(conn->trans_conn);
+       errno = ENOMEM;
+       return FALSE;
+    }
+    if (_fs_read(conn, (char *) auth_data, setuplength) == -1) {
+       xfree(auth_data);
+       return FALSE;
+    }
+    if (rep.status != AuthSuccess) {
+       xfree(auth_data);
+       _FontTransClose(conn->trans_conn);
+       errno = EPERM;
+       return FALSE;
+    }
+    /* get rest */
+    if (_fs_read(conn, (char *) &conn_accept, (long) SIZEOF(fsConnSetupAccept)) == -1) {
+       xfree(auth_data);
+       return FALSE;
+    }
+    if ((vendor_string = (char *)
+        xalloc((unsigned) conn_accept.vendor_len + 1)) == NULL) {
+       xfree(auth_data);
+       _FontTransClose(conn->trans_conn);
+       errno = ENOMEM;
+       return FALSE;
+    }
+    if (_fs_read_pad(conn, (char *) vendor_string, conn_accept.vendor_len) == -1) {
+       xfree(vendor_string);
+       xfree(auth_data);
+       return FALSE;
+    }
+    xfree(auth_data);
+    xfree(vendor_string);
+
+    if (copy_name_p)
+    {
+        conn->servername = (char *) xalloc(strlen(servername) + 1);
+        if (conn->servername == NULL)
+           return FALSE;
+        strcpy(conn->servername, servername);
+    }
+    else
+        conn->servername = servername;
+
+    return TRUE;
+}
+
+static Bool
+_fs_try_alternates(conn, timeout)
+    FSFpePtr    conn;
+    int         timeout;
+{
+    int         i;
+
+    for (i = 0; i < conn->numAlts; i++)
+       if (_fs_setup_connection(conn, conn->alts[i].name, timeout, TRUE))
+           return TRUE;
+    return FALSE;
+}
+
+#define FS_OPEN_TIMEOUT            30
+#define FS_REOPEN_TIMEOUT   10
+
+FSFpePtr
+_fs_open_server(servername)
+    char       *servername;
+{
+    FSFpePtr    conn;
+
+    conn = (FSFpePtr) xalloc(sizeof(FSFpeRec));
+    if (!conn) {
+       errno = ENOMEM;
+       return (FSFpePtr) NULL;
+    }
+    bzero((char *) conn, sizeof(FSFpeRec));
+    if (!_fs_setup_connection(conn, servername, FS_OPEN_TIMEOUT, TRUE)) {
+       if (!_fs_try_alternates(conn, FS_OPEN_TIMEOUT)) {
+           xfree(conn->alts);
+           xfree(conn);
+           return (FSFpePtr) NULL;
+       }
+    }
+    return conn;
+}
+
+Bool
+_fs_reopen_server(conn)
+    FSFpePtr    conn;
+{
+    if (_fs_setup_connection(conn, conn->servername, FS_REOPEN_TIMEOUT, FALSE))
+       return TRUE;
+    if (_fs_try_alternates(conn, FS_REOPEN_TIMEOUT))
+       return TRUE;
+    return FALSE;
+}
+
+/*
+ * expects everything to be here.  *not* to be called when reading huge
+ * numbers of replies, but rather to get each chunk
+ */
+_fs_read(conn, data, size)
+    FSFpePtr    conn;
+    char       *data;
+    unsigned long size;
+{
+    long        bytes_read;
+#if defined(SVR4) && defined(i386)
+    int                num_failed_reads = 0;
+#endif
+
+    if (size == 0) {
+
+#ifdef DEBUG
+       fprintf(stderr, "tried to read 0 bytes \n");
+#endif
+
+       return 0;
+    }
+    ESET(0);
+    /*
+     * For SVR4 with a unix-domain connection, ETEST() after selecting
+     * readable means the server has died.  To do this here, we look for
+     * two consecutive reads returning ETEST().
+     */
+    while ((bytes_read = _FontTransRead(conn->trans_conn,
+       data, (int) size)) != size) {
+       if (bytes_read > 0) {
+           size -= bytes_read;
+           data += bytes_read;
+#if defined(SVR4) && defined(i386)
+           num_failed_reads = 0;
+#endif
+       } else if (ETEST()) {
+           /* in a perfect world, this shouldn't happen */
+           /* ... but then, its less than perfect... */
+           if (_fs_wait_for_readable(conn) == -1) {    /* check for error */
+               _fs_connection_died(conn);
+               ESET(EPIPE);
+               return -1;
+           }
+#if defined(SVR4) && defined(i386)
+           num_failed_reads++;
+           if (num_failed_reads > 1) {
+               _fs_connection_died(conn);
+               ESET(EPIPE);
+               return -1;
+           }
+#endif
+           ESET(0);
+       } else if (ECHECK(EINTR)) {
+#if defined(SVR4) && defined(i386)
+           num_failed_reads = 0;
+#endif
+           continue;
+       } else {                /* something bad happened */
+           if (conn->fs_fd > 0)
+               _fs_connection_died(conn);
+           ESET(EPIPE);
+           return -1;
+       }
+    }
+    return 0;
+}
+
+_fs_write(conn, data, size)
+    FSFpePtr    conn;
+    char       *data;
+    unsigned long size;
+{
+    long        bytes_written;
+
+    if (size == 0) {
+
+#ifdef DEBUG
+       fprintf(stderr, "tried to write 0 bytes \n");
+#endif
+
+       return 0;
+    }
+
+    /* XXX - hack.  The right fix is to remember that the font server
+       has gone away when we first discovered it. */
+    if (!conn->trans_conn)
+       return -1;
+
+    ESET(0);
+    while ((bytes_written = _FontTransWrite(conn->trans_conn,
+       data, (int) size)) != size) {
+       if (bytes_written > 0) {
+           size -= bytes_written;
+           data += bytes_written;
+       } else if (ETEST()) {
+           /* XXX -- we assume this can't happen */
+
+#ifdef DEBUG
+           fprintf(stderr, "fs_write blocking\n");
+#endif
+       } else if (ECHECK(EINTR)) {
+           continue;
+       } else {                /* something bad happened */
+           _fs_connection_died(conn);
+           ESET(EPIPE);
+           return -1;
+       }
+    }
+    return 0;
+}
+
+_fs_read_pad(conn, data, len)
+    FSFpePtr    conn;
+    char       *data;
+    int         len;
+{
+    char        pad[3];
+
+    if (_fs_read(conn, data, len) == -1)
+       return -1;
+
+    /* read the junk */
+    if (padlength[len & 3]) {
+       return _fs_read(conn, pad, padlength[len & 3]);
+    }
+    return 0;
+}
+
+_fs_write_pad(conn, data, len)
+    FSFpePtr    conn;
+    char       *data;
+    int         len;
+{
+    static char pad[3];
+
+    if (_fs_write(conn, data, len) == -1)
+       return -1;
+
+    /* write the pad */
+    if (padlength[len & 3]) {
+       return _fs_write(conn, pad, padlength[len & 3]);
+    }
+    return 0;
+}
+
+/*
+ * returns the amount of data waiting to be read
+ */
+int
+_fs_data_ready(conn)
+    FSFpePtr    conn;
+{
+    BytesReadable_t readable;
+
+    if (_FontTransBytesReadable(conn->trans_conn, &readable) < 0)
+       return -1;
+    return readable;
+}
+
+int
+_fs_wait_for_readable(conn)
+    FSFpePtr    conn;
+{
+#ifndef AMOEBA
+    fd_set r_mask;
+    fd_set e_mask;
+    int         result;
+
+#ifdef DEBUG
+    fprintf(stderr, "read would block\n");
+#endif
+
+    do {
+       FD_ZERO(&r_mask);
+#ifndef MINIX
+       FD_ZERO(&e_mask);
+#endif
+       FD_SET(conn->fs_fd, &r_mask);
+       FD_SET(conn->fs_fd, &e_mask);
+       result = Select(conn->fs_fd + 1, &r_mask, NULL, &e_mask, NULL);
+       if (result == -1) {
+           if (ECHECK(EINTR) || ECHECK(EAGAIN))
+               continue;
+           else
+               return -1;
+       }
+       if (result && FD_ISSET(conn->fs_fd, &e_mask))
+           return -1;
+    } while (result <= 0);
+
+    return 0;
+#else
+    printf("fs_wait_for_readable(): fail\n");
+    return -1;
+#endif
+}
+
+int
+_fs_set_bit(mask, fd)
+    fd_set* mask;
+    int         fd;
+{
+    FD_SET(fd, mask);
+    return fd;
+}
+
+int
+_fs_is_bit_set(mask, fd)
+    fd_set* mask;
+    int         fd;
+{
+    return FD_ISSET(fd, mask);
+}
+
+void
+_fs_bit_clear(mask, fd)
+    fd_set* mask;
+    int         fd;
+{
+    FD_CLR(fd, mask);
+}
+
+int
+_fs_any_bit_set(mask)
+    fd_set* mask;
+{
+    XFD_ANYSET(mask);
+}
+
+int
+_fs_or_bits(dst, m1, m2)
+    fd_set* dst;
+    fd_set* m1;
+    fd_set* m2;
+{
+#ifdef WIN32
+    int i;
+    if (dst != m1) {
+       for (i = m1->fd_count; --i >= 0; ) {
+           if (!FD_ISSET(m1->fd_array[i], dst))
+               FD_SET(m1->fd_array[i], dst);
+       }
+    }
+    if (dst != m2) {
+       for (i = m2->fd_count; --i >= 0; ) {
+           if (!FD_ISSET(m2->fd_array[i], dst))
+               FD_SET(m2->fd_array[i], dst);
+       }
+    }
+#else
+    XFD_ORSET(dst, m1, m2);
+#endif
+}
+
+_fs_drain_bytes(conn, len)
+    FSFpePtr    conn;
+    int         len;
+{
+    char        buf[128];
+
+#ifdef DEBUG
+    fprintf(stderr, "draining wire\n");
+#endif
+
+    while (len > 0) {
+       if (_fs_read(conn, buf, (len < 128) ? len : 128) < 0)
+           return -1;
+       len -= 128;
+    }
+    return 0;
+}
+
+_fs_drain_bytes_pad(conn, len)
+    FSFpePtr    conn;
+    int         len;
+{
+    _fs_drain_bytes(conn, len);
+
+    /* read the junk */
+    if (padlength[len & 3]) {
+       _fs_drain_bytes(conn, padlength[len & 3]);
+    }
+}
+
+_fs_eat_rest_of_error(conn, err)
+    FSFpePtr    conn;
+    fsError    *err;
+{
+    int         len = (err->length - (SIZEOF(fsGenericReply) >> 2)) << 2;
+
+#ifdef DEBUG
+    fprintf(stderr, "clearing error\n");
+#endif
+
+    _fs_drain_bytes(conn, len);
+}
diff --git a/Xserver/lib/font/fc/fsio.h b/Xserver/lib/font/fc/fsio.h
new file mode 100644 (file)
index 0000000..0336c7f
--- /dev/null
@@ -0,0 +1,82 @@
+/* $XConsortium: fsio.h,v 1.12 94/01/31 12:02:17 mor Exp $ */
+/*
+ * Copyright 1990 Network Computing Devices
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the name of Network Computing Devices not be
+ * used in advertising or publicity pertaining to distribution of the
+ * software without specific, written prior permission.  Network Computing
+ * Devices makes no representations about the suitability of this software
+ * for any purpose.  It is provided "as is" without express or implied
+ * warranty.
+ *
+ * NETWORK COMPUTING DEVICES DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
+ * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS,
+ * IN NO EVENT SHALL NETWORK COMPUTING DEVICES BE LIABLE FOR ANY SPECIAL,
+ * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
+ * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
+ * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE
+ * OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ * Author:     Dave Lemke, Network Computing Devices, Inc
+ */
+
+#ifndef        _FSIO_H_
+#define        _FSIO_H_
+
+#define        REQUEST_LOG_SIZE        100
+
+typedef struct _fs_fpe_alternate {
+    char       *name;
+    Bool        subset;
+}           FSFpeAltRec, *FSFpeAltPtr;
+
+
+/* Per client access contexts */
+typedef struct _fs_client_data {
+    pointer                client;
+    struct _fs_client_data  *next;
+    XID                            acid;
+    int                            auth_generation;
+} FSClientRec, *FSClientPtr;
+
+#define FS_RECONNECT_WAIT      5
+#define FS_MAX_RECONNECT_WAIT  80
+
+/* FS specific font FontPathElement data */
+typedef struct _fs_fpe_data {
+    int         fs_fd;
+    int         current_seq;
+    char       *servername;
+    char       *requestedname; /* client's name for this connection */
+
+    int         generation;
+    int         numAlts;
+    int                fsMajorVersion; /* font server major version number */
+    FSFpeAltPtr alts;
+
+    FSClientPtr        clients;
+    XID                curacid;
+#ifdef DEBUG
+    int         reqindex;
+    int         reqbuffer[REQUEST_LOG_SIZE];
+#endif
+
+    int                attemptReconnect;
+
+/* XXX massive crock to get around stupid #include interferences */
+    pointer     blocked_requests;
+/* Data for reconnect - put it here to avoid allocate failure nightmare */
+    long        time_to_try;
+    long        reconnect_delay;
+    struct _fs_fpe_data *next_reconnect;
+    struct _XtransConnInfo *trans_conn; /* transport connection object */
+}           FSFpeRec, *FSFpePtr;
+
+FSFpePtr    _fs_open_server();
+void        _fs_bit_clear();
+
+#endif                         /* _FSIO_H_ */
diff --git a/Xserver/lib/font/fc/fslibos.h b/Xserver/lib/font/fc/fslibos.h
new file mode 100644 (file)
index 0000000..5e1f1a9
--- /dev/null
@@ -0,0 +1,219 @@
+/* $XConsortium: fslibos.h /main/16 1996/11/13 14:45:15 lehors $ */
+/* $XFree86: xc/lib/font/fc/fslibos.h,v 3.3 1996/12/23 06:02:08 dawes Exp $ */
+/*
+ * Copyright 1990 Network Computing Devices;
+ * Portions Copyright 1987 by Digital Equipment Corporation
+ */
+
+/*
+
+Copyright (c) 1987, 1994  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be included
+in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR
+OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall
+not be used in advertising or otherwise to promote the sale, use or
+other dealings in this Software without prior written authorization
+from the X Consortium.
+
+*/
+
+/*
+ * FSlib networking & os include file
+ */
+
+#include <X11/Xtrans.h>
+
+#ifndef WIN32
+
+/*
+ * makedepend screws up on #undef OPEN_MAX, so we define a new symbol
+ */
+
+#ifndef FONT_OPEN_MAX
+
+#ifndef X_NOT_POSIX
+#ifdef _POSIX_SOURCE
+#include <limits.h>
+#else
+#define _POSIX_SOURCE
+#include <limits.h>
+#undef _POSIX_SOURCE
+#endif
+#endif
+#ifndef OPEN_MAX
+#if defined(SVR4) || defined(__EMX__)
+#ifdef SCO325
+#define OPEN_MAX sysconf(_SC_OPEN_MAX)
+#else
+#define OPEN_MAX 256
+#endif
+#else
+#include <sys/param.h>
+#ifndef OPEN_MAX
+#ifdef __OSF1__
+#define OPEN_MAX 256
+#else
+#ifdef NOFILE
+#define OPEN_MAX NOFILE
+#else
+#define OPEN_MAX NOFILES_MAX
+#endif
+#endif
+#endif
+#endif
+#endif
+
+#if OPEN_MAX > 256
+#define FONT_OPEN_MAX 256
+#else
+#define FONT_OPEN_MAX OPEN_MAX
+#endif
+
+#endif /* FONT_OPEN_MAX */
+
+#ifdef WORD64
+#define NMSKBITS 64
+#else
+#define NMSKBITS 32
+#endif
+
+#define MSKCNT ((FONT_OPEN_MAX + NMSKBITS - 1) / NMSKBITS)
+
+typedef unsigned long FdSet[MSKCNT];
+typedef FdSet FdSetPtr;
+
+#if (MSKCNT==1)
+#define BITMASK(i) (1 << (i))
+#define MASKIDX(i) 0
+#endif
+
+#if (MSKCNT>1)
+#define BITMASK(i) (1 << ((i) & (NMSKBITS - 1)))
+#define MASKIDX(i) ((i) / NMSKBITS)
+#endif
+
+#define MASKWORD(buf, i) buf[MASKIDX(i)]
+#define BITSET(buf, i) MASKWORD(buf, i) |= BITMASK(i)
+#define BITCLEAR(buf, i) MASKWORD(buf, i) &= ~BITMASK(i)
+#define GETBIT(buf, i) (MASKWORD(buf, i) & BITMASK(i))
+
+#if (MSKCNT==1)
+#define COPYBITS(src, dst) dst[0] = src[0]
+#define CLEARBITS(buf) buf[0] = 0
+#define MASKANDSETBITS(dst, b1, b2) dst[0] = (b1[0] & b2[0])
+#define ORBITS(dst, b1, b2) dst[0] = (b1[0] | b2[0])
+#define UNSETBITS(dst, b1) (dst[0] &= ~b1[0])
+#define ANYSET(src) (src[0])
+#endif
+
+#if (MSKCNT==2)
+#define COPYBITS(src, dst) { dst[0] = src[0]; dst[1] = src[1]; }
+#define CLEARBITS(buf) { buf[0] = 0; buf[1] = 0; }
+#define MASKANDSETBITS(dst, b1, b2)  {\
+                     dst[0] = (b1[0] & b2[0]);\
+                     dst[1] = (b1[1] & b2[1]); }
+#define ORBITS(dst, b1, b2)  {\
+                     dst[0] = (b1[0] | b2[0]);\
+                     dst[1] = (b1[1] | b2[1]); }
+#define UNSETBITS(dst, b1) {\
+                      dst[0] &= ~b1[0]; \
+                      dst[1] &= ~b1[1]; }
+#define ANYSET(src) (src[0] || src[1])
+#endif
+
+#if (MSKCNT==3)
+#define COPYBITS(src, dst) { dst[0] = src[0]; dst[1] = src[1]; \
+                            dst[2] = src[2]; }
+#define CLEARBITS(buf) { buf[0] = 0; buf[1] = 0; buf[2] = 0; }
+#define MASKANDSETBITS(dst, b1, b2)  {\
+                     dst[0] = (b1[0] & b2[0]);\
+                     dst[1] = (b1[1] & b2[1]);\
+                     dst[2] = (b1[2] & b2[2]); }
+#define ORBITS(dst, b1, b2)  {\
+                     dst[0] = (b1[0] | b2[0]);\
+                     dst[1] = (b1[1] | b2[1]);\
+                     dst[2] = (b1[2] | b2[2]); }
+#define UNSETBITS(dst, b1) {\
+                      dst[0] &= ~b1[0]; \
+                      dst[1] &= ~b1[1]; \
+                      dst[2] &= ~b1[2]; }
+#define ANYSET(src) (src[0] || src[1] || src[2])
+#endif
+
+#if (MSKCNT==4)
+#define COPYBITS(src, dst) dst[0] = src[0]; dst[1] = src[1]; \
+                          dst[2] = src[2]; dst[3] = src[3]
+#define CLEARBITS(buf) buf[0] = 0; buf[1] = 0; buf[2] = 0; buf[3] = 0
+#define MASKANDSETBITS(dst, b1, b2)  \
+                      dst[0] = (b1[0] & b2[0]);\
+                      dst[1] = (b1[1] & b2[1]);\
+                      dst[2] = (b1[2] & b2[2]);\
+                      dst[3] = (b1[3] & b2[3])
+#define ORBITS(dst, b1, b2)  \
+                      dst[0] = (b1[0] | b2[0]);\
+                      dst[1] = (b1[1] | b2[1]);\
+                      dst[2] = (b1[2] | b2[2]);\
+                      dst[3] = (b1[3] | b2[3])
+#define UNSETBITS(dst, b1) \
+                      dst[0] &= ~b1[0]; \
+                      dst[1] &= ~b1[1]; \
+                      dst[2] &= ~b1[2]; \
+                      dst[3] &= ~b1[3]
+#define ANYSET(src) (src[0] || src[1] || src[2] || src[3])
+#endif
+
+#if (MSKCNT>4)
+#define COPYBITS(src, dst) memmove((caddr_t) dst, (caddr_t) src,\
+                                  MSKCNT*sizeof(long))
+#define CLEARBITS(buf) bzero((caddr_t) buf, MSKCNT*sizeof(long))
+#define MASKANDSETBITS(dst, b1, b2)  \
+                     { int cri;                        \
+                       for (cri=MSKCNT; --cri>=0; )    \
+                         dst[cri] = (b1[cri] & b2[cri]); }
+#define ORBITS(dst, b1, b2)  \
+                     { int cri;                        \
+                     for (cri=MSKCNT; --cri>=0; )      \
+                         dst[cri] = (b1[cri] | b2[cri]); }
+#define UNSETBITS(dst, b1) \
+                     { int cri;                        \
+                     for (cri=MSKCNT; --cri>=0; )      \
+                         dst[cri] &= ~b1[cri];  }
+#if (MSKCNT==8)
+#define ANYSET(src) (src[0] || src[1] || src[2] || src[3] || \
+                    src[4] || src[5] || src[6] || src[7])
+#endif
+#endif
+
+#else /* not WIN32 */
+
+#include <X11/Xwinsock.h>
+#include <X11/Xw32defs.h>
+
+typedef fd_set FdSet;
+typedef FdSet *FdSetPtr;
+
+#define CLEARBITS(set) FD_ZERO(&set)
+#define BITSET(set,s) FD_SET(s,&set)
+#define BITCLEAR(set,s) FD_CLR(s,&set)
+#define GETBIT(set,s) FD_ISSET(s,&set)
+#define ANYSET(set) set->fd_count
+
+#endif
diff --git a/Xserver/lib/font/fontfile/Imakefile b/Xserver/lib/font/fontfile/Imakefile
new file mode 100644 (file)
index 0000000..ee45364
--- /dev/null
@@ -0,0 +1,38 @@
+XCOMM $XConsortium: Imakefile /main/14 1996/11/03 19:58:41 kaleb $
+XCOMM $XFree86: xc/lib/font/fontfile/Imakefile,v 3.4 1996/12/26 03:41:32 dawes Exp $
+#include <Server.tmpl>
+#include <vnclibs.def>
+
+   INCLUDES = -I$(FONTINCSRC) -I../include -I$(SERVERSRC)/include $(ZLIB_INCLUDE)
+    HEADERS = 
+#ifdef FontFormatDefines
+FORMAT_DEFS = FontFormatDefines
+#endif
+
+#if GzipFontCompression
+ GUNZIP_SRC = gunzip.c
+ GUNZIP_OBJ = gunzip.o
+  GZIP_DEFS = -DX_GZIP_FONT_COMPRESSION
+#endif
+
+ ATTRIBDEFS = -DFONTDIRATTRIB
+
+    DEFINES = $(ATTRIBDEFS)
+
+
+
+       SRCS = dirfile.c fontdir.c fontfile.c fileio.c fontscale.c \
+              defaults.c bitsource.c register.c renderers.c bufio.c \
+              decompress.c filewr.c printerfont.c ffcheck.c $(GUNZIP_SRC)
+       OBJS = dirfile.o fontdir.o fontfile.o fileio.o fontscale.o \
+              defaults.o bitsource.o register.o renderers.o bufio.o \
+              decompress.o filewr.o printerfont.o ffcheck.o $(GUNZIP_OBJ)
+
+SpecialCObjectRule(fileio,$(ICONFIGFILES),$(GZIP_DEFS))
+
+SubdirLibraryRule($(OBJS))
+NormalLibraryObjectRule()
+NormalLintTarget($(SRCS))
+
+DependTarget()
+
diff --git a/Xserver/lib/font/fontfile/bitsource.c b/Xserver/lib/font/fontfile/bitsource.c
new file mode 100644 (file)
index 0000000..83ec51c
--- /dev/null
@@ -0,0 +1,173 @@
+/* $XConsortium: bitsource.c,v 1.9 94/04/17 20:16:59 gildea Exp $ */
+
+/*
+
+Copyright (c) 1991  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+*/
+
+/*
+ * Author:  Keith Packard, MIT X Consortium
+ */
+
+#include "fntfilst.h"
+
+BitmapSourcesRec       FontFileBitmapSources;
+
+Bool
+FontFileRegisterBitmapSource (fpe)
+    FontPathElementPtr fpe;
+{
+    FontPathElementPtr *new;
+    int                        i;
+    int                        newsize;
+
+    for (i = 0; i < FontFileBitmapSources.count; i++)
+       if (FontFileBitmapSources.fpe[i] == fpe)
+           return TRUE;
+    if (FontFileBitmapSources.count == FontFileBitmapSources.size)
+    {
+       newsize = FontFileBitmapSources.size + 4;
+       new = (FontPathElementPtr *) xrealloc (FontFileBitmapSources.fpe, newsize * sizeof *new);
+       if (!new)
+           return FALSE;
+       FontFileBitmapSources.size = newsize;
+       FontFileBitmapSources.fpe = new;
+    }
+    FontFileBitmapSources.fpe[FontFileBitmapSources.count++] = fpe;
+    return TRUE;
+}
+
+void
+FontFileUnregisterBitmapSource (fpe)
+    FontPathElementPtr fpe;
+{
+    int            i;
+
+    for (i = 0; i < FontFileBitmapSources.count; i++)
+       if (FontFileBitmapSources.fpe[i] == fpe)
+       {
+           FontFileBitmapSources.count--;
+           if (FontFileBitmapSources.count == 0)
+           {
+               FontFileBitmapSources.size = 0;
+               xfree (FontFileBitmapSources.fpe);
+               FontFileBitmapSources.fpe = 0;
+           }
+           else
+           {
+               for (; i < FontFileBitmapSources.count; i++)
+                   FontFileBitmapSources.fpe[i] = FontFileBitmapSources.fpe[i+1];
+           }
+           break;
+       }
+}
+
+/*
+ * Our set_path_hook: unregister all bitmap sources.
+ * This is necessary because already open fonts will keep their FPEs
+ * allocated, but they may not be on the new font path.
+ * The bitmap sources in the new path will be registered by the init_func.
+ */
+void
+FontFileEmptyBitmapSource()
+{
+    if (FontFileBitmapSources.count == 0)
+       return;
+
+    FontFileBitmapSources.count = 0;
+    FontFileBitmapSources.size = 0;
+    xfree (FontFileBitmapSources.fpe);
+    FontFileBitmapSources.fpe = 0;
+}
+
+FontFileMatchBitmapSource (fpe, pFont, flags, entry, zeroPat, vals, format, fmask, noSpecificSize)
+    FontPathElementPtr fpe;
+    FontPtr            *pFont;
+    int                        flags;
+    FontEntryPtr       entry;
+    FontNamePtr                zeroPat;
+    FontScalablePtr    vals;
+    fsBitmapFormat     format;
+    fsBitmapFormatMask fmask;
+    Bool               noSpecificSize;
+{
+    int                        source;
+    FontEntryPtr       zero;
+    FontBitmapEntryPtr bitmap;
+    int                        ret;
+    FontDirectoryPtr   dir;
+    FontScaledPtr      scaled;
+
+    /*
+     * Look through all the registered bitmap sources for
+     * the same zero name as ours; entries along that one
+     * can be scaled as desired.
+     */
+    ret = BadFontName;
+    for (source = 0; source < FontFileBitmapSources.count; source++)
+    {
+       if (FontFileBitmapSources.fpe[source] == fpe)
+           continue;
+       dir = (FontDirectoryPtr) FontFileBitmapSources.fpe[source]->private;
+       zero = FontFileFindNameInDir (&dir->scalable, zeroPat);
+       if (!zero)
+           continue;
+       scaled = FontFileFindScaledInstance (zero, vals, noSpecificSize);
+       if (scaled)
+       {
+           if (scaled->pFont)
+           {
+               *pFont = scaled->pFont;
+               (*pFont)->fpe = FontFileBitmapSources.fpe[source];
+               ret = Successful;
+           }
+           else if (scaled->bitmap)
+           {
+               entry = scaled->bitmap;
+               bitmap = &entry->u.bitmap;
+               if (bitmap->pFont)
+               {
+                   *pFont = bitmap->pFont;
+                   (*pFont)->fpe = FontFileBitmapSources.fpe[source];
+                   ret = Successful;
+               }
+               else
+               {
+                   ret = FontFileOpenBitmap (
+                               FontFileBitmapSources.fpe[source],
+                               pFont, flags, entry, format, fmask);
+                   if (ret == Successful && *pFont)
+                       (*pFont)->fpe = FontFileBitmapSources.fpe[source];
+               }
+           }
+           else /* "cannot" happen */
+           {
+               ret = BadFontName;
+           }
+           break;
+       }
+    }
+    return ret;
+}
diff --git a/Xserver/lib/font/fontfile/bufio.c b/Xserver/lib/font/fontfile/bufio.c
new file mode 100644 (file)
index 0000000..736b76f
--- /dev/null
@@ -0,0 +1,224 @@
+/* $XConsortium: bufio.c,v 1.8 94/04/17 20:17:00 gildea Exp $ */
+/* $XFree86: xc/lib/font/fontfile/bufio.c,v 3.0 1994/12/17 09:41:39 dawes Exp $ */
+
+/*
+
+Copyright (c) 1991  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be included
+in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR
+OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall
+not be used in advertising or otherwise to promote the sale, use or
+other dealings in this Software without prior written authorization
+from the X Consortium.
+
+*/
+
+/*
+ * Author:  Keith Packard, MIT X Consortium
+ */
+
+
+#include <X11/Xos.h>
+#include <fontmisc.h>
+#include <bufio.h>
+#include <errno.h>
+#ifdef X_NOT_STDC_ENV
+extern int errno;
+#endif
+
+BufFilePtr
+BufFileCreate (private, io, skip, close)
+    char    *private;
+    int            (*io)();
+    int            (*skip)();
+    int            (*close)();
+{
+    BufFilePtr f;
+
+    f = (BufFilePtr) xalloc (sizeof *f);
+    if (!f)
+       return 0;
+    f->private = private;
+    f->bufp = f->buffer;
+    f->left = 0;
+    f->io = io;
+    f->skip = skip;
+    f->close = close;
+    return f;
+}
+
+#define FileDes(f)  ((int) (f)->private)
+
+static int
+BufFileRawFill (f)
+    BufFilePtr f;
+{
+    int        left;
+
+    left = read (FileDes(f), (char *)f->buffer, BUFFILESIZE);
+    if (left <= 0) {
+       f->left = 0;
+       return BUFFILEEOF;
+    }
+    f->left = left - 1;
+    f->bufp = f->buffer + 1;
+    return f->buffer[0];
+}
+
+static int
+BufFileRawSkip (f, count)
+    BufFilePtr f;
+    int                count;
+{
+    int            curoff;
+    int            fileoff;
+    int            todo;
+
+    curoff = f->bufp - f->buffer;
+    fileoff = curoff + f->left;
+    if (curoff + count <= fileoff) {
+       f->bufp += count;
+       f->left -= count;
+    } else {
+       todo = count - (fileoff - curoff);
+       if (lseek (FileDes(f), todo, 1) == -1) {
+           if (errno != ESPIPE)
+               return BUFFILEEOF;
+           while (todo) {
+               curoff = BUFFILESIZE;
+               if (curoff > todo)
+                   curoff = todo;
+               fileoff = read (FileDes(f), (char *)f->buffer, curoff);
+               if (fileoff <= 0)
+                   return BUFFILEEOF;
+               todo -= fileoff;
+           }
+       }
+       f->left = 0;
+    }
+    return count;
+}
+
+static int
+BufFileRawClose (f, doClose)
+    BufFilePtr f;
+{
+    if (doClose)
+       close (FileDes (f));
+    return 1;
+}
+
+BufFilePtr
+BufFileOpenRead (fd)
+    int        fd;
+{
+#ifdef __EMX__
+    /* hv: I'd bet WIN32 has the same effect here */
+    setmode(fd,O_BINARY);
+#endif
+    return BufFileCreate ((char *) fd, BufFileRawFill, BufFileRawSkip, BufFileRawClose);
+}
+
+static
+BufFileRawFlush (c, f)
+    int                c;
+    BufFilePtr f;
+{
+    int        cnt;
+
+    if (c != BUFFILEEOF)
+       *f->bufp++ = c;
+    cnt = f->bufp - f->buffer;
+    f->bufp = f->buffer;
+    f->left = BUFFILESIZE;
+    if (write (FileDes(f), (char *)f->buffer, cnt) != cnt)
+       return BUFFILEEOF;
+    return c;
+}
+
+BufFilePtr
+BufFileOpenWrite (fd)
+    int        fd;
+{
+    BufFilePtr f;
+
+#ifdef __EMX__
+    /* hv: I'd bet WIN32 has the same effect here */
+    setmode(fd,O_BINARY);
+#endif
+    f = BufFileCreate ((char *) fd, BufFileRawFlush, 0, BufFileFlush);
+    f->bufp = f->buffer;
+    f->left = BUFFILESIZE;
+    return f;
+}
+
+BufFileRead (f, b, n)
+    BufFilePtr f;
+    char       *b;
+    int                n;
+{
+    int            c, cnt;
+    cnt = n;
+    while (cnt--) {
+       c = BufFileGet (f);
+       if (c == BUFFILEEOF)
+           break;
+       *b++ = c;
+    }
+    return n - cnt - 1;
+}
+
+BufFileWrite (f, b, n)
+    BufFilePtr f;
+    char       *b;
+    int                n;
+{
+    int            cnt;
+    cnt = n;
+    while (cnt--) {
+       if (BufFilePut (*b++, f) == BUFFILEEOF)
+           return BUFFILEEOF;
+    }
+    return n;
+}
+
+int
+BufFileFlush (f)
+    BufFilePtr f;
+{
+    if (f->bufp != f->buffer)
+       (*f->io) (BUFFILEEOF, f);
+}
+
+int
+BufFileClose (f, doClose)
+    BufFilePtr f;
+{
+    (void) (*f->close) (f, doClose);
+    xfree (f);
+}
+
+int
+BufFileFree (f)
+    BufFilePtr f;
+{
+    xfree (f);
+}
diff --git a/Xserver/lib/font/fontfile/decompress.c b/Xserver/lib/font/fontfile/decompress.c
new file mode 100644 (file)
index 0000000..e2fd220
--- /dev/null
@@ -0,0 +1,408 @@
+/* $XConsortium: decompress.c,v 1.6 94/04/17 20:17:00 gildea Exp $ */
+/*
+ * Copyright (c) 1985, 1986 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * James A. Woods, derived from original work by Spencer Thomas
+ * and Joseph Orost.
+ *
+ * Redistribution and use in source and binary forms are permitted
+ * provided that the above copyright notice and this paragraph are
+ * duplicated in all such forms and that any documentation,
+ * advertising materials, and other materials related to such
+ * distribution and use acknowledge that the software was developed
+ * by the University of California, Berkeley.  The name of the
+ * University may not be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
+ * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+ */
+
+/*
+
+Copyright (c) 1993  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+*/
+/* 
+ * decompress - cat a compressed file
+ */
+
+#include "fontmisc.h"
+#include <bufio.h>
+
+#define BITS   16
+
+/*
+ * a code_int must be able to hold 2**BITS values of type int, and also -1
+ */
+#if BITS > 15
+typedef long int       code_int;
+#else
+typedef int            code_int;
+#endif
+
+typedef long int         count_int;
+
+#ifdef NO_UCHAR
+ typedef char  char_type;
+#else
+ typedef       unsigned char   char_type;
+#endif /* UCHAR */
+
+static char_type magic_header[] = { "\037\235" };      /* 1F 9D */
+
+/* Defines for third byte of header */
+#define BIT_MASK       0x1f
+#define BLOCK_MASK     0x80
+/* Masks 0x40 and 0x20 are free.  I think 0x20 should mean that there is
+   a fourth header byte (for expansion).
+*/
+
+#define INIT_BITS 9                    /* initial number of bits/code */
+
+#ifdef COMPATIBLE              /* But wrong! */
+# define MAXCODE(n_bits)       (1 << (n_bits) - 1)
+#else
+# define MAXCODE(n_bits)       ((1 << (n_bits)) - 1)
+#endif /* COMPATIBLE */
+
+static code_int getcode();
+
+/*
+ * the next two codes should not be changed lightly, as they must not
+ * lie within the contiguous general code space.
+ */ 
+#define FIRST  257     /* first free entry */
+#define        CLEAR   256     /* table clear output code */
+
+#define STACK_SIZE  8192
+
+typedef struct _compressedFILE {
+    BufFilePtr     file;
+
+    char_type      *stackp;
+    code_int       oldcode;
+    char_type      finchar;
+
+    int                block_compress;
+    int                maxbits;
+    code_int   maxcode, maxmaxcode;
+
+    code_int   free_ent;
+    int                clear_flg;
+    int                n_bits;
+
+    /* bit buffer */
+    int                offset, size;
+    char_type  buf[BITS];
+
+    char_type      de_stack[STACK_SIZE];
+    char_type      *tab_suffix;
+    unsigned short  *tab_prefix;
+} CompressedFile;
+
+
+static int hsize_table[] = {
+    5003,      /* 12 bits - 80% occupancy */
+    9001,      /* 13 bits - 91% occupancy */
+    18013,     /* 14 bits - 91% occupancy */
+    35023,     /* 15 bits - 94% occupancy */
+    69001      /* 16 bits - 95% occupancy */
+};
+
+static int  BufCompressedFill(), BufCompressedSkip(), BufCompressedClose();
+
+BufFilePtr
+BufFilePushCompressed (f)
+    BufFilePtr f;
+{
+    int                    code;
+    int                    maxbits;
+    int                    hsize;
+    CompressedFile  *file;
+    int                    extra;
+
+    if ((BufFileGet(f) != (magic_header[0] & 0xFF)) ||
+       (BufFileGet(f) != (magic_header[1] & 0xFF)))
+    {
+       return 0;
+    }
+    code = BufFileGet (f);
+    maxbits = code & BIT_MASK;
+    if (maxbits > BITS || maxbits < 12)
+       return 0;
+    hsize = hsize_table[maxbits - 12];
+    extra = (1 << maxbits) * sizeof (char_type) +
+           hsize * sizeof (unsigned short);
+    file = (CompressedFile *) xalloc (sizeof (CompressedFile) + extra);
+    if (!file)
+       return 0;
+    file->file = f;
+    file->maxbits = maxbits;
+    file->block_compress = code & BLOCK_MASK;
+    file->maxmaxcode = 1 << file->maxbits;
+    file->tab_suffix = (char_type *) &file[1];
+    file->tab_prefix = (unsigned short *) (file->tab_suffix + file->maxmaxcode);
+    /*
+     * As above, initialize the first 256 entries in the table.
+     */
+    file->maxcode = MAXCODE(file->n_bits = INIT_BITS);
+    for ( code = 255; code >= 0; code-- ) {
+       file->tab_prefix[code] = 0;
+       file->tab_suffix[code] = (char_type) code;
+    }
+    file->free_ent = ((file->block_compress) ? FIRST : 256 );
+    file->clear_flg = 0;
+    file->offset = 0;
+    file->size = 0;
+    file->stackp = file->de_stack;
+    file->finchar = file->oldcode = getcode (file);
+    if (file->oldcode != -1)
+       *file->stackp++ = file->finchar;
+    return BufFileCreate ((char *) file,
+                         BufCompressedFill,
+                         BufCompressedSkip,
+                         BufCompressedClose);
+}
+
+static int
+BufCompressedClose (f, doClose)
+    BufFilePtr f;
+{
+    CompressedFile  *file;
+    BufFilePtr     raw;
+
+    file = (CompressedFile *) f->private;
+    raw = file->file;
+    xfree (file);
+    BufFileClose (raw, doClose);
+    return 1;
+}
+
+static int
+BufCompressedFill (f)
+    BufFilePtr     f;
+{
+    CompressedFile  *file;
+    register char_type *stackp, *de_stack;
+    register char_type finchar;
+    register code_int code, oldcode, incode;
+    BufChar        *buf, *bufend;
+
+    file = (CompressedFile *) f->private;
+
+    buf = f->buffer;
+    bufend = buf + BUFFILESIZE;
+    stackp = file->stackp;
+    de_stack = file->de_stack;
+    finchar = file->finchar;
+    oldcode = file->oldcode;
+    while (buf < bufend) {
+       while (stackp > de_stack && buf < bufend)
+           *buf++ = *--stackp;
+
+       if (buf == bufend)
+           break;
+
+       if (oldcode == -1)
+           break;
+
+       code = getcode (file);
+       if (code == -1)
+           break;
+    
+       if ( (code == CLEAR) && file->block_compress ) {
+           for ( code = 255; code >= 0; code-- )
+               file->tab_prefix[code] = 0;
+           file->clear_flg = 1;
+           file->free_ent = FIRST - 1;
+           if ( (code = getcode (file)) == -1 )        /* O, untimely death! */
+               break;
+       }
+       incode = code;
+       /*
+        * Special case for KwKwK string.
+        */
+       if ( code >= file->free_ent ) {
+           *stackp++ = finchar;
+           code = oldcode;
+       }
+    
+       /*
+        * Generate output characters in reverse order
+        */
+       while ( code >= 256 )
+       {
+           *stackp++ = file->tab_suffix[code];
+           code = file->tab_prefix[code];
+       }
+       finchar = file->tab_suffix[code];
+       *stackp++ = finchar;
+    
+       /*
+        * Generate the new entry.
+        */
+       if ( (code=file->free_ent) < file->maxmaxcode ) {
+           file->tab_prefix[code] = (unsigned short)oldcode;
+           file->tab_suffix[code] = finchar;
+           file->free_ent = code+1;
+       } 
+       /*
+        * Remember previous code.
+        */
+       oldcode = incode;
+    }
+    file->oldcode = oldcode;
+    file->stackp = stackp;
+    file->finchar = finchar;
+    if (buf == f->buffer) {
+       f->left = 0;
+       return BUFFILEEOF;
+    }
+    f->bufp = f->buffer + 1;
+    f->left = (buf - f->buffer) - 1;
+    return f->buffer[0];
+}
+
+/*****************************************************************
+ * TAG( getcode )
+ *
+ * Read one code from the standard input.  If BUFFILEEOF, return -1.
+ * Inputs:
+ *     stdin
+ * Outputs:
+ *     code or -1 is returned.
+ */
+
+static char_type rmask[9] = {0x00, 0x01, 0x03, 0x07, 0x0f, 0x1f, 0x3f, 0x7f, 0xff};
+
+static code_int
+getcode(file)
+    CompressedFile  *file;
+{
+    register code_int code;
+    register int r_off, bits;
+    register char_type *bp = file->buf;
+    register BufFilePtr        raw;
+
+    if ( file->clear_flg > 0 || file->offset >= file->size ||
+       file->free_ent > file->maxcode )
+    {
+       /*
+        * If the next entry will be too big for the current code
+        * size, then we must increase the size.  This implies reading
+        * a new buffer full, too.
+        */
+       if ( file->free_ent > file->maxcode ) {
+           file->n_bits++;
+           if ( file->n_bits == file->maxbits )
+               file->maxcode = file->maxmaxcode;       /* won't get any bigger now */
+           else
+               file->maxcode = MAXCODE(file->n_bits);
+       }
+       if ( file->clear_flg > 0) {
+           file->maxcode = MAXCODE (file->n_bits = INIT_BITS);
+           file->clear_flg = 0;
+       }
+       bits = file->n_bits;
+       raw = file->file;
+       while (bits > 0 && (code = BufFileGet (raw)) != BUFFILEEOF)
+       {
+           *bp++ = code;
+           --bits;
+       }
+       bp = file->buf;
+       if (bits == file->n_bits)
+           return -1;                  /* end of file */
+       file->size = file->n_bits - bits;
+       file->offset = 0;
+       /* Round size down to integral number of codes */
+       file->size = (file->size << 3) - (file->n_bits - 1);
+    }
+    r_off = file->offset;
+    bits = file->n_bits;
+    /*
+     * Get to the first byte.
+     */
+    bp += (r_off >> 3);
+    r_off &= 7;
+    /* Get first part (low order bits) */
+#ifdef NO_UCHAR
+    code = ((*bp++ >> r_off) & rmask[8 - r_off]) & 0xff;
+#else
+    code = (*bp++ >> r_off);
+#endif /* NO_UCHAR */
+    bits -= (8 - r_off);
+    r_off = 8 - r_off;         /* now, offset into code word */
+    /* Get any 8 bit parts in the middle (<=1 for up to 16 bits). */
+    if ( bits >= 8 ) {
+#ifdef NO_UCHAR
+       code |= (*bp++ & 0xff) << r_off;
+#else
+       code |= *bp++ << r_off;
+#endif /* NO_UCHAR */
+       r_off += 8;
+       bits -= 8;
+    }
+    /* high order bits. */
+    code |= (*bp & rmask[bits]) << r_off;
+    file->offset += file->n_bits;
+
+    return code;
+}
+
+static int
+BufCompressedSkip (f, bytes)
+    BufFilePtr f;
+    int                bytes;
+{
+    int                    c;
+    while (bytes--) 
+    {
+       c = BufFileGet(f);
+       if (c == BUFFILEEOF)
+           return BUFFILEEOF;
+    }
+    return 0;
+}
+
+#ifdef TEST
+main (argc, argv)
+    int            argc;
+    char    **argv;
+{
+    BufFilePtr     inputraw, input, output;
+    int                    c;
+    
+    inputraw = BufFileOpenRead (0);
+    input = BufFilePushCompressed (inputraw);
+    output = BufFileOpenWrite (1);
+    while ((c = BufFileGet (input)) != -1)
+       BufFilePut (c, output);
+    BufFileClose (input, FALSE);
+    BufFileClose (output, FALSE);
+}
+#endif
diff --git a/Xserver/lib/font/fontfile/defaults.c b/Xserver/lib/font/fontfile/defaults.c
new file mode 100644 (file)
index 0000000..91fa77e
--- /dev/null
@@ -0,0 +1,73 @@
+/* $XConsortium: defaults.c,v 1.3 94/04/17 20:17:01 rws Exp $ */
+
+/*
+
+Copyright (c) 1990  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+*/
+
+/*
+ * Author:  Keith Packard, MIT X Consortium
+ */
+
+#include    <X11/X.h>
+#include    <X11/Xproto.h>
+#include    <servermd.h>
+
+#ifndef DEFAULT_BIT_ORDER
+#ifdef BITMAP_BIT_ORDER
+#define DEFAULT_BIT_ORDER BITMAP_BIT_ORDER
+#else
+#define DEFAULT_BIT_ORDER MSBFirst
+#endif
+#endif
+
+#ifndef DEFAULT_BYTE_ORDER
+#ifdef IMAGE_BYTE_ORDER
+#define DEFAULT_BYTE_ORDER IMAGE_BYTE_ORDER
+#else
+#define DEFAULT_BYTE_ORDER MSBFirst
+#endif
+#endif
+
+#ifndef DEFAULT_GLYPH_PAD
+#ifdef GLYPHPADBYTES
+#define DEFAULT_GLYPH_PAD GLYPHPADBYTES
+#else
+#define DEFAULT_GLYPH_PAD 4
+#endif
+#endif
+
+#ifndef DEFAULT_SCAN_UNIT
+#define DEFAULT_SCAN_UNIT 1
+#endif
+
+FontDefaultFormat (bit, byte, glyph, scan)
+    int            *bit, *byte, *glyph, *scan;
+{
+    *bit = DEFAULT_BIT_ORDER;
+    *byte = DEFAULT_BYTE_ORDER;
+    *glyph = DEFAULT_GLYPH_PAD;
+    *scan = DEFAULT_SCAN_UNIT;
+}
diff --git a/Xserver/lib/font/fontfile/dirfile.c b/Xserver/lib/font/fontfile/dirfile.c
new file mode 100644 (file)
index 0000000..bf14547
--- /dev/null
@@ -0,0 +1,486 @@
+/* $XFree86: xc/lib/font/fontfile/dirfile.c,v 3.3 1997/01/27 06:56:28 dawes Exp $ */
+#ifndef lint
+static char *rid=
+    "$XConsortium: dirfile.c /main/12 1995/12/08 19:02:23 gildea $";
+#endif /* lint */
+
+/*
+
+Copyright (c) 1991  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+*/
+
+/*
+ * Author:  Keith Packard, MIT X Consortium
+ */
+
+/*
+ * dirfile.c
+ *
+ * Read fonts.dir and fonts.alias files
+ */
+
+#include "fntfilst.h"
+#include <stdio.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <errno.h>
+#ifdef X_NOT_STDC_ENV
+extern int errno;
+#endif
+
+static int ReadFontAlias();
+
+int
+FontFileReadDirectory (directory, pdir)
+    char               *directory;
+    FontDirectoryPtr   *pdir;
+{
+    char        file_name[MAXFONTNAMELEN];
+    char        font_name[MAXFONTNAMELEN];
+    char        dir_file[MAXFONTNAMELEN];
+#ifdef FONTDIRATTRIB
+    char       dir_path[MAXFONTNAMELEN];
+    char       *ptr;
+#endif
+    FILE       *file;
+    int         count,
+                i,
+                status;
+    struct stat        statb;
+
+    FontDirectoryPtr   dir = NullFontDirectory;
+
+#ifdef FONTDIRATTRIB
+    /* Check for font directory attributes */
+#ifndef __EMX__
+    if (ptr = strchr(directory, ':')) {
+#else
+    /* OS/2 path might start with a drive letter, don't clip this */
+    if (ptr = strchr(directory+2, ':')) {
+#endif
+       strncpy(dir_path, directory, ptr - directory);
+       dir_path[ptr - directory] = '\0';
+    } else {
+       strcpy(dir_path, directory);
+    }
+    strcpy(dir_file, dir_path);
+#else
+    strcpy(dir_file, directory);
+#endif
+    if (dir_file[strlen(dir_file) - 1] != '/')
+       strcat(dir_file, "/");
+    strcat(dir_file, FontDirFile);
+    file = fopen(dir_file, "r");
+    if (file) {
+       if (fstat (fileno(file), &statb) == -1)
+           return BadFontPath;
+       count = fscanf(file, "%d\n", &i);
+       if ((count == EOF) || (count != 1)) {
+           fclose(file);
+           return BadFontPath;
+       }
+       dir = FontFileMakeDir(directory, i);
+       if (dir == NULL) {
+           fclose(file);
+           return BadFontPath;
+       }
+       dir->dir_mtime = statb.st_mtime;
+       while ((count = fscanf(file, "%s %[^\n]\n", file_name, font_name)) != EOF) {
+#ifdef __EMX__
+           /* strip any existing trailing CR */
+           for (i=0; i<strlen(font_name); i++) {
+               if (font_name[i]=='\r') font_name[i] = '\0';
+           }
+#endif
+           if (count != 2) {
+               FontFileFreeDir (dir);
+               fclose(file);
+               return BadFontPath;
+           }
+           if (!FontFileAddFontFile (dir, font_name, file_name))
+           {
+               FontFileFreeDir (dir);
+               fclose(file);
+               return BadFontPath;
+           }
+       }
+       fclose(file);
+    } else if (errno != ENOENT) {
+       return BadFontPath;
+    }
+#ifdef FONTDIRATTRIB
+    status = ReadFontAlias(dir_path, FALSE, &dir);
+#else
+    status = ReadFontAlias(directory, FALSE, &dir);
+#endif
+    if (status != Successful) {
+       if (dir)
+           FontFileFreeDir (dir);
+       return status;
+    }
+    if (!dir) {
+        /*** TJR - dirty hack - this variable is set in
+            programs/Xserver/dix/dixfont.c when setting default font path  */
+       extern int settingDefaultFontPath;
+       if (settingDefaultFontPath) {
+           fprintf(stderr,"Font directory '%s' not found - ignoring\n",
+                   directory);
+           dir = FontFileMakeDir(directory, 0);
+       }
+
+       if (!dir)
+           return BadFontPath;
+    }
+
+    FontFileSortDir(dir);
+
+    *pdir = dir;
+    return Successful;
+}
+
+Bool
+FontFileDirectoryChanged(dir)
+    FontDirectoryPtr   dir;
+{
+    char       dir_file[MAXFONTNAMELEN];
+    struct stat        statb;
+
+    strcpy (dir_file, dir->directory);
+    strcat (dir_file, FontDirFile);
+    if (stat (dir_file, &statb) == -1)
+    {
+       if (errno != ENOENT || dir->dir_mtime != 0)
+           return TRUE;
+       return FALSE;           /* doesn't exist and never did: no change */
+    }
+    if (dir->dir_mtime != statb.st_mtime)
+       return TRUE;
+    strcpy (dir_file, dir->directory);
+    strcat (dir_file, FontAliasFile);
+    if (stat (dir_file, &statb) == -1)
+    {
+       if (errno != ENOENT || dir->alias_mtime != 0)
+           return TRUE;
+       return FALSE;           /* doesn't exist and never did: no change */
+    }
+    if (dir->alias_mtime != statb.st_mtime)
+       return TRUE;
+    return FALSE;
+}
+    
+/*
+ * Make each of the file names an automatic alias for each of the files.
+ */
+
+static Bool
+AddFileNameAliases(dir)
+    FontDirectoryPtr   dir;
+{
+    int                    i;
+    char           copy[MAXFONTNAMELEN];
+    char           *fileName;
+    FontTablePtr    table;
+    FontRendererPtr renderer;
+    int                    len;
+    FontNameRec            name;
+
+    table = &dir->nonScalable;
+    for (i = 0; i < table->used; i++) {
+       if (table->entries[i].type != FONT_ENTRY_BITMAP)
+           continue;
+       fileName = table->entries[i].u.bitmap.fileName;
+       renderer = FontFileMatchRenderer (fileName);
+       if (!renderer)
+           continue;
+       
+       len = strlen (fileName) - renderer->fileSuffixLen;
+       CopyISOLatin1Lowered (copy, fileName, len);
+       copy[len] = '\0';
+       name.name = copy;
+       name.length = len;
+       name.ndashes = FontFileCountDashes (copy, len);
+
+       if (!FontFileFindNameInDir(table, &name)) {
+           if (!FontFileAddFontAlias (dir, copy, table->entries[i].name.name))
+               return FALSE;
+       }
+    }
+    return TRUE;
+}
+
+/*
+ * parse the font.alias file.  Format is:
+ *
+ * alias font-name
+ *
+ * To imbed white-space in an alias name, enclose it like "font name"
+ * in double quotes.  \ escapes and character, so
+ * "font name \"With Double Quotes\" \\ and \\ back-slashes"
+ * works just fine.
+ *
+ * A line beginning with a ! denotes a newline-terminated comment.
+ */
+
+/*
+ * token types
+ */
+
+static int  lexAlias(), lexc();
+
+#define NAME           0
+#define NEWLINE                1
+#define DONE           2
+#define EALLOC         3
+
+static int
+ReadFontAlias(directory, isFile, pdir)
+    char               *directory;
+    Bool               isFile;
+    FontDirectoryPtr   *pdir;
+{
+    char               alias[MAXFONTNAMELEN];
+    char               font_name[MAXFONTNAMELEN];
+    char               alias_file[MAXFONTNAMELEN];
+    FILE               *file;
+    FontDirectoryPtr   dir;
+    int                        token;
+    char               *lexToken;
+    int                        status = Successful;
+    struct stat                statb;
+
+    dir = *pdir;
+    strcpy(alias_file, directory);
+    if (!isFile) {
+       if (directory[strlen(directory) - 1] != '/')
+           strcat(alias_file, "/");
+       strcat(alias_file, FontAliasFile);
+    }
+    file = fopen(alias_file, "r");
+    if (!file)
+       return ((errno == ENOENT) ? Successful : BadFontPath);
+    if (!dir)
+       *pdir = dir = FontFileMakeDir(directory, 10);
+    if (!dir)
+    {
+       fclose (file);
+       return AllocError;
+    }
+    if (fstat (fileno (file), &statb) == -1)
+    {
+       fclose (file);
+       return BadFontPath;
+    }
+    dir->alias_mtime = statb.st_mtime;
+    while (status == Successful) {
+       token = lexAlias(file, &lexToken);
+       switch (token) {
+       case NEWLINE:
+           break;
+       case DONE:
+           fclose(file);
+           return Successful;
+       case EALLOC:
+           status = AllocError;
+           break;
+       case NAME:
+           strcpy(alias, lexToken);
+           token = lexAlias(file, &lexToken);
+           switch (token) {
+           case NEWLINE:
+               if (strcmp(alias, "FILE_NAMES_ALIASES"))
+                   status = BadFontPath;
+               else if (!AddFileNameAliases(dir))
+                   status = AllocError;
+               break;
+           case DONE:
+               status = BadFontPath;
+               break;
+           case EALLOC:
+               status = AllocError;
+               break;
+           case NAME:
+               CopyISOLatin1Lowered((unsigned char *) alias,
+                                    (unsigned char *) alias,
+                                    strlen(alias));
+               CopyISOLatin1Lowered((unsigned char *) font_name,
+                                    (unsigned char *) lexToken,
+                                    strlen(lexToken));
+               if (!FontFileAddFontAlias (dir, alias, font_name))
+                   status = AllocError;
+               break;
+           }
+       }
+    }
+    fclose(file);
+    return status;
+}
+
+#define QUOTE          0
+#define WHITE          1
+#define NORMAL         2
+#define END            3
+#define NL             4
+#define BANG           5
+
+static int  charClass;
+
+static int
+lexAlias(file, lexToken)
+    FILE       *file;
+    char      **lexToken;
+{
+    int         c;
+    char       *t;
+    enum state {
+       Begin, Normal, Quoted, Comment
+    }           state;
+    int         count;
+
+    static char *tokenBuf = (char *) NULL;
+    static int  tokenSize = 0;
+
+    t = tokenBuf;
+    count = 0;
+    state = Begin;
+    for (;;) {
+       if (count == tokenSize) {
+           int         nsize;
+           char       *nbuf;
+
+           nsize = tokenSize ? (tokenSize << 1) : 64;
+           nbuf = (char *) xrealloc(tokenBuf, nsize);
+           if (!nbuf)
+               return EALLOC;
+           tokenBuf = nbuf;
+           tokenSize = nsize;
+           t = tokenBuf + count;
+       }
+       c = lexc(file);
+       switch (charClass) {
+       case QUOTE:
+           switch (state) {
+           case Begin:
+           case Normal:
+               state = Quoted;
+               break;
+           case Quoted:
+               state = Normal;
+               break;
+           case Comment:
+               break;
+           }
+           break;
+       case WHITE:
+           switch (state) {
+           case Begin:
+           case Comment:
+               continue;
+           case Normal:
+               *t = '\0';
+               *lexToken = tokenBuf;
+               return NAME;
+           case Quoted:
+               break;
+           }
+           /* fall through */
+       case NORMAL:
+           switch (state) {
+           case Begin:
+               state = Normal;
+               break;
+           case Comment:
+               continue;
+           }
+           *t++ = c;
+           ++count;
+           break;
+       case END:
+       case NL:
+           switch (state) {
+           case Begin:
+           case Comment:
+               *lexToken = (char *) NULL;
+               return charClass == END ? DONE : NEWLINE;
+           default:
+               *t = '\0';
+               *lexToken = tokenBuf;
+               ungetc(c, file);
+               return NAME;
+           }
+           break;
+       case BANG:
+           switch (state) {
+           case Begin:
+               state = Comment;
+               break;
+            case Comment:
+               break;
+            default:
+               *t++ = c;
+               ++count;
+           }
+           break;
+       }
+    }
+}
+
+static int
+lexc(file)
+    FILE       *file;
+{
+    int         c;
+
+    c = getc(file);
+    switch (c) {
+    case EOF:
+       charClass = END;
+       break;
+    case '\\':
+       c = getc(file);
+       if (c == EOF)
+           charClass = END;
+       else
+           charClass = NORMAL;
+       break;
+    case '"':
+       charClass = QUOTE;
+       break;
+    case ' ':
+    case '\t':
+       charClass = WHITE;
+       break;
+    case '\r':
+    case '\n':
+       charClass = NL;
+       break;
+    case '!':
+       charClass = BANG;
+       break;
+    default:
+       charClass = NORMAL;
+       break;
+    }
+    return c;
+}
diff --git a/Xserver/lib/font/fontfile/ffcheck.c b/Xserver/lib/font/fontfile/ffcheck.c
new file mode 100644 (file)
index 0000000..09d5153
--- /dev/null
@@ -0,0 +1,173 @@
+/* $XConsortium: ffcheck.c /main/1 1996/09/28 16:48:58 rws $ */
+
+/*
+
+Copyright (c) 1991  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+*/
+
+/*
+ * Author:  Keith Packard, MIT X Consortium
+ */
+/* $NCDId: @(#)fontfile.c,v 1.6 1991/07/02 17:00:46 lemke Exp $ */
+
+#include    "fntfilst.h"
+
+/*
+ * Map FPE functions to renderer functions
+ */
+
+extern int FontFileNameCheck();
+extern int FontFileInitFPE();
+extern int FontFileResetFPE();
+extern int FontFileFreeFPE();
+extern void FontFileCloseFont();
+
+
+/* Here we must check the client to see if it has a context attached to
+ * it that allows us to access the printer fonts
+ */
+
+int
+FontFileCheckOpenFont (client, fpe, flags, name, namelen, format, fmask,
+                 id, pFont, aliasName, non_cachable_font)
+    pointer            client;
+    FontPathElementPtr fpe;
+    int                        flags;
+    char               *name;
+    int                        namelen;
+    fsBitmapFormat     format;
+    fsBitmapFormatMask fmask;
+    XID                        id;
+    FontPtr            *pFont;
+    char               **aliasName;
+    FontPtr            non_cachable_font;
+{
+    if (XpClientIsBitmapClient(client))
+       return (FontFileOpenFont  (client, fpe, flags, name, namelen, format, 
+               fmask, id, pFont, aliasName, non_cachable_font));
+    return BadFontName;
+}
+
+FontFileCheckListFonts (client, fpe, pat, len, max, names)
+    pointer     client;
+    FontPathElementPtr fpe;
+    char       *pat;
+    int         len;
+    int         max;
+    FontNamesPtr names;
+{
+    if (XpClientIsBitmapClient(client))
+       return FontFileListFonts (client, fpe, pat, len, max, names);
+    return BadFontName;
+}
+
+FontFileCheckStartListFontsWithInfo(client, fpe, pat, len, max, privatep)
+    pointer     client;
+    FontPathElementPtr fpe;
+    char       *pat;
+    int         len;
+    int         max;
+    pointer    *privatep;
+{
+    if (XpClientIsBitmapClient(client))
+       return FontFileStartListFontsWithInfo(client, fpe, pat, len, 
+                               max, privatep);
+    return BadFontName;
+}
+
+FontFileCheckListNextFontWithInfo(client, fpe, namep, namelenp, pFontInfo,
+                            numFonts, private)
+    pointer            client;
+    FontPathElementPtr fpe;
+    char               **namep;
+    int                        *namelenp;
+    FontInfoPtr                *pFontInfo;
+    int                        *numFonts;
+    pointer            private;
+{
+    if (XpClientIsBitmapClient(client))
+       return FontFileListNextFontWithInfo(client, fpe, namep, namelenp, 
+                               pFontInfo, numFonts, private);
+    return BadFontName;
+}
+
+FontFileCheckStartListFontsAndAliases(client, fpe, pat, len, max, privatep)
+    pointer     client;
+    FontPathElementPtr fpe;
+    char       *pat;
+    int         len;
+    int         max;
+    pointer    *privatep;
+{
+    if (XpClientIsBitmapClient(client))
+       return FontFileStartListFontsAndAliases(client, fpe, pat, len, 
+                               max, privatep);
+    return BadFontName;
+}
+
+int
+FontFileCheckListNextFontOrAlias(client, fpe, namep, namelenp, resolvedp,
+                           resolvedlenp, private)
+    pointer            client;
+    FontPathElementPtr fpe;
+    char               **namep;
+    int                        *namelenp;
+    char               **resolvedp;
+    int                        *resolvedlenp;
+    pointer            private;
+{
+    if (XpClientIsBitmapClient(client))
+       return FontFileListNextFontOrAlias(client, fpe, namep, namelenp, 
+                               resolvedp, resolvedlenp, private);
+    return BadFontName;
+}
+
+extern void FontFileEmptyBitmapSource();
+typedef int (*IntFunc) ();
+static int  font_file_check_type;
+
+FontFileCheckRegisterFpeFunctions ()
+{
+    BitmapRegisterFontFileFunctions ();
+#ifndef CRAY
+    SpeedoRegisterFontFileFunctions ();
+    Type1RegisterFontFileFunctions();
+#endif
+    RegisterFPEFunctions(FontFileNameCheck,
+                                 FontFileInitFPE,
+                                 FontFileFreeFPE,
+                                 FontFileResetFPE,
+                                 FontFileCheckOpenFont,
+                                 FontFileCloseFont,
+                                 FontFileCheckListFonts,
+                                 FontFileCheckStartListFontsWithInfo,
+                                 FontFileCheckListNextFontWithInfo,
+                                 (IntFunc) 0,
+                                 (IntFunc) 0,
+                                 (IntFunc) 0,
+                                 FontFileCheckStartListFontsAndAliases,
+                                 FontFileCheckListNextFontOrAlias,
+                                 FontFileEmptyBitmapSource);
+}
diff --git a/Xserver/lib/font/fontfile/fileio.c b/Xserver/lib/font/fontfile/fileio.c
new file mode 100644 (file)
index 0000000..39babca
--- /dev/null
@@ -0,0 +1,89 @@
+/* $XConsortium: fileio.c /main/5 1996/11/03 19:32:03 kaleb $ */
+/* $XFree86: xc/lib/font/fontfile/fileio.c,v 3.1 1996/12/23 06:02:20 dawes Exp $ */
+
+/*
+
+Copyright (c) 1991  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+*/
+
+/*
+ * Author:  Keith Packard, MIT X Consortium
+ */
+
+#include <fntfilio.h>
+#include <X11/Xos.h>
+#ifndef O_BINARY
+#define O_BINARY 0
+#endif
+
+FontFilePtr
+FontFileOpen (name)
+    char    *name;
+{
+    int                fd;
+    int                len;
+    BufFilePtr raw, cooked;
+
+    fd = open (name, O_BINARY);
+    if (fd < 0)
+       return 0;
+    raw = BufFileOpenRead (fd);
+    if (!raw)
+    {
+       close (fd);
+       return 0;
+    }
+    len = strlen (name);
+#ifndef __EMX__
+    if (len > 2 && !strcmp (name + len - 2, ".Z")) {
+#else
+    if (len > 2 && (!strcmp (name + len - 4, ".pcz") || 
+                   !strcmp (name + len - 2, ".Z"))) {
+#endif
+       cooked = BufFilePushCompressed (raw);
+       if (!cooked) {
+           BufFileClose (raw, TRUE);
+           return 0;
+       }
+       raw = cooked;
+#ifdef X_GZIP_FONT_COMPRESSION
+    } else if (len > 3 && !strcmp (name + len - 3, ".gz")) {
+       cooked = BufFilePushZIP (raw);
+       if (!cooked) {
+           BufFileClose (raw, TRUE);
+           return 0;
+       }
+       raw = cooked;
+#endif
+    }
+    return (FontFilePtr) raw;
+}
+
+FontFileClose (f)
+    FontFilePtr        f;
+{
+    BufFileClose ((BufFilePtr) f, TRUE);
+}
+
diff --git a/Xserver/lib/font/fontfile/filewr.c b/Xserver/lib/font/fontfile/filewr.c
new file mode 100644 (file)
index 0000000..df32791
--- /dev/null
@@ -0,0 +1,65 @@
+/* $XConsortium: filewr.c,v 1.4 94/04/17 20:17:05 gildea Exp $ */
+/* $XFree86: xc/lib/font/fontfile/filewr.c,v 3.0 1994/12/17 09:41:42 dawes Exp $ */
+
+/*
+
+Copyright (c) 1991  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+*/
+
+/*
+ * Author:  Keith Packard, MIT X Consortium
+ */
+
+#include <fntfilio.h>
+#include <X11/Xos.h>
+
+FontFilePtr
+FontFileOpenWrite (name)
+    char    *name;
+{
+    int        fd;
+
+#if defined(WIN32) || defined(__EMX__)
+    fd = open (name, O_CREAT|O_TRUNC|O_RDWR|O_BINARY, 0666);
+#else
+    fd = creat (name, 0666);
+#endif
+    if (fd < 0)
+       return 0;
+    return (FontFilePtr) BufFileOpenWrite (fd);
+}
+
+FontFilePtr
+FontFileOpenWriteFd (fd)
+{
+    return (FontFilePtr) BufFileOpenWrite (fd);
+}
+
+FontFilePtr
+FontFileOpenFd (fd)
+    int        fd;
+{
+    return (FontFilePtr) BufFileOpenRead (fd);
+}
diff --git a/Xserver/lib/font/fontfile/fontdir.c b/Xserver/lib/font/fontfile/fontdir.c
new file mode 100644 (file)
index 0000000..a763e3c
--- /dev/null
@@ -0,0 +1,812 @@
+/* $XConsortium: fontdir.c /main/24 1996/09/28 16:49:04 rws $ */
+/* $XFree86: xc/lib/font/fontfile/fontdir.c,v 3.7 1996/12/23 06:02:21 dawes Exp $ */
+
+/*
+
+Copyright (c) 1991  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+*/
+
+/*
+ * Author:  Keith Packard, MIT X Consortium
+ */
+
+#include    "fntfilst.h"
+#include    <X11/keysym.h>
+
+Bool
+FontFileInitTable (table, size)
+    FontTablePtr    table;
+    int                    size;
+{
+    if (size)
+    {
+       table->entries = (FontEntryPtr) xalloc(sizeof(FontEntryRec) * size);
+       if (!table->entries)
+           return FALSE;
+    }
+    else
+       table->entries = 0;
+    table->used = 0;
+    table->size = size;
+    table->sorted = FALSE;
+    return TRUE;
+}
+
+FontFileFreeEntry (entry)
+    FontEntryPtr    entry;
+{
+    FontScalableExtraPtr   extra;
+    int i;
+
+    if (entry->name.name)
+       xfree(entry->name.name);
+
+    switch (entry->type)
+    {
+    case FONT_ENTRY_SCALABLE:
+       xfree (entry->u.scalable.fileName);
+       extra = entry->u.scalable.extra;
+       for (i = 0; i < extra->numScaled; i++)
+           if (extra->scaled[i].vals.ranges)
+               xfree (extra->scaled[i].vals.ranges);
+       xfree (extra->scaled);
+       xfree (extra);
+       break;
+    case FONT_ENTRY_BITMAP:
+       xfree (entry->u.bitmap.fileName);
+       break;
+    case FONT_ENTRY_ALIAS:
+       xfree (entry->u.alias.resolved);
+       break;
+#ifdef NOTYET
+    case FONT_ENTRY_BC:
+       break;
+#endif
+    }
+}
+
+FontFileFreeTable (table)
+    FontTablePtr    table;
+{
+    int        i;
+
+    for (i = 0; i < table->used; i++)
+       FontFileFreeEntry (&table->entries[i]);
+    xfree (table->entries);
+}
+
+FontDirectoryPtr
+FontFileMakeDir(dirName, size)
+    char       *dirName;
+    int         size;
+{
+    FontDirectoryPtr   dir;
+    int                        dirlen;
+    int                        needslash = 0;
+#ifdef FONTDIRATTRIB
+    char               *attrib;
+    int                        attriblen;
+#endif
+
+#ifdef FONTDIRATTRIB
+#ifndef __EMX__
+    attrib = strchr(dirName, ':');
+#else
+    /* OS/2 uses the colon in the drive letter descriptor, skip this */
+    attrib = strchr(dirName+2, ':');
+#endif
+    if (attrib) {
+       dirlen = attrib - dirName;
+       attriblen = strlen(attrib);
+    } else {
+       dirlen = strlen(dirName);
+       attriblen = 0;
+    }
+#else
+    dirlen = strlen(dirName);
+#endif
+    if (dirName[dirlen - 1] != '/')
+#ifdef NCD
+    if (dirlen)     /* leave out slash for builtins */
+#endif
+       needslash = 1;
+#ifdef FONTDIRATTRIB
+    dir = (FontDirectoryPtr) xalloc(sizeof *dir + dirlen + needslash + 1 +
+                                   (attriblen ? attriblen + 1 : 0));
+#else
+    dir = (FontDirectoryPtr) xalloc(sizeof *dir + dirlen + needslash + 1);
+#endif
+    if (!dir)
+       return (FontDirectoryPtr)0;
+    if (!FontFileInitTable (&dir->scalable, 0))
+    {
+       xfree (dir);
+       return (FontDirectoryPtr)0;
+    }
+    if (!FontFileInitTable (&dir->nonScalable, size))
+    {
+       FontFileFreeTable (&dir->scalable);
+       xfree (dir);
+       return (FontDirectoryPtr)0;
+    }
+    dir->directory = (char *) (dir + 1);
+    dir->dir_mtime = 0;
+    dir->alias_mtime = 0;
+#ifdef FONTDIRATTRIB
+    if (attriblen)
+       dir->attributes = dir->directory + dirlen + needslash + 1;
+    else
+       dir->attributes = NULL;
+    strncpy(dir->directory, dirName, dirlen);
+    dir->directory[dirlen] = '\0';
+    if (dir->attributes)
+       strcpy(dir->attributes, attrib);
+#else
+    strcpy(dir->directory, dirName);
+#endif
+    if (needslash)
+       strcat(dir->directory, "/");
+    return dir;
+}
+
+FontFileFreeDir (dir)
+    FontDirectoryPtr   dir;
+{
+    FontFileFreeTable (&dir->scalable);
+    FontFileFreeTable (&dir->nonScalable);
+    xfree(dir);
+}
+
+FontEntryPtr
+FontFileAddEntry(table, prototype)
+    FontTablePtr       table;
+    FontEntryPtr       prototype;
+{
+    FontEntryPtr    entry;
+    int                    newsize;
+
+    /* can't add entries to a sorted table, pointers get broken! */
+    if (table->sorted)
+       return (FontEntryPtr) 0;    /* "cannot" happen */
+    if (table->used == table->size) {
+       newsize = table->size + 100;
+       entry = (FontEntryPtr) xrealloc(table->entries,
+                                          newsize * sizeof(FontEntryRec));
+       if (!entry)
+           return (FontEntryPtr)0;
+       table->size = newsize;
+       table->entries = entry;
+    }
+    entry = &table->entries[table->used];
+    *entry = *prototype;
+    entry->name.name = (char *) xalloc(prototype->name.length + 1);
+    if (!entry->name.name)
+       return (FontEntryPtr)0;
+    memcpy (entry->name.name, prototype->name.name, prototype->name.length);
+    entry->name.name[entry->name.length] = '\0';
+    table->used++;
+    return entry;
+}
+
+static int
+FontFileNameCompare(a, b)
+    char       *a,
+               *b;
+{
+    FontEntryPtr    a_name = (FontEntryPtr) a,
+                   b_name = (FontEntryPtr) b;
+
+    return strcmp(a_name->name.name, b_name->name.name);
+}
+
+FontFileSortTable (table)
+    FontTablePtr    table;
+{
+    if (!table->sorted) {
+       qsort((char *) table->entries, table->used, sizeof(FontEntryRec),
+             FontFileNameCompare);
+       table->sorted = TRUE;
+    }
+}
+
+FontFileSortDir(dir)
+    FontDirectoryPtr   dir;
+{
+    FontFileSortTable (&dir->scalable);
+    FontFileSortTable (&dir->nonScalable);
+    /* now that the table is fixed in size, swizzle the pointers */
+    FontFileSwitchStringsToBitmapPointers (dir);
+}
+
+/*
+  Given a Font Table, SetupWildMatch() sets up various pointers and state
+  information so the table can be searched for name(s) that match a given
+  fontname pattern -- which may contain wildcards.  Under certain
+  circumstances, SetupWildMatch() will find the one table entry that
+  matches the pattern.  If those circumstances do not pertain,
+  SetupWildMatch() returns a range within the the table that should be
+  searched for matching name(s).  With the information established by
+  SetupWildMatch(), including state information in "private", the
+  PatternMatch() procedure is then used to test names in the range for a
+  match.
+*/
+
+#define isWild(c)   ((c) == XK_asterisk || (c) == XK_question)
+
+static int
+SetupWildMatch(table, pat, leftp, rightp, privatep)
+    FontTablePtr    table;
+    FontNamePtr            pat;
+    int                    *leftp,
+                   *rightp;
+    int                    *privatep;
+{
+    int         nDashes;
+    char        c;
+    char       *t;
+    char       *firstWild;
+    int         first;
+    int         center,
+                left,
+                right;
+    int         result;
+    char       *name;
+
+    name = pat->name;
+    nDashes = pat->ndashes;
+    firstWild = 0;
+    t = name;
+    while (c = *t++) {
+       if (isWild(c)) {
+           if (!firstWild)
+               firstWild = t - 1;
+       }
+    }
+    left = 0;
+    right = table->used;
+    if (firstWild)
+       *privatep = nDashes;
+    else
+       *privatep = -1;
+    if (!table->sorted) {
+       *leftp = left;
+       *rightp = right;
+       return -1;
+    } else if (firstWild) {
+       first = firstWild - name;
+       while (left < right) {
+           center = (left + right) / 2;
+           result = strncmp(name, table->entries[center].name.name, first);
+           if (result == 0)
+               break;
+           if (result < 0)
+               right = center;
+           else
+               left = center + 1;
+       }
+       *leftp = left;
+       *rightp = right;
+       return -1;
+    } else {
+       while (left < right) {
+           center = (left + right) / 2;
+           result = strcmp(name, table->entries[center].name.name);
+           if (result == 0)
+               return center;
+           if (result < 0)
+               right = center;
+           else
+               left = center + 1;
+       }
+       *leftp = 1;
+       *rightp = 0;
+       return -1;
+    }
+}
+
+static
+PatternMatch(pat, patdashes, string, stringdashes)
+    char       *pat;
+    char       *string;
+{
+    char        c,
+                t;
+
+    if (stringdashes < patdashes)
+       return 0;
+    for (;;) {
+       switch (c = *pat++) {
+       case '*':
+           if (!(c = *pat++))
+               return 1;
+           if (c == XK_minus) {
+               patdashes--;
+               for (;;) {
+                   while ((t = *string++) != XK_minus)
+                       if (!t)
+                           return 0;
+                   stringdashes--;
+                   if (PatternMatch(pat, patdashes, string, stringdashes))
+                       return 1;
+                   if (stringdashes == patdashes)
+                       return 0;
+               }
+           } else {
+               for (;;) {
+                   while ((t = *string++) != c) {
+                       if (!t)
+                           return 0;
+                       if (t == XK_minus) {
+                           if (stringdashes-- < patdashes)
+                               return 0;
+                       }
+                   }
+                   if (PatternMatch(pat, patdashes, string, stringdashes))
+                       return 1;
+               }
+           }
+       case '?':
+           if (*string++ == XK_minus)
+               stringdashes--;
+           break;
+       case '\0':
+           return (*string == '\0');
+       case XK_minus:
+           if (*string++ == XK_minus) {
+               patdashes--;
+               stringdashes--;
+               break;
+           }
+           return 0;
+       default:
+           if (c == *string++)
+               break;
+           return 0;
+       }
+    }
+}
+
+int
+FontFileCountDashes (name, namelen)
+    char    *name;
+    int            namelen;
+{
+    int        ndashes = 0;
+
+    while (namelen--)
+       if (*name++ == '\055')  /* avoid non ascii systems */
+           ++ndashes;
+    return ndashes;
+}
+
+char *
+FontFileSaveString (s)
+    char    *s;
+{
+    char    *n;
+
+    n = (char *) xalloc (strlen (s) + 1);
+    if (!n)
+       return 0;
+    strcpy (n, s);
+    return n;
+}
+
+FontEntryPtr
+FontFileFindNameInScalableDir(table, pat, vals)
+    FontTablePtr    table;
+    FontNamePtr            pat;
+    FontScalablePtr    vals;
+{
+    int         i,
+                start,
+                stop,
+                res,
+                private;
+    FontNamePtr        name;
+
+    if ((i = SetupWildMatch(table, pat, &start, &stop, &private)) >= 0)
+       return &table->entries[i];
+    for (i = start; i < stop; i++) {
+       name = &table->entries[i].name;
+       res = PatternMatch(pat->name, private, name->name, name->ndashes);
+       if (res > 0)
+       {
+           /* Check to see if enhancements requested are available */
+           if (vals)
+           {
+               int vs = vals->values_supplied;
+               int cap;
+
+               if (table->entries[i].type == FONT_ENTRY_SCALABLE)
+                   cap = table->entries[i].u.scalable.renderer->capabilities;
+               else if (table->entries[i].type == FONT_ENTRY_ALIAS)
+                   cap = ~0;   /* Calling code will have to see if true */
+               else
+                   cap = 0;
+               if (((vs & PIXELSIZE_MASK) == PIXELSIZE_ARRAY ||
+                    (vs & POINTSIZE_MASK) == POINTSIZE_ARRAY) &&
+                   !(cap & CAP_MATRIX) ||
+                   (vs & CHARSUBSET_SPECIFIED) &&
+                   !(cap & CAP_CHARSUBSETTING))
+                   continue;
+           }
+           return &table->entries[i];
+       }
+       if (res < 0)
+           break;
+    }
+    return (FontEntryPtr)0;
+}
+
+FontEntryPtr
+FontFileFindNameInDir(table, pat)
+    FontTablePtr    table;
+    FontNamePtr            pat;
+{
+    return FontFileFindNameInScalableDir(table, pat, (FontScalablePtr)0);
+}
+
+FontFileFindNamesInScalableDir(table, pat, max, names, vals,
+                              alias_behavior, newmax)
+    FontTablePtr    table;
+    FontNamePtr            pat;
+    int                    max;
+    FontNamesPtr    names;
+    FontScalablePtr    vals;
+    int                    alias_behavior;
+    int                   *newmax;
+{
+    int                    i,
+                   start,
+                   stop,
+                   res,
+                   private;
+    int                    ret = Successful;
+    FontEntryPtr    fname;
+    FontNamePtr            name;
+
+    if (max <= 0)
+       return Successful;
+    if ((i = SetupWildMatch(table, pat, &start, &stop, &private)) >= 0) {
+       if (alias_behavior == NORMAL_ALIAS_BEHAVIOR ||
+           table->entries[i].type != FONT_ENTRY_ALIAS)
+       {
+           name = &table->entries[i].name;
+           if (newmax) *newmax = max - 1;
+           return AddFontNamesName(names, name->name, name->length);
+       }
+       start = i;
+       stop = i + 1;
+    }
+    for (i = start, fname = &table->entries[start]; i < stop; i++, fname++) {
+       res = PatternMatch(pat->name, private, fname->name.name, fname->name.ndashes);
+       if (res > 0) {
+           if (vals)
+           {
+               int vs = vals->values_supplied;
+               int cap;
+
+               if (fname->type == FONT_ENTRY_SCALABLE)
+                   cap = fname->u.scalable.renderer->capabilities;
+               else if (fname->type == FONT_ENTRY_ALIAS)
+                   cap = ~0;   /* Calling code will have to see if true */
+               else
+                   cap = 0;
+               if (((vs & PIXELSIZE_MASK) == PIXELSIZE_ARRAY ||
+                    (vs & POINTSIZE_MASK) == POINTSIZE_ARRAY) &&
+                   !(cap & CAP_MATRIX) ||
+                   (vs & CHARSUBSET_SPECIFIED) &&
+                   !(cap & CAP_CHARSUBSETTING))
+                   continue;
+           }
+
+           if ((alias_behavior & IGNORE_SCALABLE_ALIASES) &&
+               fname->type == FONT_ENTRY_ALIAS)
+           {
+               FontScalableRec tmpvals;
+               if (FontParseXLFDName (fname->name.name, &tmpvals,
+                                      FONT_XLFD_REPLACE_NONE) &&
+                   !(tmpvals.values_supplied & SIZE_SPECIFY_MASK))
+                   continue;
+           }
+
+           ret = AddFontNamesName(names, fname->name.name, fname->name.length);
+           if (ret != Successful)
+               goto bail;
+
+           /* If alias_behavior is LIST_ALIASES_AND_TARGET_NAMES, mark
+              this entry as an alias by negating its length and follow
+              it by the resolved name */
+           if ((alias_behavior & LIST_ALIASES_AND_TARGET_NAMES) &&
+               fname->type == FONT_ENTRY_ALIAS)
+           {
+               names->length[names->nnames - 1] =
+                   -names->length[names->nnames - 1];
+               ret = AddFontNamesName(names, fname->u.alias.resolved,
+                                      strlen(fname->u.alias.resolved));
+               if (ret != Successful)
+                   goto bail;
+           }
+
+           if (--max <= 0)
+               break;
+       } else if (res < 0)
+           break;
+    }
+  bail: ;
+    if (newmax) *newmax = max;
+    return ret;
+}
+
+int
+FontFileFindNamesInDir(table, pat, max, names)
+    FontTablePtr    table;
+    FontNamePtr            pat;
+    int                    max;
+    FontNamesPtr    names;
+{
+    return FontFileFindNamesInScalableDir(table, pat, max, names,
+                                         (FontScalablePtr)0,
+                                         NORMAL_ALIAS_BEHAVIOR, (int *)0);
+}
+
+Bool
+FontFileMatchName(name, length, pat)
+    char       *name;
+    int                length;
+    FontNamePtr        pat;
+{
+    /* Perform a fontfile-type name match on a single name */
+    FontTableRec table;
+    FontEntryRec entries[1];
+
+    /* Dummy up a table */
+    table.used = 1;
+    table.size = 1;
+    table.sorted = TRUE;
+    table.entries = entries;
+    entries[0].name.name = name;
+    entries[0].name.length = length;
+    entries[0].name.ndashes = FontFileCountDashes(name, length);
+
+    return FontFileFindNameInDir(&table, pat) != (FontEntryPtr)0;
+}
+
+/*
+ * Add a font file to a directory.  This handles bitmap and
+ * scalable names both
+ */
+
+Bool
+FontFileAddFontFile (dir, fontName, fileName)
+    FontDirectoryPtr   dir;
+    char               *fontName;
+    char               *fileName;
+{
+    FontEntryRec           entry;
+    FontScalableRec        vals, zeroVals;
+    FontRendererPtr        renderer;
+    FontEntryPtr           existing;
+    FontScalableExtraPtr    extra;
+    FontEntryPtr           bitmap, scalable;
+    Bool                   isscale;
+
+    renderer = FontFileMatchRenderer (fileName);
+    if (!renderer)
+       return FALSE;
+    entry.name.length = strlen (fontName);
+    if (entry.name.length > MAXFONTNAMELEN)
+       entry.name.length = MAXFONTNAMELEN;
+    entry.name.name = fontName;
+    CopyISOLatin1Lowered (entry.name.name, fontName, entry.name.length);
+    entry.name.ndashes = FontFileCountDashes (entry.name.name, entry.name.length);
+    entry.name.name[entry.name.length] = '\0';
+    /*
+     * Add a bitmap name if the incoming name isn't an XLFD name, or
+     * if it isn't a scalable name (i.e. non-zero scalable fields)
+     *
+     * If name of bitmapped font contains XLFD enhancements, do not add
+     * a scalable version of the name... this can lead to confusion and
+     * ambiguity between the font name and the field enhancements.
+     */
+    isscale = entry.name.ndashes == 14 &&
+             FontParseXLFDName(entry.name.name,
+                               &vals, FONT_XLFD_REPLACE_NONE) &&
+             (vals.values_supplied & PIXELSIZE_MASK) != PIXELSIZE_ARRAY &&
+             (vals.values_supplied & POINTSIZE_MASK) != POINTSIZE_ARRAY &&
+             !(vals.values_supplied & ENHANCEMENT_SPECIFY_MASK);
+#ifdef FONTDIRATTRIB
+#define UNSCALED_ATTRIB "unscaled"
+    /* For scalable fonts, check if the "unscaled" attribute is present */
+    if (isscale && dir->attributes && dir->attributes[0] == ':') {
+       char *ptr1 = dir->attributes + 1;
+       char *ptr2;
+       int length;
+       int uslength = strlen(UNSCALED_ATTRIB);
+
+       do {
+           ptr2 = strchr(ptr1, ':');
+           if (ptr2)
+               length = ptr2 - ptr1;
+           else
+               length = dir->attributes + strlen(dir->attributes) - ptr1;
+           if (length == uslength && !strncmp(ptr1, UNSCALED_ATTRIB, uslength))
+               isscale = FALSE;
+           if (ptr2)
+               ptr1 = ptr2 + 1;
+       } while (ptr2);
+    }
+#endif
+    if (!isscale || (vals.values_supplied & SIZE_SPECIFY_MASK))
+    {
+      /* If the fontname says it is nonScalable, make sure that the
+       * renderer supports OpenBitmap and GetInfoBitmap.
+       */
+      if (renderer->OpenBitmap && renderer->GetInfoBitmap)
+      {
+       entry.type = FONT_ENTRY_BITMAP;
+       entry.u.bitmap.renderer = renderer;
+       entry.u.bitmap.pFont = NullFont;
+       if (!(entry.u.bitmap.fileName = FontFileSaveString (fileName)))
+           return FALSE;
+       if (!(bitmap = FontFileAddEntry (&dir->nonScalable, &entry)))
+       {
+           xfree (entry.u.bitmap.fileName);
+           return FALSE;
+       }
+      }
+    }
+    /*
+     * Parse out scalable fields from XLFD names - a scalable name
+     * just gets inserted, a scaled name has more things to do.
+     */
+    if (isscale)
+    {
+      /* If the fontname says it is scalable, make sure that the
+       * renderer supports OpenScalable and GetInfoScalable.
+       */
+      if (renderer->OpenScalable && renderer->GetInfoScalable)
+      {
+       if (vals.values_supplied & SIZE_SPECIFY_MASK)
+       {
+           bzero((char *)&zeroVals, sizeof(zeroVals));
+           zeroVals.x = vals.x;
+           zeroVals.y = vals.y;
+           zeroVals.values_supplied = PIXELSIZE_SCALAR | POINTSIZE_SCALAR;
+           FontParseXLFDName (entry.name.name, &zeroVals,
+                              FONT_XLFD_REPLACE_VALUE);
+           entry.name.length = strlen (entry.name.name);
+           existing = FontFileFindNameInDir (&dir->scalable, &entry.name);
+           if (existing)
+           {
+               if ((vals.values_supplied & POINTSIZE_MASK) ==
+                       POINTSIZE_SCALAR &&
+                   (int)(vals.point_matrix[3] * 10) == GetDefaultPointSize())
+               {
+                   existing->u.scalable.extra->defaults = vals;
+
+                   xfree (existing->u.scalable.fileName);
+                   if (!(existing->u.scalable.fileName = FontFileSaveString (fileName)))
+                       return FALSE;
+               }
+               FontFileCompleteXLFD(&vals, &vals);
+               FontFileAddScaledInstance (existing, &vals, NullFont,
+                                          bitmap->name.name);
+               return TRUE;
+           }
+       }
+       if (!(entry.u.scalable.fileName = FontFileSaveString (fileName)))
+           return FALSE;
+       extra = (FontScalableExtraPtr) xalloc (sizeof (FontScalableExtraRec));
+       if (!extra)
+       {
+           xfree (entry.u.scalable.fileName);
+           return FALSE;
+       }
+       bzero((char *)&extra->defaults, sizeof(extra->defaults));
+       if ((vals.values_supplied & POINTSIZE_MASK) == POINTSIZE_SCALAR &&
+           (int)(vals.point_matrix[3] * 10) == GetDefaultPointSize())
+           extra->defaults = vals;
+       else
+       {
+           FontResolutionPtr resolution;
+           int num;
+
+           extra->defaults.point_matrix[0] =
+               extra->defaults.point_matrix[3] =
+                   (double)GetDefaultPointSize() / 10.0;
+           extra->defaults.point_matrix[1] =
+               extra->defaults.point_matrix[2] = 0.0;
+           extra->defaults.values_supplied =
+               POINTSIZE_SCALAR | PIXELSIZE_UNDEFINED;
+           extra->defaults.width = -1;
+           if (vals.x <= 0 || vals.y <= 0)
+           {
+               resolution = GetClientResolutions (&num);
+               if (resolution && num > 0)
+               {
+                   extra->defaults.x = resolution->x_resolution;
+                   extra->defaults.y = resolution->y_resolution;
+               }
+               else
+               {
+                   extra->defaults.x = 75;
+                   extra->defaults.y = 75;
+               }
+            }
+            else 
+            {
+               extra->defaults.x = vals.x;
+               extra->defaults.y = vals.y;
+            }
+            FontFileCompleteXLFD (&extra->defaults, &extra->defaults);
+       }
+       extra->numScaled = 0;
+       extra->sizeScaled = 0;
+       extra->scaled = 0;
+       extra->private = 0;
+       entry.type = FONT_ENTRY_SCALABLE;
+       entry.u.scalable.renderer = renderer;
+       entry.u.scalable.extra = extra;
+       if (!(scalable = FontFileAddEntry (&dir->scalable, &entry)))
+       {
+           xfree (extra);
+           xfree (entry.u.scalable.fileName);
+           return FALSE;
+       }
+       if (vals.values_supplied & SIZE_SPECIFY_MASK)
+       {
+           FontFileCompleteXLFD(&vals, &vals);
+           FontFileAddScaledInstance (scalable, &vals, NullFont,
+                                      bitmap->name.name);
+       }
+      }
+    }
+    return TRUE;
+}
+
+Bool
+FontFileAddFontAlias (dir, aliasName, fontName)
+    FontDirectoryPtr   dir;
+    char               *aliasName;
+    char               *fontName;
+{
+    FontEntryRec       entry;
+
+    entry.name.length = strlen (aliasName);
+    CopyISOLatin1Lowered (aliasName, aliasName, entry.name.length);
+    entry.name.name = aliasName;
+    entry.name.ndashes = FontFileCountDashes (entry.name.name, entry.name.length);
+    entry.type = FONT_ENTRY_ALIAS;
+    if (!(entry.u.alias.resolved = FontFileSaveString (fontName)))
+       return FALSE;
+    if (!FontFileAddEntry (&dir->nonScalable, &entry))
+    {
+       xfree (entry.u.alias.resolved);
+       return FALSE;
+    }
+    return TRUE;
+}
diff --git a/Xserver/lib/font/fontfile/fontfile.c b/Xserver/lib/font/fontfile/fontfile.c
new file mode 100644 (file)
index 0000000..b0ab1c5
--- /dev/null
@@ -0,0 +1,1129 @@
+/* $TOG: fontfile.c /main/29 1997/05/23 16:36:56 barstow $ */
+
+/*
+
+Copyright (c) 1991  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+*/
+/* $XFree86: xc/lib/font/fontfile/fontfile.c,v 3.3.4.2 1997/07/05 15:55:36 dawes Exp $ */
+
+/*
+ * Author:  Keith Packard, MIT X Consortium
+ */
+/* $NCDId: @(#)fontfile.c,v 1.6 1991/07/02 17:00:46 lemke Exp $ */
+
+#include    "fntfilst.h"
+
+/*
+ * Map FPE functions to renderer functions
+ */
+
+int
+FontFileNameCheck (name)
+    char    *name;
+{
+#ifndef NCD
+#ifdef __EMX__
+    /* OS/2 uses D:/... as a path name for fonts, so accept this as a valid
+     * path if it starts with a letter and a colon
+     */
+    if (isalpha(*name) && name[1]==':')
+        return TRUE;
+#endif
+    return *name == '/';
+#else
+    return ((strcmp(name, "built-ins") == 0) || (*name == '/'));
+#endif
+}
+
+int
+FontFileInitFPE (fpe)
+    FontPathElementPtr fpe;
+{
+    int                        status;
+    FontDirectoryPtr   dir;
+
+    status = FontFileReadDirectory (fpe->name, &dir);
+    if (status == Successful)
+    {
+       if (dir->nonScalable.used > 0)
+           if (!FontFileRegisterBitmapSource (fpe))
+           {
+               FontFileFreeFPE (fpe);
+               return AllocError;
+           }
+       fpe->private = (pointer) dir;
+    }
+    return status;
+}
+
+/* ARGSUSED */
+int
+FontFileResetFPE (fpe)
+    FontPathElementPtr fpe;
+{
+    FontDirectoryPtr   dir;
+
+    dir = (FontDirectoryPtr) fpe->private;
+    /*
+     * The reset must fail for bitmap fonts because they get cleared when
+     * the path is set.
+     */
+    if (FontFileDirectoryChanged (dir))
+    {
+       /* can't do it, so tell the caller to close and re-open */
+       return FPEResetFailed;  
+    }
+    else 
+    {
+       if (dir->nonScalable.used > 0)
+           if (!FontFileRegisterBitmapSource (fpe))
+           {
+               return FPEResetFailed;  
+           }
+        return Successful;
+    }
+}
+
+int
+FontFileFreeFPE (fpe)
+    FontPathElementPtr fpe;
+{
+    FontFileUnregisterBitmapSource (fpe);
+    FontFileFreeDir ((FontDirectoryPtr) fpe->private);
+    return Successful;
+}
+
+static int
+transfer_values_to_alias(entryname, entrynamelength, resolvedname,
+                        aliasName, vals)
+    char               *entryname;
+    int                        entrynamelength;
+    char               *resolvedname;
+    char               **aliasName;
+    FontScalablePtr    vals;
+{
+    static char                aliasname[MAXFONTNAMELEN];
+    int                        nameok = 1, len;
+    char               lowerName[MAXFONTNAMELEN];
+
+    *aliasName = resolvedname;
+    if ((len = strlen(*aliasName)) <= MAXFONTNAMELEN &&
+       FontFileCountDashes (*aliasName, len) == 14)
+    {
+       FontScalableRec tmpVals;
+       FontScalableRec tmpVals2;
+
+       tmpVals2 = *vals;
+
+       /* If we're aliasing a scalable name, transfer values
+          from the name into the destination alias, multiplying
+          by matrices that appear in the alias. */
+
+       CopyISOLatin1Lowered (lowerName, entryname,
+                             entrynamelength);
+       lowerName[entrynamelength] = '\0';
+
+       if (FontParseXLFDName(lowerName, &tmpVals,
+                             FONT_XLFD_REPLACE_NONE) &&
+           !tmpVals.values_supplied &&
+           FontParseXLFDName(*aliasName, &tmpVals,
+                             FONT_XLFD_REPLACE_NONE))
+       {
+           double *matrix = 0, tempmatrix[4];
+
+           /* Use a matrix iff exactly one is defined */
+           if ((tmpVals.values_supplied & PIXELSIZE_MASK) ==
+               PIXELSIZE_ARRAY &&
+               !(tmpVals.values_supplied & POINTSIZE_MASK))
+               matrix = tmpVals.pixel_matrix;
+           else if ((tmpVals.values_supplied & POINTSIZE_MASK) ==
+                    POINTSIZE_ARRAY &&
+                    !(tmpVals.values_supplied & PIXELSIZE_MASK))
+               matrix = tmpVals.point_matrix;
+
+           /* If matrix given in the alias, compute new point
+              and/or pixel matrices */
+           if (matrix)
+           {
+               /* Complete the XLFD name to avoid potential
+                  gotchas */
+               if (FontFileCompleteXLFD(&tmpVals2, &tmpVals2))
+               {
+                   double hypot();
+                   tempmatrix[0] =
+                       matrix[0] * tmpVals2.point_matrix[0] +
+                       matrix[1] * tmpVals2.point_matrix[2];
+                   tempmatrix[1] =
+                       matrix[0] * tmpVals2.point_matrix[1] +
+                       matrix[1] * tmpVals2.point_matrix[3];
+                   tempmatrix[2] =
+                       matrix[2] * tmpVals2.point_matrix[0] +
+                       matrix[3] * tmpVals2.point_matrix[2];
+                   tempmatrix[3] =
+                       matrix[2] * tmpVals2.point_matrix[1] +
+                       matrix[3] * tmpVals2.point_matrix[3];
+                   tmpVals2.point_matrix[0] = tempmatrix[0];
+                   tmpVals2.point_matrix[1] = tempmatrix[1];
+                   tmpVals2.point_matrix[2] = tempmatrix[2];
+                   tmpVals2.point_matrix[3] = tempmatrix[3];
+
+                   tempmatrix[0] =
+                       matrix[0] * tmpVals2.pixel_matrix[0] +
+                       matrix[1] * tmpVals2.pixel_matrix[2];
+                   tempmatrix[1] =
+                       matrix[0] * tmpVals2.pixel_matrix[1] +
+                       matrix[1] * tmpVals2.pixel_matrix[3];
+                   tempmatrix[2] =
+                       matrix[2] * tmpVals2.pixel_matrix[0] +
+                       matrix[3] * tmpVals2.pixel_matrix[2];
+                   tempmatrix[3] =
+                       matrix[2] * tmpVals2.pixel_matrix[1] +
+                       matrix[3] * tmpVals2.pixel_matrix[3];
+                   tmpVals2.pixel_matrix[0] = tempmatrix[0];
+                   tmpVals2.pixel_matrix[1] = tempmatrix[1];
+                   tmpVals2.pixel_matrix[2] = tempmatrix[2];
+                   tmpVals2.pixel_matrix[3] = tempmatrix[3];
+
+                   tmpVals2.values_supplied =
+                       (tmpVals2.values_supplied &
+                        ~(PIXELSIZE_MASK | POINTSIZE_MASK)) |
+                       PIXELSIZE_ARRAY | POINTSIZE_ARRAY;
+               }
+               else
+                   nameok = 0;
+           }
+
+           CopyISOLatin1Lowered (aliasname, *aliasName, len + 1);
+           if (nameok && FontParseXLFDName(aliasname, &tmpVals2,
+                                 FONT_XLFD_REPLACE_VALUE))
+               /* Return a version of the aliasname that has
+                  had the vals stuffed into it.  To avoid
+                  memory leak, this alias name lives in a
+                  static buffer.  The caller needs to be done
+                  with this buffer before this procedure is
+                  called again to avoid reentrancy problems. */
+                   *aliasName = aliasname;
+       }
+    }
+    return nameok;
+}
+
+/* ARGSUSED */
+int
+FontFileOpenFont (client, fpe, flags, name, namelen, format, fmask,
+                 id, pFont, aliasName, non_cachable_font)
+    pointer            client;
+    FontPathElementPtr fpe;
+    int                        flags;
+    char               *name;
+    int                        namelen;
+    fsBitmapFormat     format;
+    fsBitmapFormatMask fmask;
+    XID                        id;
+    FontPtr            *pFont;
+    char               **aliasName;
+    FontPtr            non_cachable_font;
+{
+    FontDirectoryPtr   dir;
+    char               lowerName[MAXFONTNAMELEN];
+    char               fileName[MAXFONTFILENAMELEN*2 + 1];
+    FontNameRec                tmpName;
+    FontEntryPtr       entry;
+    FontScalableRec    vals;
+    FontScalableEntryPtr   scalable;
+    FontScaledPtr      scaled;
+    FontBitmapEntryPtr bitmap;
+    FontBCEntryPtr     bc;
+    int                        ret;
+    Bool               noSpecificSize;
+    int                        nranges;
+    fsRange            *ranges;
+    
+    if (namelen >= MAXFONTNAMELEN)
+       return AllocError;
+    dir = (FontDirectoryPtr) fpe->private;
+
+    /* Match non-scalable pattern */
+    CopyISOLatin1Lowered (lowerName, name, namelen);
+    lowerName[namelen] = '\0';
+    ranges = FontParseRanges(lowerName, &nranges);
+    tmpName.name = lowerName;
+    tmpName.length = namelen;
+    tmpName.ndashes = FontFileCountDashes (lowerName, namelen);
+    if (!FontParseXLFDName(lowerName, &vals, FONT_XLFD_REPLACE_NONE))
+       bzero(&vals, sizeof(vals));
+    if (!(entry = FontFileFindNameInDir (&dir->nonScalable, &tmpName)) &&
+       tmpName.ndashes == 14 &&
+       FontParseXLFDName (lowerName, &vals, FONT_XLFD_REPLACE_ZERO))
+    {
+        tmpName.length = strlen(lowerName);
+       entry = FontFileFindNameInDir (&dir->nonScalable, &tmpName);
+    }
+
+    if (entry)
+    {
+       int len;
+       switch (entry->type) {
+       case FONT_ENTRY_BITMAP:
+           bitmap = &entry->u.bitmap;
+           if (bitmap->pFont)
+           {
+               *pFont = bitmap->pFont;
+               (*pFont)->fpe = fpe;
+               ret = Successful;
+           }
+           else
+           {
+               ret = FontFileOpenBitmapNCF (fpe, pFont, flags, entry, format,
+                                            fmask, non_cachable_font);
+               if (ret == Successful && *pFont)
+                   (*pFont)->fpe = fpe;
+           }
+           break;
+       case FONT_ENTRY_ALIAS:
+           vals.nranges = nranges;
+           vals.ranges = ranges;
+           transfer_values_to_alias(entry->name.name, entry->name.length,
+                                    entry->u.alias.resolved, aliasName, &vals);
+           ret = FontNameAlias;
+           break;
+#ifdef NOTYET
+       case FONT_ENTRY_BC:
+           bc = &entry->u.bc;
+           entry = bc->entry;
+           ret = (*scalable->renderer->OpenScalable)
+                   (fpe, pFont, flags, entry, &bc->vals, format, fmask,
+                    non_cachable_font);
+           if (ret == Successful && *pFont)
+               (*pFont)->fpe = fpe;
+           break;
+#endif
+       default:
+           ret = BadFontName;
+       }
+    }
+    else
+    {
+       ret = BadFontName;
+    }
+
+    if (ret != BadFontName)
+    {
+       if (ranges) xfree(ranges);
+       return ret;
+    }
+
+    /* Match XLFD patterns */
+    CopyISOLatin1Lowered (lowerName, name, namelen);
+    lowerName[namelen] = '\0';
+    tmpName.name = lowerName;
+    tmpName.length = namelen;
+    tmpName.ndashes = FontFileCountDashes (lowerName, namelen);
+    if (!FontParseXLFDName (lowerName, &vals, FONT_XLFD_REPLACE_ZERO) ||
+       !(tmpName.length = strlen (lowerName),
+         entry = FontFileFindNameInScalableDir (&dir->scalable, &tmpName,
+                                                &vals)))
+    {
+       CopyISOLatin1Lowered (lowerName, name, namelen);
+       lowerName[namelen] = '\0';
+       tmpName.name = lowerName;
+       tmpName.length = namelen;
+       tmpName.ndashes = FontFileCountDashes (lowerName, namelen);
+       entry = FontFileFindNameInScalableDir (&dir->scalable, &tmpName, &vals);
+       if (entry)
+       {
+           strcpy(lowerName, entry->name.name);
+           tmpName.name = lowerName;
+           tmpName.length = entry->name.length;
+           tmpName.ndashes = entry->name.ndashes;
+       }
+    }
+    if (entry)
+    {
+       noSpecificSize = FALSE; /* TRUE breaks XLFD enhancements */
+       if (entry->type == FONT_ENTRY_SCALABLE &&
+           FontFileCompleteXLFD (&vals, &entry->u.scalable.extra->defaults))
+       {
+           scalable = &entry->u.scalable;
+           if ((vals.values_supplied & PIXELSIZE_MASK) == PIXELSIZE_ARRAY ||
+               (vals.values_supplied & POINTSIZE_MASK) == POINTSIZE_ARRAY ||
+               (vals.values_supplied &
+                ~SIZE_SPECIFY_MASK & ~CHARSUBSET_SPECIFIED))
+               scaled = 0;
+           else
+               scaled = FontFileFindScaledInstance (entry, &vals,
+                                                    noSpecificSize);
+           /*
+            * A scaled instance can occur one of two ways:
+            *
+            *  Either the font has been scaled to this
+            *   size already, in which case scaled->pFont
+            *   will point at that font.
+            *
+            *  Or a bitmap instance in this size exists,
+            *   which is handled as if we got a pattern
+            *   matching the bitmap font name.
+            */
+           if (scaled)
+           {
+               if (scaled->pFont)
+               {
+                   *pFont = scaled->pFont;
+                   (*pFont)->fpe = fpe;
+                   ret = Successful;
+               }
+               else if (scaled->bitmap)
+               {
+                   entry = scaled->bitmap;
+                   bitmap = &entry->u.bitmap;
+                   if (bitmap->pFont)
+                   {
+                       *pFont = bitmap->pFont;
+                       (*pFont)->fpe = fpe;
+                       ret = Successful;
+                   }
+                   else
+                   {
+                       ret = FontFileOpenBitmapNCF (fpe, pFont, flags, entry,
+                                                    format, fmask,
+                                                    non_cachable_font);
+                       if (ret == Successful && *pFont)
+                           (*pFont)->fpe = fpe;
+                   }
+               }
+               else /* "cannot" happen */
+               {
+                   ret = BadFontName;
+               }
+           }
+           else
+           {
+               ret = FontFileMatchBitmapSource (fpe, pFont, flags, entry, &tmpName, &vals, format, fmask, noSpecificSize);
+               if (ret != Successful)
+               {
+                   char origName[MAXFONTNAMELEN];
+
+                   CopyISOLatin1Lowered (origName, name, namelen);
+                   origName[namelen] = '\0';
+
+                   /* Pass the original XLFD name in the vals
+                      structure; the rasterizer is free to examine it
+                      for hidden meanings.  This information will not
+                      be saved in the scaled-instances table.  */
+
+                   vals.xlfdName = origName;
+                   vals.ranges = ranges;
+                   vals.nranges = nranges;
+
+                   strcpy (fileName, dir->directory);
+                   strcat (fileName, scalable->fileName);
+                   ret = (*scalable->renderer->OpenScalable) (fpe, pFont,
+                          flags, entry, fileName, &vals, format, fmask,
+                          non_cachable_font);
+
+                   /* In case rasterizer does something bad because of
+                      charset subsetting... */
+                   if (ret == Successful &&
+                       ((*pFont)->info.firstCol > (*pFont)->info.lastCol ||
+                        (*pFont)->info.firstRow > (*pFont)->info.lastRow))
+                   {
+                       (*(*pFont)->unload_font)(*pFont);
+                       ret = BadFontName;
+                   }
+                   /* Save the instance */
+                   if (ret == Successful)
+                   {
+                       if (FontFileAddScaledInstance (entry, &vals,
+                                                   *pFont, (char *) 0))
+                           ranges = 0;
+                       else
+                           (*pFont)->fpePrivate = (pointer) 0;
+                       (*pFont)->fpe = fpe;
+                   }
+               }
+           }
+       }
+    }
+    else
+       ret = BadFontName;
+
+    if (ranges)
+       xfree(ranges);
+    return ret;
+}
+
+/* ARGSUSED */
+FontFileCloseFont (fpe, pFont)
+    FontPathElementPtr fpe;
+    FontPtr            pFont;
+{
+    FontEntryPtr    entry;
+
+    if (entry = (FontEntryPtr) pFont->fpePrivate) {
+       switch (entry->type) {
+       case FONT_ENTRY_SCALABLE:
+           FontFileRemoveScaledInstance (entry, pFont);
+           break;
+       case FONT_ENTRY_BITMAP:
+           entry->u.bitmap.pFont = 0;
+           break;
+       default:
+           /* "cannot" happen */
+           break;
+       }
+       pFont->fpePrivate = 0;
+    }
+    (*pFont->unload_font) (pFont);
+}
+
+int
+FontFileOpenBitmapNCF (fpe, pFont, flags, entry, format, fmask,
+                      non_cachable_font)
+    FontPathElementPtr fpe;
+    int                        flags;
+    FontEntryPtr       entry;
+    FontPtr            *pFont;
+    FontPtr            non_cachable_font;
+{
+    FontBitmapEntryPtr bitmap;
+    char               fileName[MAXFONTFILENAMELEN*2+1];
+    int                        ret;
+    FontDirectoryPtr   dir;
+
+    dir = (FontDirectoryPtr) fpe->private;
+    bitmap = &entry->u.bitmap;
+    strcpy (fileName, dir->directory);
+    strcat (fileName, bitmap->fileName);
+    ret = (*bitmap->renderer->OpenBitmap) 
+                       (fpe, pFont, flags, entry, fileName, format, fmask,
+                        non_cachable_font);
+    if (ret == Successful)
+    {
+       bitmap->pFont = *pFont;
+       (*pFont)->fpePrivate = (pointer) entry;
+    }
+    return ret;
+}
+
+int
+FontFileOpenBitmap (fpe, pFont, flags, entry, format, fmask)
+    FontPathElementPtr fpe;
+    int                        flags;
+    FontEntryPtr       entry;
+    FontPtr            *pFont;
+{
+    return FontFileOpenBitmapNCF (fpe, pFont, flags, entry, format, fmask,
+                                 (FontPtr)0);
+}
+
+FontFileGetInfoBitmap (fpe, pFontInfo, entry)
+    FontPathElementPtr fpe;
+    FontInfoPtr                pFontInfo;
+    FontEntryPtr       entry;
+{
+    FontBitmapEntryPtr bitmap;
+    char               fileName[MAXFONTFILENAMELEN*2+1];
+    int                        ret;
+    FontDirectoryPtr   dir;
+
+    dir = (FontDirectoryPtr) fpe->private;
+    bitmap = &entry->u.bitmap;
+    strcpy (fileName, dir->directory);
+    strcat (fileName, bitmap->fileName);
+    ret = (*bitmap->renderer->GetInfoBitmap) (fpe, pFontInfo, entry, fileName);
+    return ret;
+}
+
+static void
+_FontFileAddScalableNames(names, scaleNames, nameptr, zeroChars, vals, ranges,
+                         nranges, max)
+    FontNamesPtr       names;
+    FontNamesPtr       scaleNames;
+    FontNamePtr                *nameptr;
+    char               *zeroChars;
+    FontScalablePtr    vals;
+    fsRange            *ranges;
+    int                        nranges;
+    int                        *max;
+{
+    int i;
+    FontScalableRec    zeroVals, tmpVals;
+    for (i = 0; i < scaleNames->nnames; i++)
+    {
+       char nameChars[MAXFONTNAMELEN];
+       if (!*max)
+           return;
+       FontParseXLFDName (scaleNames->names[i], &zeroVals,
+                          FONT_XLFD_REPLACE_NONE);
+       tmpVals = *vals;
+       if (FontFileCompleteXLFD (&tmpVals, &zeroVals))
+       {
+           --*max;
+
+           strcpy (nameChars, scaleNames->names[i]);
+           if ((vals->values_supplied & PIXELSIZE_MASK) ||
+               !(vals->values_supplied & PIXELSIZE_WILDCARD) ||
+               vals->y == 0)
+           {
+               tmpVals.values_supplied =
+                   (tmpVals.values_supplied & ~PIXELSIZE_MASK) |
+                   (vals->values_supplied & PIXELSIZE_MASK);
+               tmpVals.pixel_matrix[0] = vals->pixel_matrix[0];
+               tmpVals.pixel_matrix[1] = vals->pixel_matrix[1];
+               tmpVals.pixel_matrix[2] = vals->pixel_matrix[2];
+               tmpVals.pixel_matrix[3] = vals->pixel_matrix[3];
+           }
+           if ((vals->values_supplied & POINTSIZE_MASK) ||
+               !(vals->values_supplied & POINTSIZE_WILDCARD) ||
+               vals->y == 0)
+           {
+               tmpVals.values_supplied =
+                   (tmpVals.values_supplied & ~POINTSIZE_MASK) |
+                   (vals->values_supplied & POINTSIZE_MASK);
+               tmpVals.point_matrix[0] = vals->point_matrix[0];
+               tmpVals.point_matrix[1] = vals->point_matrix[1];
+               tmpVals.point_matrix[2] = vals->point_matrix[2];
+               tmpVals.point_matrix[3] = vals->point_matrix[3];
+           }
+           if (vals->width <= 0)
+               tmpVals.width = 0;
+           if (vals->x == 0)
+               tmpVals.x = 0;
+           if (vals->y == 0)
+               tmpVals.y = 0;
+           tmpVals.ranges = ranges;
+           tmpVals.nranges = nranges;
+           FontParseXLFDName (nameChars, &tmpVals,
+                              FONT_XLFD_REPLACE_VALUE);
+           /* If we're marking aliases with negative lengths, we
+              need to concoct a valid target name to follow it.
+              Otherwise we're done.  */
+           if (scaleNames->length[i] >= 0)
+           {
+               (void) AddFontNamesName (names, nameChars,
+                                        strlen (nameChars));
+               /* If our original pattern matches the name from
+                  the table and that name doesn't duplicate what
+                  we just added, add the name from the table */
+               if (strcmp(nameChars, scaleNames->names[i]) &&
+                   FontFileMatchName(scaleNames->names[i],
+                                     scaleNames->length[i],
+                                     nameptr) &&
+                   *max)
+               {
+                   --*max;
+                   (void) AddFontNamesName (names, scaleNames->names[i],
+                                            scaleNames->length[i]);
+               }
+           }
+           else
+           {
+               char *aliasName;
+               vals->ranges = ranges;
+               vals->nranges = nranges;
+               if (transfer_values_to_alias(zeroChars,
+                                            strlen(zeroChars),
+                                            scaleNames->names[++i],
+                                            &aliasName, vals))
+               {
+                   (void) AddFontNamesName (names, nameChars,
+                                            strlen (nameChars));
+                   names->length[names->nnames - 1] =
+                       -names->length[names->nnames - 1];
+                   (void) AddFontNamesName (names, aliasName,
+                                            strlen (aliasName));
+                   /* If our original pattern matches the name from
+                      the table and that name doesn't duplicate what
+                      we just added, add the name from the table */
+                   if (strcmp(nameChars, scaleNames->names[i - 1]) &&
+                       FontFileMatchName(scaleNames->names[i - 1],
+                                         -scaleNames->length[i - 1],
+                                         nameptr) &&
+                       *max)
+                   {
+                       --*max;
+                       (void) AddFontNamesName (names,
+                                                scaleNames->names[i - 1],
+                                                -scaleNames->length[i - 1]);
+                       names->length[names->nnames - 1] =
+                           -names->length[names->nnames - 1];
+                       (void) AddFontNamesName (names, aliasName,
+                                                strlen (aliasName));
+                   }
+               }
+           }
+       }
+    }
+}
+
+/* ARGSUSED */
+static int
+_FontFileListFonts (client, fpe, pat, len, max, names, mark_aliases)
+    pointer     client;
+    FontPathElementPtr fpe;
+    char       *pat;
+    int         len;
+    int         max;
+    FontNamesPtr names;
+    int                mark_aliases;
+{
+    FontDirectoryPtr   dir;
+    char               lowerChars[MAXFONTNAMELEN], zeroChars[MAXFONTNAMELEN];
+    FontNameRec                lowerName;
+    FontNameRec                zeroName;
+    FontNamesPtr       scaleNames;
+    FontScalableRec    vals;
+    int                        i;
+    fsRange            *ranges;
+    int                        nranges;
+    int                        result = BadFontName;
+
+    if (len >= MAXFONTNAMELEN)
+       return AllocError;
+    dir = (FontDirectoryPtr) fpe->private;
+    CopyISOLatin1Lowered (lowerChars, pat, len);
+    lowerChars[len] = '\0';
+    lowerName.name = lowerChars;
+    lowerName.length = len;
+    lowerName.ndashes = FontFileCountDashes (lowerChars, len);
+
+    /* Match XLFD patterns */
+
+    strcpy (zeroChars, lowerChars);
+    if (lowerName.ndashes == 14 &&
+       FontParseXLFDName (zeroChars, &vals, FONT_XLFD_REPLACE_ZERO))
+    {
+       ranges = FontParseRanges(lowerChars, &nranges);
+        result = FontFileFindNamesInScalableDir (&dir->nonScalable,
+                               &lowerName, max, names,
+                               (FontScalablePtr)0,
+                               (mark_aliases ?
+                                LIST_ALIASES_AND_TARGET_NAMES :
+                                NORMAL_ALIAS_BEHAVIOR) |
+                               IGNORE_SCALABLE_ALIASES,
+                               &max);
+       zeroName.name = zeroChars;
+       zeroName.length = strlen (zeroChars);
+       zeroName.ndashes = lowerName.ndashes;
+
+       /* Look for scalable names and aliases, adding scaled instances of
+          them to the output */
+
+       /* Scalable names... */
+       scaleNames = MakeFontNamesRecord (0);
+       if (!scaleNames)
+       {
+           if (ranges) xfree(ranges);
+           return AllocError;
+       }
+       FontFileFindNamesInScalableDir (&dir->scalable, &zeroName, max,
+                                       scaleNames, &vals,
+                                       mark_aliases ?
+                                       LIST_ALIASES_AND_TARGET_NAMES :
+                                       NORMAL_ALIAS_BEHAVIOR, (int *)0);
+       _FontFileAddScalableNames(names, scaleNames, &lowerName,
+                                 zeroChars, &vals, ranges, nranges,
+                                 &max);
+       FreeFontNames (scaleNames);
+
+       /* Scalable aliases... */
+       scaleNames = MakeFontNamesRecord (0);
+       if (!scaleNames)
+       {
+           if (ranges) xfree(ranges);
+           return AllocError;
+       }
+       FontFileFindNamesInScalableDir (&dir->nonScalable, &zeroName,
+                                       max, scaleNames, &vals,
+                                       mark_aliases ?
+                                       LIST_ALIASES_AND_TARGET_NAMES :
+                                       NORMAL_ALIAS_BEHAVIOR, (int *)0);
+       _FontFileAddScalableNames(names, scaleNames, &lowerName,
+                                 zeroChars, &vals, ranges, nranges,
+                                 &max);
+       FreeFontNames (scaleNames);
+
+       if (ranges) xfree(ranges);
+    }
+    else
+    {
+        result = FontFileFindNamesInScalableDir (&dir->nonScalable,
+                               &lowerName, max, names,
+                               (FontScalablePtr)0,
+                               mark_aliases ?
+                               LIST_ALIASES_AND_TARGET_NAMES :
+                               NORMAL_ALIAS_BEHAVIOR,
+                               &max);
+       if (result == Successful)
+           result = FontFileFindNamesInScalableDir (&dir->scalable,
+                               &lowerName, max, names,
+                               (FontScalablePtr)0,
+                               mark_aliases ?
+                               LIST_ALIASES_AND_TARGET_NAMES :
+                               NORMAL_ALIAS_BEHAVIOR, (int *)0);
+    }
+    return result;
+}
+
+typedef struct _LFWIData {
+    FontNamesPtr    names;
+    int                   current;
+} LFWIDataRec, *LFWIDataPtr;
+
+FontFileListFonts (client, fpe, pat, len, max, names)
+    pointer     client;
+    FontPathElementPtr fpe;
+    char       *pat;
+    int         len;
+    int         max;
+    FontNamesPtr names;
+{
+    return _FontFileListFonts (client, fpe, pat, len, max, names, 0);
+}
+
+FontFileStartListFontsWithInfo(client, fpe, pat, len, max, privatep)
+    pointer     client;
+    FontPathElementPtr fpe;
+    char       *pat;
+    int         len;
+    int         max;
+    pointer    *privatep;
+{
+    LFWIDataPtr        data;
+    int                ret;
+
+    data = (LFWIDataPtr) xalloc (sizeof *data);
+    if (!data)
+       return AllocError;
+    data->names = MakeFontNamesRecord (0);
+    if (!data->names)
+    {
+       xfree (data);
+       return AllocError;
+    }
+    ret = FontFileListFonts (client, fpe, pat, len, max, data->names);
+    if (ret != Successful)
+    {
+       FreeFontNames (data->names);
+       xfree (data);
+       return ret;
+    }
+    data->current = 0;
+    *privatep = (pointer) data;
+    return Successful;
+}
+
+/* ARGSUSED */
+static int
+FontFileListOneFontWithInfo (client, fpe, namep, namelenp, pFontInfo)
+    pointer            client;
+    FontPathElementPtr fpe;
+    char               **namep;
+    int                        *namelenp;
+    FontInfoPtr                *pFontInfo;
+{
+    FontDirectoryPtr   dir;
+    char               lowerName[MAXFONTNAMELEN];
+    char               fileName[MAXFONTFILENAMELEN*2 + 1];
+    FontNameRec                tmpName;
+    FontEntryPtr       entry;
+    FontScalableRec    vals;
+    FontScalableEntryPtr   scalable;
+    FontScaledPtr      scaled;
+    FontBitmapEntryPtr bitmap;
+    FontAliasEntryPtr  alias;
+    int                        ret;
+    char               *name = *namep;
+    int                        namelen = *namelenp;
+    Bool               noSpecificSize;
+    
+    if (namelen >= MAXFONTNAMELEN)
+       return AllocError;
+    dir = (FontDirectoryPtr) fpe->private;
+    CopyISOLatin1Lowered (lowerName, name, namelen);
+    lowerName[namelen] = '\0';
+    tmpName.name = lowerName;
+    tmpName.length = namelen;
+    tmpName.ndashes = FontFileCountDashes (lowerName, namelen);
+    /* Match XLFD patterns */
+    if (tmpName.ndashes == 14 &&
+       FontParseXLFDName (lowerName, &vals, FONT_XLFD_REPLACE_ZERO))
+    {
+       tmpName.length = strlen (lowerName);
+       entry = FontFileFindNameInScalableDir (&dir->scalable, &tmpName, &vals);
+       noSpecificSize = FALSE; /* TRUE breaks XLFD enhancements */
+       if (entry && entry->type == FONT_ENTRY_SCALABLE &&
+           FontFileCompleteXLFD (&vals, &entry->u.scalable.extra->defaults))
+       {
+           scalable = &entry->u.scalable;
+           scaled = FontFileFindScaledInstance (entry, &vals, noSpecificSize);
+           /*
+            * A scaled instance can occur one of two ways:
+            *
+            *  Either the font has been scaled to this
+            *   size already, in which case scaled->pFont
+            *   will point at that font.
+            *
+            *  Or a bitmap instance in this size exists,
+            *   which is handled as if we got a pattern
+            *   matching the bitmap font name.
+            */
+           if (scaled)
+           {
+               if (scaled->pFont)
+               {
+                   *pFontInfo = &scaled->pFont->info;
+                   ret = Successful;
+               }
+               else if (scaled->bitmap)
+               {
+                   entry = scaled->bitmap;
+                   bitmap = &entry->u.bitmap;
+                   if (bitmap->pFont)
+                   {
+                       *pFontInfo = &bitmap->pFont->info;
+                       ret = Successful;
+                   }
+                   else
+                   {
+                       ret = FontFileGetInfoBitmap (fpe, *pFontInfo, entry);
+                   }
+               }
+               else /* "cannot" happen */
+               {
+                   ret = BadFontName;
+               }
+           }
+           else
+           {
+#ifdef NOTDEF
+               /* no special case yet */
+               ret = FontFileMatchBitmapSource (fpe, pFont, flags, entry, &vals, format, fmask, noSpecificSize);
+               if (ret != Successful)
+#endif
+               {
+                   char origName[MAXFONTNAMELEN];
+                   fsRange *ranges;
+
+                   CopyISOLatin1Lowered (origName, name, namelen);
+                   origName[namelen] = '\0';
+                   vals.xlfdName = origName;
+                   vals.ranges = FontParseRanges(origName, &vals.nranges);
+                   ranges = vals.ranges;
+                   /* Make a new scaled instance */
+                   strcpy (fileName, dir->directory);
+                   strcat (fileName, scalable->fileName);
+                   ret = (*scalable->renderer->GetInfoScalable)
+                       (fpe, *pFontInfo, entry, &tmpName, fileName, &vals);
+                   if (ranges) xfree(ranges);
+               }
+           }
+           if (ret == Successful) return ret;
+       }
+       CopyISOLatin1Lowered (lowerName, name, namelen);
+       tmpName.length = namelen;
+    }
+    /* Match non XLFD pattern */
+    if (entry = FontFileFindNameInDir (&dir->nonScalable, &tmpName))
+    {
+       switch (entry->type) {
+       case FONT_ENTRY_BITMAP:
+           bitmap = &entry->u.bitmap;
+           if (bitmap->pFont)
+           {
+               *pFontInfo = &bitmap->pFont->info;
+               ret = Successful;
+           }
+           else
+           {
+               ret = FontFileGetInfoBitmap (fpe, *pFontInfo, entry);
+           }
+           break;
+       case FONT_ENTRY_ALIAS:
+           alias = &entry->u.alias;
+           *(char **)pFontInfo = name;
+           *namelenp = strlen (*namep = alias->resolved);
+           ret = FontNameAlias;
+           break;
+#ifdef NOTYET
+       case FONT_ENTRY_BC:
+           /* no LFWI for this yet */
+           bc = &entry->u.bc;
+           entry = bc->entry;
+           /* Make a new scaled instance */
+           strcpy (fileName, dir->directory);
+           strcat (fileName, scalable->fileName);
+           ret = (*scalable->renderer->GetInfoScalable)
+                   (fpe, *pFontInfo, entry, tmpName, fileName, &bc->vals);
+           break;
+#endif
+       default:
+           ret = BadFontName;
+       }
+    }
+    else
+    {
+       ret = BadFontName;
+    }
+    return ret;
+}
+
+FontFileListNextFontWithInfo(client, fpe, namep, namelenp, pFontInfo,
+                            numFonts, private)
+    pointer            client;
+    FontPathElementPtr fpe;
+    char               **namep;
+    int                        *namelenp;
+    FontInfoPtr                *pFontInfo;
+    int                        *numFonts;
+    pointer            private;
+{
+    LFWIDataPtr        data = (LFWIDataPtr) private;
+    int                ret;
+    char       *name;
+    int                namelen;
+
+    if (data->current == data->names->nnames)
+    {
+       FreeFontNames (data->names);
+       xfree (data);
+       return BadFontName;
+    }
+    name = data->names->names[data->current];
+    namelen = data->names->length[data->current];
+    ret = FontFileListOneFontWithInfo (client, fpe, &name, &namelen, pFontInfo);
+    if (ret == BadFontName)
+       ret = AllocError;
+    *namep = name;
+    *namelenp = namelen;
+    ++data->current;
+    *numFonts = data->names->nnames - data->current;
+    return ret;
+}
+
+int
+FontFileStartListFontsAndAliases(client, fpe, pat, len, max, privatep)
+    pointer     client;
+    FontPathElementPtr fpe;
+    char       *pat;
+    int         len;
+    int         max;
+    pointer    *privatep;
+{
+    LFWIDataPtr        data;
+    int                ret;
+
+    data = (LFWIDataPtr) xalloc (sizeof *data);
+    if (!data)
+       return AllocError;
+    data->names = MakeFontNamesRecord (0);
+    if (!data->names)
+    {
+       xfree (data);
+       return AllocError;
+    }
+    ret = _FontFileListFonts (client, fpe, pat, len, max, data->names, 1);
+    if (ret != Successful)
+    {
+       FreeFontNames (data->names);
+       xfree (data);
+       return ret;
+    }
+    data->current = 0;
+    *privatep = (pointer) data;
+    return Successful;
+}
+
+int
+FontFileListNextFontOrAlias(client, fpe, namep, namelenp, resolvedp,
+                           resolvedlenp, private)
+    pointer            client;
+    FontPathElementPtr fpe;
+    char               **namep;
+    int                        *namelenp;
+    char               **resolvedp;
+    int                        *resolvedlenp;
+    pointer            private;
+{
+    LFWIDataPtr        data = (LFWIDataPtr) private;
+    int                ret;
+    char       *name;
+    int                namelen;
+
+    if (data->current == data->names->nnames)
+    {
+       FreeFontNames (data->names);
+       xfree (data);
+       return BadFontName;
+    }
+    name = data->names->names[data->current];
+    namelen = data->names->length[data->current];
+
+    /* If this is a real font name... */
+    if (namelen >= 0)
+    {
+       *namep = name;
+       *namelenp = namelen;
+       ret = Successful;
+    }
+    /* Else if an alias */
+    else
+    {
+       /* Tell the caller that this is an alias... let him resolve it to
+          see if it's valid */
+       *namep = name;
+       *namelenp = -namelen;
+       *resolvedp = data->names->names[++data->current];
+       *resolvedlenp = data->names->length[data->current];
+       ret = FontNameAlias;
+    }
+
+    ++data->current;
+    return ret;
+}
+
+
+extern void FontFileEmptyBitmapSource();
+typedef int (*IntFunc) ();
+static int  font_file_type;
+
+FontFileRegisterLocalFpeFunctions ()
+{
+    font_file_type = RegisterFPEFunctions(FontFileNameCheck,
+                                         FontFileInitFPE,
+                                         FontFileFreeFPE,
+                                         FontFileResetFPE,
+                                         FontFileOpenFont,
+                                         FontFileCloseFont,
+                                         FontFileListFonts,
+                                         FontFileStartListFontsWithInfo,
+                                         FontFileListNextFontWithInfo,
+                                         (IntFunc) 0,
+                                         (IntFunc) 0,
+                                         (IntFunc) 0,
+                                         FontFileStartListFontsAndAliases,
+                                         FontFileListNextFontOrAlias,
+                                         FontFileEmptyBitmapSource);
+}
diff --git a/Xserver/lib/font/fontfile/fontscale.c b/Xserver/lib/font/fontfile/fontscale.c
new file mode 100644 (file)
index 0000000..4cc3dad
--- /dev/null
@@ -0,0 +1,455 @@
+/* $XConsortium: fontscale.c /main/15 1996/09/28 16:49:13 rws $ */
+/* $XFree86: xc/lib/font/fontfile/fontscale.c,v 3.4 1996/12/24 02:23:08 dawes Exp $ */
+
+/*
+
+Copyright (c) 1991  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+*/
+
+/*
+ * Author:  Keith Packard, MIT X Consortium
+ */
+
+#include    "fntfilst.h"
+#ifdef _XOPEN_SOURCE
+#include <math.h>
+#else
+#define _XOPEN_SOURCE  /* to get prototype for hypot on some systems */
+#include <math.h>
+#undef _XOPEN_SOURCE
+#endif
+
+Bool
+FontFileAddScaledInstance (entry, vals, pFont, bitmapName)
+    FontEntryPtr               entry;
+    FontScalablePtr            vals;
+    FontPtr                    pFont;
+    char                       *bitmapName;
+{
+    FontScalableEntryPtr    scalable;
+    FontScalableExtraPtr    extra;
+    FontScaledPtr          new;
+    int                            newsize;
+
+    scalable = &entry->u.scalable;
+    extra = scalable->extra;
+    if (extra->numScaled == extra->sizeScaled)
+    {
+       newsize = extra->sizeScaled + 4;
+       new = (FontScaledPtr) xrealloc (extra->scaled,
+                           newsize * sizeof (FontScaledRec));
+       if (!new)
+           return FALSE;
+       extra->sizeScaled = newsize;
+       extra->scaled = new;
+    }
+    new = &extra->scaled[extra->numScaled++];
+    new->vals = *vals;
+    new->pFont = pFont;
+    new->bitmap = (FontEntryPtr) bitmapName;
+    if (pFont)
+       pFont->fpePrivate = (pointer) entry;
+    return TRUE;
+}
+
+/* Must call this after the directory is sorted */
+
+FontFileSwitchStringsToBitmapPointers (dir)
+    FontDirectoryPtr   dir;
+{
+    int            s;
+    int            b;
+    int            i;
+    FontEntryPtr           scalable;
+    FontEntryPtr           nonScalable;
+    FontScaledPtr          scaled;
+    FontScalableExtraPtr    extra;
+    
+    scalable = dir->scalable.entries;
+    nonScalable = dir->nonScalable.entries;
+    for (s = 0; s < dir->scalable.used; s++)
+    {
+       extra = scalable[s].u.scalable.extra;
+       scaled = extra->scaled;
+       for (i = 0; i < extra->numScaled; i++)
+           for (b = 0; b < dir->nonScalable.used; b++)
+               if (nonScalable[b].name.name == (char *) scaled[i].bitmap)
+                   scaled[i].bitmap = &nonScalable[b];
+    }
+}
+
+void
+FontFileRemoveScaledInstance (entry, pFont)
+    FontEntryPtr       entry;
+    FontPtr            pFont;
+{
+    FontScalableEntryPtr    scalable;
+    FontScalableExtraPtr    extra;
+    int                            i;
+
+    scalable = &entry->u.scalable;
+    extra = scalable->extra;
+    for (i = 0; i < extra->numScaled; i++)
+    {
+       if (extra->scaled[i].pFont == pFont)
+       {
+           if (extra->scaled[i].vals.ranges)
+               xfree (extra->scaled[i].vals.ranges);
+           extra->numScaled--;
+           for (; i < extra->numScaled; i++)
+               extra->scaled[i] = extra->scaled[i+1];
+       }
+    }
+}
+
+Bool
+FontFileCompleteXLFD (vals, def)
+    register FontScalablePtr   vals;
+    FontScalablePtr    def;
+{
+    int                best;
+    FontResolutionPtr res;
+    int                num_res;
+    double     sx, sy, temp_matrix[4];
+    double     pixel_setsize_adjustment = 1.0;
+    /*
+     * If two of the three vertical scale values are specified, compute the
+     * third.  If all three are specified, make sure they are consistent
+     * (within a pixel)
+     *
+     * One purpose of this procedure is to complete XLFD names in a
+     * repeatable manner.  That is, if the user partially specifies
+     * a name (say, pixelsize but not pointsize), the results generated
+     * here result in a fully specified name that will result in the
+     * same font.
+     */
+
+    res = GetClientResolutions(&num_res);
+
+    if (!(vals->values_supplied & PIXELSIZE_MASK) ||
+       !(vals->values_supplied & POINTSIZE_MASK))
+    {
+       /* If resolution(s) unspecified and cannot be computed from
+          pixelsize and pointsize, get appropriate defaults. */
+
+       if (num_res)
+       {
+           if (vals->x <= 0)
+               vals->x = res->x_resolution;
+           if (vals->y <= 0)
+               vals->y = res->y_resolution;
+       }
+
+       if (vals->x <= 0)
+           vals->x = def->x;
+       if (vals->y <= 0)
+           vals->y = def->y;
+    }
+    else
+    {
+       /* If needed, compute resolution values from the pixel and
+          pointsize information we were given.  This problem is
+          overdetermined (four equations, two unknowns), but we don't
+          check for inconsistencies here.  If they exist, they will
+          show up in later tests for the point and pixel sizes.  */
+
+       if (vals->y <= 0)
+       {
+           double x = hypot(vals->pixel_matrix[1], vals->pixel_matrix[3]);
+           double y = hypot(vals->point_matrix[1], vals->point_matrix[3]);
+           if (y < EPS) return FALSE;
+           vals->y = (int)(x * 72.27 / y + .5);
+       }
+       if (vals->x <= 0)
+       {
+           /* If the pixelsize was given as an array, or as a scalar that
+              has been normalized for the pixel shape, we have enough
+              information to compute a separate horizontal resolution */
+
+           if ((vals->values_supplied & PIXELSIZE_MASK) == PIXELSIZE_ARRAY ||
+               (vals->values_supplied & PIXELSIZE_MASK) ==
+                   PIXELSIZE_SCALAR_NORMALIZED)
+           {
+               double x = hypot(vals->pixel_matrix[0], vals->pixel_matrix[2]);
+               double y = hypot(vals->point_matrix[0], vals->point_matrix[2]);
+               if (y < EPS) return FALSE;
+               vals->x = (int)(x * 72.27 / y + .5);
+           }
+           else
+           {
+               /* Not enough information in the pixelsize array.  Just
+                  assume the pixels are square. */
+               vals->x = vals->y;
+           }
+       }
+    }
+
+    if (vals->x <= 0 || vals->y <= 0) return FALSE;
+
+    /* If neither pixelsize nor pointsize is defined, take the pointsize
+       from the defaults structure we've been passed. */
+    if (!(vals->values_supplied & PIXELSIZE_MASK) &&
+       !(vals->values_supplied & POINTSIZE_MASK))
+    {
+       if (num_res)
+       {
+           vals->point_matrix[0] =
+           vals->point_matrix[3] = (double)res->point_size / 10.0;
+           vals->point_matrix[1] =
+           vals->point_matrix[2] = 0;
+           vals->values_supplied = (vals->values_supplied & ~POINTSIZE_MASK) |
+                                   POINTSIZE_SCALAR;
+       }
+       else if (def->values_supplied & POINTSIZE_MASK)
+       {
+           vals->point_matrix[0] = def->point_matrix[0];
+           vals->point_matrix[1] = def->point_matrix[1];
+           vals->point_matrix[2] = def->point_matrix[2];
+           vals->point_matrix[3] = def->point_matrix[3];
+           vals->values_supplied = (vals->values_supplied & ~POINTSIZE_MASK) |
+                                   (def->values_supplied & POINTSIZE_MASK);
+       }
+       else return FALSE;
+    }
+
+    /* At this point, at least two of the three vertical scale values
+       should be specified.  Our job now is to compute the missing ones
+       and check for agreement between overspecified values */
+
+    /* If pixelsize was specified by a scalar, we need to fix the matrix
+       now that we know the resolutions.  */
+    if ((vals->values_supplied & PIXELSIZE_MASK) == PIXELSIZE_SCALAR)
+    {
+       /* pixel_setsize_adjustment used below to modify permissible
+          error in pixel/pointsize matching, since multiplying a
+          number rounded to integer changes the amount of the error
+          caused by the rounding */
+
+       pixel_setsize_adjustment = (double)vals->x / (double)vals->y;
+       vals->pixel_matrix[0] *= pixel_setsize_adjustment;
+       vals->values_supplied  = vals->values_supplied & ~PIXELSIZE_MASK |
+                                PIXELSIZE_SCALAR_NORMALIZED;
+    }
+
+    sx = (double)vals->x / 72.27;
+    sy = (double)vals->y / 72.27;
+
+    /* If a pointsize was specified, make sure pixelsize is consistent
+       to within 1 pixel, then replace pixelsize with a consistent
+       floating-point value.  */
+
+    if (vals->values_supplied & POINTSIZE_MASK)
+    {
+    recompute_pixelsize: ;
+       temp_matrix[0] = vals->point_matrix[0] * sx;
+       temp_matrix[1] = vals->point_matrix[1] * sy;
+       temp_matrix[2] = vals->point_matrix[2] * sx;
+       temp_matrix[3] = vals->point_matrix[3] * sy;
+       if (vals->values_supplied & PIXELSIZE_MASK)
+       {
+           if (fabs(vals->pixel_matrix[0] - temp_matrix[0]) >
+                   pixel_setsize_adjustment ||
+               fabs(vals->pixel_matrix[1] - temp_matrix[1]) > 1 ||
+               fabs(vals->pixel_matrix[2] - temp_matrix[2]) > 1 ||
+               fabs(vals->pixel_matrix[3] - temp_matrix[3]) > 1)
+               return FALSE;
+       }
+       if ((vals->values_supplied & PIXELSIZE_MASK) == PIXELSIZE_ARRAY &&
+           (vals->values_supplied & POINTSIZE_MASK) == POINTSIZE_SCALAR)
+       {
+           /* In the special case that pixelsize came as an array and
+              pointsize as a scalar, recompute the pointsize matrix
+              from the pixelsize matrix. */
+           goto recompute_pointsize;
+       }
+
+       /* Refresh pixel matrix with precise values computed from
+          pointsize and resolution.  */
+       vals->pixel_matrix[0] = temp_matrix[0];
+       vals->pixel_matrix[1] = temp_matrix[1];
+       vals->pixel_matrix[2] = temp_matrix[2];
+       vals->pixel_matrix[3] = temp_matrix[3];
+
+       /* Set values_supplied for pixel to match that for point */
+       vals->values_supplied =
+           (vals->values_supplied & ~PIXELSIZE_MASK) |
+           (((vals->values_supplied & POINTSIZE_MASK) == POINTSIZE_ARRAY) ?
+               PIXELSIZE_ARRAY : PIXELSIZE_SCALAR_NORMALIZED);
+    }
+    else
+    {
+       /* Pointsize unspecified...  compute from pixel size and
+          resolutions */
+    recompute_pointsize: ;
+       if (fabs(sx) < EPS || fabs(sy) < EPS) return FALSE;
+       vals->point_matrix[0] = vals->pixel_matrix[0] / sx;
+       vals->point_matrix[1] = vals->pixel_matrix[1] / sy;
+       vals->point_matrix[2] = vals->pixel_matrix[2] / sx;
+       vals->point_matrix[3] = vals->pixel_matrix[3] / sy;
+
+       /* Set values_supplied for pixel to match that for point */
+       vals->values_supplied =
+           (vals->values_supplied & ~POINTSIZE_MASK) |
+           (((vals->values_supplied & PIXELSIZE_MASK) == PIXELSIZE_ARRAY) ?
+               POINTSIZE_ARRAY : POINTSIZE_SCALAR);
+
+       /* If we computed scalar pointsize from scalar pixelsize, round
+          pointsize to decipoints and recompute pixelsize so we end up
+          with a repeatable name */
+       if ((vals->values_supplied & POINTSIZE_MASK) == POINTSIZE_SCALAR)
+       {
+           /* Off-diagonal elements should be zero since no matrix was
+              specified. */
+           vals->point_matrix[0] =
+               (double)(int)(vals->point_matrix[0] * 10.0 + .5) / 10.0;
+           vals->point_matrix[3] =
+               (double)(int)(vals->point_matrix[3] * 10.0 + .5) / 10.0;
+           goto recompute_pixelsize;
+       }
+    }
+
+    /* We've succeeded.  Round everything to a few decimal places
+       for repeatability. */
+
+    vals->pixel_matrix[0] = xlfd_round_double(vals->pixel_matrix[0]);
+    vals->pixel_matrix[1] = xlfd_round_double(vals->pixel_matrix[1]);
+    vals->pixel_matrix[2] = xlfd_round_double(vals->pixel_matrix[2]);
+    vals->pixel_matrix[3] = xlfd_round_double(vals->pixel_matrix[3]);
+    vals->point_matrix[0] = xlfd_round_double(vals->point_matrix[0]);
+    vals->point_matrix[1] = xlfd_round_double(vals->point_matrix[1]);
+    vals->point_matrix[2] = xlfd_round_double(vals->point_matrix[2]);
+    vals->point_matrix[3] = xlfd_round_double(vals->point_matrix[3]);
+
+    /* Fill in the deprecated fields for the benefit of rasterizers
+       that do not handle the matrices. */
+    vals->point = vals->point_matrix[3] * 10;
+    vals->pixel = vals->pixel_matrix[3];
+
+    return TRUE;
+}
+
+static Bool
+MatchScalable (a, b)
+    FontScalablePtr    a, b;
+{
+    int i;
+
+    /* Some asymmetry here:  we assume that the first argument (a) is
+       the table entry and the second (b) the item we're trying to match
+       (the key).  We'll consider the fonts matched if the relevant
+       metrics match *and* if a) the table entry doesn't have charset
+       subsetting or b) the table entry has identical charset subsetting
+       to that in the key.  We could add logic to check if the table
+       entry has a superset of the charset required by the key, but
+       we'll resist the urge for now.  */
+
+#define EQUAL(a,b) ((a)[0] == (b)[0] && \
+                    (a)[1] == (b)[1] && \
+                    (a)[2] == (b)[2] && \
+                    (a)[3] == (b)[3])
+
+    if (!(a->x == b->x &&
+         a->y == b->y &&
+         (a->width == b->width || a->width == 0 || b->width == 0) &&
+         (!(b->values_supplied & PIXELSIZE_MASK) ||
+           (a->values_supplied & PIXELSIZE_MASK) ==
+           (b->values_supplied & PIXELSIZE_MASK) &&
+           EQUAL(a->pixel_matrix, b->pixel_matrix)) &&
+         (!(b->values_supplied & POINTSIZE_MASK) ||
+           (a->values_supplied & POINTSIZE_MASK) ==
+           (b->values_supplied & POINTSIZE_MASK) &&
+           EQUAL(a->point_matrix, b->point_matrix)) &&
+         (a->nranges == 0 || a->nranges == b->nranges)))
+      return FALSE;
+
+    for (i = 0; i < a->nranges; i++)
+       if (a->ranges[i].min_char_low != b->ranges[i].min_char_low ||
+           a->ranges[i].min_char_high != b->ranges[i].min_char_high ||
+           a->ranges[i].max_char_low != b->ranges[i].max_char_low ||
+           a->ranges[i].max_char_high != b->ranges[i].max_char_high)
+               return FALSE;
+    return TRUE;
+}
+
+FontScaledPtr
+FontFileFindScaledInstance (entry, vals, noSpecificSize)
+    FontEntryPtr       entry;
+    FontScalablePtr    vals;
+{
+    FontScalableEntryPtr    scalable;
+    FontScalableExtraPtr    extra;
+    FontScalablePtr        mvals;
+    int                            dist, i;
+    int                            mini;
+    double                 mindist;
+    register double        temp, sum=0.0;
+
+#define NORMDIFF(a, b) ( \
+    temp = (a)[0] - (b)[0], \
+    sum = temp * temp, \
+    temp = (a)[1] - (b)[1], \
+    sum += temp * temp, \
+    temp = (a)[2] - (b)[2], \
+    sum += temp * temp, \
+    temp = (a)[3] - (b)[3], \
+    sum + temp * temp )
+
+    scalable = &entry->u.scalable;
+    extra = scalable->extra;
+    if (noSpecificSize && extra->numScaled)
+    {
+       mini = 0;
+       mindist = NORMDIFF(extra->scaled[0].vals.point_matrix,
+                          vals->point_matrix);
+       for (i = 1; i < extra->numScaled; i++)
+       {
+           if (extra->scaled[i].pFont &&
+               !extra->scaled[i].pFont->info.cachable) continue;
+           mvals = &extra->scaled[i].vals;
+           dist = NORMDIFF(mvals->point_matrix, vals->point_matrix);
+           if (dist < mindist)
+           {
+               mindist = dist;
+               mini = i;
+           }
+       }
+       if (extra->scaled[mini].pFont &&
+           !extra->scaled[mini].pFont->info.cachable) return 0;
+       return &extra->scaled[mini];
+    }
+    else
+    {
+       /* See if we've scaled to this value yet */
+       for (i = 0; i < extra->numScaled; i++)
+       {
+           if (extra->scaled[i].pFont &&
+               !extra->scaled[i].pFont->info.cachable) continue;
+           if (MatchScalable (&extra->scaled[i].vals, vals))
+               return &extra->scaled[i];
+       }
+    }
+    return 0;
+}
diff --git a/Xserver/lib/font/fontfile/gunzip.c b/Xserver/lib/font/fontfile/gunzip.c
new file mode 100644 (file)
index 0000000..6cf045a
--- /dev/null
@@ -0,0 +1,224 @@
+/* $XConsortium: gunzip.c /main/1 1996/11/03 19:33:23 kaleb $ */
+/* lib/font/fontfile/gunzip.c
+   written by Mark Eichin <eichin@kitten.gen.ma.us> September 1996.
+   intended for inclusion in X11 public releases. */
+
+#include "fontmisc.h"
+#include <bufio.h>
+#include <zlib.h>
+
+typedef struct _xzip_buf {
+  z_stream z;
+  int zstat;
+  BufChar b[BUFFILESIZE];
+  BufChar b_in[BUFFILESIZE];
+  BufFilePtr f;
+} xzip_buf;
+
+static int BufZipFileSkip();   /* f, count */
+static int BufZipFileFill();   /* read: f;  write: char, f */
+static int BufZipFileClose();  /* f, flag */
+static int BufCheckZipHeader();        /* f */
+
+BufFilePtr
+BufFilePushZIP (f)
+    BufFilePtr f;
+{
+  xzip_buf *x;
+
+  x = (xzip_buf *) xalloc (sizeof (xzip_buf));
+  if (!x) return 0;
+  /* these are just for raw calloc/free */
+  x->z.zalloc = Z_NULL;
+  x->z.zfree = Z_NULL;
+  x->z.opaque = Z_NULL;
+  x->f = f;
+
+  /* force inflateInit to allocate it's own history buffer */
+  x->z.next_in = Z_NULL;
+  x->z.next_out = Z_NULL;
+  x->z.avail_in = x->z.avail_out = 0;
+
+  /* using negative windowBits sets "nowrap" mode, which turns off
+     zlib header checking [undocumented, for gzip compatibility only?] */
+  x->zstat = inflateInit2(&(x->z), -MAX_WBITS);
+  if (x->zstat != Z_OK) {
+    xfree(x);
+    return 0;
+  }
+
+  /* now that the history buffer is allocated, we provide the data buffer */
+  x->z.next_out = x->b;
+  x->z.avail_out = BUFFILESIZE;
+  x->z.next_out = x->b_in;
+  x->z.avail_in = 0;
+
+  if (BufCheckZipHeader(x->f)) {
+    xfree(x);
+    return 0;
+  }
+
+  return BufFileCreate(x,
+                      BufZipFileFill,
+                      BufZipFileSkip,
+                      BufZipFileClose);
+}
+
+static int BufZipFileClose(f, flag)
+     BufFilePtr f;
+     int flag;
+{
+  xzip_buf *x = (xzip_buf *)f->private;
+  inflateEnd (&(x->z));
+  BufFileClose (x->f, flag);
+  xfree (x);
+  return 1;
+}
+
+/* here's the real work. 
+   -- we need to put stuff in f.buffer, update f.left and f.bufp,
+      then return the first byte (or BUFFILEEOF).
+   -- to do this, we need to get stuff into avail_in, and next_in, 
+      and call inflate appropriately.
+   -- we may also need to add CRC maintenance - if inflate tells us
+      Z_STREAM_END, we then have 4bytes CRC and 4bytes length...
+   gzio.c:gzread shows most of the mechanism.
+   */
+static int BufZipFileFill (f)
+    BufFilePtr     f;
+{
+  xzip_buf *x = (xzip_buf *)f->private;
+
+  /* we only get called when left == 0... */
+  /* but just in case, deal */
+  if (f->left >= 0) {
+    f->left--;
+    return *(f->bufp++);
+  }
+  /* did we run out last time? */
+  switch (x->zstat) {
+  case Z_OK:
+    break;
+  case Z_STREAM_END:
+  case Z_DATA_ERROR:
+  case Z_ERRNO:
+    return BUFFILEEOF;
+  default:
+    return BUFFILEEOF;
+  }
+  /* now we work to consume what we can */
+  /* let zlib know what we can handle */
+  x->z.next_out = x->b;
+  x->z.avail_out = BUFFILESIZE;
+
+  /* and try to consume all of it */
+  while (x->z.avail_out > 0) {
+    /* if we don't have anything to work from... */
+    if (x->z.avail_in == 0) {
+      /* ... fill the z buf from underlying file */
+      int i, c;
+      for (i = 0; i < sizeof(x->b_in); i++) {
+       c = BufFileGet(x->f);
+       if (c == BUFFILEEOF) break;
+       x->b_in[i] = c;
+      }
+      x->z.avail_in += i;
+      x->z.next_in = x->b_in;
+    }
+    /* so now we have some output space and some input data */
+    x->zstat = inflate(&(x->z), Z_NO_FLUSH);
+    /* the inflation output happens in the f buffer directly... */
+    if (x->zstat == Z_STREAM_END) {
+      /* deal with EOF, crc */
+      break;
+    }
+    if (x->zstat != Z_OK) {
+      break;
+    }
+  }
+  f->bufp = x->b;
+  f->left = BUFFILESIZE - x->z.avail_out;  
+
+  if (f->left >= 0) {
+    f->left--;
+    return *(f->bufp++);
+  } else {
+    return BUFFILEEOF;
+  }
+}
+
+/* there should be a BufCommonSkip... */
+static int BufZipFileSkip (f, c)
+     BufFilePtr        f;
+     int c;
+{
+  /* BufFileRawSkip returns the count unchanged.
+     BufCompressedSkip returns 0.
+     That means it probably never gets called... */
+  int retval = c;
+  while(c--) {
+    int get = BufFileGet(f);
+    if (get == BUFFILEEOF) return get;
+  }
+  return retval;
+}
+
+/* now we need to duplicate check_header */
+/* contents:
+     0x1f, 0x8b        -- magic number
+     1 byte    -- method (Z_DEFLATED)
+     1 byte    -- flags (mask with RESERVED -> fail)
+     4 byte    -- time (discard)
+     1 byte    -- xflags (discard)
+     1 byte    -- "os" code (discard)
+     [if flags & EXTRA_FIELD:
+         2 bytes -- LSBfirst length n
+        n bytes -- extra data (discard)]
+     [if flags & ORIG_NAME:
+        n bytes -- null terminated name (discard)]
+     [if flags & COMMENT:
+        n bytes -- null terminated comment (discard)]
+     [if flags & HEAD_CRC:
+         2 bytes -- crc of headers? (discard)]
+ */
+
+/* gzip flag byte -- from gzio.c */
+#define ASCII_FLAG   0x01 /* bit 0 set: file probably ascii text */
+#define HEAD_CRC     0x02 /* bit 1 set: header CRC present */
+#define EXTRA_FIELD  0x04 /* bit 2 set: extra field present */
+#define ORIG_NAME    0x08 /* bit 3 set: original file name present */
+#define COMMENT      0x10 /* bit 4 set: file comment present */
+#define RESERVED     0xE0 /* bits 5..7: reserved */
+
+#define GET(f) do {c = BufFileGet(f); if (c == BUFFILEEOF) return c;} while(0)
+static int BufCheckZipHeader(f)
+     BufFilePtr f;
+{
+  int c, flags;
+  GET(f); if (c != 0x1f) return 1; /* magic 1 */
+  GET(f); if (c != 0x8b) return 2; /* magic 2 */
+  GET(f); if (c != Z_DEFLATED) return 3; /* method */
+  GET(f); if (c & RESERVED) return 4; /* reserved flags */
+  flags = c;
+  GET(f); GET(f); GET(f); GET(f); /* time */
+  GET(f);                      /* xflags */
+  GET(f);                      /* os code */
+  if (flags & EXTRA_FIELD) {
+    int len;
+    GET(f); len = c;
+    GET(f); len += (c<<8);
+    while (len-- >= 0) {
+      GET(f);
+    }
+  }
+  if (flags & ORIG_NAME) {
+    do { GET(f); } while (c != 0);
+  }
+  if (flags & COMMENT) {
+    do { GET(f); } while (c != 0);
+  }
+  if (flags & HEAD_CRC) {
+    GET(f); GET(f);            /* header crc */
+  }
+  return 0;
+}
diff --git a/Xserver/lib/font/fontfile/printerfont.c b/Xserver/lib/font/fontfile/printerfont.c
new file mode 100644 (file)
index 0000000..921de0c
--- /dev/null
@@ -0,0 +1,212 @@
+/* $XConsortium: printerfont.c /main/1 1996/09/28 16:49:21 rws $ */
+
+/*
+
+Copyright (c) 1991  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+*/
+
+/*
+ * Author:  Keith Packard, MIT X Consortium
+ */
+/* $NCDId: @(#)fontfile.c,v 1.6 1991/07/02 17:00:46 lemke Exp $ */
+
+#include    "fntfilst.h"
+
+/*
+ * Map FPE functions to renderer functions
+ */
+
+extern int FontFileInitFPE();
+extern int FontFileResetFPE();
+extern int FontFileFreeFPE();
+extern void FontFileCloseFont();
+#define PRINTERPATHPREFIX  "PRINTER:"
+
+/* STUB
+int XpClientIsPrintClient(client,fpe)
+pointer                client;
+FontPathElementPtr     fpe;
+{ return 1; }
+ */
+
+int
+PrinterFontNameCheck (name)
+    char    *name;
+{
+    if (strncmp(name,PRINTERPATHPREFIX,strlen(PRINTERPATHPREFIX)) != 0)
+       return 0;
+    name += strlen(PRINTERPATHPREFIX);
+#ifndef NCD
+    return *name == '/';
+#else
+    return ((strcmp(name, "built-ins") == 0) || (*name == '/'));
+#endif
+}
+
+int
+PrinterFontInitFPE (fpe)
+    FontPathElementPtr fpe;
+{
+    int                        status;
+    FontDirectoryPtr   dir;
+    char *             name;
+
+    name = fpe->name + strlen(PRINTERPATHPREFIX);
+    status = FontFileReadDirectory (name, &dir);
+    if (status == Successful)
+    {
+       if (dir->nonScalable.used > 0)
+           if (!FontFileRegisterBitmapSource (fpe))
+           {
+               FontFileFreeFPE (fpe);
+               return AllocError;
+           }
+       fpe->private = (pointer) dir;
+    }
+    return status;
+}
+
+/* Here we must check the client to see if it has a context attached to
+ * it that allows us to access the printer fonts
+ */
+
+int
+PrinterFontOpenFont (client, fpe, flags, name, namelen, format, fmask,
+                 id, pFont, aliasName, non_cachable_font)
+    pointer            client;
+    FontPathElementPtr fpe;
+    int                        flags;
+    char               *name;
+    int                        namelen;
+    fsBitmapFormat     format;
+    fsBitmapFormatMask fmask;
+    XID                        id;
+    FontPtr            *pFont;
+    char               **aliasName;
+    FontPtr            non_cachable_font;
+{
+    if (XpClientIsPrintClient(client,fpe))
+       return (FontFileOpenFont  (client, fpe, flags, name, namelen, format, 
+               fmask, id, pFont, aliasName, non_cachable_font));
+    return BadFontName;
+}
+
+PrinterFontListFonts (client, fpe, pat, len, max, names)
+    pointer     client;
+    FontPathElementPtr fpe;
+    char       *pat;
+    int         len;
+    int         max;
+    FontNamesPtr names;
+{
+    if (XpClientIsPrintClient(client,fpe))
+       return FontFileListFonts (client, fpe, pat, len, max, names);
+    return BadFontName;
+}
+
+PrinterFontStartListFontsWithInfo(client, fpe, pat, len, max, privatep)
+    pointer     client;
+    FontPathElementPtr fpe;
+    char       *pat;
+    int         len;
+    int         max;
+    pointer    *privatep;
+{
+    if (XpClientIsPrintClient(client,fpe))
+       return FontFileStartListFontsWithInfo(client, fpe, pat, len, 
+                               max, privatep);
+    return BadFontName;
+}
+
+PrinterFontListNextFontWithInfo(client, fpe, namep, namelenp, pFontInfo,
+                            numFonts, private)
+    pointer            client;
+    FontPathElementPtr fpe;
+    char               **namep;
+    int                        *namelenp;
+    FontInfoPtr                *pFontInfo;
+    int                        *numFonts;
+    pointer            private;
+{
+    if (XpClientIsPrintClient(client,fpe))
+       return FontFileListNextFontWithInfo(client, fpe, namep, namelenp, 
+                               pFontInfo, numFonts, private);
+    return BadFontName;
+}
+
+PrinterFontStartListFontsAndAliases(client, fpe, pat, len, max, privatep)
+    pointer     client;
+    FontPathElementPtr fpe;
+    char       *pat;
+    int         len;
+    int         max;
+    pointer    *privatep;
+{
+    if (XpClientIsPrintClient(client,fpe))
+       return FontFileStartListFontsAndAliases(client, fpe, pat, len, 
+                               max, privatep);
+    return BadFontName;
+}
+
+int
+PrinterFontListNextFontOrAlias(client, fpe, namep, namelenp, resolvedp,
+                           resolvedlenp, private)
+    pointer            client;
+    FontPathElementPtr fpe;
+    char               **namep;
+    int                        *namelenp;
+    char               **resolvedp;
+    int                        *resolvedlenp;
+    pointer            private;
+{
+    if (XpClientIsPrintClient(client,fpe))
+       return FontFileListNextFontOrAlias(client, fpe, namep, namelenp, 
+                               resolvedp, resolvedlenp, private);
+    return BadFontName;
+}
+
+extern void FontFileEmptyBitmapSource();
+typedef int (*IntFunc) ();
+static int  printer_font_type;
+
+PrinterFontRegisterFpeFunctions ()
+{
+    /* what is the use of printer font type? */
+    printer_font_type = RegisterFPEFunctions(PrinterFontNameCheck,
+                                         PrinterFontInitFPE,
+                                         FontFileFreeFPE,
+                                         FontFileResetFPE,
+                                         PrinterFontOpenFont,
+                                         FontFileCloseFont,
+                                         PrinterFontListFonts,
+                                         PrinterFontStartListFontsWithInfo,
+                                         PrinterFontListNextFontWithInfo,
+                                         (IntFunc) 0,
+                                         (IntFunc) 0,
+                                         (IntFunc) 0,
+                                         PrinterFontStartListFontsAndAliases,
+                                         PrinterFontListNextFontOrAlias,
+                                         FontFileEmptyBitmapSource);
+}
diff --git a/Xserver/lib/font/fontfile/register.c b/Xserver/lib/font/fontfile/register.c
new file mode 100644 (file)
index 0000000..1dc8866
--- /dev/null
@@ -0,0 +1,45 @@
+/* $XConsortium: register.c,v 1.3 94/04/17 20:17:07 gildea Exp $ */
+
+/*
+
+Copyright (c) 1994  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+*/
+
+/*
+ * This is in a separate source file so that small programs
+ * such as mkfontdir that want to use the fontfile utilities don't
+ * end up dragging in code from all the renderers, which is not small.
+ */
+
+FontFileRegisterFpeFunctions()
+{
+    BitmapRegisterFontFileFunctions ();
+#ifndef CRAY
+    SpeedoRegisterFontFileFunctions ();
+    Type1RegisterFontFileFunctions();
+#endif
+
+    FontFileRegisterLocalFpeFunctions ();
+}
diff --git a/Xserver/lib/font/fontfile/renderers.c b/Xserver/lib/font/fontfile/renderers.c
new file mode 100644 (file)
index 0000000..16c5279
--- /dev/null
@@ -0,0 +1,78 @@
+/* $XConsortium: renderers.c,v 1.5 94/04/17 20:17:08 gildea Exp $ */
+
+/*
+
+Copyright (c) 1991  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+*/
+
+/*
+ * Author:  Keith Packard, MIT X Consortium
+ */
+
+#include "fntfilst.h"
+
+static FontRenderersRec        renderers;
+
+Bool
+FontFileRegisterRenderer (renderer)
+    FontRendererPtr renderer;
+{
+    int                    i;
+    FontRendererPtr *new;
+
+    for (i = 0; i < renderers.number; i++)
+       if (!strcmp (renderers.renderers[i]->fileSuffix, renderer->fileSuffix))
+           return TRUE;
+    i = renderers.number + 1;
+    new = (FontRendererPtr *) xrealloc (renderers.renderers, sizeof *new * i);
+    if (!new)
+       return FALSE;
+    renderer->number = i - 1;
+    renderers.renderers = new;
+    renderers.renderers[i - 1] = renderer;
+    renderers.number = i;
+    return TRUE;
+}
+
+FontRendererPtr
+FontFileMatchRenderer (fileName)
+    char    *fileName;
+{
+    int                        i;
+    int                        fileLen;
+    FontRendererPtr    r;
+    
+    fileLen = strlen (fileName);
+    for (i = 0; i < renderers.number; i++)
+    {
+       r = renderers.renderers[i];
+       if (fileLen >= r->fileSuffixLen &&
+           !strcmp (fileName + fileLen - r->fileSuffixLen, r->fileSuffix))
+       {
+           return r;
+       }
+    }
+    return 0;
+}
diff --git a/Xserver/lib/font/include/bitmap.h b/Xserver/lib/font/include/bitmap.h
new file mode 100644 (file)
index 0000000..f404850
--- /dev/null
@@ -0,0 +1,74 @@
+/* $XConsortium: bitmap.h,v 1.5 94/04/17 20:17:27 gildea Exp $ */
+
+/*
+
+Copyright (c) 1990  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be included
+in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR
+OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall
+not be used in advertising or otherwise to promote the sale, use or
+other dealings in this Software without prior written authorization
+from the X Consortium.
+
+*/
+
+/*
+ * Author:  Keith Packard, MIT X Consortium
+ */
+
+#ifndef _BITMAP_H_
+#define _BITMAP_H_
+
+#include <fntfilio.h>
+#include <stdio.h>  /* just for NULL */
+
+/*
+ * Internal format used to store bitmap fonts
+ */
+
+typedef struct _BitmapExtra {
+    Atom       *glyphNames;
+    int        *sWidths;
+    CARD32      bitmapsSizes[GLYPHPADOPTIONS];
+    FontInfoRec info;
+}           BitmapExtraRec, *BitmapExtraPtr;
+
+typedef struct _BitmapFont {
+    unsigned    version_num;
+    int         num_chars;
+    int         num_tables;
+    CharInfoPtr metrics;       /* font metrics, including glyph pointers */
+    xCharInfo  *ink_metrics;   /* ink metrics */
+    char       *bitmaps;       /* base of bitmaps, useful only to free */
+    CharInfoPtr *encoding;     /* array of char info pointers */
+    CharInfoPtr pDefault;      /* default character */
+    BitmapExtraPtr bitmapExtra;        /* stuff not used by X server */
+}           BitmapFontRec, *BitmapFontPtr;
+
+extern int  bitmapReadFont(), bitmapReadFontInfo();
+extern int  bitmapGetGlyphs(), bitmapGetMetrics();
+extern int  bitmapGetBitmaps(), bitmapGetExtents();
+extern void bitmapUnloadFont();
+
+extern void bitmapComputeFontBounds();
+extern void bitmapComputeFontInkBounds();
+
+#endif                         /* _BITMAP_H_ */
diff --git a/Xserver/lib/font/include/bufio.h b/Xserver/lib/font/include/bufio.h
new file mode 100644 (file)
index 0000000..4126c81
--- /dev/null
@@ -0,0 +1,72 @@
+/* $XConsortium: bufio.h /main/5 1996/11/03 19:32:07 kaleb $ */
+
+/*
+
+Copyright (c) 1993  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be included
+in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR
+OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall
+not be used in advertising or otherwise to promote the sale, use or
+other dealings in this Software without prior written authorization
+from the X Consortium.
+
+*/
+
+#ifdef TEST
+
+#define xalloc(s)   malloc(s)
+#define xfree(s)    free(s)
+
+#endif
+
+#define BUFFILESIZE    8192
+#define BUFFILEEOF     -1
+
+typedef unsigned char BufChar;
+
+typedef struct _buffile {
+    BufChar *bufp;
+    int            left;
+    BufChar buffer[BUFFILESIZE];
+    int            (*io)(/* BufFilePtr f */);
+    int            (*skip)(/* BufFilePtr f, int count */);
+    int            (*close)(/* BufFilePtr f */);
+    char    *private;
+} BufFileRec, *BufFilePtr;
+
+extern BufFilePtr   BufFileCreate ();
+extern BufFilePtr   BufFileOpenRead (), BufFileOpenWrite ();
+extern BufFilePtr   BufFilePushCompressed ();
+#ifdef X_GZIP_FONT_COMPRESSION
+extern BufFilePtr   BufFilePushZIP ();
+#endif
+extern int         BufFileClose ();
+extern int         BufFileFlush ();
+#define BufFileGet(f)  ((f)->left-- ? *(f)->bufp++ : (*(f)->io) (f))
+#define BufFilePut(c,f)        (--(f)->left ? *(f)->bufp++ = (c) : (*(f)->io) (c,f))
+#define BufFileSkip(f,c)    ((*(f)->skip) (f, c))
+
+#ifndef TRUE
+#define TRUE 1
+#endif
+#ifndef FALSE
+#define FALSE 0
+#endif
diff --git a/Xserver/lib/font/include/fntfil.h b/Xserver/lib/font/include/fntfil.h
new file mode 100644 (file)
index 0000000..8e4038f
--- /dev/null
@@ -0,0 +1,81 @@
+/* $XConsortium: fntfil.h,v 1.5 94/04/17 20:17:28 gildea Exp $ */
+
+/*
+
+Copyright (c) 1991  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+*/
+
+/*
+ * Author:  Keith Packard, MIT X Consortium
+ */
+
+#ifndef _FONTFILE_H_
+#define _FONTFILE_H_
+typedef struct _FontEntry          *FontEntryPtr;
+typedef struct _FontTable          *FontTablePtr;
+typedef struct _FontName           *FontNamePtr;
+typedef struct _FontScaled         *FontScaledPtr;
+typedef struct _FontScalableExtra   *FontScalableExtraPtr;
+typedef struct _FontScalableEntry   *FontScalableEntryPtr;
+typedef struct _FontScaleAliasEntry *FontScaleAliasEntryPtr;
+typedef struct _FontBitmapEntry            *FontBitmapEntryPtr;
+typedef struct _FontAliasEntry     *FontAliasEntryPtr;
+typedef struct _FontBCEntry        *FontBCEntryPtr;
+typedef struct _FontDirectory      *FontDirectoryPtr;
+typedef struct _FontRenderer       *FontRendererPtr;
+
+#define NullFontEntry              ((FontEntryPtr) 0)
+#define NullFontTable              ((FontTablePtr) 0)
+#define NullFontName               ((FontNamePtr) 0)
+#define NullFontScaled             ((FontScaled) 0)
+#define NullFontScalableExtra      ((FontScalableExtra) 0)
+#define NullFontscalableEntry      ((FontScalableEntry) 0)
+#define NullFontScaleAliasEntry            ((FontScaleAliasEntry) 0)
+#define NullFontBitmapEntry        ((FontBitmapEntry) 0)
+#define NullFontAliasEntry         ((FontAliasEntry) 0)
+#define NullFontBCEntry                    ((FontBCEntry) 0)
+#define NullFontDirectory          ((FontDirectoryPtr) 0)
+#define NullFontRenderer           ((FontRendererPtr) 0)
+
+#define FONT_ENTRY_SCALABLE    0
+#define FONT_ENTRY_SCALE_ALIAS 1
+#define FONT_ENTRY_BITMAP      2
+#define FONT_ENTRY_ALIAS       3
+#define FONT_ENTRY_BC          4
+
+#define MAXFONTNAMELEN     1024
+#define MAXFONTFILENAMELEN  1024
+
+#define FontDirFile        "fonts.dir"
+#define FontAliasFile      "fonts.alias"
+#define FontScalableFile    "fonts.scale"
+
+extern FontEntryPtr    FontFileFindNameInDir ();
+extern FontEntryPtr    FontFileFindNameInScalableDir ();
+extern FontDirectoryPtr        FontFileMakeDir ();
+extern FontRendererPtr FontFileMatchRenderer ();
+extern char            *FontFileSaveString ();
+extern FontScaledPtr   FontFileFindScaledInstance ();
+#endif /* _FONTFILE_H_ */
diff --git a/Xserver/lib/font/include/fntfilio.h b/Xserver/lib/font/include/fntfilio.h
new file mode 100644 (file)
index 0000000..6b5598e
--- /dev/null
@@ -0,0 +1,51 @@
+/* $XConsortium: fntfilio.h,v 1.3 94/04/17 20:17:28 gildea Exp $ */
+
+/*
+
+Copyright (c) 1991  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+*/
+
+/*
+ * Author:  Keith Packard, MIT X Consortium
+ */
+
+#include    <bufio.h>
+
+typedef BufFilePtr  FontFilePtr;
+
+#define FontFileGetc(f)            BufFileGet(f)
+#define FontFilePutc(c,f)   BufFilePut(c,f)
+#define FontFileRead(f,b,n) BufFileRead(f,b,n)
+#define FontFileWrite(f,b,n)   BufFileWrite(f,b,n)
+#define FontFileSkip(f,n)   (BufFileSkip (f, n) != BUFFILEEOF)
+#define FontFileSeek(f,n)   (BufFileSeek (f,n,0) != BUFFILEEOF)
+
+#define FontFileEOF    BUFFILEEOF
+
+extern FontFilePtr  FontFileOpen ();
+extern FontFilePtr  FontFileOpenWrite ();
+extern FontFilePtr  FontFileOpenFd ();
+extern FontFilePtr  FontFileOpenWriteFd ();
+extern int         FontFileClose ();
diff --git a/Xserver/lib/font/include/fntfilst.h b/Xserver/lib/font/include/fntfilst.h
new file mode 100644 (file)
index 0000000..fd9ff49
--- /dev/null
@@ -0,0 +1,167 @@
+/* $XConsortium: fntfilst.h,v 1.8 94/04/17 20:17:29 gildea Exp $ */
+/* $XFree86: xc/lib/font/include/fntfilst.h,v 3.0 1995/11/16 11:03:45 dawes Exp $ */
+
+/*
+
+Copyright (c) 1991  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+*/
+
+/*
+ * Author:  Keith Packard, MIT X Consortium
+ */
+
+#ifndef _FONTFILEST_H_
+#define _FONTFILEST_H_
+
+#include <X11/Xos.h>
+#include "fontmisc.h"
+#include "fontstruct.h"
+#include "fntfil.h"
+#include "fontxlfd.h"
+
+typedef struct _FontName {
+    char       *name;
+    short      length;
+    short      ndashes;
+} FontNameRec;
+
+typedef struct _FontScaled {
+    FontScalableRec    vals;
+    FontEntryPtr       bitmap;
+    FontPtr            pFont;
+} FontScaledRec;
+
+typedef struct _FontScalableExtra {
+    FontScalableRec    defaults;
+    int                        numScaled;
+    int                        sizeScaled;
+    FontScaledPtr      scaled;
+    pointer            private;
+} FontScalableExtraRec;
+
+typedef struct _FontScalableEntry {
+    FontRendererPtr        renderer;
+    char                   *fileName;
+    FontScalableExtraPtr   extra;
+} FontScalableEntryRec;
+
+/*
+ * This "can't" work yet - the returned alias string must be permanent,
+ * but this layer would need to generate the appropriate name from the
+ * resolved scalable + the XLFD values passed in.  XXX
+ */
+
+typedef struct _FontScaleAliasEntry {
+    char               *resolved;
+} FontScaleAliasEntryRec;
+
+typedef struct _FontBitmapEntry {
+    FontRendererPtr    renderer;
+    char               *fileName;
+    FontPtr            pFont;
+} FontBitmapEntryRec;
+
+typedef struct _FontAliasEntry {
+    char       *resolved;
+} FontAliasEntryRec;
+
+typedef struct _FontBCEntry {
+    FontScalableRec        vals;
+    FontEntryPtr           entry;
+} FontBCEntryRec;
+
+typedef struct _FontEntry {
+    FontNameRec        name;
+    int                type;
+    union _FontEntryParts {
+       FontScalableEntryRec    scalable;
+       FontBitmapEntryRec      bitmap;
+       FontAliasEntryRec       alias;
+       FontBCEntryRec          bc;
+    } u;
+} FontEntryRec;
+
+typedef struct _FontTable {
+    int                    used;
+    int                    size;
+    FontEntryPtr    entries;
+    Bool           sorted;
+} FontTableRec;
+
+typedef struct _FontDirectory {
+    char           *directory;
+    unsigned long   dir_mtime;
+    unsigned long   alias_mtime;
+    FontTableRec    scalable;
+    FontTableRec    nonScalable;
+    char           *attributes;
+} FontDirectoryRec;
+
+/* Capability bits: for definition of capabilities bitmap in the
+   FontRendererRec to indicate support of XLFD enhancements */
+
+#define CAP_MATRIX             0x1
+#define CAP_CHARSUBSETTING     0x2
+
+typedef struct _FontRenderer {
+    char    *fileSuffix;
+    int            fileSuffixLen;
+    int            (*OpenBitmap)(/* fpe, pFont, flags, entry, fileName, format, fmask */);
+    int            (*OpenScalable)(/* fpe, pFont, flags, entry, fileName, vals, format, fmask */);
+    int            (*GetInfoBitmap)(/* fpe, pFontInfo, entry, fileName */);
+    int            (*GetInfoScalable)(/* fpe, pFontInfo, entry, fileName, vals */);
+    int            number;
+    int     capabilities;      /* Bitmap components defined above */
+} FontRendererRec;
+
+typedef struct _FontRenders {
+    int                    number;
+    FontRendererPtr *renderers;
+} FontRenderersRec, *FontRenderersPtr;
+
+typedef struct _BitmapInstance {
+    FontScalableRec    vals;
+    FontBitmapEntryPtr bitmap;
+} BitmapInstanceRec, *BitmapInstancePtr;
+
+typedef struct _BitmapScalablePrivate {
+    int                        numInstances;
+    BitmapInstancePtr  instances;
+} BitmapScalablePrivateRec, *BitmapScalablePrivatePtr;
+
+typedef struct _BitmapSources {
+    FontPathElementPtr *fpe;
+    int                        size;
+    int                        count;
+} BitmapSourcesRec, *BitmapSourcesPtr;
+
+extern BitmapSourcesRec        FontFileBitmapSources;
+
+/* Defines for FontFileFindNamesInScalableDir() behavior */
+#define NORMAL_ALIAS_BEHAVIOR          0
+#define LIST_ALIASES_AND_TARGET_NAMES   (1<<0)
+#define IGNORE_SCALABLE_ALIASES                (1<<1)
+
+#endif /* _FONTFILEST_H_ */
diff --git a/Xserver/lib/font/include/fontmisc.h b/Xserver/lib/font/include/fontmisc.h
new file mode 100644 (file)
index 0000000..0d0e407
--- /dev/null
@@ -0,0 +1,80 @@
+/* $TOG: fontmisc.h /main/7 1997/06/10 14:11:11 barstow $ */
+
+/*
+
+Copyright (c) 1991  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+*/
+/* $XFree86: xc/lib/font/include/fontmisc.h,v 3.0.4.1 1997/06/11 12:08:42 dawes Exp $ */
+
+/*
+ * Author:  Keith Packard, MIT X Consortium
+ */
+
+#ifndef _FONTMISC_H_
+#define _FONTMISC_H_
+
+#include <X11/Xfuncs.h>
+
+typedef unsigned char  *pointer;
+typedef int            Bool;
+
+#ifndef X_PROTOCOL
+#ifndef _XSERVER64
+typedef unsigned long  Atom;
+typedef unsigned long  XID;
+#else
+#include <X11/Xmd.h>
+typedef CARD32 XID;
+typedef CARD32 Atom;
+#endif 
+#endif
+
+#ifndef LSBFirst
+#define LSBFirst       0
+#define MSBFirst       1
+#endif
+
+#ifndef None
+#define None   0l
+#endif
+
+#ifndef TRUE
+#define TRUE 1
+#define FALSE 0
+#endif
+
+extern char        *NameForAtom ();
+
+extern unsigned long *Xalloc();
+extern unsigned long *Xrealloc();
+
+#define xalloc(n)   Xalloc ((unsigned) n)
+#define xfree(p)    Xfree ((pointer) p)
+#define xrealloc(p,n)  Xrealloc ((pointer)p,n)
+#define lowbit(x) ((x) & (~(x) + 1))
+
+#define assert(x)
+
+#endif /* _FONTMISC_H_ */
diff --git a/Xserver/lib/font/include/fontshow.h b/Xserver/lib/font/include/fontshow.h
new file mode 100644 (file)
index 0000000..b050dfb
--- /dev/null
@@ -0,0 +1,38 @@
+/* $XConsortium: fontshow.h,v 1.2 94/04/17 20:17:30 rws Exp $ */
+
+/*
+
+Copyright (c) 1990  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+*/
+
+/*
+ * Author:  Keith Packard, MIT X Consortium
+ */
+
+#define FONT_SHOW_INFO     (1<<0)
+#define FONT_SHOW_PROPS            (1<<1)
+#define FONT_SHOW_METRICS   (1<<2)
+#define FONT_SHOW_GLYPHS    (1<<3)
+#define FONT_SHOW_ALL      (FONT_SHOW_INFO|FONT_SHOW_PROPS|FONT_SHOW_GLYPHS)
diff --git a/Xserver/lib/font/include/fontxlfd.h b/Xserver/lib/font/include/fontxlfd.h
new file mode 100644 (file)
index 0000000..51b9a27
--- /dev/null
@@ -0,0 +1,100 @@
+/* $XConsortium: fontxlfd.h,v 1.6 94/04/17 20:17:30 gildea Exp $ */
+
+/*
+
+Copyright (c) 1990, 1994  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be included
+in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR
+OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall
+not be used in advertising or otherwise to promote the sale, use or
+other dealings in this Software without prior written authorization
+from the X Consortium.
+
+*/
+
+/*
+ * Author:  Keith Packard, MIT X Consortium
+ */
+
+#ifndef _FONTXLFD_H_
+#define _FONTXLFD_H_
+
+#include "FSproto.h"
+
+/* Constants for values_supplied bitmap */
+
+#define SIZE_SPECIFY_MASK              0xf
+
+#define PIXELSIZE_MASK                 0x3
+#define PIXELSIZE_UNDEFINED            0
+#define PIXELSIZE_SCALAR               0x1
+#define PIXELSIZE_ARRAY                        0x2
+#define PIXELSIZE_SCALAR_NORMALIZED    0x3     /* Adjusted for resolution */
+
+#define POINTSIZE_MASK                 0xc
+#define POINTSIZE_UNDEFINED            0
+#define POINTSIZE_SCALAR               0x4
+#define POINTSIZE_ARRAY                        0x8
+
+#define PIXELSIZE_WILDCARD             0x10
+#define POINTSIZE_WILDCARD             0x20
+
+#define ENHANCEMENT_SPECIFY_MASK       0x40
+
+#define CHARSUBSET_SPECIFIED           0x40
+
+#define EPS            1.0e-20
+#define XLFD_NDIGITS   3               /* Round numbers in pixel and
+                                          point arrays to this many
+                                          digits for repeatability */
+double xlfd_round_double();
+
+typedef struct _FontScalable {
+    int                values_supplied;        /* Bitmap identifying what advanced
+                                          capabilities or enhancements
+                                          were specified in the font name */
+    double     pixel_matrix[4];
+    double     point_matrix[4];
+
+    /* Pixel and point fields are deprecated in favor of the
+       transformation matrices.  They are provided and filled in for the
+       benefit of rasterizers that do not handle the matrices.  */
+
+    int                pixel,
+               point;
+
+    int         x,
+                y,
+                width;
+    char       *xlfdName;
+    int                nranges;
+    fsRange    *ranges;
+}           FontScalableRec, *FontScalablePtr;
+
+extern Bool FontParseXLFDName();
+extern fsRange *FontParseRanges();
+
+#define FONT_XLFD_REPLACE_NONE 0
+#define FONT_XLFD_REPLACE_STAR 1
+#define FONT_XLFD_REPLACE_ZERO 2
+#define FONT_XLFD_REPLACE_VALUE        3
+
+#endif                         /* _FONTXLFD_H_ */
diff --git a/Xserver/lib/font/util/Imakefile b/Xserver/lib/font/util/Imakefile
new file mode 100644 (file)
index 0000000..7da40ff
--- /dev/null
@@ -0,0 +1,20 @@
+XCOMM $XConsortium: Imakefile,v 1.11 94/02/07 16:07:31 gildea Exp $
+#include <Server.tmpl>
+
+        INCLUDES = -I$(FONTINCSRC) -I../include
+         HEADERS = 
+#ifdef FontFormatDefines
+     FORMAT_DEFS = FontFormatDefines
+#endif
+            SRCS = utilbitmap.c fontnames.c fontutil.c fontxlfd.c format.c \
+                  fontaccel.c atom.c miscutil.c private.c patcache.c
+
+            OBJS = utilbitmap.o fontnames.o fontutil.o fontxlfd.o format.o \
+                  fontaccel.o atom.o miscutil.o private.o patcache.o
+
+SubdirLibraryRule($(OBJS))
+NormalLibraryObjectRule()
+NormalLintTarget($(SRCS))
+
+DependTarget()
+
diff --git a/Xserver/lib/font/util/atom.c b/Xserver/lib/font/util/atom.c
new file mode 100644 (file)
index 0000000..f459ac9
--- /dev/null
@@ -0,0 +1,219 @@
+/* $XConsortium: atom.c,v 1.4 94/04/17 20:17:31 gildea Exp $ */
+
+/*
+
+Copyright (c) 1990, 1994  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+*/
+
+/*
+ * Author:  Keith Packard, MIT X Consortium
+ */
+
+/* lame atom replacement routines for font applications */
+
+#include "fontmisc.h"
+
+typedef struct _AtomList {
+    char               *name;
+    int                        len;
+    int                        hash;
+    Atom               atom;
+} AtomListRec, *AtomListPtr;
+
+static AtomListPtr  *hashTable;
+
+static int         hashSize, hashUsed;
+static int         hashMask;
+static int         rehash;
+
+static AtomListPtr  *reverseMap;
+static int         reverseMapSize;
+static Atom        lastAtom;
+
+static
+Hash(string, len)
+    char    *string;
+{
+    int        h;
+
+    h = 0;
+    while (len--)
+       h = (h << 3) ^ *string++;
+    if (h < 0)
+       return -h;
+    return h;
+}
+
+static
+ResizeHashTable ()
+{
+    int                newHashSize;
+    int                newHashMask;
+    AtomListPtr        *newHashTable;
+    int                i;
+    int                h;
+    int                newRehash;
+    int                r;
+
+    if (hashSize == 0)
+       newHashSize = 1024;
+    else
+       newHashSize = hashSize * 2;
+    newHashTable = (AtomListPtr *) xalloc (newHashSize * sizeof (AtomListPtr));
+    if (!newHashTable)
+       return FALSE;
+    bzero ((char *) newHashTable, newHashSize * sizeof (AtomListPtr));
+    newHashMask = newHashSize - 1;
+    newRehash = (newHashMask - 2);
+    for (i = 0; i < hashSize; i++)
+    {
+       if (hashTable[i])
+       {
+           h = (hashTable[i]->hash) & newHashMask;
+           if (newHashTable[h])
+           {
+               r = hashTable[i]->hash % newRehash | 1;
+               do {
+                   h += r;
+                   if (h >= newHashSize)
+                       h -= newHashSize;
+               } while (newHashTable[h]);
+           }
+           newHashTable[h] = hashTable[i];
+       }
+    }
+    xfree (hashTable);
+    hashTable = newHashTable;
+    hashSize = newHashSize;
+    hashMask = newHashMask;
+    rehash = newRehash;
+    return TRUE;
+}
+
+static
+ResizeReverseMap ()
+{
+    if (reverseMapSize == 0)
+       reverseMapSize = 1000;
+    else
+       reverseMapSize *= 2;
+    reverseMap = (AtomListPtr *) xrealloc (reverseMap, reverseMapSize * sizeof (AtomListPtr));
+    if (!reverseMap)
+       return FALSE;
+}
+
+static
+NameEqual (a, b, l)
+    char    *a, *b;
+{
+    while (l--)
+       if (*a++ != *b++)
+           return FALSE;
+    return TRUE;
+}
+
+Atom 
+MakeAtom(string, len, makeit)
+    char *string;
+    unsigned len;
+    int makeit;
+{
+    AtomListPtr        a;
+    int                hash;
+    int                h;
+    int                r;
+
+    hash = Hash (string, len);
+    if (hashTable)
+    {
+       h = hash & hashMask;
+       if (hashTable[h])
+       {
+           if (hashTable[h]->hash == hash && hashTable[h]->len == len &&
+               NameEqual (hashTable[h]->name, string, len))
+           {
+               return hashTable[h]->atom;
+           }
+           r = (hash % rehash) | 1;
+           for (;;)
+           {
+               h += r;
+               if (h >= hashSize)
+                   h -= hashSize;
+               if (!hashTable[h])
+                   break;
+               if (hashTable[h]->hash == hash && hashTable[h]->len == len &&
+                   NameEqual (hashTable[h]->name, string, len))
+               {
+                   return hashTable[h]->atom;
+               }
+           }
+       }
+    }
+    if (!makeit)
+       return None;
+    a = (AtomListPtr) xalloc (sizeof (AtomListRec) + len + 1);
+    a->name = (char *) (a + 1);
+    a->len = len;
+    strncpy (a->name, string, len);
+    a->name[len] = '\0';
+    a->atom = ++lastAtom;
+    a->hash = hash;
+    if (hashUsed >= hashSize / 2)
+    {
+       ResizeHashTable ();
+       h = hash & hashMask;
+       if (hashTable[h])
+       {
+           r = (hash % rehash) | 1;
+           do {
+               h += r;
+               if (h >= hashSize)
+                   h -= hashSize;
+           } while (hashTable[h]);
+       }
+    }
+    hashTable[h] = a;
+    hashUsed++;
+    if (reverseMapSize <= a->atom)
+       ResizeReverseMap();
+    reverseMap[a->atom] = a;
+    return a->atom;
+}
+
+ValidAtom(atom)
+    Atom atom;
+{
+    return (atom != None) && (atom <= lastAtom);
+}
+
+char *
+NameForAtom(atom)
+    Atom atom;
+{
+    if (atom != None && atom <= lastAtom)
+       return reverseMap[atom]->name;
+    return 0;
+}
diff --git a/Xserver/lib/font/util/fontaccel.c b/Xserver/lib/font/util/fontaccel.c
new file mode 100644 (file)
index 0000000..5417e1c
--- /dev/null
@@ -0,0 +1,104 @@
+/* $XConsortium: fontaccel.c,v 1.4 94/04/17 20:17:31 gildea Exp $ */
+
+/*
+
+Copyright (c) 1990  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be included
+in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR
+OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall
+not be used in advertising or otherwise to promote the sale, use or
+other dealings in this Software without prior written authorization
+from the X Consortium.
+
+*/
+
+/*
+ * Author:  Keith Packard, MIT X Consortium
+ */
+
+#include    "fontmisc.h"
+#include    "fontstruct.h"
+
+FontComputeInfoAccelerators(pFontInfo)
+    FontInfoPtr pFontInfo;
+{
+    pFontInfo->noOverlap = FALSE;
+    if (pFontInfo->maxOverlap <= pFontInfo->minbounds.leftSideBearing)
+       pFontInfo->noOverlap = TRUE;
+
+    if ((pFontInfo->minbounds.ascent == pFontInfo->maxbounds.ascent) &&
+           (pFontInfo->minbounds.descent == pFontInfo->maxbounds.descent) &&
+           (pFontInfo->minbounds.leftSideBearing ==
+            pFontInfo->maxbounds.leftSideBearing) &&
+           (pFontInfo->minbounds.rightSideBearing ==
+            pFontInfo->maxbounds.rightSideBearing) &&
+           (pFontInfo->minbounds.characterWidth ==
+            pFontInfo->maxbounds.characterWidth) &&
+      (pFontInfo->minbounds.attributes == pFontInfo->maxbounds.attributes)) {
+       pFontInfo->constantMetrics = TRUE;
+       if ((pFontInfo->maxbounds.leftSideBearing == 0) &&
+               (pFontInfo->maxbounds.rightSideBearing ==
+                pFontInfo->maxbounds.characterWidth) &&
+               (pFontInfo->maxbounds.ascent == pFontInfo->fontAscent) &&
+               (pFontInfo->maxbounds.descent == pFontInfo->fontDescent))
+           pFontInfo->terminalFont = TRUE;
+       else
+           pFontInfo->terminalFont = FALSE;
+    } else {
+       pFontInfo->constantMetrics = FALSE;
+       pFontInfo->terminalFont = FALSE;
+    }
+    if (pFontInfo->minbounds.characterWidth == pFontInfo->maxbounds.characterWidth)
+       pFontInfo->constantWidth = TRUE;
+    else
+       pFontInfo->constantWidth = FALSE;
+
+    if ((pFontInfo->minbounds.leftSideBearing >= 0) &&
+           (pFontInfo->maxOverlap <= 0) &&
+           (pFontInfo->minbounds.ascent >= -pFontInfo->fontDescent) &&
+           (pFontInfo->maxbounds.ascent <= pFontInfo->fontAscent) &&
+           (-pFontInfo->minbounds.descent <= pFontInfo->fontAscent) &&
+           (pFontInfo->maxbounds.descent <= pFontInfo->fontDescent))
+       pFontInfo->inkInside = TRUE;
+    else
+       pFontInfo->inkInside = FALSE;
+}
+
+FontCouldBeTerminal(pFontInfo)
+    FontInfoPtr pFontInfo;
+{
+    if ((pFontInfo->minbounds.leftSideBearing >= 0) &&
+           (pFontInfo->maxbounds.rightSideBearing <= pFontInfo->maxbounds.characterWidth) &&
+           (pFontInfo->minbounds.characterWidth == pFontInfo->maxbounds.characterWidth) &&
+           (pFontInfo->maxbounds.ascent <= pFontInfo->fontAscent) &&
+           (pFontInfo->maxbounds.descent <= pFontInfo->fontDescent) &&
+           (pFontInfo->maxbounds.leftSideBearing != 0 ||
+            pFontInfo->minbounds.rightSideBearing != pFontInfo->minbounds.characterWidth ||
+            pFontInfo->minbounds.ascent != pFontInfo->fontAscent ||
+            pFontInfo->minbounds.descent != pFontInfo->fontDescent)) {
+       /* blow off font with nothing but a SPACE */
+       if (pFontInfo->maxbounds.ascent == 0 && 
+           pFontInfo->maxbounds.descent == 0)
+               return FALSE;
+       return TRUE;
+    }
+    return FALSE;
+}
diff --git a/Xserver/lib/font/util/fontnames.c b/Xserver/lib/font/util/fontnames.c
new file mode 100644 (file)
index 0000000..c9aff6b
--- /dev/null
@@ -0,0 +1,126 @@
+/* $XConsortium: fontnames.c,v 1.2 94/04/17 20:17:32 keith Exp $ */
+
+/*
+
+Copyright (c) 1991  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be included
+in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR
+OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall
+not be used in advertising or otherwise to promote the sale, use or
+other dealings in this Software without prior written authorization
+from the X Consortium.
+
+*/
+
+/*
+ * Author:  Keith Packard, MIT X Consortium
+ *
+ *     @(#)fontnames.c 3.1     91/04/10
+ */
+
+#include       "fontmisc.h"
+#include       "fontstruct.h"
+
+void
+FreeFontNames(pFN)
+    FontNamesPtr pFN;
+{
+    int         i;
+
+    if (!pFN)
+       return;
+    for (i = 0; i < pFN->nnames; i++) {
+       xfree(pFN->names[i]);
+    }
+    xfree(pFN->names);
+    xfree(pFN->length);
+    xfree(pFN);
+}
+
+FontNamesPtr
+MakeFontNamesRecord(size)
+    unsigned    size;
+{
+    FontNamesPtr pFN;
+
+    pFN = (FontNamesPtr) xalloc(sizeof(FontNamesRec));
+    if (pFN) {
+       pFN->nnames = 0;
+       pFN->size = size;
+       if (size)
+       {
+           pFN->length = (int *) xalloc(size * sizeof(int));
+           pFN->names = (char **) xalloc(size * sizeof(char *));
+           if (!pFN->length || !pFN->names) {
+               xfree(pFN->length);
+               xfree(pFN->names);
+               xfree(pFN);
+               pFN = (FontNamesPtr) 0;
+           }
+       }
+       else
+       {
+           pFN->length = 0;
+           pFN->names = 0;
+       }
+    }
+    return pFN;
+}
+
+int
+AddFontNamesName(names, name, length)
+    FontNamesPtr names;
+    char       *name;
+    int         length;
+{
+    int         index = names->nnames;
+    char       *nelt;
+
+    nelt = (char *) xalloc(length + 1);
+    if (!nelt)
+       return AllocError;
+    if (index >= names->size) {
+       int         size = names->size << 1;
+       int        *nlength;
+       char      **nnames;
+
+       if (size == 0)
+           size = 8;
+       nlength = (int *) xrealloc(names->length, size * sizeof(int));
+       nnames = (char **) xrealloc(names->names, size * sizeof(char *));
+       if (nlength && nnames) {
+           names->size = size;
+           names->length = nlength;
+           names->names = nnames;
+       } else {
+           xfree(nelt);
+           xfree(nlength);
+           xfree(nnames);
+           return AllocError;
+       }
+    }
+    names->length[index] = length;
+    names->names[index] = nelt;
+    strncpy(nelt, name, length);
+    nelt[length] = '\0';
+    names->nnames++;
+    return Successful;
+}
diff --git a/Xserver/lib/font/util/fontutil.c b/Xserver/lib/font/util/fontutil.c
new file mode 100644 (file)
index 0000000..6d6b393
--- /dev/null
@@ -0,0 +1,419 @@
+/* $XConsortium: fontutil.c /main/11 1996/09/12 10:08:59 kaleb $ */
+/* $XFree86: xc/lib/font/util/fontutil.c,v 3.1 1996/12/23 06:02:33 dawes Exp $ */
+
+/*
+
+Copyright (c) 1991  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be included
+in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR
+OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall
+not be used in advertising or otherwise to promote the sale, use or
+other dealings in this Software without prior written authorization
+from the X Consortium.
+
+*/
+
+/*
+ * Author:  Keith Packard, MIT X Consortium
+ */
+
+#include    "fontmisc.h"
+#include    "fontstruct.h"
+#include    "FSproto.h"
+
+/* Define global here...  doesn't hurt the servers, and avoids
+   unresolved references in font clients.  */
+
+static int defaultGlyphCachingMode = DEFAULT_GLYPH_CACHING_MODE;
+int glyphCachingMode = DEFAULT_GLYPH_CACHING_MODE;
+
+void
+GetGlyphs(font, count, chars, fontEncoding, glyphcount, glyphs)
+    FontPtr     font;
+    unsigned long count;
+    unsigned char *chars;
+    FontEncoding fontEncoding;
+    unsigned long *glyphcount; /* RETURN */
+    CharInfoPtr *glyphs;       /* RETURN */
+{
+    (*font->get_glyphs) (font, count, chars, fontEncoding, glyphcount, glyphs);
+}
+
+#define MIN(a,b)    ((a)<(b)?(a):(b))
+#define MAX(a,b)    ((a)>(b)?(a):(b))
+
+void
+QueryGlyphExtents(pFont, charinfo, count, info)
+    FontPtr     pFont;
+    CharInfoPtr *charinfo;
+    unsigned long count;
+    ExtentInfoRec *info;
+{
+    register unsigned long i;
+    xCharInfo  *pCI;
+
+    info->drawDirection = pFont->info.drawDirection;
+
+    info->fontAscent = pFont->info.fontAscent;
+    info->fontDescent = pFont->info.fontDescent;
+
+    if (count != 0) {
+
+       pCI = &((*charinfo)->metrics); charinfo++;
+       /* ignore nonexisting characters when calculating text extents */
+       if ( !((pCI->characterWidth == 0)
+              && (pCI->rightSideBearing == 0)
+              && (pCI->leftSideBearing == 0)
+              && (pCI->ascent == 0)
+              && (pCI->descent == 0)) ) {
+           info->overallAscent = pCI->ascent;
+           info->overallDescent = pCI->descent;
+           info->overallLeft = pCI->leftSideBearing;
+           info->overallRight = pCI->rightSideBearing;
+           info->overallWidth = pCI->characterWidth;
+       }
+
+       if (pFont->info.constantMetrics && pFont->info.noOverlap) {
+           info->overallWidth *= count;
+           info->overallRight += (info->overallWidth -
+                                  pCI->characterWidth);
+       } else {
+           for (i = 1; i < count; i++) {
+               pCI = &((*charinfo)->metrics); charinfo++;
+               /* ignore nonexisting characters when calculating extents */
+               if ( !((pCI->characterWidth == 0)
+                      && (pCI->rightSideBearing == 0)
+                      && (pCI->leftSideBearing == 0)
+                      && (pCI->ascent == 0)
+                      && (pCI->descent == 0)) ) {
+                   info->overallAscent = MAX(
+                                             info->overallAscent,
+                                             pCI->ascent);
+                   info->overallDescent = MAX(
+                                              info->overallDescent,
+                                              pCI->descent);
+                   info->overallLeft = MIN(
+                                           info->overallLeft,
+                                           info->overallWidth + pCI->leftSideBearing);
+                   info->overallRight = MAX(
+                                            info->overallRight,
+                                            info->overallWidth + pCI->rightSideBearing);
+                   /*
+                    * yes, this order is correct; overallWidth IS incremented
+                    * last
+                    */
+                   info->overallWidth += pCI->characterWidth;
+               }
+           }
+       }
+    } else {
+       info->overallAscent = 0;
+       info->overallDescent = 0;
+       info->overallWidth = 0;
+       info->overallLeft = 0;
+       info->overallRight = 0;
+    }
+}
+
+Bool
+QueryTextExtents(pFont, count, chars, info)
+    FontPtr     pFont;
+    unsigned long count;
+    unsigned char *chars;
+    ExtentInfoRec *info;
+{
+    xCharInfo     **charinfo;
+    unsigned long   n;
+    FontEncoding    encoding;
+    int             cm;
+    int             i;
+    unsigned long   t;
+    xCharInfo      *defaultChar = 0;
+    unsigned char   defc[2];
+    int             firstReal;
+
+    charinfo = (xCharInfo **) xalloc(count * sizeof(xCharInfo *));
+    if (!charinfo)
+       return FALSE;
+    encoding = TwoD16Bit;
+    if (pFont->info.lastRow == 0)
+       encoding = Linear16Bit;
+    (*pFont->get_metrics) (pFont, count, chars, encoding, &n, charinfo);
+
+    /* Do default character substitution as get_metrics doesn't */
+
+#define IsNonExistentChar(ci) (!(ci) || \
+                              (ci)->ascent == 0 && \
+                              (ci)->descent == 0 && \
+                              (ci)->leftSideBearing == 0 && \
+                              (ci)->rightSideBearing == 0 && \
+                              (ci)->characterWidth == 0)
+
+    firstReal = n;
+    defc[0] = pFont->info.defaultCh >> 8;
+    defc[1] = pFont->info.defaultCh;
+    (*pFont->get_metrics) (pFont, 1, defc, encoding, &t, &defaultChar);
+    if (IsNonExistentChar (defaultChar))
+       defaultChar = 0;
+    for (i = 0; i < n; i++)
+    {
+       if (IsNonExistentChar (charinfo[i]))
+       {
+           if (!defaultChar)
+               continue;
+           charinfo[i] = defaultChar;
+       }
+       if (firstReal == n)
+           firstReal = i;
+    }
+    cm = pFont->info.constantMetrics;
+    pFont->info.constantMetrics = FALSE;
+    QueryGlyphExtents(pFont, charinfo + firstReal, n - firstReal, info);
+    pFont->info.constantMetrics = cm;
+    xfree(charinfo);
+    return TRUE;
+}
+
+Bool
+ParseGlyphCachingMode(str)
+    char       *str;
+{
+    if (!strcmp(str, "none")) defaultGlyphCachingMode = CACHING_OFF;
+    else if (!strcmp(str, "all")) defaultGlyphCachingMode = CACHE_ALL_GLYPHS;
+    else if (!strcmp(str, "16")) defaultGlyphCachingMode = CACHE_16_BIT_GLYPHS;
+    else return FALSE;
+    return TRUE;
+}
+
+void
+InitGlyphCaching()
+{
+    /* Set glyphCachingMode to the mode the server hopes to
+       support.  DDX drivers that do not support the requested level
+       of glyph caching can call SetGlyphCachingMode to lower the
+       level of support.
+     */
+
+    glyphCachingMode = defaultGlyphCachingMode;
+}
+
+/* ddxen can call SetGlyphCachingMode to inform us of what level of glyph
+ * caching they can support.
+ */
+void
+SetGlyphCachingMode(newmode)
+    int newmode;
+{
+    if ( (glyphCachingMode > newmode) && (newmode >= 0) )
+       glyphCachingMode = newmode;
+}
+
+#define range_alloc_granularity 16
+#define mincharp(p) ((p)->min_char_low + ((p)->min_char_high << 8))
+#define maxcharp(p) ((p)->max_char_low + ((p)->max_char_high << 8))
+
+/* add_range(): Add range to a list of ranges, with coalescence */
+int
+add_range(newrange, nranges, range, charset_subset)
+fsRange *newrange;
+int *nranges;
+fsRange **range;
+Bool charset_subset;
+{
+    int first, last, middle;
+    unsigned long keymin, keymax;
+    unsigned long ptrmin, ptrmax;
+    fsRange *ptr, *ptr1, *ptr2, *endptr;
+
+    /* There are two different ways to treat ranges:
+
+       1) Charset subsetting (support of the HP XLFD enhancements), in
+         which a range of 0x1234,0x3456 means all numbers between
+         0x1234 and 0x3456, and in which min and max might be swapped.
+
+       2) Row/column ranges, in which a range of 0x1234,0x3456 means the
+         ranges 0x1234-0x1256, 0x1334-0x1356, ...  , 0x3434-0x3456.
+         This is for support of glyph caching.
+
+       The choice of treatment is selected with the "charset_subset"
+       flag */
+
+    /* If newrange covers multiple rows; break up the rows */
+    if (!charset_subset && newrange->min_char_high != newrange->max_char_high)
+    {
+       int i, err;
+       fsRange temprange;
+       for (i = newrange->min_char_high;
+            i <= newrange->max_char_high;
+            i++)
+       {
+           temprange.min_char_low = newrange->min_char_low;
+           temprange.max_char_low = newrange->max_char_low;
+           temprange.min_char_high = temprange.max_char_high = i;
+           err = add_range(&temprange, nranges, range, charset_subset);
+           if (err != Successful) break;
+       }
+       return err;
+    }
+
+    keymin = mincharp(newrange);
+    keymax = maxcharp(newrange);
+
+    if (charset_subset && keymin > keymax)
+    {
+       unsigned long temp = keymin;
+       keymin = keymax;
+       keymax = temp;
+    }
+
+    /* add_range() maintains a sorted list; this makes possible coalescence
+       and binary searches */
+
+    /* Binary search for a range with which the new range can merge */
+
+    first = middle = 0;
+    last = *nranges - 1;
+    while (last >= first)
+    {
+       middle = (first + last) / 2;
+       ptr = (*range) + middle;
+       ptrmin = mincharp(ptr);
+       ptrmax = maxcharp(ptr);
+
+       if (ptrmin > 0 && keymax < ptrmin - 1) last = middle - 1;
+       else if (keymin > ptrmax + 1) first = middle + 1;
+       else if (!charset_subset)
+       {
+           /* We might have a range with which to merge... IF the
+              result doesn't cross rows */
+           if (newrange->min_char_high != ptr->min_char_high)
+               last = first - 1;       /* Force adding a new range */
+           break;
+       }
+       else break;     /* We have at least one range with which we can merge */
+    }
+
+    if (last < first)
+    {
+       /* Search failed; we need to add a new range to the list. */
+
+       /* Grow the list if necessary */
+       if (*nranges == 0 || *range == (fsRange *)0)
+       {
+           *range = (fsRange *)xalloc(range_alloc_granularity *
+                                      SIZEOF(fsRange));
+           *nranges = 0;
+       }
+       else if (!(*nranges % range_alloc_granularity))
+       {
+           *range = (fsRange *)xrealloc((char *)*range,
+                                         (*nranges + range_alloc_granularity) *
+                                         SIZEOF(fsRange));
+       }
+
+       /* If alloc failed, just return a null list */
+       if (*range == (fsRange *)0)
+       {
+           *nranges = 0;
+           return AllocError;
+       }
+
+       /* Should new entry go *at* or *after* ptr? */
+       ptr = (*range) + middle;
+       if (middle < *nranges && keymin > ptrmin) ptr++;        /* after */
+
+       /* Open up a space for our new range */
+       memmove((char *)(ptr + 1),
+               (char *)ptr,
+               (char *)(*range + *nranges) - (char *)ptr);
+
+       /* Insert the new range */
+       ptr->min_char_low = keymin & 0xff;
+       ptr->min_char_high = keymin >> 8;
+       ptr->max_char_low = keymax & 0xff;
+       ptr->max_char_high = keymax >> 8;
+
+       /* Update range count */
+       (*nranges)++;
+
+       /* Done */
+       return Successful;
+    }
+
+    /* Join our new range to that pointed to by "ptr" */
+    if (keymin < ptrmin)
+    {
+       ptr->min_char_low = keymin & 0xff;
+       ptr->min_char_high = keymin >> 8;
+    }
+    if (keymax > ptrmax)
+    {
+       ptr->max_char_low = keymax & 0xff;
+       ptr->max_char_high = keymax >> 8;
+    }
+
+    ptrmin = mincharp(ptr);
+    ptrmax = maxcharp(ptr);
+
+    endptr = *range + *nranges;
+
+    for (ptr1 = ptr; ptr1 >= *range; ptr1--)
+    {
+       if (ptrmin <= maxcharp(ptr1) + 1)
+       {
+           if (!charset_subset && ptr->min_char_high != ptr1->min_char_high)
+               break;
+           if (ptrmin >= mincharp(ptr1))
+               ptrmin = mincharp(ptr1);
+       }
+       else break;
+    }
+    for (ptr2 = ptr; ptr2 < endptr; ptr2++)
+    {
+       if (ptr2->min_char_low == 0 &&
+           ptr2->min_char_high == 0 ||
+           ptrmax >= mincharp(ptr2) - 1)
+       {
+           if (!charset_subset && ptr->min_char_high != ptr2->min_char_high)
+               break;
+           if (ptrmax <= maxcharp(ptr2))
+               ptrmax = maxcharp(ptr2);
+       }
+       else break;
+    }
+
+    /* We need to coalesce ranges between ptr1 and ptr2 exclusive */
+    ptr1++;
+    ptr2--;
+    if (ptr1 != ptr2)
+    {
+       memmove(ptr1, ptr2, (char *)endptr - (char *)ptr2);
+       *nranges -= (ptr2 - ptr1);
+    }
+
+    /* Write the new range into the range list */
+    ptr1->min_char_low = ptrmin & 0xff;
+    ptr1->min_char_high = ptrmin >> 8;
+    ptr1->max_char_low = ptrmax & 0xff;
+    ptr1->max_char_high = ptrmax >> 8;
+
+    return Successful;
+}
diff --git a/Xserver/lib/font/util/fontxlfd.c b/Xserver/lib/font/util/fontxlfd.c
new file mode 100644 (file)
index 0000000..76bcb05
--- /dev/null
@@ -0,0 +1,661 @@
+/* $XConsortium: fontxlfd.c /main/20 1996/09/28 16:49:26 rws $ */
+/* $XFree86: xc/lib/font/util/fontxlfd.c,v 3.5 1996/12/23 06:02:34 dawes Exp $ */
+
+/*
+
+Copyright (c) 1990  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be included
+in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR
+OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall
+not be used in advertising or otherwise to promote the sale, use or
+other dealings in this Software without prior written authorization
+from the X Consortium.
+
+*/
+
+/*
+ * Author:  Keith Packard, MIT X Consortium
+ */
+
+#include       "fontmisc.h"
+#include       "fontstruct.h"
+#include       "fontxlfd.h"
+#include       <X11/Xos.h>
+#include       <math.h>
+#if !defined(X_NOT_STDC_ENV) || defined(SCO)
+#include       <stdlib.h>
+#endif
+#if defined(X_NOT_STDC_ENV) || (defined(sony) && !defined(SYSTYPE_SYSV) && !defined(_SYSTYPE_SYSV))
+#define NO_LOCALE
+#endif
+#ifndef NO_LOCALE
+#include       <locale.h>
+#endif
+#include       <ctype.h>
+#include       <stdio.h>       /* for sprintf() */
+
+static char *
+GetInt(ptr, val)
+    char       *ptr;
+    int        *val;
+{
+    if (*ptr == '*') {
+       *val = -1;
+       ptr++;
+    } else
+       for (*val = 0; *ptr >= '0' && *ptr <= '9';)
+           *val = *val * 10 + *ptr++ - '0';
+    if (*ptr == '-')
+       return ptr;
+    return (char *) 0;
+}
+
+#define minchar(p) ((p).min_char_low + ((p).min_char_high << 8))
+#define maxchar(p) ((p).max_char_low + ((p).max_char_high << 8))
+
+
+#ifndef NO_LOCALE
+static struct lconv *locale = 0;
+#endif
+static char *radix = ".", *plus = "+", *minus = "-";
+
+static char *
+readreal(ptr, result)
+char *ptr;
+double *result;
+{
+    char buffer[80], *p1, *p2;
+    int count;
+
+#ifndef NO_LOCALE
+    /* Figure out what symbols apply in this locale */
+
+    if (!locale)
+    {
+       locale = localeconv();
+       if (locale->decimal_point && *locale->decimal_point)
+           radix = locale->decimal_point;
+       if (locale->positive_sign && *locale->positive_sign)
+           plus = locale->positive_sign;
+       if (locale->negative_sign && *locale->negative_sign)
+           minus = locale->negative_sign;
+    }
+#endif
+    /* Copy the first 80 chars of ptr into our local buffer, changing
+       symbols as needed. */
+    for (p1 = ptr, p2 = buffer;
+        *p1 && (p2 - buffer) < sizeof(buffer) - 1;
+        p1++, p2++)
+    {
+       switch(*p1)
+       {
+           case '~': *p2 = *minus; break;
+           case '+': *p2 = *plus; break;
+           case '.': *p2 = *radix; break;
+           default: *p2 = *p1;
+       }
+    }
+    *p2 = 0;
+
+    /* Now we have something that strtod() can interpret... do it. */
+#ifndef X_NOT_STDC_ENV
+    *result = strtod(buffer, &p1);
+    /* Return NULL if failure, pointer past number if success */
+    return (p1 == buffer) ? (char *)0 : (ptr + (p1 - buffer));
+#else
+    for (p1 = buffer; isspace(*p1); p1++)
+       ;
+    if (sscanf(p1, "%lf", result) != 1)
+       return (char *)0;
+    while (!isspace(*p1))
+       p1++;
+    return ptr + (p1 - buffer);
+#endif
+}
+
+static char *
+xlfd_double_to_text(value, buffer, space_required)
+double value;
+char *buffer;
+int space_required;
+{
+    char formatbuf[40];
+    register char *p1;
+    int ndigits, exponent;
+
+#ifndef NO_LOCALE
+    if (!locale)
+    {
+       locale = localeconv();
+       if (locale->decimal_point && *locale->decimal_point)
+           radix = locale->decimal_point;
+       if (locale->positive_sign && *locale->positive_sign)
+           plus = locale->positive_sign;
+       if (locale->negative_sign && *locale->negative_sign)
+           minus = locale->negative_sign;
+    }
+#endif
+    /* Compute a format to use to render the number */
+    sprintf(formatbuf, "%%.%dle", XLFD_NDIGITS);
+
+    if (space_required)
+       *buffer++ = ' ';
+
+    /* Render the number using printf's idea of formatting */
+    sprintf(buffer, formatbuf, value);
+
+    /* Find and read the exponent value */
+    for (p1 = buffer + strlen(buffer);
+       *p1-- != 'e' && p1[1] != 'E';);
+    exponent = atoi(p1 + 2);
+    if (value == 0.0) exponent = 0;
+
+    /* Figure out how many digits are significant */
+    while (p1 >= buffer && (!isdigit(*p1) || *p1 == '0')) p1--;
+    ndigits = 0;
+    while (p1 >= buffer) if (isdigit(*p1--)) ndigits++;
+
+    /* Figure out notation to use */
+    if (exponent >= XLFD_NDIGITS || ndigits - exponent > XLFD_NDIGITS + 1)
+    {
+       /* Scientific */
+       sprintf(formatbuf, "%%.%dle", ndigits - 1);
+       sprintf(buffer, formatbuf, value);
+    }
+    else
+    {
+       /* Fixed */
+       ndigits -= exponent + 1;
+       if (ndigits < 0) ndigits = 0;
+       sprintf(formatbuf, "%%.%dlf", ndigits);
+       sprintf(buffer, formatbuf, value);
+       if (exponent < 0)
+       {
+           p1 = buffer;
+           while (*p1 && *p1 != '0') p1++;
+           while (*p1++) p1[-1] = *p1;
+       }
+    }
+
+    /* Last step, convert the locale-specific sign and radix characters
+       to our own. */
+    for (p1 = buffer; *p1; p1++)
+    {
+       if (*p1 == *minus) *p1 = '~';
+       else if (*p1 == *plus) *p1 = '+';
+       else if (*p1 == *radix) *p1 = '.';
+    }
+
+    return buffer - space_required;
+}
+
+double
+xlfd_round_double(x)
+double x;
+{
+   /* Utility for XLFD users to round numbers to XLFD_NDIGITS
+      significant digits.  How do you round to n significant digits on
+      a binary machine?  */
+
+#if defined(i386) || defined(__i386__) || defined(__alpha__)
+#if !defined(__EMX__)
+#include <float.h>
+
+/* if we have IEEE 754 fp, we can round to binary digits... */
+
+#if (FLT_RADIX == 2) && (DBL_DIG == 15) && (DBL_MANT_DIG == 53)
+
+#ifndef M_LN2
+#define M_LN2       0.69314718055994530942
+#endif
+#ifndef M_LN10
+#define M_LN10      2.30258509299404568402
+#endif
+
+/* convert # of decimal digits to # of binary digits */
+#define XLFD_NDIGITS_2 ((int)(XLFD_NDIGITS * M_LN10 / M_LN2 + 0.5))
+   
+   union conv_d {
+      double d;
+      unsigned char b[8];
+   } d;
+   int i,j,k,d_exp;
+   
+   if (x == 0) 
+      return x;
+
+   /* do minor sanity check for IEEE 754 fp and correct byte order */
+   d.d = 1.0;
+   if (sizeof(double) == 8 && d.b[7] == 0x3f && d.b[6] == 0xf0) {
+      
+      /* 
+       * this code will round IEEE 754 double to XLFD_NDIGITS_2 binary digits
+       */
+      
+      d.d = x;
+      d_exp = (d.b[7] << 4) | (d.b[6] >> 4);
+      
+      i = (DBL_MANT_DIG-XLFD_NDIGITS_2) >> 3;
+      j = 1 << ((DBL_MANT_DIG-XLFD_NDIGITS_2) & 0x07);
+      for (; i<7; i++) {
+        k = d.b[i] + j;
+        d.b[i] = k;
+        if (k & 0x100) j = 1;
+        else break;
+      }
+      if ((i==7) && ((d.b[6] & 0xf0) != ((d_exp<<4) & 0xf0))) {
+        /* mantissa overflow: increment exponent */
+        d_exp = (d_exp & 0x800 ) | ((d_exp & 0x7ff) + 1);
+        d.b[7] = d_exp >> 4;
+        d.b[6] = (d.b[6] & 0x0f) | (d_exp << 4);
+      }
+      
+      i = (DBL_MANT_DIG-XLFD_NDIGITS_2) >> 3;
+      j = 1 << ((DBL_MANT_DIG-XLFD_NDIGITS_2) & 0x07);      
+      d.b[i] &= ~(j-1);
+      for (;--i>=0;) d.b[i] = 0;
+
+      return d.d;
+   }
+   else 
+#endif
+#endif /* !__EMX__ */
+#endif /* i386 || __i386__ */
+    {
+       /*
+        * If not IEEE 754:  Let printf() do it for you.  
+        */
+        
+       char formatbuf[40], buffer[40];
+        
+       sprintf(formatbuf, "%%.%dlg", XLFD_NDIGITS);
+       sprintf(buffer, formatbuf, x);
+       return atof(buffer);
+    }
+}
+
+static char *
+GetMatrix(ptr, vals, which)
+char *ptr;
+FontScalablePtr vals;
+int which;
+{
+    double *matrix;
+
+    if (which == PIXELSIZE_MASK)
+       matrix = vals->pixel_matrix;
+    else if (which == POINTSIZE_MASK)
+       matrix = vals->point_matrix;
+    else return (char *)0;
+
+    while (isspace(*ptr)) ptr++;
+    if (*ptr == '[')
+    {
+       /* This is a matrix containing real numbers.  It would be nice
+          to use strtod() or sscanf() to read the numbers, but those
+          don't handle '~' for minus and we cannot force them to use a
+          "."  for the radix.  We'll have to do the hard work ourselves
+          (in readreal()).  */
+
+       if ((ptr = readreal(++ptr, matrix + 0)) &&
+           (ptr = readreal(ptr, matrix + 1)) &&
+           (ptr = readreal(ptr, matrix + 2)) &&
+           (ptr = readreal(ptr, matrix + 3)))
+       {
+           while (isspace(*ptr)) ptr++;
+           if (*ptr != ']')
+               ptr = (char *)0;
+           else
+           {
+               ptr++;
+               while (isspace(*ptr)) ptr++;
+               if (*ptr == '-')
+               {
+                   if (which == POINTSIZE_MASK)
+                       vals->values_supplied |= POINTSIZE_ARRAY;
+                   else
+                       vals->values_supplied |= PIXELSIZE_ARRAY;
+               }
+               else ptr = (char *)0;
+           }
+       }
+    }
+    else
+    {
+       int value;
+       if (ptr = GetInt(ptr, &value))
+       {
+           vals->values_supplied &= ~which;
+           if (value > 0)
+           {
+               matrix[3] = (double)value;
+               if (which == POINTSIZE_MASK)
+               {
+                   matrix[3] /= 10.0;
+                   vals->values_supplied |= POINTSIZE_SCALAR;
+               }
+               else
+                   vals->values_supplied |= PIXELSIZE_SCALAR;
+               /* If we're concocting the pixelsize array from a scalar,
+                  we will need to normalize element 0 for the pixel shape.
+                  This is done in FontFileCompleteXLFD(). */
+               matrix[0] = matrix[3];
+               matrix[1] = matrix[2] = 0.0;
+           }
+           else if (value < 0)
+           {
+               if (which == POINTSIZE_MASK)
+                   vals->values_supplied |= POINTSIZE_WILDCARD;
+               else
+                   vals->values_supplied |= PIXELSIZE_WILDCARD;
+           }
+       }
+    }
+    return ptr;
+}
+
+
+static void append_ranges(fname, nranges, ranges)
+char *fname;
+int nranges;
+fsRange *ranges;
+{
+    if (nranges)
+    {
+        int i;
+
+        strcat(fname, "[");
+        for (i = 0; i < nranges && strlen(fname) < 1010; i++)
+        {
+           if (i) strcat(fname, " ");
+           sprintf(fname + strlen(fname), "%d",
+                   minchar(ranges[i]));
+           if (ranges[i].min_char_low ==
+               ranges[i].max_char_low &&
+               ranges[i].min_char_high ==
+               ranges[i].max_char_high) continue;
+           sprintf(fname + strlen(fname), "_%d",
+                   maxchar(ranges[i]));
+        }
+        strcat(fname, "]");
+    }
+}
+
+Bool
+FontParseXLFDName(fname, vals, subst)
+    char       *fname;
+    FontScalablePtr vals;
+    int         subst;
+{
+    register char *ptr;
+    register char *ptr1,
+               *ptr2,
+               *ptr3,
+               *ptr4;
+    register char *ptr5;
+    FontScalableRec tmpvals;
+    char        replaceChar = '0';
+    char        tmpBuf[1024];
+    int         spacingLen;
+    int                l;
+    char       *p;
+
+    bzero(&tmpvals, sizeof(tmpvals));
+    if (subst != FONT_XLFD_REPLACE_VALUE)
+       *vals = tmpvals;
+
+    if (!(*(ptr = fname) == '-' || *ptr++ == '*' && *ptr == '-') ||  /* fndry */
+           !(ptr = strchr(ptr + 1, '-')) ||    /* family_name */
+           !(ptr1 = ptr = strchr(ptr + 1, '-')) ||     /* weight_name */
+           !(ptr = strchr(ptr + 1, '-')) ||    /* slant */
+           !(ptr = strchr(ptr + 1, '-')) ||    /* setwidth_name */
+           !(ptr = strchr(ptr + 1, '-')) ||    /* add_style_name */
+           !(ptr = strchr(ptr + 1, '-')) ||    /* pixel_size */
+           !(ptr = GetMatrix(ptr + 1, &tmpvals, PIXELSIZE_MASK)) ||
+           !(ptr2 = ptr = GetMatrix(ptr + 1, &tmpvals, POINTSIZE_MASK)) ||
+           !(ptr = GetInt(ptr + 1, &tmpvals.x)) ||     /* resolution_x */
+           !(ptr3 = ptr = GetInt(ptr + 1, &tmpvals.y)) ||  /* resolution_y */
+           !(ptr4 = ptr = strchr(ptr + 1, '-')) ||     /* spacing */
+           !(ptr5 = ptr = GetInt(ptr + 1, &tmpvals.width)) || /* average_width */
+           !(ptr = strchr(ptr + 1, '-')) ||    /* charset_registry */
+           strchr(ptr + 1, '-'))/* charset_encoding */
+       return FALSE;
+
+    /* Lop off HP charset subsetting enhancement.  Interpreting this
+       field requires allocating some space in which to return the
+       results.  So, to prevent memory leaks, this procedure will simply
+       lop off and ignore charset subsetting, and initialize the
+       relevant vals fields to zero.  It's up to the caller to make its
+       own call to FontParseRanges() if it's interested in the charset
+       subsetting.  */
+
+    if (subst != FONT_XLFD_REPLACE_NONE &&
+       (p = strchr(strrchr(fname, '-'), '[')))
+    {
+       tmpvals.values_supplied |= CHARSUBSET_SPECIFIED;
+       *p = '\0';
+    }
+
+    /* Fill in deprecated fields for the benefit of rasterizers that care
+       about them. */
+    tmpvals.pixel = (tmpvals.pixel_matrix[3] >= 0) ?
+                   (int)(tmpvals.pixel_matrix[3] + .5) :
+                   (int)(tmpvals.pixel_matrix[3] - .5);
+    tmpvals.point = (tmpvals.point_matrix[3] >= 0) ?
+                    (int)(tmpvals.point_matrix[3] * 10 + .5) :
+                    (int)(tmpvals.point_matrix[3] * 10 - .5);
+
+    spacingLen = ptr4 - ptr3 + 1;
+
+    switch (subst) {
+    case FONT_XLFD_REPLACE_NONE:
+       *vals = tmpvals;
+       break;
+    case FONT_XLFD_REPLACE_STAR:
+       replaceChar = '*';
+    case FONT_XLFD_REPLACE_ZERO:
+       strcpy(tmpBuf, ptr2);
+       ptr5 = tmpBuf + (ptr5 - ptr2);
+       ptr3 = tmpBuf + (ptr3 - ptr2);
+       ptr2 = tmpBuf;
+       ptr = ptr1 + 1;
+
+       ptr = strchr(ptr, '-') + 1;             /* skip weight */
+       ptr = strchr(ptr, '-') + 1;             /* skip slant */
+       ptr = strchr(ptr, '-') + 1;             /* skip setwidth_name */
+       ptr = strchr(ptr, '-') + 1;             /* skip add_style_name */
+
+       if ((ptr - fname) + spacingLen + strlen(ptr5) + 10 >= (unsigned)1024)
+           return FALSE;
+       *ptr++ = replaceChar;
+       *ptr++ = '-';
+       *ptr++ = replaceChar;
+       *ptr++ = '-';
+       *ptr++ = '*';
+       *ptr++ = '-';
+       *ptr++ = '*';
+       if (spacingLen > 2)
+       {
+           memmove(ptr, ptr3, spacingLen);
+           ptr += spacingLen;
+       }
+       else
+       {
+           *ptr++ = '-';
+           *ptr++ = '*';
+           *ptr++ = '-';
+       }
+       *ptr++ = replaceChar;
+       strcpy(ptr, ptr5);
+       *vals = tmpvals;
+       break;
+    case FONT_XLFD_REPLACE_VALUE:
+       if (vals->values_supplied & PIXELSIZE_MASK)
+       {
+           tmpvals.values_supplied =
+               (tmpvals.values_supplied & ~PIXELSIZE_MASK) |
+               (vals->values_supplied & PIXELSIZE_MASK);
+           tmpvals.pixel_matrix[0] = vals->pixel_matrix[0];
+           tmpvals.pixel_matrix[1] = vals->pixel_matrix[1];
+           tmpvals.pixel_matrix[2] = vals->pixel_matrix[2];
+           tmpvals.pixel_matrix[3] = vals->pixel_matrix[3];
+       }
+       if (vals->values_supplied & POINTSIZE_MASK)
+       {
+           tmpvals.values_supplied =
+               (tmpvals.values_supplied & ~POINTSIZE_MASK) |
+               (vals->values_supplied & POINTSIZE_MASK);
+           tmpvals.point_matrix[0] = vals->point_matrix[0];
+           tmpvals.point_matrix[1] = vals->point_matrix[1];
+           tmpvals.point_matrix[2] = vals->point_matrix[2];
+           tmpvals.point_matrix[3] = vals->point_matrix[3];
+       }
+       if (vals->x >= 0)
+           tmpvals.x = vals->x;
+       if (vals->y >= 0)
+           tmpvals.y = vals->y;
+       if (vals->width >= 0)
+           tmpvals.width = vals->width;
+       else if (vals->width < -1)      /* overload: -1 means wildcard */
+           tmpvals.width = -vals->width;
+
+
+       p = ptr1 + 1;                           /* weight field */
+       l = strchr(p, '-') - p;
+       sprintf(tmpBuf, "%*.*s", l, l, p);
+
+       p += l + 1;                             /* slant field */
+       l = strchr(p, '-') - p;
+       sprintf(tmpBuf + strlen(tmpBuf), "-%*.*s", l, l, p);
+
+       p += l + 1;                             /* setwidth_name */
+       l = strchr(p, '-') - p;
+       sprintf(tmpBuf + strlen(tmpBuf), "-%*.*s", l, l, p);
+
+       p += l + 1;                             /* add_style_name field */
+       l = strchr(p, '-') - p;
+       sprintf(tmpBuf + strlen(tmpBuf), "-%*.*s", l, l, p);
+
+       strcat(tmpBuf, "-");
+       if ((tmpvals.values_supplied & PIXELSIZE_MASK) == PIXELSIZE_ARRAY)
+       {
+           char buffer[80];
+           strcat(tmpBuf, "[");
+           strcat(tmpBuf, xlfd_double_to_text(tmpvals.pixel_matrix[0],
+                  buffer, 0));
+           strcat(tmpBuf, xlfd_double_to_text(tmpvals.pixel_matrix[1],
+                  buffer, 1));
+           strcat(tmpBuf, xlfd_double_to_text(tmpvals.pixel_matrix[2],
+                  buffer, 1));
+           strcat(tmpBuf, xlfd_double_to_text(tmpvals.pixel_matrix[3],
+                  buffer, 1));
+           strcat(tmpBuf, "]");
+       }
+       else
+       {
+           sprintf(tmpBuf + strlen(tmpBuf), "%d",
+                   (int)(tmpvals.pixel_matrix[3] + .5));
+       }
+       strcat(tmpBuf, "-");
+       if ((tmpvals.values_supplied & POINTSIZE_MASK) == POINTSIZE_ARRAY)
+       {
+           char buffer[80];
+           strcat(tmpBuf, "[");
+           strcat(tmpBuf, xlfd_double_to_text(tmpvals.point_matrix[0],
+                  buffer, 0));
+           strcat(tmpBuf, xlfd_double_to_text(tmpvals.point_matrix[1],
+                  buffer, 1));
+           strcat(tmpBuf, xlfd_double_to_text(tmpvals.point_matrix[2],
+                  buffer, 1));
+           strcat(tmpBuf, xlfd_double_to_text(tmpvals.point_matrix[3],
+                  buffer, 1));
+           strcat(tmpBuf, "]");
+       }
+       else
+       {
+           sprintf(tmpBuf + strlen(tmpBuf), "%d",
+                   (int)(tmpvals.point_matrix[3] * 10.0 + .5));
+       }
+       sprintf(tmpBuf + strlen(tmpBuf), "-%d-%d%*.*s%d%s",
+               tmpvals.x, tmpvals.y,
+               spacingLen, spacingLen, ptr3, tmpvals.width, ptr5);
+       strcpy(ptr1 + 1, tmpBuf);
+       if ((vals->values_supplied & CHARSUBSET_SPECIFIED) && !vals->nranges)
+           strcat(fname, "[]");
+       else
+           append_ranges(fname, vals->nranges, vals->ranges);
+       break;
+    }
+    return TRUE;
+}
+
+fsRange *FontParseRanges(name, nranges)
+char *name;
+int *nranges;
+{
+    int n;
+    unsigned long l;
+    char *p1, *p2;
+    fsRange *result = (fsRange *)0;
+
+    name = strchr(name, '-');
+    for (n = 1; name && n < 14; n++)
+       name = strchr(name + 1, '-');
+
+    *nranges = 0;
+    if (!name || !(p1 = strchr(name, '['))) return (fsRange *)0;
+    p1++;
+
+    while (*p1 && *p1 != ']')
+    {
+       fsRange thisrange;
+
+       l = strtol(p1, &p2, 0);
+       if (p2 == p1 || l > 0xffff) break;
+       thisrange.max_char_low = thisrange.min_char_low = l & 0xff;
+       thisrange.max_char_high = thisrange.min_char_high = l >> 8;
+
+       p1 = p2;
+       if (*p1 == ']' || *p1 == ' ')
+       {
+           while (*p1 == ' ') p1++;
+           if (add_range(&thisrange, nranges, &result, TRUE) != Successful)
+               break;
+       }
+       else if (*p1 == '_')
+       {
+           l = strtol(++p1, &p2, 0);
+           if (p2 == p1 || l > 0xffff) break;
+           thisrange.max_char_low = l & 0xff;
+           thisrange.max_char_high = l >> 8;
+           p1 = p2;
+           if (*p1 == ']' || *p1 == ' ')
+           {
+               while (*p1 == ' ') p1++;
+               if (add_range(&thisrange, nranges, &result, TRUE) != Successful)
+                   break;
+           }
+       }
+       else break;
+    }
+
+    return result;
+}
diff --git a/Xserver/lib/font/util/format.c b/Xserver/lib/font/util/format.c
new file mode 100644 (file)
index 0000000..5456779
--- /dev/null
@@ -0,0 +1,123 @@
+/* $XConsortium: format.c,v 1.5 94/04/17 20:17:34 dpw Exp $ */
+/*
+ * Copyright 1990, 1991 Network Computing Devices;
+ * Portions Copyright 1987 by Digital Equipment Corporation
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the names of Network Computing Devices or Digital 
+ * not be used in advertising or publicity pertaining to distribution of the 
+ * software without specific, written prior permission. Network Computing 
+ * Devices and Digital make no representations about the suitability of 
+ * this software for any purpose.  It is provided "as is" without express 
+ * or implied warranty.
+ *
+ * NETWORK COMPUTING DEVICES AND DIGITAL DISCLAIM ALL WARRANTIES WITH
+ * REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS, IN NO EVENT SHALL NETWORK COMPUTING DEVICES OR DIGITAL BE
+ * LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
+ * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
+ * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+/*
+
+Copyright (c) 1987  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be included
+in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR
+OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall
+not be used in advertising or otherwise to promote the sale, use or
+other dealings in this Software without prior written authorization
+from the X Consortium.
+
+*/
+
+#include       "FSproto.h"
+#include       "font.h"
+
+int
+CheckFSFormat(format, fmask, bit_order, byte_order, scan, glyph, image)
+    fsBitmapFormat format;
+    fsBitmapFormatMask fmask;
+    int        *bit_order,
+               *byte_order,
+               *scan,
+               *glyph,
+               *image;
+{
+    /* convert format to what the low levels want */
+    if (fmask & BitmapFormatMaskBit) {
+       *bit_order = format & BitmapFormatBitOrderMask;
+       *bit_order = (*bit_order == BitmapFormatBitOrderMSB)
+                    ? MSBFirst : LSBFirst;
+    }
+    if (fmask & BitmapFormatMaskByte) {
+       *byte_order = format & BitmapFormatByteOrderMask;
+       *byte_order = (*byte_order == BitmapFormatByteOrderMSB)
+                     ? MSBFirst : LSBFirst;
+    }
+    if (fmask & BitmapFormatMaskScanLineUnit) {
+       *scan = format & BitmapFormatScanlineUnitMask;
+       /* convert byte paddings into byte counts */
+       switch (*scan) {
+       case BitmapFormatScanlineUnit8:
+           *scan = 1;
+           break;
+       case BitmapFormatScanlineUnit16:
+           *scan = 2;
+           break;
+       case BitmapFormatScanlineUnit32:
+           *scan = 4;
+           break;
+       default:
+           return BadFontFormat;
+       }
+    }
+    if (fmask & BitmapFormatMaskScanLinePad) {
+       *glyph = format & BitmapFormatScanlinePadMask;
+       /* convert byte paddings into byte counts */
+       switch (*glyph) {
+       case BitmapFormatScanlinePad8:
+           *glyph = 1;
+           break;
+       case BitmapFormatScanlinePad16:
+           *glyph = 2;
+           break;
+       case BitmapFormatScanlinePad32:
+           *glyph = 4;
+           break;
+       default:
+           return BadFontFormat;
+       }
+    }
+    if (fmask & BitmapFormatMaskImageRectangle) {
+       *image = format & BitmapFormatImageRectMask;
+
+       if (*image != BitmapFormatImageRectMin &&
+               *image != BitmapFormatImageRectMaxWidth &&
+               *image != BitmapFormatImageRectMax)
+           return BadFontFormat;
+    }
+    return Successful;
+}
diff --git a/Xserver/lib/font/util/miscutil.c b/Xserver/lib/font/util/miscutil.c
new file mode 100644 (file)
index 0000000..59ba4e0
--- /dev/null
@@ -0,0 +1,95 @@
+/* $XConsortium: miscutil.c,v 1.4 94/04/17 20:17:36 gildea Exp $ */
+
+/*
+
+Copyright (c) 1991, 1994  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be included
+in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR
+OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall
+not be used in advertising or otherwise to promote the sale, use or
+other dealings in this Software without prior written authorization
+from the X Consortium.
+
+*/
+
+#include <X11/Xosdefs.h>
+#ifndef X_NOT_STDC_ENV
+#include <stdlib.h>
+#else
+char *malloc(), *realloc();
+#endif
+
+#define XK_LATIN1
+#include    <X11/keysymdef.h>
+/* #include    <X11/Xmu/CharSet.h> */
+
+/* make sure everything initializes themselves at least once */
+
+long serverGeneration = 1;
+
+unsigned long *
+Xalloc (m)
+{
+    return (unsigned long *) malloc (m);
+}
+
+unsigned long *
+Xrealloc (n,m)
+    unsigned long   *n;
+{
+    if (!n)
+       return (unsigned long *) malloc (m);
+    else
+       return (unsigned long *) realloc ((char *) n, m);
+}
+
+Xfree (n)
+    unsigned long   *n;
+{
+    if (n)
+       free ((char *) n);
+}
+
+CopyISOLatin1Lowered (dst, src, len)
+    char    *dst, *src;
+    int            len;
+{
+    register unsigned char *dest, *source;
+
+    for (dest = (unsigned char *)dst, source = (unsigned char *)src;
+        *source && len > 0;
+        source++, dest++, len--)
+    {
+       if ((*source >= XK_A) && (*source <= XK_Z))
+           *dest = *source + (XK_a - XK_A);
+       else if ((*source >= XK_Agrave) && (*source <= XK_Odiaeresis))
+           *dest = *source + (XK_agrave - XK_Agrave);
+       else if ((*source >= XK_Ooblique) && (*source <= XK_Thorn))
+           *dest = *source + (XK_oslash - XK_Ooblique);
+       else
+           *dest = *source;
+    }
+    *dest = '\0';
+}
+
+register_fpe_functions ()
+{
+}
diff --git a/Xserver/lib/font/util/patcache.c b/Xserver/lib/font/util/patcache.c
new file mode 100644 (file)
index 0000000..36b8e2c
--- /dev/null
@@ -0,0 +1,226 @@
+/* $TOG: patcache.c /main/8 1997/06/12 11:51:59 barstow $ */
+
+/*
+
+Copyright (c) 1991  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+*/
+/* $XFree86: xc/lib/font/util/patcache.c,v 3.0.4.1 1997/07/05 15:55:37 dawes Exp $ */
+
+/*
+ * Author:  Keith Packard, MIT X Consortium
+ */
+
+#include    <fontmisc.h>
+#include    <fontstruct.h>
+
+/*
+ * Static sized hash table for looking up font name patterns
+ *
+ * LRU entries, reusing old entries
+ */
+
+#define NBUCKETS       16
+#define NENTRIES       64
+
+#define UNSET          (NENTRIES+1)
+
+typedef unsigned char  EntryPtr;
+
+typedef struct _FontPatternCacheEntry {
+    struct _FontPatternCacheEntry   *next, **prev;
+    short                          patlen;
+    char                           *pattern;
+    int                                    hash;
+    FontPtr                        pFont;      /* associated font */
+} FontPatternCacheEntryRec, *FontPatternCacheEntryPtr;
+
+typedef struct _FontPatternCache {
+    FontPatternCacheEntryPtr   buckets[NBUCKETS];
+    FontPatternCacheEntryRec   entries[NENTRIES];
+    FontPatternCacheEntryPtr   free;
+} FontPatternCacheRec;
+
+/* Create and initialize cache */
+FontPatternCachePtr
+MakeFontPatternCache ()
+{
+    FontPatternCachePtr        cache;
+    int                        i;
+    cache = (FontPatternCachePtr) xalloc (sizeof *cache);
+    if (!cache)
+       return 0;
+    for (i = 0; i < NENTRIES; i++) {
+       cache->entries[i].patlen = 0;
+       cache->entries[i].pattern = 0;
+       cache->entries[i].pFont = 0;
+    }
+    EmptyFontPatternCache (cache);
+    return cache;
+}
+
+/* toss cache */
+void
+FreeFontPatternCache (cache)
+    FontPatternCachePtr        cache;
+{
+    int            i;
+
+    for (i = 0; i < NENTRIES; i++)
+       xfree (cache->entries[i].pattern);
+    xfree (cache);
+}
+
+/* compute id for string */
+static
+Hash (string, len)
+    char    *string;
+    int            len;
+{
+    int        hash;
+
+    hash = 0;
+    while (len--)
+       hash = (hash << 1) ^ *string++;
+    if (hash < 0)
+       hash = -hash;
+    return hash;
+}
+
+/* Empty cache (for rehash) */
+void
+EmptyFontPatternCache (cache)
+    FontPatternCachePtr        cache;
+{
+    int            i;
+    
+    for (i = 0; i < NBUCKETS; i++)
+       cache->buckets[i] = 0;
+    for (i = 0; i < NENTRIES; i++)
+    {
+       cache->entries[i].next = &cache->entries[i+1];
+       cache->entries[i].prev = 0;
+       cache->entries[i].pFont = 0;
+       xfree (cache->entries[i].pattern);
+       cache->entries[i].pattern = 0;
+       cache->entries[i].patlen = 0;
+    }
+    cache->free = &cache->entries[0];
+    cache->entries[NENTRIES - 1].next = 0;
+}
+
+/* add entry */
+void
+CacheFontPattern (cache, pattern, patlen, pFont)
+    FontPatternCachePtr        cache;
+    char               *pattern;
+    int                        patlen;
+    FontPtr            pFont;
+{
+    FontPatternCacheEntryPtr   e;
+    char                       *newpat;
+    int                                i;
+
+    newpat = (char *) xalloc (patlen);
+    if (!newpat)
+       return;
+    if (cache->free)
+    {
+       e = cache->free;
+       cache->free = e->next;
+    }
+    else
+    {
+       i = rand ();
+       if (i < 0)
+           i = -i;
+       i %= NENTRIES;
+       e = &cache->entries[i];
+       if (e->next)
+           e->next->prev = e->prev;
+       *e->prev = e->next;
+       xfree (e->pattern);
+    }
+    /* set pattern */
+    memcpy (newpat, pattern, patlen);
+    e->pattern = newpat;
+    e->patlen = patlen;
+    /* link to new hash chain */
+    e->hash = Hash (pattern, patlen);
+    i = e->hash % NBUCKETS;
+    e->next = cache->buckets[i];
+    if (e->next)
+       e->next->prev = &(e->next);
+    cache->buckets[i] = e;
+    e->prev = &(cache->buckets[i]);
+    e->pFont = pFont;
+}
+
+/* find matching entry */
+FontPtr
+FindCachedFontPattern (cache, pattern, patlen)
+    FontPatternCachePtr        cache;
+    char               *pattern;
+    int                        patlen;
+{
+    int                                hash;
+    int                                i;
+    FontPatternCacheEntryPtr   e;
+
+    hash = Hash (pattern, patlen);
+    i = hash % NBUCKETS;
+    for (e = cache->buckets[i]; e; e = e->next)
+    {
+       if (e->patlen == patlen && e->hash == hash &&
+           !memcmp (e->pattern, pattern, patlen))
+       {
+           return e->pFont;
+       }
+    }
+    return 0;
+}
+
+void
+RemoveCachedFontPattern (cache, pFont)
+    FontPatternCachePtr        cache;
+    FontPtr            pFont;
+{
+    FontPatternCacheEntryPtr   e;
+    int                                i;
+
+    for (i = 0; i < NENTRIES; i++)
+    {
+       if ((e = &cache->entries[i])->pFont == pFont)
+       {
+           e->pFont = 0;
+           if (e->next)
+               e->next->prev = e->prev;
+           *e->prev = e->next;
+           e->next = cache->free;
+           cache->free = e;
+           xfree (e->pattern);
+           e->pattern = 0;
+       }
+    }
+}
diff --git a/Xserver/lib/font/util/private.c b/Xserver/lib/font/util/private.c
new file mode 100644 (file)
index 0000000..009dee4
--- /dev/null
@@ -0,0 +1,71 @@
+/* $XConsortium: private.c,v 1.4 94/04/17 20:17:37 gildea Exp $ */
+
+/*
+
+Copyright (c) 1991  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+*/
+
+/*
+ * Author:  Keith Packard, MIT X Consortium
+ */
+
+#include    "fontmisc.h"
+#include    "fontstruct.h"
+
+int _FontPrivateAllocateIndex;
+
+int
+AllocateFontPrivateIndex ()
+{
+    return _FontPrivateAllocateIndex++;
+}
+
+void
+ResetFontPrivateIndex ()
+{
+    _FontPrivateAllocateIndex = 0;
+}
+
+Bool
+_FontSetNewPrivate (pFont, n, ptr)
+    FontPtr pFont;
+    int            n;
+    pointer ptr;
+{
+    pointer *new;
+
+    if (n > pFont->maxPrivate)
+    {
+       new = (pointer *) xrealloc (pFont->devPrivates, (n + 1) * sizeof (pointer));
+       if (!new)
+           return FALSE;
+       pFont->devPrivates = new;
+       /* zero out new, uninitialized privates */
+       while(++pFont->maxPrivate < n)
+           pFont->devPrivates[pFont->maxPrivate] = (pointer)0;
+    }
+    pFont->devPrivates[n] = ptr;
+    return TRUE;
+}
diff --git a/Xserver/lib/font/util/utilbitmap.c b/Xserver/lib/font/util/utilbitmap.c
new file mode 100644 (file)
index 0000000..83130d2
--- /dev/null
@@ -0,0 +1,188 @@
+/* $XConsortium: utilbitmap.c,v 1.3 94/04/17 20:17:38 gildea Exp $ */
+
+/*
+
+Copyright (c) 1990, 1994  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+*/
+
+/*
+ * Author:  Keith Packard, MIT X Consortium
+ */
+
+/* Utility functions for reformating font bitmaps */
+
+static unsigned char _reverse_byte[0x100] = {
+       0x00, 0x80, 0x40, 0xc0, 0x20, 0xa0, 0x60, 0xe0,
+       0x10, 0x90, 0x50, 0xd0, 0x30, 0xb0, 0x70, 0xf0,
+       0x08, 0x88, 0x48, 0xc8, 0x28, 0xa8, 0x68, 0xe8,
+       0x18, 0x98, 0x58, 0xd8, 0x38, 0xb8, 0x78, 0xf8,
+       0x04, 0x84, 0x44, 0xc4, 0x24, 0xa4, 0x64, 0xe4,
+       0x14, 0x94, 0x54, 0xd4, 0x34, 0xb4, 0x74, 0xf4,
+       0x0c, 0x8c, 0x4c, 0xcc, 0x2c, 0xac, 0x6c, 0xec,
+       0x1c, 0x9c, 0x5c, 0xdc, 0x3c, 0xbc, 0x7c, 0xfc,
+       0x02, 0x82, 0x42, 0xc2, 0x22, 0xa2, 0x62, 0xe2,
+       0x12, 0x92, 0x52, 0xd2, 0x32, 0xb2, 0x72, 0xf2,
+       0x0a, 0x8a, 0x4a, 0xca, 0x2a, 0xaa, 0x6a, 0xea,
+       0x1a, 0x9a, 0x5a, 0xda, 0x3a, 0xba, 0x7a, 0xfa,
+       0x06, 0x86, 0x46, 0xc6, 0x26, 0xa6, 0x66, 0xe6,
+       0x16, 0x96, 0x56, 0xd6, 0x36, 0xb6, 0x76, 0xf6,
+       0x0e, 0x8e, 0x4e, 0xce, 0x2e, 0xae, 0x6e, 0xee,
+       0x1e, 0x9e, 0x5e, 0xde, 0x3e, 0xbe, 0x7e, 0xfe,
+       0x01, 0x81, 0x41, 0xc1, 0x21, 0xa1, 0x61, 0xe1,
+       0x11, 0x91, 0x51, 0xd1, 0x31, 0xb1, 0x71, 0xf1,
+       0x09, 0x89, 0x49, 0xc9, 0x29, 0xa9, 0x69, 0xe9,
+       0x19, 0x99, 0x59, 0xd9, 0x39, 0xb9, 0x79, 0xf9,
+       0x05, 0x85, 0x45, 0xc5, 0x25, 0xa5, 0x65, 0xe5,
+       0x15, 0x95, 0x55, 0xd5, 0x35, 0xb5, 0x75, 0xf5,
+       0x0d, 0x8d, 0x4d, 0xcd, 0x2d, 0xad, 0x6d, 0xed,
+       0x1d, 0x9d, 0x5d, 0xdd, 0x3d, 0xbd, 0x7d, 0xfd,
+       0x03, 0x83, 0x43, 0xc3, 0x23, 0xa3, 0x63, 0xe3,
+       0x13, 0x93, 0x53, 0xd3, 0x33, 0xb3, 0x73, 0xf3,
+       0x0b, 0x8b, 0x4b, 0xcb, 0x2b, 0xab, 0x6b, 0xeb,
+       0x1b, 0x9b, 0x5b, 0xdb, 0x3b, 0xbb, 0x7b, 0xfb,
+       0x07, 0x87, 0x47, 0xc7, 0x27, 0xa7, 0x67, 0xe7,
+       0x17, 0x97, 0x57, 0xd7, 0x37, 0xb7, 0x77, 0xf7,
+       0x0f, 0x8f, 0x4f, 0xcf, 0x2f, 0xaf, 0x6f, 0xef,
+       0x1f, 0x9f, 0x5f, 0xdf, 0x3f, 0xbf, 0x7f, 0xff
+};
+
+/*
+ *     Invert bit order within each BYTE of an array.
+ */
+void
+BitOrderInvert(buf, nbytes)
+    register unsigned char *buf;
+    register int nbytes;
+{
+    register unsigned char *rev = _reverse_byte;
+
+    for (; --nbytes >= 0; buf++)
+       *buf = rev[*buf];
+}
+
+/*
+ *     Invert byte order within each 16-bits of an array.
+ */
+void
+TwoByteSwap(buf, nbytes)
+    register unsigned char *buf;
+    register int nbytes;
+{
+    register unsigned char c;
+
+    for (; nbytes > 0; nbytes -= 2, buf += 2)
+    {
+       c = buf[0];
+       buf[0] = buf[1];
+       buf[1] = c;
+    }
+}
+
+/*
+ *     Invert byte order within each 32-bits of an array.
+ */
+void
+FourByteSwap(buf, nbytes)
+    register unsigned char *buf;
+    register int nbytes;
+{
+    register unsigned char c;
+
+    for (; nbytes > 0; nbytes -= 4, buf += 4) 
+    {
+       c = buf[0];
+       buf[0] = buf[3];
+       buf[3] = c;
+       c = buf[1];
+       buf[1] = buf[2];
+       buf[2] = c;
+    }
+}
+
+/*
+ *     Repad a bitmap
+ */
+
+int
+RepadBitmap (pSrc, pDst, srcPad, dstPad, width, height)
+    char       *pSrc, *pDst;
+    unsigned   srcPad, dstPad;
+    int                width, height;
+{
+    int            srcWidthBytes,dstWidthBytes;
+    int            row,col;
+    char    *pTmpSrc,*pTmpDst;
+
+    switch (srcPad) {
+    case 1:    
+       srcWidthBytes = (width+7)>>3;
+       break;
+    case 2:
+       srcWidthBytes = ((width+15)>>4)<<1;
+       break;
+    case 4:    
+       srcWidthBytes = ((width+31)>>5)<<2;
+       break;
+    case 8:    
+       srcWidthBytes = ((width+63)>>6)<<3; 
+       break;
+    default:
+       return 0;
+    }
+    switch (dstPad) {
+    case 1:    
+       dstWidthBytes = (width+7)>>3;
+       break;
+    case 2:
+       dstWidthBytes = ((width+15)>>4)<<1;
+       break;
+    case 4:    
+       dstWidthBytes = ((width+31)>>5)<<2;
+       break;
+    case 8:    
+       dstWidthBytes = ((width+63)>>6)<<3; 
+       break;
+    default:
+       return 0;
+    }
+
+    width = srcWidthBytes;
+    if (width > dstWidthBytes)
+       width = dstWidthBytes;
+    pTmpSrc= pSrc;
+    pTmpDst= pDst;
+    for (row = 0; row < height; row++)
+    {
+       for (col = 0; col < width; col++)
+           *pTmpDst++ = *pTmpSrc++;
+       while (col < dstWidthBytes)
+       {
+           *pTmpDst++ = '\0';
+           col++;
+       }
+       pTmpSrc += srcWidthBytes - width;
+    }
+    return dstWidthBytes * height;
+}
diff --git a/Xserver/lib/xtrans/Imakefile b/Xserver/lib/xtrans/Imakefile
new file mode 100644 (file)
index 0000000..4fd6178
--- /dev/null
@@ -0,0 +1,8 @@
+XCOMM $XConsortium: Imakefile /main/12 1996/09/28 16:50:08 rws $
+
+#define IncSubdir X11
+
+all::
+
+DependTarget()
+BuildIncludes(Xtrans.h,IncSubdir,..)
diff --git a/Xserver/lib/xtrans/Xtrans.c b/Xserver/lib/xtrans/Xtrans.c
new file mode 100644 (file)
index 0000000..e9cf8fe
--- /dev/null
@@ -0,0 +1,1458 @@
+/* $XConsortium: Xtrans.c,v 1.31 95/03/28 19:49:02 mor Exp $ */
+/* $XFree86: xc/lib/xtrans/Xtrans.c,v 3.15.2.2 1997/07/19 04:59:16 dawes Exp $ */
+/*
+
+Copyright (c) 1993, 1994  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be included
+in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR
+OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall
+not be used in advertising or otherwise to promote the sale, use or
+other dealings in this Software without prior written authorization
+from the X Consortium.
+
+*/
+
+/* Copyright (c) 1993, 1994 NCR Corporation - Dayton, Ohio, USA
+ *
+ * All Rights Reserved
+ *
+ * Permission to use, copy, modify, and distribute this software and its
+ * documentation for any purpose and without fee is hereby granted, provided
+ * that the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the name NCR not be used in advertising
+ * or publicity pertaining to distribution of the software without specific,
+ * written prior permission.  NCR makes no representations about the
+ * suitability of this software for any purpose.  It is provided "as is"
+ * without express or implied warranty.
+ *
+ * NCR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN
+ * NO EVENT SHALL NCR BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
+ * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
+ * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
+ * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include <ctype.h>
+
+/*
+ * The transport table contains a definition for every transport (protocol)
+ * family. All operations that can be made on the transport go through this
+ * table.
+ *
+ * Each transport is assigned a unique transport id.
+ *
+ * New transports can be added by adding an entry in this table.
+ * For compatiblity, the transport ids should never be renumbered.
+ * Always add to the end of the list.
+ */
+
+#define TRANS_TLI_INET_INDEX           1
+#define TRANS_TLI_TCP_INDEX            2
+#define TRANS_TLI_TLI_INDEX            3
+#define TRANS_SOCKET_UNIX_INDEX                4
+#define TRANS_SOCKET_LOCAL_INDEX       5
+#define TRANS_SOCKET_INET_INDEX                6
+#define TRANS_SOCKET_TCP_INDEX         7
+#define TRANS_DNET_INDEX               8
+#define TRANS_LOCAL_LOCAL_INDEX                9
+#define TRANS_LOCAL_PTS_INDEX          10
+#define TRANS_LOCAL_NAMED_INDEX                11
+#define TRANS_LOCAL_ISC_INDEX          12
+#define TRANS_LOCAL_SCO_INDEX          13
+#define TRANS_AMOEBA_INDEX             14
+#define TRANS_MNX_INET_INDEX           15
+#define TRANS_MNX_TCP_INDEX            16
+
+
+static
+Xtransport_table Xtransports[] = {
+#if defined(STREAMSCONN)
+    &TRANS(TLITCPFuncs),       TRANS_TLI_TCP_INDEX,
+    &TRANS(TLIINETFuncs),      TRANS_TLI_INET_INDEX,
+    &TRANS(TLITLIFuncs),       TRANS_TLI_TLI_INDEX,
+#endif /* STREAMSCONN */
+#if defined(TCPCONN)
+    &TRANS(SocketTCPFuncs),    TRANS_SOCKET_TCP_INDEX,
+    &TRANS(SocketINETFuncs),   TRANS_SOCKET_INET_INDEX,
+#endif /* TCPCONN */
+#if defined(DNETCONN)
+    &TRANS(DNETFuncs),         TRANS_DNET_INDEX,
+#endif /* DNETCONN */
+#if defined(UNIXCONN)
+#if !defined(LOCALCONN)
+    &TRANS(SocketLocalFuncs),  TRANS_SOCKET_LOCAL_INDEX,
+#endif /* !LOCALCONN */
+    &TRANS(SocketUNIXFuncs),   TRANS_SOCKET_UNIX_INDEX,
+#endif /* UNIXCONN */
+#if defined(OS2PIPECONN)
+    &TRANS(OS2LocalFuncs),     TRANS_LOCAL_LOCAL_INDEX,
+#endif /* OS2PIPECONN */
+#if defined(LOCALCONN)
+    &TRANS(LocalFuncs),                TRANS_LOCAL_LOCAL_INDEX,
+    &TRANS(PTSFuncs),          TRANS_LOCAL_PTS_INDEX,
+#ifdef SVR4
+    &TRANS(NAMEDFuncs),                TRANS_LOCAL_NAMED_INDEX,
+#endif
+    &TRANS(ISCFuncs),          TRANS_LOCAL_ISC_INDEX,
+    &TRANS(SCOFuncs),          TRANS_LOCAL_SCO_INDEX,
+#endif /* LOCALCONN */
+#if defined(AMRPCCONN) || defined(AMTCPCONN)
+    &TRANS(AmConnFuncs),       TRANS_AMOEBA_INDEX,
+#endif /* AMRPCCONN || AMTCPCONN */
+#if defined(MNX_TCPCONN)
+    &TRANS(MnxINETFuncs),      TRANS_MNX_INET_INDEX,
+    &TRANS(MnxTCPFuncs),       TRANS_MNX_TCP_INDEX,
+#endif /* MNX_TCPCONN */
+};
+
+#define NUMTRANS       (sizeof(Xtransports)/sizeof(Xtransport_table))
+
+
+#ifdef WIN32
+#define ioctl ioctlsocket
+#endif
+
+
+\f
+/*
+ * These are a few utility function used by the public interface functions.
+ */
+
+void
+TRANS(FreeConnInfo) (ciptr)
+
+XtransConnInfo ciptr;
+
+{
+    PRMSG (3,"FreeConnInfo(%x)\n", ciptr, 0, 0);
+
+    if (ciptr->addr)
+       xfree (ciptr->addr);
+
+    if (ciptr->peeraddr)
+       xfree (ciptr->peeraddr);
+
+    if (ciptr->port)
+       xfree (ciptr->port);
+
+    xfree ((char *) ciptr);
+}
+
+
+#define PROTOBUFSIZE   20
+
+static Xtransport *
+TRANS(SelectTransport) (protocol)
+
+char *protocol;
+
+{
+    char       protobuf[PROTOBUFSIZE];
+    int                i;
+
+    PRMSG (3,"SelectTransport(%s)\n", protocol, 0, 0);
+
+    /*
+     * Force Protocol to be lowercase as a way of doing
+     * a case insensitive match.
+     */
+
+    strncpy (protobuf, protocol, PROTOBUFSIZE);
+
+    for (i = 0; i < PROTOBUFSIZE && protobuf[i] != '\0'; i++)
+       if (isupper (protobuf[i]))
+           protobuf[i] = tolower (protobuf[i]);
+
+    /* Look at all of the configured protocols */
+
+    for (i = 0; i < NUMTRANS; i++)
+    {
+       if (!strcmp (protobuf, Xtransports[i].transport->TransName))
+           return Xtransports[i].transport;
+    }
+
+    return NULL;
+}
+
+#ifndef TEST_t
+static
+#endif /* TEST_t */
+int
+TRANS(ParseAddress) (address, protocol, host, port)
+
+char   *address;
+char   **protocol;
+char   **host;
+char   **port;
+
+{
+    /*
+     * For the font library, the address is a string formatted
+     * as "protocol/host:port[/catalogue]".  Note that the catologue
+     * is optional.  At this time, the catologue info is ignored, but
+     * we have to parse it anyways.
+     *
+     * Other than fontlib, the address is a string formatted
+     * as "protocol/host:port".
+     *
+     * If the protocol part is missing, then assume INET.
+     * If the protocol part and host part are missing, then assume local.
+     * If a "::" is found then assume DNET.
+     */
+
+    char       *mybuf, *tmpptr;
+    char       *_protocol, *_host, *_port;
+    char       hostnamebuf[256];
+
+    PRMSG (3,"ParseAddress(%s)\n", address, 0, 0);
+
+    /* Copy the string so it can be changed */
+
+    tmpptr = mybuf = (char *) xalloc (strlen (address) + 1);
+    strcpy (mybuf, address);
+
+    /* Parse the string to get each component */
+    
+    /* Get the protocol part */
+
+    _protocol = mybuf;
+
+    if ((mybuf = strpbrk (mybuf,"/:")) == NULL)
+    {
+       /* adress is in a bad format */
+       *protocol = NULL;
+       *host = NULL;
+       *port = NULL;
+       xfree (tmpptr);
+       return 0;
+    }
+
+    if (*mybuf == ':')
+    {
+       /*
+        * If there is a hostname, then assume inet, otherwise
+        * it must be local.
+        */
+       if (mybuf == tmpptr)
+       {
+           /* There is neither a protocol or host specified */
+           _protocol = "local";
+       }
+       else
+       {
+           /* Ther is a hostname specified */
+           _protocol = "inet";
+           mybuf = tmpptr;     /* reset to the begining of the host ptr */
+       }
+    }
+    else
+    {
+       /* *mybuf == '/' */
+
+       *mybuf ++= '\0'; /* put a null at the end of the protocol */
+
+       if (strlen(_protocol) == 0)
+       {
+           /*
+            * If there is a hostname, then assume inet, otherwise
+            * it must be local.
+            */
+           if (*mybuf != ':')
+               _protocol = "inet";
+           else
+               _protocol = "local";
+       }
+    }
+
+    /* Get the host part */
+
+    _host = mybuf;
+
+    if ((mybuf = strchr (mybuf,':')) == NULL)
+    {
+       *protocol = NULL;
+       *host = NULL;
+       *port = NULL;
+       xfree (tmpptr);
+       return 0;
+    }
+
+    *mybuf ++= '\0';
+
+    if (strlen(_host) == 0)
+    {
+       TRANS(GetHostname) (hostnamebuf, sizeof (hostnamebuf));
+       _host = hostnamebuf;
+    }
+
+    /* Check for DECnet */
+
+    if (*mybuf == ':')
+    {
+       _protocol = "dnet";
+       mybuf++;
+    }
+
+    /* Get the port */
+
+get_port:
+
+    _port = mybuf;
+
+#if defined(FONT_t) || defined(FS_t)
+    /*
+     * Is there an optional catalogue list?
+     */
+
+    if ((mybuf = strchr (mybuf,'/')) != NULL)
+       *mybuf ++= '\0';
+
+    /*
+     * The rest, if any, is the (currently unused) catalogue list.
+     *
+     * _catalogue = mybuf;
+     */
+#endif
+
+    /*
+     * Now that we have all of the components, allocate new
+     * string space for them.
+     */
+
+    if ((*protocol = (char *) xalloc(strlen (_protocol) + 1)) == NULL)
+    {
+       /* Malloc failed */
+       *port = NULL;
+       *host = NULL;
+       *protocol = NULL;
+       xfree (tmpptr);
+       return 0;
+    }
+    else
+        strcpy (*protocol, _protocol);
+
+    if ((*host = (char *) xalloc (strlen (_host) + 1)) == NULL)
+    {
+       /* Malloc failed */
+       *port = NULL;
+       *host = NULL;
+       xfree (*protocol);
+       *protocol = NULL;
+       xfree (tmpptr);
+       return 0;
+       }
+    else
+        strcpy (*host, _host);
+
+    if ((*port = (char *) xalloc (strlen (_port) + 1)) == NULL)
+    {
+       /* Malloc failed */
+       *port = NULL;
+       xfree (*host);
+       *host = NULL;
+       xfree (*protocol);
+       *protocol = NULL;
+       xfree (tmpptr);
+       return 0;
+    }
+    else
+        strcpy (*port, _port);
+
+    xfree (tmpptr);
+
+    return 1;
+}
+
+
+/*
+ * TRANS(Open) does all of the real work opening a connection. The only
+ * funny part about this is the type parameter which is used to decide which
+ * type of open to perform.
+ */
+
+static XtransConnInfo
+TRANS(Open) (type, address)
+
+int    type;
+char   *address;
+
+{
+    char               *protocol = NULL, *host = NULL, *port = NULL;
+    XtransConnInfo     ciptr = NULL;
+    Xtransport         *thistrans;
+
+    PRMSG (2,"Open(%d,%s)\n", type, address, 0);
+
+#if defined(WIN32) && (defined(TCPCONN) || defined(DNETCONN))
+    if (TRANS(WSAStartup)())
+    {
+       PRMSG (1,"Open: WSAStartup failed\n", 0, 0, 0);
+       return NULL;
+    }
+#endif
+
+    /* Parse the Address */
+
+    if (TRANS(ParseAddress) (address, &protocol, &host, &port) == 0)
+    {
+       PRMSG (1,"Open: Unable to Parse address %s\n", address, 0, 0);
+       return NULL;
+    }
+
+    /* Determine the transport type */
+
+    if ((thistrans = TRANS(SelectTransport) (protocol)) == NULL)
+    {
+       PRMSG (1,"Open: Unable to find transport for %s\n",
+              protocol, 0, 0);
+
+       xfree (protocol);
+       xfree (host);
+       xfree (port);
+       return NULL;
+    }
+
+    /* Open the transport */
+
+    switch (type)
+    {
+    case XTRANS_OPEN_COTS_CLIENT:
+#ifdef TRANS_CLIENT
+       ciptr = thistrans->OpenCOTSClient(thistrans, protocol, host, port);
+#endif /* TRANS_CLIENT */
+       break;
+    case XTRANS_OPEN_COTS_SERVER:
+#ifdef TRANS_SERVER
+       ciptr = thistrans->OpenCOTSServer(thistrans, protocol, host, port);
+#endif /* TRANS_SERVER */
+       break;
+    case XTRANS_OPEN_CLTS_CLIENT:
+#ifdef TRANS_CLIENT
+       ciptr = thistrans->OpenCLTSClient(thistrans, protocol, host, port);
+#endif /* TRANS_CLIENT */
+       break;
+    case XTRANS_OPEN_CLTS_SERVER:
+#ifdef TRANS_SERVER
+       ciptr = thistrans->OpenCLTSServer(thistrans, protocol, host, port);
+#endif /* TRANS_SERVER */
+       break;
+    default:
+       PRMSG (1,"Open: Unknown Open type %d\n", type, 0, 0);
+    }
+
+    if (ciptr == NULL)
+    {
+       if (!(thistrans->flags & TRANS_DISABLED))
+           PRMSG (1,"Open: transport open failed for %s/%s:%s\n",
+                  protocol, host, port);
+       xfree (protocol);
+       xfree (host);
+       xfree (port);
+       return NULL;
+    }
+
+    ciptr->transptr = thistrans;
+    ciptr->port = port;                        /* We need this for TRANS(Reopen) */
+
+    xfree (protocol);
+    xfree (host);
+
+    return ciptr;
+}
+
+
+#ifdef TRANS_REOPEN
+
+/*
+ * We might want to create an XtransConnInfo object based on a previously
+ * opened connection.  For example, the font server may clone itself and
+ * pass file descriptors to the parent.
+ */
+
+static XtransConnInfo
+TRANS(Reopen) (type, trans_id, fd, port)
+
+int    type;
+int    trans_id;
+int    fd;
+char   *port;
+
+{
+    XtransConnInfo     ciptr = NULL;
+    Xtransport         *thistrans = NULL;
+    char               *save_port;
+    int                        i;
+
+    PRMSG (2,"Reopen(%d,%d,%s)\n", trans_id, fd, port);
+
+    /* Determine the transport type */
+
+    for (i = 0; i < NUMTRANS; i++)
+       if (Xtransports[i].transport_id == trans_id)
+       {
+           thistrans = Xtransports[i].transport;
+           break;
+       }
+
+    if (thistrans == NULL)
+    {
+       PRMSG (1,"Reopen: Unable to find transport id %d\n",
+              trans_id, 0, 0);
+
+       return NULL;
+    }
+
+    if ((save_port = (char *) xalloc (strlen (port) + 1)) == NULL)
+    {
+       PRMSG (1,"Reopen: Unable to malloc port string\n", 0, 0, 0);
+
+       return NULL;
+    }
+
+    strcpy (save_port, port);
+
+    /* Get a new XtransConnInfo object */
+
+    switch (type)
+    {
+    case XTRANS_OPEN_COTS_SERVER:
+       ciptr = thistrans->ReopenCOTSServer(thistrans, fd, port);
+       break;
+    case XTRANS_OPEN_CLTS_SERVER:
+       ciptr = thistrans->ReopenCLTSServer(thistrans, fd, port);
+       break;
+    default:
+       PRMSG (1,"Reopen: Bad Open type %d\n", type, 0, 0);
+    }
+
+    if (ciptr == NULL)
+    {
+       PRMSG (1,"Reopen: transport open failed\n", 0, 0, 0);
+       return NULL;
+    }
+
+    ciptr->transptr = thistrans;
+    ciptr->port = save_port;
+
+    return ciptr;
+}
+
+#endif /* TRANS_REOPEN */
+
+
+\f
+/*
+ * These are the public interfaces to this Transport interface.
+ * These are the only functions that should have knowledge of the transport
+ * table.
+ */
+
+#ifdef TRANS_CLIENT
+
+XtransConnInfo
+TRANS(OpenCOTSClient) (address)
+
+char   *address;
+
+{
+    PRMSG (2,"OpenCOTSClient(%s)\n", address, 0, 0);
+    return TRANS(Open) (XTRANS_OPEN_COTS_CLIENT, address);
+}
+
+#endif /* TRANS_CLIENT */
+
+
+#ifdef TRANS_SERVER
+
+XtransConnInfo
+TRANS(OpenCOTSServer) (address)
+
+char   *address;
+
+{
+    PRMSG (2,"OpenCOTSServer(%s)\n", address, 0, 0);
+    return TRANS(Open) (XTRANS_OPEN_COTS_SERVER, address);
+}
+
+#endif /* TRANS_SERVER */
+
+
+#ifdef TRANS_CLIENT
+
+XtransConnInfo
+TRANS(OpenCLTSClient) (address)
+
+char   *address;
+{
+    PRMSG (2,"OpenCLTSClient(%s)\n", address, 0, 0);
+    return TRANS(Open) (XTRANS_OPEN_CLTS_CLIENT, address);
+}
+
+#endif /* TRANS_CLIENT */
+
+
+#ifdef TRANS_SERVER
+
+XtransConnInfo
+TRANS(OpenCLTSServer) (address)
+
+char   *address;
+
+{
+    PRMSG (2,"OpenCLTSServer(%s)\n", address, 0, 0);
+    return TRANS(Open) (XTRANS_OPEN_CLTS_SERVER, address);
+}
+
+#endif /* TRANS_SERVER */
+
+
+#ifdef TRANS_REOPEN
+
+XtransConnInfo
+TRANS(ReopenCOTSServer) (trans_id, fd, port)
+
+int  trans_id;
+int  fd;
+char *port;
+
+{
+    PRMSG (2,"ReopenCOTSServer(%d, %d, %s)\n", trans_id, fd, port);
+    return TRANS(Reopen) (XTRANS_OPEN_COTS_SERVER, trans_id, fd, port);
+}
+
+XtransConnInfo
+TRANS(ReopenCLTSServer) (trans_id, fd, port)
+
+int  trans_id;
+int  fd;
+char *port;
+
+{
+    PRMSG (2,"ReopenCLTSServer(%d, %d, %s)\n", trans_id, fd, port);
+    return TRANS(Reopen) (XTRANS_OPEN_CLTS_SERVER, trans_id, fd, port);
+}
+
+
+int
+TRANS(GetReopenInfo) (ciptr, trans_id, fd, port)
+
+XtransConnInfo ciptr;
+int            *trans_id;
+int            *fd;
+char           **port;
+
+{
+    int i;
+
+    for (i = 0; i < NUMTRANS; i++)
+       if (Xtransports[i].transport == ciptr->transptr)
+       {
+           *trans_id = Xtransports[i].transport_id;
+           *fd = ciptr->fd;
+
+           if ((*port = (char *) xalloc (strlen (ciptr->port) + 1)) == NULL)
+               return 0;
+           else
+           {
+               strcpy (*port, ciptr->port);
+               return 1;
+           }
+       }
+
+    return 0;
+}
+
+#endif /* TRANS_REOPEN */
+
+
+int
+TRANS(SetOption) (ciptr, option, arg)
+
+XtransConnInfo ciptr;
+int            option;
+int            arg;
+
+{
+    int        fd = ciptr->fd;
+    int        ret = 0;
+
+    PRMSG (2,"SetOption(%d,%d,%d)\n", fd, option, arg);
+
+    /*
+     * For now, all transport type use the same stuff for setting options.
+     * As long as this is true, we can put the common code here. Once a more
+     * complicated transport such as shared memory or an OSI implementation
+     * that uses the session and application libraries is implemented, this
+     * code may have to move to a transport dependent function.
+     *
+     * ret = ciptr->transptr->SetOption (ciptr, option, arg);
+     */
+
+#ifdef MINIX
+    return ciptr->transptr->SetOption(ciptr, option, arg);
+#else /* !MINIX */
+
+    switch (option)
+    {
+    case TRANS_NONBLOCKING:
+       switch (arg)
+       {
+       case 0:
+           /* Set to blocking mode */
+           break;
+       case 1: /* Set to non-blocking mode */
+
+#if defined(O_NONBLOCK) && (!defined(ultrix) && !defined(hpux) && !defined(AIXV3) && !defined(uniosu) && !defined(__EMX__) && !defined(SCO))
+           ret = fcntl (fd, F_SETFL, O_NONBLOCK);
+#else
+#ifdef FIOSNBIO
+       {
+           int arg;
+           arg = 1;
+           ret = ioctl (fd, FIOSNBIO, &arg);
+       }
+#else
+#if (defined(AIXV3) || defined(uniosu) || defined(WIN32) || defined(__EMX__)) && defined(FIONBIO)
+       {
+           int arg;
+           arg = 1;
+/* IBM TCP/IP understands this option too well: it causes TRANS(Read) to fail
+ * eventually with EWOULDBLOCK */
+#ifndef __EMX__
+           ret = ioctl (fd, FIONBIO, &arg);
+#else
+/*         ret = ioctl(fd, FIONBIO, &arg, sizeof(int));*/
+#endif
+       }
+#else
+#ifdef FNDELAY
+           ret = fcntl (fd, F_SETFL, FNDELAY);
+#else
+           ret = fcntl (fd, F_SETFL, O_NDELAY);
+#endif
+#endif /* AIXV3  || uniosu */
+#endif /* FIOSNBIO */
+#endif /* O_NONBLOCK */
+           break;
+       default:
+           /* Unknown option */
+           break;
+       }
+       break;
+    case TRANS_CLOSEONEXEC:
+#ifdef F_SETFD
+#ifdef FD_CLOEXEC
+       ret = fcntl (fd, F_SETFD, FD_CLOEXEC);
+#else
+       ret = fcntl (fd, F_SETFD, 1);
+#endif /* FD_CLOEXEC */
+#endif /* F_SETFD */
+       break;
+    }
+    
+    return ret;
+#endif /* MINIX */
+}
+
+#ifdef TRANS_SERVER
+
+int
+TRANS(CreateListener) (ciptr, port)
+
+XtransConnInfo ciptr;
+char           *port;
+
+{
+    return ciptr->transptr->CreateListener (ciptr, port);
+}
+
+int
+TRANS(NoListen) (char * protocol)
+       
+{
+   Xtransport *trans;
+   
+   if ((trans = TRANS(SelectTransport)(protocol)) == NULL) 
+   {
+       PRMSG (1,"TRANS(TransNoListen): unable to find transport: %s\n", 
+              protocol, 0, 0);
+
+       return -1;
+   }
+   
+   trans->flags |= TRANS_NOLISTEN;
+   return 0;
+}
+
+int
+TRANS(ResetListener) (ciptr)
+
+XtransConnInfo ciptr;
+
+{
+    if (ciptr->transptr->ResetListener)
+       return ciptr->transptr->ResetListener (ciptr);
+    else
+       return TRANS_RESET_NOOP;
+}
+
+
+XtransConnInfo
+TRANS(Accept) (ciptr, status)
+
+XtransConnInfo ciptr;
+int            *status;
+
+{
+    XtransConnInfo     newciptr;
+
+    PRMSG (2,"Accept(%d)\n", ciptr->fd, 0, 0);
+
+    newciptr = ciptr->transptr->Accept (ciptr, status);
+
+    if (newciptr)
+       newciptr->transptr = ciptr->transptr;
+
+    return newciptr;
+}
+
+#endif /* TRANS_SERVER */
+
+
+#ifdef TRANS_CLIENT
+
+int
+TRANS(Connect) (ciptr, address)
+
+XtransConnInfo ciptr;
+char           *address;
+
+{
+    char       *protocol;
+    char       *host;
+    char       *port;
+    int                ret;
+
+    PRMSG (2,"Connect(%d,%s)\n", ciptr->fd, address, 0);
+
+    if (TRANS(ParseAddress) (address, &protocol, &host, &port) == 0)
+    {
+       PRMSG (1,"Connect: Unable to Parse address %s\n",
+              address, 0, 0);
+       return -1;
+    }
+
+    if (!port || !*port)
+    {
+       PRMSG (1,"Connect: Missing port specification in %s\n",
+             address, 0, 0);
+       if (protocol) xfree (protocol);
+       if (host) xfree (host);
+       return -1;
+    }
+
+    ret = ciptr->transptr->Connect (ciptr, host, port);
+
+    if (protocol) xfree (protocol);
+    if (host) xfree (host);
+    if (port) xfree (port);
+    
+    return ret;
+}
+
+#endif /* TRANS_CLIENT */
+
+
+int
+TRANS(BytesReadable) (ciptr, pend)
+
+XtransConnInfo ciptr;
+BytesReadable_t        *pend;
+
+{
+    return ciptr->transptr->BytesReadable (ciptr, pend);
+}
+
+int
+TRANS(Read) (ciptr, buf, size)
+
+XtransConnInfo ciptr;
+char           *buf;
+int            size;
+
+{
+    return ciptr->transptr->Read (ciptr, buf, size);
+}
+
+int
+TRANS(Write) (ciptr, buf, size)
+
+XtransConnInfo ciptr;
+char           *buf;
+int            size;
+
+{
+    return ciptr->transptr->Write (ciptr, buf, size);
+}
+
+int
+TRANS(Readv) (ciptr, buf, size)
+
+XtransConnInfo ciptr;
+struct iovec   *buf;
+int            size;
+{
+    return ciptr->transptr->Readv (ciptr, buf, size);
+}
+
+int
+TRANS(Writev) (ciptr, buf, size)
+
+XtransConnInfo ciptr;
+struct iovec   *buf;
+int            size;
+
+{
+    return ciptr->transptr->Writev (ciptr, buf, size);
+}
+
+int
+TRANS(Disconnect) (ciptr)
+
+XtransConnInfo ciptr;
+
+{
+    return ciptr->transptr->Disconnect (ciptr);
+}
+
+int
+TRANS(Close) (ciptr)
+
+XtransConnInfo ciptr;
+
+{
+    int ret;
+
+    PRMSG (2,"Close(%d)\n", ciptr->fd, 0, 0);
+
+    ret = ciptr->transptr->Close (ciptr);
+
+    TRANS(FreeConnInfo) (ciptr);
+
+    return ret;
+}
+
+int
+TRANS(CloseForCloning) (ciptr)
+
+XtransConnInfo ciptr;
+
+{
+    int ret;
+
+    PRMSG (2,"CloseForCloning(%d)\n", ciptr->fd, 0, 0);
+
+    ret = ciptr->transptr->CloseForCloning (ciptr);
+
+    TRANS(FreeConnInfo) (ciptr);
+
+    return ret;
+}
+
+int
+TRANS(IsLocal) (ciptr)
+
+XtransConnInfo ciptr;
+
+{
+    return (ciptr->family == AF_UNIX);
+}
+
+
+int
+TRANS(GetMyAddr) (ciptr, familyp, addrlenp, addrp)
+
+XtransConnInfo ciptr;
+int            *familyp;
+int            *addrlenp;
+Xtransaddr     **addrp;
+
+{
+    PRMSG (2,"GetMyAddr(%d)\n", ciptr->fd, 0, 0);
+
+    *familyp = ciptr->family;
+    *addrlenp = ciptr->addrlen;
+
+    if ((*addrp = (Xtransaddr *) xalloc (ciptr->addrlen)) == NULL)
+    {
+       PRMSG (1,"GetMyAddr: malloc failed\n", 0, 0, 0);
+       return -1;
+    }
+    memcpy(*addrp, ciptr->addr, ciptr->addrlen);
+
+    return 0;
+}
+
+int
+TRANS(GetPeerAddr) (ciptr, familyp, addrlenp, addrp)
+
+XtransConnInfo ciptr;
+int            *familyp;
+int            *addrlenp;
+Xtransaddr     **addrp;
+
+{
+    PRMSG (2,"GetPeerAddr(%d)\n", ciptr->fd, 0, 0);
+
+    *familyp = ciptr->family;
+    *addrlenp = ciptr->peeraddrlen;
+
+    if ((*addrp = (Xtransaddr *) xalloc (ciptr->peeraddrlen)) == NULL)
+    {
+       PRMSG (1,"GetPeerAddr: malloc failed\n", 0, 0, 0);
+       return -1;
+    }
+    memcpy(*addrp, ciptr->peeraddr, ciptr->peeraddrlen);
+
+    return 0;
+}
+
+
+int
+TRANS(GetConnectionNumber) (ciptr)
+
+XtransConnInfo ciptr;
+
+{
+    return ciptr->fd;
+}
+
+\f
+/*
+ * These functions are really utility functions, but they require knowledge
+ * of the internal data structures, so they have to be part of the Transport
+ * Independant API.
+ */
+
+static int
+complete_network_count ()
+
+{
+    int count = 0;
+    int found_local = 0;
+    int i;
+
+    /*
+     * For a complete network, we only need one LOCALCONN transport to work
+     */
+
+    for (i = 0; i < NUMTRANS; i++)
+    {
+       if (Xtransports[i].transport->flags & TRANS_ALIAS
+        || Xtransports[i].transport->flags & TRANS_NOLISTEN)
+           continue;
+
+       if (Xtransports[i].transport->flags & TRANS_LOCAL)
+           found_local = 1;
+       else
+           count++;
+    }
+
+    return (count + found_local);
+}
+
+
+#ifdef TRANS_SERVER
+
+int
+TRANS(MakeAllCOTSServerListeners) (port, partial, count_ret, ciptrs_ret)
+
+char           *port;
+int            *partial;
+int            *count_ret;
+XtransConnInfo         **ciptrs_ret;
+
+{
+    char               buffer[256]; /* ??? What size ?? */
+    XtransConnInfo     ciptr, temp_ciptrs[NUMTRANS];
+    int                        status, i, j;
+
+    PRMSG (2,"MakeAllCOTSServerListeners(%s,%x)\n",
+          port ? port : "NULL", ciptrs_ret, 0);
+
+    *count_ret = 0;
+
+    for (i = 0; i < NUMTRANS; i++)
+    {
+       Xtransport *trans = Xtransports[i].transport;
+
+       if (trans->flags&TRANS_ALIAS || trans->flags&TRANS_NOLISTEN)
+           continue;
+
+       sprintf(buffer,"%s/:%s", trans->TransName, port ? port : "");
+
+       PRMSG (5,"MakeAllCOTSServerListeners: opening %s\n",
+              buffer, 0, 0);
+
+       if ((ciptr = TRANS(OpenCOTSServer(buffer))) == NULL)
+       {
+           if (trans->flags & TRANS_DISABLED)
+               continue;
+
+           PRMSG (1,
+         "MakeAllCOTSServerListeners: failed to open listener for %s\n",
+                 trans->TransName, 0, 0);
+           continue;
+       }
+
+       if ((status = TRANS(CreateListener (ciptr, port))) < 0)
+       {
+           if (status == TRANS_ADDR_IN_USE)
+           {
+               /*
+                * We failed to bind to the specified address because the
+                * address is in use.  It must be that a server is already
+                * running at this address, and this function should fail.
+                */
+
+               PRMSG (1,
+               "MakeAllCOTSServerListeners: server already running\n",
+                 0, 0, 0);
+
+               for (j = 0; j < *count_ret; j++)
+                   TRANS(Close) (temp_ciptrs[j]);
+
+               *count_ret = 0;
+               *ciptrs_ret = NULL;
+               *partial = 0;
+               return -1;
+           }
+           else
+           {
+               PRMSG (1,
+       "MakeAllCOTSServerListeners: failed to create listener for %s\n",
+                 trans->TransName, 0, 0);
+
+               continue;
+           }
+       }
+
+       PRMSG (5,
+             "MakeAllCOTSServerListeners: opened listener for %s, %d\n",
+             trans->TransName, ciptr->fd, 0);
+
+       temp_ciptrs[*count_ret] = ciptr;
+       (*count_ret)++;
+    }
+
+    *partial = (*count_ret < complete_network_count());
+
+    PRMSG (5,
+     "MakeAllCLTSServerListeners: partial=%d, actual=%d, complete=%d \n",
+       *partial, *count_ret, complete_network_count());
+
+    if (*count_ret > 0)
+    {
+       if ((*ciptrs_ret = (XtransConnInfo *) xalloc (
+           *count_ret * sizeof (XtransConnInfo))) == NULL)
+       {
+           return -1;
+       }
+
+       for (i = 0; i < *count_ret; i++)
+       {
+           (*ciptrs_ret)[i] = temp_ciptrs[i];
+       }
+    }
+    else
+       *ciptrs_ret = NULL;
+    return 0;
+}
+
+int
+TRANS(MakeAllCLTSServerListeners) (port, partial, count_ret, ciptrs_ret)
+
+char           *port;
+int            *partial;
+int            *count_ret;
+XtransConnInfo         **ciptrs_ret;
+
+{
+    char               buffer[256]; /* ??? What size ?? */
+    XtransConnInfo     ciptr, temp_ciptrs[NUMTRANS];
+    int                        status, i, j;
+
+    PRMSG (2,"MakeAllCLTSServerListeners(%s,%x)\n",
+       port ? port : "NULL", ciptrs_ret, 0);
+
+    *count_ret = 0;
+
+    for (i = 0; i < NUMTRANS; i++)
+    {
+       Xtransport *trans = Xtransports[i].transport;
+
+       if (trans->flags&TRANS_ALIAS || trans->flags&TRANS_NOLISTEN)
+           continue;
+
+       sprintf(buffer,"%s/:%s", trans->TransName, port ? port : "");
+
+       PRMSG (5,"MakeAllCLTSServerListeners: opening %s\n",
+           buffer, 0, 0);
+
+       if ((ciptr = TRANS(OpenCLTSServer (buffer))) == NULL)
+       {
+           PRMSG (1,
+       "MakeAllCLTSServerListeners: failed to open listener for %s\n",
+                 trans->TransName, 0, 0);
+           continue;
+       }
+
+       if ((status = TRANS(CreateListener (ciptr, port))) < 0)
+       {
+           if (status == TRANS_ADDR_IN_USE)
+           {
+               /*
+                * We failed to bind to the specified address because the
+                * address is in use.  It must be that a server is already
+                * running at this address, and this function should fail.
+                */
+
+               PRMSG (1,
+               "MakeAllCLTSServerListeners: server already running\n",
+                 0, 0, 0);
+
+               for (j = 0; j < *count_ret; j++)
+                   TRANS(Close) (temp_ciptrs[j]);
+
+               *count_ret = 0;
+               *ciptrs_ret = NULL;
+               *partial = 0;
+               return -1;
+           }
+           else
+           {
+               PRMSG (1,
+       "MakeAllCLTSServerListeners: failed to create listener for %s\n",
+                 trans->TransName, 0, 0);
+
+               continue;
+           }
+       }
+
+       PRMSG (5,
+       "MakeAllCLTSServerListeners: opened listener for %s, %d\n",
+             trans->TransName, ciptr->fd, 0);
+       temp_ciptrs[*count_ret] = ciptr;
+       (*count_ret)++;
+    }
+
+    *partial = (*count_ret < complete_network_count());
+
+    PRMSG (5,
+     "MakeAllCLTSServerListeners: partial=%d, actual=%d, complete=%d \n",
+       *partial, *count_ret, complete_network_count());
+
+    if (*count_ret > 0)
+    {
+       if ((*ciptrs_ret = (XtransConnInfo *) xalloc (
+           *count_ret * sizeof (XtransConnInfo))) == NULL)
+       {
+           return -1;
+       }
+
+       for (i = 0; i < *count_ret; i++)
+       {
+           (*ciptrs_ret)[i] = temp_ciptrs[i];
+       }
+    }
+    else
+       *ciptrs_ret = NULL;
+    
+    return 0;
+}
+
+#endif /* TRANS_SERVER */
+
+
+\f
+/*
+ * These routines are not part of the X Transport Interface, but they
+ * may be used by it.
+ */
+
+#ifdef CRAY
+
+/*
+ * Cray UniCOS does not have readv and writev so we emulate
+ */
+
+static int TRANS(ReadV) (ciptr, iov, iovcnt)
+
+XtransConnInfo ciptr;
+struct iovec   *iov;
+int            iovcnt;
+
+{
+    struct msghdr hdr;
+
+    hdr.msg_iov = iov;
+    hdr.msg_iovlen = iovcnt;
+    hdr.msg_accrights = 0;
+    hdr.msg_accrightslen = 0;
+    hdr.msg_name = 0;
+    hdr.msg_namelen = 0;
+
+    return (recvmsg (ciptr->fd, &hdr, 0));
+}
+
+static int TRANS(WriteV) (ciptr, iov, iovcnt)
+
+XtransConnInfo ciptr;
+struct iovec   *iov;
+int            iovcnt;
+
+{
+    struct msghdr hdr;
+
+    hdr.msg_iov = iov;
+    hdr.msg_iovlen = iovcnt;
+    hdr.msg_accrights = 0;
+    hdr.msg_accrightslen = 0;
+    hdr.msg_name = 0;
+    hdr.msg_namelen = 0;
+
+    return (sendmsg (ciptr->fd, &hdr, 0));
+}
+
+#endif /* CRAY */
+
+#if (defined(SYSV) && defined(i386) && !defined(SCO325)) || defined(WIN32) || defined(__sxg__) || defined(__EMX__)
+
+/*
+ * emulate readv
+ */
+
+static int TRANS(ReadV) (ciptr, iov, iovcnt)
+
+XtransConnInfo ciptr;
+struct iovec   *iov;
+int            iovcnt;
+
+{
+    int i, len, total;
+    char *base;
+
+    ESET(0);
+    for (i = 0, total = 0;  i < iovcnt;  i++, iov++) {
+       len = iov->iov_len;
+       base = iov->iov_base;
+       while (len > 0) {
+           register int nbytes;
+           nbytes = TRANS(Read) (ciptr, base, len);
+           if (nbytes < 0 && total == 0)  return -1;
+           if (nbytes <= 0)  return total;
+           ESET(0);
+           len   -= nbytes;
+           total += nbytes;
+           base  += nbytes;
+       }
+    }
+    return total;
+}
+
+#endif /* SYSV && i386 || WIN32 || __sxg__ */
+
+#if (defined(SYSV) && defined(i386) && !defined(SCO325)) || defined(WIN32) || defined(__sxg__) || defined(__EMX__)
+
+/*
+ * emulate writev
+ */
+
+static int TRANS(WriteV) (ciptr, iov, iovcnt)
+
+XtransConnInfo ciptr;
+struct iovec   *iov;
+int            iovcnt;
+
+{
+    int i, len, total;
+    char *base;
+
+    ESET(0);
+    for (i = 0, total = 0;  i < iovcnt;  i++, iov++) {
+       len = iov->iov_len;
+       base = iov->iov_base;
+       while (len > 0) {
+           register int nbytes;
+           nbytes = TRANS(Write) (ciptr, base, len);
+           if (nbytes < 0 && total == 0)  return -1;
+           if (nbytes <= 0)  return total;
+           ESET(0);
+           len   -= nbytes;
+           total += nbytes;
+           base  += nbytes;
+       }
+    }
+    return total;
+}
+
+#endif /* SYSV && i386 || WIN32 || __sxg__ */
+
+
+#if (defined(_POSIX_SOURCE) && !defined(AIXV3)) || defined(hpux) || defined(USG) || defined(SVR4) || defined(SCO)
+#ifndef NEED_UTSNAME
+#define NEED_UTSNAME
+#endif
+#include <sys/utsname.h>
+#endif
+
+/*
+ * TRANS(GetHostname) - similar to gethostname but allows special processing.
+ */
+
+int TRANS(GetHostname) (buf, maxlen)
+
+char *buf;
+int maxlen;
+
+{
+    int len;
+
+#ifdef NEED_UTSNAME
+    struct utsname name;
+
+    uname (&name);
+    len = strlen (name.nodename);
+    if (len >= maxlen) len = maxlen - 1;
+    strncpy (buf, name.nodename, len);
+    buf[len] = '\0';
+#else
+    buf[0] = '\0';
+    (void) gethostname (buf, maxlen);
+    buf [maxlen - 1] = '\0';
+    len = strlen(buf);
+#endif /* NEED_UTSNAME */
+    return len;
+}
diff --git a/Xserver/lib/xtrans/Xtrans.h b/Xserver/lib/xtrans/Xtrans.h
new file mode 100644 (file)
index 0000000..cae4474
--- /dev/null
@@ -0,0 +1,501 @@
+/* $XConsortium: Xtrans.h,v 1.29 95/06/08 23:20:39 gildea Exp $ */
+/* $XFree86: xc/lib/xtrans/Xtrans.h,v 3.9 1997/01/18 06:52:39 dawes Exp $ */
+/*
+
+Copyright (c) 1993, 1994  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be included
+in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR
+OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall
+not be used in advertising or otherwise to promote the sale, use or
+other dealings in this Software without prior written authorization
+from the X Consortium.
+
+*/
+
+/* Copyright (c) 1993, 1994 NCR Corporation - Dayton, Ohio, USA
+ *
+ * All Rights Reserved
+ *
+ * Permission to use, copy, modify, and distribute this software and its
+ * documentation for any purpose and without fee is hereby granted, provided
+ * that the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the name NCR not be used in advertising
+ * or publicity pertaining to distribution of the software without specific,
+ * written prior permission.  NCR makes no representations about the
+ * suitability of this software for any purpose.  It is provided "as is"
+ * without express or implied warranty.
+ *
+ * NCR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN
+ * NO EVENT SHALL NCR BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
+ * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
+ * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
+ * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#ifndef _XTRANS_H_
+#define _XTRANS_H_
+
+#include <X11/Xfuncproto.h>
+#include <X11/Xos.h>
+
+
+/*
+ * Set the functions names according to where this code is being compiled.
+ */
+
+#ifdef X11_t
+#if (defined(__STDC__) && !defined(UNIXCPP)) || defined(ANSICPP)
+#define TRANS(func) _X11Trans##func
+#else
+#define TRANS(func) _X11Trans/**/func
+#endif
+static char* __xtransname = "_X11Trans";
+#endif /* X11_t */
+
+#ifdef XSERV_t
+#if (defined(__STDC__) && !defined(UNIXCPP)) || defined(ANSICPP)
+#define TRANS(func) _XSERVTrans##func
+#else
+#define TRANS(func) _XSERVTrans/**/func
+#endif
+static char* __xtransname = "_XSERVTrans";
+#define X11_t
+#endif /* X11_t */
+
+#ifdef XIM_t
+#if (defined(__STDC__) && !defined(UNIXCPP)) || defined(ANSICPP)
+#define TRANS(func) _XimXTrans##func
+#else
+#define TRANS(func) _XimXTrans/**/func
+#endif
+static char* __xtransname = "_XimTrans";
+#endif /* XIM_t */
+
+#ifdef FS_t
+#if (defined(__STDC__) && !defined(UNIXCPP)) || defined(ANSICPP)
+#define TRANS(func) _FSTrans##func
+#else
+#define TRANS(func) _FSTrans/**/func
+#endif
+static char* __xtransname = "_FSTrans";
+#endif /* FS_t */
+
+#ifdef FONT_t
+#if (defined(__STDC__) && !defined(UNIXCPP)) || defined(ANSICPP)
+#define TRANS(func) _FontTrans##func
+#else
+#define TRANS(func) _FontTrans/**/func
+#endif
+static char* __xtransname = "_FontTrans";
+#endif /* FONT_t */
+
+#ifdef ICE_t
+#if (defined(__STDC__) && !defined(UNIXCPP)) || defined(ANSICPP)
+#define TRANS(func) _IceTrans##func
+#else
+#define TRANS(func) _IceTrans/**/func
+#endif
+static char* __xtransname = "_IceTrans";
+#endif /* ICE_t */
+
+#ifdef TEST_t
+#if (defined(__STDC__) && !defined(UNIXCPP)) || defined(ANSICPP)
+#define TRANS(func) _TESTTrans##func
+#else
+#define TRANS(func) _TESTTrans/**/func
+#endif
+static char* __xtransname = "_TESTTrans";
+#endif /* TEST_t */
+
+#if !defined(TRANS)
+#if (defined(__STDC__) && !defined(UNIXCPP)) || defined(ANSICPP)
+#define TRANS(func) _XTrans##func
+#else
+#define TRANS(func) _XTrans/**/func
+#endif
+static char* __xtransname = "_XTrans";
+#endif /* !TRANS */
+
+
+/*
+ * Create a single address structure that can be used wherever
+ * an address structure is needed. struct sockaddr is not big enough
+ * to hold a sockadd_un, so we create this definition to have a single
+ * structure that is big enough for all the structures we might need.
+ *
+ * This structure needs to be independent of the socket/TLI interface used.
+ */
+
+#define XTRANS_MAX_ADDR_LEN    128     /* large enough to hold sun_path */
+
+typedef        struct {
+    unsigned char      addr[XTRANS_MAX_ADDR_LEN];
+} Xtransaddr;
+
+
+#ifdef LONG64
+typedef int BytesReadable_t;
+#else
+typedef long BytesReadable_t;
+#endif
+
+
+#if defined(WIN32) || (defined(USG) && !defined(CRAY) && !defined(umips) && !defined(MOTOROLA) && !defined(uniosu) && !defined(__sxg__)) || defined(MINIX)
+
+/*
+ *      TRANS(Readv) and TRANS(Writev) use struct iovec, normally found
+ *      in Berkeley systems in <sys/uio.h>.  See the readv(2) and writev(2)
+ *      manual pages for details.
+ */
+
+struct iovec {
+    caddr_t iov_base;
+    int iov_len;
+};
+
+#else
+#ifndef Lynx
+#include <sys/uio.h>
+#else
+#include <uio.h>
+#endif
+#endif
+
+typedef struct _XtransConnInfo *XtransConnInfo;
+
+
+/*
+ * Transport Option definitions
+ */
+
+#define TRANS_NONBLOCKING      1
+#define        TRANS_CLOSEONEXEC       2
+
+
+/*
+ * Return values of Connect (0 is success)
+ */
+
+#define TRANS_CONNECT_FAILED   -1
+#define TRANS_TRY_CONNECT_AGAIN -2
+
+
+/*
+ * Return values of CreateListener (0 is success)
+ */
+
+#define TRANS_CREATE_LISTENER_FAILED   -1
+#define TRANS_ADDR_IN_USE              -2
+
+
+/*
+ * Return values of Accept (0 is success)
+ */
+
+#define TRANS_ACCEPT_BAD_MALLOC                        -1
+#define TRANS_ACCEPT_FAILED                    -2
+#define TRANS_ACCEPT_MISC_ERROR                        -3
+
+
+/*
+ * ResetListener return values
+ */
+
+#define TRANS_RESET_NOOP       1
+#define TRANS_RESET_NEW_FD     2
+#define TRANS_RESET_FAILURE    3
+
+
+/*
+ * Function prototypes for the exposed interface
+ */
+
+#ifdef TRANS_CLIENT
+
+XtransConnInfo TRANS(OpenCOTSClient)(
+#if NeedFunctionPrototypes
+    char *             /* address */
+#endif
+);
+
+#endif /* TRANS_CLIENT */
+
+#ifdef TRANS_SERVER
+
+XtransConnInfo TRANS(OpenCOTSServer)(
+#if NeedFunctionPrototypes
+    char *             /* address */
+#endif
+);
+
+#endif /* TRANS_SERVER */
+
+#ifdef TRANS_CLIENT
+
+XtransConnInfo TRANS(OpenCLTSClient)(
+#if NeedFunctionPrototypes
+    char *             /* address */
+#endif
+);
+
+#endif /* TRANS_CLIENT */
+
+#ifdef TRANS_SERVER
+
+XtransConnInfo TRANS(OpenCLTSServer)(
+#if NeedFunctionPrototypes
+    char *             /* address */
+#endif
+);
+
+#endif /* TRANS_SERVER */
+
+#ifdef TRANS_REOPEN
+
+XtransConnInfo TRANS(ReopenCOTSServer)(
+#if NeedFunctionPrototypes
+    int,               /* trans_id */
+    int,               /* fd */
+    char *             /* port */
+#endif
+);
+
+XtransConnInfo TRANS(ReopenCLTSServer)(
+#if NeedFunctionPrototypes
+    int,               /* trans_id */
+    int,               /* fd */
+    char *             /* port */
+#endif
+);
+
+int TRANS(GetReopenInfo)(
+#if NeedFunctionPrototypes
+    XtransConnInfo,    /* ciptr */
+    int *,             /* trans_id */
+    int *,             /* fd */
+    char **            /* port */
+#endif
+);
+
+#endif /* TRANS_REOPEN */
+
+
+int TRANS(SetOption)(
+#if NeedFunctionPrototypes
+    XtransConnInfo,    /* ciptr */
+    int,               /* option */
+    int                        /* arg */
+#endif
+);
+
+#ifdef TRANS_SERVER
+
+int TRANS(CreateListener)(
+#if NeedFunctionPrototypes
+    XtransConnInfo,    /* ciptr */
+    char *             /* port */
+#endif
+);
+
+int TRANS(NoListen) (
+#if NeedFunctionPrototypes
+    char*               /* protocol*/
+#endif
+);
+
+int TRANS(ResetListener)(
+#if NeedFunctionPrototypes
+    XtransConnInfo     /* ciptr */
+#endif
+);
+
+XtransConnInfo TRANS(Accept)(
+#if NeedFunctionPrototypes
+    XtransConnInfo,    /* ciptr */
+    int *              /* status */
+#endif
+);
+
+#endif /* TRANS_SERVER */
+
+#ifdef TRANS_CLIENT
+
+int TRANS(Connect)(
+#if NeedFunctionPrototypes
+    XtransConnInfo,    /* ciptr */
+    char *             /* address */
+#endif
+);
+
+#endif /* TRANS_CLIENT */
+
+int TRANS(BytesReadable)(
+#if NeedFunctionPrototypes
+    XtransConnInfo,    /* ciptr */
+    BytesReadable_t *  /* pend */
+#endif
+);
+
+int TRANS(Read)(
+#if NeedFunctionPrototypes
+    XtransConnInfo,    /* ciptr */
+    char *,            /* buf */
+    int                        /* size */
+#endif
+);
+
+int TRANS(Write)(
+#if NeedFunctionPrototypes
+    XtransConnInfo,    /* ciptr */
+    char *,            /* buf */
+    int                        /* size */
+#endif
+);
+
+int TRANS(Readv)(
+#if NeedFunctionPrototypes
+    XtransConnInfo,    /* ciptr */
+    struct iovec *,    /* buf */
+    int                        /* size */
+#endif
+);
+
+int TRANS(Writev)(
+#if NeedFunctionPrototypes
+    XtransConnInfo,    /* ciptr */
+    struct iovec *,    /* buf */
+    int                        /* size */
+#endif
+);
+
+int TRANS(Disconnect)(
+#if NeedFunctionPrototypes
+    XtransConnInfo     /* ciptr */
+#endif
+);
+
+int TRANS(Close)(
+#if NeedFunctionPrototypes
+    XtransConnInfo     /* ciptr */
+#endif
+);
+
+int TRANS(CloseForCloning)(
+#if NeedFunctionPrototypes
+    XtransConnInfo     /* ciptr */
+#endif
+);
+
+int TRANS(IsLocal)(
+#if NeedFunctionPrototypes
+    XtransConnInfo     /* ciptr */
+#endif
+);
+
+int TRANS(GetMyAddr)(
+#if NeedFunctionPrototypes
+    XtransConnInfo,    /* ciptr */
+    int *,             /* familyp */
+    int *,             /* addrlenp */
+    Xtransaddr **      /* addrp */
+#endif
+);
+
+int TRANS(GetPeerAddr)(
+#if NeedFunctionPrototypes
+    XtransConnInfo,    /* ciptr */
+    int *,             /* familyp */
+    int *,             /* addrlenp */
+    Xtransaddr **      /* addrp */
+#endif
+);
+
+int TRANS(GetConnectionNumber)(
+#if NeedFunctionPrototypes
+    XtransConnInfo     /* ciptr */
+#endif
+);
+
+#ifdef TRANS_SERVER
+
+int TRANS(MakeAllCOTSServerListeners)(
+#if NeedFunctionPrototypes
+    char *,            /* port */
+    int *,             /* partial */
+    int *,             /* count_ret */
+    XtransConnInfo **  /* ciptrs_ret */
+#endif
+);
+
+int TRANS(MakeAllCLTSServerListeners)(
+#if NeedFunctionPrototypes
+    char *,            /* port */
+    int *,             /* partial */
+    int *,             /* count_ret */
+    XtransConnInfo **  /* ciptrs_ret */
+#endif
+);
+
+#endif /* TRANS_SERVER */
+
+
+/*
+ * Function Prototypes for Utility Functions.
+ */
+
+#ifdef X11_t
+
+int TRANS(ConvertAddress)(
+#if NeedFunctionPrototypes
+    int *,             /* familyp */
+    int *,             /* addrlenp */
+    Xtransaddr **      /* addrp */
+#endif
+);
+
+#endif /* X11_t */
+
+#ifdef ICE_t
+
+char *
+TRANS(GetMyNetworkId)(
+#if NeedFunctionPrototypes
+    XtransConnInfo     /* ciptr */
+#endif
+);
+
+char *
+TRANS(GetPeerNetworkId)(
+#if NeedFunctionPrototypes
+    XtransConnInfo     /* ciptr */
+#endif
+);
+
+#endif /* ICE_t */
+
+#if defined(WIN32) && (defined(TCPCONN) || defined(DNETCONN))
+int TRANS(WSAStartup)();
+#endif
+
+#endif /* _XTRANS_H_ */
diff --git a/Xserver/lib/xtrans/Xtransam.c b/Xserver/lib/xtrans/Xtransam.c
new file mode 100644 (file)
index 0000000..a52e181
--- /dev/null
@@ -0,0 +1,2008 @@
+/* $XConsortium: Xtransam.c,v 1.4 94/04/17 20:23:01 mor Exp $ */
+/* $XFree86: xc/lib/xtrans/Xtransam.c,v 3.1 1996/05/10 06:55:45 dawes Exp $ */
+/*
+
+Copyright (c) 1994  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be included
+in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR
+OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall
+not be used in advertising or otherwise to promote the sale, use or
+other dealings in this Software without prior written authorization
+from the X Consortium.
+
+*/
+
+/* Copyright (c) 1994 Vrije Universiteit Amsterdam, Netherlands
+ *
+ * All Rights Reserved
+ *
+ * Permission to use, copy, modify, and distribute this software and its
+ * documentation for any purpose and without fee is hereby granted, provided
+ * that the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the name Vrije Universiteit not be used
+ * in advertising or publicity pertaining to distribution of the software
+ * without specific, written prior permission.  The Vrije Universiteit
+ * makes no representations about the suitability of this software for
+ * any purpose.  It is provided "as is" without express or implied warranty.
+ *
+ * THE VRIJE UNIVERSITEIT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN
+ * NO EVENT SHALL THE VRIJE UNIVERSITEIT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
+ * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
+ * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
+ * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+/*
+ * This is the Amoeba implementation of the X Transport service layer
+ */
+
+#define event am_event_t
+#define interval am_interval_t
+#define port am_port_t
+#include <amoeba.h>
+#include <semaphore.h>
+#include <cmdreg.h>
+#include <stdcom.h>
+#include <stderr.h>
+#include <vc.h>
+#include <circbuf.h>
+#include <exception.h>
+#include <module/signals.h>
+#include <ampolicy.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <exception.h>
+#include <fault.h>
+#include <signal.h>
+#include <ctype.h>
+#include <module/name.h>
+#include <server/x11/Xamoeba.h>
+#include <server/ip/hton.h>
+#include <server/ip/types.h>
+#include <server/ip/gen/in.h>
+#include <server/ip/gen/tcp.h>
+#include <server/ip/tcpip.h>
+#include <server/ip/tcp_io.h>
+#include <server/ip/gen/tcp_io.h>
+#include <server/ip/gen/netdb.h>
+#include <server/ip/gen/inet.h>
+#undef event
+#undef interval
+#undef port
+
+extern char *strdup();
+
+/* a new family for Amoeba RPC connections */
+#define AF_AMOEBA      33
+#define FamilyAmoeba    33
+
+#define        MAX_TCPIP_RETRY 4
+#define        CIRCBUFSIZE     4096 /* was 1024 */
+
+/*
+ * Amoeba channel description:
+ */
+typedef struct _XAmChanDesc {
+    int                        state;          /* current state of connection */
+    int                        type;           /* type of connection */
+    int                        status;         /* status used by server */
+    signum             signal;         /* signal to kill TCP/IP reader */
+    semaphore          *sema;          /* select semaphore */
+    struct vc          *virtcirc;      /* virtual circuit for Amoeba RPC */
+    struct circbuf     *circbuf;       /* circular buffer for TCP/IP */
+    capability         chancap;        /* TCP/IP channel capability */
+    XtransConnInfo     conninfo;       /* back pointer to the connect info */
+} XAmChanDesc;
+
+/* Amoeba channel descriptor states */
+#define        ACDS_FREE       0               /* unused */
+#define        ACDS_USED       1               /* intermediate state */
+#define        ACDS_CLOSED     2               /* just closed */
+
+/* Amoeba channel types */
+#define        ACDT_TCPIP      1               /* TCP/IP connection */
+#define        ACDT_VIRTCIRC   2               /* Amoeba virtual circuit connection */
+
+
+#ifdef XSERV_t
+#include "dix.h" /* clients[] needed by AmFindReadyClients */
+#define Error(list) ErrorF list
+#define Fatal(list) FatalError list
+#else
+#define Error(list) printf list
+#define Fatal(list) { printf list; exit(1); }
+#endif
+
+#define dbprintf(list) /* printf list */
+#define doprintf(list) printf list /**/
+
+/*
+ * First: utility functions.
+ */
+
+#if defined(XSERV_t) || defined(FS_t)
+
+static semaphore main_sema;
+
+/* The X-server consists of one main thread, running the non re-entrant
+ * X code, and a number of auxilary threads that take care of reading
+ * the input streams, and input devices. The following set of routines
+ * wake up the main thread when it has something to do.
+ */
+void
+InitMainThread()
+{
+    sema_init(&main_sema, 0);
+}
+
+void
+WakeUpMainThread()
+{
+    sema_up(&main_sema);
+}
+
+int
+SleepMainThread(timeout)
+am_interval_t timeout;
+{
+    dbprintf(("Sleeping main thread timeout %d\n", timeout));
+    return (sema_trydown(&main_sema, timeout) == 0) ? 0 : -1;
+}
+
+
+static int init_waiters;
+static semaphore init_sema;
+
+void
+AmInitWaitFor()
+{
+    init_waiters = 0;
+    sema_init(&init_sema, 0);
+}
+
+/*
+ * Force caller thread to wait until main has finished the initialization.
+ */
+void
+WaitForInitialization()
+{
+    init_waiters++;
+    dbprintf(("Waiting for initialization (%d)\n", init_waiters));
+    sema_down(&init_sema);
+}
+
+void
+WakeupInitWaiters()
+{
+    /* wakeup threads in initial sleep */
+    if (init_waiters > 0) {
+       dbprintf(("%d waiters wait for something ...\n", init_waiters));
+       while (init_waiters-- > 0) {
+           sema_up(&init_sema);
+       }
+    }
+}
+
+#endif /* XSERV_t || FS_t */
+
+
+#define        THREAD_STACK_SIZE (8*1024)
+
+/*
+ * Amoeba connection information is stored in, so called,
+ * channel descriptors. Channel descriptors are identified
+ * by their index in the table below.
+ */
+static XAmChanDesc XAmChanDescriptors[OPEN_MAX];
+static void XAmCleanUpChanDesc(); /* forward */
+
+/*
+ * Cleanup connection descriptors on a signal
+ */
+static void
+XAmSignalCleanUpChanDesc(sig)
+    int sig;
+{
+    XAmCleanUpChanDesc();
+    _exit(sig | 0x80);
+}
+
+/*
+ * Cleanup connection descriptors
+ */
+static void
+XAmCleanUpChanDesc()
+{
+    register int i;
+
+    for (i = 0; i < OPEN_MAX; i++) {
+       switch (XAmChanDescriptors[i].type) {
+       case ACDT_TCPIP:
+           /* The Amoeba TCP/IP server is capability based, i.e.
+            * it uses capabilities to identify connections.  Since a
+            * capability is only destroyed when it has aged too much
+            * or is explicitly deleted, the connection it identifies
+            * will tend to exist for some while even if the client is
+            * already gone. To force connections to close this loop
+            * destroys all open TCP/IP connection. This loop us auto-
+            * matically executed when exit() is called.
+            */
+           std_destroy(&XAmChanDescriptors[i].chancap);
+           break;
+       case ACDT_VIRTCIRC:
+           /* Close the virtual circuit asynchronously, or otherwise
+            * we may hang for a minute under some (?) conditions.
+            */
+           vc_close(XAmChanDescriptors[i].virtcirc, VC_BOTH | VC_ASYNC);
+           break;
+       }
+       XAmChanDescriptors[i].state = ACDS_FREE;
+    }
+}
+
+/*
+ * Allocate a channel descriptor
+ */
+static XAmChanDesc *
+XAmAllocChanDesc()
+{
+    register int i;
+
+#ifndef XSERV_t
+
+    static int initialized = 0;
+
+    /*
+     * Since the TCP/IP server is capability based its connections exists
+     * even if the owner process is long gone. To overcome this nuisance,
+     * a sweep is made over the connection descriptors when exit() is
+     * called or when an un-catched (by application program) signal is 
+     * received.
+     */
+    if (!initialized) {
+       initialized = 1;
+       atexit(XAmCleanUpChanDesc);
+       if (signal(SIGHUP, SIG_IGN) != SIG_IGN)
+           signal(SIGHUP, XAmSignalCleanUpChanDesc);
+       if (signal(SIGQUIT, SIG_IGN) != SIG_IGN)
+           signal(SIGQUIT, XAmSignalCleanUpChanDesc);
+       if (signal(SIGINT, SIG_IGN) != SIG_IGN)
+           signal(SIGINT, XAmSignalCleanUpChanDesc);
+       if (signal(SIGTERM, SIG_IGN) != SIG_IGN)
+           signal(SIGTERM, XAmSignalCleanUpChanDesc);
+    }
+#endif
+
+    for (i = 0; i < OPEN_MAX; i++) {
+       if (XAmChanDescriptors[i].state == ACDS_FREE) {
+           XAmChanDescriptors[i].state = ACDS_USED;
+           XAmChanDescriptors[i].conninfo = NULL;
+           return &XAmChanDescriptors[i];
+       }
+    }
+    return NULL;
+}
+
+/*
+ * Convert ``file descriptor'' to channel descriptor
+ */
+static XAmChanDesc *
+XAmFdToChanDesc(fd)
+    int fd;
+{
+    if (fd >= 0 && fd < OPEN_MAX) {
+       return &XAmChanDescriptors[fd];
+    } else {
+       return NULL;
+    }
+}
+
+/*
+ * Convert channel descriptor to ``file descriptor''
+ */
+static int
+XAmChanDescToFd(chandesc)
+    XAmChanDesc *chandesc;
+{
+    return chandesc - XAmChanDescriptors;
+}
+
+/*
+ * Free channel descriptor
+ */
+static void
+XAmFreeChanDesc(chandesc)
+    XAmChanDesc *chandesc;
+{
+    if (chandesc->sema) {
+       xfree(chandesc->sema);
+       chandesc->sema = NULL;
+    }
+    chandesc->state = ACDS_FREE;
+}
+
+static void XAmReaderThread();
+
+static int
+MakeAmConnection(phostname, idisplay, familyp, saddrlenp, saddrp)
+    char *phostname;
+    int idisplay;
+    int *familyp;                      /* RETURN */
+    int *saddrlenp;                    /* RETURN */
+    char **saddrp;                     /* RETURN */
+{
+    capability xservercap;
+    char xserverpath[256];
+    XAmChanDesc *chandesc;
+    errstat err;
+
+    /* Amoeba requires a server hostname */
+    if (phostname == NULL || *phostname == '\0') {
+       fprintf(stderr, "MakeAmConnection: Display name expected\n");
+       return -1;
+    }
+
+    /* allocate channel descriptor */
+    chandesc = XAmAllocChanDesc();
+    if (chandesc == NULL) {
+       fprintf(stderr, "MakeAmConnection: Out of channel capabilities\n");
+       return -1;
+    }
+
+    /*
+     * There are two possible way to make a connection on Amoeba. Either
+     * through an Amoeba RPC or a TCP/IP connection. Depending on whether
+     * the X server resides on Amoeba, Amoeba RPC's are used. Otherwise
+     * it uses a TCP/IP connection.
+     */
+    (void)sprintf(xserverpath, "%s/%s:%d", DEF_XSVRDIR, phostname, idisplay);
+    if ((err = name_lookup(xserverpath, &xservercap)) == STD_OK) {
+       am_port_t vccaps[2];
+       bufsize size;
+       errstat err;
+       header hdr;
+
+       /* Amoeba virtual circuit connection */
+       chandesc->type = ACDT_VIRTCIRC;
+
+       /* get the two connection ports from the X-server */
+       hdr.h_command = AX_CONNECT;
+       hdr.h_port = xservercap.cap_port;
+       hdr.h_priv = xservercap.cap_priv;
+       size = trans(&hdr, NILBUF, 0, &hdr, (char *)vccaps, sizeof(vccaps));
+       if (ERR_STATUS(size)) {
+           err = ERR_CONVERT(size);
+       } else {
+           err = ERR_CONVERT(hdr.h_status);
+       }
+       if (err != STD_OK || size != sizeof(vccaps)) {
+           fprintf(stderr, "Xlib: connect to Amoeba X-server failed (%s)\n",
+                   err_why(err));
+           XAmFreeChanDesc(chandesc);
+           return -1;
+       }
+
+       /* setup an Amoeba virtual circuit */
+       chandesc->virtcirc =
+           vc_create(&vccaps[1], &vccaps[0], MAXBUFSIZE, MAXBUFSIZE);
+       if (chandesc->virtcirc == (struct vc *)NULL) {
+           fprintf(stderr, "Xlib: Amoeba virtual circuit create failed\n");
+           XAmFreeChanDesc(chandesc);
+           return -1;
+       }
+
+       /* Special Amoeba family type. For Amoeba no additional access control
+        * mechanism exists;  when you have the server capability, you have
+        * the access.  Just use a fake address.
+        */
+       *familyp = AF_AMOEBA;
+       *saddrp = strdup("Amoeba");
+       *saddrlenp = strlen(*saddrp);
+    } else {
+       char tcpname[256];
+       capability tcpcap;
+       ipaddr_t ipaddr;
+       char *tcpsvr;
+       nwio_tcpcl_t tcpcl;
+       nwio_tcpconf_t tcpconf;
+       XAmChanDesc **param;
+       int result;
+
+       /* Amoeba TCP/IP connection */
+       chandesc->type = ACDT_TCPIP;
+
+       /* lookup up TCP/IP server */
+       if ((tcpsvr = getenv("TCP_SERVER")) == NULL) {
+           tcpsvr = TCP_SVR_NAME;
+       }
+       if ((err = name_lookup(tcpsvr, &tcpcap)) != STD_OK) {
+           fprintf(stderr, "Xlib: Cannot lookup %s (%s)\n",
+                   tcpsvr, err_why(err));
+           std_destroy(&chandesc->chancap);
+           XAmFreeChanDesc(chandesc);
+           return -1;
+       }
+
+       /* establish TCP/IP connection */
+       if ((err = tcpip_open(&tcpcap, &chandesc->chancap)) != STD_OK) {
+           fprintf(stderr, "Xlib: Cannot open TCP/IP server on %s (%s)\n",
+                   tcpsvr, tcpip_why(err));
+           std_destroy(&chandesc->chancap);
+           XAmFreeChanDesc(chandesc);
+           return -1;
+       }
+
+       /* lookup TCP/IP hostname */
+       if (isdigit(phostname[0])) {
+           ipaddr = inet_addr(phostname);
+       } else {
+           struct hostent *hp = gethostbyname(phostname);
+           if (hp == NULL) {
+               fprintf(stderr, "Xlib: %s unknown host\n", phostname);
+               return -1;
+           }
+           memcpy(&ipaddr, hp->h_addr, hp->h_length);
+       }
+
+       /* set remote address/port on the TCP/IP connection */
+       tcpconf.nwtc_flags = NWTC_SET_RA|NWTC_SET_RP|NWTC_LP_SEL;
+       tcpconf.nwtc_remaddr = ipaddr;
+       tcpconf.nwtc_remport = htons(6000+idisplay);
+       if ((err = tcp_ioc_setconf(&chandesc->chancap, &tcpconf)) != STD_OK) {
+           fprintf(stderr, "Xlib: Cannot configure TCP/IP server (%s)\n",
+                   tcpip_why(err));
+           std_destroy(&chandesc->chancap);
+           XAmFreeChanDesc(chandesc);
+           return -1;
+       }
+
+       /* make the actual TCP/IP connection */
+       tcpcl.nwtcl_flags = 0;
+       if ((err = tcp_ioc_connect(&chandesc->chancap, &tcpcl)) != STD_OK) {
+           fprintf(stderr, "Xlib: Cannot make TCP/IP connection (%s)\n",
+                   tcpip_why(err));
+           std_destroy(&chandesc->chancap);
+           XAmFreeChanDesc(chandesc);
+           return -1;
+       }
+
+       /* start TCP/IP reader thread */
+       chandesc->signal = sig_uniq();
+       chandesc->circbuf = cb_alloc(CIRCBUFSIZE);
+       param = (XAmChanDesc **) xalloc(sizeof(XAmChanDesc *)); /* error checking? */
+       *param = chandesc;
+       result = thread_newthread(XAmReaderThread, THREAD_STACK_SIZE,
+                                 (char *)param, sizeof(XAmChanDesc *));
+       if (result == 0) {
+           fprintf(stderr, "Xlib: Cannot start reader thread\n");
+           std_destroy(&chandesc->chancap);
+           XAmFreeChanDesc(chandesc);
+           return -1;
+       }
+       threadswitch(); /* give reader a try */
+
+       /*
+        * Family type is set to Internet so that the .Xauthority
+        * files from Unix will work under Amoeba (for Unix displays).
+        */
+       *familyp = AF_INET;
+       *saddrlenp = sizeof(ipaddr_t);
+       *saddrp = xalloc(sizeof(ipaddr_t));
+       memcpy(*saddrp, (char *)&ipaddr, sizeof(ipaddr_t)); /* error checking? */
+    }
+
+    return XAmChanDescToFd(chandesc);
+}
+
+/*
+ * The TCP/IP server silently assumes a maximum buffer size of 30000 bytes.
+ */
+#define        TCPIP_BUFSIZE   16384
+
+static void
+XAMCloseChannel(chandesc)
+XAmChanDesc *chandesc;
+{
+    if (chandesc->state == ACDS_USED && chandesc->type == ACDT_TCPIP) {
+       cb_close(chandesc->circbuf);
+       chandesc->state = ACDS_CLOSED;
+    }
+}
+
+
+/*
+ * Shutdown TCP/IP reader thread
+ */
+static void
+XAmReaderSignalCatcher(sig, us, extra)
+    signum sig;
+    thread_ustate *us;
+    _VOIDSTAR extra;
+{
+    register XAmChanDesc *chandesc = (XAmChanDesc *)extra;
+
+    XAMCloseChannel(chandesc);
+    thread_exit();
+}
+
+/*
+ * TCP/IP reader thread
+ */
+static void
+XAmReaderThread(argptr, argsize)
+    void *argptr;
+    int argsize;
+{
+    register XAmChanDesc *chandesc;
+
+    chandesc = *((XAmChanDesc **)argptr);
+    (void) sig_catch(chandesc->signal, XAmReaderSignalCatcher,
+                    (_VOIDSTAR) chandesc);
+
+    while (chandesc->state == ACDS_USED) {
+       char buffer[CIRCBUFSIZE];
+       bufsize size;
+
+       size = tcpip_read(&chandesc->chancap, buffer, sizeof(buffer));
+       if (ERR_STATUS(size) || size == 0) {
+           if (size == 0) {
+               static char msg[] = "Xlib: TCP/IP channel closed\n";
+
+               write(2, msg, sizeof(msg));
+           } else {
+               fprintf(stderr, "Xlib: TCP/IP read failed (%s)\n",
+                       err_why(ERR_CONVERT(size)));
+           }
+           XAMCloseChannel(chandesc);
+           break;
+       }
+
+       if (cb_puts(chandesc->circbuf, buffer, size) != 0) {
+           fprintf(stderr, "Xlib: short write to circular buffer\n");
+           XAMCloseChannel(chandesc);
+       }
+    }
+
+    thread_exit();
+}
+
+/*
+ * Wait until input is available or until the timer expires.
+ */
+int
+TRANS(AmSelect)(ifd, timout)
+    int ifd;
+    int timout;
+{
+    XAmChanDesc *chandesc;
+    int n;
+
+    errno = 0;
+
+    chandesc = XAmFdToChanDesc(ifd);
+    if (chandesc == NULL || chandesc->state != ACDS_USED) {
+       errno = EBADF;
+       return -1;
+    }
+
+    if (chandesc->sema == NULL) {
+       /* Allocate semaphore to sleep on when no data is
+        * available. The underlying circular buffer and
+        * virtual circuit packages manage this semaphore.
+        */
+       chandesc->sema = (semaphore *) xalloc(sizeof(semaphore));
+       if (chandesc->sema == NULL) {
+           errno = ENOMEM;
+           return -1;
+       }
+
+       sema_init(chandesc->sema, 0);
+       switch (chandesc->type) {
+       case ACDT_TCPIP:
+           cb_setsema(chandesc->circbuf, chandesc->sema);
+           break;
+       case ACDT_VIRTCIRC:
+           vc_setsema(chandesc->virtcirc, chandesc->sema);
+           break;
+       }
+    }
+
+    switch (chandesc->type) {
+    case ACDT_TCPIP:
+       if ((n = cb_full(chandesc->circbuf)) != 0) {
+           if (n < 0) errno = EPIPE;
+           return n; /* includes error as well */
+       }
+       if (sema_trydown(chandesc->sema, timout) < 0) {
+           errno = EINTR;
+           return -1;
+       } else {
+           /* we down for all the bytes in AMRead, so undo the down */
+           sema_up(chandesc->sema);
+       }
+       if ((n = cb_full(chandesc->circbuf)) < 0) {
+           errno = EPIPE;
+           return -1;
+       }
+       return n;
+
+    case ACDT_VIRTCIRC:
+       if ((n = vc_avail(chandesc->virtcirc, VC_IN)) != 0) {
+           if (n < 0) errno = EPIPE;
+           return n; /* includes error as well */
+       }
+       if (sema_trydown(chandesc->sema, timout) < 0) {
+           errno = EINTR;
+           return -1;
+       } else {
+           /* we down for all the bytes in AMRead, so undo the down */
+           sema_up(chandesc->sema);
+       }
+       if ((n = vc_avail(chandesc->virtcirc, VC_IN)) < 0) {
+           errno = EPIPE;
+           return -1;
+       }
+       return n;
+    }
+
+    errno = EINVAL;
+    return -1;
+}
+
+/*
+ * This function gets the local address of the transport and stores it in the
+ * XtransConnInfo structure for the connection.
+ */
+
+static int
+TRANS(AMGetAddr)(ciptr)
+XtransConnInfo ciptr;
+{
+    PRMSG(1,"AMGetAddr(%x)\n", ciptr, 0,0 );
+    PRMSG(1,"AMGetAddr: TODO\n", 0, 0, 0);
+
+    return -1;
+}
+
+
+/*
+ * This function gets the remote address of the socket and stores it in the
+ * XtransConnInfo structure for the connection.
+ */
+
+static int
+TRANS(AMGetPeerAddr)(ciptr)
+XtransConnInfo ciptr;
+{
+    struct nwio_tcpconf tcpconf;
+    errstat err;
+    XAmChanDesc *chandesc;
+
+    PRMSG(2,"AMGetPeerAddr(%x)\n", ciptr, 0,0 );
+
+    chandesc = XAmFdToChanDesc(ciptr->fd);
+    if (chandesc == NULL || chandesc->state != ACDS_USED) {
+       errno = EBADF;
+       return -1;
+    }
+
+    switch (chandesc->type) {
+    case ACDT_TCPIP:
+       /* get the remote adress from the TCP/IP server */
+       if ((err = tcp_ioc_getconf(&chandesc->chancap, &tcpconf)) != STD_OK) {
+           PRMSG (1, "AMGetPeerAddr: Cannot get remote address (%d)\n",
+                  (int) err, 0, 0);
+           return -1;
+       }
+
+#if 0 /* debug */
+        {
+           struct hostent *remote;
+           char *hostname;
+
+           remote = gethostbyaddr((char *) &tcpconf.nwtc_remaddr,
+                                  sizeof(tcpconf.nwtc_remaddr), AF_INET);
+           if ((remote == NULL) || (remote->h_name == NULL)) {
+               hostname = inet_ntoa(tcpconf.nwtc_remaddr);
+           } else {
+               hostname = remote->h_name;
+           }
+           PRMSG (1, "AMGetPeerAddr: remote addr `%s'\n",
+                  hostname, 0, 0);
+       }
+#endif
+
+       ciptr->peeraddrlen = sizeof(tcpconf.nwtc_remaddr);
+       ciptr->peeraddr = (char *) xalloc (ciptr->peeraddrlen);
+       if (ciptr->peeraddr == NULL) {
+           PRMSG (1, "AMGetPeerAddr: Can't allocate peeraddr\n",
+                  0, 0, 0);
+           return -1;
+       }
+
+       memcpy (ciptr->peeraddr, &tcpconf.nwtc_remaddr, ciptr->peeraddrlen);
+       break;
+
+    case ACDT_VIRTCIRC:
+       /* for Amoeba virtual circuits just copy the client address */
+       if ((ciptr->peeraddr = (char *) xalloc (ciptr->addrlen)) == NULL) {
+           PRMSG (1, "AMGetPeerAddr: Can't allocate peeraddr\n",
+                  0, 0, 0);
+           return -1;
+       }
+
+       ciptr->peeraddrlen = ciptr->addrlen;
+       memcpy (ciptr->peeraddr, ciptr->addr, ciptr->peeraddrlen);
+       break;
+    }
+
+    return 0;
+}
+
+
+static XtransConnInfo
+TRANS(AMOpen)(device)
+char   *device;
+{
+    PRMSG(1,"AMOpen(%s)\n", device, 0,0 );
+    PRMSG(1,"AMOpen: TODO\n", 0, 0, 0);
+
+    return NULL;
+}
+
+
+static int
+TRANS(AMAddrToNetbuf)(tlifamily, host, port, netbufp)
+int            tlifamily;
+char           *host;
+char           *port;
+struct netbuf  *netbufp;
+{
+    PRMSG(1,"AMAddrToNetbuf(%d,%s,%s)\n", tlifamily, host, port );
+    PRMSG(1,"AMAddrToNetbuf: TODO\n", 0, 0, 0);
+
+    return -1;
+}
+
+/*
+ * These functions are the interface supplied in the Xtransport structure
+ */
+
+#ifdef TRANS_CLIENT
+
+static XtransConnInfo
+TRANS(AMOpenCOTSClient)(thistrans, protocol, host, port)
+Xtransport     *thistrans;
+char           *protocol;
+char           *host;
+char           *port;
+{
+    XtransConnInfo  ciptr;
+    XAmChanDesc    *chandesc;
+
+    PRMSG(2,"AMOpenCOTSClient(%s,%s,%s)\n", protocol, host, port );
+    
+    ciptr = (XtransConnInfo) xcalloc (1, sizeof(struct _XtransConnInfo));
+    if (ciptr == NULL) {
+        PRMSG (1, "AMOpenCotsClient: malloc failed\n", 0, 0, 0);
+        return NULL;
+    }
+
+    ciptr->fd = MakeAmConnection (host, 0 /* TODO */, &ciptr->family,
+                                 &ciptr->addrlen, &ciptr->addr);
+    if (ciptr->fd < 0) {
+       PRMSG(1,"AMOpenCOTSClient: Unable to make connection to %s\n",
+             host, 0,0 );
+       xfree(ciptr);
+       return NULL;
+    }
+
+    /* set the back pointer */
+    chandesc = XAmFdToChanDesc(ciptr->fd);
+    chandesc->conninfo = ciptr;
+
+    TRANS(AMGetPeerAddr)(ciptr);
+
+    PRMSG(2,"AMOpenCOTSClient: made connection to %s; fd = %d, family = %d\n",
+         host, ciptr->fd, ciptr->family);
+
+    return ciptr;
+}
+
+#endif /* TRANS_CLIENT */
+
+#if defined(XSERV_t) || defined(FS_t)
+
+/* The following defines come from osdep.h;
+ * they should removed from there eventually.
+ */
+
+/*
+ * Some fundamental constants
+ */
+#define CONNECTOR_STACK 4000    /* stack for connector task */
+#define DEVREADER_STACK 4000    /* stack for device reader */
+#define CREATOR_STACK   4000    /* stack for connection creator */
+#define MAXTASKS        100     /* Maximum # clients */
+
+/*
+ * OsComm status bits
+ */
+#define CONN_KILLED     0x1     /* Connection being closed */
+#define REQ_PUSHBACK    0x2     /* Request pushed back */
+#define IGNORE          0x4     /* True if client ignored */
+#define CONN_INIT       0x8     /* True if still initializing */
+#define CONN_ALIVE      0x10    /* True if living */
+
+
+#define REPLY_BUFSIZE   30000
+
+capability     X;                      /* X capability */
+char           *XServerHostName;       /* X server host name */
+char           *XTcpServerName;        /* TCP/IP server name */
+
+static XtransConnInfo NewConns[MAXTASKS]; /* new client connections */
+int                  nNewConns;          /* # of new clients */
+
+int            maxClient;              /* Highest allocated client fd + 1*/
+static int     minClient = 1;          /* Lowest allocated client fd */
+
+static char *
+OsCommStatus(status)
+    int status;
+{
+    static char buf[100];
+
+    buf[0] = '\0';
+    if (status == 0)
+       sprintf(buf, "NONE");
+    if (status & CONN_INIT)
+       sprintf(buf, "%s INIT", buf);
+    if (status & CONN_ALIVE)
+       sprintf(buf, "%s ALIVE", buf);
+    if (status & CONN_KILLED)
+       sprintf(buf, "%s KILLED", buf);
+    if (status & REQ_PUSHBACK)
+       sprintf(buf, "%s PUSHBACK", buf);
+    if (status & IGNORE)
+       sprintf(buf, "%s IGNORE", buf);
+    return buf;
+}
+
+static char *
+OsCommFamily(family)
+    int family;
+{
+    if (family == FamilyAmoeba) {
+       return "AMOEBA";
+    } else {
+       return "TCP/IP";
+    }
+}
+
+
+/*
+ * Return status information about the open connections
+ */
+static errstat
+ConnectionStatus(hdr, buf, size)
+    header *hdr;
+    char *buf;
+    int size;
+{
+    char       *begin, *end;
+    char       *bprintf();
+    int fd;
+    XAmChanDesc *chandesc;
+
+    begin = buf;
+    end = buf + size;
+
+
+    /* all active clients */
+    begin = bprintf(begin, end, "Active clients:\n");
+    for (fd = minClient; fd < maxClient; fd++) {
+       static XAmChanDesc *chandesc;
+
+       chandesc = XAmFdToChanDesc(fd);
+       if (chandesc != NULL && chandesc->conninfo != NULL) {
+           begin = bprintf(begin, end, "%d: Family %s, State %d, Status %s\n",
+                           fd, OsCommFamily(chandesc->conninfo->family),
+                           chandesc->state, OsCommStatus(chandesc->status));
+       }
+    }
+
+    if (begin == NULL) {
+       hdr->h_size = 0;
+       return STD_SYSERR;
+    } else {
+       hdr->h_size = begin - buf;
+       return STD_OK;
+    }
+}
+
+/*
+ * Wakeup main thread if necessary
+ */
+static void
+UnblockMain(fd)
+int fd;
+{
+    XAmChanDesc *chandesc;
+
+    chandesc = XAmFdToChanDesc(fd);
+    if (chandesc != NULL) {
+       if ((chandesc->status & IGNORE) == 0) {
+           WakeUpMainThread();
+       }
+    } else {
+       Error(("UnblockMain: invalid fd %d\n", fd));
+    }
+}
+
+static void
+TcpIpReaderSignalCatcher(sig, us, extra)
+    signum sig;
+    thread_ustate *us;
+    _VOIDSTAR extra;
+{
+    XAmChanDesc *chandesc = (XAmChanDesc *) extra;
+
+    if (chandesc->conninfo != NULL) {
+       dbprintf(("TcpIpReaderSignalCatcher(%d), number %d\n",
+                 sig, chandesc->conninfo->fd));
+       if (chandesc->signal != sig) {
+           Error(("TCP/IP Reader: Connection %s got unexpected signal %d\n",
+                  chandesc->conninfo->fd, sig));
+       }
+    }
+
+    chandesc->signal = -1;
+    thread_exit();
+}
+
+void
+TcpIpReaderThread(argptr, argsize)
+    void *argptr;
+    int argsize;
+{
+    XAmChanDesc *chandesc;
+
+    if (argsize != sizeof(XAmChanDesc *)) {
+       Fatal(("Internal error: TcpIpReaderThread incorrectly called\n"));
+    }
+
+    chandesc = * ((XAmChanDesc **) argptr);
+    (void) sig_catch(chandesc->signal, TcpIpReaderSignalCatcher,
+                    (_VOIDSTAR) chandesc);
+
+    for (;;) {
+       char buffer[MAXBUFSIZE];
+       bufsize size;
+
+       size = tcpip_read(&chandesc->chancap, buffer, sizeof(buffer));
+
+       dbprintf(("TcpIpReaderThread() read %d bytes\n", size));
+       if (ERR_STATUS(size)) {
+           Error(("TCP/IP read failed (%s)\n", tcpip_why(ERR_CONVERT(size))));
+           chandesc->status |= CONN_KILLED;
+           chandesc->status &= ~CONN_ALIVE;
+           chandesc->signal = -1;
+           thread_exit();
+       }
+
+       if (size == 0 || cb_puts(chandesc->circbuf, buffer, size)) {
+           if (size != 0) {
+               Error(("TCP/IP short write to circular buffer for %d\n",
+                      XAmChanDescToFd(chandesc)));
+           } else {
+               Error(("TCP/IP read failed for client %d\n",
+                      XAmChanDescToFd(chandesc)));
+           }
+
+           chandesc->status |= CONN_KILLED;
+           chandesc->status &= ~CONN_ALIVE;
+           chandesc->signal = -1;
+           thread_exit();
+       }
+       UnblockMain(XAmChanDescToFd(chandesc));
+    }
+}
+
+static XAmChanDesc *
+AllocClientChannel()
+{
+    XAmChanDesc *chandesc;
+    int fd;
+
+    chandesc = XAmAllocChanDesc();
+    if (chandesc == NULL) {
+       return NULL;
+    }
+
+    fd = XAmChanDescToFd(chandesc);
+    if (fd >= maxClient) {
+       maxClient = fd + 1;
+       dbprintf(("new max Client: %d\n", fd));
+    }
+    if (fd < minClient) {
+       minClient = fd;
+    }
+
+    return chandesc;
+}
+
+static errstat
+AmRegisterRPCconn(client_ports, server_ports)
+am_port_t client_ports[2];
+am_port_t server_ports[2];
+{
+    XAmChanDesc *chandesc;
+
+    if ((chandesc = AllocClientChannel()) == NULL) {
+       return STD_NOSPACE;
+    }
+
+    chandesc->type = ACDT_VIRTCIRC;
+    chandesc->virtcirc = vc_create(&server_ports[0], &server_ports[1],
+                                  MAXBUFSIZE, MAXBUFSIZE);
+    if (chandesc->virtcirc == NULL) {
+       Error(("Connection refused: No memory for virtual circuit\n"));
+       XAmFreeChanDesc(chandesc);
+       return STD_NOSPACE;
+    }
+
+    dbprintf(("Amoeba connection registered\n"));
+
+    vc_warn(chandesc->virtcirc, VC_IN, UnblockMain, XAmChanDescToFd(chandesc));
+    
+    chandesc->status = CONN_INIT;
+
+    /* cause WaitFor to call EstablishNewConnections: */
+    nNewConns++;
+    WakeUpMainThread();
+
+    return STD_OK;
+}
+
+static XAmChanDesc *
+XAmFetchConnectingClient()
+{
+    XAmChanDesc *chandesc;
+    int fd;
+
+    for (fd = minClient; fd < maxClient; fd++) {
+       chandesc = XAmFdToChanDesc(fd);
+
+       if (chandesc->status & CONN_INIT) {
+           Error(("Client %d is connecting\n", fd));
+           chandesc->status &= ~CONN_INIT;
+           return chandesc;
+       }
+    }
+
+    return NULL;
+}
+
+static errstat
+AmRegisterTCPconn(chancap)
+capability *chancap;
+{
+    XAmChanDesc *chandesc, **param;
+
+    if ((chandesc = AllocClientChannel()) == NULL) {
+       return STD_NOSPACE;
+    }
+    
+    chandesc->type = ACDT_TCPIP;
+    chandesc->chancap = *chancap;
+
+    if ((chandesc->circbuf = cb_alloc(MAXBUFSIZE)) == NULL) {
+       Error(("TCPconn refused: No memory for circular buffer\n"));
+       XAmFreeChanDesc(chandesc);
+       return STD_NOSPACE;
+    }
+
+    chandesc->signal = sig_uniq();
+    param = (XAmChanDesc **) xalloc(sizeof(XAmChanDesc *)); /* error checking? */
+    *param = chandesc;
+    if (thread_newthread(TcpIpReaderThread, MAXBUFSIZE + CONNECTOR_STACK,
+                        (char *)param, sizeof(XAmChanDesc *)) == 0)
+    {
+       Error(("TCPconn refused: Cannot start reader thread\n"));
+       cb_close(chandesc->circbuf);
+       cb_free(chandesc->circbuf);
+       XAmFreeChanDesc(chandesc);
+       return STD_NOSPACE;
+    }
+
+    dbprintf(("TCP connection registered\n"));
+
+    chandesc->status = CONN_INIT;
+
+    /* cause WaitFor to call EstablishNewConnections: */
+    nNewConns++;
+    WakeUpMainThread();
+
+    return STD_OK;
+}
+
+
+/*
+ * Establishing a new connection is done in two phases. This thread does the
+ * first part. It filters out bad connect requests. A new rendevous port is
+ * sent to the client and the main loop is informed if there is a legal
+ * request. The sleep synchronizes with the main loop so that the paperwork
+ * is finished for the current connect request before the thread is ready to
+ * accept another connect.
+ */
+static void
+AmConnectorThread()
+{
+    header     req, rep;
+    am_port_t  client_ports[2];
+    am_port_t  server_ports[2];
+    short      s;
+    char       *repb;
+    extern     CreateNewClient();
+
+    WaitForInitialization();
+    dbprintf(("AmConnectorThread() running ...\n"));
+    if ((repb = (char *)xalloc(REPLY_BUFSIZE)) == NULL) {
+       Fatal(("Amoeba connector thread: malloc failed"));
+    }
+    for (;;) {
+       do {
+           req.h_port = X.cap_port;
+           s = getreq(&req, NILBUF, 0);
+       } while (ERR_CONVERT(s) == RPC_ABORTED);
+       if (ERR_STATUS(s))
+           Fatal(("Amoeba connector thread: getreq failed"));
+
+       /* TODO: check privilege fields here */
+
+       dbprintf(("AmConnectorThread() accepting a request\n"));
+
+       switch (req.h_command) {
+
+       case STD_INFO:
+           rep.h_status = STD_OK;
+           sprintf(repb, "X11R6 server on %s", XServerHostName);
+           rep.h_size = strlen(repb);
+           putrep(&rep, repb, rep.h_size);
+           break;
+
+       case STD_STATUS:
+           rep.h_status = ConnectionStatus(&rep, repb, REPLY_BUFSIZE);
+           putrep(&rep, repb, rep.h_size);
+           break;
+
+#ifdef XSERV_t
+       case AX_SHUTDOWN:
+           rep.h_status = STD_OK;
+           putrep(&rep, NILBUF, 0);
+           GiveUp(SIGTERM);
+           break;
+
+       case AX_REINIT:
+           rep.h_status = STD_OK;
+           putrep(&rep, NILBUF, 0);
+           AutoResetServer(SIGINT);
+           break;
+#endif
+
+       case AX_CONNECT:
+           uniqport(&client_ports[0]);
+           uniqport(&server_ports[1]);
+           priv2pub(&client_ports[0], &server_ports[0]);
+           priv2pub(&server_ports[1], &client_ports[1]);
+
+           rep.h_status = AmRegisterRPCconn(client_ports, server_ports);
+           if (rep.h_status == STD_OK) {
+               putrep(&rep, (bufptr)client_ports, 2*sizeof(am_port_t));
+           } else {
+               putrep(&rep, NILBUF, 0);
+           }
+           break;
+
+       default:
+           rep.h_status = STD_COMBAD;
+           putrep(&rep, NILBUF, 0);
+           break;
+       }
+    }
+}
+
+#ifdef XSERV_t
+
+/*
+ * To prevent the X-server from generating lots of error messages,
+ * in case the server is gone or when its full.
+ */
+#define        LOOP_OPEN       1
+#define        LOOP_SETCONF    2
+#define        LOOP_LISTEN     4
+
+extern char *display;          /* The display number */
+
+/*
+ * The TCP/IP connector thread listens to a well known port (6000 +
+ * display number) for connection request. When such a request arrives
+ * it allocates a communication structure and a reader thread. This
+ * thread prevents the main loop from blocking when there's no data.
+ */
+static void
+AmTCPConnectorThread()
+{
+    capability         svrcap, chancap;
+    nwio_tcpconf_t     tcpconf;
+    nwio_tcpcl_t       tcpconnopt;
+    char               name[BUFSIZ];
+    errstat            err;
+    int                        result;
+    int                        looping = 0;
+
+    strncpy(name, XTcpServerName, BUFSIZ);
+    if ((err = name_lookup(name, &svrcap)) != STD_OK) {
+       sprintf(name, "%s/%s", TCP_SVR_NAME, XTcpServerName);
+       if ((err = name_lookup(name, &svrcap)) != STD_OK)
+           Fatal(("Lookup %s failed: %s\n", XTcpServerName, err_why(err)));
+    }
+
+    WaitForInitialization();
+    dbprintf(("AmTCPConnectorThread() running ...\n"));
+
+    for (;;) {
+       /*
+        * Listen to TCP/IP port X_TCP_PORT + display for connections.
+        * Some interesting actions have to be taken to keep this connection
+        * alive and kicking :-)
+        */
+       if ((err = tcpip_open(&svrcap, &chancap)) != STD_OK) {
+           /* the server probably disappeared, just wait for it to return */
+           if (looping & LOOP_OPEN) {
+               Error(("TCP/IP open failed: %s\n", tcpip_why(err)));
+               looping |= LOOP_OPEN;
+           }
+           sleep(60);
+           (void) name_lookup(name, &svrcap);
+           continue;
+       }
+       looping &= ~LOOP_OPEN;
+
+       tcpconf.nwtc_locport = htons(X_TCP_PORT + atoi(display));
+       tcpconf.nwtc_flags = NWTC_EXCL | NWTC_LP_SET | NWTC_UNSET_RA | 
+                                                               NWTC_UNSET_RP;
+       if ((err = tcp_ioc_setconf(&chancap, &tcpconf)) != STD_OK) {
+           /* couldn't configure, probably server space problem */
+           if (looping & LOOP_SETCONF) {
+               Error(("TCP/IP setconf failed: %s\n", tcpip_why(err)));
+               looping |= LOOP_SETCONF;
+           }
+           std_destroy(&chancap);
+           sleep(60);
+           continue;
+       }
+       looping &= ~LOOP_SETCONF;
+
+       tcpconnopt.nwtcl_flags = 0;
+       if ((err = tcp_ioc_listen(&chancap, &tcpconnopt)) != STD_OK) {
+           /* couldn't listen, definitely a server memory problem */
+           if (looping & LOOP_LISTEN) {
+               Error(("TCP/IP listen failed: %s\n", tcpip_why(err)));
+               looping |= LOOP_LISTEN;
+           }
+           std_destroy(&chancap);
+           sleep(60);
+           continue;
+       }
+       looping &= ~LOOP_LISTEN;
+
+       if ((err = tcpip_keepalive_cap(&chancap)) != STD_OK) {
+           Error(("TCP/IP keep alive failed: %s\n", tcpip_why(err)));
+           std_destroy(&chancap);
+           continue;
+       }
+
+       err = AmRegisterTCPconn(&chancap);
+       if (err != STD_OK) {
+           Error(("AmRegisterTCPconn failed (%s)\n", err_why(err)));
+           std_destroy(&chancap);
+       }
+    }
+}
+
+static void
+AmStartXserverThreads(chandesc)
+XAmChanDesc *chandesc;
+{
+    char               host[100];
+    errstat            err;
+    capability         pubX;
+    static int         threadsStarted = 0;
+
+    /*
+     * Each time the server is reset this routine is called to
+     * setup the new well known sockets. For Amoeba we'll just
+     * keep using the old threads that are already running.
+     */
+    if (!threadsStarted) {
+       threadsStarted = 1;
+
+       /*
+        * Create a new capability for this X server
+        */
+       if (XServerHostName == NULL)
+           XServerHostName = getenv("XHOST");
+       if (XServerHostName == NULL) {
+           Fatal(("XHOST not set, or server host name not given\n"));
+       }
+       sprintf(host, "%s/%s:%s", DEF_XSVRDIR, XServerHostName, display);
+
+       uniqport(&X.cap_port);
+       priv2pub(&X.cap_port, &pubX.cap_port);
+       (void) name_delete(host);
+       if ((err = name_append(host, &pubX)) != 0) {
+           Error(("Cannot create capability %s: %s\n", host, err_why(err)));
+           exit(1);
+       }
+
+       /* Allow WaitFor module to initialize */
+       AmInitWaitFor();
+
+       /* Also, initialize main thread locking */
+       InitMainThread();
+
+       /* Initialize and start IOP reader thread */
+       InitializeIOPServerReader();
+
+       /* Start native Amoeba service threads */
+       if (thread_newthread(AmConnectorThread, CONNECTOR_STACK, 0, 0) <= 0) {
+           Fatal(("Cannot start Amoeba connector thread\n"));
+       }
+       if (thread_newthread(AmConnectorThread, CONNECTOR_STACK, 0, 0) <= 0) {
+           Fatal(("Cannot start Amoeba connector thread\n"));
+       }
+       chandesc->type = ACDT_VIRTCIRC;
+       chandesc->status = CONN_ALIVE;
+
+       /*
+        * Start TCP/IP service threads
+        */
+       if (XTcpServerName) {
+           if (thread_newthread(AmTCPConnectorThread,
+                                CONNECTOR_STACK, 0, 0) <= 0)
+               Fatal(("Cannot start TCP connector thread\n"));
+           if (thread_newthread(AmTCPConnectorThread,
+                                CONNECTOR_STACK, 0, 0) <= 0)
+               Fatal(("Cannot start TCP connector thread\n"));
+       }
+    }
+}
+
+int
+AmFindReadyClients(pClientsReady, mask)
+int *pClientsReady;
+long *mask;
+{
+    /* Check for clients needing attention.  They may have input,
+     * or they might be dying.  Ignore the clients not present in
+     * the file descriptor bit vector `mask'.  This is used for
+     * implementing server grabs.
+     * Returns the number of clients having data for us.
+     */
+    extern int ConnectionTranslation[];
+    XAmChanDesc *chandesc;
+    int fd;
+    int nready;
+
+    /* Since we're scheduled non-preemptively by default, allow the
+     * listener threads to run first, if needed:
+     */
+    threadswitch();
+
+    nready = 0;
+    for (fd = minClient; fd < maxClient; fd++) {
+       int which;
+       int n;
+
+       if (fd > 0 && (fd % 32) == 0) {
+           /* switch to next fd mask */
+           mask++;
+       }
+
+       if ((*mask & (1L << fd)) == 0) {
+           dbprintf(("skip %d\n", fd));
+           continue;
+       }
+
+       chandesc = XAmFdToChanDesc(fd);
+       if (chandesc->state != ACDS_USED) {
+           dbprintf(("AmFindReady: fd %d not in use\n", fd));
+           continue;
+       }
+
+       which = ConnectionTranslation[fd];
+       dbprintf(("checking client %d (fd %d) of %d\n",
+                 fd, which, maxClient));
+
+       if (chandesc->status & CONN_KILLED) {
+           dbprintf(("conn killed; close client with fd %d\n", fd));
+           CloseDownClient(clients[which]);
+           chandesc->status &= ~(CONN_KILLED | CONN_ALIVE);
+           continue;
+       }
+
+       if ((chandesc->status & CONN_ALIVE) == 0) {
+           dbprintf(("conn with %d is not alive\n", fd));
+           continue;
+       }
+
+       /* see if there is data available */
+       switch (chandesc->type) {
+       case ACDT_TCPIP:
+           n = cb_full(chandesc->circbuf);
+           break;
+       case ACDT_VIRTCIRC:
+           n = vc_avail(chandesc->virtcirc, VC_IN);
+           break;
+       default:
+           n = -1;
+       }
+
+       if (n < 0) {
+           dbprintf(("avail %d; close client %d\n", n, which));
+           CloseDownClient(clients[which]);
+           continue;
+       } else {
+           if (n > 0) {
+               *pClientsReady++ = which;
+               nready++;
+               dbprintf(("client %d has %d bytes available\n", which, n));
+           } else {
+               dbprintf(("client %d has no data available\n", which, n));
+           }
+       }
+
+       /* Clients that already have (possibly inserted) data are found
+        * with help from io.c (the ClientsWithData bit array).
+        */
+    }
+
+    return nready;
+}
+
+#endif /* XSERV_t */
+
+#endif /* XSERV_t || FS_t */
+
+static
+TRANS(AmSetAddr)(ciptr, chandesc)
+    XtransConnInfo  ciptr;
+    XAmChanDesc    *chandesc;
+{
+    switch (chandesc->type) {
+    case ACDT_TCPIP:
+       /* should really ask the TCP/IP server */
+       ciptr->family = AF_INET;
+       ciptr->addr = strdup("XXXXTODO");
+       ciptr->addrlen = strlen("XXXXTODO");
+       break;
+    case ACDT_VIRTCIRC:
+       /* For Amoeba connections the adress is not really used,
+        * so just fake something
+        */
+       ciptr->family = AF_AMOEBA;
+       ciptr->addr = strdup("Amoeba");
+       ciptr->addrlen = strlen(ciptr->addr);
+       break;
+    }
+}
+
+#ifdef TRANS_SERVER
+
+static XtransConnInfo
+TRANS(AMOpenCOTSServer)(thistrans, protocol, given_host, port)
+Xtransport     *thistrans;
+char           *protocol;
+char           *given_host;
+char           *port;
+{
+    XAmChanDesc    *chandesc;
+    XtransConnInfo  ciptr;
+
+    PRMSG(2,"AMOpenCOTSServer(%s,%s,%s)\n", protocol, given_host, port);
+
+    ciptr = (XtransConnInfo) xcalloc (1, sizeof(struct _XtransConnInfo));
+    if (ciptr == NULL) {
+        PRMSG (1, "AMOpenCotsClient: malloc failed\n", 0, 0, 0);
+        return NULL;
+    }
+
+    chandesc = XAmAllocChanDesc();
+    if (chandesc == NULL) {
+       return NULL;
+    }
+
+#ifdef XSERV_t
+    AmStartXserverThreads(chandesc);
+#endif
+
+    chandesc->conninfo = ciptr;
+    ciptr->fd = XAmChanDescToFd(chandesc);
+
+    TRANS(AmSetAddr)(ciptr, chandesc);
+    TRANS(AMGetPeerAddr)(ciptr);
+
+    return ciptr;
+}
+
+#endif /* TRANS_SERVER */
+
+
+#ifdef TRANS_CLIENT
+
+static XtransConnInfo
+TRANS(AMOpenCLTSClient)(thistrans, protocol, host, port)
+Xtransport     *thistrans;
+char           *protocol;
+char           *host;
+char           *port;
+{
+    XtransConnInfo     ciptr;
+    int                i;
+    
+    PRMSG(1,"AMOpenCLTSClient(%d,%s,%s)\n", protocol, host, port );
+    /* TODO */
+    return NULL;
+}                      
+
+#endif /* TRANS_CLIENT */
+
+
+#ifdef TRANS_SERVER
+
+static XtransConnInfo
+TRANS(AMOpenCLTSServer)(thistrans, protocol, host, port)
+Xtransport     *thistrans;
+char           *protocol;
+char           *host;
+char           *port;
+{
+    XtransConnInfo     ciptr;
+    int                i;
+    
+    PRMSG(1,"AMOpenCLTSServer(%d,%s,%s)\n", protocol, host, port );
+    /* TODO */
+    return NULL;
+}                      
+
+static int
+TRANS(AMResetListener)(ciptr)
+XtransConnInfo ciptr;
+{
+    PRMSG(2,"AMResetListener()\n", 0, 0, 0 );
+
+    /* nothing to do? */
+    return 0;
+}
+
+#endif /* TRANS_SERVER */
+
+static
+TRANS(AMSetOption)(ciptr, option, arg)
+XtransConnInfo ciptr;
+int            option;
+int            arg;
+{
+    PRMSG(1,"AMSetOption(%d,%d,%d)\n", ciptr->fd, option, arg );
+    /* TODO */
+    return -1;
+}
+
+
+#ifdef TRANS_SERVER
+
+static
+TRANS(AMCreateListener)(ciptr, req)
+XtransConnInfo ciptr;
+char          *req;
+{
+    PRMSG(2,"AMCreateListener(%x->%d,%x)\n", ciptr, ciptr->fd, req );
+
+    /* Listener threads are already created at this point */
+    return 0;
+}
+
+
+static XtransConnInfo
+TRANS(AMAccept)(ciptr)
+XtransConnInfo ciptr;
+{
+    XAmChanDesc    *chandesc;
+    XtransConnInfo  newciptr;
+
+    PRMSG(2,"AMAccept(%x->%d)\n", ciptr, ciptr->fd, 0 );
+
+#if defined(XSERV_t) || defined(FS_t)
+    chandesc = XAmFetchConnectingClient();
+    if (chandesc == NULL) {
+        PRMSG (1, "AMAccept: no client waiting?\n", 0, 0, 0);
+        return NULL;
+    }
+    nNewConns--;
+
+    newciptr = (XtransConnInfo) xcalloc (1, sizeof(struct _XtransConnInfo));
+    if (newciptr == NULL)
+    {
+        PRMSG (1, "AMAccept: malloc failed\n", 0, 0, 0);
+        return NULL;
+    }
+
+    newciptr->fd = XAmChanDescToFd(chandesc);
+    chandesc->conninfo = newciptr;
+    chandesc->status |= CONN_ALIVE;
+
+    PRMSG(2,"AMAccept: OK: (%x->%d)\n", newciptr, newciptr->fd, 0 );
+
+    TRANS(AmSetAddr)(newciptr, chandesc);
+    TRANS(AMGetPeerAddr)(newciptr);
+    
+    return newciptr;
+#else
+    return NULL;
+#endif
+}
+
+#endif /* TRANS_SERVER */
+
+
+#ifdef TRANS_CLIENT
+
+static
+TRANS(AMConnect)(ciptr, host, port)
+XtransConnInfo ciptr;
+char           *host;
+char           *port;
+{
+    /* If this function is called, we are already connected */
+    PRMSG(2, "AMConnect(%d,%s)\n", ciptr->fd, host, 0);
+    return 0;
+}
+
+#endif /* TRANS_CLIENT */
+
+
+int
+TRANS(AmFdBytesReadable)(fd, count)
+int fd;
+BytesReadable_t        *count;
+{
+    register XAmChanDesc *chandesc;
+
+    PRMSG(2, "AmFdBytesReadable(%d,%x): ", fd, count, 0 );
+
+#ifndef XSERV_t
+    /* give reader threads a chance: */
+    threadswitch();
+#endif
+
+    errno = 0;
+    chandesc = XAmFdToChanDesc(fd);
+    if (chandesc == NULL || chandesc->state != ACDS_USED) {
+       errno = EBADF;
+       *count = 0;
+       return -1;
+    }
+
+    switch (chandesc->type) {
+    case ACDT_TCPIP:
+       *count = cb_full(chandesc->circbuf);
+       break;
+    case ACDT_VIRTCIRC:
+       *count = vc_avail(chandesc->virtcirc, VC_IN);
+       break;
+    }
+
+    if (*count < 0) {
+       errno = (chandesc->state == ACDS_CLOSED) ? EINTR : EPIPE;
+       *count = 0;
+       return -1;
+    }
+
+    PRMSG(2, "AMFdBytesReadable: %d\n", *count, 0, 0 );
+
+    return 0;
+}
+
+static
+TRANS(AMBytesReadable)(ciptr, count)
+XtransConnInfo ciptr;
+BytesReadable_t        *count;
+{
+    return TRANS(AmFdBytesReadable)(ciptr->fd, count);
+}
+
+
+static
+TRANS(AMRead)(ciptr, buf, count)
+XtransConnInfo ciptr;
+char           *buf;
+int            count;
+{
+    int fdi;
+    register XAmChanDesc *chandesc;
+    register int rv;
+    BytesReadable_t avail;
+
+    fdi = ciptr->fd;
+    PRMSG(2, "AMRead(%d,%x,%d)\n", ciptr->fd, buf, count );
+
+    errno = 0;
+    chandesc = XAmFdToChanDesc(fdi);
+    if (chandesc == NULL || chandesc->state != ACDS_USED) {
+       errno = EBADF;
+       return -1;
+    }
+
+    /* do a non-blocking read (maybe only conditionally?) */
+    if ((TRANS(AMBytesReadable)(ciptr, &avail)) == 0) {
+       if (avail <= 0) {
+           PRMSG(2, "AMRead: nothing available yet\n", 0, 0, 0);
+           errno = EAGAIN;
+           return 0;
+       } else if (count > avail) {
+           PRMSG(2, "AMRead(%d): only %d of %d available\n",
+                 ciptr->fd, avail, count);
+           count = avail; /* just read amount available */
+       }
+    } else {
+       PRMSG(1, "AMRead: ...BytesReadable failed\n", 0, 0, 0);
+       return -1;
+    }
+
+    switch (chandesc->type) {
+    case ACDT_TCPIP:
+       rv = cb_gets(chandesc->circbuf, buf, count, count);
+       if (rv != count) {
+           if (rv == 0) {
+               fprintf(stderr, "Xlib: Cannot read circbuf\n");
+               errno = EPIPE;
+               rv = -1;
+           } else {
+               fprintf(stderr, "Xlib: Cannot read circbuf (%d)\n", rv);
+           }
+       }
+       break;
+
+    case ACDT_VIRTCIRC:
+       rv = vc_readall(chandesc->virtcirc, buf, count);
+       if (rv < 0) {
+           fprintf(stderr, "Xlib: Cannot read virtual circuit\n");
+           errno = EPIPE;
+           rv = -1;
+       }
+       break;
+    }
+
+    /* The circular buffer writer will only UP the semaphore when
+     * characters are available; we have to down it ourselfs.
+     */
+    if (chandesc->sema && rv > 0)
+       sema_mdown(chandesc->sema, rv);
+
+    PRMSG(2, "AMRead: %d bytes\n", rv, 0, 0);
+
+    return rv;
+}
+
+
+static
+TRANS(AMWrite)(ciptr, buf, count)
+XtransConnInfo ciptr;
+char           *buf;
+int            count;
+{
+    register XAmChanDesc *chandesc;
+    register int written;
+    
+    PRMSG(2, "AMWrite(%d,%x,%d)\n", ciptr->fd, buf, count );
+
+    errno = 0;
+    written = 0;
+
+    chandesc = XAmFdToChanDesc(ciptr->fd);
+    if (chandesc == NULL || chandesc->state != ACDS_USED) {
+       errno = EBADF;
+       return -1;
+    }
+
+    switch (chandesc->type) {
+    case ACDT_TCPIP:
+       while (count > 0) {
+           bufsize bsize;
+           int wrcnt;
+
+           wrcnt = count > TCPIP_BUFSIZE ? TCPIP_BUFSIZE : count;
+           bsize = tcpip_write(&chandesc->chancap, buf, wrcnt);
+           if (ERR_STATUS(bsize)) {
+               fprintf(stderr, "Xlib: TCP/IP write failed (%s)\n",
+                       tcpip_why(ERR_CONVERT(bsize)));
+               errno = EPIPE;
+               return -1;
+           }
+           if (bsize != wrcnt) {
+               fprintf(stderr,
+                       "Xlib: TCP/IP write failed (expected %d, wrote %d)\n",
+                       (int)bsize, wrcnt);
+               errno = EPIPE;
+               return -1;
+           }
+           buf += bsize;
+           count -= (int) bsize;
+           written += (int) bsize;
+       }
+       break;
+
+    case ACDT_VIRTCIRC:
+       if ((written = vc_write(chandesc->virtcirc, buf, count)) < 0) {
+           fprintf(stderr, "Xlib: virtual circuit write failed\n");
+           errno = EPIPE;
+           return -1;
+       }
+       break;
+    }
+
+    return written;
+}
+
+
+static
+TRANS(AMReadv)(ciptr, iov, n)
+XtransConnInfo ciptr;
+struct iovec   *iov;
+int            n;
+{
+    int i;
+    int count = 0, thiscount;
+
+    PRMSG(2, "AMReadv(%d,%x,%d)\n", ciptr->fd, ciptr, n );
+
+    for (i = 0; i < n; i++, iov++) {
+       if (iov->iov_len) {
+           thiscount = TRANS(AMRead)(ciptr, iov->iov_base, iov->iov_len);
+           if (thiscount < 0) return thiscount;
+           count += thiscount;
+           if (thiscount < iov->iov_len) break;
+       }
+    }
+
+    return count;
+}
+
+
+static
+TRANS(AMWritev)(ciptr, iov, n)
+XtransConnInfo ciptr;
+struct iovec   *iov;
+int            n;
+{
+    int i;
+    int count = 0, thiscount;
+
+    PRMSG(2, "AMWritev(%d,%x,%d)\n", ciptr->fd, iov, n );
+
+    for (i = 0; i < n; i++, iov++) {
+       if (iov->iov_len) {
+           thiscount = TRANS(AMWrite)(ciptr, iov->iov_base, iov->iov_len);
+           if (thiscount < 0)
+               return thiscount;
+           count += thiscount;
+           if (thiscount < iov->iov_len) break;
+       }
+    }
+
+    return count;
+}
+
+
+static
+TRANS(AMDisconnect)(ciptr)
+XtransConnInfo ciptr;
+{
+    register XAmChanDesc *chandesc;
+
+    PRMSG(2, "AMDisconnect(%x->%d)\n", ciptr, ciptr->fd, 0 );
+
+    chandesc = XAmFdToChanDesc(ciptr->fd);
+    if (chandesc != NULL) {
+       switch (chandesc->type) {
+       case ACDT_TCPIP:
+           if (chandesc->signal != -1) {
+               sig_raise(chandesc->signal);
+               chandesc->signal = -1;
+           }
+           std_destroy(&chandesc->chancap);
+           break;
+
+       case ACDT_VIRTCIRC:
+           vc_close(chandesc->virtcirc, VC_BOTH | VC_ASYNC);
+           break;
+       }
+#ifdef XSERV_t
+       if (ciptr->fd == maxClient - 1) {
+           maxClient--;
+           /* we could look if maxClient can be reduced even more */
+       }
+#endif
+       XAmFreeChanDesc(chandesc);
+    }
+
+    return 0;
+}
+
+
+static
+TRANS(AMClose)(ciptr)
+XtransConnInfo ciptr;
+{
+    PRMSG(2, "AMClose(%x->%d)\n", ciptr, ciptr->fd, 0 );
+
+    return TRANS(AMDisconnect)(ciptr);
+}
+
+
+Xtransport     TRANS(AmConnFuncs) = {
+       /* Combined AMOEBA RPC/TCP Interface; maybe we should split this  */
+       "amcon",
+       0,
+#ifdef TRANS_CLIENT
+       TRANS(AMOpenCOTSClient),
+#endif /* TRANS_CLIENT */
+#ifdef TRANS_SERVER
+       TRANS(AMOpenCOTSServer),
+#endif /* TRANS_SERVER */
+#ifdef TRANS_CLIENT
+       TRANS(AMOpenCLTSClient),
+#endif /* TRANS_CLIENT */
+#ifdef TRANS_SERVER
+       TRANS(AMOpenCLTSServer),
+#endif /* TRANS_SERVER */
+       TRANS(AMSetOption),
+#ifdef TRANS_SERVER
+       TRANS(AMCreateListener),
+       TRANS(AMResetListener),
+       TRANS(AMAccept),
+#endif /* TRANS_SERVER */
+#ifdef TRANS_CLIENT
+       TRANS(AMConnect),
+#endif /* TRANS_CLIENT */
+       TRANS(AMBytesReadable),
+       TRANS(AMRead),
+       TRANS(AMWrite),
+       TRANS(AMReadv),
+       TRANS(AMWritev),
+       TRANS(AMDisconnect),
+       TRANS(AMClose),
+};
diff --git a/Xserver/lib/xtrans/Xtransdnet.c b/Xserver/lib/xtrans/Xtransdnet.c
new file mode 100644 (file)
index 0000000..c05e8a1
--- /dev/null
@@ -0,0 +1,707 @@
+/* $XConsortium: Xtransdnet.c,v 1.16 95/02/10 17:54:09 mor Exp $ */
+/* $XFree86: xc/lib/xtrans/Xtransdnet.c,v 3.2 1996/05/10 06:55:47 dawes Exp $ */
+/*
+
+Copyright (c) 1993, 1994  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be included
+in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR
+OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall
+not be used in advertising or otherwise to promote the sale, use or
+other dealings in this Software without prior written authorization
+from the X Consortium.
+
+*/
+
+/* Copyright (c) 1993, 1994 NCR Corporation - Dayton, Ohio, USA
+ *
+ * All Rights Reserved
+ *
+ * Permission to use, copy, modify, and distribute this software and its
+ * documentation for any purpose and without fee is hereby granted, provided
+ * that the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the name NCR not be used in advertising
+ * or publicity pertaining to distribution of the software without specific,
+ * written prior permission.  NCR and makes no representations about the
+ * suitability of this software for any purpose.  It is provided "as is"
+ * without express or implied warranty.
+ *
+ * NCR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN
+ * NO EVENT SHALL NCR BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
+ * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
+ * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
+ * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#ifndef WIN32
+#include <netdnet/dn.h>
+#include <netdnet/dnetdb.h>
+#include <sys/ioctl.h>
+#endif /* !WIN32 */
+
+#include <stdio.h>
+
+#ifdef WIN32
+#define _WILLWINSOCK_
+#define BOOL wBOOL
+#undef Status
+#define Status wStatus
+#include <prgpre.h> /* PATHWORKS header normally in %MSTOOLS%\h\pathwork */
+#undef Status
+#define Status int
+#undef BOOL
+#include <X11/Xw32defs.h>
+#undef close
+#define close closesocket
+#endif /* WIN32 */
+
+
+#if defined(X11_t)
+#define DNETOBJ "X$X"
+#endif
+#if defined(XIM_t)
+#define DNETOBJ "IMSERVER$"
+#endif
+#if defined(FS_t) || defined(FONT_t)
+#define DNETOBJ "X$FONT"
+#endif
+#if defined(ICE_t)
+#define DNETOBJ ""
+#endif
+#if defined(TEST_t)
+#define DNETOBJ "X$TEST"
+#endif
+
+
+/*
+ * This is the DNET implementation of the X Transport service layer
+ */
+
+/*
+ * This function gets the local address of the socket and stores it in the
+ * XtransConnInfo structure for the connection.
+ */
+
+static int
+TRANS(DNETGetAddr) (ciptr)
+
+XtransConnInfo ciptr;
+
+{
+    struct sockaddr_dn sockname;
+    int                        namelen = sizeof(sockname);
+
+    PRMSG (3,"DNETGetAddr(%x)\n", ciptr, 0, 0);
+
+    if (getsockname (ciptr->fd, (struct sockaddr *) &sockname, &namelen) < 0)
+    {
+       PRMSG (1,"DNETGetAddr: getsockname() failed: %d\n",
+             EGET(), 0, 0);
+       return -1;
+    }
+
+
+    /*
+     * Everything looks good: fill in the XtransConnInfo structure.
+     */
+
+    if ((ciptr->addr = (char *) xalloc (namelen)) == NULL)
+    {
+        PRMSG (1, "DNETGetAddr: Can't allocate space for the addr\n",
+              0, 0, 0);
+        return -1;
+    }
+
+    ciptr->family = sockname.sdn_family;
+    ciptr->addrlen = namelen;
+    memcpy (ciptr->addr, &sockname, ciptr->addrlen);
+
+    return 0;
+}
+
+
+/*
+ * This function gets the remote address of the socket and stores it in the
+ * XtransConnInfo structure for the connection.
+ */
+
+static int
+TRANS(DNETGetPeerAddr) (ciptr)
+
+XtransConnInfo ciptr;
+
+{
+    struct sockaddr_dn sockname;
+    int                        namelen = sizeof(sockname);
+
+    PRMSG (3,"DNETGetPeerAddr(%x)\n", ciptr, 0, 0);
+
+    if (getpeername (ciptr->fd, (struct sockaddr *) &sockname, &namelen) < 0)
+    {
+       PRMSG (1,"DNETGetPeerAddr: getpeername() failed: %d\n",
+             EGET(), 0, 0);
+       return -1;
+    }
+
+    /*
+     * Everything looks good: fill in the XtransConnInfo structure.
+     */
+
+    if ((ciptr->peeraddr = (char *) xalloc (namelen)) == NULL)
+    {
+        PRMSG (1,
+             "DNETGetPeerAddr: Can't allocate space for the addr\n",
+             0, 0, 0);
+        return -1;
+    }
+
+    ciptr->peeraddrlen = namelen;
+    memcpy (ciptr->peeraddr, &sockname, ciptr->peeraddrlen);
+
+    return 0;
+}
+
+
+#ifdef TRANS_CLIENT
+
+static XtransConnInfo
+TRANS(DNETOpenCOTSClient) (thistrans, protocol, host, port)
+
+Xtransport     *thistrans;
+char           *protocol;
+char           *host;
+char           *port;
+
+{
+    XtransConnInfo     ciptr;
+
+    PRMSG (2,"DNETOpenCOTSClient(%s,%s,%s)\n", protocol, host, port);
+
+    if ((ciptr = (XtransConnInfo) xcalloc (
+       1, sizeof(struct _XtransConnInfo))) == NULL)
+    {
+       PRMSG (1, "DNETOpenCOTSClient: malloc failed\n", 0, 0, 0);
+       return NULL;
+    }
+
+    ciptr->index = 0;          /* only one form of DECnet */
+
+    /* nothing else to do here */
+
+    return ciptr;
+}
+
+#endif /* TRANS_CLIENT */
+
+
+#ifdef TRANS_SERVER
+
+static XtransConnInfo
+TRANS(DNETOpenCOTSServer) (thistrans, protocol, host, port)
+
+Xtransport     *thistrans;
+char           *protocol;
+char           *host;
+char           *port;
+
+{
+    XtransConnInfo     ciptr;
+
+    PRMSG (2,"DNETOpenCOTSServer(%s,%s,%s)\n", protocol, host, port);
+
+    if ((ciptr = (XtransConnInfo) xcalloc (
+       1, sizeof(struct _XtransConnInfo))) == NULL)
+    {
+       PRMSG (1, "DNETOpenCOTSServer: malloc failed\n", 0, 0, 0);
+       return NULL;
+    }
+
+    if ((ciptr->fd = socket (AF_DECnet, SOCK_STREAM, 0)) < 0)
+    {
+       xfree ((char *) ciptr);
+       return NULL;
+    }
+
+    ciptr->index = 0;          /* only one form of DECnet */
+
+    return (ciptr);
+}
+
+#endif /* TRANS_SERVER */
+
+
+#ifdef TRANS_CLIENT
+
+static XtransConnInfo
+TRANS(DNETOpenCLTSClient) (thistrans, protocol, host, port)
+
+Xtransport     *thistrans;
+char           *protocol;
+char           *host;
+char           *port;
+
+{
+    XtransConnInfo     ciptr;
+
+    PRMSG (2,"DNETOpenCLTSClient(%s,%s,%s)\n", protocol, host, port);
+
+    if ((ciptr = (XtransConnInfo) xcalloc (
+       1, sizeof (struct _XtransConnInfo))) == NULL)
+    {
+       PRMSG (1, "DNETOpenCLTSClient: malloc failed\n", 0, 0, 0);
+       return NULL;
+    }
+
+    ciptr->index = 0;          /* only one form of DECnet */
+
+    /* nothing else to do here */
+
+    return ciptr;
+}
+
+#endif /* TRANS_CLIENT */
+
+
+#ifdef TRANS_SERVER
+
+static XtransConnInfo
+TRANS(DNETOpenCLTSServer) (thistrans, protocol, host, port)
+
+Xtransport     *thistrans;
+char           *protocol;
+char           *host;
+char           *port;
+
+{
+    /* NEED TO IMPLEMENT */
+
+    PRMSG (2,"DNETOpenCLTSServer(%s,%s,%s)\n", protocol, host, port);
+    return NULL;
+}
+
+#endif /* TRANS_SERVER */
+
+
+#ifdef TRANS_REOPEN
+
+static XtransConnInfo
+TRANS(DNETReopenCOTSServer) (thistrans, fd, port)
+
+Xtransport     *thistrans;
+int            fd;
+char           *port;
+
+{
+    XtransConnInfo     ciptr;
+
+    PRMSG (2,"DNETReopenCOTSServer(%d,%s)\n", fd, port, 0);
+
+    if ((ciptr = (XtransConnInfo) xcalloc (
+       1, sizeof(struct _XtransConnInfo))) == NULL)
+    {
+       PRMSG (1, "DNETReopenCOTSServer: malloc failed\n", 0, 0, 0);
+       return NULL;
+    }
+
+    ciptr->fd = fd;
+    ciptr->index = 0;          /* only one form of DECnet */
+
+    return (ciptr);
+}
+
+static XtransConnInfo
+TRANS(DNETReopenCLTSServer) (thistrans, fd, port)
+
+Xtransport     *thistrans;
+int            fd;
+char           *port;
+
+{
+    XtransConnInfo     ciptr;
+
+    PRMSG (2,"DNETReopenCLTSServer(%d,%s)\n", fd, port, 0);
+
+    if ((ciptr = (XtransConnInfo) xcalloc (
+       1, sizeof(struct _XtransConnInfo))) == NULL)
+    {
+       PRMSG (1, "DNETReopenCLTSServer: malloc failed\n", 0, 0, 0);
+       return NULL;
+    }
+
+    ciptr->fd = fd;
+    ciptr->index = 0;          /* only one form of DECnet */
+
+    return (ciptr);
+}
+
+#endif /* TRANS_REOPEN */
+
+
+static int
+TRANS(DNETSetOption) (ciptr, option, arg)
+
+XtransConnInfo ciptr;
+int            option;
+int            arg;
+
+{
+    PRMSG (2,"DNETSetOption(%d,%d,%d)\n", ciptr->fd, option, arg);
+
+    return -1;
+}
+
+
+#ifdef TRANS_SERVER
+
+static int
+TRANS(DNETCreateListener) (ciptr, port)
+
+XtransConnInfo ciptr;
+char           *port;
+
+{
+    struct sockaddr_dn  dnsock;
+    int                        fd = ciptr->fd;
+
+    PRMSG (3, "DNETCreateListener(%x,%d)\n", ciptr, fd, 0);
+
+    bzero ((char *) &dnsock, sizeof (dnsock));
+    dnsock.sdn_family = AF_DECnet;
+
+    if (port && *port )
+       sprintf (dnsock.sdn_objname, "%s%s", DNETOBJ, port);
+    else
+#ifdef X11_t
+       return -1;
+#else
+       sprintf (dnsock.sdn_objname, "%s%d", DNETOBJ, getpid ());
+#endif
+
+    dnsock.sdn_objnamel = strlen (dnsock.sdn_objname);
+
+    if (bind (fd, (struct sockaddr *) &dnsock, sizeof (dnsock)))
+    {
+       close (fd);
+       return -1;
+    }
+
+    if (listen (fd, 5))
+    {
+       close (fd);
+       return (-1);
+    }
+
+
+    /* Set a flag to indicate that this connection is a listener */
+
+    ciptr->flags = 1;
+
+    return 0;
+}
+
+
+static XtransConnInfo
+TRANS(DNETAccept) (ciptr, status)
+
+XtransConnInfo ciptr;
+int            *status;
+
+{
+    XtransConnInfo     newciptr;
+    struct sockaddr_dn sockname;
+    int                        namelen = sizeof(sockname);
+
+    PRMSG (2, "DNETAccept(%x,%d)\n", ciptr, ciptr->fd, 0);
+
+    if ((newciptr = (XtransConnInfo) xcalloc(
+       1, sizeof (struct _XtransConnInfo))) == NULL)
+    {
+       PRMSG (1, "DNETAccept: malloc failed\n", 0, 0, 0);
+       *status = TRANS_ACCEPT_BAD_MALLOC;
+       return NULL;
+    }
+
+    if((newciptr->fd = accept (ciptr->fd,
+       (struct sockaddr *) &sockname, &namelen)) < 0)
+    {
+       PRMSG (1, "DNETAccept: accept() failed\n", 0, 0, 0);
+
+       xfree (newciptr);
+       *status = TRANS_ACCEPT_FAILED;
+       return NULL;
+    }
+
+    /*
+     * Get this address again because the transport may give a more 
+     * specific address now that a connection is established.
+     */
+
+    if (TRANS(DNETGetAddr) (newciptr) < 0)
+    {
+       PRMSG(1,
+       "DNETAccept: ...DNETGetAddr() failed:\n", 0, 0, 0);
+       close (newciptr->fd);
+       xfree (newciptr);
+       *status = TRANS_ACCEPT_MISC_ERROR;
+        return NULL;
+    }
+
+    if (TRANS(DNETGetPeerAddr) (newciptr) < 0)
+    {
+       PRMSG(1,
+       "DNETAccept: ...DNETGetPeerAddr() failed:\n", 0, 0, 0);
+
+       close (newciptr->fd);
+       if (newciptr->addr) xfree (newciptr->addr);
+       xfree (newciptr);
+       *status = TRANS_ACCEPT_MISC_ERROR;
+        return NULL;
+    }
+
+    *status = 0;
+
+    return newciptr;
+}
+
+#endif /* TRANS_SERVER */
+
+
+#ifdef TRANS_CLIENT
+
+#define OBJBUFSIZE 64
+
+static int
+TRANS(DNETConnect) (ciptr, host, port)
+
+XtransConnInfo ciptr;
+char           *host;
+char           *port;
+
+{
+    char objname[OBJBUFSIZE];
+
+    extern int dnet_conn();
+    
+    PRMSG (2,"DNETConnect(%d,%s,%s)\n", ciptr->fd, host, port);
+
+#ifdef X11_t
+    /*
+     * X has a well known port, that is transport dependent. It is easier
+     * to handle it here, than try and come up with a transport independent
+     * representation that can be passed in and resolved the usual way.
+     *
+     * The port that is passed here is really a string containing the idisplay
+     * from ConnectDisplay().
+     */
+
+    if (is_numeric (port))
+    {
+       short tmpport = (short) atoi (port);
+
+       sprintf (objname, "X$X%d", tmpport);
+    }
+    else
+#endif
+       strncpy(objname, port, OBJBUFSIZE);
+
+
+    /*
+     * Do the connect
+     */
+
+    if (!host) host = "0";
+
+    if ((ciptr->fd = dnet_conn (host, objname, SOCK_STREAM, 0, 0, 0, 0)) < 0)
+    {
+       return TRANS_CONNECT_FAILED;
+    }
+
+
+    /*
+     * Sync up the address fields of ciptr.
+     */
+
+    if (TRANS(DNETGetAddr) (ciptr) < 0)
+    {
+       PRMSG (1,
+             "DNETConnect: ...DNETGetAddr() failed:\n", 0, 0, 0);
+       return TRANS_CONNECT_FAILED;
+    }
+
+    if (TRANS(DNETGetPeerAddr) (ciptr) < 0)
+    {
+       PRMSG (1,
+             "DNETConnect: ...DNETGetPeerAddr() failed:\n",
+             0, 0, 0);
+       return TRANS_CONNECT_FAILED;
+    }
+
+    return 0;
+}
+
+#endif /* TRANS_CLIENT */
+
+
+static int
+TRANS(DNETBytesReadable) (ciptr, pend)
+
+XtransConnInfo ciptr;
+BytesReadable_t        *pend;
+
+{
+    PRMSG (2,"DNETBytesReadable(%x,%d,%x)\n", ciptr, ciptr->fd, pend);
+
+#ifdef WIN32
+    return ioctlsocket ((SOCKET) ciptr->fd, FIONREAD, (u_long *) pend);
+#else
+    return ioctl(ciptr->fd, FIONREAD, (char *)pend);
+#endif /* WIN32 */
+}
+
+
+static int
+TRANS(DNETRead) (ciptr, buf, size)
+
+XtransConnInfo ciptr;
+char           *buf;
+int            size;
+
+{
+    PRMSG (2,"DNETRead(%d,%x,%d)\n", ciptr->fd, buf, size);
+
+#ifdef WIN32
+    return recv ((SOCKET)ciptr->fd, buf, size, 0);
+#else
+    return read (ciptr->fd, buf, size);
+#endif /* WIN32 */
+}
+
+
+static int
+TRANS(DNETWrite) (ciptr, buf, size)
+
+XtransConnInfo ciptr;
+char           *buf;
+int            size;
+
+{
+    PRMSG (2,"DNETWrite(%d,%x,%d)\n", ciptr->fd, buf, size);
+
+#ifdef WIN32
+    return send ((SOCKET)ciptr->fd, buf, size, 0);
+#else
+    return write (ciptr->fd, buf, size);
+#endif /* WIN32 */
+}
+
+
+static int
+TRANS(DNETReadv) (ciptr, buf, size)
+
+XtransConnInfo ciptr;
+struct iovec   *buf;
+int            size;
+
+{
+    PRMSG (2,"DNETReadv(%d,%x,%d)\n", ciptr->fd, buf, size);
+
+    return READV (ciptr, buf, size);
+}
+
+
+static int
+TRANS(DNETWritev) (ciptr, buf, size)
+
+XtransConnInfo ciptr;
+struct iovec   *buf;
+int            size;
+
+{
+    PRMSG (2,"DNETWritev(%d,%x,%d)\n", ciptr->fd, buf, size);
+
+    return WRITEV (ciptr, buf, size);
+}
+
+
+static int
+TRANS(DNETDisconnect) (ciptr)
+
+XtransConnInfo ciptr;
+
+{
+    PRMSG (2,"DNETDisconnect(%x,%d)\n", ciptr, ciptr->fd, 0);
+
+    return shutdown (ciptr->fd, 2); /* disallow further sends and receives */
+}
+
+
+static int
+TRANS(DNETClose) (ciptr)
+
+XtransConnInfo ciptr;
+
+{
+    PRMSG (2,"DNETClose(%x,%d)\n", ciptr, ciptr->fd, 0);
+
+    return close (ciptr->fd);
+}
+
+
+Xtransport     TRANS(DNETFuncs) = {
+    /* DNET Interface */
+    "dnet",
+    0,
+#ifdef TRANS_CLIENT
+    TRANS(DNETOpenCOTSClient),
+#endif /* TRANS_CLIENT */
+#ifdef TRANS_SERVER
+    TRANS(DNETOpenCOTSServer),
+#endif /* TRANS_SERVER */
+#ifdef TRANS_CLIENT
+    TRANS(DNETOpenCLTSClient),
+#endif /* TRANS_CLIENT */
+#ifdef TRANS_SERVER
+    TRANS(DNETOpenCLTSServer),
+#endif /* TRANS_SERVER */
+#ifdef TRANS_REOPEN
+    TRANS(DNETReopenCOTSServer),
+    TRANS(DNETReopenCLTSServer),
+#endif /* TRANS_REOPEN */
+    TRANS(DNETSetOption),
+#ifdef TRANS_SERVER
+    TRANS(DNETCreateListener),
+    NULL,                                      /* ResetListener */
+    TRANS(DNETAccept),
+#endif /* TRANS_SERVER */
+#ifdef TRANS_CLIENT
+    TRANS(DNETConnect),
+#endif /* TRANS_CLIENT */
+    TRANS(DNETBytesReadable),
+    TRANS(DNETRead),
+    TRANS(DNETWrite),
+    TRANS(DNETReadv),
+    TRANS(DNETWritev),
+    TRANS(DNETDisconnect),
+    TRANS(DNETClose),
+    TRANS(DNETClose),
+};
diff --git a/Xserver/lib/xtrans/Xtransint.h b/Xserver/lib/xtrans/Xtransint.h
new file mode 100644 (file)
index 0000000..f25e3f4
--- /dev/null
@@ -0,0 +1,511 @@
+/* $XConsortium: Xtransint.h /main/25 1995/12/05 16:51:28 mor $ */
+/* $XFree86: xc/lib/xtrans/Xtransint.h,v 3.18.2.2 1997/07/19 04:59:16 dawes Exp $ */
+/*
+
+Copyright (c) 1993, 1994  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be included
+in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR
+OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall
+not be used in advertising or otherwise to promote the sale, use or
+other dealings in this Software without prior written authorization
+from the X Consortium.
+
+*/
+
+/* Copyright (c) 1993, 1994 NCR Corporation - Dayton, Ohio, USA
+ *
+ * All Rights Reserved
+ *
+ * Permission to use, copy, modify, and distribute this software and its
+ * documentation for any purpose and without fee is hereby granted, provided
+ * that the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the name NCR not be used in advertising
+ * or publicity pertaining to distribution of the software without specific,
+ * written prior permission.  NCR makes no representations about the
+ * suitability of this software for any purpose.  It is provided "as is"
+ * without express or implied warranty.
+ *
+ * NCR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN
+ * NO EVENT SHALL NCR BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
+ * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
+ * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
+ * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#ifndef _XTRANSINT_H_
+#define _XTRANSINT_H_
+
+/*
+ * XTRANSDEBUG will enable the PRMSG() macros used in the X Transport 
+ * Interface code. Each use of the PRMSG macro has a level associated with 
+ * it. XTRANSDEBUG is defined to be a level. If the invocation level is =< 
+ * the value of XTRANSDEBUG, then the message will be printed out to stderr. 
+ * Recommended levels are:
+ *
+ *     XTRANSDEBUG=1   Error messages
+ *     XTRANSDEBUG=2 API Function Tracing
+ *     XTRANSDEBUG=3 All Function Tracing
+ *     XTRANSDEBUG=4 printing of intermediate values
+ *     XTRANSDEBUG=5 really detailed stuff
+#define XTRANSDEBUG 2
+ *
+ * Defining XTRANSDEBUGTIMESTAMP will cause printing timestamps with each
+ * message.
+ */
+
+#ifndef __EMX__
+#  define XTRANSDEBUG 1
+#else
+#define XTRANSDEBUG 1
+#endif
+
+#ifdef WIN32
+#define _WILLWINSOCK_
+#endif
+
+#include "Xtrans.h"
+
+#ifdef XTRANSDEBUG
+#include <stdio.h>
+#endif /* XTRANSDEBUG */
+
+#include <errno.h>
+#ifdef X_NOT_STDC_ENV
+extern int  errno;             /* Internal system error number. */
+#endif
+
+#ifndef WIN32
+#ifndef MINIX
+#ifndef Lynx
+#include <sys/socket.h>
+#else
+#include <socket.h>
+#endif
+#endif
+#ifdef __EMX__
+#include <sys/ioctl.h>
+#endif
+
+/*
+ * Moved the setting of NEED_UTSNAME to this header file from Xtrans.c,
+ * to avoid a race condition. JKJ (6/5/97)
+ */
+#if (defined(_POSIX_SOURCE) && !defined(AIXV3)) || defined(hpux) || defined(USG) || defined(SVR4) || defined(SCO)
+#ifndef NEED_UTSNAME
+#define NEED_UTSNAME
+#endif
+#include <sys/utsname.h>
+#endif
+
+/*
+ * makedepend screws up on #undef OPEN_MAX, so we define a new symbol
+ */
+
+#ifndef TRANS_OPEN_MAX
+
+#ifndef X_NOT_POSIX
+#ifdef _POSIX_SOURCE
+#include <limits.h>
+#else
+#define _POSIX_SOURCE
+#include <limits.h>
+#undef _POSIX_SOURCE
+#endif
+#endif
+#ifndef OPEN_MAX
+#ifdef SVR4
+#define OPEN_MAX 256
+#else
+#include <sys/param.h>
+#ifndef OPEN_MAX
+#ifdef __OSF1__
+#define OPEN_MAX 256
+#else
+#ifdef NOFILE
+#define OPEN_MAX NOFILE
+#else
+#ifndef __EMX__
+#define OPEN_MAX NOFILES_MAX
+#else
+#define OPEN_MAX 256
+#endif
+#endif
+#endif
+#endif
+#endif
+#endif
+
+#if OPEN_MAX > 256
+#define TRANS_OPEN_MAX 256
+#else
+#define TRANS_OPEN_MAX OPEN_MAX
+#endif
+
+#endif /* TRANS_OPEN_MAX */
+
+#ifdef __EMX__
+#define ESET(val)
+#else
+#define ESET(val) errno = val
+#endif
+#define EGET() errno
+
+#else /* WIN32 */
+
+#define ESET(val) WSASetLastError(val)
+#define EGET() WSAGetLastError()
+
+#endif /* WIN32 */
+
+#ifndef NULL
+#define NULL 0
+#endif
+
+#ifdef X11_t
+#define X_TCP_PORT     6000
+#endif
+
+struct _XtransConnInfo {
+    struct _Xtransport     *transptr;
+    int                index;
+    char       *priv;
+    int                flags;
+    int                fd;
+    char       *port;
+    int                family;
+    char       *addr;
+    int                addrlen;
+    char       *peeraddr;
+    int                peeraddrlen;
+};
+
+#define XTRANS_OPEN_COTS_CLIENT       1
+#define XTRANS_OPEN_COTS_SERVER       2
+#define XTRANS_OPEN_CLTS_CLIENT       3
+#define XTRANS_OPEN_CLTS_SERVER       4
+
+
+typedef struct _Xtransport {
+    char       *TransName;
+    int                flags;
+
+#ifdef TRANS_CLIENT
+
+    XtransConnInfo (*OpenCOTSClient)(
+#if NeedNestedPrototypes
+       struct _Xtransport *,   /* transport */
+       char *,                 /* protocol */
+       char *,                 /* host */
+       char *                  /* port */
+#endif
+    );
+
+#endif /* TRANS_CLIENT */
+
+#ifdef TRANS_SERVER
+
+    XtransConnInfo (*OpenCOTSServer)(
+#if NeedNestedPrototypes
+       struct _Xtransport *,   /* transport */
+       char *,                 /* protocol */
+       char *,                 /* host */
+       char *                  /* port */
+#endif
+    );
+
+#endif /* TRANS_SERVER */
+
+#ifdef TRANS_CLIENT
+
+    XtransConnInfo (*OpenCLTSClient)(
+#if NeedNestedPrototypes
+       struct _Xtransport *,   /* transport */
+       char *,                 /* protocol */
+       char *,                 /* host */
+       char *                  /* port */
+#endif
+    );
+
+#endif /* TRANS_CLIENT */
+
+#ifdef TRANS_SERVER
+
+    XtransConnInfo (*OpenCLTSServer)(
+#if NeedNestedPrototypes
+       struct _Xtransport *,   /* transport */
+       char *,                 /* protocol */
+       char *,                 /* host */
+       char *                  /* port */
+#endif
+    );
+
+#endif /* TRANS_SERVER */
+
+
+#ifdef TRANS_REOPEN
+
+    XtransConnInfo (*ReopenCOTSServer)(
+#if NeedNestedPrototypes
+       struct _Xtransport *,   /* transport */
+        int,                   /* fd */
+        char *                 /* port */
+#endif
+    );
+
+    XtransConnInfo (*ReopenCLTSServer)(
+#if NeedNestedPrototypes
+       struct _Xtransport *,   /* transport */
+        int,                   /* fd */
+        char *                 /* port */
+#endif
+    );
+
+#endif /* TRANS_REOPEN */
+
+
+    int        (*SetOption)(
+#if NeedNestedPrototypes
+       XtransConnInfo,         /* connection */
+       int,                    /* option */
+       int                     /* arg */
+#endif
+    );
+
+#ifdef TRANS_SERVER
+
+    int        (*CreateListener)(
+#if NeedNestedPrototypes
+       XtransConnInfo,         /* connection */
+       char *                  /* port */
+#endif
+    );
+
+    int        (*ResetListener)(
+#if NeedNestedPrototypes
+       XtransConnInfo          /* connection */
+#endif
+    );
+
+    XtransConnInfo (*Accept)(
+#if NeedNestedPrototypes
+       XtransConnInfo,         /* connection */
+        int *                  /* status */
+#endif
+    );
+
+#endif /* TRANS_SERVER */
+
+#ifdef TRANS_CLIENT
+
+    int        (*Connect)(
+#if NeedNestedPrototypes
+       XtransConnInfo,         /* connection */
+       char *,                 /* host */
+       char *                  /* port */
+#endif
+    );
+
+#endif /* TRANS_CLIENT */
+
+    int        (*BytesReadable)(
+#if NeedNestedPrototypes
+       XtransConnInfo,         /* connection */
+       BytesReadable_t *       /* pend */
+#endif
+    );
+
+    int        (*Read)(
+#if NeedNestedPrototypes
+       XtransConnInfo,         /* connection */
+       char *,                 /* buf */
+       int                     /* size */
+#endif
+    );
+
+    int        (*Write)(
+#if NeedNestedPrototypes
+       XtransConnInfo,         /* connection */
+       char *,                 /* buf */
+       int                     /* size */
+#endif
+    );
+
+    int        (*Readv)(
+#if NeedNestedPrototypes
+       XtransConnInfo,         /* connection */
+       struct iovec *,         /* buf */
+       int                     /* size */
+#endif
+    );
+
+    int        (*Writev)(
+#if NeedNestedPrototypes
+       XtransConnInfo,         /* connection */
+       struct iovec *,         /* buf */
+       int                     /* size */
+#endif
+    );
+
+    int        (*Disconnect)(
+#if NeedNestedPrototypes
+       XtransConnInfo          /* connection */
+#endif
+    );
+
+    int        (*Close)(
+#if NeedNestedPrototypes
+       XtransConnInfo          /* connection */
+#endif
+    );
+
+    int        (*CloseForCloning)(
+#if NeedNestedPrototypes
+       XtransConnInfo          /* connection */
+#endif
+    );
+
+} Xtransport;
+
+
+typedef struct _Xtransport_table {
+    Xtransport *transport;
+    int                transport_id;
+} Xtransport_table;
+
+
+/*
+ * Flags for the flags member of Xtransport.
+ */
+
+#define TRANS_ALIAS    (1<<0)  /* record is an alias, don't create server */
+#define TRANS_LOCAL    (1<<1)  /* local transport */
+#define TRANS_DISABLED (1<<2)  /* Don't open this one */
+#define TRANS_NOLISTEN  (1<<3)  /* Don't listen on this one */
+
+
+/*
+ * readv() and writev() don't exist or don't work correctly on some
+ * systems, so they may be emulated.
+ */
+
+#if defined(CRAY) || (defined(SYSV) && defined(i386) && !defined(SCO325)) || defined(WIN32) || defined(__sxg__) || defined(__EMX__)
+
+#define READV(ciptr, iov, iovcnt)      TRANS(ReadV)(ciptr, iov, iovcnt)
+
+static int TRANS(ReadV)(
+#if NeedFunctionPrototypes
+    XtransConnInfo,    /* ciptr */
+    struct iovec *,    /* iov */
+    int                        /* iovcnt */
+#endif
+);
+
+#else
+
+#define READV(ciptr, iov, iovcnt)      readv(ciptr->fd, iov, iovcnt)
+
+#endif /* CRAY || (SYSV && i386) || WIN32 || __sxg__ || */
+
+
+#if defined(CRAY) || (defined(SYSV) && defined(i386) && !defined(SCO325)) || defined(WIN32) || defined(__sxg__) || defined(__EMX__)
+
+#define WRITEV(ciptr, iov, iovcnt)     TRANS(WriteV)(ciptr, iov, iovcnt)
+
+static int TRANS(WriteV)(
+#if NeedFunctionPrototypes
+    XtransConnInfo,    /* ciptr */
+    struct iovec *,    /* iov */
+    int                /* iovcnt */
+#endif
+);
+
+#else
+
+#define WRITEV(ciptr, iov, iovcnt)     writev(ciptr->fd, iov, iovcnt)
+
+#endif /* CRAY || WIN32 || __sxg__ */
+
+
+static int is_numeric (
+#if NeedFunctionPrototypes
+    char *             /* str */
+#endif
+);
+
+
+/*
+ * Some XTRANSDEBUG stuff
+ */
+
+#if defined(XTRANSDEBUG)
+/* add hack to the format string to avoid warnings about extra arguments
+ * to fprintf.
+ */
+#ifdef XTRANSDEBUGTIMESTAMP
+#if defined(XSERV_t) && defined(TRANS_SERVER)
+/* Use ErrorF() for the X server */
+#define PRMSG(lvl,x,a,b,c)     if (lvl <= XTRANSDEBUG){ \
+                       int hack= 0, saveerrno=errno; \
+                        struct timeval tp;\
+                        gettimeofday(&tp,0); \
+                       ErrorF(__xtransname); \
+                       ErrorF(x+hack,a,b,c); \
+                        ErrorF("timestamp (ms): %d\n",tp.tv_sec*1000+tp.tv_usec/1000); \
+                       errno=saveerrno; \
+                       } else ((void)0)
+#else
+#define PRMSG(lvl,x,a,b,c)     if (lvl <= XTRANSDEBUG){ \
+                       int hack= 0, saveerrno=errno; \
+                        struct timeval tp;\
+                        gettimeofday(&tp,0); \
+                       fprintf(stderr, __xtransname); fflush(stderr); \
+                       fprintf(stderr, x+hack,a,b,c); fflush(stderr); \
+                        fprintf(stderr, "timestamp (ms): %d\n",tp.tv_sec*1000+tp.tv_usec/1000); \
+                        fflush(stderr); \
+                       errno=saveerrno; \
+                       } else ((void)0)
+#endif /* XSERV_t && TRANS_SERVER */
+#else /* XTRANSDEBUGTIMESTAMP */
+#if defined(XSERV_t) && defined(TRANS_SERVER)
+/* Use ErrorF() for the X server */
+#define PRMSG(lvl,x,a,b,c)     if (lvl <= XTRANSDEBUG){ \
+                       int hack= 0, saveerrno=errno; \
+                       ErrorF(__xtransname); \
+                       ErrorF(x+hack,a,b,c); \
+                       errno=saveerrno; \
+                       } else ((void)0)
+#else
+#define PRMSG(lvl,x,a,b,c)     if (lvl <= XTRANSDEBUG){ \
+                       int hack= 0, saveerrno=errno; \
+                       fprintf(stderr, __xtransname); fflush(stderr); \
+                       fprintf(stderr, x+hack,a,b,c); fflush(stderr); \
+                       errno=saveerrno; \
+                       } else ((void)0)
+#endif /* XSERV_t && TRANS_SERVER */
+#endif /* XTRANSDEBUGTIMESTAMP */
+#else
+#define PRMSG(lvl,x,a,b,c)     ((void)0)
+#endif /* XTRANSDEBUG */
+
+#endif /* _XTRANSINT_H_ */
diff --git a/Xserver/lib/xtrans/Xtranslcl.c b/Xserver/lib/xtrans/Xtranslcl.c
new file mode 100644 (file)
index 0000000..7a0c5b5
--- /dev/null
@@ -0,0 +1,2666 @@
+/* $XConsortium: Xtranslcl.c /main/27 1996/09/28 16:50:14 rws $ */
+/* $XFree86: xc/lib/xtrans/Xtranslcl.c,v 3.21.2.3 1998/02/01 16:04:34 robin Exp $ */
+/*
+
+Copyright (c) 1993, 1994  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be included
+in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR
+OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall
+not be used in advertising or otherwise to promote the sale, use or
+other dealings in this Software without prior written authorization
+from the X Consortium.
+
+*/
+
+/* Copyright (c) 1993, 1994 NCR Corporation - Dayton, Ohio, USA
+ *
+ * All Rights Reserved
+ *
+ * Permission to use, copy, modify, and distribute this software and its
+ * documentation for any purpose and without fee is hereby granted, provided
+ * that the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the name NCR not be used in advertising
+ * or publicity pertaining to distribution of the software without specific,
+ * written prior permission.  NCR makes no representations about the
+ * suitability of this software for any purpose.  It is provided "as is"
+ * without express or implied warranty.
+ *
+ * NCR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN
+ * NO EVENT SHALL NCR BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
+ * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
+ * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
+ * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+/*
+ *
+ * The connection code/ideas in lib/X and server/os for SVR4/Intel 
+ * environments was contributed by the following companies/groups:
+ *
+ *     MetroLink Inc
+ *     NCR
+ *     Pittsburgh Powercomputing Corporation (PPc)/Quarterdeck Office Systems
+ *     SGCS
+ *     Unix System Laboratories (USL) / Novell
+ *     XFree86
+ *
+ * The goal is to have common connection code among all SVR4/Intel vendors.
+ *
+ * ALL THE ABOVE COMPANIES DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS 
+ * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, 
+ * IN NO EVENT SHALL THESE COMPANIES * BE LIABLE FOR ANY SPECIAL, INDIRECT 
+ * OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS 
+ * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE 
+ * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE 
+ * OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include <errno.h>
+#include <ctype.h>
+#include <sys/signal.h>
+#include <sys/ioctl.h>
+#include <sys/stat.h>
+#ifdef SVR4
+#include <sys/filio.h>
+#endif
+#include <sys/stropts.h>
+#include <sys/wait.h>
+
+/*
+ * The local transports should be treated the same as a UNIX domain socket
+ * wrt authentication, etc. Because of this, we will use struct sockaddr_un
+ * for the address format. This will simplify the code in other places like
+ * The X Server.
+ */
+
+#include <sys/socket.h>
+#ifndef X_NO_SYS_UN
+#include <sys/un.h>
+#endif
+
+#if defined(ISC) && !defined(_POSIX_SOURCE)
+typedef unsigned short  mode_t;
+/* POSIX needed for mode_t define in sys/types.h */
+#endif
+
+/*
+ * These functions actually implement the local connection mechanisms.
+ */
+
+/* Type Not Supported */
+
+static int
+TRANS(OpenFail)(ciptr, port)
+
+XtransConnInfo ciptr;
+char           *port;
+
+{
+    return -1;
+}
+
+#ifdef TRANS_REOPEN
+
+static int
+TRANS(ReopenFail)(ciptr, fd, port)
+
+XtransConnInfo ciptr;
+int            fd;
+char           *port;
+
+{
+    return 0;
+}
+
+#endif /* TRANS_REOPEN */
+
+
+\f
+static int
+TRANS(FillAddrInfo)(ciptr, sun_path, peer_sun_path)
+
+XtransConnInfo ciptr;
+char           *sun_path;
+char           *peer_sun_path;
+
+{
+    struct sockaddr_un *sunaddr;
+    struct sockaddr_un *p_sunaddr;
+
+    ciptr->family = AF_UNIX;
+    ciptr->addrlen = sizeof (struct sockaddr_un);
+
+    if ((sunaddr = (struct sockaddr_un *) xalloc (ciptr->addrlen)) == NULL)
+    {
+       PRMSG(1,"FillAddrInfo: failed to allocate memory for addr\n",
+                                                                       0,0,0);
+       return 0;
+    }
+
+    sunaddr->sun_family = AF_UNIX;
+
+    strcpy (sunaddr->sun_path, sun_path);
+#if defined(BSD44SOCKETS) && !defined(Lynx)
+    sunaddr->sun_len = strlen (sunaddr->sun_path);
+#endif
+
+    ciptr->addr = (char *) sunaddr;
+
+    ciptr->peeraddrlen = sizeof (struct sockaddr_un);
+
+    if ((p_sunaddr = (struct sockaddr_un *) xalloc (
+       ciptr->peeraddrlen)) == NULL)
+    {
+       PRMSG(1,
+          "FillAddrInfo: failed to allocate memory for peer addr\n",
+                                                                       0,0,0);
+       xfree ((char *) sunaddr);
+       ciptr->addr = NULL;
+
+       return 0;
+    }
+
+    p_sunaddr->sun_family = AF_UNIX;
+
+    strcpy (p_sunaddr->sun_path, peer_sun_path);
+#if defined(BSD44SOCKETS) && !defined(Lynx)
+    p_sunaddr->sun_len = strlen (p_sunaddr->sun_path);
+#endif
+
+    ciptr->peeraddr = (char *) p_sunaddr;
+
+    return 1;
+}
+
+
+\f
+/* PTS */
+
+#if defined(SYSV) && !defined(sco) && !defined(SCO) && !defined(ISC)
+#define SIGNAL_T int
+#else
+#define SIGNAL_T void
+#endif /* SYSV */
+
+typedef SIGNAL_T (*PFV)();
+
+extern PFV signal();
+
+extern char *ptsname(
+#if NeedFunctionPrototypes
+    int
+#endif
+);
+
+static void _dummy(sig)
+
+int sig;
+
+{
+}
+
+#define X_STREAMS_DIR  "/dev/X"
+#define DEV_PTMX       "/dev/ptmx"
+#define DEV_SPX                "/dev/spx"
+
+#if defined(X11_t)
+
+#define PTSNODENAME "/dev/X/server."
+#define NAMEDNODENAME "/dev/X/Nserver."
+
+/*
+ * ISC and SCO are only defined for X11 since they are there for
+ * backwards binary compatability only.
+ */
+
+#define X_ISC_DIR      "/dev/X/ISCCONN"
+#define ISCDEVNODENAME "/dev/X/ISCCONN/X%s"
+#define ISCTMPNODENAME "/tmp/.X11-unix/X%s"
+#define SCORNODENAME   "/dev/X%1sR"
+#define SCOSNODENAME   "/dev/X%1sS"
+#endif
+#if defined(XIM_t)
+#define PTSNODENAME    "/dev/X/XIM."
+#define NAMEDNODENAME  "/dev/X/NXIM."
+#endif
+#if defined(FS_t) || defined (FONT_t)
+/*
+ * USL has already defined something here. We need to check with them
+ * and see if their choice is usable here.
+ */
+#define PTSNODENAME    "/dev/X/fontserver."
+#define NAMEDNODENAME  "/dev/X/Nfontserver."
+#endif
+#if defined(ICE_t)
+#define PTSNODENAME    "/dev/X/ICE."
+#define NAMEDNODENAME  "/dev/X/NICE."
+#endif
+#if defined(TEST_t)
+#define PTSNODENAME    "/dev/X/transtest."
+#define NAMEDNODENAME  "/dev/X/Ntranstest."
+#endif
+
+
+\f
+#ifdef TRANS_CLIENT
+
+static int
+TRANS(PTSOpenClient)(ciptr, port)
+
+XtransConnInfo ciptr;
+char           *port;
+
+{
+    int                        fd,server,exitval,alarm_time,ret;
+    char               server_path[64];
+    char               *slave, namelen;
+    char               buf[20]; /* MAX_PATH_LEN?? */
+    PFV                        savef;
+
+    PRMSG(2,"PTSOpenClient(%s)\n", port, 0,0 );
+
+#if !defined(PTSNODENAME)
+    PRMSG(1,"PTSOpenClient: Protocol is not supported by a pts connection\n", 0,0,0);
+    return -1;
+#else
+    if (port && *port ) {
+       if( *port == '/' ) { /* A full pathname */
+               (void) sprintf(server_path, "%s", port);
+           } else {
+               (void) sprintf(server_path, "%s%s", PTSNODENAME, port);
+           }
+    } else {
+       (void) sprintf(server_path, "%s%d", PTSNODENAME, getpid());
+    }
+
+
+    /*
+     * Open the node the on which the server is listening.
+     */
+
+    if ((server = open (server_path, O_RDWR)) < 0) {
+       PRMSG(1,"PTSOpenClient: failed to open %s\n", server_path, 0,0);
+       return -1;
+    }
+
+
+    /*
+     * Open the streams based pipe that will be this connection.
+     */
+
+    if ((fd = open("/dev/ptmx", O_RDWR)) < 0) {
+       PRMSG(1,"PTSOpenClient: failed to open /dev/ptmx\n", 0,0,0);
+       return -1;
+    }
+
+    (void) grantpt(fd);
+    (void) unlockpt(fd);
+
+    slave = ptsname(fd); /* get name */
+
+    if( slave == NULL ) {
+       PRMSG(1,"PTSOpenClient: failed to get ptsname()\n", 0,0,0);
+       close(fd);
+       close(server);
+       return -1;
+    }
+
+    /*
+     * This is neccesary for the case where a program is setuid to non-root.
+     * grantpt() calls /usr/lib/pt_chmod which is set-uid root. This program will
+     * set the owner of the pt device incorrectly if the uid is not restored
+     * before it is called. The problem is that once it gets restored, it
+     * cannot be changed back to its original condition, hence the fork().
+     */
+
+    if( !fork()) {
+       uid_t       saved_euid;
+
+       saved_euid = geteuid();
+       setuid( getuid() ); /** sets the euid to the actual/real uid **/
+       if( chown( slave, saved_euid, -1 ) < 0 ) {
+               exit( 1 );
+               }
+
+       exit( 0 );
+    }
+
+    wait( &exitval );
+
+    if (chmod(slave, 0666) < 0) {
+       close(fd);
+       close(server);
+       PRMSG(1,"PTSOpenClient: Cannot chmod %s\n", slave, 0,0);
+       return(-1);
+    }
+
+    /*
+     * write slave name to server
+     */
+
+    namelen = strlen(slave);
+    buf[0] = namelen;
+    (void) sprintf(&buf[1], slave);
+    (void) write(server, buf, namelen+1);
+    (void) close(server);
+
+    /*
+     * wait for server to respond
+     */
+
+    savef = signal(SIGALRM, _dummy);
+    alarm_time = alarm (30); /* CONNECT_TIMEOUT */
+
+    ret = read(fd, buf, 1);
+
+    (void) alarm(alarm_time);
+    (void) signal(SIGALRM, savef);
+
+    if (ret != 1) {
+       PRMSG(1,
+       "PTSOpenClient: failed to get acknoledgement from server\n",
+                                                                       0,0,0);
+       (void) close(fd);
+       fd = -1;
+    }
+
+    /*
+     * Everything looks good: fill in the XtransConnInfo structure.
+     */
+
+    if (TRANS(FillAddrInfo) (ciptr, slave, server_path) == 0)
+    {
+       PRMSG(1,"PTSOpenClient: failed to fill in addr info\n",
+                                                               0,0,0);
+       close(fd);
+       return -1;
+    }
+
+    return(fd);
+
+#endif /* !PTSNODENAME */
+}
+
+#endif /* TRANS_CLIENT */
+
+
+#ifdef TRANS_SERVER
+
+static int
+TRANS(PTSOpenServer)(ciptr, port)
+
+XtransConnInfo ciptr;
+char           *port;
+
+{
+    int fd, server;
+    char server_path[64], *slave;
+
+    PRMSG(2,"PTSOpenServer(%s)\n", port, 0,0 );
+
+#if !defined(PTSNODENAME)
+    PRMSG(1,"PTSOpenServer: Protocol is not supported by a pts connection\n", 0,0,0);
+    return -1;
+#else
+    if (port && *port ) {
+       if( *port == '/' ) { /* A full pathname */
+               (void) sprintf(server_path, "%s", port);
+           } else {
+               (void) sprintf(server_path, "%s%s", PTSNODENAME, port);
+           }
+    } else {
+       (void) sprintf(server_path, "%s%d", PTSNODENAME, getpid());
+    }
+
+    mkdir(X_STREAMS_DIR, 0777);
+    chmod(X_STREAMS_DIR, 0777);
+
+    if( (fd=open(server_path, O_RDWR)) >= 0 ) {
+#if 0
+       /*
+        * This doesn't prevent the server from starting up, and doesn't
+        * prevent clients from trying to connect to the in-use PTS (which
+        * is often in use by something other than another server).
+        */
+       PRMSG(1, "PTSOpenServer: A server is already running on port %s\n", port, 0,0 );
+       PRMSG(1, "PTSOpenServer: Remove %s if this is incorrect.\n", server_path, 0,0 );
+       close(fd);
+       return(-1);
+#else
+       /* Just remove the old path (which is what happens with UNIXCONN) */
+       ;
+#endif
+    }
+
+    unlink(server_path);
+
+    if( (fd=open(DEV_PTMX, O_RDWR)) < 0) {
+       PRMSG(1, "PTSOpenServer: Unable to open %s\n", DEV_PTMX, 0,0 );
+       return(-1);
+    }
+
+    grantpt(fd);
+    unlockpt(fd);
+
+    if( (slave=ptsname(fd)) == NULL) {
+       PRMSG(1, "PTSOpenServer: Unable to get slave device name\n", 0,0,0 );
+       close(fd);
+       return(-1);
+    }
+
+    if( link(slave,server_path) < 0 ) {
+       PRMSG(1, "PTSOpenServer: Unable to link %s to %s\n", slave, server_path,0 );
+       close(fd);
+       return(-1);
+    }
+
+    if( chmod(server_path, 0666) < 0 ) {
+       PRMSG(1, "PTSOpenServer: Unable to chmod %s to 0666\n", server_path,0,0 );
+       close(fd);
+       return(-1);
+    }
+
+    if( (server=open(server_path, O_RDWR)) < 0 ) {
+       PRMSG(1, "PTSOpenServer: Unable to open server device %s\n", server_path,0,0 );
+       close(fd);
+       return(-1);
+    }
+
+    close(server);
+
+    /*
+     * Everything looks good: fill in the XtransConnInfo structure.
+     */
+
+    if (TRANS(FillAddrInfo) (ciptr, server_path, server_path) == 0)
+    {
+       PRMSG(1,"PTSOpenServer: failed to fill in addr info\n",
+                                                               0,0,0);
+       close(fd);
+       return -1;
+    }
+
+    return fd;
+
+#endif /* !PTSNODENAME */
+}
+
+static int
+TRANS(PTSAccept)(ciptr, newciptr, status)
+
+XtransConnInfo ciptr;
+XtransConnInfo newciptr;
+int            *status;
+
+{
+    int                        newfd;
+    int                        in;
+    unsigned char      length;
+    char               buf[256];
+    struct sockaddr_un *sunaddr;
+
+    PRMSG(2,"PTSAccept(%x->%d)\n",ciptr,ciptr->fd,0);
+
+    if( (in=read(ciptr->fd,&length,1)) <= 0 ){
+       if( !in ) {
+               PRMSG(2,
+               "PTSAccept: Incoming connection closed\n",0,0,0);
+               }
+       else {
+               PRMSG(1,
+       "PTSAccept: Error reading incoming connection. errno=%d \n",
+                                                               errno,0,0);
+               }
+       *status = TRANS_ACCEPT_MISC_ERROR;
+       return -1;
+    }
+
+    if( (in=read(ciptr->fd,buf,length)) <= 0 ){
+       if( !in ) {
+               PRMSG(2,
+               "PTSAccept: Incoming connection closed\n",0,0,0);
+               }
+       else {
+               PRMSG(1,
+"PTSAccept: Error reading device name for new connection. errno=%d \n",
+                                                               errno,0,0);
+               }
+       *status = TRANS_ACCEPT_MISC_ERROR;
+       return -1;
+    }
+
+    buf[length] = '\0';
+
+    if( (newfd=open(buf,O_RDWR)) < 0 ) {
+       PRMSG(1, "PTSAccept: Failed to open %s\n",buf,0,0);
+       *status = TRANS_ACCEPT_MISC_ERROR;
+       return -1;
+    }
+
+    write(newfd,"1",1);
+
+    /*
+     * Everything looks good: fill in the XtransConnInfo structure.
+     */
+
+    newciptr->addrlen=ciptr->addrlen;
+    if( (newciptr->addr=(char *)xalloc(newciptr->addrlen)) == NULL ) {
+       PRMSG(1,"PTSAccept: failed to allocate memory for peer addr\n",
+                                                                       0,0,0);
+       close(newfd);
+       *status = TRANS_ACCEPT_BAD_MALLOC;
+       return -1;
+    }
+
+    memcpy(newciptr->addr,ciptr->addr,newciptr->addrlen);
+
+    newciptr->peeraddrlen=sizeof(struct sockaddr_un);
+    if( (sunaddr=(struct sockaddr_un *)xalloc(newciptr->peeraddrlen)) == NULL ) {
+       PRMSG(1,"PTSAccept: failed to allocate memory for peer addr\n",
+                                                                       0,0,0);
+       xfree(newciptr->addr);
+       close(newfd);
+       *status = TRANS_ACCEPT_BAD_MALLOC;
+       return -1;
+    }
+
+    sunaddr->sun_family=AF_UNIX;
+    strcpy(sunaddr->sun_path,buf);
+#if defined(BSD44SOCKETS) && !defined(Lynx)
+    sunaddr->sun_len=strlen(sunaddr->sun_path);
+#endif
+
+    newciptr->peeraddr=(char *)sunaddr;
+
+    *status = 0;
+
+    return newfd;
+}
+
+#endif /* TRANS_SERVER */
+
+\f
+#ifdef SVR4
+
+/* NAMED */
+
+#ifdef TRANS_CLIENT
+
+static int
+TRANS(NAMEDOpenClient)(ciptr, port)
+
+XtransConnInfo ciptr;
+char           *port;
+
+{
+    int                        fd;
+    char               server_path[64];
+    struct stat                filestat;
+    extern int         isastream();
+
+    PRMSG(2,"NAMEDOpenClient(%s)\n", port, 0,0 );
+
+#if !defined(NAMEDNODENAME)
+    PRMSG(1,"NAMEDOpenClient: Protocol is not supported by a NAMED connection\n", 0,0,0);
+    return -1;
+#else
+    if ( port && *port ) {
+       if( *port == '/' ) { /* A full pathname */
+               (void) sprintf(server_path, "%s", port);
+           } else {
+               (void) sprintf(server_path, "%s%s", NAMEDNODENAME, port);
+           }
+    } else {
+       (void) sprintf(server_path, "%s%d", NAMEDNODENAME, getpid());
+    }
+
+    if (stat(server_path, &filestat) < 0 ) {
+       PRMSG(1,"NAMEDOpenClient: No device %s for NAMED connection\n", server_path, 0,0 );
+       return -1;
+    }
+
+    if ((filestat.st_mode & S_IFMT) != S_IFIFO) {
+       PRMSG(1,"NAMEDOpenClient: Device %s is not a FIFO\n", server_path, 0,0 );
+       /* Is this really a failure? */
+       return -1;
+    }
+
+    if ((fd = open(server_path, O_RDWR)) < 0) {
+       PRMSG(1,"NAMEDOpenClient: Cannot open %s for NAMED connection\n", server_path, 0,0 );
+       return -1;
+    }
+
+    if (isastream(fd) <= 0) {
+       PRMSG(1,"NAMEDOpenClient: %s is not a streams device\n", server_path, 0,0 );
+       (void) close(fd);
+       return -1;
+    }
+
+    /*
+     * Everything looks good: fill in the XtransConnInfo structure.
+     */
+
+    if (TRANS(FillAddrInfo) (ciptr, server_path, server_path) == 0)
+    {
+       PRMSG(1,"NAMEDOpenClient: failed to fill in addr info\n",
+                                                               0,0,0);
+       close(fd);
+       return -1;
+    }
+
+    return(fd);
+
+#endif /* !NAMEDNODENAME */
+}
+
+#endif /* TRANS_CLIENT */
+
+
+#ifdef TRANS_SERVER
+
+static int
+TRANS(NAMEDOpenServer)(ciptr, port)
+
+XtransConnInfo ciptr;
+char           *port;
+
+{
+    int                        fd, pipefd[2];
+    char               server_path[64];
+    struct stat                sbuf;
+
+    PRMSG(2,"NAMEDOpenServer(%s)\n", port, 0,0 );
+
+#if !defined(NAMEDNODENAME)
+    PRMSG(1,"NAMEDOpenServer: Protocol is not supported by a NAMED connection\n", 0,0,0);
+    return -1;
+#else
+    if ( port && *port ) {
+       if( *port == '/' ) { /* A full pathname */
+           (void) sprintf(server_path, "%s", port);
+       } else {
+           (void) sprintf(server_path, "%s%s", NAMEDNODENAME, port);
+       }
+    } else {
+       (void) sprintf(server_path, "%s%d", NAMEDNODENAME, getpid());
+    }
+
+    mkdir(X_STREAMS_DIR, 0777);
+    chmod(X_STREAMS_DIR, 0777);
+
+    if(stat(server_path, &sbuf) != 0) {
+       if (errno == ENOENT) {
+           if ((fd = creat(server_path, (mode_t)0666)) == -1) {
+               PRMSG(1, "NAMEDOpenServer: Can't open %s\n", server_path, 0,0 );
+               return(-1);
+           }
+           close(fd);
+           if (chmod(server_path, (mode_t)0666) < 0) {
+               PRMSG(1, "NAMEDOpenServer: Can't open %s\n", server_path, 0,0 );
+               return(-1);
+           }
+       } else {
+           PRMSG(1, "NAMEDOpenServer: stat on %s failed\n", server_path, 0,0 );
+           return(-1);
+       }
+    }
+
+    if( pipe(pipefd) != 0) {
+       PRMSG(1, "NAMEDOpenServer: pipe() failed, errno=%d\n",errno, 0,0 );
+       return(-1);
+    }
+
+    if( ioctl(pipefd[0], I_PUSH, "connld") != 0) {
+       PRMSG(1, "NAMEDOpenServer: ioctl(I_PUSH,\"connld\") failed, errno=%d\n",errno, 0,0 );
+       close(pipefd[0]);
+       close(pipefd[1]);
+       return(-1);
+    }
+
+    if( fattach(pipefd[0], server_path) != 0) {
+       PRMSG(1, "NAMEDOpenServer: fattach(%s) failed, errno=%d\n", server_path,errno, 0 );
+       close(pipefd[0]);
+       close(pipefd[1]);
+       return(-1);
+    }
+
+    /*
+     * Everything looks good: fill in the XtransConnInfo structure.
+     */
+
+    if (TRANS(FillAddrInfo) (ciptr, server_path, server_path) == 0)
+    {
+       PRMSG(1,"NAMEDOpenServer: failed to fill in addr info\n",
+                                                               0,0,0);
+       close(fd);
+       return -1;
+    }
+
+    return(pipefd[1]);
+
+#endif /* !NAMEDNODENAME */
+}
+
+static int
+TRANS(NAMEDAccept)(ciptr, newciptr, status)
+
+XtransConnInfo ciptr;
+XtransConnInfo newciptr;
+int            *status;
+
+{
+    struct strrecvfd str;
+
+    PRMSG(2,"NAMEDAccept(%x->%d)\n", ciptr, ciptr->fd, 0 );
+
+    if( ioctl(ciptr->fd, I_RECVFD, &str ) < 0 ) {
+       PRMSG(1, "NAMEDAccept: ioctl(I_RECVFD) failed, errno=%d\n", errno, 0,0 );
+       *status = TRANS_ACCEPT_MISC_ERROR;
+       return(-1);
+    }
+
+    /*
+     * Everything looks good: fill in the XtransConnInfo structure.
+     */
+
+    newciptr->addrlen=ciptr->addrlen;
+    if( (newciptr->addr=(char *)xalloc(newciptr->addrlen)) == NULL ) {
+       PRMSG(1,
+             "NAMEDAccept: failed to allocate memory for peer addr\n",
+                                                                       0,0,0);
+       close(str.fd);
+       *status = TRANS_ACCEPT_BAD_MALLOC;
+       return -1;
+    }
+
+    memcpy(newciptr->addr,ciptr->addr,newciptr->addrlen);
+
+    newciptr->peeraddrlen=newciptr->addrlen;
+    if( (newciptr->peeraddr=(char *)xalloc(newciptr->peeraddrlen)) == NULL ) {
+       PRMSG(1,
+       "NAMEDAccept: failed to allocate memory for peer addr\n",
+                                                                       0,0,0);
+       xfree(newciptr->addr);
+       close(str.fd);
+       *status = TRANS_ACCEPT_BAD_MALLOC;
+       return -1;
+    }
+
+    memcpy(newciptr->peeraddr,newciptr->addr,newciptr->peeraddrlen);
+
+    *status = 0;
+
+    return str.fd;
+}
+
+#endif /* TRANS_SERVER */
+
+#endif /* SVR4 */
+
+
+\f
+/*
+ * connect_spipe is used by both the SCO and ISC connection types.
+ */
+static int
+connect_spipe(fd1, fd2)
+
+int    fd1, fd2;
+
+{
+    long temp;
+    struct strfdinsert sbuf;
+
+    sbuf.databuf.maxlen = -1;
+    sbuf.databuf.len = -1;
+    sbuf.databuf.buf = NULL;
+    sbuf.ctlbuf.maxlen = sizeof(long);
+    sbuf.ctlbuf.len = sizeof(long);
+    sbuf.ctlbuf.buf = (caddr_t)&temp;
+    sbuf.offset = 0;
+    sbuf.fildes = fd2;
+    sbuf.flags = 0;
+
+    if( ioctl(fd1, I_FDINSERT, &sbuf) < 0 )
+       return(-1);
+
+    return(0);
+}
+
+/*
+ * connect_spipe is used by both the SCO and ISC connection types.
+ */
+
+static int
+named_spipe(fd, path)
+
+int    fd;
+char   *path;
+
+{
+    int oldUmask, ret;
+    struct stat sbuf;
+
+    oldUmask = umask(0);
+
+    (void) fstat(fd, &sbuf);
+    ret = mknod(path, 0020666, sbuf.st_rdev);
+
+    umask(oldUmask);
+
+    if (ret < 0) {
+       ret = -1;
+    } else {
+       ret = fd;
+    }
+    
+    return(ret);
+}
+
+\f
+/* ISC */
+
+#ifdef TRANS_CLIENT
+
+static int
+TRANS(ISCOpenClient)(ciptr, port)
+
+XtransConnInfo ciptr;
+char           *port;
+
+{
+    int                fd,fds,server;
+    char       server_path[64];
+    char       server_dev_path[64];
+    struct     strfdinsert buf;
+    long       temp;
+    mode_t     spmode;
+    struct stat        filestat;
+    
+    PRMSG(2,"ISCOpenClient(%s)\n", port, 0,0 );
+    
+#if !defined(ISCDEVNODENAME)
+    PRMSG(1,"ISCOpenClient: Protocol is not supported by a ISC connection\n", 0,0,0);
+    return -1;
+#else
+    (void) sprintf(server_path, ISCTMPNODENAME, port);
+    (void) sprintf(server_dev_path, ISCDEVNODENAME, port);
+
+    fd = fds = server = -1;
+
+    if (stat(DEV_SPX, &filestat) == -1) {
+       PRMSG(1, "ISCOpenClient: stat(%s) failed, errno=%d\n", DEV_SPX, errno, 0 );
+       return(-1);
+    }
+
+    spmode = (filestat.st_mode & S_IFMT);
+
+    if (stat(server_path, &filestat) != -1) {
+       if ((filestat.st_mode & S_IFMT) == spmode) {
+           if ((server = open(server_path, O_RDWR)) < 0) {
+               PRMSG(1,"ISCOpenClient: failed to open %s\n",
+                     server_path, 0,0 );
+           }
+       }
+    }
+    
+    if (server < 0) {
+       /* try the alternate path */
+       if (stat(server_dev_path, &filestat) != -1) {
+           if ((filestat.st_mode & S_IFMT) == spmode) {
+               if ((server = open(server_dev_path, O_RDWR)) < 0) {
+                   PRMSG(1,"ISCOpenClient: failed to open %s\n",
+                         server_dev_path, 0,0 );
+               }
+           }
+       }
+    }
+    
+    if (server < 0) {
+       PRMSG(1,"ISCOpenClient: can't open either device %s or %s\n",
+             server_path, server_dev_path, 0 );
+       return -1;
+    }
+
+    if ((fds = open(DEV_SPX, O_RDWR)) < 0 ||
+       (fd  = open(DEV_SPX, O_RDWR)) < 0) {
+       /* Failed to open all of the devices */
+       PRMSG(1,"ISCOpenClient: can't open %s\n", DEV_SPX, 0,0 );
+       (void) close(server);
+       if (fds != -1)
+           (void) close(fds);
+       if (fd != -1)
+           (void) close(fd);
+       return -1;
+    }
+
+    /* make a STREAMS-pipe */
+
+    buf.databuf.maxlen = -1;
+    buf.databuf.len = -1;
+    buf.databuf.buf = NULL;
+    buf.ctlbuf.maxlen = sizeof(long);
+    buf.ctlbuf.len = sizeof(long);
+    buf.ctlbuf.buf = (caddr_t)&temp;
+    buf.offset = 0;
+    buf.fildes = fd;
+    buf.flags = 0;
+    
+    if (ioctl(fds, I_FDINSERT, &buf) < 0 ||
+       ioctl(server, I_SENDFD, fds) < 0) {
+       PRMSG(1,"ISCOpenClient: ioctl(I_FDINSERT or I_SENDFD) failed\n",
+                                                               0,0,0 );
+       (void) close(server);
+       (void) close(fds);
+       (void) close(fd);
+       return -1;
+    }
+
+    /*
+     * Everything looks good: fill in the XtransConnInfo structure.
+     */
+    
+    if (TRANS(FillAddrInfo) (ciptr, server_path, server_path) == 0)
+    {
+       PRMSG(1,"ISCOpenClient: failed to fill in addr info\n",
+                                                               0,0,0);
+       close(fd);
+       return -1;
+    }
+
+    return (fd);
+
+#endif /* !ISCDEVNODENAME */
+}
+
+#endif /* TRANS_CLIENT */
+
+
+#ifdef TRANS_SERVER
+
+static int
+TRANS(ISCOpenServer)(ciptr, port)
+
+XtransConnInfo ciptr;
+char           *port;
+
+{
+    int        fd = -1,fds = -1;
+    char       server_path[64],server_unix_path[64];
+    
+    PRMSG(2,"ISCOpenServer(%s)\n", port, 0,0 );
+    
+#if !defined(ISCDEVNODENAME)
+    PRMSG(1,"ISCOpenServer: Protocol is not supported by a ISC connection\n", 0,0,0);
+    return -1;
+#else
+    (void) sprintf(server_path, ISCDEVNODENAME, port);
+    (void) sprintf(server_unix_path, ISCTMPNODENAME, port);
+    
+    mkdir(X_STREAMS_DIR, 0777); /* "/dev/X" */
+    chmod(X_STREAMS_DIR, 0777);
+    mkdir(X_ISC_DIR, 0777); /* "/dev/X/ISCCONN" */
+    chmod(X_ISC_DIR, 0777);
+    
+    unlink(server_path);
+    
+    if( ((fds=open(DEV_SPX, O_RDWR)) < 0) ||
+       ((fd =open(DEV_SPX, O_RDWR)) < 0)) {
+       PRMSG(1,"ISCOpenServer: failed to open %s\n", DEV_SPX, 0,0 );
+       return -1;
+    }
+    
+    if( (connect_spipe(fds, fd) < 0) ||
+       (named_spipe(fds, server_path) < 0)) {
+       PRMSG(1,"ISCOpenServer: failed connect pipes\n", 0,0,0 );
+       close(fd);
+       close(fds);
+       return -1;
+    }
+    
+#if !defined(UNIXCONN)
+    /*
+     * If the UNIX Domain socket transport is not being used, then link this
+     * device to the path /tmp/.X11-unix/X path.
+     */
+#define X_UNIX_DIR     "/tmp/.X11-unix"
+    
+    if (!mkdir(X_UNIX_DIR, 01777))
+       chmod(X_UNIX_DIR, 01777);
+    
+    unlink(server_unix_path);
+    
+#ifdef SVR4
+    /* we prefer symbolic links because hard links can't cross file systems */
+    if( symlink(server_path, server_unix_path) < 0 )
+       PRMSG(1,"ISCOpenServer: failed to link %s to %s\n",
+             server_path, server_unix_path, 0 );
+    /*
+     * Don't make this failure fatal since the listener 
+     * is already established, and this just for compatability
+     */
+#else
+#ifdef ISC40
+    /* catch SIGSYS on symlink for ISC40 compiled binaries running on ISC30 */
+    signal(SIGSYS,_dummy);
+#endif
+    if( link(server_path, server_unix_path) < 0 )
+#ifdef ISC40
+      if( symlink(server_path, server_unix_path) < 0 )
+#endif
+       PRMSG(1,"ISCOpenServer: failed to link %s to %s\n",
+             server_path, server_unix_path, 0 );
+    /*
+     * Don't make this failure fatal since the listener 
+     * is already established, and this just for compatability
+     */
+#endif /* SVR4 */
+#endif /* !UNIXCONN */
+    
+    /*
+     * Everything looks good: fill in the XtransConnInfo structure.
+     */
+    
+    if (TRANS(FillAddrInfo) (ciptr, server_path, server_path) == 0)
+    {
+       PRMSG(1,"ISCOpenServer: failed to fill in addr info\n",
+                                                               0,0,0);
+       close(fd);
+       return -1;
+    }
+
+    return fd;
+
+#endif /* !ISCDEVNODENAME */
+}
+
+static int
+TRANS(ISCAccept)(ciptr, newciptr, status)
+
+XtransConnInfo ciptr;
+XtransConnInfo newciptr;
+int            *status;
+
+{
+    struct strrecvfd str;
+    
+    PRMSG(2,"ISCAccept(%d)\n", ciptr->fd, 0,0 );
+    
+    while (ioctl(ciptr->fd, I_RECVFD, &str) < 0) {
+       if (errno != EAGAIN) {
+           PRMSG(1,"ISCAccept: Can't read fildes", 0,0,0 );
+           *status = TRANS_ACCEPT_MISC_ERROR;
+           return(-1);
+       }
+    }
+    
+    /*
+     * Everything looks good: fill in the XtransConnInfo structure.
+     */
+    
+    newciptr->addrlen=ciptr->addrlen;
+    if( (newciptr->addr=(char *)xalloc(newciptr->addrlen)) == NULL ) {
+       PRMSG(1,
+             "ISCAccept: failed to allocate memory for peer addr\n",
+             0,0,0);
+       close(str.fd);
+       *status = TRANS_ACCEPT_BAD_MALLOC;
+       return -1;
+    }
+    
+    memcpy(newciptr->addr,ciptr->addr,newciptr->addrlen);
+    
+    newciptr->peeraddrlen=newciptr->addrlen;
+    if( (newciptr->peeraddr=(char *)xalloc(newciptr->peeraddrlen)) == NULL ) {
+       PRMSG(1,
+             "ISCAccept: failed to allocate memory for peer addr\n",
+             0,0,0);
+       xfree(newciptr->addr);
+       close(str.fd);
+       *status = TRANS_ACCEPT_BAD_MALLOC;
+       return -1;
+    }
+    
+    memcpy(newciptr->peeraddr,newciptr->addr,newciptr->peeraddrlen);
+    
+    *status = 0;
+
+    return(str.fd);
+}
+
+#endif /* TRANS_SERVER */
+
+
+\f
+
+/* SCO */
+
+#ifdef TRANS_CLIENT
+
+static int
+TRANS(SCOOpenClient)(ciptr, port)
+
+XtransConnInfo ciptr;
+char           *port;
+
+{
+    int                        fd, server, fl, ret;
+    char               server_path[64];
+    struct strbuf      ctlbuf;
+    unsigned long      alarm_time;
+    void               (*savef)();
+    long               temp;
+    extern int getmsg(), putmsg();
+    
+    PRMSG(2,"SCOOpenClient(%s)\n", port, 0,0 );
+    
+#if !defined(SCORNODENAME)
+    PRMSG(1,"SCOOpenClient: Protocol is not supported by a SCO connection\n", 0,0,0);
+    return -1;
+#else
+    (void) sprintf(server_path, SCORNODENAME, port);
+    
+    if ((server = open(server_path, O_RDWR)) < 0) {
+       PRMSG(1,"SCOOpenClient: failed to open %s\n", server_path, 0,0 );
+       return -1;
+    }
+    
+    if ((fd = open(DEV_SPX, O_RDWR)) < 0) {
+       PRMSG(1,"SCOOpenClient: failed to open %s\n", DEV_SPX, 0,0 );
+       close(server);
+       return -1;
+    }
+    
+    (void) write(server, &server, 1);
+    ctlbuf.len = 0;
+    ctlbuf.maxlen = sizeof(long);
+    ctlbuf.buf = (caddr_t)&temp;
+    fl = 0;
+    
+    savef = signal(SIGALRM, _dummy);
+    alarm_time = alarm(10);
+    
+    ret = getmsg(server, &ctlbuf, 0, &fl);
+    
+    (void) alarm(alarm_time);
+    (void) signal(SIGALRM, savef);
+    
+    if (ret < 0) {
+       PRMSG(1,"SCOOpenClient: error from getmsg\n", 0,0,0 );
+       close(fd);
+       close(server);
+       return -1;
+    }
+    
+    /* The msg we got via getmsg is the result of an
+     * I_FDINSERT, so if we do a putmsg with whatever
+     * we recieved, we're doing another I_FDINSERT ...
+     */
+    (void) putmsg(fd, &ctlbuf, 0, 0);
+    (void) fcntl(fd,F_SETFL,fcntl(fd,F_GETFL,0)|O_NDELAY);
+    
+    (void) close(server);
+    
+    /*
+     * Everything looks good: fill in the XtransConnInfo structure.
+     */
+    
+    if (TRANS(FillAddrInfo) (ciptr, server_path, server_path) == 0)
+    {
+       PRMSG(1,"SCOOpenClient: failed to fill addr info\n",
+             0,0,0);
+       close(fd);
+       return -1;
+    }
+    
+    return(fd);
+
+#endif  /* !SCORNODENAME */
+}
+
+#endif /* TRANS_CLIENT */
+
+
+#ifdef TRANS_SERVER
+
+static int
+TRANS(SCOOpenServer)(ciptr, port)
+
+XtransConnInfo ciptr;
+char           *port;
+
+{
+    char               serverR_path[64];
+    char               serverS_path[64];
+    int        fdr = -1;
+    int        fds = -1;
+    
+    PRMSG(2,"SCOOpenServer(%s)\n", port, 0,0 );
+    
+#if !defined(SCORNODENAME)
+    PRMSG(1,"SCOOpenServer: Protocol is not supported by a SCO connection\n", 0,0,0);
+    return -1;
+#else
+    (void) sprintf(serverR_path, SCORNODENAME, port);
+    (void) sprintf(serverS_path, SCOSNODENAME, port);
+    
+    unlink(serverR_path);
+    unlink(serverS_path);
+    
+    if ((fds = open(DEV_SPX, O_RDWR)) < 0 ||
+       (fdr = open(DEV_SPX, O_RDWR)) < 0 ) {
+       PRMSG(2,"SCOOpenServer: failed to open %s\n", DEV_SPX, 0,0 );
+       return -1;
+    }
+    
+    if (connect_spipe(fds, fdr) != -1 &&
+       named_spipe(fds, serverS_path) != -1 &&
+       named_spipe(fdr, serverR_path) != -1) {
+       PRMSG(2,"SCOOpenServer: connect pipes\n", 0,0,0 );
+       } else {
+       PRMSG(2,"SCOOpenServer: failed to connect pipes\n", 0,0,0 );
+       close(fds);
+       close(fdr);
+       return -1;
+    }
+    
+    /*
+     * Everything looks good: fill in the XtransConnInfo structure.
+     */
+    
+    if (TRANS(FillAddrInfo) (ciptr, serverS_path, serverR_path) == 0)
+    {
+       PRMSG(1,"SCOOpenServer: failed to fill in addr info\n",
+             0,0,0);
+       close(fds);
+       close(fdr);
+       return -1;
+    }
+    
+    return(fds);
+
+#endif /* !SCORNODENAME */
+}
+
+static int
+TRANS(SCOAccept)(ciptr, newciptr, status)
+
+XtransConnInfo ciptr;
+XtransConnInfo newciptr;
+int            *status;
+
+{
+    char       c;
+    int        fd;
+    
+    PRMSG(2,"SCOAccept(%d)\n", ciptr->fd, 0,0 );
+    
+    if (read(ciptr->fd, &c, 1) < 0) {
+       PRMSG(1,"SCOAccept: can't read from client",0,0,0);
+       *status = TRANS_ACCEPT_MISC_ERROR;
+       return(-1);
+    }
+    
+    if( (fd = open(DEV_SPX, O_RDWR)) < 0 ) {
+       PRMSG(1,"SCOAccept: can't open \"%s\"",DEV_SPX, 0,0 );
+       *status = TRANS_ACCEPT_MISC_ERROR;
+       return(-1);
+    }
+    
+    if (connect_spipe(ciptr->fd, fd) < 0) {
+       PRMSG(1,"SCOAccept: can't connect pipes", 0,0,0 );
+       (void) close(fd);
+       *status = TRANS_ACCEPT_MISC_ERROR;
+       return(-1);
+    }
+    
+    /*
+     * Everything looks good: fill in the XtransConnInfo structure.
+     */
+    
+    newciptr->addrlen=ciptr->addrlen;
+    if( (newciptr->addr=(char *)xalloc(newciptr->addrlen)) == NULL ) {
+       PRMSG(1,
+             "SCOAccept: failed to allocate memory for peer addr\n",
+             0,0,0);
+       close(fd);
+       *status = TRANS_ACCEPT_BAD_MALLOC;
+       return -1;
+    }
+    
+    memcpy(newciptr->addr,ciptr->addr,newciptr->addrlen);
+    
+    newciptr->peeraddrlen=newciptr->addrlen;
+    if( (newciptr->peeraddr=(char *)xalloc(newciptr->peeraddrlen)) == NULL ) {
+       PRMSG(1,
+             "SCOAccept: failed to allocate memory for peer addr\n",
+             0,0,0);
+       xfree(newciptr->addr);
+       close(fd);
+       *status = TRANS_ACCEPT_BAD_MALLOC;
+       return -1;
+    }
+    
+    memcpy(newciptr->peeraddr,newciptr->addr,newciptr->peeraddrlen);
+    
+    *status = 0;
+
+    return(fd);
+}
+
+#endif /* TRANS_SERVER */
+
+
+\f
+#ifdef TRANS_REOPEN
+
+static int
+TRANS(PTSReopenServer)(ciptr, fd, port)
+
+XtransConnInfo ciptr;
+int            fd;
+char           *port;
+{
+    char server_path[64];
+
+    PRMSG(2,"PTSReopenServer(%d,%s)\n", fd, port, 0 );
+
+#if !defined(PTSNODENAME)
+    PRMSG(1,"PTSReopenServer: Protocol is not supported by a pts connection\n", 0,0,0);
+    return 0;
+#else
+    if (port && *port ) {
+       if( *port == '/' ) { /* A full pathname */
+               (void) sprintf(server_path, "%s", port);
+           } else {
+               (void) sprintf(server_path, "%s%s", PTSNODENAME, port);
+           }
+    } else {
+       (void) sprintf(server_path, "%s%d", PTSNODENAME, getpid());
+    }
+
+    if (TRANS(FillAddrInfo) (ciptr, server_path, server_path) == 0)
+    {
+       PRMSG(1,"PTSReopenServer: failed to fill in addr info\n",
+                                                               0,0,0);
+       return 0;
+    }
+
+    return 1;
+
+#endif /* !PTSNODENAME */
+}
+
+
+static int
+TRANS(NAMEDReopenServer)(ciptr, fd, port)
+
+XtransConnInfo ciptr;
+int            fd;
+char           *port;
+
+{
+    char server_path[64];
+
+    PRMSG(2,"NAMEDReopenServer(%s)\n", port, 0,0 );
+
+#if !defined(NAMEDNODENAME)
+    PRMSG(1,"NAMEDReopenServer: Protocol is not supported by a NAMED connection\n", 0,0,0);
+    return 0;
+#else
+    if ( port && *port ) {
+       if( *port == '/' ) { /* A full pathname */
+           (void) sprintf(server_path, "%s", port);
+       } else {
+           (void) sprintf(server_path, "%s%s", NAMEDNODENAME, port);
+       }
+    } else {
+       (void) sprintf(server_path, "%s%d", NAMEDNODENAME, getpid());
+    }
+
+    if (TRANS(FillAddrInfo) (ciptr, server_path, server_path) == 0)
+    {
+       PRMSG(1,"NAMEDReopenServer: failed to fill in addr info\n",
+                                                               0,0,0);
+       return 0;
+    }
+
+    return 1;
+
+#endif /* !NAMEDNODENAME */
+}
+
+
+static int
+TRANS(ISCReopenServer)(ciptr, fd, port)
+
+XtransConnInfo ciptr;
+int            fd;
+char           *port;
+
+{
+    char server_path[64],server_unix_path[64];
+    
+    PRMSG(2,"ISCReopenServer(%s)\n", port, 0,0 );
+    
+#if !defined(ISCDEVNODENAME)
+    PRMSG(1,"ISCReopenServer: Protocol is not supported by a ISC connection\n", 0,0,0);
+    return 0;
+#else
+    (void) sprintf(server_path, ISCDEVNODENAME, port);
+    (void) sprintf(server_unix_path, ISCTMPNODENAME, port);
+
+    if (TRANS(FillAddrInfo) (ciptr, server_path, server_path) == 0)
+    {
+       PRMSG(1,"ISCReopenServer: failed to fill in addr info\n",
+                                                               0,0,0);
+       return 0;
+    }
+    
+    return 1;
+
+#endif /* !ISCDEVNODENAME */
+}
+
+
+static int
+TRANS(SCOReopenServer)(ciptr, fd, port)
+
+XtransConnInfo ciptr;
+int            fd;
+char           *port;
+
+{
+    char               serverR_path[64];
+    char               serverS_path[64];
+    
+    PRMSG(2,"SCOReopenServer(%s)\n", port, 0,0 );
+    
+#if !defined(SCORNODENAME)
+    PRMSG(1,"SCOReopenServer: Protocol is not supported by a SCO connection\n", 0,0,0);
+    return 0;
+#else
+    (void) sprintf(serverR_path, SCORNODENAME, port);
+    (void) sprintf(serverS_path, SCOSNODENAME, port);
+    
+    if (TRANS(FillAddrInfo) (ciptr, serverS_path, serverR_path) == 0)
+    {
+       PRMSG(1,"SCOReopenServer: failed to fill in addr info\n",
+             0,0,0);
+       return 0;
+    }
+    
+    return 1;
+
+#endif /* SCORNODENAME */
+}
+
+#endif /* TRANS_REOPEN */
+
+
+\f
+/*
+ * This table contains all of the entry points for the different local
+ * connection mechanisms.
+ */
+
+typedef struct _LOCALtrans2dev {
+    char       *transname;
+
+#ifdef TRANS_CLIENT
+
+    int        (*devcotsopenclient)(
+#if NeedFunctionPrototypes
+       XtransConnInfo, char * /*port*/
+#endif
+);
+
+#endif /* TRANS_CLIENT */
+
+#ifdef TRANS_SERVER
+
+    int        (*devcotsopenserver)(
+#if NeedFunctionPrototypes
+       XtransConnInfo, char * /*port*/
+#endif
+);
+
+#endif /* TRANS_SERVER */
+
+#ifdef TRANS_CLIENT
+
+    int        (*devcltsopenclient)(
+#if NeedFunctionPrototypes
+       XtransConnInfo, char * /*port*/
+#endif
+);
+
+#endif /* TRANS_CLIENT */
+
+#ifdef TRANS_SERVER
+
+    int        (*devcltsopenserver)(
+#if NeedFunctionPrototypes
+       XtransConnInfo, char * /*port*/
+#endif
+);
+
+#endif /* TRANS_SERVER */
+
+#ifdef TRANS_REOPEN
+
+    int        (*devcotsreopenserver)(
+#if NeedFunctionPrototypes
+       XtransConnInfo,
+       int,    /* fd */
+       char *  /* port */
+#endif
+);
+
+    int        (*devcltsreopenserver)(
+#if NeedFunctionPrototypes
+       XtransConnInfo,
+       int,    /* fd */
+       char *  /* port */
+#endif
+);
+
+#endif /* TRANS_REOPEN */
+
+#ifdef TRANS_SERVER
+
+    int        (*devaccept)(
+#if NeedFunctionPrototypes
+       XtransConnInfo, XtransConnInfo, int *
+#endif
+
+);
+
+#endif /* TRANS_SERVER */
+
+} LOCALtrans2dev;
+
+static LOCALtrans2dev LOCALtrans2devtab[] = {
+{"",
+#ifdef TRANS_CLIENT
+     TRANS(PTSOpenClient),
+#endif /* TRANS_CLIENT */
+#ifdef TRANS_SERVER
+     TRANS(PTSOpenServer),
+#endif /* TRANS_SERVER */
+#ifdef TRANS_CLIENT
+     TRANS(OpenFail),
+#endif /* TRANS_CLIENT */
+#ifdef TRANS_SERVER
+     TRANS(OpenFail),
+#endif /* TRANS_SERVER */
+#ifdef TRANS_REOPEN
+     TRANS(PTSReopenServer),
+     TRANS(ReopenFail),
+#endif
+#ifdef TRANS_SERVER
+     TRANS(PTSAccept)
+#endif /* TRANS_SERVER */
+},
+
+{"local",
+#ifdef TRANS_CLIENT
+     TRANS(PTSOpenClient),
+#endif /* TRANS_CLIENT */
+#ifdef TRANS_SERVER
+     TRANS(PTSOpenServer),
+#endif /* TRANS_SERVER */
+#ifdef TRANS_CLIENT
+     TRANS(OpenFail),
+#endif /* TRANS_CLIENT */
+#ifdef TRANS_SERVER
+     TRANS(OpenFail),
+#endif /* TRANS_SERVER */
+#ifdef TRANS_REOPEN
+     TRANS(PTSReopenServer),
+     TRANS(ReopenFail),
+#endif
+#ifdef TRANS_SERVER
+     TRANS(PTSAccept)
+#endif /* TRANS_SERVER */
+},
+
+{"pts",
+#ifdef TRANS_CLIENT
+     TRANS(PTSOpenClient),
+#endif /* TRANS_CLIENT */
+#ifdef TRANS_SERVER
+     TRANS(PTSOpenServer),
+#endif /* TRANS_SERVER */
+#ifdef TRANS_CLIENT
+     TRANS(OpenFail),
+#endif /* TRANS_CLIENT */
+#ifdef TRANS_SERVER
+     TRANS(OpenFail),
+#endif /* TRANS_SERVER */
+#ifdef TRANS_REOPEN
+     TRANS(PTSReopenServer),
+     TRANS(ReopenFail),
+#endif
+#ifdef TRANS_SERVER
+     TRANS(PTSAccept)
+#endif /* TRANS_SERVER */
+},
+
+#ifdef SVR4
+{"named",
+#ifdef TRANS_CLIENT
+     TRANS(NAMEDOpenClient),
+#endif /* TRANS_CLIENT */
+#ifdef TRANS_SERVER
+     TRANS(NAMEDOpenServer),
+#endif /* TRANS_SERVER */
+#ifdef TRANS_CLIENT
+     TRANS(OpenFail),
+#endif /* TRANS_CLIENT */
+#ifdef TRANS_SERVER
+     TRANS(OpenFail),
+#endif /* TRANS_SERVER */
+#ifdef TRANS_REOPEN
+     TRANS(NAMEDReopenServer),
+     TRANS(ReopenFail),
+#endif
+#ifdef TRANS_SERVER
+     TRANS(NAMEDAccept)
+#endif /* TRANS_SERVER */
+},
+#endif /* SVR4 */
+
+{"isc",
+#ifdef TRANS_CLIENT
+     TRANS(ISCOpenClient),
+#endif /* TRANS_CLIENT */
+#ifdef TRANS_SERVER
+     TRANS(ISCOpenServer),
+#endif /* TRANS_SERVER */
+#ifdef TRANS_CLIENT
+     TRANS(OpenFail),
+#endif /* TRANS_CLIENT */
+#ifdef TRANS_SERVER
+     TRANS(OpenFail),
+#endif /* TRANS_SERVER */
+#ifdef TRANS_REOPEN
+     TRANS(ISCReopenServer),
+     TRANS(ReopenFail),
+#endif
+#ifdef TRANS_SERVER
+     TRANS(ISCAccept)
+#endif /* TRANS_SERVER */
+},
+
+{"sco",
+#ifdef TRANS_CLIENT
+     TRANS(SCOOpenClient),
+#endif /* TRANS_CLIENT */
+#ifdef TRANS_SERVER
+     TRANS(SCOOpenServer),
+#endif /* TRANS_SERVER */
+#ifdef TRANS_CLIENT
+     TRANS(OpenFail),
+#endif /* TRANS_CLIENT */
+#ifdef TRANS_SERVER
+     TRANS(OpenFail),
+#endif /* TRANS_SERVER */
+#ifdef TRANS_REOPEN
+     TRANS(SCOReopenServer),
+     TRANS(ReopenFail),
+#endif
+#ifdef TRANS_SERVER
+     TRANS(SCOAccept)
+#endif /* TRANS_SERVER */
+},
+};
+
+#define NUMTRANSPORTS  (sizeof(LOCALtrans2devtab)/sizeof(LOCALtrans2dev))
+    
+static char    *XLOCAL=NULL;
+static char    *workingXLOCAL=NULL;
+static char    *freeXLOCAL=NULL;
+
+static void
+TRANS(LocalInitTransports)(protocol)
+
+char *protocol;
+
+{
+    PRMSG(3,"LocalInitTransports(%s)\n", protocol, 0,0 );
+    
+    if( strcmp(protocol,"local") && strcmp(protocol,"LOCAL") )
+    {
+       workingXLOCAL=freeXLOCAL=(char *)xalloc (strlen (protocol) + 1);
+       if (workingXLOCAL)
+           strcpy (workingXLOCAL, protocol);
+    }
+    else {
+       XLOCAL=(char *)getenv("XLOCAL");
+       if(XLOCAL==NULL)
+           XLOCAL="UNIX:PTS:NAMED:ISC:SCO";
+       workingXLOCAL=freeXLOCAL=(char *)xalloc (strlen (XLOCAL) + 1);
+       if (workingXLOCAL)
+           strcpy (workingXLOCAL, XLOCAL);
+    }
+}
+
+static void
+TRANS(LocalEndTransports)()
+
+{
+    PRMSG(3,"LocalEndTransports()\n", 0,0,0 );
+    xfree(freeXLOCAL);
+}
+
+static LOCALtrans2dev *
+TRANS(LocalGetNextTransport)()
+
+{
+    int        i,j;
+    char       *typetocheck;
+#define TYPEBUFSIZE    32
+    char       typebuf[TYPEBUFSIZE];
+    PRMSG(3,"LocalGetNextTransport()\n", 0,0,0 );
+    
+    while(1)
+    {
+       if( workingXLOCAL == NULL || *workingXLOCAL == '\0' )
+           return NULL;
+       
+       typetocheck=workingXLOCAL;
+       workingXLOCAL=strchr(workingXLOCAL,':');
+       if(workingXLOCAL && *workingXLOCAL)
+           *workingXLOCAL++='\0';
+       
+       for(i=0;i<NUMTRANSPORTS;i++)
+       {
+           /*
+            * This is equivilent to a case insensitive strcmp(),
+            * but should be more portable.
+            */
+           strncpy(typebuf,typetocheck,TYPEBUFSIZE);
+           for(j=0;j<TYPEBUFSIZE;j++)
+               if (isupper(typebuf[j]))
+                   typebuf[j]=tolower(typebuf[j]);
+           
+           /* Now, see if they match */
+           if(!strcmp(LOCALtrans2devtab[i].transname,typebuf))
+               return &LOCALtrans2devtab[i];
+       }
+    }
+    /*NOTREACHED*/
+    return NULL;
+}
+
+#ifdef TRANS_CLIENT
+
+#ifdef NEED_UTSNAME
+#include <sys/utsname.h>
+#endif
+
+/*
+ * Make sure 'host' is really local.
+ */
+
+static int
+HostReallyLocal (host)
+
+char *host;
+
+{
+    /*
+     * The 'host' passed to this function may have been generated
+     * by either uname() or gethostname().  We try both if possible.
+     */
+
+#ifdef NEED_UTSNAME
+    struct utsname name;
+#endif
+    char buf[256];
+
+#ifdef NEED_UTSNAME
+    if (uname (&name) >= 0 && strcmp (host, name.nodename) == 0)
+       return (1);
+#endif
+
+    buf[0] = '\0';
+    (void) gethostname (buf, 256);
+    buf[255] = '\0';
+
+    if (strcmp (host, buf) == 0)
+       return (1);
+
+    return (0);
+}
+
+
+static XtransConnInfo
+TRANS(LocalOpenClient)(type, protocol, host, port)
+
+int  type;
+char *protocol;
+char *host;
+char *port;
+
+{
+    int        fd = -1;
+    LOCALtrans2dev *transptr;
+    XtransConnInfo ciptr;
+    int index;
+
+    PRMSG(3,"LocalOpenClient()\n", 0,0,0 );
+    
+    /*
+     * Make sure 'host' is really local.  If not, we return failure.
+     * The reason we make this check is because a process may advertise
+     * a "local" address for which it can accept connections, but if a
+     * process on a remote machine tries to connect to this address,
+     * we know for sure it will fail.
+     */
+
+    if (strcmp (host, "unix") != 0 && !HostReallyLocal (host))
+    {
+       PRMSG (1,
+          "LocalOpenClient: Cannot connect to non-local host %s\n",
+              host, 0, 0);
+       return NULL;
+    }
+
+
+#if defined(X11_t)
+    /*
+     * X has a well known port, that is transport dependant. It is easier
+     * to handle it here, than try and come up with a transport independent
+     * representation that can be passed in and resolved the usual way.
+     *
+     * The port that is passed here is really a string containing the idisplay
+     * from ConnectDisplay(). Since that is what we want for the local transports,
+     * we don't have to do anything special.
+     */
+#endif /* X11_t */
+    
+    if( (ciptr=(XtransConnInfo)xcalloc(1,sizeof(struct _XtransConnInfo))) == NULL )
+    {
+       PRMSG(1,"LocalOpenClient: calloc(1,%d) failed\n",
+             sizeof(struct _XtransConnInfo),0,0 );
+       return NULL;
+    }
+    
+    ciptr->fd = -1;
+    
+    TRANS(LocalInitTransports)(protocol);
+    
+    index = 0;
+    for(transptr=TRANS(LocalGetNextTransport)();
+       transptr!=NULL;transptr=TRANS(LocalGetNextTransport)(), index++)
+    {
+       switch( type )
+       {
+       case XTRANS_OPEN_COTS_CLIENT:
+           ciptr->fd=transptr->devcotsopenclient(ciptr,port);
+           break;
+       case XTRANS_OPEN_CLTS_CLIENT:
+           ciptr->fd=transptr->devcltsopenclient(ciptr,port);
+           break;
+       case XTRANS_OPEN_COTS_SERVER:
+       case XTRANS_OPEN_CLTS_SERVER:
+           PRMSG(1,
+                 "LocalOpenClient: Should not be opening a server with this function\n",
+                 0,0,0);
+           break;
+       default:
+           PRMSG(1,
+                 "LocalOpenClient: Unknown Open type %d\n",
+                 type, 0,0 );
+       }
+       if( ciptr->fd >= 0 )
+           break;
+    }
+    
+    TRANS(LocalEndTransports)();
+    
+    if( ciptr->fd < 0 )
+    {
+       xfree(ciptr);
+       return NULL;
+    }
+    
+    ciptr->priv=(char *)transptr;
+    ciptr->index = index;
+    
+    return ciptr;
+}
+
+#endif /* TRANS_CLIENT */
+
+
+#ifdef TRANS_SERVER
+
+static XtransConnInfo
+TRANS(LocalOpenServer)(type, protocol, host, port)
+
+int  type;
+char *protocol;
+char *host;
+char *port;
+
+{
+    int        i,fd = -1;
+    XtransConnInfo ciptr;
+    
+    PRMSG(2,"LocalOpenServer(%d,%s,%s)\n", type, protocol, port);
+    
+#if defined(X11_t)
+    /*
+     * For X11, the port will be in the format xserverN where N is the
+     * display number. All of the local connections just need to know
+     * the display number because they don't do any name resolution on
+     * the port. This just truncates port to the display portion.
+     */
+#endif /* X11_t */
+    
+    if( (ciptr=(XtransConnInfo)xcalloc(1,sizeof(struct _XtransConnInfo))) == NULL )
+    {
+       PRMSG(1,"LocalOpenServer: calloc(1,%d) failed\n",
+             sizeof(struct _XtransConnInfo),0,0 );
+       return NULL;
+    }
+    
+    for(i=1;i<NUMTRANSPORTS;i++)
+    {
+       if( strcmp(protocol,LOCALtrans2devtab[i].transname) != 0 )
+           continue;
+       switch( type )
+       {
+       case XTRANS_OPEN_COTS_CLIENT:
+       case XTRANS_OPEN_CLTS_CLIENT:
+           PRMSG(1,
+                 "LocalOpenServer: Should not be opening a client with this function\n",
+                 0,0,0);
+           break;
+       case XTRANS_OPEN_COTS_SERVER:
+           ciptr->fd=LOCALtrans2devtab[i].devcotsopenserver(ciptr,port);
+           break;
+       case XTRANS_OPEN_CLTS_SERVER:
+           ciptr->fd=LOCALtrans2devtab[i].devcltsopenserver(ciptr,port);
+           break;
+       default:
+           PRMSG(1,"LocalOpenServer: Unknown Open type %d\n",
+                 type ,0,0);
+       }
+       if( ciptr->fd >= 0 ) {
+           ciptr->priv=(char *)&LOCALtrans2devtab[i];
+           ciptr->index=i;
+           ciptr->flags=1;
+           return ciptr;
+       }
+    }
+    
+    xfree(ciptr);
+    return NULL;
+}
+
+#endif /* TRANS_SERVER */
+
+
+#ifdef TRANS_REOPEN
+
+static XtransConnInfo
+TRANS(LocalReopenServer)(type, index, fd, port)
+
+int  type;
+int  index;
+int  fd;
+char *port;
+
+{
+    XtransConnInfo ciptr;
+    int stat;
+    
+    PRMSG(2,"LocalReopenServer(%d,%d,%d)\n", type, index, fd);
+    
+    if( (ciptr=(XtransConnInfo)xcalloc(1,sizeof(struct _XtransConnInfo))) == NULL )
+    {
+       PRMSG(1,"LocalReopenServer: calloc(1,%d) failed\n",
+             sizeof(struct _XtransConnInfo),0,0 );
+       return NULL;
+    }
+    
+    ciptr->fd = fd;
+
+    switch( type )
+    {
+    case XTRANS_OPEN_COTS_SERVER:
+       stat = LOCALtrans2devtab[index].devcotsreopenserver(ciptr,fd,port);
+       break;
+    case XTRANS_OPEN_CLTS_SERVER:
+       stat = LOCALtrans2devtab[index].devcltsreopenserver(ciptr,fd,port);
+       break;
+    default:
+       PRMSG(1,"LocalReopenServer: Unknown Open type %d\n",
+         type ,0,0);
+    }
+
+    if( stat > 0 ) {
+       ciptr->priv=(char *)&LOCALtrans2devtab[index];
+       ciptr->index=index;
+       ciptr->flags=1;
+       return ciptr;
+    }
+    
+    xfree(ciptr);
+    return NULL;
+}
+
+#endif /* TRANS_REOPEN */
+
+
+\f
+/*
+ * This is the Local implementation of the X Transport service layer
+ */
+
+#ifdef TRANS_CLIENT
+
+static XtransConnInfo
+TRANS(LocalOpenCOTSClient)(thistrans, protocol, host, port)
+
+Xtransport *thistrans;
+char *protocol;
+char *host;
+char *port;
+
+{
+    PRMSG(2,"LocalOpenCOTSClient(%s,%s,%s)\n",protocol,host,port);
+    
+    return TRANS(LocalOpenClient)(XTRANS_OPEN_COTS_CLIENT, protocol, host, port);
+}
+
+#endif /* TRANS_CLIENT */
+
+
+#ifdef TRANS_SERVER
+
+static XtransConnInfo
+TRANS(LocalOpenCOTSServer)(thistrans, protocol, host, port)
+
+Xtransport *thistrans;
+char *protocol;
+char *host;
+char *port;
+
+{
+    char *typetocheck = NULL;
+    int found = 0;
+    char typebuf[TYPEBUFSIZE];
+
+    PRMSG(2,"LocalOpenCOTSServer(%s,%s,%s)\n",protocol,host,port);
+
+    /* Check if this local type is in the XLOCAL list */
+    TRANS(LocalInitTransports)("local");
+    typetocheck = workingXLOCAL;
+    while (typetocheck && !found) {
+       int j;
+
+       workingXLOCAL = strchr(workingXLOCAL, ':');
+       if (workingXLOCAL && *workingXLOCAL)
+           *workingXLOCAL++ = '\0';
+       strncpy(typebuf, typetocheck, TYPEBUFSIZE);
+       for (j = 0; j < TYPEBUFSIZE; j++)
+           if (isupper(typebuf[j]))
+               typebuf[j] = tolower(typebuf[j]);
+       if (!strcmp(thistrans->TransName, typebuf))
+           found = 1;
+       typetocheck = workingXLOCAL;
+    }
+    TRANS(LocalEndTransports)();
+    
+    if (!found) {
+       PRMSG(3,"LocalOpenCOTSServer: disabling %s\n",thistrans->TransName,0,0);
+       thistrans->flags |= TRANS_DISABLED;
+       return NULL;
+    }
+
+    return TRANS(LocalOpenServer)(XTRANS_OPEN_COTS_SERVER, protocol, host, port);
+}
+
+#endif /* TRANS_SERVER */
+
+
+#ifdef TRANS_CLIENT
+
+static XtransConnInfo
+TRANS(LocalOpenCLTSClient)(thistrans, protocol, host, port)
+
+Xtransport *thistrans;
+char *protocol;
+char *host;
+char *port;
+
+{
+    PRMSG(2,"LocalOpenCLTSClient(%s,%s,%s)\n",protocol,host,port);
+    
+    return TRANS(LocalOpenClient)(XTRANS_OPEN_CLTS_CLIENT, protocol, host, port);
+}
+
+#endif /* TRANS_CLIENT */
+
+
+#ifdef TRANS_SERVER
+
+static XtransConnInfo
+TRANS(LocalOpenCLTSServer)(thistrans, protocol, host, port)
+
+Xtransport *thistrans;
+char *protocol;
+char *host;
+char *port;
+
+{
+    PRMSG(2,"LocalOpenCLTSServer(%s,%s,%s)\n",protocol,host,port);
+    
+    return TRANS(LocalOpenServer)(XTRANS_OPEN_CLTS_SERVER, protocol, host, port);
+}
+
+#endif /* TRANS_SERVER */
+
+
+#ifdef TRANS_REOPEN
+
+static XtransConnInfo
+TRANS(LocalReopenCOTSServer)(thistrans, fd, port)
+
+Xtransport *thistrans;
+int       fd;
+char      *port;
+
+{
+    int index;
+
+    PRMSG(2,"LocalReopenCOTSServer(%d,%s)\n", fd, port, 0);
+    
+    for(index=1;index<NUMTRANSPORTS;index++)
+    {
+       if( strcmp(thistrans->TransName,
+           LOCALtrans2devtab[index].transname) == 0 )
+           break;
+    }
+    
+    if (index >= NUMTRANSPORTS)
+    {
+       return (NULL);
+    }
+
+    return TRANS(LocalReopenServer)(XTRANS_OPEN_COTS_SERVER,
+       index, fd, port);
+}
+
+static XtransConnInfo
+TRANS(LocalReopenCLTSServer)(thistrans, fd, port)
+
+Xtransport *thistrans;
+int       fd;
+char      *port;
+
+{
+    int index;
+
+    PRMSG(2,"LocalReopenCLTSServer(%d,%s)\n", fd, port, 0);
+    
+    for(index=1;index<NUMTRANSPORTS;index++)
+    {
+       if( strcmp(thistrans->TransName,
+           LOCALtrans2devtab[index].transname) == 0 )
+           break;
+    }
+    
+    if (index >= NUMTRANSPORTS)
+    {
+       return (NULL);
+    }
+
+    return TRANS(LocalReopenServer)(XTRANS_OPEN_CLTS_SERVER,
+       index, fd, port);
+}
+
+#endif /* TRANS_REOPEN */
+
+
+
+static
+TRANS(LocalSetOption)(ciptr, option, arg)
+
+XtransConnInfo ciptr;
+int option;
+int arg;
+
+{
+    PRMSG(2,"LocalSetOption(%d,%d,%d)\n",ciptr->fd,option,arg);
+    
+    return -1;
+}
+
+
+#ifdef TRANS_SERVER
+
+static
+TRANS(LocalCreateListener)(ciptr, port)
+
+XtransConnInfo ciptr;
+char *port;
+
+{
+    PRMSG(2,"LocalCreateListener(%x->%d,%s)\n",ciptr,ciptr->fd,port);
+    
+    return 0;
+}
+
+static XtransConnInfo
+TRANS(LocalAccept)(ciptr, status)
+
+XtransConnInfo ciptr;
+int           *status;
+
+{
+    XtransConnInfo     newciptr;
+    LOCALtrans2dev     *transptr;
+    
+    PRMSG(2,"LocalAccept(%x->%d)\n", ciptr, ciptr->fd,0);
+    
+    transptr=(LOCALtrans2dev *)ciptr->priv;
+    
+    if( (newciptr=(XtransConnInfo)xcalloc(1,sizeof(struct _XtransConnInfo)))==NULL )
+    {
+       PRMSG(1,"LocalAccept: calloc(1,%d) failed\n",
+             sizeof(struct _XtransConnInfo),0,0 );
+       *status = TRANS_ACCEPT_BAD_MALLOC;
+       return NULL;
+    }
+    
+    newciptr->fd=transptr->devaccept(ciptr,newciptr,status);
+    
+    if( newciptr->fd < 0 )
+    {
+       xfree(newciptr);
+       return NULL;
+    }
+    
+    newciptr->priv=(char *)transptr;
+    newciptr->index = ciptr->index;
+    
+    *status = 0;
+
+    return newciptr;
+}
+
+#endif /* TRANS_SERVER */
+
+
+#ifdef TRANS_CLIENT
+
+static
+TRANS(LocalConnect)(ciptr, host, port)
+
+XtransConnInfo ciptr;
+char *host;
+char *port;
+
+{
+    PRMSG(2,"LocalConnect(%x->%d,%s)\n", ciptr, ciptr->fd, port);
+    
+    return 0;
+}
+
+#endif /* TRANS_CLIENT */
+
+
+static int
+TRANS(LocalBytesReadable)(ciptr, pend )
+
+XtransConnInfo ciptr;
+BytesReadable_t *pend;
+
+{
+    PRMSG(2,"LocalBytesReadable(%x->%d,%x)\n", ciptr, ciptr->fd, pend);
+
+#if defined(ISC) || defined(SCO)
+    return ioctl(ciptr->fd, I_NREAD, (char *)pend);
+#else
+    return ioctl(ciptr->fd, FIONREAD, (char *)pend);
+#endif
+}
+
+static int
+TRANS(LocalRead)(ciptr, buf, size)
+
+XtransConnInfo ciptr;
+char *buf;
+int size;
+
+{
+    PRMSG(2,"LocalRead(%d,%x,%d)\n", ciptr->fd, buf, size );
+    
+    return read(ciptr->fd,buf,size);
+}
+
+static int
+TRANS(LocalWrite)(ciptr, buf, size)
+
+XtransConnInfo ciptr;
+char *buf;
+int size;
+
+{
+    PRMSG(2,"LocalWrite(%d,%x,%d)\n", ciptr->fd, buf, size );
+    
+    return write(ciptr->fd,buf,size);
+}
+
+static int
+TRANS(LocalReadv)(ciptr, buf, size)
+
+XtransConnInfo         ciptr;
+struct iovec   *buf;
+int            size;
+
+{
+    PRMSG(2,"LocalReadv(%d,%x,%d)\n", ciptr->fd, buf, size );
+    
+    return READV(ciptr,buf,size);
+}
+
+static int
+TRANS(LocalWritev)(ciptr, buf, size)
+
+XtransConnInfo         ciptr;
+struct iovec   *buf;
+int            size;
+
+{
+    PRMSG(2,"LocalWritev(%d,%x,%d)\n", ciptr->fd, buf, size );
+    
+    return WRITEV(ciptr,buf,size);
+}
+
+static int
+TRANS(LocalDisconnect)(ciptr)
+
+XtransConnInfo ciptr;
+
+{
+    PRMSG(2,"LocalDisconnect(%x->%d)\n", ciptr, ciptr->fd, 0);
+    
+    return 0;
+}
+
+static int
+TRANS(LocalClose)(ciptr)
+
+XtransConnInfo ciptr;
+
+{
+    struct sockaddr_un      *sockname=(struct sockaddr_un *) ciptr->addr;
+    char    path[200]; /* > sizeof sun_path +1 */
+    int        ret;
+    
+    PRMSG(2,"LocalClose(%x->%d)\n", ciptr, ciptr->fd ,0);
+    
+    ret=close(ciptr->fd);
+    
+    if(ciptr->flags
+       && sockname
+       && sockname->sun_family == AF_UNIX
+       && sockname->sun_path[0] )
+    {
+       strncpy(path,sockname->sun_path,
+               ciptr->addrlen-sizeof(sockname->sun_family));
+       unlink(path);
+    }
+    
+    return ret;
+}
+
+static int
+TRANS(LocalCloseForCloning)(ciptr)
+
+XtransConnInfo ciptr;
+
+{
+    int ret;
+
+    PRMSG(2,"LocalCloseForCloning(%x->%d)\n", ciptr, ciptr->fd ,0);
+    
+    /* Don't unlink path */
+
+    ret=close(ciptr->fd);
+    
+    return ret;
+}
+
+
+/*
+ * MakeAllCOTSServerListeners() will go through the entire Xtransports[]
+ * array defined in Xtrans.c and try to OpenCOTSServer() for each entry.
+ * We will add duplicate entries to that table so that the OpenCOTSServer()
+ * function will get called once for each type of local transport. 
+ *
+ * The TransName is in lowercase, so it will never match during a normal
+ * call to SelectTransport() in Xtrans.c.
+ */
+
+Xtransport     TRANS(LocalFuncs) = {
+       /* Local Interface */
+       "local",
+       TRANS_ALIAS | TRANS_LOCAL,
+#ifdef TRANS_CLIENT
+       TRANS(LocalOpenCOTSClient),
+#endif /* TRANS_CLIENT */
+#ifdef TRANS_SERVER
+       TRANS(LocalOpenCOTSServer),
+#endif /* TRANS_SERVER */
+#ifdef TRANS_CLIENT
+       TRANS(LocalOpenCLTSClient),
+#endif /* TRANS_CLIENT */
+#ifdef TRANS_SERVER
+       TRANS(LocalOpenCLTSServer),
+#endif /* TRANS_SERVER */
+#ifdef TRANS_REOPEN
+       TRANS(LocalReopenCOTSServer),
+       TRANS(LocalReopenCLTSServer),
+#endif
+       TRANS(LocalSetOption),
+#ifdef TRANS_SERVER
+       TRANS(LocalCreateListener),
+       NULL,                                   /* ResetListener */
+       TRANS(LocalAccept),
+#endif /* TRANS_SERVER */
+#ifdef TRANS_CLIENT
+       TRANS(LocalConnect),
+#endif /* TRANS_CLIENT */
+       TRANS(LocalBytesReadable),
+       TRANS(LocalRead),
+       TRANS(LocalWrite),
+       TRANS(LocalReadv),
+       TRANS(LocalWritev),
+       TRANS(LocalDisconnect),
+       TRANS(LocalClose),
+       TRANS(LocalCloseForCloning),
+};
+
+Xtransport     TRANS(PTSFuncs) = {
+       /* Local Interface */
+       "pts",
+       TRANS_LOCAL,
+#ifdef TRANS_CLIENT
+       TRANS(LocalOpenCOTSClient),
+#endif /* TRANS_CLIENT */
+#ifdef TRANS_SERVER
+       TRANS(LocalOpenCOTSServer),
+#endif /* TRANS_SERVER */
+#ifdef TRANS_CLIENT
+       TRANS(LocalOpenCLTSClient),
+#endif /* TRANS_CLIENT */
+#ifdef TRANS_SERVER
+       TRANS(LocalOpenCLTSServer),
+#endif /* TRANS_SERVER */
+#ifdef TRANS_REOPEN
+       TRANS(LocalReopenCOTSServer),
+       TRANS(LocalReopenCLTSServer),
+#endif
+       TRANS(LocalSetOption),
+#ifdef TRANS_SERVER
+       TRANS(LocalCreateListener),
+       NULL,                                   /* ResetListener */
+       TRANS(LocalAccept),
+#endif /* TRANS_SERVER */
+#ifdef TRANS_CLIENT
+       TRANS(LocalConnect),
+#endif /* TRANS_CLIENT */
+       TRANS(LocalBytesReadable),
+       TRANS(LocalRead),
+       TRANS(LocalWrite),
+       TRANS(LocalReadv),
+       TRANS(LocalWritev),
+       TRANS(LocalDisconnect),
+       TRANS(LocalClose),
+       TRANS(LocalCloseForCloning),
+};
+
+Xtransport     TRANS(NAMEDFuncs) = {
+       /* Local Interface */
+       "named",
+       TRANS_LOCAL,
+#ifdef TRANS_CLIENT
+       TRANS(LocalOpenCOTSClient),
+#endif /* TRANS_CLIENT */
+#ifdef TRANS_SERVER
+       TRANS(LocalOpenCOTSServer),
+#endif /* TRANS_SERVER */
+#ifdef TRANS_CLIENT
+       TRANS(LocalOpenCLTSClient),
+#endif /* TRANS_CLIENT */
+#ifdef TRANS_SERVER
+       TRANS(LocalOpenCLTSServer),
+#endif /* TRANS_SERVER */
+#ifdef TRANS_REOPEN
+       TRANS(LocalReopenCOTSServer),
+       TRANS(LocalReopenCLTSServer),
+#endif
+       TRANS(LocalSetOption),
+#ifdef TRANS_SERVER
+       TRANS(LocalCreateListener),
+       NULL,                                   /* ResetListener */
+       TRANS(LocalAccept),
+#endif /* TRANS_SERVER */
+#ifdef TRANS_CLIENT
+       TRANS(LocalConnect),
+#endif /* TRANS_CLIENT */
+       TRANS(LocalBytesReadable),
+       TRANS(LocalRead),
+       TRANS(LocalWrite),
+       TRANS(LocalReadv),
+       TRANS(LocalWritev),
+       TRANS(LocalDisconnect),
+       TRANS(LocalClose),
+       TRANS(LocalCloseForCloning),
+};
+
+Xtransport     TRANS(ISCFuncs) = {
+       /* Local Interface */
+       "isc",
+       TRANS_LOCAL,
+#ifdef TRANS_CLIENT
+       TRANS(LocalOpenCOTSClient),
+#endif /* TRANS_CLIENT */
+#ifdef TRANS_SERVER
+       TRANS(LocalOpenCOTSServer),
+#endif /* TRANS_SERVER */
+#ifdef TRANS_CLIENT
+       TRANS(LocalOpenCLTSClient),
+#endif /* TRANS_CLIENT */
+#ifdef TRANS_SERVER
+       TRANS(LocalOpenCLTSServer),
+#endif /* TRANS_SERVER */
+#ifdef TRANS_REOPEN
+       TRANS(LocalReopenCOTSServer),
+       TRANS(LocalReopenCLTSServer),
+#endif
+       TRANS(LocalSetOption),
+#ifdef TRANS_SERVER
+       TRANS(LocalCreateListener),
+       NULL,                                   /* ResetListener */
+       TRANS(LocalAccept),
+#endif /* TRANS_SERVER */
+#ifdef TRANS_CLIENT
+       TRANS(LocalConnect),
+#endif /* TRANS_CLIENT */
+       TRANS(LocalBytesReadable),
+       TRANS(LocalRead),
+       TRANS(LocalWrite),
+       TRANS(LocalReadv),
+       TRANS(LocalWritev),
+       TRANS(LocalDisconnect),
+       TRANS(LocalClose),
+       TRANS(LocalCloseForCloning),
+};
+Xtransport     TRANS(SCOFuncs) = {
+       /* Local Interface */
+       "sco",
+       TRANS_LOCAL,
+#ifdef TRANS_CLIENT
+       TRANS(LocalOpenCOTSClient),
+#endif /* TRANS_CLIENT */
+#ifdef TRANS_SERVER
+       TRANS(LocalOpenCOTSServer),
+#endif /* TRANS_SERVER */
+#ifdef TRANS_CLIENT
+       TRANS(LocalOpenCLTSClient),
+#endif /* TRANS_CLIENT */
+#ifdef TRANS_SERVER
+       TRANS(LocalOpenCLTSServer),
+#endif /* TRANS_SERVER */
+#ifdef TRANS_REOPEN
+       TRANS(LocalReopenCOTSServer),
+       TRANS(LocalReopenCLTSServer),
+#endif
+       TRANS(LocalSetOption),
+#ifdef TRANS_SERVER
+       TRANS(LocalCreateListener),
+       NULL,                                   /* ResetListener */
+       TRANS(LocalAccept),
+#endif /* TRANS_SERVER */
+#ifdef TRANS_CLIENT
+       TRANS(LocalConnect),
+#endif /* TRANS_CLIENT */
+       TRANS(LocalBytesReadable),
+       TRANS(LocalRead),
+       TRANS(LocalWrite),
+       TRANS(LocalReadv),
+       TRANS(LocalWritev),
+       TRANS(LocalDisconnect),
+       TRANS(LocalClose),
+       TRANS(LocalCloseForCloning),
+};
diff --git a/Xserver/lib/xtrans/Xtransmnx.c b/Xserver/lib/xtrans/Xtransmnx.c
new file mode 100644 (file)
index 0000000..9e5b5e6
--- /dev/null
@@ -0,0 +1,1639 @@
+/* $XFree86: xc/lib/xtrans/Xtransmnx.c,v 3.3 1996/05/10 06:55:50 dawes Exp $ */
+
+/*
+Xtransmnx.c
+
+Created:       11 April 1994 by Philip Homburg <philip@cs.vu.nl>
+*/
+
+
+#include <stdlib.h>
+#include <sys/ioctl.h>
+#include <sys/nbio.h>
+#include <net/hton.h>
+#include <net/netlib.h>
+#include <net/gen/in.h>
+#include <net/gen/netdb.h>
+#include <net/gen/tcp.h>
+#include <net/gen/tcp_io.h>
+
+struct private
+{
+       int nonblocking;
+
+       int read_inprogress;
+       char *read_buffer;
+       size_t read_bufsize;
+       size_t read_size;
+       size_t read_offset;
+
+       int write_inprogress;
+       char *write_buffer;
+       size_t write_bufsize;
+       size_t write_size;
+       size_t write_offset;
+       int write_errno;
+
+       int listen_completed;
+       u16_t listen_port;
+       XtransConnInfo listen_list;
+};
+#define RD_BUFSIZE     1024
+#define WR_BUFSIZE     1024
+
+static XtransConnInfo listen_list= NULL;
+
+static XtransConnInfo alloc_ConnInfo(Xtransport *thistrans);
+static void free_ConnInfo(XtransConnInfo ciptr);
+static struct private *alloc_private(size_t rd_size, size_t wr_size);
+static void free_private(struct private *priv);
+static void read_cb(nbio_ref_t ref, int res, int err);
+static void write_cb(nbio_ref_t ref, int res, int err);
+static void listen_cb(nbio_ref_t ref, int res, int err);
+static int restart_listen(XtransConnInfo ciptr);
+
+#ifdef TRANS_CLIENT
+static XtransConnInfo
+TRANS(MnxTcpOpenCOTSClient) (thistrans, protocol, host, port)
+
+Xtransport *thistrans;
+char      *protocol;
+char      *host;
+char       *port;
+
+{
+       XtransConnInfo  ciptr;
+       char *tcp_device;
+       int s_errno;
+       int fd;
+       nbio_ref_t ref;
+
+
+       PRMSG(2, "MnxTcpOpenCOTSClient(%s,%s,%s)\n",
+               protocol, host, port);
+
+       if ((ciptr= alloc_ConnInfo(thistrans)) == NULL)
+       {
+               PRMSG(1,
+                       "MnxTcpOpenCOTSClient: alloc_ConnInfo failed\n",
+                       0, 0, 0);
+               return NULL;
+       }
+       if ((ciptr->priv= (char *)alloc_private(RD_BUFSIZE, WR_BUFSIZE)) ==
+               NULL)
+       {
+               PRMSG(1,
+                       "MnxTcpOpenCOTSClient: alloc_private() failed\n",
+                       0, 0, 0);
+               s_errno= errno;
+               free_ConnInfo(ciptr);
+               errno= s_errno;
+               return NULL;
+       }
+
+       if ((tcp_device= getenv("TCP_DEVICE")) == NULL)
+               tcp_device= TCP_DEVICE;
+       PRMSG(4, "MnxTcpOpenCOTSClient: tcp_device= '%s'\n",
+               tcp_device, 0, 0);
+
+       if ((fd= open(tcp_device, O_RDWR)) == -1)
+       {
+               PRMSG(1,
+                       "MnxTcpOpenCOTSClient: open '%s' failed: %s\n",
+                       tcp_device, strerror(errno), 0);
+               s_errno= errno;
+               free_ConnInfo(ciptr);
+               errno= s_errno;
+               return NULL;
+       }
+       ciptr->fd= fd;
+       ref.ref_ptr= ciptr;
+       nbio_register(fd);
+       nbio_setcallback(fd, ASIO_READ, read_cb, ref);
+       nbio_setcallback(fd, ASIO_WRITE, write_cb, ref);
+       return ciptr;
+}
+#endif /* TRANS_CLIENT */
+
+#ifdef TRANS_SERVER
+static XtransConnInfo
+TRANS(MnxTcpOpenCOTSServer) (thistrans, protocol, host, port)
+
+Xtransport *thistrans;
+char      *protocol;
+char      *host;
+char      *port;
+
+{
+       XtransConnInfo  ciptr;
+       char *tcp_device;
+       int s_errno;
+       int fd;
+       nbio_ref_t ref;
+
+
+       PRMSG(2, "MnxTcpOpenCOTSServer(%s,%s,%s)\n",
+               protocol, host, port);
+
+       if ((ciptr= alloc_ConnInfo(thistrans)) == NULL)
+       {
+               PRMSG(1,
+                       "MnxTcpOpenCOTSServer: alloc_ConnInfo failed\n",
+                       0, 0, 0);
+               return NULL;
+       }
+       if ((ciptr->priv= (char *)alloc_private(RD_BUFSIZE, WR_BUFSIZE)) ==
+               NULL)
+       {
+               PRMSG(1,
+                       "MnxTcpOpenCOTSServer: alloc_private() failed\n",
+                       0, 0, 0);
+               s_errno= errno;
+               free_ConnInfo(ciptr);
+               errno= s_errno;
+               return NULL;
+       }
+
+       if ((tcp_device= getenv("TCP_DEVICE")) == NULL)
+               tcp_device= TCP_DEVICE;
+       PRMSG(4, "MnxTcpOpenCOTSServer: tcp_device= '%s'\n",
+               tcp_device, 0, 0);
+
+       if ((fd= open(tcp_device, O_RDWR)) == -1)
+       {
+               PRMSG(1,
+                       "MnxTcpOpenCOTSServer: open '%s' failed: %s\n",
+                       tcp_device, strerror(errno), 0);
+               s_errno= errno;
+               free_ConnInfo(ciptr);
+               errno= s_errno;
+               return NULL;
+       }
+       PRMSG(5, "MnxTcpOpenCOTSServer: fd= '%d'\n", fd, 0, 0);
+       ciptr->fd= fd;
+       ref.ref_ptr= ciptr;
+       nbio_register(fd);
+       nbio_setcallback(fd, ASIO_IOCTL, listen_cb, ref);
+       return ciptr;
+}
+#endif /* TRANS_SERVER */
+
+#ifdef TRANS_CLIENT
+static XtransConnInfo
+TRANS(MnxTcpOpenCLTSClient) (thistrans, protocol, host, port)
+
+Xtransport *thistrans;
+char      *protocol;
+char      *host;
+char      *port;
+
+{
+       abort();
+}
+#endif /* TRANS_CLIENT */
+
+#ifdef TRANS_SERVER
+static XtransConnInfo
+TRANS(MnxTcpOpenCLTSServer) (thistrans, protocol, host, port)
+
+Xtransport *thistrans;
+char      *protocol;
+char      *host;
+char      *port;
+
+{
+       abort();
+}
+#endif /* TRANS_SERVER */
+
+#ifdef TRANS_REOPEN
+
+static XtransConnInfo
+TRANS(MnxTcpReopenCOTSServer) (thistrans, fd, port)
+
+Xtransport *thistrans;
+int       fd;
+char      *port;
+
+{
+    XtransConnInfo     ciptr;
+    int                        i;
+
+    PRMSG (2,
+       "MnxTcpReopenCOTSServer(%d, %s)\n", fd, port, 0);
+
+    abort();
+}
+
+static XtransConnInfo
+TRANS(MnxTcpReopenCLTSServer) (thistrans, fd, port)
+
+Xtransport *thistrans;
+int       fd;
+char      *port;
+
+{
+    XtransConnInfo     ciptr;
+    int                        i;
+
+
+    PRMSG (2,
+       "MnxTcpReopenCLTSServer(%d, %s)\n", fd, port, 0);
+
+    abort();
+}
+
+#endif /* TRANS_REOPEN */
+
+
+
+static int
+TRANS(MnxTcpSetOption) (ciptr, option, arg)
+
+XtransConnInfo         ciptr;
+int            option;
+int            arg;
+
+{
+       int flags;
+       struct private *priv;
+
+       PRMSG(2, "MnxTcpSetOption(%d,%d,%d)\n",
+               ciptr->fd, option, arg);
+
+       priv= (struct private *)ciptr->priv;
+       switch(option)
+       {
+       case TRANS_NONBLOCKING:
+               flags= fcntl(ciptr->fd, F_GETFD);
+               if (flags == -1)
+               {
+                       PRMSG(1,
+                       "MnxTcpSetOption: fcntl F_GETFD failed: %s\n",
+                               strerror(errno), 0, 0);
+                       return -1;
+               }
+               if (arg == 0)
+                       flags &= ~FD_ASYNCHIO;
+               else if (arg == 1)
+                       flags |= FD_ASYNCHIO;
+               else
+               {
+                       PRMSG(1,
+               "MnxTcpSetOption: bad arg for TRANS_NONBLOCKING: %d\n",
+                               arg, 0, 0);
+                       return -1;
+               }
+               if (fcntl(ciptr->fd, F_SETFD, flags) == -1)
+               {
+                       PRMSG(1,
+                       "MnxTcpSetOption: fcntl F_SETFD failed: %s\n",
+                               strerror(errno), 0, 0);
+                       return -1;
+               }
+               priv->nonblocking= arg;
+               return 0;
+       case TRANS_CLOSEONEXEC:
+               flags= fcntl(ciptr->fd, F_GETFD);
+               if (flags == -1)
+               {
+                       PRMSG(1,
+                       "MnxTcpSetOption: fcntl F_GETFD failed: %s\n",
+                               strerror(errno), 0, 0);
+                       return -1;
+               }
+               if (arg == 0)
+                       flags &= ~FD_CLOEXEC;
+               else if (arg == 1)
+                       flags |= FD_CLOEXEC;
+               else
+               {
+                       PRMSG(1,
+               "MnxTcpSetOption: bad arg for TRANS_CLOSEONEXEC: %d\n",
+                               arg, 0, 0);
+                       return -1;
+               }
+               if (fcntl(ciptr->fd, F_SETFD, flags) == -1)
+               {
+                       PRMSG(1,
+                       "MnxTcpSetOption: fcntl F_SETFD failed: %s\n",
+                               strerror(errno), 0, 0);
+                       return -1;
+               }
+               return 0;
+       default:
+               PRMSG(1, "MnxTcpSetOption: unknown option '%d'\n",
+                       option, 0, 0);
+               errno= EINVAL;
+               return -1;
+       }
+}
+
+
+#ifdef TRANS_SERVER
+static int
+TRANS(MnxTcpCreateListener) (ciptr, port)
+
+XtransConnInfo ciptr;
+char           *port;
+
+{
+       struct servent *servp;
+       tcpport_t num_port;
+       char *check;
+       nwio_tcpconf_t tcpconf;
+       nwio_tcpcl_t tcpcl;
+       int r, s_errno, flags;
+       struct private *priv;
+       struct sockaddr_in *addr;
+
+       PRMSG(2, "MnxTcpCreateListener(%d,%s)\n", ciptr->fd, port, 0);
+
+       priv= (struct private *)ciptr->priv;
+
+       if (port == NULL)
+               num_port= 0;
+       else
+       {
+               num_port= strtol(port, &check, 10);
+               num_port= htons(num_port);
+               if (check[0] == '\0')
+                       port= NULL;
+       }
+
+#ifdef X11_t
+       /*
+        * X has a well known port, that is transport dependent. It is easier
+        * to handle it here, than try and come up with a transport independent
+        * representation that can be passed in and resolved the usual way.
+        *
+        * The port that is passed here is really a string containing the
+        * idisplay from ConnectDisplay().
+        */
+       if (port == NULL)
+               num_port= htons(ntohs(num_port) + X_TCP_PORT);
+#endif
+       if (port != NULL)
+       {
+               if ((servp = getservbyname (port, "tcp")) == NULL)
+               {
+                       PRMSG(1,
+               "MnxTcpCreateListener: can't get service for %s\n",
+                               port, 0, 0);
+                       errno= EINVAL;
+                       return TRANS_CREATE_LISTENER_FAILED;
+               }
+               num_port= servp->s_port;
+       }
+
+       tcpconf.nwtc_flags= NWTC_SHARED | NWTC_UNSET_RA | NWTC_UNSET_RP;
+       if (num_port != 0)
+       {
+               tcpconf.nwtc_locport= num_port;
+               tcpconf.nwtc_flags |= NWTC_LP_SET;
+       }
+       else
+               tcpconf.nwtc_flags |= NWTC_LP_SEL;
+
+       if (ioctl(ciptr->fd, NWIOSTCPCONF, &tcpconf) == -1)
+       {
+               PRMSG(1,
+               "MnxTcpCreateListener: NWIOSTCPCONF failed: %s\n",
+                       strerror(errno),0, 0);
+               return TRANS_CREATE_LISTENER_FAILED;
+       }
+
+       if (ioctl(ciptr->fd, NWIOGTCPCONF, &tcpconf) == -1)
+       {
+               PRMSG(1,
+               "MnxTcpListen: NWIOGTCPCONF failed: %s\n",
+                       strerror(errno),0, 0);
+               return TRANS_CREATE_LISTENER_FAILED;
+       }
+
+       priv->listen_port= tcpconf.nwtc_locport;
+
+       if ((addr= (struct sockaddr_in *)xalloc(sizeof(struct sockaddr_in)))
+               == NULL)
+       {
+               PRMSG(1, "MnxTcpAccept: malloc failed\n", 0, 0, 0);
+               return TRANS_CREATE_LISTENER_FAILED;
+       }
+       addr->sin_family= AF_INET;
+       addr->sin_addr.s_addr= tcpconf.nwtc_locaddr;
+       addr->sin_port= tcpconf.nwtc_locport;
+       if (ciptr->addr)
+               xfree(ciptr->addr);
+       ciptr->addr= (char *)addr;
+       ciptr->addrlen= sizeof(struct sockaddr_in);
+
+       flags= fcntl(ciptr->fd, F_GETFD);
+       if (flags == -1)
+       {
+               PRMSG(1,
+               "MnxTcpCreateListener: fcntl F_GETFD failed: %s\n",
+                       strerror(errno), 0, 0);
+               return TRANS_CREATE_LISTENER_FAILED;
+       }
+       if (fcntl(ciptr->fd, F_SETFD, flags | FD_ASYNCHIO) == -1)
+       {
+               PRMSG(1,
+               "MnxTcpCreateListener: fcntl F_SETFD failed: %s\n",
+                       strerror(errno), 0, 0);
+               return TRANS_CREATE_LISTENER_FAILED;
+       }
+
+       tcpcl.nwtcl_flags= 0;
+       r= ioctl(ciptr->fd, NWIOTCPLISTEN, &tcpcl);
+       s_errno= errno;
+
+       if (fcntl(ciptr->fd, F_SETFD, flags) == -1)
+       {
+               PRMSG(1,
+               "MnxTcpCreateListener: fcntl F_SETFD failed: %s\n",
+                       strerror(errno), 0, 0);
+               return TRANS_CREATE_LISTENER_FAILED;
+       }
+
+       if (r == -1 && s_errno == EINPROGRESS)
+       {
+               nbio_inprogress(ciptr->fd, ASIO_IOCTL, 1 /* read */,
+                       1 /* write */, 0 /* exception */);
+               return 0;
+       }
+       if (r == 0)
+       {
+               priv->listen_completed= 1;
+               return 0;
+       }
+
+       errno= s_errno;
+       PRMSG(1, "MnxTcpCreateListener: NWIOTCPLISTEN failed: %s\n",
+               strerror(errno), 0, 0);
+       return TRANS_CREATE_LISTENER_FAILED;
+}
+#endif /* TRANS_SERVER */
+
+
+#ifdef TRANS_SERVER
+static int
+TRANS(MnxTcpResetListener) (ciptr)
+
+XtransConnInfo ciptr;
+{
+       PRMSG(2, "MnxTcpResetListener(%d)\n", ciptr->fd, 0, 0);
+       return TRANS_RESET_NOOP;
+}
+#endif /* TRANS_SERVER */
+
+#ifdef TRANS_SERVER
+static XtransConnInfo
+TRANS(MnxTcpAccept) (ciptr_listen, status)
+
+XtransConnInfo ciptr_listen;
+int           *status;
+
+{
+       XtransConnInfo  ciptr;
+       int s_errno;
+       int fd;
+       nbio_ref_t ref;
+       struct private *priv;
+       nwio_tcpconf_t tcpconf;
+       struct sockaddr_in *addr;
+
+       PRMSG(2, "MnxTcpAccept(%d,%p)\n", ciptr_listen->fd, status, 0);
+
+       priv= (struct private *)ciptr_listen->priv;
+       *status= TRANS_ACCEPT_MISC_ERROR;
+
+       if (!priv->listen_completed)
+       {
+               PRMSG(1, "MnxTcpAccept: listen is not completed\n",
+                       0, 0, 0);
+               *status= TRANS_ACCEPT_FAILED;
+               return NULL;
+       }
+       priv->listen_completed= 0;
+
+       if ((ciptr= alloc_ConnInfo(ciptr_listen->transptr)) == NULL)
+       {
+               PRMSG(1,
+                       "MnxTcpAccept: alloc_ConnInfo failed\n",
+                       0, 0, 0);
+               *status= TRANS_ACCEPT_BAD_MALLOC;
+               return NULL;
+       }
+       if ((ciptr->priv= (char *)alloc_private(RD_BUFSIZE, WR_BUFSIZE)) ==
+               NULL)
+       {
+               PRMSG(1,
+                       "MnxTcpAccept: alloc_private() failed\n",
+                       0, 0, 0);
+               s_errno= errno;
+               free_ConnInfo(ciptr);
+               errno= s_errno;
+               *status= TRANS_ACCEPT_BAD_MALLOC;
+               return NULL;
+       }
+
+       fd= dup(ciptr_listen->fd);
+       if (fd == -1)
+       {
+               s_errno= errno;
+               PRMSG(1, "MnxTcpAccept: dup failed: %s\n",
+                       strerror(errno), 0, 0);
+               free_ConnInfo(ciptr);
+               *status= TRANS_ACCEPT_FAILED;
+               return NULL;
+       }
+       if (restart_listen(ciptr_listen) == -1)
+       {
+               priv->listen_list= listen_list;
+               listen_list= ciptr_listen;
+               PRMSG(1, "MnxTcpAccept: unable to restart listen\n",
+                       0, 0, 0);
+       }
+       ciptr->fd= fd;
+       ref.ref_ptr= ciptr;
+       nbio_register(fd);
+       nbio_setcallback(fd, ASIO_WRITE, write_cb, ref);
+       nbio_setcallback(fd, ASIO_READ, read_cb, ref);
+
+       if (ioctl(ciptr->fd, NWIOGTCPCONF, &tcpconf) == -1)
+       {
+               PRMSG(1, "MnxTcpAccept: NWIOGTCPCONF failed: %s\n",
+                       strerror(errno),0, 0);
+               close(fd);
+               free_ConnInfo(ciptr);
+               *status= TRANS_ACCEPT_MISC_ERROR;
+               return NULL;
+       }
+       if ((addr= (struct sockaddr_in *)xalloc(sizeof(struct sockaddr_in)))
+               == NULL)
+       {
+               PRMSG(1, "MnxTcpAccept: malloc failed\n", 0, 0, 0);
+               close(fd);
+               free_ConnInfo(ciptr);
+               *status= TRANS_ACCEPT_BAD_MALLOC;
+               return NULL;
+       }
+       addr->sin_family= AF_INET;
+       addr->sin_addr.s_addr= tcpconf.nwtc_locaddr;
+       addr->sin_port= tcpconf.nwtc_locport;
+       if (ciptr->addr)
+               xfree(ciptr->addr);
+       ciptr->addr= (char *)addr;
+       ciptr->addrlen= sizeof(struct sockaddr_in);
+       if (*(u8_t *)&tcpconf.nwtc_remaddr == 127)
+       {
+               /* Make ConvertAddress return FamilyLocal */
+               addr->sin_addr.s_addr= tcpconf.nwtc_remaddr;
+       }
+
+       if ((addr= (struct sockaddr_in *)xalloc(sizeof(struct sockaddr_in)))
+               == NULL)
+       {
+               PRMSG(1, "MnxTcpConnect: malloc failed\n", 0, 0, 0);
+               close(fd);
+               free_ConnInfo(ciptr);
+               *status= TRANS_ACCEPT_BAD_MALLOC;
+               return NULL;
+       }
+       addr->sin_family= AF_INET;
+       addr->sin_addr.s_addr= tcpconf.nwtc_remaddr;
+       addr->sin_port= tcpconf.nwtc_remport;
+       ciptr->peeraddr= (char *)addr;
+       ciptr->peeraddrlen= sizeof(struct sockaddr_in);
+       *status= 0;
+       return ciptr;
+}
+#endif /* TRANS_SERVER */
+
+TRANS(MnxTcpConnect) (ciptr, host, port)
+
+XtransConnInfo         ciptr;
+char           *host;
+char           *port;
+
+{
+       struct hostent *hostp;
+       struct servent *servp;
+       char hostnamebuf[256];          /* tmp space */
+       tcpport_t num_port;
+       ipaddr_t num_addr;
+       char *check;
+       nwio_tcpconf_t tcpconf;
+       nwio_tcpcl_t tcpcl;
+       struct sockaddr_in *addr;
+
+       PRMSG(2, "MnxTcpConnect(%d,%s,%s)\n", ciptr->fd, host, port);
+
+       if (!host)
+       {
+               hostnamebuf[0] = '\0';
+               (void) TRANS(GetHostname) (hostnamebuf, sizeof hostnamebuf);
+               host = hostnamebuf;
+       }
+
+
+       num_port= strtol(port, &check, 10);
+       num_port= htons(num_port);
+       if (check[0] == '\0')
+               port= NULL;
+#ifdef X11_t
+       /*
+        * X has a well known port, that is transport dependent. It is easier
+        * to handle it here, than try and come up with a transport independent
+        * representation that can be passed in and resolved the usual way.
+        *
+        * The port that is passed here is really a string containing the
+        * idisplay from ConnectDisplay().
+        */
+       if (port == NULL)
+               num_port= htons(ntohs(num_port) + X_TCP_PORT);
+#endif
+
+       num_addr= inet_addr(host);
+       if (num_addr != -1)
+               host= NULL;
+
+       if (host != NULL)
+       {
+               if ((hostp = gethostbyname(host)) == NULL)
+               {
+                       PRMSG(1,
+                       "MnxTcpConnect: can't get address for %s\n",
+                               host, 0, 0);
+                       errno= EINVAL;
+                       return TRANS_CONNECT_FAILED;
+               }
+               if (hostp->h_addrtype != AF_INET)  /* is IP host? */
+               {
+                   PRMSG(1, "MnxTcpConnect: %s in not an INET host\n",
+                         host, 0, 0);
+                   errno= EINVAL;
+                   return TRANS_CONNECT_FAILED;
+               }
+               num_addr= *(ipaddr_t *)hostp->h_addr;
+       }
+
+       if (port != NULL)
+       {
+               if ((servp = getservbyname (port, "tcp")) == NULL)
+               {
+                       PRMSG(1,
+                       "MnxTcpConnect: can't get service for %s\n",
+                               port, 0, 0);
+                       errno= EINVAL;
+                       return TRANS_CONNECT_FAILED;
+               }
+               num_port= servp->s_port;
+       }
+
+       tcpconf.nwtc_flags= NWTC_EXCL | NWTC_LP_SEL | NWTC_SET_RA |
+               NWTC_SET_RP;
+       tcpconf.nwtc_remaddr= num_addr;
+       tcpconf.nwtc_remport= num_port;
+       if (ioctl(ciptr->fd, NWIOSTCPCONF, &tcpconf) == -1)
+       {
+               PRMSG(1, "MnxTcpConnect: NWIOSTCPCONF failed: %s\n",
+                       strerror(errno),0, 0);
+               return TRANS_CONNECT_FAILED;
+       }
+
+       tcpcl.nwtcl_flags= 0;
+       if (ioctl(ciptr->fd, NWIOTCPCONN, &tcpcl) == -1)
+       {
+               PRMSG(1, "MnxTcpConnect: connect failed: %s\n",
+                       strerror(errno),0, 0);
+               if (errno == ECONNREFUSED || errno == EINTR)
+                       return TRANS_TRY_CONNECT_AGAIN;
+               else
+                       return TRANS_CONNECT_FAILED;
+       }
+
+       if (ioctl(ciptr->fd, NWIOGTCPCONF, &tcpconf) == -1)
+       {
+               PRMSG(1, "MnxTcpConnect: NWIOGTCPCONF failed: %s\n",
+                       strerror(errno),0, 0);
+               return TRANS_CONNECT_FAILED;
+       }
+       if ((addr= (struct sockaddr_in *)xalloc(sizeof(struct sockaddr_in)))
+               == NULL)
+       {
+               PRMSG(1, "MnxTcpConnect: malloc failed\n", 0, 0, 0);
+               return TRANS_CONNECT_FAILED;
+       }
+       addr->sin_family= AF_INET;
+       addr->sin_addr.s_addr= tcpconf.nwtc_locaddr;
+       addr->sin_port= tcpconf.nwtc_locport;
+       ciptr->addr= (char *)addr;
+       ciptr->addrlen= sizeof(struct sockaddr_in);
+       if (*(u8_t *)&tcpconf.nwtc_remaddr == 127)
+       {
+               /* Make ConvertAddress return FamilyLocal */
+               addr->sin_addr.s_addr= tcpconf.nwtc_remaddr;
+       }
+
+       if ((addr= (struct sockaddr_in *)xalloc(sizeof(struct sockaddr_in)))
+               == NULL)
+       {
+               PRMSG(1, "MnxTcpConnect: malloc failed\n", 0, 0, 0);
+               return TRANS_CONNECT_FAILED;
+       }
+       addr->sin_family= AF_INET;
+       addr->sin_addr.s_addr= tcpconf.nwtc_remaddr;
+       addr->sin_port= tcpconf.nwtc_remport;
+       ciptr->peeraddr= (char *)addr;
+       ciptr->peeraddrlen= sizeof(struct sockaddr_in);
+
+       return 0;
+}
+
+static int
+TRANS(MnxTcpBytesReadable) (ciptr, pend)
+
+XtransConnInfo ciptr;
+BytesReadable_t *pend;
+
+{
+       struct private *priv;
+       int r;
+
+       PRMSG(2, "MnxTcpBytesReadable(%x,%d,%x)\n",
+               ciptr, ciptr->fd, pend);
+
+       *pend= 0;
+
+       priv= (struct private *)ciptr->priv;
+       if (priv->read_inprogress)
+       {
+               PRMSG(5, "MnxTcpBytesReadable: read inprogress, %d\n",
+                       *pend, 0, 0);
+               return *pend;
+       }
+       if (priv->read_offset < priv->read_size)
+       {
+               *pend= priv->read_size-priv->read_offset;
+               PRMSG(5, "MnxTcpBytesReadable: %d\n",
+                       *pend, 0, 0);
+               return *pend;
+       }
+       priv->read_offset= 0;
+       r= read(ciptr->fd, priv->read_buffer, priv->read_bufsize);
+       if (r >= 0)
+       {
+               if (r == 0)
+                       r= 1;   /* Signal EOF condition */
+
+               priv->read_size= r;
+               PRMSG(5, "MnxTcpBytesReadable: %d\n",
+                       *pend, 0, 0);
+               *pend= r;
+       }
+       else if (r == -1 && errno == EINPROGRESS)
+       {
+               priv->read_inprogress= 1;
+               nbio_inprogress(ciptr->fd, ASIO_READ, 1 /* read */,
+                       0 /* write */, 0 /* exception */);
+       }
+       else
+       {
+               PRMSG(1, "MnxTcpBytesReadable: read failed: %s\n",
+                       strerror(errno), 0, 0);
+               return -1;
+       }
+       PRMSG(5, "MnxTcpBytesReadable: %d\n", *pend, 0, 0);
+       return *pend;
+}
+
+
+static int
+TRANS(MnxTcpRead) (ciptr, buf, size)
+
+XtransConnInfo ciptr;
+char           *buf;
+int            size;
+
+{
+       int len, r, ret, s_errno;
+       int offset;
+       struct private *priv;
+       asio_fd_set_t fd_set;
+       fwait_t fw;
+
+       PRMSG(2, "MnxTcpRead(%d,%x,%d)\n", ciptr->fd, buf, size);
+
+       priv= (struct private *)ciptr->priv;
+       offset= 0;
+
+       if (priv->read_inprogress)
+       {
+               PRMSG(5, "MnxTcpRead: EAGAIN\n", 0, 0, 0);
+               errno= EAGAIN;
+               return -1;
+       }
+
+       /* Copy any data left in the buffer */
+       if (priv->read_offset < priv->read_size)
+       {
+               len= priv->read_size-priv->read_offset;
+               if (len > size-offset)
+                       len= size-offset;
+               PRMSG(5, "MnxTcpRead: copying %d bytes\n", len, 0, 0);
+
+               memcpy(buf+offset, priv->read_buffer + priv->read_offset,
+                       len);
+               offset += len;
+               priv->read_offset += len;
+               if (priv->read_offset < priv->read_size)
+                       return offset;
+       }
+
+       /* Try to read directly into the user's buffer. */
+       ret= 0;
+       s_errno= 0;
+       while(offset < size)
+       {
+               r= read(ciptr->fd, buf+offset, size-offset);
+               if (r == -1 && errno == EINPROGRESS)
+               {
+                       r= fcancel(ciptr->fd, ASIO_READ);
+                       if (r == -1)
+                               abort();
+                       ASIO_FD_ZERO(&fd_set);
+                       ASIO_FD_SET(ciptr->fd, ASIO_READ, &fd_set);
+                       fw.fw_flags= FWF_NONBLOCK;
+                       fw.fw_bits= fd_set.afds_bits;
+                       fw.fw_maxfd= ASIO_FD_SETSIZE;
+                       r= fwait(&fw);
+                       if (r == -1 || fw.fw_fd != ciptr->fd ||
+                               fw.fw_operation != ASIO_READ)
+                       {
+                               abort();
+                       }
+                       r= fw.fw_result;
+                       errno= fw.fw_errno;
+               }
+
+               if (r > 0)
+               {
+                       PRMSG(5, "MnxTcpRead: read %d bytes\n", r,
+                               0, 0);
+                       offset += r;
+                       continue;
+               }
+               else if (r == 0)
+               {
+                       PRMSG(5, "MnxTcpRead: read EOF\n", 0, 0, 0);
+                       break;
+               }
+               else
+               {
+                       if (errno == EINTR)
+                       {
+                               PRMSG(5, "MnxTcpRead: EINTR\n",
+                                       0, 0, 0);
+                               errno= EAGAIN;
+                       }
+                       else
+                       {
+                               PRMSG(1, "MnxTcpRead: read error %s\n",
+                                       strerror(errno), 0, 0);
+                       }
+                       s_errno= errno;
+                       ret= -1;
+                       break;
+               }
+       }
+       if (offset != 0)
+               ret= offset;
+
+       if (priv->read_offset != priv->read_size)
+               abort();
+       priv->read_offset= 0;
+       priv->read_size= 0;
+       if (priv->nonblocking)
+       {
+               r= read(ciptr->fd, priv->read_buffer, priv->read_bufsize);
+               if (r >= 0)
+               {
+                       PRMSG(5, "MnxTcpRead: buffered %d bytes\n",
+                               r, 0, 0);
+                       priv->read_size= r;
+               }
+               else if (r == -1 && errno == EINPROGRESS)
+               {
+                       priv->read_inprogress= 1;
+                       nbio_inprogress(ciptr->fd, ASIO_READ, 1 /* read */,
+                               0 /* write */, 0 /* exception */);
+               }
+               else
+               {
+                       PRMSG(1, "MnxTcpRead: read failed: %s\n",
+                               strerror(errno), 0, 0);
+               }
+       }
+       errno= s_errno;
+       return ret;
+}
+
+
+static int
+TRANS(MnxTcpWrite) (ciptr, buf, size)
+
+XtransConnInfo ciptr;
+char          *buf;
+int           size;
+
+{
+       int len, r, ret, s_errno;
+       int offset;
+       struct private *priv;
+       asio_fd_set_t fd_set;
+       fwait_t fw;
+
+       PRMSG(2, "MnxTcpWrite(%d,%x,%d)\n", ciptr->fd, buf, size);
+
+       priv= (struct private *)ciptr->priv;
+       offset= 0;
+
+       if (priv->write_errno)
+       {
+               PRMSG(5, "MnxTcpWrite: write_errno %d\n",
+                       priv->write_errno, 0, 0);
+               errno= priv->write_errno;
+               return -1;
+       }
+
+       if (priv->write_inprogress)
+       {
+               PRMSG(5, "MnxTcpWrite: EAGAIN\n", 0, 0, 0);
+               errno= EAGAIN;
+               return -1;
+       }
+
+       /* Try to write directly out of the user's buffer. */
+       ret= 0;
+       s_errno= 0;
+       while(offset < size)
+       {
+               r= write(ciptr->fd, buf+offset, size-offset);
+               if (r == -1 && errno == EINPROGRESS)
+               {
+                       r= fcancel(ciptr->fd, ASIO_WRITE);
+                       if (r == -1)
+                               abort();
+                       ASIO_FD_ZERO(&fd_set);
+                       ASIO_FD_SET(ciptr->fd, ASIO_WRITE, &fd_set);
+                       fw.fw_flags= FWF_NONBLOCK;
+                       fw.fw_bits= fd_set.afds_bits;
+                       fw.fw_maxfd= ASIO_FD_SETSIZE;
+                       r= fwait(&fw);
+                       if (r == -1 || fw.fw_fd != ciptr->fd ||
+                               fw.fw_operation != ASIO_WRITE)
+                       {
+                               abort();
+                       }
+                       r= fw.fw_result;
+                       errno= fw.fw_errno;
+               }
+               if (r > 0)
+               {
+                       PRMSG(5, "MnxTcpWrite: wrote %d bytes\n", r,
+                               0, 0);
+                       offset += r;
+                       continue;
+               }
+               else if (r == 0)
+                       abort();
+               else
+               {
+                       if (errno == EINTR)
+                       {
+                               PRMSG(5, "MnxTcpWrite: EINTR\n",
+                                       0, 0, 0);
+                               errno= EAGAIN;
+                       }
+                       else
+                       {
+                               PRMSG(1,
+                               "MnxTcpWrite: write error: %s\n",
+                                       strerror(errno), 0, 0);
+                       }
+                       s_errno= errno;
+                       ret= -1;
+                       break;
+               }
+       }
+
+       /* Copy any data to the buffer */
+       if (offset < size)
+       {
+               len= priv->write_bufsize;
+               if (len > size-offset)
+                       len= size-offset;
+               PRMSG(5, "MnxTcpWrite: copying %d bytes\n", len, 0, 0);
+
+               memcpy(priv->write_buffer, buf+offset, len);
+               offset += len;
+               priv->write_offset= 0;
+               priv->write_size= len;
+       }
+       if (offset != 0)
+               ret= offset;
+
+       while (priv->write_offset < priv->write_size)
+       {
+               r= write(ciptr->fd, priv->write_buffer+priv->write_offset,
+                       priv->write_size-priv->write_offset);
+               if (r > 0)
+               {
+                       PRMSG(5, "MnxTcpWrite: wrote %d bytes\n",
+                               r, 0, 0);
+                       priv->write_offset += r;
+                       continue;
+               }
+               else if (r == -1 && errno == EINPROGRESS)
+               {
+                       priv->write_inprogress= 1;
+                       nbio_inprogress(ciptr->fd, ASIO_WRITE, 0 /* read */,
+                               1 /* write */, 0 /* exception */);
+               }
+               else
+               {
+                       PRMSG(1, "MnxTcpWrite: write failed: %s\n",
+                               strerror(errno), 0, 0);
+                       priv->write_errno= errno;
+               }
+               break;
+       }
+
+       errno= s_errno;
+       return ret;
+}
+
+
+static int
+TRANS(MnxTcpReadv) (ciptr, buf, size)
+
+XtransConnInfo ciptr;
+struct iovec   *buf;
+int            size;
+
+{
+       int i, offset, total, len, r;
+
+       PRMSG(2, "MnxTcpReadv(%d,%x,%d)\n", ciptr->fd, buf, size);
+
+       /* Simply call read a number of times. */
+       total= 0;
+       offset= 0;
+       i= 0;
+       while(i<size)
+       {
+               PRMSG(5, "MnxTcpReadv: [%d] size %d-%d\n",
+                       i, buf[i].iov_len, offset);
+               if (offset >= buf[i].iov_len)
+               {
+                       offset= 0;
+                       i++;
+                       continue;
+               }
+               len= buf[i].iov_len-offset;
+               r= TRANS(MnxTcpRead)(ciptr, buf[i].iov_base+offset, len);
+               if (r == -1)
+               {
+                       if (errno == EAGAIN)
+                       {
+                               PRMSG(5,
+                               "MnxTcpReadv: read returned: %s\n",
+                                       strerror(errno), 0, 0);
+                       }
+                       else
+                       {
+                               PRMSG(1,
+                               "MnxTcpReadv: read failed: %s\n",
+                                       strerror(errno), 0, 0);
+                       }
+                       if (total != 0)
+                               return total;
+                       else
+                               return -1;
+               }
+               if (r == 0)
+                       break;
+               if (r > len)
+                       abort();
+               total += r;
+               offset += r;
+       }
+       return total;
+}
+
+static int
+TRANS(MnxTcpWritev) (ciptr, buf, size)
+
+XtransConnInfo         ciptr;
+struct iovec   *buf;
+int            size;
+
+{
+       int i, offset, total, len, r;
+
+       PRMSG(2, "MnxTcpWritev(%d,%x,%d)\n", ciptr->fd, buf, size);
+
+       /* Simply call write a number of times. */
+       total= 0;
+       offset= 0;
+       i= 0;
+       while(i<size)
+       {
+               if (offset >= buf[i].iov_len)
+               {
+                       offset= 0;
+                       i++;
+                       continue;
+               }
+               len= buf[i].iov_len-offset;
+               r= TRANS(MnxTcpWrite)(ciptr, buf[i].iov_base+offset, len);
+               if (r == -1)
+               {
+                       if (errno == EAGAIN)
+                       {
+                               PRMSG(5, "MnxTcpWritev: AGAIN\n",
+                                       0, 0, 0);
+                       }
+                       else
+                       {
+                               PRMSG(1,
+                               "MnxTcpWritev: write failed: %s\n",
+                                       strerror(errno), 0, 0);
+                       }
+                       if (total != 0)
+                               return total;
+                       else
+                               return -1;
+               }
+               if (r == 0 || r > len)
+                       abort();
+               total += r;
+               offset += r;
+       }
+       return total;
+}
+
+
+static int
+TRANS(MnxTcpDisconnect) (ciptr)
+
+XtransConnInfo ciptr;
+
+{
+       PRMSG(2, "MnxTcpDisconnect(%x,%d)\n", ciptr, ciptr->fd, 0);
+
+       return ioctl(ciptr->fd, NWIOTCPSHUTDOWN, NULL);
+}
+
+static int
+TRANS(MnxTcpClose) (ciptr)
+
+XtransConnInfo ciptr;
+
+{
+       XtransConnInfo list, t_ciptr;
+       struct private *priv;
+
+       PRMSG(2, "MnxTcpClose(%x,%d)\n", ciptr, ciptr->fd, 0);
+
+
+       if (listen_list)
+       {
+               list= listen_list;
+               listen_list= NULL;
+               while(list)
+               {
+                       t_ciptr= list;
+                       priv= (struct private *)t_ciptr->priv;
+                       list= priv->listen_list;
+                       if (t_ciptr == ciptr)
+                               continue;
+                       if (restart_listen(t_ciptr) == -1)
+                       {
+                               priv->listen_list= listen_list;
+                               listen_list= t_ciptr;
+                       }
+               }
+       }
+
+       free_private((struct private *)ciptr->priv);
+       nbio_unregister(ciptr->fd);
+       return close (ciptr->fd);
+}
+
+
+static XtransConnInfo
+alloc_ConnInfo(thistrans)
+Xtransport *thistrans;
+{
+       XtransConnInfo ciptr;
+
+       PRMSG(2, " alloc_ConnInfo(%p)\n", thistrans, 0, 0);
+
+       if ((ciptr= (XtransConnInfo) xalloc(sizeof(struct _XtransConnInfo)))
+               == NULL)
+       {
+               PRMSG(1, " alloc_ConnInfo: malloc failed\n", 0, 0, 0);
+               return NULL;
+       }
+       ciptr->transptr= thistrans;
+       ciptr->priv= NULL;
+       ciptr->flags= 0;
+       ciptr->fd= -1;
+       ciptr->port= NULL;
+       ciptr->family= AF_INET;
+       ciptr->addr= NULL;
+       ciptr->addrlen= 0;
+       ciptr->peeraddr= NULL;
+       ciptr->peeraddrlen= 0;
+       return ciptr;
+}
+
+static void
+free_ConnInfo(ciptr)
+XtransConnInfo ciptr;
+{
+       if (ciptr == NULL)
+               return;
+       free_private((struct private *)ciptr->priv);
+       xfree(ciptr);
+}
+
+static struct private *
+alloc_private(rd_size, wr_size)
+size_t rd_size;
+size_t wr_size;
+{
+       struct private *priv;
+       int s_errno;
+       char *buf;
+
+       PRMSG(2, ":alloc_private(%d, %d)\n", rd_size, wr_size, 0);
+
+       if ((priv= (struct private *)xalloc(sizeof(struct private))) == NULL)
+       {
+               PRMSG(1, ":alloc_private: malloc failed\n", 0, 0, 0);
+               return NULL;
+       }
+       priv->nonblocking= 0;
+       priv->read_inprogress= 0;
+       priv->read_buffer= NULL;
+       priv->read_bufsize= rd_size;
+       priv->read_size= 0;
+       priv->read_offset= 0;
+
+       if (rd_size != 0)
+       {
+               if ((buf= xalloc(rd_size)) == NULL)
+               {
+                       PRMSG(1, ":alloc_private: malloc failed\n", 0, 0, 0);
+                       s_errno= errno;
+                       free_private(priv);
+                       errno= s_errno;
+                       return NULL;
+               }
+               priv->read_buffer= buf;
+       }
+
+       priv->write_inprogress= 0;
+       priv->write_buffer= NULL;
+       priv->write_bufsize= rd_size;
+       priv->write_size= 0;
+       priv->write_offset= 0;
+       priv->write_errno= 0;
+
+       if (wr_size != 0)
+       {
+               if ((buf= xalloc(wr_size)) == NULL)
+               {
+                       PRMSG(1, ":alloc_private: malloc failed\n", 0, 0, 0);
+                       s_errno= errno;
+                       free_private(priv);
+                       errno= s_errno;
+                       return NULL;
+               }
+               priv->write_buffer= buf;
+       }
+
+       priv->listen_completed= 0;
+       priv->listen_port= 0;
+       priv->listen_list= NULL;
+
+       return priv;
+}
+
+static void
+free_private(priv)
+struct private *priv;
+{
+       if (priv == NULL)
+               return;
+       xfree(priv->read_buffer);
+       xfree(priv->write_buffer);
+       xfree(priv);
+}
+
+static void
+read_cb(ref, res, err)
+nbio_ref_t ref;
+int res;
+int err;
+{
+       XtransConnInfo ciptr;
+       struct private *priv;
+
+       PRMSG(2, ":read_cb(%x,%d,%d)\n", ref.ref_ptr, res, err);
+
+       ciptr= ref.ref_ptr;
+       priv= (struct private *)ciptr->priv;
+       if (res > 0)
+               priv->read_size= res;
+       priv->read_inprogress= 0;
+}
+
+static void
+write_cb(ref, res, err)
+nbio_ref_t ref;
+int res;
+int err;
+{
+       XtransConnInfo ciptr;
+       struct private *priv;
+       int r;
+
+       PRMSG(2, ":write_cb(%x,%d,%d)\n", ref.ref_ptr, res, err);
+
+       ciptr= ref.ref_ptr;
+       priv= (struct private *)ciptr->priv;
+       if (res > 0)
+               priv->write_offset += res;
+       else if (res == 0)
+               abort();
+       else
+       {
+               priv->write_errno= err;
+               return;
+       }
+       priv->write_inprogress= 0;
+
+       while (priv->write_offset < priv->write_size)
+       {
+               r= write(ciptr->fd, priv->write_buffer+priv->write_offset,
+                       priv->write_size-priv->write_offset);
+               if (r > 0)
+               {
+                       PRMSG(5, "MnxTcpWrite: wrote %d bytes\n",
+                               r, 0, 0);
+                       priv->write_offset += r;
+                       continue;
+               }
+               else if (r == -1 && errno == EINPROGRESS)
+               {
+                       priv->write_inprogress= 1;
+                       nbio_inprogress(ciptr->fd, ASIO_WRITE, 0 /* read */,
+                               1 /* write */, 0 /* exception */);
+               }
+               else
+               {
+                       PRMSG(1, "MnxTcpWrite: write failed: %s\n",
+                               strerror(errno), 0, 0);
+                       priv->write_errno= errno;
+               }
+               break;
+       }
+}
+
+static void
+listen_cb(ref, res, err)
+nbio_ref_t ref;
+int res;
+int err;
+{
+       XtransConnInfo ciptr;
+       struct private *priv;
+       struct sockaddr_in *addr;
+       nwio_tcpconf_t tcpconf;
+
+       PRMSG(2, ":listen_cb(%x,%d,%d)\n", ref.ref_ptr, res, err);
+
+       ciptr= ref.ref_ptr;
+       priv= (struct private *)ciptr->priv;
+       if (res == 0)
+       {
+               if (ioctl(ciptr->fd, NWIOGTCPCONF, &tcpconf) == -1)
+               {
+                       PRMSG(1,
+                       ":listen_cb: NWIOGTCPCONF failed: %s\n",
+                               strerror(errno),0, 0);
+                       return;
+               }
+               if ((addr= (struct sockaddr_in *)xalloc(sizeof(struct sockaddr_in)))
+                       == NULL)
+               {
+                       PRMSG(1, ":listen_cb: malloc failed\n", 0, 0, 0);
+                       return;
+               }
+               addr->sin_family= AF_INET;
+               addr->sin_addr.s_addr= tcpconf.nwtc_locaddr;
+               addr->sin_port= tcpconf.nwtc_locport;
+               if (ciptr->addr)
+                       xfree(ciptr->addr);
+               ciptr->addr= (char *)addr;
+               ciptr->addrlen= sizeof(struct sockaddr_in);
+               priv->listen_completed= 1;
+               return;
+       }
+       PRMSG(2, ":listen_cb: listen failed: %s\n", strerror(err), 0, 0);
+       if (restart_listen(ciptr) == -1)
+       {
+               priv->listen_list= listen_list;
+               listen_list= ciptr;
+       }
+}
+
+static int
+restart_listen(ciptr)
+XtransConnInfo ciptr;
+{
+       char *tcp_device;
+       nwio_tcpconf_t tcpconf;
+       nwio_tcpcl_t tcpcl;
+       int fd, r, s_errno, flags;
+       struct private *priv;
+       nbio_ref_t ref;
+
+       PRMSG(2, ":restart_listen(%d)\n", ciptr->fd, 0, 0);
+
+       nbio_unregister(ciptr->fd);
+
+       if ((tcp_device= getenv("TCP_DEVICE")) == NULL)
+               tcp_device= TCP_DEVICE;
+
+       if ((fd= open(tcp_device, O_RDWR)) == -1)
+       {
+               PRMSG(1, ":restart_listen: open '%s' failed: %s\n",
+                       tcp_device, strerror(errno), 0);
+               return -1;
+       }
+       PRMSG(5, ":restart_listen: fd= '%d'\n", fd, 0, 0);
+       if (fd != ciptr->fd)
+       {
+               if (dup2(fd, ciptr->fd) == -1)
+                       abort();        /* no way to recover */
+               close(fd);
+       }
+       fd= ciptr->fd;
+       ref.ref_ptr= ciptr;
+       nbio_register(fd);
+       nbio_setcallback(fd, ASIO_IOCTL, listen_cb, ref);
+
+       priv= (struct private *)ciptr->priv;
+
+       tcpconf.nwtc_flags= NWTC_SHARED | NWTC_UNSET_RA | NWTC_UNSET_RP;
+       tcpconf.nwtc_locport= priv->listen_port;
+       tcpconf.nwtc_flags |= NWTC_LP_SET;
+
+       if (ioctl(ciptr->fd, NWIOSTCPCONF, &tcpconf) == -1)
+       {
+               PRMSG(1,
+               ":restart_listen: NWIOSTCPCONF failed: %s\n",
+                       strerror(errno),0, 0);
+               return -1;
+       }
+
+       flags= fcntl(ciptr->fd, F_GETFD);
+       if (flags == -1)
+       {
+               PRMSG(1,
+               ":restart_listen: fcntl F_GETFD failed: %s\n",
+                       strerror(errno), 0, 0);
+               return -1;
+       }
+       if (fcntl(ciptr->fd, F_SETFD, flags | FD_ASYNCHIO) == -1)
+       {
+               PRMSG(1,
+               ":restart_listen: fcntl F_SETFD failed: %s\n",
+                       strerror(errno), 0, 0);
+               return -1;
+       }
+
+       tcpcl.nwtcl_flags= 0;
+       r= ioctl(ciptr->fd, NWIOTCPLISTEN, &tcpcl);
+       s_errno= errno;
+
+       if (fcntl(ciptr->fd, F_SETFD, flags) == -1)
+       {
+               PRMSG(1,
+               ":restart_listen: fcntl F_SETFD failed: %s\n",
+                       strerror(errno), 0, 0);
+               return -1;
+       }
+
+       if (r == -1 && s_errno == EINPROGRESS)
+       {
+               nbio_inprogress(ciptr->fd, ASIO_IOCTL, 1 /* read */,
+                       1 /* write */, 0 /* exception */);
+               return 0;
+       }
+       if (r == 0)
+       {
+               priv->listen_completed= 1;
+               return 0;
+       }
+       errno= s_errno;
+       PRMSG(1, ":restart_listen: NWIOTCPLISTEN failed: %s\n",
+               strerror(errno), 0, 0);
+       return -1;
+}
+
+
+Xtransport     TRANS(MnxINETFuncs) =
+{
+       /* Minix TCP Interface */
+       "inet",
+       0,
+#ifdef TRANS_CLIENT
+       TRANS(MnxTcpOpenCOTSClient),
+#endif /* TRANS_CLIENT */
+#ifdef TRANS_SERVER
+       TRANS(MnxTcpOpenCOTSServer),
+#endif /* TRANS_SERVER */
+#ifdef TRANS_CLIENT
+       TRANS(MnxTcpOpenCLTSClient),
+#endif /* TRANS_CLIENT */
+#ifdef TRANS_SERVER
+       TRANS(MnxTcpOpenCLTSServer),
+#endif /* TRANS_SERVER */
+#ifdef TRANS_REOPEN
+       TRANS(MnxTcpReopenCOTSServer),
+       TRANS(MnxTcpReopenCLTSServer),
+#endif
+       TRANS(MnxTcpSetOption),
+#ifdef TRANS_SERVER
+       TRANS(MnxTcpCreateListener),
+       TRANS(MnxTcpResetListener),
+       TRANS(MnxTcpAccept),
+#endif /* TRANS_SERVER */
+#ifdef TRANS_CLIENT
+       TRANS(MnxTcpConnect),
+#endif /* TRANS_CLIENT */
+       TRANS(MnxTcpBytesReadable),
+       TRANS(MnxTcpRead),
+       TRANS(MnxTcpWrite),
+       TRANS(MnxTcpReadv),
+       TRANS(MnxTcpWritev),
+       TRANS(MnxTcpDisconnect),
+       TRANS(MnxTcpClose),
+       TRANS(MnxTcpClose),
+};
+
+Xtransport     TRANS(MnxTCPFuncs) =
+{
+       /* Minix TCP Interface */
+       "tcp",
+       TRANS_ALIAS,
+#ifdef TRANS_CLIENT
+       TRANS(MnxTcpOpenCOTSClient),
+#endif /* TRANS_CLIENT */
+#ifdef TRANS_SERVER
+       TRANS(MnxTcpOpenCOTSServer),
+#endif /* TRANS_SERVER */
+#ifdef TRANS_CLIENT
+       TRANS(MnxTcpOpenCLTSClient),
+#endif /* TRANS_CLIENT */
+#ifdef TRANS_SERVER
+       TRANS(MnxTcpOpenCLTSServer),
+#endif /* TRANS_SERVER */
+#ifdef TRANS_REOPEN
+       TRANS(MnxTcpReopenCOTSServer),
+       TRANS(MnxTcpReopenCLTSServer),
+#endif
+       TRANS(MnxTcpSetOption),
+#ifdef TRANS_SERVER
+       TRANS(MnxTcpCreateListener),
+       TRANS(MnxTcpResetListener),
+       TRANS(MnxTcpAccept),
+#endif /* TRANS_SERVER */
+#ifdef TRANS_CLIENT
+       TRANS(MnxTcpConnect),
+#endif /* TRANS_CLIENT */
+       TRANS(MnxTcpBytesReadable),
+       TRANS(MnxTcpRead),
+       TRANS(MnxTcpWrite),
+       TRANS(MnxTcpReadv),
+       TRANS(MnxTcpWritev),
+       TRANS(MnxTcpDisconnect),
+       TRANS(MnxTcpClose),
+       TRANS(MnxTcpClose),
+};
diff --git a/Xserver/lib/xtrans/Xtransos2.c b/Xserver/lib/xtrans/Xtransos2.c
new file mode 100644 (file)
index 0000000..5e78170
--- /dev/null
@@ -0,0 +1,937 @@
+/* $XFree86: xc/lib/xtrans/Xtransos2.c,v 3.5 1997/01/28 10:53:32 dawes Exp $ */
+
+/*
+ * (c) Copyright 1996 by Sebastien Marineau and Holger Veit
+ *                     <marineau@genie.uottawa.ca>
+ *                      <Holger.Veit@gmd.de>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a 
+ * copy of this software and associated documentation files (the "Software"), 
+ * to deal in the Software without restriction, including without limitation 
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense, 
+ * and/or sell copies of the Software, and to permit persons to whom the 
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ * 
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL 
+ * HOLGER VEIT  BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF 
+ * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 
+ * SOFTWARE.
+ * 
+ * Except as contained in this notice, the name of Sebastien Marineau or Holger Veit shall not be
+ * used in advertising or otherwise to promote the sale, use or other dealings
+ * in this Software without prior written authorization from Holger Veit or Sebastien Marineau.
+ *
+ */
+
+/* Implementation of the OS/2 local pipe transport layer */
+
+#define INCL_DOSNMPIPES
+#define INCL_DOSPROCESS
+#define INCL_DOSERRORS
+#define INCL_DOSFILEMGR
+#undef BYTE
+#undef BOOL
+#include <os2.h>
+
+#ifdef XSERV_t
+extern HEV hPipeSem;
+BOOL init_server_pipes();
+#endif
+
+/*************************************************************************
+ * Independent Layer
+ *************************************************************************/
+#ifdef TRANS_CLIENT
+
+static XtransConnInfo
+TRANS(Os2OpenClient)(thistrans, protocol, host, port)
+Xtransport *thistrans;
+char *protocol;
+char *host;
+char *port;
+{
+       APIRET rc;
+       HFILE hfd,hServer;
+       ULONG action,byteWritten,State;
+       char pipename[256],clientname[256];
+        char server_string[256];
+        struct sockaddr *addr_name;
+        unsigned char pipe_len;
+       XtransConnInfo ciptr;
+        static int unique_id=0;
+        int i,namelen,try;
+
+       PRMSG(2,"Os2OpenClient(%s,%s,%s)\n",protocol,host,port);
+
+       /* test, whether the host is really local, i.e. either
+        * "os2" or "local"
+        */
+       if (strcmp(protocol,"os2") && strcmp(protocol,"local")) {
+               PRMSG (1,
+                       "Os2OpenClient: Cannot connect to non-local host %s\n",
+                       host, 0, 0);
+               return NULL;
+       }
+
+   /* make the pipename */
+
+    if (port && *port ) {
+       if( *port == '/' ) { /* A full pathname */
+               (void) sprintf(pipename, "\\PIPE\\X\\%s,", port);
+           } else {
+               (void) sprintf(pipename, "%s%s", "\\PIPE\\X\\xf86.", port);
+           }
+    } else {
+       (void) sprintf(pipename, "\\PIPE\\X\\xfree86"); }
+
+    PRMSG(5, "Os2OpenClient: Creating pipe %s\n",pipename, 0,0 );
+
+       /* make a connection entry */   
+       if( (ciptr=(XtransConnInfo)xcalloc(1,sizeof(struct _XtransConnInfo))) == NULL ) {
+               PRMSG(1,"Os2OpenClient: calloc(1,%d) failed\n",
+                       sizeof(struct _XtransConnInfo),0,0 );
+               return NULL;
+       }
+
+       /* open the pipe. Try ten times before giving up at 500ms intervals*/
+    try = 0;
+    do {
+       rc = DosOpen(pipename,&hServer, &action, 0,
+               FILE_NORMAL, FILE_OPEN,
+               OPEN_ACCESS_WRITEONLY | OPEN_SHARE_DENYWRITE,
+               (PEAOP2)NULL);
+        if(rc == 0) break;
+       if (try >=10) {
+               PRMSG(1,"Os2OpenClient: Open server pipe %s failed, rc=%d\n",
+                       pipename,rc,0 );
+               PRMSG(1,"\tProbable causes: either the XServer is not running, or has not started properly,\n",
+                       0,0,0 );
+               PRMSG(1,"\tor the DISPLAY variable is set incorrectly.\n",
+                       0,0,0 );
+               xfree(ciptr);
+               return NULL;
+           }
+       try ++;
+       DosSleep(500);
+       } while (rc != 0);
+
+/* OK, now we are talking to the server. Generate a unique pipe name and pass it to
+ * the server. Make the pipe and wait for server to connect */
+
+   sprintf(clientname,"\\PIPE\\X\\%d.%d",getpid(),unique_id++);
+   rc = DosCreateNPipe (clientname, &hfd,
+                       NP_NOINHERIT | NP_ACCESS_DUPLEX,
+                       1 | NP_NOWAIT | NP_TYPE_BYTE | NP_READMODE_BYTE,
+                       16384, 16384, 0);
+   if (rc != 0){
+        PRMSG(1, "Os2OpenClient: Unable to create pipe %s\n", pipename,0,0 );
+       DosClose(hfd);
+        pipe_len=0;
+        DosWrite(hServer,&pipe_len,1,&byteWritten);
+        DosClose(hServer);
+        xfree(ciptr);
+       return(NULL);
+    }
+
+ /* Connect to the pipe. */
+
+  rc = DosConnectNPipe (hfd);
+  if (rc != 0 && rc != ERROR_PIPE_NOT_CONNECTED)
+    {
+        PRMSG(1, "Os2OpenClient: Unable to connect to pipe %s\n", pipename,0,0 );
+        DosClose (hfd);
+        DosClose(hServer);
+        xfree(ciptr);
+        return (NULL);
+    }
+
+/* Now write name to server on hServer */
+        server_string[0]=(char) strlen(clientname)+1;
+        strcpy(&server_string[1],clientname);
+        rc = DosWrite(hServer,server_string,(ULONG)server_string[0]+1,&byteWritten);
+        if(rc != 0){  /* Could not write to server pipe? */
+           PRMSG(1, "Os2OpenClient: Error writing to server pipe, handle=%d, rc=%d, w=%d\n",
+                hServer,rc,byteWritten );
+           DosClose(hServer);
+           DosClose(hfd);
+           xfree(ciptr);
+           return(NULL);
+           }
+
+      PRMSG (5, "Os2OpenCLient: Wrote pipename %s to server; len %d written %d \n",
+        &server_string[1],server_string[0]+1,byteWritten);
+
+
+/* The server will respond by opening the pipe. Wait for that for 30 secs */
+
+        i=0;
+        DosSleep(50);  /* Give it time to catch up but minimize race condition*/
+        rc = DosConnectNPipe(hfd);
+        while((rc == ERROR_PIPE_NOT_CONNECTED)&&(i++<60)) {
+                DosSleep(500);
+                rc = DosConnectNPipe(hfd);
+                }
+
+        if(rc != 0){  /* Server has not responded! */
+           PRMSG(1, "Os2OpenClient: Timeout on wait for server response, handle=%d, rc=%d\n",hServer,rc,0 );
+           PRMSG(1, "\tProbable cause: the XServer has exited or crashed while the connection was being established\n",0,0,0 );
+           PRMSG(1, "\tor the XServer is too busy to respond.\n",0,0,0 );
+           DosClose(hServer);
+           DosClose(hfd);
+           xfree(ciptr);
+           return(NULL);
+           }
+
+/* OK, the server has connected! Fill-in the info and return */
+
+        DosClose(hServer);
+
+/* Last check: make sure client is connected! */
+
+        rc = DosQueryNPHState(hfd,&State);
+        if(rc != 0){  /* Client is not connected! */
+           PRMSG(1, "Os2OpenClient: Client pipe does not appear connected. rc=%d, h=%d\n",rc,hfd,0 );
+           PRMSG(1, "\tProbable cause: the XServer has just exited.\n",0,0,0 );
+           DosClose(hfd);
+           xfree(ciptr);
+           return(NULL);
+           }
+
+        namelen=sizeof(struct sockaddr);
+        if ((ciptr->addr = (char *) xalloc (namelen)) == NULL)
+          {
+                PRMSG (1, "Os2OpenClient: Can't allocate space for the addr\n",
+               0, 0, 0);
+                DosClose(hfd);
+                xfree(ciptr);
+                return(NULL);
+           }
+        ciptr->addrlen = namelen;
+        ((struct sockaddr *)ciptr->addr)->sa_family = AF_UNIX;
+        strcpy(((struct sockaddr *)ciptr->addr)->sa_data, "local");
+
+        if ((ciptr->peeraddr = (char *) xalloc (namelen)) == NULL)
+          {
+                PRMSG (1, "Os2OpenCLient: Can't allocate space for the addr\n",
+               0, 0, 0);
+                DosClose(hfd);
+                xfree(ciptr->addr);
+                xfree(ciptr);
+                return(NULL);
+           }
+       ciptr->peeraddrlen = namelen;
+       ((struct sockaddr *)ciptr->peeraddr)->sa_family = AF_UNIX;
+       strcpy (((struct sockaddr *)ciptr->peeraddr)->sa_data,"local");
+
+       PRMSG (5, "Os2OpenCLient: Filled in struct: len %d %d name %s\n",
+                ciptr->addrlen,ciptr->peeraddrlen,((struct sockaddr *)ciptr->peeraddr)->sa_data);
+
+
+        ciptr->index=hfd;
+        ciptr->family=AF_UNIX;
+        if((ciptr->fd=_imphandle(hfd))<0){
+           PRMSG(1, "Os2OpenClient: Could not import the pipe handle into EMX\n",0,0,0 );
+           PRMSG(1, "\tProbable cause: EMX has run out of free file handles.\n",0,0,0 );
+           DosClose(hfd);
+           xfree(ciptr->addr);
+           xfree(ciptr->peeraddr);
+           xfree(ciptr);
+           return(NULL);
+           }
+    PRMSG(5, "Os2OpenClient: pipe handle %d EMX handle %d\n",ciptr->index,ciptr->fd,0 );
+        fcntl(ciptr->fd,F_SETFL,O_NDELAY);
+        fcntl(ciptr->fd,F_SETFD,FD_CLOEXEC);
+       return ciptr;
+}
+#endif /* TRANS_CLIENT */
+
+#ifdef TRANS_SERVER
+static XtransConnInfo
+TRANS(Os2OpenServer)(thistrans, protocol, host, port)
+Xtransport *thistrans;
+char *protocol;
+char *host;
+char *port;
+{
+   APIRET rc;
+   HFILE hfd;
+   ULONG action;
+   char pipename[256];
+   struct sockaddr *addr_name;
+   XtransConnInfo ciptr;
+   int namelen;
+
+#ifdef XSERV_t
+    if (! init_server_pipes()) return(NULL);
+#endif
+
+    PRMSG(2,"Os2OpenServer(%s,%s,%s)\n",protocol,host,port);
+
+   if( (ciptr=(XtransConnInfo)xcalloc(1,sizeof(struct _XtransConnInfo))) == NULL )
+    {
+       PRMSG(1,"Os2OpenServer: xcalloc(1,%d) failed\n",
+             sizeof(struct _XtransConnInfo),0,0 );
+       return NULL;
+    }
+
+
+    if (port && *port ) {
+       if( *port == '/' ) { /* A full pathname */
+               (void) sprintf(pipename, "\\PIPE\\X\\%s", port);
+           } else {
+               (void) sprintf(pipename, "%s%s", "\\PIPE\\X\\xf86.", port);
+           }
+    } else {
+       (void) sprintf(pipename, "\\PIPE\\X\\xfree86");
+    }
+
+    PRMSG(5, "Os2OpenServer: Creating pipe %s\n",pipename, 0,0 );
+
+   rc = DosCreateNPipe (pipename, &hfd,
+                       NP_NOINHERIT | NP_ACCESS_INBOUND,
+                       1 | NP_NOWAIT | NP_TYPE_BYTE | NP_READMODE_BYTE,
+                       0, 8192, 0);
+   if (rc != 0){
+        PRMSG(1, "Os2OpenServer: Unable to create pipe %s, rc=%d\n", pipename,rc,0 );
+        PRMSG(1, "\tProbable cause: there is already another XServer running on display :%s\n",port,0,0 );
+       DosClose(hfd);
+        xfree(ciptr);
+       return(NULL);
+    }
+
+ /* Connect to the pipe. */
+
+  rc = DosConnectNPipe (hfd);
+  if (rc != 0 && rc != ERROR_PIPE_NOT_CONNECTED)
+    {
+        PRMSG(1, "Os2OpenServer: Unable to connect to pipe %s\n", pipename,0,0 );
+        DosClose (hfd);
+        xfree(ciptr);
+        return (NULL);
+    }
+
+/* Pipe is now connected and waiting for client connect */
+
+/*** Put in info ***/
+
+        namelen=sizeof(struct sockaddr);
+        if ((ciptr->addr = (char *) xalloc (namelen)) == NULL)
+          {
+                PRMSG (1, "Os2OpenServer: Can't allocate space for the addr\n",
+               0, 0, 0);
+                DosClose(hfd);
+                xfree(ciptr);
+                return(NULL);
+           }
+        ciptr->addrlen = namelen;
+        ((struct sockaddr *)ciptr->addr)->sa_family = AF_UNIX;
+        strcpy (((struct sockaddr *)ciptr->addr)->sa_data, "local");
+
+        if ((ciptr->peeraddr = (char *) xalloc (namelen)) == NULL)
+          {
+                PRMSG (1, "Os2OpenServer: Can't allocate space for the addr\n",
+               0, 0, 0);
+                DosClose(hfd);
+                xfree(ciptr->addr);
+                xfree(ciptr);
+                return(NULL);
+           }
+
+       ciptr->peeraddrlen = namelen;
+       ((struct sockaddr *)ciptr->peeraddr)->sa_family = AF_UNIX;
+       strcpy(((struct sockaddr *)ciptr->peeraddr)->sa_data,"local");
+     
+      PRMSG (5, "Os2OpenServer: Filled in struct: len %d %d name %s\n",
+                ciptr->addrlen,ciptr->peeraddrlen,((struct sockaddr *)ciptr->peeraddr)->sa_data);
+
+    ciptr->index=hfd; /* Save this for later use in this unused member of struct */
+    ciptr->flags=1;     /* Listener */
+    ciptr->family=AF_UNIX;
+
+    if((ciptr->fd=_imphandle(hfd))<0){
+       DosClose(hfd);
+       xfree(ciptr->addr);
+       xfree(ciptr->peeraddr);
+       xfree(ciptr);
+       return(NULL);
+       }
+    PRMSG(5, "Os2OpenServer: Pipe handle %d EMX handle %d",ciptr->index,ciptr->fd,0 );
+
+#ifdef XSERV_t
+/* Attach the pipe sem to the pipe. Use handle index as key */
+    rc = DosSetNPipeSem(ciptr->fd, (HSEM)hPipeSem, ciptr->fd);
+    if (rc){
+        PRMSG(1, "Os2OpenCOTSServer: Could not attach sem %d to pipe %d, rc=%d\n",
+                 hPipeSem,ciptr->fd,rc);
+        DosClose(ciptr->fd);
+        xfree(ciptr->addr);
+        xfree(ciptr->peeraddr);
+        xfree(ciptr);
+         return(NULL);
+        }
+#endif
+
+    fcntl(ciptr->fd,F_SETFL,O_NDELAY);
+    fcntl(ciptr->fd,F_SETFD,FD_CLOEXEC);
+    return(ciptr);
+}
+#endif /* TRANS_SERVER */
+
+#ifdef TRANS_CLIENT
+static XtransConnInfo
+TRANS(Os2OpenCLTSClient)(thistrans, protocol, host, port)
+Xtransport *thistrans;
+char *protocol;
+char *host;
+char *port;
+{
+       PRMSG(2,"Os2OpenCLTSClient(%s,%s,%s)\n",protocol,host,port);
+       return TRANS(Os2OpenClient)(thistrans, protocol, host, port);
+}
+#endif /* TRANS_CLIENT */
+
+#ifdef TRANS_CLIENT
+static XtransConnInfo
+TRANS(Os2OpenCOTSClient)(thistrans, protocol, host, port)
+Xtransport *thistrans;
+char *protocol;
+char *host;
+char *port;
+{
+       PRMSG(2,"Os2OpenCOTSClient(%s,%s,%s)\n",protocol,host,port);
+       return TRANS(Os2OpenClient)(thistrans, protocol, host, port);
+}
+#endif /* TRANS_CLIENT */
+
+
+#ifdef TRANS_SERVER
+static XtransConnInfo
+TRANS(Os2OpenCLTSServer)(thistrans, protocol, host, port)
+Xtransport *thistrans;
+char *protocol;
+char *host;
+char *port;
+{
+       PRMSG(2,"Os2OpenCLTSServer(%s,%s,%s)\n",protocol,host,port);
+       return TRANS(Os2OpenServer)(thistrans, protocol, host, port);
+}
+#endif /* TRANS_SERVER */
+
+
+#ifdef TRANS_SERVER
+static XtransConnInfo
+TRANS(Os2OpenCOTSServer)(thistrans, protocol, host, port)
+Xtransport *thistrans;
+char *protocol;
+char *host;
+char *port;
+{
+       PRMSG(2,"Os2OpenCOTSServer(%s,%s,%s)\n",protocol,host,port);
+       return TRANS(Os2OpenServer)(thistrans, protocol, host, port);
+}
+#endif /* TRANS_SERVER */
+
+
+#ifdef TRANS_REOPEN
+static XtransConnInfo
+TRANS(Os2ReopenCOTSServer)(thistrans, fd, port)
+Xtransport *thistrans;
+int       fd;
+char      *port;
+{
+
+    XtransConnInfo ciptr;
+    char addr_name[256];
+    int namelen;
+    
+    PRMSG(2,"Os2ReopenCOTSServer(%d,%s)\n", fd, port, 0);
+    
+    if( (ciptr=(XtransConnInfo)xcalloc(1,sizeof(struct _XtransConnInfo))) == NULL )
+    {
+       PRMSG(1,"Os2ReopenCOTSServer: xcalloc(1,%d) failed\n",
+             sizeof(struct _XtransConnInfo),0,0 );
+       return NULL;
+    }
+    
+        strcpy(addr_name,"local");
+        namelen=sizeof(addr_name);
+        if ((ciptr->addr = (char *) xalloc (namelen)) == NULL)
+          {
+                PRMSG (1, "Os2ReopenCOTSServer: Can't allocate space for the addr\n",
+               0, 0, 0);
+                xfree(ciptr);
+                return(NULL);
+           }
+
+        ciptr->addrlen = namelen;
+        memcpy (ciptr->addr, addr_name, ciptr->addrlen);
+        if ((ciptr->peeraddr = (char *) xalloc (namelen)) == NULL)
+          {
+                PRMSG (1, "Os2ReopenCOTSServer: Can't allocate space for the addr\n",
+               0, 0, 0);
+                xfree(ciptr);
+                return(NULL);
+           }
+
+       ciptr->peeraddrlen = namelen;
+       memcpy (ciptr->peeraddr,addr_name, ciptr->addrlen);
+
+    ciptr->fd = fd;
+    ciptr->family=AF_UNIX;
+    ciptr->flags=1;
+    PRMSG(1,"Os2ReopenCOTSServer: Filled-in info for handle %d on port %s.\n", fd, port, 0);
+
+    return(ciptr);
+}
+
+static XtransConnInfo
+TRANS(Os2ReopenCLTSServer)(thistrans, fd, port)
+Xtransport *thistrans;
+int       fd;
+char      *port;
+{
+    PRMSG(2,"Os2ReopenCLTSServer(%d,%s)\n", fd, port, 0);
+    return TRANS(Os2ReopenCOTSServer)(thistrans, fd, port);
+}
+#endif
+
+static
+TRANS(Os2SetOption)(ciptr, option, arg)
+XtransConnInfo ciptr;
+int option;
+int arg;
+{
+    PRMSG(2,"Os2SetOption(%d,%d,%d)\n",ciptr->fd,option,arg);
+    return -1;
+}
+
+#ifdef TRANS_SERVER
+
+static
+TRANS(Os2CreateListener)(ciptr, port)
+XtransConnInfo ciptr;
+char *port;
+{
+       PRMSG(2,"Os2CreateListener(%x->%d,%s)\n",ciptr,ciptr->fd,port);
+       return 0;
+}
+
+static XtransConnInfo
+TRANS(Os2Accept)(ciptr, status)
+XtransConnInfo ciptr;
+int           *status;
+{
+    XtransConnInfo     newciptr;
+    HFILE hClient;
+    unsigned char length;
+    ULONG action;
+    char clientname[256];
+    struct sockaddr *addr_name;
+    int in,namelen;
+    APIRET rc;
+
+
+    PRMSG(2,"Os2Accept(%x->%d)\n", ciptr, ciptr->fd,0);
+    if( (newciptr=(XtransConnInfo)xcalloc(1,sizeof(struct _XtransConnInfo)))==NULL )
+    {
+       PRMSG(1,"Os2Accept: xcalloc(1,%d) failed\n",
+             sizeof(struct _XtransConnInfo),0,0 );
+       *status = TRANS_ACCEPT_BAD_MALLOC;
+       return NULL;
+    }
+
+/* Read in length of client pipe name. If fails, then reset server pipe */
+    if((in=read(ciptr->fd,&length,1))<=0){
+        PRMSG(2,"Os2Accept: Error reading incoming connection, in=%d, error=%d\n",
+             in,errno,0 );
+       *status = TRANS_ACCEPT_MISC_ERROR;
+        xfree(newciptr);
+        rc = DosDisConnectNPipe(ciptr->fd);
+        rc = DosConnectNPipe (ciptr->fd);
+        if (rc != 0 && rc != ERROR_PIPE_NOT_CONNECTED)
+        {
+                PRMSG(1, "Os2Accept: Unable to reconnect server pipe %d\n", ciptr->fd,0,0 );
+                }
+       return NULL;
+        }
+       PRMSG(5, "Os2Accept: Bytes to read for name: %d\n",length,0,0 );
+
+
+/* Check length for valid length ?? */
+
+/* Now read in length bytes from pipe for client pipe name */
+    if((in=read(ciptr->fd,clientname,length))<=0){
+        PRMSG(2,"Os2Accept: Error reading incoming connection, in=%d, error=%d\n",
+             in,errno,0 );
+       *status = TRANS_ACCEPT_MISC_ERROR;
+        xfree(newciptr);
+        rc = DosDisConnectNPipe(ciptr->fd);
+        rc = DosConnectNPipe (ciptr->fd);
+        if (rc != 0 && rc != ERROR_PIPE_NOT_CONNECTED)
+        {
+                PRMSG(1, "Os2Accept: Unable to reconnect server pipe %d\n", ciptr->fd,0,0 );
+                }
+       return NULL;
+        }
+    clientname[length]='\0';
+    PRMSG(5, "Os2Accept: Server name %s length %d\n",clientname,length,0 );
+
+
+/* Now we have the client pipe name. Open it with DosOpen  */
+
+     rc = DosOpen(clientname,&hClient, &action, 0,
+          FILE_NORMAL, FILE_OPEN,
+          OPEN_FLAGS_NOINHERIT | OPEN_ACCESS_READWRITE | OPEN_SHARE_DENYREADWRITE,
+          (PEAOP2)NULL);
+
+     PRMSG(5, "Os2Accept: Open pipe %s, handle = %d, rc=%d\n",clientname,hClient,rc );
+
+       if (rc) {
+           PRMSG(1,"Os2Accept: Open pipe %s to client failed, rc=%d\n",
+           clientname,rc,0 );
+            PRMSG(1, "\tProbable cause: the client has exited or timed-out.\n",0,0,0 );
+            xfree(newciptr);
+            rc = DosDisConnectNPipe(ciptr->fd);
+            rc = DosConnectNPipe (ciptr->fd);
+            if (rc != 0 && rc != ERROR_PIPE_NOT_CONNECTED)
+               {
+                   PRMSG(1, "Os2Accept: Unable to reconnect server pipe %d\n", ciptr->fd,0,0 );
+                   }
+           return NULL;
+            }
+
+        rc = DosSetNPHState (hClient, NP_NOWAIT | NP_READMODE_BYTE);
+        if (rc != 0)
+        {
+            PRMSG(1,"Os2Accept: Could not set pipe %s to non-blocking mode, rc=%d\n",
+           hClient,rc,0 );
+            xfree(newciptr);
+            rc = DosDisConnectNPipe(ciptr->fd);
+            rc = DosConnectNPipe (ciptr->fd);
+            if (rc != 0 && rc != ERROR_PIPE_NOT_CONNECTED)
+               {
+                   PRMSG(1, "Os2Accept: Unable to reconnect server pipe %d\n", ciptr->fd,0,0 );
+                   }
+           return NULL;
+            }
+
+/* OK, we seem to be well connected to client. Now disconnect server pipe and put again in listen */
+
+         rc = DosDisConnectNPipe(ciptr->fd);
+         rc = DosConnectNPipe (ciptr->fd);
+       PRMSG(5, "Os2Accept: Reconnecting server pipe %d, rc = %d\n",ciptr->fd,rc,0 );
+
+         if (rc != 0 && rc != ERROR_PIPE_NOT_CONNECTED)
+         {
+              PRMSG(1, "Os2Accept: Unable to reconnect server pipe %d\n", ciptr->fd,0,0 );
+              }  /* Consider this non-fatal for present connection */
+/* And finally fill-in info in newciptr */
+
+        namelen=sizeof(struct sockaddr);
+        if ((newciptr->addr = (char *) xalloc (namelen)) == NULL)
+          {
+                PRMSG (1, "Os2Accept: Can't allocate space for the addr\n",
+               0, 0, 0);
+                DosClose(hClient);
+                xfree(newciptr);
+                return(NULL);
+           }
+
+        newciptr->addrlen = namelen;
+        ((struct sockaddr *)newciptr->addr)->sa_family = AF_UNIX;
+        strcpy (((struct sockaddr *)newciptr->addr)->sa_data, "local");
+
+        if ((newciptr->peeraddr = (char *) xalloc (namelen)) == NULL)
+          {
+                PRMSG (1, "Os2Accept: Can't allocate space for the addr\n",
+               0, 0, 0);
+                DosClose(hClient);
+                xfree(ciptr->addr);
+                xfree(newciptr);
+                return(NULL);
+           }
+
+       newciptr->peeraddrlen = namelen;
+       ((struct sockaddr *)newciptr->peeraddr)->sa_family = AF_UNIX;
+       strcpy (((struct sockaddr *)newciptr->peeraddr)->sa_data, "local");
+
+      PRMSG (5, "Os2Accept: Filled in struct: len %d %d name %s\n",
+                newciptr->addrlen,newciptr->peeraddrlen,newciptr->peeraddr);
+
+
+        newciptr->index=hClient;
+        newciptr->family=AF_UNIX;
+        if((newciptr->fd=_imphandle(hClient))<0){
+           PRMSG(1,"Os2Accept: Could not import pipe %d into EMX, errno=%d\n",
+           hClient,errno,0 );
+           PRMSG(1, "\tProbable cause: EMX has run out of file handles.\n",0,0,0 );
+           DosClose(hClient);
+           xfree(newciptr->addr);
+           xfree(newciptr->peeraddr);
+           xfree(newciptr);
+           return(NULL);
+           }
+    PRMSG(5, "Os2Accept: Pipe handle %d EMX handle %d",newciptr->index,newciptr->fd,0 );
+
+#ifdef XSERV_t
+/* Attach the pipe sem to the pipe. Use handle index as key */
+    rc = DosSetNPipeSem(newciptr->fd, (HSEM)hPipeSem, newciptr->fd);
+    if (rc){
+        PRMSG(1, "Os2OpenCOTSServer: Could not attach sem %d to pipe %d, rc=%d\n",
+                 hPipeSem,newciptr->fd,rc);
+        DosClose(newciptr->fd);
+        xfree(newciptr->addr);
+        xfree(newciptr->peeraddr);
+        xfree(newciptr);
+         return(NULL);
+        }
+#endif
+
+    fcntl(ciptr->fd,F_SETFL,O_NDELAY);
+    fcntl(ciptr->fd,F_SETFD,FD_CLOEXEC);
+    *status=0;
+    return newciptr;
+}
+
+#endif /* TRANS_SERVER */
+
+#ifdef TRANS_CLIENT
+
+static
+TRANS(Os2Connect)(ciptr, host, port)
+XtransConnInfo ciptr;
+char *host;
+char *port;
+{
+    PRMSG(2,"Os2Connect(%x->%d,%s)\n", ciptr, ciptr->fd, port);
+    return 0;
+}
+
+#endif /* TRANS_CLIENT */
+
+static int
+TRANS(Os2BytesReadable)(ciptr, pend )
+XtransConnInfo ciptr;
+BytesReadable_t *pend;
+{
+   ULONG rc, state, nread;
+  AVAILDATA avail;
+  char buffer;
+
+  PRMSG(2,"Os2BytesReadable(%x->%d,%x)\n", ciptr, ciptr->fd, pend);
+
+  rc = DosPeekNPipe (ciptr->fd, &buffer, 0, &nread, &avail, &state);
+  if (rc != 0)
+    {
+      errno = EPIPE;
+      *pend = 0;
+      return -1;
+    }
+  if (state == NP_STATE_CLOSING)
+     {
+        errno = EPIPE;
+        *pend = 0;
+        return -1;
+      }
+  errno = 0;
+  *pend = avail.cbpipe;
+  return 0;
+}
+
+static int
+TRANS(Os2Read)(ciptr, buf, size)
+XtransConnInfo ciptr;
+char *buf;
+int size;
+{
+    int ret;
+    APIRET rc;
+    ULONG ulRead;
+    PRMSG(2,"Os2Read(%d,%x,%d)\n", ciptr->fd, buf, size );
+    errno = 0;
+    rc = DosRead(ciptr->fd, buf, size, &ulRead);
+    if (rc == 0){
+        ret = ulRead;
+        }
+    else if ((rc == 232) || (rc == 231)){
+        errno = EAGAIN;
+        ret = -1;
+        }
+    else if (rc == 6){
+        errno = EBADF;
+        ret = -1;
+        }
+     else if ((rc == 109) || (rc == 230) || (rc == 233)){
+        errno = EPIPE;
+       ret = -1;
+        }
+    else {
+           PRMSG(2,"Os2Read: Unknown return code from DosRead, fd %d rc=%d\n", ciptr->fd,rc,0 );
+           errno = EINVAL;
+           ret = -1;
+           }
+    return (ret);
+}
+
+static int
+TRANS(Os2Write)(ciptr, buf, size)
+XtransConnInfo ciptr;
+char *buf;
+int size;
+{
+    int ret;
+    APIRET rc;
+    ULONG nWritten;
+    PRMSG(2,"Os2Write(%d,%x,%d)\n", ciptr->fd, buf, size );
+    rc = DosWrite(ciptr->fd, buf, size, &nWritten);
+    if (rc == 0){
+         ret = nWritten;
+         if(nWritten == 0) { 
+                 errno=EAGAIN;
+                 ret = -1;
+                 }
+         }
+    else if ((rc == 39) || (rc == 112)){
+        errno = EAGAIN;
+        ret = -1;
+        }
+    else if ((rc == 109) || (rc == 230) || (rc == 233)){
+        errno = EPIPE;
+        ret = -1;
+        }
+    else if (rc == 6){
+         errno=EBADF;
+         ret = -1;
+         }
+    else {
+        PRMSG(2,"(Os2Write)Unknown return code from DosWrite, fd %d rc=%d\n", ciptr->fd,rc,0 );
+        errno = EINVAL;
+        ret = -1;
+        }
+    return (ret);
+}
+
+static int
+TRANS(Os2Readv)(ciptr, buf, size)
+XtransConnInfo         ciptr;
+struct iovec   *buf;
+int            size;
+{
+    int ret;
+    PRMSG(2,"Os2Readv(%d,%x,%d)\n", ciptr->fd, buf, size );
+    ret = READV(ciptr,buf,size);
+    if ((ret <0) && (errno == EINVAL)) errno = EPIPE;
+    return (ret);
+}
+
+static int
+TRANS(Os2Writev)(ciptr, buf, size)
+XtransConnInfo         ciptr;
+struct iovec   *buf;
+int            size;
+{
+    int ret;
+    PRMSG(2,"Os2Writev(%d,%x,%d)\n", ciptr->fd, buf, size );
+    ret = WRITEV(ciptr,buf,size);
+    if ((ret <0) && (errno == EINVAL)) errno = EPIPE;
+    if ((ret <0) && (errno == ENOSPC)) errno = EAGAIN;
+    return (ret);
+}
+
+static int
+TRANS(Os2Disconnect)(ciptr)
+XtransConnInfo ciptr;
+{
+    PRMSG(2,"Os2Disconnect(%x->%d)\n", ciptr, ciptr->fd, 0);
+    return 0;
+}
+
+static int
+TRANS(Os2Close)(ciptr)
+XtransConnInfo ciptr;
+{
+    int ret;
+    PRMSG(2,"Os2Close(%x->%d)\n", ciptr, ciptr->fd ,0);
+    ret=close(ciptr->fd);
+    return ret;
+}
+
+static int
+TRANS(Os2CloseForCloning)(ciptr)
+XtransConnInfo ciptr;
+{
+    int ret;
+
+    PRMSG(2,"Os2CloseForCloning(%x->%d)\n", ciptr, ciptr->fd ,0);
+    ret=close(ciptr->fd);
+    return ret;
+}
+
+
+Xtransport     TRANS(OS2LocalFuncs) = {
+       /* Local Interface */
+       "local",
+       TRANS_LOCAL,
+#ifdef TRANS_CLIENT
+       TRANS(Os2OpenCOTSClient),
+#endif /* TRANS_CLIENT */
+#ifdef TRANS_SERVER
+       TRANS(Os2OpenCOTSServer),
+#endif /* TRANS_SERVER */
+#ifdef TRANS_CLIENT
+       TRANS(Os2OpenCLTSClient),
+#endif /* TRANS_CLIENT */
+#ifdef TRANS_SERVER
+       TRANS(Os2OpenCLTSServer),
+#endif /* TRANS_SERVER */
+#ifdef TRANS_REOPEN
+       TRANS(Os2ReopenCOTSServer),
+       TRANS(Os2ReopenCLTSServer),
+#endif
+       TRANS(Os2SetOption),
+#ifdef TRANS_SERVER
+       TRANS(Os2CreateListener),
+       NULL,                  /* ResetListener */
+       TRANS(Os2Accept),
+#endif /* TRANS_SERVER */
+#ifdef TRANS_CLIENT
+       TRANS(Os2Connect),
+#endif /* TRANS_CLIENT */
+       TRANS(Os2BytesReadable),
+       TRANS(Os2Read),
+       TRANS(Os2Write),
+       TRANS(Os2Readv),
+       TRANS(Os2Writev),
+       TRANS(Os2Disconnect),
+       TRANS(Os2Close),
+       TRANS(Os2CloseForCloning),
+};
+
+#ifdef XSERV_t
+/* This function is used in the server to initialize the semaphore used with pipes */
+
+BOOL init_server_pipes()
+{
+   static BOOL first_time=TRUE;
+   ULONG rc;
+
+   if(first_time){
+        rc = DosCreateEventSem(NULL, &hPipeSem,DC_SEM_SHARED,FALSE);
+        if (rc){
+           PRMSG(1,"Os2OpenListener (init_server_pipes): Could not create pipe semaphore, rc=%d\n",
+                rc,0,0);
+           return(FALSE);
+           }
+     first_time=FALSE;
+     }
+return(TRUE);
+}
+#endif  /* XSERV_t */
diff --git a/Xserver/lib/xtrans/Xtranssock.c b/Xserver/lib/xtrans/Xtranssock.c
new file mode 100644 (file)
index 0000000..40696aa
--- /dev/null
@@ -0,0 +1,2012 @@
+/* $XConsortium: Xtranssock.c /main/58 1996/12/04 10:22:50 lehors $ */
+/* $XFree86: xc/lib/xtrans/Xtranssock.c,v 3.25.2.4 1998/02/01 16:04:34 robin Exp $ */
+/*
+
+Copyright (c) 1993, 1994  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be included
+in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR
+OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall
+not be used in advertising or otherwise to promote the sale, use or
+other dealings in this Software without prior written authorization
+from the X Consortium.
+
+*/
+
+/* Copyright (c) 1993, 1994 NCR Corporation - Dayton, Ohio, USA
+ *
+ * All Rights Reserved
+ *
+ * Permission to use, copy, modify, and distribute this software and its
+ * documentation for any purpose and without fee is hereby granted, provided
+ * that the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the name NCR not be used in advertising
+ * or publicity pertaining to distribution of the software without specific,
+ * written prior permission.  NCR makes no representations about the
+ * suitability of this software for any purpose.  It is provided "as is"
+ * without express or implied warranty.
+ *
+ * NCR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN
+ * NO EVENT SHALL NCR BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
+ * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
+ * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
+ * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include <ctype.h>
+#ifdef XTHREADS
+#include <X11/Xthreads.h>
+#endif
+#ifndef WIN32
+
+#if defined(TCPCONN) || defined(UNIXCONN)
+#include <netinet/in.h>
+#else
+#ifdef ESIX
+#include <lan/in.h>
+#endif
+#endif
+#if defined(TCPCONN) || defined(UNIXCONN)
+#define X_INCLUDE_NETDB_H
+#define XOS_USE_NO_LOCKING
+#include <X11/Xos_r.h>
+#endif
+
+#ifdef UNIXCONN
+#ifndef X_NO_SYS_UN
+#ifndef Lynx
+#include <sys/un.h>
+#else
+#include <un.h>
+#endif
+#endif
+#include <sys/stat.h>
+#endif
+
+#if defined(hpux) || defined(__EMX__)
+#define NO_TCP_H
+#endif /* hpux */
+#ifdef MOTOROLA
+#ifdef SYSV
+#define NO_TCP_H
+#endif /* SYSV */
+#endif /* MOTOROLA */
+#ifndef NO_TCP_H
+#ifdef __osf__
+#include <sys/param.h>
+#endif /* osf */
+#if defined(__NetBSD__) || defined(__OpenBSD__) || defined(__FreeBSD__) 
+#include <machine/endian.h>
+#endif /* __NetBSD__ || __OpenBSD__ || __FreeBSD__ */
+#include <netinet/tcp.h>
+#endif /* !NO_TCP_H */
+#include <sys/ioctl.h>
+#if defined(SVR4) && !defined(SCO325)
+#include <sys/filio.h>
+#endif
+#if (defined(i386) && defined(SYSV)) || defined(_SEQUENT_)
+#if !defined(_SEQUENT_) && !defined(ESIX) && !defined(sco)
+#include <net/errno.h>
+#endif /* _SEQUENT_  || ESIX  || SCO */
+#if !defined(ISC) || !defined(I_NREAD) || defined(SCO325)
+#include <sys/stropts.h>
+#endif
+#endif /* i386 && SYSV || _SEQUENT_ */
+
+#else /* !WIN32 */
+
+#include <X11/Xwinsock.h>
+#include <X11/Xw32defs.h>
+#undef close
+#define close closesocket
+#define ECONNREFUSED WSAECONNREFUSED
+#define EADDRINUSE WSAEADDRINUSE
+#define EPROTOTYPE WSAEPROTOTYPE
+#undef EWOULDBLOCK
+#define EWOULDBLOCK WSAEWOULDBLOCK
+#undef EINTR
+#define EINTR WSAEINTR
+#define X_INCLUDE_NETDB_H
+#define XOS_USE_MTSAFE_NETDBAPI
+#include <X11/Xos_r.h>
+#endif /* WIN32 */
+
+#if defined(SO_DONTLINGER) && defined(SO_LINGER)
+#undef SO_DONTLINGER
+#endif
+
+#if defined(__EMX__)
+#if defined(NOT_EMX09A)
+static int IBMsockInit = 0;
+#define SocketInitOnce()\
+    if (!IBMsockInit) {\
+       sock_init();\
+       IBMsockInit = 1;\
+    }
+#undef EINTR
+#define EINTR SOCEINTR
+#undef EINVAL
+#define EINVAL SOCEINVAL
+#undef errno
+#define errno sock_errno()
+#undef close
+#define close soclose
+#undef ioctl
+#define ioctl sockioctl
+#else
+#define SocketInitOnce() /**/
+#endif
+/* this is still not there */
+#define SOCKET int
+#else
+/* others don't need this */
+#define SocketInitOnce() /**/
+#endif
+
+#define MIN_BACKLOG 128
+#ifdef SOMAXCONN
+#if SOMAXCONN > MIN_BACKLOG
+#define BACKLOG SOMAXCONN
+#endif
+#endif
+#ifndef BACKLOG
+#define BACKLOG MIN_BACKLOG
+#endif
+/*
+ * This is the Socket implementation of the X Transport service layer
+ *
+ * This file contains the implementation for both the UNIX and INET domains,
+ * and can be built for either one, or both.
+ *
+ */
+
+typedef struct _Sockettrans2dev {      
+    char       *transname;
+    int                family;
+    int                devcotsname;
+    int                devcltsname;
+    int                protocol;
+} Sockettrans2dev;
+
+static Sockettrans2dev Sockettrans2devtab[] = {
+#ifdef TCPCONN
+    {"inet",AF_INET,SOCK_STREAM,SOCK_DGRAM,0},
+    {"tcp",AF_INET,SOCK_STREAM,SOCK_DGRAM,0},
+#endif /* TCPCONN */
+#ifdef UNIXCONN
+    {"unix",AF_UNIX,SOCK_STREAM,SOCK_DGRAM,0},
+#if !defined(LOCALCONN)
+    {"local",AF_UNIX,SOCK_STREAM,SOCK_DGRAM,0},
+#endif /* !LOCALCONN */
+#endif /* UNIXCONN */
+};
+
+#define NUMSOCKETFAMILIES (sizeof(Sockettrans2devtab)/sizeof(Sockettrans2dev))
+
+
+#ifdef UNIXCONN
+
+#ifdef hpux
+
+#if defined(X11_t)
+#define UNIX_PATH "/usr/spool/sockets/X11/"
+#define UNIX_DIR "/usr/spool/sockets/X11"
+#define OLD_UNIX_PATH "/tmp/.X11-unix/X"
+#endif /* X11_t */
+#if defined(XIM_t)
+#define UNIX_PATH "/usr/spool/sockets/XIM/"
+#define UNIX_DIR "/usr/spool/sockets/XIM"
+#define OLD_UNIX_PATH "/tmp/.XIM-unix/XIM"
+#endif /* XIM_t */
+#if defined(FS_t) || defined(FONT_t)
+#define UNIX_PATH "/usr/spool/sockets/fontserv/"
+#define UNIX_DIR "/usr/spool/sockets/fontserv"
+#endif /* FS_t || FONT_t */
+#if defined(ICE_t)
+#define UNIX_PATH "/usr/spool/sockets/ICE/"
+#define UNIX_DIR "/usr/spool/sockets/ICE"
+#endif /* ICE_t */
+#if defined(TEST_t)
+#define UNIX_PATH "/usr/spool/sockets/xtrans_test/"
+#define UNIX_DIR "/usr/spool/sockets/xtrans_test"
+#endif
+
+#else /* !hpux */
+
+#if defined(X11_t)
+#define UNIX_PATH "/tmp/.X11-unix/X"
+#define UNIX_DIR "/tmp/.X11-unix"
+#endif /* X11_t */
+#if defined(XIM_t)
+#define UNIX_PATH "/tmp/.XIM-unix/XIM"
+#define UNIX_DIR "/tmp/.XIM-unix"
+#endif /* XIM_t */
+#if defined(FS_t) || defined(FONT_t)
+#define UNIX_PATH "/tmp/.font-unix/fs"
+#define UNIX_DIR "/tmp/.font-unix"
+#endif /* FS_t || FONT_t */
+#if defined(ICE_t)
+#define UNIX_PATH "/tmp/.ICE-unix/"
+#define UNIX_DIR "/tmp/.ICE-unix"
+#endif /* ICE_t */
+#if defined(TEST_t)
+#define UNIX_PATH "/tmp/.Test-unix/test"
+#define UNIX_DIR "/tmp/.Test-unix"
+#endif
+
+#endif /* hpux */
+
+#endif /* UNIXCONN */
+
+
+/*
+ * These are some utility function used by the real interface function below.
+ */
+
+static int
+TRANS(SocketSelectFamily) (family)
+
+char *family;
+
+{
+    int     i;
+
+    PRMSG (3,"SocketSelectFamily(%s)\n", family, 0, 0);
+
+    for (i = 0; i < NUMSOCKETFAMILIES;i++)
+    {
+        if (!strcmp (family, Sockettrans2devtab[i].transname))
+           return i;
+    }
+
+    return -1;
+}
+
+
+/*
+ * This function gets the local address of the socket and stores it in the
+ * XtransConnInfo structure for the connection.
+ */
+
+static int
+TRANS(SocketINETGetAddr) (ciptr)
+
+XtransConnInfo ciptr;
+
+{
+    struct sockaddr_in         sockname;
+#if defined(SVR4) || defined(SCO325)
+    size_t namelen = sizeof sockname;
+#else
+    int namelen = sizeof sockname;
+#endif
+
+    PRMSG (3,"SocketINETGetAddr(%x)\n", ciptr, 0, 0);
+
+    if (getsockname (ciptr->fd,(struct sockaddr *) &sockname, &namelen) < 0)
+    {
+       PRMSG (1,"SocketINETGetAddr: getsockname() failed: %d\n",
+           EGET(),0, 0);
+       return -1;
+    }
+
+    /*
+     * Everything looks good: fill in the XtransConnInfo structure.
+     */
+
+    if ((ciptr->addr = (char *) xalloc (namelen)) == NULL)
+    {
+        PRMSG (1,
+           "SocketINETGetAddr: Can't allocate space for the addr\n",
+           0, 0, 0);
+        return -1;
+    }
+
+    ciptr->family = sockname.sin_family;
+    ciptr->addrlen = namelen;
+    memcpy (ciptr->addr, &sockname, ciptr->addrlen);
+
+    return 0;
+}
+
+
+/*
+ * This function gets the remote address of the socket and stores it in the
+ * XtransConnInfo structure for the connection.
+ */
+
+static int
+TRANS(SocketINETGetPeerAddr) (ciptr)
+
+XtransConnInfo ciptr;
+
+{
+    struct sockaddr_in         sockname;
+#if defined(SVR4) || defined(SCO325)
+    size_t namelen = sizeof sockname;
+#else
+    int namelen = sizeof sockname;
+#endif
+
+    PRMSG (3,"SocketINETGetPeerAddr(%x)\n", ciptr, 0, 0);
+
+    if (getpeername (ciptr->fd, (struct sockaddr *) &sockname, &namelen) < 0)
+    {
+       PRMSG (1,"SocketINETGetPeerAddr: getpeername() failed: %d\n",
+           EGET(), 0, 0);
+       return -1;
+    }
+
+    /*
+     * Everything looks good: fill in the XtransConnInfo structure.
+     */
+
+    if ((ciptr->peeraddr = (char *) xalloc (namelen)) == NULL)
+    {
+        PRMSG (1,
+          "SocketINETGetPeerAddr: Can't allocate space for the addr\n",
+          0, 0, 0);
+        return -1;
+    }
+
+    ciptr->peeraddrlen = namelen;
+    memcpy (ciptr->peeraddr, &sockname, ciptr->peeraddrlen);
+
+    return 0;
+}
+
+
+static XtransConnInfo
+TRANS(SocketOpen) (i, type)
+
+int i;
+int type;
+
+{
+    XtransConnInfo     ciptr;
+
+    PRMSG (3,"SocketOpen(%d,%d)\n", i, type, 0);
+
+    if ((ciptr = (XtransConnInfo) xcalloc (
+       1, sizeof(struct _XtransConnInfo))) == NULL)
+    {
+       PRMSG (1, "SocketOpen: malloc failed\n", 0, 0, 0);
+       return NULL;
+    }
+
+    if ((ciptr->fd = socket(Sockettrans2devtab[i].family, type,
+       Sockettrans2devtab[i].protocol)) < 0
+#ifndef WIN32
+#if (defined(X11_t) && !defined(USE_POLL)) || defined(FS_t) || defined(FONT_t)
+       || ciptr->fd >= TRANS_OPEN_MAX
+#endif
+#endif
+      ) {
+       PRMSG (1, "SocketOpen: socket() failed for %s\n",
+           Sockettrans2devtab[i].transname, 0, 0);
+
+       xfree ((char *) ciptr);
+       return NULL;
+    }
+
+#ifdef TCP_NODELAY
+    if (Sockettrans2devtab[i].family == AF_INET)
+    {
+       /*
+        * turn off TCP coalescence for INET sockets
+        */
+
+       int tmp = 1;
+       setsockopt (ciptr->fd, IPPROTO_TCP, TCP_NODELAY,
+           (char *) &tmp, sizeof (int));
+    }
+#endif
+
+    return ciptr;
+}
+
+
+#ifdef TRANS_REOPEN
+
+static XtransConnInfo
+TRANS(SocketReopen) (i, type, fd, port)
+
+int  i;
+int  type;
+int  fd;
+char *port;
+
+{
+    XtransConnInfo     ciptr;
+
+    PRMSG (3,"SocketReopen(%d,%d,%s)\n", type, fd, port);
+
+    if ((ciptr = (XtransConnInfo) xcalloc (
+       1, sizeof(struct _XtransConnInfo))) == NULL)
+    {
+       PRMSG (1, "SocketReopen: malloc failed\n", 0, 0, 0);
+       return NULL;
+    }
+
+    ciptr->fd = fd;
+
+    return ciptr;
+}
+
+#endif /* TRANS_REOPEN */
+
+
+/*
+ * These functions are the interface supplied in the Xtransport structure
+ */
+
+#ifdef TRANS_CLIENT
+
+static XtransConnInfo
+TRANS(SocketOpenCOTSClient) (thistrans, protocol, host, port)
+
+Xtransport *thistrans;
+char      *protocol;
+char      *host;
+char       *port;
+
+{
+    XtransConnInfo     ciptr;
+    int                        i;
+
+    PRMSG (2, "SocketOpenCOTSClient(%s,%s,%s)\n",
+       protocol, host, port);
+
+    SocketInitOnce();
+
+    if ((i = TRANS(SocketSelectFamily) (thistrans->TransName)) < 0)
+    {
+       PRMSG (1,
+       "SocketOpenCOTSClient: Unable to determine socket type for %s\n",
+           thistrans->TransName, 0, 0);
+       return NULL;
+    }
+
+    if ((ciptr = TRANS(SocketOpen) (
+       i, Sockettrans2devtab[i].devcotsname)) == NULL)
+    {
+       PRMSG (1,"SocketOpenCOTSClient: Unable to open socket for %s\n",
+           thistrans->TransName, 0, 0);
+       return NULL;
+    }
+
+    /* Save the index for later use */
+
+    ciptr->index = i;
+
+    return ciptr;
+}
+
+#endif /* TRANS_CLIENT */
+
+
+#ifdef TRANS_SERVER
+
+static XtransConnInfo
+TRANS(SocketOpenCOTSServer) (thistrans, protocol, host, port)
+
+Xtransport *thistrans;
+char      *protocol;
+char      *host;
+char      *port;
+
+{
+    XtransConnInfo     ciptr;
+    int        i;
+
+    PRMSG (2,"SocketOpenCOTSServer(%s,%s,%s)\n", protocol, host, port);
+
+    SocketInitOnce();
+
+    if ((i = TRANS(SocketSelectFamily) (thistrans->TransName)) < 0)
+    {
+       PRMSG (1,
+       "SocketOpenCOTSServer: Unable to determine socket type for %s\n",
+           thistrans->TransName, 0, 0);
+       return NULL;
+    }
+
+    if ((ciptr = TRANS(SocketOpen) (
+       i, Sockettrans2devtab[i].devcotsname)) == NULL)
+    {
+       PRMSG (1,"SocketOpenCOTSServer: Unable to open socket for %s\n",
+           thistrans->TransName, 0, 0);
+       return NULL;
+    }
+
+    /*
+     * Using this prevents the bind() check for an existing server listening
+     * on the same port, but it is required for other reasons.
+     */
+#ifdef SO_REUSEADDR
+
+    /*
+     * SO_REUSEADDR only applied to AF_INET
+     */
+
+    if (Sockettrans2devtab[i].family == AF_INET)
+    {
+       int one = 1;
+       setsockopt (ciptr->fd, SOL_SOCKET, SO_REUSEADDR,
+                   (char *) &one, sizeof (int));
+    }
+#endif
+
+    /* Save the index for later use */
+
+    ciptr->index = i;
+
+    return ciptr;
+}
+
+#endif /* TRANS_SERVER */
+
+
+#ifdef TRANS_CLIENT
+
+static XtransConnInfo
+TRANS(SocketOpenCLTSClient) (thistrans, protocol, host, port)
+
+Xtransport *thistrans;
+char      *protocol;
+char      *host;
+char      *port;
+
+{
+    XtransConnInfo     ciptr;
+    int                        i;
+
+    PRMSG (2,"SocketOpenCLTSClient(%s,%s,%s)\n", protocol, host, port);
+
+    SocketInitOnce();
+
+    if ((i = TRANS(SocketSelectFamily) (thistrans->TransName)) < 0)
+    {
+       PRMSG (1,
+       "SocketOpenCLTSClient: Unable to determine socket type for %s\n",
+           thistrans->TransName, 0, 0);
+       return NULL;
+    }
+
+    if ((ciptr = TRANS(SocketOpen) (
+       i, Sockettrans2devtab[i].devcotsname)) == NULL)
+    {
+       PRMSG (1,"SocketOpenCLTSClient: Unable to open socket for %s\n",
+             thistrans->TransName, 0, 0);
+       return NULL;
+    }
+
+    /* Save the index for later use */
+
+    ciptr->index = i;
+
+    return ciptr;
+}
+
+#endif /* TRANS_CLIENT */
+
+
+#ifdef TRANS_SERVER
+
+static XtransConnInfo
+TRANS(SocketOpenCLTSServer) (thistrans, protocol, host, port)
+
+Xtransport *thistrans;
+char      *protocol;
+char      *host;
+char      *port;
+
+{
+    XtransConnInfo     ciptr;
+    int        i;
+
+    PRMSG (2,"SocketOpenCLTSServer(%s,%s,%s)\n", protocol, host, port);
+
+    SocketInitOnce();
+
+    if ((i = TRANS(SocketSelectFamily) (thistrans->TransName)) < 0)
+    {
+       PRMSG (1,
+       "SocketOpenCLTSServer: Unable to determine socket type for %s\n",
+             thistrans->TransName, 0, 0);
+       return NULL;
+    }
+
+    if ((ciptr = TRANS(SocketOpen) (
+       i, Sockettrans2devtab[i].devcotsname)) == NULL)
+    {
+       PRMSG (1,"SocketOpenCLTSServer: Unable to open socket for %s\n",
+             thistrans->TransName, 0, 0);
+       return NULL;
+    }
+
+    /* Save the index for later use */
+
+    ciptr->index = i;
+
+    return ciptr;
+}
+
+#endif /* TRANS_SERVER */
+
+
+#ifdef TRANS_REOPEN
+
+static XtransConnInfo
+TRANS(SocketReopenCOTSServer) (thistrans, fd, port)
+
+Xtransport *thistrans;
+int       fd;
+char      *port;
+
+{
+    XtransConnInfo     ciptr;
+    int                        i;
+
+    PRMSG (2,
+       "SocketReopenCOTSServer(%d, %s)\n", fd, port, 0);
+
+    SocketInitOnce();
+
+    if ((i = TRANS(SocketSelectFamily) (thistrans->TransName)) < 0)
+    {
+       PRMSG (1,
+       "SocketReopenCOTSServer: Unable to determine socket type for %s\n",
+           thistrans->TransName, 0, 0);
+       return NULL;
+    }
+
+    if ((ciptr = TRANS(SocketReopen) (
+       i, Sockettrans2devtab[i].devcotsname, fd, port)) == NULL)
+    {
+       PRMSG (1,
+           "SocketReopenCOTSServer: Unable to reopen socket for %s\n",
+           thistrans->TransName, 0, 0);
+       return NULL;
+    }
+
+    /* Save the index for later use */
+
+    ciptr->index = i;
+
+    return ciptr;
+}
+
+static XtransConnInfo
+TRANS(SocketReopenCLTSServer) (thistrans, fd, port)
+
+Xtransport *thistrans;
+int       fd;
+char      *port;
+
+{
+    XtransConnInfo     ciptr;
+    int                        i;
+
+    PRMSG (2,
+       "SocketReopenCLTSServer(%d, %s)\n", fd, port, 0);
+
+    SocketInitOnce();
+
+    if ((i = TRANS(SocketSelectFamily) (thistrans->TransName)) < 0)
+    {
+       PRMSG (1,
+       "SocketReopenCLTSServer: Unable to determine socket type for %s\n",
+             thistrans->TransName, 0, 0);
+       return NULL;
+    }
+
+    if ((ciptr = TRANS(SocketReopen) (
+       i, Sockettrans2devtab[i].devcotsname, fd, port)) == NULL)
+    {
+       PRMSG (1,
+            "SocketReopenCLTSServer: Unable to reopen socket for %s\n",
+            thistrans->TransName, 0, 0);
+       return NULL;
+    }
+
+    /* Save the index for later use */
+
+    ciptr->index = i;
+
+    return ciptr;
+}
+
+#endif /* TRANS_REOPEN */
+
+
+static int
+TRANS(SocketSetOption) (ciptr, option, arg)
+
+XtransConnInfo         ciptr;
+int            option;
+int            arg;
+
+{
+    PRMSG (2,"SocketSetOption(%d,%d,%d)\n", ciptr->fd, option, arg);
+
+    return -1;
+}
+
+
+#ifdef TRANS_SERVER
+
+static int
+TRANS(SocketCreateListener) (ciptr, sockname, socknamelen)
+
+XtransConnInfo ciptr;
+struct sockaddr        *sockname;
+int            socknamelen;
+
+{
+    int        namelen = socknamelen;
+    int        fd = ciptr->fd;
+    int        retry;
+
+    PRMSG (3, "SocketCreateListener(%x,%d)\n", ciptr, fd, 0);
+
+    if (Sockettrans2devtab[ciptr->index].family == AF_INET)
+       retry = 20;
+    else
+       retry = 0;
+
+    while (bind (fd, (struct sockaddr *) sockname, namelen) < 0)
+    {
+       if (errno == EADDRINUSE)
+           return TRANS_ADDR_IN_USE;
+
+       if (retry-- == 0) {
+           PRMSG (1, "SocketCreateListener: failed to bind listener\n",
+               0, 0, 0);
+           close (fd);
+           return TRANS_CREATE_LISTENER_FAILED;
+       }
+#ifdef SO_REUSEADDR
+       sleep (1);
+#else
+       sleep (10);
+#endif /* SO_REUSEDADDR */
+    }
+
+    if (Sockettrans2devtab[ciptr->index].family == AF_INET) {
+#ifdef SO_DONTLINGER
+       setsockopt (fd, SOL_SOCKET, SO_DONTLINGER, (char *) NULL, 0);
+#else
+#ifdef SO_LINGER
+    {
+       static int linger[2] = { 0, 0 };
+       setsockopt (fd, SOL_SOCKET, SO_LINGER,
+               (char *) linger, sizeof (linger));
+    }
+#endif
+#endif
+}
+
+    if (listen (fd, BACKLOG) < 0)
+    {
+       PRMSG (1, "SocketCreateListener: listen() failed\n", 0, 0, 0);
+       close (fd);
+       return TRANS_CREATE_LISTENER_FAILED;
+    }
+       
+    /* Set a flag to indicate that this connection is a listener */
+
+    ciptr->flags = 1;
+
+    return 0;
+}
+
+
+#ifdef TCPCONN
+static int
+TRANS(SocketINETCreateListener) (ciptr, port)
+
+XtransConnInfo         ciptr;
+char           *port;
+
+{
+    struct sockaddr_in sockname;
+    int                namelen = sizeof(sockname);
+    int                status;
+    short      tmpport;
+    _Xgetservbynameparams sparams;
+    struct servent *servp;
+
+#define PORTBUFSIZE    64      /* what is a real size for this? */
+
+    char       portbuf[PORTBUFSIZE];
+    
+    PRMSG (2, "SocketINETCreateListener(%s)\n", port, 0, 0);
+
+#ifdef X11_t
+    /*
+     * X has a well known port, that is transport dependent. It is easier
+     * to handle it here, than try and come up with a transport independent
+     * representation that can be passed in and resolved the usual way.
+     *
+     * The port that is passed here is really a string containing the idisplay
+     * from ConnectDisplay().
+     */
+
+    if (is_numeric (port))
+    {
+       tmpport = (short) atoi (port);
+
+       sprintf (portbuf,"%d", X_TCP_PORT+tmpport);
+    }
+    else
+       strncpy (portbuf, port, PORTBUFSIZE);
+
+    port = portbuf;
+#endif
+
+    if (port && *port)
+    {
+       /* Check to see if the port string is just a number (handles X11) */
+
+       if (!is_numeric (port))
+       {
+           if ((servp = _XGetservbyname (port,"tcp",sparams)) == NULL)
+           {
+               PRMSG (1,
+            "SocketINETCreateListener: Unable to get service for %s\n",
+                     port, 0, 0);
+               return TRANS_CREATE_LISTENER_FAILED;
+           }
+           sockname.sin_port = servp->s_port;
+       }
+       else
+       {
+           tmpport = (short) atoi (port);
+           sockname.sin_port = htons (tmpport);
+       }
+    }
+    else
+       sockname.sin_port = htons (0);
+
+#ifdef BSD44SOCKETS
+    sockname.sin_len = sizeof (sockname);
+#endif
+    sockname.sin_family = AF_INET;
+    sockname.sin_addr.s_addr = htonl (INADDR_ANY);
+
+    if ((status = TRANS(SocketCreateListener) (ciptr,
+       (struct sockaddr *) &sockname, namelen)) < 0)
+    {
+       PRMSG (1,
+    "SocketINETCreateListener: ...SocketCreateListener() failed\n",
+           0, 0, 0);
+       return status;
+    }
+
+    if (TRANS(SocketINETGetAddr) (ciptr) < 0)
+    {
+       PRMSG (1,
+       "SocketINETCreateListener: ...SocketINETGetAddr() failed\n",
+           0, 0, 0);
+       return TRANS_CREATE_LISTENER_FAILED;
+    }
+
+    return 0;
+}
+
+#endif /* SOCKCONN */
+
+
+#ifdef UNIXCONN
+
+static
+TRANS(SocketUNIXCreateListener) (ciptr, port)
+
+XtransConnInfo ciptr;
+char *port;
+
+{
+    struct sockaddr_un sockname;
+    int                        namelen;
+    int                        oldUmask;
+    int                        status;
+
+    PRMSG (2, "SocketUNIXCreateListener(%s)\n",
+       port ? port : "NULL", 0, 0);
+
+    /* Make sure the directory is created */
+
+    oldUmask = umask (0);
+
+#ifdef UNIX_DIR
+    if (!mkdir (UNIX_DIR, 01777))
+        chmod (UNIX_DIR, 01777);
+#endif
+
+    sockname.sun_family = AF_UNIX;
+
+    if (port && *port) {
+       if (*port == '/') { /* a full pathname */
+           sprintf (sockname.sun_path, "%s", port);
+       } else {
+           sprintf (sockname.sun_path, "%s%s", UNIX_PATH, port);
+       }
+    } else {
+       sprintf (sockname.sun_path, "%s%d", UNIX_PATH, getpid());
+    }
+
+#if defined(BSD44SOCKETS) && !defined(Lynx)
+    sockname.sun_len = strlen(sockname.sun_path);
+    namelen = SUN_LEN(&sockname);
+#else
+    namelen = strlen(sockname.sun_path) + sizeof(sockname.sun_family);
+#endif
+
+    unlink (sockname.sun_path);
+
+    if ((status = TRANS(SocketCreateListener) (ciptr,
+       (struct sockaddr *) &sockname, namelen)) < 0)
+    {
+       PRMSG (1,
+    "SocketUNIXCreateListener: ...SocketCreateListener() failed\n",
+           0, 0, 0);
+       return status;
+    }
+
+    /*
+     * Now that the listener is esablished, create the addr info for
+     * this connection. getpeername() doesn't work for UNIX Domain Sockets
+     * on some systems (hpux at least), so we will just do it manually, instead
+     * of calling something like TRANS(SocketUNIXGetAddr).
+     */
+
+    namelen = sizeof (sockname); /* this will always make it the same size */
+
+    if ((ciptr->addr = (char *) xalloc (namelen)) == NULL)
+    {
+        PRMSG (1,
+        "SocketUNIXCreateListener: Can't allocate space for the addr\n",
+           0, 0, 0);
+        return TRANS_CREATE_LISTENER_FAILED;
+    }
+
+    ciptr->family = sockname.sun_family;
+    ciptr->addrlen = namelen;
+    memcpy (ciptr->addr, &sockname, ciptr->addrlen);
+
+    (void) umask (oldUmask);
+
+    return 0;
+}
+
+
+static
+TRANS(SocketUNIXResetListener) (ciptr)
+
+XtransConnInfo ciptr;
+
+{
+    /*
+     * See if the unix domain socket has disappeared.  If it has, recreate it.
+     */
+
+    struct sockaddr_un         *unsock = (struct sockaddr_un *) ciptr->addr;
+    struct stat                statb;
+    int                status = TRANS_RESET_NOOP;
+    void               TRANS(FreeConnInfo) ();
+
+    PRMSG (3, "SocketUNIXResetListener(%x,%d)\n", ciptr, ciptr->fd, 0);
+
+    if (stat (unsock->sun_path, &statb) == -1 ||
+        ((statb.st_mode & S_IFMT) !=
+#if (defined (sun) && defined(SVR4)) || defined(NCR) || defined(SCO) || defined(sco) || !defined(S_IFSOCK)
+                       S_IFIFO))
+#else
+                       S_IFSOCK))
+#endif
+    {
+       int oldUmask = umask (0);
+
+#ifdef UNIX_DIR
+       if (!mkdir (UNIX_DIR, 01777))
+           chmod (UNIX_DIR, 01777);
+#endif
+
+       close (ciptr->fd);
+       unlink (unsock->sun_path);
+
+       if ((ciptr->fd = socket (AF_UNIX, SOCK_STREAM, 0)) < 0)
+       {
+           TRANS(FreeConnInfo) (ciptr);
+           return TRANS_RESET_FAILURE;
+       }
+
+       if (bind (ciptr->fd, (struct sockaddr *) unsock, ciptr->addrlen) < 0)
+       {
+           close (ciptr->fd);
+           TRANS(FreeConnInfo) (ciptr);
+           return TRANS_RESET_FAILURE;
+       }
+
+       if (listen (ciptr->fd, BACKLOG) < 0)
+       {
+           close (ciptr->fd);
+           TRANS(FreeConnInfo) (ciptr);
+           return TRANS_RESET_FAILURE;
+       }
+
+       umask (oldUmask);
+
+       status = TRANS_RESET_NEW_FD;
+    }
+
+    return status;
+}
+
+#endif /* UNIXCONN */
+
+
+#ifdef TCPCONN
+
+static XtransConnInfo
+TRANS(SocketINETAccept) (ciptr, status)
+
+XtransConnInfo ciptr;
+int           *status;
+
+{
+    XtransConnInfo     newciptr;
+    struct sockaddr_in sockname;
+    int                        namelen = sizeof(sockname);
+
+    PRMSG (2, "SocketINETAccept(%x,%d)\n", ciptr, ciptr->fd, 0);
+
+    if ((newciptr = (XtransConnInfo) xcalloc (
+       1, sizeof(struct _XtransConnInfo))) == NULL)
+    {
+       PRMSG (1, "SocketINETAccept: malloc failed\n", 0, 0, 0);
+       *status = TRANS_ACCEPT_BAD_MALLOC;
+       return NULL;
+    }
+
+    if ((newciptr->fd = accept (ciptr->fd,
+       (struct sockaddr *) &sockname, &namelen)) < 0)
+    {
+       PRMSG (1, "SocketINETAccept: accept() failed\n", 0, 0, 0);
+       xfree (newciptr);
+       *status = TRANS_ACCEPT_FAILED;
+       return NULL;
+    }
+
+#ifdef TCP_NODELAY
+    {
+       /*
+        * turn off TCP coalescence for INET sockets
+        */
+
+       int tmp = 1;
+       setsockopt (newciptr->fd, IPPROTO_TCP, TCP_NODELAY,
+           (char *) &tmp, sizeof (int));
+    }
+#endif
+
+    /*
+     * Get this address again because the transport may give a more 
+     * specific address now that a connection is established.
+     */
+
+    if (TRANS(SocketINETGetAddr) (newciptr) < 0)
+    {
+       PRMSG (1,
+           "SocketINETAccept: ...SocketINETGetAddr() failed:\n",
+           0, 0, 0);
+       close (newciptr->fd);
+       xfree (newciptr);
+       *status = TRANS_ACCEPT_MISC_ERROR;
+        return NULL;
+    }
+
+    if (TRANS(SocketINETGetPeerAddr) (newciptr) < 0)
+    {
+       PRMSG (1,
+         "SocketINETAccept: ...SocketINETGetPeerAddr() failed:\n",
+               0, 0, 0);
+       close (newciptr->fd);
+       if (newciptr->addr) xfree (newciptr->addr);
+       xfree (newciptr);
+       *status = TRANS_ACCEPT_MISC_ERROR;
+        return NULL;
+    }
+
+    *status = 0;
+
+    return newciptr;
+}
+
+#endif /* TCPCONN */
+
+
+#ifdef UNIXCONN
+static XtransConnInfo
+TRANS(SocketUNIXAccept) (ciptr, status)
+
+XtransConnInfo ciptr;
+int           *status;
+
+{
+    XtransConnInfo     newciptr;
+    struct sockaddr_un sockname;
+#if defined(SVR4) || defined(SCO325)
+    size_t namelen = sizeof sockname;
+#else
+    int namelen = sizeof sockname;
+#endif
+
+    PRMSG (2, "SocketUNIXAccept(%x,%d)\n", ciptr, ciptr->fd, 0);
+
+    if ((newciptr = (XtransConnInfo) xcalloc (
+       1, sizeof(struct _XtransConnInfo))) == NULL)
+    {
+       PRMSG (1, "SocketUNIXAccept: malloc() failed\n", 0, 0, 0);
+       *status = TRANS_ACCEPT_BAD_MALLOC;
+       return NULL;
+    }
+
+    if ((newciptr->fd = accept (ciptr->fd,
+       (struct sockaddr *) &sockname, &namelen)) < 0)
+    {
+       PRMSG (1, "SocketUNIXAccept: accept() failed\n", 0, 0, 0);
+       xfree (newciptr);
+       *status = TRANS_ACCEPT_FAILED;
+       return NULL;
+    }
+
+    /*
+     * Get the socket name and the peer name from the listener socket,
+     * since this is unix domain.
+     */
+
+    if ((newciptr->addr = (char *) xalloc (ciptr->addrlen)) == NULL)
+    {
+        PRMSG (1,
+        "SocketUNIXAccept: Can't allocate space for the addr\n",
+             0, 0, 0);
+       close (newciptr->fd);
+       xfree (newciptr);
+       *status = TRANS_ACCEPT_BAD_MALLOC;
+        return NULL;
+    }
+
+
+    newciptr->addrlen = ciptr->addrlen;
+    memcpy (newciptr->addr, ciptr->addr, newciptr->addrlen);
+
+    if ((newciptr->peeraddr = (char *) xalloc (ciptr->addrlen)) == NULL)
+    {
+        PRMSG (1,
+             "SocketUNIXAccept: Can't allocate space for the addr\n",
+             0, 0, 0);
+       close (newciptr->fd);
+       if (newciptr->addr) xfree (newciptr->addr);
+       xfree (newciptr);
+       *status = TRANS_ACCEPT_BAD_MALLOC;
+        return NULL;
+    }
+    
+    newciptr->peeraddrlen = ciptr->addrlen;
+    memcpy (newciptr->peeraddr, ciptr->addr, newciptr->addrlen);
+
+    newciptr->family = AF_UNIX;
+
+    *status = 0;
+
+    return newciptr;
+}
+
+#endif /* UNIXCONN */
+
+#endif /* TRANS_SERVER */
+
+
+#ifdef TRANS_CLIENT
+
+#ifdef TCPCONN
+static int
+TRANS(SocketINETConnect) (ciptr, host, port)
+
+XtransConnInfo         ciptr;
+char           *host;
+char           *port;
+
+{
+    struct sockaddr_in sockname;
+#if defined(SVR4) || defined(SCO325)
+    size_t namelen = sizeof sockname;
+#else
+    int namelen = sizeof sockname;
+#endif
+    _Xgethostbynameparams hparams;
+    _Xgetservbynameparams sparams;
+    struct hostent     *hostp;
+    struct servent     *servp;
+
+#define PORTBUFSIZE    64      /* what is a real size for this? */
+    char       portbuf[PORTBUFSIZE];
+
+    int                        ret;
+    short              tmpport;
+    unsigned long      tmpaddr;
+    char               hostnamebuf[256];               /* tmp space */
+
+    PRMSG (2,"SocketINETConnect(%d,%s,%s)\n", ciptr->fd, host, port);
+
+    if (!host)
+    {
+       hostnamebuf[0] = '\0';
+       (void) TRANS(GetHostname) (hostnamebuf, sizeof hostnamebuf);
+       host = hostnamebuf;
+    }
+
+#ifdef X11_t
+    /*
+     * X has a well known port, that is transport dependent. It is easier
+     * to handle it here, than try and come up with a transport independent
+     * representation that can be passed in and resolved the usual way.
+     *
+     * The port that is passed here is really a string containing the idisplay
+     * from ConnectDisplay().
+     */
+
+    if (is_numeric (port))
+    {
+       tmpport = (short) atoi (port);
+
+       sprintf (portbuf, "%d", X_TCP_PORT + tmpport);
+    }
+    else
+#endif
+       strncpy (portbuf, port, PORTBUFSIZE);
+
+    /*
+     * Build the socket name.
+     */
+
+#ifdef BSD44SOCKETS
+    sockname.sin_len = sizeof (struct sockaddr_in);
+#endif
+    sockname.sin_family = AF_INET;
+
+    /*
+     * fill in sin_addr
+     */
+
+    /* check for ww.xx.yy.zz host string */
+
+    if (isascii (host[0]) && isdigit (host[0])) {
+       tmpaddr = inet_addr (host); /* returns network byte order */
+    } else {
+       tmpaddr = -1;
+    }
+
+    PRMSG (4,"SocketINETConnect: inet_addr(%s) = %x\n",
+       host, tmpaddr, 0);
+
+    if (tmpaddr == -1)
+    {
+       if ((hostp = _XGethostbyname(host,hparams)) == NULL)
+       {
+           PRMSG (1,"SocketINETConnect: Can't get address for %s\n",
+                 host, 0, 0);
+           ESET(EINVAL);
+           return TRANS_CONNECT_FAILED;
+       }
+       if (hostp->h_addrtype != AF_INET)  /* is IP host? */
+       {
+           PRMSG (1,"SocketINETConnect: not INET host%s\n",
+                 host, 0, 0);
+           ESET(EPROTOTYPE);
+           return TRANS_CONNECT_FAILED;
+       }
+       
+#if defined(CRAY) && defined(OLDTCP)
+        /* Only Cray UNICOS3 and UNICOS4 will define this */
+        {
+       long t;
+       memcpy ((char *)&t, (char *) hostp->h_addr, sizeof (t));
+       sockname.sin_addr = t;
+        }
+#else
+        memcpy ((char *) &sockname.sin_addr, (char *) hostp->h_addr,
+               sizeof (sockname.sin_addr));
+#endif /* CRAY and OLDTCP */
+       
+    }
+else
+    {
+#if defined(CRAY) && defined(OLDTCP)
+       /* Only Cray UNICOS3 and UNICOS4 will define this */
+       sockname.sin_addr = tmpaddr;
+#else
+       sockname.sin_addr.s_addr = tmpaddr;
+#endif /* CRAY and OLDTCP */
+    }
+
+    /*
+     * fill in sin_port
+     */
+    
+    /* Check for number in the port string */
+
+    if (!is_numeric (portbuf))
+    {
+       if ((servp = _XGetservbyname (portbuf,"tcp",sparams)) == NULL)
+       {
+           PRMSG (1,"SocketINETConnect: Can't get service for %s\n",
+                 portbuf, 0, 0);
+           return TRANS_CONNECT_FAILED;
+       }
+       sockname.sin_port = servp->s_port;
+    }
+    else
+    {
+       tmpport = (short) atoi (portbuf);
+       sockname.sin_port = htons (tmpport);
+    }
+    
+    PRMSG (4,"SocketINETConnect: sockname.sin_port = %d\n",
+         ntohs(sockname.sin_port), 0, 0);
+
+    /*
+     * Do the connect()
+     */
+
+    if (connect (ciptr->fd, (struct sockaddr *) &sockname, namelen) < 0)
+    {
+#ifdef WIN32
+       int olderrno = WSAGetLastError();
+#else
+       int olderrno = errno;
+#endif
+
+       PRMSG (1,"SocketINETConnect: Can't connect: errno = %d\n",
+         EGET(),0, 0);
+
+       /*
+        * If the error was ECONNREFUSED, the server may be overloaded
+        * and we should try again.
+        *
+        * If the error was EINTR, the connect was interrupted and we
+        * should try again.
+        */
+
+       if (olderrno == ECONNREFUSED || olderrno == EINTR)
+           return TRANS_TRY_CONNECT_AGAIN;
+       else
+           return TRANS_CONNECT_FAILED;        
+    }
+    
+
+    /*
+     * Sync up the address fields of ciptr.
+     */
+    
+    if (TRANS(SocketINETGetAddr) (ciptr) < 0)
+    {
+       PRMSG (1,
+          "SocketINETConnect: ...SocketINETGetAddr() failed:\n",
+          0, 0, 0);
+       return TRANS_CONNECT_FAILED;
+    }
+
+    if (TRANS(SocketINETGetPeerAddr) (ciptr) < 0)
+    {
+       PRMSG (1,
+        "SocketINETConnect: ...SocketINETGetPeerAddr() failed:\n",
+             0, 0, 0);
+       return TRANS_CONNECT_FAILED;
+    }
+
+    return 0;
+}
+
+#endif /* TCPCONN */
+
+
+\f
+#ifdef UNIXCONN
+
+/*
+ * Make sure 'host' is really local.
+ */
+
+static int
+UnixHostReallyLocal (host)
+
+char *host;
+
+{
+    char hostnamebuf[256];
+
+    TRANS(GetHostname) (hostnamebuf, sizeof (hostnamebuf));
+
+    if (strcmp (hostnamebuf, host) == 0)
+    {
+       return (1);
+    }
+    else
+    {
+       /*
+        * A host may have more than one network address.  If any of the
+        * network addresses of 'host' (specified to the connect call)
+        * match any of the network addresses of 'hostname' (determined
+        * by TRANS(GetHostname)), then the two hostnames are equivalent,
+        * and we know that 'host' is really a local host.
+        */
+       char specified_local_addr_list[10][4];
+       int scount, equiv, i, j;
+       _Xgethostbynameparams hparams;
+       struct hostent *hostp;
+
+       if ((hostp = _XGethostbyname (host,hparams)) == NULL)
+           return (0);
+
+       scount = 0;
+       while (hostp->h_addr_list[scount] && scount <= 8)
+       {
+           /*
+            * The 2nd call to gethostname() overrides the data
+            * from the 1st call, so we must save the address list.
+            */
+
+           specified_local_addr_list[scount][0] = 
+                               hostp->h_addr_list[scount][0];
+           specified_local_addr_list[scount][1] = 
+                               hostp->h_addr_list[scount][1];
+           specified_local_addr_list[scount][2] = 
+                               hostp->h_addr_list[scount][2];
+           specified_local_addr_list[scount][3] = 
+                               hostp->h_addr_list[scount][3];
+           scount++;
+       }
+       if ((hostp = _XGethostbyname (hostnamebuf,hparams)) == NULL)
+           return (0);
+
+       equiv = 0;
+       i = 0;
+
+       while (i < scount && !equiv)
+       {
+           j = 0;
+
+           while (hostp->h_addr_list[j])
+           {
+               if ((specified_local_addr_list[i][0] == 
+                                       hostp->h_addr_list[j][0]) &&
+                   (specified_local_addr_list[i][1] == 
+                                       hostp->h_addr_list[j][1]) &&
+                   (specified_local_addr_list[i][2] == 
+                                       hostp->h_addr_list[j][2]) &&
+                   (specified_local_addr_list[i][3] == 
+                                       hostp->h_addr_list[j][3]))
+               {
+                   /* They're equal, so we're done */
+                   
+                   equiv = 1;
+                   break;
+               }
+
+               j++;
+           }
+
+           i++;
+       }
+       
+    return (equiv);
+    }
+}
+
+static int
+TRANS(SocketUNIXConnect) (ciptr, host, port)
+
+XtransConnInfo ciptr;
+char *host;
+char *port;
+
+{
+    struct sockaddr_un sockname;
+    int                        namelen;
+
+#if defined(hpux) && defined(X11_t)
+    struct sockaddr_un old_sockname;
+    int                        old_namelen;
+#endif
+
+
+    PRMSG (2,"SocketUNIXConnect(%d,%s,%s)\n", ciptr->fd, host, port);
+    
+    /*
+     * Make sure 'host' is really local.  If not, we return failure.
+     * The reason we make this check is because a process may advertise
+     * a "local" network ID for which it can accept connections, but if
+     * a process on a remote machine tries to connect to this network ID,
+     * we know for sure it will fail.
+     */
+
+    if (strcmp (host, "unix") != 0 && !UnixHostReallyLocal (host))
+    {
+       PRMSG (1,
+          "SocketUNIXConnect: Cannot connect to non-local host %s\n",
+              host, 0, 0);
+       return TRANS_CONNECT_FAILED;
+    }
+
+
+    /*
+     * Check the port.
+     */
+
+    if (!port || !*port)
+    {
+       PRMSG (1,"SocketUNIXConnect: Missing port specification\n",
+             0, 0, 0);
+       return TRANS_CONNECT_FAILED;
+    }
+
+    /*
+     * Build the socket name.
+     */
+    
+    sockname.sun_family = AF_UNIX;
+
+    if (*port == '/') { /* a full pathname */
+       sprintf (sockname.sun_path, "%s", port);
+    } else {
+       sprintf (sockname.sun_path, "%s%s", UNIX_PATH, port);
+    }
+
+#if defined(BSD44SOCKETS) && !defined(Lynx)
+    sockname.sun_len = strlen (sockname.sun_path);
+    namelen = SUN_LEN (&sockname);
+#else
+    namelen = strlen (sockname.sun_path) + sizeof (sockname.sun_family);
+#endif
+
+
+#if defined(hpux) && defined(X11_t)
+    /*
+     * This is gross, but it was in Xlib
+     */
+    old_sockname.sun_family = AF_UNIX;
+    if (*port == '/') { /* a full pathname */
+       sprintf (old_sockname.sun_path, "%s", port);
+    } else {
+       sprintf (old_sockname.sun_path, "%s%s", OLD_UNIX_PATH, port);
+    }
+    old_namelen = strlen (old_sockname.sun_path) +
+       sizeof (old_sockname.sun_family);
+#endif
+
+
+    /*
+     * Do the connect()
+     */
+
+    if (connect (ciptr->fd, (struct sockaddr *) &sockname, namelen) < 0)
+    {
+       int olderrno = errno;
+       int connected = 0;
+       
+#if defined(hpux) && defined(X11_t)
+       if (olderrno == ENOENT)
+       {
+           if (connect (ciptr->fd,
+               (struct sockaddr *) &old_sockname, old_namelen) >= 0)
+           {
+               connected = 1;
+           }
+           else
+               olderrno = errno;
+       }
+#endif
+       if (!connected)
+       {
+           errno = olderrno;
+           
+           PRMSG (1,"SocketUNIXConnect: Can't connect: errno = %d\n",
+                 EGET(),0, 0);
+
+           if (olderrno == ENOENT || olderrno == EINTR)
+               return TRANS_TRY_CONNECT_AGAIN;
+           else
+               return TRANS_CONNECT_FAILED;
+       }
+    }
+
+    /*
+     * Get the socket name and the peer name from the connect socket,
+     * since this is unix domain.
+     */
+
+    if ((ciptr->addr = (char *) xalloc(namelen)) == NULL ||
+       (ciptr->peeraddr = (char *) xalloc(namelen)) == NULL)
+    {
+        PRMSG (1,
+       "SocketUNIXCreateListener: Can't allocate space for the addr\n",
+             0, 0, 0);
+        return TRANS_CONNECT_FAILED;
+    }
+
+    ciptr->family = AF_UNIX;
+    ciptr->addrlen = namelen;
+    ciptr->peeraddrlen = namelen;
+    memcpy (ciptr->addr, &sockname, ciptr->addrlen);
+    memcpy (ciptr->peeraddr, &sockname, ciptr->peeraddrlen);
+    
+    return 0;
+}
+
+#endif /* UNIXCONN */
+
+#endif /* TRANS_CLIENT */
+
+
+static int
+TRANS(SocketBytesReadable) (ciptr, pend)
+
+XtransConnInfo ciptr;
+BytesReadable_t *pend;
+{
+    PRMSG (2,"SocketBytesReadable(%x,%d,%x)\n",
+       ciptr, ciptr->fd, pend);
+
+#ifdef WIN32
+    return ioctlsocket ((SOCKET) ciptr->fd, FIONREAD, (u_long *) pend);
+#else
+#if (defined(i386) && defined(SYSV)) || defined(_SEQUENT_)
+    return ioctl (ciptr->fd, I_NREAD, (char *) pend);
+#else
+#if defined(__EMX__)
+    return ioctl (ciptr->fd, FIONREAD, (char*) pend, sizeof(int));
+#else
+    return ioctl (ciptr->fd, FIONREAD, (char *) pend);
+#endif /* __EMX__ */
+#endif /* i386 && SYSV && !SCO || _SEQUENT_ */
+#endif /* WIN32 */
+}
+
+
+static int
+TRANS(SocketRead) (ciptr, buf, size)
+
+XtransConnInfo ciptr;
+char           *buf;
+int            size;
+
+{
+    PRMSG (2,"SocketRead(%d,%x,%d)\n", ciptr->fd, buf, size);
+
+#if defined(WIN32) || defined(__EMX__)
+    return recv ((SOCKET)ciptr->fd, buf, size, 0);
+#else
+    return read (ciptr->fd, buf, size);
+#endif /* WIN32 */
+}
+
+
+static int
+TRANS(SocketWrite) (ciptr, buf, size)
+
+XtransConnInfo ciptr;
+char          *buf;
+int           size;
+
+{
+    PRMSG (2,"SocketWrite(%d,%x,%d)\n", ciptr->fd, buf, size);
+
+#if defined(WIN32) || defined(__EMX__)
+    return send ((SOCKET)ciptr->fd, buf, size, 0);
+#else
+    return write (ciptr->fd, buf, size);
+#endif /* WIN32 */
+}
+
+
+static int
+TRANS(SocketReadv) (ciptr, buf, size)
+
+XtransConnInfo ciptr;
+struct iovec   *buf;
+int            size;
+
+{
+    PRMSG (2,"SocketReadv(%d,%x,%d)\n", ciptr->fd, buf, size);
+
+    return READV (ciptr, buf, size);
+}
+
+
+static int
+TRANS(SocketWritev) (ciptr, buf, size)
+
+XtransConnInfo         ciptr;
+struct iovec   *buf;
+int            size;
+
+{
+    PRMSG (2,"SocketWritev(%d,%x,%d)\n", ciptr->fd, buf, size);
+
+    return WRITEV (ciptr, buf, size);
+}
+
+
+static int
+TRANS(SocketDisconnect) (ciptr)
+
+XtransConnInfo ciptr;
+
+{
+    PRMSG (2,"SocketDisconnect(%x,%d)\n", ciptr, ciptr->fd, 0);
+
+    return shutdown (ciptr->fd, 2); /* disallow further sends and receives */
+}
+
+
+#ifdef TCPCONN
+static int
+TRANS(SocketINETClose) (ciptr)
+
+XtransConnInfo ciptr;
+
+{
+    PRMSG (2,"SocketINETClose(%x,%d)\n", ciptr, ciptr->fd, 0);
+
+    return close (ciptr->fd);
+}
+
+#endif /* TCPCONN */
+
+
+#ifdef UNIXCONN
+static int
+TRANS(SocketUNIXClose) (ciptr)
+
+XtransConnInfo ciptr;
+
+{
+    /*
+     * If this is the server side, then once the socket is closed,
+     * it must be unlinked to completely close it
+     */
+
+    struct sockaddr_un *sockname = (struct sockaddr_un *) ciptr->addr;
+    char       path[200]; /* > sizeof sun_path +1 */
+    int ret;
+
+    PRMSG (2,"SocketUNIXClose(%x,%d)\n", ciptr, ciptr->fd, 0);
+
+    ret = close(ciptr->fd);
+
+    if (ciptr->flags
+       && sockname
+       && sockname->sun_family == AF_UNIX
+       && sockname->sun_path[0])
+    {
+       strncpy (path, sockname->sun_path,
+               ciptr->addrlen - sizeof (sockname->sun_family));
+       unlink (path);
+    }
+
+    return ret;
+}
+
+static int
+TRANS(SocketUNIXCloseForCloning) (ciptr)
+
+XtransConnInfo ciptr;
+
+{
+    /*
+     * Don't unlink path.
+     */
+
+    int ret;
+
+    PRMSG (2,"SocketUNIXCloseForCloning(%x,%d)\n",
+       ciptr, ciptr->fd, 0);
+
+    ret = close(ciptr->fd);
+
+    return ret;
+}
+
+#endif /* UNIXCONN */
+
+
+#ifdef TCPCONN
+Xtransport     TRANS(SocketTCPFuncs) = {
+       /* Socket Interface */
+       "tcp",
+        0,
+#ifdef TRANS_CLIENT
+       TRANS(SocketOpenCOTSClient),
+#endif /* TRANS_CLIENT */
+#ifdef TRANS_SERVER
+       TRANS(SocketOpenCOTSServer),
+#endif /* TRANS_SERVER */
+#ifdef TRANS_CLIENT
+       TRANS(SocketOpenCLTSClient),
+#endif /* TRANS_CLIENT */
+#ifdef TRANS_SERVER
+       TRANS(SocketOpenCLTSServer),
+#endif /* TRANS_SERVER */
+#ifdef TRANS_REOPEN
+       TRANS(SocketReopenCOTSServer),
+       TRANS(SocketReopenCLTSServer),
+#endif
+       TRANS(SocketSetOption),
+#ifdef TRANS_SERVER
+       TRANS(SocketINETCreateListener),
+       NULL,                                   /* ResetListener */
+       TRANS(SocketINETAccept),
+#endif /* TRANS_SERVER */
+#ifdef TRANS_CLIENT
+       TRANS(SocketINETConnect),
+#endif /* TRANS_CLIENT */
+       TRANS(SocketBytesReadable),
+       TRANS(SocketRead),
+       TRANS(SocketWrite),
+       TRANS(SocketReadv),
+       TRANS(SocketWritev),
+       TRANS(SocketDisconnect),
+       TRANS(SocketINETClose),
+       TRANS(SocketINETClose),
+       };
+
+Xtransport     TRANS(SocketINETFuncs) = {
+       /* Socket Interface */
+       "inet",
+       TRANS_ALIAS,
+#ifdef TRANS_CLIENT
+       TRANS(SocketOpenCOTSClient),
+#endif /* TRANS_CLIENT */
+#ifdef TRANS_SERVER
+       TRANS(SocketOpenCOTSServer),
+#endif /* TRANS_SERVER */
+#ifdef TRANS_CLIENT
+       TRANS(SocketOpenCLTSClient),
+#endif /* TRANS_CLIENT */
+#ifdef TRANS_SERVER
+       TRANS(SocketOpenCLTSServer),
+#endif /* TRANS_SERVER */
+#ifdef TRANS_REOPEN
+       TRANS(SocketReopenCOTSServer),
+       TRANS(SocketReopenCLTSServer),
+#endif
+       TRANS(SocketSetOption),
+#ifdef TRANS_SERVER
+       TRANS(SocketINETCreateListener),
+       NULL,                                   /* ResetListener */
+       TRANS(SocketINETAccept),
+#endif /* TRANS_SERVER */
+#ifdef TRANS_CLIENT
+       TRANS(SocketINETConnect),
+#endif /* TRANS_CLIENT */
+       TRANS(SocketBytesReadable),
+       TRANS(SocketRead),
+       TRANS(SocketWrite),
+       TRANS(SocketReadv),
+       TRANS(SocketWritev),
+       TRANS(SocketDisconnect),
+       TRANS(SocketINETClose),
+       TRANS(SocketINETClose),
+       };
+
+#endif /* TCPCONN */
+
+#ifdef UNIXCONN
+#if !defined(LOCALCONN)
+Xtransport     TRANS(SocketLocalFuncs) = {
+       /* Socket Interface */
+       "local",
+       0,
+#ifdef TRANS_CLIENT
+       TRANS(SocketOpenCOTSClient),
+#endif /* TRANS_CLIENT */
+#ifdef TRANS_SERVER
+       TRANS(SocketOpenCOTSServer),
+#endif /* TRANS_SERVER */
+#ifdef TRANS_CLIENT
+       TRANS(SocketOpenCLTSClient),
+#endif /* TRANS_CLIENT */
+#ifdef TRANS_SERVER
+       TRANS(SocketOpenCLTSServer),
+#endif /* TRANS_SERVER */
+#ifdef TRANS_REOPEN
+       TRANS(SocketReopenCOTSServer),
+       TRANS(SocketReopenCLTSServer),
+#endif
+       TRANS(SocketSetOption),
+#ifdef TRANS_SERVER
+       TRANS(SocketUNIXCreateListener),
+       TRANS(SocketUNIXResetListener),
+       TRANS(SocketUNIXAccept),
+#endif /* TRANS_SERVER */
+#ifdef TRANS_CLIENT
+       TRANS(SocketUNIXConnect),
+#endif /* TRANS_CLIENT */
+       TRANS(SocketBytesReadable),
+       TRANS(SocketRead),
+       TRANS(SocketWrite),
+       TRANS(SocketReadv),
+       TRANS(SocketWritev),
+       TRANS(SocketDisconnect),
+       TRANS(SocketUNIXClose),
+       TRANS(SocketUNIXCloseForCloning),
+       };
+#endif /* !LOCALCONN */
+
+Xtransport     TRANS(SocketUNIXFuncs) = {
+       /* Socket Interface */
+       "unix",
+#if !defined(LOCALCONN)
+        TRANS_ALIAS,
+#else
+       0,
+#endif
+#ifdef TRANS_CLIENT
+       TRANS(SocketOpenCOTSClient),
+#endif /* TRANS_CLIENT */
+#ifdef TRANS_SERVER
+       TRANS(SocketOpenCOTSServer),
+#endif /* TRANS_SERVER */
+#ifdef TRANS_CLIENT
+       TRANS(SocketOpenCLTSClient),
+#endif /* TRANS_CLIENT */
+#ifdef TRANS_SERVER
+       TRANS(SocketOpenCLTSServer),
+#endif /* TRANS_SERVER */
+#ifdef TRANS_REOPEN
+       TRANS(SocketReopenCOTSServer),
+       TRANS(SocketReopenCLTSServer),
+#endif
+       TRANS(SocketSetOption),
+#ifdef TRANS_SERVER
+       TRANS(SocketUNIXCreateListener),
+       TRANS(SocketUNIXResetListener),
+       TRANS(SocketUNIXAccept),
+#endif /* TRANS_SERVER */
+#ifdef TRANS_CLIENT
+       TRANS(SocketUNIXConnect),
+#endif /* TRANS_CLIENT */
+       TRANS(SocketBytesReadable),
+       TRANS(SocketRead),
+       TRANS(SocketWrite),
+       TRANS(SocketReadv),
+       TRANS(SocketWritev),
+       TRANS(SocketDisconnect),
+       TRANS(SocketUNIXClose),
+       TRANS(SocketUNIXCloseForCloning),
+       };
+
+#endif /* UNIXCONN */
diff --git a/Xserver/lib/xtrans/Xtranstli.c b/Xserver/lib/xtrans/Xtranstli.c
new file mode 100644 (file)
index 0000000..2061fc2
--- /dev/null
@@ -0,0 +1,1472 @@
+/* $XConsortium: Xtranstli.c /main/26 1995/12/13 18:07:13 kaleb $ */
+/* $XFree86: xc/lib/xtrans/Xtranstli.c,v 3.5 1996/09/01 04:14:14 dawes Exp $ */
+/*
+
+Copyright (c) 1993, 1994  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be included
+in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR
+OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall
+not be used in advertising or otherwise to promote the sale, use or
+other dealings in this Software without prior written authorization
+from the X Consortium.
+
+*/
+
+/* Copyright (c) 1993, 1994 NCR Corporation - Dayton, Ohio, USA
+ *
+ * All Rights Reserved
+ *
+ * Permission to use, copy, modify, and distribute this software and its
+ * documentation for any purpose and without fee is hereby granted, provided
+ * that the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the name NCR not be used in advertising
+ * or publicity pertaining to distribution of the software without specific,
+ * written prior permission.  NCR makes no representations about the
+ * suitability of this software for any purpose.  It is provided "as is"
+ * without express or implied warranty.
+ *
+ * NCR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN
+ * NO EVENT SHALL NCR BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
+ * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
+ * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
+ * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include <sys/un.h>
+#include <stropts.h>
+#include <poll.h>
+#include <tiuser.h>
+
+#include <netdir.h>
+#include <netconfig.h>
+
+
+/*
+ * This is the TLI implementation of the X Transport service layer
+ */
+
+typedef struct _TLItrans2dev {
+    char       *transname;
+    char       *protofamily;
+    char       *devcotsname;
+    char       *devcltsname;
+    int        family;
+} TLItrans2dev;
+
+static TLItrans2dev TLItrans2devtab[] = {
+       {"inet","inet","/dev/tcp","/dev/udp",AF_INET},
+       {"tcp","inet","/dev/tcp","/dev/udp",AF_INET},
+       {"tli","loopback","/dev/ticots","/dev/ticlts",AF_UNIX},
+};
+
+#define NUMTLIFAMILIES (sizeof(TLItrans2devtab)/sizeof(TLItrans2dev))
+    
+/*
+ * The local TLI connection, is a form of a local connection, so use a
+ * sockaddr_un for the address so that it will be treated just like the other
+ * local transports such as UNIX domain sockets, pts, and named.
+ */
+    
+#if defined(X11_t)
+#define TLINODENAME    "TLI:xserver"
+#endif
+    
+#if defined(XIM_t)
+#define TLINODENAME    "TLI:xim"
+#endif
+    
+#if defined(FS_t) || defined(FONT_t)
+#define TLINODENAME    "TLI:fontserver"
+#endif
+    
+#if defined(ICE_t)
+#define TLINODENAME    "TLI:ICE"
+#endif
+    
+#if defined(TEST_t)
+#define TLINODENAME    "TLI:test"
+#endif
+    
+
+/*
+ * These are some utility function used by the real interface function below.
+ */
+
+static int
+TRANS(TLISelectFamily)(family)
+
+char   *family;
+
+{
+    int     i;
+    
+    PRMSG(3,"TLISelectFamily(%s)\n", family, 0,0 );
+    
+    for(i=0;i<NUMTLIFAMILIES;i++)
+    {
+        if( !strcmp(family,TLItrans2devtab[i].transname) )
+           return i;
+    }
+    return -1;
+}
+
+
+/*
+ * This function gets the local address of the transport and stores it in the
+ * XtransConnInfo structure for the connection.
+ */
+
+static int
+TRANS(TLIGetAddr)(ciptr)
+
+XtransConnInfo ciptr;
+
+{
+    Xtransaddr         sockname;
+    struct netbuf      netbuf;
+    
+    PRMSG(3,"TLIGetAddr(%x)\n", ciptr, 0,0 );
+    
+    netbuf.buf=(char *)&sockname;
+    netbuf.len=sizeof(sockname);
+    netbuf.maxlen=sizeof(sockname);
+    
+    if( t_getname(ciptr->fd,&netbuf,LOCALNAME) < 0 )
+    {
+       PRMSG(1,"TLIGetAddr: t_getname(LOCALNAME) failed: %d\n",
+             errno, 0,0 );
+       return -1;
+    }
+    
+    PRMSG(4,"TLIGetAddr: got family %d len %d\n",
+         ((struct sockaddr *) &sockname)->sa_family ,netbuf.len, 0 );
+    
+    /*
+     * Everything looks good: fill in the XtransConnInfo structure.
+     */
+    
+    if( ciptr->addr )
+       xfree(ciptr->addr);
+    
+    if( (ciptr->addr=(char *)xalloc(netbuf.len)) == NULL )
+    {
+        PRMSG(1, "TLIGetAddr: Can't allocate space for the addr\n",
+             0,0,0);
+        return -1;
+    }
+    
+    ciptr->family=((struct sockaddr *) &sockname)->sa_family;
+    ciptr->addrlen=netbuf.len;
+    memcpy(ciptr->addr,&sockname,ciptr->addrlen);
+    
+    return 0;
+}
+
+
+/*
+ * This function gets the remote address of the socket and stores it in the
+ * XtransConnInfo structure for the connection.
+ */
+
+static int
+TRANS(TLIGetPeerAddr)(ciptr)
+
+XtransConnInfo ciptr;
+
+{
+    Xtransaddr         sockname;
+    struct netbuf      netbuf;
+    
+    PRMSG(3,"TLIGetPeerAddr(%x)\n", ciptr, 0,0 );
+    
+    netbuf.buf=(char *)&sockname;
+    netbuf.len=sizeof(sockname);
+    netbuf.maxlen=sizeof(sockname);
+    
+    if( t_getname(ciptr->fd,&netbuf,REMOTENAME) < 0 )
+    {
+       PRMSG(1,"TLIGetPeerAddr: t_getname(REMOTENAME) failed: %d\n",
+             errno, 0,0 );
+       return -1;
+    }
+    
+    PRMSG(4,"TLIGetPeerAddr: got family %d len %d\n",
+         ((struct sockaddr *) &sockname)->sa_family ,netbuf.len, 0 );
+    
+    /*
+     * Everything looks good: fill in the XtransConnInfo structure.
+     */
+    
+    if( ciptr->peeraddr )
+       xfree(ciptr->peeraddr);
+    
+    if( (ciptr->peeraddr=(char *)xalloc(netbuf.len)) == NULL )
+    {
+        PRMSG(1,
+             "TLIGetPeerAddr: Can't allocate space for the addr\n",
+             0,0,0);
+        return -1;
+    }
+    
+    ciptr->peeraddrlen=netbuf.len;
+    memcpy(ciptr->peeraddr,&sockname,ciptr->peeraddrlen);
+    
+    return 0;
+}
+
+
+/*
+ * This function will establish a local name for the transport. This function
+ * do extra work for the local tli connection. It must create a sockaddr_un
+ * format address so that it will look like an AF_UNIX connection to the
+ * higher layer.
+ *
+ * This function will only be called by the OPENC?TSClient() functions since
+ * the local address is set up in the CreateListner() for the server ends.
+ */
+
+static int
+TRANS(TLITLIBindLocal)(fd,family,port)
+
+int    fd;
+int    family;
+char   *port;
+
+{
+    struct sockaddr_un *sunaddr;
+    struct t_bind      *req=NULL;
+    
+    PRMSG(2, "TLITLIBindLocal(%d,%d,%s)\n", fd, family, port);
+    
+    if( family == AF_UNIX )
+    {
+       if( (req=(struct t_bind *)t_alloc(fd,T_BIND,0)) == NULL )
+       {
+           PRMSG(1,
+                 "TLITLIBindLocal() failed to allocate a t_bind\n",
+                 0,0,0 );
+           return -1;
+       }
+       
+       if( (sunaddr=(struct sockaddr_un *)
+            malloc(sizeof(struct sockaddr_un))) == NULL )
+       {
+           PRMSG(1,
+                 "TLITLIBindLocal: failed to allocate a sockaddr_un\n",
+                 0,0,0 );
+           t_free((char *)req,T_BIND);
+           return -1;
+       }
+       
+       sunaddr->sun_family=AF_UNIX;
+       
+#ifdef nuke
+       if( *port == '/' ) { /* A full pathname */
+           (void) strcpy(sunaddr->sun_path, port);
+       } else {
+           (void) sprintf(sunaddr->sun_path,"%s%s", TLINODENAME, port );
+       }
+#endif /*NUKE*/
+       
+       (void) sprintf(sunaddr->sun_path,"%s%d",
+                      TLINODENAME, getpid()^time(NULL) );
+       
+       PRMSG(4, "TLITLIBindLocal: binding to %s\n",
+             sunaddr->sun_path, 0,0);
+       
+       req->addr.buf=(char *)sunaddr;
+       req->addr.len=sizeof(*sunaddr);
+       req->addr.maxlen=sizeof(*sunaddr);
+    }
+    
+    if( t_bind(fd, req, NULL) < 0 )
+    {
+       PRMSG(1,
+             "TLIBindLocal: Unable to bind TLI device to %s\n",
+             port, 0,0 );
+       return -1;
+    }
+    return 0;
+}
+
+static XtransConnInfo
+TRANS(TLIOpen)(device)
+
+char   *device;
+
+{
+    XtransConnInfo     ciptr;
+    
+    PRMSG(3,"TLIOpen(%s)\n", device, 0,0 );
+    
+    if( (ciptr=(XtransConnInfo)xcalloc(1,sizeof(struct _XtransConnInfo))) == NULL )
+    {
+       PRMSG(1, "TLIOpen: calloc failed\n", 0,0,0 );
+       return NULL;
+    }
+    
+    if( (ciptr->fd=t_open( device, O_RDWR, NULL )) < 0 )
+    {
+       PRMSG(1, "TLIOpen: t_open failed for %s\n", device, 0,0 );
+       return NULL;
+    }
+    
+    return ciptr;
+}
+
+
+#ifdef TRANS_REOPEN
+
+static XtransConnInfo
+TRANS(TLIReopen)(device, fd, port)
+
+char   *device;
+int    fd;
+char   *port;
+
+{
+    XtransConnInfo     ciptr;
+    
+    PRMSG(3,"TLIReopen(%s,%d, %s)\n", device, fd, port );
+    
+    if (t_sync (fd) < 0)
+    {
+       PRMSG(1, "TLIReopen: t_sync failed\n", 0,0,0 );
+       return NULL;
+    }
+
+    if( (ciptr=(XtransConnInfo)xcalloc(1,sizeof(struct _XtransConnInfo))) == NULL )
+    {
+       PRMSG(1, "TLIReopen: calloc failed\n", 0,0,0 );
+       return NULL;
+    }
+    
+    ciptr->fd = fd;
+    
+    return ciptr;
+}
+
+#endif /* TRANS_REOPEN */
+
+
+static int
+TRANS(TLIAddrToNetbuf)(tlifamily, host, port, netbufp)
+
+int            tlifamily;
+char           *host;
+char           *port;
+struct netbuf  *netbufp;
+
+{
+    struct netconfig *netconfigp;
+    struct nd_hostserv nd_hostserv;
+    struct nd_addrlist *nd_addrlistp = NULL;
+    void *handlep;
+    
+    PRMSG(3,"TLIAddrToNetbuf(%d,%s,%s)\n", tlifamily, host, port );
+    
+    if( (handlep=setnetconfig()) == NULL )
+       return -1;
+    
+    nd_hostserv.h_host = host;
+    if( port && *port ) {
+       nd_hostserv.h_serv = port;
+    } else {
+       nd_hostserv.h_serv = NULL;
+    }
+    
+    while( (netconfigp=getnetconfig(handlep)) != NULL )
+    {
+       if( strcmp(netconfigp->nc_protofmly,
+                  TLItrans2devtab[tlifamily].protofamily) != 0 )
+           continue;
+       PRMSG(5,"TLIAddrToNetbuf: Trying to resolve %s.%s for %s\n",
+             host, port, TLItrans2devtab[tlifamily].protofamily );
+       if( netdir_getbyname(netconfigp,&nd_hostserv, &nd_addrlistp) == 0 )
+       {
+           /* we have at least one address to use */
+           
+           PRMSG(5, "TLIAddrToNetbuf: found address for %s.%s\n", host, port, 0 );
+           PRMSG(5, "TLIAddrToNetbuf: %s\n",taddr2uaddr(netconfigp,nd_addrlistp->n_addrs),
+                 0,0 );
+           
+           memcpy(netbufp->buf,nd_addrlistp->n_addrs->buf,
+                  nd_addrlistp->n_addrs->len);
+           netbufp->len=nd_addrlistp->n_addrs->len;
+           endnetconfig(handlep);
+           return 0;
+       }
+    }
+    endnetconfig(handlep);
+    
+    return -1;
+}
+
+/*
+ * These functions are the interface supplied in the Xtransport structure
+ */
+
+#ifdef TRANS_CLIENT
+
+static XtransConnInfo
+TRANS(TLIOpenCOTSClient)(thistrans, protocol, host, port)
+
+Xtransport     *thistrans;
+char           *protocol;
+char           *host;
+char           *port;
+
+{
+    XtransConnInfo     ciptr;
+    int                i;
+    
+    PRMSG(2,"TLIOpenCOTSClient(%s,%s,%s)\n", protocol, host, port );
+    
+    if( (i=TRANS(TLISelectFamily)(thistrans->TransName)) < 0 )
+    {
+       PRMSG(1,"TLIOpenCOTSClient: Unable to determine device for %s\n",
+             thistrans->TransName, 0,0 );
+       return NULL;
+    }
+    
+    if( (ciptr=TRANS(TLIOpen)(TLItrans2devtab[i].devcotsname)) == NULL )
+    {
+       PRMSG(1,"TLIOpenCOTSClient: Unable to open device for %s\n",
+             thistrans->TransName, 0,0 );
+       return NULL;
+    }
+    
+    if( TRANS(TLITLIBindLocal)(ciptr->fd,TLItrans2devtab[i].family,port) < 0 )
+    {
+       PRMSG(1,
+             "TLIOpenCOTSClient: ...TLITLIBindLocal() failed: %d\n",
+             errno, 0,0 );
+       t_close(ciptr->fd);
+       xfree(ciptr);
+       return NULL;
+    }
+    
+    if( TRANS(TLIGetAddr)(ciptr) < 0 )
+    {
+       PRMSG(1,
+             "TLIOpenCOTSClient: ...TLIGetAddr() failed: %d\n",
+             errno, 0,0 );
+       t_close(ciptr->fd);
+       xfree(ciptr);
+       return NULL;
+    }
+    
+    /* Save the TLIFamily for later use in TLIAddrToNetbuf() lookups */
+    ciptr->index = i;
+    
+    return ciptr;
+}
+
+#endif /* TRANS_CLIENT */
+
+
+#ifdef TRANS_SERVER
+
+static XtransConnInfo
+TRANS(TLIOpenCOTSServer)(thistrans, protocol, host, port)
+
+Xtransport     *thistrans;
+char           *protocol;
+char           *host;
+char           *port;
+
+{
+    XtransConnInfo     ciptr;
+    int                i;
+    
+    PRMSG(2,"TLIOpenCOTSServer(%s,%s,%s)\n", protocol, host, port );
+    
+    if( (i=TRANS(TLISelectFamily)(thistrans->TransName)) < 0 )
+    {
+       PRMSG(1,
+             "TLIOpenCOTSServer: Unable to determine device for %s\n",
+             thistrans->TransName, 0,0 );
+       return NULL;
+    }
+    
+    if( (ciptr=TRANS(TLIOpen)(TLItrans2devtab[i].devcotsname)) == NULL )
+    {
+       PRMSG(1,
+             "TLIOpenCOTSServer: Unable to open device for %s\n",
+             thistrans->TransName, 0,0 );
+       return NULL;
+    }
+    
+    /* Set the family type */
+
+    ciptr->family = TLItrans2devtab[i].family;
+
+
+    /* Save the TLIFamily for later use in TLIAddrToNetbuf() lookups */
+    
+    ciptr->index = i;
+    
+    return ciptr;
+}
+
+#endif /* TRANS_SERVER */
+
+
+#ifdef TRANS_CLIENT
+
+static XtransConnInfo
+TRANS(TLIOpenCLTSClient)(thistrans, protocol, host, port)
+
+Xtransport     *thistrans;
+char           *protocol;
+char           *host;
+char           *port;
+
+{
+    XtransConnInfo     ciptr;
+    int                i;
+    
+    PRMSG(2,"TLIOpenCLTSClient(%s,%s,%s)\n", protocol, host, port );
+    
+    if( (i=TRANS(TLISelectFamily)(thistrans->TransName)) < 0 )
+    {
+       PRMSG(1,
+             "TLIOpenCLTSClient: Unable to determine device for %s\n",
+             thistrans->TransName, 0,0 );
+       return NULL;
+    }
+    
+    if( (ciptr=TRANS(TLIOpen)(TLItrans2devtab[i].devcltsname)) == NULL )
+    {
+       PRMSG(1,
+             "TLIOpenCLTSClient: Unable to open device for %s\n",
+             thistrans->TransName, 0,0 );
+       return NULL;
+    }
+    
+    if( TRANS(TLITLIBindLocal)(ciptr->fd,TLItrans2devtab[i].family,port) < 0 )
+    {
+       PRMSG(1,
+             "TLIOpenCLTSClient: ...TLITLIBindLocal() failed: %d\n",
+             errno, 0,0 );
+       t_close(ciptr->fd);
+       xfree(ciptr);
+       return NULL;
+    }
+    
+    if( TRANS(TLIGetAddr)(ciptr) < 0 )
+    {
+       PRMSG(1,
+             "TLIOpenCLTSClient: ...TLIGetPeerAddr() failed: %d\n",
+             errno, 0,0 );
+       t_close(ciptr->fd);
+       xfree(ciptr);
+       return NULL;
+    }
+    
+    return ciptr;
+}                      
+
+#endif /* TRANS_CLIENT */
+
+
+#ifdef TRANS_SERVER
+
+static XtransConnInfo
+TRANS(TLIOpenCLTSServer)(thistrans, protocol, host, port)
+
+Xtransport     *thistrans;
+char           *protocol;
+char           *host;
+char           *port;
+
+{
+    XtransConnInfo     ciptr;
+    int                i;
+    
+    PRMSG(2,"TLIOpenCLTSServer(%s,%s,%s)\n", protocol, host, port );
+    
+    if( (i=TRANS(TLISelectFamily)(thistrans->TransName)) < 0 )
+    {
+       PRMSG(1,
+             "TLIOpenCLTSServer: Unable to determine device for %s\n",
+             thistrans->TransName, 0,0 );
+       return NULL;
+    }
+    
+    if( (ciptr=TRANS(TLIOpen)(TLItrans2devtab[i].devcltsname)) == NULL )
+    {
+       PRMSG(1,
+             "TLIOpenCLTSServer: Unable to open device for %s\n",
+             thistrans->TransName, 0,0 );
+       return NULL;
+    }
+    
+    return ciptr;
+}                      
+
+#endif /* TRANS_SERVER */
+
+
+#ifdef TRANS_REOPEN
+
+static XtransConnInfo
+TRANS(TLIReopenCOTSServer)(thistrans, fd, port)
+
+Xtransport     *thistrans;
+int            fd;
+char           *port;
+
+{
+    XtransConnInfo     ciptr;
+    int                        i;
+    
+    PRMSG(2,"TLIReopenCOTSServer(%d, %s)\n", fd, port, 0 );
+    
+    if( (i=TRANS(TLISelectFamily)(thistrans->TransName)) < 0 )
+    {
+       PRMSG(1,
+             "TLIReopenCOTSServer: Unable to determine device for %s\n",
+             thistrans->TransName, 0,0 );
+       return NULL;
+    }
+
+    if( (ciptr=TRANS(TLIReopen)(
+       TLItrans2devtab[i].devcotsname, fd, port)) == NULL )
+    {
+       PRMSG(1,
+             "TLIReopenCOTSServer: Unable to open device for %s\n",
+             thistrans->TransName, 0,0 );
+       return NULL;
+    }
+    
+    /* Save the TLIFamily for later use in TLIAddrToNetbuf() lookups */
+    
+    ciptr->index = i;
+    
+    return ciptr;
+}
+
+
+static XtransConnInfo
+TRANS(TLIReopenCLTSServer)(thistrans, fd, port)
+
+Xtransport     *thistrans;
+int            fd;
+char           *port;
+
+{
+    XtransConnInfo     ciptr;
+    int                i;
+    
+    PRMSG(2,"TLIReopenCLTSServer(%d, %s)\n", fd, port, 0 );
+    
+    if( (i=TRANS(TLISelectFamily)(thistrans->TransName)) < 0 )
+    {
+       PRMSG(1,
+             "TLIReopenCLTSServer: Unable to determine device for %s\n",
+             thistrans->TransName, 0,0 );
+       return NULL;
+    }
+
+    if( (ciptr=TRANS(TLIReopen)(
+       TLItrans2devtab[i].devcltsname, fd, port)) == NULL )
+    {
+       PRMSG(1,
+             "TLIReopenCLTSServer: Unable to open device for %s\n",
+             thistrans->TransName, 0,0 );
+       return NULL;
+    }
+    
+    ciptr->index = i;
+
+    return ciptr;
+}                      
+
+#endif /* TRANS_REOPEN */
+
+
+static
+TRANS(TLISetOption)(ciptr, option, arg)
+
+XtransConnInfo ciptr;
+int            option;
+int            arg;
+
+{
+    PRMSG(2,"TLISetOption(%d,%d,%d)\n", ciptr->fd, option, arg );
+    
+    return -1;
+}
+
+
+#ifdef TRANS_SERVER
+
+static
+TRANS(TLICreateListener)(ciptr, req)
+
+XtransConnInfo ciptr;
+struct t_bind  *req;
+
+{
+    struct t_bind      *ret;
+    
+    PRMSG(2,"TLICreateListener(%x->%d,%x)\n", ciptr, ciptr->fd, req );
+    
+    if( (ret=(struct t_bind *)t_alloc(ciptr->fd,T_BIND,T_ALL)) == NULL )
+    {
+       PRMSG(1, "TLICreateListener: failed to allocate a t_bind\n",
+             0,0,0 );
+       return TRANS_CREATE_LISTENER_FAILED;
+    }
+    
+    if( t_bind(ciptr->fd, req, ret) < 0 )
+    {
+       PRMSG(1, "TLICreateListener: t_bind failed\n", 0,0,0 );
+       t_free((char *)req,T_BIND);
+       t_free((char *)ret,T_BIND);
+       return TRANS_CREATE_LISTENER_FAILED;
+    }
+    
+    if( memcmp(req->addr.buf,ret->addr.buf,req->addr.len) != 0 )
+    {
+       PRMSG(1, "TLICreateListener: unable to bind to %x\n",
+             req, 0,0 );
+       t_free((char *)req,T_BIND);
+       t_free((char *)ret,T_BIND);
+       return TRANS_ADDR_IN_USE;
+    }
+    
+    /*
+     * Everything looks good: fill in the XtransConnInfo structure.
+     */
+    
+    if( (ciptr->addr=(char *)xalloc(ret->addr.len)) == NULL )
+    {
+       PRMSG(1,
+             "TLICreateListener: Unable to allocate space for the address\n",
+             0,0,0 );
+       t_free((char *)req,T_BIND);
+       t_free((char *)ret, T_BIND);
+       return TRANS_CREATE_LISTENER_FAILED;
+    }
+    
+    ciptr->addrlen=ret->addr.len;
+    memcpy(ciptr->addr,ret->addr.buf,ret->addr.len);
+    
+    t_free((char *)req,T_BIND);
+    t_free((char *)ret, T_BIND);
+    
+    return 0;
+}
+
+
+static
+TRANS(TLIINETCreateListener)(ciptr, port)
+
+XtransConnInfo ciptr;
+char           *port;
+
+{
+#define PORTBUFSIZE     64      /* what is a real size for this? */
+    char    portbuf[PORTBUFSIZE];
+    struct t_bind      *req;
+    struct sockaddr_in *sinaddr;
+    
+    PRMSG(2,"TLIINETCreateListener(%x->%d,%s)\n", ciptr,
+       ciptr->fd, port ? port : "NULL" );
+    
+#ifdef X11_t
+    /*
+     * X has a well known port, that is transport dependent. It is easier
+     * to handle it here, than try and come up with a transport independent
+     * representation that can be passed in and resolved the usual way.
+     *
+     * The port that is passed here is really a string containing the idisplay
+     * from ConnectDisplay().
+     */
+    
+    if (is_numeric (port))
+    {
+       short tmpport = (short) atoi (port);
+       
+       sprintf(portbuf,"%d", X_TCP_PORT+tmpport );
+    }
+    else
+       strncpy(portbuf,port,PORTBUFSIZE);
+    port=portbuf;
+#endif
+    
+    if( (req=(struct t_bind *)t_alloc(ciptr->fd,T_BIND,T_ALL)) == NULL )
+    {
+       PRMSG(1,
+           "TLIINETCreateListener: failed to allocate a t_bind\n",
+           0,0,0 );
+       return TRANS_CREATE_LISTENER_FAILED;
+    }
+
+    if( port && *port ) {
+       if(TRANS(TLIAddrToNetbuf)(ciptr->index,HOST_SELF,port,&(req->addr)) < 0)
+       {
+           PRMSG(1,
+                 "TLIINETCreateListener: can't resolve name:HOST_SELF.%s\n",
+                 port, 0,0 );
+           t_free((char *)req,T_BIND);
+           return TRANS_CREATE_LISTENER_FAILED;
+       }
+    } else {
+       sinaddr=(struct sockaddr_in *)req->addr.buf;
+       sinaddr->sin_family=AF_INET;
+       sinaddr->sin_port=0;
+       sinaddr->sin_addr.s_addr=0;
+    }
+
+    /* Set the qlen */
+
+    req->qlen=1;
+    
+    return TRANS(TLICreateListener)(ciptr, req);
+}
+
+
+static
+TRANS(TLITLICreateListener)(ciptr, port)
+
+XtransConnInfo ciptr;
+char           *port;
+
+{
+    struct t_bind      *req;
+    struct sockaddr_un *sunaddr;
+    
+    PRMSG(2,"TLITLICreateListener(%x->%d,%s)\n", ciptr, ciptr->fd,
+       port ? port : "NULL");
+    
+    if( (req=(struct t_bind *)t_alloc(ciptr->fd,T_BIND,0)) == NULL )
+    {
+       PRMSG(1,
+             "TLITLICreateListener: failed to allocate a t_bind\n",
+             0,0,0 );
+       return TRANS_CREATE_LISTENER_FAILED;
+    }
+    
+    if( (sunaddr=(struct sockaddr_un *)
+        malloc(sizeof(struct sockaddr_un))) == NULL )
+    {
+       PRMSG(1,
+             "TLITLICreateListener: failed to allocate a sockaddr_un\n",
+             0,0,0 );
+       t_free((char *)req,T_BIND);
+       return TRANS_CREATE_LISTENER_FAILED;
+    }
+    
+    sunaddr->sun_family=AF_UNIX;
+    if( port && *port ) {
+       if( *port == '/' ) { /* A full pathname */
+           (void) strcpy(sunaddr->sun_path, port);
+       } else {
+           (void) sprintf(sunaddr->sun_path,"%s%s", TLINODENAME, port );
+       }
+    } else {
+       (void) sprintf(sunaddr->sun_path,"%s%d", TLINODENAME, getpid());
+    }
+    
+    req->addr.buf=(char *)sunaddr;
+    req->addr.len=sizeof(*sunaddr);
+    req->addr.maxlen=sizeof(*sunaddr);
+    
+    /* Set the qlen */
+    
+    req->qlen=1;
+    
+    return TRANS(TLICreateListener)(ciptr, req);
+}
+
+
+static XtransConnInfo
+TRANS(TLIAccept)(ciptr, status)
+
+XtransConnInfo ciptr;
+int            *status;
+
+{
+    struct t_call      *call;
+    XtransConnInfo     newciptr;
+    int        i;
+    
+    PRMSG(2,"TLIAccept(%x->%d)\n", ciptr, ciptr->fd, 0 );
+    
+    if( (call=(struct t_call *)t_alloc(ciptr->fd,T_CALL,T_ALL)) == NULL )
+    {
+       PRMSG(1, "TLIAccept() failed to allocate a t_call\n", 0,0,0 );
+       *status = TRANS_ACCEPT_BAD_MALLOC;
+       return NULL;
+    }
+    
+    if( t_listen(ciptr->fd,call) < 0 )
+    {
+       extern char *t_errlist[];
+       extern int t_errno;
+       PRMSG(1, "TLIAccept() t_listen() failed\n", 0,0,0 );
+       PRMSG(1, "TLIAccept: %s\n", t_errlist[t_errno], 0,0 );
+       t_free((char *)call,T_CALL);
+       *status = TRANS_ACCEPT_MISC_ERROR;
+       return NULL;
+    }
+    
+    /*
+     * Now we need to set up the new endpoint for the incoming connection.
+     */
+    
+    i=ciptr->index; /* Makes the next line more readable */
+    
+    if( (newciptr=TRANS(TLIOpen)(TLItrans2devtab[i].devcotsname)) == NULL )
+    {
+       PRMSG(1, "TLIAccept() failed to open a new endpoint\n", 0,0,0 );
+       t_free((char *)call,T_CALL);
+       *status = TRANS_ACCEPT_MISC_ERROR;
+       return NULL;
+    }
+    
+    if( TRANS(TLITLIBindLocal)(newciptr->fd,TLItrans2devtab[i].family,"") < 0 )
+    {
+       PRMSG(1,
+             "TLIAccept: TRANS(TLITLIBindLocal)() failed: %d\n",
+             errno, 0,0 );
+       t_free((char *)call,T_CALL);
+       t_close(newciptr->fd);
+       xfree(newciptr);
+       *status = TRANS_ACCEPT_MISC_ERROR;
+       return NULL;
+    }
+    
+    
+    if( t_accept(ciptr->fd,newciptr->fd,call) < 0 )
+    {
+       extern char *t_errlist[];
+       extern int t_errno;
+       PRMSG(1, "TLIAccept() t_accept() failed\n", 0,0,0 );
+       PRMSG(1, "TLIAccept: %s\n", t_errlist[t_errno], 0,0 );
+       t_free((char *)call,T_CALL);
+       t_close(newciptr->fd);
+       xfree(newciptr->addr);
+       xfree(newciptr);
+       *status = TRANS_ACCEPT_FAILED;
+       return NULL;
+    }
+    
+    t_free((char *)call,T_CALL);
+    
+    if( TRANS(TLIGetAddr)(newciptr) < 0 )
+    {
+       PRMSG(1,
+             "TLIAccept: TRANS(TLIGetPeerAddr)() failed: %d\n",
+             errno, 0,0 );
+       t_close(newciptr->fd);
+       xfree(newciptr);
+       *status = TRANS_ACCEPT_MISC_ERROR;
+       return NULL;
+    }
+    
+    if( TRANS(TLIGetPeerAddr)(newciptr) < 0 )
+    {
+       PRMSG(1,
+             "TLIAccept: TRANS(TLIGetPeerAddr)() failed: %d\n",
+             errno, 0,0 );
+       t_close(newciptr->fd);
+       xfree(newciptr->addr);
+       xfree(newciptr);
+       *status = TRANS_ACCEPT_MISC_ERROR;
+       return NULL;
+    }
+    
+    if( ioctl(newciptr->fd, I_POP,"timod") < 0 )
+    {
+       PRMSG(1, "TLIAccept() ioctl(I_POP, \"timod\") failed %d\n",
+             errno,0,0 );
+       t_close(newciptr->fd);
+       xfree(newciptr->addr);
+       xfree(newciptr);
+       *status = TRANS_ACCEPT_MISC_ERROR;
+       return NULL;
+    }
+    
+    if( ioctl(newciptr->fd, I_PUSH,"tirdwr") < 0 )
+    {
+       PRMSG(1, "TLIAccept() ioctl(I_PUSH,\"tirdwr\") failed %d\n",
+             errno,0,0 );
+       t_close(newciptr->fd);
+       xfree(newciptr->addr);
+       xfree(newciptr);
+       *status = TRANS_ACCEPT_MISC_ERROR;
+       return NULL;
+    }
+    
+    *status = 0;
+
+    return newciptr;
+}
+
+#endif /* TRANS_SERVER */
+
+
+#ifdef TRANS_CLIENT
+
+static
+TRANS(TLIConnect)(ciptr, sndcall )
+
+XtransConnInfo ciptr;
+struct t_call  *sndcall;
+
+{
+    PRMSG(2, "TLIConnect(%x->%d,%x)\n", ciptr, ciptr->fd, sndcall);
+    
+    if( t_connect(ciptr->fd,sndcall,NULL) < 0 )
+    {
+       extern char *t_errlist[];
+       extern int t_errno;
+       PRMSG(1, "TLIConnect() t_connect() failed\n", 0,0,0 );
+       PRMSG(1, "TLIConnect: %s\n", t_errlist[t_errno], 0,0 );
+       t_free((char *)sndcall,T_CALL);
+       if (t_errno == TLOOK && t_look(ciptr->fd) == T_DISCONNECT)
+       {
+           t_rcvdis(ciptr->fd,NULL);
+           return TRANS_TRY_CONNECT_AGAIN;
+       }
+       else
+           return TRANS_CONNECT_FAILED;
+    }
+    
+    t_free((char *)sndcall,T_CALL);
+    
+    /*
+     * Sync up the address fields of ciptr.
+     */
+    
+    if( TRANS(TLIGetAddr)(ciptr) < 0 )
+    {
+       PRMSG(1,
+             "TLIConnect: ...TLIGetAddr() failed: %d\n",
+             errno, 0,0 );
+       return TRANS_CONNECT_FAILED;
+    }
+    
+    if( TRANS(TLIGetPeerAddr)(ciptr) < 0 )
+    {
+       PRMSG(1,
+             "TLIConnect: ...TLIGetPeerAddr() failed: %d\n",
+             errno, 0,0 );
+       return TRANS_CONNECT_FAILED;
+    }
+    
+    if( ioctl(ciptr->fd, I_POP,"timod") < 0 )
+    {
+       PRMSG(1, "TLIConnect() ioctl(I_POP,\"timod\") failed %d\n",
+             errno,0,0 );
+       return TRANS_CONNECT_FAILED;
+    }
+    
+    if( ioctl(ciptr->fd, I_PUSH,"tirdwr") < 0 )
+    {
+       PRMSG(1, "TLIConnect() ioctl(I_PUSH,\"tirdwr\") failed %d\n",
+             errno,0,0 );
+       return TRANS_CONNECT_FAILED;
+    }
+    
+    return 0;
+}
+
+
+static
+TRANS(TLIINETConnect)(ciptr, host, port)
+
+XtransConnInfo ciptr;
+char           *host;
+char           *port;
+
+{
+#define PORTBUFSIZE    64      /* what is a real size for this? */
+    char       portbuf[PORTBUFSIZE];   
+    struct     t_call  *sndcall;
+    
+    PRMSG(2, "TLIINETConnect(%s,%s)\n", host, port, 0);
+    
+#ifdef X11_t
+    /*
+     * X has a well known port, that is transport dependant. It is easier
+     * to handle it here, than try and come up with a transport independent
+     * representation that can be passed in and resolved the usual way.
+     *
+     * The port that is passed here is really a string containing the idisplay
+     * from ConnectDisplay().
+     */
+    
+    if (is_numeric (port))
+    {
+       short tmpport = (short) atoi (port);
+       
+       sprintf(portbuf,"%d", X_TCP_PORT+tmpport );
+    }
+    else
+#endif
+       strncpy(portbuf,port,PORTBUFSIZE);
+    
+    if( (sndcall=(struct t_call *)t_alloc(ciptr->fd,T_CALL,T_ALL)) == NULL )
+    {
+       PRMSG(1, "TLIINETConnect() failed to allocate a t_call\n", 0,0,0 );
+       return TRANS_CONNECT_FAILED;
+    }
+    
+    if( TRANS(TLIAddrToNetbuf)(ciptr->index, host, portbuf, &(sndcall->addr) ) < 0 )
+    {
+       PRMSG(1, "TLIINETConnect() unable to resolve name:%s.%s\n",
+             host, portbuf, 0 );
+       t_free((char *)sndcall,T_CALL);
+       return TRANS_CONNECT_FAILED;
+    }
+    
+    return TRANS(TLIConnect)(ciptr, sndcall );
+}
+
+
+static
+TRANS(TLITLIConnect)(ciptr, host, port)
+
+XtransConnInfo ciptr;
+char           *host;
+char           *port;
+
+{
+    struct t_call      *sndcall;
+    struct sockaddr_un *sunaddr;
+    
+    PRMSG(2, "TLITLIConnect(%s,%s)\n", host, port, 0);
+    
+    if( (sndcall=(struct t_call *)t_alloc(ciptr->fd,T_CALL,T_OPT|T_UDATA)) == NULL )
+    {
+       PRMSG(1, "TLITLIConnect() failed to allocate a t_call\n", 0,0,0 );
+       return TRANS_CONNECT_FAILED;
+    }
+    
+    if( (sunaddr=(struct sockaddr_un *)
+        malloc(sizeof(struct sockaddr_un))) == NULL )
+    {
+       PRMSG(1,
+             "TLITLIConnect: failed to allocate a sockaddr_un\n",
+             0,0,0 );
+       t_free((char *)sndcall,T_CALL);
+       return TRANS_CONNECT_FAILED;
+    }
+    
+    sunaddr->sun_family=AF_UNIX;
+    if( *port == '/' ||
+       strncmp (port, TLINODENAME, strlen (TLINODENAME)) == 0) {
+       /* Use the port as is */
+       (void) strcpy(sunaddr->sun_path, port);
+    } else {
+       (void) sprintf(sunaddr->sun_path,"%s%s", TLINODENAME, port );
+    }
+
+    sndcall->addr.buf=(char *)sunaddr;
+    sndcall->addr.len=sizeof(*sunaddr);
+    sndcall->addr.maxlen=sizeof(*sunaddr);
+    
+    return TRANS(TLIConnect)(ciptr, sndcall );
+}
+
+#endif /* TRANS_CLIENT */
+
+
+static
+TRANS(TLIBytesReadable)(ciptr, pend)
+
+XtransConnInfo ciptr;
+BytesReadable_t        *pend;
+
+{
+    int ret;
+    struct pollfd filedes;
+
+    PRMSG(2, "TLIByteReadable(%x->%d,%x)\n", ciptr, ciptr->fd, pend );
+
+    /*
+     * This function should detect hangup conditions. Use poll to check
+     * if no data is present. On SVR4, the M_HANGUP message sits on the
+     * streams head, and ioctl(N_READ) keeps returning 0 because there is
+     * no data available. The hangup goes undetected, and the client hangs.
+     */
+    
+    ret=ioctl(ciptr->fd, I_NREAD, (char *)pend);
+
+    if( ret != 0 )
+       return ret; /* Data present or error */
+
+
+    /* Zero data, or POLLHUP message */
+
+    filedes.fd=ciptr->fd;
+    filedes.events=POLLIN;
+
+    ret=poll(&filedes, 1, 0);
+    if( ret == 0 ) {
+       *pend=0;
+       return 0; /* Really, no data */
+       }
+
+    if( ret < 0 )
+       return -1; /* just pass back the error */
+
+    if( filedes.revents & (POLLHUP|POLLERR) ) /* check for hangup */
+       return -1;
+
+    /* Should only get here if data arrived after the first ioctl() */
+    return ioctl(ciptr->fd, I_NREAD, (char *)pend);
+}
+
+
+static
+TRANS(TLIRead)(ciptr, buf, size)
+
+XtransConnInfo ciptr;
+char           *buf;
+int            size;
+
+{
+    PRMSG(2, "TLIRead(%d,%x,%d)\n", ciptr->fd, buf, size );
+    
+    return read(ciptr->fd,buf,size);
+}
+
+
+static
+TRANS(TLIWrite)(ciptr, buf, size)
+
+XtransConnInfo ciptr;
+char           *buf;
+int            size;
+
+{
+    PRMSG(2, "TLIWrite(%d,%x,%d)\n", ciptr->fd, buf, size );
+    
+    return write(ciptr->fd,buf,size);
+}
+
+
+static
+TRANS(TLIReadv)(ciptr, buf, size)
+
+XtransConnInfo ciptr;
+struct iovec   *buf;
+int            size;
+
+{
+    PRMSG(2, "TLIReadv(%d,%x,%d)\n", ciptr->fd, buf, size );
+    
+    return READV(ciptr,buf,size);
+}
+
+
+static
+TRANS(TLIWritev)(ciptr, buf, size)
+
+XtransConnInfo ciptr;
+struct iovec   *buf;
+int            size;
+
+{
+    PRMSG(2, "TLIWritev(%d,%x,%d)\n", ciptr->fd, buf, size );
+    
+    return WRITEV(ciptr,buf,size);
+}
+
+
+static
+TRANS(TLIDisconnect)(ciptr)
+
+XtransConnInfo ciptr;
+
+{
+    PRMSG(2, "TLIDisconnect(%x->%d)\n", ciptr, ciptr->fd, 0 );
+    
+    /*
+     * Restore the TLI modules so that the connection can be properly shutdown.
+     * This avoids the situation where a connection goes into the TIME_WAIT
+     * state, and the address remains unavailable for a while.
+     */
+    ioctl(ciptr->fd, I_POP,"tirdwr");
+    ioctl(ciptr->fd, I_PUSH,"timod");
+
+    t_snddis(ciptr->fd,NULL);
+    
+    return 0;
+}
+
+
+static
+TRANS(TLIClose)(ciptr)
+
+XtransConnInfo ciptr;
+
+{
+    PRMSG(2, "TLIClose(%x->%d)\n", ciptr, ciptr->fd, 0 );
+    
+    t_unbind(ciptr->fd);
+
+    return (t_close(ciptr->fd));
+}
+
+
+static
+TRANS(TLICloseForCloning)(ciptr)
+
+XtransConnInfo ciptr;
+
+{
+    /*
+     * Don't unbind.
+     */
+
+    PRMSG(2, "TLICloseForCloning(%x->%d)\n", ciptr, ciptr->fd, 0 );
+    
+    return (t_close(ciptr->fd));
+}
+
+
+Xtransport     TRANS(TLITCPFuncs) = {
+       /* TLI Interface */
+       "tcp",
+        0,
+#ifdef TRANS_CLIENT
+       TRANS(TLIOpenCOTSClient),
+#endif /* TRANS_CLIENT */
+#ifdef TRANS_SERVER
+       TRANS(TLIOpenCOTSServer),
+#endif /* TRANS_SERVER */
+#ifdef TRANS_CLIENT
+       TRANS(TLIOpenCLTSClient),
+#endif /* TRANS_CLIENT */
+#ifdef TRANS_SERVER
+       TRANS(TLIOpenCLTSServer),
+#endif /* TRANS_SERVER */
+#ifdef TRANS_REOPEN
+       TRANS(TLIReopenCOTSServer),
+       TRANS(TLIReopenCLTSServer),
+#endif
+       TRANS(TLISetOption),
+#ifdef TRANS_SERVER
+       TRANS(TLIINETCreateListener),
+       NULL,                                   /* ResetListener */
+       TRANS(TLIAccept),
+#endif /* TRANS_SERVER */
+#ifdef TRANS_CLIENT
+       TRANS(TLIINETConnect),
+#endif /* TRANS_CLIENT */
+       TRANS(TLIBytesReadable),
+       TRANS(TLIRead),
+       TRANS(TLIWrite),
+       TRANS(TLIReadv),
+       TRANS(TLIWritev),
+       TRANS(TLIDisconnect),
+       TRANS(TLIClose),
+       TRANS(TLICloseForCloning),
+};
+
+Xtransport     TRANS(TLIINETFuncs) = {
+       /* TLI Interface */
+       "inet",
+       TRANS_ALIAS,
+#ifdef TRANS_CLIENT
+       TRANS(TLIOpenCOTSClient),
+#endif /* TRANS_CLIENT */
+#ifdef TRANS_SERVER
+       TRANS(TLIOpenCOTSServer),
+#endif /* TRANS_SERVER */
+#ifdef TRANS_CLIENT
+       TRANS(TLIOpenCLTSClient),
+#endif /* TRANS_CLIENT */
+#ifdef TRANS_SERVER
+       TRANS(TLIOpenCLTSServer),
+#endif /* TRANS_SERVER */
+#ifdef TRANS_REOPEN
+       TRANS(TLIReopenCOTSServer),
+       TRANS(TLIReopenCLTSServer),
+#endif
+       TRANS(TLISetOption),
+#ifdef TRANS_SERVER
+       TRANS(TLIINETCreateListener),
+       NULL,                                   /* ResetListener */
+       TRANS(TLIAccept),
+#endif /* TRANS_SERVER */
+#ifdef TRANS_CLIENT
+       TRANS(TLIINETConnect),
+#endif /* TRANS_CLIENT */
+       TRANS(TLIBytesReadable),
+       TRANS(TLIRead),
+       TRANS(TLIWrite),
+       TRANS(TLIReadv),
+       TRANS(TLIWritev),
+       TRANS(TLIDisconnect),
+       TRANS(TLIClose),
+       TRANS(TLICloseForCloning),
+};
+
+Xtransport     TRANS(TLITLIFuncs) = {
+       /* TLI Interface */
+       "tli",
+       0,
+#ifdef TRANS_CLIENT
+       TRANS(TLIOpenCOTSClient),
+#endif /* TRANS_CLIENT */
+#ifdef TRANS_SERVER
+       TRANS(TLIOpenCOTSServer),
+#endif /* TRANS_SERVER */
+#ifdef TRANS_CLIENT
+       TRANS(TLIOpenCLTSClient),
+#endif /* TRANS_CLIENT */
+#ifdef TRANS_SERVER
+       TRANS(TLIOpenCLTSServer),
+#endif /* TRANS_SERVER */
+#ifdef TRANS_REOPEN
+       TRANS(TLIReopenCOTSServer),
+       TRANS(TLIReopenCLTSServer),
+#endif
+       TRANS(TLISetOption),
+#ifdef TRANS_SERVER
+       TRANS(TLITLICreateListener),
+       NULL,                                   /* ResetListener */
+       TRANS(TLIAccept),
+#endif /* TRANS_SERVER */
+#ifdef TRANS_CLIENT
+       TRANS(TLITLIConnect),
+#endif /* TRANS_CLIENT */
+       TRANS(TLIBytesReadable),
+       TRANS(TLIRead),
+       TRANS(TLIWrite),
+       TRANS(TLIReadv),
+       TRANS(TLIWritev),
+       TRANS(TLIDisconnect),
+       TRANS(TLIClose),
+       TRANS(TLICloseForCloning),
+};
diff --git a/Xserver/lib/xtrans/Xtransutil.c b/Xserver/lib/xtrans/Xtransutil.c
new file mode 100644 (file)
index 0000000..5473d2d
--- /dev/null
@@ -0,0 +1,467 @@
+/* $XConsortium: Xtransutil.c /main/32 1996/12/04 10:22:57 lehors $ */
+/* $XFree86: xc/lib/xtrans/Xtransutil.c,v 3.9 1996/12/23 06:04:18 dawes Exp $ */
+/*
+
+Copyright (c) 1993, 1994  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be included
+in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR
+OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall
+not be used in advertising or otherwise to promote the sale, use or
+other dealings in this Software without prior written authorization
+from the X Consortium.
+
+*/
+
+/* Copyright (c) 1993, 1994 NCR Corporation - Dayton, Ohio, USA
+ *
+ * All Rights Reserved
+ *
+ * Permission to use, copy, modify, and distribute this software and its
+ * documentation for any purpose and without fee is hereby granted, provided
+ * that the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the name NCR not be used in advertising
+ * or publicity pertaining to distribution of the software without specific,
+ * written prior permission.  NCR makes no representations about the
+ * suitability of this software for any purpose.  It is provided "as is"
+ * without express or implied warranty.
+ *
+ * NCRS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN
+ * NO EVENT SHALL NCR BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
+ * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
+ * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
+ * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+/*
+ * These are some utility functions created for convenience or to provide
+ * an interface that is similar to an existing interface. These are built
+ * only using the Transport Independant API, and have no knowledge of
+ * the internal implementation.
+ */
+
+#ifdef XTHREADS
+#include <X11/Xthreads.h>
+#endif
+
+#ifdef X11_t
+
+/*
+ * These values come from X.h and Xauth.h, and MUST match them. Some
+ * of these values are also defined by the ChangeHost protocol message.
+ */
+
+#define FamilyInternet         0
+#define FamilyDECnet           1
+#define FamilyChaos            2
+#define FamilyAmoeba           33
+#define FamilyLocalHost                252
+#define FamilyKrb5Principal    253
+#define FamilyNetname          254
+#define FamilyLocal            256
+#define FamilyWild             65535
+
+/*
+ * TRANS(ConvertAddress) converts a sockaddr based address to an
+ * X authorization based address. Some of this is defined as part of
+ * the ChangeHost protocol. The rest is just doen in a consistent manner.
+ */
+
+int
+TRANS(ConvertAddress)(familyp,addrlenp,addrp)
+int    *familyp;
+int    *addrlenp;
+Xtransaddr     **addrp;
+{
+
+    PRMSG(2,"ConvertAddress(%d,%d,%x)\n",*familyp,*addrlenp,*addrp);
+
+    switch( *familyp )
+    {
+#if defined(TCPCONN) || defined(STREAMSCONN) || defined(MNX_TCPCONN)
+    case AF_INET:
+    {
+       /*
+        * Check for the BSD hack localhost address 127.0.0.1.
+        * In this case, we are really FamilyLocal.
+        */
+
+       struct sockaddr_in saddr;
+#ifdef CRAY
+#ifdef OLDTCP
+       int len = sizeof(saddr.sin_addr);
+#else
+       int len = SIZEOF_in_addr;
+#endif /* OLDTCP */
+       char *cp = (char *) &saddr.sin_addr;
+#else /* else not CRAY */
+       int len = sizeof(saddr.sin_addr.s_addr);
+       char *cp = (char *) &saddr.sin_addr.s_addr;
+#endif /* CRAY */
+
+       memcpy (&saddr, *addrp, sizeof (struct sockaddr_in));
+
+       if ((len == 4) && (cp[0] == 127) && (cp[1] == 0) &&
+           (cp[2] == 0) && (cp[3] == 1))
+       {
+           *familyp=FamilyLocal;
+       }
+       else
+       {
+           *familyp=FamilyInternet;
+           *addrlenp=len;
+           memcpy(*addrp,&saddr.sin_addr,len);
+       }
+       break;
+    }
+#endif /* defined(TCPCONN) || defined(STREAMSCONN) || MNX_TCPCONN */
+
+#if defined(DNETCONN)
+    case AF_DECnet:
+    {
+       struct sockaddr_dn saddr;
+
+       memcpy (&saddr, *addrp, sizeof (struct sockaddr_dn));
+
+       *familyp=FamilyDECnet;
+       *addrlenp=sizeof(struct dn_naddr);
+       memcpy(*addrp,&saddr.sdn_add,*addrlenp);
+
+       break;
+    }
+#endif /* defined(DNETCONN) */
+
+#if defined(UNIXCONN) || defined(LOCALCONN) || defined(OS2PIPECONN)
+    case AF_UNIX:
+    {
+       *familyp=FamilyLocal;
+       break;
+    }
+#endif /* defined(UNIXCONN) || defined(LOCALCONN) || defined(OS2PIPECONN)*/
+
+#if defined(AMRPCCONN)
+    case AF_AMOEBA:
+    {
+       *familyp=FamilyAmoeba;
+       break;
+    }
+#endif
+#if defined(AMTCPCONN) && !(defined(TCPCONN) || defined(STREAMSCONN))
+    case AF_INET:
+    {
+       *familyp=FamilyInternet;
+       break;
+    }
+#endif
+
+    default:
+       PRMSG(1,"ConvertAddress: Unknown family type %d\n",
+             *familyp, 0,0 );
+       return -1;
+    }
+
+
+    if (*familyp == FamilyLocal)
+    {
+       /*
+        * In the case of a local connection, we need to get the
+        * host name for authentication.
+        */
+       
+       char hostnamebuf[256];
+       int len = TRANS(GetHostname) (hostnamebuf, sizeof hostnamebuf);
+
+       if (len > 0) {
+           if (*addrp && *addrlenp < (len + 1))
+           {
+               xfree ((char *) *addrp);
+               *addrp = NULL;
+           }
+           if (!*addrp)
+               *addrp = (Xtransaddr *) xalloc (len + 1);
+           if (*addrp) {
+               strcpy ((char *) *addrp, hostnamebuf);
+               *addrlenp = len;
+           } else {
+               *addrlenp = 0;
+           }
+       }
+       else
+       {
+           if (*addrp)
+               xfree ((char *) *addrp);
+           *addrp = NULL;
+           *addrlenp = 0;
+       }
+    }
+
+    return 0;
+}
+
+#endif /* X11_t */
+
+#ifdef ICE_t
+
+#include <signal.h>
+
+char *
+TRANS(GetMyNetworkId) (ciptr)
+
+XtransConnInfo  ciptr;
+
+{
+    int                family = ciptr->family;
+    int                addrlen = ciptr->addrlen;
+    char       *addr = ciptr->addr;
+    char       hostnamebuf[256];
+    char       *networkId = NULL;
+    char       *transName = ciptr->transptr->TransName;
+
+    if (gethostname (hostnamebuf, sizeof (hostnamebuf)) < 0)
+    {
+       return (NULL);
+    }
+
+    switch (family)
+    {
+#if defined(UNIXCONN) || defined(STREAMSCONN) || defined(LOCALCONN) || defined(OS2PIPECONN)
+    case AF_UNIX:
+    {
+       struct sockaddr_un *saddr = (struct sockaddr_un *) addr;
+       networkId = (char *) xalloc (3 + strlen (transName) +
+           strlen (hostnamebuf) + strlen (saddr->sun_path));
+       sprintf (networkId, "%s/%s:%s", transName,
+           hostnamebuf, saddr->sun_path);
+       break;
+    }
+#endif /* defined(UNIXCONN) || defined(STREAMSCONN) || defined(LOCALCONN) || defined(OS2PIPECONN)
+*/
+
+#if defined(TCPCONN) || defined(STREAMSCONN) || defined(MNX_TCPCONN)
+    case AF_INET:
+    {
+       struct sockaddr_in *saddr = (struct sockaddr_in *) addr;
+       char portnumbuf[10];
+
+       sprintf (portnumbuf, "%d", ntohs (saddr->sin_port));
+       networkId = (char *) xalloc (3 + strlen (transName) +
+           strlen (hostnamebuf) + strlen (portnumbuf));
+       sprintf (networkId, "%s/%s:%s", transName, hostnamebuf, portnumbuf);
+       break;
+    }
+#endif /* defined(TCPCONN) || defined(STREAMSCONN) || MNX_TCPCONN */
+
+#if defined(DNETCONN)
+    case AF_DECnet:
+    {
+       struct sockaddr_dn *saddr = (struct sockaddr_dn *) addr;
+
+       networkId = (char *) xalloc (
+           13 + strlen (hostnamebuf) + saddr->sdn_objnamel);
+       sprintf (networkId, "dnet/%s::%s",
+           hostnamebuf, saddr->sdn_objname);
+       break;
+    }
+#endif /* defined(DNETCONN) */
+
+    default:
+       break;
+    }
+
+    return (networkId);
+}
+
+#include <setjmp.h>
+static jmp_buf env;
+
+#ifdef SIGALRM
+static int nameserver_timedout = 0;
+
+static 
+#ifdef SIGNALRETURNSINT
+int
+#else
+void
+#endif
+nameserver_lost(sig)
+{
+  nameserver_timedout = 1;
+  longjmp (env, -1);
+  /* NOTREACHED */
+#ifdef SIGNALRETURNSINT
+  return -1;                           /* for picky compilers */
+#endif
+}
+#endif /* SIGALARM */
+
+
+char *
+TRANS(GetPeerNetworkId) (ciptr)
+
+XtransConnInfo  ciptr;
+
+{
+    int                family = ciptr->family;
+    int                peer_addrlen = ciptr->peeraddrlen;
+    char       *peer_addr = ciptr->peeraddr;
+    char       *hostname;
+    char       *networkId = NULL;
+    char       addrbuf[256];
+    char       *addr = NULL;
+
+    switch (family)
+    {
+    case AF_UNSPEC:
+#if defined(UNIXCONN) || defined(STREAMSCONN) || defined(LOCALCONN) || defined(OS2PIPECONN)
+    case AF_UNIX:
+    {
+       if (gethostname (addrbuf, sizeof (addrbuf)) == 0)
+           addr = addrbuf;
+       break;
+    }
+#endif /* defined(UNIXCONN) || defined(STREAMSCONN) || defined(LOCALCONN) || defined(OS2PIPECONN)
+*/
+
+#if defined(TCPCONN) || defined(STREAMSCONN) || defined(MNX_TCPCONN)
+    case AF_INET:
+    {
+       struct sockaddr_in *saddr = (struct sockaddr_in *) peer_addr;
+       _Xgethostbynameparams hparams;
+       struct hostent * hostp;
+
+#ifndef WIN32
+       char *inet_ntoa();
+#endif
+
+#ifdef SIGALRM
+       /*
+        * gethostbyaddr can take a LONG time if the host does not exist.
+        * Assume that if it does not respond in NAMESERVER_TIMEOUT seconds
+        * that something is wrong and do not make the user wait.
+        * gethostbyaddr will continue after a signal, so we have to
+        * jump out of it. 
+        */
+
+       nameserver_timedout = 0;
+       signal (SIGALRM, nameserver_lost);
+       alarm (4);
+       if (setjmp(env) == 0) {
+#endif
+           hostp = _XGethostbyaddr ((char *) &saddr->sin_addr,
+               sizeof (saddr->sin_addr), AF_INET, hparams);
+#ifdef SIGALRM
+       }
+       alarm (0);
+#endif
+       if (hostp != NULL)
+         addr = hostp->h_name;
+       else
+         addr = inet_ntoa (saddr->sin_addr);
+       break;
+    }
+
+#endif /* defined(TCPCONN) || defined(STREAMSCONN) || MNX_TCPCONN */
+
+#if defined(DNETCONN)
+    case AF_DECnet:
+    {
+       struct sockaddr_dn *saddr = (struct sockaddr_dn *) peer_addr;
+       struct nodeent *np;
+
+       if (np = getnodebyaddr(saddr->sdn_add.a_addr,
+           saddr->sdn_add.a_len, AF_DECnet)) {
+           sprintf(addrbuf, "%s:", np->n_name);
+       } else {
+           sprintf(addrbuf, "%s:", dnet_htoa(&saddr->sdn_add));
+       }
+       addr = addrbuf;
+       break;
+    }
+#endif /* defined(DNETCONN) */
+
+#if defined(AMRPCCONN)
+    case AF_AMOEBA:
+    {
+       addr = "Amoeba"; /* not really used */
+       break;
+    }
+#endif
+#if defined(AMTCPCONN) && !(defined(TCPCONN) || defined(STREAMSCONN))
+    case AF_INET:
+    {
+       if (gethostname (addrbuf, sizeof (addrbuf)) == 0) {
+           addr = addrbuf;
+       } else {
+           addr = "";
+       }
+       break;
+    }
+#endif
+
+    default:
+       return (NULL);
+    }
+
+
+    hostname = (char *) xalloc (
+       strlen (ciptr->transptr->TransName) + strlen (addr) + 2);
+    strcpy (hostname, ciptr->transptr->TransName);
+    strcat (hostname, "/");
+    if (addr)
+       strcat (hostname, addr);
+
+    return (hostname);
+}
+
+#endif /* ICE_t */
+
+
+#if defined(WIN32) && (defined(TCPCONN) || defined(DNETCONN))
+int
+TRANS(WSAStartup) ()
+{
+    static WSADATA wsadata;
+
+    PRMSG (2,"WSAStartup()\n", 0, 0, 0);
+
+    if (!wsadata.wVersion && WSAStartup(MAKEWORD(1,1), &wsadata))
+        return 1;
+    return 0;
+}
+#endif
+
+
+static int
+is_numeric (str)
+
+char *str;
+
+{
+    int i;
+
+    for (i = 0; i < (int) strlen (str); i++)
+       if (!isdigit (str[i]))
+           return (0);
+
+    return (1);
+}
diff --git a/Xserver/lib/xtrans/transport.c b/Xserver/lib/xtrans/transport.c
new file mode 100644 (file)
index 0000000..ee9feae
--- /dev/null
@@ -0,0 +1,92 @@
+/* $XConsortium: transport.c,v 1.6 94/04/17 20:23:07 mor Exp $ */
+/* $XFree86: xc/lib/xtrans/transport.c,v 3.3 1996/05/06 05:55:14 dawes Exp $ */
+/*
+
+Copyright (c) 1993, 1994  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be included
+in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR
+OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall
+not be used in advertising or otherwise to promote the sale, use or
+other dealings in this Software without prior written authorization
+from the X Consortium.
+
+*/
+
+/* Copyright (c) 1993, 1994 NCR Corporation - Dayton, Ohio, USA
+ *
+ * All Rights Reserved
+ *
+ * Permission to use, copy, modify, and distribute this software and its
+ * documentation for any purpose and without fee is hereby granted, provided
+ * that the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the name NCR not be used in advertising
+ * or publicity pertaining to distribution of the software without specific,
+ * written prior permission.  NCR makes no representations about the
+ * suitability of this software for any purpose.  It is provided "as is"
+ * without express or implied warranty.
+ *
+ * NCR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN
+ * NO EVENT SHALL NCR BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
+ * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
+ * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
+ * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#ifdef XSERV_t
+#include "os.h"
+#else
+#ifndef X_NOT_STDC_ENV
+#include <stdlib.h>
+#endif
+#define xalloc(_size)          malloc(_size)
+#define xcalloc(_num,_size)    calloc(_num,_size)
+#define xrealloc(_ptr,_size)   realloc(_ptr,_size)
+#define xfree(_ptr)            free(_ptr)
+#endif
+
+#include "Xtransint.h"
+
+#ifdef DNETCONN
+#include "Xtransdnet.c"
+#endif
+#ifdef LOCALCONN
+#include "Xtranslcl.c"
+#endif
+#ifdef OS2PIPECONN
+#include "Xtransos2.c"
+#endif
+#if defined(TCPCONN) || defined(UNIXCONN)
+#include "Xtranssock.c"
+#endif
+#ifdef STREAMSCONN
+#include "Xtranstli.c"
+#endif
+#if defined(AMRPCCONN) || defined(AMTCPCONN)
+#include "Xtransam.c"
+#endif
+#if defined(MNX_TCPCONN)
+#include "Xtransmnx.c"
+#endif
+#include "Xtrans.c"
+#include "Xtransutil.c"
diff --git a/Xserver/programs/Imakefile b/Xserver/programs/Imakefile
new file mode 100644 (file)
index 0000000..bf9e096
--- /dev/null
@@ -0,0 +1,72 @@
+XCOMM $XConsortium: Imakefile /main/83 1996/12/18 16:29:30 lehors $
+XCOMM $XFree86: xc/programs/Imakefile,v 3.15.2.2 1998/02/15 16:08:40 hohndel Exp $
+#define IHaveSubdirs
+#define PassCDebugFlags CDEBUGFLAGS="$(CDEBUGFLAGS)"
+
+#if BuildServer
+       RGBSRCDIR = rgb
+        XSSRCDIR = Xserver
+#endif
+#ifndef Win32Architecture
+#if HasXServer
+     XINITSRCDIR = xinit
+#endif
+#if BuildFontServer
+       XFSSRCDIR = xfs
+#endif
+#if BuildXKBlib
+      XKBSRCDIRS = setxkbmap xkbcomp xkbevd xkbprint xkbutils
+#endif
+#if BuildScreenSaverExt
+SCREENSAVESRCDIR = beforelight
+#endif
+#if BuildXF86VidModeExt
+  XVIDTUNESRCDIR = xvidtune
+#endif
+#if BuildXF86DGA
+   XF86DGASRCDIR = xf86dga
+#endif
+#if BuildXAServer
+       XASSRCDIR = Xaserver
+#endif
+#if BuildLBX
+  LBXPROXYSRCDIR = lbxproxy
+#endif
+  PROXYMGRSRCDIR = proxymngr
+    RSTARTSRCDIR = rstart
+   SMPROXYSRCDIR = smproxy
+       TWMSRCDIR = twm
+  XCONSOLESRCDIR = xconsole
+       XDMSRCDIR = xdm
+XFINDPROXYSRCDIR = xfindproxy
+      XFWPSRCDIR = xfwp
+     XHOSTSRCDIR = xhost
+       XMHSRCDIR = xmh
+       XRXSRCDIR = xrx
+       XSMSRCDIR = xsm
+     XTERMSRCDIR = xterm
+      SCRIPTSDIR = scripts
+#endif
+
+#if BuildServersOnly
+SUBDIRS = $(XSSRCDIR)
+#else
+SUBDIRS = \
+       appres bdftopcf bitmap $(SCREENSAVESRCDIR) editres fsinfo \
+       fslsfonts fstobdf \
+       iceauth mkfontdir oclock $(PROXYMGRSRCDIR) \
+       $(RGBSRCDIR) $(RSTARTSRCDIR) $(SMPROXYSRCDIR) $(TWMSRCDIR) x11perf \
+       xauth xclipboard xclock xcmsdb $(XCONSOLESRCDIR) $(XDMSRCDIR) \
+       xdpyinfo $(XF86DGASRCDIR) xfd $(XFSSRCDIR) $(XFINDPROXYSRCDIR) \
+       $(XFWPSRCDIR) \
+       $(XHOSTSRCDIR) xieperf $(XINITSRCDIR) $(XKBSRCDIRS) xkill xlogo \
+       xlsatoms xlsclients xlsfonts xmag $(XMHSRCDIR) xmodmap xprop \
+       xrdb xrefresh $(XRXSRCDIR) xset xsetroot $(XSMSRCDIR) xstdcmap \
+       xsetmode xsetpointer \
+       $(XTERMSRCDIR) $(XVIDTUNESRCDIR) xwd xwininfo xwud \
+       $(XSSRCDIR) $(XASSRCDIR) \
+       $(LBXPROXYSRCDIR) $(SCRIPTSDIR)
+#endif
+
+MakeSubdirs($(SUBDIRS))
+DependSubdirs($(SUBDIRS))
diff --git a/Xserver/programs/Xserver/Imakefile b/Xserver/programs/Xserver/Imakefile
new file mode 100644 (file)
index 0000000..7c9f941
--- /dev/null
@@ -0,0 +1,1743 @@
+XCOMM $TOG: Imakefile /main/235 1997/05/25 15:12:21 kaleb $
+/*
+ * Server Master Makefile
+ */
+XCOMM $XFree86: xc/programs/Xserver/Imakefile,v 3.85.2.8 1998/02/07 00:44:33 dawes Exp $
+
+#include <Server.tmpl>
+
+#ifdef XFree86Version
+/* Don't strip server binaries */
+INSTPGMFLAGS = 
+#endif
+
+#define PreFbLibs $(DIX) $(OS) $(FONT) $(XPDDX)
+#define BarePostFbLibs $(MFB) $(XPFBLIBS) $(MI)
+#define PostFbLibs BarePostFbLibs $(EXTENSIONS)
+#define NoMfbBarePostFbLibs $(XPFBLIBS) $(MI)
+#define NoMfbPostFbLibs NoMfbBarePostFbLibs $(EXTENSIONS)
+
+#define MFBBareLibs PreFbLibs BarePostFbLibs
+#define NoMFBBareLibs PreFbLibs NoMfbBarePostFbLibs
+#define MFBLibs PreFbLibs PostFbLibs
+#define NoMFBLibs PreFbLibs NoMfbPostFbLibs
+#define CFBLibs PreFbLibs $(CFB) PostFbLibs
+#define CFB4Libs PreFbLibs $(CFB4) PostFbLibs
+#define CFB8Libs PreFbLibs $(CFB8) PostFbLibs
+#define CFB16Libs PreFbLibs $(CFB16) PostFbLibs
+#define CFB24Libs PreFbLibs $(CFB24) PostFbLibs
+#define CFB32Libs PreFbLibs $(CFB32) PostFbLibs
+
+#if BuildPexExt
+         PEXLIBS = PEX5/dipex/dispatch/LibraryTargetName(didipex) \
+                   PEX5/dipex/swap/LibraryTargetName(diswapex) \
+                   PEX5/dipex/objects/LibraryTargetName(diobpex) \
+                   PEX5/dipex/dispatch/LibraryTargetName(didipex) \
+                   PEX5/ddpex/mi/level4/LibraryTargetName(ddpex4) \
+                   PEX5/ddpex/mi/level3/LibraryTargetName(ddpex3) \
+                   PEX5/ddpex/mi/shared/LibraryTargetName(ddpexs) \
+                   PEX5/ddpex/mi/level2/LibraryTargetName(ddpex2) \
+                   PEX5/ddpex/mi/level1/LibraryTargetName(ddpex1) \
+                  PEX5/ospex/LibraryTargetName(ospex) 
+          PEXDIR = PEX5
+#endif
+#if BuildGlxExt /* && !GlxModule */
+#if GlxStubLib 
+        GLXLIB = glxStub/LibraryTargetName(ServerGlx) 
+        GLXDIR = glxStub 
+#else
+        GLXLIB = GlxStaticServerLib
+        GLXDIR = 
+#endif
+#endif
+
+#if BuildXInputExt
+      XINPUTEXT = Xi/LibraryTargetName(xinput)
+          XIDIR = Xi
+#endif
+#if BuildXIE
+      XIEEXT = XIE/dixie/LibraryTargetName(dixie) XIE/mixie/LibraryTargetName(mixie)
+#endif
+#if BuildXIE || BuildXIElib
+      XIEDIR = XIE
+#endif
+#if BuildXKB
+      XKBEXT = xkb/LibraryTargetName(xkb)
+      XKBDIR = xkb
+#endif
+#if BuildLBX
+         LBXEXT = lbx/LibraryTargetName(lbx) \
+                  $(TOP)/lib/lbxutil/LibraryTargetName(lbxutil)
+        LBXDIRS = lbx
+#endif
+#if BuildDBE
+         DBEEXT = dbe/LibraryTargetName(dbe)
+#endif
+#if BuildDBE || BuildDBElib
+         DBEDIR = dbe
+#endif
+#if BuildRECORD
+         RECORDEXT = record/LibraryTargetName(record)
+#endif
+#if BuildRECORD || BuildRECORDlib
+         RECORDDIR = record
+#endif
+#ifdef SiteExtensionLibs
+     SITEEXTS = SiteExtensionLibs
+#endif
+#ifdef SiteExtensionDirs
+     SITEEXTDIRS = SiteExtensionDirs
+#endif
+
+#if BuildXprint
+
+#ifndef XpRasterDDX
+#define XpRasterDDX NO
+#endif
+#ifndef XpColorPclDDX
+#define XpColorPclDDX YES
+#endif
+#ifndef XpMonoPclDDX
+#define XpMonoPclDDX NO
+#endif
+#ifndef XpPostScriptDDX
+#define XpPostScriptDDX YES
+#endif
+
+#if XpRasterDDX
+XPRASTLIB = Xprint/raster/LibraryTargetName(raster)
+#endif
+#if XpColorPclDDX
+XPPCLLIB = Xprint/pcl/LibraryTargetName(pcl)
+#endif
+#if XpMonoPclDDX
+XPMPCLLIB = Xprint/pcl-mono/LibraryTargetName(pcl)
+#endif
+#if XpPostScriptDDX
+XPPSLIB = Xprint/ps/LibraryTargetName(ps)
+#endif
+
+XPDDXLIBS = Xprint/LibraryTargetName(printer) $(XPRASTLIB) $(XPPCLLIB) $(XPMPCLLIB) $(XPPSLIB)
+XPDDXFBLIBS = $(MFB) $(CFB32)
+#if !PrintOnlyServer
+      XPFBLIBS = $(XPDDXFBLIBS)
+      XPDDX = $(XPDDXLIBS)
+#endif
+      XPDDXDIR = Xprint
+#endif
+#if !BuildXprint || PrintOnlyServer
+XPFBLIBS = dix/LibraryTargetName(xpstubs)
+#endif
+
+      OTHEREXTS = Xext/LibraryTargetName(ext) $(XKBEXT) $(XINPUTEXT) \
+                  $(XIEEXT) $(LBXEXT) $(DBEEXT) $(RECORDEXT) $(SITEEXTS)
+        EXTDIRS = Xext $(XKBDIR) $(XIDIR) $(XIEDIR) $(PEXDIR) $(GLXDIR) \
+                  $(LBXDIRS) $(DBEDIR) $(RECORDDIR) $(SITEEXTDIRS)
+     EXTENSIONS = $(OTHEREXTS) $(PEXLIBS) $(GLXLIB)
+         XAULIB = $(XAUTHSRC)/LibraryTargetName(Xau)
+       XDMCPLIB = $(XDMCPLIBSRC)/LibraryTargetName(Xdmcp)
+#if BuildLBX || GzipFontCompression
+XCOMM           ZLIB = GzipLibrary
+#endif
+             OS = os/LibraryTargetName(os) $(XAULIB) $(XDMCPLIB)
+        BSDEMUL = $(DEPXBSDLIB)
+            MFB = mfb/LibraryTargetName(mfb)
+            CFB = cfb/LibraryTargetName(cfb) cfb16/LibraryTargetName(cfb) cfb24/LibraryTargetName(cfb) cfb32/LibraryTargetName(cfb)
+           CFB8 = cfb/LibraryTargetName(cfb)
+          CFB4  = cfb/LibraryTargetName(cfb) cfb4/LibraryTargetName(cfb)
+          CFB16 = cfb/LibraryTargetName(cfb) cfb16/LibraryTargetName(cfb)
+          CFB24 = cfb/LibraryTargetName(cfb) cfb24/LibraryTargetName(cfb)
+          CFB32 = cfb/LibraryTargetName(cfb) cfb32/LibraryTargetName(cfb)
+             MI = mi/LibraryTargetName(mi)
+            DIX = dix/LibraryTargetName(dix)
+           FONT = $(DEPFONTLIB)
+#ifdef ServerExtraSysLibs
+   EXTRASYSLIBS = ServerExtraSysLibs
+#endif
+#if SystemV4 || defined(SGIArchitecture) || UseRgbTxt
+        SYSLIBS = $(ZLIB) MathLibrary Krb5Libraries $(EXTRASYSLIBS)
+#else
+        SYSLIBS = $(ZLIB) MathLibrary Krb5Libraries DBMLibrary $(EXTRASYSLIBS)
+#endif
+           CBRT = mi/LibraryTargetName(cbrt)
+        STDDIRS = include dix os mi $(XPDDXDIR) $(EXTDIRS)
+
+XCOMM
+XCOMM This turns off the default rule for compiling .c files because
+XCOMM this makefile does not really know how to build it.  This is really
+XCOMM just a hack because of the Sun version of make and nfs.
+XCOMM
+.c.o:
+
+/*               Build rule blocks, add one for each server
+ *  
+ *  If a server needs mfb, its build block should have a line like:
+ *  MFBDIR = mfb
+ *  Similarly, its build block should have:
+ *  CFB4DIR  = cfb4  (if the server needs 4 bit cfb)
+ *  CFB8DIR  = cfb   (8 bit cfb)
+ *  CFB16DIR = cfb16 (16 bit cfb)
+ *  CFB24DIR = cfb24 (24 bit cfb)
+ *  CFB32DIR = cfb32 (32 bit cfb)
+ *  
+ *  If a server does not need all of the above components, simply
+ *  omit the relevant lines from the build block.
+ *  
+ *  Additional ddx directories can be split across three variables:
+ *  DDXDIR1, DDXDIR2, and DDXDIR3.  Most servers only use DDXDIR1,
+ *  but if two servers can be built on a platform then DDXDIR1 is
+ *  typically set to the ddx directories that are shared by both
+ *  servers, DDXDIR2 is the directories unique to one of the servers,
+ *  and DDXDIR3 is the directories unique to the other server.
+ *  
+ *  If these guidelines are followed, a make at the top of the server
+ *  tree should result in each subdirectory being built only once,
+ *  even if multiple servers that share subdirectories are being built.
+ */
+
+#if XdecServer
+XCOMM
+XCOMM Digital MIPS based WS server (ultrix 4.2 and beyond)
+XCOMM
+MFBDIR  = mfb
+CFB8DIR = cfb
+DDXDIR1 = hw/dec/ws
+DECDIRS = $(STDDIRS) $(MFBDIR) $(CFB8DIR) $(DDXDIR1) $(DEPDIRS)
+DECOBJS = hw/dec/ws/init.o hw/dec/ws/sdepthinit.o
+DECLIBS = hw/dec/ws/LibraryTargetName(dec) CFB8Libs
+ServerTarget(Xdec,$(DECDIRS),$(DECOBJS),$(DECLIBS),$(SYSLIBS))
+#ifndef ServerToInstall
+#define ServerToInstall Xdec
+#endif
+#endif /* XdecServer */
+
+
+#if XdecMultiDepthServer
+XCOMM
+XCOMM Digital MIPS based WS server (ultrix 4.2 and beyond)
+XCOMM Supports 8, 12, and 24 bit pixmaps
+XCOMM
+MFBDIR   = mfb
+CFB8DIR  = cfb
+CFB16DIR = cfb16
+CFB24DIR = cfb24
+CFB32DIR = cfb32
+DDXDIR1  = hw/dec/ws
+DECDIRS1 = $(STDDIRS) $(MFBDIR) $(CFB8DIR) $(CFB16DIR) $(CFB24DIR) $(CFB32DIR) $(DDXDIR1) $(DEPDIRS)
+DECOBJS1 = hw/dec/ws/init.o hw/dec/ws/mdepthinit.o
+DECLIBS1 = hw/dec/ws/LibraryTargetName(dec) CFBLibs
+ServerTarget(Xdec_md,$(DECDIRS1),$(DECOBJS1),$(DECLIBS1),$(SYSLIBS))
+#ifndef ServerToInstall
+#define ServerToInstall Xdec_md
+#endif
+#endif /* XdecMultiDepthServer */
+
+
+#if XsunServer
+XCOMM
+XCOMM Sun server
+XCOMM
+MFBDIR = mfb
+CFB8DIR = cfb
+DDXDIR1 = hw/sun
+#ifndef AmoebaArchitecture
+SUNOBJS = hw/sun/sunInit.o
+#else
+SUNOBJS = hw/sun/sunInitColor.o
+#endif
+SUNDIRS = $(STDDIRS) $(MFBDIR) $(CFB8DIR) $(DDXDIR1) $(DEPDIRS)
+SUNLIBS = hw/sun/LibraryTargetName(sun) CFB8Libs
+SUNSYSLIBS = $(WIDECHARSYSLIB) $(SYSLIBS)
+SetUIDServerTarget(Xsun,$(SUNDIRS),$(SUNOBJS),$(SUNLIBS),$(SUNSYSLIBS))
+#ifndef ServerToInstall
+#define ServerToInstall Xsun
+#endif
+#endif /* XsunServer */
+
+
+#if Xsun24Server
+XCOMM
+XCOMM Sun multiple pixmap depth (8, 12, 24) server
+XCOMM
+MFBDIR = mfb
+CFB8DIR = cfb
+CFB16DIR = cfb16
+CFB24DIR = cfb24
+CFB32DIR = cfb32
+DDXDIR1 = hw/sun
+SUN24DIRS = $(STDDIRS) $(MFBDIR) $(CFB8DIR) $(CFB16DIR) $(CFB24DIR) $(CFB32DIR) $(DDXDIR1) $(DEPDIRS)
+SUN24OBJS = hw/sun/sunInitMulti.o
+SUN24LIBS = hw/sun/LibraryTargetName(sun) CFBLibs
+SetUIDServerTarget(Xsun24,$(SUN24DIRS),$(SUN24OBJS),$(SUN24LIBS),$(SYSLIBS))
+#ifndef ServerToInstall
+#define ServerToInstall Xsun24
+#endif
+#endif /* Xsun24Server */
+
+
+#if XsunMonoServer
+XCOMM
+XCOMM Sun monochrome server
+XCOMM
+MFBDIR = mfb
+DDXDIR1 = hw/sun
+SUNMDIRS = $(STDDIRS) $(MFBDIR) $(DDXDIR1) $(DEPDIRS)
+SUNMOBJS = hw/sun/sunInitMono.o hw/sun/sunInExMono.o
+SUNMLIBS = hw/sun/LibraryTargetName(sun) MFBBareLibs $(OTHEREXTS)
+SetUIDServerTarget(XsunMono,$(SUNMDIRS),$(SUNMOBJS),$(SUNMLIBS),$(SYSLIBS))
+#ifndef ServerToInstall
+#define ServerToInstall XsunMono
+#endif
+#endif /* XsunMonoServer */
+
+
+#if XsunAmoebaServer
+XCOMM
+XCOMM Sun server for Amoeba
+XCOMM
+MFBDIR = mfb
+CFB8DIR = cfb
+DDXDIR1 = hw/sunAmoeba
+SUNDIRS = $(STDDIRS) $(MFBDIR) $(CFB8DIR) $(DDXDIR1) $(DEPDIRS)
+SUNOBJS = hw/sunAmoeba/sunInitColor.o
+SUNLIBS = hw/sunAmoeba/LibraryTargetName(sun) CFB8Libs
+ServerTarget(Xsun,$(SUNDIRS),$(SUNOBJS),$(SUNLIBS),$(SYSLIBS))
+#ifndef ServerToInstall
+#define ServerToInstall Xsun
+#endif
+#endif /* XsunAmoebaServer */
+
+
+#if XsunAmoebaMonoServer
+XCOMM
+XCOMM Sun monochrome server for Amoeba
+XCOMM
+MFBDIR = mfb
+DDXDIR1 = hw/sunAmoeba
+SUNMDIRS = $(STDDIRS) $(MFBDIR) $(DDXDIR1) $(DEPDIRS)
+SUNMOBJS = hw/sunAmoeba/sunInitMono.o hw/sunAmoeba/sunInExMono.o
+SUNMLIBS = hw/sunAmoeba/LibraryTargetName(sun) MFBBareLibs $(OTHEREXTS)
+ServerTarget(XsunMono,$(SUNMDIRS),$(SUNMOBJS),$(SUNMLIBS),$(SYSLIBS))
+#ifndef ServerToInstall
+#define ServerToInstall XsunMono
+#endif
+#endif /* XsunAmoebaMonoServer */
+
+
+#if XsunLynxServer
+XCOMM
+XCOMM Sun server for LynxOS microSPARC 2.4.0
+XCOMM
+MFBDIR = mfb
+CFB8DIR = cfb
+DDXDIR1 = hw/sunLynx
+SUNDIRS = $(STDDIRS) $(MFBDIR) $(CFB8DIR) $(DDXDIR1) $(DEPDIRS)
+SUNOBJS = hw/sunLynx/sunLyInit.o
+SUNLIBS = hw/sunLynx/libsun.a CFB8Libs
+ServerTarget(Xsun,$(SUNDIRS),$(SUNOBJS),$(SUNLIBS),$(SYSLIBS))
+#ifndef ServerToInstall
+#define ServerToInstall Xsun
+#endif
+#endif /* XsunLynxServer */
+
+
+#if XsunLynxMonoServer
+XCOMM
+XCOMM Sun monochrome server for LynxOS microSPARC 2.4.0
+XCOMM
+MFBDIR = mfb
+DDXDIR1 = hw/sunLynx
+SUNMDIRS = $(STDDIRS) $(MFBDIR) $(DDXDIR1) $(DEPDIRS)
+SUNMOBJS = hw/sunLynx/sunInitMono.o hw/sunLynx/sunInExMono.o
+SUNMLIBS = hw/sunLynx/libsun.a MFBBareLibs $(OTHEREXTS)
+ServerTarget(XsunMono,$(SUNMDIRS),$(SUNMOBJS),$(SUNMLIBS),$(SYSLIBS))
+#ifndef ServerToInstall
+#define ServerToInstall XsunMono
+#endif
+#endif /* XsunLynxMonoServer */
+
+
+#if XibmServer
+XCOMM
+XCOMM IBM server
+XCOMM
+#if SpecialMalloc
+IBMALLOCLIB = hw/ibm/common/LibraryTargetName(ibmalloc)
+#else
+IBMALLOCLIB = 
+#endif
+MFBDIR  = mfb
+CFB8DIR = cfb
+DDXDIR1 = hw/ibm
+IBMDIRS = $(STDDIRS) $(MFBDIR) $(CFB8DIR) $(DDXDIR1) $(DEPDIRS)
+IBMOBJS = hw/ibm/common/ibmcomm.o hw/ibm/common/ibmDate.o
+IBMLIBS = hw/ibm/AIX/hft.o hw/ibm/LibraryTargetName(ibm) $(IBMALLOCLIB) CFB8Libs
+ServerTarget(Xibm,$(IBMDIRS),$(IBMOBJS),$(IBMLIBS),$(SYSLIBS))
+#ifndef ServerToInstall
+#define ServerToInstall Xibm
+#endif
+#endif /* XibmServer */
+
+
+#if XhpServer
+XCOMM
+XCOMM Hewlett Packard CFB Server
+XCOMM
+MFBDIR  = mfb
+CFB8DIR = cfb
+CFB32DIR = cfb32
+DDXDIR1 = hw/hp
+HPOBJS = hw/hp/hp.o
+HPSUBDIRS = $(STDDIRS) $(MFBDIR) $(CFB8DIR) $(CFB32DIR) $(DDXDIR1) $(DEPDIRS)
+HPLIBS = CFB32Libs
+HPSYSLIBS = $(CBRT) $(SYSLIBS)
+ServerTarget(Xhp,$(HPSUBDIRS),$(HPOBJS),$(HPLIBS),$(HPSYSLIBS))
+#ifndef ServerToInstall
+#define ServerToInstall Xhp
+#endif
+#endif /* XhpServer */
+
+
+#if XsvgaServer
+XCOMM
+XCOMM SVGA CFB Server
+XCOMM
+MFBDIR  = mfb
+CFB8DIR = cfb
+DDXDIR1 = hw/svga
+SVGASUBDIRS = $(STDDIRS) $(MFBDIR) $(CFB8DIR) $(DDXDIR1) $(DEPDIRS)
+SVGAOBJS = hw/svga/svga.o
+SVGALIBS = CFB8Libs
+SVGASYSLIBS = $(CBRT) -lm -lmalloc
+SetUIDServerTarget(Xsvga,$(SVGASUBDIRS),$(SVGAOBJS),$(SVGALIBS),$(SVGASYSLIBS))
+#ifndef ServerToInstall
+#define ServerToInstall Xsvga
+#endif
+#endif /* XsvgaServer */
+
+
+#ifdef XFree86Version
+XF86INIT   = $(XF86COMSRC)/xf86Init.o $(XF86CONFIGSRC)/xf86IniExt.o
+XF86MINIT  = $(XF86COMSRC)/xf86Init_m.o $(XF86CONFIGSRC)/xf86MIniExt.o
+XF86CONFIG = $(XF86CONFIGSRC)/xf86_Option.o
+XF86COMLIB = $(XF86COMSRC)/LibraryTargetName(xf86)
+XF86OSLIB  = $(XF86OSSRC)/LibraryTargetName(xf86_os)
+XF86HWLIB  = $(XF86HWSRC)/LibraryTargetName(xf86_hw)
+XF86LIBS   = $(XF86INIT) $(XF86CONFIG) $(XF86COMLIB) $(XF86OSLIB) \
+             $(XF86HWLIB) $(XF86OSLIB)
+XF86MLIBS  = $(XF86MINIT) $(XF86CONFIG) $(XF86COMLIB) $(XF86OSLIB) \
+             $(XF86HWLIB) $(XF86OSLIB)
+XF68INIT   = $(XF68COMSRC)/xf86Init.o $(XF68CONFIGSRC)/xf86IniExt.o
+XF68MINIT  = $(XF68COMSRC)/xf86Init_m.o $(XF68CONFIGSRC)/xf86MIniExt.o
+XF68CONFIG = $(XF68CONFIGSRC)/xf86_Option.o
+XF68COMLIB = $(XF68COMSRC)/LibraryTargetName(xf86)
+XF68OSLIB  = $(XF68OSSRC)/LibraryTargetName(xf86_os)
+XF68LIBS   = $(XF68INIT) $(XF68CONFIG) $(XF68COMLIB) $(XF68OSLIB)
+XF68MLIBS  = $(XF68MINIT) $(XF68CONFIG) $(XF68COMLIB) $(XF68OSLIB)
+XF98INIT       = $(XF98COMSRC)/xf86Init.o $(XF98CONFIGSRC)/xf86IniExt.o
+XF98MINIT      = $(XF98COMSRC)/xf86Init_m.o $(XF98CONFIGSRC)/xf86MIniExt.o
+XF98CONFIG     = $(XF98CONFIGSRC)/xf86_Option.o
+XF98COMLIB     = $(XF98COMSRC)/LibraryTargetName(xf86)
+XF98OSLIB      = $(XF98OSSRC)/LibraryTargetName(xf86_os)
+XF98HWLIB      = $(XF98HWSRC)/LibraryTargetName(xf86_hw)
+XF98HWNECLIB   = $(XF98HWNECSRC)/LibraryTargetName(xf86_hw)
+XF98HWPWSKBLIB = $(XF98HWPWSKBSRC)/LibraryTargetName(xf86_hw)
+XF98HWPWLBLIB  = $(XF98HWPWLBSRC)/LibraryTargetName(xf86_hw)
+XF98HWGA968LIB = $(XF98HWGA968SRC)/LibraryTargetName(xf86_hw)
+XF98LIBS       = $(XF98INIT) $(XF98CONFIG) $(XF98COMLIB) \
+                $(XF98HWLIB) $(XF98OSLIB)
+XF98LIBSNEC    = $(XF98INIT) $(XF98CONFIG) $(XF98COMLIB) \
+                $(XF98HWNECLIB) $(XF98OSLIB)
+XF98LIBSPWSKB  = $(XF98INIT) $(XF98CONFIG) $(XF98COMLIB) \
+                $(XF98HWPWSKBLIB) $(XF98OSLIB)
+XF98LIBSPWLB   = $(XF98INIT) $(XF98CONFIG) $(XF98COMLIB) \
+                $(XF98HWPWLBLIB) $(XF98OSLIB)
+XF98LIBSGA968  = $(XF98INIT) $(XF98CONFIG) $(XF98COMLIB) \
+                $(XF98HWGA968LIB) $(XF98OSLIB)
+XF98MLIBS      = $(XF98MINIT) $(XF98CONFIG) $(XF98COMLIB) \
+                $(XF98HWLIB) $(XF98OSLIB)
+XF98MLIBSNEC   = $(XF98MINIT) $(XF98CONFIG) $(XF98COMLIB) \
+                $(XF98HWNECLIB) $(XF98OSLIB)
+XF98MLIBSPWSKB = $(XF98MINIT) $(XF98CONFIG) $(XF98COMLIB) \
+                $(XF98HWPWSKBLIB) $(XF98OSLIB)
+XF98MLIBSPWLB  = $(XF98MINIT) $(XF98CONFIG) $(XF98COMLIB) \
+                $(XF98HWPWLBLIB) $(XF98OSLIB)
+XF98MLIBSGA968 = $(XF98MINIT) $(XF98CONFIG) $(XF98COMLIB) \
+                $(XF98HWGA968LIB) $(XF98OSLIB)
+#endif
+
+
+#if HasParallelMake
+XCOMM
+XCOMM force non-parallel build of XF86 servers to prevent MUTEX overrides
+XCOMM
+#if XF86SVGAServer
+XF86SVGA = XF86_SVGA
+#endif
+#if XF86VGA16Server
+XF86VGA16 = XF86_VGA16
+#endif
+#if XF86W32Server
+XF86W32 = XF86_W32
+#endif
+#if XF86MonoServer
+XF86MONO = XF86_Mono
+#endif
+#if XF86S3Server
+XF86S3 = XF86_S3
+#endif
+#if XF86S3VServer
+XF86S3V = XF86_S3V
+#endif
+#if XF86I8514Server
+XF868514 = XF86_8514
+#endif
+#if XF86Mach8Server
+XF86MACH8 = XF86_Mach8
+#endif
+#if XF86Mach32Server
+XF86MACH32 = XF86_Mach32
+#endif
+#if XF86Mach64Server
+XF86MACH64 = XF86_Mach64
+#endif
+#if XF86P9000Server
+XF86P9000 = XF86_P9000
+#endif
+#if XF86AGXServer
+XF86AGX = XF86_AGX
+#endif
+#if XF86I128Server
+XF86I128 = XF86_I128
+#endif
+#if XF86TGAServer
+XF86TGA = XF86_TGA
+#endif
+#if XF68FBDevServer
+XF68FBDEV = XF68_FBDev
+#endif
+#if XF98GANBWAPServer
+XF98GANBWAP = XF98_GANBWAP
+#endif
+#if XF98NEC480Server
+XF98NEC480 = XF98_NEC480
+#endif
+#if XF98NKVNECServer
+XF98NKVNEC = XF98_NKVNEC
+#endif
+#if XF98WABSServer
+XF98WABS = XF98_WABS
+#endif
+#if XF98WABEPServer
+XF98WABEP = XF98_WABEP
+#endif
+#if XF98WSNAServer
+XF98WSNA = XF98_WSNA
+#endif
+#if XF98TGUIServer
+XF98TGUI = XF98_TGUI
+#endif
+#if XF98MGAServer
+XF98MGA = XF98_MGA
+#endif
+#if XF98SVGAServer
+XF98SVGA = XF98_SVGA
+#endif
+#if XF98EGCServer
+XF98EGC = XF98_EGC
+#endif
+#if XF98NECS3Server
+XF98NECS3 = XF98_NECS3
+#endif
+#if XF98PWSKBServer
+XF98PWSKB = XF98_PWSKB
+#endif
+#if XF98PWLBServer
+XF98PWLB = XF98_PWLB
+#endif
+#if XF98GA968Server
+XF98GA968 = XF98_GA968
+#endif
+#if XnestServer
+XNEST = Xnest
+#endif
+#if XVirtualFramebufferServer
+XVFB = Xvfb
+#endif
+#if defined(XF86SVGAServer) || defined(XF98GANBWAPServer) || \
+    defined(XF98NEC480Server) || defined(XF98NKVNECServer) || \
+    defined(XF98WABSServer) || defined(XF98WABEPServer) || \
+    defined(XF98WSNAServer) || defined(XF98TGUIServer) || \
+    defined(XF98MGAServer) || defined(XF98SVGAServer) || \
+    defined(XF86VGA16Server) || defined(XF98EGCServer) || \
+    defined(XF86W32Server) || defined(XF86MonoServer) || \
+    defined(XF86S3Server) || defined(XF86S3VServer) || \
+    defined(XF98NECS3Server) || defined(XF98PWSKBServer) || \
+    defined(XF98PWLBServer) || defined(XF98GA968Server) || \
+    defined(XF86I8514Server) || defined(XF86Mach8Server) || \
+    defined(XF86Mach32Server) || defined(XF86Mach64Server) || \
+    defined(XF86P9000Server) || defined(XF86AGXServer) || \
+    defined(XF86I128Server) || defined(XF86TGAServer) || \
+    defined(XF68FBDevServer) || \
+    defined(XnestServer) || defined(XVirtualFramebufferServer)
+MakeMutex($(XF86SVGA) $(XF98GANBWAP) $(XF98NEC480) $(XF98NKVNEC) $(XF98WABS) \
+         $(XF98WABEP) $(XF98WSNA) $(XF98TGUI) $(XF98MGA) $(XF98SVGA) \
+         $(XF86VGA16) \
+         $(XF98EGC) $(XF86W32) $(XF86MONO) $(XF86S3) $(XF86S3V) $(XF98NECS3) \
+         $(XF98PWSKB) $(XF98PWLB) $(XF98GA968) $(XF868514) $(XF86MACH8) \
+         $(XF86MACH32) $(XF86MACH64) $(XF86P9000) $(XF86AGX) $(XF86I128) \
+         $(XF86TGA) $(XF68FBDEV) $(XNEST) $(XVFB))
+#endif
+MakeMutex($(STDDIRS) mfb cfb cfb16 cfb32)
+#endif
+
+
+#if XF86SVGAServer
+XCOMM
+XCOMM XFree86 SVGA Server
+XCOMM
+MFBDIR  = mfb
+CFB8DIR = cfb
+CFB16DIR = cfb16
+CFB24DIR = cfb24
+CFB32DIR = cfb32
+DDXDIR1 = hw/xfree86
+XF86SVGASUBDIRS = $(STDDIRS) $(MFBDIR) $(CFB8DIR) $(CFB16DIR) $(CFB24DIR) \
+                  $(CFB32DIR) $(DDXDIR1) $(DEPDIRS)
+XF86SVGAOBJS = $(XF86COMSRC)/XF86_SVGA.o $(XF86SRC)/vga256/vga256Conf.o \
+               $(XF86SRC)/xaa/xaavga256/xaavga256.o \
+               $(XF86SRC)/xaa/xaa16/xaa16.o $(XF86SRC)/xaa/xaa24/xaa24.o \
+               $(XF86SRC)/xaa/xaa32/xaa32.o
+XF86SVGALIBS = $(VGADRIVERSRC)/LibraryTargetName(driver256) \
+               $(XF86SRC)/xaa/LibraryTargetName(xaa) \
+               $(XF86SRC)/vga256/LibraryTargetName(vga256) \
+               $(XF86LIBS) CFBLibs
+XF86SVGASYSLIBS = $(SYSLIBS)
+#if HasParallelMake
+MakeMutex($(XF86SVGASUBDIRS) $(XF86SVGAOBJS) $(XF86SVGALIBS) $(XF86SVGASYSLIBS))
+#endif
+#if HasGnuMake
+$(XF86SVGAOBJS) $(XF86SVGALIBS) $(XF86SVGASYSLIBS):: $(XF86SVGASUBDIRS)
+       @if [ -f $@ ]; then touch $@; fi
+#endif
+SetUIDServerTarget(XF86_SVGA,$(XF86SVGASUBDIRS),$(XF86SVGAOBJS),$(XF86SVGALIBS),$(XF86SVGASYSLIBS))
+#ifndef ServerToInstall
+#define ServerToInstall XF86_SVGA
+#endif
+#ifdef OS2Architecture
+LinkFile(XF86_SVGA.def,SVGA.def)
+InstallLinkKitNonExecFile(SVGA.def,$(LINKKITDIR))
+#endif
+#endif /* XF86SVGAServer */
+
+
+#if XF86VGA16Server
+XCOMM
+XCOMM XFree86 VGA 16 color Server
+XCOMM
+DDXDIR1 = hw/xfree86
+#if XF86VGA16DualServer
+XF86VGA16MONOOBJS = $(XF86SRC)/mono/monoConf.o
+XF86VGA16MONOLIBS = $(MONODRIVERSRC)/LibraryTargetName(monodrv) \
+                    $(XF86SRC)/mono/LibraryTargetName(mono)
+#endif
+XF86VGA16SUBDIRS = $(STDDIRS) $(DDXDIR1) $(DEPDIRS)
+XF86VGA16OBJS = $(XF86COMSRC)/XF86_VGA16.o $(XF86SRC)/vga16/vga16Conf.o \
+                $(XF86SRC)/vga16/misc/vga16misc.o $(XF86VGA16MONOOBJS)
+XF86VGA16LIBS = $(VGA16DRIVERSRC)/LibraryTargetName(driver16) \
+                $(XF86SRC)/vga16/LibraryTargetName(vga16) \
+                $(XF86VGA16MONOLIBS) $(XF86MLIBS) NoMFBBareLibs $(OTHEREXTS)
+XF86VGA16SYSLIBS = $(SYSLIBS)
+#if HasParallelMake
+MakeMutex($(XF86VGA16SUBDIRS) $(XF86VGA16OBJS) $(XF86VGA16LIBS) $(XF86VGA16SYSLIBS))
+#endif
+#if HasGnuMake
+$(XF86VGA16OBJS) $(XF86VGA16LIBS) $(XF86VGA16SYSLIBS):: $(XF86VGA16SUBDIRS)
+       @if [ -f $@ ]; then touch $@; fi
+#endif
+SetUIDServerTarget(XF86_VGA16,$(XF86VGA16SUBDIRS),$(XF86VGA16OBJS),$(XF86VGA16LIBS),$(XF86VGA16SYSLIBS))
+#ifndef ServerToInstall
+#define ServerToInstall XF86_VGA16
+#endif
+#ifdef OS2Architecture
+LinkFile(XF86_VGA16.def,VGA16.def)
+InstallLinkKitNonExecFile(VGA16.def,$(LINKKITDIR))
+#endif
+#endif /* XF86VGA16Server */
+
+
+#if XF86W32Server
+XCOMM
+XCOMM XFree86 W32 Server
+XCOMM
+MFBDIR  = mfb
+CFB8DIR = cfb
+DDXDIR1 = hw/xfree86
+XF86W32SUBDIRS = $(STDDIRS) $(MFBDIR) $(CFB8DIR) $(DDXDIR1) $(DEPDIRS)
+XF86W32OBJS = $(XF86COMSRC)/XF86_W32.o $(XF86ACCELSRC)/et4000w32/w32Conf.o
+XF86W32LIBS = $(XF86ACCELSRC)/et4000w32/w32/LibraryTargetName(w32) \
+              $(XF86ACCELSRC)/et4000w32/cfb.w32/LibraryTargetName(cfb) \
+              $(XF86ACCELSRC)/et4000w32/w32/LibraryTargetName(w32) \
+              $(XF86ACCELSRC)/et4000w32/asm/LibraryTargetName(asm) \
+              $(XF86LIBS) CFB8Libs
+XF86W32SYSLIBS = $(SYSLIBS)
+#if HasParallelMake
+MakeMutex($(XF86W32SUBDIRS) $(XF86W32OBJS) $(XF86W32LIBS) $(XF86W32SYSLIBS))
+#endif
+#if HasGnuMake
+$(XF86W32OBJS) $(XF86W32LIBS) $(XF86W32SYSLIBS):: $(XF86W32SUBDIRS)
+       @if [ -f $@ ]; then touch $@; fi
+#endif
+SetUIDServerTarget(XF86_W32,$(XF86W32SUBDIRS),$(XF86W32OBJS),$(XF86W32LIBS),$(XF86W32SYSLIBS))
+#ifndef ServerToInstall
+#define ServerToInstall XF86_W32
+#endif
+#ifdef OS2Architecture
+LinkFile(XF86_W32.def,W32.def)
+InstallLinkKitNonExecFile(W32.def,$(LINKKITDIR))
+#endif
+#endif
+
+
+#if XF86MonoServer
+XCOMM
+XCOMM XFree86 Monochrome VGA Server
+XCOMM
+DDXDIR1 = hw/xfree86
+#if XF86MonoDualServer
+XF86MONOMONOOBJS = $(XF86SRC)/mono/monoConf.o
+XF86MONOMONOLIBS = $(MONODRIVERSRC)/LibraryTargetName(monodrv) \
+                   $(XF86SRC)/mono/LibraryTargetName(mono)
+#endif
+XF86MONOSUBDIRS = $(STDDIRS) $(MFBDIR) $(DDXDIR1) $(DEPDIRS)
+XF86MONOOBJS = $(XF86COMSRC)/XF86_Mono.o $(XF86SRC)/vga2/vga2Conf.o \
+               $(XF86SRC)/vga2/misc/vga2misc.o $(XF86MONOMONOOBJS)
+XF86MONOLIBS = $(VGA2DRIVERSRC)/LibraryTargetName(driver2) \
+               $(XF86SRC)/vga2/LibraryTargetName(vga2) \
+              $(XF86MONOMONOLIBS) $(XF86MLIBS) NoMFBBareLibs $(OTHEREXTS)
+XF86MONOSYSLIBS = $(SYSLIBS)
+#if HasParallelMake
+MakeMutex($(XF86MONOSUBDIRS) $(XF86MONOOBJS) $(XF86MONOLIBS) $(XF86MONOSYSLIBS))
+#endif
+#if HasGnuMake
+$(XF86MONOOBJS) $(XF86MONOLIBS) $(XF86MONOSYSLIBS):: $(XF86MONOSUBDIRS)
+       @if [ -f $@ ]; then touch $@; fi
+#endif
+SetUIDServerTarget(XF86_Mono,$(XF86MONOSUBDIRS),$(XF86MONOOBJS),$(XF86MONOLIBS),$(XF86MONOSYSLIBS))
+#ifndef ServerToInstall
+#define ServerToInstall XF86_Mono
+#endif
+#ifdef OS2Architecture
+LinkFile(XF86_Mono.def,Mono.def)
+InstallLinkKitNonExecFile(Mono.def,$(LINKKITDIR))
+#endif
+#endif /* XF86MonoServer */
+
+
+#if XF86S3Server
+XCOMM
+XCOMM XFree86 S3 Server
+XCOMM
+MFBDIR   = mfb
+CFB8DIR  = cfb
+CFB16DIR = cfb16
+CFB24DIR = cfb24
+CFB32DIR = cfb32
+DDXDIR1 = hw/xfree86
+XF86S3SUBDIRS = $(STDDIRS) $(MFBDIR) $(CFB8DIR) $(CFB16DIR) $(CFB24DIR) \
+               $(CFB32DIR) $(DDXDIR1) $(DEPDIRS)
+XF86S3OBJS = $(XF86COMSRC)/XF86_S3.o $(XF86ACCELSRC)/s3/s3Conf.o \
+             $(S3DRIVERSRC)/newmmio/newmmio.o \
+             $(S3DRIVERSRC)/mmio_928/mmio_928.o \
+             $(S3DRIVERSRC)/s3_generic/s3_generic.o
+XF86S3LIBS = $(XF86ACCELSRC)/s3/LibraryTargetName(s3) \
+             $(XF86ACCELSRC)/s3/s3newmmio/LibraryTargetName(s3newmmio) \
+             $(XF86ACCELSRC)/s3/s3mmio/LibraryTargetName(s3mmio) $(XF86LIBS) \
+             CFBLibs $(XF86ACCELSRC)/cache/LibraryTargetName(xf86cache)
+XF86S3SYSLIBS = $(SYSLIBS)
+#if HasParallelMake
+MakeMutex($(XF86S3SUBDIRS) $(XF86S3OBJS) $(XF86S3LIBS) $(XF86S3SYSLIBS))
+#endif
+SetUIDServerTarget(XF86_S3,$(XF86S3SUBDIRS),$(XF86S3OBJS),$(XF86S3LIBS),$(XF86S3SYSLIBS))
+#ifndef ServerToInstall
+#define ServerToInstall XF86_S3
+#endif
+#ifdef OS2Architecture
+LinkFile(XF86_S3.def,S3.def)
+InstallLinkKitNonExecFile(S3.def,$(LINKKITDIR))
+#endif
+#endif /* XF86S3Server */
+
+
+#if XF86S3VServer
+XCOMM
+XCOMM XFree86 S3 ViRGE Server
+XCOMM
+MFBDIR   = mfb
+CFB8DIR  = cfb
+CFB16DIR = cfb16
+CFB24DIR = cfb24
+CFB32DIR = cfb32
+DDXDIR1 = hw/xfree86
+XF86S3VSUBDIRS = $(STDDIRS) $(MFBDIR) $(CFB8DIR) $(CFB16DIR) $(CFB24DIR) \
+               $(CFB32DIR) $(DDXDIR1) $(DEPDIRS)
+XF86S3VOBJS = $(XF86COMSRC)/XF86_S3.o $(XF86ACCELSRC)/s3_virge/s3vConf.o \
+             $(S3VDRIVERSRC)/s3_virge/s3_virge.o
+XF86S3VLIBS = $(XF86ACCELSRC)/s3_virge/LibraryTargetName(s3v) $(XF86LIBS) \
+             CFBLibs $(XF86ACCELSRC)/cache/LibraryTargetName(xf86cache)
+XF86S3VSYSLIBS = $(SYSLIBS)
+#if HasParallelMake
+MakeMutex($(XF86S3VSUBDIRS) $(XF86S3VOBJS) $(XF86S3VLIBS) $(XF86S3VSYSLIBS))
+#endif
+#if HasGnuMake
+$(XF86S3VOBJS) $(XF86S3VLIBS) $(XF86S3VSYSLIBS):: $(XF86S3VSUBDIRS)
+       @if [ -f $@ ]; then touch $@; fi
+#endif
+SetUIDServerTarget(XF86_S3V,$(XF86S3VSUBDIRS),$(XF86S3VOBJS),$(XF86S3VLIBS),$(XF86S3VSYSLIBS))
+#ifndef ServerToInstall
+#define ServerToInstall XF86_S3V
+#endif
+#ifdef OS2Architecture
+LinkFile(XF86_S3V.def,S3V.def)
+InstallLinkKitNonExecFile(S3V.def,$(LINKKITDIR))
+#endif
+#endif /* XF86S3VServer */
+
+
+#if XF86I8514Server
+XCOMM
+XCOMM XFree86 8514 Server
+XCOMM
+MFBDIR  = mfb
+CFB8DIR = cfb
+DDXDIR1 = hw/xfree86
+XF868514SUBDIRS = $(STDDIRS) $(MFBDIR) $(CFB8DIR) $(DDXDIR1) $(DEPDIRS)
+XF868514OBJS = $(XF86COMSRC)/XF86_8514.o
+XF868514LIBS = $(XF86ACCELSRC)/ibm8514/LibraryTargetName(8514) $(XF86LIBS) \
+               CFB8Libs $(XF86ACCELSRC)/cache/LibraryTargetName(xf86cache)
+XF868514SYSLIBS = $(SYSLIBS)
+#if HasParallelMake
+MakeMutex($(XF868514SUBDIRS) $(XF868514OBJS) $(XF868514LIBS) $(XF868514SYSLIBS))
+#endif
+#if HasGnuMake
+$(XF868514OBJS) $(XF868514LIBS) $(XF868514SYSLIBS):: $(XF868514SUBDIRS)
+       @if [ -f $@ ]; then touch $@; fi
+#endif
+SetUIDServerTarget(XF86_8514,$(XF868514SUBDIRS),$(XF868514OBJS),$(XF868514LIBS),$(XF868514SYSLIBS))
+#ifndef ServerToInstall
+#define ServerToInstall XF86_8514
+#endif
+#ifdef OS2Architecture
+LinkFile(XF86_8514.def,8514.def)
+InstallLinkKitNonExecFile(8514.def,$(LINKKITDIR))
+#endif
+#endif /* XF86I8514Server */
+
+
+#if XF86Mach8Server
+XCOMM
+XCOMM XFree86 Mach8 Server
+XCOMM
+MFBDIR  = mfb
+CFB8DIR = cfb
+DDXDIR1 = hw/xfree86
+XF86MACH8SUBDIRS = $(STDDIRS) $(MFBDIR) $(CFB8DIR) $(DDXDIR1) $(DEPDIRS)
+XF86MACH8OBJS = $(XF86COMSRC)/XF86_Mach8.o
+XF86MACH8LIBS = $(XF86ACCELSRC)/mach8/LibraryTargetName(mach8) $(XF86LIBS) \
+                CFB8Libs $(XF86ACCELSRC)/cache/LibraryTargetName(xf86cache)
+XF86MACH8SYSLIBS = $(SYSLIBS)
+#if HasParallelMake
+MakeMutex($(XF86MACH8SUBDIRS) $(XF86MACH8OBJS) $(XF86MACH8LIBS) $(XF86MACH8SYSLIBS))
+#endif
+#if HasGnuMake
+$(XF86MACH8OBJS) $(XF86MACH8LIBS) $(XF86MACH8SYSLIBS):: $(XF86MACH8SUBDIRS)
+       @if [ -f $@ ]; then touch $@; fi
+#endif
+SetUIDServerTarget(XF86_Mach8,$(XF86MACH8SUBDIRS),$(XF86MACH8OBJS),$(XF86MACH8LIBS),$(XF86MACH8SYSLIBS))
+#ifndef ServerToInstall
+#define ServerToInstall XF86_Mach8
+#endif
+#ifdef OS2Architecture
+LinkFile(XF86_Mach8.def,Mach8.def)
+InstallLinkKitNonExecFile(Mach8.def,$(LINKKITDIR))
+#endif
+#endif /* XF86Mach8Server */
+
+
+#if XF86Mach32Server
+XCOMM
+XCOMM XFree86 Mach32 Server
+XCOMM
+MFBDIR   = mfb
+CFB8DIR  = cfb
+CFB16DIR = cfb16
+DDXDIR1  = hw/xfree86
+XF86MACH32SUBDIRS = $(STDDIRS) $(MFBDIR) $(CFB8DIR) $(CFB16DIR) $(DDXDIR1) \
+                    $(DEPDIRS)
+XF86MACH32OBJS = $(XF86COMSRC)/XF86_Mach32.o
+XF86MACH32LIBS = $(XF86ACCELSRC)/mach32/LibraryTargetName(mach32) $(XF86LIBS) \
+                 CFB16Libs $(XF86ACCELSRC)/cache/LibraryTargetName(xf86cache)
+XF86MACH32SYSLIBS = $(SYSLIBS)
+#if HasParallelMake
+MakeMutex($(XF86MACH32SUBDIRS) $(XF86MACH32OBJS) $(XF86MACH32LIBS) $(XF86MACH32SYSLIBS))
+#endif
+#if HasGnuMake
+$(XF86MACH32OBJS) $(XF86MACH32LIBS) $(XF86MACH32SYSLIBS):: $(XF86MACH32SUBDIRS)
+       @if [ -f $@ ]; then touch $@; fi
+#endif
+SetUIDServerTarget(XF86_Mach32,$(XF86MACH32SUBDIRS),$(XF86MACH32OBJS),$(XF86MACH32LIBS),$(XF86MACH32SYSLIBS))
+#ifndef ServerToInstall
+#define ServerToInstall XF86_Mach32
+#endif
+#ifdef OS2Architecture
+LinkFile(XF86_Mach32.def,Mach32.def)
+InstallLinkKitNonExecFile(Mach32.def,$(LINKKITDIR))
+#endif
+#endif /* XF86Mach32Server */
+
+
+#if XF86Mach64Server
+XCOMM
+XCOMM XFree86 Mach64 Server
+XCOMM
+MFBDIR   = mfb
+CFB8DIR  = cfb
+CFB16DIR = cfb16
+CFB24DIR = cfb24
+CFB32DIR = cfb32
+DDXDIR1  = hw/xfree86
+XF86MACH64SUBDIRS = $(STDDIRS) $(MFBDIR) $(CFB8DIR) $(CFB16DIR) $(CFB24DIR) \
+                    $(CFB32DIR) $(DDXDIR1) $(DEPDIRS)
+XF86MACH64OBJS = $(XF86COMSRC)/XF86_Mach64.o
+XF86MACH64LIBS = $(XF86ACCELSRC)/mach64/LibraryTargetName(mach64) \
+                $(XF86LIBS) CFBLibs
+XF86MACH64SYSLIBS = $(SYSLIBS)
+#if HasParallelMake
+MakeMutex($(XF86MACH64SUBDIRS) $(XF86MACH64OBJS) $(XF86MACH64LIBS) $(XF86MACH64SYSLIBS))
+#endif
+#if HasGnuMake
+$(XF86MACH64OBJS) $(XF86MACH64LIBS) $(XF86MACH64SYSLIBS):: $(XF86MACH64SUBDIRS)
+       @if [ -f $@ ]; then touch $@; fi
+#endif
+SetUIDServerTarget(XF86_Mach64,$(XF86MACH64SUBDIRS),$(XF86MACH64OBJS),$(XF86MACH64LIBS),$(XF86MACH64SYSLIBS))
+#ifndef ServerToInstall
+#define ServerToInstall XF86_Mach64
+#endif
+#ifdef OS2Architecture
+LinkFile(XF86_Mach64.def,Mach64.def)
+InstallLinkKitNonExecFile(Mach64.def,$(LINKKITDIR))
+#endif
+#endif /* XF86Mach64Server */
+
+
+#if XF86P9000Server
+XCOMM
+XCOMM XFree86 P9000 Server
+XCOMM
+MFBDIR  = mfb
+CFB8DIR = cfb
+CFB16DIR = cfb16
+CFB24DIR = cfb24
+CFB32DIR = cfb32
+DDXDIR1 = hw/xfree86
+XF86P9000SUBDIRS = $(STDDIRS) $(MFBDIR) $(CFB8DIR) $(CFB16DIR) $(CFB24DIR) \
+                  $(CFB32DIR) $(DDXDIR1) $(DEPDIRS)
+XF86P9000OBJS = $(XF86COMSRC)/XF86_P9000.o
+XF86P9000LIBS = $(XF86ACCELSRC)/p9000/LibraryTargetName(p9000) \
+                $(XF86LIBS) CFBLibs
+XF86P9000SYSLIBS = $(SYSLIBS)
+#if HasParallelMake
+MakeMutex($(XF86P9000SUBDIRS) $(XF86P9000OBJS) $(XF86P9000LIBS) $(XF86P9000SYSLIBS))
+#endif
+#if HasGnuMake
+$(XF86P9000OBJS) $(XF86P9000LIBS) $(XF86P9000SYSLIBS):: $(XF86P9000SUBDIRS)
+       @if [ -f $@ ]; then touch $@; fi
+#endif
+SetUIDServerTarget(XF86_P9000,$(XF86P9000SUBDIRS),$(XF86P9000OBJS),$(XF86P9000LIBS),$(XF86P9000SYSLIBS))
+#ifndef ServerToInstall
+#define ServerToInstall XF86_P9000
+#endif
+#ifdef OS2Architecture
+LinkFile(XF86_P9000.def,P9000.def)
+InstallLinkKitNonExecFile(P9000.def,$(LINKKITDIR))
+#endif
+#endif        /* XF86P9000Server */
+
+
+#if XF86AGXServer
+XCOMM
+XCOMM XFree86 AGX Server
+XCOMM
+MFBDIR   = mfb
+CFB8DIR  = cfb
+CFB16DIR = cfb16
+CFB24DIR = cfb24
+CFB32DIR = cfb32
+DDXDIR1  = hw/xfree86
+XF86AGXSUBDIRS = $(STDDIRS) $(MFBDIR) $(CFB8DIR) $(CFB16DIR) $(CFB24DIR) \
+                $(CFB32DIR) $(DDXDIR1) $(DEPDIRS)
+XF86AGXOBJS = $(XF86COMSRC)/XF86_AGX.o
+XF86AGXLIBS = $(XF86ACCELSRC)/agx/LibraryTargetName(agx) $(XF86LIBS) CFBLibs
+XF86AGXSYSLIBS = $(SYSLIBS)
+#if HasParallelMake
+MakeMutex($(XF86AGXSUBDIRS) $(XF86AGXOBJS) $(XF86AGXLIBS) $(XF86AGXSYSLIBS))
+#endif
+#if HasGnuMake
+$(XF86AGXOBJS) $(XF86AGXLIBS) $(XF86AGXSYSLIBS):: $(XF86AGXSUBDIRS)
+       @if [ -f $@ ]; then touch $@; fi
+#endif
+SetUIDServerTarget(XF86_AGX,$(XF86AGXSUBDIRS),$(XF86AGXOBJS),$(XF86AGXLIBS),$(XF86AGXSYSLIBS))
+#ifndef ServerToInstall
+#define ServerToInstall XF86_AGX
+#endif
+#ifdef OS2Architecture
+LinkFile(XF86_AGX.def,AGX.def)
+InstallLinkKitNonExecFile(AGX.def,$(LINKKITDIR))
+#endif
+#endif        /* XF86AGXServer */
+
+
+#if XF98GANBWAPServer
+XCOMM
+XCOMM XFree98 GA-98NB/WAP Server
+XCOMM
+MFBDIR  = mfb
+CFB8DIR = cfb
+CFB16DIR = cfb16
+CFB24DIR = cfb24
+CFB32DIR = cfb32
+DDXDIR2 = hw/xfree98
+XF98GANBWAPSUBDIRS = $(STDDIRS) $(MFBDIR) $(CFB8DIR) $(CFB16DIR) $(CFB24DIR) $(CFB32DIR) $(DDXDIR2) $(DEPDIRS)
+XF98GANBWAPOBJS = $(XF98COMSRC)/XF86_SVGA.o $(XF98SRC)/vga256/vga256Conf.o \
+                $(XF98SRC)/xaa/xaa16/xaa16.o $(XF98SRC)/xaa/xaa24/xaa24.o $(XF98SRC)/xaa/xaa32/xaa32.o $(XF98SRC)/xaa/xaavga256/xaavga256.o
+XF98GANBWAPLIBS = $(XF98VGADRIVERSRC)/LibraryTargetName(driverganbwap) \
+                 $(XF98SRC)/xaa/LibraryTargetName(xaa) \
+                 $(XF98SRC)/vga256/LibraryTargetName(ganbwap) $(XF98LIBS) \
+                 CFBLibs
+XF98GANBWAPSYSLIBS = $(SYSLIBS)
+#if HasParallelMake
+MakeMutex($(XF98GANBWAPSUBDIRS) $(XF98GANBWAPOBJS) $(XF98GANBWAPLIBS) $(XF98GANBWAPSYSLIBS))
+#endif
+#if HasGnuMake
+$(XF98GANBWAPOBJS) $(XF98GANBWAPLIBS) $(XF98GANBWAPSYSLIBS):: $(XF98GANBWAPSUBDIRS)
+       @if [ -f $@ ]; then touch $@; fi
+#endif
+SetUIDServerTarget(XF98_GANBWAP,$(XF98GANBWAPSUBDIRS),$(XF98GANBWAPOBJS),$(XF98GANBWAPLIBS),$(XF98GANBWAPSYSLIBS))
+#ifndef ServerToInstall
+#define ServerToInstall XF98_GANBWAP
+#endif
+#endif /* XF98GANBWAPServer */
+
+
+#if XF98NEC480Server
+XCOMM
+XCOMM XFree98 NEC480 Server
+XCOMM
+MFBDIR  = mfb
+CFB8DIR = cfb
+CFB16DIR = cfb16
+CFB24DIR = cfb24
+CFB32DIR = cfb32
+DDXDIR2 = hw/xfree98
+XF98NEC480SUBDIRS = $(STDDIRS) $(MFBDIR) $(CFB8DIR) $(CFB16DIR) $(CFB24DIR) $(CFB32DIR) $(DDXDIR2) $(DEPDIRS)
+XF98NEC480OBJS = $(XF98COMSRC)/XF86_SVGA.o $(XF98SRC)/vga256/nec480Conf.o\
+                $(XF98SRC)/xaa/xaa16/xaa16.o $(XF98SRC)/xaa/xaa24/xaa24.o $(XF98SRC)/xaa/xaa32/xaa32.o $(XF98SRC)/xaa/xaavga256/xaavga256.o
+XF98NEC480LIBS = $(XF98VGADRIVERSRC)/LibraryTargetName(drivernec480) \
+                $(XF98SRC)/xaa/LibraryTargetName(xaa) \
+                $(XF98SRC)/vga256/LibraryTargetName(nec480) $(XF98LIBS) \
+                CFBLibs
+XF98NEC480SYSLIBS = $(SYSLIBS)
+#if HasParallelMake
+MakeMutex($(XF98NEC480SUBDIRS) $(XF98NEC480OBJS) $(XF98NEC480LIBS) $(XF98NEC480SYSLIBS))
+#endif
+#if HasGnuMake
+$(XF98NEC480OBJS) $(XF98NEC480LIBS) $(XF98NEC480SYSLIBS):: $(XF98NEC480SUBDIRS)
+       @if [ -f $@ ]; then touch $@; fi
+#endif
+SetUIDServerTarget(XF98_NEC480,$(XF98NEC480SUBDIRS),$(XF98NEC480OBJS),$(XF98NEC480LIBS),$(XF98NEC480SYSLIBS))
+#ifndef ServerToInstall
+#define ServerToInstall XF98_NEC480
+#endif
+#endif /* XF98NEC480Server */
+
+
+#if XF98NKVNECServer
+XCOMM
+XCOMM XFree98 NEC-CIRRUS/EPSON NKV/NKV2 Server
+XCOMM
+MFBDIR  = mfb
+CFB8DIR = cfb
+CFB16DIR = cfb16
+CFB24DIR = cfb24
+CFB32DIR = cfb32
+DDXDIR2 = hw/xfree98
+XF98NKVNECSUBDIRS = $(STDDIRS) $(MFBDIR) $(CFB8DIR) $(CFB16DIR) $(CFB24DIR) $(CFB32DIR) $(DDXDIR2) $(DEPDIRS)
+XF98NKVNECOBJS = $(XF98COMSRC)/XF86_SVGA.o $(XF98SRC)/vga256/vga256Conf.o \
+                $(XF98SRC)/xaa/xaa16/xaa16.o $(XF98SRC)/xaa/xaa24/xaa24.o $(XF98SRC)/xaa/xaa32/xaa32.o $(XF98SRC)/xaa/xaavga256/xaavga256.o
+XF98NKVNECLIBS = $(XF98VGADRIVERSRC)/LibraryTargetName(drivernkvnec) \
+                $(XF98SRC)/xaa/LibraryTargetName(xaa) \
+                $(XF98SRC)/vga256/LibraryTargetName(nkvnec) $(XF98LIBS) \
+                CFBLibs
+XF98NKVNECSYSLIBS = $(SYSLIBS)
+#if HasParallelMake
+MakeMutex($(XF98NKVNECSUBDIRS) $(XF98NKVNECOBJS) $(XF98NKVNECLIBS) $(XF98NKVNECSYSLIBS))
+#endif
+#if HasGnuMake
+$(XF98NKVNECOBJS) $(XF98NKVNECLIBS) $(XF98NKVNECSYSLIBS):: $(XF98NKVNECSUBDIRS)
+       @if [ -f $@ ]; then touch $@; fi
+#endif
+SetUIDServerTarget(XF98_NKVNEC,$(XF98NKVNECSUBDIRS),$(XF98NKVNECOBJS),$(XF98NKVNECLIBS),$(XF98NKVNECSYSLIBS))
+#ifndef ServerToInstall
+#define ServerToInstall XF98_NKVNEC
+#endif
+#endif /* XF98NKVNECServer */
+
+
+#if XF98WABSServer
+XCOMM
+XCOMM XFree98 WAB-S Server
+XCOMM
+MFBDIR  = mfb
+CFB8DIR = cfb
+CFB16DIR = cfb16
+CFB24DIR = cfb24
+CFB32DIR = cfb32
+DDXDIR2 = hw/xfree98
+XF98WABSSUBDIRS = $(STDDIRS) $(MFBDIR) $(CFB8DIR) $(CFB16DIR) $(CFB24DIR) $(CFB32DIR) $(DDXDIR2) $(DEPDIRS)
+XF98WABSOBJS = $(XF98COMSRC)/XF86_SVGA.o $(XF98SRC)/vga256/vga256Conf.o \
+                $(XF98SRC)/xaa/xaa16/xaa16.o $(XF98SRC)/xaa/xaa24/xaa24.o $(XF98SRC)/xaa/xaa32/xaa32.o $(XF98SRC)/xaa/xaavga256/xaavga256.o
+XF98WABSLIBS = $(XF98VGADRIVERSRC)/LibraryTargetName(driverwabs) \
+              $(XF98SRC)/xaa/LibraryTargetName(xaa) \
+              $(XF98SRC)/vga256/LibraryTargetName(wabs) $(XF98LIBS) CFBLibs
+XF98WABSSYSLIBS = $(SYSLIBS)
+#if HasParallelMake
+MakeMutex($(XF98WABSSUBDIRS) $(XF98WABSOBJS) $(XF98WABSLIBS) $(XF98WABSSYSLIBS))
+#endif
+#if HasGnuMake
+$(XF98WABSOBJS) $(XF98WABSLIBS) $(XF98WABSSYSLIBS):: $(XF98WABSSUBDIRS)
+       @if [ -f $@ ]; then touch $@; fi
+#endif
+SetUIDServerTarget(XF98_WABS,$(XF98WABSSUBDIRS),$(XF98WABSOBJS),$(XF98WABSLIBS),$(XF98WABSSYSLIBS))
+#ifndef ServerToInstall
+#define ServerToInstall XF98_WABS
+#endif
+#endif /* XF98WABSServer */
+
+
+#if XF98WABEPServer
+XCOMM
+XCOMM XFree98 WAB-EP Server
+XCOMM
+MFBDIR  = mfb
+CFB8DIR = cfb
+CFB16DIR = cfb16
+CFB24DIR = cfb24
+CFB32DIR = cfb32
+DDXDIR2 = hw/xfree98
+XF98WABEPSUBDIRS = $(STDDIRS) $(MFBDIR) $(CFB8DIR) $(CFB16DIR) $(CFB24DIR) $(CFB32DIR) $(DDXDIR2) $(DEPDIRS)
+XF98WABEPOBJS = $(XF98COMSRC)/XF86_SVGA.o $(XF98SRC)/vga256/vga256Conf.o \
+                $(XF98SRC)/xaa/xaa16/xaa16.o $(XF98SRC)/xaa/xaa24/xaa24.o $(XF98SRC)/xaa/xaa32/xaa32.o $(XF98SRC)/xaa/xaavga256/xaavga256.o
+XF98WABEPLIBS = $(XF98VGADRIVERSRC)/LibraryTargetName(driverwabep) \
+              $(XF98SRC)/xaa/LibraryTargetName(xaa) \
+              $(XF98SRC)/vga256/LibraryTargetName(wabep) $(XF98LIBS) CFBLibs
+XF98WABEPSYSLIBS = $(SYSLIBS)
+#if HasParallelMake
+MakeMutex($(XF98WABEPSUBDIRS) $(XF98WABEPOBJS) $(XF98WABEPLIBS) $(XF98WABEPSYSLIBS))
+#endif
+#if HasGnuMake
+$(XF98WABEPOBJS) $(XF98WABEPLIBS) $(XF98WABEPSYSLIBS):: $(XF98WABEPSUBDIRS)
+       @if [ -f $@ ]; then touch $@; fi
+#endif
+SetUIDServerTarget(XF98_WABEP,$(XF98WABEPSUBDIRS),$(XF98WABEPOBJS),$(XF98WABEPLIBS),$(XF98WABEPSYSLIBS))
+#ifndef ServerToInstall
+#define ServerToInstall XF98_WABEP
+#endif
+#endif /* XF98WABEPServer */
+
+
+#if XF98WSNAServer
+XCOMM
+XCOMM XFree98 WSN-A2F Server
+XCOMM
+MFBDIR  = mfb
+CFB8DIR = cfb
+CFB16DIR = cfb16
+CFB24DIR = cfb24
+CFB32DIR = cfb32
+DDXDIR2 = hw/xfree98
+XF98WSNASUBDIRS = $(STDDIRS) $(MFBDIR) $(CFB8DIR) $(CFB16DIR) $(CFB24DIR) $(CFB32DIR) $(DDXDIR2) $(DEPDIRS)
+XF98WSNAOBJS = $(XF98COMSRC)/XF86_SVGA.o $(XF98SRC)/vga256/vga256Conf.o \
+                $(XF98SRC)/xaa/xaa16/xaa16.o $(XF98SRC)/xaa/xaa24/xaa24.o $(XF98SRC)/xaa/xaa32/xaa32.o $(XF98SRC)/xaa/xaavga256/xaavga256.o
+XF98WSNALIBS = $(XF98VGADRIVERSRC)/LibraryTargetName(driverwsna) \
+              $(XF98SRC)/xaa/LibraryTargetName(xaa) \
+              $(XF98SRC)/vga256/LibraryTargetName(wsna) $(XF98LIBS) CFBLibs
+XF98WSNASYSLIBS = $(SYSLIBS)
+#if HasParallelMake
+MakeMutex($(XF98WSNASUBDIRS) $(XF98WSNAOBJS) $(XF98WSNALIBS) $(XF98WSNASYSLIBS))
+#endif
+#if HasGnuMake
+$(XF98WSNAOBJS) $(XF98WSNALIBS) $(XF98WSNASYSLIBS):: $(XF98WSNASUBDIRS)
+       @if [ -f $@ ]; then touch $@; fi
+#endif
+SetUIDServerTarget(XF98_WSNA,$(XF98WSNASUBDIRS),$(XF98WSNAOBJS),$(XF98WSNALIBS),$(XF98WSNASYSLIBS))
+#ifndef ServerToInstall
+#define ServerToInstall XF98_WSNA
+#endif
+#endif /* XF98WSNAServer */
+
+
+#if XF98TGUIServer
+XCOMM
+XCOMM XFree98 Trident Cyber9320/9680 Server
+XCOMM
+MFBDIR  = mfb
+CFB8DIR = cfb
+CFB16DIR = cfb16
+CFB24DIR = cfb24
+CFB32DIR = cfb32
+DDXDIR2 = hw/xfree98
+XF98TGUISUBDIRS = $(STDDIRS) $(MFBDIR) $(CFB8DIR) $(CFB16DIR) $(CFB24DIR) $(CFB32DIR) $(DDXDIR2) $(DEPDIRS)
+XF98TGUIOBJS = $(XF98COMSRC)/XF86_SVGA.o $(XF98SRC)/vga256/tguiConf.o \
+                $(XF98SRC)/xaa/xaa16/xaa16.o $(XF98SRC)/xaa/xaa24/xaa24.o $(XF98SRC)/xaa/xaa32/xaa32.o $(XF98SRC)/xaa/xaavga256/xaavga256.o
+XF98TGUILIBS = $(XF98VGADRIVERSRC)/LibraryTargetName(drivertrident) \
+              $(XF98SRC)/xaa/LibraryTargetName(xaa) \
+              $(XF98SRC)/vga256/LibraryTargetName(trident) $(XF98LIBS) CFBLibs
+XF98TGUISYSLIBS = $(SYSLIBS)
+#if HasParallelMake
+MakeMutex($(XF98TGUISUBDIRS) $(XF98TGUIOBJS) $(XF98TGUILIBS) $(XF98TGUISYSLIBS))
+#endif
+#if HasGnuMake
+$(XF98TGUIOBJS) $(XF98TGUILIBS) $(XF98TGUISYSLIBS):: $(XF98TGUISUBDIRS)
+       @if [ -f $@ ]; then touch $@; fi
+#endif
+SetUIDServerTarget(XF98_TGUI,$(XF98TGUISUBDIRS),$(XF98TGUIOBJS),$(XF98TGUILIBS),$(XF98TGUISYSLIBS))
+#ifndef ServerToInstall
+#define ServerToInstall XF98_TGUI
+#endif
+#endif /* XF98TGUIServer */
+
+
+#if XF98MGAServer
+XCOMM
+XCOMM XFree98 Matrox Millennium/Mystique Server
+XCOMM
+MFBDIR  = mfb
+CFB8DIR = cfb
+CFB16DIR = cfb16
+CFB24DIR = cfb24
+CFB32DIR = cfb32
+DDXDIR2 = hw/xfree98
+XF98MGASUBDIRS = $(STDDIRS) $(MFBDIR) $(CFB8DIR) $(CFB16DIR) $(CFB24DIR) $(CFB32DIR) $(DDXDIR2) $(DEPDIRS)
+XF98MGAOBJS = $(XF98COMSRC)/XF86_SVGA.o $(XF98SRC)/vga256/mgaConf.o \
+                $(XF98SRC)/xaa/xaa16/xaa16.o $(XF98SRC)/xaa/xaa24/xaa24.o $(XF98SRC)/xaa/xaa32/xaa32.o $(XF98SRC)/xaa/xaavga256/xaavga256.o
+XF98MGALIBS = $(XF98VGADRIVERSRC)/LibraryTargetName(drivermga) \
+              $(XF98SRC)/xaa/LibraryTargetName(xaa) \
+              $(XF98SRC)/vga256/LibraryTargetName(mga) $(XF98LIBS) CFBLibs
+XF98MGASYSLIBS = $(SYSLIBS)
+#if HasParallelMake
+MakeMutex($(XF98MGASUBDIRS) $(XF98MGAOBJS) $(XF98MGALIBS) $(XF98MGASYSLIBS))
+#endif
+#if HasGnuMake
+$(XF98MGAOBJS) $(XF98MGALIBS) $(XF98MGASYSLIBS):: $(XF98MGASUBDIRS)
+       @if [ -f $@ ]; then touch $@; fi
+#endif
+SetUIDServerTarget(XF98_MGA,$(XF98MGASUBDIRS),$(XF98MGAOBJS),$(XF98MGALIBS),$(XF98MGASYSLIBS))
+#ifndef ServerToInstall
+#define ServerToInstall XF98_MGA
+#endif
+#endif /* XF98MGAServer */
+
+
+#if XF98SVGAServer
+XCOMM
+XCOMM XFree98 Cirrus Logic CLGD7555 Server
+XCOMM
+MFBDIR  = mfb
+CFB8DIR = cfb
+CFB16DIR = cfb16
+CFB24DIR = cfb24
+CFB32DIR = cfb32
+DDXDIR2 = hw/xfree98
+XF98SVGASUBDIRS = $(STDDIRS) $(MFBDIR) $(CFB8DIR) $(CFB16DIR) $(CFB24DIR) $(CFB32DIR) $(DDXDIR2) $(DEPDIRS)
+XF98SVGAOBJS = $(XF98COMSRC)/XF86_SVGA.o $(XF98SRC)/vga256/vga256Conf.o \
+                $(XF98SRC)/xaa/xaa16/xaa16.o $(XF98SRC)/xaa/xaa24/xaa24.o $(XF98SRC)/xaa/xaa32/xaa32.o $(XF98SRC)/xaa/xaavga256/xaavga256.o
+XF98SVGALIBS = $(XF98VGADRIVERSRC)/LibraryTargetName(driversvga) \
+              $(XF98SRC)/xaa/LibraryTargetName(xaa) \
+              $(XF98SRC)/vga256/LibraryTargetName(vga256) $(XF98LIBS) CFBLibs
+XF98SVGASYSLIBS = $(SYSLIBS)
+#if HasParallelMake
+MakeMutex($(XF98SVGASUBDIRS) $(XF98SVGAOBJS) $(XF98SVGALIBS) $(XF98SVGASYSLIBS))
+#endif
+#if HasGnuMake
+$(XF98SVGAOBJS) $(XF98SVGALIBS) $(XF98SVGASYSLIBS):: $(XF98SVGASUBDIRS)
+       @if [ -f $@ ]; then touch $@; fi
+#endif
+SetUIDServerTarget(XF98_SVGA,$(XF98SVGASUBDIRS),$(XF98SVGAOBJS),$(XF98SVGALIBS),$(XF98SVGASYSLIBS))
+#ifndef ServerToInstall
+#define ServerToInstall XF98_SVGA
+#endif
+#endif /* XF98SVGAServer */
+
+
+#if XF98EGCServer
+XCOMM
+XCOMM XFree98 EGC Server
+XCOMM
+DDXDIR2 = hw/xfree98
+XF98EGCSUBDIRS = $(STDDIRS) $(DDXDIR2) $(DEPDIRS)
+XF98EGCOBJS = $(XF98COMSRC)/XF86_VGA16.o $(XF98SRC)/vga16/vga16Conf.o \
+                $(XF98SRC)/vga16/misc/vga16misc.o
+XF98EGCLIBS = $(XF98VGA16DRIVERSRC)/LibraryTargetName(driver16) \
+               $(XF98SRC)/vga16/LibraryTargetName(vga16) $(XF98MLIBS) \
+               NoMFBBareLibs $(OTHEREXTS)
+XF98EGCSYSLIBS = $(SYSLIBS)
+#if HasParallelMake
+MakeMutex($(XF98EGCSUBDIRS) $(XF98EGCOBJS) $(XF98EGCLIBS) $(XF98EGCSYSLIBS))
+#endif
+#if HasGnuMake
+$(XF98EGCOBJS) $(XF98EGCLIBS) $(XF98EGCSYSLIBS):: $(XF98EGCSUBDIRS)
+       @if [ -f $@ ]; then touch $@; fi
+#endif
+SetUIDServerTarget(XF98_EGC,$(XF98EGCSUBDIRS),$(XF98EGCOBJS),$(XF98EGCLIBS),$(XF98EGCSYSLIBS))
+#ifndef ServerToInstall
+#define ServerToInstall XF98_EGC
+#endif
+#endif /* XF98EGCServer */
+
+
+#if XF98NECS3Server
+XCOMM
+XCOMM XFree98 NEC S3 Server
+XCOMM
+MFBDIR   = mfb
+CFB8DIR  = cfb
+CFB16DIR = cfb16
+CFB24DIR = cfb24
+CFB32DIR = cfb32
+DDXDIR2 = hw/xfree98
+XF98NECS3SUBDIRS = $(STDDIRS) $(MFBDIR) $(CFB8DIR) $(CFB16DIR) \
+                   $(CFB24DIR) $(CFB32DIR) $(DDXDIR2) $(DEPDIRS)
+XF98NECS3OBJS = $(XF98COMSRC)/XF86_S3.o $(XF98ACCELSRC)/s3nec/s3Conf.o \
+                $(XF98NECS3DRIVERSRC)/newmmio/newmmio.o \
+                $(XF98NECS3DRIVERSRC)/mmio_928/mmio_928.o \
+                $(XF98NECS3DRIVERSRC)/s3_generic/s3_generic.o
+XF98NECS3LIBS = $(XF98ACCELSRC)/s3nec/LibraryTargetName(s3nec) \
+                $(XF98ACCELSRC)/s3nec/s3newmmio/LibraryTargetName(s3necnewmmio) \
+                $(XF98ACCELSRC)/s3nec/s3mmio/LibraryTargetName(s3necmmio) \
+                $(XF98LIBSNEC) CFBLibs \
+                $(XF98ACCELSRC)/cache/LibraryTargetName(xf86cache)
+XF98NECS3SYSLIBS = $(SYSLIBS)
+#if HasParallelMake
+MakeMutex($(XF98NECS3SUBDIRS) $(XF98NECS3OBJS) $(XF98NECS3LIBS) $(XF98NECS3SYSLIBS))
+#endif
+#if HasGnuMake
+$(XF98NECS3OBJS) $(XF98NECS3LIBS) $(XF98NECS3SYSLIBS):: $(XF98NECS3SUBDIRS)
+       @if [ -f $@ ]; then touch $@; fi
+#endif
+SetUIDServerTarget(XF98_NECS3,$(XF98NECS3SUBDIRS),$(XF98NECS3OBJS),$(XF98NECS3LIBS),$(XF98NECS3SYSLIBS))
+#ifndef ServerToInstall
+#define ServerToInstall XF98_NECS3
+#endif
+#endif /* XF98NECS3Server */
+
+
+#if XF98PWSKBServer
+XCOMM
+XCOMM XFree98 S3 PW/PCSKB Server
+XCOMM
+MFBDIR   = mfb
+CFB8DIR  = cfb
+CFB16DIR = cfb16
+CFB24DIR = cfb24
+CFB32DIR = cfb32
+DDXDIR2 = hw/xfree98
+XF98PWSKBSUBDIRS = $(STDDIRS) $(MFBDIR) $(CFB8DIR) $(CFB16DIR) \
+                   $(CFB24DIR) $(CFB32DIR) $(DDXDIR2) $(DEPDIRS)
+XF98PWSKBOBJS = $(XF98COMSRC)/XF86_S3.o $(XF98ACCELSRC)/s3pwskb/s3Conf.o \
+                $(XF98PWSKBDRIVERSRC)/newmmio/newmmio.o \
+                $(XF98PWSKBDRIVERSRC)/mmio_928/mmio_928.o \
+                $(XF98PWSKBDRIVERSRC)/s3_generic/s3_generic.o
+XF98PWSKBLIBS = $(XF98ACCELSRC)/s3pwskb/LibraryTargetName(s3pwskb) \
+                $(XF98ACCELSRC)/s3pwskb/s3newmmio/LibraryTargetName(s3pwskbnewmmio) \
+                $(XF98ACCELSRC)/s3pwskb/s3mmio/LibraryTargetName(s3pwskbmmio) \
+                $(XF98LIBSPWSKB) CFBLibs \
+                $(XF98ACCELSRC)/cache/LibraryTargetName(xf86cache)
+XF98PWSKBSYSLIBS = $(SYSLIBS)
+#if HasParallelMake
+MakeMutex($(XF98PWSKBSUBDIRS) $(XF98PWSKBOBJS) $(XF98PWSKBLIBS) $(XF98PWSKBSYSLIBS))
+#endif
+#if HasGnuMake
+$(XF98PWSKBOBJS) $(XF98PWSKBLIBS) $(XF98PWSKBSYSLIBS):: $(XF98PWSKBSUBDIRS)
+       @if [ -f $@ ]; then touch $@; fi
+#endif
+SetUIDServerTarget(XF98_PWSKB,$(XF98PWSKBSUBDIRS),$(XF98PWSKBOBJS),$(XF98PWSKBLIBS),$(XF98PWSKBSYSLIBS))
+#ifndef ServerToInstall
+#define ServerToInstall XF98_PWSKB
+#endif
+#endif /* XF98PWSKBServer */
+
+
+#if XF98PWLBServer
+XCOMM
+XCOMM XFree98 S3 PW/LB Server
+XCOMM
+MFBDIR   = mfb
+CFB8DIR  = cfb
+CFB16DIR = cfb16
+CFB24DIR = cfb24
+CFB32DIR = cfb32
+DDXDIR2 = hw/xfree98
+XF98PWLBSUBDIRS = $(STDDIRS) $(MFBDIR) $(CFB8DIR) $(CFB16DIR) $(CFB24DIR) $(CFB32DIR) \
+                  $(DDXDIR2) $(DEPDIRS)
+XF98PWLBOBJS = $(XF98COMSRC)/XF86_S3.o $(XF98ACCELSRC)/s3pwlb/s3Conf.o \
+               $(XF98PWLBDRIVERSRC)/newmmio/newmmio.o \
+               $(XF98PWLBDRIVERSRC)/mmio_928/mmio_928.o \
+               $(XF98PWLBDRIVERSRC)/s3_generic/s3_generic.o
+XF98PWLBLIBS = $(XF98ACCELSRC)/s3pwlb/LibraryTargetName(s3pwlb) \
+               $(XF98ACCELSRC)/s3pwlb/s3newmmio/LibraryTargetName(s3pwlbnewmmio) \
+               $(XF98ACCELSRC)/s3pwlb/s3mmio/LibraryTargetName(s3pwlbmmio) \
+               $(XF98LIBSPWLB) CFBLibs \
+               $(XF98ACCELSRC)/cache/LibraryTargetName(xf86cache)
+XF98PWLBSYSLIBS = $(SYSLIBS)
+#if HasParallelMake
+MakeMutex($(XF98PWLBSUBDIRS) $(XF98PWLBOBJS) $(XF98PWLBLIBS) $(XF98PWLBSYSLIBS))
+#endif
+#if HasGnuMake
+$(XF98PWLBOBJS) $(XF98PWLBLIBS) $(XF98PWLBSYSLIBS):: $(XF98PWLBSUBDIRS)
+       @if [ -f $@ ]; then touch $@; fi
+#endif
+SetUIDServerTarget(XF98_PWLB,$(XF98PWLBSUBDIRS),$(XF98PWLBOBJS),$(XF98PWLBLIBS),$(XF98PWLBSYSLIBS))
+#ifndef ServerToInstall
+#define ServerToInstall XF98_PWLB
+#endif
+#endif /* XF98PWLBServer */
+
+
+#if XF98GA968Server
+XCOMM
+XCOMM XFree98 S3 GA-968 Server
+XCOMM
+MFBDIR   = mfb
+CFB8DIR  = cfb
+CFB16DIR = cfb16
+CFB24DIR = cfb24
+CFB32DIR = cfb32
+DDXDIR2 = hw/xfree98
+XF98GA968SUBDIRS = $(STDDIRS) $(MFBDIR) $(CFB8DIR) $(CFB16DIR) $(CFB24DIR) \
+                   $(CFB32DIR) $(DDXDIR2) $(DEPDIRS)
+XF98GA968OBJS = $(XF98COMSRC)/XF86_S3.o $(XF98ACCELSRC)/s3ga968/s3Conf.o \
+                $(XF98GA968DRIVERSRC)/newmmio/newmmio.o \
+                $(XF98GA968DRIVERSRC)/mmio_928/mmio_928.o \
+                $(XF98GA968DRIVERSRC)/s3_generic/s3_generic.o
+XF98GA968LIBS = $(XF98ACCELSRC)/s3ga968/LibraryTargetName(s3ga968) \
+                $(XF98ACCELSRC)/s3ga968/s3newmmio/LibraryTargetName(s3ga968newmmio) \
+                $(XF98ACCELSRC)/s3ga968/s3mmio/LibraryTargetName(s3ga968mmio) \
+                $(XF98LIBSGA968) CFBLibs \
+                $(XF98ACCELSRC)/cache/LibraryTargetName(xf86cache)
+XF98GA968SYSLIBS = $(SYSLIBS)
+#if HasParallelMake
+MakeMutex($(XF98GA968SUBDIRS) $(XF98GA968OBJS) $(XF98GA968LIBS) $(XF98GA968SYSLIBS))
+#endif
+#if HasGnuMake
+$(XF98GA968OBJS) $(XF98GA968LIBS) $(XF98GA968SYSLIBS):: $(XF98GA968SUBDIRS)
+       @if [ -f $@ ]; then touch $@; fi
+#endif
+SetUIDServerTarget(XF98_GA968,$(XF98GA968SUBDIRS),$(XF98GA968OBJS),$(XF98GA968LIBS),$(XF98GA968SYSLIBS))
+#ifndef ServerToInstall
+#define ServerToInstall XF98_GA968
+#endif
+#endif /* XF98GA968Server */
+
+
+#if XF86I128Server
+XCOMM
+XCOMM XFree86 I128 Server
+XCOMM
+MFBDIR   = mfb
+CFB8DIR  = cfb
+CFB16DIR = cfb16
+CFB24DIR = cfb24
+CFB32DIR = cfb32
+DDXDIR1  = hw/xfree86
+XF86I128SUBDIRS = $(STDDIRS) $(MFBDIR) $(CFB8DIR) $(CFB16DIR) $(CFB24DIR) \
+                  $(CFB32DIR) $(DDXDIR1) $(DEPDIRS)
+XF86I128OBJS = $(XF86COMSRC)/XF86_I128.o \
+              $(XF86SRC)/xaa/xaa8/xaa8.o $(XF86SRC)/xaa/xaa16/xaa16.o \
+              $(XF86SRC)/xaa/xaa24/xaa24.o $(XF86SRC)/xaa/xaa32/xaa32.o
+XF86I128LIBS = $(XF86ACCELSRC)/i128/LibraryTargetName(i128) \
+              $(XF86SRC)/xaa/LibraryTargetName(xaa) $(XF86LIBS) \
+               CFBLibs $(XF86ACCELSRC)/cache/LibraryTargetName(xf86cache)
+XF86I128SYSLIBS = $(SYSLIBS)
+#if HasParallelMake
+MakeMutex($(XF86I128SUBDIRS) $(XF86I128OBJS) $(XF86I128LIBS) $(XF86I128SYSLIBS))
+#endif
+#if HasGnuMake
+$(XF86I128OBJS) $(XF86I128LIBS) $(XF86I128SYSLIBS):: $(XF86I128SUBDIRS)
+       @if [ -f $@ ]; then touch $@; fi
+#endif
+SetUIDServerTarget(XF86_I128,$(XF86I128SUBDIRS),$(XF86I128OBJS),$(XF86I128LIBS),$(XF86I128SYSLIBS))
+#ifndef ServerToInstall
+#define ServerToInstall XF86_I128
+#endif
+#ifdef OS2Architecture
+LinkFile(XF86_I128.def,I128.def)
+InstallLinkKitNonExecFile(I128.def,$(LINKKITDIR))
+#endif
+#endif        /* XF86I128Server */
+
+
+#if XF86TGAServer
+XCOMM
+XCOMM XFree86 TGA Server
+XCOMM
+MFBDIR   = mfb
+CFB8DIR  = cfb
+CFB16DIR = cfb16
+CFB24DIR = cfb24
+CFB32DIR = cfb32
+DDXDIR1  = hw/xfree86
+XF86TGASUBDIRS = $(STDDIRS) $(MFBDIR) $(CFB8DIR) $(CFB16DIR) $(CFB24DIR) \
+                 $(CFB32DIR) $(DDXDIR1) $(DEPDIRS)
+XF86TGAOBJS = $(XF86COMSRC)/XF86_TGA.o \
+             $(XF86SRC)/xaa/xaa8/xaa8.o $(XF86SRC)/xaa/xaa16/xaa16.o \
+             $(XF86SRC)/xaa/xaa24/xaa24.o $(XF86SRC)/xaa/xaa32/xaa32.o
+XF86TGALIBS = $(XF86ACCELSRC)/tga/LibraryTargetName(tga) \
+             $(XF86SRC)/xaa/LibraryTargetName(xaa) $(XF86LIBS) \
+               CFBLibs $(XF86ACCELSRC)/cache/LibraryTargetName(xf86cache)
+XF86TGASYSLIBS = $(SYSLIBS)
+#if HasParallelMake
+MakeMutex($(XF86TGASUBDIRS) $(XF86TGAOBJS) $(XF86TGALIBS) $(XF86TGASYSLIBS))
+#endif
+#if HasGnuMake
+$(XF86TGAOBJS) $(XF86TGALIBS) $(XF86TGASYSLIBS):: $(XF86TGASUBDIRS)
+       @if [ -f $@ ]; then touch $@; fi
+#endif
+SetUIDServerTarget(XF86_TGA,$(XF86TGASUBDIRS),$(XF86TGAOBJS),$(XF86TGALIBS),$(XF86TGASYSLIBS))
+#ifndef ServerToInstall
+#define ServerToInstall XF86_TGA
+#endif
+#ifdef OS2Architecture
+LinkFile(XF86_TGA.def,TGA.def)
+InstallLinkKitNonExecFile(TGA.def,$(LINKKITDIR))
+#endif
+#endif
+
+
+#if XF68FBDevServer
+XCOMM
+XCOMM XFree68 Linux/m68k Frame Buffer Device Server
+XCOMM
+MFBDIR  = mfb
+DDXDIR3 = hw/xfree68
+#if XF68FBDevIPLAN2p2
+IPLAN2P2DIR = iplan2p2
+FBDEVFBLIBS:= $(FBDEVFBLIBS) iplan2p2/LibraryTargetName(ipl2p2)
+#endif
+#if XF68FBDevIPLAN2p4
+IPLAN2P4DIR = iplan2p4
+FBDEVFBLIBS:= $(FBDEVFBLIBS) iplan2p4/LibraryTargetName(ipl2p4)
+#endif
+#if XF68FBDevIPLAN2p8
+IPLAN2P8DIR = iplan2p8
+FBDEVFBLIBS:= $(FBDEVFBLIBS) iplan2p8/LibraryTargetName(ipl2p8)
+#endif
+#if XF68FBDevILBM
+ILBMDIR = ilbm
+FBDEVFBLIBS:= $(FBDEVFBLIBS) ilbm/LibraryTargetName(ilbm)
+#endif
+#if XF68FBDevAFB
+AFBDIR = afb
+FBDEVFBLIBS:= $(FBDEVFBLIBS) afb/LibraryTargetName(afb)
+#endif
+#if XF68FBDevCFB8
+CFB8DIR = cfb
+FBDEVFBLIBS:= $(FBDEVFBLIBS) $(CFB8)
+#endif
+#if XF68FBDevCFB16
+CFB16DIR = cfb16
+FBDEVFBLIBS:= $(FBDEVFBLIBS) $(CFB16)
+#endif
+#if XF68FBDevCFB32
+CFB32DIR = cfb32
+FBDEVFBLIBS:= $(FBDEVFBLIBS) $(CFB32)
+#endif
+XF68FBDevSUBDIRS = $(STDDIRS) $(MFBDIR) $(IPLAN2P2DIR) $(IPLAN2P4DIR) \
+                   $(IPLAN2P8DIR) $(ILBMDIR) $(AFBDIR) $(CFB8DIR) \
+                   $(CFB16DIR) $(CFB32DIR) $(DDXDIR3) $(DEPDIRS)
+XF68FBDevOBJS = $(XF68COMSRC)/XF68_FBDev.o
+XF68FBDevLIBS = $(XF68SRC)/fbdev/LibraryTargetName(fbdev) $(XF68LIBS) \
+                PreFbLibs $(FBDEVFBLIBS) PostFbLibs
+XF68FBDevSYSLIBS = $(SYSLIBS)
+#if HasParallelMake
+MakeMutex($(XF68FBDevSUBDIRS) $(XF68FBDevOBJS) $(XF68FBDevLIBS) $(XF68FBDevSYSLIBS))
+#endif
+#if HasGnuMake
+$(XF68FBDevOBJS) $(XF68FBDevLIBS) $(XF68FBDevSYSLIBS):: $(XF68FBDevSUBDIRS)
+       @if [ -f $@ ]; then touch $@; fi
+#endif
+SetUIDServerTarget(XF68_FBDev,$(XF68FBDevSUBDIRS),$(XF68FBDevOBJS),$(XF68FBDevLIBS),$(XF68FBDevSYSLIBS))
+#ifndef ServerToInstall
+#define ServerToInstall XF68_FBDev
+#endif
+#endif /* XF68FBDevServer */
+
+
+#if XprtServer
+XCOMM
+XCOMM Print Server
+XCOMM
+MFBDIR  = mfb
+CFB8DIR = cfb
+CFB32DIR = cfb32
+XPSUBDIRS = $(STDDIRS) $(MFBDIR) $(CFB8DIR) $(CFB32DIR) $(DEPDIRS)
+#if PrintOnlyServer
+XPOBJS = Xprint/ddxInit.o Xprint/miinitext.o
+XPLIBS = PreFbLibs $(XPDDXLIBS) $(XPDDXFBLIBS) PostFbLibs
+#else
+XPOBJS = Xprint/ddxInit.o
+XPLIBS = PreFbLibs PostFbLibs
+#endif
+#if (defined(SunArchitecture) || defined(SparcArchitecture)) && defined(SVR4Architecture)
+XPSYSLIBS = $(CBRT) $(SYSLIBS) -lw
+#else
+XPSYSLIBS = $(CBRT) $(SYSLIBS)
+#endif
+#if HasParallelMake
+MakeMutex($(XPSUBDIRS) $(XPOBJS) $(XPLIBS) $(XPSYSLIBS))
+#endif
+#if HasGnuMake
+$(XPOBJS) $(XPLIBS) $(XPSYSLIBS):: $(XPSUBDIRS)
+       @if [ -f $@ ]; then touch $@; fi
+#endif
+ServerTarget(Xprt,$(XPSUBDIRS),$(XPOBJS),$(XPLIBS),$(XPSYSLIBS))
+#endif /* XprtServer */
+
+#if XnestServer
+XCOMM
+XCOMM Server with Xlib-based ddx
+XCOMM
+#ifndef Win32Architecture
+XNESTDDXDIR = hw/xnest
+#else
+XNESTDDXDIR = hw
+#endif
+XNESTDIRS = $(STDDIRS) $(XNESTDDXDIR) $(DEPDIRS)
+#if !defined(LynxOSArchitecture) && !defined(Win32Architecture)
+XNESTOBJS = 
+#else
+XNESTOBJS = dix/main.o
+#endif
+XNEST = hw/xnest/LibraryTargetName(xnest)
+XNESTLIBS = PreFbLibs $(XNEST) NoMfbPostFbLibs $(XNEST)
+XNESTSYSLIBS = $(LDPRELIBS) $(XLIB) $(SYSLIBS)
+#if HasParallelMake
+MakeMutex($(XNESTDIRS) $(XNESTOBJS) $(XNESTLIBS) $(XNESTSYSLIBS))
+#endif
+#if HasGnuMake
+$(XNESTOBJS) $(XNESTLIBS) $(XNESTSYSLIBS):: $(XNESTDIRS)
+       @if [ -f $@ ]; then touch $@; fi
+#endif
+ServerTarget(Xnest,$(XNESTDIRS),$(XNESTOBJS),$(XNESTLIBS),$(XNESTSYSLIBS))
+#ifdef OS2Architecture
+InstallLinkKitNonExecFile(Xnest.def,$(LINKKITDIR))
+#endif
+#endif /* XnestServer */
+
+
+#if XnonServer
+XCOMM
+XCOMM non server, just compile sources for build test
+XCOMM
+MFBDIR   = mfb
+CFB8DIR  = cfb
+CFB16DIR = cfb16
+CFB32DIR = cfb32
+#if HasParallelMake
+MakeMutex($(STDDIRS) $(MFBDIR) $(CFB8DIR) $(CFB16DIR) $(CFB32DIR) $(DEPDIRS))
+#endif
+Xnon: $(STDDIRS) $(MFBDIR) $(CFB8DIR) $(CFB16DIR) $(CFB32DIR) $(DEPDIRS)
+#endif /* XnonServer */
+
+
+#if XVirtualFramebufferServer
+XCOMM
+XCOMM server with Virtual (malloced) framebuffer
+XCOMM
+MFBDIR   = mfb
+CFB8DIR  = cfb
+CFB16DIR = cfb16
+CFB24DIR = cfb24
+CFB32DIR = cfb32
+#ifndef Win32Architecture
+XVFBDDXDIR = hw/vfb
+#else
+XVFBDDXDIR = hw
+#endif
+XVFBDIRS = $(STDDIRS) $(MFBDIR) $(CFB8DIR) $(CFB16DIR) $(CFB24DIR) $(CFB32DIR) $(XVFBDDXDIR) $(DEPDIRS)
+#if !defined(LynxOSArchitecture) && !defined(Win32Architecture)
+XVFBOBJS = hw/vfb/stubs.o
+#else
+XVFBOBJS = hw/vfb/stubs.o dix/main.o
+#endif
+XVFB = hw/vfb/LibraryTargetName(vfb)
+XVFBLIBS = PreFbLibs $(XVFB) $(CFB) PostFbLibs
+XVFBSYSLIBS = $(SYSLIBS)
+#if HasParallelMake
+MakeMutex($(XVFBDIRS) $(XVFBOBJS) $(XVFB) $(XVFBLIBS) $(XVFBSYSLIBS))
+#endif
+#if HasGnuMake
+$(XVFBOBJS) $(XVFB) $(XVFBLIBS) $(XVFBSYSLIBS):: $(XVFBDIRS)
+       @if [ -f $@ ]; then touch $@; fi
+#endif
+ServerTarget(Xvfb,$(XVFBDIRS),$(XVFBOBJS),$(XVFBLIBS),$(XVFBSYSLIBS))
+#endif /* XVirtualFramebufferServer */
+
+
+#if XvncServer
+XCOMM
+XCOMM VNC X server
+XCOMM
+MFBDIR   = mfb
+CFB8DIR  = cfb
+CFB16DIR = cfb16
+CFB24DIR = cfb24
+CFB32DIR = cfb32
+DDXDIR1  = hw/vnc
+XVNCDIRS = $(STDDIRS) $(MFBDIR) $(CFB8DIR) $(CFB16DIR) $(CFB24DIR) $(CFB32DIR) $(DDXDIR1) $(DEPDIRS)
+XVNCOBJS = 
+#include <vnclibs.def>
+XVNC = hw/vnc/libvnc.a $(VNCLIBS)
+XVNCLIBS = PreFbLibs $(XVNC) $(CFB) PostFbLibs
+XVNCSYSLIBS = $(SYSLIBS) $(VNCSYSLIBS)
+ServerTarget(Xvnc,$(XVNCDIRS),$(XVNCOBJS),$(XVNCLIBS),$(XVNCSYSLIBS))
+#endif /* XvncServer */
+
+
+#if UseXserverWrapper
+SetUIDProgramTarget(Xwrapper,os/wrapper.o,NullParameter,NullParameter,NullParameter)
+InstallProgramWithFlags(Xwrapper,$(BINDIR),$(INSTUIDFLAGS))
+#endif
+
+CFBDIRS = $(CFB8DIR) $(CFB16DIR) $(CFB24DIR) $(CFB32DIR)
+IPLANDIRS = $(IPLAN2P2DIR) $(IPLAN2P4DIR) $(IPLAN2P8DIR)
+DDXDIRS = $(DDXDIR1) $(DDXDIR2) $(DDXDIR3) $(XVFBDDXDIR) $(XNESTDDXDIR)
+SUBDIRS = $(STDDIRS) $(MFBDIR) $(CFBDIRS) $(IPLANDIRS) $(ILBMDIR) $(AFBDIR) \
+          $(DDXDIRS)
+
+#if defined(ServerToInstall) && !defined(OS2Architecture)
+install::
+       -(cd $(DESTDIR)$(BINDIR); $(RM) X; $(LN) ServerToInstall X)
+#endif
+
+#define IHaveSubdirs
+
+DependSubdirs($(SUBDIRS))
+MakeLintLibSubdirs($(SUBDIRS))
+LintSubdirs($(SUBDIRS))
+
+ForceSubdirs($(DEPDIRS) $(SUBDIRS))
+
+InstallManPage(Xserver,$(MANDIR))
diff --git a/Xserver/programs/Xserver/Xext/Imakefile b/Xserver/programs/Xserver/Xext/Imakefile
new file mode 100644 (file)
index 0000000..f94777d
--- /dev/null
@@ -0,0 +1,80 @@
+XCOMM $XConsortium: Imakefile /main/56 1996/11/26 16:07:54 swick $
+XCOMM $XFree86: xc/programs/Xserver/Xext/Imakefile,v 3.11.2.1 1998/01/23 12:35:11 dawes Exp $
+#include <Server.tmpl>
+
+#if HasShm
+  SHMSRCS = shm.c
+  SHMOBJS = shm.o
+#endif
+
+#if BuildScreenSaverExt
+  SCRNSAVSRC = saver.c
+  SCRNSAVOBJ = saver.o
+#endif
+
+#if BuildXF86VidModeExt
+ VIDMODESRCS = xf86vmode.c
+ VIDMODEOBJS = xf86vmode.o
+#endif
+
+#if BuildXF86MiscExt
+XF86MISCSRCS = xf86misc.c
+XF86MISCOBJS = xf86misc.o
+#endif
+
+#if BuildXF86DGA
+ XF86DGASRCS = xf86dga.c
+ XF86DGAOBJS = xf86dga.o
+#endif
+
+#if BuildDPMSExt
+ DPMSSRCS = dpms.c
+ DPMSOBJS = dpms.o
+#endif
+
+#if BuildAppgroup
+  APPGROUPSRCS = appgroup.c
+  APPGROUPOBJS = appgroup.o
+#endif
+#if BuildXCSecurity
+    SECURITYSRCS = security.c
+    SECURITYOBJS = security.o
+ SERVERCONFIGDIR = ServerConfigDir
+   POLICYFILEDEF = -DDEFAULTPOLICYFILE=\"$(SERVERCONFIGDIR)/SecurityPolicy\"
+#endif
+
+       SRCS = shape.c $(SHMSRCS) mbuf.c \
+              mitmisc.c xtest.c xtest1di.c xtest1dd.c sleepuntil.c \
+             bigreq.c sync.c $(SCRNSAVSRC) xcmisc.c $(VIDMODESRCS) \
+             $(XF86MISCSRCS) $(XF86DGASRCS) $(SECURITYSRCS) \
+             $(DPMSSRCS) \
+             $(APPGROUPSRCS) xprint.c
+       OBJS = shape.o $(SHMOBJS) mbuf.o \
+              mitmisc.o xtest.o xtest1di.o xtest1dd.o sleepuntil.o \
+              bigreq.o sync.o $(SCRNSAVOBJ) xcmisc.o $(VIDMODEOBJS) \
+             $(XF86MISCOBJS) $(XF86DGAOBJS) $(SECURITYOBJS) \
+             $(DPMSOBJS) \
+             $(APPGROUPOBJS) xprint.o
+
+XF86INCLUDES = -I../hw/xfree86/common -I../hw/xfree86/os-support
+    INCLUDES = -I../include -I$(XINCLUDESRC) -I$(EXTINCSRC) $(XF86INCLUDES)
+    LINTLIBS = ../dix/llib-ldix.ln ../os/llib-los.ln
+
+NormalLibraryObjectRule()
+NormalLibraryTarget(ext,$(OBJS))
+LintLibraryTarget(ext,$(SRCS))
+NormalLintTarget($(SRCS))
+
+#if BuildXCSecurity
+SpecialCObjectRule(security,$(ICONFIGFILES),$(POLICYFILEDEF))
+#endif
+
+InstallLinkKitLibrary(ext,$(LINKKITDIR)/lib)
+
+LinkVarDirectory(xserver,.,xserver,.)
+
+#if BuildXCSecurity && InstallSecurityConfig
+InstallNonExecFile(SecurityPolicy,$(SERVERCONFIGDIR))
+#endif
+
+DependTarget()
diff --git a/Xserver/programs/Xserver/Xext/SecurityPolicy b/Xserver/programs/Xserver/Xext/SecurityPolicy
new file mode 100644 (file)
index 0000000..be6736a
--- /dev/null
@@ -0,0 +1,88 @@
+version-1 
+
+# $XConsortium: SecurityPolicy /main/3 1996/12/20 20:27:48 swick $
+
+# The site policy fields are interpreted by the XC-QUERY-SECURITY-1
+# authorization protocol.  The values are arbitrary and site-specific.
+# Refer to the Security Extension Specification for the usage of the policies.
+#sitepolicy A
+#sitepolicy B
+#sitepolicy C
+
+# Property access rules:
+# property <property> <window> <permissions>
+# <window> ::= any | root | <propertyselector>
+# <propertyselector> ::= <property> | <property>=<value>
+# <permissions> :== [ <operation> | <action> | <space> ]*
+# <operation> :== r | w | d
+#      r       read
+#      w       write
+#      d       delete
+# <action> :== a | i | e
+#      a       allow
+#      i       ignore
+#      e       error
+
+# Allow reading of application resources, but not writing.
+property RESOURCE_MANAGER      root    ar iw
+property SCREEN_RESOURCES      root    ar iw
+
+# Ignore attempts to use cut buffers.  Giving errors causes apps to crash,
+# and allowing access may give away too much information.
+property CUT_BUFFER0   root    irw
+property CUT_BUFFER1   root    irw
+property CUT_BUFFER2   root    irw
+property CUT_BUFFER3   root    irw
+property CUT_BUFFER4   root    irw
+property CUT_BUFFER5   root    irw
+property CUT_BUFFER6   root    irw
+property CUT_BUFFER7   root    irw
+
+# If you are using Motif, you probably want these.
+property _MOTIF_DEFAULT_BINDINGS       root    ar iw
+property _MOTIF_DRAG_WINDOW    root    ar iw
+property _MOTIF_DRAG_TARGETS   any     ar iw
+property _MOTIF_DRAG_ATOMS     any     ar iw
+property _MOTIF_DRAG_ATOM_PAIRS        any     ar iw
+
+# If you are running CDE you also need these
+property _MOTIF_WM_INFO                root    arw
+property TT_SESSION            root    irw
+property WM_ICON_SIZE          root    irw
+property "SDT Pixel Set"       any     irw
+
+# The next two rules let xwininfo -tree work when untrusted.
+property WM_NAME       any     ar
+
+# Allow read of WM_CLASS, but only for windows with WM_NAME.
+# This might be more restrictive than necessary, but demonstrates
+# the <required property> facility, and is also an attempt to
+# say "top level windows only."
+property WM_CLASS      WM_NAME ar
+
+# These next three let xlsclients work untrusted.  Think carefully
+# before including these; giving away the client machine name and command
+# may be exposing too much.
+property WM_STATE      WM_NAME ar
+property WM_CLIENT_MACHINE     WM_NAME ar
+property WM_COMMAND    WM_NAME ar
+
+# To let untrusted clients use the standard colormaps created by
+# xstdcmap, include these lines.
+property RGB_DEFAULT_MAP       root    ar
+property RGB_BEST_MAP  root    ar
+property RGB_RED_MAP   root    ar
+property RGB_GREEN_MAP root    ar
+property RGB_BLUE_MAP  root    ar
+property RGB_GRAY_MAP  root    ar
+
+# To let untrusted clients use the color management database created
+# by xcmsdb, include these lines.
+property XDCCC_LINEAR_RGB_CORRECTION   root    ar
+property XDCCC_LINEAR_RGB_MATRICES     root    ar
+property XDCCC_GRAY_SCREENWHITEPOINT   root    ar
+property XDCCC_GRAY_CORRECTION root    ar
+
+# To let untrusted clients use the overlay visuals that many vendors
+# support, include this line.
+property SERVER_OVERLAY_VISUALS        root    ar
diff --git a/Xserver/programs/Xserver/Xext/appgroup.c b/Xserver/programs/Xserver/Xext/appgroup.c
new file mode 100644 (file)
index 0000000..76e3c5c
--- /dev/null
@@ -0,0 +1,805 @@
+/*
+Copyright (c) 1996  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be included
+in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR
+OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall
+not be used in advertising or otherwise to promote the sale, use or
+other dealings in this Software without prior written authorization
+from the X Consortium.
+*/
+/* $XConsortium: appgroup.c /main/20 1996/12/08 16:14:27 kaleb $ */
+
+#define NEED_REPLIES
+#define NEED_EVENTS
+#include "X.h"
+#include "Xproto.h"
+#include "misc.h"
+#include "dixstruct.h"
+#include "extnsionst.h"
+#include "scrnintstr.h"
+#include "windowstr.h"
+#include "colormapst.h"
+#include "servermd.h"
+#define _XAG_SERVER_
+#include "Xagstr.h"
+#define _SECURITY_SERVER
+#include "security.h"
+#include "Xfuncproto.h"
+
+#define XSERV_t
+#include <X11/Xtrans.h>
+#include "../os/osdep.h"
+
+#include <stdio.h>
+
+typedef struct _AppGroupRec {
+    struct _AppGroupRec* next;
+    XID                        appgroupId;
+    ClientPtr*         clients;
+    int                        nclients;
+    ClientPtr          leader;
+    Bool               single_screen;
+    Window             default_root;
+    VisualID           root_visual;
+    Colormap           default_colormap;    
+    Pixel              black_pixel;
+    Pixel              white_pixel;
+    xConnSetupPrefix   connSetupPrefix;
+    char*              ConnectionInfo;
+} AppGroupRec, *AppGroupPtr;
+
+static int             ProcXagDispatch (), SProcXagDispatch ();
+static void            XagResetProc ();
+
+static unsigned char   XagReqCode = 0;
+static int             XagErrorBase;
+static int             XagCallbackRefCount = 0;
+
+static RESTYPE         RT_APPGROUP;
+static AppGroupPtr     appGrpList = NULL;
+
+extern WindowPtr* WindowTable;
+extern xConnSetupPrefix connSetupPrefix;
+extern char* ConnectionInfo;
+
+static 
+int XagAppGroupFree (what, id)
+    pointer what;
+    XID id; /* unused */
+{
+    int i;
+    AppGroupPtr pAppGrp = (AppGroupPtr) what;
+
+    if (pAppGrp->leader)
+       for (i = 0; i < pAppGrp->nclients; i++) {
+           pAppGrp->clients[i]->appgroup = NULL;
+           CloseDownClient (pAppGrp->clients[i]);
+       }
+
+    if (pAppGrp == appGrpList)
+       appGrpList = appGrpList->next;
+    else {
+       AppGroupPtr tpAppGrp;
+       for (tpAppGrp = appGrpList; 
+           tpAppGrp->next != NULL; 
+           tpAppGrp = tpAppGrp->next) {
+           if (tpAppGrp->next == pAppGrp) {
+               tpAppGrp->next = tpAppGrp->next->next;
+               break;
+           }
+       }
+    }
+    (void) xfree (pAppGrp->clients);
+    (void) xfree (pAppGrp->ConnectionInfo);
+    (void) xfree (what);
+    return Success;
+}
+
+/* static */
+void XagClientStateChange (pcbl, nulldata, calldata)
+    CallbackListPtr* pcbl;
+    pointer nulldata;
+    pointer calldata;
+{
+    SecurityAuthorizationPtr pAuth;
+    NewClientInfoRec* pci = (NewClientInfoRec*) calldata;
+    ClientPtr pClient = pci->client;
+    AppGroupPtr pAppGrp;
+    XID authId;
+
+    if (!pClient->appgroup) {
+       switch (pClient->clientState) {
+
+       case ClientStateAuthenticating:
+       case ClientStateRunning: 
+       case ClientStateCheckingSecurity:
+           return;
+
+       case ClientStateInitial: 
+       case ClientStateCheckedSecurity:
+           /* 
+            * If the client is connecting via a firewall proxy (which
+            * uses XC-QUERY-SECURITY-1, then the authId is available
+            * during ClientStateCheckedSecurity, otherwise it's
+            * available during ClientStateInitial.
+            *
+            * Don't get it from pClient because can't guarantee the order
+            * of the callbacks and the security extension might not have
+            * plugged it in yet.
+            */
+           authId = AuthorizationIDOfClient(pClient);
+           break;
+
+       case ClientStateGone:
+       case ClientStateRetained:
+           /*
+            * Don't get if from AuthorizationIDOfClient because can't
+            * guarantee the order of the callbacks and the security
+            * extension may have torn down the client's private data
+            */
+           authId = pClient->authId;
+           break;
+       }
+
+       if (authId == None)
+           return;
+
+       pAuth = (SecurityAuthorizationPtr)SecurityLookupIDByType(pClient,
+               authId, SecurityAuthorizationResType, SecurityReadAccess);
+
+       if (pAuth == NULL)
+           return;
+
+       for (pAppGrp = appGrpList; pAppGrp != NULL; pAppGrp = pAppGrp->next)
+           if (pAppGrp->appgroupId == pAuth->group) break;
+    } else {
+       pAppGrp = pClient->appgroup;
+    }
+
+    if (!pAppGrp)
+       return;
+
+    switch (pClient->clientState) {
+    case ClientStateAuthenticating:
+    case ClientStateRunning: 
+    case ClientStateCheckingSecurity:
+       break;
+
+    case ClientStateInitial: 
+    case ClientStateCheckedSecurity:
+       /* see the comment above about Initial vs. CheckedSecurity */
+       {
+           /* if this client already in AppGroup, don't add it again */
+           int i;
+           for (i = 0; i < pAppGrp->nclients; i++)
+               if (pClient == pAppGrp->clients[i]) return;
+       }
+       pAppGrp->clients = (ClientPtr*) xrealloc (pAppGrp->clients, 
+                               ++pAppGrp->nclients * sizeof (ClientPtr));
+       pAppGrp->clients[pAppGrp->nclients - 1] = pClient;
+       pClient->appgroup = pAppGrp;
+       break;
+
+    case ClientStateGone:
+    case ClientStateRetained: /* client disconnected, dump it */
+       {
+           int i;
+           for (i = 0; i < pAppGrp->nclients; i++)
+               if (pAppGrp->clients[i] == pClient) {
+                   pAppGrp->clients[i] = NULL;
+                   break;
+               }
+           for (i = 0; i < pAppGrp->nclients; i++)
+               if (pAppGrp->clients[i] == NULL && i + 1 < pAppGrp->nclients)
+                   pAppGrp->clients[i] = pAppGrp->clients[i + 1];
+           pAppGrp->nclients--;
+       }
+       pClient->appgroup = NULL; /* redundant, pClient will be freed */
+       break;
+    }
+}
+
+void
+XagExtensionInit ()
+{
+    ExtensionEntry* extEntry;
+
+    if (extEntry = AddExtension (XAGNAME,
+                               0,
+                               XagNumberErrors,
+                               ProcXagDispatch,
+                               SProcXagDispatch,
+                               XagResetProc,
+                               StandardMinorOpcode)) {
+       XagReqCode = (unsigned char)extEntry->base;
+       XagErrorBase = extEntry->errorBase;
+       RT_APPGROUP = CreateNewResourceType (XagAppGroupFree);
+    }
+}
+
+/*ARGSUSED*/
+static 
+void XagResetProc (extEntry)
+    ExtensionEntry* extEntry;
+{
+    DeleteCallback (&ClientStateCallback, XagClientStateChange, NULL);
+    XagCallbackRefCount = 0;
+    while (appGrpList) XagAppGroupFree ((pointer) appGrpList, 0);
+}
+
+static 
+int ProcXagQueryVersion (client)
+    register ClientPtr client;
+{
+    REQUEST (xXagQueryVersionReq);
+    xXagQueryVersionReply rep;
+    register int n;
+
+    REQUEST_SIZE_MATCH (xXagQueryVersionReq);
+    rep.type = X_Reply;
+    rep.length = 0;
+    rep.sequence_number = client->sequence;
+    rep.server_major_version = XAG_MAJOR_VERSION;
+    rep.server_minor_version = XAG_MINOR_VERSION;
+    if (client->swapped) {
+       swaps (&rep.sequence_number, n);
+       swapl (&rep.length, n);
+       swaps (&rep.server_major_version, n);
+       swaps (&rep.server_minor_version, n);
+    }
+    WriteToClient (client, sizeof (xXagQueryVersionReply), (char *)&rep);
+    return client->noClientException;
+}
+
+static 
+void ProcessAttr (pAppGrp, client, attrib_mask, attribs)
+    AppGroupPtr pAppGrp;
+    ClientPtr client;
+    unsigned int attrib_mask;
+    CARD32* attribs;
+{
+    int i;
+
+    for (i = XagNsingleScreen; i <= XagNappGroupLeader; i++) {
+       switch (attrib_mask & (1 << i)) {
+       case XagSingleScreenMask:
+           pAppGrp->single_screen = *attribs;
+           break;
+       case XagDefaultRootMask:
+           pAppGrp->default_root = *attribs;
+           break;
+       case XagRootVisualMask:
+           pAppGrp->root_visual = *attribs;
+           break;
+       case XagDefaultColormapMask:
+           pAppGrp->default_colormap = *attribs;
+           break;
+       case XagBlackPixelMask:
+           pAppGrp->black_pixel = *attribs;
+           break;
+       case XagWhitePixelMask:
+           pAppGrp->white_pixel = *attribs;
+           break;
+       case XagAppGroupLeaderMask:
+           pAppGrp->leader = client;
+           break;
+       default: continue;
+       }
+       attribs++;
+    }
+}
+
+static 
+void CreateConnectionInfo (pAppGrp)
+    AppGroupPtr pAppGrp;
+{
+    extern int connBlockScreenStart;
+    xConnSetup *setup = (xConnSetup*) ConnectionInfo;
+    xWindowRoot* rootp;
+    xWindowRoot* roots[MAXSCREENS];
+    unsigned int rootlens[MAXSCREENS];
+    xDepth* depth;
+    int olen;
+    int snum, i;
+
+    rootp = (xWindowRoot*) (ConnectionInfo + connBlockScreenStart);
+    for (snum = 0; snum < screenInfo.numScreens; snum++) {
+
+       rootlens[snum] = sizeof (xWindowRoot);
+       roots[snum] = rootp;
+
+       depth = (xDepth*) (rootp + 1);
+       for (i = 0; i < rootp->nDepths; i++) {
+           rootlens[snum] += sizeof (xDepth) + 
+                             depth->nVisuals * sizeof (xVisualType);
+           depth = (xDepth *)(((char*)(depth + 1)) +
+               depth->nVisuals * sizeof (xVisualType));
+       }
+       rootp = (xWindowRoot*) depth;
+    }
+    snum = 0;
+    if (pAppGrp->default_root) {
+       for (; snum < screenInfo.numVideoScreens; snum++) {
+           if (roots[snum]->windowId == pAppGrp->default_root)
+               break;
+        }
+    }
+    olen = connBlockScreenStart + rootlens[snum];
+    for (i = screenInfo.numVideoScreens; i < screenInfo.numScreens; i++)
+       olen += rootlens[i];
+    pAppGrp->ConnectionInfo = (char*) xalloc (olen);
+    if (!pAppGrp->ConnectionInfo)
+       return;
+    memmove (pAppGrp->ConnectionInfo, ConnectionInfo, connBlockScreenStart);
+    ((xConnSetup*) (pAppGrp->ConnectionInfo))->numRoots = 
+       1 + screenInfo.numScreens - screenInfo.numVideoScreens;
+    memmove (pAppGrp->ConnectionInfo + connBlockScreenStart,
+            (void*) roots[snum], rootlens[snum]);
+    rootp = (xWindowRoot*) (pAppGrp->ConnectionInfo + connBlockScreenStart);
+    if (pAppGrp->default_colormap) {
+       rootp->defaultColormap = pAppGrp->default_colormap;
+       rootp->whitePixel = pAppGrp->white_pixel;
+       rootp->blackPixel = pAppGrp->black_pixel;
+    }
+    if (pAppGrp->root_visual)
+       rootp->rootVisualID = pAppGrp->root_visual;
+    rootp = (xWindowRoot*) (((char*)rootp) + rootlens[snum]);
+    for (i = screenInfo.numVideoScreens; i < screenInfo.numScreens; i++) {
+       memmove ((void*) rootp, (void*) roots[i], rootlens[i]);
+       rootp = (xWindowRoot*) (((char*) rootp) + rootlens[i]);
+    }
+    pAppGrp->connSetupPrefix = connSetupPrefix;
+    pAppGrp->connSetupPrefix.length = olen >> 2;
+}
+
+static 
+AppGroupPtr CreateAppGroup (client, appgroupId, attrib_mask, attribs)
+    ClientPtr client;
+    XID appgroupId;
+    unsigned int attrib_mask;
+    CARD32* attribs;
+{
+    AppGroupPtr pAppGrp;
+    int i;
+
+    pAppGrp = (AppGroupPtr) xalloc (sizeof(AppGroupRec));
+    if (pAppGrp) {
+       pAppGrp->next = appGrpList;
+       appGrpList = pAppGrp;
+       pAppGrp->appgroupId = appgroupId;
+       pAppGrp->clients = (ClientPtr*) xalloc (0);
+       pAppGrp->nclients = 0;
+       pAppGrp->leader = NULL;
+       pAppGrp->default_root = 0;
+       pAppGrp->root_visual = 0;
+       pAppGrp->default_colormap = 0;
+       pAppGrp->black_pixel = -1;
+       pAppGrp->white_pixel = -1;
+       pAppGrp->ConnectionInfo = NULL;
+       ProcessAttr (pAppGrp, client, attrib_mask, attribs);
+    }
+    return pAppGrp;
+}
+
+static 
+int AttrValidate (client, attrib_mask, pAppGrp)
+    ClientPtr client;
+    int attrib_mask;
+    AppGroupPtr pAppGrp;
+{
+    WindowPtr pWin;
+    int idepth, ivids, found;
+    ScreenPtr pScreen;
+    DepthPtr pDepth;
+    ColormapPtr pColormap;
+
+    pWin = LookupWindow (pAppGrp->default_root, client);
+    /* XXX check that pWin is not NULL */
+    pScreen = pWin->drawable.pScreen;
+    if (WindowTable[pScreen->myNum]->drawable.id != pAppGrp->default_root)
+       return BadWindow;
+    pDepth = pScreen->allowedDepths;
+    if (pAppGrp->root_visual) {
+       found = FALSE;
+       for (idepth = 0; idepth < pScreen->numDepths; idepth++, pDepth++) {
+           for (ivids = 0; ivids < pDepth->numVids; ivids++) {
+               if (pAppGrp->root_visual == pDepth->vids[ivids]) {
+                   found = TRUE;
+                   break;
+               }
+           }
+       }
+       if (!found)
+           return BadMatch;
+    }
+    if (pAppGrp->default_colormap) {
+
+       pColormap = (ColormapPtr)LookupIDByType (pAppGrp->default_colormap, RT_COLORMAP);
+       /* XXX check that pColormap is not NULL */
+       if (pColormap->pScreen != pScreen)
+           return BadColor;
+       if (pColormap->pVisual->vid != (pAppGrp->root_visual ? pAppGrp->root_visual : pScreen->rootVisual))
+           return BadMatch;
+    }
+    return client->noClientException;
+}
+
+/* static */
+int ProcXagCreate (client)
+    register ClientPtr client;
+{
+    REQUEST (xXagCreateReq);
+    AppGroupPtr pAppGrp;
+    int ret;
+
+    REQUEST_AT_LEAST_SIZE (xXagCreateReq);
+
+    LEGAL_NEW_RESOURCE (stuff->app_group, client);
+    pAppGrp = CreateAppGroup (client, stuff->app_group, 
+               stuff->attrib_mask, (CARD32*) &stuff[1]);
+    if (!pAppGrp)
+       return BadAlloc;
+    ret = AttrValidate (client, stuff->attrib_mask, pAppGrp);
+    if (ret != Success) {
+       XagAppGroupFree ((pointer)pAppGrp, (XID)0);
+       return ret;
+    }
+    if (pAppGrp->single_screen) {
+       CreateConnectionInfo (pAppGrp);
+       if (!pAppGrp->ConnectionInfo)
+           return BadAlloc;
+    }
+    if (!AddResource (stuff->app_group, RT_APPGROUP, (pointer)pAppGrp))
+       return BadAlloc;
+    if (XagCallbackRefCount++ == 0)
+       (void) AddCallback (&ClientStateCallback, XagClientStateChange, NULL);
+    return client->noClientException;
+}
+
+/* static */
+int ProcXagDestroy (client)
+    register ClientPtr client;
+{
+    AppGroupPtr pAppGrp;
+    REQUEST (xXagDestroyReq);
+
+    REQUEST_SIZE_MATCH (xXagDestroyReq);
+    pAppGrp = (AppGroupPtr)SecurityLookupIDByType (client, 
+               (XID)stuff->app_group, RT_APPGROUP, SecurityReadAccess);
+    if (!pAppGrp) return XagBadAppGroup;
+    FreeResource ((XID)stuff->app_group, RT_NONE);
+    if (--XagCallbackRefCount == 0)
+       (void) DeleteCallback (&ClientStateCallback, XagClientStateChange, NULL);
+    return client->noClientException;
+}
+
+static 
+int ProcXagGetAttr (client)
+    register ClientPtr client;
+{
+    AppGroupPtr pAppGrp;
+    REQUEST (xXagGetAttrReq);
+    xXagGetAttrReply rep;
+    int n;
+
+    REQUEST_SIZE_MATCH (xXagGetAttrReq);
+    pAppGrp = (AppGroupPtr)SecurityLookupIDByType (client, 
+               (XID)stuff->app_group, RT_APPGROUP, SecurityReadAccess);
+    if (!pAppGrp) return XagBadAppGroup;
+    rep.default_root = pAppGrp->default_root;
+    rep.root_visual = pAppGrp->root_visual;
+    rep.default_colormap = pAppGrp->default_colormap;
+    rep.single_screen = pAppGrp->single_screen;
+    rep.app_group_leader = (pAppGrp->leader) ? 1 : 0;
+    if (client->swapped) {
+       swaps (&rep.sequence_number, n);
+       swapl (&rep.length, n);
+       swapl (&rep.default_root, n);
+       swapl (&rep.root_visual, n);
+       swapl (&rep.default_colormap, n);
+    }
+    WriteToClient (client, sizeof (xXagGetAttrReply), (char *)&rep);
+    return client->noClientException;
+}
+
+static 
+int ProcXagQuery (client)
+    register ClientPtr client;
+{
+    ClientPtr pClient;
+    AppGroupPtr pAppGrp;
+    REQUEST (xXagQueryReq);
+    int n;
+
+    REQUEST_SIZE_MATCH (xXagQueryReq);
+    pClient = LookupClient (stuff->resource, client);
+    for (pAppGrp = appGrpList; pAppGrp != NULL; pAppGrp = pAppGrp->next)
+       for (n = 0; n < pAppGrp->nclients; n++)
+           if (pAppGrp->clients[n] == pClient) {
+               xXagQueryReply rep;
+
+               rep.type = X_Reply;
+               rep.length = 0;
+               rep.sequence_number = client->sequence;
+               rep.app_group = pAppGrp->appgroupId;
+               if (client->swapped) {
+                   swaps (&rep.sequence_number, n);
+                   swapl (&rep.length, n);
+                   swapl (&rep.app_group, n);
+               }
+               WriteToClient (client, sizeof (xXagQueryReply), (char *)&rep);
+               return client->noClientException;
+           }
+
+    return BadMatch;
+}
+
+static 
+int ProcXagCreateAssoc (client)
+    register ClientPtr client;
+{
+    REQUEST (xXagCreateAssocReq);
+
+    REQUEST_SIZE_MATCH (xXagCreateAssocReq);
+#ifdef WIN32
+    if (stuff->window_type != XagWindowTypeWin32)
+#else
+    if (stuff->window_type != XagWindowTypeX11)
+#endif
+       return BadMatch;
+#ifdef WIN32 /* and Mac, etc */
+    if (!LocalClient (client))
+       return BadAccess;
+#endif
+
+/* Macintosh, OS/2, and MS-Windows servers have some work to do here */
+
+    return client->noClientException;
+}
+
+static 
+int ProcXagDestroyAssoc (client)
+    register ClientPtr client;
+{
+    REQUEST (xXagDestroyAssocReq);
+
+    REQUEST_SIZE_MATCH (xXagDestroyAssocReq);
+/* Macintosh, OS/2, and MS-Windows servers have some work to do here */
+    return client->noClientException;
+}
+
+static 
+int ProcXagDispatch (client)
+    register ClientPtr client;
+{
+    REQUEST (xReq);
+    switch (stuff->data)
+    {
+    case X_XagQueryVersion:
+       return ProcXagQueryVersion (client);
+    case X_XagCreate:
+       return ProcXagCreate (client);
+    case X_XagDestroy:
+       return ProcXagDestroy (client);
+    case X_XagGetAttr:
+       return ProcXagGetAttr (client);
+    case X_XagQuery:
+       return ProcXagQuery (client);
+    case X_XagCreateAssoc:
+       return ProcXagCreateAssoc (client);
+    case X_XagDestroyAssoc:
+       return ProcXagDestroyAssoc (client);
+    default:
+       return BadRequest;
+    }
+}
+
+static 
+int SProcXagQueryVersion (client)
+    register ClientPtr client;
+{
+    register int n;
+    REQUEST(xXagQueryVersionReq);
+    swaps(&stuff->length, n);
+    return ProcXagQueryVersion(client);
+}
+
+static 
+int SProcXagCreate (client)
+    ClientPtr client;
+{
+    register int n;
+    REQUEST (xXagCreateReq);
+    swaps (&stuff->length, n);
+    REQUEST_AT_LEAST_SIZE (xXagCreateReq);
+    swapl (&stuff->app_group, n);
+    swapl (&stuff->attrib_mask, n);
+    SwapRestL (stuff);
+    return ProcXagCreate (client);
+}
+
+static 
+int SProcXagDestroy (client)
+    ClientPtr client;
+{
+    register int n;
+    REQUEST (xXagDestroyReq);
+    swaps (&stuff->length, n);
+    REQUEST_SIZE_MATCH (xXagDestroyReq);
+    swapl (&stuff->app_group, n);
+    return ProcXagDestroy (client);
+}
+
+static 
+int SProcXagGetAttr (client)
+    ClientPtr client;
+{
+    register int n;
+    REQUEST (xXagGetAttrReq);
+    swaps (&stuff->length, n);
+    REQUEST_SIZE_MATCH (xXagGetAttrReq);
+    swapl (&stuff->app_group, n);
+    return ProcXagGetAttr (client);
+}
+
+static 
+int SProcXagQuery (client)
+    ClientPtr client;
+{
+    register int n;
+    REQUEST (xXagQueryReq);
+    swaps (&stuff->length, n);
+    REQUEST_SIZE_MATCH (xXagQueryReq);
+    swapl (&stuff->resource, n);
+    return ProcXagQuery (client);
+}
+
+static 
+int SProcXagCreateAssoc (client)
+    ClientPtr client;
+{
+    register int n;
+    REQUEST (xXagCreateAssocReq);
+    swaps (&stuff->length, n);
+    REQUEST_SIZE_MATCH (xXagCreateAssocReq);
+    swapl (&stuff->window, n);
+    swapl (&stuff->window_type, n);
+    swaps (&stuff->system_window_len, n);
+    return ProcXagCreateAssoc (client);
+}
+
+static 
+int SProcXagDestroyAssoc (client)
+    ClientPtr client;
+{
+    register int n;
+    REQUEST (xXagDestroyAssocReq);
+    swaps (&stuff->length, n);
+    REQUEST_SIZE_MATCH (xXagDestroyAssocReq);
+    swapl (&stuff->window, n);
+    return ProcXagDestroyAssoc (client);
+}
+
+static 
+int SProcXagDispatch (client)
+    register ClientPtr client;
+{
+    REQUEST(xReq);
+    switch (stuff->data)
+    {
+    case X_XagQueryVersion:
+       return SProcXagQueryVersion (client);
+    case X_XagCreate:
+       return SProcXagCreate (client);
+    case X_XagDestroy:
+       return SProcXagDestroy (client);
+    case X_XagGetAttr:
+       return SProcXagGetAttr (client);
+    case X_XagQuery:
+       return SProcXagQuery (client);
+    case X_XagCreateAssoc:
+       return SProcXagCreateAssoc (client);
+    case X_XagDestroyAssoc:
+       return SProcXagDestroyAssoc (client);
+    default:
+       return BadRequest;
+    }
+}
+
+Colormap XagDefaultColormap (client)
+    ClientPtr client;
+{
+    return (client->appgroup ? client->appgroup->default_colormap : None);
+}
+
+VisualID XagRootVisual (client)
+    ClientPtr client;
+{
+    return (client->appgroup ? client->appgroup->root_visual : 0);
+}
+
+ClientPtr XagLeader (client)
+    ClientPtr client;
+{
+    return (client->appgroup ? client->appgroup->leader : NULL);
+}
+
+/*
+ * Return whether the Map request event should be sent to the appgroup leader.
+ * We don't want to send it to the leader when the window is on a different
+ * screen, e.g. a print screen.
+ */
+Bool XagIsControlledRoot (client, pParent)
+    ClientPtr client;
+    WindowPtr pParent;
+{
+    if (client->appgroup) {
+       if (client->appgroup->single_screen && 
+           pParent->drawable.id == client->appgroup->default_root)
+           return TRUE;
+       else if (!pParent->parent)
+           return TRUE;
+       else
+           return FALSE;
+    }
+    return FALSE; 
+}
+
+void XagConnectionInfo (client, conn_prefix, conn_info, num_screen)
+    ClientPtr client;
+    xConnSetupPrefix** conn_prefix;
+    char** conn_info;
+    int* num_screen;
+{
+    if (client->appgroup && client->appgroup->ConnectionInfo) {
+       *conn_prefix = &client->appgroup->connSetupPrefix;
+       *conn_info = client->appgroup->ConnectionInfo;
+       *num_screen = ((xConnSetup*)(client->appgroup->ConnectionInfo))->numRoots;
+    } 
+}
+
+XID XagId (client)
+    ClientPtr client;
+{
+    return (client->appgroup ? client->appgroup->appgroupId : 0);
+}
+
+void XagGetDeltaInfo (client, buf)
+    ClientPtr client;
+    CARD32* buf;
+{
+    *buf++ = (CARD32) client->appgroup->default_root;
+    *buf++ = (CARD32) client->appgroup->root_visual;
+    *buf++ = (CARD32) client->appgroup->default_colormap;
+    *buf++ = (CARD32) client->appgroup->black_pixel;
+    *buf = (CARD32) client->appgroup->white_pixel;
+}
+
+void XagCallClientStateChange (client)
+    ClientPtr client;
+{
+    if (appGrpList) {
+       NewClientInfoRec clientinfo;
+
+       clientinfo.client = client;
+       XagClientStateChange (NULL, NULL, (pointer)&clientinfo);
+    }
+}
diff --git a/Xserver/programs/Xserver/Xext/bigreq.c b/Xserver/programs/Xserver/Xext/bigreq.c
new file mode 100644 (file)
index 0000000..bbd6839
--- /dev/null
@@ -0,0 +1,96 @@
+/* $XConsortium: bigreq.c /main/5 1996/08/01 19:22:48 dpw $ */
+/* $XFree86: xc/programs/Xserver/Xext/bigreq.c,v 3.2 1996/12/23 06:28:58 dawes Exp $ */
+/*
+
+Copyright (c) 1992  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be included
+in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR
+OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall
+not be used in advertising or otherwise to promote the sale, use or
+other dealings in this Software without prior written authorization
+from the X Consortium.
+
+*/
+
+#define NEED_EVENTS
+#include "X.h"
+#include "Xproto.h"
+#include "misc.h"
+#include "os.h"
+#include "dixstruct.h"
+#include "extnsionst.h"
+#include "bigreqstr.h"
+
+static unsigned char XBigReqCode;
+
+static void BigReqResetProc(
+#if NeedFunctionPrototypes
+    ExtensionEntry * /* extEntry */
+#endif
+);
+
+static DISPATCH_PROC(ProcBigReqDispatch);
+
+void
+BigReqExtensionInit()
+{
+    ExtensionEntry *extEntry;
+
+    if ((extEntry = AddExtension(XBigReqExtensionName, 0, 0,
+                                ProcBigReqDispatch, ProcBigReqDispatch,
+                                BigReqResetProc, StandardMinorOpcode)) != 0)
+       XBigReqCode = (unsigned char)extEntry->base;
+    DeclareExtensionSecurity(XBigReqExtensionName, TRUE);
+}
+
+/*ARGSUSED*/
+static void
+BigReqResetProc (extEntry)
+    ExtensionEntry     *extEntry;
+{
+}
+
+static int
+ProcBigReqDispatch (client)
+    register ClientPtr client;
+{
+    REQUEST(xBigReqEnableReq);
+    xBigReqEnableReply rep;
+    register int n;
+
+    if (client->swapped) {
+       swaps(&stuff->length, n);
+    }
+    if (stuff->brReqType != X_BigReqEnable)
+       return BadRequest;
+    REQUEST_SIZE_MATCH(xBigReqEnableReq);
+    client->big_requests = TRUE;
+    rep.type = X_Reply;
+    rep.length = 0;
+    rep.sequenceNumber = client->sequence;
+    rep.max_request_size = MAX_BIG_REQUEST_SIZE;
+    if (client->swapped) {
+       swaps(&rep.sequenceNumber, n);
+       swapl(&rep.max_request_size, n);
+    }
+    WriteToClient(client, sizeof(xBigReqEnableReply), (char *)&rep);
+    return(client->noClientException);
+}
diff --git a/Xserver/programs/Xserver/Xext/dpms.c b/Xserver/programs/Xserver/Xext/dpms.c
new file mode 100644 (file)
index 0000000..f3a5894
--- /dev/null
@@ -0,0 +1,425 @@
+/*****************************************************************
+
+Copyright (c) 1996 Digital Equipment Corporation, Maynard, Massachusetts.
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software.
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+DIGITAL EQUIPMENT CORPORATION BE LIABLE FOR ANY CLAIM, DAMAGES, INCLUDING, 
+BUT NOT LIMITED TO CONSEQUENTIAL OR INCIDENTAL DAMAGES, OR OTHER LIABILITY, 
+WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR 
+IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of Digital Equipment Corporation 
+shall not be used in advertising or otherwise to promote the sale, use or other
+dealings in this Software without prior written authorization from Digital 
+Equipment Corporation.
+
+******************************************************************/
+
+/*
+ * HISTORY
+ *
+ * @(#)RCSfile: dpms.c,v Revision: 1.1.4.5  (DEC) Date: 1996/03/04 15:27:00
+ */
+
+/* $XFree86: xc/programs/Xserver/Xext/dpms.c,v 3.1 1997/01/12 10:40:06 dawes Exp $ */
+
+#include "X.h"
+#include "Xproto.h"
+#include "misc.h"
+#include "os.h"
+#include "dixstruct.h"
+#include "extnsionst.h"
+#include "opaque.h"
+#include "dpms.h"
+#include "dpmsstr.h"
+#include <stdio.h>
+
+static unsigned char DPMSCode;
+static int ProcDPMSDispatch(), SProcDPMSDispatch();
+static void DPMSResetProc();
+static int ProcDPMSGetVersion(), SProcDPMSGetVersion();
+static int ProcDPMSGetTimeouts(), SProcDPMSGetTimeouts();
+static int ProcDPMSSetTimeouts(), ProcDPMSSetTimeouts();
+static int ProcDPMSEnable(), ProcDPMSEnable();
+static int ProcDPMSDisable(), ProcDPMSDisable();
+static int ProcDPMSForceLevel(), ProcDPMSForceLevel();
+
+void
+DPMSExtensionInit()
+{
+    ExtensionEntry *extEntry, *AddExtension();
+    
+    if (extEntry = AddExtension(DPMSExtensionName, 0, 0,
+                               ProcDPMSDispatch, SProcDPMSDispatch,
+                               DPMSResetProc, StandardMinorOpcode))
+       DPMSCode = (unsigned char)extEntry->base;
+    return;
+}
+
+/*ARGSUSED*/
+static void
+DPMSResetProc (extEntry)
+    ExtensionEntry     *extEntry;
+{
+}
+
+static int
+ProcDPMSGetVersion(client)
+    register ClientPtr client;
+{
+    REQUEST(xDPMSGetVersionReq);
+    xDPMSGetVersionReply rep;
+    register int n;
+
+    REQUEST_SIZE_MATCH(xDPMSGetVersionReq);
+
+    rep.type = X_Reply;
+    rep.length = 0;
+    rep.sequenceNumber = client->sequence;
+    rep.majorVersion = DPMSMajorVersion;
+    rep.minorVersion = DPMSMinorVersion;
+    if (client->swapped) {
+       swaps(&rep.sequenceNumber, n);
+       swaps(&rep.majorVersion, n);
+       swaps(&rep.minorVersion, n);
+    }
+    WriteToClient(client, sizeof(xDPMSGetVersionReply), (char *)&rep);
+    return(client->noClientException);
+}
+
+static int
+ProcDPMSCapable(client)
+    register ClientPtr client;
+{
+    REQUEST(xDPMSCapableReq);
+    xDPMSCapableReply rep;
+    register int n;
+
+    REQUEST_SIZE_MATCH(xDPMSCapableReq);
+
+    rep.type = X_Reply;
+    rep.length = 0;
+    rep.sequenceNumber = client->sequence;
+    rep.capable = DPMSCapableFlag;
+
+    WriteToClient(client, sizeof(xDPMSCapableReply), (char *)&rep);
+    return(client->noClientException);
+}
+
+static int
+ProcDPMSGetTimeouts(client)
+    register ClientPtr client;
+{
+    REQUEST(xDPMSGetTimeoutsReq);
+    xDPMSGetTimeoutsReply rep;
+    register int n;
+
+    REQUEST_SIZE_MATCH(xDPMSGetTimeoutsReq);
+
+    rep.type = X_Reply;
+    rep.length = 0;
+    rep.sequenceNumber = client->sequence;
+    rep.standby = DPMSStandbyTime / MILLI_PER_SECOND;
+    rep.suspend = DPMSSuspendTime / MILLI_PER_SECOND;
+    rep.off = DPMSOffTime / MILLI_PER_SECOND;
+
+    if (client->swapped) {
+       swaps(&rep.sequenceNumber, n);
+       swaps(&rep.standby, n);
+       swaps(&rep.suspend, n);
+       swaps(&rep.off, n);
+    }
+    WriteToClient(client, sizeof(xDPMSGetTimeoutsReply), (char *)&rep);
+    return(client->noClientException);
+}
+
+static int
+ProcDPMSSetTimeouts(client)
+    register ClientPtr client;
+{
+    REQUEST(xDPMSSetTimeoutsReq);
+    register int n;
+
+    REQUEST_SIZE_MATCH(xDPMSSetTimeoutsReq);
+
+    if ((stuff->off != 0)&&(stuff->off < stuff->suspend)) 
+    {
+       client->errorValue = stuff->off;
+       return BadValue;
+    }
+    if ((stuff->suspend != 0)&&(stuff->suspend < stuff->standby))
+    {
+       client->errorValue = stuff->suspend;
+       return BadValue;
+    }  
+       
+    DPMSStandbyTime = stuff->standby * MILLI_PER_SECOND;
+    DPMSSuspendTime = stuff->suspend * MILLI_PER_SECOND;
+    DPMSOffTime = stuff->off * MILLI_PER_SECOND;
+
+    return(client->noClientException);
+}
+
+static int
+ProcDPMSEnable(client)
+    register ClientPtr client;
+{
+    REQUEST(xDPMSEnableReq);
+
+    REQUEST_SIZE_MATCH(xDPMSEnableReq);
+
+    if (DPMSCapableFlag)
+       DPMSEnabled = TRUE;
+
+    return(client->noClientException);
+}
+
+static int
+ProcDPMSDisable(client)
+    register ClientPtr client;
+{
+    REQUEST(xDPMSDisableReq);
+
+    REQUEST_SIZE_MATCH(xDPMSDisableReq);
+
+    DPMSSet(DPMSModeOn);
+
+    DPMSEnabled = FALSE;
+
+    return(client->noClientException);
+}
+
+static int
+ProcDPMSForceLevel(client)
+    register ClientPtr client;
+{
+    REQUEST(xDPMSForceLevelReq);
+
+    REQUEST_SIZE_MATCH(xDPMSForceLevelReq);
+
+    if (!DPMSEnabled)
+       return BadMatch;
+
+    if (stuff->level == DPMSModeOn) {
+      lastDeviceEventTime.milliseconds =
+          GetTimeInMillis();
+    } else if (stuff->level == DPMSModeStandby) {
+      lastDeviceEventTime.milliseconds =
+          GetTimeInMillis() -  DPMSStandbyTime;
+    } else if (stuff->level == DPMSModeSuspend) {
+      lastDeviceEventTime.milliseconds =
+          GetTimeInMillis() -  DPMSSuspendTime;
+    } else if (stuff->level == DPMSModeOff) {
+      lastDeviceEventTime.milliseconds =
+          GetTimeInMillis() -  DPMSOffTime;
+    } else {
+       client->errorValue = stuff->level;
+       return BadValue;
+    }
+
+    DPMSSet(stuff->level);
+
+    return(client->noClientException);
+}
+
+static int
+ProcDPMSInfo(client)
+    register ClientPtr client;
+{
+    REQUEST(xDPMSInfoReq);
+    xDPMSInfoReply rep;
+    register int n;
+
+    REQUEST_SIZE_MATCH(xDPMSInfoReq);
+
+    rep.type = X_Reply;
+    rep.length = 0;
+    rep.sequenceNumber = client->sequence;
+    rep.power_level = DPMSPowerLevel;
+    rep.state = DPMSEnabled;
+
+    if (client->swapped) {
+       swaps(&rep.sequenceNumber, n);
+       swaps(&rep.power_level, n);
+    }
+    WriteToClient(client, sizeof(xDPMSInfoReply), (char *)&rep);
+    return(client->noClientException);
+}
+
+static int
+ProcDPMSDispatch (client)
+    register ClientPtr client;
+{
+    REQUEST(xReq);
+
+    switch (stuff->data)
+    {
+    case X_DPMSGetVersion:
+       return ProcDPMSGetVersion(client);
+    case X_DPMSCapable:
+       return ProcDPMSCapable(client);
+    case X_DPMSGetTimeouts:
+       return ProcDPMSGetTimeouts(client);
+    case X_DPMSSetTimeouts:
+       return ProcDPMSSetTimeouts(client);
+    case X_DPMSEnable:
+       return ProcDPMSEnable(client);
+    case X_DPMSDisable:
+       return ProcDPMSDisable(client);
+    case X_DPMSForceLevel:
+       return ProcDPMSForceLevel(client);
+    case X_DPMSInfo:
+       return ProcDPMSInfo(client);
+    default:
+       return BadRequest;
+    }
+}
+
+static int
+SProcDPMSGetVersion(client)
+    register ClientPtr client;
+{
+    register int n;
+    REQUEST(xDPMSGetVersionReq);
+
+    swaps(&stuff->length, n);
+    REQUEST_SIZE_MATCH(xDPMSGetVersionReq);
+    swaps(&stuff->majorVersion, n);
+    swaps(&stuff->minorVersion, n);
+    return ProcDPMSGetVersion(client);
+}
+
+static int
+SProcDPMSCapable(client)
+    register ClientPtr client;
+{
+    REQUEST(xDPMSCapableReq);
+    register int n;
+
+    swaps(&stuff->length, n);
+    REQUEST_SIZE_MATCH(xDPMSCapableReq);
+
+    return ProcDPMSCapable(client);
+}
+
+static int
+SProcDPMSGetTimeouts(client)
+    register ClientPtr client;
+{
+    REQUEST(xDPMSGetTimeoutsReq);
+    register int n;
+
+    swaps(&stuff->length, n);
+    REQUEST_SIZE_MATCH(xDPMSGetTimeoutsReq);
+
+    return ProcDPMSGetTimeouts(client);
+}
+
+static int
+SProcDPMSSetTimeouts(client)
+    register ClientPtr client;
+{
+    REQUEST(xDPMSSetTimeoutsReq);
+    register int n;
+
+    swaps(&stuff->length, n);
+    REQUEST_SIZE_MATCH(xDPMSSetTimeoutsReq);
+
+    swaps(&stuff->standby, n);
+    swaps(&stuff->suspend, n);
+    swaps(&stuff->off, n);
+    return ProcDPMSSetTimeouts(client);
+}
+
+static int
+SProcDPMSEnable(client)
+    register ClientPtr client;
+{
+    REQUEST(xDPMSEnableReq);
+    register int n;
+
+    swaps(&stuff->length, n);
+    REQUEST_SIZE_MATCH(xDPMSEnableReq);
+
+    return ProcDPMSEnable(client);
+}
+
+static int
+SProcDPMSDisable(client)
+    register ClientPtr client;
+{
+    REQUEST(xDPMSDisableReq);
+    register int n;
+
+    swaps(&stuff->length, n);
+    REQUEST_SIZE_MATCH(xDPMSDisableReq);
+
+    return ProcDPMSDisable(client);
+}
+
+static int
+SProcDPMSForceLevel(client)
+    register ClientPtr client;
+{
+    REQUEST(xDPMSForceLevelReq);
+    register int n;
+
+    swaps(&stuff->length, n);
+    REQUEST_SIZE_MATCH(xDPMSForceLevelReq);
+
+    swaps(&stuff->level, n);
+
+    return ProcDPMSForceLevel(client);
+}
+
+static int
+SProcDPMSInfo(client)
+    register ClientPtr client;
+{
+    REQUEST(xDPMSInfoReq);
+    register int n;
+
+    swaps(&stuff->length, n);
+    REQUEST_SIZE_MATCH(xDPMSInfoReq);
+
+    return ProcDPMSInfo(client);
+}
+
+static int
+SProcDPMSDispatch (client)
+    register ClientPtr client;
+{
+    REQUEST(xReq);
+    switch (stuff->data)
+    {
+    case X_DPMSGetVersion:
+       return SProcDPMSGetVersion(client);
+    case X_DPMSCapable:
+       return SProcDPMSCapable(client);
+    case X_DPMSGetTimeouts:
+       return SProcDPMSGetTimeouts(client);
+    case X_DPMSSetTimeouts:
+       return SProcDPMSSetTimeouts(client);
+    case X_DPMSEnable:
+       return SProcDPMSEnable(client);
+    case X_DPMSDisable:
+       return SProcDPMSDisable(client);
+    case X_DPMSForceLevel:
+       return SProcDPMSForceLevel(client);
+    case X_DPMSInfo:
+       return SProcDPMSInfo(client);
+    default:
+       return BadRequest;
+    }
+}
diff --git a/Xserver/programs/Xserver/Xext/mbuf.c b/Xserver/programs/Xserver/Xext/mbuf.c
new file mode 100644 (file)
index 0000000..2b18133
--- /dev/null
@@ -0,0 +1,1804 @@
+/************************************************************
+
+Copyright (c) 1989  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+********************************************************/
+
+/* $XConsortium: mbuf.c /main/25 1996/12/02 10:19:23 lehors $ */
+/* $XFree86: xc/programs/Xserver/Xext/mbuf.c,v 3.3 1997/01/18 06:52:58 dawes Exp $ */
+#define NEED_REPLIES
+#define NEED_EVENTS
+#include <stdio.h>
+#include "X.h"
+#include "Xproto.h"
+#include "window.h"
+#include "os.h"
+#include "windowstr.h"
+#include "scrnintstr.h"
+#include "pixmapstr.h"
+#include "extnsionst.h"
+#include "dixstruct.h"
+#include "resource.h"
+#include "opaque.h"
+#define _MULTIBUF_SERVER_      /* don't want Xlib structures */
+#include "regionstr.h"
+#include "gcstruct.h"
+#include "inputstr.h"
+#include "multibufst.h"
+#if !defined(WIN32) && !defined(MINIX) && !defined(Lynx)
+#include <sys/time.h>
+#endif
+
+/* given an OtherClientPtr obj, get the ClientPtr */
+#define rClient(obj) (clients[CLIENT_ID((obj)->resource)])
+
+/* given a MultibufferPtr b, get the ClientPtr */
+#define bClient(b)   (clients[CLIENT_ID(b->pPixmap->drawable.id)])
+
+#define ValidEventMasks (ExposureMask|MultibufferClobberNotifyMask|MultibufferUpdateNotifyMask)
+
+static unsigned char   MultibufferReqCode;
+static int             MultibufferEventBase;
+static int             MultibufferErrorBase;
+int                    MultibufferScreenIndex = -1;
+int                    MultibufferWindowIndex = -1;
+
+static void            PerformDisplayRequest (
+#if NeedFunctionPrototypes
+                               MultibuffersPtr * /* ppMultibuffers */,
+                               MultibufferPtr * /* pMultibuffer */,
+                               int /* nbuf */
+#endif
+                               );
+static Bool            QueueDisplayRequest (
+#if NeedFunctionPrototypes
+                               ClientPtr /* client */,
+                               TimeStamp /* activateTime */
+#endif
+                               );
+
+static void            BumpTimeStamp (
+#if NeedFunctionPrototypes
+                               TimeStamp * /* ts */,
+                               CARD32 /* inc */
+#endif
+                               );
+
+static void            AliasMultibuffer (
+#if NeedFunctionPrototypes
+                               MultibuffersPtr /* pMultibuffers */,
+                               int /* i */
+#endif
+                               );
+static void            RecalculateMultibufferOtherEvents (
+#if NeedFunctionPrototypes
+                               MultibufferPtr /* pMultibuffer */
+#endif
+                               );
+static int             EventSelectForMultibuffer(
+#if NeedFunctionPrototypes
+                               MultibufferPtr /* pMultibuffer */,
+                               ClientPtr /* client */,
+                               Mask /* mask */
+#endif
+                               );
+
+/*
+ * The Pixmap associated with a buffer can be found as a resource
+ * with this type
+ */
+RESTYPE                        MultibufferDrawableResType;
+static int             MultibufferDrawableDelete (
+#if NeedFunctionPrototypes
+                               pointer /* value */,
+                               XID /* id */
+#endif
+                               );
+/*
+ * The per-buffer data can be found as a resource with this type.
+ * the resource id of the per-buffer data is the same as the resource
+ * id of the pixmap
+ */
+static RESTYPE         MultibufferResType;
+static int             MultibufferDelete (
+#if NeedFunctionPrototypes
+                               pointer /* value */,
+                               XID /* id */
+#endif
+                               );
+
+/*
+ * The per-window data can be found as a resource with this type,
+ * using the window resource id
+ */
+static RESTYPE         MultibuffersResType;
+static int             MultibuffersDelete (
+#if NeedFunctionPrototypes
+                               pointer /* value */,
+                               XID /* id */
+#endif
+                               );
+
+/*
+ * Clients other than the buffer creator attach event masks in
+ * OtherClient structures; each has a resource of this type.
+ */
+static RESTYPE         OtherClientResType;
+static int             OtherClientDelete (
+#if NeedFunctionPrototypes
+                               pointer /* value */,
+                               XID /* id */
+#endif
+                               );
+
+/****************
+ * MultibufferExtensionInit
+ *
+ * Called from InitExtensions in main()
+ *
+ ****************/
+
+extern DISPATCH_PROC(ProcGetBufferAttributes);
+
+static DISPATCH_PROC(ProcClearImageBufferArea);
+static DISPATCH_PROC(ProcCreateImageBuffers);
+static DISPATCH_PROC(ProcDestroyImageBuffers);
+static DISPATCH_PROC(ProcDisplayImageBuffers);
+static DISPATCH_PROC(ProcGetBufferInfo);
+static DISPATCH_PROC(ProcGetBufferVersion);
+static DISPATCH_PROC(ProcGetMBufferAttributes);
+static DISPATCH_PROC(ProcMultibufferDispatch);
+static DISPATCH_PROC(ProcSetBufferAttributes);
+static DISPATCH_PROC(ProcSetMBufferAttributes);
+static DISPATCH_PROC(SProcClearImageBufferArea);
+static DISPATCH_PROC(SProcCreateImageBuffers);
+static DISPATCH_PROC(SProcDestroyImageBuffers);
+static DISPATCH_PROC(SProcDisplayImageBuffers);
+static DISPATCH_PROC(SProcGetBufferAttributes);
+static DISPATCH_PROC(SProcGetBufferInfo);
+static DISPATCH_PROC(SProcGetBufferVersion);
+static DISPATCH_PROC(SProcGetMBufferAttributes);
+static DISPATCH_PROC(SProcMultibufferDispatch);
+static DISPATCH_PROC(SProcSetBufferAttributes);
+static DISPATCH_PROC(SProcSetMBufferAttributes);
+
+static void            MultibufferResetProc(
+#if NeedFunctionPrototypes
+                               ExtensionEntry * /* extEntry */
+#endif
+                               );
+static void            SClobberNotifyEvent(
+#if NeedFunctionPrototypes
+                               xMbufClobberNotifyEvent * /* from */,
+                               xMbufClobberNotifyEvent * /* to */
+# endif
+                               );
+static void            SUpdateNotifyEvent(
+#if NeedFunctionPrototypes
+                               xMbufUpdateNotifyEvent * /* from */,
+                               xMbufUpdateNotifyEvent * /* to */
+#endif
+                               );
+static Bool            MultibufferPositionWindow(
+#if NeedFunctionPrototypes
+                               WindowPtr /* pWin */,
+                               int /* x */,
+                               int /* y */
+#endif
+                               );
+
+static void            SetupBackgroundPainter (
+#if NeedFunctionPrototypes
+                               WindowPtr /* pWin */,
+                               GCPtr /* pGC */
+#endif
+                               );
+
+static int             DeliverEventsToMultibuffer (
+#if NeedFunctionPrototypes
+                               MultibufferPtr /* pMultibuffer */,
+                               xEvent * /* pEvents */,
+                               int /* count */,
+                               Mask /* filter */
+#endif
+                               );
+
+void
+MultibufferExtensionInit()
+{
+    ExtensionEntry         *extEntry;
+    int                            i, j;
+    ScreenPtr              pScreen;
+    MultibufferScreenPtr    pMultibufferScreen;
+
+    /*
+     * allocate private pointers in windows and screens.  Allocating
+     * window privates may seem like an unnecessary expense, but every
+     * PositionWindow call must check to see if the window is
+     * multi-buffered; a resource lookup is too expensive.
+     */
+    MultibufferScreenIndex = AllocateScreenPrivateIndex ();
+    if (MultibufferScreenIndex < 0)
+       return;
+    MultibufferWindowIndex = AllocateWindowPrivateIndex ();
+    for (i = 0; i < screenInfo.numScreens; i++)
+    {
+       pScreen = screenInfo.screens[i];
+       if (!AllocateWindowPrivate (pScreen, MultibufferWindowIndex, 0) ||
+           !(pMultibufferScreen = (MultibufferScreenPtr) xalloc (sizeof (MultibufferScreenRec))))
+       {
+           for (j = 0; j < i; j++)
+               xfree (screenInfo.screens[j]->devPrivates[MultibufferScreenIndex].ptr);
+           return;
+       }
+       pScreen->devPrivates[MultibufferScreenIndex].ptr = (pointer) pMultibufferScreen;
+       /*
+        * wrap PositionWindow to resize the pixmap when the window
+        * changes size
+        */
+       pMultibufferScreen->PositionWindow = pScreen->PositionWindow;
+       pScreen->PositionWindow = MultibufferPositionWindow;
+    }
+    /*
+     * create the resource types
+     */
+    MultibufferDrawableResType =
+       CreateNewResourceType(MultibufferDrawableDelete)|RC_CACHED|RC_DRAWABLE;
+    MultibufferResType = CreateNewResourceType(MultibufferDelete);
+    MultibuffersResType = CreateNewResourceType(MultibuffersDelete);
+    OtherClientResType = CreateNewResourceType(OtherClientDelete);
+    if (MultibufferDrawableResType && MultibufferResType &&
+       MultibuffersResType &&  OtherClientResType &&
+       (extEntry = AddExtension(MULTIBUFFER_PROTOCOL_NAME,
+                                MultibufferNumberEvents, 
+                                MultibufferNumberErrors,
+                                ProcMultibufferDispatch, SProcMultibufferDispatch,
+                                MultibufferResetProc, StandardMinorOpcode)))
+    {
+       MultibufferReqCode = (unsigned char)extEntry->base;
+       MultibufferEventBase = extEntry->eventBase;
+       MultibufferErrorBase = extEntry->errorBase;
+       EventSwapVector[MultibufferEventBase + MultibufferClobberNotify] = (EventSwapPtr) SClobberNotifyEvent;
+       EventSwapVector[MultibufferEventBase + MultibufferUpdateNotify] = (EventSwapPtr) SUpdateNotifyEvent;
+    }
+}
+
+/*ARGSUSED*/
+static void
+MultibufferResetProc (extEntry)
+ExtensionEntry *extEntry;
+{
+    int                            i;
+    ScreenPtr              pScreen;
+    MultibufferScreenPtr    pMultibufferScreen;
+    
+    if (MultibufferScreenIndex < 0)
+       return;
+    for (i = 0; i < screenInfo.numScreens; i++)
+    {
+       pScreen = screenInfo.screens[i];
+       if (pScreen->devPrivates[MultibufferScreenIndex].ptr)
+       {
+           pMultibufferScreen = (MultibufferScreenPtr) pScreen->devPrivates[MultibufferScreenIndex].ptr;
+           pScreen->PositionWindow = pMultibufferScreen->PositionWindow;
+           xfree (pMultibufferScreen);
+       }
+    }
+}
+
+static int
+ProcGetBufferVersion (client)
+    register ClientPtr client;
+{
+    xMbufGetBufferVersionReply rep;
+    register int               n;
+
+    REQUEST_SIZE_MATCH (xMbufGetBufferVersionReq);
+    rep.type = X_Reply;
+    rep.length = 0;
+    rep.sequenceNumber = client->sequence;
+    rep.majorVersion = MULTIBUFFER_MAJOR_VERSION;
+    rep.minorVersion = MULTIBUFFER_MINOR_VERSION;
+    if (client->swapped) {
+       swaps(&rep.sequenceNumber, n);
+       swapl(&rep.length, n);
+    }
+    WriteToClient(client, sizeof (xMbufGetBufferVersionReply), (char *)&rep);
+    return (client->noClientException);
+}
+
+static void
+SetupBackgroundPainter (pWin, pGC)
+    WindowPtr  pWin;
+    GCPtr      pGC;
+{
+    pointer        gcvalues[4];
+    int                    ts_x_origin, ts_y_origin;
+    PixUnion       background;
+    int                    backgroundState;
+    Mask           gcmask;
+
+    /*
+     * First take care of any ParentRelative stuff by altering the
+     * tile/stipple origin to match the coordinates of the upper-left
+     * corner of the first ancestor without a ParentRelative background.
+     * This coordinate is, of course, negative.
+     */
+
+    ts_x_origin = ts_y_origin = 0;
+    while (pWin->backgroundState == ParentRelative) {
+       ts_x_origin -= pWin->origin.x;
+       ts_y_origin -= pWin->origin.y;
+       pWin = pWin->parent;
+    }
+    backgroundState = pWin->backgroundState;
+    background = pWin->background;
+
+    switch (backgroundState)
+    {
+    case BackgroundPixel:
+       gcvalues[0] = (pointer) background.pixel;
+       gcvalues[1] = (pointer) FillSolid;
+       gcmask = GCForeground|GCFillStyle;
+       break;
+
+    case BackgroundPixmap:
+       gcvalues[0] = (pointer) FillTiled;
+       gcvalues[1] = (pointer) background.pixmap;
+       gcvalues[2] = (pointer) ts_x_origin;
+       gcvalues[3] = (pointer) ts_y_origin;
+       gcmask = GCFillStyle|GCTile|GCTileStipXOrigin|GCTileStipYOrigin;
+       break;
+
+    default:
+       gcvalues[0] = (pointer) GXnoop;
+       gcmask = GCFunction;
+    }
+    DoChangeGC(pGC, gcmask, (XID *)gcvalues, TRUE);
+}
+
+int
+CreateImageBuffers (pWin, nbuf, ids, action, hint)
+    WindowPtr  pWin;
+    int                nbuf;
+    XID                *ids;
+    int                action;
+    int                hint;
+{
+    MultibuffersPtr    pMultibuffers;
+    MultibufferPtr     pMultibuffer;
+    ScreenPtr          pScreen;
+    int                        width, height, depth;
+    int                        i;
+    GCPtr              pClearGC = NULL;
+    xRectangle         clearRect;
+
+    DestroyImageBuffers(pWin);
+    pMultibuffers = (MultibuffersPtr) xalloc (sizeof (MultibuffersRec) +
+                                             nbuf * sizeof (MultibufferRec));
+    if (!pMultibuffers)
+       return BadAlloc;
+    pMultibuffers->pWindow = pWin;
+    pMultibuffers->buffers = (MultibufferPtr) (pMultibuffers + 1);
+    pMultibuffers->refcnt = pMultibuffers->numMultibuffer = 0;
+    if (!AddResource (pWin->drawable.id, MultibuffersResType, (pointer) pMultibuffers))
+       return BadAlloc;
+    width = pWin->drawable.width;
+    height = pWin->drawable.height;
+    depth = pWin->drawable.depth;
+    pScreen = pWin->drawable.pScreen;
+
+    if (pWin->backgroundState != None)
+    {
+       pClearGC = GetScratchGC (pWin->drawable.depth, pScreen);
+       SetupBackgroundPainter (pWin, pClearGC);
+       clearRect.x = clearRect.y = 0;
+       clearRect.width = width;
+       clearRect.height = height;
+    }
+
+    for (i = 0; i < nbuf; i++)
+    {
+       pMultibuffer = &pMultibuffers->buffers[i];
+       pMultibuffer->eventMask = 0L;
+       pMultibuffer->otherEventMask = 0L;
+       pMultibuffer->otherClients = (OtherClientsPtr) NULL;
+       pMultibuffer->number = i;
+       pMultibuffer->side = MultibufferSideMono;
+       pMultibuffer->clobber = MultibufferUnclobbered;
+       pMultibuffer->pMultibuffers = pMultibuffers;
+       if (!AddResource (ids[i], MultibufferResType, (pointer) pMultibuffer))
+           break;
+       pMultibuffer->pPixmap = (*pScreen->CreatePixmap) (pScreen, width, height, depth);
+       if (!pMultibuffer->pPixmap)
+           break;
+       if (!AddResource (ids[i], MultibufferDrawableResType, (pointer) pMultibuffer->pPixmap))
+       {
+           FreeResource (ids[i], MultibufferResType);
+           (*pScreen->DestroyPixmap) (pMultibuffer->pPixmap);
+           break;
+       }
+       pMultibuffer->pPixmap->drawable.id = ids[i];
+
+       if (i > 0 && pClearGC)
+       {
+           ValidateGC((DrawablePtr)pMultibuffer->pPixmap, pClearGC);
+           (*pClearGC->ops->PolyFillRect)((DrawablePtr)pMultibuffer->pPixmap,
+                                          pClearGC, 1, &clearRect);
+       }
+    }
+    pMultibuffers->numMultibuffer = i;
+    pMultibuffers->refcnt = i;
+    pMultibuffers->displayedMultibuffer = -1;
+    if (i > 0)
+       AliasMultibuffer (pMultibuffers, 0);
+    pMultibuffers->updateAction = action;
+    pMultibuffers->updateHint = hint;
+    pMultibuffers->windowMode = MultibufferModeMono;
+    pMultibuffers->lastUpdate.months = 0;
+    pMultibuffers->lastUpdate.milliseconds = 0;
+    pMultibuffers->width = width;
+    pMultibuffers->height = height;
+    pWin->devPrivates[MultibufferWindowIndex].ptr = (pointer) pMultibuffers;
+    if (pClearGC) FreeScratchGC(pClearGC);
+    return Success;
+}
+
+static int
+ProcCreateImageBuffers (client)
+    register ClientPtr client;
+{
+    REQUEST(xMbufCreateImageBuffersReq);
+    xMbufCreateImageBuffersReply       rep;
+    register int               n;
+    WindowPtr                  pWin;
+    XID                                *ids;
+    int                                len, nbuf;
+    int                                i;
+    int                                err;
+
+    REQUEST_AT_LEAST_SIZE (xMbufCreateImageBuffersReq);
+    len = stuff->length - (sizeof(xMbufCreateImageBuffersReq) >> 2);
+    if (len == 0)
+       return BadLength;
+    if (!(pWin = LookupWindow (stuff->window, client)))
+       return BadWindow;
+    if (pWin->drawable.class == InputOnly)
+       return BadMatch;
+    switch (stuff->updateAction)
+    {
+    case MultibufferUpdateActionUndefined:
+    case MultibufferUpdateActionBackground:
+    case MultibufferUpdateActionUntouched:
+    case MultibufferUpdateActionCopied:
+       break;
+    default:
+       client->errorValue = stuff->updateAction;
+       return BadValue;
+    }
+    switch (stuff->updateHint)
+    {
+    case MultibufferUpdateHintFrequent:
+    case MultibufferUpdateHintIntermittent:
+    case MultibufferUpdateHintStatic:
+       break;
+    default:
+       client->errorValue = stuff->updateHint;
+       return BadValue;
+    }
+    nbuf = len;
+    ids = (XID *) &stuff[1];
+    for (i = 0; i < nbuf; i++)
+    {
+       LEGAL_NEW_RESOURCE(ids[i], client);
+    }
+    err = CreateImageBuffers (pWin, nbuf, ids,
+                             stuff->updateAction, stuff->updateHint);
+    if (err != Success)
+       return err;
+    rep.type = X_Reply;
+    rep.length = 0;
+    rep.sequenceNumber = client->sequence;
+    rep.numberBuffer = ((MultibuffersPtr) (pWin->devPrivates[MultibufferWindowIndex].ptr))->numMultibuffer;
+    if (client->swapped)
+    {
+       swaps(&rep.sequenceNumber, n);
+       swapl(&rep.length, n);
+       swaps(&rep.numberBuffer, n);
+    }
+    WriteToClient(client, sizeof (xMbufCreateImageBuffersReply), (char *)&rep);
+    return (client->noClientException);
+}
+
+static int
+ProcDisplayImageBuffers (client)
+    register ClientPtr client;
+{
+    REQUEST(xMbufDisplayImageBuffersReq);
+    MultibufferPtr         *pMultibuffer;
+    MultibuffersPtr        *ppMultibuffers;
+    int                    nbuf;
+    XID                    *ids;
+    int                    i, j;
+    CARD32         minDelay;
+    TimeStamp      activateTime, bufferTime;
+    
+    REQUEST_AT_LEAST_SIZE (xMbufDisplayImageBuffersReq);
+    nbuf = stuff->length - (sizeof (xMbufDisplayImageBuffersReq) >> 2);
+    if (!nbuf)
+       return Success;
+    minDelay = stuff->minDelay;
+    ids = (XID *) &stuff[1];
+    ppMultibuffers = (MultibuffersPtr *) ALLOCATE_LOCAL(nbuf * sizeof (MultibuffersPtr));
+    pMultibuffer = (MultibufferPtr *) ALLOCATE_LOCAL(nbuf * sizeof (MultibufferPtr));
+    if (!ppMultibuffers || !pMultibuffer)
+    {
+       if (ppMultibuffers) DEALLOCATE_LOCAL(ppMultibuffers);
+       if (pMultibuffer)   DEALLOCATE_LOCAL(pMultibuffer);
+       client->errorValue = 0;
+       return BadAlloc;
+    }
+    activateTime.months = 0;
+    activateTime.milliseconds = 0;
+    for (i = 0; i < nbuf; i++)
+    {
+       pMultibuffer[i] = (MultibufferPtr) LookupIDByType (ids[i], MultibufferResType);
+       if (!pMultibuffer[i])
+       {
+           DEALLOCATE_LOCAL(ppMultibuffers);
+           DEALLOCATE_LOCAL(pMultibuffer);
+           client->errorValue = ids[i];
+           return MultibufferErrorBase + MultibufferBadBuffer;
+       }
+       ppMultibuffers[i] = pMultibuffer[i]->pMultibuffers;
+       for (j = 0; j < i; j++)
+       {
+           if (ppMultibuffers[i] == ppMultibuffers[j])
+           {
+               DEALLOCATE_LOCAL(ppMultibuffers);
+               DEALLOCATE_LOCAL(pMultibuffer);
+               client->errorValue = ids[i];
+               return BadMatch;
+           }
+       }
+       bufferTime = ppMultibuffers[i]->lastUpdate;
+       BumpTimeStamp (&bufferTime, minDelay);
+       if (CompareTimeStamps (bufferTime, activateTime) == LATER)
+           activateTime = bufferTime;
+    }
+    UpdateCurrentTime ();
+    if (CompareTimeStamps (activateTime, currentTime) == LATER &&
+       QueueDisplayRequest (client, activateTime))
+    {
+       ;
+    }
+    else
+       PerformDisplayRequest (ppMultibuffers, pMultibuffer, nbuf);
+    DEALLOCATE_LOCAL(ppMultibuffers);
+    DEALLOCATE_LOCAL(pMultibuffer);
+    return Success;
+}
+
+static int
+ProcDestroyImageBuffers (client)
+    register ClientPtr client;
+{
+    REQUEST (xMbufDestroyImageBuffersReq);
+    WindowPtr  pWin;
+
+    REQUEST_SIZE_MATCH (xMbufDestroyImageBuffersReq);
+    if (!(pWin = LookupWindow (stuff->window, client)))
+       return BadWindow;
+    DestroyImageBuffers (pWin);
+    return Success;
+}
+
+static int
+ProcSetMBufferAttributes (client)
+    register ClientPtr client;
+{
+    REQUEST (xMbufSetMBufferAttributesReq);
+    WindowPtr  pWin;
+    MultibuffersPtr    pMultibuffers;
+    int                len;
+    Mask       vmask;
+    Mask       index2;
+    CARD32     updateHint;
+    XID                *vlist;
+
+    REQUEST_AT_LEAST_SIZE (xMbufSetMBufferAttributesReq);
+    pWin = LookupWindow (stuff->window, client);
+    if (!pWin)
+       return BadWindow;
+    pMultibuffers = (MultibuffersPtr)LookupIDByType (pWin->drawable.id, MultibuffersResType);
+    if (!pMultibuffers)
+       return BadMatch;
+    len = stuff->length - (sizeof (xMbufSetMBufferAttributesReq) >> 2);
+    vmask = stuff->valueMask;
+    if (len != Ones (vmask))
+       return BadLength;
+    vlist = (XID *) &stuff[1];
+    while (vmask)
+    {
+       index2 = (Mask) lowbit (vmask);
+       vmask &= ~index2;
+       switch (index2)
+       {
+       case MultibufferWindowUpdateHint:
+           updateHint = (CARD32) *vlist;
+           switch (updateHint)
+           {
+           case MultibufferUpdateHintFrequent:
+           case MultibufferUpdateHintIntermittent:
+           case MultibufferUpdateHintStatic:
+               pMultibuffers->updateHint = updateHint;
+               break;
+           default:
+               client->errorValue = updateHint;
+               return BadValue;
+           }
+           vlist++;
+           break;
+       default:
+           client->errorValue = stuff->valueMask;
+           return BadValue;
+       }
+    }
+    return Success;
+}
+
+static int
+ProcGetMBufferAttributes (client)
+    ClientPtr  client;
+{
+    REQUEST (xMbufGetMBufferAttributesReq);
+    WindowPtr  pWin;
+    MultibuffersPtr    pMultibuffers;
+    XID                *ids;
+    xMbufGetMBufferAttributesReply  rep;
+    int                i, n;
+
+    REQUEST_SIZE_MATCH (xMbufGetMBufferAttributesReq);
+    pWin = LookupWindow (stuff->window, client);
+    if (!pWin)
+       return BadWindow;
+    pMultibuffers = (MultibuffersPtr)LookupIDByType (pWin->drawable.id, MultibuffersResType);
+    if (!pMultibuffers)
+       return BadAccess;
+    ids = (XID *) ALLOCATE_LOCAL (pMultibuffers->numMultibuffer * sizeof (XID));
+    if (!ids)
+       return BadAlloc;
+    for (i = 0; i < pMultibuffers->numMultibuffer; i++)
+       ids[i] = pMultibuffers->buffers[i].pPixmap->drawable.id;
+    rep.type = X_Reply;
+    rep.sequenceNumber = client->sequence;
+    rep.length = pMultibuffers->numMultibuffer;
+    rep.displayedBuffer = pMultibuffers->displayedMultibuffer;
+    rep.updateAction = pMultibuffers->updateAction;
+    rep.updateHint = pMultibuffers->updateHint;
+    rep.windowMode = pMultibuffers->windowMode;
+    if (client->swapped)
+    {
+       swaps(&rep.sequenceNumber, n);
+       swapl(&rep.length, n);
+       swaps(&rep.displayedBuffer, n);
+       SwapLongs (ids, pMultibuffers->numMultibuffer);
+    }
+    WriteToClient (client, sizeof(xMbufGetMBufferAttributesReply),
+                  (char *)&rep);
+    WriteToClient (client, (int)(pMultibuffers->numMultibuffer * sizeof (XID)),
+                  (char *)ids);
+    DEALLOCATE_LOCAL((pointer) ids);
+    return client->noClientException;
+}
+
+static int
+ProcSetBufferAttributes (client)
+    register ClientPtr client;
+{
+    REQUEST(xMbufSetBufferAttributesReq);
+    MultibufferPtr     pMultibuffer;
+    int                len;
+    Mask       vmask, index2;
+    XID                *vlist;
+    Mask       eventMask;
+    int                result;
+
+    REQUEST_AT_LEAST_SIZE (xMbufSetBufferAttributesReq);
+    pMultibuffer = (MultibufferPtr) LookupIDByType (stuff->buffer, MultibufferResType);
+    if (!pMultibuffer)
+       return MultibufferErrorBase + MultibufferBadBuffer;
+    len = stuff->length - (sizeof (xMbufSetBufferAttributesReq) >> 2);
+    vmask = stuff->valueMask;
+    if (len != Ones (vmask))
+       return BadLength;
+    vlist = (XID *) &stuff[1];
+    while (vmask)
+    {
+       index2 = (Mask) lowbit (vmask);
+       vmask &= ~index2;
+       switch (index2)
+       {
+       case MultibufferBufferEventMask:
+           eventMask = (Mask) *vlist;
+           vlist++;
+           result = EventSelectForMultibuffer (pMultibuffer, client, eventMask);
+           if (result != Success)
+               return result;
+           break;
+       default:
+           client->errorValue = stuff->valueMask;
+           return BadValue;
+       }
+    }
+    return Success;
+}
+
+int
+ProcGetBufferAttributes (client)
+    register ClientPtr client;
+{
+    REQUEST(xMbufGetBufferAttributesReq);
+    MultibufferPtr     pMultibuffer;
+    xMbufGetBufferAttributesReply      rep;
+    OtherClientsPtr            other;
+    int                                n;
+
+    REQUEST_SIZE_MATCH (xMbufGetBufferAttributesReq);
+    pMultibuffer = (MultibufferPtr) LookupIDByType (stuff->buffer, MultibufferResType);
+    if (!pMultibuffer)
+       return MultibufferErrorBase + MultibufferBadBuffer;
+    rep.type = X_Reply;
+    rep.sequenceNumber = client->sequence;
+    rep.length = 0;
+    rep.window = pMultibuffer->pMultibuffers->pWindow->drawable.id;
+    if (bClient (pMultibuffer) == client)
+       rep.eventMask = pMultibuffer->eventMask;
+    else
+    {
+       rep.eventMask = (Mask) 0L;
+       for (other = pMultibuffer->otherClients; other; other = other->next)
+           if (SameClient (other, client))
+           {
+               rep.eventMask = other->mask;
+               break;
+           }
+    }
+    rep.bufferIndex = pMultibuffer->number;
+    rep.side = pMultibuffer->side;
+    if (client->swapped)
+    {
+       swaps(&rep.sequenceNumber, n);
+       swapl(&rep.length, n);
+       swapl(&rep.window, n);
+       swapl(&rep.eventMask, n);
+       swaps(&rep.bufferIndex, n);
+    }
+    WriteToClient(client, sizeof (xMbufGetBufferAttributesReply), (char *)&rep);
+    return (client->noClientException);
+}
+
+static int
+ProcGetBufferInfo (client)
+    register ClientPtr client;
+{
+    REQUEST (xMbufGetBufferInfoReq);
+    DrawablePtr                    pDrawable;
+    xMbufGetBufferInfoReply rep;
+    ScreenPtr              pScreen;
+    int                            i, j, k;
+    int                            n;
+    xMbufBufferInfo        *pInfo;
+    int                            nInfo;
+    DepthPtr               pDepth;
+
+    pDrawable = (DrawablePtr) LookupDrawable (stuff->drawable, client);
+    if (!pDrawable)
+       return BadDrawable;
+    pScreen = pDrawable->pScreen;
+    nInfo = 0;
+    for (i = 0; i < pScreen->numDepths; i++)
+    {
+       pDepth = &pScreen->allowedDepths[i];
+       nInfo += pDepth->numVids;
+    }
+    pInfo = (xMbufBufferInfo *)
+               ALLOCATE_LOCAL (nInfo * sizeof (xMbufBufferInfo));
+    if (!pInfo)
+       return BadAlloc;
+
+    rep.type = X_Reply;
+    rep.sequenceNumber = client->sequence;
+    rep.length = nInfo * (sizeof (xMbufBufferInfo) >> 2);
+    rep.normalInfo = nInfo;
+    rep.stereoInfo = 0;
+    if (client->swapped)
+    {
+       swaps(&rep.sequenceNumber, n);
+       swapl(&rep.length, n);
+       swaps(&rep.normalInfo, n);
+       swaps(&rep.stereoInfo, n);
+    }
+
+    k = 0;
+    for (i = 0; i < pScreen->numDepths; i++)
+    {
+       pDepth = &pScreen->allowedDepths[i];
+       for (j = 0; j < pDepth->numVids; j++)
+       {
+           pInfo[k].visualID = pDepth->vids[j];
+           pInfo[k].maxBuffers = 0;
+           pInfo[k].depth = pDepth->depth;
+           if (client->swapped)
+           {
+               swapl (&pInfo[k].visualID, n);
+               swaps (&pInfo[k].maxBuffers, n);
+           }
+           k++;
+       }
+    }
+    WriteToClient (client, sizeof (xMbufGetBufferInfoReply), (pointer) &rep);
+    WriteToClient (client, (int) nInfo * sizeof (xMbufBufferInfo), (pointer) pInfo);
+    DEALLOCATE_LOCAL ((pointer) pInfo);
+    return client->noClientException;
+}
+
+static int
+ProcClearImageBufferArea (client)
+    register ClientPtr client;
+{
+    REQUEST (xMbufClearImageBufferAreaReq);
+    MultibufferPtr     pMultibuffer;
+    WindowPtr pWin;
+    xRectangle clearRect;
+    int width, height;
+    DrawablePtr pDrawable;
+    ScreenPtr pScreen;
+
+    REQUEST_SIZE_MATCH (xMbufClearImageBufferAreaReq);
+    pMultibuffer = (MultibufferPtr) LookupIDByType (stuff->buffer, MultibufferResType);
+    if (!pMultibuffer)
+       return MultibufferErrorBase + MultibufferBadBuffer;
+    if ((stuff->exposures != xTrue) && (stuff->exposures != xFalse))
+    {
+       client->errorValue = stuff->exposures;
+        return(BadValue);
+    }
+    pWin = pMultibuffer->pMultibuffers->pWindow;
+    width  = pWin->drawable.width;
+    height = pWin->drawable.height;
+    pScreen = pWin->drawable.pScreen;
+
+    clearRect.x = stuff->x;
+    clearRect.y = stuff->y;
+    clearRect.width  = stuff->width  ? stuff->width  : width;
+    clearRect.height = stuff->height ? stuff->height : height;
+
+    if (pWin->backgroundState != None)
+    {
+       GCPtr pClearGC;
+       pClearGC = GetScratchGC (pWin->drawable.depth, pScreen);
+       SetupBackgroundPainter (pWin, pClearGC);
+
+       if (pMultibuffer->number == pMultibuffer->pMultibuffers->displayedMultibuffer)
+           pDrawable = (DrawablePtr)pWin;
+       else
+           pDrawable = (DrawablePtr)pMultibuffer->pPixmap;
+
+       ValidateGC(pDrawable, pClearGC);
+       (*pClearGC->ops->PolyFillRect) (pDrawable, pClearGC, 1, &clearRect);
+       FreeScratchGC(pClearGC);
+    }
+
+    if (stuff->exposures)
+    {
+       RegionRec region;
+       BoxRec box;
+       box.x1 = clearRect.x;
+       box.y1 = clearRect.y;
+       box.x2 = clearRect.x + clearRect.width;
+       box.y2 = clearRect.y + clearRect.height;
+       REGION_INIT(pScreen, &region, &box, 1);
+       MultibufferExpose(pMultibuffer, &region);
+       REGION_UNINIT(pScreen, &region);
+    }
+    return Success;
+}
+
+static int
+ProcMultibufferDispatch (client)
+    register ClientPtr client;
+{
+    REQUEST(xReq);
+    switch (stuff->data) {
+    case X_MbufGetBufferVersion:
+       return ProcGetBufferVersion (client);
+    case X_MbufCreateImageBuffers:
+       return ProcCreateImageBuffers (client);
+    case X_MbufDisplayImageBuffers:
+       return ProcDisplayImageBuffers (client);
+    case X_MbufDestroyImageBuffers:
+       return ProcDestroyImageBuffers (client);
+    case X_MbufSetMBufferAttributes:
+       return ProcSetMBufferAttributes (client);
+    case X_MbufGetMBufferAttributes:
+       return ProcGetMBufferAttributes (client);
+    case X_MbufSetBufferAttributes:
+       return ProcSetBufferAttributes (client);
+    case X_MbufGetBufferAttributes:
+       return ProcGetBufferAttributes (client);
+    case X_MbufGetBufferInfo:
+       return ProcGetBufferInfo (client);
+    case X_MbufClearImageBufferArea:
+       return ProcClearImageBufferArea (client);
+    default:
+       return BadRequest;
+    }
+}
+
+static int
+SProcGetBufferVersion (client)
+    register ClientPtr client;
+{
+    register int    n;
+    REQUEST (xMbufGetBufferVersionReq);
+
+    swaps (&stuff->length, n);
+    return ProcGetBufferVersion (client);
+}
+
+static int
+SProcCreateImageBuffers (client)
+    register ClientPtr client;
+{
+    register int    n;
+    REQUEST (xMbufCreateImageBuffersReq);
+
+    swaps (&stuff->length, n);
+    REQUEST_AT_LEAST_SIZE (xMbufCreateImageBuffersReq);
+    swapl (&stuff->window, n);
+    SwapRestL(stuff);
+    return ProcCreateImageBuffers (client);
+}
+
+static int
+SProcDisplayImageBuffers (client)
+    register ClientPtr client;
+{
+    register int    n;
+    REQUEST (xMbufDisplayImageBuffersReq);
+    
+    swaps (&stuff->length, n);
+    REQUEST_AT_LEAST_SIZE (xMbufDisplayImageBuffersReq);
+    swaps (&stuff->minDelay, n);
+    swaps (&stuff->maxDelay, n);
+    SwapRestL(stuff);
+    return ProcDisplayImageBuffers (client);
+}
+
+static int
+SProcDestroyImageBuffers (client)
+    register ClientPtr client;
+{
+    register int    n;
+    REQUEST (xMbufDestroyImageBuffersReq);
+    
+    swaps (&stuff->length, n);
+    REQUEST_SIZE_MATCH (xMbufDestroyImageBuffersReq);
+    swapl (&stuff->window, n);
+    return ProcDestroyImageBuffers (client);
+}
+
+static int
+SProcSetMBufferAttributes (client)
+    register ClientPtr client;
+{
+    register int    n;
+    REQUEST (xMbufSetMBufferAttributesReq);
+
+    swaps (&stuff->length, n);
+    REQUEST_AT_LEAST_SIZE(xMbufSetMBufferAttributesReq);
+    swapl (&stuff->window, n);
+    swapl (&stuff->valueMask, n);
+    SwapRestL(stuff);
+    return ProcSetMBufferAttributes (client);
+}
+
+static int
+SProcGetMBufferAttributes (client)
+    register ClientPtr client;
+{
+    register int    n;
+    REQUEST (xMbufGetMBufferAttributesReq);
+
+    swaps (&stuff->length, n);
+    REQUEST_AT_LEAST_SIZE(xMbufGetMBufferAttributesReq);
+    swapl (&stuff->window, n);
+    return ProcGetMBufferAttributes (client);
+}
+
+static int
+SProcSetBufferAttributes (client)
+    register ClientPtr client;
+{
+    register int    n;
+    REQUEST (xMbufSetBufferAttributesReq);
+
+    swaps (&stuff->length, n);
+    REQUEST_AT_LEAST_SIZE(xMbufSetBufferAttributesReq);
+    swapl (&stuff->buffer, n);
+    swapl (&stuff->valueMask, n);
+    SwapRestL(stuff);
+    return ProcSetBufferAttributes (client);
+}
+
+static int
+SProcGetBufferAttributes (client)
+    register ClientPtr client;
+{
+    register int    n;
+    REQUEST (xMbufGetBufferAttributesReq);
+
+    swaps (&stuff->length, n);
+    REQUEST_AT_LEAST_SIZE(xMbufGetBufferAttributesReq);
+    swapl (&stuff->buffer, n);
+    return ProcGetBufferAttributes (client);
+}
+
+static int
+SProcGetBufferInfo (client)
+    register ClientPtr client;
+{
+    register int    n;
+    REQUEST (xMbufGetBufferInfoReq);
+
+    swaps (&stuff->length, n);
+    REQUEST_SIZE_MATCH (xMbufGetBufferInfoReq);
+    swapl (&stuff->drawable, n);
+    return ProcGetBufferInfo (client);
+}
+
+static int
+SProcClearImageBufferArea(client)
+    register ClientPtr client;
+{
+    register char n;
+    REQUEST(xMbufClearImageBufferAreaReq);
+
+    swaps(&stuff->length, n);
+    REQUEST_SIZE_MATCH (xMbufClearImageBufferAreaReq);
+    swapl(&stuff->buffer, n);
+    swaps(&stuff->x, n);
+    swaps(&stuff->y, n);
+    swaps(&stuff->width, n);
+    swaps(&stuff->height, n);
+    return ProcClearImageBufferArea(client);
+}
+
+static int
+SProcMultibufferDispatch (client)
+    register ClientPtr client;
+{
+    REQUEST(xReq);
+    switch (stuff->data) {
+    case X_MbufGetBufferVersion:
+       return SProcGetBufferVersion (client);
+    case X_MbufCreateImageBuffers:
+       return SProcCreateImageBuffers (client);
+    case X_MbufDisplayImageBuffers:
+       return SProcDisplayImageBuffers (client);
+    case X_MbufDestroyImageBuffers:
+       return SProcDestroyImageBuffers (client);
+    case X_MbufSetMBufferAttributes:
+       return SProcSetMBufferAttributes (client);
+    case X_MbufGetMBufferAttributes:
+       return SProcGetMBufferAttributes (client);
+    case X_MbufSetBufferAttributes:
+       return SProcSetBufferAttributes (client);
+    case X_MbufGetBufferAttributes:
+       return SProcGetBufferAttributes (client);
+    case X_MbufGetBufferInfo:
+       return SProcGetBufferInfo (client);
+    case X_MbufClearImageBufferArea:
+       return SProcClearImageBufferArea (client);
+    default:
+       return BadRequest;
+    }
+}
+
+static void
+SUpdateNotifyEvent (from, to)
+    xMbufUpdateNotifyEvent     *from, *to;
+{
+    to->type = from->type;
+    cpswaps (from->sequenceNumber, to->sequenceNumber);
+    cpswapl (from->buffer, to->buffer);
+    cpswapl (from->timeStamp, to->timeStamp);
+}
+
+static void
+SClobberNotifyEvent (from, to)
+    xMbufClobberNotifyEvent    *from, *to;
+{
+    to->type = from->type;
+    cpswaps (from->sequenceNumber, to->sequenceNumber);
+    cpswapl (from->buffer, to->buffer);
+    to->state = from->state;
+}
+
+static void
+PerformDisplayRequest (ppMultibuffers, pMultibuffer, nbuf)
+    MultibufferPtr         *pMultibuffer;
+    MultibuffersPtr        *ppMultibuffers;
+    int                    nbuf;
+{
+    GCPtr          pGC;
+    PixmapPtr      pPrevPixmap, pNewPixmap;
+    xRectangle     clearRect;
+    WindowPtr      pWin;
+    RegionPtr      pExposed;
+    int                    i;
+    MultibufferPtr  pPrevMultibuffer;
+    XID                    graphicsExpose;
+
+    UpdateCurrentTime ();
+    for (i = 0; i < nbuf; i++)
+    {
+       pWin = ppMultibuffers[i]->pWindow;
+       pGC = GetScratchGC (pWin->drawable.depth, pWin->drawable.pScreen);
+       pPrevMultibuffer =
+          &ppMultibuffers[i]->buffers[ppMultibuffers[i]->displayedMultibuffer];
+       pPrevPixmap = pPrevMultibuffer->pPixmap;
+       pNewPixmap = pMultibuffer[i]->pPixmap;
+       switch (ppMultibuffers[i]->updateAction)
+       {
+       case MultibufferUpdateActionUndefined:
+           break;
+       case MultibufferUpdateActionBackground:
+           SetupBackgroundPainter (pWin, pGC);
+           ValidateGC ((DrawablePtr)pPrevPixmap, pGC);
+           clearRect.x = 0;
+           clearRect.y = 0;
+           clearRect.width = pPrevPixmap->drawable.width;
+           clearRect.height = pPrevPixmap->drawable.height;
+           (*pGC->ops->PolyFillRect) ((DrawablePtr)pPrevPixmap, pGC,
+                                      1, &clearRect);
+           break;
+       case MultibufferUpdateActionUntouched:
+           /* copy the window to the pixmap that represents the
+            * currently displayed buffer
+            */
+           if (pPrevMultibuffer->eventMask & ExposureMask)
+           {
+               graphicsExpose = TRUE;
+               DoChangeGC (pGC, GCGraphicsExposures, &graphicsExpose, FALSE);
+           }
+           ValidateGC ((DrawablePtr)pPrevPixmap, pGC);
+           pExposed = (*pGC->ops->CopyArea)
+                           ((DrawablePtr) pWin,
+                            (DrawablePtr) pPrevPixmap,
+                            pGC,
+                            0, 0,
+                            pWin->drawable.width, pWin->drawable.height,
+                            0, 0);
+
+           /* if we couldn't copy the whole window to the buffer,
+            * send expose events (if any client wants them)
+            */
+           if (pPrevMultibuffer->eventMask & ExposureMask)
+           { /* some client wants expose events */
+               if (pExposed)
+               {
+                   RegionPtr   pWinSize;
+                   ScreenPtr pScreen = pWin->drawable.pScreen;
+
+                   pWinSize = CreateUnclippedWinSize (pWin);
+                   /* pExposed is window-relative, but at this point
+                    * pWinSize is screen-relative.  Make pWinSize be
+                    * window-relative so that region ops involving
+                    * pExposed and pWinSize behave sensibly.
+                    */
+                   REGION_TRANSLATE(pScreen, pWinSize,
+                                    -pWin->drawable.x,
+                                    -pWin->drawable.y);
+                   REGION_INTERSECT(pScreen, pExposed, pExposed, pWinSize);
+                   REGION_DESTROY(pScreen, pWinSize);
+                   MultibufferExpose (pPrevMultibuffer, pExposed);
+                   REGION_DESTROY(pScreen, pExposed);
+               }
+               graphicsExpose = FALSE;
+               DoChangeGC (pGC, GCGraphicsExposures, &graphicsExpose, FALSE);
+           }
+           break; /* end case MultibufferUpdateActionUntouched */
+
+       case MultibufferUpdateActionCopied:
+           ValidateGC ((DrawablePtr)pPrevPixmap, pGC);
+           (*pGC->ops->CopyArea) ((DrawablePtr)pNewPixmap,
+                                  (DrawablePtr)pPrevPixmap, pGC,
+                                  0, 0,
+                                  pWin->drawable.width, pWin->drawable.height,
+                                  0, 0);
+           break;
+       } /* end switch on update action */
+
+       /* display the new buffer */
+       ValidateGC ((DrawablePtr)pWin, pGC);
+       (*pGC->ops->CopyArea) ((DrawablePtr)pNewPixmap, (DrawablePtr)pWin, pGC,
+                              0, 0,
+                              pWin->drawable.width, pWin->drawable.height,
+                              0, 0);
+       ppMultibuffers[i]->lastUpdate = currentTime;
+       MultibufferUpdate (pMultibuffer[i],
+                          ppMultibuffers[i]->lastUpdate.milliseconds);
+       AliasMultibuffer (ppMultibuffers[i],
+                         pMultibuffer[i] - ppMultibuffers[i]->buffers);
+       FreeScratchGC (pGC);
+    }
+}
+
+DrawablePtr
+GetBufferPointer (pWin, i)
+    WindowPtr  pWin;
+    int                i;
+{
+    MultibuffersPtr pMultibuffers;
+
+    if (!(pMultibuffers = (MultibuffersPtr) pWin->devPrivates[MultibufferWindowIndex].ptr))
+       return NULL;
+    return (DrawablePtr) pMultibuffers->buffers[i].pPixmap;
+}
+
+int
+DisplayImageBuffers (ids, nbuf)
+    XID            *ids;
+    int            nbuf;
+{
+    MultibufferPtr  *pMultibuffer;
+    MultibuffersPtr *pMultibuffers;
+    int                    i, j;
+
+    pMultibuffer = (MultibufferPtr *) ALLOCATE_LOCAL (nbuf * sizeof *pMultibuffer +
+                                  nbuf * sizeof *pMultibuffers);
+    if (!pMultibuffer)
+       return BadAlloc;
+    pMultibuffers = (MultibuffersPtr *) (pMultibuffer + nbuf);
+    for (i = 0; i < nbuf; i++)
+    {
+       pMultibuffer[i] = (MultibufferPtr) LookupIDByType (ids[i], MultibufferResType);
+       if (!pMultibuffer[i])
+       {
+           DEALLOCATE_LOCAL (pMultibuffer);
+           return MultibufferErrorBase + MultibufferBadBuffer;
+       }
+       pMultibuffers[i] = pMultibuffer[i]->pMultibuffers;
+       for (j = 0; j < i; j++)
+           if (pMultibuffers[i] == pMultibuffers[j])
+           {
+               DEALLOCATE_LOCAL (pMultibuffer);
+               return BadMatch;
+           }
+    }
+    PerformDisplayRequest (pMultibuffers, pMultibuffer, nbuf);
+    DEALLOCATE_LOCAL (pMultibuffer);
+    return Success;
+}
+
+
+static Bool
+QueueDisplayRequest (client, activateTime)
+    ClientPtr      client;
+    TimeStamp      activateTime;
+{
+    /* see xtest.c:ProcXTestFakeInput for code similar to this */
+
+    if (!ClientSleepUntil(client, &activateTime, NULL, NULL))
+    {
+       return FALSE;
+    }
+    /* swap the request back so we can simply re-execute it */
+    if (client->swapped)
+    {
+       register int    n;
+       REQUEST (xMbufDisplayImageBuffersReq);
+       
+       SwapRestL(stuff);
+       swaps (&stuff->length, n);
+       swaps (&stuff->minDelay, n);
+       swaps (&stuff->maxDelay, n);
+    }
+    ResetCurrentRequest (client);
+    client->sequence--;
+    return TRUE;
+}
+
+
+/*
+ * Deliver events to a buffer
+ */
+
+static int
+DeliverEventsToMultibuffer (pMultibuffer, pEvents, count, filter)
+    MultibufferPtr     pMultibuffer;
+    xEvent     *pEvents;
+    int                count;
+    Mask       filter;
+{
+    int deliveries = 0, nondeliveries = 0;
+    int attempt;
+    OtherClients *other;
+
+    /* if nobody wants the event, we're done */
+    if (!((pMultibuffer->otherEventMask|pMultibuffer->eventMask) & filter))
+       return 0;
+
+    /* maybe send event to owner */
+    if ((attempt = TryClientEvents(
+       bClient(pMultibuffer), pEvents, count, pMultibuffer->eventMask, filter, (GrabPtr) 0)) != 0)
+    {
+       if (attempt > 0)
+           deliveries++;
+       else
+           nondeliveries--;
+    }
+
+    /* maybe send event to other clients */
+    for (other = pMultibuffer->otherClients; other; other=other->next)
+    {
+       if ((attempt = TryClientEvents(
+             rClient(other), pEvents, count, other->mask, filter, (GrabPtr) 0)) != 0)
+       {
+           if (attempt > 0)
+               deliveries++;
+           else
+               nondeliveries--;
+       }
+    }
+    if (deliveries)
+       return deliveries;
+    return nondeliveries;
+}
+
+/*
+ * Send Expose events to interested clients
+ */
+
+void
+MultibufferExpose (pMultibuffer, pRegion)
+    MultibufferPtr     pMultibuffer;
+    RegionPtr  pRegion;
+{
+    if (pRegion && !REGION_NIL(pRegion))
+    {
+       xEvent *pEvent;
+       PixmapPtr   pPixmap;
+       register xEvent *pe;
+       register BoxPtr pBox;
+       register int i;
+       int numRects;
+
+       pPixmap = pMultibuffer->pPixmap;
+       REGION_TRANSLATE(pPixmap->drawable.pScreen, pRegion,
+                   -pPixmap->drawable.x, -pPixmap->drawable.y);
+       /* XXX MultibufferExpose "knows" the region representation */
+       numRects = REGION_NUM_RECTS(pRegion);
+       pBox = REGION_RECTS(pRegion);
+
+       pEvent = (xEvent *) ALLOCATE_LOCAL(numRects * sizeof(xEvent));
+       if (pEvent) {
+           pe = pEvent;
+
+           for (i=1; i<=numRects; i++, pe++, pBox++)
+           {
+               pe->u.u.type = Expose;
+               pe->u.expose.window = pPixmap->drawable.id;
+               pe->u.expose.x = pBox->x1;
+               pe->u.expose.y = pBox->y1;
+               pe->u.expose.width = pBox->x2 - pBox->x1;
+               pe->u.expose.height = pBox->y2 - pBox->y1;
+               pe->u.expose.count = (numRects - i);
+           }
+           (void) DeliverEventsToMultibuffer (pMultibuffer, pEvent, numRects,
+                                              ExposureMask);
+           DEALLOCATE_LOCAL(pEvent);
+       }
+    }
+}
+
+/* send UpdateNotify event */
+void
+MultibufferUpdate (pMultibuffer, time2)
+    MultibufferPtr     pMultibuffer;
+    CARD32     time2;
+{
+    xMbufUpdateNotifyEvent     event;
+
+    event.type = MultibufferEventBase + MultibufferUpdateNotify;
+    event.buffer = pMultibuffer->pPixmap->drawable.id;
+    event.timeStamp = time2;
+    (void) DeliverEventsToMultibuffer (pMultibuffer, (xEvent *)&event,
+                               1, (Mask)MultibufferUpdateNotifyMask);
+}
+
+/*
+ * The sample implementation will never generate MultibufferClobberNotify
+ * events
+ */
+
+void
+MultibufferClobber (pMultibuffer)
+    MultibufferPtr     pMultibuffer;
+{
+    xMbufClobberNotifyEvent    event;
+
+    event.type = MultibufferEventBase + MultibufferClobberNotify;
+    event.buffer = pMultibuffer->pPixmap->drawable.id;
+    event.state = pMultibuffer->clobber;
+    (void) DeliverEventsToMultibuffer (pMultibuffer, (xEvent *)&event,
+                               1, (Mask)MultibufferClobberNotifyMask);
+}
+
+/*
+ * make the resource id for buffer i refer to the window
+ * drawable instead of the pixmap;
+ */
+
+static void
+AliasMultibuffer (pMultibuffers, i)
+    MultibuffersPtr    pMultibuffers;
+    int                i;
+{
+    MultibufferPtr     pMultibuffer;
+
+    if (i == pMultibuffers->displayedMultibuffer)
+       return;
+    /*
+     * remove the old association
+     */
+    if (pMultibuffers->displayedMultibuffer >= 0)
+    {
+       pMultibuffer = &pMultibuffers->buffers[pMultibuffers->displayedMultibuffer];
+       ChangeResourceValue (pMultibuffer->pPixmap->drawable.id,
+                            MultibufferDrawableResType,
+                            (pointer) pMultibuffer->pPixmap);
+    }
+    /*
+     * make the new association
+     */
+    pMultibuffer = &pMultibuffers->buffers[i];
+    ChangeResourceValue (pMultibuffer->pPixmap->drawable.id,
+                        MultibufferDrawableResType,
+                        (pointer) pMultibuffers->pWindow);
+    pMultibuffers->displayedMultibuffer = i;
+}
+
+/*
+ * free everything associated with multibuffering for this
+ * window
+ */
+
+void
+DestroyImageBuffers (pWin)
+    WindowPtr  pWin;
+{
+    FreeResourceByType (pWin->drawable.id, MultibuffersResType, FALSE);
+    /* Zero out the window's pointer to the buffers so they won't be reused */
+    pWin->devPrivates[MultibufferWindowIndex].ptr = NULL;
+}
+
+/*
+ * resize the buffers when the window is resized
+ */ 
+
+static Bool
+MultibufferPositionWindow (pWin, x, y)
+    WindowPtr  pWin;
+    int                x, y;
+{
+    ScreenPtr      pScreen;
+    MultibufferScreenPtr pMultibufferScreen;
+    MultibuffersPtr        pMultibuffers;
+    MultibufferPtr         pMultibuffer;
+    int                    width, height;
+    int                    i;
+    int                    dx, dy, dw, dh;
+    int                    sourcex, sourcey;
+    int                    destx, desty;
+    PixmapPtr      pPixmap;
+    GCPtr          pGC;
+    int                    savewidth, saveheight;
+    xRectangle     clearRect;
+    Bool           clear;
+
+    pScreen = pWin->drawable.pScreen;
+    pMultibufferScreen = (MultibufferScreenPtr) pScreen->devPrivates[MultibufferScreenIndex].ptr;
+    (*pMultibufferScreen->PositionWindow) (pWin, x, y);
+
+    /* if this window is not multibuffered, we're done */
+    if (!(pMultibuffers = (MultibuffersPtr) pWin->devPrivates[MultibufferWindowIndex].ptr))
+       return TRUE;
+
+    /* if new size is same as old, we're done */
+    if (pMultibuffers->width == pWin->drawable.width &&
+        pMultibuffers->height == pWin->drawable.height)
+       return TRUE;
+
+    width = pWin->drawable.width;
+    height = pWin->drawable.height;
+    dx = pWin->drawable.x - pMultibuffers->x;
+    dy = pWin->drawable.x - pMultibuffers->y;
+    dw = width - pMultibuffers->width;
+    dh = height - pMultibuffers->height;
+    GravityTranslate (0, 0, -dx, -dy, dw, dh,
+                     pWin->bitGravity, &destx, &desty);
+
+    /* if the window grew, remember to paint the window background,
+     * and maybe send expose events, for the new areas of the buffers
+     */
+    clear = pMultibuffers->width < width || pMultibuffers->height < height ||
+               pWin->bitGravity == ForgetGravity;
+
+    sourcex = 0;
+    sourcey = 0;
+    savewidth = pMultibuffers->width;
+    saveheight = pMultibuffers->height;
+    /* clip rectangle to source and destination */
+    if (destx < 0)
+    {
+       savewidth += destx;
+       sourcex -= destx;
+       destx = 0;
+    }
+    if (destx + savewidth > width)
+       savewidth = width - destx;
+    if (desty < 0)
+    {
+       saveheight += desty;
+       sourcey -= desty;
+       desty = 0;
+    }
+    if (desty + saveheight > height)
+       saveheight = height - desty;
+
+    pMultibuffers->width = width;
+    pMultibuffers->height = height;
+    pMultibuffers->x = pWin->drawable.x;
+    pMultibuffers->y = pWin->drawable.y;
+
+    pGC = GetScratchGC (pWin->drawable.depth, pScreen);
+    if (clear)
+    {
+       SetupBackgroundPainter (pWin, pGC);
+       clearRect.x = 0;
+       clearRect.y = 0;
+       clearRect.width = width;
+       clearRect.height = height;
+    }
+    for (i = 0; i < pMultibuffers->numMultibuffer; i++)
+    {
+       pMultibuffer = &pMultibuffers->buffers[i];
+       pPixmap = (*pScreen->CreatePixmap) (pScreen, width, height,
+                                           pWin->drawable.depth);
+       if (!pPixmap)
+       {
+           DestroyImageBuffers (pWin);
+           break;
+       }
+       ValidateGC ((DrawablePtr)pPixmap, pGC);
+       /*
+        * I suppose this could avoid quite a bit of work if
+        * it computed the minimal area required.
+        */
+       if (clear)
+           (*pGC->ops->PolyFillRect) ((DrawablePtr)pPixmap, pGC, 1, &clearRect);
+       if (pWin->bitGravity != ForgetGravity)
+       {
+           (*pGC->ops->CopyArea) ((DrawablePtr)pMultibuffer->pPixmap,
+                                  (DrawablePtr)pPixmap, pGC,
+                                   sourcex, sourcey, savewidth, saveheight,
+                                   destx, desty);
+       }
+       pPixmap->drawable.id = pMultibuffer->pPixmap->drawable.id;
+       (*pScreen->DestroyPixmap) (pMultibuffer->pPixmap);
+       pMultibuffer->pPixmap = pPixmap;
+       if (i != pMultibuffers->displayedMultibuffer)
+       {
+           ChangeResourceValue (pPixmap->drawable.id,
+                                MultibufferDrawableResType,
+                                (pointer) pPixmap);
+       }
+    }
+    FreeScratchGC (pGC);
+    return TRUE;
+}
+
+/* Resource delete func for MultibufferDrawableResType */
+/*ARGSUSED*/
+static int
+MultibufferDrawableDelete (value, id)
+    pointer    value;
+    XID                id;
+{
+    DrawablePtr        pDrawable = (DrawablePtr)value;
+    WindowPtr  pWin;
+    MultibuffersPtr    pMultibuffers;
+    PixmapPtr  pPixmap;
+
+    if (pDrawable->type == DRAWABLE_WINDOW)
+    {
+       pWin = (WindowPtr) pDrawable;
+       pMultibuffers = (MultibuffersPtr) pWin->devPrivates[MultibufferWindowIndex].ptr;
+       pPixmap = pMultibuffers->buffers[pMultibuffers->displayedMultibuffer].pPixmap;
+    }
+    else
+    {
+       pPixmap = (PixmapPtr) pDrawable;
+    }
+    (*pPixmap->drawable.pScreen->DestroyPixmap) (pPixmap);
+    return Success;
+}
+
+/* Resource delete func for MultibufferResType */
+/*ARGSUSED*/
+static int
+MultibufferDelete (value, id)
+    pointer    value;
+    XID                id;
+{
+    MultibufferPtr     pMultibuffer = (MultibufferPtr)value;
+    MultibuffersPtr    pMultibuffers;
+
+    pMultibuffers = pMultibuffer->pMultibuffers;
+    if (--pMultibuffers->refcnt == 0)
+    {
+       FreeResourceByType (pMultibuffers->pWindow->drawable.id,
+                           MultibuffersResType, TRUE);
+       xfree (pMultibuffers);
+    }
+    return Success;
+}
+
+/* Resource delete func for MultibuffersResType */
+/*ARGSUSED*/
+static int
+MultibuffersDelete (value, id)
+    pointer    value;
+    XID                id;
+{
+    MultibuffersPtr    pMultibuffers = (MultibuffersPtr)value;
+    int        i;
+
+    if (pMultibuffers->refcnt == pMultibuffers->numMultibuffer)
+    {
+       for (i = pMultibuffers->numMultibuffer; --i >= 0; )
+           FreeResource (pMultibuffers->buffers[i].pPixmap->drawable.id, 0);
+    }
+    return Success;
+}
+
+/* Resource delete func for OtherClientResType */
+static int
+OtherClientDelete (value, id)
+    pointer    value;
+    XID                id;
+{
+    MultibufferPtr     pMultibuffer = (MultibufferPtr)value;
+    register OtherClientsPtr   other, prev;
+
+    prev = 0;
+    for (other = pMultibuffer->otherClients; other; other = other->next)
+    {
+       if (other->resource == id)
+       {
+           if (prev)
+               prev->next = other->next;
+           else
+               pMultibuffer->otherClients = other->next;
+           xfree (other);
+           RecalculateMultibufferOtherEvents (pMultibuffer);
+           break;
+       }
+       prev = other;
+    }
+    return Success;
+}
+
+static int
+EventSelectForMultibuffer (pMultibuffer, client, mask)
+    MultibufferPtr     pMultibuffer;
+    ClientPtr  client;
+    Mask       mask;
+{
+    OtherClientsPtr    other;
+
+    if (mask & ~ValidEventMasks)
+    {
+       client->errorValue = mask;
+       return BadValue;
+    }
+    if (bClient (pMultibuffer) == client)
+    {
+       pMultibuffer->eventMask = mask;
+    }
+    else /* some other client besides the creator wants events */
+    {
+       for (other = pMultibuffer->otherClients; other; other = other->next)
+       {
+           if (SameClient (other, client))
+           {
+               if (mask == 0)
+               {
+                   FreeResource (other->resource, RT_NONE);
+                   break;
+               }
+               other->mask = mask;
+               break;
+           }
+       }
+       if (!other)
+       { /* new client that never selected events on this buffer before */
+           other = (OtherClients *) xalloc (sizeof (OtherClients));
+           if (!other)
+               return BadAlloc;
+           other->mask = mask;
+           other->resource = FakeClientID (client->index);
+           if (!AddResource (other->resource, OtherClientResType, (pointer) pMultibuffer))
+           {
+               xfree (other);
+               return BadAlloc;
+           }
+           other->next = pMultibuffer->otherClients;
+           pMultibuffer->otherClients = other;
+       }
+       RecalculateMultibufferOtherEvents (pMultibuffer);
+    }
+    return (client->noClientException);
+}
+
+/* or together all the otherClients event masks */
+static void
+RecalculateMultibufferOtherEvents (pMultibuffer)
+    MultibufferPtr     pMultibuffer;
+{
+    Mask           otherEventMask;
+    OtherClients    *other;
+
+    otherEventMask = 0L;
+    for (other = pMultibuffer->otherClients; other; other = other->next)
+       otherEventMask |= other->mask;
+    pMultibuffer->otherEventMask = otherEventMask;
+}
+
+/* add milliseconds to a timestamp, handling overflow */
+static void
+BumpTimeStamp (ts, inc)
+TimeStamp   *ts;
+CARD32     inc;
+{
+    CARD32  newms;
+
+    newms = ts->milliseconds + inc;
+    if (newms < ts->milliseconds)
+       ts->months++;
+    ts->milliseconds = newms;
+}
diff --git a/Xserver/programs/Xserver/Xext/mbufbf.c b/Xserver/programs/Xserver/Xext/mbufbf.c
new file mode 100644 (file)
index 0000000..e0a32f4
--- /dev/null
@@ -0,0 +1,1056 @@
+/*
+
+Copyright (c) 1989  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+*/
+
+/* $XConsortium: mbufbf.c,v 1.5 94/04/17 20:32:53 dpw Exp $ */
+/* $XFree86: xc/programs/Xserver/Xext/mbufbf.c,v 3.0 1994/05/08 05:17:30 dawes Exp $ */
+
+#define NEED_REPLIES
+#define NEED_EVENTS
+#include <stdio.h>
+#include "X.h"
+#include "Xproto.h"
+#include "misc.h"
+#include "os.h"
+#include "windowstr.h"
+#include "scrnintstr.h"
+#include "pixmapstr.h"
+#include "extnsionst.h"
+#include "dixstruct.h"
+#include "resource.h"
+#include "opaque.h"
+#include "regionstr.h"
+#include "gcstruct.h"
+#include "inputstr.h"
+#include "validate.h"
+#ifndef MINIX
+#include <sys/time.h>
+#endif
+
+#define _MULTIBUF_SERVER_      /* don't want Xlib structures */
+#define _MULTIBUF_BUFFER_
+#include "multibufst.h"
+
+/* 
+Support for doublebuffer hardare
+
+This code is designed to support doublebuffer hardware where the
+displayed buffer is selected on a per-pixel basis by an additional bit
+plane, called the select plane. It could probably be easily modified
+to work with systems that use window-id planes.
+
+This is done by creating a new drawable type, DRAWABLE_BUFFER. The
+type has the same exact layout as a window drawable. Your code should
+treat a DRAWABLE_BUFFER the same as it would tread a DRAWABLE_WINDOW
+when handling the gc drawing functions. In addition, PaintWindowBackground,
+CopyWindow, and all of the gc drawing functions to be able to draw into both
+framebuffers. Which framebuffer to draw into is selected by the contents of
+       pWin->devPrivates[frameWindowPrivateIndex].
+The content of the devPrivate is either from frameBuffer[0] or
+frameBuffer[1], depending on which buffer is being drawn into. When
+       pWin->devPrivates[frameWindowPrivateIndex] == frameBuffer[0],
+the functions should draw into the front framebuffer. When
+       pWin->devPrivates[frameWindowPrivateIndex] == frameBuffer[1],
+the functions should draw into the back framebuffer.
+
+In addition, you need to provide a function that allows you to copy
+bits between the buffers (optional since CopyArea can be used) and a
+function that draws into the select plane. Then, you need to register
+your functions and other information, by calling:
+
+void
+RegisterDoubleBufferHardware(pScreen, nInfo, pInfo, frameBuffer, selectPlane,
+                            CopyBufferBitsFunc, DrawSelectPlaneFunc)
+    int                        nInfo;
+    xMbufBufferInfo    *pInfo;
+    DevUnion           *frameBuffer;
+    DevUnion           selectPlane;
+
+"pInfo" is an array indicating which visuals and depths that double
+buffering is supported on. "nInfo" is the length of the array.
+
+"frameBuffer" is array of length 2. The contents of the array element
+is ddx-specific. The content of frameBuffer[0] should, when placed in
+the window private, indicate that framebuffer 0 should be drawn into.
+The contents of frameBuffer[1], when placed into the window private,
+should indicate that framebuffer 1 should be drawn into.
+
+"selectPlane" is ddx-specific. It should contain information
+neccessary for your displayProc to access the select plane.
+It is passed to DrawSelectPlaneFunc.
+
+"CopyBufferBitsFunc" is a ddx-specific function that copies from one
+buffer of a multibuffered window to another buffer. If the CopyBufferBitsFunc
+is NULL, a default function will be used that calls pScreen->CopyArea.
+
+    void CopyBufferBitsFunc(pMBWindow, srcBufferNum, dstBufferNum)
+        mbufWindowPtr pMBWindow;
+        int srcBufferNum, dstBufferNum;
+
+"DrawSelectPlaneFunc" is a ddx-specific function that fills the
+regions "prgn" of select plane with the value "bufferNum". If 
+selectPlane is a DrawablePtr (such as a PixmapPtr), you can pass
+NULL for DrawSelectPlaneFunc, a default function will be used that
+calls FillRectangle on the selectPlane.
+
+    void DrawSelectPlaneFunc(pScreen, selectPlane, prgn, bufferNum)
+        ScreenPtr      pScreen;
+        DevUnion       selectPlane;
+        RegionPtr      prgn;
+        long           bufferNum;
+
+...
+...
+...
+
+*/
+
+#define MAX_BUFFERS  2 /* Only supports 2 buffers */
+#define FRONT_BUFFER 0
+#define BACK_BUFFER  1
+
+
+/* Buffer drawables have the same structure as window drawables */
+typedef WindowRec BufferRec;
+typedef WindowPtr BufferPtr;
+
+
+/*
+ * Call RegisterHdwrBuffer for every screen that has doublebuffer hardware. 
+ */
+
+static int             bufNumInfo[MAXSCREENS];
+static xMbufBufferInfo *bufInfo[MAXSCREENS];
+static DevUnion                *bufFrameBuffer[MAXSCREENS];
+static DevUnion                bufselectPlane[MAXSCREENS];
+static void            (* bufCopyBufferBitsFunc[MAXSCREENS])();
+static void            (* bufDrawSelectPlaneFunc[MAXSCREENS])();
+
+static Bool bufMultibufferInit();
+
+
+void
+RegisterDoubleBufferHardware(pScreen, nInfo, pInfo, frameBuffer, selectPlane,
+                            CopyBufferBitsFunc, DrawSelectPlaneFunc)
+    ScreenPtr          pScreen;
+    int                        nInfo;
+    xMbufBufferInfo    *pInfo;
+    DevUnion           *frameBuffer;
+    DevUnion           selectPlane;
+    void               (* CopyBufferBitsFunc)();
+    void               (* DrawSelectPlaneFunc)();
+{
+    bufNumInfo[pScreen->myNum]     = nInfo;
+    bufInfo[pScreen->myNum]        = pInfo;
+    bufFrameBuffer[pScreen->myNum] = frameBuffer;
+    bufselectPlane[pScreen->myNum] = selectPlane;
+
+    bufCopyBufferBitsFunc[pScreen->myNum]  = CopyBufferBitsFunc;
+    bufDrawSelectPlaneFunc[pScreen->myNum] = DrawSelectPlaneFunc;
+
+    /* Register ourselves with device-independent multibuffers code */
+    RegisterMultibufferInit(pScreen, bufMultibufferInit);
+}
+
+
+/*
+ * Called by Multibuffer extension initialization.
+ * Initializes mbufScreenRec and its devPrivate.
+ */
+    
+static Bool NoopDDA_True() { return TRUE; }
+static Bool bufPositionWindow();
+static int  bufCreateImageBuffers();
+static void bufDestroyImageBuffers();
+static void bufDisplayImageBuffers();
+static void bufClearImageBufferArea();
+static void bufDestroyBuffer();
+static void bufCopyBufferBits();
+static void bufDrawSelectPlane();
+static void bufWrapScreenFuncs();
+static void bufResetProc();
+
+static void bufPostValidateTree();
+static void bufClipNotify();
+static void bufWindowExposures();
+static Bool bufChangeWindowAttributes();
+static void bufClearToBackground();
+static void bufCopyWindow();
+
+extern WindowPtr *WindowTable;
+
+static Bool
+bufMultibufferInit(pScreen, pMBScreen)
+    ScreenPtr pScreen;
+    mbufScreenPtr pMBScreen;
+{
+    mbufBufferPrivPtr  pMBPriv;
+    BoxRec             box;
+
+    /* Multibuffer info */
+    pMBScreen->nInfo = bufNumInfo[pScreen->myNum];
+    pMBScreen->pInfo = bufInfo[pScreen->myNum];
+
+    /* Hooks */
+    pMBScreen->CreateImageBuffers = bufCreateImageBuffers;
+    pMBScreen->DestroyImageBuffers = bufDestroyImageBuffers;
+    pMBScreen->DisplayImageBuffers = bufDisplayImageBuffers;
+    pMBScreen->ClearImageBufferArea = bufClearImageBufferArea;
+    pMBScreen->ChangeMBufferAttributes = NoopDDA_True;
+    pMBScreen->ChangeBufferAttributes = NoopDDA_True;
+    pMBScreen->DeleteBufferDrawable = bufDestroyBuffer;
+    pMBScreen->WrapScreenFuncs = bufWrapScreenFuncs;
+    pMBScreen->ResetProc = bufResetProc;
+    /* Create devPrivate part */
+    pMBPriv = (mbufBufferPrivPtr) xalloc(sizeof *pMBPriv);
+    if (!pMBPriv)
+       return (FALSE);
+
+    pMBScreen->devPrivate.ptr = (pointer) pMBPriv;
+    pMBPriv->frameBuffer  = bufFrameBuffer[pScreen->myNum];
+    pMBPriv->selectPlane = bufselectPlane[pScreen->myNum];
+
+    /*
+     * Initializing the subtractRgn to the screen area will ensure that
+     * the selectPlane will get cleared on the first PostValidateTree.
+     */
+
+    box.x1 = 0;
+    box.y1 = 0;
+    box.x2 = pScreen->width;
+    box.y2 = pScreen->height;
+
+    pMBPriv->rgnChanged = TRUE;
+    REGION_INIT(pScreen, &pMBPriv->backBuffer, &box, 1);
+    REGION_INIT(pScreen, &pMBPriv->subtractRgn, &box, 1);
+    REGION_INIT(pScreen, &pMBPriv->unionRgn, NullBox, 0);
+
+    /* Misc functions */
+    pMBPriv->CopyBufferBits  = bufCopyBufferBitsFunc[pScreen->myNum];
+    pMBPriv->DrawSelectPlane = bufDrawSelectPlaneFunc[pScreen->myNum];
+
+    if (!pMBPriv->CopyBufferBits)
+       pMBPriv->CopyBufferBits = bufCopyBufferBits;
+
+    if (!pMBPriv->DrawSelectPlane)
+       pMBPriv->DrawSelectPlane = bufDrawSelectPlane;
+
+    /* screen functions */
+    pMBPriv->funcsWrapped = 0;
+    pMBPriv->inClearToBackground = FALSE;
+    pMBPriv->WindowExposures = NULL;
+    pMBPriv->CopyWindow = NULL;
+    pMBPriv->ClearToBackground = NULL;
+    pMBPriv->ClipNotify = NULL;
+    pMBPriv->ChangeWindowAttributes = NULL;
+
+    /* Start out wrapped to clear select plane */
+    WRAP_SCREEN_FUNC(pScreen,pMBPriv,PostValidateTree, bufPostValidateTree);
+    return TRUE;
+}
+
+static void
+UpdateBufferFromWindow(pBuffer, pWin)
+    BufferPtr  pBuffer;
+    WindowPtr  pWin;
+{
+    pBuffer->drawable.x      = pWin->drawable.x;
+    pBuffer->drawable.y      = pWin->drawable.y;
+    pBuffer->drawable.width  = pWin->drawable.width;
+    pBuffer->drawable.height = pWin->drawable.height;
+
+    pBuffer->drawable.serialNumber = NEXT_SERIAL_NUMBER;
+
+    /* Update for PaintWindowBackground */
+    pBuffer->parent = pWin->parent;
+
+    /*
+     * Make the borderClip the same as the clipList so
+     * NotClippedByChildren comes out with just clipList.
+     */
+
+    pBuffer->clipList   = pWin->clipList;
+    pBuffer->borderClip = pWin->clipList;
+    pBuffer->winSize    = pWin->winSize;
+    pBuffer->borderSize = pWin->borderSize;
+
+    pBuffer->origin = pWin->origin;
+}
+
+static BufferPtr
+bufCreateBuffer(pScreen, pWin, bufferNum)
+    ScreenPtr  pScreen;
+    WindowPtr  pWin;
+    int                bufferNum;
+{
+    mbufBufferPrivPtr  pMBPriv;
+    DevUnion   *devPrivates;
+    BufferPtr  pBuffer;
+    int                i;
+
+    pMBPriv = MB_SCREEN_PRIV_BUFFER(pScreen);
+
+    pBuffer = AllocateWindow(pWin->drawable.pScreen);
+    if (!pBuffer)
+       return (NULL);
+
+    /* XXX- Until we know what is needed, copy everything. */
+    devPrivates = pBuffer->devPrivates;
+    *pBuffer = *pWin;
+    pBuffer->devPrivates   = devPrivates;
+
+    pBuffer->drawable.type = DRAWABLE_BUFFER;
+    pBuffer->drawable.serialNumber = NEXT_SERIAL_NUMBER;
+
+    pBuffer->nextSib    = NULL;
+    pBuffer->prevSib    = NULL;
+    pBuffer->firstChild = NULL;
+    pBuffer->lastChild  = NULL;
+
+    /* XXX - Worry about backingstore later */
+    pBuffer->backStorage   = NULL;
+    pBuffer->backingStore  = NotUseful;
+
+    /* XXX - Need to call pScreen->CreateWindow for tile/stipples
+     *       or should I just copy the devPrivates?
+     */
+    
+    for (i=0; i < pScreen->WindowPrivateLen; i++)
+       pBuffer->devPrivates[i] = pWin->devPrivates[i];
+
+    pBuffer->devPrivates[frameWindowPrivateIndex] =
+       pMBPriv->frameBuffer[bufferNum];
+
+    return pBuffer;
+}
+
+static void
+bufDestroyBuffer(pDrawable)
+    DrawablePtr        pDrawable;
+{
+    xfree(pDrawable);
+}
+
+/*ARGSUSED*/
+static int
+bufCreateImageBuffers (pWin, nbuf, ids, action, hint)
+    WindowPtr  pWin;
+    int                nbuf;
+    XID                *ids;
+    int                action;
+    int                hint;
+{
+    ScreenPtr          pScreen;
+    mbufScreenPtr      pMBScreen;
+    mbufWindowPtr      pMBWindow;
+    mbufBufferPtr      pMBBuffer;
+    int                        i;
+
+    pScreen   = pWin->drawable.pScreen;
+    pMBScreen = MB_SCREEN_PRIV(pScreen);
+    pMBWindow = MB_WINDOW_PRIV(pWin);
+
+    pMBWindow->devPrivate.ptr = (pointer) REGION_CREATE(pScreen, 0,0);
+    if (!pMBWindow->devPrivate.ptr)
+       return(0);
+    REGION_COPY(pScreen, (RegionPtr) pMBWindow->devPrivate.ptr,
+                           &pWin->clipList);
+
+    for (i = 0; i < nbuf; i++)
+    {
+       pMBBuffer = pMBWindow->buffers + i;
+       pMBBuffer->pDrawable = (DrawablePtr) bufCreateBuffer(pScreen,pWin,i);
+
+       if (!pMBBuffer->pDrawable)
+           break;
+
+       if (!AddResource (ids[i], MultibufferDrawableResType,
+                         (pointer) pMBBuffer->pDrawable))
+       {
+           bufDestroyBuffer((BufferPtr) pMBBuffer->pDrawable);
+           break;
+       }
+       pMBBuffer->pDrawable->id = ids[i];
+
+       /*
+        * If window is already mapped, generate exposures and
+        * clear the area of the newly buffers.
+        */
+
+       if ((pWin->realized) && (i != pMBWindow->displayedMultibuffer))
+           (* pMBScreen->ClearImageBufferArea)(pMBBuffer, 0,0, 0,0, TRUE);
+    }
+
+    return i;
+}
+
+static void
+bufDestroyImageBuffers(pWin)
+    WindowPtr  pWin;
+{
+    ScreenPtr          pScreen;
+    mbufWindowPtr      pMBWindow;
+
+    pScreen   = pWin->drawable.pScreen;
+
+    if (pMBWindow = MB_WINDOW_PRIV(pWin))
+    {
+       mbufBufferPrivPtr pMBPriv = MB_SCREEN_PRIV_BUFFER(pScreen);
+
+       /*
+        * if the backbuffer is currently being displayed, move the bits
+        * to the frontbuffer and display it instead.
+        */
+
+       if (pWin->realized && (pMBWindow->displayedMultibuffer == BACK_BUFFER))
+       {
+           (* pMBPriv->CopyBufferBits)(pMBWindow, BACK_BUFFER, FRONT_BUFFER);
+           REGION_SUBTRACT(pScreen, &pMBPriv->backBuffer,
+                                 &pMBPriv->backBuffer, &pWin->clipList);
+           (* pMBPriv->DrawSelectPlane)(pScreen, pMBPriv->selectPlane,
+                           &pWin->clipList, FRONT_BUFFER);
+       }
+
+       /* Switch window rendering to front buffer */
+       pWin->devPrivates[frameWindowPrivateIndex] =
+           pMBPriv->frameBuffer[FRONT_BUFFER];
+
+       REGION_DESTROY(pScreen, (RegionPtr) pMBWindow->devPrivate.ptr);
+       pMBWindow->devPrivate.ptr = NULL;
+    }
+}
+
+/*
+ * Can be replaced by pScreen->ClearToBackground if pBuffer->eventMask
+ * and wOtherEventsMasks(pBuffer) were setup.
+ */
+
+static void
+bufClearImageBufferArea(pMBBuffer, x,y, w,h, generateExposures)
+    mbufBufferPtr      pMBBuffer;
+    short              x,y;
+    unsigned short     w,h;
+    Bool               generateExposures;
+{
+    BoxRec box;
+    RegionRec  reg;
+    RegionPtr pBSReg = NullRegion;
+    ScreenPtr  pScreen;
+    BoxPtr  extents;
+    int            x1, y1, x2, y2;
+    BufferPtr pBuffer;
+
+    pBuffer = (BufferPtr) pMBBuffer->pDrawable;
+    /* compute everything using ints to avoid overflow */
+
+    x1 = pBuffer->drawable.x + x;
+    y1 = pBuffer->drawable.y + y;
+    if (w)
+        x2 = x1 + (int) w;
+    else
+        x2 = x1 + (int) pBuffer->drawable.width - (int) x;
+    if (h)
+        y2 = y1 + h;   
+    else
+        y2 = y1 + (int) pBuffer->drawable.height - (int) y;
+
+    extents = &pBuffer->clipList.extents;
+    
+    /* clip the resulting rectangle to the window clipList extents.  This
+     * makes sure that the result will fit in a box, given that the
+     * screen is < 32768 on a side.
+     */
+
+    if (x1 < extents->x1)
+       x1 = extents->x1;
+    if (x2 > extents->x2)
+       x2 = extents->x2;
+    if (y1 < extents->y1)
+       y1 = extents->y1;
+    if (y2 > extents->y2)
+       y2 = extents->y2;
+
+    if (x2 <= x1 || y2 <= y1)
+    {
+       x2 = x1 = 0;
+       y2 = y1 = 0;
+    }
+
+    box.x1 = x1;
+    box.x2 = x2;
+    box.y1 = y1;
+    box.y2 = y2;
+
+    pScreen = pBuffer->drawable.pScreen;
+    REGION_INIT(pScreen, &reg, &box, 1);
+    if (pBuffer->backStorage)
+    {
+       /*
+        * If the window has backing-store on, call through the
+        * ClearToBackground vector to handle the special semantics
+        * (i.e. things backing store is to be cleared out and
+        * an Expose event is to be generated for those areas in backing
+        * store if generateExposures is TRUE).
+        */
+       pBSReg = (* pScreen->ClearBackingStore)(pBuffer, x, y, w, h,
+                                                generateExposures);
+    }
+
+    REGION_INTERSECT(pScreen, &reg, &reg, &pBuffer->clipList);
+    if (pBuffer->backgroundState != None)
+       (*pScreen->PaintWindowBackground)(pBuffer, &reg, PW_BACKGROUND);
+    if (generateExposures)
+       MultibufferExpose(pMBBuffer, &reg);
+#ifdef _notdef
+    /* XXBS - This is the original miClearToBackground code.
+     * WindowExposures needs to be called (or the functionality emulated)
+     * in order for backingStore to work, but first, pBuffer->eventMask
+     * and wOtherEventsMasks(pBuffer) need to be setup correctly.
+     */
+
+    if (generateExposures)
+       (*pScreen->WindowExposures)(pBuffer, &reg, pBSReg);
+    else if (pBuffer->backgroundState != None)
+        (*pScreen->PaintWindowBackground)(pBuffer, &reg, PW_BACKGROUND);
+#endif
+    REGION_UNINIT(pScreen, &reg);
+    if (pBSReg)
+       REGION_DESTROY(pScreen, pBSReg);
+}
+
+static void
+bufWrapScreenFuncs(pScreen)
+    ScreenPtr pScreen;
+{
+    mbufBufferPrivPtr pMBPriv = MB_SCREEN_PRIV_BUFFER(pScreen);
+
+    WRAP_SCREEN_FUNC(pScreen,pMBPriv,PostValidateTree, bufPostValidateTree);
+    WRAP_SCREEN_FUNC(pScreen,pMBPriv,ClipNotify, bufClipNotify);
+    WRAP_SCREEN_FUNC(pScreen,pMBPriv,WindowExposures,bufWindowExposures);
+    WRAP_SCREEN_FUNC(pScreen,pMBPriv,ChangeWindowAttributes, bufChangeWindowAttributes);
+    WRAP_SCREEN_FUNC(pScreen,pMBPriv,ClearToBackground,bufClearToBackground);
+    WRAP_SCREEN_FUNC(pScreen,pMBPriv,CopyWindow,bufCopyWindow);
+}
+
+static void
+bufResetProc(pScreen)
+    ScreenPtr pScreen;
+{
+    mbufBufferPrivPtr pMBPriv = MB_SCREEN_PRIV_BUFFER(pScreen);
+
+    /*
+     * frameBuffer, selectPlane, and pInfo should be freed by
+     * whoever called RegisterDoubleBufferHardware
+     */
+
+    REGION_UNINIT(pScreen, &pMBPriv->backBuffer);
+    REGION_UNINIT(pScreen, &pMBPriv->subtractRgn);
+    REGION_UNINIT(pScreen, &pMBPriv->unionRgn);
+    xfree(pMBPriv);
+}
+
+/*---------------------------------------------------------------------------*/
+
+/* 
+ * Used if CopyBufferBitsFunc is not provided when registering.
+ * This should work for everybody since CopyArea needs to support
+ * copying between buffers anyway.
+ */
+
+static void
+bufCopyBufferBits(pMBWindow, srcBufferNum, dstBufferNum)
+    mbufWindowPtr pMBWindow;
+    int srcBufferNum, dstBufferNum;
+{
+    DrawablePtr pSrcBuffer, pDstBuffer;
+    GCPtr pGC;
+
+    pSrcBuffer = pMBWindow->buffers[srcBufferNum].pDrawable;
+    pDstBuffer = pMBWindow->buffers[dstBufferNum].pDrawable;
+
+    pGC = GetScratchGC (pDstBuffer->depth, pDstBuffer->pScreen);
+    if (!pGC)
+       return;
+
+    ValidateGC (pDstBuffer, pGC);
+    (* pGC->ops->CopyArea) (pSrcBuffer, pDstBuffer, pGC,
+                   0,0, pDstBuffer->width, pDstBuffer->height, 0,0);
+    FreeScratchGC (pGC);
+}
+
+/*
+ * Used if DrawSelectPlanFunc is not provided for when registering.
+ * However, it only works if selectPlane.ptr is a drawable. Also
+ * assumes that painting with color 0 selects the front buffer,
+ * while color 1 selects the back buffer.
+ */
+
+static void
+bufDrawSelectPlane(pScreen, selectPlane, prgn, bufferNum)
+    ScreenPtr  pScreen;
+    DevUnion   selectPlane;
+    RegionPtr  prgn;
+    long       bufferNum;
+{
+    DrawablePtr pDrawable;
+    GCPtr pGC;
+    register int i;
+    register BoxPtr pbox;
+    register xRectangle *prect;
+    int numRects;
+    XID        value;
+
+    if (REGION_NUM_RECTS(prgn) == 0)
+       return;
+
+    pDrawable = (DrawablePtr) selectPlane.ptr;
+    pGC = GetScratchGC (pDrawable->depth, pScreen);
+    if (!pGC)
+       return;
+
+    prect = (xRectangle *)ALLOCATE_LOCAL(REGION_NUM_RECTS(prgn) *
+                                        sizeof(xRectangle));
+    if (!prect)
+    {
+       FreeScratchGC(pGC);
+       return;
+    }
+
+    value = (XID) bufferNum;
+    DoChangeGC(pGC, GCForeground, &value, 0);
+    ValidateGC(pDrawable, pGC);
+
+    numRects = REGION_NUM_RECTS(prgn);
+    pbox = REGION_RECTS(prgn);
+    for (i= numRects; --i >= 0; pbox++, prect++)
+    {
+       prect->x = pbox->x1;
+       prect->y = pbox->y1;
+       prect->width = pbox->x2 - pbox->x1;
+       prect->height = pbox->y2 - pbox->y1;
+    }
+    prect -= numRects;
+    (* pGC->ops->PolyFillRect)(pDrawable, pGC, numRects, prect);
+
+    DEALLOCATE_LOCAL(prect);
+    FreeScratchGC (pGC);
+}
+
+
+static void
+bufDisplayImageBuffers(pScreen, ppMBWindow, ppMBBuffer, nbuf)
+    ScreenPtr          pScreen;
+    mbufBufferPtr      *ppMBBuffer;
+    mbufWindowPtr      *ppMBWindow;
+    int                        nbuf;
+{
+    WindowPtr       pWin;
+    BufferPtr      pPrevBuffer, pNewBuffer;
+    int                    i, number;
+    mbufBufferPrivPtr pMBPriv;
+    mbufBufferPtr   pPrevMBBuffer;
+
+    pMBPriv   = MB_SCREEN_PRIV_BUFFER(pScreen);
+
+    for (i = 0; i < nbuf; i++)
+    {
+       number = ppMBBuffer[i]->number; /* 0=frontbuffer, 1=backbuffer */
+       pWin = ppMBWindow[i]->pWindow;
+       pPrevMBBuffer = MB_DISPLAYED_BUFFER(ppMBWindow[i]);
+
+       pPrevBuffer = (BufferPtr) pPrevMBBuffer->pDrawable;
+       pNewBuffer  = (BufferPtr) ppMBBuffer[i]->pDrawable;
+
+       if (pPrevBuffer != pNewBuffer)
+       {
+           RegionPtr backBuffer = &pMBPriv->backBuffer;
+
+           /*
+            * Update the select plane and the backBuffer region.
+            */
+
+           (* pMBPriv->DrawSelectPlane)(pScreen, pMBPriv->selectPlane,
+                           &pWin->clipList, number);
+
+           if (number == BACK_BUFFER)
+               REGION_UNION(pScreen, backBuffer, backBuffer,
+                                  &pWin->clipList);
+           else
+               REGION_SUBTRACT(pScreen, backBuffer, backBuffer,
+                                  &pWin->clipList);
+
+           /* Switch which framebuffer the window draws into */
+           pWin->devPrivates[frameWindowPrivateIndex] =
+               pMBPriv->frameBuffer[number];
+       }
+
+       switch (ppMBWindow[i]->updateAction)
+       {
+       case MultibufferUpdateActionUndefined:
+           break;
+       case MultibufferUpdateActionBackground:
+           (* MB_SCREEN_PRIV(pScreen)->ClearImageBufferArea)
+               (pPrevMBBuffer, 0,0, 0,0, FALSE);
+           break;
+       case MultibufferUpdateActionUntouched:
+           break;
+       case MultibufferUpdateActionCopied:
+           if (pPrevBuffer != pNewBuffer)
+           {
+               (* pMBPriv->CopyBufferBits) (ppMBWindow[i],
+                       ppMBBuffer[i]->number, pPrevMBBuffer->number);
+           }
+           break;
+       }
+    }
+}
+
+/* Updates the backBuffer region and paints the selectPlane. */
+
+static void
+bufPostValidateTree(pParent, pChild, kind)
+    WindowPtr  pParent, pChild;
+    VTKind     kind;
+{
+    ScreenPtr pScreen;
+    mbufBufferPrivPtr pMBPriv;
+
+    if (pParent)
+       pScreen = pParent->drawable.pScreen;
+    else if (pChild)
+       pScreen = pChild->drawable.pScreen;
+    else
+       return; /* Hopeless */
+
+    pMBPriv = MB_SCREEN_PRIV_BUFFER(pScreen);
+
+    UNWRAP_SCREEN_FUNC(pScreen, pMBPriv, void, PostValidateTree);
+    if (pScreen->PostValidateTree)
+       (* pScreen->PostValidateTree)(pParent, pChild, kind);
+    REWRAP_SCREEN_FUNC(pScreen, pMBPriv, void, PostValidateTree);
+
+    /* Does backBuffer need to change? */
+    if (pMBPriv->rgnChanged)
+    {
+       RegionRec exposed;
+       RegionPtr pSubtractRgn, pUnionRgn;
+       Bool overlap;
+
+       pMBPriv->rgnChanged = FALSE;
+
+       pSubtractRgn = &pMBPriv->subtractRgn;
+       pUnionRgn    = &pMBPriv->unionRgn;
+       REGION_VALIDATE(pScreen, pSubtractRgn, &overlap);
+#ifdef DEBUG
+       if (overlap)
+           FatalError("bufPostValidateTree: subtractRgn overlaps");
+#endif
+       REGION_VALIDATE(pScreen, pUnionRgn, &overlap);
+#ifdef DEBUG
+       if (overlap)
+           FatalError("bufPostValidateTree: unionRgn overlaps");
+#endif
+
+       /* Update backBuffer: subtract must come before union */
+       REGION_SUBTRACT(pScreen, &pMBPriv->backBuffer, &pMBPriv->backBuffer,
+                             pSubtractRgn);
+       REGION_UNION(pScreen, &pMBPriv->backBuffer, &pMBPriv->backBuffer,
+                             pUnionRgn);
+
+       /* Paint gained and lost backbuffer areas in select plane */
+       REGION_INIT(pScreen, &exposed, NullBox, 0);
+       REGION_SUBTRACT(pScreen, &exposed, pSubtractRgn, pUnionRgn);
+       (* pMBPriv->DrawSelectPlane)(pScreen, pMBPriv->selectPlane,
+                                    &exposed, FRONT_BUFFER);
+
+       REGION_SUBTRACT(pScreen, &exposed, pUnionRgn, pSubtractRgn);
+       (* pMBPriv->DrawSelectPlane)(pScreen, pMBPriv->selectPlane,
+                                   &exposed, BACK_BUFFER);
+       
+       REGION_UNINIT(pScreen, &exposed);
+       REGION_EMPTY(pScreen, pSubtractRgn);
+       REGION_EMPTY(pScreen, pUnionRgn);
+    }
+}
+
+/* XXX - Knows region internals. */
+
+static Bool
+RegionsEqual(reg1, reg2)
+    RegionPtr reg1;
+    RegionPtr reg2;
+{
+    int i;
+    BoxPtr rects1, rects2;
+
+    if (reg1->extents.x1 != reg2->extents.x1) return FALSE;
+    if (reg1->extents.x2 != reg2->extents.x2) return FALSE;
+    if (reg1->extents.y1 != reg2->extents.y1) return FALSE;
+    if (reg1->extents.y2 != reg2->extents.y2) return FALSE;
+    if (REGION_NUM_RECTS(reg1) != REGION_NUM_RECTS(reg2)) return FALSE;
+    
+    rects1 = REGION_RECTS(reg1);
+    rects2 = REGION_RECTS(reg2);
+    for (i = 0; i != REGION_NUM_RECTS(reg1); i++) {
+       if (rects1[i].x1 != rects2[i].x1) return FALSE;
+       if (rects1[i].x2 != rects2[i].x2) return FALSE;
+       if (rects1[i].y1 != rects2[i].y1) return FALSE;
+       if (rects1[i].y2 != rects2[i].y2) return FALSE;
+    }
+    return TRUE;
+}
+
+/*
+ * If the window is multibuffered and displaying the backbuffer,
+ * add the old clipList to the subtractRgn and add the new clipList
+ * to the unionRgn. PostValidateTree will use subtractRgn and unionRgn
+ * to update the backBuffer region and the selectPlane.
+ *
+ * Copy changes to the window structure into the buffers.
+ * Send ClobberNotify events.
+ */
+
+static void
+bufClipNotify(pWin, dx,dy)
+    WindowPtr pWin;
+    int       dx,dy;
+{
+    ScreenPtr pScreen = pWin->drawable.pScreen;
+    mbufBufferPrivPtr pMBPriv = MB_SCREEN_PRIV_BUFFER(pScreen);
+    mbufWindowPtr      pMBWindow;
+    int i;
+
+    UNWRAP_SCREEN_FUNC(pScreen, pMBPriv, void, ClipNotify);
+    if (pScreen->ClipNotify)
+       (* pScreen->ClipNotify)(pWin, dx,dy);
+    REWRAP_SCREEN_FUNC(pScreen, pMBPriv, void, ClipNotify);
+
+    if (pMBWindow = MB_WINDOW_PRIV(pWin))
+    {
+       RegionPtr pOldClipList = (RegionPtr) pMBWindow->devPrivate.ptr;
+
+       if (! RegionsEqual(pOldClipList, &pWin->clipList))
+       {
+           if (pMBWindow->displayedMultibuffer == BACK_BUFFER)
+           {
+               pMBPriv->rgnChanged = TRUE;
+               REGION_APPEND(pScreen, &pMBPriv->subtractRgn, pOldClipList);
+               REGION_APPEND(pScreen, &pMBPriv->unionRgn, &pWin->clipList);
+           }
+
+           REGION_COPY(pScreen, pOldClipList,&pWin->clipList);
+       }
+
+       /* Update buffer x,y,w,h, and clipList */
+       for (i=0; i<pMBWindow->numMultibuffer; i++)
+       {
+           mbufBufferPtr pMBBuffer = pMBWindow->buffers + i;
+           if (pMBBuffer->clobber != pWin->visibility)
+           {
+               pMBBuffer->clobber = pWin->visibility;
+               MultibufferClobber(pMBBuffer);
+           }
+           UpdateBufferFromWindow(pMBBuffer->pDrawable, pWin);
+       }
+    }
+}
+
+/*
+ * Updates buffer's background fields when the window's changes.
+ * This is necessary because pScreen->PaintWindowBackground
+ * is used to paint the buffer.
+ *
+ * XXBS - Backingstore state will have be tracked too if it is supported.
+ */
+
+static Bool
+bufChangeWindowAttributes(pWin, mask)
+    WindowPtr pWin;
+    unsigned long mask;
+{
+    ScreenPtr pScreen = pWin->drawable.pScreen;
+    mbufBufferPrivPtr pMBPriv = MB_SCREEN_PRIV_BUFFER(pScreen);
+    mbufWindowPtr pMBWindow;
+    Bool ret;
+
+    UNWRAP_SCREEN_FUNC(pScreen, pMBPriv, Bool, ChangeWindowAttributes);
+    ret = (* pScreen->ChangeWindowAttributes)(pWin, mask);
+    REWRAP_SCREEN_FUNC(pScreen, pMBPriv, Bool, ChangeWindowAttributes);
+
+    if (pMBWindow = MB_WINDOW_PRIV(pWin))
+    {
+       if (mask & (CWBackPixmap | CWBackPixel))
+       {
+           BufferPtr pBuffer;
+           int i;
+
+           for (i=0; i<pMBWindow->displayedMultibuffer; i++)
+           {
+               pBuffer = (BufferPtr) pMBWindow->buffers[i].pDrawable;
+               pBuffer->backgroundState = pWin->backgroundState;
+               pBuffer->background = pWin->background;
+           }
+       }
+    }
+    return ret;
+}
+
+/*
+ * Send exposures and clear the background for a buffer whenever
+ * its corresponding window is exposed, except when called by
+ * ClearToBackground.
+ */
+
+static void 
+bufWindowExposures(pWin, prgn, other_exposed)
+    WindowPtr pWin;
+    register RegionPtr prgn, other_exposed;
+{
+    ScreenPtr pScreen = pWin->drawable.pScreen;
+    mbufWindowPtr pMBWindow = MB_WINDOW_PRIV(pWin);
+    mbufBufferPrivPtr pMBPriv = MB_SCREEN_PRIV_BUFFER(pScreen);
+    RegionRec tmp_rgn;
+    int i;
+    Bool handleBuffers;
+
+    handleBuffers = (!pMBPriv->inClearToBackground) &&
+       (pWin->drawable.type == DRAWABLE_WINDOW) &&
+       pMBWindow && (prgn && !REGION_NIL(prgn));
+
+    /* miWindowExposures munges prgn and other_exposed. */
+    if (handleBuffers)
+    {
+       REGION_INIT(pScreen, &tmp_rgn, NullBox, 0);
+       REGION_COPY(pScreen, &tmp_rgn,prgn);
+    }
+
+    UNWRAP_SCREEN_FUNC(pScreen, pMBPriv, void, WindowExposures);
+    (* pScreen->WindowExposures) (pWin, prgn, other_exposed);
+    REWRAP_SCREEN_FUNC(pScreen, pMBPriv, void, WindowExposures);
+
+    if (!handleBuffers)
+       return;
+
+    /*
+     * Send expose events to all clients. Paint the exposed region for all
+     * buffers except the displayed buffer since it is handled when the
+     * window is painted.
+     *
+     * XXBS - Will have to be re-written to handle BackingStore on buffers.
+     */
+
+    for (i=0; i<pMBWindow->numMultibuffer; i++)
+    {
+       mbufBufferPtr pMBBuffer;
+       BufferPtr pBuffer;
+
+       pMBBuffer = pMBWindow->buffers + i;
+       pBuffer = (BufferPtr) pMBBuffer->pDrawable;
+
+       if (i != pMBWindow->displayedMultibuffer)
+           (* pScreen->PaintWindowBackground)(pBuffer,&tmp_rgn,PW_BACKGROUND);
+       if ((pMBBuffer->otherEventMask | pMBBuffer->eventMask) & ExposureMask)
+           MultibufferExpose(pMBBuffer, &tmp_rgn);
+    }
+
+    REGION_UNINIT(pScreen, &tmp_rgn);
+}
+
+/*
+ * Set ``inClearToBackground'' so that WindowExposures does not attempt
+ * to send expose events or clear the background on the buffers.
+ */
+
+static void
+bufClearToBackground(pWin, x,y,w,h, sendExpose)
+    WindowPtr pWin;
+    int x,y, w,h;
+    Bool sendExpose;
+{
+    ScreenPtr pScreen = pWin->drawable.pScreen;
+    mbufBufferPrivPtr pMBPriv = MB_SCREEN_PRIV_BUFFER(pScreen);
+
+    pMBPriv->inClearToBackground = TRUE;
+
+    UNWRAP_SCREEN_FUNC(pScreen, pMBPriv, void, ClearToBackground);
+    (* pScreen->ClearToBackground)(pWin, x,y,w,h, sendExpose);
+    REWRAP_SCREEN_FUNC(pScreen, pMBPriv, void, ClearToBackground);
+
+    pMBPriv->inClearToBackground = FALSE;
+}
+
+/*
+ * Move bits in both buffers. It does this by calling pScreen->CopyWindow
+ * twice, once with the root window's devPrivate[frameWindowPrivateIndex]
+ * pointing to the frontbuffer pixmap and once with it pointed to the
+ * backbuffer pixmap. It does this if there are *any* existing multibuffered
+ * window... a possible optimization is to copy the backbuffer only if this
+ * window or its inferiors are multibuffered. May be faster, maybe not.
+ *
+ * XXX - Only works if your CopyWindow checks the root window's devPrivate
+ *       to see which buffer to draw into. Works for cfbPaintWindow.
+ */
+
+/*ARGSUSED*/
+static void 
+bufCopyWindow(pWin, ptOldOrg, prgnSrc)
+    WindowPtr pWin;
+    DDXPointRec ptOldOrg;
+    RegionPtr prgnSrc;
+{
+    ScreenPtr pScreen = pWin->drawable.pScreen;
+    mbufBufferPrivPtr pMBPriv = MB_SCREEN_PRIV_BUFFER(pScreen);
+    WindowPtr pwinroot;
+    DevUnion save;
+
+    UNWRAP_SCREEN_FUNC(pScreen, pMBPriv, void, CopyWindow);
+
+    pwinroot = WindowTable[pScreen->myNum];
+    save = pwinroot->devPrivates[frameWindowPrivateIndex];
+
+    /*
+     * Copy front buffer
+     */
+
+    pwinroot->devPrivates[frameWindowPrivateIndex] =
+       pMBPriv->frameBuffer[FRONT_BUFFER];
+    (* pScreen->CopyWindow)(pWin, ptOldOrg, prgnSrc);
+
+    /*
+     * Copy back buffer
+     */
+
+    /* CopyWindow translates prgnSrc... translate it back for 2nd call. */
+    REGION_TRANSLATE(pScreen, prgnSrc,
+                                 ptOldOrg.x - pWin->drawable.x,
+                                 ptOldOrg.y - pWin->drawable.y);
+    pwinroot->devPrivates[frameWindowPrivateIndex] =
+       pMBPriv->frameBuffer[BACK_BUFFER];
+    (* pScreen->CopyWindow)(pWin, ptOldOrg, prgnSrc);
+
+    pwinroot->devPrivates[frameWindowPrivateIndex] = save;
+    REWRAP_SCREEN_FUNC(pScreen, pMBPriv, void, CopyWindow);
+}
diff --git a/Xserver/programs/Xserver/Xext/mbufpx.c b/Xserver/programs/Xserver/Xext/mbufpx.c
new file mode 100644 (file)
index 0000000..12bb48d
--- /dev/null
@@ -0,0 +1,650 @@
+/************************************************************
+
+Copyright (c) 1989  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+********************************************************/
+
+/* $XConsortium: mbufpx.c,v 1.5 94/04/17 20:32:54 dpw Exp $ */
+/* $XFree86: xc/programs/Xserver/Xext/mbufpx.c,v 3.0 1994/05/08 05:17:32 dawes Exp $ */
+#define NEED_REPLIES
+#define NEED_EVENTS
+#include <stdio.h>
+#include "X.h"
+#include "Xproto.h"
+#include "misc.h"
+#include "os.h"
+#include "windowstr.h"
+#include "scrnintstr.h"
+#include "pixmapstr.h"
+#include "extnsionst.h"
+#include "dixstruct.h"
+#include "resource.h"
+#include "opaque.h"
+#include "regionstr.h"
+#include "gcstruct.h"
+#include "inputstr.h"
+#ifndef MINIX
+#include <sys/time.h>
+#endif
+
+#define _MULTIBUF_SERVER_      /* don't want Xlib structures */
+#define _MULTIBUF_PIXMAP_
+#include "multibufst.h"
+
+
+static Bool NoopDDA_True() { return TRUE; }
+
+static Bool pixPositionWindow();
+static int  pixCreateImageBuffers();
+static void pixDisplayImageBuffers();
+static void pixClearImageBufferArea();
+static void pixDeleteBufferDrawable();
+static void pixWrapScreenFuncs();
+static void pixResetProc();
+
+Bool
+pixMultibufferInit(pScreen, pMBScreen)
+    ScreenPtr pScreen;
+    mbufScreenPtr pMBScreen;
+{
+    int                        i, j, k;
+    xMbufBufferInfo    *pInfo;
+    int                        nInfo;
+    DepthPtr           pDepth;
+    mbufPixmapPrivPtr  pMBPriv;
+
+    pMBScreen->CreateImageBuffers = pixCreateImageBuffers;
+    pMBScreen->DestroyImageBuffers = (void (*)())NoopDDA;
+    pMBScreen->DisplayImageBuffers = pixDisplayImageBuffers;
+    pMBScreen->ClearImageBufferArea = pixClearImageBufferArea;
+    pMBScreen->ChangeMBufferAttributes = NoopDDA_True;
+    pMBScreen->ChangeBufferAttributes = NoopDDA_True;
+    pMBScreen->DeleteBufferDrawable = pixDeleteBufferDrawable;
+    pMBScreen->WrapScreenFuncs = pixWrapScreenFuncs;
+    pMBScreen->ResetProc = pixResetProc;
+
+    /* Support every depth and visual combination that the screen does */
+
+    nInfo = 0;
+    for (i = 0; i < pScreen->numDepths; i++)
+    {
+       pDepth = &pScreen->allowedDepths[i];
+       nInfo += pDepth->numVids;
+    }
+
+    pInfo = (xMbufBufferInfo *) xalloc (nInfo * sizeof (xMbufBufferInfo));
+    if (!pInfo)
+       return FALSE;
+
+    k = 0;
+    for (i = 0; i < pScreen->numDepths; i++)
+    {
+       pDepth = &pScreen->allowedDepths[i];
+       for (j = 0; j < pDepth->numVids; j++)
+       {
+           pInfo[k].visualID = pDepth->vids[j];
+           pInfo[k].maxBuffers = 0;
+           pInfo[k].depth = pDepth->depth;
+           k++;
+       }
+    }
+
+    pMBScreen->nInfo = nInfo;
+    pMBScreen->pInfo = pInfo;
+
+    /*
+     * Setup the devPrivate to mbufScreenRec
+     */
+
+    pMBPriv = (mbufPixmapPrivPtr) xalloc(sizeof(* pMBPriv));
+    if (!pMBPriv)
+    {
+       xfree(pInfo);
+       return (FALSE);
+    }
+    pMBScreen->devPrivate.ptr = (pointer) pMBPriv;
+    pMBPriv->PositionWindow = NULL;
+    pMBPriv->funcsWrapped = 0;
+
+    return TRUE;
+}
+
+/*ARGSUSED*/
+static int
+pixCreateImageBuffers (pWin, nbuf, ids, action, hint)
+    WindowPtr  pWin;
+    int                nbuf;
+    XID                *ids;
+    int                action;
+    int                hint;
+{
+    mbufWindowPtr      pMBWindow;
+    mbufBufferPtr      pMBBuffer;
+    ScreenPtr          pScreen;
+    int                        width, height, depth;
+    int                        i;
+
+    pMBWindow = MB_WINDOW_PRIV(pWin);
+
+    width = pWin->drawable.width;
+    height = pWin->drawable.height;
+    depth = pWin->drawable.depth;
+    pScreen = pWin->drawable.pScreen;
+
+    for (i = 0; i < nbuf; i++)
+    {
+       pMBBuffer = &pMBWindow->buffers[i];
+       pMBBuffer->pDrawable = (DrawablePtr)
+           (*pScreen->CreatePixmap) (pScreen, width, height, depth);
+       if (!pMBBuffer->pDrawable)
+           break;
+
+       if (!AddResource (ids[i], MultibufferDrawableResType,
+                         (pointer) pMBBuffer->pDrawable))
+       {
+           (*pScreen->DestroyPixmap) ((PixmapPtr) pMBBuffer->pDrawable);
+           break;
+       }
+       pMBBuffer->pDrawable->id = ids[i];
+
+       /*
+        * In the description of the CreateImageBuffers request:
+         * "If the window is mapped, or if these image buffers have
+         *  backing store, their contents will be tiled with the window
+         *  background, and zero or more expose events will be generated
+         *  for each of these buffers."
+        */
+
+       (* MB_SCREEN_PRIV(pScreen)->ClearImageBufferArea)
+           (pMBBuffer, 0,0, 0,0, TRUE);
+    }
+
+    return i;
+}
+
+/*
+ * set up the gc to clear the pixmaps;
+ */
+static Bool
+SetupBackgroundPainter (pWin, pGC)
+    WindowPtr  pWin;
+    GCPtr      pGC;
+{
+    XID                    gcvalues[4];
+    int                    ts_x_origin, ts_y_origin;
+    PixUnion       background;
+    int                    backgroundState;
+    Mask           gcmask;
+
+    /*
+     * First take care of any ParentRelative stuff by altering the
+     * tile/stipple origin to match the coordinates of the upper-left
+     * corner of the first ancestor without a ParentRelative background.
+     * This coordinate is, of course, negative.
+     */
+
+    ts_x_origin = ts_y_origin = 0;
+    while (pWin->backgroundState == ParentRelative) {
+       ts_x_origin -= pWin->origin.x;
+       ts_y_origin -= pWin->origin.y;
+       pWin = pWin->parent;
+    }
+    backgroundState = pWin->backgroundState;
+    background = pWin->background;
+
+    switch (backgroundState)
+    {
+    case BackgroundPixel:
+       gcvalues[0] = (XID) background.pixel;
+       gcvalues[1] = FillSolid;
+       gcmask = GCForeground|GCFillStyle;
+       break;
+
+    case BackgroundPixmap:
+       gcvalues[0] = FillTiled;
+       gcvalues[1] = (XID) background.pixmap;
+       gcvalues[2] = ts_x_origin;
+       gcvalues[3] = ts_y_origin;
+       gcmask = GCFillStyle|GCTile|GCTileStipXOrigin|GCTileStipYOrigin;
+       break;
+
+    default:
+       return FALSE;
+    }
+    DoChangeGC(pGC, gcmask, gcvalues, TRUE);
+    return TRUE;
+}
+
+static void
+MultibufferPaintBackgroundRectangles(pWin, pDrawable, nrects, pRects)
+    WindowPtr pWin;
+    DrawablePtr pDrawable;
+    int nrects;
+    xRectangle *pRects;
+{
+    GCPtr      pGC;
+
+    pGC = GetScratchGC (pWin->drawable.depth, pWin->drawable.pScreen);
+    if (SetupBackgroundPainter(pWin, pGC))
+    {
+       ValidateGC(pDrawable, pGC);
+       (*pGC->ops->PolyFillRect) (pDrawable, pGC, nrects, pRects);
+    }
+    FreeScratchGC(pGC);
+}
+
+static void
+MultibufferPaintBackgroundRegion(pWin, pDrawable, pRegion)
+    WindowPtr pWin;
+    DrawablePtr pDrawable;
+    RegionPtr pRegion;
+{
+    xRectangle *pRects;
+    int nrects  = REGION_NUM_RECTS(pRegion);
+    BoxPtr pbox = REGION_RECTS(pRegion);
+
+    pRects = (xRectangle *)ALLOCATE_LOCAL(nrects * sizeof(xRectangle));
+    if (pRects)
+    {
+       int i;
+       for (i = 0; i < nrects; i++)
+       {
+           pRects[i].x = pbox->x1;
+           pRects[i].y = pbox->y1;
+           pRects[i].width  = pbox->x2 - pbox->x1;
+           pRects[i].height = pbox->y2 - pbox->y1;
+       }
+       MultibufferPaintBackgroundRectangles(pWin, pDrawable, nrects, pRects);
+       DEALLOCATE_LOCAL(pRects);
+    }
+}
+
+static void
+pixDisplayImageBuffers(pScreen, ppMBWindow, ppMBBuffer, nbuf)
+    mbufBufferPtr          *ppMBBuffer;
+    mbufWindowPtr          *ppMBWindow;
+    int                    nbuf;
+{
+    GCPtr          pGC = NULL;
+    PixmapPtr      pPrevPixmap, pNewPixmap;
+    WindowPtr      pWin;
+    RegionPtr      pExposed;
+    int                    i;
+    mbufBufferPtr  pPrevMBBuffer;
+    XID                    bool;
+    xRectangle      r;
+
+    UpdateCurrentTime ();
+    for (i = 0; i < nbuf; i++)
+    {
+       pWin = ppMBWindow[i]->pWindow;
+
+       /* Time to get a different scratch GC? */
+
+       if (!pGC
+           || pGC->depth   != pWin->drawable.depth
+           || pGC->pScreen != pWin->drawable.pScreen)
+       {
+           if (pGC) FreeScratchGC(pGC);
+           pGC = GetScratchGC (pWin->drawable.depth, pWin->drawable.pScreen);
+       }
+       pPrevMBBuffer = MB_DISPLAYED_BUFFER(ppMBWindow[i]);
+       pPrevPixmap = (PixmapPtr) pPrevMBBuffer->pDrawable;
+       pNewPixmap = (PixmapPtr) ppMBBuffer[i]->pDrawable;
+
+       if (pPrevPixmap == pNewPixmap)
+       {
+         /* "If a specified buffer is already displayed, any delays and
+          *  update action will still be performed for that buffer."
+          *
+          *  We special-case this because applications do occasionally
+          *  request a redundant DisplayImageBuffers, and we can save
+          *  strokes by recognizing that the only update action that will
+          *  change the buffer contents in this case is Background.
+          */
+           if (ppMBWindow[i]->updateAction == MultibufferUpdateActionBackground)
+           {
+               r.x = r.y = 0;
+               r.width  = pWin->drawable.width;
+               r.height = pWin->drawable.height;
+               MultibufferPaintBackgroundRectangles(pWin, (DrawablePtr)pWin,
+                                                    1, &r);
+           }
+       }
+       else /* different buffer is being displayed */
+       {
+           /* perform update action */
+
+           switch (ppMBWindow[i]->updateAction)
+           {
+           case MultibufferUpdateActionUndefined:
+               break;
+
+           case MultibufferUpdateActionBackground:
+
+               r.x = r.y = 0;
+               r.width  = pPrevPixmap->drawable.width;
+               r.height = pPrevPixmap->drawable.height;
+               MultibufferPaintBackgroundRectangles(pWin,
+                                                    (DrawablePtr)pPrevPixmap,
+                                                    1, &r);
+               break;
+
+           case MultibufferUpdateActionUntouched:
+               
+               /* copy the window to the pixmap that represents the
+                * currently displayed buffer
+                */
+
+               if (pPrevMBBuffer->eventMask & ExposureMask)
+               {
+                   bool = TRUE;
+                   DoChangeGC (pGC, GCGraphicsExposures, &bool, FALSE);
+               }
+               ValidateGC ((DrawablePtr)pPrevPixmap, pGC);
+               pExposed = (*pGC->ops->CopyArea)((DrawablePtr) pWin,
+                                                (DrawablePtr) pPrevPixmap,
+                                                pGC,
+                                                0, 0,
+                                                pWin->drawable.width,
+                                                pWin->drawable.height,
+                                                0, 0);
+
+               /* if we couldn't copy the whole window to the buffer,
+                * send expose events (if any client wants them)
+                */
+
+               if (pPrevMBBuffer->eventMask & ExposureMask)
+               { /* some client wants expose events */
+                   if (pExposed)
+                   {
+                       RegionPtr        pWinSize;
+                       extern RegionPtr CreateUnclippedWinSize();
+                       ScreenPtr pScreen = pWin->drawable.pScreen;
+                       pWinSize = CreateUnclippedWinSize (pWin);
+                       /*
+                        * pExposed is window-relative, but at this point
+                        * pWinSize is screen-relative.  Make pWinSize be
+                        * window-relative so that region ops involving
+                        * pExposed and pWinSize behave sensibly.
+                        */
+                       REGION_TRANSLATE(pScreen, pWinSize,
+                                                    -pWin->drawable.x,
+                                                    -pWin->drawable.y);
+                       REGION_INTERSECT(pScreen, pExposed, pExposed, pWinSize);
+                       REGION_DESTROY(pScreen, pWinSize);
+                       MultibufferExpose (pPrevMBBuffer, pExposed);
+                       REGION_DESTROY(pScreen, pExposed);
+                   }
+                   bool = FALSE;
+                   DoChangeGC (pGC, GCGraphicsExposures, &bool, FALSE);
+               } /* end some client wants expose events */
+
+               break; /* end case MultibufferUpdateActionUntouched */
+
+           case MultibufferUpdateActionCopied:
+
+               ValidateGC ((DrawablePtr)pPrevPixmap, pGC);
+               (*pGC->ops->CopyArea) ((DrawablePtr)pNewPixmap,
+                                      (DrawablePtr)pPrevPixmap, pGC,
+                                      0, 0, pWin->drawable.width,
+                                      pWin->drawable.height, 0, 0);
+               break;
+
+           } /* end switch on update action */
+
+           /* display the new buffer */
+
+           ValidateGC ((DrawablePtr)pWin, pGC);
+           (*pGC->ops->CopyArea) ((DrawablePtr)pNewPixmap, (DrawablePtr)pWin,
+                                  pGC, 0, 0,
+                                  pWin->drawable.width, pWin->drawable.height,
+                                  0, 0);
+       }
+
+       ppMBWindow[i]->lastUpdate = currentTime;
+    }
+
+    if (pGC) FreeScratchGC (pGC);
+    return;
+}
+
+/*
+ * resize the buffers when the window is resized
+ */ 
+
+static Bool
+pixPositionWindow (pWin, x, y)
+    WindowPtr  pWin;
+    int                x, y;
+{
+    ScreenPtr      pScreen;
+    mbufPixmapPrivPtr pMBPriv;
+    mbufWindowPtr   pMBWindow;
+    mbufBufferPtr   pMBBuffer;
+    int                    width, height;
+    int                    i;
+    int                    dx, dy, dw, dh;
+    int                    sourcex, sourcey;
+    int                    destx, desty;
+    PixmapPtr      pPixmap;
+    GCPtr          pGC;
+    int                    savewidth, saveheight;
+    Bool           clear;
+    RegionRec       exposedRegion;
+    Bool           ret;
+
+    pScreen = pWin->drawable.pScreen;
+    pMBPriv = MB_SCREEN_PRIV_PIXMAP(pScreen);
+
+    UNWRAP_SCREEN_FUNC(pScreen, pMBPriv, Bool, PositionWindow);
+    ret = (* pScreen->PositionWindow) (pWin, x, y);
+    REWRAP_SCREEN_FUNC(pScreen, pMBPriv, Bool, PositionWindow);
+
+    if (!(pMBWindow = MB_WINDOW_PRIV(pWin)))
+       return ret;
+
+    /* if new size is same as old, we're done */
+
+    if (pMBWindow->width == pWin->drawable.width &&
+        pMBWindow->height == pWin->drawable.height)
+       return ret;
+
+    width = pWin->drawable.width;
+    height = pWin->drawable.height;
+    dx = pWin->drawable.x - pMBWindow->x;
+    dy = pWin->drawable.x - pMBWindow->y;
+    dw = width - pMBWindow->width;
+    dh = height - pMBWindow->height;
+    GravityTranslate (0, 0, -dx, -dy, dw, dh,
+                     pWin->bitGravity, &destx, &desty);
+
+    /* if the window grew, remember to paint the window background,
+     * and maybe send expose events, for the new areas of the buffers
+     */
+
+    clear = pMBWindow->width < width || pMBWindow->height < height ||
+           pWin->bitGravity == ForgetGravity;
+
+    sourcex = 0;
+    sourcey = 0;
+    savewidth = pMBWindow->width;
+    saveheight = pMBWindow->height;
+    /* clip rectangle to source and destination */
+    if (destx < 0)
+    {
+       savewidth += destx;
+       sourcex -= destx;
+       destx = 0;
+    }
+    if (destx + savewidth > width)
+       savewidth = width - destx;
+    if (desty < 0)
+    {
+       saveheight += desty;
+       sourcey -= desty;
+       desty = 0;
+    }
+    if (desty + saveheight > height)
+       saveheight = height - desty;
+
+    pMBWindow->width = width;
+    pMBWindow->height = height;
+    pMBWindow->x = pWin->drawable.x;
+    pMBWindow->y = pWin->drawable.y;
+
+    if (clear)
+    {
+       BoxRec box;
+
+       box.x1 = box.y1 = 0;
+       box.x2 = width;
+       box.y2 = height;
+       REGION_INIT(pScreen, &exposedRegion, &box, 1);
+       if (pWin->bitGravity != ForgetGravity)
+       {
+           RegionRec preservedRegion;
+           box.x1 = destx;
+           box.y1 = desty;
+           box.x2 = destx + savewidth;
+           box.y2 = desty + saveheight;
+           REGION_INIT(pScreen, &preservedRegion, &box, 1);
+           REGION_SUBTRACT(pScreen, &exposedRegion, &exposedRegion, &preservedRegion);
+           REGION_UNINIT(pScreen, &preservedRegion);
+       }
+
+    } /* end if (clear) */
+
+    pGC = GetScratchGC (pWin->drawable.depth, pScreen);
+
+    /* create buffers with new window size */
+
+    for (i = 0; i < pMBWindow->numMultibuffer; i++)
+    {
+       pMBBuffer = &pMBWindow->buffers[i];
+       pPixmap = (*pScreen->CreatePixmap) (pScreen, width, height, pWin->drawable.depth);
+       if (!pPixmap)
+       {
+           (* MB_SCREEN_PRIV(pScreen)->DestroyImageBuffers)(pWin);
+           break;
+       }
+       if (clear)
+       {
+           MultibufferPaintBackgroundRegion(pWin, (DrawablePtr)pPixmap, &exposedRegion);
+           MultibufferExpose(pMBBuffer, &exposedRegion);
+       }
+       if (pWin->bitGravity != ForgetGravity)
+       {
+           ValidateGC ((DrawablePtr)pPixmap, pGC);
+           (*pGC->ops->CopyArea) (pMBBuffer->pDrawable, (DrawablePtr)pPixmap,
+                                  pGC,
+                                  sourcex, sourcey, savewidth, saveheight,
+                                  destx, desty);
+       }
+       pPixmap->drawable.id = pMBBuffer->pDrawable->id;
+       (*pScreen->DestroyPixmap) ((PixmapPtr) pMBBuffer->pDrawable);
+       pMBBuffer->pDrawable = (DrawablePtr) pPixmap;
+       if (i != pMBWindow->displayedMultibuffer)
+       {
+           ChangeResourceValue (pPixmap->drawable.id,
+                                MultibufferDrawableResType,
+                                (pointer) pPixmap);
+       }
+    }
+    FreeScratchGC (pGC);
+    if (clear)
+       REGION_UNINIT(pScreen, &exposedRegion);
+    return TRUE;
+}
+
+static void
+pixWrapScreenFuncs(pScreen)
+    ScreenPtr pScreen;
+{
+    mbufPixmapPrivPtr pMBPriv = MB_SCREEN_PRIV_PIXMAP(pScreen);
+    WRAP_SCREEN_FUNC(pScreen, pMBPriv, PositionWindow, pixPositionWindow);
+}
+
+static void
+pixResetProc(pScreen)
+    ScreenPtr pScreen;
+{
+    mbufScreenPtr pMBScreen = MB_SCREEN_PRIV(pScreen);
+    mbufPixmapPrivPtr pMBPriv = MB_SCREEN_PRIV_PIXMAP(pScreen);
+
+    xfree(pMBScreen->pInfo);
+    xfree(pMBPriv);
+}
+
+static void
+pixClearImageBufferArea(pMBBuffer, x,y, width,height, exposures)
+    mbufBufferPtr      pMBBuffer;
+    short              x, y;
+    unsigned short     width, height;
+    Bool               exposures;
+{
+    WindowPtr pWin;
+    ScreenPtr pScreen;
+    BoxRec box;
+    RegionRec region;
+    int w_width, w_height;
+    DrawablePtr pDrawable;
+
+    pWin = pMBBuffer->pMBWindow->pWindow;
+    pScreen = pWin->drawable.pScreen;
+
+    w_width  = pWin->drawable.width;
+    w_height = pWin->drawable.height;
+
+    box.x1 = x;
+    box.y1 = y;
+    box.x2 = width  ? (box.x1 + width)  : w_width;
+    box.y2 = height ? (box.y1 + height) : w_height;
+
+    if (box.x1 < 0)        box.x1 = 0;
+    if (box.y1 < 0)        box.y1 = 0;
+    if (box.x2 > w_width)  box.x2 = w_width;
+    if (box.y2 > w_height) box.y2 = w_height;
+
+    REGION_INIT(pScreen, &region, &box, 1);
+
+    if (pMBBuffer->number == pMBBuffer->pMBWindow->displayedMultibuffer)
+      pDrawable = (DrawablePtr) pWin;
+    else
+      pDrawable = pMBBuffer->pDrawable;
+
+    MultibufferPaintBackgroundRegion(pWin, pDrawable, &region);
+
+    if (exposures)
+       MultibufferExpose(pMBBuffer, &region);
+
+    REGION_UNINIT(pScreen, &region);
+}
+
+static void
+pixDeleteBufferDrawable(pDrawable)
+    DrawablePtr        pDrawable;
+{
+    (* pDrawable->pScreen->DestroyPixmap)((PixmapPtr) pDrawable);
+}
diff --git a/Xserver/programs/Xserver/Xext/mitmisc.c b/Xserver/programs/Xserver/Xext/mitmisc.c
new file mode 100644 (file)
index 0000000..758acf6
--- /dev/null
@@ -0,0 +1,166 @@
+/************************************************************
+
+Copyright (c) 1989  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+********************************************************/
+
+/* RANDOM CRUFT! THIS HAS NO OFFICIAL X CONSORTIUM BLESSING */
+
+/* $XConsortium: mitmisc.c,v 1.5 94/04/17 20:32:54 rws Exp $ */
+/* $XFree86: xc/programs/Xserver/Xext/mitmisc.c,v 3.1 1996/05/06 05:55:29 dawes Exp $ */
+
+#define NEED_EVENTS
+#include "X.h"
+#include "Xproto.h"
+#include "misc.h"
+#include "os.h"
+#include "dixstruct.h"
+#include "extnsionst.h"
+#define _MITMISC_SERVER_
+#include "mitmiscstr.h"
+
+extern Bool permitOldBugs;
+
+static unsigned char MITReqCode;
+
+static void MITResetProc(
+#if NeedFunctionPrototypes
+    ExtensionEntry * /* extEntry */
+#endif
+);
+
+static DISPATCH_PROC(ProcMITDispatch);
+static DISPATCH_PROC(ProcMITGetBugMode);
+static DISPATCH_PROC(ProcMITSetBugMode);
+static DISPATCH_PROC(SProcMITDispatch);
+static DISPATCH_PROC(SProcMITGetBugMode);
+static DISPATCH_PROC(SProcMITSetBugMode);
+
+void
+MITMiscExtensionInit()
+{
+    ExtensionEntry *extEntry;
+
+    if ((extEntry = AddExtension(MITMISCNAME, 0, 0,
+                                ProcMITDispatch, SProcMITDispatch,
+                                MITResetProc, StandardMinorOpcode)) != 0)
+       MITReqCode = (unsigned char)extEntry->base;
+}
+
+/*ARGSUSED*/
+static void
+MITResetProc (extEntry)
+ExtensionEntry *extEntry;
+{
+}
+
+static int
+ProcMITSetBugMode(client)
+    register ClientPtr client;
+{
+    REQUEST(xMITSetBugModeReq);
+
+    REQUEST_SIZE_MATCH(xMITSetBugModeReq);
+    if ((stuff->onOff != xTrue) && (stuff->onOff != xFalse))
+    {
+       client->errorValue = stuff->onOff;
+       return BadValue;
+    }
+    permitOldBugs = stuff->onOff;
+    return(client->noClientException);
+}
+
+static int
+ProcMITGetBugMode(client)
+    register ClientPtr client;
+{
+    xMITGetBugModeReply rep;
+    register int n;
+
+    REQUEST_SIZE_MATCH(xMITGetBugModeReq);
+    rep.type = X_Reply;
+    rep.length = 0;
+    rep.sequenceNumber = client->sequence;
+    rep.onOff = permitOldBugs;
+    if (client->swapped) {
+       swaps(&rep.sequenceNumber, n);
+       swapl(&rep.length, n);
+    }
+    WriteToClient(client, sizeof(xMITGetBugModeReply), (char *)&rep);
+    return(client->noClientException);
+}
+
+static int
+ProcMITDispatch (client)
+    register ClientPtr client;
+{
+    REQUEST(xReq);
+    switch (stuff->data)
+    {
+    case X_MITSetBugMode:
+       return ProcMITSetBugMode(client);
+    case X_MITGetBugMode:
+       return ProcMITGetBugMode(client);
+    default:
+       return BadRequest;
+    }
+}
+
+static int
+SProcMITSetBugMode(client)
+    register ClientPtr client;
+{
+    register int n;
+    REQUEST(xMITSetBugModeReq);
+
+    swaps(&stuff->length, n);
+    return ProcMITSetBugMode(client);
+}
+
+static int
+SProcMITGetBugMode(client)
+    register ClientPtr client;
+{
+    register int n;
+    REQUEST(xMITGetBugModeReq);
+
+    swaps(&stuff->length, n);
+    return ProcMITGetBugMode(client);
+}
+
+static int
+SProcMITDispatch (client)
+    register ClientPtr client;
+{
+    REQUEST(xReq);
+    switch (stuff->data)
+    {
+    case X_MITSetBugMode:
+       return SProcMITSetBugMode(client);
+    case X_MITGetBugMode:
+       return SProcMITGetBugMode(client);
+    default:
+       return BadRequest;
+    }
+}
diff --git a/Xserver/programs/Xserver/Xext/saver.c b/Xserver/programs/Xserver/Xext/saver.c
new file mode 100644 (file)
index 0000000..0539cd7
--- /dev/null
@@ -0,0 +1,1324 @@
+/*
+ * $XConsortium: saver.c,v 1.12 94/04/17 20:59:36 dpw Exp $
+ * $XFree86: xc/programs/Xserver/Xext/saver.c,v 3.2 1996/06/10 09:11:17 dawes Exp $
+ *
+Copyright (c) 1992  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+ *
+ * Author:  Keith Packard, MIT X Consortium
+ */
+
+#define NEED_REPLIES
+#define NEED_EVENTS
+#include <stdio.h>
+#include "X.h"
+#include "Xproto.h"
+#include "misc.h"
+#include "os.h"
+#include "windowstr.h"
+#include "scrnintstr.h"
+#include "pixmapstr.h"
+#include "extnsionst.h"
+#include "dixstruct.h"
+#include "resource.h"
+#include "opaque.h"
+#include "saverproto.h"
+#include "gcstruct.h"
+#include "cursorstr.h"
+#include "colormapst.h"
+
+static unsigned char ScreenSaverReqCode = 0;
+static int ScreenSaverEventBase = 0;
+
+extern DISPATCH_PROC(ProcScreenSaverQueryInfo);
+static DISPATCH_PROC(ProcScreenSaverDispatch);
+static DISPATCH_PROC(ProcScreenSaverQueryVersion);
+static DISPATCH_PROC(ProcScreenSaverSelectInput);
+static DISPATCH_PROC(ProcScreenSaverSetAttributes);
+static DISPATCH_PROC(ProcScreenSaverUnsetAttributes);
+static DISPATCH_PROC(SProcScreenSaverDispatch);
+static DISPATCH_PROC(SProcScreenSaverQueryInfo);
+static DISPATCH_PROC(SProcScreenSaverQueryVersion);
+static DISPATCH_PROC(SProcScreenSaverSelectInput);
+static DISPATCH_PROC(SProcScreenSaverSetAttributes);
+static DISPATCH_PROC(SProcScreenSaverUnsetAttributes);
+
+static Bool ScreenSaverHandle (
+#if NeedFunctionPrototypes
+       ScreenPtr /* pScreen */,
+       int /* xstate */,
+       Bool /* force */
+#endif
+       );
+
+static Bool
+CreateSaverWindow (
+#if NeedFunctionPrototypes
+       ScreenPtr /* pScreen */
+#endif
+       );
+
+static Bool
+DestroySaverWindow (
+#if NeedFunctionPrototypes
+       ScreenPtr /* pScreen */
+#endif
+       );
+
+static void
+UninstallSaverColormap (
+#if NeedFunctionPrototypes
+       ScreenPtr /* pScreen */
+#endif
+       );
+
+static void
+CheckScreenPrivate (
+#if NeedFunctionPrototypes
+       ScreenPtr /* pScreen */
+#endif
+       );
+
+static void SScreenSaverNotifyEvent (
+#if NeedFunctionPrototypes
+       xScreenSaverNotifyEvent * /* from */,
+       xScreenSaverNotifyEvent * /* to */
+#endif
+       );
+
+static void ScreenSaverResetProc (
+#if NeedFunctionPrototypes
+       ExtensionEntry * /* extEntry */
+#endif
+       );
+
+extern WindowPtr    *WindowTable;
+
+/*
+ * each screen has a list of clients requesting
+ * ScreenSaverNotify events.  Each client has a resource
+ * for each screen it selects ScreenSaverNotify input for,
+ * this resource is used to delete the ScreenSaverNotifyRec
+ * entry from the per-screen queue.
+ */
+
+static RESTYPE EventType;   /* resource type for event masks */
+
+typedef struct _ScreenSaverEvent *ScreenSaverEventPtr;
+
+typedef struct _ScreenSaverEvent {
+    ScreenSaverEventPtr        next;
+    ClientPtr          client;
+    ScreenPtr          screen;
+    XID                        resource;
+    CARD32             mask;
+} ScreenSaverEventRec;
+
+static int ScreenSaverFreeEvents(
+#if NeedFunctionPrototypes
+    pointer /* value */,
+    XID /* id */
+#endif
+);
+
+static Bool setEventMask (
+#if NeedFunctionPrototypes
+    ScreenPtr /* pScreen */,
+    ClientPtr /* client */,
+    unsigned long /* mask */
+#endif
+);
+
+static unsigned long getEventMask (
+#if NeedFunctionPrototypes
+    ScreenPtr /* pScreen */,
+    ClientPtr /* client */
+#endif
+);
+
+/*
+ * when a client sets the screen saver attributes, a resource is
+ * kept to be freed when the client exits
+ */
+
+static RESTYPE AttrType;    /* resource type for attributes */
+
+typedef struct _ScreenSaverAttr {
+    ScreenPtr      screen;
+    ClientPtr      client;
+    XID                    resource;
+    short          x, y;
+    unsigned short  width, height, borderWidth;
+    unsigned char   class;
+    unsigned char   depth;
+    VisualID       visual;
+    CursorPtr      pCursor;
+    PixmapPtr      pBackgroundPixmap;
+    PixmapPtr      pBorderPixmap;
+    Colormap       colormap;
+    unsigned long   mask;              /* no pixmaps or cursors */
+    unsigned long   *values;
+} ScreenSaverAttrRec, *ScreenSaverAttrPtr;
+
+static int ScreenSaverFreeAttr (
+#if NeedFunctionPrototypes
+    pointer /* value */,
+    XID /* id */
+#endif
+);
+
+static void FreeAttrs (
+#if NeedFunctionPrototypes
+    ScreenSaverAttrPtr /* pAttr */
+#endif
+);
+
+static void FreeScreenAttr (
+#if NeedFunctionPrototypes
+    ScreenSaverAttrPtr /* pAttr */
+#endif
+);
+
+static void
+SendScreenSaverNotify (
+#if NeedFunctionPrototypes
+    ScreenPtr /* pScreen */,
+    int /* state */,
+    Bool /* forced */
+#endif
+);
+
+typedef struct _ScreenSaverScreenPrivate {
+    ScreenSaverEventPtr            events;
+    ScreenSaverAttrPtr     attr;
+    Bool                   hasWindow;
+    Colormap               installedMap;
+} ScreenSaverScreenPrivateRec, *ScreenSaverScreenPrivatePtr;
+
+static ScreenSaverScreenPrivatePtr
+MakeScreenPrivate (
+#if NeedFunctionPrototypes
+       ScreenPtr /* pScreen */
+#endif
+       );
+
+static int ScreenPrivateIndex;
+
+#define GetScreenPrivate(s) ((ScreenSaverScreenPrivatePtr)(s)->devPrivates[ScreenPrivateIndex].ptr)
+#define SetScreenPrivate(s,v) ((s)->devPrivates[ScreenPrivateIndex].ptr = (pointer) v);
+#define SetupScreen(s) ScreenSaverScreenPrivatePtr pPriv = GetScreenPrivate(s)
+
+#define New(t) ((t *) xalloc (sizeof (t)))
+
+/****************
+ * ScreenSaverExtensionInit
+ *
+ * Called from InitExtensions in main() or from QueryExtension() if the
+ * extension is dynamically loaded.
+ *
+ ****************/
+
+void
+ScreenSaverExtensionInit()
+{
+    ExtensionEntry *extEntry;
+    int                    i;
+    ScreenPtr      pScreen;
+
+    AttrType = CreateNewResourceType(ScreenSaverFreeAttr);
+    EventType = CreateNewResourceType(ScreenSaverFreeEvents);
+    ScreenPrivateIndex = AllocateScreenPrivateIndex ();
+    for (i = 0; i < screenInfo.numScreens; i++)
+    {
+       pScreen = screenInfo.screens[i];
+       SetScreenPrivate (pScreen, NULL);
+    }
+    if (AttrType && EventType && ScreenPrivateIndex != -1 &&
+       (extEntry = AddExtension(ScreenSaverName, ScreenSaverNumberEvents, 0,
+                                ProcScreenSaverDispatch, SProcScreenSaverDispatch,
+                                ScreenSaverResetProc, StandardMinorOpcode)))
+    {
+       ScreenSaverReqCode = (unsigned char)extEntry->base;
+       ScreenSaverEventBase = extEntry->eventBase;
+       EventSwapVector[ScreenSaverEventBase] = (EventSwapPtr) SScreenSaverNotifyEvent;
+    }
+}
+
+/*ARGSUSED*/
+static void
+ScreenSaverResetProc (extEntry)
+ExtensionEntry *extEntry;
+{
+}
+
+static void
+CheckScreenPrivate (pScreen)
+    ScreenPtr  pScreen;
+{
+    SetupScreen (pScreen);
+
+    if (!pPriv)
+       return;
+    if (!pPriv->attr && !pPriv->events &&
+       !pPriv->hasWindow && pPriv->installedMap == None)
+    {
+       xfree (pPriv);
+       SetScreenPrivate (pScreen, NULL);
+       savedScreenInfo[pScreen->myNum].ExternalScreenSaver = NULL;
+    }
+}
+
+static ScreenSaverScreenPrivatePtr
+MakeScreenPrivate (pScreen)
+    ScreenPtr  pScreen;
+{
+    SetupScreen (pScreen);
+
+    if (pPriv)
+       return pPriv;
+    pPriv = New (ScreenSaverScreenPrivateRec);
+    if (!pPriv)
+       return 0;
+    pPriv->events = 0;
+    pPriv->attr = 0;
+    pPriv->hasWindow = FALSE;
+    pPriv->installedMap = None;
+    SetScreenPrivate (pScreen, pPriv);
+    savedScreenInfo[pScreen->myNum].ExternalScreenSaver = ScreenSaverHandle;
+    return pPriv;
+}
+
+static unsigned long
+getEventMask (pScreen, client)
+    ScreenPtr  pScreen;
+    ClientPtr  client;
+{
+    SetupScreen(pScreen);
+    ScreenSaverEventPtr        pEv;
+
+    if (!pPriv)
+       return 0;
+    for (pEv = pPriv->events; pEv; pEv = pEv->next)
+       if (pEv->client == client)
+           return pEv->mask;
+    return 0;
+}
+
+static Bool
+setEventMask (pScreen, client, mask)
+    ScreenPtr  pScreen;
+    ClientPtr  client;
+    unsigned long   mask;
+{
+    SetupScreen(pScreen);
+    ScreenSaverEventPtr        pEv, *pPrev;
+
+    if (getEventMask (pScreen, client) == mask)
+       return TRUE;
+    if (!pPriv)
+    {
+       pPriv = MakeScreenPrivate (pScreen);
+       if (!pPriv)
+           return FALSE;
+    }
+    for (pPrev = &pPriv->events; (pEv = *pPrev) != 0; pPrev = &pEv->next)
+       if (pEv->client == client)
+           break;
+    if (mask == 0)
+    {
+       FreeResource (pEv->resource, EventType);
+       *pPrev = pEv->next;
+       xfree (pEv);
+       CheckScreenPrivate (pScreen);
+    }
+    else
+    {
+       if (!pEv) 
+       {
+           pEv = New (ScreenSaverEventRec);
+           if (!pEv) 
+           {
+               CheckScreenPrivate (pScreen);
+               return FALSE;
+           }
+           *pPrev = pEv;
+           pEv->next = NULL;
+           pEv->client = client;
+           pEv->screen = pScreen;
+           pEv->resource = FakeClientID (client->index);
+           if (!AddResource (pEv->resource, EventType, (pointer) pEv))
+               return FALSE;
+       }
+       pEv->mask = mask;
+    }
+    return TRUE;
+}
+
+static void
+FreeAttrs (pAttr)
+    ScreenSaverAttrPtr pAttr;
+{
+    PixmapPtr      pPixmap;
+    CursorPtr      pCursor;
+
+    if ((pPixmap = pAttr->pBackgroundPixmap) != 0)
+       (*pPixmap->drawable.pScreen->DestroyPixmap)(pPixmap);
+    if ((pPixmap = pAttr->pBorderPixmap) != 0)
+       (*pPixmap->drawable.pScreen->DestroyPixmap)(pPixmap);
+    if ((pCursor = pAttr->pCursor) != 0)
+       FreeCursor (pCursor, (Cursor) 0);
+}
+
+static void
+FreeScreenAttr (pAttr)
+    ScreenSaverAttrPtr pAttr;
+{
+    FreeAttrs (pAttr);
+    xfree (pAttr->values);
+    xfree (pAttr);
+}
+
+static int
+ScreenSaverFreeEvents (value, id)
+    pointer value;
+    XID id;
+{
+    ScreenSaverEventPtr        pOld = (ScreenSaverEventPtr)value;
+    ScreenPtr pScreen = pOld->screen;
+    SetupScreen (pScreen);
+    ScreenSaverEventPtr        pEv, *pPrev;
+
+    if (!pPriv)
+       return TRUE;
+    for (pPrev = &pPriv->events; (pEv = *pPrev) != 0; pPrev = &pEv->next)
+       if (pEv == pOld)
+           break;
+    if (!pEv)
+       return TRUE;
+    *pPrev = pEv->next;
+    xfree (pEv);
+    CheckScreenPrivate (pScreen);
+    return TRUE;
+}
+
+static int
+ScreenSaverFreeAttr (value, id)
+    pointer value;
+    XID id;
+{
+    ScreenSaverAttrPtr pOldAttr = (ScreenSaverAttrPtr)value;
+    ScreenPtr  pScreen = pOldAttr->screen;
+    SetupScreen (pScreen);
+
+    if (!pPriv)
+       return TRUE;
+    if (pPriv->attr != pOldAttr)
+       return TRUE;
+    FreeScreenAttr (pOldAttr);
+    pPriv->attr = NULL;
+    if (pPriv->hasWindow)
+    {
+       SaveScreens (SCREEN_SAVER_FORCER, ScreenSaverReset);
+       SaveScreens (SCREEN_SAVER_FORCER, ScreenSaverActive);
+    }
+    CheckScreenPrivate (pScreen);
+    return TRUE;
+}
+
+static void
+SendScreenSaverNotify (pScreen, state, forced)
+    ScreenPtr                  pScreen;
+    int            state;
+    Bool    forced;
+{
+    ScreenSaverScreenPrivatePtr        pPriv;
+    ScreenSaverEventPtr                pEv;
+    unsigned long              mask;
+    xScreenSaverNotifyEvent    ev;
+    ClientPtr                  client;
+    int                                kind;
+    ScreenSaverStuffPtr                pSaver;
+
+    UpdateCurrentTimeIf ();
+    mask = ScreenSaverNotifyMask;
+    if (state == ScreenSaverCycle)
+       mask = ScreenSaverCycleMask;
+    pScreen = screenInfo.screens[pScreen->myNum];
+    pPriv = GetScreenPrivate(pScreen);
+    if (!pPriv)
+       return;
+    pSaver = &savedScreenInfo[pScreen->myNum];
+    if (pPriv->attr)
+       kind = ScreenSaverExternal;
+    else if (ScreenSaverBlanking != DontPreferBlanking)
+       kind = ScreenSaverBlanked;
+    else
+       kind = ScreenSaverInternal;
+    for (pEv = pPriv->events; pEv; pEv = pEv->next)
+    {
+       client = pEv->client;
+       if (client->clientGone)
+           continue;
+       if (!(pEv->mask & mask))
+           continue;
+       ev.type = ScreenSaverNotify + ScreenSaverEventBase;
+       ev.state = state;
+       ev.sequenceNumber = client->sequence;
+       ev.timestamp = currentTime.milliseconds;
+       ev.root = WindowTable[pScreen->myNum]->drawable.id;
+       ev.window = savedScreenInfo[pScreen->myNum].wid;
+       ev.kind = kind;
+       ev.forced = forced;
+       WriteEventsToClient (client, 1, (xEvent *) &ev);
+    }
+}
+
+static void
+SScreenSaverNotifyEvent (from, to)
+    xScreenSaverNotifyEvent *from, *to;
+{
+    to->type = from->type;
+    to->state = from->state;
+    cpswaps (from->sequenceNumber, to->sequenceNumber);
+    cpswapl (from->timestamp, to->timestamp);    
+    cpswapl (from->root, to->root);    
+    cpswapl (from->window, to->window);    
+    to->kind = from->kind;
+    to->forced = from->forced;
+}
+
+static void
+UninstallSaverColormap (pScreen)
+    ScreenPtr  pScreen;
+{
+    SetupScreen(pScreen);
+    ColormapPtr                        pCmap;
+
+    if (pPriv && pPriv->installedMap != None)
+    {
+       pCmap = (ColormapPtr) LookupIDByType (pPriv->installedMap, RT_COLORMAP);
+       if (pCmap)
+           (*pCmap->pScreen->UninstallColormap) (pCmap);
+       pPriv->installedMap = None;
+       CheckScreenPrivate (pScreen);
+    }
+}
+
+static Bool
+CreateSaverWindow (pScreen)
+    ScreenPtr  pScreen;
+{
+    SetupScreen (pScreen);
+    ScreenSaverStuffPtr                pSaver;
+    ScreenSaverAttrPtr         pAttr;
+    WindowPtr                  pWin;
+    int                                result;
+    unsigned long              mask;
+    extern int                 GrabInProgress;
+    Colormap                   *installedMaps;
+    int                                numInstalled;
+    int                                i;
+    Colormap                   wantMap;
+    ColormapPtr                        pCmap;
+
+    pSaver = &savedScreenInfo[pScreen->myNum];
+    if (pSaver->pWindow)
+    {
+       pSaver->pWindow = NullWindow;
+       FreeResource (pSaver->wid, RT_NONE);
+       if (pPriv)
+       {
+           UninstallSaverColormap (pScreen);
+           pPriv->hasWindow = FALSE;
+           CheckScreenPrivate (pScreen);
+       }
+    }
+
+    if (!pPriv || !(pAttr = pPriv->attr))
+       return FALSE;
+
+    pPriv->installedMap = None;
+
+    if (GrabInProgress && GrabInProgress != pAttr->client->index)
+       return FALSE;
+
+    pWin = CreateWindow (pSaver->wid, WindowTable[pScreen->myNum],
+                        pAttr->x, pAttr->y, pAttr->width, pAttr->height,
+                        pAttr->borderWidth, pAttr->class, 
+                        pAttr->mask, (XID *)pAttr->values, 
+                        pAttr->depth, serverClient, pAttr->visual, 
+                        &result);
+    if (!pWin)
+       return FALSE;
+
+    if (!AddResource(pWin->drawable.id, RT_WINDOW, pWin))
+       return FALSE;
+
+    mask = 0;
+    if (pAttr->pBackgroundPixmap)
+    {
+       pWin->backgroundState = BackgroundPixmap;
+       pWin->background.pixmap = pAttr->pBackgroundPixmap;
+       pAttr->pBackgroundPixmap->refcnt++;
+       mask |= CWBackPixmap;
+    }
+    if (pAttr->pBorderPixmap)
+    {
+       pWin->borderIsPixel = FALSE;
+       pWin->border.pixmap = pAttr->pBorderPixmap;
+       pAttr->pBorderPixmap->refcnt++;
+       mask |= CWBorderPixmap;
+    }
+    if (pAttr->pCursor)
+    {
+       if (!pWin->optional)
+           if (!MakeWindowOptional (pWin))
+           {
+               FreeResource (pWin->drawable.id, RT_NONE);
+               return FALSE;
+           }
+       if (pWin->optional->cursor)
+           FreeCursor (pWin->optional->cursor, (Cursor)0);
+       pWin->optional->cursor = pAttr->pCursor;
+       pAttr->pCursor->refcnt++;
+       pWin->cursorIsNone = FALSE;
+       CheckWindowOptionalNeed (pWin);
+       mask |= CWCursor;
+    }
+    if (mask)
+       (*pScreen->ChangeWindowAttributes) (pWin, mask);
+
+    if (pAttr->colormap != None)
+       (void) ChangeWindowAttributes (pWin, CWColormap, &pAttr->colormap,
+                                      serverClient);
+
+    MapWindow (pWin, serverClient);
+
+    pPriv->hasWindow = TRUE;
+    pSaver->pWindow = pWin;
+
+    /* check and install our own colormap if it isn't installed now */
+    wantMap = wColormap (pWin);
+    if (wantMap == None)
+       return TRUE;
+    installedMaps = (Colormap *) ALLOCATE_LOCAL (pScreen->maxInstalledCmaps *
+                                                sizeof (Colormap));
+    numInstalled = (*pWin->drawable.pScreen->ListInstalledColormaps)
+                                                   (pScreen, installedMaps);
+    for (i = 0; i < numInstalled; i++) 
+       if (installedMaps[i] == wantMap)
+           break;
+
+    DEALLOCATE_LOCAL ((char *) installedMaps);
+
+    if (i < numInstalled)
+       return TRUE;
+
+    pCmap = (ColormapPtr) LookupIDByType (wantMap, RT_COLORMAP);
+    if (!pCmap)
+       return TRUE;
+
+    pPriv->installedMap = wantMap;
+
+    (*pCmap->pScreen->InstallColormap) (pCmap);
+
+    return TRUE;
+}
+
+static Bool
+DestroySaverWindow (pScreen)
+    ScreenPtr  pScreen;
+{
+    SetupScreen(pScreen);
+    ScreenSaverStuffPtr                pSaver;
+
+    if (!pPriv || !pPriv->hasWindow)
+       return FALSE;
+
+    pSaver = &savedScreenInfo[pScreen->myNum];
+    if (pSaver->pWindow)
+    {
+       pSaver->pWindow = NullWindow;
+       FreeResource (pSaver->wid, RT_NONE);
+    }
+    pPriv->hasWindow = FALSE;
+    CheckScreenPrivate (pScreen);
+    UninstallSaverColormap (pScreen);
+    return TRUE;
+}
+
+static Bool
+ScreenSaverHandle (pScreen, xstate, force)
+    ScreenPtr  pScreen;
+    int                xstate;
+    Bool       force;
+{
+    int                                state;
+    Bool                       ret = FALSE;
+    ScreenSaverScreenPrivatePtr        pPriv;
+
+    switch (xstate)
+    {
+    case SCREEN_SAVER_ON:      
+       state = ScreenSaverOn;
+       ret = CreateSaverWindow (pScreen);
+       break;
+    case SCREEN_SAVER_OFF:     
+       state = ScreenSaverOff;
+       ret = DestroySaverWindow (pScreen);
+       break;
+    case SCREEN_SAVER_CYCLE:   
+       state = ScreenSaverCycle;
+       pPriv = GetScreenPrivate (pScreen);
+       if (pPriv && pPriv->hasWindow)
+           ret = TRUE;
+       
+    }
+    SendScreenSaverNotify (pScreen, state, force);
+    return ret;
+}
+
+static int
+ProcScreenSaverQueryVersion (client)
+    register ClientPtr client;
+{
+    xScreenSaverQueryVersionReply      rep;
+    register int               n;
+
+    REQUEST_SIZE_MATCH (xScreenSaverQueryVersionReq);
+    rep.type = X_Reply;
+    rep.length = 0;
+    rep.sequenceNumber = client->sequence;
+    rep.majorVersion = ScreenSaverMajorVersion;
+    rep.minorVersion = ScreenSaverMinorVersion;
+    if (client->swapped) {
+       swaps(&rep.sequenceNumber, n);
+       swapl(&rep.length, n);
+    }
+    WriteToClient(client, sizeof (xScreenSaverQueryVersionReply), (char *)&rep);
+    return (client->noClientException);
+}
+
+int
+ProcScreenSaverQueryInfo (client)
+    register ClientPtr client;
+{
+    REQUEST(xScreenSaverQueryInfoReq);
+    xScreenSaverQueryInfoReply rep;
+    register int               n;
+    ScreenSaverStuffPtr                pSaver;
+    DrawablePtr                        pDraw;
+    CARD32                     lastInput;
+    ScreenSaverScreenPrivatePtr        pPriv;
+
+    REQUEST_SIZE_MATCH (xScreenSaverQueryInfoReq);
+    pDraw = (DrawablePtr) LookupDrawable (stuff->drawable, client);
+    if (!pDraw)
+       return BadDrawable;
+
+    pSaver = &savedScreenInfo[pDraw->pScreen->myNum];
+    pPriv = GetScreenPrivate (pDraw->pScreen);
+
+    UpdateCurrentTime ();
+    lastInput = GetTimeInMillis() - lastDeviceEventTime.milliseconds;
+
+    rep.type = X_Reply;
+    rep.length = 0;
+    rep.sequenceNumber = client->sequence;
+    rep.window = pSaver->wid;
+    if (screenIsSaved != SCREEN_SAVER_OFF)
+    {
+       rep.state = ScreenSaverOn;
+       if (ScreenSaverTime)
+           rep.tilOrSince = lastInput - ScreenSaverTime;
+       else
+           rep.tilOrSince = 0;
+    }
+    else
+    {
+       if (ScreenSaverTime)
+       {
+           rep.state = ScreenSaverOff;
+           if (ScreenSaverTime < lastInput)
+               rep.tilOrSince = 0;
+           else
+               rep.tilOrSince = ScreenSaverTime - lastInput;
+       }
+       else
+       {
+           rep.state = ScreenSaverDisabled;
+           rep.tilOrSince = 0;
+       }
+    }
+    rep.idle = lastInput;
+    rep.eventMask = getEventMask (pDraw->pScreen, client);
+    if (pPriv && pPriv->attr)
+       rep.kind = ScreenSaverExternal;
+    else if (ScreenSaverBlanking != DontPreferBlanking)
+       rep.kind = ScreenSaverBlanked;
+    else
+       rep.kind = ScreenSaverInternal;
+    if (client->swapped)
+    {
+       swaps (&rep.sequenceNumber, n);
+       swapl (&rep.length, n);
+       swapl (&rep.window, n);
+       swapl (&rep.tilOrSince, n);
+       swapl (&rep.idle, n);
+       swapl (&rep.eventMask, n);
+    }
+    WriteToClient(client, sizeof (xScreenSaverQueryInfoReply), (char *)&rep);
+    return (client->noClientException);
+}
+
+static int
+ProcScreenSaverSelectInput (client)
+    register ClientPtr client;
+{
+    REQUEST(xScreenSaverSelectInputReq);
+    DrawablePtr                        pDraw;
+
+    REQUEST_SIZE_MATCH (xScreenSaverSelectInputReq);
+    pDraw = (DrawablePtr) LookupDrawable (stuff->drawable, client);
+    if (!pDraw)
+       return BadDrawable;
+    if (!setEventMask (pDraw->pScreen, client, stuff->eventMask))
+       return BadAlloc;
+    return Success;
+}
+
+static int
+ProcScreenSaverSetAttributes (client)
+    register ClientPtr client;
+{
+    REQUEST(xScreenSaverSetAttributesReq);
+    DrawablePtr                        pDraw;
+    WindowPtr                  pParent;
+    ScreenPtr                  pScreen;
+    ScreenSaverScreenPrivatePtr pPriv = 0;
+    ScreenSaverAttrPtr         pAttr = 0;
+    int                                ret;
+    int                                len;
+    int                                class, bw, depth;
+    unsigned long              visual;
+    int                                idepth, ivisual;
+    Bool                       fOK;
+    DepthPtr                   pDepth;
+    WindowOptPtr               ancwopt;
+    unsigned long              *pVlist;
+    unsigned long              *values = 0;
+    int                                valuei;
+    unsigned long              tmask, imask;
+    unsigned long              val;
+    Pixmap                     pixID;
+    PixmapPtr                  pPixmap;
+    Cursor                     cursorID;
+    CursorPtr                  pCursor;
+    Colormap                   cmap;
+    ColormapPtr                        pCmap;
+
+    REQUEST_AT_LEAST_SIZE (xScreenSaverSetAttributesReq);
+    pDraw = (DrawablePtr) LookupDrawable (stuff->drawable, client);
+    if (!pDraw)
+       return BadDrawable;
+    pScreen = pDraw->pScreen;
+    pParent = WindowTable[pScreen->myNum];
+
+    len = stuff->length -  (sizeof(xScreenSaverSetAttributesReq) >> 2);
+    if (Ones(stuff->mask) != len)
+        return BadLength;
+    if (!stuff->width || !stuff->height)
+    {
+       client->errorValue = 0;
+        return BadValue;
+    }
+    switch (class = stuff->c_class) 
+    {
+    case CopyFromParent:
+    case InputOnly:
+    case InputOutput:
+       break;
+    default:
+       client->errorValue = class;
+       return BadValue;
+    }
+    bw = stuff->borderWidth;
+    depth = stuff->depth;
+    visual = stuff->visualID;
+
+    /* copied directly from CreateWindow */
+
+    if (class == CopyFromParent)
+       class = pParent->drawable.class;
+
+    if ((class != InputOutput) && (class != InputOnly))
+    {
+       client->errorValue = class;
+       return BadValue;
+    }
+
+    if ((class != InputOnly) && (pParent->drawable.class == InputOnly))
+        return BadMatch;
+
+    if ((class == InputOnly) && ((bw != 0) || (depth != 0)))
+        return BadMatch;
+
+    if ((class == InputOutput) && (depth == 0))
+        depth = pParent->drawable.depth;
+    ancwopt = pParent->optional;
+    if (!ancwopt)
+       ancwopt = FindWindowWithOptional(pParent)->optional;
+    if (visual == CopyFromParent)
+       visual = ancwopt->visual;
+
+    /* Find out if the depth and visual are acceptable for this Screen */
+    if ((visual != ancwopt->visual) || (depth != pParent->drawable.depth))
+    {
+       fOK = FALSE;
+       for(idepth = 0; idepth < pScreen->numDepths; idepth++)
+       {
+           pDepth = (DepthPtr) &pScreen->allowedDepths[idepth];
+           if ((depth == pDepth->depth) || (depth == 0))
+           {
+               for (ivisual = 0; ivisual < pDepth->numVids; ivisual++)
+               {
+                   if (visual == pDepth->vids[ivisual])
+                   {
+                       fOK = TRUE;
+                       break;
+                   }
+               }
+           }
+       }
+       if (fOK == FALSE)
+           return BadMatch;
+    }
+
+    if (((stuff->mask & (CWBorderPixmap | CWBorderPixel)) == 0) &&
+       (class != InputOnly) &&
+       (depth != pParent->drawable.depth))
+    {
+        return BadMatch;
+    }
+
+    if (((stuff->mask & CWColormap) == 0) &&
+       (class != InputOnly) &&
+       ((visual != ancwopt->visual) || (ancwopt->colormap == None)))
+    {
+       return BadMatch;
+    }
+
+    /* end of errors from CreateWindow */
+
+    pPriv = GetScreenPrivate (pScreen);
+    if (pPriv && pPriv->attr)
+    {
+       if (pPriv->attr->client != client)
+           return BadAccess;
+    }
+    if (!pPriv)
+    {
+       pPriv = MakeScreenPrivate (pScreen);
+       if (!pPriv)
+           return FALSE;
+    }
+    pAttr = New (ScreenSaverAttrRec);
+    if (!pAttr)
+    {
+       ret = BadAlloc;
+       goto bail;
+    }
+    /* over allocate for override redirect */
+    values = (unsigned long *) xalloc ((len + 1) * sizeof (unsigned long));
+    if (!values)
+    {
+       ret = BadAlloc;
+       goto bail;
+    }
+    valuei = 0;
+    pAttr->screen = pScreen;
+    pAttr->client = client;
+    pAttr->x = stuff->x;
+    pAttr->y = stuff->y;
+    pAttr->width = stuff->width;
+    pAttr->height = stuff->height;
+    pAttr->borderWidth = stuff->borderWidth;
+    pAttr->class = stuff->c_class;
+    pAttr->depth = depth;
+    pAttr->visual = visual;
+    pAttr->colormap = None;
+    pAttr->pCursor = NullCursor;
+    pAttr->pBackgroundPixmap = NullPixmap;
+    pAttr->pBorderPixmap = NullPixmap;
+    pAttr->values = values;
+    /*
+     * go through the mask, checking the values,
+     * looking up pixmaps and cursors and hold a reference
+     * to them.
+     */
+    pAttr->mask = tmask = stuff->mask | CWOverrideRedirect;
+    pVlist = (unsigned long *) (stuff + 1);
+    while (tmask) {
+       imask = lowbit (tmask);
+       tmask &= ~imask;
+       switch (imask)
+        {
+       case CWBackPixmap:
+           pixID = (Pixmap )*pVlist;
+           if (pixID == None)
+           {
+               *values++ = None;
+           }
+           else if (pixID == ParentRelative)
+           {
+               if (depth != pParent->drawable.depth)
+               {
+                   ret = BadMatch;
+                   goto PatchUp;
+               }
+               *values++ = ParentRelative;
+           }
+            else
+           {   
+                pPixmap = (PixmapPtr)LookupIDByType(pixID, RT_PIXMAP);
+                if (pPixmap != (PixmapPtr) NULL)
+               {
+                    if  ((pPixmap->drawable.depth != depth) ||
+                        (pPixmap->drawable.pScreen != pScreen))
+                   {
+                        ret = BadMatch;
+                       goto PatchUp;
+                   }
+                   pAttr->pBackgroundPixmap = pPixmap;
+                   pPixmap->refcnt++;
+                   pAttr->mask &= ~CWBackPixmap;
+               }
+               else
+               {
+                   ret = BadPixmap;
+                   client->errorValue = pixID;
+                   goto PatchUp;
+               }
+           }
+           break;
+       case CWBackPixel:
+           *values++ = (CARD32) *pVlist;
+           break;
+       case CWBorderPixmap:
+           pixID = (Pixmap ) *pVlist;
+           if (pixID == CopyFromParent)
+           {
+               if (depth != pParent->drawable.depth)
+               {
+                   ret = BadMatch;
+                   goto PatchUp;
+               }
+               *values++ = CopyFromParent;
+           }
+           else
+           {   
+               pPixmap = (PixmapPtr)LookupIDByType(pixID, RT_PIXMAP);
+               if (pPixmap)
+               {
+                    if  ((pPixmap->drawable.depth != depth) ||
+                        (pPixmap->drawable.pScreen != pScreen))
+                   {
+                       ret = BadMatch;
+                       goto PatchUp;
+                   }
+                   pAttr->pBorderPixmap = pPixmap;
+                   pPixmap->refcnt++;
+                   pAttr->mask &= ~CWBorderPixmap;
+               }
+               else
+               {
+                   ret = BadPixmap;
+                   client->errorValue = pixID;
+                   goto PatchUp;
+               }
+           }
+           break;
+       case CWBorderPixel:
+            *values++ = (CARD32) *pVlist;
+            break;
+       case CWBitGravity:
+           val = (CARD8 )*pVlist;
+           if (val > StaticGravity)
+           {
+               ret = BadValue;
+               client->errorValue = val;
+               goto PatchUp;
+           }
+           *values++ = val;
+           break;
+       case CWWinGravity:
+           val = (CARD8 )*pVlist;
+           if (val > StaticGravity)
+           {
+               ret = BadValue;
+               client->errorValue = val;
+               goto PatchUp;
+           }
+           *values++ = val;
+           break;
+       case CWBackingStore:
+           val = (CARD8 )*pVlist;
+           if ((val != NotUseful) && (val != WhenMapped) && (val != Always))
+           {
+               ret = BadValue;
+               client->errorValue = val;
+               goto PatchUp;
+           }
+           *values++ = val;
+           break;
+       case CWBackingPlanes:
+           *values++ = (CARD32) *pVlist;
+           break;
+       case CWBackingPixel:
+           *values++ = (CARD32) *pVlist;
+           break;
+       case CWSaveUnder:
+           val = (BOOL) *pVlist;
+           if ((val != xTrue) && (val != xFalse))
+           {
+               ret = BadValue;
+               client->errorValue = val;
+               goto PatchUp;
+           }
+           *values++ = val;
+           break;
+       case CWEventMask:
+           *values++ = (CARD32) *pVlist;
+           break;
+       case CWDontPropagate:
+           *values++ = (CARD32) *pVlist;
+           break;
+       case CWOverrideRedirect:
+           if (!(stuff->mask & CWOverrideRedirect))
+               pVlist--;
+           else
+           {
+               val = (BOOL ) *pVlist;
+               if ((val != xTrue) && (val != xFalse))
+               {
+                   ret = BadValue;
+                   client->errorValue = val;
+                   goto PatchUp;
+               }
+           }
+           *values++ = xTrue;
+           break;
+       case CWColormap:
+           cmap = (Colormap) *pVlist;
+           pCmap = (ColormapPtr)LookupIDByType(cmap, RT_COLORMAP);
+           if (!pCmap)
+           {
+               ret = BadColor;
+               client->errorValue = cmap;
+               goto PatchUp;
+           }
+           if (pCmap->pVisual->vid != visual || pCmap->pScreen != pScreen)
+           {
+               ret = BadMatch;
+               goto PatchUp;
+           }
+           pAttr->colormap = cmap;
+           pAttr->mask &= ~CWColormap;
+           break;
+       case CWCursor:
+           cursorID = (Cursor ) *pVlist;
+           if ( cursorID == None)
+           {
+               *values++ = None;
+           }
+           else
+           {
+               pCursor = (CursorPtr)LookupIDByType(cursorID, RT_CURSOR);
+               if (!pCursor)
+               {
+                   ret = BadCursor;
+                   client->errorValue = cursorID;
+                   goto PatchUp;
+               }
+               pCursor->refcnt++;
+               pAttr->pCursor = pCursor;
+               pAttr->mask &= ~CWCursor;
+           }
+           break;
+        default:
+           ret = BadValue;
+           client->errorValue = stuff->mask;
+           goto PatchUp;
+       }
+       pVlist++;
+    }
+    if (pPriv->attr)
+       FreeScreenAttr (pPriv->attr);
+    pPriv->attr = pAttr;
+    pAttr->resource = FakeClientID (client->index);
+    if (!AddResource (pAttr->resource, AttrType, (pointer) pAttr))
+       return BadAlloc;
+    return Success;
+PatchUp:
+    FreeAttrs (pAttr);
+bail:
+    CheckScreenPrivate (pScreen);
+    xfree (pAttr);
+    xfree (values);
+    return ret;
+}
+
+static int
+ProcScreenSaverUnsetAttributes (client)
+    register ClientPtr client;
+{
+    REQUEST(xScreenSaverSetAttributesReq);
+    DrawablePtr                        pDraw;
+    ScreenSaverScreenPrivatePtr        pPriv;
+
+    REQUEST_SIZE_MATCH (xScreenSaverUnsetAttributesReq);
+    pDraw = (DrawablePtr) LookupDrawable (stuff->drawable, client);
+    if (!pDraw)
+       return BadDrawable;
+    pPriv = GetScreenPrivate (pDraw->pScreen);
+    if (pPriv && pPriv->attr && pPriv->attr->client == client)
+    {
+       FreeScreenAttr (pPriv->attr);
+       pPriv->attr = NULL;
+       CheckScreenPrivate (pDraw->pScreen);
+    }
+    return Success;
+}
+
+static DISPATCH_PROC((*NormalVector[])) = {
+    ProcScreenSaverQueryVersion,
+    ProcScreenSaverQueryInfo,
+    ProcScreenSaverSelectInput,
+    ProcScreenSaverSetAttributes,
+    ProcScreenSaverUnsetAttributes,
+};
+
+#define NUM_REQUESTS   ((sizeof NormalVector) / (sizeof NormalVector[0]))
+
+static int
+ProcScreenSaverDispatch (client)
+    ClientPtr  client;
+{
+    REQUEST(xReq);
+
+    if (stuff->data < NUM_REQUESTS)
+       return (*NormalVector[stuff->data])(client);
+    return BadRequest;
+}
+
+static int
+SProcScreenSaverQueryVersion (client)
+    ClientPtr  client;
+{
+    REQUEST(xScreenSaverQueryVersionReq);
+    int            n;
+
+    swaps (&stuff->length, n);
+    REQUEST_SIZE_MATCH(xScreenSaverQueryVersionReq);
+    return ProcScreenSaverQueryVersion (client);
+}
+
+static int
+SProcScreenSaverQueryInfo (client)
+    ClientPtr  client;
+{
+    REQUEST(xScreenSaverQueryInfoReq);
+    int            n;
+
+    swaps (&stuff->length, n);
+    REQUEST_SIZE_MATCH(xScreenSaverQueryInfoReq);
+    swapl (&stuff->drawable, n);
+    return ProcScreenSaverQueryInfo (client);
+}
+
+static int
+SProcScreenSaverSelectInput (client)
+    ClientPtr  client;
+{
+    REQUEST(xScreenSaverSelectInputReq);
+    int            n;
+
+    swaps (&stuff->length, n);
+    REQUEST_SIZE_MATCH(xScreenSaverSelectInputReq);
+    swapl (&stuff->drawable, n);
+    swapl (&stuff->eventMask, n);
+    return ProcScreenSaverSelectInput (client);
+}
+
+static int
+SProcScreenSaverSetAttributes (client)
+    ClientPtr  client;
+{
+    REQUEST(xScreenSaverSetAttributesReq);
+    int            n;
+
+    swaps (&stuff->length, n);
+    REQUEST_AT_LEAST_SIZE(xScreenSaverSetAttributesReq);
+    swapl (&stuff->drawable, n);
+    swaps (&stuff->x, n);
+    swaps (&stuff->y, n);
+    swaps (&stuff->width, n);
+    swaps (&stuff->height, n);
+    swaps (&stuff->borderWidth, n);
+    swapl (&stuff->visualID, n);
+    swapl (&stuff->mask, n);
+    SwapRestL(stuff);
+    return ProcScreenSaverSetAttributes (client);
+}
+
+static int
+SProcScreenSaverUnsetAttributes (client)
+    ClientPtr  client;
+{
+    REQUEST(xScreenSaverUnsetAttributesReq);
+    int            n;
+
+    swaps (&stuff->length, n);
+    REQUEST_SIZE_MATCH(xScreenSaverUnsetAttributesReq);
+    swapl (&stuff->drawable, n);
+    return ProcScreenSaverUnsetAttributes (client);
+}
+
+static DISPATCH_PROC((*SwappedVector[])) = {
+    SProcScreenSaverQueryVersion,
+    SProcScreenSaverQueryInfo,
+    SProcScreenSaverSelectInput,
+    SProcScreenSaverSetAttributes,
+    SProcScreenSaverUnsetAttributes,
+};
+
+static int
+SProcScreenSaverDispatch (client)
+    ClientPtr  client;
+{
+    REQUEST(xReq);
+
+    if (stuff->data < NUM_REQUESTS)
+       return (*SwappedVector[stuff->data])(client);
+    return BadRequest;
+}
diff --git a/Xserver/programs/Xserver/Xext/security.c b/Xserver/programs/Xserver/Xext/security.c
new file mode 100644 (file)
index 0000000..f0153c0
--- /dev/null
@@ -0,0 +1,1992 @@
+/* $XConsortium: security.c /main/13 1996/12/15 21:24:27 rws $ */
+/*
+Copyright (c) 1996 X Consortium, Inc.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR
+OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OF
+OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall
+not be used in advertising or otherwise to promote the sale, use or
+other dealings in this Software without prior written authorization
+from the X Consortium.
+*/
+/* $XFree86: xc/programs/Xserver/Xext/security.c,v 1.2 1997/01/27 06:57:17 dawes Exp $ */
+
+#include "dixstruct.h"
+#include "extnsionst.h"
+#include "windowstr.h"
+#include "inputstr.h"
+#include "gcstruct.h"
+#include "colormapst.h"
+#include "propertyst.h"
+#define _SECURITY_SERVER
+#include "securstr.h"
+#include <assert.h>
+#include <stdarg.h>
+#ifdef LBX
+#define _XLBX_SERVER_
+#include "XLbx.h"
+extern unsigned char LbxReqCode;
+#endif
+#ifdef XAPPGROUP
+#include "Xagsrv.h"
+#endif
+#include <stdio.h>  /* for file reading operations */
+#include "Xatom.h"  /* for XA_STRING */
+
+#ifndef DEFAULTPOLICYFILE
+# define DEFAULTPOLICYFILE NULL
+#endif
+#ifdef WIN32
+#include <X11/Xos.h>
+#undef index
+#endif
+
+static int SecurityErrorBase;  /* first Security error number */
+static int SecurityEventBase;  /* first Security event number */
+
+CallbackListPtr SecurityValidateGroupCallback = NULL;  /* see security.h */
+
+RESTYPE SecurityAuthorizationResType; /* resource type for authorizations */
+
+static RESTYPE RTEventClient;
+
+/* Proc vectors for untrusted clients, swapped and unswapped versions.
+ * These are the same as the normal proc vectors except that extensions
+ * that haven't declared themselves secure will have ProcBadRequest plugged
+ * in for their major opcode dispatcher.  This prevents untrusted clients
+ * from guessing extension major opcodes and using the extension even though
+ * the extension can't be listed or queried.
+ */
+int (*UntrustedProcVector[256])(
+#if NeedNestedPrototypes
+    ClientPtr /*client*/
+#endif
+);
+int (*SwappedUntrustedProcVector[256])(
+#if NeedNestedPrototypes
+    ClientPtr /*client*/
+#endif
+);
+
+extern int ProcBadRequest();
+
+
+/* SecurityAudit
+ *
+ * Arguments:
+ *     format is the formatting string to be used to interpret the
+ *       remaining arguments.
+ *
+ * Returns: nothing.
+ *
+ * Side Effects:
+ *     Writes the message to the log file if security logging is on.
+ */
+
+void
+SecurityAudit(char *format, ...)
+{
+    va_list args;
+
+    if (auditTrailLevel < SECURITY_AUDIT_LEVEL)
+       return;
+    AuditPrefix(format);
+    va_start(args, format);
+    VErrorF(format, args);
+    va_end(args);
+} /* SecurityAudit */
+
+#define rClient(obj) (clients[CLIENT_ID((obj)->resource)])
+
+/* SecurityDeleteAuthorization
+ *
+ * Arguments:
+ *     value is the authorization to delete.
+ *     id is its resource ID.
+ *
+ * Returns: Success.
+ *
+ * Side Effects:
+ *     Frees everything associated with the authorization.
+ */
+
+static int
+SecurityDeleteAuthorization(value, id)
+    pointer value;
+    XID id;
+{
+    SecurityAuthorizationPtr pAuth = (SecurityAuthorizationPtr)value;
+    unsigned short name_len, data_len;
+    char *name, *data;
+    int status;
+    int i;
+    OtherClientsPtr pEventClient;
+
+    /* Remove the auth using the os layer auth manager */
+
+    status = AuthorizationFromID(pAuth->id, &name_len, &name,
+                                &data_len, &data);
+    assert(status);
+    status = RemoveAuthorization(name_len, name, data_len, data);
+    assert(status);
+
+    /* free the auth timer if there is one */
+
+    if (pAuth->timer) TimerFree(pAuth->timer);
+
+    /* send revoke events */
+
+    while (pEventClient = pAuth->eventClients)
+    {
+       /* send revocation event event */
+       ClientPtr client = rClient(pEventClient);
+
+       if (!client->clientGone)
+       {
+           xSecurityAuthorizationRevokedEvent are;
+           are.type = SecurityEventBase + XSecurityAuthorizationRevoked;
+           are.sequenceNumber = client->sequence;
+           are.authId = pAuth->id;
+           WriteEventsToClient(client, 1, (xEvent *)&are);
+       }
+       FreeResource(pEventClient->resource, RT_NONE);
+    }
+
+    /* kill all clients using this auth */
+
+    for (i = 1; i<currentMaxClients; i++)
+    {
+       if (clients[i] && (clients[i]->authId == pAuth->id))
+           CloseDownClient(clients[i]);
+    }
+
+    SecurityAudit("revoked authorization ID %d\n", pAuth->id);
+    xfree(pAuth);
+    return Success;
+
+} /* SecurityDeleteAuthorization */
+
+
+/* resource delete function for RTEventClient */
+static int
+SecurityDeleteAuthorizationEventClient(value, id)
+    pointer value;
+    XID id;
+{
+    OtherClientsPtr pEventClient, prev = NULL;
+    SecurityAuthorizationPtr pAuth = (SecurityAuthorizationPtr)value;
+
+    for (pEventClient = pAuth->eventClients;
+        pEventClient;
+        pEventClient = pEventClient->next)
+    {
+       if (pEventClient->resource == id)
+       {
+           if (prev)
+               prev->next = pEventClient->next;
+           else
+               pAuth->eventClients = pEventClient->next;
+           xfree(pEventClient);
+           return(Success);
+       }
+       prev = pEventClient;
+    }
+    /*NOTREACHED*/
+    return -1; /* make compiler happy */
+} /* SecurityDeleteAuthorizationEventClient */
+
+
+/* SecurityComputeAuthorizationTimeout
+ *
+ * Arguments:
+ *     pAuth is the authorization for which we are computing the timeout
+ *     seconds is the number of seconds we want to wait
+ *
+ * Returns:
+ *     the number of milliseconds that the auth timer should be set to
+ *
+ * Side Effects:
+ *     Sets pAuth->secondsRemaining to any "overflow" amount of time
+ *     that didn't fit in 32 bits worth of milliseconds
+ */
+
+static CARD32
+SecurityComputeAuthorizationTimeout(pAuth, seconds)
+    SecurityAuthorizationPtr pAuth;
+    unsigned int seconds;
+{
+    /* maxSecs is the number of full seconds that can be expressed in
+     * 32 bits worth of milliseconds
+     */
+    CARD32 maxSecs = (CARD32)(~0) / (CARD32)MILLI_PER_SECOND;
+
+    if (seconds > maxSecs)
+    { /* only come here if we want to wait more than 49 days */
+       pAuth->secondsRemaining = seconds - maxSecs;
+       return maxSecs * MILLI_PER_SECOND;
+    }
+    else
+    { /* by far the common case */
+       pAuth->secondsRemaining = 0;
+       return seconds * MILLI_PER_SECOND;
+    }
+} /* SecurityStartAuthorizationTimer */
+
+/* SecurityAuthorizationExpired
+ *
+ * This function is passed as an argument to TimerSet and gets called from
+ * the timer manager in the os layer when its time is up.
+ *
+ * Arguments:
+ *     timer is the timer for this authorization.
+ *     time is the current time.
+ *     pval is the authorization whose time is up.
+ *
+ * Returns:
+ *     A new time delay in milliseconds if the timer should wait some
+ *     more, else zero.
+ *
+ * Side Effects:
+ *     Frees the authorization resource if the timeout period is really
+ *     over, otherwise recomputes pAuth->secondsRemaining.
+ */
+
+static CARD32
+SecurityAuthorizationExpired(timer, time, pval)
+    OsTimerPtr timer;
+    CARD32 time;
+    pointer pval;
+{
+    SecurityAuthorizationPtr pAuth = (SecurityAuthorizationPtr)pval;
+
+    assert(pAuth->timer == timer);
+
+    if (pAuth->secondsRemaining)
+    {
+       return SecurityComputeAuthorizationTimeout(pAuth,
+                                                  pAuth->secondsRemaining);
+    }
+    else
+    {
+       FreeResource(pAuth->id, RT_NONE);
+       return 0;
+    }
+} /* SecurityAuthorizationExpired */
+
+/* SecurityStartAuthorizationTimer
+ *
+ * Arguments:
+ *     pAuth is the authorization whose timer should be started.
+ *
+ * Returns: nothing.
+ *
+ * Side Effects:
+ *     A timer is started, set to expire after the timeout period for
+ *     this authorization.  When it expires, the function
+ *     SecurityAuthorizationExpired will be called.
+ */
+
+static void
+SecurityStartAuthorizationTimer(pAuth)
+    SecurityAuthorizationPtr pAuth;
+{
+    pAuth->timer = TimerSet(pAuth->timer, 0,
+       SecurityComputeAuthorizationTimeout(pAuth, pAuth->timeout),
+                           SecurityAuthorizationExpired, pAuth);
+} /* SecurityStartAuthorizationTimer */
+
+
+/* Proc functions all take a client argument, execute the request in
+ * client->requestBuffer, and return a protocol error status.
+ */
+
+static int
+ProcSecurityQueryVersion(client)
+    ClientPtr client;
+{
+    REQUEST(xSecurityQueryVersionReq);
+    xSecurityQueryVersionReply         rep;
+
+    /* paranoia: this "can't happen" because this extension is hidden
+     * from untrusted clients, but just in case...
+     */
+    if (client->trustLevel != XSecurityClientTrusted)
+       return BadRequest;
+
+    REQUEST_SIZE_MATCH(xSecurityQueryVersionReq);
+    rep.type           = X_Reply;
+    rep.sequenceNumber         = client->sequence;
+    rep.length                 = 0;
+    rep.majorVersion   = SECURITY_MAJOR_VERSION;
+    rep.minorVersion   = SECURITY_MINOR_VERSION;
+    if(client->swapped)
+    {
+       register char n;
+       swaps(&rep.sequenceNumber, n);
+       swaps(&rep.majorVersion, n);
+       swaps(&rep.minorVersion, n);
+    }
+    (void)WriteToClient(client, SIZEOF(xSecurityQueryVersionReply),
+                       (char *)&rep);
+    return (client->noClientException);
+} /* ProcSecurityQueryVersion */
+
+
+static int
+SecurityEventSelectForAuthorization(pAuth, client, mask)
+    SecurityAuthorizationPtr pAuth;
+    ClientPtr client;
+    Mask mask;
+{
+    OtherClients *pEventClient;
+
+    for (pEventClient = pAuth->eventClients;
+        pEventClient;
+        pEventClient = pEventClient->next)
+    {
+       if (SameClient(pEventClient, client))
+       {
+           if (mask == 0)
+               FreeResource(pEventClient->resource, RT_NONE);
+           else
+               pEventClient->mask = mask;
+           return Success;
+       }
+    }
+    
+    pEventClient = (OtherClients *) xalloc(sizeof(OtherClients));
+    if (!pEventClient)
+       return BadAlloc;
+    pEventClient->mask = mask;
+    pEventClient->resource = FakeClientID(client->index);
+    pEventClient->next = pAuth->eventClients;
+    if (!AddResource(pEventClient->resource, RTEventClient,
+                    (pointer)pAuth))
+    {
+       xfree(pEventClient);
+       return BadAlloc;
+    }
+    pAuth->eventClients = pEventClient;
+
+    return Success;
+} /* SecurityEventSelectForAuthorization */
+
+
+static int
+ProcSecurityGenerateAuthorization(client)
+    ClientPtr client;
+{
+    REQUEST(xSecurityGenerateAuthorizationReq);
+    int len;                   /* request length in CARD32s*/
+    Bool removeAuth = FALSE;   /* if bailout, call RemoveAuthorization? */
+    SecurityAuthorizationPtr pAuth = NULL;  /* auth we are creating */
+    int err;                   /* error to return from this function */
+    int status;                        /* return value from os functions */
+    XID authId;                        /* authorization ID assigned by os layer */
+    xSecurityGenerateAuthorizationReply rep; /* reply struct */
+    unsigned int trustLevel;    /* trust level of new auth */
+    XID group;                 /* group of new auth */
+    CARD32 timeout;            /* timeout of new auth */
+    CARD32 *values;            /* list of supplied attributes */
+    char *protoname;           /* auth proto name sent in request */
+    char *protodata;           /* auth proto data sent in request */
+    unsigned int authdata_len;  /* # bytes of generated auth data */
+    char *pAuthdata;           /* generated auth data */
+    Mask eventMask;            /* what events on this auth does client want */
+
+    /* paranoia: this "can't happen" because this extension is hidden
+     * from untrusted clients, but just in case...
+     */
+    if (client->trustLevel != XSecurityClientTrusted)
+       return BadRequest;
+
+    /* check request length */
+
+    REQUEST_AT_LEAST_SIZE(xSecurityGenerateAuthorizationReq);
+    len = SIZEOF(xSecurityGenerateAuthorizationReq) >> 2;
+    len += (stuff->nbytesAuthProto + (unsigned)3) >> 2;
+    len += (stuff->nbytesAuthData  + (unsigned)3) >> 2;
+    values = ((CARD32 *)stuff) + len;
+    len += Ones(stuff->valueMask);
+    if (client->req_len != len)
+       return BadLength;
+
+    /* check valuemask */
+    if (stuff->valueMask & ~XSecurityAllAuthorizationAttributes)
+    {
+       client->errorValue = stuff->valueMask;
+       return BadValue;
+    }
+
+    /* check timeout */
+    timeout = 60;
+    if (stuff->valueMask & XSecurityTimeout)
+    {
+       timeout = *values++;
+    }
+
+    /* check trustLevel */
+    trustLevel = XSecurityClientUntrusted;
+    if (stuff->valueMask & XSecurityTrustLevel)
+    {
+       trustLevel = *values++;
+       if (trustLevel != XSecurityClientTrusted &&
+           trustLevel != XSecurityClientUntrusted)
+       {
+           client->errorValue = trustLevel;
+           return BadValue;
+       }
+    }
+
+    /* check group */
+    group = None;
+    if (stuff->valueMask & XSecurityGroup)
+    {
+       group = *values++;
+       if (SecurityValidateGroupCallback)
+       {
+           SecurityValidateGroupInfoRec vgi;
+           vgi.group = group;
+           vgi.valid = FALSE;
+           CallCallbacks(&SecurityValidateGroupCallback, (pointer)&vgi);
+
+           /* if nobody said they recognized it, it's an error */
+
+           if (!vgi.valid)
+           {
+               client->errorValue = group;
+               return BadValue;
+           }
+       }
+    }
+
+    /* check event mask */
+    eventMask = 0;
+    if (stuff->valueMask & XSecurityEventMask)
+    {
+       eventMask = *values++;
+       if (eventMask & ~XSecurityAllEventMasks)
+       {
+           client->errorValue = eventMask;
+           return BadValue;
+       }
+    }
+
+    protoname = (char *)&stuff[1];
+    protodata = protoname + ((stuff->nbytesAuthProto + (unsigned)3) >> 2);
+
+    /* call os layer to generate the authorization */
+
+    authId = GenerateAuthorization(stuff->nbytesAuthProto, protoname,
+                                  stuff->nbytesAuthData,  protodata,
+                                  &authdata_len, &pAuthdata);
+    if ((XID) ~0L == authId)
+    {
+       err = SecurityErrorBase + XSecurityBadAuthorizationProtocol;
+       goto bailout;
+    }
+
+    /* now that we've added the auth, remember to remove it if we have to
+     * abort the request for some reason (like allocation failure)
+     */
+    removeAuth = TRUE;
+
+    /* associate additional information with this auth ID */
+
+    pAuth = (SecurityAuthorizationPtr)xalloc(sizeof(SecurityAuthorizationRec));
+    if (!pAuth)
+    {
+       err = BadAlloc;
+       goto bailout;
+    }
+
+    /* fill in the auth fields */
+
+    pAuth->id = authId;
+    pAuth->timeout = timeout;
+    pAuth->group = group;
+    pAuth->trustLevel = trustLevel;
+    pAuth->refcnt = 0; /* the auth was just created; nobody's using it yet */
+    pAuth->secondsRemaining = 0;
+    pAuth->timer = NULL;
+    pAuth->eventClients = NULL;
+
+    /* handle event selection */
+    if (eventMask)
+    {
+       err = SecurityEventSelectForAuthorization(pAuth, client, eventMask);
+       if (err != Success)
+           goto bailout;
+    }
+
+    if (!AddResource(authId, SecurityAuthorizationResType, pAuth))
+    {
+       err = BadAlloc;
+       goto bailout;
+    }
+
+    /* start the timer ticking */
+
+    if (pAuth->timeout != 0)
+       SecurityStartAuthorizationTimer(pAuth);
+
+    /* tell client the auth id and data */
+
+    rep.type = X_Reply;
+    rep.length = (authdata_len + 3) >> 2;
+    rep.sequenceNumber = client->sequence;
+    rep.authId = authId;
+    rep.dataLength = authdata_len;
+
+    if (client->swapped)
+    {
+       register char n;
+       swapl(&rep.length, n);
+       swaps(&rep.sequenceNumber, n);
+       swapl(&rep.authId, n);
+       swaps(&rep.dataLength, n);
+    }
+
+    WriteToClient(client, SIZEOF(xSecurityGenerateAuthorizationReply),
+                 (char *)&rep);
+    WriteToClient(client, authdata_len, pAuthdata);
+
+    SecurityAudit("client %d generated authorization %d trust %d timeout %d group %d events %d\n",
+                 client->index, pAuth->id, pAuth->trustLevel, pAuth->timeout,
+                 pAuth->group, eventMask);
+
+    /* the request succeeded; don't call RemoveAuthorization or free pAuth */
+
+    removeAuth = FALSE;
+    pAuth = NULL;
+    err = client->noClientException;
+
+bailout:
+    if (removeAuth)
+       RemoveAuthorization(stuff->nbytesAuthProto, protoname,
+                           authdata_len, pAuthdata);
+    if (pAuth) xfree(pAuth);
+    return err;
+
+} /* ProcSecurityGenerateAuthorization */
+
+static int
+ProcSecurityRevokeAuthorization(client)
+    ClientPtr client;
+{
+    REQUEST(xSecurityRevokeAuthorizationReq);
+    SecurityAuthorizationPtr pAuth;
+
+    /* paranoia: this "can't happen" because this extension is hidden
+     * from untrusted clients, but just in case...
+     */
+    if (client->trustLevel != XSecurityClientTrusted)
+       return BadRequest;
+
+    REQUEST_SIZE_MATCH(xSecurityRevokeAuthorizationReq);
+
+    pAuth = (SecurityAuthorizationPtr)SecurityLookupIDByType(client,
+       stuff->authId, SecurityAuthorizationResType, SecurityDestroyAccess);
+    if (!pAuth)
+       return SecurityErrorBase + XSecurityBadAuthorization;
+
+    FreeResource(stuff->authId, RT_NONE);
+    return Success;
+} /* ProcSecurityRevokeAuthorization */
+
+
+static int
+ProcSecurityDispatch(client)
+    ClientPtr client;
+{
+    REQUEST(xReq);
+
+    switch (stuff->data)
+    {
+       case X_SecurityQueryVersion:
+           return ProcSecurityQueryVersion(client);
+       case X_SecurityGenerateAuthorization:
+           return ProcSecurityGenerateAuthorization(client);
+       case X_SecurityRevokeAuthorization:
+           return ProcSecurityRevokeAuthorization(client);
+       default:
+           return BadRequest;
+    }
+} /* ProcSecurityDispatch */
+
+static int
+SProcSecurityQueryVersion(client)
+    ClientPtr client;
+{
+    REQUEST(xSecurityQueryVersionReq);
+    register char      n;
+
+    swaps(&stuff->length, n);
+    REQUEST_SIZE_MATCH(xSecurityQueryVersionReq);
+    swaps(&stuff->majorVersion, n);
+    swaps(&stuff->minorVersion,n);
+    return ProcSecurityQueryVersion(client);
+} /* SProcSecurityQueryVersion */
+
+
+static int
+SProcSecurityGenerateAuthorization(client)
+    ClientPtr client;
+{
+    REQUEST(xSecurityGenerateAuthorizationReq);
+    register char      n;
+    CARD32 *values;
+    unsigned long nvalues;
+
+    swaps(&stuff->length, n);
+    REQUEST_AT_LEAST_SIZE(xSecurityGenerateAuthorizationReq);
+    swaps(&stuff->nbytesAuthProto, n);
+    swaps(&stuff->nbytesAuthData, n);
+    swapl(&stuff->valueMask, n);
+    values = (CARD32 *)(&stuff[1]) +
+       ((stuff->nbytesAuthProto + (unsigned)3) >> 2) +
+       ((stuff->nbytesAuthData + (unsigned)3) >> 2);
+    nvalues = (((CARD32 *)stuff) + stuff->length) - values;
+    SwapLongs(values, nvalues);
+    return ProcSecurityGenerateAuthorization(client);
+} /* SProcSecurityGenerateAuthorization */
+
+
+static int
+SProcSecurityRevokeAuthorization(client)
+    ClientPtr client;
+{
+    REQUEST(xSecurityRevokeAuthorizationReq);
+    register char      n;
+
+    swaps(&stuff->length, n);
+    REQUEST_SIZE_MATCH(xSecurityRevokeAuthorizationReq);
+    swapl(&stuff->authId, n);
+    return ProcSecurityRevokeAuthorization(client);
+} /* SProcSecurityRevokeAuthorization */
+
+
+static int
+SProcSecurityDispatch(client)
+    ClientPtr client;
+{
+    REQUEST(xReq);
+
+    switch (stuff->data)
+    {
+       case X_SecurityQueryVersion:
+           return SProcSecurityQueryVersion(client);
+       case X_SecurityGenerateAuthorization:
+           return SProcSecurityGenerateAuthorization(client);
+       case X_SecurityRevokeAuthorization:
+           return SProcSecurityRevokeAuthorization(client);
+       default:
+           return BadRequest;
+    }
+} /* SProcSecurityDispatch */
+
+static void 
+SwapSecurityAuthorizationRevokedEvent(from, to)
+    xSecurityAuthorizationRevokedEvent *from, *to;
+{
+    to->type = from->type;
+    to->detail = from->detail;
+    cpswaps(from->sequenceNumber, to->sequenceNumber);
+    cpswapl(from->authId, to->authId);
+}
+
+/* SecurityDetermineEventPropogationLimits
+ *
+ * This is a helper function for SecurityCheckDeviceAccess.
+ *
+ * Arguments:
+ *     dev is the device for which the starting and stopping windows for
+ *     event propogation should be determined.
+ *     The values pointed to by ppWin and ppStopWin are not used.
+ *
+ * Returns:
+ *     ppWin is filled in with a pointer to the window at which event
+ *     propogation for the given device should start given the current
+ *     state of the server (pointer position, window layout, etc.)
+ *     ppStopWin is filled in with the window at which event propogation
+ *     should stop; events should not go to ppStopWin.
+ *
+ * Side Effects: none.
+ */
+
+static void
+SecurityDetermineEventPropogationLimits(dev, ppWin, ppStopWin)
+    DeviceIntPtr dev;
+    WindowPtr *ppWin;
+    WindowPtr *ppStopWin;
+{
+    WindowPtr pFocusWin = dev->focus ? dev->focus->win : NoneWin;
+
+    if (pFocusWin == NoneWin)
+    { /* no focus -- events don't go anywhere */
+       *ppWin = *ppStopWin = NULL;
+       return;
+    }
+
+    if (pFocusWin == PointerRootWin)
+    { /* focus follows the pointer */
+       *ppWin = GetSpriteWindow();
+       *ppStopWin = NULL; /* propogate all the way to the root */
+    }
+    else
+    { /* a real window is set for the focus */
+       WindowPtr pSpriteWin = GetSpriteWindow();
+       *ppStopWin = pFocusWin->parent; /* don't go past the focus window */
+
+       /* if the pointer is in a subwindow of the focus window, start
+        * at that subwindow, else start at the focus window itself
+        */
+       if (IsParent(pFocusWin, pSpriteWin))
+            *ppWin = pSpriteWin;
+       else *ppWin = pFocusWin;
+    }
+} /* SecurityDetermineEventPropogationLimits */
+
+
+/* SecurityCheckDeviceAccess
+ *
+ * Arguments:
+ *     client is the client attempting to access a device.
+ *     dev is the device being accessed.
+ *     fromRequest is TRUE if the device access is a direct result of
+ *       the client executing some request and FALSE if it is a
+ *       result of the server trying to send an event (e.g. KeymapNotify)
+ *       to the client.
+ * Returns:
+ *     TRUE if the device access should be allowed, else FALSE.
+ *
+ * Side Effects:
+ *     An audit message is generated if access is denied.
+ */
+
+Bool
+SecurityCheckDeviceAccess(client, dev, fromRequest)
+    ClientPtr client;
+    DeviceIntPtr dev;
+    Bool fromRequest;
+{
+    WindowPtr pWin, pStopWin;
+    Bool untrusted_got_event;
+    Bool found_event_window;
+    Mask eventmask;
+    int reqtype;
+
+    /* trusted clients always allowed to do anything */
+    if (client->trustLevel == XSecurityClientTrusted)
+       return TRUE;
+
+    /* device security other than keyboard is not implemented yet */
+    if (dev != inputInfo.keyboard)
+       return TRUE;
+
+    /* some untrusted client wants access */
+
+    if (fromRequest)
+    {
+       reqtype = ((xReq *)client->requestBuffer)->reqType;
+       switch (reqtype)
+       {
+           /* never allow these */
+           case X_ChangeKeyboardMapping:
+           case X_ChangeKeyboardControl:
+           case X_SetModifierMapping:
+               SecurityAudit("client %d attempted request %d\n",
+                             client->index, reqtype);
+               return FALSE;
+           default:
+               break;
+       }
+    }
+
+    untrusted_got_event = FALSE;
+    found_event_window = FALSE;
+
+    if (dev->grab)
+    {
+       untrusted_got_event =
+           ((rClient(dev->grab))->trustLevel != XSecurityClientTrusted);
+    }
+    else
+    {
+       SecurityDetermineEventPropogationLimits(dev, &pWin, &pStopWin);
+
+       eventmask = KeyPressMask | KeyReleaseMask;
+       while ( (pWin != pStopWin) && !found_event_window)
+       {
+           OtherClients *other;
+
+           if (pWin->eventMask & eventmask)
+           {
+               found_event_window = TRUE;
+               client = wClient(pWin);
+               if (client->trustLevel != XSecurityClientTrusted)
+               {
+                   untrusted_got_event = TRUE;
+               }
+           }
+           if (wOtherEventMasks(pWin) & eventmask)
+           {
+               found_event_window = TRUE;
+               for (other = wOtherClients(pWin); other; other = other->next)
+               {
+                   if (other->mask & eventmask)
+                   {
+                       client = rClient(other);
+                       if (client->trustLevel != XSecurityClientTrusted)
+                       {
+                           untrusted_got_event = TRUE;
+                           break;
+                       }
+                   }
+               }
+           }
+           if (wDontPropagateMask(pWin) & eventmask)
+               break;
+           pWin = pWin->parent;
+       } /* while propogating the event */
+    }
+
+    /* allow access by untrusted clients only if an event would have gone 
+     * to an untrusted client
+     */
+    
+    if (!untrusted_got_event)
+    {
+       char *devname = dev->name;
+       if (!devname) devname = "unnamed";
+       if (fromRequest)
+           SecurityAudit("client %d attempted request %d device %d (%s)\n",
+                         client->index, reqtype, dev->id, devname);
+       else
+           SecurityAudit("client %d attempted to access device %d (%s)\n",
+                         client->index, dev->id, devname);
+    }
+    return untrusted_got_event;
+} /* SecurityCheckDeviceAccess */
+
+
+
+/* SecurityAuditResourceIDAccess
+ *
+ * Arguments:
+ *     client is the client doing the resource access.
+ *     id is the resource id.
+ *
+ * Returns: NULL
+ *
+ * Side Effects:
+ *     An audit message is generated with details of the denied
+ *     resource access.
+ */
+
+static pointer
+SecurityAuditResourceIDAccess(client, id)
+    ClientPtr client;
+    XID id;
+{
+    int cid = CLIENT_ID(id);
+    int reqtype = ((xReq *)client->requestBuffer)->reqType;
+    switch (reqtype)
+    {
+       case X_ChangeProperty:
+       case X_DeleteProperty:
+       case X_GetProperty:
+       {
+           xChangePropertyReq *req =
+               (xChangePropertyReq *)client->requestBuffer;
+           int propertyatom = req->property;
+           char *propertyname = NameForAtom(propertyatom);
+
+           SecurityAudit("client %d attempted request %d with window 0x%x property %s of client %d\n",
+                  client->index, reqtype, id, propertyname, cid);
+           break;
+       }
+       default:
+       {
+           SecurityAudit("client %d attempted request %d with resource 0x%x of client %d\n",
+                  client->index, reqtype, id, cid);
+           break;
+       }   
+    }
+    return NULL;
+} /* SecurityAuditResourceIDAccess */
+
+
+/* SecurityCheckResourceIDAccess
+ *
+ * This function gets plugged into client->CheckAccess and is called from
+ * SecurityLookupIDByType/Class to determine if the client can access the
+ * resource.
+ *
+ * Arguments:
+ *     client is the client doing the resource access.
+ *     id is the resource id.
+ *     rtype is its type or class.
+ *     access_mode represents the intended use of the resource; see
+ *       resource.h.
+ *     rval is a pointer to the resource structure for this resource.
+ *
+ * Returns:
+ *     If access is granted, the value of rval that was passed in, else NULL.
+ *
+ * Side Effects:
+ *     Disallowed resource accesses are audited.
+ */
+
+static pointer
+SecurityCheckResourceIDAccess(client, id, rtype, access_mode, rval)
+    ClientPtr client;
+    XID id;
+    RESTYPE rtype;
+    Mask access_mode;
+    pointer rval;
+{
+    int cid = CLIENT_ID(id);
+    int reqtype = ((xReq *)client->requestBuffer)->reqType;
+
+    if (SecurityUnknownAccess == access_mode)
+       return rval;  /* for compatibility, we have to allow access */
+
+    switch (reqtype)
+    { /* these are always allowed */
+       case X_QueryTree:
+        case X_TranslateCoords:
+        case X_GetGeometry:
+       /* property access is controlled in SecurityCheckPropertyAccess */
+       case X_GetProperty:
+       case X_ChangeProperty:
+       case X_DeleteProperty:
+       case X_RotateProperties:
+        case X_ListProperties:
+           return rval;
+       default:
+           break;
+    }
+
+    if (cid != 0)
+    { /* not a server-owned resource */
+     /*
+      * The following 'if' restricts clients to only access resources at
+      * the same trustLevel.  Since there are currently only two trust levels,
+      * and trusted clients never call this function, this degenerates into
+      * saying that untrusted clients can only access resources of other
+      * untrusted clients.  One way to add the notion of groups would be to
+      * allow values other than Trusted (0) and Untrusted (1) for this field.
+      * Clients at the same trust level would be able to use each other's
+      * resources, but not those of clients at other trust levels.  I haven't
+      * tried it, but this probably mostly works already.  The obvious
+      * competing alternative for grouping clients for security purposes is to
+      * use app groups.  dpw
+      */
+       if (client->trustLevel == clients[cid]->trustLevel
+#ifdef XAPPGROUP
+           || (RT_COLORMAP == rtype && 
+               XagDefaultColormap (client) == (Colormap) id)
+#endif
+       )
+           return rval;
+       else
+           return SecurityAuditResourceIDAccess(client, id);
+    }
+    else /* server-owned resource - probably a default colormap or root window */
+    {
+       if (RT_WINDOW == rtype || RC_DRAWABLE == rtype)
+       {
+           switch (reqtype)
+           {   /* the following operations are allowed on root windows */
+               case X_CreatePixmap:
+               case X_CreateGC:
+               case X_CreateWindow:
+               case X_CreateColormap:
+               case X_ListProperties:
+               case X_GrabPointer:
+               case X_UngrabButton:
+               case X_QueryBestSize:
+               case X_GetWindowAttributes:
+                   break;
+               case X_SendEvent:
+               { /* see if it is an event specified by the ICCCM */
+                   xSendEventReq *req = (xSendEventReq *)
+                                               (client->requestBuffer);
+                   if (req->propagate == xTrue
+                       ||
+                         (req->eventMask != ColormapChangeMask &&
+                          req->eventMask != StructureNotifyMask &&
+                          req->eventMask !=
+                             (SubstructureRedirectMask|SubstructureNotifyMask)
+                         )
+                       ||
+                         (req->event.u.u.type != UnmapNotify &&
+                          req->event.u.u.type != ConfigureRequest &&
+                          req->event.u.u.type != ClientMessage
+                         )
+                      )
+                   { /* not an ICCCM event */
+                       return SecurityAuditResourceIDAccess(client, id);
+                   }
+                   break;
+               } /* case X_SendEvent on root */
+
+               case X_ChangeWindowAttributes:
+               { /* Allow selection of PropertyNotify and StructureNotify
+                  * events on the root.
+                  */
+                   xChangeWindowAttributesReq *req =
+                       (xChangeWindowAttributesReq *)(client->requestBuffer);
+                   if (req->valueMask == CWEventMask)
+                   {
+                       CARD32 value = *((CARD32 *)(req + 1));
+                       if ( (value &
+                             ~(PropertyChangeMask|StructureNotifyMask)) == 0)
+                           break;
+                   }
+                   return SecurityAuditResourceIDAccess(client, id);
+               } /* case X_ChangeWindowAttributes on root */
+
+               default:
+               {
+#ifdef LBX
+                   /* XXX really need per extension dispatching */
+                   if (reqtype == LbxReqCode) {
+                       switch (((xReq *)client->requestBuffer)->data) {
+                       case X_LbxGetProperty:
+                       case X_LbxChangeProperty:
+                           return rval;
+                       default:
+                           break;
+                       }
+                   }
+#endif
+                   /* others not allowed */
+                   return SecurityAuditResourceIDAccess(client, id);
+               }
+           }
+       } /* end server-owned window or drawable */
+       else if (SecurityAuthorizationResType == rtype)
+       {
+           SecurityAuthorizationPtr pAuth = (SecurityAuthorizationPtr)rval;
+           if (pAuth->trustLevel != client->trustLevel)
+               return SecurityAuditResourceIDAccess(client, id);
+       }
+       else if (RT_COLORMAP != rtype)
+       { /* don't allow anything else besides colormaps */
+           return SecurityAuditResourceIDAccess(client, id);
+       }
+    }
+    return rval;
+} /* SecurityCheckResourceIDAccess */
+
+
+/* SecurityClientStateCallback
+ *
+ * Arguments:
+ *     pcbl is &ClientStateCallback.
+ *     nullata is NULL.
+ *     calldata is a pointer to a NewClientInfoRec (include/dixstruct.h)
+ *     which contains information about client state changes.
+ *
+ * Returns: nothing.
+ *
+ * Side Effects:
+ * 
+ * If a new client is connecting, its authorization ID is copied to
+ * client->authID.  If this is a generated authorization, its reference
+ * count is bumped, its timer is cancelled if it was running, and its
+ * trustlevel is copied to client->trustLevel.
+ * 
+ * If a client is disconnecting and the client was using a generated
+ * authorization, the authorization's reference count is decremented, and
+ * if it is now zero, the timer for this authorization is started.
+ */
+
+static void
+SecurityClientStateCallback(pcbl, nulldata, calldata)
+    CallbackListPtr *pcbl;
+    pointer nulldata;
+    pointer calldata;
+{
+    NewClientInfoRec *pci = (NewClientInfoRec *)calldata;
+    ClientPtr client = pci->client;
+
+    switch (client->clientState)
+    {
+       case ClientStateRunning:
+       { 
+           XID authId = AuthorizationIDOfClient(client);
+           SecurityAuthorizationPtr pAuth;
+
+           client->authId = authId;
+           pAuth = (SecurityAuthorizationPtr)LookupIDByType(authId,
+                                               SecurityAuthorizationResType);
+           if (pAuth)
+           { /* it is a generated authorization */
+               pAuth->refcnt++;
+               if (pAuth->refcnt == 1)
+               {
+                   if (pAuth->timer) TimerCancel(pAuth->timer);
+               }
+               client->trustLevel = pAuth->trustLevel;
+               if (client->trustLevel != XSecurityClientTrusted)
+               {
+                   client->CheckAccess = SecurityCheckResourceIDAccess;
+                   client->requestVector = client->swapped ?
+                       SwappedUntrustedProcVector : UntrustedProcVector;
+               }
+           }
+           break;
+       }
+       case ClientStateGone:
+       case ClientStateRetained: /* client disconnected */
+       {
+           XID authId = client->authId;
+           SecurityAuthorizationPtr pAuth;
+
+           pAuth = (SecurityAuthorizationPtr)LookupIDByType(authId,
+                                               SecurityAuthorizationResType);
+           if (pAuth)
+           { /* it is a generated authorization */
+               pAuth->refcnt--;
+               if (pAuth->refcnt == 0)
+               {
+                   SecurityStartAuthorizationTimer(pAuth);
+               }
+           }       
+           break;
+       }
+       default: break; 
+    }
+} /* SecurityClientStateCallback */
+
+#ifdef LBX
+Bool
+SecuritySameLevel(client, authId)
+    ClientPtr client;
+    XID authId;
+{
+    SecurityAuthorizationPtr pAuth;
+
+    pAuth = (SecurityAuthorizationPtr)LookupIDByType(authId,
+                                               SecurityAuthorizationResType);
+    if (pAuth)
+       return client->trustLevel == pAuth->trustLevel;
+    return client->trustLevel == XSecurityClientTrusted;
+}
+#endif
+
+/* SecurityCensorImage
+ *
+ * Called after pScreen->GetImage to prevent pieces or trusted windows from
+ * being returned in image data from an untrusted window.
+ *
+ * Arguments:
+ *     client is the client doing the GetImage.
+ *      pVisibleRegion is the visible region of the window.
+ *     widthBytesLine is the width in bytes of one horizontal line in pBuf.
+ *     pDraw is the source window.
+ *     x, y, w, h is the rectangle of image data from pDraw in pBuf.
+ *     format is the format of the image data in pBuf: ZPixmap or XYPixmap.
+ *     pBuf is the image data.
+ *
+ * Returns: nothing.
+ *
+ * Side Effects:
+ *     Any part of the rectangle (x, y, w, h) that is outside the visible
+ *     region of the window will be destroyed (overwritten) in pBuf.
+ */
+void
+SecurityCensorImage(client, pVisibleRegion, widthBytesLine, pDraw, x, y, w, h,
+                   format, pBuf)
+    ClientPtr client;
+    RegionPtr pVisibleRegion;
+    long widthBytesLine;
+    DrawablePtr pDraw;
+    int x, y, w, h;
+    unsigned int format;
+    char * pBuf;
+{
+    RegionRec imageRegion;  /* region representing x,y,w,h */
+    RegionRec censorRegion; /* region to obliterate */
+    BoxRec imageBox;
+    int nRects;
+
+    imageBox.x1 = x;
+    imageBox.y1 = y;
+    imageBox.x2 = x + w;
+    imageBox.y2 = y + h;
+    REGION_INIT(pScreen, &imageRegion, &imageBox, 1);
+    REGION_INIT(pScreen, &censorRegion, NullBox, 0);
+
+    /* censorRegion = imageRegion - visibleRegion */
+    REGION_SUBTRACT(pScreen, &censorRegion, &imageRegion, pVisibleRegion);
+    nRects = REGION_NUM_RECTS(&censorRegion);
+    if (nRects > 0)
+    { /* we have something to censor */
+       GCPtr pScratchGC = NULL;
+       PixmapPtr pPix = NULL;
+       xRectangle *pRects = NULL;
+       Bool failed = FALSE;
+       int depth = 1;
+       int bitsPerPixel = 1;
+       int i;
+       BoxPtr pBox;
+
+       /* convert region to list-of-rectangles for PolyFillRect */
+
+       pRects = (xRectangle *)ALLOCATE_LOCAL(nRects * sizeof(xRectangle *));
+       if (!pRects)
+       {
+           failed = TRUE;
+           goto failSafe;
+       }
+       for (pBox = REGION_RECTS(&censorRegion), i = 0;
+            i < nRects;
+            i++, pBox++)
+       {
+           pRects[i].x = pBox->x1;
+           pRects[i].y = pBox->y1 - imageBox.y1;
+           pRects[i].width  = pBox->x2 - pBox->x1;
+           pRects[i].height = pBox->y2 - pBox->y1;
+       }
+
+       /* use pBuf as a fake pixmap */
+
+       if (format == ZPixmap)
+       {
+           depth = pDraw->depth;
+           bitsPerPixel = pDraw->bitsPerPixel;
+       }
+
+       pPix = GetScratchPixmapHeader(pDraw->pScreen, w, h,
+                   depth, bitsPerPixel,
+                   widthBytesLine, (pointer)pBuf);
+       if (!pPix)
+       {
+           failed = TRUE;
+           goto failSafe;
+       }
+
+       pScratchGC = GetScratchGC(depth, pPix->drawable.pScreen);
+       if (!pScratchGC)
+       {
+           failed = TRUE;
+           goto failSafe;
+       }
+
+       ValidateGC(&pPix->drawable, pScratchGC);
+       (* pScratchGC->ops->PolyFillRect)(&pPix->drawable,
+                           pScratchGC, nRects, pRects);
+
+    failSafe:
+       if (failed)
+       {
+           /* Censoring was not completed above.  To be safe, wipe out
+            * all the image data so that nothing trusted gets out.
+            */
+           bzero(pBuf, (int)(widthBytesLine * h));
+       }
+       if (pRects)     DEALLOCATE_LOCAL(pRects);
+       if (pScratchGC) FreeScratchGC(pScratchGC);
+       if (pPix)       FreeScratchPixmapHeader(pPix);
+    }
+    REGION_UNINIT(pScreen, &imageRegion);
+    REGION_UNINIT(pScreen, &censorRegion);
+} /* SecurityCensorImage */
+
+/**********************************************************************/
+
+typedef struct _PropertyAccessRec {
+    ATOM name;
+    ATOM mustHaveProperty;
+    char *mustHaveValue;
+    char windowRestriction;
+#define SecurityAnyWindow          0
+#define SecurityRootWindow         1
+#define SecurityWindowWithProperty 2
+    char readAction;
+    char writeAction;
+    char destroyAction;
+    struct _PropertyAccessRec *next;
+} PropertyAccessRec, *PropertyAccessPtr;
+
+static PropertyAccessPtr PropertyAccessList = NULL;
+static char SecurityDefaultAction = SecurityErrorOperation;
+static char *SecurityPolicyFile = DEFAULTPOLICYFILE;
+static ATOM SecurityMaxPropertyName = 0;
+
+static char *SecurityKeywords[] = {
+#define SecurityKeywordComment 0
+    "#",
+#define SecurityKeywordProperty 1
+    "property",
+#define SecurityKeywordSitePolicy 2
+    "sitepolicy",
+#define SecurityKeywordRoot 3
+    "root",
+#define SecurityKeywordAny 4
+    "any"
+};
+
+#define NUMKEYWORDS (sizeof(SecurityKeywords) / sizeof(char *))
+
+#undef PROPDEBUG
+/*#define PROPDEBUG  1*/
+
+static void
+SecurityFreePropertyAccessList()
+{
+    while (PropertyAccessList)
+    {
+       PropertyAccessPtr freeit = PropertyAccessList;
+       PropertyAccessList = PropertyAccessList->next;
+       xfree(freeit);
+    }
+} /* SecurityFreePropertyAccessList */
+
+#ifndef __EMX__
+#define SecurityIsWhitespace(c) ( (c == ' ') || (c == '\t') || (c == '\n') )
+#else
+#define SecurityIsWhitespace(c) ( (c == ' ') || (c == '\t') || (c == '\n') || (c == '\r') )
+#endif
+
+static char *
+SecuritySkipWhitespace(p)
+    char *p;
+{
+    while (SecurityIsWhitespace(*p))
+       p++;
+    return p;
+} /* SecuritySkipWhitespace */
+
+
+static char *
+SecurityParseString(rest)
+    char **rest;
+{
+    char *startOfString;
+    char *s = *rest;
+    char endChar = 0;
+
+    s = SecuritySkipWhitespace(s);
+
+    if (*s == '"' || *s == '\'')
+    {
+       endChar = *s++;
+       startOfString = s;
+       while (*s && (*s != endChar))
+           s++;
+    }
+    else
+    {
+       startOfString = s;
+       while (*s && !SecurityIsWhitespace(*s))
+           s++;
+    }
+    if (*s)
+    {
+       *s = '\0';
+       *rest = s + 1;
+       return startOfString;
+    }
+    else
+    {
+       *rest = s;
+       return (endChar) ? NULL : startOfString;
+    }
+} /* SecurityParseString */
+
+
+static int
+SecurityParseKeyword(p)
+    char **p;
+{
+    int i;
+    char *s = *p;
+    s = SecuritySkipWhitespace(s);
+    for (i = 0; i < NUMKEYWORDS; i++)
+    {
+       int len = strlen(SecurityKeywords[i]);
+       if (strncmp(s, SecurityKeywords[i], len) == 0)
+       {
+           *p = s + len;
+           return (i);
+       }
+    }
+    *p = s;
+    return -1;
+} /* SecurityParseKeyword */
+
+
+static Bool
+SecurityParsePropertyAccessRule(p)
+    char *p;
+{
+    char *propname;
+    char c;
+    char action = SecurityDefaultAction;
+    char readAction, writeAction, destroyAction;
+    PropertyAccessPtr pacl, prev, cur;
+    ATOM atom;
+    char *mustHaveProperty = NULL;
+    char *mustHaveValue = NULL;
+    Bool invalid;
+    char windowRestriction;
+    int size;
+    int keyword;
+
+    /* get property name */
+    propname = SecurityParseString(&p);
+    if (!propname || (strlen(propname) == 0))
+       return FALSE;
+
+    /* get window on which property must reside for rule to apply */
+
+    keyword = SecurityParseKeyword(&p);
+    if (keyword == SecurityKeywordRoot)
+       windowRestriction = SecurityRootWindow;
+    else if (keyword == SecurityKeywordAny) 
+       windowRestriction = SecurityAnyWindow;
+    else /* not root or any, must be a property name */
+    {
+       mustHaveProperty = SecurityParseString(&p);
+       if (!mustHaveProperty || (strlen(mustHaveProperty) == 0))
+           return FALSE;
+       windowRestriction = SecurityWindowWithProperty;
+       p = SecuritySkipWhitespace(p);
+       if (*p == '=')
+       { /* property value is specified too */
+           p++; /* skip over '=' */
+           mustHaveValue = SecurityParseString(&p);
+           if (!mustHaveValue)
+               return FALSE;
+       }
+    }
+
+    /* get operations and actions */
+
+    invalid = FALSE;
+    readAction = writeAction = destroyAction = SecurityDefaultAction;
+    while ( (c = *p++) && !invalid)
+    {
+       switch (c)
+       {
+           case 'i': action = SecurityIgnoreOperation; break;
+           case 'a': action = SecurityAllowOperation;  break;
+           case 'e': action = SecurityErrorOperation;  break;
+
+           case 'r': readAction    = action; break;
+           case 'w': writeAction   = action; break;
+           case 'd': destroyAction = action; break;
+
+           default :
+               if (!SecurityIsWhitespace(c))
+                   invalid = TRUE;
+           break;
+       }
+    }
+    if (invalid)
+       return FALSE;
+
+    /* We've successfully collected all the information needed for this
+     * property access rule.  Now record it in a PropertyAccessRec.
+     */
+    size = sizeof(PropertyAccessRec);
+
+    /* If there is a property value string, allocate space for it 
+     * right after the PropertyAccessRec.
+     */
+    if (mustHaveValue)
+       size += strlen(mustHaveValue) + 1;
+    pacl = (PropertyAccessPtr)Xalloc(size);
+    if (!pacl)
+       return FALSE;
+
+    pacl->name = MakeAtom(propname, strlen(propname), TRUE);
+    if (pacl->name == BAD_RESOURCE)
+    {
+       Xfree(pacl);
+       return FALSE;
+    }
+    if (mustHaveProperty)
+    {
+       pacl->mustHaveProperty = MakeAtom(mustHaveProperty,
+                                         strlen(mustHaveProperty), TRUE);
+       if (pacl->mustHaveProperty == BAD_RESOURCE)
+       {
+           Xfree(pacl);
+           return FALSE;
+       }
+    }
+    else
+       pacl->mustHaveProperty = 0;
+
+    if (mustHaveValue)
+    {
+       pacl->mustHaveValue = (char *)(pacl + 1);
+       strcpy(pacl->mustHaveValue, mustHaveValue);
+    }
+    else
+       pacl->mustHaveValue = NULL;
+
+    SecurityMaxPropertyName = max(SecurityMaxPropertyName, pacl->name);
+
+    pacl->windowRestriction = windowRestriction;
+    pacl->readAction  = readAction;
+    pacl->writeAction = writeAction;
+    pacl->destroyAction = destroyAction;
+
+    /* link the new rule into the list of rules in order of increasing
+     * property name (atom) value to make searching easier
+     */
+
+    for (prev = NULL,  cur = PropertyAccessList;
+        cur && cur->name <= pacl->name;
+        prev = cur, cur = cur->next)
+       ;
+    if (!prev)
+    {
+       pacl->next = cur;
+       PropertyAccessList = pacl;
+    }
+    else
+    {
+       prev->next = pacl;
+       pacl->next = cur;
+    }
+    return TRUE;
+} /* SecurityParsePropertyAccessRule */
+
+static char **SecurityPolicyStrings = NULL;
+static int nSecurityPolicyStrings = 0;
+
+static Bool
+SecurityParseSitePolicy(p)
+    char *p;
+{
+    char *policyStr = SecurityParseString(&p);
+    char *copyPolicyStr;
+    char **newStrings;
+
+    if (!policyStr)
+       return FALSE;
+
+    copyPolicyStr = (char *)Xalloc(strlen(policyStr) + 1);
+    if (!copyPolicyStr)
+       return TRUE;
+    strcpy(copyPolicyStr, policyStr);
+    newStrings = (char **)Xrealloc(SecurityPolicyStrings,
+                         sizeof (char *) * (nSecurityPolicyStrings + 1));
+    if (!newStrings)
+    {
+       Xfree(copyPolicyStr);
+       return TRUE;
+    }
+
+    SecurityPolicyStrings = newStrings;
+    SecurityPolicyStrings[nSecurityPolicyStrings++] = copyPolicyStr;
+
+} /* SecurityParseSitePolicy */
+
+
+char **
+SecurityGetSitePolicyStrings(n)
+    int *n;
+{
+    *n = nSecurityPolicyStrings;
+    return SecurityPolicyStrings;
+} /* SecurityGetSitePolicyStrings */
+
+static void
+SecurityFreeSitePolicyStrings()
+{
+    if (SecurityPolicyStrings)
+    {
+       assert(nSecurityPolicyStrings);
+       while (nSecurityPolicyStrings--)
+       {
+           Xfree(SecurityPolicyStrings[nSecurityPolicyStrings]);
+       }
+       Xfree(SecurityPolicyStrings);
+       SecurityPolicyStrings = NULL;
+       nSecurityPolicyStrings = 0;
+    }
+} /* SecurityFreeSitePolicyStrings */
+
+
+static void
+SecurityLoadPropertyAccessList()
+{
+    FILE *f;
+    int lineNumber = 0;
+
+    SecurityMaxPropertyName = 0;
+
+    if (!SecurityPolicyFile)
+       return;
+
+#ifndef __EMX__
+    f = fopen(SecurityPolicyFile, "r");
+#else
+    f = fopen((char*)__XOS2RedirRoot(SecurityPolicyFile), "r");
+#endif    
+    if (!f)
+    {
+       ErrorF("error opening security policy file %s\n",
+              SecurityPolicyFile);
+       return;
+    }
+
+    while (!feof(f))
+    {
+       char buf[200];
+       Bool validLine;
+       char *p;
+
+       if (!(p = fgets(buf, sizeof(buf), f)))
+           break;
+       lineNumber++;
+
+       /* if first line, check version number */
+       if (lineNumber == 1)
+       {
+           char *v = SecurityParseString(&p);
+           if (strcmp(v, SECURITY_POLICY_FILE_VERSION) != 0)
+           {
+               ErrorF("%s: invalid security policy file version, ignoring file\n",
+                      SecurityPolicyFile);
+               break;
+           }
+           validLine = TRUE;
+       }
+       else
+       {
+           switch (SecurityParseKeyword(&p))
+           {
+               case SecurityKeywordComment:
+                   validLine = TRUE;
+               break;
+
+               case SecurityKeywordProperty:
+                   validLine = SecurityParsePropertyAccessRule(p);
+               break;
+
+               case SecurityKeywordSitePolicy:
+                   validLine = SecurityParseSitePolicy(p);
+               break;
+
+               default:
+                   validLine = (*p == '\0'); /* blank lines OK, others not */
+               break;
+           }
+       }
+
+       if (!validLine)
+           ErrorF("Line %d of %s invalid, ignoring\n",
+                  lineNumber, SecurityPolicyFile);
+    } /* end while more input */
+
+#ifdef PROPDEBUG
+    {
+       PropertyAccessPtr pacl;
+       char *op = "aie";
+       for (pacl = PropertyAccessList; pacl; pacl = pacl->next)
+       {
+           ErrorF("property %s ", NameForAtom(pacl->name));
+           switch (pacl->windowRestriction)
+           {
+               case SecurityAnyWindow: ErrorF("any "); break;
+               case SecurityRootWindow: ErrorF("root "); break;
+               case SecurityWindowWithProperty:
+               {
+                   ErrorF("%s ", NameForAtom(pacl->mustHaveProperty));
+                   if (pacl->mustHaveValue)
+                       ErrorF(" = \"%s\" ", pacl->mustHaveValue);
+
+               }
+               break;
+           }
+           ErrorF("%cr %cw %cd\n", op[pacl->readAction],
+                  op[pacl->writeAction], op[pacl->destroyAction]);
+       }
+    }
+#endif /* PROPDEBUG */
+
+    fclose(f);
+} /* SecurityLoadPropertyAccessList */
+
+
+static Bool
+SecurityMatchString(ws, cs)
+    char *ws;
+    char *cs;
+{
+    while (*ws && *cs)
+    {
+       if (*ws == '*')
+       {
+           Bool match = FALSE;
+           ws++;
+           while (!(match = SecurityMatchString(ws, cs)) && *cs)
+           {
+               cs++;
+           }
+           return match;
+       }
+       else if (*ws == *cs)
+       {
+           ws++;
+           cs++;
+       }
+       else break;
+    }
+    return ( ( (*ws == '\0') || ((*ws == '*') && *(ws+1) == '\0') )
+            && (*cs == '\0') );
+} /* SecurityMatchString */
+
+#ifdef PROPDEBUG
+#include <sys/types.h>
+#include <sys/stat.h>
+#endif
+
+
+char
+SecurityCheckPropertyAccess(client, pWin, propertyName, access_mode)
+    ClientPtr client;
+    WindowPtr pWin;
+    ATOM propertyName;
+    Mask access_mode;
+{
+    PropertyAccessPtr pacl;
+    char action = SecurityDefaultAction;
+
+    /* if client trusted or window untrusted, allow operation */
+
+    if ( (client->trustLevel == XSecurityClientTrusted) ||
+        (wClient(pWin)->trustLevel != XSecurityClientTrusted) )
+       return SecurityAllowOperation;
+
+#ifdef PROPDEBUG
+    /* For testing, it's more convenient if the property rules file gets
+     * reloaded whenever it changes, so we can rapidly try things without
+     * having to reset the server.
+     */
+    {
+       struct stat buf;
+       static time_t lastmod = 0;
+       int ret = stat(SecurityPolicyFile , &buf);
+       if ( (ret == 0) && (buf.st_mtime > lastmod) )
+       {
+           ErrorF("reloading property rules\n");
+           SecurityFreePropertyAccessList();
+           SecurityLoadPropertyAccessList();
+           lastmod = buf.st_mtime;
+       }
+    }
+#endif
+
+    /* If the property atom is bigger than any atoms on the list, 
+     * we know we won't find it, so don't even bother looking.
+     */
+    if (propertyName <= SecurityMaxPropertyName)
+    {
+       /* untrusted client operating on trusted window; see if it's allowed */
+
+       for (pacl = PropertyAccessList; pacl; pacl = pacl->next)
+       {
+           if (pacl->name < propertyName)
+               continue;
+           if (pacl->name > propertyName)
+               break;
+
+           /* pacl->name == propertyName, so see if it applies to this window */
+
+           switch (pacl->windowRestriction)
+           {
+               case SecurityAnyWindow: /* always applies */
+                   break;
+
+               case SecurityRootWindow:
+               {
+                   /* if not a root window, this rule doesn't apply */
+                   if (pWin->parent)
+                       continue;
+               }
+               break;
+
+               case SecurityWindowWithProperty:
+               {
+                   PropertyPtr pProp = wUserProps (pWin);
+                   Bool match = FALSE;
+                   char *p;
+                   char *pEndData;
+
+                   while (pProp)
+                   {
+                       if (pProp->propertyName == pacl->mustHaveProperty)
+                           break;
+                       pProp = pProp->next;
+                   }
+                   if (!pProp)
+                       continue;
+                   if (!pacl->mustHaveValue)
+                       break;
+                   if (pProp->type != XA_STRING || pProp->format != 8)
+                       continue;
+
+                   p = pProp->data;
+                   pEndData = ((char *)pProp->data) + pProp->size;
+                   while (!match && p < pEndData)
+                   {
+                        if (SecurityMatchString(pacl->mustHaveValue, p))
+                            match = TRUE;
+                        else
+                        { /* skip to the next string */
+                            while (*p++ && p < pEndData)
+                                ;
+                        }
+                   }
+                   if (!match)
+                       continue;
+               }
+               break; /* end case SecurityWindowWithProperty */
+           } /* end switch on windowRestriction */
+
+           /* If we get here, the property access rule pacl applies.
+            * If pacl doesn't apply, something above should have
+            * executed a continue, which will skip the follwing code.
+            */
+           action = SecurityAllowOperation;
+           if (access_mode & SecurityReadAccess)
+               action = max(action, pacl->readAction);
+           if (access_mode & SecurityWriteAccess)
+               action = max(action, pacl->writeAction);
+           if (access_mode & SecurityDestroyAccess)
+               action = max(action, pacl->destroyAction);
+           break;
+       } /* end for each pacl */
+    } /* end if propertyName <= SecurityMaxPropertyName */
+
+    if (SecurityAllowOperation != action)
+    { /* audit the access violation */
+       int cid = CLIENT_ID(pWin->drawable.id);
+       int reqtype = ((xReq *)client->requestBuffer)->reqType;
+       char *actionstr = (SecurityIgnoreOperation == action) ?
+                                                       "ignored" : "error";
+       SecurityAudit("client %d attempted request %d with window 0x%x property %s (atom 0x%x) of client %d, %s\n",
+               client->index, reqtype, pWin->drawable.id,
+                     NameForAtom(propertyName), propertyName, cid, actionstr);
+    }
+    return action;
+} /* SecurityCheckPropertyAccess */
+
+
+/* SecurityResetProc
+ *
+ * Arguments:
+ *     extEntry is the extension information for the security extension.
+ *
+ * Returns: nothing.
+ *
+ * Side Effects:
+ *     Performs any cleanup needed by Security at server shutdown time.
+ */
+
+static void
+SecurityResetProc(extEntry)
+    ExtensionEntry     *extEntry;
+{
+    SecurityFreePropertyAccessList();
+    SecurityFreeSitePolicyStrings();
+} /* SecurityResetProc */
+
+
+int
+XSecurityOptions(argc, argv, i)
+    int argc;
+    char **argv;
+    int i;
+{
+    if (strcmp(argv[i], "-sp") == 0)
+    {
+       if (i < argc)
+           SecurityPolicyFile = argv[++i];
+       return (i + 1);
+    }
+    return (i);
+} /* XSecurityOptions */
+
+
+
+/* SecurityExtensionInit
+ *
+ * Arguments: none.
+ *
+ * Returns: nothing.
+ *
+ * Side Effects:
+ *     Enables the Security extension if possible.
+ */
+
+void
+SecurityExtensionInit()
+{
+    ExtensionEntry     *extEntry;
+    int i;
+
+    SecurityAuthorizationResType =
+       CreateNewResourceType(SecurityDeleteAuthorization);
+
+    RTEventClient = CreateNewResourceType(
+                               SecurityDeleteAuthorizationEventClient);
+
+    if (!SecurityAuthorizationResType || !RTEventClient)
+       return;
+
+    RTEventClient |= RC_NEVERRETAIN;
+
+    if (!AddCallback(&ClientStateCallback, SecurityClientStateCallback, NULL))
+       return;
+
+    extEntry = AddExtension(SECURITY_EXTENSION_NAME,
+                           XSecurityNumberEvents, XSecurityNumberErrors,
+                           ProcSecurityDispatch, SProcSecurityDispatch,
+                            SecurityResetProc, StandardMinorOpcode);
+
+    SecurityErrorBase = extEntry->errorBase;
+    SecurityEventBase = extEntry->eventBase;
+
+    EventSwapVector[SecurityEventBase + XSecurityAuthorizationRevoked] =
+       SwapSecurityAuthorizationRevokedEvent;
+
+    /* initialize untrusted proc vectors */
+
+    for (i = 0; i < 128; i++)
+    {
+       UntrustedProcVector[i] = ProcVector[i];
+       SwappedUntrustedProcVector[i] = SwappedProcVector[i];
+    }
+
+    /* make sure insecure extensions are not allowed */
+
+    for (i = 128; i < 256; i++)
+    {
+       if (!UntrustedProcVector[i])
+       {
+           UntrustedProcVector[i] = ProcBadRequest;
+           SwappedUntrustedProcVector[i] = ProcBadRequest;
+       }
+    }
+
+    SecurityLoadPropertyAccessList();
+
+} /* SecurityExtensionInit */
diff --git a/Xserver/programs/Xserver/Xext/shape.c b/Xserver/programs/Xserver/Xext/shape.c
new file mode 100644 (file)
index 0000000..af4a14b
--- /dev/null
@@ -0,0 +1,1127 @@
+/************************************************************
+
+Copyright (c) 1989  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+********************************************************/
+
+/* $TOG: shape.c /main/37 1997/05/22 10:11:40 kaleb $ */
+
+
+
+
+/* $XFree86: xc/programs/Xserver/Xext/shape.c,v 3.1.2.1 1997/05/23 12:19:34 dawes Exp $ */
+#define NEED_REPLIES
+#define NEED_EVENTS
+#include <stdio.h>
+#include "X.h"
+#include "Xproto.h"
+#include "misc.h"
+#include "os.h"
+#include "windowstr.h"
+#include "scrnintstr.h"
+#include "pixmapstr.h"
+#include "extnsionst.h"
+#include "dixstruct.h"
+#include "resource.h"
+#include "opaque.h"
+#define _SHAPE_SERVER_ /* don't want Xlib structures */
+#include "shapestr.h"
+#include "regionstr.h"
+#include "gcstruct.h"
+
+typedef        RegionPtr (*CreateDftPtr)(
+#if NeedNestedPrototypes
+       WindowPtr /* pWin */
+#endif
+       );
+
+static int ShapeFreeClient(
+#if NeedFunctionPrototypes
+       pointer /* data */,
+       XID /* id */
+#endif
+       );
+static int ShapeFreeEvents(
+#if NeedFunctionPrototypes
+       pointer /* data */,
+       XID /* id */
+#endif
+       );
+static void SendShapeNotify(
+#if NeedFunctionPrototypes
+       WindowPtr /* pWin */,
+       int /* which */
+#endif
+       );
+static void ShapeResetProc(
+#if NeedFunctionPrototypes
+       ExtensionEntry * /* extEntry */
+#endif
+       );
+static void SShapeNotifyEvent(
+#if NeedFunctionPrototypes
+       xShapeNotifyEvent * /* from */,
+       xShapeNotifyEvent * /* to */
+#endif
+       );
+static int
+RegionOperate (
+#if NeedFunctionPrototypes
+       ClientPtr /* client */,
+       WindowPtr /* pWin */,
+       int /* kind */,
+       RegionPtr * /* destRgnp */,
+       RegionPtr /* srcRgn */,
+       int /* op */,
+       int /* xoff */,
+       int /* yoff */,
+       CreateDftPtr /* create */
+#endif
+       );
+
+#if NeedFunctionPrototypes
+#define CREATE_PROC(func) RegionPtr func(WindowPtr /* pWin */)
+#else
+#define CREATE_PROC(func) RegionPtr func(/* WindowPtr pWin */)
+#endif
+
+static CREATE_PROC(CreateBoundingShape);
+static CREATE_PROC(CreateClipShape);
+
+#undef CREATE_PROC
+
+static DISPATCH_PROC(ProcShapeCombine);
+static DISPATCH_PROC(ProcShapeDispatch);
+static DISPATCH_PROC(ProcShapeGetRectangles);
+static DISPATCH_PROC(ProcShapeInputSelected);
+static DISPATCH_PROC(ProcShapeMask);
+static DISPATCH_PROC(ProcShapeOffset);
+static DISPATCH_PROC(ProcShapeQueryExtents);
+static DISPATCH_PROC(ProcShapeQueryVersion);
+static DISPATCH_PROC(ProcShapeRectangles);
+static DISPATCH_PROC(ProcShapeSelectInput);
+static DISPATCH_PROC(SProcShapeCombine);
+static DISPATCH_PROC(SProcShapeDispatch);
+static DISPATCH_PROC(SProcShapeGetRectangles);
+static DISPATCH_PROC(SProcShapeInputSelected);
+static DISPATCH_PROC(SProcShapeMask);
+static DISPATCH_PROC(SProcShapeOffset);
+static DISPATCH_PROC(SProcShapeQueryExtents);
+static DISPATCH_PROC(SProcShapeQueryVersion);
+static DISPATCH_PROC(SProcShapeRectangles);
+static DISPATCH_PROC(SProcShapeSelectInput);
+
+static unsigned char ShapeReqCode = 0;
+static int ShapeEventBase = 0;
+static RESTYPE ClientType, EventType; /* resource types for event masks */
+
+/*
+ * each window has a list of clients requesting
+ * ShapeNotify events.  Each client has a resource
+ * for each window it selects ShapeNotify input for,
+ * this resource is used to delete the ShapeNotifyRec
+ * entry from the per-window queue.
+ */
+
+typedef struct _ShapeEvent *ShapeEventPtr;
+
+typedef struct _ShapeEvent {
+    ShapeEventPtr   next;
+    ClientPtr      client;
+    WindowPtr      window;
+    XID                    clientResource;
+} ShapeEventRec;
+
+/****************
+ * ShapeExtensionInit
+ *
+ * Called from InitExtensions in main() or from QueryExtension() if the
+ * extension is dynamically loaded.
+ *
+ ****************/
+
+void
+ShapeExtensionInit()
+{
+    ExtensionEntry *extEntry;
+
+    ClientType = CreateNewResourceType(ShapeFreeClient);
+    EventType = CreateNewResourceType(ShapeFreeEvents);
+    if (ClientType && EventType &&
+       (extEntry = AddExtension(SHAPENAME, ShapeNumberEvents, 0,
+                                ProcShapeDispatch, SProcShapeDispatch,
+                                ShapeResetProc, StandardMinorOpcode)))
+    {
+       ShapeReqCode = (unsigned char)extEntry->base;
+       ShapeEventBase = extEntry->eventBase;
+       EventSwapVector[ShapeEventBase] = (EventSwapPtr) SShapeNotifyEvent;
+    }
+}
+
+/*ARGSUSED*/
+static void
+ShapeResetProc (extEntry)
+ExtensionEntry *extEntry;
+{
+}
+
+static int
+RegionOperate (client, pWin, kind, destRgnp, srcRgn, op, xoff, yoff, create)
+    ClientPtr  client;
+    WindowPtr  pWin;
+    int                kind;
+    RegionPtr  *destRgnp, srcRgn;
+    int                op;
+    int                xoff, yoff;
+    CreateDftPtr create;       /* creates a reasonable *destRgnp */
+{
+    ScreenPtr  pScreen = pWin->drawable.pScreen;
+
+    if (srcRgn && (xoff || yoff))
+       REGION_TRANSLATE(pScreen, srcRgn, xoff, yoff);
+    if (!pWin->parent)
+    {
+       if (srcRgn)
+           REGION_DESTROY(pScreen, srcRgn);
+       return Success;
+    }
+    switch (op) {
+    case ShapeSet:
+       if (*destRgnp)
+           REGION_DESTROY(pScreen, *destRgnp);
+       *destRgnp = srcRgn;
+       srcRgn = 0;
+       break;
+    case ShapeUnion:
+       if (*destRgnp && srcRgn)
+           REGION_UNION(pScreen, *destRgnp, *destRgnp, srcRgn);
+       break;
+    case ShapeIntersect:
+       if (*destRgnp && srcRgn)
+           REGION_INTERSECT(pScreen, *destRgnp, *destRgnp, srcRgn);
+       else {
+           *destRgnp = srcRgn;
+           srcRgn = 0;
+       }
+       break;
+    case ShapeSubtract:
+       if (!*destRgnp)
+           *destRgnp = (*create)(pWin);
+       if (srcRgn)
+           REGION_SUBTRACT(pScreen, *destRgnp, *destRgnp, srcRgn);
+       break;
+    case ShapeInvert:
+       if (!*destRgnp)
+           *destRgnp = REGION_CREATE(pScreen, (BoxPtr) 0, 0);
+       else if (srcRgn)
+           REGION_SUBTRACT(pScreen, *destRgnp, srcRgn, *destRgnp);
+       break;
+    default:
+       client->errorValue = op;
+       return BadValue;
+    }
+    if (srcRgn)
+       REGION_DESTROY(pScreen, srcRgn);
+    (*pScreen->SetShape) (pWin);
+    SendShapeNotify (pWin, kind);
+    return Success;
+}
+
+static RegionPtr
+CreateBoundingShape (pWin)
+    WindowPtr  pWin;
+{
+    BoxRec     extents;
+
+    extents.x1 = -wBorderWidth (pWin);
+    extents.y1 = -wBorderWidth (pWin);
+    extents.x2 = pWin->drawable.width + wBorderWidth (pWin);
+    extents.y2 = pWin->drawable.height + wBorderWidth (pWin);
+    return REGION_CREATE(pWin->drawable.pScreen, &extents, 1);
+}
+
+static RegionPtr
+CreateClipShape (pWin)
+    WindowPtr  pWin;
+{
+    BoxRec     extents;
+
+    extents.x1 = 0;
+    extents.y1 = 0;
+    extents.x2 = pWin->drawable.width;
+    extents.y2 = pWin->drawable.height;
+    return REGION_CREATE(pWin->drawable.pScreen, &extents, 1);
+}
+
+static int
+ProcShapeQueryVersion (client)
+    register ClientPtr client;
+{
+    xShapeQueryVersionReply    rep;
+    register int               n;
+
+    REQUEST_SIZE_MATCH (xShapeQueryVersionReq);
+    rep.type = X_Reply;
+    rep.length = 0;
+    rep.sequenceNumber = client->sequence;
+    rep.majorVersion = SHAPE_MAJOR_VERSION;
+    rep.minorVersion = SHAPE_MINOR_VERSION;
+    if (client->swapped) {
+       swaps(&rep.sequenceNumber, n);
+       swapl(&rep.length, n);
+       swaps(&rep.majorVersion, n);
+       swaps(&rep.minorVersion, n);
+    }
+    WriteToClient(client, sizeof (xShapeQueryVersionReply), (char *)&rep);
+    return (client->noClientException);
+}
+
+/*****************
+ * ProcShapeRectangles
+ *
+ *****************/
+
+static int
+ProcShapeRectangles (client)
+    register ClientPtr client;
+{
+    WindowPtr          pWin;
+    ScreenPtr          pScreen;
+    REQUEST(xShapeRectanglesReq);
+    xRectangle         *prects;
+    int                        nrects, ctype;
+    RegionPtr          srcRgn;
+    RegionPtr          *destRgn;
+    CreateDftPtr       createDefault;
+    int                        destBounding;
+
+    REQUEST_AT_LEAST_SIZE (xShapeRectanglesReq);
+    UpdateCurrentTime();
+    pWin = LookupWindow (stuff->dest, client);
+    if (!pWin)
+       return BadWindow;
+    switch (stuff->destKind) {
+    case ShapeBounding:
+       destBounding = 1;
+       createDefault = CreateBoundingShape;
+       break;
+    case ShapeClip:
+       destBounding = 0;
+       createDefault = CreateClipShape;
+       break;
+    default:
+       client->errorValue = stuff->destKind;
+       return BadValue;
+    }
+    if ((stuff->ordering != Unsorted) && (stuff->ordering != YSorted) &&
+       (stuff->ordering != YXSorted) && (stuff->ordering != YXBanded))
+    {
+       client->errorValue = stuff->ordering;
+        return BadValue;
+    }
+    pScreen = pWin->drawable.pScreen;
+    nrects = ((stuff->length  << 2) - sizeof(xShapeRectanglesReq));
+    if (nrects & 4)
+       return BadLength;
+    nrects >>= 3;
+    prects = (xRectangle *) &stuff[1];
+    ctype = VerifyRectOrder(nrects, prects, (int)stuff->ordering);
+    if (ctype < 0)
+       return BadMatch;
+    srcRgn = RECTS_TO_REGION(pScreen, nrects, prects, ctype);
+
+    if (!pWin->optional)
+       MakeWindowOptional (pWin);
+    if (destBounding)
+       destRgn = &pWin->optional->boundingShape;
+    else
+       destRgn = &pWin->optional->clipShape;
+
+    return RegionOperate (client, pWin, (int)stuff->destKind,
+                         destRgn, srcRgn, (int)stuff->op,
+                         stuff->xOff, stuff->yOff, createDefault);
+}
+
+/**************
+ * ProcShapeMask
+ **************/
+
+static int
+ProcShapeMask (client)
+    register ClientPtr client;
+{
+    WindowPtr          pWin;
+    ScreenPtr          pScreen;
+    REQUEST(xShapeMaskReq);
+    RegionPtr          srcRgn;
+    RegionPtr          *destRgn;
+    PixmapPtr          pPixmap;
+    CreateDftPtr       createDefault;
+    int                        destBounding;
+
+    REQUEST_SIZE_MATCH (xShapeMaskReq);
+    UpdateCurrentTime();
+    pWin = SecurityLookupWindow (stuff->dest, client, SecurityWriteAccess);
+    if (!pWin)
+       return BadWindow;
+    switch (stuff->destKind) {
+    case ShapeBounding:
+       destBounding = 1;
+       createDefault = CreateBoundingShape;
+       break;
+    case ShapeClip:
+       destBounding = 0;
+       createDefault = CreateClipShape;
+       break;
+    default:
+       client->errorValue = stuff->destKind;
+       return BadValue;
+    }
+    pScreen = pWin->drawable.pScreen;
+    if (stuff->src == None)
+       srcRgn = 0;
+    else {
+        pPixmap = (PixmapPtr) SecurityLookupIDByType(client, stuff->src,
+                                               RT_PIXMAP, SecurityReadAccess);
+        if (!pPixmap)
+           return BadPixmap;
+       if (pPixmap->drawable.pScreen != pScreen ||
+           pPixmap->drawable.depth != 1)
+           return BadMatch;
+       srcRgn = BITMAP_TO_REGION(pScreen, pPixmap);
+       if (!srcRgn)
+           return BadAlloc;
+    }
+
+    if (!pWin->optional)
+       MakeWindowOptional (pWin);
+    if (destBounding)
+       destRgn = &pWin->optional->boundingShape;
+    else
+       destRgn = &pWin->optional->clipShape;
+
+    return RegionOperate (client, pWin, (int)stuff->destKind,
+                         destRgn, srcRgn, (int)stuff->op,
+                         stuff->xOff, stuff->yOff, createDefault);
+}
+
+/************
+ * ProcShapeCombine
+ ************/
+
+static int
+ProcShapeCombine (client)
+    register ClientPtr client;
+{
+    WindowPtr          pSrcWin, pDestWin;
+    ScreenPtr          pScreen;
+    REQUEST(xShapeCombineReq);
+    RegionPtr          srcRgn;
+    RegionPtr          *destRgn;
+    CreateDftPtr       createDefault;
+    CreateDftPtr       createSrc;
+    RegionPtr          tmp;
+    int                        destBounding;
+
+    REQUEST_SIZE_MATCH (xShapeCombineReq);
+    UpdateCurrentTime();
+    pDestWin = LookupWindow (stuff->dest, client);
+    if (!pDestWin)
+       return BadWindow;
+    if (!pDestWin->optional)
+       MakeWindowOptional (pDestWin);
+    switch (stuff->destKind) {
+    case ShapeBounding:
+       destBounding = 1;
+       createDefault = CreateBoundingShape;
+       break;
+    case ShapeClip:
+       destBounding = 0;
+       createDefault = CreateClipShape;
+       break;
+    default:
+       client->errorValue = stuff->destKind;
+       return BadValue;
+    }
+    pScreen = pDestWin->drawable.pScreen;
+
+    pSrcWin = LookupWindow (stuff->src, client);
+    if (!pSrcWin)
+       return BadWindow;
+    switch (stuff->srcKind) {
+    case ShapeBounding:
+       srcRgn = wBoundingShape (pSrcWin);
+       createSrc = CreateBoundingShape;
+       break;
+    case ShapeClip:
+       srcRgn = wClipShape (pSrcWin);
+       createSrc = CreateClipShape;
+       break;
+    default:
+       client->errorValue = stuff->srcKind;
+       return BadValue;
+    }
+    if (pSrcWin->drawable.pScreen != pScreen)
+    {
+       return BadMatch;
+    }
+
+    if (srcRgn) {
+        tmp = REGION_CREATE(pScreen, (BoxPtr) 0, 0);
+        REGION_COPY(pScreen, tmp, srcRgn);
+        srcRgn = tmp;
+    } else
+       srcRgn = (*createSrc) (pSrcWin);
+
+    if (!pDestWin->optional)
+       MakeWindowOptional (pDestWin);
+    if (destBounding)
+       destRgn = &pDestWin->optional->boundingShape;
+    else
+       destRgn = &pDestWin->optional->clipShape;
+
+    return RegionOperate (client, pDestWin, (int)stuff->destKind,
+                         destRgn, srcRgn, (int)stuff->op,
+                         stuff->xOff, stuff->yOff, createDefault);
+}
+
+/*************
+ * ProcShapeOffset
+ *************/
+
+static int
+ProcShapeOffset (client)
+    register ClientPtr client;
+{
+    WindowPtr          pWin;
+    ScreenPtr          pScreen;
+    REQUEST(xShapeOffsetReq);
+    RegionPtr          srcRgn;
+
+    REQUEST_SIZE_MATCH (xShapeOffsetReq);
+    UpdateCurrentTime();
+    pWin = LookupWindow (stuff->dest, client);
+    if (!pWin)
+       return BadWindow;
+    switch (stuff->destKind) {
+    case ShapeBounding:
+       srcRgn = wBoundingShape (pWin);
+       break;
+    case ShapeClip:
+       srcRgn = wClipShape(pWin);
+       break;
+    default:
+       client->errorValue = stuff->destKind;
+       return BadValue;
+    }
+    pScreen = pWin->drawable.pScreen;
+    if (srcRgn)
+    {
+        REGION_TRANSLATE(pScreen, srcRgn, stuff->xOff, stuff->yOff);
+        (*pScreen->SetShape) (pWin);
+    }
+    SendShapeNotify (pWin, (int)stuff->destKind);
+    return Success;
+}
+
+static int
+ProcShapeQueryExtents (client)
+    register ClientPtr client;
+{
+    REQUEST(xShapeQueryExtentsReq);
+    WindowPtr          pWin;
+    xShapeQueryExtentsReply    rep;
+    BoxRec             extents, *pExtents;
+    register int       n;
+
+    REQUEST_SIZE_MATCH (xShapeQueryExtentsReq);
+    pWin = LookupWindow (stuff->window, client);
+    if (!pWin)
+       return BadWindow;
+    rep.type = X_Reply;
+    rep.length = 0;
+    rep.sequenceNumber = client->sequence;
+    rep.boundingShaped = (wBoundingShape(pWin) != 0);
+    rep.clipShaped = (wClipShape(pWin) != 0);
+    if (wBoundingShape(pWin)) {
+     /* this is done in two steps because of a compiler bug on SunOS 4.1.3 */
+       pExtents = REGION_EXTENTS(pWin->drawable.pScreen, wBoundingShape(pWin));
+       extents = *pExtents;
+    } else {
+       extents.x1 = -wBorderWidth (pWin);
+       extents.y1 = -wBorderWidth (pWin);
+       extents.x2 = pWin->drawable.width + wBorderWidth (pWin);
+       extents.y2 = pWin->drawable.height + wBorderWidth (pWin);
+    }
+    rep.xBoundingShape = extents.x1;
+    rep.yBoundingShape = extents.y1;
+    rep.widthBoundingShape = extents.x2 - extents.x1;
+    rep.heightBoundingShape = extents.y2 - extents.y1;
+    if (wClipShape(pWin)) {
+     /* this is done in two steps because of a compiler bug on SunOS 4.1.3 */
+       pExtents = REGION_EXTENTS(pWin->drawable.pScreen, wClipShape(pWin));
+       extents = *pExtents;
+    } else {
+       extents.x1 = 0;
+       extents.y1 = 0;
+       extents.x2 = pWin->drawable.width;
+       extents.y2 = pWin->drawable.height;
+    }
+    rep.xClipShape = extents.x1;
+    rep.yClipShape = extents.y1;
+    rep.widthClipShape = extents.x2 - extents.x1;
+    rep.heightClipShape = extents.y2 - extents.y1;
+    if (client->swapped) {
+       swaps(&rep.sequenceNumber, n);
+       swapl(&rep.length, n);
+       swaps(&rep.xBoundingShape, n);
+       swaps(&rep.yBoundingShape, n);
+       swaps(&rep.widthBoundingShape, n);
+       swaps(&rep.heightBoundingShape, n);
+       swaps(&rep.xClipShape, n);
+       swaps(&rep.yClipShape, n);
+       swaps(&rep.widthClipShape, n);
+       swaps(&rep.heightClipShape, n);
+    }
+    WriteToClient(client, sizeof (xShapeQueryExtentsReply), (char *)&rep);
+    return (client->noClientException);
+}
+
+/*ARGSUSED*/
+static int
+ShapeFreeClient (data, id)
+    pointer        data;
+    XID                    id;
+{
+    ShapeEventPtr   pShapeEvent;
+    WindowPtr      pWin;
+    ShapeEventPtr   *pHead, pCur, pPrev;
+
+    pShapeEvent = (ShapeEventPtr) data;
+    pWin = pShapeEvent->window;
+    pHead = (ShapeEventPtr *) LookupIDByType(pWin->drawable.id, EventType);
+    if (pHead) {
+       pPrev = 0;
+       for (pCur = *pHead; pCur && pCur != pShapeEvent; pCur=pCur->next)
+           pPrev = pCur;
+       if (pCur)
+       {
+           if (pPrev)
+               pPrev->next = pShapeEvent->next;
+           else
+               *pHead = pShapeEvent->next;
+       }
+    }
+    xfree ((pointer) pShapeEvent);
+    return Success;
+}
+
+/*ARGSUSED*/
+static int
+ShapeFreeEvents (data, id)
+    pointer        data;
+    XID                    id;
+{
+    ShapeEventPtr   *pHead, pCur, pNext;
+
+    pHead = (ShapeEventPtr *) data;
+    for (pCur = *pHead; pCur; pCur = pNext) {
+       pNext = pCur->next;
+       FreeResource (pCur->clientResource, ClientType);
+       xfree ((pointer) pCur);
+    }
+    xfree ((pointer) pHead);
+    return Success;
+}
+
+static int
+ProcShapeSelectInput (client)
+    register ClientPtr client;
+{
+    REQUEST(xShapeSelectInputReq);
+    WindowPtr          pWin;
+    ShapeEventPtr      pShapeEvent, pNewShapeEvent, *pHead;
+    XID                        clientResource;
+
+    REQUEST_SIZE_MATCH (xShapeSelectInputReq);
+    pWin = SecurityLookupWindow (stuff->window, client, SecurityWriteAccess);
+    if (!pWin)
+       return BadWindow;
+    pHead = (ShapeEventPtr *)SecurityLookupIDByType(client,
+                       pWin->drawable.id, EventType, SecurityWriteAccess);
+    switch (stuff->enable) {
+    case xTrue:
+       if (pHead) {
+
+           /* check for existing entry. */
+           for (pShapeEvent = *pHead;
+                pShapeEvent;
+                pShapeEvent = pShapeEvent->next)
+           {
+               if (pShapeEvent->client == client)
+                   return Success;
+           }
+       }
+
+       /* build the entry */
+       pNewShapeEvent = (ShapeEventPtr)
+                           xalloc (sizeof (ShapeEventRec));
+       if (!pNewShapeEvent)
+           return BadAlloc;
+       pNewShapeEvent->next = 0;
+       pNewShapeEvent->client = client;
+       pNewShapeEvent->window = pWin;
+       /*
+        * add a resource that will be deleted when
+        * the client goes away
+        */
+       clientResource = FakeClientID (client->index);
+       pNewShapeEvent->clientResource = clientResource;
+       if (!AddResource (clientResource, ClientType, (pointer)pNewShapeEvent))
+           return BadAlloc;
+       /*
+        * create a resource to contain a pointer to the list
+        * of clients selecting input.  This must be indirect as
+        * the list may be arbitrarily rearranged which cannot be
+        * done through the resource database.
+        */
+       if (!pHead)
+       {
+           pHead = (ShapeEventPtr *) xalloc (sizeof (ShapeEventPtr));
+           if (!pHead ||
+               !AddResource (pWin->drawable.id, EventType, (pointer)pHead))
+           {
+               FreeResource (clientResource, RT_NONE);
+               return BadAlloc;
+           }
+           *pHead = 0;
+       }
+       pNewShapeEvent->next = *pHead;
+       *pHead = pNewShapeEvent;
+       break;
+    case xFalse:
+       /* delete the interest */
+       if (pHead) {
+           pNewShapeEvent = 0;
+           for (pShapeEvent = *pHead; pShapeEvent; pShapeEvent = pShapeEvent->next) {
+               if (pShapeEvent->client == client)
+                   break;
+               pNewShapeEvent = pShapeEvent;
+           }
+           if (pShapeEvent) {
+               FreeResource (pShapeEvent->clientResource, ClientType);
+               if (pNewShapeEvent)
+                   pNewShapeEvent->next = pShapeEvent->next;
+               else
+                   *pHead = pShapeEvent->next;
+               xfree (pShapeEvent);
+           }
+       }
+       break;
+    default:
+       client->errorValue = stuff->enable;
+       return BadValue;
+    }
+    return Success;
+}
+
+/*
+ * deliver the event
+ */
+
+static void
+SendShapeNotify (pWin, which)
+    WindowPtr  pWin;
+    int                which;
+{
+    ShapeEventPtr      *pHead, pShapeEvent;
+    ClientPtr          client;
+    xShapeNotifyEvent  se;
+    BoxRec             extents;
+    RegionPtr          region;
+    BYTE               shaped;
+
+    pHead = (ShapeEventPtr *) LookupIDByType(pWin->drawable.id, EventType);
+    if (!pHead)
+       return;
+    if (which == ShapeBounding) {
+       region = wBoundingShape(pWin);
+       if (region) {
+           extents = *REGION_EXTENTS(pWin->drawable.pScreen, region);
+           shaped = xTrue;
+       } else {
+           extents.x1 = -wBorderWidth (pWin);
+           extents.y1 = -wBorderWidth (pWin);
+           extents.x2 = pWin->drawable.width + wBorderWidth (pWin);
+           extents.y2 = pWin->drawable.height + wBorderWidth (pWin);
+           shaped = xFalse;
+       }
+    } else {
+       region = wClipShape(pWin);
+       if (region) {
+           extents = *REGION_EXTENTS(pWin->drawable.pScreen, region);
+           shaped = xTrue;
+       } else {
+           extents.x1 = 0;
+           extents.y1 = 0;
+           extents.x2 = pWin->drawable.width;
+           extents.y2 = pWin->drawable.height;
+           shaped = xFalse;
+       }
+    }
+    for (pShapeEvent = *pHead; pShapeEvent; pShapeEvent = pShapeEvent->next) {
+       client = pShapeEvent->client;
+       if (client == serverClient || client->clientGone)
+           continue;
+       se.type = ShapeNotify + ShapeEventBase;
+       se.kind = which;
+       se.window = pWin->drawable.id;
+       se.sequenceNumber = client->sequence;
+       se.x = extents.x1;
+       se.y = extents.y1;
+       se.width = extents.x2 - extents.x1;
+       se.height = extents.y2 - extents.y1;
+       se.time = currentTime.milliseconds;
+       se.shaped = shaped;
+       WriteEventsToClient (client, 1, (xEvent *) &se);
+    }
+}
+
+static int
+ProcShapeInputSelected (client)
+    register ClientPtr client;
+{
+    REQUEST(xShapeInputSelectedReq);
+    WindowPtr          pWin;
+    ShapeEventPtr      pShapeEvent, *pHead;
+    int                        enabled;
+    xShapeInputSelectedReply   rep;
+    register int               n;
+
+    REQUEST_SIZE_MATCH (xShapeInputSelectedReq);
+    pWin = LookupWindow (stuff->window, client);
+    if (!pWin)
+       return BadWindow;
+    pHead = (ShapeEventPtr *) SecurityLookupIDByType(client,
+                       pWin->drawable.id, EventType, SecurityReadAccess);
+    enabled = xFalse;
+    if (pHead) {
+       for (pShapeEvent = *pHead;
+            pShapeEvent;
+            pShapeEvent = pShapeEvent->next)
+       {
+           if (pShapeEvent->client == client) {
+               enabled = xTrue;
+               break;
+           }
+       }
+    }
+    rep.type = X_Reply;
+    rep.length = 0;
+    rep.sequenceNumber = client->sequence;
+    rep.enabled = enabled;
+    if (client->swapped) {
+       swaps (&rep.sequenceNumber, n);
+       swapl (&rep.length, n);
+    }
+    WriteToClient (client, sizeof (xShapeInputSelectedReply), (char *) &rep);
+    return (client->noClientException);
+}
+
+static int
+ProcShapeGetRectangles (client)
+    register ClientPtr client;
+{
+    REQUEST(xShapeGetRectanglesReq);
+    WindowPtr                  pWin;
+    xShapeGetRectanglesReply   rep;
+    xRectangle                 *rects;
+    int                                nrects, i;
+    RegionPtr                  region;
+    register int               n;
+
+    REQUEST_SIZE_MATCH(xShapeGetRectanglesReq);
+    pWin = LookupWindow (stuff->window, client);
+    if (!pWin)
+       return BadWindow;
+    switch (stuff->kind) {
+    case ShapeBounding:
+       region = wBoundingShape(pWin);
+       break;
+    case ShapeClip:
+       region = wClipShape(pWin);
+       break;
+    default:
+       client->errorValue = stuff->kind;
+       return BadValue;
+    }
+    if (!region) {
+       nrects = 1;
+       rects = (xRectangle *) ALLOCATE_LOCAL (sizeof (xRectangle));
+       if (!rects)
+           return BadAlloc;
+       switch (stuff->kind) {
+       case ShapeBounding:
+           rects->x = - (int) wBorderWidth (pWin);
+           rects->y = - (int) wBorderWidth (pWin);
+           rects->width = pWin->drawable.width + wBorderWidth (pWin);
+           rects->height = pWin->drawable.height + wBorderWidth (pWin);
+           break;
+       case ShapeClip:
+           rects->x = 0;
+           rects->y = 0;
+           rects->width = pWin->drawable.width;
+           rects->height = pWin->drawable.height;
+           break;
+       }
+    } else {
+       BoxPtr box;
+       nrects = REGION_NUM_RECTS(region);
+       box = REGION_RECTS(region);
+       rects = (xRectangle *) ALLOCATE_LOCAL (nrects * sizeof (xRectangle));
+       if (!rects && nrects)
+           return BadAlloc;
+       for (i = 0; i < nrects; i++, box++) {
+           rects[i].x = box->x1;
+           rects[i].y = box->y1;
+           rects[i].width = box->x2 - box->x1;
+           rects[i].height = box->y2 - box->y1;
+       }
+    }
+    rep.type = X_Reply;
+    rep.sequenceNumber = client->sequence;
+    rep.length = (nrects * sizeof (xRectangle)) >> 2;
+    rep.ordering = YXBanded;
+    rep.nrects = nrects;
+    if (client->swapped) {
+       swaps (&rep.sequenceNumber, n);
+       swapl (&rep.length, n);
+       swapl (&rep.nrects, n);
+       SwapShorts ((short *)rects, (unsigned long)nrects * 4);
+    }
+    WriteToClient (client, sizeof (rep), (char *) &rep);
+    WriteToClient (client, nrects * sizeof (xRectangle), (char *) rects);
+    DEALLOCATE_LOCAL (rects);
+    return client->noClientException;
+}
+
+static int
+ProcShapeDispatch (client)
+    register ClientPtr client;
+{
+    REQUEST(xReq);
+    switch (stuff->data) {
+    case X_ShapeQueryVersion:
+       return ProcShapeQueryVersion (client);
+    case X_ShapeRectangles:
+       return ProcShapeRectangles (client);
+    case X_ShapeMask:
+       return ProcShapeMask (client);
+    case X_ShapeCombine:
+       return ProcShapeCombine (client);
+    case X_ShapeOffset:
+       return ProcShapeOffset (client);
+    case X_ShapeQueryExtents:
+       return ProcShapeQueryExtents (client);
+    case X_ShapeSelectInput:
+       return ProcShapeSelectInput (client);
+    case X_ShapeInputSelected:
+       return ProcShapeInputSelected (client);
+    case X_ShapeGetRectangles:
+       return ProcShapeGetRectangles (client);
+    default:
+       return BadRequest;
+    }
+}
+
+static void
+SShapeNotifyEvent(from, to)
+    xShapeNotifyEvent *from, *to;
+{
+    to->type = from->type;
+    to->kind = from->kind;
+    cpswapl (from->window, to->window);
+    cpswaps (from->sequenceNumber, to->sequenceNumber);
+    cpswaps (from->x, to->x);
+    cpswaps (from->y, to->y);
+    cpswaps (from->width, to->width);
+    cpswaps (from->height, to->height);
+    cpswapl (from->time, to->time);
+    to->shaped = from->shaped;
+}
+
+static int
+SProcShapeQueryVersion (client)
+    register ClientPtr client;
+{
+    register int    n;
+    REQUEST (xShapeQueryVersionReq);
+
+    swaps (&stuff->length, n);
+    return ProcShapeQueryVersion (client);
+}
+
+static int
+SProcShapeRectangles (client)
+    register ClientPtr client;
+{
+    register char   n;
+    REQUEST (xShapeRectanglesReq);
+
+    swaps (&stuff->length, n);
+    REQUEST_AT_LEAST_SIZE (xShapeRectanglesReq);
+    swapl (&stuff->dest, n);
+    swaps (&stuff->xOff, n);
+    swaps (&stuff->yOff, n);
+    SwapRestS(stuff);
+    return ProcShapeRectangles (client);
+}
+
+static int
+SProcShapeMask (client)
+    register ClientPtr client;
+{
+    register char   n;
+    REQUEST (xShapeMaskReq);
+
+    swaps (&stuff->length, n);
+    REQUEST_SIZE_MATCH (xShapeMaskReq);
+    swapl (&stuff->dest, n);
+    swaps (&stuff->xOff, n);
+    swaps (&stuff->yOff, n);
+    swapl (&stuff->src, n);
+    return ProcShapeMask (client);
+}
+
+static int
+SProcShapeCombine (client)
+    register ClientPtr client;
+{
+    register char   n;
+    REQUEST (xShapeCombineReq);
+
+    swaps (&stuff->length, n);
+    REQUEST_SIZE_MATCH (xShapeCombineReq);
+    swapl (&stuff->dest, n);
+    swaps (&stuff->xOff, n);
+    swaps (&stuff->yOff, n);
+    swapl (&stuff->src, n);
+    return ProcShapeCombine (client);
+}
+
+static int
+SProcShapeOffset (client)
+    register ClientPtr client;
+{
+    register char   n;
+    REQUEST (xShapeOffsetReq);
+
+    swaps (&stuff->length, n);
+    REQUEST_SIZE_MATCH (xShapeOffsetReq);
+    swapl (&stuff->dest, n);
+    swaps (&stuff->xOff, n);
+    swaps (&stuff->yOff, n);
+    return ProcShapeOffset (client);
+}
+
+static int
+SProcShapeQueryExtents (client)
+    register ClientPtr client;
+{
+    register char   n;
+    REQUEST (xShapeQueryExtentsReq);
+
+    swaps (&stuff->length, n);
+    REQUEST_SIZE_MATCH (xShapeQueryExtentsReq);
+    swapl (&stuff->window, n);
+    return ProcShapeQueryExtents (client);
+}
+
+static int
+SProcShapeSelectInput (client)
+    register ClientPtr client;
+{
+    register char   n;
+    REQUEST (xShapeSelectInputReq);
+
+    swaps (&stuff->length, n);
+    REQUEST_SIZE_MATCH (xShapeSelectInputReq);
+    swapl (&stuff->window, n);
+    return ProcShapeSelectInput (client);
+}
+
+static int
+SProcShapeInputSelected (client)
+    register ClientPtr client;
+{
+    register int    n;
+    REQUEST (xShapeInputSelectedReq);
+
+    swaps (&stuff->length, n);
+    REQUEST_SIZE_MATCH (xShapeInputSelectedReq);
+    swapl (&stuff->window, n);
+    return ProcShapeInputSelected (client);
+}
+
+static int
+SProcShapeGetRectangles (client)
+    register ClientPtr client;
+{
+    REQUEST(xShapeGetRectanglesReq);
+    register char   n;
+
+    swaps (&stuff->length, n);
+    REQUEST_SIZE_MATCH(xShapeGetRectanglesReq);
+    swapl (&stuff->window, n);
+    return ProcShapeGetRectangles (client);
+}
+
+static int
+SProcShapeDispatch (client)
+    register ClientPtr client;
+{
+    REQUEST(xReq);
+    switch (stuff->data) {
+    case X_ShapeQueryVersion:
+       return SProcShapeQueryVersion (client);
+    case X_ShapeRectangles:
+       return SProcShapeRectangles (client);
+    case X_ShapeMask:
+       return SProcShapeMask (client);
+    case X_ShapeCombine:
+       return SProcShapeCombine (client);
+    case X_ShapeOffset:
+       return SProcShapeOffset (client);
+    case X_ShapeQueryExtents:
+       return SProcShapeQueryExtents (client);
+    case X_ShapeSelectInput:
+       return SProcShapeSelectInput (client);
+    case X_ShapeInputSelected:
+       return SProcShapeInputSelected (client);
+    case X_ShapeGetRectangles:
+       return SProcShapeGetRectangles (client);
+    default:
+       return BadRequest;
+    }
+}
diff --git a/Xserver/programs/Xserver/Xext/shm.c b/Xserver/programs/Xserver/Xext/shm.c
new file mode 100644 (file)
index 0000000..5501f94
--- /dev/null
@@ -0,0 +1,1089 @@
+/************************************************************
+
+Copyright (c) 1989  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+********************************************************/
+
+/* THIS IS NOT AN X CONSORTIUM STANDARD */
+
+/* $XConsortium: shm.c,v 1.25 95/04/06 16:00:55 dpw Exp $ */
+/* $XFree86: xc/programs/Xserver/Xext/shm.c,v 3.8 1997/01/18 06:52:59 dawes Exp $ */
+
+#include <sys/types.h>
+#ifndef Lynx
+#include <sys/ipc.h>
+#include <sys/shm.h>
+#else
+#include <ipc.h>
+#include <shm.h>
+#endif
+#define NEED_REPLIES
+#define NEED_EVENTS
+#include "X.h"
+#include "Xproto.h"
+#include "misc.h"
+#include "os.h"
+#include "dixstruct.h"
+#include "resource.h"
+#include "scrnintstr.h"
+#include "windowstr.h"
+#include "pixmapstr.h"
+#include "gcstruct.h"
+#include "extnsionst.h"
+#include "servermd.h"
+#define _XSHM_SERVER_
+#include "shmstr.h"
+#include "Xfuncproto.h"
+
+typedef struct _ShmDesc {
+    struct _ShmDesc *next;
+    int shmid;
+    int refcnt;
+    char *addr;
+    Bool writable;
+    unsigned long size;
+} ShmDescRec, *ShmDescPtr;
+
+static void miShmPutImage(XSHM_PUT_IMAGE_ARGS);
+static void fbShmPutImage(XSHM_PUT_IMAGE_ARGS);
+static PixmapPtr fbShmCreatePixmap(XSHM_CREATE_PIXMAP_ARGS);
+static int ShmDetachSegment(
+#if NeedFunctionPrototypes
+    pointer            /* value */,
+    XID                        /* shmseg */
+#endif
+    );
+static void ShmResetProc(
+#if NeedFunctionPrototypes
+    ExtensionEntry *   /* extEntry */
+#endif
+    );
+static void SShmCompletionEvent(
+#if NeedFunctionPrototypes
+    xShmCompletionEvent * /* from */,
+    xShmCompletionEvent * /* to */
+#endif
+    );
+
+static DISPATCH_PROC(ProcShmAttach);
+static DISPATCH_PROC(ProcShmCreatePixmap);
+static DISPATCH_PROC(ProcShmDetach);
+static DISPATCH_PROC(ProcShmDispatch);
+static DISPATCH_PROC(ProcShmGetImage);
+static DISPATCH_PROC(ProcShmGetImage);
+static DISPATCH_PROC(ProcShmGetImage);
+static DISPATCH_PROC(ProcShmPutImage);
+static DISPATCH_PROC(ProcShmQueryVersion);
+static DISPATCH_PROC(SProcShmAttach);
+static DISPATCH_PROC(SProcShmCreatePixmap);
+static DISPATCH_PROC(SProcShmDetach);
+static DISPATCH_PROC(SProcShmDispatch);
+static DISPATCH_PROC(SProcShmGetImage);
+static DISPATCH_PROC(SProcShmPutImage);
+static DISPATCH_PROC(SProcShmQueryVersion);
+
+static unsigned char ShmReqCode;
+static int ShmCompletionCode;
+static int BadShmSegCode;
+static RESTYPE ShmSegType, ShmPixType;
+static ShmDescPtr Shmsegs;
+static Bool sharedPixmaps;
+static int pixmapFormat;
+static int shmPixFormat[MAXSCREENS];
+static ShmFuncsPtr shmFuncs[MAXSCREENS];
+static ShmFuncs miFuncs = {NULL, miShmPutImage};
+static ShmFuncs fbFuncs = {fbShmCreatePixmap, fbShmPutImage};
+
+#define VERIFY_SHMSEG(shmseg,shmdesc,client) \
+{ \
+    shmdesc = (ShmDescPtr)LookupIDByType(shmseg, ShmSegType); \
+    if (!shmdesc) \
+    { \
+       client->errorValue = shmseg; \
+       return BadShmSegCode; \
+    } \
+}
+
+#define VERIFY_SHMPTR(shmseg,offset,needwrite,shmdesc,client) \
+{ \
+    VERIFY_SHMSEG(shmseg, shmdesc, client); \
+    if ((offset & 3) || (offset > shmdesc->size)) \
+    { \
+       client->errorValue = offset; \
+       return BadValue; \
+    } \
+    if (needwrite && !shmdesc->writable) \
+       return BadAccess; \
+}
+
+#define VERIFY_SHMSIZE(shmdesc,offset,len,client) \
+{ \
+    if ((offset + len) > shmdesc->size) \
+    { \
+       return BadAccess; \
+    } \
+}
+
+
+#if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__)
+#include <sys/signal.h>
+
+static Bool badSysCall = FALSE;
+
+static void
+SigSysHandler(signo)
+int signo;
+{
+    badSysCall = TRUE;
+}
+
+static Bool CheckForShmSyscall()
+{
+    void (*oldHandler)();
+    int shmid = -1;
+
+    /* If no SHM support in the kernel, the bad syscall will generate SIGSYS */
+    oldHandler = signal(SIGSYS, SigSysHandler);
+
+    badSysCall = FALSE;
+    shmid = shmget(IPC_PRIVATE, 4096, IPC_CREAT);
+    /* Clean up */
+    if (shmid != -1)
+    {
+       shmctl(shmid, IPC_RMID, (struct shmid_ds *)NULL);
+    }
+    signal(SIGSYS, oldHandler);
+    return(!badSysCall);
+}
+#endif
+    
+void
+ShmExtensionInit()
+{
+    ExtensionEntry *extEntry;
+    int i;
+
+#if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__)
+    if (!CheckForShmSyscall())
+    {
+       ErrorF("MIT-SHM extension disabled due to lack of kernel support\n");
+       return;
+    }
+#endif
+
+#ifdef INTERNAL_VS_EXTERNAL_PADDING
+    sharedPixmaps = xFalse;
+    pixmapFormat = 0;
+#else
+    sharedPixmaps = xTrue;
+    pixmapFormat = shmPixFormat[0];
+    for (i = 0; i < screenInfo.numScreens; i++)
+    {
+       if (!shmFuncs[i])
+           shmFuncs[i] = &miFuncs;
+       if (!shmFuncs[i]->CreatePixmap)
+           sharedPixmaps = xFalse;
+       if (shmPixFormat[i] && (shmPixFormat[i] != pixmapFormat))
+       {
+           sharedPixmaps = xFalse;
+           pixmapFormat = 0;
+       }
+    }
+    if (!pixmapFormat)
+       pixmapFormat = ZPixmap;
+#endif
+    ShmSegType = CreateNewResourceType(ShmDetachSegment);
+    ShmPixType = CreateNewResourceType(ShmDetachSegment);
+    if (ShmSegType && ShmPixType &&
+       (extEntry = AddExtension(SHMNAME, ShmNumberEvents, ShmNumberErrors,
+                                ProcShmDispatch, SProcShmDispatch,
+                                ShmResetProc, StandardMinorOpcode)))
+    {
+       ShmReqCode = (unsigned char)extEntry->base;
+       ShmCompletionCode = extEntry->eventBase;
+       BadShmSegCode = extEntry->errorBase;
+       EventSwapVector[ShmCompletionCode] = (EventSwapPtr) SShmCompletionEvent;
+    }
+}
+
+/*ARGSUSED*/
+static void
+ShmResetProc (extEntry)
+ExtensionEntry *extEntry;
+{
+    int i;
+
+    for (i = 0; i < MAXSCREENS; i++)
+    {
+       shmFuncs[i] = (ShmFuncsPtr)NULL;
+       shmPixFormat[i] = 0;
+    }
+}
+
+void
+ShmRegisterFuncs(pScreen, funcs)
+    ScreenPtr pScreen;
+    ShmFuncsPtr funcs;
+{
+    shmFuncs[pScreen->myNum] = funcs;
+}
+
+void
+ShmSetPixmapFormat(pScreen, format)
+    ScreenPtr pScreen;
+    int format;
+{
+    shmPixFormat[pScreen->myNum] = format;
+}
+
+void
+ShmRegisterFbFuncs(pScreen)
+    ScreenPtr pScreen;
+{
+    shmFuncs[pScreen->myNum] = &fbFuncs;
+}
+
+static int
+ProcShmQueryVersion(client)
+    register ClientPtr client;
+{
+    xShmQueryVersionReply rep;
+    register int n;
+
+    REQUEST_SIZE_MATCH(xShmQueryVersionReq);
+    rep.type = X_Reply;
+    rep.length = 0;
+    rep.sequenceNumber = client->sequence;
+    rep.sharedPixmaps = sharedPixmaps;
+    rep.pixmapFormat = pixmapFormat;
+    rep.majorVersion = SHM_MAJOR_VERSION;
+    rep.minorVersion = SHM_MINOR_VERSION;
+    rep.uid = geteuid();
+    rep.gid = getegid();
+    if (client->swapped) {
+       swaps(&rep.sequenceNumber, n);
+       swapl(&rep.length, n);
+       swaps(&rep.majorVersion, n);
+       swaps(&rep.minorVersion, n);
+       swaps(&rep.uid, n);
+       swaps(&rep.gid, n);
+    }
+    WriteToClient(client, sizeof(xShmQueryVersionReply), (char *)&rep);
+    return (client->noClientException);
+}
+
+static int
+ProcShmAttach(client)
+    register ClientPtr client;
+{
+    struct shmid_ds buf;
+    ShmDescPtr shmdesc;
+    REQUEST(xShmAttachReq);
+
+    REQUEST_SIZE_MATCH(xShmAttachReq);
+    LEGAL_NEW_RESOURCE(stuff->shmseg, client);
+    if ((stuff->readOnly != xTrue) && (stuff->readOnly != xFalse))
+    {
+       client->errorValue = stuff->readOnly;
+        return(BadValue);
+    }
+    for (shmdesc = Shmsegs;
+        shmdesc && (shmdesc->shmid != stuff->shmid);
+        shmdesc = shmdesc->next)
+       ;
+    if (shmdesc)
+    {
+       if (!stuff->readOnly && !shmdesc->writable)
+           return BadAccess;
+       shmdesc->refcnt++;
+    }
+    else
+    {
+       shmdesc = (ShmDescPtr) xalloc(sizeof(ShmDescRec));
+       if (!shmdesc)
+           return BadAlloc;
+       shmdesc->addr = shmat(stuff->shmid, 0,
+                             stuff->readOnly ? SHM_RDONLY : 0);
+       if ((shmdesc->addr == ((char *)-1)) ||
+           shmctl(stuff->shmid, IPC_STAT, &buf))
+       {
+           xfree(shmdesc);
+           return BadAccess;
+       }
+       shmdesc->shmid = stuff->shmid;
+       shmdesc->refcnt = 1;
+       shmdesc->writable = !stuff->readOnly;
+       shmdesc->size = buf.shm_segsz;
+       shmdesc->next = Shmsegs;
+       Shmsegs = shmdesc;
+    }
+    if (!AddResource(stuff->shmseg, ShmSegType, (pointer)shmdesc))
+       return BadAlloc;
+    return(client->noClientException);
+}
+
+/*ARGSUSED*/
+static int
+ShmDetachSegment(value, shmseg)
+    pointer value; /* must conform to DeleteType */
+    XID shmseg;
+{
+    ShmDescPtr shmdesc = (ShmDescPtr)value;
+    ShmDescPtr *prev;
+
+    if (--shmdesc->refcnt)
+       return TRUE;
+    shmdt(shmdesc->addr);
+    for (prev = &Shmsegs; *prev != shmdesc; prev = &(*prev)->next)
+       ;
+    *prev = shmdesc->next;
+    xfree(shmdesc);
+    return Success;
+}
+
+static int
+ProcShmDetach(client)
+    register ClientPtr client;
+{
+    ShmDescPtr shmdesc;
+    REQUEST(xShmDetachReq);
+
+    REQUEST_SIZE_MATCH(xShmDetachReq);
+    VERIFY_SHMSEG(stuff->shmseg, shmdesc, client);
+    FreeResource(stuff->shmseg, RT_NONE);
+    return(client->noClientException);
+}
+
+static void
+miShmPutImage(dst, pGC, depth, format, w, h, sx, sy, sw, sh, dx, dy, data)
+    DrawablePtr dst;
+    GCPtr      pGC;
+    int                depth, w, h, sx, sy, sw, sh, dx, dy;
+    unsigned int format;
+    char       *data;
+{
+    PixmapPtr pmap;
+    GCPtr putGC;
+
+    putGC = GetScratchGC(depth, dst->pScreen);
+    if (!putGC)
+       return;
+    pmap = (*dst->pScreen->CreatePixmap)(dst->pScreen, sw, sh, depth);
+    if (!pmap)
+    {
+       FreeScratchGC(putGC);
+       return;
+    }
+    ValidateGC((DrawablePtr)pmap, putGC);
+    (*putGC->ops->PutImage)((DrawablePtr)pmap, putGC, depth, -sx, -sy, w, h, 0,
+                           (format == XYPixmap) ? XYPixmap : ZPixmap, data);
+    FreeScratchGC(putGC);
+    if (format == XYBitmap)
+       (void)(*pGC->ops->CopyPlane)((DrawablePtr)pmap, dst, pGC, 0, 0, sw, sh,
+                                    dx, dy, 1L);
+    else
+       (void)(*pGC->ops->CopyArea)((DrawablePtr)pmap, dst, pGC, 0, 0, sw, sh,
+                                   dx, dy);
+    (*pmap->drawable.pScreen->DestroyPixmap)(pmap);
+}
+
+static void
+fbShmPutImage(dst, pGC, depth, format, w, h, sx, sy, sw, sh, dx, dy, data)
+    DrawablePtr dst;
+    GCPtr      pGC;
+    int                depth, w, h, sx, sy, sw, sh, dx, dy;
+    unsigned int format;
+    char       *data;
+{
+    if ((format == ZPixmap) || (depth == 1))
+    {
+       PixmapPtr pPixmap;
+
+       pPixmap = GetScratchPixmapHeader(dst->pScreen, w, h, depth,
+                       /*XXX*/depth, PixmapBytePad(w, depth), (pointer)data);
+       if (!pPixmap)
+           return;
+       if (format == XYBitmap)
+           (void)(*pGC->ops->CopyPlane)((DrawablePtr)pPixmap, dst, pGC,
+                                        sx, sy, sw, sh, dx, dy, 1L);
+       else
+           (void)(*pGC->ops->CopyArea)((DrawablePtr)pPixmap, dst, pGC,
+                                       sx, sy, sw, sh, dx, dy);
+       FreeScratchPixmapHeader(pPixmap);
+    }
+    else
+       miShmPutImage(dst, pGC, depth, format, w, h, sx, sy, sw, sh, dx, dy,
+                     data);
+}
+
+static int
+ProcShmPutImage(client)
+    register ClientPtr client;
+{
+    register GCPtr pGC;
+    register DrawablePtr pDraw;
+    long length;
+#ifdef INTERNAL_VS_EXTERNAL_PADDING
+    long lengthProto;
+    char *tmpImage;
+    int  tmpAlloced = 0;
+#endif
+    ShmDescPtr shmdesc;
+    REQUEST(xShmPutImageReq);
+
+    REQUEST_SIZE_MATCH(xShmPutImageReq);
+    VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, pGC, client);
+    VERIFY_SHMPTR(stuff->shmseg, stuff->offset, FALSE, shmdesc, client);
+    if ((stuff->sendEvent != xTrue) && (stuff->sendEvent != xFalse))
+       return BadValue;
+    if (stuff->format == XYBitmap)
+    {
+        if (stuff->depth != 1)
+            return BadMatch;
+        length = PixmapBytePad(stuff->totalWidth, 1);
+#ifdef INTERNAL_VS_EXTERNAL_PADDING
+        lengthProto = PixmapBytePadProto(stuff->totalWidth, 1);
+#endif
+    }
+    else if (stuff->format == XYPixmap)
+    {
+        if (pDraw->depth != stuff->depth)
+            return BadMatch;
+        length = PixmapBytePad(stuff->totalWidth, 1);
+       length *= stuff->depth;
+#ifdef INTERNAL_VS_EXTERNAL_PADDING
+        lengthProto = PixmapBytePadProto(stuff->totalWidth, 1);
+       lengthProto *= stuff->depth;
+#endif
+    }
+    else if (stuff->format == ZPixmap)
+    {
+        if (pDraw->depth != stuff->depth)
+            return BadMatch;
+        length = PixmapBytePad(stuff->totalWidth, stuff->depth);
+#ifdef INTERNAL_VS_EXTERNAL_PADDING
+        lengthProto = PixmapBytePadProto(stuff->totalWidth, stuff->depth);
+#endif
+    }
+    else
+    {
+       client->errorValue = stuff->format;
+        return BadValue;
+    }
+
+#ifdef INTERNAL_VS_EXTERNAL_PADDING
+    VERIFY_SHMSIZE(shmdesc, stuff->offset, lengthProto * stuff->totalHeight,
+                  client);
+#else
+    VERIFY_SHMSIZE(shmdesc, stuff->offset, length * stuff->totalHeight,
+                  client);
+#endif
+    if (stuff->srcX > stuff->totalWidth)
+    {
+       client->errorValue = stuff->srcX;
+       return BadValue;
+    }
+    if (stuff->srcY > stuff->totalHeight)
+    {
+       client->errorValue = stuff->srcY;
+       return BadValue;
+    }
+    if ((stuff->srcX + stuff->srcWidth) > stuff->totalWidth)
+    {
+       client->errorValue = stuff->srcWidth;
+       return BadValue;
+    }
+    if ((stuff->srcY + stuff->srcHeight) > stuff->totalHeight)
+    {
+       client->errorValue = stuff->srcHeight;
+       return BadValue;
+    }
+
+#ifdef INTERNAL_VS_EXTERNAL_PADDING
+    /* handle 64 bit case where protocol may pad to 32 and we want 64 
+     * In this case, length is what the server wants and lengthProto is
+     * what the protocol thinks it is.  If the the two are different,
+     * copy the protocol version (i.e. the memory shared between the 
+     * server and the client) to a version with a scanline pad of 64.
+     */
+    if (length != lengthProto) 
+    {
+       register int    i;
+       char            * stuffptr, /* pointer into protocol data */
+                       * tmpptr;   /* new location to copy to */
+
+        if(!(tmpImage = (char *) ALLOCATE_LOCAL(length*stuff->totalHeight)))
+            return (BadAlloc);
+       tmpAlloced = 1;
+    
+       bzero(tmpImage,length*stuff->totalHeight);
+    
+       if (stuff->format == XYPixmap) 
+       {
+           int lineBytes =  PixmapBytePad(stuff->totalWidth, 1);
+           int lineBytesProto = PixmapBytePadProto(stuff->totalWidth, 1);
+           int depth = stuff->depth;
+
+           stuffptr = shmdesc->addr + stuff->offset ;
+           tmpptr = tmpImage;
+           for (i = 0; i < stuff->totalHeight*stuff->depth;
+                stuffptr += lineBytesProto,tmpptr += lineBytes, i++) 
+               bcopy(stuffptr,tmpptr,lineBytesProto);
+       }
+       else 
+       {
+           for (i = 0,
+                stuffptr = shmdesc->addr + stuff->offset,
+                tmpptr=tmpImage;
+                i < stuff->totalHeight;
+                stuffptr += lengthProto,tmpptr += length, i++) 
+               bcopy(stuffptr,tmpptr,lengthProto);
+       }
+    }
+    /* handle 64-bit case where stuff is not 64-bit aligned 
+     */
+    else if ((unsigned long)(shmdesc->addr+stuff->offset) & 
+            (sizeof(long)-1)) 
+    {
+        if(!(tmpImage = (char *) ALLOCATE_LOCAL(length*stuff->totalHeight)))
+            return (BadAlloc);
+       tmpAlloced = 1;
+       bcopy((char *)(shmdesc->addr+stuff->offset),
+             tmpImage,
+             length*stuff->totalHeight);
+    }
+    else
+       tmpImage = (char *)(shmdesc->addr+stuff->offset);
+#endif
+
+    if ((((stuff->format == ZPixmap) && (stuff->srcX == 0)) ||
+        ((stuff->format != ZPixmap) &&
+         (stuff->srcX < screenInfo.bitmapScanlinePad) &&
+         ((stuff->format == XYBitmap) ||
+          ((stuff->srcY == 0) &&
+           (stuff->srcHeight == stuff->totalHeight))))) &&
+       ((stuff->srcX + stuff->srcWidth) == stuff->totalWidth))
+       (*pGC->ops->PutImage) (pDraw, pGC, stuff->depth,
+                              stuff->dstX, stuff->dstY,
+                              stuff->totalWidth, stuff->srcHeight, 
+                              stuff->srcX, stuff->format, 
+#ifdef INTERNAL_VS_EXTERNAL_PADDING
+                              tmpImage +
+#else
+                              shmdesc->addr + stuff->offset +
+#endif
+                              (stuff->srcY * length));
+    else
+       (*shmFuncs[pDraw->pScreen->myNum]->PutImage)(
+                              pDraw, pGC, stuff->depth, stuff->format,
+                              stuff->totalWidth, stuff->totalHeight,
+                              stuff->srcX, stuff->srcY,
+                              stuff->srcWidth, stuff->srcHeight,
+                              stuff->dstX, stuff->dstY,
+#ifdef INTERNAL_VS_EXTERNAL_PADDING
+                              tmpImage);
+    
+#else
+                               shmdesc->addr + stuff->offset);
+#endif
+
+    if (stuff->sendEvent)
+    {
+       xShmCompletionEvent ev;
+
+       ev.type = ShmCompletionCode;
+       ev.drawable = stuff->drawable;
+       ev.sequenceNumber = client->sequence;
+       ev.minorEvent = X_ShmPutImage;
+       ev.majorEvent = ShmReqCode;
+       ev.shmseg = stuff->shmseg;
+       ev.offset = stuff->offset;
+       WriteEventsToClient(client, 1, (xEvent *) &ev);
+    }
+
+#ifdef INTERNAL_VS_EXTERNAL_PADDING
+    if (tmpAlloced)
+        DEALLOCATE_LOCAL(tmpImage);
+#endif
+
+     return (client->noClientException);
+}
+
+
+
+static int
+ProcShmGetImage(client)
+    register ClientPtr client;
+{
+    register DrawablePtr pDraw;
+    long               lenPer, length;
+    Mask               plane;
+    xShmGetImageReply  xgi;
+    ShmDescPtr         shmdesc;
+    int                        n;
+#ifdef INTERNAL_VS_EXTERNAL_PADDING
+    long               widthBytesLine,widthBytesLineProto;
+    long               lenPerProto,lengthProto;
+    char               *tmpImage;
+    int                tmpAlloced = 0;
+#endif
+
+    REQUEST(xShmGetImageReq);
+
+    REQUEST_SIZE_MATCH(xShmGetImageReq);
+    if ((stuff->format != XYPixmap) && (stuff->format != ZPixmap))
+    {
+       client->errorValue = stuff->format;
+        return(BadValue);
+    }
+    VERIFY_DRAWABLE(pDraw, stuff->drawable, client);
+    VERIFY_SHMPTR(stuff->shmseg, stuff->offset, TRUE, shmdesc, client);
+    if (pDraw->type == DRAWABLE_WINDOW)
+    {
+      if( /* check for being viewable */
+        !((WindowPtr) pDraw)->realized ||
+         /* check for being on screen */
+         pDraw->x + stuff->x < 0 ||
+        pDraw->x + stuff->x + (int)stuff->width > pDraw->pScreen->width ||
+         pDraw->y + stuff->y < 0 ||
+         pDraw->y + stuff->y + (int)stuff->height > pDraw->pScreen->height ||
+          /* check for being inside of border */
+         stuff->x < - wBorderWidth((WindowPtr)pDraw) ||
+         stuff->x + (int)stuff->width >
+               wBorderWidth((WindowPtr)pDraw) + (int)pDraw->width ||
+         stuff->y < -wBorderWidth((WindowPtr)pDraw) ||
+         stuff->y + (int)stuff->height >
+               wBorderWidth((WindowPtr)pDraw) + (int)pDraw->height
+        )
+           return(BadMatch);
+       xgi.visual = wVisual(((WindowPtr)pDraw));
+    }
+    else
+    {
+       if (stuff->x < 0 ||
+           stuff->x+(int)stuff->width > pDraw->width ||
+           stuff->y < 0 ||
+           stuff->y+(int)stuff->height > pDraw->height
+           )
+           return(BadMatch);
+       xgi.visual = None;
+    }
+    xgi.type = X_Reply;
+    xgi.length = 0;
+    xgi.sequenceNumber = client->sequence;
+    xgi.depth = pDraw->depth;
+    if(stuff->format == ZPixmap)
+    {
+#ifdef INTERNAL_VS_EXTERNAL_PADDING
+       widthBytesLine = PixmapBytePad(stuff->width, pDraw->depth);
+       length = widthBytesLine * stuff->height;
+       widthBytesLineProto =  PixmapBytePadProto(stuff->width, pDraw->depth);
+       lengthProto = widthBytesLineProto * stuff->height;
+#else
+       length = PixmapBytePad(stuff->width, pDraw->depth) * stuff->height;
+#endif
+    }
+    else 
+    {
+#ifdef INTERNAL_VS_EXTERNAL_PADDING
+       widthBytesLine = PixmapBytePad(stuff->width, 1);
+       lenPer = widthBytesLine * stuff->height;
+       plane = ((Mask)1) << (pDraw->depth - 1);
+       /* only planes asked for */
+       length = lenPer * Ones(stuff->planeMask & (plane | (plane - 1)));
+
+       widthBytesLineProto = PixmapBytePadProto(stuff->width, 1);
+       lenPerProto = widthBytesLineProto * stuff->height;
+       lengthProto = lenPerProto * Ones(stuff->planeMask & 
+                                        (plane | (plane - 1)));
+#else
+       lenPer = PixmapBytePad(stuff->width, 1) * stuff->height;
+       plane = ((Mask)1) << (pDraw->depth - 1);
+       /* only planes asked for */
+       length = lenPer * Ones(stuff->planeMask & (plane | (plane - 1)));
+#endif
+    }
+
+#ifdef INTERNAL_VS_EXTERNAL_PADDING
+    VERIFY_SHMSIZE(shmdesc, stuff->offset, lengthProto, client);
+    xgi.size = lengthProto;
+#else
+    VERIFY_SHMSIZE(shmdesc, stuff->offset, length, client);
+    xgi.size = length;
+#endif
+
+    if (length == 0)
+    {
+       /* nothing to do */
+    }
+    else if (stuff->format == ZPixmap)
+    {
+#ifdef INTERNAL_VS_EXTERNAL_PADDING
+        /* check for protocol/server padding differences.
+        */
+        if ((widthBytesLine != widthBytesLineProto) ||
+           ((unsigned long)shmdesc->addr + stuff->offset & (sizeof(long)-1))) 
+       {
+           /* temp stuff for 64 bit alignment stuff */
+           register char * bufPtr, * protoPtr;
+           register int i;
+
+           if(!(tmpImage = (char *) ALLOCATE_LOCAL(length))) 
+             return (BadAlloc);
+           tmpAlloced = 1;
+           
+           (*pDraw->pScreen->GetImage)(pDraw, stuff->x, stuff->y,
+                                       stuff->width, stuff->height,
+                                       stuff->format, stuff->planeMask,
+                                       tmpImage);
+           
+           /* for 64-bit server, convert image to pad to 32 bits 
+            */
+           bzero(shmdesc->addr + stuff->offset,lengthProto);
+           
+           for (i=0,bufPtr=tmpImage,protoPtr=shmdesc->addr + stuff->offset; 
+                i < stuff->height;
+                bufPtr += widthBytesLine,protoPtr += widthBytesLineProto, 
+                i++)
+               bcopy(bufPtr,protoPtr,widthBytesLineProto);
+       }
+       else 
+       {
+           (*pDraw->pScreen->GetImage)(pDraw, stuff->x, stuff->y,
+                                       stuff->width, stuff->height,
+                                       stuff->format, stuff->planeMask,
+                                       shmdesc->addr + stuff->offset);
+       }
+#else
+       (*pDraw->pScreen->GetImage)(pDraw, stuff->x, stuff->y,
+                                   stuff->width, stuff->height,
+                                   stuff->format, stuff->planeMask,
+                                   shmdesc->addr + stuff->offset);
+#endif
+    }
+    else
+    {
+#ifdef INTERNAL_VS_EXTERNAL_PADDING
+       /* check for protocol/server padding differences.
+        */
+       if ((widthBytesLine != widthBytesLineProto) ||
+           ((unsigned long)shmdesc->addr + stuff->offset & 
+            (sizeof(long)-1))) 
+       {
+           if(!(tmpImage = (char *) ALLOCATE_LOCAL(length)))
+             return (BadAlloc);
+           tmpAlloced = 1;
+       }
+#endif
+
+       length = stuff->offset;
+        for (; plane; plane >>= 1)
+       {
+           if (stuff->planeMask & plane)
+           {
+#ifdef INTERNAL_VS_EXTERNAL_PADDING
+               if ((widthBytesLine != widthBytesLineProto) ||
+                   ((unsigned long)shmdesc->addr + stuff->offset & 
+                    (sizeof(long)-1))) 
+               {
+                   /* get image for each plane. 
+                    */
+                   (*pDraw->pScreen->GetImage)(pDraw,
+                                               stuff->x, stuff->y,
+                                               stuff->width, stuff->height,
+                                               stuff->format, plane,
+                                               tmpImage);
+                   
+                   /* for 64-bit server, convert image to pad to 32 bits */
+                   bzero(shmdesc->addr+length, widthBytesLine);
+                   bcopy(tmpImage, shmdesc->addr+length, widthBytesLineProto);
+                   /* increment length */
+                   length += lenPerProto;
+               }
+               else /* no diff between protocol and server */
+               {
+                   (*pDraw->pScreen->GetImage)(pDraw,
+                                               stuff->x, stuff->y,
+                                               stuff->width, stuff->height,
+                                               stuff->format, plane,
+                                               shmdesc->addr + length);
+                   length += lenPer;
+               }
+#else
+               (*pDraw->pScreen->GetImage)(pDraw,
+                                           stuff->x, stuff->y,
+                                           stuff->width, stuff->height,
+                                           stuff->format, plane,
+                                           shmdesc->addr + length);
+               length += lenPer;
+#endif
+           }
+       }
+    }
+    
+    if (client->swapped) {
+       swaps(&xgi.sequenceNumber, n);
+       swapl(&xgi.length, n);
+       swapl(&xgi.visual, n);
+       swapl(&xgi.size, n);
+    }
+    WriteToClient(client, sizeof(xShmGetImageReply), (char *)&xgi);
+
+#ifdef INTERNAL_VS_EXTERNAL_PADDING
+    if (tmpAlloced)
+       DEALLOCATE_LOCAL(tmpImage);
+#endif
+
+    return(client->noClientException);
+}
+
+static PixmapPtr
+fbShmCreatePixmap (pScreen, width, height, depth, addr)
+    ScreenPtr  pScreen;
+    int                width;
+    int                height;
+    int                depth;
+    char       *addr;
+{
+    register PixmapPtr pPixmap;
+
+    pPixmap = (*pScreen->CreatePixmap)(pScreen, 0, 0, pScreen->rootDepth);
+    if (!pPixmap)
+       return NullPixmap;
+
+    if (!(*pScreen->ModifyPixmapHeader)(pPixmap, width, height, depth,
+                 /*XXX*/depth, PixmapBytePad(width, depth), (pointer)addr))
+       return NullPixmap;
+    return pPixmap;
+}
+
+static int
+ProcShmCreatePixmap(client)
+    register ClientPtr client;
+{
+    PixmapPtr pMap;
+    register DrawablePtr pDraw;
+    DepthPtr pDepth;
+    register int i;
+    ShmDescPtr shmdesc;
+    REQUEST(xShmCreatePixmapReq);
+
+    REQUEST_SIZE_MATCH(xShmCreatePixmapReq);
+    client->errorValue = stuff->pid;
+    if (!sharedPixmaps)
+       return BadImplementation;
+    LEGAL_NEW_RESOURCE(stuff->pid, client);
+    VERIFY_GEOMETRABLE(pDraw, stuff->drawable, client);
+    VERIFY_SHMPTR(stuff->shmseg, stuff->offset, TRUE, shmdesc, client);
+    if (!stuff->width || !stuff->height)
+    {
+       client->errorValue = 0;
+        return BadValue;
+    }
+    if (stuff->depth != 1)
+    {
+        pDepth = pDraw->pScreen->allowedDepths;
+        for (i=0; i<pDraw->pScreen->numDepths; i++, pDepth++)
+          if (pDepth->depth == stuff->depth)
+               goto CreatePmap;
+       client->errorValue = stuff->depth;
+        return BadValue;
+    }
+CreatePmap:
+    VERIFY_SHMSIZE(shmdesc, stuff->offset,
+                  PixmapBytePad(stuff->width, stuff->depth) * stuff->height,
+                  client);
+    pMap = (*shmFuncs[pDraw->pScreen->myNum]->CreatePixmap)(
+                           pDraw->pScreen, stuff->width,
+                           stuff->height, stuff->depth,
+                           shmdesc->addr + stuff->offset);
+    if (pMap)
+    {
+       pMap->drawable.serialNumber = NEXT_SERIAL_NUMBER;
+       pMap->drawable.id = stuff->pid;
+       if (AddResource(stuff->pid, RT_PIXMAP, (pointer)pMap))
+       {
+           shmdesc->refcnt++;
+           if (AddResource(stuff->pid, ShmPixType, (pointer)shmdesc))
+               return(client->noClientException);
+           FreeResource(stuff->pid, RT_NONE);
+       }
+    }
+    return (BadAlloc);
+}
+
+static int
+ProcShmDispatch (client)
+    register ClientPtr client;
+{
+    REQUEST(xReq);
+    switch (stuff->data)
+    {
+    case X_ShmQueryVersion:
+       return ProcShmQueryVersion(client);
+    case X_ShmAttach:
+       return ProcShmAttach(client);
+    case X_ShmDetach:
+       return ProcShmDetach(client);
+    case X_ShmPutImage:
+       return ProcShmPutImage(client);
+    case X_ShmGetImage:
+       return ProcShmGetImage(client);
+    case X_ShmCreatePixmap:
+       return ProcShmCreatePixmap(client);
+    default:
+       return BadRequest;
+    }
+}
+
+static void
+SShmCompletionEvent(from, to)
+    xShmCompletionEvent *from, *to;
+{
+    to->type = from->type;
+    cpswaps(from->sequenceNumber, to->sequenceNumber);
+    cpswapl(from->drawable, to->drawable);
+    cpswaps(from->minorEvent, to->minorEvent);
+    to->majorEvent = from->majorEvent;
+    cpswapl(from->shmseg, to->shmseg);
+    cpswapl(from->offset, to->offset);
+}
+
+static int
+SProcShmQueryVersion(client)
+    register ClientPtr client;
+{
+    register int n;
+    REQUEST(xShmQueryVersionReq);
+
+    swaps(&stuff->length, n);
+    return ProcShmQueryVersion(client);
+}
+
+static int
+SProcShmAttach(client)
+    ClientPtr client;
+{
+    register int n;
+    REQUEST(xShmAttachReq);
+    swaps(&stuff->length, n);
+    REQUEST_SIZE_MATCH(xShmAttachReq);
+    swapl(&stuff->shmseg, n);
+    swapl(&stuff->shmid, n);
+    return ProcShmAttach(client);
+}
+
+static int
+SProcShmDetach(client)
+    ClientPtr client;
+{
+    register int n;
+    REQUEST(xShmDetachReq);
+    swaps(&stuff->length, n);
+    REQUEST_SIZE_MATCH(xShmDetachReq);
+    swapl(&stuff->shmseg, n);
+    return ProcShmDetach(client);
+}
+
+static int
+SProcShmPutImage(client)
+    ClientPtr client;
+{
+    register int n;
+    REQUEST(xShmPutImageReq);
+    swaps(&stuff->length, n);
+    REQUEST_SIZE_MATCH(xShmPutImageReq);
+    swapl(&stuff->drawable, n);
+    swapl(&stuff->gc, n);
+    swaps(&stuff->totalWidth, n);
+    swaps(&stuff->totalHeight, n);
+    swaps(&stuff->srcX, n);
+    swaps(&stuff->srcY, n);
+    swaps(&stuff->srcWidth, n);
+    swaps(&stuff->srcHeight, n);
+    swaps(&stuff->dstX, n);
+    swaps(&stuff->dstY, n);
+    swapl(&stuff->shmseg, n);
+    swapl(&stuff->offset, n);
+    return ProcShmPutImage(client);
+}
+
+static int
+SProcShmGetImage(client)
+    ClientPtr client;
+{
+    register int n;
+    REQUEST(xShmGetImageReq);
+    swaps(&stuff->length, n);
+    REQUEST_SIZE_MATCH(xShmGetImageReq);
+    swapl(&stuff->drawable, n);
+    swaps(&stuff->x, n);
+    swaps(&stuff->y, n);
+    swaps(&stuff->width, n);
+    swaps(&stuff->height, n);
+    swapl(&stuff->planeMask, n);
+    swapl(&stuff->shmseg, n);
+    swapl(&stuff->offset, n);
+    return ProcShmGetImage(client);
+}
+
+static int
+SProcShmCreatePixmap(client)
+    ClientPtr client;
+{
+    register int n;
+    REQUEST(xShmCreatePixmapReq);
+    swaps(&stuff->length, n);
+    REQUEST_SIZE_MATCH(xShmCreatePixmapReq);
+    swapl(&stuff->drawable, n);
+    swaps(&stuff->width, n);
+    swaps(&stuff->height, n);
+    swapl(&stuff->shmseg, n);
+    swapl(&stuff->offset, n);
+    return ProcShmCreatePixmap(client);
+}
+
+static int
+SProcShmDispatch (client)
+    register ClientPtr client;
+{
+    REQUEST(xReq);
+    switch (stuff->data)
+    {
+    case X_ShmQueryVersion:
+       return SProcShmQueryVersion(client);
+    case X_ShmAttach:
+       return SProcShmAttach(client);
+    case X_ShmDetach:
+       return SProcShmDetach(client);
+    case X_ShmPutImage:
+       return SProcShmPutImage(client);
+    case X_ShmGetImage:
+       return SProcShmGetImage(client);
+    case X_ShmCreatePixmap:
+       return SProcShmCreatePixmap(client);
+    default:
+       return BadRequest;
+    }
+}
diff --git a/Xserver/programs/Xserver/Xext/sleepuntil.c b/Xserver/programs/Xserver/Xext/sleepuntil.c
new file mode 100644 (file)
index 0000000..29d3e69
--- /dev/null
@@ -0,0 +1,243 @@
+/*
+ * $XConsortium: sleepuntil.c,v 1.5 94/04/17 20:32:57 dpw Exp $
+ * $XFree86: xc/programs/Xserver/Xext/sleepuntil.c,v 3.0 1996/05/06 05:55:34 dawes Exp $
+ *
+Copyright (c) 1992  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+ *
+ * Author:  Keith Packard, MIT X Consortium
+ */
+
+/* dixsleep.c - implement millisecond timeouts for X clients */
+
+#include "X.h"
+#include "Xmd.h"
+#include "misc.h"
+#include "windowstr.h"
+#include "dixstruct.h"
+#include "pixmapstr.h"
+#include "scrnintstr.h"
+
+typedef struct _Sertafied {
+    struct _Sertafied  *next;
+    TimeStamp          revive;
+    ClientPtr          pClient;
+    XID                        id;
+    void               (*notifyFunc)(
+#if NeedNestedPrototypes
+                       ClientPtr /* client */,
+                       pointer /* closure */
+#endif
+                       );
+
+    pointer            closure;
+} SertafiedRec, *SertafiedPtr;
+
+static SertafiedPtr pPending;
+static RESTYPE     SertafiedResType;
+static Bool        BlockHandlerRegistered;
+static int         SertafiedGeneration;
+
+static void        ClientAwaken(
+#if NeedFunctionPrototypes
+    ClientPtr /* client */,
+    pointer /* closure */
+#endif
+);
+static int         SertafiedDelete(
+#if NeedFunctionPrototypes
+    pointer /* value */,
+    XID /* id */
+#endif
+);
+static void        SertafiedBlockHandler(
+#if NeedFunctionPrototypes
+    pointer /* data */,
+    OSTimePtr /* wt */,
+    pointer /* LastSelectMask */
+#endif
+);
+static void        SertafiedWakeupHandler(
+#if NeedFunctionPrototypes
+    pointer /* data */,
+    int /* i */,
+    pointer /* LastSelectMask */
+#endif
+);
+
+int
+ClientSleepUntil (client, revive, notifyFunc, closure)
+    ClientPtr  client;
+    TimeStamp  *revive;
+    void       (*notifyFunc)();
+    pointer    closure;
+{
+    SertafiedPtr       pRequest, pReq, pPrev;
+
+    if (SertafiedGeneration != serverGeneration)
+    {
+       SertafiedResType = CreateNewResourceType (SertafiedDelete);
+       if (!SertafiedResType)
+           return FALSE;
+       SertafiedGeneration = serverGeneration;
+       BlockHandlerRegistered = FALSE;
+    }
+    pRequest = (SertafiedPtr) xalloc (sizeof (SertafiedRec));
+    if (!pRequest)
+       return FALSE;
+    pRequest->pClient = client;
+    pRequest->revive = *revive;
+    pRequest->id = FakeClientID (client->index);
+    pRequest->closure = closure;
+    if (!BlockHandlerRegistered)
+    {
+       if (!RegisterBlockAndWakeupHandlers (SertafiedBlockHandler,
+                                            SertafiedWakeupHandler,
+                                            (pointer) 0))
+       {
+           xfree (pRequest);
+           return FALSE;
+       }
+       BlockHandlerRegistered = TRUE;
+    }
+    pRequest->notifyFunc = 0;
+    if (!AddResource (pRequest->id, SertafiedResType, (pointer) pRequest))
+       return FALSE;
+    if (!notifyFunc)
+       notifyFunc = ClientAwaken;
+    pRequest->notifyFunc = notifyFunc;
+    /* Insert into time-ordered queue, with earliest activation time coming first. */
+    pPrev = 0;
+    for (pReq = pPending; pReq; pReq = pReq->next)
+    {
+       if (CompareTimeStamps (pReq->revive, *revive) == LATER)
+           break;
+       pPrev = pReq;
+    }
+    if (pPrev)
+       pPrev->next = pRequest;
+    else
+       pPending = pRequest;
+    pRequest->next = pReq;
+    IgnoreClient (client);
+    return TRUE;
+}
+
+static void
+ClientAwaken (client, closure)
+    ClientPtr  client;
+    pointer    closure;
+{
+    if (!client->clientGone)
+       AttendClient (client);
+}
+
+
+static int
+SertafiedDelete (value, id)
+    pointer value;
+    XID id;
+{
+    SertafiedPtr       pRequest = (SertafiedPtr)value;
+    SertafiedPtr       pReq, pPrev;
+
+    pPrev = 0;
+    for (pReq = pPending; pReq; pPrev = pReq, pReq = pReq->next)
+       if (pReq == pRequest)
+       {
+           if (pPrev)
+               pPrev->next = pReq->next;
+           else
+               pPending = pReq->next;
+           break;
+       }
+    if (pRequest->notifyFunc)
+       (*pRequest->notifyFunc) (pRequest->pClient, pRequest->closure);
+    xfree (pRequest);
+    return TRUE;
+}
+
+static void
+SertafiedBlockHandler (data, wt, LastSelectMask)
+    pointer        data;               /* unused */
+    OSTimePtr      wt;                 /* wait time */
+    pointer        LastSelectMask;
+{
+    SertafiedPtr           pReq, pNext;
+    unsigned long          newdelay, olddelay;
+    TimeStamp              now;
+
+    if (!pPending)
+       return;
+    now.milliseconds = GetTimeInMillis ();
+    now.months = currentTime.months;
+    if ((int) (now.milliseconds - currentTime.milliseconds) < 0)
+       now.months++;
+    for (pReq = pPending; pReq; pReq = pNext)
+    {
+       pNext = pReq->next;
+       if (CompareTimeStamps (pReq->revive, now) == LATER)
+           break;
+       FreeResource (pReq->id, RT_NONE);
+
+       /* AttendClient() may have been called via the resource delete
+        * function so a client may have input to be processed and so
+        *  set delay to 0 to prevent blocking in WaitForSomething().
+        */
+       AdjustWaitForDelay (wt, 0);
+    }
+    pReq = pPending;
+    if (!pReq)
+       return;
+    newdelay = pReq->revive.milliseconds - now.milliseconds;
+    AdjustWaitForDelay (wt, newdelay);
+}
+
+static void
+SertafiedWakeupHandler (data, i, LastSelectMask)
+    pointer        data;
+    int                    i;
+    pointer        LastSelectMask;
+{
+    SertafiedPtr       pReq, pNext;
+    TimeStamp          now;
+
+    now.milliseconds = GetTimeInMillis ();
+    now.months = currentTime.months;
+    if ((int) (now.milliseconds - currentTime.milliseconds) < 0)
+       now.months++;
+    for (pReq = pPending; pReq; pReq = pNext)
+    {
+       pNext = pReq->next;
+       if (CompareTimeStamps (pReq->revive, now) == LATER)
+           break;
+       FreeResource (pReq->id, RT_NONE);
+    }
+    if (!pPending)
+    {
+       RemoveBlockAndWakeupHandlers (SertafiedBlockHandler,
+                                     SertafiedWakeupHandler,
+                                     (pointer) 0);
+       BlockHandlerRegistered = FALSE;
+    }
+}
diff --git a/Xserver/programs/Xserver/Xext/sync.c b/Xserver/programs/Xserver/Xext/sync.c
new file mode 100644 (file)
index 0000000..3ebdcc2
--- /dev/null
@@ -0,0 +1,2557 @@
+/* $XConsortium: sync.c /main/13 1996/12/16 16:51:55 rws $ */
+/* $XFree86: xc/programs/Xserver/Xext/sync.c,v 3.3 1997/01/18 06:53:00 dawes Exp $ */
+/*
+
+Copyright (c) 1991, 1993  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be included
+in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR
+OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall
+not be used in advertising or otherwise to promote the sale, use or
+other dealings in this Software without prior written authorization
+from the X Consortium.
+
+
+Copyright 1991, 1993 by Digital Equipment Corporation, Maynard, Massachusetts,
+and Olivetti Research Limited, Cambridge, England.
+
+                        All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and its
+documentation for any purpose and without fee is hereby granted,
+provided that the above copyright notice appear in all copies and that
+both that copyright notice and this permission notice appear in
+supporting documentation, and that the names of Digital or Olivetti 
+not be used in advertising or publicity pertaining to distribution of the
+software without specific, written prior permission.  Digital and Olivetti
+make no representations about the suitability of this software
+for any purpose.  It is provided "as is" without express or implied warranty.
+
+DIGITAL AND OLIVETTI DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
+SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
+FITNESS, IN NO EVENT SHALL THEY BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
+USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
+OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+PERFORMANCE OF THIS SOFTWARE.
+
+*/
+
+#define NEED_REPLIES
+#define NEED_EVENTS
+#include <stdio.h>
+#include "X.h"
+#include "Xproto.h"
+#include "Xmd.h"
+#include "misc.h"
+#include "os.h"
+#include "extnsionst.h"
+#include "dixstruct.h"
+#include "resource.h"
+#include "opaque.h"
+#define _SYNC_SERVER
+#include "sync.h"
+#include "syncstr.h"
+
+/*
+ * Local Global Variables
+ */
+static int      SyncReqCode;
+static int      SyncEventBase;
+static int      SyncErrorBase;
+static RESTYPE  RTCounter = 0;
+static RESTYPE  RTAwait;
+static RESTYPE  RTAlarm;
+static RESTYPE  RTAlarmClient;
+static int SyncNumSystemCounters = 0;
+static SyncCounter **SysCounterList = NULL;
+
+#define IsSystemCounter(pCounter) \
+    (pCounter && (pCounter->client == NULL))
+
+/* these are all the alarm attributes that pertain to the alarm's trigger */
+#define XSyncCAAllTrigger \
+    (XSyncCACounter | XSyncCAValueType | XSyncCAValue | XSyncCATestType)
+
+static int
+FreeAlarm(
+#if NeedFunctionPrototypes
+    pointer /* addr */,
+    XID /* id */
+#endif
+);
+
+static int
+FreeAlarmClient(
+#if NeedFunctionPrototypes
+    pointer /* value */,
+    XID /* id */
+#endif
+);
+
+static int
+FreeAwait(
+#if NeedFunctionPrototypes
+    pointer /* addr */,
+    XID /* id */
+#endif
+);
+
+static void
+ServertimeBracketValues(
+#if NeedFunctionPrototypes
+    pointer /* pCounter */,
+    CARD64 * /* pbracket_less */,
+    CARD64 * /* pbracket_greater */
+#endif
+);
+
+static void
+ServertimeQueryValue(
+#if NeedFunctionPrototypes
+    pointer /* pCounter */,
+    CARD64 * /* pValue_return */
+#endif
+);
+
+static void
+ServertimeWakeupHandler(
+#if NeedFunctionPrototypes
+    pointer /* env */,
+    int /* rc */,
+    pointer /* LastSelectMask */
+#endif
+);
+
+static int 
+SyncInitTrigger(
+#if NeedFunctionPrototypes
+    ClientPtr /* client */,
+    SyncTrigger * /* pTrigger */,
+    XSyncCounter /* counter */,
+    Mask /* changes */
+#endif
+);
+
+static void
+SAlarmNotifyEvent(
+#if NeedFunctionPrototypes
+    xSyncAlarmNotifyEvent * /* from */,
+    xSyncAlarmNotifyEvent * /* to */
+#endif
+);
+
+static void
+SCounterNotifyEvent(
+#if NeedFunctionPrototypes
+    xSyncCounterNotifyEvent * /* from */,
+    xSyncCounterNotifyEvent * /* to */
+#endif
+);
+
+static void
+ServertimeBlockHandler(
+#if NeedFunctionPrototypes
+    pointer  /* env */,
+    struct timeval ** /* wt */,
+    pointer  /* LastSelectMask */
+#endif
+);
+
+static int
+SyncAddTriggerToCounter(
+#if NeedFunctionPrototypes
+    SyncTrigger * /* pTrigger */
+#endif
+);
+
+extern void
+SyncAlarmCounterDestroyed(
+#if NeedFunctionPrototypes
+    SyncTrigger * /* pTrigger */
+#endif
+);
+
+static void
+SyncAlarmTriggerFired(
+#if NeedFunctionPrototypes
+    SyncTrigger * /* pTrigger */
+#endif
+);
+
+static void
+SyncAwaitTriggerFired(
+#if NeedFunctionPrototypes
+    SyncTrigger * /* pTrigger */
+#endif
+);
+
+static int
+SyncChangeAlarmAttributes(
+#if NeedFunctionPrototypes
+    ClientPtr /* client */,
+    SyncAlarm * /* pAlarm */,
+    Mask /* mask */,
+    CARD32 * /* values */
+#endif
+);
+
+static Bool
+SyncCheckTriggerNegativeComparison(
+#if NeedFunctionPrototypes
+    SyncTrigger * /* pTrigger */,
+    CARD64 /* oldval */
+#endif
+);
+
+static Bool
+SyncCheckTriggerNegativeTransition(
+#if NeedFunctionPrototypes
+    SyncTrigger * /* pTrigger */,
+    CARD64 /* oldval */
+#endif
+);
+
+static Bool
+SyncCheckTriggerPositiveComparison(
+#if NeedFunctionPrototypes
+    SyncTrigger * /* pTrigger */,
+    CARD64 /* oldval */
+#endif
+);
+
+static Bool
+SyncCheckTriggerPositiveTransition(
+#if NeedFunctionPrototypes
+    SyncTrigger * /* pTrigger */,
+    CARD64 /* oldval */
+#endif
+);
+
+static SyncCounter *
+SyncCreateCounter(
+#if NeedFunctionPrototypes
+    ClientPtr /* client */,
+    XSyncCounter /* id */,
+    CARD64 /* initialvalue */
+#endif
+);
+
+static void SyncComputeBracketValues(
+#if NeedFunctionPrototypes
+    SyncCounter * /* pCounter */,
+    Bool /* startOver */
+#endif
+);
+
+static void
+SyncDeleteTriggerFromCounter(
+#if NeedFunctionPrototypes
+    SyncTrigger * /* pTrigger */
+#endif
+);
+
+static Bool
+SyncEventSelectForAlarm(
+#if NeedFunctionPrototypes
+    SyncAlarm * /* pAlarm */,
+    ClientPtr /* client */,
+    Bool /* wantevents */
+#endif
+);
+
+static void
+SyncInitServerTime(
+#if NeedFunctionPrototypes
+    void
+#endif
+);
+
+static void 
+SyncResetProc(
+#if NeedFunctionPrototypes
+    ExtensionEntry * /* extEntry */
+#endif
+);
+
+static void
+SyncSendAlarmNotifyEvents(
+#if NeedFunctionPrototypes
+    SyncAlarm * /* pAlarm */
+#endif
+);
+
+static void
+SyncSendCounterNotifyEvents(
+#if NeedFunctionPrototypes
+    ClientPtr /* client */,
+    SyncAwait ** /* ppAwait */,
+    int /* num_events */
+#endif
+);
+
+static DISPATCH_PROC(ProcSyncAwait);
+static DISPATCH_PROC(ProcSyncChangeAlarm);
+static DISPATCH_PROC(ProcSyncChangeCounter);
+static DISPATCH_PROC(ProcSyncCreateAlarm);
+static DISPATCH_PROC(ProcSyncCreateCounter);
+static DISPATCH_PROC(ProcSyncDestroyAlarm);
+static DISPATCH_PROC(ProcSyncDestroyCounter);
+static DISPATCH_PROC(ProcSyncDispatch);
+static DISPATCH_PROC(ProcSyncGetPriority);
+static DISPATCH_PROC(ProcSyncInitialize);
+static DISPATCH_PROC(ProcSyncListSystemCounters);
+static DISPATCH_PROC(ProcSyncListSystemCounters);
+static DISPATCH_PROC(ProcSyncQueryAlarm);
+static DISPATCH_PROC(ProcSyncQueryCounter);
+static DISPATCH_PROC(ProcSyncSetCounter);
+static DISPATCH_PROC(ProcSyncSetPriority);
+static DISPATCH_PROC(SProcSyncAwait);
+static DISPATCH_PROC(SProcSyncChangeAlarm);
+static DISPATCH_PROC(SProcSyncChangeCounter);
+static DISPATCH_PROC(SProcSyncCreateAlarm);
+static DISPATCH_PROC(SProcSyncCreateCounter);
+static DISPATCH_PROC(SProcSyncDestroyAlarm);
+static DISPATCH_PROC(SProcSyncDestroyCounter);
+static DISPATCH_PROC(SProcSyncDispatch);
+static DISPATCH_PROC(SProcSyncDispatch);
+static DISPATCH_PROC(SProcSyncGetPriority);
+static DISPATCH_PROC(SProcSyncInitialize);
+static DISPATCH_PROC(SProcSyncListSystemCounters);
+static DISPATCH_PROC(SProcSyncQueryAlarm);
+static DISPATCH_PROC(SProcSyncQueryCounter);
+static DISPATCH_PROC(SProcSyncSetCounter);
+static DISPATCH_PROC(SProcSyncSetPriority);
+
+/*  Each counter maintains a simple linked list of triggers that are
+ *  interested in the counter.  The two functions below are used to
+ *  delete and add triggers on this list.
+ */
+static void
+SyncDeleteTriggerFromCounter(pTrigger)
+    SyncTrigger *pTrigger;
+{
+    SyncTriggerList *pCur, *pPrev = NULL;
+
+    /* pCounter needs to be stored in pTrigger before calling here. */
+
+    if (!pTrigger->pCounter)
+       return;
+
+    for (pCur = pTrigger->pCounter->pTriglist; pCur; pCur = pCur->next)
+    {
+       if (pCur->pTrigger == pTrigger)
+       {
+           if (pPrev)
+               pPrev->next = pCur->next;
+           else
+               pTrigger->pCounter->pTriglist = pCur->next;
+           xfree(pCur);
+           break;
+       }
+    }
+
+    if (IsSystemCounter(pTrigger->pCounter))
+       SyncComputeBracketValues(pTrigger->pCounter, /*startOver*/ TRUE);
+}
+
+
+static int
+SyncAddTriggerToCounter(pTrigger)
+    SyncTrigger *pTrigger;
+{
+    SyncTriggerList *pCur;
+
+    if (!pTrigger->pCounter)
+       return Success;
+
+    /* don't do anything if it's already there */
+    for (pCur = pTrigger->pCounter->pTriglist; pCur; pCur = pCur->next)
+    {
+       if (pCur->pTrigger == pTrigger)
+           return Success;
+    }
+
+    if (!(pCur = (SyncTriggerList *)xalloc(sizeof(SyncTriggerList))))
+       return BadAlloc;
+
+    pCur->pTrigger = pTrigger;
+    pCur->next = pTrigger->pCounter->pTriglist;
+    pTrigger->pCounter->pTriglist = pCur;
+
+    if (IsSystemCounter(pTrigger->pCounter))
+       SyncComputeBracketValues(pTrigger->pCounter, /*startOver*/ TRUE);
+
+    return Success;
+}
+
+
+/*  Below are four possible functions that can be plugged into 
+ *  pTrigger->CheckTrigger, corresponding to the four possible
+ *  test-types.  These functions are called after the counter's
+ *  value changes but are also passed the old counter value
+ *  so they can inspect both the old and new values.
+ *  (PositiveTransition and NegativeTransition need to see both
+ *  pieces of information.)  These functions return the truth value
+ *  of the trigger.
+ *
+ *  All of them include the condition pTrigger->pCounter == NULL.
+ *  This is because the spec says that a trigger with a counter value 
+ *  of None is always TRUE.
+ */
+
+static Bool
+SyncCheckTriggerPositiveComparison(pTrigger, oldval)
+    SyncTrigger *pTrigger;
+    CARD64     oldval;
+{
+    return (pTrigger->pCounter == NULL ||
+           XSyncValueGreaterOrEqual(pTrigger->pCounter->value,
+                                    pTrigger->test_value));
+}
+
+static Bool
+SyncCheckTriggerNegativeComparison(pTrigger, oldval)
+    SyncTrigger *pTrigger;
+    CARD64     oldval;
+{
+    return (pTrigger->pCounter == NULL ||
+           XSyncValueLessOrEqual(pTrigger->pCounter->value,
+                                 pTrigger->test_value));
+}
+
+static Bool
+SyncCheckTriggerPositiveTransition(pTrigger, oldval)
+    SyncTrigger *pTrigger;
+    CARD64     oldval;
+{
+    return (pTrigger->pCounter == NULL ||
+           (XSyncValueLessThan(oldval, pTrigger->test_value) &&
+            XSyncValueGreaterOrEqual(pTrigger->pCounter->value,
+                                     pTrigger->test_value)));
+}
+
+static Bool
+SyncCheckTriggerNegativeTransition(pTrigger, oldval)
+    SyncTrigger *pTrigger;
+    CARD64     oldval;
+{
+    return (pTrigger->pCounter == NULL ||
+           (XSyncValueGreaterThan(oldval, pTrigger->test_value) &&
+            XSyncValueLessOrEqual(pTrigger->pCounter->value,
+                                  pTrigger->test_value)));
+}
+
+
+
+static int 
+SyncInitTrigger(client, pTrigger, counter, changes) 
+    ClientPtr       client;    /* so we can set errorValue */
+    SyncTrigger      *pTrigger;
+    XSyncCounter     counter; 
+    Mask            changes;
+{
+    SyncCounter *pCounter = pTrigger->pCounter;
+    int                status;
+    Bool       newcounter = FALSE;
+
+    if (changes & XSyncCACounter)
+    {
+       if (counter == None)
+           pCounter = NULL;
+       else if (!(pCounter = (SyncCounter *)SecurityLookupIDByType(
+                       client, counter, RTCounter, SecurityReadAccess)))
+       {
+           client->errorValue = counter;
+           return SyncErrorBase + XSyncBadCounter;
+       }
+       if (pCounter != pTrigger->pCounter)
+       { /* new counter for trigger */
+           SyncDeleteTriggerFromCounter(pTrigger);
+           pTrigger->pCounter = pCounter;
+           newcounter = TRUE;
+       }
+    }
+
+    /* if system counter, ask it what the current value is */
+
+    if (IsSystemCounter(pCounter))
+    {
+       (*pCounter->pSysCounterInfo->QueryValue) ((pointer) pCounter,
+                                                 &pCounter->value);
+    }
+
+    if (changes & XSyncCAValueType)
+    {
+       if (pTrigger->value_type != XSyncRelative &&
+           pTrigger->value_type != XSyncAbsolute)
+       {
+           client->errorValue = pTrigger->value_type;
+           return BadValue;
+       }
+    }
+
+    if (changes & XSyncCATestType)
+    {
+       if (pTrigger->test_type != XSyncPositiveTransition &&
+           pTrigger->test_type != XSyncNegativeTransition &&
+           pTrigger->test_type != XSyncPositiveComparison &&
+           pTrigger->test_type != XSyncNegativeComparison)
+       {
+           client->errorValue = pTrigger->test_type;
+           return BadValue;
+       }
+       /* select appropriate CheckTrigger function */
+
+       switch (pTrigger->test_type)
+       {
+        case XSyncPositiveTransition: 
+           pTrigger->CheckTrigger = SyncCheckTriggerPositiveTransition;
+           break;
+        case XSyncNegativeTransition: 
+           pTrigger->CheckTrigger = SyncCheckTriggerNegativeTransition;
+           break;
+        case XSyncPositiveComparison: 
+           pTrigger->CheckTrigger = SyncCheckTriggerPositiveComparison;
+           break;
+        case XSyncNegativeComparison: 
+           pTrigger->CheckTrigger = SyncCheckTriggerNegativeComparison;
+           break;
+       }
+    }
+
+    if (changes & (XSyncCAValueType | XSyncCAValue))
+    {
+       if (pTrigger->value_type == XSyncAbsolute)
+           pTrigger->test_value = pTrigger->wait_value;
+       else /* relative */
+       {
+           Bool overflow;
+           if (pCounter == NULL)
+               return BadMatch;
+
+           XSyncValueAdd(&pTrigger->test_value, pCounter->value, 
+                         pTrigger->wait_value, &overflow);
+           if (overflow)
+           {
+               client->errorValue = XSyncValueHigh32(pTrigger->wait_value);
+               return BadValue;
+           }
+       }
+    }
+
+    /*  we wait until we're sure there are no errors before registering
+     *  a new counter on a trigger
+     */
+    if (newcounter)
+    {
+       if ((status = SyncAddTriggerToCounter(pTrigger)) != Success)
+           return status;
+    }
+    else if (IsSystemCounter(pCounter))
+    {
+       SyncComputeBracketValues(pCounter, /*startOver*/ TRUE);
+    }
+    
+    return Success;
+}
+
+/*  AlarmNotify events happen in response to actions taken on an Alarm or
+ *  the counter used by the alarm.  AlarmNotify may be sent to multiple 
+ *  clients.  The alarm maintains a list of clients interested in events.
+ */
+static void
+SyncSendAlarmNotifyEvents(pAlarm)
+    SyncAlarm *pAlarm;
+{
+    SyncAlarmClientList *pcl;
+    xSyncAlarmNotifyEvent ane;
+    SyncTrigger *pTrigger = &pAlarm->trigger;
+
+    UpdateCurrentTime();
+
+    ane.type = SyncEventBase + XSyncAlarmNotify;
+    ane.kind = XSyncAlarmNotify;
+    ane.sequenceNumber = pAlarm->client->sequence;
+    ane.alarm = pAlarm->alarm_id;
+    if (pTrigger->pCounter)
+    {
+       ane.counter_value_hi = XSyncValueHigh32(pTrigger->pCounter->value);
+       ane.counter_value_lo = XSyncValueLow32(pTrigger->pCounter->value);
+    }
+    else
+    { /* XXX what else can we do if there's no counter? */
+       ane.counter_value_hi = ane.counter_value_lo = 0;
+    }
+
+    ane.alarm_value_hi = XSyncValueHigh32(pTrigger->test_value);
+    ane.alarm_value_lo = XSyncValueLow32(pTrigger->test_value);
+    ane.time = currentTime.milliseconds;
+    ane.state = pAlarm->state;
+
+    /* send to owner */
+    if (pAlarm->events && !pAlarm->client->clientGone) 
+       WriteEventsToClient(pAlarm->client, 1, (xEvent *) &ane);
+
+    /* send to other interested clients */
+    for (pcl = pAlarm->pEventClients; pcl; pcl = pcl->next)
+    {
+       if (!pAlarm->client->clientGone)
+       {
+           ane.sequenceNumber = pcl->client->sequence;
+           WriteEventsToClient(pcl->client, 1, (xEvent *) &ane);
+       }
+    }
+}
+
+
+/*  CounterNotify events only occur in response to an Await.  The events 
+ *  go only to the Awaiting client.
+ */
+static void
+SyncSendCounterNotifyEvents(client, ppAwait, num_events)
+    ClientPtr client;
+    SyncAwait **ppAwait;
+    int num_events;
+{
+    xSyncCounterNotifyEvent *pEvents, *pev;
+    int i;
+
+    if (client->clientGone)
+       return;
+    pev = pEvents = (xSyncCounterNotifyEvent *)
+                ALLOCATE_LOCAL(num_events * sizeof(xSyncCounterNotifyEvent));
+    if (!pEvents) 
+       return;
+    UpdateCurrentTime();
+    for (i = 0; i < num_events; i++, ppAwait++, pev++)
+    {
+       SyncTrigger *pTrigger = &(*ppAwait)->trigger;
+       pev->type = SyncEventBase + XSyncCounterNotify;
+       pev->kind = XSyncCounterNotify;
+       pev->sequenceNumber = client->sequence;
+       pev->counter = pTrigger->pCounter->id;
+       pev->wait_value_lo = XSyncValueLow32(pTrigger->test_value);
+       pev->wait_value_hi = XSyncValueHigh32(pTrigger->test_value);
+       pev->counter_value_lo = XSyncValueLow32(pTrigger->pCounter->value);
+       pev->counter_value_hi = XSyncValueHigh32(pTrigger->pCounter->value);
+       pev->time = currentTime.milliseconds;
+       pev->count = num_events - i - 1; /* events remaining */
+       pev->destroyed = pTrigger->pCounter->beingDestroyed;
+    }
+    /* swapping will be taken care of by this */
+    WriteEventsToClient(client, num_events, (xEvent *)pEvents);
+    DEALLOCATE_LOCAL(pEvents);
+}
+
+
+/* This function is called when an alarm's counter is destroyed.
+ * It is plugged into pTrigger->CounterDestroyed (for alarm triggers).
+ */
+void
+SyncAlarmCounterDestroyed(pTrigger)
+    SyncTrigger *pTrigger;
+{
+    SyncAlarm *pAlarm = (SyncAlarm *)pTrigger;
+
+    pAlarm->state = XSyncAlarmInactive;
+    SyncSendAlarmNotifyEvents(pAlarm);
+    pTrigger->pCounter = NULL;
+}
+
+
+/*  This function is called when an alarm "goes off."  
+ *  It is plugged into pTrigger->TriggerFired (for alarm triggers).
+ */
+static void
+SyncAlarmTriggerFired(pTrigger)
+    SyncTrigger *pTrigger;
+{
+    SyncAlarm *pAlarm = (SyncAlarm *)pTrigger;
+    CARD64 new_test_value;
+
+    /* no need to check alarm unless it's active */
+    if (pAlarm->state != XSyncAlarmActive)
+       return;
+
+    /*  " if the counter value is None, or if the delta is 0 and
+     *    the test-type is PositiveComparison or NegativeComparison,
+     *    no change is made to value (test-value) and the alarm
+     *    state is changed to Inactive before the event is generated."
+     */
+    if (pAlarm->trigger.pCounter == NULL
+       || (XSyncValueIsZero(pAlarm->delta)
+           && (pAlarm->trigger.test_type == XSyncPositiveComparison
+               || pAlarm->trigger.test_type == XSyncNegativeComparison)))
+       pAlarm->state = XSyncAlarmInactive;
+
+    new_test_value = pAlarm->trigger.test_value;
+
+    if (pAlarm->state == XSyncAlarmActive)
+    {
+       Bool overflow;
+       CARD64 oldvalue;
+       SyncTrigger *paTrigger = &pAlarm->trigger;
+
+       /* "The alarm is updated by repeatedly adding delta to the
+        *  value of the trigger and re-initializing it until it
+        *  becomes FALSE."
+        */
+       oldvalue = paTrigger->test_value;
+
+       /* XXX really should do something smarter here */
+
+       do
+       {
+           XSyncValueAdd(&paTrigger->test_value, paTrigger->test_value,
+                         pAlarm->delta, &overflow);
+       } while (!overflow && 
+             (*paTrigger->CheckTrigger)(paTrigger,
+                                       paTrigger->pCounter->value));
+
+       new_test_value = paTrigger->test_value;
+       paTrigger->test_value = oldvalue;
+
+       /* "If this update would cause value to fall outside the range
+        *  for an INT64...no change is made to value (test-value) and
+        *  the alarm state is changed to Inactive before the event is
+        *  generated."
+        */
+       if (overflow)
+       {
+           new_test_value = oldvalue;
+           pAlarm->state = XSyncAlarmInactive;
+       }
+    }
+    /*  The AlarmNotify event has to have the "new state of the alarm"
+     *  which we can't be sure of until this point.  However, it has
+     *  to have the "old" trigger test value.  That's the reason for
+     *  all the newvalue/oldvalue shuffling above.  After we send the
+     *  events, give the trigger its new test value.
+     */
+    SyncSendAlarmNotifyEvents(pAlarm);
+    pTrigger->test_value = new_test_value;
+}
+
+
+/*  This function is called when an Await unblocks, either as a result
+ *  of the trigger firing OR the counter being destroyed.
+ *  It goes into pTrigger->TriggerFired AND pTrigger->CounterDestroyed
+ *  (for Await triggers).
+ */
+static void
+SyncAwaitTriggerFired(pTrigger)
+    SyncTrigger *pTrigger;
+{
+    SyncAwait *pAwait = (SyncAwait *)pTrigger;
+    int numwaits;
+    SyncAwaitUnion *pAwaitUnion;
+    SyncAwait **ppAwait;
+    int num_events = 0;
+
+    pAwaitUnion = (SyncAwaitUnion *)pAwait->pHeader;
+    numwaits = pAwaitUnion->header.num_waitconditions;
+    ppAwait = (SyncAwait **)ALLOCATE_LOCAL(numwaits * sizeof(SyncAwait *));
+    if (!ppAwait)
+       goto bail;
+
+    pAwait = &(pAwaitUnion+1)->await;
+
+    /* "When a client is unblocked, all the CounterNotify events for
+     *  the Await request are generated contiguously. If count is 0
+     *  there are no more events to follow for this request. If
+     *  count is n, there are at least n more events to follow."
+     *
+     *  Thus, it is best to find all the counters for which events
+     *  need to be sent first, so that an accurate count field can
+     *  be stored in the events.
+     */
+    for ( ; numwaits; numwaits--, pAwait++)
+    {
+       CARD64 diff;
+       Bool overflow, diffgreater, diffequal;
+
+       /* "A CounterNotify event with the destroyed flag set to TRUE is
+        *  always generated if the counter for one of the triggers is
+        *  destroyed."
+        */
+       if (pAwait->trigger.pCounter->beingDestroyed)
+       {
+           ppAwait[num_events++] = pAwait;
+           continue;
+       }
+
+       /* "The difference between the counter and the test value is
+        *  calculated by subtracting the test value from the value of
+        *  the counter."
+        */
+       XSyncValueSubtract(&diff, pAwait->trigger.pCounter->value,
+                          pAwait->trigger.test_value, &overflow);
+
+       /* "If the difference lies outside the range for an INT64, an
+        *  event is not generated."
+        */
+       if (overflow)
+           continue;
+       diffgreater = XSyncValueGreaterThan(diff, pAwait->event_threshold);
+       diffequal   = XSyncValueEqual(diff, pAwait->event_threshold);
+
+       /* "If the test-type is PositiveTransition or
+        *  PositiveComparison, a CounterNotify event is generated if
+        *  the difference is at least event-threshold. If the test-type
+        *  is NegativeTransition or NegativeComparison, a CounterNotify
+        *  event is generated if the difference is at most
+        *  event-threshold."
+        */
+
+       if ( ((pAwait->trigger.test_type == XSyncPositiveComparison ||
+              pAwait->trigger.test_type == XSyncPositiveTransition)
+              && (diffgreater || diffequal))
+            ||
+            ((pAwait->trigger.test_type == XSyncNegativeComparison ||
+              pAwait->trigger.test_type == XSyncNegativeTransition)
+             && (!diffgreater) /* less or equal */
+             )
+          )
+       {
+           ppAwait[num_events++] = pAwait;
+       }
+    }
+    if (num_events)
+       SyncSendCounterNotifyEvents(pAwaitUnion->header.client, ppAwait,
+                                   num_events);
+    DEALLOCATE_LOCAL(ppAwait);
+
+bail:
+    /* unblock the client */
+    AttendClient(pAwaitUnion->header.client);
+    /* delete the await */
+    FreeResource(pAwaitUnion->header.delete_id, RT_NONE);
+}
+
+
+/*  This function should always be used to change a counter's value so that
+ *  any triggers depending on the counter will be checked.
+ */
+void
+SyncChangeCounter(pCounter, newval)
+    SyncCounter    *pCounter;
+    CARD64         newval;
+{
+    SyncTriggerList       *ptl, *pnext;
+    CARD64 oldval;
+
+    oldval = pCounter->value;
+    pCounter->value = newval;
+
+    /* run through triggers to see if any become true */
+    for (ptl = pCounter->pTriglist; ptl; ptl = pnext)
+    {
+       pnext = ptl->next;
+       if ((*ptl->pTrigger->CheckTrigger)(ptl->pTrigger, oldval))
+           (*ptl->pTrigger->TriggerFired)(ptl->pTrigger);
+    }
+
+    if (IsSystemCounter(pCounter))
+    {
+       SyncComputeBracketValues(pCounter, /* startOver */ FALSE);
+    }
+}
+
+
+/* loosely based on dix/events.c/EventSelectForWindow */
+static Bool
+SyncEventSelectForAlarm(pAlarm, client, wantevents)
+    SyncAlarm *pAlarm;
+    ClientPtr client;
+    Bool      wantevents;
+{
+    SyncAlarmClientList *pClients;
+
+    if (client == pAlarm->client) /* alarm owner */
+    {
+       pAlarm->events = wantevents;
+       return Success;
+    }
+
+    /* see if the client is already on the list (has events selected) */
+
+    for (pClients = pAlarm->pEventClients; pClients;
+        pClients = pClients->next)
+    {
+       if (pClients->client == client)
+       {
+           /* client's presence on the list indicates desire for 
+            * events.  If the client doesn't want events, remove it 
+            * from the list.  If the client does want events, do
+            * nothing, since it's already got them.
+            */
+           if (!wantevents)
+           {
+               FreeResource(pClients->delete_id, RT_NONE);
+           }
+           return Success;
+       }
+    }
+
+    /*  if we get here, this client does not currently have
+     *  events selected on the alarm
+     */
+
+    if (!wantevents)
+       /* client doesn't want events, and we just discovered that it 
+        * doesn't have them, so there's nothing to do.
+        */
+       return Success;
+
+    /* add new client to pAlarm->pEventClients */
+
+    pClients = (SyncAlarmClientList *) xalloc(sizeof(SyncAlarmClientList));
+    if (!pClients)
+       return BadAlloc;
+
+    /*  register it as a resource so it will be cleaned up 
+     *  if the client dies
+     */
+
+    pClients->delete_id = FakeClientID(client->index);
+    if (!AddResource(pClients->delete_id, RTAlarmClient, pAlarm))
+    {
+       xfree(pClients);
+       return BadAlloc;
+    }
+
+    /* link it into list after we know all the allocations succeed */
+
+    pClients->next = pAlarm->pEventClients;
+    pAlarm->pEventClients = pClients;
+    pClients->client = client;
+    return Success;
+}
+
+/*
+ * ** SyncChangeAlarmAttributes ** This is used by CreateAlarm and ChangeAlarm
+ */
+static int 
+SyncChangeAlarmAttributes(client, pAlarm, mask, values)
+    ClientPtr       client;
+    SyncAlarm      *pAlarm;
+    Mask           mask;
+    CARD32         *values;
+{
+    int                   status;
+    XSyncCounter   counter;
+    Mask          origmask = mask;
+
+    counter = pAlarm->trigger.pCounter ? pAlarm->trigger.pCounter->id : None;
+
+    while (mask)
+    {
+       int    index2 = lowbit(mask);
+       mask &= ~index2;
+       switch (index2)
+       {
+         case XSyncCACounter:
+           mask &= ~XSyncCACounter;
+           /* sanity check in SyncInitTrigger */
+           counter = *values++;
+           break;
+
+         case XSyncCAValueType:
+           mask &= ~XSyncCAValueType;
+           /* sanity check in SyncInitTrigger */
+           pAlarm->trigger.value_type = *values++;
+           break;
+
+         case XSyncCAValue:
+           mask &= ~XSyncCAValue;
+           XSyncIntsToValue(&pAlarm->trigger.wait_value, values[1], values[0]);
+           values += 2;
+           break;
+
+         case XSyncCATestType:
+           mask &= ~XSyncCATestType;
+           /* sanity check in SyncInitTrigger */
+           pAlarm->trigger.test_type = *values++;
+           break;
+
+         case XSyncCADelta:
+           mask &= ~XSyncCADelta;
+           XSyncIntsToValue(&pAlarm->delta, values[1], values[0]);
+           values += 2;
+           break;
+
+         case XSyncCAEvents:
+           mask &= ~XSyncCAEvents;
+           if ((*values != xTrue) && (*values != xFalse))
+           {
+               client->errorValue = *values;
+               return BadValue;
+           }
+           status = SyncEventSelectForAlarm(pAlarm, client,
+                                            (Bool)(*values++));
+           if (status != Success)
+               return status;
+           break;
+
+         default:
+           client->errorValue = mask;
+           return BadValue;
+       }
+    }
+
+    /* "If the test-type is PositiveComparison or PositiveTransition
+     *  and delta is less than zero, or if the test-type is
+     *  NegativeComparison or NegativeTransition and delta is
+     *  greater than zero, a Match error is generated."
+     */
+    if (origmask & (XSyncCADelta|XSyncCATestType))
+    {
+       CARD64 zero;
+       XSyncIntToValue(&zero, 0);
+       if ((((pAlarm->trigger.test_type == XSyncPositiveComparison) ||
+             (pAlarm->trigger.test_type == XSyncPositiveTransition))
+            && XSyncValueLessThan(pAlarm->delta, zero))
+           ||
+           (((pAlarm->trigger.test_type == XSyncNegativeComparison) ||
+             (pAlarm->trigger.test_type == XSyncNegativeTransition))
+            && XSyncValueGreaterThan(pAlarm->delta, zero))
+          )
+       {
+           return BadMatch;
+       }
+    }
+
+    /* postpone this until now, when we're sure nothing else can go wrong */
+    if ((status = SyncInitTrigger(client, &pAlarm->trigger, counter,
+                            origmask & XSyncCAAllTrigger)) != Success)
+       return status;
+
+    /* XXX spec does not really say to do this - needs clarification */
+    pAlarm->state = XSyncAlarmActive;
+    return Success;
+}
+
+
+static SyncCounter *
+SyncCreateCounter(client, id, initialvalue)
+    ClientPtr  client;
+    XSyncCounter id;
+    CARD64      initialvalue;
+{
+    SyncCounter *pCounter;
+
+    if (!(pCounter = (SyncCounter *) xalloc(sizeof(SyncCounter))))
+       return (SyncCounter *)NULL;
+
+    if (!AddResource(id, RTCounter, (pointer) pCounter))
+    {
+       xfree((pointer) pCounter);
+       return (SyncCounter *)NULL;
+    }
+
+    pCounter->client = client;
+    pCounter->id = id;
+    pCounter->value = initialvalue;
+    pCounter->pTriglist = NULL;
+    pCounter->beingDestroyed = FALSE;
+    pCounter->pSysCounterInfo = NULL;
+    return pCounter;
+}
+
+static int FreeCounter(
+#if NeedFunctionPrototypes
+    pointer /*env*/,
+    XID     /*id*/
+#endif
+);
+
+/*
+ * ***** System Counter utilities
+ */
+
+pointer 
+SyncCreateSystemCounter(name, initial, resolution, counterType,
+                       QueryValue, BracketValues)
+    char           *name;
+    CARD64          initial;
+    CARD64          resolution;
+    SyncCounterType counterType;
+    void            (*QueryValue) ();
+    void            (*BracketValues) ();
+{
+    SyncCounter    *pCounter;
+
+    SysCounterList = (SyncCounter **)xrealloc(SysCounterList,
+                           (SyncNumSystemCounters+1)*sizeof(SyncCounter *));
+    if (!SysCounterList)
+       return (pointer)NULL;
+
+    /* this function may be called before SYNC has been initialized, so we
+     * have to make sure RTCounter is created.
+     */
+    if (RTCounter == 0)
+    {
+       RTCounter = CreateNewResourceType(FreeCounter);
+       if (RTCounter == 0)
+       {
+           return (pointer)NULL;
+       }
+    }
+
+    pCounter = SyncCreateCounter((ClientPtr)NULL, FakeClientID(0), initial);
+
+    if (pCounter)
+    {
+       SysCounterInfo *psci;
+
+       psci = (SysCounterInfo *)xalloc(sizeof(SysCounterInfo));
+       if (!psci)
+       {
+           FreeResource(pCounter->id, RT_NONE);
+           return (pointer) pCounter;
+       }
+       pCounter->pSysCounterInfo = psci;
+       psci->name = name;
+       psci->resolution = resolution;
+       psci->counterType = counterType;
+       psci->QueryValue = QueryValue;
+       psci->BracketValues = BracketValues;
+       XSyncMaxValue(&psci->bracket_greater);
+       XSyncMinValue(&psci->bracket_less);
+       SysCounterList[SyncNumSystemCounters++] = pCounter;
+    }
+    return (pointer) pCounter;
+}
+
+void
+SyncDestroySystemCounter(pSysCounter)
+    pointer pSysCounter;
+{
+    SyncCounter *pCounter = (SyncCounter *)pSysCounter;
+    FreeResource(pCounter->id, RT_NONE);
+}
+
+static void
+SyncComputeBracketValues(pCounter, startOver)
+    SyncCounter *pCounter;
+    Bool startOver;
+{
+    SyncTriggerList *pCur;
+    SyncTrigger *pTrigger;
+    SysCounterInfo *psci = pCounter->pSysCounterInfo;
+    CARD64 *pnewgtval = NULL;
+    CARD64 *pnewltval = NULL;
+    SyncCounterType ct;
+
+    if (!pCounter)
+       return;
+
+    ct = pCounter->pSysCounterInfo->counterType;
+    if (ct == XSyncCounterNeverChanges)
+       return;
+
+    if (startOver)
+    {
+       XSyncMaxValue(&psci->bracket_greater);
+       XSyncMinValue(&psci->bracket_less);
+    }
+
+    for (pCur = pCounter->pTriglist; pCur; pCur = pCur->next)
+    {
+       pTrigger = pCur->pTrigger;
+       
+        if (pTrigger->test_type == XSyncPositiveComparison &&
+           ct != XSyncCounterNeverIncreases)
+       {
+           if (XSyncValueLessThan(pCounter->value, pTrigger->test_value) &&
+               XSyncValueLessThan(pTrigger->test_value,
+                                  psci->bracket_greater))
+           {
+               psci->bracket_greater = pTrigger->test_value;
+               pnewgtval = &psci->bracket_greater;
+           }
+       }
+       else if (pTrigger->test_type == XSyncNegativeComparison &&
+                ct != XSyncCounterNeverDecreases)
+       {
+           if (XSyncValueGreaterThan(pCounter->value, pTrigger->test_value) &&
+               XSyncValueGreaterThan(pTrigger->test_value,
+                                     psci->bracket_less))
+           {
+               psci->bracket_less = pTrigger->test_value;
+               pnewltval = &psci->bracket_less;
+           }
+       }
+       else if ( (pTrigger->test_type == XSyncPositiveTransition &&
+                  ct != XSyncCounterNeverIncreases)
+                ||
+                (pTrigger->test_type == XSyncNegativeTransition &&
+                 ct != XSyncCounterNeverDecreases)
+                )
+       {
+           if (XSyncValueLessThan(pCounter->value, pTrigger->test_value))
+           {
+               if (XSyncValueLessThan(pTrigger->test_value,
+                                      psci->bracket_greater))
+               {
+                   psci->bracket_greater = pTrigger->test_value;
+                   pnewgtval = &psci->bracket_greater;
+               }
+               else
+               if (XSyncValueGreaterThan(pTrigger->test_value,
+                                         psci->bracket_less))
+               {
+                   psci->bracket_less = pTrigger->test_value;
+                   pnewltval = &psci->bracket_less;
+               }
+           }
+       }
+    } /* end for each trigger */
+
+    if (pnewgtval || pnewltval)
+    {
+       (*psci->BracketValues)((pointer)pCounter, pnewltval, pnewgtval);
+    }
+}
+
+/*
+ * *****  Resource delete functions
+ */
+
+/* ARGSUSED */
+static int
+FreeAlarm(addr, id)
+    pointer         addr;
+    XID             id;
+{
+    SyncAlarm      *pAlarm = (SyncAlarm *) addr;
+
+    pAlarm->state = XSyncAlarmDestroyed;
+
+    SyncSendAlarmNotifyEvents(pAlarm);
+
+    /* delete event selections */
+
+    while (pAlarm->pEventClients)
+       FreeResource(pAlarm->pEventClients->delete_id, RT_NONE);
+
+    SyncDeleteTriggerFromCounter(&pAlarm->trigger);
+
+    xfree(pAlarm);
+    return Success;
+}
+
+
+/*
+ * ** Cleanup after the destruction of a Counter
+ */
+/* ARGSUSED */
+static int
+FreeCounter(env, id)
+    pointer         env;
+    XID             id;
+{
+    SyncCounter     *pCounter = (SyncCounter *) env;
+    SyncTriggerList *ptl, *pnext;
+
+    pCounter->beingDestroyed = TRUE;
+    /* tell all the counter's triggers that the counter has been destroyed */
+    for (ptl = pCounter->pTriglist; ptl; ptl = pnext)
+    {
+       (*ptl->pTrigger->CounterDestroyed)(ptl->pTrigger);
+       pnext = ptl->next;
+       xfree(ptl); /* destroy the trigger list as we go */
+    }
+    if (IsSystemCounter(pCounter))
+    {
+       int i, found = 0;
+
+       xfree(pCounter->pSysCounterInfo);
+
+       /* find the counter in the list of system counters and remove it */
+
+       if (SysCounterList)
+       {
+           for (i = 0; i < SyncNumSystemCounters; i++)
+           {
+               if (SysCounterList[i] == pCounter)
+               {
+                   found = i;
+                   break;
+               }
+           }
+           if (found < (SyncNumSystemCounters-1))
+           {
+               for (i = found; i < SyncNumSystemCounters-1; i++)
+               {
+                   SysCounterList[i] = SysCounterList[i+1];
+               }
+           }
+       }
+       SyncNumSystemCounters--;
+    }
+    xfree(pCounter);
+    return Success;
+}
+
+/*
+ * ** Cleanup after Await
+ */
+/* ARGSUSED */
+static int
+FreeAwait(addr, id)
+    pointer         addr;
+    XID             id;
+{
+    SyncAwaitUnion *pAwaitUnion = (SyncAwaitUnion *) addr;
+    SyncAwait *pAwait;
+    int numwaits;
+
+    pAwait = &(pAwaitUnion+1)->await; /* first await on list */
+
+    /* remove triggers from counters */
+
+    for (numwaits = pAwaitUnion->header.num_waitconditions; numwaits;
+        numwaits--, pAwait++)
+    {
+       /* If the counter is being destroyed, FreeCounter will delete 
+        * the trigger list itself, so don't do it here.
+        */
+       SyncCounter *pCounter = pAwait->trigger.pCounter;
+       if (pCounter && !pCounter->beingDestroyed)
+           SyncDeleteTriggerFromCounter(&pAwait->trigger);
+    }
+    xfree(pAwaitUnion);
+    return Success;
+}
+
+/* loosely based on dix/events.c/OtherClientGone */
+static int
+FreeAlarmClient(value, id)
+    pointer value; /* must conform to DeleteType */
+    XID   id;
+{
+    SyncAlarm *pAlarm = (SyncAlarm *)value;
+    SyncAlarmClientList *pCur, *pPrev;
+
+    for (pPrev = NULL, pCur = pAlarm->pEventClients;
+        pCur;
+        pPrev = pCur, pCur = pCur->next)
+    {
+       if (pCur->delete_id == id)
+       {
+           if (pPrev)
+               pPrev->next = pCur->next;
+           else
+               pAlarm->pEventClients = pCur->next;
+           xfree(pCur);
+           return(Success);
+       }
+    }
+    FatalError("alarm client not on event list");
+    /*NOTREACHED*/
+}
+
+
+/*
+ * *****  Proc functions
+ */
+
+
+/*
+ * ** Initialize the extension
+ */
+static int 
+ProcSyncInitialize(client)
+    ClientPtr       client;
+{
+    xSyncInitializeReply  rep;
+    int   n;
+
+    REQUEST_SIZE_MATCH(xSyncInitializeReq);
+
+    rep.type = X_Reply;
+    rep.sequenceNumber = client->sequence;
+    rep.majorVersion = SYNC_MAJOR_VERSION;
+    rep.minorVersion = SYNC_MINOR_VERSION;
+    rep.length = 0;
+
+    if (client->swapped)
+    {
+       swaps(&rep.sequenceNumber, n);
+    }
+    WriteToClient(client, sizeof(rep), (char *) &rep);
+    return (client->noClientException);
+}
+
+/*
+ * ** Get list of system counters available through the extension
+ */
+static int 
+ProcSyncListSystemCounters(client)
+    ClientPtr       client;
+{
+    xSyncListSystemCountersReply  rep;
+    int i, len;
+    xSyncSystemCounter *list, *walklist;
+    
+    REQUEST_SIZE_MATCH(xSyncListSystemCountersReq);
+
+    rep.type = X_Reply;
+    rep.sequenceNumber = client->sequence;
+    rep.nCounters = SyncNumSystemCounters;
+
+    for (i = len = 0; i < SyncNumSystemCounters; i++)
+    {
+       char *name = SysCounterList[i]->pSysCounterInfo->name;
+       /* pad to 4 byte boundary */
+       len += (sz_xSyncSystemCounter + strlen(name) + 3) & ~3;
+    }
+
+    if (len)
+    {
+       walklist = list = (xSyncSystemCounter *) ALLOCATE_LOCAL(len);
+       if (!list)
+           return BadAlloc;
+    }
+
+    rep.length = len >> 2;
+
+    if (client->swapped)
+    {
+       register char n;
+       swaps(&rep.sequenceNumber, n);
+       swapl(&rep.length, n);
+       swapl(&rep.nCounters, n);
+    }
+
+    for (i = 0; i < SyncNumSystemCounters; i++)
+    {
+       int namelen;
+       char *pname_in_reply;
+       SysCounterInfo *psci = SysCounterList[i]->pSysCounterInfo;
+
+       walklist->counter = SysCounterList[i]->id;
+       walklist->resolution_hi = XSyncValueHigh32(psci->resolution);
+       walklist->resolution_lo = XSyncValueLow32(psci->resolution);
+       namelen = strlen(psci->name);
+       walklist->name_length = namelen;
+
+       if (client->swapped)
+       {
+           register char n;
+           swapl(&walklist->counter, n);
+           swapl(&walklist->resolution_hi, n);
+           swapl(&walklist->resolution_lo, n);
+           swaps(&walklist->name_length, n);
+       }
+
+       pname_in_reply = ((char *)walklist) + sz_xSyncSystemCounter;
+       strncpy(pname_in_reply, psci->name, namelen);
+       walklist = (xSyncSystemCounter *) (((char *)walklist) + 
+                               ((sz_xSyncSystemCounter + namelen + 3) & ~3));
+    }
+
+    WriteToClient(client, sizeof(rep), (char *) &rep);
+    if (len) 
+    {
+       WriteToClient(client, len, (char *) list);
+       DEALLOCATE_LOCAL(list);
+    }
+
+    return (client->noClientException);
+}
+
+/*
+ * ** Set client Priority
+ */
+static int 
+ProcSyncSetPriority(client)
+    ClientPtr       client;
+{
+    REQUEST(xSyncSetPriorityReq);
+    ClientPtr priorityclient;
+
+    REQUEST_SIZE_MATCH(xSyncSetPriorityReq);
+
+    if (stuff->id == None)
+       priorityclient = client;
+    else if (!(priorityclient = LookupClient(stuff->id, client)))
+    {
+       client->errorValue = stuff->id;
+       return BadMatch;
+    }
+
+    if (priorityclient->priority != stuff->priority)
+    {
+       priorityclient->priority = stuff->priority;
+
+       /*  The following will force the server back into WaitForSomething
+        *  so that the change in this client's priority is immediately
+        *  reflected.
+        */
+       isItTimeToYield = TRUE;
+       dispatchException |= DE_PRIORITYCHANGE;
+    }
+    return Success;
+}
+
+/*
+ * ** Get client Priority
+ */
+static int 
+ProcSyncGetPriority(client)
+    ClientPtr       client;
+{
+    REQUEST(xSyncGetPriorityReq);
+    xSyncGetPriorityReply rep;
+    ClientPtr priorityclient;
+
+    REQUEST_SIZE_MATCH(xSyncGetPriorityReq);
+
+    if (stuff->id == None)
+       priorityclient = client;
+    else if (!(priorityclient = LookupClient(stuff->id, client)))
+    {
+       client->errorValue = stuff->id;
+       return BadMatch;
+    }
+
+    rep.type = X_Reply;
+    rep.length = 0;
+    rep.sequenceNumber = client->sequence;
+    rep.priority = priorityclient->priority;
+
+    if (client->swapped)
+    {
+       register char n;
+       swaps(&rep.sequenceNumber, n);
+       swapl(&rep.priority, n);
+    }
+
+    WriteToClient(client, sizeof(xSyncGetPriorityReply), (char *) &rep);
+
+    return (client->noClientException);
+}
+
+/*
+ * ** Create a new counter
+ */
+static int 
+ProcSyncCreateCounter(client)
+    ClientPtr       client;
+{
+    REQUEST(xSyncCreateCounterReq);
+    CARD64          initial;
+
+    REQUEST_SIZE_MATCH(xSyncCreateCounterReq);
+
+    LEGAL_NEW_RESOURCE(stuff->cid, client);
+
+    XSyncIntsToValue(&initial, stuff->initial_value_lo, stuff->initial_value_hi);
+    if (!SyncCreateCounter(client, stuff->cid, initial))
+       return BadAlloc;
+
+    return (client->noClientException);
+}
+
+/*
+ * ** Set Counter value
+ */
+static int 
+ProcSyncSetCounter(client)
+    ClientPtr       client;
+{
+    REQUEST(xSyncSetCounterReq);
+    SyncCounter    *pCounter;
+    CARD64        newvalue;
+
+    pCounter = (SyncCounter *)SecurityLookupIDByType(client, stuff->cid,
+                                          RTCounter, SecurityWriteAccess);
+    if (pCounter == NULL)
+    {
+       client->errorValue = stuff->cid;
+       return SyncErrorBase + XSyncBadCounter;
+    }
+
+    if (IsSystemCounter(pCounter))
+    {
+       client->errorValue = stuff->cid;
+       return BadAccess;
+    }
+
+    XSyncIntsToValue(&newvalue, stuff->value_lo, stuff->value_hi);
+    SyncChangeCounter(pCounter, newvalue);
+    return Success;
+}
+
+/*
+ * ** Change Counter value
+ */
+static int 
+ProcSyncChangeCounter(client)
+    ClientPtr       client;
+{
+    REQUEST(xSyncChangeCounterReq);
+    SyncCounter    *pCounter;
+    CARD64          newvalue;
+    Bool           overflow;
+
+    REQUEST_SIZE_MATCH(xSyncChangeCounterReq);
+
+    pCounter = (SyncCounter *) SecurityLookupIDByType(client, stuff->cid,
+                                           RTCounter, SecurityWriteAccess);
+    if (pCounter == NULL)
+    {
+       client->errorValue = stuff->cid;
+       return SyncErrorBase + XSyncBadCounter;
+    }
+
+    if (IsSystemCounter(pCounter))
+    {
+       client->errorValue = stuff->cid;
+       return BadAccess;
+    }
+
+    XSyncIntsToValue(&newvalue, stuff->value_lo, stuff->value_hi);
+    XSyncValueAdd(&newvalue, pCounter->value, newvalue, &overflow);
+    if (overflow)
+    {
+       /* XXX 64 bit value can't fit in 32 bits; do the best we can */
+       client->errorValue = stuff->value_hi; 
+       return BadValue;
+    }
+    SyncChangeCounter(pCounter, newvalue);
+    return Success;
+}
+
+/*
+ * ** Destroy a counter
+ */
+static int 
+ProcSyncDestroyCounter(client)
+    ClientPtr       client;
+{
+    REQUEST(xSyncDestroyCounterReq);
+    SyncCounter    *pCounter;
+
+    REQUEST_SIZE_MATCH(xSyncDestroyCounterReq);
+
+    pCounter = (SyncCounter *)SecurityLookupIDByType(client, stuff->counter,
+                                          RTCounter, SecurityDestroyAccess);
+    if (pCounter == NULL)
+    {
+       client->errorValue = stuff->counter;
+       return SyncErrorBase + XSyncBadCounter;
+    }
+    if (IsSystemCounter(pCounter))
+    {
+       client->errorValue = stuff->counter;
+       return BadAccess;
+    }
+    FreeResource(pCounter->id, RT_NONE);
+    return Success;
+}
+
+
+/*
+ * ** Await
+ */
+static int 
+ProcSyncAwait(client)
+    ClientPtr       client;
+{
+    REQUEST(xSyncAwaitReq);
+    int             len, items;
+    int             i;
+    xSyncWaitCondition *pProtocolWaitConds;
+    SyncAwaitUnion *pAwaitUnion;
+    SyncAwait     *pAwait;
+    int                   status;
+
+    REQUEST_AT_LEAST_SIZE(xSyncAwaitReq);
+
+    len = client->req_len << 2;
+    len -= sz_xSyncAwaitReq;
+    items = len / sz_xSyncWaitCondition;
+
+    if (items * sz_xSyncWaitCondition != len)
+    {
+       return BadLength;
+    }
+    if (items == 0)
+    {
+       client->errorValue = items; /* XXX protocol change */
+       return BadValue;
+    }
+
+    pProtocolWaitConds = (xSyncWaitCondition *) & stuff[1];
+
+    /*  all the memory for the entire await list is allocated 
+     *  here in one chunk
+     */
+    pAwaitUnion = (SyncAwaitUnion *)xalloc((items+1) * sizeof(SyncAwaitUnion));
+    if (!pAwaitUnion)
+       return BadAlloc;
+
+    /* first item is the header, remainder are real wait conditions */
+
+    pAwaitUnion->header.delete_id = FakeClientID(client->index);
+    if (!AddResource(pAwaitUnion->header.delete_id, RTAwait, pAwaitUnion))
+    {
+       xfree(pAwaitUnion);
+       return BadAlloc;
+    }
+
+    /* don't need to do any more memory allocation for this request! */
+
+    pAwaitUnion->header.client = client;
+    pAwaitUnion->header.num_waitconditions = 0;
+
+    pAwait = &(pAwaitUnion+1)->await; /* skip over header */
+    for (i = 0; i < items; i++, pProtocolWaitConds++, pAwait++)
+    {
+       if (pProtocolWaitConds->counter == None) /* XXX protocol change */
+       {
+           /*  this should take care of removing any triggers created by
+            *  this request that have already been registered on counters
+            */
+           FreeResource(pAwaitUnion->header.delete_id, RT_NONE);
+           client->errorValue = pProtocolWaitConds->counter;
+           return SyncErrorBase + XSyncBadCounter;
+       }
+
+       /* sanity checks are in SyncInitTrigger */
+       pAwait->trigger.pCounter = NULL;
+       pAwait->trigger.value_type = pProtocolWaitConds->value_type;
+       XSyncIntsToValue(&pAwait->trigger.wait_value,
+                        pProtocolWaitConds->wait_value_lo,
+                        pProtocolWaitConds->wait_value_hi);
+       pAwait->trigger.test_type = pProtocolWaitConds->test_type;
+
+       status = SyncInitTrigger(client, &pAwait->trigger,
+                        pProtocolWaitConds->counter, XSyncCAAllTrigger);
+       if (status != Success)
+       {
+           /*  this should take care of removing any triggers created by
+            *  this request that have already been registered on counters
+            */
+           FreeResource(pAwaitUnion->header.delete_id, RT_NONE);
+           return status;
+       }
+       /* this is not a mistake -- same function works for both cases */
+       pAwait->trigger.TriggerFired = SyncAwaitTriggerFired;
+       pAwait->trigger.CounterDestroyed = SyncAwaitTriggerFired;
+       XSyncIntsToValue(&pAwait->event_threshold,
+                        pProtocolWaitConds->event_threshold_lo,
+                        pProtocolWaitConds->event_threshold_hi);
+       pAwait->pHeader = &pAwaitUnion->header;
+       pAwaitUnion->header.num_waitconditions++;
+    }
+
+    IgnoreClient(client);
+
+    /* see if any of the triggers are already true */
+
+    pAwait = &(pAwaitUnion+1)->await; /* skip over header */
+    for (i = 0; i < items; i++, pAwait++)
+    {
+       /*  don't have to worry about NULL counters because the request
+        *  errors before we get here out if they occur
+        */
+       if ((*pAwait->trigger.CheckTrigger)(&pAwait->trigger,
+                                           pAwait->trigger.pCounter->value))
+       {
+           (*pAwait->trigger.TriggerFired)(&pAwait->trigger);
+           break; /* once is enough */
+       }
+    }
+    return Success;
+}
+
+
+/*
+ * ** Query a counter
+ */
+static int 
+ProcSyncQueryCounter(client)
+    ClientPtr       client;
+{
+    REQUEST(xSyncQueryCounterReq);
+    xSyncQueryCounterReply rep;
+    SyncCounter    *pCounter;
+
+    REQUEST_SIZE_MATCH(xSyncQueryCounterReq);
+
+    pCounter = (SyncCounter *)SecurityLookupIDByType(client, stuff->counter,
+                                           RTCounter, SecurityReadAccess);
+    if (pCounter == NULL)
+    {
+       client->errorValue = stuff->counter;
+       return SyncErrorBase + XSyncBadCounter;
+    }
+
+    rep.type = X_Reply;
+    rep.length = 0;
+    rep.sequenceNumber = client->sequence;
+
+    /* if system counter, ask it what the current value is */
+
+    if (IsSystemCounter(pCounter))
+    {
+       (*pCounter->pSysCounterInfo->QueryValue) ((pointer) pCounter,
+                                                 &pCounter->value);
+    }
+
+    rep.value_hi = XSyncValueHigh32(pCounter->value);
+    rep.value_lo = XSyncValueLow32(pCounter->value);
+    if (client->swapped)
+    {
+       register char n;
+       swaps(&rep.sequenceNumber, n);
+       swapl(&rep.length, n);
+       swapl(&rep.value_hi, n);
+       swapl(&rep.value_lo, n);
+    }
+    WriteToClient(client, sizeof(xSyncQueryCounterReply), (char *) &rep);
+    return (client->noClientException);
+}
+
+
+/*
+ * ** Create Alarm
+ */
+static int 
+ProcSyncCreateAlarm(client)
+    ClientPtr       client;
+{
+    REQUEST(xSyncCreateAlarmReq);
+    SyncAlarm      *pAlarm;
+    int             status;
+    unsigned long   len, vmask;
+    SyncTrigger            *pTrigger;
+
+    REQUEST_AT_LEAST_SIZE(xSyncCreateAlarmReq);
+
+    LEGAL_NEW_RESOURCE(stuff->id, client);
+
+    vmask = stuff->valueMask;
+    len = client->req_len - (sizeof(xSyncCreateAlarmReq) >> 2);
+    /* the "extra" call to Ones accounts for the presence of 64 bit values */
+    if (len != (Ones(vmask) + Ones(vmask & (XSyncCAValue|XSyncCADelta))))
+       return BadLength;
+
+    if (!(pAlarm = (SyncAlarm *) xalloc(sizeof(SyncAlarm))))
+    {
+       return BadAlloc;
+    }
+
+    /* set up defaults */
+
+    pTrigger = &pAlarm->trigger;
+    pTrigger->pCounter = NULL;
+    pTrigger->value_type = XSyncAbsolute;
+    XSyncIntToValue(&pTrigger->wait_value, 0L);
+    pTrigger->test_type = XSyncPositiveComparison;
+    pTrigger->TriggerFired = SyncAlarmTriggerFired;
+    pTrigger->CounterDestroyed = SyncAlarmCounterDestroyed;
+    status = SyncInitTrigger(client, pTrigger, None, XSyncCAAllTrigger);
+    if (status != Success)
+    {
+       xfree(pAlarm);
+       return status;
+    }
+
+    pAlarm->client = client;
+    pAlarm->alarm_id = stuff->id;
+    XSyncIntToValue(&pAlarm->delta, 1L);
+    pAlarm->events = TRUE;
+    pAlarm->state = XSyncAlarmInactive;
+    pAlarm->pEventClients = NULL;
+    status = SyncChangeAlarmAttributes(client, pAlarm, vmask,
+                                      (CARD32 *)&stuff[1]);
+    if (status != Success)
+    {
+       xfree(pAlarm);
+       return status;
+    }
+
+    if (!AddResource(stuff->id, RTAlarm, pAlarm))
+    {
+       xfree(pAlarm);
+       return BadAlloc;
+    }
+
+    /*  see if alarm already triggered.  NULL counter will not trigger
+     *  in CreateAlarm and sets alarm state to Inactive.
+     */
+
+    if (!pTrigger->pCounter)
+    {
+       pAlarm->state = XSyncAlarmInactive; /* XXX protocol change */
+    }
+    else if ((*pTrigger->CheckTrigger)(pTrigger, pTrigger->pCounter->value))
+    {
+       (*pTrigger->TriggerFired)(pTrigger);
+    }
+
+    return Success;
+}
+
+/*
+ * ** Change Alarm
+ */
+static int 
+ProcSyncChangeAlarm(client)
+    ClientPtr       client;
+{
+    REQUEST(xSyncChangeAlarmReq);
+    SyncAlarm   *pAlarm;
+    long        vmask;
+    int         len, status;
+
+    REQUEST_AT_LEAST_SIZE(xSyncChangeAlarmReq);
+
+    if (!(pAlarm = (SyncAlarm *)SecurityLookupIDByType(client, stuff->alarm,
+                                             RTAlarm, SecurityWriteAccess)))
+    {
+       client->errorValue = stuff->alarm;
+       return SyncErrorBase + XSyncBadAlarm;
+    }
+
+    vmask = stuff->valueMask;
+    len = client->req_len - (sizeof(xSyncChangeAlarmReq) >> 2);
+    /* the "extra" call to Ones accounts for the presence of 64 bit values */
+    if (len != (Ones(vmask) + Ones(vmask & (XSyncCAValue|XSyncCADelta))))
+       return BadLength;
+
+    if ((status = SyncChangeAlarmAttributes(client, pAlarm, vmask, 
+                                           (CARD32 *)&stuff[1])) != Success)
+       return status;
+
+    /*  see if alarm already triggered.  NULL counter WILL trigger
+     *  in ChangeAlarm.
+     */
+
+    if (!pAlarm->trigger.pCounter ||
+       (*pAlarm->trigger.CheckTrigger)(&pAlarm->trigger,
+                                       pAlarm->trigger.pCounter->value))
+    {
+       (*pAlarm->trigger.TriggerFired)(&pAlarm->trigger);
+    }
+    return Success;
+}
+
+static int 
+ProcSyncQueryAlarm(client)
+    ClientPtr       client;
+{
+    REQUEST(xSyncQueryAlarmReq);
+    SyncAlarm      *pAlarm;
+    xSyncQueryAlarmReply rep;
+    SyncTrigger    *pTrigger;
+
+    REQUEST_SIZE_MATCH(xSyncQueryAlarmReq);
+
+    pAlarm = (SyncAlarm *)SecurityLookupIDByType(client, stuff->alarm,
+                                               RTAlarm, SecurityReadAccess);
+    if (!pAlarm)
+    {
+       client->errorValue = stuff->alarm;
+       return (SyncErrorBase + XSyncBadAlarm);
+    }
+
+    rep.type = X_Reply;
+    rep.length = (sizeof(xSyncQueryAlarmReply) - sizeof(xGenericReply)) >> 2;
+    rep.sequenceNumber = client->sequence;
+
+    pTrigger = &pAlarm->trigger;
+    rep.counter = (pTrigger->pCounter) ? pTrigger->pCounter->id : None;
+
+#if 0 /* XXX unclear what to do, depends on whether relative value-types
+       * are "consumed" immediately and are considered absolute from then
+       * on.
+       */
+    rep.value_type = pTrigger->value_type;
+    rep.wait_value_hi = XSyncValueHigh32(pTrigger->wait_value);
+    rep.wait_value_lo = XSyncValueLow32(pTrigger->wait_value);
+#else
+    rep.value_type = XSyncAbsolute;
+    rep.wait_value_hi = XSyncValueHigh32(pTrigger->test_value);
+    rep.wait_value_lo = XSyncValueLow32(pTrigger->test_value);
+#endif
+
+    rep.test_type = pTrigger->test_type;
+    rep.delta_hi = XSyncValueHigh32(pAlarm->delta);
+    rep.delta_lo = XSyncValueLow32(pAlarm->delta);
+    rep.events = pAlarm->events;
+    rep.state = pAlarm->state;
+
+    if (client->swapped)
+    {
+       register char n;
+       swaps(&rep.sequenceNumber, n);
+       swapl(&rep.length, n);
+       swapl(&rep.counter, n);
+       swapl(&rep.wait_value_hi, n);
+       swapl(&rep.wait_value_lo, n);
+       swapl(&rep.test_type, n);
+       swapl(&rep.delta_hi, n);
+       swapl(&rep.delta_lo, n);
+    }
+
+    WriteToClient(client, sizeof(xSyncQueryAlarmReply), (char *) &rep);
+    return (client->noClientException);
+}
+
+
+static int 
+ProcSyncDestroyAlarm(client)
+    ClientPtr       client;
+{
+    SyncAlarm      *pAlarm;
+    REQUEST(xSyncDestroyAlarmReq);
+
+    REQUEST_SIZE_MATCH(xSyncDestroyAlarmReq);
+
+    if (!(pAlarm = (SyncAlarm *)SecurityLookupIDByType(client, stuff->alarm,
+                                             RTAlarm, SecurityDestroyAccess)))
+    {
+       client->errorValue = stuff->alarm;
+       return SyncErrorBase + XSyncBadAlarm;
+    }
+
+    FreeResource(stuff->alarm, RT_NONE);
+    return (client->noClientException);
+}
+
+/*
+ * ** Given an extension request, call the appropriate request procedure
+ */
+static int 
+ProcSyncDispatch(client)
+    ClientPtr       client;
+{
+    REQUEST(xReq);
+
+    switch (stuff->data)
+    {
+
+      case X_SyncInitialize:
+       return ProcSyncInitialize(client);
+      case X_SyncListSystemCounters:
+       return ProcSyncListSystemCounters(client);
+      case X_SyncCreateCounter:
+       return ProcSyncCreateCounter(client);
+      case X_SyncSetCounter:
+       return ProcSyncSetCounter(client);
+      case X_SyncChangeCounter:
+       return ProcSyncChangeCounter(client);
+      case X_SyncQueryCounter:
+       return ProcSyncQueryCounter(client);
+      case X_SyncDestroyCounter:
+       return ProcSyncDestroyCounter(client);
+      case X_SyncAwait:
+       return ProcSyncAwait(client);
+      case X_SyncCreateAlarm:
+       return ProcSyncCreateAlarm(client);
+      case X_SyncChangeAlarm:
+       return ProcSyncChangeAlarm(client);
+      case X_SyncQueryAlarm:
+       return ProcSyncQueryAlarm(client);
+      case X_SyncDestroyAlarm:
+       return ProcSyncDestroyAlarm(client);
+      case X_SyncSetPriority:
+       return ProcSyncSetPriority(client);
+      case X_SyncGetPriority:
+       return ProcSyncGetPriority(client);
+      default:
+       return BadRequest;
+    }
+}
+
+/*
+ * Boring Swapping stuff ...
+ */
+
+static int 
+SProcSyncInitialize(client)
+    ClientPtr       client;
+{
+    REQUEST(xSyncInitializeReq);
+    register char   n;
+
+    swaps(&stuff->length, n);
+    REQUEST_SIZE_MATCH (xSyncInitializeReq);
+
+    return ProcSyncInitialize(client);
+}
+
+static int 
+SProcSyncListSystemCounters(client)
+    ClientPtr       client;
+{
+    REQUEST(xSyncListSystemCountersReq);
+    register char   n;
+
+    swaps(&stuff->length, n);
+    REQUEST_SIZE_MATCH (xSyncListSystemCountersReq);
+
+    return ProcSyncListSystemCounters(client);
+}
+
+static int 
+SProcSyncCreateCounter(client)
+    ClientPtr       client;
+{
+    REQUEST(xSyncCreateCounterReq);
+    register char   n;
+
+    swaps(&stuff->length, n);
+    REQUEST_SIZE_MATCH (xSyncCreateCounterReq);
+    swapl(&stuff->cid, n);
+    swapl(&stuff->initial_value_lo, n);
+    swapl(&stuff->initial_value_hi, n);
+
+    return ProcSyncCreateCounter(client);
+}
+
+static int 
+SProcSyncSetCounter(client)
+    ClientPtr       client;
+{
+    REQUEST(xSyncSetCounterReq);
+    register char   n;
+
+    swaps(&stuff->length, n);
+    REQUEST_SIZE_MATCH (xSyncSetCounterReq);
+    swapl(&stuff->cid, n);
+    swapl(&stuff->value_lo, n);
+    swapl(&stuff->value_hi, n);
+
+    return ProcSyncSetCounter(client);
+}
+
+static int 
+SProcSyncChangeCounter(client)
+    ClientPtr       client;
+{
+    REQUEST(xSyncChangeCounterReq);
+    register char   n;
+
+    swaps(&stuff->length, n);
+    REQUEST_SIZE_MATCH (xSyncChangeCounterReq);
+    swapl(&stuff->cid, n);
+    swapl(&stuff->value_lo, n);
+    swapl(&stuff->value_hi, n);
+
+    return ProcSyncChangeCounter(client);
+}
+
+static int 
+SProcSyncQueryCounter(client)
+    ClientPtr       client;
+{
+    REQUEST(xSyncQueryCounterReq);
+    register char   n;
+
+    swaps(&stuff->length, n);
+    REQUEST_SIZE_MATCH (xSyncQueryCounterReq);
+    swapl(&stuff->counter, n);
+
+    return ProcSyncQueryCounter(client);
+}
+
+static int 
+SProcSyncDestroyCounter(client)
+    ClientPtr       client;
+{
+    REQUEST(xSyncDestroyCounterReq);
+    register char   n;
+
+    swaps(&stuff->length, n);
+    REQUEST_SIZE_MATCH (xSyncDestroyCounterReq);
+    swapl(&stuff->counter, n);
+
+    return ProcSyncDestroyCounter(client);
+}
+
+static int 
+SProcSyncAwait(client)
+    ClientPtr       client;
+{
+    REQUEST(xSyncAwaitReq);
+    register char   n;
+
+    swaps(&stuff->length, n);
+    REQUEST_AT_LEAST_SIZE(xSyncAwaitReq);
+    SwapRestL(stuff);
+
+    return ProcSyncAwait(client);
+}
+
+
+static int 
+SProcSyncCreateAlarm(client)
+    ClientPtr       client;
+{
+    REQUEST(xSyncCreateAlarmReq);
+    register char   n;
+
+    swaps(&stuff->length, n);
+    REQUEST_AT_LEAST_SIZE(xSyncCreateAlarmReq);
+    swapl(&stuff->id, n);
+    swapl(&stuff->valueMask, n);
+    SwapRestL(stuff);
+
+    return ProcSyncCreateAlarm(client);
+}
+
+static int 
+SProcSyncChangeAlarm(client)
+    ClientPtr       client;
+{
+    REQUEST(xSyncChangeAlarmReq);
+    register char   n;
+
+    swaps(&stuff->length, n);
+    REQUEST_AT_LEAST_SIZE(xSyncChangeAlarmReq);
+    swapl(&stuff->alarm, n);
+    swapl(&stuff->valueMask, n);
+    SwapRestL(stuff);
+    return ProcSyncChangeAlarm(client);
+}
+
+static int 
+SProcSyncQueryAlarm(client)
+    ClientPtr       client;
+{
+    REQUEST(xSyncQueryAlarmReq);
+    register char   n;
+
+    swaps(&stuff->length, n);
+    REQUEST_SIZE_MATCH (xSyncQueryAlarmReq);
+    swapl(&stuff->alarm, n);
+
+    return ProcSyncQueryAlarm(client);
+}
+
+static int 
+SProcSyncDestroyAlarm(client)
+    ClientPtr       client;
+{
+    REQUEST(xSyncDestroyAlarmReq);
+    register char   n;
+
+    swaps(&stuff->length, n);
+    REQUEST_SIZE_MATCH (xSyncDestroyAlarmReq);
+    swapl(&stuff->alarm, n);
+
+    return ProcSyncDestroyAlarm(client);
+}
+
+static int 
+SProcSyncSetPriority(client)
+    ClientPtr       client;
+{
+    REQUEST(xSyncSetPriorityReq);
+    register char   n;
+
+    swaps(&stuff->length, n);
+    REQUEST_SIZE_MATCH (xSyncSetPriorityReq);
+    swapl(&stuff->id, n);
+    swapl(&stuff->priority, n);
+
+    return ProcSyncSetPriority(client);
+}
+
+static int 
+SProcSyncGetPriority(client)
+    ClientPtr       client;
+{
+    REQUEST(xSyncGetPriorityReq);
+    register char   n;
+
+    swaps(&stuff->length, n);
+    REQUEST_SIZE_MATCH (xSyncGetPriorityReq);
+    swapl(&stuff->id, n);
+
+    return ProcSyncGetPriority(client);
+}
+
+
+static int 
+SProcSyncDispatch(client)
+    ClientPtr       client;
+{
+    REQUEST(xReq);
+
+    switch (stuff->data)
+    {
+      case X_SyncInitialize:
+       return SProcSyncInitialize(client);
+      case X_SyncListSystemCounters:
+       return SProcSyncListSystemCounters(client);
+      case X_SyncCreateCounter:
+       return SProcSyncCreateCounter(client);
+      case X_SyncSetCounter:
+       return SProcSyncSetCounter(client);
+      case X_SyncChangeCounter:
+       return SProcSyncChangeCounter(client);
+      case X_SyncQueryCounter:
+       return SProcSyncQueryCounter(client);
+      case X_SyncDestroyCounter:
+       return SProcSyncDestroyCounter(client);
+      case X_SyncAwait:
+       return SProcSyncAwait(client);
+      case X_SyncCreateAlarm:
+       return SProcSyncCreateAlarm(client);
+      case X_SyncChangeAlarm:
+       return SProcSyncChangeAlarm(client);
+      case X_SyncQueryAlarm:
+       return SProcSyncQueryAlarm(client);
+      case X_SyncDestroyAlarm:
+       return SProcSyncDestroyAlarm(client);
+      case X_SyncSetPriority:
+       return SProcSyncSetPriority(client);
+      case X_SyncGetPriority:
+       return SProcSyncGetPriority(client);
+      default:
+       return BadRequest;
+    }
+}
+
+/*
+ * Event Swapping
+ */
+
+static void 
+SCounterNotifyEvent(from, to)
+    xSyncCounterNotifyEvent *from, *to;
+{
+    to->type = from->type;
+    to->kind = from->kind;
+    cpswaps(from->sequenceNumber, to->sequenceNumber);
+    cpswapl(from->counter, to->counter);
+    cpswapl(from->wait_value_lo, to->wait_value_lo);
+    cpswapl(from->wait_value_hi, to->wait_value_hi);
+    cpswapl(from->counter_value_lo, to->counter_value_lo);
+    cpswapl(from->counter_value_hi, to->counter_value_hi);
+    cpswapl(from->time, to->time);
+    cpswaps(from->count, to->count);
+    to->destroyed = from->destroyed;
+}
+
+
+static void 
+SAlarmNotifyEvent(from, to)
+    xSyncAlarmNotifyEvent *from, *to;
+{
+    to->type = from->type;
+    to->kind = from->kind;
+    cpswaps(from->sequenceNumber, to->sequenceNumber);
+    cpswapl(from->alarm, to->alarm);
+    cpswapl(from->counter_value_lo, to->counter_value_lo);
+    cpswapl(from->counter_value_hi, to->counter_value_hi);
+    cpswapl(from->alarm_value_lo, to->alarm_value_lo);
+    cpswapl(from->alarm_value_hi, to->alarm_value_hi);
+    cpswapl(from->time, to->time);
+    to->state = from->state;
+}
+
+/*
+ * ** Close everything down. ** This is fairly simple for now.
+ */
+/* ARGSUSED */
+static void 
+SyncResetProc(extEntry)
+    ExtensionEntry *extEntry;
+{
+    xfree(SysCounterList);
+    SysCounterList = NULL;
+    RTCounter = 0;
+}
+
+
+/*
+ * ** Initialise the extension.
+ */
+void 
+SyncExtensionInit()
+{
+    ExtensionEntry *extEntry;
+
+    if (RTCounter == 0)
+    {
+       RTCounter = CreateNewResourceType(FreeCounter);
+    }
+    RTAlarm = CreateNewResourceType(FreeAlarm);
+    RTAwait = CreateNewResourceType(FreeAwait)|RC_NEVERRETAIN;
+    RTAlarmClient = CreateNewResourceType(FreeAlarmClient)|RC_NEVERRETAIN;
+
+    if (RTCounter == 0 || RTAwait == 0 || RTAlarm == 0 ||
+       RTAlarmClient == 0 ||
+       (extEntry = AddExtension(SYNC_NAME,
+                                XSyncNumberEvents, XSyncNumberErrors,
+                                ProcSyncDispatch, SProcSyncDispatch,
+                                SyncResetProc,
+                                StandardMinorOpcode)) == NULL)
+    {
+       ErrorF("Sync Extension %d.%d failed to Initialise\n",
+               SYNC_MAJOR_VERSION, SYNC_MINOR_VERSION);
+       return;
+    }
+
+    SyncReqCode = extEntry->base;
+    SyncEventBase = extEntry->eventBase;
+    SyncErrorBase = extEntry->errorBase;
+    EventSwapVector[SyncEventBase + XSyncCounterNotify] = (EventSwapPtr) SCounterNotifyEvent;
+    EventSwapVector[SyncEventBase + XSyncAlarmNotify] = (EventSwapPtr) SAlarmNotifyEvent;
+
+    /*
+     * Although SERVERTIME is implemented by the OS layer, we initialise it
+     * here because doing it in OsInit() is too early. The resource database
+     * is not initialised when OsInit() is called. This is just about OK
+     * because there is always a servertime counter.
+     */
+    SyncInitServerTime();
+
+#ifdef DEBUG
+    fprintf(stderr, "Sync Extension %d.%d\n",
+           SYNC_MAJOR_VERSION, SYNC_MINOR_VERSION);
+#endif
+}
+
+
+/*
+ * ***** SERVERTIME implementation - should go in its own file in OS directory?
+ */
+
+
+#if !defined(WIN32) && !defined(MINIX) && !defined(Lynx)
+#include <sys/time.h>
+#endif
+
+static pointer ServertimeCounter;
+static XSyncValue Now;
+static XSyncValue *pnext_time;
+
+#define GetTime()\
+{\
+    unsigned long millis = GetTimeInMillis();\
+    unsigned long maxis = XSyncValueHigh32(Now);\
+    if (millis < XSyncValueLow32(Now)) maxis++;\
+    XSyncIntsToValue(&Now, millis, maxis);\
+}
+
+/*
+*** Server Block Handler
+*** code inspired by multibuffer extension
+ */
+/*ARGSUSED*/
+static void ServertimeBlockHandler(env, wt, LastSelectMask)
+pointer env;
+struct timeval **wt;
+pointer LastSelectMask;
+{
+    XSyncValue delay;
+    unsigned long timeout;
+
+    if (pnext_time)
+    {
+        GetTime();
+
+        if (XSyncValueGreaterOrEqual(Now, *pnext_time))
+       {
+            timeout = 0;
+        } 
+       else
+       {
+           Bool overflow;
+            XSyncValueSubtract(&delay, *pnext_time, Now, &overflow);
+            timeout = XSyncValueLow32(delay);
+        }
+        AdjustWaitForDelay(wt, timeout); /* os/utils.c */
+    }
+}
+
+/*
+*** Wakeup Handler
+ */
+/*ARGSUSED*/
+static void ServertimeWakeupHandler(env, rc, LastSelectMask)
+pointer env;
+int rc;
+pointer LastSelectMask;
+{
+    if (pnext_time)
+    {
+        GetTime();
+
+        if (XSyncValueGreaterOrEqual(Now, *pnext_time))
+       {
+            SyncChangeCounter(ServertimeCounter, Now);
+        }
+    }
+}
+
+static void
+ServertimeQueryValue(pCounter, pValue_return)
+    pointer pCounter;
+    CARD64 *pValue_return;
+{
+    GetTime();
+    *pValue_return = Now;
+}
+
+static void
+ServertimeBracketValues(pCounter, pbracket_less, pbracket_greater)
+    pointer pCounter;
+    CARD64 *pbracket_less;
+    CARD64 *pbracket_greater;
+{
+    if (!pnext_time && pbracket_greater)
+    {
+       RegisterBlockAndWakeupHandlers(ServertimeBlockHandler,
+                                      ServertimeWakeupHandler,
+                                      NULL);
+    }
+    else if (pnext_time && !pbracket_greater)
+    {
+       RemoveBlockAndWakeupHandlers(ServertimeBlockHandler,
+                                    ServertimeWakeupHandler,
+                                    NULL);
+    }
+    pnext_time = pbracket_greater;
+}
+
+static void
+SyncInitServerTime()
+{
+    CARD64 resolution;
+
+    XSyncIntsToValue(&Now, GetTimeInMillis(), 0);
+    XSyncIntToValue(&resolution, 4);
+    ServertimeCounter = SyncCreateSystemCounter("SERVERTIME", Now, resolution,
+                           XSyncCounterNeverDecreases,
+                           ServertimeQueryValue, ServertimeBracketValues);
+    pnext_time = NULL;
+}
diff --git a/Xserver/programs/Xserver/Xext/xcmisc.c b/Xserver/programs/Xserver/Xext/xcmisc.c
new file mode 100644 (file)
index 0000000..099b8d4
--- /dev/null
@@ -0,0 +1,234 @@
+/* $XConsortium: xcmisc.c /main/5 1996/08/01 19:23:23 dpw $ */
+/* $XFree86: xc/programs/Xserver/Xext/xcmisc.c,v 3.2 1996/12/23 06:29:03 dawes Exp $ */
+/*
+
+Copyright (c) 1993  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be included
+in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR
+OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall
+not be used in advertising or otherwise to promote the sale, use or
+other dealings in this Software without prior written authorization
+from the X Consortium.
+
+*/
+
+#define NEED_EVENTS
+#define NEED_REPLIES
+#include "X.h"
+#include "Xproto.h"
+#include "misc.h"
+#include "os.h"
+#include "dixstruct.h"
+#include "extnsionst.h"
+#include "swaprep.h"
+#include "xcmiscstr.h"
+
+static unsigned char XCMiscCode;
+
+static void XCMiscResetProc(
+#if NeedFunctionPrototypes
+    ExtensionEntry * /* extEntry */
+#endif
+);
+
+static DISPATCH_PROC(ProcXCMiscDispatch);
+static DISPATCH_PROC(ProcXCMiscGetVersion);
+static DISPATCH_PROC(ProcXCMiscGetXIDList);
+static DISPATCH_PROC(ProcXCMiscGetXIDRange);
+static DISPATCH_PROC(SProcXCMiscDispatch);
+static DISPATCH_PROC(SProcXCMiscGetVersion);
+static DISPATCH_PROC(SProcXCMiscGetXIDList);
+static DISPATCH_PROC(SProcXCMiscGetXIDRange);
+
+void
+XCMiscExtensionInit()
+{
+    ExtensionEntry *extEntry;
+
+    if ((extEntry = AddExtension(XCMiscExtensionName, 0, 0,
+                               ProcXCMiscDispatch, SProcXCMiscDispatch,
+                               XCMiscResetProc, StandardMinorOpcode)) != 0)
+       XCMiscCode = (unsigned char)extEntry->base;
+    DeclareExtensionSecurity(XCMiscExtensionName, TRUE);
+}
+
+/*ARGSUSED*/
+static void
+XCMiscResetProc (extEntry)
+    ExtensionEntry     *extEntry;
+{
+}
+
+static int
+ProcXCMiscGetVersion(client)
+    register ClientPtr client;
+{
+    xXCMiscGetVersionReply rep;
+    register int n;
+
+    REQUEST_SIZE_MATCH(xXCMiscGetVersionReq);
+    rep.type = X_Reply;
+    rep.length = 0;
+    rep.sequenceNumber = client->sequence;
+    rep.majorVersion = XCMiscMajorVersion;
+    rep.minorVersion = XCMiscMinorVersion;
+    if (client->swapped) {
+       swaps(&rep.sequenceNumber, n);
+       swaps(&rep.majorVersion, n);
+       swaps(&rep.minorVersion, n);
+    }
+    WriteToClient(client, sizeof(xXCMiscGetVersionReply), (char *)&rep);
+    return(client->noClientException);
+}
+
+static int
+ProcXCMiscGetXIDRange(client)
+    register ClientPtr client;
+{
+    xXCMiscGetXIDRangeReply rep;
+    register int n;
+    XID min_id, max_id;
+
+    REQUEST_SIZE_MATCH(xXCMiscGetXIDRangeReq);
+    GetXIDRange(client->index, FALSE, &min_id, &max_id);
+    rep.type = X_Reply;
+    rep.length = 0;
+    rep.sequenceNumber = client->sequence;
+    rep.start_id = min_id;
+    rep.count = max_id - min_id + 1;
+    if (client->swapped) {
+       swaps(&rep.sequenceNumber, n);
+       swapl(&rep.start_id, n);
+       swapl(&rep.count, n);
+    }
+    WriteToClient(client, sizeof(xXCMiscGetXIDRangeReply), (char *)&rep);
+    return(client->noClientException);
+}
+
+static int
+ProcXCMiscGetXIDList(client)
+    register ClientPtr client;
+{
+    REQUEST(xXCMiscGetXIDListReq);
+    xXCMiscGetXIDListReply rep;
+    register int n;
+    XID *pids;
+    unsigned int count;
+
+    REQUEST_SIZE_MATCH(xXCMiscGetXIDListReq);
+
+    pids = (XID *)ALLOCATE_LOCAL(stuff->count * sizeof(XID));
+    if (!pids)
+    {
+       return BadAlloc;
+    }
+    count = GetXIDList(client, stuff->count, pids);
+    rep.type = X_Reply;
+    rep.sequenceNumber = client->sequence;
+    rep.length = count;
+    rep.count = count;
+    if (client->swapped) {
+       swaps(&rep.sequenceNumber, n);
+       swapl(&rep.length, n);
+       swapl(&rep.count, n);
+    }
+    WriteToClient(client, sizeof(xXCMiscGetXIDListReply), (char *)&rep);
+    if (count)
+    {
+       client->pSwapReplyFunc = (ReplySwapPtr) Swap32Write;
+       WriteSwappedDataToClient(client, count * sizeof(XID), pids);
+    }
+    DEALLOCATE_LOCAL(pids);
+    return(client->noClientException);
+}
+
+static int
+ProcXCMiscDispatch (client)
+    register ClientPtr client;
+{
+    REQUEST(xReq);
+    switch (stuff->data)
+    {
+    case X_XCMiscGetVersion:
+       return ProcXCMiscGetVersion(client);
+    case X_XCMiscGetXIDRange:
+       return ProcXCMiscGetXIDRange(client);
+    case X_XCMiscGetXIDList:
+       return ProcXCMiscGetXIDList(client);
+    default:
+       return BadRequest;
+    }
+}
+
+static int
+SProcXCMiscGetVersion(client)
+    register ClientPtr client;
+{
+    register int n;
+    REQUEST(xXCMiscGetVersionReq);
+
+    swaps(&stuff->length, n);
+    REQUEST_SIZE_MATCH(xXCMiscGetVersionReq);
+    swaps(&stuff->majorVersion, n);
+    swaps(&stuff->minorVersion, n);
+    return ProcXCMiscGetVersion(client);
+}
+
+static int
+SProcXCMiscGetXIDRange(client)
+    register ClientPtr client;
+{
+    register int n;
+    REQUEST(xReq);
+
+    swaps(&stuff->length, n);
+    return ProcXCMiscGetXIDRange(client);
+}
+
+static int
+SProcXCMiscGetXIDList(client)
+    register ClientPtr client;
+{
+    register int n;
+    REQUEST(xXCMiscGetXIDListReq);
+
+    swaps(&stuff->length, n);
+    swapl(&stuff->count, n);
+    return ProcXCMiscGetXIDList(client);
+}
+
+static int
+SProcXCMiscDispatch (client)
+    register ClientPtr client;
+{
+    REQUEST(xReq);
+    switch (stuff->data)
+    {
+    case X_XCMiscGetVersion:
+       return SProcXCMiscGetVersion(client);
+    case X_XCMiscGetXIDRange:
+       return SProcXCMiscGetXIDRange(client);
+    case X_XCMiscGetXIDList:
+       return SProcXCMiscGetXIDList(client);
+    default:
+       return BadRequest;
+    }
+}
diff --git a/Xserver/programs/Xserver/Xext/xf86dga.c b/Xserver/programs/Xserver/Xext/xf86dga.c
new file mode 100644 (file)
index 0000000..27d1fad
--- /dev/null
@@ -0,0 +1,483 @@
+/* $XFree86: xc/programs/Xserver/Xext/xf86dga.c,v 3.8 1997/01/18 06:53:01 dawes Exp $ */
+
+/*
+
+Copyright (c) 1995  Jon Tombs
+Copyright (c) 1995, 1996  XFree86 Inc
+
+*/
+
+#define NEED_REPLIES
+#define NEED_EVENTS
+#include "X.h"
+#include "Xproto.h"
+#include "misc.h"
+#include "dixstruct.h"
+#include "extnsionst.h"
+#include "colormapst.h"
+#include "cursorstr.h"
+#include "scrnintstr.h"
+#include "servermd.h"
+#define _XF86DGA_SERVER_
+#include "xf86dgastr.h"
+#include "swaprep.h"
+#include "../hw/xfree86/common/xf86.h"
+
+#include <X11/Xtrans.h>
+#include "../os/osdep.h"
+#include <X11/Xauth.h>
+#ifndef ESIX
+#ifndef Lynx
+#include <sys/socket.h>
+#else
+#include <socket.h>
+#endif
+#else
+#include <lan/socket.h>
+#endif
+
+extern int xf86ScreenIndex;
+
+static int DGAErrorBase;
+
+static DISPATCH_PROC(ProcDGAQueryVersion);
+static DISPATCH_PROC(ProcXF86DGADirectVideo);
+static DISPATCH_PROC(ProcXF86DGADispatch);
+static DISPATCH_PROC(ProcXF86DGAGetVidPage);
+static DISPATCH_PROC(ProcXF86DGAGetVideoLL);
+static DISPATCH_PROC(ProcXF86DGAGetViewPortSize);
+static DISPATCH_PROC(ProcXF86DGASetVidPage);
+static DISPATCH_PROC(ProcXF86DGASetViewPort);
+static DISPATCH_PROC(ProcDGAInstallColormap);
+static DISPATCH_PROC(ProcDGAQueryDirectVideo);
+static DISPATCH_PROC(ProcDGAViewPortChanged);
+
+/*
+ * SProcs should probably be deleted, a local connection can never
+ * be byte flipped!? - Jon.
+ */
+static DISPATCH_PROC(SProcXF86DGADirectVideo);
+static DISPATCH_PROC(SProcXF86DGADispatch);
+static DISPATCH_PROC(SProcXF86DGAQueryVersion);
+
+static void XF86DGAResetProc(
+#if NeedFunctionPrototypes
+    ExtensionEntry* /* extEntry */
+#endif
+);
+
+static unsigned char DGAReqCode = 0;
+
+void
+XFree86DGAExtensionInit()
+{
+    ExtensionEntry* extEntry;
+#ifdef XF86DGA_EVENTS
+    int                    i;
+    ScreenPtr      pScreen;
+
+    EventType = CreateNewResourceType(XF86DGAFreeEvents);
+    ScreenPrivateIndex = AllocateScreenPrivateIndex ();
+    for (i = 0; i < screenInfo.numScreens; i++)
+    {
+       pScreen = screenInfo.screens[i];
+       SetScreenPrivate (pScreen, NULL);
+    }
+#endif
+
+    if (
+#ifdef XF86DGA_EVENTS
+        EventType && ScreenPrivateIndex != -1 &&
+#endif
+       (extEntry = AddExtension(XF86DGANAME,
+                               XF86DGANumberEvents,
+                               XF86DGANumberErrors,
+                               ProcXF86DGADispatch,
+                               SProcXF86DGADispatch,
+                               XF86DGAResetProc,
+                               StandardMinorOpcode))) {
+       DGAReqCode = (unsigned char)extEntry->base;
+       DGAErrorBase = extEntry->errorBase;
+    }
+}
+
+/*ARGSUSED*/
+static void
+XF86DGAResetProc (extEntry)
+    ExtensionEntry* extEntry;
+{
+}
+
+static int
+ProcDGAQueryVersion(client)
+    register ClientPtr client;
+{
+    xXF86DGAQueryVersionReply rep;
+    register int n;
+
+    REQUEST_SIZE_MATCH(xXF86DGAQueryVersionReq);
+    rep.type = X_Reply;
+    rep.length = 0;
+    rep.sequenceNumber = client->sequence;
+    rep.majorVersion = XF86DGA_MAJOR_VERSION;
+    rep.minorVersion = XF86DGA_MINOR_VERSION;
+    if (client->swapped) {
+       swaps(&rep.sequenceNumber, n);
+       swapl(&rep.length, n);
+    }
+    WriteToClient(client, sizeof(xXF86DGAQueryVersionReply), (char *)&rep);
+    return (client->noClientException);
+}
+
+static int
+ProcXF86DGAGetVideoLL(client)
+    register ClientPtr client;
+{
+    REQUEST(xXF86DGAGetVideoLLReq);
+    xXF86DGAGetVideoLLReply rep;
+    ScrnInfoPtr vptr;
+    register int n;
+
+    if (stuff->screen > screenInfo.numScreens)
+       return BadValue;
+
+    vptr = (ScrnInfoPtr) screenInfo.screens[stuff->screen]->devPrivates[xf86ScreenIndex].ptr;
+    REQUEST_SIZE_MATCH(xXF86DGAGetVideoLLReq);
+    rep.type = X_Reply;
+    rep.length = 0;
+    rep.sequenceNumber = client->sequence;
+#if 0
+    xf86GetVidMemData(stuff->screen, &rep.offset, &rep.bank_size);
+#else
+    rep.offset = vptr->physBase;
+    rep.bank_size = vptr->physSize;
+#endif
+    rep.width = vptr->displayWidth;
+    rep.ram_size = vptr->videoRam;
+
+    if (client->swapped) {
+       swaps(&rep.sequenceNumber, n);
+       swapl(&rep.length, n);
+       swapl(&rep.offset, n);
+       swapl(&rep.width, n);
+       swapl(&rep.bank_size, n);
+       swapl(&rep.ram_size, n);
+    }
+    WriteToClient(client, SIZEOF(xXF86DGAGetVideoLLReply), (char *)&rep);
+    return (client->noClientException);
+}
+
+static int
+ProcXF86DGADirectVideo(client)
+    register ClientPtr client;
+{
+    REQUEST(xXF86DGADirectVideoReq);
+    ScrnInfoPtr vptr;
+
+    if (stuff->screen > screenInfo.numScreens)
+       return BadValue;
+
+    vptr = (ScrnInfoPtr) screenInfo.screens[stuff->screen]->devPrivates[xf86ScreenIndex].ptr;
+
+    REQUEST_SIZE_MATCH(xXF86DGADirectVideoReq);
+    if (!(vptr->directMode&XF86DGADirectPresent)) {
+       /* chipset doesn't know about directVideoMode */
+       return DGAErrorBase + XF86DGANoDirectVideoMode;
+    }
+    
+    /* Check that the current screen is active. */
+    if (!xf86VTSema && !(vptr->directMode & XF86DGADirectGraphics)) {
+       return DGAErrorBase + XF86DGAScreenNotActive;
+    }
+
+    if (stuff->enable&XF86DGADirectGraphics) {
+       vptr->directMode = stuff->enable|XF86DGADirectPresent;
+       if (xf86VTSema == TRUE) {
+         vptr->EnterLeaveVT(LEAVE, stuff->screen);
+         xf86VTSema = FALSE;
+       }
+    } else {
+       if (xf86VTSema == FALSE) {
+          xf86VTSema = TRUE;
+          vptr->EnterLeaveVT(ENTER, stuff->screen);
+       }
+       vptr->directMode = (0x0f&stuff->enable)|XF86DGADirectPresent;
+    }
+
+    return (client->noClientException);
+}
+
+static int
+ProcXF86DGAGetViewPortSize(client)
+    register ClientPtr client;
+{
+    REQUEST(xXF86DGAGetViewPortSizeReq);
+    xXF86DGAGetViewPortSizeReply rep;
+    register int n;
+    ScrnInfoPtr vptr;
+
+    if (stuff->screen > screenInfo.numScreens)
+       return BadValue;
+
+    vptr = (ScrnInfoPtr) screenInfo.screens[stuff->screen]->devPrivates[xf86ScreenIndex].ptr;
+
+    REQUEST_SIZE_MATCH(xXF86DGAGetViewPortSizeReq);
+    rep.type = X_Reply;
+    rep.length = 0;
+    rep.sequenceNumber = client->sequence;
+    rep.width = vptr->modes->HDisplay;
+    rep.height = vptr->modes->VDisplay;
+
+    if (client->swapped) {
+       swaps(&rep.sequenceNumber, n);
+       swapl(&rep.length, n);
+       swapl(&rep.width, n);
+       swapl(&rep.height, n);
+    }
+    WriteToClient(client, SIZEOF(xXF86DGAGetViewPortSizeReply), (char *)&rep);
+    return (client->noClientException);
+}
+
+static int
+ProcXF86DGASetViewPort(client)
+    register ClientPtr client;
+{
+    REQUEST(xXF86DGASetViewPortReq);
+    ScrnInfoPtr vptr;
+
+    if (stuff->screen > screenInfo.numScreens)
+       return BadValue;
+
+    vptr = (ScrnInfoPtr) screenInfo.screens[stuff->screen]->devPrivates[xf86ScreenIndex].ptr;
+
+    REQUEST_SIZE_MATCH(xXF86DGASetViewPortReq);
+
+    if (vptr->AdjustFrame &&
+       (xf86VTSema == TRUE || vptr->directMode&XF86DGADirectGraphics))
+       vptr->AdjustFrame(stuff->x, stuff->y);
+    else
+       return DGAErrorBase + XF86DGAScreenNotActive;
+
+    return (client->noClientException);
+}
+
+static int
+ProcXF86DGAGetVidPage(client)
+    register ClientPtr client;
+{
+    REQUEST(xXF86DGAGetVidPageReq);
+    ScrnInfoPtr vptr;
+
+    if (stuff->screen > screenInfo.numScreens)
+       return BadValue;
+
+    vptr = (ScrnInfoPtr) screenInfo.screens[stuff->screen]->devPrivates[xf86ScreenIndex].ptr;
+    ErrorF("XF86DGAGetVidPage not yet implemented\n");
+
+    REQUEST_SIZE_MATCH(xXF86DGAGetVidPageReq);
+    return (client->noClientException);
+}
+
+
+static int
+ProcXF86DGASetVidPage(client)
+    register ClientPtr client;
+{
+    REQUEST(xXF86DGASetVidPageReq);
+    ScrnInfoPtr vptr;
+
+    if (stuff->screen > screenInfo.numScreens)
+       return BadValue;
+
+    vptr = (ScrnInfoPtr) screenInfo.screens[stuff->screen]->devPrivates[xf86ScreenIndex].ptr;
+
+    REQUEST_SIZE_MATCH(xXF86DGASetVidPageReq);
+
+    if (xf86VTSema == TRUE) {/* only valid when switched away! */
+       return DGAErrorBase + XF86DGADirectNotActivated;
+    }
+    if (!xf86VTSema && !(vptr->directMode & XF86DGADirectGraphics)) {
+       return DGAErrorBase + XF86DGAScreenNotActive;
+    }
+
+    if (vptr->setBank) {
+       vptr->setBank(stuff->vpage);
+    }
+    return (client->noClientException);
+}
+
+
+static int
+ProcDGAInstallColormap(client)
+    register ClientPtr client;
+{
+    ColormapPtr pcmp;
+    ScrnInfoPtr vptr;
+    REQUEST(xXF86DGAInstallColormapReq);
+
+    REQUEST_SIZE_MATCH(xXF86DGAInstallColormapReq);
+
+    vptr = (ScrnInfoPtr) screenInfo.screens[stuff->screen]->devPrivates[xf86ScreenIndex].ptr;
+
+    if (xf86VTSema == TRUE) {/* only valid when switched away! */
+       return DGAErrorBase + XF86DGADirectNotActivated;
+    }
+    if (!xf86VTSema && !(vptr->directMode & XF86DGADirectGraphics)) {
+       return DGAErrorBase + XF86DGAScreenNotActive;
+    }
+
+    pcmp = (ColormapPtr  )LookupIDByType(stuff->id, RT_COLORMAP);
+    if (pcmp)
+    {
+       vptr->directMode |= XF86DGADirectColormap;
+        vptr->directMode |= XF86DGAHasColormap;
+        (*(pcmp->pScreen->InstallColormap)) (pcmp);
+        vptr->directMode &= ~XF86DGAHasColormap;
+        return (client->noClientException);
+    }
+    else
+    {
+        client->errorValue = stuff->id;
+        return (BadColor);
+    }
+}
+
+static int
+ProcXF86DGAQueryDirectVideo(client)
+    register ClientPtr client;
+{
+    REQUEST(xXF86DGAQueryDirectVideoReq);
+    xXF86DGAQueryDirectVideoReply rep;
+    register int n;
+    ScrnInfoPtr vptr;
+
+    if (stuff->screen > screenInfo.numScreens)
+       return BadValue;
+
+    vptr = (ScrnInfoPtr) screenInfo.screens[stuff->screen]->devPrivates[xf86ScreenIndex].ptr;
+
+    REQUEST_SIZE_MATCH(xXF86DGAQueryDirectVideoReq);
+    rep.type = X_Reply;
+    rep.length = 0;
+    rep.sequenceNumber = client->sequence;
+    rep.flags = vptr->directMode;
+
+    if (client->swapped) {
+       swaps(&rep.sequenceNumber, n);
+       swapl(&rep.length, n);
+       swapl(&rep.flags, n);
+    }
+    WriteToClient(client, SIZEOF(xXF86DGAQueryDirectVideoReply), (char *)&rep);
+    return (client->noClientException);
+}
+
+static int
+ProcXF86DGAViewPortChanged(client)
+    register ClientPtr client;
+{
+    REQUEST(xXF86DGAViewPortChangedReq);
+    xXF86DGAViewPortChangedReply rep;
+    register int n;
+    ScrnInfoPtr vptr;
+
+    if (stuff->screen > screenInfo.numScreens)
+       return BadValue;
+
+    vptr = (ScrnInfoPtr) screenInfo.screens[stuff->screen]->devPrivates[xf86ScreenIndex].ptr;
+
+    REQUEST_SIZE_MATCH(xXF86DGAViewPortChangedReq);
+    rep.type = X_Reply;
+    rep.length = 0;
+    rep.sequenceNumber = client->sequence;
+    /* For the moment, always return TRUE. */
+    rep.result = TRUE;
+
+    if (client->swapped) {
+       swaps(&rep.sequenceNumber, n);
+       swapl(&rep.length, n);
+       swapl(&rep.result, n);
+    }
+    WriteToClient(client, SIZEOF(xXF86DGAViewPortChangedReply), (char *)&rep);
+    return (client->noClientException);
+}
+
+static int
+ProcXF86DGADispatch (client)
+    register ClientPtr client;
+{
+    REQUEST(xReq);
+
+    if (!LocalClient(client))
+       return DGAErrorBase + XF86DGAClientNotLocal;
+
+    switch (stuff->data)
+    {
+    case X_XF86DGAQueryVersion:
+       return ProcDGAQueryVersion(client);
+    case X_XF86DGAGetVideoLL:
+       return ProcXF86DGAGetVideoLL(client);
+    case X_XF86DGADirectVideo:
+       return ProcXF86DGADirectVideo(client);
+    case X_XF86DGAGetViewPortSize:
+       return ProcXF86DGAGetViewPortSize(client);
+    case X_XF86DGASetViewPort:
+       return ProcXF86DGASetViewPort(client);
+    case X_XF86DGAGetVidPage:
+       return ProcXF86DGAGetVidPage(client);
+    case X_XF86DGASetVidPage:
+       return ProcXF86DGASetVidPage(client);
+    case X_XF86DGAInstallColormap:
+       return ProcDGAInstallColormap(client);
+    case X_XF86DGAQueryDirectVideo:
+       return ProcXF86DGAQueryDirectVideo(client);
+    case X_XF86DGAViewPortChanged:
+       return ProcXF86DGAViewPortChanged(client);
+    default:
+       return BadRequest;
+    }
+}
+
+static int
+SProcXF86DGAQueryVersion(client)
+    register ClientPtr client;
+{
+    register int n;
+    REQUEST(xXF86DGAQueryVersionReq);
+    swaps(&stuff->length, n);
+    return ProcDGAQueryVersion(client);
+}
+
+static int
+SProcXF86DGADirectVideo(client)
+    ClientPtr client;
+{
+    register int n;
+    REQUEST(xXF86DGADirectVideoReq);
+    swaps(&stuff->length, n);
+    REQUEST_SIZE_MATCH(xXF86DGADirectVideoReq);
+    swaps(&stuff->screen, n);
+    swaps(&stuff->enable, n);
+    return ProcXF86DGADirectVideo(client);
+}
+
+static int
+SProcXF86DGADispatch (client)
+    register ClientPtr client;
+{
+    REQUEST(xReq);
+
+    /* It is bound to be non-local when there is byte swapping */
+    if (!LocalClient(client))
+       return DGAErrorBase + XF86DGAClientNotLocal;
+
+    switch (stuff->data)
+    {
+    case X_XF86DGAQueryVersion:
+       return SProcXF86DGAQueryVersion(client);
+    case X_XF86DGADirectVideo:
+       return SProcXF86DGADirectVideo(client);
+    default:
+       return BadRequest;
+    }
+}
+
diff --git a/Xserver/programs/Xserver/Xext/xf86misc.c b/Xserver/programs/Xserver/Xext/xf86misc.c
new file mode 100644 (file)
index 0000000..dd30994
--- /dev/null
@@ -0,0 +1,632 @@
+/* $XFree86: xc/programs/Xserver/Xext/xf86misc.c,v 3.21.2.4 1998/02/25 14:26:43 dawes Exp $ */
+
+/*
+ * Copyright (c) 1995, 1996  The XFree86 Project, Inc
+ */
+
+/* THIS IS NOT AN X CONSORTIUM STANDARD */
+
+#define NEED_REPLIES
+#define NEED_EVENTS
+#include "X.h"
+#include "Xproto.h"
+#include "misc.h"
+#include "dixstruct.h"
+#include "extnsionst.h"
+#include "scrnintstr.h"
+#include "inputstr.h"
+#include "servermd.h"
+#define _XF86MISC_SERVER_
+#define _XF86MISC_SAVER_COMPAT_
+#include "xf86mscstr.h"
+#include "Xfuncproto.h"
+#include "xf86.h"
+#include "xf86Priv.h"
+#include "xf86_OSlib.h"
+
+#include <X11/Xtrans.h>
+#include "../os/osdep.h"
+#include <X11/Xauth.h>
+#ifndef ESIX
+#ifndef Lynx
+#include <sys/socket.h>
+#else
+#include <socket.h>
+#endif
+#else
+#include <lan/socket.h>
+#endif
+
+#include "swaprep.h"
+
+extern int xf86ScreenIndex;
+extern Bool xf86MiscModInDevEnabled;
+extern Bool xf86MiscModInDevAllowNonLocal;
+
+static int miscErrorBase;
+
+static void XF86MiscResetProc(
+#if NeedFunctionPrototypes
+    ExtensionEntry* /* extEntry */
+#endif
+);
+
+static DISPATCH_PROC(ProcXF86MiscDispatch);
+static DISPATCH_PROC(ProcXF86MiscGetKbdSettings);
+static DISPATCH_PROC(ProcXF86MiscGetMouseSettings);
+static DISPATCH_PROC(ProcXF86MiscGetSaver);
+static DISPATCH_PROC(ProcXF86MiscQueryVersion);
+static DISPATCH_PROC(ProcXF86MiscSetKbdSettings);
+static DISPATCH_PROC(ProcXF86MiscSetMouseSettings);
+static DISPATCH_PROC(ProcXF86MiscSetSaver);
+static DISPATCH_PROC(SProcXF86MiscDispatch);
+static DISPATCH_PROC(SProcXF86MiscGetKbdSettings);
+static DISPATCH_PROC(SProcXF86MiscGetMouseSettings);
+static DISPATCH_PROC(SProcXF86MiscGetSaver);
+static DISPATCH_PROC(SProcXF86MiscQueryVersion);
+static DISPATCH_PROC(SProcXF86MiscSetKbdSettings);
+static DISPATCH_PROC(SProcXF86MiscSetMouseSettings);
+static DISPATCH_PROC(SProcXF86MiscSetSaver);
+
+static unsigned char XF86MiscReqCode = 0;
+
+extern InputInfo inputInfo;
+
+void
+XFree86MiscExtensionInit()
+{
+    ExtensionEntry* extEntry;
+
+    if (
+       (extEntry = AddExtension(XF86MISCNAME,
+                               XF86MiscNumberEvents,
+                               XF86MiscNumberErrors,
+                               ProcXF86MiscDispatch,
+                               SProcXF86MiscDispatch,
+                               XF86MiscResetProc,
+                               StandardMinorOpcode))) {
+       XF86MiscReqCode = (unsigned char)extEntry->base;
+       miscErrorBase = extEntry->errorBase;
+    }
+}
+
+/*ARGSUSED*/
+static void
+XF86MiscResetProc (extEntry)
+    ExtensionEntry* extEntry;
+{
+}
+
+static int
+ProcXF86MiscQueryVersion(client)
+    register ClientPtr client;
+{
+    xXF86MiscQueryVersionReply rep;
+    register int n;
+
+    REQUEST_SIZE_MATCH(xXF86MiscQueryVersionReq);
+    rep.type = X_Reply;
+    rep.length = 0;
+    rep.sequenceNumber = client->sequence;
+    rep.majorVersion = XF86MISC_MAJOR_VERSION;
+    rep.minorVersion = XF86MISC_MINOR_VERSION;
+    if (client->swapped) {
+       swaps(&rep.sequenceNumber, n);
+       swapl(&rep.length, n);
+       swaps(&rep.majorVersion, n);
+       swaps(&rep.minorVersion, n);
+    }
+    WriteToClient(client, sizeof(xXF86MiscQueryVersionReply), (char *)&rep);
+    return (client->noClientException);
+}
+
+/*
+ * This will go away, but remains for now for compatibility with older
+ * clients.
+ */
+static int
+ProcXF86MiscSetSaver(client)
+    register ClientPtr client;
+{
+    REQUEST(xXF86MiscSetSaverReq);
+    ScrnInfoPtr vptr;
+
+    if (stuff->screen > screenInfo.numScreens)
+       return BadValue;
+
+    vptr = (ScrnInfoPtr) screenInfo.screens[stuff->screen]->devPrivates[xf86ScreenIndex].ptr;
+
+    REQUEST_SIZE_MATCH(xXF86MiscSetSaverReq);
+
+    if (stuff->suspendTime < 0)
+       return BadValue;
+    if (stuff->offTime < 0)
+       return BadValue;
+
+    return (client->noClientException);
+}
+
+/*
+ * This will go away, but remains for now for compatibility with older
+ * clients.
+ */
+static int
+ProcXF86MiscGetSaver(client)
+    register ClientPtr client;
+{
+    REQUEST(xXF86MiscGetSaverReq);
+    xXF86MiscGetSaverReply rep;
+    register int n;
+    ScrnInfoPtr vptr;
+
+    if (stuff->screen > screenInfo.numScreens)
+       return BadValue;
+
+    vptr = (ScrnInfoPtr) screenInfo.screens[stuff->screen]->devPrivates[xf86ScreenIndex].ptr;
+
+    REQUEST_SIZE_MATCH(xXF86MiscGetSaverReq);
+    rep.type = X_Reply;
+    rep.length = 0;
+    rep.sequenceNumber = client->sequence;
+    rep.suspendTime = 0;
+    rep.offTime = 0;
+    
+    if (client->swapped) {
+       swaps(&rep.sequenceNumber, n);
+       swapl(&rep.length, n);
+       swapl(&rep.suspendTime, n);
+       swapl(&rep.offTime, n);
+    }
+    WriteToClient(client, SIZEOF(xXF86MiscGetSaverReply), (char *)&rep);
+    return (client->noClientException);
+}
+
+static int
+ProcXF86MiscGetMouseSettings(client)
+    register ClientPtr client;
+{
+    xXF86MiscGetMouseSettingsReply rep;
+    register int n;
+
+    REQUEST_SIZE_MATCH(xXF86MiscGetMouseSettingsReq);
+    rep.type = X_Reply;
+    rep.sequenceNumber = client->sequence;
+    rep.mousetype = xf86Info.mouseDev->mseType;
+#ifdef XQUEUE
+    if (xf86Info.mouseDev->mseProc == xf86XqueMseProc)
+        rep.mousetype = MTYPE_XQUEUE;
+#endif
+#if defined(USE_OSMOUSE) || defined(OSMOUSE_ONLY)
+    if (xf86Info.mouseDev->mseProc == xf86OsMouseProc)
+        rep.mousetype = MTYPE_OSMOUSE;
+#endif
+    rep.baudrate = xf86Info.mouseDev->baudRate;
+    rep.samplerate = xf86Info.mouseDev->sampleRate;
+    rep.resolution = xf86Info.mouseDev->resolution;
+    rep.buttons = xf86Info.mouseDev->buttons;
+    rep.emulate3buttons = xf86Info.mouseDev->emulate3Buttons;
+    rep.emulate3timeout = xf86Info.mouseDev->emulate3Timeout;
+    rep.chordmiddle = xf86Info.mouseDev->chordMiddle;
+    rep.flags = xf86Info.mouseDev->mouseFlags;
+    if (xf86Info.mouseDev->mseDevice)
+        rep.devnamelen = strlen(xf86Info.mouseDev->mseDevice);
+    else
+        rep.devnamelen = 0;
+    rep.length = (sizeof(xXF86MiscGetMouseSettingsReply) -
+                 sizeof(xGenericReply) + ((rep.devnamelen+3) & ~3)) >> 2;
+    
+    if (client->swapped) {
+       swaps(&rep.sequenceNumber, n);
+       swapl(&rep.length, n);
+       swapl(&rep.mousetype, n);
+       swapl(&rep.baudrate, n);
+       swapl(&rep.samplerate, n);
+       swapl(&rep.resolution, n);
+       swapl(&rep.buttons, n);
+       swapl(&rep.emulate3buttons, n);
+       swapl(&rep.emulate3timeout, n);
+       swapl(&rep.chordmiddle, n);
+       swapl(&rep.flags, n);
+    }
+    WriteToClient(client, SIZEOF(xXF86MiscGetMouseSettingsReply), (char *)&rep);
+    if (rep.devnamelen)
+        WriteToClient(client, rep.devnamelen, xf86Info.mouseDev->mseDevice);
+    return (client->noClientException);
+}
+
+static int
+ProcXF86MiscGetKbdSettings(client)
+    register ClientPtr client;
+{
+    xXF86MiscGetKbdSettingsReply rep;
+    register int n;
+
+    REQUEST_SIZE_MATCH(xXF86MiscGetKbdSettingsReq);
+    rep.type = X_Reply;
+    rep.length = 0;
+    rep.sequenceNumber = client->sequence;
+    rep.kbdtype = xf86Info.kbdType;
+#ifdef XQUEUE
+    if (xf86Info.kbdProc == xf86XqueKbdProc)
+        rep.kbdtype = KTYPE_XQUEUE;
+#endif
+    rep.rate = xf86Info.kbdRate;
+    rep.delay = xf86Info.kbdDelay;
+    rep.servnumlock = xf86Info.serverNumLock;
+    if (client->swapped) {
+       swaps(&rep.sequenceNumber, n);
+       swapl(&rep.length, n);
+       swapl(&rep.kbdtype, n);
+       swapl(&rep.rate, n);
+       swapl(&rep.delay, n);
+    }
+    WriteToClient(client, SIZEOF(xXF86MiscGetKbdSettingsReply), (char *)&rep);
+    return (client->noClientException);
+}
+
+static int
+ProcXF86MiscSetMouseSettings(client)
+    register ClientPtr client;
+{
+    int reopen, msetype, flags, baudrate, samplerate, resolution;
+
+    REQUEST(xXF86MiscSetMouseSettingsReq);
+
+    REQUEST_SIZE_MATCH(xXF86MiscSetMouseSettingsReq);
+
+    if (xf86Verbose) {
+       ErrorF("SetMouseSettings - type: %d brate: %d srate: %d chdmid: %d\n",
+               stuff->mousetype, stuff->baudrate,
+               stuff->samplerate, stuff->chordmiddle);
+       ErrorF("                   em3but: %d em3tim: %d res: %d flags: %d\n",
+               stuff->emulate3buttons, stuff->emulate3timeout,
+               stuff->resolution, stuff->flags);
+    }
+    if (stuff->mousetype > MTYPE_OSMOUSE
+            || stuff->mousetype < MTYPE_MICROSOFT)
+       return miscErrorBase + XF86MiscBadMouseProtocol;
+#ifdef OSMOUSE_ONLY
+    if (stuff->mousetype != MTYPE_OSMOUSE)
+       return miscErrorBase + XF86MiscBadMouseProtocol;
+#else
+#ifndef XQUEUE
+    if (stuff->mousetype == MTYPE_XQUEUE)
+       return miscErrorBase + XF86MiscBadMouseProtocol;
+#endif
+#ifndef USE_OSMOUSE
+    if (stuff->mousetype == MTYPE_OSMOUSE)
+       return miscErrorBase + XF86MiscBadMouseProtocol;
+#endif
+#endif /* OSMOUSE_ONLY */
+
+    if (stuff->emulate3timeout < 0)
+       return BadValue;
+
+    if (stuff->mousetype == MTYPE_LOGIMAN
+            && !(stuff->baudrate == 1200 || stuff->baudrate == 9600) )
+       return miscErrorBase + XF86MiscBadMouseBaudRate;
+    if (stuff->mousetype == MTYPE_LOGIMAN && stuff->samplerate)
+       return miscErrorBase + XF86MiscBadMouseCombo;
+
+    samplerate = xf86Info.mouseDev->sampleRate;
+    resolution = xf86Info.mouseDev->resolution;
+    baudrate   = xf86Info.mouseDev->baudRate;
+    flags      = xf86Info.mouseDev->mouseFlags;
+    msetype    = xf86Info.mouseDev->mseType;
+#ifdef XQUEUE
+    if (xf86Info.mouseDev->mseProc == xf86XqueMseProc)
+        msetype = MTYPE_XQUEUE;
+#endif
+#if defined(USE_OSMOUSE) || defined(OSMOUSE_ONLY)
+    if (xf86Info.mouseDev->mseProc == xf86OsMouseProc)
+        msetype = MTYPE_OSMOUSE;
+#endif
+
+    reopen     = 0;
+
+    if (stuff->mousetype != msetype)
+       if (stuff->mousetype == MTYPE_XQUEUE
+               || stuff->mousetype == MTYPE_OSMOUSE
+               || msetype == MTYPE_XQUEUE
+               || msetype == MTYPE_OSMOUSE)
+           return miscErrorBase + XF86MiscBadMouseProtocol;
+       else {
+           reopen++;
+           msetype = stuff->mousetype;
+       }
+
+    if (stuff->flags & MF_REOPEN) {
+       reopen++;
+       stuff->flags &= ~MF_REOPEN;
+    }
+    if (stuff->mousetype != MTYPE_OSMOUSE
+           && stuff->mousetype != MTYPE_XQUEUE
+           && stuff->mousetype != MTYPE_PS_2
+           && stuff->mousetype != MTYPE_BUSMOUSE
+           && stuff->mousetype != MTYPE_IMPS2
+           && stuff->mousetype != MTYPE_THINKINGPS2
+           && stuff->mousetype != MTYPE_MMANPLUSPS2
+           && stuff->mousetype != MTYPE_GLIDEPOINTPS2
+           && stuff->mousetype != MTYPE_NETPS2
+           && stuff->mousetype != MTYPE_NETSCROLLPS2
+           && stuff->mousetype != MTYPE_SYSMOUSE)
+    {
+        if (stuff->baudrate < 1200)
+           return miscErrorBase + XF86MiscBadMouseBaudRate;
+        if (stuff->baudrate % 1200 != 0
+                || stuff->baudrate < 1200 || stuff->baudrate > 9600)
+           return miscErrorBase + XF86MiscBadMouseBaudRate;
+       if (xf86Info.mouseDev->baudRate != stuff->baudrate) {
+               reopen++;
+               baudrate = stuff->baudrate;
+       }
+    }
+    if (stuff->flags & (MF_CLEAR_DTR|MF_CLEAR_RTS))
+       if (stuff->mousetype != MTYPE_MOUSESYS)
+           return miscErrorBase + XF86MiscBadMouseFlags;
+       else if (xf86Info.mouseDev->mouseFlags != stuff->flags) {
+           reopen++;
+            flags = stuff->flags;
+       }
+
+    if (stuff->mousetype != MTYPE_OSMOUSE
+           && stuff->mousetype != MTYPE_XQUEUE
+           && stuff->mousetype != MTYPE_BUSMOUSE)
+    {
+        if (stuff->samplerate < 0)
+           return BadValue;
+       
+       if (xf86Info.mouseDev->sampleRate != stuff->samplerate) {
+               reopen++;
+               samplerate = stuff->samplerate;
+       }
+    }
+
+    if (stuff->resolution < 0)
+       return BadValue;
+    if (xf86Info.mouseDev->resolution != stuff->resolution) {
+       reopen++;
+       resolution = stuff->resolution;
+    }
+
+#if 0
+    /* Ignore the buttons field */
+    if (xf86Info.mouseDev->buttons != stuff->buttons)
+       /* we cannot change this field on the fly... */
+       return BadValue;
+#endif
+
+    if (stuff->chordmiddle)
+        if (stuff->emulate3buttons
+               || !(stuff->mousetype == MTYPE_MICROSOFT
+                    || stuff->mousetype == MTYPE_LOGIMAN) )
+           return miscErrorBase + XF86MiscBadMouseCombo;
+
+    xf86Info.mouseDev->chordMiddle = stuff->chordmiddle!=0;
+    xf86Info.mouseDev->emulate3Buttons = stuff->emulate3buttons!=0;
+    xf86Info.mouseDev->emulate3Timeout = stuff->emulate3timeout;
+
+    if (reopen && msetype != MTYPE_OSMOUSE && msetype != MTYPE_XQUEUE) {
+
+        (xf86Info.mouseDev->mseProc)(xf86Info.pMouse, DEVICE_CLOSE);
+
+        xf86Info.mouseDev->mseType    = msetype;
+        xf86Info.mouseDev->mouseFlags = flags;
+        xf86Info.mouseDev->baudRate   = baudrate;
+        xf86Info.mouseDev->sampleRate = samplerate;
+       xf86Info.mouseDev->resolution = resolution;
+
+       xf86Info.pMouse->public.on = FALSE;
+       xf86AllowMouseOpenFail = TRUE;
+       xf86MouseInit(xf86Info.mouseDev);
+        (xf86Info.mouseDev->mseProc)(xf86Info.pMouse, DEVICE_ON);
+    }
+
+    if (xf86Verbose)
+       ErrorF("SetMouseSettings - Succeeded\n");
+    return (client->noClientException);
+}
+
+static int
+ProcXF86MiscSetKbdSettings(client)
+    register ClientPtr client;
+{
+    REQUEST(xXF86MiscSetKbdSettingsReq);
+
+    REQUEST_SIZE_MATCH(xXF86MiscSetKbdSettingsReq);
+
+    if (xf86Verbose)
+       ErrorF("SetKbdSettings - type: %d rate: %d delay: %d snumlk: %d\n",
+               stuff->kbdtype, stuff->rate,
+               stuff->delay, stuff->servnumlock);
+    if (stuff->rate < 0)
+       return BadValue;
+    if (stuff->delay < 0)
+       return BadValue;
+    if (stuff->kbdtype < KTYPE_UNKNOWN || stuff->kbdtype > KTYPE_XQUEUE)
+       return miscErrorBase + XF86MiscBadKbdType;
+
+    if (xf86Info.kbdRate!=stuff->rate || xf86Info.kbdDelay!=stuff->delay) {
+       char rad;
+
+       xf86Info.kbdRate = stuff->rate;
+       xf86Info.kbdDelay = stuff->delay;
+        if      (xf86Info.kbdDelay <= 375) rad = 0x00;
+        else if (xf86Info.kbdDelay <= 625) rad = 0x20;
+        else if (xf86Info.kbdDelay <= 875) rad = 0x40;
+        else                               rad = 0x60;
+    
+        if      (xf86Info.kbdRate <=  2)   rad |= 0x1F;
+        else if (xf86Info.kbdRate >= 30)   rad |= 0x00;
+        else                               rad |= ((58/xf86Info.kbdRate)-2);
+    
+        xf86SetKbdRepeat(rad);
+    }
+#if 0  /* Not done yet */
+    xf86Info.kbdType = stuff->kbdtype;
+    xf86Info.serverNumLock = stuff->servnumlock!=0;
+#endif
+
+    if (xf86Verbose)
+       ErrorF("SetKbdSettings - Succeeded\n");
+    return (client->noClientException);
+}
+
+static int
+ProcXF86MiscDispatch (client)
+    register ClientPtr client;
+{
+    REQUEST(xReq);
+    switch (stuff->data)
+    {
+    case X_XF86MiscQueryVersion:
+       return ProcXF86MiscQueryVersion(client);
+    case X_XF86MiscGetSaver:
+       return ProcXF86MiscGetSaver(client);
+    case X_XF86MiscSetSaver:
+       return ProcXF86MiscSetSaver(client);
+    case X_XF86MiscGetMouseSettings:
+       return ProcXF86MiscGetMouseSettings(client);
+    case X_XF86MiscGetKbdSettings:
+       return ProcXF86MiscGetKbdSettings(client);
+    default:
+       if (!xf86MiscModInDevEnabled)
+           return miscErrorBase + XF86MiscModInDevDisabled;
+       if (xf86MiscModInDevAllowNonLocal || LocalClient (client)) {
+           switch (stuff->data) {
+               case X_XF86MiscSetMouseSettings:
+                   return ProcXF86MiscSetMouseSettings(client);
+               case X_XF86MiscSetKbdSettings:
+                   return ProcXF86MiscSetKbdSettings(client);
+               default:
+                   return BadRequest;
+           }
+       } else
+           return miscErrorBase + XF86MiscModInDevClientNotLocal;
+    }
+}
+
+static int
+SProcXF86MiscQueryVersion(client)
+    register ClientPtr client;
+{
+    register int n;
+    REQUEST(xXF86MiscQueryVersionReq);
+    swaps(&stuff->length, n);
+    return ProcXF86MiscQueryVersion(client);
+}
+
+static int
+SProcXF86MiscGetSaver(client)
+    ClientPtr client;
+{
+    register int n;
+    REQUEST(xXF86MiscGetSaverReq);
+    swaps(&stuff->length, n);
+    REQUEST_SIZE_MATCH(xXF86MiscGetSaverReq);
+    swaps(&stuff->screen, n);
+    return ProcXF86MiscGetSaver(client);
+}
+
+static int
+SProcXF86MiscSetSaver(client)
+    ClientPtr client;
+{
+    register int n;
+    REQUEST(xXF86MiscSetSaverReq);
+    swaps(&stuff->length, n);
+    REQUEST_SIZE_MATCH(xXF86MiscSetSaverReq);
+    swaps(&stuff->screen, n);
+    swapl(&stuff->suspendTime, n);
+    swapl(&stuff->offTime, n);
+    return ProcXF86MiscSetSaver(client);
+}
+
+static int
+SProcXF86MiscGetMouseSettings(client)
+    ClientPtr client;
+{
+    register int n;
+    REQUEST(xXF86MiscGetMouseSettingsReq);
+    swaps(&stuff->length, n);
+    REQUEST_SIZE_MATCH(xXF86MiscGetMouseSettingsReq);
+    return ProcXF86MiscGetMouseSettings(client);
+}
+
+static int
+SProcXF86MiscGetKbdSettings(client)
+    ClientPtr client;
+{
+    register int n;
+    REQUEST(xXF86MiscGetKbdSettingsReq);
+    swaps(&stuff->length, n);
+    REQUEST_SIZE_MATCH(xXF86MiscGetKbdSettingsReq);
+    return ProcXF86MiscGetKbdSettings(client);
+}
+
+static int
+SProcXF86MiscSetMouseSettings(client)
+    ClientPtr client;
+{
+    register int n;
+    REQUEST(xXF86MiscSetMouseSettingsReq);
+    swaps(&stuff->length, n);
+    REQUEST_SIZE_MATCH(xXF86MiscSetMouseSettingsReq);
+    swapl(&stuff->mousetype, n);
+    swapl(&stuff->baudrate, n);
+    swapl(&stuff->samplerate, n);
+    swapl(&stuff->resolution, n);
+    swapl(&stuff->buttons, n);
+    swapl(&stuff->emulate3timeout, n);
+    swapl(&stuff->flags, n);
+    return ProcXF86MiscSetMouseSettings(client);
+}
+
+static int
+SProcXF86MiscSetKbdSettings(client)
+    ClientPtr client;
+{
+    register int n;
+    REQUEST(xXF86MiscSetKbdSettingsReq);
+    swaps(&stuff->length, n);
+    REQUEST_SIZE_MATCH(xXF86MiscSetKbdSettingsReq);
+    swapl(&stuff->kbdtype, n);
+    swapl(&stuff->rate, n);
+    swapl(&stuff->delay, n);
+    return ProcXF86MiscSetKbdSettings(client);
+}
+
+static int
+SProcXF86MiscDispatch (client)
+    register ClientPtr client;
+{
+    REQUEST(xReq);
+    switch (stuff->data)
+    {
+    case X_XF86MiscQueryVersion:
+       return SProcXF86MiscQueryVersion(client);
+    case X_XF86MiscGetSaver:
+       return SProcXF86MiscGetSaver(client);
+    case X_XF86MiscSetSaver:
+       return SProcXF86MiscSetSaver(client);
+    case X_XF86MiscGetMouseSettings:
+       return SProcXF86MiscGetMouseSettings(client);
+    case X_XF86MiscGetKbdSettings:
+       return SProcXF86MiscGetKbdSettings(client);
+    default:
+       if (!xf86MiscModInDevEnabled)
+           return miscErrorBase + XF86MiscModInDevDisabled;
+       if (xf86MiscModInDevAllowNonLocal || LocalClient (client)) {
+           switch (stuff->data) {
+               case X_XF86MiscSetMouseSettings:
+                   return SProcXF86MiscSetMouseSettings(client);
+               case X_XF86MiscSetKbdSettings:
+                   return SProcXF86MiscSetKbdSettings(client);
+               default:
+                   return BadRequest;
+           }
+       } else
+           return miscErrorBase + XF86MiscModInDevClientNotLocal;
+    }
+}
+
diff --git a/Xserver/programs/Xserver/Xext/xf86vmode.c b/Xserver/programs/Xserver/Xext/xf86vmode.c
new file mode 100644 (file)
index 0000000..874a5cb
--- /dev/null
@@ -0,0 +1,1615 @@
+/* $XFree86: xc/programs/Xserver/Xext/xf86vmode.c,v 3.30.2.3 1997/06/11 12:08:44 dawes Exp $ */
+
+/*
+
+Copyright (c) 1995  Kaleb S. KEITHLEY
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL Kaleb S. KEITHLEY BE LIABLE FOR ANY CLAIM, DAMAGES 
+OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of Kaleb S. KEITHLEY 
+shall not be used in advertising or otherwise to promote the sale, use 
+or other dealings in this Software without prior written authorization
+from Kaleb S. KEITHLEY
+
+*/
+/* $XConsortium: xf86vmode.c /main/24 1996/10/26 21:56:29 kaleb $ */
+/* THIS IS NOT AN X CONSORTIUM STANDARD */
+
+#define NEED_REPLIES
+#define NEED_EVENTS
+#include "X.h"
+#include "Xproto.h"
+#include "misc.h"
+#include "dixstruct.h"
+#include "extnsionst.h"
+#include "scrnintstr.h"
+#include "servermd.h"
+#define _XF86VIDMODE_SERVER_
+#include "xf86vmstr.h"
+#include "Xfuncproto.h"
+#include "../hw/xfree86/common/xf86.h"
+#include "../hw/xfree86/common/xf86Priv.h"
+
+#include <X11/Xtrans.h>
+#include "../os/osdep.h"
+#include <X11/Xauth.h>
+#ifndef ESIX
+#ifndef Lynx
+#include <sys/socket.h>
+#else
+#include <socket.h>
+#endif
+#else
+#include <lan/socket.h>
+#endif
+
+#include "swaprep.h"
+
+extern int xf86ScreenIndex;
+extern Bool xf86VidModeEnabled;
+extern Bool xf86VidModeAllowNonLocal;
+
+static int vidmodeErrorBase;
+
+static void XF86VidModeResetProc(
+#if NeedFunctionPrototypes
+    ExtensionEntry* /* extEntry */
+#endif
+);
+
+static DISPATCH_PROC(ProcXF86VidModeDispatch);
+static DISPATCH_PROC(ProcXF86VidModeGetAllModeLines);
+static DISPATCH_PROC(ProcXF86VidModeGetModeLine);
+static DISPATCH_PROC(ProcXF86VidModeGetMonitor);
+static DISPATCH_PROC(ProcXF86VidModeLockModeSwitch);
+static DISPATCH_PROC(ProcXF86VidModeAddModeLine);
+static DISPATCH_PROC(ProcXF86VidModeDeleteModeLine);
+static DISPATCH_PROC(ProcXF86VidModeModModeLine);
+static DISPATCH_PROC(ProcXF86VidModeValidateModeLine);
+static DISPATCH_PROC(ProcXF86VidModeQueryVersion);
+static DISPATCH_PROC(ProcXF86VidModeSwitchMode);
+static DISPATCH_PROC(ProcXF86VidModeSwitchToMode);
+static DISPATCH_PROC(ProcXF86VidModeGetViewPort);
+static DISPATCH_PROC(ProcXF86VidModeSetViewPort);
+static DISPATCH_PROC(SProcXF86VidModeDispatch);
+static DISPATCH_PROC(SProcXF86VidModeGetAllModeLines);
+static DISPATCH_PROC(SProcXF86VidModeGetModeLine);
+static DISPATCH_PROC(SProcXF86VidModeGetMonitor);
+static DISPATCH_PROC(SProcXF86VidModeLockModeSwitch);
+static DISPATCH_PROC(SProcXF86VidModeAddModeLine);
+static DISPATCH_PROC(SProcXF86VidModeDeleteModeLine);
+static DISPATCH_PROC(SProcXF86VidModeModModeLine);
+static DISPATCH_PROC(SProcXF86VidModeValidateModeLine);
+static DISPATCH_PROC(SProcXF86VidModeQueryVersion);
+static DISPATCH_PROC(SProcXF86VidModeSwitchMode);
+static DISPATCH_PROC(SProcXF86VidModeSwitchToMode);
+static DISPATCH_PROC(SProcXF86VidModeGetViewPort);
+static DISPATCH_PROC(SProcXF86VidModeSetViewPort);
+
+static unsigned char XF86VidModeReqCode = 0;
+
+/* The XF86VIDMODE_EVENTS code is far from complete */
+
+#ifdef XF86VIDMODE_EVENTS
+static int XF86VidModeEventBase = 0;
+
+static void SXF86VidModeNotifyEvent();
+#if NeedFunctionPrototypes
+    xXF86VidModeNotifyEvent * /* from */,
+    xXF86VidModeNotifyEvent * /* to */
+#endif
+);
+
+extern WindowPtr *WindowTable;
+
+static RESTYPE EventType;      /* resource type for event masks */
+
+typedef struct _XF86VidModeEvent *XF86VidModeEventPtr;
+
+typedef struct _XF86VidModeEvent {
+    XF86VidModeEventPtr        next;
+    ClientPtr          client;
+    ScreenPtr          screen;
+    XID                        resource;
+    CARD32             mask;
+} XF86VidModeEventRec;
+
+static int XF86VidModeFreeEvents();
+
+typedef struct _XF86VidModeScreenPrivate {
+    XF86VidModeEventPtr        events;
+    Bool               hasWindow;
+} XF86VidModeScreenPrivateRec, *XF86VidModeScreenPrivatePtr;
+   
+static int ScreenPrivateIndex;
+
+#define GetScreenPrivate(s) ((ScreenSaverScreenPrivatePtr)(s)->devPrivates[ScreenPrivateIndex].ptr)
+#define SetScreenPrivate(s,v) ((s)->devPrivates[ScreenPrivateIndex].ptr = (pointer) v);
+#define SetupScreen(s)  ScreenSaverScreenPrivatePtr pPriv = GetScreenPrivate(s)
+
+#define New(t)  ((t *) xalloc (sizeof (t)))
+#endif
+
+void
+XFree86VidModeExtensionInit()
+{
+    ExtensionEntry* extEntry;
+#ifdef XF86VIDMODE_EVENTS
+    int                    i;
+    ScreenPtr      pScreen;
+
+    EventType = CreateNewResourceType(XF86VidModeFreeEvents);
+    ScreenPrivateIndex = AllocateScreenPrivateIndex ();
+    for (i = 0; i < screenInfo.numScreens; i++)
+    {
+       pScreen = screenInfo.screens[i];
+       SetScreenPrivate (pScreen, NULL);
+    }
+#endif
+
+    if (
+#ifdef XF86VIDMODE_EVENTS
+        EventType && ScreenPrivateIndex != -1 &&
+#endif
+       (extEntry = AddExtension(XF86VIDMODENAME,
+                               XF86VidModeNumberEvents,
+                               XF86VidModeNumberErrors,
+                               ProcXF86VidModeDispatch,
+                               SProcXF86VidModeDispatch,
+                               XF86VidModeResetProc,
+                               StandardMinorOpcode))) {
+       XF86VidModeReqCode = (unsigned char)extEntry->base;
+       vidmodeErrorBase = extEntry->errorBase;
+#ifdef XF86VIDMODE_EVENTS
+       XF86VidModeEventBase = extEntry->eventBase;
+       EventSwapVector[XF86VidModeEventBase] = SXF86VidModeNotifyEvent;
+#endif
+    }
+}
+
+/*ARGSUSED*/
+static void
+XF86VidModeResetProc (extEntry)
+    ExtensionEntry* extEntry;
+{
+}
+
+#ifdef XF86VIDMODE_EVENTS
+static void
+CheckScreenPrivate (pScreen)
+    ScreenPtr  pScreen;
+{
+    SetupScreen (pScreen);
+
+    if (!pPriv)
+       return;
+    if (!pPriv->events && !pPriv->hasWindow) {
+       xfree (pPriv);
+       SetScreenPrivate (pScreen, NULL);
+    }
+}
+    
+static XF86VidModeScreenPrivatePtr
+MakeScreenPrivate (pScreen)
+    ScreenPtr  pScreen;
+{
+    SetupScreen (pScreen);
+
+    if (pPriv)
+       return pPriv;
+    pPriv = New (XF86VidModeScreenPrivateRec);
+    if (!pPriv)
+       return 0;
+    pPriv->events = 0;
+    pPriv->hasWindow = FALSE;
+    SetScreenPrivate (pScreen, pPriv);
+    return pPriv;
+}
+
+static unsigned long
+getEventMask (pScreen, client)
+    ScreenPtr  pScreen;
+    ClientPtr  client;
+{
+    SetupScreen(pScreen);
+    XF86VidModeEventPtr pEv;
+
+    if (!pPriv)
+       return 0;
+    for (pEv = pPriv->events; pEv; pEv = pEv->next)
+       if (pEv->client == client)
+           return pEv->mask;
+    return 0;
+}
+
+static Bool
+setEventMask (pScreen, client, mask)
+    ScreenPtr  pScreen;
+    ClientPtr  client;
+    unsigned long mask;
+{
+    SetupScreen(pScreen);
+    XF86VidModeEventPtr pEv, *pPrev;
+
+    if (getEventMask (pScreen, client) == mask)
+       return TRUE;
+    if (!pPriv) {
+       pPriv = MakeScreenPrivate (pScreen);
+       if (!pPriv)
+           return FALSE;
+    }
+    for (pPrev = &pPriv->events; pEv = *pPrev; pPrev = &pEv->next)
+       if (pEv->client == client)
+           break;
+    if (mask == 0) {
+       *pPrev = pEv->next;
+       xfree (pEv);
+       CheckScreenPrivate (pScreen);
+    } else {
+       if (!pEv) {
+           pEv = New (ScreenSaverEventRec);
+           if (!pEv) {
+               CheckScreenPrivate (pScreen);
+               return FALSE;
+           }
+           *pPrev = pEv;
+           pEv->next = NULL;
+           pEv->client = client;
+           pEv->screen = pScreen;
+           pEv->resource = FakeClientID (client->index);
+       }
+       pEv->mask = mask;
+    }
+    return TRUE;
+}
+
+static int
+XF86VidModeFreeEvents (value, id)
+    pointer value;
+    XID id;
+{
+    XF86VidModeEventPtr        pOld = (XF86VidModeEventPtr)value;
+    ScreenPtr pScreen = pOld->screen;
+    SetupScreen (pScreen);
+    XF86VidModeEventPtr        pEv, *pPrev;
+
+    if (!pPriv)
+       return TRUE;
+    for (pPrev = &pPriv->events; pEv = *pPrev; pPrev = &pEv->next)
+       if (pEv == pOld)
+           break;
+    if (!pEv)
+       return TRUE;
+    *pPrev = pEv->next;
+    xfree (pEv);
+    CheckScreenPrivate (pScreen);
+    return TRUE;
+}
+
+static void
+SendXF86VidModeNotify (pScreen, state, forced)
+    ScreenPtr  pScreen;
+    int            state;
+    Bool    forced;
+{
+    XF86VidModeScreenPrivatePtr        pPriv;
+    XF86VidModeEventPtr                pEv;
+    unsigned long              mask;
+    xXF86VidModeNotifyEvent    ev;
+    ClientPtr                  client;
+    int                                kind;
+
+    UpdateCurrentTimeIf ();
+    mask = XF86VidModeNotifyMask;
+    pScreen = screenInfo.screens[pScreen->myNum];
+    pPriv = GetScreenPrivate(pScreen);
+    if (!pPriv)
+       return;
+    kind = XF86VidModeModeChange;
+    for (pEv = pPriv->events; pEv; pEv = pEv->next)
+    {
+       client = pEv->client;
+       if (client->clientGone)
+           continue;
+       if (!(pEv->mask & mask))
+           continue;
+       ev.type = XF86VidModeNotify + XF86VidModeEventBase;
+       ev.state = state;
+       ev.sequenceNumber = client->sequence;
+       ev.timestamp = currentTime.milliseconds;
+       ev.root = WindowTable[pScreen->myNum]->drawable.id;
+       ev.kind = kind;
+       ev.forced = forced;
+       WriteEventsToClient (client, 1, (xEvent *) &ev);
+    }
+}
+
+static void
+SXF86VidModeNotifyEvent (from, to)
+    xXF86VidModeNotifyEvent *from, *to;
+{
+    to->type = from->type;
+    to->state = from->state;
+    cpswaps (from->sequenceNumber, to->sequenceNumber);
+    cpswapl (from->timestamp, to->timestamp);    
+    cpswapl (from->root, to->root);    
+    to->kind = from->kind;
+    to->forced = from->forced;
+}
+#endif
+       
+static int
+ProcXF86VidModeQueryVersion(client)
+    register ClientPtr client;
+{
+    xXF86VidModeQueryVersionReply rep;
+    register int n;
+
+    REQUEST_SIZE_MATCH(xXF86VidModeQueryVersionReq);
+    rep.type = X_Reply;
+    rep.length = 0;
+    rep.sequenceNumber = client->sequence;
+    rep.majorVersion = XF86VIDMODE_MAJOR_VERSION;
+    rep.minorVersion = XF86VIDMODE_MINOR_VERSION;
+    if (client->swapped) {
+       swaps(&rep.sequenceNumber, n);
+       swapl(&rep.length, n);
+       swaps(&rep.majorVersion, n);
+       swaps(&rep.minorVersion, n);
+    }
+    WriteToClient(client, sizeof(xXF86VidModeQueryVersionReply), (char *)&rep);
+    return (client->noClientException);
+}
+
+static int
+ProcXF86VidModeGetModeLine(client)
+    register ClientPtr client;
+{
+    REQUEST(xXF86VidModeGetModeLineReq);
+    xXF86VidModeGetModeLineReply rep;
+    register int n;
+    ScrnInfoPtr vptr;
+    DisplayModePtr mptr;
+    int privsize;
+
+    if (stuff->screen > screenInfo.numScreens)
+       return BadValue;
+
+    vptr = (ScrnInfoPtr) screenInfo.screens[stuff->screen]->devPrivates[xf86ScreenIndex].ptr;
+    mptr = vptr->modes;
+
+    if (!mptr->Private)
+       privsize = 0;
+    else
+       privsize = mptr->PrivSize;
+
+    REQUEST_SIZE_MATCH(xXF86VidModeGetModeLineReq);
+    rep.type = X_Reply;
+    rep.length = (SIZEOF(xXF86VidModeGetModeLineReply) - SIZEOF(xGenericReply) +
+                 privsize * sizeof(INT32)) >> 2;
+    rep.sequenceNumber = client->sequence;
+    rep.dotclock = vptr->clock[mptr->Clock];
+    rep.hdisplay = mptr->HDisplay;
+    rep.hsyncstart = mptr->HSyncStart;
+    rep.hsyncend = mptr->HSyncEnd;
+    rep.htotal = mptr->HTotal;
+    rep.vdisplay = mptr->VDisplay;
+    rep.vsyncstart = mptr->VSyncStart;
+    rep.vsyncend = mptr->VSyncEnd;
+    rep.vtotal = mptr->VTotal;
+    rep.flags = mptr->Flags;
+    rep.privsize = privsize;
+    if (client->swapped) {
+       swaps(&rep.sequenceNumber, n);
+       swapl(&rep.length, n);
+       swapl(&rep.dotclock, n);
+       swaps(&rep.hdisplay, n);
+       swaps(&rep.hsyncstart, n);
+       swaps(&rep.hsyncend, n);
+       swaps(&rep.htotal, n);
+       swaps(&rep.vdisplay, n);
+       swaps(&rep.vsyncstart, n);
+       swaps(&rep.vsyncend, n);
+       swaps(&rep.vtotal, n);
+       swapl(&rep.flags, n);
+       swapl(&rep.privsize, n);
+    }
+    WriteToClient(client, sizeof(xXF86VidModeGetModeLineReply), (char *)&rep);
+    if (privsize) {
+       client->pSwapReplyFunc = (ReplySwapPtr) Swap32Write;
+       WriteSwappedDataToClient(client, privsize * sizeof(INT32),
+                                mptr->Private);
+    }
+    return (client->noClientException);
+}
+
+static int
+ProcXF86VidModeGetAllModeLines(client)
+    register ClientPtr client;
+{
+    REQUEST(xXF86VidModeGetAllModeLinesReq);
+    xXF86VidModeGetAllModeLinesReply rep;
+    xXF86VidModeModeInfo mdinf;
+    register int n;
+    ScrnInfoPtr vptr;
+    DisplayModePtr mptr, curmptr;
+    int privsize, modecount=1;
+    int totalPrivSize = 0;
+
+    if (stuff->screen > screenInfo.numScreens)
+       return BadValue;
+
+    vptr = (ScrnInfoPtr) screenInfo.screens[stuff->screen]->devPrivates[xf86ScreenIndex].ptr;
+    curmptr = mptr = vptr->modes;
+
+    totalPrivSize = mptr->Private ? mptr->PrivSize : 0;
+
+    while (mptr->next != curmptr) {
+       ++modecount;
+       mptr = mptr->next;
+       if (mptr->Private)
+           totalPrivSize += mptr->PrivSize;
+    }
+
+    REQUEST_SIZE_MATCH(xXF86VidModeGetAllModeLinesReq);
+    rep.type = X_Reply;
+    rep.length = (SIZEOF(xXF86VidModeGetAllModeLinesReply) - SIZEOF(xGenericReply) +
+                 modecount * sizeof(xXF86VidModeModeInfo) +
+                 totalPrivSize * sizeof(INT32)) >> 2;
+    rep.sequenceNumber = client->sequence;
+    rep.modecount = modecount;
+    if (client->swapped) {
+       swaps(&rep.sequenceNumber, n);
+       swapl(&rep.length, n);
+       swapl(&rep.modecount, n);
+    }
+    WriteToClient(client, sizeof(xXF86VidModeGetAllModeLinesReply), (char *)&rep);
+    mptr = curmptr;
+    do {
+        if (!mptr->Private)
+           privsize = 0;
+        else
+           privsize = mptr->PrivSize;
+
+        mdinf.dotclock = vptr->clock[mptr->Clock];
+        mdinf.hdisplay = mptr->HDisplay;
+        mdinf.hsyncstart = mptr->HSyncStart;
+        mdinf.hsyncend = mptr->HSyncEnd;
+        mdinf.htotal = mptr->HTotal;
+        mdinf.vdisplay = mptr->VDisplay;
+        mdinf.vsyncstart = mptr->VSyncStart;
+        mdinf.vsyncend = mptr->VSyncEnd;
+        mdinf.vtotal = mptr->VTotal;
+        mdinf.flags = mptr->Flags;
+        mdinf.privsize = privsize;
+        if (client->swapped) {
+           swapl(&mdinf.dotclock, n);
+           swaps(&mdinf.hdisplay, n);
+           swaps(&mdinf.hsyncstart, n);
+           swaps(&mdinf.hsyncend, n);
+           swaps(&mdinf.htotal, n);
+           swaps(&mdinf.vdisplay, n);
+           swaps(&mdinf.vsyncstart, n);
+           swaps(&mdinf.vsyncend, n);
+           swaps(&mdinf.vtotal, n);
+           swapl(&mdinf.flags, n);
+           swapl(&mdinf.privsize, n);
+        }
+        WriteToClient(client, sizeof(xXF86VidModeModeInfo), (char *)&mdinf);
+       if (privsize) {
+           client->pSwapReplyFunc = (ReplySwapPtr) Swap32Write;
+           WriteSwappedDataToClient(client, privsize * sizeof(INT32),
+                                    mptr->Private);
+       }
+        mptr = mptr->next;
+    } while (mptr != curmptr);
+    return (client->noClientException);
+}
+
+#define CLOCKSPD(clk,scrp)     ((clk>MAXCLOCKS)? clk: scrp->clock[clk])
+#define MODEMATCH(mptr,stuff,scrp)     \
+       (CLOCKSPD(mptr->Clock,scrp) == CLOCKSPD(stuff->dotclock,scrp) \
+                               && mptr->HDisplay  == stuff->hdisplay \
+                               && mptr->HSyncStart== stuff->hsyncstart \
+                               && mptr->HSyncEnd  == stuff->hsyncend \
+                               && mptr->HTotal    == stuff->htotal \
+                               && mptr->VDisplay  == stuff->vdisplay \
+                               && mptr->VSyncStart== stuff->vsyncstart \
+                               && mptr->VSyncEnd  == stuff->vsyncend \
+                               && mptr->VTotal    == stuff->vtotal \
+                               && mptr->Flags     == stuff->flags )
+
+#include "xf86_Config.h"
+
+static int
+ProcXF86VidModeAddModeLine(client)
+    register ClientPtr client;
+{
+    REQUEST(xXF86VidModeAddModeLineReq);
+    ScrnInfoPtr vptr;
+    DisplayModePtr curmptr, mptr, newmptr;
+    Bool clock_added = FALSE;
+    int i, len;
+
+    if (xf86Verbose > 1) {
+       ErrorF("AddModeLine - scrn: %d clock: %d\n",
+               stuff->screen, stuff->dotclock);
+       ErrorF("AddModeLine - hdsp: %d hbeg: %d hend: %d httl: %d\n",
+               stuff->hdisplay, stuff->hsyncstart,
+               stuff->hsyncend, stuff->htotal);
+       ErrorF("              vdsp: %d vbeg: %d vend: %d vttl: %d flags: %d\n",
+               stuff->vdisplay, stuff->vsyncstart, stuff->vsyncend,
+               stuff->vtotal, stuff->flags);
+       ErrorF("      after - scrn: %d clock: %d\n",
+               stuff->screen, stuff->after_dotclock);
+       ErrorF("              hdsp: %d hbeg: %d hend: %d httl: %d\n",
+               stuff->after_hdisplay, stuff->after_hsyncstart,
+               stuff->after_hsyncend, stuff->after_htotal);
+       ErrorF("              vdsp: %d vbeg: %d vend: %d vttl: %d flags: %d\n",
+               stuff->after_vdisplay, stuff->after_vsyncstart,
+               stuff->after_vsyncend, stuff->after_vtotal, stuff->after_flags);
+    }
+    if (stuff->screen > screenInfo.numScreens)
+       return BadValue;
+
+    vptr = (ScrnInfoPtr) screenInfo.screens[stuff->screen]->devPrivates[xf86ScreenIndex].ptr;
+    curmptr = mptr = vptr->modes;
+
+    REQUEST_AT_LEAST_SIZE(xXF86VidModeAddModeLineReq);
+    len = client->req_len - (sizeof(xXF86VidModeAddModeLineReq) >> 2);
+    if (len != stuff->privsize)
+       return BadLength;
+
+    if (stuff->hsyncstart < stuff->hdisplay   ||
+       stuff->hsyncend   < stuff->hsyncstart ||
+       stuff->htotal     < stuff->hsyncend   ||
+       stuff->vsyncstart < stuff->vdisplay   ||
+       stuff->vsyncend   < stuff->vsyncstart ||
+       stuff->vtotal     < stuff->vsyncend)
+       return BadValue;
+
+    if (stuff->after_hsyncstart < stuff->after_hdisplay   ||
+       stuff->after_hsyncend   < stuff->after_hsyncstart ||
+       stuff->after_htotal     < stuff->after_hsyncend   ||
+       stuff->after_vsyncstart < stuff->after_vdisplay   ||
+       stuff->after_vsyncend   < stuff->after_vsyncstart ||
+       stuff->after_vtotal     < stuff->after_vsyncend)
+       return BadValue;
+
+    if (stuff->after_htotal != 0 || stuff->after_vtotal != 0) {
+       Bool found = FALSE;
+       do {
+           if (MODEMATCH(mptr, stuff, vptr)) {
+               found = TRUE;
+               break;
+           }
+       } while ((mptr = mptr->next) != curmptr);
+       if (!found)
+           return BadValue;
+    }
+
+    newmptr = (DisplayModePtr) xalloc(sizeof(DisplayModeRec));
+
+    /* Clock checking code, mostly copied from the xf86LookupMode function */
+    if (stuff->dotclock < vptr->clocks) {
+       newmptr->Clock = stuff->dotclock;
+    } else {
+       if ((OFLG_ISSET(CLOCK_OPTION_PROGRAMABLE, &(vptr->clockOptions))) &&
+           !OFLG_ISSET(OPTION_NO_PROGRAM_CLOCKS, &(vptr->options)))
+       {
+           for (i = 0; i < vptr->clocks; i++)
+               if (stuff->dotclock == vptr->clock[i])
+                   break;
+
+           if (i >= MAXCLOCKS || vptr->clock[i]/1000 > vptr->maxClock/1000) {
+               xfree(newmptr);
+               return vidmodeErrorBase + XF86VidModeBadClock;
+           }
+       
+           if (i == vptr->clocks) {
+               vptr->clock[i] = stuff->dotclock;
+               vptr->clocks++;
+               clock_added = TRUE;
+           }
+       } else {
+           int         flags=0, j, k, Gap, Minimum_Gap = CLOCK_TOLERANCE + 1;
+           double      refresh, bestRefresh = 0.0;
+
+           if (OFLG_ISSET(OPTION_CLKDIV2, &(vptr->options)))
+               k=2;
+           else
+               k=1;
+           
+           if (xf86BestRefresh)
+               flags |= LOOKUP_BEST_REFRESH;
+
+           for (j=1 ; j<=k ; j++) {
+               i = xf86GetNearestClock(vptr, stuff->dotclock * j);
+               if (flags & LOOKUP_BEST_REFRESH) {
+                   if ( ((vptr->clock[i]/j) / 1000) > (vptr->maxClock / 1000) ) {
+                       xfree(newmptr);
+                       return vidmodeErrorBase + XF86VidModeBadClock;
+                   } else {
+                       refresh = stuff->dotclock * 1000.0 / stuff->htotal / stuff->vtotal;
+                       if (stuff->flags & V_INTERLACE) {
+                           refresh *= 2;
+                           refresh /= INTERLACE_REFRESH_WEIGHT;
+                       } else if (stuff->flags & V_DBLSCAN)
+                           refresh /= 2;
+
+                       if (refresh > bestRefresh) {
+                           newmptr->Clock = i;
+                           if (j==2) stuff->flags |= V_CLKDIV2;
+                           bestRefresh = refresh;
+                       }
+                   }
+               } else {
+                   Gap = abs( stuff->dotclock - (vptr->clock[i]/j) );
+                   if (Gap < Minimum_Gap) {
+                       if ( ((vptr->clock[i]/j) / 1000) > (vptr->maxClock / 1000) ) {
+                           xfree(newmptr);
+                           return vidmodeErrorBase + XF86VidModeBadClock;
+                       } else {
+                           newmptr->Clock = i;
+                           if (j==2) stuff->flags |= V_CLKDIV2;
+                           Minimum_Gap = Gap;
+                       }
+                   }
+               }
+           }
+       }
+    }
+
+    newmptr->CrtcHDisplay  = newmptr->HDisplay      = stuff->hdisplay;
+    newmptr->CrtcHSyncStart= newmptr->HSyncStart    = stuff->hsyncstart;
+    newmptr->CrtcHSyncEnd  = newmptr->HSyncEnd      = stuff->hsyncend;
+    newmptr->CrtcHTotal    = newmptr->HTotal        = stuff->htotal;
+    newmptr->CrtcVDisplay  = newmptr->VDisplay      = stuff->vdisplay;
+    newmptr->CrtcVSyncStart= newmptr->VSyncStart    = stuff->vsyncstart;
+    newmptr->CrtcVSyncEnd  = newmptr->VSyncEnd      = stuff->vsyncend;
+    newmptr->CrtcVTotal    = newmptr->VTotal        = stuff->vtotal;
+    newmptr->Flags         = stuff->flags;
+#if 0
+    newmptr->CrtcHSkew     = newmptr->HSkew         = stuff->hskew;
+#endif
+    newmptr->CrtcHAdjusted = FALSE;
+    newmptr->CrtcVAdjusted = FALSE;
+    newmptr->name          = "";
+    newmptr->Private       = NULL;
+    if (stuff->privsize) {
+       if (xf86Verbose > 1)
+           ErrorF("AddModeLine - Request includes privates\n");
+       newmptr->Private =
+           (INT32 *) ALLOCATE_LOCAL(stuff->privsize * sizeof(INT32));
+       memcpy(newmptr->Private, &stuff[1], stuff->privsize*sizeof(INT32));
+    }
+
+    /* Check that the mode is consistent with the monitor specs */
+    switch (xf86CheckMode(vptr, newmptr, vptr->monitor, FALSE)) {
+       case MODE_OK:
+           break;
+       case MODE_HSYNC:
+           xfree(newmptr->Private);
+           xfree(newmptr);
+           if (clock_added)
+               vptr->clocks--;
+           return vidmodeErrorBase + XF86VidModeBadHTimings;
+       case MODE_VSYNC:
+           xfree(newmptr->Private);
+           xfree(newmptr);
+           if (clock_added)
+               vptr->clocks--;
+           return vidmodeErrorBase + XF86VidModeBadVTimings;
+       default:
+           if (clock_added)
+               vptr->clocks--;
+           return vidmodeErrorBase + XF86VidModeModeUnsuitable;
+    }
+
+    /* Check that the driver is happy with the mode */
+    if (vptr->ValidMode(newmptr, xf86Verbose, MODE_VID) != MODE_OK) {
+       xfree(newmptr->Private);
+       xfree(newmptr);
+       if (clock_added)
+           vptr->clocks--;
+       return vidmodeErrorBase + XF86VidModeModeUnsuitable;
+    }
+
+    if (newmptr->Flags & V_DBLSCAN)
+    {
+       newmptr->CrtcVDisplay *= 2;
+       newmptr->CrtcVSyncStart *= 2;
+       newmptr->CrtcVSyncEnd *= 2;
+       newmptr->CrtcVTotal *= 2;
+       newmptr->CrtcVAdjusted = TRUE;
+    }
+
+    newmptr->next       = mptr->next;
+    newmptr->prev       = mptr;
+    mptr->next          = newmptr;
+    newmptr->next->prev = newmptr;
+
+#if 0  /* Do we want this? */
+    (vptr->SwitchMode)(newmptr);
+#endif
+
+    if (xf86Verbose > 1)
+       ErrorF("AddModeLine - Succeeded\n");
+    return(client->noClientException);
+}
+
+static int
+ProcXF86VidModeDeleteModeLine(client)
+    register ClientPtr client;
+{
+    REQUEST(xXF86VidModeDeleteModeLineReq);
+    ScrnInfoPtr vptr;
+    DisplayModePtr curmptr, mptr;
+    int len;
+
+    if (xf86Verbose > 1) {
+       ErrorF("DeleteModeLine - scrn: %d clock: %d\n",
+               stuff->screen, stuff->dotclock, stuff->dotclock);
+       ErrorF("                 hdsp: %d hbeg: %d hend: %d httl: %d\n",
+               stuff->hdisplay, stuff->hsyncstart,
+               stuff->hsyncend, stuff->htotal);
+       ErrorF("                 vdsp: %d vbeg: %d vend: %d vttl: %d flags: %d\n",
+               stuff->vdisplay, stuff->vsyncstart, stuff->vsyncend,
+               stuff->vtotal, stuff->flags);
+    }
+    if (stuff->screen > screenInfo.numScreens)
+       return BadValue;
+
+    vptr = (ScrnInfoPtr) screenInfo.screens[stuff->screen]->devPrivates[xf86ScreenIndex].ptr;
+    curmptr = mptr = vptr->modes;
+
+    REQUEST_AT_LEAST_SIZE(xXF86VidModeDeleteModeLineReq);
+    len = client->req_len - (sizeof(xXF86VidModeDeleteModeLineReq) >> 2);
+    if (len != stuff->privsize) {
+       if (xf86Verbose > 1) {
+           ErrorF("req_len = %d, sizeof(Req) = %d, privsize = %d, len = %d, length = %d\n",
+                   client->req_len, sizeof(xXF86VidModeDeleteModeLineReq)>>2, stuff->privsize, len, stuff->length);
+       }
+       return BadLength;
+    }
+    if (xf86Verbose > 1) {
+       ErrorF("Checking against clock: %d (%d)\n",
+               mptr->Clock, CLOCKSPD(mptr->Clock, vptr));
+       ErrorF("                 hdsp: %d hbeg: %d hend: %d httl: %d\n",
+               mptr->HDisplay, mptr->HSyncStart,
+               mptr->HSyncEnd, mptr->HTotal);
+       ErrorF("                 vdsp: %d vbeg: %d vend: %d vttl: %d flags: %d\n",
+               mptr->VDisplay, mptr->VSyncStart, mptr->VSyncEnd,
+               mptr->VTotal, mptr->Flags);
+    }
+    if (MODEMATCH(mptr, stuff, vptr))
+       return BadValue;
+
+    while ((mptr = mptr->next) != curmptr) {
+       if (xf86Verbose > 1) {
+           ErrorF("Checking against clock: %d (%d)\n",
+                   mptr->Clock, CLOCKSPD(mptr->Clock, vptr));
+           ErrorF("                 hdsp: %d hbeg: %d hend: %d httl: %d\n",
+                   mptr->HDisplay, mptr->HSyncStart,
+                   mptr->HSyncEnd, mptr->HTotal);
+           ErrorF("                 vdsp: %d vbeg: %d vend: %d vttl: %d flags: %d\n",
+                   mptr->VDisplay, mptr->VSyncStart, mptr->VSyncEnd,
+                   mptr->VTotal, mptr->Flags);
+       }
+       if (MODEMATCH(mptr, stuff, vptr)) {
+           mptr->prev->next = mptr->next;
+           mptr->next->prev = mptr->prev;
+           xfree(mptr->name);
+           xfree(mptr->Private);
+           xfree(mptr);
+           if (xf86Verbose)
+               ErrorF("DeleteModeLine - Succeeded\n");
+           return(client->noClientException);
+       }
+    }
+    return BadValue;
+}
+
+static int
+ProcXF86VidModeModModeLine(client)
+    register ClientPtr client;
+{
+    REQUEST(xXF86VidModeModModeLineReq);
+    ScrnInfoPtr vptr;
+    DisplayModePtr mptr;
+    DisplayModeRec modetmp;
+    int len;
+
+    if (xf86Verbose > 1) {
+       ErrorF("ModModeLine - scrn: %d hdsp: %d hbeg: %d hend: %d httl: %d\n",
+               stuff->screen, stuff->hdisplay, stuff->hsyncstart,
+               stuff->hsyncend, stuff->htotal);
+       ErrorF("              vdsp: %d vbeg: %d vend: %d vttl: %d flags: %d\n",
+               stuff->vdisplay, stuff->vsyncstart, stuff->vsyncend,
+               stuff->vtotal, stuff->flags);
+    }
+    if (stuff->screen > screenInfo.numScreens)
+       return BadValue;
+
+    vptr = (ScrnInfoPtr) screenInfo.screens[stuff->screen]->devPrivates[xf86ScreenIndex].ptr;
+    mptr = vptr->modes;
+
+    REQUEST_AT_LEAST_SIZE(xXF86VidModeModModeLineReq);
+    len = client->req_len - (sizeof(xXF86VidModeModModeLineReq) >> 2);
+    if (len != stuff->privsize)
+       return BadLength;
+
+    if (stuff->hsyncstart < stuff->hdisplay   ||
+       stuff->hsyncend   < stuff->hsyncstart ||
+       stuff->htotal     < stuff->hsyncend   ||
+       stuff->vsyncstart < stuff->vdisplay   ||
+       stuff->vsyncend   < stuff->vsyncstart ||
+       stuff->vtotal     < stuff->vsyncend)
+       return BadValue;
+
+    memcpy(&modetmp, mptr, sizeof(DisplayModeRec));
+
+    modetmp.HDisplay   = stuff->hdisplay;
+    modetmp.HSyncStart = stuff->hsyncstart;
+    modetmp.HSyncEnd   = stuff->hsyncend;
+    modetmp.HTotal     = stuff->htotal;
+    modetmp.VDisplay   = stuff->vdisplay;
+    modetmp.VSyncStart = stuff->vsyncstart;
+    modetmp.VSyncEnd   = stuff->vsyncend;
+    modetmp.VTotal     = stuff->vtotal;
+    modetmp.Flags      = stuff->flags;
+    if (mptr->PrivSize && stuff->privsize) {
+       if (mptr->PrivSize != stuff->privsize)
+           return BadValue;
+    }
+    if (mptr->PrivSize && mptr->Private) {
+       modetmp.Private =
+               (INT32 *)ALLOCATE_LOCAL(mptr->PrivSize * sizeof(INT32));
+       if (stuff->privsize) {
+           if (xf86Verbose > 1)
+               ErrorF("ModModeLine - Request includes privates\n");
+           memcpy(modetmp.Private, &stuff[1], mptr->PrivSize * sizeof(INT32));
+       } else
+           memcpy(modetmp.Private, mptr->Private,
+                  mptr->PrivSize * sizeof(INT32));
+    }
+
+    /* Check that the mode is consistent with the monitor specs */
+    switch (xf86CheckMode(vptr, &modetmp, vptr->monitor, FALSE)) {
+       case MODE_HSYNC:
+           DEALLOCATE_LOCAL(modetmp.Private);
+           return vidmodeErrorBase + XF86VidModeBadHTimings;
+       case MODE_VSYNC:
+           DEALLOCATE_LOCAL(modetmp.Private);
+           return vidmodeErrorBase + XF86VidModeBadVTimings;
+    }
+
+    /* Check that the driver is happy with the mode */
+    if (vptr->ValidMode(&modetmp, xf86Verbose, MODE_VID) != MODE_OK) {
+       DEALLOCATE_LOCAL(modetmp.Private);
+       return vidmodeErrorBase + XF86VidModeModeUnsuitable;
+    }
+
+    DEALLOCATE_LOCAL(modetmp.Private);
+
+    mptr->HDisplay   = stuff->hdisplay;
+    mptr->HSyncStart = stuff->hsyncstart;
+    mptr->HSyncEnd   = stuff->hsyncend;
+    mptr->HTotal     = stuff->htotal;
+    mptr->VDisplay   = stuff->vdisplay;
+    mptr->VSyncStart = stuff->vsyncstart;
+    mptr->VSyncEnd   = stuff->vsyncend;
+    mptr->VTotal     = stuff->vtotal;
+    mptr->Flags      = stuff->flags;
+    mptr->CrtcHDisplay   = stuff->hdisplay;
+    mptr->CrtcHSyncStart = stuff->hsyncstart;
+    mptr->CrtcHSyncEnd   = stuff->hsyncend;
+    mptr->CrtcHTotal     = stuff->htotal;
+    mptr->CrtcVDisplay   = stuff->vdisplay;
+    mptr->CrtcVSyncStart = stuff->vsyncstart;
+    mptr->CrtcVSyncEnd   = stuff->vsyncend;
+    mptr->CrtcVTotal     = stuff->vtotal;
+    mptr->CrtcVAdjusted = FALSE;
+    mptr->CrtcHAdjusted = FALSE;
+    if (mptr->Flags & V_DBLSCAN)
+    {
+       mptr->CrtcVDisplay *= 2;
+       mptr->CrtcVSyncStart *= 2;
+       mptr->CrtcVSyncEnd *= 2;
+       mptr->CrtcVTotal *= 2;
+       mptr->CrtcVAdjusted = TRUE;
+    }
+    if (mptr->PrivSize && stuff->privsize) {
+       memcpy(mptr->Private, &stuff[1], mptr->PrivSize * sizeof(INT32));
+    }
+
+    (vptr->SwitchMode)(mptr);
+    (vptr->AdjustFrame)(vptr->frameX0, vptr->frameY0);
+
+    if (xf86Verbose > 1)
+       ErrorF("ModModeLine - Succeeded\n");
+    return(client->noClientException);
+}
+
+static int
+ProcXF86VidModeValidateModeLine(client)
+    register ClientPtr client;
+{
+    REQUEST(xXF86VidModeValidateModeLineReq);
+    xXF86VidModeValidateModeLineReply rep;
+    ScrnInfoPtr vptr;
+    DisplayModePtr mptr;
+    DisplayModeRec modetmp;
+    int len, status;
+
+    if (xf86Verbose > 1) {
+       ErrorF("ValidateModeLine - scrn: %d clock: %d\n",
+               stuff->screen, stuff->dotclock);
+       ErrorF("                   hdsp: %d hbeg: %d hend: %d httl: %d\n",
+               stuff->hdisplay, stuff->hsyncstart,
+               stuff->hsyncend, stuff->htotal);
+       ErrorF("                   vdsp: %d vbeg: %d vend: %d vttl: %d flags: %d\n",
+               stuff->vdisplay, stuff->vsyncstart, stuff->vsyncend,
+               stuff->vtotal, stuff->flags);
+    }
+    if (stuff->screen > screenInfo.numScreens)
+       return BadValue;
+
+    vptr = (ScrnInfoPtr) screenInfo.screens[stuff->screen]->devPrivates[xf86ScreenIndex].ptr;
+    mptr = vptr->modes;
+
+    REQUEST_AT_LEAST_SIZE(xXF86VidModeValidateModeLineReq);
+    len = client->req_len - (sizeof(xXF86VidModeValidateModeLineReq) >> 2);
+    if (len != stuff->privsize)
+       return BadLength;
+
+    status = MODE_OK;
+    modetmp.Private = NULL;
+
+    if (stuff->hsyncstart < stuff->hdisplay   ||
+       stuff->hsyncend   < stuff->hsyncstart ||
+       stuff->htotal     < stuff->hsyncend   ||
+       stuff->vsyncstart < stuff->vdisplay   ||
+       stuff->vsyncend   < stuff->vsyncstart ||
+       stuff->vtotal     < stuff->vsyncend)
+    {
+       status = MODE_BAD;
+       goto status_reply;
+    }
+
+    memcpy(&modetmp, mptr, sizeof(DisplayModeRec));
+
+    modetmp.HDisplay   = stuff->hdisplay;
+    modetmp.HSyncStart = stuff->hsyncstart;
+    modetmp.HSyncEnd   = stuff->hsyncend;
+    modetmp.HTotal     = stuff->htotal;
+    modetmp.VDisplay   = stuff->vdisplay;
+    modetmp.VSyncStart = stuff->vsyncstart;
+    modetmp.VSyncEnd   = stuff->vsyncend;
+    modetmp.VTotal     = stuff->vtotal;
+    modetmp.Flags      = stuff->flags;
+    modetmp.Private    = NULL;
+    if (mptr->PrivSize && stuff->privsize) {
+       if (mptr->PrivSize != stuff->privsize) {
+           status = MODE_BAD;
+           goto status_reply;
+       }
+    }
+    if (mptr->PrivSize && mptr->Private) {
+       modetmp.Private =
+               (INT32 *)ALLOCATE_LOCAL(mptr->PrivSize * sizeof(INT32));
+       if (stuff->privsize) {
+           if (xf86Verbose)
+               ErrorF("ValidateModeLine - Request includes privates\n");
+           memcpy(modetmp.Private, &stuff[1], mptr->PrivSize * sizeof(INT32));
+       } else
+           memcpy(modetmp.Private, mptr->Private,
+                  mptr->PrivSize * sizeof(INT32));
+    }
+
+    /* Check that the mode is consistent with the monitor specs */
+    if ((status = xf86CheckMode(vptr, &modetmp, vptr->monitor, FALSE)) != MODE_OK)
+       goto status_reply;
+
+    /* Check that the driver is happy with the mode */
+    status = vptr->ValidMode(&modetmp, xf86Verbose, MODE_VID);
+
+status_reply:
+    if (modetmp.Private)
+       DEALLOCATE_LOCAL(modetmp.Private);
+    rep.type = X_Reply;
+    rep.length = (SIZEOF(xXF86VidModeValidateModeLineReply)
+                        - SIZEOF(xGenericReply)) >> 2;
+    rep.sequenceNumber = client->sequence;
+    rep.status = status;
+    if (client->swapped) {
+        register int n;
+       swaps(&rep.sequenceNumber, n);
+       swapl(&rep.length, n);
+       swapl(&rep.status, n);
+    }
+    WriteToClient(client, sizeof(xXF86VidModeValidateModeLineReply), (char *)&rep);
+    if (xf86Verbose > 1)
+       ErrorF("ValidateModeLine - Succeeded\n");
+    return(client->noClientException);
+}
+
+static int
+ProcXF86VidModeSwitchMode(client)
+    register ClientPtr client;
+{
+    REQUEST(xXF86VidModeSwitchModeReq);
+    ScreenPtr vptr;
+
+    if (stuff->screen > screenInfo.numScreens)
+       return BadValue;
+
+    vptr = screenInfo.screens[stuff->screen];
+    if (xf86Info.dontZoom)
+       return vidmodeErrorBase + XF86VidModeZoomLocked;
+
+    REQUEST_SIZE_MATCH(xXF86VidModeSwitchModeReq);
+
+    xf86ZoomViewport(vptr, (short)stuff->zoom);
+    return (client->noClientException);
+}
+
+static int
+ProcXF86VidModeSwitchToMode(client)
+    register ClientPtr client;
+{
+    REQUEST(xXF86VidModeSwitchToModeReq);
+    ScrnInfoPtr vptr;
+    DisplayModePtr curmptr, mptr;
+    int len;
+
+    if (xf86Verbose > 1) {
+       ErrorF("SwitchToMode - scrn: %d clock: %d\n",
+               stuff->screen, stuff->dotclock);
+       ErrorF("               hdsp: %d hbeg: %d hend: %d httl: %d\n",
+               stuff->hdisplay, stuff->hsyncstart,
+               stuff->hsyncend, stuff->htotal);
+       ErrorF("               vdsp: %d vbeg: %d vend: %d vttl: %d flags: %d\n",
+               stuff->vdisplay, stuff->vsyncstart, stuff->vsyncend,
+               stuff->vtotal, stuff->flags);
+    }
+    if (stuff->screen > screenInfo.numScreens)
+       return BadValue;
+
+    if (xf86Info.dontZoom)
+       return vidmodeErrorBase + XF86VidModeZoomLocked;
+
+    vptr = (ScrnInfoPtr) screenInfo.screens[stuff->screen]->devPrivates[xf86ScreenIndex].ptr;
+    curmptr = mptr = vptr->modes;
+
+    REQUEST_AT_LEAST_SIZE(xXF86VidModeSwitchToModeReq);
+    len = client->req_len - (sizeof(xXF86VidModeSwitchToModeReq) >> 2);
+    if (len != stuff->privsize)
+       return BadLength;
+
+
+    if (MODEMATCH(mptr, stuff, vptr))
+       return (client->noClientException);
+
+    while ((mptr = mptr->next) != curmptr) {
+       if (xf86Verbose > 1) {
+           ErrorF("Checking against clock: %d (%d)\n",
+                   mptr->Clock, CLOCKSPD(mptr->Clock, vptr));
+           ErrorF("                 hdsp: %d hbeg: %d hend: %d httl: %d\n",
+                   mptr->HDisplay, mptr->HSyncStart,
+                   mptr->HSyncEnd, mptr->HTotal);
+           ErrorF("                 vdsp: %d vbeg: %d vend: %d vttl: %d flags: %d\n",
+                   mptr->VDisplay, mptr->VSyncStart, mptr->VSyncEnd,
+                   mptr->VTotal, mptr->Flags);
+       }
+       if (MODEMATCH(mptr, stuff, vptr)) {
+           if ((vptr->SwitchMode)(mptr)) {
+               vptr->modes = mptr;
+               vptr->frameX0 = (vptr->frameX1 +vptr->frameX0 -mptr->HDisplay)/2;
+               vptr->frameX1 = vptr->frameX0 + mptr->HDisplay -1;
+               if (vptr->frameX0 < 0) {
+                   vptr->frameX0 = 0;
+                   vptr->frameX1 = mptr->HDisplay -1;
+               } else if (vptr->frameX1 >= vptr->virtualX) {
+                   vptr->frameX0 = vptr->virtualX - mptr->HDisplay;
+                   vptr->frameX1 = vptr->frameX0 + mptr->HDisplay -1;
+               }
+               vptr->frameY0 = (vptr->frameY1 +vptr->frameY0 -mptr->VDisplay)/2;
+               vptr->frameY1 = vptr->frameY0 + mptr->VDisplay -1;
+               if (vptr->frameY0 < 0) {
+                   vptr->frameY0 = 0;
+                   vptr->frameY1 = mptr->VDisplay -1;
+               } else if (vptr->frameY1 >= vptr->virtualY) {
+                   vptr->frameY0 = vptr->virtualY - mptr->VDisplay;
+                   vptr->frameY1 = vptr->frameY0 + mptr->VDisplay -1;
+               }
+           }
+           (vptr->AdjustFrame)(vptr->frameX0, vptr->frameY0);
+           if (xf86Verbose > 1)
+               ErrorF("SwitchToMode - Succeeded\n");
+           return(client->noClientException);
+       }
+    }
+    return BadValue;
+}
+
+static int
+ProcXF86VidModeLockModeSwitch(client)
+    register ClientPtr client;
+{
+    REQUEST(xXF86VidModeLockModeSwitchReq);
+    ScreenPtr vptr;
+
+    if (stuff->screen > screenInfo.numScreens)
+       return BadValue;
+
+    vptr = screenInfo.screens[stuff->screen];
+    if (xf86Info.dontZoom)
+       return vidmodeErrorBase + XF86VidModeZoomLocked;
+
+    REQUEST_SIZE_MATCH(xXF86VidModeLockModeSwitchReq);
+
+    xf86LockZoom(vptr, (short)stuff->lock);
+    return (client->noClientException);
+}
+
+static int
+ProcXF86VidModeGetMonitor(client)
+    register ClientPtr client;
+{
+    REQUEST(xXF86VidModeGetMonitorReq);
+    xXF86VidModeGetMonitorReply rep;
+    register int n;
+    ScrnInfoPtr vptr;
+    MonPtr mptr;
+    CARD32 *hsyncdata, *vsyncdata;
+    int i;
+
+    if (stuff->screen > screenInfo.numScreens)
+       return BadValue;
+
+    vptr = (ScrnInfoPtr) screenInfo.screens[stuff->screen]->devPrivates[xf86ScreenIndex].ptr;
+    mptr = vptr->monitor;
+
+    REQUEST_SIZE_MATCH(xXF86VidModeGetMonitorReq);
+    rep.type = X_Reply;
+    if (mptr->vendor)
+       rep.vendorLength = strlen(mptr->vendor);
+    else
+       rep.vendorLength = 0;
+    if (mptr->model)
+       rep.modelLength = strlen(mptr->model);
+    else
+       rep.modelLength = 0;
+    rep.length = (SIZEOF(xXF86VidModeGetMonitorReply) - SIZEOF(xGenericReply) +
+                 (mptr->n_hsync + mptr->n_vrefresh) * sizeof(CARD32) +
+                 ((rep.vendorLength + 3) & ~3) +
+                 ((rep.modelLength + 3) & ~3)) >> 2;
+    rep.sequenceNumber = client->sequence;
+    rep.nhsync = mptr->n_hsync;
+    rep.nvsync = mptr->n_vrefresh;
+#if 0
+    rep.bandwidth = (unsigned long)(mptr->bandwidth * 1e6);
+#endif
+    hsyncdata = ALLOCATE_LOCAL(mptr->n_hsync * sizeof(CARD32));
+    if (!hsyncdata) {
+       return BadAlloc;
+    }
+    vsyncdata = ALLOCATE_LOCAL(mptr->n_vrefresh * sizeof(CARD32));
+    if (!vsyncdata) {
+       DEALLOCATE_LOCAL(hsyncdata);
+       return BadAlloc;
+    }
+    for (i = 0; i < mptr->n_hsync; i++) {
+       hsyncdata[i] = (unsigned short)(mptr->hsync[i].lo * 100.0) |
+                      (unsigned short)(mptr->hsync[i].hi * 100.0) << 16;
+    }
+    for (i = 0; i < mptr->n_vrefresh; i++) {
+       vsyncdata[i] = (unsigned short)(mptr->vrefresh[i].lo * 100.0) |
+                      (unsigned short)(mptr->vrefresh[i].hi * 100.0) << 16;
+    }
+    
+    if (client->swapped) {
+       swaps(&rep.sequenceNumber, n);
+       swapl(&rep.length, n);
+#if 0
+       swapl(&rep.bandwidth, n);
+#endif
+    }
+    WriteToClient(client, SIZEOF(xXF86VidModeGetMonitorReply), (char *)&rep);
+    client->pSwapReplyFunc = (ReplySwapPtr) Swap32Write;
+    WriteSwappedDataToClient(client, mptr->n_hsync * sizeof(CARD32),
+                            hsyncdata);
+    WriteSwappedDataToClient(client, mptr->n_vrefresh * sizeof(CARD32),
+                            vsyncdata);
+    if (rep.vendorLength)
+       WriteToClient(client, rep.vendorLength, mptr->vendor);
+    if (rep.modelLength)
+       WriteToClient(client, rep.modelLength, mptr->model);
+    DEALLOCATE_LOCAL(hsyncdata);
+    DEALLOCATE_LOCAL(vsyncdata);
+    return (client->noClientException);
+}
+
+static int
+ProcXF86VidModeGetViewPort(client)
+    register ClientPtr client;
+{
+    REQUEST(xXF86VidModeGetViewPortReq);
+    xXF86VidModeGetViewPortReply rep;
+    ScrnInfoPtr vptr;
+    int n;
+
+    if (stuff->screen > screenInfo.numScreens)
+       return BadValue;
+
+    vptr = (ScrnInfoPtr) screenInfo.screens[stuff->screen]->devPrivates[xf86ScreenIndex].ptr;
+
+    REQUEST_SIZE_MATCH(xXF86VidModeGetViewPortReq);
+    rep.type = X_Reply;
+    rep.length = 0;
+    rep.sequenceNumber = client->sequence;
+    rep.x = vptr->frameX0;
+    rep.y = vptr->frameY0;
+
+    if (client->swapped) {
+       swaps(&rep.sequenceNumber, n);
+       swapl(&rep.length, n);
+       swapl(&rep.x, n);
+       swapl(&rep.y, n);
+    }
+    WriteToClient(client, SIZEOF(xXF86VidModeGetViewPortReply), (char *)&rep);
+    return (client->noClientException);
+}
+
+static int
+ProcXF86VidModeSetViewPort(client)
+    register ClientPtr client;
+{
+    REQUEST(xXF86VidModeSetViewPortReq);
+    ScrnInfoPtr vptr;
+    int x, y;
+
+    if (stuff->screen > screenInfo.numScreens)
+       return BadValue;
+
+    vptr = (ScrnInfoPtr) screenInfo.screens[stuff->screen]->devPrivates[xf86ScreenIndex].ptr;
+
+    REQUEST_SIZE_MATCH(xXF86VidModeSetViewPortReq);
+
+    if (stuff->x < 0)
+       x = 0;
+    else if (stuff->x + vptr->modes->HDisplay + 1 > vptr->virtualX)
+       x = vptr->virtualX - vptr->modes->HDisplay - 1;
+    else
+       x = stuff->x;
+
+    if (stuff->y < 0)
+       y = 0;
+    else if (stuff->y + vptr->modes->VDisplay + 1 > vptr->virtualY)
+       y = vptr->virtualY - vptr->modes->VDisplay - 1;
+    else
+       y = stuff->y;
+
+    if (vptr->AdjustFrame && xf86VTSema) {
+       vptr->AdjustFrame(x, y);
+       vptr->frameX0 = x;
+       vptr->frameX1 = x + vptr->modes->HDisplay - 1;
+       vptr->frameY0 = y;
+       vptr->frameY1 = y + vptr->modes->VDisplay - 1;
+    }
+    
+    return (client->noClientException);
+}
+
+
+static int
+ProcXF86VidModeDispatch (client)
+    register ClientPtr client;
+{
+    REQUEST(xReq);
+    switch (stuff->data)
+    {
+    case X_XF86VidModeQueryVersion:
+       return ProcXF86VidModeQueryVersion(client);
+    case X_XF86VidModeGetModeLine:
+       return ProcXF86VidModeGetModeLine(client);
+    case X_XF86VidModeGetAllModeLines:
+       return ProcXF86VidModeGetAllModeLines(client);
+    case X_XF86VidModeGetMonitor:
+       return ProcXF86VidModeGetMonitor(client);
+    case X_XF86VidModeValidateModeLine:
+       return ProcXF86VidModeValidateModeLine(client);
+    case X_XF86VidModeGetViewPort:
+       return ProcXF86VidModeGetViewPort(client);
+    default:
+       if (!xf86VidModeEnabled)
+           return vidmodeErrorBase + XF86VidModeExtensionDisabled;
+       if (xf86VidModeAllowNonLocal || LocalClient (client)) {
+           switch (stuff->data) {
+           case X_XF86VidModeAddModeLine:
+               return ProcXF86VidModeAddModeLine(client);
+           case X_XF86VidModeDeleteModeLine:
+               return ProcXF86VidModeDeleteModeLine(client);
+           case X_XF86VidModeModModeLine:
+               return ProcXF86VidModeModModeLine(client);
+           case X_XF86VidModeSwitchMode:
+               return ProcXF86VidModeSwitchMode(client);
+           case X_XF86VidModeSwitchToMode:
+               return ProcXF86VidModeSwitchToMode(client);
+           case X_XF86VidModeLockModeSwitch:
+               return ProcXF86VidModeLockModeSwitch(client);
+           case X_XF86VidModeSetViewPort:
+               return ProcXF86VidModeSetViewPort(client);
+           default:
+               return BadRequest;
+           }
+       } else
+           return vidmodeErrorBase + XF86VidModeClientNotLocal;
+    }
+}
+
+static int
+SProcXF86VidModeQueryVersion(client)
+    register ClientPtr client;
+{
+    register int n;
+    REQUEST(xXF86VidModeQueryVersionReq);
+    swaps(&stuff->length, n);
+    return ProcXF86VidModeQueryVersion(client);
+}
+
+static int
+SProcXF86VidModeGetModeLine(client)
+    ClientPtr client;
+{
+    register int n;
+    REQUEST(xXF86VidModeGetModeLineReq);
+    swaps(&stuff->length, n);
+    REQUEST_SIZE_MATCH(xXF86VidModeGetModeLineReq);
+    swaps(&stuff->screen, n);
+    return ProcXF86VidModeGetModeLine(client);
+}
+
+static int
+SProcXF86VidModeGetAllModeLines(client)
+    ClientPtr client;
+{
+    register int n;
+    REQUEST(xXF86VidModeGetAllModeLinesReq);
+    swaps(&stuff->length, n);
+    REQUEST_SIZE_MATCH(xXF86VidModeGetAllModeLinesReq);
+    swaps(&stuff->screen, n);
+    return ProcXF86VidModeGetAllModeLines(client);
+}
+
+static int
+SProcXF86VidModeAddModeLine(client)
+    ClientPtr client;
+{
+    register int n;
+    REQUEST(xXF86VidModeAddModeLineReq);
+    swaps(&stuff->length, n);
+    REQUEST_AT_LEAST_SIZE(xXF86VidModeAddModeLineReq);
+    swapl(&stuff->screen, n);
+    swaps(&stuff->hdisplay, n);
+    swaps(&stuff->hsyncstart, n);
+    swaps(&stuff->hsyncend, n);
+    swaps(&stuff->htotal, n);
+    swaps(&stuff->vdisplay, n);
+    swaps(&stuff->vsyncstart, n);
+    swaps(&stuff->vsyncend, n);
+    swaps(&stuff->vtotal, n);
+    swapl(&stuff->flags, n);
+    swapl(&stuff->privsize, n);
+    SwapRestL(stuff);
+    return ProcXF86VidModeAddModeLine(client);
+}
+
+static int
+SProcXF86VidModeDeleteModeLine(client)
+    ClientPtr client;
+{
+    register int n;
+    REQUEST(xXF86VidModeDeleteModeLineReq);
+    swaps(&stuff->length, n);
+    REQUEST_AT_LEAST_SIZE(xXF86VidModeDeleteModeLineReq);
+    swapl(&stuff->screen, n);
+    swaps(&stuff->hdisplay, n);
+    swaps(&stuff->hsyncstart, n);
+    swaps(&stuff->hsyncend, n);
+    swaps(&stuff->htotal, n);
+    swaps(&stuff->vdisplay, n);
+    swaps(&stuff->vsyncstart, n);
+    swaps(&stuff->vsyncend, n);
+    swaps(&stuff->vtotal, n);
+    swapl(&stuff->flags, n);
+    swapl(&stuff->privsize, n);
+    SwapRestL(stuff);
+    return ProcXF86VidModeDeleteModeLine(client);
+}
+
+static int
+SProcXF86VidModeModModeLine(client)
+    ClientPtr client;
+{
+    register int n;
+    REQUEST(xXF86VidModeModModeLineReq);
+    swaps(&stuff->length, n);
+    REQUEST_AT_LEAST_SIZE(xXF86VidModeModModeLineReq);
+    swapl(&stuff->screen, n);
+    swaps(&stuff->hdisplay, n);
+    swaps(&stuff->hsyncstart, n);
+    swaps(&stuff->hsyncend, n);
+    swaps(&stuff->htotal, n);
+    swaps(&stuff->vdisplay, n);
+    swaps(&stuff->vsyncstart, n);
+    swaps(&stuff->vsyncend, n);
+    swaps(&stuff->vtotal, n);
+    swapl(&stuff->flags, n);
+    swapl(&stuff->privsize, n);
+    SwapRestL(stuff);
+    return ProcXF86VidModeModModeLine(client);
+}
+
+static int
+SProcXF86VidModeValidateModeLine(client)
+    ClientPtr client;
+{
+    register int n;
+    REQUEST(xXF86VidModeValidateModeLineReq);
+    swaps(&stuff->length, n);
+    REQUEST_AT_LEAST_SIZE(xXF86VidModeValidateModeLineReq);
+    swapl(&stuff->screen, n);
+    swaps(&stuff->hdisplay, n);
+    swaps(&stuff->hsyncstart, n);
+    swaps(&stuff->hsyncend, n);
+    swaps(&stuff->htotal, n);
+    swaps(&stuff->vdisplay, n);
+    swaps(&stuff->vsyncstart, n);
+    swaps(&stuff->vsyncend, n);
+    swaps(&stuff->vtotal, n);
+    swapl(&stuff->flags, n);
+    swapl(&stuff->privsize, n);
+    SwapRestL(stuff);
+    return ProcXF86VidModeValidateModeLine(client);
+}
+
+static int
+SProcXF86VidModeSwitchMode(client)
+    ClientPtr client;
+{
+    register int n;
+    REQUEST(xXF86VidModeSwitchModeReq);
+    swaps(&stuff->length, n);
+    REQUEST_SIZE_MATCH(xXF86VidModeSwitchModeReq);
+    swaps(&stuff->screen, n);
+    swaps(&stuff->zoom, n);
+    return ProcXF86VidModeSwitchMode(client);
+}
+
+static int
+SProcXF86VidModeSwitchToMode(client)
+    ClientPtr client;
+{
+    register int n;
+    REQUEST(xXF86VidModeSwitchToModeReq);
+    swaps(&stuff->length, n);
+    REQUEST_SIZE_MATCH(xXF86VidModeSwitchToModeReq);
+    swaps(&stuff->screen, n);
+    return ProcXF86VidModeSwitchToMode(client);
+}
+
+static int
+SProcXF86VidModeLockModeSwitch(client)
+    ClientPtr client;
+{
+    register int n;
+    REQUEST(xXF86VidModeLockModeSwitchReq);
+    swaps(&stuff->length, n);
+    REQUEST_SIZE_MATCH(xXF86VidModeLockModeSwitchReq);
+    swaps(&stuff->screen, n);
+    swaps(&stuff->lock, n);
+    return ProcXF86VidModeLockModeSwitch(client);
+}
+
+static int
+SProcXF86VidModeGetMonitor(client)
+    ClientPtr client;
+{
+    register int n;
+    REQUEST(xXF86VidModeGetMonitorReq);
+    swaps(&stuff->length, n);
+    REQUEST_SIZE_MATCH(xXF86VidModeGetMonitorReq);
+    swaps(&stuff->screen, n);
+    return ProcXF86VidModeGetMonitor(client);
+}
+
+static int
+SProcXF86VidModeGetViewPort(client)
+    ClientPtr client;
+{
+    register int n;
+    REQUEST(xXF86VidModeGetViewPortReq);
+    swaps(&stuff->length, n);
+    REQUEST_SIZE_MATCH(xXF86VidModeGetViewPortReq);
+    swaps(&stuff->screen, n);
+    return ProcXF86VidModeGetViewPort(client);
+}
+
+static int
+SProcXF86VidModeSetViewPort(client)
+    ClientPtr client;
+{
+    register int n;
+    REQUEST(xXF86VidModeSetViewPortReq);
+    swaps(&stuff->length, n);
+    REQUEST_SIZE_MATCH(xXF86VidModeSetViewPortReq);
+    swaps(&stuff->screen, n);
+    swapl(&stuff->x, n);
+    swapl(&stuff->y, n);
+    return ProcXF86VidModeSetViewPort(client);
+}
+
+static int
+SProcXF86VidModeDispatch (client)
+    register ClientPtr client;
+{
+    REQUEST(xReq);
+    switch (stuff->data)
+    {
+    case X_XF86VidModeQueryVersion:
+       return SProcXF86VidModeQueryVersion(client);
+    case X_XF86VidModeGetModeLine:
+       return SProcXF86VidModeGetModeLine(client);
+    case X_XF86VidModeGetAllModeLines:
+       return SProcXF86VidModeGetAllModeLines(client);
+    case X_XF86VidModeGetMonitor:
+       return SProcXF86VidModeGetMonitor(client);
+    case X_XF86VidModeGetViewPort:
+       return SProcXF86VidModeGetViewPort(client);
+    case X_XF86VidModeValidateModeLine:
+       return SProcXF86VidModeValidateModeLine(client);
+    default:
+       if (!xf86VidModeEnabled)
+           return vidmodeErrorBase + XF86VidModeExtensionDisabled;
+       if (xf86VidModeAllowNonLocal || LocalClient(client)) {
+           switch (stuff->data) {
+           case X_XF86VidModeAddModeLine:
+               return SProcXF86VidModeAddModeLine(client);
+           case X_XF86VidModeDeleteModeLine:
+               return SProcXF86VidModeDeleteModeLine(client);
+           case X_XF86VidModeModModeLine:
+               return SProcXF86VidModeModModeLine(client);
+           case X_XF86VidModeSwitchMode:
+               return SProcXF86VidModeSwitchMode(client);
+           case X_XF86VidModeSwitchToMode:
+               return SProcXF86VidModeSwitchToMode(client);
+           case X_XF86VidModeLockModeSwitch:
+               return SProcXF86VidModeLockModeSwitch(client);
+           case X_XF86VidModeSetViewPort:
+               return SProcXF86VidModeSetViewPort(client);
+           default:
+               return BadRequest;
+           }
+       } else
+           return vidmodeErrorBase + XF86VidModeClientNotLocal;
+    }
+}
diff --git a/Xserver/programs/Xserver/Xext/xprint.c b/Xserver/programs/Xserver/Xext/xprint.c
new file mode 100644 (file)
index 0000000..829a8f3
--- /dev/null
@@ -0,0 +1,2873 @@
+/* $XConsortium: xprint.c /main/3 1996/11/23 17:11:55 rws $ */
+/*
+(c) Copyright 1996 Hewlett-Packard Company
+(c) Copyright 1996 International Business Machines Corp.
+(c) Copyright 1996 Sun Microsystems, Inc.
+(c) Copyright 1996 Novell, Inc.
+(c) Copyright 1996 Digital Equipment Corp.
+(c) Copyright 1996 Fujitsu Limited
+(c) Copyright 1996 Hitachi, Ltd.
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
+IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the names of the copyright holders shall
+not be used in advertising or otherwise to promote the sale, use or other
+dealings in this Software without prior written authorization from said
+copyright holders.
+*/
+/*******************************************************************
+**
+**    *********************************************************
+**    *
+**    *  File:          xprint.c
+**    *
+**    *  Copyright:     Copyright 1993, 1995 Hewlett-Packard Company
+**    *
+**    *                Copyright 1989 by The Massachusetts Institute of Technology
+**    *
+**    *                Permission to use, copy, modify, and distribute this
+**    *                software and its documentation for any purpose and without
+**    *                fee is hereby granted, provided that the above copyright
+**    *                notice appear in all copies and that both that copyright
+**    *                notice and this permission notice appear in supporting
+**    *                documentation, and that the name of MIT not be used in
+**    *                advertising or publicity pertaining to distribution of the
+**    *                software without specific prior written permission.
+**    *                M.I.T. makes no representation about the suitability of
+**    *                this software for any purpose. It is provided "as is"
+**    *                without any express or implied warranty.
+**    *
+**    *                MIT DISCLAIMS ALL WARRANTIES WITH REGARD TO  THIS  SOFTWARE,
+**    *                INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FIT-
+**    *                NESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MIT BE  LI-
+**    *                ABLE  FOR  ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
+**    *                ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,  DATA  OR
+**    *                PROFITS,  WHETHER  IN  AN  ACTION OF CONTRACT, NEGLIGENCE OR
+**    *                OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION  WITH
+**    *                THE USE OR PERFORMANCE OF THIS SOFTWARE.
+**    *
+**    *********************************************************
+**
+********************************************************************/
+/* $XFree86: xc/programs/Xserver/Xext/xprint.c,v 1.4 1997/01/02 04:05:05 dawes Exp $ */
+
+#include "X.h"
+#define NEED_EVENTS
+#include "Xproto.h"
+#undef NEED_EVENTS
+#include "misc.h"
+#include "windowstr.h"
+#include "scrnintstr.h"
+#include "pixmapstr.h"
+#include "extnsionst.h"
+#include "dixstruct.h"
+#include "Xatom.h"
+#define _XP_PRINT_SERVER_
+#include "Print.h"
+#include "Printstr.h"
+#undef _XP_PRINT_SERVER_
+#include "../Xprint/DiPrint.h"
+
+extern WindowPtr *WindowTable; /* declared in dix:globals.c */
+
+extern WindowPtr XpDiValidatePrinter();
+extern char *XpDiGetDriverName();
+extern char *XpGetAttributes();
+extern char *XpGetOneAttribute();
+extern int XpRehashPrinterList();
+extern void XpSetFontResFunc();
+
+static void XpResetProc();
+
+static int ProcXpDispatch();
+static int ProcXpSwappedDispatch();
+
+static int ProcXpQueryVersion();
+static int ProcXpGetPrinterList();
+static int ProcXpCreateContext();
+static int ProcXpSetContext();
+static int ProcXpGetContext();
+static int ProcXpDestroyContext();
+static int ProcXpGetContextScreen();
+static int ProcXpStartJob();
+static int ProcXpEndJob();
+static int ProcXpStartDoc();
+static int ProcXpEndDoc();
+static int ProcXpStartPage();
+static int ProcXpEndPage();
+static int ProcXpSelectInput();
+static int ProcXpInputSelected();
+static int ProcXpPutDocumentData();
+static int ProcXpGetDocumentData();
+static int ProcXpGetAttributes();
+static int ProcXpGetOneAttribute();
+static int ProcXpSetAttributes();
+static int ProcXpRehashPrinterList();
+static int ProcXpQueryScreens();
+static int ProcXpGetPageDimensions();
+static int ProcXpSetImageResolution();
+static int ProcXpGetImageResolution();
+
+static void SwapXpNotifyEvent();
+static void SwapXpAttributeEvent();
+
+static int SProcXpGetPrinterList();
+static int SProcXpCreateContext();
+static int SProcXpSetContext();
+static int SProcXpGetContext();
+static int SProcXpDestroyContext();
+static int SProcXpGetContextScreen();
+static int SProcXpStartJob();
+static int SProcXpEndJob();
+static int SProcXpStartDoc();
+static int SProcXpEndDoc();
+static int SProcXpStartPage();
+static int SProcXpEndPage();
+static int SProcXpSelectInput();
+static int SProcXpInputSelected();
+static int SProcXpPutDocumentData();
+static int SProcXpGetDocumentData();
+static int SProcXpGetAttributes();
+static int SProcXpGetOneAttribute();
+static int SProcXpSetAttributes();
+static int SProcXpRehashPrinterList();
+static int SProcXpGetPageDimensions();
+static int SProcXpSetImageResolution();
+static int SProcXpGetImageResolution();
+
+static void SendXpNotify();
+static void SendAttributeNotify();
+static int XpFreeClient();
+static int XpFreeContext();
+static int XpFreePage();
+static int XpFreeEvents();
+static Bool XpCloseScreen();
+static CARD32 GetAllEventMasks();
+static struct _XpEvent *AddEventRec();
+static void DeleteEventRec();
+static struct _XpEvent *FindEventRec();
+static struct _XpClient *CreateXpClient();
+static void FreeXpClient();
+static void InitContextPrivates();
+static void ResetContextPrivates();
+static struct _XpClient *FindClient();
+static struct _XpClient *AcquireClient();
+
+typedef struct _driver {
+    struct _driver *next;
+    char *name;
+    int (* CreateContext)();
+} XpDriverRec, *XpDriverPtr;
+
+typedef struct  _xpScreen {
+    Bool (* CloseScreen)();
+    struct _driver *drivers;
+} XpScreenRec, *XpScreenPtr;
+
+/*
+ * Each context has a list of XpClients indicating which clients have
+ * associated this context with their connection.
+ * Each such client has a RTclient resource allocated for it,
+ * and this per-client
+ * resource is used to delete the XpClientRec if/when the client closes
+ * its connection.
+ * The list of XpClients is also walked if/when the context is destroyed
+ * so that the ContextPtr can be removed from the client's devPrivates.
+ */
+typedef struct _XpClient {
+       struct _XpClient *pNext;
+       ClientPtr       client;
+       XpContextPtr    context;
+       CARD32          eventMask;
+       XID             contextClientID; /* unneeded sanity check? */
+} XpClientRec, *XpClientPtr;
+
+/*
+ * Each StartPage request specifies a window which forms the top level
+ * window of the page.  One of the following structs is created as a
+ * RTpage resource with the same ID as the window itself.  This enables 
+ * us to clean up when/if the window is destroyed, and to prevent the
+ * same window from being simultaneously referenced in multiple contexts.
+ * The page resource is created at the first StartPage on a given window,
+ * and is only destroyed when/if the window is destroyed.  When the
+ * EndPage is recieved (or an EndDoc or EndJob) the context field is
+ * set to NULL, but the resource remains alive.
+ */
+typedef struct _XpPage {
+       XpContextPtr    context;
+} XpPageRec, *XpPagePtr;
+
+typedef struct _XpStPageRec {
+    XpContextPtr pContext;
+    Bool slept;
+    XpPagePtr pPage;
+    WindowPtr pWin;
+} XpStPageRec, *XpStPagePtr;
+
+typedef struct _XpStDocRec {
+    XpContextPtr pContext;
+    Bool slept;
+    CARD8 type;
+} XpStDocRec, *XpStDocPtr;
+
+#define QUADPAD(x) ((((x)+3)>>2)<<2)
+
+/*
+ * Possible bit-mask values in the "state" field of a XpContextRec.
+ */
+#define JOB_STARTED (1 << 0)
+#define DOC_RAW_STARTED (1 << 1)
+#define DOC_COOKED_STARTED (1 << 2)
+#define PAGE_STARTED (1 << 3)
+#define GET_DOC_DATA_STARTED (1 << 4)
+#define JOB_GET_DATA (1 << 5)
+    
+static XpScreenPtr XpScreens[MAXSCREENS];
+static unsigned char XpReqCode;
+static int XpEventBase;
+static int XpErrorBase;
+static int XpGeneration = 0;
+static int XpWindowPrivateIndex;
+static int XpClientPrivateIndex;
+
+/* Variables for the context private machinery. 
+ * These must be initialized at compile time because
+ * main() calls InitOutput before InitExtensions, and the
+ * output drivers are likely to call AllocateContextPrivate.
+ * These variables are reset at CloseScreen time.  CloseScreen
+ * is used because it occurs after FreeAllResources, and before
+ * the next InitOutput cycle.
+ */
+static int  contextPrivateCount = 0;
+static int contextPrivateLen = 0;
+static unsigned *contextPrivateSizes = (unsigned *)NULL;
+static unsigned totalContextSize = sizeof(XpContextRec);
+
+/*
+ * There are three types of resources involved.  One is the resource associated
+ * with the context itself, with an ID specified by a printing client.  The
+ * next is a resource created by us on the client's behalf (and unknown to
+ * the client) when a client inits or sets a context which allows us to 
+ * track each client's interest in events
+ * on a particular context, and also allows us to clean up this interest
+ * record when/if the client's connection is closed.  Finally, there is
+ * a resource created for each window that's specified in a StartPage.  This
+ * resource carries the same ID as the window itself, and enables us to
+ * easily prevent the same window being referenced in multiple contexts
+ * simultaneously, and enables us to clean up if the window is destroyed
+ * before the EndPage.
+ */
+static RESTYPE RTclient, RTcontext, RTpage;
+
+/*
+ * allEvents is the OR of all the legal event mask bits.
+ */
+static CARD32 allEvents = XPPrintMask | XPAttributeMask;
+
+
+/*******************************************************************************
+ *
+ * ExtensionInit, Driver Init functions, QueryVersion, and Dispatch procs
+ *
+ ******************************************************************************/
+
+/*
+ * XpExtensionInit
+ *
+ * Called from InitExtensions in main() usually through miinitextension
+ *
+ */
+
+void
+XpExtensionInit()
+{
+    ExtensionEntry *extEntry, *AddExtension();
+    int i;
+
+    RTclient = CreateNewResourceType(XpFreeClient);
+    RTcontext = CreateNewResourceType(XpFreeContext);
+    RTpage = CreateNewResourceType(XpFreePage);
+    if (RTclient && RTcontext && RTpage &&
+        (extEntry = AddExtension(XP_PRINTNAME, XP_EVENTS, XP_ERRORS,
+                               ProcXpDispatch, ProcXpSwappedDispatch,
+                               XpResetProc, StandardMinorOpcode)))
+    {
+        XpReqCode = (unsigned char)extEntry->base;
+        XpEventBase = extEntry->eventBase;
+        XpErrorBase = extEntry->errorBase;
+        EventSwapVector[XpEventBase] = SwapXpNotifyEvent;
+        EventSwapVector[XpEventBase+1] = SwapXpAttributeEvent;
+    }
+
+    if(XpGeneration != serverGeneration)
+    {
+       XpClientPrivateIndex = AllocateClientPrivateIndex();
+       /*
+        * We allocate 0 length & simply stuff a pointer to the
+        * ContextRec in the DevUnion.
+        */
+       if(AllocateClientPrivate(XpClientPrivateIndex, 0) != TRUE)
+       {
+               /* we can't alloc a client private, should we bail??? XXX */
+       }
+       XpGeneration = serverGeneration;
+    }
+
+    for(i = 0; i < MAXSCREENS; i++)
+    {
+       /*
+        * If a screen has registered with our extension, then we
+        * wrap the screen's CloseScreen function to allow us to
+        * reset our ContextPrivate stuff.  Note that this
+        * requires a printing DDX to call XpRegisterInitFunc
+        * _before_ this extension is initialized - i.e. at screen init
+        * time, _not_ at root window creation time.
+        */
+       if(XpScreens[i] != (XpScreenPtr)NULL)
+       {
+           XpScreens[i]->CloseScreen = screenInfo.screens[i]->CloseScreen;
+           screenInfo.screens[i]->CloseScreen = XpCloseScreen;
+       }
+    }
+    DeclareExtensionSecurity(XP_PRINTNAME, TRUE);
+}
+
+static void
+XpResetProc(extEntry)
+    ExtensionEntry extEntry;
+{
+    int i;
+
+    /*
+     * We can't free up the XpScreens recs here, because extensions are
+     * closed before screens, and our CloseScreen function uses the XpScreens
+     * recs.
+    for(i = 0; i < MAXSCREENS; i++)
+    {
+       if(XpScreens[i] != (XpScreenPtr)NULL)
+           Xfree(XpScreens[i]);
+       XpScreens[i] = (XpScreenPtr)NULL;
+    }
+    */
+}
+
+static Bool
+XpCloseScreen(index, pScreen)
+    int index;
+    ScreenPtr pScreen;
+{
+    Bool (* CloseScreen)();
+
+    CloseScreen = XpScreens[index]->CloseScreen;
+    if(XpScreens[index] != (XpScreenPtr)NULL)
+    {
+       XpDriverPtr pDriv, nextDriv;
+
+       pDriv = XpScreens[index]->drivers;
+       while(pDriv != (XpDriverPtr)NULL)
+       {
+           nextDriv = pDriv->next;
+            Xfree(pDriv);
+           pDriv = nextDriv;
+       }
+       Xfree(XpScreens[index]);
+    }
+    XpScreens[index] = (XpScreenPtr)NULL;
+
+    /*
+     * It's wasteful to call ResetContextPrivates() at every CloseScreen, 
+     * but it's the best we know how to do for now.  We do this because we
+     * have to wait until after all resources have been freed (so we know
+     * how to free the ContextRecs), and before the next InitOutput cycle.
+     * See dix/main.c for the order of initialization and reset.
+     */
+    ResetContextPrivates();
+    return (*CloseScreen)(index, pScreen);
+}
+
+static void
+FreeScreenEntry(pScreenEntry)
+    XpScreenPtr pScreenEntry;
+{
+    XpDriverPtr pDriver;
+
+    pDriver = pScreenEntry->drivers; 
+    while(pDriver != (XpDriverPtr)NULL)
+    {
+       XpDriverPtr tmp;
+
+       tmp = pDriver->next;
+       xfree(pDriver);
+       pDriver = tmp;
+    }
+    xfree(pScreenEntry);
+}
+
+/*
+ * XpRegisterInitFunc tells the print extension which screens
+ * are printers as opposed to displays, and what drivers are
+ * supported on each screen.  This eliminates the need of
+ * allocating print-related private structures on windows on _all_ screens.
+ * It also hands the extension a pointer to the routine to be called
+ * whenever a context gets created for a particular driver on this screen.
+ */
+void
+XpRegisterInitFunc(pScreen, driverName, initContext)
+    ScreenPtr pScreen;
+    char *driverName;
+    int (*initContext)();
+{
+    XpDriverPtr pDriver;
+
+    if(XpScreens[pScreen->myNum] == (XpScreenPtr)NULL)
+    {
+        if((XpScreens[pScreen->myNum] =
+           (XpScreenPtr) Xalloc(sizeof(XpScreenRec))) == (XpScreenPtr)NULL)
+            return;
+       XpScreens[pScreen->myNum]->CloseScreen = (Bool(*)())NULL;
+       XpScreens[pScreen->myNum]->drivers = (XpDriverPtr)NULL;
+    }
+
+    if((pDriver = (XpDriverPtr)Xalloc(sizeof(XpDriverRec))) == 
+       (XpDriverPtr)NULL)
+       return;
+    pDriver->next = XpScreens[pScreen->myNum]->drivers;
+    pDriver->name = driverName;
+    pDriver->CreateContext = initContext;
+    XpScreens[pScreen->myNum]->drivers = pDriver;
+}
+
+static int 
+ProcXpDispatch(client)
+    ClientPtr client;
+{
+    REQUEST(xReq);
+
+    switch(stuff->data)
+    {
+       case X_PrintQueryVersion:
+            return ProcXpQueryVersion(client);
+       case X_PrintGetPrinterList:
+           return ProcXpGetPrinterList(client);
+       case X_PrintCreateContext:
+           return ProcXpCreateContext(client);
+       case X_PrintSetContext:
+           return ProcXpSetContext(client);
+       case X_PrintGetContext:
+           return ProcXpGetContext(client);
+       case X_PrintDestroyContext:
+           return ProcXpDestroyContext(client);
+       case X_PrintGetContextScreen:
+           return ProcXpGetContextScreen(client);
+       case X_PrintStartJob:
+            return ProcXpStartJob(client);
+       case X_PrintEndJob:
+            return ProcXpEndJob(client);
+       case X_PrintStartDoc:
+            return ProcXpStartDoc(client);
+       case X_PrintEndDoc:
+            return ProcXpEndDoc(client);
+       case X_PrintStartPage:
+            return ProcXpStartPage(client);
+       case X_PrintEndPage:
+            return ProcXpEndPage(client);
+       case X_PrintSelectInput:
+            return ProcXpSelectInput(client);
+       case X_PrintInputSelected:
+            return ProcXpInputSelected(client);
+       case X_PrintPutDocumentData:
+            return ProcXpPutDocumentData(client);
+       case X_PrintGetDocumentData:
+            return ProcXpGetDocumentData(client);
+       case X_PrintSetAttributes:
+           return ProcXpSetAttributes(client);
+       case X_PrintGetAttributes:
+           return ProcXpGetAttributes(client);
+       case X_PrintGetOneAttribute:
+           return ProcXpGetOneAttribute(client);
+       case X_PrintRehashPrinterList:
+           return ProcXpRehashPrinterList(client);
+       case X_PrintQueryScreens:
+            return ProcXpQueryScreens(client);
+       case X_PrintGetPageDimensions:
+            return ProcXpGetPageDimensions(client);
+       case X_PrintSetImageResolution:
+            return ProcXpSetImageResolution(client);
+       case X_PrintGetImageResolution:
+            return ProcXpGetImageResolution(client);
+       default:
+           return BadRequest;
+    }
+}
+
+static int 
+ProcXpSwappedDispatch(client)
+    ClientPtr client;
+{
+    int temp;
+    REQUEST(xReq);
+
+    switch(stuff->data)
+    {
+       case X_PrintQueryVersion:
+           swaps(&stuff->length, temp);
+            return ProcXpQueryVersion(client);
+       case X_PrintGetPrinterList:
+           return SProcXpGetPrinterList(client);
+       case X_PrintCreateContext:
+           return SProcXpCreateContext(client);
+       case X_PrintSetContext:
+           return SProcXpSetContext(client);
+       case X_PrintGetContext:
+           return SProcXpGetContext(client);
+       case X_PrintDestroyContext:
+           return SProcXpDestroyContext(client);
+       case X_PrintGetContextScreen:
+           return SProcXpGetContextScreen(client);
+       case X_PrintStartJob:
+            return SProcXpStartJob(client);
+       case X_PrintEndJob:
+            return SProcXpEndJob(client);
+       case X_PrintStartDoc:
+            return SProcXpStartDoc(client);
+       case X_PrintEndDoc:
+            return SProcXpEndDoc(client);
+       case X_PrintStartPage:
+            return SProcXpStartPage(client);
+       case X_PrintEndPage:
+            return SProcXpEndPage(client);
+       case X_PrintSelectInput:
+           return SProcXpSelectInput(client);
+       case X_PrintInputSelected:
+           return SProcXpInputSelected(client);
+       case X_PrintPutDocumentData:
+            return SProcXpPutDocumentData(client);
+       case X_PrintGetDocumentData:
+            return SProcXpGetDocumentData(client);
+       case X_PrintSetAttributes:
+           return SProcXpSetAttributes(client);
+       case X_PrintGetAttributes:
+           return SProcXpGetAttributes(client);
+       case X_PrintGetOneAttribute:
+           return SProcXpGetOneAttribute(client);
+       case X_PrintRehashPrinterList:
+           return SProcXpRehashPrinterList(client);
+       case X_PrintQueryScreens:
+           swaps(&stuff->length, temp);
+            return ProcXpQueryScreens(client);
+       case X_PrintGetPageDimensions:
+            return SProcXpGetPageDimensions(client);
+       case X_PrintSetImageResolution:
+            return SProcXpSetImageResolution(client);
+       case X_PrintGetImageResolution:
+            return SProcXpGetImageResolution(client);
+       default:
+           return BadRequest;
+    }
+}
+
+static int
+ProcXpQueryVersion(client)
+    ClientPtr client;
+{
+    REQUEST(xPrintQueryVersionReq);
+    xPrintQueryVersionReply rep;
+    register int n;
+    long l;
+
+    REQUEST_SIZE_MATCH(xPrintQueryVersionReq);
+    rep.type = X_Reply;
+    rep.length = 0;
+    rep.sequenceNumber = client->sequence;
+    rep.majorVersion = XP_MAJOR_VERSION;
+    rep.minorVersion = XP_MINOR_VERSION;
+    if (client->swapped) {
+        swaps(&rep.sequenceNumber, n);
+        swapl(&rep.length, l);
+        swaps(&rep.majorVersion, n);
+        swaps(&rep.minorVersion, n);
+    }
+    WriteToClient(client, sz_xPrintQueryVersionReply, (char *)&rep);
+    return client->noClientException;
+}
+
+/*******************************************************************************
+ *
+ * GetPrinterList : Return a list of all printers associated with this
+ *                  server.  Calls XpDiGetPrinterList, which is defined in
+ *                 the device-independent code in Xserver/Xprint.
+ *
+ ******************************************************************************/
+
+static int
+ProcXpGetPrinterList(client)
+    ClientPtr client;
+{
+    REQUEST(xPrintGetPrinterListReq);
+    int totalSize, numEntries;
+    XpDiListEntry **pList, *pEntry;
+    xPrintGetPrinterListReply *rep;
+    int n, i, totalBytes;
+    long l;
+    char *curByte;
+
+    REQUEST_AT_LEAST_SIZE(xPrintGetPrinterListReq);
+
+    totalSize = ((sz_xPrintGetPrinterListReq) >> 2) +
+                ((stuff->printerNameLen + 3) >> 2) +
+                ((stuff->localeLen + 3) >> 2);
+    if(totalSize != client->req_len)
+        return BadLength;
+
+    pList = XpDiGetPrinterList(stuff->printerNameLen, (char *)(stuff + 1), 
+                              stuff->localeLen, (char *)((stuff + 1) + 
+                              QUADPAD(stuff->printerNameLen)));
+
+    for(numEntries = 0, totalBytes = sz_xPrintGetPrinterListReply;
+       pList[numEntries] != (XpDiListEntry *)NULL;
+       numEntries++)
+    {
+       totalBytes += 2 * sizeof(CARD32); 
+       totalBytes += QUADPAD(strlen(pList[numEntries]->name));
+       totalBytes += QUADPAD(strlen(pList[numEntries]->description));
+    }
+
+    if((rep = (xPrintGetPrinterListReply *)xalloc(totalBytes)) == 
+       (xPrintGetPrinterListReply *)NULL)
+       return BadAlloc;
+
+    rep->type = X_Reply;
+    rep->length = (totalBytes - sz_xPrintGetPrinterListReply) >> 2;
+    rep->sequenceNumber = client->sequence;
+    rep->listCount = numEntries;
+    if (client->swapped) {
+        swaps(&rep->sequenceNumber, n);
+        swapl(&rep->length, l);
+        swapl(&rep->listCount, l);
+    }
+
+    for(i = 0, curByte = (char *)(rep + 1); i < numEntries; i++)
+    {
+       CARD32 *pCrd;
+       int len;
+
+       pCrd = (CARD32 *)curByte;
+       len = strlen(pList[i]->name);
+       *pCrd = len;
+        if (client->swapped)
+            swapl((long *)curByte, l);
+       curByte += sizeof(CARD32);
+       strncpy(curByte, pList[i]->name, len);
+       curByte += QUADPAD(len);
+
+       pCrd = (CARD32 *)curByte;
+       len = strlen(pList[i]->description);
+       *pCrd = len;
+        if (client->swapped)
+            swapl((long *)curByte, l);
+       curByte += sizeof(CARD32);
+       strncpy(curByte, pList[i]->description, len);
+       curByte += QUADPAD(len);
+    }
+
+    XpDiFreePrinterList(pList);
+
+    WriteToClient(client, totalBytes, (char *)rep);
+    xfree(rep);
+    return client->noClientException;
+}
+
+/*******************************************************************************
+ *
+ * QueryScreens: Returns the list of screens which are associated with
+ *               print drivers.
+ *
+ ******************************************************************************/
+
+static int
+ProcXpQueryScreens(client)
+    ClientPtr client;
+{
+    REQUEST(xPrintQueryScreensReq);
+    int i, numPrintScreens, totalSize;
+    WINDOW *pWinId;
+    xPrintQueryScreensReply *rep;
+    long l;
+
+    REQUEST_SIZE_MATCH(xPrintQueryScreensReq);
+
+    rep = (xPrintQueryScreensReply *)xalloc(sz_xPrintQueryScreensReply);
+    pWinId = (WINDOW *)(rep + 1);
+
+    for(i = 0, numPrintScreens = 0, totalSize = sz_xPrintQueryScreensReply; 
+       i < MAXSCREENS; i++)
+    {
+       /*
+        * If a screen has registered with our extension, then it's
+        * a printer screen.
+        */
+       if(XpScreens[i] != (XpScreenPtr)NULL)
+       {
+           numPrintScreens++;
+           totalSize += sizeof(WINDOW);
+           rep = (xPrintQueryScreensReply *)xrealloc(rep, totalSize);
+           *pWinId = WindowTable[i]->drawable.id;
+            if (client->swapped)
+                swapl((long *)pWinId, l);
+           pWinId++;
+       }
+    }
+
+    rep->type = X_Reply;
+    rep->sequenceNumber = client->sequence;
+    rep->length = (totalSize - sz_xPrintQueryScreensReply) >> 2;
+    rep->listCount = numPrintScreens;
+    if (client->swapped)
+    {
+       int n;
+
+        swaps(&rep->sequenceNumber, n);
+        swapl(&rep->length, l);
+        swapl(&rep->listCount, l);
+    }
+
+    WriteToClient(client, totalSize, (char *)rep);
+    xfree(rep);
+    return client->noClientException;
+}
+
+static int 
+ProcXpGetPageDimensions(client)
+    ClientPtr client;
+{
+    REQUEST(xPrintGetPageDimensionsReq);
+    CARD16 width, height;
+    xRectangle rect;
+    xPrintGetPageDimensionsReply rep;
+    XpContextPtr pContext;
+    int result;
+
+    REQUEST_SIZE_MATCH(xPrintGetPageDimensionsReq);
+
+    if((pContext =(XpContextPtr)SecurityLookupIDByType(client,
+                                                      stuff->printContext,
+                                                      RTcontext,
+                                                      SecurityReadAccess))
+       == (XpContextPtr)NULL)
+    {
+       client->errorValue = stuff->printContext;
+        return XpErrorBase+XPBadContext;
+    }
+
+    if(pContext->funcs.GetMediumDimensions != (int (*)())NULL)
+        result = pContext->funcs.GetMediumDimensions(pContext, &width, &height);
+    else
+        return BadImplementation;
+
+    if(pContext->funcs.GetReproducibleArea != (int (*)())NULL)
+        result = pContext->funcs.GetReproducibleArea(pContext, &rect);
+    else
+        return BadImplementation;
+
+    rep.type = X_Reply;
+    rep.sequenceNumber = client->sequence;
+    rep.length = 0;
+    rep.width = width;
+    rep.height = height;
+    rep.rx = rect.x;
+    rep.ry = rect.y;
+    rep.rwidth = rect.width;
+    rep.rheight = rect.height;
+
+    if(client->swapped)
+    {
+       int n;
+       long l;
+
+        swaps(&rep.sequenceNumber, n);
+        swapl(&rep.length, l);
+        swaps(&rep.width, n);
+        swaps(&rep.height, n);
+        swaps(&rep.rx, n);
+        swaps(&rep.ry, n);
+        swaps(&rep.rwidth, n);
+        swaps(&rep.rheight, n);
+    }
+
+    WriteToClient(client, sz_xPrintGetPageDimensionsReply, (char *)&rep);
+    return client->noClientException;
+}
+
+static int 
+ProcXpSetImageResolution(client)
+    ClientPtr client;
+{
+    REQUEST(xPrintSetImageResolutionReq);
+    xPrintSetImageResolutionReply rep;
+    XpContextPtr pContext;
+    Bool status;
+    int result;
+
+    REQUEST_SIZE_MATCH(xPrintSetImageResolutionReq);
+
+    if((pContext =(XpContextPtr)SecurityLookupIDByType(client,
+                                                      stuff->printContext,
+                                                      RTcontext,
+                                                      SecurityWriteAccess))
+       == (XpContextPtr)NULL)
+    {
+       client->errorValue = stuff->printContext;
+        return XpErrorBase+XPBadContext;
+    }
+
+    rep.prevRes = pContext->imageRes;
+    if(pContext->funcs.SetImageResolution != (int (*)())NULL)
+        result = pContext->funcs.SetImageResolution(pContext,
+                                                   (int)stuff->imageRes,
+                                                   &status);
+    else
+        status = FALSE;
+
+    rep.type = X_Reply;
+    rep.sequenceNumber = client->sequence;
+    rep.length = 0;
+    rep.status = status;
+
+    if(client->swapped)
+    {
+       int n;
+       long l;
+
+        swaps(&rep.sequenceNumber, n);
+        swapl(&rep.length, l);
+        swaps(&rep.prevRes, n);
+    }
+
+    WriteToClient(client, sz_xPrintSetImageResolutionReply, (char *)&rep);
+    return client->noClientException;
+}
+
+static int 
+ProcXpGetImageResolution(client)
+    ClientPtr client;
+{
+    REQUEST(xPrintGetImageResolutionReq);
+    xPrintGetImageResolutionReply rep;
+    XpContextPtr pContext;
+    Bool status;
+    int result;
+
+    REQUEST_SIZE_MATCH(xPrintGetImageResolutionReq);
+
+    if((pContext =(XpContextPtr)SecurityLookupIDByType(client,
+                                                      stuff->printContext,
+                                                      RTcontext,
+                                                      SecurityReadAccess))
+       == (XpContextPtr)NULL)
+    {
+       client->errorValue = stuff->printContext;
+        return XpErrorBase+XPBadContext;
+    }
+
+    rep.type = X_Reply;
+    rep.sequenceNumber = client->sequence;
+    rep.length = 0;
+    rep.imageRes = pContext->imageRes;
+
+    if(client->swapped)
+    {
+       int n;
+       long l;
+
+        swaps(&rep.sequenceNumber, n);
+        swapl(&rep.length, l);
+        swaps(&rep.imageRes, n);
+    }
+
+    WriteToClient(client, sz_xPrintGetImageResolutionReply, (char *)&rep);
+    return client->noClientException;
+}
+
+/*******************************************************************************
+ *
+ * RehashPrinterList : Cause the server's list of printers to be rebuilt.
+ *                     This allows new printers to be added, or old ones
+ *                    deleted without needing to restart the server.
+ *
+ ******************************************************************************/
+
+static int
+ProcXpRehashPrinterList(client)
+    ClientPtr client;
+{
+    REQUEST(xPrintRehashPrinterListReq);
+
+    REQUEST_SIZE_MATCH(xPrintRehashPrinterListReq);
+
+    return XpRehashPrinterList();
+}
+
+/******************************************************************************
+ *
+ * Context functions: Init, Set, Destroy, FreeContext
+ *                     AllocateContextPrivateIndex, AllocateContextPrivate
+ *                     and supporting functions.
+ *
+ *     Init creates a context, creates a XpClientRec for the calling
+ *     client, and stores the contextPtr in the client's devPrivates.
+ *
+ *     Set creates a XpClientRec for the calling client, and stores the
+ *     contextPtr in the client's devPrivates unless the context is None.
+ *     If the context is None, then the client's connection association
+ *     with any context is removed.
+ *
+ *     Destroy frees any and all XpClientRecs associated with the context,
+ *     frees the context itself, and removes the contextPtr from any
+ *     relevant client devPrivates.
+ *
+ *     FreeContext is called by FreeResource to free up a context.
+ *
+ ******************************************************************************/
+
+/*
+ * CreateContext creates and initializes the memory for the context itself.
+ * The driver's CreateContext function
+ * is then called.
+ */
+static int
+ProcXpCreateContext(client)
+    ClientPtr client;
+{
+    REQUEST(xPrintCreateContextReq);
+    XpScreenPtr pPrintScreen;
+    WindowPtr pRoot;
+    char *printerName, *driverName;
+    XpContextPtr pContext;
+    XpClientPtr pNewPrintClient;
+    int result = Success;
+    XpDriverPtr pDriver;
+
+    REQUEST_AT_LEAST_SIZE(xPrintCreateContextReq);
+
+    LEGAL_NEW_RESOURCE(stuff->contextID, client);
+
+    /*
+     * Check to see if the printer name is valid.
+     */
+    if((pRoot = XpDiValidatePrinter(stuff + 1, stuff->printerNameLen)) == 
+       (WindowPtr)NULL)
+       return BadMatch;
+
+    pPrintScreen = XpScreens[pRoot->drawable.pScreen->myNum];
+
+    /*
+     * Allocate and add the context resource.
+     */
+    if((pContext = (XpContextPtr) xalloc(totalContextSize)) == 
+       (XpContextPtr) NULL)
+       return BadAlloc;
+
+    InitContextPrivates(pContext);
+
+    if(AddResource(stuff->contextID, RTcontext, (pointer) pContext)
+       != TRUE)
+    {
+       xfree(pContext);
+       return BadAlloc;
+    }
+
+    pContext->contextID = stuff->contextID;
+    pContext->clientHead = (XpClientPtr)NULL;
+    pContext->screenNum = pRoot->drawable.pScreen->myNum;
+    pContext->state = 0;
+    pContext->clientSlept = (ClientPtr)NULL;
+    pContext->imageRes = 0;
+
+    pContext->funcs.DestroyContext = (int (*)())NULL;
+    pContext->funcs.StartJob = (int (*)())NULL;
+    pContext->funcs.EndJob = (int (*)())NULL;
+    pContext->funcs.StartDoc = (int (*)())NULL;
+    pContext->funcs.EndDoc = (int (*)())NULL;
+    pContext->funcs.StartPage = (int (*)())NULL;
+    pContext->funcs.EndPage = (int (*)())NULL;
+    pContext->funcs.PutDocumentData = (int (*)())NULL;
+    pContext->funcs.GetDocumentData = (int (*)())NULL;
+    pContext->funcs.GetAttributes = (char * (*)())NULL;
+    pContext->funcs.GetOneAttribute = (char * (*)())NULL;
+    pContext->funcs.SetAttributes = (int (*)())NULL;
+    pContext->funcs.AugmentAttributes = (int (*)())NULL;
+    pContext->funcs.GetMediumDimensions = (int (*)())NULL;
+    pContext->funcs.GetReproducibleArea = (int (*)())NULL;
+    pContext->funcs.SetImageResolution = (int (*)())NULL;
+
+    if((pContext->printerName = (char *)xalloc(stuff->printerNameLen + 1)) == 
+       (char *)NULL)
+    {
+       /* Freeing the context also causes the XpClients to be freed. */
+       FreeResource(stuff->contextID, RT_NONE);
+       return BadAlloc;
+    }
+    strncpy(pContext->printerName, (char *)(stuff + 1), stuff->printerNameLen);
+    pContext->printerName[stuff->printerNameLen] = (char)'\0';
+
+    driverName = XpDiGetDriverName(pRoot->drawable.pScreen->myNum, 
+                                  pContext->printerName);
+    
+    for(pDriver = pPrintScreen->drivers; 
+       pDriver != (XpDriverPtr)NULL;
+       pDriver = pDriver->next)
+    {
+       if(!strcmp(driverName, pDriver->name))
+       {
+           if(pDriver->CreateContext != (Bool (*)())NULL)
+               pDriver->CreateContext(pContext);
+           else
+               return BadImplementation;
+           break;
+       }
+    }
+
+    if (client->noClientException != Success)
+        return client->noClientException;
+    else
+       return result;
+}
+
+/*
+ * SetContext creates the calling client's contextClient resource,
+ * and stashes the contextID in the client's devPrivate.
+ */
+static int
+ProcXpSetContext(client)
+    ClientPtr client;
+{
+    REQUEST(xPrintSetContextReq);
+
+    XpContextPtr pContext;
+    XpClientPtr pPrintClient;
+    int result = Success;
+
+    REQUEST_AT_LEAST_SIZE(xPrintSetContextReq);
+
+    if((pContext = client->devPrivates[XpClientPrivateIndex].ptr) != 
+       (pointer)NULL)
+    {
+       /*
+        * Erase this client's knowledge of its old context, if any.
+        */
+        if((pPrintClient = FindClient(pContext, client)) != (XpClientPtr)NULL)
+        {
+           XpUnsetFontResFunc(client);
+           
+           if(pPrintClient->eventMask == 0)
+               FreeXpClient(pPrintClient, TRUE);
+        }
+
+        client->devPrivates[XpClientPrivateIndex].ptr = (pointer)NULL;
+    }
+    if(stuff->printContext == None)
+        return Success;
+
+    /*
+     * Check to see that the supplied XID is really a valid print context
+     * in this server.
+     */
+    if((pContext =(XpContextPtr)SecurityLookupIDByType(client,
+                                                      stuff->printContext,
+                                                      RTcontext,
+                                                      SecurityWriteAccess))
+       == (XpContextPtr)NULL)
+    {
+       client->errorValue = stuff->printContext;
+        return XpErrorBase+XPBadContext;
+    }
+
+    if((pPrintClient = AcquireClient(pContext, client)) == (XpClientPtr)NULL)
+        return BadAlloc;
+
+    client->devPrivates[XpClientPrivateIndex].ptr = pContext;
+
+    XpSetFontResFunc(client);
+
+    if (client->noClientException != Success)
+        return client->noClientException;
+    else
+       return result;
+}
+
+XpContextPtr
+XpGetPrintContext(client)
+    ClientPtr client;
+{
+    return (client->devPrivates[XpClientPrivateIndex].ptr);
+}
+
+static int
+ProcXpGetContext(client)
+    ClientPtr client;
+{
+    REQUEST(xPrintGetContextReq);
+    xPrintGetContextReply rep;
+
+    XpContextPtr pContext;
+    XpClientPtr pNewPrintClient;
+    int result = Success;
+    register int n;
+    register long l;
+
+    REQUEST_SIZE_MATCH(xPrintGetContextReq);
+
+    if((pContext = client->devPrivates[XpClientPrivateIndex].ptr) == 
+       (pointer)NULL)
+       rep.printContext = None;
+    else
+        rep.printContext = pContext->contextID;
+    rep.type = X_Reply;
+    rep.length = 0;
+    rep.sequenceNumber = client->sequence;
+    if (client->swapped) {
+        swaps(&rep.sequenceNumber, n);
+        swapl(&rep.length, l);
+        swapl(&rep.printContext, l);
+    }
+    WriteToClient(client, sz_xPrintGetContextReply, (char *)&rep);
+    return client->noClientException;
+}
+
+
+/*
+ * DestroyContext frees the context associated with the calling client.
+ * It operates by freeing the context resource ID, thus causing XpFreeContext
+ * to be called.
+ */
+static int
+ProcXpDestroyContext(client)
+    ClientPtr client;
+{
+    REQUEST(xPrintDestroyContextReq);
+
+    XpContextPtr pContext;
+    XpClientPtr pXpClient;
+    ClientPtr curClient;
+
+    REQUEST_SIZE_MATCH(xPrintDestroyContextReq);
+
+    if((pContext =(XpContextPtr)SecurityLookupIDByType(client,
+                                                      stuff->printContext,
+                                                      RTcontext,
+                                                      SecurityDestroyAccess))
+       == (XpContextPtr)NULL)
+    {
+       client->errorValue = stuff->printContext;
+        return XpErrorBase+XPBadContext;
+    }
+
+    XpUnsetFontResFunc(client);
+           
+    FreeResource(pContext->contextID, RT_NONE);
+
+    return Success;
+}
+
+static int
+ProcXpGetContextScreen(client)
+    ClientPtr client;
+{
+    REQUEST(xPrintGetContextScreenReq);
+    xPrintGetContextScreenReply rep;
+    XpContextPtr pContext;
+    int n;
+    long l;
+
+    if((pContext =(XpContextPtr)SecurityLookupIDByType(client,
+                                                      stuff->printContext,
+                                                      RTcontext,
+                                                      SecurityReadAccess))
+       == (XpContextPtr)NULL)
+        return XpErrorBase+XPBadContext;
+    
+    rep.type = X_Reply;
+    rep.sequenceNumber = client->sequence;
+    rep.length = 0;
+    rep.rootWindow = WindowTable[pContext->screenNum]->drawable.id;
+
+    if (client->swapped) {
+        swaps(&rep.sequenceNumber, n);
+        swapl(&rep.length, l);
+        swapl(&rep.rootWindow, l);
+    }
+
+    WriteToClient(client, sz_xPrintGetContextScreenReply, (char *)&rep);
+    return client->noClientException;
+}
+
+/*
+ * XpFreeContext is the routine called by dix:FreeResource when a context
+ * resource ID is freed.
+ * It checks to see if there's a partial job pending on the context, and
+ * if so it calls the appropriate End procs with the cancel flag set.
+ * It calls the driver's DestroyContext routine to allow the driver to clean
+ * up any context-related memory or state.
+ * It calls FreeXpClient to free all the 
+ * associated XpClientRecs and to set all the client->devPrivates to NULL.
+ * It frees the printer name string, and frees the context
+ * itself.
+ */
+static int
+XpFreeContext(data, id)
+    pointer data;
+    XID id;
+{
+    XpContextPtr pContext = (XpContextPtr)data;
+
+    /* Clean up any pending job on this context */
+    if(pContext->state != 0)
+    {
+       if(pContext->state & PAGE_STARTED)
+       {
+           WindowPtr pWin = (WindowPtr )LookupIDByType(
+                                      pContext->pageWin, RT_WINDOW);
+           XpPagePtr pPage = (XpPagePtr)LookupIDByType(
+                                      pContext->pageWin, RTpage);
+
+           pContext->funcs.EndPage(pContext, pWin, TRUE);
+           SendXpNotify(pContext, XPEndPageNotify, TRUE);
+           pContext->state &= ~PAGE_STARTED;
+           if(pPage)
+               pPage->context = (XpContextPtr)NULL;
+       }
+       if((pContext->state & DOC_RAW_STARTED) || 
+          (pContext->state & DOC_COOKED_STARTED))
+       {
+           pContext->funcs.EndDoc(pContext, TRUE);
+           SendXpNotify(pContext, XPEndDocNotify, TRUE);
+           pContext->state &= ~DOC_RAW_STARTED;
+           pContext->state &= ~DOC_COOKED_STARTED;
+       }
+       if(pContext->funcs.EndJob != (int (*)())NULL)
+       {
+           pContext->funcs.EndJob(pContext, TRUE);
+           SendXpNotify(pContext, XPEndJobNotify, TRUE);
+           pContext->state &= ~JOB_STARTED;
+           pContext->state &= ~GET_DOC_DATA_STARTED;
+       }
+    }
+
+    /* 
+     * Tell the driver we're destroying the context
+     * This allows the driver to free and ContextPrivate data
+     */
+    if(pContext->funcs.DestroyContext != (int (*)())NULL)
+       pContext->funcs.DestroyContext(pContext);
+
+    /* Free up all the XpClientRecs */
+    while(pContext->clientHead != (XpClientPtr)NULL)
+    {
+       FreeXpClient(pContext->clientHead, TRUE);
+    }
+
+    xfree(pContext->printerName);
+    xfree(pContext);
+    return Success; /* ??? */
+}
+
+/*
+ * XpFreeClient is the routine called by dix:FreeResource when a RTclient
+ * is freed.  It simply calls the FreeXpClient routine to do the work.
+ */
+static int
+XpFreeClient(data, id)
+    pointer data;
+    XID id;
+{
+    FreeXpClient((XpClientPtr)data, FALSE);
+}
+
+/*
+ * FreeXpClient 
+ * frees the ClientRec passed in, and sets the client->devPrivates to NULL
+ * if the client->devPrivates points to the same context as the XpClient.
+ * Called from XpFreeContext(from FreeResource), and 
+ * XpFreeClient.  The boolean freeResource specifies whether or not to call
+ * FreeResource for the XpClientRec's XID.  We should free it except if we're
+ * called from XpFreeClient (which is itself called from FreeResource for the
+ * XpClientRec's XID).
+ */
+static void
+FreeXpClient(pXpClient, freeResource)
+    XpClientPtr pXpClient;
+    Bool freeResource;
+{
+    XpClientPtr pCurrent, pPrev;
+    XpContextPtr pContext = pXpClient->context;
+
+    /*
+     * If we're freeing the clientRec associated with the context tied
+     * to the client's devPrivates, then we need to clear the devPrivates.
+     */
+    if(pXpClient->client->devPrivates[XpClientPrivateIndex].ptr == 
+       pXpClient->context)
+    {
+        pXpClient->client->devPrivates[XpClientPrivateIndex].ptr = 
+                                       (pointer)NULL;
+    }
+
+    for(pPrev = (XpClientPtr)NULL, pCurrent = pContext->clientHead; 
+       pCurrent != (XpClientPtr)NULL; 
+       pCurrent = pCurrent->pNext)
+    {
+       if(pCurrent == pXpClient)
+       {
+           if(freeResource == TRUE)
+                FreeResource (pCurrent->contextClientID, RTclient);
+
+            if (pPrev != (XpClientPtr)NULL)
+                pPrev->pNext = pCurrent->pNext;
+            else
+                pContext->clientHead = pCurrent->pNext;
+
+            xfree (pCurrent);
+           break;
+       }
+       pPrev = pCurrent;
+    }
+}
+
+/*
+ * CreateXpClient takes a ClientPtr and returns a pointer to a
+ * XpClientRec which it allocates.  It also initializes the Rec,
+ * including adding a resource on behalf of the client to enable the
+ * freeing of the Rec when the client's connection is closed.
+ */
+static XpClientPtr
+CreateXpClient(client)
+    ClientPtr client;
+{
+    XpClientPtr pNewPrintClient;
+    XID clientResource;
+
+    if((pNewPrintClient = (XpClientPtr)xalloc(sizeof(XpClientRec))) ==
+      (XpClientPtr)NULL)
+        return (XpClientPtr)NULL;
+
+    clientResource = FakeClientID(client->index);
+    if(!AddResource(clientResource, RTclient, (pointer)pNewPrintClient))
+    {
+        xfree (pNewPrintClient);
+        return (XpClientPtr)NULL;
+    }
+
+    pNewPrintClient->pNext = (XpClientPtr)NULL;
+    pNewPrintClient->client = client;
+    pNewPrintClient->context = (XpContextPtr)NULL;
+    pNewPrintClient->eventMask = 0;
+    pNewPrintClient->contextClientID = clientResource;
+
+    return pNewPrintClient;
+}
+
+/*
+ * XpFreePage is the routine called by dix:FreeResource to free the page
+ * resource built with the same ID as a page window.  It checks to see
+ * if we're in the middle of a page, and if so calls the driver's EndPage
+ * function with 'cancel' set TRUE.  It frees the memory associated with
+ * the page resource.
+ */
+static int
+XpFreePage(data, id)
+    pointer data;
+    XID id;
+{
+    XpPagePtr page = (XpPagePtr)data;
+    int result = Success;
+    WindowPtr pWin = (WindowPtr )LookupIDByType(id, RT_WINDOW);
+
+    /* Check to see if the window's being deleted in the middle of a page */
+    if(page->context != (XpContextPtr)NULL && 
+       page->context->state & PAGE_STARTED)
+    {
+       XpScreenPtr pPrintScreen = XpScreens[page->context->screenNum];
+       if(page->context->funcs.EndPage != (int (*)())NULL)
+           result = page->context->funcs.EndPage(page->context, pWin, TRUE);
+        SendXpNotify(page->context, XPEndPageNotify, (int)TRUE);
+       page->context->pageWin = 0; /* None, NULL??? XXX */
+    }
+
+    xfree(page);
+    return result;
+}
+
+/*
+ * ContextPrivate machinery.
+ * Context privates are intended for use by the drivers, allowing the
+ * drivers to maintain context-specific data.  The driver should free
+ * the associated data at DestroyContext time.
+ */
+
+static void
+InitContextPrivates(context)
+    XpContextPtr context;
+{
+    register char *ptr;
+    DevUnion *ppriv;
+    register unsigned *sizes;
+    register unsigned size;
+    register int i;
+
+    if (totalContextSize == sizeof(XpContextRec))
+        ppriv = (DevUnion *)NULL;
+    else 
+        ppriv = (DevUnion *)(context + 1);
+
+    context->devPrivates = ppriv;
+    sizes = contextPrivateSizes;
+    ptr = (char *)(ppriv + contextPrivateLen);
+    for (i = contextPrivateLen; --i >= 0; ppriv++, sizes++)
+    {
+        if ( (size = *sizes) )
+        {
+            ppriv->ptr = (pointer)ptr;
+            ptr += size;
+        }
+        else
+            ppriv->ptr = (pointer)NULL;
+    }
+}
+
+static void
+ResetContextPrivates()
+{
+    contextPrivateCount = 0;
+    contextPrivateLen = 0;
+    xfree(contextPrivateSizes);
+    contextPrivateSizes = (unsigned *)NULL;
+    totalContextSize = sizeof(XpContextRec);
+
+}
+
+int
+XpAllocateContextPrivateIndex()
+{
+    return contextPrivateCount++;
+}
+
+Bool
+XpAllocateContextPrivate(index, amount)
+    int index;
+    unsigned amount;
+{
+    unsigned oldamount;
+
+    if (index >= contextPrivateLen)
+    {
+        unsigned *nsizes;
+        nsizes = (unsigned *)xrealloc(contextPrivateSizes,
+                                      (index + 1) * sizeof(unsigned));
+        if (!nsizes)
+            return FALSE;
+        while (contextPrivateLen <= index)
+        {
+            nsizes[contextPrivateLen++] = 0;
+            totalContextSize += sizeof(DevUnion);
+        }
+        contextPrivateSizes = nsizes;
+    }
+    oldamount = contextPrivateSizes[index];
+    if (amount > oldamount)
+    {
+        contextPrivateSizes[index] = amount;
+        totalContextSize += (amount - oldamount);
+    }
+    return TRUE;
+}
+
+static XpClientPtr
+AcquireClient(pContext, client)
+    XpContextPtr pContext;
+    ClientPtr client;
+{
+    XpClientPtr pXpClient;
+
+    if((pXpClient = FindClient(pContext, client)) != (XpClientPtr)NULL)
+       return pXpClient;
+
+    if((pXpClient = CreateXpClient(client)) == (XpClientPtr)NULL)
+           return (XpClientPtr)NULL;
+
+    pXpClient->context = pContext;
+    pXpClient->pNext = pContext->clientHead;
+    pContext->clientHead = pXpClient;
+
+    return pXpClient;
+}
+
+static XpClientPtr
+FindClient(pContext, client)
+    XpContextPtr pContext;
+    ClientPtr client;
+{
+    XpClientPtr pXpClient;
+
+    for(pXpClient = pContext->clientHead; pXpClient != (XpClientPtr)NULL;
+       pXpClient = pXpClient->pNext)
+    {
+       if(pXpClient->client == client)  return pXpClient;
+    }
+    return (XpClientPtr)NULL;
+}
+
+
+/******************************************************************************
+ *
+ * Start/End Functions: StartJob, EndJob, StartDoc, EndDoc, StartPage, EndPage
+ *
+ ******************************************************************************/
+
+static int
+ProcXpStartJob(client)
+    ClientPtr client;
+{
+    REQUEST(xPrintStartJobReq);
+    XpContextPtr pContext;
+    int result = Success;
+    XpScreenPtr pPrintScreen;
+
+    REQUEST_SIZE_MATCH(xPrintStartJobReq);
+
+    /* Check to see that a context has been established by this client. */
+    if((pContext = (XpContextPtr)client->devPrivates[XpClientPrivateIndex].ptr)
+       == (XpContextPtr)NULL)
+        return XpErrorBase+XPBadContext;
+
+    if(pContext->state != 0)
+       return XpErrorBase+XPBadSequence;
+
+    if(stuff->saveData != XPSpool && stuff->saveData != XPGetData)
+    {
+       client->errorValue = stuff->saveData;
+       return BadValue;
+    }
+
+    pPrintScreen = XpScreens[pContext->screenNum];
+    if(pContext->funcs.StartJob != (int (*)())NULL)
+        result = pContext->funcs.StartJob(pContext, 
+                        (stuff->saveData == XPGetData)? TRUE:FALSE);
+    else
+        return BadImplementation;
+
+    pContext->state = JOB_STARTED;
+    if(stuff->saveData == XPGetData)
+       pContext->state |= JOB_GET_DATA;
+
+    SendXpNotify(pContext, XPStartJobNotify, FALSE);
+
+    if (client->noClientException != Success)
+        return client->noClientException;
+    else
+        return result;
+}
+
+static int
+ProcXpEndJob(client)
+    ClientPtr client;
+{
+    REQUEST(xPrintEndJobReq);
+    XpScreenPtr pPrintScreen;
+    WindowPtr pWin;
+    int result = Success;
+    XpContextPtr pContext;
+
+    REQUEST_SIZE_MATCH(xPrintEndJobReq);
+
+    if((pContext = (XpContextPtr)client->devPrivates[XpClientPrivateIndex].ptr)
+       == (XpContextPtr)NULL)
+        return XpErrorBase+XPBadSequence;
+
+    pPrintScreen = XpScreens[pContext->screenNum];
+
+    if(!(pContext->state & JOB_STARTED))
+       return XpErrorBase+XPBadSequence;
+    
+    /* Check for missing EndDoc */
+    if((pContext->state & DOC_RAW_STARTED) || 
+       (pContext->state & DOC_COOKED_STARTED))
+    {
+       if(pContext->state & PAGE_STARTED)
+       {
+           WindowPtr pWin = (WindowPtr )LookupIDByType(
+                                          pContext->pageWin, RT_WINDOW);
+           XpPagePtr pPage = (XpPagePtr)LookupIDByType(
+                                      pContext->pageWin, RTpage);
+
+           if(stuff->cancel != TRUE)
+               return XpErrorBase+XPBadSequence;
+
+            if(pContext->funcs.EndPage != (int (*)())NULL)
+                result = pContext->funcs.EndPage(pContext, pWin, TRUE);
+            else
+               return BadImplementation;
+
+           SendXpNotify(pContext, XPEndPageNotify, TRUE);
+
+           pContext->state &= ~PAGE_STARTED;
+
+           if(pPage)
+               pPage->context = (XpContextPtr)NULL;
+
+           if(result != Success) return result;
+       }
+
+        if(pContext->funcs.EndDoc != (int (*)())NULL)
+            result = pContext->funcs.EndDoc(pContext, stuff->cancel);
+        else
+           return BadImplementation;
+
+        SendXpNotify(pContext, XPEndDocNotify, stuff->cancel);
+    }
+
+    if(pContext->funcs.EndJob != (int (*)())NULL)
+        result = pContext->funcs.EndJob(pContext, stuff->cancel);
+    else
+       return BadImplementation;
+
+    pContext->state = 0;
+
+    SendXpNotify(pContext, XPEndJobNotify, stuff->cancel);
+
+    if (client->noClientException != Success)
+        return client->noClientException;
+    else
+        return result;
+}
+
+static Bool
+DoStartDoc(client, c)
+    ClientPtr client;
+    XpStDocPtr c;
+{
+    XpScreenPtr pPrintScreen;
+    int result = Success;
+    XpContextPtr pContext = c->pContext;
+
+    if(c->pContext->state & JOB_GET_DATA && 
+       !(c->pContext->state & GET_DOC_DATA_STARTED))
+    {
+       if(!c->slept)
+       {
+           c->slept = TRUE;
+           ClientSleep(client, (ClientSleepProcPtr)DoStartDoc, (pointer) c);
+           c->pContext->clientSlept = client;
+       }
+       return TRUE;
+    }
+    
+    pPrintScreen = XpScreens[pContext->screenNum];
+
+    if(pContext->funcs.StartDoc != (int (*)())NULL)
+        result = pContext->funcs.StartDoc(pContext, c->type);
+    else
+    {
+           SendErrorToClient(client, XpReqCode, X_PrintStartPage, 0, 
+                             BadImplementation);
+           return TRUE;
+    }
+
+    if(c->type == XPDocNormal)
+        pContext->state |= DOC_COOKED_STARTED;
+    else
+       pContext->state |= DOC_RAW_STARTED;
+
+    SendXpNotify(pContext, XPStartDocNotify, (int)FALSE);
+
+    xfree(c);
+    return TRUE;
+}
+
+static int
+ProcXpStartDoc(client)
+    ClientPtr client;
+{
+    REQUEST(xPrintStartDocReq);
+    XpScreenPtr pPrintScreen;
+    int result = Success;
+    XpContextPtr pContext;
+    XpStDocPtr c;
+
+    REQUEST_SIZE_MATCH(xPrintStartDocReq);
+
+    if((pContext = (XpContextPtr)client->devPrivates[XpClientPrivateIndex].ptr)
+       == (XpContextPtr)NULL)
+        return XpErrorBase+XPBadSequence;
+
+    if(!(pContext->state & JOB_STARTED) || 
+       pContext->state & DOC_RAW_STARTED ||
+       pContext->state & DOC_COOKED_STARTED)
+       return XpErrorBase+XPBadSequence;
+
+    if(stuff->type != XPDocNormal && stuff->type != XPDocRaw)
+    {
+       client->errorValue = stuff->type;
+       return BadValue;
+    }
+
+    c = (XpStDocPtr)xalloc(sizeof(XpStDocRec));
+    c->pContext = pContext;
+    c->type = stuff->type;
+    c->slept = FALSE;
+    (void)DoStartDoc(client, c);
+
+    if (client->noClientException != Success)
+        return client->noClientException;
+    else
+        return result;
+}
+
+static int
+ProcXpEndDoc(client)
+    ClientPtr client;
+{
+    REQUEST(xPrintEndDocReq);
+    XpScreenPtr pPrintScreen;
+    XpContextPtr pContext;
+    int result = Success;
+
+    REQUEST_SIZE_MATCH(xPrintEndDocReq);
+
+    if((pContext = (XpContextPtr)client->devPrivates[XpClientPrivateIndex].ptr)
+       == (XpContextPtr)NULL)
+        return XpErrorBase+XPBadSequence;
+
+    pPrintScreen = XpScreens[pContext->screenNum];
+
+    if(!(pContext->state & DOC_RAW_STARTED) &&
+       !(pContext->state & DOC_COOKED_STARTED))
+       return XpErrorBase+XPBadSequence;
+    
+    if(pContext->state & PAGE_STARTED)
+    {
+       if(stuff->cancel == TRUE)
+       {
+           WindowPtr pWin = (WindowPtr )LookupIDByType(
+                                          pContext->pageWin, RT_WINDOW);
+           XpPagePtr pPage = (XpPagePtr)LookupIDByType(
+                                      pContext->pageWin, RTpage);
+
+            if(pContext->funcs.EndPage != (int (*)())NULL)
+                result = pContext->funcs.EndPage(pContext, pWin, TRUE);
+            else
+               return BadImplementation;
+
+           SendXpNotify(pContext, XPEndPageNotify, TRUE);
+
+           if(pPage)
+               pPage->context = (XpContextPtr)NULL;
+       }
+       else
+           return XpErrorBase+XPBadSequence;
+       if(result != Success)
+           return result;
+    }
+
+    if(pContext->funcs.EndDoc != (int (*)())NULL)
+        result = pContext->funcs.EndDoc(pContext, stuff->cancel);
+    else
+       return BadImplementation;
+
+    pContext->state &= ~DOC_RAW_STARTED;
+    pContext->state &= ~DOC_COOKED_STARTED;
+
+    SendXpNotify(pContext, XPEndDocNotify, stuff->cancel);
+
+    if (client->noClientException != Success)
+        return client->noClientException;
+    else
+        return result;
+}
+
+static Bool
+DoStartPage(client, c)
+    ClientPtr client;
+    XpStPagePtr c;
+{
+    XpScreenPtr pPrintScreen;
+    WindowPtr pWin = c->pWin;
+    int result = Success;
+    XpContextPtr pContext = c->pContext;
+    XpPagePtr pPage;
+
+    if(c->pContext->state & JOB_GET_DATA && 
+       !(c->pContext->state & GET_DOC_DATA_STARTED))
+    {
+       if(!c->slept)
+       {
+           c->slept = TRUE;
+           ClientSleep(client, (ClientSleepProcPtr)DoStartPage, (pointer) c);
+           c->pContext->clientSlept = client;
+       }
+       return TRUE;
+    }
+
+    if(!(pContext->state & DOC_COOKED_STARTED))
+    {
+       /* Implied StartDoc if it was omitted */
+        if(pContext->funcs.StartDoc != (int (*)())NULL)
+            result = pContext->funcs.StartDoc(pContext, XPDocNormal);
+        else
+       {
+           SendErrorToClient(client, XpReqCode, X_PrintStartPage, 0, 
+                             BadImplementation);
+           return TRUE;
+       }
+
+       if(result != Success) 
+       {
+           SendErrorToClient(client, XpReqCode, X_PrintStartPage, 0, result);
+           return TRUE;
+       }
+
+        pContext->state |= DOC_COOKED_STARTED;
+        SendXpNotify(pContext, XPStartDocNotify, (int)FALSE);
+    }
+
+    /* ensure the window's not already being used as a page */
+    if((pPage = (XpPagePtr)LookupIDByType(c->pWin->drawable.id, RTpage)) != 
+       (XpPagePtr)NULL)
+    {
+        if(pPage->context != (XpContextPtr)NULL)
+       {
+           SendErrorToClient(client, XpReqCode, X_PrintStartPage, 0, 
+                             BadWindow);
+           return TRUE;
+       }
+    }
+    else
+    {
+        if((pPage = (XpPagePtr)xalloc(sizeof(XpPageRec))) == (XpPagePtr)NULL)
+       {
+           SendErrorToClient(client, XpReqCode, X_PrintStartPage, 0, 
+                             BadAlloc);
+           return TRUE;
+       }
+        if(AddResource(c->pWin->drawable.id, RTpage, pPage) == FALSE)
+        {
+           xfree(pPage);
+           SendErrorToClient(client, XpReqCode, X_PrintStartPage, 0, 
+                             BadAlloc);
+           return TRUE;
+        }
+    }
+
+    pPage->context = pContext;
+    pContext->pageWin = c->pWin->drawable.id;
+
+    pPrintScreen = XpScreens[pContext->screenNum];
+
+
+    if(pContext->funcs.StartPage != (int (*)())NULL)
+        result = pContext->funcs.StartPage(pContext, pWin);
+    else
+    {
+       SendErrorToClient(client, XpReqCode, X_PrintStartPage, 0, 
+                         BadImplementation);
+       return TRUE;
+    }
+
+    pContext->state |= PAGE_STARTED;
+
+    (void)MapWindow(pWin, client);
+
+    SendXpNotify(pContext, XPStartPageNotify, (int)FALSE);
+
+    return TRUE;
+}
+
+static int
+ProcXpStartPage(client)
+    ClientPtr client;
+{
+    REQUEST(xPrintStartPageReq);
+    XpScreenPtr pPrintScreen;
+    WindowPtr pWin;
+    int result = Success;
+    XpContextPtr pContext;
+    XpPagePtr pPage;
+    XpStPagePtr c;
+
+    REQUEST_SIZE_MATCH(xPrintStartPageReq);
+
+    if((pContext = (XpContextPtr)client->devPrivates[XpClientPrivateIndex].ptr)
+       == (XpContextPtr)NULL)
+        return XpErrorBase+XPBadSequence;
+
+    if(!(pContext->state & JOB_STARTED))
+       return XpErrorBase+XPBadSequence;
+
+    /* can't have pages in a raw documented */
+    if(pContext->state & DOC_RAW_STARTED)
+       return XpErrorBase+XPBadSequence;
+    
+    if(pContext->state & PAGE_STARTED)
+       return XpErrorBase+XPBadSequence;
+
+    pWin = (WindowPtr)SecurityLookupWindow(stuff->window, client,
+                                          SecurityWriteAccess);
+    if (!pWin || pWin->drawable.pScreen->myNum != pContext->screenNum)
+       return BadWindow;
+
+    if((c = (XpStPagePtr)xalloc(sizeof(XpStPageRec))) == (XpStPagePtr)NULL)
+       return BadAlloc;
+    c->pContext = pContext;
+    c->slept = FALSE;
+    c->pWin = pWin;
+
+    (void)DoStartPage(client, c);
+
+    if (client->noClientException != Success)
+        return client->noClientException;
+    else
+        return result;
+}
+
+static int
+ProcXpEndPage(client)
+    ClientPtr client;
+{
+    REQUEST(xPrintEndPageReq);
+    XpScreenPtr pPrintScreen;
+    int result = Success;
+    XpContextPtr pContext;
+    XpPagePtr page;
+    WindowPtr pWin;
+
+    REQUEST_SIZE_MATCH(xPrintEndPageReq);
+
+    if((pContext = (XpContextPtr)client->devPrivates[XpClientPrivateIndex].ptr)
+       == (XpContextPtr)NULL)
+        return XpErrorBase+XPBadSequence;
+
+    if(!(pContext->state & PAGE_STARTED))
+       return XpErrorBase+XPBadSequence;
+
+    pPrintScreen = XpScreens[pContext->screenNum];
+    pWin = (WindowPtr )LookupIDByType(pContext->pageWin, RT_WINDOW);
+
+    /* Call the ddx's EndPage proc. */
+    if(pContext->funcs.EndPage != (int (*)())NULL)
+        result = pContext->funcs.EndPage(pContext, pWin, stuff->cancel);
+    else
+       return BadImplementation;
+
+    if((page = (XpPagePtr)LookupIDByType(pContext->pageWin, RTpage)) !=
+       (XpPagePtr)NULL)
+       page->context = (XpContextPtr)NULL;
+
+    pContext->state &= ~PAGE_STARTED;
+    pContext->pageWin = 0; /* None, NULL??? XXX */
+
+    (void)UnmapWindow(pWin, FALSE);
+
+    SendXpNotify(pContext, XPEndPageNotify, stuff->cancel);
+
+    if (client->noClientException != Success)
+        return client->noClientException;
+    else
+        return result;
+}
+
+/*******************************************************************************
+ *
+ * Document Data Functions: PutDocumentData, GetDocumentData
+ *
+ ******************************************************************************/
+
+static int
+ProcXpPutDocumentData(client)
+    ClientPtr client;
+{
+    REQUEST(xPrintPutDocumentDataReq);
+    XpContextPtr pContext;
+    DrawablePtr pDraw;
+    int result = Success;
+    int len, totalSize;
+    char *pData, *pDoc_fmt, *pOptions;
+
+    REQUEST_AT_LEAST_SIZE(xPrintPutDocumentDataReq);
+
+    if((pContext = (XpContextPtr)client->devPrivates[XpClientPrivateIndex].ptr)
+       == (XpContextPtr)NULL)
+        return XpErrorBase+XPBadSequence;
+
+    if(!(pContext->state & DOC_RAW_STARTED) &&
+       !(pContext->state & DOC_COOKED_STARTED))
+        return XpErrorBase+XPBadSequence;
+
+    if (stuff->drawable) {
+       if (pContext->state & DOC_RAW_STARTED)
+           return BadDrawable;
+       pDraw = (DrawablePtr)LookupDrawable(stuff->drawable, client);
+       if (!pDraw || pDraw->pScreen->myNum != pContext->screenNum)
+           return BadDrawable;
+    } else {
+       if (pContext->state & DOC_COOKED_STARTED)
+           return BadDrawable;
+       pDraw = NULL;
+    }
+
+    pData = (char *)(&stuff[1]);
+
+    totalSize = (stuff->len_data + 3) >> 2;
+    pDoc_fmt = pData + (totalSize << 2);
+
+    totalSize += (stuff->len_fmt + 3) >> 2;
+    pOptions = pData + (totalSize << 2);
+
+    totalSize += (stuff->len_options + 3) >> 2;
+    if((totalSize + (sz_xPrintPutDocumentDataReq >> 2)) != client->req_len)
+        return BadLength;
+    
+    if(pContext->funcs.PutDocumentData != (int (*)())NULL)
+    {
+        result = (*pContext->funcs.PutDocumentData)(pContext, pDraw,
+                                         pData, stuff->len_data,
+                                         pDoc_fmt, stuff->len_fmt,
+                                         pOptions, stuff->len_options,
+                                         client);
+    }
+    else
+       return BadImplementation;
+
+    if (client->noClientException != Success)
+        return client->noClientException;
+    else
+        return result;
+}
+
+static int
+ProcXpGetDocumentData(client)
+    ClientPtr client;
+{
+    REQUEST(xPrintGetDocumentDataReq);
+    xPrintGetDocumentDataReply rep;
+    XpScreenPtr pPrintScreen;
+    XpContextPtr pContext;
+    int result = Success;
+
+    REQUEST_SIZE_MATCH(xPrintGetDocumentDataReq);
+
+    if((pContext = (XpContextPtr)SecurityLookupIDByType(client,
+                                                       stuff->printContext, 
+                                                       RTcontext,
+                                                       SecurityWriteAccess))
+       == (XpContextPtr)NULL)
+    {
+        client->errorValue = stuff->printContext;
+        return XpErrorBase+XPBadContext;
+    }
+
+    if(pContext->funcs.GetDocumentData == (int (*)())NULL)
+       return BadImplementation;
+
+    if(!(pContext->state & JOB_GET_DATA) || 
+       pContext->state & GET_DOC_DATA_STARTED)
+       return XpErrorBase+XPBadSequence;
+
+    if(stuff->maxBufferSize <= 0)
+    {
+       client->errorValue = stuff->maxBufferSize;
+        return BadValue; /* gotta have a positive buffer size */
+    }
+
+    result = (*pContext->funcs.GetDocumentData)(pContext, client, 
+                                               stuff->maxBufferSize);
+    if(result != Success)
+    {
+       rep.type = X_Reply;
+       rep.sequenceNumber = client->sequence;
+       rep.length = 0;
+       rep.dataLen = 0;
+       rep.statusCode = 1;
+       rep.finishedFlag = TRUE;
+        if (client->swapped) {
+            int n;
+            long l;
+
+            swaps(&rep.sequenceNumber, n);
+            swapl(&rep.statusCode, l); /* XXX Why are these longs??? */
+            swapl(&rep.finishedFlag, l); /* XXX Why are these longs??? */
+        }
+       (void)WriteToClient(client,sz_xPrintGetDocumentDataReply,(char *)&rep);
+    }
+    else
+        pContext->state |= GET_DOC_DATA_STARTED;
+
+    if(pContext->clientSlept != (ClientPtr)NULL)
+    {
+       ClientSignal(pContext->clientSlept);
+       ClientWakeup(pContext->clientSlept);
+       pContext->clientSlept = (ClientPtr)NULL;
+    }
+
+    return result;
+}
+
+/*******************************************************************************
+ *
+ * Attribute requests: GetAttributes, SetAttributes, GetOneAttribute
+ *
+ ******************************************************************************/
+
+static int 
+ProcXpGetAttributes(client)
+    ClientPtr client;
+{
+    REQUEST(xPrintGetAttributesReq);
+    XpContextPtr pContext;
+    char *attrs;
+    xPrintGetAttributesReply *pRep;
+    int totalSize, n;
+    unsigned long l;
+
+    REQUEST_SIZE_MATCH(xPrintGetAttributesReq);
+
+    if(stuff->type < XPJobAttr || stuff->type > XPServerAttr)
+    {
+       client->errorValue = stuff->type;
+       return BadValue;
+    }
+
+    if(stuff->type != XPServerAttr)
+    {
+        if((pContext = (XpContextPtr)SecurityLookupIDByType(
+                                               client,
+                                               stuff->printContext,
+                                               RTcontext,
+                                               SecurityReadAccess))
+          == (XpContextPtr)NULL)
+        {
+           client->errorValue = stuff->printContext;
+            return XpErrorBase+XPBadContext;
+        }
+
+        if(pContext->funcs.GetAttributes == (char *(*)())NULL)
+           return BadImplementation;
+        if((attrs = (*pContext->funcs.GetAttributes)(pContext, stuff->type)) == 
+           (char *)NULL) 
+           return BadAlloc;
+    }
+    else
+    {
+       if((attrs = XpGetAttributes((XpContextPtr)NULL, XPServerAttr)) ==
+          (char *)NULL)
+           return BadAlloc;
+    }
+
+    totalSize = sz_xPrintGetAttributesReply + QUADPAD(strlen(attrs));
+    if((pRep = (xPrintGetAttributesReply *)malloc(totalSize)) ==
+       (xPrintGetAttributesReply *)NULL)
+       return BadAlloc;
+
+    pRep->type = X_Reply;
+    pRep->length = (totalSize - sz_xPrintGetAttributesReply) >> 2;
+    pRep->sequenceNumber = client->sequence;
+    pRep->stringLen = strlen(attrs);
+
+    if (client->swapped) {
+        swaps(&pRep->sequenceNumber, n);
+        swapl(&pRep->length, l);
+        swapl(&pRep->stringLen, l);
+    }
+
+    strncpy((char*)(pRep + 1), attrs, strlen(attrs));
+    xfree(attrs);
+
+    WriteToClient(client, totalSize, (char *)pRep);
+
+    xfree(pRep);
+
+    return client->noClientException;
+}
+
+static int 
+ProcXpSetAttributes(client)
+    ClientPtr client;
+{
+    REQUEST(xPrintSetAttributesReq);
+    int result = Success;
+    XpContextPtr pContext;
+    char *attr;
+
+    REQUEST_AT_LEAST_SIZE(xPrintSetAttributesReq);
+
+    if(stuff->type < XPJobAttr || stuff->type > XPServerAttr)
+    {
+       client->errorValue = stuff->type;
+       return BadValue;
+    }
+
+    /*
+     * Disallow changing of read-only attribute pools
+     */
+    if(stuff->type == XPPrinterAttr || stuff->type == XPServerAttr)
+       return BadMatch;
+
+    if((pContext = (XpContextPtr)SecurityLookupIDByType(
+                                       client,
+                                       stuff->printContext,
+                                       RTcontext,
+                                       SecurityWriteAccess))
+       == (XpContextPtr)NULL)
+    {
+        client->errorValue = stuff->printContext;
+        return XpErrorBase+XPBadContext;
+    }
+
+    if(pContext->funcs.SetAttributes == (int (*)())NULL)
+       return BadImplementation;
+    
+    /* 
+     * Check for attributes being set after their relevant phase
+     * has already begun (e.g. Job attributes set after StartJob).
+     */
+    if((pContext->state & JOB_STARTED) && stuff->type == XPJobAttr)
+       return XpErrorBase+XPBadSequence;
+    if(((pContext->state & DOC_RAW_STARTED) || 
+       (pContext->state & DOC_COOKED_STARTED)) && stuff->type == XPDocAttr)
+       return XpErrorBase+XPBadSequence;
+    if((pContext->state & PAGE_STARTED) && stuff->type == XPPageAttr)
+       return XpErrorBase+XPBadSequence;
+
+    if((attr = (char *)malloc(stuff->stringLen + 1)) == (char *)NULL)
+       return BadAlloc;
+
+    strncpy(attr, (char *)(stuff + 1), stuff->stringLen);
+    attr[stuff->stringLen] = (char)'\0';
+
+    if(stuff->rule == XPAttrReplace)
+        (*pContext->funcs.SetAttributes)(pContext, stuff->type, attr);
+    else if(stuff->rule == XPAttrMerge)
+        (*pContext->funcs.AugmentAttributes)(pContext, stuff->type, attr);
+    else
+    {
+       client->errorValue = stuff->rule;
+       result = BadValue;
+    }
+
+    xfree(attr);
+
+    SendAttributeNotify(pContext, stuff->type);
+
+    return result;
+}
+
+static int 
+ProcXpGetOneAttribute(client)
+    ClientPtr client;
+{
+    REQUEST(xPrintGetOneAttributeReq);
+    XpContextPtr pContext;
+    char *value, *attrName;
+    xPrintGetOneAttributeReply *pRep;
+    int totalSize, n;
+    unsigned long l;
+
+    REQUEST_AT_LEAST_SIZE(xPrintGetOneAttributeReq);
+
+    totalSize = ((sz_xPrintGetOneAttributeReq) >> 2) +
+                ((stuff->nameLen + 3) >> 2);
+    if(totalSize != client->req_len)
+        return BadLength;
+
+    if(stuff->type < XPJobAttr || stuff->type > XPServerAttr)
+    {
+       client->errorValue = stuff->type;
+       return BadValue;
+    }
+    
+    if((attrName = (char *)malloc(stuff->nameLen + 1)) == (char *)NULL)
+       return BadAlloc;
+    strncpy(attrName, (char *)(stuff+1), stuff->nameLen);
+    attrName[stuff->nameLen] = (char)'\0';
+
+    if(stuff->type != XPServerAttr)
+    {
+        if((pContext = (XpContextPtr)SecurityLookupIDByType(
+                                               client,
+                                               stuff->printContext, 
+                                               RTcontext,
+                                               SecurityReadAccess))
+          == (XpContextPtr)NULL)
+        {
+           client->errorValue = stuff->printContext;
+            return XpErrorBase+XPBadContext;
+        }
+
+        if(pContext->funcs.GetOneAttribute == (char *(*)())NULL)
+           return BadImplementation;
+        if((value = (*pContext->funcs.GetOneAttribute)(pContext, stuff->type,
+           attrName)) == (char *)NULL) 
+           return BadAlloc;
+    }
+    else
+    {
+       if((value = XpGetOneAttribute((XpContextPtr)NULL, XPServerAttr,
+           attrName)) == (char *)NULL)
+           return BadAlloc;
+    }
+
+    free(attrName);
+
+    totalSize = sz_xPrintGetOneAttributeReply + QUADPAD(strlen(value));
+    if((pRep = (xPrintGetOneAttributeReply *)malloc(totalSize)) ==
+       (xPrintGetOneAttributeReply *)NULL)
+       return BadAlloc;
+
+    pRep->type = X_Reply;
+    pRep->length = (totalSize - sz_xPrintGetOneAttributeReply) >> 2;
+    pRep->sequenceNumber = client->sequence;
+    pRep->valueLen = strlen(value);
+
+    if (client->swapped) {
+        swaps(&pRep->sequenceNumber, n);
+        swapl(&pRep->length, l);
+        swapl(&pRep->valueLen, l);
+    }
+
+    strncpy((char*)(pRep + 1), value, strlen(value));
+
+    WriteToClient(client, totalSize, (char *)pRep);
+
+    xfree(pRep);
+
+    return client->noClientException;
+}
+
+/*******************************************************************************
+ *
+ * Print Event requests: SelectInput InputSelected, SendXpNotify
+ *
+ ******************************************************************************/
+
+
+static int
+ProcXpSelectInput(client)
+    ClientPtr client;
+{
+    REQUEST(xPrintSelectInputReq);
+    int result = Success;
+    XpContextPtr pContext;
+    XpClientPtr pPrintClient;
+
+    REQUEST_SIZE_MATCH(xPrintSelectInputReq);
+
+    /*
+     * Check to see that the supplied XID is really a valid print context
+     * in this server.
+     */
+    if((pContext=(XpContextPtr)SecurityLookupIDByType(client,
+                                                     stuff->printContext,
+                                                     RTcontext,
+                                                     SecurityWriteAccess))
+       == (XpContextPtr)NULL)
+    {
+       client->errorValue = stuff->printContext;
+        return XpErrorBase+XPBadContext;
+    }
+
+    if(stuff->eventMask & ~allEvents)
+    {
+       client->errorValue = stuff->eventMask;
+        return BadValue; /* bogus event mask bits */
+    }
+
+    if((pPrintClient = AcquireClient(pContext, client)) == (XpClientPtr)NULL)
+       return BadAlloc;
+
+    pPrintClient->eventMask = stuff->eventMask;
+
+    return result;
+}
+
+static int
+ProcXpInputSelected(client)
+    ClientPtr client;
+{
+    REQUEST(xPrintInputSelectedReq);
+    xPrintInputSelectedReply rep;
+    register int n;
+    long l, allMask;
+    WindowPtr pWin;
+    XpClientPtr pXpClient;
+    XpContextPtr pContext;
+
+    REQUEST_SIZE_MATCH(xPrintInputSelectedReq);
+
+    if((pContext=(XpContextPtr)SecurityLookupIDByType(client,
+                                                     stuff->printContext,
+                                                     RTcontext,
+                                                     SecurityReadAccess))
+       == (XpContextPtr)NULL)
+    {
+       client->errorValue = stuff->printContext;
+        return XpErrorBase+XPBadContext;
+    }
+
+    pXpClient = FindClient(pContext, client);
+
+    rep.type = X_Reply;
+    rep.length = 0;
+    rep.sequenceNumber = client->sequence;
+    rep.eventMask = (pXpClient != (XpClientPtr)NULL)? pXpClient->eventMask : 0;
+    rep.allEventsMask = GetAllEventMasks(pContext);
+
+    if (client->swapped) {
+        swaps(&rep.sequenceNumber, n);
+        swapl(&rep.length, l);
+        swapl(&rep.eventMask, l);
+        swapl(&rep.allEventsMask, l);
+    }
+
+    WriteToClient(client, sz_xPrintInputSelectedReply, (char *)&rep);
+    return client->noClientException;
+}
+
+static void
+SendAttributeNotify(pContext, which)
+    XpContextPtr pContext;
+    int which;
+{
+    XpClientPtr        pXpClient;
+    xPrintAttributeEvent   ae;
+    ClientPtr  client;
+
+    pXpClient = pContext->clientHead;
+    if(pXpClient == (XpClientPtr)NULL) 
+        return; /* Nobody's interested in the events (or this context). */
+
+    for (pXpClient = pContext->clientHead; 
+         pXpClient != (XpClientPtr)NULL; 
+         pXpClient = pXpClient->pNext)
+    {
+        client = pXpClient->client;
+        if (client == serverClient || client->clientGone || 
+           !(pXpClient->eventMask & XPAttributeMask))
+            continue;
+        ae.type = XPAttributeNotify + XpEventBase;
+        ae.detail = which;
+        ae.printContext = pContext->contextID;
+        ae.sequenceNumber = client->sequence;
+        WriteEventsToClient (client, 1, (xEvent *) &ae);
+    }
+}
+static void
+SendXpNotify(pContext, which, val)
+    XpContextPtr pContext;
+    int which;
+    int val;
+{
+    XpClientPtr        pXpClient;
+    xPrintPrintEvent   pe;
+    ClientPtr  client;
+
+    pXpClient = pContext->clientHead;
+    if(pXpClient == (XpClientPtr)NULL) 
+        return; /* Nobody's interested in the events (or this context). */
+
+    for (pXpClient = pContext->clientHead; 
+         pXpClient != (XpClientPtr)NULL; 
+         pXpClient = pXpClient->pNext)
+    {
+        client = pXpClient->client;
+        if (client == serverClient || client->clientGone || 
+           !(pXpClient->eventMask & XPPrintMask))
+            continue;
+        pe.type = XPPrintNotify + XpEventBase;
+        pe.detail = which;
+        pe.printContext = pContext->contextID;
+       pe.cancel = (Bool)val;
+        pe.sequenceNumber = client->sequence;
+        WriteEventsToClient (client, 1, (xEvent *) &pe);
+    }
+}
+
+static CARD32
+GetAllEventMasks(pContext)
+    XpContextPtr pContext;
+{
+    XpClientPtr pPrintClient;
+    CARD32 totalMask = (CARD32)0;
+    
+    for (pPrintClient = pContext->clientHead;
+         pPrintClient != (XpClientPtr)NULL;
+         pPrintClient = pPrintClient->pNext)
+    {
+        totalMask |= pPrintClient->eventMask;
+    }
+    return totalMask;
+}
+
+/*
+ * XpContextOfClient - returns the XpContextPtr to the context
+ * associated with the specified client, or NULL if the client
+ * does not currently have a context set.
+ */
+XpContextPtr
+XpContextOfClient(client)
+    ClientPtr client;
+{
+    XpContextPtr pContext;
+
+    return (XpContextPtr)client->devPrivates[XpClientPrivateIndex].ptr;
+}
+
+
+/*******************************************************************************
+ *
+ * Swap-request functions
+ *
+ ******************************************************************************/
+
+static int
+SProcXpCreateContext(client)
+    ClientPtr client;
+{
+    int i;
+    long n;
+
+    REQUEST(xPrintCreateContextReq);
+
+    swaps(&stuff->length, i);
+    swapl(&stuff->contextID, n);
+    swapl(&stuff->printerNameLen, n);
+    swapl(&stuff->localeLen, n);
+    return ProcXpCreateContext(client);
+}
+
+static int
+SProcXpGetPrinterList(client)
+    ClientPtr client;
+{
+    int i;
+    long n;
+
+    REQUEST(xPrintGetPrinterListReq);
+
+    swaps(&stuff->length, i);
+    swapl(&stuff->printerNameLen, n);
+    swapl(&stuff->localeLen, n);
+    return ProcXpGetPrinterList(client);
+}
+
+static int
+SProcXpRehashPrinterList(client)
+    ClientPtr client;
+{
+    int i;
+    long n;
+
+    REQUEST(xPrintRehashPrinterListReq);
+    swaps(&stuff->length, i);
+    return ProcXpRehashPrinterList(client);
+}
+
+static int
+SProcXpSetContext(client)
+    ClientPtr client;
+{
+    int i;
+    long n;
+
+    REQUEST(xPrintSetContextReq);
+    swaps(&stuff->length, i);
+    swapl(&stuff->printContext, i);
+    return ProcXpSetContext(client);
+}
+
+static int
+SProcXpGetContext(client)
+    ClientPtr client;
+{
+    int i;
+
+    REQUEST(xPrintGetContextReq);
+    swaps(&stuff->length, i);
+    return ProcXpGetContext(client);
+}
+
+static int
+SProcXpDestroyContext(client)
+    ClientPtr client;
+{
+    int i;
+    long n;
+
+    REQUEST(xPrintDestroyContextReq);
+    swaps(&stuff->length, i);
+    swapl(&stuff->printContext, n);
+    return ProcXpDestroyContext(client);
+}
+
+static int
+SProcXpGetContextScreen(client)
+    ClientPtr client;
+{
+    int i;
+    long n;
+
+    REQUEST(xPrintGetContextScreenReq);
+    swaps(&stuff->length, i);
+    swapl(&stuff->printContext, n);
+    return ProcXpGetContextScreen(client);
+}
+
+static int
+SProcXpInputSelected(client)
+    ClientPtr client;
+{
+    int i;
+    long n;
+
+    REQUEST(xPrintInputSelectedReq);
+    swaps(&stuff->length, i);
+    swapl(&stuff->printContext, n);
+    return ProcXpInputSelected(client);
+}
+
+static int
+SProcXpStartJob(client)
+    ClientPtr client;
+{
+    int i;
+
+    REQUEST(xPrintStartJobReq);
+    swaps(&stuff->length, i);
+    return ProcXpStartJob(client);
+}
+
+static int
+SProcXpEndJob(client)
+    ClientPtr client;
+{
+    int i;
+
+    REQUEST(xPrintEndJobReq);
+    swaps(&stuff->length, i);
+    return ProcXpEndJob(client);
+}
+
+static int
+SProcXpStartDoc(client)
+    ClientPtr client;
+{
+    int i;
+
+    REQUEST(xPrintStartDocReq);
+    swaps(&stuff->length, i);
+    return ProcXpStartDoc(client);
+}
+
+static int
+SProcXpEndDoc(client)
+    ClientPtr client;
+{
+    int i;
+
+    REQUEST(xPrintEndDocReq);
+    swaps(&stuff->length, i);
+    return ProcXpEndDoc(client);
+}
+
+static int
+SProcXpStartPage(client)
+    ClientPtr client;
+{
+    int i;
+    long n;
+
+    REQUEST(xPrintStartPageReq);
+    swaps(&stuff->length, i);
+    swapl(&stuff->window, n);
+    return ProcXpStartPage(client);
+}
+
+static int
+SProcXpEndPage(client)
+    ClientPtr client;
+{
+    int i;
+
+    REQUEST(xPrintEndPageReq);
+    swaps(&stuff->length, i);
+    return ProcXpEndPage(client);
+}
+
+static int
+SProcXpPutDocumentData(client)
+    ClientPtr client;
+{
+    long n;
+    int i;
+
+    REQUEST(xPrintPutDocumentDataReq);
+    swaps(&stuff->length, i);
+    swapl(&stuff->drawable, n);
+    swapl(&stuff->len_data, n);
+    swaps(&stuff->len_fmt, i);
+    swaps(&stuff->len_options, i);
+    return ProcXpPutDocumentData(client);
+}
+
+static int
+SProcXpGetDocumentData(client)
+    ClientPtr client;
+{
+    long n;
+    int i;
+
+    REQUEST(xPrintGetDocumentDataReq);
+    swaps(&stuff->length, i);
+    swapl(&stuff->printContext, n);
+    swapl(&stuff->maxBufferSize, n);
+    return ProcXpGetDocumentData(client);
+}
+
+static int
+SProcXpGetAttributes(client)
+    ClientPtr client;
+{
+    long n;
+    int i;
+
+    REQUEST(xPrintGetAttributesReq);
+    swaps(&stuff->length, i);
+    swapl(&stuff->printContext, n);
+    return ProcXpGetAttributes(client);
+}
+
+static int
+SProcXpSetAttributes(client)
+    ClientPtr client;
+{
+    long n;
+    int i;
+
+    REQUEST(xPrintSetAttributesReq);
+    swaps(&stuff->length, i);
+    swapl(&stuff->printContext, n);
+    swapl(&stuff->stringLen, n);
+    return ProcXpSetAttributes(client);
+}
+
+static int
+SProcXpGetOneAttribute(client)
+    ClientPtr client;
+{
+    long n;
+    int i;
+
+    REQUEST(xPrintGetOneAttributeReq);
+    swaps(&stuff->length, i);
+    swapl(&stuff->printContext, n);
+    swapl(&stuff->nameLen, n);
+    return ProcXpGetOneAttribute(client);
+}
+
+static int
+SProcXpSelectInput(client)
+    ClientPtr client;
+{
+    long n;
+    int i;
+
+    REQUEST(xPrintSelectInputReq);
+    swaps(&stuff->length, i);
+    swapl(&stuff->eventMask, n);
+    swapl(&stuff->printContext, n);
+    return ProcXpSelectInput(client);
+}
+static int 
+SProcXpGetPageDimensions(client)
+    ClientPtr client;
+{
+    long n;
+    int i;
+
+    REQUEST(xPrintGetPageDimensionsReq);
+    swaps(&stuff->length, i);
+    swapl(&stuff->printContext, n);
+    return ProcXpGetPageDimensions(client);
+}
+static int 
+SProcXpSetImageResolution(client)
+    ClientPtr client;
+{
+    long n;
+    int i;
+
+    REQUEST(xPrintSetImageResolutionReq);
+    swaps(&stuff->length, i);
+    swapl(&stuff->printContext, n);
+    swaps(&stuff->imageRes, i);
+    return ProcXpSetImageResolution(client);
+}
+static int 
+SProcXpGetImageResolution(client)
+    ClientPtr client;
+{
+    long n;
+    int i;
+
+    REQUEST(xPrintGetImageResolutionReq);
+    swaps(&stuff->length, i);
+    swapl(&stuff->printContext, n);
+    return ProcXpGetImageResolution(client);
+}
+
+static void
+SwapXpNotifyEvent(src, dst)
+    xPrintPrintEvent *src, *dst;
+{
+    /*
+     * Swap the sequence number and context fields.
+     */
+    cpswaps(src->sequenceNumber, dst->sequenceNumber);
+    cpswapl(src->printContext, dst->printContext);
+
+    /*
+     * Copy the byte-long fields.
+     */
+    dst->type = src->type;
+    dst->detail = src->detail;
+    dst->cancel = src->cancel;
+}
+
+static void
+SwapXpAttributeEvent(src, dst)
+    xPrintAttributeEvent *src, *dst;
+{
+    /*
+     * Swap the sequence number and context fields.
+     */
+    cpswaps(src->sequenceNumber, dst->sequenceNumber);
+    cpswapl(src->printContext, dst->printContext);
+
+    /*
+     * Copy the byte-long fields.
+     */
+    dst->type = src->type;
+    dst->detail = src->detail;
+}
diff --git a/Xserver/programs/Xserver/Xext/xtest.c b/Xserver/programs/Xserver/Xext/xtest.c
new file mode 100644 (file)
index 0000000..fbfe7a0
--- /dev/null
@@ -0,0 +1,555 @@
+/* $XConsortium: xtest.c,v 1.22 94/04/17 20:32:59 dpw Exp $ */
+/* $XFree86: xc/programs/Xserver/Xext/xtest.c,v 3.1 1996/05/06 05:55:41 dawes Exp $ */
+/*
+
+Copyright (c) 1992  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be included
+in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR
+OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall
+not be used in advertising or otherwise to promote the sale, use or
+other dealings in this Software without prior written authorization
+from the X Consortium.
+
+*/
+
+#include "X.h"
+#define NEED_EVENTS
+#include "Xproto.h"
+#include "misc.h"
+#include "os.h"
+#include "dixstruct.h"
+#include "extnsionst.h"
+#include "windowstr.h"
+#include "inputstr.h"
+#include "scrnintstr.h"
+#include "dixevents.h"
+#define _XTEST_SERVER_
+#include "XTest.h"
+#include "xteststr.h"
+#ifdef XINPUT
+#include "XI.h"
+#include "XIproto.h"
+#define EXTENSION_EVENT_BASE   64
+#include "extinit.h"           /* LookupDeviceIntRec */
+#endif /* XINPUT */
+
+static unsigned char XTestReqCode;
+
+#ifdef XINPUT
+extern int DeviceValuator;
+#endif /* XINPUT */
+
+static void XTestResetProc(
+#if NeedFunctionPrototypes
+    ExtensionEntry * /* extEntry */
+#endif
+);
+static int XTestSwapFakeInput(
+#if NeedFunctionPrototypes
+    ClientPtr /* client */,
+    xReq * /* req */
+#endif
+);
+
+static DISPATCH_PROC(ProcXTestCompareCursor);
+static DISPATCH_PROC(ProcXTestDispatch);
+static DISPATCH_PROC(ProcXTestFakeInput);
+static DISPATCH_PROC(ProcXTestGetVersion);
+static DISPATCH_PROC(ProcXTestGrabControl);
+static DISPATCH_PROC(SProcXTestCompareCursor);
+static DISPATCH_PROC(SProcXTestDispatch);
+static DISPATCH_PROC(SProcXTestFakeInput);
+static DISPATCH_PROC(SProcXTestGetVersion);
+static DISPATCH_PROC(SProcXTestGrabControl);
+
+void
+XTestExtensionInit()
+{
+    ExtensionEntry *extEntry;
+
+    if ((extEntry = AddExtension(XTestExtensionName, 0, 0,
+                                ProcXTestDispatch, SProcXTestDispatch,
+                                XTestResetProc, StandardMinorOpcode)) != 0)
+       XTestReqCode = (unsigned char)extEntry->base;
+}
+
+/*ARGSUSED*/
+static void
+XTestResetProc (extEntry)
+ExtensionEntry *extEntry;
+{
+}
+
+static int
+ProcXTestGetVersion(client)
+    register ClientPtr client;
+{
+    xXTestGetVersionReply rep;
+    register int n;
+
+    REQUEST_SIZE_MATCH(xXTestGetVersionReq);
+    rep.type = X_Reply;
+    rep.length = 0;
+    rep.sequenceNumber = client->sequence;
+    rep.majorVersion = XTestMajorVersion;
+    rep.minorVersion = XTestMinorVersion;
+    if (client->swapped) {
+       swaps(&rep.sequenceNumber, n);
+       swaps(&rep.minorVersion, n);
+    }
+    WriteToClient(client, sizeof(xXTestGetVersionReply), (char *)&rep);
+    return(client->noClientException);
+}
+
+static int
+ProcXTestCompareCursor(client)
+    register ClientPtr client;
+{
+    REQUEST(xXTestCompareCursorReq);
+    xXTestCompareCursorReply rep;
+    WindowPtr pWin;
+    CursorPtr pCursor;
+    register int n;
+
+    REQUEST_SIZE_MATCH(xXTestCompareCursorReq);
+    pWin = (WindowPtr)LookupWindow(stuff->window, client);
+    if (!pWin)
+        return(BadWindow);
+    if (stuff->cursor == None)
+       pCursor = NullCursor;
+    else if (stuff->cursor == XTestCurrentCursor)
+       pCursor = GetSpriteCursor();
+    else {
+       pCursor = (CursorPtr)LookupIDByType(stuff->cursor, RT_CURSOR);
+       if (!pCursor) 
+       {
+           client->errorValue = stuff->cursor;
+           return (BadCursor);
+       }
+    }
+    rep.type = X_Reply;
+    rep.length = 0;
+    rep.sequenceNumber = client->sequence;
+    rep.same = (wCursor(pWin) == pCursor);
+    if (client->swapped) {
+       swaps(&rep.sequenceNumber, n);
+    }
+    WriteToClient(client, sizeof(xXTestCompareCursorReply), (char *)&rep);
+    return(client->noClientException);
+}
+
+static int
+ProcXTestFakeInput(client)
+    register ClientPtr client;
+{
+    REQUEST(xXTestFakeInputReq);
+    int nev;
+    int        n;
+    xEvent *ev;
+    DeviceIntPtr dev;
+    WindowPtr root;
+    int type;
+#ifdef XINPUT
+    Bool extension = FALSE;
+    deviceValuator *dv;
+    int base;
+    int *values;
+#endif /* XINPUT */
+
+    nev = (stuff->length << 2) - sizeof(xReq);
+    if ((nev % sizeof(xEvent)) || !nev)
+       return BadLength;
+    nev /= sizeof(xEvent);
+    UpdateCurrentTime();
+    ev = (xEvent *)&((xReq *)stuff)[1];
+    type = ev->u.u.type & 0177;
+#ifdef XINPUT
+    if (type >= EXTENSION_EVENT_BASE)
+    {
+       type -= DeviceValuator;
+       switch (type) {
+       case XI_DeviceKeyPress:
+       case XI_DeviceKeyRelease:
+       case XI_DeviceButtonPress:
+       case XI_DeviceButtonRelease:
+       case XI_DeviceMotionNotify:
+       case XI_ProximityIn:
+       case XI_ProximityOut:
+           break;
+       default:
+           client->errorValue = ev->u.u.type;
+           return BadValue;
+       }
+       if (nev == 1 && type == XI_DeviceMotionNotify)
+           return BadLength;
+       if (type == XI_DeviceMotionNotify)
+           base = ((deviceValuator *)(ev+1))->first_valuator;
+       else
+           base = 0;
+       for (n = 1; n < nev; n++)
+       {
+           dv = (deviceValuator *)(ev + n);
+           if (dv->type != DeviceValuator)
+           {
+               client->errorValue = dv->type;
+               return BadValue;
+           }
+           if (dv->first_valuator != base)
+           {
+               client->errorValue = dv->first_valuator;
+               return BadValue;
+           }
+           if (!dv->num_valuators || dv->num_valuators > 6)
+           {
+               client->errorValue = dv->num_valuators;
+               return BadValue;
+           }
+           base += dv->num_valuators;
+       }
+       type = type - XI_DeviceKeyPress + KeyPress;
+       extension = TRUE;
+    }
+    else
+#endif /* XINPUT */
+    {
+       if (nev != 1)
+           return BadLength;
+       switch (type)
+       {
+       case KeyPress:
+       case KeyRelease:
+       case MotionNotify:
+       case ButtonPress:
+       case ButtonRelease:
+           break;
+       default:
+           client->errorValue = ev->u.u.type;
+           return BadValue;
+       }
+    }
+    if (ev->u.keyButtonPointer.time)
+    {
+       TimeStamp activateTime;
+       CARD32 ms;
+
+       activateTime = currentTime;
+       ms = activateTime.milliseconds + ev->u.keyButtonPointer.time;
+       if (ms < activateTime.milliseconds)
+           activateTime.months++;
+       activateTime.milliseconds = ms;
+       ev->u.keyButtonPointer.time = 0;
+
+       /* see mbuf.c:QueueDisplayRequest for code similar to this */
+
+       if (!ClientSleepUntil(client, &activateTime, NULL, NULL))
+       {
+           return BadAlloc;
+       }
+       /* swap the request back so we can simply re-execute it */
+       if (client->swapped)
+       {
+           (void) XTestSwapFakeInput(client, (xReq *)stuff);
+           swaps(&stuff->length, n);
+       }
+       ResetCurrentRequest (client);
+       client->sequence--;
+       return Success;
+    }
+#ifdef XINPUT
+    if (extension)
+    {
+       dev = LookupDeviceIntRec(stuff->deviceid & 0177);
+       if (!dev)
+       {
+           client->errorValue = stuff->deviceid & 0177;
+           return BadValue;
+       }
+       if (nev > 1)
+       {
+           dv = (deviceValuator *)(ev + 1);
+           if (!dev->valuator || dv->first_valuator >= dev->valuator->numAxes)
+           {
+               client->errorValue = dv->first_valuator;
+               return BadValue;
+           }
+           if (dv->first_valuator + dv->num_valuators >
+               dev->valuator->numAxes)
+           {
+               client->errorValue = dv->num_valuators;
+               return BadValue;
+           }
+       }
+    }
+#endif /* XINPUT */
+    switch (type)
+    {
+    case KeyPress:
+    case KeyRelease:
+#ifdef XINPUT
+       if (!extension)
+#endif /* XINPUT */
+           dev = (DeviceIntPtr)LookupKeyboardDevice();
+       if (ev->u.u.detail < dev->key->curKeySyms.minKeyCode ||
+           ev->u.u.detail > dev->key->curKeySyms.maxKeyCode)
+       {
+           client->errorValue = ev->u.u.detail;
+           return BadValue;
+       }
+       break;
+    case MotionNotify:
+#ifdef XINPUT
+       if (extension)
+       {
+           if (ev->u.u.detail != xFalse && ev->u.u.detail != xTrue)
+           {
+               client->errorValue = ev->u.u.detail;
+               return BadValue;
+           }
+           if (ev->u.u.detail == xTrue && dev->valuator->mode == Absolute)
+           {
+               values = dev->valuator->axisVal + dv->first_valuator;
+               for (n = 1; n < nev; n++)
+               {
+                   dv = (deviceValuator *)(ev + n);
+                   switch (dv->num_valuators)
+                   {
+                   case 6:
+                       dv->valuator5 += values[5];
+                   case 5:
+                       dv->valuator4 += values[4];
+                   case 4:
+                       dv->valuator3 += values[3];
+                   case 3:
+                       dv->valuator2 += values[2];
+                   case 2:
+                       dv->valuator1 += values[1];
+                   case 1:
+                       dv->valuator0 += values[0];
+                   }
+                   values += 6;
+               }
+           }
+           break;
+       }
+#endif /* XINPUT */
+       dev = (DeviceIntPtr)LookupPointerDevice();
+       if (ev->u.keyButtonPointer.root == None)
+           root = GetCurrentRootWindow();
+       else
+       {
+           root = LookupWindow(ev->u.keyButtonPointer.root, client);
+           if (!root)
+               return BadWindow;
+           if (root->parent)
+           {
+               client->errorValue = ev->u.keyButtonPointer.root;
+               return BadValue;
+           }
+       }
+       if (ev->u.u.detail == xTrue)
+       {
+           int x, y;
+           GetSpritePosition(&x, &y);
+           ev->u.keyButtonPointer.rootX += x;
+           ev->u.keyButtonPointer.rootY += y;
+       }
+       else if (ev->u.u.detail != xFalse)
+       {
+           client->errorValue = ev->u.u.detail;
+           return BadValue;
+       }
+       if (ev->u.keyButtonPointer.rootX < 0)
+           ev->u.keyButtonPointer.rootX = 0;
+       else if (ev->u.keyButtonPointer.rootX >= root->drawable.width)
+           ev->u.keyButtonPointer.rootX = root->drawable.width - 1;
+       if (ev->u.keyButtonPointer.rootY < 0)
+           ev->u.keyButtonPointer.rootY = 0;
+       else if (ev->u.keyButtonPointer.rootY >= root->drawable.height)
+           ev->u.keyButtonPointer.rootY = root->drawable.height - 1;
+       if (root != GetCurrentRootWindow())
+       {
+           NewCurrentScreen(root->drawable.pScreen,
+                            ev->u.keyButtonPointer.rootX,
+                            ev->u.keyButtonPointer.rootY);
+           return client->noClientException;
+       }
+       (*root->drawable.pScreen->SetCursorPosition)
+           (root->drawable.pScreen,
+            ev->u.keyButtonPointer.rootX,
+            ev->u.keyButtonPointer.rootY, FALSE);
+       break;
+    case ButtonPress:
+    case ButtonRelease:
+#ifdef XINPUT
+       if (!extension)
+#endif /* XINPUT */
+           dev = (DeviceIntPtr)LookupPointerDevice();
+       if (!ev->u.u.detail || ev->u.u.detail > dev->button->numButtons)
+       {
+           client->errorValue = ev->u.u.detail;
+           return BadValue;
+       }
+       break;
+    }
+    if (screenIsSaved == SCREEN_SAVER_ON)
+       SaveScreens(SCREEN_SAVER_OFF, ScreenSaverReset);
+    ev->u.keyButtonPointer.time = currentTime.milliseconds;
+    (*dev->public.processInputProc)(ev, dev, nev);
+    return client->noClientException;
+}
+
+static int
+ProcXTestGrabControl(client)
+    register ClientPtr client;
+{
+    REQUEST(xXTestGrabControlReq);
+
+    REQUEST_SIZE_MATCH(xXTestGrabControlReq);
+    if ((stuff->impervious != xTrue) && (stuff->impervious != xFalse))
+    {
+       client->errorValue = stuff->impervious;
+        return(BadValue);
+    }
+    if (stuff->impervious)
+       MakeClientGrabImpervious(client);
+    else
+       MakeClientGrabPervious(client);
+    return(client->noClientException);
+}
+
+static int
+ProcXTestDispatch (client)
+    register ClientPtr client;
+{
+    REQUEST(xReq);
+    switch (stuff->data)
+    {
+    case X_XTestGetVersion:
+       return ProcXTestGetVersion(client);
+    case X_XTestCompareCursor:
+       return ProcXTestCompareCursor(client);
+    case X_XTestFakeInput:
+       return ProcXTestFakeInput(client);
+    case X_XTestGrabControl:
+       return ProcXTestGrabControl(client);
+    default:
+       return BadRequest;
+    }
+}
+
+static int
+SProcXTestGetVersion(client)
+    register ClientPtr client;
+{
+    register int n;
+    REQUEST(xXTestGetVersionReq);
+
+    swaps(&stuff->length, n);
+    REQUEST_SIZE_MATCH(xXTestGetVersionReq);
+    swaps(&stuff->minorVersion, n);
+    return ProcXTestGetVersion(client);
+}
+
+static int
+SProcXTestCompareCursor(client)
+    register ClientPtr client;
+{
+    register int n;
+    REQUEST(xXTestCompareCursorReq);
+
+    swaps(&stuff->length, n);
+    REQUEST_SIZE_MATCH(xXTestCompareCursorReq);
+    swapl(&stuff->window, n);
+    swapl(&stuff->cursor, n);
+    return ProcXTestCompareCursor(client);
+}
+
+static int
+XTestSwapFakeInput(client, req)
+    register ClientPtr client;
+    xReq *req;
+{
+    register int nev;
+    register xEvent *ev;
+    xEvent sev;
+    EventSwapPtr proc;
+
+    nev = ((req->length << 2) - sizeof(xReq)) / sizeof(xEvent);
+    for (ev = (xEvent *)&req[1]; --nev >= 0; ev++)
+    {
+       /* Swap event */
+       proc = EventSwapVector[ev->u.u.type & 0177];
+       /* no swapping proc; invalid event type? */
+       if (!proc ||  proc ==  NotImplemented) {
+           client->errorValue = ev->u.u.type;
+           return BadValue;
+       }
+       (*proc)(ev, &sev);
+       *ev = sev;
+    }
+    return Success;
+}
+
+static int
+SProcXTestFakeInput(client)
+    register ClientPtr client;
+{
+    register int n;
+    REQUEST(xReq);
+
+    swaps(&stuff->length, n);
+    n = XTestSwapFakeInput(client, stuff);
+    if (n != Success)
+       return n;
+    return ProcXTestFakeInput(client);
+}
+
+static int
+SProcXTestGrabControl(client)
+    register ClientPtr client;
+{
+    register int n;
+    REQUEST(xXTestGrabControlReq);
+
+    swaps(&stuff->length, n);
+    REQUEST_SIZE_MATCH(xXTestGrabControlReq);
+    return ProcXTestGrabControl(client);
+}
+
+static int
+SProcXTestDispatch (client)
+    register ClientPtr client;
+{
+    REQUEST(xReq);
+    switch (stuff->data)
+    {
+    case X_XTestGetVersion:
+       return SProcXTestGetVersion(client);
+    case X_XTestCompareCursor:
+       return SProcXTestCompareCursor(client);
+    case X_XTestFakeInput:
+       return SProcXTestFakeInput(client);
+    case X_XTestGrabControl:
+       return SProcXTestGrabControl(client);
+    default:
+       return BadRequest;
+    }
+}
diff --git a/Xserver/programs/Xserver/Xext/xtest1.frags b/Xserver/programs/Xserver/Xext/xtest1.frags
new file mode 100644 (file)
index 0000000..bdf7943
--- /dev/null
@@ -0,0 +1,90 @@
+There are several code fragments that need to be placed in the device
+dependent part of the server.  These are described below.  These code
+fragments are device and implementation dependent.
+
+This code fragment should go in your ddx InitInput() routine:
+
+#ifdef XTESTEXT1
+extern KeyCode xtest_command_key;
+#endif
+
+#ifdef XTESTEXT1
+    xtest_command_key = <whatever-is-a-good-keycode-for-your-keyboard>;
+#endif
+
+This code fragment should go at the front of the file that handles
+keyboards:
+
+#ifdef XTESTEXT1
+/*
+ * defined in xtestext1di.c
+ */
+extern int     on_steal_input;
+extern Bool    XTestStealKeyData();
+#endif XTESTEXT1
+
+This code fragment should go in the function that parses input from the
+keyboard or pointer after you know what input action has occurred, but before
+you have told the server about it.  If conditionalizes the actual function
+call to pass the information on:
+
+#ifdef XTESTEXT1
+       if (!on_steal_input ||
+           XTestStealKeyData(code, direction, dev_type, x, y))
+#endif /* XTESTEXT1 */
+       handle_device_event(...);
+
+This code fragment should go in the function that handles mouse motion after
+you have figured out how much the mouse has moved:
+
+#ifdef XTESTEXT1
+       if (on_steal_input)
+           XTestStealMotionData(dx, dy, dev, x, y);
+#endif XTESTEXT1
+
+
+This code fragment should go at the front of the os-specific code where
+you wait (by doing a select on the socket in our implementation) for
+something to happen:
+
+#ifdef XTESTEXT1
+extern int     playback_on;
+void XTestComputeWaitTime();
+#endif  XTESTEXT1
+
+These code fragments should go in the os-specific code on both sides of
+where you wait (by doing a select on the socket in our implementation)
+for something to happen:
+
+#ifdef XTESTEXT1
+           if (playback_on)
+                   XTestComputeWaitTime(wt = &waittime);
+#endif XTESTEXT1
+           ... code to do select ...
+           WakeupHandler(i, LastSelectMask);
+#ifdef XTESTEXT1
+           if (playback_on)
+                   i = XTestProcessInputAction(i, &waittime);
+#endif XTESTEXT1
+
+
+You also need to implement the following routines (documentation
+is needed; for now, see server/ddx/hp/hp/x_hil.c):
+
+void
+XTestGenerateEvent(dev_type, keycode, keystate, mousex, mousey)
+       int     dev_type;
+       int     keycode;
+       int     keystate;
+       int     mousex;
+       int     mousey;
+
+void
+XTestGetPointerPos(fmousex, fmousey)
+       short *fmousex, *fmousey;
+
+void
+XTestJumpPointer(jx, jy, dev_type)
+       int     jx;
+       int     jy;
+       int     dev_type;
diff --git a/Xserver/programs/Xserver/Xext/xtest1dd.c b/Xserver/programs/Xserver/Xext/xtest1dd.c
new file mode 100644 (file)
index 0000000..8edcff9
--- /dev/null
@@ -0,0 +1,1653 @@
+/* $XConsortium: xtest1dd.c,v 1.14 94/04/17 20:33:00 gildea Exp $ */
+/* $XFree86: xc/programs/Xserver/Xext/xtest1dd.c,v 3.0 1996/05/06 05:55:42 dawes Exp $ */
+/*
+ *     File: xtest1dd.c
+ *
+ *     This file contains the device dependent parts of the input
+ *     synthesis extension.
+ */
+
+/*
+
+
+Copyright (c) 1986, 1987, 1988   X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+
+Copyright 1986, 1987, 1988 by Hewlett-Packard Corporation
+
+Permission to use, copy, modify, and distribute this
+software and its documentation for any purpose and without
+fee is hereby granted, provided that the above copyright
+notice appear in all copies and that both that copyright
+notice and this permission notice appear in supporting
+documentation, and that the name of Hewlett-Packard not be used in
+advertising or publicity pertaining to distribution of the
+software without specific, written prior permission.
+
+Hewlett-Packard makes no representations about the 
+suitability of this software for any purpose.  It is provided 
+"as is" without express or implied warranty.
+
+This software is not subject to any license of the American
+Telephone and Telegraph Company or of the Regents of the
+University of California.
+
+*/
+
+/***************************************************************
+ * include files
+ ***************************************************************/
+
+#define        NEED_EVENTS
+#define        NEED_REPLIES
+
+#include <stdio.h>
+#include "Xos.h"
+#include "X.h"
+#include "Xmd.h"
+#include "Xproto.h"
+#include "misc.h"
+#include "dixstruct.h"
+#define  XTestSERVER_SIDE
+#include "xtestext1.h" 
+
+#include "xtest1dd.h"
+
+/***************************************************************
+ * defines
+ ***************************************************************/
+
+/*
+ * the size of the fake input action array
+ */
+#define ACTION_ARRAY_SIZE      100
+
+/***************************************************************
+ * externals
+ ***************************************************************/
+
+/*
+ * Holds the xTestInputAction event type code.
+ * This is defined in xtestext1di.c.
+ */
+extern int                     XTestInputActionType;
+/*
+ * Holds the xTestFakeAck event type code.
+ * This is defined in xtestext1di.c.
+ */
+extern int                     XTestFakeAckType;
+/*
+ * used in the WriteReplyToClient macro
+ */
+extern int                     exclusive_steal;
+
+/***************************************************************
+ * variables
+ ***************************************************************/
+
+/*
+ * array to hold fake input actions
+ */
+struct {
+       /*
+        * holds the action type, one of: XTestDELAY_ACTION,
+        * XTestKEY_ACTION, XTestMOTION_ACTION, XTestJUMP_ACTION
+        */
+       CARD8   type;   
+       /*
+        * holds the device type, in the range 0 to 15
+        */
+       CARD8   device;
+       /*
+        * for XTestKEY_ACTION type, holds the keycode
+        */
+       CARD8   keycode;
+       /*
+        * for XTestKEY_ACTION type, holds the key up/down state
+        */
+       CARD8   keystate;
+       /*
+        * for XTestMOTION_ACTION and XTestJUMP_ACTION types,
+        * holds the x and y coordinates to move the mouse to
+        */
+       int     x;
+       int     y;
+       /*
+        * holds the time to delay (in milliseconds) before performing
+        * the action
+        */
+       CARD32  delay_time;
+}action_array[ACTION_ARRAY_SIZE];
+
+/*
+ * write index for input action array
+ */
+static int                     write_index = 0;
+/*
+ * read index for input action array
+ */
+static int                     read_index = 0;
+/*
+ * this is where the input actions are accumulated until they are sent
+ * to a client (in a wire event)
+ */
+static xTestInputActionEvent   input_action_packet;
+/*
+ * holds the index (in bytes) into the input actions buffer in the
+ * current input action event
+ */
+static int                     packet_index;
+/*
+ * set to 1 when the input action event is full and needs to be sent to the 
+ * client
+ */
+static int                     input_action_event_full = 0;
+/*
+ * logical x position of the mouse during input action gathering
+ */
+short                          xtest_mousex;
+/*
+ * logical y position of the mouse during input action gathering
+ */
+short                          xtest_mousey;
+/*
+ * logical x position of the mouse during input action playback
+ */
+static short                   mx;
+/*
+ * logical y position of the mouse during input action playback
+ */
+static short                   my;
+/*
+ * logical x position of the mouse while we are reading fake input actions
+ * from the client and putting them into the fake input action array
+ */
+static short                   pmousex;
+/*
+ * logical y position of the mouse while we are reading fake input actions
+ * from the client and putting them into the fake input action array
+ */
+static short                   pmousey;
+/*
+ * The playback_on flag is set to 1 while there are input actions in the 
+ * input action array.  It is set to 0 when the server has received all of
+ * the user actions.
+ */
+int                    playback_on = 0;
+/*
+ * identity of the client using XTestGetInput to get user input actions
+ */
+ClientPtr              current_xtest_client;
+/*
+ * if 1 send multiple input actions per XTestInputAction event;
+ * if 0 send one input action per XTestInputAction event
+ */
+static char                    packed_mode;
+/*
+ * identity of the client using the XTestFakeInput function to send some
+ * fake input actions to the server
+ */
+ClientPtr              playback_client = NULL;
+/*
+ * Set to 1 when the XTestFAKE_ACK_REQUEST flag is set in a XTestFakeInput
+ * request.  Set back to 0 when all of the input actions have been sent
+ * to the server.
+ */
+static int                     acknowledge = 0;
+/*
+ * The server's idea of the current time is saved in these variables when
+ * a XTestFakeInput request is received.  It is restored when all fake input
+ * actions are sent to the server or when the playback client disconnects.
+ */
+static int                     saved_sec;
+static int                     saved_usec;
+/*
+ * Set to 1 when there is a valid time in saved_sec and saved_usec.
+ */
+static int                     time_saved = 0;
+/*
+ * holds the extension's notion of what the current time is while it is 
+ * sending input actions to a client
+ */
+static struct timeval          current_time;
+/*
+ * holds the time when the extension should place the next fake input action
+ * into the server's normal events queue
+ */
+static struct timeval          play_time;
+/*
+ * set to 1 when play_time is first set, cleared to 0 when the
+ * client using the extension disconnects, or when XTestReset is called
+ */
+static char                    play_clock = 0;
+/*
+ * holds the amount of time left until the next input action from the
+ * input action array can be sent to the server
+ */
+static struct timeval          rtime;
+/*
+ * Set to 1 after the extension is done waiting for the correct time delay
+ * for an input action to be sent to the server.  Remains a 1 until the time
+ * delay for the next input action is computed.  Then set to 0 if the
+ * extension has to wait for the correct time delay.
+ */
+static int                     go_for_next = 1;
+/*
+ * needed to restore waitime if playback is to be aborted
+ */
+static struct timeval          *restorewait;
+/*
+ * tmon special command key
+ *
+ * To use the test monitor program (called tmon) efficiently, it is
+ * desirable to have the extension be able to recognize a special "trigger"
+ * key.  If the extension did not do this, tmon would have to have the
+ * extension send all keyboard user input actions exclusively to tmon,
+ * only to have tmon send them right back if they were not the command key.
+ *
+ * If the extension can recognize the command key, then tmon can let the
+ * extension handle keyboard user input actions normally until the command
+ * key is pressed (and released), and only then have the extension start
+ * sending keyboard user input actions exclusively to tmon.
+ *
+ * Any key on the keyboard can be used for this command key.  It is most
+ * convenient if it is a low-frequency key.  If you want to generate a
+ * normal occurrance of this key to a client, just hit it twice.  Tmon
+ * will recognize the first occurrance of the key, take control of the input
+ * actions, and wait for certain keys.  If it sees another occurrance of the
+ * command key, it will send one occurrance of the command key to the
+ * extension, and go back to waiting.
+ *
+ * set and also referenced in device layer
+ * XXX there should be a way to set this through the protocol
+ */
+KeyCode                        xtest_command_key = 0;
+
+/***************************************************************
+ * function declarations
+ ***************************************************************/
+
+static void    parse_key_fake(
+#if NeedFunctionPrototypes
+                       XTestKeyInfo    * /* fkey */
+#endif
+                       );
+static void    parse_motion_fake(
+#if NeedFunctionPrototypes
+                       XTestMotionInfo * /* fmotion */
+#endif
+                       );
+static void    parse_jump_fake(
+#if NeedFunctionPrototypes
+                       XTestJumpInfo   * /* fjump */
+#endif
+                       );
+static void    parse_delay_fake(
+#if NeedFunctionPrototypes
+                       XTestDelayInfo  * /* tevent */
+#endif
+                       );
+static void    send_ack(
+#if NeedFunctionPrototypes
+                       ClientPtr        /* client */
+#endif
+                       );
+static void    start_play_clock(
+#if NeedFunctionPrototypes
+                       void
+#endif
+                       );
+static void    compute_action_time(
+#if NeedFunctionPrototypes
+                       struct timeval  * /* rtime */
+#endif
+                       );
+static int     find_residual_time(
+#if NeedFunctionPrototypes
+                       struct timeval  * /* rtime */
+#endif
+                       );
+
+static CARD16  check_time_event(
+#if NeedFunctionPrototypes
+                       void
+#endif
+                       );
+static CARD32  current_ms(
+#if NeedFunctionPrototypes
+                       struct timeval  * /* otime */
+#endif
+                       );
+static int     there_is_room(
+#if NeedFunctionPrototypes
+                       int     /* actsize */
+#endif
+                       );
+
+/******************************************************************************
+ *
+ *     stop_stealing_input
+ *
+ *     Stop stealing input actions.
+ */
+void
+stop_stealing_input()
+{
+/*
+ * put any code that you might need to stop stealing input actions here
+ */
+       if (packet_index != 0) 
+       {
+               /*
+                * if there is a partially full input action event waiting
+                * when this function is called, send it to the client
+                */
+               flush_input_actions();
+       }
+}
+
+/******************************************************************************
+ *
+ *     steal_input
+ *
+ *     Start stealing input actions and sending them to the passed-in client.
+ */
+void
+steal_input(client, mode)
+/*
+ * which client is to receive the input action events
+ */
+ClientPtr      client;
+/*
+ * what input action packing mode to use.  one of 0, XTestPACKED_MOTION,
+ * or XTestPACKED_ACTIONS; optionally 'or'ed with XTestEXCLUSIVE,
+ */
+CARD32         mode;
+{
+       if (packet_index != 0) 
+       {
+               /*
+                * if there is a partially full input action event waiting
+                * when this function is called, send it to the client
+                */
+               flush_input_actions();
+       }
+       else
+       {       
+               /*
+                * otherwise, set up a new input action event
+                */
+               input_action_packet.type = XTestInputActionType;
+               packet_index = 0;
+       }
+       /*
+        * set up the new input action packing mode
+        */
+       packed_mode = mode & ~(XTestEXCLUSIVE);
+       /*
+        * keep track of where the mouse is
+        */
+       XTestGetPointerPos(&xtest_mousex, &xtest_mousey);
+       /*
+        * keep track of which client is getting input actions
+        */
+       current_xtest_client = client;
+       /*
+        * find out what time it is
+        */
+       X_GETTIMEOFDAY(&current_time);
+       /*
+        * jump to the initial position of the mouse, using a device type of 0.
+        */
+       XTestStealJumpData(xtest_mousex, xtest_mousey, 0);
+}
+       
+/******************************************************************************
+ *
+ *     flush_input_actions
+ *
+ *     Write the input actions event to the current requesting client
+ *     and re-initialize the input action event.
+ */
+void
+flush_input_actions()
+{
+       /*
+        * pointer to the input action event
+        */
+       char                    *rep;
+       /*
+        * loop index
+        */
+       int                     i;
+
+       if (packet_index == 0)
+       {
+               /*
+                * empty input actions event 
+                */
+               return;
+       }
+       else if (packet_index < XTestACTIONS_SIZE)
+       {
+               /*
+                * fill to the end of the input actions event with 0's
+                */
+               for (i = packet_index; i <XTestACTIONS_SIZE; i++)
+               {
+                       input_action_packet.actions[i] = 0;
+               }
+       }
+       rep = (char *) (&input_action_packet);
+
+       /*
+        * set the serial number of the input action event
+        */
+       input_action_packet.sequenceNumber = current_xtest_client->sequence;
+       /*
+        * send the input action event to the client
+        */
+       WriteEventsToClient(current_xtest_client, 1, (xEvent *) rep);
+       /*
+        * re-initialize the input action event
+        */
+       input_action_event_full = 0;
+       input_action_packet.type = XTestInputActionType;
+       packet_index = 0;
+}      
+
+/******************************************************************************
+ *
+ *     XTestStealJumpData
+ *
+ *     Create one or more input actions and put them in the input action
+ *     event.  The input actions will be an (maybe) XTestDELAY_ACTION
+ *     and an XTestJUMP_ACTION.
+ */
+void
+XTestStealJumpData(jx, jy, dev_type)
+/*
+ * the x and y coordinates to jump to
+ */
+short  jx;
+short  jy;
+/*
+ * which device caused the jump
+ */
+int    dev_type;
+{      
+       XTestJumpInfo   *jmp_ptr;
+       /*
+        * time delta (in ms) from previous event
+        */
+       CARD16                  tchar;
+
+       /*
+        * Get the time delta from the previous event.  If needed,
+        * the check_time_event routine will put an XTestDELAY_ACTION
+        * type action in the input action event.
+        */
+       tchar = check_time_event();
+       if (!there_is_room(sizeof(XTestJumpInfo)))
+       {
+               /*
+                * If there isn't room in the input action event for
+                * an XTestJUMP_ACTION, then send that event to the
+                * client and start filling an empty one.
+                */
+               flush_input_actions();
+       }
+       /*
+        * update the logical mouse position
+        */
+       xtest_mousex = jx;
+       xtest_mousey = jy;
+       /*
+        * point jmp_ptr to the correct place in the input action event
+        */
+       jmp_ptr = (XTestJumpInfo *)
+                 &(input_action_packet.actions[packet_index]);
+       /*
+        * compute the input action header
+        */
+       jmp_ptr->header = (XTestPackDeviceID(dev_type) | XTestJUMP_ACTION);     
+       /*
+        * set the x and y coordinates to jump to in the input action
+        */
+       jmp_ptr->jumpx = jx;
+       jmp_ptr->jumpy = jy;
+       /*
+        * set the delay time in the input action
+        */
+       jmp_ptr->delay_time = tchar;
+       /*
+        * increment the packet index by the size of the input action
+        */
+       packet_index = packet_index + sizeof(XTestJumpInfo);
+       if (packed_mode == 0)
+       {
+               /*
+                * if input actions are not packed, send the input
+                * action event to the client
+                */
+               flush_input_actions();
+       }
+}      
+
+/******************************************************************************
+ *
+ *     current_ms
+ *
+ *     Returns the number of milliseconds from the passed-in time to the
+ *     current time, and then updates the passed-in time to the current time.
+ */
+static CARD32
+current_ms(otime)
+struct timeval *otime;
+{      
+       struct timeval  tval;
+       unsigned long   the_ms;
+       unsigned long   sec;
+       unsigned long   usec;
+
+       /*
+        * get the current time
+        */
+       X_GETTIMEOFDAY(&tval);
+       if (tval.tv_usec < otime->tv_usec)
+       {
+               /*
+                * borrow a second's worth of microseconds if needed
+                */
+               usec = tval.tv_usec - otime->tv_usec + 1000000;
+               sec = tval.tv_sec - 1 - otime->tv_sec;
+       }
+       else
+       {
+               usec = tval.tv_usec - otime->tv_usec;
+               sec = tval.tv_sec - otime->tv_sec;
+       }
+       /*
+        * update the passed-in time to the new time
+        */
+       *otime = tval;
+       /*
+        * compute the number of milliseconds contained in
+        * 'sec' seconds and 'usec' microseconds
+        */
+       the_ms = (sec * 1000000L + usec) / 1000L;
+       return (the_ms);
+}
+
+/******************************************************************************
+ *
+ *     check_time_event
+ *
+ *     If time delta is > XTestSHORT_DELAY_TIME then insert a time event
+ *     and return 0; else return the delay time.
+ */
+static CARD16
+check_time_event()
+{
+       CARD32          tstamp;
+       CARD16          tchar;
+       XTestDelayInfo  *tptr;
+
+       /*
+        * get the number of milliseconds between input actions
+        */
+       tstamp = current_ms(&current_time);
+       /*
+        * if the number of milliseconds is too large to fit in a CARD16,
+        * then add a XTestDELAY_ACTION to the input action event.
+        */
+       if (tstamp > XTestSHORT_DELAY_TIME)
+       {
+               /*
+                * If there isn't room in the input action event for
+                * an XTestDELAY_ACTION, then send that event to the
+                * client and start filling an empty one.
+                */
+               if (!there_is_room(sizeof(XTestDelayInfo)))
+               {
+                       flush_input_actions();
+               }
+               /*
+                * point tptr to the correct place in the input action event
+                */
+               tptr = (XTestDelayInfo *)
+                      (&(input_action_packet.actions[packet_index]));
+               /*
+                * compute the input action header
+                */
+               tptr->header = XTestPackDeviceID(XTestDELAY_DEVICE_ID) |
+                              XTestDELAY_ACTION;
+               /*
+                * set the delay time in the input action
+                */
+               tptr->delay_time = tstamp;
+               /*
+                * increment the packet index by the size of the input action
+                */
+               packet_index = packet_index + (sizeof(XTestDelayInfo));
+               if (packed_mode != XTestPACKED_ACTIONS) 
+               {
+                       /*
+                        * if input actions are not packed, send the input
+                        * action event to the client
+                        */
+                       flush_input_actions();
+               }
+               /*
+                * set the returned delay time to 0
+                */
+               tchar = 0;
+       }
+       else
+       {
+               /*
+                * set the returned delay time to the computed delay time
+                */
+               tchar = tstamp;
+       }
+       return(tchar);
+}
+
+/******************************************************************************
+ *
+ *     there_is_room
+ *
+ *     Checks if there is room in the input_action_packet for an input action
+ *     of the size actsize bytes.  Returns 1 if there is space, 0 otherwise.
+ *
+ */
+static int
+there_is_room(actsize)
+/*
+ * the number of bytes of space needed
+ */
+int    actsize;
+{
+       if ((packet_index + actsize) > XTestACTIONS_SIZE)
+       { 
+               input_action_event_full = 1;
+               return(0);
+       }
+       else
+       {
+               return(1);
+       }
+}
+
+/******************************************************************************
+ *
+ *     XTestStealMotionData
+ *
+ *     Put motion information from the locator into an input action.
+ *
+ *     called from x_hil.c
+ */
+void
+XTestStealMotionData(dx, dy, dev_type, mx, my)
+/*
+ * the x and y delta motion of the locator
+ */
+short  dx;
+short  dy;
+/*
+ * which locator did the moving
+ */
+int    dev_type;
+/*
+ * the x and y position of the locator before the delta motion
+ */
+short  mx;
+short  my;
+{
+       /*
+        * pointer to a XTestMOTION_ACTION input action
+        */
+       XTestMotionInfo *fm;
+       /*
+        * time delta from previous event
+        */
+       CARD16                  tchar;
+
+       /*
+        * if the current position of the locator is not the same as
+        * the logical position, then update the logical position
+        */
+       if ((mx != xtest_mousex) || (my != xtest_mousey))
+       {
+               XTestStealJumpData(mx, my, dev_type);
+       }
+       /*
+        * if the delta motion is outside the range that can
+        * be held in a motion input action, use a jump input action
+        */
+       if ((dx > XTestMOTION_MAX) || (dx < XTestMOTION_MIN) ||
+           (dy > XTestMOTION_MAX) || (dy < XTestMOTION_MIN))
+       {
+               XTestStealJumpData((xtest_mousex + dx),
+                                  (xtest_mousey + dy), dev_type);
+       }
+       else
+       { 
+               /*
+                * compute the new logical position of the mouse
+                */
+               xtest_mousex += dx;
+               xtest_mousey += dy;
+               /*
+                * Get the time delta from the previous event.  If needed,
+                * the check_time_event routine will put an XTestDELAY_ACTION
+                * type action in the input action event.
+                */
+               tchar = check_time_event();
+               /*
+                * If there isn't room in the input action event for
+                * an XTestDELAY_ACTION, then send that event to the
+                * client and start filling an empty one.
+                */
+               if (!there_is_room(sizeof(XTestMotionInfo)))
+               {
+                       flush_input_actions();
+               /*
+                * point fm to the correct place in the input action event
+                */
+               }
+               fm = (XTestMotionInfo *)
+                    &(input_action_packet.actions[packet_index]);
+               /*
+                * compute the input action header
+                */
+               fm->header = XTestMOTION_ACTION;
+               if (dx < 0)     
+               {  
+                       fm->header |= XTestX_NEGATIVE;
+                       dx = abs(dx);
+               }
+               if (dy < 0)   
+               {  
+                       fm->header |= XTestY_NEGATIVE;
+                       dy = abs(dy);
+               }
+               fm->header |= XTestPackDeviceID(dev_type);
+               /*
+                * compute the motion data byte
+                */
+               fm->motion_data = XTestPackYMotionValue(dy);
+               fm->motion_data |= XTestPackXMotionValue(dx);
+               /*
+                * set the delay time in the input action
+                */
+               fm->delay_time = tchar;
+               /*
+                * increment the packet index by the size of the input action
+                */
+               packet_index = packet_index + sizeof(XTestMotionInfo);
+               if (packed_mode == 0)
+               {
+                       /*
+                        * if input actions are not packed, send the input
+                        * action event to the client
+                        */
+                       flush_input_actions();
+               }
+
+       }   
+}
+
+/******************************************************************************
+ *
+ *     XTestStealKeyData
+ *
+ *     Place this key data in the input_action_packet.
+ *
+ */
+Bool
+XTestStealKeyData(keycode, keystate, dev_type, locx, locy)
+/*
+ * which key/button moved
+ */
+CARD8  keycode;
+/*
+ * whether the key/button was pressed or released
+ */
+char   keystate;
+/*
+ * which device caused the input action
+ */
+int    dev_type;
+/*
+ * the x and y coordinates of the locator when the action happenned
+ */
+short  locx;
+short  locy;
+{
+       /*
+        * pointer to key/button motion input action
+        */
+       XTestKeyInfo    *kp;
+       /*
+        * time delta from previous event
+        */
+       CARD16                  tchar;
+       char            keytrans;
+
+       /*
+        * update the logical position of the locator if the physical position
+        * of the locator is not the same as the logical position.
+        */
+       if ((locx != xtest_mousex) || (locy != xtest_mousey))
+       {
+               XTestStealJumpData(locx, locy, dev_type);
+       }
+       /*
+        * Get the time delta from the previous event.  If needed,
+        * the check_time_event routine will put an XTestDELAY_ACTION
+        * type action in the input action event.
+        */
+       tchar = check_time_event();
+       if (!there_is_room(sizeof(XTestKeyInfo)))
+       {
+               /*
+                * If there isn't room in the input action event for
+                * an XTestDELAY_ACTION, then send that event to the
+                * client and start filling an empty one.
+                */
+               flush_input_actions();
+       }
+       /*
+        * point kp to the correct place in the input action event
+        */
+       kp = (XTestKeyInfo *)
+            (&(input_action_packet.actions[packet_index]));
+       /*
+        * compute the input action header
+        */
+       kp->header = XTestPackDeviceID(dev_type);
+       if ((keystate == KeyRelease) || (keystate == ButtonRelease))
+       {
+               keytrans = XTestKEY_UP;
+       }
+       else if ((keystate == KeyPress) || (keystate == ButtonPress))
+       {
+               keytrans = XTestKEY_DOWN;
+       }
+       else
+       {
+               printf("%s: invalid key/button state %d.\n",
+                      XTestEXTENSION_NAME,
+                      keystate);
+       }
+       kp->header = kp->header | keytrans | XTestKEY_ACTION;
+       /*
+        * set the keycode in the input action
+        */
+       kp->keycode = keycode;
+       /*
+        * set the delay time in the input action
+        */
+       kp->delay_time = tchar;
+       /*
+        * increment the packet index by the size of the input action
+        */
+       packet_index = packet_index + sizeof(XTestKeyInfo);
+       /*
+        * if the command key has been released or input actions are not
+        * packed, send the input action event to the client
+        */
+       if(((keycode == xtest_command_key) && (keystate == KeyRelease)) ||
+          (packed_mode != XTestPACKED_ACTIONS))
+       {       
+               flush_input_actions();
+       }
+       /* return TRUE if the event should be passed on to DIX */
+       if (exclusive_steal)
+               return ((keystate == KeyRelease) &&
+                       (keycode == xtest_command_key));
+       else
+               return ((keystate != KeyRelease) ||
+                       (keycode != xtest_command_key));
+}
+
+/******************************************************************************
+ *
+ *     parse_fake_input
+ *
+ *     Parsing routine for a XTestFakeInput request.  It will take a request
+ *     and parse its contents into the input action array.  Eventually the
+ *     XTestProcessInputAction routine will be called to take input actions
+ *     from the input action array and send them to the server to be handled.
+ */
+void
+parse_fake_input(client, req)
+/*
+ * which client did the XTestFakeInput request
+ */
+ClientPtr      client;
+/*
+ * a pointer to the xTestFakeInputReq structure sent by the client
+ */
+char           *req;
+{      
+       /*
+        * if set to 1, done processing input actions from the request
+        */
+       int                     done = 0;
+       /*
+        * type of input action
+        */
+       CARD8                   action_type;
+       /*
+        * device type
+        */
+       CARD8                   dev_type;
+       /*
+        * pointer to an xTestFakeInputReq structure
+        */
+       xTestFakeInputReq       *request;
+       /*
+        * holds the index into the action list in the request
+        */
+       int                     parse_index;    
+
+       /*
+        * get a correct-type pointer to the client-supplied request data
+        */
+       request = (xTestFakeInputReq *) req;
+       /*
+        * save the acknowledge requested state for use in
+        * XTestProcessInputAction
+        */
+       acknowledge = request->ack;
+       /*
+        * set up an index into the action list in the request
+        */
+       parse_index = 0;
+       if (write_index >= ACTION_ARRAY_SIZE)
+       {
+               /*
+                * if the input action array is full, don't add any more
+                */
+               done = 1;
+       }
+       while (!done)
+       { 
+               /*
+                * get the type of input action in the list
+                */
+               action_type = (request->action_list[parse_index])
+                             & XTestACTION_TYPE_MASK;
+               /*
+                * get the type of device in the list
+                */
+               dev_type = XTestUnpackDeviceID(request->action_list[parse_index]);
+               /*
+                * process the input action appropriately
+                */
+               switch (action_type)
+               { 
+               case XTestKEY_ACTION:
+                       parse_key_fake((XTestKeyInfo *)
+                                      &(request->action_list[parse_index]));
+                       parse_index = parse_index + sizeof(XTestKeyInfo);
+                       break;
+               case XTestMOTION_ACTION:
+                       parse_motion_fake((XTestMotionInfo *)
+                                         &(request->action_list[parse_index]));
+                       parse_index = parse_index + sizeof(XTestMotionInfo);
+                       break;
+               case XTestJUMP_ACTION:
+                       parse_jump_fake((XTestJumpInfo *)
+                                       &(request->action_list[parse_index]));
+                       parse_index = parse_index + sizeof(XTestJumpInfo);
+                       break;
+               case XTestDELAY_ACTION:
+                       if (dev_type == XTestDELAY_DEVICE_ID)
+                       { 
+                               parse_delay_fake((XTestDelayInfo *)
+                                                &(request->action_list[parse_index]));
+                               parse_index = parse_index +
+                                             sizeof(XTestDelayInfo);
+                       }
+                       else
+                       { 
+                               /*
+                                * An invalid input action header byte has
+                                * been detected, so there are no more
+                                * input actions in this request.
+                                * The intended invalid action header byte
+                                * for this case should have a value of 0.
+                                */
+                               done = 1;
+                       }
+                       break;
+               }
+               if (parse_index >= XTestMAX_ACTION_LIST_SIZE)
+               {
+                       /*
+                        * entire XTestFakeInput request has been processed
+                        */
+                       done = 1;
+               }
+               if (write_index >= ACTION_ARRAY_SIZE) 
+               {
+                       /*
+                        * no room in the input actions array
+                        */
+                       done = 1;
+               }
+       }
+       if (write_index > read_index)
+       { 
+               /*
+                * there are fake input actions in the input action array
+                * to be given to the server
+                */
+               playback_on = 1;
+               playback_client = client;
+       } 
+}
+
+/******************************************************************************
+ *
+ *     parse_key_fake
+ *
+ *     Called from parse_fake_input.
+ *
+ *     Copy the fake key input action from its packed form into the array of
+ *     pending input events.
+ */
+static void
+parse_key_fake(fkey)
+XTestKeyInfo   *fkey;
+{      
+       action_array[write_index].type = XTestKEY_ACTION;
+       action_array[write_index].device = XTestUnpackDeviceID(fkey->header);
+       action_array[write_index].keycode = fkey->keycode;
+       action_array[write_index].keystate = fkey->header & XTestKEY_STATE_MASK;
+       action_array[write_index].delay_time = fkey->delay_time;
+       write_index++;
+}
+
+/******************************************************************************
+ *
+ *     parse_motion_fake
+ *
+ *     Called from parse_fake_input.
+ *
+ *     Copy the fake motion input action from its packed form into the array of
+ *     pending input events.
+ */
+static void
+parse_motion_fake(fmotion)
+XTestMotionInfo        *fmotion;
+{      
+       int     dx;
+       int     dy;
+
+       dx = (XTestUnpackXMotionValue(fmotion->motion_data));
+       dy = (XTestUnpackYMotionValue(fmotion->motion_data));
+       if (((fmotion->header) & XTestX_SIGN_BIT_MASK) == XTestX_NEGATIVE)
+       {
+               pmousex -= dx;
+       }
+       else
+       {
+               pmousex += dx;
+       }
+       if (((fmotion->header) & XTestY_SIGN_BIT_MASK) == XTestY_NEGATIVE)
+       {
+               pmousey -= dy;
+       }
+       else 
+       {
+               pmousey += dy;
+       }
+       action_array[write_index].type = XTestJUMP_ACTION;
+       action_array[write_index].device = XTestUnpackDeviceID(fmotion->header);
+       action_array[write_index].x = pmousex;
+       action_array[write_index].y = pmousey;
+       action_array[write_index].delay_time = fmotion->delay_time;
+       write_index++;
+}
+
+/******************************************************************************
+ *
+ *     parse_jump_fake
+ *
+ *     Called from parse_fake_input.
+ *
+ *     Copy the fake jump input action from its packed form into the array of
+ *     pending input events.
+ */
+static void
+parse_jump_fake(fjump)
+XTestJumpInfo  *fjump;
+{
+       pmousex = fjump->jumpx;
+       pmousey = fjump->jumpy;
+       action_array[write_index].type = XTestJUMP_ACTION;
+       action_array[write_index].device = XTestUnpackDeviceID(fjump->header);
+       action_array[write_index].x = pmousex;
+       action_array[write_index].y = pmousey;
+       action_array[write_index].delay_time = fjump->delay_time;
+       write_index++;
+}
+
+/******************************************************************************
+ *
+ *     parse_delay_fake
+ *
+ *     Called from parse_fake_input.
+ *
+ *     Copy the fake delay input action from its packed form into the array of
+ *     pending input events.
+ */
+static void
+parse_delay_fake(tevent)
+XTestDelayInfo *tevent;
+{
+       action_array[write_index].type = XTestDELAY_ACTION;
+       action_array[write_index].delay_time = tevent->delay_time;
+       write_index++;
+}
+
+/******************************************************************************
+ *
+ *     XTestComputeWaitTime
+ *
+ *     Compute the amount of time the server should wait before sending the
+ *     next monitor event in playback mode.
+ */
+void
+XTestComputeWaitTime(waittime)
+struct timeval *waittime;
+{      
+       /*
+        * The playback_on flag is set to 1 in parse_fake_input.  It is set to
+        * 0 in XTestProcessInputAction if the server has replayed all input
+        * actions.
+        */
+       if (playback_on)
+       {  
+               if (!play_clock)
+               {
+                       /*
+                        * if the playback clock has never been set,
+                        * then do it now
+                        */
+                       start_play_clock();
+               }
+               /*
+                * We need to save the waittime the first time through.  This
+                * is a value the server uses, and we have to restore it when
+                * all of the input actions are processed by the server.
+                */
+               if (!time_saved)
+               {
+                       saved_sec = waittime->tv_sec;
+                       saved_usec = waittime->tv_usec; 
+                       time_saved = 1;
+               }       
+               if (go_for_next) 
+               {
+                       /*
+                        * if we just processed an input action, figure out
+                        * how long to wait for the next input action
+                        */
+                       compute_action_time(&rtime);
+               }
+               else  
+               {
+                       /*
+                        * else just find out how much more time to wait
+                        * on the current input action
+                        */
+                       (void)find_residual_time(&rtime);
+               }
+               waittime->tv_sec = rtime.tv_sec;
+               waittime->tv_usec = rtime.tv_usec;
+       }
+}
+
+/******************************************************************************
+ *
+ *     XTestProcessInputAction
+ *
+ *     If there are any input actions in the input action array,
+ *     then take one out and process it.
+ *
+ */
+int
+XTestProcessInputAction(readable, waittime)
+/*
+ * This is the value that a 'select' function returned just before this
+ * routine was called.  If the select timed out, this value will be 0.
+ *
+ * This extension modifies the select call's timeout value to cause the
+ * select to time out when the next input action is ready to given to
+ * the server.  This routine is called immediately after the select, to 
+ * give it a chance to process an input action.  If we have an input action
+ * to process and the only reason that the select returned was because it
+ * timed out, then we change the select value to 1 and return 1 instead of 0.
+ */
+int            readable;
+/*
+ * this is the timeout value that the select was called with
+ */
+struct timeval *waittime;
+{      
+int mousex, mousey;
+       /*
+        * if playback_on is 0, then the input action array is empty
+        */
+       if (playback_on)
+       { 
+               restorewait = waittime;
+               /*
+                * figure out if we need to wait for the next input action
+                */
+               if (find_residual_time(&rtime) > 0) 
+               {
+                       /*
+                        * still have to wait before processing the current
+                        * input action
+                        */
+                       go_for_next = 0;
+               }
+               else 
+               {
+                       /*
+                        * don't have to wait any longer before processing
+                        * the current input action
+                        */
+                       go_for_next = 1;
+               }
+               /*
+                * if we have an input action to process and the only reason
+                * that the select returned was because it timed out, then we
+                * change the select value to 1 and return 1 instead of 0
+                */
+               if (readable == 0) 
+               {
+                       readable++;                     
+               }
+               /*
+                * if we don't need to wait, then get an input action from
+                * the input action array and process it
+                */
+               if (go_for_next)
+               {  
+                       /*
+                        * There are three possible types of input actions in
+                        * the input action array (motion input actions are
+                        * converted to jump input actions before being put
+                        * into the input action array).  Delay input actions 
+                        * are processed by the compute_action_time function
+                        * which is called from XTestComputeWaitTime.  The
+                        * other two types of input actions are processed here.
+                        */
+                       if (action_array[read_index].type == XTestJUMP_ACTION)
+                       {       
+                               XTestJumpPointer(
+                                       action_array[read_index].x, 
+                                       action_array[read_index].y, 
+                                       action_array[read_index].device);
+                               mx = action_array[read_index].x;
+                               my = action_array[read_index].y;
+                       }
+                       if (action_array[read_index].type == XTestKEY_ACTION)
+                           {
+                           GetSpritePosition(&mousex, &mousey);
+                           XTestGenerateEvent(
+                                    action_array[read_index].device, 
+                                    action_array[read_index].keycode, 
+                                    action_array[read_index].keystate,
+                                    mousex,
+                                    mousey);
+                           }
+                       read_index++;
+                       /*
+                        * if all input actions are processed, then restore 
+                        * the server state 
+                        */
+                       if (read_index >= write_index)
+                       { 
+                               waittime->tv_sec = saved_sec;
+                               waittime->tv_usec = saved_usec;
+                               time_saved = 0;
+                               playback_on = 0;
+                               if (acknowledge) 
+                               { 
+                                       /*
+                                        * if the playback client is waiting
+                                        * for an xTestFakeAck event, send
+                                        * it to him
+                                        */
+                                       send_ack(playback_client);              
+                                       acknowledge = 0;
+                               }
+                               write_index = 0;
+                               read_index = 0;
+                               playback_client = (ClientPtr) NULL;
+                               play_clock = 0;
+                       }
+               }
+       }
+       return(readable);
+}
+
+/******************************************************************************
+ *
+ *     send_ack
+ *
+ *     send an xTestFakeAck event to the client
+ */
+static void
+send_ack(client)
+ClientPtr      client;
+{
+       xTestFakeAckEvent  rep;
+
+       /*
+        * set the serial number of the xTestFakeAck event
+        */
+       rep.sequenceNumber = client->sequence;
+       rep.type = XTestFakeAckType;
+       WriteEventsToClient(client, 1, (xEvent *) &rep);                
+}              
+
+/******************************************************************************
+ *
+ *     start_play_clock
+ *
+ *     start the clock for play back.
+ */
+static void
+start_play_clock()
+{
+       X_GETTIMEOFDAY(&play_time);
+       /*
+        * flag that play_time is valid
+        */
+       play_clock = 1;
+}
+
+/******************************************************************************
+ *
+ *     compute_action_time
+ *
+ *     Set the play clock to the time when the next input action should be put
+ *     into the server's input queue.  Fill the rtime structure with values
+ *     for the delta until the time for the next input action.
+ */
+static void
+compute_action_time(rtime)
+struct timeval *rtime;
+{
+       /*
+        * holds the delay time in milliseconds
+        */
+       unsigned long   dtime;
+       /*
+        * holds the number of microseconds in the sum of the dtime value
+        * and the play_time value
+        */
+       unsigned long   tot_usec;
+       /*
+        * holds the number of seconds and microseconds in the
+        * dtime value
+        */
+       unsigned long   sec;
+       unsigned long   usec;
+       /*
+        * holds the current time
+        */
+       struct timeval  btime;
+
+       /*
+        * Put the time from the current input action in dtime
+        */
+       dtime = action_array[read_index].delay_time;
+       /*
+        * If the current input action is a delay input action,
+        * add in the time from the following input action.
+        */
+       if ((action_array[read_index].type == XTestDELAY_ACTION) &&
+           ((read_index + 1) < write_index))
+       {  
+               read_index++;
+               dtime = dtime + action_array[read_index].delay_time;
+       }
+       /*
+        * compute the number of seconds and microseconds in the
+        * dtime value
+        */
+       sec = dtime / 1000;
+       usec = (dtime % 1000) * 1000;
+       /*
+        * get the current time in btime
+        */
+       X_GETTIMEOFDAY(&btime);
+       /*
+        * compute the number of microseconds in the sum of the dtime value
+        * and the current usec value
+        */
+       tot_usec = btime.tv_usec + usec;
+       /*
+        * if it is greater than one second's worth, adjust the seconds
+        */
+       if (tot_usec >= 1000000)
+       { 
+               tot_usec -= 1000000;
+               sec++;
+       }
+       play_time.tv_usec = tot_usec;
+       play_time.tv_sec = btime.tv_sec + sec;
+       /*
+        * put the time until the next input action in rtime
+        */
+       rtime->tv_sec = sec;
+       rtime->tv_usec = usec;
+}
+
+/******************************************************************************
+ *
+ *     find_residual_time
+ *
+ *     Find the time interval from the current time to the value in play_time.
+ *     This is the time to wait till putting the next input action into the
+ *     server's input queue.  If the time is already up, reset play_time to
+ *     the current time.
+ */
+static int
+find_residual_time(the_residual)
+struct timeval *the_residual;
+{
+       /*
+        * if > 0, there is time to wait.  If < 0, then don't wait
+        */
+       int             wait = 1;
+       /*
+        * holds the current time
+        */
+       struct timeval  btime;
+       /*
+        * holds the current time in seconds and microseconds
+        */
+       unsigned long   bsec;
+       unsigned long   busec;
+       /*
+        * holds the playback time in seconds and microseconds
+        */
+       unsigned long   psec;
+       unsigned long   pusec;
+
+       /*
+        * get the current time in btime
+        */
+       X_GETTIMEOFDAY(&btime);
+       /*
+        * get the current time in seconds and microseconds
+        */
+       bsec = btime.tv_sec;
+       busec = btime.tv_usec;
+       /*
+        * get the playback time in seconds and microseconds
+        */
+       psec = play_time.tv_sec;
+       pusec = play_time.tv_usec;
+       /*
+        * if the current time is already later than the playback time,
+        * we don't need to wait
+        */
+       if (bsec > psec)        
+       {
+           wait = -1;
+       }
+       else
+       { 
+               if (bsec == psec)
+               { 
+                       /*
+                        * if the current and playback times have the same
+                        * second value, then compare the microsecond values
+                        */
+                       if ( busec >= pusec) 
+                       { 
+                               /*
+                                * if the current time is already later than
+                                * the playback time, we don't need to wait
+                                */
+                               wait = -1;
+                       }
+                       else
+                       { 
+                               the_residual->tv_usec = pusec - busec;
+                               the_residual->tv_sec = 0;
+                       }
+               }
+               else    
+               { 
+                       if (busec > pusec)
+                       { 
+                               /*
+                                * 'borrow' a second's worth of microseconds
+                                * from the seconds left to wait
+                                */
+                               the_residual->tv_usec = 1000000 - busec + pusec;
+                               psec--;
+                               the_residual->tv_sec = psec - bsec;
+                       }
+                       else
+                       { 
+                               the_residual->tv_sec = psec - bsec;
+                               the_residual->tv_usec = pusec - busec;
+                       }
+               }
+       }
+       if (wait < 0)
+       { 
+               /*
+                * if don't need to wait, set the playback time
+                * to the current time
+                */
+               X_GETTIMEOFDAY(&play_time);
+               /*
+                * set the time to wait to 0
+                */
+               the_residual->tv_sec = 0;
+               the_residual->tv_usec = 0;
+       }
+       return(wait);
+}
+       
+/******************************************************************************
+ *
+ *     abort_play_back
+ */
+void
+abort_play_back()
+{
+       /*
+        * If we were playing back input actions at the time of the abort,
+        * restore the original wait time for the select in the main wait
+        * loop of the server
+        */
+       if (playback_on)
+       {
+               restorewait->tv_sec = saved_sec;
+               restorewait->tv_usec = saved_usec;
+       }
+       /*
+        * make the input action array empty
+        */
+       read_index = 0;
+       write_index = 0;
+       /*
+        * we are no longer playing back anything
+        */
+       playback_on = 0;
+       play_clock = 0;
+       go_for_next = 1;
+       /*
+        * there is no valid wait time saved any more
+        */
+       time_saved = 0;
+       /*
+        * there are no valid clients using this extension
+        */
+       playback_client = (ClientPtr) NULL;
+       current_xtest_client = (ClientPtr) NULL;
+}
+
+/******************************************************************************
+ *
+ *     return_input_array_size
+ *
+ *     Return the number of input actions in the input action array.
+ */
+void
+return_input_array_size(client)
+/*
+ * which client to send the reply to
+ */
+ClientPtr      client;
+{
+       xTestQueryInputSizeReply  rep;
+
+       rep.type = X_Reply;
+       /*
+        * set the serial number of the reply
+        */
+       rep.sequenceNumber = client->sequence;
+       rep.length = 0;
+       rep.size_return = ACTION_ARRAY_SIZE;
+       WriteReplyToClient(client,
+                          sizeof(xTestQueryInputSizeReply),
+                          (pointer) &rep);             
+}              
diff --git a/Xserver/programs/Xserver/Xext/xtest1dd.h b/Xserver/programs/Xserver/Xext/xtest1dd.h
new file mode 100644 (file)
index 0000000..78ff37e
--- /dev/null
@@ -0,0 +1,126 @@
+/* $XFree86: xc/programs/Xserver/Xext/xtest1dd.h,v 3.0 1996/05/06 05:55:43 dawes Exp $ */
+/************************************************************
+
+Copyright 1996 by Thomas E. Dickey <dickey@clark.net>
+
+                        All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and its
+documentation for any purpose and without fee is hereby granted,
+provided that the above copyright notice appear in all copies and that
+both that copyright notice and this permission notice appear in
+supporting documentation, and that the name of the above listed
+copyright holder(s) not be used in advertising or publicity pertaining
+to distribution of the software without specific, written prior
+permission.
+
+THE ABOVE LISTED COPYRIGHT HOLDER(S) DISCLAIM ALL WARRANTIES WITH REGARD
+TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+AND FITNESS, IN NO EVENT SHALL THE ABOVE LISTED COPYRIGHT HOLDER(S) BE
+LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+
+********************************************************/
+
+#ifndef XTEST1DD_H
+#define XTEST1DD_H 1
+
+extern short           xtest_mousex;
+extern short           xtest_mousey;
+extern int             playback_on;
+extern ClientPtr       current_xtest_client;
+extern ClientPtr       playback_client;
+extern KeyCode         xtest_command_key;
+
+extern void stop_stealing_input(
+#if NeedFunctionPrototypes
+       void
+#endif
+);
+
+extern void
+steal_input(
+#if NeedFunctionPrototypes
+       ClientPtr              /* client */,
+       CARD32                 /* mode */
+#endif
+);
+
+extern void
+flush_input_actions(
+#if NeedFunctionPrototypes
+       void
+#endif
+);
+
+extern void
+XTestStealJumpData(
+#if NeedFunctionPrototypes2
+       short                  /* jx */,
+       short                  /* jy */,
+       int                    /* dev_type */
+#endif
+);
+
+extern void
+XTestStealMotionData(
+#if NeedFunctionPrototypes2
+       short                  /* dx */,
+       short                  /* dy */,
+       int                    /* dev_type */,
+       short                  /* mx */,
+       short                  /* my */
+#endif
+);
+
+extern Bool
+XTestStealKeyData(
+#if NeedFunctionPrototypes2
+       CARD8                  /* keycode */,
+       char                   /* keystate */,
+       int                    /* dev_type */,
+       short                  /* locx */,
+       short                  /* locy */
+#endif
+);
+
+extern void
+parse_fake_input(
+#if NeedFunctionPrototypes
+       ClientPtr              /* client */,
+       char *                 /* req */
+#endif
+);
+
+extern void
+XTestComputeWaitTime(
+#if NeedFunctionPrototypes
+       struct timeval *       /* waittime */
+#endif
+);
+
+extern int
+XTestProcessInputAction(
+#if NeedFunctionPrototypes
+       int                    /* readable */,
+       struct timeval *       /* waittime */
+#endif
+);
+
+extern void
+abort_play_back(
+#if NeedFunctionPrototypes
+       void
+#endif
+);
+
+extern void
+return_input_array_size(
+#if NeedFunctionPrototypes
+       ClientPtr              /* client */
+#endif
+);
+
+#endif /* XTEST1DD_H */
diff --git a/Xserver/programs/Xserver/Xext/xtest1di.c b/Xserver/programs/Xserver/Xext/xtest1di.c
new file mode 100644 (file)
index 0000000..f66b49f
--- /dev/null
@@ -0,0 +1,974 @@
+/* $XConsortium: xtest1di.c,v 1.13 94/04/17 20:33:01 rws Exp $ */
+/* $XFree86: xc/programs/Xserver/Xext/xtest1di.c,v 3.0 1996/05/06 05:55:45 dawes Exp $ */
+/*
+ *     File:  xtest1di.c
+ *
+ *     This file contains the device independent parts of the input
+ *     synthesis extension.
+ */
+
+/*
+
+
+Copyright (c) 1986, 1987, 1988   X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+
+Copyright 1986, 1987, 1988 by Hewlett-Packard Corporation
+
+Permission to use, copy, modify, and distribute this
+software and its documentation for any purpose and without
+fee is hereby granted, provided that the above copyright
+notice appear in all copies and that both that copyright
+notice and this permission notice appear in supporting
+documentation, and that the name of Hewlett-Packard not be used in
+advertising or publicity pertaining to distribution of the
+software without specific, written prior permission.
+
+Hewlett-Packard makes no representations about the 
+suitability of this software for any purpose.  It is provided 
+"as is" without express or implied warranty.
+
+This software is not subject to any license of the American
+Telephone and Telegraph Company or of the Regents of the
+University of California.
+
+*/
+
+/*****************************************************************************
+ * include files
+ ****************************************************************************/
+
+#define         NEED_EVENTS
+#define         NEED_REPLIES
+
+#include <stdio.h>
+#include "X.h"
+#include "Xproto.h"
+#include "misc.h"
+#include "os.h"
+#include "gcstruct.h"   
+#include "extnsionst.h"
+#include "dixstruct.h"
+#include "opaque.h"
+#define  XTestSERVER_SIDE
+#include "xtestext1.h"
+
+#include "xtest1dd.h"
+
+/*****************************************************************************
+ * defines
+ ****************************************************************************/
+
+/*****************************************************************************
+ * externals
+ ****************************************************************************/
+
+/*
+ * id of client using XTestGetInput
+ *
+ * defined in xtest1dd.c
+ */
+extern ClientPtr       current_xtest_client;
+/*
+ * id of client using XTestFakeInput
+ *
+ * defined in xtest1dd.c
+ */
+extern ClientPtr       playback_client;
+
+/*****************************************************************************
+ * variables
+ ****************************************************************************/
+
+/*
+ * Holds the request type code for this extension.  The request type code
+ * for this extension may vary depending on how many extensions are installed
+ * already, so the initial value given below will be added to the base request
+ * code that is aquired when this extension is installed.
+ */
+static int             XTestReqCode = 0;
+/*
+ * Holds the two event type codes for this extension.  The event type codes
+ * for this extension may vary depending on how many extensions are installed
+ * already, so the initial values given below will be added to the base event
+ * code that is aquired when this extension is installed.
+ */
+int                    XTestInputActionType = 0;
+int                    XTestFakeAckType = 1;
+/*
+ * true => monitor stealing input
+ */
+int                    on_steal_input = FALSE;
+/*
+ * true => monitor alone getting input
+ */
+int                    exclusive_steal = FALSE;
+/*
+ * holds the resource type assigned to this extension
+ */
+static RESTYPE         XTestType;
+/*
+ * holds the resource ID for the client currently using XTestGetInput
+ */
+static XID             current_client_id;
+
+/*****************************************************************************
+ * function declarations
+ ****************************************************************************/
+
+static DISPATCH_PROC(ProcXTestDispatch);
+static DISPATCH_PROC(SProcXTestDispatch);
+static DISPATCH_PROC(ProcTestFakeInput);
+static DISPATCH_PROC(SProcTestFakeInput);
+static DISPATCH_PROC(ProcTestGetInput);
+static DISPATCH_PROC(SProcTestGetInput);
+static DISPATCH_PROC(ProcTestStopInput);
+static DISPATCH_PROC(SProcTestStopInput);
+static DISPATCH_PROC(ProcTestReset);
+static DISPATCH_PROC(SProcTestReset);
+static DISPATCH_PROC(ProcTestQueryInputSize);
+static DISPATCH_PROC(SProcTestQueryInputSize);
+
+static void    XTestResetProc(
+#if NeedFunctionPrototypes
+       ExtensionEntry *        /* unused */
+#endif
+       );
+static void    SReplyXTestDispatch(
+#if NeedFunctionPrototypes
+       ClientPtr               /* client_ptr */,
+       int                     /* size */,
+       char *                  /* reply_ptr */
+#endif
+       );
+static void    SEventXTestDispatch(
+#if NeedFunctionPrototypes
+       xEvent *                /* from */,
+       xEvent *                /* to */
+#endif
+       );
+
+static int     XTestCurrentClientGone(
+#if NeedFunctionPrototypes
+       pointer                 /* value */,
+       XID                     /* id */
+#endif
+       );
+
+/*****************************************************************************
+ *
+ *     XTestExtension1Init
+ *
+ *     Called from InitExtensions in main() or from QueryExtension() if the
+ *     extension is dynamically loaded.
+ *
+ *     XTestExtension1Init has no events or errors
+ *     (other than the core errors).
+ */
+void
+XTestExtension1Init()
+{
+       /*
+        * holds the pointer to the extension entry structure
+        */
+       ExtensionEntry  *extEntry;
+
+       extEntry = AddExtension(XTestEXTENSION_NAME,
+                               XTestEVENT_COUNT,
+                               0,
+                               ProcXTestDispatch,
+                               SProcXTestDispatch,
+                               XTestResetProc,
+                               StandardMinorOpcode);
+       if (extEntry)
+       {
+               /*
+                * remember the request code assigned to this extension
+                */
+               XTestReqCode = extEntry->base;
+               /*
+                * make an atom saying that this extension is present
+                */
+               (void) MakeAtom(XTestEXTENSION_NAME,
+                               strlen(XTestEXTENSION_NAME),
+                               TRUE);
+               /*
+                * remember the event codes assigned to this extension
+                */
+               XTestInputActionType += extEntry->eventBase;
+               XTestFakeAckType += extEntry->eventBase;
+               /*
+                * install the routine to handle byte-swapping the replies
+                * for this extension in the ReplySwapVector table
+                */
+               ReplySwapVector[XTestReqCode] = (ReplySwapPtr) SReplyXTestDispatch;
+               /*
+                * install the routine to handle byte-swapping the events
+                * for this extension in the EventSwapVector table
+                */
+               EventSwapVector[XTestInputActionType] = SEventXTestDispatch;
+               EventSwapVector[XTestFakeAckType] = SEventXTestDispatch;
+               /*
+                * get the resource type for this extension
+                */
+               XTestType = CreateNewResourceType(XTestCurrentClientGone);
+               if (XTestType == 0)
+               {
+                       FatalError("XTestExtension1Init: CreateNewResourceType failed\n");
+               }
+       } 
+       else 
+       {
+               FatalError("XTestExtension1Init: AddExtensions failed\n");
+       }
+}
+
+/*****************************************************************************
+ *
+ *     ProcXTestDispatch
+ *
+ *
+ */
+static int
+ProcXTestDispatch(client)
+       register ClientPtr      client;
+{
+       REQUEST(xReq);
+       if (stuff->data == X_TestFakeInput)
+       {
+               return(ProcTestFakeInput(client));
+       }
+       else if (stuff->data == X_TestGetInput)
+       {
+               return(ProcTestGetInput(client));
+       }
+       else if (stuff->data == X_TestStopInput)
+       {
+               return(ProcTestStopInput(client));
+       }
+       else if (stuff->data == X_TestReset)
+       {
+               return(ProcTestReset(client));
+       }
+       else if (stuff->data == X_TestQueryInputSize)
+       {
+               return(ProcTestQueryInputSize(client));
+       }
+       else
+       {
+               SendErrorToClient(client,
+                                 XTestReqCode,
+                                 stuff->data,
+                                 None,
+                                 BadRequest);
+               return(BadRequest);
+       }
+}
+
+/*****************************************************************************
+ *
+ *     SProcXTestDispatch
+ *
+ *
+ */
+static int
+SProcXTestDispatch(client)
+       register ClientPtr      client;
+{
+       REQUEST(xReq);
+       if (stuff->data == X_TestFakeInput)
+       {
+               return(SProcTestFakeInput(client));
+       }
+       else if (stuff->data == X_TestGetInput)
+       {
+               return(SProcTestGetInput(client));
+       }
+       else if (stuff->data == X_TestStopInput)
+       {
+               return(SProcTestStopInput(client));
+       }
+       else if (stuff->data == X_TestReset)
+       {
+               return(SProcTestReset(client));
+       }
+       else if (stuff->data == X_TestQueryInputSize)
+       {
+               return(SProcTestQueryInputSize(client));
+       }
+       else
+       {
+               SendErrorToClient(client,
+                                 XTestReqCode,
+                                 stuff->data,
+                                 None,
+                                 BadRequest);
+               return(BadRequest);
+       }
+}
+
+/*****************************************************************************
+ *
+ *     SProcTestFakeInput
+ *
+ *
+ */
+static int
+SProcTestFakeInput(client)
+       register ClientPtr      client;
+{
+       /*
+        * used in the swaps and swapl macros for temporary storage space
+        */
+       register char   n;
+       /*
+        * index counter
+        */
+       int             i;
+       /*
+        * pointer to the next input action in the request
+        */
+       CARD8           *input_action_ptr;
+       /*
+        * holds the type of the next input action in the request
+        */
+       int             input_action_type;
+
+       REQUEST(xTestFakeInputReq);
+       /*
+        * byte-swap the fields in the request
+        */
+       swaps(&stuff->length, n);
+       swapl(&stuff->ack, n);
+       /*
+        * have to parse and then byte-swap the input action list here
+        */
+       for (i = 0; i < XTestMAX_ACTION_LIST_SIZE;)
+       {
+               /*
+                * point to the next input action in the request
+                */
+               input_action_ptr = &(((xTestFakeInputReq *) stuff)->action_list[i]);
+               /*
+                * figure out what type of input action it is
+                */
+               input_action_type = (*input_action_ptr) & XTestACTION_TYPE_MASK;
+               /*
+                * byte-swap the input action according to it's type
+                */
+               switch (input_action_type)
+               {
+               case XTestKEY_ACTION:
+                       /*
+                        * byte-swap the delay_time field
+                        */
+                       swaps(&(((XTestKeyInfo *) input_action_ptr)->delay_time), n);
+                       /*
+                        * advance to the next input action
+                        */
+                       i += sizeof(XTestKeyInfo);
+                       break;
+               case XTestMOTION_ACTION:
+                       /*
+                        * byte-swap the delay_time field
+                        */
+                       swaps(&(((XTestMotionInfo *) input_action_ptr)->delay_time), n);
+                       /*
+                        * advance to the next input action
+                        */
+                       i += sizeof(XTestMotionInfo);
+                       break;
+               case XTestJUMP_ACTION:
+                       /*
+                        * byte-swap the jumpx field
+                        */
+                       swaps(&(((XTestJumpInfo *) input_action_ptr)->jumpx), n);
+                       /*
+                        * byte-swap the jumpy field
+                        */
+                       swaps(&(((XTestJumpInfo *) input_action_ptr)->jumpy), n);
+                       /*
+                        * byte-swap the delay_time field
+                        */
+                       swaps(&(((XTestJumpInfo *) input_action_ptr)->delay_time), n);
+                       /*
+                        * advance to the next input action
+                        */
+                       i += sizeof(XTestJumpInfo);
+                       break;
+               default:
+                       /*
+                        * if this is a delay input action, then byte-swap it,
+                        * otherwise we have reached the end of the input
+                        * actions in this request
+                        */
+                       if (XTestUnpackDeviceID(*input_action_ptr) ==
+                           XTestDELAY_DEVICE_ID)
+                       {
+                               /*
+                                * byte-swap the delay_time field
+                                */
+                               swapl(&(((XTestDelayInfo *) input_action_ptr)->delay_time), n);
+                               /*
+                                * advance to the next input action
+                                */
+                               i += sizeof(XTestDelayInfo);
+                       }
+                       else
+                       {
+                               /*
+                                * if the input action header byte is 0 or
+                                * ill-formed, then there are no more input
+                                * actions in this request
+                                */
+                               i = XTestMAX_ACTION_LIST_SIZE;
+                       }
+                       break;
+               }
+       }
+       return(ProcTestFakeInput(client));
+}
+
+/*****************************************************************************
+ *
+ *     SProcTestGetInput
+ *
+ *
+ */
+static int
+SProcTestGetInput(client)
+       register ClientPtr      client;
+{
+       /*
+        * used in the swaps and swapl macros for temporary storage space
+        */
+       register char   n;
+
+       REQUEST(xTestGetInputReq);
+       /*
+        * byte-swap the fields in the request
+        */
+       swaps(&stuff->length, n);
+       swapl(&stuff->mode, n);
+       return(ProcTestGetInput(client));
+}
+
+/*****************************************************************************
+ *
+ *     SProcTestStopInput
+ *
+ *
+ */
+static int
+SProcTestStopInput(client)
+       register ClientPtr      client;
+{
+       /*
+        * used in the swaps and swapl macros for temporary storage space
+        */
+       register char   n;
+
+       REQUEST(xTestStopInputReq);
+       /*
+        * byte-swap the length field in the request
+        */
+       swaps(&stuff->length, n);
+       return(ProcTestStopInput(client));
+}
+
+/*****************************************************************************
+ *
+ *     SProcTestReset
+ *
+ *
+ */
+static int
+SProcTestReset(client)
+       register ClientPtr      client;
+{
+       /*
+        * used in the swaps and swapl macros for temporary storage space
+        */
+       register char   n;
+
+       REQUEST(xTestResetReq);
+       /*
+        * byte-swap the length field in the request
+        */
+       swaps(&stuff->length, n);
+       return(ProcTestReset(client));
+}
+
+/*****************************************************************************
+ *
+ *     SProcTestQueryInputSize
+ *
+ *
+ */
+static int
+SProcTestQueryInputSize(client)
+       register ClientPtr      client;
+{
+       /*
+        * used in the swaps and swapl macros for temporary storage space
+        */
+       register char   n;
+
+       REQUEST(xTestQueryInputSizeReq);
+       /*
+        * byte-swap the length field in the request
+        */
+       swaps(&stuff->length, n);
+       return(ProcTestQueryInputSize(client));
+}
+
+/*****************************************************************************
+ *
+ *     ProcTestFakeInput
+ *
+ *
+ */
+static int
+ProcTestFakeInput(client)
+       register ClientPtr      client;
+{
+       REQUEST(xTestFakeInputReq);
+       REQUEST_SIZE_MATCH(xTestFakeInputReq);
+
+       if (playback_client == NULL)
+           {
+           playback_client = client;
+           current_client_id = FakeClientID(client->index);
+           AddResource(current_client_id,
+                   XTestType,
+                   0);
+           MakeClientGrabImpervious(client);
+           }
+       if (playback_client == client)
+       {
+               /*
+                * This extension does not need to clean up any
+                * server state when a client using this function
+                * "goes away".  The server will just process any
+                * input actions that have already been sent to it,
+                * and will then reset its association with a client.
+                */
+               parse_fake_input(client, (char *)stuff);
+               return(Success);
+       }
+       else
+       {
+               /*
+                * this is a request by another client to send fake
+                * input while the server is still being used
+                */
+               SendErrorToClient(client,
+                                 XTestReqCode,
+                                 X_TestFakeInput,
+                                 None,
+                                 BadAccess);
+               return(BadAccess);
+       }
+}
+
+/*****************************************************************************
+ *
+ *     ProcTestGetInput
+ *
+ *
+ */
+static int
+ProcTestGetInput(client)
+       register ClientPtr      client;
+{
+       REQUEST(xTestGetInputReq);
+       REQUEST_SIZE_MATCH(xTestGetInputReq);
+       if (on_steal_input)
+       {
+               /*
+                * this is a request by another client to get fake input
+                * while the server is still sending input to the first client
+                */
+               SendErrorToClient(client,
+                                 XTestReqCode,
+                                 X_TestGetInput,
+                                 None,
+                                 BadAccess);
+               return(BadAccess);
+       }
+       else
+       { 
+               /*
+                * Set up a resource associated with the client using this
+                * function so that this extension gets called when the 
+                * client "goes away".  This allows this extension to
+                * clean up the server state.
+                */
+               current_client_id = FakeClientID(client->index);
+               AddResource(current_client_id,
+                           XTestType,
+                           0);
+               /*
+                * indicate that a client is stealing input
+                */
+               on_steal_input = TRUE;
+               if ((stuff->mode & XTestEXCLUSIVE) == 0)
+               {
+                       exclusive_steal = FALSE;
+               }
+               else 
+               {
+                       exclusive_steal = TRUE;
+               }
+               steal_input(client, stuff->mode);
+               return(Success);
+       }
+}
+
+/*****************************************************************************
+ *
+ *     ProcTestStopInput
+ *
+ *
+ */
+static int
+ProcTestStopInput(client)
+       register ClientPtr      client;
+{
+       REQUEST_SIZE_MATCH(xTestStopInputReq);
+       if (on_steal_input && (current_xtest_client == client)) 
+       { 
+               on_steal_input = FALSE;
+               exclusive_steal = FALSE;
+               stop_stealing_input();  
+               /*
+                * remove the resource associated with this client
+                */
+               FreeResource(current_client_id, RT_NONE);
+               return(Success);
+       }
+       else
+       {
+               /*
+                * this is a request to stop fake input when fake input has
+                * never been started or from a client that hasn't started
+                * fake input
+                */
+               SendErrorToClient(client,
+                                 XTestReqCode,
+                                 X_TestStopInput,
+                                 None,
+                                 BadAccess);
+               return(BadAccess);
+       }
+}
+
+/*****************************************************************************
+ *
+ *     ProcTestReset
+ *
+ *
+ */
+static int
+ProcTestReset(client)
+       register ClientPtr      client;
+{
+       REQUEST_SIZE_MATCH(xTestResetReq);
+       on_steal_input = FALSE;
+       exclusive_steal = FALSE;
+       /*
+        * defined in xtest1dd.c
+        */
+       stop_stealing_input();  
+       /*
+        * defined in xtest1dd.c
+        */
+       abort_play_back();
+       return(Success);
+}
+
+/*****************************************************************************
+ *
+ *     ProcTestQueryInputSize
+ *
+ *
+ */
+static int
+ProcTestQueryInputSize(client)
+       register ClientPtr      client;
+{
+       REQUEST_SIZE_MATCH(xTestQueryInputSizeReq);
+       /*
+        * defined in xtest1dd.c
+        */
+       return_input_array_size(client);
+       return(Success);
+}
+
+/*****************************************************************************
+ *
+ *     XTestResetProc
+ *
+ *     This function is called by the server when the server has no clients
+ *     connected to it.  It must put eveything back the way it was before
+ *     this extension was installed.
+ */
+/*ARGSUSED*/
+static void
+XTestResetProc(unused)
+       ExtensionEntry * unused;
+{
+       /*
+        * remove the routine to handle byte-swapping the replies
+        * for this extension in the ReplySwapVector table
+        */
+       ReplySwapVector[XTestReqCode] = ReplyNotSwappd;
+       /*
+        * remove the routine to handle byte-swapping the events
+        * for this extension in the EventSwapVector table
+        */
+       EventSwapVector[XTestInputActionType] = NotImplemented;
+       EventSwapVector[XTestFakeAckType] = NotImplemented;
+       /*
+        * reset the variables initialized just once at load time
+        */
+       XTestReqCode = 0;
+       XTestInputActionType = 0;
+       XTestFakeAckType = 1;
+       on_steal_input = FALSE;
+       exclusive_steal = FALSE;
+       playback_client = 0;    /* Don't really need this but it looks nice */
+}
+
+/*****************************************************************************
+ *
+ *     PXTestCurrentClientGone
+ *
+ *     This routine is called when a client that has asked for input actions
+ *     to be sent to it "goes away".  This routine must clean up the 
+ *     server state.
+ */
+/*ARGSUSED*/
+static int
+XTestCurrentClientGone(value, id)
+       pointer value;
+       XID     id;
+{
+       /*
+        * defined in xtest1dd.c
+        */
+       on_steal_input = FALSE;
+       exclusive_steal = FALSE;
+       /*
+        * defined in xtestdd.c
+        */
+       playback_client = 0;
+       abort_play_back();
+       return TRUE;
+}
+
+/*****************************************************************************
+ *
+ *     SReplyXTestDispatch
+ *
+ *     Swap any replies defined in this extension.
+ */
+static void
+SReplyXTestDispatch(client_ptr, size, reply_ptr)
+       ClientPtr       client_ptr;
+       int             size;
+       char            *reply_ptr;
+{
+       /*
+        * used in the swaps and swapl macros for temporary storage space
+        */
+       register char   n;
+       /*
+        * pointer to xTestQueryInputSizeReply
+        */
+       xTestQueryInputSizeReply        *rep_ptr;
+
+       /*
+        * there is only one reply in this extension, so byte-swap it
+        */
+       rep_ptr = (xTestQueryInputSizeReply *) reply_ptr;
+       swaps(&(rep_ptr->sequenceNumber), n);
+       swapl(&(rep_ptr->length), n);
+       swapl(&(rep_ptr->size_return), n);
+       /*
+        * now write the swapped reply to the client
+        */
+       WriteToClient(client_ptr, size, reply_ptr);
+}
+
+/*****************************************************************************
+ *
+ *     SEventXTestDispatch
+ *
+ *     Swap any events defined in this extension.
+ */
+static void
+SEventXTestDispatch(from, to)
+       xEvent  *from;
+       xEvent  *to;
+{
+       /*
+        * used in the swaps and swapl macros for temporary storage space
+        */
+       register char   n;
+       /*
+        * index counter
+        */
+       int             i;
+       /*
+        * pointer to the next input action in the event
+        */
+       CARD8           *input_action_ptr;
+       /*
+        * holds the type of the next input action in the event
+        */
+       int             input_action_type;
+
+
+       /*
+        * copy the type information from the "from" event to the "to" event
+        */
+       ((xTestInputActionEvent *) to)->type =
+       ((xTestInputActionEvent *) from)->type;
+       /*
+        * copy the sequence number information from the "from" event to the
+        * "to" event
+        */
+       ((xTestInputActionEvent *) to)->sequenceNumber =
+       ((xTestInputActionEvent *) from)->sequenceNumber;
+       /*
+        * byte-swap the sequence number in the "to" event
+        */
+       swaps(&(((xTestInputActionEvent *) to)->sequenceNumber), n);
+       /*
+        * If the event is an xTestInputActionEvent, then it needs more
+        * processing.  Otherwise, it is an xTestFakeAckEvent, which
+        * has no other information in it.
+        */
+       if ((((xTestInputActionEvent *) to)->type & 0x7f) ==
+           XTestInputActionType)
+       {
+               /*
+                * copy the input actions from the "from" event
+                * to the "to" event
+                */
+               for (i = 0; i < XTestACTIONS_SIZE; i++)
+               {
+                       ((xTestInputActionEvent *) to)->actions[i] =
+                       ((xTestInputActionEvent *) from)->actions[i];
+               }
+               /*
+                * byte-swap the input actions in the "to" event
+                */
+               for (i = 0; i < XTestACTIONS_SIZE; i++)
+               {
+                       /*
+                        * point to the next input action in the event
+                        */
+                       input_action_ptr = &(((xTestInputActionEvent *) to)->actions[i]);
+                       /*
+                        * figure out what type of input action it is
+                        */
+                       input_action_type = (*input_action_ptr) &
+                                           XTestACTION_TYPE_MASK;
+                       /*
+                        * byte-swap the input action according to it's type
+                        */
+                       switch (input_action_type)
+                       {
+                       case XTestKEY_ACTION:
+                               /*
+                                * byte-swap the delay_time field
+                                */
+                               swaps(&(((XTestKeyInfo *) input_action_ptr)->delay_time), n);
+                               /*
+                                * advance to the next input action
+                                */
+                               i += sizeof(XTestKeyInfo);
+                               break;
+                       case XTestMOTION_ACTION:
+                               /*
+                                * byte-swap the delay_time field
+                                */
+                               swaps(&(((XTestMotionInfo *) input_action_ptr)->delay_time), n);
+                               /*
+                                * advance to the next input action
+                                */
+                               i += sizeof(XTestMotionInfo);
+                               break;
+                       case XTestJUMP_ACTION:
+                               /*
+                                * byte-swap the jumpx field
+                                */
+                               swaps(&(((XTestJumpInfo *) input_action_ptr)->jumpx), n);
+                               /*
+                                * byte-swap the jumpy field
+                                */
+                               swaps(&(((XTestJumpInfo *) input_action_ptr)->jumpy), n);
+                               /*
+                                * byte-swap the delay_time field
+                                */
+                               swaps(&(((XTestJumpInfo *) input_action_ptr)->delay_time), n);
+                               /*
+                                * advance to the next input action
+                                */
+                               i += sizeof(XTestJumpInfo);
+                               break;
+                       default:
+                               /*
+                                * if this is a delay input action, then
+                                * byte-swap it, otherwise we have reached the
+                                * end of the input actions in this event
+                                */
+                               if (XTestUnpackDeviceID(*input_action_ptr) ==
+                                   XTestDELAY_DEVICE_ID)
+                               {
+                                       /*
+                                        * byte-swap the delay_time field
+                                        */
+                                       swapl(&(((XTestDelayInfo *) input_action_ptr)->delay_time), n);
+                                       /*
+                                        * advance to the next input action
+                                        */
+                                       i += sizeof(XTestDelayInfo);
+                               }
+                               else
+                               {
+                                       /*
+                                        * if the input action header byte is 0
+                                        * or ill-formed, then there are no
+                                        * more input actions in this event
+                                        */
+                                       i = XTestACTIONS_SIZE;
+                               }
+                               break;
+                       }
+               }
+       }
+}
diff --git a/Xserver/programs/Xserver/Xprint/DiPrint.h b/Xserver/programs/Xserver/Xprint/DiPrint.h
new file mode 100644 (file)
index 0000000..feb7563
--- /dev/null
@@ -0,0 +1,54 @@
+/* $XConsortium: DiPrint.h /main/1 1996/09/28 16:57:42 rws $ */
+/*
+(c) Copyright 1996 Hewlett-Packard Company
+(c) Copyright 1996 International Business Machines Corp.
+(c) Copyright 1996 Sun Microsystems, Inc.
+(c) Copyright 1996 Novell, Inc.
+(c) Copyright 1996 Digital Equipment Corp.
+(c) Copyright 1996 Fujitsu Limited
+(c) Copyright 1996 Hitachi, Ltd.
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
+IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the names of the copyright holders shall
+not be used in advertising or otherwise to promote the sale, use or other
+dealings in this Software without prior written authorization from said
+copyright holders.
+*/
+/*
+ * The XpDiListEntry struct is the type of each element of the array
+ * handed back to the extension code to handle a GetPrinterList request.
+ * We don't use the printerDb directly because of the desire to handle
+ * multiple locales.  Creating this new array for each GetPrinterList
+ * request will allow us to build it with the description in the locale of
+ * the requesting client.
+ */
+typedef struct _diListEntry {
+    char *name;
+    char *description;
+    char *localeName;
+    unsigned long rootWinId;
+} XpDiListEntry;
+
+extern void XpDiFreePrinterList(XpDiListEntry **list);
+
+extern XpDiListEntry **XpDiGetPrinterList(
+    int nameLen,
+    char *name,
+    int localeLen,
+    char *locale);
diff --git a/Xserver/programs/Xserver/Xserver.man b/Xserver/programs/Xserver/Xserver.man
new file mode 100644 (file)
index 0000000..fb127ef
--- /dev/null
@@ -0,0 +1,688 @@
+.\" $XConsortium: Xserver.man /main/62 1996/12/09 17:06:18 kaleb $
+.\" $XFree86: xc/programs/Xserver/Xserver.man,v 3.5.2.4 1998/02/24 13:20:02 dawes Exp $
+.\" Copyright (c) 1984 - 1991, 1993, 1994  X Consortium
+.\" 
+.\" Permission is hereby granted, free of charge, to any person obtaining
+.\" a copy of this software and associated documentation files (the
+.\" "Software"), to deal in the Software without restriction, including
+.\" without limitation the rights to use, copy, modify, merge, publish,
+.\" distribute, sublicense, and/or sell copies of the Software, and to
+.\" permit persons to whom the Software is furnished to do so, subject to
+.\" the following conditions:
+.\" 
+.\" The above copyright notice and this permission notice shall be included
+.\" in all copies or substantial portions of the Software.
+.\" 
+.\" THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+.\" OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+.\" MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+.\" IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR
+.\" OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+.\" ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+.\" OTHER DEALINGS IN THE SOFTWARE.
+.\" 
+.\" Except as contained in this notice, the name of the X Consortium shall
+.\" not be used in advertising or otherwise to promote the sale, use or
+.\" other dealings in this Software without prior written authorization
+.\" from the X Consortium.
+.TH XSERVER 1 "Release 6.3"  "X Version 11"
+.SH NAME
+Xserver \- X Window System display server
+.SH SYNOPSIS
+.B X
+[option ...]
+.SH DESCRIPTION
+.I X
+is the generic name for the X Window System display server.  It is
+frequently a link or a copy of the appropriate server binary for
+driving the most frequently used server on a given machine.
+.SH "STARTING THE SERVER"
+The X server is usually started from the X Display Manager program \fIxdm(1)\fP.
+This utility is run from the system boot files and takes care of keeping
+the server running, prompting for usernames and passwords, and starting up
+the user sessions.
+.PP
+Installations that run more than one window system may need to use the
+\fIxinit(1)\fP utility instead of \fIxdm\fP.  However, \fIxinit\fP is
+to be considered a tool for building startup scripts and is not
+intended for use by end users.  Site administrators are \fBstrongly\fP
+urged to use \fIxdm\fP, or build other interfaces for novice users.
+.PP
+The X server may also be started directly by the user, though this
+method is usually reserved for testing and is not recommended for
+normal operation.  On some platforms, the user must have special
+permission to start the X server, often because access to certain
+devices (e.g. /dev/mouse) is restricted.
+.PP
+When the X server starts up, it typically takes over the display.  If
+you are running on a workstation whose console is the display, you may
+not be able to log into the console while the server is running.
+.SH OPTIONS
+All of the X servers accept the following command line options:
+.TP 8
+.B :\fIdisplaynumber\fP
+the X server runs as the given \fIdisplaynumber\fP, which by default is 0.
+If multiple X servers are to run simultaneously on a host, each must have
+a unique display number.  See the DISPLAY
+NAMES section of the \fIX(1)\fP manual page to learn how to specify
+which display number clients should try to use.
+.TP 8
+.B \-a \fInumber\fP
+sets pointer acceleration (i.e. the ratio of how much is reported to how much
+the user actually moved the pointer).
+.TP 8
+.B \-ac
+disables host-based access control mechanisms.  Enables access by any host,
+and permits any host to modify the access control list.
+Use with extreme caution.
+This option exists primarily for running test suites remotely.
+.TP 8
+.B \-audit \fIlevel\fP
+Sets the audit trail level.  The default level is 1, meaning only connection
+rejections are reported.  Level 2 additionally reports all successful
+connections and disconnects.  Level 4 enables messages from the
+SECURITY extension, if present, including generation and revocation of
+authorizations and violations of the security policy.
+Level 0 turns off the audit trail.
+Audit lines are sent as standard error output.
+.TP 8
+.B \-auth \fIauthorization-file\fP
+Specifies a file which contains a collection of authorization records used
+to authenticate access.  See also the \fIxdm\fP and \fIXsecurity\fP manual
+pages.
+.TP 8
+.B bc
+disables certain kinds of error checking, for bug compatibility with
+previous releases (e.g., to work around bugs in R2 and R3 xterms and toolkits).
+Deprecated.
+.TP 8
+.B \-bs
+disables backing store support on all screens.
+.TP 8
+.B \-c
+turns off key-click.
+.TP 8
+.B c \fIvolume\fP
+sets key-click volume (allowable range: 0-100).
+.TP 8
+.B \-cc \fIclass\fP
+sets the visual class for the root window of color screens.
+The class numbers are as specified in the X protocol.
+Not obeyed by all servers.
+.TP 8
+.B \-co \fIfilename\fP
+sets name of RGB color database.  The default is <XRoot>/lib/X11/rgb,
+where <XRoot> refers to the root of the X11 install tree.
+.ig
+.TP 8
+.B \-config \fIfilename\fP
+reads more options from the given file.  Options in the file may be separated
+by newlines if desired.  If a '#' character appears on a line, all characters
+between it and the next newline are ignored, providing a simple commenting
+facility.  The \fB\-config\fP option itself may appear in the file.
+..
+.TP 8
+.B \-core
+causes the server to generate a core dump on fatal errors.
+.TP 8
+.B \-dpi \fIresolution\fP
+sets the resolution of the screen, in dots per inch.
+To be used when the server cannot determine the screen size from the hardware.
+.TP 8
+.B dpms
+Enable DPMS (when supported).
+.TP 8
+.B \-dpms
+Disable DPMS.
+.TP 8
+.B \-deferglyphs \fIwhichfonts\fP
+specifies the types of fonts for which the server should attempt to use
+deferred glyph loading.  \fIwhichfonts\fP can be all (all fonts),
+none (no fonts), or 16 (16 bit fonts only).
+.TP 8
+.B \-f \fIvolume\fP
+sets feep (bell) volume (allowable range: 0-100).
+.TP 8
+.B \-fc \fIcursorFont\fP
+sets default cursor font.
+.TP 8
+.B \-fn \fIfont\fP
+sets the default font.
+.TP 8
+.B \-fp \fIfontPath\fP
+sets the search path for fonts.  This path is a comma separated list
+of directories which the X server searches for font databases.
+.TP 8
+.B \-help
+prints a usage message.
+.TP 8
+.B \-I
+causes all remaining command line arguments to be ignored.
+.TP 8
+.B \-kb
+disables the XKEYBOARD extension if present.
+.TP 8
+.B \-nolisten \fItrans-type\fP
+Disable a transport type.  For example, TCP/IP connections can be disabled
+with
+.B \-nolisten tcp
+.TP 8
+.B \-nolock
+Disable the use of an X server lock file.
+.TP 8
+.B \-p \fIminutes\fP
+sets screen-saver pattern cycle time in minutes.
+.TP 8
+.B \-pn
+permits the server to continue running if it fails to establish all of
+its well-known sockets (connection points for clients), but
+establishes at least one.
+.TP 8
+.B \-r
+turns off auto-repeat.
+.TP 8
+.B r
+turns on auto-repeat.
+.TP 8
+.B \-s \fIminutes\fP
+sets screen-saver timeout time in minutes.
+.TP 8
+.B \-su
+disables save under support on all screens.
+.TP 8
+.B \-t \fInumber\fP
+sets pointer acceleration threshold in pixels (i.e. after how many pixels
+pointer acceleration should take effect).
+.TP 8
+.B \-terminate
+causes the server to terminate at server reset, instead of continuing to run.
+.TP 8
+.B \-to \fIseconds\fP
+sets default connection timeout in seconds.
+.TP 8
+.B \-tst
+disables all testing extensions (e.g., XTEST, XTrap, XTestExtension1, RECORD).
+.TP 8
+.B tty\fIxx\fP
+ignored, for servers started the ancient way (from init).
+.TP 8
+.B v
+sets video-off screen-saver preference.
+.TP 8
+.B \-v
+sets video-on screen-saver preference.
+.TP 8
+.B \-wm
+forces the default backing-store of all windows to be WhenMapped.  This
+is a backdoor way of getting backing-store to apply to all windows.
+Although all mapped windows will have backing store, the backing store
+attribute value reported by the server for a window will be the last
+value established by a client.  If it has never been set by a client,
+the server will report the default value, NotUseful.  This behavior is
+required by the X protocol, which allows the server to exceed the
+client's backing store expectations but does not provide a way to tell
+the client that it is doing so.
+.TP 8
+.B \-x \fIextension\fP
+loads the specified extension at init.
+This is a no-op for most implementations.
+.SH SERVER DEPENDENT OPTIONS
+Some X servers accept the following options:
+.TP 8
+.B \-ld \fIkilobytes\fP
+sets the data space limit of the server to the specified number of kilobytes.
+A value of zero makes the data size as large as possible.  The default value
+of \-1 leaves the data space limit unchanged.
+.TP 8
+.B \-lf \fIfiles\fP
+sets the number-of-open-files limit of the server to the specified number.
+A value of zero makes the limit as large as possible.  The default value
+of \-1 leaves the limit unchanged.
+.TP 8
+.B \-ls \fIkilobytes\fP
+sets the stack space limit of the server to the specified number of kilobytes.
+A value of zero makes the stack size as large as possible.  The default value
+of \-1 leaves the stack space limit unchanged.
+.TP 8
+.B \-logo
+turns on the X Window System logo display in the screen-saver.
+There is currently no way to change this from a client.
+.TP 8
+.B nologo
+turns off the X Window System logo display in the screen-saver.
+There is currently no way to change this from a client.
+.SH XDMCP OPTIONS
+X servers that support XDMCP have the following options.
+See the \fIX Display Manager Control Protocol\fP specification for more
+information.
+.TP 8
+.B \-query \fIhost-name\fP
+Enable XDMCP and send Query packets to the specified host.
+.TP 8
+.B \-broadcast
+Enable XDMCP and broadcast BroadcastQuery packets to the network.  The
+first responding display manager will be chosen for the session.
+.TP 8
+.B \-indirect \fIhost-name\fP
+Enable XDMCP and send IndirectQuery packets to the specified host.
+.TP 8
+.B \-port \fIport-num\fP
+Use an alternate port number for XDMCP packets.  Must be specified before
+any \-query, \-broadcast or \-indirect options.
+.TP 8
+.B \-class \fIdisplay-class\fP
+XDMCP has an additional display qualifier used in resource lookup for
+display-specific options.  This option sets that value, by default it 
+is "MIT-Unspecified" (not a very useful value).
+.TP 8
+.B \-cookie \fIxdm-auth-bits\fP
+When testing XDM-AUTHENTICATION-1, a private key is shared between the
+server and the manager.  This option sets the value of that private
+data (not that it is very private, being on the command line!).
+.TP 8
+.B \-displayID \fIdisplay-id\fP
+Yet another XDMCP specific value, this one allows the display manager to
+identify each display so that it can locate the shared key.
+.SH XKEYBOARD OPTIONS
+X servers that support the XKEYBOARD extension accept the following options:
+.ig
+.TP 8
+.B \-xkbdir \fIdirectory\fP
+base directory for keyboard layout files
+..
+.TP 8
+.B \-xkbmap \fIfilename\fP
+keyboard description to load on startup
+.TP 8
+.B [+-]accessx
+enable(+) or disable(-) AccessX key sequences
+.TP 8
+.B \-ar1 \fImilliseconds\fP
+sets the length of time in milliseconds that a key must be depressed before
+autorepeat starts
+.TP 8
+.B \-ar2 \fImilliseconds\fP
+sets the length of time in milliseconds that should elapse between
+autorepeat-generated keystrokes
+.PP
+Many servers also have device-specific command line options.  See the
+manual pages for the individual servers for more details.
+.SH SECURITY EXTENSION OPTIONS
+X servers that support the SECURITY extension accept the following option:
+.TP 8
+.B \-sp \fIfilename\fP
+causes
+the server to attempt to read and interpret filename as a security policy
+file with the format described below.  The file is read at
+server startup and reread at each server reset.
+.PP
+The syntax of the security policy file is as follows.
+Notation: "*" means zero or more occurrences of the preceding element,
+and "+" means one or more occurrences.  To interpret <foo/bar>, ignore
+the text after the /; it is used to distinguish between instances of
+<foo> in the next section.
+.PP
+.nf
+<policy file> ::= <version line> <other line>*
+
+<version line> ::= <string/v> '\en'
+
+<other line > ::= <comment> | <access rule> | <site policy> | <blank line>
+
+<comment> ::= # <not newline>* '\en'
+
+<blank line> ::= <space> '\en'
+
+<site policy> ::= sitepolicy <string/sp> '\en'
+
+<access rule> ::= property <property/ar> <window> <perms> '\en'
+
+<property> ::= <string>
+
+<window> ::= any | root | <required property>
+
+<required property> ::= <property/rp> | <property with value>
+
+<property with value> ::= <property/rpv> = <string/rv>
+
+<perms> ::= [ <operation> | <action> | <space> ]*
+
+<operation> ::= r | w | d
+
+<action> ::= a | i | e
+
+<string> ::= <dbl quoted string> | <single quoted string> | <unqouted string>
+
+<dbl quoted string> ::= <space> " <not dqoute>* " <space>
+
+<single quoted string> ::= <space> ' <not squote>* ' <space>
+
+<unquoted string> ::= <space> <not space>+ <space>
+
+<space> ::= [ ' ' | '\et' ]*
+
+Character sets:
+
+<not newline> ::= any character except '\en'
+<not dqoute>  ::= any character except "
+<not squote>  ::= any character except '
+<not space>   ::= any character except those in <space>
+.fi
+.PP
+The semantics associated with the above syntax are as follows.
+.PP
+<version line>, the first line in the file, specifies the file format
+version.  If the server does not recognize the version <string/v>, it
+ignores the rest of the file.  The version string for the file format
+described here is "version-1" .
+.PP
+Once past the <version line>, lines that do not match the above syntax
+are ignored.
+.PP
+<comment> lines are ignored.
+.PP
+<sitepolicy> lines are currently ignored.  They are intended to
+specify the site policies used by the XC-QUERY-SECURITY-1
+authorization method.
+.PP
+<access rule> lines specify how the server should react to untrusted
+client requests that affect the X Window property named <property/ar>.
+The rest of this section describes the interpretation of an
+<access rule>.
+.PP
+For an <access rule> to apply to a given instance of <property/ar>,
+<property/ar> must be on a window that is in the set of windows
+specified by <window>.  If <window> is any, the rule applies to
+<property/ar> on any window.  If <window> is root, the rule applies to
+<property/ar> only on root windows.
+.PP
+If <window> is <required property>, the following apply.  If <required
+property> is a <property/rp>, the rule applies when the window also
+has that <property/rp>, regardless of its value.  If <required
+property> is a <property with value>, <property/rpv> must also have
+the value specified by <string/rv>.  In this case, the property must
+have type STRING and format 8, and should contain one or more
+null-terminated strings.  If any of the strings match <string/rv>, the
+rule applies.
+.PP
+The definition of string matching is simple case-sensitive string
+comparison with one elaboration: the occurence of the character '*' in
+<string/rv> is a wildcard meaning "any string."  A <string/rv> can
+contain multiple wildcards anywhere in the string.  For example, "x*"
+matches strings that begin with x, "*x" matches strings that end with
+x, "*x*" matches strings containing x, and "x*y*" matches strings that
+start with x and subsequently contain y.
+.PP
+There may be multiple <access rule> lines for a given <property/ar>.
+The rules are tested in the order that they appear in the file.  The
+first rule that applies is used.
+.PP
+<perms> specify operations that untrusted clients may attempt, and
+the actions that the server should take in response to those operations.
+.PP
+<operation> can be r (read), w (write), or d (delete).  The following
+table shows how X Protocol property requests map to these operations
+in the X Consortium server implementation.
+.PP
+.nf
+GetProperty    r, or r and d if delete = True
+ChangeProperty w
+RotateProperties       r and w
+DeleteProperty d
+ListProperties none, untrusted clients can always list all properties
+.fi
+.PP
+<action> can be a (allow), i (ignore), or e (error).  Allow means
+execute the request as if it had been issued by a trusted client.
+Ignore means treat the request as a no-op.  In the case of
+GetProperty, ignore means return an empty property value if the
+property exists, regardless of its actual value.  Error means do not
+execute the request and return a BadAtom error with the atom set to
+the property name.  Error is the default action for all properties,
+including those not listed in the security policy file.
+.PP
+An <action> applies to all <operation>s that follow it, until the next
+<action> is encountered.  Thus, irwad  means ignore read and write,
+allow delete.
+.PP
+GetProperty and RotateProperties may do multiple operations (r and d,
+or r and w).  If different actions apply to the operations, the most
+severe action is applied to the whole request; there is no partial
+request execution.  The severity ordering is: allow < ignore < error.
+Thus, if the <perms> for a property are ired (ignore read, error
+delete), and an untrusted client attempts GetProperty on that property
+with delete = True, an error is returned, but the property value is
+not.  Similarly, if any of the properties in a RotateProperties do not
+allow both read and write, an error is returned without changing any
+property values.
+.PP
+Here is an example security policy file.
+.PP
+.ta 3i 4i
+.nf
+version-1 
+
+# Allow reading of application resources, but not writing.
+property RESOURCE_MANAGER      root    ar iw
+property SCREEN_RESOURCES      root    ar iw
+
+# Ignore attempts to use cut buffers.  Giving errors causes apps to crash,
+# and allowing access may give away too much information.
+property CUT_BUFFER0   root    irw
+property CUT_BUFFER1   root    irw
+property CUT_BUFFER2   root    irw
+property CUT_BUFFER3   root    irw
+property CUT_BUFFER4   root    irw
+property CUT_BUFFER5   root    irw
+property CUT_BUFFER6   root    irw
+property CUT_BUFFER7   root    irw
+
+# If you are using Motif, you probably want these.
+property _MOTIF_DEFAULT_BINDINGS       root    ar iw
+property _MOTIF_DRAG_WINDOW    root    ar iw
+property _MOTIF_DRAG_TARGETS   any     ar iw
+property _MOTIF_DRAG_ATOMS     any     ar iw
+property _MOTIF_DRAG_ATOM_PAIRS        any     ar iw
+
+# The next two rules let xwininfo -tree work when untrusted.
+property WM_NAME       any     ar
+
+# Allow read of WM_CLASS, but only for windows with WM_NAME.
+# This might be more restrictive than necessary, but demonstrates
+# the <required property> facility, and is also an attempt to
+# say "top level windows only."
+property WM_CLASS      WM_NAME ar
+
+# These next three let xlsclients work untrusted.  Think carefully
+# before including these; giving away the client machine name and command
+# may be exposing too much.
+property WM_STATE      WM_NAME ar
+property WM_CLIENT_MACHINE     WM_NAME ar
+property WM_COMMAND    WM_NAME ar
+
+# To let untrusted clients use the standard colormaps created by
+# xstdcmap, include these lines.
+property RGB_DEFAULT_MAP       root    ar
+property RGB_BEST_MAP  root    ar
+property RGB_RED_MAP   root    ar
+property RGB_GREEN_MAP root    ar
+property RGB_BLUE_MAP  root    ar
+property RGB_GRAY_MAP  root    ar
+
+# To let untrusted clients use the color management database created
+# by xcmsdb, include these lines.
+property XDCCC_LINEAR_RGB_CORRECTION   root    ar
+property XDCCC_LINEAR_RGB_MATRICES     root    ar
+property XDCCC_GRAY_SCREENWHITEPOINT   root    ar
+property XDCCC_GRAY_CORRECTION root    ar
+
+# To let untrusted clients use the overlay visuals that many vendors
+# support, include this line.
+property SERVER_OVERLAY_VISUALS        root    ar
+
+# Dumb examples to show other capabilities.
+
+# oddball property names and explicit specification of error conditions
+property "property with spaces"        'property with "'       aw er ed
+
+# Allow deletion of Woo-Hoo if window also has property OhBoy with value
+# ending in "son".  Reads and writes will cause an error.
+property Woo-Hoo       OhBoy = "*son"  ad
+
+.fi
+.SH "NETWORK CONNECTIONS"
+The X server supports client connections via a platform-dependent subset of
+the following transport types: TCP\/IP, Unix Domain sockets, DECnet,
+and several varieties of SVR4 local connections.  See the DISPLAY
+NAMES section of the \fIX(1)\fP manual page to learn how to specify
+which transport type clients should try to use.
+.SH GRANTING ACCESS
+The X server implements a platform-dependent subset of the following
+authorization protocols: MIT-MAGIC-COOKIE-1, XDM-AUTHORIZATION-1,
+SUN-DES-1, and MIT-KERBEROS-5.  See the \fIXsecurity(1)\fP manual page
+for information on the operation of these protocols.
+.PP
+Authorization data required by the above protocols is passed to the
+server in a private file named with the \fB\-auth\fP command line
+option.  Each time the server is about to accept the first connection
+after a reset (or when the server is starting), it reads this file.
+If this file contains any authorization records, the local host is not
+automatically allowed access to the server, and only clients which
+send one of the authorization records contained in the file in the
+connection setup information will be allowed access.  See the
+\fIXau\fP manual page for a description of the binary format of this
+file.  See \fIxauth(1)\fP for maintenance of this file, and distribution
+of its contents to remote hosts.
+.PP
+The X server also uses a host-based access control list for deciding
+whether or not to accept connections from clients on a particular machine.
+If no other authorization mechanism is being used,
+this list initially consists of the host on which the server is running as
+well as any machines listed in the file \fI/etc/X\fBn\fI.hosts\fR, where
+\fBn\fP is the display number of the server.  Each line of the file should
+contain either an Internet hostname (e.g. expo.lcs.mit.edu) or a DECnet
+hostname in double colon format (e.g. hydra::).  There should be no leading
+or trailing spaces on any lines.  For example:
+.sp
+.in +8
+.nf 
+joesworkstation
+corporate.company.com
+star::
+bigcpu::
+.fi
+.in -8
+.PP
+Users can add or remove hosts from this list and enable or disable access
+control using the \fIxhost\fP command from the same machine as the server.
+.PP
+The X protocol intrinsically does not have any notion of window operation
+permissions or place any restrictions on what a client can do; if a program can
+connect to a display, it has full run of the screen.  
+X servers that support the SECURITY extension fare better because clients
+can be designated untrusted via the authorization they use to connect; see
+the \fIxauth(1)\fP manual page for details.  Restrictions are imposed
+on untrusted clients that curtail the mischief they can do.  See the SECURITY
+extension specification for a complete list of these restrictions.
+.PP
+Sites that have better
+authentication and authorization systems might wish to make
+use of the hooks in the libraries and the server to provide additional
+security models.
+.SH SIGNALS
+The X server attaches special meaning to the following signals:
+.TP 8
+.I SIGHUP
+This signal causes the server to close all existing connections, free all
+resources, and restore all defaults.  It is sent by the display manager
+whenever the main user's main application (usually an \fIxterm\fP or window
+manager) exits to force the server to clean up and prepare for the next
+user.
+.TP 8
+.I SIGTERM
+This signal causes the server to exit cleanly.
+.TP 8
+.I SIGUSR1
+This signal is used quite differently from either of the above.  When the
+server starts, it checks to see if it has inherited SIGUSR1 as SIG_IGN
+instead of the usual SIG_DFL.  In this case, the server sends a SIGUSR1 to
+its parent process after it has set up the various connection schemes.
+\fIXdm\fP uses this feature to recognize when connecting to the server
+is possible.
+.SH FONTS
+The X server
+can obtain fonts from directories and/or from font servers.
+The list of directories and font servers
+the X server uses when trying to open a font is controlled
+by the \fIfont path\fP.  
+.LP
+The default font path is
+"<XRoot>/lib/X11/fonts/misc/,
+<XRoot>/lib/X11/fonts/Speedo/,
+<XRoot>/lib/X11/fonts/Type1/,
+<XRoot>/lib/X11/fonts/75dpi/,
+<XRoot>/lib/X11/fonts/100dpi/" .
+where <XRoot> refers to the root of the X11 install tree.
+.LP
+The font path can be set with the \fB\-fp\fP option or by \fIxset(1)\fP
+after the server has started.
+.SH FILES
+.TP 30
+/etc/X\fBn\fP.hosts
+Initial access control list for display number \fBn\fP
+.TP 30
+<XRoot>/lib/X11/fonts/misc, <XRoot>/lib/X11/fonts/75dpi, <XRoot>/lib/X11/fonts/100dpi 
+Bitmap font directories
+.TP 30
+<XRoot>/lib/X11/fonts/Speedo, <XRoot>/lib/X11/fonts/Type1
+Outline font directories
+.TP 30
+<XRoot>/lib/X11/fonts/PEX
+PEX font directories
+.TP 30
+<XRoot>/lib/X11/rgb.txt
+Color database
+.TP 30
+/tmp/.X11-unix/X\fBn\fP
+Unix domain socket for display number \fBn\fP
+.TP 30
+/tmp/rcX\fBn\fP
+Kerberos 5 replay cache for display number \fBn\fP
+.TP 30
+/usr/adm/X\fBn\fPmsgs
+Error log file for display number \fBn\fP if run from \fIinit(8)\fP
+.TP 30
+<XRoot>/lib/X11/xdm/xdm-errors
+Default error log file if the server is run from \fIxdm(1)\fP
+.LP
+Note: <XRoot> refers to the root of the X11 install tree.
+.SH "SEE ALSO"
+General information: X(1)
+.PP
+Protocols:
+.I "X Window System Protocol,"
+.I "The X Font Service Protocol,"
+.I "X Display Manager Control Protocol"
+.PP
+Fonts: bdftopcf(1), mkfontdir(1), xfs(1), xlsfonts(1), xfontsel(1), xfd(1),
+.I "X Logical Font Description Conventions"
+.PP
+Security: Xsecurity(1), xauth(1), Xau(1), xdm(1), xhost(1),
+.I "Security Extension Specification"
+.PP
+Starting the server: xdm(1), xinit(1)
+.PP
+Controlling the server once started: xset(1), xsetroot(1), xhost(1)
+.PP
+Server-specific man pages: 
+Xdec(1), XmacII(1), Xsun(1), Xnest(1), Xvfb(1),
+XF86_Accel(1), XF86_Mono(1), XF86_SVGA(1), XF86_VGA16(1), XFree86(1)
+.PP
+Server internal documentation:
+.I "Definition of the Porting Layer for the X v11 Sample Server"
+.SH AUTHORS
+The sample server was originally written by Susan Angebranndt, Raymond
+Drewry, Philip Karlton, and Todd Newman, from Digital Equipment
+Corporation, with support from a large cast.  It has since been
+extensively rewritten by Keith Packard and Bob Scheifler, from MIT.
+Dave Wiggins took over post-R5 and made substantial improvements.
diff --git a/Xserver/programs/Xserver/Xvnc.man b/Xserver/programs/Xserver/Xvnc.man
new file mode 100644 (file)
index 0000000..e2a385d
--- /dev/null
@@ -0,0 +1,169 @@
+.TH Xvnc 1 "28 February 2003" "RealVNC Ltd" "Virtual Network Computing"
+.SH NAME
+Xvnc \- the X VNC server 
+.SH SYNOPSIS
+.B Xvnc
+.RI [ options ] 
+.RI : display#
+.SH DESCRIPTION
+.B Xvnc
+is the X VNC (Virtual Network Computing) server.  It is based on a standard X
+server, but it has a "virtual" screen rather than a physical one.  X
+applications display themselves on it as if it were a normal X display, but
+they can only be accessed via a VNC viewer - see \fBvncviewer\fP(1).
+
+So Xvnc is really two servers in one. To the applications it is an X server,
+and to the remote VNC users it is a VNC server. By convention we have arranged
+that the VNC server display number will be the same as the X server display
+number, which means you can use eg. snoopy:2 to refer to display 2 on machine
+"snoopy" in both the X world and the VNC world.
+
+The best way of starting \fBXvnc\fP is via the \fBvncserver\fP script.  This
+sets up the environment appropriately and runs some X applications to get you
+going.  See the manual page for \fBvncserver\fP(1) for more information.
+
+.SH OPTIONS
+.B Xvnc
+takes lots of options - running \fBXvnc -help\fP gives a list.  Many of these
+are standard X server options, which are described in the \fBXserver\fP(1)
+manual page.
+
+.TP
+.B \-geometry \fIwidth\fPx\fIheight\fP
+Specify the size of the desktop to be created. Default is 640x480.
+
+.TP
+.B \-depth \fIdepth\fP
+Specify the pixel depth in bits of the desktop to be created. Default is 8,
+other possible values are 15, 16 and 24 - anything else is likely to cause
+strange behaviour by applications.
+
+.TP
+.B \-pixelformat \fIformat\fP
+Specify pixel format for server to use (BGRnnn or RGBnnn).  The default for
+depth 8 is BGR233 (meaning the most significant two bits represent blue, the
+next three green, and the least significant three represent red), the default
+for depth 16 is RGB565 and for depth 24 is RGB888.
+
+.TP
+.B \-cc 3
+As an alternative to the default TrueColor visual, this allows you to run an
+Xvnc server with a PseudoColor visual (i.e. one which uses a colour map or
+palette), which can be useful for running some old X applications which only
+work on such a display.  Note that viewing such a desktop can be painful
+because it usually results in a full-screen redraw every time an entry in the
+colour map changes.  Values other than 3 (PseudoColor) and 4 (TrueColor) for
+the \-cc option may result in strange behaviour, and PseudoColor desktops must
+be 8 bits deep.
+
+.TP
+.B \-rfbport \fIport\fP
+Specifies the TCP port on which Xvnc listens for connections from viewers (the
+protocol used in VNC is called RFB - "remote framebuffer").  The default is
+5900 plus the display number.
+
+.TP
+.B \-rfbwait \fItime\fP
+Time in milliseconds to wait for a viewer which is blocking Xvnc.  This is
+necessary because Xvnc is single-threaded and sometimes blocks until the viewer
+has finished sending or receiving a message - note that this does not mean an
+update will be aborted after this time.  Default is 20000 (20 seconds).
+
+.TP
+.B \-nocursor
+Don't draw a cursor.  This can be useful when debugging a viewer to make the
+updates drawn more predictable.
+
+.TP
+.B \-rfbauth \fIpasswd-file\fP
+Specifies the file containing the password used to authenticate viewers.  The
+file is accessed each time a connection comes in, so it can be changed on the
+fly via \fBvncpasswd\fP(1).
+
+.TP
+.B \-httpd \fIdirectory\fP
+Run a mini-HTTP server which serves files from the given directory.  Normally
+the directory will contain the classes for the Java viewer.  In addition, files
+with a .vnc extension will have certain substitutions made so that a single
+installation of the Java VNC viewer can be served by separate instances of
+Xvnc.
+
+.TP
+.B \-httpport \fIport\fP
+Specifies the port on which the mini-HTTP server runs.  Default is 5800 plus
+the display number.
+
+.TP
+.B \-deferupdate \fItime\fP
+Xvnc uses a "deferred update" mechanism which enhances performance in many
+cases. After any change to the framebuffer, Xvnc waits for this number of
+milliseconds (default 40) before sending an update to any waiting clients. This
+means that more changes tend to get coalesced together in a single
+update. Setting it to 0 results in the same behaviour as earlier versions of
+Xvnc, where the first change to the framebuffer causes an immediate update to
+any waiting clients.
+
+.TP
+.B \-economictranslate
+The server normally uses a lookup table for translating pixel values when the
+viewer requests a different format from the native one used by the server.
+This can use up to 256Kbytes per connected viewer, so if you have many viewers
+you may wish to specify this option which will save memory at the expense of a
+little bit of speed. Only relevant for 16-bit-deep desktops.
+
+.TP
+.B \-maxrects \fInum\fP
+Sets the maximum number of rectangles Xvnc will send in one update.  If an
+update would consist of more than this many rectangles, then an update of a
+single bounding rectangle is sent instead.  This makes sense because sending a
+large number of small rectangles is less efficient than sending one large
+rectangle, even when this means updating pixels which haven't actually changed.
+The default is 50.
+
+.TP
+.B \-desktop \fIdesktop-name\fP
+Each desktop has a name which may be displayed by the viewer. It defaults to
+"x11".
+
+.TP
+.B \-alwaysshared
+Always treat new clients as shared (i.e. ignore client's shared flag). 
+
+.TP
+.B \-nevershared
+Never treat new clients as shared (i.e. ignore client's shared flag). 
+
+.TP
+.B \-dontdisconnect
+Don't disconnect existing clients when a new "non-shared" connection comes
+in. Instead the new connection is refused. New "shared" connections are still
+allowed in the normal way.
+
+.TP
+.B \-localhost
+Only allow connections from the same machine. Useful if you use SSH and want to
+stop non-SSH connections from any other hosts. See the guide to using VNC with
+SSH on the web site.
+
+.TP
+.B \-inetd 
+This significantly changes Xvnc's behaviour so that it can be launched from
+inetd. Instead of listening for TCP connections it uses its standard input and
+standard output as a connection to the VNC viewer. See the information on the
+extras page on the web site for details.
+
+.SH SEE ALSO
+.BR vncconnect (1),
+.BR vncpasswd (1),
+.BR vncserver (1),
+.BR vncviewer (1),
+.BR Xserver (1)
+.br
+http://www.realvnc.com
+
+.SH AUTHOR
+Tristan Richardson, RealVNC Ltd.
+
+VNC was originally developed by the RealVNC team while at Olivetti Research Ltd
+/ AT&T Laboratories Cambridge.  It is now being maintained by RealVNC Ltd.  See
+http://www.realvnc.com for details.
diff --git a/Xserver/programs/Xserver/cfb/Imakefile b/Xserver/programs/Xserver/cfb/Imakefile
new file mode 100644 (file)
index 0000000..18df87d
--- /dev/null
@@ -0,0 +1,252 @@
+XCOMM $XConsortium: Imakefile /main/67 1996/12/02 10:19:53 lehors $
+XCOMM $XFree86: xc/programs/Xserver/cfb/Imakefile,v 3.9.2.1 1997/05/03 09:45:03 dawes Exp $
+#include <Server.tmpl>
+
+#ifndef PixelSize
+#define PixelSize 8
+#endif
+
+#if PixelSize == 8
+/* cfb8cppl.c MUST come last to avoid confusing makedepend */
+PSZSRCS = cfb8bit.c cfbteblt8.c cfbglrop8.c cfbpush8.c cfbrctstp8.c cfb8cppl.c
+PSZOBJS = cfb8bit.o cfbteblt8.o cfbglrop8.o cfbpush8.o cfbrctstp8.o cfb8cppl.o
+#ifdef MipsArchitecture
+#ifndef ArcArchitecture
+#ifndef Mips64Architecture
+STIPPLESRC = stipmips.s stipmipste.s
+STIPPLEOBJ = stipmips.o stipmipste.o
+STIPPLEDEF = -DHAS_STIPPLE_CODE
+#endif
+#endif
+#endif
+#ifdef SparcArchitecture
+STIPPLESRC = stipsparc.s stipsparcte.s
+STIPPLEOBJ = stipsparc.o stipsparcte.o
+STIPPLEDEF = -DHAS_STIPPLE_CODE
+#endif
+#endif
+
+#if PixelSize == 32
+#ifdef SparcArchitecture
+STIPPLESRC = stipsprc32.s stipsprcte32.s
+STIPPLEOBJ = stipsprc32.o stipsprcte32.o
+STIPPLEDEF = -DHAS_STIPPLE_CODE
+#endif
+#endif
+
+
+SRCS =  cfbgc.c cfbrrop.c cfbwindow.c \
+        cfbpntwin.c cfbmskbits.c cfbpixmap.c cfbbitblt.c \
+        cfbfillsp.c cfbsetsp.c cfbscrinit.c cfballpriv.c \
+        cfbgetsp.c cfbfillrct.c \
+        cfbsolidC.c cfbsolidX.c cfbsolidG.c \
+        cfbtileoddC.c cfbtileoddG.c cfbtile32C.c cfbtile32G.c \
+        cfbcmap.c cfbzerarcC.c cfbzerarcX.c cfbzerarcG.c \
+        cfbfillarcC.c cfbfillarcG.c \
+        cfbigblt8.c cfbglblt8.c cfbtegblt.c cfbbstore.c \
+        cfbbltC.c cfbbltX.c cfbbltO.c cfbbltG.c \
+        cfbpolypnt.c \
+        cfbbres.c cfbline.c cfbhrzvert.c cfbbresd.c cfbimage.c cfbseg.c \
+        cfb8lineCO.c cfb8lineX.c cfb8lineG.c cfb8lineCP.c \
+        cfb8segC.c cfb8segX.c cfb8segG.c cfb8segCS.c \
+        cfbply1rctC.c cfbply1rctG.c $(PSZSRCS)
+
+OBJS =   cfbgc.o cfbrrop.o cfbwindow.o \
+        cfbgetsp.o cfbfillrct.o \
+        cfbsolidC.o cfbsolidX.o cfbsolidG.o \
+        cfbtileoddC.o cfbtileoddG.o cfbtile32C.o cfbtile32G.o \
+        cfbfillsp.o cfbsetsp.o cfbscrinit.o cfballpriv.o \
+        cfbpntwin.o cfbmskbits.o cfbpixmap.o \
+        cfbcmap.o cfbzerarcC.o cfbzerarcX.o cfbzerarcG.o \
+        cfbfillarcC.o cfbfillarcG.o \
+        cfbigblt8.o cfbglblt8.o cfbtegblt.o cfbbstore.o \
+        cfbpolypnt.o \
+        cfbbres.o cfbline.o cfbhrzvert.o cfbbresd.o cfbimage.o cfbseg.o \
+        cfb8lineCO.o cfb8lineX.o cfb8lineG.o cfb8lineCP.o \
+        cfb8segCS.o cfb8segX.o cfb8segG.o cfb8segC.o \
+        cfbbitblt.o cfbbltC.o cfbbltX.o cfbbltO.o cfbbltG.o \
+        cfbply1rctC.o cfbply1rctG.o $(PSZOBJS) $(STIPPLEOBJ)
+
+#ifdef XFree86Version
+EXTRAINCLUDES = -I../hw/xfree86/common
+EXTRADEFINES  = -DXFREE86
+#endif
+   INCLUDES = -I. -I../cfb -I../mfb -I../mi -I../include -I$(XINCLUDESRC) \
+             -I$(FONTINCSRC) $(EXTRAINCLUDES)
+   LINTLIBS = ../dix/llib-ldix.ln ../os/llib-los.ln \
+            ../mfb/llib-lmfb.ln ../mi/llib-lmi.ln
+    DEFINES = -DPSZ=PixelSize $(EXTRADEFINES)
+
+NormalLibraryObjectRule()
+NormalLibraryTarget(cfb,$(OBJS))
+LintLibraryTarget(cfb,$(SRCS))
+
+NormalLintTarget($(SRCS))
+
+#ifdef LinkDirectory
+
+LinkSourceFile(cfb.h,LinkDirectory)
+LinkSourceFile(cfbmap.h,LinkDirectory)
+LinkSourceFile(cfballpriv.c,LinkDirectory)
+LinkSourceFile(cfbbitblt.c,LinkDirectory)
+LinkSourceFile(cfbblt.c,LinkDirectory)
+LinkSourceFile(cfbbres.c,LinkDirectory)
+LinkSourceFile(cfbbresd.c,LinkDirectory)
+LinkSourceFile(cfbbstore.c,LinkDirectory)
+LinkSourceFile(cfbcmap.c,LinkDirectory)
+LinkSourceFile(cfbfillarc.c,LinkDirectory)
+LinkSourceFile(cfbfillrct.c,LinkDirectory)
+LinkSourceFile(cfbfillsp.c,LinkDirectory)
+LinkSourceFile(cfbgc.c,LinkDirectory)
+LinkSourceFile(cfbgetsp.c,LinkDirectory)
+LinkSourceFile(cfbhrzvert.c,LinkDirectory)
+LinkSourceFile(cfbimage.c,LinkDirectory)
+LinkSourceFile(cfbline.c,LinkDirectory)
+LinkSourceFile(cfb8line.c,LinkDirectory)
+LinkSourceFile(cfbmskbits.c,LinkDirectory)
+LinkSourceFile(cfbmskbits.h,LinkDirectory)
+LinkSourceFile(cfbpixmap.c,LinkDirectory)
+LinkSourceFile(cfbply1rct.c,LinkDirectory)
+LinkSourceFile(cfbpntwin.c,LinkDirectory)
+LinkSourceFile(cfbpolypnt.c,LinkDirectory)
+LinkSourceFile(cfbrrop.c,LinkDirectory)
+LinkSourceFile(cfbrrop.h,LinkDirectory)
+LinkSourceFile(cfbscrinit.c,LinkDirectory)
+LinkSourceFile(cfbsetsp.c,LinkDirectory)
+LinkSourceFile(cfbsolid.c,LinkDirectory)
+LinkSourceFile(cfbigblt8.c,LinkDirectory)
+LinkSourceFile(cfbglblt8.c,LinkDirectory)
+LinkSourceFile(cfbtegblt.c,LinkDirectory)
+LinkSourceFile(cfbtileodd.c,LinkDirectory)
+LinkSourceFile(cfbtile32.c,LinkDirectory)
+LinkSourceFile(cfbwindow.c,LinkDirectory)
+LinkSourceFile(cfbzerarc.c,LinkDirectory)
+LinkSourceFile(cfb8bit.h,LinkDirectory)
+#if PixelSize == 8
+LinkSourceFile(cfb8bit.c,LinkDirectory)
+LinkSourceFile(cfb8cppl.c,LinkDirectory)
+LinkSourceFile(cfbpush8.c,LinkDirectory)
+LinkSourceFile(cfbrctstp8.c,LinkDirectory)
+LinkSourceFile(cfbteblt8.c,LinkDirectory)
+#ifdef MipsArchitecture
+LinkSourceFile(stipmips.s,LinkDirectory)
+#endif
+#ifdef SparcArchitecture
+LinkSourceFile(stipsparc.s,LinkDirectory)
+#endif
+#endif
+#if PixelSize == 32
+#ifdef SparcArchitecture
+LinkSourceFile(stipsprc32.s,LinkDirectory)
+#endif
+#endif
+#endif
+
+ObjectFromSpecialSource(cfbseg,cfbline,-DPOLYSEGMENT)
+
+ObjectFromSpecialSource(cfbfillarcC,cfbfillarc,-DRROP=GXcopy)
+ObjectFromSpecialSource(cfbfillarcG,cfbfillarc,-DRROP=GXset)
+
+ObjectFromSpecialSource(cfbzerarcC,cfbzerarc,-DRROP=GXcopy)
+ObjectFromSpecialSource(cfbzerarcX,cfbzerarc,-DRROP=GXxor)
+ObjectFromSpecialSource(cfbzerarcG,cfbzerarc,-DRROP=GXset)
+
+ObjectFromSpecialSource(cfbbltC,cfbblt,-DMROP=Mcopy)
+ObjectFromSpecialSource(cfbbltX,cfbblt,-DMROP=Mxor)
+ObjectFromSpecialSource(cfbbltO,cfbblt,-DMROP=Mor)
+ObjectFromSpecialSource(cfbbltG,cfbblt,-DMROP=0)
+
+ObjectFromSpecialSource(cfbsolidC,cfbsolid,-DRROP=GXcopy)
+ObjectFromSpecialSource(cfbsolidX,cfbsolid,-DRROP=GXxor)
+ObjectFromSpecialSource(cfbsolidG,cfbsolid,-DRROP=GXset)
+
+ObjectFromSpecialSource(cfbtileoddC,cfbtileodd,-DMROP=Mcopy)
+ObjectFromSpecialSource(cfbtileoddG,cfbtileodd,-DMROP=0)
+
+ObjectFromSpecialSource(cfbtile32C,cfbtile32,-DMROP=Mcopy)
+ObjectFromSpecialSource(cfbtile32G,cfbtile32,-DMROP=0)
+
+ObjectFromSpecialSource(cfb8lineCO,cfb8line,-DRROP=GXcopy)
+ObjectFromSpecialSource(cfb8lineCP,cfb8line,-DRROP=GXcopy -DPREVIOUS)
+ObjectFromSpecialSource(cfb8lineX,cfb8line,-DRROP=GXxor)
+ObjectFromSpecialSource(cfb8lineG,cfb8line,-DRROP=GXset)
+
+ObjectFromSpecialSource(cfb8segCS,cfb8line,-DRROP=GXcopy -DPOLYSEGMENT -DWIDTH_SHIFT)
+ObjectFromSpecialSource(cfb8segC,cfb8line,-DRROP=GXcopy -DPOLYSEGMENT)
+ObjectFromSpecialSource(cfb8segX,cfb8line,-DRROP=GXxor -DPOLYSEGMENT)
+ObjectFromSpecialSource(cfb8segG,cfb8line,-DRROP=GXset -DPOLYSEGMENT)
+
+ObjectFromSpecialSource(cfbply1rctC,cfbply1rct,-DRROP=GXcopy)
+ObjectFromSpecialSource(cfbply1rctG,cfbply1rct,-DRROP=GXset)
+
+SpecialCObjectRule(cfbglblt8,$(_NOOP_),$(STIPPLEDEF))
+SpecialCObjectRule(cfbpixmap,$(ICONFIGFILES),$(_NOOP_))
+SpecialCObjectRule(cfbcmap,$(ICONFIGFILES),$(EXT_DEFINES) $(GLX_DEFINES))
+
+#if PixelSize == 8
+ObjectFromSpecialSource(cfbglrop8,cfbglblt8,-DGLYPHROP)
+
+#ifdef MipsArchitecture
+stipmipste.s: stipmips.s
+       $(RM) $@
+       $(LN) stipmips.s stipmipste.s
+clean::
+       $(RM) stipmipste.s
+
+stipmipste.o: stipmipste.s
+       $(AS) -o $@ -DTETEXT stipmipste.s
+#endif
+
+#ifdef SparcArchitecture
+stipsparcte.s: stipsparc.s
+       $(RM) $@
+       $(LN) stipsparc.s stipsparcte.s
+clean::
+       $(RM) stipsparcte.s
+
+stipsparc.o: stipsparc.s
+       $(CPP) stipsparc.s | $(AS) -o $@ -
+
+stipsparcte.o: stipsparcte.s
+       $(CPP) -DTETEXT stipsparcte.s | $(AS) -o $@ -
+#endif
+#endif
+
+#if PixelSize == 32
+#ifdef SparcArchitecture
+stipsprcte32.s: stipsprc32.s
+       $(RM) $@
+       $(LN) stipsprc32.s stipsprcte32.s
+clean::
+       $(RM) stipsprcte32.s
+
+stipsprc32.o: stipsprc32.s
+       $(CPP) stipsprc32.s | $(AS) -o $@ -
+
+stipsprcte32.o: stipsprcte32.s
+       $(CPP) -DTETEXT stipsprcte32.s | $(AS) -o $@ -
+#endif
+#endif
+
+#if PixelSize == 32
+InstallLinkKitNamedLibrary(cfb,cfb32,$(LINKKITDIR)/lib)
+#endif
+#if PixelSize == 24
+InstallLinkKitNamedLibrary(cfb,cfb24,$(LINKKITDIR)/lib)
+#endif
+#if PixelSize == 16
+InstallLinkKitNamedLibrary(cfb,cfb16,$(LINKKITDIR)/lib)
+#endif
+#if PixelSize == 8
+InstallLinkKitLibrary(cfb,$(LINKKITDIR)/lib)
+InstallLinkKitNonExecFile(cfb.h,$(LINKKITDIR)/include)
+InstallLinkKitNonExecFile(cfb8bit.h,$(LINKKITDIR)/include)
+InstallLinkKitNonExecFile(cfbmap.h,$(LINKKITDIR)/include)
+InstallLinkKitNonExecFile(cfbmskbits.h,$(LINKKITDIR)/include)
+InstallLinkKitNonExecFile(cfbrrop.h,$(LINKKITDIR)/include)
+#endif
+
+#ifndef OS2Architecture
+DependTarget()
+#endif
+
diff --git a/Xserver/programs/Xserver/cfb/cfb.h b/Xserver/programs/Xserver/cfb/cfb.h
new file mode 100644 (file)
index 0000000..adfb352
--- /dev/null
@@ -0,0 +1,1507 @@
+/* $XConsortium: cfb.h,v 5.37 94/04/17 20:28:38 dpw Exp $ */
+/* $XFree86: xc/programs/Xserver/cfb/cfb.h,v 3.3.2.2 1997/05/30 13:50:37 hohndel Exp $ */
+/************************************************************
+Copyright 1987 by Sun Microsystems, Inc. Mountain View, CA.
+
+                    All Rights Reserved
+
+Permission  to  use,  copy,  modify,  and  distribute   this
+software  and  its documentation for any purpose and without
+fee is hereby granted, provided that the above copyright no-
+tice  appear  in all copies and that both that copyright no-
+tice and this permission notice appear in  supporting  docu-
+mentation,  and  that the names of Sun or X Consortium
+not be used in advertising or publicity pertaining to 
+distribution  of  the software  without specific prior 
+written permission. Sun and X Consortium make no 
+representations about the suitability of this software for 
+any purpose. It is provided "as is" without any express or 
+implied warranty.
+
+SUN DISCLAIMS ALL WARRANTIES WITH REGARD TO  THIS  SOFTWARE,
+INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FIT-
+NESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SUN BE  LI-
+ABLE  FOR  ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
+ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,  DATA  OR
+PROFITS,  WHETHER  IN  AN  ACTION OF CONTRACT, NEGLIGENCE OR
+OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION  WITH
+THE USE OR PERFORMANCE OF THIS SOFTWARE.
+
+********************************************************/
+
+#include "X.h"
+#include "pixmap.h"
+#include "region.h"
+#include "gc.h"
+#include "colormap.h"
+#include "miscstruct.h"
+#include "servermd.h"
+#include "windowstr.h"
+#include "mfb.h"
+#undef PixelType
+
+#include "cfbmap.h"
+
+/*
+   private filed of pixmap
+   pixmap.devPrivate = (unsigned int *)pointer_to_bits
+   pixmap.devKind = width_of_pixmap_in_bytes
+*/
+
+extern int  cfbGCPrivateIndex;
+extern int  cfbWindowPrivateIndex;
+
+/* private field of GC */
+typedef struct {
+    unsigned char       rop;            /* special case rop values */
+    /* next two values unused in cfb, included for compatibility with mfb */
+    unsigned char       ropOpStip;      /* rop for opaque stipple */
+    /* this value is ropFillArea in mfb, usurped for cfb */
+    unsigned char       oneRect;       /*  drawable has one clip rect */
+    unsigned           fExpose:1;      /* callexposure handling ? */
+    unsigned           freeCompClip:1;
+    PixmapPtr          pRotatedPixmap;
+    RegionPtr          pCompositeClip; /* FREE_CC or REPLACE_CC */
+    unsigned long      xor, and;       /* reduced rop values */
+    } cfbPrivGC;
+
+typedef cfbPrivGC      *cfbPrivGCPtr;
+
+#define cfbGetGCPrivate(pGC)   ((cfbPrivGCPtr)\
+       (pGC)->devPrivates[cfbGCPrivateIndex].ptr)
+
+#define cfbGetCompositeClip(pGC) (((cfbPrivGCPtr)\
+       (pGC)->devPrivates[cfbGCPrivateIndex].ptr)->pCompositeClip)
+
+/* way to carry RROP info around */
+typedef struct {
+    unsigned char      rop;
+    unsigned long      xor, and;
+} cfbRRopRec, *cfbRRopPtr;
+
+/* private field of window */
+typedef struct {
+    unsigned   char fastBorder; /* non-zero if border is 32 bits wide */
+    unsigned   char fastBackground;
+    unsigned short unused; /* pad for alignment with Sun compiler */
+    DDXPointRec        oldRotate;
+    PixmapPtr  pRotatedBackground;
+    PixmapPtr  pRotatedBorder;
+    } cfbPrivWin;
+
+#define cfbGetWindowPrivate(_pWin) ((cfbPrivWin *)\
+       (_pWin)->devPrivates[cfbWindowPrivateIndex].ptr)
+
+
+/* cfb8bit.c */
+
+extern int cfbSetStipple(
+#if NeedFunctionPrototypes
+    int /*alu*/,
+    unsigned long /*fg*/,
+    unsigned long /*planemask*/
+#endif
+);
+
+extern int cfbSetOpaqueStipple(
+#if NeedFunctionPrototypes
+    int /*alu*/,
+    unsigned long /*fg*/,
+    unsigned long /*bg*/,
+    unsigned long /*planemask*/
+#endif
+);
+
+extern int cfbComputeClipMasks32(
+#if NeedFunctionPrototypes
+    BoxPtr /*pBox*/,
+    int /*numRects*/,
+    int /*x*/,
+    int /*y*/,
+    int /*w*/,
+    int /*h*/,
+    CARD32 * /*clips*/
+#endif
+);
+/* cfb8cppl.c */
+
+extern void cfbCopyImagePlane(
+#if NeedFunctionPrototypes
+    DrawablePtr /*pSrcDrawable*/,
+    DrawablePtr /*pDstDrawable*/,
+    int /*rop*/,
+    RegionPtr /*prgnDst*/,
+    DDXPointPtr /*pptSrc*/,
+    unsigned long /*planemask*/
+#endif
+);
+
+extern void cfbCopyPlane8to1(
+#if NeedFunctionPrototypes
+    DrawablePtr /*pSrcDrawable*/,
+    DrawablePtr /*pDstDrawable*/,
+    int /*rop*/,
+    RegionPtr /*prgnDst*/,
+    DDXPointPtr /*pptSrc*/,
+    unsigned long /*planemask*/,
+    unsigned long /*bitPlane*/
+#endif
+);
+/* cfb8lineCO.c */
+
+extern int cfb8LineSS1RectCopy(
+#if NeedFunctionPrototypes
+    DrawablePtr /*pDrawable*/,
+    GCPtr /*pGC*/,
+    int /*mode*/,
+    int /*npt*/,
+    DDXPointPtr /*pptInit*/,
+    DDXPointPtr /*pptInitOrig*/,
+    int * /*x1p*/,
+    int * /*y1p*/,
+    int * /*x2p*/,
+    int * /*y2p*/
+#endif
+);
+
+extern void cfb8LineSS1Rect(
+#if NeedFunctionPrototypes
+    DrawablePtr /*pDrawable*/,
+    GCPtr /*pGC*/,
+    int /*mode*/,
+    int /*npt*/,
+    DDXPointPtr /*pptInit*/
+#endif
+);
+
+extern void cfb8ClippedLineCopy(
+#if NeedFunctionPrototypes
+    DrawablePtr /*pDrawable*/,
+    GCPtr /*pGC*/,
+    int /*x1*/,
+    int /*y1*/,
+    int /*x2*/,
+    int /*y2*/,
+    BoxPtr /*boxp*/,
+    Bool /*shorten*/
+#endif
+);
+/* cfb8lineCP.c */
+
+extern int cfb8LineSS1RectPreviousCopy(
+#if NeedFunctionPrototypes
+    DrawablePtr /*pDrawable*/,
+    GCPtr /*pGC*/,
+    int /*mode*/,
+    int /*npt*/,
+    DDXPointPtr /*pptInit*/,
+    DDXPointPtr /*pptInitOrig*/,
+    int * /*x1p*/,
+    int * /*y1p*/,
+    int * /*x2p*/,
+    int * /*y2p*/
+
+#endif
+);
+/* cfb8lineG.c */
+
+extern int cfb8LineSS1RectGeneral(
+#if NeedFunctionPrototypes
+    DrawablePtr /*pDrawable*/,
+    GCPtr /*pGC*/,
+    int /*mode*/,
+    int /*npt*/,
+    DDXPointPtr /*pptInit*/,
+    DDXPointPtr /*pptInitOrig*/,
+    int * /*x1p*/,
+    int * /*y1p*/,
+    int * /*x2p*/,
+    int * /*y2p*/
+#endif
+);
+
+extern void cfb8ClippedLineGeneral(
+#if NeedFunctionPrototypes
+    DrawablePtr /*pDrawable*/,
+    GCPtr /*pGC*/,
+    int /*x1*/,
+    int /*y1*/,
+    int /*x2*/,
+    int /*y2*/,
+    BoxPtr /*boxp*/,
+    Bool /*shorten*/
+#endif
+);
+/* cfb8lineX.c */
+
+extern int cfb8LineSS1RectXor(
+#if NeedFunctionPrototypes
+    DrawablePtr /*pDrawable*/,
+    GCPtr /*pGC*/,
+    int /*mode*/,
+    int /*npt*/,
+    DDXPointPtr /*pptInit*/,
+    DDXPointPtr /*pptInitOrig*/,
+    int * /*x1p*/,
+    int * /*y1p*/,
+    int * /*x2p*/,
+    int * /*y2p*/
+#endif
+);
+
+extern void cfb8ClippedLineXor(
+#if NeedFunctionPrototypes
+    DrawablePtr /*pDrawable*/,
+    GCPtr /*pGC*/,
+    int /*x1*/,
+    int /*y1*/,
+    int /*x2*/,
+    int /*y2*/,
+    BoxPtr /*boxp*/,
+    Bool /*shorten*/
+#endif
+);
+/* cfb8segC.c */
+
+extern int cfb8SegmentSS1RectCopy(
+#if NeedFunctionPrototypes
+    DrawablePtr /*pDrawable*/,
+    GCPtr /*pGC*/,
+    int /*nseg*/,
+    xSegment * /*pSegInit*/
+#endif
+);
+/* cfb8segCS.c */
+
+extern int cfb8SegmentSS1RectShiftCopy(
+#if NeedFunctionPrototypes
+    DrawablePtr /*pDrawable*/,
+    GCPtr /*pGC*/,
+    int /*nseg*/,
+    xSegment * /*pSegInit*/
+#endif
+);
+
+extern void cfb8SegmentSS1Rect(
+#if NeedFunctionPrototypes
+    DrawablePtr /*pDrawable*/,
+    GCPtr /*pGC*/,
+    int /*nseg*/,
+    xSegment * /*pSegInit*/
+#endif
+);
+/* cfb8segG.c */
+
+extern int cfb8SegmentSS1RectGeneral(
+#if NeedFunctionPrototypes
+    DrawablePtr /*pDrawable*/,
+    GCPtr /*pGC*/,
+    int /*nseg*/,
+    xSegment * /*pSegInit*/
+#endif
+);
+/* cfbsegX.c */
+
+extern int cfb8SegmentSS1RectXor(
+#if NeedFunctionPrototypes
+    DrawablePtr /*pDrawable*/,
+    GCPtr /*pGC*/,
+    int /*nseg*/,
+    xSegment * /*pSegInit*/
+#endif
+);
+/* cfballpriv.c */
+
+extern Bool cfbAllocatePrivates(
+#if NeedFunctionPrototypes
+    ScreenPtr /*pScreen*/,
+    int * /*window_index*/,
+    int * /*gc_index*/
+#endif
+);
+/* cfbbitblt.c */
+
+extern RegionPtr cfbBitBlt(
+#if NeedFunctionPrototypes
+    DrawablePtr /*pSrcDrawable*/,
+    DrawablePtr /*pDstDrawable*/,
+    GCPtr/*pGC*/,
+    int /*srcx*/,
+    int /*srcy*/,
+    int /*width*/,
+    int /*height*/,
+    int /*dstx*/,
+    int /*dsty*/,
+    void (* /*doBitBlt*/)(
+#if NeedNestedPrototypes
+       DrawablePtr /*pSrc*/,
+       DrawablePtr /*pDst*/,
+       int /*alu*/,
+       RegionPtr /*prgnDst*/,
+       DDXPointPtr /*pptSrc*/,
+       unsigned long /*planemask*/,
+       unsigned long /*bitPlane*/
+#endif
+       ),
+    unsigned long /*bitPlane*/
+#endif
+);
+
+extern void cfbDoBitblt(
+#if NeedFunctionPrototypes
+    DrawablePtr /*pSrc*/,
+    DrawablePtr /*pDst*/,
+    int /*alu*/,
+    RegionPtr /*prgnDst*/,
+    DDXPointPtr /*pptSrc*/,
+    unsigned long /*planemask*/
+#endif
+);
+
+extern RegionPtr cfbCopyArea(
+#if NeedFunctionPrototypes
+    DrawablePtr /*pSrcDrawable*/,
+    DrawablePtr /*pDstDrawable*/,
+    GCPtr/*pGC*/,
+    int /*srcx*/,
+    int /*srcy*/,
+    int /*width*/,
+    int /*height*/,
+    int /*dstx*/,
+    int /*dsty*/
+#endif
+);
+
+extern void cfbCopyPlane1to8(
+#if NeedFunctionPrototypes
+    DrawablePtr /*pSrcDrawable*/,
+    DrawablePtr /*pDstDrawable*/,
+    int /*rop*/,
+    RegionPtr /*prgnDst*/,
+    DDXPointPtr /*pptSrc*/,
+    unsigned long /*planemask*/,
+    unsigned long /*bitPlane*/
+#endif
+);
+
+extern RegionPtr cfbCopyPlane(
+#if NeedFunctionPrototypes
+    DrawablePtr /*pSrcDrawable*/,
+    DrawablePtr /*pDstDrawable*/,
+    GCPtr /*pGC*/,
+    int /*srcx*/,
+    int /*srcy*/,
+    int /*width*/,
+    int /*height*/,
+    int /*dstx*/,
+    int /*dsty*/,
+    unsigned long /*bitPlane*/
+#endif
+);
+/* cfbbltC.c */
+
+extern void cfbDoBitbltCopy(
+#if NeedFunctionPrototypes
+    DrawablePtr /*pSrc*/,
+    DrawablePtr /*pDst*/,
+    int /*alu*/,
+    RegionPtr /*prgnDst*/,
+    DDXPointPtr /*pptSrc*/,
+    unsigned long /*planemask*/
+#endif
+);
+/* cfbbltG.c */
+
+extern void cfbDoBitbltGeneral(
+#if NeedFunctionPrototypes
+    DrawablePtr /*pSrc*/,
+    DrawablePtr /*pDst*/,
+    int /*alu*/,
+    RegionPtr /*prgnDst*/,
+    DDXPointPtr /*pptSrc*/,
+    unsigned long /*planemask*/
+#endif
+);
+/* cfbbltO.c */
+
+extern void cfbDoBitbltOr(
+#if NeedFunctionPrototypes
+    DrawablePtr /*pSrc*/,
+    DrawablePtr /*pDst*/,
+    int /*alu*/,
+    RegionPtr /*prgnDst*/,
+    DDXPointPtr /*pptSrc*/,
+    unsigned long /*planemask*/
+#endif
+);
+/* cfbbltX.c */
+
+extern void cfbDoBitbltXor(
+#if NeedFunctionPrototypes
+    DrawablePtr /*pSrc*/,
+    DrawablePtr /*pDst*/,
+    int /*alu*/,
+    RegionPtr /*prgnDst*/,
+    DDXPointPtr /*pptSrc*/,
+    unsigned long /*planemask*/
+#endif
+);
+/* cfbbres.c */
+
+extern void cfbBresS(
+#if NeedFunctionPrototypes
+    int /*rop*/,
+    unsigned long /*and*/,
+    unsigned long /*xor*/,
+    unsigned long * /*addrl*/,
+    int /*nlwidth*/,
+    int /*signdx*/,
+    int /*signdy*/,
+    int /*axis*/,
+    int /*x1*/,
+    int /*y1*/,
+    int /*e*/,
+    int /*e1*/,
+    int /*e2*/,
+    int /*len*/
+#endif
+);
+/* cfbbresd.c */
+
+extern void cfbBresD(
+#if NeedFunctionPrototypes
+    cfbRRopPtr /*rrops*/,
+    int * /*pdashIndex*/,
+    unsigned char * /*pDash*/,
+    int /*numInDashList*/,
+    int * /*pdashOffset*/,
+    int /*isDoubleDash*/,
+    unsigned long * /*addrl*/,
+    int /*nlwidth*/,
+    int /*signdx*/,
+    int /*signdy*/,
+    int /*axis*/,
+    int /*x1*/,
+    int /*y1*/,
+    int /*e*/,
+    int /*e1*/,
+    int /*e2*/,
+    int /*len*/
+#endif
+);
+/* cfbbstore.c */
+
+extern void cfbSaveAreas(
+#if NeedFunctionPrototypes
+    PixmapPtr /*pPixmap*/,
+    RegionPtr /*prgnSave*/,
+    int /*xorg*/,
+    int /*yorg*/,
+    WindowPtr /*pWin*/
+#endif
+);
+
+extern void cfbRestoreAreas(
+#if NeedFunctionPrototypes
+    PixmapPtr /*pPixmap*/,
+    RegionPtr /*prgnRestore*/,
+    int /*xorg*/,
+    int /*yorg*/,
+    WindowPtr /*pWin*/
+#endif
+);
+/* cfbcmap.c */
+
+extern int cfbListInstalledColormaps(
+#if NeedFunctionPrototypes
+    ScreenPtr  /*pScreen*/,
+    Colormap   * /*pmaps*/
+#endif
+);
+
+extern void cfbInstallColormap(
+#if NeedFunctionPrototypes
+    ColormapPtr        /*pmap*/
+#endif
+);
+
+extern void cfbUninstallColormap(
+#if NeedFunctionPrototypes
+    ColormapPtr        /*pmap*/
+#endif
+);
+
+extern void cfbResolveColor(
+#if NeedFunctionPrototypes
+    unsigned short * /*pred*/,
+    unsigned short * /*pgreen*/,
+    unsigned short * /*pblue*/,
+    VisualPtr /*pVisual*/
+#endif
+);
+
+extern Bool cfbInitializeColormap(
+#if NeedFunctionPrototypes
+    ColormapPtr /*pmap*/
+#endif
+);
+
+extern int cfbExpandDirectColors(
+#if NeedFunctionPrototypes
+    ColormapPtr /*pmap*/,
+    int /*ndef*/,
+    xColorItem * /*indefs*/,
+    xColorItem * /*outdefs*/
+#endif
+);
+
+extern Bool cfbCreateDefColormap(
+#if NeedFunctionPrototypes
+    ScreenPtr /*pScreen*/
+#endif
+);
+
+extern Bool cfbSetVisualTypes(
+#if NeedFunctionPrototypes
+    int /*depth*/,
+    int /*visuals*/,
+    int /*bitsPerRGB*/
+#endif
+);
+
+extern Bool cfbInitVisuals(
+#if NeedFunctionPrototypes
+    VisualPtr * /*visualp*/,
+    DepthPtr * /*depthp*/,
+    int * /*nvisualp*/,
+    int * /*ndepthp*/,
+    int * /*rootDepthp*/,
+    VisualID * /*defaultVisp*/,
+    unsigned long /*sizes*/,
+    int /*bitsPerRGB*/
+#endif
+);
+/* cfbfillarcC.c */
+
+extern void cfbPolyFillArcSolidCopy(
+#if NeedFunctionPrototypes
+    DrawablePtr /*pDraw*/,
+    GCPtr /*pGC*/,
+    int /*narcs*/,
+    xArc * /*parcs*/
+#endif
+);
+/* cfbfillarcG.c */
+
+extern void cfbPolyFillArcSolidGeneral(
+#if NeedFunctionPrototypes
+    DrawablePtr /*pDraw*/,
+    GCPtr /*pGC*/,
+    int /*narcs*/,
+    xArc * /*parcs*/
+#endif
+);
+/* cfbfillrct.c */
+
+extern void cfbFillBoxTileOdd(
+#if NeedFunctionPrototypes
+    DrawablePtr /*pDrawable*/,
+    int /*n*/,
+    BoxPtr /*rects*/,
+    PixmapPtr /*tile*/,
+    int /*xrot*/,
+    int /*yrot*/
+#endif
+);
+
+extern void cfbFillRectTileOdd(
+#if NeedFunctionPrototypes
+    DrawablePtr /*pDrawable*/,
+    GCPtr /*pGC*/,
+    int /*nBox*/,
+    BoxPtr /*pBox*/
+#endif
+);
+
+extern void cfbPolyFillRect(
+#if NeedFunctionPrototypes
+    DrawablePtr /*pDrawable*/,
+    GCPtr /*pGC*/,
+    int /*nrectFill*/,
+    xRectangle * /*prectInit*/
+#endif
+);
+/* cfbfillsp.c */
+
+extern void cfbUnnaturalTileFS(
+#if NeedFunctionPrototypes
+    DrawablePtr /*pDrawable*/,
+    GCPtr/*pGC*/,
+    int /*nInit*/,
+    DDXPointPtr /*pptInit*/,
+    int * /*pwidthInit*/,
+    int /*fSorted*/
+#endif
+);
+
+extern void cfbUnnaturalStippleFS(
+#if NeedFunctionPrototypes
+    DrawablePtr /*pDrawable*/,
+    GCPtr/*pGC*/,
+    int /*nInit*/,
+    DDXPointPtr /*pptInit*/,
+    int * /*pwidthInit*/,
+    int /*fSorted*/
+#endif
+);
+
+extern void cfb8Stipple32FS(
+#if NeedFunctionPrototypes
+    DrawablePtr /*pDrawable*/,
+    GCPtr /*pGC*/,
+    int /*nInit*/,
+    DDXPointPtr /*pptInit*/,
+    int * /*pwidthInit*/,
+    int /*fSorted*/
+#endif
+);
+
+extern void cfb8OpaqueStipple32FS(
+#if NeedFunctionPrototypes
+    DrawablePtr /*pDrawable*/,
+    GCPtr /*pGC*/,
+    int /*nInit*/,
+    DDXPointPtr /*pptInit*/,
+    int * /*pwidthInit*/,
+    int /*fSorted*/
+#endif
+);
+/* cfbgc.c */
+
+extern GCOpsPtr cfbMatchCommon(
+#if NeedFunctionPrototypes
+    GCPtr /*pGC*/,
+    cfbPrivGCPtr /*devPriv*/
+#endif
+);
+
+extern Bool cfbCreateGC(
+#if NeedFunctionPrototypes
+    GCPtr /*pGC*/
+#endif
+);
+
+extern void cfbValidateGC(
+#if NeedFunctionPrototypes
+    GCPtr /*pGC*/,
+    unsigned long /*changes*/,
+    DrawablePtr /*pDrawable*/
+#endif
+);
+
+/* cfbgetsp.c */
+
+extern void cfbGetSpans(
+#if NeedFunctionPrototypes
+    DrawablePtr /*pDrawable*/,
+    int /*wMax*/,
+    DDXPointPtr /*ppt*/,
+    int * /*pwidth*/,
+    int /*nspans*/,
+    char * /*pdstStart*/
+#endif
+);
+/* cfbglblt8.c */
+
+extern void cfbPolyGlyphBlt8(
+#if NeedFunctionPrototypes
+    DrawablePtr /*pDrawable*/,
+    GCPtr /*pGC*/,
+    int /*x*/,
+    int /*y*/,
+    unsigned int /*nglyph*/,
+    CharInfoPtr * /*ppci*/,
+    pointer /*pglyphBase*/
+#endif
+);
+/* cfbglrop8.c */
+
+extern void cfbPolyGlyphRop8(
+#if NeedFunctionPrototypes
+    DrawablePtr /*pDrawable*/,
+    GCPtr /*pGC*/,
+    int /*x*/,
+    int /*y*/,
+    unsigned int /*nglyph*/,
+    CharInfoPtr * /*ppci*/,
+    pointer /*pglyphBase*/
+#endif
+);
+/* cfbhrzvert.c */
+
+extern int cfbHorzS(
+#if NeedFunctionPrototypes
+    int /*rop*/,
+    unsigned long /*and*/,
+    unsigned long /*xor*/,
+    unsigned long * /*addrl*/,
+    int /*nlwidth*/,
+    int /*x1*/,
+    int /*y1*/,
+    int /*len*/
+#endif
+);
+
+extern void cfbVertS(
+#if NeedFunctionPrototypes
+    int /*rop*/,
+    unsigned long /*and*/,
+    unsigned long /*xor*/,
+    unsigned long * /*addrl*/,
+    int /*nlwidth*/,
+    int /*x1*/,
+    int /*y1*/,
+    int /*len*/
+#endif
+);
+/* cfbigblt8.c */
+
+extern void cfbImageGlyphBlt8(
+#if NeedFunctionPrototypes
+    DrawablePtr /*pDrawable*/,
+    GCPtr /*pGC*/,
+    int /*x*/,
+    int /*y*/,
+    unsigned int /*nglyph*/,
+    CharInfoPtr * /*ppci*/,
+    pointer /*pglyphBase*/
+#endif
+);
+/* cfbimage.c */
+
+extern void cfbPutImage(
+#if NeedFunctionPrototypes
+    DrawablePtr /*pDraw*/,
+    GCPtr /*pGC*/,
+    int /*depth*/,
+    int /*x*/,
+    int /*y*/,
+    int /*w*/,
+    int /*h*/,
+    int /*leftPad*/,
+    int /*format*/,
+    char * /*pImage*/
+#endif
+);
+
+extern void cfbGetImage(
+#if NeedFunctionPrototypes
+    DrawablePtr /*pDrawable*/,
+    int /*sx*/,
+    int /*sy*/,
+    int /*w*/,
+    int /*h*/,
+    unsigned int /*format*/,
+    unsigned long /*planeMask*/,
+    char * /*pdstLine*/
+#endif
+);
+/* cfbline.c */
+
+extern void cfbLineSS(
+#if NeedFunctionPrototypes
+    DrawablePtr /*pDrawable*/,
+    GCPtr /*pGC*/,
+    int /*mode*/,
+    int /*npt*/,
+    DDXPointPtr /*pptInit*/
+#endif
+);
+
+extern void cfbLineSD(
+#if NeedFunctionPrototypes
+    DrawablePtr /*pDrawable*/,
+    GCPtr /*pGC*/,
+    int /*mode*/,
+    int /*npt*/,
+    DDXPointPtr /*pptInit*/
+#endif
+);
+/* cfbmskbits.c */
+/* cfbpixmap.c */
+
+extern PixmapPtr cfbCreatePixmap(
+#if NeedFunctionPrototypes
+    ScreenPtr /*pScreen*/,
+    int /*width*/,
+    int /*height*/,
+    int /*depth*/
+#endif
+);
+
+extern Bool cfbDestroyPixmap(
+#if NeedFunctionPrototypes
+    PixmapPtr /*pPixmap*/
+#endif
+);
+
+extern PixmapPtr cfbCopyPixmap(
+#if NeedFunctionPrototypes
+    PixmapPtr /*pSrc*/
+#endif
+);
+
+extern void cfbPadPixmap(
+#if NeedFunctionPrototypes
+    PixmapPtr /*pPixmap*/
+#endif
+);
+
+extern void cfbXRotatePixmap(
+#if NeedFunctionPrototypes
+    PixmapPtr /*pPix*/,
+    int /*rw*/
+#endif
+);
+
+extern void cfbYRotatePixmap(
+#if NeedFunctionPrototypes
+    PixmapPtr /*pPix*/,
+    int /*rh*/
+#endif
+);
+
+extern void cfbCopyRotatePixmap(
+#if NeedFunctionPrototypes
+    PixmapPtr /*psrcPix*/,
+    PixmapPtr * /*ppdstPix*/,
+    int /*xrot*/,
+    int /*yrot*/
+#endif
+);
+/* cfbply1rctC.c */
+
+extern void cfbFillPoly1RectCopy(
+#if NeedFunctionPrototypes
+    DrawablePtr /*pDrawable*/,
+    GCPtr /*pGC*/,
+    int /*shape*/,
+    int /*mode*/,
+    int /*count*/,
+    DDXPointPtr /*ptsIn*/
+#endif
+);
+/* cfbply1rctG.c */
+
+extern void cfbFillPoly1RectGeneral(
+#if NeedFunctionPrototypes
+    DrawablePtr /*pDrawable*/,
+    GCPtr /*pGC*/,
+    int /*shape*/,
+    int /*mode*/,
+    int /*count*/,
+    DDXPointPtr /*ptsIn*/
+#endif
+);
+/* cfbpntwin.c */
+
+extern void cfbPaintWindow(
+#if NeedFunctionPrototypes
+    WindowPtr /*pWin*/,
+    RegionPtr /*pRegion*/,
+    int /*what*/
+#endif
+);
+
+extern void cfbFillBoxSolid(
+#if NeedFunctionPrototypes
+    DrawablePtr /*pDrawable*/,
+    int /*nBox*/,
+    BoxPtr /*pBox*/,
+    unsigned long /*pixel*/
+#endif
+);
+
+extern void cfbFillBoxTile32(
+#if NeedFunctionPrototypes
+    DrawablePtr /*pDrawable*/,
+    int /*nBox*/,
+    BoxPtr /*pBox*/,
+    PixmapPtr /*tile*/
+#endif
+);
+/* cfbpolypnt.c */
+
+extern void cfbPolyPoint(
+#if NeedFunctionPrototypes
+    DrawablePtr /*pDrawable*/,
+    GCPtr /*pGC*/,
+    int /*mode*/,
+    int /*npt*/,
+    xPoint * /*pptInit*/
+#endif
+);
+/* cfbpush8.c */
+
+extern void cfbPushPixels8(
+#if NeedFunctionPrototypes
+    GCPtr /*pGC*/,
+    PixmapPtr /*pBitmap*/,
+    DrawablePtr /*pDrawable*/,
+    int /*dx*/,
+    int /*dy*/,
+    int /*xOrg*/,
+    int /*yOrg*/
+#endif
+);
+/* cfbrctstp8.c */
+
+extern void cfb8FillRectOpaqueStippled32(
+#if NeedFunctionPrototypes
+    DrawablePtr /*pDrawable*/,
+    GCPtr /*pGC*/,
+    int /*nBox*/,
+    BoxPtr /*pBox*/
+#endif
+);
+
+extern void cfb8FillRectTransparentStippled32(
+#if NeedFunctionPrototypes
+    DrawablePtr /*pDrawable*/,
+    GCPtr /*pGC*/,
+    int /*nBox*/,
+    BoxPtr /*pBox*/
+#endif
+);
+
+extern void cfb8FillRectStippledUnnatural(
+#if NeedFunctionPrototypes
+    DrawablePtr /*pDrawable*/,
+    GCPtr /*pGC*/,
+    int /*nBox*/,
+    BoxPtr /*pBox*/
+#endif
+);
+/* cfbrrop.c */
+
+extern int cfbReduceRasterOp(
+#if NeedFunctionPrototypes
+    int /*rop*/,
+    unsigned long /*fg*/,
+    unsigned long /*pm*/,
+    unsigned long * /*andp*/,
+    unsigned long * /*xorp*/
+#endif
+);
+/* cfbscrinit.c */
+
+extern Bool cfbCloseScreen(
+#if NeedFunctionPrototypes
+    int /*index*/,
+    ScreenPtr /*pScreen*/
+#endif
+);
+
+extern Bool cfbSetupScreen(
+#if NeedFunctionPrototypes
+    ScreenPtr /*pScreen*/,
+    pointer /*pbits*/,
+    int /*xsize*/,
+    int /*ysize*/,
+    int /*dpix*/,
+    int /*dpiy*/,
+    int /*width*/
+#endif
+);
+
+extern int cfbFinishScreenInit(
+#if NeedFunctionPrototypes
+    ScreenPtr /*pScreen*/,
+    pointer /*pbits*/,
+    int /*xsize*/,
+    int /*ysize*/,
+    int /*dpix*/,
+    int /*dpiy*/,
+    int /*width*/
+#endif
+);
+
+extern Bool cfbScreenInit(
+#if NeedFunctionPrototypes
+    ScreenPtr /*pScreen*/,
+    pointer /*pbits*/,
+    int /*xsize*/,
+    int /*ysize*/,
+    int /*dpix*/,
+    int /*dpiy*/,
+    int /*width*/
+#endif
+);
+/* cfbseg.c */
+
+extern void cfbSegmentSS(
+#if NeedFunctionPrototypes
+    DrawablePtr /*pDrawable*/,
+    GCPtr /*pGC*/,
+    int /*nseg*/,
+    xSegment * /*pSeg*/
+#endif
+);
+
+extern void cfbSegmentSD(
+#if NeedFunctionPrototypes
+    DrawablePtr /*pDrawable*/,
+    GCPtr /*pGC*/,
+    int /*nseg*/,
+    xSegment * /*pSeg*/
+#endif
+);
+/* cfbsetsp.c */
+
+extern int cfbSetScanline(
+#if NeedFunctionPrototypes
+    int /*y*/,
+    int /*xOrigin*/,
+    int /*xStart*/,
+    int /*xEnd*/,
+    unsigned int * /*psrc*/,
+    int /*alu*/,
+    int * /*pdstBase*/,
+    int /*widthDst*/,
+    unsigned long /*planemask*/
+#endif
+);
+
+extern void cfbSetSpans(
+#if NeedFunctionPrototypes
+    DrawablePtr /*pDrawable*/,
+    GCPtr /*pGC*/,
+    char * /*psrc*/,
+    DDXPointPtr /*ppt*/,
+    int * /*pwidth*/,
+    int /*nspans*/,
+    int /*fSorted*/
+#endif
+);
+/* cfbsolidC.c */
+
+extern void cfbFillRectSolidCopy(
+#if NeedFunctionPrototypes
+    DrawablePtr /*pDrawable*/,
+    GCPtr /*pGC*/,
+    int /*nBox*/,
+    BoxPtr /*pBox*/
+#endif
+);
+
+extern void cfbSolidSpansCopy(
+#if NeedFunctionPrototypes
+    DrawablePtr /*pDrawable*/,
+    GCPtr /*pGC*/,
+    int /*nInit*/,
+    DDXPointPtr /*pptInit*/,
+    int * /*pwidthInit*/,
+    int /*fSorted*/
+#endif
+);
+/* cfbsolidG.c */
+
+extern void cfbFillRectSolidGeneral(
+#if NeedFunctionPrototypes
+    DrawablePtr /*pDrawable*/,
+    GCPtr /*pGC*/,
+    int /*nBox*/,
+    BoxPtr /*pBox*/
+#endif
+);
+
+extern void cfbSolidSpansGeneral(
+#if NeedFunctionPrototypes
+    DrawablePtr /*pDrawable*/,
+    GCPtr /*pGC*/,
+    int /*nInit*/,
+    DDXPointPtr /*pptInit*/,
+    int * /*pwidthInit*/,
+    int /*fSorted*/
+#endif
+);
+/* cfbsolidX.c */
+
+extern void cfbFillRectSolidXor(
+#if NeedFunctionPrototypes
+    DrawablePtr /*pDrawable*/,
+    GCPtr /*pGC*/,
+    int /*nBox*/,
+    BoxPtr /*pBox*/
+#endif
+);
+
+extern void cfbSolidSpansXor(
+#if NeedFunctionPrototypes
+    DrawablePtr /*pDrawable*/,
+    GCPtr /*pGC*/,
+    int /*nInit*/,
+    DDXPointPtr /*pptInit*/,
+    int * /*pwidthInit*/,
+    int /*fSorted*/
+#endif
+);
+/* cfbteblt8.c */
+
+extern void cfbTEGlyphBlt8(
+#if NeedFunctionPrototypes
+    DrawablePtr /*pDrawable*/,
+    GCPtr/*pGC*/,
+    int /*xInit*/,
+    int /*yInit*/,
+    unsigned int /*nglyph*/,
+    CharInfoPtr * /*ppci*/,
+    pointer /*pglyphBase*/
+#endif
+);
+/* cfbtegblt.c */
+
+extern void cfbTEGlyphBlt(
+#if NeedFunctionPrototypes
+    DrawablePtr /*pDrawable*/,
+    GCPtr/*pGC*/,
+    int /*x*/,
+    int /*y*/,
+    unsigned int /*nglyph*/,
+    CharInfoPtr * /*ppci*/,
+    pointer /*pglyphBase*/
+#endif
+);
+/* cfbtile32C.c */
+
+extern void cfbFillRectTile32Copy(
+#if NeedFunctionPrototypes
+    DrawablePtr /*pDrawable*/,
+    GCPtr /*pGC*/,
+    int /*nBox*/,
+    BoxPtr /*pBox*/
+#endif
+);
+
+extern void cfbTile32FSCopy(
+#if NeedFunctionPrototypes
+    DrawablePtr /*pDrawable*/,
+    GCPtr /*pGC*/,
+    int /*nInit*/,
+    DDXPointPtr /*pptInit*/,
+    int * /*pwidthInit*/,
+    int /*fSorted*/
+#endif
+);
+/* cfbtile32G.c */
+
+extern void cfbFillRectTile32General(
+#if NeedFunctionPrototypes
+    DrawablePtr /*pDrawable*/,
+    GCPtr /*pGC*/,
+    int /*nBox*/,
+    BoxPtr /*pBox*/
+#endif
+);
+
+extern void cfbTile32FSGeneral(
+#if NeedFunctionPrototypes
+    DrawablePtr /*pDrawable*/,
+    GCPtr /*pGC*/,
+    int /*nInit*/,
+    DDXPointPtr /*pptInit*/,
+    int * /*pwidthInit*/,
+    int /*fSorted*/
+#endif
+);
+/* cfbtileoddC.c */
+
+extern void cfbFillBoxTileOddCopy(
+#if NeedFunctionPrototypes
+    DrawablePtr /*pDrawable*/,
+    int /*nBox*/,
+    BoxPtr /*pBox*/,
+    PixmapPtr /*tile*/,
+    int /*xrot*/,
+    int /*yrot*/,
+    int /*alu*/,
+    unsigned long /*planemask*/
+#endif
+);
+
+extern void cfbFillSpanTileOddCopy(
+#if NeedFunctionPrototypes
+    DrawablePtr /*pDrawable*/,
+    int /*n*/,
+    DDXPointPtr /*ppt*/,
+    int * /*pwidth*/,
+    PixmapPtr /*tile*/,
+    int /*xrot*/,
+    int /*yrot*/,
+    int /*alu*/,
+    unsigned long /*planemask*/
+#endif
+);
+
+extern void cfbFillBoxTile32sCopy(
+#if NeedFunctionPrototypes
+    DrawablePtr /*pDrawable*/,
+    int /*nBox*/,
+    BoxPtr /*pBox*/,
+    PixmapPtr /*tile*/,
+    int /*xrot*/,
+    int /*yrot*/,
+    int /*alu*/,
+    unsigned long /*planemask*/
+#endif
+);
+
+extern void cfbFillSpanTile32sCopy(
+#if NeedFunctionPrototypes
+    DrawablePtr /*pDrawable*/,
+    int /*n*/,
+    DDXPointPtr /*ppt*/,
+    int * /*pwidth*/,
+    PixmapPtr /*tile*/,
+    int /*xrot*/,
+    int /*yrot*/,
+    int /*alu*/,
+    unsigned long /*planemask*/
+#endif
+);
+/* cfbtileoddG.c */
+
+extern void cfbFillBoxTileOddGeneral(
+#if NeedFunctionPrototypes
+    DrawablePtr /*pDrawable*/,
+    int /*nBox*/,
+    BoxPtr /*pBox*/,
+    PixmapPtr /*tile*/,
+    int /*xrot*/,
+    int /*yrot*/,
+    int /*alu*/,
+    unsigned long /*planemask*/
+#endif
+);
+
+extern void cfbFillSpanTileOddGeneral(
+#if NeedFunctionPrototypes
+    DrawablePtr /*pDrawable*/,
+    int /*n*/,
+    DDXPointPtr /*ppt*/,
+    int * /*pwidth*/,
+    PixmapPtr /*tile*/,
+    int /*xrot*/,
+    int /*yrot*/,
+    int /*alu*/,
+    unsigned long /*planemask*/
+#endif
+);
+
+extern void cfbFillBoxTile32sGeneral(
+#if NeedFunctionPrototypes
+    DrawablePtr /*pDrawable*/,
+    int /*nBox*/,
+    BoxPtr /*pBox*/,
+    PixmapPtr /*tile*/,
+    int /*xrot*/,
+    int /*yrot*/,
+    int /*alu*/,
+    unsigned long /*planemask*/
+#endif
+);
+
+extern void cfbFillSpanTile32sGeneral(
+#if NeedFunctionPrototypes
+    DrawablePtr /*pDrawable*/,
+    int /*n*/,
+    DDXPointPtr /*ppt*/,
+    int * /*pwidth*/,
+    PixmapPtr /*tile*/,
+    int /*xrot*/,
+    int /*yrot*/,
+    int /*alu*/,
+    unsigned long /*planemask*/
+#endif
+);
+/* cfbwindow.c */
+
+extern Bool cfbCreateWindow(
+#if NeedFunctionPrototypes
+    WindowPtr /*pWin*/
+#endif
+);
+
+extern Bool cfbDestroyWindow(
+#if NeedFunctionPrototypes
+    WindowPtr /*pWin*/
+#endif
+);
+
+extern Bool cfbMapWindow(
+#if NeedFunctionPrototypes
+    WindowPtr /*pWindow*/
+#endif
+);
+
+extern Bool cfbPositionWindow(
+#if NeedFunctionPrototypes
+    WindowPtr /*pWin*/,
+    int /*x*/,
+    int /*y*/
+#endif
+);
+
+extern Bool cfbUnmapWindow(
+#if NeedFunctionPrototypes
+    WindowPtr /*pWindow*/
+#endif
+);
+
+extern void cfbCopyWindow(
+#if NeedFunctionPrototypes
+    WindowPtr /*pWin*/,
+    DDXPointRec /*ptOldOrg*/,
+    RegionPtr /*prgnSrc*/
+#endif
+);
+
+extern Bool cfbChangeWindowAttributes(
+#if NeedFunctionPrototypes
+    WindowPtr /*pWin*/,
+    unsigned long /*mask*/
+#endif
+);
+/* cfbzerarcC.c */
+
+extern void cfbZeroPolyArcSS8Copy(
+#if NeedFunctionPrototypes
+    DrawablePtr /*pDraw*/,
+    GCPtr /*pGC*/,
+    int /*narcs*/,
+    xArc * /*parcs*/
+#endif
+);
+/* cfbzerarcG.c */
+
+extern void cfbZeroPolyArcSS8General(
+#if NeedFunctionPrototypes
+    DrawablePtr /*pDraw*/,
+    GCPtr /*pGC*/,
+    int /*narcs*/,
+    xArc * /*parcs*/
+#endif
+);
+/* cfbzerarcX.c */
+
+extern void cfbZeroPolyArcSS8Xor(
+#if NeedFunctionPrototypes
+    DrawablePtr /*pDraw*/,
+    GCPtr /*pGC*/,
+    int /*narcs*/,
+    xArc * /*parcs*/
+#endif
+);
+
+/*
+ * This is the only completely portable way to
+ * compute this info
+ */
+
+#define BitsPerPixel(d) (\
+    PixmapWidthPaddingInfo[d].notPower2 ? \
+    (PixmapWidthPaddingInfo[d].bytesPerPixel * 8) : \
+    ((1 << PixmapWidthPaddingInfo[d].padBytesLog2) * 8 / \
+    (PixmapWidthPaddingInfo[d].padRoundUp+1)))
+
+/* Common macros for extracting drawing information */
+
+#if !defined(SINGLEDEPTH) && PSZ != 8 || defined(FORCE_SEPARATE_PRIVATE)
+
+#define CFB_NEED_SCREEN_PRIVATE
+
+extern int cfbScreenPrivateIndex;
+#define cfbGetScreenPixmap(s)  ((PixmapPtr) (s)->devPrivates[cfbScreenPrivateIndex].ptr)
+#else
+#define cfbGetScreenPixmap(s)  ((PixmapPtr) (s)->devPrivate)
+#endif
+
+#ifdef PIXMAP_PER_WINDOW
+#define cfbGetWindowPixmap(d)  ((PixmapPtr) ((WindowPtr) d)->devPrivates[frameWindowPrivateIndex].ptr)
+#else
+#define cfbGetWindowPixmap(d) cfbGetScreenPixmap((d)->pScreen)
+#endif
+
+#define cfbGetTypedWidth(pDrawable,wtype) (\
+    (((pDrawable)->type != DRAWABLE_PIXMAP) ? \
+     (int) (cfbGetWindowPixmap(pDrawable)->devKind) : \
+     (int)(((PixmapPtr)pDrawable)->devKind)) / sizeof (wtype))
+
+#define cfbGetByteWidth(pDrawable) cfbGetTypedWidth(pDrawable, unsigned char)
+
+#define cfbGetPixelWidth(pDrawable) cfbGetTypedWidth(pDrawable, PixelType)
+
+#define cfbGetLongWidth(pDrawable) cfbGetTypedWidth(pDrawable, unsigned long)
+    
+#define cfbGetTypedWidthAndPointer(pDrawable, width, pointer, wtype, ptype) {\
+    PixmapPtr   _pPix; \
+    if ((pDrawable)->type != DRAWABLE_PIXMAP) \
+       _pPix = cfbGetWindowPixmap(pDrawable); \
+    else \
+       _pPix = (PixmapPtr) (pDrawable); \
+    (pointer) = (ptype *) _pPix->devPrivate.ptr; \
+    (width) = ((int) _pPix->devKind) / sizeof (wtype); \
+}
+
+#define cfbGetByteWidthAndPointer(pDrawable, width, pointer) \
+    cfbGetTypedWidthAndPointer(pDrawable, width, pointer, unsigned char, unsigned char)
+
+#define cfbGetLongWidthAndPointer(pDrawable, width, pointer) \
+    cfbGetTypedWidthAndPointer(pDrawable, width, pointer, unsigned long, unsigned long)
+
+#define cfbGetPixelWidthAndPointer(pDrawable, width, pointer) \
+    cfbGetTypedWidthAndPointer(pDrawable, width, pointer, PixelType, PixelType)
+
+#define cfbGetWindowTypedWidthAndPointer(pWin, width, pointer, wtype, ptype) {\
+    PixmapPtr  _pPix = cfbGetWindowPixmap((DrawablePtr) (pWin)); \
+    (pointer) = (ptype *) _pPix->devPrivate.ptr; \
+    (width) = ((int) _pPix->devKind) / sizeof (wtype); \
+}
+
+#define cfbGetWindowLongWidthAndPointer(pWin, width, pointer) \
+    cfbGetWindowTypedWidthAndPointer(pWin, width, pointer, unsigned long, unsigned long)
+
+#define cfbGetWindowByteWidthAndPointer(pWin, width, pointer) \
+    cfbGetWindowTypedWidthAndPointer(pWin, width, pointer, unsigned char, unsigned char)
+
+#define cfbGetWindowPixelWidthAndPointer(pDrawable, width, pointer) \
+    cfbGetWindowTypedWidthAndPointer(pDrawable, width, pointer, PixelType, PixelType)
+
+/* Macros which handle a coordinate in a single register */
+
+/* Most compilers will convert divide by 65536 into a shift, if signed
+ * shifts exist.  If your machine does arithmetic shifts and your compiler
+ * can't get it right, add to this line.
+ */
+
+/* mips compiler - what a joke - it CSEs the 65536 constant into a reg
+ * forcing as to use div instead of shift.  Let's be explicit.
+ */
+
+#if defined(mips) || defined(sparc) || defined(__alpha) || defined(__alpha__) || defined(__i386__) || defined(i386)
+#define GetHighWord(x) (((int) (x)) >> 16)
+#else
+#define GetHighWord(x) (((int) (x)) / 65536)
+#endif
+
+#if IMAGE_BYTE_ORDER == MSBFirst
+#define intToCoord(i,x,y)   (((x) = GetHighWord(i)), ((y) = (int) ((short) (i))))
+#define coordToInt(x,y)        (((x) << 16) | (y))
+#define intToX(i)      (GetHighWord(i))
+#define intToY(i)      ((int) ((short) i))
+#else
+#define intToCoord(i,x,y)   (((x) = (int) ((short) (i))), ((y) = GetHighWord(i)))
+#define coordToInt(x,y)        (((y) << 16) | (x))
+#define intToX(i)      ((int) ((short) (i)))
+#define intToY(i)      (GetHighWord(i))
+#endif
diff --git a/Xserver/programs/Xserver/cfb/cfb8bit.c b/Xserver/programs/Xserver/cfb/cfb8bit.c
new file mode 100644 (file)
index 0000000..4772542
--- /dev/null
@@ -0,0 +1,468 @@
+/* $XConsortium: cfb8bit.c,v 1.13 94/09/29 20:33:11 dpw Exp $ */
+/*
+
+Copyright (c) 1989, 1994  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be included
+in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR
+OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall
+not be used in advertising or otherwise to promote the sale, use or
+other dealings in this Software without prior written authorization
+from the X Consortium.
+
+*/
+
+/*
+ * cfb8bit.c
+ *
+ * 8 bit color frame buffer utility routines
+ */
+
+
+#if PSZ == 8
+
+#include       "X.h"
+#include       "Xmd.h"
+#include       "Xproto.h"
+#include       "gcstruct.h"
+#include       "windowstr.h"
+#include       "scrnintstr.h"
+#include       "pixmapstr.h"
+#include       "regionstr.h"
+#include       "cfb.h"
+#include       "cfbmskbits.h"
+#include       "cfb8bit.h"
+
+PixelGroup cfb8StippleMasks[NUM_MASKS] = {
+#if NUM_MASKS == 16
+    0x00000000, 0x000000ff, 0x0000ff00, 0x0000ffff,
+    0x00ff0000, 0x00ff00ff, 0x00ffff00, 0x00ffffff,
+    0xff000000, 0xff0000ff, 0xff00ff00, 0xff00ffff,
+    0xffff0000, 0xffff00ff, 0xffffff00, 0xffffffff
+#else /* NUM_MASKS == 256 */
+    0x0000000000000000,        0x00000000000000ff,
+    0x000000000000ff00,        0x000000000000ffff,
+    0x0000000000ff0000,        0x0000000000ff00ff,
+    0x0000000000ffff00,        0x0000000000ffffff,
+    0x00000000ff000000,        0x00000000ff0000ff,
+    0x00000000ff00ff00,        0x00000000ff00ffff,
+    0x00000000ffff0000,        0x00000000ffff00ff,
+    0x00000000ffffff00,        0x00000000ffffffff,
+    0x000000ff00000000,        0x000000ff000000ff,
+    0x000000ff0000ff00,        0x000000ff0000ffff,
+    0x000000ff00ff0000,        0x000000ff00ff00ff,
+    0x000000ff00ffff00,        0x000000ff00ffffff,
+    0x000000ffff000000,        0x000000ffff0000ff,
+    0x000000ffff00ff00,        0x000000ffff00ffff,
+    0x000000ffffff0000,        0x000000ffffff00ff,
+    0x000000ffffffff00,        0x000000ffffffffff,
+    0x0000ff0000000000,        0x0000ff00000000ff,
+    0x0000ff000000ff00,        0x0000ff000000ffff,
+    0x0000ff0000ff0000,        0x0000ff0000ff00ff,
+    0x0000ff0000ffff00,        0x0000ff0000ffffff,
+    0x0000ff00ff000000,        0x0000ff00ff0000ff,
+    0x0000ff00ff00ff00,        0x0000ff00ff00ffff,
+    0x0000ff00ffff0000,        0x0000ff00ffff00ff,
+    0x0000ff00ffffff00,        0x0000ff00ffffffff,
+    0x0000ffff00000000,        0x0000ffff000000ff,
+    0x0000ffff0000ff00,        0x0000ffff0000ffff,
+    0x0000ffff00ff0000,        0x0000ffff00ff00ff,
+    0x0000ffff00ffff00,        0x0000ffff00ffffff,
+    0x0000ffffff000000,        0x0000ffffff0000ff,
+    0x0000ffffff00ff00,        0x0000ffffff00ffff,
+    0x0000ffffffff0000,        0x0000ffffffff00ff,
+    0x0000ffffffffff00,        0x0000ffffffffffff,
+    0x00ff000000000000,        0x00ff0000000000ff,
+    0x00ff00000000ff00,        0x00ff00000000ffff,
+    0x00ff000000ff0000,        0x00ff000000ff00ff,
+    0x00ff000000ffff00,        0x00ff000000ffffff,
+    0x00ff0000ff000000,        0x00ff0000ff0000ff,
+    0x00ff0000ff00ff00,        0x00ff0000ff00ffff,
+    0x00ff0000ffff0000,        0x00ff0000ffff00ff,
+    0x00ff0000ffffff00,        0x00ff0000ffffffff,
+    0x00ff00ff00000000,        0x00ff00ff000000ff,
+    0x00ff00ff0000ff00,        0x00ff00ff0000ffff,
+    0x00ff00ff00ff0000,        0x00ff00ff00ff00ff,
+    0x00ff00ff00ffff00,        0x00ff00ff00ffffff,
+    0x00ff00ffff000000,        0x00ff00ffff0000ff,
+    0x00ff00ffff00ff00,        0x00ff00ffff00ffff,
+    0x00ff00ffffff0000,        0x00ff00ffffff00ff,
+    0x00ff00ffffffff00,        0x00ff00ffffffffff,
+    0x00ffff0000000000,        0x00ffff00000000ff,
+    0x00ffff000000ff00,        0x00ffff000000ffff,
+    0x00ffff0000ff0000,        0x00ffff0000ff00ff,
+    0x00ffff0000ffff00,        0x00ffff0000ffffff,
+    0x00ffff00ff000000,        0x00ffff00ff0000ff,
+    0x00ffff00ff00ff00,        0x00ffff00ff00ffff,
+    0x00ffff00ffff0000,        0x00ffff00ffff00ff,
+    0x00ffff00ffffff00,        0x00ffff00ffffffff,
+    0x00ffffff00000000,        0x00ffffff000000ff,
+    0x00ffffff0000ff00,        0x00ffffff0000ffff,
+    0x00ffffff00ff0000,        0x00ffffff00ff00ff,
+    0x00ffffff00ffff00,        0x00ffffff00ffffff,
+    0x00ffffffff000000,        0x00ffffffff0000ff,
+    0x00ffffffff00ff00,        0x00ffffffff00ffff,
+    0x00ffffffffff0000,        0x00ffffffffff00ff,
+    0x00ffffffffffff00,        0x00ffffffffffffff,
+    0xff00000000000000,        0xff000000000000ff,
+    0xff0000000000ff00,        0xff0000000000ffff,
+    0xff00000000ff0000,        0xff00000000ff00ff,
+    0xff00000000ffff00,        0xff00000000ffffff,
+    0xff000000ff000000,        0xff000000ff0000ff,
+    0xff000000ff00ff00,        0xff000000ff00ffff,
+    0xff000000ffff0000,        0xff000000ffff00ff,
+    0xff000000ffffff00,        0xff000000ffffffff,
+    0xff0000ff00000000,        0xff0000ff000000ff,
+    0xff0000ff0000ff00,        0xff0000ff0000ffff,
+    0xff0000ff00ff0000,        0xff0000ff00ff00ff,
+    0xff0000ff00ffff00,        0xff0000ff00ffffff,
+    0xff0000ffff000000,        0xff0000ffff0000ff,
+    0xff0000ffff00ff00,        0xff0000ffff00ffff,
+    0xff0000ffffff0000,        0xff0000ffffff00ff,
+    0xff0000ffffffff00,        0xff0000ffffffffff,
+    0xff00ff0000000000,        0xff00ff00000000ff,
+    0xff00ff000000ff00,        0xff00ff000000ffff,
+    0xff00ff0000ff0000,        0xff00ff0000ff00ff,
+    0xff00ff0000ffff00,        0xff00ff0000ffffff,
+    0xff00ff00ff000000,        0xff00ff00ff0000ff,
+    0xff00ff00ff00ff00,        0xff00ff00ff00ffff,
+    0xff00ff00ffff0000,        0xff00ff00ffff00ff,
+    0xff00ff00ffffff00,        0xff00ff00ffffffff,
+    0xff00ffff00000000,        0xff00ffff000000ff,
+    0xff00ffff0000ff00,        0xff00ffff0000ffff,
+    0xff00ffff00ff0000,        0xff00ffff00ff00ff,
+    0xff00ffff00ffff00,        0xff00ffff00ffffff,
+    0xff00ffffff000000,        0xff00ffffff0000ff,
+    0xff00ffffff00ff00,        0xff00ffffff00ffff,
+    0xff00ffffffff0000,        0xff00ffffffff00ff,
+    0xff00ffffffffff00,        0xff00ffffffffffff,
+    0xffff000000000000,        0xffff0000000000ff,
+    0xffff00000000ff00,        0xffff00000000ffff,
+    0xffff000000ff0000,        0xffff000000ff00ff,
+    0xffff000000ffff00,        0xffff000000ffffff,
+    0xffff0000ff000000,        0xffff0000ff0000ff,
+    0xffff0000ff00ff00,        0xffff0000ff00ffff,
+    0xffff0000ffff0000,        0xffff0000ffff00ff,
+    0xffff0000ffffff00,        0xffff0000ffffffff,
+    0xffff00ff00000000,        0xffff00ff000000ff,
+    0xffff00ff0000ff00,        0xffff00ff0000ffff,
+    0xffff00ff00ff0000,        0xffff00ff00ff00ff,
+    0xffff00ff00ffff00,        0xffff00ff00ffffff,
+    0xffff00ffff000000,        0xffff00ffff0000ff,
+    0xffff00ffff00ff00,        0xffff00ffff00ffff,
+    0xffff00ffffff0000,        0xffff00ffffff00ff,
+    0xffff00ffffffff00,        0xffff00ffffffffff,
+    0xffffff0000000000,        0xffffff00000000ff,
+    0xffffff000000ff00,        0xffffff000000ffff,
+    0xffffff0000ff0000,        0xffffff0000ff00ff,
+    0xffffff0000ffff00,        0xffffff0000ffffff,
+    0xffffff00ff000000,        0xffffff00ff0000ff,
+    0xffffff00ff00ff00,        0xffffff00ff00ffff,
+    0xffffff00ffff0000,        0xffffff00ffff00ff,
+    0xffffff00ffffff00,        0xffffff00ffffffff,
+    0xffffffff00000000,        0xffffffff000000ff,
+    0xffffffff0000ff00,        0xffffffff0000ffff,
+    0xffffffff00ff0000,        0xffffffff00ff00ff,
+    0xffffffff00ffff00,        0xffffffff00ffffff,
+    0xffffffffff000000,        0xffffffffff0000ff,
+    0xffffffffff00ff00,        0xffffffffff00ffff,
+    0xffffffffffff0000,        0xffffffffffff00ff,
+    0xffffffffffffff00,        0xffffffffffffffff
+#endif
+};
+
+int    cfb8StippleMode, cfb8StippleAlu, cfb8StippleRRop;
+PixelGroup cfb8StippleFg, cfb8StippleBg, cfb8StipplePm;
+PixelGroup cfb8StippleAnd[NUM_MASKS], cfb8StippleXor[NUM_MASKS];
+
+int
+cfb8SetStipple (alu, fg, planemask)
+int            alu;
+unsigned long  fg, planemask;
+{
+    unsigned long   and, xor, rrop;
+    int        s;
+    unsigned long   c;
+
+    cfb8StippleMode = FillStippled;
+    cfb8StippleAlu = alu;
+    cfb8StippleFg = fg & PMSK;
+    cfb8StipplePm = planemask & PMSK;
+    rrop = cfbReduceRasterOp (alu, fg, planemask, &and, &xor);
+    cfb8StippleRRop = rrop;
+    /*
+     * create the appropriate pixel-fill bits for current
+     * foreground
+     */
+    for (s = 0; s < NUM_MASKS; s++)
+    {
+       c = cfb8StippleMasks[s];
+       cfb8StippleAnd[s] = and | ~c;
+       cfb8StippleXor[s] = xor & c;
+    }
+    return TRUE;
+}
+
+
+int
+cfb8SetOpaqueStipple (alu, fg, bg, planemask)
+int            alu;
+unsigned long  fg, bg, planemask;
+{
+    unsigned long   andfg, xorfg, andbg, xorbg, rropfg, rropbg;
+    int        s;
+    unsigned long   c;
+
+    cfb8StippleMode = FillOpaqueStippled;
+    cfb8StippleAlu = alu;
+    cfb8StippleFg = fg & PMSK;
+    cfb8StippleBg = bg & PMSK;
+    cfb8StipplePm = planemask & PMSK;
+    rropfg = cfbReduceRasterOp (alu, cfb8StippleFg, cfb8StipplePm, &andfg, &xorfg);
+    rropbg = cfbReduceRasterOp (alu, cfb8StippleBg, cfb8StipplePm, &andbg, &xorbg);
+    if (rropfg == rropbg)
+       cfb8StippleRRop = rropfg;
+    else
+       cfb8StippleRRop = GXset;
+    /*
+     * create the appropriate pixel-fill bits for current
+     * foreground
+     */
+    for (s = 0; s < NUM_MASKS; s++)
+    {
+       c = cfb8StippleMasks[s];
+       cfb8StippleAnd[s] = (andfg | ~c) & (andbg | c);
+       cfb8StippleXor[s] = (xorfg & c) | (xorbg & ~c);
+    }
+    return TRUE;
+}
+
+/*
+ * a grungy little routine.  This computes clip masks
+ * for partial character blts.  Returns rgnOUT if the
+ * entire character is clipped; returns rgnIN if the entire
+ * character is unclipped; returns rgnPART if a portion of
+ * the character is visible.  Computes clip masks for each
+ * longword of the character -- and those with the
+ * contents of the glyph to compute the visible bits.
+ */
+
+#if PGSZ == 32
+#if (BITMAP_BIT_ORDER == MSBFirst)
+PixelGroup cfb8BitLenMasks[PGSZ] = {
+    0xffffffff, 0x7fffffff, 0x3fffffff, 0x1fffffff,
+    0x0fffffff, 0x07ffffff, 0x03ffffff, 0x01ffffff,
+    0x00ffffff, 0x007fffff, 0x003fffff, 0x001fffff,
+    0x000fffff, 0x0007ffff, 0x0003ffff, 0x0001ffff,
+    0x0000ffff, 0x00007fff, 0x00003fff, 0x00001fff,
+    0x00000fff, 0x000007ff, 0x000003ff, 0x000001ff,
+    0x000000ff, 0x0000007f, 0x0000003f, 0x0000001f,
+    0x0000000f, 0x00000007, 0x00000003, 0x00000001,
+};
+#else
+PixelGroup cfb8BitLenMasks[PGSZ] = {
+    0xffffffff, 0xfffffffe, 0xfffffffc, 0xfffffff8,
+    0xfffffff0, 0xffffffe0, 0xffffffc0, 0xffffff80,
+    0xffffff00, 0xfffffe00, 0xfffffc00, 0xfffff800,
+    0xfffff000, 0xffffe000, 0xffffc000, 0xffff8000,
+    0xffff0000, 0xfffe0000, 0xfffc0000, 0xfff80000,
+    0xfff00000, 0xffe00000, 0xffc00000, 0xff800000,
+    0xff000000, 0xfe000000, 0xfc000000, 0xf8000000,
+    0xf0000000, 0xe0000000, 0xc0000000, 0x80000000,
+};
+#endif /* BITMAP_BIT_ORDER */
+#else /* PGSZ == 64 */
+#if (BITMAP_BIT_ORDER == MSBFirst)
+PixelGroup cfb8BitLenMasks[PGSZ] = {
+    0xffffffffffffffff,    0x7fffffffffffffff,
+    0x3fffffffffffffff,    0x1fffffffffffffff,
+    0x0fffffffffffffff,    0x07ffffffffffffff,
+    0x03ffffffffffffff,    0x01ffffffffffffff,
+    0x00ffffffffffffff,    0x007fffffffffffff,
+    0x003fffffffffffff,    0x001fffffffffffff,
+    0x000fffffffffffff,    0x0007ffffffffffff,
+    0x0003ffffffffffff,    0x0001ffffffffffff,
+    0x0000ffffffffffff,    0x00007fffffffffff,
+    0x00003fffffffffff,    0x00001fffffffffff,
+    0x00000fffffffffff,    0x000007ffffffffff,
+    0x000003ffffffffff,    0x000001ffffffffff,
+    0x000000ffffffffff,    0x0000007fffffffff,
+    0x0000003fffffffff,    0x0000001fffffffff,
+    0x0000000fffffffff,    0x00000007ffffffff,
+    0x00000003ffffffff,    0x00000001ffffffff,
+    0x00000000ffffffff,    0x000000007fffffff,
+    0x000000003fffffff,    0x000000001fffffff,
+    0x000000000fffffff,    0x0000000007ffffff,
+    0x0000000003ffffff,    0x0000000001ffffff,
+    0x0000000000ffffff,    0x00000000007fffff,
+    0x00000000003fffff,    0x00000000001fffff,
+    0x00000000000fffff,    0x000000000007ffff,
+    0x000000000003ffff,    0x000000000001ffff,
+    0x000000000000ffff,    0x0000000000007fff,
+    0x0000000000003fff,    0x0000000000001fff,
+    0x0000000000000fff,    0x00000000000007ff,
+    0x00000000000003ff,    0x00000000000001ff,
+    0x00000000000000ff,    0x000000000000007f,
+    0x000000000000003f,    0x000000000000001f,
+    0x000000000000000f,    0x0000000000000007,
+    0x0000000000000003,    0x0000000000000001
+};
+#else
+PixelGroup cfb8BitLenMasks[PGSZ] = {
+    0xffffffffffffffff,    0xfffffffffffffffe,
+    0xfffffffffffffffc,    0xfffffffffffffff8,
+    0xfffffffffffffff0,    0xffffffffffffffe0,
+    0xffffffffffffffc0,    0xffffffffffffff80,
+    0xffffffffffffff00,    0xfffffffffffffe00,
+    0xfffffffffffffc00,    0xfffffffffffff800,
+    0xfffffffffffff000,    0xffffffffffffe000,
+    0xffffffffffffc000,    0xffffffffffff8000,
+    0xffffffffffff0000,    0xfffffffffffe0000,
+    0xfffffffffffc0000,    0xfffffffffff80000,
+    0xfffffffffff00000,    0xffffffffffe00000,
+    0xffffffffffc00000,    0xffffffffff800000,
+    0xffffffffff000000,    0xfffffffffe000000,
+    0xfffffffffc000000,    0xfffffffff8000000,
+    0xfffffffff0000000,    0xffffffffe0000000,
+    0xffffffffc0000000,    0xffffffff80000000,
+    0xffffffff00000000,    0xfffffffe00000000,
+    0xfffffffc00000000,    0xfffffff800000000,
+    0xfffffff000000000,    0xffffffe000000000,
+    0xffffffc000000000,    0xffffff8000000000,
+    0xffffff0000000000,    0xfffffe0000000000,
+    0xfffffc0000000000,    0xfffff80000000000,
+    0xfffff00000000000,    0xffffe00000000000,
+    0xffffc00000000000,    0xffff800000000000,
+    0xffff000000000000,    0xfffe000000000000,
+    0xfffc000000000000,    0xfff8000000000000,
+    0xfff0000000000000,    0xffe0000000000000,
+    0xffc0000000000000,    0xff80000000000000,
+    0xff00000000000000,    0xfe00000000000000,
+    0xfc00000000000000,    0xf800000000000000,
+    0xf000000000000000,    0xe000000000000000,
+    0xc000000000000000,    0x8000000000000000
+};
+#endif /* BITMAP_BIT_ORDER */
+#endif /* PGSZ */
+
+
+
+int
+cfb8ComputeClipMasks32 (pBox, numRects, x, y, w, h, clips)
+    BoxPtr     pBox;
+    int                numRects;
+    int                x, y, w, h;
+    CARD32      *clips;
+{
+    int            yBand, yBandBot;
+    int            ch;
+    unsigned long          clip;
+    int            partIN = FALSE, partOUT = FALSE;
+    int            result;
+
+    if (numRects == 0)
+       return rgnOUT;
+    while (numRects && pBox->y2 <= y)
+    {
+       --numRects;
+       ++pBox;
+    }
+    if (!numRects || pBox->y1 >= y + h)
+       return rgnOUT;
+    yBand = pBox->y1;
+    while (numRects && pBox->y1 == yBand && pBox->x2 <= x)
+    {
+       --numRects;
+       ++pBox;
+    }
+    if (!numRects || pBox->y1 >= y + h)
+       return rgnOUT;
+    if (numRects &&
+       x >= pBox->x1 &&
+       x + w <= pBox->x2 &&
+       y >= pBox->y1 &&
+       y + h <= pBox->y2)
+    {
+       return rgnIN;
+    }
+    ch = 0;
+    while (numRects && pBox->y1 < y + h)
+    {
+       yBand = pBox->y1;
+       yBandBot = pBox->y2;
+       while (ch < h && y + ch < yBand)
+       {
+           partOUT = TRUE;
+           clips[ch++] = 0;
+       }
+       if (ch >= h)
+           break;
+       while (numRects && pBox->y1 == yBand && pBox->x2 <= x)
+       {
+           --numRects;
+           ++pBox;
+       }
+       if (!numRects)
+           break;
+       clip = 0;
+       while (numRects && pBox->y1 == yBand && pBox->x1 < x + w)
+       {
+           if (x < pBox->x1)
+               if (pBox->x2 < x + w)
+                   clip |= cfb8BitLenMasks[pBox->x1 - x] & ~cfb8BitLenMasks[pBox->x2 - x];
+               else
+                   clip |= cfb8BitLenMasks[pBox->x1 - x];
+           else
+               if (pBox->x2 < x + w)
+                   clip |= ~cfb8BitLenMasks[pBox->x2 - x];
+               else
+                   clip = ~0;
+           --numRects;
+           ++pBox;
+       }
+       if (clip != 0)
+               partIN = TRUE;
+       if (clip != ~0)
+               partOUT = TRUE;
+       while (ch < h && y + ch < yBandBot)
+           clips[ch++] = clip;
+       while (numRects && pBox->y1 == yBand)
+       {
+           --numRects;
+           ++pBox;
+       }
+    }
+    while (ch < h)
+    {
+       partOUT = TRUE;
+       clips[ch++] = 0;
+    }
+    result = rgnOUT;
+    if (partIN)
+    {
+       if (partOUT)
+           result = rgnPART;
+       else
+           result = rgnIN;
+    }
+    return result;
+}
+
+#endif /* PSZ == 8 */
diff --git a/Xserver/programs/Xserver/cfb/cfb8bit.h b/Xserver/programs/Xserver/cfb/cfb8bit.h
new file mode 100644 (file)
index 0000000..90686b2
--- /dev/null
@@ -0,0 +1,1577 @@
+/*
+ * cfb8bit.h
+ *
+ * Defines which are only useful to 8 bit color frame buffers
+ *
+ * That doesn't seem to be true any more.  Some of the macros in here 
+ * are used for depths other than 8.  Perhaps the file should be
+ * renamed.  dpw
+ */
+
+/*
+
+Copyright (c) 1989  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+*/
+
+/* $XConsortium: cfb8bit.h,v 1.18 95/04/07 18:59:27 kaleb Exp $ */
+/* $XFree86: xc/programs/Xserver/cfb/cfb8bit.h,v 3.2 1996/06/29 09:05:22 dawes Exp $ */
+
+#include "servermd.h"
+
+#if (BITMAP_BIT_ORDER == MSBFirst)
+#define GetBitGroup(x)         (((PixelGroup) (x)) >> (PGSZ - PGSZB))
+#define NextBitGroup(x)                ((x) <<= PGSZB)
+#define NextSomeBits(x,n)      ((x) <<= (n))
+#else
+#define GetBitGroup(x)         ((x) & PGSZBMSK)
+#define NextBitGroup(x)                ((x) >>= PGSZB)
+#define NextSomeBits(x,n)      ((x) >>= (n))
+#endif
+
+#define RotBitsLeft(x,k)    ((x) = BitLeft (x,k) | \
+                                  BitRight (x, PGSZ-(k)))
+
+#if defined(__GNUC__) && defined(mc68020)
+#undef RotBitsLeft
+#define RotBitsLeft(x,k)       asm("rol%.l %2,%0" \
+                               : "=d" (x) \
+                               : "0" (x), "dI" (k))
+#endif
+
+#if PSZ == 8
+
+#define GetPixelGroup(x)               (cfb8StippleXor[GetBitGroup(x)])
+#define RRopPixels(dst,x)      (DoRRop(dst,cfb8StippleAnd[x], cfb8StippleXor[x]))
+#define RRopPixelGroup(dst,x)  (RRopPixels(dst,GetBitGroup(x)))
+#define MaskRRopPixels(dst,x,mask)  (DoMaskRRop(dst,cfb8StippleAnd[x], cfb8StippleXor[x], mask))
+
+#define NUM_MASKS      (1<<PPW) /* XXX goes in cfbmskbits.h? */
+extern int             cfb8StippleMode, cfb8StippleAlu;
+extern PixelGroup      cfb8StippleFg, cfb8StippleBg, cfb8StipplePm;
+extern PixelGroup      cfb8StippleMasks[NUM_MASKS];
+extern PixelGroup      cfb8StippleAnd[NUM_MASKS], cfb8StippleXor[NUM_MASKS];
+extern int             cfb8StippleRRop;
+
+#define cfb8PixelMasks cfb8StippleMasks
+#define cfb8Pixels     cfb8StippleXor
+
+#define cfb8CheckPixels(fg, bg) \
+    (FillOpaqueStippled == cfb8StippleMode && \
+     GXcopy == cfb8StippleAlu && \
+     ((fg) & PMSK) == cfb8StippleFg && \
+     ((bg) & PMSK) == cfb8StippleBg && \
+     PMSK == cfb8StipplePm)
+
+#define cfb8CheckOpaqueStipple(alu,fg,bg,pm) \
+    ((FillOpaqueStippled == cfb8StippleMode && \
+      (alu) == cfb8StippleAlu && \
+      ((fg) & PMSK) == cfb8StippleFg && \
+      ((bg) & PMSK) == cfb8StippleBg && \
+      ((pm) & PMSK) == cfb8StipplePm) ? 0 : cfb8SetOpaqueStipple(alu,fg,bg,pm))
+
+#define cfb8CheckStipple(alu,fg,pm) \
+    ((FillStippled == cfb8StippleMode && \
+      (alu) == cfb8StippleAlu && \
+      ((fg) & PMSK) == cfb8StippleFg && \
+      ((pm) & PMSK) == cfb8StipplePm) ? 0 : cfb8SetStipple(alu,fg,pm))
+
+#define cfb8SetPixels(fg,bg) cfb8SetOpaqueStipple(GXcopy,fg,bg,PMSK)
+
+/*
+ * These macros are shared between the unnatural spans code
+ * and the unnatural rectangle code.  No reasonable person
+ * would attempt to use them anyplace else.
+ */
+
+#define NextUnnaturalStippleWord \
+       if (bitsLeft >= MFB_PPW) \
+       { \
+           inputBits = *srcTemp++; \
+           bitsLeft -= MFB_PPW; \
+           partBitsLeft = MFB_PPW; \
+       } \
+       else \
+       { \
+           inputBits = 0; \
+           if (bitsLeft) \
+               inputBits = *srcTemp & ~cfb8BitLenMasks[bitsLeft]; \
+           srcTemp = srcStart; \
+           partBitsLeft = bitsLeft; \
+           bitsLeft = bitsWhole; \
+       }
+
+#define NextUnnaturalStippleBits \
+    if (partBitsLeft >= PPW) { \
+       bits = GetBitGroup (inputBits); \
+       NextBitGroup (inputBits); \
+       partBitsLeft -= PPW; \
+    } else { \
+       bits = GetBitGroup (inputBits); \
+       nextPartBits = PPW - partBitsLeft; \
+       NextUnnaturalStippleWord \
+       if (partBitsLeft < nextPartBits) { \
+           if (partBitsLeft) {\
+               bits |= BitRight (GetBitGroup (inputBits), \
+                                 PPW - nextPartBits) & PPWMSK;\
+               nextPartBits -= partBitsLeft; \
+           } \
+           NextUnnaturalStippleWord \
+       } \
+       bits |= BitRight (GetBitGroup (inputBits), \
+                         PPW - nextPartBits) & PPWMSK; \
+       NextSomeBits (inputBits, nextPartBits); \
+       partBitsLeft -= nextPartBits; \
+    }
+
+#define NextUnnaturalStippleBitsFast \
+    if (partBitsLeft >= PPW) { \
+       bits = GetBitGroup(inputBits); \
+       NextBitGroup(inputBits); \
+       partBitsLeft -= PPW; \
+    } else { \
+       bits = GetBitGroup (inputBits); \
+       nextPartBits = PPW - partBitsLeft; \
+       inputBits = *srcTemp++; \
+       bits |= BitRight (GetBitGroup (inputBits), \
+                         partBitsLeft) & PPWMSK; \
+       NextSomeBits (inputBits, nextPartBits); \
+       partBitsLeft =  MFB_PPW - nextPartBits; \
+    }
+
+/*
+ * WriteBitGroup takes the destination address, a pixel
+ * value (which must be 8 bits duplicated 4 time with PFILL)
+ * and the PPW bits to write, which must be in the low order
+ * bits of the register (probably from GetBitGroup) and writes
+ * the appropriate locations in memory with the pixel value.  This
+ * is a copy-mode only operation.
+ */
+
+#define RRopBitGroup(dst,bits)                                 \
+    {                                                          \
+    register PixelGroup    _bitsTmp = (bits);                  \
+    *(dst) = RRopPixels(*(dst),bits);                          \
+    }
+
+#define MaskRRopBitGroup(dst,bits,mask)                                \
+    {                                                          \
+    register PixelGroup   _bitsTmp = (bits);                   \
+    *(dst) = MaskRRopPixels(*(dst),bits,mask);                 \
+    }
+#endif /* PSZ == 8 */
+
+#if !defined(AVOID_MEMORY_READ) && PSZ == 8
+
+#define WriteBitGroup(dst,pixel,bits)                          \
+    {                                                          \
+    register PixelGroup _maskTmp = cfb8PixelMasks[(bits)];   \
+    *(dst) = (*(dst) & ~_maskTmp) | ((pixel) & _maskTmp);      \
+    }
+
+#define SwitchBitGroup(dst,pixel,bits)                         \
+    {                                                          \
+    register PixelGroup _maskTmp = cfb8PixelMasks[(bits)];   \
+    register PixelGroup _pixTmp = ((pixel) & _maskTmp);        \
+    _maskTmp = ~_maskTmp;                                      \
+    SwitchBitsLoop (*(dst) = (*(dst) & _maskTmp) | _pixTmp;)   \
+    }
+    
+#else /* AVOID_MEMORY_READ */
+
+#if PGSZ == 32
+#if (BITMAP_BIT_ORDER == MSBFirst)
+#define SinglePixel0   3
+#define SinglePixel1   2
+#define SinglePixel2   1
+#define SinglePixel3   0
+#define SinglePixel4   7
+#define SinglePixel5   6
+#define SinglePixel6   5
+#define SinglePixel7   4
+#define SinglePixel8   0xB
+#define SinglePixel9   0xA
+#define DoublePixel0   1
+#define DoublePixel1   0
+#define DoublePixel2   3
+#define DoublePixel3   2
+#define DoublePixel4   5
+#define DoublePixel5   4
+#else
+#define SinglePixel0   0
+#define SinglePixel1   1
+#define SinglePixel2   2
+#define SinglePixel3   3
+#define SinglePixel4   4
+#define SinglePixel5   5
+#define SinglePixel6   6
+#define SinglePixel7   7
+#define SinglePixel8   8
+#define SinglePixel9   9
+#define DoublePixel0   0
+#define DoublePixel1   1
+#define DoublePixel2   2
+#define DoublePixel3   3
+#define DoublePixel4   4
+#define DoublePixel5   5
+#endif
+#define QuadPixel0     0
+#define QuadPixel1     1
+#define QuadPixel2     2
+#else /* PGSZ == 64 */
+#if (BITMAP_BIT_ORDER == MSBFirst)
+#define SinglePixel0   7
+#define SinglePixel1   6
+#define SinglePixel2   5
+#define SinglePixel3   4
+#define SinglePixel4   3
+#define SinglePixel5   2
+#define SinglePixel6   1
+#define SinglePixel7   0
+#define DoublePixel0   3
+#define DoublePixel1   2
+#define DoublePixel2   1
+#define DoublePixel3   0
+#define QuadPixel0     1
+#define QuadPixel1     0
+#else
+#define SinglePixel0   0
+#define SinglePixel1   1
+#define SinglePixel2   2
+#define SinglePixel3   3
+#define SinglePixel4   4
+#define SinglePixel5   5
+#define SinglePixel6   6
+#define SinglePixel7   7
+#define DoublePixel0   0
+#define DoublePixel1   1
+#define DoublePixel2   2
+#define DoublePixel3   3
+#define QuadPixel0     0
+#define QuadPixel1     1
+#endif
+#define OctaPixel0     0
+#endif /* PGSZ == 64 */
+
+#if PSZ == 8
+
+#if PGSZ == 32
+#define WriteBitGroup(dst,pixel,bits) \
+       switch (bits) {                 \
+       case 0:                         \
+           break;                      \
+       case 1:                         \
+           ((CARD8 *) (dst))[SinglePixel0] = (pixel);  \
+           break;                      \
+       case 2:                         \
+           ((CARD8 *) (dst))[SinglePixel1] = (pixel);  \
+           break;                      \
+       case 3:                         \
+           ((CARD16 *) (dst))[DoublePixel0] = (pixel); \
+           break;                      \
+       case 4:                         \
+           ((CARD8 *) (dst))[SinglePixel2] = (pixel);  \
+           break;                      \
+       case 5:                         \
+           ((CARD8 *) (dst))[SinglePixel0] = (pixel);  \
+           ((CARD8 *) (dst))[SinglePixel2] = (pixel);  \
+           break;                      \
+       case 6:                         \
+           ((CARD8 *) (dst))[SinglePixel1] = (pixel);  \
+           ((CARD8 *) (dst))[SinglePixel2] = (pixel);  \
+           break;                      \
+       case 7:                         \
+           ((CARD16 *) (dst))[DoublePixel0] = (pixel); \
+           ((CARD8 *) (dst))[SinglePixel2] = (pixel);  \
+           break;                      \
+       case 8:                         \
+           ((CARD8 *) (dst))[SinglePixel3] = (pixel);  \
+           break;                      \
+       case 9:                         \
+           ((CARD8 *) (dst))[SinglePixel0] = (pixel);  \
+           ((CARD8 *) (dst))[SinglePixel3] = (pixel);  \
+           break;                      \
+       case 10:                        \
+           ((CARD8 *) (dst))[SinglePixel1] = (pixel);  \
+           ((CARD8 *) (dst))[SinglePixel3] = (pixel);  \
+           break;                      \
+       case 11:                        \
+           ((CARD16 *) (dst))[DoublePixel0] = (pixel); \
+           ((CARD8 *) (dst))[SinglePixel3] = (pixel);  \
+           break;                      \
+       case 12:                        \
+           ((CARD16 *) (dst))[DoublePixel1] = (pixel); \
+           break;                      \
+       case 13:                        \
+           ((CARD8 *) (dst))[SinglePixel0] = (pixel);  \
+           ((CARD16 *) (dst))[DoublePixel1] = (pixel); \
+           break;                      \
+       case 14:                        \
+           ((CARD8 *) (dst))[SinglePixel1] = (pixel);  \
+           ((CARD16 *) (dst))[DoublePixel1] = (pixel); \
+           break;                      \
+       case 15:                        \
+           ((CARD32 *) (dst))[0] = (pixel);    \
+           break;                      \
+       }
+#else /* PGSZ == 64 */
+#define WriteBitGroup(dst,pixel,bits)                          \
+    if ( bits == 0xff )                                                \
+       ((PixelGroup *) (dst))[OctaPixel0] = (pixel);           \
+    else {                                                     \
+       switch (bits & 0x0f) {                                  \
+           case 0:                                             \
+               break;                                          \
+           case 1:                                             \
+               ((CARD8 *) (dst))[SinglePixel0] = (pixel);      \
+               break;                                          \
+           case 2:                                             \
+               ((CARD8 *) (dst))[SinglePixel1] = (pixel);      \
+               break;                                          \
+           case 3:                                             \
+               ((CARD16 *) (dst))[DoublePixel0] = (pixel);     \
+               break;                                          \
+           case 4:                                             \
+               ((CARD8 *) (dst))[SinglePixel2] = (pixel);      \
+               break;                                          \
+           case 5:                                             \
+               ((CARD8 *) (dst))[SinglePixel0] = (pixel);      \
+               ((CARD8 *) (dst))[SinglePixel2] = (pixel);      \
+               break;                                          \
+           case 6:                                             \
+               ((CARD8 *) (dst))[SinglePixel1] = (pixel);      \
+               ((CARD8 *) (dst))[SinglePixel2] = (pixel);      \
+               break;                                          \
+           case 7:                                             \
+               ((CARD16 *) (dst))[DoublePixel0] = (pixel);     \
+               ((CARD8 *) (dst))[SinglePixel2] = (pixel);      \
+               break;                                          \
+           case 8:                                             \
+               ((CARD8 *) (dst))[SinglePixel3] = (pixel);      \
+               break;                                          \
+           case 9:                                             \
+               ((CARD8 *) (dst))[SinglePixel0] = (pixel);      \
+               ((CARD8 *) (dst))[SinglePixel3] = (pixel);      \
+               break;                                          \
+           case 10:                                            \
+               ((CARD8 *) (dst))[SinglePixel1] = (pixel);      \
+               ((CARD8 *) (dst))[SinglePixel3] = (pixel);      \
+               break;                                          \
+           case 11:                                            \
+               ((CARD16 *) (dst))[DoublePixel0] = (pixel);     \
+               ((CARD8 *) (dst))[SinglePixel3] = (pixel);      \
+               break;                                          \
+           case 12:                                            \
+               ((CARD16 *) (dst))[DoublePixel1] = (pixel);     \
+               break;                                          \
+           case 13:                                            \
+               ((CARD8 *) (dst))[SinglePixel0] = (pixel);      \
+               ((CARD16 *) (dst))[DoublePixel1] = (pixel);     \
+               break;                                          \
+           case 14:                                            \
+               ((CARD8 *) (dst))[SinglePixel1] = (pixel);      \
+               ((CARD16 *) (dst))[DoublePixel1] = (pixel);     \
+               break;                                          \
+           case 15:                                            \
+               ((CARD32 *) (dst))[QuadPixel0] = (pixel);       \
+               break;                                          \
+       }                                                       \
+       switch ((bits & 0xf0) >> 4) {                           \
+           case 0:                                             \
+               break;                                          \
+           case 1:                                             \
+               ((CARD8 *) (dst))[SinglePixel4] = (pixel);      \
+               break;                                          \
+           case 2:                                             \
+               ((CARD8 *) (dst))[SinglePixel5] = (pixel);      \
+               break;                                          \
+           case 3:                                             \
+               ((CARD16 *) (dst))[DoublePixel2] = (pixel);     \
+               break;                                          \
+           case 4:                                             \
+               ((CARD8 *) (dst))[SinglePixel6] = (pixel);      \
+               break;                                          \
+           case 5:                                             \
+               ((CARD8 *) (dst))[SinglePixel4] = (pixel);      \
+               ((CARD8 *) (dst))[SinglePixel6] = (pixel);      \
+               break;                                          \
+           case 6:                                             \
+               ((CARD8 *) (dst))[SinglePixel5] = (pixel);      \
+               ((CARD8 *) (dst))[SinglePixel6] = (pixel);      \
+               break;                                          \
+           case 7:                                             \
+               ((CARD16 *) (dst))[DoublePixel2] = (pixel);     \
+               ((CARD8 *) (dst))[SinglePixel6] = (pixel);      \
+               break;                                          \
+           case 8:                                             \
+               ((CARD8 *) (dst))[SinglePixel7] = (pixel);      \
+               break;                                          \
+           case 9:                                             \
+               ((CARD8 *) (dst))[SinglePixel4] = (pixel);      \
+               ((CARD8 *) (dst))[SinglePixel7] = (pixel);      \
+               break;                                          \
+           case 10:                                            \
+               ((CARD8 *) (dst))[SinglePixel5] = (pixel);      \
+               ((CARD8 *) (dst))[SinglePixel7] = (pixel);      \
+               break;                                          \
+           case 11:                                            \
+               ((CARD16 *) (dst))[DoublePixel2] = (pixel);     \
+               ((CARD8 *) (dst))[SinglePixel7] = (pixel);      \
+               break;                                          \
+           case 12:                                            \
+               ((CARD16 *) (dst))[DoublePixel3] = (pixel);     \
+               break;                                          \
+           case 13:                                            \
+               ((CARD8 *) (dst))[SinglePixel4] = (pixel);      \
+               ((CARD16 *) (dst))[DoublePixel3] = (pixel);     \
+               break;                                          \
+           case 14:                                            \
+               ((CARD8 *) (dst))[SinglePixel5] = (pixel);      \
+               ((CARD16 *) (dst))[DoublePixel3] = (pixel);     \
+               break;                                          \
+           case 15:                                            \
+               ((CARD32 *) (dst))[QuadPixel1] = (pixel);       \
+               break;                                          \
+       }                                                       \
+    }
+#endif /* PGSZ == 64 */
+
+#if PGSZ == 32
+#define SwitchBitGroup(dst,pixel,bits) { \
+       switch (bits) { \
+       case 0: \
+                   break; \
+       case 1: \
+           SwitchBitsLoop (((CARD8 *) (dst))[SinglePixel0] = (pixel);) \
+           break; \
+       case 2: \
+           SwitchBitsLoop (((CARD8 *) (dst))[SinglePixel1] = (pixel);) \
+           break; \
+       case 3: \
+           SwitchBitsLoop (((CARD16 *) (dst))[DoublePixel0] = (pixel);) \
+           break; \
+       case 4: \
+           SwitchBitsLoop (((CARD8 *) (dst))[SinglePixel2] = (pixel);) \
+           break; \
+       case 5: \
+           SwitchBitsLoop (((CARD8 *) (dst))[SinglePixel0] = (pixel); \
+                    ((CARD8 *) (dst))[SinglePixel2] = (pixel);) \
+           break; \
+       case 6: \
+           SwitchBitsLoop (((CARD8 *) (dst))[SinglePixel1] = (pixel); \
+                    ((CARD8 *) (dst))[SinglePixel2] = (pixel);) \
+           break; \
+       case 7: \
+           SwitchBitsLoop (((CARD16 *) (dst))[DoublePixel0] = (pixel); \
+                    ((CARD8 *) (dst))[SinglePixel2] = (pixel);) \
+           break; \
+       case 8: \
+           SwitchBitsLoop (((CARD8 *) (dst))[SinglePixel3] = (pixel);) \
+           break; \
+       case 9: \
+           SwitchBitsLoop (((CARD8 *) (dst))[SinglePixel0] = (pixel); \
+                    ((CARD8 *) (dst))[SinglePixel3] = (pixel);) \
+           break; \
+       case 10: \
+           SwitchBitsLoop (((CARD8 *) (dst))[SinglePixel1] = (pixel); \
+                    ((CARD8 *) (dst))[SinglePixel3] = (pixel);) \
+           break; \
+       case 11: \
+           SwitchBitsLoop (((CARD16 *) (dst))[DoublePixel0] = (pixel); \
+                    ((CARD8 *) (dst))[SinglePixel3] = (pixel);) \
+           break; \
+       case 12: \
+           SwitchBitsLoop (((CARD16 *) (dst))[DoublePixel1] = (pixel);) \
+           break; \
+       case 13: \
+           SwitchBitsLoop (((CARD8 *) (dst))[SinglePixel0] = (pixel); \
+                    ((CARD16 *) (dst))[DoublePixel1] = (pixel);) \
+           break; \
+       case 14: \
+           SwitchBitsLoop (((CARD8 *) (dst))[SinglePixel1] = (pixel); \
+                    ((CARD16 *) (dst))[DoublePixel1] = (pixel);) \
+           break; \
+       case 15: \
+           SwitchBitsLoop (((CARD32 *) (dst))[0] = (pixel);) \
+           break; \
+       } \
+}
+#else /* PGSZ == 64 */
+#define SwitchBitGroup(dst,pixel,bits) {                                  \
+    if ( bits == 0xff )                                                           \
+       SwitchBitsLoop (((PixelGroup *) (dst))[OctaPixel0] = (pixel);)     \
+    else {                                                                \
+       switch (bits & 0x0f) {                                             \
+           case 0:                                                        \
+                       break;                                                     \
+           case 1:                                                        \
+               SwitchBitsLoop (((CARD8 *) (dst))[SinglePixel0] = (pixel);) \
+               break;                                                     \
+           case 2:                                                        \
+               SwitchBitsLoop (((CARD8 *) (dst))[SinglePixel1] = (pixel);) \
+               break;                                                     \
+           case 3:                                                        \
+               SwitchBitsLoop (((CARD16 *) (dst))[DoublePixel0] = (pixel);)\
+               break;                                                     \
+           case 4:                                                        \
+               SwitchBitsLoop (((CARD8 *) (dst))[SinglePixel2] = (pixel);) \
+               break;                                                     \
+           case 5:                                                        \
+               SwitchBitsLoop (((CARD8 *) (dst))[SinglePixel0] = (pixel);  \
+                               ((CARD8 *) (dst))[SinglePixel2] = (pixel);) \
+               break;                                                     \
+           case 6:                                                        \
+               SwitchBitsLoop (((CARD8 *) (dst))[SinglePixel1] = (pixel);  \
+                               ((CARD8 *) (dst))[SinglePixel2] = (pixel);) \
+               break;                                                     \
+           case 7:                                                        \
+               SwitchBitsLoop (((CARD16 *) (dst))[DoublePixel0] = (pixel); \
+                               ((CARD8 *) (dst))[SinglePixel2] = (pixel);) \
+               break;                                                     \
+           case 8:                                                        \
+               SwitchBitsLoop (((CARD8 *) (dst))[SinglePixel3] = (pixel);) \
+               break;                                                     \
+           case 9:                                                        \
+               SwitchBitsLoop (((CARD8 *) (dst))[SinglePixel0] = (pixel);  \
+                               ((CARD8 *) (dst))[SinglePixel3] = (pixel);) \
+               break;                                                     \
+           case 10:                                                       \
+               SwitchBitsLoop (((CARD8 *) (dst))[SinglePixel1] = (pixel);  \
+                               ((CARD8 *) (dst))[SinglePixel3] = (pixel);) \
+               break;                                                     \
+           case 11:                                                       \
+               SwitchBitsLoop (((CARD16 *) (dst))[DoublePixel0] = (pixel); \
+                               ((CARD8 *) (dst))[SinglePixel3] = (pixel);) \
+               break;                                                     \
+           case 12:                                                       \
+               SwitchBitsLoop (((CARD16 *) (dst))[DoublePixel1] = (pixel);)\
+               break;                                                     \
+           case 13:                                                       \
+               SwitchBitsLoop (((CARD8 *) (dst))[SinglePixel0] = (pixel);  \
+                               ((CARD16 *) (dst))[DoublePixel1] = (pixel);)\
+               break;                                                     \
+           case 14:                                                       \
+               SwitchBitsLoop (((CARD8 *) (dst))[SinglePixel1] = (pixel);  \
+                               ((CARD16 *) (dst))[DoublePixel1] = (pixel);)\
+               break;                                                     \
+           case 15:                                                       \
+               SwitchBitsLoop (((CARD32 *) (dst))[QuadPixel0] = (pixel);)    \
+               break;                                                     \
+       }                                                                  \
+       switch ((bits & 0xf0) >> 4) {                                      \
+           case 0:                                                        \
+                       break;                                                     \
+           case 1:                                                        \
+               SwitchBitsLoop (((CARD8 *) (dst))[SinglePixel4] = (pixel);) \
+               break;                                                     \
+           case 2:                                                        \
+               SwitchBitsLoop (((CARD8 *) (dst))[SinglePixel5] = (pixel);) \
+               break;                                                     \
+           case 3:                                                        \
+               SwitchBitsLoop (((CARD16 *) (dst))[DoublePixel2] = (pixel);)\
+               break;                                                     \
+           case 4:                                                        \
+               SwitchBitsLoop (((CARD8 *) (dst))[SinglePixel6] = (pixel);) \
+               break;                                                     \
+           case 5:                                                        \
+               SwitchBitsLoop (((CARD8 *) (dst))[SinglePixel4] = (pixel);  \
+                               ((CARD8 *) (dst))[SinglePixel6] = (pixel);) \
+               break;                                                     \
+           case 6:                                                        \
+               SwitchBitsLoop (((CARD8 *) (dst))[SinglePixel5] = (pixel);  \
+                               ((CARD8 *) (dst))[SinglePixel6] = (pixel);) \
+               break;                                                     \
+           case 7:                                                        \
+               SwitchBitsLoop (((CARD16 *) (dst))[DoublePixel2] = (pixel); \
+                               ((CARD8 *) (dst))[SinglePixel6] = (pixel);) \
+               break;                                                     \
+           case 8:                                                        \
+               SwitchBitsLoop (((CARD8 *) (dst))[SinglePixel7] = (pixel);) \
+               break;                                                     \
+           case 9:                                                        \
+               SwitchBitsLoop (((CARD8 *) (dst))[SinglePixel4] = (pixel);  \
+                               ((CARD8 *) (dst))[SinglePixel7] = (pixel);) \
+               break;                                                     \
+           case 10:                                                       \
+               SwitchBitsLoop (((CARD8 *) (dst))[SinglePixel5] = (pixel);  \
+                               ((CARD8 *) (dst))[SinglePixel7] = (pixel);) \
+               break;                                                     \
+           case 11:                                                       \
+               SwitchBitsLoop (((CARD16 *) (dst))[DoublePixel2] = (pixel); \
+                               ((CARD8 *) (dst))[SinglePixel7] = (pixel);) \
+               break;                                                     \
+           case 12:                                                       \
+               SwitchBitsLoop (((CARD16 *) (dst))[DoublePixel3] = (pixel);)\
+               break;                                                     \
+           case 13:                                                       \
+               SwitchBitsLoop (((CARD8 *) (dst))[SinglePixel4] = (pixel);  \
+                               ((CARD16 *) (dst))[DoublePixel3] = (pixel);)\
+               break;                                                     \
+           case 14:                                                       \
+               SwitchBitsLoop (((CARD8 *) (dst))[SinglePixel5] = (pixel);  \
+                               ((CARD16 *) (dst))[DoublePixel3] = (pixel);)\
+               break;                                                     \
+           case 15:                                                       \
+               SwitchBitsLoop (((CARD32 *) (dst))[QuadPixel1] = (pixel);) \
+               break;                                                     \
+       }                                                                  \
+    }                                                                     \
+}
+#endif /* PGSZ == 64 */
+#endif /* PSZ == 8 */
+
+#if PSZ == 16
+
+#if PGSZ == 32
+#define WriteBitGroup(dst,pixel,bits) \
+       switch (bits) {                 \
+       case 0:                         \
+           break;                      \
+       case 1:                         \
+           ((CARD16 *) (dst))[SinglePixel0] = (pixel); \
+           break;                      \
+       case 2:                         \
+           ((CARD16 *) (dst))[SinglePixel1] = (pixel); \
+           break;                      \
+       case 3:                         \
+           ((CARD32 *) (dst))[DoublePixel0] = (pixel); \
+           break;                      \
+       case 4:                         \
+           ((CARD16 *) (dst))[SinglePixel2] = (pixel); \
+           break;                      \
+       case 5:                         \
+           ((CARD16 *) (dst))[SinglePixel0] = (pixel); \
+           ((CARD16 *) (dst))[SinglePixel2] = (pixel); \
+           break;                      \
+       case 6:                         \
+           ((CARD16 *) (dst))[SinglePixel1] = (pixel); \
+           ((CARD16 *) (dst))[SinglePixel2] = (pixel); \
+           break;                      \
+       case 7:                         \
+           ((CARD32 *) (dst))[DoublePixel0] = (pixel); \
+           ((CARD16 *) (dst))[SinglePixel2] = (pixel); \
+           break;                      \
+       case 8:                         \
+           ((CARD16 *) (dst))[SinglePixel3] = (pixel); \
+           break;                      \
+       case 9:                         \
+           ((CARD16 *) (dst))[SinglePixel0] = (pixel); \
+           ((CARD16 *) (dst))[SinglePixel3] = (pixel); \
+           break;                      \
+       case 10:                        \
+           ((CARD16 *) (dst))[SinglePixel1] = (pixel); \
+           ((CARD16 *) (dst))[SinglePixel3] = (pixel); \
+           break;                      \
+       case 11:                        \
+           ((CARD32 *) (dst))[DoublePixel0] = (pixel); \
+           ((CARD16 *) (dst))[SinglePixel3] = (pixel); \
+           break;                      \
+       case 12:                        \
+           ((CARD32 *) (dst))[DoublePixel1] = (pixel); \
+           break;                      \
+       case 13:                        \
+           ((CARD16 *) (dst))[SinglePixel0] = (pixel); \
+           ((CARD32 *) (dst))[DoublePixel1] = (pixel); \
+           break;                      \
+       case 14:                        \
+           ((CARD16 *) (dst))[SinglePixel1] = (pixel); \
+           ((CARD32 *) (dst))[DoublePixel1] = (pixel); \
+           break;                      \
+       case 15:                        \
+           ((CARD32 *) (dst))[DoublePixel0] = (pixel); \
+           ((CARD32 *) (dst))[DoublePixel1] = (pixel); \
+           break;                      \
+       }
+#else /* PGSZ == 64 */
+#define WriteBitGroup(dst,pixel,bits) \
+    if ( bits == 0xff )        {                                               \
+       ((PixelGroup *) (dst))[QuadPixel0] = (pixel);                   \
+       ((PixelGroup *) (dst))[QuadPixel1] = (pixel);                   \
+    }                                                                  \
+    else {                                                             \
+       switch (bits & 0x0f) {                                          \
+       case 0:                         \
+           break;                      \
+       case 1:                         \
+           ((CARD16 *) (dst))[SinglePixel0] = (pixel); \
+           break;                      \
+       case 2:                         \
+           ((CARD16 *) (dst))[SinglePixel1] = (pixel); \
+           break;                      \
+       case 3:                         \
+           ((CARD32 *) (dst))[DoublePixel0] = (pixel); \
+           break;                      \
+       case 4:                         \
+           ((CARD16 *) (dst))[SinglePixel2] = (pixel); \
+           break;                      \
+       case 5:                         \
+           ((CARD16 *) (dst))[SinglePixel0] = (pixel); \
+           ((CARD16 *) (dst))[SinglePixel2] = (pixel); \
+           break;                      \
+       case 6:                         \
+           ((CARD16 *) (dst))[SinglePixel1] = (pixel); \
+           ((CARD16 *) (dst))[SinglePixel2] = (pixel); \
+           break;                      \
+       case 7:                         \
+           ((CARD32 *) (dst))[DoublePixel0] = (pixel); \
+           ((CARD16 *) (dst))[SinglePixel2] = (pixel); \
+           break;                      \
+       case 8:                         \
+           ((CARD16 *) (dst))[SinglePixel3] = (pixel); \
+           break;                      \
+       case 9:                         \
+           ((CARD16 *) (dst))[SinglePixel0] = (pixel); \
+           ((CARD16 *) (dst))[SinglePixel3] = (pixel); \
+           break;                      \
+       case 10:                        \
+           ((CARD16 *) (dst))[SinglePixel1] = (pixel); \
+           ((CARD16 *) (dst))[SinglePixel3] = (pixel); \
+           break;                      \
+       case 11:                        \
+           ((CARD32 *) (dst))[DoublePixel0] = (pixel); \
+           ((CARD16 *) (dst))[SinglePixel3] = (pixel); \
+           break;                      \
+       case 12:                        \
+           ((CARD32 *) (dst))[DoublePixel1] = (pixel); \
+           break;                      \
+       case 13:                        \
+           ((CARD16 *) (dst))[SinglePixel0] = (pixel); \
+           ((CARD32 *) (dst))[DoublePixel1] = (pixel); \
+           break;                      \
+       case 14:                        \
+           ((CARD16 *) (dst))[SinglePixel1] = (pixel); \
+           ((CARD32 *) (dst))[DoublePixel1] = (pixel); \
+           break;                      \
+       case 15:                        \
+           ((CARD32 *) (dst))[DoublePixel0] = (pixel); \
+           ((CARD32 *) (dst))[DoublePixel1] = (pixel); \
+           break;                      \
+       }                               \
+       switch ((bits & 0xf0) >> 4) {                   \
+       case 0:                         \
+           break;                      \
+       case 1:                         \
+           ((CARD16 *) (dst))[SinglePixel4] = (pixel); \
+           break;                      \
+       case 2:                         \
+           ((CARD16 *) (dst))[SinglePixel5] = (pixel); \
+           break;                      \
+       case 3:                         \
+           ((CARD32 *) (dst))[DoublePixel2] = (pixel); \
+           break;                      \
+       case 4:                         \
+           ((CARD16 *) (dst))[SinglePixel6] = (pixel); \
+           break;                      \
+       case 5:                         \
+           ((CARD16 *) (dst))[SinglePixel4] = (pixel); \
+           ((CARD16 *) (dst))[SinglePixel6] = (pixel); \
+           break;                      \
+       case 6:                         \
+           ((CARD16 *) (dst))[SinglePixel5] = (pixel); \
+           ((CARD16 *) (dst))[SinglePixel6] = (pixel); \
+           break;                      \
+       case 7:                         \
+           ((CARD32 *) (dst))[DoublePixel2] = (pixel); \
+           ((CARD16 *) (dst))[SinglePixel6] = (pixel); \
+           break;                      \
+       case 8:                         \
+           ((CARD16 *) (dst))[SinglePixel7] = (pixel); \
+           break;                      \
+       case 9:                         \
+           ((CARD16 *) (dst))[SinglePixel4] = (pixel); \
+           ((CARD16 *) (dst))[SinglePixel7] = (pixel); \
+           break;                      \
+       case 10:                        \
+           ((CARD16 *) (dst))[SinglePixel5] = (pixel); \
+           ((CARD16 *) (dst))[SinglePixel7] = (pixel); \
+           break;                      \
+       case 11:                        \
+           ((CARD32 *) (dst))[DoublePixel2] = (pixel); \
+           ((CARD16 *) (dst))[SinglePixel7] = (pixel); \
+           break;                      \
+       case 12:                        \
+           ((CARD32 *) (dst))[DoublePixel3] = (pixel); \
+           break;                      \
+       case 13:                        \
+           ((CARD16 *) (dst))[SinglePixel4] = (pixel); \
+           ((CARD32 *) (dst))[DoublePixel3] = (pixel); \
+           break;                      \
+       case 14:                        \
+           ((CARD16 *) (dst))[SinglePixel5] = (pixel); \
+           ((CARD32 *) (dst))[DoublePixel3] = (pixel); \
+           break;                      \
+       case 15:                        \
+           ((CARD32 *) (dst))[DoublePixel2] = (pixel); \
+           ((CARD32 *) (dst))[DoublePixel3] = (pixel); \
+           break;                      \
+       }                               \
+    }
+#endif /* PGSZ */
+
+#if PGSZ == 32
+#define SwitchBitGroup(dst,pixel,bits) { \
+       switch (bits) { \
+       case 0: \
+                   break; \
+       case 1: \
+           SwitchBitsLoop (((CARD16 *) (dst))[SinglePixel0] = (pixel);) \
+           break; \
+       case 2: \
+           SwitchBitsLoop (((CARD16 *) (dst))[SinglePixel1] = (pixel);) \
+           break; \
+       case 3: \
+           SwitchBitsLoop (((CARD32 *) (dst))[DoublePixel0] = (pixel);) \
+           break; \
+       case 4: \
+           SwitchBitsLoop (((CARD16 *) (dst))[SinglePixel2] = (pixel);) \
+           break; \
+       case 5: \
+           SwitchBitsLoop (((CARD16 *) (dst))[SinglePixel0] = (pixel); \
+                    ((CARD16 *) (dst))[SinglePixel2] = (pixel);) \
+           break; \
+       case 6: \
+           SwitchBitsLoop (((CARD16 *) (dst))[SinglePixel1] = (pixel); \
+                    ((CARD16 *) (dst))[SinglePixel2] = (pixel);) \
+           break; \
+       case 7: \
+           SwitchBitsLoop (((CARD32 *) (dst))[DoublePixel0] = (pixel); \
+                    ((CARD16 *) (dst))[SinglePixel2] = (pixel);) \
+           break; \
+       case 8: \
+           SwitchBitsLoop (((CARD16 *) (dst))[SinglePixel3] = (pixel);) \
+           break; \
+       case 9: \
+           SwitchBitsLoop (((CARD16 *) (dst))[SinglePixel0] = (pixel); \
+                    ((CARD16 *) (dst))[SinglePixel3] = (pixel);) \
+           break; \
+       case 10: \
+           SwitchBitsLoop (((CARD16 *) (dst))[SinglePixel1] = (pixel); \
+                    ((CARD16 *) (dst))[SinglePixel3] = (pixel);) \
+           break; \
+       case 11: \
+           SwitchBitsLoop (((CARD32 *) (dst))[DoublePixel0] = (pixel); \
+                    ((CARD16 *) (dst))[SinglePixel3] = (pixel);) \
+           break; \
+       case 12: \
+           SwitchBitsLoop (((CARD32 *) (dst))[DoublePixel1] = (pixel);) \
+           break; \
+       case 13: \
+           SwitchBitsLoop (((CARD16 *) (dst))[SinglePixel0] = (pixel); \
+                    ((CARD32 *) (dst))[DoublePixel1] = (pixel);) \
+           break; \
+       case 14: \
+           SwitchBitsLoop (((CARD16 *) (dst))[SinglePixel1] = (pixel); \
+                    ((CARD32 *) (dst))[DoublePixel1] = (pixel);) \
+           break; \
+       case 15: \
+           SwitchBitsLoop (((CARD32 *) (dst))[DoublePixel0] = (pixel); \
+                           ((CARD32 *) (dst))[DoublePixel1] = (pixel);) \
+           break; \
+       } \
+}
+#else /* PGSZ == 64 */
+#define SwitchBitGroup(dst,pixel,bits) { \
+       cfb cannot hack 64-bit SwitchBitGroup psz=PSZ
+#endif /* PGSZ */
+
+#endif /* PSZ == 16 */
+
+#if PSZ == 24
+/* 32 000011112222*/
+/* 24 000111222333*/
+/* 16 001122334455*/
+/*  8 0123456789AB*/
+#if PGSZ == 32
+#define WriteBitGroup(dst,pixel,bits) \
+       { \
+       register CARD32 reg_pixel = (pixel); \
+       switch (bits) {                 \
+       case 0:                         \
+           break;                      \
+       case 1:                         \
+           ((CARD16 *) (dst))[DoublePixel0] = reg_pixel;       \
+           ((CARD8 *) (dst))[SinglePixel2] = ((reg_pixel>>16)&0xFF);   \
+           break;                      \
+       case 2:                         \
+           ((CARD8 *) (dst))[SinglePixel3] = reg_pixel&0xFF;   \
+           ((CARD16 *) (dst))[DoublePixel2] = (reg_pixel>>8)&0xFFFF;   \
+           break;                      \
+       case 3:                         \
+           ((CARD8 *) (dst))[SinglePixel3] = reg_pixel & 0xFF; \
+           ((CARD16 *) (dst))[DoublePixel0] = reg_pixel;       \
+           ((CARD16 *) (dst))[DoublePixel2] = (reg_pixel>>8)&0xFFFF;   \
+           ((CARD8 *) (dst))[SinglePixel2] = (reg_pixel>>16&0xFF);     \
+           break;                      \
+       case 4:                         \
+           ((CARD16 *) (dst))[DoublePixel3] = reg_pixel;       \
+           ((CARD8 *) (dst))[SinglePixel8] = (reg_pixel>>16)&0xFF; \
+           break;                      \
+       case 5:                         \
+           ((CARD16 *) (dst))[DoublePixel0] = \
+           ((CARD16 *) (dst))[DoublePixel3] = reg_pixel;       \
+           reg_pixel >>= 16;   \
+           ((CARD8 *) (dst))[SinglePixel2] = \
+           ((CARD8 *) (dst))[SinglePixel8] = reg_pixel&0xFF; \
+           break;                      \
+       case 6:                         \
+           ((CARD8 *) (dst))[SinglePixel3] = reg_pixel;        \
+           ((CARD16 *) (dst))[DoublePixel3] = reg_pixel;       \
+           reg_pixel >>= 8;    \
+           ((CARD16 *) (dst))[DoublePixel2] = reg_pixel;       \
+           reg_pixel >>= 8;    \
+           ((CARD8 *) (dst))[SinglePixel8] = reg_pixel&0xFF; \
+           break;                      \
+       case 7:                         \
+           ((CARD16 *) (dst))[DoublePixel0] = \
+           ((CARD16 *) (dst))[DoublePixel3] = reg_pixel;       \
+           ((CARD8 *) (dst))[SinglePixel3] = reg_pixel&0xFF;   \
+           reg_pixel >>= 8;    \
+           ((CARD16 *) (dst))[DoublePixel2] = reg_pixel;       \
+           reg_pixel >>= 8;    \
+           ((CARD8 *) (dst))[SinglePixel2] = \
+           ((CARD8 *) (dst))[SinglePixel8] = reg_pixel&0xFF; \
+           break;                      \
+       case 8:                         \
+           ((CARD8 *) (dst))[SinglePixel9] = reg_pixel&0xFF;   \
+           ((CARD16 *) (dst))[DoublePixel5] = (reg_pixel>>8);  \
+           break;                      \
+       case 9:                         \
+           ((CARD16 *) (dst))[DoublePixel0] = reg_pixel;       \
+           ((CARD8 *) (dst))[SinglePixel9] = reg_pixel&0xFF;   \
+           reg_pixel >>= 8;    \
+           ((CARD16 *) (dst))[DoublePixel5] = reg_pixel;       \
+           reg_pixel >>= 8;    \
+           ((CARD8 *) (dst))[SinglePixel2] = reg_pixel&0xFF;   \
+           break;                      \
+       case 10:                        \
+           ((CARD8 *) (dst))[SinglePixel3] = \
+           ((CARD8 *) (dst))[SinglePixel9] = reg_pixel&0xFF;   \
+           reg_pixel >>= 8;    \
+           ((CARD16 *) (dst))[DoublePixel2] = \
+           ((CARD16 *) (dst))[DoublePixel5] = reg_pixel;       \
+           break;                      \
+       case 11:                        \
+           ((CARD8 *) (dst))[SinglePixel3] = \
+           ((CARD8 *) (dst))[SinglePixel9] = reg_pixel;        \
+           ((CARD16 *) (dst))[DoublePixel0] = reg_pixel;       \
+           reg_pixel >>= 8;    \
+           ((CARD16 *) (dst))[DoublePixel2] = \
+           ((CARD16 *) (dst))[DoublePixel5] = reg_pixel;       \
+           reg_pixel >>= 8;    \
+           ((CARD8 *) (dst))[SinglePixel2] = reg_pixel;        \
+           break;                      \
+       case 12:                        \
+           ((CARD16 *) (dst))[DoublePixel3] = reg_pixel;       \
+           ((CARD8 *) (dst))[SinglePixel9] = reg_pixel;        \
+           reg_pixel >>= 8;    \
+           ((CARD16 *) (dst))[DoublePixel5] = reg_pixel;       \
+           reg_pixel >>= 8;    \
+           ((CARD8 *) (dst))[SinglePixel8] = reg_pixel; \
+           break;                      \
+       case 13:                        \
+           ((CARD16 *) (dst))[DoublePixel0] = \
+           ((CARD16 *) (dst))[DoublePixel3] = reg_pixel;       \
+           ((CARD8 *) (dst))[SinglePixel9] = reg_pixel;        \
+           reg_pixel >>= 8;    \
+           ((CARD16 *) (dst))[DoublePixel5] = reg_pixel;       \
+           reg_pixel >>= 8;    \
+           ((CARD8 *) (dst))[SinglePixel2] = \
+           ((CARD8 *) (dst))[SinglePixel8] = reg_pixel; \
+           break;                      \
+       case 14:                        \
+           ((CARD8 *) (dst))[SinglePixel3] = \
+           ((CARD8 *) (dst))[SinglePixel9] = reg_pixel;        \
+           ((CARD16 *) (dst))[DoublePixel3] = reg_pixel;       \
+           reg_pixel >>= 8;    \
+           ((CARD16 *) (dst))[DoublePixel2] = \
+           ((CARD16 *) (dst))[DoublePixel5] = reg_pixel;       \
+           reg_pixel >>= 8;    \
+           ((CARD8 *) (dst))[SinglePixel8] = reg_pixel; \
+           break;                      \
+       case 15:                        \
+           ((CARD16 *) (dst))[DoublePixel0] = \
+           ((CARD16 *) (dst))[DoublePixel3] = reg_pixel;       \
+           ((CARD8 *) (dst))[SinglePixel3] = \
+           ((CARD8 *) (dst))[SinglePixel9] = reg_pixel;        \
+           reg_pixel >>= 8;    \
+           ((CARD16 *) (dst))[DoublePixel2] = \
+           ((CARD16 *) (dst))[DoublePixel5] = reg_pixel;       \
+           reg_pixel >>= 8;    \
+           ((CARD8 *) (dst))[SinglePixel8] = \
+           ((CARD8 *) (dst))[SinglePixel2] = reg_pixel;        \
+           break;                      \
+       } \
+      }
+#else /* PGSZ == 64 */
+#define WriteBitGroup(dst,pixel,bits) \
+    if ( bits == 0xff )         {                                 \
+       ((PixelGroup *) (dst))[DoublePixel0] = (pixel);    \
+       ((PixelGroup *) (dst))[DoublePixel1] = (pixel);    \
+       ((PixelGroup *) (dst))[DoublePixel2] = (pixel);    \
+       ((PixelGroup *) (dst))[DoublePixel3] = (pixel);    \
+    }                                                     \
+    else {                                                \
+       switch (bits & 0x0f) {                             \
+       case 0:                         \
+           break;                      \
+       case 1:                         \
+           ((CARD32 *) (dst))[SinglePixel0] = (pixel); \
+           break;                      \
+       case 2:                         \
+           ((CARD32 *) (dst))[SinglePixel1] = (pixel); \
+           break;                      \
+       case 3:                         \
+           ((CARD32 *) (dst))[SinglePixel0] = (pixel); \
+           ((CARD32 *) (dst))[SinglePixel1] = (pixel); \
+           break;                      \
+       case 4:                         \
+           ((CARD32 *) (dst))[SinglePixel2] = (pixel); \
+           break;                      \
+       case 5:                         \
+           ((CARD32 *) (dst))[SinglePixel0] = (pixel); \
+           ((CARD32 *) (dst))[SinglePixel2] = (pixel); \
+           break;                      \
+       case 6:                         \
+           ((CARD32 *) (dst))[SinglePixel1] = (pixel); \
+           ((CARD32 *) (dst))[SinglePixel2] = (pixel); \
+           break;                      \
+       case 7:                         \
+           ((CARD32 *) (dst))[SinglePixel0] = (pixel); \
+           ((CARD32 *) (dst))[SinglePixel1] = (pixel); \
+           ((CARD32 *) (dst))[SinglePixel2] = (pixel); \
+           break;                      \
+       case 8:                         \
+           ((CARD32 *) (dst))[SinglePixel3] = (pixel); \
+           break;                      \
+       case 9:                         \
+           ((CARD32 *) (dst))[SinglePixel0] = (pixel); \
+           ((CARD32 *) (dst))[SinglePixel3] = (pixel); \
+           break;                      \
+       case 10:                        \
+           ((CARD32 *) (dst))[SinglePixel1] = (pixel); \
+           ((CARD32 *) (dst))[SinglePixel3] = (pixel); \
+           break;                      \
+       case 11:                        \
+           ((CARD32 *) (dst))[SinglePixel0] = (pixel); \
+           ((CARD32 *) (dst))[SinglePixel1] = (pixel); \
+           ((CARD32 *) (dst))[SinglePixel3] = (pixel); \
+           break;                      \
+       case 12:                        \
+           ((CARD32 *) (dst))[SinglePixel2] = (pixel); \
+           ((CARD32 *) (dst))[SinglePixel3] = (pixel); \
+           break;                      \
+       case 13:                        \
+           ((CARD32 *) (dst))[SinglePixel0] = (pixel); \
+           ((CARD32 *) (dst))[SinglePixel2] = (pixel); \
+           ((CARD32 *) (dst))[SinglePixel3] = (pixel); \
+           break;                      \
+       case 14:                        \
+           ((CARD32 *) (dst))[SinglePixel1] = (pixel); \
+           ((CARD32 *) (dst))[SinglePixel2] = (pixel); \
+           ((CARD32 *) (dst))[SinglePixel3] = (pixel); \
+           break;                      \
+       case 15:                        \
+           ((CARD32 *) (dst))[SinglePixel0] = (pixel); \
+           ((CARD32 *) (dst))[SinglePixel1] = (pixel); \
+           ((CARD32 *) (dst))[SinglePixel2] = (pixel); \
+           ((CARD32 *) (dst))[SinglePixel3] = (pixel); \
+           break;                      \
+       }                               \
+       switch ((bits & 0xf0) >> 4) {   \
+       case 0:                         \
+           break;                      \
+       case 1:                         \
+           ((CARD32 *) (dst))[SinglePixel4] = (pixel); \
+           break;                      \
+       case 2:                         \
+           ((CARD32 *) (dst))[SinglePixel5] = (pixel); \
+           break;                      \
+       case 3:                         \
+           ((CARD32 *) (dst))[SinglePixel4] = (pixel); \
+           ((CARD32 *) (dst))[SinglePixel5] = (pixel); \
+           break;                      \
+       case 4:                         \
+           ((CARD32 *) (dst))[SinglePixel6] = (pixel); \
+           break;                      \
+       case 5:                         \
+           ((CARD32 *) (dst))[SinglePixel4] = (pixel); \
+           ((CARD32 *) (dst))[SinglePixel6] = (pixel); \
+           break;                      \
+       case 6:                         \
+           ((CARD32 *) (dst))[SinglePixel5] = (pixel); \
+           ((CARD32 *) (dst))[SinglePixel6] = (pixel); \
+           break;                      \
+       case 7:                         \
+           ((CARD32 *) (dst))[SinglePixel4] = (pixel); \
+           ((CARD32 *) (dst))[SinglePixel5] = (pixel); \
+           ((CARD32 *) (dst))[SinglePixel6] = (pixel); \
+           break;                      \
+       case 8:                         \
+           ((CARD32 *) (dst))[SinglePixel7] = (pixel); \
+           break;                      \
+       case 9:                         \
+           ((CARD32 *) (dst))[SinglePixel4] = (pixel); \
+           ((CARD32 *) (dst))[SinglePixel7] = (pixel); \
+           break;                      \
+       case 10:                        \
+           ((CARD32 *) (dst))[SinglePixel5] = (pixel); \
+           ((CARD32 *) (dst))[SinglePixel7] = (pixel); \
+           break;                      \
+       case 11:                        \
+           ((CARD32 *) (dst))[SinglePixel4] = (pixel); \
+           ((CARD32 *) (dst))[SinglePixel5] = (pixel); \
+           ((CARD32 *) (dst))[SinglePixel7] = (pixel); \
+           break;                      \
+       case 12:                        \
+           ((CARD32 *) (dst))[SinglePixel6] = (pixel); \
+           ((CARD32 *) (dst))[SinglePixel7] = (pixel); \
+           break;                      \
+       case 13:                        \
+           ((CARD32 *) (dst))[SinglePixel4] = (pixel); \
+           ((CARD32 *) (dst))[SinglePixel6] = (pixel); \
+           ((CARD32 *) (dst))[SinglePixel7] = (pixel); \
+           break;                      \
+       case 14:                        \
+           ((CARD32 *) (dst))[SinglePixel5] = (pixel); \
+           ((CARD32 *) (dst))[SinglePixel6] = (pixel); \
+           ((CARD32 *) (dst))[SinglePixel7] = (pixel); \
+           break;                      \
+       case 15:                        \
+           ((CARD32 *) (dst))[SinglePixel4] = (pixel); \
+           ((CARD32 *) (dst))[SinglePixel5] = (pixel); \
+           ((CARD32 *) (dst))[SinglePixel6] = (pixel); \
+           ((CARD32 *) (dst))[SinglePixel7] = (pixel); \
+           break;                      \
+       }                               \
+    }
+#endif /* PGSZ */
+
+#if PGSZ == 32
+#define SwitchBitGroup(dst,pixel,bits) { \
+       switch (bits) { \
+       case 0: \
+                   break; \
+       case 1: \
+           SwitchBitsLoop (((CARD16 *) (dst))[DoublePixel0] = (pixel); \
+                           ((CARD8 *) (dst))[SinglePixel2] = (pixel);) \
+           break; \
+       case 2: \
+           SwitchBitsLoop (((CARD8 *) (dst))[SinglePixel3] = (pixel); \
+                           ((CARD16 *) (dst))[DoublePixel2] = (pixel);) \
+           break; \
+       case 3: \
+           SwitchBitsLoop (((CARD32 *) (dst))[QuadPixel0] = (pixel); \
+                           ((CARD16 *) (dst))[DoublePixel2] = (pixel);) \
+           break; \
+       case 4: \
+           SwitchBitsLoop (((CARD16 *) (dst))[DoublePixel3] = (pixel); \
+                           ((CARD8 *) (dst))[SinglePixel8] = (pixel);) \
+           break; \
+       case 5: \
+           SwitchBitsLoop (((CARD16 *) (dst))[DoublePixel0] = (pixel); \
+                           ((CARD8 *) (dst))[SinglePixel2] = (pixel); \
+                           ((CARD16 *) (dst))[DoublePixel3] = (pixel); \
+                           ((CARD8 *) (dst))[SinglePixel8] = (pixel);) \
+           break; \
+       case 6: \
+           SwitchBitsLoop (((CARD8 *) (dst))[SinglePixel3] = (pixel); \
+                           ((CARD32 *) (dst))[QuadPixel2] = (pixel); \
+                           ((CARD8 *) (dst))[SinglePixel8] = (pixel);) \
+           break; \
+       case 7: \
+           SwitchBitsLoop (((CARD32 *) (dst))[QuadPixel0] = (pixel); \
+                           ((CARD32 *) (dst))[QuadPixel1] = (pixel); \
+                           ((CARD8 *) (dst))[SinglePixel8] = (pixel);) \
+           break; \
+       case 8: \
+           SwitchBitsLoop (((CARD8 *) (dst))[SinglePixel9] = (pixel); \
+                           ((CARD16 *) (dst))[DoublePixel5] = (pixel);) \
+           break; \
+       case 9: \
+           SwitchBitsLoop (((CARD16 *) (dst))[DoublePixel0] = (pixel); \
+                           ((CARD8 *) (dst))[SinglePixel2] = (pixel); \
+                           ((CARD8 *) (dst))[SinglePixel9] = (pixel); \
+                           ((CARD16 *) (dst))[DoublePixel5] = (pixel);) \
+           break; \
+       case 10: \
+           SwitchBitsLoop (((CARD8 *) (dst))[SinglePixel3] = (pixel); \
+                           ((CARD16 *) (dst))[DoublePixel2] = (pixel); \
+                           ((CARD8 *) (dst))[SinglePixel9] = (pixel); \
+                           ((CARD16 *) (dst))[DoublePixel5] = (pixel);) \
+           break; \
+       case 11: \
+           SwitchBitsLoop (((CARD32 *) (dst))[QuadPixel0] = (pixel); \
+                           ((CARD16 *) (dst))[DoublePixel3] = (pixel);) \
+                           ((CARD8 *) (dst))[SinglePixel9] = (pixel); \
+                           ((CARD16 *) (dst))[DoublePixel5] = (pixel);) \
+           break; \
+       case 12: \
+           SwitchBitsLoop (((CARD16 *) (dst))[DoublePixel3] = (pixel); \
+                           ((CARD32 *) (dst))[QuadPixel2] = (pixel);) \
+           break; \
+       case 13: \
+           SwitchBitsLoop (((CARD16 *) (dst))[SinglePixel0] = (pixel); \
+                           ((CARD8 *) (dst))[SinglePixel2] = (pixel); \
+                           ((CARD16 *) (dst))[DoublePixel3] = (pixel); \
+                           ((CARD32 *) (dst))[QuadPixel2] = (pixel);) \
+           break; \
+       case 14: \
+           SwitchBitsLoop (((CARD8 *) (dst))[SinglePixel3] = (pixel); \
+                           ((CARD32 *) (dst))[QuadPixel1] = (pixel); \
+                           ((CARD32 *) (dst))[QuadPixel2] = (pixel);) \
+           break; \
+       case 15: \
+           SwitchBitsLoop (((CARD32 *) (dst))[QuadPixel0] = (pixel); \
+                           ((CARD32 *) (dst))[QuadPixel1] = (pixel); \
+                           ((CARD32 *) (dst))[QuadPixel2] = (pixel);) \
+           break; \
+       } \
+}
+#else /* PGSZ == 64 */
+#define SwitchBitGroup(dst,pixel,bits) { \
+       cfb cannot hack 64-bit SwitchBitGroup psz=PSZ
+#endif /* PGSZ */
+
+#endif /* PSZ == 24 */
+
+#if PSZ == 32
+
+#if PGSZ == 32
+#define WriteBitGroup(dst,pixel,bits) \
+       switch (bits) {                 \
+       case 0:                         \
+           break;                      \
+       case 1:                         \
+           ((CARD32 *) (dst))[SinglePixel0] = (pixel); \
+           break;                      \
+       case 2:                         \
+           ((CARD32 *) (dst))[SinglePixel1] = (pixel); \
+           break;                      \
+       case 3:                         \
+           ((CARD32 *) (dst))[SinglePixel0] = (pixel); \
+           ((CARD32 *) (dst))[SinglePixel1] = (pixel); \
+           break;                      \
+       case 4:                         \
+           ((CARD32 *) (dst))[SinglePixel2] = (pixel); \
+           break;                      \
+       case 5:                         \
+           ((CARD32 *) (dst))[SinglePixel0] = (pixel); \
+           ((CARD32 *) (dst))[SinglePixel2] = (pixel); \
+           break;                      \
+       case 6:                         \
+           ((CARD32 *) (dst))[SinglePixel1] = (pixel); \
+           ((CARD32 *) (dst))[SinglePixel2] = (pixel); \
+           break;                      \
+       case 7:                         \
+           ((CARD32 *) (dst))[SinglePixel0] = (pixel); \
+           ((CARD32 *) (dst))[SinglePixel1] = (pixel); \
+           ((CARD32 *) (dst))[SinglePixel2] = (pixel); \
+           break;                      \
+       case 8:                         \
+           ((CARD32 *) (dst))[SinglePixel3] = (pixel); \
+           break;                      \
+       case 9:                         \
+           ((CARD32 *) (dst))[SinglePixel0] = (pixel); \
+           ((CARD32 *) (dst))[SinglePixel3] = (pixel); \
+           break;                      \
+       case 10:                        \
+           ((CARD32 *) (dst))[SinglePixel1] = (pixel); \
+           ((CARD32 *) (dst))[SinglePixel3] = (pixel); \
+           break;                      \
+       case 11:                        \
+           ((CARD32 *) (dst))[SinglePixel0] = (pixel); \
+           ((CARD32 *) (dst))[SinglePixel1] = (pixel); \
+           ((CARD32 *) (dst))[SinglePixel3] = (pixel); \
+           break;                      \
+       case 12:                        \
+           ((CARD32 *) (dst))[SinglePixel2] = (pixel); \
+           ((CARD32 *) (dst))[SinglePixel3] = (pixel); \
+           break;                      \
+       case 13:                        \
+           ((CARD32 *) (dst))[SinglePixel0] = (pixel); \
+           ((CARD32 *) (dst))[SinglePixel2] = (pixel); \
+           ((CARD32 *) (dst))[SinglePixel3] = (pixel); \
+           break;                      \
+       case 14:                        \
+           ((CARD32 *) (dst))[SinglePixel1] = (pixel); \
+           ((CARD32 *) (dst))[SinglePixel2] = (pixel); \
+           ((CARD32 *) (dst))[SinglePixel3] = (pixel); \
+           break;                      \
+       case 15:                        \
+           ((CARD32 *) (dst))[SinglePixel0] = (pixel); \
+           ((CARD32 *) (dst))[SinglePixel1] = (pixel); \
+           ((CARD32 *) (dst))[SinglePixel2] = (pixel); \
+           ((CARD32 *) (dst))[SinglePixel3] = (pixel); \
+           break;                      \
+       }
+#else /* PGSZ == 64 */
+#define WriteBitGroup(dst,pixel,bits) \
+    if ( bits == 0xff )         {                                 \
+       ((PixelGroup *) (dst))[DoublePixel0] = (pixel);    \
+       ((PixelGroup *) (dst))[DoublePixel1] = (pixel);    \
+       ((PixelGroup *) (dst))[DoublePixel2] = (pixel);    \
+       ((PixelGroup *) (dst))[DoublePixel3] = (pixel);    \
+    }                                                     \
+    else {                                                \
+       switch (bits & 0x0f) {                             \
+       case 0:                         \
+           break;                      \
+       case 1:                         \
+           ((CARD32 *) (dst))[SinglePixel0] = (pixel); \
+           break;                      \
+       case 2:                         \
+           ((CARD32 *) (dst))[SinglePixel1] = (pixel); \
+           break;                      \
+       case 3:                         \
+           ((CARD32 *) (dst))[SinglePixel0] = (pixel); \
+           ((CARD32 *) (dst))[SinglePixel1] = (pixel); \
+           break;                      \
+       case 4:                         \
+           ((CARD32 *) (dst))[SinglePixel2] = (pixel); \
+           break;                      \
+       case 5:                         \
+           ((CARD32 *) (dst))[SinglePixel0] = (pixel); \
+           ((CARD32 *) (dst))[SinglePixel2] = (pixel); \
+           break;                      \
+       case 6:                         \
+           ((CARD32 *) (dst))[SinglePixel1] = (pixel); \
+           ((CARD32 *) (dst))[SinglePixel2] = (pixel); \
+           break;                      \
+       case 7:                         \
+           ((CARD32 *) (dst))[SinglePixel0] = (pixel); \
+           ((CARD32 *) (dst))[SinglePixel1] = (pixel); \
+           ((CARD32 *) (dst))[SinglePixel2] = (pixel); \
+           break;                      \
+       case 8:                         \
+           ((CARD32 *) (dst))[SinglePixel3] = (pixel); \
+           break;                      \
+       case 9:                         \
+           ((CARD32 *) (dst))[SinglePixel0] = (pixel); \
+           ((CARD32 *) (dst))[SinglePixel3] = (pixel); \
+           break;                      \
+       case 10:                        \
+           ((CARD32 *) (dst))[SinglePixel1] = (pixel); \
+           ((CARD32 *) (dst))[SinglePixel3] = (pixel); \
+           break;                      \
+       case 11:                        \
+           ((CARD32 *) (dst))[SinglePixel0] = (pixel); \
+           ((CARD32 *) (dst))[SinglePixel1] = (pixel); \
+           ((CARD32 *) (dst))[SinglePixel3] = (pixel); \
+           break;                      \
+       case 12:                        \
+           ((CARD32 *) (dst))[SinglePixel2] = (pixel); \
+           ((CARD32 *) (dst))[SinglePixel3] = (pixel); \
+           break;                      \
+       case 13:                        \
+           ((CARD32 *) (dst))[SinglePixel0] = (pixel); \
+           ((CARD32 *) (dst))[SinglePixel2] = (pixel); \
+           ((CARD32 *) (dst))[SinglePixel3] = (pixel); \
+           break;                      \
+       case 14:                        \
+           ((CARD32 *) (dst))[SinglePixel1] = (pixel); \
+           ((CARD32 *) (dst))[SinglePixel2] = (pixel); \
+           ((CARD32 *) (dst))[SinglePixel3] = (pixel); \
+           break;                      \
+       case 15:                        \
+           ((CARD32 *) (dst))[SinglePixel0] = (pixel); \
+           ((CARD32 *) (dst))[SinglePixel1] = (pixel); \
+           ((CARD32 *) (dst))[SinglePixel2] = (pixel); \
+           ((CARD32 *) (dst))[SinglePixel3] = (pixel); \
+           break;                      \
+       }                               \
+       switch ((bits & 0xf0) >> 4) {   \
+       case 0:                         \
+           break;                      \
+       case 1:                         \
+           ((CARD32 *) (dst))[SinglePixel4] = (pixel); \
+           break;                      \
+       case 2:                         \
+           ((CARD32 *) (dst))[SinglePixel5] = (pixel); \
+           break;                      \
+       case 3:                         \
+           ((CARD32 *) (dst))[SinglePixel4] = (pixel); \
+           ((CARD32 *) (dst))[SinglePixel5] = (pixel); \
+           break;                      \
+       case 4:                         \
+           ((CARD32 *) (dst))[SinglePixel6] = (pixel); \
+           break;                      \
+       case 5:                         \
+           ((CARD32 *) (dst))[SinglePixel4] = (pixel); \
+           ((CARD32 *) (dst))[SinglePixel6] = (pixel); \
+           break;                      \
+       case 6:                         \
+           ((CARD32 *) (dst))[SinglePixel5] = (pixel); \
+           ((CARD32 *) (dst))[SinglePixel6] = (pixel); \
+           break;                      \
+       case 7:                         \
+           ((CARD32 *) (dst))[SinglePixel4] = (pixel); \
+           ((CARD32 *) (dst))[SinglePixel5] = (pixel); \
+           ((CARD32 *) (dst))[SinglePixel6] = (pixel); \
+           break;                      \
+       case 8:                         \
+           ((CARD32 *) (dst))[SinglePixel7] = (pixel); \
+           break;                      \
+       case 9:                         \
+           ((CARD32 *) (dst))[SinglePixel4] = (pixel); \
+           ((CARD32 *) (dst))[SinglePixel7] = (pixel); \
+           break;                      \
+       case 10:                        \
+           ((CARD32 *) (dst))[SinglePixel5] = (pixel); \
+           ((CARD32 *) (dst))[SinglePixel7] = (pixel); \
+           break;                      \
+       case 11:                        \
+           ((CARD32 *) (dst))[SinglePixel4] = (pixel); \
+           ((CARD32 *) (dst))[SinglePixel5] = (pixel); \
+           ((CARD32 *) (dst))[SinglePixel7] = (pixel); \
+           break;                      \
+       case 12:                        \
+           ((CARD32 *) (dst))[SinglePixel6] = (pixel); \
+           ((CARD32 *) (dst))[SinglePixel7] = (pixel); \
+           break;                      \
+       case 13:                        \
+           ((CARD32 *) (dst))[SinglePixel4] = (pixel); \
+           ((CARD32 *) (dst))[SinglePixel6] = (pixel); \
+           ((CARD32 *) (dst))[SinglePixel7] = (pixel); \
+           break;                      \
+       case 14:                        \
+           ((CARD32 *) (dst))[SinglePixel5] = (pixel); \
+           ((CARD32 *) (dst))[SinglePixel6] = (pixel); \
+           ((CARD32 *) (dst))[SinglePixel7] = (pixel); \
+           break;                      \
+       case 15:                        \
+           ((CARD32 *) (dst))[SinglePixel4] = (pixel); \
+           ((CARD32 *) (dst))[SinglePixel5] = (pixel); \
+           ((CARD32 *) (dst))[SinglePixel6] = (pixel); \
+           ((CARD32 *) (dst))[SinglePixel7] = (pixel); \
+           break;                      \
+       }                               \
+    }
+#endif /* PGSZ */
+
+#if PGSZ == 32
+#define SwitchBitGroup(dst,pixel,bits) { \
+       switch (bits) { \
+       case 0: \
+                   break; \
+       case 1: \
+           SwitchBitsLoop (((CARD32 *) (dst))[SinglePixel0] = (pixel);) \
+           break; \
+       case 2: \
+           SwitchBitsLoop (((CARD32 *) (dst))[SinglePixel1] = (pixel);) \
+           break; \
+       case 3: \
+           SwitchBitsLoop (((CARD32 *) (dst))[SinglePixel0] = (pixel); \
+                           ((CARD32 *) (dst))[SinglePixel1] = (pixel);) \
+           break; \
+       case 4: \
+           SwitchBitsLoop (((CARD32 *) (dst))[SinglePixel2] = (pixel);) \
+           break; \
+       case 5: \
+           SwitchBitsLoop (((CARD32 *) (dst))[SinglePixel0] = (pixel); \
+                           ((CARD32 *) (dst))[SinglePixel2] = (pixel);) \
+           break; \
+       case 6: \
+           SwitchBitsLoop (((CARD32 *) (dst))[SinglePixel1] = (pixel); \
+                           ((CARD32 *) (dst))[SinglePixel2] = (pixel);) \
+           break; \
+       case 7: \
+           SwitchBitsLoop (((CARD32 *) (dst))[SinglePixel0] = (pixel); \
+                           ((CARD32 *) (dst))[SinglePixel1] = (pixel); \
+                           ((CARD32 *) (dst))[SinglePixel2] = (pixel);) \
+           break; \
+       case 8: \
+           SwitchBitsLoop (((CARD32 *) (dst))[SinglePixel3] = (pixel);) \
+           break; \
+       case 9: \
+           SwitchBitsLoop (((CARD32 *) (dst))[SinglePixel0] = (pixel); \
+                           ((CARD32 *) (dst))[SinglePixel3] = (pixel);) \
+           break; \
+       case 10: \
+           SwitchBitsLoop (((CARD32 *) (dst))[SinglePixel1] = (pixel); \
+                           ((CARD32 *) (dst))[SinglePixel3] = (pixel);) \
+           break; \
+       case 11: \
+           SwitchBitsLoop (((CARD32 *) (dst))[SinglePixel0] = (pixel); \
+                           ((CARD32 *) (dst))[SinglePixel1] = (pixel); \
+                           ((CARD32 *) (dst))[SinglePixel3] = (pixel);) \
+           break; \
+       case 12: \
+           SwitchBitsLoop (((CARD32 *) (dst))[SinglePixel2] = (pixel); \
+                           ((CARD32 *) (dst))[SinglePixel3] = (pixel);) \
+           break; \
+       case 13: \
+           SwitchBitsLoop (((CARD32 *) (dst))[SinglePixel0] = (pixel); \
+                           ((CARD32 *) (dst))[SinglePixel2] = (pixel); \
+                           ((CARD32 *) (dst))[SinglePixel3] = (pixel);) \
+           break; \
+       case 14: \
+           SwitchBitsLoop (((CARD32 *) (dst))[SinglePixel1] = (pixel); \
+                           ((CARD32 *) (dst))[SinglePixel2] = (pixel); \
+                           ((CARD32 *) (dst))[SinglePixel3] = (pixel);) \
+           break; \
+       case 15: \
+           SwitchBitsLoop (((CARD32 *) (dst))[SinglePixel0] = (pixel); \
+                           ((CARD32 *) (dst))[SinglePixel1] = (pixel); \
+                           ((CARD32 *) (dst))[SinglePixel2] = (pixel); \
+                           ((CARD32 *) (dst))[SinglePixel3] = (pixel);) \
+           break; \
+       } \
+}
+#else /* PGSZ == 64 */
+#define SwitchBitGroup(dst,pixel,bits) { \
+       cfb cannot hack 64-bit SwitchBitGroup psz=PSZ
+#endif /* PGSZ */
+
+#endif /* PSZ == 32 */
+#endif /* AVOID_MEMORY_READ */
+
+extern PixelGroup cfb8BitLenMasks[PGSZ];
+
+extern int cfb8SetStipple (
+#if NeedFunctionPrototypes
+    int        /*alu*/,
+    unsigned long /*fg*/,
+    unsigned long /*planemask*/
+#endif
+);
+
+extern int cfb8SetOpaqueStipple (
+#if NeedFunctionPrototypes
+    int /*alu*/,
+    unsigned long /*fg*/,
+    unsigned long /*bg*/,
+    unsigned long /*planemask*/
+#endif
+);
+
+extern int cfb8ComputeClipMasks32 (
+#if NeedFunctionPrototypes
+    BoxPtr     /*pBox*/,
+    int                /*numRects*/,
+    int                /*x*/,
+    int                /*y*/,
+    int                /*w*/,
+    int                /*h*/,
+    CARD32 * /*clips*/
+#endif
+);
diff --git a/Xserver/programs/Xserver/cfb/cfb8cppl.c b/Xserver/programs/Xserver/cfb/cfb8cppl.c
new file mode 100644 (file)
index 0000000..0b5a9e6
--- /dev/null
@@ -0,0 +1,221 @@
+/*
+ * $XConsortium: cfb8cppl.c,v 1.15 94/04/17 20:28:41 dpw Exp $
+ *
+Copyright (c) 1990  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+ *
+ * Author:  Keith Packard, MIT X Consortium
+ */
+
+#if PSZ == 8
+#include "X.h"
+#include "Xmd.h"
+#include "gcstruct.h"
+#include "window.h"
+#include "pixmapstr.h"
+#include "scrnintstr.h"
+#include "windowstr.h"
+#include "cfb.h"
+#undef   PSZ /* for maskbits.h */
+#include "maskbits.h"
+#include "mergerop.h"
+
+#if BITMAP_BIT_ORDER == MSBFirst
+#define LeftMost    (MFB_PPW-1)
+#define StepBit(bit, inc)  ((bit) -= (inc))
+#else
+#define LeftMost    0
+#define StepBit(bit, inc)  ((bit) += (inc))
+#endif
+
+#define GetBits(psrc, nBits, curBit, bitPos, bits) {\
+    bits = 0; \
+    while (nBits--) \
+    { \
+       bits |= (PixelType)(((*psrc++ >> bitPos) & 1)) << curBit; \
+       StepBit (curBit, 1); \
+    } \
+}
+
+void
+cfbCopyImagePlane (pSrcDrawable, pDstDrawable, rop, prgnDst, pptSrc, planemask)
+    DrawablePtr pSrcDrawable;
+    DrawablePtr pDstDrawable;
+    int        rop;
+    RegionPtr prgnDst;
+    DDXPointPtr pptSrc;
+    unsigned long planemask;
+{
+    cfbCopyPlane8to1 (pSrcDrawable, pDstDrawable, rop, prgnDst, pptSrc,
+                     (unsigned long) ~0L, planemask);
+}
+
+void
+cfbCopyPlane8to1 (pSrcDrawable, pDstDrawable, rop, prgnDst, pptSrc, planemask, bitPlane)
+    DrawablePtr pSrcDrawable;
+    DrawablePtr pDstDrawable;
+    int        rop;
+    RegionPtr prgnDst;
+    DDXPointPtr pptSrc;
+    unsigned long planemask;
+    unsigned long   bitPlane;
+{
+    int                            srcx, srcy, dstx, dsty, width, height;
+    unsigned char          *psrcBase;
+    PixelType              *pdstBase;
+    int                            widthSrc, widthDst;
+    unsigned char          *psrcLine;
+    PixelType              *pdstLine;
+    register unsigned char  *psrc;
+    register int           i;
+    register int           curBit;
+    register int           bitPos;
+    register unsigned long  bits;
+    register PixelType     *pdst;
+    PixelType              startmask, endmask;
+    int                            niStart, niEnd;
+    int                            bitStart, bitEnd;
+    int                            nl, nlMiddle;
+    int                            nbox;
+    BoxPtr                 pbox;
+    MROP_DECLARE()
+
+    if (!(planemask & 1))
+       return;
+
+    if (rop != GXcopy)
+       MROP_INITIALIZE (rop, planemask);
+
+    cfbGetByteWidthAndPointer (pSrcDrawable, widthSrc, psrcBase)
+
+    mfbGetPixelWidthAndPointer (pDstDrawable, widthDst, pdstBase)
+
+    bitPos = ffs (bitPlane) - 1;
+
+    nbox = REGION_NUM_RECTS(prgnDst);
+    pbox = REGION_RECTS(prgnDst);
+    while (nbox--)
+    {
+       dstx = pbox->x1;
+       dsty = pbox->y1;
+       srcx = pptSrc->x;
+       srcy = pptSrc->y;
+       width = pbox->x2 - pbox->x1;
+       height = pbox->y2 - pbox->y1;
+       pbox++;
+       pptSrc++;
+       psrcLine = psrcBase + srcy * widthSrc + srcx;
+       pdstLine = mfbScanline(pdstBase, dstx, dsty, widthDst);
+       dstx &= MFB_PIM;
+       if (dstx + width <= MFB_PPW)
+       {
+           maskpartialbits(dstx, width, startmask);
+           nlMiddle = 0;
+           endmask = 0;
+       }
+       else
+       {
+           maskbits (dstx, width, startmask, endmask, nlMiddle);
+       }
+       if (startmask)
+       {
+           niStart = min(MFB_PPW - dstx, width);
+           bitStart = LeftMost;
+           StepBit (bitStart, dstx);
+       }
+       if (endmask)
+       {
+           niEnd = (dstx + width) & MFB_PIM;
+           bitEnd = LeftMost;
+       }
+       if (rop == GXcopy)
+       {
+           while (height--)
+           {
+               psrc = psrcLine;
+               pdst = pdstLine;
+               psrcLine += widthSrc;
+               mfbScanlineInc(pdstLine, widthDst);
+               if (startmask)
+               {
+                   i = niStart;
+                   curBit = bitStart;
+                   GetBits (psrc, i, curBit, bitPos, bits);
+                   *pdst = *pdst & ~startmask | bits;
+                   pdst++;
+               }
+               nl = nlMiddle;
+               while (nl--)
+               {
+                   i = MFB_PPW;
+                   curBit = LeftMost;
+                   GetBits (psrc, i, curBit, bitPos, bits);
+                   *pdst++ = bits;
+               }
+               if (endmask)
+               {
+                   i = niEnd;
+                   curBit = bitEnd;
+                   GetBits (psrc, i, curBit, bitPos, bits);
+                   *pdst = *pdst & ~endmask | bits;
+               }
+           }
+       }
+       else
+       {
+           while (height--)
+           {
+               psrc = psrcLine;
+               pdst = pdstLine;
+               psrcLine += widthSrc;
+               mfbScanlineInc(pdstLine, widthDst);
+               if (startmask)
+               {
+                   i = niStart;
+                   curBit = bitStart;
+                   GetBits (psrc, i, curBit, bitPos, bits);
+                   *pdst = MROP_MASK(bits, *pdst, startmask);
+                   pdst++;
+               }
+               nl = nlMiddle;
+               while (nl--)
+               {
+                   i = MFB_PPW;
+                   curBit = LeftMost;
+                   GetBits (psrc, i, curBit, bitPos, bits);
+                   *pdst = MROP_SOLID(bits, *pdst);
+                   pdst++;
+               }
+               if (endmask)
+               {
+                   i = niEnd;
+                   curBit = bitEnd;
+                   GetBits (psrc, i, curBit, bitPos, bits);
+                   *pdst = MROP_MASK (bits, *pdst, endmask);
+               }
+           }
+       }
+    }
+}
+
+#endif
diff --git a/Xserver/programs/Xserver/cfb/cfb8line.c b/Xserver/programs/Xserver/cfb/cfb8line.c
new file mode 100644 (file)
index 0000000..34bb600
--- /dev/null
@@ -0,0 +1,1458 @@
+/*
+ * $TOG: cfb8line.c /main/33 1997/07/17 19:33:47 kaleb $
+ *
+Copyright (c) 1990  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+ *
+ * Author:  Keith Packard, MIT X Consortium
+ *
+ * $XFree86: xc/programs/Xserver/cfb/cfb8line.c,v 3.2.2.3 1997/07/19 04:59:19 dawes Exp $
+ * Jeff Anton'x fixes: cfb8line.c   97/02/07
+ */
+
+#include "X.h"
+
+#include "gcstruct.h"
+#include "windowstr.h"
+#include "pixmapstr.h"
+#include "regionstr.h"
+#include "scrnintstr.h"
+#include "mistruct.h"
+
+#include "cfb.h"
+#include "cfbmskbits.h"
+#include "cfbrrop.h"
+#include "miline.h"
+
+#ifdef PIXEL_ADDR
+
+#if defined(__GNUC__) && defined(mc68020)
+#define STUPID volatile
+#define REARRANGE
+#else
+#define STUPID
+#endif
+
+#ifdef __GNUC__
+/* lame compiler doesn't even look at 'register' attributes */
+#define I_H do{
+#define I_T }while(0);
+#define IMPORTANT_START I_H I_H I_H I_H I_H I_H I_H I_H I_H I_H
+#define IMPORTANT_END  I_T I_T I_T I_T I_T I_T I_T I_T I_T I_T
+#else
+#define IMPORTANT_START
+#define IMPORTANT_END
+#endif
+
+#define isClipped(c,ul,lr)  ((((c) - (ul)) | ((lr) - (c))) & ClipMask)
+
+#ifdef POLYSEGMENT
+
+# ifdef sun
+#  define WIDTH_FAST  1152
+# endif
+
+# ifdef ultrix
+#  define WIDTH_FAST  1024
+# endif
+
+# ifdef Mips
+#  define WIDTH_FAST 4096
+# endif
+# ifdef WIDTH_FAST
+#  if WIDTH_FAST == 1024
+#   define FAST_MUL(y) ((y) << 10)
+#  endif
+
+#  if WIDTH_FAST == 1152
+#   define FAST_MUL(y) (((y) << 10) + ((y) << 7))
+#  endif
+
+#  if WIDTH_FAST == 1280
+#   define FAST_MUL(y) (((y) << 10) + ((y) << 8))
+#  endif
+
+#  if WIDTH_FAST == 2048
+#   define FAST_MUL(y) ((y) << 11)
+#  endif
+
+#  if WIDTH_FAST == 4096
+#   define FAST_MUL(y) ((y) << 12)
+#  endif
+# endif
+
+# if defined(WIDTH_SHIFT)
+#  ifdef FAST_MUL
+#   define FUNC_NAME(e)            RROP_NAME(RROP_NAME_CAT(e,Shift))
+#   if RROP == GXcopy
+#    define INCLUDE_OTHERS
+#    define SERIOUS_UNROLLING
+#   endif
+#   define INCLUDE_DRAW
+#   define NWIDTH(nwidth)   WIDTH_FAST
+#   define WIDTH_MUL(y,w)   FAST_MUL(y)
+#  endif
+# else
+#  define FUNC_NAME(e)     RROP_NAME(e)
+#  define WIDTH_MUL(y,w)    ((y) * (w))
+#  define NWIDTH(nwidth)    (nwidth)
+#  define INCLUDE_DRAW
+#  if !defined (FAST_MUL) && RROP == GXcopy
+#   define INCLUDE_OTHERS
+#   define SERIOUS_UNROLLING
+#  endif
+# endif
+#else
+
+# define INCLUDE_DRAW
+# define WIDTH_MUL(y,w)        ((y) * (w))
+# define NWIDTH(nwidth)        nwidth
+# ifdef PREVIOUS
+#  define FUNC_NAME(e) RROP_NAME(RROP_NAME_CAT(e,Previous))
+# else
+#  define FUNC_NAME(e) RROP_NAME(e)
+#  if RROP == GXcopy
+#   define INCLUDE_OTHERS
+#   ifdef PLENTIFUL_REGISTERS
+#    define SAVE_X2Y2
+#   endif
+#   define ORIGIN
+#   define SERIOUS_UNROLLING
+#  else
+#   define EITHER_MODE
+#  endif
+# endif
+#endif
+
+#if PSZ == 24
+#define PXL2ADR(x)  ((x)*3 >> 2)
+
+#if RROP == GXcopy
+#define body_rop \
+           addrp = (PixelType *)((unsigned long)addrb & ~0x03); \
+           switch((unsigned long)addrb & 3){ \
+           case 0: \
+             *addrp = (*addrp & 0xFF000000)|(piQxelXor[0] & 0xFFFFFF); \
+             break; \
+           case 1: \
+             *addrp = (*addrp & 0xFF)|(piQxelXor[2] & 0xFFFFFF00); \
+             break; \
+           case 3: \
+             *addrp = (*addrp & 0xFFFFFF)|(piQxelXor[0] & 0xFF000000); \
+             *(addrp+1)=(*(addrp+1) & 0xFFFF0000)|(piQxelXor[1] & 0xFFFF); \
+             break; \
+           case 2: \
+             *addrp = (*addrp & 0xFFFF)|(piQxelXor[1] & 0xFFFF0000); \
+             *(addrp+1)=(*(addrp+1) & 0xFFFFFF00)|(piQxelXor[2] & 0xFF); \
+             break; \
+           }
+#endif
+#if RROP == GXxor
+#define body_rop \
+           addrp = (PixelType *)((unsigned long)addrb & ~0x03); \
+           switch((unsigned long)addrb & 3){ \
+           case 0: \
+             *addrp ^= piQxelXor[0] & 0xFFFFFF; \
+             break; \
+           case 1: \
+             *addrp ^= piQxelXor[2] & 0xFFFFFF00; \
+             break; \
+           case 3: \
+             *addrp ^= piQxelXor[0] & 0xFF000000; \
+             *(addrp+1) ^= piQxelXor[1] & 0xFFFF; \
+             break; \
+           case 2: \
+             *addrp ^= piQxelXor[1] & 0xFFFF0000; \
+             *(addrp+1) ^= piQxelXor[2] & 0xFF; \
+             break; \
+           }
+#endif
+#if RROP == GXand
+#define body_rop \
+           addrp = (PixelType *)((unsigned long)addrb & ~0x03); \
+           switch((unsigned long)addrb & 3){ \
+           case 0: \
+             *addrp &= piQxelAnd[0] | 0xFF000000; \
+             break; \
+           case 1: \
+             *addrp &= piQxelAnd[2] | 0xFF; \
+             break; \
+           case 3: \
+             *addrp &= 0xFFFFFF | piQxelAnd[0]; \
+             *(addrp+1) &= 0xFFFF0000 | piQxelAnd[1]; \
+             break; \
+           case 2: \
+             *addrp &= 0xFFFF | piQxelAnd[1]; \
+             *(addrp+1) &= 0xFFFFFF00 | piQxelAnd[2]; \
+             break; \
+           }
+#endif
+#if RROP == GXor
+#define body_rop \
+           addrp = (PixelType *)((unsigned long)addrb & ~0x03); \
+           switch((unsigned long)addrb & 3){ \
+           case 0: \
+             *addrp |= piQxelOr[0] & 0xFFFFFF; \
+             break; \
+           case 1: \
+             *addrp |= piQxelOr[2] & 0xFFFFFF00; \
+             break; \
+           case 3: \
+             *addrp |= piQxelOr[0] & 0xFF000000; \
+             *(addrp+1) |= piQxelOr[1] & 0xFFFF; \
+             break; \
+           case 2: \
+             *addrp |= piQxelOr[1] & 0xFFFF0000; \
+             *(addrp+1) |= piQxelOr[2] & 0xFF; \
+             break; \
+           }
+#endif
+#if RROP == GXset
+#define body_rop \
+           addrp = (PixelType *)((unsigned long)addrb & ~0x03); \
+           switch((unsigned long)addrb & 3){ \
+           case 0: \
+             *addrp = (*addrp & (piQxelAnd[0]|0xFF000000)) \
+                       ^ (piQxelXor[0] & 0xFFFFFF); \
+             break; \
+           case 1: \
+             *addrp = (*addrp & (piQxelAnd[2]|0xFF)) \
+                       ^ (piQxelXor[2] & 0xFFFFFF00); \
+             break; \
+           case 3: \
+             *addrp = (*addrp & (piQxelAnd[0]|0xFFFFFF)) \
+                       ^ (piQxelXor[0] & 0xFF000000); \
+             *(addrp+1) = (*(addrp+1) & (piQxelAnd[1]|0xFFFF0000)) \
+                       ^ (piQxelXor[1] & 0xFFFF); \
+             break; \
+           case 2: \
+             *addrp = (*addrp & (piQxelAnd[1]|0xFFFF)) \
+                       ^ (piQxelXor[1] & 0xFFFF0000); \
+             *(addrp+1) = (*(addrp+1) & (piQxelAnd[2]|0xFFFFFF00)) \
+                       ^ (piQxelXor[2] & 0xFF); \
+             break; \
+           }
+#endif
+#endif /* PSZ == 24 */
+
+#define BUGFIX_clip
+
+#ifdef INCLUDE_DRAW
+
+int
+#ifdef POLYSEGMENT
+FUNC_NAME(cfb8SegmentSS1Rect) (pDrawable, pGC, nseg, pSegInit)
+    DrawablePtr        pDrawable;
+    GCPtr      pGC;
+    int                nseg;
+    xSegment   *pSegInit;
+#else
+FUNC_NAME(cfb8LineSS1Rect) (pDrawable, pGC, mode, npt, pptInit, pptInitOrig,
+                           x1p,y1p,x2p,y2p)
+    DrawablePtr pDrawable;
+    GCPtr      pGC;
+    int        mode;           /* Origin or Previous */
+    int        npt;            /* number of points */
+    DDXPointPtr pptInit, pptInitOrig;
+    int        *x1p, *y1p, *x2p, *y2p;
+#endif /* POLYSEGEMENT */
+{
+    register long   e;
+    register int    y1_or_e1;
+    register PixelType   *addrp;
+    register int    stepmajor;
+    register int    stepminor;
+#ifndef REARRANGE
+    register long   e3;
+#endif
+#ifdef mc68000
+    register short  x1_or_len;
+#else
+    register int    x1_or_len;
+#endif
+    RROP_DECLARE
+
+#ifdef SAVE_X2Y2
+# define c2 y2
+#else
+    register int    c2;
+#endif
+#ifndef ORIGIN
+    register int _x1, _y1, _x2, _y2;   /* only used for CoordModePrevious */
+    int extents_x1, extents_y1, extents_x2, extents_y2;
+#endif /* !ORIGIN */
+#ifndef PREVIOUS
+    register int upperleft, lowerright;
+    CARD32      ClipMask = 0x80008000;
+#endif /* !PREVIOUS */
+#ifdef POLYSEGMENT
+    register int    capStyle;
+#endif /* POLYSEGMENT */
+#ifdef SAVE_X2Y2
+    register int    x2, y2;
+# define X1  x1_or_len
+# define Y1  y1_or_e1
+# define X2  x2
+# define Y2  y2
+#else
+# ifdef POLYSEGMENT
+#  define X1  x1_or_len
+#  define Y1  y1_or_e1
+# else
+#  define X1  intToX(y1_or_e1)
+#  define Y1  intToY(y1_or_e1)
+# endif /* POLYSEGMENT */
+# define X2  intToX(c2)
+# define Y2  intToY(c2)
+#endif /* SAVE_X2Y2 */
+    PixelType   *addr;
+    int                    nwidth;
+    cfbPrivGCPtr    devPriv;
+    BoxPtr         extents;
+    int                    *ppt;
+#if PSZ == 24
+    int xBase;     /* x of addr */
+    int xOffset;   /* x of addrp */
+    int xOffset_t; /* x of t */
+    PixelType   *addrLineEnd;
+    char *addrb;
+    int stepmajor3, stepminor3, majordx, minordx;
+#endif
+#ifdef BUGFIX_clip
+    int ex_x1, ex_y1, ex_x2, ex_y2;
+#endif
+    int                    octant;
+    unsigned int    bias = miGetZeroLineBias(pDrawable->pScreen);
+
+    devPriv = cfbGetGCPrivate(pGC);
+    cfbGetPixelWidthAndPointer (pDrawable, nwidth, addr);
+#ifndef REARRANGE
+    RROP_FETCH_GCPRIV(devPriv);
+#endif
+    extents = &devPriv->pCompositeClip->extents;
+#ifndef PREVIOUS
+    c2 = *((int *) &pDrawable->x);
+    c2 -= (c2 & 0x8000) << 1;
+    upperleft = *((int *) &extents->x1) - c2;
+    lowerright = *((int *) &extents->x2) - c2 - 0x00010001;
+#endif /* !PREVIOUS */
+#ifdef BUGFIX_clip
+    ex_x1 = extents->x1 - pDrawable->x;
+    ex_y1 = extents->y1 - pDrawable->y;
+    ex_x2 = extents->x2 - pDrawable->x;
+    ex_y2 = extents->y2 - pDrawable->y;
+#endif
+#if PSZ == 24
+    xBase = pDrawable->x;
+    addr += WIDTH_MUL(pDrawable->y,nwidth);
+#else
+    addr = addr + WIDTH_MUL(pDrawable->y,nwidth) + pDrawable->x;
+#endif
+#ifdef POLYSEGMENT
+    capStyle = pGC->capStyle - CapNotLast;
+    ppt = (int *) pSegInit;
+    while (nseg--)
+#else /* POLYSEGMENT */
+#ifdef EITHER_MODE
+    mode -= CoordModePrevious;
+    if (!mode)
+#endif /* EITHER_MODE */       
+#ifndef ORIGIN
+    {  /* CoordModePrevious */
+       ppt = (int *)pptInit + 1;
+       _x1 = *x1p;
+       _y1 = *y1p;
+       extents_x1 = extents->x1 - pDrawable->x;
+       extents_x2 = extents->x2 - pDrawable->x;
+       extents_y1 = extents->y1 - pDrawable->y;
+       extents_y2 = extents->y2 - pDrawable->y;
+       if (_x1 < extents_x1 || _x1 >= extents_x2 ||
+           _y1 < extents_y1 || _y1 >= extents_y2)
+       {
+           c2 = *ppt++;
+           intToCoord(c2, _x2, _y2);
+           *x2p = _x1 + _x2;
+           *y2p = _y1 + _y2;
+           return 1;
+       }
+#if PSZ == 24
+       addrLineEnd = addr + WIDTH_MUL(_y1, nwidth);
+       xOffset = xBase + _x1;
+       addrb = (char *)addrLineEnd + xOffset * 3;
+       addrp = (PixelType *)((unsigned long)addrb & ~0x03);
+#else
+       addrp = addr + WIDTH_MUL(_y1, nwidth) + _x1;
+#endif
+       _x2 = _x1;
+       _y2 = _y1;      
+    }
+#endif /* !ORIGIN */
+#ifdef EITHER_MODE
+    else
+#endif /* EITHER_MODE */
+#ifndef PREVIOUS
+    {
+       ppt = (int *) pptInit;
+       c2 = *ppt++;
+       if (isClipped (c2, upperleft, lowerright))
+       {
+           return 1;
+       }
+#ifdef SAVE_X2Y2
+       intToCoord(c2,x2,y2);
+#endif
+#if PSZ == 24
+       addrLineEnd = addr + WIDTH_MUL(Y2, nwidth);
+       xOffset = xBase + X2;
+       addrb = (char *)addrLineEnd + xOffset * 3;
+       addrp = (PixelType *)((unsigned long)addrb & ~0x03);
+#else
+       addrp = addr + WIDTH_MUL(Y2, nwidth) + X2;
+#endif
+    }
+#endif /* !PREVIOUS */    
+    while (--npt)
+#endif /* POLYSEGMENT */
+    {
+#ifdef POLYSEGMENT
+       y1_or_e1 = ppt[0];
+       c2 = ppt[1];
+       ppt += 2;
+       if (isClipped(y1_or_e1,upperleft,lowerright)|isClipped(c2,upperleft,lowerright))
+           break;
+       intToCoord(y1_or_e1,x1_or_len,y1_or_e1);
+       /* compute now to avoid needing x1, y1 later */
+#if PSZ == 24
+       addrLineEnd = addr + WIDTH_MUL(y1_or_e1, nwidth);
+       xOffset = xBase + x1_or_len;
+       addrb = (char *)addrLineEnd + xOffset * 3;
+       addrp = (PixelType *)((unsigned long)addrb & ~0x03);
+#else
+       addrp = addr + WIDTH_MUL(y1_or_e1, nwidth) + x1_or_len;
+#endif
+#else /* !POLYSEGMENT */
+#ifdef EITHER_MODE
+       if (!mode)
+#endif /* EITHER_MODE */       
+#ifndef ORIGIN
+       {       
+           /* CoordModePrevious */
+           _x1 = _x2;
+           _y1 = _y2;
+           c2 = *ppt++;
+           intToCoord(c2, _x2, _y2);
+           _x2 = _x1 + _x2;
+           _y2 = _y1 + _y2;
+
+#ifdef BUGFIX_clip
+           if (_x2 < ex_x1 || _x2 >= ex_x2 ||
+               _y2 < ex_y1 || _y2 >= ex_y2)
+#else
+           if (_x2 < extents_x1 || _x2 >= extents_x2 ||
+               _y2 < extents_y1 || _y2 >= extents_y2)
+#endif
+           {
+               break;
+           }
+           CalcLineDeltas(_x1, _y1, _x2, _y2, x1_or_len, y1_or_e1,
+                          stepmajor, stepminor, 1, NWIDTH(nwidth), octant);
+       }
+#endif /* !ORIGIN */
+#ifdef EITHER_MODE
+       else
+#endif /* EITHER_MODE */
+#ifndef PREVIOUS
+        {
+#ifndef SAVE_X2Y2
+           y1_or_e1 = c2;
+#else
+           y1_or_e1 = y2;
+           x1_or_len = x2;
+#endif /* SAVE_X2Y2 */
+           c2 = *ppt++;
+
+           if (isClipped (c2, upperleft, lowerright))
+               break;
+#ifdef SAVE_X2Y2
+           intToCoord(c2,x2,y2);
+#endif
+           CalcLineDeltas(X1, Y1, X2, Y2, x1_or_len, y1_or_e1,
+                          stepmajor, stepminor, 1, NWIDTH(nwidth), octant);
+       }
+#endif /* !PREVIOUS */
+#endif /* POLYSEGMENT */
+
+#ifdef POLYSEGMENT
+       CalcLineDeltas(X1, Y1, X2, Y2, x1_or_len, y1_or_e1,
+                      stepmajor, stepminor, 1, NWIDTH(nwidth), octant);
+       /*
+        * although the horizontal code works for polyline, it
+        * slows down 10 pixel lines by 15%.  Thus, this
+        * code is optimized for horizontal segments and
+        * random orientation lines, which seems like a reasonable
+        * assumption
+        */
+       if (y1_or_e1 != 0)
+       {
+#endif /* POLYSEGMENT */
+       if (x1_or_len < y1_or_e1)
+       {
+#ifdef REARRANGE
+           register int        e3;
+#endif
+
+           e3 = x1_or_len;
+           x1_or_len = y1_or_e1;
+           y1_or_e1 = e3;
+
+           e3 = stepminor;
+           stepminor = stepmajor;
+           stepmajor = e3;
+           SetYMajorOctant(octant);
+       }
+
+       e = -x1_or_len;
+#ifdef POLYSEGMENT
+       if (!capStyle)
+           x1_or_len--;
+#endif
+
+       {
+#ifdef REARRANGE
+       register int e3;
+       RROP_DECLARE
+       RROP_FETCH_GCPRIV(devPriv);
+#endif
+
+       y1_or_e1 = y1_or_e1 << 1;
+       e3 = e << 1;
+
+       FIXUP_ERROR(e, octant, bias);
+
+#if PSZ == 24
+       if (stepmajor == 1  ||  stepmajor == -1){
+           stepmajor3 = stepmajor * 3;
+           stepminor3 = stepminor * sizeof (long);
+           majordx = stepmajor; minordx = 0;
+         } else {
+           stepmajor3 = stepmajor * sizeof (long);
+           stepminor3 = stepminor * 3;
+           majordx = 0; minordx = stepminor;
+         }
+#endif
+#if PSZ == 24
+#define body {\
+           body_rop \
+           addrb += stepmajor3; \
+             xOffset += majordx; \
+           e += y1_or_e1; \
+           if (e >= 0){ \
+               addrb += stepminor3; \
+                 xOffset += minordx; \
+               e += e3; \
+           } \
+       }
+#else /* PSZ == 24 */
+
+#define body {\
+           RROP_SOLID(addrp); \
+           addrp += stepmajor; \
+           e += y1_or_e1; \
+           if (e >= 0) \
+           { \
+               addrp += stepminor; \
+               e += e3; \
+            } \
+       }
+#endif /* PSZ == 24 */
+
+#ifdef LARGE_INSTRUCTION_CACHE
+
+# ifdef SERIOUS_UNROLLING
+#  define UNROLL       16
+# else
+#  define UNROLL       4
+# endif
+#define CASE(n)        case -n: body
+
+       while ((x1_or_len -= UNROLL) >= 0)
+       {
+           body body body body
+# if UNROLL >= 8
+           body body body body
+# endif
+# if UNROLL >= 12
+           body body body body
+# endif
+# if UNROLL >= 16
+           body body body body
+# endif
+       }
+       switch (x1_or_len)
+       {
+       CASE(1) CASE(2) CASE(3)
+# if UNROLL >= 8
+       CASE(4) CASE(5) CASE(6) CASE(7)
+# endif
+# if UNROLL >= 12
+       CASE(8) CASE(9) CASE(10) CASE(11)
+# endif
+# if UNROLL >= 16
+       CASE(12) CASE(13) CASE(14) CASE(15)
+# endif
+       }
+#else /* !LARGE_INSTRUCTION_CACHE */
+
+       IMPORTANT_START
+       IMPORTANT_START
+
+       if (x1_or_len & 1)
+           body
+       x1_or_len >>= 1;
+       while (x1_or_len--) {
+           body body
+       }
+
+       IMPORTANT_END
+       IMPORTANT_END
+#endif /* LARGE_INSTRUCTION_CACHE */
+
+#ifdef POLYSEGMENT
+#if PSZ == 24
+       body_rop
+#else
+       RROP_SOLID(addrp);
+#endif
+#endif
+#if PSZ == 24
+       addrp = (PixelType *)((unsigned long)addrb & ~0x03);
+#endif
+       }
+#undef body
+#ifdef POLYSEGMENT
+       }
+       else
+       {
+# ifdef REARRANGE
+           register int    e3;
+           RROP_DECLARE
+           RROP_FETCH_GCPRIV(devPriv);
+# endif /* REARRANGE */
+           if (stepmajor < 0)
+           {
+#if PSZ == 24
+               xOffset -= x1_or_len;
+               addrp = addrLineEnd + PXL2ADR(xOffset);
+#else
+               addrp -= x1_or_len;
+#endif
+               if (capStyle)
+                   x1_or_len++;
+               else
+#if PSZ == 24
+                 xOffset++;
+               addrp = addrLineEnd + PXL2ADR(xOffset);
+#else
+                   addrp++;
+#endif
+           }
+           else
+           {
+#if PSZ == 24
+               addrp = addrLineEnd + PXL2ADR(xOffset);
+#endif
+               if (capStyle)
+                   x1_or_len++;
+           }
+# if PSZ == 24
+           y1_or_e1 = xOffset & 3;
+# else
+           /* Round addrp down to the next PixelGroup boundary, and
+            * set y1_or_e1 to the excess (in pixels)
+            * (assumes PGSZB is a power of 2). */
+           y1_or_e1 = (((unsigned long) addrp) & (PGSZB - 1)) / (PSZ / 8);
+           addrp -= y1_or_e1;
+# endif /* PSZ == 24 */
+#if PSZ == 24
+           {
+#if RROP == GXcopy
+             register int nlmiddle;
+             int leftIndex = xOffset & 3;
+             int rightIndex = (xOffset + x1_or_len) & 3;
+#else
+             register int pidx;
+#endif
+
+#if RROP == GXcopy
+             nlmiddle = x1_or_len;
+             if(leftIndex){
+               nlmiddle -= (4 - leftIndex);
+             }
+             if(rightIndex){
+               nlmiddle -= rightIndex;
+             }
+             
+             nlmiddle >>= 2;
+             switch(leftIndex+x1_or_len){
+             case 4:
+               switch(leftIndex){
+               case 0:
+                 *addrp++ = piQxelXor[0];
+                 *addrp++ = piQxelXor[1];
+                 *addrp   = piQxelXor[2];
+                 break;
+               case 1:
+                 *addrp++ = ((*addrp) & 0xFFFFFF) | (piQxelXor[0] & 0xFF000000);
+                 *addrp++ = piQxelXor[1];
+                 *addrp   = piQxelXor[2];
+                 break;
+               case 2:
+                 *addrp++ =((*addrp) & 0xFFFF) | (piQxelXor[1] & 0xFFFF0000);
+                 *addrp = piQxelXor[2];
+                 break;
+               case 3:
+                 *addrp =((*addrp) & 0xFF) | (piQxelXor[2] & 0xFFFFFF00);
+                 break;
+               }
+               break;
+             case 3:
+               switch(leftIndex){
+               case 0:
+                 *addrp++ = piQxelXor[0];
+                 *addrp++ = piQxelXor[1];
+                 *addrp = ((*addrp) & 0xFFFFFF00) | (piQxelXor[2] & 0xFF);
+                 break;
+               case 1:
+                 *addrp++ = ((*addrp) & 0xFFFFFF) | (piQxelXor[0] & 0xFF000000);
+                 *addrp++ = piQxelXor[1];
+                 *addrp = ((*addrp) & 0xFFFFFF00) | (piQxelXor[2] & 0xFF);
+                 break;
+               case 2:
+                 *addrp++ =((*addrp) & 0xFFFF) | (piQxelXor[1] & 0xFFFF0000);
+                 *addrp = ((*addrp) & 0xFFFFFF00) | (piQxelXor[2] & 0xFF);
+                 break;
+               }
+               break;
+             case 2:
+               switch(leftIndex){
+/*
+               case 2:
+                 *addrp++ = ((*addrp) & 0xFFFF) | (piQxelXor[1] & 0xFFFF0000);
+                 *addrp = ((*addrp) & 0xFFFFFF00) | (piQxelXor[2] & 0xFF);
+                 break;
+*/
+               case 1:
+                 *addrp++ = ((*addrp) & 0xFFFFFF) | (piQxelXor[0] & 0xFF000000);
+                 *addrp = ((*addrp) & 0xFFFF0000) | (piQxelXor[1] & 0xFFFF);
+                 break;
+               case 0:
+                 *addrp++ =  piQxelXor[0];
+                 *addrp = ((*addrp) & 0xFFFF0000) | (piQxelXor[1] & 0xFFFF);
+                 break;
+               }
+               break;
+             case 1: /*only if leftIndex = 0 and w = 1*/
+               if(x1_or_len){
+               *addrp =  ((*addrp) & 0xFF000000) | (piQxelXor[0] & 0xFFFFFF);
+               }
+/*
+               else{
+               *addrp++ =  ((*addrp) & 0xFFFFFF) | (piQxelXor[0] & 0xFF000000);
+               *addrp =  ((*addrp) & 0xFFFF0000) | (piQxelXor[1] & 0xFFFF);
+               }
+*/
+               break;
+             case 0: /*never*/
+               break;
+             default:
+               {
+/*
+                 maskbits(y1_or_e1, x1_or_len, e, e3, x1_or_len)
+*/
+                 switch(leftIndex){
+                 case 0:
+                   break;
+                 case 1:
+                   *addrp++ = ((*addrp) & 0xFFFFFF) | (piQxelXor[0] & 0xFF000000);
+                   *addrp++ = piQxelXor[1];
+                   *addrp++ = piQxelXor[2];
+                   break;
+                 case 2:
+                   *addrp++ = ((*addrp) & 0xFFFF) | (piQxelXor[1] & 0xFFFF0000);
+                   *addrp++ = piQxelXor[2];
+                   break;
+                 case 3:
+                   *addrp++ = ((*addrp) & 0xFF) | (piQxelXor[2] & 0xFFFFFF00);
+                   break;
+                 }
+                 while(nlmiddle--){
+                   *addrp++ = piQxelXor[0];
+                   *addrp++ = piQxelXor[1];
+                   *addrp++ = piQxelXor[2];
+                 }
+                 switch(rightIndex++){
+                 case 0:
+                   break;
+                 case 1:
+                   *addrp = ((*addrp) & 0xFF000000) | (piQxelXor[0] & 0xFFFFFF);
+                   break;
+                 case 2:
+                   *addrp++ = piQxelXor[0];
+                   *addrp = ((*addrp) & 0xFFFF0000) | (piQxelXor[1] & 0xFFFF);
+                   break;
+                 case 3:
+                   *addrp++ = piQxelXor[0];
+                   *addrp++ = piQxelXor[1];
+                   *addrp = ((*addrp) & 0xFFFFFF00) | (piQxelXor[2] & 0xFF);
+                   break;
+                 }
+/*
+                 if (e3){
+                   e3 &= 0xFFFFFF;
+                   switch(rightIndex&3){
+                   case 0:
+                     *addrp = ((*addrp) & (0xFF000000 | ~e3))
+                       | (piQxelXor[0] & 0xFFFFFF & e3);
+                     break;
+                   case 1:
+                     *addrp++ = ((*addrp) & (0xFFFFFF | ~(e3<<24)))
+                                 | (piQxelXor[0] & 0xFF000000 & (e3<<24));
+                     *addrp = ((*addrp) & (0xFFFF0000|~(e3 >> 8)))
+                                 | (piQxelXor[1] & 0xFFFF & (e3 >> 8));
+                     break;
+                   case 2:
+                     *addrp++ = ((*addrp) & (0xFFFF|~(e3 << 16)))
+                                 | (piQxelXor[1] & 0xFFFF0000 & (e3 << 16));
+                     *addrp = ((*addrp) & (0xFFFFFF00|~(e3>>16)))
+                                 | (piQxelXor[2] & 0xFF & (e3 >> 16));
+                     break;
+                   case 3:
+                     *addrp++ = ((*addrp) & (0xFF|~(e3<<8)))
+                                 | (piQxelXor[2] & 0xFFFFFF00 & (e3<<8));
+                     break;
+                   }
+                 }
+*/
+               }
+             }
+#else /* GXcopy */
+             addrp = (PixelType *)((char *)addrLineEnd + ((xOffset * 3) & ~0x03));
+             if (x1_or_len <= 1){
+               if (x1_or_len)
+                 RROP_SOLID24(addrp, xOffset);
+             } else {
+               maskbits(xOffset, x1_or_len, e, e3, x1_or_len);
+               pidx = xOffset & 3;
+               if (e){
+                 RROP_SOLID_MASK(addrp, e, pidx-1);
+                 addrp++;
+                 if (pidx == 3)
+                   pidx = 0;
+               }
+               while (--x1_or_len >= 0){
+                 RROP_SOLID(addrp, pidx);
+                 addrp++;
+                 if (++pidx == 3)
+                   pidx = 0;
+               }
+               if (e3)
+                 RROP_SOLID_MASK(addrp, e3, pidx);
+             }
+#endif /* GXcopy */
+           }
+#else /* PSZ == 24 */
+           if (y1_or_e1 + x1_or_len <= PPW)
+             {
+               if (x1_or_len)
+                 {
+                   maskpartialbits(y1_or_e1, x1_or_len, e)
+                     RROP_SOLID_MASK((unsigned long *) addrp, e);
+                 }
+             }
+           else
+           {
+               maskbits(y1_or_e1, x1_or_len, e, e3, x1_or_len)
+               if (e)
+               {
+                   RROP_SOLID_MASK((unsigned long *) addrp, e);
+                   addrp += PPW;
+               }
+#if 0
+               RROP_SPAN_lu(addrp, x1_or_len)
+#else
+               RROP_SPAN(addrp, x1_or_len)
+#endif
+               if (e3)
+#if 0
+                   RROP_SOLID_MASK_lu((unsigned long *) addrp, e3);
+#else
+                   RROP_SOLID_MASK((unsigned long *) addrp, e3);
+#endif
+           }
+#endif /* PSZ == 24 */
+       }
+#endif /* POLYSEGMENT */
+    }
+#ifdef POLYSEGMENT
+    if (nseg >= 0)
+       return (xSegment *) ppt - pSegInit;
+#else
+    if (npt)
+    {
+#ifdef EITHER_MODE
+       if (!mode)
+#endif /* EITHER_MODE */
+#ifndef ORIGIN
+       {
+           *x1p = _x1;
+           *y1p = _y1;         
+           *x2p = _x2;
+           *y2p = _y2;
+       }
+#endif /* !ORIGIN */       
+       return ((DDXPointPtr) ppt - pptInit) - 1;
+    }
+#endif /* POLYSEGMENT */
+
+#ifndef POLYSEGMENT
+# ifndef ORIGIN
+#  define C2  c2
+# else
+#  define C2  ppt[-1]
+# endif
+#ifdef EITHER_MODE
+    if (pGC->capStyle != CapNotLast &&
+       ((mode ? (C2 != *((int *) pptInitOrig))
+              : ((_x2 != pptInitOrig->x) ||
+                 (_y2 != pptInitOrig->y)))
+        || (ppt == ((int *)pptInitOrig) + 2)))
+#endif /* EITHER_MODE */
+#ifdef PREVIOUS
+    if (pGC->capStyle != CapNotLast &&
+       ((_x2 != pptInitOrig->x) ||
+        (_y2 != pptInitOrig->y) ||
+        (ppt == ((int *)pptInitOrig) + 2)))
+#endif /* PREVIOUS */
+#ifdef ORIGIN
+    if (pGC->capStyle != CapNotLast &&
+       ((C2 != *((int *) pptInitOrig)) ||
+        (ppt == ((int *)pptInitOrig) + 2)))
+#endif /* !PREVIOUS */
+    {
+# ifdef REARRANGE
+       RROP_DECLARE
+
+       RROP_FETCH_GCPRIV(devPriv);
+# endif
+#if PSZ == 24
+#if RROP == GXcopy
+           switch(xOffset & 3){
+           case 0:
+             *addrp = ((*addrp)&0xFF000000)|(piQxelXor[0] & 0xFFFFFF);
+             break;
+           case 3:
+             *addrp = ((*addrp)&0xFF)|(piQxelXor[2] & 0xFFFFFF00);
+             break;
+           case 1:
+             *addrp = ((*addrp)&0xFFFFFF)|(piQxelXor[0] & 0xFF000000);
+             *(addrp+1) = ((*(addrp+1))&0xFFFF0000)|(piQxelXor[1] & 0xFFFF);
+             break;
+           case 2:
+             *addrp = ((*addrp)&0xFFFF)|(piQxelXor[1] & 0xFFFF0000);
+             *(addrp+1) = ((*(addrp+1))&0xFFFFFF00)|(piQxelXor[2] & 0xFF);
+             break;
+           }
+#endif
+#if RROP == GXxor
+           switch(xOffset & 3){
+           case 0:
+             *addrp ^= (piQxelXor[0] & 0xFFFFFF);
+             break;
+           case 3:
+             *addrp ^= (piQxelXor[2] & 0xFFFFFF00);
+             break;
+           case 1:
+             *addrp ^= (piQxelXor[0] & 0xFF000000);
+             *(addrp+1) ^= (piQxelXor[1] & 0xFFFF);
+             break;
+           case 2:
+             *addrp ^= (piQxelXor[1] & 0xFFFF0000);
+             *(addrp+1) ^= (piQxelXor[2] & 0xFF);
+             break;
+           }
+#endif
+#if RROP == GXand
+           switch(xOffset & 3){
+           case 0:
+             *addrp &= (piQxelAnd[0] | 0xFF000000);
+             break;
+           case 3:
+             *addrp &= (piQxelAnd[2] | 0xFF);
+             break;
+           case 1:
+             *addrp &= (0xFFFFFF|piQxelAnd[0]);
+             *(addrp+1) &= (0xFFFF0000|piQxelAnd[1]);
+             break;
+           case 2:
+             *addrp &= (0xFFFF|piQxelAnd[1]);
+             *(addrp+1) &= (0xFFFFFF00|piQxelAnd[2]);
+             break;
+           }
+#endif
+#if RROP == GXor
+           switch(xOffset & 3){
+           case 0:
+             *addrp |= (piQxelOr[0] & 0xFFFFFF);
+             break;
+           case 3:
+             *addrp |= (piQxelOr[2] & 0xFFFFFF00);
+             break;
+           case 1:
+             *addrp |= (piQxelOr[0] & 0xFF000000);
+             *(addrp+1) |= (piQxelOr[1] & 0xFFFF);
+             break;
+           case 2:
+             *addrp |= (piQxelOr[1] & 0xFFFF0000);
+             *(addrp+1) |= (piQxelOr[2] & 0xFF);
+             break;
+           }
+#endif
+#if RROP == GXset
+           switch(xOffset & 3){
+           case 0:
+             *addrp = (((*addrp)&(piQxelAnd[0] |0xFF000000))^(piQxelXor[0] & 0xFFFFFF));
+             break;
+           case 3:
+             *addrp = (((*addrp)&(piQxelAnd[2]|0xFF))^(piQxelXor[2] & 0xFFFFFF00));
+             break;
+           case 1:
+             *addrp = (((*addrp)&(piQxelAnd[0]|0xFFFFFF))^(piQxelXor[0] & 0xFF000000));
+             *(addrp+1) = (((*(addrp+1))&(piQxelAnd[1]|0xFFFF0000))^(piQxelXor[1] & 0xFFFF));
+             break;
+           case 2:
+             *addrp = (((*addrp)&(piQxelAnd[1]|0xFFFF))^(piQxelXor[1] & 0xFFFF0000));
+             *(addrp+1) = (((*(addrp+1))&(piQxelAnd[2]|0xFFFFFF00))^(piQxelXor[2] & 0xFF));
+             break;
+           } 
+#endif
+#else
+       RROP_SOLID (addrp);
+# endif
+    }
+#endif /* !POLYSEGMENT */
+    return -1;
+}
+
+#endif /* INCLUDE_DRAW */
+
+
+#ifdef INCLUDE_OTHERS
+
+#ifdef POLYSEGMENT
+
+void
+cfb8SegmentSS1Rect (pDrawable, pGC, nseg, pSegInit)
+    DrawablePtr            pDrawable;
+    GCPtr          pGC;
+    int                    nseg;
+    xSegment       *pSegInit;
+{
+    int            (*func)();
+    void    (*clip)();
+    int            drawn;
+    cfbPrivGCPtr    devPriv;
+
+    devPriv = cfbGetGCPrivate(pGC);
+#ifdef NO_ONE_RECT
+    if (REGION_NUM_RECTS(devPriv->pCompositeClip) != 1)
+    {
+       cfbSegmentSS(pDrawable, pGC, nseg, pSegInit);
+       return;
+    }
+#endif
+    switch (devPriv->rop)
+    {
+    case GXcopy:
+       func = cfb8SegmentSS1RectCopy;
+       clip = cfb8ClippedLineCopy;
+#ifdef FAST_MUL
+       if (cfbGetPixelWidth (pDrawable) == WIDTH_FAST)
+           func = cfb8SegmentSS1RectShiftCopy;
+#endif
+       break;
+    case GXxor:
+       func = cfb8SegmentSS1RectXor;
+       clip = cfb8ClippedLineXor;
+       break;
+    default:
+       func = cfb8SegmentSS1RectGeneral;
+       clip = cfb8ClippedLineGeneral;
+       break;
+    }
+    while (nseg)
+    {
+       drawn = (*func) (pDrawable, pGC, nseg, pSegInit);
+       if (drawn == -1)
+           break;
+       (*clip) (pDrawable, pGC,
+                        pSegInit[drawn-1].x1, pSegInit[drawn-1].y1,
+                        pSegInit[drawn-1].x2, pSegInit[drawn-1].y2,
+                        &devPriv->pCompositeClip->extents,
+                        pGC->capStyle == CapNotLast);
+       pSegInit += drawn;
+       nseg -= drawn;
+    }
+}
+
+#else /* POLYSEGMENT */
+
+void
+cfb8LineSS1Rect (pDrawable, pGC, mode, npt, pptInit)
+    DrawablePtr        pDrawable;
+    GCPtr      pGC;
+    int                mode;
+    int                npt;
+    DDXPointPtr        pptInit;
+{
+    int            (*func)();
+    void    (*clip)();
+    int            drawn;
+    cfbPrivGCPtr    devPriv;
+    int x1, y1, x2, y2;
+    DDXPointPtr pptInitOrig = pptInit;
+
+    devPriv = cfbGetGCPrivate(pGC);
+#ifdef NO_ONE_RECT
+    if (REGION_NUM_RECTS(devPriv->pCompositeClip) != 1)
+    {
+       cfbLineSS(pDrawable, pGC, mode, npt, pptInit);
+       return;
+    }
+#endif
+    switch (devPriv->rop)
+    {
+    case GXcopy:
+       func = cfb8LineSS1RectCopy;
+       clip = cfb8ClippedLineCopy;
+       if (mode == CoordModePrevious)
+           func = cfb8LineSS1RectPreviousCopy;
+       break;
+    case GXxor:
+       func = cfb8LineSS1RectXor;
+       clip = cfb8ClippedLineXor;
+       break;
+    default:
+       func = cfb8LineSS1RectGeneral;
+       clip = cfb8ClippedLineGeneral;
+       break;
+    }
+    if (mode == CoordModePrevious)
+    {
+       x1 = pptInit->x;
+       y1 = pptInit->y;
+       while (npt > 1)
+       {
+           drawn = (*func) (pDrawable, pGC, mode, npt, pptInit, pptInitOrig,
+                            &x1, &y1, &x2, &y2);
+           if (drawn == -1)
+               break;
+           (*clip) (pDrawable, pGC, x1, y1, x2, y2,
+                    &devPriv->pCompositeClip->extents,
+                    drawn != npt - 1 || pGC->capStyle == CapNotLast);
+           pptInit += drawn;
+           npt -= drawn;
+           x1 = x2;
+           y1 = y2;
+       }
+    }
+    else
+    {
+       while (npt > 1)
+       {
+           drawn = (*func) (pDrawable, pGC, mode, npt, pptInit, pptInitOrig,
+                            &x1, &y1, &x2, &y2);
+           if (drawn == -1)
+               break;
+           (*clip) (pDrawable, pGC,
+                    pptInit[drawn-1].x, pptInit[drawn-1].y,
+                    pptInit[drawn].x, pptInit[drawn].y,
+                    &devPriv->pCompositeClip->extents,
+                    drawn != npt - 1 || pGC->capStyle == CapNotLast);
+           pptInit += drawn;
+           npt -= drawn;
+       }
+    }
+}
+
+#endif /* else POLYSEGMENT */
+#endif /* INCLUDE_OTHERS */
+
+#if !defined(POLYSEGMENT) && !defined (PREVIOUS)
+
+void
+RROP_NAME (cfb8ClippedLine) (pDrawable, pGC, x1, y1, x2, y2, boxp, shorten)
+    DrawablePtr        pDrawable;
+    GCPtr      pGC;
+    int                x1, y1, x2, y2;
+    BoxPtr     boxp;
+    Bool       shorten;
+{
+    int                    oc1, oc2;
+    int                    e, e1, e3, len;
+    int                    adx, ady;
+
+    PixelType      *addr;
+    int                    nwidth;
+    int                    stepx, stepy;
+    int                    xorg, yorg;
+    int             new_x1, new_y1, new_x2, new_y2;
+    Bool           pt1_clipped, pt2_clipped;
+    int                    changex, changey, result;
+#if PSZ == 24
+    int xOffset;
+    PixelType   *addrLineEnd;
+    char *addrb;
+    int stepx3, stepy3;
+#endif
+    int                    octant;
+    unsigned int    bias = miGetZeroLineBias(pDrawable->pScreen);
+
+    cfbGetPixelWidthAndPointer(pDrawable, nwidth, addr);
+
+    xorg = pDrawable->x;
+    yorg = pDrawable->y;
+    x1 += xorg;
+    y1 += yorg;
+    x2 += xorg;
+    y2 += yorg;
+    oc1 = 0;
+    oc2 = 0;
+    OUTCODES (oc1, x1, y1, boxp);
+    OUTCODES (oc2, x2, y2, boxp);
+
+    if (oc1 & oc2)
+       return;
+
+    CalcLineDeltas(x1, y1, x2, y2, adx, ady, stepx, stepy, 1, nwidth, octant);
+
+    if (adx <= ady)
+    {
+       int     t;
+
+       t = adx;
+       adx = ady;
+       ady = t;
+
+       t = stepx;
+       stepx = stepy;
+       stepy = t;
+       
+       SetYMajorOctant(octant);
+    }
+    e = - adx;
+    e1 = ady << 1;
+    e3 = - (adx << 1);
+
+    FIXUP_ERROR(e, octant, bias);
+
+    new_x1 = x1;
+    new_y1 = y1;
+    new_x2 = x2;
+    new_y2 = y2;
+    pt1_clipped = 0;
+    pt2_clipped = 0;
+
+    if (IsXMajorOctant(octant))
+    {
+       result = miZeroClipLine(boxp->x1, boxp->y1, boxp->x2 - 1, boxp->y2 - 1,
+                               &new_x1, &new_y1, &new_x2, &new_y2,
+                               adx, ady,
+                               &pt1_clipped, &pt2_clipped,
+                               octant, bias, oc1, oc2);
+       if (result == -1)
+           return;
+       
+       len = abs(new_x2 - new_x1) - 1; /* this routine needs the "-1" */
+       
+       /* if we've clipped the endpoint, always draw the full length
+        * of the segment, because then the capstyle doesn't matter 
+        * if x2,y2 isn't clipped, use the capstyle
+        * (shorten == TRUE <--> CapNotLast)
+        */
+       if (pt2_clipped || !shorten)
+           len++;
+       
+       if (pt1_clipped)
+       {
+           /* must calculate new error terms */
+           changex = abs(new_x1 - x1);
+           changey = abs(new_y1 - y1);
+           e = e + changey * e3 + changex * e1;            
+       }
+    }
+    else /* Y_AXIS */
+    {
+       result = miZeroClipLine(boxp->x1, boxp->y1, boxp->x2 - 1, boxp->y2 - 1,
+                               &new_x1, &new_y1, &new_x2, &new_y2,
+                               ady, adx,
+                               &pt1_clipped, &pt2_clipped,
+                               octant, bias, oc1, oc2);
+       if (result == -1)
+           return;
+       
+       len = abs(new_y2 - new_y1) - 1; /* this routine needs the "-1" */
+       
+       /* if we've clipped the endpoint, always draw the full length
+        * of the segment, because then the capstyle doesn't matter 
+        * if x2,y2 isn't clipped, use the capstyle
+        * (shorten == TRUE <--> CapNotLast)
+        */
+       if (pt2_clipped || !shorten)
+           len++;
+       
+       if (pt1_clipped)
+       {
+           /* must calculate new error terms */
+           changex = abs(new_x1 - x1);
+           changey = abs(new_y1 - y1);
+           e = e + changex * e3 + changey * e1;
+       }
+    }
+    x1 = new_x1;
+    y1 = new_y1;
+    {
+    register PixelType *addrp;
+    RROP_DECLARE
+
+    RROP_FETCH_GC(pGC);
+
+#if PSZ == 24
+    xOffset = x1;
+    addrLineEnd = addr + (y1 * nwidth);
+    addrb = (char *)addrLineEnd + x1 * 3;
+    if (stepx == 1  ||  stepx == -1){
+      stepx3 = stepx * 3;
+      stepy3 = stepy * sizeof (long);
+    } else {
+      stepx3 = stepx * sizeof (long);
+      stepy3 = stepy * 3;
+    }
+#else
+    addrp = addr + (y1 * nwidth) + x1;
+#endif
+
+#ifndef REARRANGE
+    if (!ady)
+    {
+#if PSZ == 24
+#define body {\
+           body_rop \
+           addrb += stepx3; \
+       }
+#else
+#define body   { RROP_SOLID(addrp); addrp += stepx; }
+#endif
+       while (len >= PGSZB)
+       {
+           body body body body
+#if PGSZ == 64
+           body body body body
+#endif
+           len -= PGSZB;
+       }
+       switch (len)
+       {
+#if PGSZ == 64
+       case  7: body case 6: body case 5: body case 4: body
+#endif
+       case  3: body case 2: body case 1: body
+       }
+#undef body
+    }
+    else
+#endif /* !REARRANGE */
+    {
+#if PSZ == 24
+#define body {\
+           body_rop \
+           addrb += stepx3; \
+           e += e1; \
+           if (e >= 0) \
+           { \
+               addrb += stepy3; \
+               e += e3; \
+           } \
+       }
+#else
+#define body {\
+           RROP_SOLID(addrp); \
+           addrp += stepx; \
+           e += e1; \
+           if (e >= 0) \
+           { \
+               addrp += stepy; \
+               e += e3; \
+            } \
+       }
+#endif
+
+#ifdef LARGE_INSTRUCTION_CACHE
+       while ((len -= PGSZB) >= 0)
+       {
+           body body body body
+#if PGSZ == 64
+           body body body body
+#endif
+       }
+       switch (len)
+       {
+       case  -1: body case -2: body case -3: body
+#if PGSZ == 64
+       case  -4: body case -5: body case -6: body case -7: body
+#endif
+       }
+#else /* !LARGE_INSTRUCTION_CACHE */
+       IMPORTANT_START;
+
+       while ((len -= 2) >= 0)
+       {
+           body body;
+       }
+       if (len & 1)
+           body;
+
+       IMPORTANT_END;
+#endif /* LARGE_INSTRUCTION_CACHE */
+    }
+#if PSZ == 24
+    body_rop
+#else
+    RROP_SOLID(addrp);
+#endif
+#undef body
+    }
+}
+
+#endif /* !POLYSEGMENT && !PREVIOUS */
+#endif /* PIXEL_ADDR */
diff --git a/Xserver/programs/Xserver/cfb/cfballpriv.c b/Xserver/programs/Xserver/cfb/cfballpriv.c
new file mode 100644 (file)
index 0000000..0ad48b0
--- /dev/null
@@ -0,0 +1,85 @@
+/*
+ * $XConsortium: cfballpriv.c,v 1.5 94/04/17 20:28:42 dpw Exp $
+ *
+Copyright (c) 1991  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+ *
+ * Author:  Keith Packard, MIT X Consortium
+ */
+
+#include "X.h"
+#include "Xmd.h"
+#include "servermd.h"
+#include "scrnintstr.h"
+#include "pixmapstr.h"
+#include "resource.h"
+#include "colormap.h"
+#include "colormapst.h"
+#include "cfb.h"
+#include "mi.h"
+#include "mistruct.h"
+#include "dix.h"
+#include "cfbmskbits.h"
+#include "mibstore.h"
+
+int cfbWindowPrivateIndex;
+int cfbGCPrivateIndex;
+#ifdef CFB_NEED_SCREEN_PRIVATE
+int cfbScreenPrivateIndex;
+#endif
+
+extern RegionPtr (*cfbPuntCopyPlane)();
+
+Bool
+cfbAllocatePrivates(pScreen, window_index, gc_index)
+    ScreenPtr  pScreen;
+    int                *window_index, *gc_index;
+{
+    if (!window_index || !gc_index ||
+       *window_index == -1 && *gc_index == -1)
+    {
+       if (!mfbAllocatePrivates(pScreen,
+                                &cfbWindowPrivateIndex, &cfbGCPrivateIndex))
+           return FALSE;
+       if (window_index)
+           *window_index = cfbWindowPrivateIndex;
+       if (gc_index)
+           *gc_index = cfbGCPrivateIndex;
+    }
+    else
+    {
+       cfbWindowPrivateIndex = *window_index;
+       cfbGCPrivateIndex = *gc_index;
+    }
+    if (!AllocateWindowPrivate(pScreen, cfbWindowPrivateIndex,
+                              sizeof(cfbPrivWin)) ||
+       !AllocateGCPrivate(pScreen, cfbGCPrivateIndex, sizeof(cfbPrivGC)))
+       return FALSE;
+    cfbPuntCopyPlane = miCopyPlane;
+#ifdef CFB_NEED_SCREEN_PRIVATE
+    cfbScreenPrivateIndex = AllocateScreenPrivateIndex ();
+    if (cfbScreenPrivateIndex == -1)
+       return FALSE;
+#endif
+    return TRUE;
+}
diff --git a/Xserver/programs/Xserver/cfb/cfbbitblt.c b/Xserver/programs/Xserver/cfb/cfbbitblt.c
new file mode 100644 (file)
index 0000000..cc78882
--- /dev/null
@@ -0,0 +1,760 @@
+/*
+ * cfb copy area
+ */
+
+/*
+
+Copyright (c) 1989  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+Author: Keith Packard
+
+*/
+/* $XConsortium: cfbbitblt.c,v 5.51 94/05/27 11:00:56 dpw Exp $ */
+
+#include       "X.h"
+#include       "Xmd.h"
+#include       "Xproto.h"
+#include       "gcstruct.h"
+#include       "windowstr.h"
+#include       "scrnintstr.h"
+#include       "pixmapstr.h"
+#include       "regionstr.h"
+#include       "cfb.h"
+#include       "cfbmskbits.h"
+#include       "cfb8bit.h"
+#include       "fastblt.h"
+#define MFB_CONSTS_ONLY
+#include       "maskbits.h"
+
+RegionPtr
+cfbBitBlt (pSrcDrawable, pDstDrawable,
+            pGC, srcx, srcy, width, height, dstx, dsty, doBitBlt, bitPlane)
+    register DrawablePtr pSrcDrawable;
+    register DrawablePtr pDstDrawable;
+    GC *pGC;
+    int srcx, srcy;
+    int width, height;
+    int dstx, dsty;
+    void (*doBitBlt)();
+    unsigned long bitPlane;
+{
+    RegionPtr prgnSrcClip;     /* may be a new region, or just a copy */
+    Bool freeSrcClip = FALSE;
+
+    RegionPtr prgnExposed;
+    RegionRec rgnDst;
+    DDXPointPtr pptSrc;
+    register DDXPointPtr ppt;
+    register BoxPtr pbox;
+    int i;
+    register int dx;
+    register int dy;
+    xRectangle origSource;
+    DDXPointRec origDest;
+    int numRects;
+    BoxRec fastBox;
+    int fastClip = 0;          /* for fast clipping with pixmap source */
+    int fastExpose = 0;                /* for fast exposures with pixmap source */
+
+    origSource.x = srcx;
+    origSource.y = srcy;
+    origSource.width = width;
+    origSource.height = height;
+    origDest.x = dstx;
+    origDest.y = dsty;
+
+    if ((pSrcDrawable != pDstDrawable) &&
+       pSrcDrawable->pScreen->SourceValidate)
+    {
+       (*pSrcDrawable->pScreen->SourceValidate) (pSrcDrawable, srcx, srcy, width, height);
+    }
+
+    srcx += pSrcDrawable->x;
+    srcy += pSrcDrawable->y;
+
+    /* clip the source */
+
+    if (pSrcDrawable->type == DRAWABLE_PIXMAP)
+    {
+       if ((pSrcDrawable == pDstDrawable) &&
+           (pGC->clientClipType == CT_NONE))
+       {
+           prgnSrcClip = cfbGetCompositeClip(pGC);
+       }
+       else
+       {
+           fastClip = 1;
+       }
+    }
+    else
+    {
+       if (pGC->subWindowMode == IncludeInferiors)
+       {
+           if (!((WindowPtr) pSrcDrawable)->parent)
+           {
+               /*
+                * special case bitblt from root window in
+                * IncludeInferiors mode; just like from a pixmap
+                */
+               fastClip = 1;
+           }
+           else if ((pSrcDrawable == pDstDrawable) &&
+               (pGC->clientClipType == CT_NONE))
+           {
+               prgnSrcClip = cfbGetCompositeClip(pGC);
+           }
+           else
+           {
+               prgnSrcClip = NotClippedByChildren((WindowPtr)pSrcDrawable);
+               freeSrcClip = TRUE;
+           }
+       }
+       else
+       {
+           prgnSrcClip = &((WindowPtr)pSrcDrawable)->clipList;
+       }
+    }
+
+    fastBox.x1 = srcx;
+    fastBox.y1 = srcy;
+    fastBox.x2 = srcx + width;
+    fastBox.y2 = srcy + height;
+
+    /* Don't create a source region if we are doing a fast clip */
+    if (fastClip)
+    {
+       fastExpose = 1;
+       /*
+        * clip the source; if regions extend beyond the source size,
+        * make sure exposure events get sent
+        */
+       if (fastBox.x1 < pSrcDrawable->x)
+       {
+           fastBox.x1 = pSrcDrawable->x;
+           fastExpose = 0;
+       }
+       if (fastBox.y1 < pSrcDrawable->y)
+       {
+           fastBox.y1 = pSrcDrawable->y;
+           fastExpose = 0;
+       }
+       if (fastBox.x2 > pSrcDrawable->x + (int) pSrcDrawable->width)
+       {
+           fastBox.x2 = pSrcDrawable->x + (int) pSrcDrawable->width;
+           fastExpose = 0;
+       }
+       if (fastBox.y2 > pSrcDrawable->y + (int) pSrcDrawable->height)
+       {
+           fastBox.y2 = pSrcDrawable->y + (int) pSrcDrawable->height;
+           fastExpose = 0;
+       }
+    }
+    else
+    {
+       REGION_INIT(pGC->pScreen, &rgnDst, &fastBox, 1);
+       REGION_INTERSECT(pGC->pScreen, &rgnDst, &rgnDst, prgnSrcClip);
+    }
+
+    dstx += pDstDrawable->x;
+    dsty += pDstDrawable->y;
+
+    if (pDstDrawable->type == DRAWABLE_WINDOW)
+    {
+       if (!((WindowPtr)pDstDrawable)->realized)
+       {
+           if (!fastClip)
+               REGION_UNINIT(pGC->pScreen, &rgnDst);
+           if (freeSrcClip)
+               REGION_DESTROY(pGC->pScreen, prgnSrcClip);
+           return NULL;
+       }
+    }
+
+    dx = srcx - dstx;
+    dy = srcy - dsty;
+
+    /* Translate and clip the dst to the destination composite clip */
+    if (fastClip)
+    {
+       RegionPtr cclip;
+
+        /* Translate the region directly */
+        fastBox.x1 -= dx;
+        fastBox.x2 -= dx;
+        fastBox.y1 -= dy;
+        fastBox.y2 -= dy;
+
+       /* If the destination composite clip is one rectangle we can
+          do the clip directly.  Otherwise we have to create a full
+          blown region and call intersect */
+
+       /* XXX because CopyPlane uses this routine for 8-to-1 bit
+        * copies, this next line *must* also correctly fetch the
+        * composite clip from an mfb gc
+        */
+
+       cclip = cfbGetCompositeClip(pGC);
+        if (REGION_NUM_RECTS(cclip) == 1)
+        {
+           BoxPtr pBox = REGION_RECTS(cclip);
+
+           if (fastBox.x1 < pBox->x1) fastBox.x1 = pBox->x1;
+           if (fastBox.x2 > pBox->x2) fastBox.x2 = pBox->x2;
+           if (fastBox.y1 < pBox->y1) fastBox.y1 = pBox->y1;
+           if (fastBox.y2 > pBox->y2) fastBox.y2 = pBox->y2;
+
+           /* Check to see if the region is empty */
+           if (fastBox.x1 >= fastBox.x2 || fastBox.y1 >= fastBox.y2)
+           {
+               REGION_INIT(pGC->pScreen, &rgnDst, NullBox, 0);
+           }
+           else
+           {
+               REGION_INIT(pGC->pScreen, &rgnDst, &fastBox, 1);
+           }
+       }
+        else
+       {
+           /* We must turn off fastClip now, since we must create
+              a full blown region.  It is intersected with the
+              composite clip below. */
+           fastClip = 0;
+           REGION_INIT(pGC->pScreen, &rgnDst, &fastBox,1);
+       }
+    }
+    else
+    {
+        REGION_TRANSLATE(pGC->pScreen, &rgnDst, -dx, -dy);
+    }
+
+    if (!fastClip)
+    {
+       REGION_INTERSECT(pGC->pScreen, &rgnDst,
+                                  &rgnDst,
+                                  cfbGetCompositeClip(pGC));
+    }
+
+    /* Do bit blitting */
+    numRects = REGION_NUM_RECTS(&rgnDst);
+    if (numRects && width && height)
+    {
+       if(!(pptSrc = (DDXPointPtr)ALLOCATE_LOCAL(numRects *
+                                                 sizeof(DDXPointRec))))
+       {
+           REGION_UNINIT(pGC->pScreen, &rgnDst);
+           if (freeSrcClip)
+               REGION_DESTROY(pGC->pScreen, prgnSrcClip);
+           return NULL;
+       }
+       pbox = REGION_RECTS(&rgnDst);
+       ppt = pptSrc;
+       for (i = numRects; --i >= 0; pbox++, ppt++)
+       {
+           ppt->x = pbox->x1 + dx;
+           ppt->y = pbox->y1 + dy;
+       }
+
+       (*doBitBlt) (pSrcDrawable, pDstDrawable, pGC->alu, &rgnDst, pptSrc, pGC->planemask, bitPlane);
+       DEALLOCATE_LOCAL(pptSrc);
+    }
+
+    prgnExposed = NULL;
+    if ( cfbGetGCPrivate(pGC)->fExpose)
+    {
+       extern RegionPtr    miHandleExposures();
+
+        /* Pixmap sources generate a NoExposed (we return NULL to do this) */
+        if (!fastExpose)
+           prgnExposed =
+               miHandleExposures(pSrcDrawable, pDstDrawable, pGC,
+                                 origSource.x, origSource.y,
+                                 (int)origSource.width,
+                                 (int)origSource.height,
+                                 origDest.x, origDest.y, bitPlane);
+    }
+    REGION_UNINIT(pGC->pScreen, &rgnDst);
+    if (freeSrcClip)
+       REGION_DESTROY(pGC->pScreen, prgnSrcClip);
+    return prgnExposed;
+}
+
+
+void
+cfbDoBitblt (pSrc, pDst, alu, prgnDst, pptSrc, planemask)
+    DrawablePtr            pSrc, pDst;
+    int                    alu;
+    RegionPtr      prgnDst;
+    DDXPointPtr            pptSrc;
+    unsigned long   planemask;
+{
+    void (*blt)() = cfbDoBitbltGeneral;
+    if ((planemask & PMSK) == PMSK) {
+       switch (alu) {
+       case GXcopy:
+           blt = cfbDoBitbltCopy;
+           break;
+       case GXxor:
+           blt = cfbDoBitbltXor;
+           break;
+       case GXor:
+           blt = cfbDoBitbltOr;
+           break;
+       }
+    }
+    (*blt) (pSrc, pDst, alu, prgnDst, pptSrc, planemask);
+}
+
+RegionPtr
+cfbCopyArea(pSrcDrawable, pDstDrawable,
+            pGC, srcx, srcy, width, height, dstx, dsty)
+    register DrawablePtr pSrcDrawable;
+    register DrawablePtr pDstDrawable;
+    GC *pGC;
+    int srcx, srcy;
+    int width, height;
+    int dstx, dsty;
+{
+    void (*doBitBlt) ();
+    
+    doBitBlt = cfbDoBitbltCopy;
+    if (pGC->alu != GXcopy || (pGC->planemask & PMSK) != PMSK)
+    {
+       doBitBlt = cfbDoBitbltGeneral;
+       if ((pGC->planemask & PMSK) == PMSK)
+       {
+           switch (pGC->alu) {
+           case GXxor:
+               doBitBlt = cfbDoBitbltXor;
+               break;
+           case GXor:
+               doBitBlt = cfbDoBitbltOr;
+               break;
+           }
+       }
+    }
+    return cfbBitBlt (pSrcDrawable, pDstDrawable,
+            pGC, srcx, srcy, width, height, dstx, dsty, doBitBlt, 0L);
+}
+
+#if PSZ == 8
+void
+cfbCopyPlane1to8 (pSrcDrawable, pDstDrawable, rop, prgnDst, pptSrc, planemask, bitPlane)
+    DrawablePtr pSrcDrawable;  /* must be a bitmap */
+    DrawablePtr pDstDrawable;  /* must be depth 8 drawable */
+    int        rop;            /* not used; caller must call cfb8CheckOpaqueStipple
+                        * beforehand to get cfb8StippleRRop set correctly */
+    unsigned long planemask;   /* to apply to destination writes */
+    RegionPtr prgnDst;         /* region in destination to draw to;
+                                * screen relative coords. if dest is a window;
+                                * drawable relative if dest is a pixmap */
+    DDXPointPtr pptSrc;                /* drawable relative src coords to copy from;
+                                * must be one point for each box in prgnDst */
+    unsigned long   bitPlane;  /* not used; assumed always to be 1 */
+{
+    int        srcx, srcy;     /* upper left corner of box being copied in source */
+    int dstx, dsty;    /* upper left corner of box being copied in dest */
+    int width, height; /* in pixels, unpadded, of box being copied */
+    int xoffSrc; /* bit # in leftmost word of row from which copying starts */
+    int xoffDst; /* byte # in leftmost word of row from which copying starts */
+    unsigned long *psrcBase, *pdstBase; /* start of drawable's pixel data */
+    int        widthSrc;    /* # of groups of 32 pixels (1 bit/pixel) in src bitmap*/
+    int widthDst;    /* # of groups of 4 pixels (8 bits/pixel) in dst */
+    unsigned long *psrcLine, *pdstLine; /* steps a row at a time thru src/dst; 
+                                        * may point into middle of row */
+    register unsigned long *psrc, *pdst; /* steps within the row */
+    register unsigned long bits, tmp;   /* bits from source */
+    register int leftShift;
+    register int rightShift;
+    unsigned long startmask;           /* left edge pixel mask */
+    unsigned long endmask;             /* right edge pixel mask */
+    register int nlMiddle;   /* number of words in middle of the row to draw */
+    register int nl;
+    int firstoff;
+    int secondoff;
+    unsigned long src;
+    int nbox;          /* number of boxes in region to copy */
+    BoxPtr  pbox;      /* steps thru boxes in region */
+    int pixelsRemainingOnRightEdge; /* # pixels to be drawn on a row after
+                                    * the main "middle" loop */
+
+    cfbGetLongWidthAndPointer (pSrcDrawable, widthSrc, psrcBase)
+    cfbGetLongWidthAndPointer (pDstDrawable, widthDst, pdstBase)
+
+    nbox = REGION_NUM_RECTS(prgnDst);
+    pbox = REGION_RECTS(prgnDst);
+    while (nbox--)
+    {
+       dstx = pbox->x1;
+       dsty = pbox->y1;
+       srcx = pptSrc->x;
+       srcy = pptSrc->y;
+       width = pbox->x2 - pbox->x1;
+       height = pbox->y2 - pbox->y1;
+       pbox++;
+       pptSrc++;
+
+       psrcLine = psrcBase + srcy * widthSrc + (srcx >> MFB_PWSH);
+       pdstLine = pdstBase + dsty * widthDst + (dstx >> PWSH);
+       xoffSrc = srcx & MFB_PIM; /* finds starting bit in src */
+       xoffDst = dstx & PIM;  /* finds starting byte in dst */
+
+       /* compute startmask, endmask, nlMiddle */
+
+       if (xoffDst + width < PPW) /* XXX should this be '<= PPW' ? */
+       { /* the copy only affects one word per row in destination */
+           maskpartialbits(dstx, width, startmask);
+           endmask = 0;  /* nothing on right edge */
+           nlMiddle = 0; /* nothing in middle */
+       }
+       else
+       { /* the copy will affect multiple words per row in destination */
+           maskbits(dstx, width, startmask, endmask, nlMiddle);
+       }
+
+       /*
+        * compute constants for the first four bits to be
+        * copied.  This avoids troubles with partial first
+        * writes, and difficult shift computation
+        */
+       if (startmask)
+       {
+           firstoff = xoffSrc - xoffDst;
+           if (firstoff > (MFB_PPW-PPW))
+               secondoff = MFB_PPW - firstoff;
+           if (xoffDst)
+           {
+               srcx += (PPW-xoffDst);
+               xoffSrc = srcx & MFB_PIM;
+           }
+       }
+       leftShift = xoffSrc;
+       rightShift = MFB_PPW - leftShift;
+
+       pixelsRemainingOnRightEdge = (nlMiddle & 7) * PPW +
+                                       ((dstx + width) & PIM);
+
+       /* setup is done; now let's move some bits */
+
+       /* caller must call cfb8CheckOpaqueStipple before this function
+        * to set cfb8StippleRRop!
+        */
+
+       if (cfb8StippleRRop == GXcopy)
+       {
+           while (height--)
+           { /* one iteration of this loop copies one row */
+               psrc = psrcLine;
+               pdst = pdstLine;
+               psrcLine += widthSrc;
+               pdstLine += widthDst;
+               bits = *psrc++;
+               if (startmask)
+               {
+                   if (firstoff < 0)
+                       tmp = BitRight (bits, -firstoff);
+                   else
+                   {
+                       tmp = BitLeft (bits, firstoff);
+                       /*
+                        * need a more cautious test for partialmask
+                        * case...
+                        */
+                       if (firstoff >= (MFB_PPW-PPW))
+                       {
+                           bits = *psrc++;
+                           if (firstoff != (MFB_PPW-PPW))
+                               tmp |= BitRight (bits, secondoff);
+                       }
+                   }
+                   *pdst = (*pdst & ~startmask) | (GetPixelGroup(tmp) & startmask);
+                   pdst++;
+               }
+               nl = nlMiddle;
+               while (nl >= 8)
+               {
+                   nl -= 8;
+                   tmp = BitLeft(bits, leftShift);
+                   bits = *psrc++;
+                   if (rightShift != MFB_PPW)
+                       tmp |= BitRight(bits, rightShift);
+
+#ifdef FAST_CONSTANT_OFFSET_MODE
+# define StorePixels(pdst,o,pixels)    (pdst)[o] = (pixels)
+# define EndStep(pdst,o)               (pdst) += (o)
+# define StoreRopPixels(pdst,o,and,xor)        (pdst)[o] = DoRRop((pdst)[o],and,xor);
+#else
+# define StorePixels(pdst,o,pixels)    *(pdst)++ = (pixels)
+# define EndStep(pdst,o)
+# define StoreRopPixels(pdst,o,and,xor)        *(pdst) = DoRRop(*(pdst),and,xor); (pdst)++;
+#endif
+
+#define Step(c)                        NextBitGroup(c);
+#define StoreBitsPlain(o,c)    StorePixels(pdst,o,GetPixelGroup(c))
+#define StoreRopBitsPlain(o,c) StoreRopPixels(pdst,o,\
+                                       cfb8StippleAnd[GetBitGroup(c)], \
+                                       cfb8StippleXor[GetBitGroup(c)])
+#define StoreBits0(c)          StoreBitsPlain(0,c)
+#define StoreRopBits0(c)       StoreRopBitsPlain(0,c)
+
+#if (BITMAP_BIT_ORDER == MSBFirst)
+# define StoreBits(o,c)        StoreBitsPlain(o,c)
+# define StoreRopBits(o,c)  StoreRopBitsPlain(o,c)
+# define FirstStep(c)  Step(c)
+#else /* BITMAP_BIT_ORDER == LSBFirst */
+#if PGSZ == 64
+# define StoreBits(o,c)        StorePixels(pdst,o, (cfb8Pixels[c & 0xff]))
+# define StoreRopBits(o,c)  StoreRopPixels(pdst,o, \
+    (cfb8StippleAnd[c & 0xff]), \
+    (cfb8StippleXor[c & 0xff]))
+# define FirstStep(c)  c = BitLeft (c, 8);
+#else
+/* 0x3c is 0xf << 2 (4 bits, long word) */
+# define StoreBits(o,c)        StorePixels(pdst,o,*((unsigned long *)\
+                           (((char *) cfb8Pixels) + (c & 0x3c))))
+# define StoreRopBits(o,c)  StoreRopPixels(pdst,o, \
+    *((unsigned long *) (((char *) cfb8StippleAnd) + (c & 0x3c))), \
+    *((unsigned long *) (((char *) cfb8StippleXor) + (c & 0x3c))))
+# define FirstStep(c)  c = BitLeft (c, 2);
+#endif /* PGSZ */
+#endif /* BITMAP_BIT_ORDER */
+
+                   StoreBits0(tmp);    FirstStep(tmp);
+                   StoreBits(1,tmp);   Step(tmp);
+                   StoreBits(2,tmp);   Step(tmp);
+                   StoreBits(3,tmp);   Step(tmp);
+                   StoreBits(4,tmp);   Step(tmp);
+                   StoreBits(5,tmp);   Step(tmp);
+                   StoreBits(6,tmp);   Step(tmp);
+                   StoreBits(7,tmp);   EndStep (pdst,8);
+               }
+
+               /* do rest of middle and partial word on right edge */
+
+               if (pixelsRemainingOnRightEdge)
+               {
+                   tmp = BitLeft(bits, leftShift);
+
+                   if (pixelsRemainingOnRightEdge > rightShift)
+                   {
+                       bits = *psrc++;
+                       tmp |= BitRight (bits, rightShift);
+                   }
+                   EndStep (pdst, nl);
+                   switch (nl)
+                   {
+                   case 7:
+                       StoreBitsPlain(-7,tmp); Step(tmp);
+                   case 6:
+                       StoreBitsPlain(-6,tmp); Step(tmp);
+                   case 5:
+                       StoreBitsPlain(-5,tmp); Step(tmp);
+                   case 4:
+                       StoreBitsPlain(-4,tmp); Step(tmp);
+                   case 3:
+                       StoreBitsPlain(-3,tmp); Step(tmp);
+                   case 2:
+                       StoreBitsPlain(-2,tmp); Step(tmp);
+                   case 1:
+                       StoreBitsPlain(-1,tmp); Step(tmp);
+                   }
+                   if (endmask)
+                       *pdst = (*pdst & ~endmask) | (GetPixelGroup(tmp) & endmask);
+               }
+           }
+       }
+       else /* cfb8StippleRRop != GXcopy */
+       {
+           while (height--)
+           { /* one iteration of this loop copies one row */
+               psrc = psrcLine;
+               pdst = pdstLine;
+               psrcLine += widthSrc;
+               pdstLine += widthDst;
+               bits = *psrc++;
+
+               /* do partial word on left edge */
+
+               if (startmask)
+               {
+                   if (firstoff < 0)
+                       tmp = BitRight (bits, -firstoff);
+                   else
+                   {
+                       tmp = BitLeft (bits, firstoff);
+                       if (firstoff >= (MFB_PPW-PPW))
+                       {
+                           bits = *psrc++;
+                           if (firstoff != (MFB_PPW-PPW))
+                               tmp |= BitRight (bits, secondoff);
+                       }
+                   }
+                   src = GetBitGroup(tmp);
+                   *pdst = MaskRRopPixels (*pdst, src, startmask);
+                   pdst++;
+               }
+
+               /* do middle of row */
+
+               nl = nlMiddle;
+               while (nl >= 8)
+               {
+                   nl -= 8;
+                   tmp = BitLeft(bits, leftShift);
+                   bits = *psrc++;
+                   if (rightShift != MFB_PPW)
+                       tmp |= BitRight(bits, rightShift);
+                   StoreRopBits0(tmp);         FirstStep(tmp);
+                   StoreRopBits(1,tmp);        Step(tmp);
+                   StoreRopBits(2,tmp);        Step(tmp);
+                   StoreRopBits(3,tmp);        Step(tmp);
+                   StoreRopBits(4,tmp);        Step(tmp);
+                   StoreRopBits(5,tmp);        Step(tmp);
+                   StoreRopBits(6,tmp);        Step(tmp);
+                   StoreRopBits(7,tmp);        EndStep(pdst,8);
+               }
+
+               /* do rest of middle and partial word on right edge */
+
+               if (pixelsRemainingOnRightEdge)
+               {
+                   tmp = BitLeft(bits, leftShift);
+
+                   if (pixelsRemainingOnRightEdge > rightShift)
+                   {
+                       bits = *psrc++; /* XXX purify abr here */
+                       tmp |= BitRight (bits, rightShift);
+                   }
+                   while (nl--)
+                   {
+                       src = GetBitGroup (tmp);
+                       *pdst = RRopPixels (*pdst, src);
+                       pdst++;
+                       NextBitGroup(tmp);
+                   }
+                   if (endmask)
+                   {
+                       src = GetBitGroup (tmp);
+                       *pdst = MaskRRopPixels (*pdst, src, endmask);
+                   }
+               }
+           } /* end copy one row */
+       } /* end alu is non-copy-mode case */
+    } /* end iteration over region boxes */
+}
+
+#endif
+
+/* shared among all different cfb depths through linker magic */
+RegionPtr   (*cfbPuntCopyPlane)();
+
+RegionPtr cfbCopyPlane(pSrcDrawable, pDstDrawable,
+           pGC, srcx, srcy, width, height, dstx, dsty, bitPlane)
+    DrawablePtr        pSrcDrawable;
+    DrawablePtr                pDstDrawable;
+    GCPtr              pGC;
+    int                srcx, srcy;
+    int                width, height;
+    int                dstx, dsty;
+    unsigned long      bitPlane;
+{
+    RegionPtr  ret;
+    extern RegionPtr    miHandleExposures();
+    void               (*doBitBlt)();
+
+#if PSZ == 8
+
+    if (pSrcDrawable->bitsPerPixel == 1 && pDstDrawable->bitsPerPixel == 8)
+    {
+       if (bitPlane == 1)
+       {
+                   doBitBlt = cfbCopyPlane1to8;
+           cfb8CheckOpaqueStipple (pGC->alu,
+                                   pGC->fgPixel, pGC->bgPixel,
+                                   pGC->planemask);
+           ret = cfbBitBlt (pSrcDrawable, pDstDrawable,
+                   pGC, srcx, srcy, width, height, dstx, dsty, doBitBlt, bitPlane);
+       }
+       else
+           ret = miHandleExposures (pSrcDrawable, pDstDrawable,
+               pGC, srcx, srcy, width, height, dstx, dsty, bitPlane);
+    }
+    else if (pSrcDrawable->bitsPerPixel == 8 && pDstDrawable->bitsPerPixel == 1)
+    {
+       extern  int InverseAlu[16];
+       int oldalu;
+
+       oldalu = pGC->alu;
+       if ((pGC->fgPixel & 1) == 0 && (pGC->bgPixel&1) == 1)
+           pGC->alu = InverseAlu[pGC->alu];
+       else if ((pGC->fgPixel & 1) == (pGC->bgPixel & 1))
+           pGC->alu = mfbReduceRop(pGC->alu, pGC->fgPixel);
+       ret = cfbBitBlt (pSrcDrawable, pDstDrawable,
+                        pGC, srcx, srcy, width, height, dstx, dsty, 
+                        cfbCopyPlane8to1, bitPlane);
+       pGC->alu = oldalu;
+    }
+    else if (pSrcDrawable->bitsPerPixel == 8 && pDstDrawable->bitsPerPixel == 8)
+    {
+       PixmapPtr       pBitmap;
+       ScreenPtr       pScreen = pSrcDrawable->pScreen;
+       GCPtr           pGC1;
+
+       pBitmap = (*pScreen->CreatePixmap) (pScreen, width, height, 1);
+       if (!pBitmap)
+           return NULL;
+       pGC1 = GetScratchGC (1, pScreen);
+       if (!pGC1)
+       {
+           (*pScreen->DestroyPixmap) (pBitmap);
+           return NULL;
+       }
+       /*
+        * don't need to set pGC->fgPixel,bgPixel as copyPlane8to1
+        * ignores pixel values, expecting the rop to "do the
+        * right thing", which GXcopy will.
+        */
+       ValidateGC ((DrawablePtr) pBitmap, pGC1);
+       /* no exposures here, scratch GC's don't get graphics expose */
+       (void) cfbBitBlt (pSrcDrawable, (DrawablePtr) pBitmap,
+                         pGC1, srcx, srcy, width, height, 0, 0, 
+                         cfbCopyPlane8to1, bitPlane);
+       cfb8CheckOpaqueStipple (pGC->alu,
+                               pGC->fgPixel, pGC->bgPixel,
+                               pGC->planemask);
+       /* no exposures here, copy bits from inside a pixmap */
+       (void) cfbBitBlt ((DrawablePtr) pBitmap, pDstDrawable, pGC,
+                           0, 0, width, height, dstx, dsty, cfbCopyPlane1to8, 1);
+       FreeScratchGC (pGC1);
+       (*pScreen->DestroyPixmap) (pBitmap);
+       /* compute resultant exposures */
+       ret = miHandleExposures (pSrcDrawable, pDstDrawable, pGC,
+                                srcx, srcy, width, height,
+                                dstx, dsty, bitPlane);
+    }
+    else
+#endif
+    ret = (*cfbPuntCopyPlane) (pSrcDrawable, pDstDrawable,
+           pGC, srcx, srcy, width, height, dstx, dsty, bitPlane);
+    return ret;
+}
diff --git a/Xserver/programs/Xserver/cfb/cfbblt.c b/Xserver/programs/Xserver/cfb/cfbblt.c
new file mode 100644 (file)
index 0000000..f3bfa25
--- /dev/null
@@ -0,0 +1,698 @@
+/*
+ * cfb copy area
+ */
+
+/*
+
+Copyright (c) 1989  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+Author: Keith Packard
+
+*/
+/* $XConsortium: cfbblt.c,v 1.13 94/04/17 20:28:44 dpw Exp $ */
+/* $XFree86: xc/programs/Xserver/cfb/cfbblt.c,v 3.1 1996/12/09 11:50:52 dawes Exp $ */
+
+#include       "X.h"
+#include       "Xmd.h"
+#include       "Xproto.h"
+#include       "gcstruct.h"
+#include       "windowstr.h"
+#include       "scrnintstr.h"
+#include       "pixmapstr.h"
+#include       "regionstr.h"
+#include       "cfb.h"
+#include       "cfbmskbits.h"
+#include       "cfb8bit.h"
+#include       "fastblt.h"
+#include       "mergerop.h"
+
+#ifdef notdef /* XXX fails right now, walks off end of pixmaps */
+#if defined (FAST_UNALIGNED_READS) && PSZ == 8
+#define DO_UNALIGNED_BITBLT
+#endif
+#endif
+
+#if defined(FAST_MEMCPY) && (MROP == Mcopy) && PSZ == 8
+#define DO_MEMCPY
+#endif
+
+void
+MROP_NAME(cfbDoBitblt)(pSrc, pDst, alu, prgnDst, pptSrc, planemask)
+    DrawablePtr            pSrc, pDst;
+    int                    alu;
+    RegionPtr      prgnDst;
+    DDXPointPtr            pptSrc;
+    unsigned long   planemask;
+{
+    unsigned long *psrcBase, *pdstBase;        
+                               /* start of src and dst bitmaps */
+    int widthSrc, widthDst;    /* add to get to same position in next line */
+
+    BoxPtr pbox;
+    int nbox;
+
+    BoxPtr pboxTmp, pboxNext, pboxBase, pboxNew1, pboxNew2;
+                               /* temporaries for shuffling rectangles */
+    DDXPointPtr pptTmp, pptNew1, pptNew2;
+                               /* shuffling boxes entails shuffling the
+                                  source points too */
+    int w, h;
+    int xdir;                  /* 1 = left right, -1 = right left/ */
+    int ydir;                  /* 1 = top down, -1 = bottom up */
+
+    unsigned long *psrcLine, *pdstLine;        
+                               /* pointers to line with current src and dst */
+    register unsigned long *psrc;/* pointer to current src longword */
+    register unsigned long *pdst;/* pointer to current dst longword */
+
+    MROP_DECLARE_REG()
+
+                               /* following used for looping through a line */
+    unsigned long startmask, endmask;  /* masks for writing ends of dst */
+    int nlMiddle;              /* whole longwords in dst */
+    int xoffSrc, xoffDst;
+    register int leftShift, rightShift;
+    register unsigned long bits;
+    register unsigned long bits1;
+    register int nl;           /* temp copy of nlMiddle */
+
+                               /* place to store full source word */
+    int nstart;                        /* number of ragged bits at start of dst */
+    int nend;                  /* number of ragged bits at end of dst */
+    int srcStartOver;          /* pulling nstart bits from src
+                                  overflows into the next word? */
+    int careful;
+    int tmpSrc;
+#if PSZ == 24
+#ifdef DO_MEMCPY
+    int w2;
+#endif
+#endif
+
+    MROP_INITIALIZE(alu,planemask);
+
+    cfbGetLongWidthAndPointer (pSrc, widthSrc, psrcBase)
+
+    cfbGetLongWidthAndPointer (pDst, widthDst, pdstBase)
+
+    /* XXX we have to err on the side of safety when both are windows,
+     * because we don't know if IncludeInferiors is being used.
+     */
+    careful = ((pSrc == pDst) ||
+              ((pSrc->type == DRAWABLE_WINDOW) &&
+               (pDst->type == DRAWABLE_WINDOW)));
+
+    pbox = REGION_RECTS(prgnDst);
+    nbox = REGION_NUM_RECTS(prgnDst);
+
+    pboxNew1 = NULL;
+    pptNew1 = NULL;
+    pboxNew2 = NULL;
+    pptNew2 = NULL;
+    if (careful && (pptSrc->y < pbox->y1))
+    {
+        /* walk source botttom to top */
+       ydir = -1;
+       widthSrc = -widthSrc;
+       widthDst = -widthDst;
+
+       if (nbox > 1)
+       {
+           /* keep ordering in each band, reverse order of bands */
+           pboxNew1 = (BoxPtr)ALLOCATE_LOCAL(sizeof(BoxRec) * nbox);
+           if(!pboxNew1)
+               return;
+           pptNew1 = (DDXPointPtr)ALLOCATE_LOCAL(sizeof(DDXPointRec) * nbox);
+           if(!pptNew1)
+           {
+               DEALLOCATE_LOCAL(pboxNew1);
+               return;
+           }
+           pboxBase = pboxNext = pbox+nbox-1;
+           while (pboxBase >= pbox)
+           {
+               while ((pboxNext >= pbox) &&
+                      (pboxBase->y1 == pboxNext->y1))
+                   pboxNext--;
+               pboxTmp = pboxNext+1;
+               pptTmp = pptSrc + (pboxTmp - pbox);
+               while (pboxTmp <= pboxBase)
+               {
+                   *pboxNew1++ = *pboxTmp++;
+                   *pptNew1++ = *pptTmp++;
+               }
+               pboxBase = pboxNext;
+           }
+           pboxNew1 -= nbox;
+           pbox = pboxNew1;
+           pptNew1 -= nbox;
+           pptSrc = pptNew1;
+        }
+    }
+    else
+    {
+       /* walk source top to bottom */
+       ydir = 1;
+    }
+
+    if (careful && (pptSrc->x < pbox->x1))
+    {
+       /* walk source right to left */
+        xdir = -1;
+
+       if (nbox > 1)
+       {
+           /* reverse order of rects in each band */
+           pboxNew2 = (BoxPtr)ALLOCATE_LOCAL(sizeof(BoxRec) * nbox);
+           pptNew2 = (DDXPointPtr)ALLOCATE_LOCAL(sizeof(DDXPointRec) * nbox);
+           if(!pboxNew2 || !pptNew2)
+           {
+               if (pptNew2) DEALLOCATE_LOCAL(pptNew2);
+               if (pboxNew2) DEALLOCATE_LOCAL(pboxNew2);
+               if (pboxNew1)
+               {
+                   DEALLOCATE_LOCAL(pptNew1);
+                   DEALLOCATE_LOCAL(pboxNew1);
+               }
+               return;
+           }
+           pboxBase = pboxNext = pbox;
+           while (pboxBase < pbox+nbox)
+           {
+               while ((pboxNext < pbox+nbox) &&
+                      (pboxNext->y1 == pboxBase->y1))
+                   pboxNext++;
+               pboxTmp = pboxNext;
+               pptTmp = pptSrc + (pboxTmp - pbox);
+               while (pboxTmp != pboxBase)
+               {
+                   *pboxNew2++ = *--pboxTmp;
+                   *pptNew2++ = *--pptTmp;
+               }
+               pboxBase = pboxNext;
+           }
+           pboxNew2 -= nbox;
+           pbox = pboxNew2;
+           pptNew2 -= nbox;
+           pptSrc = pptNew2;
+       }
+    }
+    else
+    {
+       /* walk source left to right */
+        xdir = 1;
+    }
+
+    while(nbox--)
+    {
+       w = pbox->x2 - pbox->x1;
+       h = pbox->y2 - pbox->y1;
+
+#if PSZ == 24
+#ifdef DO_MEMCPY
+       w2 = w * 3;
+#endif
+#endif
+       if (ydir == -1) /* start at last scanline of rectangle */
+       {
+           psrcLine = psrcBase + ((pptSrc->y+h-1) * -widthSrc);
+           pdstLine = pdstBase + ((pbox->y2-1) * -widthDst);
+       }
+       else /* start at first scanline */
+       {
+           psrcLine = psrcBase + (pptSrc->y * widthSrc);
+           pdstLine = pdstBase + (pbox->y1 * widthDst);
+       }
+#if PSZ == 24
+       if (w == 1 && ((pbox->x1 & 3) == 0  ||  (pbox->x1 & 3) == 3))
+#else
+       if ((pbox->x1 & PIM) + w <= PPW)
+#endif
+       {
+           maskpartialbits (pbox->x1, w, endmask);
+           startmask = 0;
+           nlMiddle = 0;
+       }
+       else
+       {
+           maskbits(pbox->x1, w, startmask, endmask, nlMiddle);
+       }
+
+#ifdef DO_MEMCPY
+       /* If the src and dst scanline don't overlap, do forward case.  */
+
+       if ((xdir == 1) || (pptSrc->y != pbox->y1)
+               || (pptSrc->x + w <= pbox->x1))
+       {
+#if PSZ == 24
+           char *psrc = (char *) psrcLine + (pptSrc->x * 3);
+           char *pdst = (char *) pdstLine + (pbox->x1 * 3);
+#else
+           char *psrc = (char *) psrcLine + pptSrc->x;
+           char *pdst = (char *) pdstLine + pbox->x1;
+#endif
+           while (h--)
+           {
+#if PSZ == 24
+               memcpy(pdst, psrc, w2);
+#else
+               memcpy(pdst, psrc, w);
+#endif
+               pdst += widthDst << PWSH;
+               psrc += widthSrc << PWSH;
+           }
+       }
+#else /* ! DO_MEMCPY */
+       if (xdir == 1)
+       {
+#if PSZ == 24
+           xoffSrc = (4 - pptSrc->x) & 3;
+           xoffDst = (4 - pbox->x1) & 3;
+           pdstLine += (pbox->x1 * 3) >> 2;
+           psrcLine += (pptSrc->x * 3) >> 2;
+#else
+           xoffSrc = pptSrc->x & PIM;
+           xoffDst = pbox->x1 & PIM;
+           pdstLine += (pbox->x1 >> PWSH);
+           psrcLine += (pptSrc->x >> PWSH);
+#endif
+#ifdef DO_UNALIGNED_BITBLT
+           nl = xoffSrc - xoffDst;
+           psrcLine = (unsigned long *)
+                       (((unsigned char *) psrcLine) + nl);
+#else
+           if (xoffSrc == xoffDst)
+#endif
+           {
+               while (h--)
+               {
+                   psrc = psrcLine;
+                   pdst = pdstLine;
+                   pdstLine += widthDst;
+                   psrcLine += widthSrc;
+                   if (startmask)
+                   {
+                       *pdst = MROP_MASK(*psrc, *pdst, startmask);
+                       psrc++;
+                       pdst++;
+                   }
+                   nl = nlMiddle;
+
+#ifdef LARGE_INSTRUCTION_CACHE
+#ifdef FAST_CONSTANT_OFFSET_MODE
+
+                   psrc += nl & (UNROLL-1);
+                   pdst += nl & (UNROLL-1);
+
+#define BodyOdd(n) pdst[-n] = MROP_SOLID (psrc[-n], pdst[-n]);
+#define BodyEven(n) pdst[-n] = MROP_SOLID (psrc[-n], pdst[-n]);
+
+#define LoopReset \
+pdst += UNROLL; \
+psrc += UNROLL;
+
+#else
+
+#define BodyOdd(n)  *pdst = MROP_SOLID (*psrc, *pdst); pdst++; psrc++;
+#define BodyEven(n) BodyOdd(n)
+
+#define LoopReset   ;
+
+#endif
+                   PackedLoop
+
+#undef BodyOdd
+#undef BodyEven
+#undef LoopReset
+
+#else
+#ifdef NOTDEF
+                   /* you'd think this would be faster --
+                    * a single instruction instead of 6
+                    * but measurements show it to be ~15% slower
+                    */
+                   while ((nl -= 6) >= 0)
+                   {
+                       asm ("moveml %1+,#0x0c0f;moveml#0x0c0f,%0"
+                            : "=m" (*(char *)pdst)
+                            : "m" (*(char *)psrc)
+                            : "d0", "d1", "d2", "d3",
+                              "a2", "a3");
+                       pdst += 6;
+                   }
+                   nl += 6;
+                   while (nl--)
+                       *pdst++ = *psrc++;
+#endif
+                   DuffL(nl, label1,
+                           *pdst = MROP_SOLID (*psrc, *pdst);
+                           pdst++; psrc++;)
+#endif
+
+                   if (endmask)
+                       *pdst = MROP_MASK(*psrc, *pdst, endmask);
+               }
+           }
+#ifndef DO_UNALIGNED_BITBLT
+           else
+           {
+               if (xoffSrc > xoffDst)
+               {
+#if PSZ == 24
+                   leftShift = (xoffSrc - xoffDst) << 3;
+#else
+#if PGSZ == 32
+                   leftShift = (xoffSrc - xoffDst) << (5 - PWSH);
+#else /* PGSZ == 64 */
+                   leftShift = (xoffSrc - xoffDst) << (6 - PWSH);
+#endif /* PGSZ */
+#endif
+                   rightShift = PGSZ - leftShift;
+               }
+               else
+               {
+#if PSZ == 24
+                   rightShift = (xoffDst - xoffSrc) << 3;
+#else
+#if PGSZ == 32
+                   rightShift = (xoffDst - xoffSrc) << (5 - PWSH);
+#else /* PGSZ == 64 */
+                   rightShift = (xoffDst - xoffSrc) << (6 - PWSH);
+#endif /* PGSZ */
+#endif
+                   leftShift = PGSZ - rightShift;
+               }
+               while (h--)
+               {
+                   psrc = psrcLine;
+                   pdst = pdstLine;
+                   pdstLine += widthDst;
+                   psrcLine += widthSrc;
+                   bits = 0;
+                   if (xoffSrc > xoffDst)
+                       bits = *psrc++;
+                   if (startmask)
+                   {
+                       bits1 = BitLeft(bits,leftShift);
+                       bits = *psrc++;
+                       bits1 |= BitRight(bits,rightShift);
+                       *pdst = MROP_MASK(bits1, *pdst, startmask);
+                       pdst++;
+                   }
+                   nl = nlMiddle;
+
+#ifdef LARGE_INSTRUCTION_CACHE
+                   bits1 = bits;
+
+#ifdef FAST_CONSTANT_OFFSET_MODE
+
+                   psrc += nl & (UNROLL-1);
+                   pdst += nl & (UNROLL-1);
+
+#define BodyOdd(n) \
+bits = psrc[-n]; \
+pdst[-n] = MROP_SOLID(BitLeft(bits1, leftShift) | BitRight(bits, rightShift), pdst[-n]);
+
+#define BodyEven(n) \
+bits1 = psrc[-n]; \
+pdst[-n] = MROP_SOLID(BitLeft(bits, leftShift) | BitRight(bits1, rightShift), pdst[-n]);
+
+#define LoopReset \
+pdst += UNROLL; \
+psrc += UNROLL;
+
+#else
+
+#define BodyOdd(n) \
+bits = *psrc++; \
+*pdst = MROP_SOLID(BitLeft(bits1, leftShift) | BitRight(bits, rightShift), *pdst); \
+pdst++;
+                  
+#define BodyEven(n) \
+bits1 = *psrc++; \
+*pdst = MROP_SOLID(BitLeft(bits, leftShift) | BitRight(bits1, rightShift), *pdst); \
+pdst++;
+
+#define LoopReset   ;
+
+#endif /* !FAST_CONSTANT_OFFSET_MODE */
+
+                   PackedLoop
+
+#undef BodyOdd
+#undef BodyEven
+#undef LoopReset
+
+#else
+                   DuffL (nl,label2,
+                       bits1 = BitLeft(bits, leftShift);
+                       bits = *psrc++;
+                       *pdst = MROP_SOLID (bits1 | BitRight(bits, rightShift), *pdst);
+                       pdst++;
+                   )
+#endif
+
+                   if (endmask)
+                   {
+                       bits1 = BitLeft(bits, leftShift);
+                       if (BitLeft(endmask, rightShift))
+                       {
+                           bits = *psrc;
+                           bits1 |= BitRight(bits, rightShift);
+                       }
+                       *pdst = MROP_MASK (bits1, *pdst, endmask);
+                   }
+               }
+           }
+#endif /* DO_UNALIGNED_BITBLT */
+       }
+#endif /* ! DO_MEMCPY */
+       else    /* xdir == -1 */
+       {
+#if PSZ == 24
+           xoffSrc = (pptSrc->x + w) & 3;
+           xoffDst = pbox->x2 & 3;
+           pdstLine += ((pbox->x2 * 3 - 1) >> 2) + 1;
+           psrcLine += (((pptSrc->x+w) * 3 - 1) >> 2) + 1;
+#else
+           xoffSrc = (pptSrc->x + w - 1) & PIM;
+           xoffDst = (pbox->x2 - 1) & PIM;
+           pdstLine += ((pbox->x2-1) >> PWSH) + 1;
+           psrcLine += ((pptSrc->x+w - 1) >> PWSH) + 1;
+#endif
+#ifdef DO_UNALIGNED_BITBLT
+#if PSZ == 24
+           nl = xoffDst - xoffSrc;
+#else
+           nl = xoffSrc - xoffDst;
+#endif
+           psrcLine = (unsigned long *)
+                       (((unsigned char *) psrcLine) + nl);
+#else
+           if (xoffSrc == xoffDst)
+#endif
+           {
+               while (h--)
+               {
+                   psrc = psrcLine;
+                   pdst = pdstLine;
+                   pdstLine += widthDst;
+                   psrcLine += widthSrc;
+                   if (endmask)
+                   {
+                       pdst--;
+                       psrc--;
+                       *pdst = MROP_MASK (*psrc, *pdst, endmask);
+                   }
+                   nl = nlMiddle;
+
+#ifdef LARGE_INSTRUCTION_CACHE
+#ifdef FAST_CONSTANT_OFFSET_MODE
+                   psrc -= nl & (UNROLL - 1);
+                   pdst -= nl & (UNROLL - 1);
+
+#define BodyOdd(n) pdst[n-1] = MROP_SOLID (psrc[n-1], pdst[n-1]);
+
+#define BodyEven(n) BodyOdd(n)
+
+#define LoopReset \
+pdst -= UNROLL;\
+psrc -= UNROLL;
+
+#else
+
+#define BodyOdd(n)  --pdst; --psrc; *pdst = MROP_SOLID(*psrc, *pdst);
+#define BodyEven(n) BodyOdd(n)
+#define LoopReset   ;
+
+#endif
+                   PackedLoop
+
+#undef BodyOdd
+#undef BodyEven
+#undef LoopReset
+
+#else
+                   DuffL(nl,label3,
+                        --pdst; --psrc; *pdst = MROP_SOLID (*psrc, *pdst);)
+#endif
+
+                   if (startmask)
+                   {
+                       --pdst;
+                       --psrc;
+                       *pdst = MROP_MASK(*psrc, *pdst, startmask);
+                   }
+               }
+           }
+#ifndef DO_UNALIGNED_BITBLT
+           else
+           {
+               if (xoffDst > xoffSrc)
+               {
+#if PSZ == 24
+                   leftShift = (xoffDst - xoffSrc) << 3;
+                   rightShift = PGSZ - leftShift;
+#else
+#if PGSZ == 32
+                   rightShift = (xoffDst - xoffSrc) << (5 - PWSH);
+#else /* PGSZ == 64 */
+                   rightShift = (xoffDst - xoffSrc) << (6 - PWSH);
+#endif /* PGSZ */
+                   leftShift = PGSZ - rightShift;
+#endif
+               }
+               else
+               {
+#if PSZ == 24
+                   rightShift = (xoffSrc - xoffDst) << 3;
+                   leftShift = PGSZ - rightShift;
+#else
+#if PGSZ == 32
+                   leftShift = (xoffSrc - xoffDst) << (5 - PWSH);
+#else /* PGSZ == 64 */
+                   leftShift = (xoffSrc - xoffDst) << (6 - PWSH);
+#endif /* PGSZ */
+                   rightShift = PGSZ - leftShift;
+#endif
+               }
+               while (h--)
+               {
+                   psrc = psrcLine;
+                   pdst = pdstLine;
+                   pdstLine += widthDst;
+                   psrcLine += widthSrc;
+                   bits = 0;
+#if PSZ == 24
+                   if (xoffSrc > xoffDst)
+#else
+                   if (xoffDst > xoffSrc)
+#endif
+                       bits = *--psrc;
+                   if (endmask)
+                   {
+                       bits1 = BitRight(bits, rightShift);
+                       bits = *--psrc;
+                       bits1 |= BitLeft(bits, leftShift);
+                       pdst--;
+                       *pdst = MROP_MASK(bits1, *pdst, endmask);
+                   }
+                   nl = nlMiddle;
+
+#ifdef LARGE_INSTRUCTION_CACHE
+                   bits1 = bits;
+#ifdef FAST_CONSTANT_OFFSET_MODE
+                   psrc -= nl & (UNROLL - 1);
+                   pdst -= nl & (UNROLL - 1);
+
+#define BodyOdd(n) \
+bits = psrc[n-1]; \
+pdst[n-1] = MROP_SOLID(BitRight(bits1, rightShift) | BitLeft(bits, leftShift),pdst[n-1]);
+
+#define BodyEven(n) \
+bits1 = psrc[n-1]; \
+pdst[n-1] = MROP_SOLID(BitRight(bits, rightShift) | BitLeft(bits1, leftShift),pdst[n-1]);
+
+#define LoopReset \
+pdst -= UNROLL; \
+psrc -= UNROLL;
+
+#else
+
+#define BodyOdd(n) \
+bits = *--psrc; --pdst; \
+*pdst = MROP_SOLID(BitRight(bits1, rightShift) | BitLeft(bits, leftShift),*pdst);
+
+#define BodyEven(n) \
+bits1 = *--psrc; --pdst; \
+*pdst = MROP_SOLID(BitRight(bits, rightShift) | BitLeft(bits1, leftShift),*pdst);
+
+#define LoopReset   ;
+
+#endif
+
+                   PackedLoop
+
+#undef BodyOdd
+#undef BodyEven
+#undef LoopReset
+
+#else
+                   DuffL (nl, label4,
+                       bits1 = BitRight(bits, rightShift);
+                       bits = *--psrc;
+                       --pdst;
+                       *pdst = MROP_SOLID(bits1 | BitLeft(bits, leftShift),*pdst);
+                   )
+#endif
+
+                   if (startmask)
+                   {
+                       bits1 = BitRight(bits, rightShift);
+                       if (BitRight (startmask, leftShift))
+                       {
+                           bits = *--psrc;
+                           bits1 |= BitLeft(bits, leftShift);
+                       }
+                       --pdst;
+                       *pdst = MROP_MASK(bits1, *pdst, startmask);
+                   }
+               }
+           }
+#endif
+       }
+       pbox++;
+       pptSrc++;
+    }
+    if (pboxNew2)
+    {
+       DEALLOCATE_LOCAL(pptNew2);
+       DEALLOCATE_LOCAL(pboxNew2);
+    }
+    if (pboxNew1)
+    {
+       DEALLOCATE_LOCAL(pptNew1);
+       DEALLOCATE_LOCAL(pboxNew1);
+    }
+}
diff --git a/Xserver/programs/Xserver/cfb/cfbbres.c b/Xserver/programs/Xserver/cfb/cfbbres.c
new file mode 100644 (file)
index 0000000..d4fe023
--- /dev/null
@@ -0,0 +1,339 @@
+/***********************************************************
+
+Copyright (c) 1987  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+
+Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
+
+                        All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and its 
+documentation for any purpose and without fee is hereby granted, 
+provided that the above copyright notice appear in all copies and that
+both that copyright notice and this permission notice appear in 
+supporting documentation, and that the name of Digital not be
+used in advertising or publicity pertaining to distribution of the
+software without specific, written prior permission.  
+
+DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
+ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
+DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
+ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+SOFTWARE.
+
+******************************************************************/
+/* $XConsortium: cfbbres.c,v 1.15 94/04/17 20:28:45 dpw Exp $ */
+/* $XFree86: xc/programs/Xserver/cfb/cfbbres.c,v 3.1 1996/08/25 14:05:40 dawes Exp $ */
+#include "X.h"
+#include "misc.h"
+#include "cfb.h"
+#include "cfbmskbits.h"
+#include "servermd.h"
+#include "miline.h"
+
+/* Solid bresenham line */
+/* NOTES
+   e2 is used less often than e1, so it's not in a register
+*/
+
+void
+cfbBresS(rop, and, xor, addrl, nlwidth, signdx, signdy, axis, x1, y1, e, e1,
+        e2, len)
+    int                    rop;
+    unsigned long   and, xor;
+    unsigned long   *addrl;            /* pointer to base of bitmap */
+    int                    nlwidth;            /* width in longwords of bitmap */
+    register int    signdx;
+    int                    signdy;             /* signs of directions */
+    int                    axis;               /* major axis (Y_AXIS or X_AXIS) */
+    int                    x1, y1;             /* initial point */
+    register int    e;                 /* error accumulator */
+    register int    e1;                        /* bresenham increments */
+    int                    e2;
+    int                    len;                /* length of line */
+{
+    register int       e3 = e2-e1;
+#if PSZ == 24
+    unsigned long piQxelXor[3],piQxelAnd[3];
+    char *addrb;
+    int nlwidth3, signdx3;
+#endif
+#ifdef PIXEL_ADDR
+    register PixelType *addrp;         /* Pixel pointer */
+
+    if (len == 0)
+       return;
+    /* point to first point */
+    nlwidth <<= PWSH;
+#if PSZ == 24
+    addrp = (PixelType *)(addrl) + (y1 * nlwidth);
+    addrb = (char *)addrp + x1 * 3;
+
+    piQxelXor[0] = (xor << 24) | xor;
+    piQxelXor[1] = (xor << 16)| (xor >> 8);
+    piQxelXor[2] = (xor << 8) | (xor >> 16);
+    piQxelAnd[0] = (and << 24) | and;
+    piQxelAnd[1] = (and << 16)| (and >> 8);
+    piQxelAnd[2] = (and << 8) | (and >> 16);
+#else
+    addrp = (PixelType *)(addrl) + (y1 * nlwidth) + x1;
+#endif
+    if (signdy < 0)
+       nlwidth = -nlwidth;
+    e = e-e1;                  /* to make looping easier */
+#if PSZ == 24
+    nlwidth3 = nlwidth * sizeof (long);
+    signdx3 = signdx * 3;
+#endif
+    
+    if (axis == Y_AXIS)
+    {
+       int     t;
+
+       t = nlwidth;
+       nlwidth = signdx;
+       signdx = t;
+#if PSZ == 24
+       t = nlwidth3;
+       nlwidth3 = signdx3;
+       signdx3 = t;
+#endif
+    }
+    if (rop == GXcopy)
+    {
+       --len;
+#if PSZ == 24
+#define body_copy \
+           addrp = (PixelType *)((unsigned long)addrb & ~0x03); \
+           switch((unsigned long)addrb & 3){ \
+           case 0: \
+             *addrp = ((*addrp)&0xFF000000)|(piQxelXor[0] & 0xFFFFFF); \
+             break; \
+           case 1: \
+             *addrp = ((*addrp)&0xFF)|(piQxelXor[2] & 0xFFFFFF00); \
+             break; \
+           case 3: \
+             *addrp = ((*addrp)&0xFFFFFF)|(piQxelXor[0] & 0xFF000000); \
+             *(addrp+1) = ((*(addrp+1))&0xFFFF0000)|(piQxelXor[1] & 0xFFFF); \
+             break; \
+           case 2: \
+             *addrp = ((*addrp)&0xFFFF)|(piQxelXor[1] & 0xFFFF0000); \
+             *(addrp+1) = ((*(addrp+1))&0xFFFFFF00)|(piQxelXor[2] & 0xFF); \
+             break; \
+           }
+#define body {\
+           body_copy \
+           addrb += signdx3; \
+           e += e1; \
+           if (e >= 0) \
+           { \
+               addrb += nlwidth3; \
+               e += e3; \
+            } \
+           }
+#else /* PSZ == 24 */
+#define body {\
+           *addrp = xor; \
+           addrp += signdx; \
+           e += e1; \
+           if (e >= 0) \
+           { \
+               addrp += nlwidth; \
+               e += e3; \
+           } \
+       }
+#endif /* PSZ == 24 */
+       while (len >= 4)
+       {
+           body body body body
+           len -= 4;
+       }
+       switch (len)
+       {
+       case  3: body case  2: body case  1: body
+       }
+#undef body
+#if PSZ == 24
+       body_copy
+# undef body_copy
+#else
+       *addrp = xor;
+#endif
+    }
+    else /* not GXcopy */
+    {
+       while(len--)
+       { 
+#if PSZ == 24
+           addrp = (PixelType *)((unsigned long)addrb & ~0x03);
+           switch((unsigned long)addrb & 3){
+           case 0:
+             *addrp = (*addrp & (piQxelAnd[0]|0xFF000000))
+                       ^ (piQxelXor[0] & 0xFFFFFF);
+             break;
+           case 1:
+             *addrp = (*addrp & (piQxelAnd[2]|0xFF))
+                       ^ (piQxelXor[2] & 0xFFFFFF00);
+             break;
+           case 3:
+             *addrp = (*addrp & (piQxelAnd[0]|0xFFFFFF))
+                       ^ (piQxelXor[0] & 0xFF000000);
+             *(addrp+1) = (*(addrp+1) & (piQxelAnd[1]|0xFFFF0000))
+                       ^ (piQxelXor[1] & 0xFFFF);
+             break;
+           case 2:
+             *addrp = (*addrp & (piQxelAnd[1]|0xFFFF))
+                       ^ (piQxelXor[1] & 0xFFFF0000);
+             *(addrp+1) = (*(addrp+1) & (piQxelAnd[2]|0xFFFFFF00))
+                       ^ (piQxelXor[2] & 0xFF);
+             break;
+           }
+           e += e1;
+           if (e >= 0)
+           {
+               addrb += nlwidth3;
+               e += e3;
+           }
+           addrb += signdx3;
+#else /* PSZ == 24 */
+           *addrp = DoRRop (*addrp, and, xor);
+           e += e1;
+           if (e >= 0)
+           {
+               addrp += nlwidth;
+               e += e3;
+           }
+           addrp += signdx;
+#endif /* PSZ == 24 */
+       }
+    }
+#else /* !PIXEL_ADDR */
+    register unsigned long   tmp, bit;
+    unsigned long leftbit, rightbit;
+
+    /* point to longword containing first point */
+#if PSZ == 24
+    addrl = (addrl + (y1 * nlwidth) + ((x1 * 3) >>2);
+#else
+    addrl = (addrl + (y1 * nlwidth) + (x1 >> PWSH));
+#endif
+    if (signdy < 0)
+           nlwidth = -nlwidth;
+    e = e-e1;                  /* to make looping easier */
+
+    leftbit = cfbmask[0];
+#if PSZ == 24
+    rightbit = cfbmask[(PPW-1)<<1];
+    bit = cfbmask[(x1 & 3)<<1];
+#else
+    rightbit = cfbmask[PPW-1];
+    bit = cfbmask[x1 & PIM];
+#endif
+
+    if (axis == X_AXIS)
+    {
+       if (signdx > 0)
+       {
+           while (len--)
+           { 
+               *addrl = DoMaskRRop (*addrl, and, xor, bit);
+               bit = SCRRIGHT(bit,1);
+               e += e1;
+               if (e >= 0)
+               {
+                   addrl += nlwidth;
+                   e += e3;
+               }
+               if (!bit)
+               {
+                   bit = leftbit;
+                   addrl++;
+               }
+           }
+       }
+       else
+       {
+           while (len--)
+           { 
+               *addrl = DoMaskRRop (*addrl, and, xor, bit);
+               e += e1;
+               bit = SCRLEFT(bit,1);
+               if (e >= 0)
+               {
+                   addrl += nlwidth;
+                   e += e3;
+               }
+               if (!bit)
+               {
+                   bit = rightbit;
+                   addrl--;
+               }
+           }
+       }
+    } /* if X_AXIS */
+    else
+    {
+       if (signdx > 0)
+       {
+           while(len--)
+           {
+               *addrl = DoMaskRRop (*addrl, and, xor, bit);
+               e += e1;
+               if (e >= 0)
+               {
+                   bit = SCRRIGHT(bit,1);
+                   if (!bit)
+                   {
+                       bit = leftbit;
+                       addrl++;
+                   }
+                   e += e3;
+               }
+               addrl += nlwidth;
+           }
+       }
+       else
+       {
+           while(len--)
+           {
+               *addrl = DoMaskRRop (*addrl, and, xor, bit);
+               e += e1;
+               if (e >= 0)
+               {
+                   bit = SCRLEFT(bit,1);
+                   if (!bit)
+                   {
+                       bit = rightbit;
+                       addrl--;
+                   }
+                   e += e3;
+               }
+               addrl += nlwidth;
+           }
+       }
+    } /* else Y_AXIS */
+#endif
+}
diff --git a/Xserver/programs/Xserver/cfb/cfbbresd.c b/Xserver/programs/Xserver/cfb/cfbbresd.c
new file mode 100644 (file)
index 0000000..322fa7f
--- /dev/null
@@ -0,0 +1,403 @@
+/***********************************************************
+
+Copyright (c) 1987  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+
+Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
+
+                        All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and its 
+documentation for any purpose and without fee is hereby granted, 
+provided that the above copyright notice appear in all copies and that
+both that copyright notice and this permission notice appear in 
+supporting documentation, and that the name of Digital not be
+used in advertising or publicity pertaining to distribution of the
+software without specific, written prior permission.  
+
+DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
+ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
+DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
+ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+SOFTWARE.
+
+******************************************************************/
+/* $XConsortium: cfbbresd.c,v 1.16 94/04/17 20:28:45 dpw Exp $ */
+/* $XFree86: xc/programs/Xserver/cfb/cfbbresd.c,v 3.1 1996/08/25 14:05:42 dawes Exp $ */
+#include "X.h"
+#include "misc.h"
+#include "cfb.h"
+#include "cfbmskbits.h"
+#include "miline.h"
+
+/* Dashed bresenham line */
+
+void
+cfbBresD(rrops,
+        pdashIndex, pDash, numInDashList, pdashOffset, isDoubleDash,
+        addrl, nlwidth,
+        signdx, signdy, axis, x1, y1, e, e1, e2, len)
+    cfbRRopPtr     rrops;
+    int                    *pdashIndex;        /* current dash */
+    unsigned char   *pDash;            /* dash list */
+    int                    numInDashList;      /* total length of dash list */
+    int                    *pdashOffset;       /* offset into current dash */
+    int                    isDoubleDash;
+    unsigned long   *addrl;            /* pointer to base of bitmap */
+    int                    nlwidth;            /* width in longwords of bitmap */
+    int                    signdx, signdy;     /* signs of directions */
+    int                    axis;               /* major axis (Y_AXIS or X_AXIS) */
+    int                    x1, y1;             /* initial point */
+    register int    e;                 /* error accumulator */
+    register int    e1;                        /* bresenham increments */
+    int                    e2;
+    int                    len;                /* length of line */
+{
+#ifdef PIXEL_ADDR
+    register PixelType *addrp;
+#endif
+    register           int e3 = e2-e1;
+    int                        dashIndex;
+    int                        dashOffset;
+    int                        dashRemaining;
+    unsigned long      xorFg, andFg, xorBg, andBg;
+    Bool               isCopy;
+    int                        thisDash;
+#if PSZ == 24
+    unsigned long xorPiQxlFg[3], andPiQxlFg[3], xorPiQxlBg[3], andPiQxlBg[3]; 
+    char *addrb;
+    int signdx3, signdy3;
+#endif
+
+    dashOffset = *pdashOffset;
+    dashIndex = *pdashIndex;
+    isCopy = (rrops[0].rop == GXcopy && rrops[1].rop == GXcopy);
+#if PSZ == 24
+    xorFg = rrops[0].xor & 0xffffff;
+    andFg = rrops[0].and & 0xffffff;
+    xorBg = rrops[1].xor & 0xffffff;
+    andBg = rrops[1].and & 0xffffff;
+    xorPiQxlFg[0] = xorFg | (xorFg << 24);
+    xorPiQxlFg[1] = (xorFg >> 8) | (xorFg << 16);
+    xorPiQxlFg[2] = (xorFg >> 16) | (xorFg << 8);
+    andPiQxlFg[0] = andFg | (andFg << 24);
+    andPiQxlFg[1] = (andFg >> 8) | (andFg << 16);
+    andPiQxlFg[2] = (andFg >> 16) | (andFg << 8);
+    xorPiQxlBg[0] = xorBg | (xorBg << 24);
+    xorPiQxlBg[1] = (xorBg >> 8) | (xorBg << 16);
+    xorPiQxlBg[2] = (xorBg >> 16) | (xorBg << 8);
+    andPiQxlBg[0] = andBg | (andBg << 24);
+    andPiQxlBg[1] = (andBg >> 8) | (andBg << 16);
+    andPiQxlBg[2] = (andFg >> 16) | (andBg << 8);
+#else
+    xorFg = rrops[0].xor;
+    andFg = rrops[0].and;
+    xorBg = rrops[1].xor;
+    andBg = rrops[1].and;
+#endif
+    dashRemaining = pDash[dashIndex] - dashOffset;
+    if ((thisDash = dashRemaining) >= len)
+    {
+       thisDash = len;
+       dashRemaining -= len;
+    }
+    e = e-e1;                  /* to make looping easier */
+
+#define BresStep(minor,major) {if ((e += e1) >= 0) { e += e3; minor; } major;}
+
+#define NextDash {\
+    dashIndex++; \
+    if (dashIndex == numInDashList) \
+       dashIndex = 0; \
+    dashRemaining = pDash[dashIndex]; \
+    if ((thisDash = dashRemaining) >= len) \
+    { \
+       dashRemaining -= len; \
+       thisDash = len; \
+    } \
+}
+
+#ifdef PIXEL_ADDR
+
+#if PSZ == 24
+#define Loop(store) while (thisDash--) {\
+                       store; \
+                       BresStep(addrb+=signdy3,addrb+=signdx3) \
+                   }
+    /* point to first point */
+    nlwidth <<= PWSH;
+    addrp = (PixelType *)(addrl) + (y1 * nlwidth);
+    addrb = (char *)addrp + x1 * 3;
+
+#else
+#define Loop(store) while (thisDash--) {\
+                       store; \
+                       BresStep(addrp+=signdy,addrp+=signdx) \
+                   }
+    /* point to first point */
+    nlwidth <<= PWSH;
+    addrp = (PixelType *)(addrl) + (y1 * nlwidth) + x1;
+#endif
+    signdy *= nlwidth;
+#if PSZ == 24
+    signdx3 = signdx * 3;
+    signdy3 = signdy * sizeof (long);
+#endif
+    if (axis == Y_AXIS)
+    {
+       int t;
+
+       t = signdx;
+       signdx = signdy;
+       signdy = t;
+#if PSZ == 24
+       t = signdx3;
+       signdx3 = signdy3;
+       signdy3 = t;
+#endif
+    }
+
+    if (isCopy)
+    {
+#if PSZ == 24
+#define body_copy(pix) { \
+       addrp = (PixelType *)((unsigned long)addrb & ~0x03); \
+       switch((unsigned long)addrb & 3){ \
+       case 0: \
+         *addrp = (*addrp & 0xFF000000)|((pix)[0] & 0xFFFFFF); \
+         break; \
+       case 1: \
+         *addrp = (*addrp & 0xFF)|((pix)[2] & 0xFFFFFF00); \
+         break; \
+       case 3: \
+         *addrp = (*addrp & 0xFFFFFF)|((pix)[0] & 0xFF000000); \
+         *(addrp+1) = (*(addrp+1) & 0xFFFF0000)|((pix)[1] & 0xFFFF); \
+         break; \
+       case 2: \
+         *addrp = (*addrp & 0xFFFF)|((pix)[1] & 0xFFFF0000); \
+         *(addrp+1) = (*(addrp+1) & 0xFFFFFF00)|((pix)[2] & 0xFF); \
+         break; \
+       } \
+}
+#endif /* PSZ == 24 */
+                   
+       for (;;)
+       { 
+           len -= thisDash;
+           if (dashIndex & 1) {
+               if (isDoubleDash) {
+#if PSZ == 24
+                   Loop(body_copy(xorPiQxlBg))
+#else
+                   Loop(*addrp = xorBg)
+#endif
+               } else {
+                   Loop(;)
+               }
+           } else {
+#if PSZ == 24
+               Loop(body_copy(xorPiQxlFg))
+#else
+               Loop(*addrp = xorFg)
+#endif
+           }
+           if (!len)
+               break;
+           NextDash
+       }
+#undef body_copy
+    }
+    else
+    {
+#define body_set(and, xor) { \
+       addrp = (PixelType *)((unsigned long)addrb & ~0x03); \
+       switch((unsigned long)addrb & 3){ \
+       case 0: \
+         *addrp = (*addrp & ((and)[0]|0xFF000000)) ^ ((xor)[0] & 0xFFFFFF); \
+         break; \
+       case 1: \
+         *addrp = (*addrp & ((and)[2]|0xFF)) ^ ((xor)[2] & 0xFFFFFF00); \
+         break; \
+       case 3: \
+         *addrp = (*addrp & ((and)[0]|0xFFFFFF)) ^ ((xor)[0] & 0xFF000000); \
+         *(addrp+1)=(*(addrp+1)&((and)[1]|0xFFFF0000)) ^ ((xor)[1]&0xFFFF); \
+         break; \
+       case 2: \
+         *addrp = (*addrp & ((and)[1]|0xFFFF)) ^ ((xor)[1] & 0xFFFF0000); \
+         *(addrp+1)=(*(addrp+1)&((and)[2]|0xFFFFFF00)) ^ ((xor)[2] & 0xFF); \
+         break; \
+       } \
+}
+
+       for (;;)
+       { 
+           len -= thisDash;
+           if (dashIndex & 1) {
+               if (isDoubleDash) {
+#if PSZ == 24
+                   Loop(body_set(andPiQxlBg, xorPiQxlBg))
+#else
+                   Loop(*addrp = DoRRop(*addrp,andBg, xorBg))
+#endif
+               } else {
+                   Loop(;)
+               }
+           } else {
+#if PSZ == 24
+               Loop(body_set(andPiQxlFg, xorPiQxlFg))
+#else
+               Loop(*addrp = DoRRop(*addrp,andFg, xorFg))
+#endif
+           }
+           if (!len)
+               break;
+           NextDash
+       }
+#undef body_set
+    }
+#else /* !PIXEL_ADDR */
+    {
+       register unsigned long  tmp;
+       unsigned long           startbit, bit;
+
+       /* point to longword containing first point */
+#if PSZ == 24
+       addrl = (addrl + (y1 * nlwidth) + ((x1*3) >> 2);
+#else
+       addrl = (addrl + (y1 * nlwidth) + (x1 >> PWSH));
+#endif
+       signdy = signdy * nlwidth;
+
+       if (signdx > 0)
+           startbit = cfbmask[0];
+       else
+#if PSZ == 24
+           startbit = cfbmask[(PPW-1)<<1];
+       bit = cfbmask[(x1 & 3)<<1];
+#else
+           startbit = cfbmask[PPW-1];
+       bit = cfbmask[x1 & PIM];
+#endif
+
+#if PSZ == 24
+#define X_Loop(store)  while(thisDash--) {\
+                           store; \
+                           BresStep(addrl += signdy, \
+                                    if (signdx > 0) \
+                                        bit = SCRRIGHT(bit,1); \
+                                    else \
+                                        bit = SCRLEFT(bit,1); \
+                                    if (!bit) \
+                                    { \
+                                        bit = startbit; \
+                                        addrl += signdx; \
+                                    }) \
+                       }
+#define Y_Loop(store)  while(thisDash--) {\
+                           store; \
+                           BresStep(if (signdx > 0) \
+                                        bit = SCRRIGHT(bit,1); \
+                                    else \
+                                        bit = SCRLEFT(bit,1); \
+                                    if (!bit) \
+                                    { \
+                                        bit = startbit; \
+                                        addrl += signdx; \
+                                    }, \
+                                    addrl += signdy) \
+                       }
+#else
+#define X_Loop(store)  while(thisDash--) {\
+                           store; \
+                           BresStep(addrl += signdy, \
+                                    if (signdx > 0) \
+                                        bit = SCRRIGHT(bit,1); \
+                                    else \
+                                        bit = SCRLEFT(bit,1); \
+                                    if (!bit) \
+                                    { \
+                                        bit = startbit; \
+                                        addrl += signdx; \
+                                    }) \
+                       }
+#define Y_Loop(store)  while(thisDash--) {\
+                           store; \
+                           BresStep(if (signdx > 0) \
+                                        bit = SCRRIGHT(bit,1); \
+                                    else \
+                                        bit = SCRLEFT(bit,1); \
+                                    if (!bit) \
+                                    { \
+                                        bit = startbit; \
+                                        addrl += signdx; \
+                                    }, \
+                                    addrl += signdy) \
+                       }
+#endif
+
+       if (axis == X_AXIS)
+       {
+           for (;;)
+           {
+               len -= thisDash;
+               if (dashIndex & 1) {
+                   if (isDoubleDash) {
+                       X_Loop(*addrl = DoMaskRRop(*addrl, andBg, xorBg, bit));
+                   } else {
+                       X_Loop(;)
+                   }
+               } else {
+                   X_Loop(*addrl = DoMaskRRop(*addrl, andFg, xorFg, bit));
+               }
+               if (!len)
+                   break;
+               NextDash
+           }
+       } /* if X_AXIS */
+       else
+       {
+           for (;;)
+           {
+               len -= thisDash;
+               if (dashIndex & 1) {
+                   if (isDoubleDash) {
+                       Y_Loop(*addrl = DoMaskRRop(*addrl, andBg, xorBg, bit));
+                   } else {
+                       Y_Loop(;)
+                   }
+               } else {
+                   Y_Loop(*addrl = DoMaskRRop(*addrl, andFg, xorFg, bit));
+               }
+               if (!len)
+                   break;
+               NextDash
+           }
+       } /* else Y_AXIS */
+    }
+#endif
+    *pdashIndex = dashIndex;
+    *pdashOffset = pDash[dashIndex] - dashRemaining;
+}
diff --git a/Xserver/programs/Xserver/cfb/cfbbstore.c b/Xserver/programs/Xserver/cfb/cfbbstore.c
new file mode 100644 (file)
index 0000000..022a048
--- /dev/null
@@ -0,0 +1,150 @@
+/*-
+ * cfbbstore.c --
+ *     Functions required by the backing-store implementation in MI.
+ *
+ * Copyright (c) 1987 by the Regents of the University of California
+ *
+ * Permission to use, copy, modify, and distribute this
+ * software and its documentation for any purpose and without
+ * fee is hereby granted, provided that the above copyright
+ * notice appear in all copies.  The University of California
+ * makes no representations about the suitability of this
+ * software for any purpose.  It is provided "as is" without
+ * express or implied warranty.
+ *
+ *
+ */
+#ifndef lint
+static char rcsid[] =
+"$XConsortium: cfbbstore.c,v 5.8 93/12/13 17:21:51 dpw Exp $ SPRITE (Berkeley)";
+#endif
+
+#include    "cfb.h"
+#include    "X.h"
+#include    "mibstore.h"
+#include    "regionstr.h"
+#include    "scrnintstr.h"
+#include    "pixmapstr.h"
+#include    "windowstr.h"
+
+/*-
+ *-----------------------------------------------------------------------
+ * cfbSaveAreas --
+ *     Function called by miSaveAreas to actually fetch the areas to be
+ *     saved into the backing pixmap. This is very simple to do, since
+ *     cfbDoBitblt is designed for this very thing. The region to save is
+ *     already destination-relative and we're given the offset to the
+ *     window origin, so we have only to create an array of points of the
+ *     u.l. corners of the boxes in the region translated to the screen
+ *     coordinate system and fetch the screen pixmap out of its devPrivate
+ *     field....
+ *
+ * Results:
+ *     None.
+ *
+ * Side Effects:
+ *     Data are copied from the screen into the pixmap.
+ *
+ *-----------------------------------------------------------------------
+ */
+void
+cfbSaveAreas(pPixmap, prgnSave, xorg, yorg, pWin)
+    PixmapPtr          pPixmap;        /* Backing pixmap */
+    RegionPtr          prgnSave;       /* Region to save (pixmap-relative) */
+    int                        xorg;           /* X origin of region */
+    int                        yorg;           /* Y origin of region */
+    WindowPtr          pWin;
+{
+    register DDXPointPtr pPt;
+    DDXPointPtr                pPtsInit;
+    register BoxPtr    pBox;
+    register int       i;
+    ScreenPtr          pScreen = pPixmap->drawable.pScreen;
+    PixmapPtr          pScrPix;
+    
+    i = REGION_NUM_RECTS(prgnSave);
+    pPtsInit = (DDXPointPtr)ALLOCATE_LOCAL(i * sizeof(DDXPointRec));
+    if (!pPtsInit)
+       return;
+    
+    pBox = REGION_RECTS(prgnSave);
+    pPt = pPtsInit;
+    while (--i >= 0) {
+       pPt->x = pBox->x1 + xorg;
+       pPt->y = pBox->y1 + yorg;
+       pPt++;
+       pBox++;
+    }
+
+#ifdef CFB_NEED_SCREEN_PRIVATE
+    pScrPix = (PixmapPtr) pScreen->devPrivates[cfbScreenPrivateIndex].ptr;
+#else
+    pScrPix = (PixmapPtr) pScreen->devPrivate;
+#endif
+
+    cfbDoBitbltCopy((DrawablePtr) pScrPix, (DrawablePtr)pPixmap,
+                   GXcopy, prgnSave, pPtsInit, ~0L);
+
+    DEALLOCATE_LOCAL (pPtsInit);
+}
+
+/*-
+ *-----------------------------------------------------------------------
+ * cfbRestoreAreas --
+ *     Function called by miRestoreAreas to actually fetch the areas to be
+ *     restored from the backing pixmap. This is very simple to do, since
+ *     cfbDoBitblt is designed for this very thing. The region to restore is
+ *     already destination-relative and we're given the offset to the
+ *     window origin, so we have only to create an array of points of the
+ *     u.l. corners of the boxes in the region translated to the pixmap
+ *     coordinate system and fetch the screen pixmap out of its devPrivate
+ *     field....
+ *
+ * Results:
+ *     None.
+ *
+ * Side Effects:
+ *     Data are copied from the pixmap into the screen.
+ *
+ *-----------------------------------------------------------------------
+ */
+void
+cfbRestoreAreas(pPixmap, prgnRestore, xorg, yorg, pWin)
+    PixmapPtr          pPixmap;        /* Backing pixmap */
+    RegionPtr          prgnRestore;    /* Region to restore (screen-relative)*/
+    int                        xorg;           /* X origin of window */
+    int                        yorg;           /* Y origin of window */
+    WindowPtr          pWin;
+{
+    register DDXPointPtr pPt;
+    DDXPointPtr                pPtsInit;
+    register BoxPtr    pBox;
+    register int       i;
+    ScreenPtr          pScreen = pPixmap->drawable.pScreen;
+    PixmapPtr          pScrPix;
+    
+    i = REGION_NUM_RECTS(prgnRestore);
+    pPtsInit = (DDXPointPtr)ALLOCATE_LOCAL(i*sizeof(DDXPointRec));
+    if (!pPtsInit)
+       return;
+    
+    pBox = REGION_RECTS(prgnRestore);
+    pPt = pPtsInit;
+    while (--i >= 0) {
+       pPt->x = pBox->x1 - xorg;
+       pPt->y = pBox->y1 - yorg;
+       pPt++;
+       pBox++;
+    }
+
+#ifdef CFB_NEED_SCREEN_PRIVATE
+    pScrPix = (PixmapPtr) pScreen->devPrivates[cfbScreenPrivateIndex].ptr;
+#else
+    pScrPix = (PixmapPtr) pScreen->devPrivate;
+#endif
+
+    cfbDoBitbltCopy((DrawablePtr)pPixmap, (DrawablePtr) pScrPix,
+                   GXcopy, prgnRestore, pPtsInit, ~0L);
+
+    DEALLOCATE_LOCAL (pPtsInit);
+}
diff --git a/Xserver/programs/Xserver/cfb/cfbcmap.c b/Xserver/programs/Xserver/cfb/cfbcmap.c
new file mode 100644 (file)
index 0000000..267d1c0
--- /dev/null
@@ -0,0 +1,588 @@
+/* $XConsortium: cfbcmap.c,v 4.19 94/04/17 20:28:46 dpw Exp $ */
+/* $XFree86: xc/programs/Xserver/cfb/cfbcmap.c,v 3.1.8.2 1997/05/11 05:04:17 dawes Exp $ */
+/************************************************************
+Copyright 1987 by Sun Microsystems, Inc. Mountain View, CA.
+
+                    All Rights Reserved
+
+Permission  to  use,  copy,  modify,  and  distribute   this
+software  and  its documentation for any purpose and without
+fee is hereby granted, provided that the above copyright no-
+tice  appear  in all copies and that both that copyright no-
+tice and this permission notice appear in  supporting  docu-
+mentation,  and  that the names of Sun or X Consortium
+not be used in advertising or publicity pertaining to 
+distribution  of  the software  without specific prior 
+written permission. Sun and X Consortium make no 
+representations about the suitability of this software for 
+any purpose. It is provided "as is" without any express or 
+implied warranty.
+
+SUN DISCLAIMS ALL WARRANTIES WITH REGARD TO  THIS  SOFTWARE,
+INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FIT-
+NESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SUN BE  LI-
+ABLE  FOR  ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
+ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,  DATA  OR
+PROFITS,  WHETHER  IN  AN  ACTION OF CONTRACT, NEGLIGENCE OR
+OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION  WITH
+THE USE OR PERFORMANCE OF THIS SOFTWARE.
+
+********************************************************/
+
+
+#include "X.h"
+#include "Xproto.h"
+#include "scrnintstr.h"
+#include "colormapst.h"
+#include "resource.h"
+
+#ifdef GLXEXT
+#ifdef GLX_MODULE
+Bool (*GlxInitVisualsPtr)(
+#else
+extern Bool GlxInitVisuals(
+#endif
+#if NeedFunctionPrototypes
+    VisualPtr *         /*visualp*/,
+    DepthPtr *          /*depthp*/,
+    int *               /*nvisualp*/,
+    int *               /*ndepthp*/,
+    int *               /*rootDepthp*/,
+    VisualID *          /*defaultVisp*/,
+    unsigned long       /*sizes*/,
+    int                 /*bitsPerRGB*/
+#endif
+#ifdef GLX_MODULE
+) = NULL;
+#else
+);
+#endif
+#endif
+
+#ifdef STATIC_COLOR
+
+static ColormapPtr InstalledMaps[MAXSCREENS];
+
+int
+cfbListInstalledColormaps(pScreen, pmaps)
+    ScreenPtr  pScreen;
+    Colormap   *pmaps;
+{
+    /* By the time we are processing requests, we can guarantee that there
+     * is always a colormap installed */
+    *pmaps = InstalledMaps[pScreen->myNum]->mid;
+    return (1);
+}
+
+
+void
+cfbInstallColormap(pmap)
+    ColormapPtr        pmap;
+{
+    int index = pmap->pScreen->myNum;
+    ColormapPtr oldpmap = InstalledMaps[index];
+
+    if(pmap != oldpmap)
+    {
+       /* Uninstall pInstalledMap. No hardware changes required, just
+        * notify all interested parties. */
+       if(oldpmap != (ColormapPtr)None)
+           WalkTree(pmap->pScreen, TellLostMap, (char *)&oldpmap->mid);
+       /* Install pmap */
+       InstalledMaps[index] = pmap;
+       WalkTree(pmap->pScreen, TellGainedMap, (char *)&pmap->mid);
+
+    }
+}
+
+void
+cfbUninstallColormap(pmap)
+    ColormapPtr        pmap;
+{
+    int index = pmap->pScreen->myNum;
+    ColormapPtr curpmap = InstalledMaps[index];
+
+    if(pmap == curpmap)
+    {
+       if (pmap->mid != pmap->pScreen->defColormap)
+       {
+           curpmap = (ColormapPtr) LookupIDByType(pmap->pScreen->defColormap,
+                                                  RT_COLORMAP);
+           (*pmap->pScreen->InstallColormap)(curpmap);
+       }
+    }
+}
+
+#endif
+
+void
+cfbResolveColor(pred, pgreen, pblue, pVisual)
+    unsigned short     *pred, *pgreen, *pblue;
+    register VisualPtr pVisual;
+{
+    int shift = 16 - pVisual->bitsPerRGBValue;
+    unsigned lim = (1 << pVisual->bitsPerRGBValue) - 1;
+
+    if ((pVisual->class == PseudoColor) || (pVisual->class == DirectColor))
+    {
+       /* rescale to rgb bits */
+       *pred = ((*pred >> shift) * 65535) / lim;
+       *pgreen = ((*pgreen >> shift) * 65535) / lim;
+       *pblue = ((*pblue >> shift) * 65535) / lim;
+    }
+    else if (pVisual->class == GrayScale)
+    {
+       /* rescale to gray then rgb bits */
+       *pred = (30L * *pred + 59L * *pgreen + 11L * *pblue) / 100;
+       *pblue = *pgreen = *pred = ((*pred >> shift) * 65535) / lim;
+    }
+    else if (pVisual->class == StaticGray)
+    {
+       unsigned limg = pVisual->ColormapEntries - 1;
+       /* rescale to gray then [0..limg] then [0..65535] then rgb bits */
+       *pred = (30L * *pred + 59L * *pgreen + 11L * *pblue) / 100;
+       *pred = ((((*pred * (limg + 1))) >> 16) * 65535) / limg;
+       *pblue = *pgreen = *pred = ((*pred >> shift) * 65535) / lim;
+    }
+    else
+    {
+       unsigned limr, limg, limb;
+
+       limr = pVisual->redMask >> pVisual->offsetRed;
+       limg = pVisual->greenMask >> pVisual->offsetGreen;
+       limb = pVisual->blueMask >> pVisual->offsetBlue;
+       /* rescale to [0..limN] then [0..65535] then rgb bits */
+       *pred = ((((((*pred * (limr + 1)) >> 16) *
+                   65535) / limr) >> shift) * 65535) / lim;
+       *pgreen = ((((((*pgreen * (limg + 1)) >> 16) *
+                     65535) / limg) >> shift) * 65535) / lim;
+       *pblue = ((((((*pblue * (limb + 1)) >> 16) *
+                    65535) / limb) >> shift) * 65535) / lim;
+    }
+}
+
+Bool
+cfbInitializeColormap(pmap)
+    register ColormapPtr       pmap;
+{
+    register unsigned i;
+    register VisualPtr pVisual;
+    unsigned lim, maxent, shift;
+
+    pVisual = pmap->pVisual;
+    lim = (1 << pVisual->bitsPerRGBValue) - 1;
+    shift = 16 - pVisual->bitsPerRGBValue;
+    maxent = pVisual->ColormapEntries - 1;
+    if (pVisual->class == TrueColor)
+    {
+       unsigned limr, limg, limb;
+
+       limr = pVisual->redMask >> pVisual->offsetRed;
+       limg = pVisual->greenMask >> pVisual->offsetGreen;
+       limb = pVisual->blueMask >> pVisual->offsetBlue;
+       for(i = 0; i <= maxent; i++)
+       {
+           /* rescale to [0..65535] then rgb bits */
+           pmap->red[i].co.local.red =
+               ((((i * 65535) / limr) >> shift) * 65535) / lim;
+           pmap->green[i].co.local.green =
+               ((((i * 65535) / limg) >> shift) * 65535) / lim;
+           pmap->blue[i].co.local.blue =
+               ((((i * 65535) / limb) >> shift) * 65535) / lim;
+       }
+    }
+    else if (pVisual->class == StaticColor)
+    {
+       unsigned limr, limg, limb;
+
+       limr = pVisual->redMask >> pVisual->offsetRed;
+       limg = pVisual->greenMask >> pVisual->offsetGreen;
+       limb = pVisual->blueMask >> pVisual->offsetBlue;
+       for(i = 0; i <= maxent; i++)
+       {
+           /* rescale to [0..65535] then rgb bits */
+           pmap->red[i].co.local.red =
+               ((((((i & pVisual->redMask) >> pVisual->offsetRed)
+                   * 65535) / limr) >> shift) * 65535) / lim;
+           pmap->red[i].co.local.green =
+               ((((((i & pVisual->greenMask) >> pVisual->offsetGreen)
+                   * 65535) / limg) >> shift) * 65535) / lim;
+           pmap->red[i].co.local.blue =
+               ((((((i & pVisual->blueMask) >> pVisual->offsetBlue)
+                   * 65535) / limb) >> shift) * 65535) / lim;
+       }
+    }
+    else if (pVisual->class == StaticGray)
+    {
+       for(i = 0; i <= maxent; i++)
+       {
+           /* rescale to [0..65535] then rgb bits */
+           pmap->red[i].co.local.red = ((((i * 65535) / maxent) >> shift)
+                                        * 65535) / lim;
+           pmap->red[i].co.local.green = pmap->red[i].co.local.red;
+           pmap->red[i].co.local.blue = pmap->red[i].co.local.red;
+       }
+    }
+    return TRUE;
+}
+
+/* When simulating DirectColor on PseudoColor hardware, multiple
+   entries of the colormap must be updated
+ */
+
+#define AddElement(mask) { \
+    pixel = red | green | blue; \
+    for (i = 0; i < nresult; i++) \
+       if (outdefs[i].pixel == pixel) \
+           break; \
+    if (i == nresult) \
+    { \
+       nresult++; \
+       outdefs[i].pixel = pixel; \
+       outdefs[i].flags = 0; \
+    } \
+    outdefs[i].flags |= (mask); \
+    outdefs[i].red = pmap->red[red >> pVisual->offsetRed].co.local.red; \
+    outdefs[i].green = pmap->green[green >> pVisual->offsetGreen].co.local.green; \
+    outdefs[i].blue = pmap->blue[blue >> pVisual->offsetBlue].co.local.blue; \
+}
+
+cfbExpandDirectColors (pmap, ndef, indefs, outdefs)
+    ColormapPtr        pmap;
+    int                ndef;
+    xColorItem *indefs, *outdefs;
+{
+    int                    minred, mingreen, minblue;
+    register int    red, green, blue;
+    int                    maxred, maxgreen, maxblue;
+    int                    stepred, stepgreen, stepblue;
+    VisualPtr      pVisual;
+    register int    pixel;
+    register int    nresult;
+    register int    i;
+
+    pVisual = pmap->pVisual;
+
+    stepred = 1 << pVisual->offsetRed;
+    stepgreen = 1 << pVisual->offsetGreen;
+    stepblue = 1 << pVisual->offsetBlue;
+    maxred = pVisual->redMask;
+    maxgreen = pVisual->greenMask;
+    maxblue = pVisual->blueMask;
+    nresult = 0;
+    for (;ndef--; indefs++)
+    {
+       if (indefs->flags & DoRed)
+       {
+           red = indefs->pixel & pVisual->redMask;
+           for (green = 0; green <= maxgreen; green += stepgreen)
+           {
+               for (blue = 0; blue <= maxblue; blue += stepblue)
+               {
+                   AddElement (DoRed)
+               }
+           }
+       }
+       if (indefs->flags & DoGreen)
+       {
+           green = indefs->pixel & pVisual->greenMask;
+           for (red = 0; red <= maxred; red += stepred)
+           {
+               for (blue = 0; blue <= maxblue; blue += stepblue)
+               {
+                   AddElement (DoGreen)
+               }
+           }
+       }
+       if (indefs->flags & DoBlue)
+       {
+           blue = indefs->pixel & pVisual->blueMask;
+           for (red = 0; red <= maxred; red += stepred)
+           {
+               for (green = 0; green <= maxgreen; green += stepgreen)
+               {
+                   AddElement (DoBlue)
+               }
+           }
+       }
+    }
+    return nresult;
+}
+
+Bool
+cfbCreateDefColormap(pScreen)
+    ScreenPtr pScreen;
+{
+    unsigned short     zero = 0, ones = 0xFFFF;
+    VisualPtr  pVisual;
+    ColormapPtr        cmap;
+    Pixel wp, bp;
+    
+    for (pVisual = pScreen->visuals;
+        pVisual->vid != pScreen->rootVisual;
+        pVisual++)
+       ;
+
+    if (CreateColormap(pScreen->defColormap, pScreen, pVisual, &cmap,
+                      (pVisual->class & DynamicClass) ? AllocNone : AllocAll,
+                      0)
+       != Success)
+       return FALSE;
+    wp = pScreen->whitePixel;
+    bp = pScreen->blackPixel;
+    if ((AllocColor(cmap, &ones, &ones, &ones, &wp, 0) !=
+                  Success) ||
+       (AllocColor(cmap, &zero, &zero, &zero, &bp, 0) !=
+                  Success))
+       return FALSE;
+    pScreen->whitePixel = wp;
+    pScreen->blackPixel = bp;
+    (*pScreen->InstallColormap)(cmap);
+    return TRUE;
+}
+
+extern int defaultColorVisualClass;
+
+#define _RZ(d) ((d + 2) / 3)
+#define _RS(d) 0
+#define _RM(d) ((1 << _RZ(d)) - 1)
+#define _GZ(d) ((d - _RZ(d) + 1) / 2)
+#define _GS(d) _RZ(d)
+#define _GM(d) (((1 << _GZ(d)) - 1) << _GS(d))
+#define _BZ(d) (d - _RZ(d) - _GZ(d))
+#define _BS(d) (_RZ(d) + _GZ(d))
+#define _BM(d) (((1 << _BZ(d)) - 1) << _BS(d))
+#define _CE(d) (1 << _RZ(d))
+
+#define MAX_PSEUDO_DEPTH    10     /* largest DAC size I know */
+
+#define StaticGrayMask (1 << StaticGray)
+#define GrayScaleMask  (1 << GrayScale)
+#define StaticColorMask        (1 << StaticColor)
+#define PseudoColorMask        (1 << PseudoColor)
+#define TrueColorMask  (1 << TrueColor)
+#define DirectColorMask (1 << DirectColor)
+
+#define ALL_VISUALS    (StaticGrayMask|\
+                        GrayScaleMask|\
+                        StaticColorMask|\
+                        PseudoColorMask|\
+                        TrueColorMask|\
+                        DirectColorMask)
+
+#define LARGE_VISUALS  (TrueColorMask|\
+                        DirectColorMask)
+
+typedef struct _cfbVisuals {
+    struct _cfbVisuals *next;
+    int                        depth;
+    int                        bitsPerRGB;
+    int                        visuals;
+    int                        count;
+} cfbVisualsRec, *cfbVisualsPtr;
+
+static int  cfbVisualPriority[] = {
+    PseudoColor, DirectColor, GrayScale, StaticColor, TrueColor, StaticGray
+};
+
+#define NUM_PRIORITY   6
+
+static cfbVisualsPtr   cfbVisuals;
+
+Bool
+cfbSetVisualTypes (depth, visuals, bitsPerRGB)
+    int            depth;
+    int            visuals;
+{
+    cfbVisualsPtr   new, *prev, v;
+    int                    count;
+
+    new = (cfbVisualsPtr) xalloc (sizeof *new);
+    if (!new)
+       return FALSE;
+    new->next = 0;
+    new->depth = depth;
+    new->visuals = visuals;
+    new->bitsPerRGB = bitsPerRGB;
+    count = (visuals >> 1) & 033333333333;
+    count = visuals - count - ((count >> 1) & 033333333333);
+    count = (((count + (count >> 3)) & 030707070707) % 077);   /* HAKMEM 169 */
+    new->count = count;
+    for (prev = &cfbVisuals; v = *prev; prev = &v->next);
+    *prev = new;
+    return TRUE;
+}
+
+/*
+ * Given a list of formats for a screen, create a list
+ * of visuals and depths for the screen which coorespond to
+ * the set which can be used with this version of cfb.
+ */
+
+Bool
+cfbInitVisuals (visualp, depthp, nvisualp, ndepthp, rootDepthp, defaultVisp, sizes, bitsPerRGB)
+    VisualPtr  *visualp;
+    DepthPtr   *depthp;
+    int                *nvisualp, *ndepthp;
+    int                *rootDepthp;
+    VisualID   *defaultVisp;
+    unsigned long   sizes;
+    int                bitsPerRGB;
+{
+    int                i, j, k;
+    VisualPtr  visual;
+    DepthPtr   depth;
+    VisualID   *vid;
+    int                d, b;
+    int                f;
+    int                ndepth, nvisual;
+    int                nvtype;
+    int                vtype;
+    VisualID   defaultVisual;
+    cfbVisualsPtr   visuals, nextVisuals;
+
+    /* none specified, we'll guess from pixmap formats */
+    if (!cfbVisuals) 
+    {
+       for (f = 0; f < screenInfo.numPixmapFormats; f++) 
+       {
+           d = screenInfo.formats[f].depth;
+           b = screenInfo.formats[f].bitsPerPixel;
+           if (sizes & (1 << (b - 1)))
+           {
+               if (d > MAX_PSEUDO_DEPTH)
+                   vtype = LARGE_VISUALS;
+               else if (d == 1)
+                   vtype = StaticGrayMask;
+               else
+                   vtype = ALL_VISUALS;
+           }
+           else
+               vtype = 0;
+           if (!cfbSetVisualTypes (d, vtype, bitsPerRGB))
+               return FALSE;
+       }
+    }
+    nvisual = 0;
+    ndepth = 0;
+    for (visuals = cfbVisuals; visuals; visuals = nextVisuals) 
+    {
+       nextVisuals = visuals->next;
+       ndepth++;
+       nvisual += visuals->count;
+    }
+    depth = (DepthPtr) xalloc (ndepth * sizeof (DepthRec));
+    visual = (VisualPtr) xalloc (nvisual * sizeof (VisualRec));
+    if (!depth || !visual)
+    {
+       xfree (depth);
+       xfree (visual);
+       return FALSE;
+    }
+    *depthp = depth;
+    *visualp = visual;
+    *ndepthp = ndepth;
+    *nvisualp = nvisual;
+    for (visuals = cfbVisuals; visuals; visuals = nextVisuals) 
+    {
+       nextVisuals = visuals->next;
+       d = visuals->depth;
+       vtype = visuals->visuals;
+       nvtype = visuals->count;
+       vid = NULL;
+       if (nvtype)
+       {
+           vid = (VisualID *) xalloc (nvtype * sizeof (VisualID));
+           if (!vid)
+               return FALSE;
+       }
+       depth->depth = d;
+       depth->numVids = nvtype;
+       depth->vids = vid;
+       depth++;
+       for (i = 0; i < NUM_PRIORITY; i++) {
+           if (! (vtype & (1 << cfbVisualPriority[i])))
+               continue;
+           visual->class = cfbVisualPriority[i];
+           visual->bitsPerRGBValue = visuals->bitsPerRGB;
+           visual->ColormapEntries = 1 << d;
+           visual->nplanes = d;
+           visual->vid = *vid = FakeClientID (0);
+           switch (visual->class) {
+           case PseudoColor:
+           case GrayScale:
+           case StaticGray:
+               visual->redMask = 0;
+               visual->greenMask =  0;
+               visual->blueMask =  0;
+               visual->offsetRed  =  0;
+               visual->offsetGreen = 0;
+               visual->offsetBlue =  0;
+               break;
+           case DirectColor:
+           case TrueColor:
+               visual->ColormapEntries = _CE(d);
+               /* fall through */
+           case StaticColor:
+               visual->redMask =  _RM(d);
+               visual->greenMask =  _GM(d);
+               visual->blueMask =  _BM(d);
+               visual->offsetRed  =  _RS(d);
+               visual->offsetGreen = _GS(d);
+               visual->offsetBlue =  _BS(d);
+           }
+           vid++;
+           visual++;
+       }
+       xfree (visuals);
+    }
+    cfbVisuals = NULL;
+    visual = *visualp;
+    depth = *depthp;
+    for (i = 0; i < ndepth; i++)
+    {
+       if (*rootDepthp && *rootDepthp != depth[i].depth)
+           continue;
+       for (j = 0; j < depth[i].numVids; j++)
+       {
+           for (k = 0; k < nvisual; k++)
+               if (visual[k].vid == depth[i].vids[j])
+                   break;
+           if (k == nvisual)
+               continue;
+           if (defaultColorVisualClass < 0 ||
+               visual[k].class == defaultColorVisualClass)
+               break;
+       }
+       if (j != depth[i].numVids)
+           break;
+    }
+    if (i == ndepth) {
+       i = 0;
+       j = 0;
+    }
+    *rootDepthp = depth[i].depth;
+    *defaultVisp = depth[i].vids[j];
+
+#ifdef GLXEXT
+#ifdef GLX_MODULE
+    if( GlxInitVisualsPtr != NULL ) 
+       return (*GlxInitVisualsPtr)
+#else
+    return GlxInitVisuals
+#endif
+          (
+               visualp, 
+               depthp,
+               nvisualp,
+               ndepthp,
+               rootDepthp,
+               defaultVisp,
+               sizes,
+               bitsPerRGB
+           );
+#else
+    return TRUE;
+#endif
+
+}
diff --git a/Xserver/programs/Xserver/cfb/cfbfillarc.c b/Xserver/programs/Xserver/cfb/cfbfillarc.c
new file mode 100644 (file)
index 0000000..2658dcb
--- /dev/null
@@ -0,0 +1,369 @@
+/************************************************************
+
+Copyright (c) 1989  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+********************************************************/
+
+/* $XConsortium: cfbfillarc.c /main/17 1995/12/06 16:57:18 dpw $ */
+/* $XFree86: xc/programs/Xserver/cfb/cfbfillarc.c,v 3.1 1996/08/13 11:27:33 dawes Exp $ */
+
+#include "X.h"
+#include "Xprotostr.h"
+#include "miscstruct.h"
+#include "gcstruct.h"
+#include "pixmapstr.h"
+#include "scrnintstr.h"
+#include "cfb.h"
+#include "cfbmskbits.h"
+#include "mifillarc.h"
+#include "cfbrrop.h"
+#include "mi.h"
+
+/* gcc 1.35 is stupid */
+#if defined(__GNUC__) && __GNUC__ < 2 && defined(mc68020)
+#define STUPID volatile
+#else
+#define STUPID
+#endif
+
+static void
+RROP_NAME(cfbFillEllipseSolid) (pDraw, pGC, arc)
+    DrawablePtr pDraw;
+    GCPtr pGC;
+    xArc *arc;
+{
+    STUPID int x, y, e;
+    STUPID int yk, xk, ym, xm, dx, dy, xorg, yorg;
+    miFillArcRec info;
+#if PSZ == 24
+    unsigned char *addrlt, *addrlb;
+#else
+    unsigned long *addrlt, *addrlb;
+#endif
+    register unsigned long *addrl;
+    register int n;
+    int nlwidth;
+    RROP_DECLARE
+    register int xpos;
+    register int slw;
+    unsigned long startmask, endmask;
+    int        nlmiddle;
+#if PSZ == 24
+    register int pidx;
+    int xpos3;
+#endif
+
+#if PSZ == 24
+    cfbGetByteWidthAndPointer (pDraw, nlwidth, addrlt)
+#else
+    cfbGetLongWidthAndPointer (pDraw, nlwidth, addrlt)
+#endif
+
+    RROP_FETCH_GC(pGC);
+    miFillArcSetup(arc, &info);
+    MIFILLARCSETUP();
+    xorg += pDraw->x;
+    yorg += pDraw->y;
+    addrlb = addrlt;
+    addrlt += nlwidth * (yorg - y);
+    addrlb += nlwidth * (yorg + y + dy);
+    while (y)
+    {
+       addrlt += nlwidth;
+       addrlb -= nlwidth;
+       MIFILLARCSTEP(slw);
+       if (!slw)
+           continue;
+       xpos = xorg - x;
+#if PSZ == 24
+       xpos3 = (xpos * 3) & ~0x03;
+       addrl = (unsigned long *)((char *)addrlt + xpos3);
+       if (slw == 1){
+         RROP_SOLID24(addrl, xpos);
+         if (miFillArcLower(slw)){
+           addrl = (unsigned long *)((char *)addrlb + xpos3);
+           RROP_SOLID24(addrl, xpos);
+          }
+         continue;
+       }
+       maskbits(xpos, slw, startmask, endmask, nlmiddle);
+       xpos &= 3;
+       pidx = xpos;
+       if (startmask){
+         RROP_SOLID_MASK(addrl, startmask, pidx-1);
+         addrl++;
+         if (pidx == 3)
+           pidx = 0;
+       }
+       n = nlmiddle;
+       while (--n >= 0){
+         RROP_SOLID(addrl, pidx);
+         addrl++;
+         if (++pidx == 3)
+           pidx = 0;
+       }
+       if (endmask)
+         RROP_SOLID_MASK(addrl, endmask, pidx);
+       if (!miFillArcLower(slw))
+         continue;
+       addrl = (unsigned long *)((char *)addrlb + xpos3);
+       pidx = xpos;
+       if (startmask){
+         RROP_SOLID_MASK(addrl, startmask, pidx-1);
+         addrl++;
+         if (pidx == 3)
+           pidx = 0;
+       }
+       n = nlmiddle;
+       while (--n >= 0){
+         RROP_SOLID(addrl, pidx);
+         addrl++;
+         if (++pidx == 3)
+           pidx = 0;
+       }
+       if (endmask)
+         RROP_SOLID_MASK(addrl, endmask, pidx);
+#else /* PSZ == 24 */
+       addrl = addrlt + (xpos >> PWSH);
+       if (((xpos & PIM) + slw) <= PPW)
+       {
+           maskpartialbits(xpos, slw, startmask);
+           RROP_SOLID_MASK(addrl,startmask);
+           if (miFillArcLower(slw))
+           {
+               addrl = addrlb + (xpos >> PWSH);
+               RROP_SOLID_MASK(addrl, startmask);
+           }
+           continue;
+       }
+       maskbits(xpos, slw, startmask, endmask, nlmiddle);
+       if (startmask)
+       {
+           RROP_SOLID_MASK(addrl, startmask);
+           addrl++;
+       }
+       n = nlmiddle;
+       RROP_SPAN(addrl,n)
+
+       if (endmask)
+           RROP_SOLID_MASK(addrl, endmask);
+       if (!miFillArcLower(slw))
+           continue;
+       addrl = addrlb + (xpos >> PWSH);
+       if (startmask)
+       {
+           RROP_SOLID_MASK(addrl, startmask);
+           addrl++;
+       }
+       n = nlmiddle;
+       RROP_SPAN(addrl, n);
+       if (endmask)
+           RROP_SOLID_MASK(addrl, endmask);
+#endif /* PSZ == 24 */
+    }
+}
+
+#if PSZ == 24
+#define FILLSPAN(xl,xr,addr) \
+    if (xr >= xl){ \
+       n = xr - xl + 1; \
+       addrl = (unsigned long *)((char *)addr + ((xl * 3) & ~0x03)); \
+       if (n <= 1){ \
+          if (n) \
+            RROP_SOLID24(addrl, xl); \
+       } else { \
+         maskbits(xl, n, startmask, endmask, n); \
+          pidx = xl & 3; \
+         if (startmask){ \
+           RROP_SOLID_MASK(addrl, startmask, pidx-1); \
+           addrl++; \
+           if (pidx == 3) \
+             pidx = 0; \
+         } \
+         while (--n >= 0){ \
+           RROP_SOLID(addrl, pidx); \
+           addrl++; \
+           if (++pidx == 3) \
+             pidx = 0; \
+         } \
+         if (endmask) \
+           RROP_SOLID_MASK(addrl, endmask, pidx); \
+       } \
+    }
+#else /* PSZ == 24 */
+#define FILLSPAN(xl,xr,addr) \
+    if (xr >= xl) \
+    { \
+       n = xr - xl + 1; \
+       addrl = addr + (xl >> PWSH); \
+       if (((xl & PIM) + n) <= PPW) \
+       { \
+           maskpartialbits(xl, n, startmask); \
+           RROP_SOLID_MASK(addrl, startmask); \
+       } \
+       else \
+       { \
+           maskbits(xl, n, startmask, endmask, n); \
+           if (startmask) \
+           { \
+               RROP_SOLID_MASK(addrl, startmask); \
+               addrl++; \
+           } \
+           while (n--) \
+           { \
+               RROP_SOLID(addrl); \
+               ++addrl; \
+           } \
+           if (endmask) \
+               RROP_SOLID_MASK(addrl, endmask); \
+       } \
+    }
+#endif /* PSZ == 24 */
+
+#define FILLSLICESPANS(flip,addr) \
+    if (!flip) \
+    { \
+       FILLSPAN(xl, xr, addr); \
+    } \
+    else \
+    { \
+       xc = xorg - x; \
+       FILLSPAN(xc, xr, addr); \
+       xc += slw - 1; \
+       FILLSPAN(xl, xc, addr); \
+    }
+
+static void
+RROP_NAME(cfbFillArcSliceSolid)(pDraw, pGC, arc)
+    DrawablePtr pDraw;
+    GCPtr pGC;
+    xArc *arc;
+{
+    int yk, xk, ym, xm, dx, dy, xorg, yorg, slw;
+    register int x, y, e;
+    miFillArcRec info;
+    miArcSliceRec slice;
+    int xl, xr, xc;
+#if PSZ == 24
+    unsigned char *addrlt, *addrlb;
+#else
+    unsigned long *addrlt, *addrlb;
+#endif
+    register unsigned long *addrl;
+    register int n;
+    int nlwidth;
+    RROP_DECLARE
+    unsigned long startmask, endmask;
+#if PSZ == 24
+    register int pidx;
+#endif /* PSZ == 24 */
+
+#if PSZ == 24
+    cfbGetByteWidthAndPointer (pDraw, nlwidth, addrlt)
+#else
+    cfbGetLongWidthAndPointer (pDraw, nlwidth, addrlt)
+#endif
+
+    RROP_FETCH_GC(pGC);
+    miFillArcSetup(arc, &info);
+    miFillArcSliceSetup(arc, &slice, pGC);
+    MIFILLARCSETUP();
+    xorg += pDraw->x;
+    yorg += pDraw->y;
+    addrlb = addrlt;
+    addrlt += nlwidth * (yorg - y);
+    addrlb += nlwidth * (yorg + y + dy);
+    slice.edge1.x += pDraw->x;
+    slice.edge2.x += pDraw->x;
+    while (y > 0)
+    {
+       addrlt += nlwidth;
+       addrlb -= nlwidth;
+       MIFILLARCSTEP(slw);
+       MIARCSLICESTEP(slice.edge1);
+       MIARCSLICESTEP(slice.edge2);
+       if (miFillSliceUpper(slice))
+       {
+           MIARCSLICEUPPER(xl, xr, slice, slw);
+           FILLSLICESPANS(slice.flip_top, addrlt);
+       }
+       if (miFillSliceLower(slice))
+       {
+           MIARCSLICELOWER(xl, xr, slice, slw);
+           FILLSLICESPANS(slice.flip_bot, addrlb);
+       }
+    }
+}
+
+void
+RROP_NAME(cfbPolyFillArcSolid) (pDraw, pGC, narcs, parcs)
+    DrawablePtr        pDraw;
+    GCPtr      pGC;
+    int                narcs;
+    xArc       *parcs;
+{
+    register xArc *arc;
+    register int i;
+    int x2, y2;
+    BoxRec box;
+    RegionPtr cclip;
+
+    cclip = cfbGetCompositeClip(pGC);
+    for (arc = parcs, i = narcs; --i >= 0; arc++)
+    {
+       if (miFillArcEmpty(arc))
+           continue;
+       if (miCanFillArc(arc))
+       {
+           box.x1 = arc->x + pDraw->x;
+           box.y1 = arc->y + pDraw->y;
+           /*
+            * Because box.x2 and box.y2 get truncated to 16 bits, and the
+            * RECT_IN_REGION test treats the resulting number as a signed
+            * integer, the RECT_IN_REGION test alone can go the wrong way.
+            * This can result in a server crash because the rendering
+            * routines in this file deal directly with cpu addresses
+            * of pixels to be stored, and do not clip or otherwise check
+            * that all such addresses are within their respective pixmaps.
+            * So we only allow the RECT_IN_REGION test to be used for
+            * values that can be expressed correctly in a signed short.
+            */
+           x2 = box.x1 + (int)arc->width + 1;
+           box.x2 = x2;
+           y2 = box.y1 + (int)arc->height + 1;
+           box.y2 = y2;
+           if ( (x2 <= MAXSHORT) && (y2 <= MAXSHORT) &&
+                   (RECT_IN_REGION(pDraw->pScreen, cclip, &box) == rgnIN) )
+           {
+               if ((arc->angle2 >= FULLCIRCLE) ||
+                   (arc->angle2 <= -FULLCIRCLE))
+                   RROP_NAME(cfbFillEllipseSolid)(pDraw, pGC, arc);
+               else
+                   RROP_NAME(cfbFillArcSliceSolid)(pDraw, pGC, arc);
+               continue;
+           }
+       }
+       miPolyFillArc(pDraw, pGC, 1, arc);
+    }
+}
diff --git a/Xserver/programs/Xserver/cfb/cfbfillrct.c b/Xserver/programs/Xserver/cfb/cfbfillrct.c
new file mode 100644 (file)
index 0000000..f205ace
--- /dev/null
@@ -0,0 +1,304 @@
+/*
+ * Fill rectangles.
+ */
+
+/*
+
+Copyright (c) 1989  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+*/
+
+/* $XConsortium: cfbfillrct.c,v 5.18 94/04/17 20:28:47 dpw Exp $ */
+/* $XFree86: xc/programs/Xserver/cfb/cfbfillrct.c,v 3.1.4.1 1997/05/10 07:02:48 hohndel Exp $ */
+
+#include "X.h"
+#include "Xmd.h"
+#include "servermd.h"
+#include "gcstruct.h"
+#include "window.h"
+#include "pixmapstr.h"
+#include "scrnintstr.h"
+#include "windowstr.h"
+
+#include "cfb.h"
+#include "cfbmskbits.h"
+#include "mergerop.h"
+
+
+void
+cfbFillBoxTileOdd (pDrawable, n, rects, tile, xrot, yrot)
+    DrawablePtr        pDrawable;
+    int                n;
+    BoxPtr     rects;
+    PixmapPtr  tile;
+    int                xrot, yrot;
+{
+#if PSZ == 24
+    if (tile->drawable.width & 3)
+#else
+    if (tile->drawable.width & PIM)
+#endif
+       cfbFillBoxTileOddCopy (pDrawable, n, rects, tile, xrot, yrot, GXcopy, ~0L);
+    else
+       cfbFillBoxTile32sCopy (pDrawable, n, rects, tile, xrot, yrot, GXcopy, ~0L);
+}
+
+void
+cfbFillRectTileOdd (pDrawable, pGC, nBox, pBox)
+    DrawablePtr        pDrawable;
+    GCPtr      pGC;
+    int                nBox;
+    BoxPtr     pBox;
+{
+    int        xrot, yrot;
+    void    (*fill)();
+
+    xrot = pDrawable->x + pGC->patOrg.x;
+    yrot = pDrawable->y + pGC->patOrg.y;
+#if PSZ == 24
+    if (pGC->tile.pixmap->drawable.width & 3)
+#else
+    if (pGC->tile.pixmap->drawable.width & PIM)
+#endif
+    {
+       fill = cfbFillBoxTileOddGeneral;
+       if ((pGC->planemask & PMSK) == PMSK)
+       {
+           if (pGC->alu == GXcopy)
+               fill = cfbFillBoxTileOddCopy;
+       }
+    }
+    else
+    {
+       fill = cfbFillBoxTile32sGeneral;
+       if ((pGC->planemask & PMSK) == PMSK)
+       {
+           if (pGC->alu == GXcopy)
+               fill = cfbFillBoxTile32sCopy;
+       }
+    }
+    (*fill) (pDrawable, nBox, pBox, pGC->tile.pixmap, xrot, yrot, pGC->alu, pGC->planemask);
+}
+
+#define NUM_STACK_RECTS        1024
+
+void
+cfbPolyFillRect(pDrawable, pGC, nrectFill, prectInit)
+    DrawablePtr pDrawable;
+    register GCPtr pGC;
+    int                nrectFill;      /* number of rectangles to fill */
+    xRectangle *prectInit;     /* Pointer to first rectangle to fill */
+{
+    xRectangle     *prect;
+    RegionPtr      prgnClip;
+    register BoxPtr pbox;
+    register BoxPtr pboxClipped;
+    BoxPtr         pboxClippedBase;
+    BoxPtr         pextent;
+    BoxRec         stackRects[NUM_STACK_RECTS];
+    cfbPrivGC      *priv;
+    int                    numRects;
+    void           (*BoxFill)();
+    int                    n;
+    int                    xorg, yorg;
+
+#if PSZ != 8
+    if ((pGC->fillStyle == FillStippled) ||
+       (pGC->fillStyle == FillOpaqueStippled)) {
+       miPolyFillRect(pDrawable, pGC, nrectFill, prectInit);
+       return;
+    }
+#endif
+
+    priv = cfbGetGCPrivate(pGC);
+    prgnClip = priv->pCompositeClip;
+
+    BoxFill = 0;
+    switch (pGC->fillStyle)
+    {
+    case FillSolid:
+       switch (priv->rop) {
+       case GXcopy:
+           BoxFill = cfbFillRectSolidCopy;
+           break;
+       case GXxor:
+           BoxFill = cfbFillRectSolidXor;
+           break;
+       default:
+           BoxFill = cfbFillRectSolidGeneral;
+           break;
+       }
+       break;
+    case FillTiled:
+       if (!cfbGetGCPrivate(pGC)->pRotatedPixmap)
+           BoxFill = cfbFillRectTileOdd;
+       else
+       {
+           if (pGC->alu == GXcopy && (pGC->planemask & PMSK) == PMSK)
+               BoxFill = cfbFillRectTile32Copy;
+           else
+               BoxFill = cfbFillRectTile32General;
+       }
+       break;
+#if PSZ == 8
+    case FillStippled:
+       if (!cfbGetGCPrivate(pGC)->pRotatedPixmap)
+           BoxFill = cfb8FillRectStippledUnnatural;
+       else
+           BoxFill = cfb8FillRectTransparentStippled32;
+       break;
+    case FillOpaqueStippled:
+       if (!cfbGetGCPrivate(pGC)->pRotatedPixmap)
+           BoxFill = cfb8FillRectStippledUnnatural;
+       else
+           BoxFill = cfb8FillRectOpaqueStippled32;
+       break;
+#endif
+    }
+    prect = prectInit;
+    xorg = pDrawable->x;
+    yorg = pDrawable->y;
+    if (xorg || yorg)
+    {
+       prect = prectInit;
+       n = nrectFill;
+       while(n--)
+       {
+           prect->x += xorg;
+           prect->y += yorg;
+           prect++;
+       }
+    }
+
+    prect = prectInit;
+
+    numRects = REGION_NUM_RECTS(prgnClip) * nrectFill;
+    if (numRects > NUM_STACK_RECTS)
+    {
+       pboxClippedBase = (BoxPtr)ALLOCATE_LOCAL(numRects * sizeof(BoxRec));
+       if (!pboxClippedBase)
+           return;
+    }
+    else
+       pboxClippedBase = stackRects;
+
+    pboxClipped = pboxClippedBase;
+       
+    if (REGION_NUM_RECTS(prgnClip) == 1)
+    {
+       int x1, y1, x2, y2, bx2, by2;
+
+       pextent = REGION_RECTS(prgnClip);
+       x1 = pextent->x1;
+       y1 = pextent->y1;
+       x2 = pextent->x2;
+       y2 = pextent->y2;
+       while (nrectFill--)
+       {
+           if ((pboxClipped->x1 = prect->x) < x1)
+               pboxClipped->x1 = x1;
+    
+           if ((pboxClipped->y1 = prect->y) < y1)
+               pboxClipped->y1 = y1;
+    
+           bx2 = (int) prect->x + (int) prect->width;
+           if (bx2 > x2)
+               bx2 = x2;
+           pboxClipped->x2 = bx2;
+    
+           by2 = (int) prect->y + (int) prect->height;
+           if (by2 > y2)
+               by2 = y2;
+           pboxClipped->y2 = by2;
+
+           prect++;
+           if ((pboxClipped->x1 < pboxClipped->x2) &&
+               (pboxClipped->y1 < pboxClipped->y2))
+           {
+               pboxClipped++;
+           }
+       }
+    }
+    else
+    {
+       int x1, y1, x2, y2, bx2, by2;
+
+       pextent = REGION_EXTENTS(pGC->pScreen, prgnClip);
+       x1 = pextent->x1;
+       y1 = pextent->y1;
+       x2 = pextent->x2;
+       y2 = pextent->y2;
+       while (nrectFill--)
+       {
+           BoxRec box;
+    
+           if ((box.x1 = prect->x) < x1)
+               box.x1 = x1;
+    
+           if ((box.y1 = prect->y) < y1)
+               box.y1 = y1;
+    
+           bx2 = (int) prect->x + (int) prect->width;
+           if (bx2 > x2)
+               bx2 = x2;
+           box.x2 = bx2;
+    
+           by2 = (int) prect->y + (int) prect->height;
+           if (by2 > y2)
+               by2 = y2;
+           box.y2 = by2;
+    
+           prect++;
+    
+           if ((box.x1 >= box.x2) || (box.y1 >= box.y2))
+               continue;
+    
+           n = REGION_NUM_RECTS (prgnClip);
+           pbox = REGION_RECTS(prgnClip);
+    
+           /* clip the rectangle to each box in the clip region
+              this is logically equivalent to calling Intersect()
+           */
+           while(n--)
+           {
+               pboxClipped->x1 = max(box.x1, pbox->x1);
+               pboxClipped->y1 = max(box.y1, pbox->y1);
+               pboxClipped->x2 = min(box.x2, pbox->x2);
+               pboxClipped->y2 = min(box.y2, pbox->y2);
+               pbox++;
+
+               /* see if clipping left anything */
+               if(pboxClipped->x1 < pboxClipped->x2 && 
+                  pboxClipped->y1 < pboxClipped->y2)
+               {
+                   pboxClipped++;
+               }
+           }
+       }
+    }
+    if (pboxClipped != pboxClippedBase)
+       (*BoxFill) (pDrawable, pGC,
+                   pboxClipped-pboxClippedBase, pboxClippedBase);
+    if (pboxClippedBase != stackRects)
+       DEALLOCATE_LOCAL(pboxClippedBase);
+}
diff --git a/Xserver/programs/Xserver/cfb/cfbfillsp.c b/Xserver/programs/Xserver/cfb/cfbfillsp.c
new file mode 100644 (file)
index 0000000..f68a77b
--- /dev/null
@@ -0,0 +1,1001 @@
+/************************************************************
+Copyright 1987 by Sun Microsystems, Inc. Mountain View, CA.
+
+                    All Rights Reserved
+
+Permission  to  use,  copy,  modify,  and  distribute   this
+software  and  its documentation for any purpose and without
+fee is hereby granted, provided that the above copyright no-
+tice  appear  in all copies and that both that copyright no-
+tice and this permission notice appear in  supporting  docu-
+mentation,  and  that the names of Sun or X Consortium
+not be used in advertising or publicity pertaining to 
+distribution  of  the software  without specific prior 
+written permission. Sun and X Consortium make no 
+representations about the suitability of this software for 
+any purpose. It is provided "as is" without any express or 
+implied warranty.
+
+SUN DISCLAIMS ALL WARRANTIES WITH REGARD TO  THIS  SOFTWARE,
+INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FIT-
+NESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SUN BE  LI-
+ABLE  FOR  ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
+ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,  DATA  OR
+PROFITS,  WHETHER  IN  AN  ACTION OF CONTRACT, NEGLIGENCE OR
+OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION  WITH
+THE USE OR PERFORMANCE OF THIS SOFTWARE.
+
+********************************************************/
+
+/***********************************************************
+
+Copyright (c) 1987  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+
+Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
+
+                        All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and its 
+documentation for any purpose and without fee is hereby granted, 
+provided that the above copyright notice appear in all copies and that
+both that copyright notice and this permission notice appear in 
+supporting documentation, and that the name of Digital not be
+used in advertising or publicity pertaining to distribution of the
+software without specific, written prior permission.  
+
+DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
+ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
+DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
+ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+SOFTWARE.
+
+******************************************************************/
+
+/* $XConsortium: cfbfillsp.c,v 5.24 94/04/17 20:28:48 dpw Exp $ */
+/* $XFree86: xc/programs/Xserver/cfb/cfbfillsp.c,v 3.1 1996/12/09 11:50:54 dawes Exp $ */
+
+#include "X.h"
+#include "Xmd.h"
+#include "servermd.h"
+#include "gcstruct.h"
+#include "window.h"
+#include "pixmapstr.h"
+#include "scrnintstr.h"
+#include "windowstr.h"
+
+#include "cfb.h"
+#include "cfbmskbits.h"
+
+#include "mergerop.h"
+
+#if PSZ == 8
+#include "cfb8bit.h"
+#endif
+
+#define MFB_CONSTS_ONLY
+#include "maskbits.h"
+
+#include "mi.h"
+#include "mispans.h"
+
+/* scanline filling for color frame buffer
+   written by drewry, oct 1986 modified by smarks
+   changes for compatibility with Little-endian systems Jul 1987; MIT:yba.
+
+   these routines all clip.  they assume that anything that has called
+them has already translated the points (i.e. pGC->miTranslate is
+non-zero, which is howit gets set in cfbCreateGC().)
+
+   the number of new scnalines created by clipping ==
+MaxRectsPerBand * nSpans.
+
+    FillSolid is overloaded to be used for OpaqueStipple as well,
+if fgPixel == bgPixel.  
+Note that for solids, PrivGC.rop == PrivGC.ropOpStip
+
+
+    FillTiled is overloaded to be used for OpaqueStipple, if
+fgPixel != bgPixel.  based on the fill style, it uses
+{RotatedTile, gc.alu} or {RotatedStipple, PrivGC.ropOpStip}
+*/
+
+#ifdef notdef
+#include       <stdio.h>
+static
+dumpspans(n, ppt, pwidth)
+    int        n;
+    DDXPointPtr ppt;
+    int *pwidth;
+{
+    fprintf(stderr,"%d spans\n", n);
+    while (n--) {
+       fprintf(stderr, "[%d,%d] %d\n", ppt->x, ppt->y, *pwidth);
+       ppt++;
+       pwidth++;
+    }
+    fprintf(stderr, "\n");
+}
+#endif
+
+/* Fill spans with tiles that aren't 32 bits wide */
+void
+cfbUnnaturalTileFS(pDrawable, pGC, nInit, pptInit, pwidthInit, fSorted)
+DrawablePtr pDrawable;
+GC             *pGC;
+int            nInit;          /* number of spans to fill */
+DDXPointPtr pptInit;           /* pointer to list of start points */
+int *pwidthInit;               /* pointer to list of n widths */
+int fSorted;
+{
+    int n;                     /* number of spans to fill */
+    register DDXPointPtr ppt;  /* pointer to list of start points */
+    register int *pwidth;      /* pointer to list of n widths */
+    void    (*fill)();
+    int        xrot, yrot;
+
+    if (!(pGC->planemask))
+       return;
+
+#if PSZ == 24
+    if (pGC->tile.pixmap->drawable.width & 3)
+#else
+    if (pGC->tile.pixmap->drawable.width & PIM)
+#endif
+    {
+       fill = cfbFillSpanTileOddGeneral;
+       if ((pGC->planemask & PMSK) == PMSK)
+       {
+           if (pGC->alu == GXcopy)
+               fill = cfbFillSpanTileOddCopy;
+       }
+    }
+    else
+    {
+       fill = cfbFillSpanTile32sGeneral;
+       if ((pGC->planemask & PMSK) == PMSK)
+       {
+           if (pGC->alu == GXcopy)
+               fill = cfbFillSpanTile32sCopy;
+       }
+    }
+    n = nInit * miFindMaxBand( cfbGetCompositeClip(pGC) );
+    if ( n == 0 )
+       return;
+    pwidth = (int *)ALLOCATE_LOCAL(n * sizeof(int));
+    ppt = (DDXPointRec *)ALLOCATE_LOCAL(n * sizeof(DDXPointRec));
+    if(!ppt || !pwidth)
+    {
+       if (ppt) DEALLOCATE_LOCAL(ppt);
+       if (pwidth) DEALLOCATE_LOCAL(pwidth);
+       return;
+    }
+    n = miClipSpans( cfbGetCompositeClip(pGC),
+                    pptInit, pwidthInit, nInit, 
+                    ppt, pwidth, fSorted);
+
+    xrot = pDrawable->x + pGC->patOrg.x;
+    yrot = pDrawable->y + pGC->patOrg.y;
+
+    (*fill) (pDrawable, n, ppt, pwidth, pGC->tile.pixmap, xrot, yrot, pGC->alu, pGC->planemask);
+
+    DEALLOCATE_LOCAL(ppt);
+    DEALLOCATE_LOCAL(pwidth);
+}
+
+#if PSZ == 8
+
+void
+cfbUnnaturalStippleFS(pDrawable, pGC, nInit, pptInit, pwidthInit, fSorted)
+DrawablePtr pDrawable;
+GC             *pGC;
+int            nInit;          /* number of spans to fill */
+DDXPointPtr pptInit;           /* pointer to list of start points */
+int *pwidthInit;               /* pointer to list of n widths */
+int fSorted;
+{
+                               /* next three parameters are post-clip */
+    int                    n;          /* number of spans to fill */
+    DDXPointPtr            ppt;        /* pointer to list of start points */
+    int                    *pwidth;    /* pointer to list of n widths */
+    int                    *pwidthFree;/* copies of the pointers to free */
+    DDXPointPtr            pptFree;
+    unsigned long   *pdstBase; /* pointer to start of bitmap */
+    int                    nlwDst;     /* width in longwords of bitmap */
+    register unsigned long    *pdst;   /* pointer to current word in bitmap */
+    PixmapPtr      pStipple;   /* pointer to stipple we want to fill with */
+    int                    nlw;
+    int                    x, y, w, xrem, xSrc, ySrc;
+    int                    stwidth, stippleWidth;
+    int                    stippleHeight;
+    register unsigned long  bits, inputBits;
+    register int    partBitsLeft;
+    int                    nextPartBits;
+    int                    bitsLeft, bitsWhole;
+    unsigned long   *srcTemp, *srcStart;
+    unsigned long   *psrcBase;
+    unsigned long   startmask, endmask;
+
+    if (pGC->fillStyle == FillStippled)
+       cfb8CheckStipple (pGC->alu, pGC->fgPixel, pGC->planemask);
+    else
+       cfb8CheckOpaqueStipple (pGC->alu, pGC->fgPixel, pGC->bgPixel, pGC->planemask);
+
+    if (cfb8StippleRRop == GXnoop)
+       return;
+
+    n = nInit * miFindMaxBand( cfbGetCompositeClip(pGC) );
+    if ( n == 0 )
+       return;
+    pwidthFree = (int *)ALLOCATE_LOCAL(n * sizeof(int));
+    pptFree = (DDXPointRec *)ALLOCATE_LOCAL(n * sizeof(DDXPointRec));
+    if(!pptFree || !pwidthFree)
+    {
+       if (pptFree) DEALLOCATE_LOCAL(pptFree);
+       if (pwidthFree) DEALLOCATE_LOCAL(pwidthFree);
+       return;
+    }
+
+    pwidth = pwidthFree;
+    ppt = pptFree;
+    n = miClipSpans( cfbGetCompositeClip(pGC),
+                    pptInit, pwidthInit, nInit, 
+                    ppt, pwidth, fSorted);
+
+    /*
+     *  OK,  so what's going on here?  We have two Drawables:
+     *
+     *  The Stipple:
+     *         Depth = 1
+     *         Width = stippleWidth
+     *         Words per scanline = stwidth
+     *         Pointer to pixels = pStipple->devPrivate.ptr
+     */
+
+    pStipple = pGC->stipple;
+
+    stwidth = pStipple->devKind >> PWSH;
+    stippleWidth = pStipple->drawable.width;
+    stippleHeight = pStipple->drawable.height;
+    psrcBase = (unsigned long *) pStipple->devPrivate.ptr;
+
+    /*
+     * The Target:
+     *         Depth = PSZ
+     *         Width = determined from *pwidth
+     *         Words per scanline = nlwDst
+     *         Pointer to pixels = addrlBase
+     */
+
+    cfbGetLongWidthAndPointer (pDrawable, nlwDst, pdstBase)
+
+    /* this replaces rotating the stipple. Instead we just adjust the offset
+     * at which we start grabbing bits from the stipple.
+     * Ensure that ppt->x - xSrc >= 0 and ppt->y - ySrc >= 0,
+     * so that iline and xrem always stay within the stipple bounds.
+     */
+
+    modulus (pGC->patOrg.x, stippleWidth, xSrc);
+    xSrc += pDrawable->x - stippleWidth;
+    modulus (pGC->patOrg.y, stippleHeight, ySrc);
+    ySrc += pDrawable->y - stippleHeight;
+
+    bitsWhole = stippleWidth;
+
+    while (n--)
+    {
+       x = ppt->x;
+       y = ppt->y;
+       ppt++;
+       w = *pwidth++;
+       pdst = pdstBase + y * nlwDst + (x >> PWSH);
+       y = (y - ySrc) % stippleHeight;
+       srcStart = psrcBase + y * stwidth;
+       xrem = ((x & ~(PGSZB-1)) - xSrc) % stippleWidth;
+       srcTemp = srcStart + (xrem >> MFB_PWSH);
+       bitsLeft = stippleWidth - (xrem & ~MFB_PIM);
+       xrem &= MFB_PIM;
+       NextUnnaturalStippleWord
+       if (partBitsLeft < xrem)
+           FatalError ("cfbUnnaturalStippleFS bad partBitsLeft %d xrem %d",
+                       partBitsLeft, xrem);
+       NextSomeBits (inputBits, xrem);
+       partBitsLeft -= xrem;
+       if (((x & PIM) + w) <= PPW)
+       {
+           maskpartialbits (x, w, startmask)
+           NextUnnaturalStippleBits
+           *pdst = MaskRRopPixels(*pdst,bits,startmask);
+       }
+       else
+       {
+           maskbits (x, w, startmask, endmask, nlw);
+           nextPartBits = (x & (PGSZB-1)) + w;
+           if (nextPartBits < partBitsLeft)
+           {
+               if (startmask)
+               {
+                   MaskRRopBitGroup(pdst,GetBitGroup(inputBits),startmask)
+                   pdst++;
+                   NextBitGroup (inputBits);
+               }
+               while (nlw--)
+               {
+                   RRopBitGroup (pdst, GetBitGroup (inputBits));
+                   pdst++;
+                   NextBitGroup (inputBits);
+               }
+               if (endmask)
+               {
+                   MaskRRopBitGroup(pdst,GetBitGroup(inputBits),endmask)
+               }
+           }
+           else if (bitsLeft != bitsWhole && nextPartBits < partBitsLeft + bitsLeft)
+           {
+               NextUnnaturalStippleBitsFast
+               if (startmask)
+               {
+                   *pdst = MaskRRopPixels(*pdst,bits,startmask);
+                   pdst++;
+                   NextUnnaturalStippleBitsFast
+               }
+               while (nlw--)
+               {
+                   *pdst = RRopPixels(*pdst,bits);
+                   pdst++;
+                   NextUnnaturalStippleBitsFast
+               }
+               if (endmask)
+                   *pdst = MaskRRopPixels (*pdst,bits,endmask);
+           }
+           else
+           {
+               NextUnnaturalStippleBits
+               if (startmask)
+               {
+                   *pdst = MaskRRopPixels(*pdst,bits,startmask);
+                   pdst++;
+                   NextUnnaturalStippleBits
+               }
+               while (nlw--)
+               {
+                   *pdst = RRopPixels(*pdst,bits);
+                   pdst++;
+                   NextUnnaturalStippleBits
+               }
+               if (endmask)
+                   *pdst = MaskRRopPixels(*pdst,bits,endmask);
+           }
+       }
+    }
+    DEALLOCATE_LOCAL(pptFree);
+    DEALLOCATE_LOCAL(pwidthFree);
+}
+
+#else /* PSZ != 8 */
+
+/* Fill spans with stipples that aren't 32 bits wide */
+void
+cfbUnnaturalStippleFS(pDrawable, pGC, nInit, pptInit, pwidthInit, fSorted)
+DrawablePtr pDrawable;
+GC             *pGC;
+int            nInit;          /* number of spans to fill */
+DDXPointPtr pptInit;           /* pointer to list of start points */
+int *pwidthInit;               /* pointer to list of n widths */
+int fSorted;
+{
+                               /* next three parameters are post-clip */
+    int                            n;          /* number of spans to fill */
+    register DDXPointPtr    ppt;       /* pointer to list of start points */
+    register int           *pwidth;    /* pointer to list of n widths */
+    int                            iline;      /* first line of tile to use */
+    unsigned long          *addrlBase; /* pointer to start of bitmap */
+    int                            nlwidth;    /* width in longwords of bitmap */
+    register unsigned long  *pdst;     /* pointer to current word in bitmap */
+    PixmapPtr              pStipple;   /* pointer to stipple we want to fill with */
+    register int           w;
+    int                            width,  x, xrem, xSrc, ySrc;
+    unsigned long          tmpSrc, tmpDst1, tmpDst2;
+    int                            stwidth, stippleWidth;
+    unsigned long          *psrcS;
+    int                            rop, stiprop;
+    int                            stippleHeight;
+    int                            *pwidthFree;    /* copies of the pointers to free */
+    DDXPointPtr                    pptFree;
+    unsigned long          fgfill, bgfill;
+
+    if (!(pGC->planemask))
+       return;
+
+    n = nInit * miFindMaxBand( cfbGetCompositeClip(pGC) );
+    if ( n == 0 )
+       return;
+    pwidthFree = (int *)ALLOCATE_LOCAL(n * sizeof(int));
+    pptFree = (DDXPointRec *)ALLOCATE_LOCAL(n * sizeof(DDXPointRec));
+    if(!pptFree || !pwidthFree)
+    {
+       if (pptFree) DEALLOCATE_LOCAL(pptFree);
+       if (pwidthFree) DEALLOCATE_LOCAL(pwidthFree);
+       return;
+    }
+    pwidth = pwidthFree;
+    ppt = pptFree;
+    n = miClipSpans( cfbGetCompositeClip(pGC),
+                    pptInit, pwidthInit, nInit, 
+                    ppt, pwidth, fSorted);
+    rop = pGC->alu;
+    if (pGC->fillStyle == FillStippled) {
+       switch (rop) {
+           case GXand:
+           case GXcopy:
+           case GXnoop:
+           case GXor:
+               stiprop = rop;
+               break;
+           default:
+               stiprop = rop;
+               rop = GXcopy;
+       }
+    }
+    fgfill = PFILL(pGC->fgPixel);
+    bgfill = PFILL(pGC->bgPixel);
+
+    /*
+     *  OK,  so what's going on here?  We have two Drawables:
+     *
+     *  The Stipple:
+     *         Depth = 1
+     *         Width = stippleWidth
+     *         Words per scanline = stwidth
+     *         Pointer to pixels = pStipple->devPrivate.ptr
+     */
+    pStipple = pGC->stipple;
+
+    stwidth = pStipple->devKind / PGSZB;
+    stippleWidth = pStipple->drawable.width;
+    stippleHeight = pStipple->drawable.height;
+
+    /*
+     * The Target:
+     *         Depth = PSZ
+     *         Width = determined from *pwidth
+     *         Words per scanline = nlwidth
+     *         Pointer to pixels = addrlBase
+     */
+
+    cfbGetLongWidthAndPointer (pDrawable, nlwidth, addrlBase)
+
+    /* this replaces rotating the stipple. Instead we just adjust the offset
+     * at which we start grabbing bits from the stipple.
+     * Ensure that ppt->x - xSrc >= 0 and ppt->y - ySrc >= 0,
+     * so that iline and xrem always stay within the stipple bounds.
+     */
+    modulus (pGC->patOrg.x, stippleWidth, xSrc);
+    xSrc += pDrawable->x - stippleWidth;
+    modulus (pGC->patOrg.y, stippleHeight, ySrc);
+    ySrc += pDrawable->y - stippleHeight;
+
+    while (n--)
+    {
+       iline = (ppt->y - ySrc) % stippleHeight;
+       x = ppt->x;
+       pdst = addrlBase + (ppt->y * nlwidth);
+        psrcS = (unsigned long *) pStipple->devPrivate.ptr + (iline * stwidth);
+
+       if (*pwidth)
+       {
+           width = *pwidth;
+           while(width > 0)
+           {
+               int xtemp, tmpx;
+               register unsigned long *ptemp;
+               register unsigned long *pdsttmp;
+               /*
+                *  Do a stripe through the stipple & destination w pixels
+                *  wide.  w is not more than:
+                *      -       the width of the destination
+                *      -       the width of the stipple
+                *      -       the distance between x and the next word 
+                *              boundary in the destination
+                *      -       the distance between x and the next word
+                *              boundary in the stipple
+                */
+
+               /* width of dest/stipple */
+                xrem = (x - xSrc) % stippleWidth;
+#if PSZ == 24
+               w = 1;
+#else
+               w = min((stippleWidth - xrem), width);
+               /* dist to word bound in dest */
+               w = min(w, PPW - (x & PIM));
+               /* dist to word bound in stip */
+               w = min(w, MFB_PPW - (x & MFB_PIM));
+#endif
+
+               xtemp = (xrem & MFB_PIM);
+               ptemp = (unsigned long *)(psrcS + (xrem >> MFB_PWSH));
+#if PSZ == 24
+               tmpx = x & 3;
+               pdsttmp = pdst + ((x * 3)>>2);
+#else
+               tmpx = x & PIM;
+               pdsttmp = pdst + (x>>PWSH);
+#endif
+               switch ( pGC->fillStyle ) {
+                   case FillOpaqueStippled:
+#if PSZ == 24
+                       getstipplepixels24(ptemp, xtemp, 0, &bgfill, &tmpDst1, xrem);
+                       getstipplepixels24(ptemp, xtemp, 1, &fgfill, &tmpDst2, xrem);
+#else
+                       getstipplepixels(ptemp, xtemp, w, 0, &bgfill, &tmpDst1);
+                       getstipplepixels(ptemp, xtemp, w, 1, &fgfill, &tmpDst2);
+#endif
+                       break;
+                   case FillStippled:
+                       /* Fill tmpSrc with the source pixels */
+#if PSZ == 24
+                       getbits24(pdsttmp, tmpSrc, x);
+                       getstipplepixels24(ptemp, xtemp, 0, &tmpSrc, &tmpDst1, xrem);
+#else
+                       getbits(pdsttmp, tmpx, w, tmpSrc);
+                       getstipplepixels(ptemp, xtemp, w, 0, &tmpSrc, &tmpDst1);
+#endif
+                       if (rop != stiprop) {
+#if PSZ == 24
+                           putbitsrop24(fgfill, 0, &tmpSrc, pGC->planemask, stiprop);
+#else
+                           putbitsrop(fgfill, 0, w, &tmpSrc, pGC->planemask, stiprop);
+#endif
+                       } else {
+                           tmpSrc = fgfill;
+                       }
+#if PSZ == 24
+                       getstipplepixels24(ptemp, xtemp, 1, &tmpSrc, &tmpDst2, xrem);
+#else
+                       getstipplepixels(ptemp, xtemp, w, 1, &tmpSrc, &tmpDst2);
+#endif
+                       break;
+               }
+               tmpDst2 |= tmpDst1;
+#if PSZ == 24
+               putbitsrop24(tmpDst2, tmpx, pdsttmp, pGC->planemask, rop);
+#else
+               putbitsrop(tmpDst2, tmpx, w, pdsttmp, pGC->planemask, rop);
+#endif
+               x += w;
+               width -= w;
+           }
+       }
+       ppt++;
+       pwidth++;
+    }
+    DEALLOCATE_LOCAL(pptFree);
+    DEALLOCATE_LOCAL(pwidthFree);
+}
+
+#endif /* PSZ == 8 */
+
+#if PSZ == 8
+
+void
+cfb8Stipple32FS (pDrawable, pGC, nInit, pptInit, pwidthInit, fSorted)
+    DrawablePtr pDrawable;
+    GCPtr      pGC;
+    int                nInit;                  /* number of spans to fill */
+    DDXPointPtr pptInit;               /* pointer to list of start points */
+    int                *pwidthInit;            /* pointer to list of n widths */
+    int        fSorted;
+{
+                               /* next three parameters are post-clip */
+    int                    n;                  /* number of spans to fill */
+    DDXPointPtr            ppt;                /* pointer to list of start points */
+    int                    *pwidth;            /* pointer to list of n widths */
+    unsigned long   *src;              /* pointer to bits in stipple, if needed */
+    int                    stippleHeight;      /* height of the stipple */
+    PixmapPtr      stipple;
+
+    int                    nlwDst;             /* width in longwords of the dest pixmap */
+    int                    x,y,w;              /* current span */
+    unsigned long   startmask;
+    unsigned long   endmask;
+    register unsigned long *dst;       /* pointer to bits we're writing */
+    register int    nlw;
+    unsigned long   *dstTmp;
+    int                    nlwTmp;
+
+    unsigned long   *pbits;            /* pointer to start of pixmap */
+    register unsigned long  xor;
+    register unsigned long  mask;
+    register unsigned long  bits;      /* bits from stipple */
+    int                    wEnd;
+
+    int                    *pwidthFree;        /* copies of the pointers to free */
+    DDXPointPtr            pptFree;
+    cfbPrivGCPtr    devPriv;
+
+    devPriv = cfbGetGCPrivate(pGC);
+    cfb8CheckStipple (pGC->alu, pGC->fgPixel, pGC->planemask);
+    n = nInit * miFindMaxBand(devPriv->pCompositeClip);
+    if ( n == 0 )
+       return;
+    pwidthFree = (int *)ALLOCATE_LOCAL(n * sizeof(int));
+    pptFree = (DDXPointRec *)ALLOCATE_LOCAL(n * sizeof(DDXPointRec));
+    if(!pptFree || !pwidthFree)
+    {
+       if (pptFree) DEALLOCATE_LOCAL(pptFree);
+       if (pwidthFree) DEALLOCATE_LOCAL(pwidthFree);
+       return;
+    }
+    pwidth = pwidthFree;
+    ppt = pptFree;
+    n = miClipSpans(devPriv->pCompositeClip,
+                    pptInit, pwidthInit, nInit,
+                    ppt, pwidth, fSorted);
+
+    stipple = devPriv->pRotatedPixmap;
+    src = (unsigned long *)stipple->devPrivate.ptr;
+    stippleHeight = stipple->drawable.height;
+
+    cfbGetLongWidthAndPointer (pDrawable, nlwDst, pbits)
+
+    while (n--)
+    {
+       w = *pwidth++;
+       x = ppt->x;
+       y = ppt->y;
+       ppt++;
+       dst = pbits + (y * nlwDst) + (x >> PWSH);
+       if (((x & PIM) + w) <= PPW)
+       {
+           maskpartialbits(x, w, startmask);
+           endmask = 0;
+           nlw = 0;
+       }
+       else
+       {
+           maskbits (x, w, startmask, endmask, nlw);
+       }
+       bits = src[y % stippleHeight];
+       RotBitsLeft (bits, (x & ((PGSZ-1) & ~PIM)));
+#if PPW == 4
+       if (cfb8StippleRRop == GXcopy)
+       {
+           xor = devPriv->xor;
+           if (w < (PGSZ*2))
+           {
+               if (startmask)
+               {
+                   mask = cfb8PixelMasks[GetBitGroup(bits)];
+                   *dst = (*dst & ~(mask & startmask)) |
+                          (xor & (mask & startmask));
+                   dst++;
+                   RotBitsLeft (bits, PGSZB);
+               }
+               while (nlw--)
+               {
+                   WriteBitGroup (dst,xor,GetBitGroup(bits))
+                   dst++;
+                   RotBitsLeft (bits, PGSZB);
+               }
+               if (endmask)
+               {
+                   mask = cfb8PixelMasks[GetBitGroup(bits)];
+                   *dst = (*dst & ~(mask & endmask)) |
+                          (xor & (mask & endmask));
+               }
+           }
+           else
+           { /* XXX constants probably not OK here */
+               wEnd = 7 - (nlw & 7);
+               nlw = (nlw >> 3) + 1;
+               dstTmp = dst;
+               nlwTmp = nlw;
+               if (startmask)
+               {
+                   mask = cfb8PixelMasks[GetBitGroup(bits)];
+                   *dstTmp = (*dstTmp & ~(mask & startmask)) |
+                          (xor & (mask & startmask));
+                   dstTmp++;
+                   RotBitsLeft (bits, PGSZB);
+               }
+               w = 7 - wEnd;
+               while (w--)
+               {
+                   dst = dstTmp;
+                   dstTmp++;
+                   nlw = nlwTmp;
+#if defined(__GNUC__) && defined(mc68020)
+                   mask = cfb8PixelMasks[GetBitGroup(bits)];
+                   xor = xor & mask;
+                   mask = ~mask;
+                   while (nlw--)
+                   {
+                       *dst = (*dst & mask) | xor;
+                       dst += 8;
+                   }
+                   xor = devPriv->xor;
+#else
+#define SwitchBitsLoop(body) \
+    while (nlw--)      \
+    {          \
+       body    \
+       dst += 8;       \
+    }
+                   SwitchBitGroup(dst, xor, GetBitGroup(bits));
+#undef SwitchBitsLoop
+#endif
+                   NextBitGroup (bits);
+               }
+               nlwTmp--;
+               w = wEnd + 1;
+               if (endmask)
+               {
+                   mask = cfb8PixelMasks[GetBitGroup(bits)];
+                   dst = dstTmp + (nlwTmp << 3);
+                   *dst = (*dst & ~(mask & endmask)) |
+                          (xor &  (mask & endmask));
+               }
+               while (w--)
+               {
+                   nlw = nlwTmp;
+                   dst = dstTmp;
+                   dstTmp++;
+#if defined(__GNUC__) && defined(mc68020)
+                   mask = cfb8PixelMasks[GetBitGroup(bits)];
+                   xor = xor & mask;
+                   mask = ~mask;
+                   while (nlw--)
+                   {
+                       *dst = (*dst & mask) | xor;
+                       dst += 8;
+                   }
+                   xor = devPriv->xor;
+#else
+#define SwitchBitsLoop(body) \
+       while (nlw--)   \
+       {               \
+           body        \
+           dst += 8;   \
+       }
+                   SwitchBitGroup(dst, xor, GetBitGroup(bits));
+#undef SwitchBitsLoop
+#endif
+                   NextBitGroup (bits);
+               }
+           }
+       }
+       else
+#endif /* PPW == 4 */
+       {
+           if (startmask)
+           {
+               xor = GetBitGroup(bits);
+               *dst = MaskRRopPixels(*dst, xor, startmask);
+               dst++;
+               RotBitsLeft (bits, PGSZB);
+           }
+           while (nlw--)
+           {
+               RRopBitGroup(dst, GetBitGroup(bits));
+               dst++;
+               RotBitsLeft (bits, PGSZB);
+           }
+           if (endmask)
+           {
+               xor = GetBitGroup(bits);
+               *dst = MaskRRopPixels(*dst, xor, endmask);
+           }
+       }
+    }
+    DEALLOCATE_LOCAL(pptFree);
+    DEALLOCATE_LOCAL(pwidthFree);
+}
+
+void
+cfb8OpaqueStipple32FS (pDrawable, pGC, nInit, pptInit, pwidthInit, fSorted)
+    DrawablePtr pDrawable;
+    GCPtr      pGC;
+    int                nInit;                  /* number of spans to fill */
+    DDXPointPtr pptInit;               /* pointer to list of start points */
+    int                *pwidthInit;            /* pointer to list of n widths */
+    int        fSorted;
+{
+                               /* next three parameters are post-clip */
+    int                    n;                  /* number of spans to fill */
+    DDXPointPtr            ppt;                /* pointer to list of start points */
+    int                    *pwidth;            /* pointer to list of n widths */
+    unsigned long   *src;              /* pointer to bits in stipple, if needed */
+    int                    stippleHeight;      /* height of the stipple */
+    PixmapPtr      stipple;
+
+    int                    nlwDst;             /* width in longwords of the dest pixmap */
+    int                    x,y,w;              /* current span */
+    unsigned long   startmask;
+    unsigned long   endmask;
+    register unsigned long *dst;       /* pointer to bits we're writing */
+    register int    nlw;
+    unsigned long   *dstTmp;
+    int                    nlwTmp;
+
+    unsigned long   *pbits;            /* pointer to start of pixmap */
+    register unsigned long  xor;
+    register unsigned long  mask;
+    register unsigned long  bits;      /* bits from stipple */
+    int                    wEnd;
+
+    int                    *pwidthFree;        /* copies of the pointers to free */
+    DDXPointPtr            pptFree;
+    cfbPrivGCPtr    devPriv;
+
+    devPriv = cfbGetGCPrivate(pGC);
+
+    cfb8CheckOpaqueStipple(pGC->alu, pGC->fgPixel, pGC->bgPixel, pGC->planemask);
+
+    n = nInit * miFindMaxBand(devPriv->pCompositeClip);
+    if ( n == 0 )
+       return;
+    pwidthFree = (int *)ALLOCATE_LOCAL(n * sizeof(int));
+    pptFree = (DDXPointRec *)ALLOCATE_LOCAL(n * sizeof(DDXPointRec));
+    if(!pptFree || !pwidthFree)
+    {
+       if (pptFree) DEALLOCATE_LOCAL(pptFree);
+       if (pwidthFree) DEALLOCATE_LOCAL(pwidthFree);
+       return;
+    }
+    pwidth = pwidthFree;
+    ppt = pptFree;
+    n = miClipSpans(devPriv->pCompositeClip,
+                    pptInit, pwidthInit, nInit,
+                    ppt, pwidth, fSorted);
+
+    stipple = devPriv->pRotatedPixmap;
+    src = (unsigned long *)stipple->devPrivate.ptr;
+    stippleHeight = stipple->drawable.height;
+
+    cfbGetLongWidthAndPointer (pDrawable, nlwDst, pbits)
+
+    while (n--)
+    {
+       w = *pwidth++;
+       x = ppt->x;
+       y = ppt->y;
+       ppt++;
+       dst = pbits + (y * nlwDst) + (x >> PWSH);
+       if (((x & PIM) + w) <= PPW)
+       {
+           maskpartialbits(x, w, startmask);
+           endmask = 0;
+           nlw = 0;
+       }
+       else
+       {
+           maskbits (x, w, startmask, endmask, nlw);
+       }
+       bits = src[y % stippleHeight];
+       RotBitsLeft (bits, (x & ((PGSZ-1) & ~PIM)));
+#if PPW == 4
+       if (cfb8StippleRRop == GXcopy)
+       {
+           xor = devPriv->xor;
+           if (w < PGSZ*2)
+           {
+               if (startmask)
+               {
+                   *dst = *dst & ~startmask |
+                          GetPixelGroup (bits) & startmask;
+                   dst++;
+                   RotBitsLeft (bits, PGSZB);
+               }
+               while (nlw--)
+               {
+                   *dst++ = GetPixelGroup(bits);
+                   RotBitsLeft (bits, PGSZB);
+               }
+               if (endmask)
+               {
+                   *dst = *dst & ~endmask |
+                          GetPixelGroup (bits) & endmask;
+               }
+           }
+           else
+           { /* XXX consts probably not OK here */
+               wEnd = 7 - (nlw & 7);
+               nlw = (nlw >> 3) + 1;
+               dstTmp = dst;
+               nlwTmp = nlw;
+               if (startmask)
+               {
+                   *dstTmp = *dstTmp & ~startmask |
+                          GetPixelGroup (bits) & startmask;
+                   dstTmp++;
+                   RotBitsLeft (bits, PGSZB);
+               }
+               w = 7 - wEnd;
+               while (w--)
+               {
+                   nlw = nlwTmp;
+                   dst = dstTmp;
+                   dstTmp++;
+                   xor = GetPixelGroup (bits);
+                   while (nlw--)
+                   {
+                       *dst = xor;
+                       dst += 8;
+                   }
+                   NextBitGroup (bits);
+               }
+               nlwTmp--;
+               w = wEnd + 1;
+               if (endmask)
+               {
+                   dst = dstTmp + (nlwTmp << 3);
+                   *dst = (*dst & ~endmask) |
+                          GetPixelGroup (bits) & endmask;
+               }
+               while (w--)
+               {
+                   nlw = nlwTmp;
+                   dst = dstTmp;
+                   dstTmp++;
+                   xor = GetPixelGroup (bits);
+                   while (nlw--)
+                   {
+                       *dst = xor;
+                       dst += 8;
+                   }
+                   NextBitGroup (bits);
+               }
+           }
+       }
+       else
+#endif /* PPW == 4 */
+       {
+           if (startmask)
+           {
+               xor = GetBitGroup(bits);
+               *dst = MaskRRopPixels(*dst, xor, startmask);
+               dst++;
+               RotBitsLeft (bits, PGSZB);
+           }
+           while (nlw--)
+           {
+               RRopBitGroup(dst, GetBitGroup(bits));
+               dst++;
+               RotBitsLeft (bits, PGSZB);
+           }
+           if (endmask)
+           {
+               xor = GetBitGroup(bits);
+               *dst = MaskRRopPixels(*dst, xor, endmask);
+           }
+       }
+    }
+    DEALLOCATE_LOCAL(pptFree);
+    DEALLOCATE_LOCAL(pwidthFree);
+}
+
+#endif /* PSZ == 8 */
diff --git a/Xserver/programs/Xserver/cfb/cfbgc.c b/Xserver/programs/Xserver/cfb/cfbgc.c
new file mode 100644 (file)
index 0000000..c2f996a
--- /dev/null
@@ -0,0 +1,784 @@
+/***********************************************************
+
+Copyright (c) 1987  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+
+Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
+
+                        All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and its 
+documentation for any purpose and without fee is hereby granted, 
+provided that the above copyright notice appear in all copies and that
+both that copyright notice and this permission notice appear in 
+supporting documentation, and that the name of Digital not be
+used in advertising or publicity pertaining to distribution of the
+software without specific, written prior permission.  
+
+DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
+ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
+DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
+ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+SOFTWARE.
+
+******************************************************************/
+
+/* $XConsortium: cfbgc.c,v 5.62 94/04/17 20:28:49 dpw Exp $ */
+
+#include "X.h"
+#include "Xmd.h"
+#include "Xproto.h"
+#include "cfb.h"
+#include "fontstruct.h"
+#include "dixfontstr.h"
+#include "gcstruct.h"
+#include "windowstr.h"
+#include "pixmapstr.h"
+#include "scrnintstr.h"
+#include "region.h"
+
+#include "mistruct.h"
+#include "mibstore.h"
+#include "migc.h"
+
+#include "cfbmskbits.h"
+#include "cfb8bit.h"
+
+#if PSZ == 8
+# define useTEGlyphBlt  cfbTEGlyphBlt8
+#else
+# ifdef WriteBitGroup
+#  define useTEGlyphBlt        cfbImageGlyphBlt8
+# else
+#  define useTEGlyphBlt        cfbTEGlyphBlt
+# endif
+#endif
+
+#ifdef WriteBitGroup
+# define useImageGlyphBlt      cfbImageGlyphBlt8
+# define usePolyGlyphBlt       cfbPolyGlyphBlt8
+#else
+# define useImageGlyphBlt      miImageGlyphBlt
+# define usePolyGlyphBlt       miPolyGlyphBlt
+#endif
+
+#ifdef FOUR_BIT_CODE
+# define usePushPixels cfbPushPixels8
+#else
+# define usePushPixels mfbPushPixels
+#endif
+
+#ifdef PIXEL_ADDR
+# define ZeroPolyArc   cfbZeroPolyArcSS8Copy
+#else
+# define ZeroPolyArc   miZeroPolyArc
+#endif
+
+GCFuncs cfbGCFuncs = {
+    cfbValidateGC,
+    miChangeGC,
+    miCopyGC,
+    miDestroyGC,
+    miChangeClip,
+    miDestroyClip,
+    miCopyClip,
+};
+
+GCOps  cfbTEOps1Rect = {
+    cfbSolidSpansCopy,
+    cfbSetSpans,
+    cfbPutImage,
+    cfbCopyArea,
+    cfbCopyPlane,
+    cfbPolyPoint,
+#ifdef PIXEL_ADDR
+    cfb8LineSS1Rect,
+    cfb8SegmentSS1Rect,
+#else
+    cfbLineSS,
+    cfbSegmentSS,
+#endif
+    miPolyRectangle,
+    ZeroPolyArc,
+    cfbFillPoly1RectCopy,
+    cfbPolyFillRect,
+    cfbPolyFillArcSolidCopy,
+    miPolyText8,
+    miPolyText16,
+    miImageText8,
+    miImageText16,
+    useTEGlyphBlt,
+    usePolyGlyphBlt,
+    usePushPixels
+#ifdef NEED_LINEHELPER
+    ,NULL
+#endif
+};
+
+GCOps  cfbNonTEOps1Rect = {
+    cfbSolidSpansCopy,
+    cfbSetSpans,
+    cfbPutImage,
+    cfbCopyArea,
+    cfbCopyPlane,
+    cfbPolyPoint,
+#ifdef PIXEL_ADDR
+    cfb8LineSS1Rect,
+    cfb8SegmentSS1Rect,
+#else
+    cfbLineSS,
+    cfbSegmentSS,
+#endif
+    miPolyRectangle,
+    ZeroPolyArc,
+    cfbFillPoly1RectCopy,
+    cfbPolyFillRect,
+    cfbPolyFillArcSolidCopy,
+    miPolyText8,
+    miPolyText16,
+    miImageText8,
+    miImageText16,
+    useImageGlyphBlt,
+    usePolyGlyphBlt,
+    usePushPixels
+#ifdef NEED_LINEHELPER
+    ,NULL
+#endif
+};
+
+GCOps  cfbTEOps = {
+    cfbSolidSpansCopy,
+    cfbSetSpans,
+    cfbPutImage,
+    cfbCopyArea,
+    cfbCopyPlane,
+    cfbPolyPoint,
+    cfbLineSS,
+    cfbSegmentSS,
+    miPolyRectangle,
+    ZeroPolyArc,
+    miFillPolygon,
+    cfbPolyFillRect,
+    cfbPolyFillArcSolidCopy,
+    miPolyText8,
+    miPolyText16,
+    miImageText8,
+    miImageText16,
+    useTEGlyphBlt,
+    usePolyGlyphBlt,
+    usePushPixels
+#ifdef NEED_LINEHELPER
+    ,NULL
+#endif
+};
+
+GCOps  cfbNonTEOps = {
+    cfbSolidSpansCopy,
+    cfbSetSpans,
+    cfbPutImage,
+    cfbCopyArea,
+    cfbCopyPlane,
+    cfbPolyPoint,
+    cfbLineSS,
+    cfbSegmentSS,
+    miPolyRectangle,
+#ifdef PIXEL_ADDR
+    cfbZeroPolyArcSS8Copy,
+#else
+    miZeroPolyArc,
+#endif
+    miFillPolygon,
+    cfbPolyFillRect,
+    cfbPolyFillArcSolidCopy,
+    miPolyText8,
+    miPolyText16,
+    miImageText8,
+    miImageText16,
+    useImageGlyphBlt,
+    usePolyGlyphBlt,
+    usePushPixels
+#ifdef NEED_LINEHELPER
+    ,NULL
+#endif
+};
+
+GCOps *
+cfbMatchCommon (pGC, devPriv)
+    GCPtr          pGC;
+    cfbPrivGCPtr    devPriv;
+{
+    if (pGC->lineWidth != 0)
+       return 0;
+    if (pGC->lineStyle != LineSolid)
+       return 0;
+    if (pGC->fillStyle != FillSolid)
+       return 0;
+    if (devPriv->rop != GXcopy)
+       return 0;
+    if (pGC->font &&
+       FONTMAXBOUNDS(pGC->font,rightSideBearing) -
+        FONTMINBOUNDS(pGC->font,leftSideBearing) <= 32 &&
+       FONTMINBOUNDS(pGC->font,characterWidth) >= 0)
+    {
+       if (TERMINALFONT(pGC->font)
+#ifdef FOUR_BIT_CODE
+           && FONTMAXBOUNDS(pGC->font,characterWidth) >= PGSZB
+#endif
+       )
+#ifdef NO_ONE_RECT
+            return &cfbTEOps1Rect;
+#else
+           if (devPriv->oneRect)
+               return &cfbTEOps1Rect;
+           else
+               return &cfbTEOps;
+#endif
+       else
+#ifdef NO_ONE_RECT
+           return &cfbNonTEOps1Rect;
+#else
+           if (devPriv->oneRect)
+               return &cfbNonTEOps1Rect;
+           else
+               return &cfbNonTEOps;
+#endif
+    }
+    return 0;
+}
+
+Bool
+cfbCreateGC(pGC)
+    register GCPtr pGC;
+{
+    cfbPrivGC  *pPriv;
+
+    if (PixmapWidthPaddingInfo[pGC->depth].padPixelsLog2 == LOG2_BITMAP_PAD)
+       return (mfbCreateGC(pGC));
+    pGC->clientClip = NULL;
+    pGC->clientClipType = CT_NONE;
+
+    /*
+     * some of the output primitives aren't really necessary, since they
+     * will be filled in ValidateGC because of dix/CreateGC() setting all
+     * the change bits.  Others are necessary because although they depend
+     * on being a color frame buffer, they don't change 
+     */
+
+    pGC->ops = &cfbNonTEOps;
+    pGC->funcs = &cfbGCFuncs;
+
+    /* cfb wants to translate before scan conversion */
+    pGC->miTranslate = 1;
+
+    pPriv = cfbGetGCPrivate(pGC);
+    pPriv->rop = pGC->alu;
+    pPriv->oneRect = FALSE;
+    pPriv->fExpose = TRUE;
+    pPriv->freeCompClip = FALSE;
+    pPriv->pRotatedPixmap = (PixmapPtr) NULL;
+    return TRUE;
+}
+
+/* Clipping conventions
+       if the drawable is a window
+           CT_REGION ==> pCompositeClip really is the composite
+           CT_other ==> pCompositeClip is the window clip region
+       if the drawable is a pixmap
+           CT_REGION ==> pCompositeClip is the translated client region
+               clipped to the pixmap boundary
+           CT_other ==> pCompositeClip is the pixmap bounding box
+*/
+
+void
+cfbValidateGC(pGC, changes, pDrawable)
+    register GCPtr  pGC;
+    unsigned long   changes;
+    DrawablePtr            pDrawable;
+{
+    int         mask;          /* stateChanges */
+    int         index;         /* used for stepping through bitfields */
+    int                new_rrop;
+    int         new_line, new_text, new_fillspans, new_fillarea;
+    int                new_rotate;
+    int                xrot, yrot;
+    /* flags for changing the proc vector */
+    cfbPrivGCPtr devPriv;
+    int                oneRect;
+
+    new_rotate = pGC->lastWinOrg.x != pDrawable->x ||
+                pGC->lastWinOrg.y != pDrawable->y;
+
+    pGC->lastWinOrg.x = pDrawable->x;
+    pGC->lastWinOrg.y = pDrawable->y;
+    devPriv = cfbGetGCPrivate(pGC);
+
+    new_rrop = FALSE;
+    new_line = FALSE;
+    new_text = FALSE;
+    new_fillspans = FALSE;
+    new_fillarea = FALSE;
+
+    /*
+     * if the client clip is different or moved OR the subwindowMode has
+     * changed OR the window's clip has changed since the last validation
+     * we need to recompute the composite clip 
+     */
+
+    if ((changes & (GCClipXOrigin|GCClipYOrigin|GCClipMask|GCSubwindowMode)) ||
+       (pDrawable->serialNumber != (pGC->serialNumber & DRAWABLE_SERIAL_BITS))
+       )
+    {
+       miComputeCompositeClip (pGC, pDrawable);
+#ifdef NO_ONE_RECT
+       devPriv->oneRect = FALSE;
+#else
+       oneRect = REGION_NUM_RECTS(devPriv->pCompositeClip) == 1;
+       if (oneRect != devPriv->oneRect)
+           new_line = TRUE;
+       devPriv->oneRect = oneRect;
+#endif
+    }
+
+    mask = changes;
+    while (mask) {
+       index = lowbit (mask);
+       mask &= ~index;
+
+       /*
+        * this switch acculmulates a list of which procedures might have
+        * to change due to changes in the GC.  in some cases (e.g.
+        * changing one 16 bit tile for another) we might not really need
+        * a change, but the code is being paranoid. this sort of batching
+        * wins if, for example, the alu and the font have been changed,
+        * or any other pair of items that both change the same thing. 
+        */
+       switch (index) {
+       case GCFunction:
+       case GCForeground:
+           new_rrop = TRUE;
+           break;
+       case GCPlaneMask:
+           new_rrop = TRUE;
+           new_text = TRUE;
+           break;
+       case GCBackground:
+           break;
+       case GCLineStyle:
+       case GCLineWidth:
+           new_line = TRUE;
+           break;
+       case GCJoinStyle:
+       case GCCapStyle:
+           break;
+       case GCFillStyle:
+           new_text = TRUE;
+           new_fillspans = TRUE;
+           new_line = TRUE;
+           new_fillarea = TRUE;
+           break;
+       case GCFillRule:
+           break;
+       case GCTile:
+           new_fillspans = TRUE;
+           new_fillarea = TRUE;
+           break;
+
+       case GCStipple:
+           if (pGC->stipple)
+           {
+               int width = pGC->stipple->drawable.width;
+               PixmapPtr nstipple;
+
+               if ((width <= PGSZ) && !(width & (width - 1)) &&
+                   (nstipple = cfbCopyPixmap(pGC->stipple)))
+               {
+                   cfbPadPixmap(nstipple);
+                   (*pGC->pScreen->DestroyPixmap)(pGC->stipple);
+                   pGC->stipple = nstipple;
+               }
+           }
+           new_fillspans = TRUE;
+           new_fillarea = TRUE;
+           break;
+
+       case GCTileStipXOrigin:
+           new_rotate = TRUE;
+           break;
+
+       case GCTileStipYOrigin:
+           new_rotate = TRUE;
+           break;
+
+       case GCFont:
+           new_text = TRUE;
+           break;
+       case GCSubwindowMode:
+           break;
+       case GCGraphicsExposures:
+           break;
+       case GCClipXOrigin:
+           break;
+       case GCClipYOrigin:
+           break;
+       case GCClipMask:
+           break;
+       case GCDashOffset:
+           break;
+       case GCDashList:
+           break;
+       case GCArcMode:
+           break;
+       default:
+           break;
+       }
+    }
+
+    /*
+     * If the drawable has changed,  ensure suitable
+     * entries are in the proc vector. 
+     */
+    if (pDrawable->serialNumber != (pGC->serialNumber & (DRAWABLE_SERIAL_BITS))) {
+       new_fillspans = TRUE;   /* deal with FillSpans later */
+    }
+
+    if (new_rotate || new_fillspans)
+    {
+       Bool new_pix = FALSE;
+
+       xrot = pGC->patOrg.x + pDrawable->x;
+       yrot = pGC->patOrg.y + pDrawable->y;
+
+       switch (pGC->fillStyle)
+       {
+       case FillTiled:
+           if (!pGC->tileIsPixel)
+           {
+               int width = pGC->tile.pixmap->drawable.width * PSZ;
+
+               if ((width <= PGSZ) && !(width & (width - 1)))
+               {
+                   cfbCopyRotatePixmap(pGC->tile.pixmap,
+                                       &devPriv->pRotatedPixmap,
+                                       xrot, yrot);
+                   new_pix = TRUE;
+               }
+           }
+           break;
+#ifdef FOUR_BIT_CODE
+       case FillStippled:
+       case FillOpaqueStippled:
+           {
+               int width = pGC->stipple->drawable.width;
+
+               if ((width <= PGSZ) && !(width & (width - 1)))
+               {
+                   mfbCopyRotatePixmap(pGC->stipple,
+                                       &devPriv->pRotatedPixmap, xrot, yrot);
+                   new_pix = TRUE;
+               }
+           }
+           break;
+#endif
+       }
+       if (!new_pix && devPriv->pRotatedPixmap)
+       {
+           (*pGC->pScreen->DestroyPixmap)(devPriv->pRotatedPixmap);
+           devPriv->pRotatedPixmap = (PixmapPtr) NULL;
+       }
+    }
+
+    if (new_rrop)
+    {
+       int old_rrop;
+
+       old_rrop = devPriv->rop;
+       devPriv->rop = cfbReduceRasterOp (pGC->alu, pGC->fgPixel,
+                                          pGC->planemask,
+                                          &devPriv->and, &devPriv->xor);
+       if (old_rrop == devPriv->rop)
+           new_rrop = FALSE;
+       else
+       {
+#ifdef PIXEL_ADDR
+           new_line = TRUE;
+#endif
+#ifdef WriteBitGroup
+           new_text = TRUE;
+#endif
+           new_fillspans = TRUE;
+           new_fillarea = TRUE;
+       }
+    }
+
+    if (new_rrop || new_fillspans || new_text || new_fillarea || new_line)
+    {
+       GCOps   *newops;
+
+       if (newops = cfbMatchCommon (pGC, devPriv))
+       {
+           if (pGC->ops->devPrivate.val)
+               miDestroyGCOps (pGC->ops);
+           pGC->ops = newops;
+           new_rrop = new_line = new_fillspans = new_text = new_fillarea = 0;
+       }
+       else
+       {
+           if (!pGC->ops->devPrivate.val)
+           {
+               pGC->ops = miCreateGCOps (pGC->ops);
+               pGC->ops->devPrivate.val = 1;
+           }
+       }
+    }
+
+    /* deal with the changes we've collected */
+    if (new_line)
+    {
+       pGC->ops->FillPolygon = miFillPolygon;
+#ifdef NO_ONE_RECT
+       if (pGC->fillStyle == FillSolid)
+       {
+           switch (devPriv->rop) {
+           case GXcopy:
+               pGC->ops->FillPolygon = cfbFillPoly1RectCopy;
+               break;
+           default:
+               pGC->ops->FillPolygon = cfbFillPoly1RectGeneral;
+               break;
+           }
+       }
+#else
+       if (devPriv->oneRect && pGC->fillStyle == FillSolid)
+       {
+           switch (devPriv->rop) {
+           case GXcopy:
+               pGC->ops->FillPolygon = cfbFillPoly1RectCopy;
+               break;
+           default:
+               pGC->ops->FillPolygon = cfbFillPoly1RectGeneral;
+               break;
+           }
+       }
+#endif
+       if (pGC->lineWidth == 0)
+       {
+#ifdef PIXEL_ADDR
+           if ((pGC->lineStyle == LineSolid) && (pGC->fillStyle == FillSolid))
+           {
+               switch (devPriv->rop)
+               {
+               case GXxor:
+                   pGC->ops->PolyArc = cfbZeroPolyArcSS8Xor;
+                   break;
+               case GXcopy:
+                   pGC->ops->PolyArc = cfbZeroPolyArcSS8Copy;
+                   break;
+               default:
+                   pGC->ops->PolyArc = cfbZeroPolyArcSS8General;
+                   break;
+               }
+           }
+           else
+#endif
+               pGC->ops->PolyArc = miZeroPolyArc;
+       }
+       else
+           pGC->ops->PolyArc = miPolyArc;
+       pGC->ops->PolySegment = miPolySegment;
+       switch (pGC->lineStyle)
+       {
+       case LineSolid:
+           if(pGC->lineWidth == 0)
+           {
+               if (pGC->fillStyle == FillSolid)
+               {
+#if defined(PIXEL_ADDR) && !defined(NO_ONE_RECT)
+                   if (devPriv->oneRect &&
+                       ((pDrawable->x >= pGC->pScreen->width - 32768) &&
+                        (pDrawable->y >= pGC->pScreen->height - 32768)))
+                   {
+                       pGC->ops->Polylines = cfb8LineSS1Rect;
+                       pGC->ops->PolySegment = cfb8SegmentSS1Rect;
+                   } else
+#endif
+#ifdef NO_ONE_RECT
+                   {
+                       pGC->ops->Polylines = cfb8LineSS1Rect;
+                       pGC->ops->PolySegment = cfb8SegmentSS1Rect;
+                   }
+#else
+                   {
+                       pGC->ops->Polylines = cfbLineSS;
+                       pGC->ops->PolySegment = cfbSegmentSS;
+                   }
+#endif
+               }
+               else
+                   pGC->ops->Polylines = miZeroLine;
+           }
+           else
+               pGC->ops->Polylines = miWideLine;
+           break;
+       case LineOnOffDash:
+       case LineDoubleDash:
+           if (pGC->lineWidth == 0 && pGC->fillStyle == FillSolid)
+           {
+               pGC->ops->Polylines = cfbLineSD;
+               pGC->ops->PolySegment = cfbSegmentSD;
+           } else
+               pGC->ops->Polylines = miWideDash;
+           break;
+       }
+    }
+
+    if (new_text && (pGC->font))
+    {
+        if (FONTMAXBOUNDS(pGC->font,rightSideBearing) -
+            FONTMINBOUNDS(pGC->font,leftSideBearing) > 32 ||
+           FONTMINBOUNDS(pGC->font,characterWidth) < 0)
+        {
+            pGC->ops->PolyGlyphBlt = miPolyGlyphBlt;
+            pGC->ops->ImageGlyphBlt = miImageGlyphBlt;
+        }
+        else
+        {
+#ifdef WriteBitGroup
+           if (pGC->fillStyle == FillSolid)
+           {
+               if (devPriv->rop == GXcopy)
+                   pGC->ops->PolyGlyphBlt = cfbPolyGlyphBlt8;
+               else
+#ifdef FOUR_BIT_CODE
+                   pGC->ops->PolyGlyphBlt = cfbPolyGlyphRop8;
+#else
+                   pGC->ops->PolyGlyphBlt = miPolyGlyphBlt;
+#endif
+           }
+           else
+#endif
+               pGC->ops->PolyGlyphBlt = miPolyGlyphBlt;
+            /* special case ImageGlyphBlt for terminal emulator fonts */
+#if !defined(WriteBitGroup) || PSZ == 8
+           if (TERMINALFONT(pGC->font) &&
+               (pGC->planemask & PMSK) == PMSK
+#ifdef FOUR_BIT_CODE
+               && FONTMAXBOUNDS(pGC->font,characterWidth) >= PGSZB
+#endif
+               )
+           {
+               pGC->ops->ImageGlyphBlt = useTEGlyphBlt;
+           }
+            else
+#endif
+           {
+#ifdef WriteBitGroup
+               if (devPriv->rop == GXcopy &&
+                   pGC->fillStyle == FillSolid &&
+                   (pGC->planemask & PMSK) == PMSK)
+                   pGC->ops->ImageGlyphBlt = cfbImageGlyphBlt8;
+               else
+#endif
+                   pGC->ops->ImageGlyphBlt = miImageGlyphBlt;
+           }
+        }
+    }    
+
+
+    if (new_fillspans) {
+       switch (pGC->fillStyle) {
+       case FillSolid:
+           switch (devPriv->rop) {
+           case GXcopy:
+               pGC->ops->FillSpans = cfbSolidSpansCopy;
+               break;
+           case GXxor:
+               pGC->ops->FillSpans = cfbSolidSpansXor;
+               break;
+           default:
+               pGC->ops->FillSpans = cfbSolidSpansGeneral;
+               break;
+           }
+           break;
+       case FillTiled:
+           if (devPriv->pRotatedPixmap)
+           {
+               if (pGC->alu == GXcopy && (pGC->planemask & PMSK) == PMSK)
+                   pGC->ops->FillSpans = cfbTile32FSCopy;
+               else
+                   pGC->ops->FillSpans = cfbTile32FSGeneral;
+           }
+           else
+               pGC->ops->FillSpans = cfbUnnaturalTileFS;
+           break;
+       case FillStippled:
+#ifdef FOUR_BIT_CODE
+           if (devPriv->pRotatedPixmap)
+               pGC->ops->FillSpans = cfb8Stipple32FS;
+           else
+#endif
+               pGC->ops->FillSpans = cfbUnnaturalStippleFS;
+           break;
+       case FillOpaqueStippled:
+#ifdef FOUR_BIT_CODE
+           if (devPriv->pRotatedPixmap)
+               pGC->ops->FillSpans = cfb8OpaqueStipple32FS;
+           else
+#endif
+               pGC->ops->FillSpans = cfbUnnaturalStippleFS;
+           break;
+       default:
+           FatalError("cfbValidateGC: illegal fillStyle\n");
+       }
+    } /* end of new_fillspans */
+
+    if (new_fillarea) {
+#ifndef FOUR_BIT_CODE
+       pGC->ops->PolyFillRect = miPolyFillRect;
+       if (pGC->fillStyle == FillSolid || pGC->fillStyle == FillTiled)
+       {
+           pGC->ops->PolyFillRect = cfbPolyFillRect;
+       }
+#endif
+#ifdef FOUR_BIT_CODE
+       pGC->ops->PushPixels = mfbPushPixels;
+       if (pGC->fillStyle == FillSolid && devPriv->rop == GXcopy)
+           pGC->ops->PushPixels = cfbPushPixels8;
+#endif
+       pGC->ops->PolyFillArc = miPolyFillArc;
+       if (pGC->fillStyle == FillSolid)
+       {
+           switch (devPriv->rop)
+           {
+           case GXcopy:
+               pGC->ops->PolyFillArc = cfbPolyFillArcSolidCopy;
+               break;
+           default:
+               pGC->ops->PolyFillArc = cfbPolyFillArcSolidGeneral;
+               break;
+           }
+       }
+    }
+}
diff --git a/Xserver/programs/Xserver/cfb/cfbgetsp.c b/Xserver/programs/Xserver/cfb/cfbgetsp.c
new file mode 100644 (file)
index 0000000..884755d
--- /dev/null
@@ -0,0 +1,200 @@
+/* $XConsortium: cfbgetsp.c,v 5.14 94/04/17 20:28:50 dpw Exp $ */
+/* $XFree86: xc/programs/Xserver/cfb/cfbgetsp.c,v 3.0.4.1 1997/07/13 14:44:57 dawes Exp $ */
+/***********************************************************
+
+Copyright (c) 1987  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+
+Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
+
+                        All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and its 
+documentation for any purpose and without fee is hereby granted, 
+provided that the above copyright notice appear in all copies and that
+both that copyright notice and this permission notice appear in 
+supporting documentation, and that the name of Digital not be
+used in advertising or publicity pertaining to distribution of the
+software without specific, written prior permission.  
+
+DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
+ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
+DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
+ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+SOFTWARE.
+
+******************************************************************/
+
+#include "X.h"
+#include "Xmd.h"
+#include "servermd.h"
+
+#include "misc.h"
+#include "region.h"
+#include "gc.h"
+#include "windowstr.h"
+#include "pixmapstr.h"
+#include "scrnintstr.h"
+
+#include "cfb.h"
+#include "cfbmskbits.h"
+
+/* GetSpans -- for each span, gets bits from drawable starting at ppt[i]
+ * and continuing for pwidth[i] bits
+ * Each scanline returned will be server scanline padded, i.e., it will come
+ * out to an integral number of words.
+ */
+void
+cfbGetSpans(pDrawable, wMax, ppt, pwidth, nspans, pchardstStart)
+    DrawablePtr                pDrawable;      /* drawable from which to get bits */
+    int                        wMax;           /* largest value of all *pwidths */
+    register DDXPointPtr ppt;          /* points to start copying from */
+    int                        *pwidth;        /* list of number of bits to copy */
+    int                        nspans;         /* number of scanlines to copy */
+    char               *pchardstStart; /* where to put the bits */
+{
+    PixelGroup *pdstStart = (PixelGroup *)pchardstStart;
+    register PixelGroup        *pdst;          /* where to put the bits */
+    register PixelGroup        *psrc;          /* where to get the bits */
+    register PixelGroup        tmpSrc;         /* scratch buffer for bits */
+    PixelGroup         *psrcBase;      /* start of src bitmap */
+    int                        widthSrc;       /* width of pixmap in bytes */
+    register DDXPointPtr pptLast;      /* one past last point to get */
+    int                xEnd;           /* last pixel to copy from */
+    register int       nstart; 
+    int                        nend; 
+    PixelGroup         startmask, endmask;
+    int                        nlMiddle, nl, srcBit;
+    int                        w;
+    PixelGroup         *pdstNext;
+#if PSZ == 24
+    register char *psrcb, *pdstb;
+    register int xIndex = 0;
+#endif
+
+    switch (pDrawable->bitsPerPixel) {
+       case 1:
+           mfbGetSpans(pDrawable, wMax, ppt, pwidth, nspans, pchardstStart);
+           return;
+       case PSZ:
+           break;
+       default:
+           FatalError("cfbGetSpans: invalid depth\n");
+    }
+
+    
+    cfbGetLongWidthAndPointer (pDrawable, widthSrc, psrcBase)
+
+#ifdef PIXEL_ADDR
+# if PSZ != 24
+    if ((nspans == 1) && (*pwidth == 1))
+    {
+       tmpSrc = *((PixelType *)(psrcBase + (ppt->y * widthSrc))
+                  + ppt->x);
+#if BITMAP_BIT_ORDER == MSBFirst
+       tmpSrc <<= (sizeof (unsigned long) - sizeof (PixelType)) * 8;
+#endif
+       *pdstStart = tmpSrc;
+       return;
+    }
+# endif /* PSZ != 24 */
+#endif
+    pdst = pdstStart;
+    pptLast = ppt + nspans;
+    while(ppt < pptLast)
+    {
+#if PSZ == 24
+       xEnd = min(ppt->x + *pwidth, widthSrc * sizeof(long) / 3);
+       w = xEnd - ppt->x;
+       psrc = psrcBase + ppt->y * widthSrc;
+       srcBit = ppt->x;
+       psrcb = (char *)psrc + (ppt->x * 3);
+       xIndex = 0;
+       pdstb = (char *)pdst;
+       pdstNext = pdst + ((w * 3 + 3) >> 2);
+#else
+       xEnd = min(ppt->x + *pwidth, widthSrc << PWSH);
+       w = xEnd - ppt->x;
+       psrc = psrcBase + ppt->y * widthSrc + (ppt->x >> PWSH); 
+       srcBit = ppt->x & PIM;
+       pdstNext = pdst + ((w + PPW - 1) >> PWSH);
+#endif
+
+#if PSZ == 24
+       if (w < 0)
+         FatalError("cfb24GetSpans: Internal error (w < 0)\n");
+       nl = w;
+       while (nl--){ 
+         psrc = (PixelGroup *)((unsigned long)psrcb & ~0x03);
+         getbits24(psrc, tmpSrc, srcBit);
+         pdst = (PixelGroup *)((unsigned long)pdstb & ~0x03);
+         putbits24(tmpSrc, nstart, PPW, pdst, ~((unsigned long)0), xIndex);
+         srcBit++;
+         psrcb += 3;
+         xIndex++;
+         pdstb += 3;
+       } 
+       pdst = pdstNext;
+#else /* PSZ == 24 */
+       if (srcBit + w <= PPW) 
+       { 
+           getbits(psrc, srcBit, w, tmpSrc);
+           putbits(tmpSrc, 0, w, pdst, ~((unsigned long)0)); 
+           pdst++;
+       } 
+       else 
+       { 
+           maskbits(ppt->x, w, startmask, endmask, nlMiddle);
+           nstart = 0; 
+           if (startmask) 
+           { 
+               nstart = PPW - srcBit; 
+               getbits(psrc, srcBit, nstart, tmpSrc);
+               putbits(tmpSrc, 0, nstart, pdst, ~((unsigned long)0));
+               if(srcBit + nstart >= PPW)
+                   psrc++;
+           } 
+           nl = nlMiddle; 
+           while (nl--) 
+           { 
+               tmpSrc = *psrc;
+               putbits(tmpSrc, nstart, PPW, pdst, ~((unsigned long)0));
+               psrc++;
+               pdst++;
+           } 
+           if (endmask) 
+           { 
+               nend = xEnd & PIM; 
+               getbits(psrc, 0, nend, tmpSrc);
+               putbits(tmpSrc, nstart, nend, pdst, ~((unsigned long)0));
+           } 
+           pdst = pdstNext;
+       } 
+#endif /* PSZ == 24 */
+        ppt++;
+       pwidth++;
+    }
+}
diff --git a/Xserver/programs/Xserver/cfb/cfbglblt8.c b/Xserver/programs/Xserver/cfb/cfbglblt8.c
new file mode 100644 (file)
index 0000000..5125ddd
--- /dev/null
@@ -0,0 +1,465 @@
+/* $XConsortium: cfbglblt8.c,v 5.31 94/04/17 20:28:51 dpw Exp $ */
+/* $XFree86: xc/programs/Xserver/cfb/cfbglblt8.c,v 3.1 1996/08/13 11:27:34 dawes Exp $ */
+/*
+
+Copyright (c) 1989  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+*/
+
+/*
+ * Poly glyph blt.  Accepts an arbitrary font <= 32 bits wide, in Copy mode
+ * only.
+ */
+
+#include       "X.h"
+#include       "Xmd.h"
+#include       "Xproto.h"
+#include       "cfb.h"
+#include       "fontstruct.h"
+#include       "dixfontstr.h"
+#include       "gcstruct.h"
+#include       "windowstr.h"
+#include       "scrnintstr.h"
+#include       "pixmapstr.h"
+#include       "regionstr.h"
+#include       "cfbmskbits.h"
+#include       "cfb8bit.h"
+
+#define BOX_OVERLAP(box1, box2, xoffset, yoffset) \
+       ((box1)->x1 <= ((int) (box2)->x2 + (xoffset)) && \
+        ((int) (box2)->x1 + (xoffset)) <= (box1)->x2 && \
+        (box1)->y1 <= ((int) (box2)->y2 + (yoffset)) && \
+        ((int) (box2)->y1 + (yoffset)) <= (box1)->y2)
+
+#define BOX_CONTAINS(box1, box2, xoffset, yoffset) \
+       ((box1)->x1 <= ((int) (box2)->x1 + (xoffset)) && \
+        ((int) (box2)->x2 + (xoffset)) <= (box1)->x2 && \
+        (box1)->y1 <= ((int) (box2)->y1 + (yoffset)) && \
+        ((int) (box2)->y2 + (yoffset)) <= (box1)->y2)
+
+#if defined(FOUR_BIT_CODE) || defined(WriteBitGroup) && !defined(GLYPHROP)
+
+#if GLYPHPADBYTES != 4
+#define USE_LEFTBITS
+#endif
+
+#ifdef USE_LEFTBITS
+typedef        unsigned char   *glyphPointer;
+extern unsigned long endtab[];
+
+#define GlyphBits(bits,width,dst)      getleftbits(bits,width,dst); \
+                                       (dst) &= widthMask; \
+                                       (bits) += widthGlyph;
+#define GlyphBitsS(bits,width,dst,off) GlyphBits(bits,width,dst); \
+                                       dst = BitRight (dst, off);
+#else
+typedef CARD32 *glyphPointer;
+
+#define GlyphBits(bits,width,dst)      dst = *bits++;
+#define GlyphBitsS(bits,width,dst,off) dst = BitRight(*bits++, off);
+#endif
+
+#ifdef GLYPHROP
+#define cfbPolyGlyphBlt8       cfbPolyGlyphRop8
+#define cfbPolyGlyphBlt8Clipped        cfbPolyGlyphRop8Clipped
+
+#undef WriteBitGroup
+#define WriteBitGroup(dst,pixel,bits)  RRopBitGroup(dst,bits)
+
+#endif
+
+static void cfbPolyGlyphBlt8Clipped();
+
+#if defined(HAS_STIPPLE_CODE) && !defined(GLYPHROP) && !defined(USE_LEFTBITS)
+#define USE_STIPPLE_CODE
+#endif
+
+#if defined(__GNUC__) && !defined(GLYPHROP) && (defined(mc68020) || defined(mc68000) || defined(__mc68000__)) && PSZ == 8 && !defined(USE_LEFTBITS)
+#ifdef USE_STIPPLE_CODE
+#undef USE_STIPPLE_CODE
+#endif
+#include "stip68kgnu.h"
+#endif
+
+#if PSZ == 24
+#define DST_INC            3
+#else
+#define DST_INC            (PGSZB >> PWSH)
+#endif
+
+/*  cfbStippleStack/cfbStippleStackTE are coded in assembly language.
+ *  They are only provided on some architecures.
+ */
+#ifdef USE_STIPPLE_CODE
+extern void            cfbStippleStack (), cfbStippleStackTE ();
+#endif
+
+void
+cfbPolyGlyphBlt8 (pDrawable, pGC, x, y, nglyph, ppci, pglyphBase)
+    DrawablePtr pDrawable;
+    GCPtr      pGC;
+    int        x, y;
+    unsigned int nglyph;
+    CharInfoPtr *ppci;         /* array of character info */
+    pointer    pglyphBase;     /* start of array of glyphs */
+{
+    register unsigned long  c;
+#ifndef GLYPHROP
+    register unsigned long  pixel;
+#endif
+    register unsigned long  *dst;
+    register glyphPointer   glyphBits;
+    register int           xoff;
+
+    FontPtr            pfont = pGC->font;
+    CharInfoPtr                pci;
+    unsigned long      *dstLine;
+    unsigned long      *pdstBase;
+    int                        hTmp;
+    int                        bwidthDst;
+    int                        widthDst;
+    int                        h;
+    int                        ew;
+    BoxRec             bbox;           /* for clipping */
+    int                        widthDiff;
+    int                        w;
+    RegionPtr          clip;
+    BoxPtr             extents;
+#ifdef USE_LEFTBITS
+    int                        widthGlyph;
+    unsigned long      widthMask;
+#endif
+#ifndef STIPPLE
+#ifdef USE_STIPPLE_CODE
+    void               (*stipple)();
+
+    stipple = cfbStippleStack;
+    if (FONTCONSTMETRICS(pfont))
+       stipple = cfbStippleStackTE;
+#endif
+#endif
+    
+    x += pDrawable->x;
+    y += pDrawable->y;
+
+    /* compute an approximate (but covering) bounding box */
+    bbox.x1 = 0;
+    if ((ppci[0]->metrics.leftSideBearing < 0))
+       bbox.x1 = ppci[0]->metrics.leftSideBearing;
+    h = nglyph - 1;
+    w = ppci[h]->metrics.rightSideBearing;
+    while (--h >= 0)
+       w += ppci[h]->metrics.characterWidth;
+    bbox.x2 = w;
+    bbox.y1 = -FONTMAXBOUNDS(pfont,ascent);
+    bbox.y2 = FONTMAXBOUNDS(pfont,descent);
+
+    clip = cfbGetCompositeClip(pGC);
+    extents = &clip->extents;
+
+    if (!clip->data) 
+    {
+       if (!BOX_CONTAINS(extents, &bbox, x, y))
+       {
+           if (BOX_OVERLAP (extents, &bbox, x, y))
+               cfbPolyGlyphBlt8Clipped(pDrawable, pGC, x, y,
+                                       nglyph, ppci, pglyphBase);
+           return;
+       }
+    }
+    else
+    {
+       /* check to make sure some of the text appears on the screen */
+       if (!BOX_OVERLAP (extents, &bbox, x, y))
+           return;
+    
+       bbox.x1 += x;
+       bbox.x2 += x;
+       bbox.y1 += y;
+       bbox.y2 += y;
+    
+       switch (RECT_IN_REGION(pGC->pScreen, clip, &bbox))
+       {
+         case rgnPART:
+           cfbPolyGlyphBlt8Clipped(pDrawable, pGC, x, y,
+                                   nglyph, ppci, pglyphBase);
+         case rgnOUT:
+           return;
+       }
+    }
+
+#ifdef GLYPHROP
+    cfb8CheckStipple (pGC->alu, pGC->fgPixel, pGC->planemask);
+#else
+    pixel = cfbGetGCPrivate(pGC)->xor;
+#endif
+
+    cfbGetTypedWidthAndPointer (pDrawable, bwidthDst, pdstBase, char, unsigned long)
+
+    widthDst = bwidthDst / PGSZB;
+    while (nglyph--)
+    {
+       pci = *ppci++;
+       glyphBits = (glyphPointer) FONTGLYPHBITS(pglyphBase,pci);
+       xoff = x + pci->metrics.leftSideBearing;
+#if PSZ == 24
+       dstLine = pdstBase + (y - pci->metrics.ascent) * widthDst +((xoff>> 2)*3);
+#else
+       dstLine = pdstBase +
+                 (y - pci->metrics.ascent) * widthDst + (xoff >> PWSH);
+#endif
+       x += pci->metrics.characterWidth;
+       if (hTmp = pci->metrics.descent + pci->metrics.ascent)
+       {
+#if PSZ == 24
+           xoff &= 0x03;
+#else
+           xoff &= PIM;
+#endif /* PSZ == 24 */
+#ifdef STIPPLE
+           STIPPLE(dstLine,glyphBits,pixel,bwidthDst,hTmp,xoff);
+#else
+#ifdef USE_STIPPLE_CODE
+           (*stipple)(dstLine,glyphBits,pixel,bwidthDst,hTmp,xoff);
+#else
+#ifdef USE_LEFTBITS
+           w = pci->metrics.rightSideBearing - pci->metrics.leftSideBearing;
+           widthGlyph = PADGLYPHWIDTHBYTES(w);
+           widthMask = endtab[w];
+#endif
+           do {
+               dst = dstLine;
+               dstLine = (unsigned long *) (((char *) dstLine) + bwidthDst);
+               GlyphBits(glyphBits, w, c)
+               WriteBitGroup(dst, pixel, GetBitGroup(BitRight(c,xoff)));
+               dst += DST_INC;
+               c = BitLeft(c,PGSZB - xoff);
+               while (c)
+               {
+                   WriteBitGroup(dst, pixel, GetBitGroup(c));
+                   NextBitGroup(c);
+                   dst += DST_INC;
+               }
+           } while (--hTmp);
+#endif /* USE_STIPPLE_CODE else */
+#endif /* STIPPLE else */
+       }
+    }
+}
+
+static void
+cfbPolyGlyphBlt8Clipped (pDrawable, pGC, x, y, nglyph, ppci, pglyphBase)
+    DrawablePtr pDrawable;
+    GCPtr      pGC;
+    int        x, y;
+    unsigned int nglyph;
+    CharInfoPtr *ppci;         /* array of character info */
+    unsigned char *pglyphBase; /* start of array of glyphs */
+{
+    register unsigned long  c;
+#ifndef GLYPHROP
+    register unsigned long  pixel;
+#endif
+    register unsigned long  *dst;
+    register glyphPointer   glyphBits;
+    register int           xoff;
+    unsigned long          c1;
+
+    CharInfoPtr                pci;
+    FontPtr            pfont = pGC->font;
+    unsigned long      *dstLine;
+    unsigned long      *pdstBase;
+    CARD32             *cTmp, *clips;
+    int                        maxAscent, maxDescent;
+    int                        minLeftBearing;
+    int                        hTmp;
+    int                        widthDst;
+    int                        bwidthDst;
+    int                        ew;
+    int                        xG, yG;
+    BoxPtr             pBox;
+    int                        numRects;
+    int                        widthDiff;
+    int                        w;
+    RegionPtr          pRegion;
+    int                        yBand;
+#ifdef GLYPHROP
+    unsigned long       bits;
+#endif
+#ifdef USE_LEFTBITS
+    int                        widthGlyph;
+    unsigned long      widthMask;
+#endif
+
+#ifdef GLYPHROP
+    cfb8CheckStipple (pGC->alu, pGC->fgPixel, pGC->planemask);
+#else
+    pixel = cfbGetGCPrivate(pGC)->xor;
+#endif
+    
+    cfbGetTypedWidthAndPointer (pDrawable, bwidthDst, pdstBase, char, unsigned long)
+
+    widthDst = bwidthDst / PGSZB;
+    maxAscent = FONTMAXBOUNDS(pfont,ascent);
+    maxDescent = FONTMAXBOUNDS(pfont,descent);
+    minLeftBearing = FONTMINBOUNDS(pfont,leftSideBearing);
+
+    pRegion = cfbGetCompositeClip(pGC);
+
+    pBox = REGION_RECTS(pRegion);
+    numRects = REGION_NUM_RECTS (pRegion);
+    while (numRects && pBox->y2 <= y - maxAscent)
+    {
+       ++pBox;
+       --numRects;
+    }
+    if (!numRects || pBox->y1 >= y + maxDescent)
+       return;
+    yBand = pBox->y1;
+    while (numRects && pBox->y1 == yBand && pBox->x2 <= x + minLeftBearing)
+    {
+       ++pBox;
+       --numRects;
+    }
+    if (!numRects)
+       return;
+    clips = (CARD32 *)ALLOCATE_LOCAL ((maxAscent + maxDescent) *
+                                               sizeof (CARD32));
+    while (nglyph--)
+    {
+       pci = *ppci++;
+       glyphBits = (glyphPointer) FONTGLYPHBITS(pglyphBase,pci);
+       w = pci->metrics.rightSideBearing - pci->metrics.leftSideBearing;
+       xG = x + pci->metrics.leftSideBearing;
+       yG = y - pci->metrics.ascent;
+       x += pci->metrics.characterWidth;
+       if (hTmp = pci->metrics.descent + pci->metrics.ascent)
+       {
+#if PSZ == 24
+           dstLine = pdstBase + yG * widthDst + ((xG>> 2)*3);
+           /* never use (xG*3)>>2 */
+#else
+           dstLine = pdstBase + yG * widthDst + (xG >> PWSH);
+#endif
+#if PSZ == 24
+           xoff = xG & 3;
+#else
+           xoff = xG & PIM;
+#endif
+#ifdef USE_LEFTBITS
+           w = pci->metrics.rightSideBearing - pci->metrics.leftSideBearing;
+           widthGlyph = PADGLYPHWIDTHBYTES(w);
+           widthMask = endtab[w];
+#endif
+           switch (cfb8ComputeClipMasks32 (pBox, numRects, xG, yG, w, hTmp, clips))
+           {
+           case rgnPART:
+#ifdef USE_LEFTBITS
+               cTmp = clips;
+               do {
+                   dst = dstLine;
+                   dstLine = (unsigned long *) (((char *) dstLine) + bwidthDst);
+                   GlyphBits(glyphBits, w, c)
+                   c &= *cTmp++;
+                   if (c)
+                   {
+                       WriteBitGroup(dst, pixel, GetBitGroup(BitRight(c,xoff)));
+                       c = BitLeft(c,PGSZB - xoff); 
+                       dst += DST_INC;
+                       while (c)
+                       {
+                           WriteBitGroup(dst, pixel, GetBitGroup(c));
+                           NextBitGroup(c);
+                           dst += DST_INC;
+                       }
+                   }
+               } while (--hTmp);
+               break;
+#else /* !USE_LEFT_BITS */
+               {
+                   int h;
+    
+                   h = hTmp;
+                   do
+                   {
+                       --h;
+                       clips[h] = clips[h] & glyphBits[h];
+                   } while (h);
+               }
+               glyphBits = clips;
+               /* fall through */
+#endif /* USE_LEFT_BITS */
+           case rgnIN:
+#ifdef STIPPLE
+               STIPPLE(dstLine,glyphBits,pixel,bwidthDst,hTmp,xoff);
+#else
+#ifdef USE_STIPPLE_CODE
+               cfbStippleStackTE(dstLine,glyphBits,pixel,bwidthDst,hTmp,xoff);
+#else
+               do {
+                   dst = dstLine;
+                   dstLine = (unsigned long *) (((char *) dstLine) + bwidthDst);
+                   GlyphBits(glyphBits, w, c)
+                   if (c)
+                   {
+                       /* This code originally could read memory locations
+                        * that were not mapped. Hence we have to check the
+                        * trailing bits to see whether they are zero and if
+                        * then skip them correctly. This is no problem for
+                        * the GXcopy case, since there only the pixels that
+                        * are non-zero are written ...
+                        */
+#ifndef GLYPHROP
+                       WriteBitGroup(dst, pixel, GetBitGroup(BitRight(c,xoff)));
+                       c = BitLeft(c,PGSZB - xoff);
+                       dst += DST_INC;
+#else /* GLYPHROP */
+                        if (bits = GetBitGroup(BitRight(c,xoff)))
+                         WriteBitGroup(dst, pixel, bits);
+                       c = BitLeft(c,PGSZB - xoff);
+                       dst += DST_INC;
+
+                       while (c && ((bits = GetBitGroup(c)) == 0))
+                       {
+                           NextBitGroup(c);
+                           dst += DST_INC;
+                        } 
+#endif /* GLYPHROP */
+                       while (c)
+                       {
+                           WriteBitGroup(dst, pixel, GetBitGroup(c));
+                           NextBitGroup(c);
+                           dst += DST_INC;
+                       }
+                   }
+               } while (--hTmp);
+#endif /* USE_STIPPLE_CODE else */
+#endif /* STIPPLE else */
+               break;
+           }
+       }
+    }
+    DEALLOCATE_LOCAL (clips);
+}
+
+#endif /* FOUR_BIT_CODE */
diff --git a/Xserver/programs/Xserver/cfb/cfbhrzvert.c b/Xserver/programs/Xserver/cfb/cfbhrzvert.c
new file mode 100644 (file)
index 0000000..f6e4bb9
--- /dev/null
@@ -0,0 +1,521 @@
+/***********************************************************
+
+Copyright (c) 1987  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+
+Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
+
+                        All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and its 
+documentation for any purpose and without fee is hereby granted, 
+provided that the above copyright notice appear in all copies and that
+both that copyright notice and this permission notice appear in 
+supporting documentation, and that the name of Digital not be
+used in advertising or publicity pertaining to distribution of the
+software without specific, written prior permission.  
+
+DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
+ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
+DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
+ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+SOFTWARE.
+
+******************************************************************/
+/* $XConsortium: cfbhrzvert.c,v 1.8 94/04/17 20:28:51 dpw Exp $ */
+/* $XFree86: xc/programs/Xserver/cfb/cfbhrzvert.c,v 3.2 1996/11/24 09:51:43 dawes Exp $ */
+#include "X.h"
+
+#include "gc.h"
+#include "window.h"
+#include "pixmap.h"
+#include "region.h"
+
+#include "cfb.h"
+#include "cfbmskbits.h"
+
+/* horizontal solid line
+   abs(len) > 1
+*/
+cfbHorzS(rop, and, xor, addrl, nlwidth, x1, y1, len)
+register int rop;
+register unsigned long and;
+register unsigned long xor;
+register unsigned long *addrl; /* pointer to base of bitmap */
+int nlwidth;           /* width in longwords of bitmap */
+int x1;                        /* initial point */ 
+int y1;
+int len;               /* length of line */
+{
+    register int nlmiddle;
+    register unsigned long startmask;
+    register unsigned long endmask;
+#if PSZ == 24
+    int leftIndex, rightIndex, xOffset;
+    unsigned long piQxelAnd[3], piQxelXor[3];
+    piQxelAnd[0] = (and & 0xFFFFFF) | ((and<<24)  & 0xFF000000);
+    piQxelAnd[1] = ((and>>8)  & 0xFFFF)| ((and<<16) & 0xFFFF0000);
+    piQxelAnd[2] = ((and<<8) & 0xFFFFFF00) | ((and>>16) & 0xFF);
+
+    piQxelXor[0] = (xor & 0xFFFFFF) | ((xor<<24) & 0xFF000000);
+    piQxelXor[1] = ((xor>>8)  & 0xFFFF)| ((xor<<16) & 0xFFFF0000);
+    piQxelXor[2] = ((xor<<8) & 0xFFFFFF00) | ((xor>>16) & 0xFF);
+
+    leftIndex = x1 & 3;
+    rightIndex = ((x1 + len) < 5)?0:(x1 + len)&3;
+    nlmiddle = len;
+    if(leftIndex){
+      nlmiddle -= (4 - leftIndex);
+    }
+    if(rightIndex){
+      nlmiddle -= rightIndex;
+    }
+    if (nlmiddle < 0)
+      nlmiddle = 0;
+
+    nlmiddle >>= 2;
+
+    addrl += (y1 * nlwidth) + (x1 >> 2)*3 + (leftIndex?leftIndex-1:0);
+
+    switch(leftIndex+len){
+    case 4:
+      switch(leftIndex){
+      case 0:
+       *addrl++ = DoRRop (*addrl, piQxelAnd[0], piQxelXor[0]);
+       *addrl++ = DoRRop (*addrl, piQxelAnd[1], piQxelXor[1]);
+       *addrl   = DoRRop (*addrl, piQxelAnd[2], piQxelXor[2]);
+       break;
+      case 1:
+       *addrl++ = DoMaskRRop (*addrl, piQxelAnd[0], piQxelXor[0], 0xFF000000);
+       *addrl++ = DoRRop (*addrl, piQxelAnd[1], piQxelXor[1]);
+       *addrl   = DoRRop (*addrl, piQxelAnd[2], piQxelXor[2]);
+       break;
+      case 2:
+       *addrl++ = DoMaskRRop (*addrl, piQxelAnd[1], piQxelXor[1], 0xFFFF0000);
+       *addrl   = DoRRop (*addrl, piQxelAnd[2], piQxelXor[2]);
+       break;
+      case 3:
+       *addrl = DoMaskRRop (*addrl, piQxelAnd[2], piQxelXor[2], 0xFFFFFF00);
+       break;
+      }
+      break;
+    case 3:
+      switch(leftIndex){
+      case 0:
+       *addrl++ = DoRRop (*addrl, piQxelAnd[0], piQxelXor[0]);
+       *addrl++ = DoRRop (*addrl, piQxelAnd[1], piQxelXor[1]);
+       *addrl = DoMaskRRop (*addrl, piQxelAnd[2], piQxelXor[2], 0xFF);
+       break;
+      case 1:
+       *addrl++ = DoMaskRRop (*addrl, piQxelAnd[0], piQxelXor[0], 0xFF000000);
+       *addrl++ = DoRRop (*addrl, piQxelAnd[1], piQxelXor[1]);
+       *addrl = DoMaskRRop (*addrl, piQxelAnd[2], piQxelXor[2], 0xFF);
+       break;
+      case 2:
+       *addrl++ = DoMaskRRop (*addrl, piQxelAnd[1], piQxelXor[1], 0xFFFF0000);
+       *addrl = DoMaskRRop (*addrl, piQxelAnd[2], piQxelXor[2], 0xFF);
+       break;
+      }
+      break;
+    case 2:
+      if(leftIndex){
+       *addrl++ = DoMaskRRop (*addrl, piQxelAnd[0], piQxelXor[0], 0xFF000000);
+      }
+      else{
+       *addrl++ = DoRRop (*addrl, piQxelAnd[0], piQxelXor[0]);
+      }
+      *addrl =  DoMaskRRop (*addrl, piQxelAnd[1], piQxelXor[1], 0xFFFF);
+      break;
+    case 1: /*only if leftIndex = 0 and w = 1*/
+      *addrl = DoMaskRRop (*addrl, piQxelAnd[0], piQxelXor[0], 0xFFFFFF);
+      break;
+    case 0: /*never*/
+      break;
+    default:
+      {
+       if (rop == GXcopy){
+         switch(leftIndex){
+         case 0:
+           break;
+         case 1:
+           *addrl++ = ((*addrl) & 0xFFFFFF) | (piQxelXor[0] & 0xFF000000);
+           *addrl++ = piQxelXor[1];
+           *addrl++ = piQxelXor[2];
+           break;
+         case 2:
+           *addrl++ = ((*addrl) & 0xFFFF) | (piQxelXor[1] & 0xFFFF0000);
+           *addrl++ = piQxelXor[2];
+           break;
+         case 3:
+           *addrl++ = ((*addrl) & 0xFF) | (piQxelXor[2] & 0xFFFFFF00);
+           break;
+         }
+         while(nlmiddle--){
+           *addrl++ = piQxelXor[0];
+           *addrl++ = piQxelXor[1];
+           *addrl++ = piQxelXor[2];
+         }
+         switch(rightIndex){
+         case 0:
+           break;
+         case 1:
+           *addrl = ((*addrl) & 0xFF000000) | (piQxelXor[0] & 0xFFFFFF);
+           break;
+         case 2:
+           *addrl++ = piQxelXor[0];
+           *addrl = ((*addrl) & 0xFFFF0000) | (piQxelXor[1] & 0xFFFF);
+           break;
+         case 3:
+           *addrl++ = piQxelXor[0];
+           *addrl++ = piQxelXor[1];
+           *addrl = ((*addrl) & 0xFFFFFF00) | (piQxelXor[2] & 0xFF);
+           break;
+         }
+       }
+       else{
+         if(rop == GXxor){
+         switch(leftIndex){
+         case 0:
+           break;
+         case 1:
+           *addrl++ ^= (piQxelXor[0]&0xFF000000);
+           *addrl++ ^= piQxelXor[1];
+           *addrl++ ^= piQxelXor[2];
+           break;
+         case 2:
+           *addrl++ ^= (piQxelXor[1]& 0xFFFF0000);
+           *addrl++ ^= piQxelXor[2];
+           break;
+         case 3:
+           *addrl++ ^= (piQxelXor[2]& 0xFFFFFF00);
+           break;
+         }
+         while(nlmiddle--){
+           *addrl++ ^= piQxelXor[0];
+           *addrl++ ^= piQxelXor[1];
+           *addrl++ ^= piQxelXor[2];
+         }
+         switch(rightIndex){
+         case 0:
+           break;
+         case 1:
+           *addrl ^= (piQxelXor[0]& 0xFFFFFF);
+           break;
+         case 2:
+           *addrl++ ^= piQxelXor[0];
+           *addrl ^= (piQxelXor[1]&0xFFFF);
+           break;
+         case 3:
+           *addrl++ ^= piQxelXor[0];
+           *addrl++ ^= piQxelXor[1];
+           *addrl ^= (piQxelXor[2]&0xFF);
+           break;
+         }
+       }
+         else{
+           switch(leftIndex){
+           case 0:
+             break;
+           case 1:
+             *addrl++ = DoMaskRRop (*addrl, piQxelAnd[0], piQxelXor[0], 0xFF000000);
+             *addrl++ = DoRRop (*addrl, piQxelAnd[1], piQxelXor[1]);
+             *addrl++ = DoRRop (*addrl, piQxelAnd[2], piQxelXor[2]);
+             break;
+           case 2:
+             *addrl++ = DoMaskRRop (*addrl, piQxelAnd[1], piQxelXor[1], 0xFFFF0000);
+             *addrl++ = DoRRop (*addrl, piQxelAnd[2], piQxelXor[2]);
+             break;
+           case 3:
+             *addrl++ = DoMaskRRop (*addrl, piQxelAnd[2], piQxelXor[2], 0xFFFFFF00);
+             break;
+         }
+         while(nlmiddle--){
+           *addrl++ = DoRRop (*addrl, piQxelAnd[0], piQxelXor[0]);
+           *addrl++ = DoRRop (*addrl, piQxelAnd[1], piQxelXor[1]);
+           *addrl++ = DoRRop (*addrl, piQxelAnd[2], piQxelXor[2]);
+         }
+         switch(rightIndex){
+         case 0:
+           break;
+         case 1:
+           *addrl++ = DoMaskRRop (*addrl, piQxelAnd[0], piQxelXor[0], 0xFFFFFF);
+           break;
+         case 2:
+           *addrl++ = DoRRop (*addrl, piQxelAnd[0], piQxelXor[0]);
+           *addrl = DoMaskRRop (*addrl, piQxelAnd[1], piQxelXor[1], 0xFFFF);
+           break;
+         case 3:
+           *addrl++ = DoRRop (*addrl, piQxelAnd[0], piQxelXor[0]);
+           *addrl++ = DoRRop (*addrl, piQxelAnd[1], piQxelXor[1]);
+           *addrl = DoMaskRRop (*addrl, piQxelAnd[2], piQxelXor[2], 0xFF);
+           break;
+         }
+
+         }
+       }
+      }
+    }
+#else
+    addrl = addrl + (y1 * nlwidth) + (x1 >> PWSH);
+
+    /* all bits inside same longword */
+    if ( ((x1 & PIM) + len) < PPW)
+    {
+       maskpartialbits(x1, len, startmask);
+       *addrl = DoMaskRRop (*addrl, and, xor, startmask);
+    }
+    else
+    {
+       maskbits(x1, len, startmask, endmask, nlmiddle);
+       if (rop == GXcopy)
+       {
+           if (startmask)
+           {
+               *addrl = (*addrl & ~startmask) | (xor & startmask);
+               addrl++;
+           }
+           while (nlmiddle--)
+               *addrl++ = xor;
+           if (endmask)
+               *addrl = (*addrl & ~endmask) | (xor & endmask);
+       }
+       else
+       {
+           if (startmask)
+           {
+               *addrl = DoMaskRRop (*addrl, and, xor, startmask);
+               addrl++;
+           }
+           if (rop == GXxor)
+           {
+               while (nlmiddle--)
+                   *addrl++ ^= xor;
+           }
+           else
+           {
+               while (nlmiddle--)
+               {
+                   *addrl = DoRRop (*addrl, and, xor);
+                   addrl++;
+               }
+           }
+           if (endmask)
+               *addrl = DoMaskRRop (*addrl, and, xor, endmask);
+       }
+    }
+#endif
+}
+
+/* vertical solid line */
+
+void
+cfbVertS(rop, and, xor, addrl, nlwidth, x1, y1, len)
+int rop;
+register unsigned long and, xor;
+register unsigned long *addrl; /* pointer to base of bitmap */
+register int nlwidth;  /* width in longwords of bitmap */
+int x1, y1;            /* initial point */
+register int len;      /* length of line */
+{
+#if PSZ == 24
+    int xIdx;
+    unsigned long and2, xor2, offset, mask, mask2;
+#endif
+#ifdef PIXEL_ADDR
+    register PixelType    *bits = (PixelType *) addrl;
+
+#if PSZ == 24
+    nlwidth <<= PWSH;
+    xIdx = x1 & 3;
+    bits = (PixelType *)(addrl + (y1 * nlwidth) + ((x1*3) >> 2));
+#else
+    nlwidth <<= PWSH;
+    bits = bits + (y1 * nlwidth) + x1;
+#endif
+#if PSZ == 24
+    mask2 = 0;
+    switch(xIdx){
+      case 0:
+        mask = 0xFF000000;
+       xor &= 0xFFFFFF;
+       and |= 0xFF000000;
+       break;
+      case 3:
+       mask = 0xFF;
+       xor &= 0xFFFFFF;
+       xor <<= 8;
+       and <<= 8;
+       and |= 0xFF;
+       break;
+      case 1:
+       mask = 0xFFFFFF;
+       mask2 = 0xFFFF0000;
+       xor2 = (xor>>8) & 0xFFFF;
+       xor &= 0xFF;
+       xor <<= 24;
+       and2 = (and >> 8 ) | 0xFFFF0000;
+       and <<= 24;
+       and |= 0xFFFFFF;
+       break;
+      case 2:
+       mask = 0x0000FFFF;
+       mask2 = 0xFFFFFF00;
+       xor2 = (xor >> 16) & 0xFF;
+       xor <<= 16;
+       xor &= 0xFFFF0000;
+       and2 = (and >> 16) | 0xFFFFFF00;
+       and <<= 16;
+       and |= 0xFFFF;
+       break;
+      }
+#endif
+
+    /*
+     * special case copy and xor to avoid a test per pixel
+     */
+    if (rop == GXcopy)
+    {
+#if PSZ == 24
+      switch(xIdx){
+      case 0:
+      case 3:
+       while (len--){
+         *bits = (*bits & mask)| xor;
+         bits += nlwidth;
+       }
+       break;
+      case 1:
+      case 2:
+       while (len--){
+         *bits = (*bits & mask)| xor;
+         bits++;
+         *bits = (*bits & mask2)| xor2;
+         bits--;
+         bits += nlwidth;
+       }
+       break;
+      }
+#else
+       while (len--)
+       {
+           *bits = xor;
+           bits += nlwidth;
+       }
+#endif
+    }
+    else if (rop == GXxor)
+    {
+#if PSZ == 24
+      switch(xIdx){
+      case 0:
+      case 3:
+       while (len--){
+         *bits ^=  xor;
+         bits += nlwidth;
+       }
+       break;
+      case 1:
+      case 2:
+       while (len--){
+         *bits ^= xor;
+         bits++;
+         *bits ^= xor2;
+         bits--;
+         bits += nlwidth;
+       }
+       break;
+      }
+#else
+       while (len--)
+       {
+           *bits ^= xor;
+           bits += nlwidth;
+       }
+#endif
+    }
+    else
+    {
+#if PSZ == 24
+      switch(xIdx){
+      case 0:
+       while (len--){
+         *bits = DoMaskRRop(*bits, and, xor, 0x00FFFFFF);
+         bits += nlwidth;
+       }
+       break;
+      case 3:
+       while (len--){
+         *bits = DoMaskRRop(*bits, and, xor, 0xFFFFFF00);
+         bits += nlwidth;
+       }
+       break;
+      case 1:
+       while (len--){
+         *bits = DoMaskRRop(*bits, and, xor, 0xFF000000);
+         bits++;
+         *bits = DoMaskRRop(*bits, and2, xor2, 0x0000FFFF);
+         bits--;
+         bits += nlwidth;
+       }
+       break;
+      case 2:
+       while (len--){
+         *bits = DoMaskRRop(*bits, and, xor, 0xFFFF0000);
+         bits++;
+         *bits = DoMaskRRop(*bits, and2, xor2, 0x000000FF);
+         bits--;
+         bits += nlwidth;
+       }
+       break;
+      }
+#else
+       while (len--)
+       {
+           *bits = DoRRop(*bits, and, xor);
+           bits += nlwidth;
+       }
+#endif
+    }
+#else /* !PIXEL_ADDR */
+#if PSZ == 24
+    addrl = addrl + (y1 * nlwidth) + ((x1*3) >>2);
+
+    and |= ~cfbmask[(x1 & 3)<<1];
+    xor &= cfbmask[(x1 & 3)<<1];
+#else
+    addrl = addrl + (y1 * nlwidth) + (x1 >> PWSH);
+
+    and |= ~cfbmask[x1 & PIM];
+    xor &= cfbmask[x1 & PIM];
+#endif
+
+    while (len--)
+    {
+       *addrl = DoRRop (*addrl, and, xor);
+       addrl += nlwidth;
+    }
+#endif
+}
diff --git a/Xserver/programs/Xserver/cfb/cfbigblt8.c b/Xserver/programs/Xserver/cfb/cfbigblt8.c
new file mode 100644 (file)
index 0000000..db24781
--- /dev/null
@@ -0,0 +1,98 @@
+/*
+ * $XConsortium: cfbigblt8.c,v 1.9 94/04/17 20:28:52 dpw Exp $
+ *
+Copyright (c) 1990  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+ *
+ * Author:  Keith Packard, MIT X Consortium
+ */
+
+#include       "X.h"
+#include       "Xmd.h"
+#include       "Xproto.h"
+#include       "cfb.h"
+#include       "fontstruct.h"
+#include       "dixfontstr.h"
+#include       "gcstruct.h"
+#include       "windowstr.h"
+#include       "scrnintstr.h"
+#include       "pixmapstr.h"
+#include       "regionstr.h"
+#include       "cfbmskbits.h"
+#include       "cfb8bit.h"
+
+void
+cfbImageGlyphBlt8 (pDrawable, pGC, x, y, nglyph, ppci, pglyphBase)
+    DrawablePtr            pDrawable;
+    GCPtr          pGC;
+    int                    x, y;
+    unsigned int    nglyph;
+    CharInfoPtr            *ppci;
+    pointer        pglyphBase;
+{
+    ExtentInfoRec info;                /* used by QueryGlyphExtents() */
+    xRectangle backrect;
+    int                fillStyle;
+    int                alu;
+    int                fgPixel;
+    int                rop;
+    int                xor;
+    int                and;
+    int                pm;
+    cfbPrivGC      *priv;
+
+    QueryGlyphExtents(pGC->font, ppci, (unsigned long)nglyph, &info);
+
+    if (info.overallWidth >= 0)
+    {
+       backrect.x = x;
+       backrect.width = info.overallWidth;
+    }
+    else
+    {
+       backrect.x = x + info.overallWidth;
+       backrect.width = -info.overallWidth;
+    }
+    backrect.y = y - FONTASCENT(pGC->font);
+    backrect.height = FONTASCENT(pGC->font) + FONTDESCENT(pGC->font);
+
+    priv = cfbGetGCPrivate(pGC);
+
+    /* this code cheats by knowing that ValidateGC isn't
+     * necessary for PolyFillRect
+     */
+
+    fgPixel = pGC->fgPixel;
+
+    pGC->fgPixel = pGC->bgPixel;
+    priv->xor = PFILL(pGC->bgPixel);
+
+    (*pGC->ops->PolyFillRect) (pDrawable, pGC, 1, &backrect);
+
+    pGC->fgPixel = fgPixel;
+
+    priv->xor = PFILL(pGC->fgPixel);
+
+    (*pGC->ops->PolyGlyphBlt) (pDrawable, pGC, x, y, nglyph, ppci, pglyphBase);
+    
+}
diff --git a/Xserver/programs/Xserver/cfb/cfbimage.c b/Xserver/programs/Xserver/cfb/cfbimage.c
new file mode 100644 (file)
index 0000000..21ef2d2
--- /dev/null
@@ -0,0 +1,193 @@
+/***********************************************************
+
+Copyright (c) 1987  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+
+Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
+
+                        All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and its 
+documentation for any purpose and without fee is hereby granted, 
+provided that the above copyright notice appear in all copies and that
+both that copyright notice and this permission notice appear in 
+supporting documentation, and that the name of Digital not be
+used in advertising or publicity pertaining to distribution of the
+software without specific, written prior permission.  
+
+DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
+ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
+DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
+ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+SOFTWARE.
+
+******************************************************************/
+/* $XConsortium: cfbimage.c,v 1.18 94/04/17 20:28:52 dpw Exp $ */
+
+#include "X.h"
+#include "windowstr.h"
+#include "pixmapstr.h"
+#include "scrnintstr.h"
+#include "gcstruct.h"
+#include "cfb.h"
+#include "cfbmskbits.h"
+#include "servermd.h"
+
+void
+cfbPutImage(pDraw, pGC, depth, x, y, w, h, leftPad, format, pImage)
+    DrawablePtr pDraw;
+    GCPtr      pGC;
+    int                depth, x, y, w, h;
+    int                leftPad;
+    int                format;
+    char       *pImage;
+{
+    int                bitsPerPixel;
+    PixmapPtr   pPixmap;
+
+    if ((w == 0) || (h == 0))
+       return;
+
+    if (format != XYPixmap)
+    {
+       pPixmap = GetScratchPixmapHeader(pDraw->pScreen, w+leftPad, h, depth,
+                     BitsPerPixel(depth), PixmapBytePad(w+leftPad, depth),
+                     (pointer)pImage);
+       if (!pPixmap)
+           return;
+       
+       cfbGetGCPrivate(pGC)->fExpose = FALSE;
+       if (format == ZPixmap)
+           (void)(*pGC->ops->CopyArea)((DrawablePtr)pPixmap, pDraw, pGC,
+                                       leftPad, 0, w, h, x, y);
+       else
+           (void)(*pGC->ops->CopyPlane)((DrawablePtr)pPixmap, pDraw, pGC,
+                                        leftPad, 0, w, h, x, y, 1);
+       cfbGetGCPrivate(pGC)->fExpose = TRUE;
+        FreeScratchPixmapHeader(pPixmap);
+    }
+    else
+    {
+       unsigned long   oldFg, oldBg;
+       XID             gcv[3];
+       unsigned long   oldPlanemask;
+       unsigned long   i;
+       long            bytesPer;
+
+       depth = pGC->depth;
+       oldPlanemask = pGC->planemask;
+       oldFg = pGC->fgPixel;
+       oldBg = pGC->bgPixel;
+       gcv[0] = ~0L;
+       gcv[1] = 0;
+       DoChangeGC(pGC, GCForeground | GCBackground, gcv, 0);
+       bytesPer = (long)h * BitmapBytePad(w + leftPad);
+
+       for (i = 1 << (depth-1); i != 0; i >>= 1, pImage += bytesPer)
+       {
+           if (i & oldPlanemask)
+           {
+               gcv[0] = i;
+               DoChangeGC(pGC, GCPlaneMask, gcv, 0);
+               ValidateGC(pDraw, pGC);
+               (*pGC->ops->PutImage)(pDraw, pGC, 1, x, y, w, h, leftPad,
+                                XYBitmap, pImage);
+           }
+       }
+       gcv[0] = oldPlanemask;
+       gcv[1] = oldFg;
+       gcv[2] = oldBg;
+       DoChangeGC(pGC, GCPlaneMask | GCForeground | GCBackground, gcv, 0);
+    }
+}
+
+void
+cfbGetImage(pDrawable, sx, sy, w, h, format, planeMask, pdstLine)
+    DrawablePtr pDrawable;
+    int                sx, sy, w, h;
+    unsigned int format;
+    unsigned long planeMask;
+    char       *pdstLine;
+{
+    BoxRec box;
+    DDXPointRec ptSrc;
+    RegionRec rgnDst;
+    ScreenPtr pScreen;
+    PixmapPtr pPixmap;
+
+    if ((w == 0) || (h == 0))
+       return;
+    if (pDrawable->bitsPerPixel == 1)
+    {
+       mfbGetImage(pDrawable, sx, sy, w, h, format, planeMask, pdstLine);
+       return;
+    }
+    pScreen = pDrawable->pScreen;
+    if (format == ZPixmap)
+    {
+       pPixmap = GetScratchPixmapHeader(pScreen, w, h, 
+                       pDrawable->depth, pDrawable->bitsPerPixel,
+                       PixmapBytePad(w,pDrawable->depth), (pointer)pdstLine);
+       if (!pPixmap)
+           return;
+       if ((planeMask & PMSK) != PMSK)
+           bzero((char *)pdstLine, pPixmap->devKind * h);
+        ptSrc.x = sx + pDrawable->x;
+        ptSrc.y = sy + pDrawable->y;
+        box.x1 = 0;
+        box.y1 = 0;
+        box.x2 = w;
+        box.y2 = h;
+        REGION_INIT(pScreen, &rgnDst, &box, 1);
+       cfbDoBitblt(pDrawable, (DrawablePtr)pPixmap, GXcopy, &rgnDst,
+                   &ptSrc, planeMask);
+        REGION_UNINIT(pScreen, &rgnDst);
+       FreeScratchPixmapHeader(pPixmap);
+    }
+    else
+    {
+#if PSZ == 8
+       pPixmap = GetScratchPixmapHeader(pScreen, w, h,  /*depth*/ 1,
+                       /*bpp*/ 1, BitmapBytePad(w), (pointer)pdstLine);
+       if (!pPixmap)
+           return;
+
+        ptSrc.x = sx + pDrawable->x;
+        ptSrc.y = sy + pDrawable->y;
+        box.x1 = 0;
+        box.y1 = 0;
+        box.x2 = w;
+        box.y2 = h;
+        REGION_INIT(pScreen, &rgnDst, &box, 1);
+       cfbCopyImagePlane (pDrawable, (DrawablePtr)pPixmap, GXcopy, &rgnDst,
+                   &ptSrc, planeMask);
+        REGION_UNINIT(pScreen, &rgnDst);
+       FreeScratchPixmapHeader(pPixmap);
+#else
+       miGetImage (pDrawable, sx, sy, w, h, format, planeMask, pdstLine);
+#endif
+    }
+}
diff --git a/Xserver/programs/Xserver/cfb/cfbline.c b/Xserver/programs/Xserver/cfb/cfbline.c
new file mode 100644 (file)
index 0000000..17e8d2b
--- /dev/null
@@ -0,0 +1,755 @@
+/***********************************************************
+
+Copyright (c) 1987  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+
+Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
+
+                        All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and its 
+documentation for any purpose and without fee is hereby granted, 
+provided that the above copyright notice appear in all copies and that
+both that copyright notice and this permission notice appear in 
+supporting documentation, and that the name of Digital not be
+used in advertising or publicity pertaining to distribution of the
+software without specific, written prior permission.  
+
+DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
+ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
+DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
+ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+SOFTWARE.
+
+******************************************************************/
+/* $XConsortium: cfbline.c,v 1.24 94/07/28 14:33:33 dpw Exp $ */
+/* $XFree86: xc/programs/Xserver/cfb/cfbline.c,v 3.0 1996/06/29 09:05:38 dawes Exp $ */
+#include "X.h"
+
+#include "gcstruct.h"
+#include "windowstr.h"
+#include "pixmapstr.h"
+#include "regionstr.h"
+#include "scrnintstr.h"
+#include "mistruct.h"
+
+#include "cfb.h"
+#include "cfbmskbits.h"
+#include "miline.h"
+
+/* single-pixel lines on a color frame buffer
+
+   NON-SLOPED LINES
+   horizontal lines are always drawn left to right; we have to
+move the endpoints right by one after they're swapped.
+   horizontal lines will be confined to a single band of a
+region.  the code finds that band (giving up if the lower
+bound of the band is above the line we're drawing); then it
+finds the first box in that band that contains part of the
+line.  we clip the line to subsequent boxes in that band.
+   vertical lines are always drawn top to bottom (y-increasing.)
+this requires adding one to the y-coordinate of each endpoint
+after swapping.
+
+   SLOPED LINES
+   when clipping a sloped line, we bring the second point inside
+the clipping box, rather than one beyond it, and then add 1 to
+the length of the line before drawing it.  this lets us use
+the same box for finding the outcodes for both endpoints.  since
+the equation for clipping the second endpoint to an edge gives us
+1 beyond the edge, we then have to move the point towards the
+first point by one step on the major axis.
+   eventually, there will be a diagram here to explain what's going
+on.  the method uses Cohen-Sutherland outcodes to determine
+outsideness, and a method similar to Pike's layers for doing the
+actual clipping.
+
+*/
+
+void
+#ifdef POLYSEGMENT
+cfbSegmentSS (pDrawable, pGC, nseg, pSeg)
+    DrawablePtr        pDrawable;
+    GCPtr      pGC;
+    int                nseg;
+    register xSegment  *pSeg;
+#else
+cfbLineSS (pDrawable, pGC, mode, npt, pptInit)
+    DrawablePtr pDrawable;
+    GCPtr      pGC;
+    int                mode;           /* Origin or Previous */
+    int                npt;            /* number of points */
+    DDXPointPtr pptInit;
+#endif
+{
+    int nboxInit;
+    register int nbox;
+    BoxPtr pboxInit;
+    register BoxPtr pbox;
+#ifndef POLYSEGMENT
+    register DDXPointPtr ppt;  /* pointer to list of translated points */
+#endif
+
+    unsigned int oc1;          /* outcode of point 1 */
+    unsigned int oc2;          /* outcode of point 2 */
+
+    unsigned long *addrl;      /* address of destination pixmap */
+    int nlwidth;               /* width in longwords of destination pixmap */
+    int xorg, yorg;            /* origin of window */
+
+    int adx;           /* abs values of dx and dy */
+    int ady;
+    int signdx;                /* sign of dx and dy */
+    int signdy;
+    int e, e1, e2;             /* bresenham error and increments */
+    int len;                   /* length of segment */
+    int axis;                  /* major axis */
+    int octant;
+    unsigned int bias = miGetZeroLineBias(pDrawable->pScreen);
+
+                               /* a bunch of temporaries */
+    int tmp;
+    register int y1, y2;
+    register int x1, x2;
+    RegionPtr cclip;
+    cfbPrivGCPtr    devPriv;
+    unsigned long   xor, and;
+    int                    alu;
+
+    devPriv = cfbGetGCPrivate(pGC);
+    cclip = devPriv->pCompositeClip;
+    pboxInit = REGION_RECTS(cclip);
+    nboxInit = REGION_NUM_RECTS(cclip);
+
+    cfbGetLongWidthAndPointer (pDrawable, nlwidth, addrl)
+
+    alu = devPriv->rop;
+    xor = devPriv->xor;
+    and = devPriv->and;
+    xorg = pDrawable->x;
+    yorg = pDrawable->y;
+#ifdef POLYSEGMENT
+    while (nseg--)
+#else
+    ppt = pptInit;
+    x2 = ppt->x + xorg;
+    y2 = ppt->y + yorg;
+    while(--npt)
+#endif
+    {
+       nbox = nboxInit;
+       pbox = pboxInit;
+
+#ifdef POLYSEGMENT
+       x1 = pSeg->x1 + xorg;
+       y1 = pSeg->y1 + yorg;
+       x2 = pSeg->x2 + xorg;
+       y2 = pSeg->y2 + yorg;
+       pSeg++;
+#else
+       x1 = x2;
+       y1 = y2;
+       ++ppt;
+       if (mode == CoordModePrevious)
+       {
+           xorg = x1;
+           yorg = y1;
+       }
+       x2 = ppt->x + xorg;
+       y2 = ppt->y + yorg;
+#endif
+
+       if (x1 == x2)  /* vertical line */
+       {
+           /* make the line go top to bottom of screen, keeping
+              endpoint semantics
+           */
+           if (y1 > y2)
+           {
+               register int tmp;
+
+               tmp = y2;
+               y2 = y1 + 1;
+               y1 = tmp + 1;
+#ifdef POLYSEGMENT
+               if (pGC->capStyle != CapNotLast)
+                   y1--;
+#endif
+           }
+#ifdef POLYSEGMENT
+           else if (pGC->capStyle != CapNotLast)
+               y2++;
+#endif
+           /* get to first band that might contain part of line */
+           while ((nbox) && (pbox->y2 <= y1))
+           {
+               pbox++;
+               nbox--;
+           }
+
+           if (nbox)
+           {
+               /* stop when lower edge of box is beyond end of line */
+               while((nbox) && (y2 >= pbox->y1))
+               {
+                   if ((x1 >= pbox->x1) && (x1 < pbox->x2))
+                   {
+                       int y1t, y2t;
+                       /* this box has part of the line in it */
+                       y1t = max(y1, pbox->y1);
+                       y2t = min(y2, pbox->y2);
+                       if (y1t != y2t)
+                       {
+                           cfbVertS (alu, and, xor,
+                                     addrl, nlwidth, 
+                                     x1, y1t, y2t-y1t);
+                       }
+                   }
+                   nbox--;
+                   pbox++;
+               }
+           }
+#ifndef POLYSEGMENT
+           y2 = ppt->y + yorg;
+#endif
+       }
+       else if (y1 == y2)  /* horizontal line */
+       {
+           /* force line from left to right, keeping
+              endpoint semantics
+           */
+           if (x1 > x2)
+           {
+               register int tmp;
+
+               tmp = x2;
+               x2 = x1 + 1;
+               x1 = tmp + 1;
+#ifdef POLYSEGMENT
+               if (pGC->capStyle != CapNotLast)
+                   x1--;
+#endif
+           }
+#ifdef POLYSEGMENT
+           else if (pGC->capStyle != CapNotLast)
+               x2++;
+#endif
+
+           /* find the correct band */
+           while( (nbox) && (pbox->y2 <= y1))
+           {
+               pbox++;
+               nbox--;
+           }
+
+           /* try to draw the line, if we haven't gone beyond it */
+           if ((nbox) && (pbox->y1 <= y1))
+           {
+               /* when we leave this band, we're done */
+               tmp = pbox->y1;
+               while((nbox) && (pbox->y1 == tmp))
+               {
+                   int x1t, x2t;
+
+                   if (pbox->x2 <= x1)
+                   {
+                       /* skip boxes until one might contain start point */
+                       nbox--;
+                       pbox++;
+                       continue;
+                   }
+
+                   /* stop if left of box is beyond right of line */
+                   if (pbox->x1 >= x2)
+                   {
+                       nbox = 0;
+                       break;
+                   }
+
+                   x1t = max(x1, pbox->x1);
+                   x2t = min(x2, pbox->x2);
+                   if (x1t != x2t)
+                   {
+                       cfbHorzS (alu, and, xor,
+                                 addrl, nlwidth, 
+                                 x1t, y1, x2t-x1t);
+                   }
+                   nbox--;
+                   pbox++;
+               }
+           }
+#ifndef POLYSEGMENT
+           x2 = ppt->x + xorg;
+#endif
+       }
+       else    /* sloped line */
+       {
+           CalcLineDeltas(x1, y1, x2, y2, adx, ady, signdx, signdy,
+                          1, 1, octant);
+
+           if (adx > ady)
+           {
+               axis = X_AXIS;
+               e1 = ady << 1;
+               e2 = e1 - (adx << 1);
+               e = e1 - adx;
+           }
+           else
+           {
+               axis = Y_AXIS;
+               e1 = adx << 1;
+               e2 = e1 - (ady << 1);
+               e = e1 - ady;
+               SetYMajorOctant(octant);
+           }
+
+           FIXUP_ERROR(e, octant, bias);
+
+           /* we have bresenham parameters and two points.
+              all we have to do now is clip and draw.
+           */
+
+           while(nbox--)
+           {
+               oc1 = 0;
+               oc2 = 0;
+               OUTCODES(oc1, x1, y1, pbox);
+               OUTCODES(oc2, x2, y2, pbox);
+               if ((oc1 | oc2) == 0)
+               {
+                   if (axis == X_AXIS)
+                       len = adx;
+                   else
+                       len = ady;
+#ifdef POLYSEGMENT
+                   if (pGC->capStyle != CapNotLast)
+                       len++;
+#endif
+                   cfbBresS (alu, and, xor,
+                         addrl, nlwidth,
+                         signdx, signdy, axis, x1, y1,
+                         e, e1, e2, len);
+                   break;
+               }
+               else if (oc1 & oc2)
+               {
+                   pbox++;
+               }
+               else
+               {
+                   int new_x1 = x1, new_y1 = y1, new_x2 = x2, new_y2 = y2;
+                   int clip1 = 0, clip2 = 0;
+                   int clipdx, clipdy;
+                   int err;
+                   
+                   if (miZeroClipLine(pbox->x1, pbox->y1, pbox->x2-1,
+                                      pbox->y2-1,
+                                      &new_x1, &new_y1, &new_x2, &new_y2,
+                                      adx, ady, &clip1, &clip2,
+                                      octant, bias, oc1, oc2) == -1)
+                   {
+                       pbox++;
+                       continue;
+                   }
+
+                   if (axis == X_AXIS)
+                       len = abs(new_x2 - new_x1);
+                   else
+                       len = abs(new_y2 - new_y1);
+#ifdef POLYSEGMENT
+                   if (clip2 != 0 || pGC->capStyle != CapNotLast)
+                       len++;
+#else
+                   len += (clip2 != 0);
+#endif
+                   if (len)
+                   {
+                       /* unwind bresenham error term to first point */
+                       if (clip1)
+                       {
+                           clipdx = abs(new_x1 - x1);
+                           clipdy = abs(new_y1 - y1);
+                           if (axis == X_AXIS)
+                               err = e+((clipdy*e2) + ((clipdx-clipdy)*e1));
+                           else
+                               err = e+((clipdx*e2) + ((clipdy-clipdx)*e1));
+                       }
+                       else
+                           err = e;
+                           cfbBresS(alu, and, xor,
+                                    addrl, nlwidth,
+                                    signdx, signdy, axis, new_x1, new_y1,
+                                    err, e1, e2, len);
+                   }
+                   pbox++;
+               }
+           } /* while (nbox--) */
+       } /* sloped line */
+    } /* while (nline--) */
+
+#ifndef POLYSEGMENT
+    /* paint the last point if the end style isn't CapNotLast.
+       (Assume that a projecting, butt, or round cap that is one
+        pixel wide is the same as the single pixel of the endpoint.)
+    */
+
+    if ((pGC->capStyle != CapNotLast) &&
+       ((ppt->x + xorg != pptInit->x + pDrawable->x) ||
+        (ppt->y + yorg != pptInit->y + pDrawable->y) ||
+        (ppt == pptInit + 1)))
+    {
+       nbox = nboxInit;
+       pbox = pboxInit;
+       while (nbox--)
+       {
+           if ((x2 >= pbox->x1) &&
+               (y2 >= pbox->y1) &&
+               (x2 <  pbox->x2) &&
+               (y2 <  pbox->y2))
+           {
+               unsigned long mask;
+               unsigned long scrbits;
+
+#if PSZ == 24
+               mask = cfbmask[(x2 & 3)<<1];
+               addrl += (y2 * nlwidth) + ((x2*3) >> 2);
+#else
+               mask = cfbmask[x2 & PIM];
+               addrl += (y2 * nlwidth) + (x2 >> PWSH);
+#endif
+               scrbits = *addrl;
+               *addrl = (scrbits & ~mask) |
+                        (DoRRop (scrbits, and, xor) & mask);
+               break;
+           }
+           else
+               pbox++;
+       }
+    }
+#endif
+}
+
+/*
+ * Draw dashed 1-pixel lines.
+ */
+
+void
+#ifdef POLYSEGMENT
+cfbSegmentSD (pDrawable, pGC, nseg, pSeg)
+    DrawablePtr        pDrawable;
+    register GCPtr     pGC;
+    int                nseg;
+    register xSegment  *pSeg;
+#else
+cfbLineSD( pDrawable, pGC, mode, npt, pptInit)
+    DrawablePtr pDrawable;
+    register GCPtr pGC;
+    int mode;          /* Origin or Previous */
+    int npt;           /* number of points */
+    DDXPointPtr pptInit;
+#endif
+{
+    int nboxInit;
+    register int nbox;
+    BoxPtr pboxInit;
+    register BoxPtr pbox;
+#ifndef POLYSEGMENT
+    register DDXPointPtr ppt;  /* pointer to list of translated points */
+#endif
+
+    register unsigned int oc1;         /* outcode of point 1 */
+    register unsigned int oc2;         /* outcode of point 2 */
+
+    unsigned long *addrl;              /* address of destination pixmap */
+    int nlwidth;               /* width in longwords of destination pixmap */
+    int xorg, yorg;            /* origin of window */
+
+    int adx;           /* abs values of dx and dy */
+    int ady;
+    int signdx;                /* sign of dx and dy */
+    int signdy;
+    int e, e1, e2;             /* bresenham error and increments */
+    int len;                   /* length of segment */
+    int axis;                  /* major axis */
+    int octant;
+    unsigned int bias = miGetZeroLineBias(pDrawable->pScreen);
+    int x1, x2, y1, y2;
+    RegionPtr cclip;
+    cfbRRopRec     rrops[2];
+    unsigned char   *pDash;
+    int                    dashOffset;
+    int                    numInDashList;
+    int                    dashIndex;
+    int                    isDoubleDash;
+    int                    dashIndexTmp, dashOffsetTmp;
+    int                    unclippedlen;
+    cfbPrivGCPtr    devPriv;
+
+    devPriv = cfbGetGCPrivate(pGC);
+    cclip = devPriv->pCompositeClip;
+    rrops[0].rop = devPriv->rop;
+    rrops[0].and = devPriv->and;
+    rrops[0].xor = devPriv->xor;
+    if (pGC->alu == GXcopy)
+    {
+       rrops[1].rop = GXcopy;
+       rrops[1].and = 0;
+       rrops[1].xor = PFILL (pGC->bgPixel);
+    }
+    else
+    {
+       rrops[1].rop = cfbReduceRasterOp (pGC->alu,
+                                         pGC->bgPixel, pGC->planemask,
+                                         &rrops[1].and, &rrops[1].xor);
+    }
+    pboxInit = REGION_RECTS(cclip);
+    nboxInit = REGION_NUM_RECTS(cclip);
+
+    cfbGetLongWidthAndPointer (pDrawable, nlwidth, addrl)
+
+    /* compute initial dash values */
+     
+    pDash = (unsigned char *) pGC->dash;
+    numInDashList = pGC->numInDashList;
+    isDoubleDash = (pGC->lineStyle == LineDoubleDash);
+    dashIndex = 0;
+    dashOffset = 0;
+    miStepDash ((int)pGC->dashOffset, &dashIndex, pDash,
+               numInDashList, &dashOffset);
+
+    xorg = pDrawable->x;
+    yorg = pDrawable->y;
+#ifdef POLYSEGMENT
+    while (nseg--)
+#else
+    ppt = pptInit;
+    x2 = ppt->x + xorg;
+    y2 = ppt->y + yorg;
+    while(--npt)
+#endif
+    {
+       nbox = nboxInit;
+       pbox = pboxInit;
+
+#ifdef POLYSEGMENT
+       x1 = pSeg->x1 + xorg;
+       y1 = pSeg->y1 + yorg;
+       x2 = pSeg->x2 + xorg;
+       y2 = pSeg->y2 + yorg;
+       pSeg++;
+#else
+       x1 = x2;
+       y1 = y2;
+       ++ppt;
+       if (mode == CoordModePrevious)
+       {
+           xorg = x1;
+           yorg = y1;
+       }
+       x2 = ppt->x + xorg;
+       y2 = ppt->y + yorg;
+#endif
+
+       CalcLineDeltas(x1, y1, x2, y2, adx, ady, signdx, signdy, 1, 1, octant);
+
+       if (adx > ady)
+       {
+           axis = X_AXIS;
+           e1 = ady << 1;
+           e2 = e1 - (adx << 1);
+           e = e1 - adx;
+           unclippedlen = adx;
+       }
+       else
+       {
+           axis = Y_AXIS;
+           e1 = adx << 1;
+           e2 = e1 - (ady << 1);
+           e = e1 - ady;
+           unclippedlen = ady;
+           SetYMajorOctant(octant);
+       }
+
+       FIXUP_ERROR(e, octant, bias);
+
+       /* we have bresenham parameters and two points.
+          all we have to do now is clip and draw.
+       */
+
+       while(nbox--)
+       {
+           oc1 = 0;
+           oc2 = 0;
+           OUTCODES(oc1, x1, y1, pbox);
+           OUTCODES(oc2, x2, y2, pbox);
+           if ((oc1 | oc2) == 0)
+           {
+#ifdef POLYSEGMENT
+               if (pGC->capStyle != CapNotLast)
+                   unclippedlen++;
+               dashIndexTmp = dashIndex;
+               dashOffsetTmp = dashOffset;
+               cfbBresD (rrops,
+                     &dashIndexTmp, pDash, numInDashList,
+                     &dashOffsetTmp, isDoubleDash,
+                     addrl, nlwidth,
+                     signdx, signdy, axis, x1, y1,
+                     e, e1, e2, unclippedlen);
+               break;
+#else
+               cfbBresD (rrops,
+                     &dashIndex, pDash, numInDashList,
+                     &dashOffset, isDoubleDash,
+                     addrl, nlwidth,
+                     signdx, signdy, axis, x1, y1,
+                     e, e1, e2, unclippedlen);
+               goto dontStep;
+#endif
+           }
+           else if (oc1 & oc2)
+           {
+               pbox++;
+           }
+           else /* have to clip */
+           {
+               int new_x1 = x1, new_y1 = y1, new_x2 = x2, new_y2 = y2;
+               int clip1 = 0, clip2 = 0;
+               int clipdx, clipdy;
+               int err;
+               int dashIndexTmp, dashOffsetTmp;
+               
+               if (miZeroClipLine(pbox->x1, pbox->y1, pbox->x2-1,
+                                  pbox->y2-1,
+                                  &new_x1, &new_y1, &new_x2, &new_y2,
+                                  adx, ady, &clip1, &clip2,
+                                  octant, bias, oc1, oc2) == -1)
+               {
+                   pbox++;
+                   continue;
+               }
+
+               dashIndexTmp = dashIndex;
+               dashOffsetTmp = dashOffset;
+
+               if (clip1)
+               {
+                   int dlen;
+    
+                   if (axis == X_AXIS)
+                       dlen = abs(new_x1 - x1);
+                   else
+                       dlen = abs(new_y1 - y1);
+                   miStepDash (dlen, &dashIndexTmp, pDash,
+                               numInDashList, &dashOffsetTmp);
+               }
+               
+               if (axis == X_AXIS)
+                   len = abs(new_x2 - new_x1);
+               else
+                   len = abs(new_y2 - new_y1);
+#ifdef POLYSEGMENT
+               if (clip2 != 0 || pGC->capStyle != CapNotLast)
+                   len++;
+#else
+               len += (clip2 != 0);
+#endif
+               if (len)
+               {
+                   /* unwind bresenham error term to first point */
+                   if (clip1)
+                   {
+                       clipdx = abs(new_x1 - x1);
+                       clipdy = abs(new_y1 - y1);
+                       if (axis == X_AXIS)
+                           err = e+((clipdy*e2) + ((clipdx-clipdy)*e1));
+                       else
+                           err = e+((clipdx*e2) + ((clipdy-clipdx)*e1));
+                   }
+                   else
+                       err = e;
+                   cfbBresD (rrops,
+                             &dashIndexTmp, pDash, numInDashList,
+                             &dashOffsetTmp, isDoubleDash,
+                             addrl, nlwidth,
+                             signdx, signdy, axis, new_x1, new_y1,
+                             err, e1, e2, len);
+               }
+               pbox++;
+           }
+       } /* while (nbox--) */
+#ifndef POLYSEGMENT
+       /*
+        * walk the dash list around to the next line
+        */
+       miStepDash (unclippedlen, &dashIndex, pDash,
+                   numInDashList, &dashOffset);
+dontStep:      ;
+#endif
+    } /* while (nline--) */
+
+#ifndef POLYSEGMENT
+    /* paint the last point if the end style isn't CapNotLast.
+       (Assume that a projecting, butt, or round cap that is one
+        pixel wide is the same as the single pixel of the endpoint.)
+    */
+
+    if ((pGC->capStyle != CapNotLast) &&
+        ((dashIndex & 1) == 0 || isDoubleDash) &&
+       ((ppt->x + xorg != pptInit->x + pDrawable->x) ||
+        (ppt->y + yorg != pptInit->y + pDrawable->y) ||
+        (ppt == pptInit + 1)))
+    {
+       nbox = nboxInit;
+       pbox = pboxInit;
+       while (nbox--)
+       {
+           if ((x2 >= pbox->x1) &&
+               (y2 >= pbox->y1) &&
+               (x2 <  pbox->x2) &&
+               (y2 <  pbox->y2))
+           {
+               unsigned long   mask;
+               int             pix;
+
+               pix = 0;
+               if (dashIndex & 1)
+                   pix = 1;
+#if PSZ == 24
+               mask = cfbmask[(x2 & 3)<<1];
+               addrl += (y2 * nlwidth) + ((x2 *3)>> 2);
+#else
+               mask = cfbmask[x2 & PIM];
+               addrl += (y2 * nlwidth) + (x2 >> PWSH);
+#endif
+               *addrl = DoMaskRRop (*addrl, rrops[pix].and, rrops[pix].xor, mask);
+               break;
+           }
+           else
+               pbox++;
+       }
+    }
+#endif
+}
diff --git a/Xserver/programs/Xserver/cfb/cfbmap.h b/Xserver/programs/Xserver/cfb/cfbmap.h
new file mode 100644 (file)
index 0000000..4a359d1
--- /dev/null
@@ -0,0 +1,197 @@
+/*
+ * $XConsortium: cfbmap.h,v 1.11 95/06/08 23:20:39 gildea Exp $
+ * $XFree86: xc/programs/Xserver/cfb/cfbmap.h,v 3.3 1996/06/29 09:05:40 dawes Exp $
+ *
+Copyright (c) 1991  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+ *
+ * Author:  Keith Packard, MIT X Consortium
+ */
+
+/*
+ * Map names around so that multiple depths can be supported simultaneously
+ */
+
+/* a losing vendor cpp dumps core if we define NAME in terms of CATNAME */
+
+#if PSZ != 8
+#if PSZ == 32
+#if (defined(__STDC__) && !defined(UNIXCPP)) || defined(ANSICPP)
+#define NAME(subname) cfb32##subname
+#else
+#define NAME(subname) cfb32/**/subname
+#endif
+#endif
+
+#if PSZ == 24
+#if (defined(__STDC__) && !defined(UNIXCPP)) || defined(ANSICPP)
+#define NAME(subname) cfb24##subname
+#else
+#define NAME(subname) cfb24/**/subname
+#endif
+#endif
+
+#if PSZ == 16
+#if (defined(__STDC__) && !defined(UNIXCPP)) || defined(ANSICPP)
+#define NAME(subname) cfb16##subname
+#else
+#define NAME(subname) cfb16/**/subname
+#endif
+#endif
+
+#if PSZ == 4
+#if (defined(__STDC__) && !defined(UNIXCPP)) || defined(ANSICPP)
+#define NAME(subname) cfb4##subname
+#else
+#define NAME(subname) cfb4/**/subname
+#endif
+#endif
+
+#ifndef NAME
+cfb can not hack PSZ yet
+#endif
+
+#if (defined(__STDC__) && !defined(UNIXCPP)) || defined(ANSICPP)
+#define CATNAME(prefix,subname) prefix##subname
+#else
+#define CATNAME(prefix,subname) prefix/**/subname
+#endif
+
+#define cfbScreenPrivateIndex NAME(ScreenPrivateIndex)
+#define QuartetBitsTable NAME(QuartetBitsTable)
+#define QuartetPixelMaskTable NAME(QuartetPixelMaskTable)
+#define cfbAllocatePrivates NAME(AllocatePrivates)
+#define cfbBSFuncRec NAME(BSFuncRec)
+#define cfbBitBlt NAME(BitBlt)
+#define cfbBresD NAME(BresD)
+#define cfbBresS NAME(BresS)
+#define cfbChangeWindowAttributes NAME(ChangeWindowAttributes)
+#define cfbCloseScreen NAME(CloseScreen)
+#define cfbCopyArea NAME(CopyArea)
+#define cfbCopyImagePlane NAME(CopyImagePlane)
+#define cfbCopyPixmap NAME(CopyPixmap)
+#define cfbCopyPlane NAME(CopyPlane)
+#define cfbCopyRotatePixmap NAME(CopyRotatePixmap)
+#define cfbCopyWindow NAME(CopyWindow)
+#define cfbCreateGC NAME(CreateGC)
+#define cfbCreatePixmap NAME(CreatePixmap)
+#define cfbCreateWindow NAME(CreateWindow)
+#define cfbCreateScreenResources NAME(CreateScreenResources)
+#define cfbDestroyPixmap NAME(DestroyPixmap)
+#define cfbDestroyWindow NAME(DestroyWindow)
+#define cfbDoBitblt NAME(DoBitblt)
+#define cfbDoBitbltCopy NAME(DoBitbltCopy)
+#define cfbDoBitbltGeneral NAME(DoBitbltGeneral)
+#define cfbDoBitbltOr NAME(DoBitbltOr)
+#define cfbDoBitbltXor NAME(DoBitbltXor)
+#define cfbFillBoxSolid NAME(FillBoxSolid)
+#define cfbFillBoxTile32 NAME(FillBoxTile32)
+#define cfbFillBoxTile32sCopy NAME(FillBoxTile32sCopy)
+#define cfbFillBoxTile32sGeneral NAME(FillBoxTile32sGeneral)
+#define cfbFillBoxTileOdd NAME(FillBoxTileOdd)
+#define cfbFillBoxTileOddCopy NAME(FillBoxTileOddCopy)
+#define cfbFillBoxTileOddGeneral NAME(FillBoxTileOddGeneral)
+#define cfbFillPoly1RectCopy NAME(FillPoly1RectCopy)
+#define cfbFillPoly1RectGeneral NAME(FillPoly1RectGeneral)
+#define cfbFillRectSolidCopy NAME(FillRectSolidCopy)
+#define cfbFillRectSolidGeneral NAME(FillRectSolidGeneral)
+#define cfbFillRectSolidXor NAME(FillRectSolidXor)
+#define cfbFillRectTile32Copy NAME(FillRectTile32Copy)
+#define cfbFillRectTile32General NAME(FillRectTile32General)
+#define cfbFillRectTileOdd NAME(FillRectTileOdd)
+#define cfbFillSpanTile32sCopy NAME(FillSpanTile32sCopy)
+#define cfbFillSpanTile32sGeneral NAME(FillSpanTile32sGeneral)
+#define cfbFillSpanTileOddCopy NAME(FillSpanTileOddCopy)
+#define cfbFillSpanTileOddGeneral NAME(FillSpanTileOddGeneral)
+#define cfbFinishScreenInit NAME(FinishScreenInit)
+#define cfbGCFuncs NAME(GCFuncs)
+#define cfbGetImage NAME(GetImage)
+#define cfbGetSpans NAME(GetSpans)
+#define cfbHorzS NAME(HorzS)
+#define cfbImageGlyphBlt8 NAME(ImageGlyphBlt8)
+#define cfbLineSD NAME(LineSD)
+#define cfbLineSS NAME(LineSS)
+#define cfbMapWindow NAME(MapWindow)
+#define cfbMatchCommon NAME(MatchCommon)
+#define cfbNonTEOps NAME(NonTEOps)
+#define cfbNonTEOps1Rect NAME(NonTEOps1Rect)
+#define cfbPadPixmap NAME(PadPixmap)
+#define cfbPaintWindow NAME(PaintWindow)
+#define cfbPolyGlyphBlt8 NAME(PolyGlyphBlt8)
+#define cfbPolyGlyphRop8 NAME(PolyGlyphRop8)
+#define cfbPolyFillArcSolidCopy NAME(PolyFillArcSolidCopy)
+#define cfbPolyFillArcSolidGeneral NAME(PolyFillArcSolidGeneral)
+#define cfbPolyFillRect NAME(PolyFillRect)
+#define cfbPolyPoint NAME(PolyPoint)
+#define cfbPositionWindow NAME(PositionWindow)
+#define cfbPutImage NAME(PutImage)
+#define cfbReduceRasterOp NAME(ReduceRasterOp)
+#define cfbRestoreAreas NAME(RestoreAreas)
+#define cfbSaveAreas NAME(SaveAreas)
+#define cfbScreenInit NAME(ScreenInit)
+#define cfbSegmentSD NAME(SegmentSD)
+#define cfbSegmentSS NAME(SegmentSS)
+#define cfbSetScanline NAME(SetScanline)
+#define cfbSetSpans NAME(SetSpans)
+#define cfbSetupScreen NAME(SetupScreen)
+#define cfbSolidSpansCopy NAME(SolidSpansCopy)
+#define cfbSolidSpansGeneral NAME(SolidSpansGeneral)
+#define cfbSolidSpansXor NAME(SolidSpansXor)
+#define cfbStippleStack NAME(StippleStack)
+#define cfbStippleStackTE NAME(StippleStackTE)
+#define cfbTEGlyphBlt NAME(TEGlyphBlt)
+#define cfbTEOps NAME(TEOps)
+#define cfbTEOps1Rect NAME(TEOps1Rect)
+#define cfbTile32FSCopy NAME(Tile32FSCopy)
+#define cfbTile32FSGeneral NAME(Tile32FSGeneral)
+#define cfbUnmapWindow NAME(UnmapWindow)
+#define cfbUnnaturalStippleFS NAME(UnnaturalStippleFS)
+#define cfbUnnaturalTileFS NAME(UnnaturalTileFS)
+#define cfbValidateGC NAME(ValidateGC)
+#define cfbVertS NAME(VertS)
+#define cfbXRotatePixmap NAME(XRotatePixmap)
+#define cfbYRotatePixmap NAME(YRotatePixmap)
+#define cfbendpartial NAME(endpartial)
+#define cfbendtab NAME(endtab)
+#define cfbmask NAME(mask)
+#define cfbrmask NAME(rmask)
+#define cfbstartpartial NAME(startpartial)
+#define cfbstarttab NAME(starttab)
+#define cfb8LineSS1Rect NAME(LineSS1Rect)
+#define cfb8SegmentSS1Rect NAME(SegmentSS1Rect)
+#define cfb8ClippedLineCopy NAME(ClippedLineCopy)
+#define cfb8ClippedLineXor NAME(ClippedLineXor)
+#define cfb8ClippedLineGeneral  NAME(ClippedLineGeneral )
+#define cfb8SegmentSS1RectCopy NAME(SegmentSS1RectCopy)
+#define cfb8SegmentSS1RectXor NAME(SegmentSS1RectXor)
+#define cfb8SegmentSS1RectGeneral  NAME(SegmentSS1RectGeneral )
+#define cfb8SegmentSS1RectShiftCopy NAME(SegmentSS1RectShiftCopy)
+#define cfb8LineSS1RectCopy NAME(LineSS1RectCopy)
+#define cfb8LineSS1RectXor NAME(LineSS1RectXor)
+#define cfb8LineSS1RectGeneral  NAME(LineSS1RectGeneral )
+#define cfb8LineSS1RectPreviousCopy NAME(LineSS1RectPreviousCopy)
+#define cfbZeroPolyArcSS8Copy NAME(ZeroPolyArcSSCopy)
+#define cfbZeroPolyArcSS8Xor NAME(ZeroPolyArcSSXor)
+#define cfbZeroPolyArcSS8General NAME(ZeroPolyArcSSGeneral)
+
+#endif /* PSZ != 8 */
diff --git a/Xserver/programs/Xserver/cfb/cfbmskbits.c b/Xserver/programs/Xserver/cfb/cfbmskbits.c
new file mode 100644 (file)
index 0000000..e98cc82
--- /dev/null
@@ -0,0 +1,1398 @@
+/************************************************************
+Copyright 1987 by Sun Microsystems, Inc. Mountain View, CA.
+
+                    All Rights Reserved
+
+Permission  to  use,  copy,  modify,  and  distribute   this
+software  and  its documentation for any purpose and without
+fee is hereby granted, provided that the above copyright no-
+tice  appear  in all copies and that both that copyright no-
+tice and this permission notice appear in  supporting  docu-
+mentation,  and  that the names of Sun or X Consortium
+not be used in advertising or publicity pertaining to 
+distribution  of  the software  without specific prior 
+written permission. Sun and X Consortium make no 
+representations about the suitability of this software for 
+any purpose. It is provided "as is" without any express or 
+implied warranty.
+
+SUN DISCLAIMS ALL WARRANTIES WITH REGARD TO  THIS  SOFTWARE,
+INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FIT-
+NESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SUN BE  LI-
+ABLE  FOR  ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
+ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,  DATA  OR
+PROFITS,  WHETHER  IN  AN  ACTION OF CONTRACT, NEGLIGENCE OR
+OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION  WITH
+THE USE OR PERFORMANCE OF THIS SOFTWARE.
+
+********************************************************/
+
+/* $XConsortium: cfbmskbits.c,v 4.13 94/07/28 12:30:41 dpw Exp $ */
+/* $XFree86: xc/programs/Xserver/cfb/cfbmskbits.c,v 3.0 1996/06/29 09:05:41 dawes Exp $ */
+
+/*
+ * ==========================================================================
+ * Converted to Color Frame Buffer by smarks@sun, April-May 1987.  The "bit 
+ * numbering" in the doc below really means "byte numbering" now.
+ * ==========================================================================
+ */
+
+/*
+   these tables are used by several macros in the cfb code.
+
+   the vax numbers everything left to right, so bit indices on the
+screen match bit indices in longwords.  the pc-rt and Sun number
+bits on the screen the way they would be written on paper,
+(i.e. msb to the left), and so a bit index n on the screen is
+bit index 32-n in a longword
+
+   see also cfbmskbits.h
+*/
+#include       <X.h>
+#include       <Xmd.h>
+#include       <servermd.h>
+#include       "cfb.h"
+#include       "cfbmskbits.h"
+
+#define _cfbBits(a) (PixelGroup)(a)
+
+#if    (BITMAP_BIT_ORDER == MSBFirst)
+#define cfbBits(v)     _cfbBits(v)
+#else /* BITMAP_BIT_ORDER == LSBFirst */
+#define cfbFlip2(a)    ((((a) & 0x1) << 1) | (((a) & 0x2) >> 1))
+#define cfbFlip4(a)    ((cfbFlip2(a) << 2) | cfbFlip2(a >> 2))
+#define cfbFlip8(a)    ((cfbFlip4(a) << 4) | cfbFlip4(a >> 4))
+#define cfbFlip16(a)   ((cfbFlip8(a) << 8) | cfbFlip8(a >> 8))
+#define cfbFlip32(a)   ((cfbFlip16(a) << 16) | cfbFlip16(a >> 16))
+#if PGSZ == 32
+#define cfbBits(a)     cfbFlip32(_cfbBits(a))
+#else /* PGSZ == 64 */
+#define cfbFlip64(a)   ((cfbFlip32(a) << 32) | cfbFlip32(a >> 32))
+#define cfbBits(a)     cfbFlip64(_cfbBits(a))
+#endif /* PGSZ */
+#endif /* BITMAP_BIT_ORDER */
+
+/* NOTE:
+the first element in starttab could be 0xffffffff.  making it 0
+lets us deal with a full first word in the middle loop, rather
+than having to do the multiple reads and masks that we'd
+have to do if we thought it was partial.
+*/
+#if PSZ == 4
+#if PGSZ == 32
+PixelGroup cfbstarttab[] =
+    {
+       cfbBits(0x00000000),
+       cfbBits(0x0FFFFFFF),
+       cfbBits(0x00FFFFFF),
+       cfbBits(0x000FFFFF),
+       cfbBits(0x0000FFFF),
+       cfbBits(0x00000FFF),
+       cfbBits(0x000000FF),
+       cfbBits(0x0000000F)
+    };
+PixelGroup cfbendtab[] =
+    {
+       cfbBits(0x00000000),
+       cfbBits(0xF0000000),
+       cfbBits(0xFF000000),
+       cfbBits(0xFFF00000),
+       cfbBits(0xFFFF0000),
+       cfbBits(0xFFFFF000),
+       cfbBits(0xFFFFFF00),
+       cfbBits(0xFFFFFFF0)
+    };
+#else /* PGSZ == 64 */
+PixelGroup cfbstarttab[] =
+    {
+       cfbBits(0x0000000000000000),
+       cfbBits(0x0FFFFFFFFFFFFFFF),
+       cfbBits(0x00FFFFFFFFFFFFFF),
+       cfbBits(0x000FFFFFFFFFFFFF),
+       cfbBits(0x0000FFFFFFFFFFFF),
+       cfbBits(0x00000FFFFFFFFFFF),
+       cfbBits(0x000000FFFFFFFFFF),
+       cfbBits(0x0000000FFFFFFFFF),
+       cfbBits(0x00000000FFFFFFFF),
+       cfbBits(0x000000000FFFFFFF),
+       cfbBits(0x0000000000FFFFFF),
+       cfbBits(0x00000000000FFFFF),
+       cfbBits(0x000000000000FFFF),
+       cfbBits(0x0000000000000FFF),
+       cfbBits(0x00000000000000FF),
+       cfbBits(0x000000000000000F),
+    };
+PixelGroup cfbendtab[] =
+    {
+       cfbBits(0x0000000000000000),
+       cfbBits(0xF000000000000000),
+       cfbBits(0xFF00000000000000),
+       cfbBits(0xFFF0000000000000),
+       cfbBits(0xFFFF000000000000),
+       cfbBits(0xFFFFF00000000000),
+       cfbBits(0xFFFFFF0000000000),
+       cfbBits(0xFFFFFFF000000000),
+       cfbBits(0xFFFFFFFF00000000),
+       cfbBits(0xFFFFFFFFF0000000),
+       cfbBits(0xFFFFFFFFFF000000),
+       cfbBits(0xFFFFFFFFFFF00000),
+       cfbBits(0xFFFFFFFFFFFF0000),
+       cfbBits(0xFFFFFFFFFFFFF000),
+       cfbBits(0xFFFFFFFFFFFFFF00),
+       cfbBits(0xFFFFFFFFFFFFFFF0),
+    };
+#endif /* PGSZ */
+#endif /* PSZ == 4 */
+
+#if PSZ == 8
+#if PGSZ == 32
+PixelGroup cfbstarttab[] =
+    {
+       cfbBits(0x00000000),
+       cfbBits(0x00FFFFFF),
+       cfbBits(0x0000FFFF),
+       cfbBits(0x000000FF)
+    };
+PixelGroup cfbendtab[] =
+    {
+       cfbBits(0x00000000),
+       cfbBits(0xFF000000),
+       cfbBits(0xFFFF0000),
+       cfbBits(0xFFFFFF00)
+    };
+#else /* PGSZ == 64 */
+PixelGroup cfbstarttab[] =
+    {
+       cfbBits(0x0000000000000000),
+       cfbBits(0x00FFFFFFFFFFFFFF),
+       cfbBits(0x0000FFFFFFFFFFFF),
+       cfbBits(0x000000FFFFFFFFFF),
+       cfbBits(0x00000000FFFFFFFF),
+       cfbBits(0x0000000000FFFFFF),
+       cfbBits(0x000000000000FFFF),
+       cfbBits(0x00000000000000FF)
+    };
+PixelGroup cfbendtab[] =
+    {
+       cfbBits(0x0000000000000000),
+       cfbBits(0xFF00000000000000),
+       cfbBits(0xFFFF000000000000),
+       cfbBits(0xFFFFFF0000000000),
+       cfbBits(0xFFFFFFFF00000000),
+       cfbBits(0xFFFFFFFFFF000000),
+       cfbBits(0xFFFFFFFFFFFF0000),
+       cfbBits(0xFFFFFFFFFFFFFF00)
+    };
+#endif /* PGSZ */
+#endif /* PSZ == 8 */
+
+#if PSZ == 16
+#if PGSZ == 32
+PixelGroup cfbstarttab[] =
+    {
+       cfbBits(0x00000000),
+       cfbBits(0x0000FFFF),
+    };
+PixelGroup cfbendtab[] =
+    {
+       cfbBits(0x00000000),
+       cfbBits(0xFFFF0000),
+    };
+#else /* PGSZ == 64 */
+PixelGroup cfbstarttab[] =
+    {
+       cfbBits(0x0000000000000000),
+       cfbBits(0x0000FFFFFFFFFFFF),
+       cfbBits(0x00000000FFFFFFFF),
+       cfbBits(0x000000000000FFFF),
+    };
+PixelGroup cfbendtab[] =
+    {
+       cfbBits(0x0000000000000000),
+       cfbBits(0xFFFF000000000000),
+       cfbBits(0xFFFFFFFF00000000),
+       cfbBits(0xFFFFFFFFFFFF0000),
+    };
+#endif /* PGSZ */
+#endif
+
+#if PSZ == 24
+#if PGSZ == 32
+PixelGroup cfbstarttab[] =
+    {
+       cfbBits(0x00000000),
+       cfbBits(0x000000FF),
+       cfbBits(0x0000FFFF),
+       cfbBits(0x00FFFFFF),
+    };
+PixelGroup cfbendtab[] = 
+    {
+       cfbBits(0x00000000),
+       cfbBits(0xFFFFFF00),
+       cfbBits(0xFFFF0000),
+       cfbBits(0xFF000000),
+    };
+#else /* PGSZ == 64 */
+PixelGroup cfbstarttab[] =
+    {
+       cfbBits(0x0000000000000000),
+       cfbBits(0x000000FFFFFFFFFF),
+       cfbBits(0x000000000000FFFF),
+    };
+PixelGroup cfbendtab[] = 
+    {
+       cfbBits(0x0000000000000000),
+       cfbBits(0xFFFFFFFFFF000000),
+       cfbBits(0xFFFF000000000000),
+    };
+#endif /* PGSZ */
+#endif /* PSZ == 24 */
+
+#if PSZ == 32
+#if PGSZ == 32
+PixelGroup cfbstarttab[] =
+    {
+       cfbBits(0x00000000),
+    };
+PixelGroup cfbendtab[] = 
+    {
+       cfbBits(0x00000000),
+    };
+#else /* PGSZ == 64 */
+PixelGroup cfbstarttab[] =
+    {
+       cfbBits(0x0000000000000000),
+       cfbBits(0x00000000FFFFFFFF),
+    };
+PixelGroup cfbendtab[] = 
+    {
+       cfbBits(0x0000000000000000),
+       cfbBits(0xFFFFFFFF00000000),
+    };
+#endif /* PGSZ */
+#endif /* PSZ == 32 */
+
+/* a hack, for now, since the entries for 0 need to be all
+   1 bits, not all zeros.
+   this means the code DOES NOT WORK for segments of length
+   0 (which is only a problem in the horizontal line code.)
+*/
+#if PSZ == 4
+#if PGSZ == 32
+PixelGroup cfbstartpartial[] =
+    {
+       cfbBits(0xFFFFFFFF),
+       cfbBits(0x0FFFFFFF),
+       cfbBits(0x00FFFFFF),
+       cfbBits(0x000FFFFF),
+       cfbBits(0x0000FFFF),
+       cfbBits(0x00000FFF),
+       cfbBits(0x000000FF),
+       cfbBits(0x0000000F)
+    };
+
+PixelGroup cfbendpartial[] =
+    {
+       cfbBits(0xFFFFFFFF),
+       cfbBits(0xF0000000),
+       cfbBits(0xFF000000),
+       cfbBits(0xFFF00000),
+       cfbBits(0xFFFF0000),
+       cfbBits(0xFFFFF000),
+       cfbBits(0xFFFFFF00),
+       cfbBits(0xFFFFFFF0)
+    };
+#else /* PGSZ == 64 */
+PixelGroup cfbstartpartial[] =
+    {
+       cfbBits(0xFFFFFFFFFFFFFFFF),
+       cfbBits(0x0FFFFFFFFFFFFFFF),
+       cfbBits(0x00FFFFFFFFFFFFFF),
+       cfbBits(0x000FFFFFFFFFFFFF),
+       cfbBits(0x0000FFFFFFFFFFFF),
+       cfbBits(0x00000FFFFFFFFFFF),
+       cfbBits(0x000000FFFFFFFFFF),
+       cfbBits(0x0000000FFFFFFFFF),
+       cfbBits(0x00000000FFFFFFFF),
+       cfbBits(0x000000000FFFFFFF),
+       cfbBits(0x0000000000FFFFFF),
+       cfbBits(0x00000000000FFFFF),
+       cfbBits(0x000000000000FFFF),
+       cfbBits(0x0000000000000FFF),
+       cfbBits(0x00000000000000FF),
+       cfbBits(0x000000000000000F),
+    };
+
+PixelGroup cfbendpartial[] =
+    {
+       cfbBits(0xFFFFFFFFFFFFFFFF),
+       cfbBits(0xF000000000000000),
+       cfbBits(0xFF00000000000000),
+       cfbBits(0xFFF0000000000000),
+       cfbBits(0xFFFF000000000000),
+       cfbBits(0xFFFFF00000000000),
+       cfbBits(0xFFFFFF0000000000),
+       cfbBits(0xFFFFFFF000000000),
+       cfbBits(0xFFFFFFFF00000000),
+       cfbBits(0xFFFFFFFFF0000000),
+       cfbBits(0xFFFFFFFFFF000000),
+       cfbBits(0xFFFFFFFFFFF00000),
+       cfbBits(0xFFFFFFFFFFFF0000),
+       cfbBits(0xFFFFFFFFFFFFF000),
+       cfbBits(0xFFFFFFFFFFFFFF00),
+       cfbBits(0xFFFFFFFFFFFFFFF0),
+    };
+#endif /* PGSZ */
+#endif /* PSZ == 4 */
+
+#if PSZ == 8
+#if PGSZ == 32
+PixelGroup cfbstartpartial[] =
+    {
+       cfbBits(0xFFFFFFFF),
+       cfbBits(0x00FFFFFF),
+       cfbBits(0x0000FFFF),
+       cfbBits(0x000000FF)
+    };
+
+PixelGroup cfbendpartial[] =
+    {
+       cfbBits(0xFFFFFFFF),
+       cfbBits(0xFF000000),
+       cfbBits(0xFFFF0000),
+       cfbBits(0xFFFFFF00)
+    };
+#else /* PGSZ == 64 */
+PixelGroup cfbstartpartial[] =
+    {
+       cfbBits(0xFFFFFFFFFFFFFFFF),
+       cfbBits(0x00FFFFFFFFFFFFFF),
+       cfbBits(0x0000FFFFFFFFFFFF),
+       cfbBits(0x000000FFFFFFFFFF),
+       cfbBits(0x00000000FFFFFFFF),
+       cfbBits(0x0000000000FFFFFF),
+       cfbBits(0x000000000000FFFF),
+       cfbBits(0x00000000000000FF),
+    };
+
+PixelGroup cfbendpartial[] =
+    {
+       cfbBits(0xFFFFFFFFFFFFFFFF),
+       cfbBits(0xFF00000000000000),
+       cfbBits(0xFFFF000000000000),
+       cfbBits(0xFFFFFF0000000000),
+       cfbBits(0xFFFFFFFF00000000),
+       cfbBits(0xFFFFFFFFFF000000),
+       cfbBits(0xFFFFFFFFFFFF0000),
+       cfbBits(0xFFFFFFFFFFFFFF00),
+    };
+#endif /* PGSZ */
+#endif /* PSZ == 8 */
+
+#if PSZ == 16
+#if PGSZ == 32
+PixelGroup cfbstartpartial[] =
+    {
+       cfbBits(0xFFFFFFFF),
+       cfbBits(0x0000FFFF),
+    };
+
+PixelGroup cfbendpartial[] =
+    {
+       cfbBits(0xFFFFFFFF),
+       cfbBits(0xFFFF0000),
+    };
+#else /* PGSZ == 64 */
+PixelGroup cfbstartpartial[] =
+    {
+       cfbBits(0xFFFFFFFFFFFFFFFF),
+       cfbBits(0x0000FFFFFFFFFFFF),
+       cfbBits(0x00000000FFFFFFFF),
+       cfbBits(0x000000000000FFFF),
+    };
+
+PixelGroup cfbendpartial[] =
+    {
+       cfbBits(0xFFFFFFFFFFFFFFFF),
+       cfbBits(0xFFFF000000000000),
+       cfbBits(0xFFFFFFFF00000000),
+       cfbBits(0xFFFFFFFFFFFF0000),
+    };
+#endif /* PGSZ */
+#endif /* PSZ == 16 */
+
+#if PSZ == 24
+#if PGSZ == 32
+PixelGroup cfbstartpartial[] =
+    {
+       cfbBits(0xFFFFFFFF),
+       cfbBits(0x000000FF),
+       cfbBits(0x0000FFFF),
+       cfbBits(0x00FFFFFF),
+    };
+
+PixelGroup cfbendpartial[] =
+    {
+       cfbBits(0xFFFFFFFF),
+       cfbBits(0xFFFFFF00),
+       cfbBits(0xFFFF0000),
+       cfbBits(0xFF000000),
+    };
+#else /* PGSZ == 64 */
+PixelGroup cfbstartpartial[] =
+    {
+       cfbBits(0xFFFFFFFFFFFFFFFF),
+       cfbBits(0x0000FFFFFFFFFFFF),
+       cfbBits(0x000000FFFFFFFFFF),
+       cfbBits(0x00000000FFFFFFFF),
+       cfbBits(0x0000000000FFFFFF),
+       cfbBits(0x000000000000FFFF),
+       cfbBits(0x00000000000000FF),
+    };
+
+PixelGroup cfbendpartial[] =
+    {
+       cfbBits(0xFFFFFFFFFFFFFFFF),
+       cfbBits(0xFFFFFFFFFFFF0000),
+       cfbBits(0xFFFFFFFFFF000000),
+       cfbBits(0xFFFFFFFF00000000),
+       cfbBits(0xFFFFFF0000000000),
+       cfbBits(0xFFFF000000000000),
+       cfbBits(0xFF00000000000000),
+    };
+#endif /* PGSZ */
+#endif /* PSZ == 24 */
+
+#if PSZ == 32
+#if PGSZ == 32
+PixelGroup cfbstartpartial[] =
+    {
+       cfbBits(0xFFFFFFFF),
+    };
+
+PixelGroup cfbendpartial[] =
+    {
+       cfbBits(0xFFFFFFFF),
+    };
+#else /* PGSZ == 64 */
+PixelGroup cfbstartpartial[] =
+    {
+       cfbBits(0xFFFFFFFFFFFFFFFF),
+       cfbBits(0x00000000FFFFFFFF),
+    };
+
+PixelGroup cfbendpartial[] =
+    {
+       cfbBits(0xFFFFFFFFFFFFFFFF),
+       cfbBits(0xFFFFFFFF00000000),
+    };
+#endif /* PGSZ */
+#endif /* PSZ == 32 */
+
+/* used for masking bits in bresenham lines
+   mask[n] is used to mask out all but bit n in a longword (n is a
+screen position).
+   rmask[n] is used to mask out the single bit at position n (n
+is a screen posiotion.)
+*/
+
+#if PSZ == 4
+#if PGSZ == 32
+PixelGroup cfbmask[] =
+    {
+       cfbBits(0xF0000000),
+       cfbBits(0x0F000000),
+       cfbBits(0x00F00000),
+       cfbBits(0x000F0000),
+       cfbBits(0x0000F000),
+       cfbBits(0x00000F00),
+       cfbBits(0x000000F0),
+       cfbBits(0x0000000F)
+    }; 
+PixelGroup cfbrmask[] = 
+    {
+       cfbBits(0x0FFFFFFF),
+       cfbBits(0xF0FFFFFF),
+       cfbBits(0xFF0FFFFF),
+       cfbBits(0xFFF0FFFF),
+       cfbBits(0xFFFF0FFF),
+       cfbBits(0xFFFFF0FF),
+       cfbBits(0xFFFFFF0F),
+       cfbBits(0xFFFFFFF0)
+    };
+#else /* PGSZ == 64 */
+PixelGroup cfbmask[] =
+    {
+       cfbBits(0xF000000000000000),
+       cfbBits(0x0F00000000000000),
+       cfbBits(0x00F0000000000000),
+       cfbBits(0x000F000000000000),
+       cfbBits(0x0000F00000000000),
+       cfbBits(0x00000F0000000000),
+       cfbBits(0x000000F000000000),
+       cfbBits(0x0000000F00000000),
+       cfbBits(0x00000000F0000000),
+       cfbBits(0x000000000F000000),
+       cfbBits(0x0000000000F00000),
+       cfbBits(0x00000000000F0000),
+       cfbBits(0x000000000000F000),
+       cfbBits(0x0000000000000F00),
+       cfbBits(0x00000000000000F0),
+       cfbBits(0x000000000000000F),
+    }; 
+PixelGroup cfbrmask[] = 
+    {
+       cfbBits(0x0FFFFFFFFFFFFFFF),
+       cfbBits(0xF0FFFFFFFFFFFFFF),
+       cfbBits(0xFF0FFFFFFFFFFFFF),
+       cfbBits(0xFFF0FFFFFFFFFFFF),
+       cfbBits(0xFFFF0FFFFFFFFFFF),
+       cfbBits(0xFFFFF0FFFFFFFFFF),
+       cfbBits(0xFFFFFF0FFFFFFFFF),
+       cfbBits(0xFFFFFFF0FFFFFFFF),
+       cfbBits(0xFFFFFFFF0FFFFFFF),
+       cfbBits(0xFFFFFFFFF0FFFFFF),
+       cfbBits(0xFFFFFFFFFF0FFFFF),
+       cfbBits(0xFFFFFFFFFFF0FFFF),
+       cfbBits(0xFFFFFFFFFFFF0FFF),
+       cfbBits(0xFFFFFFFFFFFFF0FF),
+       cfbBits(0xFFFFFFFFFFFFFF0F),
+       cfbBits(0xFFFFFFFFFFFFFFF0),
+    };
+#endif /* PGSZ */
+#endif /* PSZ == 4 */
+
+#if PSZ == 8
+#if PGSZ == 32
+PixelGroup cfbmask[] =
+    {
+       cfbBits(0xFF000000),
+       cfbBits(0x00FF0000),
+       cfbBits(0x0000FF00),
+       cfbBits(0x000000FF)
+    }; 
+PixelGroup cfbrmask[] = 
+    {
+       cfbBits(0x00FFFFFF),
+       cfbBits(0xFF00FFFF),
+       cfbBits(0xFFFF00FF),
+       cfbBits(0xFFFFFF00)
+    };
+#else /* PGSZ == 64 */
+PixelGroup cfbmask[] =
+    {
+       cfbBits(0xFF00000000000000),
+       cfbBits(0x00FF000000000000),
+       cfbBits(0x0000FF0000000000),
+       cfbBits(0x000000FF00000000),
+       cfbBits(0x00000000FF000000),
+       cfbBits(0x0000000000FF0000),
+       cfbBits(0x000000000000FF00),
+       cfbBits(0x00000000000000FF),
+    }; 
+PixelGroup cfbrmask[] = 
+    {
+       cfbBits(0x00FFFFFFFFFFFFFF),
+       cfbBits(0xFF00FFFFFFFFFFFF),
+       cfbBits(0xFFFF00FFFFFFFFFF),
+       cfbBits(0xFFFFFF00FFFFFFFF),
+       cfbBits(0xFFFFFFFF00FFFFFF),
+       cfbBits(0xFFFFFFFFFF00FFFF),
+       cfbBits(0xFFFFFFFFFFFF00FF),
+       cfbBits(0xFFFFFFFFFFFFFF00),
+    };
+#endif /* PGSZ */
+#endif /* PSZ == 8 */
+
+#if PSZ == 16
+#if PGSZ == 32
+PixelGroup cfbmask[] =
+    {
+       cfbBits(0xFFFF0000),
+       cfbBits(0x0000FFFF),
+    }; 
+PixelGroup cfbrmask[] = 
+    {
+       cfbBits(0x0000FFFF),
+       cfbBits(0xFFFF0000),
+    };
+#else /* PGSZ == 64 */
+PixelGroup cfbmask[] =
+    {
+       cfbBits(0xFFFF000000000000),
+       cfbBits(0x0000FFFF00000000),
+       cfbBits(0x00000000FFFF0000),
+       cfbBits(0x000000000000FFFF),
+    }; 
+PixelGroup cfbrmask[] = 
+    {
+       cfbBits(0x0000FFFFFFFFFFFF),
+       cfbBits(0xFFFF0000FFFFFFFF),
+       cfbBits(0xFFFFFFFF0000FFFF),
+       cfbBits(0xFFFFFFFFFFFF0000),
+    };
+#endif /* PGSZ */
+#endif /* PSZ == 16 */
+
+#if PSZ == 24
+#if PGSZ == 32
+PixelGroup cfbmask[] =
+    {
+       cfbBits(0xFFFFFF00),
+       cfbBits(0x00000000),
+       cfbBits(0x000000FF),
+       cfbBits(0xFFFF0000),
+       cfbBits(0x0000FFFF),
+       cfbBits(0xFF000000),
+       cfbBits(0x00FFFFFF),
+       cfbBits(0x00000000),
+    }; 
+PixelGroup cfbrmask[] = 
+    {
+       cfbBits(0x000000FF),
+       cfbBits(0xFFFFFFFF),
+       cfbBits(0xFFFFFF00),
+       cfbBits(0x0000FFFF),
+       cfbBits(0xFFFF0000),
+       cfbBits(0x00FFFFFF),
+       cfbBits(0xFF000000),
+       cfbBits(0xFFFFFFFF),
+    };
+#else /* PGSZ == 64 */
+PixelGroup cfbmask[] =
+    {
+       cfbBits(0xFFFFFF0000000000),
+       cfbBits(0x000000FFFFFF0000),
+       cfbBits(0x000000000000FFFF),
+    }; 
+PixelGroup cfbmask2[] =
+    {
+       cfbBits(0x0000000000000000),
+       cfbBits(0x0000000000000000),
+       cfbBits(0xFF00000000000000),
+    }; 
+PixelGroup cfbrmask[] = 
+    {
+       cfbBits(0x000000FFFFFFFFFF),
+       cfbBits(0xFFFFFF000000FFFF),
+       cfbBits(0xFFFFFFFFFFFF0000),
+    };
+PixelGroup cfbrmask2[] = 
+    {
+       cfbBits(0x0000000000000000),
+       cfbBits(0x0000000000000000),
+       cfbBits(0x00FFFFFFFFFFFFFF),
+    };
+#endif /* PGSZ */
+#endif /* PSZ == 24 */
+
+#if PSZ == 32
+#if PGSZ == 32
+PixelGroup cfbmask[] =
+    {
+       cfbBits(0xFFFFFFFF),
+    }; 
+PixelGroup cfbrmask[] = 
+    {
+       cfbBits(0xFFFFFFFF),
+    };
+#else /* PGSZ == 64 */
+PixelGroup cfbmask[] =
+    {
+       cfbBits(0xFFFFFFFF00000000),
+       cfbBits(0x00000000FFFFFFFF),
+    }; 
+PixelGroup cfbrmask[] = 
+    {
+       cfbBits(0x00000000FFFFFFFF),
+       cfbBits(0xFFFFFFFF00000000),
+    };
+#endif /* PGSZ */
+#endif /* PSZ == 32 */
+
+/*
+ * QuartetBitsTable contains PPW+1 masks whose binary values are masks in the
+ * low order quartet that contain the number of bits specified in the
+ * index.  This table is used by getstipplepixels.
+ */
+#if PSZ == 4
+PixelGroup QuartetBitsTable[] = {
+#if PGSZ == 32
+#if (BITMAP_BIT_ORDER == MSBFirst)
+    0x00000000,                         /* 0 - 00000000 */
+    0x00000080,                                /* 1 - 10000000 */
+    0x000000C0,                         /* 2 - 11000000 */
+    0x000000E0,                         /* 3 - 11100000 */
+    0x000000F0,                         /* 4 - 11110000 */
+    0x000000F8,                         /* 5 - 11111000 */
+    0x000000FC,                         /* 6 - 11111100 */
+    0x000000FE,                         /* 7 - 11111110 */
+    0x000000FF                          /* 8 - 11111111 */
+#else /* (BITMAP_BIT_ORDER == LSBFirst */
+    0x00000000,                         /* 0 - 00000000 */
+    0x00000001,                         /* 1 - 00000001 */
+    0x00000003,                         /* 2 - 00000011 */
+    0x00000007,                         /* 3 - 00000111 */
+    0x0000000F,                         /* 4 - 00001111 */
+    0x0000001F,                         /* 5 - 00011111 */
+    0x0000003F,                         /* 6 - 00111111 */
+    0x0000007F,                         /* 7 - 01111111 */
+    0x000000FF                          /* 8 - 11111111 */
+#endif /* (BITMAP_BIT_ORDER == MSBFirst) */
+#else /* PGSZ == 64 */
+#if (BITMAP_BIT_ORDER == MSBFirst)
+    0x00000000,                         /* 0 - 0000000000000000 */
+    0x00008000,                                /* 1 - 1000000000000000 */
+    0x0000C000,                         /* 2 - 1100000000000000 */
+    0x0000E000,                         /* 3 - 1110000000000000 */
+    0x0000F000,                         /* 4 - 1111000000000000 */
+    0x0000F800,                         /* 5 - 1111100000000000 */
+    0x0000FC00,                         /* 6 - 1111110000000000 */
+    0x0000FE00,                         /* 7 - 1111111000000000 */
+    0x0000FF00,                         /* 8 - 1111111100000000 */
+    0x0000FF80,                                /* 9 - 1111111110000000 */
+    0x0000FFC0,                         /* 10- 1111111111000000 */
+    0x0000FFE0,                         /* 11- 1111111111100000 */
+    0x0000FFF0,                         /* 12- 1111111111110000 */
+    0x0000FFF8,                         /* 13- 1111111111111000 */
+    0x0000FFFC,                         /* 14- 1111111111111100 */
+    0x0000FFFE,                         /* 15- 1111111111111110 */
+    0x0000FFFF,                         /* 16- 1111111111111111 */
+#else /* (BITMAP_BIT_ORDER == LSBFirst */
+    0x00000000,                         /* 0 - 0000000000000000 */
+    0x00000001,                         /* 1 - 0000000000000001 */
+    0x00000003,                         /* 2 - 0000000000000011 */
+    0x00000007,                         /* 3 - 0000000000000111 */
+    0x0000000F,                         /* 4 - 0000000000001111 */
+    0x0000001F,                         /* 5 - 0000000000011111 */
+    0x0000003F,                         /* 6 - 0000000000111111 */
+    0x0000007F,                         /* 7 - 0000000001111111 */
+    0x000000FF,                         /* 8 - 0000000011111111 */
+    0x000001FF,                         /* 9 - 0000000111111111 */
+    0x000003FF,                         /* 10- 0000001111111111 */
+    0x000007FF,                         /* 11- 0000011111111111 */
+    0x00000FFF,                         /* 12- 0000111111111111 */
+    0x00001FFF,                         /* 13- 0001111111111111 */
+    0x00003FFF,                         /* 14- 0011111111111111 */
+    0x00007FFF,                         /* 15- 0111111111111111 */
+    0x0000FFFF,                         /* 16- 1111111111111111 */
+#endif /* (BITMAP_BIT_ORDER == MSBFirst) */
+#endif /* PGSZ */
+};
+#endif /* PSZ == 4 */
+
+#if PSZ == 8
+PixelGroup QuartetBitsTable[] = {
+#if PGSZ == 32
+#if (BITMAP_BIT_ORDER == MSBFirst)
+    0x00000000,                         /* 0 - 0000 */
+    0x00000008,                         /* 1 - 1000 */
+    0x0000000C,                         /* 2 - 1100 */
+    0x0000000E,                         /* 3 - 1110 */
+    0x0000000F                          /* 4 - 1111 */
+#else /* (BITMAP_BIT_ORDER == LSBFirst */
+    0x00000000,                         /* 0 - 0000 */
+    0x00000001,                         /* 1 - 0001 */
+    0x00000003,                         /* 2 - 0011 */
+    0x00000007,                         /* 3 - 0111 */
+    0x0000000F                          /* 4 - 1111 */
+#endif /* (BITMAP_BIT_ORDER == MSBFirst) */
+#else /* PGSZ == 64 */
+#if (BITMAP_BIT_ORDER == MSBFirst)
+    0x00000000,                         /* 0 - 00000000 */
+    0x00000080,                         /* 1 - 10000000 */
+    0x000000C0,                         /* 2 - 11000000 */
+    0x000000E0,                         /* 3 - 11100000 */
+    0x000000F0,                         /* 4 - 11110000 */
+    0x000000F8,                         /* 5 - 11111000 */
+    0x000000FC,                         /* 6 - 11111100 */
+    0x000000FE,                         /* 7 - 11111110 */
+    0x000000FF                          /* 8 - 11111111 */
+#else /* (BITMAP_BIT_ORDER == LSBFirst */
+    0x00000000,                         /* 0 - 00000000 */
+    0x00000001,                         /* 1 - 00000001 */
+    0x00000003,                         /* 2 - 00000011 */
+    0x00000007,                         /* 3 - 00000111 */
+    0x0000000F,                         /* 4 - 10000111 */
+    0x0000001F,                         /* 5 - 00011111 */
+    0x0000003F,                         /* 6 - 00111111 */
+    0x0000007F,                         /* 7 - 01111111 */
+    0x000000FF                          /* 8 - 11111111 */
+#endif /* (BITMAP_BIT_ORDER == MSBFirst) */
+#endif /* PGSZ */
+};
+#endif /* PSZ == 8 */
+
+#if PSZ == 16
+PixelGroup QuartetBitsTable[] = {
+#if PGSZ == 32
+#if (BITMAP_BIT_ORDER == MSBFirst)
+    0x00000000,                         /* 0 - 00 */
+    0x00000002,                         /* 1 - 10 */
+    0x00000003,                         /* 2 - 11 */
+#else /* (BITMAP_BIT_ORDER == LSBFirst */
+    0x00000000,                         /* 0 - 00 */
+    0x00000001,                         /* 1 - 01 */
+    0x00000003,                         /* 2 - 11 */
+#endif /* (BITMAP_BIT_ORDER == MSBFirst) */
+#else /* PGSZ == 64 */
+#if (BITMAP_BIT_ORDER == MSBFirst)
+    0x00000000,                         /* 0 - 0000 */
+    0x00000008,                         /* 1 - 1000 */
+    0x0000000C,                         /* 2 - 1100 */
+    0x0000000E,                         /* 3 - 1110 */
+    0x0000000F,                         /* 4 - 1111 */
+#else /* (BITMAP_BIT_ORDER == LSBFirst */
+    0x00000000,                         /* 0 - 0000 */
+    0x00000001,                         /* 1 - 0001 */
+    0x00000003,                         /* 2 - 0011 */
+    0x00000007,                         /* 3 - 0111 */
+    0x0000000F,                         /* 4 - 1111 */
+#endif /* (BITMAP_BIT_ORDER == MSBFirst) */
+#endif /* PGSZ */
+};
+#endif /* PSZ == 16 */
+
+#if PSZ == 24
+PixelGroup QuartetBitsTable[] = {
+#if PGSZ == 32
+#if (BITMAP_BIT_ORDER == MSBFirst)
+    0x00000000,                         /* 0 - 0 */
+    0x00000001,                         /* 1 - 1 */
+#else /* (BITMAP_BIT_ORDER == LSBFirst */
+    0x00000000,                         /* 0 - 0 */
+    0x00000001,                         /* 1 - 1 */
+#endif /* (BITMAP_BIT_ORDER == MSBFirst) */
+#else /* PGSZ == 64 */
+#if (BITMAP_BIT_ORDER == MSBFirst)
+    0x00000000,                         /* 0 - 00 */
+    0x00000002,                         /* 1 - 10 */
+    0x00000003,                         /* 2 - 11*/
+#else /* (BITMAP_BIT_ORDER == LSBFirst */
+    0x00000000,                         /* 0 - 00 */
+    0x00000001,                         /* 1 - 01 */
+    0x00000003,                         /* 2 - 11 */
+#endif /* (BITMAP_BIT_ORDER == MSBFirst) */
+#endif /* PGSZ */
+};
+#endif /* PSZ == 24 */
+
+#if PSZ == 32
+PixelGroup QuartetBitsTable[] = {
+#if PGSZ == 32
+#if (BITMAP_BIT_ORDER == MSBFirst)
+    0x00000000,                         /* 0 - 0 */
+    0x00000001,                         /* 1 - 1 */
+#else /* (BITMAP_BIT_ORDER == LSBFirst */
+    0x00000000,                         /* 0 - 0 */
+    0x00000001,                         /* 1 - 1 */
+#endif /* (BITMAP_BIT_ORDER == MSBFirst) */
+#else /* PGSZ == 64 */
+#if (BITMAP_BIT_ORDER == MSBFirst)
+    0x00000000,                         /* 0 - 00 */
+    0x00000002,                         /* 1 - 10 */
+    0x00000003,                         /* 2 - 11*/
+#else /* (BITMAP_BIT_ORDER == LSBFirst */
+    0x00000000,                         /* 0 - 00 */
+    0x00000001,                         /* 1 - 01 */
+    0x00000003,                         /* 2 - 11 */
+#endif /* (BITMAP_BIT_ORDER == MSBFirst) */
+#endif /* PGSZ */
+};
+#endif /* PSZ == 32 */
+
+/*
+ * QuartetPixelMaskTable is used by getstipplepixels to get a pixel mask
+ * corresponding to a quartet of bits.  Note: the bit/byte order dependency
+ * is handled by QuartetBitsTable above.
+ */
+#if PSZ == 4
+#if PGSZ == 32
+PixelGroup QuartetPixelMaskTable[] = {
+    0x00000000,
+    0x0000000F,
+    0x000000F0,
+    0x000000FF,
+    0x00000F00,
+    0x00000F0F,
+    0x00000FF0,
+    0x00000FFF,
+    0x0000F000,
+    0x0000F00F,
+    0x0000F0F0,
+    0x0000F0FF,
+    0x0000FF00,
+    0x0000FF0F,
+    0x0000FFF0,
+    0x0000FFFF,
+    0x000F0000,
+    0x000F000F,
+    0x000F00F0,
+    0x000F00FF,
+    0x000F0F00,
+    0x000F0F0F,
+    0x000F0FF0,
+    0x000F0FFF,
+    0x000FF000,
+    0x000FF00F,
+    0x000FF0F0,
+    0x000FF0FF,
+    0x000FFF00,
+    0x000FFF0F,
+    0x000FFFF0,
+    0x000FFFFF,
+    0x00F00000,
+    0x00F0000F,
+    0x00F000F0,
+    0x00F000FF,
+    0x00F00F00,
+    0x00F00F0F,
+    0x00F00FF0,
+    0x00F00FFF,
+    0x00F0F000,
+    0x00F0F00F,
+    0x00F0F0F0,
+    0x00F0F0FF,
+    0x00F0FF00,
+    0x00F0FF0F,
+    0x00F0FFF0,
+    0x00F0FFFF,
+    0x00FF0000,
+    0x00FF000F,
+    0x00FF00F0,
+    0x00FF00FF,
+    0x00FF0F00,
+    0x00FF0F0F,
+    0x00FF0FF0,
+    0x00FF0FFF,
+    0x00FFF000,
+    0x00FFF00F,
+    0x00FFF0F0,
+    0x00FFF0FF,
+    0x00FFFF00,
+    0x00FFFF0F,
+    0x00FFFFF0,
+    0x00FFFFFF,
+    0x0F000000,
+    0x0F00000F,
+    0x0F0000F0,
+    0x0F0000FF,
+    0x0F000F00,
+    0x0F000F0F,
+    0x0F000FF0,
+    0x0F000FFF,
+    0x0F00F000,
+    0x0F00F00F,
+    0x0F00F0F0,
+    0x0F00F0FF,
+    0x0F00FF00,
+    0x0F00FF0F,
+    0x0F00FFF0,
+    0x0F00FFFF,
+    0x0F0F0000,
+    0x0F0F000F,
+    0x0F0F00F0,
+    0x0F0F00FF,
+    0x0F0F0F00,
+    0x0F0F0F0F,
+    0x0F0F0FF0,
+    0x0F0F0FFF,
+    0x0F0FF000,
+    0x0F0FF00F,
+    0x0F0FF0F0,
+    0x0F0FF0FF,
+    0x0F0FFF00,
+    0x0F0FFF0F,
+    0x0F0FFFF0,
+    0x0F0FFFFF,
+    0x0FF00000,
+    0x0FF0000F,
+    0x0FF000F0,
+    0x0FF000FF,
+    0x0FF00F00,
+    0x0FF00F0F,
+    0x0FF00FF0,
+    0x0FF00FFF,
+    0x0FF0F000,
+    0x0FF0F00F,
+    0x0FF0F0F0,
+    0x0FF0F0FF,
+    0x0FF0FF00,
+    0x0FF0FF0F,
+    0x0FF0FFF0,
+    0x0FF0FFFF,
+    0x0FFF0000,
+    0x0FFF000F,
+    0x0FFF00F0,
+    0x0FFF00FF,
+    0x0FFF0F00,
+    0x0FFF0F0F,
+    0x0FFF0FF0,
+    0x0FFF0FFF,
+    0x0FFFF000,
+    0x0FFFF00F,
+    0x0FFFF0F0,
+    0x0FFFF0FF,
+    0x0FFFFF00,
+    0x0FFFFF0F,
+    0x0FFFFFF0,
+    0x0FFFFFFF,
+    0xF0000000,
+    0xF000000F,
+    0xF00000F0,
+    0xF00000FF,
+    0xF0000F00,
+    0xF0000F0F,
+    0xF0000FF0,
+    0xF0000FFF,
+    0xF000F000,
+    0xF000F00F,
+    0xF000F0F0,
+    0xF000F0FF,
+    0xF000FF00,
+    0xF000FF0F,
+    0xF000FFF0,
+    0xF000FFFF,
+    0xF00F0000,
+    0xF00F000F,
+    0xF00F00F0,
+    0xF00F00FF,
+    0xF00F0F00,
+    0xF00F0F0F,
+    0xF00F0FF0,
+    0xF00F0FFF,
+    0xF00FF000,
+    0xF00FF00F,
+    0xF00FF0F0,
+    0xF00FF0FF,
+    0xF00FFF00,
+    0xF00FFF0F,
+    0xF00FFFF0,
+    0xF00FFFFF,
+    0xF0F00000,
+    0xF0F0000F,
+    0xF0F000F0,
+    0xF0F000FF,
+    0xF0F00F00,
+    0xF0F00F0F,
+    0xF0F00FF0,
+    0xF0F00FFF,
+    0xF0F0F000,
+    0xF0F0F00F,
+    0xF0F0F0F0,
+    0xF0F0F0FF,
+    0xF0F0FF00,
+    0xF0F0FF0F,
+    0xF0F0FFF0,
+    0xF0F0FFFF,
+    0xF0FF0000,
+    0xF0FF000F,
+    0xF0FF00F0,
+    0xF0FF00FF,
+    0xF0FF0F00,
+    0xF0FF0F0F,
+    0xF0FF0FF0,
+    0xF0FF0FFF,
+    0xF0FFF000,
+    0xF0FFF00F,
+    0xF0FFF0F0,
+    0xF0FFF0FF,
+    0xF0FFFF00,
+    0xF0FFFF0F,
+    0xF0FFFFF0,
+    0xF0FFFFFF,
+    0xFF000000,
+    0xFF00000F,
+    0xFF0000F0,
+    0xFF0000FF,
+    0xFF000F00,
+    0xFF000F0F,
+    0xFF000FF0,
+    0xFF000FFF,
+    0xFF00F000,
+    0xFF00F00F,
+    0xFF00F0F0,
+    0xFF00F0FF,
+    0xFF00FF00,
+    0xFF00FF0F,
+    0xFF00FFF0,
+    0xFF00FFFF,
+    0xFF0F0000,
+    0xFF0F000F,
+    0xFF0F00F0,
+    0xFF0F00FF,
+    0xFF0F0F00,
+    0xFF0F0F0F,
+    0xFF0F0FF0,
+    0xFF0F0FFF,
+    0xFF0FF000,
+    0xFF0FF00F,
+    0xFF0FF0F0,
+    0xFF0FF0FF,
+    0xFF0FFF00,
+    0xFF0FFF0F,
+    0xFF0FFFF0,
+    0xFF0FFFFF,
+    0xFFF00000,
+    0xFFF0000F,
+    0xFFF000F0,
+    0xFFF000FF,
+    0xFFF00F00,
+    0xFFF00F0F,
+    0xFFF00FF0,
+    0xFFF00FFF,
+    0xFFF0F000,
+    0xFFF0F00F,
+    0xFFF0F0F0,
+    0xFFF0F0FF,
+    0xFFF0FF00,
+    0xFFF0FF0F,
+    0xFFF0FFF0,
+    0xFFF0FFFF,
+    0xFFFF0000,
+    0xFFFF000F,
+    0xFFFF00F0,
+    0xFFFF00FF,
+    0xFFFF0F00,
+    0xFFFF0F0F,
+    0xFFFF0FF0,
+    0xFFFF0FFF,
+    0xFFFFF000,
+    0xFFFFF00F,
+    0xFFFFF0F0,
+    0xFFFFF0FF,
+    0xFFFFFF00,
+    0xFFFFFF0F,
+    0xFFFFFFF0,
+    0xFFFFFFFF,
+};
+#else /* PGSZ == 64 */
+No QuartetPixelMaskTable for psz=PSZ
+this would be a 64K entry table, a bit much I think.
+Try breaking things in two:
+mask = table[index&0xff00]<<32 | table[index&0xff]
+#endif /* PGSZ */
+#endif /* PSZ == 4 */
+
+#if PSZ == 8
+PixelGroup QuartetPixelMaskTable[] = {
+#if PGSZ == 32
+    0x00000000,
+    0x000000FF,
+    0x0000FF00,
+    0x0000FFFF,
+    0x00FF0000,
+    0x00FF00FF,
+    0x00FFFF00,
+    0x00FFFFFF,
+    0xFF000000,
+    0xFF0000FF,
+    0xFF00FF00,
+    0xFF00FFFF,
+    0xFFFF0000,
+    0xFFFF00FF,
+    0xFFFFFF00,
+    0xFFFFFFFF
+#else /* PGSZ == 64 */
+    0x0000000000000000,    0x00000000000000FF,
+    0x000000000000FF00,    0x000000000000FFFF,
+    0x0000000000FF0000,    0x0000000000FF00FF,
+    0x0000000000FFFF00,    0x0000000000FFFFFF,
+    0x00000000FF000000,    0x00000000FF0000FF,
+    0x00000000FF00FF00,    0x00000000FF00FFFF,
+    0x00000000FFFF0000,    0x00000000FFFF00FF,
+    0x00000000FFFFFF00,    0x00000000FFFFFFFF,
+    0x000000FF00000000,    0x000000FF000000FF,
+    0x000000FF0000FF00,    0x000000FF0000FFFF,
+    0x000000FF00FF0000,    0x000000FF00FF00FF,
+    0x000000FF00FFFF00,    0x000000FF00FFFFFF,
+    0x000000FFFF000000,    0x000000FFFF0000FF,
+    0x000000FFFF00FF00,    0x000000FFFF00FFFF,
+    0x000000FFFFFF0000,    0x000000FFFFFF00FF,
+    0x000000FFFFFFFF00,    0x000000FFFFFFFFFF,
+    0x0000FF0000000000,    0x0000FF00000000FF,
+    0x0000FF000000FF00,    0x0000FF000000FFFF,
+    0x0000FF0000FF0000,    0x0000FF0000FF00FF,
+    0x0000FF0000FFFF00,    0x0000FF0000FFFFFF,
+    0x0000FF00FF000000,    0x0000FF00FF0000FF,
+    0x0000FF00FF00FF00,    0x0000FF00FF00FFFF,
+    0x0000FF00FFFF0000,    0x0000FF00FFFF00FF,
+    0x0000FF00FFFFFF00,    0x0000FF00FFFFFFFF,
+    0x0000FFFF00000000,    0x0000FFFF000000FF,
+    0x0000FFFF0000FF00,    0x0000FFFF0000FFFF,
+    0x0000FFFF00FF0000,    0x0000FFFF00FF00FF,
+    0x0000FFFF00FFFF00,    0x0000FFFF00FFFFFF,
+    0x0000FFFFFF000000,    0x0000FFFFFF0000FF,
+    0x0000FFFFFF00FF00,    0x0000FFFFFF00FFFF,
+    0x0000FFFFFFFF0000,    0x0000FFFFFFFF00FF,
+    0x0000FFFFFFFFFF00,    0x0000FFFFFFFFFFFF,
+    0x00FF000000000000,    0x00FF0000000000FF,
+    0x00FF00000000FF00,    0x00FF00000000FFFF,
+    0x00FF000000FF0000,    0x00FF000000FF00FF,
+    0x00FF000000FFFF00,    0x00FF000000FFFFFF,
+    0x00FF0000FF000000,    0x00FF0000FF0000FF,
+    0x00FF0000FF00FF00,    0x00FF0000FF00FFFF,
+    0x00FF0000FFFF0000,    0x00FF0000FFFF00FF,
+    0x00FF0000FFFFFF00,    0x00FF0000FFFFFFFF,
+    0x00FF00FF00000000,    0x00FF00FF000000FF,
+    0x00FF00FF0000FF00,    0x00FF00FF0000FFFF,
+    0x00FF00FF00FF0000,    0x00FF00FF00FF00FF,
+    0x00FF00FF00FFFF00,    0x00FF00FF00FFFFFF,
+    0x00FF00FFFF000000,    0x00FF00FFFF0000FF,
+    0x00FF00FFFF00FF00,    0x00FF00FFFF00FFFF,
+    0x00FF00FFFFFF0000,    0x00FF00FFFFFF00FF,
+    0x00FF00FFFFFFFF00,    0x00FF00FFFFFFFFFF,
+    0x00FFFF0000000000,    0x00FFFF00000000FF,
+    0x00FFFF000000FF00,    0x00FFFF000000FFFF,
+    0x00FFFF0000FF0000,    0x00FFFF0000FF00FF,
+    0x00FFFF0000FFFF00,    0x00FFFF0000FFFFFF,
+    0x00FFFF00FF000000,    0x00FFFF00FF0000FF,
+    0x00FFFF00FF00FF00,    0x00FFFF00FF00FFFF,
+    0x00FFFF00FFFF0000,    0x00FFFF00FFFF00FF,
+    0x00FFFF00FFFFFF00,    0x00FFFF00FFFFFFFF,
+    0x00FFFFFF00000000,    0x00FFFFFF000000FF,
+    0x00FFFFFF0000FF00,    0x00FFFFFF0000FFFF,
+    0x00FFFFFF00FF0000,    0x00FFFFFF00FF00FF,
+    0x00FFFFFF00FFFF00,    0x00FFFFFF00FFFFFF,
+    0x00FFFFFFFF000000,    0x00FFFFFFFF0000FF,
+    0x00FFFFFFFF00FF00,    0x00FFFFFFFF00FFFF,
+    0x00FFFFFFFFFF0000,    0x00FFFFFFFFFF00FF,
+    0x00FFFFFFFFFFFF00,    0x00FFFFFFFFFFFFFF,
+    0xFF00000000000000,    0xFF000000000000FF,
+    0xFF0000000000FF00,    0xFF0000000000FFFF,
+    0xFF00000000FF0000,    0xFF00000000FF00FF,
+    0xFF00000000FFFF00,    0xFF00000000FFFFFF,
+    0xFF000000FF000000,    0xFF000000FF0000FF,
+    0xFF000000FF00FF00,    0xFF000000FF00FFFF,
+    0xFF000000FFFF0000,    0xFF000000FFFF00FF,
+    0xFF000000FFFFFF00,    0xFF000000FFFFFFFF,
+    0xFF0000FF00000000,    0xFF0000FF000000FF,
+    0xFF0000FF0000FF00,    0xFF0000FF0000FFFF,
+    0xFF0000FF00FF0000,    0xFF0000FF00FF00FF,
+    0xFF0000FF00FFFF00,    0xFF0000FF00FFFFFF,
+    0xFF0000FFFF000000,    0xFF0000FFFF0000FF,
+    0xFF0000FFFF00FF00,    0xFF0000FFFF00FFFF,
+    0xFF0000FFFFFF0000,    0xFF0000FFFFFF00FF,
+    0xFF0000FFFFFFFF00,    0xFF0000FFFFFFFFFF,
+    0xFF00FF0000000000,    0xFF00FF00000000FF,
+    0xFF00FF000000FF00,    0xFF00FF000000FFFF,
+    0xFF00FF0000FF0000,    0xFF00FF0000FF00FF,
+    0xFF00FF0000FFFF00,    0xFF00FF0000FFFFFF,
+    0xFF00FF00FF000000,    0xFF00FF00FF0000FF,
+    0xFF00FF00FF00FF00,    0xFF00FF00FF00FFFF,
+    0xFF00FF00FFFF0000,    0xFF00FF00FFFF00FF,
+    0xFF00FF00FFFFFF00,    0xFF00FF00FFFFFFFF,
+    0xFF00FFFF00000000,    0xFF00FFFF000000FF,
+    0xFF00FFFF0000FF00,    0xFF00FFFF0000FFFF,
+    0xFF00FFFF00FF0000,    0xFF00FFFF00FF00FF,
+    0xFF00FFFF00FFFF00,    0xFF00FFFF00FFFFFF,
+    0xFF00FFFFFF000000,    0xFF00FFFFFF0000FF,
+    0xFF00FFFFFF00FF00,    0xFF00FFFFFF00FFFF,
+    0xFF00FFFFFFFF0000,    0xFF00FFFFFFFF00FF,
+    0xFF00FFFFFFFFFF00,    0xFF00FFFFFFFFFFFF,
+    0xFFFF000000000000,    0xFFFF0000000000FF,
+    0xFFFF00000000FF00,    0xFFFF00000000FFFF,
+    0xFFFF000000FF0000,    0xFFFF000000FF00FF,
+    0xFFFF000000FFFF00,    0xFFFF000000FFFFFF,
+    0xFFFF0000FF000000,    0xFFFF0000FF0000FF,
+    0xFFFF0000FF00FF00,    0xFFFF0000FF00FFFF,
+    0xFFFF0000FFFF0000,    0xFFFF0000FFFF00FF,
+    0xFFFF0000FFFFFF00,    0xFFFF0000FFFFFFFF,
+    0xFFFF00FF00000000,    0xFFFF00FF000000FF,
+    0xFFFF00FF0000FF00,    0xFFFF00FF0000FFFF,
+    0xFFFF00FF00FF0000,    0xFFFF00FF00FF00FF,
+    0xFFFF00FF00FFFF00,    0xFFFF00FF00FFFFFF,
+    0xFFFF00FFFF000000,    0xFFFF00FFFF0000FF,
+    0xFFFF00FFFF00FF00,    0xFFFF00FFFF00FFFF,
+    0xFFFF00FFFFFF0000,    0xFFFF00FFFFFF00FF,
+    0xFFFF00FFFFFFFF00,    0xFFFF00FFFFFFFFFF,
+    0xFFFFFF0000000000,    0xFFFFFF00000000FF,
+    0xFFFFFF000000FF00,    0xFFFFFF000000FFFF,
+    0xFFFFFF0000FF0000,    0xFFFFFF0000FF00FF,
+    0xFFFFFF0000FFFF00,    0xFFFFFF0000FFFFFF,
+    0xFFFFFF00FF000000,    0xFFFFFF00FF0000FF,
+    0xFFFFFF00FF00FF00,    0xFFFFFF00FF00FFFF,
+    0xFFFFFF00FFFF0000,    0xFFFFFF00FFFF00FF,
+    0xFFFFFF00FFFFFF00,    0xFFFFFF00FFFFFFFF,
+    0xFFFFFFFF00000000,    0xFFFFFFFF000000FF,
+    0xFFFFFFFF0000FF00,    0xFFFFFFFF0000FFFF,
+    0xFFFFFFFF00FF0000,    0xFFFFFFFF00FF00FF,
+    0xFFFFFFFF00FFFF00,    0xFFFFFFFF00FFFFFF,
+    0xFFFFFFFFFF000000,    0xFFFFFFFFFF0000FF,
+    0xFFFFFFFFFF00FF00,    0xFFFFFFFFFF00FFFF,
+    0xFFFFFFFFFFFF0000,    0xFFFFFFFFFFFF00FF,
+    0xFFFFFFFFFFFFFF00,    0xFFFFFFFFFFFFFFFF,
+#endif /* PGSZ */
+};
+#endif /* PSZ == 8 */
+
+#if PSZ == 16
+PixelGroup QuartetPixelMaskTable[] = {
+#if PGSZ == 32
+    0x00000000,
+    0x0000FFFF,
+    0xFFFF0000,
+    0xFFFFFFFF,
+#else /* PGSZ == 64 */
+    0x0000000000000000,    0x000000000000FFFF,
+    0x00000000FFFF0000,    0x00000000FFFFFFFF,
+    0x0000FFFF00000000,    0x0000FFFF0000FFFF,
+    0x0000FFFFFFFF0000,    0x0000FFFFFFFFFFFF,
+    0xFFFF000000000000,    0xFFFF00000000FFFF,
+    0xFFFF0000FFFF0000,    0xFFFF0000FFFFFFFF,
+    0xFFFFFFFF00000000,    0xFFFFFFFF0000FFFF,
+    0xFFFFFFFFFFFF0000,    0xFFFFFFFFFFFFFFFF,
+#endif /* PGSZ */
+};
+#endif /* PSZ == 16 */
+
+#if PSZ == 24
+PixelGroup QuartetPixelMaskTable[] = {
+#if PGSZ == 32
+/* Four pixels consist three pixel groups....*/
+    0x00000000, 0x00FFFFFF, /*0x00000000, *//*0*/
+/*    0x00000000, 0x00000000, 0x00000000,*/ /*0*/
+/*    0x00FFFFFF, 0x00000000, 0x00000000,*/ /*1*/
+/*    0xFF000000, 0x0000FFFF, 0x00000000,*/ /*2*/
+/*    0xFFFFFFFF, 0x0000FFFF, 0x00000000,*/ /*3*/
+/*    0x00000000, 0xFFFF0000, 0x000000FF,*/ /*4*/
+/*    0x00FFFFFF, 0xFFFF0000, 0x000000FF,*/ /*5*/
+/*    0xFF000000, 0xFFFFFFFF, 0x000000FF,*/ /*6*/
+/*    0xFFFFFFFF, 0xFFFFFFFF, 0x000000FF,*/ /*7*/
+/*    0x00000000, 0x00000000, 0xFFFFFF00,*/ /*8*/
+/*    0x00FFFFFF, 0x00000000, 0xFFFFFF00,*/ /*9*/
+/*    0xFF000000, 0x0000FFFF, 0xFFFFFF00,*/ /*10*/
+/*    0xFFFFFFFF, 0x0000FFFF, 0xFFFFFF00,*/ /*11*/
+/*    0x00000000, 0xFFFF0000, 0xFFFFFFFF,*/ /*12*/
+/*    0x00FFFFFF, 0xFFFF0000, 0xFFFFFFFF,*/ /*13*/
+/*    0xFF000000, 0xFFFFFFFF, 0xFFFFFFFF,*/ /*14*/
+/*    0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,*/ /*15*/
+#else /* PGSZ == 64 */
+    0x0000000000000000,    0x0000000000FFFFFF,
+    0x0000FFFFFF000000,    0xFFFFFFFFFFFFFFFF
+#endif /* PGSZ */
+};
+#endif /* PSZ == 24 */
+
+#if PSZ == 32
+PixelGroup QuartetPixelMaskTable[] = {
+#if PGSZ == 32
+    0x00000000,
+    0xFFFFFFFF,
+#else /* PGSZ == 64 */
+    0x0000000000000000,
+    0x00000000FFFFFFFF,
+    0xFFFFFFFF00000000,
+    0xFFFFFFFFFFFFFFFF
+#endif /* PGSZ */
+};
+#endif /* PSZ == 32 */
+
+#if PSZ == 24
+int cfb24Shift[] = 
+#if    (BITMAP_BIT_ORDER == MSBFirst)
+{8,0,16,16,8,24,0,0};
+#else  /* (BITMAP_BIT_ORDER == LSBFirst) */
+{0,0,24,8,16,16,8,0};
+#endif /* (BITMAP_BIT_ORDER == MSBFirst) */
+#endif
diff --git a/Xserver/programs/Xserver/cfb/cfbmskbits.h b/Xserver/programs/Xserver/cfb/cfbmskbits.h
new file mode 100644 (file)
index 0000000..92275c8
--- /dev/null
@@ -0,0 +1,902 @@
+/************************************************************
+Copyright 1987 by Sun Microsystems, Inc. Mountain View, CA.
+
+                    All Rights Reserved
+
+Permission  to  use,  copy,  modify,  and  distribute   this
+software  and  its documentation for any purpose and without
+fee is hereby granted, provided that the above copyright no-
+tice  appear  in all copies and that both that copyright no-
+tice and this permission notice appear in  supporting  docu-
+mentation,  and  that the names of Sun or X Consortium
+not be used in advertising or publicity pertaining to 
+distribution  of  the software  without specific prior 
+written permission. Sun and X Consortium make no 
+representations about the suitability of this software for 
+any purpose. It is provided "as is" without any express or 
+implied warranty.
+
+SUN DISCLAIMS ALL WARRANTIES WITH REGARD TO  THIS  SOFTWARE,
+INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FIT-
+NESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SUN BE  LI-
+ABLE  FOR  ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
+ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,  DATA  OR
+PROFITS,  WHETHER  IN  AN  ACTION OF CONTRACT, NEGLIGENCE OR
+OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION  WITH
+THE USE OR PERFORMANCE OF THIS SOFTWARE.
+
+********************************************************/
+
+/* $XConsortium: cfbmskbits.h,v 4.25 94/04/17 20:28:55 dpw Exp $ */
+/* $XFree86: xc/programs/Xserver/cfb/cfbmskbits.h,v 3.3.2.1 1997/05/27 06:28:09 dawes Exp $ */
+/* Optimizations for PSZ == 32 added by Kyle Marvin (marvin@vitec.com) */
+
+#include       "X.h"
+#include       "Xmd.h"
+#include       "servermd.h"
+#ifdef XFREE86
+#define NO_COMPILER_H_EXTRAS
+#include       "compiler.h"
+#endif
+
+/*
+ * ==========================================================================
+ * Converted from mfb to support memory-mapped color framebuffer by smarks@sun, 
+ * April-May 1987.
+ *
+ * The way I did the conversion was to consider each longword as an
+ * array of four bytes instead of an array of 32 one-bit pixels.  So
+ * getbits() and putbits() retain much the same calling sequence, but
+ * they move bytes around instead of bits.  Of course, this entails the
+ * removal of all of the one-bit-pixel dependencies from the other
+ * files, but the major bit-hacking stuff should be covered here.
+ *
+ * I've created some new macros that make it easier to understand what's 
+ * going on in the pixel calculations, and that make it easier to change the 
+ * pixel size.
+ *
+ * name            explanation
+ * ----            -----------
+ * PSZ     pixel size (in bits)
+ * PGSZ     pixel group size (in bits)
+ * PGSZB    pixel group size (in bytes)
+ * PGSZBMSK mask with lowest PGSZB bits set to 1
+ * PPW     pixels per word (pixels per pixel group)
+ * PPWMSK   mask with lowest PPW bits set to 1
+ * PLST            index of last pixel in a word (should be PPW-1)
+ * PIM     pixel index mask (index within a pixel group)
+ * PWSH            pixel-to-word shift (should be log2(PPW))
+ * PMSK            mask with lowest PSZ bits set to 1
+ *
+ *
+ * Here are some sample values.  In the notation cfbA,B: A is PSZ, and
+ * B is PGSZB.  All the other values are derived from these
+ * two.  This table does not show all combinations!
+ *
+ * name            cfb8,4    cfb24,4      cfb32,4    cfb8,8    cfb24,8    cfb32,8
+ * ----            ------    -------      ------     ------    ------     -------
+ * PSZ       8         24           32          8        24         32
+ * PGSZ             32         32           32         64        64         64
+ * PGSZB      4          4            4          8         8          8
+ * PGSZBMSK 0xF        0xF?         0xF        0xFF      0xFF       0xFF
+ * PPW       4          1            1          8         2          2
+ * PPWMSK   0xF        0x1          0x1        0xFF       0x3?       0x3    
+ * PLST              3          0            0          7         1          1
+ * PIM     0x3        0x0          0x0        0x7       0x1?        0x1
+ * PWSH              2          0            0          3         1          1
+ * PMSK            0xFF      0xFFFFFF     0xFFFFFFFF 0xFF      0xFFFFFF   0xFFFFFFFF
+ *
+ *
+ * I have also added a new macro, PFILL, that takes one pixel and
+ * replicates it throughout a word.  This macro definition is dependent
+ * upon pixel and word size; it doesn't use macros like PPW and so
+ * forth.  Examples: for monochrome, PFILL(1) => 0xffffffff, PFILL(0) =>
+ * 0x00000000.  For 8-bit color, PFILL(0x5d) => 0x5d5d5d5d.  This macro
+ * is used primarily for replicating a plane mask into a word.
+ *
+ * Color framebuffers operations also support the notion of a plane
+ * mask.  This mask determines which planes of the framebuffer can be
+ * altered; the others are left unchanged.  I have added another
+ * parameter to the putbits and putbitsrop macros that is the plane
+ * mask.
+ * ==========================================================================
+ */
+
+/*
+ *  PSZ needs to be defined before we get here.  Usually it comes from a
+ *  -DPSZ=foo on the compilation command line.
+ */
+
+#ifndef PSZ
+#define PSZ 8
+#endif
+
+/*
+ *  PixelGroup is the data type used to operate on groups of pixels.
+ *  We typedef it here to unsigned long with the assumption that you
+ *  want to manipulate as many pixels at a time as you can.  If unsigned
+ *  long is not appropriate for your server, define it to something else
+ *  before including this file.  In this case you will also have to define
+ *  PGSZB to the size in bytes of PixelGroup.
+ */
+#ifndef PixelGroup
+typedef unsigned long PixelGroup;
+#ifdef LONG64
+#define PGSZB 8
+#else
+#define PGSZB 4
+#endif /* LONG64 */
+#endif /* PixelGroup */
+
+#define PGSZ   (PGSZB << 3)
+#define PPW    (PGSZ/PSZ)
+#define PLST   (PPW-1)
+#define PIM    PLST
+#define PMSK   (((PixelGroup)1 << PSZ) - 1)
+#define PPWMSK  (((PixelGroup)1 << PPW) - 1) /* instead of BITMSK */
+#define PGSZBMSK (((PixelGroup)1 << PGSZB) - 1)
+
+/*  set PWSH = log2(PPW) using brute force */
+
+#if PPW == 1
+#define PWSH 0
+#else
+#if PPW == 2
+#define PWSH 1
+#else
+#if PPW == 4
+#define PWSH 2
+#else
+#if PPW == 8
+#define PWSH 3
+#else
+#if PPW == 16
+#define PWSH 4
+#endif /* PPW == 16 */
+#endif /* PPW == 8 */
+#endif /* PPW == 4 */
+#endif /* PPW == 2 */
+#endif /* PPW == 1 */
+
+/*  Defining PIXEL_ADDR means that individual pixels are addressable by this
+ *  machine (as type PixelType).  A possible CFB architecture which supported
+ *  8-bits-per-pixel on a non byte-addressable machine would not have this
+ *  defined.
+ *
+ *  Defining FOUR_BIT_CODE means that cfb knows how to stipple on this machine;
+ *  eventually, stippling code for 16 and 32 bit devices should be written
+ *  which would allow them to also use FOUR_BIT_CODE.  There isn't that
+ *  much to do in those cases, but it would make them quite a bit faster.
+ */
+
+#if PSZ == 8
+#define PIXEL_ADDR
+typedef CARD8 PixelType;
+#define FOUR_BIT_CODE
+#endif
+
+#if PSZ == 16
+#define PIXEL_ADDR
+typedef CARD16 PixelType;
+#endif
+
+#if PSZ == 24
+#undef PMSK
+#define PMSK   0xFFFFFF
+/*#undef PIM
+#define PIM 3*/
+#define PIXEL_ADDR
+typedef CARD32 PixelType;
+#endif
+
+#if PSZ == 32
+#undef PMSK
+#define PMSK   0xFFFFFFFF
+#define PIXEL_ADDR
+typedef CARD32 PixelType;
+#endif
+
+
+/* the following notes use the following conventions:
+SCREEN LEFT                            SCREEN RIGHT
+in this file and maskbits.c, left and right refer to screen coordinates,
+NOT bit numbering in registers.
+
+cfbstarttab[n] 
+       pixels[0,n-1] = 0's     pixels[n,PPW-1] = 1's
+cfbendtab[n] =
+       pixels[0,n-1] = 1's     pixels[n,PPW-1] = 0's
+
+cfbstartpartial[], cfbendpartial[]
+       these are used as accelerators for doing putbits and masking out
+bits that are all contained between longword boudaries.  the extra
+256 bytes of data seems a small price to pay -- code is smaller,
+and narrow things (e.g. window borders) go faster.
+
+the names may seem misleading; they are derived not from which end
+of the word the bits are turned on, but at which end of a scanline
+the table tends to be used.
+
+look at the tables and macros to understand boundary conditions.
+(careful readers will note that starttab[n] = ~endtab[n] for n != 0)
+
+-----------------------------------------------------------------------
+these two macros depend on the screen's bit ordering.
+in both of them x is a screen position.  they are used to
+combine bits collected from multiple longwords into a
+single destination longword, and to unpack a single
+source longword into multiple destinations.
+
+SCRLEFT(dst, x)
+       takes dst[x, PPW] and moves them to dst[0, PPW-x]
+       the contents of the rest of dst are 0 ONLY IF
+       dst is UNSIGNED.
+       is cast as an unsigned.
+       this is a right shift on the VAX, left shift on
+       Sun and pc-rt.
+
+SCRRIGHT(dst, x)
+       takes dst[0,x] and moves them to dst[PPW-x, PPW]
+       the contents of the rest of dst are 0 ONLY IF
+       dst is UNSIGNED.
+       this is a left shift on the VAX, right shift on
+       Sun and pc-rt.
+
+
+the remaining macros are cpu-independent; all bit order dependencies
+are built into the tables and the two macros above.
+
+maskbits(x, w, startmask, endmask, nlw)
+       for a span of width w starting at position x, returns
+a mask for ragged pixels at start, mask for ragged pixels at end,
+and the number of whole longwords between the ends.
+
+maskpartialbits(x, w, mask)
+       works like maskbits(), except all the pixels are in the
+       same longword (i.e. (x&0xPIM + w) <= PPW)
+
+mask32bits(x, w, startmask, endmask, nlw)
+       as maskbits, but does not calculate nlw.  it is used by
+       cfbGlyphBlt to put down glyphs <= PPW bits wide.
+
+getbits(psrc, x, w, dst)
+       starting at position x in psrc (x < PPW), collect w
+       pixels and put them in the screen left portion of dst.
+       psrc is a longword pointer.  this may span longword boundaries.
+       it special-cases fetching all w bits from one longword.
+
+       +--------+--------+             +--------+
+       |    | m |n|      |     ==>     | m |n|  |
+       +--------+--------+             +--------+
+           x      x+w                  0     w
+       psrc     psrc+1                 dst
+                       m = PPW - x
+                       n = w - m
+
+       implementation:
+       get m pixels, move to screen-left of dst, zeroing rest of dst;
+       get n pixels from next word, move screen-right by m, zeroing
+                lower m pixels of word.
+       OR the two things together.
+
+putbits(src, x, w, pdst, planemask)
+       starting at position x in pdst, put down the screen-leftmost
+       w bits of src.  pdst is a longword pointer.  this may
+       span longword boundaries.
+       it special-cases putting all w bits into the same longword.
+
+       +--------+                      +--------+--------+
+       | m |n|  |              ==>     |    | m |n|      |
+       +--------+                      +--------+--------+
+       0     w                              x     x+w
+       dst                             pdst     pdst+1
+                       m = PPW - x
+                       n = w - m
+
+       implementation:
+       get m pixels, shift screen-right by x, zero screen-leftmost x
+               pixels; zero rightmost m bits of *pdst and OR in stuff
+               from before the semicolon.
+       shift src screen-left by m, zero bits n-32;
+               zero leftmost n pixels of *(pdst+1) and OR in the
+               stuff from before the semicolon.
+
+putbitsrop(src, x, w, pdst, planemask, ROP)
+       like putbits but calls DoRop with the rasterop ROP (see cfb.h for
+       DoRop)
+
+getleftbits(psrc, w, dst)
+       get the leftmost w (w<=PPW) bits from *psrc and put them
+       in dst.  this is used by the cfbGlyphBlt code for glyphs
+       <=PPW bits wide.
+*/
+
+#if    (BITMAP_BIT_ORDER == MSBFirst)
+#define BitRight(lw,n) ((lw) >> (n))
+#define BitLeft(lw,n)  ((lw) << (n))
+#else  /* (BITMAP_BIT_ORDER == LSBFirst) */
+#define BitRight(lw,n) ((lw) << (n))
+#define BitLeft(lw,n)  ((lw) >> (n))
+#endif /* (BITMAP_BIT_ORDER == MSBFirst) */
+
+#define SCRLEFT(lw, n) BitLeft (lw, (n) * PSZ)
+#define SCRRIGHT(lw, n)        BitRight(lw, (n) * PSZ)
+
+/*
+ * Note that the shift direction is independent of the byte ordering of the 
+ * machine.  The following is portable code.
+ */
+#if PPW == 16
+#define PFILL(p) ( ((p)&PMSK)          | \
+                  ((p)&PMSK) <<   PSZ | \
+                  ((p)&PMSK) << 2*PSZ | \
+                  ((p)&PMSK) << 3*PSZ | \
+                  ((p)&PMSK) << 4*PSZ | \
+                  ((p)&PMSK) << 5*PSZ | \
+                  ((p)&PMSK) << 6*PSZ | \
+                  ((p)&PMSK) << 7*PSZ | \
+                  ((p)&PMSK) << 8*PSZ | \
+                  ((p)&PMSK) << 9*PSZ | \
+                  ((p)&PMSK) << 10*PSZ | \
+                  ((p)&PMSK) << 11*PSZ | \
+                  ((p)&PMSK) << 12*PSZ | \
+                  ((p)&PMSK) << 13*PSZ | \
+                  ((p)&PMSK) << 14*PSZ | \
+                  ((p)&PMSK) << 15*PSZ ) 
+#define PFILL2(p, pf) { \
+    pf = (p) & PMSK; \
+    pf |= (pf << PSZ); \
+    pf |= (pf << 2*PSZ); \
+    pf |= (pf << 4*PSZ); \
+    pf |= (pf << 8*PSZ); \
+}
+#endif /* PPW == 16 */
+#if PPW == 8
+#define PFILL(p) ( ((p)&PMSK)          | \
+                  ((p)&PMSK) <<   PSZ | \
+                  ((p)&PMSK) << 2*PSZ | \
+                  ((p)&PMSK) << 3*PSZ | \
+                  ((p)&PMSK) << 4*PSZ | \
+                  ((p)&PMSK) << 5*PSZ | \
+                  ((p)&PMSK) << 6*PSZ | \
+                  ((p)&PMSK) << 7*PSZ )
+#define PFILL2(p, pf) { \
+    pf = (p) & PMSK; \
+    pf |= (pf << PSZ); \
+    pf |= (pf << 2*PSZ); \
+    pf |= (pf << 4*PSZ); \
+}
+#endif
+#if PPW == 4
+#define PFILL(p) ( ((p)&PMSK)          | \
+                  ((p)&PMSK) <<   PSZ | \
+                  ((p)&PMSK) << 2*PSZ | \
+                  ((p)&PMSK) << 3*PSZ )
+#define PFILL2(p, pf) { \
+    pf = (p) & PMSK; \
+    pf |= (pf << PSZ); \
+    pf |= (pf << 2*PSZ); \
+}
+#endif
+#if PPW == 2
+#define PFILL(p) ( ((p)&PMSK)          | \
+                  ((p)&PMSK) <<   PSZ )
+#define PFILL2(p, pf) { \
+    pf = (p) & PMSK; \
+    pf |= (pf << PSZ); \
+}
+#endif
+#if PPW == 1
+#define PFILL(p)       (p)
+#define PFILL2(p,pf)   (pf = (p))
+#endif
+
+/*
+ * Reduced raster op - using precomputed values, perform the above
+ * in three instructions
+ */
+
+#define DoRRop(dst, and, xor)  (((dst) & (and)) ^ (xor))
+
+#define DoMaskRRop(dst, and, xor, mask) \
+    (((dst) & ((and) | ~(mask))) ^ (xor & mask))
+
+#if PSZ != 32 || PPW != 1
+
+# if (PSZ == 24 && PPW == 1)
+#define maskbits(x, w, startmask, endmask, nlw) {\
+    startmask = cfbstarttab[(x)&3]; \
+    endmask = cfbendtab[((x)+(w)) & 3]; \
+    nlw = ((((x)+(w))*3)>>2) - (((x)*3 +3)>>2); \
+}
+
+#define mask32bits(x, w, startmask, endmask) \
+    startmask = cfbstarttab[(x)&3]; \
+    endmask = cfbendtab[((x)+(w)) & 3];
+
+#define maskpartialbits(x, w, mask) \
+    mask = cfbstartpartial[(x) & 3] & cfbendpartial[((x)+(w)) & 3];
+
+#define maskbits24(x, w, startmask, endmask, nlw) \
+    startmask = cfbstarttab24[(x) & 3]; \
+    endmask = cfbendtab24[((x)+(w)) & 3]; \
+    if (startmask){ \
+       nlw = (((w) - (4 - ((x) & 3))) >> 2); \
+    } else { \
+       nlw = (w) >> 2; \
+    }
+
+#define getbits24(psrc, dst, index) {\
+    register int idx; \
+    switch(idx = ((index)&3)<<1){ \
+       case 0: \
+               dst = (*(psrc) &cfbmask[idx]); \
+               break; \
+       case 6: \
+               dst = BitLeft((*(psrc) &cfbmask[idx]), cfb24Shift[idx]); \
+               break; \
+       default: \
+               dst = BitLeft((*(psrc) &cfbmask[idx]), cfb24Shift[idx]) | \
+               BitRight(((*((psrc)+1)) &cfbmask[idx+1]), cfb24Shift[idx+1]); \
+       }; \
+}
+
+#define putbits24(src, x, w, pdst, planemask, index) {\
+    register PixelGroup dstpixel; \
+    register unsigned int idx; \
+    switch(idx = ((index)&3)<<1){ \
+       case 0: \
+               dstpixel = (*(pdst) &cfbmask[idx]); \
+               break; \
+       case 6: \
+               dstpixel = BitLeft((*(pdst) &cfbmask[idx]), cfb24Shift[idx]); \
+               break; \
+       default: \
+               dstpixel = BitLeft((*(pdst) &cfbmask[idx]), cfb24Shift[idx])| \
+               BitRight(((*((pdst)+1)) &cfbmask[idx+1]), cfb24Shift[idx+1]); \
+       }; \
+    dstpixel &= ~(planemask); \
+    dstpixel |= (src & planemask); \
+    *(pdst) &= cfbrmask[idx]; \
+    switch(idx){ \
+       case 0: \
+               *(pdst) |=  (dstpixel & cfbmask[idx]); \
+               break; \
+       case 2: \
+       case 4: \
+               pdst++;idx++; \
+               *(pdst) = ((*(pdst))  & cfbrmask[idx]) | \
+                               (BitLeft(dstpixel, cfb24Shift[idx]) & cfbmask[idx]); \
+               pdst--;idx--; \
+       case 6: \
+               *(pdst) |=  (BitRight(dstpixel, cfb24Shift[idx]) & cfbmask[idx]); \
+               break; \
+       }; \
+}
+
+#define putbitsrop24(src, x, pdst, planemask, rop) \
+{ \
+    register PixelGroup t1, dstpixel; \
+    register unsigned int idx; \
+    switch(idx = (x)<<1){ \
+       case 0: \
+               dstpixel = (*(pdst) &cfbmask[idx]); \
+               break; \
+       case 6: \
+               dstpixel = BitLeft((*(pdst) &cfbmask[idx]), cfb24Shift[idx]); \
+               break; \
+       default: \
+               dstpixel = BitLeft((*(pdst) &cfbmask[idx]), cfb24Shift[idx])| \
+               BitRight(((*((pdst)+1)) &cfbmask[idx+1]), cfb24Shift[idx+1]); \
+       }; \
+    DoRop(t1, rop, (src), dstpixel); \
+    dstpixel &= ~planemask; \
+    dstpixel |= (t1 & planemask); \
+    *(pdst) &= cfbrmask[idx]; \
+    switch(idx){ \
+       case 0: \
+               *(pdst) |= (dstpixel & cfbmask[idx]); \
+               break; \
+       case 2: \
+       case 4: \
+               *((pdst)+1) = ((*((pdst)+1))  & cfbrmask[idx+1]) | \
+                               (BitLeft(dstpixel, cfb24Shift[idx+1]) & (cfbmask[idx+1])); \
+       case 6: \
+               *(pdst) |= (BitRight(dstpixel, cfb24Shift[idx]) & cfbmask[idx]); \
+       }; \
+}
+# else  /* PSZ == 24 && PPW == 1 */
+#define maskbits(x, w, startmask, endmask, nlw) \
+    startmask = cfbstarttab[(x)&PIM]; \
+    endmask = cfbendtab[((x)+(w)) & PIM]; \
+    if (startmask) \
+       nlw = (((w) - (PPW - ((x)&PIM))) >> PWSH); \
+    else \
+       nlw = (w) >> PWSH;
+
+#define maskpartialbits(x, w, mask) \
+    mask = cfbstartpartial[(x) & PIM] & cfbendpartial[((x) + (w)) & PIM];
+
+#define mask32bits(x, w, startmask, endmask) \
+    startmask = cfbstarttab[(x)&PIM]; \
+    endmask = cfbendtab[((x)+(w)) & PIM];
+
+/* FIXME */
+#define maskbits24(x, w, startmask, endmask, nlw) \
+    abort()
+#define getbits24(psrc, dst, index) \
+    abort()
+#define putbits24(src, x, w, pdst, planemask, index) \
+    abort()
+#define putbitsrop24(src, x, pdst, planemask, rop) \
+    abort()
+
+#endif /* PSZ == 24 && PPW == 1 */
+
+#define getbits(psrc, x, w, dst) \
+if ( ((x) + (w)) <= PPW) \
+{ \
+    dst = SCRLEFT(*(psrc), (x)); \
+} \
+else \
+{ \
+    int m; \
+    m = PPW-(x); \
+    dst = (SCRLEFT(*(psrc), (x)) & cfbendtab[m]) | \
+         (SCRRIGHT(*((psrc)+1), m) & cfbstarttab[m]); \
+}
+
+
+#define putbits(src, x, w, pdst, planemask) \
+if ( ((x)+(w)) <= PPW) \
+{ \
+    PixelGroup tmpmask; \
+    maskpartialbits((x), (w), tmpmask); \
+    tmpmask &= PFILL(planemask); \
+    *(pdst) = (*(pdst) & ~tmpmask) | (SCRRIGHT(src, x) & tmpmask); \
+} \
+else \
+{ \
+    unsigned long m; \
+    unsigned long n; \
+    PixelGroup pm = PFILL(planemask); \
+    m = PPW-(x); \
+    n = (w) - m; \
+    *(pdst) = (*(pdst) & (cfbendtab[x] | ~pm)) | \
+       (SCRRIGHT(src, x) & (cfbstarttab[x] & pm)); \
+    *((pdst)+1) = (*((pdst)+1) & (cfbstarttab[n] | ~pm)) | \
+       (SCRLEFT(src, m) & (cfbendtab[n] & pm)); \
+}
+#if defined(__GNUC__) && defined(mc68020)
+#undef getbits
+#define FASTGETBITS(psrc, x, w, dst) \
+    asm ("bfextu %3{%1:%2},%0" \
+        : "=d" (dst) : "di" (x), "di" (w), "o" (*(char *)(psrc)))
+
+#define getbits(psrc,x,w,dst) \
+{ \
+    FASTGETBITS(psrc, (x) * PSZ, (w) * PSZ, dst); \
+    dst = SCRLEFT(dst,PPW-(w)); \
+}
+
+#define FASTPUTBITS(src, x, w, pdst) \
+    asm ("bfins %3,%0{%1:%2}" \
+        : "=o" (*(char *)(pdst)) \
+        : "di" (x), "di" (w), "d" (src), "0" (*(char *) (pdst)))
+
+#undef putbits
+#define putbits(src, x, w, pdst, planemask) \
+{ \
+    if (planemask != PMSK) { \
+        PixelGroup _m, _pm; \
+        FASTGETBITS(pdst, (x) * PSZ , (w) * PSZ, _m); \
+        PFILL2(planemask, _pm); \
+        _m &= (~_pm); \
+        _m |= (SCRRIGHT(src, PPW-(w)) & _pm); \
+        FASTPUTBITS(_m, (x) * PSZ, (w) * PSZ, pdst); \
+    } else { \
+        FASTPUTBITS(SCRRIGHT(src, PPW-(w)), (x) * PSZ, (w) * PSZ, pdst); \
+    } \
+}
+    
+
+#endif /* mc68020 */
+
+#define putbitsrop(src, x, w, pdst, planemask, rop) \
+if ( ((x)+(w)) <= PPW) \
+{ \
+    PixelGroup tmpmask; \
+    PixelGroup t1, t2; \
+    maskpartialbits((x), (w), tmpmask); \
+    PFILL2(planemask, t1); \
+    tmpmask &= t1; \
+    t1 = SCRRIGHT((src), (x)); \
+    DoRop(t2, rop, t1, *(pdst)); \
+    *(pdst) = (*(pdst) & ~tmpmask) | (t2 & tmpmask); \
+} \
+else \
+{ \
+    unsigned long m; \
+    unsigned long n; \
+    PixelGroup t1, t2; \
+    PixelGroup pm; \
+    PFILL2(planemask, pm); \
+    m = PPW-(x); \
+    n = (w) - m; \
+    t1 = SCRRIGHT((src), (x)); \
+    DoRop(t2, rop, t1, *(pdst)); \
+    *(pdst) = (*(pdst) & (cfbendtab[x] | ~pm)) | (t2 & (cfbstarttab[x] & pm));\
+    t1 = SCRLEFT((src), m); \
+    DoRop(t2, rop, t1, *((pdst) + 1)); \
+    *((pdst)+1) = (*((pdst)+1) & (cfbstarttab[n] | ~pm)) | \
+       (t2 & (cfbendtab[n] & pm)); \
+}
+
+#else /* PSZ == 32 && PPW == 1*/
+
+/*
+ * These macros can be optimized for 32-bit pixels since there is no
+ * need to worry about left/right edge masking.  These macros were
+ * derived from the above using the following reductions:
+ *
+ *     - x & PIW = 0   [since PIW = 0]
+ *     - all masking tables are only indexed by 0  [ due to above ]
+ *     - cfbstartab[0] and cfbendtab[0] = 0    [ no left/right edge masks]
+ *    - cfbstartpartial[0] and cfbendpartial[0] = ~0 [no partial pixel mask]
+ *
+ * Macro reduction based upon constants cannot be performed automatically
+ *       by the compiler since it does not know the contents of the masking
+ *       arrays in cfbmskbits.c.
+ */
+#define maskbits(x, w, startmask, endmask, nlw) \
+    startmask = endmask = 0; \
+    nlw = (w);
+
+#define maskpartialbits(x, w, mask) \
+    mask = 0xFFFFFFFF;
+
+#define mask32bits(x, w, startmask, endmask) \
+    startmask = endmask = 0;
+
+/*
+ * For 32-bit operations, getbits(), putbits(), and putbitsrop() 
+ * will only be invoked with x = 0 and w = PPW (1).  The getbits() 
+ * macro is only called within left/right edge logic, which doesn't
+ * happen for 32-bit pixels.
+ */
+#define getbits(psrc, x, w, dst) (dst) = *(psrc)
+
+#define putbits(src, x, w, pdst, planemask) \
+    *(pdst) = (*(pdst) & ~planemask) | (src & planemask);
+
+#define putbitsrop(src, x, w, pdst, planemask, rop) \
+{ \
+    PixelGroup t1; \
+    DoRop(t1, rop, (src), *(pdst)); \
+    *(pdst) = (*(pdst) & ~planemask) | (t1 & planemask); \
+}
+
+#endif /* PSZ != 32 */
+
+/*
+ * Use these macros only when you're using the MergeRop stuff
+ * in ../mfb/mergerop.h
+ */
+
+/* useful only when not spanning destination longwords */
+#if PSZ == 24
+#define putbitsmropshort24(src,x,w,pdst,index) {\
+    PixelGroup   _tmpmask; \
+    PixelGroup   _t1; \
+    maskpartialbits ((x), (w), _tmpmask); \
+    _t1 = SCRRIGHT((src), (x)); \
+    DoMaskMergeRop24(_t1, pdst, _tmpmask, index); \
+}
+#endif
+#define putbitsmropshort(src,x,w,pdst) {\
+    PixelGroup   _tmpmask; \
+    PixelGroup   _t1; \
+    maskpartialbits ((x), (w), _tmpmask); \
+    _t1 = SCRRIGHT((src), (x)); \
+    *pdst = DoMaskMergeRop(_t1, *pdst, _tmpmask); \
+}
+
+/* useful only when spanning destination longwords */
+#define putbitsmroplong(src,x,w,pdst) { \
+    PixelGroup   _startmask, _endmask; \
+    int                    _m; \
+    PixelGroup   _t1; \
+    _m = PPW - (x); \
+    _startmask = cfbstarttab[x]; \
+    _endmask = cfbendtab[(w) - _m]; \
+    _t1 = SCRRIGHT((src), (x)); \
+    pdst[0] = DoMaskMergeRop(_t1,pdst[0],_startmask); \
+    _t1 = SCRLEFT ((src),_m); \
+    pdst[1] = DoMaskMergeRop(_t1,pdst[1],_endmask); \
+}
+
+#define putbitsmrop(src,x,w,pdst) \
+if ((x) + (w) <= PPW) {\
+    putbitsmropshort(src,x,w,pdst); \
+} else { \
+    putbitsmroplong(src,x,w,pdst); \
+}
+
+#if GETLEFTBITS_ALIGNMENT == 1
+#define getleftbits(psrc, w, dst)      dst = *((unsigned int *) psrc)
+#define getleftbits24(psrc, w, dst, idx){      \
+       regiseter int index; \
+       switch(index = ((idx)&3)<<1){ \
+       case 0: \
+       dst = (*((unsigned int *) psrc))&cfbmask[index]; \
+       break; \
+       case 2: \
+       case 4: \
+       dst = BitLeft(((*((unsigned int *) psrc))&cfbmask[index]), cfb24Shift[index]); \
+       dst |= BitRight(((*((unsigned int *) psrc)+1)&cfbmask[index]), cfb4Shift[index]); \
+       break; \
+       case 6: \
+       dst = BitLeft((*((unsigned int *) psrc)),cfb24Shift[index]); \
+       break; \
+       }; \
+}
+#endif /* GETLEFTBITS_ALIGNMENT == 1 */
+
+#define getglyphbits(psrc, x, w, dst) \
+{ \
+    dst = BitLeft((unsigned) *(psrc), (x)); \
+    if ( ((x) + (w)) > 32) \
+       dst |= (BitRight((unsigned) *((psrc)+1), 32-(x))); \
+}
+#if GETLEFTBITS_ALIGNMENT == 2
+#define getleftbits(psrc, w, dst) \
+    { \
+       if ( ((int)(psrc)) & 0x01 ) \
+               getglyphbits( ((unsigned int *)(((char *)(psrc))-1)), 8, (w), (dst) ); \
+       else \
+               dst = *((unsigned int *) psrc); \
+    }
+#endif /* GETLEFTBITS_ALIGNMENT == 2 */
+
+#if GETLEFTBITS_ALIGNMENT == 4
+#define getleftbits(psrc, w, dst) \
+    { \
+       int off, off_b; \
+       off_b = (off = ( ((int)(psrc)) & 0x03)) << 3; \
+       getglyphbits( \
+               (unsigned int *)( ((char *)(psrc)) - off), \
+               (off_b), (w), (dst) \
+              ); \
+    }
+#endif /* GETLEFTBITS_ALIGNMENT == 4 */
+
+/*
+ * getstipplepixels( psrcstip, x, w, ones, psrcpix, destpix )
+ *
+ * Converts bits to pixels in a reasonable way.  Takes w (1 <= w <= PPW)
+ * bits from *psrcstip, starting at bit x; call this a quartet of bits.
+ * Then, takes the pixels from *psrcpix corresponding to the one-bits (if
+ * ones is TRUE) or the zero-bits (if ones is FALSE) of the quartet
+ * and puts these pixels into destpix.
+ *
+ * Example:
+ *
+ *      getstipplepixels( &(0x08192A3B), 17, 4, 1, &(0x4C5D6E7F), dest )
+ *
+ * 0x08192A3B = 0000 1000 0001 1001 0010 1010 0011 1011
+ *
+ * This will take 4 bits starting at bit 17, so the quartet is 0x5 = 0101.
+ * It will take pixels from 0x4C5D6E7F corresponding to the one-bits in this
+ * quartet, so dest = 0x005D007F.
+ *
+ * XXX Works with both byte order.
+ * XXX This works for all values of x and w within a doubleword.
+ */
+#if (BITMAP_BIT_ORDER == MSBFirst)
+#define getstipplepixels( psrcstip, x, w, ones, psrcpix, destpix ) \
+{ \
+    PixelGroup q; \
+    int m; \
+    if ((m = ((x) - ((PPW*PSZ)-PPW))) > 0) { \
+        q = (*(psrcstip)) << m; \
+       if ( (x)+(w) > (PPW*PSZ) ) \
+           q |= *((psrcstip)+1) >> ((PPW*PSZ)-m); \
+    } \
+    else \
+        q = (*(psrcstip)) >> -m; \
+    q = QuartetBitsTable[(w)] & ((ones) ? q : ~q); \
+    *(destpix) = (*(psrcpix)) & QuartetPixelMaskTable[q]; \
+}
+#else /* BITMAP_BIT_ORDER == LSB */
+
+/*================================================================
+   BEGIN ORL VNC modification
+   Only use ldq_u on XFREE86 platforms */
+
+#ifdef XFREE86
+#define getstipplepixels( psrcstip, xt, w, ones, psrcpix, destpix ) \
+{ \
+    PixelGroup q; \
+    q = ldq_u(psrcstip) >> (xt); \
+    if ( ((xt)+(w)) > (PPW*PSZ) ) \
+        q |= (ldq_u((psrcstip)+1)) << ((PPW*PSZ)-(xt)); \
+    q = QuartetBitsTable[(w)] & ((ones) ? q : ~q); \
+    *(destpix) = (*(psrcpix)) & QuartetPixelMaskTable[q]; \
+}
+#else /* XFREE86 */
+#define getstipplepixels( psrcstip, xt, w, ones, psrcpix, destpix ) \
+{ \
+    PixelGroup q; \
+    q = *(psrcstip) >> (xt); \
+    if ( ((xt)+(w)) > (PPW*PSZ) ) \
+        q |= (*((psrcstip)+1)) << ((PPW*PSZ)-(xt)); \
+    q = QuartetBitsTable[(w)] & ((ones) ? q : ~q); \
+    *(destpix) = (*(psrcpix)) & QuartetPixelMaskTable[q]; \
+}
+#endif /* XFREE86 */
+
+/* END ORL VNC modification
+================================================================*/
+
+#if PSZ == 24
+# if 0
+#define getstipplepixels24( psrcstip,xt,w,ones,psrcpix,destpix,stipindex,srcindex,dstindex) \
+{ \
+    PixelGroup q, srcpix, srcstip; \
+    unsigned long src; \
+    register unsigned int sidx; \
+    register unsigned int didx; \
+    register unsigned int stipidx; \
+    sidx = ((srcindex) & 3)<<1; \
+    didx = ((dstindex) & 3)<<1; \
+    q = *(psrcstip) >> (xt); \
+/*    if((srcindex)!=0)*/ \
+/*    src = (((*(psrcpix)) << cfb24Shift[sidx]) & (cfbmask[sidx])) |*/ \
+/*     (((*((psrcpix)+1)) << cfb24Shift[sidx+1]) & (cfbmask[sidx+1])); */\
+/*    else */\
+       src = (*(psrcpix))&0xFFFFFF; \
+    if ( ((xt)+(w)) > PGSZ ) \
+        q |= (*((psrcstip)+1)) << (PGSZ -(xt)); \
+    q = QuartetBitsTable[(w)] & ((ones) ? q : ~q); \
+    src &= QuartetPixelMaskTable[q]; \
+    *(destpix) &= cfbrmask[didx]; \
+    switch(didx) {\
+       case 0: \
+               *(destpix) |= (src &cfbmask[didx]); \
+               break; \
+       case 2: \
+       case 4: \
+               destpix++;didx++; \
+               *(destpix) = ((*(destpix)) & (cfbrmask[didx]))| \
+                       (BitLeft(src, cfb24Shift[didx]) & (cfbmask[didx])); \
+               destpix--; didx--;\
+       case 6: \
+               *(destpix) |= (BitRight(src, cfb24Shift[didx]) & cfbmask[didx]); \
+               break; \
+       }; \
+}
+# else
+#define getstipplepixels24(psrcstip,xt,ones,psrcpix,destpix,stipindex) \
+{ \
+    PixelGroup q, srcpix, srcstip; \
+    unsigned long src; \
+    register unsigned int stipidx; \
+    q = *(psrcstip) >> (xt); \
+    q = ((ones) ? q : ~q) & 1; \
+    *(destpix) = (*(psrcpix)) & QuartetPixelMaskTable[q]; \
+}
+# endif
+#endif /* PSZ == 24 */
+#endif
+
+extern PixelGroup cfbstarttab[];
+extern PixelGroup cfbendtab[];
+extern PixelGroup cfbstartpartial[];
+extern PixelGroup cfbendpartial[];
+extern PixelGroup cfbrmask[];
+extern PixelGroup cfbmask[];
+extern PixelGroup QuartetBitsTable[];
+extern PixelGroup QuartetPixelMaskTable[];
+#if PSZ == 24
+extern int cfb24Shift[];
+#endif
diff --git a/Xserver/programs/Xserver/cfb/cfbpixmap.c b/Xserver/programs/Xserver/cfb/cfbpixmap.c
new file mode 100644 (file)
index 0000000..951f583
--- /dev/null
@@ -0,0 +1,371 @@
+/* $XConsortium: cfbpixmap.c,v 5.14 94/04/17 20:28:56 dpw Exp $ */
+/***********************************************************
+
+Copyright (c) 1987  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+
+Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
+
+                        All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and its 
+documentation for any purpose and without fee is hereby granted, 
+provided that the above copyright notice appear in all copies and that
+both that copyright notice and this permission notice appear in 
+supporting documentation, and that the name of Digital not be
+used in advertising or publicity pertaining to distribution of the
+software without specific, written prior permission.  
+
+DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
+ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
+DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
+ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+SOFTWARE.
+
+******************************************************************/
+/* pixmap management
+   written by drewry, september 1986
+
+   on a monchrome device, a pixmap is a bitmap.
+*/
+
+#include "Xmd.h"
+#include "servermd.h"
+#include "scrnintstr.h"
+#include "pixmapstr.h"
+#include "mi.h"
+#include "cfb.h"
+#include "cfbmskbits.h"
+
+extern unsigned long endtab[];
+
+PixmapPtr
+cfbCreatePixmap (pScreen, width, height, depth)
+    ScreenPtr  pScreen;
+    int                width;
+    int                height;
+    int                depth;
+{
+    PixmapPtr pPixmap;
+    int datasize;
+    int paddedWidth;
+
+    paddedWidth = PixmapBytePad(width, depth);
+    datasize = height * paddedWidth;
+    pPixmap = AllocatePixmap(pScreen, datasize);
+    if (!pPixmap)
+       return NullPixmap;
+    pPixmap->drawable.type = DRAWABLE_PIXMAP;
+    pPixmap->drawable.class = 0;
+    pPixmap->drawable.pScreen = pScreen;
+    pPixmap->drawable.depth = depth;
+    pPixmap->drawable.bitsPerPixel = BitsPerPixel(depth);
+    pPixmap->drawable.id = 0;
+    pPixmap->drawable.serialNumber = NEXT_SERIAL_NUMBER;
+    pPixmap->drawable.x = 0;
+    pPixmap->drawable.y = 0;
+    pPixmap->drawable.width = width;
+    pPixmap->drawable.height = height;
+    pPixmap->devKind = paddedWidth;
+    pPixmap->refcnt = 1;
+#ifdef PIXPRIV
+    pPixmap->devPrivate.ptr = datasize ?
+               (pointer)((char *)pPixmap + pScreen->totalPixmapSize) : NULL;
+#else
+    pPixmap->devPrivate.ptr = (pointer)(pPixmap + 1);
+#endif
+    return pPixmap;
+}
+
+Bool
+cfbDestroyPixmap(pPixmap)
+    PixmapPtr pPixmap;
+{
+    if(--pPixmap->refcnt)
+       return TRUE;
+    xfree(pPixmap);
+    return TRUE;
+}
+
+PixmapPtr
+cfbCopyPixmap(pSrc)
+    register PixmapPtr pSrc;
+{
+    register PixmapPtr pDst;
+    int                size;
+    ScreenPtr pScreen;
+
+    size = pSrc->drawable.height * pSrc->devKind;
+    pScreen = pSrc->drawable.pScreen;
+    pDst = (*pScreen->CreatePixmap) (pScreen, pSrc->drawable.width, 
+                               pSrc->drawable.height, pSrc->drawable.depth);
+    if (!pDst)
+       return NullPixmap;
+    memmove((char *)pDst->devPrivate.ptr, (char *)pSrc->devPrivate.ptr, size);
+    return pDst;
+}
+
+
+/* replicates a pattern to be a full 32 bits wide.
+   relies on the fact that each scnaline is longword padded.
+   doesn't do anything if pixmap is not a factor of 32 wide.
+   changes width field of pixmap if successful, so that the fast
+       cfbXRotatePixmap code gets used if we rotate the pixmap later.
+       cfbYRotatePixmap code gets used if we rotate the pixmap later.
+
+   calculate number of times to repeat
+   for each scanline of pattern
+      zero out area to be filled with replicate
+      left shift and or in original as many times as needed
+*/
+void
+cfbPadPixmap(pPixmap)
+    PixmapPtr pPixmap;
+{
+    register int width = (pPixmap->drawable.width) * (pPixmap->drawable.bitsPerPixel);
+    register int h;
+    register unsigned long mask;
+    register unsigned long *p;
+    register unsigned long bits; /* real pattern bits */
+    register int i;
+    int rep;                    /* repeat count for pattern */
+    if (width >= PGSZ)
+        return;
+
+    rep = PGSZ/width;
+    if (rep*width != PGSZ)
+        return;
+    mask = endtab[width];
+    p = (unsigned long *)(pPixmap->devPrivate.ptr);
+    for (h=0; h < pPixmap->drawable.height; h++)
+    {
+        *p &= mask;
+        bits = *p;
+        for(i=1; i<rep; i++)
+        {
+#if (BITMAP_BIT_ORDER == MSBFirst) 
+            bits >>= width;
+#else
+           bits <<= width;
+#endif
+            *p |= bits;
+        }
+        p++;
+    }    
+    pPixmap->drawable.width = PGSZ/(pPixmap->drawable.bitsPerPixel);
+}
+
+
+#ifdef notdef
+/*
+ * cfb debugging routine -- assumes pixmap is 1 byte deep 
+ */
+static cfbdumppixmap(pPix)
+    PixmapPtr  pPix;
+{
+    unsigned int *pw;
+    char *psrc, *pdst;
+    int        i, j;
+    char       line[66];
+
+    ErrorF(  "pPixmap: 0x%x\n", pPix);
+    ErrorF(  "%d wide %d high\n", pPix->drawable.width, pPix->drawable.height);
+    if (pPix->drawable.width > 64)
+    {
+       ErrorF(  "too wide to see\n");
+       return;
+    }
+
+    pw = (unsigned int *) pPix->devPrivate.ptr;
+    psrc = (char *) pw;
+
+/*
+    for ( i=0; i<pPix->drawable.height; ++i )
+       ErrorF( "0x%x\n", pw[i] );
+*/
+
+    for ( i = 0; i < pPix->drawable.height; ++i ) {
+       pdst = line;
+       for(j = 0; j < pPix->drawable.width; j++) {
+           *pdst++ = *psrc++ ? 'X' : ' ' ;
+       }
+       *pdst++ = '\n';
+       *pdst++ = '\0';
+       ErrorF( "%s", line);
+    }
+}
+#endif /* notdef */
+
+/* Rotates pixmap pPix by w pixels to the right on the screen. Assumes that
+ * words are PGSZ bits wide, and that the least significant bit appears on the
+ * left.
+ */
+void
+cfbXRotatePixmap(pPix, rw)
+    PixmapPtr  pPix;
+    register int rw;
+{
+    register unsigned long     *pw, *pwFinal;
+    register unsigned long     t;
+    int                                rot;
+
+    if (pPix == NullPixmap)
+        return;
+
+    switch (((DrawablePtr) pPix)->bitsPerPixel) {
+       case PSZ:
+           break;
+       case 1:
+           mfbXRotatePixmap(pPix, rw);
+           return;
+       default:
+           ErrorF("cfbXRotatePixmap: unsupported bitsPerPixel %d\n", ((DrawablePtr) pPix)->bitsPerPixel);
+           return;
+    }
+    pw = (unsigned long *)pPix->devPrivate.ptr;
+    modulus (rw, (int) pPix->drawable.width, rot);
+    if(pPix->drawable.width == PPW)
+    {
+        pwFinal = pw + pPix->drawable.height;
+       while(pw < pwFinal)
+       {
+           t = *pw;
+           *pw++ = SCRRIGHT(t, rot) |
+                   (SCRLEFT(t, (PPW-rot)) & cfbendtab[rot]);
+       }
+    }
+    else
+    {
+        ErrorF("cfb internal error: trying to rotate odd-sized pixmap.\n");
+#ifdef notdef
+       register unsigned long *pwTmp;
+       int size, tsize;
+
+       tsize = PixmapBytePad(pPix->drawable.width - rot, pPix->drawable.depth);
+       pwTmp = (unsigned long *) ALLOCATE_LOCAL(pPix->drawable.height * tsize);
+       if (!pwTmp)
+           return;
+       /* divide pw (the pixmap) in two vertically at (w - rot) and swap */
+       tsize >>= 2;
+       size = pPix->devKind >> SIZE0F(PixelGroup);
+       cfbQuickBlt((long *)pw, (long *)pwTmp,
+                   0, 0, 0, 0,
+                   (int)pPix->drawable.width - rot, (int)pPix->drawable.height,
+                   size, tsize);
+       cfbQuickBlt((long *)pw, (long *)pw,
+                   (int)pPix->drawable.width - rot, 0, 0, 0,
+                   rot, (int)pPix->drawable.height,
+                   size, size);
+       cfbQuickBlt((long *)pwTmp, (long *)pw,
+                   0, 0, rot, 0,
+                   (int)pPix->drawable.width - rot, (int)pPix->drawable.height,
+                   tsize, size);
+       DEALLOCATE_LOCAL(pwTmp);
+#endif
+    }
+}
+
+/* Rotates pixmap pPix by h lines.  Assumes that h is always less than
+   pPix->drawable.height
+   works on any width.
+ */
+void
+cfbYRotatePixmap(pPix, rh)
+    register PixmapPtr pPix;
+    int        rh;
+{
+    int nbyDown;       /* bytes to move down to row 0; also offset of
+                          row rh */
+    int nbyUp;         /* bytes to move up to line rh; also
+                          offset of first line moved down to 0 */
+    char *pbase;
+    char *ptmp;
+    int        rot;
+
+    if (pPix == NullPixmap)
+       return;
+    switch (((DrawablePtr) pPix)->bitsPerPixel) {
+       case PSZ:
+           break;
+       case 1:
+           mfbYRotatePixmap(pPix, rh);
+           return;
+       default:
+           ErrorF("cfbYRotatePixmap: unsupported bitsPerPixel %d\n", ((DrawablePtr) pPix)->bitsPerPixel);
+           return;
+    }
+
+    modulus (rh, (int) pPix->drawable.height, rot);
+    pbase = (char *)pPix->devPrivate.ptr;
+
+    nbyDown = rot * pPix->devKind;
+    nbyUp = (pPix->devKind * pPix->drawable.height) - nbyDown;
+    if(!(ptmp = (char *)ALLOCATE_LOCAL(nbyUp)))
+       return;
+
+    memmove(ptmp, pbase, nbyUp);               /* save the low rows */
+    memmove(pbase, pbase+nbyUp, nbyDown);      /* slide the top rows down */
+    memmove(pbase+nbyDown, ptmp, nbyUp);       /* move lower rows up to row rot */
+    DEALLOCATE_LOCAL(ptmp);
+}
+
+void
+cfbCopyRotatePixmap(psrcPix, ppdstPix, xrot, yrot)
+    register PixmapPtr psrcPix, *ppdstPix;
+    int        xrot, yrot;
+{
+    register PixmapPtr pdstPix;
+
+    if ((pdstPix = *ppdstPix) &&
+       (pdstPix->devKind == psrcPix->devKind) &&
+       (pdstPix->drawable.height == psrcPix->drawable.height))
+    {
+       memmove((char *)pdstPix->devPrivate.ptr,
+               (char *)psrcPix->devPrivate.ptr,
+             psrcPix->drawable.height * psrcPix->devKind);
+       pdstPix->drawable.width = psrcPix->drawable.width;
+       pdstPix->drawable.depth = psrcPix->drawable.depth;
+       pdstPix->drawable.bitsPerPixel = psrcPix->drawable.bitsPerPixel;
+       pdstPix->drawable.serialNumber = NEXT_SERIAL_NUMBER;
+    }
+    else
+    {
+       if (pdstPix)
+           /* FIX XBUG 6168 */
+           (*pdstPix->drawable.pScreen->DestroyPixmap)(pdstPix);
+       *ppdstPix = pdstPix = cfbCopyPixmap(psrcPix);
+       if (!pdstPix)
+           return;
+    }
+    cfbPadPixmap(pdstPix);
+    if (xrot)
+       cfbXRotatePixmap(pdstPix, xrot);
+    if (yrot)
+       cfbYRotatePixmap(pdstPix, yrot);
+}
diff --git a/Xserver/programs/Xserver/cfb/cfbply1rct.c b/Xserver/programs/Xserver/cfb/cfbply1rct.c
new file mode 100644 (file)
index 0000000..56eccf3
--- /dev/null
@@ -0,0 +1,352 @@
+/*
+ * $XConsortium: cfbply1rct.c /main/16 1996/08/12 22:07:31 dpw $
+ * $XFree86: xc/programs/Xserver/cfb/cfbply1rct.c,v 3.3 1996/12/23 06:29:21 dawes Exp $
+ *
+Copyright (c) 1990  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+ *
+ * Author:  Keith Packard, MIT X Consortium
+ */
+
+#include "X.h"
+
+#include "gcstruct.h"
+#include "windowstr.h"
+#include "pixmapstr.h"
+#include "regionstr.h"
+#include "scrnintstr.h"
+#include "mistruct.h"
+
+#include "cfb.h"
+#include "cfbmskbits.h"
+#include "cfbrrop.h"
+
+void
+RROP_NAME(cfbFillPoly1Rect) (pDrawable, pGC, shape, mode, count, ptsIn)
+    DrawablePtr        pDrawable;
+    GCPtr      pGC;
+    int                shape;
+    int                mode;
+    int                count;
+    DDXPointPtr        ptsIn;
+{
+    cfbPrivGCPtr    devPriv;
+    int                    nwidth;
+    unsigned long   *addrl, *addr;
+#if PSZ == 24
+    unsigned long startmask, endmask;
+    register int pidx;
+#endif
+    int                    maxy;
+    int                    origin;
+    register int    vertex1, vertex2;
+    int                    c;
+    BoxPtr         extents;
+    int                    clip;
+    int                    y;
+    int                    *vertex1p, *vertex2p;
+    int                    *endp;
+    int                    x1, x2;
+    int                    dx1, dx2;
+    int                    dy1, dy2;
+    int                    e1, e2;
+    int                    step1, step2;
+    int                    sign1, sign2;
+    int                    h;
+    int                    l, r;
+    unsigned long   mask, bits = ~((unsigned long)0);
+    int                    nmiddle;
+    RROP_DECLARE
+
+    if (mode == CoordModePrevious)
+    {
+       miFillPolygon (pDrawable, pGC, shape, mode, count, ptsIn);
+       return;
+    }
+    
+    devPriv = cfbGetGCPrivate(pGC);
+#ifdef NO_ONE_RECT
+    if (REGION_NUM_RECTS(devPriv->pCompositeClip) != 1)
+    {
+       miFillPolygon (pDrawable, pGC, shape, mode, count, ptsIn);
+       return;
+    }
+#endif
+    origin = *((int *) &pDrawable->x);
+    vertex2 = origin - ((origin & 0x8000) << 1);
+    extents = &devPriv->pCompositeClip->extents;
+    RROP_FETCH_GCPRIV(devPriv);
+    vertex1 = *((int *) &extents->x1) - vertex2;
+    vertex2 = *((int *) &extents->x2) - vertex2 - 0x00010001;
+    clip = 0;
+    y = 32767;
+    maxy = 0;
+    vertex2p = (int *) ptsIn;
+    endp = vertex2p + count;
+    if (shape == Convex)
+    {
+       while (count--)
+       {
+           c = *vertex2p;
+           clip |= (c - vertex1) | (vertex2 - c);
+           c = intToY(c);
+           if (c < y) 
+           {
+               y = c;
+               vertex1p = vertex2p;
+           }
+           vertex2p++;
+           if (c > maxy)
+               maxy = c;
+       }
+    }
+    else
+    {
+       int yFlip = 0;
+       dx1 = 1;
+       x2 = -1;
+       x1 = -1;
+       while (count--)
+       {
+           c = *vertex2p;
+           clip |= (c - vertex1) | (vertex2 - c);
+           c = intToY(c);
+           if (c < y) 
+           {
+               y = c;
+               vertex1p = vertex2p;
+           }
+           vertex2p++;
+           if (c > maxy)
+               maxy = c;
+           if (c == x1)
+               continue;
+           if (dx1 > 0)
+           {
+               if (x2 < 0)
+                   x2 = c;
+               else
+                   dx2 = dx1 = (c - x1) >> 31;
+           }
+           else
+               if ((c - x1) >> 31 != dx1) 
+               {
+                   dx1 = ~dx1;
+                   yFlip++;
+               }
+           x1 = c;
+               }
+       x1 = (x2 - c) >> 31;
+       if (x1 != dx1)
+           yFlip++;
+       if (x1 != dx2)
+           yFlip++;
+       if (yFlip != 2) 
+           clip = 0x8000;
+    }
+    if (y == maxy)
+       return;
+
+    if (clip & 0x80008000)
+    {
+       miFillPolygon (pDrawable, pGC, shape, mode, vertex2p - (int *) ptsIn, ptsIn);
+       return;
+    }
+
+#define AddrYPlus(a,y)  (unsigned long *) (((unsigned char *) (a)) + (y) * nwidth)
+
+    cfbGetTypedWidthAndPointer(pDrawable, nwidth, addrl, unsigned char, unsigned long);
+    addrl = AddrYPlus(addrl,y + pDrawable->y);
+    origin = intToX(origin);
+    vertex2p = vertex1p;
+    vertex2 = vertex1 = *vertex2p++;
+    if (vertex2p == endp)
+       vertex2p = (int *) ptsIn;
+#define Setup(c,x,vertex,dx,dy,e,sign,step) {\
+    x = intToX(vertex); \
+    if (dy = intToY(c) - y) { \
+       dx = intToX(c) - x; \
+       step = 0; \
+       if (dx >= 0) \
+       { \
+           e = 0; \
+           sign = 1; \
+           if (dx >= dy) {\
+               step = dx / dy; \
+               dx = dx % dy; \
+           } \
+       } \
+       else \
+       { \
+           e = 1 - dy; \
+           sign = -1; \
+           dx = -dx; \
+           if (dx >= dy) { \
+               step = - (dx / dy); \
+               dx = dx % dy; \
+           } \
+       } \
+    } \
+    x += origin; \
+    vertex = c; \
+}
+
+#define Step(x,dx,dy,e,sign,step) {\
+    x += step; \
+    if ((e += dx) > 0) \
+    { \
+       x += sign; \
+       e -= dy; \
+    } \
+}
+    for (;;)
+    {
+       if (y == intToY(vertex1))
+       {
+           do
+           {
+               if (vertex1p == (int *) ptsIn)
+                   vertex1p = endp;
+               c = *--vertex1p;
+               Setup (c,x1,vertex1,dx1,dy1,e1,sign1,step1)
+           } while (y >= intToY(vertex1));
+           h = dy1;
+       }
+       else
+       {
+           Step(x1,dx1,dy1,e1,sign1,step1)
+           h = intToY(vertex1) - y;
+       }
+       if (y == intToY(vertex2))
+       {
+           do
+           {
+               c = *vertex2p++;
+               if (vertex2p == endp)
+                   vertex2p = (int *) ptsIn;
+               Setup (c,x2,vertex2,dx2,dy2,e2,sign2,step2)
+           } while (y >= intToY(vertex2));
+           if (dy2 < h)
+               h = dy2;
+       }
+       else
+       {
+           Step(x2,dx2,dy2,e2,sign2,step2)
+           if ((c = (intToY(vertex2) - y)) < h)
+               h = c;
+       }
+       /* fill spans for this segment */
+       y += h;
+       for (;;)
+       {
+           l = x1;
+           r = x2;
+           nmiddle = x2 - x1;
+           if (nmiddle < 0)
+           {
+               nmiddle = -nmiddle;
+               l = x2;
+               r = x1;
+           }
+#if PPW > 1
+           c = l & PIM;
+           l -= c;
+#endif
+
+#if PGSZ == 32
+#define LWRD_SHIFT 2
+#else /* PGSZ == 64 */
+#define LWRD_SHIFT 3
+#endif /* PGSZ */
+
+#if PSZ == 24
+           addr = (unsigned long *)((char *)addrl + ((l * 3) & ~0x03));
+#else /* PSZ == 24 */
+#if PWSH > LWRD_SHIFT
+           l = l >> (PWSH - LWRD_SHIFT);
+#endif
+#if PWSH < LWRD_SHIFT
+           l = l << (LWRD_SHIFT - PWSH);
+#endif
+           addr = (unsigned long *) (((char *) addrl) + l);
+#endif /* PSZ == 24 */
+#if PSZ == 24
+           if (nmiddle <= 1){
+             if (nmiddle)
+               RROP_SOLID24(addr, l);
+           } else {
+             maskbits(l, nmiddle, startmask, endmask, nmiddle);
+             pidx = l & 3;
+             if (startmask){
+               RROP_SOLID_MASK(addr, startmask, pidx-1);
+               addr++;
+               if (pidx == 3)
+                 pidx = 0;
+             }
+             while (--nmiddle >= 0){
+               RROP_SOLID(addr, pidx);
+               addr++;
+               if (++pidx == 3)
+                 pidx = 0;
+             }
+             if (endmask)
+               RROP_SOLID_MASK(addr, endmask, pidx);
+           }
+#else /* PSZ == 24 */
+#if PPW > 1
+           if (c + nmiddle < PPW)
+           {
+               mask = SCRRIGHT (bits,c) ^ SCRRIGHT (bits,c+nmiddle);
+               RROP_SOLID_MASK(addr,mask);
+           }
+           else
+           {
+               if (c)
+               {
+                   mask = SCRRIGHT(bits, c);
+                   RROP_SOLID_MASK(addr,mask);
+                   nmiddle += c - PPW;
+                   addr++;
+               }
+#endif
+               nmiddle >>= PWSH;
+               while (--nmiddle >= 0) {
+                   RROP_SOLID(addr); addr++;
+               }
+#if PPW > 1
+               if (mask = ~SCRRIGHT(bits, r & PIM))
+                   RROP_SOLID_MASK(addr,mask);
+           }
+#endif
+#endif /* PSZ == 24 */
+           if (!--h)
+               break;
+           addrl = AddrYPlus (addrl, 1);
+           Step(x1,dx1,dy1,e1,sign1,step1)
+           Step(x2,dx2,dy2,e2,sign2,step2)
+       }
+       if (y == maxy)
+           break;
+       addrl = AddrYPlus (addrl, 1);
+    }
+}
diff --git a/Xserver/programs/Xserver/cfb/cfbpntwin.c b/Xserver/programs/Xserver/cfb/cfbpntwin.c
new file mode 100644 (file)
index 0000000..f1ef5a3
--- /dev/null
@@ -0,0 +1,708 @@
+/* $XConsortium: cfbpntwin.c,v 5.18 94/04/17 20:28:57 dpw Exp $ */
+/* $XFree86: xc/programs/Xserver/cfb/cfbpntwin.c,v 3.0 1996/06/29 09:05:45 dawes Exp $ */
+/***********************************************************
+
+Copyright (c) 1987  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+
+Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
+
+                        All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and its 
+documentation for any purpose and without fee is hereby granted, 
+provided that the above copyright notice appear in all copies and that
+both that copyright notice and this permission notice appear in 
+supporting documentation, and that the name of Digital not be
+used in advertising or publicity pertaining to distribution of the
+software without specific, written prior permission.  
+
+DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
+ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
+DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
+ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+SOFTWARE.
+
+******************************************************************/
+
+#include "X.h"
+
+#include "windowstr.h"
+#include "regionstr.h"
+#include "pixmapstr.h"
+#include "scrnintstr.h"
+
+#include "cfb.h"
+#include "cfbmskbits.h"
+#include "mi.h"
+
+void
+cfbPaintWindow(pWin, pRegion, what)
+    WindowPtr  pWin;
+    RegionPtr  pRegion;
+    int                what;
+{
+    register cfbPrivWin        *pPrivWin;
+    WindowPtr  pBgWin;
+
+    pPrivWin = cfbGetWindowPrivate(pWin);
+
+    switch (what) {
+    case PW_BACKGROUND:
+       switch (pWin->backgroundState) {
+       case None:
+           break;
+       case ParentRelative:
+           do {
+               pWin = pWin->parent;
+           } while (pWin->backgroundState == ParentRelative);
+           (*pWin->drawable.pScreen->PaintWindowBackground)(pWin, pRegion,
+                                                            what);
+           break;
+       case BackgroundPixmap:
+           if (pPrivWin->fastBackground)
+           {
+               cfbFillBoxTile32 ((DrawablePtr)pWin,
+                                 (int)REGION_NUM_RECTS(pRegion),
+                                 REGION_RECTS(pRegion),
+                                 pPrivWin->pRotatedBackground);
+           }
+           else
+           {
+               cfbFillBoxTileOdd ((DrawablePtr)pWin,
+                                  (int)REGION_NUM_RECTS(pRegion),
+                                  REGION_RECTS(pRegion),
+                                  pWin->background.pixmap,
+                                  (int) pWin->drawable.x, (int) pWin->drawable.y);
+           }
+           break;
+       case BackgroundPixel:
+           cfbFillBoxSolid ((DrawablePtr)pWin,
+                            (int)REGION_NUM_RECTS(pRegion),
+                            REGION_RECTS(pRegion),
+                            pWin->background.pixel);
+           break;
+       }
+       break;
+    case PW_BORDER:
+       if (pWin->borderIsPixel)
+       {
+           cfbFillBoxSolid ((DrawablePtr)pWin,
+                            (int)REGION_NUM_RECTS(pRegion),
+                            REGION_RECTS(pRegion),
+                            pWin->border.pixel);
+       }
+       else if (pPrivWin->fastBorder)
+       {
+           cfbFillBoxTile32 ((DrawablePtr)pWin,
+                             (int)REGION_NUM_RECTS(pRegion),
+                             REGION_RECTS(pRegion),
+                             pPrivWin->pRotatedBorder);
+       }
+       else
+       {
+           for (pBgWin = pWin;
+                pBgWin->backgroundState == ParentRelative;
+                pBgWin = pBgWin->parent);
+
+           cfbFillBoxTileOdd ((DrawablePtr)pWin,
+                              (int)REGION_NUM_RECTS(pRegion),
+                              REGION_RECTS(pRegion),
+                              pWin->border.pixmap,
+                              (int) pBgWin->drawable.x,
+                              (int) pBgWin->drawable.y);
+       }
+       break;
+    }
+}
+
+/*
+ * Use the RROP macros in copy mode
+ */
+
+#define RROP GXcopy
+#include "cfbrrop.h"
+
+#ifdef RROP_UNROLL
+# define Expand(left,right,leftAdjust) {\
+    int part = nmiddle & RROP_UNROLL_MASK; \
+    int widthStep; \
+    widthStep = widthDst - nmiddle - leftAdjust; \
+    nmiddle >>= RROP_UNROLL_SHIFT; \
+    while (h--) { \
+       left \
+       pdst += part; \
+       switch (part) { \
+           RROP_UNROLL_CASE(pdst) \
+       } \
+       m = nmiddle; \
+       while (m) { \
+           pdst += RROP_UNROLL; \
+           RROP_UNROLL_LOOP(pdst) \
+           m--; \
+       } \
+       right \
+       pdst += widthStep; \
+    } \
+}
+
+#else
+# define Expand(left, right, leftAdjust) { \
+    int widthStep; \
+    widthStep = widthDst - nmiddle - leftAdjust; \
+    while (h--) { \
+       left \
+       m = nmiddle; \
+       while (m--) {\
+           RROP_SOLID(pdst); \
+           pdst++; \
+       } \
+       right \
+       pdst += widthStep; \
+    } \
+}
+#endif
+
+void
+cfbFillBoxSolid (pDrawable, nBox, pBox, pixel)
+    DrawablePtr            pDrawable;
+    int                    nBox;
+    BoxPtr         pBox;
+    unsigned long   pixel;
+{
+    unsigned long   *pdstBase;
+    int                    widthDst;
+    register int    h;
+    register unsigned long   rrop_xor;
+    register unsigned long   *pdst;
+    register unsigned long   leftMask, rightMask;
+    int                    nmiddle;
+    register int    m;
+    int                    w;
+#if PSZ == 24
+    int leftIndex, rightIndex;
+    unsigned long piQxelArray[3], xOffset, *pdstULC; /*upper left corner*/
+
+    piQxelArray[0] = (pixel&0xFFFFFF) | ((pixel&0xFF)<<24);
+    piQxelArray[1] = ((pixel&0xFFFF00)>>8) | ((pixel&0xFFFF)<<16);
+    piQxelArray[2] = ((pixel&0xFFFFFF)<<8) | ((pixel&0xFF0000)>>16);
+#endif
+
+    cfbGetLongWidthAndPointer(pDrawable, widthDst, pdstBase);
+
+    rrop_xor = PFILL(pixel);
+    for (; nBox; nBox--, pBox++)
+    {
+       pdst = pdstBase + pBox->y1 * widthDst;
+       h = pBox->y2 - pBox->y1;
+       w = pBox->x2 - pBox->x1;
+#if PSZ == 8
+       if (w == 1)
+       {
+           register char    *pdstb = ((char *) pdst) + pBox->x1;
+           int     incr = widthDst * PGSZB;
+
+           while (h--)
+           {
+               *pdstb = rrop_xor;
+               pdstb += incr;
+           }
+       }
+       else
+       {
+#endif
+#if PSZ == 24
+/* _Box has x1, y1, x2, y2*/
+         leftIndex = pBox->x1 & 3;
+         rightIndex = ((leftIndex+w)<5)?0:(pBox->x2 &3);
+         nmiddle = w - rightIndex;
+         if(leftIndex){
+             nmiddle -= (4 - leftIndex);
+         }
+         nmiddle >>= 2;
+         if(nmiddle < 0)
+           nmiddle = 0;
+
+         pdst = pdstBase + pBox->y1 * widthDst + ((pBox->x1*3) >> 2);
+
+         switch(leftIndex+w){
+         case 4:
+           switch(leftIndex){
+           case 0:
+             while(h--){
+               *pdst++ = piQxelArray[0];
+               *pdst++ = piQxelArray[1];
+               *pdst   = piQxelArray[2];
+               pdst -=2;
+               pdst += widthDst;
+             }
+             break;
+           case 1:
+             while(h--){
+               *pdst++ = ((*pdst) & 0xFFFFFF) | (piQxelArray[0] & 0xFF000000);
+               *pdst++ = piQxelArray[1];
+               *pdst   = piQxelArray[2];
+               pdst -=2;
+               pdst += widthDst;
+             }
+             break;
+           case 2:
+             while(h--){
+               *pdst++ = ((*pdst) & 0xFFFF) | (piQxelArray[1] & 0xFFFF0000);
+               *pdst-- = piQxelArray[2];
+               pdst += widthDst;
+             }
+             break;
+           case 3:
+             while(h--){
+               *pdst = ((*pdst) & 0xFF) | (piQxelArray[2] & 0xFFFFFF00);
+               pdst += widthDst;
+             }
+             break;
+           }
+           break;
+         case 3:
+           switch(leftIndex){
+           case 0:
+             while(h--){
+               *pdst++ = piQxelArray[0];
+               *pdst++ = piQxelArray[1];
+               *pdst-- = ((*pdst) & 0xFFFFFF00) | (piQxelArray[2] & 0xFF);
+               pdst--;
+               pdst += widthDst;
+             }
+             break;
+           case 1:
+             while(h--){
+               *pdst++ = ((*pdst) & 0xFFFFFF) | (piQxelArray[0] & 0xFF000000);
+               *pdst++ = piQxelArray[1];
+               *pdst-- = ((*pdst) & 0xFFFFFF00) | (piQxelArray[2] & 0xFF);
+               pdst--;
+               pdst += widthDst;
+             }
+             break;
+           case 2:
+             while(h--){
+               *pdst++ = ((*pdst) & 0xFFFF) | (piQxelArray[1] & 0xFFFF0000);
+               *pdst-- = ((*pdst) & 0xFFFFFF00) | (piQxelArray[2] & 0xFF);
+               pdst += widthDst;
+             }
+             break;
+           }
+           break;
+         case 2:
+           while(h--){
+             if(leftIndex){
+               *pdst++ = ((*pdst) & 0xFFFFFF) | (piQxelArray[0] & 0xFF000000);
+             }
+             else{
+               *pdst++ = piQxelArray[0];
+             }
+               *pdst-- = ((*pdst) & 0xFFFF0000) | (piQxelArray[1] & 0xFFFF);
+               pdst += widthDst;
+           }
+           break;
+         case 1: /*only if leftIndex = 0 and w = 1*/
+           while(h--){
+               *pdst = ((*pdst) & 0xFF000000) | (piQxelArray[0] & 0xFFFFFF);
+               pdst += widthDst;
+             }
+           break;
+         case 0: /*never*/
+           break;
+         default:
+         {
+           w = nmiddle;
+           pdstULC = pdst;
+/*         maskbits (pBox->x1, w, leftMask, rightMask, nmiddle);*/
+           while(h--){
+             nmiddle = w;
+             pdst = pdstULC;
+             switch(leftIndex){
+             case 0:
+               break;
+             case 1:
+               *pdst++ = ((*pdst) & 0xFFFFFF) | (piQxelArray[0] & 0xFF000000);
+               *pdst++ = piQxelArray[1];
+               *pdst++ = piQxelArray[2];
+               break;
+             case 2:
+               *pdst++ = ((*pdst) & 0xFFFF) | (piQxelArray[1] & 0xFFFF0000);
+               *pdst++ = piQxelArray[2];
+               break;
+             case 3:
+               *pdst++ = ((*pdst) & 0xFF) | (piQxelArray[2] & 0xFFFFFF00);
+               break;
+             }
+             while(nmiddle--){
+               *pdst++ = piQxelArray[0];
+               *pdst++ = piQxelArray[1];
+               *pdst++ = piQxelArray[2];
+             }
+             switch(rightIndex){
+             case 0:
+               break;
+             case 1:
+               *pdst = ((*pdst) & 0xFF000000) | (piQxelArray[0] & 0xFFFFFF);
+               break;
+             case 2:
+               *pdst++ = piQxelArray[0];
+               *pdst = ((*pdst) & 0xFFFF0000) | (piQxelArray[1] & 0xFFFF);
+               break;
+             case 3:
+               *pdst++ = piQxelArray[0];
+               *pdst++ = piQxelArray[1];
+               *pdst = ((*pdst) & 0xFFFFFF00) | (piQxelArray[2] & 0xFF);
+               break;
+           }
+           pdstULC += widthDst;
+           }
+
+         }
+       }
+#else
+       pdst += (pBox->x1 >> PWSH);
+       if ((pBox->x1 & PIM) + w <= PPW)
+       {
+           maskpartialbits(pBox->x1, w, leftMask);
+           while (h--) {
+               *pdst = (*pdst & ~leftMask) | (rrop_xor & leftMask);
+               pdst += widthDst;
+           }
+       }
+       else
+       {
+           maskbits (pBox->x1, w, leftMask, rightMask, nmiddle);
+           if (leftMask)
+           {
+               if (rightMask)
+               {
+                   Expand (RROP_SOLID_MASK (pdst, leftMask); pdst++; ,
+                           RROP_SOLID_MASK (pdst, rightMask); ,
+                           1)
+               }
+               else
+               {
+                   Expand (RROP_SOLID_MASK (pdst, leftMask); pdst++;,
+                           ;,
+                           1)
+               }
+           }
+           else
+           {
+               if (rightMask)
+               {
+                   Expand (;,
+                           RROP_SOLID_MASK (pdst, rightMask);,
+                           0)
+               }
+               else
+               {
+                   Expand (;,
+                           ;,
+                           0)
+               }
+           }
+       }
+#endif
+#if PSZ == 8
+       }
+#endif
+    }
+}
+
+void
+cfbFillBoxTile32 (pDrawable, nBox, pBox, tile)
+    DrawablePtr            pDrawable;
+    int                    nBox;       /* number of boxes to fill */
+    BoxPtr         pBox;       /* pointer to list of boxes to fill */
+    PixmapPtr      tile;       /* rotated, expanded tile */
+{
+    register unsigned long  rrop_xor;  
+    register unsigned long  *pdst;
+    register int           m;
+    unsigned long          *psrc;
+    int                            tileHeight;
+
+    int                            widthDst;
+    int                            w;
+    int                            h;
+    register unsigned long  leftMask;
+    register unsigned long  rightMask;
+    int                            nmiddle;
+    int                            y;
+    int                            srcy;
+
+    unsigned long          *pdstBase;
+#if PSZ == 24
+    int                            leftIndex, rightIndex;
+    unsigned long piQxelArray[3], xOffset, *pdstULC;
+#endif
+
+    tileHeight = tile->drawable.height;
+    psrc = (unsigned long *)tile->devPrivate.ptr;
+
+    cfbGetLongWidthAndPointer (pDrawable, widthDst, pdstBase);
+
+    while (nBox--)
+    {
+#if PSZ == 24
+       w = pBox->x2 - pBox->x1;
+       h = pBox->y2 - pBox->y1;
+       y = pBox->y1;
+       leftIndex = pBox->x1 & 3;
+/*     rightIndex = ((leftIndex+w)<5)?0:pBox->x2 &3;*/
+       rightIndex = pBox->x2 &3;
+       nmiddle = w - rightIndex;
+       if(leftIndex){
+         nmiddle -= (4 - leftIndex);
+       }
+       nmiddle >>= 2;
+       if(nmiddle < 0)
+         nmiddle = 0;
+
+       pdst = pdstBase + ((pBox->x1 *3)>> 2) +  pBox->y1 * widthDst;
+       srcy = y % tileHeight;
+
+#define StepTile    piQxelArray[0] = (psrc[srcy] & 0xFFFFFF) | ((psrc[srcy] & 0xFF)<<24); \
+                   piQxelArray[1] = (psrc[srcy] & 0xFFFF00) | ((psrc[srcy] & 0xFFFF)<<16); \
+                   piQxelArray[2] = ((psrc[srcy] & 0xFF0000)>>16) | \
+                                    ((psrc[srcy] & 0xFFFFFF)<<8); \
+                   /*rrop_xor = psrc[srcy];*/ \
+                   ++srcy; \
+                   if (srcy == tileHeight) \
+                       srcy = 0;
+
+         switch(leftIndex+w){
+         case 4:
+           switch(leftIndex){
+           case 0:
+             while(h--){
+                 StepTile
+               *pdst++ = piQxelArray[0];
+               *pdst++ = piQxelArray[1];
+               *pdst   = piQxelArray[2];
+               pdst-=2;
+               pdst += widthDst;
+             }
+             break;
+           case 1:
+             while(h--){
+                 StepTile
+               *pdst++ = ((*pdst) & 0xFFFFFF) | (piQxelArray[0] & 0xFF000000);
+               *pdst++ = piQxelArray[1];
+               *pdst   = piQxelArray[2];
+               pdst-=2;
+               pdst += widthDst;
+             }
+             break;
+           case 2:
+             while(h--){
+                 StepTile
+               *pdst++ = ((*pdst) & 0xFFFF) | (piQxelArray[1] & 0xFFFF0000);
+               *pdst--   = piQxelArray[2];
+               pdst += widthDst;
+             }
+             break;
+           case 3:
+             while(h--){
+                 StepTile
+               *pdst = ((*pdst) & 0xFF) | (piQxelArray[2] & 0xFFFFFF00);
+               pdst += widthDst;
+             }
+             break;
+           }
+           break;
+         case 3:
+           switch(leftIndex){
+           case 0:
+             while(h--){
+                 StepTile
+               *pdst++ = piQxelArray[0];
+               *pdst++ = piQxelArray[1];
+               *pdst-- = ((*pdst) & 0xFFFFFF00) | (piQxelArray[2] & 0xFF);
+               pdst--;
+               pdst += widthDst;
+             }
+             break;
+           case 1:
+             while(h--){
+                 StepTile
+               *pdst++ = ((*pdst) & 0xFFFFFF) | (piQxelArray[0] & 0xFF000000);
+               *pdst++ = piQxelArray[1];
+               *pdst-- = ((*pdst) & 0xFFFFFF00) | (piQxelArray[2] & 0xFF);
+               pdst--;
+               pdst += widthDst;
+             }
+             break;
+           case 2:
+             while(h--){
+                 StepTile
+               *pdst++ = ((*pdst) & 0xFFFF) | (piQxelArray[1] & 0xFFFF0000);
+               *pdst-- = ((*pdst) & 0xFFFFFF00) | (piQxelArray[2] & 0xFF);
+               pdst += widthDst;
+             }
+             break;
+           }
+           break;
+         case 2:
+           while(h--){
+                 StepTile
+             if(leftIndex){
+               *pdst++ = ((*pdst) & 0xFFFFFF) | (piQxelArray[0] & 0xFF000000);
+             }
+             else{
+               *pdst++ = piQxelArray[0];
+             }
+               *pdst-- = ((*pdst) & 0xFFFF0000) | (piQxelArray[1] & 0xFFFF);
+               pdst += widthDst;
+           }
+           break;
+         case 1: /*only if leftIndex = 0 and w = 1*/
+           while(h--){
+                 StepTile
+               *pdst = ((*pdst) & 0xFF000000) | (piQxelArray[0] & 0xFFFFFF);
+               pdst += widthDst;
+             }
+           break;
+         case 0: /*never*/
+           break;
+         default:
+         {
+           w = nmiddle;
+           pdstULC = pdst;
+
+           while(h--){
+             StepTile
+             nmiddle = w;
+             pdst = pdstULC;
+             switch(leftIndex){
+             case 0:
+               break;
+             case 1:
+               *pdst++ = ((*pdst) & 0xFFFFFF) | (piQxelArray[0] & 0xFF000000);
+               *pdst++ = piQxelArray[1];
+               *pdst++ = piQxelArray[2];
+               break;
+             case 2:
+               *pdst++ = ((*pdst) & 0xFFFF) | (piQxelArray[1] & 0xFFFF0000);
+               *pdst++ = piQxelArray[2];
+               break;
+             case 3:
+               *pdst++ = ((*pdst) & 0xFF) | (piQxelArray[2] & 0xFFFFFF00);
+               break;
+             }
+             while(nmiddle--){
+               *pdst++ = piQxelArray[0];
+               *pdst++ = piQxelArray[1];
+               *pdst++ = piQxelArray[2];
+             }
+             switch(rightIndex){
+             case 0:
+               break;
+             case 1:
+               *pdst = ((*pdst) & 0xFF000000) | (piQxelArray[0] & 0xFFFFFF);
+               break;
+             case 2:
+               *pdst++ = piQxelArray[0];
+               *pdst = ((*pdst) & 0xFFFF0000) | (piQxelArray[1] & 0xFFFF);
+               break;
+             case 3:
+               *pdst++ = piQxelArray[0];
+               *pdst++ = piQxelArray[1];
+               *pdst = ((*pdst) & 0xFFFFFF00) | (piQxelArray[2] & 0xFF);
+               break;
+             }
+             pdstULC += widthDst;
+           }
+         }
+         }
+#else
+       w = pBox->x2 - pBox->x1;
+       h = pBox->y2 - pBox->y1;
+       y = pBox->y1;
+       pdst = pdstBase + (pBox->y1 * widthDst) + (pBox->x1 >> PWSH);
+       srcy = y % tileHeight;
+
+#define StepTile    rrop_xor = psrc[srcy]; \
+                   ++srcy; \
+                   if (srcy == tileHeight) \
+                       srcy = 0;
+
+       if ( ((pBox->x1 & PIM) + w) < PPW)
+       {
+           maskpartialbits(pBox->x1, w, leftMask);
+           rightMask = ~leftMask;
+           while (h--)
+           {
+               StepTile
+               *pdst = (*pdst & rightMask) | (rrop_xor & leftMask);
+               pdst += widthDst;
+           }
+       }
+       else
+       {
+           maskbits(pBox->x1, w, leftMask, rightMask, nmiddle);
+
+           if (leftMask)
+           {
+               if (rightMask)
+               {
+                   Expand (StepTile
+                           RROP_SOLID_MASK(pdst, leftMask); pdst++;,
+                           RROP_SOLID_MASK(pdst, rightMask);,
+                           1)
+               }
+               else
+               {
+                   Expand (StepTile
+                           RROP_SOLID_MASK(pdst, leftMask); pdst++;,
+                           ;,
+                           1)
+               }
+           }
+           else
+           {
+               if (rightMask)
+               {
+                   Expand (StepTile
+                           ,
+                           RROP_SOLID_MASK(pdst, rightMask);,
+                           0)
+               }
+               else
+               {
+                   Expand (StepTile
+                           ,
+                           ;,
+                           0)
+               }
+           }
+       }
+#endif
+        pBox++;
+    }
+}
diff --git a/Xserver/programs/Xserver/cfb/cfbpolypnt.c b/Xserver/programs/Xserver/cfb/cfbpolypnt.c
new file mode 100644 (file)
index 0000000..8e65ed9
--- /dev/null
@@ -0,0 +1,199 @@
+/************************************************************
+
+Copyright (c) 1989  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+********************************************************/
+
+/* $XConsortium: cfbpolypnt.c,v 5.17 94/04/17 20:28:57 dpw Exp $ */
+/* $XFree86: xc/programs/Xserver/cfb/cfbpolypnt.c,v 3.0 1996/06/29 09:05:47 dawes Exp $ */
+
+#include "X.h"
+#include "gcstruct.h"
+#include "windowstr.h"
+#include "pixmapstr.h"
+#include "regionstr.h"
+#include "scrnintstr.h"
+#include "cfb.h"
+#include "cfbmskbits.h"
+
+#define isClipped(c,ul,lr)  ((((c) - (ul)) | ((lr) - (c))) & ClipMask)
+
+/* WARNING: pbox contains two shorts. This code assumes they are packed
+ * and can be referenced together as an INT32.
+ */
+
+#define PointLoop(fill) { \
+    for (nbox = REGION_NUM_RECTS(cclip), pbox = REGION_RECTS(cclip); \
+        --nbox >= 0; \
+        pbox++) \
+    { \
+       c1 = *((INT32 *) &pbox->x1) - off; \
+       c2 = *((INT32 *) &pbox->x2) - off - 0x00010001; \
+       for (ppt = (INT32 *) pptInit, i = npt; --i >= 0;) \
+       { \
+           pt = *ppt++; \
+           if (!isClipped(pt,c1,c2)) { \
+               fill \
+           } \
+       } \
+    } \
+}
+
+#if PSZ == 24
+# include "cfbrrop24.h"
+#endif
+
+void
+cfbPolyPoint(pDrawable, pGC, mode, npt, pptInit)
+    DrawablePtr pDrawable;
+    GCPtr pGC;
+    int mode;
+    int npt;
+    xPoint *pptInit;
+{
+    register INT32   pt;
+    register INT32   c1, c2;
+    register unsigned long   ClipMask = 0x80008000;
+    register unsigned long   xor;
+#ifdef PIXEL_ADDR
+    register PixelType   *addrp;
+    register int    npwidth;
+    PixelType      *addrpt;
+#else
+    register unsigned long    *addrl;
+    register int    nlwidth;
+    register int    xoffset;
+    unsigned long   *addrlt;
+#endif
+#if PSZ == 24
+    RROP_DECLARE
+    register int xtmp;
+    register PixelType *p;
+#endif
+    register INT32  *ppt;
+    RegionPtr      cclip;
+    int                    nbox;
+    register int    i;
+    register BoxPtr pbox;
+    unsigned long   and;
+    int                    rop = pGC->alu;
+    int                    off;
+    cfbPrivGCPtr    devPriv;
+    xPoint         *pptPrev;
+
+    devPriv =cfbGetGCPrivate(pGC);
+    rop = devPriv->rop;
+    if (rop == GXnoop)
+       return;
+    cclip = devPriv->pCompositeClip;
+    xor = devPriv->xor;
+    if ((mode == CoordModePrevious) && (npt > 1))
+    {
+       for (pptPrev = pptInit + 1, i = npt - 1; --i >= 0; pptPrev++)
+       {
+           pptPrev->x += (pptPrev-1)->x;
+           pptPrev->y += (pptPrev-1)->y;
+       }
+    }
+    off = *((int *) &pDrawable->x);
+    off -= (off & 0x8000) << 1;
+#ifdef PIXEL_ADDR
+    cfbGetPixelWidthAndPointer(pDrawable, npwidth, addrp);
+#if PSZ == 24
+    addrp = addrp + pDrawable->y * npwidth;
+#else
+    addrp = addrp + pDrawable->y * npwidth + pDrawable->x;
+#endif
+    if (rop == GXcopy)
+    {
+#if PSZ == 24
+      RROP_COPY_SETUP(xor)
+#endif
+       if (!(npwidth & (npwidth - 1)))
+       {
+           npwidth = ffs(npwidth) - 1;
+#if PSZ == 24
+           PointLoop(
+                     xtmp = pDrawable->x + intToX(pt);
+                     p = addrp + (intToY(pt) << npwidth) + ((xtmp * 3) >>2);
+                     RROP_SOLID24_COPY(p, xtmp))
+#else
+           PointLoop(*(addrp + (intToY(pt) << npwidth) + intToX(pt)) = xor;)
+#endif
+       }
+#ifdef sun
+       else if (npwidth == 1152)
+       {
+           register int    y;
+           PointLoop(y = intToY(pt); *(addrp + (y << 10) + (y << 7) + intToX(pt)) = xor;)
+       }
+#endif
+       else
+       {
+#if PSZ == 24
+           PointLoop(
+                     xtmp = pDrawable->x + intToX(pt);
+                     p = addrp + intToY(pt) * npwidth + ((xtmp * 3) >> 2);
+                     RROP_SOLID24_COPY(p, xtmp))
+#else
+           PointLoop(*(addrp + intToY(pt) * npwidth + intToX(pt)) = xor;)
+#endif
+       }
+    }
+    else
+    {
+       and = devPriv->and;
+#if PSZ == 24
+       RROP_SET_SETUP(xor, and)
+       PointLoop(  
+                 xtmp = pDrawable->x + intToX(pt);
+                 p = addrp + intToY(pt) * npwidth + ((xtmp * 3) >> 2);
+                 RROP_SOLID24_SET(p, xtmp))
+#else
+       PointLoop(  addrpt = addrp + intToY(pt) * npwidth + intToX(pt);
+                   *addrpt = DoRRop (*addrpt, and, xor);)
+#endif
+    }
+#else /* !PIXEL_ADDR */
+    cfbGetLongWidthAndPointer(pDrawable, nlwidth, addrl);
+    addrl = addrl + pDrawable->y * nlwidth + (pDrawable->x >> PWSH);
+    xoffset = pDrawable->x & PIM;
+    and = devPriv->and;
+#if PSZ == 24
+    PointLoop(   addrlt = addrl + intToY(pt) * nlwidth
+                          + ((intToX(pt) + xoffset) >> PWSH);
+                  *addrlt = DoRRop (*addrlt,
+                          and | ~cfbmask[(intToX(pt) + xoffset) & PIM],
+                          xor & cfbmask[(intToX(pt) + xoffset) & PIM]);
+            )
+#else
+    PointLoop(   addrlt = addrl + intToY(pt) * nlwidth
+                          + ((intToX(pt) + xoffset) >> PWSH);
+                  *addrlt = DoRRop (*addrlt,
+                          and | ~cfbmask[((intToX(pt) + xoffset) & 3)<<1],
+                          xor & cfbmask[((intToX(pt) + xoffset) & 3)<<1]);
+            )
+#endif
+#endif /* PIXEL_ADDR */
+}
diff --git a/Xserver/programs/Xserver/cfb/cfbpush8.c b/Xserver/programs/Xserver/cfb/cfbpush8.c
new file mode 100644 (file)
index 0000000..646699b
--- /dev/null
@@ -0,0 +1,181 @@
+/*
+ * Push Pixels for 8 bit displays.
+ */
+
+/*
+
+Copyright (c) 1989  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+*/
+/* $XConsortium: cfbpush8.c,v 5.14 94/04/17 20:28:58 dpw Exp $ */
+
+#if PSZ == 8
+
+#include       "X.h"
+#include       "Xmd.h"
+#include       "Xproto.h"
+#include       "gcstruct.h"
+#include       "windowstr.h"
+#include       "scrnintstr.h"
+#include       "pixmapstr.h"
+#include       "regionstr.h"
+#include       "cfb.h"
+#include       "cfbmskbits.h"
+#include       "cfb8bit.h"
+#define MFB_CONSTS_ONLY
+#include       "maskbits.h"
+
+void
+cfbPushPixels8 (pGC, pBitmap, pDrawable, dx, dy, xOrg, yOrg)
+    GCPtr      pGC;
+    PixmapPtr  pBitmap;
+    DrawablePtr        pDrawable;
+    int                dx, dy, xOrg, yOrg;
+{
+    register unsigned long   *src, *dst;
+    register unsigned long   pixel;
+    register unsigned long   c, bits;
+    unsigned long   *pdstLine, *psrcLine;
+    unsigned long   *pdstBase;
+    int                    srcWidth;
+    int                    dstWidth;
+    int                    xoff;
+    int                    nBitmapLongs, nPixmapLongs;
+    int                    nBitmapTmp, nPixmapTmp;
+    unsigned long   rightMask;
+    BoxRec         bbox;
+    cfbPrivGCPtr    devPriv;
+
+    bbox.x1 = xOrg;
+    bbox.y1 = yOrg;
+    bbox.x2 = bbox.x1 + dx;
+    bbox.y2 = bbox.y1 + dy;
+    devPriv = cfbGetGCPrivate(pGC);
+    
+    switch (RECT_IN_REGION(pGC->pScreen, devPriv->pCompositeClip, &bbox))
+    {
+      case rgnPART:
+       mfbPushPixels(pGC, pBitmap, pDrawable, dx, dy, xOrg, yOrg);
+      case rgnOUT:
+       return;
+    }
+
+    cfbGetLongWidthAndPointer (pDrawable, dstWidth, pdstBase)
+
+    psrcLine = (unsigned long *) pBitmap->devPrivate.ptr;
+    srcWidth = (int) pBitmap->devKind >> PWSH;
+    
+    pixel = devPriv->xor;
+    xoff = xOrg & PIM;
+    nBitmapLongs = (dx + xoff) >> MFB_PWSH;
+    nPixmapLongs = (dx + PGSZB + xoff) >> PWSH;
+
+    rightMask = ~cfb8BitLenMasks[((dx + xoff) & MFB_PIM)];
+
+    pdstLine = pdstBase + (yOrg * dstWidth) + (xOrg >> PWSH);
+
+    while (dy--)
+    {
+       c = 0;
+       nPixmapTmp = nPixmapLongs;
+       nBitmapTmp = nBitmapLongs;
+       src = psrcLine;
+       dst = pdstLine;
+       while (nBitmapTmp--)
+       {
+           bits = *src++;
+           c |= BitRight (bits, xoff);
+           WriteBitGroup(dst, pixel, GetBitGroup(c));
+           NextBitGroup(c);
+           dst++;
+           WriteBitGroup(dst, pixel, GetBitGroup(c));
+           NextBitGroup(c);
+           dst++;
+           WriteBitGroup(dst, pixel, GetBitGroup(c));
+           NextBitGroup(c);
+           dst++;
+           WriteBitGroup(dst, pixel, GetBitGroup(c));
+           NextBitGroup(c);
+           dst++;
+           WriteBitGroup(dst, pixel, GetBitGroup(c));
+           NextBitGroup(c);
+           dst++;
+           WriteBitGroup(dst, pixel, GetBitGroup(c));
+           NextBitGroup(c);
+           dst++;
+           WriteBitGroup(dst, pixel, GetBitGroup(c));
+           NextBitGroup(c);
+           dst++;
+           WriteBitGroup(dst, pixel, GetBitGroup(c));
+           NextBitGroup(c);
+           dst++;
+           nPixmapTmp -= 8;
+           c = 0;
+           if (xoff)
+               c = BitLeft (bits, PGSZ - xoff);
+       }
+       if (BitLeft (rightMask, xoff))
+           c |= BitRight (*src, xoff);
+       c &= rightMask;
+       switch (nPixmapTmp) {
+       case 8:
+           WriteBitGroup(dst, pixel, GetBitGroup(c));
+           NextBitGroup(c);
+           dst++;
+       case 7:
+           WriteBitGroup(dst, pixel, GetBitGroup(c));
+           NextBitGroup(c);
+           dst++;
+       case 6:
+           WriteBitGroup(dst, pixel, GetBitGroup(c));
+           NextBitGroup(c);
+           dst++;
+       case 5:
+           WriteBitGroup(dst, pixel, GetBitGroup(c));
+           NextBitGroup(c);
+           dst++;
+       case 4:
+           WriteBitGroup(dst, pixel, GetBitGroup(c));
+           NextBitGroup(c);
+           dst++;
+       case 3:
+           WriteBitGroup(dst, pixel, GetBitGroup(c));
+           NextBitGroup(c);
+           dst++;
+       case 2:
+           WriteBitGroup(dst, pixel, GetBitGroup(c));
+           NextBitGroup(c);
+           dst++;
+       case 1:
+           WriteBitGroup(dst, pixel, GetBitGroup(c));
+           NextBitGroup(c);
+           dst++;
+       case 0:
+           break;
+       }
+       pdstLine += dstWidth;
+       psrcLine += srcWidth;
+    }
+}
+
+#endif
diff --git a/Xserver/programs/Xserver/cfb/cfbrctstp8.c b/Xserver/programs/Xserver/cfb/cfbrctstp8.c
new file mode 100644 (file)
index 0000000..2dabfa8
--- /dev/null
@@ -0,0 +1,594 @@
+/*
+ * Fill 32 bit stippled rectangles for 8 bit frame buffers
+ */
+/*
+
+Copyright (c) 1989  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+Author: Keith Packard, MIT X Consortium
+
+*/
+
+/* $XConsortium: cfbrctstp8.c,v 1.17 94/04/17 20:28:59 dpw Exp $ */
+/* $XFree86: xc/programs/Xserver/cfb/cfbrctstp8.c,v 3.0 1996/12/09 11:50:55 dawes Exp $ */
+
+#if PSZ == 8
+
+#include "X.h"
+#include "Xmd.h"
+#include "servermd.h"
+#include "gcstruct.h"
+#include "window.h"
+#include "pixmapstr.h"
+#include "scrnintstr.h"
+#include "windowstr.h"
+
+#include "cfb.h"
+#include "cfbmskbits.h"
+#include "cfb8bit.h"
+
+#define MFB_CONSTS_ONLY
+#include "maskbits.h"
+
+void
+cfb8FillRectOpaqueStippled32 (pDrawable, pGC, nBox, pBox)
+    DrawablePtr            pDrawable;
+    GCPtr          pGC;
+    int                    nBox;       /* number of boxes to fill */
+    register BoxPtr pBox;      /* pointer to list of boxes to fill */
+{
+    unsigned long   *src;
+    int stippleHeight;
+
+    int nlwDst;                /* width in longwords of the dest pixmap */
+    int w;             /* width of current box */
+    register int h;    /* height of current box */
+    unsigned long startmask;
+    unsigned long endmask;     /* masks for reggedy bits at either end of line */
+    int nlwMiddle;     /* number of longwords between sides of boxes */
+    register int nlw;                  /* loop version of nlwMiddle */
+    unsigned long *dstLine;
+    register unsigned long *dst;       /* pointer to bits we're writing */
+    unsigned long *dstTmp;
+    int y;                             /* current scan line */
+
+    unsigned long *pbits;/* pointer to start of pixmap */
+    register unsigned long bits;       /* bits from stipple */
+    int        rot, lastStop, i;
+    register unsigned long  xor, and;
+    cfbPrivGCPtr           devPriv;
+    PixmapPtr              stipple;
+    int            wEnd;
+
+    devPriv = cfbGetGCPrivate(pGC);
+    stipple = devPriv->pRotatedPixmap;
+
+    cfb8CheckOpaqueStipple(pGC->alu, pGC->fgPixel, pGC->bgPixel, pGC->planemask);
+
+    stippleHeight = stipple->drawable.height;
+    src = (unsigned long *)stipple->devPrivate.ptr;
+
+    cfbGetLongWidthAndPointer (pDrawable, nlwDst, pbits)
+
+    while (nBox--)
+    {
+       w = pBox->x2 - pBox->x1;
+       h = pBox->y2 - pBox->y1;
+       y = pBox->y1;
+       dstLine = pbits + (pBox->y1 * nlwDst) + ((pBox->x1 & ~PIM) >> PWSH);
+       if (((pBox->x1 & PIM) + w) <= PPW)
+       {
+           maskpartialbits(pBox->x1, w, startmask);
+           nlwMiddle = 0;
+           endmask = 0;
+       }
+       else
+       {
+           maskbits (pBox->x1, w, startmask, endmask, nlwMiddle);
+       }
+       rot = (pBox->x1 & ((PGSZ-1) & ~PIM));
+       pBox++;
+       y = y % stippleHeight;
+#if PPW == 4
+       if (cfb8StippleRRop == GXcopy)
+       {
+           if (w < PGSZ*2)
+           {
+               while (h--)
+               {
+                   bits = src[y];
+                   y++;
+                   if (y == stippleHeight)
+                       y = 0;
+                   if (rot)
+                       RotBitsLeft(bits,rot);
+                   dst = dstLine;
+                   dstLine += nlwDst;
+                   if (startmask)
+                   {
+                       *dst = *dst & ~startmask |
+                               GetPixelGroup (bits) & startmask;
+                       dst++;
+                       RotBitsLeft (bits, PGSZB);
+                   }
+                   nlw = nlwMiddle;
+                   while (nlw--)
+                   {
+                       *dst++ = GetPixelGroup(bits);
+                       RotBitsLeft (bits, PGSZB);
+                   }
+                   if (endmask)
+                   {
+                       *dst = *dst & ~endmask |
+                             GetPixelGroup (bits) & endmask;
+                   }
+               }
+           }
+           else
+           {
+               wEnd = 7 - (nlwMiddle & 7);
+               nlwMiddle = (nlwMiddle >> 3) + 1;
+               while (h--)
+               {
+                   bits = src[y];
+                   y++;
+                   if (y == stippleHeight)
+                       y = 0;
+                   if (rot != 0)
+                       RotBitsLeft (bits, rot);
+                   dstTmp = dstLine;
+                   dstLine += nlwDst;
+                   if (startmask)
+                   {
+                       *dstTmp = *dstTmp & ~startmask |
+                              GetPixelGroup (bits) & startmask;
+                       dstTmp++;
+                       RotBitsLeft (bits, PGSZB);
+                   }
+                   w = 7 - wEnd;
+                   while (w--)
+                   {
+                       nlw = nlwMiddle;
+                       dst = dstTmp;
+                       dstTmp++;
+                       xor = GetPixelGroup (bits);
+                       while (nlw--)
+                       {
+                           *dst = xor;
+                           dst += 8;
+                       }
+                       NextBitGroup (bits);
+                   }
+                   nlwMiddle--;
+                   w = wEnd + 1;
+                   if (endmask)
+                   {
+                       dst = dstTmp + (nlwMiddle << 3);
+                       *dst = (*dst & ~endmask) |
+                              GetPixelGroup (bits) & endmask;
+                   }
+                   while (w--)
+                   {
+                       nlw = nlwMiddle;
+                       dst = dstTmp;
+                       dstTmp++;
+                       xor = GetPixelGroup (bits);
+                       while (nlw--)
+                       {
+                           *dst = xor;
+                           dst += 8;
+                       }
+                       NextBitGroup (bits);
+                   }
+                   nlwMiddle++;
+               }
+           }
+       }
+       else
+#endif /* PPW == 4 */
+       {
+           while (h--)
+           {
+               bits = src[y];
+               y++;
+               if (y == stippleHeight)
+                   y = 0;
+               if (rot)
+                   RotBitsLeft(bits,rot);
+               dst = dstLine;
+               dstLine += nlwDst;
+               if (startmask)
+               {
+                   xor = GetBitGroup(bits);
+                   *dst = MaskRRopPixels(*dst, xor, startmask);
+                   dst++;
+                   RotBitsLeft (bits, PGSZB);
+               }
+               nlw = nlwMiddle;
+               while (nlw--)
+               {
+                   RRopBitGroup(dst, GetBitGroup(bits));
+                   dst++;
+                   RotBitsLeft (bits, PGSZB);
+               }
+               if (endmask)
+               {
+                   xor = GetBitGroup(bits);
+                   *dst = MaskRRopPixels(*dst, xor, endmask);
+               }
+           }
+       }
+    }
+}
+
+void
+cfb8FillRectTransparentStippled32 (pDrawable, pGC, nBox, pBox)
+    DrawablePtr            pDrawable;
+    GCPtr          pGC;
+    int                    nBox;       /* number of boxes to fill */
+    BoxPtr         pBox;       /* pointer to list of boxes to fill */
+{
+    int                    x, y, w, h;
+    int                    nlwMiddle, nlwDst, nlwTmp;
+    unsigned long   startmask, endmask;
+    register unsigned long   *dst;
+    unsigned long   *dstLine, *pbits, *dstTmp;
+    unsigned long   *src;
+    register unsigned long   xor;
+    register unsigned long   bits, mask;
+    int                    rot;
+    int                    wEnd;
+    cfbPrivGCPtr    devPriv;
+    PixmapPtr      stipple;
+    int                    stippleHeight;
+    register int    nlw;
+    
+    devPriv = cfbGetGCPrivate(pGC);
+    stipple = devPriv->pRotatedPixmap;
+    src = (unsigned long *)stipple->devPrivate.ptr;
+    stippleHeight = stipple->drawable.height;
+
+    cfb8CheckStipple (pGC->alu, pGC->fgPixel, pGC->planemask);
+
+    cfbGetLongWidthAndPointer (pDrawable, nlwDst, pbits)
+
+    while (nBox--)
+    {
+       x = pBox->x1;
+       w = pBox->x2 - x;
+       if (((x & PIM) + w) <= PPW)
+       {
+           maskpartialbits(x, w, startmask);
+           endmask = 0;
+           nlwMiddle = 0;
+       }
+       else
+       {
+           maskbits (x, w, startmask, endmask, nlwMiddle);
+       }
+       rot = (x & ((PGSZ-1) & ~PIM));
+       y = pBox->y1;
+       dstLine = pbits + (y * nlwDst) + (x >> PWSH);
+       h = pBox->y2 - y;
+       pBox++;
+       y %= stippleHeight;
+#if PPW == 4
+       if (cfb8StippleRRop == GXcopy)
+       {
+           xor = devPriv->xor;
+           if (w < PGSZ*2)
+           {
+               while (h--)
+               {
+                   bits = src[y];
+                   y++;
+                   if (y == stippleHeight)
+                       y = 0;
+                   if (rot != 0)
+                       RotBitsLeft (bits, rot);
+                   dst = dstLine;
+                   dstLine += nlwDst;
+                   if (startmask)
+                   {
+                       mask = cfb8PixelMasks[GetBitGroup(bits)];
+                       *dst = (*dst & ~(mask & startmask)) |
+                              (xor & (mask & startmask));
+                       dst++;
+                       RotBitsLeft (bits, PGSZB);
+                   }
+                   nlw = nlwMiddle;
+                   while (nlw--)
+                   {
+                       WriteBitGroup (dst,xor,GetBitGroup(bits))
+                       dst++;
+                       RotBitsLeft (bits, PGSZB);
+                   }
+                   if (endmask)
+                   {
+                       mask = cfb8PixelMasks[GetBitGroup(bits)];
+                       *dst = (*dst & ~(mask & endmask)) |
+                              (xor & (mask & endmask));
+                   }
+               }
+           }
+           else
+           {
+               wEnd = 7 - (nlwMiddle & 7);
+               nlwMiddle = (nlwMiddle >> 3) + 1;
+               while (h--)
+               {
+                   bits = src[y];
+                   y++;
+                   if (y == stippleHeight)
+                       y = 0;
+                   if (rot != 0)
+                       RotBitsLeft (bits, rot);
+                   dstTmp = dstLine;
+                   dstLine += nlwDst;
+                   if (startmask)
+                   {
+                       mask = cfb8PixelMasks[GetBitGroup(bits)];
+                       *dstTmp = (*dstTmp & ~(mask & startmask)) |
+                              (xor & (mask & startmask));
+                       dstTmp++;
+                       RotBitsLeft (bits, PGSZB);
+                   }
+                   w = 7 - wEnd;
+                   while (w--)
+                   {
+                       nlw = nlwMiddle;
+                       dst = dstTmp;
+                       dstTmp++;
+#if defined(__GNUC__) && defined(mc68020)
+                       mask = cfb8PixelMasks[GetBitGroup(bits)];
+                       xor = xor & mask;
+                       mask = ~mask;
+                       while (nlw--)
+                       {
+                           *dst = (*dst & mask) | xor;
+                           dst += 8;
+                       }
+                       xor = devPriv->xor;
+#else
+#define SwitchBitsLoop(body) \
+       while (nlw--)   \
+       {               \
+           body        \
+           dst += 8;   \
+       }
+                       SwitchBitGroup(dst, xor, GetBitGroup(bits));
+#undef SwitchBitsLoop
+#endif
+                       NextBitGroup (bits);
+                   }
+                   nlwMiddle--;
+                   w = wEnd + 1;
+                   if (endmask)
+                   {
+                       mask = cfb8PixelMasks[GetBitGroup(bits)];
+                       dst = dstTmp + (nlwMiddle << 3);
+                       *dst = (*dst & ~(mask & endmask)) |
+                              (xor &  (mask & endmask));
+                   }
+                   while (w--)
+                   {
+                       nlw = nlwMiddle;
+                       dst = dstTmp;
+                       dstTmp++;
+#if defined(__GNUC__) && defined(mc68020)
+                       mask = cfb8PixelMasks[GetBitGroup(bits)];
+                       xor = xor & mask;
+                       mask = ~mask;
+                       while (nlw--)
+                       {
+                           *dst = (*dst & mask) | xor;
+                           dst += 8;
+                       }
+                       xor = devPriv->xor;
+#else
+#define SwitchBitsLoop(body) \
+       while (nlw--)   \
+       {               \
+           body        \
+           dst += 8;   \
+       }
+                       SwitchBitGroup(dst, xor, GetBitGroup(bits));
+#undef SwitchBitsLoop
+#endif
+                       NextBitGroup (bits);
+                   }
+                   nlwMiddle++;
+               }
+           }
+       }
+       else
+#endif /* PPW == 4 */
+       {
+           while (h--)
+           {
+               bits = src[y];
+               y++;
+               if (y == stippleHeight)
+                   y = 0;
+               if (rot != 0)
+                   RotBitsLeft (bits, rot);
+               dst = dstLine;
+               dstLine += nlwDst;
+               if (startmask)
+               {
+                   xor = GetBitGroup(bits);
+                   *dst = MaskRRopPixels(*dst, xor, startmask);
+                   dst++;
+                   RotBitsLeft (bits, PGSZB);
+               }
+               nlw = nlwMiddle;
+               while (nlw--)
+               {
+                   RRopBitGroup(dst, GetBitGroup(bits));
+                   dst++;
+                   RotBitsLeft (bits, PGSZB);
+               }
+               if (endmask)
+               {
+                   xor = GetBitGroup(bits);
+                   *dst = MaskRRopPixels(*dst, xor, endmask);
+               }
+           }
+       }
+    }
+}
+
+
+void
+cfb8FillRectStippledUnnatural (pDrawable, pGC, nBox, pBox)
+    DrawablePtr            pDrawable;
+    GCPtr          pGC;
+    int                    nBox;
+    register BoxPtr pBox;
+{
+    unsigned long   *pdstBase; /* pointer to start of bitmap */
+    unsigned long   *pdstLine; /* current destination line */
+    int                    nlwDst;     /* width in longwords of bitmap */
+    PixmapPtr      pStipple;   /* pointer to stipple we want to fill with */
+    int                    nlwMiddle;
+    register int    nlw;
+    int                    x, y, w, h, xrem, xSrc, ySrc;
+    int                    stwidth, stippleWidth;
+    int                    stippleHeight;
+    register unsigned long  bits, inputBits;
+    register int    partBitsLeft;
+    int                    nextPartBits;
+    int                    bitsLeft, bitsWhole;
+    register unsigned long    *pdst;   /* pointer to current word in bitmap */
+    unsigned long   *srcTemp, *srcStart;
+    unsigned long   *psrcBase;
+    unsigned long   startmask, endmask;
+
+    if (pGC->fillStyle == FillStippled)
+       cfb8CheckStipple (pGC->alu, pGC->fgPixel, pGC->planemask);
+    else
+       cfb8CheckOpaqueStipple (pGC->alu, pGC->fgPixel, pGC->bgPixel, pGC->planemask);
+
+    if (cfb8StippleRRop == GXnoop)
+       return;
+
+    /*
+     *  OK,  so what's going on here?  We have two Drawables:
+     *
+     *  The Stipple:
+     *         Depth = 1
+     *         Width = stippleWidth
+     *         Words per scanline = stwidth
+     *         Pointer to pixels = pStipple->devPrivate.ptr
+     */
+
+    pStipple = pGC->stipple;
+
+    stwidth = pStipple->devKind >> PWSH;
+    stippleWidth = pStipple->drawable.width;
+    stippleHeight = pStipple->drawable.height;
+    psrcBase = (unsigned long *) pStipple->devPrivate.ptr;
+
+    /*
+     * The Target:
+     *         Depth = PSZ
+     *         Width = determined from *pwidth
+     *         Words per scanline = nlwDst
+     *         Pointer to pixels = addrlBase
+     */
+
+    xSrc = pDrawable->x;
+    ySrc = pDrawable->y;
+
+    cfbGetLongWidthAndPointer (pDrawable, nlwDst, pdstBase)
+
+    /* this replaces rotating the stipple. Instead we just adjust the offset
+     * at which we start grabbing bits from the stipple.
+     * Ensure that ppt->x - xSrc >= 0 and ppt->y - ySrc >= 0,
+     * so that iline and xrem always stay within the stipple bounds.
+     */
+
+    xSrc += (pGC->patOrg.x % stippleWidth) - stippleWidth;
+    ySrc += (pGC->patOrg.y % stippleHeight) - stippleHeight;
+
+    bitsWhole = stippleWidth;
+
+    while (nBox--)
+    {
+       x = pBox->x1;
+       y = pBox->y1;
+       w = pBox->x2 - x;
+       h = pBox->y2 - y;
+       pBox++;
+       pdstLine = pdstBase + y * nlwDst + (x >> PWSH);
+       y = (y - ySrc) % stippleHeight;
+       srcStart = psrcBase + y * stwidth;
+       xrem = ((x & ~PIM) - xSrc) % stippleWidth;
+       if (((x & PIM) + w) < PPW)
+       {
+           maskpartialbits (x, w, startmask);
+           nlwMiddle = 0;
+           endmask = 0;
+       }
+       else
+       {
+           maskbits (x, w, startmask, endmask, nlwMiddle);
+       }
+       while (h--)
+       {
+           srcTemp = srcStart + (xrem >> MFB_PWSH);
+           bitsLeft = stippleWidth - (xrem & ~MFB_PIM);
+           NextUnnaturalStippleWord
+           NextSomeBits (inputBits, (xrem & MFB_PIM));
+           partBitsLeft -= (xrem & MFB_PIM);
+           NextUnnaturalStippleBits
+           nlw = nlwMiddle;
+           pdst = pdstLine;
+           if (startmask)
+           {
+               *pdst = MaskRRopPixels(*pdst,bits,startmask);
+               pdst++;
+               NextUnnaturalStippleBits
+           }
+           while (nlw--)
+           {
+               *pdst = RRopPixels(*pdst,bits);
+               pdst++;
+               NextUnnaturalStippleBits
+           }
+           if (endmask)
+               *pdst = MaskRRopPixels(*pdst,bits,endmask);
+           pdstLine += nlwDst;
+           y++;
+           srcStart += stwidth;
+           if (y == stippleHeight)
+           {
+               y = 0;
+               srcStart = psrcBase;
+           }
+       }
+    }
+}
+
+#endif /* PSZ == 8 */
diff --git a/Xserver/programs/Xserver/cfb/cfbrrop.c b/Xserver/programs/Xserver/cfb/cfbrrop.c
new file mode 100644 (file)
index 0000000..d49cba2
--- /dev/null
@@ -0,0 +1,222 @@
+/*
+ * $XConsortium: cfbrrop.c,v 1.8 94/04/17 20:28:59 dpw Exp $
+ *
+Copyright (c) 1989  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+ *
+ * Author:  Keith Packard, MIT X Consortium
+ */
+
+/* cfb reduced rasterop computations */
+
+#include "X.h"
+#include "Xmd.h"
+#include "Xproto.h"
+#include "cfb.h"
+#include "cfbmskbits.h"
+
+/* A description:
+ *
+ * There are four possible operations on each bit in the destination word,
+ *
+ *         1   2   3   4
+ *
+ *    0            0   0   1   1
+ *    1            0   1   0   1
+ *
+ * On examination of the reduced rop equation (dst = (dst & and) ^ xor),
+ * these four fall to reduced rops as follows:
+ *
+ *  and            0   1   1   0
+ *  xor            0   0   1   1
+ *
+ * or, (if 'and' is expensive) (dst = (dst | or) ^ xor)
+ *
+ *  or     1   0   0   1
+ *  xor            1   0   1   0
+ *
+ * The trouble with using this later equation is that trivial
+ * rasterop reduction is more difficult; some common rasterops
+ * use complicated expressions of xor/and instead of the simple
+ * ones while other common rasterops are not made any simpler:
+ *
+ * GXcopy:     *dst = ~xor             instead of  *dst = xor
+ * GXand:      *dst = *dst & ~or       instead of  *dst = *dst & and
+ * GXor:       *dst = *dst | or        instead of  *dst = *dst | xor
+ * GXxor:      *dst = *dst ^ xor       instead of  *dst = *dst ^ xor
+ *
+ * If you're really set on using this second mechanism, the changes
+ * are pretty simple.
+ *
+ * All that remains is to provide a mechanism for computing and/xor values
+ * based on the raster op and foreground value.
+ *
+ * The 16 rops fall as follows, with the associated reduced
+ * rop and/xor and or/xor values.  The values in parenthesis following the
+ * reduced values gives an equation using the source value for
+ * the reduced value, and is one of {0, src, ~src, 1} as appropriate.
+ *
+ *     clear           and             andReverse      copy
+ *     src  0  1           0   1           0   1           0   1
+ *  dst        0   0   0       0   0   0       0   0   1       0   0   1
+ *     1   0   0       1   0   1       1   0   0       1   0   1
+ *
+ *  and            0   0 (0)       0   1 (src)     0   1 (src)     0   0 (0)
+ *  xor            0   0 (0)       0   0 (0)       0   1 (src)     0   1 (src)
+ *
+ *  or     1   1 (1)       1   0 (~src)    1   0 (~src)    1   1 (1)
+ *  xor            1   1 (1)       1   0 (~src)    1   1 (1)       1   0 (~src)
+ *
+ *     andInverted     noop            xor             or
+ *     src  0  1           0   1           0   1           0   1
+ *  dst        0   0   0       0   0   0       0   0   1       0   0   1
+ *     1   1   0       1   1   1       1   1   0       1   1   1
+ *
+ *  and            1   0 (~src)    1   1 (1)       1   1 (1)       1   0 (~src)
+ *  xor            0   0 (0)       0   0 (0)       0   1 (src)     0   1 (src)
+ *
+ *  or     0   1 (src)     0   0 (0)       0   0 (0)       0   1 (src)
+ *  xor            0   1 (src)     0   0 (0)       0   1 (src)     0   0 (0)
+ *
+ *     nor             equiv           invert          orReverse
+ *     src  0  1           0   1           0   1           0   1
+ *  dst        0   1   0       0   1   0       0   1   1       0   1   1
+ *     1   0   0       1   0   1       1   0   0       1   0   1
+ *
+ *  and            1   0 (~src)    1   1 (1)       1   1 (1)       1   0 (~src)
+ *  xor            1   0 (~src)    1   0 (~src)    1   1 (1)       1   1 (1)
+ *
+ *  or     0   1 (src)     0   0 (0)       0   0 (0)       0   1 (src)
+ *  xor            1   1 (1)       1   0 (~src)    1   1 (1)       1   0 (~src)
+ *
+ *     copyInverted    orInverted      nand            set
+ *     src  0  1           0   1           0   1           0   1
+ *  dst        0   1   0       0   1   0       0   1   1       0   1   1
+ *     1   1   0       1   1   1       1   1   0       1   1   1
+ *
+ *  and            0   0 (0)       0   1 (src)     0   1 (src)     0   0 (0)
+ *  xor            1   0 (~src)    1   0 (~src)    1   1 (1)       1   1 (1)
+ *
+ *  or     1   1 (1)       1   0 (~src)    1   0 (~src)    1   1 (1)
+ *  xor            0   1 (src)     0   0 (0)       0   1 (src)     0   0 (0)
+ */
+
+int
+cfbReduceRasterOp (rop, fg, pm, andp, xorp)
+    int                    rop;
+    unsigned long   fg, pm;
+    unsigned long   *andp, *xorp;
+{
+    unsigned long   and, xor;
+    int                    rrop;
+
+    fg = PFILL (fg);
+    pm = PFILL (pm);
+    switch (rop)
+    {
+    case GXclear:
+       and = 0;
+       xor = 0;
+       break;
+    case GXand:
+       and = fg;
+       xor = 0;
+       break;
+    case GXandReverse:
+       and = fg;
+       xor = fg;
+       break;
+    case GXcopy:
+       and = 0;
+       xor = fg;
+       break;
+    case GXandInverted:
+       and = ~fg;
+       xor = 0;
+       break;
+    case GXnoop:
+       and = ~0;
+       xor = 0;
+       break;
+    case GXxor:
+       and = ~0;
+       xor = fg;
+       break;
+    case GXor:
+       and = ~fg;
+       xor = fg;
+       break;
+    case GXnor:
+       and = ~fg;
+       xor = ~fg;
+       break;
+    case GXequiv:
+       and = ~0;
+       xor = ~fg;
+       break;
+    case GXinvert:
+       and = ~0;
+       xor = ~0;
+       break;
+    case GXorReverse:
+       and = ~fg;
+       xor = ~0;
+       break;
+    case GXcopyInverted:
+       and = 0;
+       xor = ~fg;
+       break;
+    case GXorInverted:
+       and = fg;
+       xor = ~fg;
+       break;
+    case GXnand:
+       and = fg;
+       xor = ~0;
+       break;
+    case GXset:
+       and = 0;
+       xor = ~0;
+       break;
+    }
+    and |= ~pm;
+    xor &= pm;
+    *andp = and;
+    *xorp = xor;
+    /* check for some special cases to reduce computation */
+    if (and == 0)
+       rrop = GXcopy;
+    /* nothing checks for GXnoop
+    else if (and == ~0 && xor == 0)
+       rrop = GXnoop;
+    */
+    else if (and == ~0)
+       rrop = GXxor;
+    else if (xor == 0)
+       rrop = GXand;
+    else if ( (and ^ xor) == ~0) /* fix XBUG 6541 */
+       rrop = GXor;
+    else
+       rrop = GXset;   /* rop not reduced */
+    return rrop;
+}
diff --git a/Xserver/programs/Xserver/cfb/cfbrrop.h b/Xserver/programs/Xserver/cfb/cfbrrop.h
new file mode 100644 (file)
index 0000000..cb15540
--- /dev/null
@@ -0,0 +1,334 @@
+/*
+ * $XConsortium: cfbrrop.h,v 1.10 95/06/08 23:20:39 gildea Exp $
+ * $XFree86: xc/programs/Xserver/cfb/cfbrrop.h,v 3.2 1997/01/08 20:32:41 dawes Exp $
+ *
+Copyright (c) 1989  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+ *
+ * Author:  Keith Packard, MIT X Consortium
+ */
+
+#ifndef GXcopy
+#include "X.h"
+#endif
+
+#define RROP_FETCH_GC(gc) \
+    RROP_FETCH_GCPRIV(((cfbPrivGCPtr)(gc)->devPrivates[cfbGCPrivateIndex].ptr))
+
+#ifndef RROP
+#define RROP GXset
+#endif
+
+#if RROP == GXcopy
+#if PSZ == 24
+#define RROP_DECLARE   register unsigned long  rrop_xor; \
+    unsigned long piQxelXor[3], spiQxelXor[8];
+#define RROP_FETCH_GCPRIV(devPriv)  rrop_xor = (devPriv)->xor; \
+    spiQxelXor[0] = rrop_xor & 0xFFFFFF; \
+    spiQxelXor[2] = rrop_xor << 24; \
+    spiQxelXor[3] = (rrop_xor & 0xFFFF00)>> 8; \
+    spiQxelXor[4] = rrop_xor << 16; \
+    spiQxelXor[5] = (rrop_xor & 0xFF0000)>> 16; \
+    spiQxelXor[6] = rrop_xor << 8; \
+    spiQxelXor[1] = spiQxelXor[7] = 0; \
+    piQxelXor[0] = (rrop_xor & 0xFFFFFF)|(rrop_xor << 24); \
+    piQxelXor[1] = (rrop_xor << 16)|((rrop_xor & 0xFFFF00)>> 8); \
+    piQxelXor[2] = (rrop_xor << 8)|((rrop_xor & 0xFF0000)>> 16);
+#define RROP_SOLID24(dst,index)            {\
+           register int idx = ((index) & 3)<< 1; \
+           *(dst) = (*(dst) & cfbrmask[idx])|spiQxelXor[idx]; \
+           if (idx == 2  ||  idx == 4){ \
+              idx++; \
+             *((dst)+1) = (*((dst)+1) & cfbrmask[idx])|spiQxelXor[idx]; \
+           } \
+       }
+#define RROP_SOLID(dst, idx) \
+           (*(dst) = piQxelXor[(idx)])
+#define RROP_SOLID_MASK(dst,mask,idx) \
+           (*(dst) = (*(dst) & ~(mask))|(piQxelXor[(idx)] & (mask)))
+#else
+#define RROP_FETCH_GCPRIV(devPriv)  rrop_xor = (devPriv)->xor;
+#define RROP_DECLARE   register unsigned long  rrop_xor;
+#define RROP_SOLID(dst)            (*(dst) = (rrop_xor))
+#define RROP_SOLID_MASK(dst,mask) (*(dst) = (*(dst) & ~(mask)) | ((rrop_xor) & (mask)))
+#define RROP_SOLID_lu(dst)         stl_u(rrop_xor, dst)
+#define RROP_SOLID_MASK_lu(dst,mask) stl_u((ldl_u(dst) & ~(mask)) | ((rrop_xor) & (mask)), dst)
+#endif
+#define RROP_NAME(prefix)   RROP_NAME_CAT(prefix,Copy)
+#endif /* GXcopy */
+
+#if RROP == GXxor
+#if PSZ == 24
+#define RROP_DECLARE   register unsigned long  rrop_xor; \
+    unsigned long piQxelXor[3], spiQxelXor[8];
+#define RROP_FETCH_GCPRIV(devPriv)  rrop_xor = (devPriv)->xor; \
+    spiQxelXor[0] = rrop_xor & 0xFFFFFF; \
+    spiQxelXor[2] = rrop_xor << 24; \
+    spiQxelXor[3] = (rrop_xor & 0xFFFF00)>> 8; \
+    spiQxelXor[4] = rrop_xor << 16; \
+    spiQxelXor[5] = (rrop_xor & 0xFF0000)>> 16; \
+    spiQxelXor[6] = rrop_xor << 8; \
+    spiQxelXor[1] = spiQxelXor[7] = 0; \
+    piQxelXor[0] = (rrop_xor & 0xFFFFFF)|(rrop_xor << 24); \
+    piQxelXor[1] = (rrop_xor << 16)|((rrop_xor & 0xFFFF00)>> 8); \
+    piQxelXor[2] = (rrop_xor << 8)|((rrop_xor & 0xFF0000)>> 16);
+#define RROP_SOLID24(dst,index)             {\
+           register int idx = ((index) & 3)<< 1; \
+           *(dst) ^= spiQxelXor[idx]; \
+           if (idx == 2  ||  idx == 4) \
+             *((dst)+1) ^= spiQxelXor[idx+1]; \
+       }
+#define RROP_SOLID(dst,idx) \
+           (*(dst) ^= piQxelXor[(idx)])
+#define RROP_SOLID_MASK(dst,mask,idx) \
+           (*(dst) ^= (piQxelXor[(idx)] & (mask)))
+#else
+#define RROP_DECLARE   register unsigned long  rrop_xor;
+#define RROP_FETCH_GCPRIV(devPriv)  rrop_xor = (devPriv)->xor;
+#define RROP_SOLID(dst)            (*(dst) ^= (rrop_xor))
+#define RROP_SOLID_MASK(dst,mask) (*(dst) ^= ((rrop_xor) & (mask)))
+#endif
+#define RROP_NAME(prefix)   RROP_NAME_CAT(prefix,Xor)
+#endif /* GXxor */
+
+#if RROP == GXand
+#if PSZ == 24
+#define RROP_DECLARE   register unsigned long  rrop_and; \
+    unsigned long piQxelAnd[3], spiQxelAnd[6];
+#define RROP_FETCH_GCPRIV(devPriv)  rrop_and = (devPriv)->and; \
+    spiQxelAnd[0] = (rrop_and & 0xFFFFFF) | 0xFF000000; \
+    spiQxelAnd[2] = (rrop_and << 24) | 0xFFFFFF; \
+    spiQxelAnd[3] = ((rrop_and & 0xFFFF00)>> 8) | 0xFFFF0000; \
+    spiQxelAnd[4] = (rrop_and << 16) | 0xFFFF; \
+    spiQxelAnd[5] = ((rrop_and & 0xFF0000)>> 16) | 0xFFFFFF00; \
+    spiQxelAnd[1] = (rrop_and << 8) | 0xFF; \
+    piQxelAnd[0] = (rrop_and & 0xFFFFFF)|(rrop_and << 24); \
+    piQxelAnd[1] = (rrop_and << 16)|((rrop_and & 0xFFFF00)>> 8); \
+    piQxelAnd[2] = (rrop_and << 8)|((rrop_and & 0xFF0000)>> 16); 
+#define RROP_SOLID24(dst,index)            {\
+           switch((index) & 3){ \
+           case 0: \
+             *(dst) &= spiQxelAnd[0]; \
+             break; \
+           case 3: \
+             *(dst) &= spiQxelAnd[1]; \
+             break; \
+           case 1: \
+             *(dst) &= spiQxelAnd[2]; \
+             *((dst)+1) &= spiQxelAnd[3]; \
+             break; \
+           case 2: \
+             *(dst) &= spiQxelAnd[4]; \
+             *((dst)+1) &= spiQxelAnd[5]; \
+             break; \
+           } \
+           }
+#define RROP_SOLID(dst,idx) \
+           (*(dst) &= piQxelAnd[(idx)])
+#define RROP_SOLID_MASK(dst,mask,idx) \
+           (*(dst) &= (piQxelAnd[(idx)] | ~(mask)))
+#else
+#define RROP_DECLARE   register unsigned long  rrop_and;
+#define RROP_FETCH_GCPRIV(devPriv)  rrop_and = (devPriv)->and;
+#define RROP_SOLID(dst)            (*(dst) &= (rrop_and))
+#define RROP_SOLID_MASK(dst,mask) (*(dst) &= ((rrop_and) | ~(mask)))
+#endif
+#define RROP_NAME(prefix)   RROP_NAME_CAT(prefix,And)
+#endif /* GXand */
+
+#if RROP == GXor
+#if PSZ == 24
+#define RROP_DECLARE   register unsigned long  rrop_or; \
+    unsigned long piQxelOr[3], spiQxelOr[6];
+#define RROP_FETCH_GCPRIV(devPriv)  rrop_or = (devPriv)->xor; \
+    spiQxelOr[0] = rrop_or & 0xFFFFFF; \
+    spiQxelOr[1] = rrop_or << 24; \
+    spiQxelOr[2] = rrop_or << 16; \
+    spiQxelOr[3] = rrop_or << 8; \
+    spiQxelOr[4] = (rrop_or & 0xFFFF00)>> 8; \
+    spiQxelOr[5] = (rrop_or & 0xFF0000)>> 16; \
+    piQxelOr[0] = (rrop_or & 0xFFFFFF)|(rrop_or << 24); \
+    piQxelOr[1] = (rrop_or << 16)|((rrop_or & 0xFFFF00)>> 8); \
+    piQxelOr[2] = (rrop_or << 8)|((rrop_or & 0xFF0000)>> 16);
+#define RROP_SOLID24(dst,index)             {\
+           switch((index) & 3){ \
+           case 0: \
+             *(dst) |= spiQxelOr[0]; \
+             break; \
+           case 3: \
+             *(dst) |= spiQxelOr[3]; \
+             break; \
+           case 1: \
+             *(dst) |= spiQxelOr[1]; \
+             *((dst)+1) |= spiQxelOr[4]; \
+             break; \
+           case 2: \
+             *(dst) |= spiQxelOr[2]; \
+             *((dst)+1) |= spiQxelOr[5]; \
+             break; \
+           } \
+           }
+#define RROP_SOLID(dst,idx) \
+           (*(dst) |= piQxelOr[(idx)])
+#define RROP_SOLID_MASK(dst,mask,idx) \
+           (*(dst) |= (piQxelOr[(idx)] & (mask)))
+#else
+#define RROP_DECLARE   register unsigned long  rrop_or;
+#define RROP_FETCH_GCPRIV(devPriv)  rrop_or = (devPriv)->xor;
+#define RROP_SOLID(dst)            (*(dst) |= (rrop_or))
+#define RROP_SOLID_MASK(dst,mask) (*(dst) |= ((rrop_or) & (mask)))
+#endif
+#define RROP_NAME(prefix)   RROP_NAME_CAT(prefix,Or)
+#endif /* GXor */
+
+#if RROP == GXnoop
+#define RROP_DECLARE
+#define RROP_FETCH_GCPRIV(devPriv)
+#define RROP_SOLID(dst)
+#define RROP_SOLID_MASK(dst,mask)
+#define RROP_NAME(prefix)   RROP_NAME_CAT(prefix,Noop)
+#endif /* GXnoop */
+
+#if RROP ==  GXset
+#if PSZ == 24
+#define RROP_DECLARE       register unsigned long      rrop_and, rrop_xor; \
+    unsigned long piQxelAnd[3], piQxelXor[3],  spiQxelAnd[6], spiQxelXor[6];
+#define RROP_FETCH_GCPRIV(devPriv)  rrop_and = (devPriv)->and; \
+                                   rrop_xor = (devPriv)->xor; \
+    spiQxelXor[0] = rrop_xor & 0xFFFFFF; \
+    spiQxelXor[1] = rrop_xor << 24; \
+    spiQxelXor[2] = rrop_xor << 16; \
+    spiQxelXor[3] = rrop_xor << 8; \
+    spiQxelXor[4] = (rrop_xor & 0xFFFF00)>> 8; \
+    spiQxelXor[5] = (rrop_xor & 0xFF0000)>> 16; \
+    spiQxelAnd[0] = (rrop_and & 0xFFFFFF) | 0xFF000000; \
+    spiQxelAnd[1] = (rrop_and << 24) | 0xFFFFFF; \
+    spiQxelAnd[2] = (rrop_and << 16) | 0xFFFF; \
+    spiQxelAnd[3] = (rrop_and << 8) | 0xFF; \
+    spiQxelAnd[4] = ((rrop_and & 0xFFFF00)>> 8) | 0xFFFF0000; \
+    spiQxelAnd[5] = ((rrop_and & 0xFF0000)>> 16) | 0xFFFFFF00; \
+    piQxelAnd[0] = (rrop_and & 0xFFFFFF)|(rrop_and << 24); \
+    piQxelAnd[1] = (rrop_and << 16)|((rrop_and & 0xFFFF00)>> 8); \
+    piQxelAnd[2] = (rrop_and << 8)|((rrop_and & 0xFF0000)>> 16); \
+    piQxelXor[0] = (rrop_xor & 0xFFFFFF)|(rrop_xor << 24); \
+    piQxelXor[1] = (rrop_xor << 16)|((rrop_xor & 0xFFFF00)>> 8); \
+    piQxelXor[2] = (rrop_xor << 8)|((rrop_xor & 0xFF0000)>> 16);
+#define RROP_SOLID24(dst,index)             {\
+           switch((index) & 3){ \
+           case 0: \
+             *(dst) = ((*(dst) & (piQxelAnd[0] |0xFF000000))^(piQxelXor[0] & 0xFFFFFF)); \
+             break; \
+           case 3: \
+             *(dst) = ((*(dst) & (piQxelAnd[2]|0xFF))^(piQxelXor[2] & 0xFFFFFF00)); \
+             break; \
+           case 1: \
+             *(dst) = ((*(dst) & (piQxelAnd[0]|0xFFFFFF))^(piQxelXor[0] & 0xFF000000)); \
+             *((dst)+1) = ((*((dst)+1) & (piQxelAnd[1]|0xFFFF0000))^(piQxelXor[1] & 0xFFFF)); \
+             break; \
+           case 2: \
+             *(dst) = ((*(dst) & (piQxelAnd[1]|0xFFFF))^(piQxelXor[1] & 0xFFFF0000)); \
+             *((dst)+1) = ((*((dst)+1) & (piQxelAnd[2]|0xFFFFFF00))^(piQxelXor[2] & 0xFF)); \
+             break; \
+           } \
+           }
+#define RROP_SOLID(dst,idx) \
+           (*(dst) = DoRRop (*(dst), piQxelAnd[(idx)], piQxelXor[(idx)]))
+#define RROP_SOLID_MASK(dst,mask,idx) \
+           (*(dst) = DoMaskRRop (*(dst), piQxelAnd[(idx)], piQxelXor[(idx)], (mask)))
+#else
+#define RROP_DECLARE       register unsigned long      rrop_and, rrop_xor;
+#define RROP_FETCH_GCPRIV(devPriv)  rrop_and = (devPriv)->and; \
+                                   rrop_xor = (devPriv)->xor;
+#define RROP_SOLID(dst)            (*(dst) = DoRRop (*(dst), rrop_and, rrop_xor))
+#define RROP_SOLID_MASK(dst,mask)   (*(dst) = DoMaskRRop (*(dst), rrop_and, rrop_xor, (mask)))
+#endif
+#define RROP_NAME(prefix)   RROP_NAME_CAT(prefix,General)
+#endif /* GXset */
+
+#define RROP_UNROLL_CASE1(p,i)    case (i): RROP_SOLID((p) - (i));
+#define RROP_UNROLL_CASE2(p,i)    RROP_UNROLL_CASE1(p,(i)+1) RROP_UNROLL_CASE1(p,i)
+#define RROP_UNROLL_CASE4(p,i)    RROP_UNROLL_CASE2(p,(i)+2) RROP_UNROLL_CASE2(p,i)
+#define RROP_UNROLL_CASE8(p,i)    RROP_UNROLL_CASE4(p,(i)+4) RROP_UNROLL_CASE4(p,i)
+#define RROP_UNROLL_CASE16(p,i)   RROP_UNROLL_CASE8(p,(i)+8) RROP_UNROLL_CASE8(p,i)
+#define RROP_UNROLL_CASE3(p)   RROP_UNROLL_CASE2(p,2) RROP_UNROLL_CASE1(p,1)
+#define RROP_UNROLL_CASE7(p)   RROP_UNROLL_CASE4(p,4) RROP_UNROLL_CASE3(p)
+#define RROP_UNROLL_CASE15(p)  RROP_UNROLL_CASE8(p,8) RROP_UNROLL_CASE7(p)
+#define RROP_UNROLL_CASE31(p)  RROP_UNROLL_CASE16(p,16) RROP_UNROLL_CASE15(p)
+#ifdef LONG64
+#define RROP_UNROLL_CASE63(p)  RROP_UNROLL_CASE32(p,32) RROP_UNROLL_CASE31(p)
+#endif /* LONG64 */
+
+#define RROP_UNROLL_LOOP1(p,i) RROP_SOLID((p) + (i));
+#define RROP_UNROLL_LOOP2(p,i) RROP_UNROLL_LOOP1(p,(i)) RROP_UNROLL_LOOP1(p,(i)+1)
+#define RROP_UNROLL_LOOP4(p,i) RROP_UNROLL_LOOP2(p,(i)) RROP_UNROLL_LOOP2(p,(i)+2)
+#define RROP_UNROLL_LOOP8(p,i) RROP_UNROLL_LOOP4(p,(i)) RROP_UNROLL_LOOP4(p,(i)+4)
+#define RROP_UNROLL_LOOP16(p,i) RROP_UNROLL_LOOP8(p,(i)) RROP_UNROLL_LOOP8(p,(i)+8)
+#define RROP_UNROLL_LOOP32(p,i) RROP_UNROLL_LOOP16(p,(i)) RROP_UNROLL_LOOP16(p,(i)+16)
+#ifdef LONG64
+#define RROP_UNROLL_LOOP64(p,i) RROP_UNROLL_LOOP32(p,(i)) RROP_UNROLL_LOOP32(p,(i)+32)
+#endif /* LONG64 */
+
+#if defined (FAST_CONSTANT_OFFSET_MODE) && defined (SHARED_IDCACHE) && (RROP == GXcopy)
+
+#ifdef LONG64
+#define RROP_UNROLL_SHIFT      6
+#define RROP_UNROLL_CASE(p)    RROP_UNROLL_CASE63(p)
+#define RROP_UNROLL_LOOP(p)    RROP_UNROLL_LOOP64(p,-64)
+#else /* not LONG64 */
+#define RROP_UNROLL_SHIFT      5
+#define RROP_UNROLL_CASE(p)    RROP_UNROLL_CASE31(p)
+#define RROP_UNROLL_LOOP(p)    RROP_UNROLL_LOOP32(p,-32)
+#endif /* LONG64 */
+#define RROP_UNROLL            (1<<RROP_UNROLL_SHIFT)
+#define RROP_UNROLL_MASK       (RROP_UNROLL-1)
+
+#define RROP_SPAN(pdst,nmiddle) {\
+    int part = (nmiddle) & RROP_UNROLL_MASK; \
+    (nmiddle) >>= RROP_UNROLL_SHIFT; \
+    (pdst) += part * (sizeof (unsigned long) / sizeof (*pdst)); \
+    switch (part) {\
+       RROP_UNROLL_CASE((unsigned long *) (pdst)) \
+    } \
+    while (--(nmiddle) >= 0) { \
+       (pdst) += RROP_UNROLL * (sizeof (unsigned long) / sizeof (*pdst)); \
+       RROP_UNROLL_LOOP((unsigned long *) (pdst)) \
+    } \
+}
+#else
+#define RROP_SPAN(pdst,nmiddle) \
+    while (--(nmiddle) >= 0) { \
+       RROP_SOLID((unsigned long *) (pdst)); \
+       (pdst) += sizeof (unsigned long) / sizeof (*pdst); \
+    }
+#define RROP_SPAN_lu(pdst,nmiddle) \
+    while (--(nmiddle) >= 0) { \
+       RROP_SOLID_lu((unsigned long *) (pdst)); \
+       (pdst) += sizeof (unsigned long) / sizeof (*pdst); \
+    }
+#endif
+
+#if (defined(__STDC__) && !defined(UNIXCPP)) || defined(ANSICPP)
+#define RROP_NAME_CAT(prefix,suffix)   prefix##suffix
+#else
+#define RROP_NAME_CAT(prefix,suffix)   prefix/**/suffix
+#endif
diff --git a/Xserver/programs/Xserver/cfb/cfbscrinit.c b/Xserver/programs/Xserver/cfb/cfbscrinit.c
new file mode 100644 (file)
index 0000000..a54aa97
--- /dev/null
@@ -0,0 +1,195 @@
+/************************************************************
+Copyright 1987 by Sun Microsystems, Inc. Mountain View, CA.
+
+                    All Rights Reserved
+
+Permission  to  use,  copy,  modify,  and  distribute   this
+software  and  its documentation for any purpose and without
+fee is hereby granted, provided that the above copyright no-
+tice  appear  in all copies and that both that copyright no-
+tice and this permission notice appear in  supporting  docu-
+mentation,  and  that the names of Sun or X Consortium
+not be used in advertising or publicity pertaining to 
+distribution  of  the software  without specific prior 
+written permission. Sun and X Consortium make no 
+representations about the suitability of this software for 
+any purpose. It is provided "as is" without any express or 
+implied warranty.
+
+SUN DISCLAIMS ALL WARRANTIES WITH REGARD TO  THIS  SOFTWARE,
+INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FIT-
+NESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SUN BE  LI-
+ABLE  FOR  ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
+ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,  DATA  OR
+PROFITS,  WHETHER  IN  AN  ACTION OF CONTRACT, NEGLIGENCE OR
+OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION  WITH
+THE USE OR PERFORMANCE OF THIS SOFTWARE.
+
+********************************************************/
+/* $XConsortium: cfbscrinit.c,v 5.32 94/04/17 20:29:00 dpw Exp $ */
+
+#include "X.h"
+#include "Xmd.h"
+#include "servermd.h"
+#include "scrnintstr.h"
+#include "pixmapstr.h"
+#include "resource.h"
+#include "colormap.h"
+#include "colormapst.h"
+#include "cfb.h"
+#include "mi.h"
+#include "mistruct.h"
+#include "dix.h"
+#include "cfbmskbits.h"
+#include "mibstore.h"
+
+
+miBSFuncRec cfbBSFuncRec = {
+    cfbSaveAreas,
+    cfbRestoreAreas,
+    (void (*)()) 0,
+    (PixmapPtr (*)()) 0,
+    (PixmapPtr (*)()) 0,
+};
+
+Bool
+cfbCloseScreen (index, pScreen)
+    int                index;
+    ScreenPtr  pScreen;
+{
+    int            d;
+    DepthPtr   depths = pScreen->allowedDepths;
+
+    for (d = 0; d < pScreen->numDepths; d++)
+       xfree (depths[d].vids);
+    xfree (depths);
+    xfree (pScreen->visuals);
+#ifdef CFB_NEED_SCREEN_PRIVATE
+    xfree (pScreen->devPrivates[cfbScreenPrivateIndex].ptr);
+#else
+    xfree (pScreen->devPrivate);
+#endif
+    return TRUE;
+}
+
+Bool
+cfbSetupScreen(pScreen, pbits, xsize, ysize, dpix, dpiy, width)
+    register ScreenPtr pScreen;
+    pointer pbits;             /* pointer to screen bitmap */
+    int xsize, ysize;          /* in pixels */
+    int dpix, dpiy;            /* dots per inch */
+    int width;                 /* pixel width of frame buffer */
+{
+    int        i;
+    extern RegionPtr   (*cfbPuntCopyPlane)();
+
+    if (!cfbAllocatePrivates(pScreen, (int *) 0, (int *) 0))
+       return FALSE;
+    pScreen->defColormap = FakeClientID(0);
+    /* let CreateDefColormap do whatever it wants for pixels */ 
+    pScreen->blackPixel = pScreen->whitePixel = (Pixel) 0;
+    pScreen->QueryBestSize = mfbQueryBestSize;
+    /* SaveScreen */
+    pScreen->GetImage = cfbGetImage;
+    pScreen->GetSpans = cfbGetSpans;
+    pScreen->CreateWindow = cfbCreateWindow;
+    pScreen->DestroyWindow = cfbDestroyWindow;
+    pScreen->PositionWindow = cfbPositionWindow;
+    pScreen->ChangeWindowAttributes = cfbChangeWindowAttributes;
+    pScreen->RealizeWindow = cfbMapWindow;
+    pScreen->UnrealizeWindow = cfbUnmapWindow;
+    pScreen->PaintWindowBackground = cfbPaintWindow;
+    pScreen->PaintWindowBorder = cfbPaintWindow;
+    pScreen->CopyWindow = cfbCopyWindow;
+    pScreen->CreatePixmap = cfbCreatePixmap;
+    pScreen->DestroyPixmap = cfbDestroyPixmap;
+    pScreen->RealizeFont = mfbRealizeFont;
+    pScreen->UnrealizeFont = mfbUnrealizeFont;
+    pScreen->CreateGC = cfbCreateGC;
+    pScreen->CreateColormap = cfbInitializeColormap;
+    pScreen->DestroyColormap = (void (*)())NoopDDA;
+#ifdef STATIC_COLOR
+    pScreen->InstallColormap = cfbInstallColormap;
+    pScreen->UninstallColormap = cfbUninstallColormap;
+    pScreen->ListInstalledColormaps = cfbListInstalledColormaps;
+    pScreen->StoreColors = (void (*)())NoopDDA;
+#endif
+    pScreen->ResolveColor = cfbResolveColor;
+    pScreen->BitmapToRegion = mfbPixmapToRegion;
+
+    mfbRegisterCopyPlaneProc (pScreen, cfbCopyPlane);
+    return TRUE;
+}
+
+#ifdef CFB_NEED_SCREEN_PRIVATE
+Bool
+cfbCreateScreenResources(pScreen)
+    ScreenPtr pScreen;
+{
+    Bool retval;
+
+    pointer oldDevPrivate = pScreen->devPrivate;
+    pScreen->devPrivate = pScreen->devPrivates[cfbScreenPrivateIndex].ptr;
+    retval = miCreateScreenResources(pScreen);
+    pScreen->devPrivates[cfbScreenPrivateIndex].ptr = pScreen->devPrivate;
+    pScreen->devPrivate = oldDevPrivate;
+    return retval;
+}
+#endif
+
+cfbFinishScreenInit(pScreen, pbits, xsize, ysize, dpix, dpiy, width)
+    register ScreenPtr pScreen;
+    pointer pbits;             /* pointer to screen bitmap */
+    int xsize, ysize;          /* in pixels */
+    int dpix, dpiy;            /* dots per inch */
+    int width;                 /* pixel width of frame buffer */
+{
+    int        i, j;
+#ifdef CFB_NEED_SCREEN_PRIVATE
+    pointer oldDevPrivate;
+#endif
+    VisualPtr  visuals;
+    DepthPtr   depths;
+    int                nvisuals;
+    int                ndepths;
+    int                rootdepth;
+    VisualID   defaultVisual;
+
+    rootdepth = 0;
+    if (!cfbInitVisuals (&visuals, &depths, &nvisuals, &ndepths, &rootdepth,
+                        &defaultVisual,((unsigned long)1<<(PSZ-1)), 8))
+       return FALSE;
+#ifdef CFB_NEED_SCREEN_PRIVATE
+    oldDevPrivate = pScreen->devPrivate;
+#endif
+    if (! miScreenInit(pScreen, pbits, xsize, ysize, dpix, dpiy, width,
+                       rootdepth, ndepths, depths,
+                       defaultVisual, nvisuals, visuals,
+                       (miBSFuncPtr) 0))
+       return FALSE;
+    /* overwrite miCloseScreen with our own */
+    pScreen->CloseScreen = cfbCloseScreen;
+    /* init backing store here so we can overwrite CloseScreen without stepping
+     * on the backing store wrapped version */
+    miInitializeBackingStore (pScreen, &cfbBSFuncRec);
+#ifdef CFB_NEED_SCREEN_PRIVATE
+    pScreen->CreateScreenResources = cfbCreateScreenResources;
+    pScreen->devPrivates[cfbScreenPrivateIndex].ptr = pScreen->devPrivate;
+    pScreen->devPrivate = oldDevPrivate;
+#endif
+    return TRUE;
+}
+
+/* dts * (inch/dot) * (25.4 mm / inch) = mm */
+Bool
+cfbScreenInit(pScreen, pbits, xsize, ysize, dpix, dpiy, width)
+    register ScreenPtr pScreen;
+    pointer pbits;             /* pointer to screen bitmap */
+    int xsize, ysize;          /* in pixels */
+    int dpix, dpiy;            /* dots per inch */
+    int width;                 /* pixel width of frame buffer */
+{
+    if (!cfbSetupScreen(pScreen, pbits, xsize, ysize, dpix, dpiy, width))
+       return FALSE;
+    return cfbFinishScreenInit(pScreen, pbits, xsize, ysize, dpix, dpiy, width);
+}
diff --git a/Xserver/programs/Xserver/cfb/cfbsetsp.c b/Xserver/programs/Xserver/cfb/cfbsetsp.c
new file mode 100644 (file)
index 0000000..e640c19
--- /dev/null
@@ -0,0 +1,308 @@
+/* $XConsortium: cfbsetsp.c,v 5.10 94/04/17 20:29:01 dpw Exp $ */
+/* $XFree86: xc/programs/Xserver/cfb/cfbsetsp.c,v 3.0 1996/06/29 09:05:49 dawes Exp $ */
+/***********************************************************
+
+Copyright (c) 1987  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+
+Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
+
+                        All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and its 
+documentation for any purpose and without fee is hereby granted, 
+provided that the above copyright notice appear in all copies and that
+both that copyright notice and this permission notice appear in 
+supporting documentation, and that the name of Digital not be
+used in advertising or publicity pertaining to distribution of the
+software without specific, written prior permission.  
+
+DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
+ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
+DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
+ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+SOFTWARE.
+
+******************************************************************/
+
+#include "X.h"
+#include "Xmd.h"
+#include "servermd.h"
+
+#include "misc.h"
+#include "regionstr.h"
+#include "gcstruct.h"
+#include "windowstr.h"
+#include "pixmapstr.h"
+#include "scrnintstr.h"
+
+#include "cfb.h"
+#include "cfbmskbits.h"
+#include <mergerop.h>
+
+/* cfbSetScanline -- copies the bits from psrc to the drawable starting at
+ * (xStart, y) and continuing to (xEnd, y).  xOrigin tells us where psrc 
+ * starts on the scanline. (I.e., if this scanline passes through multiple
+ * boxes, we may not want to start grabbing bits at psrc but at some offset
+ * further on.) 
+ */
+cfbSetScanline(y, xOrigin, xStart, xEnd, psrc, alu, pdstBase, widthDst, planemask)
+    int                        y;
+    int                        xOrigin;        /* where this scanline starts */
+    int                        xStart;         /* first bit to use from scanline */
+    int                        xEnd;           /* last bit to use from scanline + 1 */
+    register unsigned int *psrc;
+    register int       alu;            /* raster op */
+    int                        *pdstBase;      /* start of the drawable */
+    int                        widthDst;       /* width of drawable in words */
+    unsigned long      planemask;
+{
+    int                        w;              /* width of scanline in bits */
+    register int       *pdst;          /* where to put the bits */
+    register int       tmpSrc;         /* scratch buffer to collect bits in */
+    int                        dstBit;         /* offset in bits from beginning of 
+                                        * word */
+    register int       nstart;         /* number of bits from first partial */
+    register int       nend;           /* " " last partial word */
+    int                        offSrc;
+    int                startmask, endmask, nlMiddle, nl;
+#if PSZ == 24
+    register char *psrcb, *pdstb;
+    register int       xIndex;
+#endif
+    DeclareMergeRop()
+
+    InitializeMergeRop(alu,planemask);
+#if PSZ == 24
+    pdst = pdstBase + (y * widthDst);
+    xIndex = xStart;
+    pdstb = (char *)pdst + (xStart * 3);
+    offSrc = xStart - xOrigin;
+    psrcb = (char *)psrc + (offSrc * 3);
+#else
+    pdst = pdstBase + (y * widthDst) + (xStart >> PWSH); 
+    psrc += (xStart - xOrigin) >> PWSH;
+    offSrc = (xStart - xOrigin) & PIM;
+#endif
+    w = xEnd - xStart;
+    dstBit = xStart & PIM;
+
+#if PSZ == 24
+    nl = w;
+    while (nl--){
+      psrc = (unsigned int *)((unsigned long)psrcb & ~0x03);
+      getbits24(psrc, tmpSrc, offSrc);
+      pdst = (int *)((unsigned long)pdstb & ~0x03);
+      DoMergeRop24(tmpSrc, pdst, xIndex);
+      offSrc++;
+      psrcb += 3;
+      xIndex++;
+      pdstb += 3;
+    } 
+#else /* PSZ == 24 */
+    if (dstBit + w <= PPW) 
+    { 
+       maskpartialbits(dstBit, w, startmask);
+       endmask = 0;
+       nlMiddle = 0;
+    } 
+    else 
+    { 
+       maskbits(xStart, w, startmask, endmask, nlMiddle);
+    }
+    if (startmask) 
+       nstart = PPW - dstBit; 
+    else 
+       nstart = 0; 
+    if (endmask) 
+       nend = xEnd & PIM; 
+    else 
+       nend = 0; 
+    if (startmask) 
+    { 
+       getbits(psrc, offSrc, nstart, tmpSrc);
+       putbitsmropshort(tmpSrc, dstBit, nstart, pdst);
+       pdst++; 
+       offSrc += nstart;
+       if (offSrc > PLST)
+       {
+           psrc++;
+           offSrc -= PPW;
+       }
+    } 
+    nl = nlMiddle; 
+    while (nl--) 
+    { 
+       getbits(psrc, offSrc, PPW, tmpSrc);
+       *pdst = DoMergeRop(tmpSrc, *pdst);
+       pdst++; 
+       psrc++; 
+    } 
+    if (endmask) 
+    { 
+       getbits(psrc, offSrc, nend, tmpSrc);
+       putbitsmropshort(tmpSrc, 0, nend, pdst);
+    } 
+#endif /* PSZ == 24 */
+}
+
+\f
+
+/* SetSpans -- for each span copy pwidth[i] bits from psrc to pDrawable at
+ * ppt[i] using the raster op from the GC.  If fSorted is TRUE, the scanlines
+ * are in increasing Y order.
+ * Source bit lines are server scanline padded so that they always begin
+ * on a word boundary.
+ */ 
+void
+cfbSetSpans(pDrawable, pGC, pcharsrc, ppt, pwidth, nspans, fSorted)
+    DrawablePtr                pDrawable;
+    GCPtr              pGC;
+    char               *pcharsrc;
+    register DDXPointPtr ppt;
+    int                        *pwidth;
+    int                        nspans;
+    int                        fSorted;
+{
+    unsigned int       *psrc = (unsigned int *)pcharsrc;
+    unsigned long      *pdstBase;      /* start of dst bitmap */
+    int                widthDst;       /* width of bitmap in words */
+    register BoxPtr    pbox, pboxLast, pboxTest;
+    register DDXPointPtr pptLast;
+    int                alu;
+    RegionPtr          prgnDst;
+    int                        xStart, xEnd;
+    int                        yMax;
+
+    alu = pGC->alu;
+    prgnDst = cfbGetCompositeClip(pGC);
+    pptLast = ppt + nspans;
+
+    cfbGetLongWidthAndPointer (pDrawable, widthDst, pdstBase)
+
+    yMax = (int) pDrawable->y + (int) pDrawable->height;
+
+    pbox = REGION_RECTS(prgnDst);
+    pboxLast = pbox + REGION_NUM_RECTS(prgnDst);
+
+    if(fSorted)
+    {
+    /* scan lines sorted in ascending order. Because they are sorted, we
+     * don't have to check each scanline against each clip box.  We can be
+     * sure that this scanline only has to be clipped to boxes at or after the
+     * beginning of this y-band 
+     */
+       pboxTest = pbox;
+       while(ppt < pptLast)
+       {
+           pbox = pboxTest;
+           if(ppt->y >= yMax)
+               break;
+           while(pbox < pboxLast)
+           {
+               if(pbox->y1 > ppt->y)
+               {
+                   /* scanline is before clip box */
+                   break;
+               }
+               else if(pbox->y2 <= ppt->y)
+               {
+                   /* clip box is before scanline */
+                   pboxTest = ++pbox;
+                   continue;
+               }
+               else if(pbox->x1 > ppt->x + *pwidth) 
+               {
+                   /* clip box is to right of scanline */
+                   break;
+               }
+               else if(pbox->x2 <= ppt->x)
+               {
+                   /* scanline is to right of clip box */
+                   pbox++;
+                   continue;
+               }
+
+               /* at least some of the scanline is in the current clip box */
+               xStart = max(pbox->x1, ppt->x);
+               xEnd = min(ppt->x + *pwidth, pbox->x2);
+               cfbSetScanline(ppt->y, ppt->x, xStart, xEnd, psrc, alu,
+                   (int *)pdstBase, widthDst, pGC->planemask);
+               if(ppt->x + *pwidth <= pbox->x2)
+               {
+                   /* End of the line, as it were */
+                   break;
+               }
+               else
+                   pbox++;
+           }
+           /* We've tried this line against every box; it must be outside them
+            * all.  move on to the next point */
+           ppt++;
+           psrc += PixmapWidthInPadUnits(*pwidth, pDrawable->depth);
+           pwidth++;
+       }
+    }
+    else
+    {
+    /* scan lines not sorted. We must clip each line against all the boxes */
+       while(ppt < pptLast)
+       {
+           if(ppt->y >= 0 && ppt->y < yMax)
+           {
+               
+               for(pbox = REGION_RECTS(prgnDst); pbox< pboxLast; pbox++)
+               {
+                   if(pbox->y1 > ppt->y)
+                   {
+                       /* rest of clip region is above this scanline,
+                        * skip it */
+                       break;
+                   }
+                   if(pbox->y2 <= ppt->y)
+                   {
+                       /* clip box is below scanline */
+                       pbox++;
+                       break;
+                   }
+                   if(pbox->x1 <= ppt->x + *pwidth &&
+                      pbox->x2 > ppt->x)
+                   {
+                       xStart = max(pbox->x1, ppt->x);
+                       xEnd = min(pbox->x2, ppt->x + *pwidth);
+                       cfbSetScanline(ppt->y, ppt->x, xStart, xEnd, psrc, alu,
+                           (int *)pdstBase, widthDst, pGC->planemask);
+                   }
+
+               }
+           }
+       psrc += PixmapWidthInPadUnits(*pwidth, pDrawable->depth);
+       ppt++;
+       pwidth++;
+       }
+    }
+}
+
diff --git a/Xserver/programs/Xserver/cfb/cfbsolid.c b/Xserver/programs/Xserver/cfb/cfbsolid.c
new file mode 100644 (file)
index 0000000..d7e9a03
--- /dev/null
@@ -0,0 +1,1329 @@
+/*
+ * $XConsortium: cfbsolid.c,v 1.9 94/04/17 20:29:02 dpw Exp $
+ * $XFree86: xc/programs/Xserver/cfb/cfbsolid.c,v 3.0 1996/06/29 09:05:51 dawes Exp $
+ *
+Copyright (c) 1990  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+ *
+ * Author:  Keith Packard, MIT X Consortium
+ */
+
+
+#include "X.h"
+#include "Xmd.h"
+#include "servermd.h"
+#include "gcstruct.h"
+#include "window.h"
+#include "pixmapstr.h"
+#include "scrnintstr.h"
+#include "windowstr.h"
+
+#include "cfb.h"
+#include "cfbmskbits.h"
+#include "cfbrrop.h"
+
+#include "mi.h"
+#include "mispans.h"
+
+#if defined(FAST_CONSTANT_OFFSET_MODE) && (RROP != GXcopy)
+# define Expand(left,right,leftAdjust) {\
+    int part = nmiddle & 3; \
+    int widthStep; \
+    widthStep = widthDst - nmiddle - leftAdjust; \
+    nmiddle >>= 2; \
+    pdst = pdstRect; \
+    while (h--) { \
+       left \
+       pdst += part; \
+       switch (part) { \
+           RROP_UNROLL_CASE3(pdst) \
+       } \
+       m = nmiddle; \
+       while (m) { \
+           pdst += 4; \
+           RROP_UNROLL_LOOP4(pdst,-4) \
+           m--; \
+       } \
+       right \
+       pdst += widthStep; \
+    } \
+}
+#else
+# ifdef RROP_UNROLL
+#  define Expand(left,right,leftAdjust) {\
+    int part = nmiddle & RROP_UNROLL_MASK; \
+    int widthStep; \
+    widthStep = widthDst - nmiddle - leftAdjust; \
+    nmiddle >>= RROP_UNROLL_SHIFT; \
+    pdst = pdstRect; \
+    while (h--) { \
+       left \
+       pdst += part; \
+       switch (part) { \
+           RROP_UNROLL_CASE(pdst) \
+       } \
+       m = nmiddle; \
+       while (m) { \
+           pdst += RROP_UNROLL; \
+           RROP_UNROLL_LOOP(pdst) \
+           m--; \
+       } \
+       right \
+       pdst += widthStep; \
+    } \
+}
+
+# else
+#  define Expand(left, right, leftAdjust) { \
+    while (h--) { \
+       pdst = pdstRect; \
+       left \
+       m = nmiddle; \
+       while (m--) {\
+           RROP_SOLID(pdst); \
+           pdst++; \
+       } \
+       right \
+       pdstRect += widthDst; \
+    } \
+}
+# endif
+#endif
+       
+
+void
+RROP_NAME(cfbFillRectSolid) (pDrawable, pGC, nBox, pBox)
+    DrawablePtr            pDrawable;
+    GCPtr          pGC;
+    int                    nBox;
+    BoxPtr         pBox;
+{
+    register int    m;
+    register unsigned long   *pdst;
+    RROP_DECLARE
+    register unsigned long   leftMask, rightMask;
+    unsigned long   *pdstBase, *pdstRect;
+    int                    nmiddle;
+    int                    h;
+    int                    w;
+    int                    widthDst;
+    cfbPrivGCPtr    devPriv;
+#if PSZ == 24
+    int leftIndex, rightIndex, xOffset;
+#endif
+
+    devPriv = cfbGetGCPrivate(pGC);
+
+    cfbGetLongWidthAndPointer (pDrawable, widthDst, pdstBase)
+
+    RROP_FETCH_GC(pGC)
+    
+    for (; nBox; nBox--, pBox++)
+    {
+       pdstRect = pdstBase + pBox->y1 * widthDst;
+       h = pBox->y2 - pBox->y1;
+       w = pBox->x2 - pBox->x1;
+#if PSZ == 8
+       if (w == 1)
+       {
+           register char    *pdstb = ((char *) pdstRect) + pBox->x1;
+           int     incr = widthDst * PGSZB;
+
+           while (h--)
+           {
+               RROP_SOLID (pdstb);
+               pdstb += incr;
+           }
+       }
+       else
+       {
+#endif
+#if PSZ == 24
+       leftIndex = pBox->x1 &3;
+/*     rightIndex = ((leftIndex+w)<5)?0:pBox->x2 &3;*/
+       rightIndex = pBox->x2 &3;
+
+       nmiddle = w - rightIndex;
+       if(leftIndex){
+         nmiddle -= (4 - leftIndex);
+       }
+       nmiddle >>= 2;
+       if(nmiddle < 0)
+         nmiddle = 0;
+
+       pdstRect += (pBox->x1 * 3) >> 2;
+       pdst = pdstRect;        
+       switch(leftIndex+w){
+       case 4:
+           switch(leftIndex){
+           case 0:
+               while(h--){
+#if RROP == GXcopy
+                   *pdst++ = piQxelXor[0];
+                   *pdst++ = piQxelXor[1];
+                   *pdst-- = piQxelXor[2];
+#endif
+#if RROP == GXxor
+                   *pdst++ ^= piQxelXor[0];
+                   *pdst++ ^= piQxelXor[1];
+                   *pdst-- ^= piQxelXor[2];
+#endif
+#if RROP == GXand
+                   *pdst++ &= piQxelAnd[0];
+                   *pdst++ &= piQxelAnd[1];
+                   *pdst-- &= piQxelAnd[2];
+#endif
+#if RROP == GXor
+                   *pdst++ |= piQxelOr[0];
+                   *pdst++ |= piQxelOr[1];
+                   *pdst-- |= piQxelOr[2];
+#endif
+#if RROP == GXset
+                   *pdst = DoRRop((*pdst), piQxelAnd[0], piQxelXor[0]);
+                   pdst++;
+                   *pdst = DoRRop((*pdst), piQxelAnd[1], piQxelXor[1]);
+                   pdst++;
+                   *pdst = DoRRop((*pdst), piQxelAnd[2], piQxelXor[2]);
+                   pdst--;
+#endif
+                   pdst--;
+                   pdst += widthDst;
+               }
+               break;
+           case 1:
+               while(h--){
+#if RROP == GXcopy
+                   *pdst++ = ((*pdst) & 0xFFFFFF) | (piQxelXor[0] & 0xFF000000);
+                   *pdst++ = piQxelXor[1];
+                   *pdst-- = piQxelXor[2];
+#endif
+#if RROP == GXxor
+                   *pdst++ ^= (piQxelXor[0] & 0xFF000000);
+                   *pdst++ ^= piQxelXor[1];
+                   *pdst-- ^= piQxelXor[2];
+#endif
+#if RROP == GXand
+                   *pdst++ &= (piQxelAnd[0] | 0x00FFFFFF);
+                   *pdst++ &= piQxelAnd[1];
+                   *pdst-- &= piQxelAnd[2];
+#endif
+#if RROP == GXor
+                   *pdst++ |= (piQxelOr[0] & 0xFF000000);
+                   *pdst++ |= piQxelOr[1];
+                   *pdst-- |= piQxelOr[2];
+#endif
+#if RROP == GXset
+                   *pdst = DoMaskRRop((*pdst), piQxelAnd[0], piQxelXor[0], 0xFF000000);
+                   pdst++;
+                   *pdst = DoRRop((*pdst), piQxelAnd[1], piQxelXor[1]);
+                   pdst++;
+                   *pdst = DoRRop((*pdst), piQxelAnd[2], piQxelXor[2]);
+                   pdst--;
+#endif
+                   pdst--;
+                   pdst += widthDst;
+               }
+               break;
+           case 2:
+               while(h--){
+#if RROP == GXcopy
+                   *pdst++ = ((*pdst) & 0xFFFF) | (piQxelXor[1] & 0xFFFF0000);
+                   *pdst-- = piQxelXor[2];
+#endif
+#if RROP == GXxor
+                   *pdst++ ^= (piQxelXor[1] & 0xFFFF0000);
+                   *pdst-- ^= piQxelXor[2];
+#endif
+#if RROP == GXand
+                   *pdst++ &= (piQxelAnd[1] | 0xFFFF);
+                   *pdst-- &= piQxelAnd[2];
+#endif
+#if RROP == GXor
+                   *pdst++ |= (piQxelOr[1] & 0xFFFF0000);
+                   *pdst-- |= piQxelOr[2];
+#endif
+#if RROP == GXset
+                   *pdst = DoMaskRRop((*pdst), piQxelAnd[1], piQxelXor[1], 0xFFFF0000);
+                   pdst++;
+                   *pdst = DoRRop((*pdst), piQxelAnd[2], piQxelXor[2]);
+                   pdst--;
+#endif
+                   pdst += widthDst;
+               }
+               break;
+           case 3:
+               while(h--){
+#if RROP == GXcopy
+                   *pdst = ((*pdst) & 0xFF) | (piQxelXor[2] & 0xFFFFFF00);
+#endif
+#if RROP == GXxor
+                   *pdst ^= (piQxelXor[2] & 0xFFFFFF00);
+#endif
+#if RROP == GXand
+                   *pdst &= (piQxelAnd[2] | 0xFF);
+#endif
+#if RROP == GXor
+                   *pdst |= (piQxelOr[2] & 0xFFFFFF00);
+#endif
+#if RROP == GXset
+                   *pdst = DoMaskRRop((*pdst), piQxelAnd[2], piQxelXor[2], 0xFFFFFF00);
+#endif
+                   pdst += widthDst;
+               }
+               break;
+           }
+           break;
+       case 3:
+           switch(leftIndex){
+           case 0:
+               while(h--){
+#if RROP == GXcopy
+                   *pdst++ = piQxelXor[0];
+                   *pdst++ = piQxelXor[1];
+                   *pdst-- = ((*pdst) & 0xFFFFFF00) | (piQxelXor[2] & 0xFF);
+#endif
+#if RROP == GXxor
+                   *pdst++ ^= piQxelXor[0];
+                   *pdst++ ^= piQxelXor[1];
+                   *pdst-- ^= (piQxelXor[2] & 0xFF);
+#endif
+#if RROP == GXand
+                   *pdst++ &= piQxelAnd[0];
+                   *pdst++ &= piQxelAnd[1];
+                   *pdst-- &= (piQxeAnd[2] | 0xFFFFFF00);
+#endif
+#if RROP == GXor
+                   *pdst++ |= piQxelOr[0];
+                   *pdst++ |= piQxelOr[1];
+                   *pdst-- |= (piQxelOr[2] & 0xFF);
+#endif
+#if RROP == GXset
+                   *pdst = DoRRop((*pdst), piQxelAnd[0], piQxelXor[0]);
+                   pdst++;
+                   *pdst = DoRRop((*pdst), piQxelAnd[1], piQxelXor[1]);
+                   pdst++;
+                   *pdst = DoMaskRRop((*pdst), piQxelAnd[2], piQxelXor[2], 0xFF);
+                   pdst--;
+#endif
+                   pdst--;
+                   pdst += widthDst;
+               }
+               break;
+           case 1:
+               while(h--){
+#if RROP == GXcopy
+                   *pdst++ = ((*pdst) & 0xFFFFFF) | (piQxelXor[0] & 0xFF000000);
+                   *pdst++ = piQxelXor[1];
+                   *pdst-- = ((*pdst) & 0xFFFFFF00) | (piQxelXor[2] & 0xFF);
+#endif
+#if RROP == GXxor
+                   *pdst++ ^= (piQxelXor[0] & 0xFF000000);
+                   *pdst++ ^= piQxelXor[1];
+                   *pdst-- ^= (piQxelXor[2] & 0xFF);
+#endif
+#if RROP == GXand
+                   *pdst++ &= (piQxelAnd[0] | 0x00FFFFFF);
+                   *pdst++ &= piQxelAnd[1];
+                   *pdst-- &= (piQxelAnd[2] | 0xFFFFFF00);
+#endif
+#if RROP == GXor
+                   *pdst++ |= (piQxelOr[0] & 0xFF000000);
+                   *pdst++ |= piQxelOr[1];
+                   *pdst-- |= (piQxelOr[2] & 0xFF);
+#endif
+#if RROP == GXset
+                   *pdst = DoMaskRRop((*pdst), piQxelAnd[0], piQxelXor[0], 0xFF000000);
+                   pdst++;
+                   *pdst = DoRRop((*pdst), piQxelAnd[1], piQxelXor[1]);
+                   pdst++;
+                   *pdst = DoMaskRRop((*pdst), piQxelAnd[2], piQxelXor[2], 0xFF);
+                   pdst--;
+#endif
+                   pdst--;
+                   pdst += widthDst;
+               }
+               break;
+           case 2:
+               while(h--){
+#if RROP == GXcopy
+                   *pdst++ = ((*pdst) & 0xFFFF) | (piQxelXor[1] & 0xFFFF0000);
+                   *pdst-- = ((*pdst) & 0xFFFFFF00) | (piQxelXor[2] & 0xFF);
+#endif
+#if RROP == GXxor
+                   *pdst++ ^= (piQxelXor[1] & 0xFFFF0000);
+                   *pdst-- ^= (piQxelXor[2] & 0xFF);
+#endif
+#if RROP == GXand
+                   *pdst++ &= (piQxelAnd[1] | 0xFFFF);
+                   *pdst-- &= (piQxelAnd[2] | 0xFFFFFF00);
+#endif
+#if RROP == GXor
+                   *pdst++ |= (piQxelOr[1] & 0xFFFF0000);
+                   *pdst-- |= (piQxelOr[2] & 0xFF);
+#endif
+#if RROP == GXset
+                   *pdst = DoMaskRRop((*pdst), piQxelAnd[1], piQxelXor[1], 0xFFFF0000);
+                   pdst++;
+                   *pdst = DoMaskRRop((*pdst), piQxelAnd[2], piQxelXor[2], 0xFF);
+                   pdst--;
+#endif
+                   pdst += widthDst;
+               }
+               break;
+           case 3:
+               while(h--){
+#if RROP == GXcopy
+                   *pdst = ((*pdst) & 0xFF) | (piQxelXor[2] & 0xFFFFFF00);
+#endif
+#if RROP == GXxor
+                   *pdst ^= (piQxelXor[2] & 0xFFFFFF00);
+#endif
+#if RROP == GXand
+                   *pdst &= (piQxelAnd[2] | 0xFF);
+#endif
+#if RROP == GXor
+                   *pdst |= (piQxelOr[2] & 0xFFFFFF00);
+#endif
+#if RROP == GXset
+                   *pdst = DoMaskRRop((*pdst), piQxelAnd[2], piQxelXor[2], 0xFFFFFF00);
+#endif
+                   pdst += widthDst;
+               }
+               break;
+           }
+           break;
+       case 2: /* leftIndex + w = 2*/
+           switch(leftIndex){
+           case 2:
+               while(h--){
+#if RROP == GXcopy
+                   *pdst++ = ((*pdst) & 0xFFFF) | (piQxelXor[1] & 0xFFFF0000);
+                   *pdst-- = ((*pdst) & 0xFFFFFF00) | (piQxelXor[2] & 0xFF);
+#endif
+#if RROP == GXxor
+                   *pdst++ ^= (piQxelXor[1] & 0xFFFF0000);
+                   *pdst-- ^= (piQxelXor[2] & 0xFF);
+#endif
+#if RROP == GXand
+                   *pdst++ &= (piQxelAnd[1] | 0xFFFF0000);
+                   *pdst-- &= (piQxelAnd[2] | 0xFF);
+#endif
+#if RROP == GXor
+                   *pdst++ |= (piQxelOr[1] & 0xFFFF0000);
+                   *pdst-- |= (piQxelOr[2] & 0xFF);
+#endif
+#if RROP == GXset
+                   *pdst = DoMaskRRop((*pdst), piQxelAnd[1], piQxelXor[1], 0xFFFF0000);
+                   pdst++;
+                   *pdst = DoMaskRRop((*pdst), piQxelAnd[2], piQxelXor[2], 0xFF);
+                   pdst--;
+#endif
+                   pdst += widthDst;
+                 }
+               break;
+           case 1:
+               while(h--){
+#if RROP == GXcopy
+                   *pdst++ = ((*pdst) & 0xFFFFFF) | (piQxelXor[0] & 0xFF000000);
+                   *pdst-- = ((*pdst) & 0xFFFF0000) | (piQxelXor[1] & 0xFFFF);
+#endif
+#if RROP == GXxor
+                   *pdst++ ^= (piQxelXor[0] & 0xFF000000);
+                   *pdst-- ^= (piQxelXor[1] & 0xFFFF);
+#endif
+#if RROP == GXand
+                   *pdst++ &= (piQxelAnd[0] | 0xFFFFFF);
+                   *pdst-- &= (piQxelAnd[1] | 0xFFFF0000);
+#endif
+#if RROP == GXor
+                   *pdst++ |= (piQxelOr[0] & 0xFF000000);
+                   *pdst-- |= (piQxelOr[1] & 0xFFFF);
+#endif
+#if RROP == GXset
+                   *pdst = DoMaskRRop((*pdst), piQxelAnd[0], piQxelXor[0], 0xFF000000);
+                   pdst++;
+                   *pdst = DoMaskRRop((*pdst), piQxelAnd[1], piQxelXor[1], 0xFFFF);
+                   pdst--;
+#endif
+                   pdst += widthDst;
+                 }
+               break;
+           case 0: /*case 2 leftIndex == 0 */
+               while(h--){
+#if RROP == GXcopy
+                   *pdst++ = piQxelXor[0];
+                   *pdst-- = ((*pdst) & 0xFFFF0000) | (piQxelXor[1] & 0xFFFF);
+#endif
+#if RROP == GXxor
+                   *pdst++ ^= piQxelXor[0];
+                   *pdst-- ^= (piQxelXor[1] & 0xFFFF);
+#endif
+#if RROP == GXand
+                   *pdst++ &= piQxelAnd[0];
+                   *pdst-- &= (piQxelAnd[1] | 0xFFFF0000);
+#endif
+#if RROP == GXor
+                   *pdst++ |= piQxelOr[0];
+                   *pdst-- |= (piQxelOr[1] & 0xFFFF);
+#endif
+#if RROP == GXset
+                   *pdst = DoRRop((*pdst), piQxelAnd[0], piQxelXor[0]);
+                   pdst++;
+                   *pdst = DoMaskRRop((*pdst), piQxelAnd[1], piQxelXor[1], 0xFFFF);
+                   pdst--;
+#endif
+                   pdst += widthDst;
+               }
+               break;
+           }
+           break;
+       case 1: /*only if leftIndex = 0 and w = 1*/
+           while(h--){
+#if RROP == GXcopy
+               *pdst = ((*pdst) & 0xFF000000) | (piQxelXor[0] & 0xFFFFFF);
+#endif
+#if RROP == GXxor
+               *pdst ^= (piQxelXor[0] & 0xFFFFFF);
+#endif
+#if RROP == GXand
+               *pdst &= (piQxelAnd[0] | 0xFF000000);
+#endif
+#if RROP == GXor
+               *pdst |= (piQxelOr[0] & 0xFFFFFF);
+#endif
+#if RROP == GXset
+               *pdst = DoMaskRRop((*pdst), piQxelAnd[0], piQxelXor[0], 0xFFFFFF);
+#endif
+               pdst += widthDst;
+           }
+           break;
+       case 0: /*never*/
+           break;
+       default:
+           {
+               while(h--){
+                   pdst = pdstRect;
+                   switch(leftIndex){
+                   case 0:
+                       break;
+                   case 1:
+#if RROP == GXcopy
+                       *pdst++ = ((*pdst) & 0xFFFFFF) | (piQxelXor[0] & 0xFF000000);
+                       *pdst++ = piQxelXor[1];
+                       *pdst++ = piQxelXor[2];
+#endif
+#if RROP == GXxor
+                       *pdst++ ^= (piQxelXor[0] & 0xFF000000);
+                       *pdst++ ^= piQxelXor[1];
+                       *pdst++ ^= piQxelXor[2];
+#endif
+#if RROP == GXand
+                       *pdst++ &= (piQxelAnd[0] | 0xFFFFFF);
+                       *pdst++ &= piQxelAnd[1];
+                       *pdst++ &= piQxelAnd[2];
+#endif
+#if RROP == GXor
+                       *pdst++ |= (piQxelOr[0] & 0xFF000000);
+                       *pdst++ |= piQxelOr[1];
+                       *pdst++ |= piQxelOr[2];
+#endif
+#if RROP == GXset
+                       *pdst = DoMaskRRop((*pdst), piQxelAnd[0], piQxelXor[0], 0xFF000000);
+                       pdst++;
+                       *pdst = DoRRop((*pdst), piQxelAnd[1], piQxelXor[1]);
+                       pdst++;
+                       *pdst = DoRRop((*pdst), piQxelAnd[2], piQxelXor[2]);
+                       pdst++;
+#endif
+                   break;
+                   case 2:
+#if RROP == GXcopy
+                       *pdst++ = (((*pdst) & 0xFFFF) | (piQxelXor[1] & 0xFFFF0000));
+                       *pdst++ = piQxelXor[2];
+#endif
+#if RROP == GXxor
+                       *pdst++ ^=(piQxelXor[1] & 0xFFFF0000);
+                       *pdst++ ^= piQxelXor[2];
+#endif
+#if RROP == GXand
+                       *pdst++ &= (piQxelAnd[1] | 0xFFFF);
+                       *pdst++ &= piQxelAnd[2];
+#endif
+#if RROP == GXor
+                       *pdst++ |= (piQxelOr[1] & 0xFFFF0000);
+                       *pdst++ |= piQxelOr[2];
+#endif
+#if RROP == GXset
+                       *pdst = DoMaskRRop((*pdst), piQxelAnd[1], piQxelXor[1], 0xFFFF0000);
+                       pdst++;
+                       *pdst = DoRRop((*pdst), piQxelAnd[2], piQxelXor[2]);
+                       pdst++;
+#endif
+                       break;
+                   case 3:
+#if RROP == GXcopy
+                       *pdst++ = ((*pdst) & 0xFF) | (piQxelXor[2] & 0xFFFFFF00);
+#endif
+#if RROP == GXxor
+                       *pdst++ ^= (piQxelXor[2] & 0xFFFFFF00);
+#endif
+#if RROP == GXand
+                       *pdst++ &= (piQxelAnd[2] | 0xFF);
+#endif
+#if RROP == GXor
+                       *pdst++ |= (piQxelOr[2] & 0xFFFFFF00);
+#endif
+#if RROP == GXset
+                       *pdst = DoMaskRRop((*pdst), piQxelAnd[2], piQxelXor[2], 0xFFFFFF00);
+                       pdst++;
+#endif
+                       break;
+                     }
+                   m = nmiddle;
+                   while(m--){
+#if RROP == GXcopy
+                       *pdst++ = piQxelXor[0];
+                       *pdst++ = piQxelXor[1];
+                       *pdst++ = piQxelXor[2];
+#endif
+#if RROP == GXxor
+                       *pdst++ ^= piQxelXor[0];
+                       *pdst++ ^= piQxelXor[1];
+                       *pdst++ ^= piQxelXor[2];
+#endif
+#if RROP == GXand
+                       *pdst++ &= piQxelAnd[0];
+                       *pdst++ &= piQxelAnd[1];
+                       *pdst++ &= piQxelAnd[2];
+#endif
+#if RROP == GXor
+                       *pdst++ |= piQxelOr[0];
+                       *pdst++ |= piQxelOr[1];
+                       *pdst++ |= piQxelOr[2];
+#endif
+#if RROP == GXset
+                       *pdst = DoRRop((*pdst), piQxelAnd[0], piQxelXor[0]);
+                       pdst++;
+                       *pdst = DoRRop((*pdst), piQxelAnd[1], piQxelXor[1]);
+                       pdst++;
+                       *pdst = DoRRop((*pdst), piQxelAnd[2], piQxelXor[2]);
+                       pdst++;
+#endif
+               }
+               switch(rightIndex){
+               case 0:
+                 break;
+               case 1:
+#if RROP == GXcopy
+                 *pdst++ = ((*pdst) & 0xFF000000) | (piQxelXor[0] & 0xFFFFFF);
+#endif
+#if RROP == GXxor
+                 *pdst++ ^= (piQxelXor[0] & 0xFFFFFF);
+#endif
+#if RROP == GXand
+                 *pdst++ &= (piQxelAnd[0] | 0xFF);
+#endif
+#if RROP == GXor
+                 *pdst++ |= (piQxelOr[0] & 0xFFFFFF);
+#endif
+#if RROP == GXset
+                 *pdst++ = DoMaskRRop((*pdst), piQxelAnd[0], piQxelXor[0], 0xFFFFFF);
+#endif
+                 break;
+               case 2:
+#if RROP == GXcopy
+                 *pdst++ = piQxelXor[0];
+                 *pdst++ = ((*pdst) & 0xFFFF0000) | (piQxelXor[1] & 0xFFFF);
+#endif
+#if RROP == GXxor
+                 *pdst++ ^= piQxelXor[0];
+                 *pdst++ ^= (piQxelXor[1] & 0xFFFF);
+#endif
+#if RROP == GXand
+                 *pdst++ &= piQxelAnd[0];
+                 *pdst++ &= (piQxelAnd[1] | 0xFFFF0000);
+#endif
+#if RROP == GXor
+                 *pdst++ |= piQxelOr[0];
+                 *pdst++ |= (piQxelOr[1] & 0xFFFF);
+#endif
+#if RROP == GXset
+                 *pdst = DoRRop((*pdst), piQxelAnd[0], piQxelXor[0]);
+                 *pdst++;
+                 *pdst = DoMaskRRop((*pdst), piQxelAnd[1], piQxelXor[1], 0xFFFF);
+                 *pdst++;
+#endif
+                 break;
+               case 3:
+#if RROP == GXcopy
+                 *pdst++ = piQxelXor[0];
+                 *pdst++ = piQxelXor[1];
+                 *pdst++ = ((*pdst) & 0xFFFFFF00) | (piQxelXor[2] & 0xFF);
+#endif
+#if RROP == GXxor
+                 *pdst++ ^= piQxelXor[0];
+                 *pdst++ ^= piQxelXor[1];
+                 *pdst++ ^= (piQxelXor[2] & 0xFF);
+#endif
+#if RROP == GXand
+                 *pdst++ &= piQxelAnd[0];
+                 *pdst++ &= piQxelAnd[1];
+                 *pdst++ &= (piQxelAnd[2] | 0xFFFFFF00);
+#endif
+#if RROP == GXor
+                 *pdst++ |= piQxelOr[0];
+                 *pdst++ |= piQxelOr[1];
+                 *pdst++ |= (piQxelOr[2] & 0xFF);
+#endif
+#if RROP == GXset
+                 *pdst = DoRRop((*pdst), piQxelAnd[0], piQxelXor[0]);
+                 pdst++;
+                 *pdst = DoRRop((*pdst), piQxelAnd[1], piQxelXor[1]);
+                 pdst++;
+                 *pdst = DoMaskRRop((*pdst), piQxelAnd[2], piQxelXor[2], 0xFF);
+                 pdst++;
+#endif
+                 break;
+               }
+               pdstRect += widthDst;
+           }
+       }
+       }
+#else /* PSZ != 24 */
+       pdstRect += (pBox->x1 >> PWSH);
+       if ((pBox->x1 & PIM) + w <= PPW)
+       {
+           maskpartialbits(pBox->x1, w, leftMask);
+           pdst = pdstRect;
+           while (h--) {
+               RROP_SOLID_MASK (pdst, leftMask);
+               pdst += widthDst;
+           }
+       }
+       else
+       {
+           maskbits (pBox->x1, w, leftMask, rightMask, nmiddle);
+           if (leftMask)
+           {
+               if (rightMask)  /* left mask and right mask */
+               {
+                   Expand(RROP_SOLID_MASK (pdst, leftMask); pdst++;,
+                          RROP_SOLID_MASK (pdst, rightMask);, 1)
+               }
+               else    /* left mask and no right mask */
+               {
+                   Expand(RROP_SOLID_MASK (pdst, leftMask); pdst++;,
+                          ;, 1)
+               }
+           }
+           else
+           {
+               if (rightMask)  /* no left mask and right mask */
+               {
+                   Expand(;,
+                          RROP_SOLID_MASK (pdst, rightMask);, 0)
+               }
+               else    /* no left mask and no right mask */
+               {
+                   Expand(;,
+                           ;, 0)
+               }
+           }
+       }
+#endif
+#if PSZ == 8
+       }
+#endif
+    }
+}
+
+void
+RROP_NAME(cfbSolidSpans) (pDrawable, pGC, nInit, pptInit, pwidthInit, fSorted)
+    DrawablePtr pDrawable;
+    GCPtr      pGC;
+    int                nInit;                  /* number of spans to fill */
+    DDXPointPtr pptInit;               /* pointer to list of start points */
+    int                *pwidthInit;            /* pointer to list of n widths */
+    int        fSorted;
+{
+    unsigned long   *pdstBase;
+    int                    widthDst;
+
+    RROP_DECLARE
+    
+    register unsigned long  *pdst;
+    register int           nlmiddle;
+    register unsigned long  startmask, endmask;
+    register int           w;
+    int                            x;
+    
+                               /* next three parameters are post-clip */
+    int                    n;          /* number of spans to fill */
+    DDXPointPtr            ppt;        /* pointer to list of start points */
+    int                    *pwidthFree;/* copies of the pointers to free */
+    DDXPointPtr            pptFree;
+    int                    *pwidth;
+    cfbPrivGCPtr    devPriv;
+#if PSZ == 24
+    int leftIndex, rightIndex, xOffset;
+#endif
+
+    devPriv = cfbGetGCPrivate(pGC);
+    RROP_FETCH_GCPRIV(devPriv)
+    n = nInit * miFindMaxBand(devPriv->pCompositeClip);
+    pwidthFree = (int *)ALLOCATE_LOCAL(n * sizeof(int));
+    pptFree = (DDXPointRec *)ALLOCATE_LOCAL(n * sizeof(DDXPointRec));
+    if(!pptFree || !pwidthFree)
+    {
+       if (pptFree) DEALLOCATE_LOCAL(pptFree);
+       if (pwidthFree) DEALLOCATE_LOCAL(pwidthFree);
+       return;
+    }
+    pwidth = pwidthFree;
+    ppt = pptFree;
+    n = miClipSpans(devPriv->pCompositeClip,
+                    pptInit, pwidthInit, nInit,
+                    ppt, pwidth, fSorted);
+
+    cfbGetLongWidthAndPointer (pDrawable, widthDst, pdstBase)
+
+    while (n--)
+    {
+       x = ppt->x;
+       pdst = pdstBase + (ppt->y * widthDst);
+       ++ppt;
+       w = *pwidth++;
+       if (!w)
+           continue;
+#if PSZ == 24
+       leftIndex = x &3;
+/*     rightIndex = ((leftIndex+w)<5)?0:(x+w)&3;*/
+       rightIndex = (x+w)&3;
+
+       nlmiddle = w - rightIndex;
+       if(leftIndex){
+         nlmiddle -= (4 - leftIndex);
+       }
+/*     nlmiddle += 3;*/
+       nlmiddle >>= 2;
+       if(nlmiddle < 0)
+         nlmiddle = 0;
+
+       pdst += (x >> 2)*3;
+       pdst += leftIndex? (leftIndex -1):0;
+       switch(leftIndex+w){
+       case 4:
+           switch(leftIndex){
+           case 0:
+#if RROP == GXcopy
+                   *pdst++ = piQxelXor[0];
+                   *pdst++ = piQxelXor[1];
+                   *pdst-- = piQxelXor[2];
+#endif
+#if RROP == GXxor
+                   *pdst++ ^= piQxelXor[0];
+                   *pdst++ ^= piQxelXor[1];
+                   *pdst-- ^= piQxelXor[2];
+#endif
+#if RROP == GXand
+                   *pdst++ &= piQxelAnd[0];
+                   *pdst++ &= piQxelAnd[1];
+                   *pdst-- &= piQxelAnd[2];
+#endif
+#if RROP == GXor
+                   *pdst++ |= piQxelOr[0];
+                   *pdst++ |= piQxelOr[1];
+                   *pdst-- |= piQxelOr[2];
+#endif
+#if RROP == GXset
+                   *pdst = DoRRop((*pdst), piQxelAnd[0], piQxelXor[0]);
+                   pdst++;
+                   *pdst = DoRRop((*pdst), piQxelAnd[1], piQxelXor[1]);
+                   pdst++;
+                   *pdst = DoRRop((*pdst), piQxelAnd[2], piQxelXor[2]);
+                   pdst--;
+#endif
+                   pdst--;
+               break;
+           case 1:
+#if RROP == GXcopy
+                   *pdst++ = ((*pdst) & 0xFFFFFF) | (piQxelXor[0] & 0xFF000000);
+                   *pdst++ = piQxelXor[1];
+                   *pdst-- = piQxelXor[2];
+#endif
+#if RROP == GXxor
+                   *pdst++ ^= (piQxelXor[0] & 0xFF000000);
+                   *pdst++ ^= piQxelXor[1];
+                   *pdst-- ^= piQxelXor[2];
+#endif
+#if RROP == GXand
+                   *pdst++ &= (piQxelAnd[0] | 0x00FFFFFF);
+                   *pdst++ &= piQxelAnd[1];
+                   *pdst-- &= piQxelAnd[2];
+#endif
+#if RROP == GXor
+                   *pdst++ |= (piQxelOr[0] & 0xFF000000);
+                   *pdst++ |= piQxelOr[1];
+                   *pdst-- |= piQxelOr[2];
+#endif
+#if RROP == GXset
+                   *pdst = DoMaskRRop((*pdst), piQxelAnd[0], piQxelXor[0], 0xFF000000);
+                   pdst++;
+                   *pdst = DoRRop((*pdst), piQxelAnd[1], piQxelXor[1]);
+                   pdst++;
+                   *pdst = DoRRop((*pdst), piQxelAnd[2], piQxelXor[2]);
+                   pdst--;
+#endif
+                   pdst--;
+               break;
+           case 2:
+#if RROP == GXcopy
+                   *pdst++ = ((*pdst) & 0xFFFF) | (piQxelXor[1] & 0xFFFF0000);
+                   *pdst-- = piQxelXor[2];
+#endif
+#if RROP == GXxor
+                   *pdst++ ^= (piQxelXor[1] & 0xFFFF0000);
+                   *pdst-- ^= piQxelXor[2];
+#endif
+#if RROP == GXand
+                   *pdst++ &= (piQxelAnd[1] | 0xFFFF);
+                   *pdst-- &= piQxelAnd[2];
+#endif
+#if RROP == GXor
+                   *pdst++ |= (piQxelOr[1] & 0xFFFF0000);
+                   *pdst-- |= piQxelOr[2];
+#endif
+#if RROP == GXset
+                   *pdst = DoMaskRRop((*pdst), piQxelAnd[1], piQxelXor[1], 0xFFFF0000);
+                   pdst++;
+                   *pdst = DoRRop((*pdst), piQxelAnd[2], piQxelXor[2]);
+                   pdst--;
+#endif
+               break;
+           case 3:
+#if RROP == GXcopy
+                   *pdst = ((*pdst) & 0xFF) | (piQxelXor[2] & 0xFFFFFF00);
+#endif
+#if RROP == GXxor
+                   *pdst ^= (piQxelXor[2] & 0xFFFFFF00);
+#endif
+#if RROP == GXand
+                   *pdst &= (piQxelAnd[2] | 0xFF);
+#endif
+#if RROP == GXor
+                   *pdst |= (piQxelOr[2] & 0xFFFFFF00);
+#endif
+#if RROP == GXset
+                   *pdst = DoMaskRRop((*pdst), piQxelAnd[2], piQxelXor[2], 0xFFFFFF00);
+#endif
+               break;
+           }
+           break;
+       case 3:
+           switch(leftIndex){
+           case 0:
+#if RROP == GXcopy
+                   *pdst++ = piQxelXor[0];
+                   *pdst++ = piQxelXor[1];
+                   *pdst-- = ((*pdst) & 0xFFFFFF00) | (piQxelXor[2] & 0xFF);
+#endif
+#if RROP == GXxor
+                   *pdst++ ^= piQxelXor[0];
+                   *pdst++ ^= piQxelXor[1];
+                   *pdst-- ^= (piQxelXor[2] & 0xFF);
+#endif
+#if RROP == GXand
+                   *pdst++ &= piQxelAnd[0];
+                   *pdst++ &= piQxelAnd[1];
+                   *pdst-- &= (piQxelAnd[2] | 0xFFFFFF00);
+#endif
+#if RROP == GXor
+                   *pdst++ |= piQxelOr[0];
+                   *pdst++ |= piQxelOr[1];
+
+                   *pdst-- |= (piQxelOr[2] & 0xFF);
+#endif
+#if RROP == GXset
+                   *pdst = DoRRop((*pdst), piQxelAnd[0], piQxelXor[0]);
+                   pdst++;
+                   *pdst = DoRRop((*pdst), piQxelAnd[1], piQxelXor[1]);
+                   pdst++;
+                   *pdst = DoMaskRRop((*pdst), piQxelAnd[2], piQxelXor[2], 0xFF);
+                   pdst--;
+#endif
+                   pdst--;
+               break;
+           case 1:
+#if RROP == GXcopy
+                   *pdst++ = ((*pdst) & 0xFFFFFF) | (piQxelXor[0] & 0xFF000000);
+                   *pdst++ = piQxelXor[1];
+                   *pdst-- = ((*pdst) & 0xFFFFFF00) | (piQxelXor[2] & 0xFF);
+#endif
+#if RROP == GXxor
+                   *pdst++ ^= (piQxelXor[0] & 0xFF000000);
+                   *pdst++ ^= piQxelXor[1];
+                   *pdst-- ^= (piQxelXor[2] & 0xFF);
+#endif
+#if RROP == GXand
+                   *pdst++ &= (piQxelAnd[0] | 0x00FFFFFF);
+                   *pdst++ &= piQxelAnd[1];
+                   *pdst-- &= (piQxelAnd[2] | 0xFFFFFF00);
+#endif
+#if RROP == GXor
+                   *pdst++ |= (piQxelOr[0] & 0xFF000000);
+                   *pdst++ |= piQxelOr[1];
+                   *pdst-- |= (piQxelOr[2] & 0xFF);
+#endif
+#if RROP == GXset
+                   *pdst = DoMaskRRop((*pdst), piQxelAnd[0], piQxelXor[0], 0xFF000000);
+                   pdst++;
+                   *pdst = DoRRop((*pdst), piQxelAnd[1], piQxelXor[1]);
+                   pdst++;
+                   *pdst = DoMaskRRop((*pdst), piQxelAnd[2], piQxelXor[2], 0xFF);
+                   pdst--;
+#endif
+                   pdst--;
+               break;
+           case 2:
+/*             pdst++;*/
+#if RROP == GXcopy
+                   *pdst++ = ((*pdst) & 0xFFFF) | (piQxelXor[1] & 0xFFFF0000);
+                   *pdst-- = ((*pdst) & 0xFFFFFF00) | (piQxelXor[2] & 0xFF);
+#endif
+#if RROP == GXxor
+                   *pdst++ ^= (piQxelXor[1] & 0xFFFF0000);
+                   *pdst-- ^= (piQxelXor[2] & 0xFF);
+#endif
+#if RROP == GXand
+                   *pdst++ &= (piQxelAnd[1] | 0xFFFF);
+                   *pdst-- &= (piQxelAnd[2] | 0xFFFFFF00);
+#endif
+#if RROP == GXor
+                   *pdst++ |= (piQxelOr[1] & 0xFFFF0000);
+                   *pdst-- |= (piQxelOr[2] & 0xFF);
+#endif
+#if RROP == GXset
+                   *pdst = DoMaskRRop((*pdst), piQxelAnd[1], piQxelXor[1], 0xFFFF0000);
+                   pdst++;
+                   *pdst = DoMaskRRop((*pdst), piQxelAnd[2], piQxelXor[2], 0xFF);
+                   pdst--;
+#endif
+               break;
+           }
+           break;
+       case 2: /* leftIndex + w = 2*/
+           if(leftIndex){
+#if RROP == GXcopy
+                   *pdst++ = ((*pdst) & 0xFFFFFF) | (piQxelXor[0] & 0xFF000000);
+                   *pdst-- = ((*pdst) & 0xFFFF0000) | (piQxelXor[1] & 0xFFFF);
+#endif
+#if RROP == GXxor
+                   *pdst++ ^= (piQxelXor[0] & 0xFF000000);
+                   *pdst-- ^= (piQxelXor[1] & 0xFFFF);
+#endif
+#if RROP == GXand
+                   *pdst++ &= (piQxelAnd[0] | 0xFFFFFF);
+                   *pdst-- &= (piQxelAnd[1] | 0xFFFF0000);
+#endif
+#if RROP == GXor
+                   *pdst++ |= (piQxelOr[0] & 0xFF000000);
+                   *pdst-- |= (piQxelOr[1] & 0xFFFF);
+#endif
+#if RROP == GXset
+                   *pdst = DoMaskRRop((*pdst), piQxelAnd[0], piQxelXor[0], 0xFF000000);
+                   pdst++;
+                   *pdst = DoMaskRRop((*pdst), piQxelAnd[1], piQxelXor[1], 0xFFFF);
+                   pdst--;
+#endif
+           }
+           else{ /*case 2 leftIndex === 0 */
+#if RROP == GXcopy
+                   *pdst++ = piQxelXor[0];
+                   *pdst-- = ((*pdst) & 0xFFFF0000) | (piQxelXor[1] & 0xFFFF);
+#endif
+#if RROP == GXxor
+                   *pdst++ ^= piQxelXor[0];
+                   *pdst-- ^= (piQxelXor[1] & 0xFFFF);
+#endif
+#if RROP == GXand
+                   *pdst++ &= piQxelAnd[0];
+                   *pdst-- &= (piQxelAnd[1] | 0xFFFF0000);
+#endif
+#if RROP == GXor
+                   *pdst++ |= piQxelOr[0];
+                   *pdst-- |= (piQxelOr[1] & 0xFFFF);
+#endif
+#if RROP == GXset
+                   *pdst = DoRRop((*pdst), piQxelAnd[0], piQxelXor[0]);
+                   pdst++;
+                   *pdst = DoMaskRRop((*pdst), piQxelAnd[1], piQxelXor[1], 0xFFFF);
+                   pdst--;
+#endif
+           }
+           break;
+       case 1: /*only if leftIndex = 0 and w = 1*/
+#if RROP == GXcopy
+               *pdst = ((*pdst) & 0xFF000000) | (piQxelXor[0] & 0xFFFFFF);
+#endif
+#if RROP == GXxor
+               *pdst ^= (piQxelXor[0] & 0xFFFFFF);
+#endif
+#if RROP == GXand
+               *pdst &= (piQxelAnd[0] | 0xFF000000);
+#endif
+#if RROP == GXor
+               *pdst |= (piQxelOr[0] & 0xFFFFFF);
+#endif
+#if RROP == GXset
+               *pdst = DoMaskRRop((*pdst), piQxelAnd[0], piQxelXor[0], 0xFFFFFF);
+#endif
+           break;
+       case 0: /*never*/
+           break;
+       default:
+       {
+           switch(leftIndex){
+                   case 0:
+                       break;
+                   case 1:
+#if RROP == GXcopy
+                       *pdst++ = ((*pdst) & 0xFFFFFF) | (piQxelXor[0] & 0xFF000000);
+                       *pdst++ = piQxelXor[1];
+                       *pdst++ = piQxelXor[2];
+#endif
+#if RROP == GXxor
+                       *pdst++ ^= (piQxelXor[0] & 0xFF000000);
+                       *pdst++ ^= piQxelXor[1];
+                       *pdst++ ^= piQxelXor[2];
+#endif
+#if RROP == GXand
+                       *pdst++ &= (piQxelAnd[0] | 0xFFFFFF);
+                       *pdst++ &= piQxelAnd[1];
+                       *pdst++ &= piQxelAnd[2];
+#endif
+#if RROP == GXor
+                       *pdst++ |= (piQxelOr[0] & 0xFF000000);
+                       *pdst++ |= piQxelOr[1];
+                       *pdst++ |= piQxelOr[2];
+#endif
+#if RROP == GXset
+                       *pdst = DoMaskRRop((*pdst), piQxelAnd[0], piQxelXor[0], 0xFF000000);
+                       pdst++;
+                       *pdst = DoRRop((*pdst), piQxelAnd[1], piQxelXor[1]);
+                       pdst++;
+                       *pdst = DoRRop((*pdst), piQxelAnd[2], piQxelXor[2]);
+                       pdst++;
+#endif
+                   break;
+                   case 2:
+#if RROP == GXcopy
+                       *pdst++ = (((*pdst) & 0xFFFF) | (piQxelXor[1] & 0xFFFF0000));
+                       *pdst++ = piQxelXor[2];
+#endif
+#if RROP == GXxor
+                       *pdst++ ^=(piQxelXor[1] & 0xFFFF0000);
+                       *pdst++ ^= piQxelXor[2];
+#endif
+#if RROP == GXand
+                       *pdst++ &= (piQxelAnd[1] | 0xFFFF);
+                       *pdst++ &= piQxelAnd[2];
+#endif
+#if RROP == GXor
+                       *pdst++ |= (piQxelOr[1] & 0xFFFF0000);
+                       *pdst++ |= piQxelOr[2];
+#endif
+#if RROP == GXset
+                       *pdst = DoMaskRRop((*pdst), piQxelAnd[1], piQxelXor[1], 0xFFFF0000);
+                       pdst++;
+                       *pdst = DoRRop((*pdst), piQxelAnd[2], piQxelXor[2]);
+                       pdst++;
+#endif
+                       break;
+                   case 3:
+#if RROP == GXcopy
+                       *pdst++ = ((*pdst) & 0xFF) | (piQxelXor[2] & 0xFFFFFF00);
+#endif
+#if RROP == GXxor
+                       *pdst++ ^= (piQxelXor[2] & 0xFFFFFF00);
+#endif
+#if RROP == GXand
+                       *pdst++ &= (piQxelAnd[2] | 0xFF);
+#endif
+#if RROP == GXor
+                       *pdst++ |= (piQxelOr[2] & 0xFFFFFF00);
+#endif
+#if RROP == GXset
+                       *pdst = DoMaskRRop((*pdst), piQxelAnd[2], piQxelXor[2], 0xFFFFFF00);
+                       pdst++;
+#endif
+                       break;
+                   }
+                   while(nlmiddle--){
+#if RROP == GXcopy
+                       *pdst++ = piQxelXor[0];
+                       *pdst++ = piQxelXor[1];
+                       *pdst++ = piQxelXor[2];
+#endif
+#if RROP == GXxor
+                       *pdst++ ^= piQxelXor[0];
+                       *pdst++ ^= piQxelXor[1];
+                       *pdst++ ^= piQxelXor[2];
+#endif
+#if RROP == GXand
+                       *pdst++ &= piQxelAnd[0];
+                       *pdst++ &= piQxelAnd[1];
+                       *pdst++ &= piQxelAnd[2];
+#endif
+#if RROP == GXor
+                       *pdst++ |= piQxelOr[0];
+                       *pdst++ |= piQxelOr[1];
+                       *pdst++ |= piQxelOr[2];
+#endif
+#if RROP == GXset
+                       *pdst = DoRRop((*pdst), piQxelAnd[0], piQxelXor[0]);
+                       pdst++;
+                       *pdst = DoRRop((*pdst), piQxelAnd[1], piQxelXor[1]);
+                       pdst++;
+                       *pdst = DoRRop((*pdst), piQxelAnd[2], piQxelXor[2]);
+                       pdst++;
+#endif
+               }
+               switch(rightIndex){
+               case 0:
+                 break;
+               case 1:
+#if RROP == GXcopy
+                 *pdst++ = ((*pdst) & 0xFF000000) | (piQxelXor[0] & 0xFFFFFF);
+#endif
+#if RROP == GXxor
+                 *pdst++ ^= (piQxelXor[0] & 0xFFFFFF);
+#endif
+#if RROP == GXand
+                 *pdst++ &= (piQxelAnd[0] | 0xFF);
+#endif
+#if RROP == GXor
+                 *pdst++ |= (piQxelOr[0] & 0xFFFFFF);
+#endif
+#if RROP == GXset
+                 *pdst = DoMaskRRop((*pdst), piQxelAnd[0], piQxelXor[0], 0xFFFFFF);
+#endif
+                 break;
+               case 2:
+#if RROP == GXcopy
+                 *pdst++ = piQxelXor[0];
+                 *pdst++ = ((*pdst) & 0xFFFF0000) | (piQxelXor[1] & 0xFFFF);
+#endif
+#if RROP == GXxor
+                 *pdst++ ^= piQxelXor[0];
+                 *pdst++ ^= (piQxelXor[1] & 0xFFFF);
+#endif
+#if RROP == GXand
+                 *pdst++ &= piQxelAnd[0];
+                 *pdst++ &= (piQxelAnd[1] | 0xFFFF0000);
+#endif
+#if RROP == GXor
+                 *pdst++ |= piQxelOr[0];
+                 *pdst++ |= (piQxelOr[1] & 0xFFFF);
+#endif
+#if RROP == GXset
+                 *pdst = DoRRop((*pdst), piQxelAnd[0], piQxelXor[0]);
+                 *pdst++;
+                 *pdst = DoMaskRRop((*pdst), piQxelAnd[1], piQxelXor[1], 0xFFFF);
+                 *pdst++;
+#endif
+                 break;
+               case 3:
+#if RROP == GXcopy
+                 *pdst++ = piQxelXor[0];
+                 *pdst++ = piQxelXor[1];
+                 *pdst++ = ((*pdst) & 0xFFFFFF00) | (piQxelXor[2] & 0xFF);
+#endif
+#if RROP == GXxor
+                 *pdst++ ^= piQxelXor[0];
+                 *pdst++ ^= piQxelXor[1];
+                 *pdst++ ^= (piQxelXor[2] & 0xFF);
+#endif
+#if RROP == GXand
+                 *pdst++ &= piQxelAnd[0];
+                 *pdst++ &= piQxelAnd[1];
+                 *pdst++ &= (piQxelAnd[2] | 0xFFFFFF00);
+#endif
+#if RROP == GXor
+                 *pdst++ |= piQxelOr[0];
+                 *pdst++ |= piQxelOr[1];
+                 *pdst++ |= (piQxelOr[2] & 0xFF);
+#endif
+#if RROP == GXset
+                 *pdst = DoRRop((*pdst), piQxelAnd[0], piQxelXor[0]);
+                 pdst++;
+                 *pdst = DoRRop((*pdst), piQxelAnd[1], piQxelXor[1]);
+                 pdst++;
+                 *pdst = DoMaskRRop((*pdst), piQxelAnd[2], piQxelXor[2], 0xFF);
+                 pdst++;
+#endif
+                 break;
+               }
+       }
+}
+#else
+#if PSZ == 8
+       if (w <= PGSZB)
+       {
+           register char   *addrb;
+
+           addrb = ((char *) pdst) + x;
+           while (w--)
+           {
+               RROP_SOLID (addrb);
+               addrb++;
+           }
+       }
+#else
+       if ((x & PIM) + w <= PPW)
+       {
+           pdst += x >> PWSH;
+           maskpartialbits (x, w, startmask);
+           RROP_SOLID_MASK (pdst, startmask);
+       }
+#endif
+       else
+       {
+           pdst += x >> PWSH;
+           maskbits (x, w, startmask, endmask, nlmiddle);
+           if (startmask)
+           {
+               RROP_SOLID_MASK (pdst, startmask);
+               ++pdst;
+           }
+           
+           RROP_SPAN(pdst,nlmiddle)
+           if (endmask)
+           {
+               RROP_SOLID_MASK (pdst, endmask);
+           }
+       }
+#endif
+    }
+    DEALLOCATE_LOCAL(pptFree);
+    DEALLOCATE_LOCAL(pwidthFree);
+}
diff --git a/Xserver/programs/Xserver/cfb/cfbteblt8.c b/Xserver/programs/Xserver/cfb/cfbteblt8.c
new file mode 100644 (file)
index 0000000..b30a821
--- /dev/null
@@ -0,0 +1,584 @@
+/*
+ * TEGblt - ImageText expanded glyph fonts only.  For
+ * 8 bit displays, in Copy mode with no clipping.
+ */
+
+/*
+
+Copyright (c) 1989  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+*/
+
+/* $XConsortium: cfbteblt8.c,v 5.24 94/09/29 15:26:00 dpw Exp $ */
+
+#if PSZ == 8
+
+#include       "X.h"
+#include       "Xmd.h"
+#include       "Xproto.h"
+#include       "cfb.h"
+#include       "fontstruct.h"
+#include       "dixfontstr.h"
+#include       "gcstruct.h"
+#include       "windowstr.h"
+#include       "scrnintstr.h"
+#include       "pixmapstr.h"
+#include       "regionstr.h"
+#include       "cfbmskbits.h"
+#include       "cfb8bit.h"
+
+/*
+ * this code supports up to 5 characters at a time.  The performance
+ * differences between 4 and 5 is usually small (~7% on PMAX) and
+ * frequently negative (SPARC and Sun3), so this file is compiled
+ * only once for now.  If you want to use the other options, you'll
+ * need to hack cfbgc.c as well.
+ */
+
+#ifndef NGLYPHS
+#define NGLYPHS 4
+#define DO_COMMON
+#endif
+
+#ifdef DO_COMMON
+#define CFBTEGBLT8 cfbTEGlyphBlt8
+#endif
+
+/*
+ * On little-endian machines (or where fonts are padded to 32-bit
+ * boundaries) we can use some magic to avoid the expense of getleftbits
+ */
+
+#if ((BITMAP_BIT_ORDER == LSBFirst && NGLYPHS >= 4) || GLYPHPADBYTES == 4)
+
+#if GLYPHPADBYTES == 1
+typedef unsigned char  *glyphPointer;
+#define USE_LEFTBITS
+#endif
+
+#if GLYPHPADBYTES == 2
+typedef unsigned short *glyphPointer;
+#define USE_LEFTBITS
+#endif
+
+#if GLYPHPADBYTES == 4
+typedef unsigned int   *glyphPointer;
+#endif
+
+#define GetBitsL       c = BitLeft (*leftChar++, lshift)
+#define NGetBits1S(r)   c = BitRight(*char1++ r, xoff1)
+#define NGetBits1L(r)   GetBitsL | BitRight(*char1++ r, xoff1)
+#define NGetBits1U(r)   c = *char1++ r
+#define NGetBits2S(r)   NGetBits1S(| BitRight(*char2++ r, widthGlyph))
+#define NGetBits2L(r)   NGetBits1L(| BitRight(*char2++ r, widthGlyph))
+#define NGetBits2U(r)   NGetBits1U(| BitRight(*char2++ r, widthGlyph))
+#define NGetBits3S(r)   NGetBits2S(| BitRight(*char3++ r, widthGlyph))
+#define NGetBits3L(r)   NGetBits2L(| BitRight(*char3++ r, widthGlyph))
+#define NGetBits3U(r)   NGetBits2U(| BitRight(*char3++ r, widthGlyph))
+#define NGetBits4S(r)   NGetBits3S(| BitRight(*char4++ r, widthGlyph))
+#define NGetBits4L(r)   NGetBits3L(| BitRight(*char4++ r, widthGlyph))
+#define NGetBits4U(r)   NGetBits3U(| BitRight(*char4++ r, widthGlyph))
+#define NGetBits5S(r)   NGetBits4S(| BitRight(*char5++ r, widthGlyph))
+#define NGetBits5L(r)   NGetBits4L(| BitRight(*char5++ r, widthGlyph))
+#define NGetBits5U(r)   NGetBits4U(| BitRight(*char5++ r, widthGlyph))
+#define GetBits1S   c = BitRight(*char1++, xoff1)
+#define GetBits1L   GetBitsL | BitRight(*char1++, xoff1)
+#define GetBits1U   c = *char1++
+#define GetBits2S   NGetBits1S(| BitRight(*char2++, widthGlyph))
+#define GetBits2L   NGetBits1L(| BitRight(*char2++, widthGlyph))
+#define GetBits2U   NGetBits1U(| BitRight(*char2++, widthGlyph))
+#define GetBits3S   NGetBits2S(| BitRight(*char3++, widthGlyph))
+#define GetBits3L   NGetBits2L(| BitRight(*char3++, widthGlyph))
+#define GetBits3U   NGetBits2U(| BitRight(*char3++, widthGlyph))
+#define GetBits4S   NGetBits3S(| BitRight(*char4++, widthGlyph))
+#define GetBits4L   NGetBits3L(| BitRight(*char4++, widthGlyph))
+#define GetBits4U   NGetBits3U(| BitRight(*char4++, widthGlyph))
+#define GetBits5S   NGetBits4S(| BitRight(*char5++, widthGlyph))
+#define GetBits5L   NGetBits4L(| BitRight(*char5++, widthGlyph))
+#define GetBits5U   NGetBits4U(| BitRight(*char5++, widthGlyph))
+
+#else
+
+typedef unsigned int   *glyphPointer;
+
+#define USE_LEFTBITS
+#define ALL_LEFTBITS
+
+#define GetBitsL    WGetBitsL
+#define GetBits1S   WGetBits1S
+#define GetBits1L   WGetBits1L
+#define GetBits1U   WGetBits1U
+
+#define GetBits2S   GetBits1S Get1Bits (char2, tmpSrc) \
+                   c |= BitRight(tmpSrc, xoff2);
+#define GetBits2L   GetBits1L Get1Bits (char2, tmpSrc) \
+                   c |= BitRight(tmpSrc, xoff2);
+#define GetBits2U   GetBits1U Get1Bits (char2, tmpSrc) \
+                   c |= BitRight(tmpSrc, xoff2);
+
+#define GetBits3S   GetBits2S Get1Bits (char3, tmpSrc) \
+                   c |= BitRight(tmpSrc, xoff3);
+#define GetBits3L   GetBits2L Get1Bits (char3, tmpSrc) \
+                   c |= BitRight(tmpSrc, xoff3);
+#define GetBits3U   GetBits2U Get1Bits (char3, tmpSrc) \
+                   c |= BitRight(tmpSrc, xoff3);
+
+#define GetBits4S   GetBits3S Get1Bits (char4, tmpSrc) \
+                   c |= BitRight(tmpSrc, xoff4);
+#define GetBits4L   GetBits3L Get1Bits (char4, tmpSrc) \
+                   c |= BitRight(tmpSrc, xoff4);
+#define GetBits4U   GetBits3U Get1Bits (char4, tmpSrc) \
+                   c |= BitRight(tmpSrc, xoff4);
+
+#define GetBits5S   GetBits4S Get1Bits (char5, tmpSrc) \
+                   c |= BitRight(tmpSrc, xoff5);
+#define GetBits5L   GetBits4L Get1Bits (char5, tmpSrc) \
+                   c |= BitRight(tmpSrc, xoff5);
+#define GetBits5U   GetBits4U Get1Bits (char5, tmpSrc) \
+                   c |= BitRight(tmpSrc, xoff5);
+
+#endif
+
+#ifdef USE_LEFTBITS
+extern unsigned long endtab[];
+
+#define IncChar(c)  (c = (glyphPointer) (((char *) c) + glyphBytes))
+
+#define Get1Bits(ch,dst)    glyphbits (ch, widthGlyph, glyphMask, dst); \
+                           IncChar (ch);
+
+#define glyphbits(bits,width,mask,dst) getleftbits(bits,width,dst); \
+                                       dst &= mask;
+
+#define WGetBitsL   Get1Bits(leftChar,c); \
+                   c = BitLeft (c, lshift);
+#define WGetBits1S  Get1Bits (char1, c) \
+                   c = BitRight (c, xoff1);
+#define WGetBits1L  WGetBitsL Get1Bits (char1, tmpSrc) \
+                   c |= BitRight (tmpSrc, xoff1);
+#define WGetBits1U  Get1Bits (char1, c)
+
+#else
+#define WGetBitsL   GetBitsL
+#define WGetBits1S  GetBits1S
+#define WGetBits1L  GetBits1L
+#define WGetBits1U  GetBits1U
+#endif
+
+#if NGLYPHS == 2
+# define GetBitsNS GetBits2S
+# define GetBitsNL GetBits2L
+# define GetBitsNU GetBits2U
+# define LastChar char2
+#ifndef CFBTEGBLT8
+# define CFBTEGBLT8 cfbTEGlyphBlt8x2
+#endif
+#endif
+#if NGLYPHS == 3
+# define GetBitsNS GetBits3S
+# define GetBitsNL GetBits3L
+# define GetBitsNU GetBits3U
+# define LastChar char3
+#ifndef CFBTEGBLT8
+# define CFBTEGBLT8 cfbTEGlyphBlt8x3
+#endif
+#endif
+#if NGLYPHS == 4
+# define GetBitsNS GetBits4S
+# define GetBitsNL GetBits4L
+# define GetBitsNU GetBits4U
+# define LastChar char4
+#ifndef CFBTEGBLT8
+# define CFBTEGBLT8 cfbTEGlyphBlt8x4
+#endif
+#endif
+#if NGLYPHS == 5
+# define GetBitsNS GetBits5S
+# define GetBitsNL GetBits5L
+# define GetBitsNU GetBits5U
+# define LastChar char5
+#ifndef CFBTEGBLT8
+# define CFBTEGBLT8 cfbTEGlyphBlt8x5
+#endif
+#endif
+
+/* another ugly giant macro */
+#define SwitchEm    switch (ew) \
+                   { \
+                   case 0: \
+                       break; \
+                   case 1: \
+                       while (hTmp--) { \
+                           GetBits; \
+                           StoreBits0 \
+                           Loop \
+                       } \
+                       break; \
+                   case 2: \
+                       while (hTmp--) { \
+                           GetBits; \
+                           StoreBits0 FirstStep StoreBits(1) \
+                           Loop \
+                       } \
+                       break; \
+                   case 3: \
+                       while (hTmp--) { \
+                           GetBits; \
+                           StoreBits0 FirstStep StoreBits(1) Step StoreBits(2) \
+                           Loop \
+                       } \
+                       break; \
+                   case 4: \
+                       while (hTmp--) { \
+                           GetBits; \
+                           StoreBits0 FirstStep StoreBits(1) Step \
+                           StoreBits(2) Step StoreBits(3) \
+                           Loop \
+                       } \
+                       break; \
+                   case 5: \
+                       while (hTmp--) { \
+                           GetBits; \
+                           StoreBits0 FirstStep StoreBits(1) Step \
+                           StoreBits(2) Step StoreBits(3) Step \
+                           StoreBits(4) \
+                           Loop \
+                       } \
+                       break; \
+                   case 6: \
+                       while (hTmp--) { \
+                           GetBits; \
+                           StoreBits0 FirstStep StoreBits(1) Step \
+                           StoreBits(2) Step StoreBits(3) Step \
+                           StoreBits(4) Step StoreBits(5) \
+                           Loop \
+                       } \
+                       break; \
+                   case 7: \
+                       while (hTmp--) { \
+                           GetBits; \
+                           StoreBits0 FirstStep StoreBits(1) Step \
+                           StoreBits(2) Step StoreBits(3) Step \
+                           StoreBits(4) Step StoreBits(5) Step \
+                           StoreBits(6) \
+                           Loop \
+                       } \
+                       break; \
+                   case 8: \
+                       while (hTmp--) { \
+                           GetBits; \
+                           StoreBits0 FirstStep StoreBits(1) Step \
+                           StoreBits(2) Step StoreBits(3) Step \
+                           StoreBits(4) Step StoreBits(5) Step \
+                           StoreBits(6) Step StoreBits(7) \
+                           Loop \
+                       } \
+                       break; \
+                   }
+
+#ifdef FAST_CONSTANT_OFFSET_MODE
+#define StorePixels(o,p)    dst[o] = p
+#define Loop               dst += widthDst;
+#else
+#define StorePixels(o,p)    *dst++ = (p)
+#define Loop               dst += widthLeft;
+#endif
+
+#define Step               NextBitGroup(c);
+
+#if (BITMAP_BIT_ORDER == MSBFirst)
+#define StoreBits(o)   StorePixels(o,GetPixelGroup(c));
+#define FirstStep      Step
+#else
+#if PGSZ == 64
+#define StoreBits(o)   StorePixels(o,cfb8Pixels[(c) & PGSZBMSK]);
+#define FirstStep      Step
+#else /* PGSZ == 32 */
+#define StoreBits(o)   StorePixels(o,*((unsigned long *) (((char *) cfb8Pixels) + (c & 0x3c))));
+#define FirstStep      c = BitLeft (c, 2);
+#endif /* PGSZ */
+#endif /* BITMAP_BIT_ORDER */
+
+
+void
+CFBTEGBLT8 (pDrawable, pGC, xInit, yInit, nglyph, ppci, pglyphBase)
+    DrawablePtr pDrawable;
+    GC                 *pGC;
+    int        xInit, yInit;
+    unsigned int nglyph;
+    CharInfoPtr *ppci;         /* array of character info */
+    pointer    pglyphBase;     /* start of array of glyphs */
+{
+    register unsigned long  c;
+    register unsigned long  *dst;
+    register unsigned long  leftMask, rightMask;
+    register int           hTmp;
+    register int           xoff1;
+    register glyphPointer   char1;
+    register glyphPointer   char2;
+#if NGLYPHS >= 3
+    register glyphPointer   char3;
+#endif
+#if NGLYPHS >= 4
+    register glyphPointer   char4;
+#endif
+#if NGLYPHS >= 5
+    register glyphPointer   char5;
+#endif
+#ifdef ALL_LEFTBITS
+    int xoff2, xoff3, xoff4, xoff5;
+#endif
+
+    FontPtr            pfont = pGC->font;
+    unsigned long      *dstLine;
+    glyphPointer       oldRightChar;
+    unsigned long      *pdstBase;
+    glyphPointer       leftChar;
+    int                        widthDst, widthLeft;
+    int                        widthGlyph;
+    int                        h;
+    int                        ew;
+    int                        x, y;
+    BoxRec             bbox;           /* for clipping */
+    int                        lshift;
+    int                        widthGlyphs;
+#ifdef USE_LEFTBITS
+    register unsigned long  glyphMask;
+    register unsigned long  tmpSrc;
+    register int           glyphBytes;
+#endif
+
+    widthGlyph = FONTMAXBOUNDS(pfont,characterWidth);
+    h = FONTASCENT(pfont) + FONTDESCENT(pfont);
+    if (!h)
+       return;
+    x = xInit + FONTMAXBOUNDS(pfont,leftSideBearing) + pDrawable->x;
+    y = yInit - FONTASCENT(pfont) + pDrawable->y;
+    bbox.x1 = x;
+    bbox.x2 = x + (widthGlyph * nglyph);
+    bbox.y1 = y;
+    bbox.y2 = y + h;
+
+    switch (RECT_IN_REGION(pGC->pScreen,  cfbGetCompositeClip(pGC), &bbox))
+    {
+      case rgnPART:
+       cfbImageGlyphBlt8(pDrawable, pGC, xInit, yInit, nglyph, ppci, pglyphBase);
+      case rgnOUT:
+       return;
+    }
+
+    if (!cfb8CheckPixels (pGC->fgPixel, pGC->bgPixel))
+       cfb8SetPixels (pGC->fgPixel, pGC->bgPixel);
+
+    leftChar = 0;
+
+    cfbGetLongWidthAndPointer(pDrawable, widthDst, pdstBase)
+
+#if NGLYPHS == 2
+    widthGlyphs = widthGlyph << 1;
+#else
+#if NGLYPHS == 4
+    widthGlyphs = widthGlyph << 2;
+#else
+    widthGlyphs = widthGlyph * NGLYPHS;
+#endif
+#endif
+
+#ifdef USE_LEFTBITS
+    glyphMask = endtab[widthGlyph];
+    glyphBytes = GLYPHWIDTHBYTESPADDED(*ppci);
+#endif
+
+    pdstBase += y * widthDst;
+#ifdef DO_COMMON
+    if (widthGlyphs <= 32)
+#endif
+       while (nglyph >= NGLYPHS)
+       {
+           nglyph -= NGLYPHS;
+           hTmp = h;
+           dstLine = pdstBase + (x >> PWSH);
+           xoff1 = x & PIM;
+           char1 = (glyphPointer) FONTGLYPHBITS(pglyphBase, *ppci++);
+           char2 = (glyphPointer) FONTGLYPHBITS(pglyphBase, *ppci++);
+#ifdef ALL_LEFTBITS
+           xoff2 = xoff1 + widthGlyph;
+#endif
+#if NGLYPHS >= 3
+           char3 = (glyphPointer) FONTGLYPHBITS(pglyphBase, *ppci++);
+#ifdef ALL_LEFTBITS
+           xoff3 = xoff2 + widthGlyph;
+#endif
+#endif
+#if NGLYPHS >= 4
+           char4 = (glyphPointer) FONTGLYPHBITS(pglyphBase, *ppci++);
+#ifdef ALL_LEFTBITS
+           xoff4 = xoff3 + widthGlyph;
+#endif
+#endif
+#if NGLYPHS >= 5
+           char5 = (glyphPointer) FONTGLYPHBITS(pglyphBase, *ppci++);
+#ifdef ALL_LEFTBITS
+           xoff5 = xoff4 + widthGlyph;
+#endif
+#endif
+           oldRightChar = LastChar;
+           dst = dstLine;
+           if (xoff1)
+           {
+               ew = ((widthGlyphs - (PGSZB - xoff1)) >> PWSH) + 1;
+#ifndef FAST_CONSTANT_OFFSET_MODE
+               widthLeft = widthDst - ew;
+#endif
+               if (!leftChar)
+               {
+                   leftMask = cfbendtab[xoff1];
+                   rightMask = cfbstarttab[xoff1];
+
+#define StoreBits0     StorePixels (0,dst[0] & leftMask | \
+                                      GetPixelGroup(c) & rightMask);
+#define GetBits GetBitsNS
+
+                   SwitchEm
+
+#undef GetBits
+#undef StoreBits0
+
+               }
+               else
+               {
+                   lshift = widthGlyph - xoff1;
+    
+#define StoreBits0  StorePixels (0,GetPixelGroup(c));
+#define GetBits GetBitsNL
+    
+                   SwitchEm
+    
+#undef GetBits
+#undef StoreBits0
+    
+               }
+           }
+           else
+           {
+#if NGLYPHS == 4 && PGSZ == 32
+               ew = widthGlyph;    /* widthGlyphs >> 2 */
+#else
+               ew = widthGlyphs >> PWSH;
+#endif
+#ifndef FAST_CONSTANT_OFFSET_MODE
+               widthLeft = widthDst - ew;
+#endif
+
+#define StoreBits0  StorePixels (0,GetPixelGroup(c));
+#define GetBits        GetBitsNU
+
+               SwitchEm
+
+#undef GetBits
+#undef StoreBits0
+
+           }
+           x += widthGlyphs;
+           leftChar = oldRightChar;
+       }
+    while (nglyph--)
+    {
+       xoff1 = x & PIM;
+       char1 = (glyphPointer) FONTGLYPHBITS(pglyphBase, *ppci++);
+       hTmp = h;
+       dstLine = pdstBase + (x >> PWSH);
+       oldRightChar = char1;
+       dst = dstLine;
+       if (xoff1)
+       {
+           ew = ((widthGlyph - (PGSZB - xoff1)) >> PWSH) + 1;
+#ifndef FAST_CONSTANT_OFFSET_MODE
+           widthLeft = widthDst - ew;
+#endif
+           if (!leftChar)
+           {
+               leftMask = cfbendtab[xoff1];
+               rightMask = cfbstarttab[xoff1];
+
+#define StoreBits0     StorePixels (0,dst[0] & leftMask | GetPixelGroup(c) & rightMask);
+#define GetBits        WGetBits1S
+
+               SwitchEm
+#undef GetBits
+#undef StoreBits0
+
+           }
+           else
+           {
+               lshift = widthGlyph - xoff1;
+
+#define StoreBits0  StorePixels (0,GetPixelGroup(c));
+#define GetBits WGetBits1L
+
+               SwitchEm
+#undef GetBits
+#undef StoreBits0
+
+           }
+       }
+       else
+       {
+           ew = widthGlyph >> PWSH;
+
+#ifndef FAST_CONSTANT_OFFSET_MODE
+           widthLeft = widthDst - ew;
+#endif
+
+#define StoreBits0  StorePixels (0,GetPixelGroup(c));
+#define GetBits        WGetBits1U
+
+           SwitchEm
+
+#undef GetBits
+#undef StoreBits0
+
+       }
+       x += widthGlyph;
+       leftChar = oldRightChar;
+    }
+    /*
+     * draw the tail of the last character
+     */
+    xoff1 = x & PIM;
+    if (xoff1)
+    {
+       rightMask = cfbstarttab[xoff1];
+       leftMask = cfbendtab[xoff1];
+       lshift = widthGlyph - xoff1;
+       dst = pdstBase + (x >> PWSH);
+       hTmp = h;
+       while (hTmp--)
+       {
+           GetBitsL;
+           *dst = (*dst & rightMask) | (GetPixelGroup(c) & leftMask);
+           dst += widthDst;
+       }
+    }
+}
+#endif /* PSZ == 8 */
diff --git a/Xserver/programs/Xserver/cfb/cfbtegblt.c b/Xserver/programs/Xserver/cfb/cfbtegblt.c
new file mode 100644 (file)
index 0000000..7c07f12
--- /dev/null
@@ -0,0 +1,225 @@
+/* $XConsortium: cfbtegblt.c,v 5.9 94/04/17 20:29:03 dpw Exp $ */
+/* $XFree86: xc/programs/Xserver/cfb/cfbtegblt.c,v 3.0 1996/06/29 09:05:52 dawes Exp $ */
+/***********************************************************
+
+Copyright (c) 1987  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+
+Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
+
+                        All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and its 
+documentation for any purpose and without fee is hereby granted, 
+provided that the above copyright notice appear in all copies and that
+both that copyright notice and this permission notice appear in 
+supporting documentation, and that the name of Digital not be
+used in advertising or publicity pertaining to distribution of the
+software without specific, written prior permission.  
+
+DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
+ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
+DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
+ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+SOFTWARE.
+
+******************************************************************/
+#include       "X.h"
+#include       "Xmd.h"
+#include       "Xproto.h"
+#include       "cfb.h"
+#include       "fontstruct.h"
+#include       "dixfontstr.h"
+#include       "gcstruct.h"
+#include       "windowstr.h"
+#include       "scrnintstr.h"
+#include       "pixmapstr.h"
+#include       "regionstr.h"
+#include       "cfbmskbits.h"
+#include       "mi.h"
+#define MFB_CONSTS_ONLY
+#include       "maskbits.h"
+
+/*
+    this works for fonts with glyphs <= 32 bits wide, on an
+    arbitrarily deep display.  Use cfbTEGlyphBlt8 for 8 bit displays.
+
+    This should be called only with a terminal-emulator font;
+this means that the FIXED_METRICS flag is set, and that
+glyphbounds == charbounds.
+
+    in theory, this goes faster; even if it doesn't, it reduces the
+flicker caused by writing a string over itself with image text (since
+the background gets repainted per character instead of per string.)
+this seems to be important for some converted X10 applications.
+
+    Image text looks at the bits in the glyph and the fg and bg in the
+GC.  it paints a rectangle, as defined in the protocol dcoument,
+and the paints the characters.
+
+*/
+
+void
+cfbTEGlyphBlt(pDrawable, pGC, x, y, nglyph, ppci, pglyphBase)
+    DrawablePtr pDrawable;
+    GC                 *pGC;
+    int        x, y;
+    unsigned int nglyph;
+    CharInfoPtr *ppci;         /* array of character info */
+    pointer    pglyphBase;     /* start of array of glyphs */
+{
+    FontPtr    pfont = pGC->font;
+    int widthDst;
+    unsigned long *pdstBase;   /* pointer to longword with top row 
+                                  of current glyph */
+
+    int w;                     /* width of glyph and char */
+    int h;                     /* height of glyph and char */
+    register int xpos=x;       /* current x%32  */
+    int ypos=y;                        /* current y%32 */
+    register unsigned char *pglyph;
+    int widthGlyph;
+
+    register unsigned long *pdst;/* pointer to current longword in dst */
+    int hTmp;                  /* counter for height */
+    BoxRec bbox;               /* for clipping */
+
+    register int wtmp,xtemp,width;
+    unsigned long bgfill,fgfill,*ptemp,tmpDst1,tmpDst2,*pdtmp;
+    int tmpx;
+#if PSZ == 24
+    int xIndex;
+#endif
+
+    xpos += pDrawable->x;
+    ypos += pDrawable->y;
+
+    cfbGetLongWidthAndPointer (pDrawable, widthDst, pdstBase)
+
+    wtmp = FONTMAXBOUNDS(pfont,characterWidth);
+    h = FONTASCENT(pfont) + FONTDESCENT(pfont);
+    widthGlyph = GLYPHWIDTHBYTESPADDED(*ppci);
+
+    xpos += FONTMAXBOUNDS(pfont,leftSideBearing);
+    ypos -= FONTASCENT(pfont);
+
+    bbox.x1 = xpos;
+    bbox.x2 = xpos + (wtmp * nglyph);
+    bbox.y1 = ypos;
+    bbox.y2 = ypos + h;
+
+    fgfill = PFILL(pGC->fgPixel);
+    bgfill = PFILL(pGC->bgPixel);
+
+    switch (RECT_IN_REGION(pGC->pScreen,  cfbGetCompositeClip(pGC), &bbox))
+    {
+      case rgnOUT:
+       break;
+      case rgnPART:
+       /* this is the WRONG thing to do, but it works.
+          calling the non-terminal text is easy, but slow, given
+          what we know about the font.
+
+          the right thing to do is something like:
+           for each clip rectangle
+               compute at which row the glyph starts to be in it,
+                  and at which row the glyph ceases to be in it
+               compute which is the first glyph inside the left
+                   edge, and the last one inside the right edge
+               draw a fractional first glyph, using only
+                   the rows we know are in
+               draw all the whole glyphs, using the appropriate rows
+               draw any pieces of the last glyph, using the right rows
+
+          this way, the code would take advantage of knowing that
+          all glyphs are the same height and don't overlap.
+
+          one day...
+       */
+       miImageGlyphBlt(pDrawable, pGC, x, y, nglyph, ppci, pglyphBase);
+       break;
+      case rgnIN:
+
+        pdtmp = pdstBase + (widthDst * ypos);
+        while(nglyph--)
+        {
+
+           pglyph = FONTGLYPHBITS(pglyphBase, *ppci++);
+            pdst = pdtmp;
+           hTmp = h;
+
+           while (hTmp--)
+           {
+               x = xpos;
+               width = wtmp;
+               xtemp = 0;
+
+               while (width > 0)
+               {
+#if PSZ == 24
+                   tmpx = x & 3;
+                   w = 1;
+#else
+                   tmpx = x & PIM;
+                   w = min(width, PPW - tmpx);
+                   w = min(w, (PGSZ - xtemp));
+#endif
+
+#if PSZ == 24
+                   ptemp = (unsigned long *)(pglyph + ((xtemp *3)>> 2));
+#else
+                   ptemp = (unsigned long *)(pglyph + (xtemp >> MFB_PWSH));
+#endif
+#if PSZ == 24
+                   getstipplepixels24(ptemp,xtemp,0,&bgfill,&tmpDst1, xtemp);
+                   getstipplepixels24(ptemp,xtemp,1,&fgfill,&tmpDst2, xtemp);
+#else
+                   getstipplepixels(ptemp,xtemp,w,0,&bgfill,&tmpDst1);
+                   getstipplepixels(ptemp,xtemp,w,1,&fgfill,&tmpDst2);
+#endif
+
+                   {
+                       unsigned long tmpDst = tmpDst1 | tmpDst2;
+#if PSZ == 24
+                       unsigned long *pdsttmp = pdst + ((x*3) >> 2);
+                       putbits24(tmpDst,tmpx,w,pdsttmp,pGC->planemask,x);
+#else
+                       unsigned long *pdsttmp = pdst + (x >> PWSH);
+                       putbits(tmpDst,tmpx,w,pdsttmp,pGC->planemask);
+#endif
+                   }
+                   x += w;
+                   xtemp += w;
+                   width -= w;
+               }
+               pglyph += widthGlyph;
+                pdst += widthDst;
+           }
+           xpos += wtmp;
+        }     
+       break;
+    }
+}
diff --git a/Xserver/programs/Xserver/cfb/cfbtile32.c b/Xserver/programs/Xserver/cfb/cfbtile32.c
new file mode 100644 (file)
index 0000000..e9bf1ea
--- /dev/null
@@ -0,0 +1,506 @@
+/*
+ * Fill 32 bit tiled rectangles.  Used by both PolyFillRect and PaintWindow.
+ * no depth dependencies.
+ */
+
+/*
+
+Copyright (c) 1989  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+*/
+
+/* $XConsortium: cfbtile32.c,v 1.8 94/04/17 20:29:05 dpw Exp $ */
+/* $XFree86: xc/programs/Xserver/cfb/cfbtile32.c,v 3.0 1996/06/29 09:05:53 dawes Exp $ */
+
+#include "X.h"
+#include "Xmd.h"
+#include "servermd.h"
+#include "gcstruct.h"
+#include "window.h"
+#include "pixmapstr.h"
+#include "scrnintstr.h"
+#include "windowstr.h"
+
+#include "cfb.h"
+#include "cfbmskbits.h"
+#include "cfb8bit.h"
+
+#include "mergerop.h"
+
+#include "mi.h"
+#include "mispans.h"
+
+#ifdef sparc
+#define SHARED_IDCACHE
+#endif
+
+#if PSZ == 24
+#define STORE(p)    (*(p) = MROP_PREBUILT_SOLID(srcpix,*(p)))
+/*#define STORE24(p,index)    {\
+           register int idx = ((index) & 3)<< 1; \
+           *(p) = (((MROP_PREBUILT_SOLID(srcpix,*(p))<<cfb24Shift[idx])&cfbmask[idx])| \
+                   (*(p)&cfbrmask[idx])); \
+           idx++; \
+           (p)++; \
+           *(p) = (((MROP_PREBUILT_SOLID(srcpix,*(p))>>cfb24Shift[idx])&cfbmask[idx])| \
+                   (*(p)&cfbrmask[idx])); \
+           (p)--; \
+       }*/
+#define STORE24(p,index)    MROP_PREBUILT_SOLID24(srcpix, (p), index)
+
+#define STORE_MASK(p,mask)    (*(p) = MROP_PREBUILT_MASK(srcpix,*(p),(mask)))
+#define QSTORE(p)    ((*(p) = MROP_PREBUILT_SOLID(((srcpix<<24)|srcpix),*(p))), \
+                      (p)++,(*(p) = MROP_PREBUILT_SOLID(((srcpix<<16)|(srcpix>>8)),*(p))), \
+                      (p)++,(*(p) = MROP_PREBUILT_SOLID(((srcpix<<8)|(srcpix>>16)),*(p))))
+
+
+
+/* XXX TJR: I doubt that this optimised case works (because the non-24 bit case
+   was broken), so I've added the #if 0 below.  Someone who knows what they're
+   doing can re-enable it if they fix it */
+
+#if (MROP == Mcopy) && defined(FAST_CONSTANT_OFFSET_MODE) && defined(SHARED_IDCACHE) && 0
+# define Expand(left,right) {\
+    int part = nlwMiddle & ((PGSZB*2)-1); \
+    nlwMiddle *= 3; \
+    nlwMiddle >>= PWSH + 3; \
+    while (h--) { \
+       srcpix = psrc[srcy]; \
+       MROP_PREBUILD(srcpix); \
+       ++srcy; \
+       if (srcy == tileHeight) \
+           srcy = 0; \
+       left \
+       p += part; \
+       switch (part) { \
+       case 7: \
+           STORE24(p - 7, xtmp - 7); \
+       case 6: \
+           STORE24(p - 6, xtmp - 6); \
+       case 5: \
+           STORE24(p - 5, xtmp - 5); \
+       case 4: \
+           STORE24(p - 4, xtmp - 4); \
+       case 3: \
+           STORE24(p - 3, xtmp - 3); \
+       case 2: \
+           STORE24(p - 2, xtmp - 2); \
+       case 1: \
+           STORE24(p - 1, xtmp - 1); \
+       } \
+       nlw = nlwMiddle; \
+       while (nlw) { \
+           STORE24 (p + 0, xtmp + 0); \
+           STORE24 (p + 1, xtmp + 1); \
+           STORE24 (p + 2, xtmp + 2); \
+           STORE24 (p + 3, xtmp + 3); \
+           STORE24 (p + 4, xtmp + 4); \
+           STORE24 (p + 5, xtmp + 5); \
+           STORE24 (p + 6, xtmp + 6); \
+           STORE24 (p + 7, xtmp + 7); \
+           p += 8; \
+           xtmp += 8; \
+           nlw--; \
+       } \
+       right \
+       p += nlwExtra; \
+    } \
+}
+#else
+#define Expand(left,right) {\
+    while (h--)        { \
+       srcpix = psrc[srcy]; \
+       MROP_PREBUILD(srcpix); \
+       ++srcy; \
+       if (srcy == tileHeight) \
+           srcy = 0; \
+       left \
+       while (nlw--) \
+       { \
+           STORE24(p,xtmp); \
+           if(xtmp&3) p++; \
+           xtmp++; \
+       } \
+       right \
+       p += nlwExtra; \
+    } \
+}
+#endif
+#else /*PSZ != 24*/
+#define STORE(p)    (*(p) = MROP_PREBUILT_SOLID(srcpix,*(p)))
+
+#if (MROP == Mcopy) && defined(FAST_CONSTANT_OFFSET_MODE) && defined(SHARED_IDCACHE)
+# define Expand(left,right) {\
+    int part = nlwMiddle & 7; \
+    nlwMiddle >>= 3; \
+    while (h--) { \
+       srcpix = psrc[srcy]; \
+       MROP_PREBUILD(srcpix); \
+       ++srcy; \
+       if (srcy == tileHeight) \
+           srcy = 0; \
+       left \
+       p += part; \
+       switch (part) { \
+       case 7: \
+           STORE(p - 7); \
+       case 6: \
+           STORE(p - 6); \
+       case 5: \
+           STORE(p - 5); \
+       case 4: \
+           STORE(p - 4); \
+       case 3: \
+           STORE(p - 3); \
+       case 2: \
+           STORE(p - 2); \
+       case 1: \
+           STORE(p - 1); \
+       } \
+       nlw = nlwMiddle; \
+       while (nlw) { \
+           STORE (p + 0); \
+           STORE (p + 1); \
+           STORE (p + 2); \
+           STORE (p + 3); \
+           STORE (p + 4); \
+           STORE (p + 5); \
+           STORE (p + 6); \
+           STORE (p + 7); \
+           p += 8; \
+           nlw--; \
+       } \
+       right \
+       p += nlwExtra; \
+    } \
+}
+#else
+#define Expand(left,right) {\
+    while (h--)        { \
+       srcpix = psrc[srcy]; \
+       MROP_PREBUILD(srcpix); \
+       ++srcy; \
+       if (srcy == tileHeight) \
+           srcy = 0; \
+       left \
+       nlw = nlwMiddle; \
+       while (nlw--) \
+       { \
+           STORE(p); \
+           p++; \
+       } \
+       right \
+       p += nlwExtra; \
+    } \
+}
+#endif
+#endif /*PSZ == 24*/
+
+void
+MROP_NAME(cfbFillRectTile32) (pDrawable, pGC, nBox, pBox)
+    DrawablePtr            pDrawable;
+    GCPtr          pGC;
+    int                    nBox;       /* number of boxes to fill */
+    BoxPtr         pBox;       /* pointer to list of boxes to fill */
+{
+    register unsigned long srcpix;     
+    unsigned long *psrc;               /* pointer to bits in tile, if needed */
+    int tileHeight;    /* height of the tile */
+
+    int nlwDst;                /* width in longwords of the dest pixmap */
+    int w;             /* width of current box */
+    register int h;    /* height of current box */
+    register unsigned long startmask;
+    register unsigned long endmask; /* masks for reggedy bits at either end of line */
+    int nlwMiddle;     /* number of longwords between sides of boxes */
+    int nlwExtra;      /* to get from right of box to left of next span */
+    register int nlw;  /* loop version of nlwMiddle */
+    register unsigned long *p; /* pointer to bits we're writing */
+    int y;             /* current scan line */
+    int srcy;          /* current tile position */
+
+    unsigned long *pbits;/* pointer to start of pixmap */
+    PixmapPtr      tile;       /* rotated, expanded tile */
+    MROP_DECLARE_REG()
+    MROP_PREBUILT_DECLARE()
+#if PSZ == 24
+    unsigned long xtmp;
+#endif
+
+    tile = cfbGetGCPrivate(pGC)->pRotatedPixmap;
+    tileHeight = tile->drawable.height;
+    psrc = (unsigned long *)tile->devPrivate.ptr;
+
+    MROP_INITIALIZE(pGC->alu, pGC->planemask);
+
+    cfbGetLongWidthAndPointer (pDrawable, nlwDst, pbits)
+
+    while (nBox--)
+    {
+       w = pBox->x2 - pBox->x1;
+       h = pBox->y2 - pBox->y1;
+       y = pBox->y1;
+#if PSZ == 24
+       xtmp = pBox->x1;
+       p = pbits + (y * nlwDst) + ((pBox->x1*3) >> 2);
+/*     p = pbits + (y * nlwDst) + ((pBox->x1>> 2)*3);*/
+#else
+       p = pbits + (y * nlwDst) + (pBox->x1 >> PWSH);
+#endif
+       srcy = y % tileHeight;
+
+#if PSZ == 24
+       if (w == 1  &&  ((pBox->x1 & 3) == 0  ||  (pBox->x1 & 3) == 3))
+#else
+       if ( ((pBox->x1 & PIM) + w) <= PPW)
+#endif
+       {
+           maskpartialbits(pBox->x1, w, startmask);
+           nlwExtra = nlwDst;
+           while (h--)
+           {
+               srcpix = psrc[srcy];
+               MROP_PREBUILD(srcpix);
+               ++srcy;
+               if (srcy == tileHeight)
+                   srcy = 0;
+               *p = MROP_PREBUILT_MASK (srcpix, *p, startmask);
+               p += nlwExtra;
+           }
+       }
+       else
+       {
+           maskbits(pBox->x1, w, startmask, endmask, nlwMiddle);
+           nlwExtra = nlwDst - nlwMiddle;
+
+           if (startmask)
+           {
+               nlwExtra -= 1;
+               if (endmask)
+               {
+                   Expand(*p = MROP_PREBUILT_MASK(srcpix, *p, startmask); p++;,
+                          *p = MROP_PREBUILT_MASK(srcpix, *p, endmask);)
+               }
+               else
+               {
+                   Expand(*p = MROP_PREBUILT_MASK(srcpix, *p, startmask); p++;,
+                          ;)
+               }
+           }
+           else
+           {
+               if (endmask)
+               {
+                   Expand(;,
+                          *p = MROP_PREBUILT_MASK(srcpix, *p, endmask);)
+               }
+               else
+               {
+                   Expand(;,
+                          ;)
+               }
+           }
+       }
+        pBox++;
+    }
+}
+
+void
+MROP_NAME(cfbTile32FS)(pDrawable, pGC, nInit, pptInit, pwidthInit, fSorted)
+    DrawablePtr pDrawable;
+    GCPtr      pGC;
+    int                nInit;                  /* number of spans to fill */
+    DDXPointPtr pptInit;               /* pointer to list of start points */
+    int                *pwidthInit;            /* pointer to list of n widths */
+    int        fSorted;
+{
+                               /* next three parameters are post-clip */
+    int                        n;      /* number of spans to fill */
+    DDXPointPtr                ppt;    /* pointer to list of start points */
+    int                        *pwidth;/* pointer to list of n widths */
+    unsigned long      *pbits; /* pointer to start of bitmap */
+    int                        nlwDst; /* width in longwords of bitmap */
+    register unsigned long *p; /* pointer to current longword in bitmap */
+    register int       w;      /* current span width */
+    register int       nlw;
+    register int       x;
+    register unsigned long startmask;
+    register unsigned long endmask;
+    register unsigned long  srcpix;
+    int                        y;
+    int                        *pwidthFree;/* copies of the pointers to free */
+    DDXPointPtr                pptFree;
+    PixmapPtr          tile;
+    unsigned long      *psrc;  /* pointer to bits in tile */
+    int                        tileHeight;/* height of the tile */
+    MROP_DECLARE_REG ()
+    MROP_PREBUILT_DECLARE()
+#if PSZ == 24      
+    unsigned long      xtmp;
+#endif
+
+    n = nInit * miFindMaxBand( cfbGetCompositeClip(pGC) );
+    pwidthFree = (int *)ALLOCATE_LOCAL(n * sizeof(int));
+    pptFree = (DDXPointRec *)ALLOCATE_LOCAL(n * sizeof(DDXPointRec));
+    if(!pptFree || !pwidthFree)
+    {
+       if (pptFree) DEALLOCATE_LOCAL(pptFree);
+       if (pwidthFree) DEALLOCATE_LOCAL(pwidthFree);
+       return;
+    }
+    pwidth = pwidthFree;
+    ppt = pptFree;
+    n = miClipSpans( cfbGetCompositeClip(pGC),
+                    pptInit, pwidthInit, nInit,
+                    ppt, pwidth, fSorted);
+
+    tile = cfbGetGCPrivate(pGC)->pRotatedPixmap;
+    tileHeight = tile->drawable.height;
+    psrc = (unsigned long *)tile->devPrivate.ptr;
+
+    MROP_INITIALIZE(pGC->alu, pGC->planemask);
+
+    cfbGetLongWidthAndPointer (pDrawable, nlwDst, pbits)
+
+#if MROP == Mcopy
+    if (!(tileHeight & (tileHeight-1)))
+    {
+       tileHeight--;
+       while (n--)
+       {
+           x = ppt->x;
+           y = ppt->y;
+           ++ppt;
+           w = *pwidth++;
+#if PSZ == 24
+/*         p = pbits + (y * nlwDst) + ((x*3) >> 2);*/
+           xtmp = x;
+           p = pbits + (y * nlwDst) + ((x >> 2)*3);
+#else
+           p = pbits + (y * nlwDst) + (x >> PWSH);
+#endif
+           srcpix = psrc[y & tileHeight];
+           MROP_PREBUILD(srcpix);
+    
+#if PSZ == 24
+           if ((x & 3) + w < 5)
+#else
+           if ((x & PIM) + w < PPW)
+#endif
+           {
+               maskpartialbits(x, w, startmask);
+               *p = MROP_PREBUILT_MASK (srcpix, *p, startmask);
+           }
+           else
+           {
+               maskbits(x, w, startmask, endmask, nlw);
+               if (startmask)
+               {
+                   *p = MROP_PREBUILT_MASK(srcpix, *p, startmask);
+#if PSZ == 24
+                   if(xtmp&3) p++;
+                   xtmp++;
+#else
+                   p++;
+#endif
+               }
+               while (nlw--)
+               {
+#if PSZ == 24
+                   STORE24(p,xtmp);
+                   if(xtmp&3) p++;
+                   ++xtmp;
+#else
+                   STORE(p);
+                   ++p;
+#endif
+               }
+               if (endmask)
+               {
+                   *p = MROP_PREBUILT_MASK(srcpix, *p, endmask);
+               }
+           }
+       }
+    }
+    else
+#endif
+    {
+       while (n--)
+       {
+           x = ppt->x;
+           y = ppt->y;
+           ++ppt;
+           w = *pwidth++;
+#if PSZ == 24
+/*         p = pbits + (y * nlwDst) + ((x *3)>> 2);*/
+           p = pbits + (y * nlwDst) + ((x >> 2)*3);
+           xtmp = x;
+#else
+           p = pbits + (y * nlwDst) + (x >> PWSH);
+#endif
+           srcpix = psrc[y % tileHeight];
+           MROP_PREBUILD(srcpix);
+    
+#if PSZ == 24
+           if ((x & 3) + w < 5)
+#else
+           if ((x & PIM) + w < PPW)
+#endif
+           {
+               maskpartialbits(x, w, startmask);
+               *p = MROP_PREBUILT_MASK (srcpix, *p, startmask);
+           }
+           else
+           {
+               maskbits(x, w, startmask, endmask, nlw);
+               if (startmask)
+               {
+                   *p = MROP_PREBUILT_MASK(srcpix, *p, startmask);
+#if PSZ == 24
+                   if(xtmp&3)p++;
+                   xtmp++;
+#else
+                   p++;
+#endif
+               }
+               while (nlw--)
+               {
+#if PSZ == 24
+                   STORE24(p,xtmp);
+                   if(xtmp&3)p++;
+                   xtmp++;
+#else
+                   STORE(p);
+                   ++p;
+#endif
+               }
+               if (endmask)
+               {
+                   *p = MROP_PREBUILT_MASK(srcpix, *p, endmask);
+               }
+           }
+       }
+    }
+    DEALLOCATE_LOCAL(pptFree);
+    DEALLOCATE_LOCAL(pwidthFree);
+}
diff --git a/Xserver/programs/Xserver/cfb/cfbtileodd.c b/Xserver/programs/Xserver/cfb/cfbtileodd.c
new file mode 100644 (file)
index 0000000..30ac617
--- /dev/null
@@ -0,0 +1,1220 @@
+/*
+ * Fill odd tiled rectangles and spans.
+ * no depth dependencies.
+ */
+
+/*
+
+Copyright (c) 1989  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+*/
+
+/* $XConsortium: cfbtileodd.c,v 1.16 94/04/17 20:29:06 dpw Exp $ */
+/* $XFree86: xc/programs/Xserver/cfb/cfbtileodd.c,v 3.0 1996/06/29 09:05:55 dawes Exp $ */
+
+#include "X.h"
+#include "Xmd.h"
+#include "servermd.h"
+#include "gcstruct.h"
+#include "window.h"
+#include "pixmapstr.h"
+#include "scrnintstr.h"
+#include "windowstr.h"
+
+#include "cfb.h"
+#include "cfbmskbits.h"
+#include "cfb8bit.h"
+
+#include "mergerop.h"
+
+#if PSZ == 24
+#if PGSZ == 32
+#define LEFTSHIFT_AMT (3)
+#else /* PGSZ == 64 */
+#define LEFTSHIFT_AMT (4 - PWSH)
+#endif /* PGSZ */
+#else /* PSZ != 24 */
+#if PGSZ == 32
+#define LEFTSHIFT_AMT (5 - PWSH)
+#else /* PGSZ == 64 */
+#define LEFTSHIFT_AMT (6 - PWSH)
+#endif /* PGSZ */
+#endif /* PSZ == 24*/
+
+#define LastTileBits {\
+    tmp = bits; \
+    if (tileEndPart) \
+       bits = (*pSrc & tileEndMask) | BitRight (*pSrcLine, tileEndLeftShift); \
+    else \
+       bits = *pSrc; \
+}
+
+#if PSZ == 24
+#define ResetTileBits {\
+    pSrc = pSrcLine; \
+    nlwSrc = widthSrc;\
+    if (tileEndPart) { \
+       if (4 - xoff + tileEndPart <= 4) {\
+           bits = *pSrc++; \
+           nlwSrc--; \
+       } else \
+           bits = BitLeft(tmp, tileEndLeftShift) | \
+                  BitRight(bits, tileEndRightShift); \
+       xoff = (xoff + xoffStep) & 3; \
+       leftShift = xoff << LEFTSHIFT_AMT; \
+       rightShift = PGSZ - leftShift; \
+    }\
+}
+#else
+#define ResetTileBits {\
+    pSrc = pSrcLine; \
+    nlwSrc = widthSrc;\
+    if (tileEndPart) { \
+       if (PPW - xoff + tileEndPart <= PPW) {\
+           bits = *pSrc++; \
+           nlwSrc--; \
+       } else \
+           bits = BitLeft(tmp, tileEndLeftShift) | \
+                  BitRight(bits, tileEndRightShift); \
+       xoff = (xoff + xoffStep) & PIM; \
+       leftShift = xoff << LEFTSHIFT_AMT; \
+       rightShift = PGSZ - leftShift; \
+    }\
+}
+#endif
+
+#define NextTileBits {\
+    if (nlwSrc == 1) {\
+       LastTileBits\
+    } else { \
+       if (nlwSrc == 0) {\
+           ResetTileBits\
+       } \
+       if (nlwSrc == 1) {\
+           LastTileBits\
+       } else {\
+           tmp = bits; \
+           bits = *pSrc++; \
+       }\
+    }\
+    nlwSrc--; \
+}
+
+void
+MROP_NAME(cfbFillBoxTileOdd) (pDrawable, nBox, pBox, tile, xrot, yrot, alu, planemask)
+    DrawablePtr            pDrawable;
+    int                    nBox;       /* number of boxes to fill */
+    register BoxPtr pBox;      /* pointer to list of boxes to fill */
+    PixmapPtr      tile;       /* tile */
+    int                    xrot, yrot;
+    int                    alu;
+    unsigned long   planemask;
+{
+    int tileWidth;     /* width of tile in pixels */
+    int tileHeight;    /* height of the tile */
+    int widthSrc;
+
+    int widthDst;      /* width in longwords of the dest pixmap */
+    int w;             /* width of current box */
+    int h;             /* height of current box */
+    unsigned long startmask;
+    unsigned long endmask;/* masks for reggedy bits at either end of line */
+    int nlwMiddle;     /* number of longwords between sides of boxes */
+    int nlwSrc;                /* number of whole longwords in source */
+    
+    register int nlw;  /* loop version of nlwMiddle */
+    int srcy;          /* current tile y position */
+    int srcx;          /* current tile x position */
+    int xoffDst, xoffSrc;
+    int leftShift, rightShift;
+
+    MROP_DECLARE_REG()
+
+    unsigned long *pDstBase;   /* pointer to start of dest */
+    unsigned long *pDstLine;   /* poitner to start of dest box */
+    unsigned long *pSrcBase;   /* pointer to start of source */
+    unsigned long *pSrcLine;   /* pointer to start of source line */
+    register unsigned long *pDst;
+    register unsigned long *pSrc;
+    register unsigned long bits, tmp;
+    register int          nlwPart;
+    int xoffStart, xoff;
+    int leftShiftStart, rightShiftStart, nlwSrcStart;
+    unsigned long tileEndMask;
+    int tileEndLeftShift, tileEndRightShift;
+    int        xoffStep;
+    int tileEndPart;
+    int needFirst;
+    unsigned long   narrow[2];
+    unsigned long   narrowMask;
+    int            narrowShift;
+    Bool    narrowTile;
+
+    MROP_INITIALIZE (alu, planemask)
+
+    tileHeight = tile->drawable.height;
+    tileWidth = tile->drawable.width;
+    widthSrc = tile->devKind / PGSZB;
+    narrowTile = FALSE;
+    if (widthSrc == 1)
+    {
+       narrowShift = tileWidth;
+       narrowMask = cfbendpartial [tileWidth];
+       tileWidth *= 2;
+       widthSrc = 2;
+       narrowTile = TRUE;
+    }
+    pSrcBase = (unsigned long *)tile->devPrivate.ptr;
+
+    cfbGetLongWidthAndPointer (pDrawable, widthDst, pDstBase)
+
+#if PSZ == 24
+    tileEndPart = (4 - tileWidth) & 3;
+    tileEndMask = cfbendpartial[tileWidth & 3];
+#else
+    tileEndPart = tileWidth & PIM;
+    tileEndMask = cfbendpartial[tileEndPart];
+#endif /* PSZ == 24 */
+    tileEndLeftShift = (tileEndPart) << LEFTSHIFT_AMT;
+    tileEndRightShift = PGSZ - tileEndLeftShift;
+#if PSZ == 24
+    xoffStep = 4 - tileEndPart;
+#else
+    xoffStep = PPW - tileEndPart;
+#endif /* PSZ == 24 */
+    /*
+     * current assumptions: tile > 32 bits wide.
+     */
+    while (nBox--)
+    {
+       w = pBox->x2 - pBox->x1;
+       h = pBox->y2 - pBox->y1;
+       modulus (pBox->x1 - xrot, tileWidth, srcx);
+       modulus (pBox->y1 - yrot, tileHeight, srcy);
+#if PSZ == 24
+       xoffDst = (4 - pBox->x1) & 3;
+       if (w == 1  &&  (xoffDst == 0  ||  xoffDst == 1))
+#else
+       xoffDst = pBox->x1 & PIM;
+       if (xoffDst + w < PPW)
+#endif
+       {
+           maskpartialbits(pBox->x1, w, startmask);
+           endmask = 0;
+           nlwMiddle = 0;
+       }
+       else
+       {
+           maskbits (pBox->x1, w, startmask, endmask, nlwMiddle)
+       }
+#if PSZ == 24
+       pDstLine = pDstBase + (pBox->y1 * widthDst) + ((pBox->x1*3) >> 2);
+#else
+       pDstLine = pDstBase + (pBox->y1 * widthDst) + (pBox->x1 >> PWSH);
+#endif
+       pSrcLine = pSrcBase + (srcy * widthSrc);
+#if PSZ == 24
+       xoffSrc = (4 - srcx) & 3;
+#else
+       xoffSrc = srcx & PIM;
+#endif
+       if (xoffSrc >= xoffDst)
+       {
+           xoffStart = xoffSrc - xoffDst;
+           needFirst = 1;
+       }
+       else
+       {
+#if PSZ == 24
+           xoffStart = 4 - (xoffDst - xoffSrc);
+#else
+           xoffStart = PPW - (xoffDst - xoffSrc);
+#endif
+           needFirst = 0;
+       }
+       leftShiftStart = (xoffStart) << LEFTSHIFT_AMT;
+       rightShiftStart = PGSZ - leftShiftStart;
+#if PSZ == 24
+       nlwSrcStart = widthSrc - ((srcx*3) >> 2);
+#else
+       nlwSrcStart = widthSrc - (srcx >> PWSH);
+#endif
+       while (h--)
+       {
+           /* XXX only works when narrowShift >= PPW/2 */
+           if (narrowTile)
+           {
+               tmp = pSrcBase[srcy] & narrowMask; /* source width == 1 */
+               narrow[0] = tmp | SCRRIGHT (tmp, narrowShift);
+#if PSZ == 24
+               narrow[1] = BitLeft (tmp, 8) |
+                           BitRight(tmp, 16);
+#else
+               narrow[1] = SCRLEFT (tmp, PPW - narrowShift) |
+                           SCRRIGHT(tmp, 2 * narrowShift - PPW);
+#endif
+               pSrcLine = narrow;
+           }
+           xoff = xoffStart;
+           leftShift = leftShiftStart;
+           rightShift = rightShiftStart;
+           nlwSrc = nlwSrcStart;
+#if PSZ == 24
+           pSrc = pSrcLine + ((srcx * 3) >> 2);
+#else
+           pSrc = pSrcLine + (srcx >> PWSH);
+#endif
+           pDst = pDstLine;
+           bits = 0;
+           if (needFirst)
+           {
+               NextTileBits
+           }
+           if (startmask)
+           {
+               NextTileBits
+               tmp = BitLeft(tmp, leftShift);
+               if (rightShift != PGSZ)
+                   tmp |= BitRight(bits,rightShift);
+               *pDst = MROP_MASK (tmp, *pDst, startmask);
+               ++pDst;
+           }
+           nlw = nlwMiddle;
+           while (nlw)
+           {
+#if MROP == Mcopy
+               if (nlwSrc > 1)
+               {
+                   nlwPart = nlw;
+                   if (nlwPart >= nlwSrc)
+                       nlwPart = nlwSrc - 1;
+                   nlw -= nlwPart;
+                   nlwSrc -= nlwPart;
+                   if (rightShift != PGSZ)
+                   {
+                       while (nlwPart--)
+                       {
+                           tmp = bits;
+                           bits = *pSrc++;
+                           *pDst = MROP_SOLID(BitLeft(tmp, leftShift) |
+                                             BitRight (bits, rightShift),
+                                             *pDst);
+                           ++pDst;
+                       }
+                   }
+                   else
+                   {
+                       if (nlwPart)
+                       {
+                           *pDst = MROP_SOLID (bits, *pDst);
+                           ++pDst;
+                           nlwPart--;
+                           while (nlwPart--)
+                           {
+                               *pDst = MROP_SOLID(*pSrc, *pDst);
+                               ++pDst; ++pSrc;
+                           }
+                           bits = *pSrc++;
+                       }
+                   }
+               }
+               else
+#endif
+               {
+                   NextTileBits
+                   if (rightShift != PGSZ)
+                   {
+                       *pDst = MROP_SOLID(BitLeft(tmp, leftShift) |
+                                          BitRight(bits, rightShift),
+                                          *pDst);
+                   }
+                   else
+                   {
+                       *pDst = MROP_SOLID (tmp, *pDst);
+                   }
+                   ++pDst;
+                   nlw--;
+               }
+           }
+           if (endmask)
+           {
+               NextTileBits
+               if (rightShift == PGSZ)
+                   bits = 0;
+               *pDst = MROP_MASK (BitLeft(tmp, leftShift) |
+                                  BitRight(bits,rightShift),
+                                  *pDst, endmask);
+           }
+           pDstLine += widthDst;
+           pSrcLine += widthSrc;
+           if (++srcy == tileHeight)
+           {
+               srcy = 0;
+               pSrcLine = pSrcBase;
+           }
+       }
+       pBox++;
+    }
+}
+
+void
+MROP_NAME(cfbFillSpanTileOdd) (pDrawable, n, ppt, pwidth, tile, xrot, yrot, alu, planemask)
+    DrawablePtr        pDrawable;
+    int                n;
+    DDXPointPtr        ppt;
+    int                *pwidth;
+    PixmapPtr  tile;
+    int                xrot, yrot;
+    int                alu;
+    unsigned long   planemask;
+{
+    int tileWidth;     /* width of tile in pixels */
+    int tileHeight;    /* height of the tile */
+    int widthSrc;
+
+    int widthDst;              /* width in longwords of the dest pixmap */
+    int w;             /* width of current span */
+    unsigned long startmask;
+    unsigned long endmask;     /* masks for reggedy bits at either end of line */
+    int nlwSrc;                /* number of whole longwords in source */
+    
+    register int nlw;  /* loop version of nlwMiddle */
+    int srcy;          /* current tile y position */
+    int srcx;          /* current tile x position */
+    int xoffDst, xoffSrc;
+    int leftShift, rightShift;
+
+    MROP_DECLARE_REG()
+
+    unsigned long *pDstBase;   /* pointer to start of dest */
+    unsigned long *pDstLine;   /* poitner to start of dest box */
+    unsigned long *pSrcBase;   /* pointer to start of source */
+    unsigned long *pSrcLine;   /* pointer to start of source line */
+    register unsigned long *pDst;
+    register unsigned long *pSrc;
+    register unsigned long bits, tmp;
+    register int          nlwPart;
+    int xoffStart, xoff;
+    int leftShiftStart, rightShiftStart, nlwSrcStart;
+    unsigned long tileEndMask;
+    int tileEndLeftShift, tileEndRightShift;
+    int        xoffStep;
+    int tileEndPart;
+    int needFirst;
+    unsigned long   narrow[2];
+    unsigned long   narrowMask;
+    int            narrowShift;
+    Bool    narrowTile;
+
+    MROP_INITIALIZE (alu, planemask)
+
+    tileHeight = tile->drawable.height;
+    tileWidth = tile->drawable.width;
+    widthSrc = tile->devKind / PGSZB;
+    narrowTile = FALSE;
+    if (widthSrc == 1)
+    {
+       narrowShift = tileWidth;
+       narrowMask = cfbendpartial [tileWidth];
+       tileWidth *= 2;
+       widthSrc = 2;
+       narrowTile = TRUE;
+    }
+    pSrcBase = (unsigned long *)tile->devPrivate.ptr;
+
+    cfbGetLongWidthAndPointer (pDrawable, widthDst, pDstBase)
+
+#if PSZ == 24
+    tileEndPart = (4 - tileWidth) & 3;
+    tileEndMask = cfbendpartial[tileWidth & 3];
+#else
+    tileEndPart = tileWidth & PIM;
+    tileEndMask = cfbendpartial[tileEndPart];
+#endif
+    tileEndLeftShift = (tileEndPart) << LEFTSHIFT_AMT;
+    tileEndRightShift = PGSZ - tileEndLeftShift;
+#if PSZ == 24
+    xoffStep = 4 - tileEndPart;
+#else
+    xoffStep = PPW - tileEndPart;
+#endif
+    while (n--)
+    {
+       w = *pwidth++;
+       modulus (ppt->x - xrot, tileWidth, srcx);
+       modulus (ppt->y - yrot, tileHeight, srcy);
+#if PSZ == 24
+       xoffDst = (4 - ppt->x) & 3;
+       if (w == 1  &&  (xoffDst == 0  ||  xoffDst == 1))
+#else
+       xoffDst = ppt->x & PIM;
+       if (xoffDst + w < PPW)
+#endif
+       {
+           maskpartialbits(ppt->x, w, startmask);
+           endmask = 0;
+           nlw = 0;
+       }
+       else
+       {
+           maskbits (ppt->x, w, startmask, endmask, nlw)
+       }
+#if PSZ == 24
+       pDstLine = pDstBase + (ppt->y * widthDst)  + ((ppt->x *3)>> 2);
+#else
+       pDstLine = pDstBase + (ppt->y * widthDst) + (ppt->x >> PWSH);
+#endif
+       pSrcLine = pSrcBase + (srcy * widthSrc);
+#if PSZ == 24
+       xoffSrc = (4 - srcx) & 3;
+#else
+       xoffSrc = srcx & PIM;
+#endif
+       if (xoffSrc >= xoffDst)
+       {
+           xoffStart = xoffSrc - xoffDst;
+           needFirst = 1;
+       }
+       else
+       {
+#if PSZ == 24
+           xoffStart = 4 - (xoffDst - xoffSrc);
+#else
+           xoffStart = PPW - (xoffDst - xoffSrc);
+#endif
+           needFirst = 0;
+       }
+       leftShiftStart = (xoffStart) << LEFTSHIFT_AMT;
+       rightShiftStart = PGSZ - leftShiftStart;
+#if PSZ == 24
+       nlwSrcStart = widthSrc - ((srcx*3) >> 2);
+#else
+       nlwSrcStart = widthSrc - (srcx >> PWSH);
+#endif
+       /* XXX only works when narrowShift >= PPW/2 */
+       if (narrowTile)
+       {
+           tmp = pSrcBase[srcy] & narrowMask;  /* source width == 1 */
+           narrow[0] = tmp | SCRRIGHT (tmp, narrowShift);
+#if PSZ == 24
+           narrow[1] = BitLeft (tmp, 8) |
+                       BitRight(tmp, 16);
+#else
+           narrow[1] = SCRLEFT (tmp, PPW - narrowShift) |
+                       SCRRIGHT(tmp, 2 * narrowShift - PPW);
+#endif
+           pSrcLine = narrow;
+       }
+       xoff = xoffStart;
+       leftShift = leftShiftStart;
+       rightShift = rightShiftStart;
+       nlwSrc = nlwSrcStart;
+#if PSZ == 24
+       pSrc = pSrcLine + ((srcx * 3) >> 2);
+#else
+       pSrc = pSrcLine + (srcx >> PWSH);
+#endif
+       pDst = pDstLine;
+       bits = 0;
+       if (needFirst)
+       {
+           NextTileBits
+       }
+       if (startmask)
+       {
+           NextTileBits
+           tmp = BitLeft(tmp, leftShift);
+           if (rightShift != PGSZ)
+               tmp |= BitRight(bits,rightShift);
+           *pDst = MROP_MASK (tmp, *pDst, startmask);
+           ++pDst;
+       }
+       while (nlw)
+       {
+#if MROP == Mcopy
+           if (nlwSrc > 1)
+           {
+               nlwPart = nlw;
+               if (nlwPart >= nlwSrc)
+                   nlwPart = nlwSrc - 1;
+               nlw -= nlwPart;
+               nlwSrc -= nlwPart;
+               if (rightShift != PGSZ)
+               {
+                   while (nlwPart--)
+                   {
+                       tmp = bits;
+                       bits = *pSrc++;
+                       *pDst = MROP_SOLID(BitLeft(tmp, leftShift) |
+                                         BitRight (bits, rightShift),
+                                         *pDst);
+                       ++pDst;
+                   }
+               }
+               else
+               {
+                   if (nlwPart)
+                   {
+                       *pDst = MROP_SOLID (bits, *pDst);
+                       ++pDst;
+                       nlwPart--;
+                       while (nlwPart--)
+                       {
+                           *pDst = MROP_SOLID(*pSrc, *pDst);
+                           ++pDst; ++pSrc;
+                       }
+                       bits = *pSrc++;
+                   }
+               }
+           }
+           else
+#endif
+           {
+               NextTileBits
+               if (rightShift != PGSZ)
+               {
+                   *pDst = MROP_SOLID(BitLeft(tmp, leftShift) |
+                                      BitRight(bits, rightShift),
+                                      *pDst);
+                   ++pDst;
+               }
+               else
+               {
+                   *pDst = MROP_SOLID (tmp, *pDst);
+                   ++pDst;
+               }
+               nlw--;
+           }
+       }
+       if (endmask)
+       {
+           NextTileBits
+           if (rightShift == PGSZ)
+               bits = 0;
+           *pDst = MROP_MASK (BitLeft(tmp, leftShift) |
+                              BitRight(bits,rightShift),
+                              *pDst, endmask);
+       }
+       ppt++;
+    }
+}
+
+# include "fastblt.h"
+
+#define IncSrcPtr   psrc++; if (!--srcRemaining) { srcRemaining = widthSrc; psrc = psrcStart; }
+
+void
+MROP_NAME(cfbFillBoxTile32s) (pDrawable, nBox, pBox, tile, xrot, yrot, alu, planemask)
+    DrawablePtr            pDrawable;
+    int                    nBox;       /* number of boxes to fill */
+    register BoxPtr pBox;      /* pointer to list of boxes to fill */
+    PixmapPtr      tile;       /* tile */
+    int                    xrot, yrot;
+    int                    alu;
+    unsigned long   planemask;
+{
+    int        tileWidth;      /* width of tile */
+    int tileHeight;    /* height of the tile */
+    int        widthSrc;       /* width in longwords of the source tile */
+
+    int widthDst;      /* width in longwords of the dest pixmap */
+    int w;             /* width of current box */
+    int h;             /* height of current box */
+    unsigned long startmask;
+    unsigned long endmask;/* masks for reggedy bits at either end of line */
+    int nlMiddle;      /* number of longwords between sides of boxes */
+    
+    register int nl;   /* loop version of nlMiddle */
+    int srcy;          /* current tile y position */
+    int srcx;          /* current tile x position */
+    int        srcRemaining;   /* number of longwords remaining in source */
+    int xoffDst, xoffSrc;
+    int        srcStart;       /* number of longwords source offset at left of box */
+    int        leftShift, rightShift;
+
+    MROP_DECLARE_REG()
+
+    unsigned long          *pdstBase;  /* pointer to start of dest */
+    unsigned long          *pdstLine;  /* poitner to start of dest box */
+    unsigned long          *psrcBase;  /* pointer to start of source */
+    unsigned long          *psrcLine;  /* pointer to fetch point of source */
+    unsigned long          *psrcStart; /* pointer to start of source line */
+    register unsigned long  *pdst;
+    register unsigned long  *psrc;
+    register unsigned long  bits, bits1;
+    register int           nlTemp;
+
+    MROP_INITIALIZE (alu, planemask)
+
+    psrcBase = (unsigned long *)tile->devPrivate.ptr;
+    tileHeight = tile->drawable.height;
+    tileWidth = tile->drawable.width;
+#if PSZ == 24
+    widthSrc = tile->devKind / PGSZB;
+#else
+    widthSrc = tileWidth >> PWSH;
+#endif
+
+    cfbGetLongWidthAndPointer (pDrawable, widthDst, pdstBase)
+
+    while (nBox--)
+    {
+       w = pBox->x2 - pBox->x1;
+       h = pBox->y2 - pBox->y1;
+
+       /* set up source */
+       modulus (pBox->x1 - xrot, tileWidth, srcx);
+       modulus (pBox->y1 - yrot, tileHeight, srcy);
+#if PSZ == 24
+       xoffSrc = (4 - srcx) & 3;
+       srcStart = (srcx * 3) >> 2;
+#else
+       xoffSrc = srcx & PIM;
+       srcStart = (srcx >> PWSH);
+#endif
+       psrcStart = psrcBase + (srcy * widthSrc);
+       psrcLine = psrcStart + srcStart;
+
+       /* set up dest */
+#if PSZ == 24
+       xoffDst = (4 - pBox->x1) & 3;
+       pdstLine = pdstBase + (pBox->y1 * widthDst) + ((pBox->x1*3) >> 2);
+#else
+       xoffDst = pBox->x1 & PIM;
+       pdstLine = pdstBase + (pBox->y1 * widthDst) + (pBox->x1 >> PWSH);
+#endif
+       /* set up masks */
+#if PSZ == 24
+       if (w == 1  &&  (xoffDst == 0  ||  xoffDst == 1))
+#else
+       if (xoffDst + w < PPW)
+#endif
+       {
+           maskpartialbits(pBox->x1, w, startmask);
+           endmask = 0;
+           nlMiddle = 0;
+       }
+       else
+       {
+           maskbits (pBox->x1, w, startmask, endmask, nlMiddle)
+       }
+       if (xoffSrc == xoffDst)
+       {
+           while (h--)
+           {
+               psrc = psrcLine;
+               pdst = pdstLine;
+               srcRemaining = widthSrc - srcStart;
+               if (startmask)
+               {
+                   *pdst = MROP_MASK (*psrc, *pdst, startmask);
+                   pdst++;
+                   IncSrcPtr
+               }
+               nlTemp = nlMiddle;
+               while (nlTemp)
+               {
+                   nl = nlTemp;
+                   if (nl > srcRemaining)
+                       nl = srcRemaining;
+
+                   nlTemp -= nl;
+                   srcRemaining -= nl;
+
+#if MROP == Mcopy
+#ifdef LARGE_INSTRUCTION_CACHE
+#ifdef FAST_CONSTANT_OFFSET_MODE
+
+                   psrc += nl & (UNROLL-1);
+                   pdst += nl & (UNROLL-1);
+
+#define BodyOdd(n) pdst[-n] = MROP_SOLID (psrc[-n], pdst[-n]);
+#define BodyEven(n) pdst[-n] = MROP_SOLID (psrc[-n], pdst[-n]);
+
+#define LoopReset \
+pdst += UNROLL; \
+psrc += UNROLL;
+
+#else
+
+#define BodyOdd(n)  *pdst = MROP_SOLID (*psrc, *pdst); pdst++; psrc++;
+#define BodyEven(n) BodyOdd(n)
+
+#define LoopReset   ;
+
+#endif
+                   PackedLoop
+
+#undef BodyOdd
+#undef BodyEven
+#undef LoopReset
+
+#else
+                   DuffL(nl, label1,
+                           *pdst = MROP_SOLID (*psrc, *pdst);
+                           pdst++; psrc++;)
+#endif
+#else
+                   while (nl--) {
+                           *pdst = MROP_SOLID (*psrc, *pdst);
+                           pdst++; psrc++;
+                   }
+#endif
+                   if (!srcRemaining)
+                   {
+                       srcRemaining = widthSrc;
+                       psrc = psrcStart;
+                   }
+               }
+               if (endmask)
+               {
+                   *pdst = MROP_MASK (*psrc, *pdst, endmask);
+               }
+               pdstLine += widthDst;
+               psrcLine += widthSrc;
+               psrcStart += widthSrc;
+               if (++srcy == tileHeight)
+               {
+                   psrcStart = psrcBase;
+                   psrcLine = psrcStart + srcStart;
+                   srcy = 0;
+               }
+           }
+       }
+       else
+       {
+           if (xoffSrc > xoffDst)
+           {
+               leftShift = (xoffSrc - xoffDst) << LEFTSHIFT_AMT;
+               rightShift = PGSZ - leftShift;
+           }
+           else
+           {
+               rightShift = (xoffDst - xoffSrc) << LEFTSHIFT_AMT;
+               leftShift = PGSZ - rightShift;
+           }
+           while (h--)
+           {
+               psrc = psrcLine;
+               pdst = pdstLine;
+               bits = 0;
+               srcRemaining = widthSrc - srcStart;
+               if (xoffSrc > xoffDst)
+               {
+                   bits = *psrc;
+                   IncSrcPtr
+               }
+               if (startmask)
+               {
+                   bits1 = BitLeft(bits,leftShift);
+                   bits = *psrc;
+                   IncSrcPtr
+                   bits1 |= BitRight(bits,rightShift);
+                   *pdst = MROP_MASK(bits1, *pdst, startmask);
+                   pdst++;
+               }
+               nlTemp = nlMiddle;
+               while (nlTemp)
+               {
+                   nl = nlTemp;
+                   if (nl > srcRemaining)
+                       nl = srcRemaining;
+
+                   nlTemp -= nl;
+                   srcRemaining -= nl;
+    
+#if MROP == Mcopy
+#ifdef LARGE_INSTRUCTION_CACHE
+                   bits1 = bits;
+    
+#ifdef FAST_CONSTANT_OFFSET_MODE
+    
+                   psrc += nl & (UNROLL-1);
+                   pdst += nl & (UNROLL-1);
+    
+#define BodyOdd(n) \
+    bits = psrc[-n]; \
+    pdst[-n] = MROP_SOLID(BitLeft(bits1, leftShift) | BitRight(bits, rightShift), pdst[-n]);
+    
+#define BodyEven(n) \
+    bits1 = psrc[-n]; \
+    pdst[-n] = MROP_SOLID(BitLeft(bits, leftShift) | BitRight(bits1, rightShift), pdst[-n]);
+    
+#define LoopReset \
+    pdst += UNROLL; \
+    psrc += UNROLL;
+    
+#else
+    
+#define BodyOdd(n) \
+    bits = *psrc++; \
+    *pdst = MROP_SOLID(BitLeft(bits1, leftShift) | BitRight(bits, rightShift), *pdst); \
+    pdst++;
+                  
+#define BodyEven(n) \
+    bits1 = *psrc++; \
+    *pdst = MROP_SOLID(BitLeft(bits, leftShift) | BitRight(bits1, rightShift), *pdst); \
+    pdst++;
+    
+#define LoopReset   ;
+    
+#endif /* !FAST_CONSTANT_OFFSET_MODE */
+    
+                   PackedLoop
+    
+#undef BodyOdd
+#undef BodyEven
+#undef LoopReset
+    
+#else
+                   DuffL (nl,label2,
+                       bits1 = BitLeft(bits, leftShift);
+                       bits = *psrc++;
+                       *pdst = MROP_SOLID (bits1 | BitRight(bits, rightShift), *pdst);
+                       pdst++;
+                   )
+#endif
+#else
+                   while (nl--) {
+                       bits1 = BitLeft(bits, leftShift);
+                       bits = *psrc++;
+                       *pdst = MROP_SOLID (bits1 | BitRight(bits, rightShift), *pdst);
+                       pdst++;
+                   }
+#endif
+                   if (!srcRemaining)
+                   {
+                       srcRemaining = widthSrc;
+                       psrc = psrcStart;
+                   }
+               }
+
+               if (endmask)
+               {
+                   bits1 = BitLeft(bits, leftShift);
+                   if (BitLeft(endmask, rightShift))
+                   {
+                       bits = *psrc;
+                       bits1 |= BitRight(bits, rightShift);
+                   }
+                   *pdst = MROP_MASK (bits1, *pdst, endmask);
+               }
+               pdstLine += widthDst;
+               psrcLine += widthSrc;
+               psrcStart += widthSrc;
+               if (++srcy == tileHeight)
+               {
+                   psrcStart = psrcBase;
+                   psrcLine = psrcStart + srcStart;
+                   srcy = 0;
+               }
+           }
+       }
+       pBox++;
+    }
+}
+
+void
+MROP_NAME(cfbFillSpanTile32s) (pDrawable, n, ppt, pwidth, tile, xrot, yrot, alu, planemask)
+    DrawablePtr        pDrawable;
+    int                n;
+    DDXPointPtr        ppt;
+    int                *pwidth;
+    PixmapPtr  tile;
+    int                xrot, yrot;
+    int                alu;
+    unsigned long   planemask;
+{
+    int        tileWidth;      /* width of tile */
+    int tileHeight;    /* height of the tile */
+    int        widthSrc;       /* width in longwords of the source tile */
+
+    int widthDst;      /* width in longwords of the dest pixmap */
+    int w;             /* width of current box */
+    unsigned long startmask;
+    unsigned long endmask;/* masks for reggedy bits at either end of line */
+    int nlMiddle;      /* number of longwords between sides of boxes */
+    
+    register int nl;   /* loop version of nlMiddle */
+    int srcy;          /* current tile y position */
+    int srcx;          /* current tile x position */
+    int        srcRemaining;   /* number of longwords remaining in source */
+    int xoffDst, xoffSrc;
+    int        srcStart;       /* number of longwords source offset at left of box */
+    int        leftShift, rightShift;
+
+    MROP_DECLARE_REG()
+
+    unsigned long          *pdstBase;  /* pointer to start of dest */
+    unsigned long          *pdstLine;  /* poitner to start of dest box */
+    unsigned long          *psrcBase;  /* pointer to start of source */
+    unsigned long          *psrcLine;  /* pointer to fetch point of source */
+    unsigned long          *psrcStart; /* pointer to start of source line */
+    register unsigned long  *pdst;
+    register unsigned long  *psrc;
+    register unsigned long  bits, bits1;
+    register int           nlTemp;
+
+    MROP_INITIALIZE (alu, planemask)
+
+    psrcBase = (unsigned long *)tile->devPrivate.ptr;
+    tileHeight = tile->drawable.height;
+    tileWidth = tile->drawable.width;
+#if PSZ == 24
+    widthSrc = tile->devKind / PGSZB;
+#else
+    widthSrc = tileWidth >> PWSH;
+#endif
+
+    cfbGetLongWidthAndPointer (pDrawable, widthDst, pdstBase)
+
+    while (n--)
+    {
+       w = *pwidth++;
+
+       /* set up source */
+       modulus (ppt->x - xrot, tileWidth, srcx);
+       modulus (ppt->y - yrot, tileHeight, srcy);
+#if PSZ == 24
+       xoffSrc = (4 - srcx) & 3;
+       srcStart = (srcx * 3) >> 2;
+#else
+       xoffSrc = srcx & PIM;
+       srcStart = (srcx >> PWSH);
+#endif
+       psrcStart = psrcBase + (srcy * widthSrc);
+       psrcLine = psrcStart + srcStart;
+
+       /* set up dest */
+#if PSZ == 24
+       xoffDst = (4 - ppt->x) & 3;
+       pdstLine = pdstBase + (ppt->y * widthDst) + ((ppt->x *3) >> 2);
+       /* set up masks */
+       if (w == 1  &&  (xoffDst == 0  ||  xoffDst == 1))
+#else
+       xoffDst = ppt->x & PIM;
+       pdstLine = pdstBase + (ppt->y * widthDst) + (ppt->x >> PWSH);
+       /* set up masks */
+       if (xoffDst + w < PPW)
+#endif
+       {
+           maskpartialbits(ppt->x, w, startmask);
+           endmask = 0;
+           nlMiddle = 0;
+       }
+       else
+       {
+           maskbits (ppt->x, w, startmask, endmask, nlMiddle)
+       }
+
+       if (xoffSrc == xoffDst)
+       {
+           psrc = psrcLine;
+           pdst = pdstLine;
+           srcRemaining = widthSrc - srcStart;
+           if (startmask)
+           {
+               *pdst = MROP_MASK (*psrc, *pdst, startmask);
+               pdst++;
+               IncSrcPtr
+           }
+           nlTemp = nlMiddle;
+           while (nlTemp)
+           {
+               nl = nlTemp;
+               if (nl > srcRemaining)
+                   nl = srcRemaining;
+
+               nlTemp -= nl;
+               srcRemaining -= nl;
+
+#if MROP == Mcopy
+#ifdef LARGE_INSTRUCTION_CACHE
+#ifdef FAST_CONSTANT_OFFSET_MODE
+
+               psrc += nl & (UNROLL-1);
+               pdst += nl & (UNROLL-1);
+
+#define BodyOdd(n) pdst[-n] = MROP_SOLID (psrc[-n], pdst[-n]);
+#define BodyEven(n) pdst[-n] = MROP_SOLID (psrc[-n], pdst[-n]);
+
+#define LoopReset \
+pdst += UNROLL; \
+psrc += UNROLL;
+
+#else
+
+#define BodyOdd(n)  *pdst = MROP_SOLID (*psrc, *pdst); pdst++; psrc++;
+#define BodyEven(n) BodyOdd(n)
+
+#define LoopReset   ;
+
+#endif
+               PackedLoop
+
+#undef BodyOdd
+#undef BodyEven
+#undef LoopReset
+
+#else
+               DuffL(nl, label1,
+                       *pdst = MROP_SOLID (*psrc, *pdst);
+                       pdst++; psrc++;)
+#endif
+#else
+               while (nl--) {
+                       *pdst = MROP_SOLID (*psrc, *pdst);
+                       pdst++; psrc++;
+               }
+#endif
+               if (!srcRemaining)
+               {
+                   srcRemaining = widthSrc;
+                   psrc = psrcStart;
+               }
+           }
+           if (endmask)
+           {
+               *pdst = MROP_MASK (*psrc, *pdst, endmask);
+           }
+       }
+       else
+       {
+           if (xoffSrc > xoffDst)
+           {
+               leftShift = (xoffSrc - xoffDst) << LEFTSHIFT_AMT;
+               rightShift = PGSZ - leftShift;
+           }
+           else
+           {
+               rightShift = (xoffDst - xoffSrc) << LEFTSHIFT_AMT;
+               leftShift = PGSZ - rightShift;
+           }
+           psrc = psrcLine;
+           pdst = pdstLine;
+           bits = 0;
+           srcRemaining = widthSrc - srcStart;
+           if (xoffSrc > xoffDst)
+           {
+               bits = *psrc;
+               IncSrcPtr
+           }
+           if (startmask)
+           {
+               bits1 = BitLeft(bits,leftShift);
+               bits = *psrc;
+               IncSrcPtr
+               bits1 |= BitRight(bits,rightShift);
+               *pdst = MROP_MASK(bits1, *pdst, startmask);
+               pdst++;
+           }
+           nlTemp = nlMiddle;
+           while (nlTemp)
+           {
+               nl = nlTemp;
+               if (nl > srcRemaining)
+                   nl = srcRemaining;
+
+               nlTemp -= nl;
+               srcRemaining -= nl;
+
+#if MROP == Mcopy
+#ifdef LARGE_INSTRUCTION_CACHE
+               bits1 = bits;
+
+#ifdef FAST_CONSTANT_OFFSET_MODE
+
+               psrc += nl & (UNROLL-1);
+               pdst += nl & (UNROLL-1);
+
+#define BodyOdd(n) \
+bits = psrc[-n]; \
+pdst[-n] = MROP_SOLID(BitLeft(bits1, leftShift) | BitRight(bits, rightShift), pdst[-n]);
+
+#define BodyEven(n) \
+bits1 = psrc[-n]; \
+pdst[-n] = MROP_SOLID(BitLeft(bits, leftShift) | BitRight(bits1, rightShift), pdst[-n]);
+
+#define LoopReset \
+pdst += UNROLL; \
+psrc += UNROLL;
+
+#else
+
+#define BodyOdd(n) \
+bits = *psrc++; \
+*pdst = MROP_SOLID(BitLeft(bits1, leftShift) | BitRight(bits, rightShift), *pdst); \
+pdst++;
+              
+#define BodyEven(n) \
+bits1 = *psrc++; \
+*pdst = MROP_SOLID(BitLeft(bits, leftShift) | BitRight(bits1, rightShift), *pdst); \
+pdst++;
+
+#define LoopReset   ;
+
+#endif /* !FAST_CONSTANT_OFFSET_MODE */
+
+               PackedLoop
+
+#undef BodyOdd
+#undef BodyEven
+#undef LoopReset
+
+#else
+               DuffL (nl,label2,
+                   bits1 = BitLeft(bits, leftShift);
+                   bits = *psrc++;
+                   *pdst = MROP_SOLID (bits1 | BitRight(bits, rightShift), *pdst);
+                   pdst++;
+               )
+#endif
+#else
+               while (nl--) {
+                   bits1 = BitLeft(bits,leftShift);
+                   bits = *psrc++;
+                   *pdst = MROP_SOLID(bits1|BitRight(bits,rightShift), *pdst);
+                   pdst++;
+               }
+#endif
+               if (!srcRemaining)
+               {
+                   srcRemaining = widthSrc;
+                   psrc = psrcStart;
+               }
+           }
+
+           if (endmask)
+           {
+               bits1 = BitLeft(bits, leftShift);
+               if (BitLeft(endmask, rightShift))
+               {
+                   bits = *psrc;
+                   bits1 |= BitRight(bits, rightShift);
+               }
+               *pdst = MROP_MASK (bits1, *pdst, endmask);
+           }
+       }
+       ppt++;
+    }
+}
diff --git a/Xserver/programs/Xserver/cfb/cfbwindow.c b/Xserver/programs/Xserver/cfb/cfbwindow.c
new file mode 100644 (file)
index 0000000..bc854a5
--- /dev/null
@@ -0,0 +1,335 @@
+/* $XConsortium: cfbwindow.c,v 5.22 94/04/17 20:29:07 dpw Exp $ */
+/***********************************************************
+
+Copyright (c) 1987  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+
+Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
+
+                        All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and its 
+documentation for any purpose and without fee is hereby granted, 
+provided that the above copyright notice appear in all copies and that
+both that copyright notice and this permission notice appear in 
+supporting documentation, and that the name of Digital not be
+used in advertising or publicity pertaining to distribution of the
+software without specific, written prior permission.  
+
+DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
+ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
+DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
+ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+SOFTWARE.
+
+******************************************************************/
+
+#include "X.h"
+#include "scrnintstr.h"
+#include "windowstr.h"
+#include "cfb.h"
+#include "mistruct.h"
+#include "regionstr.h"
+#include "cfbmskbits.h"
+
+extern WindowPtr *WindowTable;
+
+Bool
+cfbCreateWindow(pWin)
+    WindowPtr pWin;
+{
+    cfbPrivWin *pPrivWin;
+
+    pPrivWin = cfbGetWindowPrivate(pWin);
+    pPrivWin->pRotatedBorder = NullPixmap;
+    pPrivWin->pRotatedBackground = NullPixmap;
+    pPrivWin->fastBackground = FALSE;
+    pPrivWin->fastBorder = FALSE;
+    pPrivWin->oldRotate.x = 0;
+    pPrivWin->oldRotate.y = 0;
+
+#ifdef PIXMAP_PER_WINDOW
+    /* Setup pointer to Screen pixmap */
+    pWin->devPrivates[frameWindowPrivateIndex].ptr =
+       (pointer) cfbGetScreenPixmap(pWin->drawable.pScreen);
+#endif
+
+    return TRUE;
+}
+
+Bool
+cfbDestroyWindow(pWin)
+    WindowPtr pWin;
+{
+    cfbPrivWin *pPrivWin;
+
+    pPrivWin = cfbGetWindowPrivate(pWin);
+
+    if (pPrivWin->pRotatedBorder)
+       (*pWin->drawable.pScreen->DestroyPixmap)(pPrivWin->pRotatedBorder);
+    if (pPrivWin->pRotatedBackground)
+       (*pWin->drawable.pScreen->DestroyPixmap)(pPrivWin->pRotatedBackground);
+    return(TRUE);
+}
+
+/*ARGSUSED*/
+Bool
+cfbMapWindow(pWindow)
+    WindowPtr pWindow;
+{
+    return(TRUE);
+}
+
+/* (x, y) is the upper left corner of the window on the screen 
+   do we really need to pass this?  (is it a;ready in pWin->absCorner?)
+   we only do the rotation for pixmaps that are 32 bits wide (padded
+or otherwise.)
+   cfbChangeWindowAttributes() has already put a copy of the pixmap
+in pPrivWin->pRotated*
+*/
+/*ARGSUSED*/
+Bool
+cfbPositionWindow(pWin, x, y)
+    WindowPtr pWin;
+    int x, y;
+{
+    cfbPrivWin *pPrivWin;
+    int setxy = 0;
+
+    pPrivWin = cfbGetWindowPrivate(pWin);
+    if (pWin->backgroundState == BackgroundPixmap && pPrivWin->fastBackground)
+    {
+       cfbXRotatePixmap(pPrivWin->pRotatedBackground,
+                     pWin->drawable.x - pPrivWin->oldRotate.x);
+       cfbYRotatePixmap(pPrivWin->pRotatedBackground,
+                     pWin->drawable.y - pPrivWin->oldRotate.y);
+       setxy = 1;
+    }
+
+    if (!pWin->borderIsPixel &&        pPrivWin->fastBorder)
+    {
+       while (pWin->backgroundState == ParentRelative)
+           pWin = pWin->parent;
+       cfbXRotatePixmap(pPrivWin->pRotatedBorder,
+                     pWin->drawable.x - pPrivWin->oldRotate.x);
+       cfbYRotatePixmap(pPrivWin->pRotatedBorder,
+                     pWin->drawable.y - pPrivWin->oldRotate.y);
+       setxy = 1;
+    }
+    if (setxy)
+    {
+       pPrivWin->oldRotate.x = pWin->drawable.x;
+       pPrivWin->oldRotate.y = pWin->drawable.y;
+    }
+    return (TRUE);
+}
+
+/*ARGSUSED*/
+Bool
+cfbUnmapWindow(pWindow)
+    WindowPtr pWindow;
+{
+    return (TRUE);
+}
+
+/* UNCLEAN!
+   this code calls the bitblt helper code directly.
+
+   cfbCopyWindow copies only the parts of the destination that are
+visible in the source.
+*/
+
+
+void 
+cfbCopyWindow(pWin, ptOldOrg, prgnSrc)
+    WindowPtr pWin;
+    DDXPointRec ptOldOrg;
+    RegionPtr prgnSrc;
+{
+    DDXPointPtr pptSrc;
+    register DDXPointPtr ppt;
+    RegionRec rgnDst;
+    register BoxPtr pbox;
+    register int dx, dy;
+    register int i, nbox;
+    WindowPtr pwinRoot;
+
+    pwinRoot = WindowTable[pWin->drawable.pScreen->myNum];
+
+    REGION_INIT(pWin->drawable.pScreen, &rgnDst, NullBox, 0);
+
+    dx = ptOldOrg.x - pWin->drawable.x;
+    dy = ptOldOrg.y - pWin->drawable.y;
+    REGION_TRANSLATE(pWin->drawable.pScreen, prgnSrc, -dx, -dy);
+    REGION_INTERSECT(pWin->drawable.pScreen, &rgnDst, &pWin->borderClip, prgnSrc);
+
+    pbox = REGION_RECTS(&rgnDst);
+    nbox = REGION_NUM_RECTS(&rgnDst);
+    if(!nbox || !(pptSrc = (DDXPointPtr )ALLOCATE_LOCAL(nbox * sizeof(DDXPointRec))))
+    {
+       REGION_UNINIT(pWin->drawable.pScreen, &rgnDst);
+       return;
+    }
+    ppt = pptSrc;
+
+    for (i = nbox; --i >= 0; ppt++, pbox++)
+    {
+       ppt->x = pbox->x1 + dx;
+       ppt->y = pbox->y1 + dy;
+    }
+
+    cfbDoBitbltCopy((DrawablePtr)pwinRoot, (DrawablePtr)pwinRoot,
+               GXcopy, &rgnDst, pptSrc, ~0L);
+    DEALLOCATE_LOCAL(pptSrc);
+    REGION_UNINIT(pWin->drawable.pScreen, &rgnDst);
+}
+
+
+
+/* swap in correct PaintWindow* routine.  If we can use a fast output
+routine (i.e. the pixmap is paddable to 32 bits), also pre-rotate a copy
+of it in devPrivates[cfbWindowPrivateIndex].ptr.
+*/
+Bool
+cfbChangeWindowAttributes(pWin, mask)
+    WindowPtr pWin;
+    unsigned long mask;
+{
+    register unsigned long index;
+    register cfbPrivWin *pPrivWin;
+    int width;
+    WindowPtr  pBgWin;
+
+    pPrivWin = cfbGetWindowPrivate(pWin);
+
+    /*
+     * When background state changes from ParentRelative and
+     * we had previously rotated the fast border pixmap to match
+     * the parent relative origin, rerotate to match window
+     */
+    if (mask & (CWBackPixmap | CWBackPixel) &&
+       pWin->backgroundState != ParentRelative &&
+       pPrivWin->fastBorder &&
+       (pPrivWin->oldRotate.x != pWin->drawable.x ||
+        pPrivWin->oldRotate.y != pWin->drawable.y))
+    {
+       cfbXRotatePixmap(pPrivWin->pRotatedBorder,
+                     pWin->drawable.x - pPrivWin->oldRotate.x);
+       cfbYRotatePixmap(pPrivWin->pRotatedBorder,
+                     pWin->drawable.y - pPrivWin->oldRotate.y);
+       pPrivWin->oldRotate.x = pWin->drawable.x;
+       pPrivWin->oldRotate.y = pWin->drawable.y;
+    }
+    while(mask)
+    {
+       index = lowbit (mask);
+       mask &= ~index;
+       switch(index)
+       {
+       case CWBackPixmap:
+           if (pWin->backgroundState == None)
+           {
+               pPrivWin->fastBackground = FALSE;
+           }
+           else if (pWin->backgroundState == ParentRelative)
+           {
+               pPrivWin->fastBackground = FALSE;
+               /* Rotate border to match parent origin */
+               if (pPrivWin->pRotatedBorder) {
+                   for (pBgWin = pWin->parent;
+                        pBgWin->backgroundState == ParentRelative;
+                        pBgWin = pBgWin->parent);
+                   cfbXRotatePixmap(pPrivWin->pRotatedBorder,
+                                 pBgWin->drawable.x - pPrivWin->oldRotate.x);
+                   cfbYRotatePixmap(pPrivWin->pRotatedBorder,
+                                 pBgWin->drawable.y - pPrivWin->oldRotate.y);
+                   pPrivWin->oldRotate.x = pBgWin->drawable.x;
+                   pPrivWin->oldRotate.y = pBgWin->drawable.y;
+               }
+           }
+           else if (((width = (pWin->background.pixmap->drawable.width * PSZ))
+                     <= PGSZ) && !(width & (width - 1)))
+           {
+               cfbCopyRotatePixmap(pWin->background.pixmap,
+                                   &pPrivWin->pRotatedBackground,
+                                   pWin->drawable.x,
+                                   pWin->drawable.y);
+               if (pPrivWin->pRotatedBackground)
+               {
+                   pPrivWin->fastBackground = TRUE;
+                   pPrivWin->oldRotate.x = pWin->drawable.x;
+                   pPrivWin->oldRotate.y = pWin->drawable.y;
+               }
+               else
+               {
+                   pPrivWin->fastBackground = FALSE;
+               }
+           }
+           else
+           {
+               pPrivWin->fastBackground = FALSE;
+           }
+           break;
+
+       case CWBackPixel:
+           pPrivWin->fastBackground = FALSE;
+           break;
+
+       case CWBorderPixmap:
+           if (((width = (pWin->border.pixmap->drawable.width * PSZ)) <= PGSZ) &&
+               !(width & (width - 1)))
+           {
+               for (pBgWin = pWin;
+                    pBgWin->backgroundState == ParentRelative;
+                    pBgWin = pBgWin->parent);
+               cfbCopyRotatePixmap(pWin->border.pixmap,
+                                   &pPrivWin->pRotatedBorder,
+                                   pBgWin->drawable.x,
+                                   pBgWin->drawable.y);
+               if (pPrivWin->pRotatedBorder)
+               {
+                   pPrivWin->fastBorder = TRUE;
+                   pPrivWin->oldRotate.x = pBgWin->drawable.x;
+                   pPrivWin->oldRotate.y = pBgWin->drawable.y;
+               }
+               else
+               {
+                   pPrivWin->fastBorder = FALSE;
+               }
+           }
+           else
+           {
+               pPrivWin->fastBorder = FALSE;
+           }
+           break;
+        case CWBorderPixel:
+           pPrivWin->fastBorder = FALSE;
+           break;
+       }
+    }
+    return (TRUE);
+}
+
diff --git a/Xserver/programs/Xserver/cfb/cfbzerarc.c b/Xserver/programs/Xserver/cfb/cfbzerarc.c
new file mode 100644 (file)
index 0000000..fab643b
--- /dev/null
@@ -0,0 +1,318 @@
+/************************************************************
+
+Copyright (c) 1989  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+********************************************************/
+
+/* $XConsortium: cfbzerarc.c /main/24 1995/12/06 16:58:51 dpw $ */
+/* $XFree86: xc/programs/Xserver/cfb/cfbzerarc.c,v 3.0 1996/06/29 09:05:57 dawes Exp $ */
+
+/* Derived from:
+ * "Algorithm for drawing ellipses or hyperbolae with a digital plotter"
+ * by M. L. V. Pitteway
+ * The Computer Journal, November 1967, Volume 10, Number 3, pp. 282-289
+ */
+
+#include "X.h"
+#include "Xprotostr.h"
+#include "miscstruct.h"
+#include "gcstruct.h"
+#include "pixmapstr.h"
+#include "scrnintstr.h"
+#include "cfb.h"
+#include "cfbmskbits.h"
+#include "mizerarc.h"
+#include "cfbrrop.h"
+#include "mi.h"
+
+#ifdef PIXEL_ADDR
+
+static void
+RROP_NAME(cfbZeroArcSS8) (pDraw, pGC, arc)
+    DrawablePtr pDraw;
+    GCPtr pGC;
+    xArc *arc;
+{
+    miZeroArcRec info;
+    Bool do360;
+    register int x;
+    PixelType *addrp;
+    register PixelType *yorgp, *yorgop;
+#if PSZ == 24
+    int xorg, xorg3, xorgo, xorgo3;
+    register int xtmp;
+#endif
+    RROP_DECLARE
+    register int yoffset;
+    int npwidth, dyoffset;
+    register int y, a, b, d, mask;
+    register int k1, k3, dx, dy;
+
+    cfbGetPixelWidthAndPointer(pDraw,npwidth, addrp)
+
+    RROP_FETCH_GC (pGC);
+    do360 = miZeroArcSetup(arc, &info, TRUE);
+    yorgp = addrp + ((info.yorg + pDraw->y) * npwidth);
+    yorgop = addrp + ((info.yorgo + pDraw->y) * npwidth);
+    info.xorg += pDraw->x;
+    info.xorgo += pDraw->x;
+#if PSZ == 24
+    xorg = info.xorg;
+    xorg3 = xorg * 3;
+    info.xorg = (info.xorg * 3) >> 2;
+    xorgo = info.xorgo;
+    xorgo3 = xorgo * 3; 
+    info.xorgo = (info.xorgo * 3) >> 2;
+#endif
+    MIARCSETUP();
+    yoffset = y ? npwidth : 0;
+    dyoffset = 0;
+    mask = info.initialMask;
+    if (!(arc->width & 1))
+    {
+#if PSZ == 24
+       if (mask & 2)
+           RROP_SOLID24((yorgp + info.xorgo), xorgo);
+       if (mask & 8)
+           RROP_SOLID24((yorgop + info.xorgo), xorgo);
+#else
+       if (mask & 2)
+           RROP_SOLID((yorgp + info.xorgo));
+       if (mask & 8)
+           RROP_SOLID((yorgop + info.xorgo));
+#endif /* PSZ == 24 */
+    }
+    if (!info.end.x || !info.end.y)
+    {
+       mask = info.end.mask;
+       info.end = info.altend;
+    }
+    if (do360 && (arc->width == arc->height) && !(arc->width & 1))
+    {
+       register int xoffset = npwidth;
+#if PSZ == 24
+       PixelType *yorghb = yorgp + (info.h * npwidth);
+       register int tmp1, tmp2, tmp1_3, tmp2_3;
+
+       tmp1 = xorg + info.h;
+       tmp1_3 = tmp1 * 3;
+       tmp2 = xorg - info.h;
+       tmp2_3 = tmp2 * 3;
+       while (1)
+       {
+           xtmp = (xorg3 + x * 3) >> 2;
+           RROP_SOLID24(yorgp + yoffset + xtmp, xorg + x);
+           RROP_SOLID24(yorgop - yoffset + xtmp, xorg + x);
+           xtmp = (xorg3 - x * 3) >> 2;
+           RROP_SOLID24(yorgp + yoffset + xtmp, xorg - x);
+           RROP_SOLID24(yorgop - yoffset + xtmp, xorg - x);
+           if (a < 0)
+               break;
+           xtmp = (tmp1_3 - y * 3) >> 2;
+           RROP_SOLID24(yorghb - xoffset + xtmp, tmp1 - y);
+           RROP_SOLID24(yorghb + xoffset + xtmp, tmp1 - y);
+           xtmp = (tmp2_3 + y * 3) >> 2;
+           RROP_SOLID24(yorghb - xoffset + xtmp, tmp2 + y);
+           RROP_SOLID24(yorghb + xoffset + xtmp, tmp2 + y);
+           xoffset += npwidth;
+           MIARCCIRCLESTEP(yoffset += npwidth;);
+       }
+#else
+       PixelType *yorghb = yorgp + (info.h * npwidth) + info.xorg;
+       PixelType *yorgohb = yorghb - info.h;
+
+       yorgp += info.xorg;
+       yorgop += info.xorg;
+       yorghb += info.h;
+       while (1)
+       {
+           RROP_SOLID(yorgp + yoffset + x);
+           RROP_SOLID(yorgp + yoffset - x);
+           RROP_SOLID(yorgop - yoffset - x);
+           RROP_SOLID(yorgop - yoffset + x);
+           if (a < 0)
+               break;
+           RROP_SOLID(yorghb - xoffset - y);
+           RROP_SOLID(yorgohb - xoffset + y);
+           RROP_SOLID(yorgohb + xoffset + y);
+           RROP_SOLID(yorghb + xoffset - y);
+           xoffset += npwidth;
+           MIARCCIRCLESTEP(yoffset += npwidth;);
+       }
+       yorgp -= info.xorg;
+       yorgop -= info.xorg;
+#endif /* PSZ == 24 */
+       x = info.w;
+       yoffset = info.h * npwidth;
+    }
+    else if (do360)
+    {
+       while (y < info.h || x < info.w)
+       {
+           MIARCOCTANTSHIFT(dyoffset = npwidth;);
+#if PSZ == 24
+           xtmp = (xorg3 + x * 3) >> 2;
+           RROP_SOLID24(yorgp + yoffset + xtmp, xorg + x);
+           RROP_SOLID24(yorgop - yoffset + xtmp, xorg + x);
+           xtmp = (xorgo3 - x * 3) >> 2;
+           RROP_SOLID24(yorgp + yoffset + xtmp, xorgo - x);
+           RROP_SOLID24(yorgop - yoffset + xtmp, xorgo - x);
+#else
+           RROP_SOLID(yorgp + yoffset + info.xorg + x);
+           RROP_SOLID(yorgp + yoffset + info.xorgo - x);
+           RROP_SOLID(yorgop - yoffset + info.xorgo - x);
+           RROP_SOLID(yorgop - yoffset + info.xorg + x);
+#endif
+           MIARCSTEP(yoffset += dyoffset;, yoffset += npwidth;);
+       }
+    }
+    else
+    {
+       while (y < info.h || x < info.w)
+       {
+           MIARCOCTANTSHIFT(dyoffset = npwidth;);
+           if ((x == info.start.x) || (y == info.start.y))
+           {
+               mask = info.start.mask;
+               info.start = info.altstart;
+           }
+#if PSZ == 24
+           if (mask & 1){
+             xtmp = (xorg3 + x * 3) >> 2;
+             RROP_SOLID24(yorgp + yoffset + xtmp, xorg + x);
+           }
+           if (mask & 2){
+             xtmp = (xorgo3 - x * 3) >> 2;
+             RROP_SOLID24(yorgp + yoffset + xtmp, xorgo - x);
+           }
+           if (mask & 4){
+             xtmp = (xorgo3 - x * 3) >> 2;
+             RROP_SOLID24(yorgop - yoffset + xtmp, xorgo - x);
+           }
+           if (mask & 8){
+             xtmp = (xorg3 + x * 3) >> 2;
+             RROP_SOLID24(yorgop - yoffset + xtmp, xorg + x);
+           }
+#else
+           if (mask & 1)
+               RROP_SOLID(yorgp + yoffset + info.xorg + x);
+           if (mask & 2)
+               RROP_SOLID(yorgp + yoffset + info.xorgo - x);
+           if (mask & 4)
+               RROP_SOLID(yorgop - yoffset + info.xorgo - x);
+           if (mask & 8)
+               RROP_SOLID(yorgop - yoffset + info.xorg + x);
+#endif /* PSZ == 24 */
+           if ((x == info.end.x) || (y == info.end.y))
+           {
+               mask = info.end.mask;
+               info.end = info.altend;
+           }
+           MIARCSTEP(yoffset += dyoffset;, yoffset += npwidth;);
+       }
+    }
+    if ((x == info.start.x) || (y == info.start.y))
+       mask = info.start.mask;
+#if PSZ == 24
+    if (mask & 1){
+      xtmp = (xorg3 + x * 3) >> 2;
+      RROP_SOLID24(yorgp + yoffset + xtmp, xorg + x);
+    }
+    if (mask & 4){
+      xtmp = (xorgo3 - x * 3) >> 2;
+      RROP_SOLID24(yorgop - yoffset + xtmp, xorgo - x);
+    }
+#else
+    if (mask & 1)
+       RROP_SOLID(yorgp + yoffset + info.xorg + x);
+    if (mask & 4)
+       RROP_SOLID(yorgop - yoffset + info.xorgo - x);
+#endif /* PSZ == 24 */
+    if (arc->height & 1)
+    {
+#if PSZ == 24
+       if (mask & 2){
+         xtmp = (xorgo3 - x * 3) >> 2;
+         RROP_SOLID24(yorgp + yoffset + xtmp, xorgo - x);
+       }
+       if (mask & 8){
+         xtmp = (xorg3 + x * 3) >> 2;
+         RROP_SOLID24(yorgop - yoffset + xtmp, xorg + x);
+       }
+#else
+       if (mask & 2)
+           RROP_SOLID(yorgp + yoffset + info.xorgo - x);
+       if (mask & 8)
+           RROP_SOLID(yorgop - yoffset + info.xorg + x);
+#endif /* PSZ == 24 */
+    }
+}
+
+void
+RROP_NAME (cfbZeroPolyArcSS8) (pDraw, pGC, narcs, parcs)
+    register DrawablePtr       pDraw;
+    GCPtr      pGC;
+    int                narcs;
+    xArc       *parcs;
+{
+    register xArc *arc;
+    register int i;
+    BoxRec box;
+    int x2, y2;
+    RegionPtr cclip;
+
+    cclip = cfbGetCompositeClip(pGC);
+    for (arc = parcs, i = narcs; --i >= 0; arc++)
+    {
+       if (miCanZeroArc(arc))
+       {
+           box.x1 = arc->x + pDraw->x;
+           box.y1 = arc->y + pDraw->y;
+           /*
+            * Because box.x2 and box.y2 get truncated to 16 bits, and the
+            * RECT_IN_REGION test treats the resulting number as a signed
+            * integer, the RECT_IN_REGION test alone can go the wrong way.
+            * This can result in a server crash because the rendering
+            * routines in this file deal directly with cpu addresses
+            * of pixels to be stored, and do not clip or otherwise check
+            * that all such addresses are within their respective pixmaps.
+            * So we only allow the RECT_IN_REGION test to be used for
+            * values that can be expressed correctly in a signed short.
+            */
+           x2 = box.x1 + (int)arc->width + 1;
+           box.x2 = x2;
+           y2 = box.y1 + (int)arc->height + 1;
+           box.y2 = y2;
+           if ( (x2 <= MAXSHORT) && (y2 <= MAXSHORT) &&
+                   (RECT_IN_REGION(pDraw->pScreen, cclip, &box) == rgnIN) )
+               RROP_NAME (cfbZeroArcSS8) (pDraw, pGC, arc);
+           else
+               miZeroPolyArc(pDraw, pGC, 1, arc);
+       }
+       else
+           miPolyArc(pDraw, pGC, 1, arc);
+    }
+}
+
+#endif
diff --git a/Xserver/programs/Xserver/cfb/stip68kgnu.h b/Xserver/programs/Xserver/cfb/stip68kgnu.h
new file mode 100644 (file)
index 0000000..74345d0
--- /dev/null
@@ -0,0 +1,124 @@
+/*
+ * $XConsortium: stip68kgnu.h,v 1.3 94/04/17 20:29:08 dpw Exp $
+ * $XFree86: xc/programs/Xserver/cfb/stip68kgnu.h,v 3.0.4.1 1997/05/11 05:04:17 dawes Exp $
+ *
+Copyright (c) 1990  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+ *
+ * Author:  Keith Packard, MIT X Consortium
+ */
+
+/*
+ * Stipple stack macro for 68k GCC
+ */
+
+#define STIPPLE(addr,stipple,value,width,count,shift) \
+    __asm volatile ( \
+       "lea    5f,%/a1\n\
+       moveq   #28,%/d2\n\
+       addl    %2,%/d2\n\
+       moveq   #28,%/d3\n\
+       subql   #4,%2\n\
+       negl    %2\n\
+1:\n\
+       movel   %0,%/a0\n\
+       addl    %6,%0\n\
+       movel   %3@+,%/d1\n\
+       jeq     3f\n\
+       movel   %/d1,%/d0\n\
+       lsrl    %/d2,%/d0\n\
+       lsll    #5,%/d0\n\
+       lsll    %2,%/d1\n\
+       jmp     %/a1@(%/d0:l)\n\
+2:\n\
+       addl    #4,%/a0\n\
+       movel   %/d1,%/d0\n\
+       lsrl    %/d3,%/d0\n\
+       lsll    #5,%/d0\n\
+       lsll    #4,%/d1\n\
+       jmp     %/a1@(%/d0:l)\n\
+5:\n\
+       jne 2b ; dbra %1,1b ; jra 4f\n\
+       . = 5b + 0x20\n\
+       moveb   %5,%/a0@(3)\n\
+       andl    %/d1,%/d1 ; jne 2b ; dbra %1,1b ; jra 4f\n\
+       . = 5b + 0x40\n\
+       moveb   %5,%/a0@(2)\n\
+       andl    %/d1,%/d1 ; jne 2b ; dbra %1,1b ; jra 4f\n\
+       . = 5b + 0x60\n\
+       movew   %5,%/a0@(2)\n\
+       andl    %/d1,%/d1 ; jne 2b ; dbra %1,1b ; jra 4f\n\
+       . = 5b + 0x80\n\
+       moveb   %5,%/a0@(1)\n\
+       andl    %/d1,%/d1 ; jne 2b ; dbra %1,1b ; jra 4f ;\n\
+       . = 5b + 0xa0\n\
+       moveb   %5,%/a0@(3) ; moveb     %5,%/a0@(1)\n\
+       andl    %/d1,%/d1 ; jne 2b ; dbra %1,1b ; jra 4f ;\n\
+       . = 5b + 0xc0\n\
+       movew   %5,%/a0@(1)\n\
+       andl    %/d1,%/d1 ; jne 2b ; dbra %1,1b ; jra 4f ;\n\
+       . = 5b + 0xe0\n\
+       movew   %5,%/a0@(2) ; moveb     %5,%/a0@(1)\n\
+       andl    %/d1,%/d1 ; jne 2b ; dbra %1,1b ; jra 4f ;\n\
+       . = 5b + 0x100\n\
+       moveb   %5,%/a0@\n\
+       andl    %/d1,%/d1 ; jne 2b ; dbra %1,1b ; jra 4f ;\n\
+       . = 5b + 0x120\n\
+       moveb   %5,%/a0@(3) ; moveb     %5,%/a0@\n\
+       andl    %/d1,%/d1 ; jne 2b ; dbra %1,1b ; jra 4f ;\n\
+       . = 5b + 0x140\n\
+       moveb   %5,%/a0@(2) ; moveb     %5,%/a0@\n\
+       andl    %/d1,%/d1 ; jne 2b ; dbra %1,1b ; jra 4f ;\n\
+       . = 5b + 0x160\n\
+       movew   %5,%/a0@(2) ; moveb     %5,%/a0@\n\
+       andl    %/d1,%/d1 ; jne 2b ; dbra %1,1b ; jra 4f ;\n\
+       . = 5b + 0x180\n\
+       movew   %5,%/a0@\n\
+       andl    %/d1,%/d1 ; jne 2b ; dbra %1,1b ; jra 4f ;\n\
+       . = 5b + 0x1a0\n\
+       moveb   %5,%/a0@(3) ; movew     %5,%/a0@\n\
+       andl    %/d1,%/d1 ; jne 2b ; dbra %1,1b ; jra 4f ;\n\
+       . = 5b + 0x1c0\n\
+       moveb   %5,%/a0@(2) ; movew     %5,%/a0@\n\
+       andl    %/d1,%/d1 ; jne 2b ; dbra %1,1b ; jra 4f ;\n\
+       . = 5b + 0x1e0\n\
+       movel   %5,%/a0@\n\
+       andl    %/d1,%/d1 ; jne 2b ; \n\
+3:     dbra %1,1b ; \n\
+4:\n"\
+           : "=a" (addr),          /* %0 */ \
+             "=d" (count),         /* %1 */ \
+             "=d" (shift),         /* %2 */ \
+             "=a" (stipple)        /* %3 */ \
+           : "0" (addr),           /* %4 */ \
+             "d" (value),          /* %5 */ \
+             "a" (width),          /* %6 */ \
+             "1" (count-1),        /* %7 */ \
+             "2" (shift),          /* %8 */ \
+             "3" (stipple)         /* %9 */ \
+           : /* ctemp */           "d0", \
+             /* c */               "d1", \
+             /* lshift */          "d2", \
+             /* rshift */          "d3", \
+             /* atemp */           "a0", \
+             /* case */            "a1")
diff --git a/Xserver/programs/Xserver/cfb/stipmips.s b/Xserver/programs/Xserver/cfb/stipmips.s
new file mode 100644 (file)
index 0000000..e67e8c3
--- /dev/null
@@ -0,0 +1,282 @@
+/*
+ * $XConsortium: stipmips.s,v 1.10 94/04/17 20:29:08 keith Exp $
+ *
+Copyright (c) 1990  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+ *
+ * Author:  Keith Packard, MIT X Consortium
+ */
+
+/*
+ * MIPS assembly code for optimized text rendering.
+ *
+ * Other stippling could be done in assembly, but the payoff is
+ * not nearly as large.  Mostly because large areas are heavily
+ * optimized already.
+ */
+
+#ifdef MIPSEL
+# define BitsR         sll
+# define BitsL         srl
+# define BO(o)         o
+# define HO(o)         o
+# define WO(o)         o
+# define FourBits(dest,bits)   and     dest, bits, 0xf
+#else
+# define BitsR srl
+# define BitsL sll
+# define BO(o)         3-o
+# define HO(o)         2-o
+# define WO(o)         o
+# define FourBits(dest,bits)   srl     dest, bits, 28
+#endif
+
+/* reordering instructions would be fatal here */
+       .set    noreorder
+
+       
+/*
+ * cfbStippleStack(addr, stipple, value, stride, Count, Shift)
+ *               4       5       6      7     16(sp) 20(sp)
+ *
+ *  Apply successive 32-bit stipples starting at addr, addr+stride, ...
+ *
+ *  Used for text rendering, but only when no data could be lost
+ *  when the stipple is shifted left by Shift bits
+ */
+/* arguments */
+#define addr   $4
+#define stipple        $5
+#define value  $6
+#define stride $7
+#define Count  16($sp)
+#define Shift  20($sp)
+
+/* local variables */
+#define count  $14
+#define shift  $13
+#define atemp  $12
+#define bits   $11
+#define lshift $9
+#define sbase  $8
+#define stemp  $2
+
+#define CASE_SIZE      5       /* case blocks are 2^5 bytes each */
+#define CASE_MASK      0x1e0   /* first case mask */
+
+#define ForEachLine    $200
+#define NextLine       $201
+#define NextLine1      $202
+#define CaseBegin      $203
+#define ForEachBits    $204
+#define ForEachBits1   $205
+#define NextBits       $206
+
+#ifdef TETEXT
+#define        cfbStippleStack cfbStippleStackTE
+#endif
+
+       .globl  cfbStippleStack
+       .ent    cfbStippleStack 2
+cfbStippleStack:
+       .frame  $sp, 0, $31
+       lw      count, Count                    /* fetch stack params */
+       la      sbase,CaseBegin                 /* load up switch table */
+       lw      shift, Shift
+       li      lshift, 4                       /* compute offset within */
+       subu    lshift, lshift, shift           /*  stipple of remaining bits */
+#ifdef MIPSEL
+       addu    shift, shift, CASE_SIZE         /* first shift for LSB */
+#else
+       addu    shift, shift, 28-CASE_SIZE      /* first shift for MSB */
+#endif
+       /* do ... while (--count > 0); */
+ForEachLine:
+       lw      bits, 0(stipple)                /* get stipple bits */
+       move    atemp, addr                     /* set up for this line */
+#ifdef TETEXT
+       /* Terminal emulator fonts are expanded and have many 0 rows */
+       beqz    bits, NextLine                  /* skip out early on 0 */
+#endif
+       addu    addr, addr, stride              /* step for the loop */
+       BitsR   stemp, bits, shift              /* get first bits */
+       and     stemp, stemp, CASE_MASK         /* compute first branch */
+       addu    stemp, stemp, sbase             /*  ... */
+       j       stemp                           /*  ... */
+       BitsL   bits, bits, lshift              /* set remaining bits */
+
+ForEachBits:
+       addu    atemp, atemp, 4
+ForEachBits1:
+       FourBits(stemp, bits)                   /* compute jump for */
+       sll     stemp, stemp, CASE_SIZE         /*  next four bits */
+       addu    stemp, stemp, sbase             /*  ... */
+       j       stemp                           /*  ... */
+       BitsL   bits, bits, 4                   /* step for remaining bits */
+CaseBegin:
+       bnez    bits, ForEachBits1              /* 0 */
+       addu    atemp, atemp, 4
+NextLine:
+       addu    count, count, -1
+       bnez    count, ForEachLine
+       addu    stipple, stipple, 4
+       j       $31
+       nop
+       nop
+
+       bnez    bits, ForEachBits               /* 1 */
+       sb      value, BO(0)(atemp)
+       addu    count, count, -1
+       bnez    count, ForEachLine
+       addu    stipple, stipple, 4
+       j       $31
+       nop
+       nop
+                                       
+       bnez    bits, ForEachBits               /* 2 */
+       sb      value, BO(1)(atemp)
+       addu    count, count, -1
+       bnez    count, ForEachLine
+       addu    stipple, stipple, 4
+       j       $31
+       nop
+       nop
+                                       
+       bnez    bits, ForEachBits               /* 3 */
+       sh      value, HO(0)(atemp)
+       addu    count, count, -1
+       bnez    count, ForEachLine
+       addu    stipple, stipple, 4
+       j       $31
+       nop
+       nop
+                                       
+       bnez    bits, ForEachBits               /* 4 */
+       sb      value, BO(2)(atemp)
+       addu    count, count, -1
+       bnez    count, ForEachLine
+       addu    stipple, stipple, 4
+       j       $31
+       nop
+       nop
+                                       
+       sb      value, BO(0)(atemp)             /* 5 */
+       bnez    bits, ForEachBits
+       sb      value, BO(2)(atemp)
+       addu    count, count, -1
+       bnez    count, ForEachLine
+       addu    stipple, stipple, 4
+       j       $31
+       nop
+                                       
+       sb      value, BO(1)(atemp)             /* 6 */
+       bnez    bits, ForEachBits
+       sb      value, BO(2)(atemp)
+       addu    count, count, -1
+       bnez    count, ForEachLine
+       addu    stipple, stipple, 4
+       j       $31
+       nop
+                                       
+       bnez    bits, ForEachBits               /* 7 */
+       swl     value, BO(2)(atemp)             /* untested on MSB */
+       addu    count, count, -1
+       bnez    count, ForEachLine
+       addu    stipple, stipple, 4
+       j       $31
+       nop
+       nop
+                                       
+       bnez    bits, ForEachBits               /* 8 */
+       sb      value, BO(3)(atemp)
+       addu    count, count, -1
+       bnez    count, ForEachLine
+       addu    stipple, stipple, 4
+       j       $31
+       nop
+       nop
+                                       
+       sb      value, BO(0)(atemp)             /* 9 */
+       bnez    bits, ForEachBits
+       sb      value, BO(3)(atemp)
+       addu    count, count, -1
+       bnez    count, ForEachLine
+       addu    stipple, stipple, 4
+       j       $31
+       nop
+                                       
+       sb      value, BO(1)(atemp)             /* a */
+       bnez    bits, ForEachBits
+       sb      value, BO(3)(atemp)
+       addu    count, count, -1
+       bnez    count, ForEachLine
+       addu    stipple, stipple, 4
+       j       $31
+       nop
+
+       sh      value, HO(0)(atemp)             /* b */
+       bnez    bits, ForEachBits
+       sb      value, BO(3)(atemp)
+       addu    count, count, -1
+       bnez    count, ForEachLine
+       addu    stipple, stipple, 4
+       j       $31
+       nop
+                                       
+       bnez    bits, ForEachBits               /* c */
+       sh      value, HO(2)(atemp)
+       addu    count, count, -1
+       bnez    count, ForEachLine
+       addu    stipple, stipple, 4
+       j       $31
+       nop
+       nop
+                                       
+       sb      value, BO(0)(atemp)             /* d */
+       bnez    bits, ForEachBits
+       sh      value, HO(2)(atemp)
+       addu    count, count, -1
+       bnez    count, ForEachLine
+       addu    stipple, stipple, 4
+       j       $31
+       nop
+
+       bnez    bits, ForEachBits               /* e */
+       swr     value, BO(1)(atemp)             /* untested on MSB */
+       addu    count, count, -1
+       bnez    count, ForEachLine
+       addu    stipple, stipple, 4
+       j       $31
+       nop
+       nop
+                                       
+       bnez    bits, ForEachBits               /* f */
+       sw      value, WO(0)(atemp)
+       addu    count, count, -1
+       bnez    count, ForEachLine
+       addu    stipple, stipple, 4
+       j       $31
+       nop
+       nop
+                                       
+       .end    cfbStippleStack
diff --git a/Xserver/programs/Xserver/cfb/stipple68k.s b/Xserver/programs/Xserver/cfb/stipple68k.s
new file mode 100644 (file)
index 0000000..d2e2eea
--- /dev/null
@@ -0,0 +1,232 @@
+/*
+ * $XConsortium: stipple68k.s,v 1.3 94/04/17 20:29:09 keith Exp $
+ * $XFree86: xc/programs/Xserver/cfb/stipple68k.s,v 3.0 1996/08/13 11:27:37 dawes Exp $
+ *
+Copyright (c) 1990  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+ *
+ * Author:  Keith Packard, MIT X Consortium
+ */
+
+/*
+ * Stipple code for 68k processors
+ */
+
+#ifdef __ELF__
+#ifdef TETEXT
+#define _cfbStippleStack cfbStippleStackTE
+#else
+#define _cfbStippleStack cfbStippleStack
+#endif
+#else
+#ifdef TETEXT
+#define _cfbStippleStack _cfbStippleStackTE
+#endif
+#endif
+
+
+#define atemp  a0
+#define addr   a1
+#define stipple        a2
+#define stride a3
+#define case   a4
+
+#define ctemp  d0
+#define value  d1
+#define count  d2
+#define shift  d3
+#define c      d4
+#define lshift d5
+#define rshift d6
+
+#define PushMask       #0x3e38
+#define PopMask                #0x1c7c
+#define NumReg 8
+#define arg0   36
+#define arg1   40
+#define arg2   44
+#define arg3   48
+#define arg4   52
+#define arg5   56
+#define arg6   60
+
+#ifdef __ELF__
+#define ForEachLine    .L2
+#define ForEachBits    .L5
+#define a0 %A0
+#define a1 %A1
+#define a2 %A2
+#define a3 %A3
+#define a4 %A4
+#define a5 %A5
+#define a6 %A6
+#define sp %SP
+#define d0 %D0
+#define d1 %D1
+#define d2 %D2
+#define d3 %D3
+#define d4 %D4
+#define d5 %D5
+#define d6 %D6
+#define d7 %D7
+#else
+#define ForEachLine    L2
+#define ForEachBits    L5
+#endif
+#define CASE_SIZE      5
+
+.text
+       .even
+       .globl _cfbStippleStack
+_cfbStippleStack:
+       moveml  PushMask,sp@-
+       movel   sp@(arg0),addr
+       movel   sp@(arg1),stipple
+       movel   sp@(arg2),value
+       movel   sp@(arg3),stride
+       movew   sp@(arg4+2),count
+       movel   sp@(arg5),shift
+       subqw   #1,count                /* predecrement count */
+       lea     CaseBegin,case
+       movew   #28,lshift
+       addl    shift,lshift
+       movew   #28,rshift
+       subql   #4,shift
+       negl    shift
+ForEachLine:
+       movel   addr,atemp
+       addl    stride,addr
+       movel   stipple@+,c
+#ifdef TETEXT
+       jeq     NextLine
+#endif
+       /* Get first few bits */
+       movel   c,ctemp
+       lsrl    lshift,ctemp
+       lsll    #CASE_SIZE,ctemp
+       lsll    shift,c                 /* set up for next bits */
+       jmp     case@(ctemp:l)
+
+ForEachBits:
+       addl    #4,atemp
+       movel   c,ctemp
+       lsrl    rshift,ctemp            /* better than lsrl, andi */
+       lsll    #CASE_SIZE,ctemp
+       lsll    #4,c                    /* set up for next bits */
+       jmp     case@(ctemp:l)
+
+#define Break                          \
+       andl    c,c                     ; \
+       jne     ForEachBits             ; \
+       dbra    count,ForEachLine       ; \
+       moveml  sp@+,PopMask            ; \
+       rts                             ;
+
+CaseBegin:
+       jne     ForEachBits             /* 0 */
+NextLine:
+       dbra    count,ForEachLine
+       moveml  sp@+,PopMask
+       rts
+       
+       . = CaseBegin + 0x20
+
+       moveb   value,atemp@(3)         /* 1 */
+       Break
+
+       . = CaseBegin + 0x40
+
+       moveb   value,atemp@(2)         /* 2 */
+       Break
+
+       . = CaseBegin + 0x60
+
+       movew   value,atemp@(2)         /* 3 */
+       Break
+
+       . = CaseBegin + 0x80
+
+       moveb   value,atemp@(1)         /* 4 */
+       Break
+
+       . = CaseBegin + 0xa0
+
+       moveb   value,atemp@(3)         /* 5 */
+       moveb   value,atemp@(1)
+       Break
+
+       . = CaseBegin + 0xc0
+
+       movew   value,atemp@(1)         /* 6 */
+       Break
+
+       . = CaseBegin + 0xe0
+
+       movew   value,atemp@(2)         /* 7 */
+       moveb   value,atemp@(1) 
+       Break
+
+       . = CaseBegin + 0x100
+
+       moveb   value,atemp@            /* 8 */
+       Break
+
+       . = CaseBegin + 0x120
+
+       moveb   value,atemp@(3)         /* 9 */
+       moveb   value,atemp@
+       Break
+
+       . = CaseBegin + 0x140
+
+       moveb   value,atemp@(2)         /* a */
+       moveb   value,atemp@
+       Break
+
+       . = CaseBegin + 0x160
+
+       movew   value,atemp@(2)         /* b */
+       moveb   value,atemp@
+       Break
+
+       . = CaseBegin + 0x180
+
+       movew   value,atemp@            /* c */
+       Break
+
+       . = CaseBegin + 0x1a0
+
+       moveb   value,atemp@(3)         /* d */
+       movew   value,atemp@
+       Break
+
+       . = CaseBegin + 0x1c0
+
+       moveb   value,atemp@(2)         /* e */
+       movew   value,atemp@
+       Break
+
+       . = CaseBegin + 0x1e0
+
+       movel   value,atemp@            /* f */
+       Break
diff --git a/Xserver/programs/Xserver/cfb/stipsparc.s b/Xserver/programs/Xserver/cfb/stipsparc.s
new file mode 100644 (file)
index 0000000..fbfd6a6
--- /dev/null
@@ -0,0 +1,281 @@
+/*
+ * $XConsortium: stipsparc.s,v 1.9 94/04/17 20:29:09 rws Exp $
+ *
+Copyright (c) 1990  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+ *
+ * Author:  Keith Packard, MIT X Consortium
+ */
+
+/*
+ * SPARC assembly code for optimized text rendering.
+ *
+ * Other stippling could be done in assembly, but the payoff is
+ * not nearly as large.  Mostly because large areas are heavily
+ * optimized already.
+ */
+
+/* not that I expect to ever see an LSB SPARC, but ... */
+#ifdef LITTLE_ENDIAN
+# define BitsR         sll
+# define BitsL         srl
+# define BO(o)         o
+# define HO(o)         o
+# define WO(o)         o
+# define FourBits(dest,bits)   and     bits, 0xf, dest
+#else
+# define BitsR         srl
+# define BitsL         sll
+# define BO(o)         3-o
+# define HO(o)         2-o
+# define WO(o)         o
+# define FourBits(dest,bits)   srl     bits, 28, dest
+#endif
+
+/*
+ * cfbStippleStack(addr, stipple, value, stride, Count, Shift)
+ *               4       5       6      7     16(sp) 20(sp)
+ *
+ *  Apply successive 32-bit stipples starting at addr, addr+stride, ...
+ *
+ *  Used for text rendering, but only when no data could be lost
+ *  when the stipple is shifted left by Shift bits
+ */
+/* arguments */
+#define addr   %i0
+#define stipple        %i1
+#define value  %i2
+#define stride %i3
+#define count  %i4
+#define shift  %i5
+
+/* local variables */
+#define atemp  %l0
+#define bits   %l1
+#define lshift %l2
+#define sbase  %l3
+#define stemp  %l4
+
+#define CASE_SIZE      5       /* case blocks are 2^5 bytes each */
+#define CASE_MASK      0x1e0   /* first case mask */
+
+#define ForEachLine    LY1
+#define NextLine       LY2
+#define CaseBegin      LY3
+#define ForEachBits    LY4
+#define NextBits       LY5
+
+#if defined(SVR4) || (defined(linux) && (defined(sparc) || defined(__sparc__)))
+#ifdef TETEXT
+#define        _cfbStippleStack        cfbStippleStackTE
+#else
+#define        _cfbStippleStack        cfbStippleStack
+#endif
+#else
+#ifdef TETEXT
+#define        _cfbStippleStack        _cfbStippleStackTE
+#endif
+#endif
+       .seg    "text"
+       .proc   16
+       .globl  _cfbStippleStack
+_cfbStippleStack:
+       save    %sp,-64,%sp
+       sethi   %hi(CaseBegin),sbase            /* load up switch table */
+       or      sbase,%lo(CaseBegin),sbase
+
+       mov     4,lshift                        /* compute offset within */
+       sub     lshift, shift, lshift           /*  stipple of remaining bits */
+#ifdef LITTLE_ENDIAN
+       inc     CASE_SIZE, shift                /* first shift for LSB */
+#else
+       inc     28-CASE_SIZE, shift             /* first shift for MSB */
+#endif
+       /* do ... while (--count > 0); */
+ForEachLine:
+       ld      [stipple],bits                  /* get stipple bits */
+       mov     addr,atemp                      /* set up for this line */
+#ifdef TETEXT
+       /* Terminal emulator fonts are expanded and have many 0 rows */
+       tst     bits
+       bz      NextLine                        /* skip out early on 0 */
+#endif
+       add     addr, stride, addr              /* step for the loop */
+       BitsR   bits, shift, stemp              /* get first bits */
+       and     stemp, CASE_MASK, stemp         /* compute first jump */
+       BitsL   bits, lshift, bits              /* set remaining bits */
+       jmp     sbase+stemp                     /*  ... */
+       tst     bits
+
+ForEachBits:
+       inc     4, atemp
+ForEachBits1:
+       FourBits(stemp, bits)                   /* compute jump for */
+       sll     stemp, CASE_SIZE, stemp         /*  these four bits */
+       BitsL   bits, 4, bits                   /* step for remaining bits */
+       jmp     sbase+stemp                     /* jump */
+       tst     bits
+CaseBegin:
+       bnz,a   ForEachBits1                    /* 0 */
+       inc     4, atemp
+NextLine:
+       deccc   1, count
+       bnz,a   ForEachLine
+       inc     4, stipple
+       ret
+       restore
+       nop
+
+       bnz     ForEachBits                     /* 1 */
+       stb     value, [atemp+BO(0)]
+       deccc   1, count
+       bnz,a   ForEachLine
+       inc     4, stipple
+       ret
+       restore
+       nop
+                                       
+       bnz     ForEachBits                     /* 2 */
+       stb     value, [atemp+BO(1)]
+       deccc   1, count
+       bnz,a   ForEachLine
+       inc     4, stipple
+       ret
+       restore
+       nop
+                                       
+       bnz     ForEachBits                     /* 3 */
+       sth     value, [atemp+HO(0)]
+       deccc   1, count
+       bnz,a   ForEachLine
+       inc     4, stipple
+       ret
+       restore
+       nop
+                                       
+       bnz     ForEachBits                     /* 4 */
+       stb     value, [atemp+BO(2)]
+       deccc   1, count
+       bnz,a   ForEachLine
+       inc     4, stipple
+       ret
+       restore
+       nop
+                                       
+       stb     value, [atemp+BO(0)]            /* 5 */
+       bnz     ForEachBits
+       stb     value, [atemp+BO(2)]
+       deccc   1, count
+       bnz,a   ForEachLine
+       inc     4, stipple
+       ret
+       restore
+                                       
+       stb     value, [atemp+BO(1)]            /* 6 */
+       bnz     ForEachBits
+       stb     value, [atemp+BO(2)]
+       deccc   1, count
+       bnz,a   ForEachLine
+       inc     4, stipple
+       ret
+       restore
+                                       
+       sth     value, [atemp+HO(0)]            /* 7 */
+       bnz     ForEachBits
+       stb     value, [atemp+BO(2)]
+       deccc   1, count
+       bnz,a   ForEachLine
+       inc     4, stipple
+       ret
+       restore
+                                       
+       bnz     ForEachBits                     /* 8 */
+       stb     value, [atemp+BO(3)]
+       deccc   1, count
+       bnz,a   ForEachLine
+       inc     4, stipple
+       ret
+       restore
+       nop
+                                       
+       stb     value, [atemp+BO(0)]            /* 9 */
+       bnz     ForEachBits
+       stb     value, [atemp+BO(3)]
+       deccc   1, count
+       bnz,a   ForEachLine
+       inc     4, stipple
+       ret
+       restore
+                                       
+       stb     value, [atemp+BO(1)]            /* a */
+       bnz     ForEachBits
+       stb     value, [atemp+BO(3)]
+       deccc   1, count
+       bnz,a   ForEachLine
+       inc     4, stipple
+       ret
+       restore
+                                       
+       sth     value, [atemp+HO(0)]            /* b */
+       bnz     ForEachBits
+       stb     value, [atemp+BO(3)]
+       deccc   1, count
+       bnz,a   ForEachLine
+       inc     4, stipple
+       ret
+       restore
+                                       
+       bnz     ForEachBits                     /* c */
+       sth     value, [atemp+HO(2)]
+       deccc   1, count
+       bnz,a   ForEachLine
+       inc     4, stipple
+       ret
+       restore
+       nop
+                                       
+       stb     value, [atemp+BO(0)]            /* d */
+       bnz     ForEachBits
+       sth     value, [atemp+HO(2)]
+       deccc   1, count
+       bnz,a   ForEachLine
+       inc     4, stipple
+       ret
+       restore
+                                       
+       stb     value, [atemp+BO(1)]            /* e */
+       bnz     ForEachBits
+       sth     value, [atemp+HO(2)]
+       deccc   1, count
+       bnz,a   ForEachLine
+       inc     4, stipple
+       ret
+       restore
+                                       
+       bnz     ForEachBits                     /* f */
+       st      value, [atemp+WO(0)]
+       deccc   1, count
+       bnz,a   ForEachLine
+       inc     4, stipple
+       ret
+       restore
diff --git a/Xserver/programs/Xserver/cfb/stipsprc32.s b/Xserver/programs/Xserver/cfb/stipsprc32.s
new file mode 100644 (file)
index 0000000..00c0b6a
--- /dev/null
@@ -0,0 +1,282 @@
+/*
+ * $XConsortium: stipsprc32.s,v 1.3 94/04/17 20:29:10 rws Exp $
+ *
+Copyright (c) 1990  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+ *
+ * Author:  Keith Packard, MIT X Consortium
+ */
+
+/*
+ * SPARC assembly code for optimized text rendering.
+ *
+ * Other stippling could be done in assembly, but the payoff is
+ * not nearly as large.  Mostly because large areas are heavily
+ * optimized already.
+ */
+
+/* not that I expect to ever see an LSB SPARC, but ... */
+#ifdef LITTLE_ENDIAN
+# define BitsR         sll
+# define BitsL         srl
+# define WO(o)         3-o
+# define FourBits(dest,bits)   and     bits, 0xf, dest
+#else
+# define BitsR         srl
+# define BitsL         sll
+# define WO(o)         o
+# define FourBits(dest,bits)   srl     bits, 28, dest
+#endif
+
+/*
+ * cfb32StippleStack(addr, stipple, value, stride, Count, Shift)
+ *               4       5       6      7     16(sp) 20(sp)
+ *
+ *  Apply successive 32-bit stipples starting at addr, addr+stride, ...
+ *
+ *  Used for text rendering, but only when no data could be lost
+ *  when the stipple is shifted left by Shift bits
+ */
+/* arguments */
+#define addr   %i0
+#define stipple        %i1
+#define value  %i2
+#define stride %i3
+#define count  %i4
+#define shift  %i5
+
+/* local variables */
+#define atemp  %l0
+#define bits   %l1
+#define lshift %l2
+#define sbase  %l3
+#define stemp  %l4
+
+#define CASE_SIZE      5       /* case blocks are 2^5 bytes each */
+#define CASE_MASK      0x1e0   /* first case mask */
+
+#define ForEachLine    LY1
+#define NextLine       LY2
+#define CaseBegin      LY3
+#define ForEachBits    LY4
+#define NextBits       LY5
+
+#if defined(SVR4) || (defined(linux) && (defined(sparc) || defined(__sparc__)))
+#ifdef TETEXT
+#define        _cfb32StippleStack      cfb32StippleStackTE
+#else
+#define        _cfb32StippleStack      cfb32StippleStack
+#endif
+#else
+#ifdef TETEXT
+#define        _cfb32StippleStack      _cfb32StippleStackTE
+#endif
+#endif
+
+       .seg    "text"
+       .proc   16
+       .globl  _cfb32StippleStack
+_cfb32StippleStack:
+       save    %sp,-64,%sp
+       sethi   %hi(CaseBegin),sbase            /* load up switch table */
+       or      sbase,%lo(CaseBegin),sbase
+
+       mov     4,lshift                        /* compute offset within */
+       sub     lshift, shift, lshift           /*  stipple of remaining bits */
+#ifdef LITTLE_ENDIAN
+       inc     CASE_SIZE, shift                /* first shift for LSB */
+#else
+       inc     28-CASE_SIZE, shift             /* first shift for MSB */
+#endif
+       /* do ... while (--count > 0); */
+ForEachLine:
+       ld      [stipple],bits                  /* get stipple bits */
+       mov     addr,atemp                      /* set up for this line */
+#ifdef TETEXT
+       /* Terminal emulator fonts are expanded and have many 0 rows */
+       tst     bits
+       bz      NextLine                        /* skip out early on 0 */
+#endif
+       add     addr, stride, addr              /* step for the loop */
+       BitsR   bits, shift, stemp              /* get first bits */
+       and     stemp, CASE_MASK, stemp         /* compute first jump */
+       BitsL   bits, lshift, bits              /* set remaining bits */
+       jmp     sbase+stemp                     /*  ... */
+       tst     bits
+
+ForEachBits:
+       inc     16, atemp
+ForEachBits1:
+       FourBits(stemp, bits)                   /* compute jump for */
+       sll     stemp, CASE_SIZE, stemp         /*  these four bits */
+       BitsL   bits, 4, bits                   /* step for remaining bits */
+       jmp     sbase+stemp                     /* jump */
+       tst     bits
+CaseBegin:
+       bnz,a   ForEachBits1                    /* 0 */
+       inc     16, atemp
+NextLine:
+       deccc   1, count
+NextLine1:
+       bnz,a   ForEachLine
+       inc     4, stipple
+       ret
+       restore
+       nop
+
+       bnz     ForEachBits                     /* 1 */
+       st      value, [atemp+WO(12)]
+       deccc   1, count
+       bnz,a   ForEachLine
+       inc     4, stipple
+       ret
+       restore
+       nop
+                                       
+       bnz     ForEachBits                     /* 2 */
+       st      value, [atemp+WO(8)]
+       deccc   1, count
+       bnz,a   ForEachLine
+       inc     4, stipple
+       ret
+       restore
+       nop
+                                       
+       st      value, [atemp+WO(8)]            /* 3 */
+       bnz     ForEachBits
+       st      value, [atemp+WO(12)]
+       deccc   1, count
+       bnz,a   ForEachLine
+       inc     4, stipple
+       ret
+       restore
+                                       
+       bnz     ForEachBits                     /* 4 */
+       st      value, [atemp+WO(4)]
+       deccc   1, count
+       bnz,a   ForEachLine
+       inc     4, stipple
+       ret
+       restore
+       nop
+                                       
+       st      value, [atemp+WO(4)]            /* 5 */
+       bnz     ForEachBits
+       st      value, [atemp+WO(12)]
+       deccc   1, count
+       bnz,a   ForEachLine
+       inc     4, stipple
+       ret
+       restore
+                                       
+       st      value, [atemp+WO(4)]            /* 6 */
+       bnz     ForEachBits
+       st      value, [atemp+WO(8)]
+       deccc   1, count
+       bnz,a   ForEachLine
+       inc     4, stipple
+       ret
+       restore
+                                       
+       st      value, [atemp+WO(4)]            /* 7 */
+       st      value, [atemp+WO(8)]
+       bnz     ForEachBits
+       st      value, [atemp+WO(12)]
+       b       NextLine1
+       deccc   1, count
+       nop
+       nop
+                                       
+       bnz     ForEachBits                     /* 8 */
+       st      value, [atemp+WO(0)]
+       deccc   1, count
+       bnz,a   ForEachLine
+       inc     4, stipple
+       ret
+       restore
+       nop
+                                       
+       st      value, [atemp+WO(0)]            /* 9 */
+       bnz     ForEachBits
+       st      value, [atemp+WO(12)]
+       deccc   1, count
+       bnz,a   ForEachLine
+       inc     4, stipple
+       ret
+       restore
+                                       
+       st      value, [atemp+WO(0)]            /* a */
+       bnz     ForEachBits
+       st      value, [atemp+WO(8)]
+       deccc   1, count
+       bnz,a   ForEachLine
+       inc     4, stipple
+       ret
+       restore
+                                       
+       st      value, [atemp+WO(0)]            /* b */
+       st      value, [atemp+WO(8)]
+       bnz     ForEachBits
+       st      value, [atemp+WO(12)]
+       b       NextLine1
+       deccc   1, count
+       nop
+       nop
+                                       
+       st      value, [atemp+WO(0)]            /* c */
+       bnz     ForEachBits
+       st      value, [atemp+WO(4)]
+       deccc   1, count
+       bnz,a   ForEachLine
+       inc     4, stipple
+       ret
+       restore
+                                       
+       st      value, [atemp+WO(0)]            /* d */
+       st      value, [atemp+WO(4)]
+       bnz     ForEachBits
+       st      value, [atemp+WO(12)]
+       b       NextLine1
+       deccc   1, count
+       nop
+       nop
+                                       
+       st      value, [atemp+WO(0)]            /* e */
+       st      value, [atemp+WO(4)]
+       bnz     ForEachBits
+       st      value, [atemp+WO(8)]
+       b       NextLine1
+       deccc   1, count
+       nop
+       nop
+                                       
+       st      value, [atemp+WO(0)]            /* f */
+       st      value, [atemp+WO(4)]
+       st      value, [atemp+WO(8)]
+       bnz     ForEachBits
+       st      value, [atemp+WO(12)]
+       deccc   1, count
+       bnz,a   ForEachLine
+       inc     4, stipple
+       ret
+       restore
diff --git a/Xserver/programs/Xserver/cfb16/Imakefile b/Xserver/programs/Xserver/cfb16/Imakefile
new file mode 100644 (file)
index 0000000..3cd2304
--- /dev/null
@@ -0,0 +1,5 @@
+XCOMM $XConsortium: Imakefile,v 1.1 91/12/28 13:32:27 rws Exp $
+#define PixelSize      16
+#define LinkDirectory ../cfb
+
+#include "../cfb/Imakefile"
diff --git a/Xserver/programs/Xserver/cfb24/Imakefile b/Xserver/programs/Xserver/cfb24/Imakefile
new file mode 100644 (file)
index 0000000..46e93dd
--- /dev/null
@@ -0,0 +1,5 @@
+XCOMM $XFree86: xc/programs/Xserver/cfb24/Imakefile,v 3.0 1996/06/29 09:06:07 dawes Exp $
+#define PixelSize      24
+#define LinkDirectory ../cfb
+
+#include "../cfb/Imakefile"
diff --git a/Xserver/programs/Xserver/cfb24/cfbrrop24.h b/Xserver/programs/Xserver/cfb24/cfbrrop24.h
new file mode 100644 (file)
index 0000000..f77009d
--- /dev/null
@@ -0,0 +1,60 @@
+/* $XFree86: xc/programs/Xserver/cfb24/cfbrrop24.h,v 3.0 1996/06/29 09:06:09 dawes Exp $ */
+
+#define RROP_DECLARE       register unsigned long rrop_and, rrop_xor; \
+    unsigned long piQxelAnd[3], piQxelXor[3],  spiQxelAnd[8], spiQxelXor[8];
+
+#define RROP_COPY_SETUP(ptn)  \
+    spiQxelXor[0] = ptn & 0xFFFFFF; \
+    spiQxelXor[2] = ptn << 24; \
+    spiQxelXor[3] = (ptn & 0xFFFF00)>> 8; \
+    spiQxelXor[4] = ptn << 16; \
+    spiQxelXor[5] = (ptn & 0xFF0000)>> 16; \
+    spiQxelXor[6] = ptn << 8; \
+    spiQxelXor[1] = spiQxelXor[7] = 0;
+
+#define RROP_SOLID24_COPY(dst,index)       {\
+           register int idx = ((index) & 3)<< 1; \
+           *(dst) = (*(dst) & cfbrmask[idx])|spiQxelXor[idx]; \
+           idx++; \
+           *((dst)+1) = (*((dst)+1) & cfbrmask[idx])|spiQxelXor[idx]; \
+       }
+
+#define RROP_SET_SETUP(xor, and) \
+    spiQxelXor[0] = xor & 0xFFFFFF; \
+    spiQxelXor[1] = xor << 24; \
+    spiQxelXor[2] = xor << 16; \
+    spiQxelXor[3] = xor << 8; \
+    spiQxelXor[4] = (xor >> 8) & 0xFFFF; \
+    spiQxelXor[5] = (xor >> 16) & 0xFF; \
+    spiQxelAnd[0] = (and & 0xFFFFFF) | 0xFF000000; \
+    spiQxelAnd[1] = (and << 24) | 0xFFFFFF; \
+    spiQxelAnd[2] = (and << 16) | 0xFFFF; \
+    spiQxelAnd[3] = (and << 8) | 0xFF; \
+    spiQxelAnd[4] = ((and >> 8) & 0xFFFF) | 0xFFFF0000; \
+    spiQxelAnd[5] = ((and >> 16) & 0xFF) | 0xFFFFFF00; \
+    piQxelAnd[0] = (and & 0xFFFFFF)|(and << 24); \
+    piQxelAnd[1] = (and << 16)|((and >> 8) & 0xFFFF); \
+    piQxelAnd[2] = (and << 8)|((and >> 16) & 0xFF); \
+    piQxelXor[0] = (xor & 0xFFFFFF)|(xor << 24); \
+    piQxelXor[1] = (xor << 16)|((xor >> 8) & 0xFFFF); \
+    piQxelXor[2] = (xor << 8)|((xor >> 16) & 0xFF);
+
+
+#define RROP_SOLID24_SET(dst,index)         {\
+           switch((index) & 3){ \
+           case 0: \
+             *(dst) = ((*(dst) & (piQxelAnd[0] |0xFF000000))^(piQxelXor[0] & 0xFFFFFF)); \
+             break; \
+           case 3: \
+             *(dst) = ((*(dst) & (piQxelAnd[2]|0xFF))^(piQxelXor[2] & 0xFFFFFF00)); \
+             break; \
+           case 1: \
+             *(dst) = ((*(dst) & (piQxelAnd[0]|0xFFFFFF))^(piQxelXor[0] & 0xFF000000)); \
+             *((dst)+1) = ((*((dst)+1) & (piQxelAnd[1]|0xFFFF0000))^(piQxelXor[1] & 0xFFFF)); \
+             break; \
+           case 2: \
+             *(dst) = ((*(dst) & (piQxelAnd[1]|0xFFFF))^(piQxelXor[1] & 0xFFFF0000)); \
+             *((dst)+1) = ((*((dst)+1) & (piQxelAnd[2]|0xFFFFFF00))^(piQxelXor[2] & 0xFF)); \
+             break; \
+           } \
+           }
diff --git a/Xserver/programs/Xserver/cfb32/Imakefile b/Xserver/programs/Xserver/cfb32/Imakefile
new file mode 100644 (file)
index 0000000..ca7a0a7
--- /dev/null
@@ -0,0 +1,5 @@
+XCOMM $XConsortium: Imakefile,v 1.1 91/12/28 13:32:46 rws Exp $
+#define PixelSize      32
+#define LinkDirectory ../cfb
+
+#include "../cfb/Imakefile"
diff --git a/Xserver/programs/Xserver/dix/BuiltInAtoms b/Xserver/programs/Xserver/dix/BuiltInAtoms
new file mode 100644 (file)
index 0000000..910c627
--- /dev/null
@@ -0,0 +1,329 @@
+File: .../x11/server/dix/BuiltInAtoms
+
+This file is of a fixed format and is used to generate both the file
+include/XAtom.h and dix/initatoms.c. Neither of those files should be
+edited directly. Changing the atoms in this file, or even the order in
+which they occur, is equivalent to forcing a new (minor) version number
+on the server. Take care.
+
+The format of the file is that each built in atom starts in column 1
+with no text, other than spaces and tabs, on that line other than a
+mandatory trailing "@" at the end of the line. For each atom (Foo)
+below the defines will be of the form
+       #define XA_Foo <n>
+and the string value of the atom will be "Foo".
+
+The comment lines in this file are not guaranteed to be accurate. To see the
+current truth, look at the Xlib documentation as well as the protocol spec.
+
+Atoms occur in five distinct name spaces within the protocol. Any particular
+atom may or may not have some client interpretation within each of the name
+spaces. For each of the built in atoms, the intended semantics and the space
+within which it is defined is indicated.
+
+Those name spaces are
+       Property names
+       Property types
+       Selections
+       Font properties
+       Type of a ClientMessage event   (none built into server)
+
+For the font properties mentioned here, see the spec for more information.
+
+                               -- Selections --
+
+PRIMARY                                                                              @
+       Selection.
+SECONDARY                                                                    @
+       Selection.
+
+                       -- Property types and names --
+
+ARC                                                                          @
+       Property type:
+               x, y: INT16
+               width, height: CARD16,
+               angle1, angle2: INT16
+ATOM                                                                         @
+       Property type:
+               atom: ATOM
+BITMAP                                                                       @
+       Property type:
+               bitmap: PIXMAP
+                       This is asserted to be of depth 1.
+CARDINAL                                                                     @
+       Property type:
+               card: CARD32 or CARD16 or CARD8
+               the datum size is dependent on the property format
+COLORMAP                                                                     @
+       Property type:
+               colormap: COLORMAP
+CURSOR                                                                       @
+       Property type:
+               cursor: CURSOR
+CUT_BUFFER0                                                                  @
+CUT_BUFFER1                                                                  @
+CUT_BUFFER2                                                                  @
+CUT_BUFFER3                                                                  @
+CUT_BUFFER4                                                                  @
+CUT_BUFFER5                                                                  @
+CUT_BUFFER6                                                                  @
+CUT_BUFFER7                                                                  @
+       Property name:  (type: STRING)
+               Used to implement cut buffer ring, in particular Andrew uses
+               this mechanism.  Anyone else using this sort of IPC mechanism
+               should use these properties.
+
+               Data is normally fetched and stored out of CUT_BUFFER0; the
+               RotateProperties request is used to rotate these buffers.
+DRAWABLE                                                                     @
+       Property type:
+               drawable: DRAWABLE
+FONT                                                                         @
+       Property type:
+               font: FONT
+INTEGER                                                                              @
+       Property type:
+               card: INT32 or INT16 or INT8
+               the datum size is dependent on the property format
+PIXMAP                                                                       @
+       Property type:
+               pixmap: PIXMAP
+POINT                                                                        @
+       Property type:
+               x, y: INT16
+RECTANGLE                                                                    @
+       Property type:
+               x, y: INT16
+               width, height: CARD16
+RESOURCE_MANAGER                                                             @
+       Property name: (type: STRING)
+               Contents of the user's resource manager data base.
+RGB_COLOR_MAP                                                                @
+       Property type:
+               colormap:       COLORMAP
+               red-max:        CARD32
+               red-mult:       CARD32
+               green-max:      CARD32
+               green-mult:     CARD32
+               blue-max:       CARD32
+               blue-mult:      CARD32
+               base-pixel:     CARD32
+
+       The fields `red_max', `green_max', and `blue_max' give the maximum
+       red, green, and blue values, respectively.  Each color
+       coefficient ranges from 0 to its max, inclusive.  For example,
+       a common colormap allocation is 3/3/2:  3 planes for red, 3
+       planes for green, and 2 planes for blue.  Such a colormap would
+       have red_max == 7, green_max = 7, and blue_max = 3.  An alternate
+       allocation that uses only 216 colors is red_max = 5, green_max =
+       5, and blue_max = 5.
+
+       The fields `red_mult', `green_mult', and `blue_mult' give the
+       scale factors used to compose a full pixel value.  (See next
+       paragraph.)  For a 3/3/2 allocation red_mult might be 32,
+       green_mult might be 4, and blue_mult might be 1.  For a
+       6-colors-each allocation, red_mult might be 36, green_mult might
+       be 6, and blue_mult might be 1.
+
+       The field `base_pixel' gives the base pixel value used to
+       compose a full pixel value.  Normally base_pixel is obtained
+       from a call to XAllocColorPlanes().  Given integer red, green,
+       and blue coefficients in their appropriate ranges, one can
+       compute a corresponding pixel value with the expression:
+
+               r * red_mult + g * green_mult + b * blue_mult + base_pixel
+       
+       For gray-scale colormaps, only the colormap, red_max, red_mult,
+       and base_pixel fields are defined; the other fields are
+       ignored.  To compute a gray-scale pixel value, use:
+
+               gray * red_mult + base_pixel
+
+       This is provided to allow applications to share color maps.
+
+RGB_BEST_MAP                                                                 @
+RGB_BLUE_MAP                                                                 @
+RGB_DEFAULT_MAP                                                                      @
+RGB_GRAY_MAP                                                                 @
+RGB_GREEN_MAP                                                                @
+RGB_RED_MAP                                                                  @
+       Property name:  (type: RGB_COLOR_MAP)
+               The needs of most applications can be met with five colormaps.
+               Polite applications may need only a small RGB space, and can
+               use a portion of the default color map. Applications doing
+               high-quality RGB rendering will need an entire colormap,
+               filled with as large an RGB space as possible, e.g. 332. For
+               color separations, an application may need maximum device
+               resolution for each of red, green, and blue, even if this
+               requires three renderings with three colormaps.
+
+               Each of the above five names would be used for sharing color
+               maps.
+STRING                                                                       @
+       Property type:
+               sequence of Bytes
+VISUALID                                                                     @
+       Property type:
+               visual: VISUALID
+WINDOW                                                                       @
+       Property type:
+               window: WINDOW
+WM_COMMAND                                                                   @
+       Property name: (type: STRING)
+               Command line arguments used to invoke this application. The
+               arguments are delimited by null characters (ASCII 0).
+WM_HINTS                                                                     @
+       Property type:
+               flags:          CARD32
+               input:          BOOL32
+               initial-state:  CARD32
+               icon-pixmap:    PIXMAP
+               icon-window:    WINDOW
+               icon_mask:      BITMAP
+               icon-x, icon-y: INT32
+                   flags contains the following bits
+                       0x00000001      input hint
+                       0x00000002      state hint
+                       0x00000004      icon pixmap hint
+                       0x00000008      icon window hint
+                       0x00000010      icon position hint
+                    values for initial-state
+                       0               unspecified -> application does not
+                               care and WM should pick one.
+                       1               normal
+                       2               zoomed
+                       3               iconic
+                       4               inactive -> application believes
+                               itself to be seldomly used. WM may wish to
+                               place it on an inactive menu.
+               This type is potentially extensible. The order is critical;
+               append to the end only.
+       Property name:  (type: WM_HINTS)
+               Additional hints set by the client for use by the window
+               manager.
+WM_CLIENT_MACHINE                                                            @
+       Property name:  (type: STRING)
+               used to communicate with the window manager.  The host name
+               of the machine the client is running on may be set here.
+WM_ICON_NAME                                                                 @
+       Property name:  (type: STRING)
+               what the application would like the label to be for
+               the iconic form of the window.
+WM_ICON_SIZE                                                                 @
+       Property type:
+               minWidth, min-height:   CARD32
+               maxWidth, max-height:   CARD32
+               widthInc, height-inc:   CARD32
+       Property name:  (type: ICON_SIZE)
+               The window manager may set this property on the root window
+               to specify the icon sizes it allows.
+WM_NAME                                                                              @
+       Property name:  (type: STRING)
+               used to communicate with the window manager. This is
+               what the application would like the label for the window.
+WM_NORMAL_HINTS                                                                      @
+       Property name:  (type: SIZE_HINTS)
+               used to communicate with the window manager. This is size
+               hints for a window in its "normal" state.
+WM_SIZE_HINTS                                                                @
+       Property type:
+               flags:                          CARD32
+               x, y:                           INT32
+               width, height:                  CARD32
+               min-width, min-height:          CARD32
+               max-width, max-height:          CARD32
+               width-inc, height-inc:          CARD32
+               min-aspect-x, min-aspect-y:     CARD32
+               max-aspect-x, max-aspect-y:     CARD32
+                   flags contains the following bits
+                       0x00000001      user specified x and y
+                       0x00000002      user specified width and height
+                       0x00000004      program specified position
+                       0x00000008      program specified size
+                       0x00000010      program specified minimum size
+                       0x00000020      program specified maximum size
+                       0x00000040      program specified resize increment
+                       0x00000080      program specified aspect ratio
+               This type is potentially extensible. The order is critical;
+               append to the end only.
+WM_ZOOM_HINTS                                                                @
+       Property name:  (type: SIZE_HINTS)
+               used to communicate with the window manager. This is size
+               hints for a window in its "zoomed" state.
+
+                               -- Font properties --
+
+MIN_SPACE                                                                    @
+       Font property: CARD32
+NORM_SPACE                                                                   @
+       Font property: CARD32
+MAX_SPACE                                                                    @
+       Font property: CARD32
+END_SPACE                                                                    @
+       Font property: CARD32
+SUPERSCRIPT_X                                                                @
+       Font property: INT32
+SUPERSCRIPT_Y                                                                @
+       Font property: INT32
+SUBSCRIPT_X                                                                  @
+       Font property: INT32
+SUBSCRIPT_Y                                                                  @
+       Font property: INT32
+UNDERLINE_POSITION                                                           @
+       Font property: INT32
+UNDERLINE_THICKNESS                                                          @
+       Font property: CARD32   
+STRIKEOUT_ASCENT                                                             @
+       Font property: INT32
+STRIKEOUT_DESCENT                                                            @
+       Font property: INT32
+ITALIC_ANGLE                                                                 @
+       Font property: INT32
+X_HEIGHT                                                                     @
+       Font property: INT32
+QUAD_WIDTH                                                                   @
+       Font property: INT32
+WEIGHT                                                                               @
+       Font property: CARD32
+POINT_SIZE                                                                   @
+       Font property: CARD32
+RESOLUTION                                                                   @
+       Font property: CARD32
+
+The following optional properties on fonts have values that are atoms. The
+atom print name is the useful information.
+
+COPYRIGHT                                                                    @
+       of the font distribution
+NOTICE                                                                       @
+       trademark/copyright of the character shapes
+FONT_NAME                                                                    @
+       name of this particular instance of a font
+FAMILY_NAME                                                                  @
+       name of the 'font family' to which it belongs
+FULL_NAME                                                                    @
+       full text name of the font
+
+The following aren't in order but putting them at the end avoids encoding
+changes.
+
+CAP_HEIGHT                                                                   @
+       Font property: CARD32
+
+
+WM_CLASS                                                                     @
+       Property name: (type: STRING)
+               Used (possibly by some window managers; definitely by 
+               session managers) to look up resources in the resource 
+               data base on behalf of the client who set this property.
+               There are 2 elements:
+                       {char *resource_name; char *resource_class;}
+               delimited by a null character (ascii 0)
+
+WM_TRANSIENT_FOR                                                             @
+       Property name: (type: WINDOW)
+               Used by transient top-level windows, such as dialog 
+               boxes, to point to their logical "parents".  The window 
+               manager can then take down the dialog boxes when the
+               "parent" gets iconified, for instance.
diff --git a/Xserver/programs/Xserver/dix/CHANGES b/Xserver/programs/Xserver/dix/CHANGES
new file mode 100644 (file)
index 0000000..d8fb7c3
--- /dev/null
@@ -0,0 +1,17 @@
+The following changes have been made to this directory since R3 (for
+a full description, see doc/Server/r4.tbl.ms):
+
+     o  Windows restructured (memory reduction, devPrivates and speedups)
+     o  GCs restructured (memory reduction, devPrivates and wrappers)
+     o  Screens restructured (window ops merged in, devPrivates)
+     o  Pixmaps restructured (drawable changes mostly)
+     o  Cursors restructured (shares glyph bits now)
+     o  Visuals restructured (screen index removed, fields rearranged)
+     o  Devices restructured (input extension changes)
+     o  Out of memory changes.  Many interfaces now return OutOfMemory
+       status.
+     o  Synchronous grab code rewritten.  Should conform to our
+       understanding of the protocol now.  Be careful when time
+       stamping events (don't allow time to run backwards).
+     o  Resource types redesigned and rewritten.
+     o  Internal fake color allocation routine for software cursors.
diff --git a/Xserver/programs/Xserver/dix/Imakefile b/Xserver/programs/Xserver/dix/Imakefile
new file mode 100644 (file)
index 0000000..287f7ec
--- /dev/null
@@ -0,0 +1,91 @@
+XCOMM $XConsortium: Imakefile /main/52 1996/12/02 10:20:03 lehors $
+XCOMM $XFree86: xc/programs/Xserver/dix/Imakefile,v 3.8 1997/01/08 20:32:47 dawes Exp $
+#include <Server.tmpl>
+
+#if PrintOnlyServer
+XPSRC = xpstubs.c
+XPOBJ = xpstubs.o
+#endif
+
+#if !HasFfs
+FFS_SRC = ffs.c
+FFS_OBJ = ffs.o
+#endif
+
+SRCS = atom.c colormap.c cursor.c devices.c dispatch.c dixutils.c events.c \
+       extension.c gc.c globals.c glyphcurs.c grabs.c \
+       main.c property.c resource.c swaprep.c swapreq.c \
+       tables.c window.c initatoms.c dixfonts.c privates.c pixmap.c $(FFS_SRC)
+OBJS = atom.o colormap.o cursor.o devices.o dispatch.o dixutils.o events.o \
+       extension.o gc.o globals.o glyphcurs.o grabs.o \
+       main.o property.o resource.o swaprep.o swapreq.o \
+       tables.o window.o initatoms.o dixfonts.o privates.o pixmap.o $(FFS_OBJ)
+
+    INCLUDES = -I../include -I$(XINCLUDESRC) -I$(FONTINCSRC) -I$(EXTINCSRC)
+    LINTLIBS = ../os/llib-los.ln
+
+/*
+ * The following configuration parameters may be set in the appropriate
+ * .macros files or site.def in the directory util/imake.includes/:
+ *
+ *     DefaultFontPath                COMPILEDDEFAULTFONTPATH
+ *     DefaultRGBDatabase             RGB_DB
+ *
+ * The sample util/imake.includes/Imake.tmpl will provide generic defaults.
+ * The values in site.h are simply a last line of defense and should not be
+ * changed.
+ */
+
+#ifdef DefaultFontPath
+DEFAULTFONTPATH = DefaultFontPath
+SITE_FONT_PATH = -DCOMPILEDDEFAULTFONTPATH=\"$(DEFAULTFONTPATH)\"
+#endif
+
+#ifdef DefaultRGBDatabase
+DEFAULTRGBDATABASE = DefaultRGBDatabase
+   SITE_RGB_DB = -DRGB_DB=\"$(DEFAULTRGBDATABASE)\"
+#endif
+
+#ifdef DefaultDisplayClass
+DEFAULTDISPLAYCLASS = DefaultDisplayClass
+   SITE_DISPLAY_CLASS = -DCOMPILEDDISPLAYCLASS=\"$(DEFAULTDISPLAYCLASS)\"
+#endif
+
+#ifdef XVendorString
+VENDORSTRING = XVendorString
+   VENDOR_STRING = -DVENDOR_STRING=\"$(VENDORSTRING)\"
+#endif
+
+#ifdef XVendorRelease
+VENDORRELEASE = XVendorRelease
+   VENDOR_RELEASE = -DVENDOR_RELEASE=$(VENDORRELEASE)
+#endif
+
+#if HasKrb5
+         K5DEFS = Krb5Defines
+#endif
+
+SITE_DEFINES = $(SITE_FONT_PATH) $(SITE_RGB_DB) $(SITE_DISPLAY_CLASS)
+
+VENDOR_DEFINES = $(VENDOR_STRING) $(VENDOR_RELEASE)
+
+NormalLibraryObjectRule()
+NormalLibraryTarget(dix,$(OBJS))
+LintLibraryTarget(dix,$(SRCS) $(XPSRC))
+NormalLintTarget($(SRCS) $(XPSRC))
+
+SpecialCObjectRule(globals,$(ICONFIGFILES),$(SITE_DEFINES))
+SpecialCObjectRule(tables,$(ICONFIGFILES),$(K5DEFS))
+SpecialCObjectRule(dispatch,$(ICONFIGFILES),$(K5DEFS))
+SpecialCObjectRule(main,$(ICONFIGFILES),$(VENDOR_DEFINES))
+SpecialCObjectRule(pixmap,$(ICONFIGFILES),$(_NOOP_))
+SpecialCObjectRule(privates,$(ICONFIGFILES),$(_NOOP_))
+
+#if PrintOnlyServer
+NormalLibraryTarget(xpstubs,$(XPOBJ))
+#endif
+
+InstallLinkKitLibrary(dix,$(LINKKITDIR)/lib)
+InstallLinkKitLibrary(xpstubs,$(LINKKITDIR)/lib)
+
+DependTarget()
diff --git a/Xserver/programs/Xserver/dix/atom.c b/Xserver/programs/Xserver/dix/atom.c
new file mode 100644 (file)
index 0000000..d8cb27a
--- /dev/null
@@ -0,0 +1,214 @@
+/***********************************************************
+
+Copyright (c) 1987  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+
+Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
+
+                        All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and its 
+documentation for any purpose and without fee is hereby granted, 
+provided that the above copyright notice appear in all copies and that
+both that copyright notice and this permission notice appear in 
+supporting documentation, and that the name of Digital not be
+used in advertising or publicity pertaining to distribution of the
+software without specific, written prior permission.  
+
+DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
+ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
+DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
+ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+SOFTWARE.
+
+******************************************************************/
+
+/* $XConsortium: atom.c,v 1.30 94/04/17 20:26:16 dpw Exp $ */
+/* $XFree86: xc/programs/Xserver/dix/atom.c,v 3.0 1996/04/15 11:19:31 dawes Exp $ */
+
+#include "X.h"
+#include "Xatom.h"
+#include "misc.h"
+#include "resource.h"
+#include "dix.h"
+
+#define InitialTableSize 100
+
+typedef struct _Node {
+    struct _Node   *left,   *right;
+    Atom a;
+    unsigned int fingerPrint;
+    char   *string;
+} NodeRec, *NodePtr;
+
+static Atom lastAtom = None;
+static NodePtr atomRoot = (NodePtr)NULL;
+static unsigned long tableLength;
+static NodePtr *nodeTable;
+
+Atom 
+MakeAtom(string, len, makeit)
+    char *string;
+    unsigned len;
+    Bool makeit;
+{
+    register    NodePtr * np;
+    unsigned i;
+    int     comp;
+    register unsigned int   fp = 0;
+
+    np = &atomRoot;
+    for (i = 0; i < (len+1)/2; i++)
+    {
+       fp = fp * 27 + string[i];
+       fp = fp * 27 + string[len - 1 - i];
+    }
+    while (*np != (NodePtr) NULL)
+    {
+       if (fp < (*np)->fingerPrint)
+           np = &((*np)->left);
+       else if (fp > (*np)->fingerPrint)
+           np = &((*np)->right);
+       else
+       {                              /* now start testing the strings */
+           comp = strncmp(string, (*np)->string, (int)len);
+           if ((comp < 0) || ((comp == 0) && (len < strlen((*np)->string))))
+               np = &((*np)->left);
+           else if (comp > 0)
+               np = &((*np)->right);
+           else
+               return(*np)->a;
+           }
+    }
+    if (makeit)
+    {
+       register NodePtr nd;
+
+       nd = (NodePtr) xalloc(sizeof(NodeRec));
+       if (!nd)
+           return BAD_RESOURCE;
+       if (lastAtom < XA_LAST_PREDEFINED)
+       {
+           nd->string = string;
+       }
+       else
+       {
+           nd->string = (char *) xalloc(len + 1);
+           if (!nd->string) {
+               xfree(nd);
+               return BAD_RESOURCE;
+           }
+           strncpy(nd->string, string, (int)len);
+           nd->string[len] = 0;
+       }
+       if ((lastAtom + 1) >= tableLength) {
+           NodePtr *table;
+
+           table = (NodePtr *) xrealloc(nodeTable,
+                                        tableLength * (2 * sizeof(NodePtr)));
+           if (!table) {
+               if (nd->string != string)
+                   xfree(nd->string);
+               xfree(nd);
+               return BAD_RESOURCE;
+           }
+           tableLength <<= 1;
+           nodeTable = table;
+       }
+       *np = nd;
+       nd->left = nd->right = (NodePtr) NULL;
+       nd->fingerPrint = fp;
+       nd->a = (++lastAtom);
+       *(nodeTable+lastAtom) = nd;
+       return nd->a;
+    }
+    else
+       return None;
+}
+
+Bool
+ValidAtom(atom)
+    Atom atom;
+{
+    return (atom != None) && (atom <= lastAtom);
+}
+
+char *
+NameForAtom(atom)
+    Atom atom;
+{
+    NodePtr node;
+    if (atom > lastAtom) return 0;
+    if ((node = nodeTable[atom]) == (NodePtr)NULL) return 0;
+    return node->string;
+}
+
+void
+AtomError()
+{
+    FatalError("initializing atoms");
+}
+
+void
+FreeAtom(patom)
+    NodePtr patom;
+{
+    if(patom->left)
+       FreeAtom(patom->left);
+    if(patom->right)
+       FreeAtom(patom->right);
+    if (patom->a > XA_LAST_PREDEFINED)
+       xfree(patom->string);
+    xfree(patom);
+}
+
+void
+FreeAllAtoms()
+{
+    if(atomRoot == (NodePtr)NULL)
+       return;
+    FreeAtom(atomRoot);
+    atomRoot = (NodePtr)NULL;
+    xfree(nodeTable);
+    nodeTable = (NodePtr *)NULL;
+    lastAtom = None;
+}
+
+void
+InitAtoms()
+{
+    FreeAllAtoms();
+    tableLength = InitialTableSize;
+    nodeTable = (NodePtr *)xalloc(InitialTableSize*sizeof(NodePtr));
+    if (!nodeTable)
+       AtomError();
+    nodeTable[None] = (NodePtr)NULL;
+    MakePredeclaredAtoms();
+    if (lastAtom != XA_LAST_PREDEFINED)
+       AtomError ();
+}
+
+    
diff --git a/Xserver/programs/Xserver/dix/buildatoms b/Xserver/programs/Xserver/dix/buildatoms
new file mode 100755 (executable)
index 0000000..dfbbca8
--- /dev/null
@@ -0,0 +1,43 @@
+#!/bin/sh
+hfile=../../../include/Xatom.h
+cfile=initatoms.c
+rm -f $hfile $cfile
+umask 222
+awk '
+BEGIN {
+       hfile = "'$hfile'";
+       cfile = "'$cfile'";
+       hformat = "#define XA_%s ((Atom) %d)\n";
+       printf("#ifndef XATOM_H\n") > hfile;
+       printf("#define XATOM_H 1\n\n") > hfile;
+       printf("/* THIS IS A GENERATED FILE\n") > hfile;
+       printf(" *\n") > hfile;
+       printf(" * Do not change!  Changing this file implies a protocol change!\n") > hfile;
+       printf(" */\n\n") > hfile;
+
+       printf("/* THIS IS A GENERATED FILE\n") > cfile;
+       printf(" *\n") > cfile;
+       printf(" * Do not change!  Changing this file implies a protocol change!\n") > cfile;
+       printf(" */\n\n") > cfile;
+       printf("#include \"X.h\"\n") > cfile;
+       printf("#include \"Xatom.h\"\n") > cfile;
+       printf("#include \"misc.h\"\n") > cfile;
+       printf("#include \"dix.h\"\n") > cfile;
+       printf("void MakePredeclaredAtoms()\n") > cfile;
+       printf("{\n") > cfile;
+
+       }
+
+NF == 2 && $2 == "@" {
+       printf(hformat, $1, ++atomno) > hfile ;
+       printf("    if (MakeAtom(\"%s\", %d, 1) != XA_%s) AtomError();\n", $1, length($1), $1) > cfile ;
+       }
+
+END {
+       printf("\n") > hfile;
+       printf(hformat, "LAST_PREDEFINED", atomno) > hfile ;
+       printf("#endif /* XATOM_H */\n") > hfile;
+       printf("}\n") > cfile ;
+       }
+' BuiltInAtoms
+exit 0
diff --git a/Xserver/programs/Xserver/dix/colormap.c b/Xserver/programs/Xserver/dix/colormap.c
new file mode 100644 (file)
index 0000000..1b6cf08
--- /dev/null
@@ -0,0 +1,2794 @@
+/***********************************************************
+
+Copyright (c) 1987  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+
+Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
+
+                        All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and its 
+documentation for any purpose and without fee is hereby granted, 
+provided that the above copyright notice appear in all copies and that
+both that copyright notice and this permission notice appear in 
+supporting documentation, and that the name of Digital not be
+used in advertising or publicity pertaining to distribution of the
+software without specific, written prior permission.  
+
+DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
+ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
+DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
+ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+SOFTWARE.
+
+******************************************************************/
+
+/* $XConsortium: colormap.c /main/71 1996/06/17 11:01:33 mor $ */
+/* $XFree86: xc/programs/Xserver/dix/colormap.c,v 3.1 1996/12/23 06:29:34 dawes Exp $ */
+
+#include "X.h"
+#define NEED_EVENTS
+#include "Xproto.h"
+#include "misc.h"
+#include "dix.h"
+#include "colormapst.h"
+#include "os.h"
+#include "scrnintstr.h"
+#include "resource.h"
+#include "windowstr.h"
+
+extern XID clientErrorValue;
+
+static Pixel FindBestPixel(
+#if NeedFunctionPrototypes
+    EntryPtr /*pentFirst*/,
+    int /*size*/,
+    xrgb * /*prgb*/,
+    int /*channel*/
+#endif
+);
+
+static int AllComp(
+#if NeedFunctionPrototypes
+    EntryPtr /*pent*/,
+    xrgb * /*prgb*/
+#endif
+);
+
+static int RedComp(
+#if NeedFunctionPrototypes
+    EntryPtr /*pent*/,
+    xrgb * /*prgb*/
+#endif
+);
+
+static int GreenComp(
+#if NeedFunctionPrototypes
+    EntryPtr /*pent*/,
+    xrgb * /*prgb*/
+#endif
+);
+
+static int BlueComp(
+#if NeedFunctionPrototypes
+    EntryPtr /*pent*/,
+    xrgb * /*prgb*/
+#endif
+);
+
+static void FreePixels(
+#if NeedFunctionPrototypes
+    register ColormapPtr /*pmap*/,
+    register int /*client*/
+#endif
+);
+
+static void CopyFree(
+#if NeedFunctionPrototypes
+    int /*channel*/,
+    int /*client*/,
+    ColormapPtr /*pmapSrc*/,
+    ColormapPtr /*pmapDst*/
+#endif
+);
+
+static void FreeCell(
+#if NeedFunctionPrototypes
+    ColormapPtr /*pmap*/,
+    Pixel /*i*/,
+    int /*channel*/
+#endif
+);
+
+static void UpdateColors(
+#if NeedFunctionPrototypes
+    ColormapPtr /*pmap*/
+#endif
+);
+
+static int AllocDirect(
+#if NeedFunctionPrototypes
+    int /*client*/,
+    ColormapPtr /*pmap*/,
+    int /*c*/,
+    int /*r*/,
+    int /*g*/,
+    int /*b*/,
+    Bool /*contig*/,
+    Pixel * /*pixels*/,
+    Pixel * /*prmask*/,
+    Pixel * /*pgmask*/,
+    Pixel * /*pbmask*/
+#endif
+);
+
+static int AllocPseudo(
+#if NeedFunctionPrototypes
+    int /*client*/,
+    ColormapPtr /*pmap*/,
+    int /*c*/,
+    int /*r*/,
+    Bool /*contig*/,
+    Pixel * /*pixels*/,
+    Pixel * /*pmask*/,
+    Pixel ** /*pppixFirst*/
+#endif
+);
+
+static Bool AllocCP(
+#if NeedFunctionPrototypes
+    ColormapPtr /*pmap*/,
+    EntryPtr /*pentFirst*/,
+    int /*count*/,
+    int /*planes*/,
+    Bool /*contig*/,
+    Pixel * /*pixels*/,
+    Pixel * /*pMask*/
+#endif
+);
+
+static Bool AllocShared(
+#if NeedFunctionPrototypes
+    ColormapPtr /*pmap*/,
+    Pixel * /*ppix*/,
+    int /*c*/,
+    int /*r*/,
+    int /*g*/,
+    int /*b*/,
+    Pixel /*rmask*/,
+    Pixel /*gmask*/,
+    Pixel /*bmask*/,
+    Pixel * /*ppixFirst*/
+#endif
+);
+
+static int FreeCo(
+#if NeedFunctionPrototypes
+    ColormapPtr /*pmap*/,
+    int /*client*/,
+    int /*color*/,
+    int /*npixIn*/,
+    Pixel * /*ppixIn*/,
+    Pixel /*mask*/
+#endif
+);
+
+static int   TellNoMap(
+#if NeedFunctionPrototypes
+    WindowPtr  /*pwin*/,
+    Colormap   * /*pmid*/
+#endif
+);
+
+#define NUMRED(vis) ((vis->redMask >> vis->offsetRed) + 1)
+#define NUMGREEN(vis) ((vis->greenMask >> vis->offsetGreen) + 1)
+#define NUMBLUE(vis) ((vis->blueMask >> vis->offsetBlue) + 1)
+#define RGBMASK(vis) (vis->redMask | vis->greenMask | vis->blueMask)
+
+/* GetNextBitsOrBreak(bits, mask, base)  -- 
+ * (Suggestion: First read the macro, then read this explanation.
+ *
+ * Either generate the next value to OR in to a pixel or break out of this
+ * while loop 
+ *
+ * This macro is used when we're trying to generate all 2^n combinations of
+ * bits in mask.  What we're doing here is counting in binary, except that
+ * the bits we use to count may not be contiguous.  This macro will be
+ * called 2^n times, returning a different value in bits each time. Then
+ * it will cause us to break out of a surrounding loop. (It will always be
+ * called from within a while loop.)
+ * On call: mask is the value we want to find all the combinations for
+ * base has 1 bit set where the least significant bit of mask is set
+ *
+ * For example,if mask is 01010, base should be 0010 and we count like this:
+ * 00010 (see this isn't so hard), 
+ *     then we add base to bits and get 0100. (bits & ~mask) is (0100 & 0100) so
+ *      we add that to bits getting (0100 + 0100) =
+ * 01000 for our next value.
+ *      then we add 0010 to get 
+ * 01010 and we're done (easy as 1, 2, 3)
+ */
+#define GetNextBitsOrBreak(bits, mask, base)   \
+           if((bits) == (mask))                \
+               break;                          \
+           (bits) += (base);                   \
+           while((bits) & ~(mask))             \
+               (bits) += ((bits) & ~(mask));   
+/* ID of server as client */
+#define SERVER_ID      0
+
+typedef struct _colorResource
+{
+       Colormap        mid;
+       int             client;
+} colorResource;
+
+/* Invariants:
+ * refcnt == 0 means entry is empty
+ * refcnt > 0 means entry is useable by many clients, so it can't be changed
+ * refcnt == AllocPrivate means entry owned by one client only
+ * fShared should only be set if refcnt == AllocPrivate, and only in red map
+ */
+
+
+/* Create and initialize the color map */
+int 
+CreateColormap (mid, pScreen, pVisual, ppcmap, alloc, client)
+    Colormap   mid;            /* resource to use for this colormap */
+    ScreenPtr  pScreen;
+    VisualPtr  pVisual;
+    ColormapPtr        *ppcmap;        
+    int                alloc;          /* 1 iff all entries are allocated writeable */
+    int                client;
+{
+    int                class, size;
+    unsigned long sizebytes;
+    ColormapPtr        pmap;
+    register   EntryPtr        pent;
+    int                i;
+    register   Pixel   *ppix, **pptr;
+    extern int colormapPrivateCount;
+
+    class = pVisual->class;
+    if(!(class & DynamicClass) && (alloc != AllocNone) && (client != SERVER_ID))
+       return (BadMatch);
+
+    size = pVisual->ColormapEntries;
+    sizebytes = (size * sizeof(Entry)) +
+               (MAXCLIENTS * sizeof(Pixel *)) +
+               (MAXCLIENTS * sizeof(int));
+    if ((class | DynamicClass) == DirectColor)
+       sizebytes *= 3;
+    sizebytes += sizeof(ColormapRec);
+    pmap = (ColormapPtr) xalloc(sizebytes);
+    if (!pmap)
+       return (BadAlloc);
+    pmap->red = (EntryPtr)((char *)pmap + sizeof(ColormapRec));    
+    sizebytes = size * sizeof(Entry);
+    pmap->clientPixelsRed = (Pixel **)((char *)pmap->red + sizebytes);
+    pmap->numPixelsRed = (int *)((char *)pmap->clientPixelsRed +
+                                (MAXCLIENTS * sizeof(Pixel *)));
+    pmap->mid = mid;
+    pmap->flags = 0;   /* start out with all flags clear */
+    if(mid == pScreen->defColormap)
+       pmap->flags |= IsDefault;
+    pmap->pScreen = pScreen;
+    pmap->pVisual = pVisual;
+    pmap->class = class;
+    if ((class | DynamicClass) == DirectColor)
+       size = NUMRED(pVisual);
+    pmap->freeRed = size;
+    bzero ((char *) pmap->red, (int)sizebytes);
+    bzero((char *) pmap->numPixelsRed, MAXCLIENTS * sizeof(int));
+    for (pptr = &pmap->clientPixelsRed[MAXCLIENTS]; --pptr >= pmap->clientPixelsRed; )
+       *pptr = (Pixel *)NULL;
+    if (alloc == AllocAll)
+    {
+       if (class & DynamicClass)
+           pmap->flags |= AllAllocated;
+       for (pent = &pmap->red[size - 1]; pent >= pmap->red; pent--)
+           pent->refcnt = AllocPrivate;
+       pmap->freeRed = 0;
+       ppix = (Pixel *)xalloc(size * sizeof(Pixel));
+       if (!ppix)
+       {
+           xfree(pmap);
+           return (BadAlloc);
+       }
+       pmap->clientPixelsRed[client] = ppix;
+       for(i = 0; i < size; i++)
+           ppix[i] = i;
+       pmap->numPixelsRed[client] = size;
+    }
+
+    if ((class | DynamicClass) == DirectColor)
+    {
+       pmap->freeGreen = NUMGREEN(pVisual);
+       pmap->green = (EntryPtr)((char *)pmap->numPixelsRed +
+                                (MAXCLIENTS * sizeof(int)));
+       pmap->clientPixelsGreen = (Pixel **)((char *)pmap->green + sizebytes);
+       pmap->numPixelsGreen = (int *)((char *)pmap->clientPixelsGreen +
+                                      (MAXCLIENTS * sizeof(Pixel *)));
+       pmap->freeBlue = NUMBLUE(pVisual);
+       pmap->blue = (EntryPtr)((char *)pmap->numPixelsGreen +
+                               (MAXCLIENTS * sizeof(int)));
+       pmap->clientPixelsBlue = (Pixel **)((char *)pmap->blue + sizebytes);
+       pmap->numPixelsBlue = (int *)((char *)pmap->clientPixelsBlue +
+                                     (MAXCLIENTS * sizeof(Pixel *)));
+
+       bzero ((char *) pmap->green, (int)sizebytes);
+       bzero ((char *) pmap->blue, (int)sizebytes);
+
+       memmove((char *) pmap->clientPixelsGreen,
+               (char *) pmap->clientPixelsRed,
+             MAXCLIENTS * sizeof(Pixel *));
+       memmove((char *) pmap->clientPixelsBlue,
+               (char *) pmap->clientPixelsRed,
+             MAXCLIENTS * sizeof(Pixel *));
+       bzero((char *) pmap->numPixelsGreen, MAXCLIENTS * sizeof(int));
+       bzero((char *) pmap->numPixelsBlue, MAXCLIENTS * sizeof(int));
+
+       /* If every cell is allocated, mark its refcnt */
+       if (alloc == AllocAll)
+       {
+           size = pmap->freeGreen;
+           for(pent = &pmap->green[size-1]; pent >= pmap->green; pent--)
+               pent->refcnt = AllocPrivate;
+           pmap->freeGreen = 0;
+           ppix = (Pixel *) xalloc(size * sizeof(Pixel));
+           if (!ppix)
+           {
+               xfree(pmap->clientPixelsRed[client]);
+               xfree(pmap);
+               return(BadAlloc);
+           }
+           pmap->clientPixelsGreen[client] = ppix;
+           for(i = 0; i < size; i++)
+               ppix[i] = i;
+           pmap->numPixelsGreen[client] = size;
+
+           size = pmap->freeBlue;
+           for(pent = &pmap->blue[size-1]; pent >= pmap->blue; pent--)
+               pent->refcnt = AllocPrivate;
+           pmap->freeBlue = 0;
+           ppix = (Pixel *) xalloc(size * sizeof(Pixel));
+           if (!ppix)
+           {
+               xfree(pmap->clientPixelsGreen[client]);
+               xfree(pmap->clientPixelsRed[client]);
+               xfree(pmap);
+               return(BadAlloc);
+           }
+           pmap->clientPixelsBlue[client] = ppix;
+           for(i = 0; i < size; i++)
+               ppix[i] = i;
+           pmap->numPixelsBlue[client] = size;
+       }
+    }
+    if (!AddResource(mid, RT_COLORMAP, (pointer)pmap))
+       return (BadAlloc);
+    /* If the device wants a chance to initialize the colormap in any way,
+     * this is it.  In specific, if this is a Static colormap, this is the
+     * time to fill in the colormap's values */
+    pmap->flags |= BeingCreated;
+
+
+    /*
+     * Allocate the array of devPrivate's for this colormap.
+     */
+
+    if (colormapPrivateCount == 0)
+       pmap->devPrivates = NULL;
+    else
+    {
+       pmap->devPrivates = (DevUnion *) xalloc (
+           colormapPrivateCount * sizeof(DevUnion));
+
+       if (!pmap->devPrivates)
+       {
+           FreeResource (mid, RT_NONE);
+           return BadAlloc;
+       }
+    }
+
+    if (!(*pScreen->CreateColormap)(pmap))
+    {
+       FreeResource (mid, RT_NONE);
+       return BadAlloc;
+    }
+    pmap->flags &= ~BeingCreated;
+    *ppcmap = pmap;
+    return (Success);
+}
+
+int
+FreeColormap (value, mid)
+    pointer    value; /* must conform to DeleteType */
+    XID                mid;
+{
+    int                i;
+    register EntryPtr pent;
+    ColormapPtr        pmap = (ColormapPtr)value;
+
+    if(CLIENT_ID(mid) != SERVER_ID)
+    {
+        (*pmap->pScreen->UninstallColormap) (pmap);
+        WalkTree(pmap->pScreen, (VisitWindowProcPtr)TellNoMap, (pointer) &mid);
+    }
+
+    /* This is the device's chance to undo anything it needs to, especially
+     * to free any storage it allocated */
+    (*pmap->pScreen->DestroyColormap)(pmap);
+
+    if(pmap->clientPixelsRed)
+    {
+       for(i = 0; i < MAXCLIENTS; i++)
+           xfree(pmap->clientPixelsRed[i]);
+    }
+
+    if ((pmap->class == PseudoColor) || (pmap->class == GrayScale))
+    {
+       for(pent = &pmap->red[pmap->pVisual->ColormapEntries - 1];
+           pent >= pmap->red;
+           pent--)
+       {
+           if(pent->fShared)
+           {
+               if (--pent->co.shco.red->refcnt == 0)
+                   xfree(pent->co.shco.red);
+               if (--pent->co.shco.green->refcnt == 0)
+                   xfree(pent->co.shco.green);
+               if (--pent->co.shco.blue->refcnt == 0)
+                   xfree(pent->co.shco.blue);
+           }
+       }
+    }
+    if((pmap->class | DynamicClass) == DirectColor)
+    {
+        for(i = 0; i < MAXCLIENTS; i++)
+       {
+            xfree(pmap->clientPixelsGreen[i]);
+            xfree(pmap->clientPixelsBlue[i]);
+        }
+    }
+
+    if (pmap->devPrivates)
+       xfree(pmap->devPrivates);
+
+    xfree(pmap);
+    return(Success);
+}
+
+/* Tell window that pmid has disappeared */
+static int
+TellNoMap (pwin, pmid)
+    WindowPtr  pwin;
+    Colormap   *pmid;
+{
+    xEvent     xE;
+    if (wColormap(pwin) == *pmid)
+    {
+       /* This should be call to DeliverEvent */
+       xE.u.u.type = ColormapNotify;
+       xE.u.colormap.window = pwin->drawable.id;
+       xE.u.colormap.colormap = None;
+       xE.u.colormap.new = TRUE;
+       xE.u.colormap.state = ColormapUninstalled;
+       DeliverEvents(pwin, &xE, 1, (WindowPtr)NULL);
+       if (pwin->optional) {
+           pwin->optional->colormap = None;
+           CheckWindowOptionalNeed (pwin);
+       }
+    }
+
+    return (WT_WALKCHILDREN);
+}
+
+/* Tell window that pmid got uninstalled */
+int
+TellLostMap (pwin, value)
+    WindowPtr  pwin;
+    pointer    value;
+{
+    Colormap   *pmid = (Colormap *)value;
+    xEvent     xE;
+    if (wColormap(pwin) == *pmid)
+    {
+       /* This should be call to DeliverEvent */
+       xE.u.u.type = ColormapNotify;
+       xE.u.colormap.window = pwin->drawable.id;
+       xE.u.colormap.colormap = *pmid;
+       xE.u.colormap.new = FALSE;
+       xE.u.colormap.state = ColormapUninstalled;
+       DeliverEvents(pwin, &xE, 1, (WindowPtr)NULL);
+    }
+
+    return (WT_WALKCHILDREN);
+}
+
+/* Tell window that pmid got installed */
+int
+TellGainedMap (pwin, value)
+    WindowPtr  pwin;
+    pointer    value;
+{
+    Colormap   *pmid = (Colormap *)value;
+    xEvent     xE;
+    if (wColormap (pwin) == *pmid)
+    {
+       /* This should be call to DeliverEvent */
+       xE.u.u.type = ColormapNotify;
+       xE.u.colormap.window = pwin->drawable.id;
+       xE.u.colormap.colormap = *pmid;
+       xE.u.colormap.new = FALSE;
+       xE.u.colormap.state = ColormapInstalled;
+       DeliverEvents(pwin, &xE, 1, (WindowPtr)NULL);
+    }
+
+    return (WT_WALKCHILDREN);
+}
+
+  
+int
+CopyColormapAndFree (mid, pSrc, client)
+    Colormap   mid;
+    ColormapPtr        pSrc;
+    int                client;
+{
+    ColormapPtr        pmap = (ColormapPtr) NULL;
+    int                result, alloc, size;
+    Colormap   midSrc;
+    ScreenPtr  pScreen;
+    VisualPtr  pVisual;
+
+    pScreen = pSrc->pScreen;
+    pVisual = pSrc->pVisual;
+    midSrc = pSrc->mid;
+    alloc = ((pSrc->flags & AllAllocated) && CLIENT_ID(midSrc) == client) ?
+            AllocAll : AllocNone;
+    size = pVisual->ColormapEntries;
+
+    /* If the create returns non-0, it failed */
+    result = CreateColormap (mid, pScreen, pVisual, &pmap, alloc, client);
+    if(result != Success)
+        return(result);
+    if(alloc == AllocAll)
+    {
+       memmove((char *)pmap->red, (char *)pSrc->red, size * sizeof(Entry));
+       if((pmap->class | DynamicClass) == DirectColor)
+       {
+           memmove((char *)pmap->green, (char *)pSrc->green, size * sizeof(Entry));
+           memmove((char *)pmap->blue, (char *)pSrc->blue, size * sizeof(Entry));
+       }
+       pSrc->flags &= ~AllAllocated;
+       FreePixels(pSrc, client);
+       UpdateColors(pmap);
+       return(Success);
+    }
+
+    CopyFree(REDMAP, client, pSrc, pmap);
+    if ((pmap->class | DynamicClass) == DirectColor)
+    {
+       CopyFree(GREENMAP, client, pSrc, pmap);
+       CopyFree(BLUEMAP, client, pSrc, pmap);
+    }
+    if (pmap->class & DynamicClass)
+       UpdateColors(pmap);
+    /* XXX should worry about removing any RT_CMAPENTRY resource */
+    return(Success);
+}
+
+/* Helper routine for freeing large numbers of cells from a map */
+static void
+CopyFree (channel, client, pmapSrc, pmapDst)
+    int                channel, client;
+    ColormapPtr        pmapSrc, pmapDst;
+{
+    int                z, npix, oldFree;
+    EntryPtr   pentSrcFirst, pentDstFirst;
+    EntryPtr   pentSrc, pentDst;
+    Pixel      *ppix;
+    int                nalloc;
+
+    switch(channel)
+    {
+      default: /* so compiler can see that everything gets initialized */
+      case REDMAP:
+       ppix = (pmapSrc->clientPixelsRed)[client];
+       npix = (pmapSrc->numPixelsRed)[client];
+       pentSrcFirst = pmapSrc->red;
+       pentDstFirst = pmapDst->red;
+       oldFree = pmapSrc->freeRed;
+       break;
+      case GREENMAP:
+       ppix = (pmapSrc->clientPixelsGreen)[client];
+       npix = (pmapSrc->numPixelsGreen)[client];
+       pentSrcFirst = pmapSrc->green;
+       pentDstFirst = pmapDst->green;
+       oldFree = pmapSrc->freeGreen;
+       break;
+      case BLUEMAP:
+       ppix = (pmapSrc->clientPixelsBlue)[client];
+       npix = (pmapSrc->numPixelsBlue)[client];
+       pentSrcFirst = pmapSrc->blue;
+       pentDstFirst = pmapDst->blue;
+       oldFree = pmapSrc->freeBlue;
+       break;
+    }
+    nalloc = 0;
+    if (pmapSrc->class & DynamicClass)
+    {
+       for(z = npix; --z >= 0; ppix++)
+       {
+           /* Copy entries */
+           pentSrc = pentSrcFirst + *ppix;
+           pentDst = pentDstFirst + *ppix;
+           if (pentDst->refcnt > 0)
+           {
+               pentDst->refcnt++;
+           }
+           else
+           {
+               *pentDst = *pentSrc;
+               nalloc++;
+               if (pentSrc->refcnt > 0)
+                   pentDst->refcnt = 1;
+               else
+                   pentSrc->fShared = FALSE;
+           }
+           FreeCell(pmapSrc, *ppix, channel);
+       }
+    }
+
+    /* Note that FreeCell has already fixed pmapSrc->free{Color} */
+    switch(channel)
+    {
+      case REDMAP:
+        pmapDst->freeRed -= nalloc;
+        (pmapDst->clientPixelsRed)[client] =
+           (pmapSrc->clientPixelsRed)[client];
+        (pmapSrc->clientPixelsRed)[client] = (Pixel *) NULL;
+        (pmapDst->numPixelsRed)[client] = (pmapSrc->numPixelsRed)[client];
+        (pmapSrc->numPixelsRed)[client] = 0;
+       break;
+      case GREENMAP:
+        pmapDst->freeGreen -= nalloc;
+        (pmapDst->clientPixelsGreen)[client] =
+           (pmapSrc->clientPixelsGreen)[client];
+        (pmapSrc->clientPixelsGreen)[client] = (Pixel *) NULL;
+        (pmapDst->numPixelsGreen)[client] = (pmapSrc->numPixelsGreen)[client];
+        (pmapSrc->numPixelsGreen)[client] = 0;
+       break;
+      case BLUEMAP:
+        pmapDst->freeBlue -= nalloc;
+        pmapDst->clientPixelsBlue[client] = pmapSrc->clientPixelsBlue[client];
+        pmapSrc->clientPixelsBlue[client] = (Pixel *) NULL;
+        pmapDst->numPixelsBlue[client] = pmapSrc->numPixelsBlue[client];
+        pmapSrc->numPixelsBlue[client] = 0;
+       break;
+    }
+}
+
+/* Free the ith entry in a color map.  Must handle freeing of
+ * colors allocated through AllocColorPlanes */
+static void
+FreeCell (pmap, i, channel)
+    ColormapPtr pmap;
+    Pixel i;
+    int        channel;
+{
+    EntryPtr pent;
+    int        *pCount;
+
+
+    switch (channel)
+    {
+      default: /* so compiler can see that everything gets initialized */
+      case PSEUDOMAP:
+      case REDMAP:
+          pent = (EntryPtr) &pmap->red[i];
+         pCount = &pmap->freeRed;
+         break;
+      case GREENMAP:
+          pent = (EntryPtr) &pmap->green[i];
+         pCount = &pmap->freeGreen;
+         break;
+      case BLUEMAP:
+          pent = (EntryPtr) &pmap->blue[i];
+         pCount = &pmap->freeBlue;
+         break;
+    }
+    /* If it's not privately allocated and it's not time to free it, just
+     * decrement the count */
+    if (pent->refcnt > 1)
+       pent->refcnt--;
+    else
+    {
+        /* If the color type is shared, find the sharedcolor. If decremented
+         * refcnt is 0, free the shared cell. */
+        if (pent->fShared)
+       {
+           if(--pent->co.shco.red->refcnt == 0)
+               xfree(pent->co.shco.red);
+           if(--pent->co.shco.green->refcnt == 0)
+               xfree(pent->co.shco.green);
+           if(--pent->co.shco.blue->refcnt == 0)
+               xfree(pent->co.shco.blue);
+           pent->fShared = FALSE;
+       }
+       pent->refcnt = 0;
+       *pCount += 1;
+    }
+}
+
+static void
+UpdateColors (pmap)
+    ColormapPtr        pmap;
+{
+    xColorItem         *defs;
+    register xColorItem *pdef;
+    register EntryPtr  pent;
+    register VisualPtr pVisual;
+    int                        i, n, size;
+
+    pVisual = pmap->pVisual;
+    size = pVisual->ColormapEntries;
+    defs = (xColorItem *)ALLOCATE_LOCAL(size * sizeof(xColorItem));
+    if (!defs)
+       return;
+    n = 0;
+    pdef = defs;
+    if (pmap->class == DirectColor)
+    {
+        for (i = 0; i < size; i++)
+       {
+           if (!pmap->red[i].refcnt &&
+               !pmap->green[i].refcnt &&
+               !pmap->blue[i].refcnt)
+               continue;
+           pdef->pixel = ((Pixel)i << pVisual->offsetRed) |
+                         ((Pixel)i << pVisual->offsetGreen) |
+                         ((Pixel)i << pVisual->offsetBlue);
+           pdef->red = pmap->red[i].co.local.red;
+           pdef->green = pmap->green[i].co.local.green;
+           pdef->blue = pmap->blue[i].co.local.blue;
+           pdef->flags = DoRed|DoGreen|DoBlue;
+           pdef++;
+           n++;
+       }
+    }
+    else
+    {
+        for (i = 0, pent = pmap->red; i < size; i++, pent++)
+       {
+           if (!pent->refcnt)
+               continue;
+           pdef->pixel = i;
+           if(pent->fShared)
+           {
+               pdef->red = pent->co.shco.red->color;
+               pdef->green = pent->co.shco.green->color;
+               pdef->blue = pent->co.shco.blue->color;
+           }
+           else
+           {
+               pdef->red = pent->co.local.red;
+               pdef->green = pent->co.local.green;
+               pdef->blue = pent->co.local.blue;
+           }
+           pdef->flags = DoRed|DoGreen|DoBlue;
+           pdef++;
+           n++;
+       }
+    }
+    if (n)
+       (*pmap->pScreen->StoreColors)(pmap, n, defs);
+    DEALLOCATE_LOCAL(defs);
+}
+
+/* Get a read-only color from a ColorMap (probably slow for large maps)
+ * Returns by changing the value in pred, pgreen, pblue and pPix
+ */
+int
+AllocColor (pmap, pred, pgreen, pblue, pPix, client)
+    ColormapPtr                pmap;
+    unsigned short     *pred, *pgreen, *pblue;
+    Pixel              *pPix;
+    int                        client;
+{
+    Pixel      pixR, pixG, pixB;
+    int                entries;
+    xrgb       rgb;
+    int                class;
+    VisualPtr  pVisual;
+    int                npix;
+    Pixel      *ppix;
+
+    pVisual = pmap->pVisual;
+    (*pmap->pScreen->ResolveColor) (pred, pgreen, pblue, pVisual);
+    rgb.red = *pred;
+    rgb.green = *pgreen;
+    rgb.blue = *pblue;
+    class = pmap->class;
+    entries = pVisual->ColormapEntries;
+
+    /* If the colormap is being created, then we want to be able to change
+     * the colormap, even if it's a static type. Otherwise, we'd never be
+     * able to initialize static colormaps
+     */
+    if(pmap->flags & BeingCreated)
+       class |= DynamicClass;
+
+    /* If this is one of the static storage classes, and we're not initializing
+     * it, the best we can do is to find the closest color entry to the
+     * requested one and return that.
+     */
+    switch (class) {
+    case StaticColor:
+    case StaticGray:
+       /* Look up all three components in the same pmap */
+       *pPix = pixR = FindBestPixel(pmap->red, entries, &rgb, PSEUDOMAP);
+       *pred = pmap->red[pixR].co.local.red;
+       *pgreen = pmap->red[pixR].co.local.green;
+       *pblue = pmap->red[pixR].co.local.blue;
+       npix = pmap->numPixelsRed[client];
+       ppix = (Pixel *) xrealloc(pmap->clientPixelsRed[client],
+                                 (npix + 1) * sizeof(Pixel));
+       if (!ppix)
+           return (BadAlloc);
+       ppix[npix] = pixR;
+       pmap->clientPixelsRed[client] = ppix;
+       pmap->numPixelsRed[client]++;
+       break;
+
+    case TrueColor:
+       /* Look up each component in its own map, then OR them together */
+       pixR = FindBestPixel(pmap->red, NUMRED(pVisual), &rgb, REDMAP);
+       pixG = FindBestPixel(pmap->green, NUMGREEN(pVisual), &rgb, GREENMAP);
+       pixB = FindBestPixel(pmap->blue, NUMBLUE(pVisual), &rgb, BLUEMAP);
+       *pPix = (pixR << pVisual->offsetRed) |
+               (pixG << pVisual->offsetGreen) |
+               (pixB << pVisual->offsetBlue);
+       *pred = pmap->red[pixR].co.local.red;
+       *pgreen = pmap->green[pixG].co.local.green;
+       *pblue = pmap->blue[pixB].co.local.blue;
+       npix = pmap->numPixelsRed[client];
+       ppix = (Pixel *) xrealloc(pmap->clientPixelsRed[client],
+                                 (npix + 1) * sizeof(Pixel));
+       if (!ppix)
+           return (BadAlloc);
+       ppix[npix] = pixR;
+       pmap->clientPixelsRed[client] = ppix;
+       npix = pmap->numPixelsGreen[client];
+       ppix = (Pixel *) xrealloc(pmap->clientPixelsGreen[client],
+                                 (npix + 1) * sizeof(Pixel));
+       if (!ppix)
+           return (BadAlloc);
+       ppix[npix] = pixG;
+       pmap->clientPixelsGreen[client] = ppix;
+       npix = pmap->numPixelsBlue[client];
+       ppix = (Pixel *) xrealloc(pmap->clientPixelsBlue[client],
+                                 (npix + 1) * sizeof(Pixel));
+       if (!ppix)
+           return (BadAlloc);
+       ppix[npix] = pixB;
+       pmap->clientPixelsBlue[client] = ppix;
+       pmap->numPixelsRed[client]++;
+       pmap->numPixelsGreen[client]++;
+       pmap->numPixelsBlue[client]++;
+       break;
+
+    case GrayScale:
+    case PseudoColor:
+       if (FindColor(pmap, pmap->red, entries, &rgb, pPix, PSEUDOMAP,
+                     client, AllComp) != Success)
+           return (BadAlloc);
+        break;
+
+    case DirectColor:
+       pixR = (*pPix & pVisual->redMask) >> pVisual->offsetRed; 
+       if (FindColor(pmap, pmap->red, NUMRED(pVisual), &rgb, &pixR, REDMAP,
+                     client, RedComp) != Success)
+           return (BadAlloc);
+       pixG = (*pPix & pVisual->greenMask) >> pVisual->offsetGreen; 
+       if (FindColor(pmap, pmap->green, NUMGREEN(pVisual), &rgb, &pixG,
+                     GREENMAP, client, GreenComp) != Success)
+       {
+           (void)FreeCo(pmap, client, REDMAP, 1, &pixR, (Pixel)0);
+           return (BadAlloc);
+       }
+       pixB = (*pPix & pVisual->blueMask) >> pVisual->offsetBlue; 
+       if (FindColor(pmap, pmap->blue, NUMBLUE(pVisual), &rgb, &pixB, BLUEMAP,
+                     client, BlueComp) != Success)
+       {
+           (void)FreeCo(pmap, client, GREENMAP, 1, &pixG, (Pixel)0);
+           (void)FreeCo(pmap, client, REDMAP, 1, &pixR, (Pixel)0);
+           return (BadAlloc);
+       }
+       *pPix = pixR | pixG | pixB;
+       break;
+    }
+
+    /* if this is the client's first pixel in this colormap, tell the
+     * resource manager that the client has pixels in this colormap which
+     * should be freed when the client dies */
+    if ((pmap->numPixelsRed[client] == 1) &&
+       (CLIENT_ID(pmap->mid) != client) &&
+       !(pmap->flags & BeingCreated))
+    {
+       colorResource   *pcr;
+
+       pcr = (colorResource *) xalloc(sizeof(colorResource));
+       if (!pcr)
+       {
+           (void)FreeColors(pmap, client, 1, pPix, (Pixel)0);
+           return (BadAlloc);
+       }
+       pcr->mid = pmap->mid;
+       pcr->client = client;
+       if (!AddResource(FakeClientID(client), RT_CMAPENTRY, (pointer)pcr))
+           return (BadAlloc);
+    }
+    return (Success);
+}
+
+/*
+ * FakeAllocColor -- fake an AllocColor request by
+ * returning a free pixel if availible, otherwise returning
+ * the closest matching pixel.  This is used by the mi
+ * software sprite code to recolor cursors.  A nice side-effect
+ * is that this routine will never return failure.
+ */
+
+void
+FakeAllocColor (pmap, item)
+    register ColormapPtr pmap;
+    register xColorItem  *item;
+{
+    Pixel      pixR, pixG, pixB;
+    Pixel      temp;
+    int                entries;
+    xrgb       rgb;
+    int                class;
+    register VisualPtr pVisual;
+
+    pVisual = pmap->pVisual;
+    rgb.red = item->red;
+    rgb.green = item->green;
+    rgb.blue = item->blue;
+    (*pmap->pScreen->ResolveColor) (&rgb.red, &rgb.green, &rgb.blue, pVisual);
+    class = pmap->class;
+    entries = pVisual->ColormapEntries;
+
+    switch (class) {
+    case GrayScale:
+    case PseudoColor:
+       item->pixel = 0;
+       if (FindColor(pmap, pmap->red, entries, &rgb, &temp, PSEUDOMAP,
+                     -1, AllComp) == Success) {
+           item->pixel = temp;
+           break;
+       }
+       /* fall through ... */
+    case StaticColor:
+    case StaticGray:
+       item->pixel = FindBestPixel(pmap->red, entries, &rgb, PSEUDOMAP);
+       break;
+
+    case DirectColor:
+       /* Look up each component in its own map, then OR them together */
+       pixR = (item->pixel & pVisual->redMask) >> pVisual->offsetRed; 
+       pixG = (item->pixel & pVisual->greenMask) >> pVisual->offsetGreen; 
+       pixB = (item->pixel & pVisual->blueMask) >> pVisual->offsetBlue; 
+       if (FindColor(pmap, pmap->red, NUMRED(pVisual), &rgb, &pixR, REDMAP,
+                     -1, RedComp) != Success)
+           pixR = FindBestPixel(pmap->red, NUMRED(pVisual), &rgb, REDMAP)
+                       << pVisual->offsetRed;
+       if (FindColor(pmap, pmap->green, NUMGREEN(pVisual), &rgb, &pixG,
+                     GREENMAP, -1, GreenComp) != Success)
+           pixG = FindBestPixel(pmap->green, NUMGREEN(pVisual), &rgb,
+                                GREENMAP) << pVisual->offsetGreen;
+       if (FindColor(pmap, pmap->blue, NUMBLUE(pVisual), &rgb, &pixB, BLUEMAP,
+                     -1, BlueComp) != Success)
+           pixB = FindBestPixel(pmap->blue, NUMBLUE(pVisual), &rgb, BLUEMAP)
+                       << pVisual->offsetBlue;
+       item->pixel = pixR | pixG | pixB;
+       break;
+
+    case TrueColor:
+       /* Look up each component in its own map, then OR them together */
+       pixR = FindBestPixel(pmap->red, NUMRED(pVisual), &rgb, REDMAP);
+       pixG = FindBestPixel(pmap->green, NUMGREEN(pVisual), &rgb, GREENMAP);
+       pixB = FindBestPixel(pmap->blue, NUMBLUE(pVisual), &rgb, BLUEMAP);
+       item->pixel = (pixR << pVisual->offsetRed) |
+                     (pixG << pVisual->offsetGreen) |
+                     (pixB << pVisual->offsetBlue);
+       break;
+    }
+}
+
+/* free a pixel value obtained from FakeAllocColor */
+void
+FakeFreeColor(pmap, pixel)
+    register ColormapPtr pmap;
+    Pixel pixel;
+{
+    register VisualPtr pVisual;
+    Pixel pixR, pixG, pixB;
+
+    switch (pmap->class) {
+    case GrayScale:
+    case PseudoColor:
+       if (pmap->red[pixel].refcnt == AllocTemporary)
+           pmap->red[pixel].refcnt = 0;
+       break;
+    case DirectColor:
+       pVisual = pmap->pVisual;
+       pixR = (pixel & pVisual->redMask) >> pVisual->offsetRed; 
+       pixG = (pixel & pVisual->greenMask) >> pVisual->offsetGreen; 
+       pixB = (pixel & pVisual->blueMask) >> pVisual->offsetBlue; 
+       if (pmap->red[pixR].refcnt == AllocTemporary)
+           pmap->red[pixR].refcnt = 0;
+       if (pmap->green[pixG].refcnt == AllocTemporary)
+           pmap->green[pixG].refcnt = 0;
+       if (pmap->blue[pixB].refcnt == AllocTemporary)
+           pmap->blue[pixB].refcnt = 0;
+       break;
+    }
+}
+
+typedef unsigned short BigNumUpper;
+typedef unsigned long  BigNumLower;
+
+#define BIGNUMLOWERBITS        24
+#define BIGNUMUPPERBITS        16
+#define BIGNUMLOWER (1 << BIGNUMLOWERBITS)
+#define BIGNUMUPPER (1 << BIGNUMUPPERBITS)
+#define UPPERPART(i)   ((i) >> BIGNUMLOWERBITS)
+#define LOWERPART(i)   ((i) & (BIGNUMLOWER - 1))
+
+typedef struct _bignum {
+    BigNumUpper        upper;
+    BigNumLower        lower;
+} BigNumRec, *BigNumPtr;
+
+#define BigNumGreater(x,y) (((x)->upper > (y)->upper) ||\
+                           ((x)->upper == (y)->upper && (x)->lower > (y)->lower))
+
+#define UnsignedToBigNum(u,r)  (((r)->upper = UPPERPART(u)), \
+                                ((r)->lower = LOWERPART(u)))
+
+#define MaxBigNum(r)           (((r)->upper = BIGNUMUPPER-1), \
+                                ((r)->lower = BIGNUMLOWER-1))
+
+static void
+#if NeedFunctionPrototypes
+BigNumAdd (BigNumPtr x, BigNumPtr y, BigNumPtr r)
+#else
+BigNumAdd (x, y, r)
+    BigNumPtr  x, y, r;
+#endif
+{
+    BigNumLower        lower, carry = 0;
+
+    lower = x->lower + y->lower;
+    if (lower >= BIGNUMLOWER) {
+       lower -= BIGNUMLOWER;
+       carry = 1;
+    }
+    r->lower = lower;
+    r->upper = x->upper + y->upper + carry;
+}
+
+static Pixel
+FindBestPixel(pentFirst, size, prgb, channel)
+    EntryPtr   pentFirst;
+    int                size;
+    xrgb       *prgb;
+    int                channel;
+{
+    EntryPtr   pent;
+    Pixel      pixel, final;
+    long       dr, dg, db;
+    unsigned long   sq;
+    BigNumRec  minval, sum, temp;
+
+    final = 0;
+    MaxBigNum(&minval);
+    /* look for the minimal difference */
+    for (pent = pentFirst, pixel = 0; pixel < size; pent++, pixel++)
+    {
+       dr = dg = db = 0;
+       switch(channel)
+       {
+         case PSEUDOMAP:
+             dg = pent->co.local.green - prgb->green;
+             db = pent->co.local.blue - prgb->blue;
+         case REDMAP:
+             dr = pent->co.local.red - prgb->red;
+             break;
+         case GREENMAP:
+             dg = pent->co.local.green - prgb->green;
+             break;
+         case BLUEMAP:
+             db = pent->co.local.blue - prgb->blue;
+             break;
+       }
+       sq = dr * dr;
+       UnsignedToBigNum (sq, &sum);
+       sq = dg * dg;
+       UnsignedToBigNum (sq, &temp);
+       BigNumAdd (&sum, &temp, &sum);
+       sq = db * db;
+       UnsignedToBigNum (sq, &temp);
+       BigNumAdd (&sum, &temp, &sum);
+       if (BigNumGreater (&minval, &sum))
+       {
+           final = pixel;
+           minval = sum;
+       }
+    }
+    return(final);
+}
+
+/* Tries to find a color in pmap that exactly matches the one requested in prgb
+ * if it can't it allocates one.
+ * Starts looking at pentFirst + *pPixel, so if you want a specific pixel,
+ * load *pPixel with that value, otherwise set it to 0
+ */
+int
+FindColor (pmap, pentFirst, size, prgb, pPixel, channel, client, comp)
+    ColormapPtr        pmap;
+    EntryPtr   pentFirst;
+    int                size;
+    xrgb       *prgb;
+    Pixel      *pPixel;
+    int                channel;
+    int                client;
+    ColorCompareProcPtr comp;
+{
+    EntryPtr   pent;
+    Bool       foundFree;
+    Pixel      pixel, Free;
+    int                npix, count, *nump;
+    Pixel      **pixp, *ppix;
+    xColorItem def;
+
+    foundFree = FALSE;
+
+    if((pixel = *pPixel) >= size)
+       pixel = 0;
+    /* see if there is a match, and also look for a free entry */
+    for (pent = pentFirst + pixel, count = size; --count >= 0; )
+    {
+        if (pent->refcnt > 0)
+       {
+           if ((*comp) (pent, prgb))
+           {
+               if (client >= 0)
+                   pent->refcnt++;
+               *pPixel = pixel;
+               switch(channel)
+               {
+                 case REDMAP:
+                   *pPixel <<= pmap->pVisual->offsetRed;
+                 case PSEUDOMAP:
+                   break;
+                 case GREENMAP:
+                   *pPixel <<= pmap->pVisual->offsetGreen;
+                   break;
+                 case BLUEMAP:
+                   *pPixel <<= pmap->pVisual->offsetBlue;
+                   break;
+               }
+               goto gotit;
+           }
+        }
+       else if (!foundFree && pent->refcnt == 0)
+       {
+           Free = pixel;
+           foundFree = TRUE;
+           /* If we're initializing the colormap, then we are looking for
+            * the first free cell we can find, not to minimize the number
+            * of entries we use.  So don't look any further. */
+           if(pmap->flags & BeingCreated)
+               break;
+       }
+       pixel++;
+       if(pixel >= size)
+       {
+           pent = pentFirst;
+           pixel = 0;
+       }
+       else
+           pent++;
+    }
+
+    /* If we got here, we didn't find a match.  If we also didn't find
+     * a free entry, we're out of luck.  Otherwise, we'll usurp a free
+     * entry and fill it in */
+    if (!foundFree)
+       return (BadAlloc);
+    pent = pentFirst + Free;
+    pent->fShared = FALSE;
+    pent->refcnt = (client >= 0) ? 1 : AllocTemporary;
+
+    switch (channel)
+    {
+      case PSEUDOMAP:
+        pent->co.local.red = prgb->red;
+        pent->co.local.green = prgb->green;
+        pent->co.local.blue = prgb->blue;
+        def.red = prgb->red;
+       def.green = prgb->green;
+       def.blue = prgb->blue;
+       def.flags = (DoRed|DoGreen|DoBlue);
+       if (client >= 0)
+           pmap->freeRed--;
+       def.pixel = Free;
+       break;
+
+      case REDMAP:
+        pent->co.local.red = prgb->red;
+        def.red = prgb->red;
+       def.green = pmap->green[0].co.local.green;
+       def.blue = pmap->blue[0].co.local.blue;
+       def.flags = DoRed;
+       if (client >= 0)
+           pmap->freeRed--;
+       def.pixel = Free << pmap->pVisual->offsetRed;
+       break;
+
+      case GREENMAP:
+       pent->co.local.green = prgb->green;
+       def.red = pmap->red[0].co.local.red;
+        def.green = prgb->green;
+       def.blue = pmap->blue[0].co.local.blue;
+       def.flags = DoGreen;
+       if (client >= 0)
+           pmap->freeGreen--;
+       def.pixel = Free << pmap->pVisual->offsetGreen;
+       break;
+
+      case BLUEMAP:
+       pent->co.local.blue = prgb->blue;
+       def.red = pmap->red[0].co.local.red;
+       def.green = pmap->green[0].co.local.green;
+       def.blue = prgb->blue;
+       def.flags = DoBlue;
+       if (client >= 0)
+           pmap->freeBlue--;
+       def.pixel = Free << pmap->pVisual->offsetBlue;
+       break;
+    }
+    (*pmap->pScreen->StoreColors) (pmap, 1, &def);
+    pixel = Free;      
+    *pPixel = def.pixel;
+
+gotit:
+    if (pmap->flags & BeingCreated || client == -1)
+       return(Success);
+    /* Now remember the pixel, for freeing later */
+    switch (channel)
+    {
+      case PSEUDOMAP:
+      case REDMAP:
+       nump = pmap->numPixelsRed;
+       pixp = pmap->clientPixelsRed;
+       break;
+
+      case GREENMAP:
+       nump = pmap->numPixelsGreen;
+       pixp = pmap->clientPixelsGreen;
+       break;
+
+      case BLUEMAP:
+       nump = pmap->numPixelsBlue;
+       pixp = pmap->clientPixelsBlue;
+       break;
+    }
+    npix = nump[client];
+    ppix = (Pixel *) xrealloc (pixp[client], (npix + 1) * sizeof(Pixel));
+    if (!ppix)
+    {
+       pent->refcnt--;
+       if (!pent->fShared)
+           switch (channel)
+           {
+             case PSEUDOMAP:
+             case REDMAP:
+               pmap->freeRed++;
+               break;
+             case GREENMAP:
+               pmap->freeGreen++;
+               break;
+             case BLUEMAP:
+               pmap->freeBlue++;
+               break;
+           }
+       return(BadAlloc);
+    }
+    ppix[npix] = pixel;
+    pixp[client] = ppix;
+    nump[client]++;
+
+    return(Success);
+}
+
+/* Comparison functions -- passed to FindColor to determine if an
+ * entry is already the color we're looking for or not */
+static int
+AllComp (pent, prgb)
+    EntryPtr   pent;
+    xrgb       *prgb;
+{
+    if((pent->co.local.red == prgb->red) &&
+       (pent->co.local.green == prgb->green) &&
+       (pent->co.local.blue == prgb->blue) )
+       return (1);
+    return (0);
+}
+
+static int
+RedComp (pent, prgb)
+    EntryPtr   pent;
+    xrgb       *prgb;
+{
+    if (pent->co.local.red == prgb->red) 
+       return (1);
+    return (0);
+}
+
+static int
+GreenComp (pent, prgb)
+    EntryPtr   pent;
+    xrgb       *prgb;
+{
+    if (pent->co.local.green == prgb->green) 
+       return (1);
+    return (0);
+}
+
+static int
+BlueComp (pent, prgb)
+    EntryPtr   pent;
+    xrgb       *prgb;
+{
+    if (pent->co.local.blue == prgb->blue) 
+       return (1);
+    return (0);
+}
+
+
+/* Read the color value of a cell */
+
+int
+QueryColors (pmap, count, ppixIn, prgbList)
+    ColormapPtr        pmap;
+    int                count;
+    Pixel      *ppixIn;
+    xrgb       *prgbList;
+{
+    Pixel      *ppix, pixel;
+    xrgb       *prgb;
+    VisualPtr  pVisual;
+    EntryPtr   pent;
+    Pixel      i;
+    int                errVal = Success;
+
+    pVisual = pmap->pVisual;
+    if ((pmap->class | DynamicClass) == DirectColor)
+    {
+       int numred, numgreen, numblue;
+       Pixel rgbbad;
+
+       numred = NUMRED(pVisual);
+       numgreen = NUMGREEN(pVisual);
+       numblue = NUMBLUE(pVisual);
+       rgbbad = ~RGBMASK(pVisual);
+       for( ppix = ppixIn, prgb = prgbList; --count >= 0; ppix++, prgb++)
+       {
+           pixel = *ppix;
+           if (pixel & rgbbad) {
+               clientErrorValue = pixel;
+               errVal =  BadValue;
+               continue;
+           }
+           i  = (pixel & pVisual->redMask) >> pVisual->offsetRed;
+           if (i >= numred)
+           {
+               clientErrorValue = pixel;
+               errVal =  BadValue;
+               continue;
+           }
+           prgb->red = pmap->red[i].co.local.red;
+           i  = (pixel & pVisual->greenMask) >> pVisual->offsetGreen;
+           if (i >= numgreen)
+           {
+               clientErrorValue = pixel;
+               errVal =  BadValue;
+               continue;
+           }
+           prgb->green = pmap->green[i].co.local.green;
+           i  = (pixel & pVisual->blueMask) >> pVisual->offsetBlue;
+           if (i >= numblue)
+           {
+               clientErrorValue = pixel;
+               errVal =  BadValue;
+               continue;
+           }
+           prgb->blue = pmap->blue[i].co.local.blue;
+       }
+    }
+    else
+    {
+       for( ppix = ppixIn, prgb = prgbList; --count >= 0; ppix++, prgb++)
+       {
+           pixel = *ppix;
+           if (pixel >= pVisual->ColormapEntries)
+           {
+               clientErrorValue = pixel;
+               errVal = BadValue;
+           }
+           else
+           {
+               pent = (EntryPtr)&pmap->red[pixel];
+               if (pent->fShared)
+               {
+                   prgb->red = pent->co.shco.red->color;
+                   prgb->green = pent->co.shco.green->color;
+                   prgb->blue = pent->co.shco.blue->color;
+               }
+               else
+               {
+                   prgb->red = pent->co.local.red;
+                   prgb->green = pent->co.local.green;
+                   prgb->blue = pent->co.local.blue;
+               }
+           }
+       }
+    }
+    return (errVal);
+}
+
+static void
+FreePixels(pmap, client)
+    register ColormapPtr       pmap;
+    register int               client;
+{
+    register Pixel             *ppix, *ppixStart;
+    register int               n;
+    int                                class;
+#ifdef LBX
+    Bool                       grabbed;
+    Bool                       zeroRefCount;
+    Bool                       anyRefCountReachedZero = 0;
+#endif
+
+    class = pmap->class;
+    ppixStart = pmap->clientPixelsRed[client];
+    if (class & DynamicClass)
+    {
+       n = pmap->numPixelsRed[client];
+#ifdef LBX
+       grabbed = LbxCheckCmapGrabbed (pmap);
+       if (grabbed)
+       {
+           /*
+            * If the colormap is grabbed by a proxy, the server must
+            * notify the proxy of all cells that are freed (the refcount
+            * has reached zero on these cells).
+            */
+
+           LbxBeginFreeCellsEvent (pmap);
+           LbxSortPixelList (ppixStart, n);
+       }
+#endif
+       for (ppix = ppixStart; --n >= 0; )
+       {
+           FreeCell(pmap, *ppix, REDMAP);
+#ifdef LBX
+           /*
+            * Only PSEUDO colormaps are grabbed by LBX proxies.
+            * Check if the ref count reached zero on this pixel.
+            */
+
+           zeroRefCount = pmap->red[*ppix].refcnt == 0;
+           if (zeroRefCount)
+               anyRefCountReachedZero = 1;
+           
+           if (grabbed && zeroRefCount)
+               LbxAddFreeCellToEvent (pmap, *ppix);
+#endif
+           ppix++;
+       }
+#ifdef LBX
+       if (grabbed)
+           LbxEndFreeCellsEvent (pmap);
+       else if (anyRefCountReachedZero)
+       {
+           /*
+            * We only send LbxFreeCell events to a proxy that has the colormap
+            * grabbed.  If the colormap is not grabbed, the proxy that last
+            * had the colormap grabbed will not be able to do a smart grab
+            * in the future.  A smart grab can only occur if the proxy is kept
+            * up to date on every alloc/free change in the colormap.
+            */
+
+           LbxDisableSmartGrab (pmap);
+       }
+#endif
+    }
+
+    xfree(ppixStart);
+    pmap->clientPixelsRed[client] = (Pixel *) NULL;
+    pmap->numPixelsRed[client] = 0;
+    if ((class | DynamicClass) == DirectColor) 
+    {
+        ppixStart = pmap->clientPixelsGreen[client];
+       if (class & DynamicClass)
+           for (ppix = ppixStart, n = pmap->numPixelsGreen[client]; --n >= 0;)
+               FreeCell(pmap, *ppix++, GREENMAP);
+       xfree(ppixStart);
+       pmap->clientPixelsGreen[client] = (Pixel *) NULL;
+       pmap->numPixelsGreen[client] = 0;
+
+        ppixStart = pmap->clientPixelsBlue[client];
+       if (class & DynamicClass)
+           for (ppix = ppixStart, n = pmap->numPixelsBlue[client]; --n >= 0; )
+               FreeCell(pmap, *ppix++, BLUEMAP);
+       xfree(ppixStart);
+       pmap->clientPixelsBlue[client] = (Pixel *) NULL;
+       pmap->numPixelsBlue[client] = 0;
+    }
+}
+
+/* Free all of a client's colors and cells */
+/*ARGSUSED*/
+int
+FreeClientPixels (value, fakeid)
+    pointer value;  /* must conform to DeleteType */
+    XID        fakeid;
+{
+    ColormapPtr pmap;
+    colorResource *pcr = (colorResource *)value;
+
+    pmap = (ColormapPtr) LookupIDByType(pcr->mid, RT_COLORMAP);
+    if (pmap)
+       FreePixels(pmap, pcr->client);
+    xfree(pcr);
+    return Success;
+}
+
+int
+AllocColorCells (client, pmap, colors, planes, contig, ppix, masks)
+    int                client;
+    ColormapPtr        pmap;
+    int                colors, planes;
+    Bool       contig;
+    Pixel      *ppix;
+    Pixel      *masks;
+{
+    Pixel      rmask, gmask, bmask, *ppixFirst, r, g, b;
+    int                n, class;
+    int                ok;
+    int                oldcount;
+    colorResource *pcr = (colorResource *)NULL;
+
+    class = pmap->class;
+    if (!(class & DynamicClass))
+       return (BadAlloc); /* Shouldn't try on this type */
+    oldcount = pmap->numPixelsRed[client];
+    if (pmap->class == DirectColor)
+       oldcount += pmap->numPixelsGreen[client] + pmap->numPixelsBlue[client];
+    if (!oldcount && (CLIENT_ID(pmap->mid) != client))
+    {
+       pcr = (colorResource *) xalloc(sizeof(colorResource));
+       if (!pcr)
+           return (BadAlloc);
+    }
+
+    if (pmap->class == DirectColor)
+    {
+        ok = AllocDirect (client, pmap, colors, planes, planes, planes,
+                         contig, ppix, &rmask, &gmask, &bmask);
+       if(ok == Success)
+       {
+           for (r = g = b = 1, n = planes; --n >= 0; r += r, g += g, b += b)
+           {
+               while(!(rmask & r))
+                   r += r;
+               while(!(gmask & g))
+                   g += g;
+               while(!(bmask & b))
+                   b += b;
+               *masks++ = r | g | b;
+           }
+       }
+    }
+    else
+    {
+        ok = AllocPseudo (client, pmap, colors, planes, contig, ppix, &rmask,
+                         &ppixFirst);
+       if(ok == Success)
+       {
+           for (r = 1, n = planes; --n >= 0; r += r)
+           {
+               while(!(rmask & r))
+                   r += r;
+               *masks++ = r;
+           }
+       }
+    }
+
+    /* if this is the client's first pixels in this colormap, tell the
+     * resource manager that the client has pixels in this colormap which
+     * should be freed when the client dies */
+    if ((ok == Success) && pcr)
+    {
+       pcr->mid = pmap->mid;
+       pcr->client = client;
+       if (!AddResource(FakeClientID(client), RT_CMAPENTRY, (pointer)pcr))
+           ok = BadAlloc;
+    } else if (pcr)
+       xfree(pcr);
+
+    return (ok);
+}
+
+
+int
+AllocColorPlanes (client, pmap, colors, r, g, b, contig, pixels,
+                 prmask, pgmask, pbmask)
+    int                client;
+    ColormapPtr        pmap;
+    int                colors, r, g, b;
+    Bool       contig;
+    Pixel      *pixels;
+    Pixel      *prmask, *pgmask, *pbmask;
+{
+    int                ok;
+    Pixel      mask, *ppixFirst;
+    register Pixel shift;
+    register int i;
+    int                class;
+    int                oldcount;
+    colorResource *pcr = (colorResource *)NULL;
+
+    class = pmap->class;
+    if (!(class & DynamicClass))
+       return (BadAlloc); /* Shouldn't try on this type */
+    oldcount = pmap->numPixelsRed[client];
+    if (class == DirectColor)
+       oldcount += pmap->numPixelsGreen[client] + pmap->numPixelsBlue[client];
+    if (!oldcount && (CLIENT_ID(pmap->mid) != client))
+    {
+       pcr = (colorResource *) xalloc(sizeof(colorResource));
+       if (!pcr)
+           return (BadAlloc);
+    }
+
+    if (class == DirectColor)
+    {
+        ok = AllocDirect (client, pmap, colors, r, g, b, contig, pixels,
+                         prmask, pgmask, pbmask);
+    }
+    else
+    {
+       /* Allocate the proper pixels */
+       /* XXX This is sort of bad, because of contig is set, we force all
+        * r + g + b bits to be contiguous.  Should only force contiguity
+        * per mask 
+        */
+        ok = AllocPseudo (client, pmap, colors, r + g + b, contig, pixels,
+                         &mask, &ppixFirst);
+
+       if(ok == Success)
+       {
+           /* now split that mask into three */
+           *prmask = *pgmask = *pbmask = 0;
+           shift = 1;
+           for (i = r; --i >= 0; shift += shift)
+           {
+               while (!(mask & shift))
+                   shift += shift;
+               *prmask |= shift;
+           }
+           for (i = g; --i >= 0; shift += shift)
+           {
+               while (!(mask & shift))
+                   shift += shift;
+               *pgmask |= shift;
+           }
+           for (i = b; --i >= 0; shift += shift)
+           {
+               while (!(mask & shift))
+                   shift += shift;
+               *pbmask |= shift;
+           }
+
+           /* set up the shared color cells */
+           if (!AllocShared(pmap, pixels, colors, r, g, b,
+                            *prmask, *pgmask, *pbmask, ppixFirst))
+           {
+               (void)FreeColors(pmap, client, colors, pixels, mask);
+               ok = BadAlloc;
+           }
+       }
+    }
+
+    /* if this is the client's first pixels in this colormap, tell the
+     * resource manager that the client has pixels in this colormap which
+     * should be freed when the client dies */
+    if ((ok == Success) && pcr)
+    {
+       pcr->mid = pmap->mid;
+       pcr->client = client;
+       if (!AddResource(FakeClientID(client), RT_CMAPENTRY, (pointer)pcr))
+           ok = BadAlloc;
+    } else if (pcr)
+       xfree(pcr);
+
+    return (ok);
+}
+
+static int
+AllocDirect (client, pmap, c, r, g, b, contig, pixels, prmask, pgmask, pbmask)
+    int                client;
+    ColormapPtr        pmap;
+    int                c, r, g, b;
+    Bool       contig;
+    Pixel      *pixels;
+    Pixel      *prmask, *pgmask, *pbmask;
+{
+    Pixel      *ppixRed, *ppixGreen, *ppixBlue;
+    Pixel      *ppix, *pDst, *p;
+    int                npix, npixR, npixG, npixB;
+    Bool       okR, okG, okB;
+    Pixel      *rpix = 0, *gpix = 0, *bpix = 0;
+
+    npixR = c << r;
+    npixG = c << g;
+    npixB = c << b;
+    if ((r >= 32) || (g >= 32) || (b >= 32) ||
+       (npixR > pmap->freeRed) || (npixR < c) ||
+       (npixG > pmap->freeGreen) || (npixG < c) ||
+       (npixB > pmap->freeBlue) || (npixB < c))
+       return BadAlloc;
+
+    /* start out with empty pixels */
+    for(p = pixels; p < pixels + c; p++)
+       *p = 0;
+
+    ppixRed = (Pixel *)ALLOCATE_LOCAL(npixR * sizeof(Pixel));
+    ppixGreen = (Pixel *)ALLOCATE_LOCAL(npixG * sizeof(Pixel));
+    ppixBlue = (Pixel *)ALLOCATE_LOCAL(npixB * sizeof(Pixel));
+    if (!ppixRed || !ppixGreen || !ppixBlue)
+    {
+       if (ppixBlue) DEALLOCATE_LOCAL(ppixBlue);
+       if (ppixGreen) DEALLOCATE_LOCAL(ppixGreen);
+       if (ppixRed) DEALLOCATE_LOCAL(ppixRed);
+       return(BadAlloc);
+    }
+
+    okR = AllocCP(pmap, pmap->red, c, r, contig, ppixRed, prmask);
+    okG = AllocCP(pmap, pmap->green, c, g, contig, ppixGreen, pgmask);
+    okB = AllocCP(pmap, pmap->blue, c, b, contig, ppixBlue, pbmask);
+
+    if (okR && okG && okB)
+    {
+       rpix = (Pixel *) xrealloc(pmap->clientPixelsRed[client],
+                                 (pmap->numPixelsRed[client] + (c << r)) *
+                                 sizeof(Pixel));
+       if (rpix)
+           pmap->clientPixelsRed[client] = rpix;
+       gpix = (Pixel *) xrealloc(pmap->clientPixelsGreen[client],
+                                 (pmap->numPixelsGreen[client] + (c << g)) *
+                                 sizeof(Pixel));
+       if (gpix)
+           pmap->clientPixelsGreen[client] = gpix;
+       bpix = (Pixel *) xrealloc(pmap->clientPixelsBlue[client],
+                                 (pmap->numPixelsBlue[client] + (c << b)) *
+                                 sizeof(Pixel));
+       if (bpix)
+           pmap->clientPixelsBlue[client] = bpix;
+    }
+
+    if (!okR || !okG || !okB || !rpix || !gpix || !bpix)
+    {
+       if (okR)
+           for(ppix = ppixRed, npix = npixR; --npix >= 0; ppix++)
+               pmap->red[*ppix].refcnt = 0;
+       if (okG)
+           for(ppix = ppixGreen, npix = npixG; --npix >= 0; ppix++)
+               pmap->green[*ppix].refcnt = 0;
+       if (okB)
+           for(ppix = ppixBlue, npix = npixB; --npix >= 0; ppix++)
+               pmap->blue[*ppix].refcnt = 0;
+       DEALLOCATE_LOCAL(ppixBlue);
+       DEALLOCATE_LOCAL(ppixGreen);
+       DEALLOCATE_LOCAL(ppixRed);
+       return(BadAlloc);
+    }
+
+    *prmask <<= pmap->pVisual->offsetRed;
+    *pgmask <<= pmap->pVisual->offsetGreen;
+    *pbmask <<= pmap->pVisual->offsetBlue;
+
+    ppix = rpix + pmap->numPixelsRed[client];
+    for (pDst = pixels, p = ppixRed; p < ppixRed + npixR; p++)
+    {
+       *ppix++ = *p;
+       if(p < ppixRed + c)
+           *pDst++ |= *p << pmap->pVisual->offsetRed;
+    }
+    pmap->numPixelsRed[client] += npixR;
+    pmap->freeRed -= npixR;
+
+    ppix = gpix + pmap->numPixelsGreen[client];
+    for (pDst = pixels, p = ppixGreen; p < ppixGreen + npixG; p++)
+    {
+       *ppix++ = *p;
+       if(p < ppixGreen + c)
+           *pDst++ |= *p << pmap->pVisual->offsetGreen;
+    }
+    pmap->numPixelsGreen[client] += npixG;
+    pmap->freeGreen -= npixG;
+
+    ppix = bpix + pmap->numPixelsBlue[client];
+    for (pDst = pixels, p = ppixBlue; p < ppixBlue + npixB; p++)
+    {
+       *ppix++ = *p;
+       if(p < ppixBlue + c)
+           *pDst++ |= *p << pmap->pVisual->offsetBlue;
+    }
+    pmap->numPixelsBlue[client] += npixB;
+    pmap->freeBlue -= npixB;
+
+    DEALLOCATE_LOCAL(ppixBlue);
+    DEALLOCATE_LOCAL(ppixGreen);
+    DEALLOCATE_LOCAL(ppixRed);
+
+    return (Success);
+}
+
+static int
+AllocPseudo (client, pmap, c, r, contig, pixels, pmask, pppixFirst)
+    int                client;
+    ColormapPtr        pmap;
+    int                c, r;
+    Bool       contig;
+    Pixel      *pixels;
+    Pixel      *pmask;
+    Pixel      **pppixFirst;
+{
+    Pixel      *ppix, *p, *pDst, *ppixTemp;
+    int                npix;
+    Bool       ok;
+
+    npix = c << r;
+    if ((r >= 32) || (npix > pmap->freeRed) || (npix < c))
+       return(BadAlloc);
+    if(!(ppixTemp = (Pixel *)ALLOCATE_LOCAL(npix * sizeof(Pixel))))
+       return(BadAlloc);
+    ok = AllocCP(pmap, pmap->red, c, r, contig, ppixTemp, pmask);
+
+    if (ok)
+    {
+
+       /* all the allocated pixels are added to the client pixel list,
+        * but only the unique ones are returned to the client */
+       ppix = (Pixel *)xrealloc(pmap->clientPixelsRed[client],
+                        (pmap->numPixelsRed[client] + npix) * sizeof(Pixel));
+       if (!ppix)
+       {
+           for (p = ppixTemp; p < ppixTemp + npix; p++)
+               pmap->red[*p].refcnt = 0;
+           return (BadAlloc);
+       }
+       pmap->clientPixelsRed[client] = ppix;
+       ppix += pmap->numPixelsRed[client];
+       *pppixFirst = ppix;
+       pDst = pixels;
+       for (p = ppixTemp; p < ppixTemp + npix; p++)
+       {
+           *ppix++ = *p;
+           if(p < ppixTemp + c)
+               *pDst++ = *p;
+       }
+       pmap->numPixelsRed[client] += npix;
+       pmap->freeRed -= npix;
+    }
+    DEALLOCATE_LOCAL(ppixTemp);
+    return (ok ? Success : BadAlloc);
+}
+
+/* Allocates count << planes pixels from colormap pmap for client. If
+ * contig, then the plane mask is made of consecutive bits.  Returns
+ * all count << pixels in the array pixels. The first count of those
+ * pixels are the unique pixels.  *pMask has the mask to Or with the
+ * unique pixels to get the rest of them.
+ *
+ * Returns True iff all pixels could be allocated 
+ * All cells allocated will have refcnt set to AllocPrivate and shared to FALSE
+ * (see AllocShared for why we care)
+ */
+static Bool
+AllocCP (pmap, pentFirst, count, planes, contig, pixels, pMask)
+    ColormapPtr        pmap;
+    EntryPtr   pentFirst;
+    int                count, planes;
+    Bool       contig;
+    Pixel      *pixels, *pMask;
+    
+{
+    EntryPtr   ent;
+    Pixel      pixel, base, entries, maxp, save;
+    int                dplanes, found;
+    Pixel      *ppix;
+    Pixel      mask;
+    Pixel      finalmask;
+
+    dplanes = pmap->pVisual->nplanes;
+
+    /* Easy case.  Allocate pixels only */
+    if (planes == 0)
+    {
+        /* allocate writable entries */
+       ppix = pixels;
+        ent = pentFirst;
+        pixel = 0;
+        while (--count >= 0)
+       {
+            /* Just find count unallocated cells */
+           while (ent->refcnt)
+           {
+               ent++;
+               pixel++;
+           }
+           ent->refcnt = AllocPrivate;
+           *ppix++ = pixel;
+           ent->fShared = FALSE;
+        }
+        *pMask = 0;
+        return (TRUE);
+    }
+    else if (planes > dplanes)
+    {
+       return (FALSE);
+    }
+
+    /* General case count pixels * 2 ^ planes cells to be allocated */
+
+    /* make room for new pixels */
+    ent = pentFirst;
+
+    /* first try for contiguous planes, since it's fastest */
+    for (mask = (((Pixel)1) << planes) - 1, base = 1, dplanes -= (planes - 1);
+         --dplanes >= 0;
+         mask += mask, base += base)
+    {
+        ppix = pixels;
+        found = 0;
+        pixel = 0;
+        entries = pmap->pVisual->ColormapEntries - mask;
+        while (pixel < entries)
+       {
+           save = pixel;
+           maxp = pixel + mask + base;
+           /* check if all are free */
+           while (pixel != maxp && ent[pixel].refcnt == 0)
+               pixel += base;
+           if (pixel == maxp)
+               {
+                   /* this one works */
+                   *ppix++ = save;
+                   found++;
+                   if (found == count)
+                   {
+                       /* found enough, allocate them all */
+                       while (--count >= 0)
+                       {
+                           pixel = pixels[count];
+                           maxp = pixel + mask;
+                           while (1)
+                           {
+                               ent[pixel].refcnt = AllocPrivate;
+                               ent[pixel].fShared = FALSE;
+                               if (pixel == maxp)
+                                   break;
+                               pixel += base;
+                               *ppix++ = pixel;
+                           }
+                       }
+                       *pMask = mask;
+                       return (TRUE);
+                   }
+               }
+           pixel = save + 1;
+           if (pixel & mask)
+               pixel += mask;
+        }
+    }
+
+    dplanes = pmap->pVisual->nplanes;
+    if (contig || planes == 1 || dplanes < 3)
+       return (FALSE);
+
+    /* this will be very slow for large maps, need a better algorithm */
+
+    /*
+       we can generate the smallest and largest numbers that fits in dplanes
+       bits and contain exactly planes bits set as follows. First, we need to
+       check that it is possible to generate such a mask at all.
+       (Non-contiguous masks need one more bit than contiguous masks). Then
+       the smallest such mask consists of the rightmost planes-1 bits set, then
+       a zero, then a one in position planes + 1. The formula is
+         (3 << (planes-1)) -1
+       The largest such masks consists of the leftmost planes-1 bits set, then
+       a zero, then a one bit in position dplanes-planes-1. If dplanes is
+       smaller than 32 (the number of bits in a word) then the formula is:
+         (1<<dplanes) - (1<<(dplanes-planes+1) + (1<<dplanes-planes-1)
+       If dplanes = 32, then we can't calculate (1<<dplanes) and we have
+       to use:
+         ( (1<<(planes-1)) - 1) << (dplanes-planes+1) + (1<<(dplanes-planes-1))
+         
+         << Thank you, Loretta>>>
+
+    */
+
+    finalmask =
+        (((((Pixel)1)<<(planes-1)) - 1) << (dplanes-planes+1)) +
+         (((Pixel)1)<<(dplanes-planes-1));
+    for (mask = (((Pixel)3) << (planes -1)) - 1; mask <= finalmask; mask++)
+    {
+        /* next 3 magic statements count number of ones (HAKMEM #169) */
+        pixel = (mask >> 1) & 033333333333;
+        pixel = mask - pixel - ((pixel >> 1) & 033333333333);
+        if ((((pixel + (pixel >> 3)) & 030707070707) % 077) != planes)
+           continue;
+        ppix = pixels;
+        found = 0;
+        entries = pmap->pVisual->ColormapEntries - mask;
+        base = lowbit (mask);
+        for (pixel = 0; pixel < entries; pixel++)
+       {
+           if (pixel & mask)
+               continue;
+           maxp = 0;
+           /* check if all are free */
+           while (ent[pixel + maxp].refcnt == 0)
+           {
+               GetNextBitsOrBreak(maxp, mask, base);
+           }
+           if ((maxp < mask) || (ent[pixel + mask].refcnt != 0))
+               continue;
+           /* this one works */
+           *ppix++ = pixel;
+           found++;
+           if (found < count)
+               continue;
+           /* found enough, allocate them all */
+           while (--count >= 0)
+           {
+               pixel = (pixels)[count];
+               maxp = 0;
+               while (1)
+               {
+                   ent[pixel + maxp].refcnt = AllocPrivate;
+                   ent[pixel + maxp].fShared = FALSE;
+                   GetNextBitsOrBreak(maxp, mask, base);
+                   *ppix++ = pixel + maxp;
+               }
+           }
+
+           *pMask = mask;
+           return (TRUE);
+       }
+    }
+    return (FALSE);
+}
+
+static Bool
+AllocShared (pmap, ppix, c, r, g, b, rmask, gmask, bmask, ppixFirst)
+    ColormapPtr        pmap;
+    Pixel      *ppix;
+    int                c, r, g, b;
+    Pixel      rmask, gmask, bmask;
+    Pixel      *ppixFirst;     /* First of the client's new pixels */
+{
+    Pixel      *pptr, *cptr;
+    int                npix, z, npixClientNew, npixShared;
+    Pixel      basemask, base, bits, common;
+    SHAREDCOLOR *pshared, **ppshared, **psharedList;
+
+    npixClientNew = c << (r + g + b);
+    npixShared = (c << r) + (c << g) + (c << b);
+    psharedList = (SHAREDCOLOR **)ALLOCATE_LOCAL(npixShared *
+                                                sizeof(SHAREDCOLOR *));
+    if (!psharedList)
+       return FALSE;
+    ppshared = psharedList;
+    for (z = npixShared; --z >= 0; )
+    {
+       if (!(ppshared[z] = (SHAREDCOLOR *)xalloc(sizeof(SHAREDCOLOR))))
+       {
+           for (z++ ; z < npixShared; z++)
+               xfree(ppshared[z]);
+           return FALSE;
+       }
+    }
+    for(pptr = ppix, npix = c; --npix >= 0; pptr++)
+    {
+       basemask = ~(gmask | bmask);
+       common = *pptr & basemask;
+       if (rmask)
+       {
+           bits = 0;
+           base = lowbit (rmask);
+           while(1)
+           {
+               pshared = *ppshared++;
+               pshared->refcnt = 1 << (g + b);
+               for (cptr = ppixFirst, z = npixClientNew; --z >= 0; cptr++)
+               {
+                   if ((*cptr & basemask) == (common | bits))
+                   {
+                       pmap->red[*cptr].fShared = TRUE;
+                       pmap->red[*cptr].co.shco.red = pshared;
+                   }
+               }
+               GetNextBitsOrBreak(bits, rmask, base);
+           }
+       }
+       else
+       {
+           pshared = *ppshared++;
+           pshared->refcnt = 1 << (g + b);
+           for (cptr = ppixFirst, z = npixClientNew; --z >= 0; cptr++)
+           {
+               if ((*cptr & basemask) == common)
+               {
+                   pmap->red[*cptr].fShared = TRUE;
+                   pmap->red[*cptr].co.shco.red = pshared;
+               }
+           }
+       }
+       basemask = ~(rmask | bmask);
+       common = *pptr & basemask;
+       if (gmask)
+       {
+           bits = 0;
+           base = lowbit (gmask);
+           while(1)
+           {
+               pshared = *ppshared++;
+               pshared->refcnt = 1 << (r + b);
+               for (cptr = ppixFirst, z = npixClientNew; --z >= 0; cptr++)
+               {
+                   if ((*cptr & basemask) == (common | bits))
+                   {
+                       pmap->red[*cptr].co.shco.green = pshared;
+                   }
+               }
+               GetNextBitsOrBreak(bits, gmask, base);
+           }
+       }
+       else
+       {
+           pshared = *ppshared++;
+           pshared->refcnt = 1 << (g + b);
+           for (cptr = ppixFirst, z = npixClientNew; --z >= 0; cptr++)
+           {
+               if ((*cptr & basemask) == common)
+               {
+                   pmap->red[*cptr].co.shco.green = pshared;
+               }
+           }
+       }
+       basemask = ~(rmask | gmask);
+       common = *pptr & basemask;
+       if (bmask)
+       {
+           bits = 0;
+           base = lowbit (bmask);
+           while(1)
+           {
+               pshared = *ppshared++;
+               pshared->refcnt = 1 << (r + g);
+               for (cptr = ppixFirst, z = npixClientNew; --z >= 0; cptr++)
+               {
+                   if ((*cptr & basemask) == (common | bits))
+                   {
+                       pmap->red[*cptr].co.shco.blue = pshared;
+                   }
+               }
+               GetNextBitsOrBreak(bits, bmask, base);
+           }
+       }
+       else
+       {
+           pshared = *ppshared++;
+           pshared->refcnt = 1 << (g + b);
+           for (cptr = ppixFirst, z = npixClientNew; --z >= 0; cptr++)
+           {
+               if ((*cptr & basemask) == common)
+               {
+                   pmap->red[*cptr].co.shco.blue = pshared;
+               }
+           }
+       }
+    }
+    DEALLOCATE_LOCAL(psharedList);
+    return TRUE;
+}
+
+
+/* Free colors and/or cells (probably slow for large numbers) */
+
+int
+FreeColors (pmap, client, count, pixels, mask)
+    ColormapPtr        pmap;
+    int                client, count;
+    Pixel      *pixels;
+    Pixel      mask;
+{
+    int                rval, result, class;
+    Pixel      rmask;
+
+    class = pmap->class;
+    if (pmap->flags & AllAllocated)
+       return(BadAccess);
+    if ((class | DynamicClass) == DirectColor)
+    {
+       rmask = mask & RGBMASK(pmap->pVisual);
+        result = FreeCo(pmap, client, REDMAP, count, pixels,
+                       mask & pmap->pVisual->redMask);
+       /* If any of the three calls fails, we must report that, if more
+        * than one fails, it's ok that we report the last one */
+        rval = FreeCo(pmap, client, GREENMAP, count, pixels,
+                     mask & pmap->pVisual->greenMask);
+       if(rval != Success)
+           result = rval;
+       rval = FreeCo(pmap, client, BLUEMAP, count, pixels,
+                     mask & pmap->pVisual->blueMask);
+       if(rval != Success)
+           result = rval;
+    }
+    else
+    {
+       rmask = mask & ((((Pixel)1) << pmap->pVisual->nplanes) - 1);
+        result = FreeCo(pmap, client, PSEUDOMAP, count, pixels, rmask);
+    }
+    if ((mask != rmask) && count)
+    {
+       clientErrorValue = *pixels | mask;
+       result = BadValue;
+    }
+    /* XXX should worry about removing any RT_CMAPENTRY resource */
+    return (result);
+}
+
+/* Helper for FreeColors -- frees all combinations of *newpixels and mask bits
+ * which the client has allocated in channel colormap cells of pmap.
+ * doesn't change newpixels if it doesn't need to */
+static int
+FreeCo (pmap, client, color, npixIn, ppixIn, mask)
+    ColormapPtr        pmap;           /* which colormap head */
+    int                client;         
+    int                color;          /* which sub-map, eg RED, BLUE, PSEUDO */
+    int                npixIn;         /* number of pixels passed in */
+    Pixel      *ppixIn;        /* list of base pixels */
+    Pixel      mask;           /* mask client gave us */ 
+{
+
+    Pixel      *ppixClient, pixTest;
+    int                npixClient, npixNew, npix;
+    Pixel      bits, base, cmask, rgbbad;
+    Pixel      *pptr, *cptr;
+    int        n, zapped;
+    int                errVal = Success;
+    int                offset, numents;
+#ifdef LBX
+    Bool       grabbed;
+    Bool       zeroRefCount;
+    Bool       anyRefCountReachedZero = 0;
+#endif
+
+    if (npixIn == 0)
+        return (errVal);
+    bits = 0;
+    zapped = 0;
+    base = lowbit (mask);
+
+    switch(color)
+    {
+      case REDMAP:
+       cmask = pmap->pVisual->redMask;
+       rgbbad = ~RGBMASK(pmap->pVisual);
+       offset = pmap->pVisual->offsetRed;
+       numents = (cmask >> offset) + 1;
+       ppixClient = pmap->clientPixelsRed[client];
+       npixClient = pmap->numPixelsRed[client];
+       break;
+      case GREENMAP:
+       cmask = pmap->pVisual->greenMask;
+       rgbbad = ~RGBMASK(pmap->pVisual);
+       offset = pmap->pVisual->offsetGreen;
+       numents = (cmask >> offset) + 1;
+       ppixClient = pmap->clientPixelsGreen[client];
+       npixClient = pmap->numPixelsGreen[client];
+       break;
+      case BLUEMAP:
+       cmask = pmap->pVisual->blueMask;
+       rgbbad = ~RGBMASK(pmap->pVisual);
+       offset = pmap->pVisual->offsetBlue;
+       numents = (cmask >> offset) + 1;
+       ppixClient = pmap->clientPixelsBlue[client];
+       npixClient = pmap->numPixelsBlue[client];
+       break;
+      default: /* so compiler can see that everything gets initialized */
+      case PSEUDOMAP:
+       cmask = ~((Pixel)0);
+       rgbbad = 0;
+       offset = 0;
+       numents = pmap->pVisual->ColormapEntries;
+       ppixClient = pmap->clientPixelsRed[client];
+       npixClient = pmap->numPixelsRed[client];
+       break;
+    }
+
+#ifdef LBX
+    grabbed = LbxCheckCmapGrabbed (pmap);
+
+    if (grabbed)
+    {
+       /*
+        * If the colormap is grabbed by a proxy, the server must
+        * notify the proxy of all cells that are freed (the refcount
+        * has reached zero on these cells).
+        */
+
+       LbxBeginFreeCellsEvent (pmap);
+       LbxSortPixelList (ppixIn, npixIn);
+    }
+#endif
+
+    /* zap all pixels which match */
+    while (1)
+    {
+        /* go through pixel list */
+        for (pptr = ppixIn, n = npixIn; --n >= 0; pptr++)
+       {
+           pixTest = ((*pptr | bits) & cmask) >> offset;
+           if ((pixTest >= numents) || (*pptr & rgbbad))
+           {
+               clientErrorValue = *pptr | bits;
+               errVal = BadValue;
+               continue;
+           }
+
+           /* find match in client list */
+           for (cptr = ppixClient, npix = npixClient;
+                --npix >= 0 && *cptr != pixTest;
+                cptr++) ;
+
+           if (npix >= 0)
+           {
+               if (pmap->class & DynamicClass)
+               {
+                   FreeCell(pmap, pixTest, color);
+#ifdef LBX
+                   /*
+                    * Only PSEUDO colormaps are grabbed by LBX proxies.
+                    * Check if the ref count reached zero on this pixel.
+                    */
+
+                   zeroRefCount = pmap->red[pixTest].refcnt == 0;
+                   if (zeroRefCount)
+                       anyRefCountReachedZero = 1;
+
+                   if (grabbed && zeroRefCount)
+                       LbxAddFreeCellToEvent (pmap, pixTest);
+#endif
+               }
+               *cptr = ~((Pixel)0);
+               zapped++;
+           }
+           else
+               errVal = BadAccess;
+       }
+        /* generate next bits value */
+       GetNextBitsOrBreak(bits, mask, base);
+    }
+
+#ifdef LBX
+    if (grabbed)
+       LbxEndFreeCellsEvent (pmap);
+    else if (anyRefCountReachedZero)
+    {
+       /*
+        * We only send LbxFreeCell events to a proxy that has the colormap
+        * grabbed.  If the colormap is not grabbed, the proxy that last
+        * had the colormap grabbed will not be able to do a smart grab
+        * in the future.  A smart grab can only occur if the proxy is kept
+        * up to date on every alloc/free change in the colormap.
+        */
+       
+       LbxDisableSmartGrab (pmap);
+    }
+#endif
+
+    /* delete freed pixels from client pixel list */
+    if (zapped)
+    {
+        npixNew = npixClient - zapped;
+        if (npixNew)
+       {
+           /* Since the list can only get smaller, we can do a copy in
+            * place and then realloc to a smaller size */
+           pptr = cptr = ppixClient;
+
+           /* If we have all the new pixels, we don't have to examine the
+            * rest of the old ones */
+           for(npix = 0; npix < npixNew; cptr++)
+           {
+               if (*cptr != ~((Pixel)0))
+               {
+                   *pptr++ = *cptr;
+                   npix++;
+               }
+           }
+           pptr = (Pixel *)xrealloc(ppixClient, npixNew * sizeof(Pixel));
+           if (pptr)
+               ppixClient = pptr;
+           npixClient = npixNew;
+        }
+       else
+       {
+           npixClient = 0;
+           xfree(ppixClient);
+           ppixClient = (Pixel *)NULL;
+       }
+       switch(color)
+       {
+         case PSEUDOMAP:
+         case REDMAP:
+           pmap->clientPixelsRed[client] = ppixClient;
+           pmap->numPixelsRed[client] = npixClient;
+           break;
+         case GREENMAP:
+           pmap->clientPixelsGreen[client] = ppixClient;
+           pmap->numPixelsGreen[client] = npixClient;
+           break;
+         case BLUEMAP:
+           pmap->clientPixelsBlue[client] = ppixClient;
+           pmap->numPixelsBlue[client] = npixClient;
+           break;
+       }
+    }
+    return (errVal);
+}
+
+
+
+/* Redefine color values */
+int
+StoreColors (pmap, count, defs)
+    ColormapPtr        pmap;
+    int                count;
+    xColorItem *defs;
+{
+    register Pixel     pix;
+    register xColorItem *pdef;
+    register EntryPtr  pent, pentT, pentLast;
+    register VisualPtr pVisual;
+    SHAREDCOLOR                *pred, *pgreen, *pblue;
+    int                        n, ChgRed, ChgGreen, ChgBlue, idef;
+    int                        class, errVal = Success;
+    int                        ok;
+
+
+    class = pmap->class;
+    if(!(class & DynamicClass) && !(pmap->flags & BeingCreated))
+    {
+       return(BadAccess);
+    }
+    pVisual = pmap->pVisual;
+
+    idef = 0;
+    if((class | DynamicClass) == DirectColor)
+    {
+       int numred, numgreen, numblue;
+       Pixel rgbbad;
+
+       numred = NUMRED(pVisual);
+       numgreen = NUMGREEN(pVisual);
+       numblue = NUMBLUE(pVisual);
+       rgbbad = ~RGBMASK(pVisual);
+        for (pdef = defs, n = 0; n < count; pdef++, n++)
+       {
+           ok = TRUE;
+            (*pmap->pScreen->ResolveColor)
+               (&pdef->red, &pdef->green, &pdef->blue, pmap->pVisual);
+
+           if (pdef->pixel & rgbbad)
+           {
+               errVal = BadValue;
+               clientErrorValue = pdef->pixel;
+               continue;
+           }
+           pix = (pdef->pixel & pVisual->redMask) >> pVisual->offsetRed;
+           if (pix >= numred)
+           {
+               errVal = BadValue;
+               ok = FALSE;
+           }
+           else if (pmap->red[pix].refcnt != AllocPrivate)
+           {
+               errVal = BadAccess;
+               ok = FALSE;
+           }
+           else if (pdef->flags & DoRed)
+           {
+               pmap->red[pix].co.local.red = pdef->red;
+           }
+           else
+           {
+               pdef->red = pmap->red[pix].co.local.red;
+           }
+
+           pix = (pdef->pixel & pVisual->greenMask) >> pVisual->offsetGreen;
+           if (pix >= numgreen)
+           {
+               errVal = BadValue;
+               ok = FALSE;
+           }
+           else if (pmap->green[pix].refcnt != AllocPrivate)
+           {
+               errVal = BadAccess;
+               ok = FALSE;
+           }
+           else if (pdef->flags & DoGreen)
+           {
+               pmap->green[pix].co.local.green = pdef->green;
+           }
+           else
+           {
+               pdef->green = pmap->green[pix].co.local.green;
+           }
+
+           pix = (pdef->pixel & pVisual->blueMask) >> pVisual->offsetBlue;
+           if (pix >= numblue)
+           {
+               errVal = BadValue;
+               ok = FALSE;
+           }
+           else if (pmap->blue[pix].refcnt != AllocPrivate)
+           {
+               errVal = BadAccess;
+               ok = FALSE;
+           }
+           else if (pdef->flags & DoBlue)
+           {
+               pmap->blue[pix].co.local.blue = pdef->blue;
+           }
+           else
+           {
+               pdef->blue = pmap->blue[pix].co.local.blue;
+           }
+           /* If this is an o.k. entry, then it gets added to the list
+            * to be sent to the hardware.  If not, skip it.  Once we've
+            * skipped one, we have to copy all the others.
+            */
+           if(ok)
+           {
+               if(idef != n)
+                   defs[idef] = defs[n];
+               idef++;
+           } else
+               clientErrorValue = pdef->pixel;
+       }
+    }
+    else
+    {
+        for (pdef = defs, n = 0; n < count; pdef++, n++)
+       {
+
+           ok = TRUE;
+           if (pdef->pixel >= pVisual->ColormapEntries)
+           {
+               clientErrorValue = pdef->pixel;
+               errVal = BadValue;
+               ok = FALSE;
+           }
+           else if (pmap->red[pdef->pixel].refcnt != AllocPrivate)
+           {
+               errVal = BadAccess;
+               ok = FALSE;
+           }
+
+           /* If this is an o.k. entry, then it gets added to the list
+            * to be sent to the hardware.  If not, skip it.  Once we've
+            * skipped one, we have to copy all the others.
+            */
+           if(ok)
+           {
+               if(idef != n)
+                   defs[idef] = defs[n];
+               idef++;
+           }
+           else
+               continue;
+
+            (*pmap->pScreen->ResolveColor)
+               (&pdef->red, &pdef->green, &pdef->blue, pmap->pVisual);
+
+           pent = &pmap->red[pdef->pixel];
+
+           if(pdef->flags & DoRed)
+           {
+               if(pent->fShared)
+               {
+                   pent->co.shco.red->color = pdef->red;
+                   if (pent->co.shco.red->refcnt > 1)
+                       ok = FALSE;
+               }
+               else
+                   pent->co.local.red = pdef->red;
+           }
+           else
+           {
+               if(pent->fShared)
+                   pdef->red = pent->co.shco.red->color;
+               else
+                   pdef->red = pent->co.local.red;
+           }
+           if(pdef->flags & DoGreen)
+           {
+               if(pent->fShared)
+               {
+                   pent->co.shco.green->color = pdef->green;
+                   if (pent->co.shco.green->refcnt > 1)
+                       ok = FALSE;
+               }
+               else
+                   pent->co.local.green = pdef->green;
+           }
+           else
+           {
+               if(pent->fShared)
+                   pdef->green = pent->co.shco.green->color;
+               else
+                   pdef->green = pent->co.local.green;
+           }
+           if(pdef->flags & DoBlue)
+           {
+               if(pent->fShared)
+               {
+                   pent->co.shco.blue->color = pdef->blue;
+                   if (pent->co.shco.blue->refcnt > 1)
+                       ok = FALSE;
+               }
+               else
+                   pent->co.local.blue = pdef->blue;
+           }
+           else
+           {
+               if(pent->fShared)
+                   pdef->blue = pent->co.shco.blue->color;
+               else
+                   pdef->blue = pent->co.local.blue;
+           }
+
+           if(!ok)
+           {
+                /* have to run through the colormap and change anybody who
+                * shares this value */
+               pred = pent->co.shco.red;
+               pgreen = pent->co.shco.green;
+               pblue = pent->co.shco.blue;
+               ChgRed = pdef->flags & DoRed;
+               ChgGreen = pdef->flags & DoGreen;
+               ChgBlue = pdef->flags & DoBlue;
+               pentLast = pmap->red + pVisual->ColormapEntries;
+
+               for(pentT = pmap->red; pentT < pentLast; pentT++)
+               {
+                   if(pentT->fShared && (pentT != pent))
+                   {
+                       xColorItem      defChg;
+
+                       /* There are, alas, devices in this world too dumb
+                        * to read their own hardware colormaps.  Sick, but
+                        * true.  So we're going to be really nice and load
+                        * the xColorItem with the proper value for all the
+                        * fields.  We will only set the flags for those
+                        * fields that actually change.  Smart devices can
+                        * arrange to change only those fields.  Dumb devices
+                        * can rest assured that we have provided for them,
+                        * and can change all three fields */
+
+                       defChg.flags = 0;
+                       if(ChgRed && pentT->co.shco.red == pred)
+                       {
+                           defChg.flags |= DoRed;
+                       }
+                       if(ChgGreen && pentT->co.shco.green == pgreen)
+                       {
+                           defChg.flags |= DoGreen;
+                       }
+                       if(ChgBlue && pentT->co.shco.blue == pblue)
+                       {
+                           defChg.flags |= DoBlue;
+                       }
+                       if(defChg.flags != 0)
+                       {
+                           defChg.pixel = pentT - pmap->red;
+                           defChg.red = pentT->co.shco.red->color;
+                           defChg.green = pentT->co.shco.green->color;
+                           defChg.blue = pentT->co.shco.blue->color;
+                           (*pmap->pScreen->StoreColors) (pmap, 1, &defChg);
+                       }
+                   }
+               }
+
+           }
+       }
+    }
+    /* Note that we use idef, the count of acceptable entries, and not
+     * count, the count of proposed entries */
+    if (idef != 0)
+       ( *pmap->pScreen->StoreColors) (pmap, idef, defs);
+    return (errVal);
+}
+
+int
+IsMapInstalled(map, pWin)
+    Colormap   map;
+    WindowPtr  pWin;
+{
+    Colormap   *pmaps;
+    int                imap, nummaps, found;
+
+    pmaps = (Colormap *) ALLOCATE_LOCAL( 
+             pWin->drawable.pScreen->maxInstalledCmaps * sizeof(Colormap));
+    if(!pmaps)
+       return(FALSE);
+    nummaps = (*pWin->drawable.pScreen->ListInstalledColormaps)
+        (pWin->drawable.pScreen, pmaps);
+    found = FALSE;
+    for(imap = 0; imap < nummaps; imap++)
+    {
+       if(pmaps[imap] == map)
+       {
+           found = TRUE;
+           break;
+       }
+    }
+    DEALLOCATE_LOCAL(pmaps);
+    return (found);
+}
diff --git a/Xserver/programs/Xserver/dix/cursor.c b/Xserver/programs/Xserver/dix/cursor.c
new file mode 100644 (file)
index 0000000..4fafc60
--- /dev/null
@@ -0,0 +1,405 @@
+/***********************************************************
+
+Copyright (c) 1987  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+
+Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
+
+                        All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and its 
+documentation for any purpose and without fee is hereby granted, 
+provided that the above copyright notice appear in all copies and that
+both that copyright notice and this permission notice appear in 
+supporting documentation, and that the name of Digital not be
+used in advertising or publicity pertaining to distribution of the
+software without specific, written prior permission.  
+
+DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
+ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
+DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
+ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+SOFTWARE.
+
+******************************************************************/
+
+
+/* $XConsortium: cursor.c /main/19 1996/08/01 19:20:16 dpw $ */
+/* $XFree86: xc/programs/Xserver/dix/cursor.c,v 3.1 1996/12/23 06:29:36 dawes Exp $ */
+
+#include "X.h"
+#include "Xmd.h"
+#include "servermd.h"
+#include "scrnintstr.h"
+#include "dixstruct.h"
+#include "cursorstr.h"
+#include "dixfontstr.h"
+#include "opaque.h"
+
+typedef struct _GlyphShare {
+    FontPtr font;
+    unsigned short sourceChar;
+    unsigned short maskChar;
+    CursorBitsPtr bits;
+    struct _GlyphShare *next;
+} GlyphShare, *GlyphSharePtr;
+
+static GlyphSharePtr sharedGlyphs = (GlyphSharePtr)NULL;
+
+static void
+#if NeedFunctionPrototypes
+FreeCursorBits(CursorBitsPtr bits)
+#else
+FreeCursorBits(bits)
+    CursorBitsPtr bits;
+#endif
+{
+    if (--bits->refcnt > 0)
+       return;
+    xfree(bits->source);
+    xfree(bits->mask);
+    if (bits->refcnt == 0)
+    {
+       register GlyphSharePtr *prev, this;
+
+       for (prev = &sharedGlyphs;
+            (this = *prev) && (this->bits != bits);
+            prev = &this->next)
+           ;
+       if (this)
+       {
+           *prev = this->next;
+           CloseFont(this->font, (Font)0);
+           xfree(this);
+       }
+       xfree(bits);
+    }
+}
+
+/*
+ * To be called indirectly by DeleteResource; must use exactly two args
+ */
+/*ARGSUSED*/
+int
+FreeCursor(value, cid)
+    pointer    value; /* must conform to DeleteType */
+    XID        cid;    
+{
+    int                nscr;
+    CursorPtr  pCurs = (CursorPtr)value;
+
+    ScreenPtr  pscr;
+
+    if ( --pCurs->refcnt > 0)
+       return(Success);
+
+    for (nscr = 0; nscr < screenInfo.numScreens; nscr++)
+    {
+       pscr = screenInfo.screens[nscr];
+       (void)( *pscr->UnrealizeCursor)( pscr, pCurs);
+    }
+    FreeCursorBits(pCurs->bits);
+    xfree( pCurs);
+    return(Success);
+}
+
+/*
+ * does nothing about the resource table, just creates the data structure.
+ * does not copy the src and mask bits
+ */
+CursorPtr 
+AllocCursor(psrcbits, pmaskbits, cm,
+           foreRed, foreGreen, foreBlue, backRed, backGreen, backBlue)
+    unsigned char *    psrcbits;               /* server-defined padding */
+    unsigned char *    pmaskbits;              /* server-defined padding */
+    CursorMetricPtr    cm;
+    unsigned           foreRed, foreGreen, foreBlue;
+    unsigned           backRed, backGreen, backBlue;
+{
+    CursorBitsPtr  bits;
+    CursorPtr  pCurs;
+    int                nscr;
+    ScreenPtr  pscr;
+
+    pCurs = (CursorPtr)xalloc(sizeof(CursorRec) + sizeof(CursorBits));
+    if (!pCurs)
+    {
+       xfree(psrcbits);
+       xfree(pmaskbits);
+       return (CursorPtr)NULL;
+    }
+    bits = (CursorBitsPtr)((char *)pCurs + sizeof(CursorRec));
+    bits->source = psrcbits;
+    bits->mask = pmaskbits;
+    bits->width = cm->width;
+    bits->height = cm->height;
+    bits->xhot = cm->xhot;
+    bits->yhot = cm->yhot;
+    bits->refcnt = -1;
+
+    pCurs->bits = bits;
+    pCurs->refcnt = 1;         
+
+    pCurs->foreRed = foreRed;
+    pCurs->foreGreen = foreGreen;
+    pCurs->foreBlue = foreBlue;
+
+    pCurs->backRed = backRed;
+    pCurs->backGreen = backGreen;
+    pCurs->backBlue = backBlue;
+
+    /*
+     * realize the cursor for every screen
+     */
+    for (nscr = 0; nscr < screenInfo.numScreens; nscr++)
+    {
+       pscr = screenInfo.screens[nscr];
+        if (!( *pscr->RealizeCursor)( pscr, pCurs))
+       {
+           while (--nscr >= 0)
+           {
+               pscr = screenInfo.screens[nscr];
+               ( *pscr->UnrealizeCursor)( pscr, pCurs);
+           }
+           FreeCursorBits(bits);
+           xfree(pCurs);
+           return (CursorPtr)NULL;
+       }
+    }
+    return pCurs;
+}
+
+int
+AllocGlyphCursor(source, sourceChar, mask, maskChar,
+                foreRed, foreGreen, foreBlue, backRed, backGreen, backBlue,
+                ppCurs, client)
+    Font source, mask;
+    unsigned int sourceChar, maskChar;
+    unsigned foreRed, foreGreen, foreBlue;
+    unsigned backRed, backGreen, backBlue;
+    CursorPtr *ppCurs;
+    ClientPtr client;
+{
+    FontPtr  sourcefont, maskfont;
+    unsigned char   *srcbits;
+    unsigned char   *mskbits;
+    CursorMetricRec cm;
+    int res;
+    CursorBitsPtr  bits;
+    CursorPtr  pCurs;
+    int                nscr;
+    ScreenPtr  pscr;
+    GlyphSharePtr pShare;
+
+    sourcefont = (FontPtr) SecurityLookupIDByType(client, source, RT_FONT,
+                                                 SecurityReadAccess);
+    maskfont = (FontPtr) SecurityLookupIDByType(client, mask, RT_FONT,
+                                               SecurityReadAccess);
+
+    if (!sourcefont)
+    {
+       client->errorValue = source;
+       return(BadFont);
+    }
+    if (!maskfont && (mask != None))
+    {
+       client->errorValue = mask;
+       return(BadFont);
+    }
+    if (sourcefont != maskfont)
+       pShare = (GlyphSharePtr)NULL;
+    else
+    {
+       for (pShare = sharedGlyphs;
+            pShare &&
+            ((pShare->font != sourcefont) ||
+             (pShare->sourceChar != sourceChar) ||
+             (pShare->maskChar != maskChar));
+            pShare = pShare->next)
+           ;
+    }
+    if (pShare)
+    {
+       pCurs = (CursorPtr)xalloc(sizeof(CursorRec));
+       if (!pCurs)
+           return BadAlloc;
+       bits = pShare->bits;
+       bits->refcnt++;
+    }
+    else
+    {
+       if (!CursorMetricsFromGlyph(sourcefont, sourceChar, &cm))
+       {
+           client->errorValue = sourceChar;
+           return BadValue;
+       }
+       if (!maskfont)
+       {
+           register long n;
+           register unsigned char *mskptr;
+
+           n = BitmapBytePad(cm.width)*(long)cm.height;
+           mskptr = mskbits = (unsigned char *)xalloc(n);
+           if (!mskptr)
+               return BadAlloc;
+           while (--n >= 0)
+               *mskptr++ = ~0;
+       }
+       else
+       {
+           if (!CursorMetricsFromGlyph(maskfont, maskChar, &cm))
+           {
+               client->errorValue = maskChar;
+               return BadValue;
+           }
+           if ((res = ServerBitsFromGlyph(maskfont, maskChar, &cm, &mskbits)) != 0)
+               return res;
+       }
+       if ((res = ServerBitsFromGlyph(sourcefont, sourceChar, &cm, &srcbits)) != 0)
+       {
+           xfree(mskbits);
+           return res;
+       }
+       if (sourcefont != maskfont)
+       {
+           pCurs = (CursorPtr)xalloc(sizeof(CursorRec) + sizeof(CursorBits));
+           if (pCurs)
+               bits = (CursorBitsPtr)((char *)pCurs + sizeof(CursorRec));
+           else
+               bits = (CursorBitsPtr)NULL;
+       }
+       else
+       {
+           pCurs = (CursorPtr)xalloc(sizeof(CursorRec));
+           if (pCurs)
+               bits = (CursorBitsPtr)xalloc(sizeof(CursorBits));
+           else
+               bits = (CursorBitsPtr)NULL;
+       }
+       if (!bits)
+       {
+           xfree(pCurs);
+           xfree(mskbits);
+           xfree(srcbits);
+           return BadAlloc;
+       }
+       bits->source = srcbits;
+       bits->mask = mskbits;
+       bits->width = cm.width;
+       bits->height = cm.height;
+       bits->xhot = cm.xhot;
+       bits->yhot = cm.yhot;
+       if (sourcefont != maskfont)
+           bits->refcnt = -1;
+       else
+       {
+           bits->refcnt = 1;
+           pShare = (GlyphSharePtr)xalloc(sizeof(GlyphShare));
+           if (!pShare)
+           {
+               FreeCursorBits(bits);
+               return BadAlloc;
+           }
+           pShare->font = sourcefont;
+           sourcefont->refcnt++;
+           pShare->sourceChar = sourceChar;
+           pShare->maskChar = maskChar;
+           pShare->bits = bits;
+           pShare->next = sharedGlyphs;
+           sharedGlyphs = pShare;
+       }
+    }
+    pCurs->bits = bits;
+    pCurs->refcnt = 1;
+
+    pCurs->foreRed = foreRed;
+    pCurs->foreGreen = foreGreen;
+    pCurs->foreBlue = foreBlue;
+
+    pCurs->backRed = backRed;
+    pCurs->backGreen = backGreen;
+    pCurs->backBlue = backBlue;
+
+    /*
+     * realize the cursor for every screen
+     */
+    for (nscr = 0; nscr < screenInfo.numScreens; nscr++)
+    {
+       pscr = screenInfo.screens[nscr];
+        if (!( *pscr->RealizeCursor)( pscr, pCurs))
+       {
+           while (--nscr >= 0)
+           {
+               pscr = screenInfo.screens[nscr];
+               ( *pscr->UnrealizeCursor)( pscr, pCurs);
+           }
+           FreeCursorBits(pCurs->bits);
+           xfree(pCurs);
+           return BadAlloc;
+       }
+    }
+    *ppCurs = pCurs;
+    return Success;
+}
+
+/***********************************************************
+ * CreateRootCursor
+ *
+ * look up the name of a font
+ * open the font
+ * add the font to the resource table
+ * make a cursor from the glyphs
+ * add the cursor to the resource table
+ *************************************************************/
+
+CursorPtr 
+CreateRootCursor(pfilename, glyph)
+    char *             pfilename;
+    unsigned int       glyph;
+{
+    CursorPtr  curs;
+    FontPtr    cursorfont;
+    int        err;
+    XID                fontID;
+
+    fontID = FakeClientID(0);
+    err = OpenFont(serverClient, fontID, FontLoadAll | FontOpenSync,
+       (unsigned)strlen( pfilename), pfilename);
+    if (err != Success)
+       return NullCursor;
+
+    cursorfont = (FontPtr)LookupIDByType(fontID, RT_FONT);
+    if (!cursorfont)
+       return NullCursor;
+    if (AllocGlyphCursor(fontID, glyph, fontID, glyph + 1,
+                        0, 0, 0, ~0, ~0, ~0, &curs, serverClient) != Success)
+       return NullCursor;
+
+    if (!AddResource(FakeClientID(0), RT_CURSOR, (pointer)curs))
+       return NullCursor;
+
+    return curs;
+}
diff --git a/Xserver/programs/Xserver/dix/devices.c b/Xserver/programs/Xserver/dix/devices.c
new file mode 100644 (file)
index 0000000..90a2f61
--- /dev/null
@@ -0,0 +1,1753 @@
+/************************************************************
+
+Copyright (c) 1987  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+
+Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
+
+                        All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and its 
+documentation for any purpose and without fee is hereby granted, 
+provided that the above copyright notice appear in all copies and that
+both that copyright notice and this permission notice appear in 
+supporting documentation, and that the name of Digital not be
+used in advertising or publicity pertaining to distribution of the
+software without specific, written prior permission.  
+
+DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
+ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
+DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
+ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+SOFTWARE.
+
+********************************************************/
+
+
+/* $XFree86: xc/programs/Xserver/dix/devices.c,v 3.11 1996/12/24 02:23:43 dawes Exp $ */
+/* $XConsortium: devices.c /main/54 1996/09/25 00:45:00 dpw $ */
+
+#include "X.h"
+#include "misc.h"
+#include "resource.h"
+#define NEED_EVENTS
+#define NEED_REPLIES
+#include "Xproto.h"
+#include "windowstr.h"
+#include "inputstr.h"
+#include "scrnintstr.h"
+#include "cursorstr.h"
+#include "dixstruct.h"
+#include "site.h"
+#define        XKB_IN_SERVER
+#ifdef XKB
+#include "XKBsrv.h"
+#endif
+#ifdef XCSECURITY
+#define _SECURITY_SERVER
+#include "extensions/security.h"
+#endif
+
+#include "dispatch.h"
+#include "swaprep.h"
+#include "dixevents.h"
+
+DeviceIntPtr
+_AddInputDevice(deviceProc, autoStart)
+    DeviceProc deviceProc;
+    Bool autoStart;
+{
+    register DeviceIntPtr dev;
+
+    if (inputInfo.numDevices >= MAX_DEVICES)
+       return (DeviceIntPtr)NULL;
+    dev = (DeviceIntPtr) xalloc(sizeof(DeviceIntRec));
+    if (!dev)
+       return (DeviceIntPtr)NULL;
+    dev->name = (char *)NULL;
+    dev->type = 0;
+    dev->id = inputInfo.numDevices;
+    inputInfo.numDevices++;
+    dev->public.on = FALSE;
+    dev->public.processInputProc = (ProcessInputProc)NoopDDA;
+    dev->public.realInputProc = (ProcessInputProc)NoopDDA;
+    dev->public.enqueueInputProc = EnqueueEvent;
+    dev->deviceProc = deviceProc;
+    dev->startup = autoStart;
+    dev->sync.frozen = FALSE;
+    dev->sync.other = NullGrab;
+    dev->sync.state = NOT_GRABBED;
+    dev->sync.event = (xEvent *) NULL;
+    dev->sync.evcount = 0;
+    dev->grab = NullGrab;
+    dev->grabTime = currentTime;
+    dev->fromPassiveGrab = FALSE;
+    dev->key = (KeyClassPtr)NULL;
+    dev->valuator = (ValuatorClassPtr)NULL;
+    dev->button = (ButtonClassPtr)NULL;
+    dev->focus = (FocusClassPtr)NULL;
+    dev->proximity = (ProximityClassPtr)NULL;
+    dev->kbdfeed = (KbdFeedbackPtr)NULL;
+    dev->ptrfeed = (PtrFeedbackPtr)NULL;
+    dev->intfeed = (IntegerFeedbackPtr)NULL;
+    dev->stringfeed = (StringFeedbackPtr)NULL;
+    dev->bell = (BellFeedbackPtr)NULL;
+    dev->leds = (LedFeedbackPtr)NULL;
+    dev->next = inputInfo.off_devices;
+#ifdef XKB
+    dev->xkb_interest= NULL;
+#endif
+    inputInfo.off_devices = dev;
+    return dev;
+}
+
+Bool
+EnableDevice(dev)
+    register DeviceIntPtr dev;
+{
+    register DeviceIntPtr *prev;
+
+    for (prev = &inputInfo.off_devices;
+        *prev && (*prev != dev);
+        prev = &(*prev)->next)
+       ;
+    if ((*prev != dev) || !dev->inited ||
+       ((*dev->deviceProc)(dev, DEVICE_ON) != Success))
+       return FALSE;
+    *prev = dev->next;
+    dev->next = inputInfo.devices;
+    inputInfo.devices = dev;
+    return TRUE;
+}
+
+Bool
+DisableDevice(dev)
+    register DeviceIntPtr dev;
+{
+    register DeviceIntPtr *prev;
+
+    for (prev = &inputInfo.devices;
+        *prev && (*prev != dev);
+        prev = &(*prev)->next)
+       ;
+    if (*prev != dev)
+       return FALSE;
+    (void)(*dev->deviceProc)(dev, DEVICE_OFF);
+    *prev = dev->next;
+    dev->next = inputInfo.off_devices;
+    inputInfo.off_devices = dev;
+    return TRUE;
+}
+
+int
+InitAndStartDevices()
+{
+    register DeviceIntPtr dev, next;
+
+    for (dev = inputInfo.off_devices; dev; dev = dev->next)
+       dev->inited = ((*dev->deviceProc)(dev, DEVICE_INIT) == Success);
+    for (dev = inputInfo.off_devices; dev; dev = next)
+    {
+       next = dev->next;
+       if (dev->inited && dev->startup)
+           (void)EnableDevice(dev);
+    }
+    for (dev = inputInfo.devices;
+        dev && (dev != inputInfo.keyboard);
+        dev = dev->next)
+       ;
+    if (!dev || (dev != inputInfo.keyboard))
+       return BadImplementation;
+    for (dev = inputInfo.devices;
+        dev && (dev != inputInfo.pointer);
+        dev = dev->next)
+       ;
+    if (!dev || (dev != inputInfo.pointer))
+       return BadImplementation;
+    return Success;
+}
+
+static void
+#if NeedFunctionPrototypes
+CloseDevice(register DeviceIntPtr dev)
+#else
+CloseDevice(dev)
+    register DeviceIntPtr dev;
+#endif
+{
+    KbdFeedbackPtr k, knext;
+    PtrFeedbackPtr p, pnext;
+    IntegerFeedbackPtr i, inext;
+    StringFeedbackPtr s, snext;
+    BellFeedbackPtr b, bnext;
+    LedFeedbackPtr l, lnext;
+
+    if (dev->inited)
+       (void)(*dev->deviceProc)(dev, DEVICE_CLOSE);
+    xfree(dev->name);
+    if (dev->key)
+    {
+#ifdef XKB
+       if (dev->key->xkbInfo)
+           XkbFreeInfo(dev->key->xkbInfo);
+#endif
+       xfree(dev->key->curKeySyms.map);
+       xfree(dev->key->modifierKeyMap);
+       xfree(dev->key);
+    }
+    xfree(dev->valuator);
+#ifdef XKB
+    if ((dev->button)&&(dev->button->xkb_acts))
+       xfree(dev->button->xkb_acts);
+#endif
+    xfree(dev->button);
+    if (dev->focus)
+    {
+       xfree(dev->focus->trace);
+       xfree(dev->focus);
+    }
+    xfree(dev->proximity);
+    for (k=dev->kbdfeed; k; k=knext)
+    {
+       knext = k->next;
+#ifdef XKB
+       if (k->xkb_sli)
+           XkbFreeSrvLedInfo(k->xkb_sli);
+#endif
+       xfree(k);
+    }
+    for (p=dev->ptrfeed; p; p=pnext)
+    {
+       pnext = p->next;
+       xfree(p);
+    }
+    for (i=dev->intfeed; i; i=inext)
+    {
+       inext = i->next;
+       xfree(i);
+    }
+    for (s=dev->stringfeed; s; s=snext)
+    {
+       snext = s->next;
+       xfree(s->ctrl.symbols_supported);
+       xfree(s->ctrl.symbols_displayed);
+       xfree(s);
+    }
+    for (b=dev->bell; b; b=bnext)
+    {
+       bnext = b->next;
+       xfree(b);
+    }
+    for (l=dev->leds; l; l=lnext)
+    {
+       lnext = l->next;
+#ifdef XKB
+       if (l->xkb_sli)
+           XkbFreeSrvLedInfo(l->xkb_sli);
+#endif
+       xfree(l);
+    }
+#ifdef XKB
+    while (dev->xkb_interest) {
+       XkbRemoveResourceClient((DevicePtr)dev,dev->xkb_interest->resource);
+    }
+#endif
+    xfree(dev->sync.event);
+    xfree(dev);
+}
+
+void
+CloseDownDevices()
+{
+    register DeviceIntPtr dev, next;
+
+    for (dev = inputInfo.devices; dev; dev = next)
+    {
+       next = dev->next;
+       CloseDevice(dev);
+    }
+    for (dev = inputInfo.off_devices; dev; dev = next)
+    {
+       next = dev->next;
+       CloseDevice(dev);
+    }
+    inputInfo.keyboard = NULL;
+    inputInfo.pointer = NULL;
+}
+
+void
+RemoveDevice(dev)
+    register DeviceIntPtr dev;
+{
+    register DeviceIntPtr prev,tmp,next;
+
+    prev= NULL;
+    for (tmp= inputInfo.devices; tmp; (prev = tmp), (tmp = next)) {
+       next = tmp->next;
+       if (tmp==dev) {
+           CloseDevice(tmp);
+           if (prev==NULL)
+               inputInfo.devices = next;
+           else
+               prev->next = next;
+           inputInfo.numDevices--;
+           if (inputInfo.keyboard == tmp)
+               inputInfo.keyboard = NULL;
+           else if (inputInfo.pointer == tmp)
+               inputInfo.pointer = NULL;
+           return;
+       }
+    }
+
+    prev= NULL;
+    for (tmp= inputInfo.off_devices; tmp; (prev = tmp), (tmp = next)) {
+       next = tmp->next;
+       if (tmp==dev) {
+           CloseDevice(tmp);
+           if (prev==NULL)
+               inputInfo.off_devices = next;
+           else
+               prev->next = next;
+           inputInfo.numDevices--;
+           if (inputInfo.keyboard == tmp)
+               inputInfo.keyboard = NULL;
+           else if (inputInfo.pointer == tmp)
+               inputInfo.pointer = NULL;
+           return;
+       }
+    }
+    ErrorF("Internal Error! Attempt to remove a non-existent device\n");
+    return;
+}
+
+int
+NumMotionEvents()
+{
+    return inputInfo.pointer->valuator->numMotionEvents;
+}
+
+void
+_RegisterPointerDevice(device)
+    DeviceIntPtr device;
+{
+    inputInfo.pointer = device;
+#ifdef XKB
+    if (noXkbExtension) {
+       device->public.processInputProc = CoreProcessPointerEvent;
+       device->public.realInputProc = CoreProcessPointerEvent;
+    } else {
+       device->public.processInputProc = ProcessPointerEvent;
+       device->public.realInputProc = ProcessPointerEvent;
+    }
+#else
+    device->public.processInputProc = ProcessPointerEvent;
+    device->public.realInputProc = ProcessPointerEvent;
+#endif
+    device->ActivateGrab = ActivatePointerGrab;
+    device->DeactivateGrab = DeactivatePointerGrab;
+    if (!device->name)
+    {
+       char *p = "pointer";
+       device->name = (char *)xalloc(strlen(p) + 1);
+       strcpy(device->name, p);
+    }
+}
+
+void
+_RegisterKeyboardDevice(device)
+    DeviceIntPtr device;
+{
+    inputInfo.keyboard = device;
+#ifdef XKB
+    if (noXkbExtension) {
+       device->public.processInputProc = CoreProcessKeyboardEvent;
+       device->public.realInputProc = CoreProcessKeyboardEvent;
+    } else {
+       device->public.processInputProc = ProcessKeyboardEvent;
+       device->public.realInputProc = ProcessKeyboardEvent;
+    }
+#else
+    device->public.processInputProc = ProcessKeyboardEvent;
+    device->public.realInputProc = ProcessKeyboardEvent;
+#endif
+    device->ActivateGrab = ActivateKeyboardGrab;
+    device->DeactivateGrab = DeactivateKeyboardGrab;
+    if (!device->name)
+    {
+       char *k = "keyboard";
+       device->name = (char *)xalloc(strlen(k) + 1);
+       strcpy(device->name, k);
+    }
+}
+
+DevicePtr
+LookupKeyboardDevice()
+{
+    return inputInfo.keyboard ? &inputInfo.keyboard->public : NULL;
+}
+
+DevicePtr
+LookupPointerDevice()
+{
+    return inputInfo.pointer ? &inputInfo.pointer->public : NULL;
+}
+
+DevicePtr
+LookupDevice(id)
+    int id;
+{
+    DeviceIntPtr dev;
+
+    for (dev=inputInfo.devices; dev; dev=dev->next) {
+        if (dev->id == (CARD8)id)
+            return (DevicePtr)dev;
+    }
+    for (dev=inputInfo.off_devices; dev; dev=dev->next) {
+        if (dev->id == (CARD8)id)
+            return (DevicePtr)dev;
+    }
+    return NULL;
+}
+
+void
+QueryMinMaxKeyCodes(minCode, maxCode)
+    KeyCode *minCode, *maxCode;
+{
+    if (inputInfo.keyboard) {
+       *minCode = inputInfo.keyboard->key->curKeySyms.minKeyCode;
+       *maxCode = inputInfo.keyboard->key->curKeySyms.maxKeyCode;
+    }
+}
+
+Bool
+SetKeySymsMap(dst, src)
+    register KeySymsPtr dst, src;
+{
+    int i, j;
+    int rowDif = src->minKeyCode - dst->minKeyCode;
+           /* if keysym map size changes, grow map first */
+
+    if (src->mapWidth < dst->mapWidth)
+    {
+        for (i = src->minKeyCode; i <= src->maxKeyCode; i++)
+       {
+#define SI(r, c) (((r-src->minKeyCode)*src->mapWidth) + (c))
+#define DI(r, c) (((r - dst->minKeyCode)*dst->mapWidth) + (c))
+           for (j = 0; j < src->mapWidth; j++)
+               dst->map[DI(i, j)] = src->map[SI(i, j)];
+           for (j = src->mapWidth; j < dst->mapWidth; j++)
+               dst->map[DI(i, j)] = NoSymbol;
+#undef SI
+#undef DI
+       }
+       return TRUE;
+    }
+    else if (src->mapWidth > dst->mapWidth)
+    {
+        KeySym *map;
+       int bytes = sizeof(KeySym) * src->mapWidth *
+                   (dst->maxKeyCode - dst->minKeyCode + 1);
+        map = (KeySym *)xalloc(bytes);
+       if (!map)
+           return FALSE;
+       bzero((char *)map, bytes);
+        if (dst->map)
+       {
+            for (i = 0; i <= dst->maxKeyCode-dst->minKeyCode; i++)
+               memmove((char *)&map[i*src->mapWidth],
+                       (char *)&dst->map[i*dst->mapWidth],
+                     dst->mapWidth * sizeof(KeySym));
+           xfree(dst->map);
+       }
+       dst->mapWidth = src->mapWidth;
+       dst->map = map;
+    }
+    memmove((char *)&dst->map[rowDif * dst->mapWidth],
+           (char *)src->map,
+         (int)(src->maxKeyCode - src->minKeyCode + 1) *
+         dst->mapWidth * sizeof(KeySym));
+    return TRUE;
+}
+
+static Bool
+#if NeedFunctionPrototypes
+InitModMap(register KeyClassPtr keyc)
+#else
+InitModMap(keyc)
+    register KeyClassPtr keyc;
+#endif
+{
+    int i, j;
+    CARD8 keysPerModifier[8];
+    CARD8 mask;
+
+    keyc->maxKeysPerModifier = 0;
+    for (i = 0; i < 8; i++)
+       keysPerModifier[i] = 0;
+    for (i = 8; i < MAP_LENGTH; i++)
+    {
+       for (j = 0, mask = 1; j < 8; j++, mask <<= 1)
+       {
+           if (mask & keyc->modifierMap[i])
+           {
+               if (++keysPerModifier[j] > keyc->maxKeysPerModifier)
+                   keyc->maxKeysPerModifier = keysPerModifier[j];
+           }
+       }
+    }
+    keyc->modifierKeyMap = (KeyCode *)xalloc(8*keyc->maxKeysPerModifier);
+    if (!keyc->modifierKeyMap && keyc->maxKeysPerModifier)
+       return (FALSE);
+    bzero((char *)keyc->modifierKeyMap, 8*(int)keyc->maxKeysPerModifier);
+    for (i = 0; i < 8; i++)
+       keysPerModifier[i] = 0;
+    for (i = 8; i < MAP_LENGTH; i++)
+    {
+       for (j = 0, mask = 1; j < 8; j++, mask <<= 1)
+       {
+           if (mask & keyc->modifierMap[i])
+           {
+               keyc->modifierKeyMap[(j*keyc->maxKeysPerModifier) +
+                                    keysPerModifier[j]] = i;
+               keysPerModifier[j]++;
+           }
+       }
+    }
+    return TRUE;
+}
+
+Bool
+InitKeyClassDeviceStruct(dev, pKeySyms, pModifiers)
+    DeviceIntPtr dev;
+    KeySymsPtr pKeySyms;
+    CARD8 pModifiers[];
+{
+    int i;
+    register KeyClassPtr keyc;
+
+    keyc = (KeyClassPtr)xalloc(sizeof(KeyClassRec));
+    if (!keyc)
+       return FALSE;
+    keyc->curKeySyms.map = (KeySym *)NULL;
+    keyc->curKeySyms.mapWidth = 0;
+    keyc->curKeySyms.minKeyCode = pKeySyms->minKeyCode;
+    keyc->curKeySyms.maxKeyCode = pKeySyms->maxKeyCode;
+    keyc->modifierKeyMap = (KeyCode *)NULL;
+    keyc->state = 0;
+    keyc->prev_state = 0;
+    if (pModifiers)
+       memmove((char *)keyc->modifierMap, (char *)pModifiers, MAP_LENGTH);
+    else
+       bzero((char *)keyc->modifierMap, MAP_LENGTH);
+    bzero((char *)keyc->down, DOWN_LENGTH);
+    for (i = 0; i < 8; i++)
+       keyc->modifierKeyCount[i] = 0;
+    if (!SetKeySymsMap(&keyc->curKeySyms, pKeySyms) || !InitModMap(keyc))
+    {
+       xfree(keyc->curKeySyms.map);
+       xfree(keyc->modifierKeyMap);
+       xfree(keyc);
+       return FALSE;
+    }
+    dev->key = keyc;
+#ifdef XKB
+    dev->key->xkbInfo= NULL;
+    if (!noXkbExtension) XkbInitDevice(dev);
+#endif
+    return TRUE;
+}
+
+Bool
+InitButtonClassDeviceStruct(dev, numButtons, map)
+    register DeviceIntPtr dev;
+    int numButtons;
+    CARD8 *map;
+{
+    register ButtonClassPtr butc;
+    int i;
+
+    butc = (ButtonClassPtr)xalloc(sizeof(ButtonClassRec));
+    if (!butc)
+       return FALSE;
+    butc->numButtons = numButtons;
+    for (i = 1; i <= numButtons; i++)
+       butc->map[i] = map[i];
+    butc->buttonsDown = 0;
+    butc->state = 0;
+    butc->motionMask = 0;
+    bzero((char *)butc->down, DOWN_LENGTH);
+#ifdef XKB
+    butc->xkb_acts=    NULL;
+#endif
+    dev->button = butc;
+    return TRUE;
+}
+
+Bool
+InitValuatorClassDeviceStruct(dev, numAxes, motionProc, numMotionEvents, mode)
+    DeviceIntPtr dev;
+    ValuatorMotionProcPtr motionProc;
+    int numAxes;
+    int numMotionEvents;
+    int mode;
+{
+    int i;
+    register ValuatorClassPtr valc;
+
+    valc = (ValuatorClassPtr)xalloc(sizeof(ValuatorClassRec) +
+                                   numAxes * sizeof(AxisInfo) +
+                                   numAxes * sizeof(unsigned int));
+    if (!valc)
+       return FALSE;
+    valc->GetMotionProc = motionProc;
+    valc->numMotionEvents = numMotionEvents;
+    valc->motionHintWindow = NullWindow;
+    valc->numAxes = numAxes;
+    valc->mode = mode;
+    valc->axes = (AxisInfoPtr)(valc + 1);
+    valc->axisVal = (int *)(valc->axes + numAxes);
+    for (i=0; i<numAxes; i++)
+       valc->axisVal[i]=0;
+    dev->valuator = valc;
+    return TRUE;
+}
+
+Bool
+InitFocusClassDeviceStruct(dev)
+    DeviceIntPtr dev;
+{
+    register FocusClassPtr focc;
+
+    focc = (FocusClassPtr)xalloc(sizeof(FocusClassRec));
+    if (!focc)
+       return FALSE;
+    focc->win = PointerRootWin;
+    focc->revert = None;
+    focc->time = currentTime;
+    focc->trace = (WindowPtr *)NULL;
+    focc->traceSize = 0;
+    focc->traceGood = 0;
+    dev->focus = focc;
+    return TRUE;
+}
+
+Bool
+InitKbdFeedbackClassDeviceStruct(dev, bellProc, controlProc)
+    DeviceIntPtr dev;
+    BellProcPtr bellProc;
+    KbdCtrlProcPtr controlProc;
+{
+    register KbdFeedbackPtr feedc;
+
+    feedc = (KbdFeedbackPtr)xalloc(sizeof(KbdFeedbackClassRec));
+    if (!feedc)
+       return FALSE;
+    feedc->BellProc = bellProc;
+    feedc->CtrlProc = controlProc;
+#ifdef XKB
+    defaultKeyboardControl.autoRepeat = TRUE;
+#endif
+    feedc->ctrl = defaultKeyboardControl;
+    feedc->ctrl.id = 0;
+    if ((feedc->next = dev->kbdfeed) != 0)
+       feedc->ctrl.id = dev->kbdfeed->ctrl.id + 1;
+    dev->kbdfeed = feedc;
+#ifdef XKB
+    feedc->xkb_sli= NULL;
+    if (!noXkbExtension)
+       XkbFinishDeviceInit(dev);
+#endif
+    (*dev->kbdfeed->CtrlProc)(dev,&dev->kbdfeed->ctrl);
+    return TRUE;
+}
+
+Bool
+InitPtrFeedbackClassDeviceStruct(dev, controlProc)
+    DeviceIntPtr dev;
+    PtrCtrlProcPtr controlProc;
+{
+    register PtrFeedbackPtr feedc;
+
+    feedc = (PtrFeedbackPtr)xalloc(sizeof(PtrFeedbackClassRec));
+    if (!feedc)
+       return FALSE;
+    feedc->CtrlProc = controlProc;
+#ifdef sgi
+    feedc->ctrl.num = 1;
+    feedc->ctrl.den = 1;
+    feedc->ctrl.threshold = 1;
+#else
+    feedc->ctrl = defaultPointerControl;
+#endif
+    feedc->ctrl.id = 0;
+    if ( (feedc->next = dev->ptrfeed) )
+        feedc->ctrl.id = dev->ptrfeed->ctrl.id + 1;
+    dev->ptrfeed = feedc;
+    (*controlProc)(dev, &feedc->ctrl);
+    return TRUE;
+}
+
+
+LedCtrl defaultLedControl = {
+       DEFAULT_LEDS, DEFAULT_LEDS_MASK, 0};
+
+BellCtrl defaultBellControl = {
+       DEFAULT_BELL,
+       DEFAULT_BELL_PITCH,
+       DEFAULT_BELL_DURATION,
+       0};
+
+IntegerCtrl defaultIntegerControl = {
+       DEFAULT_INT_RESOLUTION,
+       DEFAULT_INT_MIN_VALUE,
+       DEFAULT_INT_MAX_VALUE,
+       DEFAULT_INT_DISPLAYED,
+       0};
+
+Bool
+InitStringFeedbackClassDeviceStruct (dev, controlProc, max_symbols,
+                                    num_symbols_supported, symbols)
+    DeviceIntPtr dev;
+    StringCtrlProcPtr controlProc;
+    int max_symbols;
+    int num_symbols_supported;
+    KeySym *symbols;
+{
+    int i;
+    register StringFeedbackPtr feedc;
+
+    feedc = (StringFeedbackPtr)xalloc(sizeof(StringFeedbackClassRec));
+    if (!feedc)
+       return FALSE;
+    feedc->CtrlProc = controlProc;
+    feedc->ctrl.num_symbols_supported = num_symbols_supported;
+    feedc->ctrl.num_symbols_displayed = 0;
+    feedc->ctrl.max_symbols = max_symbols;
+    feedc->ctrl.symbols_supported = (KeySym *) 
+       xalloc (sizeof (KeySym) * num_symbols_supported);
+    feedc->ctrl.symbols_displayed = (KeySym *) 
+       xalloc (sizeof (KeySym) * max_symbols);
+    if (!feedc->ctrl.symbols_supported || !feedc->ctrl.symbols_displayed)
+    {
+       if (feedc->ctrl.symbols_supported)
+           xfree(feedc->ctrl.symbols_supported);
+       if (feedc->ctrl.symbols_displayed)
+           xfree(feedc->ctrl.symbols_displayed);
+       xfree(feedc);
+       return FALSE;
+    }
+    for (i=0; i<num_symbols_supported; i++)
+       *(feedc->ctrl.symbols_supported+i) = *symbols++;
+    for (i=0; i<max_symbols; i++)
+       *(feedc->ctrl.symbols_displayed+i) = (KeySym) NULL;
+    feedc->ctrl.id = 0;
+    if ( (feedc->next = dev->stringfeed) )
+       feedc->ctrl.id = dev->stringfeed->ctrl.id + 1;
+    dev->stringfeed = feedc;
+    (*controlProc)(dev, &feedc->ctrl);
+    return TRUE;
+}
+
+Bool
+InitBellFeedbackClassDeviceStruct (dev, bellProc, controlProc)
+    DeviceIntPtr dev;
+    BellProcPtr bellProc;
+    BellCtrlProcPtr controlProc;
+{
+    register BellFeedbackPtr feedc;
+
+    feedc = (BellFeedbackPtr)xalloc(sizeof(BellFeedbackClassRec));
+    if (!feedc)
+       return FALSE;
+    feedc->CtrlProc = controlProc;
+    feedc->BellProc = bellProc;
+    feedc->ctrl = defaultBellControl;
+    feedc->ctrl.id = 0;
+    if ( (feedc->next = dev->bell) )
+       feedc->ctrl.id = dev->bell->ctrl.id + 1;
+    dev->bell = feedc;
+    (*controlProc)(dev, &feedc->ctrl);
+    return TRUE;
+}
+
+Bool
+InitLedFeedbackClassDeviceStruct (dev, controlProc)
+    DeviceIntPtr dev;
+    LedCtrlProcPtr controlProc;
+{
+    register LedFeedbackPtr feedc;
+
+    feedc = (LedFeedbackPtr)xalloc(sizeof(LedFeedbackClassRec));
+    if (!feedc)
+       return FALSE;
+    feedc->CtrlProc = controlProc;
+    feedc->ctrl = defaultLedControl;
+    feedc->ctrl.id = 0;
+    if ( (feedc->next = dev->leds) )
+       feedc->ctrl.id = dev->leds->ctrl.id + 1;
+#ifdef XKB
+    feedc->xkb_sli= NULL;
+#endif
+    dev->leds = feedc;
+    (*controlProc)(dev, &feedc->ctrl);
+    return TRUE;
+}
+
+Bool
+InitIntegerFeedbackClassDeviceStruct (dev, controlProc)
+    DeviceIntPtr dev;
+    IntegerCtrlProcPtr controlProc;
+{
+    register IntegerFeedbackPtr feedc;
+
+    feedc = (IntegerFeedbackPtr)xalloc(sizeof(IntegerFeedbackClassRec));
+    if (!feedc)
+       return FALSE;
+    feedc->CtrlProc = controlProc;
+    feedc->ctrl = defaultIntegerControl;
+    feedc->ctrl.id = 0;
+    if ( (feedc->next = dev->intfeed) )
+       feedc->ctrl.id = dev->intfeed->ctrl.id + 1;
+    dev->intfeed = feedc;
+    (*controlProc)(dev, &feedc->ctrl);
+    return TRUE;
+}
+
+Bool
+InitPointerDeviceStruct(device, map, numButtons, motionProc, controlProc,
+                       numMotionEvents)
+    DevicePtr device;
+    CARD8 *map;
+    int numButtons;
+    PtrCtrlProcPtr controlProc;
+    ValuatorMotionProcPtr motionProc;
+    int numMotionEvents;
+{
+    DeviceIntPtr dev = (DeviceIntPtr)device;
+
+    return(InitButtonClassDeviceStruct(dev, numButtons, map) &&
+          InitValuatorClassDeviceStruct(dev, 2, motionProc,
+                                        numMotionEvents, 0) &&
+          InitPtrFeedbackClassDeviceStruct(dev, controlProc));
+}
+
+Bool
+InitKeyboardDeviceStruct(device, pKeySyms, pModifiers, bellProc, controlProc)
+    DevicePtr device;
+    KeySymsPtr pKeySyms;
+    CARD8 pModifiers[];
+    BellProcPtr bellProc;
+    KbdCtrlProcPtr controlProc;
+{
+    DeviceIntPtr dev = (DeviceIntPtr)device;
+
+    return(InitKeyClassDeviceStruct(dev, pKeySyms, pModifiers) &&
+          InitFocusClassDeviceStruct(dev) &&
+          InitKbdFeedbackClassDeviceStruct(dev, bellProc, controlProc));
+}
+
+void
+SendMappingNotify(request, firstKeyCode, count, client)
+    unsigned int request, count;
+    unsigned int firstKeyCode;
+    ClientPtr  client;
+{
+    int i;
+    xEvent event;
+
+    event.u.u.type = MappingNotify;
+    event.u.mappingNotify.request = request;
+    if (request == MappingKeyboard)
+    {
+        event.u.mappingNotify.firstKeyCode = firstKeyCode;
+        event.u.mappingNotify.count = count;
+    }
+#ifdef XKB
+    if (!noXkbExtension &&
+       ((request == MappingKeyboard) || (request == MappingModifier))) {
+       XkbApplyMappingChange(inputInfo.keyboard,request,firstKeyCode,count,
+                                                                       client);
+    }
+#endif
+
+   /* 0 is the server client */
+    for (i=1; i<currentMaxClients; i++)
+    {
+       if (clients[i] && clients[i]->clientState == ClientStateRunning)
+       {
+#ifdef XKB
+           if (!noXkbExtension &&
+               (request == MappingKeyboard) &&
+               (clients[i]->xkbClientFlags != 0) &&
+               (clients[i]->mapNotifyMask&XkbKeySymsMask))
+               continue;
+#endif
+           event.u.u.sequenceNumber = clients[i]->sequence;
+           WriteEventsToClient(clients[i], 1, &event);
+       }
+    }
+}
+
+/*
+ * n-squared algorithm. n < 255 and don't want to copy the whole thing and
+ * sort it to do the checking. How often is it called? Just being lazy?
+ */
+Bool
+BadDeviceMap(buff, length, low, high, errval)
+    register BYTE *buff;
+    int length;
+    unsigned low, high;
+    XID *errval;
+{
+    register int     i, j;
+
+    for (i = 0; i < length; i++)
+       if (buff[i])                   /* only check non-zero elements */
+       {
+           if ((low > buff[i]) || (high < buff[i]))
+           {
+               *errval = buff[i];
+               return TRUE;
+           }
+           for (j = i + 1; j < length; j++)
+               if (buff[i] == buff[j])
+               {
+                   *errval = buff[i];
+                   return TRUE;
+               }
+       }
+    return FALSE;
+}
+
+Bool
+AllModifierKeysAreUp(dev, map1, per1, map2, per2)
+    register DeviceIntPtr dev;
+    register CARD8 *map1, *map2;
+    int per1, per2;
+{
+    register int i, j, k;
+    register CARD8 *down = dev->key->down;
+
+    for (i = 8; --i >= 0; map2 += per2)
+    {
+       for (j = per1; --j >= 0; map1++)
+       {
+           if (*map1 && BitIsOn(down, *map1))
+           {
+               for (k = per2; (--k >= 0) && (*map1 != map2[k]);)
+                 ;
+               if (k < 0)
+                   return FALSE;
+           }
+       }
+    }
+    return TRUE;
+}
+
+int 
+ProcSetModifierMapping(client)
+    ClientPtr client;
+{
+    xSetModifierMappingReply rep;
+    REQUEST(xSetModifierMappingReq);
+    KeyCode *inputMap;
+    int inputMapLen;
+    register int i;
+    DeviceIntPtr keybd = inputInfo.keyboard;
+    register KeyClassPtr keyc = keybd->key;
+    
+    REQUEST_AT_LEAST_SIZE(xSetModifierMappingReq);
+
+    if (client->req_len != ((stuff->numKeyPerModifier<<1) +
+                           (sizeof (xSetModifierMappingReq)>>2)))
+       return BadLength;
+
+    inputMapLen = 8*stuff->numKeyPerModifier;
+    inputMap = (KeyCode *)&stuff[1];
+
+    /*
+     * Now enforce the restriction that "all of the non-zero keycodes must be
+     * in the range specified by min-keycode and max-keycode in the
+     * connection setup (else a Value error)"
+     */
+    i = inputMapLen;
+    while (i--)
+    {
+       if (inputMap[i]
+           && (inputMap[i] < keyc->curKeySyms.minKeyCode
+               || inputMap[i] > keyc->curKeySyms.maxKeyCode))
+       {
+           client->errorValue = inputMap[i];
+           return BadValue;
+       }
+    }
+
+#ifdef XCSECURITY
+    if (!SecurityCheckDeviceAccess(client, keybd, TRUE))
+       return BadAccess;
+#endif 
+
+#ifdef LBX
+    LbxFlushModifierMapTag();
+#endif
+    rep.type = X_Reply;
+    rep.length = 0;
+    rep.sequenceNumber = client->sequence;
+    rep.success = MappingSuccess;
+
+    /*
+     * Now enforce the restriction that none of the old or new
+     * modifier keys may be down while we change the mapping,  and
+     * that the DDX layer likes the choice.
+     */
+    if (!AllModifierKeysAreUp(keybd, keyc->modifierKeyMap,
+                             (int)keyc->maxKeysPerModifier,
+                             inputMap, (int)stuff->numKeyPerModifier)
+           ||
+       !AllModifierKeysAreUp(keybd, inputMap, (int)stuff->numKeyPerModifier,
+                             keyc->modifierKeyMap,
+                             (int)keyc->maxKeysPerModifier))
+    {
+       rep.success = MappingBusy;
+    }
+    else
+    {
+       for (i = 0; i < inputMapLen; i++)
+       {
+           if (inputMap[i] && !LegalModifier(inputMap[i], (DevicePtr)keybd))
+           {
+               rep.success = MappingFailed;
+               break;
+           }
+       }
+    }
+
+    if (rep.success == MappingSuccess)
+    {
+       KeyCode *map;
+       /*
+        *      Now build the keyboard's modifier bitmap from the
+        *      list of keycodes.
+        */
+       map = (KeyCode *)xalloc(inputMapLen);
+       if (!map && inputMapLen)
+           return BadAlloc;
+       if (keyc->modifierKeyMap)
+           xfree(keyc->modifierKeyMap);
+       keyc->modifierKeyMap = map;
+       memmove((char *)map, (char *)inputMap, inputMapLen);
+
+       keyc->maxKeysPerModifier = stuff->numKeyPerModifier;
+       for (i = 0; i < MAP_LENGTH; i++)
+           keyc->modifierMap[i] = 0;
+       for (i = 0; i < inputMapLen; i++)
+       {
+           if (inputMap[i])
+               keyc->modifierMap[inputMap[i]] |=
+                   (1<<(((unsigned int)i)/keyc->maxKeysPerModifier));
+       }
+    }
+
+    if (rep.success == MappingSuccess)
+        SendMappingNotify(MappingModifier, 0, 0, client);
+
+    WriteReplyToClient(client, sizeof(xSetModifierMappingReply), &rep);
+
+    return(client->noClientException);
+}
+
+int
+ProcGetModifierMapping(client)
+    ClientPtr client;
+{
+    xGetModifierMappingReply rep;
+    register KeyClassPtr keyc = inputInfo.keyboard->key;
+
+    REQUEST_SIZE_MATCH(xReq);
+    rep.type = X_Reply;
+    rep.numKeyPerModifier = keyc->maxKeysPerModifier;
+    rep.sequenceNumber = client->sequence;
+    /* length counts 4 byte quantities - there are 8 modifiers 1 byte big */
+    rep.length = keyc->maxKeysPerModifier << 1;
+
+    WriteReplyToClient(client, sizeof(xGetModifierMappingReply), &rep);
+
+    /* Use the (modified by DDX) map that SetModifierMapping passed in */
+    (void)WriteToClient(client, (int)(keyc->maxKeysPerModifier << 3),
+                       (char *)keyc->modifierKeyMap);
+    return client->noClientException;
+}
+
+int
+ProcChangeKeyboardMapping(client)
+    ClientPtr client;
+{
+    REQUEST(xChangeKeyboardMappingReq);
+    unsigned len;
+    KeySymsRec keysyms;
+    register KeySymsPtr curKeySyms = &inputInfo.keyboard->key->curKeySyms;
+    REQUEST_AT_LEAST_SIZE(xChangeKeyboardMappingReq);
+
+    len = client->req_len - (sizeof(xChangeKeyboardMappingReq) >> 2);  
+    if (len != (stuff->keyCodes * stuff->keySymsPerKeyCode))
+            return BadLength;
+    if ((stuff->firstKeyCode < curKeySyms->minKeyCode) ||
+       (stuff->firstKeyCode > curKeySyms->maxKeyCode))
+    {
+           client->errorValue = stuff->firstKeyCode;
+           return BadValue;
+    }
+    if ( ((unsigned)(stuff->firstKeyCode + stuff->keyCodes - 1) >
+         curKeySyms->maxKeyCode) ||
+       (stuff->keySymsPerKeyCode == 0))
+    {
+           client->errorValue = stuff->keySymsPerKeyCode;
+           return BadValue;
+    }
+#ifdef XCSECURITY
+    if (!SecurityCheckDeviceAccess(client, inputInfo.keyboard,
+                                  TRUE))
+       return BadAccess;
+#endif 
+    keysyms.minKeyCode = stuff->firstKeyCode;
+    keysyms.maxKeyCode = stuff->firstKeyCode + stuff->keyCodes - 1;
+    keysyms.mapWidth = stuff->keySymsPerKeyCode;
+    keysyms.map = (KeySym *)&stuff[1];
+    if (!SetKeySymsMap(curKeySyms, &keysyms))
+       return BadAlloc;
+#ifdef LBX
+    LbxFlushKeyboardMapTag();
+#endif
+    SendMappingNotify(MappingKeyboard, stuff->firstKeyCode, stuff->keyCodes,
+                                                                       client);
+    return client->noClientException;
+
+}
+
+int
+ProcSetPointerMapping(client)
+    ClientPtr client;
+{
+    REQUEST(xSetPointerMappingReq);
+    BYTE *map;
+    xSetPointerMappingReply rep;
+    register unsigned int i;
+    DeviceIntPtr mouse = inputInfo.pointer;
+
+    REQUEST_AT_LEAST_SIZE(xSetPointerMappingReq);
+    if (client->req_len != (sizeof(xSetPointerMappingReq)+stuff->nElts+3) >> 2)
+       return BadLength;
+    rep.type = X_Reply;
+    rep.length = 0;
+    rep.sequenceNumber = client->sequence;
+    rep.success = MappingSuccess;
+    map = (BYTE *)&stuff[1];
+    if (stuff->nElts != mouse->button->numButtons)
+    {
+       client->errorValue = stuff->nElts;
+       return BadValue;
+    }
+    if (BadDeviceMap(&map[0], (int)stuff->nElts, 1, 255, &client->errorValue))
+       return BadValue;
+    for (i=0; i < stuff->nElts; i++)
+       if ((mouse->button->map[i + 1] != map[i]) &&
+           BitIsOn(mouse->button->down, i + 1))
+       {
+           rep.success = MappingBusy;
+           WriteReplyToClient(client, sizeof(xSetPointerMappingReply), &rep);
+            return Success;
+       }
+    for (i = 0; i < stuff->nElts; i++)
+       mouse->button->map[i + 1] = map[i];
+    SendMappingNotify(MappingPointer, 0, 0, client);
+    WriteReplyToClient(client, sizeof(xSetPointerMappingReply), &rep);
+    return Success;
+}
+
+int
+ProcGetKeyboardMapping(client)
+    ClientPtr client;
+{
+    xGetKeyboardMappingReply rep;
+    REQUEST(xGetKeyboardMappingReq);
+    KeySymsPtr curKeySyms = &inputInfo.keyboard->key->curKeySyms;
+
+    REQUEST_SIZE_MATCH(xGetKeyboardMappingReq);
+
+    if ((stuff->firstKeyCode < curKeySyms->minKeyCode) ||
+        (stuff->firstKeyCode > curKeySyms->maxKeyCode))
+    {
+       client->errorValue = stuff->firstKeyCode;
+       return BadValue;
+    }
+    if (stuff->firstKeyCode + stuff->count >
+       (unsigned)(curKeySyms->maxKeyCode + 1))
+    {
+       client->errorValue = stuff->count;
+        return BadValue;
+    }
+
+    rep.type = X_Reply;
+    rep.sequenceNumber = client->sequence;
+    rep.keySymsPerKeyCode = curKeySyms->mapWidth;
+    /* length is a count of 4 byte quantities and KeySyms are 4 bytes */
+    rep.length = (curKeySyms->mapWidth * stuff->count);
+    WriteReplyToClient(client, sizeof(xGetKeyboardMappingReply), &rep);
+    client->pSwapReplyFunc = (ReplySwapPtr) CopySwap32Write;
+    WriteSwappedDataToClient(
+       client,
+       curKeySyms->mapWidth * stuff->count * sizeof(KeySym),
+       &curKeySyms->map[(stuff->firstKeyCode - curKeySyms->minKeyCode) *
+                        curKeySyms->mapWidth]);
+
+    return client->noClientException;
+}
+
+int
+ProcGetPointerMapping(client)
+    ClientPtr client;
+{
+    xGetPointerMappingReply rep;
+    ButtonClassPtr butc = inputInfo.pointer->button;
+
+    REQUEST_SIZE_MATCH(xReq);
+    rep.type = X_Reply;
+    rep.sequenceNumber = client->sequence;
+    rep.nElts = butc->numButtons;
+    rep.length = ((unsigned)rep.nElts + (4-1))/4;
+    WriteReplyToClient(client, sizeof(xGetPointerMappingReply), &rep);
+    (void)WriteToClient(client, (int)rep.nElts, (char *)&butc->map[1]);
+    return Success;    
+}
+
+void
+NoteLedState(keybd, led, on)
+    DeviceIntPtr keybd;
+    int                led;
+    Bool       on;
+{
+    KeybdCtrl *ctrl = &keybd->kbdfeed->ctrl;
+    if (on)
+       ctrl->leds |= ((Leds)1 << (led - 1));
+    else
+       ctrl->leds &= ~((Leds)1 << (led - 1));
+}
+
+int
+Ones(mask)                /* HACKMEM 169 */
+    unsigned long mask;
+{
+    register unsigned long y;
+
+    y = (mask >> 1) &033333333333;
+    y = mask - y - ((y >>1) & 033333333333);
+    return (((y + (y >> 3)) & 030707070707) % 077);
+}
+
+int
+ProcChangeKeyboardControl (client)
+    ClientPtr client;
+{
+#define DO_ALL    (-1)
+    KeybdCtrl ctrl;
+    DeviceIntPtr keybd = inputInfo.keyboard;
+    XID *vlist;
+    int t;
+    int led = DO_ALL;
+    int key = DO_ALL;
+    BITS32 vmask, index2;
+    int mask, i;
+    REQUEST(xChangeKeyboardControlReq);
+
+    REQUEST_AT_LEAST_SIZE(xChangeKeyboardControlReq);
+    vmask = stuff->mask;
+    if (client->req_len != (sizeof(xChangeKeyboardControlReq)>>2)+Ones(vmask))
+       return BadLength;
+#ifdef XCSECURITY
+    if (!SecurityCheckDeviceAccess(client, keybd, TRUE))
+       return BadAccess;
+#endif 
+    vlist = (XID *)&stuff[1];          /* first word of values */
+    ctrl = keybd->kbdfeed->ctrl;
+    while (vmask)
+    {
+       index2 = (BITS32) lowbit (vmask);
+       vmask &= ~index2;
+       switch (index2)
+       {
+       case KBKeyClickPercent: 
+           t = (INT8)*vlist;
+           vlist++;
+           if (t == -1)
+               t = defaultKeyboardControl.click;
+           else if (t < 0 || t > 100)
+           {
+               client->errorValue = t;
+               return BadValue;
+           }
+           ctrl.click = t;
+           break;
+       case KBBellPercent:
+           t = (INT8)*vlist;
+           vlist++;
+           if (t == -1)
+               t = defaultKeyboardControl.bell;
+           else if (t < 0 || t > 100)
+           {
+               client->errorValue = t;
+               return BadValue;
+           }
+           ctrl.bell = t;
+           break;
+       case KBBellPitch:
+           t = (INT16)*vlist;
+           vlist++;
+           if (t == -1)
+               t = defaultKeyboardControl.bell_pitch;
+           else if (t < 0)
+           {
+               client->errorValue = t;
+               return BadValue;
+           }
+           ctrl.bell_pitch = t;
+           break;
+       case KBBellDuration:
+           t = (INT16)*vlist;
+           vlist++;
+           if (t == -1)
+               t = defaultKeyboardControl.bell_duration;
+           else if (t < 0)
+           {
+               client->errorValue = t;
+               return BadValue;
+           }
+           ctrl.bell_duration = t;
+           break;
+       case KBLed:
+           led = (CARD8)*vlist;
+           vlist++;
+           if (led < 1 || led > 32)
+           {
+               client->errorValue = led;
+               return BadValue;
+           }
+           if (!(stuff->mask & KBLedMode))
+               return BadMatch;
+           break;
+       case KBLedMode:
+           t = (CARD8)*vlist;
+           vlist++;
+           if (t == LedModeOff)
+           {
+               if (led == DO_ALL)
+                   ctrl.leds = 0x0;
+               else
+                   ctrl.leds &= ~(((Leds)(1)) << (led - 1));
+           }
+           else if (t == LedModeOn)
+           {
+               if (led == DO_ALL)
+                   ctrl.leds = ~0L;
+               else
+                   ctrl.leds |= (((Leds)(1)) << (led - 1));
+           }
+           else
+           {
+               client->errorValue = t;
+               return BadValue;
+           }
+#ifdef XKB
+           if (!noXkbExtension) {
+               XkbEventCauseRec        cause;
+               XkbSetCauseCoreReq(&cause,X_ChangeKeyboardControl,client);
+               keybd->kbdfeed->ctrl.leds = ctrl.leds;
+               XkbSetIndicators(keybd,((led == DO_ALL) ? ~0L : (1L<<(led-1))),
+                                                       ctrl.leds, &cause);
+           }
+#endif
+           break;
+       case KBKey:
+           key = (KeyCode)*vlist;
+           vlist++;
+           if ((KeyCode)key < inputInfo.keyboard->key->curKeySyms.minKeyCode ||
+               (KeyCode)key > inputInfo.keyboard->key->curKeySyms.maxKeyCode)
+           {
+               client->errorValue = key;
+               return BadValue;
+           }
+           if (!(stuff->mask & KBAutoRepeatMode))
+               return BadMatch;
+           break;
+       case KBAutoRepeatMode:
+           i = (key >> 3);
+           mask = (1 << (key & 7));
+           t = (CARD8)*vlist;
+           vlist++;
+#ifdef XKB
+           if (!noXkbExtension && key != DO_ALL)
+               XkbDisableComputedAutoRepeats(keybd,key);
+#endif
+           if (t == AutoRepeatModeOff)
+           {
+               if (key == DO_ALL)
+                   ctrl.autoRepeat = FALSE;
+               else
+                   ctrl.autoRepeats[i] &= ~mask;
+           }
+           else if (t == AutoRepeatModeOn)
+           {
+               if (key == DO_ALL)
+                   ctrl.autoRepeat = TRUE;
+               else
+                   ctrl.autoRepeats[i] |= mask;
+           }
+           else if (t == AutoRepeatModeDefault)
+           {
+               if (key == DO_ALL)
+                   ctrl.autoRepeat = defaultKeyboardControl.autoRepeat;
+               else
+                   ctrl.autoRepeats[i] =
+                           (ctrl.autoRepeats[i] & ~mask) |
+                           (defaultKeyboardControl.autoRepeats[i] & mask);
+           }
+           else
+           {
+               client->errorValue = t;
+               return BadValue;
+           }
+           break;
+       default:
+           client->errorValue = stuff->mask;
+           return BadValue;
+       }
+    }
+    keybd->kbdfeed->ctrl = ctrl;
+#ifdef XKB
+    /* The XKB RepeatKeys control and core protocol global autorepeat */
+    /* value are linked        */
+    if (!noXkbExtension) {
+       XkbSetRepeatKeys(keybd,key,keybd->kbdfeed->ctrl.autoRepeat);
+    }
+    else
+#endif
+    (*keybd->kbdfeed->CtrlProc)(keybd, &keybd->kbdfeed->ctrl);
+    return Success;
+#undef DO_ALL
+} 
+
+int
+ProcGetKeyboardControl (client)
+    ClientPtr client;
+{
+    int i;
+    register KeybdCtrl *ctrl = &inputInfo.keyboard->kbdfeed->ctrl;
+    xGetKeyboardControlReply rep;
+
+    REQUEST_SIZE_MATCH(xReq);
+    rep.type = X_Reply;
+    rep.length = 5;
+    rep.sequenceNumber = client->sequence;
+    rep.globalAutoRepeat = ctrl->autoRepeat;
+    rep.keyClickPercent = ctrl->click;
+    rep.bellPercent = ctrl->bell;
+    rep.bellPitch = ctrl->bell_pitch;
+    rep.bellDuration = ctrl->bell_duration;
+    rep.ledMask = ctrl->leds;
+    for (i = 0; i < 32; i++)
+       rep.map[i] = ctrl->autoRepeats[i];
+    WriteReplyToClient(client, sizeof(xGetKeyboardControlReply), &rep);
+    return Success;
+} 
+
+int
+ProcBell(client)
+    ClientPtr client;
+{
+    register DeviceIntPtr keybd = inputInfo.keyboard;
+    int base = keybd->kbdfeed->ctrl.bell;
+    int newpercent;
+    REQUEST(xBellReq);
+    REQUEST_SIZE_MATCH(xBellReq);
+    if (stuff->percent < -100 || stuff->percent > 100)
+    {
+       client->errorValue = stuff->percent;
+       return BadValue;
+    }
+    newpercent = (base * stuff->percent) / 100;
+    if (stuff->percent < 0)
+        newpercent = base + newpercent;
+    else
+       newpercent = base - newpercent + stuff->percent;
+#ifdef XKB
+    if (!noXkbExtension)
+       XkbHandleBell(FALSE,FALSE, keybd, newpercent, &keybd->kbdfeed->ctrl, 0, 
+                     None, NULL, client);
+       else
+#endif
+    (*keybd->kbdfeed->BellProc)(newpercent, keybd,
+                               (pointer) &keybd->kbdfeed->ctrl, 0);
+    return Success;
+} 
+
+int
+ProcChangePointerControl(client)
+    ClientPtr client;
+{
+    DeviceIntPtr mouse = inputInfo.pointer;
+    PtrCtrl ctrl;              /* might get BadValue part way through */
+    REQUEST(xChangePointerControlReq);
+
+    REQUEST_SIZE_MATCH(xChangePointerControlReq);
+    ctrl = mouse->ptrfeed->ctrl;
+    if ((stuff->doAccel != xTrue) && (stuff->doAccel != xFalse))
+    {
+       client->errorValue = stuff->doAccel;
+       return(BadValue);
+    }
+    if ((stuff->doThresh != xTrue) && (stuff->doThresh != xFalse))
+    {
+       client->errorValue = stuff->doThresh;
+       return(BadValue);
+    }
+    if (stuff->doAccel)
+    {
+       if (stuff->accelNum == -1)
+           ctrl.num = defaultPointerControl.num;
+       else if (stuff->accelNum < 0)
+       {
+           client->errorValue = stuff->accelNum;
+           return BadValue;
+       }
+       else ctrl.num = stuff->accelNum;
+       if (stuff->accelDenum == -1)
+           ctrl.den = defaultPointerControl.den;
+       else if (stuff->accelDenum <= 0)
+       {
+           client->errorValue = stuff->accelDenum;
+           return BadValue;
+       }
+       else ctrl.den = stuff->accelDenum;
+    }
+    if (stuff->doThresh)
+    {
+       if (stuff->threshold == -1)
+           ctrl.threshold = defaultPointerControl.threshold;
+       else if (stuff->threshold < 0)
+       {
+           client->errorValue = stuff->threshold;
+           return BadValue;
+       }
+       else ctrl.threshold = stuff->threshold;
+    }
+    mouse->ptrfeed->ctrl = ctrl;
+    (*mouse->ptrfeed->CtrlProc)(mouse, &mouse->ptrfeed->ctrl);
+    return Success;
+} 
+
+int
+ProcGetPointerControl(client)
+    ClientPtr client;
+{
+    register PtrCtrl *ctrl = &inputInfo.pointer->ptrfeed->ctrl;
+    xGetPointerControlReply rep;
+
+    REQUEST_SIZE_MATCH(xReq);
+    rep.type = X_Reply;
+    rep.length = 0;
+    rep.sequenceNumber = client->sequence;
+    rep.threshold = ctrl->threshold;
+    rep.accelNumerator = ctrl->num;
+    rep.accelDenominator = ctrl->den;
+    WriteReplyToClient(client, sizeof(xGenericReply), &rep);
+    return Success;
+}
+
+void
+MaybeStopHint(dev, client)
+    register DeviceIntPtr dev;
+    ClientPtr client;
+{
+    GrabPtr grab = dev->grab;
+
+    if ((grab && SameClient(grab, client) &&
+        ((grab->eventMask & PointerMotionHintMask) ||
+         (grab->ownerEvents &&
+          (EventMaskForClient(dev->valuator->motionHintWindow, client) &
+           PointerMotionHintMask)))) ||
+       (!grab &&
+        (EventMaskForClient(dev->valuator->motionHintWindow, client) &
+         PointerMotionHintMask)))
+       dev->valuator->motionHintWindow = NullWindow;
+}
+
+int
+ProcGetMotionEvents(client)
+    ClientPtr client;
+{
+    WindowPtr pWin;
+    xTimecoord * coords = (xTimecoord *) NULL;
+    xGetMotionEventsReply rep;
+    int     i, count, xmin, xmax, ymin, ymax;
+    unsigned long nEvents;
+    DeviceIntPtr mouse = inputInfo.pointer;
+    TimeStamp start, stop;
+    REQUEST(xGetMotionEventsReq);
+
+    REQUEST_SIZE_MATCH(xGetMotionEventsReq);
+    pWin = SecurityLookupWindow(stuff->window, client, TRUE);
+    if (!pWin)
+       return BadWindow;
+    if (mouse->valuator->motionHintWindow)
+       MaybeStopHint(mouse, client);
+    rep.type = X_Reply;
+    rep.sequenceNumber = client->sequence;
+    nEvents = 0;
+    start = ClientTimeToServerTime(stuff->start);
+    stop = ClientTimeToServerTime(stuff->stop);
+    if ((CompareTimeStamps(start, stop) != LATER) &&
+       (CompareTimeStamps(start, currentTime) != LATER) &&
+       mouse->valuator->numMotionEvents)
+    {
+       if (CompareTimeStamps(stop, currentTime) == LATER)
+           stop = currentTime;
+       coords = (xTimecoord *)ALLOCATE_LOCAL(mouse->valuator->numMotionEvents
+                                             * sizeof(xTimecoord));
+       if (!coords)
+           return BadAlloc;
+       count = (*mouse->valuator->GetMotionProc) (mouse, coords,
+                                                  start.milliseconds,
+                                                  stop.milliseconds,
+                                                  pWin->drawable.pScreen);
+       xmin = pWin->drawable.x - wBorderWidth (pWin);
+       xmax = pWin->drawable.x + (int)pWin->drawable.width +
+               wBorderWidth (pWin);
+       ymin = pWin->drawable.y - wBorderWidth (pWin);
+       ymax = pWin->drawable.y + (int)pWin->drawable.height +
+               wBorderWidth (pWin);
+       for (i = 0; i < count; i++)
+           if ((xmin <= coords[i].x) && (coords[i].x < xmax) &&
+                   (ymin <= coords[i].y) && (coords[i].y < ymax))
+           {
+               coords[nEvents].time = coords[i].time;
+               coords[nEvents].x = coords[i].x - pWin->drawable.x;
+               coords[nEvents].y = coords[i].y - pWin->drawable.y;
+               nEvents++;
+           }
+    }
+    rep.length = nEvents * (sizeof(xTimecoord) >> 2);
+    rep.nEvents = nEvents;
+    WriteReplyToClient(client, sizeof(xGetMotionEventsReply), &rep);
+    if (nEvents)
+    {
+       client->pSwapReplyFunc = (ReplySwapPtr) SwapTimeCoordWrite;
+       WriteSwappedDataToClient(client, nEvents * sizeof(xTimecoord),
+                                (char *)coords);
+    }
+    if (coords)
+       DEALLOCATE_LOCAL(coords);
+    return Success;
+}
+
+int
+ProcQueryKeymap(client)
+    ClientPtr client;
+{
+    xQueryKeymapReply rep;
+    int i;
+    CARD8 *down = inputInfo.keyboard->key->down;
+
+    REQUEST_SIZE_MATCH(xReq);
+    rep.type = X_Reply;
+    rep.sequenceNumber = client->sequence;
+    rep.length = 2;
+#ifdef XCSECURITY
+    if (!SecurityCheckDeviceAccess(client, inputInfo.keyboard, TRUE))
+    {
+       bzero((char *)&rep.map[0], 32);
+    }
+    else
+#endif
+    for (i = 0; i<32; i++)
+       rep.map[i] = down[i];
+    WriteReplyToClient(client, sizeof(xQueryKeymapReply), &rep);
+    return Success;
+}
+
+/******************************************************************************
+ * The following entrypoints are provided for binary compatibility with
+ * previous versions (they make casts, where the current version changes types
+ * for more stringent prototype checking).
+ ******************************************************************************/
+#ifdef AddInputDevice
+#undef AddInputDevice
+
+#if NeedFunctionPrototypes
+DevicePtr
+AddInputDevice(
+    DeviceProc deviceProc,
+    Bool autoStart)
+#else
+DevicePtr
+AddInputDevice(deviceProc, autoStart)
+    DeviceProc deviceProc;
+    Bool autoStart;
+#endif
+{
+    return (DevicePtr)_AddInputDevice(deviceProc, autoStart);
+}
+#endif /* AddInputDevice */
+
+#ifdef RegisterPointerDevice
+#undef RegisterPointerDevice
+
+#if NeedFunctionPrototypes
+void
+RegisterPointerDevice(DevicePtr device)
+#else
+void
+RegisterPointerDevice(device)
+    DevicePtr device;
+#endif
+{
+    _RegisterPointerDevice((DeviceIntPtr)device);
+}
+#endif /* RegisterPointerDevice */
+
+#ifdef RegisterKeyboardDevice
+#undef RegisterKeyboardDevice
+
+#if NeedFunctionPrototypes
+void
+RegisterKeyboardDevice(DevicePtr device)
+#else
+void
+RegisterKeyboardDevice(device)
+    DevicePtr device;
+#endif
+{
+    _RegisterKeyboardDevice((DeviceIntPtr)device);
+}
+#endif /* RegisterKeyboardDevice */
diff --git a/Xserver/programs/Xserver/dix/dispatch.c b/Xserver/programs/Xserver/dix/dispatch.c
new file mode 100644 (file)
index 0000000..40179c9
--- /dev/null
@@ -0,0 +1,3955 @@
+/* $XConsortium: dispatch.c /main/195 1996/12/15 21:24:40 rws $ */
+/* $XFree86: xc/programs/Xserver/dix/dispatch.c,v 3.7 1996/12/23 06:29:38 dawes Exp $ */
+/************************************************************
+
+Copyright (c) 1987, 1989  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+
+Copyright 1987, 1989 by Digital Equipment Corporation, Maynard, Massachusetts.
+
+                        All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and its 
+documentation for any purpose and without fee is hereby granted, 
+provided that the above copyright notice appear in all copies and that
+both that copyright notice and this permission notice appear in 
+supporting documentation, and that the name of Digital not be
+used in advertising or publicity pertaining to distribution of the
+software without specific, written prior permission.  
+
+DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
+ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
+DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
+ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+SOFTWARE.
+
+********************************************************/
+
+#include "windowstr.h"
+#include "fontstruct.h"
+#include "dixfontstr.h"
+#include "gcstruct.h"
+#include "selection.h"
+#include "colormapst.h"
+#include "cursorstr.h"
+#include "scrnintstr.h"
+#include "opaque.h"
+#include "input.h"
+#include "servermd.h"
+#include "extnsionst.h"
+#include "dixfont.h"
+#include "dispatch.h"
+#include "swaprep.h"
+#include "swapreq.h"
+#include "dixevents.h"
+#ifdef XCSECURITY
+#define _SECURITY_SERVER
+#include "extensions/security.h"
+#endif
+#ifdef XAPPGROUP
+#include "extensions/Xagsrv.h"
+#endif
+
+#define mskcnt ((MAXCLIENTS + 31) / 32)
+#define BITMASK(i) (1 << ((i) & 31))
+#define MASKIDX(i) ((i) >> 5)
+#define MASKWORD(buf, i) buf[MASKIDX(i)]
+#define BITSET(buf, i) MASKWORD(buf, i) |= BITMASK(i)
+#define BITCLEAR(buf, i) MASKWORD(buf, i) &= ~BITMASK(i)
+#define GETBIT(buf, i) (MASKWORD(buf, i) & BITMASK(i))
+
+extern WindowPtr *WindowTable;
+extern xConnSetupPrefix connSetupPrefix;
+extern char *ConnectionInfo;
+
+Selection *CurrentSelections;
+int NumCurrentSelections;
+
+extern CARD32 defaultScreenSaverTime;
+extern CARD32 defaultScreenSaverInterval;
+extern int  defaultScreenSaverBlanking;
+extern int  defaultScreenSaverAllowExposures;
+static ClientPtr grabClient;
+#define GrabNone 0
+#define GrabActive 1
+#define GrabKickout 2
+static int grabState = GrabNone;
+static long grabWaiters[mskcnt];
+CallbackListPtr ServerGrabCallback = NULL;
+HWEventQueuePtr checkForInput[2];
+extern int connBlockScreenStart;
+
+#ifdef XKB
+extern Bool noXkbExtension;
+#endif
+
+static void KillAllClients(
+#if NeedFunctionPrototypes
+    void
+#endif
+);
+
+static void DeleteClientFromAnySelections(
+#if NeedFunctionPrototypes
+    ClientPtr /*client*/
+#endif
+);
+
+#ifdef LBX
+extern unsigned long  StandardRequestLength();
+#endif
+
+static int nextFreeClientID; /* always MIN free client ID */
+
+static int     nClients;       /* number of authorized clients */
+
+CallbackListPtr ClientStateCallback;
+char dispatchException = 0;
+char isItTimeToYield;
+
+/* Various of the DIX function interfaces were not designed to allow
+ * the client->errorValue to be set on BadValue and other errors.
+ * Rather than changing interfaces and breaking untold code we introduce
+ * a new global that dispatch can use.
+ */
+XID clientErrorValue;   /* XXX this is a kludge */
+
+#define SAME_SCREENS(a, b) (\
+    (a.pScreen == b.pScreen))
+
+void
+SetInputCheck(c0, c1)
+    HWEventQueuePtr c0, c1;
+{
+    checkForInput[0] = c0;
+    checkForInput[1] = c1;
+}
+
+void
+UpdateCurrentTime()
+{
+    TimeStamp systime;
+
+    /* To avoid time running backwards, we must call GetTimeInMillis before
+     * calling ProcessInputEvents.
+     */
+    systime.months = currentTime.months;
+    systime.milliseconds = GetTimeInMillis();
+    if (systime.milliseconds < currentTime.milliseconds)
+       systime.months++;
+    if (*checkForInput[0] != *checkForInput[1])
+       ProcessInputEvents();
+    if (CompareTimeStamps(systime, currentTime) == LATER)
+       currentTime = systime;
+}
+
+/* Like UpdateCurrentTime, but can't call ProcessInputEvents */
+void
+UpdateCurrentTimeIf()
+{
+    TimeStamp systime;
+
+    systime.months = currentTime.months;
+    systime.milliseconds = GetTimeInMillis();
+    if (systime.milliseconds < currentTime.milliseconds)
+       systime.months++;
+    if (*checkForInput[0] == *checkForInput[1])
+       currentTime = systime;
+}
+
+void
+InitSelections()
+{
+    if (CurrentSelections)
+       xfree(CurrentSelections);
+    CurrentSelections = (Selection *)NULL;
+    NumCurrentSelections = 0;
+}
+
+void 
+FlushClientCaches(id)
+    XID id;
+{
+    int i;
+    register ClientPtr client;
+
+    client = clients[CLIENT_ID(id)];
+    if (client == NullClient)
+        return ;
+    for (i=0; i<currentMaxClients; i++)
+    {
+       client = clients[i];
+        if (client != NullClient)
+       {
+            if (client->lastDrawableID == id)
+           {
+               client->lastDrawableID = WindowTable[0]->drawable.id;
+               client->lastDrawable = (DrawablePtr)WindowTable[0];
+           }
+            else if (client->lastGCID == id)
+           {
+                client->lastGCID = INVALID;
+               client->lastGC = (GCPtr)NULL;
+           }
+       }
+    }
+}
+
+#define MAJOROP ((xReq *)client->requestBuffer)->reqType
+
+void
+Dispatch()
+{
+    register int        *clientReady;     /* array of request ready clients */
+    register int       result;
+    register ClientPtr client;
+    register int       nready;
+    register HWEventQueuePtr* icheck = checkForInput;
+
+    nextFreeClientID = 1;
+    InitSelections();
+    nClients = 0;
+
+    clientReady = (int *) ALLOCATE_LOCAL(sizeof(int) * MaxClients);
+    if (!clientReady)
+       return;
+
+    while (!dispatchException)
+    {
+        if (*icheck[0] != *icheck[1])
+       {
+           ProcessInputEvents();
+           FlushIfCriticalOutputPending();
+       }
+
+       nready = WaitForSomething(clientReady);
+
+       /***************** 
+       *  Handle events in round robin fashion, doing input between 
+       *  each round 
+       *****************/
+
+       while (!dispatchException && (--nready >= 0))
+       {
+           client = clients[clientReady[nready]];
+           if (! client)
+           {
+               /* KillClient can cause this to happen */
+               continue;
+           }
+           /* GrabServer activation can cause this to be true */
+           if (grabState == GrabKickout)
+           {
+               grabState = GrabActive;
+               break;
+           }
+           isItTimeToYield = FALSE;
+            requestingClient = client;
+           while (!isItTimeToYield)
+           {
+               if (*icheck[0] != *icheck[1])
+               {
+                   ProcessInputEvents();
+                   FlushIfCriticalOutputPending();
+               }
+          
+               /* now, finally, deal with client requests */
+
+               result = ReadRequestFromClient(client);
+               if (result <= 0) 
+               {
+                   if (result < 0)
+                       CloseDownClient(client);
+                   break;
+               }
+
+               client->sequence++;
+#ifdef DEBUG
+               if (client->requestLogIndex == MAX_REQUEST_LOG)
+                   client->requestLogIndex = 0;
+               client->requestLog[client->requestLogIndex] = MAJOROP;
+               client->requestLogIndex++;
+#endif
+               if (result > (MAX_BIG_REQUEST_SIZE << 2))
+                   result = BadLength;
+               else
+                   result = (* client->requestVector[MAJOROP])(client);
+           
+               if (result != Success) 
+               {
+                   if (client->noClientException != Success)
+                        CloseDownClient(client);
+                    else
+                       SendErrorToClient(client, MAJOROP,
+                                         MinorOpcodeOfRequest(client),
+                                         client->errorValue, result);
+                   break;
+               }
+           }
+           FlushAllOutput();
+
+           requestingClient = NULL;
+       }
+       dispatchException &= ~DE_PRIORITYCHANGE;
+    }
+    KillAllClients();
+    DEALLOCATE_LOCAL(clientReady);
+    dispatchException &= ~DE_RESET;
+}
+
+#undef MAJOROP
+
+/*ARGSUSED*/
+int
+ProcBadRequest(client)
+    ClientPtr client;
+{
+    return (BadRequest);
+}
+
+int
+ProcCreateWindow(client)
+    register ClientPtr client;
+{
+    register WindowPtr pParent, pWin;
+    REQUEST(xCreateWindowReq);
+    int result;
+    int len;
+
+    REQUEST_AT_LEAST_SIZE(xCreateWindowReq);
+    
+    LEGAL_NEW_RESOURCE(stuff->wid, client);
+    if (!(pParent = (WindowPtr)SecurityLookupWindow(stuff->parent, client,
+                                                   SecurityWriteAccess)))
+        return BadWindow;
+    len = client->req_len - (sizeof(xCreateWindowReq) >> 2);
+    if (Ones(stuff->mask) != len)
+        return BadLength;
+    if (!stuff->width || !stuff->height)
+    {
+       client->errorValue = 0;
+        return BadValue;
+    }
+    pWin = CreateWindow(stuff->wid, pParent, stuff->x,
+                             stuff->y, stuff->width, stuff->height, 
+                             stuff->borderWidth, stuff->class,
+                             stuff->mask, (XID *) &stuff[1], 
+                             (int)stuff->depth, 
+                             client, stuff->visual, &result);
+    if (pWin)
+    {
+       Mask mask = pWin->eventMask;
+
+       pWin->eventMask = 0; /* subterfuge in case AddResource fails */
+       if (!AddResource(stuff->wid, RT_WINDOW, (pointer)pWin))
+           return BadAlloc;
+       pWin->eventMask = mask;
+    }
+    if (client->noClientException != Success)
+        return(client->noClientException);
+    else
+        return(result);
+}
+
+int
+ProcChangeWindowAttributes(client)
+    register ClientPtr client;
+{
+    register WindowPtr pWin;
+    REQUEST(xChangeWindowAttributesReq);
+    register int result;
+    int len;
+
+    REQUEST_AT_LEAST_SIZE(xChangeWindowAttributesReq);
+    pWin = (WindowPtr)SecurityLookupWindow(stuff->window, client,
+                                          SecurityWriteAccess);
+    if (!pWin)
+        return(BadWindow);
+    len = client->req_len - (sizeof(xChangeWindowAttributesReq) >> 2);
+    if (len != Ones(stuff->valueMask))
+        return BadLength;
+    result =  ChangeWindowAttributes(pWin, 
+                                 stuff->valueMask, 
+                                 (XID *) &stuff[1], 
+                                 client);
+    if (client->noClientException != Success)
+        return(client->noClientException);
+    else
+        return(result);
+}
+
+int
+ProcGetWindowAttributes(client)
+    register ClientPtr client;
+{
+    register WindowPtr pWin;
+    REQUEST(xResourceReq);
+    xGetWindowAttributesReply wa;
+
+    REQUEST_SIZE_MATCH(xResourceReq);
+    pWin = (WindowPtr)SecurityLookupWindow(stuff->id, client,
+                                          SecurityReadAccess);
+    if (!pWin)
+        return(BadWindow);
+    GetWindowAttributes(pWin, client, &wa);
+    WriteReplyToClient(client, sizeof(xGetWindowAttributesReply), &wa);
+    return(client->noClientException);
+}
+
+int
+ProcDestroyWindow(client)
+    register ClientPtr client;
+{
+    register WindowPtr pWin;
+    REQUEST(xResourceReq);
+
+    REQUEST_SIZE_MATCH(xResourceReq);
+    pWin = (WindowPtr)SecurityLookupWindow(stuff->id, client,
+                                          SecurityDestroyAccess);
+    if (!pWin)
+        return(BadWindow);
+    if (pWin->parent)
+       FreeResource(stuff->id, RT_NONE);
+    return(client->noClientException);
+}
+
+int
+ProcDestroySubwindows(client)
+    register ClientPtr client;
+{
+    register WindowPtr pWin;
+    REQUEST(xResourceReq);
+
+    REQUEST_SIZE_MATCH(xResourceReq);
+    pWin = (WindowPtr)SecurityLookupWindow(stuff->id, client,
+                                          SecurityDestroyAccess);
+    if (!pWin)
+        return(BadWindow);
+    DestroySubwindows(pWin, client);
+    return(client->noClientException);
+}
+
+int
+ProcChangeSaveSet(client)
+    register ClientPtr client;
+{
+    register WindowPtr pWin;
+    REQUEST(xChangeSaveSetReq);
+    register int result;
+                 
+    REQUEST_SIZE_MATCH(xChangeSaveSetReq);
+    pWin = (WindowPtr)SecurityLookupWindow(stuff->window, client,
+                                          SecurityReadAccess);
+    if (!pWin)
+        return(BadWindow);
+    if (client->clientAsMask == (CLIENT_BITS(pWin->drawable.id)))
+        return BadMatch;
+    if ((stuff->mode == SetModeInsert) || (stuff->mode == SetModeDelete))
+    {
+        result = AlterSaveSetForClient(client, pWin, stuff->mode);
+       if (client->noClientException != Success)
+           return(client->noClientException);
+       else
+            return(result);
+    }
+    else
+    {
+       client->errorValue = stuff->mode;
+       return( BadValue );
+    }
+}
+
+int
+ProcReparentWindow(client)
+    register ClientPtr client;
+{
+    register WindowPtr pWin, pParent;
+    REQUEST(xReparentWindowReq);
+    register int result;
+
+    REQUEST_SIZE_MATCH(xReparentWindowReq);
+    pWin = (WindowPtr)SecurityLookupWindow(stuff->window, client,
+                                          SecurityWriteAccess);
+    if (!pWin)
+        return(BadWindow);
+    pParent = (WindowPtr)SecurityLookupWindow(stuff->parent, client,
+                                             SecurityWriteAccess);
+    if (!pParent)
+        return(BadWindow);
+    if (SAME_SCREENS(pWin->drawable, pParent->drawable))
+    {
+        if ((pWin->backgroundState == ParentRelative) &&
+            (pParent->drawable.depth != pWin->drawable.depth))
+            return BadMatch;
+       if ((pWin->drawable.class != InputOnly) &&
+           (pParent->drawable.class == InputOnly))
+           return BadMatch;
+        result =  ReparentWindow(pWin, pParent, 
+                        (short)stuff->x, (short)stuff->y, client);
+       if (client->noClientException != Success)
+            return(client->noClientException);
+       else
+            return(result);
+    }
+    else 
+        return (BadMatch);
+}
+
+int
+ProcMapWindow(client)
+    register ClientPtr client;
+{
+    register WindowPtr pWin;
+    REQUEST(xResourceReq);
+
+    REQUEST_SIZE_MATCH(xResourceReq);
+    pWin = (WindowPtr)SecurityLookupWindow(stuff->id, client,
+                                          SecurityReadAccess);
+    if (!pWin)
+        return(BadWindow);
+    MapWindow(pWin, client);
+           /* update cache to say it is mapped */
+    return(client->noClientException);
+}
+
+int
+ProcMapSubwindows(client)
+    register ClientPtr client;
+{
+    register WindowPtr pWin;
+    REQUEST(xResourceReq);
+
+    REQUEST_SIZE_MATCH(xResourceReq);
+    pWin = (WindowPtr)SecurityLookupWindow( stuff->id, client,
+                                           SecurityReadAccess);
+    if (!pWin)
+        return(BadWindow);
+    MapSubwindows(pWin, client);
+           /* update cache to say it is mapped */
+    return(client->noClientException);
+}
+
+int
+ProcUnmapWindow(client)
+    register ClientPtr client;
+{
+    register WindowPtr pWin;
+    REQUEST(xResourceReq);
+
+    REQUEST_SIZE_MATCH(xResourceReq);
+    pWin = (WindowPtr)SecurityLookupWindow( stuff->id, client,
+                                           SecurityReadAccess);
+    if (!pWin)
+        return(BadWindow);
+    UnmapWindow(pWin, FALSE);
+           /* update cache to say it is mapped */
+    return(client->noClientException);
+}
+
+int
+ProcUnmapSubwindows(client)
+    register ClientPtr client;
+{
+    register WindowPtr pWin;
+    REQUEST(xResourceReq);
+
+    REQUEST_SIZE_MATCH(xResourceReq);
+    pWin = (WindowPtr)SecurityLookupWindow( stuff->id, client,
+                                           SecurityReadAccess);
+    if (!pWin)
+        return(BadWindow);
+    UnmapSubwindows(pWin);
+    return(client->noClientException);
+}
+
+int
+ProcConfigureWindow(client)
+    register ClientPtr client;
+{
+    register WindowPtr pWin;
+    REQUEST(xConfigureWindowReq);
+    register int result;
+    int len;
+
+    REQUEST_AT_LEAST_SIZE(xConfigureWindowReq);
+    pWin = (WindowPtr)SecurityLookupWindow( stuff->window, client,
+                                           SecurityWriteAccess);
+    if (!pWin)
+        return(BadWindow);
+    len = client->req_len - (sizeof(xConfigureWindowReq) >> 2);
+    if (Ones((Mask)stuff->mask) != len)
+        return BadLength;
+    result =  ConfigureWindow(pWin, (Mask)stuff->mask, (XID *) &stuff[1], 
+                             client);
+    if (client->noClientException != Success)
+        return(client->noClientException);
+    else
+        return(result);
+}
+
+int
+ProcCirculateWindow(client)
+    register ClientPtr client;
+{
+    register WindowPtr pWin;
+    REQUEST(xCirculateWindowReq);
+
+    REQUEST_SIZE_MATCH(xCirculateWindowReq);
+    if ((stuff->direction != RaiseLowest) &&
+       (stuff->direction != LowerHighest))
+    {
+       client->errorValue = stuff->direction;
+        return BadValue;
+    }
+    pWin = (WindowPtr)SecurityLookupWindow(stuff->window, client,
+                                          SecurityWriteAccess);
+    if (!pWin)
+        return(BadWindow);
+    CirculateWindow(pWin, (int)stuff->direction, client);
+    return(client->noClientException);
+}
+
+int
+GetGeometry(client, rep)
+    register ClientPtr client;
+    xGetGeometryReply *rep;
+{
+    register DrawablePtr pDraw;
+    REQUEST(xResourceReq);
+
+    REQUEST_SIZE_MATCH(xResourceReq);
+    SECURITY_VERIFY_GEOMETRABLE (pDraw, stuff->id, client, SecurityReadAccess);
+    rep->type = X_Reply;
+    rep->length = 0;
+    rep->sequenceNumber = client->sequence;
+    rep->root = WindowTable[pDraw->pScreen->myNum]->drawable.id;
+    rep->depth = pDraw->depth;
+    rep->width = pDraw->width;
+    rep->height = pDraw->height;
+
+    /* XXX - Because the pixmap-implementation of the multibuffer extension 
+     *       may have the buffer-id's drawable resource value be a pointer
+     *       to the buffer's window instead of the buffer itself
+     *       (this happens if the buffer is the displayed buffer),
+     *       we also have to check that the id matches before we can
+     *       truly say that it is a DRAWABLE_WINDOW.
+     */
+
+    if ((pDraw->type == UNDRAWABLE_WINDOW) ||
+        ((pDraw->type == DRAWABLE_WINDOW) && (stuff->id == pDraw->id)))
+    {
+        register WindowPtr pWin = (WindowPtr)pDraw;
+       rep->x = pWin->origin.x - wBorderWidth (pWin);
+       rep->y = pWin->origin.y - wBorderWidth (pWin);
+       rep->borderWidth = pWin->borderWidth;
+    }
+    else /* DRAWABLE_PIXMAP or DRAWABLE_BUFFER */
+    {
+       rep->x = rep->y = rep->borderWidth = 0;
+    }
+
+    return Success;
+}
+
+
+int
+ProcGetGeometry(client)
+    register ClientPtr client;
+{
+    xGetGeometryReply rep;
+    int status;
+
+    if ((status = GetGeometry(client, &rep)) != Success)
+       return status;
+
+    WriteReplyToClient(client, sizeof(xGetGeometryReply), &rep);
+    return(client->noClientException);
+}
+
+
+int
+ProcQueryTree(client)
+    register ClientPtr client;
+{
+
+    xQueryTreeReply reply;
+    int numChildren = 0;
+    register WindowPtr pChild, pWin, pHead;
+    Window  *childIDs = (Window *)NULL;
+    REQUEST(xResourceReq);
+
+    REQUEST_SIZE_MATCH(xResourceReq);
+    pWin = (WindowPtr)SecurityLookupWindow(stuff->id, client,
+                                          SecurityReadAccess);
+    if (!pWin)
+        return(BadWindow);
+    reply.type = X_Reply;
+    reply.root = WindowTable[pWin->drawable.pScreen->myNum]->drawable.id;
+    reply.sequenceNumber = client->sequence;
+    if (pWin->parent)
+       reply.parent = pWin->parent->drawable.id;
+    else
+        reply.parent = (Window)None;
+
+    pHead = RealChildHead(pWin);
+    for (pChild = pWin->lastChild; pChild != pHead; pChild = pChild->prevSib)
+       numChildren++;
+    if (numChildren)
+    {
+       int curChild = 0;
+
+       childIDs = (Window *) ALLOCATE_LOCAL(numChildren * sizeof(Window));
+       if (!childIDs)
+           return BadAlloc;
+       for (pChild = pWin->lastChild; pChild != pHead; pChild = pChild->prevSib)
+           childIDs[curChild++] = pChild->drawable.id;
+    }
+    
+    reply.nChildren = numChildren;
+    reply.length = (numChildren * sizeof(Window)) >> 2;
+    
+    WriteReplyToClient(client, sizeof(xQueryTreeReply), &reply);
+    if (numChildren)
+    {
+       client->pSwapReplyFunc = (ReplySwapPtr) Swap32Write;
+       WriteSwappedDataToClient(client, numChildren * sizeof(Window), childIDs);
+       DEALLOCATE_LOCAL(childIDs);
+    }
+
+    return(client->noClientException);
+}
+
+int
+ProcInternAtom(client)
+    register ClientPtr client;
+{
+    Atom atom;
+    char *tchar;
+    REQUEST(xInternAtomReq);
+
+    REQUEST_FIXED_SIZE(xInternAtomReq, stuff->nbytes);
+    if ((stuff->onlyIfExists != xTrue) && (stuff->onlyIfExists != xFalse))
+    {
+       client->errorValue = stuff->onlyIfExists;
+        return(BadValue);
+    }
+    tchar = (char *) &stuff[1];
+    atom = MakeAtom(tchar, stuff->nbytes, !stuff->onlyIfExists);
+    if (atom != BAD_RESOURCE)
+    {
+       xInternAtomReply reply;
+       reply.type = X_Reply;
+       reply.length = 0;
+       reply.sequenceNumber = client->sequence;
+       reply.atom = atom;
+       WriteReplyToClient(client, sizeof(xInternAtomReply), &reply);
+       return(client->noClientException);
+    }
+    else
+       return (BadAlloc);
+}
+
+int
+ProcGetAtomName(client)
+    register ClientPtr client;
+{
+    char *str;
+    xGetAtomNameReply reply;
+    int len;
+    REQUEST(xResourceReq);
+
+    REQUEST_SIZE_MATCH(xResourceReq);
+    if ( (str = NameForAtom(stuff->id)) )
+    {
+       len = strlen(str);
+       reply.type = X_Reply;
+       reply.length = (len + 3) >> 2;
+       reply.sequenceNumber = client->sequence;
+       reply.nameLength = len;
+       WriteReplyToClient(client, sizeof(xGetAtomNameReply), &reply);
+       (void)WriteToClient(client, len, str);
+       return(client->noClientException);
+    }
+    else 
+    { 
+       client->errorValue = stuff->id;
+       return (BadAtom);
+    }
+}
+
+#ifdef K5AUTH
+extern int k5_bad();
+#endif
+
+int
+ProcSetSelectionOwner(client)
+    register ClientPtr client;
+{
+    WindowPtr pWin;
+    TimeStamp time;
+    REQUEST(xSetSelectionOwnerReq);
+
+    REQUEST_SIZE_MATCH(xSetSelectionOwnerReq);
+    UpdateCurrentTime();
+    time = ClientTimeToServerTime(stuff->time);
+
+    /* If the client's time stamp is in the future relative to the server's
+       time stamp, do not set the selection, just return success. */
+    if (CompareTimeStamps(time, currentTime) == LATER)
+       return Success;
+    if (stuff->window != None)
+    {
+        pWin = (WindowPtr)SecurityLookupWindow(stuff->window, client,
+                                              SecurityReadAccess);
+        if (!pWin)
+            return(BadWindow);
+    }
+    else
+        pWin = (WindowPtr)None;
+    if (ValidAtom(stuff->selection))
+    {
+       int i = 0;
+
+       /*
+        * First, see if the selection is already set... 
+        */
+       while ((i < NumCurrentSelections) && 
+              CurrentSelections[i].selection != stuff->selection) 
+            i++;
+        if (i < NumCurrentSelections)
+        {        
+           xEvent event;
+
+           /* If the timestamp in client's request is in the past relative
+               to the time stamp indicating the last time the owner of the
+               selection was set, do not set the selection, just return 
+               success. */
+            if (CompareTimeStamps(time, CurrentSelections[i].lastTimeChanged)
+               == EARLIER)
+               return Success;
+           if (CurrentSelections[i].client &&
+               (!pWin || (CurrentSelections[i].client != client)))
+           {
+               event.u.u.type = SelectionClear;
+               event.u.selectionClear.time = time.milliseconds;
+               event.u.selectionClear.window = CurrentSelections[i].window;
+               event.u.selectionClear.atom = CurrentSelections[i].selection;
+               (void) TryClientEvents (CurrentSelections[i].client, &event, 1,
+                               NoEventMask, NoEventMask /* CantBeFiltered */,
+                               NullGrab);
+           }
+       }
+       else
+       {
+           /*
+            * It doesn't exist, so add it...
+            */
+           Selection *newsels;
+
+           if (i == 0)
+               newsels = (Selection *)xalloc(sizeof(Selection));
+           else
+               newsels = (Selection *)xrealloc(CurrentSelections,
+                           (NumCurrentSelections + 1) * sizeof(Selection));
+           if (!newsels)
+               return BadAlloc;
+           NumCurrentSelections++;
+           CurrentSelections = newsels;
+           CurrentSelections[i].selection = stuff->selection;
+       }
+        CurrentSelections[i].lastTimeChanged = time;
+       CurrentSelections[i].window = stuff->window;
+       CurrentSelections[i].pWin = pWin;
+       CurrentSelections[i].client = (pWin ? client : NullClient);
+       return (client->noClientException);
+    }
+    else 
+    {
+       client->errorValue = stuff->selection;
+        return (BadAtom);
+    }
+}
+
+int
+ProcGetSelectionOwner(client)
+    register ClientPtr client;
+{
+    REQUEST(xResourceReq);
+
+    REQUEST_SIZE_MATCH(xResourceReq);
+    if (ValidAtom(stuff->id))
+    {
+       int i;
+        xGetSelectionOwnerReply reply;
+
+       i = 0;
+        while ((i < NumCurrentSelections) && 
+              CurrentSelections[i].selection != stuff->id) i++;
+        reply.type = X_Reply;
+       reply.length = 0;
+       reply.sequenceNumber = client->sequence;
+        if (i < NumCurrentSelections)
+            reply.owner = CurrentSelections[i].window;
+        else
+            reply.owner = None;
+        WriteReplyToClient(client, sizeof(xGetSelectionOwnerReply), &reply);
+        return(client->noClientException);
+    }
+    else            
+    {
+       client->errorValue = stuff->id;
+        return (BadAtom); 
+    }
+}
+
+int
+ProcConvertSelection(client)
+    register ClientPtr client;
+{
+    Bool paramsOkay;
+    xEvent event;
+    WindowPtr pWin;
+    REQUEST(xConvertSelectionReq);
+
+    REQUEST_SIZE_MATCH(xConvertSelectionReq);
+    pWin = (WindowPtr)SecurityLookupWindow(stuff->requestor, client,
+                                          SecurityReadAccess);
+    if (!pWin)
+        return(BadWindow);
+
+    paramsOkay = (ValidAtom(stuff->selection) && ValidAtom(stuff->target));
+    if (stuff->property != None)
+       paramsOkay &= ValidAtom(stuff->property);
+    if (paramsOkay)
+    {
+       int i;
+
+       i = 0;
+       while ((i < NumCurrentSelections) && 
+              CurrentSelections[i].selection != stuff->selection) i++;
+       if ((i < NumCurrentSelections) && 
+           (CurrentSelections[i].window != None)
+#ifdef XCSECURITY
+           && (!client->CheckAccess ||
+               (* client->CheckAccess)(client, CurrentSelections[i].window,
+                                       RT_WINDOW, SecurityReadAccess,
+                                       CurrentSelections[i].pWin))
+#endif
+           )
+       {        
+           event.u.u.type = SelectionRequest;
+           event.u.selectionRequest.time = stuff->time;
+           event.u.selectionRequest.owner = 
+                       CurrentSelections[i].window;
+           event.u.selectionRequest.requestor = stuff->requestor;
+           event.u.selectionRequest.selection = stuff->selection;
+           event.u.selectionRequest.target = stuff->target;
+           event.u.selectionRequest.property = stuff->property;
+           if (TryClientEvents(
+               CurrentSelections[i].client, &event, 1, NoEventMask,
+               NoEventMask /* CantBeFiltered */, NullGrab))
+               return (client->noClientException);
+       }
+       event.u.u.type = SelectionNotify;
+       event.u.selectionNotify.time = stuff->time;
+       event.u.selectionNotify.requestor = stuff->requestor;
+       event.u.selectionNotify.selection = stuff->selection;
+       event.u.selectionNotify.target = stuff->target;
+       event.u.selectionNotify.property = None;
+       (void) TryClientEvents(client, &event, 1, NoEventMask,
+                              NoEventMask /* CantBeFiltered */, NullGrab);
+       return (client->noClientException);
+    }
+    else 
+    {
+       client->errorValue = stuff->property;
+        return (BadAtom);
+    }
+}
+
+int
+ProcGrabServer(client)
+    register ClientPtr client;
+{
+    REQUEST_SIZE_MATCH(xReq);
+    if (grabState != GrabNone && client != grabClient)
+    {
+       ResetCurrentRequest(client);
+       client->sequence--;
+       BITSET(grabWaiters, client->index);
+       IgnoreClient(client);
+       return(client->noClientException);
+    }
+    OnlyListenToOneClient(client);
+    grabState = GrabKickout;
+    grabClient = client;
+
+    if (ServerGrabCallback)
+    {
+       ServerGrabInfoRec grabinfo;
+       grabinfo.client = client;
+       grabinfo.grabstate  = SERVER_GRABBED;
+       CallCallbacks(&ServerGrabCallback, (pointer)&grabinfo);
+    }
+
+    return(client->noClientException);
+}
+
+static void
+#if NeedFunctionPrototypes
+UngrabServer(ClientPtr client)
+#else
+UngrabServer(client)
+    ClientPtr client;
+#endif
+{
+    int i;
+
+    grabState = GrabNone;
+    ListenToAllClients();
+    for (i = mskcnt; --i >= 0 && !grabWaiters[i]; )
+       ;
+    if (i >= 0)
+    {
+       i <<= 5;
+       while (!GETBIT(grabWaiters, i))
+           i++;
+       BITCLEAR(grabWaiters, i);
+       AttendClient(clients[i]);
+    }
+
+    if (ServerGrabCallback)
+    {
+       ServerGrabInfoRec grabinfo;
+       grabinfo.client = client;
+       grabinfo.grabstate  = SERVER_UNGRABBED;
+       CallCallbacks(&ServerGrabCallback, (pointer)&grabinfo);
+    }
+}
+
+int
+ProcUngrabServer(client)
+    register ClientPtr client;
+{
+    REQUEST_SIZE_MATCH(xReq);
+    UngrabServer(client);
+    return(client->noClientException);
+}
+
+int
+ProcTranslateCoords(client)
+    register ClientPtr client;
+{
+    REQUEST(xTranslateCoordsReq);
+
+    register WindowPtr pWin, pDst;
+    xTranslateCoordsReply rep;
+
+    REQUEST_SIZE_MATCH(xTranslateCoordsReq);
+    pWin = (WindowPtr)SecurityLookupWindow(stuff->srcWid, client,
+                                          SecurityReadAccess);
+    if (!pWin)
+        return(BadWindow);
+    pDst = (WindowPtr)SecurityLookupWindow(stuff->dstWid, client,
+                                          SecurityReadAccess);
+    if (!pDst)
+        return(BadWindow);
+    rep.type = X_Reply;
+    rep.length = 0;
+    rep.sequenceNumber = client->sequence;
+    if (!SAME_SCREENS(pWin->drawable, pDst->drawable))
+    {
+       rep.sameScreen = xFalse;
+        rep.child = None;
+       rep.dstX = rep.dstY = 0;
+    }
+    else
+    {
+       INT16 x, y;
+       rep.sameScreen = xTrue;
+       rep.child = None;
+       /* computing absolute coordinates -- adjust to destination later */
+       x = pWin->drawable.x + stuff->srcX;
+       y = pWin->drawable.y + stuff->srcY;
+       pWin = pDst->firstChild;
+       while (pWin)
+       {
+#ifdef SHAPE
+           BoxRec  box;
+#endif
+           if ((pWin->mapped) &&
+               (x >= pWin->drawable.x - wBorderWidth (pWin)) &&
+               (x < pWin->drawable.x + (int)pWin->drawable.width +
+                wBorderWidth (pWin)) &&
+               (y >= pWin->drawable.y - wBorderWidth (pWin)) &&
+               (y < pWin->drawable.y + (int)pWin->drawable.height +
+                wBorderWidth (pWin))
+#ifdef SHAPE
+               /* When a window is shaped, a further check
+                * is made to see if the point is inside
+                * borderSize
+                */
+               && (!wBoundingShape(pWin) ||
+                   POINT_IN_REGION(pWin->drawable.pScreen, 
+                                       &pWin->borderSize, x, y, &box))
+#endif
+               )
+            {
+               rep.child = pWin->drawable.id;
+               pWin = (WindowPtr) NULL;
+           }
+           else
+               pWin = pWin->nextSib;
+       }
+       /* adjust to destination coordinates */
+       rep.dstX = x - pDst->drawable.x;
+       rep.dstY = y - pDst->drawable.y;
+    }
+    WriteReplyToClient(client, sizeof(xTranslateCoordsReply), &rep);
+    return(client->noClientException);
+}
+
+int
+ProcOpenFont(client)
+    register ClientPtr client;
+{
+    int        err;
+    REQUEST(xOpenFontReq);
+
+    REQUEST_FIXED_SIZE(xOpenFontReq, stuff->nbytes);
+    client->errorValue = stuff->fid;
+    LEGAL_NEW_RESOURCE(stuff->fid, client);
+    err = OpenFont(client, stuff->fid, (Mask) 0,
+               stuff->nbytes, (char *)&stuff[1]);
+    if (err == Success)
+    {
+       return(client->noClientException);
+    }
+    else
+       return err;
+}
+
+int
+ProcCloseFont(client)
+    register ClientPtr client;
+{
+    FontPtr pFont;
+    REQUEST(xResourceReq);
+
+    REQUEST_SIZE_MATCH(xResourceReq);
+    pFont = (FontPtr)SecurityLookupIDByType(client, stuff->id, RT_FONT,
+                                           SecurityDestroyAccess);
+    if ( pFont != (FontPtr)NULL)       /* id was valid */
+    {
+        FreeResource(stuff->id, RT_NONE);
+       return(client->noClientException);
+    }
+    else
+    {
+       client->errorValue = stuff->id;
+        return (BadFont);
+    }
+}
+
+int
+ProcQueryFont(client)
+    register ClientPtr client;
+{
+    xQueryFontReply    *reply;
+    FontPtr pFont;
+    register GC *pGC;
+    REQUEST(xResourceReq);
+
+    REQUEST_SIZE_MATCH(xResourceReq);
+    client->errorValue = stuff->id;            /* EITHER font or gc */
+    pFont = (FontPtr)SecurityLookupIDByType(client, stuff->id, RT_FONT,
+                                           SecurityReadAccess);
+    if (!pFont)
+    {
+         /* can't use VERIFY_GC because it might return BadGC */
+       pGC = (GC *) SecurityLookupIDByType(client, stuff->id, RT_GC,
+                                           SecurityReadAccess);
+        if (!pGC)
+       {
+           client->errorValue = stuff->id;
+            return(BadFont);     /* procotol spec says only error is BadFont */
+       }
+       pFont = pGC->font;
+    }
+
+    {
+       xCharInfo       *pmax = FONTINKMAX(pFont);
+       xCharInfo       *pmin = FONTINKMIN(pFont);
+       int             nprotoxcistructs;
+       int             rlength;
+
+       nprotoxcistructs = (
+          pmax->rightSideBearing == pmin->rightSideBearing &&
+          pmax->leftSideBearing == pmin->leftSideBearing &&
+          pmax->descent == pmin->descent &&
+          pmax->ascent == pmin->ascent &&
+          pmax->characterWidth == pmin->characterWidth) ?
+               0 : N2dChars(pFont);
+
+       rlength = sizeof(xQueryFontReply) +
+                    FONTINFONPROPS(FONTCHARSET(pFont)) * sizeof(xFontProp)  +
+                    nprotoxcistructs * sizeof(xCharInfo);
+       reply = (xQueryFontReply *)ALLOCATE_LOCAL(rlength);
+       if(!reply)
+       {
+           return(BadAlloc);
+       }
+
+       reply->type = X_Reply;
+       reply->length = (rlength - sizeof(xGenericReply)) >> 2;
+       reply->sequenceNumber = client->sequence;
+       QueryFont( pFont, reply, nprotoxcistructs);
+
+        WriteReplyToClient(client, rlength, reply);
+       DEALLOCATE_LOCAL(reply);
+       return(client->noClientException);
+    }
+}
+
+int
+ProcQueryTextExtents(client)
+    register ClientPtr client;
+{
+    REQUEST(xQueryTextExtentsReq);
+    xQueryTextExtentsReply reply;
+    FontPtr pFont;
+    GC *pGC;
+    ExtentInfoRec info;
+    unsigned long length;
+
+    REQUEST_AT_LEAST_SIZE(xQueryTextExtentsReq);
+        
+    pFont = (FontPtr)SecurityLookupIDByType(client, stuff->fid, RT_FONT,
+                                           SecurityReadAccess);
+    if (!pFont)
+    {
+        pGC = (GC *)SecurityLookupIDByType(client, stuff->fid, RT_GC,
+                                          SecurityReadAccess);
+        if (!pGC)
+       {
+           client->errorValue = stuff->fid;
+            return(BadFont);
+       }
+       pFont = pGC->font;
+    }
+    length = client->req_len - (sizeof(xQueryTextExtentsReq) >> 2);
+    length = length << 1;
+    if (stuff->oddLength)
+    {
+       if (length == 0)
+           return(BadLength);
+        length--;
+    }
+    if (!QueryTextExtents(pFont, length, (unsigned char *)&stuff[1], &info))
+       return(BadAlloc);
+    reply.type = X_Reply;
+    reply.length = 0;
+    reply.sequenceNumber = client->sequence;
+    reply.drawDirection = info.drawDirection;
+    reply.fontAscent = info.fontAscent;
+    reply.fontDescent = info.fontDescent;
+    reply.overallAscent = info.overallAscent;
+    reply.overallDescent = info.overallDescent;
+    reply.overallWidth = info.overallWidth;
+    reply.overallLeft = info.overallLeft;
+    reply.overallRight = info.overallRight;
+    WriteReplyToClient(client, sizeof(xQueryTextExtentsReply), &reply);
+    return(client->noClientException);
+}
+
+int
+ProcListFonts(client)
+    register ClientPtr client;
+{
+    REQUEST(xListFontsReq);
+
+    REQUEST_FIXED_SIZE(xListFontsReq, stuff->nbytes);
+
+    return ListFonts(client, (unsigned char *) &stuff[1], stuff->nbytes, 
+       stuff->maxNames);
+}
+
+int
+ProcListFontsWithInfo(client)
+    register ClientPtr client;
+{
+    REQUEST(xListFontsWithInfoReq);
+
+    REQUEST_FIXED_SIZE(xListFontsWithInfoReq, stuff->nbytes);
+
+    return StartListFontsWithInfo(client, stuff->nbytes,
+                                 (unsigned char *) &stuff[1], stuff->maxNames);
+}
+
+/*ARGSUSED*/
+int
+dixDestroyPixmap(value, pid)
+    pointer value; /* must conform to DeleteType */
+    XID pid;
+{
+    PixmapPtr pPixmap = (PixmapPtr)value;
+    return (*pPixmap->drawable.pScreen->DestroyPixmap)(pPixmap);
+}
+
+int
+ProcCreatePixmap(client)
+    register ClientPtr client;
+{
+    PixmapPtr pMap;
+    register DrawablePtr pDraw;
+    REQUEST(xCreatePixmapReq);
+    DepthPtr pDepth;
+    register int i;
+
+    REQUEST_SIZE_MATCH(xCreatePixmapReq);
+    client->errorValue = stuff->pid;
+    LEGAL_NEW_RESOURCE(stuff->pid, client);
+    SECURITY_VERIFY_GEOMETRABLE (pDraw, stuff->drawable, client,
+                                SecurityReadAccess);
+    if (!stuff->width || !stuff->height)
+    {
+       client->errorValue = 0;
+        return BadValue;
+    }
+    if (stuff->depth != 1)
+    {
+        pDepth = pDraw->pScreen->allowedDepths;
+        for (i=0; i<pDraw->pScreen->numDepths; i++, pDepth++)
+          if (pDepth->depth == stuff->depth)
+               goto CreatePmap;
+       client->errorValue = stuff->depth;
+        return BadValue;
+    }
+CreatePmap:
+    pMap = (PixmapPtr)(*pDraw->pScreen->CreatePixmap)
+               (pDraw->pScreen, stuff->width,
+                stuff->height, stuff->depth);
+    if (pMap)
+    {
+       pMap->drawable.serialNumber = NEXT_SERIAL_NUMBER;
+       pMap->drawable.id = stuff->pid;
+       if (AddResource(stuff->pid, RT_PIXMAP, (pointer)pMap))
+           return(client->noClientException);
+    }
+    return (BadAlloc);
+}
+
+int
+ProcFreePixmap(client)
+    register ClientPtr client;
+{
+    PixmapPtr pMap;
+
+    REQUEST(xResourceReq);
+
+    REQUEST_SIZE_MATCH(xResourceReq);
+    pMap = (PixmapPtr)SecurityLookupIDByType(client, stuff->id, RT_PIXMAP,
+                                            SecurityDestroyAccess);
+    if (pMap) 
+    {
+       FreeResource(stuff->id, RT_NONE);
+       return(client->noClientException);
+    }
+    else 
+    {
+       client->errorValue = stuff->id;
+       return (BadPixmap);
+    }
+}
+
+int
+ProcCreateGC(client)
+    register ClientPtr client;
+{
+    int error;
+    GC *pGC;
+    register DrawablePtr pDraw;
+    unsigned len;
+    REQUEST(xCreateGCReq);
+
+    REQUEST_AT_LEAST_SIZE(xCreateGCReq);
+    client->errorValue = stuff->gc;
+    LEGAL_NEW_RESOURCE(stuff->gc, client);
+    SECURITY_VERIFY_DRAWABLE (pDraw, stuff->drawable, client,
+                             SecurityReadAccess);
+    len = client->req_len -  (sizeof(xCreateGCReq) >> 2);
+    if (len != Ones(stuff->mask))
+        return BadLength;
+    pGC = (GC *)CreateGC(pDraw, stuff->mask, 
+                        (XID *) &stuff[1], &error);
+    if (error != Success)
+        return error;
+    if (!AddResource(stuff->gc, RT_GC, (pointer)pGC))
+       return (BadAlloc);
+    return(client->noClientException);
+}
+
+int
+ProcChangeGC(client)
+    register ClientPtr client;
+{
+    GC *pGC;
+    REQUEST(xChangeGCReq);
+    int result;
+    unsigned len;
+               
+    REQUEST_AT_LEAST_SIZE(xChangeGCReq);
+    SECURITY_VERIFY_GC(pGC, stuff->gc, client, SecurityWriteAccess);
+    len = client->req_len -  (sizeof(xChangeGCReq) >> 2);
+    if (len != Ones(stuff->mask))
+        return BadLength;
+    result = dixChangeGC(client, pGC, stuff->mask, (CARD32 *) &stuff[1], 0);
+    if (client->noClientException != Success)
+        return(client->noClientException);
+    else
+    {
+       client->errorValue = clientErrorValue;
+        return(result);
+    }
+}
+
+int
+ProcCopyGC(client)
+    register ClientPtr client;
+{
+    register GC *dstGC;
+    register GC *pGC;
+    int result;
+    REQUEST(xCopyGCReq);
+
+    REQUEST_SIZE_MATCH(xCopyGCReq);
+    SECURITY_VERIFY_GC( pGC, stuff->srcGC, client, SecurityReadAccess);
+    SECURITY_VERIFY_GC( dstGC, stuff->dstGC, client, SecurityWriteAccess);
+    if ((dstGC->pScreen != pGC->pScreen) || (dstGC->depth != pGC->depth))
+        return (BadMatch);    
+    result = CopyGC(pGC, dstGC, stuff->mask);
+    if (client->noClientException != Success)
+        return(client->noClientException);
+    else
+    {
+       client->errorValue = clientErrorValue;
+        return(result);
+    }
+}
+
+int
+ProcSetDashes(client)
+    register ClientPtr client;
+{
+    register GC *pGC;
+    int result;
+    REQUEST(xSetDashesReq);
+
+    REQUEST_FIXED_SIZE(xSetDashesReq, stuff->nDashes);
+    if (stuff->nDashes == 0)
+    {
+        client->errorValue = 0;
+         return BadValue;
+    }
+
+    SECURITY_VERIFY_GC(pGC,stuff->gc, client, SecurityWriteAccess);
+
+    result = SetDashes(pGC, stuff->dashOffset, stuff->nDashes,
+                      (unsigned char *)&stuff[1]);
+    if (client->noClientException != Success)
+        return(client->noClientException);
+    else
+    {
+       client->errorValue = clientErrorValue;
+        return(result);
+    }
+}
+
+int
+ProcSetClipRectangles(client)
+    register ClientPtr client;
+{
+    int        nr;
+    int result;
+    register GC *pGC;
+    REQUEST(xSetClipRectanglesReq);
+
+    REQUEST_AT_LEAST_SIZE(xSetClipRectanglesReq);
+    if ((stuff->ordering != Unsorted) && (stuff->ordering != YSorted) &&
+       (stuff->ordering != YXSorted) && (stuff->ordering != YXBanded))
+    {
+       client->errorValue = stuff->ordering;
+        return BadValue;
+    }
+    SECURITY_VERIFY_GC(pGC,stuff->gc, client, SecurityWriteAccess);
+                
+    nr = (client->req_len << 2) - sizeof(xSetClipRectanglesReq);
+    if (nr & 4)
+       return(BadLength);
+    nr >>= 3;
+    result = SetClipRects(pGC, stuff->xOrigin, stuff->yOrigin,
+                         nr, (xRectangle *)&stuff[1], (int)stuff->ordering);
+    if (client->noClientException != Success)
+        return(client->noClientException);
+    else
+        return(result);
+}
+
+int
+ProcFreeGC(client)
+    register ClientPtr client;
+{
+    register GC *pGC;
+    REQUEST(xResourceReq);
+
+    REQUEST_SIZE_MATCH(xResourceReq);
+    SECURITY_VERIFY_GC(pGC, stuff->id, client, SecurityDestroyAccess);
+    FreeResource(stuff->id, RT_NONE);
+    return(client->noClientException);
+}
+
+int
+ProcClearToBackground(client)
+    register ClientPtr client;
+{
+    REQUEST(xClearAreaReq);
+    register WindowPtr pWin;
+
+    REQUEST_SIZE_MATCH(xClearAreaReq);
+    pWin = (WindowPtr)SecurityLookupWindow(stuff->window, client,
+                                          SecurityWriteAccess);
+    if (!pWin)
+        return(BadWindow);
+    if (pWin->drawable.class == InputOnly)
+    {
+       client->errorValue = stuff->window;
+       return (BadMatch);
+    }              
+    if ((stuff->exposures != xTrue) && (stuff->exposures != xFalse))
+    {
+       client->errorValue = stuff->exposures;
+        return(BadValue);
+    }
+    (*pWin->drawable.pScreen->ClearToBackground)(pWin, stuff->x, stuff->y,
+                              stuff->width, stuff->height,
+                              (Bool)stuff->exposures);
+    return(client->noClientException);
+}
+
+int
+ProcCopyArea(client)
+    register ClientPtr client;
+{
+    register DrawablePtr pDst;
+    register DrawablePtr pSrc;
+    register GC *pGC;
+    REQUEST(xCopyAreaReq);
+    RegionPtr pRgn;
+
+    REQUEST_SIZE_MATCH(xCopyAreaReq);
+
+    VALIDATE_DRAWABLE_AND_GC(stuff->dstDrawable, pDst, pGC, client); 
+    if (stuff->dstDrawable != stuff->srcDrawable)
+    {
+       SECURITY_VERIFY_DRAWABLE(pSrc, stuff->srcDrawable, client,
+                                SecurityReadAccess);
+       if ((pDst->pScreen != pSrc->pScreen) || (pDst->depth != pSrc->depth))
+       {
+           client->errorValue = stuff->dstDrawable;
+           return (BadMatch);
+       }
+    }
+    else
+        pSrc = pDst;
+
+    SET_DBE_SRCBUF(pSrc, stuff->srcDrawable);
+
+    pRgn = (*pGC->ops->CopyArea)(pSrc, pDst, pGC, stuff->srcX, stuff->srcY,
+                                stuff->width, stuff->height, 
+                                stuff->dstX, stuff->dstY);
+    if (pGC->graphicsExposures)
+    {
+       (*pDst->pScreen->SendGraphicsExpose)
+               (client, pRgn, stuff->dstDrawable, X_CopyArea, 0);
+       if (pRgn)
+           REGION_DESTROY(pDst->pScreen, pRgn);
+    }
+
+    return(client->noClientException);
+}
+
+int
+ProcCopyPlane(client)
+    register ClientPtr client;
+{
+    register DrawablePtr psrcDraw, pdstDraw;
+    register GC *pGC;
+    REQUEST(xCopyPlaneReq);
+    RegionPtr pRgn;
+
+    REQUEST_SIZE_MATCH(xCopyPlaneReq);
+
+    VALIDATE_DRAWABLE_AND_GC(stuff->dstDrawable, pdstDraw, pGC, client);
+    if (stuff->dstDrawable != stuff->srcDrawable)
+    {
+       SECURITY_VERIFY_DRAWABLE(psrcDraw, stuff->srcDrawable, client,
+                                SecurityReadAccess);
+       if (pdstDraw->pScreen != psrcDraw->pScreen)
+       {
+           client->errorValue = stuff->dstDrawable;
+           return (BadMatch);
+       }
+    }
+    else
+        psrcDraw = pdstDraw;
+
+    SET_DBE_SRCBUF(psrcDraw, stuff->srcDrawable);
+
+    /* Check to see if stuff->bitPlane has exactly ONE good bit set */
+    if(stuff->bitPlane == 0 || (stuff->bitPlane & (stuff->bitPlane - 1)) ||
+       (stuff->bitPlane > (1L << (psrcDraw->depth - 1))))
+    {
+       client->errorValue = stuff->bitPlane;
+       return(BadValue);
+    }
+
+    pRgn = (*pGC->ops->CopyPlane)(psrcDraw, pdstDraw, pGC, stuff->srcX, stuff->srcY,
+                                stuff->width, stuff->height, 
+                                stuff->dstX, stuff->dstY, stuff->bitPlane);
+    if (pGC->graphicsExposures)
+    {
+       (*pdstDraw->pScreen->SendGraphicsExpose)
+               (client, pRgn, stuff->dstDrawable, X_CopyPlane, 0);
+       if (pRgn)
+           REGION_DESTROY(pdstDraw->pScreen, pRgn);
+    }
+    return(client->noClientException);
+}
+
+int
+ProcPolyPoint(client)
+    register ClientPtr client;
+{
+    int npoint;
+    register GC *pGC;
+    register DrawablePtr pDraw;
+    REQUEST(xPolyPointReq);
+
+    REQUEST_AT_LEAST_SIZE(xPolyPointReq);
+    if ((stuff->coordMode != CoordModeOrigin) && 
+       (stuff->coordMode != CoordModePrevious))
+    {
+       client->errorValue = stuff->coordMode;
+        return BadValue;
+    }
+    VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, pGC, client); 
+    npoint = ((client->req_len << 2) - sizeof(xPolyPointReq)) >> 2;
+    if (npoint)
+        (*pGC->ops->PolyPoint)(pDraw, pGC, stuff->coordMode, npoint,
+                         (xPoint *) &stuff[1]);
+    return (client->noClientException);
+}
+
+int
+ProcPolyLine(client)
+    register ClientPtr client;
+{
+    int npoint;
+    register GC *pGC;
+    register DrawablePtr pDraw;
+    REQUEST(xPolyLineReq);
+
+    REQUEST_AT_LEAST_SIZE(xPolyLineReq);
+    if ((stuff->coordMode != CoordModeOrigin) && 
+       (stuff->coordMode != CoordModePrevious))
+    {
+       client->errorValue = stuff->coordMode;
+        return BadValue;
+    }
+    VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, pGC, client);
+    npoint = ((client->req_len << 2) - sizeof(xPolyLineReq)) >> 2;
+    if (npoint > 1)
+       (*pGC->ops->Polylines)(pDraw, pGC, stuff->coordMode, npoint, 
+                             (DDXPointPtr) &stuff[1]);
+    return(client->noClientException);
+}
+
+int
+ProcPolySegment(client)
+    register ClientPtr client;
+{
+    int nsegs;
+    register GC *pGC;
+    register DrawablePtr pDraw;
+    REQUEST(xPolySegmentReq);
+
+    REQUEST_AT_LEAST_SIZE(xPolySegmentReq);
+    VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, pGC, client);
+    nsegs = (client->req_len << 2) - sizeof(xPolySegmentReq);
+    if (nsegs & 4)
+       return(BadLength);
+    nsegs >>= 3;
+    if (nsegs)
+        (*pGC->ops->PolySegment)(pDraw, pGC, nsegs, (xSegment *) &stuff[1]);
+    return (client->noClientException);
+}
+
+int
+ProcPolyRectangle (client)
+    register ClientPtr client;
+{
+    int nrects;
+    register GC *pGC;
+    register DrawablePtr pDraw;
+    REQUEST(xPolyRectangleReq);
+
+    REQUEST_AT_LEAST_SIZE(xPolyRectangleReq);
+    VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, pGC, client);
+    nrects = (client->req_len << 2) - sizeof(xPolyRectangleReq);
+    if (nrects & 4)
+       return(BadLength);
+    nrects >>= 3;
+    if (nrects)
+        (*pGC->ops->PolyRectangle)(pDraw, pGC, 
+                   nrects, (xRectangle *) &stuff[1]);
+    return(client->noClientException);
+}
+
+int
+ProcPolyArc(client)
+    register ClientPtr client;
+{
+    int                narcs;
+    register GC *pGC;
+    register DrawablePtr pDraw;
+    REQUEST(xPolyArcReq);
+
+    REQUEST_AT_LEAST_SIZE(xPolyArcReq);
+    VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, pGC, client);
+    narcs = (client->req_len << 2) - sizeof(xPolyArcReq);
+    if (narcs % sizeof(xArc))
+       return(BadLength);
+    narcs /= sizeof(xArc);
+    if (narcs)
+        (*pGC->ops->PolyArc)(pDraw, pGC, narcs, (xArc *) &stuff[1]);
+    return (client->noClientException);
+}
+
+int
+ProcFillPoly(client)
+    register ClientPtr client;
+{
+    int          things;
+    register GC *pGC;
+    register DrawablePtr pDraw;
+    REQUEST(xFillPolyReq);
+
+    REQUEST_AT_LEAST_SIZE(xFillPolyReq);
+    if ((stuff->shape != Complex) && (stuff->shape != Nonconvex) &&  
+       (stuff->shape != Convex))
+    {
+       client->errorValue = stuff->shape;
+        return BadValue;
+    }
+    if ((stuff->coordMode != CoordModeOrigin) && 
+       (stuff->coordMode != CoordModePrevious))
+    {
+       client->errorValue = stuff->coordMode;
+        return BadValue;
+    }
+
+    VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, pGC, client);
+    things = ((client->req_len << 2) - sizeof(xFillPolyReq)) >> 2;
+    if (things)
+        (*pGC->ops->FillPolygon) (pDraw, pGC, stuff->shape,
+                        stuff->coordMode, things,
+                        (DDXPointPtr) &stuff[1]);
+    return(client->noClientException);
+}
+
+int
+ProcPolyFillRectangle(client)
+    register ClientPtr client;
+{
+    int             things;
+    register GC *pGC;
+    register DrawablePtr pDraw;
+    REQUEST(xPolyFillRectangleReq);
+
+    REQUEST_AT_LEAST_SIZE(xPolyFillRectangleReq);
+    VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, pGC, client);
+    things = (client->req_len << 2) - sizeof(xPolyFillRectangleReq);
+    if (things & 4)
+       return(BadLength);
+    things >>= 3;
+    if (things)
+        (*pGC->ops->PolyFillRect) (pDraw, pGC, things,
+                     (xRectangle *) &stuff[1]);
+    return (client->noClientException);
+}
+
+int
+ProcPolyFillArc(client)
+    register ClientPtr client;
+{
+    int                narcs;
+    register GC *pGC;
+    register DrawablePtr pDraw;
+    REQUEST(xPolyFillArcReq);
+
+    REQUEST_AT_LEAST_SIZE(xPolyFillArcReq);
+    VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, pGC, client);
+    narcs = (client->req_len << 2) - sizeof(xPolyFillArcReq);
+    if (narcs % sizeof(xArc))
+       return(BadLength);
+    narcs /= sizeof(xArc);
+    if (narcs)
+        (*pGC->ops->PolyFillArc) (pDraw, pGC, narcs, (xArc *) &stuff[1]);
+    return (client->noClientException);
+}
+
+/* 64-bit server notes: the protocol restricts padding of images to
+ * 8-, 16-, or 32-bits. We would like to have 64-bits for the server
+ * to use internally. Removes need for internal alignment checking.
+ * All of the PutImage functions could be changed individually, but
+ * as currently written, they call other routines which require things
+ * to be 64-bit padded on scanlines, so we changed things here.
+ * If an image would be padded differently for 64- versus 32-, then
+ * copy each scanline to a 64-bit padded scanline.
+ * Also, we need to make sure that the image is aligned on a 64-bit
+ * boundary, even if the scanlines are padded to our satisfaction.
+ */
+int
+ProcPutImage(client)
+    register ClientPtr client;
+{
+    register   GC *pGC;
+    register   DrawablePtr pDraw;
+    long       length;         /* length of scanline server padded */
+    long       lengthProto;    /* length of scanline protocol padded */
+    char       *tmpImage;
+    REQUEST(xPutImageReq);
+
+    REQUEST_AT_LEAST_SIZE(xPutImageReq);
+    VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, pGC, client);
+    if (stuff->format == XYBitmap)
+    {
+        if ((stuff->depth != 1) ||
+           (stuff->leftPad >= (unsigned int)screenInfo.bitmapScanlinePad))
+            return BadMatch;
+        length             = BitmapBytePad(stuff->width + stuff->leftPad);
+#ifdef INTERNAL_VS_EXTERNAL_PADDING
+        lengthProto = BitmapBytePadProto(stuff->width + stuff->leftPad);
+#endif
+    }
+    else if (stuff->format == XYPixmap)
+    {
+        if ((pDraw->depth != stuff->depth) || 
+           (stuff->leftPad >= (unsigned int)screenInfo.bitmapScanlinePad))
+            return BadMatch;
+        length      = BitmapBytePad(stuff->width + stuff->leftPad);
+       length      *= stuff->depth;
+#ifdef INTERNAL_VS_EXTERNAL_PADDING
+        lengthProto = BitmapBytePadProto(stuff->width + stuff->leftPad);
+       lengthProto *= stuff->depth;
+#endif
+    }
+    else if (stuff->format == ZPixmap)
+    {
+        if ((pDraw->depth != stuff->depth) || (stuff->leftPad != 0))
+            return BadMatch;
+        length      = PixmapBytePad(stuff->width, stuff->depth);
+#ifdef INTERNAL_VS_EXTERNAL_PADDING
+        lengthProto = PixmapBytePadProto(stuff->width, stuff->depth);
+#endif
+    }
+    else
+    {
+       client->errorValue = stuff->format;
+        return BadValue;
+    }
+
+#ifdef INTERNAL_VS_EXTERNAL_PADDING
+    /* handle 64 bit case where protocol may pad to 32 and we want 64 */
+    if ( length != lengthProto ) {
+       register int    i;
+       char            * stuffptr, /* pointer into protocol data */
+                       * tmpptr;   /* new location to copy to */
+
+        if(!(tmpImage = (char *) ALLOCATE_LOCAL(length*stuff->height)))
+            return (BadAlloc);
+    
+       bzero(tmpImage,length*stuff->height);
+    
+       if ( stuff->format == XYPixmap ) {
+           int lineBytes = BitmapBytePad(stuff->width + stuff->leftPad);
+           int lineBytesProto = 
+               BitmapBytePadProto(stuff->width + stuff->leftPad);
+           int depth = stuff->depth;
+
+           stuffptr = (char *)&stuff[1];
+           tmpptr = tmpImage;
+           for ( i = 0; i < stuff->height*stuff->depth;
+               stuffptr += lineBytesProto,tmpptr += lineBytes, i++) 
+               memmove(tmpptr,stuffptr,lineBytesProto);
+       }
+       else {
+           for ( i = 0,stuffptr = (char *)&stuff[1],tmpptr=tmpImage;
+               i < stuff->height;
+               stuffptr += lengthProto,tmpptr += length, i++) 
+               memmove(tmpptr,stuffptr,lengthProto);
+       }
+    }
+
+    /* handle 64-bit case where stuff is not 64-bit aligned */
+    else if ((unsigned long)&stuff[1] & (sizeof(long)-1)) {
+        if(!(tmpImage = (char *) ALLOCATE_LOCAL(length*stuff->height)))
+            return (BadAlloc);
+       memmove(tmpImage,(char *)&stuff[1],length*stuff->height);
+    }
+    else
+       tmpImage = (char *)&stuff[1];
+#else
+    tmpImage = (char *)&stuff[1];
+    lengthProto = length;
+#endif /* INTERNAL_VS_EXTERNAL_PADDING */
+       
+    if (((((lengthProto * stuff->height) + (unsigned)3) >> 2) + 
+       (sizeof(xPutImageReq) >> 2)) != client->req_len)
+       return BadLength;
+
+    (*pGC->ops->PutImage) (pDraw, pGC, stuff->depth, stuff->dstX, stuff->dstY,
+                 stuff->width, stuff->height, 
+                 stuff->leftPad, stuff->format, tmpImage);
+
+#ifdef INTERNAL_VS_EXTERNAL_PADDING
+    /* free up our temporary space if used */
+    if (tmpImage != (char *)&stuff[1])
+        DEALLOCATE_LOCAL(tmpImage);
+#endif /* INTERNAL_VS_EXTERNAL_PADDING */
+
+     return (client->noClientException);
+}
+
+
+int
+DoGetImage(client, format, drawable, x, y, width, height, planemask, im_return)
+    register ClientPtr client;
+    Drawable drawable;
+    int format;
+    int x, y, width, height;
+    Mask planemask;
+    xGetImageReply **im_return;
+{
+    register DrawablePtr pDraw;
+    int                        nlines, linesPerBuf;
+    register int       linesDone;
+    long               widthBytesLine, length;
+#ifdef INTERNAL_VS_EXTERNAL_PADDING
+    long               widthBytesLineProto, lengthProto;
+#endif
+    Mask               plane;
+    char               *pBuf;
+    xGetImageReply     xgi;
+    RegionPtr pVisibleRegion = NULL;
+
+    if ((format != XYPixmap) && (format != ZPixmap))
+    {
+       client->errorValue = format;
+        return(BadValue);
+    }
+    SECURITY_VERIFY_DRAWABLE(pDraw, drawable, client, SecurityReadAccess);
+    if(pDraw->type == DRAWABLE_WINDOW)
+    {
+      if( /* check for being viewable */
+        !((WindowPtr) pDraw)->realized ||
+         /* check for being on screen */
+         pDraw->x + x < 0 ||
+        pDraw->x + x + width > pDraw->pScreen->width ||
+         pDraw->y + y < 0 ||
+         pDraw->y + y + height > pDraw->pScreen->height ||
+          /* check for being inside of border */
+         x < - wBorderWidth((WindowPtr)pDraw) ||
+         x + width > wBorderWidth((WindowPtr)pDraw) + (int)pDraw->width ||
+         y < -wBorderWidth((WindowPtr)pDraw) ||
+         y + height > wBorderWidth ((WindowPtr)pDraw) + (int)pDraw->height
+        )
+           return(BadMatch);
+       xgi.visual = wVisual (((WindowPtr) pDraw));
+    }
+    else
+    {
+      if(x < 0 ||
+         x+width > (int)pDraw->width ||
+         y < 0 ||
+         y+height > (int)pDraw->height
+        )
+           return(BadMatch);
+       xgi.visual = None;
+    }
+
+    SET_DBE_SRCBUF(pDraw, drawable);
+
+    xgi.type = X_Reply;
+    xgi.sequenceNumber = client->sequence;
+    xgi.depth = pDraw->depth;
+    if(format == ZPixmap)
+    {
+       widthBytesLine = PixmapBytePad(width, pDraw->depth);
+       length = widthBytesLine * height;
+
+#ifdef INTERNAL_VS_EXTERNAL_PADDING
+       widthBytesLineProto = PixmapBytePadProto(width, pDraw->depth);
+       lengthProto         = widthBytesLineProto * height;
+#endif
+    }
+    else 
+    {
+       widthBytesLine = BitmapBytePad(width);
+       plane = ((Mask)1) << (pDraw->depth - 1);
+       /* only planes asked for */
+       length = widthBytesLine * height *
+                Ones(planemask & (plane | (plane - 1)));
+
+#ifdef INTERNAL_VS_EXTERNAL_PADDING
+       widthBytesLineProto = BitmapBytePadProto(width);
+       lengthProto = widthBytesLineProto * height *
+                Ones(planemask & (plane | (plane - 1)));
+#endif
+    }
+
+#ifdef INTERNAL_VS_EXTERNAL_PADDING
+    xgi.length = lengthProto;
+#else
+    xgi.length = length;
+#endif
+
+    if (im_return) {
+       pBuf = (char *)xalloc(sz_xGetImageReply + length);
+       if (!pBuf)
+           return (BadAlloc);
+       if (widthBytesLine == 0)
+           linesPerBuf = 0;
+       else
+           linesPerBuf = height;
+       *im_return = (xGetImageReply *)pBuf;
+       *(xGetImageReply *)pBuf = xgi;
+       pBuf += sz_xGetImageReply;
+    } else {
+       xgi.length = (xgi.length + 3) >> 2;
+       if (widthBytesLine == 0 || height == 0)
+           linesPerBuf = 0;
+       else if (widthBytesLine >= IMAGE_BUFSIZE)
+           linesPerBuf = 1;
+       else
+       {
+           linesPerBuf = IMAGE_BUFSIZE / widthBytesLine;
+           if (linesPerBuf > height)
+               linesPerBuf = height;
+       }
+       length = linesPerBuf * widthBytesLine;
+       if (linesPerBuf < height)
+       {
+           /* we have to make sure intermediate buffers don't need padding */
+           while ((linesPerBuf > 1) &&
+                  (length & ((1 << LOG2_BYTES_PER_SCANLINE_PAD)-1)))
+           {
+               linesPerBuf--;
+               length -= widthBytesLine;
+           }
+           while (length & ((1 << LOG2_BYTES_PER_SCANLINE_PAD)-1))
+           {
+               linesPerBuf++;
+               length += widthBytesLine;
+           }
+       }
+       if(!(pBuf = (char *) ALLOCATE_LOCAL(length)))
+           return (BadAlloc);
+       WriteReplyToClient(client, sizeof (xGetImageReply), &xgi);
+    }
+
+#ifdef XCSECURITY
+    if (client->trustLevel != XSecurityClientTrusted &&
+       pDraw->type == DRAWABLE_WINDOW)
+    {
+       pVisibleRegion = NotClippedByChildren((WindowPtr)pDraw);
+       if (pVisibleRegion)
+       {
+           REGION_TRANSLATE(pScreen, pVisibleRegion, -pDraw->x, -pDraw->y);
+       }
+    }
+#endif
+
+    if (linesPerBuf == 0)
+    {
+       /* nothing to do */
+    }
+    else if (format == ZPixmap)
+    {
+        linesDone = 0;
+        while (height - linesDone > 0)
+        {
+           nlines = min(linesPerBuf, height - linesDone);
+           (*pDraw->pScreen->GetImage) (pDraw,
+                                        x,
+                                        y + linesDone,
+                                        width, 
+                                        nlines,
+                                        format,
+                                        planemask,
+                                        (pointer) pBuf);
+#ifdef XCSECURITY
+           if (pVisibleRegion)
+               SecurityCensorImage(client, pVisibleRegion, widthBytesLine,
+                       pDraw, x, y + linesDone, width, 
+                       nlines, format, pBuf);
+#endif
+
+#ifdef INTERNAL_VS_EXTERNAL_PADDING
+           /* for 64-bit server, convert image to pad to 32 bits */
+           if ( widthBytesLine != widthBytesLineProto ) {
+               register char * bufPtr, * protoPtr;
+               register int i;
+
+               for (i = 1,
+                    bufPtr = pBuf + widthBytesLine,
+                    protoPtr = pBuf + widthBytesLineProto;
+                    i < nlines;
+                    bufPtr += widthBytesLine,
+                    protoPtr += widthBytesLineProto, 
+                    i++)
+                   memmove(protoPtr, bufPtr, widthBytesLineProto);
+           }
+#endif
+           /* Note that this is NOT a call to WriteSwappedDataToClient,
+               as we do NOT byte swap */
+           if (!im_return)
+/* Don't split me, gcc pukes when you do */
+#ifdef INTERNAL_VS_EXTERNAL_PADDING
+               (void)WriteToClient(client,
+                                   (int)(nlines * widthBytesLineProto),
+                                   pBuf);
+#else
+               (void)WriteToClient(client,
+                                   (int)(nlines * widthBytesLine),
+                                   pBuf);
+#endif
+           linesDone += nlines;
+        }
+    }
+    else /* XYPixmap */
+    {
+        for (; plane; plane >>= 1)
+       {
+           if (planemask & plane)
+           {
+               linesDone = 0;
+               while (height - linesDone > 0)
+               {
+                   nlines = min(linesPerBuf, height - linesDone);
+                   (*pDraw->pScreen->GetImage) (pDraw,
+                                                x,
+                                                y + linesDone,
+                                                width, 
+                                                nlines,
+                                                format,
+                                                plane,
+                                                (pointer)pBuf);
+#ifdef XCSECURITY
+                   if (pVisibleRegion)
+                       SecurityCensorImage(client, pVisibleRegion,
+                               widthBytesLine,
+                               pDraw, x, y + linesDone, width, 
+                               nlines, format, pBuf);
+#endif
+
+#ifdef INTERNAL_VS_EXTERNAL_PADDING
+                   /* for 64-bit server, convert image to pad to 32 bits */
+                   if ( widthBytesLine != widthBytesLineProto ) {
+                       register char * bufPtr, * protoPtr;
+                       register int i;
+
+                       for (i = 1,
+                            bufPtr = pBuf + widthBytesLine,
+                            protoPtr = pBuf + widthBytesLineProto;
+                            i < nlines;
+                            bufPtr += widthBytesLine,
+                            protoPtr += widthBytesLineProto,
+                            i++)
+                           memmove(protoPtr, bufPtr, widthBytesLineProto);
+                   }
+#endif
+                   /* Note: NOT a call to WriteSwappedDataToClient,
+                      as we do NOT byte swap */
+                   if (im_return) {
+#ifdef INTERNAL_VS_EXTERNAL_PADDING
+                       pBuf += nlines * widthBytesLineProto;
+#else
+                       pBuf += nlines * widthBytesLine;
+#endif
+                   } else
+/* Don't split me, gcc pukes when you do */
+#ifdef INTERNAL_VS_EXTERNAL_PADDING
+                       (void)WriteToClient(client,
+                                       (int)(nlines * widthBytesLineProto),
+                                       pBuf);
+#else
+                       (void)WriteToClient(client,
+                                       (int)(nlines * widthBytesLine),
+                                       pBuf);
+#endif
+                   linesDone += nlines;
+               }
+            }
+       }
+    }
+#ifdef XCSECURITY
+    if (pVisibleRegion)
+       REGION_DESTROY(pScreen, pVisibleRegion);
+#endif
+    if (!im_return)
+       DEALLOCATE_LOCAL(pBuf);
+    return (client->noClientException);
+}
+
+int
+ProcGetImage(client)
+    register ClientPtr client;
+{
+    REQUEST(xGetImageReq);
+
+    REQUEST_SIZE_MATCH(xGetImageReq);
+
+    return DoGetImage(client, stuff->format, stuff->drawable,
+                     stuff->x, stuff->y,
+                     (int)stuff->width, (int)stuff->height,
+                     stuff->planeMask, (xGetImageReply **)NULL);
+}
+
+int
+ProcPolyText(client)
+    register ClientPtr client;
+{
+    int        err;
+    REQUEST(xPolyTextReq);
+    DrawablePtr pDraw;
+    GC *pGC;
+
+    REQUEST_AT_LEAST_SIZE(xPolyTextReq);
+    VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, pGC, client);
+
+    err = PolyText(client,
+                  pDraw,
+                  pGC,
+                  (unsigned char *)&stuff[1],
+                  ((unsigned char *) stuff) + (client->req_len << 2),
+                  stuff->x,
+                  stuff->y,
+                  stuff->reqType,
+                  stuff->drawable);
+
+    if (err == Success)
+    {
+       return(client->noClientException);
+    }
+    else
+       return err;
+}
+
+int
+ProcImageText8(client)
+    register ClientPtr client;
+{
+    int        err;
+    register DrawablePtr pDraw;
+    register GC *pGC;
+
+    REQUEST(xImageTextReq);
+
+    REQUEST_FIXED_SIZE(xImageTextReq, stuff->nChars);
+    VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, pGC, client);
+
+    err = ImageText(client,
+                   pDraw,
+                   pGC,
+                   stuff->nChars,
+                   (unsigned char *)&stuff[1],
+                   stuff->x,
+                   stuff->y,
+                   stuff->reqType,
+                   stuff->drawable);
+
+    if (err == Success)
+    {
+       return(client->noClientException);
+    }
+    else
+       return err;
+}
+
+int
+ProcImageText16(client)
+    register ClientPtr client;
+{
+    int        err;
+    register DrawablePtr pDraw;
+    register GC *pGC;
+
+    REQUEST(xImageTextReq);
+
+    REQUEST_FIXED_SIZE(xImageTextReq, stuff->nChars << 1);
+    VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, pGC, client);
+
+    err = ImageText(client,
+                   pDraw,
+                   pGC,
+                   stuff->nChars,
+                   (unsigned char *)&stuff[1],
+                   stuff->x,
+                   stuff->y,
+                   stuff->reqType,
+                   stuff->drawable);
+
+    if (err == Success)
+    {
+       return(client->noClientException);
+    }
+    else
+       return err;
+}
+
+
+int
+ProcCreateColormap(client)
+    register ClientPtr client;
+{
+    VisualPtr  pVisual;
+    ColormapPtr        pmap;
+    Colormap   mid;
+    register WindowPtr   pWin;
+    ScreenPtr pScreen;
+    REQUEST(xCreateColormapReq);
+    int i, result;
+
+    REQUEST_SIZE_MATCH(xCreateColormapReq);
+
+    if ((stuff->alloc != AllocNone) && (stuff->alloc != AllocAll))
+    {
+       client->errorValue = stuff->alloc;
+        return(BadValue);
+    }
+    mid = stuff->mid;
+    LEGAL_NEW_RESOURCE(mid, client);
+    pWin = (WindowPtr)SecurityLookupWindow(stuff->window, client,
+                                          SecurityReadAccess);
+    if (!pWin)
+        return(BadWindow);
+
+    pScreen = pWin->drawable.pScreen;
+    for (i = 0, pVisual = pScreen->visuals;
+        i < pScreen->numVisuals;
+        i++, pVisual++)
+    {
+       if (pVisual->vid != stuff->visual)
+           continue;
+       result =  CreateColormap(mid, pScreen, pVisual, &pmap,
+                                (int)stuff->alloc, client->index);
+       if (client->noClientException != Success)
+           return(client->noClientException);
+       else
+           return(result);
+    }
+    client->errorValue = stuff->visual;
+    return(BadValue);
+}
+
+int
+ProcFreeColormap(client)
+    register ClientPtr client;
+{
+    ColormapPtr pmap;
+    REQUEST(xResourceReq);
+
+    REQUEST_SIZE_MATCH(xResourceReq);
+    pmap = (ColormapPtr )SecurityLookupIDByType(client, stuff->id, RT_COLORMAP,
+                                               SecurityDestroyAccess);
+    if (pmap) 
+    {
+       /* Freeing a default colormap is a no-op */
+       if (!(pmap->flags & IsDefault))
+           FreeResource(stuff->id, RT_NONE);
+       return (client->noClientException);
+    }
+    else 
+    {
+       client->errorValue = stuff->id;
+       return (BadColor);
+    }
+}
+
+
+int
+ProcCopyColormapAndFree(client)
+    register ClientPtr client;
+{
+    Colormap   mid;
+    ColormapPtr        pSrcMap;
+    REQUEST(xCopyColormapAndFreeReq);
+    int result;
+
+    REQUEST_SIZE_MATCH(xCopyColormapAndFreeReq);
+    mid = stuff->mid;
+    LEGAL_NEW_RESOURCE(mid, client);
+    if( (pSrcMap = (ColormapPtr )SecurityLookupIDByType(client,        stuff->srcCmap,
+               RT_COLORMAP, SecurityReadAccess|SecurityWriteAccess)) )
+    {
+       result = CopyColormapAndFree(mid, pSrcMap, client->index);
+       if (client->noClientException != Success)
+            return(client->noClientException);
+       else
+            return(result);
+    }
+    else
+    {
+       client->errorValue = stuff->srcCmap;
+       return(BadColor);
+    }
+}
+
+int
+ProcInstallColormap(client)
+    register ClientPtr client;
+{
+    ColormapPtr pcmp;
+    REQUEST(xResourceReq);
+
+    REQUEST_SIZE_MATCH(xResourceReq);
+    pcmp = (ColormapPtr)SecurityLookupIDByType(client, stuff->id,
+                                           RT_COLORMAP, SecurityReadAccess);
+    if (pcmp)
+    {
+        (*(pcmp->pScreen->InstallColormap)) (pcmp);
+        return (client->noClientException);        
+    }
+    else
+    {
+        client->errorValue = stuff->id;
+        return (BadColor);
+    }
+}
+
+int
+ProcUninstallColormap(client)
+    register ClientPtr client;
+{
+    ColormapPtr pcmp;
+    REQUEST(xResourceReq);
+
+    REQUEST_SIZE_MATCH(xResourceReq);
+    pcmp = (ColormapPtr)SecurityLookupIDByType(client, stuff->id,
+                                       RT_COLORMAP, SecurityReadAccess);
+    if (pcmp)
+    {
+       if(pcmp->mid != pcmp->pScreen->defColormap)
+            (*(pcmp->pScreen->UninstallColormap)) (pcmp);
+        return (client->noClientException);        
+    }
+    else
+    {
+        client->errorValue = stuff->id;
+        return (BadColor);
+    }
+}
+
+int
+ProcListInstalledColormaps(client)
+    register ClientPtr client;
+{
+    xListInstalledColormapsReply *preply; 
+    int nummaps;
+    WindowPtr pWin;
+    REQUEST(xResourceReq);
+
+    REQUEST_SIZE_MATCH(xResourceReq);
+    pWin = (WindowPtr)SecurityLookupWindow(stuff->id, client,
+                                          SecurityReadAccess);
+
+    if (!pWin)
+        return(BadWindow);
+
+    preply = (xListInstalledColormapsReply *) 
+               ALLOCATE_LOCAL(sizeof(xListInstalledColormapsReply) +
+                    pWin->drawable.pScreen->maxInstalledCmaps *
+                    sizeof(Colormap));
+    if(!preply)
+        return(BadAlloc);
+
+    preply->type = X_Reply;
+    preply->sequenceNumber = client->sequence;
+    nummaps = (*pWin->drawable.pScreen->ListInstalledColormaps)
+        (pWin->drawable.pScreen, (Colormap *)&preply[1]);
+    preply->nColormaps = nummaps;
+    preply->length = nummaps;
+    WriteReplyToClient(client, sizeof (xListInstalledColormapsReply), preply);
+    client->pSwapReplyFunc = (ReplySwapPtr) Swap32Write;
+    WriteSwappedDataToClient(client, nummaps * sizeof(Colormap), &preply[1]);
+    DEALLOCATE_LOCAL(preply);
+    return(client->noClientException);
+}
+
+int
+ProcAllocColor(client)
+    register ClientPtr client;
+{
+    ColormapPtr pmap;
+    int        retval;
+    xAllocColorReply acr;
+    REQUEST(xAllocColorReq);
+
+    REQUEST_SIZE_MATCH(xAllocColorReq);
+    pmap = (ColormapPtr)SecurityLookupIDByType(client, stuff->cmap,
+                                       RT_COLORMAP, SecurityWriteAccess);
+    if (pmap)
+    {
+#ifdef LBX
+       /*
+        * If the colormap is grabbed by a proxy, the server will have
+        * to regain control over the colormap.  This AllocColor request
+        * will be handled after the server gets back the colormap control.
+        */
+       if (LbxCheckColorRequest (client, pmap, (xReq *) stuff))
+           return Success;
+#endif
+       acr.type = X_Reply;
+       acr.length = 0;
+       acr.sequenceNumber = client->sequence;
+       acr.red = stuff->red;
+       acr.green = stuff->green;
+       acr.blue = stuff->blue;
+       acr.pixel = 0;
+       if( (retval = AllocColor(pmap, &acr.red, &acr.green, &acr.blue,
+                              &acr.pixel, client->index)) )
+       {
+            if (client->noClientException != Success)
+                return(client->noClientException);
+           else
+               return (retval);
+       }
+        WriteReplyToClient(client, sizeof(xAllocColorReply), &acr);
+       return (client->noClientException);
+
+    }
+    else
+    {
+        client->errorValue = stuff->cmap;
+        return (BadColor);
+    }
+}
+
+int
+ProcAllocNamedColor           (client)
+    register ClientPtr client;
+{
+    ColormapPtr pcmp;
+    REQUEST(xAllocNamedColorReq);
+
+    REQUEST_FIXED_SIZE(xAllocNamedColorReq, stuff->nbytes);
+    pcmp = (ColormapPtr)SecurityLookupIDByType(client, stuff->cmap,
+                                           RT_COLORMAP, SecurityWriteAccess);
+    if (pcmp)
+    {
+       int             retval;
+
+       xAllocNamedColorReply ancr;
+
+#ifdef LBX
+       /*
+        * If the colormap is grabbed by a proxy, the server will have
+        * to regain control over the colormap.  This AllocNamedColor request
+        * will be handled after the server gets back the colormap control.
+        */
+       if (LbxCheckColorRequest (client, pcmp, (xReq *) stuff))
+           return Success;
+#endif
+       ancr.type = X_Reply;
+       ancr.length = 0;
+       ancr.sequenceNumber = client->sequence;
+
+       if(OsLookupColor(pcmp->pScreen->myNum, (char *)&stuff[1], stuff->nbytes,
+                        &ancr.exactRed, &ancr.exactGreen, &ancr.exactBlue))
+       {
+           ancr.screenRed = ancr.exactRed;
+           ancr.screenGreen = ancr.exactGreen;
+           ancr.screenBlue = ancr.exactBlue;
+           ancr.pixel = 0;
+           if( (retval = AllocColor(pcmp,
+                        &ancr.screenRed, &ancr.screenGreen, &ancr.screenBlue,
+                        &ancr.pixel, client->index)) )
+           {
+                if (client->noClientException != Success)
+                    return(client->noClientException);
+                else
+                   return(retval);
+           }
+            WriteReplyToClient(client, sizeof (xAllocNamedColorReply), &ancr);
+           return (client->noClientException);
+       }
+       else
+           return(BadName);
+       
+    }
+    else
+    {
+        client->errorValue = stuff->cmap;
+        return (BadColor);
+    }
+}
+
+int
+ProcAllocColorCells           (client)
+    register ClientPtr client;
+{
+    ColormapPtr pcmp;
+    REQUEST(xAllocColorCellsReq);
+
+    REQUEST_SIZE_MATCH(xAllocColorCellsReq);
+    pcmp = (ColormapPtr)SecurityLookupIDByType(client, stuff->cmap,
+                                       RT_COLORMAP, SecurityWriteAccess);
+    if (pcmp)
+    {
+       xAllocColorCellsReply   accr;
+       int                     npixels, nmasks, retval;
+       long                    length;
+       Pixel                   *ppixels, *pmasks;
+
+#ifdef LBX
+       /*
+        * If the colormap is grabbed by a proxy, the server will have
+        * to regain control over the colormap.  This AllocColorCells request
+        * will be handled after the server gets back the colormap control.
+        */
+       if (LbxCheckColorRequest (client, pcmp, (xReq *) stuff))
+           return Success;
+#endif
+       npixels = stuff->colors;
+       if (!npixels)
+       {
+           client->errorValue = npixels;
+           return (BadValue);
+       }
+       if (stuff->contiguous != xTrue && stuff->contiguous != xFalse)
+       {
+           client->errorValue = stuff->contiguous;
+           return (BadValue);
+       }
+       nmasks = stuff->planes;
+       length = ((long)npixels + (long)nmasks) * sizeof(Pixel);
+       ppixels = (Pixel *)ALLOCATE_LOCAL(length);
+       if(!ppixels)
+            return(BadAlloc);
+       pmasks = ppixels + npixels;
+
+       if( (retval = AllocColorCells(client->index, pcmp, npixels, nmasks, 
+                                   (Bool)stuff->contiguous, ppixels, pmasks)) )
+       {
+           DEALLOCATE_LOCAL(ppixels);
+            if (client->noClientException != Success)
+                return(client->noClientException);
+           else
+               return(retval);
+       }
+       accr.type = X_Reply;
+       accr.length = length >> 2;
+       accr.sequenceNumber = client->sequence;
+       accr.nPixels = npixels;
+       accr.nMasks = nmasks;
+        WriteReplyToClient(client, sizeof (xAllocColorCellsReply), &accr);
+       client->pSwapReplyFunc = (ReplySwapPtr) Swap32Write;
+       WriteSwappedDataToClient(client, length, ppixels);
+       DEALLOCATE_LOCAL(ppixels);
+        return (client->noClientException);        
+    }
+    else
+    {
+        client->errorValue = stuff->cmap;
+        return (BadColor);
+    }
+}
+
+int
+ProcAllocColorPlanes(client)
+    register ClientPtr client;
+{
+    ColormapPtr pcmp;
+    REQUEST(xAllocColorPlanesReq);
+
+    REQUEST_SIZE_MATCH(xAllocColorPlanesReq);
+    pcmp = (ColormapPtr)SecurityLookupIDByType(client, stuff->cmap,
+                                       RT_COLORMAP, SecurityWriteAccess);
+    if (pcmp)
+    {
+       xAllocColorPlanesReply  acpr;
+       int                     npixels, retval;
+       long                    length;
+       Pixel                   *ppixels;
+
+#ifdef LBX
+       /*
+        * If the colormap is grabbed by a proxy, the server will have
+        * to regain control over the colormap.  This AllocColorPlanes request
+        * will be handled after the server gets back the colormap control.
+        */
+       if (LbxCheckColorRequest (client, pcmp, (xReq *) stuff))
+           return Success;
+#endif
+       npixels = stuff->colors;
+       if (!npixels)
+       {
+           client->errorValue = npixels;
+           return (BadValue);
+       }
+       if (stuff->contiguous != xTrue && stuff->contiguous != xFalse)
+       {
+           client->errorValue = stuff->contiguous;
+           return (BadValue);
+       }
+       acpr.type = X_Reply;
+       acpr.sequenceNumber = client->sequence;
+       acpr.nPixels = npixels;
+       length = (long)npixels * sizeof(Pixel);
+       ppixels = (Pixel *)ALLOCATE_LOCAL(length);
+       if(!ppixels)
+            return(BadAlloc);
+       if( (retval = AllocColorPlanes(client->index, pcmp, npixels,
+           (int)stuff->red, (int)stuff->green, (int)stuff->blue,
+           (Bool)stuff->contiguous, ppixels,
+           &acpr.redMask, &acpr.greenMask, &acpr.blueMask)) )
+       {
+            DEALLOCATE_LOCAL(ppixels);
+            if (client->noClientException != Success)
+                return(client->noClientException);
+           else
+               return(retval);
+       }
+       acpr.length = length >> 2;
+       WriteReplyToClient(client, sizeof(xAllocColorPlanesReply), &acpr);
+       client->pSwapReplyFunc = (ReplySwapPtr) Swap32Write;
+       WriteSwappedDataToClient(client, length, ppixels);
+       DEALLOCATE_LOCAL(ppixels);
+        return (client->noClientException);        
+    }
+    else
+    {
+        client->errorValue = stuff->cmap;
+        return (BadColor);
+    }
+}
+
+int
+ProcFreeColors          (client)
+    register ClientPtr client;
+{
+    ColormapPtr pcmp;
+    REQUEST(xFreeColorsReq);
+
+    REQUEST_AT_LEAST_SIZE(xFreeColorsReq);
+    pcmp = (ColormapPtr)SecurityLookupIDByType(client, stuff->cmap,
+                                       RT_COLORMAP, SecurityWriteAccess);
+    if (pcmp)
+    {
+       int     count;
+        int     retval;
+
+       if(pcmp->flags & AllAllocated)
+           return(BadAccess);
+       count = ((client->req_len << 2)- sizeof(xFreeColorsReq)) >> 2;
+       retval =  FreeColors(pcmp, client->index, count,
+           (Pixel *)&stuff[1], (Pixel)stuff->planeMask);
+        if (client->noClientException != Success)
+            return(client->noClientException);
+        else
+       {
+           client->errorValue = clientErrorValue;
+            return(retval);
+       }
+
+    }
+    else
+    {
+        client->errorValue = stuff->cmap;
+        return (BadColor);
+    }
+}
+
+int
+ProcStoreColors               (client)
+    register ClientPtr client;
+{
+    ColormapPtr pcmp;
+    REQUEST(xStoreColorsReq);
+
+    REQUEST_AT_LEAST_SIZE(xStoreColorsReq);
+    pcmp = (ColormapPtr)SecurityLookupIDByType(client, stuff->cmap,
+                                       RT_COLORMAP, SecurityWriteAccess);
+    if (pcmp)
+    {
+       int     count;
+        int     retval;
+
+        count = (client->req_len << 2) - sizeof(xStoreColorsReq);
+       if (count % sizeof(xColorItem))
+           return(BadLength);
+       count /= sizeof(xColorItem);
+       retval = StoreColors(pcmp, count, (xColorItem *)&stuff[1]);
+        if (client->noClientException != Success)
+            return(client->noClientException);
+        else
+       {
+           client->errorValue = clientErrorValue;
+            return(retval);
+       }
+    }
+    else
+    {
+        client->errorValue = stuff->cmap;
+        return (BadColor);
+    }
+}
+
+int
+ProcStoreNamedColor           (client)
+    register ClientPtr client;
+{
+    ColormapPtr pcmp;
+    REQUEST(xStoreNamedColorReq);
+
+    REQUEST_FIXED_SIZE(xStoreNamedColorReq, stuff->nbytes);
+    pcmp = (ColormapPtr)SecurityLookupIDByType(client, stuff->cmap,
+                                       RT_COLORMAP, SecurityWriteAccess);
+    if (pcmp)
+    {
+       xColorItem      def;
+        int             retval;
+
+       if(OsLookupColor(pcmp->pScreen->myNum, (char *)&stuff[1],
+                        stuff->nbytes, &def.red, &def.green, &def.blue))
+       {
+           def.flags = stuff->flags;
+           def.pixel = stuff->pixel;
+           retval = StoreColors(pcmp, 1, &def);
+            if (client->noClientException != Success)
+                return(client->noClientException);
+           else
+               return(retval);
+       }
+        return (BadName);        
+    }
+    else
+    {
+        client->errorValue = stuff->cmap;
+        return (BadColor);
+    }
+}
+
+int
+ProcQueryColors(client)
+    register ClientPtr client;
+{
+    ColormapPtr pcmp;
+    REQUEST(xQueryColorsReq);
+
+    REQUEST_AT_LEAST_SIZE(xQueryColorsReq);
+    pcmp = (ColormapPtr)SecurityLookupIDByType(client, stuff->cmap,
+                                       RT_COLORMAP, SecurityReadAccess);
+    if (pcmp)
+    {
+       int                     count, retval;
+       xrgb                    *prgbs;
+       xQueryColorsReply       qcr;
+
+       count = ((client->req_len << 2) - sizeof(xQueryColorsReq)) >> 2;
+       prgbs = (xrgb *)ALLOCATE_LOCAL(count * sizeof(xrgb));
+       if(!prgbs && count)
+            return(BadAlloc);
+       if( (retval = QueryColors(pcmp, count, (Pixel *)&stuff[1], prgbs)) )
+       {
+           if (prgbs) DEALLOCATE_LOCAL(prgbs);
+           if (client->noClientException != Success)
+                return(client->noClientException);
+           else
+           {
+               client->errorValue = clientErrorValue;
+               return (retval);
+           }
+       }
+       qcr.type = X_Reply;
+       qcr.length = (count * sizeof(xrgb)) >> 2;
+       qcr.sequenceNumber = client->sequence;
+       qcr.nColors = count;
+       WriteReplyToClient(client, sizeof(xQueryColorsReply), &qcr);
+       if (count)
+       {
+           client->pSwapReplyFunc = (ReplySwapPtr) SQColorsExtend;
+           WriteSwappedDataToClient(client, count * sizeof(xrgb), prgbs);
+       }
+       if (prgbs) DEALLOCATE_LOCAL(prgbs);
+       return(client->noClientException);
+       
+    }
+    else
+    {
+        client->errorValue = stuff->cmap;
+        return (BadColor);
+    }
+} 
+
+int
+ProcLookupColor(client)
+    register ClientPtr client;
+{
+    ColormapPtr pcmp;
+    REQUEST(xLookupColorReq);
+
+    REQUEST_FIXED_SIZE(xLookupColorReq, stuff->nbytes);
+    pcmp = (ColormapPtr)SecurityLookupIDByType(client, stuff->cmap,
+                                       RT_COLORMAP, SecurityReadAccess);
+    if (pcmp)
+    {
+       xLookupColorReply lcr;
+
+       if(OsLookupColor(pcmp->pScreen->myNum, (char *)&stuff[1], stuff->nbytes,
+                        &lcr.exactRed, &lcr.exactGreen, &lcr.exactBlue))
+       {
+           lcr.type = X_Reply;
+           lcr.length = 0;
+           lcr.sequenceNumber = client->sequence;
+           lcr.screenRed = lcr.exactRed;
+           lcr.screenGreen = lcr.exactGreen;
+           lcr.screenBlue = lcr.exactBlue;
+           (*pcmp->pScreen->ResolveColor)(&lcr.screenRed,
+                                          &lcr.screenGreen,
+                                          &lcr.screenBlue,
+                                          pcmp->pVisual);
+           WriteReplyToClient(client, sizeof(xLookupColorReply), &lcr);
+           return(client->noClientException);
+       }
+        return (BadName);        
+    }
+    else
+    {
+        client->errorValue = stuff->cmap;
+        return (BadColor);
+    }
+}
+
+int
+ProcCreateCursor( client)
+    register ClientPtr client;
+{
+    CursorPtr  pCursor;
+
+    register PixmapPtr         src;
+    register PixmapPtr         msk;
+    unsigned char *    srcbits;
+    unsigned char *    mskbits;
+    unsigned short     width, height;
+    long               n;
+    CursorMetricRec cm;
+
+
+    REQUEST(xCreateCursorReq);
+
+    REQUEST_SIZE_MATCH(xCreateCursorReq);
+    LEGAL_NEW_RESOURCE(stuff->cid, client);
+
+    src = (PixmapPtr)SecurityLookupIDByType(client, stuff->source,
+                                             RT_PIXMAP, SecurityReadAccess);
+    msk = (PixmapPtr)SecurityLookupIDByType(client, stuff->mask,
+                                             RT_PIXMAP, SecurityReadAccess);
+    if (   src == (PixmapPtr)NULL)
+    {
+       client->errorValue = stuff->source;
+       return (BadPixmap);
+    }
+    if ( msk == (PixmapPtr)NULL)
+    {
+       if (stuff->mask != None)
+       {
+           client->errorValue = stuff->mask;
+           return (BadPixmap);
+       }
+    }
+    else if (  src->drawable.width != msk->drawable.width
+           || src->drawable.height != msk->drawable.height
+           || src->drawable.depth != 1
+           || msk->drawable.depth != 1)
+       return (BadMatch);
+
+    width = src->drawable.width;
+    height = src->drawable.height;
+
+    if ( stuff->x > width 
+      || stuff->y > height )
+       return (BadMatch);
+
+    n = BitmapBytePad(width)*height;
+    srcbits = (unsigned char *)xalloc(n);
+    if (!srcbits)
+       return (BadAlloc);
+    mskbits = (unsigned char *)xalloc(n);
+    if (!mskbits)
+    {
+       xfree(srcbits);
+       return (BadAlloc);
+    }
+
+    /* zeroing the (pad) bits helps some ddx cursor handling */
+    bzero((char *)srcbits, n);
+    (* src->drawable.pScreen->GetImage)( (DrawablePtr)src, 0, 0, width, height,
+                                        XYPixmap, 1, (pointer)srcbits);
+    if ( msk == (PixmapPtr)NULL)
+    {
+       register unsigned char *bits = mskbits;
+       while (--n >= 0)
+           *bits++ = ~0;
+    }
+    else
+    {
+       /* zeroing the (pad) bits helps some ddx cursor handling */
+       bzero((char *)mskbits, n);
+       (* msk->drawable.pScreen->GetImage)( (DrawablePtr)msk, 0, 0, width,
+                                       height, XYPixmap, 1, (pointer)mskbits);
+    }
+    cm.width = width;
+    cm.height = height;
+    cm.xhot = stuff->x;
+    cm.yhot = stuff->y;
+    pCursor = AllocCursor( srcbits, mskbits, &cm,
+           stuff->foreRed, stuff->foreGreen, stuff->foreBlue,
+           stuff->backRed, stuff->backGreen, stuff->backBlue);
+
+    if (pCursor && AddResource(stuff->cid, RT_CURSOR, (pointer)pCursor))
+           return (client->noClientException);
+    return BadAlloc;
+}
+
+int
+ProcCreateGlyphCursor( client)
+    register ClientPtr client;
+{
+    CursorPtr pCursor;
+    int res;
+
+    REQUEST(xCreateGlyphCursorReq);
+
+    REQUEST_SIZE_MATCH(xCreateGlyphCursorReq);
+    LEGAL_NEW_RESOURCE(stuff->cid, client);
+
+    res = AllocGlyphCursor(stuff->source, stuff->sourceChar,
+                          stuff->mask, stuff->maskChar,
+                          stuff->foreRed, stuff->foreGreen, stuff->foreBlue,
+                          stuff->backRed, stuff->backGreen, stuff->backBlue,
+                          &pCursor, client);
+    if (res != Success)
+       return res;
+    if (AddResource(stuff->cid, RT_CURSOR, (pointer)pCursor))
+       return client->noClientException;
+    return BadAlloc;
+}
+
+
+int
+ProcFreeCursor(client)
+    register ClientPtr client;
+{
+    CursorPtr pCursor;
+    REQUEST(xResourceReq);
+
+    REQUEST_SIZE_MATCH(xResourceReq);
+    pCursor = (CursorPtr)SecurityLookupIDByType(client, stuff->id,
+                                       RT_CURSOR, SecurityDestroyAccess);
+    if (pCursor) 
+    {
+       FreeResource(stuff->id, RT_NONE);
+       return (client->noClientException);
+    }
+    else 
+    {
+       client->errorValue = stuff->id;
+       return (BadCursor);
+    }
+}
+
+int
+ProcQueryBestSize   (client)
+    register ClientPtr client;
+{
+    xQueryBestSizeReply        reply;
+    register DrawablePtr pDraw;
+    ScreenPtr pScreen;
+    REQUEST(xQueryBestSizeReq);
+
+    REQUEST_SIZE_MATCH(xQueryBestSizeReq);
+    if ((stuff->class != CursorShape) && 
+       (stuff->class != TileShape) && 
+       (stuff->class != StippleShape))
+    {
+       client->errorValue = stuff->class;
+        return(BadValue);
+    }
+    SECURITY_VERIFY_GEOMETRABLE (pDraw, stuff->drawable, client,
+                                SecurityReadAccess);
+    if (stuff->class != CursorShape && pDraw->type == UNDRAWABLE_WINDOW)
+       return (BadMatch);
+    pScreen = pDraw->pScreen;
+    (* pScreen->QueryBestSize)(stuff->class, &stuff->width,
+                              &stuff->height, pScreen);
+    reply.type = X_Reply;
+    reply.length = 0;
+    reply.sequenceNumber = client->sequence;
+    reply.width = stuff->width;
+    reply.height = stuff->height;
+    WriteReplyToClient(client, sizeof(xQueryBestSizeReply), &reply);
+    return (client->noClientException);
+}
+
+
+int
+ProcSetScreenSaver            (client)
+    register ClientPtr client;
+{
+    int blankingOption, exposureOption;
+    REQUEST(xSetScreenSaverReq);
+
+    REQUEST_SIZE_MATCH(xSetScreenSaverReq);
+    blankingOption = stuff->preferBlank;
+    if ((blankingOption != DontPreferBlanking) &&
+        (blankingOption != PreferBlanking) &&
+        (blankingOption != DefaultBlanking))
+    {
+       client->errorValue = blankingOption;
+        return BadValue;
+    }
+    exposureOption = stuff->allowExpose;
+    if ((exposureOption != DontAllowExposures) &&
+        (exposureOption != AllowExposures) &&
+        (exposureOption != DefaultExposures))
+    {
+       client->errorValue = exposureOption;
+        return BadValue;
+    }
+    if (stuff->timeout < -1)
+    {
+       client->errorValue = stuff->timeout;
+        return BadValue;
+    }
+    if (stuff->interval < -1)
+    {
+       client->errorValue = stuff->interval;
+        return BadValue;
+    }
+
+    if (blankingOption == DefaultBlanking)
+       ScreenSaverBlanking = defaultScreenSaverBlanking;
+    else
+       ScreenSaverBlanking = blankingOption; 
+    if (exposureOption == DefaultExposures)
+       ScreenSaverAllowExposures = defaultScreenSaverAllowExposures;
+    else
+       ScreenSaverAllowExposures = exposureOption;
+
+    if (stuff->timeout >= 0)
+       ScreenSaverTime = stuff->timeout * MILLI_PER_SECOND;
+    else 
+       ScreenSaverTime = defaultScreenSaverTime;
+    if (stuff->interval >= 0)
+       ScreenSaverInterval = stuff->interval * MILLI_PER_SECOND;
+    else
+       ScreenSaverInterval = defaultScreenSaverInterval;
+    return (client->noClientException);
+}
+
+int
+ProcGetScreenSaver(client)
+    register ClientPtr client;
+{
+    xGetScreenSaverReply rep;
+
+    REQUEST_SIZE_MATCH(xReq);
+    rep.type = X_Reply;
+    rep.length = 0;
+    rep.sequenceNumber = client->sequence;
+    rep.timeout = ScreenSaverTime / MILLI_PER_SECOND;
+    rep.interval = ScreenSaverInterval / MILLI_PER_SECOND;
+    rep.preferBlanking = ScreenSaverBlanking;
+    rep.allowExposures = ScreenSaverAllowExposures;
+    WriteReplyToClient(client, sizeof(xGetScreenSaverReply), &rep);
+    return (client->noClientException);
+}
+
+int
+ProcChangeHosts(client)
+    register ClientPtr client;
+{
+    REQUEST(xChangeHostsReq);
+    int result;
+
+    REQUEST_FIXED_SIZE(xChangeHostsReq, stuff->hostLength);
+
+    if(stuff->mode == HostInsert)
+       result = AddHost(client, (int)stuff->hostFamily,
+                        stuff->hostLength, (pointer)&stuff[1]);
+    else if (stuff->mode == HostDelete)
+       result = RemoveHost(client, (int)stuff->hostFamily, 
+                           stuff->hostLength, (pointer)&stuff[1]);  
+    else
+    {
+       client->errorValue = stuff->mode;
+        return BadValue;
+    }
+    if (!result)
+       result = client->noClientException;
+    return (result);
+}
+
+int
+ProcListHosts(client)
+    register ClientPtr client;
+{
+    xListHostsReply reply;
+    int        len, nHosts, result;
+    pointer    pdata;
+
+    REQUEST_SIZE_MATCH(xListHostsReq);
+#ifdef XCSECURITY
+    /* untrusted clients can't list hosts */
+    if (client->trustLevel != XSecurityClientTrusted)
+    {
+       SecurityAudit("client %d attempted to list hosts\n", client->index);
+       return BadAccess;
+    }
+#endif
+    result = GetHosts(&pdata, &nHosts, &len, &reply.enabled);
+    if (result != Success)
+       return(result);
+    reply.type = X_Reply;
+    reply.sequenceNumber = client->sequence;
+    reply.nHosts = nHosts;
+    reply.length = len >> 2;
+    WriteReplyToClient(client, sizeof(xListHostsReply), &reply);
+    if (nHosts)
+    {
+       client->pSwapReplyFunc = (ReplySwapPtr) SLHostsExtend;
+       WriteSwappedDataToClient(client, len, pdata);
+    }
+    xfree(pdata);
+    return (client->noClientException);
+}
+
+int
+ProcChangeAccessControl(client)
+    register ClientPtr client;
+{
+    int result;
+    REQUEST(xSetAccessControlReq);
+
+    REQUEST_SIZE_MATCH(xSetAccessControlReq);
+    if ((stuff->mode != EnableAccess) && (stuff->mode != DisableAccess))
+    {
+       client->errorValue = stuff->mode;
+        return BadValue;
+    }
+    result = ChangeAccessControl(client, stuff->mode == EnableAccess);
+    if (!result)
+       result = client->noClientException;
+    return (result);
+}
+
+int
+ProcKillClient(client)
+    register ClientPtr client;
+{
+    REQUEST(xResourceReq);
+    ClientPtr  killclient;
+
+    REQUEST_SIZE_MATCH(xResourceReq);
+    if (stuff->id == AllTemporary)
+    {
+       CloseDownRetainedResources();
+        return (client->noClientException);
+    }
+
+    if ((killclient = LookupClient(stuff->id, client)))
+    {
+       CloseDownClient(killclient);
+       /* if an LBX proxy gets killed, isItTimeToYield will be set */
+       if (isItTimeToYield || (client == killclient))
+       {
+           /* force yield and return Success, so that Dispatch()
+            * doesn't try to touch client
+            */
+           isItTimeToYield = TRUE;
+           return (Success);
+       }
+       return (client->noClientException);
+    }
+    else
+    {
+       client->errorValue = stuff->id;
+       return (BadValue);
+    }
+}
+
+int
+ProcSetFontPath(client)
+    register ClientPtr client;
+{
+    unsigned char *ptr;
+    unsigned long nbytes, total;
+    long nfonts;
+    int n, result;
+    int error;
+    REQUEST(xSetFontPathReq);
+    
+    REQUEST_AT_LEAST_SIZE(xSetFontPathReq);
+    
+    nbytes = (client->req_len << 2) - sizeof(xSetFontPathReq);
+    total = nbytes;
+    ptr = (unsigned char *)&stuff[1];
+    nfonts = stuff->nFonts;
+    while (--nfonts >= 0)
+    {
+       if ((total == 0) || (total < (n = (*ptr + 1))))
+           return(BadLength);
+       total -= n;
+       ptr += n;
+    }
+    if (total >= 4)
+       return(BadLength);
+    result = SetFontPath(client, stuff->nFonts, (unsigned char *)&stuff[1],
+                        &error);
+    if (!result)
+    {
+       result = client->noClientException;
+       client->errorValue = error;
+    }
+    return (result);
+}
+
+int
+ProcGetFontPath(client)
+    register ClientPtr client;
+{
+    xGetFontPathReply reply;
+    int stringLens, numpaths;
+    unsigned char *bufferStart;
+
+    REQUEST_SIZE_MATCH(xReq);
+    bufferStart = GetFontPath(&numpaths, &stringLens);
+
+    reply.type = X_Reply;
+    reply.sequenceNumber = client->sequence;
+    reply.length = (stringLens + numpaths + 3) >> 2;
+    reply.nPaths = numpaths;
+
+    WriteReplyToClient(client, sizeof(xGetFontPathReply), &reply);
+    if (stringLens || numpaths)
+       (void)WriteToClient(client, stringLens + numpaths, (char *)bufferStart);
+    return(client->noClientException);
+}
+
+int
+ProcChangeCloseDownMode(client)
+    register ClientPtr client;
+{
+    REQUEST(xSetCloseDownModeReq);
+
+    REQUEST_SIZE_MATCH(xSetCloseDownModeReq);
+    if ((stuff->mode == AllTemporary) ||
+       (stuff->mode == RetainPermanent) ||
+       (stuff->mode == RetainTemporary))
+    {
+       client->closeDownMode = stuff->mode;
+       return (client->noClientException);
+    }
+    else   
+    {
+       client->errorValue = stuff->mode;
+       return (BadValue);
+    }
+}
+
+int ProcForceScreenSaver(client)
+    register ClientPtr client;
+{    
+    REQUEST(xForceScreenSaverReq);
+
+    REQUEST_SIZE_MATCH(xForceScreenSaverReq);
+    
+    if ((stuff->mode != ScreenSaverReset) && 
+       (stuff->mode != ScreenSaverActive))
+    {
+       client->errorValue = stuff->mode;
+        return BadValue;
+    }
+    SaveScreens(SCREEN_SAVER_FORCER, (int)stuff->mode);
+    return client->noClientException;
+}
+
+int ProcNoOperation(client)
+    register ClientPtr client;
+{
+    REQUEST_AT_LEAST_SIZE(xReq);
+    
+    /* noop -- don't do anything */
+    return(client->noClientException);
+}
+
+void
+InitProcVectors()
+{
+    int i;
+    for (i = 0; i<256; i++)
+    {
+       if(!ProcVector[i])
+       {
+            ProcVector[i] = SwappedProcVector[i] = ProcBadRequest;
+           ReplySwapVector[i] = ReplyNotSwappd;
+       }
+#ifdef K5AUTH
+       if (!k5_Vector[i])
+       {
+           k5_Vector[i] = k5_bad;
+       }
+#endif
+    }
+    for(i = LASTEvent; i < 128; i++)
+    {
+       EventSwapVector[i] = NotImplemented;
+    }
+    
+}
+
+/**********************
+ * CloseDownClient
+ *
+ *  Client can either mark his resources destroy or retain.  If retained and
+ *  then killed again, the client is really destroyed.
+ *********************/
+
+Bool terminateAtReset = FALSE;
+
+void
+CloseDownClient(client)
+    register ClientPtr client;
+{
+    Bool really_close_down = client->clientGone ||
+                            client->closeDownMode == DestroyAll;
+
+    if (!client->clientGone)
+    {
+       /* ungrab server if grabbing client dies */
+       if (grabState != GrabNone && grabClient == client)
+       {
+           UngrabServer(client);
+       }
+       BITCLEAR(grabWaiters, client->index);
+       DeleteClientFromAnySelections(client);
+       ReleaseActiveGrabs(client);
+       DeleteClientFontStuff(client);
+       if (!really_close_down)
+       {
+           /*  This frees resources that should never be retained
+            *  no matter what the close down mode is.  Actually we
+            *  could do this unconditionally, but it's probably
+            *  better not to traverse all the client's resources
+            *  twice (once here, once a few lines down in
+            *  FreeClientResources) in the common case of
+            *  really_close_down == TRUE.
+            */
+           FreeClientNeverRetainResources(client);
+           client->clientState = ClientStateRetained;
+           if (ClientStateCallback)
+            {
+               NewClientInfoRec clientinfo;
+
+               clientinfo.client = client; 
+               clientinfo.prefix = (xConnSetupPrefix *)NULL;  
+               clientinfo.setup = (xConnSetup *) NULL;
+               CallCallbacks((&ClientStateCallback), (pointer)&clientinfo);
+            } 
+       }
+       client->clientGone = TRUE;  /* so events aren't sent to client */
+       if (ClientIsAsleep(client))
+           ClientSignal (client);
+       ProcessWorkQueueZombies();
+#ifdef LBX
+       ProcessQTagZombies();
+#endif
+       CloseDownConnection(client);
+
+       /* If the client made it to the Running stage, nClients has
+        * been incremented on its behalf, so we need to decrement it
+        * now.  If it hasn't gotten to Running, nClients has *not*
+        * been incremented, so *don't* decrement it.
+        */
+       if (client->clientState != ClientStateInitial &&
+           client->clientState != ClientStateAuthenticating )
+       {
+           --nClients;
+       }
+    }
+
+    if (really_close_down)
+    {
+       if (client->clientState == ClientStateRunning && nClients == 0)
+       {
+           if (terminateAtReset)
+               dispatchException |= DE_TERMINATE;
+           else
+               dispatchException |= DE_RESET;
+       }
+       client->clientState = ClientStateGone;
+       if (ClientStateCallback)
+       {
+           NewClientInfoRec clientinfo;
+
+           clientinfo.client = client; 
+           clientinfo.prefix = (xConnSetupPrefix *)NULL;  
+           clientinfo.setup = (xConnSetup *) NULL;
+           CallCallbacks((&ClientStateCallback), (pointer)&clientinfo);
+       }           
+       FreeClientResources(client);
+       if (client->index < nextFreeClientID)
+           nextFreeClientID = client->index;
+       clients[client->index] = NullClient;
+       xfree(client);
+
+       while (!clients[currentMaxClients-1])
+           currentMaxClients--;
+    }
+}
+
+static void
+KillAllClients()
+{
+    int i;
+    for (i=1; i<currentMaxClients; i++)
+        if (clients[i])
+            CloseDownClient(clients[i]);     
+}
+
+/*********************
+ * CloseDownRetainedResources
+ *
+ *    Find all clients that are gone and have terminated in RetainTemporary 
+ *    and  destroy their resources.
+ *********************/
+
+void
+CloseDownRetainedResources()
+{
+    register int i;
+    register ClientPtr client;
+
+    for (i=1; i<currentMaxClients; i++)
+    {
+        client = clients[i];
+        if (client && (client->closeDownMode == RetainTemporary)
+           && (client->clientGone))
+           CloseDownClient(client);
+    }
+}
+
+void InitClient(client, i, ospriv)
+    ClientPtr client;
+    int i;
+    pointer ospriv;
+{
+    client->index = i;
+    client->sequence = 0; 
+    client->clientAsMask = ((Mask)i) << CLIENTOFFSET;
+    client->clientGone = FALSE;
+    if (i)
+    {
+       client->closeDownMode = DestroyAll;
+       client->lastDrawable = (DrawablePtr)WindowTable[0];
+       client->lastDrawableID = WindowTable[0]->drawable.id;
+    }
+    else
+    {
+       client->closeDownMode = RetainPermanent;
+       client->lastDrawable = (DrawablePtr)NULL;
+       client->lastDrawableID = INVALID;
+    }
+    client->lastGC = (GCPtr) NULL;
+    client->lastGCID = INVALID;
+    client->numSaved = 0;
+    client->saveSet = (pointer *)NULL;
+    client->noClientException = Success;
+#ifdef DEBUG
+    client->requestLogIndex = 0;
+#endif
+    client->requestVector = InitialVector;
+    client->osPrivate = ospriv;
+    client->swapped = FALSE;
+    client->big_requests = FALSE;
+    client->priority = 0;
+    client->clientState = ClientStateInitial;
+#ifdef XKB
+    if (!noXkbExtension) {
+       client->xkbClientFlags = 0;
+       client->mapNotifyMask = 0;
+       QueryMinMaxKeyCodes(&client->minKC,&client->maxKC);
+    }
+#endif
+    client->replyBytesRemaining = 0;
+#ifdef LBX
+    client->readRequest = StandardReadRequestFromClient;
+#endif
+#ifdef XCSECURITY
+    client->trustLevel = XSecurityClientTrusted;
+    client->CheckAccess = NULL;
+    client->authId = 0;
+#endif
+#ifdef XAPPGROUP
+    client->appgroup = NULL;
+#endif
+    client->fontResFunc = NULL;
+}
+
+extern int clientPrivateLen;
+extern unsigned *clientPrivateSizes;
+extern unsigned totalClientSize;
+
+int
+InitClientPrivates(client)
+    ClientPtr client;
+{
+    register char *ptr;
+    DevUnion *ppriv;
+    register unsigned *sizes;
+    register unsigned size;
+    register int i;
+
+    if (totalClientSize == sizeof(ClientRec))
+       ppriv = (DevUnion *)NULL;
+    else if (client->index)
+       ppriv = (DevUnion *)(client + 1);
+    else
+    {
+       ppriv = (DevUnion *)xalloc(totalClientSize - sizeof(ClientRec));
+       if (!ppriv)
+           return 0;
+    }
+    client->devPrivates = ppriv;
+    sizes = clientPrivateSizes;
+    ptr = (char *)(ppriv + clientPrivateLen);
+    for (i = clientPrivateLen; --i >= 0; ppriv++, sizes++)
+    {
+       if ( (size = *sizes) )
+       {
+           ppriv->ptr = (pointer)ptr;
+           ptr += size;
+       }
+       else
+           ppriv->ptr = (pointer)NULL;
+    }
+    return 1;
+}
+
+/************************
+ * int NextAvailableClient(ospriv)
+ *
+ * OS dependent portion can't assign client id's because of CloseDownModes.
+ * Returns NULL if there are no free clients.
+ *************************/
+
+ClientPtr
+NextAvailableClient(ospriv)
+    pointer ospriv;
+{
+    register int i;
+    register ClientPtr client;
+    xReq data;
+
+    i = nextFreeClientID;
+    if (i == MAXCLIENTS)
+       return (ClientPtr)NULL;
+    clients[i] = client = (ClientPtr)xalloc(totalClientSize);
+    if (!client)
+       return (ClientPtr)NULL;
+    InitClient(client, i, ospriv);
+    InitClientPrivates(client);
+    if (!InitClientResources(client))
+    {
+       xfree(client);
+       return (ClientPtr)NULL;
+    }
+    data.reqType = 1;
+    data.length = (sz_xReq + sz_xConnClientPrefix) >> 2;
+    if (!InsertFakeRequest(client, (char *)&data, sz_xReq))
+    {
+       FreeClientResources(client);
+       xfree(client);
+       return (ClientPtr)NULL;
+    }
+    if (i == currentMaxClients)
+       currentMaxClients++;
+    while ((nextFreeClientID < MAXCLIENTS) && clients[nextFreeClientID])
+       nextFreeClientID++;
+    if (ClientStateCallback)
+    {
+       NewClientInfoRec clientinfo;
+
+        clientinfo.client = client; 
+        clientinfo.prefix = (xConnSetupPrefix *)NULL;  
+        clientinfo.setup = (xConnSetup *) NULL;
+       CallCallbacks((&ClientStateCallback), (pointer)&clientinfo);
+    }  
+    return(client);
+}
+
+int
+ProcInitialConnection(client)
+    register ClientPtr client;
+{
+    REQUEST(xReq);
+    register xConnClientPrefix *prefix;
+    int whichbyte = 1;
+
+    prefix = (xConnClientPrefix *)((char *)stuff + sz_xReq);
+    if ((prefix->byteOrder != 'l') && (prefix->byteOrder != 'B'))
+       return (client->noClientException = -1);
+    if (((*(char *) &whichbyte) && (prefix->byteOrder == 'B')) ||
+       (!(*(char *) &whichbyte) && (prefix->byteOrder == 'l')))
+    {
+       client->swapped = TRUE;
+       SwapConnClientPrefix(prefix);
+    }
+    stuff->reqType = 2;
+    stuff->length += ((prefix->nbytesAuthProto + (unsigned)3) >> 2) +
+                    ((prefix->nbytesAuthString + (unsigned)3) >> 2);
+    if (client->swapped)
+    {
+       swaps(&stuff->length, whichbyte);
+    }
+    ResetCurrentRequest(client);
+    return (client->noClientException);
+}
+
+#ifdef LBX
+void
+IncrementClientCount()
+{
+    nClients++;
+}
+#endif
+
+int
+SendConnSetup(client, reason)
+    register ClientPtr client;
+    char *reason;
+{
+    register xWindowRoot *root;
+    register int i;
+    int numScreens;
+    char* lConnectionInfo;
+    xConnSetupPrefix* lconnSetupPrefix;
+
+    if (reason)
+    {
+       xConnSetupPrefix csp;
+       char pad[3];
+
+       csp.success = xFalse;
+       csp.lengthReason = strlen(reason);
+       csp.length = (csp.lengthReason + (unsigned)3) >> 2;
+       csp.majorVersion = X_PROTOCOL;
+       csp.minorVersion = X_PROTOCOL_REVISION;
+       if (client->swapped)
+           WriteSConnSetupPrefix(client, &csp);
+       else
+           (void)WriteToClient(client, sz_xConnSetupPrefix, (char *) &csp);
+        (void)WriteToClient(client, (int)csp.lengthReason, reason);
+       return (client->noClientException = -1);
+    }
+
+    numScreens = screenInfo.numScreens;
+    lConnectionInfo = ConnectionInfo;
+    lconnSetupPrefix = &connSetupPrefix;
+
+    /* We're about to start speaking X protocol back to the client by
+     * sending the connection setup info.  This means the authorization
+     * step is complete, and we can count the client as an
+     * authorized one.
+     */
+    nClients++;
+
+    client->requestVector = client->swapped ? SwappedProcVector : ProcVector;
+    client->sequence = 0;
+#ifdef XAPPGROUP
+    XagConnectionInfo (client, &lconnSetupPrefix, &lConnectionInfo, &numScreens);
+#endif
+    ((xConnSetup *)lConnectionInfo)->ridBase = client->clientAsMask;
+    ((xConnSetup *)lConnectionInfo)->ridMask = RESOURCE_ID_MASK;
+    /* fill in the "currentInputMask" */
+    root = (xWindowRoot *)(lConnectionInfo + connBlockScreenStart);
+    for (i=0; i<numScreens; i++) 
+    {
+       register unsigned int j;
+       register xDepth *pDepth;
+
+        root->currentInputMask = WindowTable[i]->eventMask |
+                                wOtherEventMasks (WindowTable[i]);
+       pDepth = (xDepth *)(root + 1);
+       for (j = 0; j < root->nDepths; j++)
+       {
+           pDepth = (xDepth *)(((char *)(pDepth + 1)) +
+                               pDepth->nVisuals * sizeof(xVisualType));
+       }
+       root = (xWindowRoot *)pDepth;
+    }
+
+    if (client->swapped)
+    {
+       WriteSConnSetupPrefix(client, lconnSetupPrefix);
+       WriteSConnectionInfo(client,
+                            (unsigned long)(lconnSetupPrefix->length << 2),
+                            lConnectionInfo);
+    }
+    else
+    {
+       (void)WriteToClient(client, sizeof(xConnSetupPrefix),
+                           (char *) lconnSetupPrefix);
+       (void)WriteToClient(client, (int)(lconnSetupPrefix->length << 2),
+                           lConnectionInfo);
+    }
+    client->clientState = ClientStateRunning;
+    if (ClientStateCallback)
+    {
+       NewClientInfoRec clientinfo;
+
+        clientinfo.client = client; 
+        clientinfo.prefix = lconnSetupPrefix;  
+        clientinfo.setup = (xConnSetup *)lConnectionInfo;
+       CallCallbacks((&ClientStateCallback), (pointer)&clientinfo);
+    }  
+    return (client->noClientException);
+}
+
+int
+ProcEstablishConnection(client)
+    register ClientPtr client;
+{
+    char *reason, *auth_proto, *auth_string;
+    register xConnClientPrefix *prefix;
+    REQUEST(xReq);
+
+    prefix = (xConnClientPrefix *)((char *)stuff + sz_xReq);
+    auth_proto = (char *)prefix + sz_xConnClientPrefix;
+    auth_string = auth_proto + ((prefix->nbytesAuthProto + 3) & ~3);
+    if ((prefix->majorVersion != X_PROTOCOL) ||
+       (prefix->minorVersion != X_PROTOCOL_REVISION))
+       reason = "Protocol version mismatch";
+    else
+       reason = ClientAuthorized(client,
+                                 (unsigned short)prefix->nbytesAuthProto,
+                                 auth_proto,
+                                 (unsigned short)prefix->nbytesAuthString,
+                                 auth_string);
+    /*
+     * If Kerberos is being used for this client, the clientState
+     * will be set to ClientStateAuthenticating at this point.
+     * More messages need to be exchanged among the X server, Kerberos
+     * server, and client to figure out if everyone is authorized.
+     * So we don't want to send the connection setup info yet, since
+     * the auth step isn't really done.
+     */
+    if (client->clientState == ClientStateCheckingSecurity)
+       client->clientState = ClientStateCheckedSecurity;
+    else if (client->clientState != ClientStateAuthenticating)
+       return(SendConnSetup(client, reason));
+    return(client->noClientException);
+}
+
+void
+SendErrorToClient(client, majorCode, minorCode, resId, errorCode)
+    ClientPtr client;
+    unsigned int majorCode;
+    unsigned int minorCode;
+    XID resId;
+    int errorCode;
+{
+    xError rep;
+
+    rep.type = X_Error;
+    rep.sequenceNumber = client->sequence;
+    rep.errorCode = errorCode;
+    rep.majorCode = majorCode;
+    rep.minorCode = minorCode;
+    rep.resourceID = resId;
+
+    WriteEventsToClient (client, 1, (xEvent *)&rep);
+}
+
+void
+DeleteWindowFromAnySelections(pWin)
+    WindowPtr pWin;
+{
+    register int i;
+
+    for (i = 0; i< NumCurrentSelections; i++)
+        if (CurrentSelections[i].pWin == pWin)
+        {
+            CurrentSelections[i].pWin = (WindowPtr)NULL;
+            CurrentSelections[i].window = None;
+           CurrentSelections[i].client = NullClient;
+       }
+}
+
+static void
+DeleteClientFromAnySelections(client)
+    ClientPtr client;
+{
+    register int i;
+
+    for (i = 0; i< NumCurrentSelections; i++)
+        if (CurrentSelections[i].client == client)
+        {
+            CurrentSelections[i].pWin = (WindowPtr)NULL;
+            CurrentSelections[i].window = None;
+           CurrentSelections[i].client = NullClient;
+       }
+}
+
+void
+MarkClientException(client)
+    ClientPtr client;
+{
+    client->noClientException = -1;
+}
diff --git a/Xserver/programs/Xserver/dix/dispatch.h b/Xserver/programs/Xserver/dix/dispatch.h
new file mode 100644 (file)
index 0000000..48b287b
--- /dev/null
@@ -0,0 +1,206 @@
+/* $XFree86: xc/programs/Xserver/dix/dispatch.h,v 3.1 1996/05/06 05:56:15 dawes Exp $ */
+/************************************************************
+
+Copyright 1996 by Thomas E. Dickey <dickey@clark.net>
+
+                        All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and its
+documentation for any purpose and without fee is hereby granted,
+provided that the above copyright notice appear in all copies and that
+both that copyright notice and this permission notice appear in
+supporting documentation, and that the name of the above listed
+copyright holder(s) not be used in advertising or publicity pertaining
+to distribution of the software without specific, written prior
+permission.
+
+THE ABOVE LISTED COPYRIGHT HOLDER(S) DISCLAIM ALL WARRANTIES WITH REGARD
+TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+AND FITNESS, IN NO EVENT SHALL THE ABOVE LISTED COPYRIGHT HOLDER(S) BE
+LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+
+********************************************************/
+
+/*
+ * This prototypes the dispatch.c module (except for functions declared in
+ * global headers), plus related dispatch procedures from devices.c, events.c,
+ * extension.c, property.c. 
+ */
+
+#ifndef DISPATCH_H
+#define DISPATCH_H 1
+
+#ifdef LBX
+void IncrementClientCount(
+#if NeedFunctionPrototypes
+    void
+#endif
+);
+#endif
+
+void CloseDownClient(
+#if NeedFunctionPrototypes
+    ClientPtr client
+#endif
+);
+
+void Dispatch(
+#if NeedFunctionPrototypes
+    void
+#endif
+);
+
+void InitProcVectors(
+#if NeedFunctionPrototypes
+    void
+#endif
+);
+
+ClientPtr NextAvailableClient(
+#if NeedFunctionPrototypes
+    pointer ospriv
+#endif
+);
+
+int SendConnSetup(
+#if NeedFunctionPrototypes
+    ClientPtr /* client */,
+    char * /* reason */
+#endif
+);
+
+void SetInputCheck(
+#if NeedFunctionPrototypes
+    HWEventQueuePtr /* c0 */,
+    HWEventQueuePtr /* c1 */
+#endif
+);
+
+DISPATCH_PROC(InitClientPrivates);
+DISPATCH_PROC(ProcAllocColor);
+DISPATCH_PROC(ProcAllocColorCells);
+DISPATCH_PROC(ProcAllocColorPlanes);
+DISPATCH_PROC(ProcAllocNamedColor);
+DISPATCH_PROC(ProcAllowEvents);
+DISPATCH_PROC(ProcBadRequest);
+DISPATCH_PROC(ProcBell);
+DISPATCH_PROC(ProcChangeAccessControl);
+DISPATCH_PROC(ProcChangeActivePointerGrab);
+DISPATCH_PROC(ProcChangeCloseDownMode);
+DISPATCH_PROC(ProcChangeGC);
+DISPATCH_PROC(ProcChangeHosts);
+DISPATCH_PROC(ProcChangeKeyboardControl);
+DISPATCH_PROC(ProcChangeKeyboardMapping);
+DISPATCH_PROC(ProcChangePointerControl);
+DISPATCH_PROC(ProcChangeProperty);
+DISPATCH_PROC(ProcChangeSaveSet);
+DISPATCH_PROC(ProcChangeWindowAttributes);
+DISPATCH_PROC(ProcCirculateWindow);
+DISPATCH_PROC(ProcClearToBackground);
+DISPATCH_PROC(ProcCloseFont);
+DISPATCH_PROC(ProcConfigureWindow);
+DISPATCH_PROC(ProcConvertSelection);
+DISPATCH_PROC(ProcCopyArea);
+DISPATCH_PROC(ProcCopyColormapAndFree);
+DISPATCH_PROC(ProcCopyGC);
+DISPATCH_PROC(ProcCopyPlane);
+DISPATCH_PROC(ProcCreateColormap);
+DISPATCH_PROC(ProcCreateCursor);
+DISPATCH_PROC(ProcCreateGC);
+DISPATCH_PROC(ProcCreateGlyphCursor);
+DISPATCH_PROC(ProcCreatePixmap);
+DISPATCH_PROC(ProcCreateWindow);
+DISPATCH_PROC(ProcDeleteProperty);
+DISPATCH_PROC(ProcDestroySubwindows);
+DISPATCH_PROC(ProcDestroyWindow);
+DISPATCH_PROC(ProcEstablishConnection);
+DISPATCH_PROC(ProcFillPoly);
+DISPATCH_PROC(ProcForceScreenSaver);
+DISPATCH_PROC(ProcFreeColormap);
+DISPATCH_PROC(ProcFreeColors);
+DISPATCH_PROC(ProcFreeCursor);
+DISPATCH_PROC(ProcFreeGC);
+DISPATCH_PROC(ProcFreePixmap);
+DISPATCH_PROC(ProcGetAtomName);
+DISPATCH_PROC(ProcGetFontPath);
+DISPATCH_PROC(ProcGetGeometry);
+DISPATCH_PROC(ProcGetImage);
+DISPATCH_PROC(ProcGetInputFocus);
+DISPATCH_PROC(ProcGetKeyboardControl);
+DISPATCH_PROC(ProcGetKeyboardMapping);
+DISPATCH_PROC(ProcGetModifierMapping);
+DISPATCH_PROC(ProcGetMotionEvents);
+DISPATCH_PROC(ProcGetPointerControl);
+DISPATCH_PROC(ProcGetPointerMapping);
+DISPATCH_PROC(ProcGetProperty);
+DISPATCH_PROC(ProcGetScreenSaver);
+DISPATCH_PROC(ProcGetSelectionOwner);
+DISPATCH_PROC(ProcGetWindowAttributes);
+DISPATCH_PROC(ProcGrabButton);
+DISPATCH_PROC(ProcGrabKey);
+DISPATCH_PROC(ProcGrabKeyboard);
+DISPATCH_PROC(ProcGrabPointer);
+DISPATCH_PROC(ProcGrabServer);
+DISPATCH_PROC(ProcImageText16);
+DISPATCH_PROC(ProcImageText8);
+DISPATCH_PROC(ProcInitialConnection);
+DISPATCH_PROC(ProcInstallColormap);
+DISPATCH_PROC(ProcInternAtom);
+DISPATCH_PROC(ProcKillClient);
+DISPATCH_PROC(ProcListExtensions);
+DISPATCH_PROC(ProcListFonts);
+DISPATCH_PROC(ProcListFontsWithInfo);
+DISPATCH_PROC(ProcListHosts);
+DISPATCH_PROC(ProcListInstalledColormaps);
+DISPATCH_PROC(ProcListProperties);
+DISPATCH_PROC(ProcLookupColor);
+DISPATCH_PROC(ProcMapSubwindows);
+DISPATCH_PROC(ProcMapWindow);
+DISPATCH_PROC(ProcNoOperation);
+DISPATCH_PROC(ProcOpenFont);
+DISPATCH_PROC(ProcPolyArc);
+DISPATCH_PROC(ProcPolyFillArc);
+DISPATCH_PROC(ProcPolyFillRectangle);
+DISPATCH_PROC(ProcPolyLine);
+DISPATCH_PROC(ProcPolyPoint);
+DISPATCH_PROC(ProcPolyRectangle);
+DISPATCH_PROC(ProcPolySegment);
+DISPATCH_PROC(ProcPolyText);
+DISPATCH_PROC(ProcPutImage);
+DISPATCH_PROC(ProcQueryBestSize);
+DISPATCH_PROC(ProcQueryColors);
+DISPATCH_PROC(ProcQueryExtension);
+DISPATCH_PROC(ProcQueryFont);
+DISPATCH_PROC(ProcQueryKeymap);
+DISPATCH_PROC(ProcQueryPointer);
+DISPATCH_PROC(ProcQueryTextExtents);
+DISPATCH_PROC(ProcQueryTree);
+DISPATCH_PROC(ProcRecolorCursor);
+DISPATCH_PROC(ProcReparentWindow);
+DISPATCH_PROC(ProcRotateProperties);
+DISPATCH_PROC(ProcSendEvent);
+DISPATCH_PROC(ProcSetClipRectangles);
+DISPATCH_PROC(ProcSetDashes);
+DISPATCH_PROC(ProcSetFontPath);
+DISPATCH_PROC(ProcSetInputFocus);
+DISPATCH_PROC(ProcSetModifierMapping);
+DISPATCH_PROC(ProcSetPointerMapping);
+DISPATCH_PROC(ProcSetScreenSaver);
+DISPATCH_PROC(ProcSetSelectionOwner);
+DISPATCH_PROC(ProcStoreColors);
+DISPATCH_PROC(ProcStoreNamedColor);
+DISPATCH_PROC(ProcTranslateCoords);
+DISPATCH_PROC(ProcUngrabButton);
+DISPATCH_PROC(ProcUngrabKey);
+DISPATCH_PROC(ProcUngrabKeyboard);
+DISPATCH_PROC(ProcUngrabPointer);
+DISPATCH_PROC(ProcUngrabServer);
+DISPATCH_PROC(ProcUninstallColormap);
+DISPATCH_PROC(ProcUnmapSubwindows);
+DISPATCH_PROC(ProcUnmapWindow);
+DISPATCH_PROC(ProcWarpPointer);
+
+#endif /* DISPATCH_H */
diff --git a/Xserver/programs/Xserver/dix/dixfonts.c b/Xserver/programs/Xserver/dix/dixfonts.c
new file mode 100644 (file)
index 0000000..f086d6d
--- /dev/null
@@ -0,0 +1,2270 @@
+/************************************************************************
+Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
+
+                        All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and its
+documentation for any purpose and without fee is hereby granted,
+provided that the above copyright notice appear in all copies and that
+both that copyright notice and this permission notice appear in
+supporting documentation, and that the name of Digital not be
+used in advertising or publicity pertaining to distribution of the
+software without specific, written prior permission.
+
+DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
+ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
+DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
+ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+SOFTWARE.
+
+************************************************************************/
+
+/* $XConsortium: dixfonts.c /main/58 1996/09/28 17:11:55 rws $ */
+/* $XFree86: xc/programs/Xserver/dix/dixfonts.c,v 3.6 1996/12/23 06:29:40 dawes Exp $ */
+
+#define NEED_REPLIES
+#include "X.h"
+#include "Xmd.h"
+#include "Xproto.h"
+#include "scrnintstr.h"
+#include "resource.h"
+#include "dixstruct.h"
+#include "cursorstr.h"
+#include "misc.h"
+#include "opaque.h"
+#include "dixfontstr.h"
+#include "closestr.h"
+
+#ifdef DEBUG
+#include       <stdio.h>
+#endif
+
+#define QUERYCHARINFO(pci, pr)  *(pr) = (pci)->metrics
+
+static Mask FontFormat = 
+#if IMAGE_BYTE_ORDER == LSBFirst
+    BitmapFormatByteOrderLSB |
+#else
+    BitmapFormatByteOrderMSB |
+#endif
+
+#if BITMAP_BIT_ORDER == LSBFirst
+    BitmapFormatBitOrderLSB |
+#else
+    BitmapFormatBitOrderMSB |
+#endif
+
+    BitmapFormatImageRectMin |
+
+#if GLYPHPADBYTES == 1
+    BitmapFormatScanlinePad8 |
+#endif
+
+#if GLYPHPADBYTES == 2
+    BitmapFormatScanlinePad16 |
+#endif
+
+#if GLYPHPADBYTES == 4
+    BitmapFormatScanlinePad32 |
+#endif
+
+#if GLYPHPADBYTES == 8
+    BitmapFormatScanlinePad64 |
+#endif
+
+    BitmapFormatScanlineUnit8;
+
+extern pointer fosNaturalParams;
+extern FontPtr defaultFont;
+
+static FontPathElementPtr *font_path_elements = (FontPathElementPtr *) 0;
+static int  num_fpes = 0;
+static FPEFunctions *fpe_functions = (FPEFunctions *) 0;
+static int  num_fpe_types = 0;
+
+static unsigned char *font_path_string;
+
+static int  num_slept_fpes = 0;
+static int  size_slept_fpes = 0;
+static FontPathElementPtr *slept_fpes = (FontPathElementPtr *) 0;
+static FontPatternCachePtr patternCache;
+
+int
+FontToXError(err)
+    int         err;
+{
+    switch (err) {
+    case Successful:
+       return Success;
+    case AllocError:
+       return BadAlloc;
+    case BadFontName:
+    case BadFontPath:
+       return BadName;
+    case BadFontFormat:        /* is there something better? */
+    case BadCharRange:
+       return BadValue;
+    default:
+       return err;
+    }
+}
+
+
+/*
+ * adding RT_FONT prevents conflict with default cursor font
+ */
+Bool
+SetDefaultFont(defaultfontname)
+    char       *defaultfontname;
+{
+    int         err;
+    FontPtr     pf;
+    XID         fid;
+
+    fid = FakeClientID(0);
+    err = OpenFont(serverClient, fid, FontLoadAll | FontOpenSync,
+                  (unsigned) strlen(defaultfontname), defaultfontname);
+    if (err != Success)
+       return FALSE;
+    pf = (FontPtr) LookupIDByType(fid, RT_FONT);
+    if (pf == (FontPtr) NULL)
+       return FALSE;
+    defaultFont = pf;
+    return TRUE;
+}
+
+/*
+ * note that the font wakeup queue is not refcounted.  this is because
+ * an fpe needs to be added when it's inited, and removed when it's finally
+ * freed, in order to handle any data that isn't requested, like FS events.
+ *
+ * since the only thing that should call these routines is the renderer's
+ * init_fpe() and free_fpe(), there shouldn't be any problem in using
+ * freed data.
+ */
+void
+QueueFontWakeup(fpe)
+    FontPathElementPtr fpe;
+{
+    int         i;
+    FontPathElementPtr *new;
+
+    for (i = 0; i < num_slept_fpes; i++) {
+       if (slept_fpes[i] == fpe) {
+
+#ifdef DEBUG
+           fprintf(stderr, "re-queueing fpe wakeup\n");
+#endif
+
+           return;
+       }
+    }
+    if (num_slept_fpes == size_slept_fpes) {
+       new = (FontPathElementPtr *)
+           xrealloc(slept_fpes,
+                    sizeof(FontPathElementPtr) * (size_slept_fpes + 4));
+       if (!new)
+           return;
+       slept_fpes = new;
+       size_slept_fpes += 4;
+    }
+    slept_fpes[num_slept_fpes] = fpe;
+    num_slept_fpes++;
+}
+
+void
+RemoveFontWakeup(fpe)
+    FontPathElementPtr fpe;
+{
+    int         i,
+                j;
+
+    for (i = 0; i < num_slept_fpes; i++) {
+       if (slept_fpes[i] == fpe) {
+           for (j = i; j < num_slept_fpes; j++) {
+               slept_fpes[j] = slept_fpes[j + 1];
+           }
+           num_slept_fpes--;
+           return;
+       }
+    }
+}
+
+/* ARGSUSED */
+void
+FontWakeup(data, count, LastSelectMask)
+    pointer     data;
+    int                count;
+    pointer     LastSelectMask;
+{
+    int         i;
+    FontPathElementPtr fpe;
+
+    if (count < 0)
+       return;
+    /* wake up any fpe's that may be waiting for information */
+    for (i = 0; i < num_slept_fpes; i++) {
+       fpe = slept_fpes[i];
+       (void) (*fpe_functions[fpe->type].wakeup_fpe) (fpe, LastSelectMask);
+    }
+}
+
+/* XXX -- these two funcs may want to be broken into macros */
+static void
+#if NeedFunctionPrototypes
+UseFPE(FontPathElementPtr fpe)
+#else
+UseFPE(fpe)
+    FontPathElementPtr fpe;
+#endif
+{
+    fpe->refcount++;
+}
+
+static void
+#if NeedFunctionPrototypes
+FreeFPE (FontPathElementPtr fpe)
+#else
+FreeFPE (fpe)
+    FontPathElementPtr fpe;
+#endif
+{
+    fpe->refcount--;
+    if (fpe->refcount == 0) {
+       (*fpe_functions[fpe->type].free_fpe) (fpe);
+       xfree(fpe->name);
+       xfree(fpe);
+    }
+}
+
+static Bool
+#if NeedFunctionPrototypes
+doOpenFont(ClientPtr client, OFclosurePtr c)
+#else
+doOpenFont(client, c)
+    ClientPtr   client;
+    OFclosurePtr c;
+#endif
+{
+    FontPtr     pfont = NullFont;
+    FontPathElementPtr fpe;
+    ScreenPtr   pScr;
+    int         err = Successful;
+    int         i;
+    char       *alias,
+               *newname;
+    int         newlen;
+    int                aliascount = 20;
+
+    if (client->clientGone)
+    {
+       if (c->current_fpe < c->num_fpes)
+       {
+           fpe = c->fpe_list[c->current_fpe];
+           (*fpe_functions[fpe->type].client_died) ((pointer) client, fpe);
+       }
+       err = Successful;
+       goto bail;
+    }
+    while (c->current_fpe < c->num_fpes) {
+       fpe = c->fpe_list[c->current_fpe];
+       err = (*fpe_functions[fpe->type].open_font)
+           ((pointer) client, fpe, c->flags,
+            c->fontname, c->fnamelen, FontFormat,
+            BitmapFormatMaskByte |
+            BitmapFormatMaskBit |
+            BitmapFormatMaskImageRectangle |
+            BitmapFormatMaskScanLinePad |
+            BitmapFormatMaskScanLineUnit,
+            c->fontid, &pfont, &alias,
+            c->non_cachable_font && c->non_cachable_font->fpe == fpe ?
+                c->non_cachable_font :
+                (FontPtr)0);
+
+       if (err == FontNameAlias && alias) {
+           newlen = strlen(alias);
+           newname = (char *) xrealloc(c->fontname, newlen);
+           if (!newname) {
+               err = AllocError;
+               break;
+           }
+           memmove(newname, alias, newlen);
+           c->fontname = newname;
+           c->fnamelen = newlen;
+           c->current_fpe = 0;
+           if (--aliascount <= 0)
+               break;
+           continue;
+       }
+       if (err == BadFontName) {
+           c->current_fpe++;
+           continue;
+       }
+       if (err == Suspended) {
+           if (!c->slept) {
+               c->slept = TRUE;
+               ClientSleep(client, (ClientSleepProcPtr)doOpenFont, (pointer) c);
+           }
+           return TRUE;
+       }
+       break;
+    }
+
+    if (err != Successful)
+       goto bail;
+    if (!pfont) {
+       err = BadFontName;
+       goto bail;
+    }
+    if (!pfont->fpe)
+       pfont->fpe = fpe;
+    pfont->refcnt++;
+    if (pfont->refcnt == 1) {
+       UseFPE(pfont->fpe);
+       for (i = 0; i < screenInfo.numScreens; i++) {
+           pScr = screenInfo.screens[i];
+           if (pScr->RealizeFont)
+           {
+               if (!(*pScr->RealizeFont) (pScr, pfont))
+               {
+                   CloseFont (pfont, (Font) 0);
+                   err = AllocError;
+                   goto bail;
+               }
+           }
+       }
+    }
+    if (!AddResource(c->fontid, RT_FONT, (pointer) pfont)) {
+       err = AllocError;
+       goto bail;
+    }
+    if (patternCache && pfont != c->non_cachable_font)
+       CacheFontPattern(patternCache, c->origFontName, c->origFontNameLen,
+                        pfont);
+bail:
+    if (err != Successful && c->client != serverClient) {
+       SendErrorToClient(c->client, X_OpenFont, 0,
+                         c->fontid, FontToXError(err));
+    }
+    if (c->slept)
+       ClientWakeup(c->client);
+    for (i = 0; i < c->num_fpes; i++) {
+       FreeFPE(c->fpe_list[i]);
+    }
+    xfree(c->fpe_list);
+    xfree(c->fontname);
+    xfree(c);
+    return TRUE;
+}
+
+int
+OpenFont(client, fid, flags, lenfname, pfontname)
+    ClientPtr   client;
+    XID         fid;
+    Mask        flags;
+    unsigned    lenfname;
+    char       *pfontname;
+{
+    OFclosurePtr c;
+    int         i;
+    FontPtr     cached = (FontPtr)0;
+
+#ifdef FONTDEBUG
+    char *f;
+    f = (char *)xalloc(lenfname + 1);
+    memmove(f, pfontname, lenfname);
+    f[lenfname] = '\0';
+    ErrorF("OpenFont: fontname is \"%s\"\n", f);
+    xfree(f);
+#endif
+    if (!lenfname)
+       return BadName;
+    if (patternCache)
+    {
+
+    /*
+    ** Check name cache.  If we find a cached version of this font that
+    ** is cachable, immediately satisfy the request with it.  If we find
+    ** a cached version of this font that is non-cachable, we do not
+    ** satisfy the request with it.  Instead, we pass the FontPtr to the
+    ** FPE's open_font code (the fontfile FPE in turn passes the
+    ** information to the rasterizer; the fserve FPE ignores it).
+    **
+    ** Presumably, the font is marked non-cachable because the FPE has
+    ** put some licensing restrictions on it.  If the FPE, using
+    ** whatever logic it relies on, determines that it is willing to
+    ** share this existing font with the client, then it has the option
+    ** to return the FontPtr we passed it as the newly-opened font.
+    ** This allows the FPE to exercise its licensing logic without
+    ** having to create another instance of a font that already exists.
+    */
+
+       cached = FindCachedFontPattern(patternCache, pfontname, lenfname);
+       if (cached && cached->info.cachable)
+       {
+           if (!AddResource(fid, RT_FONT, (pointer) cached))
+               return BadAlloc;
+           cached->refcnt++;
+           return Success;
+       }
+    }
+    c = (OFclosurePtr) xalloc(sizeof(OFclosureRec));
+    if (!c)
+       return BadAlloc;
+    c->fontname = (char *) xalloc(lenfname);
+    c->origFontName = pfontname;
+    c->origFontNameLen = lenfname;
+    if (!c->fontname) {
+       xfree(c);
+       return BadAlloc;
+    }
+    /*
+     * copy the current FPE list, so that if it gets changed by another client
+     * while we're blocking, the request still appears atomic
+     */
+    c->fpe_list = (FontPathElementPtr *)
+       xalloc(sizeof(FontPathElementPtr) * num_fpes);
+    if (!c->fpe_list) {
+       xfree(c->fontname);
+       xfree(c);
+       return BadAlloc;
+    }
+    memmove(c->fontname, pfontname, lenfname);
+    for (i = 0; i < num_fpes; i++) {
+       c->fpe_list[i] = font_path_elements[i];
+       UseFPE(c->fpe_list[i]);
+    }
+    c->client = client;
+    c->fontid = fid;
+    c->current_fpe = 0;
+    c->num_fpes = num_fpes;
+    c->fnamelen = lenfname;
+    c->slept = FALSE;
+    c->flags = flags;
+    c->non_cachable_font = cached;
+
+    (void) doOpenFont(client, c);
+    return Success;
+}
+
+/*
+ * Decrement font's ref count, and free storage if ref count equals zero
+ */
+/*ARGSUSED*/
+int
+CloseFont(value, fid)
+    pointer    value;  /* must conform to DeleteType */
+    XID                fid;
+{
+    int         nscr;
+    ScreenPtr   pscr;
+    FontPathElementPtr fpe;
+    FontPtr     pfont = (FontPtr)value;
+
+    if (pfont == NullFont)
+       return (Success);
+    if (--pfont->refcnt == 0) {
+       if (patternCache && pfont->info.cachable)
+           RemoveCachedFontPattern (patternCache, pfont);
+       /*
+        * since the last reference is gone, ask each screen to free any
+        * storage it may have allocated locally for it.
+        */
+       for (nscr = 0; nscr < screenInfo.numScreens; nscr++) {
+           pscr = screenInfo.screens[nscr];
+           if (pscr->UnrealizeFont)
+               (*pscr->UnrealizeFont) (pscr, pfont);
+       }
+       if (pfont == defaultFont)
+           defaultFont = NULL;
+#ifdef LBX
+       LbxFreeFontTag(pfont);
+#endif
+       fpe = pfont->fpe;
+       (*fpe_functions[fpe->type].close_font) (fpe, pfont);
+       FreeFPE(fpe);
+    }
+    return (Success);
+}
+
+
+/***====================================================================***/
+
+ /*
+  * \ Sets up pReply as the correct QueryFontReply for pFont with the first
+  * nProtoCCIStructs char infos. \
+  */
+
+void
+QueryFont(pFont, pReply, nProtoCCIStructs)
+    FontPtr          pFont;
+    xQueryFontReply *pReply;   /* caller must allocate this storage */
+    int              nProtoCCIStructs;
+{
+    FontPropPtr      pFP;
+    int              r,
+                     c,
+                     i;
+    xFontProp       *prFP;
+    xCharInfo       *prCI;
+    xCharInfo       *charInfos[256];
+    unsigned char    chars[512];
+    int              ninfos;
+    unsigned long    ncols;
+    unsigned long    count;
+
+    /* pr->length set in dispatch */
+    pReply->minCharOrByte2 = pFont->info.firstCol;
+    pReply->defaultChar = pFont->info.defaultCh;
+    pReply->maxCharOrByte2 = pFont->info.lastCol;
+    pReply->drawDirection = pFont->info.drawDirection;
+    pReply->allCharsExist = pFont->info.allExist;
+    pReply->minByte1 = pFont->info.firstRow;
+    pReply->maxByte1 = pFont->info.lastRow;
+    pReply->fontAscent = pFont->info.fontAscent;
+    pReply->fontDescent = pFont->info.fontDescent;
+
+    pReply->minBounds = pFont->info.ink_minbounds;
+    pReply->maxBounds = pFont->info.ink_maxbounds;
+
+    pReply->nFontProps = pFont->info.nprops;
+    pReply->nCharInfos = nProtoCCIStructs;
+
+    for (i = 0, pFP = pFont->info.props, prFP = (xFontProp *) (&pReply[1]);
+           i < pFont->info.nprops;
+           i++, pFP++, prFP++) {
+       prFP->name = pFP->name;
+       prFP->value = pFP->value;
+    }
+
+    ninfos = 0;
+    ncols = (unsigned long) (pFont->info.lastCol - pFont->info.firstCol + 1);
+    prCI = (xCharInfo *) (prFP);
+    for (r = pFont->info.firstRow;
+           ninfos < nProtoCCIStructs && r <= (int)pFont->info.lastRow;
+           r++) {
+       i = 0;
+       for (c = pFont->info.firstCol; c <= (int)pFont->info.lastCol; c++) {
+           chars[i++] = r;
+           chars[i++] = c;
+       }
+       (*pFont->get_metrics) (pFont, ncols, chars, TwoD16Bit,
+                              &count, charInfos);
+       i = 0;
+       for (i = 0; i < (int) count && ninfos < nProtoCCIStructs; i++) {
+           *prCI = *charInfos[i];
+           prCI++;
+           ninfos++;
+       }
+    }
+    return;
+}
+
+static Bool
+#if NeedFunctionPrototypes
+doListFontsAndAliases(ClientPtr client, LFclosurePtr c)
+#else
+doListFontsAndAliases(client, c)
+    ClientPtr   client;
+    LFclosurePtr c;
+#endif
+{
+    FontPathElementPtr fpe;
+    int         err = Successful;
+    FontNamesPtr names = NULL;
+    char       *name, *resolved=NULL;
+    int         namelen, resolvedlen;
+    int                nnames;
+    int         stringLens;
+    int         i;
+    xListFontsReply reply;
+    char       *bufptr;
+    char       *bufferStart;
+    int                aliascount;
+
+    if (client->clientGone)
+    {
+       if (c->current.current_fpe < c->num_fpes)
+       {
+           fpe = c->fpe_list[c->current.current_fpe];
+           (*fpe_functions[fpe->type].client_died) ((pointer) client, fpe);
+       }
+       err = Successful;
+       goto bail;
+    }
+
+    if (!c->current.patlen)
+       goto finish;
+
+    while (c->current.current_fpe < c->num_fpes) {
+       fpe = c->fpe_list[c->current.current_fpe];
+       err = Successful;
+
+       if (!fpe_functions[fpe->type].start_list_fonts_and_aliases)
+       {
+           /* This FPE doesn't support/require list_fonts_and_aliases */
+
+           err = (*fpe_functions[fpe->type].list_fonts)
+               ((pointer) c->client, fpe, c->current.pattern,
+                c->current.patlen, c->current.max_names - c->names->nnames,
+                c->names);
+
+           if (err == Suspended) {
+               if (!c->slept) {
+                   c->slept = TRUE;
+                   ClientSleep(client,
+                       (ClientSleepProcPtr)doListFontsAndAliases,
+                       (pointer) c);
+               }
+               return TRUE;
+           }
+
+           err = BadFontName;
+       }
+       else
+       {
+           /* Start of list_fonts_and_aliases functionality.  Modeled
+              after list_fonts_with_info in that it resolves aliases,
+              except that the information collected from FPEs is just
+              names, not font info.  Each list_next_font_or_alias()
+              returns either a name into name/namelen or an alias into
+              name/namelen and its target name into resolved/resolvedlen.
+              The code at this level then resolves the alias by polling
+              the FPEs.  */
+
+           if (!c->current.list_started) {
+               err = (*fpe_functions[fpe->type].start_list_fonts_and_aliases)
+                   ((pointer) c->client, fpe, c->current.pattern,
+                    c->current.patlen, c->current.max_names - c->names->nnames,
+                    &c->current.private);
+               if (err == Suspended) {
+                   if (!c->slept) {
+                       ClientSleep(client,
+                                   (ClientSleepProcPtr)doListFontsAndAliases,
+                                   (pointer) c);
+                       c->slept = TRUE;
+                   }
+                   return TRUE;
+               }
+               if (err == Successful)
+                   c->current.list_started = TRUE;
+           }
+           if (err == Successful) {
+               char    *tmpname;
+               name = 0;
+               err = (*fpe_functions[fpe->type].list_next_font_or_alias)
+                   ((pointer) c->client, fpe, &name, &namelen, &tmpname,
+                    &resolvedlen, c->current.private);
+               if (err == Suspended) {
+                   if (!c->slept) {
+                       ClientSleep(client,
+                                   (ClientSleepProcPtr)doListFontsAndAliases,
+                                   (pointer) c);
+                       c->slept = TRUE;
+                   }
+                   return TRUE;
+               }
+               if (err == FontNameAlias) {
+                   if (resolved) xfree(resolved);
+                   resolved = (char *) xalloc(resolvedlen + 1);
+                   if (resolved)
+                       memmove(resolved, tmpname, resolvedlen + 1);
+               }
+           }
+
+           if (err == Successful)
+           {
+               if (c->haveSaved)
+               {
+                   if (c->savedName)
+                       (void)AddFontNamesName(c->names, c->savedName,
+                                              c->savedNameLen);
+               }
+               else
+                   (void)AddFontNamesName(c->names, name, namelen);
+           }
+
+           /*
+            * When we get an alias back, save our state and reset back to
+            * the start of the FPE looking for the specified name.  As
+            * soon as a real font is found for the alias, pop back to the
+            * old state
+            */
+           else if (err == FontNameAlias) {
+               char    tmp_pattern[256];
+               /*
+                * when an alias recurses, we need to give
+                * the last FPE a chance to clean up; so we call
+                * it again, and assume that the error returned
+                * is BadFontName, indicating the alias resolution
+                * is complete.
+                */
+               memmove(tmp_pattern, resolved, resolvedlen);
+               if (c->haveSaved)
+               {
+                   char    *tmpname;
+                   int     tmpnamelen;
+
+                   tmpname = 0;
+                   (void) (*fpe_functions[fpe->type].list_next_font_or_alias)
+                       ((pointer) c->client, fpe, &tmpname, &tmpnamelen,
+                        &tmpname, &tmpnamelen, c->current.private);
+                   if (--aliascount <= 0)
+                   {
+                       err = BadFontName;
+                       goto ContBadFontName;
+                   }
+               }
+               else
+               {
+                   c->saved = c->current;
+                   c->haveSaved = TRUE;
+                   if (c->savedName)
+                       xfree(c->savedName);
+                   c->savedName = (char *)xalloc(namelen + 1);
+                   if (c->savedName)
+                       memmove(c->savedName, name, namelen + 1);
+                   c->savedNameLen = namelen;
+                   aliascount = 20;
+               }
+               memmove(c->current.pattern, tmp_pattern, resolvedlen);
+               c->current.patlen = resolvedlen;
+               c->current.max_names = c->names->nnames + 1;
+               c->current.current_fpe = -1;
+               c->current.private = 0;
+               err = BadFontName;
+           }
+       }
+       /*
+        * At the end of this FPE, step to the next.  If we've finished
+        * processing an alias, pop state back. If we've collected enough
+        * font names, quit.
+        */
+       if (err == BadFontName) {
+         ContBadFontName: ;
+           c->current.list_started = FALSE;
+           c->current.current_fpe++;
+           err = Successful;
+           if (c->haveSaved)
+           {
+               if (c->names->nnames == c->current.max_names ||
+                       c->current.current_fpe == c->num_fpes) {
+                   c->haveSaved = FALSE;
+                   c->current = c->saved;
+                   /* Give the saved namelist a chance to clean itself up */
+                   continue;
+               }
+           }
+           if (c->names->nnames == c->current.max_names)
+               break;
+       }
+    }
+
+    /*
+     * send the reply
+     */
+    if (err != Successful) {
+       SendErrorToClient(client, X_ListFonts, 0, 0, FontToXError(err));
+       goto bail;
+    }
+
+finish:
+
+    names = c->names;
+    nnames = names->nnames;
+    client = c->client;
+    stringLens = 0;
+    for (i = 0; i < nnames; i++)
+       stringLens += (names->length[i] <= 255) ? names->length[i] : 0;
+
+    reply.type = X_Reply;
+    reply.length = (stringLens + nnames + 3) >> 2;
+    reply.nFonts = nnames;
+    reply.sequenceNumber = client->sequence;
+
+    bufptr = bufferStart = (char *) ALLOCATE_LOCAL(reply.length << 2);
+
+    if (!bufptr && reply.length) {
+       SendErrorToClient(client, X_ListFonts, 0, 0, BadAlloc);
+       goto bail;
+    }
+    /*
+     * since WriteToClient long word aligns things, copy to temp buffer and
+     * write all at once
+     */
+    for (i = 0; i < nnames; i++) {
+       if (names->length[i] > 255)
+           reply.nFonts--;
+       else
+       {
+           *bufptr++ = names->length[i];
+           memmove( bufptr, names->names[i], names->length[i]);
+           bufptr += names->length[i];
+       }
+    }
+    nnames = reply.nFonts;
+    reply.length = (stringLens + nnames + 3) >> 2;
+    client->pSwapReplyFunc = ReplySwapVector[X_ListFonts];
+    WriteSwappedDataToClient(client, sizeof(xListFontsReply), &reply);
+    (void) WriteToClient(client, stringLens + nnames, bufferStart);
+    DEALLOCATE_LOCAL(bufferStart);
+
+bail:
+    if (c->slept)
+       ClientWakeup(client);
+    for (i = 0; i < c->num_fpes; i++)
+       FreeFPE(c->fpe_list[i]);
+    xfree(c->fpe_list);
+    if (c->savedName) xfree(c->savedName);
+    FreeFontNames(names);
+    xfree(c);
+    if (resolved) xfree(resolved);
+    return TRUE;
+}
+
+int
+ListFonts(client, pattern, length, max_names)
+    ClientPtr   client;
+    unsigned char *pattern;
+    unsigned int length;
+    unsigned int max_names;
+{
+    int         i;
+    LFclosurePtr c;
+
+    if (!(c = (LFclosurePtr) xalloc(sizeof *c)))
+       return BadAlloc;
+    c->fpe_list = (FontPathElementPtr *)
+       xalloc(sizeof(FontPathElementPtr) * num_fpes);
+    if (!c->fpe_list) {
+       xfree(c);
+       return BadAlloc;
+    }
+    c->names = MakeFontNamesRecord(max_names < 100 ? max_names : 100);
+    if (!c->names)
+    {
+       xfree(c->fpe_list);
+       xfree(c);
+       return BadAlloc;
+    }
+    memmove( c->current.pattern, pattern, length);
+    for (i = 0; i < num_fpes; i++) {
+       c->fpe_list[i] = font_path_elements[i];
+       UseFPE(c->fpe_list[i]);
+    }
+    c->client = client;
+    c->num_fpes = num_fpes;
+    c->current.patlen = length;
+    c->current.current_fpe = 0;
+    c->current.max_names = max_names;
+    c->current.list_started = FALSE;
+    c->current.private = 0;
+    c->haveSaved = FALSE;
+    c->slept = FALSE;
+    c->savedName = 0;
+    doListFontsAndAliases(client, c);
+    return Success;
+}
+
+int
+doListFontsWithInfo(client, c)
+    ClientPtr   client;
+    LFWIclosurePtr c;
+{
+    FontPathElementPtr fpe;
+    int         err = Successful;
+    char       *name;
+    int         namelen;
+    int         numFonts;
+    FontInfoRec fontInfo,
+               *pFontInfo;
+    xListFontsWithInfoReply *reply;
+    int         length;
+    xFontProp  *pFP;
+    int         i;
+    int                aliascount;
+    xListFontsWithInfoReply finalReply;
+
+    if (client->clientGone)
+    {
+       if (c->current.current_fpe < c->num_fpes)
+       {
+           fpe = c->fpe_list[c->current.current_fpe];
+           (*fpe_functions[fpe->type].client_died) ((pointer) client, fpe);
+       }
+       err = Successful;
+       goto bail;
+    }
+    client->pSwapReplyFunc = ReplySwapVector[X_ListFontsWithInfo];
+    if (!c->current.patlen)
+       goto finish;
+    while (c->current.current_fpe < c->num_fpes)
+    {
+       fpe = c->fpe_list[c->current.current_fpe];
+       err = Successful;
+       if (!c->current.list_started)
+       {
+           err = (*fpe_functions[fpe->type].start_list_fonts_with_info)
+               (client, fpe, c->current.pattern, c->current.patlen,
+                c->current.max_names, &c->current.private);
+           if (err == Suspended)
+           {
+               if (!c->slept)
+               {
+                   ClientSleep(client, (ClientSleepProcPtr)doListFontsWithInfo, c);
+                   c->slept = TRUE;
+               }
+               return TRUE;
+           }
+           if (err == Successful)
+               c->current.list_started = TRUE;
+       }
+       if (err == Successful)
+       {
+           name = 0;
+           pFontInfo = &fontInfo;
+           err = (*fpe_functions[fpe->type].list_next_font_with_info)
+               (client, fpe, &name, &namelen, &pFontInfo,
+                &numFonts, c->current.private);
+           if (err == Suspended)
+           {
+               if (!c->slept)
+               {
+                   ClientSleep(client,
+                            (ClientSleepProcPtr)doListFontsWithInfo,
+                            c);
+                   c->slept = TRUE;
+               }
+               return TRUE;
+           }
+       }
+       /*
+        * When we get an alias back, save our state and reset back to the
+        * start of the FPE looking for the specified name.  As soon as a real
+        * font is found for the alias, pop back to the old state
+        */
+       if (err == FontNameAlias)
+       {
+           /*
+            * when an alias recurses, we need to give
+            * the last FPE a chance to clean up; so we call
+            * it again, and assume that the error returned
+            * is BadFontName, indicating the alias resolution
+            * is complete.
+            */
+           if (c->haveSaved)
+           {
+               char    *tmpname;
+               int     tmpnamelen;
+               FontInfoPtr tmpFontInfo;
+
+               tmpname = 0;
+               tmpFontInfo = &fontInfo;
+               (void) (*fpe_functions[fpe->type].list_next_font_with_info)
+                   (client, fpe, &tmpname, &tmpnamelen, &tmpFontInfo,
+                    &numFonts, c->current.private);
+               if (--aliascount <= 0)
+               {
+                   err = BadFontName;
+                   goto ContBadFontName;
+               }
+           }
+           else
+           {
+               c->saved = c->current;
+               c->haveSaved = TRUE;
+               c->savedNumFonts = numFonts;
+               c->savedName = (char *) pFontInfo;
+               aliascount = 20;
+           }
+           memmove(c->current.pattern, name, namelen);
+           c->current.patlen = namelen;
+           c->current.max_names = 1;
+           c->current.current_fpe = 0;
+           c->current.private = 0;
+           c->current.list_started = FALSE;
+       }
+       /*
+        * At the end of this FPE, step to the next.  If we've finished
+        * processing an alias, pop state back.  If we've sent enough font
+        * names, quit.  Always wait for BadFontName to let the FPE
+        * have a chance to clean up.
+        */
+       else if (err == BadFontName)
+       {
+         ContBadFontName: ;
+           c->current.list_started = FALSE;
+           c->current.current_fpe++;
+           err = Successful;
+           if (c->haveSaved)
+           {
+               if (c->current.max_names == 0 ||
+                       c->current.current_fpe == c->num_fpes)
+               {
+                   c->haveSaved = FALSE;
+                   c->saved.max_names -= (1 - c->current.max_names);
+                   c->current = c->saved;
+               }
+           }
+           else if (c->current.max_names == 0)
+               break;
+       }
+       else if (err == Successful)
+       {
+           length = sizeof(*reply) + pFontInfo->nprops * sizeof(xFontProp);
+           reply = c->reply;
+           if (c->length < length)
+           {
+               reply = (xListFontsWithInfoReply *) xrealloc(c->reply, length);
+               if (!reply)
+               {
+                   err = AllocError;
+                   break;
+               }
+               c->reply = reply;
+               c->length = length;
+           }
+           if (c->haveSaved)
+           {
+               numFonts = c->savedNumFonts;
+               name = c->savedName;
+               namelen = strlen(name);
+           }
+           reply->type = X_Reply;
+           reply->length = (sizeof *reply - sizeof(xGenericReply) +
+                            pFontInfo->nprops * sizeof(xFontProp) +
+                            namelen + 3) >> 2;
+           reply->sequenceNumber = client->sequence;
+           reply->nameLength = namelen;
+           reply->minBounds = pFontInfo->ink_minbounds;
+           reply->maxBounds = pFontInfo->ink_maxbounds;
+           reply->minCharOrByte2 = pFontInfo->firstCol;
+           reply->maxCharOrByte2 = pFontInfo->lastCol;
+           reply->defaultChar = pFontInfo->defaultCh;
+           reply->nFontProps = pFontInfo->nprops;
+           reply->drawDirection = pFontInfo->drawDirection;
+           reply->minByte1 = pFontInfo->firstRow;
+           reply->maxByte1 = pFontInfo->lastRow;
+           reply->allCharsExist = pFontInfo->allExist;
+           reply->fontAscent = pFontInfo->fontAscent;
+           reply->fontDescent = pFontInfo->fontDescent;
+           reply->nReplies = numFonts;
+           pFP = (xFontProp *) (reply + 1);
+           for (i = 0; i < pFontInfo->nprops; i++)
+           {
+               pFP->name = pFontInfo->props[i].name;
+               pFP->value = pFontInfo->props[i].value;
+               pFP++;
+           }
+           WriteSwappedDataToClient(client, length, reply);
+           (void) WriteToClient(client, namelen, name);
+           if (pFontInfo == &fontInfo)
+           {
+               xfree(fontInfo.props);
+               xfree(fontInfo.isStringProp);
+           }
+           --c->current.max_names;
+       }
+    }
+finish:
+    length = sizeof(xListFontsWithInfoReply);
+    bzero((char *) &finalReply, sizeof(xListFontsWithInfoReply));
+    finalReply.type = X_Reply;
+    finalReply.sequenceNumber = client->sequence;
+    finalReply.length = (sizeof(xListFontsWithInfoReply)
+                    - sizeof(xGenericReply)) >> 2;
+    WriteSwappedDataToClient(client, length, &finalReply);
+bail:
+    if (c->slept)
+       ClientWakeup(client);
+    for (i = 0; i < c->num_fpes; i++)
+       FreeFPE(c->fpe_list[i]);
+    xfree(c->reply);
+    xfree(c->fpe_list);
+    xfree(c);
+    return TRUE;
+}
+
+int
+StartListFontsWithInfo(client, length, pattern, max_names)
+    ClientPtr   client;
+    int         length;
+    unsigned char       *pattern;
+    int         max_names;
+{
+    int                    i;
+    LFWIclosurePtr  c;
+
+    if (!(c = (LFWIclosurePtr) xalloc(sizeof *c)))
+       goto badAlloc;
+    c->fpe_list = (FontPathElementPtr *)
+       xalloc(sizeof(FontPathElementPtr) * num_fpes);
+    if (!c->fpe_list)
+    {
+       xfree(c);
+       goto badAlloc;
+    }
+    memmove(c->current.pattern, pattern, length);
+    for (i = 0; i < num_fpes; i++)
+    {
+       c->fpe_list[i] = font_path_elements[i];
+       UseFPE(c->fpe_list[i]);
+    }
+    c->client = client;
+    c->num_fpes = num_fpes;
+    c->reply = 0;
+    c->length = 0;
+    c->current.patlen = length;
+    c->current.current_fpe = 0;
+    c->current.max_names = max_names;
+    c->current.list_started = FALSE;
+    c->current.private = 0;
+    c->savedNumFonts = 0;
+    c->haveSaved = FALSE;
+    c->slept = FALSE;
+    doListFontsWithInfo(client, c);
+    return Success;
+badAlloc:
+    return BadAlloc;
+}
+
+#define TextEltHeader 2
+#define FontShiftSize 5
+static XID clearGC[] = { CT_NONE };
+#define clearGCmask (GCClipMask)
+
+int
+doPolyText(client, c)
+    ClientPtr   client;
+    register PTclosurePtr c;
+{
+    register FontPtr pFont = c->pGC->font, oldpFont;
+    Font       fid, oldfid;
+    int err = Success, lgerr;  /* err is in X error, not font error, space */
+    enum { NEVER_SLEPT, START_SLEEP, SLEEPING } client_state;
+    FontPathElementPtr fpe;
+    GC *origGC;
+
+    if (client->clientGone)
+    {
+       fpe = c->pGC->font->fpe;
+       (*fpe_functions[fpe->type].client_died) ((pointer) client, fpe);
+
+       if (c->slept)
+       {
+           /* Client has died, but we cannot bail out right now.  We
+              need to clean up after the work we did when going to
+              sleep.  Setting the drawable pointer to 0 makes this
+              happen without any attempts to render or perform other
+              unnecessary activities.  */
+           c->pDraw = (DrawablePtr)0;
+       }
+       else
+       {
+           err = Success;
+           goto bail;
+       }
+    }
+
+    /* Make sure our drawable hasn't disappeared while we slept. */
+    if (c->slept &&
+       c->pDraw &&
+       c->pDraw != (DrawablePtr)SecurityLookupIDByClass(client, c->did,
+                                       RC_DRAWABLE, SecurityWriteAccess))
+    {
+       /* Our drawable has disappeared.  Treat like client died... ask
+          the FPE code to clean up after client and avoid further
+          rendering while we clean up after ourself.  */
+       fpe = c->pGC->font->fpe;
+       (*fpe_functions[fpe->type].client_died) ((pointer) client, fpe);
+       c->pDraw = (DrawablePtr)0;
+    }
+
+    client_state = c->slept ? SLEEPING : NEVER_SLEPT;
+
+    while (c->endReq - c->pElt > TextEltHeader)
+    {
+       if (*c->pElt == FontChange)
+        {
+           if (c->endReq - c->pElt < FontShiftSize)
+           {
+                err = BadLength;
+                goto bail;
+           }
+
+           oldpFont = pFont;
+           oldfid = fid;
+
+           fid =  ((Font)*(c->pElt+4))         /* big-endian */
+                | ((Font)*(c->pElt+3)) << 8
+                | ((Font)*(c->pElt+2)) << 16
+                | ((Font)*(c->pElt+1)) << 24;
+           pFont = (FontPtr)SecurityLookupIDByType(client, fid, RT_FONT,
+                                                   SecurityReadAccess);
+           if (!pFont)
+           {
+               client->errorValue = fid;
+               err = BadFont;
+               /* restore pFont and fid for step 4 (described below) */
+               pFont = oldpFont;
+               fid = oldfid;
+
+               /* If we're in START_SLEEP mode, the following step
+                  shortens the request...  in the unlikely event that
+                  the fid somehow becomes valid before we come through
+                  again to actually execute the polytext, which would
+                  then mess up our refcounting scheme badly.  */
+               c->err = err;
+               c->endReq = c->pElt;
+
+               goto bail;
+           }
+
+           /* Step 3 (described below) on our new font */
+           if (client_state == START_SLEEP)
+               pFont->refcnt++;
+           else
+           {
+               if (pFont != c->pGC->font && c->pDraw)
+               {
+                   ChangeGC( c->pGC, GCFont, &fid);
+                   ValidateGC(c->pDraw, c->pGC);
+                   if (c->reqType == X_PolyText8)
+                       c->polyText = (PolyTextPtr) c->pGC->ops->PolyText8;
+                   else
+                       c->polyText = (PolyTextPtr) c->pGC->ops->PolyText16;
+               }
+
+               /* Undo the refcnt++ we performed when going to sleep */
+               if (client_state == SLEEPING)
+                   (void)CloseFont(c->pGC->font, (Font)0);
+           }
+           c->pElt += FontShiftSize;
+       }
+       else    /* print a string */
+       {
+           unsigned char *pNextElt;
+           pNextElt = c->pElt + TextEltHeader + (*c->pElt)*c->itemSize;
+           if ( pNextElt > c->endReq)
+           {
+               err = BadLength;
+               goto bail;
+           }
+           if (client_state == START_SLEEP)
+           {
+               c->pElt = pNextElt;
+               continue;
+           }
+           if (c->pDraw)
+           {
+               lgerr = LoadGlyphs(client, c->pGC->font, *c->pElt, c->itemSize,
+                                  c->pElt + TextEltHeader);
+           }
+           else lgerr = Successful;
+
+           if (lgerr == Suspended)
+           {
+               if (!c->slept) {
+                   int len;
+                   GC *pGC;
+                   PTclosurePtr new_closure;
+
+    /*  We're putting the client to sleep.  We need to do a few things
+       to ensure successful and atomic-appearing execution of the
+       remainder of the request.  First, copy the remainder of the
+       request into a safe malloc'd area.  Second, create a scratch GC
+       to use for the remainder of the request.  Third, mark all fonts
+       referenced in the remainder of the request to prevent their
+       deallocation.  Fourth, make the original GC look like the
+       request has completed...  set its font to the final font value
+       from this request.  These GC manipulations are for the unlikely
+       (but possible) event that some other client is using the GC.
+       Steps 3 and 4 are performed by running this procedure through
+       the remainder of the request in a special no-render mode
+       indicated by client_state = START_SLEEP.  */
+
+                   /* Step 1 */
+                   /* Allocate a malloc'd closure structure to replace
+                      the local one we were passed */
+                   new_closure = (PTclosurePtr) xalloc(sizeof(PTclosureRec));
+                   if (!new_closure)
+                   {
+                       err = BadAlloc;
+                       goto bail;
+                   }
+                   *new_closure = *c;
+                   c = new_closure;
+
+                   len = c->endReq - c->pElt;
+                   c->data = (unsigned char *)xalloc(len);
+                   if (!c->data)
+                   {
+                       xfree(c);
+                       err = BadAlloc;
+                       goto bail;
+                   }
+                   memmove(c->data, c->pElt, len);
+                   c->pElt = c->data;
+                   c->endReq = c->pElt + len;
+
+                   /* Step 2 */
+
+                   pGC = GetScratchGC(c->pGC->depth, c->pGC->pScreen);
+                   if (!pGC)
+                   {
+                       xfree(c->data);
+                       xfree(c);
+                       err = BadAlloc;
+                       goto bail;
+                   }
+                   if ((err = CopyGC(c->pGC, pGC, GCFunction |
+                                     GCPlaneMask | GCForeground |
+                                     GCBackground | GCFillStyle |
+                                     GCTile | GCStipple |
+                                     GCTileStipXOrigin |
+                                     GCTileStipYOrigin | GCFont |
+                                     GCSubwindowMode | GCClipXOrigin |
+                                     GCClipYOrigin | GCClipMask)) !=
+                                     Success)
+                   {
+                       FreeScratchGC(pGC);
+                       xfree(c->data);
+                       xfree(c);
+                       err = BadAlloc;
+                       goto bail;
+                   }
+                   origGC = c->pGC;
+                   c->pGC = pGC;
+                   ValidateGC(c->pDraw, c->pGC);
+                   
+                   c->slept = TRUE;
+                   ClientSleep(client,
+                            (ClientSleepProcPtr)doPolyText,
+                            (pointer) c);
+
+                   /* Set up to perform steps 3 and 4 */
+                   client_state = START_SLEEP;
+                   continue;   /* on to steps 3 and 4 */
+               }
+               return TRUE;
+           }
+           else if (lgerr != Successful)
+           {
+               err = FontToXError(lgerr);
+               goto bail;
+           }
+           if (c->pDraw)
+           {
+               c->xorg += *((INT8 *)(c->pElt + 1));    /* must be signed */
+               c->xorg = (* c->polyText)(c->pDraw, c->pGC, c->xorg, c->yorg,
+                   *c->pElt, c->pElt + TextEltHeader);
+           }
+           c->pElt = pNextElt;
+       }
+    }
+
+bail:
+
+    if (client_state == START_SLEEP)
+    {
+       /* Step 4 */
+       if (pFont != origGC->font)
+       {
+           ChangeGC(origGC, GCFont, &fid);
+           ValidateGC(c->pDraw, origGC);
+       }
+
+       /* restore pElt pointer for execution of remainder of the request */
+       c->pElt = c->data;
+       return TRUE;
+    }
+
+    if (c->err != Success) err = c->err;
+    if (err != Success && c->client != serverClient) {
+       SendErrorToClient(c->client, c->reqType, 0, 0, err);
+    }
+    if (c->slept)
+    {
+       ClientWakeup(c->client);
+       ChangeGC(c->pGC, clearGCmask, clearGC);
+
+       /* Unreference the font from the scratch GC */
+       CloseFont(c->pGC->font, (Font)0);
+       c->pGC->font = NullFont;
+
+       FreeScratchGC(c->pGC);
+       xfree(c->data);
+       xfree(c);
+    }
+    return TRUE;
+}
+
+int
+PolyText(client, pDraw, pGC, pElt, endReq, xorg, yorg, reqType, did)
+    ClientPtr client;
+    DrawablePtr pDraw;
+    GC *pGC;
+    unsigned char *pElt;
+    unsigned char *endReq;
+    int xorg;
+    int yorg;
+    int reqType;
+    XID did;
+{
+    PTclosureRec local_closure;
+
+    local_closure.pElt = pElt;
+    local_closure.endReq = endReq;
+    local_closure.client = client;
+    local_closure.pDraw = pDraw;
+    local_closure.xorg = xorg;
+    local_closure.yorg = yorg;
+    if ((local_closure.reqType = reqType) == X_PolyText8)
+    {
+       local_closure.polyText = (PolyTextPtr) pGC->ops->PolyText8;
+       local_closure.itemSize = 1;
+    }
+    else
+    {
+       local_closure.polyText =  (PolyTextPtr) pGC->ops->PolyText16;
+       local_closure.itemSize = 2;
+    }
+    local_closure.pGC = pGC;
+    local_closure.did = did;
+    local_closure.err = Success;
+    local_closure.slept = FALSE;
+
+    (void) doPolyText(client, &local_closure);
+    return Success;
+}
+
+
+#undef TextEltHeader
+#undef FontShiftSize
+
+int
+doImageText(client, c)
+    ClientPtr   client;
+    register ITclosurePtr c;
+{
+    int err = Success, lgerr;  /* err is in X error, not font error, space */
+    FontPathElementPtr fpe;
+
+    if (client->clientGone)
+    {
+       fpe = c->pGC->font->fpe;
+       (*fpe_functions[fpe->type].client_died) ((pointer) client, fpe);
+       err = Success;
+       goto bail;
+    }
+
+    /* Make sure our drawable hasn't disappeared while we slept. */
+    if (c->slept &&
+       c->pDraw &&
+       c->pDraw != (DrawablePtr)SecurityLookupIDByClass(client, c->did,
+                                       RC_DRAWABLE, SecurityWriteAccess))
+    {
+       /* Our drawable has disappeared.  Treat like client died... ask
+          the FPE code to clean up after client. */
+       fpe = c->pGC->font->fpe;
+       (*fpe_functions[fpe->type].client_died) ((pointer) client, fpe);
+       err = Success;
+       goto bail;
+    }
+
+    lgerr = LoadGlyphs(client, c->pGC->font, c->nChars, c->itemSize, c->data);
+    if (lgerr == Suspended)
+    {
+        if (!c->slept) {
+           GC *pGC;
+           unsigned char *data;
+           ITclosurePtr new_closure;
+
+           /* We're putting the client to sleep.  We need to
+              save some state.  Similar problem to that handled
+              in doPolyText, but much simpler because the
+              request structure is much simpler. */
+
+           new_closure = (ITclosurePtr) xalloc(sizeof(ITclosureRec));
+           if (!new_closure)
+           {
+               err = BadAlloc;
+               goto bail;
+           }
+           *new_closure = *c;
+           c = new_closure;
+
+           data = (unsigned char *)xalloc(c->nChars * c->itemSize);
+           if (!data)
+           {
+               xfree(c);
+               err = BadAlloc;
+               goto bail;
+           }
+           memmove(data, c->data, c->nChars * c->itemSize);
+           c->data = data;
+
+           pGC = GetScratchGC(c->pGC->depth, c->pGC->pScreen);
+           if (!pGC)
+           {
+               xfree(c->data);
+               xfree(c);
+               err = BadAlloc;
+               goto bail;
+           }
+           if ((err = CopyGC(c->pGC, pGC, GCFunction | GCPlaneMask |
+                             GCForeground | GCBackground | GCFillStyle |
+                             GCTile | GCStipple | GCTileStipXOrigin |
+                             GCTileStipYOrigin | GCFont |
+                             GCSubwindowMode | GCClipXOrigin |
+                             GCClipYOrigin | GCClipMask)) != Success)
+           {
+               FreeScratchGC(pGC);
+               xfree(c->data);
+               xfree(c);
+               err = BadAlloc;
+               goto bail;
+           }
+           c->pGC = pGC;
+           ValidateGC(c->pDraw, c->pGC);
+
+           c->slept = TRUE;
+            ClientSleep(client, (ClientSleepProcPtr)doImageText, (pointer) c);
+        }
+        return TRUE;
+    }
+    else if (lgerr != Successful)
+    {
+        err = FontToXError(lgerr);
+        goto bail;
+    }
+    if (c->pDraw)
+    {
+       (* c->imageText)(c->pDraw, c->pGC, c->xorg, c->yorg,
+           c->nChars, c->data);
+    }
+
+bail:
+
+    if (err != Success && c->client != serverClient) {
+       SendErrorToClient(c->client, c->reqType, 0, 0, err);
+    }
+    if (c->slept)
+    {
+       ClientWakeup(c->client);
+       ChangeGC(c->pGC, clearGCmask, clearGC);
+
+       /* Unreference the font from the scratch GC */
+       CloseFont(c->pGC->font, (Font)0);
+       c->pGC->font = NullFont;
+
+       FreeScratchGC(c->pGC);
+       xfree(c->data);
+       xfree(c);
+    }
+    return TRUE;
+}
+
+int
+ImageText(client, pDraw, pGC, nChars, data, xorg, yorg, reqType, did)
+    ClientPtr client;
+    DrawablePtr pDraw;
+    GC *pGC;
+    int nChars;
+    unsigned char *data;
+    int xorg;
+    int yorg;
+    int reqType;
+    XID did;
+{
+    ITclosureRec local_closure;
+
+    local_closure.client = client;
+    local_closure.pDraw = pDraw;
+    local_closure.pGC = pGC;
+    local_closure.nChars = nChars;
+    local_closure.data = data;
+    local_closure.xorg = xorg;
+    local_closure.yorg = yorg;
+    if ((local_closure.reqType = reqType) == X_ImageText8)
+    {
+       local_closure.imageText = (ImageTextPtr) pGC->ops->ImageText8;
+       local_closure.itemSize = 1;
+    }
+    else
+    {
+       local_closure.imageText = (ImageTextPtr) pGC->ops->ImageText16;
+       local_closure.itemSize = 2;
+    }
+    local_closure.did = did;
+    local_closure.slept = FALSE;
+
+    (void) doImageText(client, &local_closure);
+    return Success;
+}
+
+
+/* does the necessary magic to figure out the fpe type */
+static int
+#if NeedFunctionPrototypes
+DetermineFPEType(char *pathname)
+#else
+DetermineFPEType(pathname)
+    char       *pathname;
+#endif
+{
+    int         i;
+
+    for (i = 0; i < num_fpe_types; i++) {
+       if ((*fpe_functions[i].name_check) (pathname))
+           return i;
+    }
+    return -1;
+}
+
+
+static void
+#if NeedFunctionPrototypes
+FreeFontPath(FontPathElementPtr *list, int n, Bool force)
+#else
+FreeFontPath(list, n, force)
+    FontPathElementPtr *list;
+    Bool               force;
+    int         n;
+#endif
+{
+    int         i;
+
+    for (i = 0; i < n; i++) {
+       if (force) {
+           /* Sanity check that all refcounts will be 0 by the time
+              we get to the end of the list. */
+           int found = 1;      /* the first reference is us */
+           int j;
+           for (j = i+1; j < n; j++) {
+               if (list[j] == list[i])
+                   found++;
+           }
+           if (list[i]->refcount != found) {
+               ErrorF("FreeFontPath: FPE \"%.*s\" refcount is %d, should be %d; fixing.\n",
+                      list[i]->name_length, list[i]->name,
+                      list[i]->refcount, found);
+               list[i]->refcount = found; /* ensure it will get freed */
+           }
+       }
+       FreeFPE(list[i]);
+    }
+    xfree((char *) list);
+}
+
+static FontPathElementPtr
+#if NeedFunctionPrototypes
+find_existing_fpe(FontPathElementPtr *list, int num, unsigned char *name, int len)
+#else
+find_existing_fpe(list, num, name, len)
+    FontPathElementPtr *list;
+    int         num;
+    unsigned char *name;
+    int         len;
+#endif
+{
+    FontPathElementPtr fpe;
+    int         i;
+
+    for (i = 0; i < num; i++) {
+       fpe = list[i];
+       if (fpe->name_length == len && memcmp(name, fpe->name, len) == 0)
+           return fpe;
+    }
+    return (FontPathElementPtr) 0;
+}
+
+
+static int
+#if NeedFunctionPrototypes
+SetFontPathElements(int npaths, unsigned char *paths, int *bad)
+#else
+SetFontPathElements(npaths, paths, bad)
+    int         npaths;
+    unsigned char *paths;
+    int        *bad;
+#endif
+{
+    int         i,
+                err;
+    int         valid_paths = 0;
+    unsigned int len;
+    unsigned char *cp = paths;
+    FontPathElementPtr fpe,
+               *fplist;
+
+    fplist = (FontPathElementPtr *)
+       xalloc(sizeof(FontPathElementPtr) * npaths);
+    if (!fplist) {
+       *bad = 0;
+       return BadAlloc;
+    }
+    for (i = 0; i < num_fpe_types; i++) {
+       if (fpe_functions[i].set_path_hook)
+           (*fpe_functions[i].set_path_hook) ();
+    }
+    for (i = 0; i < npaths; i++) {
+       len = (unsigned int) (*cp++);
+
+       if (len) {
+           /* if it's already in our active list, just reset it */
+           /*
+            * note that this can miss FPE's in limbo -- may be worth catching
+            * them, though it'd muck up refcounting
+            */
+           fpe = find_existing_fpe(font_path_elements, num_fpes, cp, len);
+           if (fpe) {
+               err = (*fpe_functions[fpe->type].reset_fpe) (fpe);
+               if (err == Successful) {
+                   UseFPE(fpe);/* since it'll be decref'd later when freed
+                                * from the old list */
+                   fplist[valid_paths++] = fpe;
+                   cp += len;
+                   continue;
+               }
+               /* if error or can't do it, act like it's a new one */
+           }
+           fpe = (FontPathElementPtr) xalloc(sizeof(FontPathElementRec));
+           if (!fpe) {
+               err = BadAlloc;
+               goto bail;
+           }
+           fpe->name = (char *) xalloc(len + 1);
+           if (!fpe->name) {
+               xfree(fpe);
+               err = BadAlloc;
+               goto bail;
+           }
+           fpe->refcount = 1;
+
+           strncpy(fpe->name, (char *) cp, (int) len);
+           cp += len;
+           fpe->name[len] = '\0';
+           fpe->name_length = len;
+           fpe->type = DetermineFPEType(fpe->name);
+           if (fpe->type == -1) {
+               xfree(fpe->name);
+               xfree(fpe);
+               err = BadValue;
+               goto bail;
+           }
+           err = (*fpe_functions[fpe->type].init_fpe) (fpe);
+           if (err != Successful) {
+               xfree(fpe->name);
+               xfree(fpe);
+               err = Successful;
+           }
+           else {
+             fplist[valid_paths++] = fpe;
+           }
+       } else {
+           err = BadValue;
+           goto bail;
+       }
+    }
+
+    FreeFontPath(font_path_elements, num_fpes, FALSE);
+    font_path_elements = fplist;
+    if (patternCache)
+       EmptyFontPatternCache(patternCache);
+    num_fpes = valid_paths;
+
+    return Success;
+bail:
+    *bad = i;
+    while (--i >= 0)
+       FreeFPE(fplist[i]);
+    xfree(fplist);
+    return err;
+}
+
+/* XXX -- do we need to pass error down to each renderer? */
+int
+SetFontPath(client, npaths, paths, error)
+    ClientPtr   client;
+    int         npaths;
+    unsigned char *paths;
+    int        *error;
+{
+    int   err = Success;
+
+    if (npaths == 0) {
+       if (SetDefaultFontPath(defaultFontPath) != Success)
+           return BadName;
+    } else {
+       err = SetFontPathElements(npaths, paths, error);
+    }
+    return err;
+}
+
+/*** TJR - dirty hack - this variable is used in lib/font/fontfile/dirfile.c */
+int settingDefaultFontPath = 0;
+
+int
+SetDefaultFontPath(path)
+    char       *path;
+{
+    unsigned char *cp,
+               *pp,
+               *nump,
+               *newpath;
+    int         num = 1,
+                len,
+                err,
+                size = 0,
+                bad;
+
+    /* get enough for string, plus values -- use up commas */
+    len = strlen(path) + 1;
+    nump = cp = newpath = (unsigned char *) ALLOCATE_LOCAL(len);
+    if (!newpath)
+       return BadAlloc;
+    pp = (unsigned char *) path;
+    cp++;
+    while (*pp) {
+       if (*pp == ',') {
+           *nump = (unsigned char) size;
+           nump = cp++;
+           pp++;
+           num++;
+           size = 0;
+       } else {
+           *cp++ = *pp++;
+           size++;
+       }
+    }
+    *nump = (unsigned char) size;
+
+    settingDefaultFontPath = 1;
+
+    err = SetFontPathElements(num, newpath, &bad);
+
+    settingDefaultFontPath = 0;
+
+    DEALLOCATE_LOCAL(newpath);
+
+    return err;
+}
+
+unsigned char *
+GetFontPath(count, length)
+    int                        *count;
+    int                        *length;
+{
+    int                        i;
+    unsigned char       *c;
+    int                        len;
+    FontPathElementPtr fpe;
+
+    len = 0;
+    for (i = 0; i < num_fpes; i++) {
+       fpe = font_path_elements[i];
+       len += fpe->name_length + 1;
+    }
+    font_path_string = (unsigned char *) xrealloc(font_path_string, len);
+    if (!font_path_string)
+       return NULL;
+
+    c = font_path_string;
+    *length = 0;
+    for (i = 0; i < num_fpes; i++) {
+       fpe = font_path_elements[i];
+       *c = fpe->name_length;
+       *length += *c++;
+       memmove(c, fpe->name, fpe->name_length);
+       c += fpe->name_length;
+    }
+    *count = num_fpes;
+    return font_path_string;
+}
+
+int
+LoadGlyphs(client, pfont, nchars, item_size, data)
+    ClientPtr   client;
+    FontPtr     pfont;
+    unsigned    nchars;
+    int         item_size;
+    unsigned char *data;
+{
+    if (fpe_functions[pfont->fpe->type].load_glyphs)
+       return (*fpe_functions[pfont->fpe->type].load_glyphs)
+           (client, pfont, 0, nchars, item_size, data);
+    else
+       return Successful;
+}
+
+void
+DeleteClientFontStuff(client)
+    ClientPtr  client;
+{
+    int                        i;
+    FontPathElementPtr fpe;
+
+    for (i = 0; i < num_fpes; i++)
+    {
+       fpe = font_path_elements[i];
+       if (fpe_functions[fpe->type].client_died)
+           (*fpe_functions[fpe->type].client_died) ((pointer) client, fpe);
+    }
+}
+
+void
+InitFonts ()
+{
+    patternCache = MakeFontPatternCache();
+
+    if (screenInfo.numScreens > screenInfo.numVideoScreens) {
+       PrinterFontRegisterFpeFunctions();
+       FontFileCheckRegisterFpeFunctions();
+       check_fs_register_fpe_functions();
+    } else {
+       FontFileRegisterFpeFunctions();
+       fs_register_fpe_functions();
+    }
+}
+
+int
+GetDefaultPointSize ()
+{
+    return 120;
+}
+
+
+FontResolutionPtr
+GetClientResolutions (num)
+    int        *num;
+{
+    if (requestingClient && requestingClient->fontResFunc != NULL &&
+       !requestingClient->clientGone)
+    {
+       return (*requestingClient->fontResFunc)(requestingClient, num);
+    }
+    else {
+       static struct _FontResolution res;
+       ScreenPtr   pScreen;
+
+       pScreen = screenInfo.screens[0];
+       res.x_resolution = (pScreen->width * 25.4) / pScreen->mmWidth;
+       /*
+        * XXX - we'll want this as long as bitmap instances are prevalent 
+        so that we can match them from scalable fonts
+        */
+       if (res.x_resolution < 88)
+           res.x_resolution = 75;
+       else
+           res.x_resolution = 100;
+       res.y_resolution = (pScreen->height * 25.4) / pScreen->mmHeight;
+       if (res.y_resolution < 88)
+           res.y_resolution = 75;
+       else
+           res.y_resolution = 100;
+       res.point_size = 120;
+       *num = 1;
+       return &res;
+    }
+}
+
+/*
+ * returns the type index of the new fpe
+ *
+ * should be called (only once!) by each type of fpe when initialized
+ */
+
+int
+#if NeedFunctionPrototypes
+RegisterFPEFunctions(
+    int         (*name_func) (
+                  char* /* name */
+                  ),
+    int         (*init_func) (
+                  FontPathElementPtr /* fpe */
+                  ),
+    int         (*free_func) (
+                  FontPathElementPtr /* fpe */
+                  ),
+    int         (*reset_func) (
+                  FontPathElementPtr /* fpe */
+                  ),
+    int         (*open_func) (
+                  pointer /* client */,
+                  FontPathElementPtr /* fpe */,
+                  int /* flags */,
+                  char* /* name */,
+                  int /* namelen */,
+                  fsBitmapFormat /* format */,
+                  fsBitmapFormatMask /* fmask */,
+                  unsigned long /* id (type XID or FSID) */,
+                  FontPtr* /* pFont */,
+                  char** /* aliasName */,
+                  FontPtr /* non_cachable_font */
+                  ),
+    int         (*close_func) (
+                  FontPathElementPtr /* fpe */,
+                  FontPtr /* pFont */
+                  ),
+    int         (*list_func) (
+                  pointer /* client */,
+                  FontPathElementPtr /* fpe */,
+                  char* /* pat */,
+                  int /* len */,
+                  int /* max */,
+                  FontNamesPtr /* names */
+                  ),
+    int         (*start_lfwi_func) (
+                  pointer /* client */,
+                  FontPathElementPtr /* fpe */,
+                  char* /* pat */,
+                  int /* patlen */,
+                  int /* maxnames */,
+                  pointer* /* privatep */
+                  ),
+    int         (*next_lfwi_func) (
+                  pointer /* client */,
+                  FontPathElementPtr /* fpe */,
+                  char** /* name */,
+                  int* /* namelen */,
+                  FontInfoPtr* /* info */,
+                  int* /* numFonts */,
+                  pointer /* private */
+                  ),
+    int         (*wakeup_func) (
+                  FontPathElementPtr /* fpe */,
+                  unsigned long* /* LastSelectMask */
+                  ),
+    int         (*client_died) (
+                  pointer /* client */,
+                  FontPathElementPtr /* fpe */
+                  ),
+    int         (*load_glyphs) (
+                  pointer /* client */,
+                  FontPtr /* pfont */,
+                  Bool /* range_flag */,
+                  unsigned int /* nchars */,
+                  int /* item_size */,
+                  unsigned char* /* data */
+                  ),
+    int         (*start_list_alias_func) (
+                  pointer /* client */,
+                  FontPathElementPtr /* fpe */,
+                  char* /* pat */,
+                  int /* len */,
+                  int /* max */,
+                  pointer* /* privatep */
+                  ),
+    int         (*next_list_alias_func) (
+                  pointer /* client */,
+                  FontPathElementPtr /* fpe */,
+                  char** /* namep */,
+                  int* /* namelenp */,
+                  char** /* resolvedp */,
+                  int* /* resolvedlenp */,
+                  pointer /* private */
+                  ),
+    void        (*set_path_func) (
+                  void
+                  )
+)
+#else
+RegisterFPEFunctions(name_func, init_func, free_func, reset_func,
+          open_func, close_func, list_func, start_lfwi_func, next_lfwi_func,
+                    wakeup_func, client_died, load_glyphs,
+                    start_list_alias_func, next_list_alias_func,
+                    set_path_func)
+    Bool        (*name_func) ();
+    int         (*init_func) ();
+    int         (*free_func) ();
+    int         (*reset_func) ();
+    int         (*open_func) ();
+    int         (*close_func) ();
+    int         (*list_func) ();
+    int         (*start_lfwi_func) ();
+    int         (*next_lfwi_func) ();
+    int         (*wakeup_func) ();
+    int                (*client_died) ();
+    int                (*load_glyphs) ();
+    int                (*start_list_alias_func) ();
+    int                (*next_list_alias_func) ();
+    void       (*set_path_func) ();
+#endif
+{
+    FPEFunctions *new;
+
+    /* grow the list */
+    new = (FPEFunctions *) xrealloc(fpe_functions,
+                                (num_fpe_types + 1) * sizeof(FPEFunctions));
+    if (!new)
+       return -1;
+    fpe_functions = new;
+
+    fpe_functions[num_fpe_types].name_check = name_func;
+    fpe_functions[num_fpe_types].open_font = open_func;
+    fpe_functions[num_fpe_types].close_font = close_func;
+    fpe_functions[num_fpe_types].wakeup_fpe = wakeup_func;
+    fpe_functions[num_fpe_types].list_fonts = list_func;
+    fpe_functions[num_fpe_types].start_list_fonts_with_info =
+       start_lfwi_func;
+    fpe_functions[num_fpe_types].list_next_font_with_info =
+       next_lfwi_func;
+    fpe_functions[num_fpe_types].init_fpe = init_func;
+    fpe_functions[num_fpe_types].free_fpe = free_func;
+    fpe_functions[num_fpe_types].reset_fpe = reset_func;
+    fpe_functions[num_fpe_types].client_died = client_died;
+    fpe_functions[num_fpe_types].load_glyphs = load_glyphs;
+    fpe_functions[num_fpe_types].start_list_fonts_and_aliases =
+       start_list_alias_func;
+    fpe_functions[num_fpe_types].list_next_font_or_alias =
+       next_list_alias_func;
+    fpe_functions[num_fpe_types].set_path_hook = set_path_func;
+
+    return num_fpe_types++;
+}
+
+void
+FreeFonts()
+{
+    if (patternCache) {
+       FreeFontPatternCache(patternCache);
+       patternCache = 0;
+    }
+    FreeFontPath(font_path_elements, num_fpes, TRUE);
+    font_path_elements = 0;
+    num_fpes = 0;
+    xfree(fpe_functions);
+    num_fpe_types = 0;
+    fpe_functions = (FPEFunctions *) 0;
+}
+
+/* convenience functions for FS interface */
+
+FontPtr
+find_old_font(id)
+    XID         id;
+{
+    return (FontPtr) SecurityLookupIDByType(NullClient, id, RT_NONE,
+                                           SecurityUnknownAccess);
+}
+
+Font
+GetNewFontClientID()
+{
+    return FakeClientID(0);
+}
+
+int
+StoreFontClientFont(pfont, id)
+    FontPtr     pfont;
+    Font        id;
+{
+    return AddResource(id, RT_NONE, (pointer) pfont);
+}
+
+void
+DeleteFontClientID(id)
+    Font        id;
+{
+    FreeResource(id, RT_NONE);
+}
+
+int
+client_auth_generation(client)
+    ClientPtr client;
+{
+    return 0;
+}
+
+static int  fs_handlers_installed = 0;
+static unsigned int last_server_gen;
+
+int
+init_fs_handlers(fpe, block_handler)
+    FontPathElementPtr fpe;
+    BlockHandlerProcPtr block_handler;
+{
+    /* if server has reset, make sure the b&w handlers are reinstalled */
+    if (last_server_gen < serverGeneration) {
+       last_server_gen = serverGeneration;
+       fs_handlers_installed = 0;
+    }
+    if (fs_handlers_installed == 0) {
+
+#ifdef DEBUG
+       fprintf(stderr, "adding FS b & w handlers\n");
+#endif
+
+       if (!RegisterBlockAndWakeupHandlers(block_handler,
+                                           FontWakeup, (pointer) 0))
+           return AllocError;
+       fs_handlers_installed++;
+    }
+    QueueFontWakeup(fpe);
+    return Successful;
+}
+
+void
+remove_fs_handlers(fpe, block_handler, all)
+    FontPathElementPtr fpe;
+    BlockHandlerProcPtr block_handler;
+    Bool        all;
+{
+    if (all) {
+       /* remove the handlers if no one else is using them */
+       if (--fs_handlers_installed == 0) {
+
+#ifdef DEBUG
+           fprintf(stderr, "removing FS b & w handlers\n");
+#endif
+
+           RemoveBlockAndWakeupHandlers(block_handler, FontWakeup,
+                                        (pointer) 0);
+       }
+    }
+    RemoveFontWakeup(fpe);
+}
+
+#ifdef DEBUG
+#define GLWIDTHBYTESPADDED(bits,nbytes) \
+       ((nbytes) == 1 ? (((bits)+7)>>3)        /* pad to 1 byte */ \
+       :(nbytes) == 2 ? ((((bits)+15)>>3)&~1)  /* pad to 2 bytes */ \
+       :(nbytes) == 4 ? ((((bits)+31)>>3)&~3)  /* pad to 4 bytes */ \
+       :(nbytes) == 8 ? ((((bits)+63)>>3)&~7)  /* pad to 8 bytes */ \
+       : 0)
+
+#define GLYPH_SIZE(ch, nbytes)          \
+       GLWIDTHBYTESPADDED((ch)->metrics.rightSideBearing - \
+                       (ch)->metrics.leftSideBearing, (nbytes))
+dump_char_ascii(cip)
+    CharInfoPtr cip;
+{
+    int         r,
+                l;
+    int         bpr;
+    int         byte;
+    static unsigned maskTab[] = {
+       (1 << 7), (1 << 6), (1 << 5), (1 << 4),
+       (1 << 3), (1 << 2), (1 << 1), (1 << 0),
+    };
+
+    bpr = GLYPH_SIZE(cip, 4);
+    for (r = 0; r < (cip->metrics.ascent + cip->metrics.descent); r++) {
+       pointer     row = (pointer) cip->bits + r * bpr;
+
+       byte = 0;
+       for (l = 0; l <= (cip->metrics.rightSideBearing -
+                         cip->metrics.leftSideBearing); l++) {
+           if (maskTab[l & 7] & row[l >> 3])
+               putchar('X');
+           else
+               putchar('.');
+       }
+       putchar('\n');
+    }
+}
+
+#endif
diff --git a/Xserver/programs/Xserver/dix/dixutils.c b/Xserver/programs/Xserver/dix/dixutils.c
new file mode 100644 (file)
index 0000000..edabfd7
--- /dev/null
@@ -0,0 +1,1011 @@
+/***********************************************************
+
+Copyright (c) 1987  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+
+Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
+
+                        All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and its 
+documentation for any purpose and without fee is hereby granted, 
+provided that the above copyright notice appear in all copies and that
+both that copyright notice and this permission notice appear in 
+supporting documentation, and that the name of Digital not be
+used in advertising or publicity pertaining to distribution of the
+software without specific, written prior permission.  
+
+DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
+ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
+DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
+ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+SOFTWARE.
+
+******************************************************************/
+
+/*
+
+(c)Copyright 1988,1991 Adobe Systems Incorporated. All rights reserved.
+
+Permission to use, copy, modify, distribute, and sublicense this software and its
+documentation for any purpose and without fee is hereby granted, provided that
+the above copyright notices appear in all copies and that both those copyright
+notices and this permission notice appear in supporting documentation and that
+the name of Adobe Systems Incorporated not be used in advertising or publicity
+pertaining to distribution of the software without specific, written prior
+permission.  No trademark license to use the Adobe trademarks is hereby
+granted.  If the Adobe trademark "Display PostScript"(tm) is used to describe
+this software, its functionality or for any other purpose, such use shall be
+limited to a statement that this software works in conjunction with the Display
+PostScript system.  Proper trademark attribution to reflect Adobe's ownership
+of the trademark shall be given whenever any such reference to the Display
+PostScript system is made.
+
+ADOBE MAKES NO REPRESENTATIONS ABOUT THE SUITABILITY OF THE SOFTWARE FOR ANY
+PURPOSE.  IT IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY.  ADOBE
+DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED
+WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-
+INFRINGEMENT OF THIRD PARTY RIGHTS.  IN NO EVENT SHALL ADOBE BE LIABLE TO YOU
+OR ANY OTHER PARTY FOR ANY SPECIAL, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY
+DAMAGES WHATSOEVER WHETHER IN AN ACTION OF CONTRACT,NEGLIGENCE, STRICT
+LIABILITY OR ANY OTHER ACTION ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+PERFORMANCE OF THIS SOFTWARE.  ADOBE WILL NOT PROVIDE ANY TRAINING OR OTHER
+SUPPORT FOR THE SOFTWARE.
+
+Adobe, PostScript, and Display PostScript are trademarks of Adobe Systems
+Incorporated which may be registered in certain jurisdictions.
+
+Author:  Adobe Systems Incorporated
+
+*/
+
+/* $TOG: dixutils.c /main/33 1997/05/22 10:02:20 kaleb $ */
+
+
+
+
+/* $XFree86: xc/programs/Xserver/dix/dixutils.c,v 3.1.2.1 1997/05/23 12:19:35 dawes Exp $ */
+
+#include "X.h"
+#include "Xmd.h"
+#include "misc.h"
+#include "windowstr.h"
+#include "dixstruct.h"
+#include "pixmapstr.h"
+#include "scrnintstr.h"
+#define  XK_LATIN1
+#include "keysymdef.h"
+#ifdef XCSECURITY
+#define _SECURITY_SERVER
+#include "extensions/security.h"
+#endif
+
+/*
+ * CompareTimeStamps returns -1, 0, or +1 depending on if the first
+ * argument is less than, equal to or greater than the second argument.
+ */
+
+int
+CompareTimeStamps(a, b)
+    TimeStamp a, b;
+{
+    if (a.months < b.months)
+       return EARLIER;
+    if (a.months > b.months)
+       return LATER;
+    if (a.milliseconds < b.milliseconds)
+       return EARLIER;
+    if (a.milliseconds > b.milliseconds)
+       return LATER;
+    return SAMETIME;
+}
+
+/*
+ * convert client times to server TimeStamps
+ */
+
+#define HALFMONTH ((unsigned long) 1<<31)
+TimeStamp
+ClientTimeToServerTime(c)
+     CARD32 c;
+{
+    TimeStamp ts;
+    if (c == CurrentTime)
+       return currentTime;
+    ts.months = currentTime.months;
+    ts.milliseconds = c;
+    if (c > currentTime.milliseconds)
+    {
+       if (((unsigned long) c - currentTime.milliseconds) > HALFMONTH)
+           ts.months -= 1;
+    }
+    else if (c < currentTime.milliseconds)
+    {
+       if (((unsigned long)currentTime.milliseconds - c) > HALFMONTH)
+           ts.months += 1;
+    }
+    return ts;
+}
+
+/*
+ * ISO Latin-1 case conversion routine
+ *
+ * this routine always null-terminates the result, so
+ * beware of too-small buffers
+ */
+
+void
+CopyISOLatin1Lowered(dest, source, length)
+    register unsigned char *dest, *source;
+    int length;
+{
+    register int i;
+
+    for (i = 0; i < length; i++, source++, dest++)
+    {
+       if ((*source >= XK_A) && (*source <= XK_Z))
+           *dest = *source + (XK_a - XK_A);
+       else if ((*source >= XK_Agrave) && (*source <= XK_Odiaeresis))
+           *dest = *source + (XK_agrave - XK_Agrave);
+       else if ((*source >= XK_Ooblique) && (*source <= XK_Thorn))
+           *dest = *source + (XK_oslash - XK_Ooblique);
+       else
+           *dest = *source;
+    }
+    *dest = '\0';
+}
+
+#ifdef XCSECURITY
+
+/* SecurityLookupWindow and SecurityLookupDrawable:
+ * Look up the window/drawable taking into account the client doing
+ * the lookup and the type of access desired.  Return the window/drawable
+ * if it exists and the client is allowed access, else return NULL.
+ * Most Proc* functions should be calling these instead of
+ * LookupWindow and LookupDrawable, which do no access checks.
+ */
+
+WindowPtr
+SecurityLookupWindow(rid, client, access_mode)
+    XID rid;
+    ClientPtr client;
+    Mask access_mode;
+{
+    WindowPtr  pWin;
+
+    client->errorValue = rid;
+    if(rid == INVALID)
+       return NULL;
+    if (client->trustLevel != XSecurityClientTrusted)
+       return (WindowPtr)SecurityLookupIDByType(client, rid, RT_WINDOW, access_mode);
+    if (client->lastDrawableID == rid)
+    {
+        if (client->lastDrawable->type == DRAWABLE_WINDOW)
+            return ((WindowPtr) client->lastDrawable);
+        return (WindowPtr) NULL;
+    }
+    pWin = (WindowPtr)SecurityLookupIDByType(client, rid, RT_WINDOW, access_mode);
+    if (pWin && pWin->drawable.type == DRAWABLE_WINDOW) {
+       client->lastDrawable = (DrawablePtr) pWin;
+       client->lastDrawableID = rid;
+       client->lastGCID = INVALID;
+       client->lastGC = (GCPtr)NULL;
+    }
+    return pWin;
+}
+
+
+pointer
+SecurityLookupDrawable(rid, client, access_mode)
+    XID rid;
+    ClientPtr client;
+    Mask access_mode;
+{
+    register DrawablePtr pDraw;
+
+    if(rid == INVALID)
+       return (pointer) NULL;
+    if (client->trustLevel != XSecurityClientTrusted)
+       return (DrawablePtr)SecurityLookupIDByClass(client, rid, RC_DRAWABLE,
+                                                   access_mode);
+    if (client->lastDrawableID == rid)
+       return ((pointer) client->lastDrawable);
+    pDraw = (DrawablePtr)SecurityLookupIDByClass(client, rid, RC_DRAWABLE,
+                                                access_mode);
+    if (pDraw && (pDraw->type != UNDRAWABLE_WINDOW))
+        return (pointer)pDraw;         
+    return (pointer)NULL;
+}
+
+/* We can't replace the LookupWindow and LookupDrawable functions with
+ * macros because of compatibility with loadable servers.
+ */
+
+WindowPtr
+LookupWindow(rid, client)
+    XID rid;
+    ClientPtr client;
+{
+    return SecurityLookupWindow(rid, client, SecurityUnknownAccess);
+}
+
+pointer
+LookupDrawable(rid, client)
+    XID rid;
+    ClientPtr client;
+{
+    return SecurityLookupDrawable(rid, client, SecurityUnknownAccess);
+}
+
+#else /* not XCSECURITY */
+
+WindowPtr
+LookupWindow(rid, client)
+    XID rid;
+    ClientPtr client;
+{
+    WindowPtr  pWin;
+
+    client->errorValue = rid;
+    if(rid == INVALID)
+       return NULL;
+    if (client->lastDrawableID == rid)
+    {
+        if (client->lastDrawable->type == DRAWABLE_WINDOW)
+            return ((WindowPtr) client->lastDrawable);
+        return (WindowPtr) NULL;
+    }
+    pWin = (WindowPtr)LookupIDByType(rid, RT_WINDOW);
+    if (pWin && pWin->drawable.type == DRAWABLE_WINDOW) {
+       client->lastDrawable = (DrawablePtr) pWin;
+       client->lastDrawableID = rid;
+       client->lastGCID = INVALID;
+       client->lastGC = (GCPtr)NULL;
+    }
+    return pWin;
+}
+
+
+pointer
+LookupDrawable(rid, client)
+    XID rid;
+    ClientPtr client;
+{
+    register DrawablePtr pDraw;
+
+    if(rid == INVALID)
+       return (pointer) NULL;
+    if (client->lastDrawableID == rid)
+       return ((pointer) client->lastDrawable);
+    pDraw = (DrawablePtr)LookupIDByClass(rid, RC_DRAWABLE);
+    if (pDraw && (pDraw->type != UNDRAWABLE_WINDOW))
+        return (pointer)pDraw;         
+    return (pointer)NULL;
+}
+
+#endif /* XCSECURITY */
+
+ClientPtr
+LookupClient(rid, client)
+    XID rid;
+    ClientPtr client;
+{
+    pointer pRes = (pointer)SecurityLookupIDByClass(client, rid, RC_ANY,
+                                                   SecurityReadAccess);
+    int clientIndex = CLIENT_ID(rid);
+
+    if (clientIndex && pRes && clients[clientIndex] && !(rid & SERVER_BIT))
+    {
+       return clients[clientIndex];
+    }
+    return (ClientPtr)NULL;
+}
+
+
+int
+AlterSaveSetForClient(client, pWin, mode)
+    ClientPtr client;
+    WindowPtr pWin;
+    unsigned mode;
+{
+    int numnow;
+    pointer *pTmp;
+    int j;
+
+    numnow = client->numSaved;
+    j = 0;
+    if (numnow)
+    {
+       pTmp = client->saveSet;
+       while ((j < numnow) && (pTmp[j] != (pointer)pWin))
+           j++;
+    }
+    if (mode == SetModeInsert)
+    {
+       if (j < numnow)         /* duplicate */
+          return(Success);
+       numnow++;
+       pTmp = (pointer *)xrealloc(client->saveSet, sizeof(pointer) * numnow);
+       if (!pTmp)
+           return(BadAlloc);
+       client->saveSet = pTmp;
+               client->numSaved = numnow;
+       client->saveSet[numnow - 1] = (pointer)pWin;
+       return(Success);
+    }
+    else if ((mode == SetModeDelete) && (j < numnow))
+    {
+       while (j < numnow-1)
+       {
+           pTmp[j] = pTmp[j+1];
+          j++;
+       }
+       numnow--;
+        if (numnow)
+       {
+           pTmp = (pointer *)xrealloc(client->saveSet,
+                                      sizeof(pointer) * numnow);
+           if (pTmp)
+               client->saveSet = pTmp;
+       }
+        else
+        {
+            xfree(client->saveSet);
+           client->saveSet = (pointer *)NULL;
+       }
+       client->numSaved = numnow;
+       return(Success);
+    }
+    return(Success);
+}
+
+void
+DeleteWindowFromAnySaveSet(pWin)
+    WindowPtr pWin;
+{
+    register int i;
+    register ClientPtr client;
+    
+    for (i = 0; i< currentMaxClients; i++)
+    {    
+       client = clients[i];
+       if (client && client->numSaved)
+           (void)AlterSaveSetForClient(client, pWin, SetModeDelete);
+    }
+}
+
+/* No-op Don't Do Anything : sometimes we need to be able to call a procedure
+ * that doesn't do anything.  For example, on screen with only static
+ * colormaps, if someone calls install colormap, it's easier to have a dummy
+ * procedure to call than to check if there's a procedure 
+ */
+void
+NoopDDA(
+#if NeedVarargsPrototypes
+    void* f, ...
+#endif
+)
+{
+}
+
+typedef struct _BlockHandler {
+    BlockHandlerProcPtr BlockHandler;
+    WakeupHandlerProcPtr WakeupHandler;
+    pointer blockData;
+    Bool    deleted;
+} BlockHandlerRec, *BlockHandlerPtr;
+
+static BlockHandlerPtr handlers;
+static int             numHandlers;
+static int             sizeHandlers;
+static Bool            inHandler;
+static Bool            handlerDeleted;
+
+/* called from the OS layer */
+void
+BlockHandler(pTimeout, pReadmask)
+pointer        pTimeout;       /* DIX doesn't want to know how OS represents time */
+pointer pReadmask;     /* nor how it represents the set of descriptors */
+{
+    register int i, j;
+    
+    ++inHandler;
+    for (i = 0; i < screenInfo.numScreens; i++)
+       (* screenInfo.screens[i]->BlockHandler)(i, 
+                               screenInfo.screens[i]->blockData,
+                               pTimeout, pReadmask);
+    for (i = 0; i < numHandlers; i++)
+       (*handlers[i].BlockHandler) (handlers[i].blockData,
+                                    pTimeout, pReadmask);
+    if (handlerDeleted)
+    {
+       for (i = 0; i < numHandlers;)
+           if (handlers[i].deleted)
+           {
+               for (j = i; j < numHandlers - 1; j++)
+                   handlers[j] = handlers[j+1];
+               numHandlers--;
+           }
+           else
+               i++;
+       handlerDeleted = FALSE;
+    }
+    --inHandler;
+}
+
+void
+WakeupHandler(result, pReadmask)
+int    result; /* 32 bits of undefined result from the wait */
+pointer pReadmask;     /* the resulting descriptor mask */
+{
+    register int i, j;
+
+    ++inHandler;
+    for (i = numHandlers - 1; i >= 0; i--)
+       (*handlers[i].WakeupHandler) (handlers[i].blockData,
+                                     result, pReadmask);
+    for (i = 0; i < screenInfo.numScreens; i++)
+       (* screenInfo.screens[i]->WakeupHandler)(i, 
+                               screenInfo.screens[i]->wakeupData,
+                               result, pReadmask);
+    if (handlerDeleted)
+    {
+       for (i = 0; i < numHandlers;)
+           if (handlers[i].deleted)
+           {
+               for (j = i; j < numHandlers - 1; j++)
+                   handlers[j] = handlers[j+1];
+               numHandlers--;
+           }
+           else
+               i++;
+       handlerDeleted = FALSE;
+    }
+    --inHandler;
+}
+
+/* Reentrant with BlockHandler and WakeupHandler, except wakeup won't
+ * get called until next time
+ */
+
+Bool
+RegisterBlockAndWakeupHandlers (blockHandler, wakeupHandler, blockData)
+    BlockHandlerProcPtr blockHandler;
+    WakeupHandlerProcPtr wakeupHandler;
+    pointer blockData;
+{
+    BlockHandlerPtr new;
+
+    if (numHandlers >= sizeHandlers)
+    {
+       new = (BlockHandlerPtr) xrealloc (handlers, (numHandlers + 1) *
+                                         sizeof (BlockHandlerRec));
+       if (!new)
+           return FALSE;
+       handlers = new;
+       sizeHandlers = numHandlers + 1;
+    }
+    handlers[numHandlers].BlockHandler = blockHandler;
+    handlers[numHandlers].WakeupHandler = wakeupHandler;
+    handlers[numHandlers].blockData = blockData;
+    handlers[numHandlers].deleted = FALSE;
+    numHandlers = numHandlers + 1;
+    return TRUE;
+}
+
+void
+RemoveBlockAndWakeupHandlers (blockHandler, wakeupHandler, blockData)
+    BlockHandlerProcPtr blockHandler;
+    WakeupHandlerProcPtr wakeupHandler;
+    pointer blockData;
+{
+    int            i;
+
+    for (i = 0; i < numHandlers; i++)
+       if (handlers[i].BlockHandler == blockHandler &&
+           handlers[i].WakeupHandler == wakeupHandler &&
+           handlers[i].blockData == blockData)
+       {
+           if (inHandler)
+           {
+               handlerDeleted = TRUE;
+               handlers[i].deleted = TRUE;
+           }
+           else
+           {
+               for (; i < numHandlers - 1; i++)
+                   handlers[i] = handlers[i+1];
+               numHandlers--;
+           }
+           break;
+       }
+}
+
+void
+InitBlockAndWakeupHandlers ()
+{
+    xfree (handlers);
+    handlers = (BlockHandlerPtr) 0;
+    numHandlers = 0;
+    sizeHandlers = 0;
+}
+
+/*
+ * A general work queue.  Perform some task before the server
+ * sleeps for input.
+ */
+
+WorkQueuePtr           workQueue;
+static WorkQueuePtr    *workQueueLast = &workQueue;
+
+void
+ProcessWorkQueue()
+{
+    WorkQueuePtr    q, *p;
+
+    p = &workQueue;
+    /*
+     * Scan the work queue once, calling each function.  Those
+     * which return TRUE are removed from the queue, otherwise
+     * they will be called again.  This must be reentrant with
+     * QueueWorkProc.
+     */
+    while (q = *p)
+    {
+       if ((*q->function) (q->client, q->closure))
+       {
+           /* remove q from the list */
+           *p = q->next;    /* don't fetch until after func called */
+           xfree (q);
+       }
+       else
+       {
+           p = &q->next;    /* don't fetch until after func called */
+       }
+    }
+    workQueueLast = p;
+}
+
+void
+ProcessWorkQueueZombies()
+{
+    WorkQueuePtr    q, *p;
+
+    p = &workQueue;
+    while (q = *p)
+    {
+       if (q->client && q->client->clientGone)
+       {
+           (void) (*q->function) (q->client, q->closure);
+           /* remove q from the list */
+           *p = q->next;    /* don't fetch until after func called */
+           xfree (q);
+       }
+       else
+       {
+           p = &q->next;    /* don't fetch until after func called */
+       }
+    }
+    workQueueLast = p;
+}
+
+Bool
+#if NeedFunctionPrototypes
+QueueWorkProc (
+    Bool       (*function)(
+#if NeedNestedPrototypes
+               ClientPtr       /* pClient */,
+               pointer         /* closure */
+#endif
+               ),
+    ClientPtr  client,
+    pointer    closure)
+#else
+QueueWorkProc (function, client, closure)
+    Bool       (*function)();
+    ClientPtr  client;
+    pointer    closure;
+#endif
+{
+    WorkQueuePtr    q;
+
+    q = (WorkQueuePtr) xalloc (sizeof *q);
+    if (!q)
+       return FALSE;
+    q->function = function;
+    q->client = client;
+    q->closure = closure;
+    q->next = NULL;
+    *workQueueLast = q;
+    workQueueLast = &q->next;
+    return TRUE;
+}
+
+/*
+ * Manage a queue of sleeping clients, awakening them
+ * when requested, by using the OS functions IgnoreClient
+ * and AttendClient.  Note that this *ignores* the troubles
+ * with request data interleaving itself with events, but
+ * we'll leave that until a later time.
+ */
+
+typedef struct _SleepQueue {
+    struct _SleepQueue *next;
+    ClientPtr          client;
+    ClientSleepProcPtr  function;
+    pointer            closure;
+} SleepQueueRec, *SleepQueuePtr;
+
+static SleepQueuePtr   sleepQueue = NULL;
+
+Bool
+ClientSleep (client, function, closure)
+    ClientPtr  client;
+    ClientSleepProcPtr function;
+    pointer    closure;
+{
+    SleepQueuePtr   q;
+
+    q = (SleepQueuePtr) xalloc (sizeof *q);
+    if (!q)
+       return FALSE;
+
+    IgnoreClient (client);
+    q->next = sleepQueue;
+    q->client = client;
+    q->function = function;
+    q->closure = closure;
+    sleepQueue = q;
+    return TRUE;
+}
+
+Bool
+ClientSignal (client)
+    ClientPtr  client;
+{
+    SleepQueuePtr   q;
+
+    for (q = sleepQueue; q; q = q->next)
+       if (q->client == client)
+       {
+           return QueueWorkProc (q->function, q->client, q->closure);
+       }
+    return FALSE;
+}
+
+void
+ClientWakeup (client)
+    ClientPtr  client;
+{
+    SleepQueuePtr   q, *prev;
+
+    prev = &sleepQueue;
+    while ( (q = *prev) )
+    {
+       if (q->client == client)
+       {
+           *prev = q->next;
+           xfree (q);
+           if (client->clientGone)
+               CloseDownClient(client);
+           else
+               AttendClient (client);
+           break;
+       }
+       prev = &q->next;
+    }
+}
+
+Bool
+ClientIsAsleep (client)
+    ClientPtr  client;
+{
+    SleepQueuePtr   q;
+
+    for (q = sleepQueue; q; q = q->next)
+       if (q->client == client)
+           return TRUE;
+    return FALSE;
+}
+
+/*
+ *  Generic Callback Manager
+ */
+
+/* ===== Private Procedures ===== */
+
+static int numCallbackListsToCleanup = 0;
+static CallbackListPtr **listsToCleanup = NULL;
+
+static Bool 
+#if NeedFunctionPrototypes
+_AddCallback(
+    CallbackListPtr *pcbl,
+    CallbackProcPtr callback,
+    pointer         data)
+#else
+_AddCallback(pcbl, callback, data)
+    CallbackListPtr *pcbl;
+    CallbackProcPtr callback;
+    pointer         data;
+#endif
+{
+    CallbackPtr     cbr;
+
+    cbr = (CallbackPtr) xalloc(sizeof(CallbackRec));
+    if (!cbr)
+       return FALSE;
+    cbr->proc = callback;
+    cbr->data = data;
+    cbr->next = (*pcbl)->list;
+    cbr->deleted = FALSE;
+    (*pcbl)->list = cbr;
+    return TRUE;
+}
+
+static Bool 
+#if NeedFunctionPrototypes
+_DeleteCallback(
+    CallbackListPtr *pcbl,
+    CallbackProcPtr callback,
+    pointer         data)
+#else
+_DeleteCallback(pcbl, callback, data)
+    CallbackListPtr *pcbl;
+    CallbackProcPtr callback;
+    pointer         data;
+#endif
+{
+    CallbackListPtr cbl = *pcbl;
+    CallbackPtr     cbr, pcbr;
+
+    for (pcbr = NULL, cbr = cbl->list;
+        cbr != NULL;
+        pcbr = cbr, cbr = cbr->next)
+    {
+       if ((cbr->proc == callback) && (cbr->data == data))
+           break;
+    }
+    if (cbr != NULL)
+    {
+       if (cbl->inCallback)
+       {
+           ++(cbl->numDeleted);
+           cbr->deleted = TRUE;
+       }
+       else
+       {
+           if (pcbr == NULL)
+               cbl->list = cbr->next;
+           else
+               pcbr->next = cbr->next;
+           xfree(cbr);
+       }
+       return TRUE;
+    }
+    return FALSE;
+}
+
+static void 
+#if NeedFunctionPrototypes
+_CallCallbacks(
+    CallbackListPtr    *pcbl,
+    pointer        call_data)
+#else
+_CallCallbacks(pcbl, call_data)
+    CallbackListPtr    *pcbl;
+    pointer        call_data;
+#endif
+{
+    CallbackListPtr cbl = *pcbl;
+    CallbackPtr     cbr, pcbr;
+
+    ++(cbl->inCallback);
+    for (cbr = cbl->list; cbr != NULL; cbr = cbr->next)
+    {
+       (*(cbr->proc)) (pcbl, cbr->data, call_data);
+    }
+    --(cbl->inCallback);
+
+    if (cbl->inCallback) return;
+
+    /* Was the entire list marked for deletion? */
+
+    if (cbl->deleted)
+    {
+       DeleteCallbackList(pcbl);
+       return;
+    }
+
+    /* Were some individual callbacks on the list marked for deletion?
+     * If so, do the deletions.
+     */
+
+    if (cbl->numDeleted)
+    {
+       for (pcbr = NULL, cbr = cbl->list; (cbr != NULL) && cbl->numDeleted; )
+       {
+           if (cbr->deleted)
+           {
+               if (pcbr)
+               {
+                   cbr = cbr->next;
+                   xfree(pcbr->next);
+                   pcbr->next = cbr;
+               } else
+               {
+                   cbr = cbr->next;
+                   xfree(cbl->list);
+                   cbl->list = cbr;
+               }
+               cbl->numDeleted--;
+           }
+           else /* this one wasn't deleted */
+           {
+               pcbr = cbr;
+               cbr = cbr->next;
+           }
+       }
+    }
+}
+
+static void
+#if NeedFunctionPrototypes
+_DeleteCallbackList(
+    CallbackListPtr    *pcbl)
+#else
+_DeleteCallbackList(pcbl)
+    CallbackListPtr    *pcbl;
+#endif
+{
+    CallbackListPtr cbl = *pcbl;
+    CallbackPtr     cbr, nextcbr;
+    int i;
+
+    if (cbl->inCallback)
+    {
+       cbl->deleted = TRUE;
+       return;
+    }
+
+    for (i = 0; i < numCallbackListsToCleanup; i++)
+    {
+       if ((listsToCleanup[i] = pcbl) != 0)
+       {
+           listsToCleanup[i] = NULL;
+           break;
+       }
+    }
+
+    for (cbr = cbl->list; cbr != NULL; cbr = nextcbr)
+    {
+       nextcbr = cbr->next;
+       xfree(cbr);
+    }
+    xfree(cbl);
+    *pcbl = NULL;
+}
+
+static CallbackFuncsRec default_cbfuncs =
+{
+    _AddCallback,
+    _DeleteCallback,
+    _CallCallbacks,
+    _DeleteCallbackList
+};
+
+/* ===== Public Procedures ===== */
+
+Bool
+CreateCallbackList(pcbl, cbfuncs)
+    CallbackListPtr  *pcbl;
+    CallbackFuncsPtr cbfuncs;
+{
+    CallbackListPtr  cbl;
+    int i;
+
+    if (!pcbl) return FALSE;
+    cbl = (CallbackListPtr) xalloc(sizeof(CallbackListRec));
+    if (!cbl) return FALSE;
+    cbl->funcs = cbfuncs ? *cbfuncs : default_cbfuncs;
+    cbl->inCallback = 0;
+    cbl->deleted = FALSE;
+    cbl->numDeleted = 0;
+    cbl->list = NULL;
+    *pcbl = cbl;
+
+    for (i = 0; i < numCallbackListsToCleanup; i++)
+    {
+       if (!listsToCleanup[i])
+       {
+           listsToCleanup[i] = pcbl;
+           return TRUE;
+       }    
+    }
+
+    listsToCleanup = (CallbackListPtr **)xnfrealloc(listsToCleanup,
+               sizeof(CallbackListPtr *) * (numCallbackListsToCleanup+1));
+    listsToCleanup[numCallbackListsToCleanup] = pcbl;
+    numCallbackListsToCleanup++;
+    return TRUE;
+}
+
+Bool 
+AddCallback(pcbl, callback, data)
+    CallbackListPtr *pcbl;
+    CallbackProcPtr callback;
+    pointer         data;
+{
+    if (!pcbl) return FALSE;
+    if (!*pcbl)
+    {  /* list hasn't been created yet; go create it */
+       if (!CreateCallbackList(pcbl, (CallbackFuncsPtr)NULL))
+           return FALSE;
+    }
+    return ((*(*pcbl)->funcs.AddCallback) (pcbl, callback, data));
+}
+
+Bool 
+DeleteCallback(pcbl, callback, data)
+    CallbackListPtr *pcbl;
+    CallbackProcPtr callback;
+    pointer         data;
+{
+    if (!pcbl || !*pcbl) return FALSE;
+    return ((*(*pcbl)->funcs.DeleteCallback) (pcbl, callback, data));
+}
+
+void 
+CallCallbacks(pcbl, call_data)
+    CallbackListPtr    *pcbl;
+    pointer        call_data;
+{
+    if (!pcbl || !*pcbl) return;
+    (*(*pcbl)->funcs.CallCallbacks) (pcbl, call_data);
+}
+
+void
+DeleteCallbackList(pcbl)
+    CallbackListPtr    *pcbl;
+{
+    if (!pcbl || !*pcbl) return;
+    (*(*pcbl)->funcs.DeleteCallbackList) (pcbl);
+}
+
+void 
+InitCallbackManager()
+{
+    int i;
+
+    for (i = 0; i < numCallbackListsToCleanup; i++)
+    {
+       DeleteCallbackList(listsToCleanup[i]);
+    }
+    if (listsToCleanup) xfree(listsToCleanup);
+
+    numCallbackListsToCleanup = 0;
+    listsToCleanup = NULL;
+}
diff --git a/Xserver/programs/Xserver/dix/events.c b/Xserver/programs/Xserver/dix/events.c
new file mode 100644 (file)
index 0000000..b6251ac
--- /dev/null
@@ -0,0 +1,3837 @@
+/************************************************************
+
+Copyright (c) 1987  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+
+Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
+
+                        All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and its 
+documentation for any purpose and without fee is hereby granted, 
+provided that the above copyright notice appear in all copies and that
+both that copyright notice and this permission notice appear in 
+supporting documentation, and that the name of Digital not be
+used in advertising or publicity pertaining to distribution of the
+software without specific, written prior permission.  
+
+DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
+ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
+DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
+ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+SOFTWARE.
+
+********************************************************/
+
+
+/* $XConsortium: events.c /main/187 1996/09/25 00:47:41 dpw $ */
+/* $XFree86: xc/programs/Xserver/dix/events.c,v 3.11 1996/12/24 02:23:45 dawes Exp $ */
+
+#include "X.h"
+#include "misc.h"
+#include "resource.h"
+#define NEED_EVENTS
+#define NEED_REPLIES
+#include "Xproto.h"
+#include "windowstr.h"
+#include "inputstr.h"
+#include "scrnintstr.h"
+#include "cursorstr.h"
+
+#include "dixstruct.h"
+
+#ifdef XKB
+#include "XKBsrv.h"
+#endif
+
+#ifdef XCSECURITY
+#define _SECURITY_SERVER
+#include "extensions/security.h"
+#endif
+
+#include "XIproto.h"
+#include "exevents.h"
+#include "extnsionst.h"
+
+#include "dixevents.h"
+#include "dixgrabs.h"
+#include "dispatch.h"
+
+extern WindowPtr *WindowTable;
+
+#define EXTENSION_EVENT_BASE  64
+
+#define NoSuchEvent 0x80000000 /* so doesn't match NoEventMask */
+#define StructureAndSubMask ( StructureNotifyMask | SubstructureNotifyMask )
+#define AllButtonsMask ( \
+       Button1Mask | Button2Mask | Button3Mask | Button4Mask | Button5Mask )
+#define MotionMask ( \
+       PointerMotionMask | Button1MotionMask | \
+       Button2MotionMask | Button3MotionMask | Button4MotionMask | \
+       Button5MotionMask | ButtonMotionMask )
+#define PropagateMask ( \
+       KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | \
+       MotionMask )
+#define PointerGrabMask ( \
+       ButtonPressMask | ButtonReleaseMask | \
+       EnterWindowMask | LeaveWindowMask | \
+       PointerMotionHintMask | KeymapStateMask | \
+       MotionMask )
+#define AllModifiersMask ( \
+       ShiftMask | LockMask | ControlMask | Mod1Mask | Mod2Mask | \
+       Mod3Mask | Mod4Mask | Mod5Mask )
+#define AllEventMasks (lastEventMask|(lastEventMask-1))
+/*
+ * The following relies on the fact that the Button<n>MotionMasks are equal
+ * to the corresponding Button<n>Masks from the current modifier/button state.
+ */
+#define Motion_Filter(class) (PointerMotionMask | \
+                             (class)->state | (class)->motionMask)
+
+
+#define WID(w) ((w) ? ((w)->drawable.id) : 0)
+
+#define rClient(obj) (clients[CLIENT_ID((obj)->resource)])
+
+CallbackListPtr EventCallback;
+CallbackListPtr DeviceEventCallback;
+
+#define DNPMCOUNT 8
+
+Mask DontPropagateMasks[DNPMCOUNT];
+static int DontPropagateRefCnts[DNPMCOUNT];
+
+#ifdef DEBUG
+static debug_events = 0;
+#endif
+InputInfo inputInfo;
+
+static struct {
+    QdEventPtr         pending, *pendtail;
+    DeviceIntPtr       replayDev;      /* kludgy rock to put flag for */
+    WindowPtr          replayWin;      /*   ComputeFreezes            */
+    Bool               playingEvents;
+    TimeStamp          time;
+} syncEvents;
+
+/*
+ * The window trace information is used to avoid having to compute all the
+ * windows between the root and the current pointer window each time a button
+ * or key goes down. The grabs on each of those windows must be checked.
+ */
+static WindowPtr *spriteTrace = (WindowPtr *)NULL;
+#define ROOT spriteTrace[0]
+static int spriteTraceSize = 0;
+static int spriteTraceGood;
+
+typedef struct {
+    int                x, y;
+    ScreenPtr  pScreen;
+} HotSpot;
+
+static  struct {
+    CursorPtr  current;
+    BoxRec     hotLimits;      /* logical constraints of hot spot */
+    Bool       confined;       /* confined to screen */
+#ifdef SHAPE
+    RegionPtr  hotShape;       /* additional logical shape constraint */
+#endif
+    BoxRec     physLimits;     /* physical constraints of hot spot */
+    WindowPtr  win;            /* window of logical position */
+    HotSpot    hot;            /* logical pointer position */
+    HotSpot    hotPhys;        /* physical pointer position */
+} sprite;                      /* info about the cursor sprite */
+
+static void DoEnterLeaveEvents(
+#if NeedFunctionPrototypes
+    WindowPtr /*fromWin*/,
+    WindowPtr /*toWin*/,
+    int /*mode*/
+#endif
+);
+
+static WindowPtr XYToWindow(
+#if NeedFunctionPrototypes
+    int /*x*/,
+    int /*y*/
+#endif
+);
+
+extern Bool permitOldBugs;
+extern Bool Must_have_memory;
+extern int lastEvent;
+#ifdef XINPUT
+extern int DeviceMotionNotify, DeviceButtonPress, DeviceKeyPress;
+#endif
+
+static Mask lastEventMask;
+
+#define CantBeFiltered NoEventMask
+static Mask filters[128] =
+{
+       NoSuchEvent,                   /* 0 */
+       NoSuchEvent,                   /* 1 */
+       KeyPressMask,                  /* KeyPress */
+       KeyReleaseMask,                /* KeyRelease */
+       ButtonPressMask,               /* ButtonPress */
+       ButtonReleaseMask,             /* ButtonRelease */
+       PointerMotionMask,             /* MotionNotify (initial state) */
+       EnterWindowMask,               /* EnterNotify */
+       LeaveWindowMask,               /* LeaveNotify */
+       FocusChangeMask,               /* FocusIn */
+       FocusChangeMask,               /* FocusOut */
+       KeymapStateMask,               /* KeymapNotify */
+       ExposureMask,                  /* Expose */
+       CantBeFiltered,                /* GraphicsExpose */
+       CantBeFiltered,                /* NoExpose */
+       VisibilityChangeMask,          /* VisibilityNotify */
+       SubstructureNotifyMask,        /* CreateNotify */
+       StructureAndSubMask,           /* DestroyNotify */
+       StructureAndSubMask,           /* UnmapNotify */
+       StructureAndSubMask,           /* MapNotify */
+       SubstructureRedirectMask,      /* MapRequest */
+       StructureAndSubMask,           /* ReparentNotify */
+       StructureAndSubMask,           /* ConfigureNotify */
+       SubstructureRedirectMask,      /* ConfigureRequest */
+       StructureAndSubMask,           /* GravityNotify */
+       ResizeRedirectMask,            /* ResizeRequest */
+       StructureAndSubMask,           /* CirculateNotify */
+       SubstructureRedirectMask,      /* CirculateRequest */
+       PropertyChangeMask,            /* PropertyNotify */
+       CantBeFiltered,                /* SelectionClear */
+       CantBeFiltered,                /* SelectionRequest */
+       CantBeFiltered,                /* SelectionNotify */
+       ColormapChangeMask,            /* ColormapNotify */
+       CantBeFiltered,                /* ClientMessage */
+       CantBeFiltered                 /* MappingNotify */
+};
+
+static CARD8 criticalEvents[32] =
+{
+    0x3c                               /* key and button events */
+};
+
+Mask
+GetNextEventMask()
+{
+    lastEventMask <<= 1;
+    return lastEventMask;
+}
+
+void
+SetMaskForEvent(mask, event)
+    Mask mask;
+    int event;
+{
+    if ((event < LASTEvent) || (event >= 128))
+       FatalError("SetMaskForEvent: bogus event number");
+    filters[event] = mask;
+}
+
+void
+SetCriticalEvent(event)
+    int event;
+{
+    if (event >= 128)
+       FatalError("SetCriticalEvent: bogus event number");
+    criticalEvents[event >> 3] |= 1 << (event & 7);
+}
+
+static void
+#if NeedFunctionPrototypes
+SyntheticMotion(int x, int y)
+#else
+SyntheticMotion(x, y)
+    int x, y;
+#endif
+{
+    xEvent xE;
+
+    xE.u.keyButtonPointer.rootX = x;
+    xE.u.keyButtonPointer.rootY = y;
+    if (syncEvents.playingEvents)
+       xE.u.keyButtonPointer.time = syncEvents.time.milliseconds;
+    else
+       xE.u.keyButtonPointer.time = currentTime.milliseconds;
+    xE.u.u.type = MotionNotify;
+    (*inputInfo.pointer->public.processInputProc)(&xE, inputInfo.pointer, 1);
+}
+
+#ifdef SHAPE
+static void
+#if NeedFunctionPrototypes
+ConfineToShape(RegionPtr shape, int *px, int *py)
+#else
+ConfineToShape(shape, px, py)
+    RegionPtr shape;
+    int *px, *py;
+#endif
+{
+    BoxRec box;
+    int x = *px, y = *py;
+    int incx = 1, incy = 1;
+
+    if (POINT_IN_REGION(sprite.hot.pScreen, shape, x, y, &box))
+       return;
+    box = *REGION_EXTENTS(sprite.hot.pScreen, shape);
+    /* this is rather crude */
+    do {
+       x += incx;
+       if (x >= box.x2)
+       {
+           incx = -1;
+           x = *px - 1;
+       }
+       else if (x < box.x1)
+       {
+           incx = 1;
+           x = *px;
+           y += incy;
+           if (y >= box.y2)
+           {
+               incy = -1;
+               y = *py - 1;
+           }
+           else if (y < box.y1)
+               return; /* should never get here! */
+       }
+    } while (!POINT_IN_REGION(sprite.hot.pScreen, shape, x, y, &box));
+    *px = x;
+    *py = y;
+}
+#endif
+
+static void
+#if NeedFunctionPrototypes
+CheckPhysLimits(
+    CursorPtr cursor,
+    Bool generateEvents,
+    Bool confineToScreen,
+    ScreenPtr pScreen)
+#else
+CheckPhysLimits(cursor, generateEvents, confineToScreen, pScreen)
+    CursorPtr cursor;
+    Bool generateEvents;
+    Bool confineToScreen;
+    ScreenPtr pScreen;
+#endif
+{
+    HotSpot new;
+
+    if (!cursor)
+       return;
+    new = sprite.hotPhys;
+    if (pScreen)
+       new.pScreen = pScreen;
+    else
+       pScreen = new.pScreen;
+    (*pScreen->CursorLimits) (pScreen, cursor, &sprite.hotLimits,
+                             &sprite.physLimits);
+    sprite.confined = confineToScreen;
+    (* pScreen->ConstrainCursor)(pScreen, &sprite.physLimits);
+    if (new.x < sprite.physLimits.x1)
+       new.x = sprite.physLimits.x1;
+    else
+       if (new.x >= sprite.physLimits.x2)
+           new.x = sprite.physLimits.x2 - 1;
+    if (new.y < sprite.physLimits.y1)
+       new.y = sprite.physLimits.y1;
+    else
+       if (new.y >= sprite.physLimits.y2)
+           new.y = sprite.physLimits.y2 - 1;
+#ifdef SHAPE
+    if (sprite.hotShape)
+       ConfineToShape(sprite.hotShape, &new.x, &new.y);
+#endif
+    if ((pScreen != sprite.hotPhys.pScreen) ||
+       (new.x != sprite.hotPhys.x) || (new.y != sprite.hotPhys.y))
+    {
+       if (pScreen != sprite.hotPhys.pScreen)
+           sprite.hotPhys = new;
+       (*pScreen->SetCursorPosition) (pScreen, new.x, new.y, generateEvents);
+       if (!generateEvents)
+           SyntheticMotion(new.x, new.y);
+    }
+}
+
+static void
+#if NeedFunctionPrototypes
+CheckVirtualMotion(
+    register QdEventPtr qe,
+    register WindowPtr pWin)
+#else
+CheckVirtualMotion(qe, pWin)
+    register QdEventPtr qe;
+    register WindowPtr pWin;
+#endif
+{
+
+    if (qe)
+    {
+       sprite.hot.pScreen = qe->pScreen;
+       sprite.hot.x = qe->event->u.keyButtonPointer.rootX;
+       sprite.hot.y = qe->event->u.keyButtonPointer.rootY;
+       pWin = inputInfo.pointer->grab ? inputInfo.pointer->grab->confineTo :
+                                        NullWindow;
+    }
+    if (pWin)
+    {
+       BoxRec lims;
+
+       if (sprite.hot.pScreen != pWin->drawable.pScreen)
+       {
+           sprite.hot.pScreen = pWin->drawable.pScreen;
+           sprite.hot.x = sprite.hot.y = 0;
+       }
+       lims = *REGION_EXTENTS(pWin->drawable.pScreen, &pWin->borderSize);
+       if (sprite.hot.x < lims.x1)
+           sprite.hot.x = lims.x1;
+       else if (sprite.hot.x >= lims.x2)
+           sprite.hot.x = lims.x2 - 1;
+       if (sprite.hot.y < lims.y1)
+           sprite.hot.y = lims.y1;
+       else if (sprite.hot.y >= lims.y2)
+           sprite.hot.y = lims.y2 - 1;
+#ifdef SHAPE
+       if (wBoundingShape(pWin))
+           ConfineToShape(&pWin->borderSize, &sprite.hot.x, &sprite.hot.y);
+#endif
+       if (qe)
+       {
+           qe->pScreen = sprite.hot.pScreen;
+           qe->event->u.keyButtonPointer.rootX = sprite.hot.x;
+           qe->event->u.keyButtonPointer.rootY = sprite.hot.y;
+       }
+    }
+    ROOT = WindowTable[sprite.hot.pScreen->myNum];
+}
+
+void
+ConfineCursorToWindow(pWin, generateEvents, confineToScreen)
+    WindowPtr pWin;
+    Bool generateEvents;
+    Bool confineToScreen;
+{
+    ScreenPtr pScreen = pWin->drawable.pScreen;
+
+    if (syncEvents.playingEvents)
+    {
+       CheckVirtualMotion((QdEventPtr)NULL, pWin);
+       SyntheticMotion(sprite.hot.x, sprite.hot.y);
+    }
+    else
+    {
+       sprite.hotLimits = *REGION_EXTENTS( pScreen, &pWin->borderSize);
+#ifdef SHAPE
+       sprite.hotShape = wBoundingShape(pWin) ? &pWin->borderSize
+                                              : NullRegion;
+#endif
+       CheckPhysLimits(sprite.current, generateEvents, confineToScreen,
+                       pScreen);
+    }
+}
+
+Bool
+PointerConfinedToScreen()
+{
+    return sprite.confined;
+}
+
+static void
+#if NeedFunctionPrototypes
+ChangeToCursor(CursorPtr cursor)
+#else
+ChangeToCursor(cursor)
+    CursorPtr cursor;
+#endif
+{
+    if (cursor != sprite.current)
+    {
+       if ((sprite.current->bits->xhot != cursor->bits->xhot) ||
+               (sprite.current->bits->yhot != cursor->bits->yhot))
+           CheckPhysLimits(cursor, FALSE, PointerConfinedToScreen(),
+                           (ScreenPtr)NULL);
+       (*sprite.hotPhys.pScreen->DisplayCursor) (sprite.hotPhys.pScreen,
+                                                 cursor);
+       sprite.current = cursor;
+    }
+}
+
+/* returns true if b is a descendent of a */
+Bool
+IsParent(a, b)
+    register WindowPtr a, b;
+{
+    for (b = b->parent; b; b = b->parent)
+       if (b == a) return TRUE;
+    return FALSE;
+}
+
+static void
+#if NeedFunctionPrototypes
+PostNewCursor(void)
+#else
+PostNewCursor()
+#endif
+{
+    register    WindowPtr win;
+    register    GrabPtr grab = inputInfo.pointer->grab;
+
+    if (syncEvents.playingEvents)
+       return;
+    if (grab)
+    {
+       if (grab->cursor)
+       {
+           ChangeToCursor(grab->cursor);
+           return;
+       }
+       if (IsParent(grab->window, sprite.win))
+           win = sprite.win;
+       else
+           win = grab->window;
+    }
+    else
+       win = sprite.win;
+    for (; win; win = win->parent)
+       if (win->optional && win->optional->cursor != NullCursor)
+       {
+           ChangeToCursor(win->optional->cursor);
+           return;
+       }
+}
+
+WindowPtr
+GetCurrentRootWindow()
+{
+    return ROOT;
+}
+
+WindowPtr
+GetSpriteWindow()
+{
+    return sprite.win;
+}
+
+CursorPtr
+GetSpriteCursor()
+{
+    return sprite.current;
+}
+
+void
+GetSpritePosition(px, py)
+    int *px, *py;
+{
+    *px = sprite.hotPhys.x;
+    *py = sprite.hotPhys.y;
+}
+
+#define TIMESLOP (5 * 60 * 1000) /* 5 minutes */
+
+static void
+#if NeedFunctionPrototypes
+MonthChangedOrBadTime(register xEvent *xE)
+#else
+MonthChangedOrBadTime(xE)
+    register xEvent *xE;
+#endif
+{
+    /* If the ddx/OS is careless about not processing timestamped events from
+     * different sources in sorted order, then it's possible for time to go
+     * backwards when it should not.  Here we ensure a decent time.
+     */
+    if ((currentTime.milliseconds - xE->u.keyButtonPointer.time) > TIMESLOP)
+       currentTime.months++;
+    else
+       xE->u.keyButtonPointer.time = currentTime.milliseconds;
+}
+
+#define NoticeTime(xE) { \
+    if ((xE)->u.keyButtonPointer.time < currentTime.milliseconds) \
+       MonthChangedOrBadTime(xE); \
+    currentTime.milliseconds = (xE)->u.keyButtonPointer.time; \
+    lastDeviceEventTime = currentTime; }
+
+void
+NoticeEventTime(xE)
+    register xEvent *xE;
+{
+    if (!syncEvents.playingEvents)
+       NoticeTime(xE);
+}
+
+/**************************************************************************
+ *            The following procedures deal with synchronous events       *
+ **************************************************************************/
+
+void
+EnqueueEvent(xE, device, count)
+    xEvent             *xE;
+    DeviceIntPtr       device;
+    int                        count;
+{
+    register QdEventPtr tail = *syncEvents.pendtail;
+    register QdEventPtr qe;
+    xEvent             *qxE;
+
+    NoticeTime(xE);
+    if (DeviceEventCallback)
+    {
+       DeviceEventInfoRec eventinfo;
+       /*  The RECORD spec says that the root window field of motion events
+        *  must be valid.  At this point, it hasn't been filled in yet, so
+        *  we do it here.  The long expression below is necessary to get
+        *  the current root window; the apparently reasonable alternative
+        *  GetCurrentRootWindow()->drawable.id doesn't give you the right
+        *  answer on the first motion event after a screen change because
+        *  the data that GetCurrentRootWindow relies on hasn't been
+        *  updated yet.
+        */
+       if (xE->u.u.type == MotionNotify)
+           xE->u.keyButtonPointer.root =
+               WindowTable[sprite.hotPhys.pScreen->myNum]->drawable.id;
+       eventinfo.events = xE;
+       eventinfo.count = count;
+       CallCallbacks(&DeviceEventCallback, (pointer)&eventinfo);
+    }
+    if (xE->u.u.type == MotionNotify)
+    {
+       sprite.hotPhys.x = xE->u.keyButtonPointer.rootX;
+       sprite.hotPhys.y = xE->u.keyButtonPointer.rootY;
+       /* do motion compression */
+       if (tail &&
+           (tail->event->u.u.type == MotionNotify) &&
+           (tail->pScreen == sprite.hotPhys.pScreen))
+       {
+           tail->event->u.keyButtonPointer.rootX = sprite.hotPhys.x;
+           tail->event->u.keyButtonPointer.rootY = sprite.hotPhys.y;
+           tail->event->u.keyButtonPointer.time = xE->u.keyButtonPointer.time;
+           tail->months = currentTime.months;
+           return;
+       }
+    }
+    qe = (QdEventPtr)xalloc(sizeof(QdEventRec) + (count * sizeof(xEvent)));
+    if (!qe)
+       return;
+    qe->next = (QdEventPtr)NULL;
+    qe->device = device;
+    qe->pScreen = sprite.hotPhys.pScreen;
+    qe->months = currentTime.months;
+    qe->event = (xEvent *)(qe + 1);
+    qe->evcount = count;
+    for (qxE = qe->event; --count >= 0; qxE++, xE++)
+       *qxE = *xE;
+    if (tail)
+       syncEvents.pendtail = &tail->next;
+    *syncEvents.pendtail = qe;
+}
+
+static void
+#if NeedFunctionPrototypes
+PlayReleasedEvents(void)
+#else
+PlayReleasedEvents()
+#endif
+{
+    register QdEventPtr *prev, qe;
+    register DeviceIntPtr dev;
+
+    prev = &syncEvents.pending;
+    while ( (qe = *prev) )
+    {
+       if (!qe->device->sync.frozen)
+       {
+           *prev = qe->next;
+           if (*syncEvents.pendtail == *prev)
+               syncEvents.pendtail = prev;
+           if (qe->event->u.u.type == MotionNotify)
+               CheckVirtualMotion(qe, NullWindow);
+           syncEvents.time.months = qe->months;
+           syncEvents.time.milliseconds = qe->event->u.keyButtonPointer.time;
+           (*qe->device->public.processInputProc)(qe->event, qe->device,
+                                                  qe->evcount);
+           xfree(qe);
+           for (dev = inputInfo.devices; dev && dev->sync.frozen; dev = dev->next)
+               ;
+           if (!dev)
+               break;
+           /* Playing the event may have unfrozen another device. */
+           /* So to play it safe, restart at the head of the queue */
+           prev = &syncEvents.pending;
+       }
+       else
+           prev = &qe->next;
+    } 
+}
+
+static void
+#if NeedFunctionPrototypes
+FreezeThaw(register DeviceIntPtr dev, Bool frozen)
+#else
+FreezeThaw(dev, frozen)
+    register DeviceIntPtr dev;
+    Bool frozen;
+#endif
+{
+    dev->sync.frozen = frozen;
+    if (frozen)
+       dev->public.processInputProc = dev->public.enqueueInputProc;
+    else
+       dev->public.processInputProc = dev->public.realInputProc;
+}
+
+void
+ComputeFreezes()
+{
+    register DeviceIntPtr replayDev = syncEvents.replayDev;
+    register int i;
+    WindowPtr w;
+    register xEvent *xE;
+    int count;
+    GrabPtr grab;
+    register DeviceIntPtr dev;
+
+    for (dev = inputInfo.devices; dev; dev = dev->next)
+       FreezeThaw(dev, dev->sync.other || (dev->sync.state >= FROZEN));
+    if (syncEvents.playingEvents || (!replayDev && !syncEvents.pending))
+       return;
+    syncEvents.playingEvents = TRUE;
+    if (replayDev)
+    {
+       xE = replayDev->sync.event;
+       count = replayDev->sync.evcount;
+       syncEvents.replayDev = (DeviceIntPtr)NULL;
+       w = XYToWindow(
+           xE->u.keyButtonPointer.rootX, xE->u.keyButtonPointer.rootY);
+       for (i = 0; i < spriteTraceGood; i++)
+           if (syncEvents.replayWin == spriteTrace[i])
+           {
+               if (!CheckDeviceGrabs(replayDev, xE, i+1, count))
+                   if (replayDev->focus)
+                       DeliverFocusedEvent(replayDev, xE, w, count);
+                   else
+                       DeliverDeviceEvents(w, xE, NullGrab, NullWindow,
+                                           replayDev, count);
+               goto playmore;
+           }
+       /* must not still be in the same stack */
+       if (replayDev->focus)
+           DeliverFocusedEvent(replayDev, xE, w, count);
+       else
+           DeliverDeviceEvents(w, xE, NullGrab, NullWindow, replayDev, count);
+    }
+playmore:
+    for (dev = inputInfo.devices; dev; dev = dev->next)
+    {
+       if (!dev->sync.frozen)
+       {
+           PlayReleasedEvents();
+           break;
+       }
+    }
+    syncEvents.playingEvents = FALSE;
+    /* the following may have been skipped during replay, so do it now */
+    if ((grab = inputInfo.pointer->grab) && grab->confineTo)
+    {
+       if (grab->confineTo->drawable.pScreen != sprite.hotPhys.pScreen)
+           sprite.hotPhys.x = sprite.hotPhys.y = 0;
+       ConfineCursorToWindow(grab->confineTo, TRUE, TRUE);
+    }
+    else
+       ConfineCursorToWindow(WindowTable[sprite.hotPhys.pScreen->myNum],
+                             TRUE, FALSE);
+    PostNewCursor();
+}
+
+void
+CheckGrabForSyncs(thisDev, thisMode, otherMode)
+    register DeviceIntPtr thisDev;
+    Bool thisMode, otherMode;
+{
+    register GrabPtr grab = thisDev->grab;
+    register DeviceIntPtr dev;
+
+    if (thisMode == GrabModeSync)
+       thisDev->sync.state = FROZEN_NO_EVENT;
+    else
+    {  /* free both if same client owns both */
+       thisDev->sync.state = THAWED;
+       if (thisDev->sync.other &&
+           (CLIENT_BITS(thisDev->sync.other->resource) ==
+            CLIENT_BITS(grab->resource)))
+           thisDev->sync.other = NullGrab;
+    }
+    for (dev = inputInfo.devices; dev; dev = dev->next)
+    {
+       if (dev != thisDev)
+       {
+           if (otherMode == GrabModeSync)
+               dev->sync.other = grab;
+           else
+           {   /* free both if same client owns both */
+               if (dev->sync.other &&
+                   (CLIENT_BITS(dev->sync.other->resource) ==
+                    CLIENT_BITS(grab->resource)))
+                   dev->sync.other = NullGrab;
+           }
+       }
+    }
+    ComputeFreezes();
+}
+
+void
+ActivatePointerGrab(mouse, grab, time, autoGrab)
+    register GrabPtr grab;
+    register DeviceIntPtr mouse;
+    TimeStamp time;
+    Bool autoGrab;
+{
+    WindowPtr oldWin = (mouse->grab) ? mouse->grab->window
+                                    : sprite.win;
+
+    if (grab->confineTo)
+    {
+       if (grab->confineTo->drawable.pScreen != sprite.hotPhys.pScreen)
+           sprite.hotPhys.x = sprite.hotPhys.y = 0;
+       ConfineCursorToWindow(grab->confineTo, FALSE, TRUE);
+    }
+    DoEnterLeaveEvents(oldWin, grab->window, NotifyGrab);
+    mouse->valuator->motionHintWindow = NullWindow;
+    if (syncEvents.playingEvents)
+       mouse->grabTime = syncEvents.time;
+    else
+       mouse->grabTime = time;
+    if (grab->cursor)
+       grab->cursor->refcnt++;
+    mouse->activeGrab = *grab;
+    mouse->grab = &mouse->activeGrab;
+    mouse->fromPassiveGrab = autoGrab;
+    PostNewCursor();
+    CheckGrabForSyncs(mouse,
+                     (Bool)grab->pointerMode, (Bool)grab->keyboardMode);
+}
+
+void
+DeactivatePointerGrab(mouse)
+    register DeviceIntPtr mouse;
+{
+    register GrabPtr grab = mouse->grab;
+    register DeviceIntPtr dev;
+
+    mouse->valuator->motionHintWindow = NullWindow;
+    mouse->grab = NullGrab;
+    mouse->sync.state = NOT_GRABBED;
+    mouse->fromPassiveGrab = FALSE;
+    for (dev = inputInfo.devices; dev; dev = dev->next)
+    {
+       if (dev->sync.other == grab)
+           dev->sync.other = NullGrab;
+    }
+    DoEnterLeaveEvents(grab->window, sprite.win, NotifyUngrab);
+    if (grab->confineTo)
+       ConfineCursorToWindow(ROOT, FALSE, FALSE);
+    PostNewCursor();
+    if (grab->cursor)
+       FreeCursor(grab->cursor, (Cursor)0);
+    ComputeFreezes();
+}
+
+void
+ActivateKeyboardGrab(keybd, grab, time, passive)
+    register DeviceIntPtr keybd;
+    GrabPtr grab;
+    TimeStamp time;
+    Bool passive;
+{
+    WindowPtr oldWin;
+
+    if (keybd->grab)
+       oldWin = keybd->grab->window;
+    else if (keybd->focus)
+       oldWin = keybd->focus->win;
+    else
+       oldWin = sprite.win;
+    if (oldWin == FollowKeyboardWin)
+       oldWin = inputInfo.keyboard->focus->win;
+    if (keybd->valuator)
+       keybd->valuator->motionHintWindow = NullWindow;
+    DoFocusEvents(keybd, oldWin, grab->window, NotifyGrab);
+    if (syncEvents.playingEvents)
+       keybd->grabTime = syncEvents.time;
+    else
+       keybd->grabTime = time;
+    keybd->activeGrab = *grab;
+    keybd->grab = &keybd->activeGrab;
+    keybd->fromPassiveGrab = passive;
+    CheckGrabForSyncs(keybd,
+                     (Bool)grab->keyboardMode, (Bool)grab->pointerMode);
+}
+
+void
+DeactivateKeyboardGrab(keybd)
+    register DeviceIntPtr keybd;
+{
+    register GrabPtr grab = keybd->grab;
+    register DeviceIntPtr dev;
+    register WindowPtr focusWin = keybd->focus ? keybd->focus->win
+                                              : sprite.win;
+
+    if (focusWin == FollowKeyboardWin)
+       focusWin = inputInfo.keyboard->focus->win;
+    if (keybd->valuator)
+       keybd->valuator->motionHintWindow = NullWindow;
+    keybd->grab = NullGrab;
+    keybd->sync.state = NOT_GRABBED;
+    keybd->fromPassiveGrab = FALSE;
+    for (dev = inputInfo.devices; dev; dev = dev->next)
+    {
+       if (dev->sync.other == grab)
+           dev->sync.other = NullGrab;
+    }
+    DoFocusEvents(keybd, grab->window, focusWin, NotifyUngrab);
+    ComputeFreezes();
+}
+
+void
+AllowSome(client, time, thisDev, newState)
+    ClientPtr          client;
+    TimeStamp          time;
+    register DeviceIntPtr thisDev;
+    int                        newState;
+{
+    Bool thisGrabbed, otherGrabbed, othersFrozen, thisSynced;
+    TimeStamp grabTime;
+    register DeviceIntPtr dev;
+
+    thisGrabbed = thisDev->grab && SameClient(thisDev->grab, client);
+    thisSynced = FALSE;
+    otherGrabbed = FALSE;
+    othersFrozen = TRUE;
+    grabTime = thisDev->grabTime;
+    for (dev = inputInfo.devices; dev; dev = dev->next)
+    {
+       if (dev == thisDev)
+           continue;
+       if (dev->grab && SameClient(dev->grab, client))
+       {
+           if (!(thisGrabbed || otherGrabbed) ||
+               (CompareTimeStamps(dev->grabTime, grabTime) == LATER))
+               grabTime = dev->grabTime;
+           otherGrabbed = TRUE;
+           if (thisDev->sync.other == dev->grab)
+               thisSynced = TRUE;
+           if (dev->sync.state < FROZEN)
+               othersFrozen = FALSE;
+       }
+       else if (!dev->sync.other || !SameClient(dev->sync.other, client))
+           othersFrozen = FALSE;
+    }
+    if (!((thisGrabbed && thisDev->sync.state >= FROZEN) || thisSynced))
+       return;
+    if ((CompareTimeStamps(time, currentTime) == LATER) ||
+       (CompareTimeStamps(time, grabTime) == EARLIER))
+       return;
+    switch (newState)
+    {
+       case THAWED:                   /* Async */
+           if (thisGrabbed)
+               thisDev->sync.state = THAWED;
+           if (thisSynced)
+               thisDev->sync.other = NullGrab;
+           ComputeFreezes();
+           break;
+       case FREEZE_NEXT_EVENT:         /* Sync */
+           if (thisGrabbed)
+           {
+               thisDev->sync.state = FREEZE_NEXT_EVENT;
+               if (thisSynced)
+                   thisDev->sync.other = NullGrab;
+               ComputeFreezes();
+           }
+           break;
+       case THAWED_BOTH:               /* AsyncBoth */
+           if (othersFrozen)
+           {
+               for (dev = inputInfo.devices; dev; dev = dev->next)
+               {
+                   if (dev->grab && SameClient(dev->grab, client))
+                       dev->sync.state = THAWED;
+                   if (dev->sync.other && SameClient(dev->sync.other, client))
+                       dev->sync.other = NullGrab;
+               }
+               ComputeFreezes();
+           }
+           break;
+       case FREEZE_BOTH_NEXT_EVENT:    /* SyncBoth */
+           if (othersFrozen)
+           {
+               for (dev = inputInfo.devices; dev; dev = dev->next)
+               {
+                   if (dev->grab && SameClient(dev->grab, client))
+                       dev->sync.state = FREEZE_BOTH_NEXT_EVENT;
+                   if (dev->sync.other && SameClient(dev->sync.other, client))
+                       dev->sync.other = NullGrab;
+               }
+               ComputeFreezes();
+           }
+           break;
+       case NOT_GRABBED:               /* Replay */
+           if (thisGrabbed && thisDev->sync.state == FROZEN_WITH_EVENT)
+           {
+               if (thisSynced)
+                   thisDev->sync.other = NullGrab;
+               syncEvents.replayDev = thisDev;
+               syncEvents.replayWin = thisDev->grab->window;
+               (*thisDev->DeactivateGrab)(thisDev);
+               syncEvents.replayDev = (DeviceIntPtr)NULL;
+           }
+           break;
+       case THAW_OTHERS:               /* AsyncOthers */
+           if (othersFrozen)
+           {
+               for (dev = inputInfo.devices; dev; dev = dev->next)
+               {
+                   if (dev == thisDev)
+                       continue;
+                   if (dev->grab && SameClient(dev->grab, client))
+                       dev->sync.state = THAWED;
+                   if (dev->sync.other && SameClient(dev->sync.other, client))
+                       dev->sync.other = NullGrab;
+               }
+               ComputeFreezes();
+           }
+           break;
+    }
+}
+
+int
+ProcAllowEvents(client)
+    register ClientPtr client;
+{
+    TimeStamp          time;
+    DeviceIntPtr       mouse = inputInfo.pointer;
+    DeviceIntPtr       keybd = inputInfo.keyboard;
+    REQUEST(xAllowEventsReq);
+
+    REQUEST_SIZE_MATCH(xAllowEventsReq);
+    time = ClientTimeToServerTime(stuff->time);
+    switch (stuff->mode)
+    {
+       case ReplayPointer:
+           AllowSome(client, time, mouse, NOT_GRABBED);
+           break;
+       case SyncPointer: 
+           AllowSome(client, time, mouse, FREEZE_NEXT_EVENT);
+           break;
+       case AsyncPointer: 
+           AllowSome(client, time, mouse, THAWED);
+           break;
+       case ReplayKeyboard: 
+           AllowSome(client, time, keybd, NOT_GRABBED);
+           break;
+       case SyncKeyboard: 
+           AllowSome(client, time, keybd, FREEZE_NEXT_EVENT);
+           break;
+       case AsyncKeyboard: 
+           AllowSome(client, time, keybd, THAWED);
+           break;
+       case SyncBoth:
+           AllowSome(client, time, keybd, FREEZE_BOTH_NEXT_EVENT);
+           break;
+       case AsyncBoth:
+           AllowSome(client, time, keybd, THAWED_BOTH);
+           break;
+       default: 
+           client->errorValue = stuff->mode;
+           return BadValue;
+    }
+    return Success;
+}
+
+void
+ReleaseActiveGrabs(client)
+    ClientPtr client;
+{
+    register DeviceIntPtr dev;
+    Bool    done;
+
+    /* XXX CloseDownClient should remove passive grabs before
+     * releasing active grabs.
+     */
+    do {
+       done = TRUE;
+       for (dev = inputInfo.devices; dev; dev = dev->next)
+       {
+           if (dev->grab && SameClient(dev->grab, client))
+           {
+               (*dev->DeactivateGrab)(dev);
+               done = FALSE;
+           }
+       }
+    } while (!done);
+}
+
+/**************************************************************************
+ *            The following procedures deal with delivering events        *
+ **************************************************************************/
+
+int
+TryClientEvents (client, pEvents, count, mask, filter, grab)
+    ClientPtr client;
+    GrabPtr grab;
+    xEvent *pEvents;
+    int count;
+    Mask mask, filter;
+{
+    int i;
+    int type;
+
+#ifdef DEBUG
+    if (debug_events) ErrorF(
+       "Event([%d, %d], mask=0x%x), client=%d",
+       pEvents->u.u.type, pEvents->u.u.detail, mask, client->index);
+#endif
+    if ((client) && (client != serverClient) && (!client->clientGone) &&
+       ((filter == CantBeFiltered) || (mask & filter)))
+    {
+       if (grab && !SameClient(grab, client))
+           return -1; /* don't send, but notify caller */
+       type = pEvents->u.u.type;
+       if (type == MotionNotify)
+       {
+           if (mask & PointerMotionHintMask)
+           {
+               if (WID(inputInfo.pointer->valuator->motionHintWindow) ==
+                   pEvents->u.keyButtonPointer.event)
+               {
+#ifdef DEBUG
+                   if (debug_events) ErrorF("\n");
+#endif
+                   return 1; /* don't send, but pretend we did */
+               }
+               pEvents->u.u.detail = NotifyHint;
+           }
+           else
+           {
+               pEvents->u.u.detail = NotifyNormal;
+           }
+       }
+#ifdef XINPUT
+       else
+       {
+           if ((type == DeviceMotionNotify) &&
+               MaybeSendDeviceMotionNotifyHint
+                       ((deviceKeyButtonPointer*)pEvents, mask) != 0)
+               return 1;
+       }
+#endif
+       type &= 0177;
+       if (type != KeymapNotify)
+       {
+           /* all extension events must have a sequence number */
+           for (i = 0; i < count; i++)
+               pEvents[i].u.u.sequenceNumber = client->sequence;
+       }
+
+       if (BitIsOn(criticalEvents, type))
+           SetCriticalOutputPending();
+
+       WriteEventsToClient(client, count, pEvents);
+#ifdef DEBUG
+       if (debug_events) ErrorF(  " delivered\n");
+#endif
+       return 1;
+    }
+    else
+    {
+#ifdef DEBUG
+       if (debug_events) ErrorF("\n");
+#endif
+       return 0;
+    }
+}
+
+int
+DeliverEventsToWindow(pWin, pEvents, count, filter, grab, mskidx)
+    register WindowPtr pWin;
+    GrabPtr grab;
+    xEvent *pEvents;
+    int count;
+    Mask filter;
+    int mskidx;
+{
+    int deliveries = 0, nondeliveries = 0;
+    int attempt;
+    register InputClients *other;
+    ClientPtr client = NullClient;
+    Mask deliveryMask;         /* If a grab occurs due to a button press, then
+                             this mask is the mask of the grab. */
+    int type = pEvents->u.u.type;
+
+    /* CantBeFiltered means only window owner gets the event */
+    if ((filter == CantBeFiltered) || !(type & EXTENSION_EVENT_BASE))
+    {
+       /* if nobody ever wants to see this event, skip some work */
+       if (filter != CantBeFiltered &&
+           !((wOtherEventMasks(pWin)|pWin->eventMask) & filter))
+           return 0;
+       if ( (attempt = TryClientEvents(wClient(pWin), pEvents, count,
+                                     pWin->eventMask, filter, grab)) )
+       {
+           if (attempt > 0)
+           {
+               deliveries++;
+               client = wClient(pWin);
+               deliveryMask = pWin->eventMask;
+           } else
+               nondeliveries--;
+       }
+    }
+    if (filter != CantBeFiltered)
+    {
+       if (type & EXTENSION_EVENT_BASE)
+       {
+           OtherInputMasks *inputMasks;
+
+           inputMasks = wOtherInputMasks(pWin);
+           if (!inputMasks ||
+               !(inputMasks->inputEvents[mskidx] & filter))
+               return 0;
+           other = inputMasks->inputClients;
+       }
+       else
+           other = (InputClients *)wOtherClients(pWin);
+       for (; other; other = other->next)
+       {
+           if ( (attempt = TryClientEvents(rClient(other), pEvents, count,
+                                         other->mask[mskidx], filter, grab)) )
+           {
+               if (attempt > 0)
+               {
+                   deliveries++;
+                   client = rClient(other);
+                   deliveryMask = other->mask[mskidx];
+               } else
+                   nondeliveries--;
+           }
+       }
+    }
+    if ((type == ButtonPress) && deliveries && (!grab))
+    {
+       GrabRec tempGrab;
+
+       tempGrab.device = inputInfo.pointer;
+       tempGrab.resource = client->clientAsMask;
+       tempGrab.window = pWin;
+       tempGrab.ownerEvents = (deliveryMask & OwnerGrabButtonMask) ? TRUE : FALSE;
+       tempGrab.eventMask = deliveryMask;
+       tempGrab.keyboardMode = GrabModeAsync;
+       tempGrab.pointerMode = GrabModeAsync;
+       tempGrab.confineTo = NullWindow;
+       tempGrab.cursor = NullCursor;
+       (*inputInfo.pointer->ActivateGrab)(inputInfo.pointer, &tempGrab,
+                                          currentTime, TRUE);
+    }
+    else if ((type == MotionNotify) && deliveries)
+       inputInfo.pointer->valuator->motionHintWindow = pWin;
+#ifdef XINPUT
+    else
+    {
+       if (((type == DeviceMotionNotify) || (type == DeviceButtonPress)) &&
+           deliveries)
+           CheckDeviceGrabAndHintWindow (pWin, type,
+                                         (deviceKeyButtonPointer*) pEvents,
+                                         grab, client, deliveryMask);
+    }
+#endif
+    if (deliveries)
+       return deliveries;
+    return nondeliveries;
+}
+
+/* If the event goes to dontClient, don't send it and return 0.  if
+   send works,  return 1 or if send didn't work, return 2.
+   Only works for core events.
+*/
+
+int
+MaybeDeliverEventsToClient(pWin, pEvents, count, filter, dontClient)
+    register WindowPtr pWin;
+    xEvent *pEvents;
+    int count;
+    Mask filter;
+    ClientPtr dontClient;
+{
+    register OtherClients *other;
+
+    if (pWin->eventMask & filter)
+    {
+        if (wClient(pWin) == dontClient)
+           return 0;
+       return TryClientEvents(wClient(pWin), pEvents, count,
+                              pWin->eventMask, filter, NullGrab);
+    }
+    for (other = wOtherClients(pWin); other; other = other->next)
+    {
+       if (other->mask & filter)
+       {
+            if (SameClient(other, dontClient))
+               return 0;
+           return TryClientEvents(rClient(other), pEvents, count,
+                                  other->mask, filter, NullGrab);
+       }
+    }
+    return 2;
+}
+
+static void
+#if NeedFunctionPrototypes
+FixUpEventFromWindow(
+    xEvent *xE,
+    WindowPtr pWin,
+    Window child,
+    Bool calcChild)
+#else
+FixUpEventFromWindow(xE, pWin, child, calcChild)
+    xEvent *xE;
+    WindowPtr pWin;
+    Window child;
+    Bool calcChild;
+#endif
+{
+    if (calcChild)
+    {
+        WindowPtr w=spriteTrace[spriteTraceGood-1];
+
+       /* If the search ends up past the root should the child field be 
+               set to none or should the value in the argument be passed 
+               through. It probably doesn't matter since everyone calls 
+               this function with child == None anyway. */
+
+        while (w) 
+        {
+            /* If the source window is same as event window, child should be
+               none.  Don't bother going all all the way back to the root. */
+
+           if (w == pWin)
+           { 
+               child = None;
+               break;
+           }
+           
+           if (w->parent == pWin)
+           {
+               child = w->drawable.id;
+               break;
+            }
+           w = w->parent;
+        }          
+    }
+    xE->u.keyButtonPointer.root = ROOT->drawable.id;
+    xE->u.keyButtonPointer.event = pWin->drawable.id;
+    if (sprite.hot.pScreen == pWin->drawable.pScreen)
+    {
+       xE->u.keyButtonPointer.sameScreen = xTrue;
+       xE->u.keyButtonPointer.child = child;
+       xE->u.keyButtonPointer.eventX =
+           xE->u.keyButtonPointer.rootX - pWin->drawable.x;
+       xE->u.keyButtonPointer.eventY =
+           xE->u.keyButtonPointer.rootY - pWin->drawable.y;
+    }
+    else
+    {
+       xE->u.keyButtonPointer.sameScreen = xFalse;
+       xE->u.keyButtonPointer.child = None;
+       xE->u.keyButtonPointer.eventX = 0;
+       xE->u.keyButtonPointer.eventY = 0;
+    }
+}
+
+int
+DeliverDeviceEvents(pWin, xE, grab, stopAt, dev, count)
+    register WindowPtr pWin, stopAt;
+    register xEvent *xE;
+    GrabPtr grab;
+    DeviceIntPtr dev;
+    int count;
+{
+    Window child = None;
+    int type = xE->u.u.type;
+    Mask filter = filters[type];
+    int deliveries = 0;
+
+    if (type & EXTENSION_EVENT_BASE)
+    {
+       register OtherInputMasks *inputMasks;
+       int mskidx = dev->id;
+
+       inputMasks = wOtherInputMasks(pWin);
+       if (inputMasks && !(filter & inputMasks->deliverableEvents[mskidx]))
+           return 0;
+       while (pWin)
+       {
+           if (inputMasks && (inputMasks->inputEvents[mskidx] & filter))
+           {
+               FixUpEventFromWindow(xE, pWin, child, FALSE);
+               deliveries = DeliverEventsToWindow(pWin, xE, count, filter,
+                                                  grab, mskidx);
+               if (deliveries > 0)
+                   return deliveries;
+           }
+           if ((deliveries < 0) ||
+               (pWin == stopAt) ||
+               (inputMasks &&
+                (filter & inputMasks->dontPropagateMask[mskidx])))
+               return 0;
+           child = pWin->drawable.id;
+           pWin = pWin->parent;
+           if (pWin)
+               inputMasks = wOtherInputMasks(pWin);
+       }
+    }
+    else
+    {
+       if (!(filter & pWin->deliverableEvents))
+           return 0;
+       while (pWin)
+       {
+           if ((wOtherEventMasks(pWin)|pWin->eventMask) & filter)
+           {
+               FixUpEventFromWindow(xE, pWin, child, FALSE);
+               deliveries = DeliverEventsToWindow(pWin, xE, count, filter,
+                                                  grab, 0);
+               if (deliveries > 0)
+                   return deliveries;
+           }
+           if ((deliveries < 0) ||
+               (pWin == stopAt) ||
+               (filter & wDontPropagateMask(pWin)))
+               return 0;
+           child = pWin->drawable.id;
+           pWin = pWin->parent;
+       }
+    }
+    return 0;
+}
+
+/* not useful for events that propagate up the tree or extension events */
+int
+DeliverEvents(pWin, xE, count, otherParent)
+    register WindowPtr pWin, otherParent;
+    register xEvent *xE;
+    int count;
+{
+    Mask filter;
+    int     deliveries;
+
+    if (!count)
+       return 0;
+    filter = filters[xE->u.u.type];
+    if ((filter & SubstructureNotifyMask) && (xE->u.u.type != CreateNotify))
+       xE->u.destroyNotify.event = pWin->drawable.id;
+    if (filter != StructureAndSubMask)
+       return DeliverEventsToWindow(pWin, xE, count, filter, NullGrab, 0);
+    deliveries = DeliverEventsToWindow(pWin, xE, count, StructureNotifyMask,
+                                      NullGrab, 0);
+    if (pWin->parent)
+    {
+       xE->u.destroyNotify.event = pWin->parent->drawable.id;
+       deliveries += DeliverEventsToWindow(pWin->parent, xE, count,
+                                           SubstructureNotifyMask, NullGrab,
+                                           0);
+       if (xE->u.u.type == ReparentNotify)
+       {
+           xE->u.destroyNotify.event = otherParent->drawable.id;
+           deliveries += DeliverEventsToWindow(otherParent, xE, count,
+                                               SubstructureNotifyMask,
+                                               NullGrab, 0);
+       }
+    }
+    return deliveries;
+}
+
+static WindowPtr 
+#if NeedFunctionPrototypes
+XYToWindow(int x, int y)
+#else
+XYToWindow(x, y)
+       int x, y;
+#endif
+{
+    register WindowPtr  pWin;
+#ifdef SHAPE
+    BoxRec             box;
+#endif
+
+    spriteTraceGood = 1;       /* root window still there */
+    pWin = ROOT->firstChild;
+    while (pWin)
+    {
+       if ((pWin->mapped) &&
+               (x >= pWin->drawable.x - wBorderWidth (pWin)) &&
+               (x < pWin->drawable.x + (int)pWin->drawable.width +
+                   wBorderWidth(pWin)) &&
+               (y >= pWin->drawable.y - wBorderWidth (pWin)) &&
+               (y < pWin->drawable.y + (int)pWin->drawable.height +
+                   wBorderWidth (pWin))
+#ifdef SHAPE
+               /* When a window is shaped, a further check
+                * is made to see if the point is inside
+                * borderSize
+                */
+               && (!wBoundingShape(pWin) ||
+                   POINT_IN_REGION(pWin->drawable.pScreen, 
+                           &pWin->borderSize, x, y, &box))
+#endif
+               )
+       {
+           if (spriteTraceGood >= spriteTraceSize)
+           {
+               spriteTraceSize += 10;
+               Must_have_memory = TRUE; /* XXX */
+               spriteTrace = (WindowPtr *)xrealloc(
+                   spriteTrace, spriteTraceSize*sizeof(WindowPtr));
+               Must_have_memory = FALSE; /* XXX */
+           }
+           spriteTrace[spriteTraceGood++] = pWin;
+           pWin = pWin->firstChild;
+       }
+       else
+           pWin = pWin->nextSib;
+    }
+    return spriteTrace[spriteTraceGood-1];
+}
+
+static Bool
+#if NeedFunctionPrototypes
+CheckMotion(xEvent *xE)
+#else
+CheckMotion(xE)
+    xEvent *xE;
+#endif
+{
+    WindowPtr prevSpriteWin = sprite.win;
+
+    if (xE && !syncEvents.playingEvents)
+    {
+       if (sprite.hot.pScreen != sprite.hotPhys.pScreen)
+       {
+           sprite.hot.pScreen = sprite.hotPhys.pScreen;
+           ROOT = WindowTable[sprite.hot.pScreen->myNum];
+       }
+       sprite.hot.x = xE->u.keyButtonPointer.rootX;
+       sprite.hot.y = xE->u.keyButtonPointer.rootY;
+       if (sprite.hot.x < sprite.physLimits.x1)
+           sprite.hot.x = sprite.physLimits.x1;
+       else if (sprite.hot.x >= sprite.physLimits.x2)
+           sprite.hot.x = sprite.physLimits.x2 - 1;
+       if (sprite.hot.y < sprite.physLimits.y1)
+           sprite.hot.y = sprite.physLimits.y1;
+       else if (sprite.hot.y >= sprite.physLimits.y2)
+           sprite.hot.y = sprite.physLimits.y2 - 1;
+#ifdef SHAPE
+       if (sprite.hotShape)
+           ConfineToShape(sprite.hotShape, &sprite.hot.x, &sprite.hot.y);
+#endif
+       sprite.hotPhys = sprite.hot;
+       if ((sprite.hotPhys.x != xE->u.keyButtonPointer.rootX) ||
+           (sprite.hotPhys.y != xE->u.keyButtonPointer.rootY))
+           (*sprite.hotPhys.pScreen->SetCursorPosition)(
+               sprite.hotPhys.pScreen,
+               sprite.hotPhys.x, sprite.hotPhys.y, FALSE);
+       xE->u.keyButtonPointer.rootX = sprite.hot.x;
+       xE->u.keyButtonPointer.rootY = sprite.hot.y;
+    }
+
+    sprite.win = XYToWindow(sprite.hot.x, sprite.hot.y);
+#ifdef notyet
+    if (!(sprite.win->deliverableEvents &
+         Motion_Filter(inputInfo.pointer->button))
+       !syncEvents.playingEvents)
+    {
+       /* XXX Do PointerNonInterestBox here */
+    }
+#endif
+    if (sprite.win != prevSpriteWin)
+    {
+       if (prevSpriteWin != NullWindow) {
+           if (!xE)
+               UpdateCurrentTimeIf();
+           DoEnterLeaveEvents(prevSpriteWin, sprite.win, NotifyNormal);
+       }
+       PostNewCursor();
+        return FALSE;
+    }
+    return TRUE;
+}
+
+void
+WindowsRestructured()
+{
+    (void) CheckMotion((xEvent *)NULL);
+}
+
+void
+DefineInitialRootWindow(win)
+    register WindowPtr win;
+{
+    register ScreenPtr pScreen = win->drawable.pScreen;
+
+    sprite.hotPhys.pScreen = pScreen;
+    sprite.hotPhys.x = pScreen->width / 2;
+    sprite.hotPhys.y = pScreen->height / 2;
+    sprite.hot = sprite.hotPhys;
+    sprite.hotLimits.x2 = pScreen->width;
+    sprite.hotLimits.y2 = pScreen->height;
+    sprite.win = win;
+    sprite.current = wCursor (win);
+    spriteTraceGood = 1;
+    ROOT = win;
+    (*pScreen->CursorLimits) (
+       pScreen, sprite.current, &sprite.hotLimits, &sprite.physLimits);
+    sprite.confined = FALSE;
+    (*pScreen->ConstrainCursor) (pScreen, &sprite.physLimits);
+    (*pScreen->SetCursorPosition) (pScreen, sprite.hot.x, sprite.hot.y, FALSE);
+    (*pScreen->DisplayCursor) (pScreen, sprite.current);
+}
+
+/*
+ * This does not take any shortcuts, and even ignores its argument, since
+ * it does not happen very often, and one has to walk up the tree since
+ * this might be a newly instantiated cursor for an intermediate window
+ * between the one the pointer is in and the one that the last cursor was
+ * instantiated from.
+ */
+/*ARGSUSED*/
+void
+WindowHasNewCursor(pWin)
+    WindowPtr pWin;
+{
+    PostNewCursor();
+}
+
+void
+NewCurrentScreen(newScreen, x, y)
+    ScreenPtr newScreen;
+    int x,y;
+{
+    sprite.hotPhys.x = x;
+    sprite.hotPhys.y = y;
+    if (newScreen != sprite.hotPhys.pScreen)
+       ConfineCursorToWindow(WindowTable[newScreen->myNum], TRUE, FALSE);
+}
+
+int
+ProcWarpPointer(client)
+    ClientPtr client;
+{
+    WindowPtr  dest = NULL;
+    int                x, y;
+    ScreenPtr  newScreen;
+
+    REQUEST(xWarpPointerReq);
+
+    REQUEST_SIZE_MATCH(xWarpPointerReq);
+    if (stuff->dstWid != None)
+    {
+       dest = SecurityLookupWindow(stuff->dstWid, client, SecurityReadAccess);
+       if (!dest)
+           return BadWindow;
+    }
+    x = sprite.hotPhys.x;
+    y = sprite.hotPhys.y;
+    if (stuff->srcWid != None)
+    {
+       int     winX, winY;
+        WindowPtr source = SecurityLookupWindow(stuff->srcWid, client,
+                                               SecurityReadAccess);
+       if (!source)
+           return BadWindow;
+       winX = source->drawable.x;
+       winY = source->drawable.y;
+       if (source->drawable.pScreen != sprite.hotPhys.pScreen ||
+           x < winX + stuff->srcX ||
+           y < winY + stuff->srcY ||
+           (stuff->srcWidth != 0 &&
+            winX + stuff->srcX + (int)stuff->srcWidth < x) ||
+           (stuff->srcHeight != 0 &&
+            winY + stuff->srcY + (int)stuff->srcHeight < y) ||
+           !PointInWindowIsVisible(source, x, y))
+           return Success;
+    }
+    if (dest)
+    {
+       x = dest->drawable.x;
+       y = dest->drawable.y;
+       newScreen = dest->drawable.pScreen;
+    }
+    else
+       newScreen = sprite.hotPhys.pScreen;
+    x += stuff->dstX;
+    y += stuff->dstY;
+    if (x < 0)
+       x = 0;
+    else if (x >= newScreen->width)
+       x = newScreen->width - 1;
+    if (y < 0)
+       y = 0;
+    else if (y >= newScreen->height)
+       y = newScreen->height - 1;
+
+    if (newScreen == sprite.hotPhys.pScreen)
+    {
+       if (x < sprite.physLimits.x1)
+           x = sprite.physLimits.x1;
+       else if (x >= sprite.physLimits.x2)
+           x = sprite.physLimits.x2 - 1;
+       if (y < sprite.physLimits.y1)
+           y = sprite.physLimits.y1;
+       else if (y >= sprite.physLimits.y2)
+           y = sprite.physLimits.y2 - 1;
+#ifdef SHAPE
+       if (sprite.hotShape)
+           ConfineToShape(sprite.hotShape, &x, &y);
+#endif
+       (*newScreen->SetCursorPosition)(newScreen, x, y, TRUE);
+    }
+    else if (!PointerConfinedToScreen())
+    {
+       NewCurrentScreen(newScreen, x, y);
+    }
+    return Success;
+}
+
+/* "CheckPassiveGrabsOnWindow" checks to see if the event passed in causes a
+       passive grab set on the window to be activated. */
+
+static Bool
+#if NeedFunctionPrototypes
+CheckPassiveGrabsOnWindow(
+    WindowPtr pWin,
+    register DeviceIntPtr device,
+    register xEvent *xE,
+    int count)
+#else
+CheckPassiveGrabsOnWindow(pWin, device, xE, count)
+    WindowPtr pWin;
+    register DeviceIntPtr device;
+    register xEvent *xE;
+    int count;
+#endif
+{
+    register GrabPtr grab = wPassiveGrabs(pWin);
+    GrabRec tempGrab;
+    register xEvent *dxE;
+
+    if (!grab)
+       return FALSE;
+    tempGrab.window = pWin;
+    tempGrab.device = device;
+    tempGrab.type = xE->u.u.type;
+    tempGrab.detail.exact = xE->u.u.detail;
+    tempGrab.detail.pMask = NULL;
+    tempGrab.modifiersDetail.pMask = NULL;
+    for (; grab; grab = grab->next)
+    {
+#ifdef XKB
+       DeviceIntPtr    gdev;
+       XkbSrvInfoPtr   xkbi;
+
+       gdev= grab->modifierDevice;
+       xkbi= gdev->key->xkbInfo;
+#endif
+       tempGrab.modifierDevice = grab->modifierDevice;
+       if (device == grab->modifierDevice &&
+           (xE->u.u.type == KeyPress
+#ifdef XINPUT
+            || xE->u.u.type == DeviceKeyPress
+#endif
+            ))
+           tempGrab.modifiersDetail.exact =
+#ifdef XKB
+               (noXkbExtension?gdev->key->prev_state:xkbi->state.grab_mods);
+#else
+               grab->modifierDevice->key->prev_state;
+#endif
+       else
+           tempGrab.modifiersDetail.exact =
+#ifdef XKB
+               (noXkbExtension ? gdev->key->state : xkbi->state.grab_mods);
+#else
+               grab->modifierDevice->key->state;
+#endif
+       if (GrabMatchesSecond(&tempGrab, grab) &&
+           (!grab->confineTo ||
+            (grab->confineTo->realized &&
+             REGION_NOTEMPTY( grab->confineTo->drawable.pScreen, 
+               &grab->confineTo->borderSize))))
+       {
+#ifdef XCSECURITY
+           if (!SecurityCheckDeviceAccess(wClient(pWin), device, FALSE))
+               return FALSE;
+#endif
+#ifdef XKB
+           if (!noXkbExtension) {
+               xE->u.keyButtonPointer.state &= 0x1f00;
+               xE->u.keyButtonPointer.state |=
+                               tempGrab.modifiersDetail.exact&(~0x1f00);
+           }
+#endif
+           (*device->ActivateGrab)(device, grab, currentTime, TRUE);
+           FixUpEventFromWindow(xE, grab->window, None, TRUE);
+
+           (void) TryClientEvents(rClient(grab), xE, count,
+                                  filters[xE->u.u.type],
+                                  filters[xE->u.u.type],  grab);
+
+           if (device->sync.state == FROZEN_NO_EVENT)
+           {
+               if (device->sync.evcount < count)
+               {
+                   Must_have_memory = TRUE; /* XXX */
+                   device->sync.event = (xEvent *)xrealloc(device->sync.event,
+                                                           count*
+                                                           sizeof(xEvent));
+                   Must_have_memory = FALSE; /* XXX */
+               }
+               device->sync.evcount = count;
+               for (dxE = device->sync.event; --count >= 0; dxE++, xE++)
+                   *dxE = *xE;
+               device->sync.state = FROZEN_WITH_EVENT;
+            }  
+           return TRUE;
+       }
+    }
+    return FALSE;
+}
+
+/*
+"CheckDeviceGrabs" handles both keyboard and pointer events that may cause
+a passive grab to be activated.  If the event is a keyboard event, the
+ancestors of the focus window are traced down and tried to see if they have
+any passive grabs to be activated.  If the focus window itself is reached and
+it's descendants contain they pointer, the ancestors of the window that the
+pointer is in are then traced down starting at the focus window, otherwise no
+grabs are activated.  If the event is a pointer event, the ancestors of the
+window that the pointer is in are traced down starting at the root until
+CheckPassiveGrabs causes a passive grab to activate or all the windows are
+tried. PRH
+*/
+
+Bool
+CheckDeviceGrabs(device, xE, checkFirst, count)
+    register DeviceIntPtr device;
+    register xEvent *xE;
+    int checkFirst;
+    int count;
+{
+    register int i;
+    register WindowPtr pWin;
+    register FocusClassPtr focus = device->focus;
+
+    if ((xE->u.u.type == ButtonPress
+#ifdef XINPUT
+        || xE->u.u.type == DeviceButtonPress
+#endif
+        ) && device->button->buttonsDown != 1)
+       return FALSE;
+
+    i = checkFirst;
+
+    if (focus)
+    {
+       for (; i < focus->traceGood; i++)
+       {
+           pWin = focus->trace[i];
+           if (pWin->optional &&
+               CheckPassiveGrabsOnWindow(pWin, device, xE, count))
+               return TRUE;
+       }
+  
+       if ((focus->win == NoneWin) ||
+           (i >= spriteTraceGood) ||
+           ((i > checkFirst) && (pWin != spriteTrace[i-1])))
+           return FALSE;
+    }
+        
+    for (; i < spriteTraceGood; i++)
+    {
+       pWin = spriteTrace[i];
+       if (pWin->optional &&
+           CheckPassiveGrabsOnWindow(pWin, device, xE, count))
+           return TRUE;
+    }
+
+    return FALSE;
+}
+
+void
+DeliverFocusedEvent(keybd, xE, window, count)
+    xEvent *xE;
+    DeviceIntPtr keybd;
+    WindowPtr window;
+    int count;
+{
+    WindowPtr focus = keybd->focus->win;
+    int mskidx = 0;
+
+    if (focus == FollowKeyboardWin)
+       focus = inputInfo.keyboard->focus->win;
+    if (!focus)
+       return;
+    if (focus == PointerRootWin)
+    {
+       DeliverDeviceEvents(window, xE, NullGrab, NullWindow, keybd, count);
+       return;
+    }
+    if ((focus == window) || IsParent(focus, window))
+    {
+       if (DeliverDeviceEvents(window, xE, NullGrab, focus, keybd, count))
+           return;
+    }
+    /* just deliver it to the focus window */
+    FixUpEventFromWindow(xE, focus, None, FALSE);
+    if (xE->u.u.type & EXTENSION_EVENT_BASE)
+       mskidx = keybd->id;
+    (void)DeliverEventsToWindow(focus, xE, count, filters[xE->u.u.type],
+                               NullGrab, mskidx);
+}
+
+void
+DeliverGrabbedEvent(xE, thisDev, deactivateGrab, count)
+    register xEvent *xE;
+    register DeviceIntPtr thisDev;
+    Bool deactivateGrab;
+    int count;
+{
+    register GrabPtr grab = thisDev->grab;
+    int deliveries = 0;
+    register DeviceIntPtr dev;
+    register xEvent *dxE;
+
+    if (grab->ownerEvents)
+    {
+       WindowPtr focus;
+
+       if (thisDev->focus)
+       {
+           focus = thisDev->focus->win;
+           if (focus == FollowKeyboardWin)
+               focus = inputInfo.keyboard->focus->win;
+       }
+       else
+           focus = PointerRootWin;
+       if (focus == PointerRootWin)
+           deliveries = DeliverDeviceEvents(sprite.win, xE, grab, NullWindow,
+                                            thisDev, count);
+       else if (focus && (focus == sprite.win || IsParent(focus, sprite.win)))
+           deliveries = DeliverDeviceEvents(sprite.win, xE, grab, focus,
+                                            thisDev, count);
+       else if (focus)
+           deliveries = DeliverDeviceEvents(focus, xE, grab, focus,
+                                            thisDev, count);
+    }
+    if (!deliveries)
+    {
+       FixUpEventFromWindow(xE, grab->window, None, TRUE);
+       deliveries = TryClientEvents(rClient(grab), xE, count,
+                                    (Mask)grab->eventMask,
+                                    filters[xE->u.u.type], grab);
+       if (deliveries && (xE->u.u.type == MotionNotify
+#ifdef XINPUT
+                          || xE->u.u.type == DeviceMotionNotify
+#endif
+                          ))
+           thisDev->valuator->motionHintWindow = grab->window;
+    }
+    if (deliveries && !deactivateGrab && (xE->u.u.type != MotionNotify
+#ifdef XINPUT
+                                         && xE->u.u.type != DeviceMotionNotify
+#endif
+                                         ))
+       switch (thisDev->sync.state)
+       {
+       case FREEZE_BOTH_NEXT_EVENT:
+           for (dev = inputInfo.devices; dev; dev = dev->next)
+           {
+               if (dev == thisDev)
+                   continue;
+               FreezeThaw(dev, TRUE);
+               if ((dev->sync.state == FREEZE_BOTH_NEXT_EVENT) &&
+                   (CLIENT_BITS(dev->grab->resource) ==
+                    CLIENT_BITS(thisDev->grab->resource)))
+                   dev->sync.state = FROZEN_NO_EVENT;
+               else
+                   dev->sync.other = thisDev->grab;
+           }
+           /* fall through */
+       case FREEZE_NEXT_EVENT:
+           thisDev->sync.state = FROZEN_WITH_EVENT;
+           FreezeThaw(thisDev, TRUE);
+           if (thisDev->sync.evcount < count)
+           {
+               Must_have_memory = TRUE; /* XXX */
+               thisDev->sync.event = (xEvent *)xrealloc(thisDev->sync.event,
+                                                        count*sizeof(xEvent));
+               Must_have_memory = FALSE; /* XXX */
+           }
+           thisDev->sync.evcount = count;
+           for (dxE = thisDev->sync.event; --count >= 0; dxE++, xE++)
+               *dxE = *xE;
+           break;
+       }
+}
+
+void
+#ifdef XKB
+CoreProcessKeyboardEvent (xE, keybd, count)
+#else
+ProcessKeyboardEvent (xE, keybd, count)
+#endif
+    register xEvent *xE;
+    register DeviceIntPtr keybd;
+    int count;
+{
+    int             key, bit;
+    register BYTE   *kptr;
+    register int    i;
+    register CARD8  modifiers;
+    register CARD16 mask;
+    GrabPtr         grab = keybd->grab;
+    Bool            deactivateGrab = FALSE;
+    register KeyClassPtr keyc = keybd->key;
+
+    if (!syncEvents.playingEvents)
+    {
+       NoticeTime(xE);
+       if (DeviceEventCallback)
+       {
+           DeviceEventInfoRec eventinfo;
+           eventinfo.events = xE;
+           eventinfo.count = count;
+           CallCallbacks(&DeviceEventCallback, (pointer)&eventinfo);
+       }
+    }
+    xE->u.keyButtonPointer.state = (keyc->state |
+                                   inputInfo.pointer->button->state);
+    xE->u.keyButtonPointer.rootX = sprite.hot.x;
+    xE->u.keyButtonPointer.rootY = sprite.hot.y;
+    key = xE->u.u.detail;
+    kptr = &keyc->down[key >> 3];
+    bit = 1 << (key & 7);
+    modifiers = keyc->modifierMap[key];
+#ifdef DEBUG
+    if ((xkbDebugFlags&0x4)&&
+       ((xE->u.u.type==KeyPress)||(xE->u.u.type==KeyRelease))) {
+       ErrorF("CoreProcessKbdEvent: Key %d %s\n",key,
+                       (xE->u.u.type==KeyPress?"down":"up"));
+    }
+#endif
+    switch (xE->u.u.type)
+    {
+       case KeyPress: 
+           if (*kptr & bit) /* allow ddx to generate multiple downs */
+           {   
+               if (!modifiers)
+               {
+                   xE->u.u.type = KeyRelease;
+                   (*keybd->public.processInputProc)(xE, keybd, count);
+                   xE->u.u.type = KeyPress;
+                   /* release can have side effects, don't fall through */
+                   (*keybd->public.processInputProc)(xE, keybd, count);
+               }
+               return;
+           }
+           inputInfo.pointer->valuator->motionHintWindow = NullWindow;
+           *kptr |= bit;
+           keyc->prev_state = keyc->state;
+           for (i = 0, mask = 1; modifiers; i++, mask <<= 1)
+           {
+               if (mask & modifiers)
+               {
+                   /* This key affects modifier "i" */
+                   keyc->modifierKeyCount[i]++;
+                   keyc->state |= mask;
+                   modifiers &= ~mask;
+               }
+           }
+           if (!grab && CheckDeviceGrabs(keybd, xE, 0, count))
+           {
+               keybd->activatingKey = key;
+               return;
+           }
+           break;
+       case KeyRelease: 
+           if (!(*kptr & bit)) /* guard against duplicates */
+               return;
+           inputInfo.pointer->valuator->motionHintWindow = NullWindow;
+           *kptr &= ~bit;
+           keyc->prev_state = keyc->state;
+           for (i = 0, mask = 1; modifiers; i++, mask <<= 1)
+           {
+               if (mask & modifiers) {
+                   /* This key affects modifier "i" */
+                   if (--keyc->modifierKeyCount[i] <= 0) {
+                       keyc->state &= ~mask;
+                       keyc->modifierKeyCount[i] = 0;
+                   }
+                   modifiers &= ~mask;
+               }
+           }
+           if (keybd->fromPassiveGrab && (key == keybd->activatingKey))
+               deactivateGrab = TRUE;
+           break;
+       default: 
+           FatalError("Impossible keyboard event");
+    }
+    if (grab)
+       DeliverGrabbedEvent(xE, keybd, deactivateGrab, count);
+    else
+       DeliverFocusedEvent(keybd, xE, sprite.win, count);
+    if (deactivateGrab)
+        (*keybd->DeactivateGrab)(keybd);
+}
+
+void
+#ifdef XKB
+CoreProcessPointerEvent (xE, mouse, count)
+#else
+ProcessPointerEvent (xE, mouse, count)
+#endif
+    register xEvent            *xE;
+    register DeviceIntPtr      mouse;
+    int                                count;
+{
+    register GrabPtr   grab = mouse->grab;
+    Bool                deactivateGrab = FALSE;
+    register ButtonClassPtr butc = mouse->button;
+#ifdef XKB
+    XkbSrvInfoPtr xkbi= inputInfo.keyboard->key->xkbInfo;
+#endif
+
+    if (!syncEvents.playingEvents)
+       NoticeTime(xE)
+    xE->u.keyButtonPointer.state = (butc->state | (
+#ifdef XKB
+                       (noXkbExtension ?
+                               inputInfo.keyboard->key->state :
+                               xkbi->state.grab_mods)
+#else
+                       inputInfo.keyboard->key->state
+#endif
+                                   ));
+    {
+       NoticeTime(xE);
+       if (DeviceEventCallback)
+       {
+           DeviceEventInfoRec eventinfo;
+           /* see comment in EnqueueEvents regarding the next three lines */
+           if (xE->u.u.type == MotionNotify)
+               xE->u.keyButtonPointer.root =
+                   WindowTable[sprite.hotPhys.pScreen->myNum]->drawable.id;
+           eventinfo.events = xE;
+           eventinfo.count = count;
+           CallCallbacks(&DeviceEventCallback, (pointer)&eventinfo);
+       }
+    }
+    if (xE->u.u.type != MotionNotify)
+    {
+       register int  key;
+       register BYTE *kptr;
+       int           bit;
+
+       xE->u.keyButtonPointer.rootX = sprite.hot.x;
+       xE->u.keyButtonPointer.rootY = sprite.hot.y;
+       key = xE->u.u.detail;
+       kptr = &butc->down[key >> 3];
+       bit = 1 << (key & 7);
+       switch (xE->u.u.type)
+       {
+       case ButtonPress: 
+           mouse->valuator->motionHintWindow = NullWindow;
+           butc->buttonsDown++;
+           butc->motionMask = ButtonMotionMask;
+           *kptr |= bit;
+           xE->u.u.detail = butc->map[key];
+           if (xE->u.u.detail == 0)
+               return;
+           if (xE->u.u.detail <= 5)
+               butc->state |= (Button1Mask >> 1) << xE->u.u.detail;
+           filters[MotionNotify] = Motion_Filter(butc);
+           if (!grab)
+               if (CheckDeviceGrabs(mouse, xE, 0, count))
+                   return;
+           break;
+       case ButtonRelease: 
+           mouse->valuator->motionHintWindow = NullWindow;
+           if (!--butc->buttonsDown)
+               butc->motionMask = 0;
+           *kptr &= ~bit;
+           xE->u.u.detail = butc->map[key];
+           if (xE->u.u.detail == 0)
+               return;
+           if (xE->u.u.detail <= 5)
+               butc->state &= ~((Button1Mask >> 1) << xE->u.u.detail);
+           filters[MotionNotify] = Motion_Filter(butc);
+           if (!butc->state && mouse->fromPassiveGrab)
+               deactivateGrab = TRUE;
+           break;
+       default: 
+           FatalError("bogus pointer event from ddx");
+       }
+    }
+    else if (!CheckMotion(xE))
+       return;
+    if (grab)
+       DeliverGrabbedEvent(xE, mouse, deactivateGrab, count);
+    else
+       DeliverDeviceEvents(sprite.win, xE, NullGrab, NullWindow,
+                           mouse, count);
+    if (deactivateGrab)
+        (*mouse->DeactivateGrab)(mouse);
+}
+
+#define AtMostOneClient \
+       (SubstructureRedirectMask | ResizeRedirectMask | ButtonPressMask)
+
+void
+RecalculateDeliverableEvents(pWin)
+    register WindowPtr pWin;
+{
+    register OtherClients *others;
+    register WindowPtr pChild;
+
+    pChild = pWin;
+    while (1)
+    {
+       if (pChild->optional)
+       {
+           pChild->optional->otherEventMasks = 0;
+           for (others = wOtherClients(pChild); others; others = others->next)
+           {
+               pChild->optional->otherEventMasks |= others->mask;
+           }
+       }
+       pChild->deliverableEvents = pChild->eventMask|
+                                   wOtherEventMasks(pChild);
+       if (pChild->parent)
+           pChild->deliverableEvents |=
+               (pChild->parent->deliverableEvents &
+                ~wDontPropagateMask(pChild) & PropagateMask);
+       if (pChild->firstChild)
+       {
+           pChild = pChild->firstChild;
+           continue;
+       }
+       while (!pChild->nextSib && (pChild != pWin))
+           pChild = pChild->parent;
+       if (pChild == pWin)
+           break;
+       pChild = pChild->nextSib;
+    }
+}
+
+int
+OtherClientGone(value, id)
+    pointer value; /* must conform to DeleteType */
+    XID   id;
+{
+    register OtherClientsPtr other, prev;
+    register WindowPtr pWin = (WindowPtr)value;
+
+    prev = 0;
+    for (other = wOtherClients(pWin); other; other = other->next)
+    {
+       if (other->resource == id)
+       {
+           if (prev)
+               prev->next = other->next;
+           else
+           {
+               if (!(pWin->optional->otherClients = other->next))
+                   CheckWindowOptionalNeed (pWin);
+           }
+           xfree(other);
+           RecalculateDeliverableEvents(pWin);
+           return(Success);
+       }
+       prev = other;
+    }
+    FatalError("client not on event list");
+    /*NOTREACHED*/
+    return -1; /* make compiler happy */
+}
+
+int
+EventSelectForWindow(pWin, client, mask)
+    register WindowPtr pWin;
+    register ClientPtr client;
+    Mask mask;
+{
+    Mask check;
+    OtherClients * others;
+
+    if (mask & ~AllEventMasks)
+    {
+       client->errorValue = mask;
+       return BadValue;
+    }
+    check = (mask & AtMostOneClient);
+    if (check & (pWin->eventMask|wOtherEventMasks(pWin)))
+    {                                 /* It is illegal for two different
+                                         clients to select on any of the
+                                         events for AtMostOneClient. However,
+                                         it is OK, for some client to
+                                         continue selecting on one of those
+                                         events.  */
+       if ((wClient(pWin) != client) && (check & pWin->eventMask))
+           return BadAccess;
+       for (others = wOtherClients (pWin); others; others = others->next)
+       {
+           if (!SameClient(others, client) && (check & others->mask))
+               return BadAccess;
+       }
+    }
+    if (wClient (pWin) == client)
+    {
+       check = pWin->eventMask;
+#if SGIMISC
+       pWin->eventMask =
+           (mask & ~SGIMiscSpecialDestroyMask) | (pWin->eventMask & SGIMiscSpecialDestroyMask);
+#else
+       pWin->eventMask = mask;
+#endif
+    }
+    else
+    {
+       for (others = wOtherClients (pWin); others; others = others->next)
+       {
+           if (SameClient(others, client))
+           {
+               check = others->mask;
+#if SGIMISC
+               mask = (mask & ~SGIMiscSpecialDestroyMask) | (others->mask & SGIMiscSpecialDestroyMask);
+#endif
+               if (mask == 0)
+               {
+                   FreeResource(others->resource, RT_NONE);
+                   return Success;
+               }
+               else
+                   others->mask = mask;
+               goto maskSet;
+           }
+       }
+       check = 0;
+       if (!pWin->optional && !MakeWindowOptional (pWin))
+           return BadAlloc;
+       others = (OtherClients *) xalloc(sizeof(OtherClients));
+       if (!others)
+           return BadAlloc;
+       others->mask = mask;
+       others->resource = FakeClientID(client->index);
+       others->next = pWin->optional->otherClients;
+       pWin->optional->otherClients = others;
+       if (!AddResource(others->resource, RT_OTHERCLIENT, (pointer)pWin))
+           return BadAlloc;
+    }
+maskSet: 
+    if ((inputInfo.pointer->valuator->motionHintWindow == pWin) &&
+       (mask & PointerMotionHintMask) &&
+       !(check & PointerMotionHintMask) &&
+       !inputInfo.pointer->grab)
+       inputInfo.pointer->valuator->motionHintWindow = NullWindow;
+    RecalculateDeliverableEvents(pWin);
+    return Success;
+}
+
+/*ARGSUSED*/
+int
+EventSuppressForWindow(pWin, client, mask, checkOptional)
+    register WindowPtr pWin;
+    register ClientPtr client;
+    Mask mask;
+    Bool *checkOptional;
+{
+    register int i, free;
+
+    if ((mask & ~PropagateMask) && !permitOldBugs)
+    {
+       client->errorValue = mask;
+       return BadValue;
+    }
+    if (pWin->dontPropagate)
+       DontPropagateRefCnts[pWin->dontPropagate]--;
+    if (!mask)
+       i = 0;
+    else
+    {
+       for (i = DNPMCOUNT, free = 0; --i > 0; )
+       {
+           if (!DontPropagateRefCnts[i])
+               free = i;
+           else if (mask == DontPropagateMasks[i])
+               break;
+       }
+       if (!i && free)
+       {
+           i = free;
+           DontPropagateMasks[i] = mask;
+       }
+    }
+    if (i || !mask)
+    {
+       pWin->dontPropagate = i;
+       if (i)
+           DontPropagateRefCnts[i]++;
+       if (pWin->optional)
+       {
+           pWin->optional->dontPropagateMask = mask;
+           *checkOptional = TRUE;
+       }
+    }
+    else
+    {
+       if (!pWin->optional && !MakeWindowOptional (pWin))
+       {
+           if (pWin->dontPropagate)
+               DontPropagateRefCnts[pWin->dontPropagate]++;
+           return BadAlloc;
+       }
+       pWin->dontPropagate = 0;
+        pWin->optional->dontPropagateMask = mask;
+    }
+    RecalculateDeliverableEvents(pWin);
+    return Success;
+}
+
+static WindowPtr 
+#if NeedFunctionPrototypes
+CommonAncestor(
+    register WindowPtr a,
+    register WindowPtr b)
+#else
+CommonAncestor(a, b)
+    register WindowPtr a, b;
+#endif
+{
+    for (b = b->parent; b; b = b->parent)
+       if (IsParent(b, a)) return b;
+    return NullWindow;
+}
+
+static void
+#if NeedFunctionPrototypes
+EnterLeaveEvent(
+    int type,
+    int mode,
+    int detail,
+    register WindowPtr pWin,
+    Window child)
+#else
+EnterLeaveEvent(type, mode, detail, pWin, child)
+    int type, mode, detail;
+    register WindowPtr pWin;
+    Window child;
+#endif
+{
+    xEvent             event;
+    register DeviceIntPtr keybd = inputInfo.keyboard;
+    WindowPtr          focus;
+    register DeviceIntPtr mouse = inputInfo.pointer;
+    register GrabPtr   grab = mouse->grab;
+    Mask               mask;
+
+    if ((pWin == mouse->valuator->motionHintWindow) &&
+       (detail != NotifyInferior))
+       mouse->valuator->motionHintWindow = NullWindow;
+    if (grab)
+    {
+       mask = (pWin == grab->window) ? grab->eventMask : 0;
+       if (grab->ownerEvents)
+           mask |= EventMaskForClient(pWin, rClient(grab));
+    }
+    else
+    {
+       mask = pWin->eventMask | wOtherEventMasks(pWin);
+    }
+    if (mask & filters[type])
+    {
+       event.u.u.type = type;
+       event.u.u.detail = detail;
+       event.u.enterLeave.time = currentTime.milliseconds;
+       event.u.enterLeave.rootX = sprite.hot.x;
+       event.u.enterLeave.rootY = sprite.hot.y;
+       /* Counts on the same initial structure of crossing & button events! */
+       FixUpEventFromWindow(&event, pWin, None, FALSE);
+       /* Enter/Leave events always set child */
+       event.u.enterLeave.child = child;
+       event.u.enterLeave.flags = event.u.keyButtonPointer.sameScreen ?
+                                           ELFlagSameScreen : 0;
+#ifdef XKB
+       if (!noXkbExtension) {
+           event.u.enterLeave.state = mouse->button->state & 0x1f00;
+           event.u.enterLeave.state |= 
+                       XkbGrabStateFromRec(&keybd->key->xkbInfo->state);
+       } else
+#endif
+       event.u.enterLeave.state = keybd->key->state | mouse->button->state;
+       event.u.enterLeave.mode = mode;
+       focus = keybd->focus->win;
+       if ((focus != NoneWin) &&
+           ((pWin == focus) || (focus == PointerRootWin) ||
+            IsParent(focus, pWin)))
+           event.u.enterLeave.flags |= ELFlagFocus;
+       if (grab)
+           (void)TryClientEvents(rClient(grab), &event, 1, mask,
+                                 filters[type], grab);
+       else
+           (void)DeliverEventsToWindow(pWin, &event, 1, filters[type],
+                                       NullGrab, 0);
+    }
+    if ((type == EnterNotify) && (mask & KeymapStateMask))
+    {
+       xKeymapEvent ke;
+
+#ifdef XCSECURITY
+       ClientPtr client = grab ? rClient(grab)
+                               : clients[CLIENT_ID(pWin->drawable.id)];
+       if (!SecurityCheckDeviceAccess(client, keybd, FALSE))
+       {
+           bzero((char *)&ke.map[0], 31);
+       }
+       else
+#endif
+       memmove((char *)&ke.map[0], (char *)&keybd->key->down[1], 31);
+       ke.type = KeymapNotify;
+       if (grab)
+           (void)TryClientEvents(rClient(grab), (xEvent *)&ke, 1, mask,
+                                 KeymapStateMask, grab);
+       else
+           (void)DeliverEventsToWindow(pWin, (xEvent *)&ke, 1,
+                                       KeymapStateMask, NullGrab, 0);
+    }
+}
+
+static void
+#if NeedFunctionPrototypes
+EnterNotifies(WindowPtr ancestor, WindowPtr child, int mode, int detail)
+#else
+EnterNotifies(ancestor, child, mode, detail)
+    WindowPtr ancestor, child;
+    int mode, detail;
+#endif
+{
+    WindowPtr  parent = child->parent;
+
+    if (ancestor == parent)
+       return;
+    EnterNotifies(ancestor, parent, mode, detail);
+    EnterLeaveEvent(EnterNotify, mode, detail, parent, child->drawable.id);
+}
+
+static void
+#if NeedFunctionPrototypes
+LeaveNotifies(WindowPtr child, WindowPtr ancestor, int mode, int detail)
+#else
+LeaveNotifies(child, ancestor, mode, detail)
+    WindowPtr child, ancestor;
+    int detail, mode;
+#endif
+{
+    register WindowPtr  pWin;
+
+    if (ancestor == child)
+       return;
+    for (pWin = child->parent; pWin != ancestor; pWin = pWin->parent)
+    {
+       EnterLeaveEvent(LeaveNotify, mode, detail, pWin, child->drawable.id);
+       child = pWin;
+    }
+}
+
+static void
+#if NeedFunctionPrototypes
+DoEnterLeaveEvents(WindowPtr fromWin, WindowPtr toWin, int mode)
+#else
+DoEnterLeaveEvents(fromWin, toWin, mode)
+    WindowPtr fromWin, toWin;
+    int mode;
+#endif
+{
+    if (fromWin == toWin)
+       return;
+    if (IsParent(fromWin, toWin))
+    {
+       EnterLeaveEvent(LeaveNotify, mode, NotifyInferior, fromWin, None);
+       EnterNotifies(fromWin, toWin, mode, NotifyVirtual);
+       EnterLeaveEvent(EnterNotify, mode, NotifyAncestor, toWin, None);
+    }
+    else if (IsParent(toWin, fromWin))
+    {
+       EnterLeaveEvent(LeaveNotify, mode, NotifyAncestor, fromWin, None);
+       LeaveNotifies(fromWin, toWin, mode, NotifyVirtual);
+       EnterLeaveEvent(EnterNotify, mode, NotifyInferior, toWin, None);
+    }
+    else
+    { /* neither fromWin nor toWin is descendent of the other */
+       WindowPtr common = CommonAncestor(toWin, fromWin);
+       /* common == NullWindow ==> different screens */
+       EnterLeaveEvent(LeaveNotify, mode, NotifyNonlinear, fromWin, None);
+       LeaveNotifies(fromWin, common, mode, NotifyNonlinearVirtual);
+       EnterNotifies(common, toWin, mode, NotifyNonlinearVirtual);
+       EnterLeaveEvent(EnterNotify, mode, NotifyNonlinear, toWin, None);
+    }
+}
+
+static void
+#if NeedFunctionPrototypes
+FocusEvent(DeviceIntPtr dev, int type, int mode, int detail, register WindowPtr pWin)
+#else
+FocusEvent(dev, type, mode, detail, pWin)
+    DeviceIntPtr dev;
+    int type, mode, detail;
+    register WindowPtr pWin;
+#endif
+{
+    xEvent event;
+
+#ifdef XINPUT
+    if (dev != inputInfo.keyboard)
+    {
+       DeviceFocusEvent(dev, type, mode, detail, pWin);
+       return;
+    }
+#endif
+    event.u.focus.mode = mode;
+    event.u.u.type = type;
+    event.u.u.detail = detail;
+    event.u.focus.window = pWin->drawable.id;
+    (void)DeliverEventsToWindow(pWin, &event, 1, filters[type], NullGrab,
+                               0);
+    if ((type == FocusIn) &&
+       ((pWin->eventMask | wOtherEventMasks(pWin)) & KeymapStateMask))
+    {
+       xKeymapEvent ke;
+#ifdef XCSECURITY
+       ClientPtr client = clients[CLIENT_ID(pWin->drawable.id)];
+       if (!SecurityCheckDeviceAccess(client, dev, FALSE))
+       {
+           bzero((char *)&ke.map[0], 31);
+       }
+       else
+#endif
+       memmove((char *)&ke.map[0], (char *)&dev->key->down[1], 31);
+       ke.type = KeymapNotify;
+       (void)DeliverEventsToWindow(pWin, (xEvent *)&ke, 1,
+                                   KeymapStateMask, NullGrab, 0);
+    }
+}
+
+ /*
+  * recursive because it is easier
+  * no-op if child not descended from ancestor
+  */
+static Bool
+#if NeedFunctionPrototypes
+FocusInEvents(
+    DeviceIntPtr dev,
+    WindowPtr ancestor, WindowPtr child, WindowPtr skipChild,
+    int mode, int detail,
+    Bool doAncestor)
+#else
+FocusInEvents(dev, ancestor, child, skipChild, mode, detail, doAncestor)
+    DeviceIntPtr dev;
+    WindowPtr ancestor, child, skipChild;
+    int mode, detail;
+    Bool doAncestor;
+#endif
+{
+    if (child == NullWindow)
+       return ancestor == NullWindow;
+    if (ancestor == child)
+    {
+       if (doAncestor)
+           FocusEvent(dev, FocusIn, mode, detail, child);
+       return TRUE;
+    }
+    if (FocusInEvents(dev, ancestor, child->parent, skipChild, mode, detail,
+                     doAncestor))
+    {
+       if (child != skipChild)
+           FocusEvent(dev, FocusIn, mode, detail, child);
+       return TRUE;
+    }
+    return FALSE;
+}
+
+/* dies horribly if ancestor is not an ancestor of child */
+static void
+#if NeedFunctionPrototypes
+FocusOutEvents(
+    DeviceIntPtr dev,
+    WindowPtr child, WindowPtr ancestor,
+    int mode, int detail,
+    Bool doAncestor)
+#else
+FocusOutEvents(dev, child, ancestor, mode, detail, doAncestor)
+    DeviceIntPtr dev;
+    WindowPtr child, ancestor;
+    int mode;
+    int detail;
+    Bool doAncestor;
+#endif
+{
+    register WindowPtr  pWin;
+
+    for (pWin = child; pWin != ancestor; pWin = pWin->parent)
+       FocusEvent(dev, FocusOut, mode, detail, pWin);
+    if (doAncestor)
+       FocusEvent(dev, FocusOut, mode, detail, ancestor);
+}
+
+void
+DoFocusEvents(dev, fromWin, toWin, mode)
+    DeviceIntPtr dev;
+    WindowPtr fromWin, toWin;
+    int mode;
+{
+    int     out, in;                  /* for holding details for to/from
+                                         PointerRoot/None */
+    int     i;
+
+    if (fromWin == toWin)
+       return;
+    out = (fromWin == NoneWin) ? NotifyDetailNone : NotifyPointerRoot;
+    in = (toWin == NoneWin) ? NotifyDetailNone : NotifyPointerRoot;
+ /* wrong values if neither, but then not referenced */
+
+    if ((toWin == NullWindow) || (toWin == PointerRootWin))
+    {
+       if ((fromWin == NullWindow) || (fromWin == PointerRootWin))
+       {
+           if (fromWin == PointerRootWin)
+               FocusOutEvents(dev, sprite.win, ROOT, mode, NotifyPointer,
+                              TRUE);
+           /* Notify all the roots */
+           for (i=0; i<screenInfo.numScreens; i++)
+               FocusEvent(dev, FocusOut, mode, out, WindowTable[i]);
+       }
+       else
+       {
+           if (IsParent(fromWin, sprite.win))
+             FocusOutEvents(dev, sprite.win, fromWin, mode, NotifyPointer,
+                            FALSE);
+           FocusEvent(dev, FocusOut, mode, NotifyNonlinear, fromWin);
+           /* next call catches the root too, if the screen changed */
+           FocusOutEvents(dev, fromWin->parent, NullWindow, mode,
+                          NotifyNonlinearVirtual, FALSE);
+       }
+       /* Notify all the roots */
+       for (i=0; i<screenInfo.numScreens; i++)
+           FocusEvent(dev, FocusIn, mode, in, WindowTable[i]);
+       if (toWin == PointerRootWin)
+           (void)FocusInEvents(dev, ROOT, sprite.win, NullWindow, mode,
+                               NotifyPointer, TRUE);
+    }
+    else
+    {
+       if ((fromWin == NullWindow) || (fromWin == PointerRootWin))
+       {
+           if (fromWin == PointerRootWin)
+               FocusOutEvents(dev, sprite.win, ROOT, mode, NotifyPointer,
+                              TRUE);
+           for (i=0; i<screenInfo.numScreens; i++)
+             FocusEvent(dev, FocusOut, mode, out, WindowTable[i]);
+           if (toWin->parent != NullWindow)
+             (void)FocusInEvents(dev, ROOT, toWin, toWin, mode,
+                                 NotifyNonlinearVirtual, TRUE);
+           FocusEvent(dev, FocusIn, mode, NotifyNonlinear, toWin);
+           if (IsParent(toWin, sprite.win))
+              (void)FocusInEvents(dev, toWin, sprite.win, NullWindow, mode,
+                                  NotifyPointer, FALSE);
+       }
+       else
+       {
+           if (IsParent(toWin, fromWin))
+           {
+               FocusEvent(dev, FocusOut, mode, NotifyAncestor, fromWin);
+               FocusOutEvents(dev, fromWin->parent, toWin, mode,
+                              NotifyVirtual, FALSE);
+               FocusEvent(dev, FocusIn, mode, NotifyInferior, toWin);
+               if ((IsParent(toWin, sprite.win)) &&
+                       (sprite.win != fromWin) &&
+                       (!IsParent(fromWin, sprite.win)) &&
+                       (!IsParent(sprite.win, fromWin)))
+                   (void)FocusInEvents(dev, toWin, sprite.win, NullWindow,
+                                       mode, NotifyPointer, FALSE);
+           }
+           else
+               if (IsParent(fromWin, toWin))
+               {
+                   if ((IsParent(fromWin, sprite.win)) &&
+                           (sprite.win != fromWin) &&
+                           (!IsParent(toWin, sprite.win)) &&
+                           (!IsParent(sprite.win, toWin)))
+                       FocusOutEvents(dev, sprite.win, fromWin, mode,
+                                      NotifyPointer, FALSE);
+                   FocusEvent(dev, FocusOut, mode, NotifyInferior, fromWin);
+                   (void)FocusInEvents(dev, fromWin, toWin, toWin, mode,
+                                       NotifyVirtual, FALSE);
+                   FocusEvent(dev, FocusIn, mode, NotifyAncestor, toWin);
+               }
+               else
+               {
+               /* neither fromWin or toWin is child of other */
+                   WindowPtr common = CommonAncestor(toWin, fromWin);
+               /* common == NullWindow ==> different screens */
+                   if (IsParent(fromWin, sprite.win))
+                       FocusOutEvents(dev, sprite.win, fromWin, mode,
+                                      NotifyPointer, FALSE);
+                   FocusEvent(dev, FocusOut, mode, NotifyNonlinear, fromWin);
+                   if (fromWin->parent != NullWindow)
+                     FocusOutEvents(dev, fromWin->parent, common, mode,
+                                    NotifyNonlinearVirtual, FALSE);
+                   if (toWin->parent != NullWindow)
+                     (void)FocusInEvents(dev, common, toWin, toWin, mode,
+                                         NotifyNonlinearVirtual, FALSE);
+                   FocusEvent(dev, FocusIn, mode, NotifyNonlinear, toWin);
+                   if (IsParent(toWin, sprite.win))
+                       (void)FocusInEvents(dev, toWin, sprite.win, NullWindow,
+                                           mode, NotifyPointer, FALSE);
+               }
+       }
+    }
+}
+
+int
+#if NeedFunctionPrototypes
+SetInputFocus(
+    ClientPtr client,
+    DeviceIntPtr dev,
+    Window focusID,
+    CARD8 revertTo,
+    Time ctime,
+    Bool followOK)
+#else
+SetInputFocus(client, dev, focusID, revertTo, ctime, followOK)
+    ClientPtr client;
+    DeviceIntPtr dev;
+    Window focusID;
+    CARD8 revertTo;
+    Time ctime;
+    Bool followOK;
+#endif
+{
+    register FocusClassPtr focus;
+    register WindowPtr focusWin;
+    int mode;
+    TimeStamp time;
+
+    UpdateCurrentTime();
+    if ((revertTo != RevertToParent) &&
+       (revertTo != RevertToPointerRoot) &&
+       (revertTo != RevertToNone) &&
+       ((revertTo != RevertToFollowKeyboard) || !followOK))
+    {
+       client->errorValue = revertTo;
+       return BadValue;
+    }
+    time = ClientTimeToServerTime(ctime);
+    if ((focusID == None) || (focusID == PointerRoot))
+       focusWin = (WindowPtr)focusID;
+    else if ((focusID == FollowKeyboard) && followOK)
+       focusWin = inputInfo.keyboard->focus->win;
+    else if (!(focusWin = SecurityLookupWindow(focusID, client,
+                                              SecurityReadAccess)))
+       return BadWindow;
+    else
+    {
+       /* It is a match error to try to set the input focus to an 
+       unviewable window. */
+
+       if(!focusWin->realized)
+           return(BadMatch);
+    }
+    focus = dev->focus;
+    if ((CompareTimeStamps(time, currentTime) == LATER) ||
+       (CompareTimeStamps(time, focus->time) == EARLIER))
+       return Success;
+    mode = (dev->grab) ? NotifyWhileGrabbed : NotifyNormal;
+    if (focus->win == FollowKeyboardWin)
+       DoFocusEvents(dev, inputInfo.keyboard->focus->win, focusWin, mode);
+    else
+       DoFocusEvents(dev, focus->win, focusWin, mode);
+    focus->time = time;
+    focus->revert = revertTo;
+    if (focusID == FollowKeyboard)
+       focus->win = FollowKeyboardWin;
+    else
+       focus->win = focusWin;
+    if ((focusWin == NoneWin) || (focusWin == PointerRootWin))
+       focus->traceGood = 0;
+    else
+    {
+        int depth = 0;
+       register WindowPtr pWin;
+
+        for (pWin = focusWin; pWin; pWin = pWin->parent) depth++;
+        if (depth > focus->traceSize)
+        {
+           focus->traceSize = depth+1;
+           Must_have_memory = TRUE; /* XXX */
+           focus->trace = (WindowPtr *)xrealloc(focus->trace,
+                                                focus->traceSize *
+                                                sizeof(WindowPtr));
+           Must_have_memory = FALSE; /* XXX */
+       }
+       focus->traceGood = depth;
+        for (pWin = focusWin, depth--; pWin; pWin = pWin->parent, depth--) 
+           focus->trace[depth] = pWin;
+    }
+    return Success;
+}
+
+int
+ProcSetInputFocus(client)
+    ClientPtr client;
+{
+    REQUEST(xSetInputFocusReq);
+
+    REQUEST_SIZE_MATCH(xSetInputFocusReq);
+#ifdef XCSECURITY
+    if (!SecurityCheckDeviceAccess(client, inputInfo.keyboard, TRUE))
+       return Success;
+#endif
+    return SetInputFocus(client, inputInfo.keyboard, stuff->focus,
+                        stuff->revertTo, stuff->time, FALSE);
+}
+
+int
+ProcGetInputFocus(client)
+    ClientPtr client;
+{
+    xGetInputFocusReply rep;
+    FocusClassPtr focus = inputInfo.keyboard->focus;
+
+    REQUEST_SIZE_MATCH(xReq);
+    rep.type = X_Reply;
+    rep.length = 0;
+    rep.sequenceNumber = client->sequence;
+    if (focus->win == NoneWin)
+       rep.focus = None;
+    else if (focus->win == PointerRootWin)
+       rep.focus = PointerRoot;
+    else rep.focus = focus->win->drawable.id;
+    rep.revertTo = focus->revert;
+    WriteReplyToClient(client, sizeof(xGetInputFocusReply), &rep);
+    return Success;
+}
+
+int
+ProcGrabPointer(client)
+    ClientPtr client;
+{
+    xGrabPointerReply rep;
+    DeviceIntPtr device = inputInfo.pointer;
+    GrabPtr grab;
+    WindowPtr pWin, confineTo;
+    CursorPtr cursor, oldCursor;
+    REQUEST(xGrabPointerReq);
+    TimeStamp time;
+
+    REQUEST_SIZE_MATCH(xGrabPointerReq);
+    UpdateCurrentTime();
+    if ((stuff->pointerMode != GrabModeSync) &&
+       (stuff->pointerMode != GrabModeAsync))
+    {
+       client->errorValue = stuff->pointerMode;
+        return BadValue;
+    }
+    if ((stuff->keyboardMode != GrabModeSync) &&
+       (stuff->keyboardMode != GrabModeAsync))
+    {
+       client->errorValue = stuff->keyboardMode;
+        return BadValue;
+    }
+    if ((stuff->ownerEvents != xFalse) && (stuff->ownerEvents != xTrue))
+    {
+       client->errorValue = stuff->ownerEvents;
+        return BadValue;
+    }
+    if ((stuff->eventMask & ~PointerGrabMask) && !permitOldBugs)
+    {
+       client->errorValue = stuff->eventMask;
+        return BadValue;
+    }
+    pWin = SecurityLookupWindow(stuff->grabWindow, client, SecurityReadAccess);
+    if (!pWin)
+       return BadWindow;
+    if (stuff->confineTo == None)
+       confineTo = NullWindow;
+    else
+    {
+       confineTo = SecurityLookupWindow(stuff->confineTo, client,
+                                        SecurityReadAccess);
+       if (!confineTo)
+           return BadWindow;
+    }
+    if (stuff->cursor == None)
+       cursor = NullCursor;
+    else
+    {
+       cursor = (CursorPtr)SecurityLookupIDByType(client, stuff->cursor,
+                                               RT_CURSOR, SecurityReadAccess);
+       if (!cursor)
+       {
+           client->errorValue = stuff->cursor;
+           return BadCursor;
+       }
+    }
+       /* at this point, some sort of reply is guaranteed. */
+    time = ClientTimeToServerTime(stuff->time);
+    rep.type = X_Reply;
+    rep.sequenceNumber = client->sequence;
+    rep.length = 0;
+    grab = device->grab;
+    if ((grab) && !SameClient(grab, client))
+       rep.status = AlreadyGrabbed;
+    else if ((!pWin->realized) ||
+            (confineTo &&
+               !(confineTo->realized &&
+                 REGION_NOTEMPTY( confineTo->drawable.pScreen, 
+                       &confineTo->borderSize))))
+       rep.status = GrabNotViewable;
+    else if (device->sync.frozen &&
+            device->sync.other && !SameClient(device->sync.other, client))
+       rep.status = GrabFrozen;
+    else if ((CompareTimeStamps(time, currentTime) == LATER) ||
+            (CompareTimeStamps(time, device->grabTime) == EARLIER))
+       rep.status = GrabInvalidTime;
+    else
+    {
+       GrabRec tempGrab;
+
+       oldCursor = NullCursor;
+       if (grab)
+       {
+           if (grab->confineTo && !confineTo)
+               ConfineCursorToWindow(ROOT, FALSE, FALSE);
+           oldCursor = grab->cursor;
+       }
+       tempGrab.cursor = cursor;
+       tempGrab.resource = client->clientAsMask;
+       tempGrab.ownerEvents = stuff->ownerEvents;
+       tempGrab.eventMask = stuff->eventMask;
+       tempGrab.confineTo = confineTo;
+       tempGrab.window = pWin;
+       tempGrab.keyboardMode = stuff->keyboardMode;
+       tempGrab.pointerMode = stuff->pointerMode;
+       tempGrab.device = device;
+       (*device->ActivateGrab)(device, &tempGrab, time, FALSE);
+       if (oldCursor)
+           FreeCursor (oldCursor, (Cursor)0);
+       rep.status = GrabSuccess;
+    }
+    WriteReplyToClient(client, sizeof(xGrabPointerReply), &rep);
+    return Success;
+}
+
+int
+ProcChangeActivePointerGrab(client)
+    ClientPtr client;
+{
+    DeviceIntPtr device = inputInfo.pointer;
+    register GrabPtr grab = device->grab;
+    CursorPtr newCursor, oldCursor;
+    REQUEST(xChangeActivePointerGrabReq);
+    TimeStamp time;
+
+    REQUEST_SIZE_MATCH(xChangeActivePointerGrabReq);
+    if ((stuff->eventMask & ~PointerGrabMask) && !permitOldBugs)
+    {
+       client->errorValue = stuff->eventMask;
+        return BadValue;
+    }
+    if (stuff->cursor == None)
+       newCursor = NullCursor;
+    else
+    {
+       newCursor = (CursorPtr)SecurityLookupIDByType(client, stuff->cursor,
+                                               RT_CURSOR, SecurityReadAccess);
+       if (!newCursor)
+       {
+           client->errorValue = stuff->cursor;
+           return BadCursor;
+       }
+    }
+    if (!grab)
+       return Success;
+    if (!SameClient(grab, client))
+       return Success;
+    time = ClientTimeToServerTime(stuff->time);
+    if ((CompareTimeStamps(time, currentTime) == LATER) ||
+            (CompareTimeStamps(time, device->grabTime) == EARLIER))
+       return Success;
+    oldCursor = grab->cursor;
+    grab->cursor = newCursor;
+    if (newCursor)
+       newCursor->refcnt++;
+    PostNewCursor();
+    if (oldCursor)
+       FreeCursor(oldCursor, (Cursor)0);
+    grab->eventMask = stuff->eventMask;
+    return Success;
+}
+
+int
+ProcUngrabPointer(client)
+    ClientPtr client;
+{
+    DeviceIntPtr device = inputInfo.pointer;
+    GrabPtr grab;
+    TimeStamp time;
+    REQUEST(xResourceReq);
+
+    REQUEST_SIZE_MATCH(xResourceReq);
+    UpdateCurrentTime();
+    grab = device->grab;
+    time = ClientTimeToServerTime(stuff->id);
+    if ((CompareTimeStamps(time, currentTime) != LATER) &&
+           (CompareTimeStamps(time, device->grabTime) != EARLIER) &&
+           (grab) && SameClient(grab, client))
+       (*device->DeactivateGrab)(device);
+    return Success;
+}
+
+int
+GrabDevice(client, dev, this_mode, other_mode, grabWindow, ownerEvents, ctime,
+          mask, status)
+    register ClientPtr client;
+    register DeviceIntPtr dev;
+    unsigned this_mode;
+    unsigned other_mode;
+    Window grabWindow;
+    unsigned ownerEvents;
+    Time ctime;
+    Mask mask;
+    CARD8 *status;
+{
+    register WindowPtr pWin;
+    register GrabPtr grab;
+    TimeStamp time;
+
+    UpdateCurrentTime();
+    if ((this_mode != GrabModeSync) && (this_mode != GrabModeAsync))
+    {
+       client->errorValue = this_mode;
+        return BadValue;
+    }
+    if ((other_mode != GrabModeSync) && (other_mode != GrabModeAsync))
+    {
+       client->errorValue = other_mode;
+        return BadValue;
+    }
+    if ((ownerEvents != xFalse) && (ownerEvents != xTrue))
+    {
+       client->errorValue = ownerEvents;
+        return BadValue;
+    }
+    pWin = SecurityLookupWindow(grabWindow, client, SecurityReadAccess);
+    if (!pWin)
+       return BadWindow;
+    time = ClientTimeToServerTime(ctime);
+    grab = dev->grab;
+    if (grab && !SameClient(grab, client))
+       *status = AlreadyGrabbed;
+    else if (!pWin->realized)
+       *status = GrabNotViewable;
+    else if ((CompareTimeStamps(time, currentTime) == LATER) ||
+            (CompareTimeStamps(time, dev->grabTime) == EARLIER))
+       *status = GrabInvalidTime;
+    else if (dev->sync.frozen &&
+            dev->sync.other && !SameClient(dev->sync.other, client))
+       *status = GrabFrozen;
+    else
+    {
+       GrabRec tempGrab;
+
+       tempGrab.window = pWin;
+       tempGrab.resource = client->clientAsMask;
+       tempGrab.ownerEvents = ownerEvents;
+       tempGrab.keyboardMode = this_mode;
+       tempGrab.pointerMode = other_mode;
+       tempGrab.eventMask = mask;
+       tempGrab.device = dev;
+       (*dev->ActivateGrab)(dev, &tempGrab, time, FALSE);
+       *status = GrabSuccess;
+    }
+    return Success;
+}
+
+int
+ProcGrabKeyboard(client)
+    ClientPtr client;
+{
+    xGrabKeyboardReply rep;
+    REQUEST(xGrabKeyboardReq);
+    int result;
+
+    REQUEST_SIZE_MATCH(xGrabKeyboardReq);
+#ifdef XCSECURITY
+    if (!SecurityCheckDeviceAccess(client, inputInfo.keyboard, TRUE))
+    {
+       result = Success;
+       rep.status = AlreadyGrabbed;
+    }
+    else
+#endif
+    result = GrabDevice(client, inputInfo.keyboard, stuff->keyboardMode,
+                       stuff->pointerMode, stuff->grabWindow,
+                       stuff->ownerEvents, stuff->time,
+                       KeyPressMask | KeyReleaseMask, &rep.status);
+    if (result != Success)
+       return result;
+    rep.type = X_Reply;
+    rep.sequenceNumber = client->sequence;
+    rep.length = 0;
+    WriteReplyToClient(client, sizeof(xGrabKeyboardReply), &rep);
+    return Success;
+}
+
+int
+ProcUngrabKeyboard(client)
+    ClientPtr client;
+{
+    DeviceIntPtr device = inputInfo.keyboard;
+    GrabPtr grab;
+    TimeStamp time;
+    REQUEST(xResourceReq);
+
+    REQUEST_SIZE_MATCH(xResourceReq);
+    UpdateCurrentTime();
+    grab = device->grab;
+    time = ClientTimeToServerTime(stuff->id);
+    if ((CompareTimeStamps(time, currentTime) != LATER) &&
+       (CompareTimeStamps(time, device->grabTime) != EARLIER) &&
+       (grab) && SameClient(grab, client))
+       (*device->DeactivateGrab)(device);
+    return Success;
+}
+
+int
+ProcQueryPointer(client)
+    ClientPtr client;
+{
+    xQueryPointerReply rep;
+    WindowPtr pWin, t;
+    REQUEST(xResourceReq);
+    DeviceIntPtr mouse = inputInfo.pointer;
+
+    REQUEST_SIZE_MATCH(xResourceReq);
+    pWin = SecurityLookupWindow(stuff->id, client, SecurityReadAccess);
+    if (!pWin)
+       return BadWindow;
+    if (mouse->valuator->motionHintWindow)
+       MaybeStopHint(mouse, client);
+    rep.type = X_Reply;
+    rep.sequenceNumber = client->sequence;
+    rep.mask = mouse->button->state | inputInfo.keyboard->key->state;
+    rep.length = 0;
+    rep.root = (ROOT)->drawable.id;
+    rep.rootX = sprite.hot.x;
+    rep.rootY = sprite.hot.y;
+    rep.child = None;
+    if (sprite.hot.pScreen == pWin->drawable.pScreen)
+    {
+       rep.sameScreen = xTrue;
+       rep.winX = sprite.hot.x - pWin->drawable.x;
+       rep.winY = sprite.hot.y - pWin->drawable.y;
+       for (t = sprite.win; t; t = t->parent)
+           if (t->parent == pWin)
+           {
+               rep.child = t->drawable.id;
+               break;
+           }
+    }
+    else
+    {
+       rep.sameScreen = xFalse;
+       rep.winX = 0;
+       rep.winY = 0;
+    }
+    WriteReplyToClient(client, sizeof(xQueryPointerReply), &rep);
+
+    return(Success);    
+}
+
+void
+InitEvents()
+{
+    int i;
+
+    sprite.hot.pScreen = sprite.hotPhys.pScreen = (ScreenPtr)NULL;
+    inputInfo.numDevices = 0;
+    inputInfo.devices = (DeviceIntPtr)NULL;
+    inputInfo.off_devices = (DeviceIntPtr)NULL;
+    inputInfo.keyboard = (DeviceIntPtr)NULL;
+    inputInfo.pointer = (DeviceIntPtr)NULL;
+    if (spriteTraceSize == 0)
+    {
+       spriteTraceSize = 32;
+       spriteTrace = (WindowPtr *)xalloc(32*sizeof(WindowPtr));
+       if (!spriteTrace)
+           FatalError("failed to allocate spriteTrace");
+    }
+    spriteTraceGood = 0;
+    lastEventMask = OwnerGrabButtonMask;
+    filters[MotionNotify] = PointerMotionMask;
+    sprite.win = NullWindow;
+    sprite.current = NullCursor;
+    sprite.hotLimits.x1 = 0;
+    sprite.hotLimits.y1 = 0;
+    sprite.hotLimits.x2 = 0;
+    sprite.hotLimits.y2 = 0;
+    sprite.confined = FALSE;
+    syncEvents.replayDev = (DeviceIntPtr)NULL;
+    syncEvents.replayWin = NullWindow;
+    while (syncEvents.pending)
+    {
+       QdEventPtr next = syncEvents.pending->next;
+       xfree(syncEvents.pending);
+       syncEvents.pending = next;
+    }
+    syncEvents.pendtail = &syncEvents.pending;
+    syncEvents.playingEvents = FALSE;
+    syncEvents.time.months = 0;
+    syncEvents.time.milliseconds = 0;  /* hardly matters */
+    currentTime.months = 0;
+    currentTime.milliseconds = GetTimeInMillis();
+    lastDeviceEventTime = currentTime;
+    for (i = 0; i < DNPMCOUNT; i++)
+    {
+       DontPropagateMasks[i] = 0;
+       DontPropagateRefCnts[i] = 0;
+    }
+}
+
+int
+ProcSendEvent(client)
+    ClientPtr client;
+{
+    WindowPtr pWin;
+    WindowPtr effectiveFocus = NullWindow; /* only set if dest==InputFocus */
+    REQUEST(xSendEventReq);
+
+    REQUEST_SIZE_MATCH(xSendEventReq);
+
+    /* The client's event type must be a core event type or one defined by an
+       extension. */
+
+    if ( ! ((stuff->event.u.u.type > X_Reply &&
+            stuff->event.u.u.type < LASTEvent) || 
+           (stuff->event.u.u.type >= EXTENSION_EVENT_BASE &&
+            stuff->event.u.u.type < (unsigned)lastEvent)))
+    {
+       client->errorValue = stuff->event.u.u.type;
+       return BadValue;
+    }
+    if (stuff->event.u.u.type == ClientMessage &&
+       stuff->event.u.u.detail != 8 &&
+       stuff->event.u.u.detail != 16 &&
+       stuff->event.u.u.detail != 32 &&
+       !permitOldBugs)
+    {
+       client->errorValue = stuff->event.u.u.detail;
+       return BadValue;
+    }
+    if ((stuff->eventMask & ~AllEventMasks) && !permitOldBugs)
+    {
+       client->errorValue = stuff->eventMask;
+       return BadValue;
+    }
+
+    if (stuff->destination == PointerWindow)
+       pWin = sprite.win;
+    else if (stuff->destination == InputFocus)
+    {
+       WindowPtr inputFocus = inputInfo.keyboard->focus->win;
+
+       if (inputFocus == NoneWin)
+           return Success;
+
+       /* If the input focus is PointerRootWin, send the event to where
+       the pointer is if possible, then perhaps propogate up to root. */
+       if (inputFocus == PointerRootWin)
+           inputFocus = ROOT;
+
+       if (IsParent(inputFocus, sprite.win))
+       {
+           effectiveFocus = inputFocus;
+           pWin = sprite.win;
+       }
+       else
+           effectiveFocus = pWin = inputFocus;
+    }
+    else
+       pWin = SecurityLookupWindow(stuff->destination, client,
+                                   SecurityReadAccess);
+    if (!pWin)
+       return BadWindow;
+    if ((stuff->propagate != xFalse) && (stuff->propagate != xTrue))
+    {
+       client->errorValue = stuff->propagate;
+       return BadValue;
+    }
+    stuff->event.u.u.type |= 0x80;
+    if (stuff->propagate)
+    {
+       for (;pWin; pWin = pWin->parent)
+       {
+           if (DeliverEventsToWindow(pWin, &stuff->event, 1, stuff->eventMask,
+                                     NullGrab, 0))
+               return Success;
+           if (pWin == effectiveFocus)
+               return Success;
+           stuff->eventMask &= ~wDontPropagateMask(pWin);
+           if (!stuff->eventMask)
+               break;
+       }
+    }
+    else
+       (void)DeliverEventsToWindow(pWin, &stuff->event, 1, stuff->eventMask,
+                                   NullGrab, 0);
+    return Success;
+}
+
+int
+ProcUngrabKey(client)
+    ClientPtr client;
+{
+    REQUEST(xUngrabKeyReq);
+    WindowPtr pWin;
+    GrabRec tempGrab;
+    DeviceIntPtr keybd = inputInfo.keyboard;
+
+    REQUEST_SIZE_MATCH(xUngrabKeyReq);
+    pWin = SecurityLookupWindow(stuff->grabWindow, client, SecurityReadAccess);
+    if (!pWin)
+       return BadWindow;
+    if (((stuff->key > keybd->key->curKeySyms.maxKeyCode) ||
+        (stuff->key < keybd->key->curKeySyms.minKeyCode))
+       && (stuff->key != AnyKey))
+    {
+       client->errorValue = stuff->key;
+        return BadValue;
+    }
+    if ((stuff->modifiers != AnyModifier) &&
+       (stuff->modifiers & ~AllModifiersMask))
+    {
+       client->errorValue = stuff->modifiers;
+       return BadValue;
+    }
+
+    tempGrab.resource = client->clientAsMask;
+    tempGrab.device = keybd;
+    tempGrab.window = pWin;
+    tempGrab.modifiersDetail.exact = stuff->modifiers;
+    tempGrab.modifiersDetail.pMask = NULL;
+    tempGrab.modifierDevice = inputInfo.keyboard;
+    tempGrab.type = KeyPress;
+    tempGrab.detail.exact = stuff->key;
+    tempGrab.detail.pMask = NULL;
+
+    if (!DeletePassiveGrabFromList(&tempGrab))
+       return(BadAlloc);
+    return(Success);
+}
+
+int
+ProcGrabKey(client)
+    ClientPtr client;
+{
+    WindowPtr pWin;
+    REQUEST(xGrabKeyReq);
+    GrabPtr grab;
+    DeviceIntPtr keybd = inputInfo.keyboard;
+
+    REQUEST_SIZE_MATCH(xGrabKeyReq);
+    if ((stuff->ownerEvents != xTrue) && (stuff->ownerEvents != xFalse))
+    {
+       client->errorValue = stuff->ownerEvents;
+       return(BadValue);
+    }
+    if ((stuff->pointerMode != GrabModeSync) &&
+       (stuff->pointerMode != GrabModeAsync))
+    {
+       client->errorValue = stuff->pointerMode;
+        return BadValue;
+    }
+    if ((stuff->keyboardMode != GrabModeSync) &&
+       (stuff->keyboardMode != GrabModeAsync))
+    {
+       client->errorValue = stuff->keyboardMode;
+        return BadValue;
+    }
+    if (((stuff->key > keybd->key->curKeySyms.maxKeyCode) ||
+        (stuff->key < keybd->key->curKeySyms.minKeyCode))
+       && (stuff->key != AnyKey))
+    {
+       client->errorValue = stuff->key;
+        return BadValue;
+    }
+    if ((stuff->modifiers != AnyModifier) &&
+       (stuff->modifiers & ~AllModifiersMask))
+    {
+       client->errorValue = stuff->modifiers;
+       return BadValue;
+    }
+    pWin = SecurityLookupWindow(stuff->grabWindow, client, SecurityReadAccess);
+    if (!pWin)
+       return BadWindow;
+
+    grab = CreateGrab(client->index, keybd, pWin, 
+       (Mask)(KeyPressMask | KeyReleaseMask), (Bool)stuff->ownerEvents,
+       (Bool)stuff->keyboardMode, (Bool)stuff->pointerMode,
+       keybd, stuff->modifiers, KeyPress, stuff->key, NullWindow, NullCursor);
+    if (!grab)
+       return BadAlloc;
+    return AddPassiveGrabToList(grab);
+}
+
+int
+ProcGrabButton(client)
+    ClientPtr client;
+{
+    WindowPtr pWin, confineTo;
+    REQUEST(xGrabButtonReq);
+    CursorPtr cursor;
+    GrabPtr grab;
+
+    REQUEST_SIZE_MATCH(xGrabButtonReq);
+    if ((stuff->pointerMode != GrabModeSync) &&
+       (stuff->pointerMode != GrabModeAsync))
+    {
+       client->errorValue = stuff->pointerMode;
+        return BadValue;
+    }
+    if ((stuff->keyboardMode != GrabModeSync) &&
+       (stuff->keyboardMode != GrabModeAsync))
+    {
+       client->errorValue = stuff->keyboardMode;
+        return BadValue;
+    }
+    if ((stuff->modifiers != AnyModifier) &&
+       (stuff->modifiers & ~AllModifiersMask))
+    {
+       client->errorValue = stuff->modifiers;
+       return BadValue;
+    }
+    if ((stuff->ownerEvents != xFalse) && (stuff->ownerEvents != xTrue))
+    {
+       client->errorValue = stuff->ownerEvents;
+       return BadValue;
+    }
+    if (stuff->eventMask & ~PointerGrabMask)
+    {
+       client->errorValue = stuff->eventMask;
+        return BadValue;
+    }
+    pWin = SecurityLookupWindow(stuff->grabWindow, client, SecurityReadAccess);
+    if (!pWin)
+       return BadWindow;
+    if (stuff->confineTo == None)
+       confineTo = NullWindow;
+    else
+    {
+       confineTo = SecurityLookupWindow(stuff->confineTo, client,
+                                        SecurityReadAccess);
+       if (!confineTo)
+           return BadWindow;
+    }
+    if (stuff->cursor == None)
+       cursor = NullCursor;
+    else
+    {
+       cursor = (CursorPtr)SecurityLookupIDByType(client, stuff->cursor,
+                                               RT_CURSOR, SecurityReadAccess);
+       if (!cursor)
+       {
+           client->errorValue = stuff->cursor;
+           return BadCursor;
+       }
+    }
+
+    grab = CreateGrab(client->index, inputInfo.pointer, pWin, 
+       permitOldBugs ? (Mask)(stuff->eventMask |
+                              ButtonPressMask | ButtonReleaseMask) :
+                       (Mask)stuff->eventMask,
+       (Bool)stuff->ownerEvents, (Bool) stuff->keyboardMode,
+       (Bool)stuff->pointerMode, inputInfo.keyboard, stuff->modifiers,
+       ButtonPress, stuff->button, confineTo, cursor);
+    if (!grab)
+       return BadAlloc;
+    return AddPassiveGrabToList(grab);
+}
+
+int
+ProcUngrabButton(client)
+    ClientPtr client;
+{
+    REQUEST(xUngrabButtonReq);
+    WindowPtr pWin;
+    GrabRec tempGrab;
+
+    REQUEST_SIZE_MATCH(xUngrabButtonReq);
+    if ((stuff->modifiers != AnyModifier) &&
+       (stuff->modifiers & ~AllModifiersMask))
+    {
+       client->errorValue = stuff->modifiers;
+       return BadValue;
+    }
+    pWin = SecurityLookupWindow(stuff->grabWindow, client, SecurityReadAccess);
+    if (!pWin)
+       return BadWindow;
+
+    tempGrab.resource = client->clientAsMask;
+    tempGrab.device = inputInfo.pointer;
+    tempGrab.window = pWin;
+    tempGrab.modifiersDetail.exact = stuff->modifiers;
+    tempGrab.modifiersDetail.pMask = NULL;
+    tempGrab.modifierDevice = inputInfo.keyboard;
+    tempGrab.type = ButtonPress;
+    tempGrab.detail.exact = stuff->button;
+    tempGrab.detail.pMask = NULL;
+
+    if (!DeletePassiveGrabFromList(&tempGrab))
+       return(BadAlloc);
+    return(Success);
+}
+
+void
+DeleteWindowFromAnyEvents(pWin, freeResources)
+    WindowPtr          pWin;
+    Bool               freeResources;
+{
+    WindowPtr          parent;
+    DeviceIntPtr       mouse = inputInfo.pointer;
+    DeviceIntPtr       keybd = inputInfo.keyboard;
+    FocusClassPtr      focus = keybd->focus;
+    OtherClientsPtr    oc;
+    GrabPtr            passive;
+
+
+    /* Deactivate any grabs performed on this window, before making any
+       input focus changes. */
+
+    if (mouse->grab &&
+       ((mouse->grab->window == pWin) || (mouse->grab->confineTo == pWin)))
+       (*mouse->DeactivateGrab)(mouse);
+
+    /* Deactivating a keyboard grab should cause focus events. */
+
+    if (keybd->grab && (keybd->grab->window == pWin))
+       (*keybd->DeactivateGrab)(keybd);
+
+    /* If the focus window is a root window (ie. has no parent) then don't 
+       delete the focus from it. */
+    
+    if ((pWin == focus->win) && (pWin->parent != NullWindow))
+    {
+       int focusEventMode = NotifyNormal;
+
+       /* If a grab is in progress, then alter the mode of focus events. */
+
+       if (keybd->grab)
+           focusEventMode = NotifyWhileGrabbed;
+
+       switch (focus->revert)
+       {
+       case RevertToNone:
+           DoFocusEvents(keybd, pWin, NoneWin, focusEventMode);
+           focus->win = NoneWin;
+           focus->traceGood = 0;
+           break;
+       case RevertToParent:
+           parent = pWin;
+           do
+           {
+               parent = parent->parent;
+               focus->traceGood--;
+           } while (!parent->realized
+/* This would be a good protocol change -- windows being reparented
+   during SaveSet processing would cause the focus to revert to the
+   nearest enclosing window which will survive the death of the exiting
+   client, instead of ending up reverting to a dying window and thence
+   to None
+ */
+#ifdef NOTDEF
+             || clients[CLIENT_ID(parent->drawable.id)]->clientGone
+#endif
+               );
+           DoFocusEvents(keybd, pWin, parent, focusEventMode);
+           focus->win = parent;
+           focus->revert = RevertToNone;
+           break;
+       case RevertToPointerRoot:
+           DoFocusEvents(keybd, pWin, PointerRootWin, focusEventMode);
+           focus->win = PointerRootWin;
+           focus->traceGood = 0;
+           break;
+       }
+    }
+
+    if (mouse->valuator->motionHintWindow == pWin)
+       mouse->valuator->motionHintWindow = NullWindow;
+
+    if (freeResources)
+    {
+       if (pWin->dontPropagate)
+           DontPropagateRefCnts[pWin->dontPropagate]--;
+       while ( (oc = wOtherClients(pWin)) )
+           FreeResource(oc->resource, RT_NONE);
+       while ( (passive = wPassiveGrabs(pWin)) )
+           FreeResource(passive->resource, RT_NONE);
+     }
+#ifdef XINPUT
+    DeleteWindowFromAnyExtEvents(pWin, freeResources);
+#endif
+}
+
+/* Call this whenever some window at or below pWin has changed geometry */
+
+/*ARGSUSED*/
+void
+CheckCursorConfinement(pWin)
+    WindowPtr pWin;
+{
+    GrabPtr grab = inputInfo.pointer->grab;
+    WindowPtr confineTo;
+
+    if (grab && (confineTo = grab->confineTo))
+    {
+       if (!REGION_NOTEMPTY( confineTo->drawable.pScreen, 
+                       &confineTo->borderSize))
+           (*inputInfo.pointer->DeactivateGrab)(inputInfo.pointer);
+       else if ((pWin == confineTo) || IsParent(pWin, confineTo))
+           ConfineCursorToWindow(confineTo, TRUE, TRUE);
+    }
+}
+
+Mask
+EventMaskForClient(pWin, client)
+    WindowPtr          pWin;
+    ClientPtr          client;
+{
+    register OtherClientsPtr   other;
+
+    if (wClient (pWin) == client)
+       return pWin->eventMask;
+    for (other = wOtherClients(pWin); other; other = other->next)
+    {
+       if (SameClient(other, client))
+           return other->mask;
+    }
+    return 0;
+}
+
+int
+ProcRecolorCursor(client)
+    ClientPtr client;
+{
+    CursorPtr pCursor;
+    int                nscr;
+    ScreenPtr  pscr;
+    REQUEST(xRecolorCursorReq);
+
+    REQUEST_SIZE_MATCH(xRecolorCursorReq);
+    pCursor = (CursorPtr)SecurityLookupIDByType(client, stuff->cursor,
+                                       RT_CURSOR, SecurityWriteAccess);
+    if ( !pCursor) 
+    {
+       client->errorValue = stuff->cursor;
+       return (BadCursor);
+    }
+
+    pCursor->foreRed = stuff->foreRed;
+    pCursor->foreGreen = stuff->foreGreen;
+    pCursor->foreBlue = stuff->foreBlue;
+
+    pCursor->backRed = stuff->backRed;
+    pCursor->backGreen = stuff->backGreen;
+    pCursor->backBlue = stuff->backBlue;
+
+    for (nscr = 0; nscr < screenInfo.numScreens; nscr++)
+    {
+       pscr = screenInfo.screens[nscr];
+       ( *pscr->RecolorCursor)(pscr, pCursor,
+                               (pCursor == sprite.current) &&
+                               (pscr == sprite.hotPhys.pScreen));
+    }
+    return (Success);
+}
+
+void
+WriteEventsToClient(pClient, count, events)
+    ClientPtr  pClient;
+    int                count;
+    xEvent     *events;
+{
+    xEvent    eventTo, *eventFrom;
+    int       i;
+
+#ifdef XKB
+    if ((!noXkbExtension)&&(!XkbFilterEvents(pClient, count, events)))
+       return;
+#endif
+
+    if (EventCallback)
+    {
+       EventInfoRec eventinfo;
+       eventinfo.client = pClient;
+       eventinfo.events = events;
+       eventinfo.count = count;
+       CallCallbacks(&EventCallback, (pointer)&eventinfo);
+    }
+    if(pClient->swapped)
+    {
+       for(i = 0; i < count; i++)
+       {
+           eventFrom = &events[i];
+           /* Remember to strip off the leading bit of type in case
+              this event was sent with "SendEvent." */
+           (*EventSwapVector[eventFrom->u.u.type & 0177])
+               (eventFrom, &eventTo);
+           (void)WriteToClient(pClient, sizeof(xEvent), (char *)&eventTo);
+       }
+    }
+    else
+    {
+       (void)WriteToClient(pClient, count * sizeof(xEvent), (char *) events);
+    }
+}
diff --git a/Xserver/programs/Xserver/dix/extension.c b/Xserver/programs/Xserver/dix/extension.c
new file mode 100644 (file)
index 0000000..f6d930a
--- /dev/null
@@ -0,0 +1,473 @@
+/***********************************************************
+
+Copyright (c) 1987  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+
+Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
+
+                        All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and its 
+documentation for any purpose and without fee is hereby granted, 
+provided that the above copyright notice appear in all copies and that
+both that copyright notice and this permission notice appear in 
+supporting documentation, and that the name of Digital not be
+used in advertising or publicity pertaining to distribution of the
+software without specific, written prior permission.  
+
+DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
+ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
+DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
+ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+SOFTWARE.
+
+******************************************************************/
+/* $XConsortium: extension.c /main/36 1996/09/28 11:23:27 rws $ */
+/* $XFree86: xc/programs/Xserver/dix/extension.c,v 3.5 1996/12/23 06:29:44 dawes Exp $ */
+
+#include "X.h"
+#define NEED_EVENTS
+#define NEED_REPLIES
+#include "Xproto.h"
+#include "misc.h"
+#include "dixstruct.h"
+#include "extnsionst.h"
+#include "gcstruct.h"
+#include "scrnintstr.h"
+#include "dispatch.h"
+#ifdef XCSECURITY
+#define _SECURITY_SERVER
+#include "extensions/security.h"
+#endif
+
+#define EXTENSION_BASE  128
+#define EXTENSION_EVENT_BASE  64
+#define LAST_EVENT  128
+#define LAST_ERROR 255
+
+ScreenProcEntry AuxillaryScreenProcs[MAXSCREENS];
+
+static ExtensionEntry **extensions = (ExtensionEntry **)NULL;
+
+int lastEvent = EXTENSION_EVENT_BASE;
+static int lastError = FirstExtensionError;
+static unsigned int NumExtensions = 0;
+
+ExtensionEntry *AddExtension(name, NumEvents, NumErrors, MainProc, 
+                             SwappedMainProc, CloseDownProc, MinorOpcodeProc)
+    char *name;
+    int NumEvents;
+    int NumErrors;
+    int (* MainProc)();
+    int (* SwappedMainProc)();
+    void (* CloseDownProc)();
+    unsigned short (* MinorOpcodeProc)();
+{
+    int i;
+    register ExtensionEntry *ext, **newexts;
+
+    if (!MainProc || !SwappedMainProc || !CloseDownProc || !MinorOpcodeProc)
+        return((ExtensionEntry *) NULL);
+    if ((lastEvent + NumEvents > LAST_EVENT) || 
+               (unsigned)(lastError + NumErrors > LAST_ERROR))
+        return((ExtensionEntry *) NULL);
+
+    ext = (ExtensionEntry *) xalloc(sizeof(ExtensionEntry));
+    if (!ext)
+       return((ExtensionEntry *) NULL);
+    ext->name = (char *)xalloc(strlen(name) + 1);
+    ext->num_aliases = 0;
+    ext->aliases = (char **)NULL;
+    if (!ext->name)
+    {
+       xfree(ext);
+       return((ExtensionEntry *) NULL);
+    }
+    strcpy(ext->name,  name);
+    i = NumExtensions;
+    newexts = (ExtensionEntry **) xrealloc(extensions,
+                                          (i + 1) * sizeof(ExtensionEntry *));
+    if (!newexts)
+    {
+       xfree(ext->name);
+       xfree(ext);
+       return((ExtensionEntry *) NULL);
+    }
+    NumExtensions++;
+    extensions = newexts;
+    extensions[i] = ext;
+    ext->index = i;
+    ext->base = i + EXTENSION_BASE;
+    ext->CloseDown = CloseDownProc;
+    ext->MinorOpcode = MinorOpcodeProc;
+    ProcVector[i + EXTENSION_BASE] = MainProc;
+    SwappedProcVector[i + EXTENSION_BASE] = SwappedMainProc;
+    if (NumEvents)
+    {
+        ext->eventBase = lastEvent;
+       ext->eventLast = lastEvent + NumEvents;
+       lastEvent += NumEvents;
+    }
+    else
+    {
+        ext->eventBase = 0;
+        ext->eventLast = 0;
+    }
+    if (NumErrors)
+    {
+        ext->errorBase = lastError;
+       ext->errorLast = lastError + NumErrors;
+       lastError += NumErrors;
+    }
+    else
+    {
+        ext->errorBase = 0;
+        ext->errorLast = 0;
+    }
+#ifdef XCSECURITY
+    ext->secure = FALSE;
+#endif
+
+#ifdef LBX
+    (void) LbxAddExtension(name, ext->base, ext->eventBase, ext->errorBase);
+#endif
+    return(ext);
+}
+
+Bool AddExtensionAlias(alias, ext)
+    char *alias;
+    ExtensionEntry *ext;
+{
+    char *name;
+    char **aliases;
+
+    aliases = (char **)xrealloc(ext->aliases,
+                               (ext->num_aliases + 1) * sizeof(char *));
+    if (!aliases)
+       return FALSE;
+    ext->aliases = aliases;
+    name = (char *)xalloc(strlen(alias) + 1);
+    if (!name)
+       return FALSE;
+    strcpy(name,  alias);
+    ext->aliases[ext->num_aliases] = name;
+    ext->num_aliases++;
+#ifdef LBX
+    return LbxAddExtensionAlias(ext->index, alias);
+#else
+    return TRUE;
+#endif
+}
+
+static int
+FindExtension(extname, len)
+    char *extname;
+    int len;
+{
+    int i, j;
+
+    for (i=0; i<NumExtensions; i++)
+    {
+       if ((strlen(extensions[i]->name) == len) &&
+           !strncmp(extname, extensions[i]->name, len))
+           break;
+       for (j = extensions[i]->num_aliases; --j >= 0;)
+       {
+           if ((strlen(extensions[i]->aliases[j]) == len) &&
+               !strncmp(extname, extensions[i]->aliases[j], len))
+               break;
+       }
+       if (j >= 0) break;
+    }
+    return ((i == NumExtensions) ? -1 : i);
+}
+
+void
+DeclareExtensionSecurity(extname, secure)
+    char *extname;
+    Bool secure;
+{
+#ifdef XCSECURITY
+    int i = FindExtension(extname, strlen(extname));
+    if (i >= 0)
+    {
+       int majorop = extensions[i]->base;
+       extensions[i]->secure = secure;
+       if (secure)
+       {
+           UntrustedProcVector[majorop] = ProcVector[majorop];
+           SwappedUntrustedProcVector[majorop] = SwappedProcVector[majorop];
+       }
+       else
+       {
+           UntrustedProcVector[majorop]        = ProcBadRequest;
+           SwappedUntrustedProcVector[majorop] = ProcBadRequest;
+       }
+    }
+#endif
+#ifdef LBX
+    LbxDeclareExtensionSecurity(extname, secure);
+#endif
+}
+
+unsigned short
+StandardMinorOpcode(client)
+    ClientPtr client;
+{
+    return ((xReq *)client->requestBuffer)->data;
+}
+
+unsigned short
+MinorOpcodeOfRequest(client)
+    ClientPtr client;
+{
+    unsigned char major;
+
+    major = ((xReq *)client->requestBuffer)->reqType;
+    if (major < EXTENSION_BASE)
+       return 0;
+    major -= EXTENSION_BASE;
+    if (major >= NumExtensions)
+       return 0;
+    return (*extensions[major]->MinorOpcode)(client);
+}
+
+void
+CloseDownExtensions()
+{
+    register int i,j;
+
+#ifdef LBX
+    LbxCloseDownExtensions();
+#endif
+
+    for (i = NumExtensions - 1; i >= 0; i--)
+    {
+       (* extensions[i]->CloseDown)(extensions[i]);
+       NumExtensions = i;
+       xfree(extensions[i]->name);
+       for (j = extensions[i]->num_aliases; --j >= 0;)
+           xfree(extensions[i]->aliases[j]);
+       xfree(extensions[i]->aliases);
+       xfree(extensions[i]);
+    }
+    xfree(extensions);
+    extensions = (ExtensionEntry **)NULL;
+    lastEvent = EXTENSION_EVENT_BASE;
+    lastError = FirstExtensionError;
+    for (i=0; i<MAXSCREENS; i++)
+    {
+       register ScreenProcEntry *spentry = &AuxillaryScreenProcs[i];
+
+       while (spentry->num)
+       {
+           spentry->num--;
+           xfree(spentry->procList[spentry->num].name);
+       }
+       xfree(spentry->procList);
+       spentry->procList = (ProcEntryPtr)NULL;
+    }
+}
+
+
+int
+ProcQueryExtension(client)
+    ClientPtr client;
+{
+    xQueryExtensionReply reply;
+    int i;
+    REQUEST(xQueryExtensionReq);
+
+    REQUEST_FIXED_SIZE(xQueryExtensionReq, stuff->nbytes);
+    
+    reply.type = X_Reply;
+    reply.length = 0;
+    reply.major_opcode = 0;
+    reply.sequenceNumber = client->sequence;
+
+    if ( ! NumExtensions )
+        reply.present = xFalse;
+    else
+    {
+       i = FindExtension((char *)&stuff[1], stuff->nbytes);
+        if (i < 0
+#ifdef XCSECURITY
+           /* don't show insecure extensions to untrusted clients */
+           || (client->trustLevel == XSecurityClientUntrusted &&
+               !extensions[i]->secure)
+#endif
+           )
+            reply.present = xFalse;
+        else
+        {            
+            reply.present = xTrue;
+           reply.major_opcode = extensions[i]->base;
+           reply.first_event = extensions[i]->eventBase;
+           reply.first_error = extensions[i]->errorBase;
+       }
+    }
+    WriteReplyToClient(client, sizeof(xQueryExtensionReply), &reply);
+    return(client->noClientException);
+}
+
+int
+ProcListExtensions(client)
+    ClientPtr client;
+{
+    xListExtensionsReply reply;
+    char *bufptr, *buffer;
+    int total_length = 0;
+
+    REQUEST_SIZE_MATCH(xReq);
+
+    reply.type = X_Reply;
+    reply.nExtensions = 0;
+    reply.length = 0;
+    reply.sequenceNumber = client->sequence;
+    buffer = NULL;
+
+    if ( NumExtensions )
+    {
+        register int i, j;
+
+        for (i=0;  i<NumExtensions; i++)
+       {
+#ifdef XCSECURITY
+           /* don't show insecure extensions to untrusted clients */
+           if (client->trustLevel == XSecurityClientUntrusted &&
+               !extensions[i]->secure)
+               continue;
+#endif
+           total_length += strlen(extensions[i]->name) + 1;
+           reply.nExtensions += 1 + extensions[i]->num_aliases;
+           for (j = extensions[i]->num_aliases; --j >= 0;)
+               total_length += strlen(extensions[i]->aliases[j]) + 1;
+       }
+        reply.length = (total_length + 3) >> 2;
+       buffer = bufptr = (char *)ALLOCATE_LOCAL(total_length);
+       if (!buffer)
+           return(BadAlloc);
+        for (i=0;  i<NumExtensions; i++)
+        {
+           int len;
+#ifdef XCSECURITY
+           if (client->trustLevel == XSecurityClientUntrusted &&
+               !extensions[i]->secure)
+               continue;
+#endif
+            *bufptr++ = len = strlen(extensions[i]->name);
+           memmove(bufptr, extensions[i]->name,  len);
+           bufptr += len;
+           for (j = extensions[i]->num_aliases; --j >= 0;)
+           {
+               *bufptr++ = len = strlen(extensions[i]->aliases[j]);
+               memmove(bufptr, extensions[i]->aliases[j],  len);
+               bufptr += len;
+           }
+       }
+    }
+    WriteReplyToClient(client, sizeof(xListExtensionsReply), &reply);
+    if (reply.length)
+    {
+        WriteToClient(client, total_length, buffer);
+       DEALLOCATE_LOCAL(buffer);
+    }
+    return(client->noClientException);
+}
+
+
+ExtensionLookupProc 
+LookupProc(name, pGC)
+    char *name;
+    GCPtr pGC;
+{
+    register int i;
+    register ScreenProcEntry *spentry;
+    spentry  = &AuxillaryScreenProcs[pGC->pScreen->myNum];
+    if (spentry->num)    
+    {
+        for (i = 0; i < spentry->num; i++)
+            if (strcmp(name, spentry->procList[i].name) == 0)
+                return(spentry->procList[i].proc);
+    }
+    return (ExtensionLookupProc)NULL;
+}
+
+Bool
+RegisterProc(name, pGC, proc)
+    char *name;
+    GC *pGC;
+    ExtensionLookupProc proc;
+{
+    return RegisterScreenProc(name, pGC->pScreen, proc);
+}
+
+Bool
+RegisterScreenProc(name, pScreen, proc)
+    char *name;
+    ScreenPtr pScreen;
+    ExtensionLookupProc proc;
+{
+    register ScreenProcEntry *spentry;
+    register ProcEntryPtr procEntry = (ProcEntryPtr)NULL;
+    char *newname;
+    int i;
+
+    spentry = &AuxillaryScreenProcs[pScreen->myNum];
+    /* first replace duplicates */
+    if (spentry->num)
+    {
+        for (i = 0; i < spentry->num; i++)
+            if (strcmp(name, spentry->procList[i].name) == 0)
+           {
+                procEntry = &spentry->procList[i];
+               break;
+           }
+    }
+    if (procEntry)
+        procEntry->proc = proc;
+    else
+    {
+       newname = (char *)xalloc(strlen(name)+1);
+       if (!newname)
+           return FALSE;
+       procEntry = (ProcEntryPtr)
+                           xrealloc(spentry->procList,
+                                    sizeof(ProcEntryRec) * (spentry->num+1));
+       if (!procEntry)
+       {
+           xfree(newname);
+           return FALSE;
+       }
+       spentry->procList = procEntry;
+        procEntry += spentry->num;
+        procEntry->name = newname;
+        strcpy(newname, name);
+        procEntry->proc = proc;
+        spentry->num++;        
+    }
+    return TRUE;
+}
diff --git a/Xserver/programs/Xserver/dix/ffs.c b/Xserver/programs/Xserver/dix/ffs.c
new file mode 100644 (file)
index 0000000..49e28a2
--- /dev/null
@@ -0,0 +1,39 @@
+/* $XConsortium: ffs.c /main/1 1996/12/02 10:20:11 lehors $ */
+/*
+
+Copyright (C) 1996 X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a
+copy of this software and associated documentation files (the "Soft-
+ware"), to deal in the Software without restriction, including without
+limitation the rights to use, copy, modify, merge, publish, distribute,
+sublicense, and/or sell copies of the Software, and to permit persons to
+whom the Software is furnished to do so, subject to the following condi-
+tions:
+
+The above copyright notice and this permission notice shall be included
+in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL-
+ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT
+SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABIL-
+ITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall
+not be used in advertising or otherwise to promote the sale, use or
+other dealings in this Software without prior written authorization from
+the X Consortium.
+
+*/
+
+int
+ffs(int i)
+{
+    int j;
+    for (j = 1; (i & 1) == 0; j++)
+       i >>= 1;
+    return j;
+}
diff --git a/Xserver/programs/Xserver/dix/gc.c b/Xserver/programs/Xserver/dix/gc.c
new file mode 100644 (file)
index 0000000..00a565f
--- /dev/null
@@ -0,0 +1,1335 @@
+/***********************************************************
+
+Copyright (c) 1987  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+
+Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
+
+                        All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and its 
+documentation for any purpose and without fee is hereby granted, 
+provided that the above copyright notice appear in all copies and that
+both that copyright notice and this permission notice appear in 
+supporting documentation, and that the name of Digital not be
+used in advertising or publicity pertaining to distribution of the
+software without specific, written prior permission.  
+
+DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
+ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
+DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
+ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+SOFTWARE.
+
+******************************************************************/
+
+/* $XConsortium: gc.c /main/70 1996/08/01 19:21:09 dpw $ */
+/* $XFree86: xc/programs/Xserver/dix/gc.c,v 3.4 1996/12/23 06:29:45 dawes Exp $ */
+
+#include "X.h"
+#include "Xmd.h"
+#include "Xproto.h"
+#include "misc.h"
+#include "resource.h"
+#include "gcstruct.h"
+#include "pixmapstr.h"
+#include "dixfontstr.h"
+#include "scrnintstr.h"
+#include "region.h"
+
+#include "dix.h"
+#include <assert.h>
+
+extern XID clientErrorValue;
+extern FontPtr defaultFont;
+
+static Bool CreateDefaultTile(
+#if NeedFunctionPrototypes
+    GCPtr /*pGC*/
+#endif
+);
+
+unsigned char DefaultDash[2] = {4, 4};
+
+void
+ValidateGC(pDraw, pGC)
+    DrawablePtr        pDraw;
+    GC         *pGC;
+{
+    (*pGC->funcs->ValidateGC) (pGC, pGC->stateChanges, pDraw);
+    pGC->stateChanges = 0;
+    pGC->serialNumber = pDraw->serialNumber;
+}
+
+
+/* dixChangeGC(client, pGC, mask, pC32, pUnion)
+ * 
+ * This function was created as part of the Security extension
+ * implementation.  The client performing the gc change must be passed so
+ * that access checks can be performed on any tiles, stipples, or fonts
+ * that are specified.  ddxen can call this too; they should normally
+ * pass NullClient for the client since any access checking should have
+ * already been done at a higher level.
+ * 
+ * Since we had to create a new function anyway, we decided to change the
+ * way the list of gc values is passed to eliminate the compiler warnings
+ * caused by the DoChangeGC interface.  You can pass the values via pC32
+ * or pUnion, but not both; one of them must be NULL.  If you don't need
+ * to pass any pointers, you can use either one:
+ * 
+ *     /* example calling dixChangeGC using pC32 parameter
+ *     CARD32 v[2];
+ *     v[0] = foreground;
+ *     v[1] = background;
+ *     dixChangeGC(client, pGC, GCForeground|GCBackground, v, NULL);
+ * 
+ *     /* example calling dixChangeGC using pUnion parameter;
+ *     /* same effect as above
+ *     ChangeGCVal v[2];
+ *     v[0].val = foreground;
+ *     v[1].val = background;
+ *     dixChangeGC(client, pGC, GCForeground|GCBackground, NULL, v);
+ * 
+ * However, if you need to pass a pointer to a pixmap or font, you MUST
+ * use the pUnion parameter.
+ * 
+ *     /* example calling dixChangeGC passing pointers in the value list
+ *     ChangeGCVal v[2];
+ *     v[0].val = FillTiled;
+ *     v[1].ptr = pPixmap; /* pointer to a pixmap
+ *     dixChangeGC(client, pGC, GCFillStyle|GCTile, NULL, v);
+ * 
+ * Note: we could have gotten by with just the pUnion parameter, but on
+ * 64 bit machines that would have forced us to copy the value list that
+ * comes in the ChangeGC request.
+ * 
+ * Ideally, we'd change all the DoChangeGC calls to dixChangeGC, but this
+ * is far too many changes to consider at this time, so we've only
+ * changed the ones that caused compiler warnings.  New code should use
+ * dixChangeGC.
+ * 
+ * dpw
+ */
+
+#define NEXTVAL(_type, _var) { \
+      if (pC32) _var = (_type)*pC32++; \
+      else { \
+       _var = (_type)(pUnion->val); pUnion++; \
+      } \
+    }
+
+#define NEXT_PTR(_type, _var) { \
+    assert(pUnion); _var = (_type)pUnion->ptr; pUnion++; }
+
+int
+dixChangeGC(client, pGC, mask, pC32, pUnion)
+    ClientPtr client;
+    register GC        *pGC;
+    register BITS32    mask;
+    CARD32             *pC32;
+    ChangeGCValPtr     pUnion;
+{
+    register BITS32    index2;
+    register int       error = 0;
+    PixmapPtr          pPixmap;
+    BITS32             maskQ;
+
+    assert( (pC32 && !pUnion) || (!pC32 && pUnion) );
+    pGC->serialNumber |= GC_CHANGE_SERIAL_BIT;
+
+    maskQ = mask;      /* save these for when we walk the GCque */
+    while (mask && !error) 
+    {
+       index2 = (BITS32) lowbit (mask);
+       mask &= ~index2;
+       pGC->stateChanges |= index2;
+       switch (index2)
+       {
+           case GCFunction:
+           {
+               CARD8 newalu;
+               NEXTVAL(CARD8, newalu);
+               if (newalu <= GXset)
+                   pGC->alu = newalu;
+               else
+               {
+                   clientErrorValue = newalu;
+                   error = BadValue;
+               }
+               break;
+           }
+           case GCPlaneMask:
+               NEXTVAL(unsigned long, pGC->planemask);
+               break;
+           case GCForeground:
+               NEXTVAL(unsigned long, pGC->fgPixel);
+               /*
+                * this is for CreateGC
+                */
+               if (!pGC->tileIsPixel && !pGC->tile.pixmap)
+               {
+                   pGC->tileIsPixel = TRUE;
+                   pGC->tile.pixel = pGC->fgPixel;
+               }
+               break;
+           case GCBackground:
+               NEXTVAL(unsigned long, pGC->bgPixel);
+               break;
+           case GCLineWidth:           /* ??? line width is a CARD16 */
+                NEXTVAL(CARD16, pGC->lineWidth);
+               break;
+           case GCLineStyle:
+           {
+               unsigned int newlinestyle;
+               NEXTVAL(unsigned int, newlinestyle);
+               if (newlinestyle <= LineDoubleDash)
+                   pGC->lineStyle = newlinestyle;
+               else
+               {
+                   clientErrorValue = newlinestyle;
+                   error = BadValue;
+               }
+               break;
+           }
+           case GCCapStyle:
+           {
+               unsigned int newcapstyle;
+               NEXTVAL(unsigned int, newcapstyle);
+               if (newcapstyle <= CapProjecting)
+                   pGC->capStyle = newcapstyle;
+               else
+               {
+                   clientErrorValue = newcapstyle;
+                   error = BadValue;
+               }
+               break;
+           }
+           case GCJoinStyle:
+           {
+               unsigned int newjoinstyle;
+               NEXTVAL(unsigned int, newjoinstyle);
+               if (newjoinstyle <= JoinBevel)
+                   pGC->joinStyle = newjoinstyle;
+               else
+               {
+                   clientErrorValue = newjoinstyle;
+                   error = BadValue;
+               }
+               break;
+           }
+           case GCFillStyle:
+           {
+               unsigned int newfillstyle;
+               NEXTVAL(unsigned int, newfillstyle);
+               if (newfillstyle <= FillOpaqueStippled)
+                   pGC->fillStyle = newfillstyle;
+               else
+               {
+                   clientErrorValue = newfillstyle;
+                   error = BadValue;
+               }
+               break;
+           }
+           case GCFillRule:
+           {
+               unsigned int newfillrule;
+               NEXTVAL(unsigned int, newfillrule);
+               if (newfillrule <= WindingRule)
+                   pGC->fillRule = newfillrule;
+               else
+               {
+                   clientErrorValue = newfillrule;
+                   error = BadValue;
+               }
+               break;
+           }
+           case GCTile:
+           {
+               XID newpix = 0;
+               if (pUnion)
+               {
+                   NEXT_PTR(PixmapPtr, pPixmap);
+               }
+               else
+               {
+                   NEXTVAL(XID, newpix);
+                   pPixmap = (PixmapPtr)SecurityLookupIDByType(client,
+                                       newpix, RT_PIXMAP, SecurityReadAccess);
+               }
+               if (pPixmap)
+               {
+                   if ((pPixmap->drawable.depth != pGC->depth) ||
+                       (pPixmap->drawable.pScreen != pGC->pScreen))
+                   {
+                       error = BadMatch;
+                   }
+                   else
+                   {
+                       pPixmap->refcnt++;
+                       if (!pGC->tileIsPixel)
+                           (* pGC->pScreen->DestroyPixmap)(pGC->tile.pixmap);
+                       pGC->tileIsPixel = FALSE;
+                       pGC->tile.pixmap = pPixmap;
+                   }
+               }
+               else
+               {
+                   clientErrorValue = newpix;
+                   error = BadPixmap;
+               }
+               break;
+           }
+           case GCStipple:
+           {
+               XID newstipple = 0;
+               if (pUnion)
+               {
+                   NEXT_PTR(PixmapPtr, pPixmap);
+               }
+               else
+               {
+                   NEXTVAL(XID, newstipple)
+                   pPixmap = (PixmapPtr)SecurityLookupIDByType(client,
+                               newstipple, RT_PIXMAP, SecurityReadAccess);
+               }
+               if (pPixmap)
+               {
+                   if ((pPixmap->drawable.depth != 1) ||
+                       (pPixmap->drawable.pScreen != pGC->pScreen))
+                   {
+                       error = BadMatch;
+                   }
+                   else
+                   {
+                       pPixmap->refcnt++;
+                       if (pGC->stipple)
+                           (* pGC->pScreen->DestroyPixmap)(pGC->stipple);
+                       pGC->stipple = pPixmap;
+                   }
+               }
+               else
+               {
+                   clientErrorValue = newstipple;
+                   error = BadPixmap;
+               }
+               break;
+           }
+           case GCTileStipXOrigin:
+               NEXTVAL(INT16, pGC->patOrg.x);
+               break;
+           case GCTileStipYOrigin:
+               NEXTVAL(INT16, pGC->patOrg.y);
+               break;
+           case GCFont:
+           {
+               FontPtr pFont;
+               XID newfont = 0;
+               if (pUnion)
+               {
+                   NEXT_PTR(FontPtr, pFont);
+               }
+               else
+               {
+                   NEXTVAL(XID, newfont)
+                   pFont = (FontPtr)SecurityLookupIDByType(client, newfont,
+                                               RT_FONT, SecurityReadAccess);
+               }
+               if (pFont)
+               {
+                   pFont->refcnt++;
+                   if (pGC->font)
+                       CloseFont(pGC->font, (Font)0);
+                   pGC->font = pFont;
+                }
+               else
+               {
+                   clientErrorValue = newfont;
+                   error = BadFont;
+               }
+               break;
+           }
+           case GCSubwindowMode:
+           {
+               unsigned int newclipmode;
+               NEXTVAL(unsigned int, newclipmode);
+               if (newclipmode <= IncludeInferiors)
+                   pGC->subWindowMode = newclipmode;
+               else
+               {
+                   clientErrorValue = newclipmode;
+                   error = BadValue;
+               }
+               break;
+           }
+           case GCGraphicsExposures:
+           {
+               unsigned int newge;
+               NEXTVAL(unsigned int, newge);
+               if (newge <= xTrue)
+                   pGC->graphicsExposures = newge;
+               else
+               {
+                   clientErrorValue = newge;
+                   error = BadValue;
+               }
+               break;
+           }
+           case GCClipXOrigin:
+               NEXTVAL(INT16, pGC->clipOrg.x);
+               break;
+           case GCClipYOrigin:
+               NEXTVAL(INT16, pGC->clipOrg.y);
+               break;
+           case GCClipMask:
+           {
+               Pixmap pid;
+               int    clipType;
+
+               if (pUnion)
+               {
+                   NEXT_PTR(PixmapPtr, pPixmap);
+               }
+               else
+               {
+                   NEXTVAL(Pixmap, pid)
+                   if (pid == None)
+                   {
+                       clipType = CT_NONE;
+                       pPixmap = NullPixmap;
+                   }
+                   else
+                       pPixmap = (PixmapPtr)SecurityLookupIDByType(client,
+                                       pid, RT_PIXMAP, SecurityReadAccess);
+               }
+
+               if (pPixmap)
+               {
+                   if ((pPixmap->drawable.depth != 1) ||
+                       (pPixmap->drawable.pScreen != pGC->pScreen))
+                   {
+                       error = BadMatch;
+                   }
+                   else
+                   {
+                       clipType = CT_PIXMAP;
+                       pPixmap->refcnt++;
+                   }
+               }
+               else if (!pUnion && (pid != None))
+               {
+                   clientErrorValue = pid;
+                   error = BadPixmap;
+               }
+               if(error == Success)
+               {
+                   (*pGC->funcs->ChangeClip)(pGC, clipType,
+                                             (pointer)pPixmap, 0);
+               }
+               break;
+           }
+           case GCDashOffset:
+               NEXTVAL(INT16, pGC->dashOffset);
+               break;
+           case GCDashList:
+           {
+               CARD8 newdash;
+               NEXTVAL(CARD8, newdash);
+               if (newdash == 4)
+               {
+                   if (pGC->dash != DefaultDash)
+                   {
+                       xfree(pGC->dash);
+                       pGC->numInDashList = 2;
+                       pGC->dash = DefaultDash;
+                   }
+               }
+               else if (newdash != 0)
+               {
+                   unsigned char *dash;
+
+                   dash = (unsigned char *)xalloc(2 * sizeof(unsigned char));
+                   if (dash)
+                   {
+                       if (pGC->dash != DefaultDash)
+                           xfree(pGC->dash);
+                       pGC->numInDashList = 2;
+                       pGC->dash = dash;
+                       dash[0] = newdash;
+                       dash[1] = newdash;
+                   }
+                   else
+                       error = BadAlloc;
+               }
+               else
+               {
+                  clientErrorValue = newdash;
+                  error = BadValue;
+               }
+               break;
+           }
+           case GCArcMode:
+           {
+               unsigned int newarcmode;
+               NEXTVAL(unsigned int, newarcmode);
+               if (newarcmode <= ArcPieSlice)
+                   pGC->arcMode = newarcmode;
+               else
+               {
+                   clientErrorValue = newarcmode;
+                   error = BadValue;
+               }
+               break;
+           }
+           default:
+               clientErrorValue = maskQ;
+               error = BadValue;
+               break;
+       }
+    } /* end while mask && !error */
+
+    if (pGC->fillStyle == FillTiled && pGC->tileIsPixel)
+    {
+       if (!CreateDefaultTile (pGC))
+       {
+           pGC->fillStyle = FillSolid;
+           error = BadAlloc;
+       }
+    }
+    (*pGC->funcs->ChangeGC)(pGC, maskQ);
+    return error;
+}
+
+#undef NEXTVAL
+#undef NEXT_PTR
+
+/* Publically defined entry to ChangeGC.  Just calls dixChangeGC and tells
+ * it that all of the entries are constants or IDs */
+int
+ChangeGC(pGC, mask, pval)
+    register GC        *pGC;
+    register BITS32    mask;
+    XID                        *pval;
+{
+    return (dixChangeGC(NullClient, pGC, mask, pval, NULL));
+}
+
+/* DoChangeGC(pGC, mask, pval, fPointer)
+   mask is a set of bits indicating which values to change.
+   pval contains an appropriate value for each mask.
+   fPointer is true if the values for tiles, stipples, fonts or clipmasks
+   are pointers instead of IDs.  Note: if you are passing pointers you
+   MUST declare the array of values as type pointer!  Other data types
+   may not be large enough to hold pointers on some machines.  Yes,
+   this means you have to cast to (XID *) when you pass the array to
+   DoChangeGC.  Similarly, if you are not passing pointers (fPointer = 0) you
+   MUST declare the array as type XID (not unsigned long!), or again the wrong
+   size data type may be used.  To avoid this cruftiness, use dixChangeGC
+   above.
+
+   if there is an error, the value is marked as changed 
+   anyway, which is probably wrong, but infrequent.
+
+NOTE:
+       all values sent over the protocol for ChangeGC requests are
+32 bits long
+*/
+int
+DoChangeGC(pGC, mask, pval, fPointer)
+    register GC        *pGC;
+    register BITS32    mask;
+    XID                        *pval;
+    int                        fPointer;
+{
+    if (fPointer)
+    /* XXX might be a problem on 64 bit big-endian servers */
+       dixChangeGC(NullClient, pGC, mask, NULL, (ChangeGCValPtr)pval);
+    else
+       dixChangeGC(NullClient, pGC, mask, pval, NULL);
+}
+
+
+/* CreateGC(pDrawable, mask, pval, pStatus)
+   creates a default GC for the given drawable, using mask to fill
+   in any non-default values.
+   Returns a pointer to the new GC on success, NULL otherwise.
+   returns status of non-default fields in pStatus
+BUG:
+   should check for failure to create default tile
+
+*/
+
+static GCPtr
+#if NeedFunctionPrototypes
+AllocateGC(ScreenPtr pScreen)
+#else
+AllocateGC(pScreen)
+    ScreenPtr pScreen;
+#endif
+{
+    GCPtr pGC;
+    register char *ptr;
+    register DevUnion *ppriv;
+    register unsigned *sizes;
+    register unsigned size;
+    register int i;
+
+    pGC = (GCPtr)xalloc(pScreen->totalGCSize);
+    if (pGC)
+    {
+       ppriv = (DevUnion *)(pGC + 1);
+       pGC->devPrivates = ppriv;
+       sizes = pScreen->GCPrivateSizes;
+       ptr = (char *)(ppriv + pScreen->GCPrivateLen);
+       for (i = pScreen->GCPrivateLen; --i >= 0; ppriv++, sizes++)
+       {
+           if ( (size = *sizes) )
+           {
+               ppriv->ptr = (pointer)ptr;
+               ptr += size;
+           }
+           else
+               ppriv->ptr = (pointer)NULL;
+       }
+    }
+    return pGC;
+}
+
+GCPtr
+CreateGC(pDrawable, mask, pval, pStatus)
+    DrawablePtr        pDrawable;
+    BITS32     mask;
+    XID                *pval;
+    int                *pStatus;
+{
+    register GCPtr pGC;
+
+    pGC = AllocateGC(pDrawable->pScreen);
+    if (!pGC)
+    {
+       *pStatus = BadAlloc;
+       return (GCPtr)NULL;
+    }
+
+    pGC->pScreen = pDrawable->pScreen;
+    pGC->depth = pDrawable->depth;
+    pGC->alu = GXcopy; /* dst <- src */
+    pGC->planemask = ~0;
+    pGC->serialNumber = GC_CHANGE_SERIAL_BIT;
+    pGC->funcs = 0;
+
+    pGC->fgPixel = 0;
+    pGC->bgPixel = 1;
+    pGC->lineWidth = 0;
+    pGC->lineStyle = LineSolid;
+    pGC->capStyle = CapButt;
+    pGC->joinStyle = JoinMiter;
+    pGC->fillStyle = FillSolid;
+    pGC->fillRule = EvenOddRule;
+    pGC->arcMode = ArcPieSlice;
+    if (mask & GCForeground)
+    {
+       /*
+        * magic special case -- ChangeGC checks for this condition
+        * and snags the Foreground value to create a pseudo default-tile
+        */
+       pGC->tileIsPixel = FALSE;
+       pGC->tile.pixmap = NullPixmap;
+    }
+    else
+    {
+       pGC->tileIsPixel = TRUE;
+       pGC->tile.pixel = 0;
+    }
+
+    pGC->patOrg.x = 0;
+    pGC->patOrg.y = 0;
+    pGC->subWindowMode = ClipByChildren;
+    pGC->graphicsExposures = TRUE;
+    pGC->clipOrg.x = 0;
+    pGC->clipOrg.y = 0;
+    pGC->clientClipType = CT_NONE;
+    pGC->clientClip = (pointer)NULL;
+    pGC->numInDashList = 2;
+    pGC->dash = DefaultDash;
+    pGC->dashOffset = 0;
+    pGC->lastWinOrg.x = 0;
+    pGC->lastWinOrg.y = 0;
+
+    /* use the default font and stipple */
+    pGC->font = defaultFont;
+    defaultFont->refcnt++;
+    pGC->stipple = pGC->pScreen->PixmapPerDepth[0];
+    pGC->stipple->refcnt++;
+
+    pGC->stateChanges = (1 << (GCLastBit+1)) - 1;
+    if (!(*pGC->pScreen->CreateGC)(pGC))
+       *pStatus = BadAlloc;
+    else if (mask)
+        *pStatus = ChangeGC(pGC, mask, pval);
+    else
+       *pStatus = Success;
+    if (*pStatus != Success)
+    {
+       if (!pGC->tileIsPixel && !pGC->tile.pixmap)
+           pGC->tileIsPixel = TRUE; /* undo special case */
+       FreeGC(pGC, (XID)0);
+       pGC = (GCPtr)NULL;
+    }
+
+    return (pGC);
+}
+
+static Bool
+CreateDefaultTile (pGC)
+    GCPtr   pGC;
+{
+    XID                tmpval[3];
+    PixmapPtr  pTile;
+    GCPtr      pgcScratch;
+    xRectangle rect;
+    CARD16     w, h;
+
+    w = 1;
+    h = 1;
+    (*pGC->pScreen->QueryBestSize)(TileShape, &w, &h, pGC->pScreen);
+    pTile = (PixmapPtr)
+           (*pGC->pScreen->CreatePixmap)(pGC->pScreen,
+                                         w, h, pGC->depth);
+    pgcScratch = GetScratchGC(pGC->depth, pGC->pScreen);
+    if (!pTile || !pgcScratch)
+    {
+       if (pTile)
+           (*pTile->drawable.pScreen->DestroyPixmap)(pTile);
+       if (pgcScratch)
+           FreeScratchGC(pgcScratch);
+       return FALSE;
+    }
+    tmpval[0] = GXcopy;
+    tmpval[1] = pGC->tile.pixel;
+    tmpval[2] = FillSolid;
+    (void)ChangeGC(pgcScratch, GCFunction | GCForeground | GCFillStyle, 
+                  tmpval);
+    ValidateGC((DrawablePtr)pTile, pgcScratch);
+    rect.x = 0;
+    rect.y = 0;
+    rect.width = w;
+    rect.height = h;
+    (*pgcScratch->ops->PolyFillRect)((DrawablePtr)pTile, pgcScratch, 1, &rect);
+    /* Always remember to free the scratch graphics context after use. */
+    FreeScratchGC(pgcScratch);
+
+    pGC->tileIsPixel = FALSE;
+    pGC->tile.pixmap = pTile;
+    return TRUE;
+}
+
+int
+CopyGC(pgcSrc, pgcDst, mask)
+    register GC                *pgcSrc;
+    register GC                *pgcDst;
+    register BITS32    mask;
+{
+    register BITS32    index2;
+    BITS32             maskQ;
+    int                error = 0;
+
+    if (pgcSrc == pgcDst)
+       return Success;
+    pgcDst->serialNumber |= GC_CHANGE_SERIAL_BIT;
+    pgcDst->stateChanges |= mask;
+    maskQ = mask;
+    while (mask)
+    {
+       index2 = (BITS32) lowbit (mask);
+       mask &= ~index2;
+       switch (index2)
+       {
+           case GCFunction:
+               pgcDst->alu = pgcSrc->alu;
+               break;
+           case GCPlaneMask:
+               pgcDst->planemask = pgcSrc->planemask;
+               break;
+           case GCForeground:
+               pgcDst->fgPixel = pgcSrc->fgPixel;
+               break;
+           case GCBackground:
+               pgcDst->bgPixel = pgcSrc->bgPixel;
+               break;
+           case GCLineWidth:
+               pgcDst->lineWidth = pgcSrc->lineWidth;
+               break;
+           case GCLineStyle:
+               pgcDst->lineStyle = pgcSrc->lineStyle;
+               break;
+           case GCCapStyle:
+               pgcDst->capStyle = pgcSrc->capStyle;
+               break;
+           case GCJoinStyle:
+               pgcDst->joinStyle = pgcSrc->joinStyle;
+               break;
+           case GCFillStyle:
+               pgcDst->fillStyle = pgcSrc->fillStyle;
+               break;
+           case GCFillRule:
+               pgcDst->fillRule = pgcSrc->fillRule;
+               break;
+           case GCTile:
+               {
+                   if (EqualPixUnion(pgcDst->tileIsPixel,
+                                     pgcDst->tile,
+                                     pgcSrc->tileIsPixel,
+                                     pgcSrc->tile))
+                   {
+                       break;
+                   }
+                   if (!pgcDst->tileIsPixel)
+                       (* pgcDst->pScreen->DestroyPixmap)(pgcDst->tile.pixmap);
+                   pgcDst->tileIsPixel = pgcSrc->tileIsPixel;
+                   pgcDst->tile = pgcSrc->tile;
+                   if (!pgcDst->tileIsPixel)
+                      pgcDst->tile.pixmap->refcnt++;
+                   break;
+               }
+           case GCStipple:
+               {
+                   if (pgcDst->stipple == pgcSrc->stipple)
+                       break;
+                   if (pgcDst->stipple)
+                       (* pgcDst->pScreen->DestroyPixmap)(pgcDst->stipple);
+                   pgcDst->stipple = pgcSrc->stipple;
+                   if (pgcDst->stipple)
+                       pgcDst->stipple->refcnt ++;
+                   break;
+               }
+           case GCTileStipXOrigin:
+               pgcDst->patOrg.x = pgcSrc->patOrg.x;
+               break;
+           case GCTileStipYOrigin:
+               pgcDst->patOrg.y = pgcSrc->patOrg.y;
+               break;
+           case GCFont:
+               if (pgcDst->font == pgcSrc->font)
+                   break;
+               if (pgcDst->font)
+                   CloseFont(pgcDst->font, (Font)0);
+               if ((pgcDst->font = pgcSrc->font) != NullFont)
+                   (pgcDst->font)->refcnt++;
+               break;
+           case GCSubwindowMode:
+               pgcDst->subWindowMode = pgcSrc->subWindowMode;
+               break;
+           case GCGraphicsExposures:
+               pgcDst->graphicsExposures = pgcSrc->graphicsExposures;
+               break;
+           case GCClipXOrigin:
+               pgcDst->clipOrg.x = pgcSrc->clipOrg.x;
+               break;
+           case GCClipYOrigin:
+               pgcDst->clipOrg.y = pgcSrc->clipOrg.y;
+               break;
+           case GCClipMask:
+               (* pgcDst->funcs->CopyClip)(pgcDst, pgcSrc);
+               break;
+           case GCDashOffset:
+               pgcDst->dashOffset = pgcSrc->dashOffset;
+               break;
+           case GCDashList:
+               if (pgcSrc->dash == DefaultDash)
+               {
+                   if (pgcDst->dash != DefaultDash)
+                   {
+                       xfree(pgcDst->dash);
+                       pgcDst->numInDashList = pgcSrc->numInDashList;
+                       pgcDst->dash = pgcSrc->dash;
+                   }
+               }
+               else
+               {
+                   unsigned char *dash;
+                   unsigned int i;
+
+                   dash = (unsigned char *)xalloc(pgcSrc->numInDashList *
+                                                  sizeof(unsigned char));
+                   if (dash)
+                   {
+                       if (pgcDst->dash != DefaultDash)
+                           xfree(pgcDst->dash);
+                       pgcDst->numInDashList = pgcSrc->numInDashList;
+                       pgcDst->dash = dash;
+                       for (i=0; i<pgcSrc->numInDashList; i++)
+                           dash[i] = pgcSrc->dash[i];
+                   }
+                   else
+                       error = BadAlloc;
+               }
+               break;
+           case GCArcMode:
+               pgcDst->arcMode = pgcSrc->arcMode;
+               break;
+           default:
+               clientErrorValue = maskQ;
+               error = BadValue;
+               break;
+       }
+    }
+    if (pgcDst->fillStyle == FillTiled && pgcDst->tileIsPixel)
+    {
+       if (!CreateDefaultTile (pgcDst))
+       {
+           pgcDst->fillStyle = FillSolid;
+           error = BadAlloc;
+       }
+    }
+    (*pgcDst->funcs->CopyGC) (pgcSrc, maskQ, pgcDst);
+    return error;
+}
+
+/*****************
+ * FreeGC 
+ *   does the diX part of freeing the characteristics in the GC 
+ ***************/
+
+/*ARGSUSED*/
+int
+FreeGC(value, gid)
+    pointer value; /* must conform to DeleteType */
+    XID gid;
+{
+    GCPtr pGC = (GCPtr)value;
+
+    CloseFont(pGC->font, (Font)0);
+    (* pGC->funcs->DestroyClip)(pGC);
+
+    if (!pGC->tileIsPixel)
+       (* pGC->pScreen->DestroyPixmap)(pGC->tile.pixmap);
+    if (pGC->stipple)
+       (* pGC->pScreen->DestroyPixmap)(pGC->stipple);
+
+    (*pGC->funcs->DestroyGC) (pGC);
+    if (pGC->dash != DefaultDash)
+       xfree(pGC->dash);
+    xfree(pGC);
+    return(Success);
+}
+
+void
+SetGCMask(pGC, selectMask, newDataMask)
+    GCPtr pGC;
+    Mask selectMask;
+    Mask newDataMask;
+{
+    pGC->stateChanges = (~selectMask & pGC->stateChanges) |
+                       (selectMask & newDataMask);
+    if (selectMask & newDataMask)
+        pGC->serialNumber |= GC_CHANGE_SERIAL_BIT;        
+}
+
+
+
+/* CreateScratchGC(pScreen, depth)
+    like CreateGC, but doesn't do the default tile or stipple,
+since we can't create them without already having a GC.  any code
+using the tile or stipple has to set them explicitly anyway,
+since the state of the scratch gc is unknown.  This is OK
+because ChangeGC() has to be able to deal with NULL tiles and
+stipples anyway (in case the CreateGC() call has provided a 
+value for them -- we can't set the default tile until the
+client-supplied attributes are installed, since the fgPixel
+is what fills the default tile.  (maybe this comment should
+go with CreateGC() or ChangeGC().)
+*/
+
+GCPtr
+CreateScratchGC(pScreen, depth)
+    ScreenPtr pScreen;
+    unsigned depth;
+{
+    register GCPtr pGC;
+
+    pGC = AllocateGC(pScreen);
+    if (!pGC)
+       return (GCPtr)NULL;
+
+    pGC->pScreen = pScreen;
+    pGC->depth = depth;
+    pGC->alu = GXcopy; /* dst <- src */
+    pGC->planemask = ~0;
+    pGC->serialNumber = 0;
+
+    pGC->fgPixel = 0;
+    pGC->bgPixel = 1;
+    pGC->lineWidth = 0;
+    pGC->lineStyle = LineSolid;
+    pGC->capStyle = CapButt;
+    pGC->joinStyle = JoinMiter;
+    pGC->fillStyle = FillSolid;
+    pGC->fillRule = EvenOddRule;
+    pGC->arcMode = ArcPieSlice;
+    pGC->font = defaultFont;
+    if ( pGC->font)  /* necessary, because open of default font could fail */
+       pGC->font->refcnt++;
+    pGC->tileIsPixel = TRUE;
+    pGC->tile.pixel = 0;
+    pGC->stipple = NullPixmap;
+    pGC->patOrg.x = 0;
+    pGC->patOrg.y = 0;
+    pGC->subWindowMode = ClipByChildren;
+    pGC->graphicsExposures = TRUE;
+    pGC->clipOrg.x = 0;
+    pGC->clipOrg.y = 0;
+    pGC->clientClipType = CT_NONE;
+    pGC->dashOffset = 0;
+    pGC->numInDashList = 2;
+    pGC->dash = DefaultDash;
+    pGC->lastWinOrg.x = 0;
+    pGC->lastWinOrg.y = 0;
+
+    pGC->stateChanges = (1 << (GCLastBit+1)) - 1;
+    if (!(*pScreen->CreateGC)(pGC))
+    {
+       FreeGC(pGC, (XID)0);
+       pGC = (GCPtr)NULL;
+    }
+    return pGC;
+}
+
+void
+FreeGCperDepth(screenNum)
+    int screenNum;
+{
+    register int i;
+    register ScreenPtr pScreen;
+    GCPtr *ppGC;
+
+    pScreen = screenInfo.screens[screenNum];
+    ppGC = pScreen->GCperDepth;
+
+    for (i = 0; i <= pScreen->numDepths; i++)
+       (void)FreeGC(ppGC[i], (XID)0);
+    pScreen->rgf = ~0L;
+}
+
+
+Bool
+CreateGCperDepth(screenNum)
+    int screenNum;
+{
+    register int i;
+    register ScreenPtr pScreen;
+    DepthPtr pDepth;
+    GCPtr *ppGC;
+
+    pScreen = screenInfo.screens[screenNum];
+    pScreen->rgf = 0;
+    ppGC = pScreen->GCperDepth;
+    /* do depth 1 separately because it's not included in list */
+    if (!(ppGC[0] = CreateScratchGC(pScreen, 1)))
+       return FALSE;
+    ppGC[0]->graphicsExposures = FALSE;
+
+    pDepth = pScreen->allowedDepths;
+    for (i=0; i<pScreen->numDepths; i++, pDepth++)
+    {
+       if (!(ppGC[i+1] = CreateScratchGC(pScreen, pDepth->depth)))
+       {
+           for (; i >= 0; i--)
+               (void)FreeGC(ppGC[i], (XID)0);
+           return FALSE;
+       }
+       ppGC[i+1]->graphicsExposures = FALSE;
+    }
+    return TRUE;
+}
+
+Bool
+CreateDefaultStipple(screenNum)
+    int screenNum;
+{
+    register ScreenPtr pScreen;
+    XID tmpval[3];
+    xRectangle rect;
+    CARD16 w, h;
+    GCPtr pgcScratch;
+
+    pScreen = screenInfo.screens[screenNum];
+
+    w = 16;
+    h = 16;
+    (* pScreen->QueryBestSize)(StippleShape, &w, &h, pScreen);
+    if (!(pScreen->PixmapPerDepth[0] =
+                       (*pScreen->CreatePixmap)(pScreen, w, h, 1)))
+       return FALSE;
+    /* fill stipple with 1 */
+    tmpval[0] = GXcopy; tmpval[1] = 1; tmpval[2] = FillSolid;
+    pgcScratch = GetScratchGC(1, pScreen);
+    if (!pgcScratch)
+    {
+       (*pScreen->DestroyPixmap)(pScreen->PixmapPerDepth[0]);
+       return FALSE;
+    }
+    (void)ChangeGC(pgcScratch, GCFunction|GCForeground|GCFillStyle, tmpval);
+    ValidateGC((DrawablePtr)pScreen->PixmapPerDepth[0], pgcScratch);
+    rect.x = 0;
+    rect.y = 0;
+    rect.width = w;
+    rect.height = h;
+    (*pgcScratch->ops->PolyFillRect)((DrawablePtr)pScreen->PixmapPerDepth[0], 
+                                    pgcScratch, 1, &rect);
+    FreeScratchGC(pgcScratch);
+    return TRUE;
+}
+
+void
+FreeDefaultStipple(screenNum)
+    int screenNum;
+{
+    ScreenPtr pScreen = screenInfo.screens[screenNum];
+    (*pScreen->DestroyPixmap)(pScreen->PixmapPerDepth[0]);
+}
+
+int
+SetDashes(pGC, offset, ndash, pdash)
+register GCPtr pGC;
+unsigned offset;
+register unsigned ndash;
+register unsigned char *pdash;
+{
+    register long i;
+    register unsigned char *p, *indash;
+    BITS32 maskQ = 0;
+
+    i = ndash;
+    p = pdash;
+    while (i--)
+    {
+       if (!*p++)
+       {
+           /* dash segment must be > 0 */
+           clientErrorValue = 0;
+           return BadValue;
+       }
+    }
+
+    if (ndash & 1)
+       p = (unsigned char *)xalloc(2 * ndash * sizeof(unsigned char));
+    else
+       p = (unsigned char *)xalloc(ndash * sizeof(unsigned char));
+    if (!p)
+       return BadAlloc;
+
+    pGC->serialNumber |= GC_CHANGE_SERIAL_BIT;
+    if (offset != pGC->dashOffset)
+    {
+       pGC->dashOffset = offset;
+       pGC->stateChanges |= GCDashOffset;
+       maskQ |= GCDashOffset;
+    }
+
+    if (pGC->dash != DefaultDash)
+       xfree(pGC->dash);
+    pGC->numInDashList = ndash;
+    pGC->dash = p;
+    if (ndash & 1)
+    {
+       pGC->numInDashList += ndash;
+       indash = pdash;
+       i = ndash;
+       while (i--)
+           *p++ = *indash++;
+    }
+    while(ndash--)
+       *p++ = *pdash++;
+    pGC->stateChanges |= GCDashList;
+    maskQ |= GCDashList;
+
+    if (pGC->funcs->ChangeGC)
+       (*pGC->funcs->ChangeGC) (pGC, maskQ);
+    return Success;
+}
+
+int
+VerifyRectOrder(nrects, prects, ordering)
+    int                        nrects;
+    xRectangle         *prects;
+    int                        ordering;
+{
+    register xRectangle        *prectP, *prectN;
+    register int       i;
+
+    switch(ordering)
+    {
+      case Unsorted:
+         return CT_UNSORTED;
+      case YSorted:
+         if(nrects > 1)
+         {
+             for(i = 1, prectP = prects, prectN = prects + 1;
+                 i < nrects;
+                 i++, prectP++, prectN++)
+                 if(prectN->y < prectP->y)
+                     return -1;
+         }
+         return CT_YSORTED;
+      case YXSorted:
+         if(nrects > 1)
+         {
+             for(i = 1, prectP = prects, prectN = prects + 1;
+                 i < nrects;
+                 i++, prectP++, prectN++)
+                 if((prectN->y < prectP->y) ||
+                     ( (prectN->y == prectP->y) &&
+                       (prectN->x < prectP->x) ) )
+                     return -1;
+         }
+         return CT_YXSORTED;
+      case YXBanded:
+         if(nrects > 1)
+         {
+             for(i = 1, prectP = prects, prectN = prects + 1;
+                 i < nrects;
+                 i++, prectP++, prectN++)
+                 if((prectN->y != prectP->y &&
+                     prectN->y < prectP->y + (int) prectP->height) ||
+                    ((prectN->y == prectP->y) &&
+                     (prectN->height != prectP->height ||
+                      prectN->x < prectP->x + (int) prectP->width)))
+                     return -1;
+         }
+         return CT_YXBANDED;
+    }
+    return -1;
+}
+
+int
+SetClipRects(pGC, xOrigin, yOrigin, nrects, prects, ordering)
+    GCPtr              pGC;
+    int                        xOrigin, yOrigin;
+    int                        nrects;
+    xRectangle         *prects;
+    int                        ordering;
+{
+    int                        newct, size;
+    xRectangle                 *prectsNew;
+
+    newct = VerifyRectOrder(nrects, prects, ordering);
+    if (newct < 0)
+       return(BadMatch);
+    size = nrects * sizeof(xRectangle);
+    prectsNew = (xRectangle *) xalloc(size);
+    if (!prectsNew && size)
+       return BadAlloc;
+
+    pGC->serialNumber |= GC_CHANGE_SERIAL_BIT;
+    pGC->clipOrg.x = xOrigin;
+    pGC->stateChanges |= GCClipXOrigin;
+                
+    pGC->clipOrg.y = yOrigin;
+    pGC->stateChanges |= GCClipYOrigin;
+
+    if (size)
+       memmove((char *)prectsNew, (char *)prects, size);
+    (*pGC->funcs->ChangeClip)(pGC, newct, (pointer)prectsNew, nrects);
+    if (pGC->funcs->ChangeGC)
+       (*pGC->funcs->ChangeGC) (pGC, GCClipXOrigin|GCClipYOrigin|GCClipMask);
+    return Success;
+}
+
+
+/*
+   sets reasonable defaults 
+   if we can get a pre-allocated one, use it and mark it as used.
+   if we can't, create one out of whole cloth (The Velveteen GC -- if
+   you use it often enough it will become real.)
+*/
+GCPtr
+GetScratchGC(depth, pScreen)
+    register unsigned depth;
+    register ScreenPtr pScreen;
+{
+    register int i;
+    register GCPtr pGC;
+
+    for (i=0; i<=pScreen->numDepths; i++)
+        if ( pScreen->GCperDepth[i]->depth == depth &&
+            !(pScreen->rgf & (1L << (i+1)))
+          )
+       {
+           pScreen->rgf |= (1L << (i+1));
+            pGC = (pScreen->GCperDepth[i]);
+
+           pGC->alu = GXcopy;
+           pGC->planemask = ~0;
+           pGC->serialNumber = 0;
+           pGC->fgPixel = 0;
+           pGC->bgPixel = 1;
+           pGC->lineWidth = 0;
+           pGC->lineStyle = LineSolid;
+           pGC->capStyle = CapButt;
+           pGC->joinStyle = JoinMiter;
+           pGC->fillStyle = FillSolid;
+           pGC->fillRule = EvenOddRule;
+           pGC->arcMode = ArcChord;
+           pGC->patOrg.x = 0;
+           pGC->patOrg.y = 0;
+           pGC->subWindowMode = ClipByChildren;
+           pGC->graphicsExposures = FALSE;
+           pGC->clipOrg.x = 0;
+           pGC->clipOrg.y = 0;
+           if (pGC->clientClipType != CT_NONE)
+               (*pGC->funcs->ChangeClip) (pGC, CT_NONE, NULL, 0);
+           pGC->stateChanges = (1 << (GCLastBit+1)) - 1;
+           return pGC;
+       }
+    /* if we make it this far, need to roll our own */
+    pGC = CreateScratchGC(pScreen, depth);
+    if (pGC)
+       pGC->graphicsExposures = FALSE;
+    return pGC;
+}
+
+/*
+   if the gc to free is in the table of pre-existing ones,
+mark it as available.
+   if not, free it for real
+*/
+void
+FreeScratchGC(pGC)
+    register GCPtr pGC;
+{
+    register ScreenPtr pScreen = pGC->pScreen;
+    register int i;
+
+    for (i=0; i<=pScreen->numDepths; i++)
+    {
+        if ( pScreen->GCperDepth[i] == pGC)
+       {
+           pScreen->rgf &= ~(1L << (i+1));
+           return;
+       }
+    }
+    (void)FreeGC(pGC, (GContext)0);
+}
diff --git a/Xserver/programs/Xserver/dix/globals.c b/Xserver/programs/Xserver/dix/globals.c
new file mode 100644 (file)
index 0000000..fdcc18b
--- /dev/null
@@ -0,0 +1,150 @@
+/************************************************************
+
+Copyright (c) 1987  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+
+Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
+
+                        All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and its 
+documentation for any purpose and without fee is hereby granted, 
+provided that the above copyright notice appear in all copies and that
+both that copyright notice and this permission notice appear in 
+supporting documentation, and that the name of Digital not be
+used in advertising or publicity pertaining to distribution of the
+software without specific, written prior permission.  
+
+DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
+ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
+DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
+ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+SOFTWARE.
+
+********************************************************/
+
+/* $XConsortium: globals.c,v 1.53 94/04/17 20:26:37 rws Exp $ */
+
+
+
+
+
+/* $XFree86: xc/programs/Xserver/dix/globals.c,v 1.2.2.1 1997/06/01 12:33:21 dawes Exp $ */
+
+#include "X.h"
+#include "Xmd.h"
+#include "misc.h"
+#include "windowstr.h"
+#include "scrnintstr.h"
+#include "input.h"
+#include "dixfont.h"
+#include "site.h"
+#include "dixstruct.h"
+#include "os.h"
+
+ScreenInfo screenInfo;
+KeybdCtrl defaultKeyboardControl = {
+       DEFAULT_KEYBOARD_CLICK,
+       DEFAULT_BELL,
+       DEFAULT_BELL_PITCH,
+       DEFAULT_BELL_DURATION,
+       DEFAULT_AUTOREPEAT,
+       DEFAULT_AUTOREPEATS,
+       DEFAULT_LEDS,
+       0};
+
+PtrCtrl defaultPointerControl = {
+       DEFAULT_PTR_NUMERATOR,
+       DEFAULT_PTR_DENOMINATOR,
+       DEFAULT_PTR_THRESHOLD,
+       0};
+
+ClientPtr *clients;
+ClientPtr  serverClient;
+int  currentMaxClients;   /* current size of clients array */
+
+WindowPtr *WindowTable;
+
+unsigned long globalSerialNumber = 0;
+unsigned long serverGeneration = 0;
+
+/* these next four are initialized in main.c */
+CARD32 ScreenSaverTime;
+CARD32 ScreenSaverInterval;
+int  ScreenSaverBlanking;
+int  ScreenSaverAllowExposures;
+
+#ifdef DPMSExtension
+#define DEFAULT_STANDBY_TIME DEFAULT_SCREEN_SAVER_TIME * 2
+#define DEFAULT_SUSPEND_TIME DEFAULT_SCREEN_SAVER_TIME * 3
+#define DEFAULT_OFF_TIME DEFAULT_SCREEN_SAVER_TIME * 4
+CARD32 defaultDPMSStandbyTime = DEFAULT_STANDBY_TIME;
+CARD32 defaultDPMSSuspendTime = DEFAULT_SUSPEND_TIME;
+CARD32 defaultDPMSOffTime = DEFAULT_OFF_TIME;
+CARD16 DPMSPowerLevel = 0;
+Bool defaultDPMSEnabled = FALSE;
+Bool DPMSEnabledSwitch = FALSE;          /* these denote the DPMS command line */
+Bool DPMSDisabledSwitch = FALSE;  /*                      switch states */
+Bool DPMSCapableFlag = FALSE;
+CARD32 DPMSStandbyTime;
+CARD32 DPMSSuspendTime;
+CARD32 DPMSOffTime;
+Bool DPMSEnabled;
+#endif
+
+CARD32 defaultScreenSaverTime = DEFAULT_SCREEN_SAVER_TIME;
+CARD32 defaultScreenSaverInterval = DEFAULT_SCREEN_SAVER_INTERVAL;
+int  defaultScreenSaverBlanking = DEFAULT_SCREEN_SAVER_BLANKING;
+int  defaultScreenSaverAllowExposures = DEFAULT_SCREEN_SAVER_EXPOSURES;
+#ifndef NOLOGOHACK
+int  logoScreenSaver = DEFAULT_LOGO_SCREEN_SAVER;
+#endif
+
+char *defaultFontPath = COMPILEDDEFAULTFONTPATH;
+char *defaultTextFont = COMPILEDDEFAULTFONT;
+char *defaultCursorFont = COMPILEDCURSORFONT;
+char *rgbPath = RGB_DB;
+char *defaultDisplayClass = COMPILEDDISPLAYCLASS;
+FontPtr defaultFont;   /* not declared in dix.h to avoid including font.h in
+                       every compilation of dix code */
+CursorPtr rootCursor;
+ClientPtr requestingClient;    /* XXX this should be obsolete now, remove? */
+
+TimeStamp currentTime;
+TimeStamp lastDeviceEventTime;
+
+Bool permitOldBugs = FALSE; /* turn off some error checking, to permit certain
+                            * old broken clients (like R2/R3 xterms) to work
+                            */
+
+int defaultColorVisualClass = -1;
+int monitorResolution = 0;
+
+char *display;
+
+CARD32 TimeOutValue = DEFAULT_TIMEOUT * MILLI_PER_SECOND;
+int    argcGlobal;
+char   **argvGlobal;
diff --git a/Xserver/programs/Xserver/dix/glyphcurs.c b/Xserver/programs/Xserver/dix/glyphcurs.c
new file mode 100644 (file)
index 0000000..e22abe3
--- /dev/null
@@ -0,0 +1,198 @@
+/************************************************************************
+
+Copyright (c) 1987  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+
+Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
+
+                        All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and its 
+documentation for any purpose and without fee is hereby granted, 
+provided that the above copyright notice appear in all copies and that
+both that copyright notice and this permission notice appear in 
+supporting documentation, and that the name of Digital not be
+used in advertising or publicity pertaining to distribution of the
+software without specific, written prior permission.  
+
+DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
+ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
+DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
+ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+SOFTWARE.
+
+************************************************************************/
+
+/* $XConsortium: glyphcurs.c /main/28 1996/08/01 19:21:16 dpw $ */
+
+#include "misc.h"
+#include "fontstruct.h"
+#include "dixfontstr.h"
+#include "scrnintstr.h"
+#include "gcstruct.h"
+#include "resource.h"
+#include "dix.h"
+#include "cursorstr.h"
+#include "opaque.h"
+#include "servermd.h"
+
+
+/*
+    get the bits out of the font in a portable way.  to avoid
+dealing with padding and such-like, we draw the glyph into
+a bitmap, then read the bits out with GetImage, which
+uses server-natural format.
+    since all screens return the same bitmap format, we'll just use
+the first one we find.
+    the character origin lines up with the hotspot in the
+cursor metrics.
+*/
+
+int
+ServerBitsFromGlyph(pfont, ch, cm, ppbits)
+    FontPtr    pfont;
+    unsigned int ch;
+    register CursorMetricPtr cm;
+    unsigned char **ppbits;
+{
+    register ScreenPtr pScreen;
+    register GCPtr pGC;
+    xRectangle rect;
+    PixmapPtr ppix;
+    long nby;
+    char *pbits;
+    ChangeGCVal gcval[3];
+    unsigned char char2b[2];
+
+    /* turn glyph index into a protocol-format char2b */
+    char2b[0] = (unsigned char)(ch >> 8);
+    char2b[1] = (unsigned char)(ch & 0xff);
+
+    pScreen = screenInfo.screens[0];
+    nby = BitmapBytePad(cm->width) * (long)cm->height;
+    pbits = (char *)xalloc(nby);
+    if (!pbits)
+       return BadAlloc;
+    /* zeroing the (pad) bits seems to help some ddx cursor handling */
+    bzero(pbits, nby);
+
+    ppix = (PixmapPtr)(*pScreen->CreatePixmap)(pScreen, cm->width,
+                                              cm->height, 1);
+    pGC = GetScratchGC(1, pScreen);
+    if (!ppix || !pGC)
+    {
+       if (ppix)
+           (*pScreen->DestroyPixmap)(ppix);
+       if (pGC)
+           FreeScratchGC(pGC);
+       xfree(pbits);
+       return BadAlloc;
+    }
+
+    rect.x = 0;
+    rect.y = 0;
+    rect.width = cm->width;
+    rect.height = cm->height;
+
+    /* fill the pixmap with 0 */
+    gcval[0].val = GXcopy;
+    gcval[1].val = 0;
+    gcval[2].ptr = (pointer)pfont;
+    dixChangeGC(NullClient, pGC, GCFunction | GCForeground | GCFont,
+               NULL, gcval);
+    ValidateGC((DrawablePtr)ppix, pGC);
+    (*pGC->ops->PolyFillRect)((DrawablePtr)ppix, pGC, 1, &rect);
+
+    /* draw the glyph */
+    gcval[0].val = 1;
+    dixChangeGC(NullClient, pGC, GCForeground, NULL, gcval);
+    ValidateGC((DrawablePtr)ppix, pGC);
+    (*pGC->ops->PolyText16)((DrawablePtr)ppix, pGC, cm->xhot, cm->yhot,
+                           1, (unsigned short *)char2b);
+    (*pScreen->GetImage)((DrawablePtr)ppix, 0, 0, cm->width, cm->height,
+                        XYPixmap, 1, pbits);
+    *ppbits = (unsigned char *)pbits;
+    FreeScratchGC(pGC);
+    (*pScreen->DestroyPixmap)(ppix);
+    return Success;
+}
+
+
+Bool
+CursorMetricsFromGlyph( pfont, ch, cm)
+    register FontPtr   pfont;
+    unsigned           ch;
+    register CursorMetricPtr cm;
+{
+    CharInfoPtr        pci;
+    unsigned long      nglyphs;
+    CARD8              chs[2];
+    FontEncoding       encoding;
+
+    chs[0] = ch >> 8;
+    chs[1] = ch;
+    encoding = (FONTLASTROW(pfont) == 0) ? Linear16Bit : TwoD16Bit;
+    if (encoding == Linear16Bit)
+    {
+       if (ch < pfont->info.firstCol || pfont->info.lastCol < ch)
+           return FALSE;
+    }
+    else
+    {
+       if (chs[0] < pfont->info.firstRow || pfont->info.lastRow < chs[0])
+           return FALSE;
+       if (chs[1] < pfont->info.firstCol || pfont->info.lastCol < chs[1])
+           return FALSE;
+    }
+    (*pfont->get_glyphs) (pfont, 1, chs, encoding, &nglyphs, &pci);
+    if (nglyphs == 0)
+       return FALSE;
+    cm->width = pci->metrics.rightSideBearing - pci->metrics.leftSideBearing;
+    cm->height = pci->metrics.descent + pci->metrics.ascent;
+    if (pci->metrics.leftSideBearing > 0)
+    {
+       cm->width += pci->metrics.leftSideBearing;
+       cm->xhot = 0;
+    }
+    else
+    {
+       cm->xhot = -pci->metrics.leftSideBearing;
+       if (pci->metrics.rightSideBearing < 0)
+           cm->width -= pci->metrics.rightSideBearing;
+    }
+    if (pci->metrics.ascent < 0)
+    {
+       cm->height -= pci->metrics.ascent;
+       cm->yhot = 0;
+    }
+    else
+    {
+       cm->yhot = pci->metrics.ascent;
+       if (pci->metrics.descent < 0)
+           cm->height -= pci->metrics.descent;
+    }
+    return TRUE;
+}
diff --git a/Xserver/programs/Xserver/dix/grabs.c b/Xserver/programs/Xserver/dix/grabs.c
new file mode 100644 (file)
index 0000000..28325b4
--- /dev/null
@@ -0,0 +1,493 @@
+/* $XConsortium: grabs.c,v 5.10 94/04/17 20:26:39 dpw Exp $ */
+/* $XFree86: xc/programs/Xserver/dix/grabs.c,v 3.0 1996/04/15 11:19:48 dawes Exp $ */
+/*
+
+Copyright (c) 1987  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be included
+in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR
+OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall
+not be used in advertising or otherwise to promote the sale, use or
+other dealings in this Software without prior written authorization
+from the X Consortium.
+
+
+Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts,
+
+                        All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and its 
+documentation for any purpose and without fee is hereby granted, 
+provided that the above copyright notice appear in all copies and that
+both that copyright notice and this permission notice appear in 
+supporting documentation, and that the name of Digital not be
+used in advertising or publicity pertaining to distribution of the
+software without specific, written prior permission.  
+DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
+ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
+DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
+ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+WHETHER IN AN action OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+SOFTWARE.
+
+*/
+
+#include "X.h"
+#include "misc.h"
+#define NEED_EVENTS
+#include "Xproto.h"
+#include "windowstr.h"
+#include "inputstr.h"
+#include "cursorstr.h"
+#include "dixgrabs.h"
+
+extern InputInfo inputInfo;
+
+#define BITMASK(i) (((Mask)1) << ((i) & 31))
+#define MASKIDX(i) ((i) >> 5)
+#define MASKWORD(buf, i) buf[MASKIDX(i)]
+#define BITSET(buf, i) MASKWORD(buf, i) |= BITMASK(i)
+#define BITCLEAR(buf, i) MASKWORD(buf, i) &= ~BITMASK(i)
+#define GETBIT(buf, i) (MASKWORD(buf, i) & BITMASK(i))
+
+GrabPtr
+#if NeedFunctionPrototypes
+CreateGrab(
+    int client,
+    DeviceIntPtr device,
+    WindowPtr window,
+    Mask eventMask,
+    Bool ownerEvents, Bool keyboardMode, Bool pointerMode,
+    DeviceIntPtr modDevice,
+    unsigned short modifiers,
+    int type,
+    KeyCode keybut,    /* key or button */
+    WindowPtr confineTo,
+    CursorPtr cursor)
+#else
+CreateGrab(client, device, window, eventMask, ownerEvents, keyboardMode,
+          pointerMode, modDevice, modifiers, type, keybut, confineTo, cursor)
+    int client;
+    DeviceIntPtr device;
+    WindowPtr window;
+    Mask eventMask;
+    Bool ownerEvents, keyboardMode, pointerMode;
+    DeviceIntPtr modDevice;
+    unsigned short modifiers;
+    int type;
+    KeyCode keybut;    /* key or button */
+    WindowPtr confineTo;
+    CursorPtr cursor;
+#endif
+{
+    GrabPtr grab;
+
+    grab = (GrabPtr)xalloc(sizeof(GrabRec));
+    if (!grab)
+       return (GrabPtr)NULL;
+    grab->resource = FakeClientID(client);
+    grab->device = device;
+    grab->coreGrab = ((device == inputInfo.keyboard) ||
+                     (device == inputInfo.pointer));
+    grab->window = window;
+    grab->eventMask = eventMask;
+    grab->ownerEvents = ownerEvents;
+    grab->keyboardMode = keyboardMode;
+    grab->pointerMode = pointerMode;
+    grab->modifiersDetail.exact = modifiers;
+    grab->modifiersDetail.pMask = NULL;
+    grab->modifierDevice = modDevice;
+    grab->coreMods = ((modDevice == inputInfo.keyboard) ||
+                     (modDevice == inputInfo.pointer));
+    grab->type = type;
+    grab->detail.exact = keybut;
+    grab->detail.pMask = NULL;
+    grab->confineTo = confineTo;
+    grab->cursor = cursor;
+    if (cursor)
+       cursor->refcnt++;
+    return grab;
+
+}
+
+static void
+#if NeedFunctionPrototypes
+FreeGrab(GrabPtr pGrab)
+#else
+FreeGrab(pGrab)
+    GrabPtr pGrab;
+#endif
+{
+    if (pGrab->modifiersDetail.pMask != NULL)
+       xfree(pGrab->modifiersDetail.pMask);
+
+    if (pGrab->detail.pMask != NULL)
+       xfree(pGrab->detail.pMask);
+
+    if (pGrab->cursor)
+       FreeCursor(pGrab->cursor, (Cursor)0);
+
+    xfree(pGrab);
+}
+
+/*ARGSUSED*/
+int
+DeletePassiveGrab(value, id)
+    pointer value;
+    XID   id;
+{
+    register GrabPtr g, prev;
+    GrabPtr pGrab = (GrabPtr)value;
+
+    /* it is OK if the grab isn't found */
+    prev = 0;
+    for (g = (wPassiveGrabs (pGrab->window)); g; g = g->next)
+    {
+       if (pGrab == g)
+       {
+           if (prev)
+               prev->next = g->next;
+           else
+               if (!(pGrab->window->optional->passiveGrabs = g->next))
+                   CheckWindowOptionalNeed (pGrab->window);
+           break;
+       }
+       prev = g;
+    }
+    FreeGrab(pGrab);
+    return Success;
+}
+
+static Mask *
+#if NeedFunctionPrototypes
+DeleteDetailFromMask(Mask *pDetailMask, unsigned short detail)
+#else
+DeleteDetailFromMask(pDetailMask, detail)
+    Mask *pDetailMask;
+    unsigned short detail;
+#endif
+{
+    register Mask *mask;
+    register int i;
+
+    mask = (Mask *)xalloc(sizeof(Mask) * MasksPerDetailMask);
+    if (mask)
+    {
+       if (pDetailMask)
+           for (i = 0; i < MasksPerDetailMask; i++)
+               mask[i]= pDetailMask[i];
+       else
+           for (i = 0; i < MasksPerDetailMask; i++)
+               mask[i]= ~0L;
+       BITCLEAR(mask, detail);
+    }
+    return mask; 
+}
+
+static Bool
+#if NeedFunctionPrototypes
+IsInGrabMask(
+    DetailRec firstDetail,
+    DetailRec secondDetail,
+    unsigned short exception)
+#else
+IsInGrabMask(firstDetail, secondDetail, exception)
+    DetailRec firstDetail, secondDetail;
+    unsigned short exception;
+#endif
+{
+    if (firstDetail.exact == exception)
+    {
+       if (firstDetail.pMask == NULL)
+           return TRUE;
+       
+       /* (at present) never called with two non-null pMasks */
+       if (secondDetail.exact == exception)
+           return FALSE;
+
+       if (GETBIT(firstDetail.pMask, secondDetail.exact))
+           return TRUE;
+    }
+    
+    return FALSE;
+}
+
+static Bool 
+#if NeedFunctionPrototypes
+IdenticalExactDetails(
+    unsigned short firstExact,
+    unsigned short secondExact,
+    unsigned short exception)
+#else
+IdenticalExactDetails(firstExact, secondExact, exception)
+    unsigned short firstExact, secondExact, exception;
+#endif
+{
+    if ((firstExact == exception) || (secondExact == exception))
+       return FALSE;
+   
+    if (firstExact == secondExact)
+       return TRUE;
+
+    return FALSE;
+}
+
+static Bool 
+#if NeedFunctionPrototypes
+DetailSupersedesSecond(
+    DetailRec firstDetail,
+    DetailRec secondDetail,
+    unsigned short exception)
+#else
+DetailSupersedesSecond(firstDetail, secondDetail, exception)
+    DetailRec firstDetail, secondDetail;
+    unsigned short exception;
+#endif
+{
+    if (IsInGrabMask(firstDetail, secondDetail, exception))
+       return TRUE;
+
+    if (IdenticalExactDetails(firstDetail.exact, secondDetail.exact,
+                             exception))
+       return TRUE;
+  
+    return FALSE;
+}
+
+static Bool
+#if NeedFunctionPrototypes
+GrabSupersedesSecond(GrabPtr pFirstGrab, GrabPtr pSecondGrab)
+#else
+GrabSupersedesSecond(pFirstGrab, pSecondGrab)
+    GrabPtr pFirstGrab, pSecondGrab;
+#endif
+{
+    if (!DetailSupersedesSecond(pFirstGrab->modifiersDetail,
+                               pSecondGrab->modifiersDetail, 
+                               (unsigned short)AnyModifier))
+       return FALSE;
+
+    if (DetailSupersedesSecond(pFirstGrab->detail,
+                              pSecondGrab->detail, (unsigned short)AnyKey))
+       return TRUE;
+    return FALSE;
+}
+
+Bool
+GrabMatchesSecond(pFirstGrab, pSecondGrab)
+    GrabPtr pFirstGrab, pSecondGrab;
+{
+    if ((pFirstGrab->device != pSecondGrab->device) ||
+       (pFirstGrab->modifierDevice != pSecondGrab->modifierDevice) ||
+       (pFirstGrab->type != pSecondGrab->type))
+       return FALSE;
+
+    if (GrabSupersedesSecond(pFirstGrab, pSecondGrab) ||
+       GrabSupersedesSecond(pSecondGrab, pFirstGrab))
+       return TRUE;
+    if (DetailSupersedesSecond(pSecondGrab->detail, pFirstGrab->detail,
+                              (unsigned short)AnyKey) 
+       && 
+       DetailSupersedesSecond(pFirstGrab->modifiersDetail,
+                              pSecondGrab->modifiersDetail,
+                              (unsigned short)AnyModifier))
+       return TRUE;
+
+    if (DetailSupersedesSecond(pFirstGrab->detail, pSecondGrab->detail,
+                              (unsigned short)AnyKey)
+       && 
+       DetailSupersedesSecond(pSecondGrab->modifiersDetail,
+                              pFirstGrab->modifiersDetail,
+                              (unsigned short)AnyModifier))
+       return TRUE;
+
+    return FALSE;
+}
+
+int
+AddPassiveGrabToList(pGrab)
+    GrabPtr pGrab;
+{
+    GrabPtr grab;
+
+    for (grab = wPassiveGrabs(pGrab->window); grab; grab = grab->next)
+    {
+       if (GrabMatchesSecond(pGrab, grab))
+       {
+           if (CLIENT_BITS(pGrab->resource) != CLIENT_BITS(grab->resource))
+           {
+               FreeGrab(pGrab);
+               return BadAccess;
+           }
+       }
+    }
+
+    if (!pGrab->window->optional && !MakeWindowOptional (pGrab->window))
+    {
+       FreeGrab(pGrab);
+       return BadAlloc;
+    }
+    pGrab->next = pGrab->window->optional->passiveGrabs;
+    pGrab->window->optional->passiveGrabs = pGrab;
+    if (AddResource(pGrab->resource, RT_PASSIVEGRAB, (pointer)pGrab))
+       return Success;
+    return BadAlloc;
+}
+
+/* the following is kinda complicated, because we need to be able to back out
+ * if any allocation fails
+ */
+
+Bool
+DeletePassiveGrabFromList(pMinuendGrab)
+    GrabPtr pMinuendGrab;
+{
+    register GrabPtr grab;
+    GrabPtr *deletes, *adds;
+    Mask ***updates, **details;
+    int i, ndels, nadds, nups;
+    Bool ok;
+
+#define UPDATE(mask,exact) \
+       if (!(details[nups] = DeleteDetailFromMask(mask, exact))) \
+         ok = FALSE; \
+       else \
+         updates[nups++] = &(mask)
+
+    i = 0;
+    for (grab = wPassiveGrabs(pMinuendGrab->window); grab; grab = grab->next)
+       i++;
+    if (!i)
+       return TRUE;
+    deletes = (GrabPtr *)ALLOCATE_LOCAL(i * sizeof(GrabPtr));
+    adds = (GrabPtr *)ALLOCATE_LOCAL(i * sizeof(GrabPtr));
+    updates = (Mask ***)ALLOCATE_LOCAL(i * sizeof(Mask **));
+    details = (Mask **)ALLOCATE_LOCAL(i * sizeof(Mask *));
+    if (!deletes || !adds || !updates || !details)
+    {
+       if (details) DEALLOCATE_LOCAL(details);
+       if (updates) DEALLOCATE_LOCAL(updates);
+       if (adds) DEALLOCATE_LOCAL(adds);
+       if (deletes) DEALLOCATE_LOCAL(deletes);
+       return FALSE;
+    }
+    ndels = nadds = nups = 0;
+    ok = TRUE;
+    for (grab = wPassiveGrabs(pMinuendGrab->window);
+        grab && ok;
+        grab = grab->next)
+    {
+       if ((CLIENT_BITS(grab->resource) != CLIENT_BITS(pMinuendGrab->resource)) ||
+           !GrabMatchesSecond(grab, pMinuendGrab))
+           continue;
+       if (GrabSupersedesSecond(pMinuendGrab, grab))
+       {
+           deletes[ndels++] = grab;
+       }
+       else if ((grab->detail.exact == AnyKey)
+                && (grab->modifiersDetail.exact != AnyModifier))
+       {
+           UPDATE(grab->detail.pMask, pMinuendGrab->detail.exact);
+       }
+       else if ((grab->modifiersDetail.exact == AnyModifier) 
+                && (grab->detail.exact != AnyKey))
+       {
+           UPDATE(grab->modifiersDetail.pMask,
+                  pMinuendGrab->modifiersDetail.exact);
+       }
+       else if ((pMinuendGrab->detail.exact != AnyKey)
+                && (pMinuendGrab->modifiersDetail.exact != AnyModifier))
+       {
+           GrabPtr pNewGrab;
+
+           UPDATE(grab->detail.pMask, pMinuendGrab->detail.exact);
+
+           pNewGrab = CreateGrab(CLIENT_ID(grab->resource), grab->device,
+                                 grab->window, (Mask)grab->eventMask,
+                                 (Bool)grab->ownerEvents,
+                                 (Bool)grab->keyboardMode,
+                                 (Bool)grab->pointerMode,
+                                 grab->modifierDevice,
+                                 AnyModifier, (int)grab->type,
+                                 pMinuendGrab->detail.exact,
+                                 grab->confineTo, grab->cursor);
+           if (!pNewGrab)
+               ok = FALSE;
+           else if (!(pNewGrab->modifiersDetail.pMask =
+                      DeleteDetailFromMask(grab->modifiersDetail.pMask,
+                                        pMinuendGrab->modifiersDetail.exact))
+                    ||
+                    (!pNewGrab->window->optional &&
+                     !MakeWindowOptional(pNewGrab->window)))
+           {
+               FreeGrab(pNewGrab);
+               ok = FALSE;
+           }
+           else if (!AddResource(pNewGrab->resource, RT_PASSIVEGRAB,
+                                 (pointer)pNewGrab))
+               ok = FALSE;
+           else
+               adds[nadds++] = pNewGrab;
+       }   
+       else if (pMinuendGrab->detail.exact == AnyKey)
+       {
+           UPDATE(grab->modifiersDetail.pMask,
+                  pMinuendGrab->modifiersDetail.exact);
+       }
+       else
+       {
+           UPDATE(grab->detail.pMask, pMinuendGrab->detail.exact);
+       }
+    }
+
+    if (!ok)
+    {
+       for (i = 0; i < nadds; i++)
+           FreeResource(adds[i]->resource, RT_NONE);
+       for (i = 0; i < nups; i++)
+           xfree(details[i]);
+    }
+    else
+    {
+       for (i = 0; i < ndels; i++)
+           FreeResource(deletes[i]->resource, RT_NONE);
+       for (i = 0; i < nadds; i++)
+       {
+           grab = adds[i];
+           grab->next = grab->window->optional->passiveGrabs;
+           grab->window->optional->passiveGrabs = grab;
+       }
+       for (i = 0; i < nups; i++)
+       {
+           xfree(*updates[i]);
+           *updates[i] = details[i];
+       }
+    }
+    DEALLOCATE_LOCAL(details);
+    DEALLOCATE_LOCAL(updates);
+    DEALLOCATE_LOCAL(adds);
+    DEALLOCATE_LOCAL(deletes);
+    return ok;
+
+#undef UPDATE
+}
diff --git a/Xserver/programs/Xserver/dix/initatoms.c b/Xserver/programs/Xserver/dix/initatoms.c
new file mode 100644 (file)
index 0000000..7aadd90
--- /dev/null
@@ -0,0 +1,80 @@
+/* THIS IS A GENERATED FILE
+ *
+ * Do not change!  Changing this file implies a protocol change!
+ */
+
+#include "X.h"
+#include "Xatom.h"
+#include "misc.h"
+#include "dix.h"
+void MakePredeclaredAtoms()
+{
+    if (MakeAtom("PRIMARY", 7, 1) != XA_PRIMARY) AtomError();
+    if (MakeAtom("SECONDARY", 9, 1) != XA_SECONDARY) AtomError();
+    if (MakeAtom("ARC", 3, 1) != XA_ARC) AtomError();
+    if (MakeAtom("ATOM", 4, 1) != XA_ATOM) AtomError();
+    if (MakeAtom("BITMAP", 6, 1) != XA_BITMAP) AtomError();
+    if (MakeAtom("CARDINAL", 8, 1) != XA_CARDINAL) AtomError();
+    if (MakeAtom("COLORMAP", 8, 1) != XA_COLORMAP) AtomError();
+    if (MakeAtom("CURSOR", 6, 1) != XA_CURSOR) AtomError();
+    if (MakeAtom("CUT_BUFFER0", 11, 1) != XA_CUT_BUFFER0) AtomError();
+    if (MakeAtom("CUT_BUFFER1", 11, 1) != XA_CUT_BUFFER1) AtomError();
+    if (MakeAtom("CUT_BUFFER2", 11, 1) != XA_CUT_BUFFER2) AtomError();
+    if (MakeAtom("CUT_BUFFER3", 11, 1) != XA_CUT_BUFFER3) AtomError();
+    if (MakeAtom("CUT_BUFFER4", 11, 1) != XA_CUT_BUFFER4) AtomError();
+    if (MakeAtom("CUT_BUFFER5", 11, 1) != XA_CUT_BUFFER5) AtomError();
+    if (MakeAtom("CUT_BUFFER6", 11, 1) != XA_CUT_BUFFER6) AtomError();
+    if (MakeAtom("CUT_BUFFER7", 11, 1) != XA_CUT_BUFFER7) AtomError();
+    if (MakeAtom("DRAWABLE", 8, 1) != XA_DRAWABLE) AtomError();
+    if (MakeAtom("FONT", 4, 1) != XA_FONT) AtomError();
+    if (MakeAtom("INTEGER", 7, 1) != XA_INTEGER) AtomError();
+    if (MakeAtom("PIXMAP", 6, 1) != XA_PIXMAP) AtomError();
+    if (MakeAtom("POINT", 5, 1) != XA_POINT) AtomError();
+    if (MakeAtom("RECTANGLE", 9, 1) != XA_RECTANGLE) AtomError();
+    if (MakeAtom("RESOURCE_MANAGER", 16, 1) != XA_RESOURCE_MANAGER) AtomError();
+    if (MakeAtom("RGB_COLOR_MAP", 13, 1) != XA_RGB_COLOR_MAP) AtomError();
+    if (MakeAtom("RGB_BEST_MAP", 12, 1) != XA_RGB_BEST_MAP) AtomError();
+    if (MakeAtom("RGB_BLUE_MAP", 12, 1) != XA_RGB_BLUE_MAP) AtomError();
+    if (MakeAtom("RGB_DEFAULT_MAP", 15, 1) != XA_RGB_DEFAULT_MAP) AtomError();
+    if (MakeAtom("RGB_GRAY_MAP", 12, 1) != XA_RGB_GRAY_MAP) AtomError();
+    if (MakeAtom("RGB_GREEN_MAP", 13, 1) != XA_RGB_GREEN_MAP) AtomError();
+    if (MakeAtom("RGB_RED_MAP", 11, 1) != XA_RGB_RED_MAP) AtomError();
+    if (MakeAtom("STRING", 6, 1) != XA_STRING) AtomError();
+    if (MakeAtom("VISUALID", 8, 1) != XA_VISUALID) AtomError();
+    if (MakeAtom("WINDOW", 6, 1) != XA_WINDOW) AtomError();
+    if (MakeAtom("WM_COMMAND", 10, 1) != XA_WM_COMMAND) AtomError();
+    if (MakeAtom("WM_HINTS", 8, 1) != XA_WM_HINTS) AtomError();
+    if (MakeAtom("WM_CLIENT_MACHINE", 17, 1) != XA_WM_CLIENT_MACHINE) AtomError();
+    if (MakeAtom("WM_ICON_NAME", 12, 1) != XA_WM_ICON_NAME) AtomError();
+    if (MakeAtom("WM_ICON_SIZE", 12, 1) != XA_WM_ICON_SIZE) AtomError();
+    if (MakeAtom("WM_NAME", 7, 1) != XA_WM_NAME) AtomError();
+    if (MakeAtom("WM_NORMAL_HINTS", 15, 1) != XA_WM_NORMAL_HINTS) AtomError();
+    if (MakeAtom("WM_SIZE_HINTS", 13, 1) != XA_WM_SIZE_HINTS) AtomError();
+    if (MakeAtom("WM_ZOOM_HINTS", 13, 1) != XA_WM_ZOOM_HINTS) AtomError();
+    if (MakeAtom("MIN_SPACE", 9, 1) != XA_MIN_SPACE) AtomError();
+    if (MakeAtom("NORM_SPACE", 10, 1) != XA_NORM_SPACE) AtomError();
+    if (MakeAtom("MAX_SPACE", 9, 1) != XA_MAX_SPACE) AtomError();
+    if (MakeAtom("END_SPACE", 9, 1) != XA_END_SPACE) AtomError();
+    if (MakeAtom("SUPERSCRIPT_X", 13, 1) != XA_SUPERSCRIPT_X) AtomError();
+    if (MakeAtom("SUPERSCRIPT_Y", 13, 1) != XA_SUPERSCRIPT_Y) AtomError();
+    if (MakeAtom("SUBSCRIPT_X", 11, 1) != XA_SUBSCRIPT_X) AtomError();
+    if (MakeAtom("SUBSCRIPT_Y", 11, 1) != XA_SUBSCRIPT_Y) AtomError();
+    if (MakeAtom("UNDERLINE_POSITION", 18, 1) != XA_UNDERLINE_POSITION) AtomError();
+    if (MakeAtom("UNDERLINE_THICKNESS", 19, 1) != XA_UNDERLINE_THICKNESS) AtomError();
+    if (MakeAtom("STRIKEOUT_ASCENT", 16, 1) != XA_STRIKEOUT_ASCENT) AtomError();
+    if (MakeAtom("STRIKEOUT_DESCENT", 17, 1) != XA_STRIKEOUT_DESCENT) AtomError();
+    if (MakeAtom("ITALIC_ANGLE", 12, 1) != XA_ITALIC_ANGLE) AtomError();
+    if (MakeAtom("X_HEIGHT", 8, 1) != XA_X_HEIGHT) AtomError();
+    if (MakeAtom("QUAD_WIDTH", 10, 1) != XA_QUAD_WIDTH) AtomError();
+    if (MakeAtom("WEIGHT", 6, 1) != XA_WEIGHT) AtomError();
+    if (MakeAtom("POINT_SIZE", 10, 1) != XA_POINT_SIZE) AtomError();
+    if (MakeAtom("RESOLUTION", 10, 1) != XA_RESOLUTION) AtomError();
+    if (MakeAtom("COPYRIGHT", 9, 1) != XA_COPYRIGHT) AtomError();
+    if (MakeAtom("NOTICE", 6, 1) != XA_NOTICE) AtomError();
+    if (MakeAtom("FONT_NAME", 9, 1) != XA_FONT_NAME) AtomError();
+    if (MakeAtom("FAMILY_NAME", 11, 1) != XA_FAMILY_NAME) AtomError();
+    if (MakeAtom("FULL_NAME", 9, 1) != XA_FULL_NAME) AtomError();
+    if (MakeAtom("CAP_HEIGHT", 10, 1) != XA_CAP_HEIGHT) AtomError();
+    if (MakeAtom("WM_CLASS", 8, 1) != XA_WM_CLASS) AtomError();
+    if (MakeAtom("WM_TRANSIENT_FOR", 16, 1) != XA_WM_TRANSIENT_FOR) AtomError();
+}
diff --git a/Xserver/programs/Xserver/dix/main.c b/Xserver/programs/Xserver/dix/main.c
new file mode 100644 (file)
index 0000000..51043d8
--- /dev/null
@@ -0,0 +1,749 @@
+/***********************************************************
+
+Copyright (c) 1987  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+
+Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
+
+                        All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and its 
+documentation for any purpose and without fee is hereby granted, 
+provided that the above copyright notice appear in all copies and that
+both that copyright notice and this permission notice appear in 
+supporting documentation, and that the name of Digital not be
+used in advertising or publicity pertaining to distribution of the
+software without specific, written prior permission.  
+
+DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
+ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
+DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
+ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+SOFTWARE.
+
+******************************************************************/
+/* $XConsortium: main.c /main/82 1996/09/28 17:12:09 rws $ */
+/* $XFree86: xc/programs/Xserver/dix/main.c,v 3.10.2.2 1998/01/22 10:47:08 dawes Exp $ */
+
+#define NEED_EVENTS
+#include "X.h"
+#include "Xproto.h"
+#include "scrnintstr.h"
+#include "misc.h"
+#include "os.h"
+#include "windowstr.h"
+#include "resource.h"
+#include "dixstruct.h"
+#include "gcstruct.h"
+#include "extension.h"
+#include "extnsionst.h"
+#include "colormap.h"
+#include "colormapst.h"
+#include "cursorstr.h"
+#include "font.h"
+#include "opaque.h"
+#include "servermd.h"
+#include "site.h"
+#include "dixfont.h"
+#include "dixevents.h"         /* InitEvents() */
+#include "dispatch.h"          /* InitProcVectors() */
+
+extern CARD32 defaultScreenSaverTime;
+extern CARD32 defaultScreenSaverInterval;
+extern int defaultScreenSaverBlanking;
+extern int defaultScreenSaverAllowExposures;
+
+#ifdef DPMSExtension
+#include "dpms.h"
+#endif
+
+void ddxGiveUp();
+
+extern int InitClientPrivates(
+#if NeedFunctionPrototypes
+    ClientPtr /*client*/
+#endif
+);
+
+extern void Dispatch(
+#if NeedFunctionPrototypes
+    void
+#endif
+);
+
+extern char *display;
+char *ConnectionInfo;
+xConnSetupPrefix connSetupPrefix;
+
+extern WindowPtr *WindowTable;
+extern FontPtr defaultFont;
+extern int screenPrivateCount;
+
+static Bool CreateConnectionBlock(
+#if NeedFunctionPrototypes
+    void
+#endif
+);
+
+static void FreeScreen(
+#if NeedFunctionPrototypes
+    ScreenPtr /*pScreen*/
+#endif
+);
+
+PaddingInfo PixmapWidthPaddingInfo[33];
+
+#ifdef INTERNAL_VS_EXTERNAL_PADDING
+/* add padding info for 32-bit interface. PutImage and GetImage will
+ * work on 32-bit padding while the rest of the server will work
+ * on 64-bit padding (Alpha).
+ */
+PaddingInfo PixmapWidthPaddingInfoProto[33];
+#endif
+
+int connBlockScreenStart;
+
+static int restart = 0;
+
+/*
+ * Dummy entry for EventSwapVector[]
+ */
+/*ARGSUSED*/
+void
+NotImplemented(
+#if NeedFunctionPrototypes && defined(EVENT_SWAP_PTR)
+       xEvent * from,
+       xEvent * to
+#endif
+       )
+{
+    FatalError("Not implemented");
+}
+
+/*
+ * Dummy entry for ReplySwapVector[]
+ */
+/*ARGSUSED*/
+void
+ReplyNotSwappd(
+#if NeedNestedPrototypes
+       ClientPtr pClient ,
+       int size ,
+       void * pbuf
+#endif
+       )
+{
+    FatalError("Not implemented");
+}
+
+/*
+ * This array encodes the answer to the question "what is the log base 2
+ * of the number of pixels that fit in a scanline pad unit?"
+ * Note that ~0 is an invalid entry (mostly for the benefit of the reader).
+ */
+static int answer[6][4] = {
+       /* pad   pad   pad     pad*/
+       /*  8     16    32    64 */
+
+       {   3,     4,    5 ,   6 },     /* 1 bit per pixel */
+       {   1,     2,    3 ,   4 },     /* 4 bits per pixel */
+       {   0,     1,    2 ,   3 },     /* 8 bits per pixel */
+       {   ~0,    0,    1 ,   2 },     /* 16 bits per pixel */
+       {   ~0,    ~0,   0 ,   1 },     /* 24 bits per pixel */
+       {   ~0,    ~0,   0 ,   1 }      /* 32 bits per pixel */
+};
+
+/*
+ * This array gives the answer to the question "what is the first index for
+ * the answer array above given the number of bits per pixel?"
+ * Note that ~0 is an invalid entry (mostly for the benefit of the reader).
+ */
+static int indexForBitsPerPixel[ 33 ] = {
+       ~0, 0, ~0, ~0,  /* 1 bit per pixel */
+       1, ~0, ~0, ~0,  /* 4 bits per pixel */
+       2, ~0, ~0, ~0,  /* 8 bits per pixel */
+       ~0,~0, ~0, ~0,
+       3, ~0, ~0, ~0,  /* 16 bits per pixel */
+       ~0,~0, ~0, ~0,
+       4, ~0, ~0, ~0,  /* 24 bits per pixel */
+       ~0,~0, ~0, ~0,
+       5               /* 32 bits per pixel */
+};
+
+/*
+ * This array gives the bytesperPixel value for cases where the number
+ * of bits per pixel is a multiple of 8 but not a power of 2.
+ */
+static int answerBytesPerPixel[ 33 ] = {
+       ~0, 0, ~0, ~0,  /* 1 bit per pixel */
+       0, ~0, ~0, ~0,  /* 4 bits per pixel */
+       0, ~0, ~0, ~0,  /* 8 bits per pixel */
+       ~0,~0, ~0, ~0,
+       0, ~0, ~0, ~0,  /* 16 bits per pixel */
+       ~0,~0, ~0, ~0,
+       3, ~0, ~0, ~0,  /* 24 bits per pixel */
+       ~0,~0, ~0, ~0,
+       0               /* 32 bits per pixel */
+};
+
+/*
+ * This array gives the answer to the question "what is the second index for
+ * the answer array above given the number of bits per scanline pad unit?"
+ * Note that ~0 is an invalid entry (mostly for the benefit of the reader).
+ */
+static int indexForScanlinePad[ 65 ] = {
+       ~0, ~0, ~0, ~0,
+       ~0, ~0, ~0, ~0,
+        0, ~0, ~0, ~0, /* 8 bits per scanline pad unit */
+       ~0, ~0, ~0, ~0,
+        1, ~0, ~0, ~0, /* 16 bits per scanline pad unit */
+       ~0, ~0, ~0, ~0,
+       ~0, ~0, ~0, ~0,
+       ~0, ~0, ~0, ~0,
+        2, ~0, ~0, ~0, /* 32 bits per scanline pad unit */
+       ~0, ~0, ~0, ~0,
+       ~0, ~0, ~0, ~0,
+       ~0, ~0, ~0, ~0,
+       ~0, ~0, ~0, ~0,
+       ~0, ~0, ~0, ~0,
+       ~0, ~0, ~0, ~0,
+       ~0, ~0, ~0, ~0,
+        3              /* 64 bits per scanline pad unit */
+};
+
+
+int
+main(argc, argv)
+    int                argc;
+    char       *argv[];
+{
+    int                i, j, k;
+    HWEventQueueType   alwaysCheckForInput[2];
+
+    /* Notice if we're restart.  Probably this is because we jumped through
+     * uninitialized pointer */
+    if (restart)
+       FatalError("server restarted. Jumped through uninitialized pointer?\n");
+    else
+       restart = 1;
+
+#if 0
+    ExpandCommandLine(&argc, &argv);
+#endif
+
+    /* These are needed by some routines which are called from interrupt
+     * handlers, thus have no direct calling path back to main and thus
+     * can't be passed argc, argv as parameters */
+    argcGlobal = argc;
+    argvGlobal = argv;
+    display = "0";
+    ProcessCommandLine(argc, argv);
+
+    alwaysCheckForInput[0] = 0;
+    alwaysCheckForInput[1] = 1;
+    while(1)
+    {
+       serverGeneration++;
+        ScreenSaverTime = defaultScreenSaverTime;
+       ScreenSaverInterval = defaultScreenSaverInterval;
+       ScreenSaverBlanking = defaultScreenSaverBlanking;
+       ScreenSaverAllowExposures = defaultScreenSaverAllowExposures;
+#ifdef DPMSExtension
+       DPMSStandbyTime = defaultDPMSStandbyTime;
+       DPMSSuspendTime = defaultDPMSSuspendTime;
+       DPMSOffTime = defaultDPMSOffTime;
+       DPMSEnabled = defaultDPMSEnabled;
+       DPMSPowerLevel = 0;
+#endif
+       InitBlockAndWakeupHandlers();
+       /* Perform any operating system dependent initializations you'd like */
+       OsInit();               
+       if(serverGeneration == 1)
+       {
+           CreateWellKnownSockets();
+           InitProcVectors();
+           clients = (ClientPtr *)xalloc(MAXCLIENTS * sizeof(ClientPtr));
+           if (!clients)
+               FatalError("couldn't create client array");
+           for (i=1; i<MAXCLIENTS; i++) 
+               clients[i] = NullClient;
+           serverClient = (ClientPtr)xalloc(sizeof(ClientRec));
+           if (!serverClient)
+               FatalError("couldn't create server client");
+           InitClient(serverClient, 0, (pointer)NULL);
+       }
+       else
+           ResetWellKnownSockets ();
+        clients[0] = serverClient;
+        currentMaxClients = 1;
+
+       if (!InitClientResources(serverClient))      /* for root resources */
+           FatalError("couldn't init server resources");
+
+       SetInputCheck(&alwaysCheckForInput[0], &alwaysCheckForInput[1]);
+       screenInfo.arraySize = MAXSCREENS;
+       screenInfo.numScreens = 0;
+       screenInfo.numVideoScreens = -1;
+       WindowTable = (WindowPtr *)xalloc(MAXSCREENS * sizeof(WindowPtr));
+       if (!WindowTable)
+           FatalError("couldn't create root window table");
+
+       /*
+        * Just in case the ddx doesnt supply a format for depth 1 (like qvss).
+        */
+       j = indexForBitsPerPixel[ 1 ];
+       k = indexForScanlinePad[ BITMAP_SCANLINE_PAD ];
+       PixmapWidthPaddingInfo[1].padRoundUp = BITMAP_SCANLINE_PAD-1;
+       PixmapWidthPaddingInfo[1].padPixelsLog2 = answer[j][k];
+       j = indexForBitsPerPixel[8]; /* bits per byte */
+       PixmapWidthPaddingInfo[1].padBytesLog2 = answer[j][k];
+
+#ifdef INTERNAL_VS_EXTERNAL_PADDING
+       /* Fake out protocol interface to make them believe we support
+        * a different padding than the actual internal padding.
+        */
+       j = indexForBitsPerPixel[ 1 ];
+       k = indexForScanlinePad[ BITMAP_SCANLINE_PAD_PROTO ];
+       PixmapWidthPaddingInfoProto[1].padRoundUp = BITMAP_SCANLINE_PAD_PROTO-1;
+       PixmapWidthPaddingInfoProto[1].padPixelsLog2 = answer[j][k];
+       j = indexForBitsPerPixel[8]; /* bits per byte */
+       PixmapWidthPaddingInfoProto[1].padBytesLog2 = answer[j][k];
+#endif /* INTERNAL_VS_EXTERNAL_PADDING */
+
+       InitAtoms();
+       InitEvents();
+       InitGlyphCaching();
+       ResetClientPrivates();
+       ResetScreenPrivates();
+       ResetWindowPrivates();
+       ResetGCPrivates();
+#ifdef PIXPRIV
+       ResetPixmapPrivates();
+#endif
+       ResetColormapPrivates();
+       ResetFontPrivateIndex();
+       InitCallbackManager();
+       InitOutput(&screenInfo, argc, argv);
+       if (screenInfo.numScreens < 1)
+           FatalError("no screens found");
+       if (screenInfo.numVideoScreens < 0)
+           screenInfo.numVideoScreens = screenInfo.numScreens;
+#ifdef XPRINT
+       PrinterInitOutput(&screenInfo, argc, argv);
+#endif
+       InitExtensions(argc, argv);
+       if (!InitClientPrivates(serverClient))
+           FatalError("failed to allocate serverClient devprivates");
+       for (i = 0; i < screenInfo.numScreens; i++)
+       {
+           ScreenPtr pScreen = screenInfo.screens[i];
+           if (!CreateScratchPixmapsForScreen(i))
+               FatalError("failed to create scratch pixmaps");
+           if (pScreen->CreateScreenResources &&
+               !(*pScreen->CreateScreenResources)(pScreen))
+               FatalError("failed to create screen resources");
+           if (!CreateGCperDepth(i))
+               FatalError("failed to create scratch GCs");
+           if (!CreateDefaultStipple(i))
+               FatalError("failed to create default stipple");
+           if (!CreateRootWindow(pScreen))
+               FatalError("failed to create root window");
+       }
+       InitInput(argc, argv);
+       if (InitAndStartDevices() != Success)
+           FatalError("failed to initialize core devices");
+
+       InitFonts();
+       if (SetDefaultFontPath(defaultFontPath) != Success)
+           ErrorF("failed to set default font path '%s'", defaultFontPath);
+       if (!SetDefaultFont(defaultTextFont))
+           FatalError("could not open default font '%s'", defaultTextFont);
+       if (!(rootCursor = CreateRootCursor(defaultCursorFont, 0)))
+           FatalError("could not open default cursor font '%s'",
+                      defaultCursorFont);
+#ifdef DPMSExtension
+       /* check all screens, looking for DPMS Capabilities */
+       DPMSCapableFlag = DPMSSupported();
+       if (!DPMSCapableFlag)
+           DPMSEnabled = FALSE;
+#endif
+       for (i = 0; i < screenInfo.numScreens; i++)
+           InitRootWindow(WindowTable[i]);
+        DefineInitialRootWindow(WindowTable[0]);
+
+       if (!CreateConnectionBlock())
+           FatalError("could not create connection block info");
+
+       Dispatch();
+
+       /* Now free up whatever must be freed */
+       if (screenIsSaved == SCREEN_SAVER_ON)
+           SaveScreens(SCREEN_SAVER_OFF, ScreenSaverReset);
+       CloseDownExtensions();
+       FreeAllResources();
+       CloseDownDevices();
+       for (i = screenInfo.numScreens - 1; i >= 0; i--)
+       {
+           FreeScratchPixmapsForScreen(i);
+           FreeGCperDepth(i);
+           FreeDefaultStipple(i);
+           (* screenInfo.screens[i]->CloseScreen)(i, screenInfo.screens[i]);
+           FreeScreen(screenInfo.screens[i]);
+           screenInfo.numScreens = i;
+       }
+       xfree(WindowTable);
+       FreeFonts ();
+       xfree(serverClient->devPrivates);
+
+       if (dispatchException & DE_TERMINATE)
+       {
+           OsCleanup();
+           ddxGiveUp();
+           break;
+       }
+
+       xfree(ConnectionInfo);
+    }
+    return(0);
+}
+
+static int padlength[4] = {0, 3, 2, 1};
+
+static Bool
+CreateConnectionBlock()
+{
+    xConnSetup setup;
+    xWindowRoot root;
+    xDepth     depth;
+    xVisualType visual;
+    xPixmapFormat format;
+    unsigned long vid;
+    int i, j, k,
+        lenofblock,
+        sizesofar = 0;
+    char *pBuf;
+
+    
+    /* Leave off the ridBase and ridMask, these must be sent with 
+       connection */
+
+    setup.release = VENDOR_RELEASE;
+    /*
+     * per-server image and bitmap parameters are defined in Xmd.h
+     */
+    setup.imageByteOrder = screenInfo.imageByteOrder;
+
+#ifdef INTERNAL_VS_EXTERNAL_PADDING
+    if ( screenInfo.bitmapScanlineUnit > 32 )
+       setup.bitmapScanlineUnit  = 32;
+    else
+#endif 
+       setup.bitmapScanlineUnit  = screenInfo.bitmapScanlineUnit;
+#ifdef INTERNAL_VS_EXTERNAL_PADDING
+    if ( screenInfo.bitmapScanlinePad > 32 )
+       setup.bitmapScanlinePad = 32;
+    else
+#endif 
+       setup.bitmapScanlinePad = screenInfo.bitmapScanlinePad;
+
+    setup.bitmapBitOrder = screenInfo.bitmapBitOrder;
+    setup.motionBufferSize = NumMotionEvents();
+    setup.numRoots = screenInfo.numScreens;
+    setup.nbytesVendor = strlen(VENDOR_STRING); 
+    setup.numFormats = screenInfo.numPixmapFormats;
+    setup.maxRequestSize = MAX_REQUEST_SIZE;
+    QueryMinMaxKeyCodes(&setup.minKeyCode, &setup.maxKeyCode);
+    
+    lenofblock = sizeof(xConnSetup) + 
+            ((setup.nbytesVendor + 3) & ~3) +
+           (setup.numFormats * sizeof(xPixmapFormat)) +
+            (setup.numRoots * sizeof(xWindowRoot));
+    ConnectionInfo = (char *) xalloc(lenofblock);
+    if (!ConnectionInfo)
+       return FALSE;
+
+    memmove(ConnectionInfo, (char *)&setup, sizeof(xConnSetup));
+    sizesofar = sizeof(xConnSetup);
+    pBuf = ConnectionInfo + sizeof(xConnSetup);
+
+    memmove(pBuf, VENDOR_STRING, (int)setup.nbytesVendor);
+    sizesofar += setup.nbytesVendor;
+    pBuf += setup.nbytesVendor;
+    i = padlength[setup.nbytesVendor & 3];
+    sizesofar += i;
+    while (--i >= 0)
+        *pBuf++ = 0;
+    
+    for (i=0; i<screenInfo.numPixmapFormats; i++)
+    {
+       format.depth = screenInfo.formats[i].depth;
+       format.bitsPerPixel = screenInfo.formats[i].bitsPerPixel;
+#ifdef INTERNAL_VS_EXTERNAL_PADDING
+       if ( screenInfo.formats[i].scanlinePad > 32 )
+           format.scanLinePad = 32;
+       else
+#endif
+           format.scanLinePad = screenInfo.formats[i].scanlinePad;
+       memmove(pBuf, (char *)&format, sizeof(xPixmapFormat));
+       pBuf += sizeof(xPixmapFormat);
+       sizesofar += sizeof(xPixmapFormat);
+    }
+
+    connBlockScreenStart = sizesofar;
+    for (i=0; i<screenInfo.numScreens; i++) 
+    {
+       ScreenPtr       pScreen;
+       DepthPtr        pDepth;
+       VisualPtr       pVisual;
+
+       pScreen = screenInfo.screens[i];
+       root.windowId = WindowTable[i]->drawable.id;
+       root.defaultColormap = pScreen->defColormap;
+       root.whitePixel = pScreen->whitePixel;
+       root.blackPixel = pScreen->blackPixel;
+       root.currentInputMask = 0;    /* filled in when sent */
+       root.pixWidth = pScreen->width;
+       root.pixHeight = pScreen->height;
+       root.mmWidth = pScreen->mmWidth;
+       root.mmHeight = pScreen->mmHeight;
+       root.minInstalledMaps = pScreen->minInstalledCmaps;
+       root.maxInstalledMaps = pScreen->maxInstalledCmaps; 
+       root.rootVisualID = pScreen->rootVisual;                
+       root.backingStore = pScreen->backingStoreSupport;
+       root.saveUnders = pScreen->saveUnderSupport != NotUseful;
+       root.rootDepth = pScreen->rootDepth;
+       root.nDepths = pScreen->numDepths;
+       memmove(pBuf, (char *)&root, sizeof(xWindowRoot));
+       sizesofar += sizeof(xWindowRoot);
+       pBuf += sizeof(xWindowRoot);
+
+       pDepth = pScreen->allowedDepths;
+       for(j = 0; j < pScreen->numDepths; j++, pDepth++)
+       {
+           lenofblock += sizeof(xDepth) + 
+                   (pDepth->numVids * sizeof(xVisualType));
+           pBuf = (char *)xrealloc(ConnectionInfo, lenofblock);
+           if (!pBuf)
+           {
+               xfree(ConnectionInfo);
+               return FALSE;
+           }
+           ConnectionInfo = pBuf;
+           pBuf += sizesofar;            
+           depth.depth = pDepth->depth;
+           depth.nVisuals = pDepth->numVids;
+           memmove(pBuf, (char *)&depth, sizeof(xDepth));
+           pBuf += sizeof(xDepth);
+           sizesofar += sizeof(xDepth);
+           for(k = 0; k < pDepth->numVids; k++)
+           {
+               vid = pDepth->vids[k];
+               for (pVisual = pScreen->visuals;
+                    pVisual->vid != vid;
+                    pVisual++)
+                   ;
+               visual.visualID = vid;
+               visual.class = pVisual->class;
+               visual.bitsPerRGB = pVisual->bitsPerRGBValue;
+               visual.colormapEntries = pVisual->ColormapEntries;
+               visual.redMask = pVisual->redMask;
+               visual.greenMask = pVisual->greenMask;
+               visual.blueMask = pVisual->blueMask;
+               memmove(pBuf, (char *)&visual, sizeof(xVisualType));
+               pBuf += sizeof(xVisualType);
+               sizesofar += sizeof(xVisualType);
+           }
+       }
+    }
+    connSetupPrefix.success = xTrue;
+    connSetupPrefix.length = lenofblock/4;
+    connSetupPrefix.majorVersion = X_PROTOCOL;
+    connSetupPrefix.minorVersion = X_PROTOCOL_REVISION;
+    return TRUE;
+}
+
+/*
+       grow the array of screenRecs if necessary.
+       call the device-supplied initialization procedure 
+with its screen number, a pointer to its ScreenRec, argc, and argv.
+       return the number of successfully installed screens.
+
+*/
+
+int
+#if NeedFunctionPrototypes
+AddScreen(
+    Bool       (* pfnInit)(
+#if NeedNestedPrototypes
+       int /*index*/,
+       ScreenPtr /*pScreen*/,
+       int /*argc*/,
+       char ** /*argv*/
+#endif
+               ),
+    int argc,
+    char **argv)
+#else
+AddScreen(pfnInit, argc, argv)
+    Bool       (* pfnInit)();
+    int argc;
+    char **argv;
+#endif
+{
+
+    int i;
+    int scanlinepad, format, depth, bitsPerPixel, j, k;
+    ScreenPtr pScreen;
+#ifdef DEBUG
+    void       (**jNI) ();
+#endif /* DEBUG */
+
+    i = screenInfo.numScreens;
+    if (i == MAXSCREENS)
+       return -1;
+
+    pScreen = (ScreenPtr) xalloc(sizeof(ScreenRec));
+    if (!pScreen)
+       return -1;
+
+    pScreen->devPrivates = (DevUnion *)xalloc(screenPrivateCount *
+                                             sizeof(DevUnion));
+    if (!pScreen->devPrivates && screenPrivateCount)
+    {
+       xfree(pScreen);
+       return -1;
+    }
+    pScreen->myNum = i;
+    pScreen->WindowPrivateLen = 0;
+    pScreen->WindowPrivateSizes = (unsigned *)NULL;
+    pScreen->totalWindowSize = sizeof(WindowRec);
+    pScreen->GCPrivateLen = 0;
+    pScreen->GCPrivateSizes = (unsigned *)NULL;
+    pScreen->totalGCSize = sizeof(GC);
+#ifdef PIXPRIV
+    pScreen->PixmapPrivateLen = 0;
+    pScreen->PixmapPrivateSizes = (unsigned *)NULL;
+    pScreen->totalPixmapSize = BitmapBytePad(sizeof(PixmapRec)*8);
+#endif
+    pScreen->ClipNotify = 0;   /* for R4 ddx compatibility */
+    pScreen->CreateScreenResources = 0;
+    
+#ifdef DEBUG
+    for (jNI = &pScreen->QueryBestSize; 
+        jNI < (void (**) ()) &pScreen->SendGraphicsExpose;
+        jNI++)
+       *jNI = NotImplemented;
+#endif /* DEBUG */
+
+    /*
+     * This loop gets run once for every Screen that gets added,
+     * but thats ok.  If the ddx layer initializes the formats
+     * one at a time calling AddScreen() after each, then each
+     * iteration will make it a little more accurate.  Worst case
+     * we do this loop N * numPixmapFormats where N is # of screens.
+     * Anyway, this must be called after InitOutput and before the
+     * screen init routine is called.
+     */
+    for (format=0; format<screenInfo.numPixmapFormats; format++)
+    {
+       depth = screenInfo.formats[format].depth;
+       bitsPerPixel = screenInfo.formats[format].bitsPerPixel;
+       scanlinepad = screenInfo.formats[format].scanlinePad;
+       j = indexForBitsPerPixel[ bitsPerPixel ];
+       k = indexForScanlinePad[ scanlinepad ];
+       PixmapWidthPaddingInfo[ depth ].padPixelsLog2 = answer[j][k];
+       PixmapWidthPaddingInfo[ depth ].padRoundUp =
+           (scanlinepad/bitsPerPixel) - 1;
+       j = indexForBitsPerPixel[ 8 ]; /* bits per byte */
+       PixmapWidthPaddingInfo[ depth ].padBytesLog2 = answer[j][k];
+       if (answerBytesPerPixel[bitsPerPixel])
+       {
+           PixmapWidthPaddingInfo[ depth ].notPower2 = 1;
+           PixmapWidthPaddingInfo[ depth ].bytesPerPixel =
+               answerBytesPerPixel[bitsPerPixel];
+       }
+       else
+       {
+           PixmapWidthPaddingInfo[ depth ].notPower2 = 0;
+       }
+
+#ifdef INTERNAL_VS_EXTERNAL_PADDING
+       /* Fake out protocol interface to make them believe we support
+        * a different padding than the actual internal padding.
+        */
+       j = indexForBitsPerPixel[ bitsPerPixel ];
+       k = indexForScanlinePad[ BITMAP_SCANLINE_PAD_PROTO ];
+       PixmapWidthPaddingInfoProto[ depth ].padPixelsLog2 = answer[j][k];
+       PixmapWidthPaddingInfoProto[ depth ].padRoundUp =
+           (BITMAP_SCANLINE_PAD_PROTO/bitsPerPixel) - 1;
+       j = indexForBitsPerPixel[ 8 ]; /* bits per byte */
+       PixmapWidthPaddingInfoProto[ depth ].padBytesLog2 = answer[j][k];
+       if (answerBytesPerPixel[bitsPerPixel])
+       {
+           PixmapWidthPaddingInfoProto[ depth ].notPower2 = 1;
+           PixmapWidthPaddingInfoProto[ depth ].bytesPerPixel =
+               answerBytesPerPixel[bitsPerPixel];
+       }
+       else
+       {
+           PixmapWidthPaddingInfoProto[ depth ].notPower2 = 0;
+       }
+#endif /* INTERNAL_VS_EXTERNAL_PADDING */
+    }
+  
+    /* This is where screen specific stuff gets initialized.  Load the
+       screen structure, call the hardware, whatever.
+       This is also where the default colormap should be allocated and
+       also pixel values for blackPixel, whitePixel, and the cursor
+       Note that InitScreen is NOT allowed to modify argc, argv, or
+       any of the strings pointed to by argv.  They may be passed to
+       multiple screens. 
+    */ 
+    pScreen->rgf = ~0L;  /* there are no scratch GCs yet*/
+    WindowTable[i] = NullWindow;
+    screenInfo.screens[i] = pScreen;
+    screenInfo.numScreens++;
+    if (!(*pfnInit)(i, pScreen, argc, argv))
+    {
+       FreeScreen(pScreen);
+       screenInfo.numScreens--;
+       return -1;
+    }
+    return i;
+}
+
+static void
+FreeScreen(pScreen)
+    ScreenPtr pScreen;
+{
+    xfree(pScreen->WindowPrivateSizes);
+    xfree(pScreen->GCPrivateSizes);
+#ifdef PIXPRIV
+    xfree(pScreen->PixmapPrivateSizes);
+#endif
+    xfree(pScreen->devPrivates);
+    xfree(pScreen);
+}
diff --git a/Xserver/programs/Xserver/dix/pixmap.c b/Xserver/programs/Xserver/dix/pixmap.c
new file mode 100644 (file)
index 0000000..ea3cc38
--- /dev/null
@@ -0,0 +1,150 @@
+/* $XConsortium: pixmap.c /main/4 1996/08/12 22:04:49 dpw $ */
+/* $XFree86: xc/programs/Xserver/dix/pixmap.c,v 3.1 1996/12/23 06:29:47 dawes Exp $ */
+/*
+
+Copyright (c) 1993  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be included
+in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR
+OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall
+not be used in advertising or otherwise to promote the sale, use or
+other dealings in this Software without prior written authorization
+from the X Consortium.
+
+*/
+
+#include "X.h"
+#include "scrnintstr.h"
+#include "misc.h"
+#include "os.h"
+#include "windowstr.h"
+#include "resource.h"
+#include "dixstruct.h"
+#include "gcstruct.h"
+#include "servermd.h"
+#include "site.h"
+
+
+/*
+ *  Scratch pixmap management and device independent pixmap allocation
+ *  function.
+ */
+
+
+/* callable by ddx */
+PixmapPtr
+GetScratchPixmapHeader(pScreen, width, height, depth, bitsPerPixel, devKind,
+                      pPixData)
+    ScreenPtr   pScreen;
+    int                width;
+    int                height;
+    int                depth;
+    int                bitsPerPixel;
+    int                devKind;
+    pointer     pPixData;
+{
+    PixmapPtr pPixmap = pScreen->pScratchPixmap;
+
+    if (pPixmap)
+       pScreen->pScratchPixmap = NULL;
+    else
+       /* width and height of 0 means don't allocate any pixmap data */
+       pPixmap = (*pScreen->CreatePixmap)(pScreen, 0, 0, depth);
+
+    if (pPixmap)
+       if ((*pScreen->ModifyPixmapHeader)(pPixmap, width, height, depth,
+                                          bitsPerPixel, devKind, pPixData))
+           return pPixmap;
+    return NullPixmap;
+}
+
+
+/* callable by ddx */
+void
+FreeScratchPixmapHeader(pPixmap)
+    PixmapPtr pPixmap;
+{
+    if (pPixmap)
+    {
+       ScreenPtr pScreen = pPixmap->drawable.pScreen;
+
+       pPixmap->devPrivate.ptr = NULL; /* lest ddx chases bad ptr */
+       if (pScreen->pScratchPixmap)
+           (*pScreen->DestroyPixmap)(pPixmap);
+       else
+           pScreen->pScratchPixmap = pPixmap;
+    }
+}
+
+
+Bool
+CreateScratchPixmapsForScreen(scrnum)
+    int scrnum;
+{
+    /* let it be created on first use */
+    screenInfo.screens[scrnum]->pScratchPixmap = NULL;
+    return TRUE;
+}
+
+
+void
+FreeScratchPixmapsForScreen(scrnum)
+    int scrnum;
+{
+    FreeScratchPixmapHeader(screenInfo.screens[scrnum]->pScratchPixmap);
+}
+
+
+/* callable by ddx */
+PixmapPtr
+AllocatePixmap(pScreen, pixDataSize)
+    ScreenPtr pScreen;
+    int pixDataSize;
+{
+    PixmapPtr pPixmap;
+#ifdef PIXPRIV
+    char *ptr;
+    DevUnion *ppriv;
+    unsigned *sizes;
+    unsigned size;
+    int i;
+
+    pPixmap = (PixmapPtr)xalloc(pScreen->totalPixmapSize + pixDataSize);
+    if (!pPixmap)
+       return NullPixmap;
+    ppriv = (DevUnion *)(pPixmap + 1);
+    pPixmap->devPrivates = ppriv;
+    sizes = pScreen->PixmapPrivateSizes;
+    ptr = (char *)(ppriv + pScreen->PixmapPrivateLen);
+    for (i = pScreen->PixmapPrivateLen; --i >= 0; ppriv++, sizes++)
+    {
+        if ((size = *sizes) != 0)
+        {
+           ppriv->ptr = (pointer)ptr;
+           ptr += size;
+        }
+        else
+           ppriv->ptr = (pointer)NULL;
+    }
+#else
+    pPixmap = (PixmapPtr)xalloc(sizeof(PixmapRec) + pixDataSize);
+#endif
+    return pPixmap;
+}
diff --git a/Xserver/programs/Xserver/dix/privates.c b/Xserver/programs/Xserver/dix/privates.c
new file mode 100644 (file)
index 0000000..9a1a156
--- /dev/null
@@ -0,0 +1,355 @@
+/* $XConsortium: privates.c /main/5 1996/06/17 10:56:22 mor $ */
+/* $XFree86: xc/programs/Xserver/dix/privates.c,v 3.2 1997/01/23 10:57:19 dawes Exp $ */
+/*
+
+Copyright (c) 1993  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be included
+in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR
+OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall
+not be used in advertising or otherwise to promote the sale, use or
+other dealings in this Software without prior written authorization
+from the X Consortium.
+
+*/
+
+#include "X.h"
+#include "scrnintstr.h"
+#include "misc.h"
+#include "os.h"
+#include "windowstr.h"
+#include "resource.h"
+#include "dixstruct.h"
+#include "gcstruct.h"
+#include "colormapst.h"
+#include "servermd.h"
+#include "site.h"
+
+/*
+ *  See the Wrappers and devPrivates section in "Definition of the
+ *  Porting Layer for the X v11 Sample Server" (doc/Server/ddx.tbl.ms)
+ *  for information on how to use devPrivates.
+ */
+
+/*
+ *  client private machinery
+ */
+
+static int  clientPrivateCount;
+int clientPrivateLen;
+unsigned *clientPrivateSizes;
+unsigned totalClientSize;
+
+void
+ResetClientPrivates()
+{
+    clientPrivateCount = 0;
+    clientPrivateLen = 0;
+    xfree(clientPrivateSizes);
+    clientPrivateSizes = (unsigned *)NULL;
+    totalClientSize = sizeof(ClientRec);
+
+}
+
+int
+AllocateClientPrivateIndex()
+{
+    return clientPrivateCount++;
+}
+
+Bool
+AllocateClientPrivate(index2, amount)
+    int index2;
+    unsigned amount;
+{
+    unsigned oldamount;
+
+    if (index2 >= clientPrivateLen)
+    {
+       unsigned *nsizes;
+       nsizes = (unsigned *)xrealloc(clientPrivateSizes,
+                                     (index2 + 1) * sizeof(unsigned));
+       if (!nsizes)
+           return FALSE;
+       while (clientPrivateLen <= index2)
+       {
+           nsizes[clientPrivateLen++] = 0;
+           totalClientSize += sizeof(DevUnion);
+       }
+       clientPrivateSizes = nsizes;
+    }
+    oldamount = clientPrivateSizes[index2];
+    if (amount > oldamount)
+    {
+       clientPrivateSizes[index2] = amount;
+       totalClientSize += (amount - oldamount);
+    }
+    return TRUE;
+}
+
+/*
+ *  screen private machinery
+ */
+
+int  screenPrivateCount;
+
+void
+ResetScreenPrivates()
+{
+    screenPrivateCount = 0;
+}
+
+/* this can be called after some screens have been created,
+ * so we have to worry about resizing existing devPrivates
+ */
+int
+AllocateScreenPrivateIndex()
+{
+    int                index2;
+    int                i;
+    ScreenPtr  pScreen;
+    DevUnion   *nprivs;
+
+    index2 = screenPrivateCount++;
+    for (i = 0; i < screenInfo.numScreens; i++)
+    {
+       pScreen = screenInfo.screens[i];
+       nprivs = (DevUnion *)xrealloc(pScreen->devPrivates,
+                                     screenPrivateCount * sizeof(DevUnion));
+       if (!nprivs)
+       {
+           screenPrivateCount--;
+           return -1;
+       }
+       pScreen->devPrivates = nprivs;
+    }
+    return index2;
+}
+
+
+/*
+ *  window private machinery
+ */
+
+static int  windowPrivateCount;
+
+void
+ResetWindowPrivates()
+{
+    windowPrivateCount = 0;
+}
+
+int
+AllocateWindowPrivateIndex()
+{
+    return windowPrivateCount++;
+}
+
+Bool
+AllocateWindowPrivate(pScreen, index2, amount)
+    register ScreenPtr pScreen;
+    int index2;
+    unsigned amount;
+{
+    unsigned oldamount;
+
+    if (index2 >= pScreen->WindowPrivateLen)
+    {
+       unsigned *nsizes;
+       nsizes = (unsigned *)xrealloc(pScreen->WindowPrivateSizes,
+                                     (index2 + 1) * sizeof(unsigned));
+       if (!nsizes)
+           return FALSE;
+       while (pScreen->WindowPrivateLen <= index2)
+       {
+           nsizes[pScreen->WindowPrivateLen++] = 0;
+           pScreen->totalWindowSize += sizeof(DevUnion);
+       }
+       pScreen->WindowPrivateSizes = nsizes;
+    }
+    oldamount = pScreen->WindowPrivateSizes[index2];
+    if (amount > oldamount)
+    {
+       pScreen->WindowPrivateSizes[index2] = amount;
+       pScreen->totalWindowSize += (amount - oldamount);
+    }
+    return TRUE;
+}
+
+
+/*
+ *  gc private machinery 
+ */
+
+static int  gcPrivateCount;
+
+void
+ResetGCPrivates()
+{
+    gcPrivateCount = 0;
+}
+
+int
+AllocateGCPrivateIndex()
+{
+    return gcPrivateCount++;
+}
+
+Bool
+AllocateGCPrivate(pScreen, index2, amount)
+    register ScreenPtr pScreen;
+    int index2;
+    unsigned amount;
+{
+    unsigned oldamount;
+
+    if (index2 >= pScreen->GCPrivateLen)
+    {
+       unsigned *nsizes;
+       nsizes = (unsigned *)xrealloc(pScreen->GCPrivateSizes,
+                                     (index2 + 1) * sizeof(unsigned));
+       if (!nsizes)
+           return FALSE;
+       while (pScreen->GCPrivateLen <= index2)
+       {
+           nsizes[pScreen->GCPrivateLen++] = 0;
+           pScreen->totalGCSize += sizeof(DevUnion);
+       }
+       pScreen->GCPrivateSizes = nsizes;
+    }
+    oldamount = pScreen->GCPrivateSizes[index2];
+    if (amount > oldamount)
+    {
+       pScreen->GCPrivateSizes[index2] = amount;
+       pScreen->totalGCSize += (amount - oldamount);
+    }
+    return TRUE;
+}
+
+
+/*
+ *  pixmap private machinery
+ */
+#ifdef PIXPRIV
+static int  pixmapPrivateCount;
+
+void
+ResetPixmapPrivates()
+{
+    pixmapPrivateCount = 0;
+}
+
+int
+AllocatePixmapPrivateIndex()
+{
+    return pixmapPrivateCount++;
+}
+
+Bool
+AllocatePixmapPrivate(pScreen, index2, amount)
+    register ScreenPtr pScreen;
+    int index2;
+    unsigned amount;
+{
+    unsigned oldamount;
+
+    if (index2 >= pScreen->PixmapPrivateLen)
+    {
+       unsigned *nsizes;
+       nsizes = (unsigned *)xrealloc(pScreen->PixmapPrivateSizes,
+                                     (index2 + 1) * sizeof(unsigned));
+       if (!nsizes)
+           return FALSE;
+       while (pScreen->PixmapPrivateLen <= index2)
+       {
+           nsizes[pScreen->PixmapPrivateLen++] = 0;
+           pScreen->totalPixmapSize += sizeof(DevUnion);
+       }
+       pScreen->PixmapPrivateSizes = nsizes;
+    }
+    oldamount = pScreen->PixmapPrivateSizes[index2];
+    if (amount > oldamount)
+    {
+       pScreen->PixmapPrivateSizes[index2] = amount;
+       pScreen->totalPixmapSize += (amount - oldamount);
+    }
+    pScreen->totalPixmapSize = BitmapBytePad(pScreen->totalPixmapSize * 8);
+    return TRUE;
+}
+#endif
+
+
+/*
+ *  colormap private machinery
+ */
+
+int  colormapPrivateCount;
+
+void
+ResetColormapPrivates()
+{
+    colormapPrivateCount = 0;
+}
+
+
+int
+AllocateColormapPrivateIndex (initPrivFunc)
+
+InitCmapPrivFunc initPrivFunc;
+
+{
+    int                index;
+    int                i;
+    ColormapPtr        pColormap;
+    DevUnion   *privs;
+
+    index = colormapPrivateCount++;
+
+    for (i = 0; i < screenInfo.numScreens; i++)
+    {
+       /*
+        * AllocateColormapPrivateIndex may be called after the
+        * default colormap has been created on each screen!
+        *
+        * We must resize the devPrivates array for the default
+        * colormap on each screen, making room for this new private.
+        * We also call the initialization function 'initPrivFunc' on
+        * the new private allocated for each default colormap.
+        */
+
+       ScreenPtr pScreen = screenInfo.screens[i];
+
+       pColormap = (ColormapPtr) LookupIDByType (
+           pScreen->defColormap, RT_COLORMAP);
+
+       privs = (DevUnion *) xrealloc (pColormap->devPrivates,
+           colormapPrivateCount * sizeof(DevUnion));
+
+       pColormap->devPrivates = privs;
+
+       if (!privs || !(*initPrivFunc)(pColormap))
+       {
+           colormapPrivateCount--;
+           return -1;
+       }
+    }
+
+    return index;
+}
diff --git a/Xserver/programs/Xserver/dix/property.c b/Xserver/programs/Xserver/dix/property.c
new file mode 100644 (file)
index 0000000..7a197f8
--- /dev/null
@@ -0,0 +1,743 @@
+/***********************************************************
+
+Copyright (c) 1987  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+
+Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
+
+                        All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and its 
+documentation for any purpose and without fee is hereby granted, 
+provided that the above copyright notice appear in all copies and that
+both that copyright notice and this permission notice appear in 
+supporting documentation, and that the name of Digital not be
+used in advertising or publicity pertaining to distribution of the
+software without specific, written prior permission.  
+
+DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
+ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
+DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
+ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+SOFTWARE.
+
+******************************************************************/
+/* $XConsortium: property.c /main/41 1996/12/22 12:33:58 rws $ */
+/* $XFree86: xc/programs/Xserver/dix/property.c,v 3.5 1996/12/24 11:52:04 dawes Exp $ */
+
+#include "X.h"
+#define NEED_REPLIES
+#define NEED_EVENTS
+#include "Xproto.h"
+#include "windowstr.h"
+#include "propertyst.h"
+#include "dixstruct.h"
+#include "dispatch.h"
+#include "swaprep.h"
+#ifdef XCSECURITY
+#define _SECURITY_SERVER
+#include "extensions/security.h"
+#endif
+
+#if defined(LBX) || defined(LBX_COMPAT)
+int fWriteToClient(client, len, buf)
+    ClientPtr   client;
+    int         len;
+    char        *buf;
+{
+    return WriteToClient(client, len, buf);
+}
+#endif
+
+/*****************************************************************
+ * Property Stuff
+ *
+ *    ChangeProperty, DeleteProperty, GetProperties,
+ *    ListProperties
+ *
+ *   Properties below to windows.  A allocate slots each time
+ *   a property is added.  No fancy searching done.
+ *
+ *****************************************************************/
+
+#ifdef notdef
+static void
+PrintPropertys(pWin)
+    WindowPtr pWin;
+{
+    PropertyPtr pProp;
+    register int j;
+
+    pProp = pWin->userProps;
+    while (pProp)
+    {
+        ErrorF(  "%x %x\n", pProp->propertyName, pProp->type);
+        ErrorF("property format: %d\n", pProp->format);
+        ErrorF("property data: \n");
+        for (j=0; j<(pProp->format/8)*pProp->size; j++)
+           ErrorF("%c\n", pProp->data[j]);
+        pProp = pProp->next;
+    }
+}
+#endif
+
+int
+ProcRotateProperties(client)
+    ClientPtr client;
+{
+    int     i, j, delta;
+    REQUEST(xRotatePropertiesReq);
+    WindowPtr pWin;
+    register    Atom * atoms;
+    PropertyPtr * props;               /* array of pointer */
+    PropertyPtr pProp;
+    xEvent event;
+
+    REQUEST_FIXED_SIZE(xRotatePropertiesReq, stuff->nAtoms << 2);
+    UpdateCurrentTime();
+    pWin = (WindowPtr) SecurityLookupWindow(stuff->window, client,
+                                           SecurityWriteAccess);
+    if (!pWin)
+        return(BadWindow);
+    if (!stuff->nAtoms)
+       return(Success);
+    atoms = (Atom *) & stuff[1];
+    props = (PropertyPtr *)ALLOCATE_LOCAL(stuff->nAtoms * sizeof(PropertyPtr));
+    if (!props)
+       return(BadAlloc);
+    for (i = 0; i < stuff->nAtoms; i++)
+    {
+#ifdef XCSECURITY
+       char action = SecurityCheckPropertyAccess(client, pWin, atoms[i],
+                               SecurityReadAccess|SecurityWriteAccess);
+#endif
+        if (!ValidAtom(atoms[i])
+#ifdef XCSECURITY
+           || (SecurityErrorOperation == action)
+#endif
+          )
+        {
+            DEALLOCATE_LOCAL(props);
+           client->errorValue = atoms[i];
+            return BadAtom;
+        }
+#ifdef XCSECURITY
+       if (SecurityIgnoreOperation == action)
+        {
+            DEALLOCATE_LOCAL(props);
+           return Success;
+       }
+#endif
+        for (j = i + 1; j < stuff->nAtoms; j++)
+            if (atoms[j] == atoms[i])
+            {
+                DEALLOCATE_LOCAL(props);
+                return BadMatch;
+            }
+        pProp = wUserProps (pWin);
+        while (pProp)
+        {
+            if (pProp->propertyName == atoms[i])
+                goto found;
+           pProp = pProp->next;
+        }
+        DEALLOCATE_LOCAL(props);
+        return BadMatch;
+found: 
+        props[i] = pProp;
+    }
+    delta = stuff->nPositions;
+
+    /* If the rotation is a complete 360 degrees, then moving the properties
+       around and generating PropertyNotify events should be skipped. */
+
+    if ( (stuff->nAtoms != 0) && (abs(delta) % stuff->nAtoms) != 0 ) 
+    {
+       while (delta < 0)                  /* faster if abs value is small */
+            delta += stuff->nAtoms;
+       for (i = 0; i < stuff->nAtoms; i++)
+       {
+           /* Generate a PropertyNotify event for each property whose value
+               is changed in the order in which they appear in the request. */
+           event.u.u.type = PropertyNotify;
+            event.u.property.window = pWin->drawable.id;
+           event.u.property.state = PropertyNewValue;
+           event.u.property.atom = props[i]->propertyName;     
+           event.u.property.time = currentTime.milliseconds;
+           DeliverEvents(pWin, &event, 1, (WindowPtr)NULL);
+       
+            props[i]->propertyName = atoms[(i + delta) % stuff->nAtoms];
+       }
+    }
+    DEALLOCATE_LOCAL(props);
+    return Success;
+}
+
+int 
+ProcChangeProperty(client)
+    ClientPtr client;
+{            
+    WindowPtr pWin;
+    char format, mode;
+    unsigned long len;
+    int sizeInBytes;
+    int totalSize;
+    int err;
+    REQUEST(xChangePropertyReq);
+
+    REQUEST_AT_LEAST_SIZE(xChangePropertyReq);
+    UpdateCurrentTime();
+    format = stuff->format;
+    mode = stuff->mode;
+    if ((mode != PropModeReplace) && (mode != PropModeAppend) &&
+       (mode != PropModePrepend))
+    {
+       client->errorValue = mode;
+       return BadValue;
+    }
+    if ((format != 8) && (format != 16) && (format != 32))
+    {
+       client->errorValue = format;
+        return BadValue;
+    }
+    len = stuff->nUnits;
+    if (len > ((0xffffffff - sizeof(xChangePropertyReq)) >> 2))
+       return BadLength;
+    sizeInBytes = format>>3;
+    totalSize = len * sizeInBytes;
+    REQUEST_FIXED_SIZE(xChangePropertyReq, totalSize);
+
+    pWin = (WindowPtr)SecurityLookupWindow(stuff->window, client,
+                                          SecurityWriteAccess);
+    if (!pWin)
+       return(BadWindow);
+    if (!ValidAtom(stuff->property))
+    {
+       client->errorValue = stuff->property;
+       return(BadAtom);
+    }
+    if (!ValidAtom(stuff->type))
+    {
+       client->errorValue = stuff->type;
+       return(BadAtom);
+    }
+
+#ifdef XCSECURITY
+    switch (SecurityCheckPropertyAccess(client, pWin, stuff->property,
+                                       SecurityWriteAccess))
+    {
+       case SecurityErrorOperation:
+           client->errorValue = stuff->property;
+           return BadAtom;
+       case SecurityIgnoreOperation:
+           return Success;
+    }
+#endif
+
+#ifdef LBX
+    err = LbxChangeWindowProperty(client, pWin, stuff->property, stuff->type,
+        (int)format, (int)mode, len, TRUE, (pointer)&stuff[1], TRUE, NULL);
+#else
+    err = ChangeWindowProperty(pWin, stuff->property, stuff->type, (int)format,
+                              (int)mode, len, (pointer)&stuff[1], TRUE);
+#endif
+    if (err != Success)
+       return err;
+    else
+       return client->noClientException;
+}
+
+int
+ChangeWindowProperty(pWin, property, type, format, mode, len, value, sendevent)
+    WindowPtr  pWin;
+    Atom       property, type;
+    int                format, mode;
+    unsigned long len;
+    pointer    value;
+    Bool       sendevent;
+{
+#ifdef LBX
+    return LbxChangeWindowProperty(NULL, pWin, property, type,
+                                  format, mode, len, TRUE, value,
+                                  sendevent, NULL);
+#else
+    PropertyPtr pProp;
+    xEvent event;
+    int sizeInBytes;
+    int totalSize;
+    pointer data;
+
+    sizeInBytes = format>>3;
+    totalSize = len * sizeInBytes;
+
+    /* first see if property already exists */
+
+    pProp = wUserProps (pWin);
+    while (pProp)
+    {
+       if (pProp->propertyName == property)
+           break;
+       pProp = pProp->next;
+    }
+    if (!pProp)   /* just add to list */
+    {
+       if (!pWin->optional && !MakeWindowOptional (pWin))
+           return(BadAlloc);
+        pProp = (PropertyPtr)xalloc(sizeof(PropertyRec));
+       if (!pProp)
+           return(BadAlloc);
+        data = (pointer)xalloc(totalSize);
+       if (!data && len)
+       {
+           xfree(pProp);
+           return(BadAlloc);
+       }
+        pProp->propertyName = property;
+        pProp->type = type;
+        pProp->format = format;
+        pProp->data = data;
+       if (len)
+           memmove((char *)data, (char *)value, totalSize);
+       pProp->size = len;
+        pProp->next = pWin->optional->userProps;
+        pWin->optional->userProps = pProp;
+    }
+    else
+    {
+       /* To append or prepend to a property the request format and type
+               must match those of the already defined property.  The
+               existing format and type are irrelevant when using the mode
+               "PropModeReplace" since they will be written over. */
+
+        if ((format != pProp->format) && (mode != PropModeReplace))
+           return(BadMatch);
+        if ((pProp->type != type) && (mode != PropModeReplace))
+            return(BadMatch);
+        if (mode == PropModeReplace)
+        {
+           if (totalSize != pProp->size * (pProp->format >> 3))
+           {
+               data = (pointer)xrealloc(pProp->data, totalSize);
+               if (!data && len)
+                   return(BadAlloc);
+               pProp->data = data;
+           }
+           if (len)
+               memmove((char *)pProp->data, (char *)value, totalSize);
+           pProp->size = len;
+           pProp->type = type;
+           pProp->format = format;
+       }
+       else if (len == 0)
+       {
+           /* do nothing */
+       }
+        else if (mode == PropModeAppend)
+        {
+           data = (pointer)xrealloc(pProp->data,
+                                    sizeInBytes * (len + pProp->size));
+           if (!data)
+               return(BadAlloc);
+            pProp->data = data;
+           memmove(&((char *)data)[pProp->size * sizeInBytes], 
+                   (char *)value,
+                 totalSize);
+            pProp->size += len;
+       }
+        else if (mode == PropModePrepend)
+        {
+            data = (pointer)xalloc(sizeInBytes * (len + pProp->size));
+           if (!data)
+               return(BadAlloc);
+           memmove(&((char *)data)[totalSize], (char *)pProp->data, 
+                 (int)(pProp->size * sizeInBytes));
+            memmove((char *)data, (char *)value, totalSize);
+           xfree(pProp->data);
+            pProp->data = data;
+            pProp->size += len;
+       }
+    }
+    if (sendevent)
+    {
+       event.u.u.type = PropertyNotify;
+       event.u.property.window = pWin->drawable.id;
+       event.u.property.state = PropertyNewValue;
+       event.u.property.atom = pProp->propertyName;
+       event.u.property.time = currentTime.milliseconds;
+       DeliverEvents(pWin, &event, 1, (WindowPtr)NULL);
+    }
+
+    /* Addition for RFB X server */
+    if (pWin->parent == NullWindow) {
+       extern void rfbRootPropertyChange();
+       rfbRootPropertyChange(pProp);
+    }
+
+    return(Success);
+#endif
+}
+
+int
+DeleteProperty(pWin, propName)
+    WindowPtr pWin;
+    Atom propName;
+{
+    PropertyPtr pProp, prevProp;
+    xEvent event;
+
+    if (!(pProp = wUserProps (pWin)))
+       return(Success);
+    prevProp = (PropertyPtr)NULL;
+    while (pProp)
+    {
+       if (pProp->propertyName == propName)
+           break;
+        prevProp = pProp;
+       pProp = pProp->next;
+    }
+    if (pProp) 
+    {              
+        if (prevProp == (PropertyPtr)NULL)      /* takes care of head */
+        {
+            if (!(pWin->optional->userProps = pProp->next))
+               CheckWindowOptionalNeed (pWin);
+        }
+       else
+        {
+            prevProp->next = pProp->next;
+        }
+#ifdef LBX
+       if (pProp->tag_id)
+           TagDeleteTag(pProp->tag_id);
+#endif
+       event.u.u.type = PropertyNotify;
+       event.u.property.window = pWin->drawable.id;
+       event.u.property.state = PropertyDelete;
+        event.u.property.atom = pProp->propertyName;
+       event.u.property.time = currentTime.milliseconds;
+       DeliverEvents(pWin, &event, 1, (WindowPtr)NULL);
+       xfree(pProp->data);
+        xfree(pProp);
+    }
+    return(Success);
+}
+
+void
+DeleteAllWindowProperties(pWin)
+    WindowPtr pWin;
+{
+    PropertyPtr pProp, pNextProp;
+    xEvent event;
+
+    pProp = wUserProps (pWin);
+    while (pProp)
+    {
+#ifdef LBX
+       if (pProp->tag_id)
+           TagDeleteTag(pProp->tag_id);
+#endif
+       event.u.u.type = PropertyNotify;
+       event.u.property.window = pWin->drawable.id;
+       event.u.property.state = PropertyDelete;
+       event.u.property.atom = pProp->propertyName;
+       event.u.property.time = currentTime.milliseconds;
+       DeliverEvents(pWin, &event, 1, (WindowPtr)NULL);
+       pNextProp = pProp->next;
+        xfree(pProp->data);
+        xfree(pProp);
+       pProp = pNextProp;
+    }
+}
+
+static int
+NullPropertyReply(client, propertyType, format, reply)
+    ClientPtr client;
+    ATOM propertyType;
+    int format;
+    xGetPropertyReply *reply;
+{
+    reply->nItems = 0;
+    reply->length = 0;
+    reply->bytesAfter = 0;
+    reply->propertyType = propertyType;
+    reply->format = format;
+    WriteReplyToClient(client, sizeof(xGenericReply), reply);
+    return(client->noClientException);
+}
+
+/*****************
+ * GetProperty
+ *    If type Any is specified, returns the property from the specified
+ *    window regardless of its type.  If a type is specified, returns the
+ *    property only if its type equals the specified type.
+ *    If delete is True and a property is returned, the property is also
+ *    deleted from the window and a PropertyNotify event is generated on the
+ *    window.
+ *****************/
+
+int
+ProcGetProperty(client)
+    ClientPtr client;
+{
+    PropertyPtr pProp, prevProp;
+    unsigned long n, len, ind;
+    WindowPtr pWin;
+    xGetPropertyReply reply;
+    REQUEST(xGetPropertyReq);
+
+    REQUEST_SIZE_MATCH(xGetPropertyReq);
+    if (stuff->delete)
+       UpdateCurrentTime();
+    pWin = (WindowPtr)SecurityLookupWindow(stuff->window, client,
+                                          SecurityReadAccess);
+    if (!pWin)
+       return BadWindow;
+
+    if (!ValidAtom(stuff->property))
+    {
+       client->errorValue = stuff->property;
+       return(BadAtom);
+    }
+    if ((stuff->delete != xTrue) && (stuff->delete != xFalse))
+    {
+       client->errorValue = stuff->delete;
+       return(BadValue);
+    }
+    if ((stuff->type != AnyPropertyType) && !ValidAtom(stuff->type))
+    {
+       client->errorValue = stuff->type;
+       return(BadAtom);
+    }
+
+    pProp = wUserProps (pWin);
+    prevProp = (PropertyPtr)NULL;
+    while (pProp)
+    {
+       if (pProp->propertyName == stuff->property) 
+           break;
+       prevProp = pProp;
+       pProp = pProp->next;
+    }
+
+    reply.type = X_Reply;
+    reply.sequenceNumber = client->sequence;
+    if (!pProp) 
+       return NullPropertyReply(client, None, 0, &reply);
+
+#ifdef XCSECURITY
+    {
+       Mask access_mode = SecurityReadAccess;
+
+       if (stuff->delete)
+           access_mode |= SecurityDestroyAccess;
+       switch(SecurityCheckPropertyAccess(client, pWin, stuff->property,
+                                          access_mode))
+       {
+           case SecurityErrorOperation:
+               client->errorValue = stuff->property;
+               return BadAtom;;
+           case SecurityIgnoreOperation:
+               return NullPropertyReply(client, pProp->type, pProp->format,
+                                        &reply);
+       }
+    }
+#endif
+    /* If the request type and actual type don't match. Return the
+    property information, but not the data. */
+
+    if (((stuff->type != pProp->type) &&
+        (stuff->type != AnyPropertyType))
+       )
+    {
+       reply.bytesAfter = pProp->size;
+       reply.format = pProp->format;
+       reply.length = 0;
+       reply.nItems = 0;
+       reply.propertyType = pProp->type;
+       WriteReplyToClient(client, sizeof(xGenericReply), &reply);
+       return(Success);
+    }
+#ifdef LBX
+    /* make sure we have the current value */                       
+    if (pProp->tag_id && pProp->owner_pid) {
+       LbxStallPropRequest(client, pProp);
+       return client->noClientException;
+    }                                              
+#endif
+
+/*
+ *  Return type, format, value to client
+ */
+    n = (pProp->format/8) * pProp->size; /* size (bytes) of prop */
+    ind = stuff->longOffset << 2;        
+
+   /* If longOffset is invalid such that it causes "len" to
+           be negative, it's a value error. */
+
+    if (n < ind)
+    {
+       client->errorValue = stuff->longOffset;
+       return BadValue;
+    }
+
+    len = min(n - ind, 4 * stuff->longLength);
+
+    reply.bytesAfter = n - (ind + len);
+    reply.format = pProp->format;
+    reply.length = (len + 3) >> 2;
+    reply.nItems = len / (pProp->format / 8 );
+    reply.propertyType = pProp->type;
+
+    if (stuff->delete && (reply.bytesAfter == 0))
+    { /* send the event */
+       xEvent event;
+
+       event.u.u.type = PropertyNotify;
+       event.u.property.window = pWin->drawable.id;
+       event.u.property.state = PropertyDelete;
+       event.u.property.atom = pProp->propertyName;
+       event.u.property.time = currentTime.milliseconds;
+       DeliverEvents(pWin, &event, 1, (WindowPtr)NULL);
+    }
+
+    WriteReplyToClient(client, sizeof(xGenericReply), &reply);
+    if (len)
+    {
+       switch (reply.format) {
+       case 32: client->pSwapReplyFunc = (ReplySwapPtr)CopySwap32Write; break;
+       case 16: client->pSwapReplyFunc = (ReplySwapPtr)CopySwap16Write; break;
+       default: client->pSwapReplyFunc = (ReplySwapPtr)WriteToClient; break;
+       }
+       WriteSwappedDataToClient(client, len,
+                                (char *)pProp->data + ind);
+    }
+
+    if (stuff->delete && (reply.bytesAfter == 0))
+    { /* delete the Property */
+#ifdef LBX
+       if (pProp->tag_id)
+           TagDeleteTag(pProp->tag_id);
+#endif
+       if (prevProp == (PropertyPtr)NULL) /* takes care of head */
+       {
+           if (!(pWin->optional->userProps = pProp->next))
+               CheckWindowOptionalNeed (pWin);
+       }
+       else
+           prevProp->next = pProp->next;
+       xfree(pProp->data);
+       xfree(pProp);
+    }
+    return(client->noClientException);
+}
+
+int
+ProcListProperties(client)
+    ClientPtr client;
+{
+    Atom *pAtoms, *temppAtoms;
+    xListPropertiesReply xlpr;
+    int        numProps = 0;
+    WindowPtr pWin;
+    PropertyPtr pProp;
+    REQUEST(xResourceReq);
+
+    REQUEST_SIZE_MATCH(xResourceReq);
+    pWin = (WindowPtr)SecurityLookupWindow(stuff->id, client,
+                                          SecurityReadAccess);
+    if (!pWin)
+        return(BadWindow);
+
+    pProp = wUserProps (pWin);
+    while (pProp)
+    {        
+        pProp = pProp->next;
+       numProps++;
+    }
+    if (numProps)
+        if(!(pAtoms = (Atom *)ALLOCATE_LOCAL(numProps * sizeof(Atom))))
+            return(BadAlloc);
+
+    xlpr.type = X_Reply;
+    xlpr.nProperties = numProps;
+    xlpr.length = (numProps * sizeof(Atom)) >> 2;
+    xlpr.sequenceNumber = client->sequence;
+    pProp = wUserProps (pWin);
+    temppAtoms = pAtoms;
+    while (pProp)
+    {
+       *temppAtoms++ = pProp->propertyName;
+       pProp = pProp->next;
+    }
+    WriteReplyToClient(client, sizeof(xGenericReply), &xlpr);
+    if (numProps)
+    {
+        client->pSwapReplyFunc = (ReplySwapPtr)Swap32Write;
+        WriteSwappedDataToClient(client, numProps * sizeof(Atom), pAtoms);
+        DEALLOCATE_LOCAL(pAtoms);
+    }
+    return(client->noClientException);
+}
+
+int 
+ProcDeleteProperty(client)
+    register ClientPtr client;
+{
+    WindowPtr pWin;
+    REQUEST(xDeletePropertyReq);
+    int result;
+              
+    REQUEST_SIZE_MATCH(xDeletePropertyReq);
+    UpdateCurrentTime();
+    pWin = (WindowPtr)SecurityLookupWindow(stuff->window, client,
+                                          SecurityWriteAccess);
+    if (!pWin)
+        return(BadWindow);
+    if (!ValidAtom(stuff->property))
+    {
+       client->errorValue = stuff->property;
+       return (BadAtom);
+    }
+
+#ifdef XCSECURITY
+    switch(SecurityCheckPropertyAccess(client, pWin, stuff->property,
+                                      SecurityDestroyAccess))
+    {
+       case SecurityErrorOperation:
+           client->errorValue = stuff->property;
+           return BadAtom;;
+       case SecurityIgnoreOperation:
+           return Success;
+    }
+#endif
+
+    result = DeleteProperty(pWin, stuff->property);
+    if (client->noClientException != Success)
+       return(client->noClientException);
+    else
+       return(result);
+}
diff --git a/Xserver/programs/Xserver/dix/resource.c b/Xserver/programs/Xserver/dix/resource.c
new file mode 100644 (file)
index 0000000..ba925f6
--- /dev/null
@@ -0,0 +1,871 @@
+/************************************************************
+
+Copyright (c) 1987  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+
+Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
+
+                        All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and its 
+documentation for any purpose and without fee is hereby granted, 
+provided that the above copyright notice appear in all copies and that
+both that copyright notice and this permission notice appear in 
+supporting documentation, and that the name of Digital not be
+used in advertising or publicity pertaining to distribution of the
+software without specific, written prior permission.  
+
+DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
+ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
+DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
+ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+SOFTWARE.
+
+********************************************************/
+
+/* $XConsortium: resource.c /main/39 1996/10/30 11:17:56 rws $ */
+/* $XFree86: xc/programs/Xserver/dix/resource.c,v 3.1 1996/12/23 06:29:51 dawes Exp $ */
+
+/*     Routines to manage various kinds of resources:
+ *
+ *     CreateNewResourceType, CreateNewResourceClass, InitClientResources,
+ *     FakeClientID, AddResource, FreeResource, FreeClientResources,
+ *     FreeAllResources, LookupIDByType, LookupIDByClass, GetXIDRange
+ */
+
+/* 
+ *      A resource ID is a 32 bit quantity, the upper 3 bits of which are
+ *     off-limits for client-visible resources.  The next 7 bits are
+ *      used as client ID, and the low 22 bits come from the client.
+ *     A resource ID is "hashed" by extracting and xoring subfields
+ *      (varying with the size of the hash table).
+ *
+ *      It is sometimes necessary for the server to create an ID that looks
+ *      like it belongs to a client.  This ID, however,  must not be one
+ *      the client actually can create, or we have the potential for conflict.
+ *      The 30th bit of the ID is reserved for the server's use for this
+ *      purpose.  By setting CLIENT_ID(id) to the client, the SERVER_BIT to
+ *      1, and an otherwise arbitrary ID in the low 22 bits, we can create a
+ *      resource "owned" by the client.
+ */
+
+#define NEED_EVENTS
+#include "X.h"
+#include "misc.h"
+#include "os.h"
+#include "resource.h"
+#include "dixstruct.h" 
+#include "opaque.h"
+#include "windowstr.h"
+#include "inputstr.h"
+#include "dixfont.h"
+#include "dixevents.h"
+#include "dixgrabs.h"
+#include "colormap.h"
+#include "cursor.h"
+#include <assert.h>
+
+extern WindowPtr *WindowTable;
+
+static void RebuildTable(
+#if NeedFunctionPrototypes
+    int /*client*/
+#endif
+);
+
+#define SERVER_MINID 32
+
+#define INITBUCKETS 64
+#define INITHASHSIZE 6
+#define MAXHASHSIZE 11
+
+typedef struct _Resource {
+    struct _Resource   *next;
+    XID                        id;
+    RESTYPE            type;
+    pointer            value;
+} ResourceRec, *ResourcePtr;
+#define NullResource ((ResourcePtr)NULL)
+
+typedef struct _ClientResource {
+    ResourcePtr *resources;
+    int                elements;
+    int                buckets;
+    int                hashsize;       /* log(2)(buckets) */
+    XID                fakeID;
+    XID                endFakeID;
+    XID                expectID;
+} ClientResourceRec;
+
+static RESTYPE lastResourceType;
+static RESTYPE lastResourceClass;
+static RESTYPE TypeMask;
+
+static DeleteType *DeleteFuncs = (DeleteType *)NULL;
+
+RESTYPE
+CreateNewResourceType(deleteFunc)
+    DeleteType deleteFunc;
+{
+    RESTYPE next = lastResourceType + 1;
+    DeleteType *funcs;
+
+    if (next & lastResourceClass)
+       return 0;
+    funcs = (DeleteType *)xrealloc(DeleteFuncs,
+                                  (next + 1) * sizeof(DeleteType));
+    if (!funcs)
+       return 0;
+    lastResourceType = next;
+    DeleteFuncs = funcs;
+    DeleteFuncs[next] = deleteFunc;
+    return next;
+}
+
+RESTYPE
+CreateNewResourceClass()
+{
+    RESTYPE next = lastResourceClass >> 1;
+
+    if (next & lastResourceType)
+       return 0;
+    lastResourceClass = next;
+    TypeMask = next - 1;
+    return next;
+}
+
+ClientResourceRec clientTable[MAXCLIENTS];
+
+/*****************
+ * InitClientResources
+ *    When a new client is created, call this to allocate space
+ *    in resource table
+ *****************/
+
+Bool
+InitClientResources(client)
+    ClientPtr client;
+{
+    register int i, j;
+    if (client == serverClient)
+    {
+       lastResourceType = RT_LASTPREDEF;
+       lastResourceClass = RC_LASTPREDEF;
+       TypeMask = RC_LASTPREDEF - 1;
+       if (DeleteFuncs)
+           xfree(DeleteFuncs);
+       DeleteFuncs = (DeleteType *)xalloc((lastResourceType + 1) *
+                                          sizeof(DeleteType));
+       if (!DeleteFuncs)
+           return FALSE;
+       DeleteFuncs[RT_NONE & TypeMask] = (DeleteType)NoopDDA;
+       DeleteFuncs[RT_WINDOW & TypeMask] = DeleteWindow;
+       DeleteFuncs[RT_PIXMAP & TypeMask] = dixDestroyPixmap;
+       DeleteFuncs[RT_GC & TypeMask] = FreeGC;
+       DeleteFuncs[RT_FONT & TypeMask] = CloseFont;
+       DeleteFuncs[RT_CURSOR & TypeMask] = FreeCursor;
+       DeleteFuncs[RT_COLORMAP & TypeMask] = FreeColormap;
+       DeleteFuncs[RT_CMAPENTRY & TypeMask] = FreeClientPixels;
+       DeleteFuncs[RT_OTHERCLIENT & TypeMask] = OtherClientGone;
+       DeleteFuncs[RT_PASSIVEGRAB & TypeMask] = DeletePassiveGrab;
+    }
+    clientTable[i = client->index].resources =
+       (ResourcePtr *)xalloc(INITBUCKETS*sizeof(ResourcePtr));
+    if (!clientTable[i].resources)
+       return FALSE;
+    clientTable[i].buckets = INITBUCKETS;
+    clientTable[i].elements = 0;
+    clientTable[i].hashsize = INITHASHSIZE;
+    /* Many IDs allocated from the server client are visible to clients,
+     * so we don't use the SERVER_BIT for them, but we have to start
+     * past the magic value constants used in the protocol.  For normal
+     * clients, we can start from zero, with SERVER_BIT set.
+     */
+    clientTable[i].fakeID = client->clientAsMask |
+                           (client->index ? SERVER_BIT : SERVER_MINID);
+    clientTable[i].endFakeID = (clientTable[i].fakeID | RESOURCE_ID_MASK) + 1;
+    clientTable[i].expectID = client->clientAsMask;
+    for (j=0; j<INITBUCKETS; j++) 
+    {
+        clientTable[i].resources[j] = NullResource;
+    }
+    return TRUE;
+}
+
+static int
+#if NeedFunctionPrototypes
+Hash(int client, register XID id)
+#else
+Hash(client, id)
+    int client;
+    register XID id;
+#endif
+{
+    id &= RESOURCE_ID_MASK;
+    switch (clientTable[client].hashsize)
+    {
+       case 6:
+           return ((int)(0x03F & (id ^ (id>>6) ^ (id>>12))));
+       case 7:
+           return ((int)(0x07F & (id ^ (id>>7) ^ (id>>13))));
+       case 8:
+           return ((int)(0x0FF & (id ^ (id>>8) ^ (id>>16))));
+       case 9:
+           return ((int)(0x1FF & (id ^ (id>>9))));
+       case 10:
+           return ((int)(0x3FF & (id ^ (id>>10))));
+       case 11:
+           return ((int)(0x7FF & (id ^ (id>>11))));
+    }
+    return -1;
+}
+
+static XID
+#if NeedFunctionPrototypes
+AvailableID(
+    register int client,
+    register XID id,
+    register XID maxid,
+    register XID goodid)
+#else
+AvailableID(client, id, maxid, goodid)
+    register int client;
+    register XID id, maxid, goodid;
+#endif
+{
+    register ResourcePtr res;
+
+    if ((goodid >= id) && (goodid <= maxid))
+       return goodid;
+    for (; id <= maxid; id++)
+    {
+       res = clientTable[client].resources[Hash(client, id)];
+       while (res && (res->id != id))
+           res = res->next;
+       if (!res)
+           return id;
+    }
+    return 0;
+}
+
+void
+GetXIDRange(client, server, minp, maxp)
+    int client;
+    Bool server;
+    XID *minp, *maxp;
+{
+    register XID id, maxid;
+    register ResourcePtr *resp;
+    register ResourcePtr res;
+    register int i;
+    XID goodid;
+
+    id = (Mask)client << CLIENTOFFSET;
+    if (server)
+       id |= client ? SERVER_BIT : SERVER_MINID;
+    maxid = id | RESOURCE_ID_MASK;
+    goodid = 0;
+    for (resp = clientTable[client].resources, i = clientTable[client].buckets;
+        --i >= 0;)
+    {
+       for (res = *resp++; res; res = res->next)
+       {
+           if ((res->id < id) || (res->id > maxid))
+               continue;
+           if (((res->id - id) >= (maxid - res->id)) ?
+               (goodid = AvailableID(client, id, res->id - 1, goodid)) :
+               !(goodid = AvailableID(client, res->id + 1, maxid, goodid)))
+               maxid = res->id - 1;
+           else
+               id = res->id + 1;
+       }
+    }
+    if (id > maxid)
+       id = maxid = 0;
+    *minp = id;
+    *maxp = maxid;
+}
+
+/*  GetXIDList is called by the XC-MISC extension's MiscGetXIDList function.
+ *  This function tries to find count unused XIDs for the given client.  It 
+ *  puts the IDs in the array pids and returns the number found, which should
+ *  almost always be the number requested.
+ *
+ *  The circumstances that lead to a call to this function are very rare.
+ *  Xlib must run out of IDs while trying to generate a request that wants
+ *  multiple ID's, like the Multi-buffering CreateImageBuffers request.
+ *
+ *  No rocket science in the implementation; just iterate over all
+ *  possible IDs for the given client and pick the first count IDs
+ *  that aren't in use.  A more efficient algorithm could probably be
+ *  invented, but this will be used so rarely that this should suffice.
+ */
+
+unsigned int
+GetXIDList(pClient, count, pids)
+    ClientPtr pClient;
+    unsigned int count;
+    XID *pids;
+{
+    unsigned int found = 0;
+    XID id = pClient->clientAsMask;
+    XID maxid;
+
+    maxid = id | RESOURCE_ID_MASK;
+    while ( (found < count) && (id <= maxid) )
+    {
+       if (!LookupIDByClass(id, RC_ANY))
+       {
+           pids[found++] = id;
+       }
+       id++;
+    }
+    return found;
+}
+
+/*
+ * Return the next usable fake client ID.
+ *
+ * Normally this is just the next one in line, but if we've used the last
+ * in the range, we need to find a new range of safe IDs to avoid
+ * over-running another client.
+ */
+
+XID
+FakeClientID(client)
+    register int client;
+{
+    XID id, maxid;
+
+    id = clientTable[client].fakeID++;
+    if (id != clientTable[client].endFakeID)
+       return id;
+    GetXIDRange(client, TRUE, &id, &maxid);
+    if (!id) {
+       if (!client)
+           FatalError("FakeClientID: server internal ids exhausted\n");
+       MarkClientException(clients[client]);
+       id = ((Mask)client << CLIENTOFFSET) | (SERVER_BIT * 3);
+       maxid = id | RESOURCE_ID_MASK;
+    }
+    clientTable[client].fakeID = id + 1;
+    clientTable[client].endFakeID = maxid + 1;
+    return id;
+}
+
+Bool
+AddResource(id, type, value)
+    XID id;
+    RESTYPE type;
+    pointer value;
+{
+    int client;
+    register ClientResourceRec *rrec;
+    register ResourcePtr res, *head;
+       
+    client = CLIENT_ID(id);
+    rrec = &clientTable[client];
+    if (!rrec->buckets)
+    {
+       ErrorF("AddResource(%x, %x, %x), client=%d \n",
+               id, type, (unsigned long)value, client);
+        FatalError("client not in use\n");
+    }
+    if ((rrec->elements >= 4*rrec->buckets) &&
+       (rrec->hashsize < MAXHASHSIZE))
+       RebuildTable(client);
+    head = &rrec->resources[Hash(client, id)];
+    res = (ResourcePtr)xalloc(sizeof(ResourceRec));
+    if (!res)
+    {
+       (*DeleteFuncs[type & TypeMask])(value, id);
+       return FALSE;
+    }
+    res->next = *head;
+    res->id = id;
+    res->type = type;
+    res->value = value;
+    *head = res;
+    rrec->elements++;
+    if (!(id & SERVER_BIT) && (id >= rrec->expectID))
+       rrec->expectID = id + 1;
+    return TRUE;
+}
+
+static void
+RebuildTable(client)
+    int client;
+{
+    register int j;
+    register ResourcePtr res, next;
+    ResourcePtr **tails, *resources;
+    register ResourcePtr **tptr, *rptr;
+
+    /*
+     * For now, preserve insertion order, since some ddx layers depend
+     * on resources being free in the opposite order they are added.
+     */
+
+    j = 2 * clientTable[client].buckets;
+    tails = (ResourcePtr **)ALLOCATE_LOCAL(j * sizeof(ResourcePtr *));
+    if (!tails)
+       return;
+    resources = (ResourcePtr *)xalloc(j * sizeof(ResourcePtr));
+    if (!resources)
+    {
+       DEALLOCATE_LOCAL(tails);
+       return;
+    }
+    for (rptr = resources, tptr = tails; --j >= 0; rptr++, tptr++)
+    {
+       *rptr = NullResource;
+       *tptr = rptr;
+    }
+    clientTable[client].hashsize++;
+    for (j = clientTable[client].buckets,
+        rptr = clientTable[client].resources;
+        --j >= 0;
+        rptr++)
+    {
+       for (res = *rptr; res; res = next)
+       {
+           next = res->next;
+           res->next = NullResource;
+           tptr = &tails[Hash(client, res->id)];
+           **tptr = res;
+           *tptr = &res->next;
+       }
+    }
+    DEALLOCATE_LOCAL(tails);
+    clientTable[client].buckets *= 2;
+    xfree(clientTable[client].resources);
+    clientTable[client].resources = resources;
+}
+
+void
+FreeResource(id, skipDeleteFuncType)
+    XID id;
+    RESTYPE skipDeleteFuncType;
+{
+    int                cid;
+    register    ResourcePtr res;
+    register   ResourcePtr *prev, *head;
+    register   int *eltptr;
+    int                elements;
+    Bool       gotOne = FALSE;
+
+    if (((cid = CLIENT_ID(id)) < MAXCLIENTS) && clientTable[cid].buckets)
+    {
+       head = &clientTable[cid].resources[Hash(cid, id)];
+       eltptr = &clientTable[cid].elements;
+
+       prev = head;
+       while ( (res = *prev) )
+       {
+           if (res->id == id)
+           {
+               RESTYPE rtype = res->type;
+               *prev = res->next;
+               elements = --*eltptr;
+               if (rtype & RC_CACHED)
+                   FlushClientCaches(res->id);
+               if (rtype != skipDeleteFuncType)
+                   (*DeleteFuncs[rtype & TypeMask])(res->value, res->id);
+               xfree(res);
+               if (*eltptr != elements)
+                   prev = head; /* prev may no longer be valid */
+               gotOne = TRUE;
+           }
+           else
+               prev = &res->next;
+        }
+       if(clients[cid] && (id == clients[cid]->lastDrawableID))
+       {
+           clients[cid]->lastDrawable = (DrawablePtr)WindowTable[0];
+           clients[cid]->lastDrawableID = WindowTable[0]->drawable.id;
+       }
+    }
+    if (!gotOne)
+       FatalError("Freeing resource id=%X which isn't there", id);
+}
+
+
+void
+FreeResourceByType(id, type, skipFree)
+    XID id;
+    RESTYPE type;
+    Bool    skipFree;
+{
+    int                cid;
+    register    ResourcePtr res;
+    register   ResourcePtr *prev, *head;
+
+    if (((cid = CLIENT_ID(id)) < MAXCLIENTS) && clientTable[cid].buckets)
+    {
+       head = &clientTable[cid].resources[Hash(cid, id)];
+
+       prev = head;
+       while ( (res = *prev) )
+       {
+           if (res->id == id && res->type == type)
+           {
+               *prev = res->next;
+               if (type & RC_CACHED)
+                   FlushClientCaches(res->id);
+               if (!skipFree)
+                   (*DeleteFuncs[type & TypeMask])(res->value, res->id);
+               xfree(res);
+               break;
+           }
+           else
+               prev = &res->next;
+        }
+       if(clients[cid] && (id == clients[cid]->lastDrawableID))
+       {
+           clients[cid]->lastDrawable = (DrawablePtr)WindowTable[0];
+           clients[cid]->lastDrawableID = WindowTable[0]->drawable.id;
+       }
+    }
+}
+
+/*
+ * Change the value associated with a resource id.  Caller
+ * is responsible for "doing the right thing" with the old
+ * data
+ */
+
+Bool
+ChangeResourceValue (id, rtype, value)
+    XID        id;
+    RESTYPE rtype;
+    pointer value;
+{
+    int    cid;
+    register    ResourcePtr res;
+
+    if (((cid = CLIENT_ID(id)) < MAXCLIENTS) && clientTable[cid].buckets)
+    {
+       res = clientTable[cid].resources[Hash(cid, id)];
+
+       for (; res; res = res->next)
+           if ((res->id == id) && (res->type == rtype))
+           {
+               if (rtype & RC_CACHED)
+                   FlushClientCaches(res->id);
+               res->value = value;
+               return TRUE;
+           }
+    }
+    return FALSE;
+}
+
+/* Note: if func adds or deletes resources, then func can get called
+ * more than once for some resources.  If func adds new resources,
+ * func might or might not get called for them.  func cannot both
+ * add and delete an equal number of resources!
+ */
+
+void
+FindClientResourcesByType(client, type, func, cdata)
+    ClientPtr client;
+    RESTYPE type;
+    FindResType func;
+    pointer cdata;
+{
+    register ResourcePtr *resources;
+    register ResourcePtr this, next;
+    int i, elements;
+    register int *eltptr;
+
+    if (!client)
+       client = serverClient;
+
+    resources = clientTable[client->index].resources;
+    eltptr = &clientTable[client->index].elements;
+    for (i = 0; i < clientTable[client->index].buckets; i++) 
+    {
+        for (this = resources[i]; this; this = next)
+       {
+           next = this->next;
+           if (!type || this->type == type) {
+               elements = *eltptr;
+               (*func)(this->value, this->id, cdata);
+               if (*eltptr != elements)
+                   next = resources[i]; /* start over */
+           }
+       }
+    }
+}
+
+void
+FreeClientNeverRetainResources(client)
+    ClientPtr client;
+{
+    ResourcePtr *resources;
+    ResourcePtr this;
+    ResourcePtr *prev;
+    int j;
+
+    if (!client)
+       return;
+
+    resources = clientTable[client->index].resources;
+    for (j=0; j < clientTable[client->index].buckets; j++) 
+    {
+       prev = &resources[j];
+        while ( (this = *prev) )
+       {
+           RESTYPE rtype = this->type;
+           if (rtype & RC_NEVERRETAIN)
+           {
+               *prev = this->next;
+               if (rtype & RC_CACHED)
+                   FlushClientCaches(this->id);
+               (*DeleteFuncs[rtype & TypeMask])(this->value, this->id);
+               xfree(this);        
+           }
+           else
+               prev = &this->next;
+       }
+    }
+}
+
+void
+FreeClientResources(client)
+    ClientPtr client;
+{
+    register ResourcePtr *resources;
+    register ResourcePtr this;
+    int j;
+
+    /* This routine shouldn't be called with a null client, but just in
+       case ... */
+
+    if (!client)
+       return;
+
+    HandleSaveSet(client);
+
+    resources = clientTable[client->index].resources;
+    for (j=0; j < clientTable[client->index].buckets; j++) 
+    {
+        /* It may seem silly to update the head of this resource list as
+       we delete the members, since the entire list will be deleted any way, 
+       but there are some resource deletion functions "FreeClientPixels" for 
+       one which do a LookupID on another resource id (a Colormap id in this
+       case), so the resource list must be kept valid up to the point that
+       it is deleted, so every time we delete a resource, we must update the
+       head, just like in FreeResource. I hope that this doesn't slow down
+       mass deletion appreciably. PRH */
+
+       ResourcePtr *head;
+
+       head = &resources[j];
+
+        for (this = *head; this; this = *head)
+       {
+           RESTYPE rtype = this->type;
+           *head = this->next;
+           if (rtype & RC_CACHED)
+               FlushClientCaches(this->id);
+           (*DeleteFuncs[rtype & TypeMask])(this->value, this->id);
+           xfree(this);            
+       }
+    }
+    xfree(clientTable[client->index].resources);
+    clientTable[client->index].buckets = 0;
+}
+
+void
+FreeAllResources()
+{
+    int        i;
+
+    for (i = currentMaxClients; --i >= 0; ) 
+    {
+        if (clientTable[i].buckets) 
+           FreeClientResources(clients[i]);
+    }
+}
+
+Bool
+LegalNewID(id, client)
+    XID id;
+    register ClientPtr client;
+{
+    return ((client->clientAsMask == (id & ~RESOURCE_ID_MASK)) &&
+           ((clientTable[client->index].expectID <= id) ||
+            !LookupIDByClass(id, RC_ANY)));
+}
+
+#ifdef XCSECURITY
+
+/* SecurityLookupIDByType and SecurityLookupIDByClass:
+ * These are the heart of the resource ID security system.  They take
+ * two additional arguments compared to the old LookupID functions:
+ * the client doing the lookup, and the access mode (see resource.h).
+ * The resource is returned if it exists and the client is allowed access,
+ * else NULL is returned.
+ */
+
+pointer
+SecurityLookupIDByType(client, id, rtype, mode)
+    ClientPtr client;
+    XID id;
+    RESTYPE rtype;
+    Mask mode;
+{
+    int    cid;
+    register    ResourcePtr res;
+    pointer retval = NULL;
+
+    assert(client == NullClient ||
+     (client->index <= currentMaxClients && clients[client->index] == client));
+    assert( (rtype & TypeMask) <= lastResourceType);
+
+    if (((cid = CLIENT_ID(id)) < MAXCLIENTS) &&
+       clientTable[cid].buckets)
+    {
+       res = clientTable[cid].resources[Hash(cid, id)];
+
+       for (; res; res = res->next)
+           if ((res->id == id) && (res->type == rtype))
+           {
+               retval = res->value;
+               break;
+           }
+    }
+    if (retval && client && client->CheckAccess)
+       retval = (* client->CheckAccess)(client, id, rtype, mode, retval);
+    return retval;
+}
+
+
+pointer
+SecurityLookupIDByClass(client, id, classes, mode)
+    ClientPtr client;
+    XID id;
+    RESTYPE classes;
+    Mask mode;
+{
+    int    cid;
+    register    ResourcePtr res;
+    pointer retval = NULL;
+
+    assert(client == NullClient ||
+     (client->index <= currentMaxClients && clients[client->index] == client));
+    assert (classes >= lastResourceClass);
+
+    if (((cid = CLIENT_ID(id)) < MAXCLIENTS) &&
+       clientTable[cid].buckets)
+    {
+       res = clientTable[cid].resources[Hash(cid, id)];
+
+       for (; res; res = res->next)
+           if ((res->id == id) && (res->type & classes))
+           {
+               retval = res->value;
+               break;
+           }
+    }
+    if (retval && client && client->CheckAccess)
+       retval = (* client->CheckAccess)(client, id, classes, mode, retval);
+    return retval;
+}
+
+/* We can't replace the LookupIDByType and LookupIDByClass functions with
+ * macros because of compatibility with loadable servers.
+ */
+
+pointer
+LookupIDByType(id, rtype)
+    XID id;
+    RESTYPE rtype;
+{
+    return SecurityLookupIDByType(NullClient, id, rtype,
+                                 SecurityUnknownAccess);
+}
+
+pointer
+LookupIDByClass(id, classes)
+    XID id;
+    RESTYPE classes;
+{
+    return SecurityLookupIDByClass(NullClient, id, classes,
+                                  SecurityUnknownAccess);
+}
+
+#else /* not XCSECURITY */
+
+/*
+ *  LookupIDByType returns the object with the given id and type, else NULL.
+ */ 
+pointer
+LookupIDByType(id, rtype)
+    XID id;
+    RESTYPE rtype;
+{
+    int    cid;
+    register    ResourcePtr res;
+
+    if (((cid = CLIENT_ID(id)) < MAXCLIENTS) &&
+       clientTable[cid].buckets)
+    {
+       res = clientTable[cid].resources[Hash(cid, id)];
+
+       for (; res; res = res->next)
+           if ((res->id == id) && (res->type == rtype))
+               return res->value;
+    }
+    return (pointer)NULL;
+}
+
+/*
+ *  LookupIDByClass returns the object with the given id and any one of the
+ *  given classes, else NULL.
+ */ 
+pointer
+LookupIDByClass(id, classes)
+    XID id;
+    RESTYPE classes;
+{
+    int    cid;
+    register    ResourcePtr res;
+
+    if (((cid = CLIENT_ID(id)) < MAXCLIENTS) &&
+       clientTable[cid].buckets)
+    {
+       res = clientTable[cid].resources[Hash(cid, id)];
+
+       for (; res; res = res->next)
+           if ((res->id == id) && (res->type & classes))
+               return res->value;
+    }
+    return (pointer)NULL;
+}
+
+#endif /* XCSECURITY */
diff --git a/Xserver/programs/Xserver/dix/swaprep.c b/Xserver/programs/Xserver/dix/swaprep.c
new file mode 100644 (file)
index 0000000..9e3ff9e
--- /dev/null
@@ -0,0 +1,1465 @@
+/************************************************************
+
+Copyright (c) 1987  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+
+Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
+
+                        All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and its 
+documentation for any purpose and without fee is hereby granted, 
+provided that the above copyright notice appear in all copies and that
+both that copyright notice and this permission notice appear in 
+supporting documentation, and that the name of Digital not be
+used in advertising or publicity pertaining to distribution of the
+software without specific, written prior permission.  
+
+DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
+ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
+DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
+ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+SOFTWARE.
+
+********************************************************/
+
+/* $XConsortium: swaprep.c /main/25 1995/12/08 13:39:45 dpw $ */
+/* $XFree86: xc/programs/Xserver/dix/swaprep.c,v 3.2 1996/04/15 11:19:58 dawes Exp $ */
+
+#include "X.h"
+#define NEED_REPLIES
+#define NEED_EVENTS
+#include "Xproto.h"
+#include "misc.h"
+#include "dixstruct.h"
+#include "fontstruct.h"
+#include "scrnintstr.h"
+#include "swaprep.h"
+
+static void SwapFontInfo(
+#if NeedFunctionPrototypes
+    xQueryFontReply * /* pr */
+#endif
+);
+
+#ifndef LBX
+static void SwapCharInfo(
+#if NeedFunctionPrototypes
+    xCharInfo * /* pInfo */
+#endif
+    );
+
+static void SwapFont(
+#if NeedFunctionPrototypes
+    xQueryFontReply * /* pr */,
+    Bool /* hasGlyphs */
+#endif
+    );
+#endif
+
+/* Thanks to Jack Palevich for testing and subsequently rewriting all this */
+void
+Swap32Write(pClient, size, pbuf)
+    ClientPtr  pClient;
+    int                size;  /* in bytes */
+    register CARD32 *pbuf;
+{
+    register int i;
+    register char n;
+
+    size >>= 2;
+    for(i = 0; i < size; i++)
+    /* brackets are mandatory here, because "swapl" macro expands
+       to several statements */
+    {   
+       swapl(&pbuf[i], n);
+    }
+    (void)WriteToClient(pClient, size << 2, (char *) pbuf);
+}
+
+void
+CopySwap32Write(pClient, size, pbuf)
+    ClientPtr  pClient;
+    int                size;   /* in bytes */
+    CARD32     *pbuf;
+{
+    int bufsize = size;
+    CARD32 *pbufT;
+    register CARD32 *from, *to, *fromLast, *toLast;
+    CARD32 tmpbuf[1];
+    
+    /* Allocate as big a buffer as we can... */
+    while (!(pbufT = (CARD32 *) ALLOCATE_LOCAL(bufsize)))
+    {
+        bufsize >>= 1;
+       if (bufsize == 4)
+       {
+           pbufT = tmpbuf;
+           break;
+       }
+    }
+    
+    /* convert lengths from # of bytes to # of longs */
+    size >>= 2;
+    bufsize >>= 2;
+
+    from = pbuf;
+    fromLast = from + size;
+    while (from < fromLast) {
+       int nbytes;
+        to = pbufT;
+        toLast = to + min (bufsize, fromLast - from);
+        nbytes = (toLast - to) << 2;
+        while (to < toLast) {
+            /* can't write "cpswapl(*from++, *to++)" because cpswapl is a macro
+              that evaulates its args more than once */
+           cpswapl(*from, *to);
+            from++;
+            to++;
+           }
+       (void)WriteToClient (pClient, nbytes, (char *) pbufT);
+       }
+
+    if (pbufT != tmpbuf)
+       DEALLOCATE_LOCAL ((char *) pbufT);
+}
+
+void
+CopySwap16Write(pClient, size, pbuf)
+    ClientPtr  pClient;
+    int                size;   /* in bytes */
+    short      *pbuf;
+{
+    int bufsize = size;
+    short *pbufT;
+    register short *from, *to, *fromLast, *toLast;
+    short tmpbuf[2];
+    
+    /* Allocate as big a buffer as we can... */
+    while (!(pbufT = (short *) ALLOCATE_LOCAL(bufsize)))
+    {
+        bufsize >>= 1;
+       if (bufsize == 4)
+       {
+           pbufT = tmpbuf;
+           break;
+       }
+    }
+    
+    /* convert lengths from # of bytes to # of shorts */
+    size >>= 1;
+    bufsize >>= 1;
+
+    from = pbuf;
+    fromLast = from + size;
+    while (from < fromLast) {
+       int nbytes;
+        to = pbufT;
+        toLast = to + min (bufsize, fromLast - from);
+        nbytes = (toLast - to) << 1;
+        while (to < toLast) {
+            /* can't write "cpswaps(*from++, *to++)" because cpswaps is a macro
+              that evaulates its args more than once */
+           cpswaps(*from, *to);
+            from++;
+            to++;
+           }
+       (void)WriteToClient (pClient, nbytes, (char *) pbufT);
+       }
+
+    if (pbufT != tmpbuf)
+       DEALLOCATE_LOCAL ((char *) pbufT);
+}
+
+
+/* Extra-small reply */
+void
+SGenericReply(pClient, size, pRep)
+    ClientPtr                  pClient;
+    int                                size;
+    xGenericReply              *pRep;
+{
+    register char n;
+
+    swaps(&pRep->sequenceNumber, n);
+    (void)WriteToClient(pClient, size, (char *) pRep);
+}
+
+/* Extra-large reply */
+void
+SGetWindowAttributesReply(pClient, size, pRep)
+    ClientPtr                  pClient;
+    int                                size;
+    xGetWindowAttributesReply  *pRep;
+{
+    register char n;
+
+    swaps(&pRep->sequenceNumber, n);
+    swapl(&pRep->length, n);
+    swapl(&pRep->visualID, n);
+    swaps(&pRep->class, n);
+    swapl(&pRep->backingBitPlanes, n);
+    swapl(&pRep->backingPixel, n);
+    swapl(&pRep->colormap, n);
+    swapl(&pRep->allEventMasks, n);
+    swapl(&pRep->yourEventMask, n);
+    swaps(&pRep->doNotPropagateMask, n);
+    (void)WriteToClient(pClient, size, (char *) pRep);
+}
+
+void
+SGetGeometryReply(pClient, size, pRep)
+    ClientPtr          pClient;
+    int                        size;
+    xGetGeometryReply  *pRep;
+{
+    register char n;
+
+    swaps(&pRep->sequenceNumber, n);
+    swapl(&pRep->root, n);
+    swaps(&pRep->x, n);
+    swaps(&pRep->y, n);
+    swaps(&pRep->width, n);
+    swaps(&pRep->height, n);
+    swaps(&pRep->borderWidth, n);
+    (void)WriteToClient(pClient, size, (char *) pRep);
+}
+
+void
+SQueryTreeReply(pClient, size, pRep)
+    ClientPtr          pClient;
+    int                        size;
+    xQueryTreeReply    *pRep;
+{
+    register char n;
+
+    swaps(&pRep->sequenceNumber, n);
+    swapl(&pRep->length, n);
+    swapl(&pRep->root, n);
+    swapl(&pRep->parent, n);
+    swaps(&pRep->nChildren, n);
+    (void)WriteToClient(pClient, size, (char *) pRep);
+}
+
+void
+SInternAtomReply(pClient, size, pRep)
+    ClientPtr          pClient;
+    int                        size;
+    xInternAtomReply   *pRep;
+{
+    register char n;
+
+    swaps(&pRep->sequenceNumber, n);
+    swapl(&pRep->atom, n);
+    (void)WriteToClient(pClient, size, (char *) pRep);
+}
+
+void
+SGetAtomNameReply(pClient, size, pRep)
+    ClientPtr                  pClient;
+    int                                size;
+    xGetAtomNameReply  *pRep;
+{
+    register char n;
+
+    swaps(&pRep->sequenceNumber, n);
+    swapl(&pRep->length, n);
+    swaps(&pRep->nameLength, n);
+    (void)WriteToClient(pClient, size, (char *) pRep);
+}
+
+
+void
+SGetPropertyReply(pClient, size, pRep)
+    ClientPtr                  pClient;
+    int                                size;
+    xGetPropertyReply  *pRep;
+{
+    register char n;
+
+    swaps(&pRep->sequenceNumber, n);
+    swapl(&pRep->length, n);
+    swapl(&pRep->propertyType, n);
+    swapl(&pRep->bytesAfter, n);
+    swapl(&pRep->nItems, n);
+    (void)WriteToClient(pClient, size, (char *) pRep);
+}
+
+void
+SListPropertiesReply(pClient, size, pRep)
+    ClientPtr                  pClient;
+    int                                size;
+    xListPropertiesReply       *pRep;
+{
+    register char n;
+
+    swaps(&pRep->sequenceNumber, n);
+    swapl(&pRep->length, n);
+    swaps(&pRep->nProperties, n);
+    (void)WriteToClient(pClient, size, (char *) pRep);
+}
+
+void
+SGetSelectionOwnerReply(pClient, size, pRep)
+    ClientPtr                  pClient;
+    int                                size;
+    xGetSelectionOwnerReply    *pRep;
+{
+    register char n;
+
+    swaps(&pRep->sequenceNumber, n);
+    swapl(&pRep->owner, n);
+    (void)WriteToClient(pClient, size, (char *) pRep);
+}
+
+
+void
+SQueryPointerReply(pClient, size, pRep)
+    ClientPtr          pClient;
+    int                        size;
+    xQueryPointerReply *pRep;
+{
+    register char n;
+
+    swaps(&pRep->sequenceNumber, n);
+    swapl(&pRep->root, n);
+    swapl(&pRep->child, n);
+    swaps(&pRep->rootX, n);
+    swaps(&pRep->rootY, n);
+    swaps(&pRep->winX, n);
+    swaps(&pRep->winY, n);
+    swaps(&pRep->mask, n);
+    (void)WriteToClient(pClient, size, (char *) pRep);
+}
+
+void
+SwapTimecoord(pCoord)
+    xTimecoord *pCoord;
+{
+    register char n;
+
+    swapl(&pCoord->time, n);
+    swaps(&pCoord->x, n);
+    swaps(&pCoord->y, n);
+}
+
+void
+SwapTimeCoordWrite(pClient, size, pRep)
+    ClientPtr                  pClient;
+    int                                size;
+    xTimecoord                 *pRep;
+{
+    int        i, n;
+    xTimecoord                 *pRepT;
+
+    n = size / sizeof(xTimecoord);
+    pRepT = pRep;
+    for(i = 0; i < n; i++)
+    {
+       SwapTimecoord(pRepT);
+       pRepT++;
+    }
+    (void)WriteToClient(pClient, size, (char *) pRep);
+
+}
+void
+SGetMotionEventsReply(pClient, size, pRep)
+    ClientPtr                  pClient;
+    int                                size;
+    xGetMotionEventsReply      *pRep;
+{
+    register char n;
+
+    swaps(&pRep->sequenceNumber, n);
+    swapl(&pRep->length, n);
+    swapl(&pRep->nEvents, n);
+    (void)WriteToClient(pClient, size, (char *) pRep);
+}
+
+void
+STranslateCoordsReply(pClient, size, pRep)
+    ClientPtr                  pClient;
+    int                                size;
+    xTranslateCoordsReply      *pRep;
+{
+    register char n;
+
+    swaps(&pRep->sequenceNumber, n);
+    swapl(&pRep->child, n);
+    swaps(&pRep->dstX, n);
+    swaps(&pRep->dstY, n);
+    (void)WriteToClient(pClient, size, (char *) pRep);
+}
+
+void
+SGetInputFocusReply(pClient, size, pRep)
+    ClientPtr          pClient;
+    int                        size;
+    xGetInputFocusReply        *pRep;
+{
+    register char n;
+
+    swaps(&pRep->sequenceNumber, n);
+    swapl(&pRep->focus, n);
+    (void)WriteToClient(pClient, size, (char *) pRep);
+}
+
+/* extra long reply */
+void
+SQueryKeymapReply(pClient, size, pRep)
+    ClientPtr                  pClient;
+    int                                size;
+    xQueryKeymapReply  *pRep;
+{
+    register char n;
+
+    swaps(&pRep->sequenceNumber, n);
+    swapl(&pRep->length, n);
+    (void)WriteToClient(pClient, size, (char *) pRep);
+}
+
+#ifndef LBX
+static
+#endif
+void
+SwapCharInfo(pInfo)
+    xCharInfo  *pInfo;
+{
+    register char n;
+
+    swaps(&pInfo->leftSideBearing, n);
+    swaps(&pInfo->rightSideBearing, n);
+    swaps(&pInfo->characterWidth, n);
+    swaps(&pInfo->ascent, n);
+    swaps(&pInfo->descent, n);
+    swaps(&pInfo->attributes, n);
+}
+
+static void
+SwapFontInfo(pr)
+    xQueryFontReply *pr;
+{
+    register char              n;
+
+    swaps(&pr->minCharOrByte2, n);
+    swaps(&pr->maxCharOrByte2, n);
+    swaps(&pr->defaultChar, n);
+    swaps(&pr->nFontProps, n);
+    swaps(&pr->fontAscent, n);
+    swaps(&pr->fontDescent, n);
+    SwapCharInfo( &pr->minBounds);
+    SwapCharInfo( &pr->maxBounds);
+    swapl(&pr->nCharInfos, n);
+}
+
+#ifndef LBX
+static
+#endif
+void
+SwapFont( pr, hasGlyphs)
+    xQueryFontReply *  pr;
+    Bool hasGlyphs;
+{
+    unsigned   i;
+    xCharInfo *        pxci;
+    unsigned   nchars, nprops;
+    char       *pby;
+    register char n;
+
+    swaps(&pr->sequenceNumber, n);
+    swapl(&pr->length, n);
+    nchars = pr->nCharInfos;
+    nprops = pr->nFontProps;
+    SwapFontInfo(pr);
+    pby = (char *) &pr[1];
+    /* Font properties are an atom and either an int32 or a CARD32, so
+     * they are always 2 4 byte values */
+    for(i = 0; i < nprops; i++)
+    {
+       swapl(pby, n);
+       pby += 4;
+       swapl(pby, n);
+       pby += 4;
+    }
+    if (hasGlyphs)
+    {
+       pxci = (xCharInfo *)pby;
+       for(i = 0; i< nchars; i++, pxci++)
+           SwapCharInfo(pxci);
+    }
+}
+
+void
+SQueryFontReply(pClient, size, pRep)
+    ClientPtr          pClient;
+    int                        size;
+    xQueryFontReply    *pRep;
+{
+    SwapFont(pRep, TRUE);
+    (void)WriteToClient(pClient, size, (char *) pRep);
+}
+
+void
+SQueryTextExtentsReply(pClient, size, pRep)
+    ClientPtr                  pClient;
+    int                                size;
+    xQueryTextExtentsReply     *pRep;
+{
+    register char n;
+
+    swaps(&pRep->sequenceNumber, n);
+    swaps(&pRep->fontAscent, n);
+    swaps(&pRep->fontDescent, n);
+    swaps(&pRep->overallAscent, n);
+    swaps(&pRep->overallDescent, n);
+    swapl(&pRep->overallWidth, n);
+    swapl(&pRep->overallLeft, n);
+    swapl(&pRep->overallRight, n);
+    (void)WriteToClient(pClient, size, (char *) pRep);
+}
+
+void
+SListFontsReply(pClient, size, pRep)
+    ClientPtr          pClient;
+    int                        size;
+    xListFontsReply    *pRep;
+{
+    register char n;
+
+    swaps(&pRep->sequenceNumber, n);
+    swapl(&pRep->length, n);
+    swaps(&pRep->nFonts, n);
+    (void)WriteToClient(pClient, size, (char *) pRep);
+}
+
+void
+SListFontsWithInfoReply(pClient, size, pRep)
+    ClientPtr                  pClient;
+    int                                size;
+    xListFontsWithInfoReply    *pRep;
+{
+    SwapFont((xQueryFontReply *)pRep, FALSE);
+    (void)WriteToClient(pClient, size, (char *) pRep);
+}
+
+void
+SGetFontPathReply(pClient, size, pRep)
+    ClientPtr          pClient;
+    int                        size;
+    xGetFontPathReply  *pRep;
+{
+    register char n;
+
+    swaps(&pRep->sequenceNumber, n);
+    swapl(&pRep->length, n);
+    swaps(&pRep->nPaths, n);
+    (void)WriteToClient(pClient, size, (char *) pRep);
+}
+
+void
+SGetImageReply(pClient, size, pRep)
+    ClientPtr          pClient;
+    int                        size;
+    xGetImageReply     *pRep;
+{
+    register char n;
+
+    swaps(&pRep->sequenceNumber, n);
+    swapl(&pRep->length, n);
+    swapl(&pRep->visual, n);
+    (void)WriteToClient(pClient, size, (char *) pRep);
+    /* Fortunately, image doesn't need swapping */
+}
+
+void
+SListInstalledColormapsReply(pClient, size, pRep)
+    ClientPtr                          pClient;
+    int                                        size;
+    xListInstalledColormapsReply       *pRep;
+{
+    register char n;
+
+    swaps(&pRep->sequenceNumber, n);
+    swapl(&pRep->length, n);
+    swaps(&pRep->nColormaps, n);
+    (void)WriteToClient(pClient, size, (char *) pRep);
+}
+
+void
+SAllocColorReply(pClient, size, pRep)
+    ClientPtr          pClient;
+    int                        size;
+    xAllocColorReply   *pRep;
+{
+    register char n;
+
+    swaps(&pRep->sequenceNumber, n);
+    swaps(&pRep->red, n);
+    swaps(&pRep->green, n);
+    swaps(&pRep->blue, n);
+    swapl(&pRep->pixel, n);
+    (void)WriteToClient(pClient, size, (char *) pRep);
+}
+
+void
+SAllocNamedColorReply(pClient, size, pRep)
+    ClientPtr                  pClient;
+    int                                size;
+    xAllocNamedColorReply      *pRep;
+{
+    register char n;
+
+    swaps(&pRep->sequenceNumber, n);
+    swapl(&pRep->pixel, n);
+    swaps(&pRep->exactRed, n);
+    swaps(&pRep->exactGreen, n);
+    swaps(&pRep->exactBlue, n);
+    swaps(&pRep->screenRed, n);
+    swaps(&pRep->screenGreen, n);
+    swaps(&pRep->screenBlue, n);
+    (void)WriteToClient(pClient, size, (char *) pRep);
+}
+
+void
+SAllocColorCellsReply(pClient, size, pRep)
+    ClientPtr                  pClient;
+    int                                size;
+    xAllocColorCellsReply      *pRep;
+{
+    register char n;
+
+    swaps(&pRep->sequenceNumber, n);
+    swapl(&pRep->length, n);
+    swaps(&pRep->nPixels, n);
+    swaps(&pRep->nMasks, n);
+    (void)WriteToClient(pClient, size, (char *) pRep);
+}
+
+
+void
+SAllocColorPlanesReply(pClient, size, pRep)
+    ClientPtr                  pClient;
+    int                                size;
+    xAllocColorPlanesReply     *pRep;
+{
+    register char n;
+
+    swaps(&pRep->sequenceNumber, n);
+    swapl(&pRep->length, n);
+    swaps(&pRep->nPixels, n);
+    swapl(&pRep->redMask, n);
+    swapl(&pRep->greenMask, n);
+    swapl(&pRep->blueMask, n);
+    (void)WriteToClient(pClient, size, (char *) pRep);
+}
+
+void
+SwapRGB(prgb)
+    xrgb       *prgb;
+{
+    register char n;
+
+    swaps(&prgb->red, n);
+    swaps(&prgb->green, n);
+    swaps(&prgb->blue, n);
+}
+
+void
+SQColorsExtend(pClient, size, prgb)
+    ClientPtr  pClient;
+    int                size;
+    xrgb       *prgb;
+{
+    int                i, n;
+    xrgb       *prgbT;
+
+    n = size / sizeof(xrgb);
+    prgbT = prgb;
+    for(i = 0; i < n; i++)
+    {
+       SwapRGB(prgbT);
+       prgbT++;
+    }
+    (void)WriteToClient(pClient, size, (char *) prgb);
+}
+
+void
+SQueryColorsReply(pClient, size, pRep)
+    ClientPtr          pClient;
+    int                        size;
+    xQueryColorsReply  *pRep;
+{
+    register char n;
+
+    swaps(&pRep->sequenceNumber, n);
+    swapl(&pRep->length, n);
+    swaps(&pRep->nColors, n);
+    (void)WriteToClient(pClient, size, (char *) pRep);
+}
+
+void
+SLookupColorReply(pClient, size, pRep)
+    ClientPtr          pClient;
+    int                        size;
+    xLookupColorReply  *pRep;
+{
+    register char n;
+
+    swaps(&pRep->sequenceNumber, n);
+    swaps(&pRep->exactRed, n);
+    swaps(&pRep->exactGreen, n);
+    swaps(&pRep->exactBlue, n);
+    swaps(&pRep->screenRed, n);
+    swaps(&pRep->screenGreen, n);
+    swaps(&pRep->screenBlue, n);
+    (void)WriteToClient(pClient, size, (char *) pRep);
+}
+
+void
+SQueryBestSizeReply(pClient, size, pRep)
+    ClientPtr          pClient;
+    int                        size;
+    xQueryBestSizeReply        *pRep;
+{
+    register char n;
+
+    swaps(&pRep->sequenceNumber, n);
+    swaps(&pRep->width, n);
+    swaps(&pRep->height, n);
+    (void)WriteToClient(pClient, size, (char *) pRep);
+}
+
+void
+SListExtensionsReply(pClient, size, pRep)
+    ClientPtr                  pClient;
+    int                                size;
+    xListExtensionsReply       *pRep;
+{
+    register char n;
+
+    swaps(&pRep->sequenceNumber, n);
+    swapl(&pRep->length, n);
+    (void)WriteToClient(pClient, size, (char *) pRep);
+}
+
+void
+SGetKeyboardMappingReply(pClient, size, pRep)
+    ClientPtr                  pClient;
+    int                                size;
+    xGetKeyboardMappingReply   *pRep;
+{
+    register char n;
+
+    swaps(&pRep->sequenceNumber, n);
+    swapl(&pRep->length, n);
+    (void)WriteToClient(pClient, size, (char *) pRep);
+}
+
+void
+SGetPointerMappingReply(pClient, size, pRep)
+    ClientPtr                  pClient;
+    int                                size;
+    xGetPointerMappingReply    *pRep;
+{
+    register char n;
+
+    swaps(&pRep->sequenceNumber, n);
+    swapl(&pRep->length, n);
+    (void)WriteToClient(pClient, size, (char *) pRep);
+}
+
+void
+SGetModifierMappingReply(pClient, size, pRep)
+    ClientPtr                  pClient;
+    int                                size;
+    xGetModifierMappingReply   *pRep;
+{
+    register char n;
+
+    swaps(&pRep->sequenceNumber, n);
+    swapl(&pRep->length, n);
+    (void)WriteToClient(pClient, size, (char *) pRep);
+}
+
+void
+SGetKeyboardControlReply(pClient, size, pRep)
+    ClientPtr                  pClient;
+    int                                size;
+    xGetKeyboardControlReply   *pRep;
+{
+    register char n;
+
+    swaps(&pRep->sequenceNumber, n);
+    swapl(&pRep->length, n);
+    swapl(&pRep->ledMask, n);
+    swaps(&pRep->bellPitch, n);
+    swaps(&pRep->bellDuration, n);
+    (void)WriteToClient(pClient, size, (char *) pRep);
+}
+
+void
+SGetPointerControlReply(pClient, size, pRep)
+    ClientPtr                  pClient;
+    int                                size;
+    xGetPointerControlReply    *pRep;
+{
+    register char n;
+
+    swaps(&pRep->sequenceNumber, n);
+    swaps(&pRep->accelNumerator, n);
+    swaps(&pRep->accelDenominator, n);
+    swaps(&pRep->threshold, n);
+    (void)WriteToClient(pClient, size, (char *) pRep);
+}
+
+void
+SGetScreenSaverReply(pClient, size, pRep)
+    ClientPtr                  pClient;
+    int                                size;
+    xGetScreenSaverReply       *pRep;
+{
+    register char n;
+
+    swaps(&pRep->sequenceNumber, n);
+    swaps(&pRep->timeout, n);
+    swaps(&pRep->interval, n);
+    (void)WriteToClient(pClient, size, (char *) pRep);
+}
+
+void
+SLHostsExtend(pClient, size, buf)
+    ClientPtr          pClient;
+    int                        size;
+    char               *buf;
+{
+    char *bufT = buf;
+    char *endbuf = buf + size;
+    while (bufT < endbuf) {
+       xHostEntry *host = (xHostEntry *) bufT;
+       int len = host->length;
+        register char n;
+       swaps (&host->length, n);
+       bufT += sizeof (xHostEntry) + (((len + 3) >> 2) << 2);
+       }
+    (void)WriteToClient (pClient, size, buf);
+}
+
+void
+SListHostsReply(pClient, size, pRep)
+    ClientPtr          pClient;
+    int                        size;
+    xListHostsReply    *pRep;
+{
+    register char n;
+
+    swaps(&pRep->sequenceNumber, n);
+    swapl(&pRep->length, n);
+    swaps(&pRep->nHosts, n);
+    (void)WriteToClient(pClient, size, (char *) pRep);
+}
+
+
+
+void
+SErrorEvent(from, to)
+    xError     *from, *to;
+{
+    to->type = X_Error;
+    to->errorCode = from->errorCode;
+    cpswaps(from->sequenceNumber, to->sequenceNumber);
+    cpswapl(from->resourceID, to->resourceID);
+    cpswaps(from->minorCode, to->minorCode);
+    to->majorCode = from->majorCode;
+}
+
+void
+SKeyButtonPtrEvent(from, to)
+    xEvent     *from, *to;
+{
+    to->u.u.type = from->u.u.type;
+    to->u.u.detail = from->u.u.detail;
+    cpswaps(from->u.u.sequenceNumber, to->u.u.sequenceNumber);
+    cpswapl(from->u.keyButtonPointer.time,
+        to->u.keyButtonPointer.time);
+    cpswapl(from->u.keyButtonPointer.root,
+        to->u.keyButtonPointer.root);
+    cpswapl(from->u.keyButtonPointer.event,
+        to->u.keyButtonPointer.event);
+    cpswapl(from->u.keyButtonPointer.child,
+        to->u.keyButtonPointer.child);
+    cpswaps(from->u.keyButtonPointer.rootX,
+        to->u.keyButtonPointer.rootX);
+    cpswaps(from->u.keyButtonPointer.rootY,
+       to->u.keyButtonPointer.rootY);
+    cpswaps(from->u.keyButtonPointer.eventX,
+        to->u.keyButtonPointer.eventX);
+    cpswaps(from->u.keyButtonPointer.eventY,
+        to->u.keyButtonPointer.eventY);
+    cpswaps(from->u.keyButtonPointer.state,
+        to->u.keyButtonPointer.state);
+    to->u.keyButtonPointer.sameScreen = 
+       from->u.keyButtonPointer.sameScreen;
+}
+
+void
+SEnterLeaveEvent(from, to)
+    xEvent     *from, *to;
+{
+    to->u.u.type = from->u.u.type;
+    to->u.u.detail = from->u.u.detail;
+    cpswaps(from->u.u.sequenceNumber, to->u.u.sequenceNumber);
+    cpswapl(from->u.enterLeave.time, to->u.enterLeave.time);
+    cpswapl(from->u.enterLeave.root, to->u.enterLeave.root);
+    cpswapl(from->u.enterLeave.event, to->u.enterLeave.event);
+    cpswapl(from->u.enterLeave.child, to->u.enterLeave.child);
+    cpswaps(from->u.enterLeave.rootX, to->u.enterLeave.rootX);
+    cpswaps(from->u.enterLeave.rootY, to->u.enterLeave.rootY);
+    cpswaps(from->u.enterLeave.eventX, to->u.enterLeave.eventX);
+    cpswaps(from->u.enterLeave.eventY, to->u.enterLeave.eventY);
+    cpswaps(from->u.enterLeave.state, to->u.enterLeave.state);
+    to->u.enterLeave.mode = from->u.enterLeave.mode;
+    to->u.enterLeave.flags = from->u.enterLeave.flags;
+}
+
+void
+SFocusEvent(from, to)
+    xEvent     *from, *to;
+{
+    to->u.u.type = from->u.u.type;
+    to->u.u.detail = from->u.u.detail;
+    cpswaps(from->u.u.sequenceNumber, to->u.u.sequenceNumber);
+    cpswapl(from->u.focus.window, to->u.focus.window);
+    to->u.focus.mode = from->u.focus.mode;
+}
+
+void
+SExposeEvent(from, to)
+    xEvent     *from, *to;
+{
+    to->u.u.type = from->u.u.type;
+    cpswaps(from->u.u.sequenceNumber, to->u.u.sequenceNumber);
+    cpswapl(from->u.expose.window, to->u.expose.window);
+    cpswaps(from->u.expose.x, to->u.expose.x);
+    cpswaps(from->u.expose.y, to->u.expose.y);
+    cpswaps(from->u.expose.width, to->u.expose.width);
+    cpswaps(from->u.expose.height, to->u.expose.height);
+    cpswaps(from->u.expose.count, to->u.expose.count);
+}
+
+void
+SGraphicsExposureEvent(from, to)
+    xEvent     *from, *to;
+{
+    to->u.u.type = from->u.u.type;
+    cpswaps(from->u.u.sequenceNumber, to->u.u.sequenceNumber);
+    cpswapl(from->u.graphicsExposure.drawable,
+        to->u.graphicsExposure.drawable);
+    cpswaps(from->u.graphicsExposure.x, 
+       to->u.graphicsExposure.x);
+    cpswaps(from->u.graphicsExposure.y, 
+       to->u.graphicsExposure.y);
+    cpswaps(from->u.graphicsExposure.width, 
+       to->u.graphicsExposure.width);
+    cpswaps(from->u.graphicsExposure.height, 
+       to->u.graphicsExposure.height);
+    cpswaps(from->u.graphicsExposure.minorEvent,
+        to->u.graphicsExposure.minorEvent);
+    cpswaps(from->u.graphicsExposure.count,
+       to->u.graphicsExposure.count);
+    to->u.graphicsExposure.majorEvent = 
+       from->u.graphicsExposure.majorEvent;
+}
+
+void
+SNoExposureEvent(from, to)
+    xEvent     *from, *to;
+{
+    to->u.u.type = from->u.u.type;
+    cpswaps(from->u.u.sequenceNumber, to->u.u.sequenceNumber);
+    cpswapl(from->u.noExposure.drawable, to->u.noExposure.drawable);
+    cpswaps(from->u.noExposure.minorEvent, to->u.noExposure.minorEvent);
+    to->u.noExposure.majorEvent = from->u.noExposure.majorEvent;
+}
+
+void
+SVisibilityEvent(from, to)
+    xEvent     *from, *to;
+{
+    to->u.u.type = from->u.u.type;
+    cpswaps(from->u.u.sequenceNumber, to->u.u.sequenceNumber);
+    cpswapl(from->u.visibility.window, to->u.visibility.window);
+    to->u.visibility.state = from->u.visibility.state;
+}
+
+void
+SCreateNotifyEvent(from, to)
+    xEvent     *from, *to;
+{
+    to->u.u.type = from->u.u.type;
+    cpswaps(from->u.u.sequenceNumber, to->u.u.sequenceNumber);
+    cpswapl(from->u.createNotify.window, to->u.createNotify.window);
+    cpswapl(from->u.createNotify.parent, to->u.createNotify.parent);
+    cpswaps(from->u.createNotify.x, to->u.createNotify.x);
+    cpswaps(from->u.createNotify.y, to->u.createNotify.y);
+    cpswaps(from->u.createNotify.width, to->u.createNotify.width);
+    cpswaps(from->u.createNotify.height, to->u.createNotify.height);
+    cpswaps(from->u.createNotify.borderWidth,
+        to->u.createNotify.borderWidth);
+    to->u.createNotify.override = from->u.createNotify.override;
+}
+
+void
+SDestroyNotifyEvent(from, to)
+    xEvent     *from, *to;
+{
+    to->u.u.type = from->u.u.type;
+    cpswaps(from->u.u.sequenceNumber, to->u.u.sequenceNumber);
+    cpswapl(from->u.destroyNotify.event, to->u.destroyNotify.event);
+    cpswapl(from->u.destroyNotify.window, to->u.destroyNotify.window);
+}
+
+void
+SUnmapNotifyEvent(from, to)
+    xEvent     *from, *to;
+{
+    to->u.u.type = from->u.u.type;
+    cpswaps(from->u.u.sequenceNumber, to->u.u.sequenceNumber);
+    cpswapl(from->u.unmapNotify.event, to->u.unmapNotify.event);
+    cpswapl(from->u.unmapNotify.window, to->u.unmapNotify.window);
+    to->u.unmapNotify.fromConfigure = from->u.unmapNotify.fromConfigure;
+}
+
+void
+SMapNotifyEvent(from, to)
+    xEvent     *from, *to;
+{
+    to->u.u.type = from->u.u.type;
+    cpswaps(from->u.u.sequenceNumber, to->u.u.sequenceNumber);
+    cpswapl(from->u.mapNotify.event, to->u.mapNotify.event);
+    cpswapl(from->u.mapNotify.window, to->u.mapNotify.window);
+    to->u.mapNotify.override = from->u.mapNotify.override;
+}
+
+void
+SMapRequestEvent(from, to)
+    xEvent     *from, *to;
+{
+    to->u.u.type = from->u.u.type;
+    cpswaps(from->u.u.sequenceNumber, to->u.u.sequenceNumber);
+    cpswapl(from->u.mapRequest.parent, to->u.mapRequest.parent);
+    cpswapl(from->u.mapRequest.window, to->u.mapRequest.window);
+}
+
+void
+SReparentEvent(from, to)
+    xEvent     *from, *to;
+{
+    to->u.u.type = from->u.u.type;
+    cpswaps(from->u.u.sequenceNumber, to->u.u.sequenceNumber);
+    cpswapl(from->u.reparent.event, to->u.reparent.event);
+    cpswapl(from->u.reparent.window, to->u.reparent.window);
+    cpswapl(from->u.reparent.parent, to->u.reparent.parent);
+    cpswaps(from->u.reparent.x, to->u.reparent.x);
+    cpswaps(from->u.reparent.y, to->u.reparent.y);
+    to->u.reparent.override = from->u.reparent.override;
+}
+
+void
+SConfigureNotifyEvent(from, to)
+    xEvent     *from, *to;
+{
+    to->u.u.type = from->u.u.type;
+    cpswaps(from->u.u.sequenceNumber, to->u.u.sequenceNumber);
+    cpswapl(from->u.configureNotify.event,
+        to->u.configureNotify.event);
+    cpswapl(from->u.configureNotify.window,
+        to->u.configureNotify.window);
+    cpswapl(from->u.configureNotify.aboveSibling,
+        to->u.configureNotify.aboveSibling);
+    cpswaps(from->u.configureNotify.x, to->u.configureNotify.x);
+    cpswaps(from->u.configureNotify.y, to->u.configureNotify.y);
+    cpswaps(from->u.configureNotify.width, to->u.configureNotify.width);
+    cpswaps(from->u.configureNotify.height,
+        to->u.configureNotify.height);
+    cpswaps(from->u.configureNotify.borderWidth,
+        to->u.configureNotify.borderWidth);
+    to->u.configureNotify.override = from->u.configureNotify.override;
+}
+
+void
+SConfigureRequestEvent(from, to)
+    xEvent     *from, *to;
+{
+    to->u.u.type = from->u.u.type;
+    to->u.u.detail = from->u.u.detail;  /* actually stack-mode */
+    cpswaps(from->u.u.sequenceNumber, to->u.u.sequenceNumber);
+    cpswapl(from->u.configureRequest.parent,
+        to->u.configureRequest.parent);
+    cpswapl(from->u.configureRequest.window,
+        to->u.configureRequest.window);
+    cpswapl(from->u.configureRequest.sibling,
+        to->u.configureRequest.sibling);
+    cpswaps(from->u.configureRequest.x, to->u.configureRequest.x);
+    cpswaps(from->u.configureRequest.y, to->u.configureRequest.y);
+    cpswaps(from->u.configureRequest.width,
+        to->u.configureRequest.width);
+    cpswaps(from->u.configureRequest.height,
+        to->u.configureRequest.height);
+    cpswaps(from->u.configureRequest.borderWidth,
+        to->u.configureRequest.borderWidth);
+    cpswaps(from->u.configureRequest.valueMask,
+        to->u.configureRequest.valueMask);
+}
+
+
+void
+SGravityEvent(from, to)
+    xEvent     *from, *to;
+{
+    to->u.u.type = from->u.u.type;
+    cpswaps(from->u.u.sequenceNumber, to->u.u.sequenceNumber);
+    cpswapl(from->u.gravity.event, to->u.gravity.event);
+    cpswapl(from->u.gravity.window, to->u.gravity.window);
+    cpswaps(from->u.gravity.x, to->u.gravity.x);
+    cpswaps(from->u.gravity.y, to->u.gravity.y);
+}
+
+void
+SResizeRequestEvent(from, to)
+    xEvent     *from, *to;
+{
+    to->u.u.type = from->u.u.type;
+    cpswaps(from->u.u.sequenceNumber, to->u.u.sequenceNumber);
+    cpswapl(from->u.resizeRequest.window, to->u.resizeRequest.window);
+    cpswaps(from->u.resizeRequest.width, to->u.resizeRequest.width);
+    cpswaps(from->u.resizeRequest.height, to->u.resizeRequest.height);
+}
+
+void
+SCirculateEvent(from, to)
+    xEvent     *from, *to;
+{
+    to->u.u.type = from->u.u.type;
+    to->u.u.detail = from->u.u.detail;
+    cpswaps(from->u.u.sequenceNumber, to->u.u.sequenceNumber);
+    cpswapl(from->u.circulate.event, to->u.circulate.event);
+    cpswapl(from->u.circulate.window, to->u.circulate.window);
+    cpswapl(from->u.circulate.parent, to->u.circulate.parent);
+    to->u.circulate.place = from->u.circulate.place;
+}
+
+void
+SPropertyEvent(from, to)
+    xEvent     *from, *to;
+{
+    to->u.u.type = from->u.u.type;
+    cpswaps(from->u.u.sequenceNumber, to->u.u.sequenceNumber);
+    cpswapl(from->u.property.window, to->u.property.window);
+    cpswapl(from->u.property.atom, to->u.property.atom);
+    cpswapl(from->u.property.time, to->u.property.time);
+    to->u.property.state = from->u.property.state;
+}
+
+void
+SSelectionClearEvent(from, to)
+    xEvent     *from, *to;
+{
+    to->u.u.type = from->u.u.type;
+    cpswaps(from->u.u.sequenceNumber, to->u.u.sequenceNumber);
+    cpswapl(from->u.selectionClear.time, to->u.selectionClear.time);
+    cpswapl(from->u.selectionClear.window, to->u.selectionClear.window);
+    cpswapl(from->u.selectionClear.atom, to->u.selectionClear.atom);
+}
+
+void
+SSelectionRequestEvent(from, to)
+    xEvent     *from, *to;
+{
+    to->u.u.type = from->u.u.type;
+    cpswaps(from->u.u.sequenceNumber, to->u.u.sequenceNumber);
+    cpswapl(from->u.selectionRequest.time, to->u.selectionRequest.time);
+    cpswapl(from->u.selectionRequest.owner,
+        to->u.selectionRequest.owner);
+    cpswapl(from->u.selectionRequest.requestor,
+       to->u.selectionRequest.requestor);
+    cpswapl(from->u.selectionRequest.selection,
+       to->u.selectionRequest.selection);
+    cpswapl(from->u.selectionRequest.target,
+        to->u.selectionRequest.target);
+    cpswapl(from->u.selectionRequest.property,
+       to->u.selectionRequest.property);
+}
+
+void
+SSelectionNotifyEvent(from, to)
+    xEvent     *from, *to;
+{
+    to->u.u.type = from->u.u.type;
+    cpswaps(from->u.u.sequenceNumber, to->u.u.sequenceNumber);
+    cpswapl(from->u.selectionNotify.time, to->u.selectionNotify.time);
+    cpswapl(from->u.selectionNotify.requestor,
+       to->u.selectionNotify.requestor);
+    cpswapl(from->u.selectionNotify.selection,
+       to->u.selectionNotify.selection);
+    cpswapl(from->u.selectionNotify.target,
+       to->u.selectionNotify.target);
+    cpswapl(from->u.selectionNotify.property,
+        to->u.selectionNotify.property);
+}
+
+void
+SColormapEvent(from, to)
+    xEvent     *from, *to;
+{
+    to->u.u.type = from->u.u.type;
+    cpswaps(from->u.u.sequenceNumber, to->u.u.sequenceNumber);
+    cpswapl(from->u.colormap.window, to->u.colormap.window);
+    cpswapl(from->u.colormap.colormap, to->u.colormap.colormap);
+    to->u.colormap.new = from->u.colormap.new;
+    to->u.colormap.state = from->u.colormap.state;
+}
+
+void
+SMappingEvent(from, to)
+    xEvent     *from, *to;
+{
+    to->u.u.type = from->u.u.type;
+    cpswaps(from->u.u.sequenceNumber, to->u.u.sequenceNumber);
+    to->u.mappingNotify.request = from->u.mappingNotify.request;
+    to->u.mappingNotify.firstKeyCode =
+       from->u.mappingNotify.firstKeyCode;
+    to->u.mappingNotify.count = from->u.mappingNotify.count;
+}
+
+void
+SClientMessageEvent(from, to)
+    xEvent     *from, *to;
+{
+    to->u.u.type = from->u.u.type;
+    to->u.u.detail = from->u.u.detail;  /* actually format */
+    cpswaps(from->u.u.sequenceNumber, to->u.u.sequenceNumber);
+    cpswapl(from->u.clientMessage.window, to->u.clientMessage.window);
+    cpswapl(from->u.clientMessage.u.l.type, 
+           to->u.clientMessage.u.l.type);
+    switch (from->u.u.detail) {
+       case 8:
+          memmove(to->u.clientMessage.u.b.bytes, 
+                 from->u.clientMessage.u.b.bytes,20);
+         break;
+       case 16:
+         cpswaps(from->u.clientMessage.u.s.shorts0,
+            to->u.clientMessage.u.s.shorts0);
+         cpswaps(from->u.clientMessage.u.s.shorts1,
+            to->u.clientMessage.u.s.shorts1);
+         cpswaps(from->u.clientMessage.u.s.shorts2,
+            to->u.clientMessage.u.s.shorts2);
+         cpswaps(from->u.clientMessage.u.s.shorts3,
+            to->u.clientMessage.u.s.shorts3);
+         cpswaps(from->u.clientMessage.u.s.shorts4,
+            to->u.clientMessage.u.s.shorts4);
+         cpswaps(from->u.clientMessage.u.s.shorts5,
+            to->u.clientMessage.u.s.shorts5);
+         cpswaps(from->u.clientMessage.u.s.shorts6,
+            to->u.clientMessage.u.s.shorts6);
+         cpswaps(from->u.clientMessage.u.s.shorts7,
+            to->u.clientMessage.u.s.shorts7);
+         cpswaps(from->u.clientMessage.u.s.shorts8,
+            to->u.clientMessage.u.s.shorts8);
+         cpswaps(from->u.clientMessage.u.s.shorts9,
+            to->u.clientMessage.u.s.shorts9);
+         break;
+       case 32:
+         cpswapl(from->u.clientMessage.u.l.longs0,
+            to->u.clientMessage.u.l.longs0);
+         cpswapl(from->u.clientMessage.u.l.longs1,
+            to->u.clientMessage.u.l.longs1);
+         cpswapl(from->u.clientMessage.u.l.longs2,
+            to->u.clientMessage.u.l.longs2);
+         cpswapl(from->u.clientMessage.u.l.longs3,
+            to->u.clientMessage.u.l.longs3);
+         cpswapl(from->u.clientMessage.u.l.longs4,
+            to->u.clientMessage.u.l.longs4);
+         break;
+       }
+}
+
+void
+SKeymapNotifyEvent(from, to)
+    xEvent     *from, *to;
+{
+    /* Keymap notify events are special; they have no
+       sequence number field, and contain entirely 8-bit data */
+    *to = *from;
+}
+
+void
+SwapConnSetupInfo(pInfo, pInfoTBase)
+    char               *pInfo;
+    char               *pInfoTBase;
+{
+    int                i, j, k;
+    ScreenPtr  pScreen;
+    DepthPtr   pDepth;
+    char       *pInfoT;
+    xConnSetup *pConnSetup = (xConnSetup *)pInfo;
+
+    pInfoT = pInfoTBase;
+    SwapConnSetup(pConnSetup, (xConnSetup *)pInfoT);
+    pInfo += sizeof(xConnSetup);
+    pInfoT += sizeof(xConnSetup);
+
+    /* Copy the vendor string */
+    i = (pConnSetup->nbytesVendor + 3) & ~3;
+    memmove(pInfoT, pInfo, i);
+    pInfo += i;
+    pInfoT += i;
+
+    /* The Pixmap formats don't need to be swapped, just copied. */
+    i = sizeof(xPixmapFormat) * screenInfo.numPixmapFormats;
+    memmove(pInfoT, pInfo, i);
+    pInfo += i;
+    pInfoT += i;
+
+    for(i = 0; i < screenInfo.numScreens; i++)
+    {
+       pScreen = screenInfo.screens[i];
+       SwapWinRoot((xWindowRoot *)pInfo, (xWindowRoot *)pInfoT);
+       pInfo += sizeof(xWindowRoot);
+       pInfoT += sizeof(xWindowRoot);
+       pDepth = pScreen->allowedDepths;
+       for(j = 0; j < pScreen->numDepths; j++, pDepth++)
+       {
+            ((xDepth *)pInfoT)->depth = ((xDepth *)pInfo)->depth;
+           cpswaps(((xDepth *)pInfo)->nVisuals, ((xDepth *)pInfoT)->nVisuals);
+           pInfo += sizeof(xDepth);
+           pInfoT += sizeof(xDepth);
+           for(k = 0; k < pDepth->numVids; k++)
+           {
+               SwapVisual((xVisualType *)pInfo, (xVisualType *)pInfoT);
+               pInfo += sizeof(xVisualType);
+               pInfoT += sizeof(xVisualType);
+           }
+       }
+    }
+}
+
+
+void
+WriteSConnectionInfo(pClient, size, pInfo)
+    ClientPtr          pClient;
+    unsigned long      size;
+    char               *pInfo;
+{
+    char       *pInfoTBase;
+
+    pInfoTBase = (char *) ALLOCATE_LOCAL(size);
+    if (!pInfoTBase)
+    {
+       pClient->noClientException = -1;
+       return;
+    }
+    SwapConnSetupInfo(pInfo, pInfoTBase);
+    (void)WriteToClient(pClient, (int)size, (char *) pInfoTBase);
+    DEALLOCATE_LOCAL(pInfoTBase);
+}
+
+void
+SwapConnSetup(pConnSetup, pConnSetupT)
+    xConnSetup         *pConnSetup, *pConnSetupT;
+{
+    cpswapl(pConnSetup->release, pConnSetupT->release);
+    cpswapl(pConnSetup->ridBase, pConnSetupT->ridBase);
+    cpswapl(pConnSetup->ridMask, pConnSetupT->ridMask);
+    cpswapl(pConnSetup->motionBufferSize, pConnSetupT->motionBufferSize);
+    cpswaps(pConnSetup->nbytesVendor, pConnSetupT->nbytesVendor);
+    cpswaps(pConnSetup->maxRequestSize, pConnSetupT->maxRequestSize);
+    pConnSetupT->minKeyCode = pConnSetup->minKeyCode;
+    pConnSetupT->maxKeyCode = pConnSetup->maxKeyCode;
+    pConnSetupT->numRoots = pConnSetup->numRoots;
+    pConnSetupT->numFormats = pConnSetup->numFormats;
+    pConnSetupT->imageByteOrder = pConnSetup->imageByteOrder;
+    pConnSetupT->bitmapBitOrder = pConnSetup->bitmapBitOrder;
+    pConnSetupT->bitmapScanlineUnit = pConnSetup->bitmapScanlineUnit;
+    pConnSetupT->bitmapScanlinePad = pConnSetup->bitmapScanlinePad;
+}
+
+void
+SwapWinRoot(pRoot, pRootT)
+    xWindowRoot        *pRoot, *pRootT;
+{
+    cpswapl(pRoot->windowId, pRootT->windowId);
+    cpswapl(pRoot->defaultColormap, pRootT->defaultColormap);
+    cpswapl(pRoot->whitePixel, pRootT->whitePixel);
+    cpswapl(pRoot->blackPixel, pRootT->blackPixel);
+    cpswapl(pRoot->currentInputMask, pRootT->currentInputMask);
+    cpswaps(pRoot->pixWidth, pRootT->pixWidth);
+    cpswaps(pRoot->pixHeight, pRootT->pixHeight);
+    cpswaps(pRoot->mmWidth, pRootT->mmWidth);
+    cpswaps(pRoot->mmHeight, pRootT->mmHeight);
+    cpswaps(pRoot->minInstalledMaps, pRootT->minInstalledMaps);
+    cpswaps(pRoot->maxInstalledMaps, pRootT->maxInstalledMaps);
+    cpswapl(pRoot->rootVisualID, pRootT->rootVisualID);
+    pRootT->backingStore = pRoot->backingStore;
+    pRootT->saveUnders = pRoot->saveUnders;
+    pRootT->rootDepth = pRoot->rootDepth;
+    pRootT->nDepths = pRoot->nDepths;
+}
+
+void
+SwapVisual(pVis, pVisT)
+    xVisualType        *pVis, *pVisT;
+{
+    cpswapl(pVis->visualID, pVisT->visualID);
+    pVisT->class = pVis->class;
+    pVisT->bitsPerRGB = pVis->bitsPerRGB;
+    cpswaps(pVis->colormapEntries, pVisT->colormapEntries);
+    cpswapl(pVis->redMask, pVisT->redMask);
+    cpswapl(pVis->greenMask, pVisT->greenMask);
+    cpswapl(pVis->blueMask, pVisT->blueMask);
+}
+
+void
+SwapConnSetupPrefix(pcspFrom, pcspTo)
+    xConnSetupPrefix   *pcspFrom;
+    xConnSetupPrefix   *pcspTo;
+{
+    pcspTo->success = pcspFrom->success;
+    pcspTo->lengthReason = pcspFrom->lengthReason;
+    cpswaps(pcspFrom->majorVersion, pcspTo->majorVersion);
+    cpswaps(pcspFrom->minorVersion, pcspTo->minorVersion);
+    cpswaps(pcspFrom->length, pcspTo->length);
+}
+
+void
+WriteSConnSetupPrefix(pClient, pcsp)
+    ClientPtr          pClient;
+    xConnSetupPrefix   *pcsp;
+{
+    xConnSetupPrefix   cspT;
+
+    SwapConnSetupPrefix(pcsp, &cspT);
+    (void)WriteToClient(pClient, sizeof(cspT), (char *) &cspT);
+}
diff --git a/Xserver/programs/Xserver/dix/swapreq.c b/Xserver/programs/Xserver/dix/swapreq.c
new file mode 100644 (file)
index 0000000..3a9eb25
--- /dev/null
@@ -0,0 +1,1176 @@
+/************************************************************
+
+Copyright (c) 1987  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+
+Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
+
+                        All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and its 
+documentation for any purpose and without fee is hereby granted, 
+provided that the above copyright notice appear in all copies and that
+both that copyright notice and this permission notice appear in 
+supporting documentation, and that the name of Digital not be
+used in advertising or publicity pertaining to distribution of the
+software without specific, written prior permission.  
+
+DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
+ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
+DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
+ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+SOFTWARE.
+
+********************************************************/
+
+/* $XConsortium: swapreq.c,v 1.39 94/04/17 20:26:45 dpw Exp $ */
+/* $XFree86: xc/programs/Xserver/dix/swapreq.c,v 3.1 1996/05/06 05:56:24 dawes Exp $ */
+
+#include "X.h"
+#define NEED_EVENTS
+#include "Xproto.h"
+#include "Xprotostr.h"
+#include "misc.h"
+#include "dixstruct.h"
+#include "extnsionst.h"        /* for SendEvent */
+#include "swapreq.h"
+
+extern int (* ProcVector[256]) ();
+
+/* Thanks to Jack Palevich for testing and subsequently rewriting all this */
+
+/* Byte swap a list of longs */
+
+void
+SwapLongs (list, count)
+       register CARD32 *list;
+       register unsigned long count;
+{
+       register char n;
+
+       while (count >= 8) {
+           swapl(list+0, n);
+           swapl(list+1, n);
+           swapl(list+2, n);
+           swapl(list+3, n);
+           swapl(list+4, n);
+           swapl(list+5, n);
+           swapl(list+6, n);
+           swapl(list+7, n);
+           list += 8;
+           count -= 8;
+       }
+       if (count != 0) {
+           do {
+               swapl(list, n);
+               list++;
+           } while (--count != 0);
+       }
+}
+
+/* Byte swap a list of shorts */
+
+void
+SwapShorts (list, count)
+       register short *list;
+       register unsigned long count;
+{
+       register char n;
+
+       while (count >= 16) {
+           swaps(list+0, n);
+           swaps(list+1, n);
+           swaps(list+2, n);
+           swaps(list+3, n);
+           swaps(list+4, n);
+           swaps(list+5, n);
+           swaps(list+6, n);
+           swaps(list+7, n);
+           swaps(list+8, n);
+           swaps(list+9, n);
+           swaps(list+10, n);
+           swaps(list+11, n);
+           swaps(list+12, n);
+           swaps(list+13, n);
+           swaps(list+14, n);
+           swaps(list+15, n);
+           list += 16;
+           count -= 16;
+       }
+       if (count != 0) {
+           do {
+               swaps(list, n);
+               list++;
+           } while (--count != 0);
+       }
+}
+
+/* The following is used for all requests that have
+   no fields to be swapped (except "length") */
+int
+SProcSimpleReq(client)
+       register ClientPtr client;
+{
+    register char n;
+
+    REQUEST(xReq);
+    swaps(&stuff->length, n);
+    return(*ProcVector[stuff->reqType])(client);
+}
+
+/* The following is used for all requests that have
+   only a single 32-bit field to be swapped, coming
+   right after the "length" field */
+int
+SProcResourceReq(client)
+       register ClientPtr client;
+{
+    register char n;
+
+    REQUEST(xResourceReq);
+    swaps(&stuff->length, n);
+    REQUEST_AT_LEAST_SIZE(xResourceReq); /* not EXACT */
+    swapl(&stuff->id, n);
+    return(*ProcVector[stuff->reqType])(client);
+}
+
+int
+SProcCreateWindow(client)
+    register ClientPtr client;
+{
+    register char n;
+
+    REQUEST(xCreateWindowReq);
+    swaps(&stuff->length, n);
+    REQUEST_AT_LEAST_SIZE(xCreateWindowReq);
+    swapl(&stuff->wid, n);
+    swapl(&stuff->parent, n);
+    swaps(&stuff->x, n);
+    swaps(&stuff->y, n);
+    swaps(&stuff->width, n);
+    swaps(&stuff->height, n);
+    swaps(&stuff->borderWidth, n);
+    swaps(&stuff->class, n);
+    swapl(&stuff->visual, n);
+    swapl(&stuff->mask, n);
+    SwapRestL(stuff);
+    return((* ProcVector[X_CreateWindow])(client));
+}
+
+int
+SProcChangeWindowAttributes(client)
+    register ClientPtr client;
+{
+    register char n;
+
+    REQUEST(xChangeWindowAttributesReq);
+    swaps(&stuff->length, n);
+    REQUEST_AT_LEAST_SIZE(xChangeWindowAttributesReq);
+    swapl(&stuff->window, n);
+    swapl(&stuff->valueMask, n);
+    SwapRestL(stuff);
+    return((* ProcVector[X_ChangeWindowAttributes])(client));
+}
+
+int
+SProcReparentWindow(client)
+    register ClientPtr client;
+{
+    register char n;
+    REQUEST(xReparentWindowReq);
+    swaps(&stuff->length, n);
+    REQUEST_SIZE_MATCH(xReparentWindowReq);
+    swapl(&stuff->window, n);
+    swapl(&stuff->parent, n);
+    swaps(&stuff->x, n);
+    swaps(&stuff->y, n);
+    return((* ProcVector[X_ReparentWindow])(client));
+}
+
+int
+SProcConfigureWindow(client)
+    register ClientPtr client;
+{
+    register char n;
+    REQUEST(xConfigureWindowReq);
+    swaps(&stuff->length, n);
+    REQUEST_AT_LEAST_SIZE(xConfigureWindowReq);
+    swapl(&stuff->window, n);
+    swaps(&stuff->mask, n);
+    SwapRestL(stuff);
+    return((* ProcVector[X_ConfigureWindow])(client));
+
+}
+
+
+int
+SProcInternAtom(client)
+    register ClientPtr client;
+{
+    register char n;
+    REQUEST(xInternAtomReq);
+    swaps(&stuff->length, n);
+    REQUEST_AT_LEAST_SIZE(xInternAtomReq);
+    swaps(&stuff->nbytes, n);
+    return((* ProcVector[X_InternAtom])(client));
+}
+
+int
+SProcChangeProperty(client)
+    register ClientPtr client;
+{
+    register char n;
+    REQUEST(xChangePropertyReq);
+    swaps(&stuff->length, n);
+    REQUEST_AT_LEAST_SIZE(xChangePropertyReq);
+    swapl(&stuff->window, n);
+    swapl(&stuff->property, n);
+    swapl(&stuff->type, n);
+    swapl(&stuff->nUnits, n);
+    switch ( stuff->format ) {
+        case 8 :
+           break;
+        case 16:
+           SwapRestS(stuff);
+           break;
+       case 32:
+           SwapRestL(stuff);
+           break;
+       }
+    return((* ProcVector[X_ChangeProperty])(client));
+}
+
+int 
+SProcDeleteProperty(client)
+    register ClientPtr client;
+{
+    register char n;
+    REQUEST(xDeletePropertyReq);
+    swaps(&stuff->length, n);
+    REQUEST_SIZE_MATCH(xDeletePropertyReq);
+    swapl(&stuff->window, n);
+    swapl(&stuff->property, n);
+    return((* ProcVector[X_DeleteProperty])(client));
+              
+}
+
+int 
+SProcGetProperty(client)
+    register ClientPtr client;
+{
+    register char n;
+    REQUEST(xGetPropertyReq);
+    swaps(&stuff->length, n);
+    REQUEST_SIZE_MATCH(xGetPropertyReq);
+    swapl(&stuff->window, n);
+    swapl(&stuff->property, n);
+    swapl(&stuff->type, n);
+    swapl(&stuff->longOffset, n);
+    swapl(&stuff->longLength, n);
+    return((* ProcVector[X_GetProperty])(client));
+}
+
+int
+SProcSetSelectionOwner(client)
+    register ClientPtr client;
+{
+    register char n;
+    REQUEST(xSetSelectionOwnerReq);
+    swaps(&stuff->length, n);
+    REQUEST_SIZE_MATCH(xSetSelectionOwnerReq);
+    swapl(&stuff->window, n);
+    swapl(&stuff->selection, n);
+    swapl(&stuff->time, n);
+    return((* ProcVector[X_SetSelectionOwner])(client));
+}
+
+int
+SProcConvertSelection(client)
+    register ClientPtr client;
+{
+    register char n;
+    REQUEST(xConvertSelectionReq);
+    swaps(&stuff->length, n);
+    REQUEST_SIZE_MATCH(xConvertSelectionReq);
+    swapl(&stuff->requestor, n);
+    swapl(&stuff->selection, n);
+    swapl(&stuff->target, n);
+    swapl(&stuff->property, n);
+    swapl(&stuff->time, n);
+    return((* ProcVector[X_ConvertSelection])(client));
+}
+
+int
+SProcSendEvent(client)
+    register ClientPtr client;
+{
+    register char n;
+    xEvent eventT;
+    EventSwapPtr proc;
+    REQUEST(xSendEventReq);
+    swaps(&stuff->length, n);
+    REQUEST_SIZE_MATCH(xSendEventReq);
+    swapl(&stuff->destination, n);
+    swapl(&stuff->eventMask, n);
+
+    /* Swap event */
+    proc = EventSwapVector[stuff->event.u.u.type & 0177];
+    if (!proc ||  proc == NotImplemented)    /* no swapping proc; invalid event type? */
+       return (BadValue);
+    (*proc)(&stuff->event, &eventT);
+    stuff->event = eventT;
+
+    return((* ProcVector[X_SendEvent])(client));
+}
+
+int
+SProcGrabPointer(client)
+    register ClientPtr client;
+{
+    register char n;
+    REQUEST(xGrabPointerReq);
+    swaps(&stuff->length, n);
+    REQUEST_SIZE_MATCH(xGrabPointerReq);
+    swapl(&stuff->grabWindow, n);
+    swaps(&stuff->eventMask, n);
+    swapl(&stuff->confineTo, n);
+    swapl(&stuff->cursor, n);
+    swapl(&stuff->time, n);
+    return((* ProcVector[X_GrabPointer])(client));
+}
+
+int
+SProcGrabButton(client)
+    register ClientPtr client;
+{
+    register char n;
+    REQUEST(xGrabButtonReq);
+    swaps(&stuff->length, n);
+    REQUEST_SIZE_MATCH(xGrabButtonReq);
+    swapl(&stuff->grabWindow, n);
+    swaps(&stuff->eventMask, n);
+    swapl(&stuff->confineTo, n);
+    swapl(&stuff->cursor, n);
+    swaps(&stuff->modifiers, n);
+    return((* ProcVector[X_GrabButton])(client));
+}
+
+int
+SProcUngrabButton(client)
+    register ClientPtr client;
+{
+    register char n;
+    REQUEST(xUngrabButtonReq);
+    swaps(&stuff->length, n);
+    REQUEST_SIZE_MATCH(xUngrabButtonReq);
+    swapl(&stuff->grabWindow, n);
+    swaps(&stuff->modifiers, n);
+    return((* ProcVector[X_UngrabButton])(client));
+}
+
+int
+SProcChangeActivePointerGrab(client)
+    register ClientPtr client;
+{
+    register char n;
+    REQUEST(xChangeActivePointerGrabReq);
+    swaps(&stuff->length, n);
+    REQUEST_SIZE_MATCH(xChangeActivePointerGrabReq);
+    swapl(&stuff->cursor, n);
+    swapl(&stuff->time, n);
+    swaps(&stuff->eventMask, n);
+    return((* ProcVector[X_ChangeActivePointerGrab])(client));
+}
+
+int
+SProcGrabKeyboard(client)
+    register ClientPtr client;
+{
+    register char n;
+    REQUEST(xGrabKeyboardReq);
+    swaps(&stuff->length, n);
+    REQUEST_SIZE_MATCH(xGrabKeyboardReq);
+    swapl(&stuff->grabWindow, n);
+    swapl(&stuff->time, n);
+    return((* ProcVector[X_GrabKeyboard])(client));
+}
+
+int
+SProcGrabKey(client)
+    register ClientPtr client;
+{
+    register char n;
+    REQUEST(xGrabKeyReq);
+    swaps(&stuff->length, n);
+    REQUEST_SIZE_MATCH(xGrabKeyReq);
+    swapl(&stuff->grabWindow, n);
+    swaps(&stuff->modifiers, n);
+    return((* ProcVector[X_GrabKey])(client));
+}
+
+int
+SProcUngrabKey(client)
+    register ClientPtr client;
+{
+    register char n;
+    REQUEST(xUngrabKeyReq);
+    swaps(&stuff->length, n);
+    REQUEST_SIZE_MATCH(xUngrabKeyReq);
+    swapl(&stuff->grabWindow, n);
+    swaps(&stuff->modifiers, n);
+    return((* ProcVector[X_UngrabKey])(client));
+}
+
+int
+SProcGetMotionEvents(client)
+    register ClientPtr client;
+{
+    register char n;
+    REQUEST(xGetMotionEventsReq);
+    swaps(&stuff->length, n);
+    REQUEST_SIZE_MATCH(xGetMotionEventsReq);
+    swapl(&stuff->window, n);
+    swapl(&stuff->start, n);
+    swapl(&stuff->stop, n);
+    return((* ProcVector[X_GetMotionEvents])(client));
+}
+
+int
+SProcTranslateCoords(client)
+    register ClientPtr client;
+{
+    register char n;
+    REQUEST(xTranslateCoordsReq);
+    swaps(&stuff->length, n);
+    REQUEST_SIZE_MATCH(xTranslateCoordsReq);
+    swapl(&stuff->srcWid, n);
+    swapl(&stuff->dstWid, n);
+    swaps(&stuff->srcX, n);
+    swaps(&stuff->srcY, n);
+    return((* ProcVector[X_TranslateCoords])(client));
+}
+
+int
+SProcWarpPointer(client)
+    register ClientPtr client;
+{
+    register char n;
+    REQUEST(xWarpPointerReq);
+    swaps(&stuff->length, n);
+    REQUEST_SIZE_MATCH(xWarpPointerReq);
+    swapl(&stuff->srcWid, n);
+    swapl(&stuff->dstWid, n);
+    swaps(&stuff->srcX, n);
+    swaps(&stuff->srcY, n);
+    swaps(&stuff->srcWidth, n);
+    swaps(&stuff->srcHeight, n);
+    swaps(&stuff->dstX, n);
+    swaps(&stuff->dstY, n);
+    return((* ProcVector[X_WarpPointer])(client));
+}
+
+int
+SProcSetInputFocus(client)
+    register ClientPtr client;
+{
+    register char n;
+    REQUEST(xSetInputFocusReq);
+    swaps(&stuff->length, n);
+    REQUEST_SIZE_MATCH(xSetInputFocusReq);
+    swapl(&stuff->focus, n);
+    swapl(&stuff->time, n);
+    return((* ProcVector[X_SetInputFocus])(client));
+}
+
+int
+SProcOpenFont(client)
+    register ClientPtr client;
+{
+    register char n;
+    REQUEST(xOpenFontReq);
+    swaps(&stuff->length, n);
+    REQUEST_AT_LEAST_SIZE(xOpenFontReq);
+    swapl(&stuff->fid, n);
+    swaps(&stuff->nbytes, n);
+    return((* ProcVector[X_OpenFont])(client));
+}
+
+int
+SProcListFonts(client)
+    register ClientPtr client;
+{
+    register char n;
+    REQUEST(xListFontsReq);
+    swaps(&stuff->length, n);
+    REQUEST_AT_LEAST_SIZE(xListFontsReq);
+    swaps(&stuff->maxNames, n);
+    swaps(&stuff->nbytes, n);
+    return((* ProcVector[X_ListFonts])(client));
+}
+
+int
+SProcListFontsWithInfo(client)
+    register ClientPtr client;
+{
+    register char n;
+    REQUEST(xListFontsWithInfoReq);
+    swaps(&stuff->length, n);
+    REQUEST_AT_LEAST_SIZE(xListFontsWithInfoReq);
+    swaps(&stuff->maxNames, n);
+    swaps(&stuff->nbytes, n);
+    return((* ProcVector[X_ListFontsWithInfo])(client));
+}
+
+int
+SProcSetFontPath(client)
+    register ClientPtr client;
+{
+    register char n;
+    REQUEST(xSetFontPathReq);
+    swaps(&stuff->length, n);
+    REQUEST_AT_LEAST_SIZE(xSetFontPathReq);
+    swaps(&stuff->nFonts, n);
+    return((* ProcVector[X_SetFontPath])(client));
+}
+
+int
+SProcCreatePixmap(client)
+    register ClientPtr client;
+{
+    register char n;
+    REQUEST(xCreatePixmapReq);
+
+    swaps(&stuff->length, n);
+    REQUEST_SIZE_MATCH(xCreatePixmapReq);
+    swapl(&stuff->pid, n);
+    swapl(&stuff->drawable, n);
+    swaps(&stuff->width, n);
+    swaps(&stuff->height, n);
+    return((* ProcVector[X_CreatePixmap])(client));
+}
+
+int
+SProcCreateGC(client)
+    register ClientPtr client;
+{
+    register char n;
+    REQUEST(xCreateGCReq);
+    swaps(&stuff->length, n);
+    REQUEST_AT_LEAST_SIZE(xCreateGCReq);
+    swapl(&stuff->gc, n);
+    swapl(&stuff->drawable, n);
+    swapl(&stuff->mask, n);
+    SwapRestL(stuff);
+    return((* ProcVector[X_CreateGC])(client));
+}
+
+int
+SProcChangeGC(client)
+    register ClientPtr client;
+{
+    register char n;
+    REQUEST(xChangeGCReq);
+    swaps(&stuff->length, n);
+    REQUEST_AT_LEAST_SIZE(xChangeGCReq);
+    swapl(&stuff->gc, n);
+    swapl(&stuff->mask, n);
+    SwapRestL(stuff);
+    return((* ProcVector[X_ChangeGC])(client));
+}
+
+int
+SProcCopyGC(client)
+    register ClientPtr client;
+{
+    register char n;
+    REQUEST(xCopyGCReq);
+    swaps(&stuff->length, n);
+    REQUEST_SIZE_MATCH(xCopyGCReq);
+    swapl(&stuff->srcGC, n);
+    swapl(&stuff->dstGC, n);
+    swapl(&stuff->mask, n);
+    return((* ProcVector[X_CopyGC])(client));
+}
+
+int
+SProcSetDashes(client)
+    register ClientPtr client;
+{
+    register char n;
+    REQUEST(xSetDashesReq);
+    swaps(&stuff->length, n);
+    REQUEST_AT_LEAST_SIZE(xSetDashesReq);
+    swapl(&stuff->gc, n);
+    swaps(&stuff->dashOffset, n);
+    swaps(&stuff->nDashes, n);
+    return((* ProcVector[X_SetDashes])(client));
+
+}
+
+int
+SProcSetClipRectangles(client)
+    register ClientPtr client;
+{
+    register char n;
+    REQUEST(xSetClipRectanglesReq);
+    swaps(&stuff->length, n);
+    REQUEST_AT_LEAST_SIZE(xSetClipRectanglesReq);
+    swapl(&stuff->gc, n);
+    swaps(&stuff->xOrigin, n);
+    swaps(&stuff->yOrigin, n);
+    SwapRestS(stuff);
+    return((* ProcVector[X_SetClipRectangles])(client));
+}
+
+int
+SProcClearToBackground(client)
+    register ClientPtr client;
+{
+    register char n;
+    REQUEST(xClearAreaReq);
+    swaps(&stuff->length, n);
+    REQUEST_SIZE_MATCH(xClearAreaReq);
+    swapl(&stuff->window, n);
+    swaps(&stuff->x, n);
+    swaps(&stuff->y, n);
+    swaps(&stuff->width, n);
+    swaps(&stuff->height, n);
+    return((* ProcVector[X_ClearArea])(client));
+}
+
+int
+SProcCopyArea(client)
+    register ClientPtr client;
+{
+    register char n;
+    REQUEST(xCopyAreaReq);
+    swaps(&stuff->length, n);
+    REQUEST_SIZE_MATCH(xCopyAreaReq);
+    swapl(&stuff->srcDrawable, n);
+    swapl(&stuff->dstDrawable, n);
+    swapl(&stuff->gc, n);
+    swaps(&stuff->srcX, n);
+    swaps(&stuff->srcY, n);
+    swaps(&stuff->dstX, n);
+    swaps(&stuff->dstY, n);
+    swaps(&stuff->width, n);
+    swaps(&stuff->height, n);
+    return((* ProcVector[X_CopyArea])(client));
+}
+
+int
+SProcCopyPlane(client)
+    register ClientPtr client;
+{
+    register char n;
+    REQUEST(xCopyPlaneReq);
+    swaps(&stuff->length, n);
+    REQUEST_SIZE_MATCH(xCopyPlaneReq);
+    swapl(&stuff->srcDrawable, n);
+    swapl(&stuff->dstDrawable, n);
+    swapl(&stuff->gc, n);
+    swaps(&stuff->srcX, n);
+    swaps(&stuff->srcY, n);
+    swaps(&stuff->dstX, n);
+    swaps(&stuff->dstY, n);
+    swaps(&stuff->width, n);
+    swaps(&stuff->height, n);
+    swapl(&stuff->bitPlane, n);
+    return((* ProcVector[X_CopyPlane])(client));
+}
+
+/* The following routine is used for all Poly drawing requests
+   (except FillPoly, which uses a different request format) */
+int
+SProcPoly(client)
+    register ClientPtr client;
+{
+    register char n;
+
+    REQUEST(xPolyPointReq);
+    swaps(&stuff->length, n);
+    REQUEST_AT_LEAST_SIZE(xPolyPointReq);
+    swapl(&stuff->drawable, n);
+    swapl(&stuff->gc, n);
+    SwapRestS(stuff);
+    return((* ProcVector[stuff->reqType])(client));
+}
+
+/* cannot use SProcPoly for this one, because xFillPolyReq
+   is longer than xPolyPointReq, and we don't want to swap
+   the difference as shorts! */
+int
+SProcFillPoly(client)
+    register ClientPtr client;
+{
+    register char n;
+
+    REQUEST(xFillPolyReq);
+    swaps(&stuff->length, n);
+    REQUEST_AT_LEAST_SIZE(xFillPolyReq);
+    swapl(&stuff->drawable, n);
+    swapl(&stuff->gc, n);
+    SwapRestS(stuff);
+    return((* ProcVector[X_FillPoly])(client));
+}
+
+int
+SProcPutImage(client)
+    register ClientPtr client;
+{
+    register char n;
+    REQUEST(xPutImageReq);
+    swaps(&stuff->length, n);
+    REQUEST_AT_LEAST_SIZE(xPutImageReq);
+    swapl(&stuff->drawable, n);
+    swapl(&stuff->gc, n);
+    swaps(&stuff->width, n);
+    swaps(&stuff->height, n);
+    swaps(&stuff->dstX, n);
+    swaps(&stuff->dstY, n);
+    /* Image should already be swapped */
+    return((* ProcVector[X_PutImage])(client));
+
+}
+
+int
+SProcGetImage(client)
+    register ClientPtr client;
+{
+    register char n;
+    REQUEST(xGetImageReq);
+    swaps(&stuff->length, n);
+    REQUEST_SIZE_MATCH(xGetImageReq);
+    swapl(&stuff->drawable, n);
+    swaps(&stuff->x, n);
+    swaps(&stuff->y, n);
+    swaps(&stuff->width, n);
+    swaps(&stuff->height, n);
+    swapl(&stuff->planeMask, n);
+    return((* ProcVector[X_GetImage])(client));
+}
+
+/* ProcPolyText used for both PolyText8 and PolyText16 */
+
+int
+SProcPolyText(client)
+    register ClientPtr client;
+{
+    register char n;
+    REQUEST(xPolyTextReq);
+    swaps(&stuff->length, n);
+    REQUEST_AT_LEAST_SIZE(xPolyTextReq);
+    swapl(&stuff->drawable, n);
+    swapl(&stuff->gc, n);
+    swaps(&stuff->x, n);
+    swaps(&stuff->y, n);
+    return((* ProcVector[stuff->reqType])(client));
+}
+
+/* ProcImageText used for both ImageText8 and ImageText16 */
+
+int
+SProcImageText(client)
+    register ClientPtr client;
+{
+    register char n;
+    REQUEST(xImageTextReq);
+    swaps(&stuff->length, n);
+    REQUEST_AT_LEAST_SIZE(xImageTextReq);
+    swapl(&stuff->drawable, n);
+    swapl(&stuff->gc, n);
+    swaps(&stuff->x, n);
+    swaps(&stuff->y, n);
+    return((* ProcVector[stuff->reqType])(client));
+}
+
+int
+SProcCreateColormap(client)
+    register ClientPtr client;
+{
+    register char n;
+    REQUEST(xCreateColormapReq);
+    swaps(&stuff->length, n);
+    REQUEST_SIZE_MATCH(xCreateColormapReq);
+    swapl(&stuff->mid, n);
+    swapl(&stuff->window, n);
+    swapl(&stuff->visual, n);
+    return((* ProcVector[X_CreateColormap])(client));
+}
+
+
+int
+SProcCopyColormapAndFree(client)
+    register ClientPtr client;
+{
+    register char n;
+    REQUEST(xCopyColormapAndFreeReq);
+    swaps(&stuff->length, n);
+    REQUEST_SIZE_MATCH(xCopyColormapAndFreeReq);
+    swapl(&stuff->mid, n);
+    swapl(&stuff->srcCmap, n);
+    return((* ProcVector[X_CopyColormapAndFree])(client));
+
+}
+
+int
+SProcAllocColor                (client)
+    register ClientPtr client;
+{
+    register char n;
+    REQUEST(xAllocColorReq);
+    swaps(&stuff->length, n);
+    REQUEST_SIZE_MATCH(xAllocColorReq);
+    swapl(&stuff->cmap, n);
+    swaps(&stuff->red, n);
+    swaps(&stuff->green, n);
+    swaps(&stuff->blue, n);
+    return((* ProcVector[X_AllocColor])(client));
+}
+
+int
+SProcAllocNamedColor           (client)
+    register ClientPtr client;
+{
+    register char n;
+
+    REQUEST(xAllocNamedColorReq);
+    swaps(&stuff->length, n);
+    REQUEST_AT_LEAST_SIZE(xAllocNamedColorReq);
+    swapl(&stuff->cmap, n);
+    swaps(&stuff->nbytes, n);
+    return((* ProcVector[X_AllocNamedColor])(client));
+}
+
+int
+SProcAllocColorCells           (client)
+    register ClientPtr client;
+{
+    register char n;
+    REQUEST(xAllocColorCellsReq);
+    swaps(&stuff->length, n);
+    REQUEST_SIZE_MATCH(xAllocColorCellsReq);
+    swapl(&stuff->cmap, n);
+    swaps(&stuff->colors, n);
+    swaps(&stuff->planes, n);
+    return((* ProcVector[X_AllocColorCells])(client));
+}
+
+int
+SProcAllocColorPlanes(client)
+    register ClientPtr client;
+{
+    register char n;
+    REQUEST(xAllocColorPlanesReq);
+    swaps(&stuff->length, n);
+    REQUEST_SIZE_MATCH(xAllocColorPlanesReq);
+    swapl(&stuff->cmap, n);
+    swaps(&stuff->colors, n);
+    swaps(&stuff->red, n);
+    swaps(&stuff->green, n);
+    swaps(&stuff->blue, n);
+    return((* ProcVector[X_AllocColorPlanes])(client));
+}
+
+int
+SProcFreeColors          (client)
+    register ClientPtr client;
+{
+    register char n;
+    REQUEST(xFreeColorsReq);
+    swaps(&stuff->length, n);
+    REQUEST_AT_LEAST_SIZE(xFreeColorsReq);
+    swapl(&stuff->cmap, n);
+    swapl(&stuff->planeMask, n);
+    SwapRestL(stuff);
+    return((* ProcVector[X_FreeColors])(client));
+
+}
+
+void
+SwapColorItem(pItem)
+    xColorItem *pItem;
+{
+    register char n;
+
+    swapl(&pItem->pixel, n);
+    swaps(&pItem->red, n);
+    swaps(&pItem->green, n);
+    swaps(&pItem->blue, n);
+}
+
+int
+SProcStoreColors               (client)
+    register ClientPtr client;
+{
+    register char n;
+    long count;
+    xColorItem         *pItem;
+
+    REQUEST(xStoreColorsReq);
+    swaps(&stuff->length, n);
+    REQUEST_AT_LEAST_SIZE(xStoreColorsReq);
+    swapl(&stuff->cmap, n);
+    pItem = (xColorItem *) &stuff[1];
+    for(count = LengthRestB(stuff)/sizeof(xColorItem); --count >= 0; )
+       SwapColorItem(pItem++);
+    return((* ProcVector[X_StoreColors])(client));
+}
+
+int
+SProcStoreNamedColor           (client)
+    register ClientPtr client;
+{
+    register char n;
+    REQUEST(xStoreNamedColorReq);
+    swaps(&stuff->length, n);
+    REQUEST_AT_LEAST_SIZE(xStoreNamedColorReq);
+    swapl(&stuff->cmap, n);
+    swapl(&stuff->pixel, n);
+    swaps(&stuff->nbytes, n);
+    return((* ProcVector[X_StoreNamedColor])(client));
+}
+
+int
+SProcQueryColors(client)
+    register ClientPtr client;
+{
+    register char n;
+    REQUEST(xQueryColorsReq);
+    swaps(&stuff->length, n);
+    REQUEST_AT_LEAST_SIZE(xQueryColorsReq);
+    swapl(&stuff->cmap, n);
+    SwapRestL(stuff);
+    return((* ProcVector[X_QueryColors])(client));
+} 
+
+int
+SProcLookupColor(client)
+    register ClientPtr client;
+{
+    register char n;
+    REQUEST(xLookupColorReq);
+    swaps(&stuff->length, n);
+    REQUEST_AT_LEAST_SIZE(xLookupColorReq);
+    swapl(&stuff->cmap, n);
+    swaps(&stuff->nbytes, n);
+    return((* ProcVector[X_LookupColor])(client));
+}
+
+int
+SProcCreateCursor( client)
+    register ClientPtr client;
+{
+    register char n;
+    REQUEST(xCreateCursorReq);
+    swaps(&stuff->length, n);
+    REQUEST_SIZE_MATCH(xCreateCursorReq);
+    swapl(&stuff->cid, n);
+    swapl(&stuff->source, n);
+    swapl(&stuff->mask, n);
+    swaps(&stuff->foreRed, n);
+    swaps(&stuff->foreGreen, n);
+    swaps(&stuff->foreBlue, n);
+    swaps(&stuff->backRed, n);
+    swaps(&stuff->backGreen, n);
+    swaps(&stuff->backBlue, n);
+    swaps(&stuff->x, n);
+    swaps(&stuff->y, n);
+    return((* ProcVector[X_CreateCursor])(client));
+}
+
+int
+SProcCreateGlyphCursor( client)
+    register ClientPtr client;
+{
+    register char n;
+    REQUEST(xCreateGlyphCursorReq);
+    swaps(&stuff->length, n);
+    REQUEST_SIZE_MATCH(xCreateGlyphCursorReq);
+    swapl(&stuff->cid, n);
+    swapl(&stuff->source, n);
+    swapl(&stuff->mask, n);
+    swaps(&stuff->sourceChar, n);
+    swaps(&stuff->maskChar, n);
+    swaps(&stuff->foreRed, n);
+    swaps(&stuff->foreGreen, n);
+    swaps(&stuff->foreBlue, n);
+    swaps(&stuff->backRed, n);
+    swaps(&stuff->backGreen, n);
+    swaps(&stuff->backBlue, n);
+    return((* ProcVector[X_CreateGlyphCursor])(client));
+}
+
+
+int
+SProcRecolorCursor(client)
+    register ClientPtr client;
+{
+    register char n;
+    REQUEST(xRecolorCursorReq);
+    swaps(&stuff->length, n);
+    REQUEST_SIZE_MATCH(xRecolorCursorReq);
+    swapl(&stuff->cursor, n);
+    swaps(&stuff->foreRed, n);
+    swaps(&stuff->foreGreen, n);
+    swaps(&stuff->foreBlue, n);
+    swaps(&stuff->backRed, n);
+    swaps(&stuff->backGreen, n);
+    swaps(&stuff->backBlue, n);
+    return((* ProcVector[X_RecolorCursor])(client));
+}
+
+int
+SProcQueryBestSize   (client)
+    register ClientPtr client;
+{
+    register char n;
+    REQUEST(xQueryBestSizeReq);
+    swaps(&stuff->length, n);
+    REQUEST_SIZE_MATCH(xQueryBestSizeReq);
+    swapl(&stuff->drawable, n);
+    swaps(&stuff->width, n);
+    swaps(&stuff->height, n);
+    return((* ProcVector[X_QueryBestSize])(client));
+
+}
+
+int
+SProcQueryExtension   (client)
+    register ClientPtr client;
+{
+    register char n;
+    REQUEST(xQueryExtensionReq);
+    swaps(&stuff->length, n);
+    REQUEST_AT_LEAST_SIZE(xQueryExtensionReq);
+    swaps(&stuff->nbytes, n);
+    return((* ProcVector[X_QueryExtension])(client));
+}
+
+int
+SProcChangeKeyboardMapping   (client)
+    register ClientPtr client;
+{
+    register char n;
+    REQUEST(xChangeKeyboardMappingReq);
+    swaps(&stuff->length, n);
+    REQUEST_AT_LEAST_SIZE(xChangeKeyboardMappingReq);
+    SwapRestL(stuff);
+    return((* ProcVector[X_ChangeKeyboardMapping])(client));
+}
+
+
+int
+SProcChangeKeyboardControl   (client)
+    register ClientPtr client;
+{
+    register char n;
+    REQUEST(xChangeKeyboardControlReq);
+    swaps(&stuff->length, n);
+    REQUEST_AT_LEAST_SIZE(xChangeKeyboardControlReq);
+    swapl(&stuff->mask, n);
+    SwapRestL(stuff);
+    return((* ProcVector[X_ChangeKeyboardControl])(client));
+}
+
+int
+SProcChangePointerControl   (client)
+    register ClientPtr client;
+{
+    register char n;
+    REQUEST(xChangePointerControlReq);
+    swaps(&stuff->length, n);
+    REQUEST_SIZE_MATCH(xChangePointerControlReq);
+    swaps(&stuff->accelNum, n);
+    swaps(&stuff->accelDenum, n);
+    swaps(&stuff->threshold, n);
+    return((* ProcVector[X_ChangePointerControl])(client));
+}
+
+
+int
+SProcSetScreenSaver            (client)
+    register ClientPtr client;
+{
+    register char n;
+    REQUEST(xSetScreenSaverReq);
+    swaps(&stuff->length, n);
+    REQUEST_SIZE_MATCH(xSetScreenSaverReq);
+    swaps(&stuff->timeout, n);
+    swaps(&stuff->interval, n);
+    return((* ProcVector[X_SetScreenSaver])(client));
+}
+
+int
+SProcChangeHosts(client)
+    register ClientPtr client;
+{
+    register char n;
+
+    REQUEST(xChangeHostsReq);
+    swaps(&stuff->length, n);
+    REQUEST_AT_LEAST_SIZE(xChangeHostsReq);
+    swaps(&stuff->hostLength, n);
+    return((* ProcVector[X_ChangeHosts])(client));
+
+}
+
+int SProcRotateProperties(client)
+    register ClientPtr client;
+{
+    register char n;
+    REQUEST(xRotatePropertiesReq);
+    swaps(&stuff->length, n);
+    REQUEST_AT_LEAST_SIZE(xRotatePropertiesReq);
+    swapl(&stuff->window, n);
+    swaps(&stuff->nAtoms, n);
+    swaps(&stuff->nPositions, n);
+    SwapRestL(stuff);
+    return ((* ProcVector[X_RotateProperties])(client));
+}
+
+/*ARGSUSED*/
+int
+SProcNoOperation(client)
+    ClientPtr client;
+{
+    register char n;
+    REQUEST(xReq);
+    swaps(&stuff->length, n);
+    return ((* ProcVector[X_NoOperation])(client));
+}
+
+void
+SwapConnClientPrefix(pCCP)
+    xConnClientPrefix  *pCCP;
+{
+    register char n;
+
+    swaps(&pCCP->majorVersion, n);
+    swaps(&pCCP->minorVersion, n);
+    swaps(&pCCP->nbytesAuthProto, n);
+    swaps(&pCCP->nbytesAuthString, n);
+}
diff --git a/Xserver/programs/Xserver/dix/swapreq.h b/Xserver/programs/Xserver/dix/swapreq.h
new file mode 100644 (file)
index 0000000..a7240a5
--- /dev/null
@@ -0,0 +1,137 @@
+/* $XFree86: xc/programs/Xserver/dix/swapreq.h,v 3.0 1996/04/15 11:20:01 dawes Exp $ */
+/************************************************************
+
+Copyright 1996 by Thomas E. Dickey <dickey@clark.net>
+
+                        All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and its
+documentation for any purpose and without fee is hereby granted,
+provided that the above copyright notice appear in all copies and that
+both that copyright notice and this permission notice appear in
+supporting documentation, and that the name of the above listed
+copyright holder(s) not be used in advertising or publicity pertaining
+to distribution of the software without specific, written prior
+permission.
+
+THE ABOVE LISTED COPYRIGHT HOLDER(S) DISCLAIM ALL WARRANTIES WITH REGARD
+TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+AND FITNESS, IN NO EVENT SHALL THE ABOVE LISTED COPYRIGHT HOLDER(S) BE
+LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+
+********************************************************/
+
+#ifndef SWAPREQ_H
+#define SWAPREQ_H 1
+
+void
+SwapLongs (
+#if NeedFunctionPrototypes
+    CARD32 * /* list */,
+    unsigned long /* count */
+#endif
+);
+
+void
+SwapShorts (
+#if NeedFunctionPrototypes
+    short * /* list */,
+    unsigned long  /* count */
+#endif
+);
+
+void
+SwapColorItem(
+#if NeedFunctionPrototypes
+    xColorItem * /* pItem */
+#endif
+);
+
+void
+SwapConnClientPrefix(
+#if NeedFunctionPrototypes
+    xConnClientPrefix * /* pCCP */
+#endif
+);
+
+#undef SWAPREQ_PROC
+
+#if NeedFunctionPrototypes
+#define SWAPREQ_PROC(func) int func(ClientPtr /* client */)
+#else
+#define SWAPREQ_PROC(func) int func(/* ClientPtr client */)
+#endif
+
+SWAPREQ_PROC(SProcAllocColor);
+SWAPREQ_PROC(SProcAllocColorCells);
+SWAPREQ_PROC(SProcAllocColorPlanes);
+SWAPREQ_PROC(SProcAllocNamedColor);
+SWAPREQ_PROC(SProcChangeActivePointerGrab);
+SWAPREQ_PROC(SProcChangeGC);
+SWAPREQ_PROC(SProcChangeHosts);
+SWAPREQ_PROC(SProcChangeKeyboardControl);
+SWAPREQ_PROC(SProcChangeKeyboardMapping);
+SWAPREQ_PROC(SProcChangePointerControl);
+SWAPREQ_PROC(SProcChangeProperty);
+SWAPREQ_PROC(SProcChangeWindowAttributes);
+SWAPREQ_PROC(SProcClearToBackground);
+SWAPREQ_PROC(SProcConfigureWindow);
+SWAPREQ_PROC(SProcConvertSelection);
+SWAPREQ_PROC(SProcCopyArea);
+SWAPREQ_PROC(SProcCopyColormapAndFree);
+SWAPREQ_PROC(SProcCopyGC);
+SWAPREQ_PROC(SProcCopyPlane);
+SWAPREQ_PROC(SProcCreateColormap);
+SWAPREQ_PROC(SProcCreateCursor);
+SWAPREQ_PROC(SProcCreateGC);
+SWAPREQ_PROC(SProcCreateGlyphCursor);
+SWAPREQ_PROC(SProcCreatePixmap);
+SWAPREQ_PROC(SProcCreateWindow);
+SWAPREQ_PROC(SProcDeleteProperty);
+SWAPREQ_PROC(SProcFillPoly);
+SWAPREQ_PROC(SProcFreeColors);
+SWAPREQ_PROC(SProcGetImage);
+SWAPREQ_PROC(SProcGetMotionEvents);
+SWAPREQ_PROC(SProcGetProperty);
+SWAPREQ_PROC(SProcGrabButton);
+SWAPREQ_PROC(SProcGrabKey);
+SWAPREQ_PROC(SProcGrabKeyboard);
+SWAPREQ_PROC(SProcGrabPointer);
+SWAPREQ_PROC(SProcImageText);
+SWAPREQ_PROC(SProcInternAtom);
+SWAPREQ_PROC(SProcListFonts);
+SWAPREQ_PROC(SProcListFontsWithInfo);
+SWAPREQ_PROC(SProcLookupColor);
+SWAPREQ_PROC(SProcNoOperation);
+SWAPREQ_PROC(SProcOpenFont);
+SWAPREQ_PROC(SProcPoly);
+SWAPREQ_PROC(SProcPolyText);
+SWAPREQ_PROC(SProcPutImage);
+SWAPREQ_PROC(SProcQueryBestSize);
+SWAPREQ_PROC(SProcQueryColors);
+SWAPREQ_PROC(SProcQueryExtension);
+SWAPREQ_PROC(SProcRecolorCursor);
+SWAPREQ_PROC(SProcReparentWindow);
+SWAPREQ_PROC(SProcResourceReq);
+SWAPREQ_PROC(SProcRotateProperties);
+SWAPREQ_PROC(SProcSendEvent);
+SWAPREQ_PROC(SProcSetClipRectangles);
+SWAPREQ_PROC(SProcSetDashes);
+SWAPREQ_PROC(SProcSetFontPath);
+SWAPREQ_PROC(SProcSetInputFocus);
+SWAPREQ_PROC(SProcSetScreenSaver);
+SWAPREQ_PROC(SProcSetSelectionOwner);
+SWAPREQ_PROC(SProcSimpleReq);
+SWAPREQ_PROC(SProcStoreColors);
+SWAPREQ_PROC(SProcStoreNamedColor);
+SWAPREQ_PROC(SProcTranslateCoords);
+SWAPREQ_PROC(SProcUngrabButton);
+SWAPREQ_PROC(SProcUngrabKey);
+SWAPREQ_PROC(SProcWarpPointer);
+
+#undef SWAPREQ_PROC
+
+#endif /* SWAPREQ_H */
diff --git a/Xserver/programs/Xserver/dix/tables.c b/Xserver/programs/Xserver/dix/tables.c
new file mode 100644 (file)
index 0000000..ec3cdae
--- /dev/null
@@ -0,0 +1,531 @@
+/***********************************************************
+
+Copyright (c) 1987  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+
+Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
+
+                        All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and its 
+documentation for any purpose and without fee is hereby granted, 
+provided that the above copyright notice appear in all copies and that
+both that copyright notice and this permission notice appear in 
+supporting documentation, and that the name of Digital not be
+used in advertising or publicity pertaining to distribution of the
+software without specific, written prior permission.  
+
+DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
+ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
+DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
+ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+SOFTWARE.
+
+******************************************************************/
+/* $XConsortium: tables.c,v 1.25 94/04/17 20:26:46 gildea Exp $ */
+/* $XFree86: xc/programs/Xserver/dix/tables.c,v 3.1 1996/05/06 05:56:25 dawes Exp $ */
+
+#include "X.h"
+#define NEED_EVENTS
+#define NEED_REPLIES
+#include "Xproto.h"
+#include "windowstr.h"
+#include "extnsionst.h"
+#include "dixstruct.h"
+#include "dispatch.h"
+#include "swaprep.h"
+#include "swapreq.h"
+
+#ifdef K5AUTH
+extern int
+    k5_stage1(), k5_stage2(), k5_stage3(), k5_bad();
+#endif
+
+int (* InitialVector[3]) (
+#if NeedNestedPrototypes
+       ClientPtr /* client */
+#endif
+    ) =
+{
+    0,
+    ProcInitialConnection,
+    ProcEstablishConnection
+};
+
+int (* ProcVector[256]) (
+#if NeedNestedPrototypes
+       ClientPtr /* client */
+#endif
+    ) =
+{
+    ProcBadRequest,
+    ProcCreateWindow,
+    ProcChangeWindowAttributes,
+    ProcGetWindowAttributes,
+    ProcDestroyWindow,
+    ProcDestroySubwindows,             /* 5 */
+    ProcChangeSaveSet,
+    ProcReparentWindow,
+    ProcMapWindow,
+    ProcMapSubwindows,
+    ProcUnmapWindow,                   /* 10 */
+    ProcUnmapSubwindows,
+    ProcConfigureWindow,
+    ProcCirculateWindow,
+    ProcGetGeometry,
+    ProcQueryTree,                     /* 15 */
+    ProcInternAtom,
+    ProcGetAtomName,
+    ProcChangeProperty,
+    ProcDeleteProperty,
+    ProcGetProperty,                   /* 20 */
+    ProcListProperties,
+    ProcSetSelectionOwner,
+    ProcGetSelectionOwner,
+    ProcConvertSelection,
+    ProcSendEvent,                     /* 25 */
+    ProcGrabPointer,
+    ProcUngrabPointer,
+    ProcGrabButton,
+    ProcUngrabButton,
+    ProcChangeActivePointerGrab,       /* 30 */
+    ProcGrabKeyboard,
+    ProcUngrabKeyboard,
+    ProcGrabKey,
+    ProcUngrabKey,
+    ProcAllowEvents,                   /* 35 */
+    ProcGrabServer,
+    ProcUngrabServer,
+    ProcQueryPointer,
+    ProcGetMotionEvents,
+    ProcTranslateCoords,               /* 40 */
+    ProcWarpPointer,
+    ProcSetInputFocus,
+    ProcGetInputFocus,
+    ProcQueryKeymap,
+    ProcOpenFont,                      /* 45 */
+    ProcCloseFont,
+    ProcQueryFont,
+    ProcQueryTextExtents,
+    ProcListFonts,
+    ProcListFontsWithInfo,             /* 50 */
+    ProcSetFontPath,
+    ProcGetFontPath,
+    ProcCreatePixmap,
+    ProcFreePixmap,
+    ProcCreateGC,                      /* 55 */
+    ProcChangeGC,
+    ProcCopyGC,
+    ProcSetDashes,
+    ProcSetClipRectangles,
+    ProcFreeGC,                                /* 60 */
+    ProcClearToBackground,
+    ProcCopyArea,
+    ProcCopyPlane,
+    ProcPolyPoint,
+    ProcPolyLine,                      /* 65 */
+    ProcPolySegment,
+    ProcPolyRectangle,
+    ProcPolyArc,
+    ProcFillPoly,
+    ProcPolyFillRectangle,             /* 70 */
+    ProcPolyFillArc,
+    ProcPutImage,
+    ProcGetImage,
+    ProcPolyText,
+    ProcPolyText,                      /* 75 */
+    ProcImageText8,
+    ProcImageText16,
+    ProcCreateColormap,
+    ProcFreeColormap,
+    ProcCopyColormapAndFree,           /* 80 */
+    ProcInstallColormap,
+    ProcUninstallColormap,
+    ProcListInstalledColormaps,
+    ProcAllocColor,
+    ProcAllocNamedColor,               /* 85 */
+    ProcAllocColorCells,
+    ProcAllocColorPlanes,
+    ProcFreeColors,
+    ProcStoreColors,
+    ProcStoreNamedColor,               /* 90 */
+    ProcQueryColors,
+    ProcLookupColor,
+    ProcCreateCursor,
+    ProcCreateGlyphCursor,
+    ProcFreeCursor,                    /* 95 */
+    ProcRecolorCursor,
+    ProcQueryBestSize,
+    ProcQueryExtension,
+    ProcListExtensions,
+    ProcChangeKeyboardMapping,         /* 100 */
+    ProcGetKeyboardMapping,
+    ProcChangeKeyboardControl,
+    ProcGetKeyboardControl,
+    ProcBell,
+    ProcChangePointerControl,          /* 105 */
+    ProcGetPointerControl,
+    ProcSetScreenSaver,
+    ProcGetScreenSaver,
+    ProcChangeHosts,
+    ProcListHosts,                     /* 110 */
+    ProcChangeAccessControl,
+    ProcChangeCloseDownMode,
+    ProcKillClient,
+    ProcRotateProperties,
+    ProcForceScreenSaver,              /* 115 */
+    ProcSetPointerMapping,
+    ProcGetPointerMapping,
+    ProcSetModifierMapping,
+    ProcGetModifierMapping,
+    0,                                 /* 120 */
+    0,
+    0,
+    0,
+    0,
+    0,                                 /* 125 */
+    0,
+    ProcNoOperation    
+};
+
+int (* SwappedProcVector[256]) (
+#if NeedNestedPrototypes
+       ClientPtr /* client */
+#endif
+    ) =
+{
+    ProcBadRequest,
+    SProcCreateWindow,
+    SProcChangeWindowAttributes,
+    SProcResourceReq,                  /* GetWindowAttributes */
+    SProcResourceReq,                  /* DestroyWindow */
+    SProcResourceReq,                  /* 5 DestroySubwindows */
+    SProcResourceReq,                  /* SProcChangeSaveSet, */
+    SProcReparentWindow,
+    SProcResourceReq,                  /* MapWindow */
+    SProcResourceReq,                  /* MapSubwindows */
+    SProcResourceReq,                  /* 10 UnmapWindow */
+    SProcResourceReq,                  /* UnmapSubwindows */
+    SProcConfigureWindow,
+    SProcResourceReq,                  /* SProcCirculateWindow, */
+    SProcResourceReq,                  /* GetGeometry */
+    SProcResourceReq,                  /* 15 QueryTree */
+    SProcInternAtom,
+    SProcResourceReq,                  /* SProcGetAtomName, */
+    SProcChangeProperty,
+    SProcDeleteProperty,
+    SProcGetProperty,                  /* 20 */
+    SProcResourceReq,                  /* SProcListProperties, */
+    SProcSetSelectionOwner,
+    SProcResourceReq,                  /* SProcGetSelectionOwner, */
+    SProcConvertSelection,
+    SProcSendEvent,                    /* 25 */
+    SProcGrabPointer,
+    SProcResourceReq,                  /* SProcUngrabPointer, */
+    SProcGrabButton,
+    SProcUngrabButton,
+    SProcChangeActivePointerGrab,      /* 30 */
+    SProcGrabKeyboard,
+    SProcResourceReq,                  /* SProcUngrabKeyboard, */
+    SProcGrabKey,
+    SProcUngrabKey,
+    SProcResourceReq,                  /* 35 SProcAllowEvents, */
+    SProcSimpleReq,                    /* SProcGrabServer, */
+    SProcSimpleReq,                    /* SProcUngrabServer, */
+    SProcResourceReq,                  /* SProcQueryPointer, */
+    SProcGetMotionEvents,
+    SProcTranslateCoords,              /*40 */
+    SProcWarpPointer,
+    SProcSetInputFocus,
+    SProcSimpleReq,                    /* SProcGetInputFocus, */
+    SProcSimpleReq,                    /* QueryKeymap, */
+    SProcOpenFont,                     /* 45 */
+    SProcResourceReq,                  /* SProcCloseFont, */
+    SProcResourceReq,                  /* SProcQueryFont, */
+    SProcResourceReq,                  /* SProcQueryTextExtents,  */
+    SProcListFonts,
+    SProcListFontsWithInfo,            /* 50 */
+    SProcSetFontPath,
+    SProcSimpleReq,                    /* GetFontPath, */
+    SProcCreatePixmap,
+    SProcResourceReq,                  /* SProcFreePixmap, */
+    SProcCreateGC,                     /* 55 */
+    SProcChangeGC,
+    SProcCopyGC,
+    SProcSetDashes,
+    SProcSetClipRectangles,
+    SProcResourceReq,                  /* 60 SProcFreeGC, */
+    SProcClearToBackground,
+    SProcCopyArea,
+    SProcCopyPlane,
+    SProcPoly,                         /* PolyPoint, */
+    SProcPoly,                         /* 65 PolyLine */
+    SProcPoly,                         /* PolySegment, */
+    SProcPoly,                         /* PolyRectangle, */
+    SProcPoly,                         /* PolyArc, */
+    SProcFillPoly,
+    SProcPoly,                         /* 70 PolyFillRectangle */
+    SProcPoly,                         /* PolyFillArc, */
+    SProcPutImage,
+    SProcGetImage,
+    SProcPolyText,
+    SProcPolyText,                     /* 75 */
+    SProcImageText,
+    SProcImageText,
+    SProcCreateColormap,
+    SProcResourceReq,                  /* SProcFreeColormap, */
+    SProcCopyColormapAndFree,          /* 80 */
+    SProcResourceReq,                  /* SProcInstallColormap, */
+    SProcResourceReq,                  /* SProcUninstallColormap, */
+    SProcResourceReq,                  /* SProcListInstalledColormaps, */
+    SProcAllocColor,
+    SProcAllocNamedColor,              /* 85 */
+    SProcAllocColorCells,
+    SProcAllocColorPlanes,
+    SProcFreeColors,
+    SProcStoreColors,
+    SProcStoreNamedColor,              /* 90 */
+    SProcQueryColors,
+    SProcLookupColor,
+    SProcCreateCursor,
+    SProcCreateGlyphCursor,
+    SProcResourceReq,                  /* 95 SProcFreeCursor, */
+    SProcRecolorCursor,
+    SProcQueryBestSize,
+    SProcQueryExtension,
+    SProcSimpleReq,                    /* ListExtensions, */
+    SProcChangeKeyboardMapping,                /* 100 */
+    SProcSimpleReq,                    /* GetKeyboardMapping, */
+    SProcChangeKeyboardControl,
+    SProcSimpleReq,                    /* GetKeyboardControl, */
+    SProcSimpleReq,                    /* Bell, */
+    SProcChangePointerControl,         /* 105 */
+    SProcSimpleReq,                    /* GetPointerControl, */
+    SProcSetScreenSaver,
+    SProcSimpleReq,                    /* GetScreenSaver, */
+    SProcChangeHosts,
+    SProcSimpleReq,                    /* 110 ListHosts, */
+    SProcSimpleReq,                    /* SProcChangeAccessControl, */
+    SProcSimpleReq,                    /* SProcChangeCloseDownMode, */
+    SProcResourceReq,                  /* SProcKillClient, */
+    SProcRotateProperties,
+    SProcSimpleReq,                    /* 115 ForceScreenSaver */
+    SProcSimpleReq,                    /* SetPointerMapping, */
+    SProcSimpleReq,                    /* GetPointerMapping, */
+    SProcSimpleReq,                    /* SetModifierMapping, */
+    SProcSimpleReq,                    /* GetModifierMapping, */
+    0,                                 /* 120 */
+    0,
+    0,
+    0,
+    0,
+    0,                                 /* 125 */
+    0,
+    SProcNoOperation
+};
+
+EventSwapPtr EventSwapVector[128] =
+{
+    (EventSwapPtr)SErrorEvent,
+    NotImplemented,
+    SKeyButtonPtrEvent,
+    SKeyButtonPtrEvent,
+    SKeyButtonPtrEvent,
+    SKeyButtonPtrEvent,                        /* 5 */
+    SKeyButtonPtrEvent,
+    SEnterLeaveEvent,
+    SEnterLeaveEvent,
+    SFocusEvent,
+    SFocusEvent,                       /* 10 */
+    SKeymapNotifyEvent,
+    SExposeEvent,
+    SGraphicsExposureEvent,
+    SNoExposureEvent,
+    SVisibilityEvent,                  /* 15 */
+    SCreateNotifyEvent,
+    SDestroyNotifyEvent,
+    SUnmapNotifyEvent,
+    SMapNotifyEvent,
+    SMapRequestEvent,                  /* 20 */
+    SReparentEvent,
+    SConfigureNotifyEvent,
+    SConfigureRequestEvent,
+    SGravityEvent,
+    SResizeRequestEvent,               /* 25 */
+    SCirculateEvent,
+    SCirculateEvent,
+    SPropertyEvent,
+    SSelectionClearEvent,
+    SSelectionRequestEvent,            /* 30 */
+    SSelectionNotifyEvent,
+    SColormapEvent,
+    SClientMessageEvent,
+    SMappingEvent,
+};
+
+
+ReplySwapPtr ReplySwapVector[256] =
+{
+    ReplyNotSwappd,
+    ReplyNotSwappd,
+    ReplyNotSwappd,
+    (ReplySwapPtr)SGetWindowAttributesReply,
+    ReplyNotSwappd,
+    ReplyNotSwappd,                            /* 5 */
+    ReplyNotSwappd,
+    ReplyNotSwappd,
+    ReplyNotSwappd,
+    ReplyNotSwappd,
+    ReplyNotSwappd,                            /* 10 */
+    ReplyNotSwappd,
+    ReplyNotSwappd,
+    ReplyNotSwappd,
+    (ReplySwapPtr)SGetGeometryReply,
+    (ReplySwapPtr)SQueryTreeReply,             /* 15 */
+    (ReplySwapPtr)SInternAtomReply,
+    (ReplySwapPtr)SGetAtomNameReply,
+    ReplyNotSwappd,
+    ReplyNotSwappd,
+    (ReplySwapPtr)SGetPropertyReply,           /* 20 */
+    (ReplySwapPtr)SListPropertiesReply,
+    ReplyNotSwappd,
+    (ReplySwapPtr)SGetSelectionOwnerReply,
+    ReplyNotSwappd,
+    ReplyNotSwappd,                            /* 25 */
+    (ReplySwapPtr)SGenericReply,               /* SGrabPointerReply, */
+    ReplyNotSwappd,
+    ReplyNotSwappd,
+    ReplyNotSwappd,
+    ReplyNotSwappd,                            /* 30 */
+    (ReplySwapPtr)SGenericReply,               /* SGrabKeyboardReply, */
+    ReplyNotSwappd,
+    ReplyNotSwappd,
+    ReplyNotSwappd,
+    ReplyNotSwappd,                            /* 35 */
+    ReplyNotSwappd,
+    ReplyNotSwappd,
+    (ReplySwapPtr)SQueryPointerReply,
+    (ReplySwapPtr)SGetMotionEventsReply,
+    (ReplySwapPtr)STranslateCoordsReply,       /* 40 */
+    ReplyNotSwappd,
+    ReplyNotSwappd,
+    (ReplySwapPtr)SGetInputFocusReply,
+    (ReplySwapPtr)SQueryKeymapReply,
+    ReplyNotSwappd,                            /* 45 */
+    ReplyNotSwappd,
+    (ReplySwapPtr)SQueryFontReply,
+    (ReplySwapPtr)SQueryTextExtentsReply,
+    (ReplySwapPtr)SListFontsReply,
+    (ReplySwapPtr)SListFontsWithInfoReply,     /* 50 */
+    ReplyNotSwappd,
+    (ReplySwapPtr)SGetFontPathReply,
+    ReplyNotSwappd,
+    ReplyNotSwappd,
+    ReplyNotSwappd,                            /* 55 */
+    ReplyNotSwappd,
+    ReplyNotSwappd,
+    ReplyNotSwappd,
+    ReplyNotSwappd,
+    ReplyNotSwappd,                            /* 60 */
+    ReplyNotSwappd,
+    ReplyNotSwappd,
+    ReplyNotSwappd,
+    ReplyNotSwappd,
+    ReplyNotSwappd,                            /* 65 */
+    ReplyNotSwappd,
+    ReplyNotSwappd,
+    ReplyNotSwappd,
+    ReplyNotSwappd,
+    ReplyNotSwappd,                            /* 70 */
+    ReplyNotSwappd,
+    ReplyNotSwappd,
+    (ReplySwapPtr)SGetImageReply,
+    ReplyNotSwappd,
+    ReplyNotSwappd,                            /* 75 */
+    ReplyNotSwappd,
+    ReplyNotSwappd,
+    ReplyNotSwappd,
+    ReplyNotSwappd,
+    ReplyNotSwappd,                            /* 80 */
+    ReplyNotSwappd,
+    ReplyNotSwappd,
+    (ReplySwapPtr)SListInstalledColormapsReply,
+    (ReplySwapPtr)SAllocColorReply,
+    (ReplySwapPtr)SAllocNamedColorReply,       /* 85 */
+    (ReplySwapPtr)SAllocColorCellsReply,
+    (ReplySwapPtr)SAllocColorPlanesReply,
+    ReplyNotSwappd,
+    ReplyNotSwappd,
+    ReplyNotSwappd,                            /* 90 */
+    (ReplySwapPtr)SQueryColorsReply,
+    (ReplySwapPtr)SLookupColorReply,
+    ReplyNotSwappd,
+    ReplyNotSwappd,
+    ReplyNotSwappd,                            /* 95 */
+    ReplyNotSwappd,
+    (ReplySwapPtr)SQueryBestSizeReply,
+    (ReplySwapPtr)SGenericReply,               /* SQueryExtensionReply, */
+    (ReplySwapPtr)SListExtensionsReply,
+    ReplyNotSwappd,                            /* 100 */
+    (ReplySwapPtr)SGetKeyboardMappingReply,
+    ReplyNotSwappd,
+    (ReplySwapPtr)SGetKeyboardControlReply,
+    ReplyNotSwappd,
+    ReplyNotSwappd,                            /* 105 */
+    (ReplySwapPtr)SGetPointerControlReply,
+    ReplyNotSwappd,
+    (ReplySwapPtr)SGetScreenSaverReply,
+    ReplyNotSwappd,
+    (ReplySwapPtr)SListHostsReply,             /* 110 */
+    ReplyNotSwappd,
+    ReplyNotSwappd,
+    ReplyNotSwappd,
+    ReplyNotSwappd,
+    ReplyNotSwappd,                            /* 115 */
+    (ReplySwapPtr)SGenericReply,               /* SetPointerMapping */
+    (ReplySwapPtr)SGetPointerMappingReply,
+    (ReplySwapPtr)SGenericReply,               /* SetModifierMapping */
+    (ReplySwapPtr)SGetModifierMappingReply,    /* 119 */
+    ReplyNotSwappd,                            /* 120 */
+    ReplyNotSwappd,                            /* 121 */
+    ReplyNotSwappd,                            /* 122 */
+    ReplyNotSwappd,                            /* 123 */
+    ReplyNotSwappd,                            /* 124 */
+    ReplyNotSwappd,                            /* 125 */
+    ReplyNotSwappd,                            /* 126 */
+    ReplyNotSwappd,                            /* NoOperation */
+    ReplyNotSwappd
+};
+
+#ifdef K5AUTH
+int (*k5_Vector[256])() =
+{
+    k5_bad,
+    k5_stage1,
+    k5_bad,
+    k5_stage3
+};
+#endif
diff --git a/Xserver/programs/Xserver/dix/window.c b/Xserver/programs/Xserver/dix/window.c
new file mode 100644 (file)
index 0000000..c5e1f75
--- /dev/null
@@ -0,0 +1,3803 @@
+/* $XConsortium: window.c /main/210 1996/10/28 07:24:59 kaleb $ */
+/* $XFree86: xc/programs/Xserver/dix/window.c,v 3.6 1997/01/18 06:53:16 dawes Exp $ */
+/*
+
+Copyright (c) 1987  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be included
+in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR
+OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall
+not be used in advertising or otherwise to promote the sale, use or
+other dealings in this Software without prior written authorization
+from the X Consortium.
+
+
+Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts,
+
+                       All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and its 
+documentation for any purpose and without fee is hereby granted, 
+provided that the above copyright notice appear in all copies and that
+both that copyright notice and this permission notice appear in 
+supporting documentation, and that the name of Digital not be
+used in advertising or publicity pertaining to distribution of the
+software without specific, written prior permission.  
+
+DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
+ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
+DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
+ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+SOFTWARE.
+
+*/
+
+#include "misc.h"
+#include "scrnintstr.h"
+#include "os.h"
+#include "regionstr.h"
+#include "validate.h"
+#include "windowstr.h"
+#include "input.h"
+#include "resource.h"
+#include "colormapst.h"
+#include "cursorstr.h"
+#include "dixstruct.h"
+#include "gcstruct.h"
+#include "servermd.h"
+#include "dixevents.h"
+#ifdef XAPPGROUP
+#include "extensions/Xagsrv.h"
+#endif
+#ifdef XCSECURITY
+#define _SECURITY_SERVER
+#include "extensions/security.h"
+#endif
+
+extern Bool permitOldBugs;
+
+#if defined(NEED_SCREEN_REGIONS)
+#define REGION_PTR(pScreen,pWin) \
+    register ScreenPtr pScreen = pWin->drawable.pScreen;
+#else
+#define REGION_PTR(pScreen,pWin) /* nothing */
+#endif
+
+/******
+ * Window stuff for server 
+ *
+ *    CreateRootWindow, CreateWindow, ChangeWindowAttributes,
+ *    GetWindowAttributes, DeleteWindow, DestroySubWindows,
+ *    HandleSaveSet, ReparentWindow, MapWindow, MapSubWindows,
+ *    UnmapWindow, UnmapSubWindows, ConfigureWindow, CirculateWindow,
+ *
+ ******/
+
+static unsigned char _back_lsb[4] = {0x88, 0x22, 0x44, 0x11};
+static unsigned char _back_msb[4] = {0x11, 0x44, 0x22, 0x88};
+
+int screenIsSaved = SCREEN_SAVER_OFF;
+
+ScreenSaverStuffRec savedScreenInfo[MAXSCREENS];
+
+extern WindowPtr *WindowTable;
+
+extern int rand();
+
+static Bool TileScreenSaver(
+#if NeedFunctionPrototypes
+    int /*i*/,
+    int /*kind*/
+#endif
+);
+
+
+#define INPUTONLY_LEGAL_MASK (CWWinGravity | CWEventMask | \
+                             CWDontPropagate | CWOverrideRedirect | CWCursor )
+
+#define BOXES_OVERLAP(b1, b2) \
+      (!( ((b1)->x2 <= (b2)->x1)  || \
+       ( ((b1)->x1 >= (b2)->x2)) || \
+       ( ((b1)->y2 <= (b2)->y1)) || \
+       ( ((b1)->y1 >= (b2)->y2)) ) )
+
+#define RedirectSend(pWin) \
+    ((pWin->eventMask|wOtherEventMasks(pWin)) & SubstructureRedirectMask)
+
+#define SubSend(pWin) \
+    ((pWin->eventMask|wOtherEventMasks(pWin)) & SubstructureNotifyMask)
+
+#define StrSend(pWin) \
+    ((pWin->eventMask|wOtherEventMasks(pWin)) & StructureNotifyMask)
+
+#define SubStrSend(pWin,pParent) (StrSend(pWin) || SubSend(pParent))
+
+
+int numSaveUndersViewable = 0;
+int deltaSaveUndersViewable = 0;
+
+#ifdef DEBUG
+/******
+ * PrintWindowTree
+ *    For debugging only
+ ******/
+
+int
+PrintChildren(p1, indent)
+    WindowPtr p1;
+    int indent;
+{
+    WindowPtr p2;
+    int i;
+
+    while (p1)
+    {
+       p2 = p1->firstChild;
+       for (i=0; i<indent; i++) ErrorF( " ");
+       ErrorF( "%x\n", p1->drawable.id);
+       miPrintRegion(&p1->clipList);
+       PrintChildren(p2, indent+4);
+       p1 = p1->nextSib;
+    }
+}
+
+PrintWindowTree()
+{
+    int i;
+    WindowPtr pWin, p1;
+
+    for (i=0; i<screenInfo.numScreens; i++)
+    {
+       ErrorF( "WINDOW %d\n", i);
+       pWin = WindowTable[i];
+       miPrintRegion(&pWin->clipList);
+       p1 = pWin->firstChild;
+       PrintChildren(p1, 4);
+    }
+}
+#endif
+
+int
+TraverseTree(pWin, func, data)
+    register WindowPtr pWin;
+    VisitWindowProcPtr func;
+    pointer data;
+{
+    register int result;
+    register WindowPtr pChild;
+
+    if (!(pChild = pWin))
+       return(WT_NOMATCH);
+    while (1)
+    {
+       result = (* func)(pChild, data);
+       if (result == WT_STOPWALKING)
+           return(WT_STOPWALKING);
+       if ((result == WT_WALKCHILDREN) && pChild->firstChild)
+       {
+           pChild = pChild->firstChild;
+           continue;
+       }
+       while (!pChild->nextSib && (pChild != pWin))
+           pChild = pChild->parent;
+       if (pChild == pWin)
+           break;
+       pChild = pChild->nextSib;
+    }
+    return(WT_NOMATCH);
+}
+
+/*****
+ * WalkTree
+ *   Walk the window tree, for SCREEN, preforming FUNC(pWin, data) on
+ *   each window.  If FUNC returns WT_WALKCHILDREN, traverse the children,
+ *   if it returns WT_DONTWALKCHILDREN, dont.  If it returns WT_STOPWALKING
+ *   exit WalkTree.  Does depth-first traverse.
+ *****/
+
+int
+WalkTree(pScreen, func, data)
+    ScreenPtr pScreen;
+    VisitWindowProcPtr func;
+    pointer data;
+{
+    return(TraverseTree(WindowTable[pScreen->myNum], func, data));
+}
+
+/* hack for forcing backing store on all windows */
+int    defaultBackingStore = NotUseful;
+/* hack to force no backing store */
+Bool   disableBackingStore = FALSE;
+/* hack to force no save unders */
+Bool   disableSaveUnders = FALSE;
+
+static void
+#if NeedFunctionPrototypes
+SetWindowToDefaults(register WindowPtr pWin)
+#else
+SetWindowToDefaults(pWin)
+    register WindowPtr pWin;
+#endif
+{
+    pWin->prevSib = NullWindow;
+    pWin->firstChild = NullWindow;
+    pWin->lastChild = NullWindow;
+
+    pWin->valdata = (ValidatePtr)NULL;
+    pWin->optional = (WindowOptPtr)NULL;
+    pWin->cursorIsNone = TRUE;
+
+    pWin->backingStore = NotUseful;
+    pWin->DIXsaveUnder = FALSE;
+    pWin->backStorage = (pointer) NULL;
+
+    pWin->mapped = FALSE;          /* off */
+    pWin->realized = FALSE;    /* off */
+    pWin->viewable = FALSE;
+    pWin->visibility = VisibilityNotViewable;
+    pWin->overrideRedirect = FALSE;
+    pWin->saveUnder = FALSE;
+
+    pWin->bitGravity = ForgetGravity;
+    pWin->winGravity = NorthWestGravity;
+
+    pWin->eventMask = 0;
+    pWin->deliverableEvents = 0;
+    pWin->dontPropagate = 0;
+    pWin->forcedBS = FALSE;
+#ifdef NEED_DBE_BUF_BITS
+    pWin->srcBuffer = DBE_FRONT_BUFFER;
+    pWin->dstBuffer = DBE_FRONT_BUFFER;
+#endif
+}
+
+static void
+#if NeedFunctionPrototypes
+MakeRootTile(WindowPtr pWin)
+#else
+MakeRootTile(pWin)
+    WindowPtr pWin;
+#endif
+{
+    ScreenPtr pScreen = pWin->drawable.pScreen;
+    GCPtr pGC;
+    unsigned char back[128];
+    int len = BitmapBytePad(4);
+    register unsigned char *from, *to;
+    register int i, j;
+
+    pWin->background.pixmap = (*pScreen->CreatePixmap)(pScreen, 4, 4,
+                                                   pScreen->rootDepth);
+
+    pWin->backgroundState = BackgroundPixmap;
+    pGC = GetScratchGC(pScreen->rootDepth, pScreen);
+    if (!pWin->background.pixmap || !pGC)
+       FatalError("cound not create root tile");
+
+    {
+       CARD32 attributes[2];
+
+       attributes[0] = pScreen->whitePixel;
+       attributes[1] = pScreen->blackPixel;
+
+       (void)ChangeGC(pGC, GCForeground | GCBackground, attributes);
+    }
+
+   ValidateGC((DrawablePtr)pWin->background.pixmap, pGC);
+
+   from = (screenInfo.bitmapBitOrder == LSBFirst) ? _back_lsb : _back_msb;
+   to = back;
+
+   for (i = 4; i > 0; i--, from++)
+       for (j = len; j > 0; j--)
+           *to++ = *from;
+
+   (*pGC->ops->PutImage)((DrawablePtr)pWin->background.pixmap, pGC, 1,
+                   0, 0, 4, 4, 0, XYBitmap, (char *)back);
+
+   FreeScratchGC(pGC);
+
+}
+
+WindowPtr
+AllocateWindow(pScreen)
+    ScreenPtr pScreen;
+{
+    WindowPtr pWin;
+    register char *ptr;
+    register DevUnion *ppriv;
+    register unsigned *sizes;
+    register unsigned size;
+    register int i;
+
+    pWin = (WindowPtr)xalloc(pScreen->totalWindowSize);
+    if (pWin)
+    {
+       ppriv = (DevUnion *)(pWin + 1);
+       pWin->devPrivates = ppriv;
+       sizes = pScreen->WindowPrivateSizes;
+       ptr = (char *)(ppriv + pScreen->WindowPrivateLen);
+       for (i = pScreen->WindowPrivateLen; --i >= 0; ppriv++, sizes++)
+       {
+           if ( (size = *sizes) )
+           {
+               ppriv->ptr = (pointer)ptr;
+               ptr += size;
+           }
+           else
+               ppriv->ptr = (pointer)NULL;
+       }
+    }
+    return pWin;
+}
+
+/*****
+ * CreateRootWindow
+ *    Makes a window at initialization time for specified screen
+ *****/
+
+Bool
+CreateRootWindow(pScreen)
+    ScreenPtr  pScreen;
+{
+    WindowPtr  pWin;
+    BoxRec     box;
+    PixmapFormatRec *format;
+
+    pWin = AllocateWindow(pScreen);
+    if (!pWin)
+       return FALSE;
+
+    savedScreenInfo[pScreen->myNum].pWindow = NULL;
+    savedScreenInfo[pScreen->myNum].wid = FakeClientID(0);
+    savedScreenInfo[pScreen->myNum].ExternalScreenSaver = NULL;
+    screenIsSaved = SCREEN_SAVER_OFF;
+
+    WindowTable[pScreen->myNum] = pWin;
+
+    pWin->drawable.pScreen = pScreen;
+    pWin->drawable.type = DRAWABLE_WINDOW;
+
+    pWin->drawable.depth = pScreen->rootDepth;
+    for (format = screenInfo.formats;
+        format->depth != pScreen->rootDepth;
+        format++)
+       ;
+    pWin->drawable.bitsPerPixel = format->bitsPerPixel;
+
+    pWin->drawable.serialNumber = NEXT_SERIAL_NUMBER;
+
+    pWin->parent = NullWindow;
+    SetWindowToDefaults(pWin);
+
+    pWin->optional = (WindowOptRec *) xalloc (sizeof (WindowOptRec));
+
+    pWin->optional->dontPropagateMask = 0;
+    pWin->optional->otherEventMasks = 0;
+    pWin->optional->otherClients = NULL;
+    pWin->optional->passiveGrabs = NULL;
+    pWin->optional->userProps = NULL;
+    pWin->optional->backingBitPlanes = ~0L;
+    pWin->optional->backingPixel = 0;
+#ifdef SHAPE
+    pWin->optional->boundingShape = NULL;
+    pWin->optional->clipShape = NULL;
+#endif
+#ifdef XINPUT
+    pWin->optional->inputMasks = NULL;
+#endif
+    pWin->optional->colormap = pScreen->defColormap;
+    pWin->optional->visual = pScreen->rootVisual;
+
+    pWin->nextSib = NullWindow;
+
+    pWin->drawable.id = FakeClientID(0);
+
+    pWin->origin.x = pWin->origin.y = 0;
+    pWin->drawable.height = pScreen->height;
+    pWin->drawable.width = pScreen->width;
+    pWin->drawable.x = pWin->drawable.y = 0;
+
+    box.x1 = 0;
+    box.y1 = 0;
+    box.x2 = pScreen->width;
+    box.y2 = pScreen->height;
+    REGION_INIT(pScreen, &pWin->clipList, &box, 1);
+    REGION_INIT(pScreen, &pWin->winSize, &box, 1);
+    REGION_INIT(pScreen, &pWin->borderSize, &box, 1);
+    REGION_INIT(pScreen, &pWin->borderClip, &box, 1);
+
+    pWin->drawable.class = InputOutput;
+    pWin->optional->visual = pScreen->rootVisual;
+
+    pWin->backgroundState = BackgroundPixel;
+    pWin->background.pixel = pScreen->whitePixel;
+
+    pWin->borderIsPixel = TRUE;
+    pWin->border.pixel = pScreen->blackPixel;
+    pWin->borderWidth = 0;
+
+    if (!AddResource(pWin->drawable.id, RT_WINDOW, (pointer)pWin))
+       return FALSE;
+
+    if (disableBackingStore)
+       pScreen->backingStoreSupport = NotUseful;
+
+#ifdef DO_SAVE_UNDERS
+    if ((pScreen->backingStoreSupport != NotUseful) &&
+       (pScreen->saveUnderSupport == NotUseful))
+    {
+       /*
+        * If the screen has backing-store but no save-unders, let the
+        * clients know we can support save-unders using backing-store.
+        */
+       pScreen->saveUnderSupport = USE_DIX_SAVE_UNDERS;
+    }
+#endif /* DO_SAVE_UNDERS */
+               
+    if (disableSaveUnders)
+       pScreen->saveUnderSupport = NotUseful;
+
+    return TRUE;
+}
+
+void
+InitRootWindow(pWin)
+    WindowPtr pWin;
+{
+    ScreenPtr pScreen;
+
+    pScreen = pWin->drawable.pScreen;
+    if (!(*pScreen->CreateWindow)(pWin))
+       return; /* XXX */
+    (*pScreen->PositionWindow)(pWin, 0, 0);
+
+    pWin->cursorIsNone = FALSE;
+    pWin->optional->cursor = rootCursor;
+    rootCursor->refcnt++;
+    MakeRootTile(pWin);
+    pWin->backingStore = defaultBackingStore;
+    pWin->forcedBS = (defaultBackingStore != NotUseful);
+    /* We SHOULD check for an error value here XXX */
+    (*pScreen->ChangeWindowAttributes)(pWin,
+                      CWBackPixmap|CWBorderPixel|CWCursor|CWBackingStore);
+
+    MapWindow(pWin, serverClient);
+}
+
+/* Set the region to the intersection of the rectangle and the
+ * window's winSize.  The window is typically the parent of the
+ * window from which the region came.
+ */
+
+void
+ClippedRegionFromBox(pWin, Rgn, x, y, w, h)
+    register WindowPtr pWin;
+    RegionPtr Rgn;
+    register int x, y;
+    int w, h;
+{
+    REGION_PTR(pScreen, pWin)
+    BoxRec box;
+
+    box = *(REGION_EXTENTS(pScreen, &pWin->winSize));
+    /* we do these calculations to avoid overflows */
+    if (x > box.x1)
+       box.x1 = x;
+    if (y > box.y1)
+       box.y1 = y;
+    x += w;
+    if (x < box.x2)
+       box.x2 = x;
+    y += h;
+    if (y < box.y2)
+       box.y2 = y;
+    if (box.x1 > box.x2)
+       box.x2 = box.x1;
+    if (box.y1 > box.y2)
+       box.y2 = box.y1;
+    REGION_RESET(pScreen, Rgn, &box);
+    REGION_INTERSECT(pScreen, Rgn, Rgn, &pWin->winSize);
+}
+
+WindowPtr
+RealChildHead(pWin)
+    register WindowPtr pWin;
+{
+    if (!pWin->parent &&
+       (screenIsSaved == SCREEN_SAVER_ON) &&
+       (HasSaverWindow (pWin->drawable.pScreen->myNum)))
+       return (pWin->firstChild);
+    else
+       return (NullWindow);
+}
+
+/*****
+ * CreateWindow
+ *    Makes a window in response to client request 
+ *****/
+
+WindowPtr
+CreateWindow(wid, pParent, x, y, w, h, bw, class, vmask, vlist,
+            depth, client, visual, error)
+    Window wid;
+    register WindowPtr pParent;
+    int x,y;
+    unsigned int w, h, bw;
+    unsigned int class;
+    register Mask vmask;
+    XID *vlist;
+    int depth;
+    ClientPtr client;
+    VisualID visual;
+    int *error;
+{
+    register WindowPtr pWin;
+    WindowPtr pHead;
+    register ScreenPtr pScreen;
+    xEvent event;
+    int idepth, ivisual;
+    Bool fOK;
+    DepthPtr pDepth;
+    PixmapFormatRec *format;
+    register WindowOptPtr ancwopt;
+
+    if (class == CopyFromParent)
+       class = pParent->drawable.class;
+
+    if ((class != InputOutput) && (class != InputOnly))
+    {
+       *error = BadValue;
+       client->errorValue = class;
+       return NullWindow;
+    }
+
+    if ((class != InputOnly) && (pParent->drawable.class == InputOnly))
+    {
+       *error = BadMatch;
+       return NullWindow;
+    }
+
+    if ((class == InputOnly) && ((bw != 0) || (depth != 0)))
+    {
+       *error = BadMatch;
+       return NullWindow;
+    }
+
+    pScreen = pParent->drawable.pScreen;
+
+    if ((class == InputOutput) && (depth == 0))
+       depth = pParent->drawable.depth;
+    ancwopt = pParent->optional;
+    if (!ancwopt)
+       ancwopt = FindWindowWithOptional(pParent)->optional;
+    if (visual == CopyFromParent) {
+#ifdef XAPPGROUP
+       VisualID ag_visual;
+
+       if (client->appgroup && !pParent->parent &&
+           (ag_visual = XagRootVisual (client)))
+           visual = ag_visual;
+       else
+#endif
+       visual = ancwopt->visual;
+    }
+
+    /* Find out if the depth and visual are acceptable for this Screen */
+    if ((visual != ancwopt->visual) || (depth != pParent->drawable.depth))
+    {
+       fOK = FALSE;
+       for(idepth = 0; idepth < pScreen->numDepths; idepth++)
+       {
+           pDepth = (DepthPtr) &pScreen->allowedDepths[idepth];
+           if ((depth == pDepth->depth) || (depth == 0))
+           {
+               for (ivisual = 0; ivisual < pDepth->numVids; ivisual++)
+               {
+                   if (visual == pDepth->vids[ivisual])
+                   {
+                       fOK = TRUE;
+                       break;
+                   }
+               }
+           }
+       }
+       if (fOK == FALSE)
+       {
+           *error = BadMatch;
+           return NullWindow;
+       }
+    }
+
+    if (((vmask & (CWBorderPixmap | CWBorderPixel)) == 0) &&
+       (class != InputOnly) &&
+       (depth != pParent->drawable.depth))
+    {
+       *error = BadMatch;
+       return NullWindow;
+    }
+
+    if (((vmask & CWColormap) == 0) &&
+       (class != InputOnly) &&
+       ((visual != ancwopt->visual) || (ancwopt->colormap == None)))
+    {
+       *error = BadMatch;
+       return NullWindow;
+    }
+
+    pWin = AllocateWindow(pScreen);
+    if (!pWin)
+    {
+       *error = BadAlloc;
+       return NullWindow;
+    }
+    pWin->drawable = pParent->drawable;
+    pWin->drawable.depth = depth;
+    if (depth == pParent->drawable.depth)
+       pWin->drawable.bitsPerPixel = pParent->drawable.bitsPerPixel;
+    else
+    {
+       for (format = screenInfo.formats; format->depth != depth; format++)
+           ;
+       pWin->drawable.bitsPerPixel = format->bitsPerPixel;
+    }
+    if (class == InputOnly)
+       pWin->drawable.type = (short) UNDRAWABLE_WINDOW;
+    pWin->drawable.serialNumber = NEXT_SERIAL_NUMBER;
+
+    pWin->drawable.id = wid;
+    pWin->drawable.class = class;
+
+    pWin->parent = pParent;
+    SetWindowToDefaults(pWin);
+
+    if (visual != ancwopt->visual)
+    {
+       if (!MakeWindowOptional (pWin))
+       {
+           xfree (pWin);
+           *error = BadAlloc;
+           return NullWindow;
+       }
+       pWin->optional->visual = visual;
+       pWin->optional->colormap = None;
+    }
+
+    pWin->borderWidth = bw;
+#ifdef XCSECURITY
+    /*  can't let untrusted clients have background None windows;
+     *  they make it too easy to steal window contents
+     */
+    if (client->trustLevel != XSecurityClientTrusted)
+    {
+       pWin->backgroundState = BackgroundPixel;
+       pWin->background.pixel = 0;
+    }
+    else
+#endif
+    pWin->backgroundState = None;
+
+    pWin->borderIsPixel = pParent->borderIsPixel;
+    pWin->border = pParent->border;
+    if (pWin->borderIsPixel == FALSE)
+       pWin->border.pixmap->refcnt++;
+               
+    pWin->origin.x = x + (int)bw;
+    pWin->origin.y = y + (int)bw;
+    pWin->drawable.width = w;
+    pWin->drawable.height = h;
+    pWin->drawable.x = pParent->drawable.x + x + (int)bw;
+    pWin->drawable.y = pParent->drawable.y + y + (int)bw;
+
+       /* set up clip list correctly for unobscured WindowPtr */
+    REGION_INIT(pScreen, &pWin->clipList, NullBox, 1);
+    REGION_INIT(pScreen, &pWin->borderClip, NullBox, 1);
+    REGION_INIT(pScreen, &pWin->winSize, NullBox, 1);
+    REGION_INIT(pScreen, &pWin->borderSize, NullBox, 1);
+
+    pHead = RealChildHead(pParent);
+    if (pHead)
+    {
+       pWin->nextSib = pHead->nextSib;
+       if (pHead->nextSib)
+           pHead->nextSib->prevSib = pWin;
+       else
+           pParent->lastChild = pWin;
+       pHead->nextSib = pWin;
+       pWin->prevSib = pHead;
+    }
+    else
+    {
+       pWin->nextSib = pParent->firstChild;
+       if (pParent->firstChild)
+           pParent->firstChild->prevSib = pWin;
+       else
+           pParent->lastChild = pWin;
+       pParent->firstChild = pWin;
+    }
+
+    SetWinSize (pWin);
+    SetBorderSize (pWin);
+
+    /* We SHOULD check for an error value here XXX */
+    if (!(*pScreen->CreateWindow)(pWin))
+    {
+       *error = BadAlloc;
+       DeleteWindow(pWin, None);
+       return NullWindow;
+    }
+    /* We SHOULD check for an error value here XXX */
+    (*pScreen->PositionWindow)(pWin, pWin->drawable.x, pWin->drawable.y);
+
+    if (!(vmask & CWEventMask))
+       RecalculateDeliverableEvents(pWin);
+
+    if (vmask)
+       *error = ChangeWindowAttributes(pWin, vmask, vlist, wClient (pWin));
+    else
+       *error = Success;
+
+    if (*error != Success)
+    {
+       DeleteWindow(pWin, None);
+       return NullWindow;
+    }
+    if (!(vmask & CWBackingStore) && (defaultBackingStore != NotUseful))
+    {
+       XID value = defaultBackingStore;
+       (void)ChangeWindowAttributes(pWin, CWBackingStore, &value, wClient (pWin));
+       pWin->forcedBS = TRUE;
+    }
+
+    if (SubSend(pParent))
+    {
+       event.u.u.type = CreateNotify;
+       event.u.createNotify.window = wid;
+       event.u.createNotify.parent = pParent->drawable.id;
+       event.u.createNotify.x = x;
+       event.u.createNotify.y = y;
+       event.u.createNotify.width = w;
+       event.u.createNotify.height = h;
+       event.u.createNotify.borderWidth = bw;
+       event.u.createNotify.override = pWin->overrideRedirect;
+       DeliverEvents(pParent, &event, 1, NullWindow);          
+    }
+
+    return pWin;
+}
+
+static void
+#if NeedFunctionPrototypes
+FreeWindowResources(register WindowPtr pWin)
+#else
+FreeWindowResources(pWin)
+    register WindowPtr pWin;
+#endif
+{
+    register ScreenPtr pScreen = pWin->drawable.pScreen;
+
+    DeleteWindowFromAnySaveSet(pWin);
+    DeleteWindowFromAnySelections(pWin);
+    DeleteWindowFromAnyEvents(pWin, TRUE);
+    REGION_UNINIT(pScreen, &pWin->clipList);
+    REGION_UNINIT(pScreen, &pWin->winSize);
+    REGION_UNINIT(pScreen, &pWin->borderClip);
+    REGION_UNINIT(pScreen, &pWin->borderSize);
+#ifdef SHAPE
+    if (wBoundingShape (pWin))
+       REGION_DESTROY(pScreen, wBoundingShape (pWin));
+    if (wClipShape (pWin))
+       REGION_DESTROY(pScreen, wClipShape (pWin));
+#endif
+    if (pWin->borderIsPixel == FALSE)
+       (*pScreen->DestroyPixmap)(pWin->border.pixmap);
+    if (pWin->backgroundState == BackgroundPixmap)
+       (*pScreen->DestroyPixmap)(pWin->background.pixmap);
+
+    DeleteAllWindowProperties(pWin);
+    /* We SHOULD check for an error value here XXX */
+    (*pScreen->DestroyWindow)(pWin);
+    DisposeWindowOptional (pWin);
+}
+
+static void
+#if NeedFunctionPrototypes
+CrushTree(WindowPtr pWin)
+#else
+CrushTree(pWin)
+    WindowPtr pWin;
+#endif
+{
+    register WindowPtr pChild, pSib, pParent;
+    UnrealizeWindowProcPtr UnrealizeWindow;
+    xEvent event;
+
+    if (!(pChild = pWin->firstChild))
+       return;
+    UnrealizeWindow = pWin->drawable.pScreen->UnrealizeWindow;
+    while (1)
+    {
+       if (pChild->firstChild)
+       {
+           pChild = pChild->firstChild;
+           continue;
+       }
+       while (1)
+       {
+           pParent = pChild->parent;
+           if (SubStrSend(pChild, pParent))
+           {
+               event.u.u.type = DestroyNotify;
+               event.u.destroyNotify.window = pChild->drawable.id;
+               DeliverEvents(pChild, &event, 1, NullWindow);           
+           }
+           FreeResource(pChild->drawable.id, RT_WINDOW);
+           pSib = pChild->nextSib;
+#ifdef DO_SAVE_UNDERS
+           if (pChild->saveUnder && pChild->viewable)
+               deltaSaveUndersViewable--;
+#endif
+           pChild->viewable = FALSE;
+           if (pChild->realized)
+           {
+               pChild->realized = FALSE;
+               (*UnrealizeWindow)(pChild);
+           }
+           FreeWindowResources(pChild);
+           xfree(pChild);
+           if ( (pChild = pSib) )
+               break;
+           pChild = pParent;
+           pChild->firstChild = NullWindow;
+           pChild->lastChild = NullWindow;
+           if (pChild == pWin)
+               return;
+       }
+    }
+}
+       
+/*****
+ *  DeleteWindow
+ *      Deletes child of window then window itself
+ *      If wid is None, don't send any events
+ *****/
+
+/*ARGSUSED*/
+int
+DeleteWindow(value, wid)
+    pointer value;
+    XID wid;
+ {
+    register WindowPtr pParent;
+    register WindowPtr pWin = (WindowPtr)value;
+    xEvent event;
+
+    UnmapWindow(pWin, FALSE);
+
+    CrushTree(pWin);
+
+    pParent = pWin->parent;
+    if (wid && pParent && SubStrSend(pWin, pParent))
+    {
+       event.u.u.type = DestroyNotify;
+       event.u.destroyNotify.window = pWin->drawable.id;
+       DeliverEvents(pWin, &event, 1, NullWindow);             
+    }
+
+    FreeWindowResources(pWin);
+    if (pParent)
+    {
+       if (pParent->firstChild == pWin)
+           pParent->firstChild = pWin->nextSib;
+       if (pParent->lastChild == pWin)
+           pParent->lastChild = pWin->prevSib;
+       if (pWin->nextSib)
+           pWin->nextSib->prevSib = pWin->prevSib;
+       if (pWin->prevSib)
+           pWin->prevSib->nextSib = pWin->nextSib;
+    }
+    xfree(pWin);
+    return Success;
+}
+
+/*ARGSUSED*/
+void
+DestroySubwindows(pWin, client)
+    register WindowPtr pWin;
+    ClientPtr client;
+{
+    /* XXX
+     * The protocol is quite clear that each window should be
+     * destroyed in turn, however, unmapping all of the first
+     * eliminates most of the calls to ValidateTree.  So,
+     * this implementation is incorrect in that all of the
+     * UnmapNotifies occur before all of the DestroyNotifies.
+     * If you care, simply delete the call to UnmapSubwindows.
+     */
+    UnmapSubwindows(pWin);
+    while (pWin->lastChild)
+       FreeResource(pWin->lastChild->drawable.id, RT_NONE);
+}
+
+#define DeviceEventMasks (KeyPressMask | KeyReleaseMask | ButtonPressMask | \
+    ButtonReleaseMask | PointerMotionMask)
+
+/*****
+ *  ChangeWindowAttributes
+ *   
+ *  The value-mask specifies which attributes are to be changed; the
+ *  value-list contains one value for each one bit in the mask, from least
+ *  to most significant bit in the mask.  
+ *****/
+int
+ChangeWindowAttributes(pWin, vmask, vlist, client)
+    register WindowPtr pWin;
+    Mask vmask;
+    XID *vlist;
+    ClientPtr client;
+{
+    register Mask index2;
+    register XID *pVlist;
+    PixmapPtr pPixmap;
+    Pixmap pixID;
+    CursorPtr pCursor, pOldCursor;
+    Cursor cursorID;
+    WindowPtr pChild;
+    Colormap cmap;
+    ColormapPtr        pCmap;
+    xEvent xE;
+    int result;
+    register ScreenPtr pScreen;
+    Mask vmaskCopy = 0;
+    register Mask tmask;
+    unsigned int val;
+    int error;
+    Bool checkOptional = FALSE;
+    Bool borderRelative = FALSE;
+    WindowPtr pLayerWin;
+
+    if ((pWin->drawable.class == InputOnly) && (vmask & (~INPUTONLY_LEGAL_MASK)))
+       return BadMatch;
+
+    error = Success;
+    pScreen = pWin->drawable.pScreen;
+    pVlist = vlist;
+    tmask = vmask;
+    while (tmask)
+    {
+       index2 = (Mask) lowbit (tmask);
+       tmask &= ~index2;
+       switch (index2)
+       {
+         case CWBackPixmap:
+           pixID = (Pixmap )*pVlist;
+           pVlist++;
+           if (pWin->backgroundState == ParentRelative)
+               borderRelative = TRUE;
+           if (pixID == None)
+           {
+#ifdef XCSECURITY
+               /*  can't let untrusted clients have background None windows */
+               if (client->trustLevel == XSecurityClientTrusted)
+               {
+#endif
+               if (pWin->backgroundState == BackgroundPixmap)
+                   (*pScreen->DestroyPixmap)(pWin->background.pixmap);
+               if (!pWin->parent)
+                   MakeRootTile(pWin);
+               else
+                   pWin->backgroundState = None;
+#ifdef XCSECURITY
+               }
+               else
+               { /* didn't change the background to None, so don't tell ddx */
+                   index2 = 0; 
+               }
+#endif
+           }
+           else if (pixID == ParentRelative)
+           {
+               if (pWin->parent &&
+                   pWin->drawable.depth != pWin->parent->drawable.depth)
+               {
+                   error = BadMatch;
+                   goto PatchUp;
+               }
+               if (pWin->backgroundState == BackgroundPixmap)
+                   (*pScreen->DestroyPixmap)(pWin->background.pixmap);
+               if (!pWin->parent)
+                   MakeRootTile(pWin);
+               else
+                   pWin->backgroundState = ParentRelative;
+               borderRelative = TRUE;
+               /* Note that the parent's backgroundTile's refcnt is NOT
+                * incremented. */
+           }
+           else
+           {   
+               pPixmap = (PixmapPtr)SecurityLookupIDByType(client, pixID,
+                                               RT_PIXMAP, SecurityReadAccess);
+               if (pPixmap != (PixmapPtr) NULL)
+               {
+                   if  ((pPixmap->drawable.depth != pWin->drawable.depth) ||
+                        (pPixmap->drawable.pScreen != pScreen))
+                   {
+                       error = BadMatch;
+                       goto PatchUp;
+                   }
+                   if (pWin->backgroundState == BackgroundPixmap)
+                       (*pScreen->DestroyPixmap)(pWin->background.pixmap);
+                   pWin->backgroundState = BackgroundPixmap;
+                   pWin->background.pixmap = pPixmap;
+                   pPixmap->refcnt++;
+               }
+               else
+               {
+                   error = BadPixmap;
+                   client->errorValue = pixID;
+                   goto PatchUp;
+               }
+           }
+           break;
+         case CWBackPixel:
+           if (pWin->backgroundState == ParentRelative)
+               borderRelative = TRUE;
+           if (pWin->backgroundState == BackgroundPixmap)
+               (*pScreen->DestroyPixmap)(pWin->background.pixmap);
+           pWin->backgroundState = BackgroundPixel;
+           pWin->background.pixel = (CARD32 ) *pVlist;
+                  /* background pixel overrides background pixmap,
+                     so don't let the ddx layer see both bits */
+           vmaskCopy &= ~CWBackPixmap;
+           pVlist++;
+           break;
+         case CWBorderPixmap:
+           pixID = (Pixmap ) *pVlist;
+           pVlist++;
+           if (pixID == CopyFromParent)
+           {
+               if (!pWin->parent ||
+                   (pWin->drawable.depth != pWin->parent->drawable.depth))
+               {
+                   error = BadMatch;
+                   goto PatchUp;
+               }
+               if (pWin->borderIsPixel == FALSE)
+                   (*pScreen->DestroyPixmap)(pWin->border.pixmap);
+               pWin->border = pWin->parent->border;
+               if ((pWin->borderIsPixel = pWin->parent->borderIsPixel) == TRUE)
+               {
+                   index2 = CWBorderPixel;
+               }
+               else
+               {
+                   pWin->parent->border.pixmap->refcnt++;
+               }
+           }
+           else
+           {   
+               pPixmap = (PixmapPtr)SecurityLookupIDByType(client, pixID,
+                                       RT_PIXMAP, SecurityReadAccess);
+               if (pPixmap)
+               {
+                   if  ((pPixmap->drawable.depth != pWin->drawable.depth) ||
+                        (pPixmap->drawable.pScreen != pScreen))
+                   {
+                       error = BadMatch;
+                       goto PatchUp;
+                   }
+                   if (pWin->borderIsPixel == FALSE)
+                       (*pScreen->DestroyPixmap)(pWin->border.pixmap);
+                   pWin->borderIsPixel = FALSE;
+                   pWin->border.pixmap = pPixmap;
+                   pPixmap->refcnt++;
+               }
+               else
+               {
+                   error = BadPixmap;
+                   client->errorValue = pixID;
+                   goto PatchUp;
+               }
+           }
+           break;
+         case CWBorderPixel:
+           if (pWin->borderIsPixel == FALSE)
+               (*pScreen->DestroyPixmap)(pWin->border.pixmap);
+           pWin->borderIsPixel = TRUE;
+           pWin->border.pixel = (CARD32) *pVlist;
+                   /* border pixel overrides border pixmap,
+                      so don't let the ddx layer see both bits */
+           vmaskCopy &= ~CWBorderPixmap;
+           pVlist++;
+           break;
+         case CWBitGravity:
+           val = (CARD8 )*pVlist;
+           pVlist++;
+           if (val > StaticGravity)
+           {
+               error = BadValue;
+               client->errorValue = val;
+               goto PatchUp;
+           }
+           pWin->bitGravity = val;
+           break;
+         case CWWinGravity:
+           val = (CARD8 )*pVlist;
+           pVlist++;
+           if (val > StaticGravity)
+           {
+               error = BadValue;
+               client->errorValue = val;
+               goto PatchUp;
+           }
+           pWin->winGravity = val;
+           break;
+         case CWBackingStore:
+           val = (CARD8 )*pVlist;
+           pVlist++;
+           if ((val != NotUseful) && (val != WhenMapped) && (val != Always))
+           {
+               error = BadValue;
+               client->errorValue = val;
+               goto PatchUp;
+           }
+           pWin->backingStore = val;
+           pWin->forcedBS = FALSE;
+           break;
+         case CWBackingPlanes:
+           if (pWin->optional || ((CARD32)*pVlist != (CARD32)~0L)) {
+               if (!pWin->optional && !MakeWindowOptional (pWin))
+               {
+                   error = BadAlloc;
+                   goto PatchUp;
+               }
+               pWin->optional->backingBitPlanes = (CARD32) *pVlist;
+               if ((CARD32)*pVlist == (CARD32)~0L)
+                   checkOptional = TRUE;
+           }
+           pVlist++;
+           break;
+         case CWBackingPixel:
+           if (pWin->optional || (CARD32) *pVlist) {
+               if (!pWin->optional && !MakeWindowOptional (pWin))
+               {
+                   error = BadAlloc;
+                   goto PatchUp;
+               }
+               pWin->optional->backingPixel = (CARD32) *pVlist;
+               if (!*pVlist)
+                   checkOptional = TRUE;
+           }
+           pVlist++;
+           break;
+         case CWSaveUnder:
+           val = (BOOL) *pVlist;
+           pVlist++;
+           if ((val != xTrue) && (val != xFalse))
+           {
+               error = BadValue;
+               client->errorValue = val;
+               goto PatchUp;
+           }
+#ifdef DO_SAVE_UNDERS
+           if (pWin->parent && (pWin->saveUnder != val) && (pWin->viewable) &&
+               DO_SAVE_UNDERS(pWin))
+           {
+               /*
+                * Re-check all siblings and inferiors for obscurity or
+                * exposition (hee hee).
+                */
+               if (pWin->saveUnder)
+                   deltaSaveUndersViewable--;
+               else
+                   deltaSaveUndersViewable++;
+               pWin->saveUnder = val;
+
+               if (pWin->firstChild)
+               {
+                    pLayerWin = (*pScreen->GetLayerWindow)(pWin);
+                   if ((*pScreen->ChangeSaveUnder)(pLayerWin->parent, pWin->nextSib))
+                       (*pScreen->PostChangeSaveUnder)(pLayerWin->parent,
+                                                       pWin->nextSib);
+               }
+               else
+               {
+                   if ((*pScreen->ChangeSaveUnder)(pWin, pWin->nextSib))
+                       (*pScreen->PostChangeSaveUnder)(pWin,
+                                                       pWin->nextSib);
+               }                                   
+           }
+           else
+           {
+               /*  If we're changing the saveUnder attribute of the root 
+                *  window, all we do is set pWin->saveUnder so that
+                *  GetWindowAttributes returns the right value.  We don't
+                *  do the "normal" save-under processing (as above).
+                *  Hope that doesn't cause any problems.
+                */
+               pWin->saveUnder = val;
+           }
+#else
+           pWin->saveUnder = val;
+#endif /* DO_SAVE_UNDERS */
+           break;
+         case CWEventMask:
+           result = EventSelectForWindow(pWin, client, (Mask )*pVlist);
+           if (result)
+           {
+               error = result;
+               goto PatchUp;
+           }
+           pVlist++;
+           break;
+         case CWDontPropagate:
+           result = EventSuppressForWindow(pWin, client, (Mask )*pVlist,
+                                           &checkOptional);
+           if (result)
+           {
+               error = result;
+               goto PatchUp;
+           }
+           pVlist++;
+           break;
+         case CWOverrideRedirect:
+           val = (BOOL ) *pVlist;
+           pVlist++;
+           if ((val != xTrue) && (val != xFalse))
+           {
+               error = BadValue;
+               client->errorValue = val;
+               goto PatchUp;
+           }
+           pWin->overrideRedirect = val;
+           break;
+         case CWColormap:
+           cmap = (Colormap) *pVlist;
+           pVlist++;
+           if (cmap == CopyFromParent)
+           {
+#ifdef XAPPGROUP
+               Colormap ag_colormap;
+               ClientPtr win_owner;
+
+               /*
+                * win_owner == client for CreateWindow, other clients
+                * can ChangeWindowAttributes
+                */
+               win_owner = LookupClient (pWin->drawable.id, client);
+
+               if ( win_owner && win_owner->appgroup &&
+                   !pWin->parent->parent &&
+                   (ag_colormap = XagDefaultColormap (win_owner)))
+                   cmap = ag_colormap;
+               else
+#endif
+               if (pWin->parent &&
+                   (!pWin->optional ||
+                    pWin->optional->visual == wVisual (pWin->parent)))
+               {
+                   cmap = wColormap (pWin->parent);
+               }
+               else
+                   cmap = None;
+           }
+           if (cmap == None)
+           {
+               error = BadMatch;
+               goto PatchUp;
+           }
+           pCmap = (ColormapPtr)SecurityLookupIDByType(client, cmap,
+                                             RT_COLORMAP, SecurityReadAccess);
+           if (!pCmap)
+           {
+               error = BadColor;
+               client->errorValue = cmap;
+               goto PatchUp;
+           }
+           if (pCmap->pVisual->vid != wVisual (pWin) ||
+               pCmap->pScreen != pScreen)
+           {
+               error = BadMatch;
+               goto PatchUp;
+           }
+           if (cmap != wColormap (pWin))
+           {
+               if (!pWin->optional)
+               {
+                   if (!MakeWindowOptional (pWin))
+                   {
+                       error = BadAlloc;
+                       goto PatchUp;
+                   }
+               }
+               else if (pWin->parent && cmap == wColormap (pWin->parent))
+                   checkOptional = TRUE;
+
+               /*
+                * propagate the original colormap to any children
+                * inheriting it
+                */
+
+               for (pChild = pWin->firstChild; pChild; pChild=pChild->nextSib)
+               {
+                   if (!pChild->optional && !MakeWindowOptional (pChild))
+                   {
+                       error = BadAlloc;
+                       goto PatchUp;
+                   }
+               }
+
+               pWin->optional->colormap = cmap;
+
+               /*
+                * check on any children now matching the new colormap
+                */
+
+               for (pChild = pWin->firstChild; pChild; pChild=pChild->nextSib)
+               {
+                   if (pChild->optional->colormap == cmap)
+                       CheckWindowOptionalNeed (pChild);
+               }
+
+               xE.u.u.type = ColormapNotify;
+               xE.u.colormap.window = pWin->drawable.id;
+               xE.u.colormap.colormap = cmap;
+               xE.u.colormap.new = xTrue;
+               xE.u.colormap.state = IsMapInstalled(cmap, pWin);
+               DeliverEvents(pWin, &xE, 1, NullWindow);
+           }
+           break;
+         case CWCursor:
+           cursorID = (Cursor ) *pVlist;
+           pVlist++;
+           /*
+            * install the new
+            */
+           if ( cursorID == None)
+           {
+               if (pWin == WindowTable[pWin->drawable.pScreen->myNum])
+                   pCursor = rootCursor;
+               else
+                   pCursor = (CursorPtr) None;
+           }
+           else
+           {
+               pCursor = (CursorPtr)SecurityLookupIDByType(client, cursorID,
+                                               RT_CURSOR, SecurityReadAccess);
+               if (!pCursor)
+               {
+                   error = BadCursor;
+                   client->errorValue = cursorID;
+                   goto PatchUp;
+               }
+           }
+
+           if (pCursor != wCursor (pWin))
+           {
+               /*
+                * patch up child windows so they don't lose cursors.
+                */
+
+               for (pChild = pWin->firstChild; pChild; pChild=pChild->nextSib)
+               {
+                   if (!pChild->optional && !pChild->cursorIsNone &&
+                       !MakeWindowOptional (pChild))
+                   {
+                       error = BadAlloc;
+                       goto PatchUp;
+                   }
+               }
+
+               pOldCursor = 0;
+               if (pCursor == (CursorPtr) None)
+               {
+                   pWin->cursorIsNone = TRUE;
+                   if (pWin->optional)
+                   {
+                       pOldCursor = pWin->optional->cursor;
+                       pWin->optional->cursor = (CursorPtr) None;
+                       checkOptional = TRUE;
+                   }
+               } else {
+                   if (!pWin->optional)
+                   {
+                       if (!MakeWindowOptional (pWin))
+                       {
+                           error = BadAlloc;
+                           goto PatchUp;
+                       }
+                   }
+                   else if (pWin->parent && pCursor == wCursor (pWin->parent))
+                       checkOptional = TRUE;
+                   pOldCursor = pWin->optional->cursor;
+                   pWin->optional->cursor = pCursor;
+                   pCursor->refcnt++;
+                   pWin->cursorIsNone = FALSE;
+                   /*
+                    * check on any children now matching the new cursor
+                    */
+
+                   for (pChild=pWin->firstChild; pChild; pChild=pChild->nextSib)
+                   {
+                       if (pChild->optional &&
+                           (pChild->optional->cursor == pCursor))
+                           CheckWindowOptionalNeed (pChild);
+                   }
+               }
+
+               if (pWin->realized)
+                   WindowHasNewCursor( pWin);
+
+               /* Can't free cursor until here - old cursor
+                * is needed in WindowHasNewCursor
+                */
+               if (pOldCursor)
+                   FreeCursor (pOldCursor, (Cursor)0);
+           }
+           break;
+        default:
+           error = BadValue;
+           client->errorValue = vmask;
+           goto PatchUp;
+      }
+      vmaskCopy |= index2;
+    }
+PatchUp:
+    if (checkOptional)
+       CheckWindowOptionalNeed (pWin);
+
+       /* We SHOULD check for an error value here XXX */
+    (*pScreen->ChangeWindowAttributes)(pWin, vmaskCopy);
+
+    /* 
+       If the border contents have changed, redraw the border. 
+       Note that this has to be done AFTER pScreen->ChangeWindowAttributes
+       for the tile to be rotated, and the correct function selected.
+    */
+    if (((vmaskCopy & (CWBorderPixel | CWBorderPixmap)) || borderRelative)
+       && pWin->viewable && HasBorder (pWin))
+    {
+       RegionRec exposed;
+
+       REGION_INIT(pScreen, &exposed, NullBox, 0);
+       REGION_SUBTRACT(pScreen, &exposed, &pWin->borderClip, &pWin->winSize);
+       (*pWin->drawable.pScreen->PaintWindowBorder)(pWin, &exposed, PW_BORDER);
+       REGION_UNINIT(pScreen, &exposed);
+    }
+    return error;
+}
+
+
+/*****
+ * GetWindowAttributes
+ *    Notice that this is different than ChangeWindowAttributes
+ *****/
+
+void
+GetWindowAttributes(pWin, client, wa)
+    register WindowPtr pWin;
+    ClientPtr client;
+    xGetWindowAttributesReply *wa;
+{
+    wa->type = X_Reply;
+    wa->bitGravity = pWin->bitGravity;
+    wa->winGravity = pWin->winGravity;
+    if (pWin->forcedBS && pWin->backingStore != Always)
+       wa->backingStore = NotUseful;
+    else
+       wa->backingStore = pWin->backingStore;
+    wa->length = (sizeof(xGetWindowAttributesReply) -
+                sizeof(xGenericReply)) >> 2;
+    wa->sequenceNumber = client->sequence;
+    wa->backingBitPlanes =  wBackingBitPlanes (pWin);
+    wa->backingPixel =  wBackingPixel (pWin);
+    wa->saveUnder = (BOOL)pWin->saveUnder;
+    wa->override = pWin->overrideRedirect;
+    if (!pWin->mapped)
+       wa->mapState = IsUnmapped;
+    else if (pWin->realized)
+       wa->mapState = IsViewable;
+    else
+       wa->mapState = IsUnviewable;
+
+    wa->colormap =  wColormap (pWin);
+    wa->mapInstalled = (wa->colormap == None) ? xFalse
+                               : IsMapInstalled(wa->colormap, pWin);
+
+    wa->yourEventMask = EventMaskForClient(pWin, client);
+    wa->allEventMasks = pWin->eventMask | wOtherEventMasks (pWin);
+    wa->doNotPropagateMask = wDontPropagateMask (pWin);
+    wa->class = pWin->drawable.class;
+    wa->visualID = wVisual (pWin);
+}
+
+
+WindowPtr
+MoveWindowInStack(pWin, pNextSib)
+    register WindowPtr pWin, pNextSib;
+{
+    register WindowPtr pParent = pWin->parent;
+    WindowPtr pFirstChange = pWin; /* highest window where list changes */
+
+    if (pWin->nextSib != pNextSib)
+    {
+       if (!pNextSib)        /* move to bottom */
+       {
+           if (pParent->firstChild == pWin)
+               pParent->firstChild = pWin->nextSib;
+           /* if (pWin->nextSib) */     /* is always True: pNextSib == NULL
+                                         * and pWin->nextSib != pNextSib
+                                         * therefore pWin->nextSib != NULL */
+           pFirstChange = pWin->nextSib;
+           pWin->nextSib->prevSib = pWin->prevSib;
+           if (pWin->prevSib)
+               pWin->prevSib->nextSib = pWin->nextSib;
+           pParent->lastChild->nextSib = pWin;
+           pWin->prevSib = pParent->lastChild;
+           pWin->nextSib = NullWindow;
+           pParent->lastChild = pWin;
+       }
+       else if (pParent->firstChild == pNextSib) /* move to top */
+       {
+           pFirstChange = pWin;
+           if (pParent->lastChild == pWin)
+              pParent->lastChild = pWin->prevSib;
+           if (pWin->nextSib)
+               pWin->nextSib->prevSib = pWin->prevSib;
+           if (pWin->prevSib)
+               pWin->prevSib->nextSib = pWin->nextSib;
+           pWin->nextSib = pParent->firstChild;
+           pWin->prevSib = (WindowPtr ) NULL;
+           pNextSib->prevSib = pWin;
+           pParent->firstChild = pWin;
+       }
+       else                    /* move in middle of list */
+       {
+           WindowPtr pOldNext = pWin->nextSib;
+
+           pFirstChange = NullWindow;
+           if (pParent->firstChild == pWin)
+               pFirstChange = pParent->firstChild = pWin->nextSib;
+           if (pParent->lastChild == pWin) {
+              pFirstChange = pWin;
+              pParent->lastChild = pWin->prevSib;
+           }
+           if (pWin->nextSib)
+               pWin->nextSib->prevSib = pWin->prevSib;
+           if (pWin->prevSib)
+               pWin->prevSib->nextSib = pWin->nextSib;
+           pWin->nextSib = pNextSib;
+           pWin->prevSib = pNextSib->prevSib;
+           if (pNextSib->prevSib)
+               pNextSib->prevSib->nextSib = pWin;
+           pNextSib->prevSib = pWin;
+           if (!pFirstChange) {                     /* do we know it yet? */
+               pFirstChange = pParent->firstChild;  /* no, search from top */
+               while ((pFirstChange != pWin) && (pFirstChange != pOldNext))
+                    pFirstChange = pFirstChange->nextSib;
+           }
+       }
+    }
+
+    return( pFirstChange );
+}
+
+RegionPtr
+CreateUnclippedWinSize (pWin)
+    register WindowPtr  pWin;
+{
+    RegionPtr  pRgn;
+    BoxRec     box;
+
+    box.x1 = pWin->drawable.x;
+    box.y1 = pWin->drawable.y;
+    box.x2 = pWin->drawable.x + (int) pWin->drawable.width;
+    box.y2 = pWin->drawable.y + (int) pWin->drawable.height;
+    pRgn = REGION_CREATE(pWin->drawable.pScreen, &box, 1);
+#ifdef SHAPE
+    if (wBoundingShape (pWin) || wClipShape (pWin)) {
+       REGION_PTR(pScreen, pWin)
+
+       REGION_TRANSLATE(pScreen, pRgn, - pWin->drawable.x,
+                        - pWin->drawable.y);
+       if (wBoundingShape (pWin))
+           REGION_INTERSECT(pScreen, pRgn, pRgn, wBoundingShape (pWin));
+       if (wClipShape (pWin))
+           REGION_INTERSECT(pScreen, pRgn, pRgn, wClipShape (pWin));
+       REGION_TRANSLATE(pScreen, pRgn, pWin->drawable.x, pWin->drawable.y);
+    }
+#endif
+    return pRgn;
+}
+
+void
+SetWinSize (pWin)
+    register WindowPtr pWin;
+{
+    ClippedRegionFromBox(pWin->parent, &pWin->winSize,
+                        pWin->drawable.x, pWin->drawable.y,
+                        (int)pWin->drawable.width,
+                        (int)pWin->drawable.height);
+#ifdef SHAPE
+    if (wBoundingShape (pWin) || wClipShape (pWin)) {
+       REGION_PTR(pScreen, pWin)
+
+       REGION_TRANSLATE(pScreen, &pWin->winSize, - pWin->drawable.x,
+                        - pWin->drawable.y);
+       if (wBoundingShape (pWin))
+           REGION_INTERSECT(pScreen, &pWin->winSize, &pWin->winSize,
+                            wBoundingShape (pWin));
+       if (wClipShape (pWin))
+           REGION_INTERSECT(pScreen, &pWin->winSize, &pWin->winSize,
+                            wClipShape (pWin));
+       REGION_TRANSLATE(pScreen, &pWin->winSize, pWin->drawable.x,
+                        pWin->drawable.y);
+    }
+#endif
+}
+
+void
+SetBorderSize (pWin)
+    register WindowPtr pWin;
+{
+    int        bw;
+
+    if (HasBorder (pWin)) {
+       bw = wBorderWidth (pWin);
+       ClippedRegionFromBox(pWin->parent, &pWin->borderSize,
+               pWin->drawable.x - bw, pWin->drawable.y - bw,
+               (int)(pWin->drawable.width + (bw<<1)),
+               (int)(pWin->drawable.height + (bw<<1)));
+#ifdef SHAPE
+       if (wBoundingShape (pWin)) {
+           REGION_PTR(pScreen, pWin)
+
+           REGION_TRANSLATE(pScreen, &pWin->borderSize, - pWin->drawable.x,
+                            - pWin->drawable.y);
+           REGION_INTERSECT(pScreen, &pWin->borderSize, &pWin->borderSize,
+                            wBoundingShape (pWin));
+           REGION_TRANSLATE(pScreen, &pWin->borderSize, pWin->drawable.x,
+                            pWin->drawable.y);
+           REGION_UNION(pScreen, &pWin->borderSize, &pWin->borderSize,
+                        &pWin->winSize);
+       }
+#endif
+    } else {
+       REGION_COPY(pWin->drawable.pScreen, &pWin->borderSize,
+                                              &pWin->winSize);
+    }
+}
+
+void
+GravityTranslate (x, y, oldx, oldy, dw, dh, gravity, destx, desty)
+    register int x, y;         /* new window position */
+    int                oldx, oldy;     /* old window position */
+    int                dw, dh;
+    unsigned   gravity;
+    register int *destx, *desty;       /* position relative to gravity */
+{
+    switch (gravity) {
+    case NorthGravity:
+       *destx = x + dw / 2;
+       *desty = y;
+       break;
+    case NorthEastGravity:
+       *destx = x + dw;
+       *desty = y;
+       break;
+    case WestGravity:
+       *destx = x;
+       *desty = y + dh / 2;
+       break;
+    case CenterGravity:
+       *destx = x + dw / 2;
+       *desty = y + dh / 2;
+       break;
+    case EastGravity:
+       *destx = x + dw;
+       *desty = y + dh / 2;
+       break;
+    case SouthWestGravity:
+       *destx = x;
+       *desty = y + dh;
+       break;
+    case SouthGravity:
+       *destx = x + dw / 2;
+       *desty = y + dh;
+       break;
+    case SouthEastGravity:
+       *destx = x + dw;
+       *desty = y + dh;
+       break;
+    case StaticGravity:
+       *destx = oldx;
+       *desty = oldy;
+       break;
+    default:
+       *destx = x;
+       *desty = y;
+       break;
+    }
+}
+
+/* XXX need to retile border on each window with ParentRelative origin */
+void
+ResizeChildrenWinSize(pWin, dx, dy, dw, dh)
+    register WindowPtr pWin;
+    int dx, dy, dw, dh;
+{
+    register ScreenPtr pScreen;
+    register WindowPtr pSib, pChild;
+    Bool resized = (dw || dh);
+
+    pScreen = pWin->drawable.pScreen;
+
+    for (pSib = pWin->firstChild; pSib; pSib = pSib->nextSib)
+    {
+       if (resized && (pSib->winGravity > NorthWestGravity))
+       {
+           int cwsx, cwsy;
+
+           cwsx = pSib->origin.x;
+           cwsy = pSib->origin.y;
+           GravityTranslate (cwsx, cwsy, cwsx - dx, cwsy - dy, dw, dh,
+                       pSib->winGravity, &cwsx, &cwsy);
+           if (cwsx != pSib->origin.x || cwsy != pSib->origin.y)
+           {
+               xEvent event;
+
+               event.u.u.type = GravityNotify;
+               event.u.gravity.window = pSib->drawable.id;
+               event.u.gravity.x = cwsx - wBorderWidth (pSib);
+               event.u.gravity.y = cwsy - wBorderWidth (pSib);
+               DeliverEvents (pSib, &event, 1, NullWindow);
+               pSib->origin.x = cwsx;
+               pSib->origin.y = cwsy;
+           }
+       }
+       pSib->drawable.x = pWin->drawable.x + pSib->origin.x;
+       pSib->drawable.y = pWin->drawable.y + pSib->origin.y;
+       SetWinSize (pSib);
+       SetBorderSize (pSib);
+       (*pScreen->PositionWindow)(pSib, pSib->drawable.x, pSib->drawable.y);
+       if ( (pChild = pSib->firstChild) )
+       {
+           while (1)
+           {
+               pChild->drawable.x = pChild->parent->drawable.x +
+                                    pChild->origin.x;
+               pChild->drawable.y = pChild->parent->drawable.y +
+                                    pChild->origin.y;
+               SetWinSize (pChild);
+               SetBorderSize (pChild);
+               (*pScreen->PositionWindow)(pChild,
+                                   pChild->drawable.x, pChild->drawable.y);
+               if (pChild->firstChild)
+               {
+                   pChild = pChild->firstChild;
+                   continue;
+               }
+               while (!pChild->nextSib && (pChild != pSib))
+                   pChild = pChild->parent;
+               if (pChild == pSib)
+                   break;
+               pChild = pChild->nextSib;
+           }
+       }
+    }
+}
+
+#define GET_INT16(m, f) \
+       if (m & mask) \
+         { \
+            f = (INT16) *pVlist;\
+           pVlist++; \
+        }
+#define GET_CARD16(m, f) \
+       if (m & mask) \
+        { \
+           f = (CARD16) *pVlist;\
+           pVlist++;\
+        }
+
+#define GET_CARD8(m, f) \
+       if (m & mask) \
+        { \
+           f = (CARD8) *pVlist;\
+           pVlist++;\
+        }
+
+#define ChangeMask ((Mask)(CWX | CWY | CWWidth | CWHeight))
+
+#define IllegalInputOnlyConfigureMask (CWBorderWidth)
+
+/*
+ * IsSiblingAboveMe
+ *     returns Above if pSib above pMe in stack or Below otherwise 
+ */
+
+static int
+#if NeedFunctionPrototypes
+IsSiblingAboveMe(
+    register WindowPtr pMe,
+    register WindowPtr pSib)
+#else
+IsSiblingAboveMe(pMe, pSib)
+    register WindowPtr pMe, pSib;
+#endif
+{
+    register WindowPtr pWin;
+
+    pWin = pMe->parent->firstChild;
+    while (pWin)
+    {
+       if (pWin == pSib)
+           return(Above);
+       else if (pWin == pMe)
+           return(Below);
+       pWin = pWin->nextSib;
+    }
+    return(Below);
+}
+
+static BoxPtr
+#if NeedFunctionPrototypes
+WindowExtents(
+    register WindowPtr pWin,
+    register BoxPtr pBox)
+#else
+WindowExtents(pWin, pBox)
+    register WindowPtr pWin;
+    register BoxPtr pBox;
+#endif
+{
+    pBox->x1 = pWin->drawable.x - wBorderWidth (pWin);
+    pBox->y1 = pWin->drawable.y - wBorderWidth (pWin);
+    pBox->x2 = pWin->drawable.x + (int)pWin->drawable.width
+              + wBorderWidth (pWin);
+    pBox->y2 = pWin->drawable.y + (int)pWin->drawable.height
+              + wBorderWidth (pWin);
+    return(pBox);
+}
+
+#ifdef SHAPE
+#define IS_SHAPED(pWin)        (wBoundingShape (pWin) != (RegionPtr) NULL)
+
+static RegionPtr
+#if NeedFunctionPrototypes
+MakeBoundingRegion (
+    register WindowPtr pWin,
+    BoxPtr     pBox)
+#else
+MakeBoundingRegion (pWin, pBox)
+    register WindowPtr pWin;
+    BoxPtr     pBox;
+#endif
+{
+    RegionPtr  pRgn;
+    REGION_PTR(pScreen, pWin)
+
+    pRgn = REGION_CREATE(pScreen, pBox, 1);
+    if (wBoundingShape (pWin)) {
+           REGION_TRANSLATE(pScreen, pRgn, -pWin->origin.x,
+                                                 -pWin->origin.y);
+           REGION_INTERSECT(pScreen, pRgn, pRgn, wBoundingShape (pWin));
+           REGION_TRANSLATE(pScreen, pRgn, pWin->origin.x,
+                                                 pWin->origin.y);
+    }
+    return pRgn;
+}
+
+static Bool
+#if NeedFunctionPrototypes
+ShapeOverlap (
+    WindowPtr  pWin,
+    BoxPtr     pWinBox,
+    WindowPtr  pSib,
+    BoxPtr     pSibBox)
+#else
+ShapeOverlap (pWin, pWinBox, pSib, pSibBox)
+    WindowPtr  pWin, pSib;
+    BoxPtr     pWinBox, pSibBox;
+#endif
+{
+    RegionPtr  pWinRgn, pSibRgn;
+    register ScreenPtr pScreen;
+    Bool       ret;
+
+    if (!IS_SHAPED(pWin) && !IS_SHAPED(pSib))
+       return TRUE;
+    pScreen = pWin->drawable.pScreen;
+    pWinRgn = MakeBoundingRegion (pWin, pWinBox);
+    pSibRgn = MakeBoundingRegion (pSib, pSibBox);
+    REGION_INTERSECT(pScreen, pWinRgn, pWinRgn, pSibRgn);
+    ret = REGION_NOTEMPTY(pScreen, pWinRgn);
+    REGION_DESTROY(pScreen, pWinRgn);
+    REGION_DESTROY(pScreen, pSibRgn);
+    return ret;
+}
+#endif
+
+static Bool
+#if NeedFunctionPrototypes
+AnyWindowOverlapsMe(
+    WindowPtr pWin,
+    WindowPtr pHead,
+    register BoxPtr box)
+#else
+AnyWindowOverlapsMe(pWin, pHead, box)
+    WindowPtr pWin, pHead;
+    register BoxPtr box;
+#endif
+{
+    register WindowPtr pSib;
+    BoxRec sboxrec;
+    register BoxPtr sbox;
+
+    for (pSib = pWin->prevSib; pSib != pHead; pSib = pSib->prevSib)
+    {
+       if (pSib->mapped)
+       {
+           sbox = WindowExtents(pSib, &sboxrec);
+           if (BOXES_OVERLAP(sbox, box)
+#ifdef SHAPE
+           && ShapeOverlap (pWin, box, pSib, sbox)
+#endif
+           )
+               return(TRUE);
+       }
+    }
+    return(FALSE);
+}
+
+static Bool
+#if NeedFunctionPrototypes
+IOverlapAnyWindow(
+    WindowPtr pWin,
+    register BoxPtr box)
+#else
+IOverlapAnyWindow(pWin, box)
+    WindowPtr pWin;
+    register BoxPtr box;
+#endif
+{
+    register WindowPtr pSib;
+    BoxRec sboxrec;
+    register BoxPtr sbox;
+
+    for (pSib = pWin->nextSib; pSib; pSib = pSib->nextSib)
+    {
+       if (pSib->mapped)
+       {
+           sbox = WindowExtents(pSib, &sboxrec);
+           if (BOXES_OVERLAP(sbox, box)
+#ifdef SHAPE
+           && ShapeOverlap (pWin, box, pSib, sbox)
+#endif
+           )
+               return(TRUE);
+       }
+    }
+    return(FALSE);
+}
+
+/*
+ *   WhereDoIGoInTheStack() 
+ *       Given pWin and pSib and the relationshipe smode, return
+ *       the window that pWin should go ABOVE.
+ *       If a pSib is specified:
+ *           Above:  pWin is placed just above pSib
+ *           Below:  pWin is placed just below pSib
+ *           TopIf:  if pSib occludes pWin, then pWin is placed
+ *                   at the top of the stack
+ *           BottomIf:  if pWin occludes pSib, then pWin is 
+ *                      placed at the bottom of the stack
+ *           Opposite: if pSib occludes pWin, then pWin is placed at the
+ *                     top of the stack, else if pWin occludes pSib, then
+ *                     pWin is placed at the bottom of the stack
+ *
+ *       If pSib is NULL:
+ *           Above:  pWin is placed at the top of the stack
+ *           Below:  pWin is placed at the bottom of the stack
+ *           TopIf:  if any sibling occludes pWin, then pWin is placed at
+ *                   the top of the stack
+ *           BottomIf: if pWin occludes any sibline, then pWin is placed at
+ *                     the bottom of the stack
+ *           Opposite: if any sibling occludes pWin, then pWin is placed at
+ *                     the top of the stack, else if pWin occludes any
+ *                     sibling, then pWin is placed at the bottom of the stack
+ *
+ */
+
+static WindowPtr
+#if NeedFunctionPrototypes
+WhereDoIGoInTheStack(
+    register WindowPtr pWin,
+    register WindowPtr pSib,
+    short x,
+    short y,
+    unsigned short w,
+    unsigned short h,
+    int smode)
+#else
+WhereDoIGoInTheStack(pWin, pSib, x, y, w, h, smode)
+    register WindowPtr pWin, pSib;
+    short x, y;
+    unsigned short w, h;
+    int smode;
+#endif
+{
+    BoxRec box;
+    register ScreenPtr pScreen;
+    WindowPtr pHead, pFirst;
+
+    if ((pWin == pWin->parent->firstChild) &&
+       (pWin == pWin->parent->lastChild))
+       return((WindowPtr ) NULL);
+    pHead = RealChildHead(pWin->parent);
+    pFirst = pHead ? pHead->nextSib : pWin->parent->firstChild;
+    pScreen = pWin->drawable.pScreen;
+    box.x1 = x;
+    box.y1 = y;
+    box.x2 = x + (int)w;
+    box.y2 = y + (int)h;
+    switch (smode)
+    {
+      case Above:
+       if (pSib)
+          return(pSib);
+       else if (pWin == pFirst)
+           return(pWin->nextSib);
+       else
+           return(pFirst);
+      case Below:
+       if (pSib)
+           if (pSib->nextSib != pWin)
+               return(pSib->nextSib);
+           else
+               return(pWin->nextSib);
+       else
+           return NullWindow;
+      case TopIf:
+       if ((!pWin->mapped || (pSib && !pSib->mapped)) && !permitOldBugs)
+           return(pWin->nextSib);
+       else if (pSib)
+       {
+           if ((IsSiblingAboveMe(pWin, pSib) == Above) &&
+               (RECT_IN_REGION(pScreen, &pSib->borderSize, &box) != rgnOUT))
+               return(pFirst);
+           else
+               return(pWin->nextSib);
+       }
+       else if (AnyWindowOverlapsMe(pWin, pHead, &box))
+           return(pFirst);
+       else
+           return(pWin->nextSib);
+      case BottomIf:
+       if ((!pWin->mapped || (pSib && !pSib->mapped)) && !permitOldBugs)
+           return(pWin->nextSib);
+       else if (pSib)
+       {
+           if ((IsSiblingAboveMe(pWin, pSib) == Below) &&
+               (RECT_IN_REGION(pScreen, &pSib->borderSize, &box) != rgnOUT))
+               return NullWindow;
+           else
+               return(pWin->nextSib);
+       }
+       else if (IOverlapAnyWindow(pWin, &box))
+           return NullWindow;
+       else
+           return(pWin->nextSib);
+      case Opposite:
+       if ((!pWin->mapped || (pSib && !pSib->mapped)) && !permitOldBugs)
+           return(pWin->nextSib);
+       else if (pSib)
+       {
+           if (RECT_IN_REGION(pScreen, &pSib->borderSize, &box) != rgnOUT)
+           {
+               if (IsSiblingAboveMe(pWin, pSib) == Above)
+                   return(pFirst);
+               else
+                   return NullWindow;
+           }
+           else
+               return(pWin->nextSib);
+       }
+       else if (AnyWindowOverlapsMe(pWin, pHead, &box))
+       {
+           /* If I'm occluded, I can't possibly be the first child
+            * if (pWin == pWin->parent->firstChild)
+            *    return pWin->nextSib;
+            */
+           return(pFirst);
+       }
+       else if (IOverlapAnyWindow(pWin, &box))
+           return NullWindow;
+       else
+           return pWin->nextSib;
+      default:
+      {
+       ErrorF("Internal error in ConfigureWindow, smode == %d\n",smode );
+       return pWin->nextSib;
+      }
+    }
+}
+
+static void
+#if NeedFunctionPrototypes
+ReflectStackChange(
+    register WindowPtr pWin,
+    register WindowPtr pSib,
+    VTKind  kind)
+#else
+ReflectStackChange(pWin, pSib, kind)
+    register WindowPtr pWin, pSib;
+    VTKind  kind;
+#endif
+{
+/* Note that pSib might be NULL */
+
+    Bool WasViewable = (Bool)pWin->viewable;
+    WindowPtr pParent;
+    Bool anyMarked;
+    WindowPtr pFirstChange;
+#ifdef DO_SAVE_UNDERS
+    Bool       dosave = FALSE;
+#endif
+    WindowPtr  pLayerWin;
+    ScreenPtr pScreen = pWin->drawable.pScreen;
+
+    /* if this is a root window, can't be restacked */
+    if (!(pParent = pWin->parent))
+       return ;
+
+    pFirstChange = MoveWindowInStack(pWin, pSib);
+
+    if (WasViewable)
+    {
+       anyMarked = (*pScreen->MarkOverlappedWindows)(pWin, pFirstChange,
+                                                     &pLayerWin);
+       if (pLayerWin != pWin) pFirstChange = pLayerWin;
+#ifdef DO_SAVE_UNDERS
+       if (DO_SAVE_UNDERS(pWin))
+       {
+           dosave = (*pScreen->ChangeSaveUnder)(pLayerWin, pFirstChange);
+       }
+#endif /* DO_SAVE_UNDERS */
+       if (anyMarked)
+       {
+           (*pScreen->ValidateTree)(pLayerWin->parent, pFirstChange, kind);
+           (*pScreen->HandleExposures)(pLayerWin->parent);
+       }
+#ifdef DO_SAVE_UNDERS
+       if (dosave)
+           (*pScreen->PostChangeSaveUnder)(pLayerWin, pFirstChange);
+#endif /* DO_SAVE_UNDERS */
+       if (anyMarked && pWin->drawable.pScreen->PostValidateTree)
+           (*pScreen->PostValidateTree)(pLayerWin->parent, pFirstChange, kind);
+    }
+    if (pWin->realized)
+       WindowsRestructured ();
+}
+
+/*****
+ * ConfigureWindow
+ *****/
+
+int
+ConfigureWindow(pWin, mask, vlist, client)
+    register WindowPtr pWin;
+    register Mask mask;
+    XID *vlist;
+    ClientPtr client;
+{
+#define RESTACK_WIN    0
+#define MOVE_WIN       1
+#define RESIZE_WIN     2
+#define REBORDER_WIN   3
+    register WindowPtr pSib = NullWindow;
+    register WindowPtr pParent = pWin->parent;
+    Window sibwid;
+    Mask index2, tmask;
+    register XID *pVlist;
+    short x,   y, beforeX, beforeY;
+    unsigned short w = pWin->drawable.width,
+                  h = pWin->drawable.height,
+                  bw = pWin->borderWidth;
+    int action, smode = Above;
+#ifdef XAPPGROUP
+    ClientPtr win_owner;
+    ClientPtr ag_leader = NULL;
+#endif
+    xEvent event;
+
+    if ((pWin->drawable.class == InputOnly) && (mask & IllegalInputOnlyConfigureMask))
+       return(BadMatch);
+
+    if ((mask & CWSibling) && !(mask & CWStackMode))
+       return(BadMatch);
+
+    pVlist = vlist;
+
+    if (pParent)
+    {
+       x = pWin->drawable.x - pParent->drawable.x - (int)bw;
+       y = pWin->drawable.y - pParent->drawable.y - (int)bw;
+    }
+    else
+    {
+       x = pWin->drawable.x;
+       y = pWin->drawable.y;
+    }
+    beforeX = x;
+    beforeY = y;
+    action = RESTACK_WIN;      
+    if ((mask & (CWX | CWY)) && (!(mask & (CWHeight | CWWidth))))
+    {
+       GET_INT16(CWX, x);
+       GET_INT16(CWY, y);
+       action = MOVE_WIN;
+    }
+       /* or should be resized */
+    else if (mask & (CWX |  CWY | CWWidth | CWHeight))
+    {
+       GET_INT16(CWX, x);
+       GET_INT16(CWY, y);
+       GET_CARD16(CWWidth, w);
+       GET_CARD16 (CWHeight, h);
+       if (!w || !h)
+       {
+           client->errorValue = 0;
+           return BadValue;
+       }
+       action = RESIZE_WIN;
+    }
+    tmask = mask & ~ChangeMask;
+    while (tmask)
+    {
+       index2 = (Mask)lowbit (tmask);
+       tmask &= ~index2;
+       switch (index2)
+       {
+         case CWBorderWidth:
+           GET_CARD16(CWBorderWidth, bw);
+           break;
+         case CWSibling:
+           sibwid = (Window ) *pVlist;
+           pVlist++;
+           pSib = (WindowPtr )SecurityLookupIDByType(client, sibwid,
+                                               RT_WINDOW, SecurityReadAccess);
+           if (!pSib)
+           {
+               client->errorValue = sibwid;
+               return(BadWindow);
+           }
+           if (pSib->parent != pParent)
+               return(BadMatch);
+           if (pSib == pWin)
+               return(BadMatch);
+           break;
+         case CWStackMode:
+           GET_CARD8(CWStackMode, smode);
+           if ((smode != TopIf) && (smode != BottomIf) &&
+               (smode != Opposite) && (smode != Above) && (smode != Below))
+           {
+               client->errorValue = smode;
+               return(BadValue);
+           }
+           break;
+         default:
+           client->errorValue = mask;
+           return(BadValue);
+       }
+    }
+       /* root really can't be reconfigured, so just return */
+    if (!pParent)
+       return Success;
+
+       /* Figure out if the window should be moved.  Doesnt
+          make the changes to the window if event sent */
+
+    if (mask & CWStackMode)
+       pSib = WhereDoIGoInTheStack(pWin, pSib, pParent->drawable.x + x,
+                                   pParent->drawable.y + y,
+                                   w + (bw << 1), h + (bw << 1), smode);
+    else
+       pSib = pWin->nextSib;
+
+#ifdef XAPPGROUP
+    win_owner = clients[CLIENT_ID(pWin->drawable.id)];
+    ag_leader = XagLeader (win_owner);
+#endif
+
+    if ((!pWin->overrideRedirect) && 
+       (RedirectSend(pParent)
+#ifdef XAPPGROUP
+       || (win_owner->appgroup && ag_leader && 
+           XagIsControlledRoot (client, pParent))
+#endif
+       ))
+    {
+       event.u.u.type = ConfigureRequest;
+       event.u.configureRequest.window = pWin->drawable.id;
+       if (mask & CWSibling)
+          event.u.configureRequest.sibling = sibwid;
+       else
+           event.u.configureRequest.sibling = None;
+       if (mask & CWStackMode)
+          event.u.u.detail = smode;
+       else
+           event.u.u.detail = Above;
+       event.u.configureRequest.x = x;
+       event.u.configureRequest.y = y;
+       event.u.configureRequest.width = w;
+       event.u.configureRequest.height = h;
+       event.u.configureRequest.borderWidth = bw;
+       event.u.configureRequest.valueMask = mask;
+#ifdef XAPPGROUP
+       /* make sure if the ag_leader maps the window it goes to the wm */
+       if (ag_leader && ag_leader != client && 
+           XagIsControlledRoot (client, pParent)) {
+           event.u.configureRequest.parent = XagId (win_owner);
+           (void) TryClientEvents (ag_leader, &event, 1,
+                                   NoEventMask, NoEventMask, NullGrab);
+           return Success;
+       }
+#endif
+       event.u.configureRequest.parent = pParent->drawable.id;
+       if (MaybeDeliverEventsToClient(pParent, &event, 1,
+               SubstructureRedirectMask, client) == 1)
+           return(Success);
+    }
+    if (action == RESIZE_WIN)
+    {
+       Bool size_change = (w != pWin->drawable.width)
+                       || (h != pWin->drawable.height);
+       if (size_change && ((pWin->eventMask|wOtherEventMasks(pWin)) & ResizeRedirectMask))
+       {
+           xEvent eventT;
+           eventT.u.u.type = ResizeRequest;
+           eventT.u.resizeRequest.window = pWin->drawable.id;
+           eventT.u.resizeRequest.width = w;
+           eventT.u.resizeRequest.height = h;
+           if (MaybeDeliverEventsToClient(pWin, &eventT, 1,
+                                      ResizeRedirectMask, client) == 1)
+           {
+               /* if event is delivered, leave the actual size alone. */
+               w = pWin->drawable.width;
+               h = pWin->drawable.height;
+               size_change = FALSE;
+           }
+       }
+       if (!size_change)
+       {
+           if (mask & (CWX | CWY))
+               action = MOVE_WIN;
+           else if (mask & (CWStackMode | CWBorderWidth))
+               action = RESTACK_WIN;
+           else   /* really nothing to do */
+               return(Success) ;
+       }
+    }
+
+    if (action == RESIZE_WIN)
+           /* we've already checked whether there's really a size change */
+           goto ActuallyDoSomething;
+    if ((mask & CWX) && (x != beforeX))
+           goto ActuallyDoSomething;
+    if ((mask & CWY) && (y != beforeY))
+           goto ActuallyDoSomething;
+    if ((mask & CWBorderWidth) && (bw != wBorderWidth (pWin)))
+           goto ActuallyDoSomething;
+    if (mask & CWStackMode)
+    {
+       if (pWin->nextSib != pSib)
+           goto ActuallyDoSomething;
+    }
+    return(Success);
+
+ActuallyDoSomething:
+    if (SubStrSend(pWin, pParent))
+    {
+       event.u.u.type = ConfigureNotify;
+       event.u.configureNotify.window = pWin->drawable.id;
+       if (pSib)
+           event.u.configureNotify.aboveSibling = pSib->drawable.id;
+       else
+           event.u.configureNotify.aboveSibling = None;
+       event.u.configureNotify.x = x;
+       event.u.configureNotify.y = y;
+       event.u.configureNotify.width = w;
+       event.u.configureNotify.height = h;
+       event.u.configureNotify.borderWidth = bw;
+       event.u.configureNotify.override = pWin->overrideRedirect;
+       DeliverEvents(pWin, &event, 1, NullWindow);
+    }
+    if (mask & CWBorderWidth)
+    {
+       if (action == RESTACK_WIN)
+       {
+           action = MOVE_WIN;
+           pWin->borderWidth = bw;
+       }
+       else if ((action == MOVE_WIN) &&
+                (beforeX + wBorderWidth (pWin) == x + (int)bw) &&
+                (beforeY + wBorderWidth (pWin) == y + (int)bw))
+       {
+           action = REBORDER_WIN;
+           (*pWin->drawable.pScreen->ChangeBorderWidth)(pWin, bw);
+       }
+       else
+           pWin->borderWidth = bw;
+    }
+    if (action == MOVE_WIN)
+       (*pWin->drawable.pScreen->MoveWindow)(pWin, x, y, pSib,
+                  (mask & CWBorderWidth) ? VTOther : VTMove);
+    else if (action == RESIZE_WIN)
+       (*pWin->drawable.pScreen->ResizeWindow)(pWin, x, y, w, h, pSib);
+    else if (mask & CWStackMode)
+       ReflectStackChange(pWin, pSib, VTOther);
+
+    if (action != RESTACK_WIN)
+       CheckCursorConfinement(pWin);
+
+    return(Success);
+#undef RESTACK_WIN
+#undef MOVE_WIN
+#undef RESIZE_WIN
+#undef REBORDER_WIN
+}
+
+
+/******
+ *
+ * CirculateWindow
+ *    For RaiseLowest, raises the lowest mapped child (if any) that is
+ *    obscured by another child to the top of the stack.  For LowerHighest,
+ *    lowers the highest mapped child (if any) that is obscuring another
+ *    child to the bottom of the stack.         Exposure processing is performed 
+ *
+ ******/
+
+int
+CirculateWindow(pParent, direction, client)
+    WindowPtr pParent;
+    int direction;
+    ClientPtr client;
+{
+    register WindowPtr pWin, pHead, pFirst;
+    xEvent event;
+    BoxRec box;
+
+    pHead = RealChildHead(pParent);
+    pFirst = pHead ? pHead->nextSib : pParent->firstChild;
+    if (direction == RaiseLowest)
+    {
+       for (pWin = pParent->lastChild;
+            (pWin != pHead) &&
+            !(pWin->mapped &&
+              AnyWindowOverlapsMe(pWin, pHead, WindowExtents(pWin, &box)));
+            pWin = pWin->prevSib) ;
+       if (pWin == pHead)
+           return Success;
+    }
+    else
+    {
+       for (pWin = pFirst;
+            pWin &&
+            !(pWin->mapped &&
+              IOverlapAnyWindow(pWin, WindowExtents(pWin, &box)));
+            pWin = pWin->nextSib) ;
+       if (!pWin)
+           return Success;
+    }
+
+    event.u.circulate.window = pWin->drawable.id;
+    event.u.circulate.parent = pParent->drawable.id;
+    event.u.circulate.event = pParent->drawable.id;
+    if (direction == RaiseLowest)
+       event.u.circulate.place = PlaceOnTop;
+    else
+       event.u.circulate.place = PlaceOnBottom;
+
+    if (RedirectSend(pParent))
+    {
+       event.u.u.type = CirculateRequest;
+       if (MaybeDeliverEventsToClient(pParent, &event, 1,
+               SubstructureRedirectMask, client) == 1)
+           return(Success);
+    }
+
+    event.u.u.type = CirculateNotify;
+    DeliverEvents(pWin, &event, 1, NullWindow);
+    ReflectStackChange(pWin,
+                      (direction == RaiseLowest) ? pFirst : NullWindow,
+                      VTStack);
+
+    return(Success);
+}
+
+static int
+#if NeedFunctionPrototypes
+CompareWIDs(
+    WindowPtr pWin,
+    pointer   value) /* must conform to VisitWindowProcPtr */
+#else
+CompareWIDs(pWin, value)
+    WindowPtr pWin;
+    pointer   value; /* must conform to VisitWindowProcPtr */
+#endif
+{
+    Window *wid = (Window *)value;
+
+    if (pWin->drawable.id == *wid)
+       return(WT_STOPWALKING);
+    else
+       return(WT_WALKCHILDREN);
+}
+
+/*****
+ *  ReparentWindow
+ *****/
+
+int
+ReparentWindow(pWin, pParent, x, y, client)
+    register WindowPtr pWin, pParent;
+    int x,y;
+    ClientPtr client;
+{
+    WindowPtr pPrev, pPriorParent;
+    Bool WasMapped = (Bool)(pWin->mapped);
+    xEvent event;
+    int bw = wBorderWidth (pWin);
+    register ScreenPtr pScreen;
+
+    pScreen = pWin->drawable.pScreen;
+    if (TraverseTree(pWin, CompareWIDs, (pointer)&pParent->drawable.id) == WT_STOPWALKING)
+       return(BadMatch);               
+    if (!MakeWindowOptional(pWin))
+       return(BadAlloc);
+
+    if (WasMapped)
+       UnmapWindow(pWin, FALSE);
+
+    event.u.u.type = ReparentNotify;
+    event.u.reparent.window = pWin->drawable.id;
+    event.u.reparent.parent = pParent->drawable.id;
+    event.u.reparent.x = x;
+    event.u.reparent.y = y;
+    event.u.reparent.override = pWin->overrideRedirect;
+    DeliverEvents(pWin, &event, 1, pParent);
+
+    /* take out of sibling chain */
+
+    pPriorParent = pPrev = pWin->parent;
+    if (pPrev->firstChild == pWin)
+       pPrev->firstChild = pWin->nextSib;
+    if (pPrev->lastChild == pWin)
+       pPrev->lastChild = pWin->prevSib;
+
+    if (pWin->nextSib)
+       pWin->nextSib->prevSib = pWin->prevSib;
+    if (pWin->prevSib)
+       pWin->prevSib->nextSib = pWin->nextSib;
+
+    /* insert at begining of pParent */
+    pWin->parent = pParent;
+    pPrev = RealChildHead(pParent);
+    if (pPrev)
+    {
+       pWin->nextSib = pPrev->nextSib;
+       if (pPrev->nextSib)
+           pPrev->nextSib->prevSib = pWin;
+       else
+           pParent->lastChild = pWin;
+       pPrev->nextSib = pWin;
+       pWin->prevSib = pPrev;
+    }
+    else
+    {
+       pWin->nextSib = pParent->firstChild;
+       pWin->prevSib = NullWindow;
+       if (pParent->firstChild)
+           pParent->firstChild->prevSib = pWin;
+       else
+           pParent->lastChild = pWin;
+       pParent->firstChild = pWin;
+    }
+
+    pWin->origin.x = x + bw;
+    pWin->origin.y = y + bw;
+    pWin->drawable.x = x + bw + pParent->drawable.x;
+    pWin->drawable.y = y + bw + pParent->drawable.y;
+
+    /* clip to parent */
+    SetWinSize (pWin);
+    SetBorderSize (pWin);
+
+    if (pScreen->ReparentWindow)
+       (*pScreen->ReparentWindow)(pWin, pPriorParent);
+    (*pScreen->PositionWindow)(pWin, pWin->drawable.x, pWin->drawable.y);
+    ResizeChildrenWinSize(pWin, 0, 0, 0, 0);
+
+    CheckWindowOptionalNeed(pWin);
+
+    if (WasMapped)
+       MapWindow(pWin, client);
+    RecalculateDeliverableEvents(pWin);
+    return(Success);
+}
+
+static void
+#if NeedFunctionPrototypes
+RealizeTree(WindowPtr pWin)
+#else
+RealizeTree(pWin)
+    WindowPtr pWin;
+#endif
+{
+    register WindowPtr pChild;
+    RealizeWindowProcPtr Realize;
+
+    Realize = pWin->drawable.pScreen->RealizeWindow;
+    pChild = pWin;
+    while (1)
+    {
+       if (pChild->mapped)
+       {
+           pChild->realized = TRUE;
+#ifdef DO_SAVE_UNDERS
+           if (pChild->saveUnder)
+               deltaSaveUndersViewable++;
+#endif
+           pChild->viewable = (pChild->drawable.class == InputOutput);
+           (* Realize)(pChild);
+           if (pChild->firstChild)
+           {
+               pChild = pChild->firstChild;
+               continue;
+           }
+       }
+       while (!pChild->nextSib && (pChild != pWin))
+           pChild = pChild->parent;
+       if (pChild == pWin)
+           return;
+       pChild = pChild->nextSib;
+    }
+}
+
+/*****
+ * MapWindow
+ *    If some other client has selected SubStructureReDirect on the parent
+ *    and override-redirect is xFalse, then a MapRequest event is generated,
+ *    but the window remains unmapped. Otherwise, the window is mapped and a
+ *    MapNotify event is generated.
+ *****/
+
+int
+MapWindow(pWin, client)
+    register WindowPtr pWin;
+    ClientPtr client;
+{
+    register ScreenPtr pScreen;
+
+    register WindowPtr pParent;
+#ifdef DO_SAVE_UNDERS
+    Bool       dosave = FALSE;
+#endif
+    WindowPtr  pLayerWin;
+
+    if (pWin->mapped)
+       return(Success);
+
+#ifdef XCSECURITY
+    /*  don't let an untrusted client map a child-of-trusted-window, InputOnly
+     *  window; too easy to steal device input
+     */
+    if ( (client->trustLevel != XSecurityClientTrusted) &&
+        (pWin->drawable.class == InputOnly) &&
+        (wClient(pWin->parent)->trustLevel == XSecurityClientTrusted) )
+        return Success;
+#endif 
+
+    pScreen = pWin->drawable.pScreen;
+    if ( (pParent = pWin->parent) )
+    {
+       xEvent event;
+       Bool anyMarked;
+#ifdef XAPPGROUP
+       ClientPtr win_owner = clients[CLIENT_ID(pWin->drawable.id)];
+       ClientPtr ag_leader = XagLeader (win_owner);
+#endif
+
+       if ((!pWin->overrideRedirect) && 
+           (RedirectSend(pParent)
+#ifdef XAPPGROUP
+           || (win_owner->appgroup && ag_leader &&
+               XagIsControlledRoot (client, pParent))
+#endif
+       ))
+       {
+           event.u.u.type = MapRequest;
+           event.u.mapRequest.window = pWin->drawable.id;
+#ifdef XAPPGROUP
+           /* make sure if the ag_leader maps the window it goes to the wm */
+           if (ag_leader && ag_leader != client &&
+               XagIsControlledRoot (client, pParent)) {
+               event.u.mapRequest.parent = XagId (win_owner);
+               (void) TryClientEvents (ag_leader, &event, 1,
+                                       NoEventMask, NoEventMask, NullGrab);
+               return Success;
+           }
+#endif
+           event.u.mapRequest.parent = pParent->drawable.id;
+
+           if (MaybeDeliverEventsToClient(pParent, &event, 1,
+               SubstructureRedirectMask, client) == 1)
+               return(Success);
+       }
+
+       pWin->mapped = TRUE;
+       if (SubStrSend(pWin, pParent))
+       {
+           event.u.u.type = MapNotify;
+           event.u.mapNotify.window = pWin->drawable.id;
+           event.u.mapNotify.override = pWin->overrideRedirect;
+           DeliverEvents(pWin, &event, 1, NullWindow);
+       }
+
+       if (!pParent->realized)
+           return(Success);
+       RealizeTree(pWin);
+       if (pWin->viewable)
+       {
+           anyMarked = (*pScreen->MarkOverlappedWindows)(pWin, pWin,
+                                                         &pLayerWin);
+#ifdef DO_SAVE_UNDERS
+           if (DO_SAVE_UNDERS(pWin))
+           {
+               dosave = (*pScreen->ChangeSaveUnder)(pLayerWin, pWin->nextSib);
+           }
+#endif /* DO_SAVE_UNDERS */
+           if (anyMarked)
+           {
+               (*pScreen->ValidateTree)(pLayerWin->parent, pLayerWin, VTMap);
+               (*pScreen->HandleExposures)(pLayerWin->parent);
+           }
+#ifdef DO_SAVE_UNDERS
+           if (dosave)
+               (*pScreen->PostChangeSaveUnder)(pLayerWin, pWin->nextSib);
+#endif /* DO_SAVE_UNDERS */
+       if (anyMarked && pScreen->PostValidateTree)
+           (*pScreen->PostValidateTree)(pLayerWin->parent, pLayerWin, VTMap);
+       }
+       WindowsRestructured ();
+    }
+    else
+    {
+       RegionRec   temp;
+
+       pWin->mapped = TRUE;
+       pWin->realized = TRUE;     /* for roots */
+       pWin->viewable = pWin->drawable.class == InputOutput;
+       /* We SHOULD check for an error value here XXX */
+       (*pScreen->RealizeWindow)(pWin);
+       if (pScreen->ClipNotify)
+           (*pScreen->ClipNotify) (pWin, 0, 0);
+       if (pScreen->PostValidateTree)
+           (*pScreen->PostValidateTree)(NullWindow, pWin, VTMap);
+       REGION_INIT(pScreen, &temp, NullBox, 0);
+       REGION_COPY(pScreen, &temp, &pWin->clipList);
+       (*pScreen->WindowExposures) (pWin, &temp, NullRegion);
+       REGION_UNINIT(pScreen, &temp);
+    }
+
+    return(Success);
+}
+
+
+/*****
+ * MapSubwindows
+ *    Performs a MapWindow all unmapped children of the window, in top
+ *    to bottom stacking order.
+ *****/
+
+void
+MapSubwindows(pParent, client)
+    register WindowPtr pParent;
+    ClientPtr client;
+{
+    register WindowPtr pWin;
+    WindowPtr          pFirstMapped = NullWindow;
+#ifdef DO_SAVE_UNDERS
+    WindowPtr          pFirstSaveUndered = NullWindow;
+#endif
+    register ScreenPtr pScreen;
+    register Mask      parentRedirect;
+    register Mask      parentNotify;
+    xEvent             event;
+    Bool               anyMarked;
+#ifdef DO_SAVE_UNDERS
+    Bool       dosave = FALSE;
+#endif
+    WindowPtr          pLayerWin;
+
+    pScreen = pParent->drawable.pScreen;
+    parentRedirect = RedirectSend(pParent);
+    parentNotify = SubSend(pParent);
+    anyMarked = FALSE;
+    for (pWin = pParent->firstChild; pWin; pWin = pWin->nextSib)
+    {
+       if (!pWin->mapped)
+       {
+           if (parentRedirect && !pWin->overrideRedirect)
+           {
+               event.u.u.type = MapRequest;
+               event.u.mapRequest.window = pWin->drawable.id;
+               event.u.mapRequest.parent = pParent->drawable.id;
+    
+               if (MaybeDeliverEventsToClient(pParent, &event, 1,
+                   SubstructureRedirectMask, client) == 1)
+                   continue;
+           }
+    
+           pWin->mapped = TRUE;
+           if (parentNotify || StrSend(pWin))
+           {
+               event.u.u.type = MapNotify;
+               event.u.mapNotify.window = pWin->drawable.id;
+               event.u.mapNotify.override = pWin->overrideRedirect;
+               DeliverEvents(pWin, &event, 1, NullWindow);
+           }
+    
+           if (!pFirstMapped)
+               pFirstMapped = pWin;
+           if (pParent->realized)
+           {
+               RealizeTree(pWin);
+               if (pWin->viewable)
+               {
+                   anyMarked |= (*pScreen->MarkOverlappedWindows)(pWin, pWin,
+                                                       (WindowPtr *)NULL);
+#ifdef DO_SAVE_UNDERS
+                   if (DO_SAVE_UNDERS(pWin))
+                   {
+                       dosave = TRUE;
+                   }
+#endif /* DO_SAVE_UNDERS */
+               }
+           }
+       }
+    }
+
+    if (pFirstMapped)
+    {
+       pLayerWin = (*pScreen->GetLayerWindow)(pParent);
+       if (pLayerWin->parent != pParent) {
+           anyMarked |= (*pScreen->MarkOverlappedWindows)(pLayerWin,
+                                                          pLayerWin,
+                                                          (WindowPtr *)NULL);
+           pFirstMapped = pLayerWin;
+       }
+        if (anyMarked)
+        {
+#ifdef DO_SAVE_UNDERS
+           if (pLayerWin->parent != pParent)
+           {
+               if (dosave || (DO_SAVE_UNDERS(pLayerWin)))
+               {
+                   dosave = (*pScreen->ChangeSaveUnder)(pLayerWin,
+                                                        pLayerWin);
+               }
+           }
+           else if (dosave)
+           {
+               dosave = FALSE;
+               for (pWin = pParent->firstChild; pWin; pWin = pWin->nextSib)
+               {
+                   if (DO_SAVE_UNDERS(pWin))
+                   {
+                       dosave |= (*pScreen->ChangeSaveUnder)(pWin,
+                                                             pWin->nextSib);
+                       if (dosave && !pFirstSaveUndered)
+                           pFirstSaveUndered = pWin;
+                   }
+               }
+            }
+#endif /* DO_SAVE_UNDERS */
+           (*pScreen->ValidateTree)(pLayerWin->parent, pFirstMapped, VTMap);
+           (*pScreen->HandleExposures)(pLayerWin->parent);
+       }
+#ifdef DO_SAVE_UNDERS
+        if (dosave)
+           (*pScreen->PostChangeSaveUnder)(pLayerWin,
+                                           pFirstSaveUndered->nextSib);
+#endif /* DO_SAVE_UNDERS */
+        if (anyMarked && pScreen->PostValidateTree)
+           (*pScreen->PostValidateTree)(pLayerWin->parent, pFirstMapped,
+                                        VTMap);
+        WindowsRestructured ();
+    }
+}
+
+static void
+#if NeedFunctionPrototypes
+UnrealizeTree(
+    WindowPtr pWin,
+    Bool fromConfigure)
+#else
+UnrealizeTree(pWin, fromConfigure)
+    WindowPtr pWin;
+    Bool fromConfigure;
+#endif
+{
+    register WindowPtr pChild;
+    UnrealizeWindowProcPtr Unrealize;
+    MarkUnrealizedWindowProcPtr MarkUnrealizedWindow;
+
+    Unrealize = pWin->drawable.pScreen->UnrealizeWindow;
+    MarkUnrealizedWindow = pWin->drawable.pScreen->MarkUnrealizedWindow;
+    pChild = pWin;
+    while (1)
+    {
+       if (pChild->realized)
+       {
+           pChild->realized = FALSE;
+           pChild->visibility = VisibilityNotViewable;
+           (* Unrealize)(pChild);
+           DeleteWindowFromAnyEvents(pChild, FALSE);
+           if (pChild->viewable)
+           {
+#ifdef DO_SAVE_UNDERS
+               if (pChild->saveUnder)
+                   deltaSaveUndersViewable--;
+#endif
+               pChild->viewable = FALSE;
+               if (pChild->backStorage)
+                   (*pChild->drawable.pScreen->SaveDoomedAreas)(
+                                           pChild, &pChild->clipList, 0, 0);
+               (* MarkUnrealizedWindow)(pChild, pWin, fromConfigure);
+               pChild->drawable.serialNumber = NEXT_SERIAL_NUMBER;
+           }
+           if (pChild->firstChild)
+           {
+               pChild = pChild->firstChild;
+               continue;
+           }
+       }
+       while (!pChild->nextSib && (pChild != pWin))
+           pChild = pChild->parent;
+       if (pChild == pWin)
+           return;
+       pChild = pChild->nextSib;
+    }
+}
+
+/*****
+ * UnmapWindow
+ *    If the window is already unmapped, this request has no effect.
+ *    Otherwise, the window is unmapped and an UnMapNotify event is
+ *    generated.  Cannot unmap a root window.
+ *****/
+
+int
+UnmapWindow(pWin, fromConfigure)
+    register WindowPtr pWin;
+    Bool fromConfigure;
+{
+    register WindowPtr pParent;
+    xEvent event;
+    Bool wasRealized = (Bool)pWin->realized;
+    Bool wasViewable = (Bool)pWin->viewable;
+    ScreenPtr pScreen = pWin->drawable.pScreen;
+    WindowPtr pLayerWin = pWin;
+
+    if ((!pWin->mapped) || (!(pParent = pWin->parent)))
+       return(Success);
+    if (SubStrSend(pWin, pParent))
+    {
+       event.u.u.type = UnmapNotify;
+       event.u.unmapNotify.window = pWin->drawable.id;
+       event.u.unmapNotify.fromConfigure = fromConfigure;
+       DeliverEvents(pWin, &event, 1, NullWindow);
+    }
+    if (wasViewable && !fromConfigure)
+    {
+       pWin->valdata = UnmapValData;
+       (*pScreen->MarkOverlappedWindows)(pWin, pWin->nextSib, &pLayerWin);
+       (*pScreen->MarkWindow)(pLayerWin->parent);
+    }
+    pWin->mapped = FALSE;
+    if (wasRealized)
+       UnrealizeTree(pWin, fromConfigure);
+    if (wasViewable)
+    {
+       if (!fromConfigure)
+       {
+           (*pScreen->ValidateTree)(pLayerWin->parent, pWin, VTUnmap);
+           (*pScreen->HandleExposures)(pLayerWin->parent);
+       }
+#ifdef DO_SAVE_UNDERS
+       if (DO_SAVE_UNDERS(pWin))
+       {
+           if ( (*pScreen->ChangeSaveUnder)(pLayerWin, pWin->nextSib) )
+           {
+               (*pScreen->PostChangeSaveUnder)(pLayerWin, pWin->nextSib);
+           }
+       }
+       pWin->DIXsaveUnder = FALSE;
+#endif /* DO_SAVE_UNDERS */
+       if (!fromConfigure && pScreen->PostValidateTree)
+           (*pScreen->PostValidateTree)(pLayerWin->parent, pWin, VTUnmap);
+    }
+    if (wasRealized && !fromConfigure)
+       WindowsRestructured ();
+    return(Success);
+}
+
+/*****
+ * UnmapSubwindows
+ *    Performs an UnmapWindow request with the specified mode on all mapped
+ *    children of the window, in bottom to top stacking order.
+ *****/
+
+void
+UnmapSubwindows(pWin)
+    register WindowPtr pWin;
+{
+    register WindowPtr pChild, pHead;
+    xEvent event;
+    Bool wasRealized = (Bool)pWin->realized;
+    Bool wasViewable = (Bool)pWin->viewable;
+    Bool anyMarked = FALSE;
+    Mask parentNotify;
+    WindowPtr pLayerWin;
+    ScreenPtr pScreen = pWin->drawable.pScreen;
+
+    if (!pWin->firstChild)
+       return;
+    parentNotify = SubSend(pWin);
+    pHead = RealChildHead(pWin);
+
+    if (wasViewable)
+       pLayerWin = (*pScreen->GetLayerWindow)(pWin);
+
+    for (pChild = pWin->lastChild; pChild != pHead; pChild = pChild->prevSib)
+    {
+       if (pChild->mapped)
+       {
+           if (parentNotify || StrSend(pChild))
+           {
+               event.u.u.type = UnmapNotify;
+               event.u.unmapNotify.window = pChild->drawable.id;
+               event.u.unmapNotify.fromConfigure = xFalse;
+               DeliverEvents(pChild, &event, 1, NullWindow);
+           }
+           if (pChild->viewable)
+           {
+               pChild->valdata = UnmapValData;
+               anyMarked = TRUE;
+           }
+           pChild->mapped = FALSE;
+           if (pChild->realized)
+               UnrealizeTree(pChild, FALSE);
+           if (wasViewable)
+           {
+#ifdef DO_SAVE_UNDERS
+               pChild->DIXsaveUnder = FALSE;
+#endif /* DO_SAVE_UNDERS */
+               if (pChild->backStorage)
+                   (*pScreen->SaveDoomedAreas)(
+                                           pChild, &pChild->clipList, 0, 0);
+           }
+       }
+    }
+    if (wasViewable)
+    {
+       if (anyMarked)
+       {
+           if (pLayerWin->parent == pWin)
+               (*pScreen->MarkWindow)(pWin);
+           else
+           {
+               WindowPtr ptmp;
+                (*pScreen->MarkOverlappedWindows)(pWin, pLayerWin,
+                                                 (WindowPtr *)NULL);
+               (*pScreen->MarkWindow)(pLayerWin->parent);
+               
+               /* Windows between pWin and pLayerWin may not have been marked */
+               ptmp = pWin;
+               while (ptmp != pLayerWin->parent)
+               {
+                   (*pScreen->MarkWindow)(ptmp);
+                   ptmp = ptmp->parent;
+               }
+                pHead = pWin->firstChild;
+           }
+           (*pScreen->ValidateTree)(pLayerWin->parent, pHead, VTUnmap);
+           (*pScreen->HandleExposures)(pLayerWin->parent);
+       }
+#ifdef DO_SAVE_UNDERS
+       if (DO_SAVE_UNDERS(pWin))
+       {
+           if ( (*pScreen->ChangeSaveUnder)(pLayerWin, pLayerWin))
+               (*pScreen->PostChangeSaveUnder)(pLayerWin, pLayerWin);
+       }
+#endif /* DO_SAVE_UNDERS */
+       if (anyMarked && pScreen->PostValidateTree)
+           (*pScreen->PostValidateTree)(pLayerWin->parent, pHead, VTUnmap);
+    }
+    if (wasRealized)
+       WindowsRestructured ();
+}
+
+
+void
+HandleSaveSet(client)
+    register ClientPtr client;
+{
+    register WindowPtr pParent, pWin;
+    register int j;
+
+    for (j=0; j<client->numSaved; j++)
+    {
+       pWin = (WindowPtr)client->saveSet[j];
+       pParent = pWin->parent;
+       while (pParent && (wClient (pParent) == client))
+           pParent = pParent->parent;
+       if (pParent)
+       {
+           if (pParent != pWin->parent)
+           {
+               ReparentWindow(pWin, pParent,
+                              pWin->drawable.x - wBorderWidth (pWin) - pParent->drawable.x,
+                              pWin->drawable.y - wBorderWidth (pWin) - pParent->drawable.y,
+                              client);
+               if(!pWin->realized && pWin->mapped)
+                   pWin->mapped = FALSE;
+           }
+           MapWindow(pWin, client);
+       }
+    }
+    xfree(client->saveSet);
+    client->numSaved = 0;
+    client->saveSet = (pointer *)NULL;
+}
+
+Bool
+VisibleBoundingBoxFromPoint(pWin, x, y, box)
+    register WindowPtr pWin;
+    int x, y;  /* in root */
+    BoxPtr box;          /* "return" value */
+{
+    if (!pWin->realized)
+       return (FALSE);
+    if (POINT_IN_REGION(pWin->drawable.pScreen, &pWin->clipList, x, y, box))
+       return(TRUE);
+    return(FALSE);
+}
+
+Bool
+PointInWindowIsVisible(pWin, x, y)
+    register WindowPtr pWin;
+    int x, y;  /* in root */
+{
+    BoxRec box;
+
+    if (!pWin->realized)
+       return (FALSE);
+    if (POINT_IN_REGION(pWin->drawable.pScreen, &pWin->borderClip,
+                                                 x, y, &box))
+       return(TRUE);
+    return(FALSE);
+}
+
+
+RegionPtr
+NotClippedByChildren(pWin)
+    register WindowPtr pWin;
+{
+    register ScreenPtr pScreen;
+    RegionPtr pReg;
+
+    pScreen = pWin->drawable.pScreen;
+    pReg = REGION_CREATE(pScreen, NullBox, 1);
+    if (pWin->parent ||
+       screenIsSaved != SCREEN_SAVER_ON ||
+       !HasSaverWindow (pWin->drawable.pScreen->myNum))
+    {
+       REGION_INTERSECT(pScreen, pReg, &pWin->borderClip, &pWin->winSize);
+    }
+    return(pReg);
+}
+
+
+void
+SendVisibilityNotify(pWin)
+    WindowPtr pWin;
+{
+    xEvent event;
+    event.u.u.type = VisibilityNotify;
+    event.u.visibility.window = pWin->drawable.id;
+    event.u.visibility.state = pWin->visibility;
+    DeliverEvents(pWin, &event, 1, NullWindow);
+}
+
+
+#define RANDOM_WIDTH 32
+
+#ifndef NOLOGOHACK
+extern int logoScreenSaver;
+static void DrawLogo(
+#if NeedFunctionPrototypes
+    WindowPtr /*pWin*/
+#endif
+);
+#endif
+
+void
+SaveScreens(on, mode)
+    int on;
+    int mode;
+{
+    int i;
+    int what;
+    int type;
+
+    if (on == SCREEN_SAVER_FORCER)
+    {
+       UpdateCurrentTimeIf();
+       lastDeviceEventTime = currentTime;
+       if (mode == ScreenSaverReset)
+           what = SCREEN_SAVER_OFF;
+       else
+           what = SCREEN_SAVER_ON;
+       type = what;
+    }
+    else
+    {
+       what = on;
+       type = what;
+       if (what == screenIsSaved)
+           type = SCREEN_SAVER_CYCLE;
+    }
+    for (i = 0; i < screenInfo.numScreens; i++)
+    {
+       if (on == SCREEN_SAVER_FORCER)
+          (* screenInfo.screens[i]->SaveScreen) (screenInfo.screens[i], on);
+       if (savedScreenInfo[i].ExternalScreenSaver)
+       {
+           if ((*savedScreenInfo[i].ExternalScreenSaver)
+               (screenInfo.screens[i], type, on == SCREEN_SAVER_FORCER))
+               continue;
+       }
+       if (type == screenIsSaved)
+           continue;
+       switch (type) {
+       case SCREEN_SAVER_OFF:
+           if (savedScreenInfo[i].blanked == SCREEN_IS_BLANKED)
+           {
+              (* screenInfo.screens[i]->SaveScreen) (screenInfo.screens[i],
+                                                     what);
+           }
+           else if (HasSaverWindow (i))
+           {
+               savedScreenInfo[i].pWindow = NullWindow;
+               FreeResource(savedScreenInfo[i].wid, RT_NONE);
+           }
+           break;
+       case SCREEN_SAVER_CYCLE:
+           if (savedScreenInfo[i].blanked == SCREEN_IS_TILED)
+           {
+               WindowPtr pWin = savedScreenInfo[i].pWindow;
+               /* make it look like screen saver is off, so that
+                * NotClippedByChildren will compute a clip list
+                * for the root window, so miPaintWindow works
+                */
+               screenIsSaved = SCREEN_SAVER_OFF;
+#ifndef NOLOGOHACK
+               if (logoScreenSaver)
+                   (*pWin->drawable.pScreen->ClearToBackground)(pWin, 0, 0, 0, 0, FALSE);
+#endif
+               (*pWin->drawable.pScreen->MoveWindow)(pWin,
+                          (short)(-(rand() % RANDOM_WIDTH)),
+                          (short)(-(rand() % RANDOM_WIDTH)),
+                          pWin->nextSib, VTMove);
+#ifndef NOLOGOHACK
+               if (logoScreenSaver)
+                   DrawLogo(pWin);
+#endif
+               screenIsSaved = SCREEN_SAVER_ON;
+           }
+           break;
+       case SCREEN_SAVER_ON:
+           if (ScreenSaverBlanking != DontPreferBlanking)
+           {
+               if ((* screenInfo.screens[i]->SaveScreen)
+                  (screenInfo.screens[i], what))
+               {
+                  savedScreenInfo[i].blanked = SCREEN_IS_BLANKED;
+                  continue;
+               }
+               if ((ScreenSaverAllowExposures != DontAllowExposures) &&
+                   TileScreenSaver(i, SCREEN_IS_BLACK))
+               {
+                   savedScreenInfo[i].blanked = SCREEN_IS_BLACK;
+                   continue;
+               }
+           }
+           if ((ScreenSaverAllowExposures != DontAllowExposures) &&
+               TileScreenSaver(i, SCREEN_IS_TILED))
+           {
+               savedScreenInfo[i].blanked = SCREEN_IS_TILED;
+           }
+           else
+               savedScreenInfo[i].blanked = SCREEN_ISNT_SAVED;
+           break;
+       }
+    }
+    screenIsSaved = what;
+}
+
+static Bool
+#if NeedFunctionPrototypes
+TileScreenSaver(int i, int kind)
+#else
+TileScreenSaver(i, kind)
+    int i;
+    int        kind;
+#endif
+{
+    int j;
+    int result;
+    XID attributes[3];
+    Mask mask;
+    WindowPtr pWin;            
+    CursorMetricRec cm;
+    unsigned char *srcbits, *mskbits;
+    CursorPtr cursor;
+    XID            cursorID;
+    int        attri;
+
+    mask = 0;
+    attri = 0;
+    switch (kind) {
+    case SCREEN_IS_TILED:
+       switch (WindowTable[i]->backgroundState) {
+       case BackgroundPixel:
+           attributes[attri++] = WindowTable[i]->background.pixel;
+           mask |= CWBackPixel;
+           break;
+       case BackgroundPixmap:
+           attributes[attri++] = None;
+           mask |= CWBackPixmap;
+           break;
+       default:
+           break;
+       }
+       break;
+    case SCREEN_IS_BLACK:
+       attributes[attri++] = WindowTable[i]->drawable.pScreen->blackPixel;
+       mask |= CWBackPixel;
+       break;
+    }
+    mask |= CWOverrideRedirect;
+    attributes[attri++] = xTrue;
+
+    /*
+     * create a blank cursor
+     */
+
+    cm.width=16;
+    cm.height=16;
+    cm.xhot=8;
+    cm.yhot=8;
+    srcbits = (unsigned char *)xalloc( BitmapBytePad(32)*16);
+    mskbits = (unsigned char *)xalloc( BitmapBytePad(32)*16);
+    if (!srcbits || !mskbits)
+    {
+       xfree(srcbits);
+       xfree(mskbits);
+       cursor = 0;
+    }
+    else
+    {
+       for (j=0; j<BitmapBytePad(32)*16; j++)
+           srcbits[j] = mskbits[j] = 0x0;
+       cursor = AllocCursor(srcbits, mskbits, &cm, 0, 0, 0, 0, 0, 0);
+       if (cursor)
+       {
+           cursorID = FakeClientID(0);
+           if (AddResource (cursorID, RT_CURSOR, (pointer) cursor))
+           {
+               attributes[attri] = cursorID;
+               mask |= CWCursor;
+           }
+           else
+               cursor = 0;
+       }
+       else
+       {
+           xfree (srcbits);
+           xfree (mskbits);
+       }
+    }
+
+    pWin = savedScreenInfo[i].pWindow =
+        CreateWindow(savedScreenInfo[i].wid,
+             WindowTable[i],
+             -RANDOM_WIDTH, -RANDOM_WIDTH,
+             (unsigned short)screenInfo.screens[i]->width + RANDOM_WIDTH,
+             (unsigned short)screenInfo.screens[i]->height + RANDOM_WIDTH,
+             0, InputOutput, mask, attributes, 0, serverClient,
+             wVisual (WindowTable[i]), &result);
+
+    if (cursor)
+       FreeResource (cursorID, RT_NONE);
+
+    if (!pWin)
+       return FALSE;
+
+    if (!AddResource(pWin->drawable.id, RT_WINDOW,
+                    (pointer)savedScreenInfo[i].pWindow))
+       return FALSE;
+
+    if (mask & CWBackPixmap)
+    {
+       MakeRootTile (pWin);
+       (*pWin->drawable.pScreen->ChangeWindowAttributes)(pWin, CWBackPixmap);
+    }
+    MapWindow(pWin, serverClient);
+#ifndef NOLOGOHACK
+    if (kind == SCREEN_IS_TILED && logoScreenSaver)
+       DrawLogo(pWin);
+#endif
+    return TRUE;
+}
+
+/*
+ * FindWindowWithOptional
+ *
+ * search ancestors of the given window for an entry containing
+ * a WindowOpt structure.  Assumptions:         some parent will
+ * contain the structure.
+ */
+
+WindowPtr
+FindWindowWithOptional (w)
+    register WindowPtr w;
+{
+    do
+       w = w->parent;
+    while (!w->optional);
+    return w;
+}
+
+/*
+ * CheckWindowOptionalNeed
+ *
+ * check each optional entry in the given window to see if
+ * the value is satisfied by the default rules.         If so,
+ * release the optional record
+ */
+
+void
+CheckWindowOptionalNeed (w)
+    register WindowPtr w;
+{
+    register WindowOptPtr optional;
+    register WindowOptPtr parentOptional;
+
+    if (!w->parent)
+       return;
+    optional = w->optional;
+    if (optional->dontPropagateMask != DontPropagateMasks[w->dontPropagate])
+       return;
+    if (optional->otherEventMasks != 0)
+       return;
+    if (optional->otherClients != NULL)
+       return;
+    if (optional->passiveGrabs != NULL)
+       return;
+    if (optional->userProps != NULL)
+       return;
+    if (optional->backingBitPlanes != ~0L)
+       return;
+    if (optional->backingPixel != 0)
+       return;
+#ifdef SHAPE
+    if (optional->boundingShape != NULL)
+       return;
+    if (optional->clipShape != NULL)
+       return;
+#endif
+#ifdef XINPUT
+    if (optional->inputMasks != NULL)
+       return;
+#endif
+    parentOptional = FindWindowWithOptional(w)->optional;
+    if (optional->visual != parentOptional->visual)
+       return;
+    if (optional->cursor != None &&
+       (optional->cursor != parentOptional->cursor ||
+        w->parent->cursorIsNone))
+       return;
+    if (optional->colormap != parentOptional->colormap)
+       return;
+    DisposeWindowOptional (w);
+}
+
+/*
+ * MakeWindowOptional
+ *
+ * create an optional record and initialize it with the default
+ * values.
+ */
+
+Bool
+MakeWindowOptional (pWin)
+    register WindowPtr pWin;
+{
+    register WindowOptPtr optional;
+    register WindowOptPtr parentOptional;
+
+    if (pWin->optional)
+       return TRUE;
+    optional = (WindowOptPtr) xalloc (sizeof (WindowOptRec));
+    if (!optional)
+       return FALSE;
+    optional->dontPropagateMask = DontPropagateMasks[pWin->dontPropagate];
+    optional->otherEventMasks = 0;
+    optional->otherClients = NULL;
+    optional->passiveGrabs = NULL;
+    optional->userProps = NULL;
+    optional->backingBitPlanes = ~0L;
+    optional->backingPixel = 0;
+#ifdef SHAPE
+    optional->boundingShape = NULL;
+    optional->clipShape = NULL;
+#endif
+#ifdef XINPUT
+    optional->inputMasks = NULL;
+#endif
+    parentOptional = FindWindowWithOptional(pWin)->optional;
+    optional->visual = parentOptional->visual;
+    if (!pWin->cursorIsNone)
+    {
+       optional->cursor = parentOptional->cursor;
+       optional->cursor->refcnt++;
+    }
+    else
+    {
+       optional->cursor = None;
+    }
+    optional->colormap = parentOptional->colormap;
+    pWin->optional = optional;
+    return TRUE;
+}
+
+void
+DisposeWindowOptional (pWin)
+    register WindowPtr pWin;
+{
+    if (!pWin->optional)
+       return;
+    /*
+     * everything is peachy.  Delete the optional record
+     * and clean up
+     */
+    if (pWin->optional->cursor)
+    {
+       FreeCursor (pWin->optional->cursor, (Cursor)0);
+       pWin->cursorIsNone = FALSE;
+    }
+    else
+       pWin->cursorIsNone = TRUE;
+    xfree (pWin->optional);
+    pWin->optional = NULL;
+}
+
+#ifndef NOLOGOHACK
+static void
+#if NeedFunctionPrototypes
+DrawLogo(WindowPtr pWin)
+#else
+DrawLogo(pWin)
+    WindowPtr pWin;
+#endif
+{
+    DrawablePtr pDraw;
+    ScreenPtr pScreen;
+    int x, y;
+    unsigned int width, height, size;
+    GC *pGC;
+    int thin, gap, d31;
+    DDXPointRec poly[4];
+    ChangeGCVal fore[2], back[2];
+    xrgb rgb[2];
+    BITS32 fmask, bmask;
+    ColormapPtr cmap;
+
+    pDraw = (DrawablePtr)pWin;
+    pScreen = pDraw->pScreen;
+    x = -pWin->origin.x;
+    y = -pWin->origin.y;
+    width = pScreen->width;
+    height = pScreen->height;
+    pGC = GetScratchGC(pScreen->rootDepth, pScreen);
+    if (!pGC)
+       return;
+
+    if ((rand() % 100) <= 17) /* make the probability for white fairly low */
+       fore[0].val = pScreen->whitePixel;
+    else
+       fore[0].val = pScreen->blackPixel;
+    if ((pWin->backgroundState == BackgroundPixel) &&
+       (cmap = (ColormapPtr)LookupIDByType(wColormap (pWin), RT_COLORMAP))) {
+       Pixel querypixels[2];
+
+       querypixels[0] = fore[0].val;
+       querypixels[1] = pWin->background.pixel;
+       QueryColors(cmap, 2, querypixels, rgb);
+       if ((rgb[0].red == rgb[1].red) &&
+           (rgb[0].green == rgb[1].green) &&
+           (rgb[0].blue == rgb[1].blue)) {
+           if (fore[0].val == pScreen->blackPixel)
+               fore[0].val = pScreen->whitePixel;
+           else
+               fore[0].val = pScreen->blackPixel;
+       }
+    }
+    fore[1].val = FillSolid;
+    fmask = GCForeground|GCFillStyle;
+    if (pWin->backgroundState == BackgroundPixel) {
+       back[0].val = pWin->background.pixel;
+       back[1].val = FillSolid;
+       bmask = GCForeground|GCFillStyle;
+    } else {
+       back[0].val = 0;
+       back[1].val = 0;
+       dixChangeGC(NullClient, pGC, GCTileStipXOrigin|GCTileStipYOrigin,
+                   NULL, back);
+       back[0].val = FillTiled;
+       back[1].ptr = pWin->background.pixmap;
+       bmask = GCFillStyle|GCTile;
+    }
+
+    /* should be the same as the reference function XmuDrawLogo() */
+
+    size = width;
+    if (height < width)
+        size = height;
+    size = RANDOM_WIDTH + rand() % (size - RANDOM_WIDTH);
+    size &= ~1;
+    x += rand() % (width - size);
+    y += rand() % (height - size);
+
+/*
+ * Draw what will be the thin strokes.
+ *
+ *           -----
+ *          /    /
+ *         /    /
+ *        /    /
+ *       /    /
+ *      /____/
+ *           d
+ *
+ * Point d is 9/44 (~1/5) of the way across.
+ */
+
+    thin = (size / 11);
+    if (thin < 1) thin = 1;
+    gap = (thin+3) / 4;
+    d31 = thin + thin + gap;
+    poly[0].x = x + size;             poly[0].y = y;
+    poly[1].x = x + size-d31;         poly[1].y = y;
+    poly[2].x = x + 0;                poly[2].y = y + size;
+    poly[3].x = x + d31;              poly[3].y = y + size;
+    dixChangeGC(NullClient, pGC, fmask, NULL, fore);
+    ValidateGC(pDraw, pGC);
+    (*pGC->ops->FillPolygon)(pDraw, pGC, Convex, CoordModeOrigin, 4, poly);
+
+/*
+ * Erase area not needed for lower thin stroke.
+ *
+ *           ------
+ *          /    /
+ *         /  __ /
+ *        /  / /
+ *       /  /  /
+ *      /__/__/
+ */
+
+    poly[0].x = x + d31/2;                      poly[0].y = y + size;
+    poly[1].x = x + size / 2;                   poly[1].y = y + size/2;
+    poly[2].x = x + (size/2)+(d31-(d31/2));     poly[2].y = y + size/2;
+    poly[3].x = x + d31;                        poly[3].y = y + size;
+    dixChangeGC(NullClient, pGC, bmask, NULL, back);
+    ValidateGC(pDraw, pGC);
+    (*pGC->ops->FillPolygon)(pDraw, pGC, Convex, CoordModeOrigin, 4, poly);
+
+/*
+ * Erase area not needed for upper thin stroke.
+ *
+ *          ------
+ *         /  /  /
+ *        /--/  /
+ *       /     /
+ *      /     /
+ *     /_____/
+ */
+
+    poly[0].x = x + size - d31/2;               poly[0].y = y;
+    poly[1].x = x + size / 2;                   poly[1].y = y + size/2;
+    poly[2].x = x + (size/2)-(d31-(d31/2));     poly[2].y = y + size/2;
+    poly[3].x = x + size - d31;                         poly[3].y = y;
+    ValidateGC(pDraw, pGC);
+    (*pGC->ops->FillPolygon)(pDraw, pGC, Convex, CoordModeOrigin, 4, poly);
+
+/*
+ * Draw thick stroke.
+ * Point b is 1/4 of the way across.
+ *
+ *      b
+ * -----
+ * \   \
+ *  \   \
+ *   \   \
+ *    \           \
+ *     \____\
+ */
+
+    poly[0].x = x;                    poly[0].y = y;
+    poly[1].x = x + size/4;           poly[1].y = y;
+    poly[2].x = x + size;             poly[2].y = y + size;
+    poly[3].x = x + size - size/4;     poly[3].y = y + size;
+    dixChangeGC(NullClient, pGC, fmask, NULL, fore);
+    ValidateGC(pDraw, pGC);
+    (*pGC->ops->FillPolygon)(pDraw, pGC, Convex, CoordModeOrigin, 4, poly);
+
+/*
+ * Erase to create gap.
+ *
+ *         /
+ *        /
+ *       /
+ *      /
+ *     /
+ */
+
+    poly[0].x = x + size- thin;              poly[0].y = y;
+    poly[1].x = x + size-( thin+gap);  poly[1].y = y;
+    poly[2].x = x + thin;            poly[2].y = y + size;
+    poly[3].x = x + thin + gap;              poly[3].y = y + size;
+    dixChangeGC(NullClient, pGC, bmask, NULL, back);
+    ValidateGC(pDraw, pGC);
+    (*pGC->ops->FillPolygon)(pDraw, pGC, Convex, CoordModeOrigin, 4, poly);
+
+    FreeScratchGC(pGC);
+}
+
+#endif
diff --git a/Xserver/programs/Xserver/dix/xpstubs.c b/Xserver/programs/Xserver/dix/xpstubs.c
new file mode 100644 (file)
index 0000000..6ef6747
--- /dev/null
@@ -0,0 +1,47 @@
+/*
+Copyright (c) 1996  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be included
+in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR
+OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall
+not be used in advertising or otherwise to promote the sale, use or
+other dealings in this Software without prior written authorization
+from the X Consortium.
+*/
+
+/* $XConsortium: xpstubs.c /main/1 1996/09/28 17:12:15 rws $ */
+
+#include "misc.h"
+#include "font.h"
+
+Bool
+XpClientIsBitmapClient(client)
+    ClientPtr client;
+{
+    return TRUE;
+}
+
+Bool
+XpClientIsPrintClient(client, fpe)
+    ClientPtr client;
+    FontPathElementPtr fpe;
+{
+    return FALSE;
+}
diff --git a/Xserver/programs/Xserver/hw/vnc/Imakefile b/Xserver/programs/Xserver/hw/vnc/Imakefile
new file mode 100644 (file)
index 0000000..9ab79d8
--- /dev/null
@@ -0,0 +1,28 @@
+XCOMM $XConsortium: Imakefile,v 1.5 94/01/21 22:04:27 dpw Exp $
+#include <Server.tmpl>
+
+SRCS = init.c sockets.c kbdptr.c cmap.c draw.c cutpaste.c \
+       dispcur.c sprite.c rfbserver.c translate.c httpd.c auth.c \
+       rre.c corre.c stats.c hextile.c zrle.cc
+
+OBJS = init.o sockets.o kbdptr.o cmap.o draw.o cutpaste.o \
+       dispcur.o sprite.o rfbserver.o translate.o httpd.o auth.o \
+       rre.o corre.o stats.o hextile.o zrle.o
+
+#include <vnclibs.def>
+INCLUDES = -I. -I$(XBUILDINCDIR) -I$(FONTINCSRC) -I$(XINCLUDESRC) \
+          -I../../cfb -I../../mfb -I../../mi -I../../include -I../../os \
+          $(VNCCPPFLAGS)
+
+DEFINES = ServerOSDefines
+
+all:: $(OBJS)
+
+NormalLibraryObjectRule()
+NormalLibraryTarget(vnc,$(OBJS) buildtime.o)
+SpecialCObjectRule(init,$(ICONFIGFILES),-DXVNCRELEASE=\"XvncRelease\")
+SpecialCplusplusObjectRule(zrle,zrle,$(ALLDEFINES))
+
+DependTarget()
+
+buildtime.o: $(OBJS)
diff --git a/Xserver/programs/Xserver/hw/vnc/README b/Xserver/programs/Xserver/hw/vnc/README
new file mode 100644 (file)
index 0000000..0f824ac
--- /dev/null
@@ -0,0 +1,4 @@
+
+This is the directory containing the code specific to the VNC X server.  Note
+that within this directory the name RFB is still used instead of VNC.
+
diff --git a/Xserver/programs/Xserver/hw/vnc/auth.c b/Xserver/programs/Xserver/hw/vnc/auth.c
new file mode 100644 (file)
index 0000000..e9a7977
--- /dev/null
@@ -0,0 +1,193 @@
+/*
+ * auth.c - deal with authentication.
+ *
+ * This file implements the VNC authentication protocol when setting up an RFB
+ * connection.
+ */
+
+/*
+ *  Copyright (C) 2002 RealVNC Ltd.
+ *  Copyright (C) 1999 AT&T Laboratories Cambridge.  All Rights Reserved.
+ *
+ *  This is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This software is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this software; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,
+ *  USA.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include "windowstr.h"
+#include "rfb.h"
+
+
+#define MAX_AUTH_TRIES 5
+#define AUTH_TOO_MANY_BASE_DELAY 10 * 1000 /* in ms, doubles for each failure
+                                             over MAX_AUTH_TRIES */
+
+static int rfbAuthFailure();
+static CARD32 rfbAuthReenable(OsTimerPtr timer, CARD32 now, pointer arg);
+
+char *rfbAuthPasswdFile = NULL;
+int rfbAuthTries = 0;
+Bool rfbAuthTooManyTries = FALSE;
+static OsTimerPtr timer = NULL;
+
+
+/*
+ * rfbAuthNewClient is called when we reach the point of authenticating
+ * a new client.  If authentication isn't being used then we simply send
+ * rfbNoAuth.  Otherwise we send rfbVncAuth plus the challenge.
+ */
+
+void
+rfbAuthNewClient(cl)
+    rfbClientPtr cl;
+{
+    char buf[4 + CHALLENGESIZE];
+    int len;
+
+    cl->state = RFB_AUTHENTICATION;
+
+    if (rfbAuthPasswdFile && !cl->reverseConnection) {
+
+       if (rfbAuthTooManyTries) {
+           rfbClientConnFailed(cl, "Too many authentication failures");
+           return;
+       }
+
+       *(CARD32 *)buf = Swap32IfLE(rfbVncAuth);
+       vncRandomBytes(cl->authChallenge);
+       memcpy(&buf[4], (char *)cl->authChallenge, CHALLENGESIZE);
+       len = 4 + CHALLENGESIZE;
+
+    } else {
+
+       *(CARD32 *)buf = Swap32IfLE(rfbNoAuth);
+       len = 4;
+       cl->state = RFB_INITIALISATION;
+    }
+
+    if (WriteExact(cl->sock, buf, len) < 0) {
+       rfbLogPerror("rfbAuthNewClient: write");
+       rfbCloseSock(cl->sock);
+       return;
+    }
+}
+
+
+/*
+ * rfbAuthProcessClientMessage is called when the client sends its
+ * authentication response.
+ */
+
+void
+rfbAuthProcessClientMessage(cl)
+    rfbClientPtr cl;
+{
+    char *passwd;
+    int i, n;
+    CARD8 response[CHALLENGESIZE];
+    CARD32 authResult;
+
+    n = ReadExact(cl->sock, (char *)response, CHALLENGESIZE);
+
+    if (n <= 0) {
+       if (n == 0)
+            rfbLog("rfbAuthProcessClientMessage: read failed\n");
+        else
+           rfbLogPerror("rfbAuthProcessClientMessage: read");
+        rfbAuthFailure();
+       rfbCloseSock(cl->sock);
+       return;
+    }
+
+    passwd = vncDecryptPasswdFromFile(rfbAuthPasswdFile);
+
+    if (passwd == NULL) {
+       rfbLog("rfbAuthProcessClientMessage: could not get password from %s\n",
+              rfbAuthPasswdFile);
+
+       authResult = Swap32IfLE(rfbVncAuthFailed);
+
+       if (WriteExact(cl->sock, (char *)&authResult, 4) < 0) {
+           rfbLogPerror("rfbAuthProcessClientMessage: write");
+       }
+       rfbCloseSock(cl->sock);
+       return;
+    }
+
+    vncEncryptBytes(cl->authChallenge, passwd);
+
+    /* Lose the password from memory */
+    for (i = strlen(passwd); i >= 0; i--) {
+       passwd[i] = '\0';
+    }
+
+    free((char *)passwd);
+
+    if (memcmp(cl->authChallenge, response, CHALLENGESIZE) != 0) {
+       rfbLog("rfbAuthProcessClientMessage: authentication failed from %s\n",
+              cl->host);
+
+        authResult = rfbAuthFailure();
+        authResult = Swap32IfLE(authResult);
+
+       if (WriteExact(cl->sock, (char *)&authResult, 4) < 0) {
+           rfbLogPerror("rfbAuthProcessClientMessage: write");
+       }
+       rfbCloseSock(cl->sock);
+       return;
+    }
+
+    rfbAuthTries = 0;
+
+    authResult = Swap32IfLE(rfbVncAuthOK);
+
+    if (WriteExact(cl->sock, (char *)&authResult, 4) < 0) {
+       rfbLogPerror("rfbAuthProcessClientMessage: write");
+       rfbCloseSock(cl->sock);
+       return;
+    }
+
+    cl->state = RFB_INITIALISATION;
+}
+
+
+static int rfbAuthFailure()
+{
+  int i;
+
+  rfbAuthTries++;
+
+  if (rfbAuthTries >= MAX_AUTH_TRIES) {
+
+    CARD32 delay = AUTH_TOO_MANY_BASE_DELAY;
+    for (i = MAX_AUTH_TRIES; i < rfbAuthTries; i++)
+      delay *= 2;
+    timer = TimerSet(timer, 0, delay, rfbAuthReenable, NULL);
+
+    rfbAuthTooManyTries = TRUE;
+    return rfbVncAuthTooMany;
+  }
+
+  return rfbVncAuthFailed;
+}
+
+
+static CARD32
+rfbAuthReenable(OsTimerPtr timer, CARD32 now, pointer arg)
+{
+    rfbAuthTooManyTries = FALSE;
+    return 0;
+}
diff --git a/Xserver/programs/Xserver/hw/vnc/buildtime.c b/Xserver/programs/Xserver/hw/vnc/buildtime.c
new file mode 100644 (file)
index 0000000..feece51
--- /dev/null
@@ -0,0 +1 @@
+char buildtime[] = __DATE__ " " __TIME__;
diff --git a/Xserver/programs/Xserver/hw/vnc/cmap.c b/Xserver/programs/Xserver/hw/vnc/cmap.c
new file mode 100644 (file)
index 0000000..0d33443
--- /dev/null
@@ -0,0 +1,140 @@
+/*
+ * cmap.c
+ */
+
+/*
+ *  Copyright (C) 1999 AT&T Laboratories Cambridge.  All Rights Reserved.
+ *
+ *  This is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This software is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this software; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,
+ *  USA.
+ */
+
+/*
+
+Copyright (c) 1993  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be included
+in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR
+OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall
+not be used in advertising or otherwise to promote the sale, use or
+other dealings in this Software without prior written authorization
+from the X Consortium.
+
+*/
+
+#include <stdio.h>
+#include "scrnintstr.h"
+#include "resource.h"
+#include "colormapst.h"
+#include "rfb.h"
+
+ColormapPtr rfbInstalledColormap;
+
+int
+rfbListInstalledColormaps(pScreen, pmaps)
+    ScreenPtr  pScreen;
+    Colormap   *pmaps;
+{
+    /* By the time we are processing requests, we can guarantee that there
+     * is always a colormap installed */
+    *pmaps = rfbInstalledColormap->mid;
+    return (1);
+}
+
+
+void
+rfbInstallColormap(pmap)
+    ColormapPtr        pmap;
+{
+    ColormapPtr oldpmap = rfbInstalledColormap;
+
+    if (pmap != oldpmap) {
+
+       if(oldpmap != (ColormapPtr)None)
+           WalkTree(pmap->pScreen, TellLostMap, (char *)&oldpmap->mid);
+       /* Install pmap */
+       rfbInstalledColormap = pmap;
+       WalkTree(pmap->pScreen, TellGainedMap, (char *)&pmap->mid);
+
+       rfbSetClientColourMaps(0, 0);
+    }
+}
+
+void
+rfbUninstallColormap(pmap)
+    ColormapPtr        pmap;
+{
+    ColormapPtr curpmap = rfbInstalledColormap;
+
+    if(pmap == curpmap)
+    {
+       if (pmap->mid != pmap->pScreen->defColormap)
+       {
+           curpmap = (ColormapPtr) LookupIDByType(pmap->pScreen->defColormap,
+                                                  RT_COLORMAP);
+           (*pmap->pScreen->InstallColormap)(curpmap);
+       }
+    }
+}
+
+
+/*
+ * rfbStoreColors.  We have a set of pixels but they may be in any order.
+ * If some of them happen to be in continuous ascending order then we can
+ * group them together into a single call to rfbSetClientColourMaps.
+ */
+
+void
+rfbStoreColors(pmap, ndef, pdefs)
+    ColormapPtr pmap;
+    int         ndef;
+    xColorItem  *pdefs;
+{
+    int i;
+    int first = -1;
+    int n = 0;
+
+    if (pmap == rfbInstalledColormap) {
+       for (i = 0; i < ndef; i++) {
+           if ((first != -1) && (first + n == pdefs[i].pixel)) {
+               n++;
+           } else {
+               if (first != -1) {
+                   rfbSetClientColourMaps(first, n);
+               }
+               first = pdefs[i].pixel;
+               n = 1;
+           }
+       }
+       rfbSetClientColourMaps(first, n);
+    }
+}
diff --git a/Xserver/programs/Xserver/hw/vnc/corre.c b/Xserver/programs/Xserver/hw/vnc/corre.c
new file mode 100644 (file)
index 0000000..8fd660c
--- /dev/null
@@ -0,0 +1,350 @@
+/*
+ * corre.c
+ *
+ * Routines to implement Compact Rise-and-Run-length Encoding (CoRRE).  This
+ * code is based on krw's original javatel rfbserver.
+ */
+
+/*
+ *  Copyright (C) 2002 RealVNC Ltd.
+ *  Copyright (C) 1999 AT&T Laboratories Cambridge.  All Rights Reserved.
+ *
+ *  This is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This software is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this software; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,
+ *  USA.
+ */
+
+#include <stdio.h>
+#include "rfb.h"
+
+/*
+ * rreBeforeBuf contains pixel data in the client's format.
+ * rreAfterBuf contains the RRE encoded version.  If the RRE encoded version is
+ * larger than the raw data or if it exceeds rreAfterBufSize then
+ * raw encoding is used instead.
+ */
+
+static int rreBeforeBufSize = 0;
+static char *rreBeforeBuf = NULL;
+
+static int rreAfterBufSize = 0;
+static char *rreAfterBuf = NULL;
+static int rreAfterBufLen;
+
+static int subrectEncode8(CARD8 *data, int w, int h);
+static int subrectEncode16(CARD16 *data, int w, int h);
+static int subrectEncode32(CARD32 *data, int w, int h);
+static CARD32 getBgColour(char *data, int size, int bpp);
+static Bool rfbSendSmallRectEncodingCoRRE(rfbClientPtr cl, int x, int y,
+                                         int w, int h);
+
+
+/*
+ * rfbSendRectEncodingCoRRE - send an arbitrary size rectangle using CoRRE
+ * encoding.
+ */
+
+Bool
+rfbSendRectEncodingCoRRE(cl, x, y, w, h)
+    rfbClientPtr cl;
+    int x, y, w, h;
+{
+    if (h > cl->correMaxHeight) {
+      return (rfbSendRectEncodingCoRRE(cl, x, y, w, cl->correMaxHeight) &&
+              rfbSendRectEncodingCoRRE(cl, x, y + cl->correMaxHeight, w,
+                                       h - cl->correMaxHeight));
+    }
+
+    if (w > cl->correMaxWidth) {
+      return (rfbSendRectEncodingCoRRE(cl, x, y, cl->correMaxWidth, h) &&
+              rfbSendRectEncodingCoRRE(cl, x + cl->correMaxWidth, y,
+                                       w - cl->correMaxWidth, h));
+    }
+
+    return rfbSendSmallRectEncodingCoRRE(cl, x, y, w, h);
+}
+
+
+
+/*
+ * rfbSendSmallRectEncodingCoRRE - send a small (guaranteed < 256x256)
+ * rectangle using CoRRE encoding.
+ */
+
+static Bool
+rfbSendSmallRectEncodingCoRRE(cl, x, y, w, h)
+    rfbClientPtr cl;
+    int x, y, w, h;
+{
+    rfbFramebufferUpdateRectHeader rect;
+    rfbRREHeader hdr;
+    int nSubrects;
+    int i;
+    char *fbptr = (rfbScreen.pfbMemory + (rfbScreen.paddedWidthInBytes * y)
+                  + (x * (rfbScreen.bitsPerPixel / 8)));
+
+    int maxRawSize = (rfbScreen.width * rfbScreen.height
+                     * (cl->format.bitsPerPixel / 8));
+
+    if (rreBeforeBufSize < maxRawSize) {
+       rreBeforeBufSize = maxRawSize;
+       if (rreBeforeBuf == NULL)
+           rreBeforeBuf = (char *)xalloc(rreBeforeBufSize);
+       else
+           rreBeforeBuf = (char *)xrealloc(rreBeforeBuf, rreBeforeBufSize);
+    }
+
+    if (rreAfterBufSize < maxRawSize) {
+       rreAfterBufSize = maxRawSize;
+       if (rreAfterBuf == NULL)
+           rreAfterBuf = (char *)xalloc(rreAfterBufSize);
+       else
+           rreAfterBuf = (char *)xrealloc(rreAfterBuf, rreAfterBufSize);
+    }
+
+    (*cl->translateFn)(cl->translateLookupTable, &rfbServerFormat,
+                      &cl->format, fbptr, rreBeforeBuf,
+                      rfbScreen.paddedWidthInBytes, w, h);
+
+    switch (cl->format.bitsPerPixel) {
+    case 8:
+       nSubrects = subrectEncode8((CARD8 *)rreBeforeBuf, w, h);
+       break;
+    case 16:
+       nSubrects = subrectEncode16((CARD16 *)rreBeforeBuf, w, h);
+       break;
+    case 32:
+       nSubrects = subrectEncode32((CARD32 *)rreBeforeBuf, w, h);
+       break;
+    default:
+       rfbLog("getBgColour: bpp %d?\n",cl->format.bitsPerPixel);
+       exit(1);
+    }
+       
+    if (nSubrects < 0) {
+
+       /* RRE encoding was too large, use raw */
+
+       return rfbSendRectEncodingRaw(cl, x, y, w, h);
+    }
+
+    cl->rfbRectanglesSent[rfbEncodingCoRRE]++;
+    cl->rfbBytesSent[rfbEncodingCoRRE] += (sz_rfbFramebufferUpdateRectHeader
+                                          + sz_rfbRREHeader + rreAfterBufLen);
+
+    if (ublen + sz_rfbFramebufferUpdateRectHeader + sz_rfbRREHeader
+       > UPDATE_BUF_SIZE)
+    {
+       if (!rfbSendUpdateBuf(cl))
+           return FALSE;
+    }
+
+    rect.r.x = Swap16IfLE(x);
+    rect.r.y = Swap16IfLE(y);
+    rect.r.w = Swap16IfLE(w);
+    rect.r.h = Swap16IfLE(h);
+    rect.encoding = Swap32IfLE(rfbEncodingCoRRE);
+
+    memcpy(&updateBuf[ublen], (char *)&rect,
+          sz_rfbFramebufferUpdateRectHeader);
+    ublen += sz_rfbFramebufferUpdateRectHeader;
+
+    hdr.nSubrects = Swap32IfLE(nSubrects);
+
+    memcpy(&updateBuf[ublen], (char *)&hdr, sz_rfbRREHeader);
+    ublen += sz_rfbRREHeader;
+
+    for (i = 0; i < rreAfterBufLen;) {
+
+       int bytesToCopy = UPDATE_BUF_SIZE - ublen;
+
+       if (i + bytesToCopy > rreAfterBufLen) {
+           bytesToCopy = rreAfterBufLen - i;
+       }
+
+       memcpy(&updateBuf[ublen], &rreAfterBuf[i], bytesToCopy);
+
+       ublen += bytesToCopy;
+       i += bytesToCopy;
+
+       if (ublen == UPDATE_BUF_SIZE) {
+           if (!rfbSendUpdateBuf(cl))
+               return FALSE;
+       }
+    }
+
+    return TRUE;
+}
+
+
+
+/*
+ * subrectEncode() encodes the given multicoloured rectangle as a background 
+ * colour overwritten by single-coloured rectangles.  It returns the number 
+ * of subrectangles in the encoded buffer, or -1 if subrect encoding won't
+ * fit in the buffer.  It puts the encoded rectangles in rreAfterBuf.  The
+ * single-colour rectangle partition is not optimal, but does find the biggest
+ * horizontal or vertical rectangle top-left anchored to each consecutive 
+ * coordinate position.
+ *
+ * The coding scheme is simply [<bgcolour><subrect><subrect>...] where each 
+ * <subrect> is [<colour><x><y><w><h>].
+ */
+
+#define DEFINE_SUBRECT_ENCODE(bpp)                                           \
+static int                                                                   \
+subrectEncode##bpp(data,w,h)                                                 \
+    CARD##bpp *data;                                                         \
+    int w;                                                                   \
+    int h;                                                                   \
+{                                                                            \
+    CARD##bpp cl;                                                            \
+    rfbCoRRERectangle subrect;                                               \
+    int x,y;                                                                 \
+    int i,j;                                                                 \
+    int hx=0,hy,vx=0,vy;                                                     \
+    int hyflag;                                                                      \
+    CARD##bpp *seg;                                                          \
+    CARD##bpp *line;                                                         \
+    int hw,hh,vw,vh;                                                         \
+    int thex,they,thew,theh;                                                 \
+    int numsubs = 0;                                                         \
+    int newLen;                                                                      \
+    CARD##bpp bg = (CARD##bpp)getBgColour((char*)data,w*h,bpp);                      \
+                                                                             \
+    *((CARD##bpp*)rreAfterBuf) = bg;                                         \
+                                                                             \
+    rreAfterBufLen = (bpp/8);                                                \
+                                                                             \
+    for (y=0; y<h; y++) {                                                    \
+      line = data+(y*w);                                                     \
+      for (x=0; x<w; x++) {                                                  \
+        if (line[x] != bg) {                                                 \
+          cl = line[x];                                                              \
+          hy = y-1;                                                          \
+          hyflag = 1;                                                        \
+          for (j=y; j<h; j++) {                                                      \
+            seg = data+(j*w);                                                \
+            if (seg[x] != cl) {break;}                                       \
+            i = x;                                                           \
+            while ((seg[i] == cl) && (i < w)) i += 1;                        \
+            i -= 1;                                                          \
+            if (j == y) vx = hx = i;                                         \
+            if (i < vx) vx = i;                                                      \
+            if ((hyflag > 0) && (i >= hx)) {hy += 1;} else {hyflag = 0;}      \
+          }                                                                  \
+          vy = j-1;                                                          \
+                                                                             \
+          /*  We now have two possible subrects: (x,y,hx,hy) and (x,y,vx,vy)  \
+           *  We'll choose the bigger of the two.                            \
+           */                                                                \
+          hw = hx-x+1;                                                       \
+          hh = hy-y+1;                                                       \
+          vw = vx-x+1;                                                       \
+          vh = vy-y+1;                                                       \
+                                                                             \
+          thex = x;                                                          \
+          they = y;                                                          \
+                                                                             \
+          if ((hw*hh) > (vw*vh)) {                                           \
+            thew = hw;                                                       \
+            theh = hh;                                                       \
+          } else {                                                           \
+            thew = vw;                                                       \
+            theh = vh;                                                       \
+          }                                                                  \
+                                                                             \
+          subrect.x = thex;                                                  \
+          subrect.y = they;                                                  \
+          subrect.w = thew;                                                  \
+          subrect.h = theh;                                                  \
+                                                                             \
+         newLen = rreAfterBufLen + (bpp/8) + sz_rfbCoRRERectangle;           \
+          if ((newLen > (w * h * (bpp/8))) || (newLen > rreAfterBufSize))     \
+           return -1;                                                        \
+                                                                             \
+         numsubs += 1;                                                       \
+         *((CARD##bpp*)(rreAfterBuf + rreAfterBufLen)) = cl;                 \
+         rreAfterBufLen += (bpp/8);                                          \
+         memcpy(&rreAfterBuf[rreAfterBufLen],&subrect,sz_rfbCoRRERectangle); \
+         rreAfterBufLen += sz_rfbCoRRERectangle;                             \
+                                                                             \
+          /*                                                                 \
+           * Now mark the subrect as done.                                   \
+           */                                                                \
+          for (j=they; j < (they+theh); j++) {                               \
+            for (i=thex; i < (thex+thew); i++) {                             \
+              data[j*w+i] = bg;                                                      \
+            }                                                                \
+          }                                                                  \
+        }                                                                    \
+      }                                                                              \
+    }                                                                        \
+                                                                             \
+    return numsubs;                                                          \
+}
+
+DEFINE_SUBRECT_ENCODE(8)
+DEFINE_SUBRECT_ENCODE(16)
+DEFINE_SUBRECT_ENCODE(32)
+
+
+/*
+ * getBgColour() gets the most prevalent colour in a byte array.
+ */
+static CARD32
+getBgColour(data,size,bpp)
+    char *data;
+    int size;
+    int bpp;
+{
+    
+#define NUMCLRS 256
+  
+  static int counts[NUMCLRS];
+  int i,j,k;
+
+  int maxcount = 0;
+  CARD8 maxclr = 0;
+
+  if (bpp != 8) {
+    if (bpp == 16) {
+      return ((CARD16 *)data)[0];
+    } else if (bpp == 32) {
+      return ((CARD32 *)data)[0];
+    } else {
+      rfbLog("getBgColour: bpp %d?\n",bpp);
+      exit(1);
+    }
+  }
+
+  for (i=0; i<NUMCLRS; i++) {
+    counts[i] = 0;
+  }
+
+  for (j=0; j<size; j++) {
+    k = (int)(((CARD8 *)data)[j]);
+    if (k >= NUMCLRS) {
+      rfbLog("getBgColour: unusual colour = %d\n", k);
+      exit(1);
+    }
+    counts[k] += 1;
+    if (counts[k] > maxcount) {
+      maxcount = counts[k];
+      maxclr = ((CARD8 *)data)[j];
+    }
+  }
+  
+  return maxclr;
+}
diff --git a/Xserver/programs/Xserver/hw/vnc/cutpaste.c b/Xserver/programs/Xserver/hw/vnc/cutpaste.c
new file mode 100644 (file)
index 0000000..2860f51
--- /dev/null
@@ -0,0 +1,88 @@
+/*
+ * cutpaste.c - routines to deal with cut & paste buffers / selection.
+ */
+
+/*
+ *  Copyright (C) 2002 RealVNC Ltd.
+ *  Copyright (C) 1999 AT&T Laboratories Cambridge.  All Rights Reserved.
+ *
+ *  This is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This software is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this software; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,
+ *  USA.
+ */
+
+#include <stdio.h>
+#define NEED_EVENTS
+#include <X.h>
+#include <Xproto.h>
+#include "rfb.h"
+#include "selection.h"
+#include "input.h"
+#include <property.h>
+#include <Xatom.h>
+
+extern WindowPtr *WindowTable; /* Why isn't this in a header file? */
+extern Selection *CurrentSelections;
+extern int NumCurrentSelections;
+
+
+static Bool inSetXCutText = FALSE;
+
+/*
+ * rfbSetXCutText sets the cut buffer to be the given string.  We also clear
+ * the primary selection.  Ideally we'd like to set it to the same thing, but I
+ * can't work out how to do that without some kind of helper X client.
+ */
+
+void
+rfbSetXCutText(char *str, int len)
+{
+    int i = 0;
+
+    inSetXCutText = TRUE;
+    ChangeWindowProperty(WindowTable[0], XA_CUT_BUFFER0, XA_STRING,
+                        8, PropModeReplace, len,
+                        (pointer)str, TRUE);
+    
+    while ((i < NumCurrentSelections) && 
+          CurrentSelections[i].selection != XA_PRIMARY)
+       i++;
+
+    if (i < NumCurrentSelections) {
+       xEvent event;
+
+       if (CurrentSelections[i].client) {
+           event.u.u.type = SelectionClear;
+           event.u.selectionClear.time = GetTimeInMillis();
+           event.u.selectionClear.window = CurrentSelections[i].window;
+           event.u.selectionClear.atom = CurrentSelections[i].selection;
+           (void) TryClientEvents (CurrentSelections[i].client, &event, 1,
+                               NoEventMask, NoEventMask /* CantBeFiltered */,
+                               NullGrab);
+       }
+
+       CurrentSelections[i].window = None;
+       CurrentSelections[i].pWin = NULL;
+       CurrentSelections[i].client = NullClient;
+    }
+
+    inSetXCutText = FALSE;
+}
+
+
+void rfbGotXCutText(char *str, int len)
+{
+    if (!inSetXCutText)
+       rfbSendServerCutText(str, len);
+}
diff --git a/Xserver/programs/Xserver/hw/vnc/dispcur.c b/Xserver/programs/Xserver/hw/vnc/dispcur.c
new file mode 100644 (file)
index 0000000..6a89d25
--- /dev/null
@@ -0,0 +1,403 @@
+/*
+ * dispcur.c
+ *
+ * cursor display routines - based on midispcur.c
+ */
+
+/*
+ *  Copyright (C) 1999 AT&T Laboratories Cambridge.  All Rights Reserved.
+ *
+ *  This is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This software is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this software; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,
+ *  USA.
+ */
+
+/*
+
+Copyright (c) 1989  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+*/
+
+#define NEED_EVENTS
+# include   "X.h"
+# include   "misc.h"
+# include   "input.h"
+# include   "cursorstr.h"
+# include   "windowstr.h"
+# include   "regionstr.h"
+# include   "dixstruct.h"
+# include   "scrnintstr.h"
+# include   "servermd.h"
+# include   "mipointer.h"
+# include   "sprite.h"
+# include   "gcstruct.h"
+
+extern WindowPtr    *WindowTable;
+
+/* per-screen private data */
+
+static int     rfbDCScreenIndex;
+static unsigned long rfbDCGeneration = 0;
+
+static Bool    rfbDCCloseScreen();
+
+typedef struct {
+    GCPtr          pSourceGC, pMaskGC;
+    GCPtr          pSaveGC, pRestoreGC;
+    GCPtr          pPixSourceGC, pPixMaskGC;
+    CloseScreenProcPtr CloseScreen;
+    PixmapPtr      pSave;
+} rfbDCScreenRec, *rfbDCScreenPtr;
+
+/* per-cursor per-screen private data */
+typedef struct {
+    PixmapPtr          sourceBits;         /* source bits */
+    PixmapPtr          maskBits;           /* mask bits */
+} rfbDCCursorRec, *rfbDCCursorPtr;
+
+/*
+ * sprite/cursor method table
+ */
+
+static Bool    rfbDCRealizeCursor(),       rfbDCUnrealizeCursor();
+static Bool    rfbDCPutUpCursor(),         rfbDCSaveUnderCursor();
+static Bool    rfbDCRestoreUnderCursor();
+
+static rfbSpriteCursorFuncRec rfbDCFuncs = {
+    rfbDCRealizeCursor,
+    rfbDCUnrealizeCursor,
+    rfbDCPutUpCursor,
+    rfbDCSaveUnderCursor,
+    rfbDCRestoreUnderCursor,
+};
+
+Bool
+rfbDCInitialize (pScreen, screenFuncs)
+    ScreenPtr              pScreen;
+    miPointerScreenFuncPtr  screenFuncs;
+{
+    rfbDCScreenPtr   pScreenPriv;
+
+    if (rfbDCGeneration != serverGeneration)
+    {
+       rfbDCScreenIndex = AllocateScreenPrivateIndex ();
+       if (rfbDCScreenIndex < 0)
+           return FALSE;
+       rfbDCGeneration = serverGeneration;
+    }
+    pScreenPriv = (rfbDCScreenPtr) xalloc (sizeof (rfbDCScreenRec));
+    if (!pScreenPriv)
+       return FALSE;
+
+    /*
+     * initialize the entire private structure to zeros
+     */
+
+    pScreenPriv->pSourceGC =
+       pScreenPriv->pMaskGC =
+       pScreenPriv->pSaveGC =
+       pScreenPriv->pRestoreGC =
+       pScreenPriv->pPixSourceGC =
+       pScreenPriv->pPixMaskGC = NULL;
+    
+    pScreenPriv->pSave = NULL;
+
+    pScreenPriv->CloseScreen = pScreen->CloseScreen;
+    pScreen->CloseScreen = rfbDCCloseScreen;
+    
+    pScreen->devPrivates[rfbDCScreenIndex].ptr = (pointer) pScreenPriv;
+
+    if (!rfbSpriteInitialize (pScreen, &rfbDCFuncs, screenFuncs))
+    {
+       xfree ((pointer) pScreenPriv);
+       return FALSE;
+    }
+    return TRUE;
+}
+
+#define tossGC(gc)  (gc ? FreeGC (gc, (GContext) 0) : 0)
+#define tossPix(pix)   (pix ? (*pScreen->DestroyPixmap) (pix) : TRUE)
+
+static Bool
+rfbDCCloseScreen (index, pScreen)
+    ScreenPtr  pScreen;
+{
+    rfbDCScreenPtr   pScreenPriv;
+
+    pScreenPriv = (rfbDCScreenPtr) pScreen->devPrivates[rfbDCScreenIndex].ptr;
+    pScreen->CloseScreen = pScreenPriv->CloseScreen;
+    tossGC (pScreenPriv->pSourceGC);
+    tossGC (pScreenPriv->pMaskGC);
+    tossGC (pScreenPriv->pSaveGC);
+    tossGC (pScreenPriv->pRestoreGC);
+    tossGC (pScreenPriv->pPixSourceGC);
+    tossGC (pScreenPriv->pPixMaskGC);
+    tossPix (pScreenPriv->pSave);
+    xfree ((pointer) pScreenPriv);
+    return (*pScreen->CloseScreen) (index, pScreen);
+}
+
+static Bool
+rfbDCRealizeCursor (pScreen, pCursor)
+    ScreenPtr  pScreen;
+    CursorPtr  pCursor;
+{
+    if (pCursor->bits->refcnt <= 1)
+       pCursor->bits->devPriv[pScreen->myNum] = (pointer)NULL;
+    return TRUE;
+}
+
+static rfbDCCursorPtr
+rfbDCRealize (pScreen, pCursor)
+    ScreenPtr  pScreen;
+    CursorPtr  pCursor;
+{
+    rfbDCCursorPtr   pPriv;
+    GCPtr          pGC;
+    XID                    gcvals[3];
+
+    pPriv = (rfbDCCursorPtr) xalloc (sizeof (rfbDCCursorRec));
+    if (!pPriv)
+       return (rfbDCCursorPtr)NULL;
+    pPriv->sourceBits = (*pScreen->CreatePixmap) (pScreen, pCursor->bits->width, pCursor->bits->height, 1);
+    if (!pPriv->sourceBits)
+    {
+       xfree ((pointer) pPriv);
+       return (rfbDCCursorPtr)NULL;
+    }
+    pPriv->maskBits =  (*pScreen->CreatePixmap) (pScreen, pCursor->bits->width, pCursor->bits->height, 1);
+    if (!pPriv->maskBits)
+    {
+       (*pScreen->DestroyPixmap) (pPriv->sourceBits);
+       xfree ((pointer) pPriv);
+       return (rfbDCCursorPtr)NULL;
+    }
+    pCursor->bits->devPriv[pScreen->myNum] = (pointer) pPriv;
+
+    /* create the two sets of bits, clipping as appropriate */
+
+    pGC = GetScratchGC (1, pScreen);
+    if (!pGC)
+    {
+       (void) rfbDCUnrealizeCursor (pScreen, pCursor);
+       return (rfbDCCursorPtr)NULL;
+    }
+
+    ValidateGC ((DrawablePtr)pPriv->sourceBits, pGC);
+    (*pGC->ops->PutImage) ((DrawablePtr)pPriv->sourceBits, pGC, 1,
+                          0, 0, pCursor->bits->width, pCursor->bits->height,
+                          0, XYPixmap, (char *)pCursor->bits->source);
+    gcvals[0] = GXand;
+    ChangeGC (pGC, GCFunction, gcvals);
+    ValidateGC ((DrawablePtr)pPriv->sourceBits, pGC);
+    (*pGC->ops->PutImage) ((DrawablePtr)pPriv->sourceBits, pGC, 1,
+                          0, 0, pCursor->bits->width, pCursor->bits->height,
+                          0, XYPixmap, (char *)pCursor->bits->mask);
+
+    /* mask bits -- pCursor->mask & ~pCursor->source */
+    gcvals[0] = GXcopy;
+    ChangeGC (pGC, GCFunction, gcvals);
+    ValidateGC ((DrawablePtr)pPriv->maskBits, pGC);
+    (*pGC->ops->PutImage) ((DrawablePtr)pPriv->maskBits, pGC, 1,
+                          0, 0, pCursor->bits->width, pCursor->bits->height,
+                          0, XYPixmap, (char *)pCursor->bits->mask);
+    gcvals[0] = GXandInverted;
+    ChangeGC (pGC, GCFunction, gcvals);
+    ValidateGC ((DrawablePtr)pPriv->maskBits, pGC);
+    (*pGC->ops->PutImage) ((DrawablePtr)pPriv->maskBits, pGC, 1,
+                          0, 0, pCursor->bits->width, pCursor->bits->height,
+                          0, XYPixmap, (char *)pCursor->bits->source);
+    FreeScratchGC (pGC);
+    return pPriv;
+}
+
+static Bool
+rfbDCUnrealizeCursor (pScreen, pCursor)
+    ScreenPtr  pScreen;
+    CursorPtr  pCursor;
+{
+    rfbDCCursorPtr   pPriv;
+
+    pPriv = (rfbDCCursorPtr) pCursor->bits->devPriv[pScreen->myNum];
+    if (pPriv && (pCursor->bits->refcnt <= 1))
+    {
+       (*pScreen->DestroyPixmap) (pPriv->sourceBits);
+       (*pScreen->DestroyPixmap) (pPriv->maskBits);
+       xfree ((pointer) pPriv);
+       pCursor->bits->devPriv[pScreen->myNum] = (pointer)NULL;
+    }
+    return TRUE;
+}
+
+static void
+rfbDCPutBits (pDrawable, pPriv, sourceGC, maskGC, x, y, w, h, source, mask)
+    DrawablePtr            pDrawable;
+    GCPtr          sourceGC, maskGC;
+    int             x, y;
+    unsigned        w, h;
+    rfbDCCursorPtr   pPriv;
+    unsigned long   source, mask;
+{
+    XID            gcvals[1];
+
+    if (sourceGC->fgPixel != source)
+    {
+       gcvals[0] = source;
+       DoChangeGC (sourceGC, GCForeground, gcvals, 0);
+    }
+    if (sourceGC->serialNumber != pDrawable->serialNumber)
+       ValidateGC (pDrawable, sourceGC);
+    (*sourceGC->ops->PushPixels) (sourceGC, pPriv->sourceBits, pDrawable, w, h, x, y);
+    if (maskGC->fgPixel != mask)
+    {
+       gcvals[0] = mask;
+       DoChangeGC (maskGC, GCForeground, gcvals, 0);
+    }
+    if (maskGC->serialNumber != pDrawable->serialNumber)
+       ValidateGC (pDrawable, maskGC);
+    (*maskGC->ops->PushPixels) (maskGC, pPriv->maskBits, pDrawable, w, h, x, y);
+}
+
+#define EnsureGC(gc,win) (gc || rfbDCMakeGC(&gc, win))
+
+static GCPtr
+rfbDCMakeGC(ppGC, pWin)
+    GCPtr      *ppGC;
+    WindowPtr  pWin;
+{
+    GCPtr pGC;
+    int   status;
+    XID   gcvals[2];
+
+    gcvals[0] = IncludeInferiors;
+    gcvals[1] = FALSE;
+    pGC = CreateGC((DrawablePtr)pWin,
+                  GCSubwindowMode|GCGraphicsExposures, gcvals, &status);
+    if (pGC)
+       (*pWin->drawable.pScreen->DrawGuarantee) (pWin, pGC, GuaranteeVisBack);
+    *ppGC = pGC;
+    return pGC;
+}
+
+static Bool
+rfbDCPutUpCursor (pScreen, pCursor, x, y, source, mask)
+    ScreenPtr      pScreen;
+    CursorPtr      pCursor;
+    int                    x, y;
+    unsigned long   source, mask;
+{
+    rfbDCScreenPtr   pScreenPriv;
+    rfbDCCursorPtr   pPriv;
+    WindowPtr      pWin;
+
+    pPriv = (rfbDCCursorPtr) pCursor->bits->devPriv[pScreen->myNum];
+    if (!pPriv)
+    {
+       pPriv = rfbDCRealize(pScreen, pCursor);
+       if (!pPriv)
+           return FALSE;
+    }
+    pScreenPriv = (rfbDCScreenPtr) pScreen->devPrivates[rfbDCScreenIndex].ptr;
+    pWin = WindowTable[pScreen->myNum];
+    if (!EnsureGC(pScreenPriv->pSourceGC, pWin))
+       return FALSE;
+    if (!EnsureGC(pScreenPriv->pMaskGC, pWin))
+    {
+       FreeGC (pScreenPriv->pSourceGC, (GContext) 0);
+       pScreenPriv->pSourceGC = 0;
+       return FALSE;
+    }
+    rfbDCPutBits ((DrawablePtr)pWin, pPriv,
+                pScreenPriv->pSourceGC, pScreenPriv->pMaskGC,
+                x, y, pCursor->bits->width, pCursor->bits->height,
+                source, mask);
+    return TRUE;
+}
+
+static Bool
+rfbDCSaveUnderCursor (pScreen, x, y, w, h)
+    ScreenPtr  pScreen;
+    int                x, y, w, h;
+{
+    rfbDCScreenPtr   pScreenPriv;
+    PixmapPtr      pSave;
+    WindowPtr      pWin;
+    GCPtr          pGC;
+
+    pScreenPriv = (rfbDCScreenPtr) pScreen->devPrivates[rfbDCScreenIndex].ptr;
+    pSave = pScreenPriv->pSave;
+    pWin = WindowTable[pScreen->myNum];
+    if (!pSave || pSave->drawable.width < w || pSave->drawable.height < h)
+    {
+       if (pSave)
+           (*pScreen->DestroyPixmap) (pSave);
+       pScreenPriv->pSave = pSave =
+               (*pScreen->CreatePixmap) (pScreen, w, h, pScreen->rootDepth);
+       if (!pSave)
+           return FALSE;
+    }
+    if (!EnsureGC(pScreenPriv->pSaveGC, pWin))
+       return FALSE;
+    pGC = pScreenPriv->pSaveGC;
+    if (pSave->drawable.serialNumber != pGC->serialNumber)
+       ValidateGC ((DrawablePtr) pSave, pGC);
+    (*pGC->ops->CopyArea) ((DrawablePtr) pWin, (DrawablePtr) pSave, pGC,
+                           x, y, w, h, 0, 0);
+    return TRUE;
+}
+
+static Bool
+rfbDCRestoreUnderCursor (pScreen, x, y, w, h)
+    ScreenPtr  pScreen;
+    int                x, y, w, h;
+{
+    rfbDCScreenPtr   pScreenPriv;
+    PixmapPtr      pSave;
+    WindowPtr      pWin;
+    GCPtr          pGC;
+
+    pScreenPriv = (rfbDCScreenPtr) pScreen->devPrivates[rfbDCScreenIndex].ptr;
+    pSave = pScreenPriv->pSave;
+    pWin = WindowTable[pScreen->myNum];
+    if (!pSave)
+       return FALSE;
+    if (!EnsureGC(pScreenPriv->pRestoreGC, pWin))
+       return FALSE;
+    pGC = pScreenPriv->pRestoreGC;
+    if (pWin->drawable.serialNumber != pGC->serialNumber)
+       ValidateGC ((DrawablePtr) pWin, pGC);
+    (*pGC->ops->CopyArea) ((DrawablePtr) pSave, (DrawablePtr) pWin, pGC,
+                           0, 0, w, h, x, y);
+    return TRUE;
+}
diff --git a/Xserver/programs/Xserver/hw/vnc/dispcur.h b/Xserver/programs/Xserver/hw/vnc/dispcur.h
new file mode 100644 (file)
index 0000000..1e85f1c
--- /dev/null
@@ -0,0 +1,23 @@
+/*
+ *  Copyright (C) 2002 RealVNC Ltd.  All Rights Reserved.
+ *
+ *  This is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This software is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this software; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,
+ *  USA.
+ */
+
+#include <mipointer.h>
+
+extern Bool rfbDCInitialize(ScreenPtr pScreen,
+                           miPointerScreenFuncPtr screenFuncs);
diff --git a/Xserver/programs/Xserver/hw/vnc/draw.c b/Xserver/programs/Xserver/hw/vnc/draw.c
new file mode 100644 (file)
index 0000000..599e313
--- /dev/null
@@ -0,0 +1,1998 @@
+/*
+ * draw.c - drawing routines for the RFB X server.  This is a set of
+ * wrappers around the standard MI/MFB/CFB drawing routines which work out
+ * to a fair approximation the region of the screen being modified by the
+ * drawing.  If the RFB client is ready then the modified region of the screen
+ * is sent to the client, otherwise the modified region will simply grow with
+ * each drawing request until the client is ready.
+ */
+
+/*
+ *  Copyright (C) 2002-2003 RealVNC Ltd.
+ *  Copyright (C) 1999 AT&T Laboratories Cambridge.  All Rights Reserved.
+ *
+ *  This is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This software is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this software; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,
+ *  USA.
+ */
+
+/*
+
+Copyright (c) 1989  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+*/
+
+#include <stdio.h>
+#include "scrnintstr.h"
+#include "gcstruct.h"
+#include "windowstr.h"
+#include "regionstr.h"
+#include "dixfontstr.h"
+#include "rfb.h"
+#include "mfb.h"
+
+extern WindowPtr *WindowTable; /* Why isn't this in a header file? */
+
+int rfbDeferUpdateTime = 40; /* ms */
+
+/* MAX_RECTS_PER_OP is the maximum number of rectangles we generate from
+   operations like Polylines and PolySegment.  If the operation is more complex
+   than this, we simply use the bounding box.  Ideally it would be a
+   command-line option, but that would involve an extra malloc each time, so we
+   fix it here. */
+#define MAX_RECTS_PER_OP 5
+
+
+/****************************************************************************/
+/*
+ * Macro definitions
+ */
+/****************************************************************************/
+
+/* SLIGHTLY DIRTY HACK - use Composite Clip region calculated by mfb */
+
+#define WINDOW_CLIP_REGION(_w, _gc) \
+  (((mfbPrivGCPtr)((_gc)->devPrivates[mfbGCPrivateIndex].ptr))->pCompositeClip)
+
+#define TRC(x) if (rfbTrace) rfbLog x
+
+/* ADD_TO_MODIFIED_REGION adds the given region to the modified region for each
+   client */
+
+#define ADD_TO_MODIFIED_REGION(pScreen,reg)                                   \
+  {                                                                           \
+      rfbClientPtr cl;                                                        \
+      for (cl = rfbClientHead; cl; cl = cl->next) {                           \
+          if (REGION_NUM_RECTS(&cl->modifiedRegion) > rfbMaxRects) {          \
+              BoxRec boundingBox = *(REGION_EXTENTS((pScreen),                \
+                                                    &cl->modifiedRegion));    \
+              REGION_RESET((pScreen), &cl->modifiedRegion, &boundingBox);     \
+          }                                                                   \
+                                                                              \
+         REGION_UNION((pScreen),&cl->modifiedRegion,&cl->modifiedRegion,reg);\
+      }                                                                       \
+  }
+
+/* SCHEDULE_FB_UPDATE is used at the end of each drawing routine to schedule an
+   update to be sent to each client if there is one pending and the client is
+   ready for it.  */
+
+#define SCHEDULE_FB_UPDATE(pScreen,prfb)                               \
+  if (!prfb->dontSendFramebufferUpdate) {                              \
+      rfbClientPtr cl, nextCl;                                         \
+      for (cl = rfbClientHead; cl; cl = nextCl) {                      \
+         nextCl = cl->next;                                            \
+         if (!cl->deferredUpdateScheduled && FB_UPDATE_PENDING(cl) &&  \
+             REGION_NOTEMPTY(pScreen,&cl->requestedRegion))            \
+         {                                                             \
+             rfbScheduleDeferredUpdate(cl);                            \
+         }                                                             \
+      }                                                                        \
+  }
+
+/* function prototypes */
+
+static void rfbCopyRegion(ScreenPtr pScreen, rfbClientPtr cl,
+                         RegionPtr src, RegionPtr dst, int dx, int dy);
+
+/* GC funcs */
+
+static void rfbValidateGC(GCPtr, unsigned long /*changes*/, DrawablePtr);
+static void rfbChangeGC(GCPtr, unsigned long /*mask*/);
+static void rfbCopyGC(GCPtr /*src*/, unsigned long /*mask*/, GCPtr /*dst*/);
+static void rfbDestroyGC(GCPtr);
+static void rfbChangeClip(GCPtr, int /*type*/, pointer /*pValue*/,
+                         int /*nrects*/);
+static void rfbDestroyClip(GCPtr);
+static void rfbCopyClip(GCPtr /*dst*/, GCPtr /*src*/);
+
+/* GC ops */
+
+static void rfbFillSpans();
+static void rfbSetSpans();
+static void rfbPutImage();
+static RegionPtr rfbCopyArea();
+static RegionPtr rfbCopyPlane();
+static void rfbPolyPoint();
+static void rfbPolylines();
+static void rfbPolySegment();
+static void rfbPolyRectangle();
+static void rfbPolyArc();
+static void rfbFillPolygon();
+static void rfbPolyFillRect();
+static void rfbPolyFillArc();
+static int rfbPolyText8();
+static int rfbPolyText16();
+static void rfbImageText8();
+static void rfbImageText16();
+static void rfbImageGlyphBlt();
+static void rfbPolyGlyphBlt();
+static void rfbPushPixels();
+
+
+static GCFuncs rfbGCFuncs = {
+    rfbValidateGC,
+    rfbChangeGC,
+    rfbCopyGC,
+    rfbDestroyGC,
+    rfbChangeClip,
+    rfbDestroyClip,
+    rfbCopyClip,
+};
+
+
+static GCOps rfbGCOps = {
+    rfbFillSpans,      rfbSetSpans,    rfbPutImage,    
+    rfbCopyArea,       rfbCopyPlane,   rfbPolyPoint,
+    rfbPolylines,      rfbPolySegment, rfbPolyRectangle,
+    rfbPolyArc,                rfbFillPolygon, rfbPolyFillRect,
+    rfbPolyFillArc,    rfbPolyText8,   rfbPolyText16,
+    rfbImageText8,     rfbImageText16, rfbImageGlyphBlt,
+    rfbPolyGlyphBlt,   rfbPushPixels
+};
+
+
+
+/****************************************************************************/
+/*
+ * Screen functions wrapper stuff
+ */
+/****************************************************************************/
+
+#define SCREEN_PROLOGUE(scrn, field)           \
+    ScreenPtr pScreen = scrn;                  \
+    rfbScreenInfoPtr prfb = &rfbScreen;                \
+    pScreen->field = prfb->field;
+
+#define SCREEN_EPILOGUE(field, wrapper) \
+    pScreen->field = wrapper;
+
+
+/*
+ * CloseScreen wrapper -- unwrap everything, free the private data
+ * and call the wrapped CloseScreen function.
+ */
+
+Bool
+rfbCloseScreen (i, pScreen)
+    int i;
+    ScreenPtr  pScreen;
+{
+    rfbScreenInfoPtr prfb = &rfbScreen;
+
+    pScreen->CloseScreen = prfb->CloseScreen;
+    pScreen->CreateGC = prfb->CreateGC;
+    pScreen->PaintWindowBackground = prfb->PaintWindowBackground;
+    pScreen->PaintWindowBorder = prfb->PaintWindowBorder;
+    pScreen->CopyWindow = prfb->CopyWindow;
+    pScreen->ClearToBackground = prfb->ClearToBackground;
+    pScreen->RestoreAreas = prfb->RestoreAreas;
+
+    TRC(("Unwrapped screen functions\n"));
+
+    return (*pScreen->CloseScreen) (i, pScreen);
+}
+
+/*
+ * CreateGC - wrap the GC funcs (the GC ops will be wrapped when the GC
+ * func "ValidateGC" is called).
+ */
+
+Bool
+rfbCreateGC (pGC)
+    GCPtr   pGC;
+{
+    Bool ret;
+    rfbGCPtr pGCPriv;
+
+    SCREEN_PROLOGUE(pGC->pScreen,CreateGC);
+    
+    pGCPriv = (rfbGCPtr)pGC->devPrivates[rfbGCIndex].ptr;
+
+    ret = (*pScreen->CreateGC) (pGC);
+
+    TRC(("rfbCreateGC called\n"));
+
+    pGCPriv->wrapOps = NULL;
+    pGCPriv->wrapFuncs = pGC->funcs;
+    pGC->funcs = &rfbGCFuncs;
+
+    SCREEN_EPILOGUE(CreateGC,rfbCreateGC);
+
+    return ret;
+}
+
+/*
+ * PaintWindowBackground - the region being modified is just the given region.
+ */
+
+void
+rfbPaintWindowBackground (pWin, pRegion, what)
+    WindowPtr  pWin;
+    RegionPtr  pRegion;
+    int                what;
+{
+    SCREEN_PROLOGUE(pWin->drawable.pScreen,PaintWindowBackground);
+
+    TRC(("rfbPaintWindowBackground called\n"));
+
+    ADD_TO_MODIFIED_REGION(pScreen,pRegion);
+
+    (*pScreen->PaintWindowBackground) (pWin, pRegion, what);
+
+    SCHEDULE_FB_UPDATE(pScreen, prfb);
+
+    SCREEN_EPILOGUE(PaintWindowBackground,rfbPaintWindowBackground);
+}
+
+/*
+ * PaintWindowBorder - the region being modified is just the given region.
+ */
+
+void
+rfbPaintWindowBorder (pWin, pRegion, what)
+    WindowPtr  pWin;
+    RegionPtr  pRegion;
+    int                what;
+{
+    SCREEN_PROLOGUE(pWin->drawable.pScreen,PaintWindowBorder);
+
+    TRC(("rfbPaintWindowBorder called\n"));
+
+    ADD_TO_MODIFIED_REGION(pScreen,pRegion);
+
+    (*pScreen->PaintWindowBorder) (pWin, pRegion, what);
+
+    SCHEDULE_FB_UPDATE(pScreen, prfb);
+
+    SCREEN_EPILOGUE(PaintWindowBorder,rfbPaintWindowBorder);
+}
+
+/*
+ * CopyWindow - the region being modified is the translation of the old
+ * region, clipped to the border clip region of the window.  Note that any
+ * parts of the window which have become newly-visible will not be affected by
+ * this call - a separate PaintWindowBackground/Border will be called to do
+ * that.  If the client will accept CopyRect messages then use rfbCopyRegion to
+ * optimise the pending screen changes into a single "copy region" plus the
+ * ordinary modified region.
+ */
+
+void
+rfbCopyWindow (pWin, ptOldOrg, pOldRegion)
+    WindowPtr  pWin;
+    DDXPointRec        ptOldOrg;
+    RegionPtr  pOldRegion;
+{
+    rfbClientPtr cl;
+    RegionRec srcRegion, dstRegion;
+    SCREEN_PROLOGUE(pWin->drawable.pScreen,CopyWindow);
+
+    TRC(("rfbCopyWindow called\n"));
+
+    REGION_INIT(pScreen,&dstRegion,NullBox,0);
+    REGION_COPY(pScreen,&dstRegion,pOldRegion);
+    REGION_TRANSLATE(pWin->drawable.pScreen, &dstRegion,
+                    pWin->drawable.x - ptOldOrg.x,
+                    pWin->drawable.y - ptOldOrg.y);
+    REGION_INTERSECT(pWin->drawable.pScreen, &dstRegion, &dstRegion,
+                    &pWin->borderClip);
+
+    for (cl = rfbClientHead; cl; cl = cl->next) {
+       if (cl->useCopyRect) {
+           REGION_INIT(pScreen,&srcRegion,NullBox,0);
+           REGION_COPY(pScreen,&srcRegion,pOldRegion);
+
+           rfbCopyRegion(pScreen, cl, &srcRegion, &dstRegion,
+                         pWin->drawable.x - ptOldOrg.x,
+                         pWin->drawable.y - ptOldOrg.y);
+
+           REGION_UNINIT(pSrc->pScreen, &srcRegion);
+
+       } else {
+
+           REGION_UNION(pScreen, &cl->modifiedRegion, &cl->modifiedRegion,
+                        &dstRegion);
+       }
+    }
+
+    REGION_UNINIT(pSrc->pScreen, &dstRegion);
+
+    (*pScreen->CopyWindow) (pWin, ptOldOrg, pOldRegion);
+
+    SCHEDULE_FB_UPDATE(pScreen, prfb);
+
+    SCREEN_EPILOGUE(CopyWindow,rfbCopyWindow);
+}
+
+/*
+ * ClearToBackground - when generateExposures is false, the region being
+ * modified is the given rectangle (clipped to the "window clip region").
+ */
+
+void
+rfbClearToBackground (pWin, x, y, w, h, generateExposures)
+    WindowPtr pWin;
+    int x,y,w,h;
+    Bool generateExposures;
+{
+    RegionRec tmpRegion;
+    BoxRec box;
+    SCREEN_PROLOGUE(pWin->drawable.pScreen,ClearToBackground);
+
+    TRC(("rfbClearToBackground called\n"));
+
+    if (!generateExposures) {
+       box.x1 = x + pWin->drawable.x;
+       box.y1 = y + pWin->drawable.y;
+       box.x2 = w ? (box.x1 + w) : (pWin->drawable.x + pWin->drawable.width);
+       box.y2 = h ? (box.y1 + h) : (pWin->drawable.y + pWin->drawable.height);
+
+       SAFE_REGION_INIT(pScreen, &tmpRegion, &box, 0);
+
+       REGION_INTERSECT(pScreen, &tmpRegion, &tmpRegion, &pWin->clipList);
+
+       ADD_TO_MODIFIED_REGION(pScreen, &tmpRegion);
+
+       REGION_UNINIT(pScreen, &tmpRegion);
+    }
+
+    (*pScreen->ClearToBackground) (pWin, x, y, w, h, generateExposures);
+
+    if (!generateExposures) {
+       SCHEDULE_FB_UPDATE(pScreen, prfb);
+    }
+
+    SCREEN_EPILOGUE(ClearToBackground,rfbClearToBackground);
+}
+
+/*
+ * RestoreAreas - just be safe here - the region being modified is the whole
+ * exposed region.
+ */
+
+RegionPtr
+rfbRestoreAreas (pWin, prgnExposed)
+    WindowPtr  pWin;
+    RegionPtr  prgnExposed;
+{
+    RegionPtr result;
+    SCREEN_PROLOGUE(pWin->drawable.pScreen,RestoreAreas);
+
+    TRC(("rfbRestoreAreas called\n"));
+
+    ADD_TO_MODIFIED_REGION(pScreen, prgnExposed);
+
+    result = (*pScreen->RestoreAreas) (pWin, prgnExposed);
+
+    SCHEDULE_FB_UPDATE(pScreen, prfb);
+
+    SCREEN_EPILOGUE(RestoreAreas,rfbRestoreAreas);
+
+    return result;
+}
+
+
+
+/****************************************************************************/
+/*
+ * GC funcs wrapper stuff
+ *
+ * We only really want to wrap the GC ops, but to do this we need to wrap
+ * ValidateGC and so all the other GC funcs must be wrapped as well.
+ */
+/****************************************************************************/
+
+#define GC_FUNC_PROLOGUE(pGC)                                          \
+    rfbGCPtr pGCPriv = (rfbGCPtr) (pGC)->devPrivates[rfbGCIndex].ptr;  \
+    (pGC)->funcs = pGCPriv->wrapFuncs;                                 \
+    if (pGCPriv->wrapOps)                                              \
+       (pGC)->ops = pGCPriv->wrapOps;
+
+#define GC_FUNC_EPILOGUE(pGC)          \
+    pGCPriv->wrapFuncs = (pGC)->funcs; \
+    (pGC)->funcs = &rfbGCFuncs;                \
+    if (pGCPriv->wrapOps) {            \
+       pGCPriv->wrapOps = (pGC)->ops;  \
+       (pGC)->ops = &rfbGCOps;         \
+    }
+
+
+/*
+ * ValidateGC - call the wrapped ValidateGC, then wrap the resulting GC ops if
+ * the drawing will be to a viewable window.
+ */
+
+static void
+rfbValidateGC (pGC, changes, pDrawable)
+    GCPtr      pGC;
+    unsigned long changes;
+    DrawablePtr        pDrawable;
+{
+    GC_FUNC_PROLOGUE(pGC);
+
+    TRC(("rfbValidateGC called\n"));
+
+    (*pGC->funcs->ValidateGC) (pGC, changes, pDrawable);
+    
+    pGCPriv->wrapOps = NULL;
+    if (pDrawable->type == DRAWABLE_WINDOW && ((WindowPtr)pDrawable)->viewable)
+    {
+       WindowPtr   pWin = (WindowPtr) pDrawable;
+       RegionPtr   pRegion = &pWin->clipList;
+
+       if (pGC->subWindowMode == IncludeInferiors)
+           pRegion = &pWin->borderClip;
+       if (REGION_NOTEMPTY(pDrawable->pScreen, pRegion)) {
+           pGCPriv->wrapOps = pGC->ops;
+           TRC(("rfbValidateGC: wrapped GC ops\n"));
+       }
+    }
+
+    GC_FUNC_EPILOGUE(pGC);
+}
+
+/*
+ * All other GC funcs simply unwrap the GC funcs and ops, call the wrapped
+ * function and then rewrap the funcs and ops.
+ */
+
+static void
+rfbChangeGC (pGC, mask)
+    GCPtr          pGC;
+    unsigned long   mask;
+{
+    GC_FUNC_PROLOGUE(pGC);
+    (*pGC->funcs->ChangeGC) (pGC, mask);
+    GC_FUNC_EPILOGUE(pGC);
+}
+
+static void
+rfbCopyGC (pGCSrc, mask, pGCDst)
+    GCPtr          pGCSrc, pGCDst;
+    unsigned long   mask;
+{
+    GC_FUNC_PROLOGUE(pGCDst);
+    (*pGCDst->funcs->CopyGC) (pGCSrc, mask, pGCDst);
+    GC_FUNC_EPILOGUE(pGCDst);
+}
+
+static void
+rfbDestroyGC (pGC)
+    GCPtr   pGC;
+{
+    GC_FUNC_PROLOGUE(pGC);
+    (*pGC->funcs->DestroyGC) (pGC);
+    GC_FUNC_EPILOGUE(pGC);
+}
+
+static void
+rfbChangeClip (pGC, type, pvalue, nrects)
+    GCPtr   pGC;
+    int                type;
+    pointer    pvalue;
+    int                nrects;
+{
+    GC_FUNC_PROLOGUE(pGC);
+    (*pGC->funcs->ChangeClip) (pGC, type, pvalue, nrects);
+    GC_FUNC_EPILOGUE(pGC);
+}
+
+static void
+rfbDestroyClip(pGC)
+    GCPtr      pGC;
+{
+    GC_FUNC_PROLOGUE(pGC);
+    (* pGC->funcs->DestroyClip)(pGC);
+    GC_FUNC_EPILOGUE(pGC);
+}
+
+static void
+rfbCopyClip(pgcDst, pgcSrc)
+    GCPtr pgcDst, pgcSrc;
+{
+    GC_FUNC_PROLOGUE(pgcDst);
+    (* pgcDst->funcs->CopyClip)(pgcDst, pgcSrc);
+    GC_FUNC_EPILOGUE(pgcDst);
+}
+
+
+/****************************************************************************/
+/*
+ * GC ops wrapper stuff
+ *
+ * Note that these routines will only have been wrapped for drawing to
+ * viewable windows so we don't need to check each time that the drawable
+ * is a viewable window.
+ */
+/****************************************************************************/
+
+#define GC_OP_PROLOGUE(pDrawable,pGC) \
+    rfbScreenInfoPtr prfb = &rfbScreen; \
+    rfbGCPtr pGCPrivate = (rfbGCPtr) (pGC)->devPrivates[rfbGCIndex].ptr; \
+    GCFuncs *oldFuncs = pGC->funcs; \
+    (pGC)->funcs = pGCPrivate->wrapFuncs; \
+    (pGC)->ops = pGCPrivate->wrapOps;
+
+#define GC_OP_EPILOGUE(pGC) \
+    pGCPrivate->wrapOps = (pGC)->ops; \
+    (pGC)->funcs = oldFuncs; \
+    (pGC)->ops = &rfbGCOps;
+
+
+/*
+ * FillSpans - being very safe - the region being modified is the border clip
+ * region of the window.
+ */
+
+static void
+rfbFillSpans(pDrawable, pGC, nInit, pptInit, pwidthInit, fSorted)
+    DrawablePtr pDrawable;
+    GCPtr      pGC;
+    int                nInit;                  /* number of spans to fill */
+    DDXPointPtr pptInit;               /* pointer to list of start points */
+    int                *pwidthInit;            /* pointer to list of n widths */
+    int        fSorted;
+{
+    GC_OP_PROLOGUE(pDrawable,pGC);
+
+    TRC(("rfbFillSpans called\n"));
+
+    ADD_TO_MODIFIED_REGION(pDrawable->pScreen,
+                          &((WindowPtr)pDrawable)->borderClip);
+
+    (*pGC->ops->FillSpans) (pDrawable, pGC, nInit, pptInit,pwidthInit,fSorted);
+
+    SCHEDULE_FB_UPDATE(pDrawable->pScreen, prfb);
+
+    GC_OP_EPILOGUE(pGC);
+}
+
+/*
+ * SetSpans - being very safe - the region being modified is the border clip
+ * region of the window.
+ */
+
+static void
+rfbSetSpans(pDrawable, pGC, psrc, ppt, pwidth, nspans, fSorted)
+    DrawablePtr                pDrawable;
+    GCPtr              pGC;
+    char               *psrc;
+    register DDXPointPtr ppt;
+    int                        *pwidth;
+    int                        nspans;
+    int                        fSorted;
+{
+    GC_OP_PROLOGUE(pDrawable,pGC);
+
+    TRC(("rfbSetSpans called\n"));
+
+    ADD_TO_MODIFIED_REGION(pDrawable->pScreen,
+                          &((WindowPtr)pDrawable)->borderClip);
+
+    (*pGC->ops->SetSpans) (pDrawable, pGC, psrc, ppt, pwidth, nspans, fSorted);
+
+    SCHEDULE_FB_UPDATE(pDrawable->pScreen, prfb);
+
+    GC_OP_EPILOGUE(pGC);
+}
+
+/*
+ * PutImage - the region being modified is the rectangle of the
+ * PutImage (clipped to the window clip region).
+ */
+
+static void
+rfbPutImage(pDrawable, pGC, depth, x, y, w, h, leftPad, format, pBits)
+    DrawablePtr          pDrawable;
+    GCPtr        pGC;
+    int                  depth;
+    int                  x;
+    int                  y;
+    int                  w;
+    int                  h;
+    int                  leftPad;
+    int                  format;
+    char         *pBits;
+{
+    RegionRec tmpRegion;
+    BoxRec box;
+    GC_OP_PROLOGUE(pDrawable, pGC);
+
+    TRC(("rfbPutImage called\n"));
+
+    box.x1 = x + pDrawable->x;
+    box.y1 = y + pDrawable->y;
+    box.x2 = box.x1 + w;
+    box.y2 = box.y1 + h;
+
+    SAFE_REGION_INIT(pDrawable->pScreen, &tmpRegion, &box, 0);
+
+    REGION_INTERSECT(pDrawable->pScreen, &tmpRegion, &tmpRegion,
+                    WINDOW_CLIP_REGION((WindowPtr)pDrawable,pGC));
+
+    ADD_TO_MODIFIED_REGION(pDrawable->pScreen, &tmpRegion);
+
+    REGION_UNINIT(pDrawable->pScreen, &tmpRegion);
+
+    (*pGC->ops->PutImage) (pDrawable, pGC, depth, x, y, w, h,
+                          leftPad, format, pBits);
+
+    SCHEDULE_FB_UPDATE(pDrawable->pScreen, prfb);
+
+    GC_OP_EPILOGUE(pGC);
+}
+
+/*
+ * CopyArea - the region being modified is the destination rectangle (clipped
+ * to the window clip region).
+ * If the client will accept CopyRect messages then use rfbCopyRegion
+ * to optimise the pending screen changes into a single "copy region" plus
+ * the ordinary modified region.
+ */
+
+static RegionPtr
+rfbCopyArea (pSrc, pDst, pGC, srcx, srcy, w, h, dstx, dsty)
+    DrawablePtr          pSrc;
+    DrawablePtr          pDst;
+    GCPtr        pGC;
+    int                  srcx;
+    int                  srcy;
+    int                  w;
+    int                  h;
+    int                  dstx;
+    int                  dsty;
+{
+    rfbClientPtr cl;
+    RegionPtr rgn;
+    RegionRec srcRegion, dstRegion;
+    BoxRec box;
+    GC_OP_PROLOGUE(pDst, pGC);
+
+    TRC(("rfbCopyArea called\n"));
+
+    box.x1 = dstx + pDst->x;
+    box.y1 = dsty + pDst->y;
+    box.x2 = box.x1 + w;
+    box.y2 = box.y1 + h;
+
+    SAFE_REGION_INIT(pDst->pScreen, &dstRegion, &box, 0);
+    REGION_INTERSECT(pDst->pScreen, &dstRegion, &dstRegion,
+                    WINDOW_CLIP_REGION((WindowPtr)pDst,pGC));
+
+    if ((pSrc->type == DRAWABLE_WINDOW) && (pSrc->pScreen == pDst->pScreen)) {
+       box.x1 = srcx + pSrc->x;
+       box.y1 = srcy + pSrc->y;
+       box.x2 = box.x1 + w;
+       box.y2 = box.y1 + h;
+
+       for (cl = rfbClientHead; cl; cl = cl->next) {
+           if (cl->useCopyRect) {
+               SAFE_REGION_INIT(pSrc->pScreen, &srcRegion, &box, 0);
+               REGION_INTERSECT(pSrc->pScreen, &srcRegion, &srcRegion,
+                                &((WindowPtr)pSrc)->clipList);
+
+               rfbCopyRegion(pSrc->pScreen, cl, &srcRegion, &dstRegion,
+                             dstx + pDst->x - srcx - pSrc->x,
+                             dsty + pDst->y - srcy - pSrc->y);
+
+               REGION_UNINIT(pSrc->pScreen, &srcRegion);
+
+           } else {
+
+               REGION_UNION(pScreen, &cl->modifiedRegion, &cl->modifiedRegion,
+                            &dstRegion);
+           }
+       }
+
+    } else {
+
+       ADD_TO_MODIFIED_REGION(pDst->pScreen, &dstRegion);
+    }
+
+    REGION_UNINIT(pDst->pScreen, &dstRegion);
+
+    rgn = (*pGC->ops->CopyArea) (pSrc, pDst, pGC, srcx, srcy, w, h,
+                                dstx, dsty);
+
+    SCHEDULE_FB_UPDATE(pDst->pScreen, prfb);
+
+    GC_OP_EPILOGUE(pGC);
+
+    return rgn;
+}
+
+
+/*
+ * CopyPlane - the region being modified is the destination rectangle (clipped
+ * to the window clip region).
+ */
+
+static RegionPtr
+rfbCopyPlane (pSrc, pDst, pGC, srcx, srcy, w, h, dstx, dsty, plane)
+    DrawablePtr          pSrc;
+    DrawablePtr          pDst;
+    register GCPtr pGC;
+    int          srcx,
+                 srcy;
+    int          w,
+                 h;
+    int          dstx,
+                 dsty;
+    unsigned long  plane;
+{
+    RegionPtr rgn;
+    RegionRec tmpRegion;
+    BoxRec box;
+    GC_OP_PROLOGUE(pDst, pGC);
+
+    TRC(("rfbCopyPlane called\n"));
+
+    box.x1 = dstx + pDst->x;
+    box.y1 = dsty + pDst->y;
+    box.x2 = box.x1 + w;
+    box.y2 = box.y1 + h;
+
+    SAFE_REGION_INIT(pDst->pScreen, &tmpRegion, &box, 0);
+
+    REGION_INTERSECT(pDst->pScreen, &tmpRegion, &tmpRegion,
+                    WINDOW_CLIP_REGION((WindowPtr)pDst,pGC));
+
+    ADD_TO_MODIFIED_REGION(pDst->pScreen, &tmpRegion);
+
+    REGION_UNINIT(pDst->pScreen, &tmpRegion);
+
+    rgn = (*pGC->ops->CopyPlane) (pSrc, pDst, pGC, srcx, srcy, w, h,
+                                 dstx, dsty, plane);
+
+    SCHEDULE_FB_UPDATE(pDst->pScreen, prfb);
+
+    GC_OP_EPILOGUE(pGC);
+
+    return rgn;
+}
+
+/*
+ * PolyPoint - find the smallest rectangle which encloses the points drawn
+ * (and clip).
+ */
+
+static void
+rfbPolyPoint (pDrawable, pGC, mode, npt, pts)
+    DrawablePtr pDrawable;
+    GCPtr      pGC;
+    int                mode;           /* Origin or Previous */
+    int                npt;
+    xPoint     *pts;
+{
+    int i;
+    RegionRec tmpRegion;
+    BoxRec box;
+    GC_OP_PROLOGUE(pDrawable, pGC);
+
+    TRC(("rfbPolyPoint called: %d points\n",npt));
+
+    if (npt) {
+       int minX = pts[0].x, maxX = pts[0].x;
+       int minY = pts[0].y, maxY = pts[0].y;
+
+       if (mode == CoordModePrevious)
+       {
+           int x = pts[0].x, y = pts[0].y;
+
+           for (i = 1; i < npt; i++) {
+               x += pts[i].x;
+               y += pts[i].y;
+               if (x < minX) minX = x;
+               if (x > maxX) maxX = x;
+               if (y < minY) minY = y;
+               if (y > maxY) maxY = y;
+           }
+       }
+       else
+       {
+           for (i = 1; i < npt; i++) {
+               if (pts[i].x < minX) minX = pts[i].x;
+               if (pts[i].x > maxX) maxX = pts[i].x;
+               if (pts[i].y < minY) minY = pts[i].y;
+               if (pts[i].y > maxY) maxY = pts[i].y;
+           }
+       }
+
+       box.x1 = minX + pDrawable->x;
+       box.y1 = minY + pDrawable->y;
+       box.x2 = maxX + 1 + pDrawable->x;
+       box.y2 = maxY + 1 + pDrawable->y;
+
+       SAFE_REGION_INIT(pDrawable->pScreen, &tmpRegion, &box, 0);
+
+       REGION_INTERSECT(pDrawable->pScreen, &tmpRegion, &tmpRegion,
+                        WINDOW_CLIP_REGION(((WindowPtr)pDrawable),pGC));
+
+       ADD_TO_MODIFIED_REGION(pDrawable->pScreen, &tmpRegion);
+
+       REGION_UNINIT(pDrawable->pScreen, &tmpRegion);
+    }
+
+    (*pGC->ops->PolyPoint) (pDrawable, pGC, mode, npt, pts);
+
+    if (npt) {
+       SCHEDULE_FB_UPDATE(pDrawable->pScreen, prfb);
+    }
+
+    GC_OP_EPILOGUE(pGC);
+}
+
+/*
+ * PolyLines - take the union of bounding boxes around each line (and clip).
+ */
+
+static void
+rfbPolylines (pDrawable, pGC, mode, npt, ppts)
+    DrawablePtr          pDrawable;
+    GCPtr        pGC;
+    int                  mode;
+    int                  npt;
+    DDXPointPtr          ppts;
+{
+    RegionPtr tmpRegion;
+    xRectangle regRects[MAX_RECTS_PER_OP];
+    int i, extra, nregRects, lw;
+    int prevX, prevY, curX, curY;
+    int rectX1, rectY1, rectX2, rectY2;
+    int minX, minY, maxX, maxY;
+    GC_OP_PROLOGUE(pDrawable, pGC);
+
+    TRC(("rfbPolylines called: %d points\n",npt));
+
+    if (npt) {
+       lw = pGC->lineWidth;
+       if (lw == 0)
+           lw = 1;
+
+       if (npt == 1)
+       {
+           nregRects = 1;
+           regRects[0].x = ppts[0].x - lw + pDrawable->x; /* being safe */
+           regRects[0].y = ppts[0].y - lw + pDrawable->y;
+           regRects[0].width = 2*lw;
+           regRects[0].height = 2*lw;
+       }
+       else
+       {
+           nregRects = npt - 1;
+
+           /*
+            * mitered joins can project quite a way from
+            * the line end; the 11 degree miter limit limits
+            * this extension to lw / (2 * tan(11/2)), rounded up
+            * and converted to int yields 6 * lw
+            */
+
+           if (pGC->joinStyle == JoinMiter) {
+               extra = 6 * lw;
+           } else {
+               extra = lw / 2;
+           }
+
+           prevX = ppts[0].x + pDrawable->x;
+           prevY = ppts[0].y + pDrawable->y;
+            minX = maxX = prevX;
+            minY = maxY = prevY;
+
+           for (i = 0; i < nregRects; i++) {
+               if (mode == CoordModeOrigin) {
+                   curX = pDrawable->x + ppts[i+1].x;
+                   curY = pDrawable->y + ppts[i+1].y;
+               } else {
+                   curX = prevX + ppts[i+1].x;
+                   curY = prevY + ppts[i+1].y;
+               }
+
+               if (prevX > curX) {
+                    rectX1 = curX - extra;
+                    rectX2 = prevX + extra + 1;
+               } else {
+                    rectX1 = prevX - extra;
+                    rectX2 = curX + extra + 1;
+               }
+
+               if (prevY > curY) {
+                    rectY1 = curY - extra;
+                    rectY2 = prevY + extra + 1;
+               } else {
+                    rectY1 = prevY - extra;
+                    rectY2 = curY + extra + 1;
+               }
+
+                if (nregRects <= MAX_RECTS_PER_OP) {
+                   regRects[i].x = rectX1;
+                   regRects[i].y = rectY1;
+                   regRects[i].width = rectX2 - rectX1;
+                   regRects[i].height = rectY2 - rectY1;
+                } else {
+                    if (rectX1 < minX) minX = rectX1;
+                    if (rectY1 < minY) minY = rectY1;
+                    if (rectX2 > maxX) maxX = rectX2;
+                    if (rectY2 > maxY) maxY = rectY2;
+                }
+
+               prevX = curX;
+               prevY = curY;
+           }
+
+            if (nregRects > MAX_RECTS_PER_OP) {
+                regRects[0].x = minX;
+                regRects[0].y = minY;
+                regRects[0].width = maxX - minX;
+                regRects[0].height = maxY - minY;
+                nregRects = 1;
+            }
+       }
+
+       tmpRegion = RECTS_TO_REGION(pDrawable->pScreen, nregRects, regRects,
+                                    CT_NONE);
+       REGION_INTERSECT(pDrawable->pScreen, tmpRegion, tmpRegion,
+                        WINDOW_CLIP_REGION((WindowPtr)pDrawable,pGC));
+
+       ADD_TO_MODIFIED_REGION(pDrawable->pScreen, tmpRegion);
+
+       REGION_DESTROY(pDrawable->pScreen, tmpRegion);
+    }
+
+    (*pGC->ops->Polylines) (pDrawable, pGC, mode, npt, ppts);
+
+    if (npt) {
+       SCHEDULE_FB_UPDATE(pDrawable->pScreen, prfb);
+    }
+
+    GC_OP_EPILOGUE(pGC);
+}
+
+/*
+ * PolySegment - take the union of bounding boxes around each segment (and
+ * clip).
+ */
+
+static void
+rfbPolySegment(pDrawable, pGC, nseg, segs)
+    DrawablePtr pDrawable;
+    GCPtr      pGC;
+    int                nseg;
+    xSegment   *segs;
+{
+    RegionPtr tmpRegion;
+    xRectangle regRects[MAX_RECTS_PER_OP];
+    int i, extra, lw, nregRects;
+    int rectX1, rectY1, rectX2, rectY2;
+    int minX, minY, maxX, maxY;
+
+    GC_OP_PROLOGUE(pDrawable, pGC);
+
+    TRC(("rfbPolySegment called: %d segments\n",nseg));
+
+    if (nseg) {
+        nregRects = nseg;
+       lw = pGC->lineWidth;
+       extra = lw / 2;
+
+        minX = maxX = segs[0].x1;
+        minY = maxY = segs[0].y1;
+
+       for (i = 0; i < nseg; i++)
+       {
+           if (segs[i].x1 > segs[i].x2) {
+                rectX1 = pDrawable->x + segs[i].x2 - extra;
+                rectX2 = pDrawable->x + segs[i].x1 + extra + 1;
+           } else {
+                rectX1 = pDrawable->x + segs[i].x1 - extra;
+                rectX2 = pDrawable->x + segs[i].x2 + extra + 1;
+           }
+
+           if (segs[i].y1 > segs[i].y2) {
+                rectY1 = pDrawable->y + segs[i].y2 - extra;
+                rectY2 = pDrawable->y + segs[i].y1 + extra + 1;
+           } else {
+                rectY1 = pDrawable->y + segs[i].y1 - extra;
+                rectY2 = pDrawable->y + segs[i].y2 + extra + 1;
+           }
+
+            if (nseg <= MAX_RECTS_PER_OP) {
+                regRects[i].x = rectX1;
+                regRects[i].y = rectY1;
+                regRects[i].width = rectX2 - rectX1;
+                regRects[i].height = rectY2 - rectY1;
+            } else {
+                if (rectX1 < minX) minX = rectX1;
+                if (rectY1 < minY) minY = rectY1;
+                if (rectX2 > maxX) maxX = rectX2;
+                if (rectY2 > maxY) maxY = rectY2;
+            }
+       }
+
+        if (nseg > MAX_RECTS_PER_OP) {
+            regRects[0].x = minX;
+            regRects[0].y = minY;
+            regRects[0].width = maxX - minX;
+            regRects[0].height = maxY - minY;
+            nregRects = 1;
+        }
+
+       tmpRegion = RECTS_TO_REGION(pDrawable->pScreen, nregRects, regRects,
+                                    CT_NONE);
+       REGION_INTERSECT(pDrawable->pScreen, tmpRegion, tmpRegion,
+                        WINDOW_CLIP_REGION((WindowPtr)pDrawable,pGC));
+
+       ADD_TO_MODIFIED_REGION(pDrawable->pScreen, tmpRegion);
+
+       REGION_DESTROY(pDrawable->pScreen, tmpRegion);
+    }
+
+    (*pGC->ops->PolySegment) (pDrawable, pGC, nseg, segs);
+
+    if (nseg) {
+       SCHEDULE_FB_UPDATE(pDrawable->pScreen, prfb);
+    }
+
+    GC_OP_EPILOGUE(pGC);
+}
+
+/*
+ * PolyRectangle (rectangle outlines) - take the union of bounding boxes
+ * around each line (and clip).
+ */
+
+static void
+rfbPolyRectangle(pDrawable, pGC, nrects, rects)
+    DrawablePtr        pDrawable;
+    GCPtr      pGC;
+    int                nrects;
+    xRectangle *rects;
+{
+    int i, extra, lw, nregRects;
+    int rectX1, rectY1, rectX2, rectY2;
+    int minX, minY, maxX, maxY;
+    RegionPtr tmpRegion;
+    xRectangle regRects[MAX_RECTS_PER_OP*4];
+    GC_OP_PROLOGUE(pDrawable, pGC);
+
+    TRC(("rfbPolyRectangle called: %d rects\n",nrects));
+
+    if (nrects) {
+        nregRects = nrects * 4;
+       lw = pGC->lineWidth;
+       extra = lw / 2;
+
+        minX = maxX = rects[0].x;
+        minY = maxY = rects[0].y;
+
+       for (i = 0; i < nrects; i++)
+       {
+            if (nrects <= MAX_RECTS_PER_OP) {
+                regRects[i*4].x = rects[i].x - extra + pDrawable->x;
+                regRects[i*4].y = rects[i].y - extra + pDrawable->y;
+                regRects[i*4].width = rects[i].width + 1 + 2 * extra;
+                regRects[i*4].height = 1 + 2 * extra;
+
+                regRects[i*4+1].x = rects[i].x - extra + pDrawable->x;
+                regRects[i*4+1].y = rects[i].y - extra + pDrawable->y;
+                regRects[i*4+1].width = 1 + 2 * extra;
+                regRects[i*4+1].height = rects[i].height + 1 + 2 * extra;
+
+                regRects[i*4+2].x
+                    = rects[i].x + rects[i].width - extra + pDrawable->x;
+                regRects[i*4+2].y = rects[i].y - extra + pDrawable->y;
+                regRects[i*4+2].width = 1 + 2 * extra;
+                regRects[i*4+2].height = rects[i].height + 1 + 2 * extra;
+
+                regRects[i*4+3].x = rects[i].x - extra + pDrawable->x;
+                regRects[i*4+3].y
+                    = rects[i].y + rects[i].height - extra + pDrawable->y;
+                regRects[i*4+3].width = rects[i].width + 1 + 2 * extra;
+                regRects[i*4+3].height = 1 + 2 * extra;
+            } else {
+                rectX1 = pDrawable->x + rects[i].x - extra;
+                rectY1 = pDrawable->y + rects[i].y - extra;
+                rectX2 = pDrawable->x + rects[i].x + rects[i].width + extra+1;
+                rectY2 = pDrawable->y + rects[i].y + rects[i].height + extra+1;
+                if (rectX1 < minX) minX = rectX1;
+                if (rectY1 < minY) minY = rectY1;
+                if (rectX2 > maxX) maxX = rectX2;
+                if (rectY2 > maxY) maxY = rectY2;
+            }
+       }
+
+        if (nrects > MAX_RECTS_PER_OP) {
+            regRects[0].x = minX;
+            regRects[0].y = minY;
+            regRects[0].width = maxX - minX;
+            regRects[0].height = maxY - minY;
+            nregRects = 1;
+        }
+
+       tmpRegion = RECTS_TO_REGION(pDrawable->pScreen, nregRects,
+                                   regRects, CT_NONE);
+       REGION_INTERSECT(pDrawable->pScreen, tmpRegion, tmpRegion,
+                        WINDOW_CLIP_REGION((WindowPtr)pDrawable,pGC));
+
+       ADD_TO_MODIFIED_REGION(pDrawable->pScreen, tmpRegion);
+
+       REGION_DESTROY(pDrawable->pScreen, tmpRegion);
+    }
+
+    (*pGC->ops->PolyRectangle) (pDrawable, pGC, nrects, rects);
+
+    if (nrects) {
+       SCHEDULE_FB_UPDATE(pDrawable->pScreen, prfb);
+    }
+
+    GC_OP_EPILOGUE(pGC);
+}
+
+/*
+ * PolyArc - take the union of bounding boxes around each arc (and clip).
+ * Bounding boxes assume each is a full circle / ellipse.
+ */
+
+static void
+rfbPolyArc(pDrawable, pGC, narcs, arcs)
+    DrawablePtr        pDrawable;
+    register GCPtr     pGC;
+    int                narcs;
+    xArc       *arcs;
+{
+    int i, extra, lw, nregRects;
+    int rectX1, rectY1, rectX2, rectY2;
+    int minX, minY, maxX, maxY;
+    RegionPtr tmpRegion;
+    xRectangle regRects[MAX_RECTS_PER_OP];
+    GC_OP_PROLOGUE(pDrawable, pGC);
+
+    TRC(("rfbPolyArc called: %d arcs\n",narcs));
+
+    if (narcs) {
+        nregRects = narcs;
+       lw = pGC->lineWidth;
+       if (lw == 0)
+           lw = 1;
+       extra = lw / 2;
+
+        minX = maxX = arcs[0].x;
+        minY = maxY = arcs[0].y;
+
+       for (i = 0; i < narcs; i++)
+       {
+            if (narcs <= MAX_RECTS_PER_OP) {
+                regRects[i].x = arcs[i].x - extra + pDrawable->x;
+                regRects[i].y = arcs[i].y - extra + pDrawable->y;
+                regRects[i].width = arcs[i].width + lw;
+                regRects[i].height = arcs[i].height + lw;
+            } else {
+                rectX1 = pDrawable->x + arcs[i].x - extra;
+                rectY1 = pDrawable->y + arcs[i].y - extra;
+                rectX2 = pDrawable->x + arcs[i].x + arcs[i].width + lw;
+                rectY2 = pDrawable->y + arcs[i].y + arcs[i].height + lw;
+                if (rectX1 < minX) minX = rectX1;
+                if (rectY1 < minY) minY = rectY1;
+                if (rectX2 > maxX) maxX = rectX2;
+                if (rectY2 > maxY) maxY = rectY2;
+            }
+       }
+
+        if (narcs > MAX_RECTS_PER_OP) {
+            regRects[0].x = minX;
+            regRects[0].y = minY;
+            regRects[0].width = maxX - minX;
+            regRects[0].height = maxY - minY;
+            nregRects = 1;
+        }
+
+       tmpRegion = RECTS_TO_REGION(pDrawable->pScreen, nregRects, regRects,
+                                    CT_NONE);
+       REGION_INTERSECT(pDrawable->pScreen, tmpRegion, tmpRegion,
+                        WINDOW_CLIP_REGION((WindowPtr)pDrawable,pGC));
+
+       ADD_TO_MODIFIED_REGION(pDrawable->pScreen, tmpRegion);
+
+       REGION_DESTROY(pDrawable->pScreen, tmpRegion);
+    }
+
+    (*pGC->ops->PolyArc) (pDrawable, pGC, narcs, arcs);
+
+    if (narcs) {
+       SCHEDULE_FB_UPDATE(pDrawable->pScreen, prfb);
+    }
+
+    GC_OP_EPILOGUE(pGC);
+}
+
+/*
+ * FillPolygon - take bounding box around polygon (and clip).
+ */
+
+static void
+rfbFillPolygon(pDrawable, pGC, shape, mode, count, pts)
+    register DrawablePtr pDrawable;
+    register GCPtr     pGC;
+    int                        shape, mode;
+    int                        count;
+    DDXPointPtr                pts;
+{
+    int i;
+    RegionRec tmpRegion;
+    BoxRec box;
+    GC_OP_PROLOGUE(pDrawable, pGC);
+
+    TRC(("rfbFillPolygon called\n"));
+
+    if (count) {
+       int minX = pts[0].x, maxX = pts[0].x;
+       int minY = pts[0].y, maxY = pts[0].y;
+
+       if (mode == CoordModePrevious)
+       {
+           int x = pts[0].x, y = pts[0].y;
+
+           for (i = 1; i < count; i++) {
+               x += pts[i].x;
+               y += pts[i].y;
+               if (x < minX) minX = x;
+               if (x > maxX) maxX = x;
+               if (y < minY) minY = y;
+               if (y > maxY) maxY = y;
+           }
+       }
+       else
+       {
+           for (i = 1; i < count; i++) {
+               if (pts[i].x < minX) minX = pts[i].x;
+               if (pts[i].x > maxX) maxX = pts[i].x;
+               if (pts[i].y < minY) minY = pts[i].y;
+               if (pts[i].y > maxY) maxY = pts[i].y;
+           }
+       }
+
+       box.x1 = minX + pDrawable->x;
+       box.y1 = minY + pDrawable->y;
+       box.x2 = maxX + 1 + pDrawable->x;
+       box.y2 = maxY + 1 + pDrawable->y;
+
+       SAFE_REGION_INIT(pDrawable->pScreen, &tmpRegion, &box, 0);
+
+       REGION_INTERSECT(pDrawable->pScreen, &tmpRegion, &tmpRegion,
+                        WINDOW_CLIP_REGION(((WindowPtr)pDrawable),pGC));
+
+       ADD_TO_MODIFIED_REGION(pDrawable->pScreen, &tmpRegion);
+
+       REGION_UNINIT(pDrawable->pScreen, &tmpRegion);
+    }
+
+    (*pGC->ops->FillPolygon) (pDrawable, pGC, shape, mode, count, pts);
+
+    if (count) {
+       SCHEDULE_FB_UPDATE(pDrawable->pScreen, prfb);
+    }
+
+    GC_OP_EPILOGUE(pGC);
+}
+
+/*
+ * PolyFillRect - take the union of the given rectangles (and clip).
+ */
+
+static void
+rfbPolyFillRect(pDrawable, pGC, nrects, rects)
+    DrawablePtr pDrawable;
+    GCPtr      pGC;
+    int                nrects;
+    xRectangle *rects;
+{
+    RegionPtr tmpRegion;
+    xRectangle regRects[MAX_RECTS_PER_OP];
+    int i, nregRects;
+    int rectX1, rectY1, rectX2, rectY2;
+    int minX, minY, maxX, maxY;
+    GC_OP_PROLOGUE(pDrawable, pGC);
+
+    TRC(("rfbPolyFillRect called: %d rects\n",nrects));
+
+    if (nrects) {
+        nregRects = nrects;
+
+        minX = maxX = rects[0].x;
+        minY = maxY = rects[0].y;
+
+       for (i = 0; i < nrects; i++) {
+            if (nrects <= MAX_RECTS_PER_OP) {
+                regRects[i].x = rects[i].x + pDrawable->x;
+                regRects[i].y = rects[i].y + pDrawable->y;
+                regRects[i].width = rects[i].width;
+                regRects[i].height = rects[i].height;
+            } else {
+                rectX1 = pDrawable->x + rects[i].x;
+                rectY1 = pDrawable->y + rects[i].y;
+                rectX2 = pDrawable->x + rects[i].x + rects[i].width;
+                rectY2 = pDrawable->y + rects[i].y + rects[i].height;
+                if (rectX1 < minX) minX = rectX1;
+                if (rectY1 < minY) minY = rectY1;
+                if (rectX2 > maxX) maxX = rectX2;
+                if (rectY2 > maxY) maxY = rectY2;
+            }
+       }
+
+        if (nrects > MAX_RECTS_PER_OP) {
+            regRects[0].x = minX;
+            regRects[0].y = minY;
+            regRects[0].width = maxX - minX;
+            regRects[0].height = maxY - minY;
+            nregRects = 1;
+        }
+
+       tmpRegion = RECTS_TO_REGION(pDrawable->pScreen, nregRects, regRects,
+                                   CT_NONE);
+       REGION_INTERSECT(pDrawable->pScreen, tmpRegion, tmpRegion,
+                        WINDOW_CLIP_REGION((WindowPtr)pDrawable,pGC));
+
+       ADD_TO_MODIFIED_REGION(pDrawable->pScreen, tmpRegion);
+
+       REGION_DESTROY(pDrawable->pScreen, tmpRegion);
+    }
+
+    (*pGC->ops->PolyFillRect) (pDrawable, pGC, nrects, rects);
+
+    if (nrects) {
+       SCHEDULE_FB_UPDATE(pDrawable->pScreen, prfb);
+    }
+
+    GC_OP_EPILOGUE(pGC);
+}
+
+/*
+ * PolyFillArc - take the union of bounding boxes around each arc (and clip).
+ * Bounding boxes assume each is a full circle / ellipse.
+ */
+
+static void
+rfbPolyFillArc(pDrawable, pGC, narcs, arcs)
+    DrawablePtr        pDrawable;
+    GCPtr      pGC;
+    int                narcs;
+    xArc       *arcs;
+{
+    int i, extra, lw, nregRects;
+    int rectX1, rectY1, rectX2, rectY2;
+    int minX, minY, maxX, maxY;
+    RegionPtr tmpRegion;
+    xRectangle regRects[MAX_RECTS_PER_OP];
+    GC_OP_PROLOGUE(pDrawable, pGC);
+
+    TRC(("rfbPolyFillArc called: %d arcs\n",narcs));
+
+    if (narcs) {
+        nregRects = narcs;
+       lw = pGC->lineWidth;
+       if (lw == 0)
+           lw = 1;
+       extra = lw / 2;
+
+        minX = maxX = arcs[0].x;
+        minY = maxY = arcs[0].y;
+
+       for (i = 0; i < narcs; i++)
+       {
+            if (narcs <= MAX_RECTS_PER_OP) {
+                regRects[i].x = arcs[i].x - extra + pDrawable->x;
+                regRects[i].y = arcs[i].y - extra + pDrawable->y;
+                regRects[i].width = arcs[i].width + lw;
+                regRects[i].height = arcs[i].height + lw;
+            } else {
+                rectX1 = pDrawable->x + arcs[i].x - extra;
+                rectY1 = pDrawable->y + arcs[i].y - extra;
+                rectX2 = pDrawable->x + arcs[i].x + arcs[i].width + lw;
+                rectY2 = pDrawable->y + arcs[i].y + arcs[i].height + lw;
+                if (rectX1 < minX) minX = rectX1;
+                if (rectY1 < minY) minY = rectY1;
+                if (rectX2 > maxX) maxX = rectX2;
+                if (rectY2 > maxY) maxY = rectY2;
+            }
+       }
+
+        if (narcs > MAX_RECTS_PER_OP) {
+            regRects[0].x = minX;
+            regRects[0].y = minY;
+            regRects[0].width = maxX - minX;
+            regRects[0].height = maxY - minY;
+            nregRects = 1;
+        }
+
+       tmpRegion = RECTS_TO_REGION(pDrawable->pScreen, nregRects, regRects,
+                                    CT_NONE);
+       REGION_INTERSECT(pDrawable->pScreen, tmpRegion, tmpRegion,
+                        WINDOW_CLIP_REGION((WindowPtr)pDrawable,pGC));
+
+       ADD_TO_MODIFIED_REGION(pDrawable->pScreen, tmpRegion);
+
+       REGION_DESTROY(pDrawable->pScreen, tmpRegion);
+    }
+
+    (*pGC->ops->PolyFillArc) (pDrawable, pGC, narcs, arcs);
+
+    if (narcs) {
+       SCHEDULE_FB_UPDATE(pDrawable->pScreen, prfb);
+    }
+
+    GC_OP_EPILOGUE(pGC);
+}
+
+/*
+ * Get a rough bounding box around n characters of the given font.
+ */
+
+static void GetTextBoundingBox(pDrawable, font, x, y, n, pbox)
+    DrawablePtr pDrawable;
+    FontPtr font;
+    int x, y, n;
+    BoxPtr pbox;
+{
+    int maxAscent, maxDescent, maxCharWidth;
+
+    if (FONTASCENT(font) > FONTMAXBOUNDS(font,ascent))
+       maxAscent = FONTASCENT(font);
+    else
+       maxAscent = FONTMAXBOUNDS(font,ascent);
+
+    if (FONTDESCENT(font) > FONTMAXBOUNDS(font,descent))
+       maxDescent = FONTDESCENT(font);
+    else
+       maxDescent = FONTMAXBOUNDS(font,descent);
+
+    if (FONTMAXBOUNDS(font,rightSideBearing) > FONTMAXBOUNDS(font,characterWidth))
+       maxCharWidth = FONTMAXBOUNDS(font,rightSideBearing);
+    else
+       maxCharWidth = FONTMAXBOUNDS(font,characterWidth);
+
+    pbox->x1 = pDrawable->x + x;
+    pbox->y1 = pDrawable->y + y - maxAscent;
+    pbox->x2 = pbox->x1 + maxCharWidth * n;
+    pbox->y2 = pbox->y1 + maxAscent + maxDescent;
+
+    if (FONTMINBOUNDS(font,leftSideBearing) < 0) {
+       pbox->x1 += FONTMINBOUNDS(font,leftSideBearing);
+    }
+}
+
+
+/*
+ * PolyText8 - use rough bounding box.
+ */
+
+static int
+rfbPolyText8(pDrawable, pGC, x, y, count, chars)
+    DrawablePtr pDrawable;
+    GCPtr      pGC;
+    int                x, y;
+    int        count;
+    char       *chars;
+{
+    int        ret;
+    RegionRec tmpRegion;
+    BoxRec box;
+    GC_OP_PROLOGUE(pDrawable, pGC);
+
+    TRC(("rfbPolyText8 called '%.*s'\n",count,chars));
+
+    if (count) {
+       GetTextBoundingBox(pDrawable, pGC->font, x, y, count, &box);
+
+       SAFE_REGION_INIT(pDrawable->pScreen, &tmpRegion, &box, 0);
+
+       REGION_INTERSECT(pDrawable->pScreen, &tmpRegion, &tmpRegion,
+                        WINDOW_CLIP_REGION(((WindowPtr)pDrawable),pGC));
+
+       ADD_TO_MODIFIED_REGION(pDrawable->pScreen, &tmpRegion);
+
+       REGION_UNINIT(pDrawable->pScreen, &tmpRegion);
+    }
+
+    ret = (*pGC->ops->PolyText8) (pDrawable, pGC, x, y, count, chars);
+
+    if (count) {
+       SCHEDULE_FB_UPDATE(pDrawable->pScreen, prfb);
+    }
+
+    GC_OP_EPILOGUE(pGC);
+    return ret;
+}
+
+/*
+ * PolyText16 - use rough bounding box.
+ */
+
+static int
+rfbPolyText16(pDrawable, pGC, x, y, count, chars)
+    DrawablePtr pDrawable;
+    GCPtr      pGC;
+    int                x, y;
+    int                count;
+    unsigned short *chars;
+{
+    int        ret;
+    RegionRec tmpRegion;
+    BoxRec box;
+    GC_OP_PROLOGUE(pDrawable, pGC);
+
+    TRC(("rfbPolyText16 called\n"));
+
+    if (count) {
+       GetTextBoundingBox(pDrawable, pGC->font, x, y, count, &box);
+
+       SAFE_REGION_INIT(pDrawable->pScreen, &tmpRegion, &box, 0);
+
+       REGION_INTERSECT(pDrawable->pScreen, &tmpRegion, &tmpRegion,
+                        WINDOW_CLIP_REGION(((WindowPtr)pDrawable),pGC));
+
+       ADD_TO_MODIFIED_REGION(pDrawable->pScreen, &tmpRegion);
+
+       REGION_UNINIT(pDrawable->pScreen, &tmpRegion);
+    }
+
+    ret = (*pGC->ops->PolyText16) (pDrawable, pGC, x, y, count, chars);
+
+    if (count) {
+       SCHEDULE_FB_UPDATE(pDrawable->pScreen, prfb);
+    }
+
+    GC_OP_EPILOGUE(pGC);
+    return ret;
+}
+
+/*
+ * ImageText8 - use rough bounding box.
+ */
+
+static void
+rfbImageText8(pDrawable, pGC, x, y, count, chars)
+    DrawablePtr pDrawable;
+    GCPtr      pGC;
+    int                x, y;
+    int                count;
+    char       *chars;
+{
+    RegionRec tmpRegion;
+    BoxRec box;
+    GC_OP_PROLOGUE(pDrawable, pGC);
+
+    TRC(("rfbImageText8 called '%.*s'\n",count,chars));
+
+    if (count) {
+       GetTextBoundingBox(pDrawable, pGC->font, x, y, count, &box);
+
+       SAFE_REGION_INIT(pDrawable->pScreen, &tmpRegion, &box, 0);
+
+       REGION_INTERSECT(pDrawable->pScreen, &tmpRegion, &tmpRegion,
+                        WINDOW_CLIP_REGION(((WindowPtr)pDrawable),pGC));
+
+       ADD_TO_MODIFIED_REGION(pDrawable->pScreen, &tmpRegion);
+
+       REGION_UNINIT(pDrawable->pScreen, &tmpRegion);
+    }
+
+    (*pGC->ops->ImageText8) (pDrawable, pGC, x, y, count, chars);
+
+    if (count) {
+       SCHEDULE_FB_UPDATE(pDrawable->pScreen, prfb);
+    }
+
+    GC_OP_EPILOGUE(pGC);
+}
+
+/*
+ * ImageText16 - use rough bounding box.
+ */
+
+static void
+rfbImageText16(pDrawable, pGC, x, y, count, chars)
+    DrawablePtr pDrawable;
+    GCPtr      pGC;
+    int                x, y;
+    int                count;
+    unsigned short *chars;
+{
+    RegionRec tmpRegion;
+    BoxRec box;
+    GC_OP_PROLOGUE(pDrawable, pGC);
+
+    TRC(("rfbImageText16 called\n"));
+
+    if (count) {
+       GetTextBoundingBox(pDrawable, pGC->font, x, y, count, &box);
+
+       SAFE_REGION_INIT(pDrawable->pScreen, &tmpRegion, &box, 0);
+
+       REGION_INTERSECT(pDrawable->pScreen, &tmpRegion, &tmpRegion,
+                        WINDOW_CLIP_REGION(((WindowPtr)pDrawable),pGC));
+
+       ADD_TO_MODIFIED_REGION(pDrawable->pScreen, &tmpRegion);
+
+       REGION_UNINIT(pDrawable->pScreen, &tmpRegion);
+    }
+
+    (*pGC->ops->ImageText16) (pDrawable, pGC, x, y, count, chars);
+
+    if (count) {
+       SCHEDULE_FB_UPDATE(pDrawable->pScreen, prfb);
+    }
+
+    GC_OP_EPILOGUE(pGC);
+}
+
+/*
+ * ImageGlyphBlt - use rough bounding box.
+ */
+
+static void
+rfbImageGlyphBlt(pDrawable, pGC, x, y, nglyph, ppci, pglyphBase)
+    DrawablePtr pDrawable;
+    GCPtr      pGC;
+    int        x, y;
+    unsigned int nglyph;
+    CharInfoPtr *ppci;         /* array of character info */
+    pointer    pglyphBase;     /* start of array of glyphs */
+{
+    RegionRec tmpRegion;
+    BoxRec box;
+    GC_OP_PROLOGUE(pDrawable, pGC);
+
+    TRC(("rfbImageGlyphBlt called\n"));
+
+    if (nglyph) {
+       GetTextBoundingBox(pDrawable, pGC->font, x, y, nglyph, &box);
+
+       SAFE_REGION_INIT(pDrawable->pScreen, &tmpRegion, &box, 0);
+
+       REGION_INTERSECT(pDrawable->pScreen, &tmpRegion, &tmpRegion,
+                        WINDOW_CLIP_REGION(((WindowPtr)pDrawable),pGC));
+
+       ADD_TO_MODIFIED_REGION(pDrawable->pScreen, &tmpRegion);
+
+       REGION_UNINIT(pDrawable->pScreen, &tmpRegion);
+    }
+
+    (*pGC->ops->ImageGlyphBlt) (pDrawable, pGC, x, y, nglyph, ppci,pglyphBase);
+
+    if (nglyph) {
+       SCHEDULE_FB_UPDATE(pDrawable->pScreen, prfb);
+    }
+
+    GC_OP_EPILOGUE(pGC);
+}
+
+/*
+ * PolyGlyphBlt - use rough bounding box.
+ */
+
+static void
+rfbPolyGlyphBlt(pDrawable, pGC, x, y, nglyph, ppci, pglyphBase)
+    DrawablePtr pDrawable;
+    GCPtr      pGC;
+    int        x, y;
+    unsigned int nglyph;
+    CharInfoPtr *ppci;         /* array of character info */
+    pointer    pglyphBase;     /* start of array of glyphs */
+{
+    RegionRec tmpRegion;
+    BoxRec box;
+    GC_OP_PROLOGUE(pDrawable, pGC);
+
+    TRC(("rfbPolyGlyphBlt called\n"));
+
+    if (nglyph) {
+       GetTextBoundingBox(pDrawable, pGC->font, x, y, nglyph, &box);
+
+       SAFE_REGION_INIT(pDrawable->pScreen, &tmpRegion, &box, 0);
+
+       REGION_INTERSECT(pDrawable->pScreen, &tmpRegion, &tmpRegion,
+                        WINDOW_CLIP_REGION(((WindowPtr)pDrawable),pGC));
+
+       ADD_TO_MODIFIED_REGION(pDrawable->pScreen, &tmpRegion);
+
+       REGION_UNINIT(pDrawable->pScreen, &tmpRegion);
+    }
+
+    (*pGC->ops->PolyGlyphBlt) (pDrawable, pGC, x, y, nglyph, ppci, pglyphBase);
+
+    if (nglyph) {
+       SCHEDULE_FB_UPDATE(pDrawable->pScreen, prfb);
+    }
+
+    GC_OP_EPILOGUE(pGC);
+}
+
+/*
+ * PushPixels - be fairly safe - region modified is intersection of the given
+ * rectangle with the window clip region.
+ */
+
+static void
+rfbPushPixels(pGC, pBitMap, pDrawable, w, h, x, y)
+    GCPtr      pGC;
+    PixmapPtr  pBitMap;
+    DrawablePtr pDrawable;
+    int                w, h, x, y;
+{
+    RegionRec tmpRegion;
+    BoxRec box;
+    GC_OP_PROLOGUE(pDrawable, pGC);
+
+    TRC(("rfbPushPixels called\n"));
+
+    box.x1 = x + pDrawable->x;
+    box.y1 = y + pDrawable->y;
+    box.x2 = box.x1 + w;
+    box.y2 = box.y1 + h;
+
+    SAFE_REGION_INIT(pDrawable->pScreen, &tmpRegion, &box, 0);
+
+    REGION_INTERSECT(pDrawable->pScreen, &tmpRegion, &tmpRegion,
+                    WINDOW_CLIP_REGION(((WindowPtr)pDrawable),pGC));
+
+    ADD_TO_MODIFIED_REGION(pDrawable->pScreen, &tmpRegion);
+
+    REGION_UNINIT(pDrawable->pScreen, &tmpRegion);
+
+    (*pGC->ops->PushPixels) (pGC, pBitMap, pDrawable, w, h, x, y);
+
+    SCHEDULE_FB_UPDATE(pDrawable->pScreen, prfb);
+
+    GC_OP_EPILOGUE(pGC);
+}
+
+
+
+/****************************************************************************/
+/*
+ * Other functions
+ */
+/****************************************************************************/
+
+/*
+ * rfbCopyRegion.  Args are src and dst regions plus a translation (dx,dy).
+ * Takes these args together with the existing modified region and possibly an
+ * existing copy region and translation.  Produces a combined modified region
+ * plus copy region and translation.  Note that the copy region is the
+ * destination of the copy.
+ *
+ * First we trim parts of src which are invalid (ie in the modified region).
+ * Then we see if there is any overlap between the src and the existing copy
+ * region.  If not then the two copies cannot be combined, so we choose
+ * whichever is bigger to form the basis of a new copy, while the other copy is
+ * just done the hard way by being added to the modified region.  So if the
+ * existing copy is bigger then we simply add the destination of the new copy
+ * to the modified region and we're done.  If the new copy is bigger, we add
+ * the old copy region to the modified region and behave as though there is no
+ * existing copy region.
+ * 
+ * At this stage we now know that either the two copies can be combined, or
+ * that there is no existing copy.  We temporarily add both the existing copy
+ * region and dst to the modified region (this is the entire area of the screen
+ * affected in any way).  Finally we calculate the new copy region, and remove
+ * it from the modified region.
+ *
+ * Note:
+ *   1. The src region is modified by this routine.
+ *   2. When the copy region is empty, copyDX and copyDY MUST be set to zero.
+ */
+
+static void
+rfbCopyRegion(pScreen, cl, src, dst, dx, dy)
+    ScreenPtr pScreen;
+    rfbClientPtr cl;
+    RegionPtr src;
+    RegionPtr dst;
+    int dx, dy;
+{
+    RegionRec tmp;
+
+    /* src = src - modifiedRegion */
+
+    REGION_SUBTRACT(pScreen, src, src, &cl->modifiedRegion);
+
+    if (REGION_NOTEMPTY(pScreen, &cl->copyRegion)) {
+
+       REGION_INIT(pScreen, &tmp, NullBox, 0);
+       REGION_INTERSECT(pScreen, &tmp, src, &cl->copyRegion);
+
+       if (REGION_NOTEMPTY(pScreen, &tmp)) {
+
+           /* if src and copyRegion overlap:
+                src = src intersect copyRegion */
+
+           REGION_COPY(pScreen, src, &tmp);
+
+       } else {
+
+           /* if no overlap, find bigger region */
+
+           int newArea = (((REGION_EXTENTS(pScreen,src))->x2
+                           - (REGION_EXTENTS(pScreen,src))->x1)
+                          * ((REGION_EXTENTS(pScreen,src))->y2
+                             - (REGION_EXTENTS(pScreen,src))->y1));
+
+           int oldArea = (((REGION_EXTENTS(pScreen,&cl->copyRegion))->x2
+                           - (REGION_EXTENTS(pScreen,&cl->copyRegion))->x1)
+                          * ((REGION_EXTENTS(pScreen,&cl->copyRegion))->y2
+                            - (REGION_EXTENTS(pScreen,&cl->copyRegion))->y1));
+
+           if (oldArea > newArea) {
+
+               /* existing copy is bigger:
+                    modifiedRegion = modifiedRegion union dst
+                    copyRegion = copyRegion - dst
+                    return */
+
+               REGION_UNION(pScreen, &cl->modifiedRegion, &cl->modifiedRegion,
+                            dst);
+               REGION_SUBTRACT(pScreen, &cl->copyRegion, &cl->copyRegion,
+                               dst);
+               if (!REGION_NOTEMPTY(pScreen, &cl->copyRegion)) {
+                   cl->copyDX = 0;
+                   cl->copyDY = 0;
+               }
+               return;
+           }
+
+           /* new copy is bigger:
+                modifiedRegion = modifiedRegion union copyRegion
+                copyRegion = empty */
+
+           REGION_UNION(pScreen, &cl->modifiedRegion, &cl->modifiedRegion,
+                        &cl->copyRegion);
+           REGION_EMPTY(pScreen, &cl->copyRegion);
+           cl->copyDX = cl->copyDY = 0;
+       }
+    }
+
+
+    /* modifiedRegion = modifiedRegion union dst union copyRegion */
+
+    REGION_UNION(pScreen, &cl->modifiedRegion, &cl->modifiedRegion, dst);
+    REGION_UNION(pScreen, &cl->modifiedRegion, &cl->modifiedRegion,
+                &cl->copyRegion);
+
+    /* copyRegion = T(src) intersect dst */
+
+    REGION_TRANSLATE(pScreen, src, dx, dy);
+    REGION_INTERSECT(pScreen, &cl->copyRegion, src, dst);
+
+    /* modifiedRegion = modifiedRegion - copyRegion */
+
+    REGION_SUBTRACT(pScreen, &cl->modifiedRegion, &cl->modifiedRegion,
+                   &cl->copyRegion);
+
+    /* combine new translation T with existing translation */
+
+    if (REGION_NOTEMPTY(pScreen, &cl->copyRegion)) {
+       cl->copyDX += dx;
+       cl->copyDY += dy;
+    } else {
+       cl->copyDX = 0;
+       cl->copyDY = 0;
+    }
+}
+
+
+/*
+ * rfbDeferredUpdateCallback() is called when a client's deferredUpdateTimer
+ * goes off.
+ */
+
+static CARD32
+rfbDeferredUpdateCallback(OsTimerPtr timer, CARD32 now, pointer arg)
+{
+  rfbClientPtr cl = (rfbClientPtr)arg;
+
+  rfbSendFramebufferUpdate(cl);
+
+  cl->deferredUpdateScheduled = FALSE;
+  return 0;
+}
+
+
+/*
+ * rfbScheduleDeferredUpdate() is called from the SCHEDULE_FB_UPDATE macro
+ * to schedule an update.
+ */
+
+void
+rfbScheduleDeferredUpdate(rfbClientPtr cl)
+{
+    if (rfbDeferUpdateTime != 0) {
+       cl->deferredUpdateTimer = TimerSet(cl->deferredUpdateTimer, 0,
+                                          rfbDeferUpdateTime,
+                                          rfbDeferredUpdateCallback, cl);
+       cl->deferredUpdateScheduled = TRUE;
+    } else {
+       rfbSendFramebufferUpdate(cl);
+    }
+}
+
+
+/*
+ * PrintRegion is useful for debugging.
+ */
+
+#if 0
+static void
+PrintRegion(pScreen,reg)
+    ScreenPtr pScreen;
+    RegionPtr reg;
+{
+    int nrects = REGION_NUM_RECTS(reg);
+    int i;
+
+    rfbLog("Region num rects %d extents %d,%d %d,%d\n",nrects,
+          (REGION_EXTENTS(pScreen,reg))->x1,
+          (REGION_EXTENTS(pScreen,reg))->y1,
+          (REGION_EXTENTS(pScreen,reg))->x2,
+          (REGION_EXTENTS(pScreen,reg))->y2);
+
+    for (i = 0; i < nrects; i++) {
+       rfbLog("    rect %d,%d %dx%d\n",
+              REGION_RECTS(reg)[i].x1,
+              REGION_RECTS(reg)[i].y1,
+              REGION_RECTS(reg)[i].x2-REGION_RECTS(reg)[i].x1,
+              REGION_RECTS(reg)[i].y2-REGION_RECTS(reg)[i].y1);
+    }
+}
+#endif
diff --git a/Xserver/programs/Xserver/hw/vnc/hextile.c b/Xserver/programs/Xserver/hw/vnc/hextile.c
new file mode 100644 (file)
index 0000000..f80a3ac
--- /dev/null
@@ -0,0 +1,345 @@
+/*
+ * hextile.c
+ *
+ * Routines to implement Hextile Encoding
+ */
+
+/*
+ *  Copyright (C) 2002 RealVNC Ltd.
+ *  Copyright (C) 1999 AT&T Laboratories Cambridge.  All Rights Reserved.
+ *
+ *  This is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This software is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this software; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,
+ *  USA.
+ */
+
+#include <stdio.h>
+#include "rfb.h"
+
+static Bool sendHextiles8(rfbClientPtr cl, int x, int y, int w, int h);
+static Bool sendHextiles16(rfbClientPtr cl, int x, int y, int w, int h);
+static Bool sendHextiles32(rfbClientPtr cl, int x, int y, int w, int h);
+
+
+/*
+ * rfbSendRectEncodingHextile - send a rectangle using hextile encoding.
+ */
+
+Bool
+rfbSendRectEncodingHextile(cl, x, y, w, h)
+    rfbClientPtr cl;
+    int x, y, w, h;
+{
+    rfbFramebufferUpdateRectHeader rect;
+
+    if (ublen + sz_rfbFramebufferUpdateRectHeader > UPDATE_BUF_SIZE) {
+       if (!rfbSendUpdateBuf(cl))
+           return FALSE;
+    }
+
+    rect.r.x = Swap16IfLE(x);
+    rect.r.y = Swap16IfLE(y);
+    rect.r.w = Swap16IfLE(w);
+    rect.r.h = Swap16IfLE(h);
+    rect.encoding = Swap32IfLE(rfbEncodingHextile);
+
+    memcpy(&updateBuf[ublen], (char *)&rect,
+          sz_rfbFramebufferUpdateRectHeader);
+    ublen += sz_rfbFramebufferUpdateRectHeader;
+
+    cl->rfbRectanglesSent[rfbEncodingHextile]++;
+    cl->rfbBytesSent[rfbEncodingHextile] += sz_rfbFramebufferUpdateRectHeader;
+
+    switch (cl->format.bitsPerPixel) {
+    case 8:
+       return sendHextiles8(cl, x, y, w, h);
+    case 16:
+       return sendHextiles16(cl, x, y, w, h);
+    case 32:
+       return sendHextiles32(cl, x, y, w, h);
+    }
+
+    rfbLog("rfbSendRectEncodingHextile: bpp %d?\n", cl->format.bitsPerPixel);
+    return FALSE;
+}
+
+
+#define PUT_PIXEL8(pix) (updateBuf[ublen++] = (pix))
+
+#define PUT_PIXEL16(pix) (updateBuf[ublen++] = ((char*)&(pix))[0], \
+                         updateBuf[ublen++] = ((char*)&(pix))[1])
+
+#define PUT_PIXEL32(pix) (updateBuf[ublen++] = ((char*)&(pix))[0], \
+                         updateBuf[ublen++] = ((char*)&(pix))[1], \
+                         updateBuf[ublen++] = ((char*)&(pix))[2], \
+                         updateBuf[ublen++] = ((char*)&(pix))[3])
+
+
+#define DEFINE_SEND_HEXTILES(bpp)                                            \
+                                                                             \
+                                                                             \
+static Bool subrectEncode##bpp(CARD##bpp *data, int w, int h, CARD##bpp bg,   \
+                              CARD##bpp fg, Bool mono);                      \
+static void testColours##bpp(CARD##bpp *data, int size, Bool *mono,          \
+                            Bool *solid, CARD##bpp *bg, CARD##bpp *fg);      \
+                                                                             \
+                                                                             \
+/*                                                                           \
+ * rfbSendHextiles                                                           \
+ */                                                                          \
+                                                                             \
+static Bool                                                                  \
+sendHextiles##bpp(cl, rx, ry, rw, rh)                                        \
+    rfbClientPtr cl;                                                         \
+    int rx, ry, rw, rh;                                                              \
+{                                                                            \
+    int x, y, w, h;                                                          \
+    int startUblen;                                                          \
+    char *fbptr;                                                             \
+    CARD##bpp bg=0, fg=0, newBg, newFg;                                              \
+    Bool mono, solid;                                                        \
+    Bool validBg = FALSE;                                                    \
+    Bool validFg = FALSE;                                                    \
+    CARD##bpp clientPixelData[16*16*(bpp/8)];                                \
+                                                                             \
+    for (y = ry; y < ry+rh; y += 16) {                                       \
+       for (x = rx; x < rx+rw; x += 16) {                                    \
+           w = h = 16;                                                       \
+           if (rx+rw - x < 16)                                               \
+               w = rx+rw - x;                                                \
+           if (ry+rh - y < 16)                                               \
+               h = ry+rh - y;                                                \
+                                                                             \
+           if ((ublen + 1 + (2 + 16 * 16) * (bpp/8)) > UPDATE_BUF_SIZE) {    \
+               if (!rfbSendUpdateBuf(cl))                                    \
+                   return FALSE;                                             \
+           }                                                                 \
+                                                                             \
+           fbptr = (rfbScreen.pfbMemory + (rfbScreen.paddedWidthInBytes * y) \
+                    + (x * (rfbScreen.bitsPerPixel / 8)));                   \
+                                                                             \
+           (*cl->translateFn)(cl->translateLookupTable, &rfbServerFormat,    \
+                              &cl->format, fbptr, (char *)clientPixelData,   \
+                              rfbScreen.paddedWidthInBytes, w, h);           \
+                                                                             \
+           startUblen = ublen;                                               \
+           updateBuf[startUblen] = 0;                                        \
+           ublen++;                                                          \
+                                                                             \
+           testColours##bpp(clientPixelData, w * h,                          \
+                            &mono, &solid, &newBg, &newFg);                  \
+                                                                             \
+           if (!validBg || (newBg != bg)) {                                  \
+               validBg = TRUE;                                               \
+               bg = newBg;                                                   \
+               updateBuf[startUblen] |= rfbHextileBackgroundSpecified;       \
+               PUT_PIXEL##bpp(bg);                                           \
+           }                                                                 \
+                                                                             \
+           if (solid) {                                                      \
+               cl->rfbBytesSent[rfbEncodingHextile] += ublen - startUblen;   \
+               continue;                                                     \
+           }                                                                 \
+                                                                             \
+           updateBuf[startUblen] |= rfbHextileAnySubrects;                   \
+                                                                             \
+           if (mono) {                                                       \
+               if (!validFg || (newFg != fg)) {                              \
+                   validFg = TRUE;                                           \
+                   fg = newFg;                                               \
+                   updateBuf[startUblen] |= rfbHextileForegroundSpecified;   \
+                   PUT_PIXEL##bpp(fg);                                       \
+               }                                                             \
+           } else {                                                          \
+               validFg = FALSE;                                              \
+               updateBuf[startUblen] |= rfbHextileSubrectsColoured;          \
+           }                                                                 \
+                                                                             \
+           if (!subrectEncode##bpp(clientPixelData, w, h, bg, fg, mono)) {   \
+               /* encoding was too large, use raw */                         \
+               validBg = FALSE;                                              \
+               validFg = FALSE;                                              \
+               ublen = startUblen;                                           \
+               updateBuf[ublen++] = rfbHextileRaw;                           \
+               (*cl->translateFn)(cl->translateLookupTable,                  \
+                                  &rfbServerFormat, &cl->format, fbptr,      \
+                                  (char *)clientPixelData,                   \
+                                  rfbScreen.paddedWidthInBytes, w, h);       \
+                                                                             \
+               memcpy(&updateBuf[ublen], (char *)clientPixelData,            \
+                      w * h * (bpp/8));                                      \
+                                                                             \
+               ublen += w * h * (bpp/8);                                     \
+           }                                                                 \
+                                                                             \
+           cl->rfbBytesSent[rfbEncodingHextile] += ublen - startUblen;       \
+       }                                                                     \
+    }                                                                        \
+                                                                             \
+    return TRUE;                                                             \
+}                                                                            \
+                                                                             \
+                                                                             \
+static Bool                                                                  \
+subrectEncode##bpp(CARD##bpp *data, int w, int h, CARD##bpp bg,                      \
+                  CARD##bpp fg, Bool mono)                                   \
+{                                                                            \
+    CARD##bpp cl;                                                            \
+    int x,y;                                                                 \
+    int i,j;                                                                 \
+    int hx=0,hy,vx=0,vy;                                                     \
+    int hyflag;                                                                      \
+    CARD##bpp *seg;                                                          \
+    CARD##bpp *line;                                                         \
+    int hw,hh,vw,vh;                                                         \
+    int thex,they,thew,theh;                                                 \
+    int numsubs = 0;                                                         \
+    int newLen;                                                                      \
+    int nSubrectsUblen;                                                              \
+                                                                             \
+    nSubrectsUblen = ublen;                                                  \
+    ublen++;                                                                 \
+                                                                             \
+    for (y=0; y<h; y++) {                                                    \
+       line = data+(y*w);                                                    \
+       for (x=0; x<w; x++) {                                                 \
+           if (line[x] != bg) {                                              \
+               cl = line[x];                                                 \
+               hy = y-1;                                                     \
+               hyflag = 1;                                                   \
+               for (j=y; j<h; j++) {                                         \
+                   seg = data+(j*w);                                         \
+                   if (seg[x] != cl) {break;}                                \
+                   i = x;                                                    \
+                   while ((seg[i] == cl) && (i < w)) i += 1;                 \
+                   i -= 1;                                                   \
+                   if (j == y) vx = hx = i;                                  \
+                   if (i < vx) vx = i;                                       \
+                   if ((hyflag > 0) && (i >= hx)) {                          \
+                       hy += 1;                                              \
+                   } else {                                                  \
+                       hyflag = 0;                                           \
+                   }                                                         \
+               }                                                             \
+               vy = j-1;                                                     \
+                                                                             \
+               /* We now have two possible subrects: (x,y,hx,hy) and         \
+                * (x,y,vx,vy).  We'll choose the bigger of the two.          \
+                */                                                           \
+               hw = hx-x+1;                                                  \
+               hh = hy-y+1;                                                  \
+               vw = vx-x+1;                                                  \
+               vh = vy-y+1;                                                  \
+                                                                             \
+               thex = x;                                                     \
+               they = y;                                                     \
+                                                                             \
+               if ((hw*hh) > (vw*vh)) {                                      \
+                   thew = hw;                                                \
+                   theh = hh;                                                \
+               } else {                                                      \
+                   thew = vw;                                                \
+                   theh = vh;                                                \
+               }                                                             \
+                                                                             \
+               if (mono) {                                                   \
+                   newLen = ublen - nSubrectsUblen + 2;                      \
+               } else {                                                      \
+                   newLen = ublen - nSubrectsUblen + bpp/8 + 2;              \
+               }                                                             \
+                                                                             \
+               if (newLen > (w * h * (bpp/8)))                               \
+                   return FALSE;                                             \
+                                                                             \
+               numsubs += 1;                                                 \
+                                                                             \
+               if (!mono) PUT_PIXEL##bpp(cl);                                \
+                                                                             \
+               updateBuf[ublen++] = rfbHextilePackXY(thex,they);             \
+               updateBuf[ublen++] = rfbHextilePackWH(thew,theh);             \
+                                                                             \
+               /*                                                            \
+                * Now mark the subrect as done.                              \
+                */                                                           \
+               for (j=they; j < (they+theh); j++) {                          \
+                   for (i=thex; i < (thex+thew); i++) {                      \
+                       data[j*w+i] = bg;                                     \
+                   }                                                         \
+               }                                                             \
+           }                                                                 \
+       }                                                                     \
+    }                                                                        \
+                                                                             \
+    updateBuf[nSubrectsUblen] = numsubs;                                     \
+                                                                             \
+    return TRUE;                                                             \
+}                                                                            \
+                                                                             \
+                                                                             \
+/*                                                                           \
+ * testColours() tests if there are one (solid), two (mono) or more          \
+ * colours in a tile and gets a reasonable guess at the best background              \
+ * pixel, and the foreground pixel for mono.                                 \
+ */                                                                          \
+                                                                             \
+static void                                                                  \
+testColours##bpp(data,size,mono,solid,bg,fg)                                 \
+    CARD##bpp *data;                                                         \
+    int size;                                                                \
+    Bool *mono;                                                                      \
+    Bool *solid;                                                             \
+    CARD##bpp *bg;                                                           \
+    CARD##bpp *fg;                                                           \
+{                                                                            \
+    CARD##bpp colour1=0, colour2=0;                                          \
+    int n1 = 0, n2 = 0;                                                              \
+    *mono = TRUE;                                                            \
+    *solid = TRUE;                                                           \
+                                                                             \
+    for (; size > 0; size--, data++) {                                       \
+                                                                             \
+       if (n1 == 0)                                                          \
+           colour1 = *data;                                                  \
+                                                                             \
+       if (*data == colour1) {                                               \
+           n1++;                                                             \
+           continue;                                                         \
+       }                                                                     \
+                                                                             \
+       if (n2 == 0) {                                                        \
+           *solid = FALSE;                                                   \
+           colour2 = *data;                                                  \
+       }                                                                     \
+                                                                             \
+       if (*data == colour2) {                                               \
+           n2++;                                                             \
+           continue;                                                         \
+       }                                                                     \
+                                                                             \
+       *mono = FALSE;                                                        \
+       break;                                                                \
+    }                                                                        \
+                                                                             \
+    if (n1 > n2) {                                                           \
+       *bg = colour1;                                                        \
+       *fg = colour2;                                                        \
+    } else {                                                                 \
+       *bg = colour2;                                                        \
+       *fg = colour1;                                                        \
+    }                                                                        \
+}
+
+DEFINE_SEND_HEXTILES(8)
+DEFINE_SEND_HEXTILES(16)
+DEFINE_SEND_HEXTILES(32)
diff --git a/Xserver/programs/Xserver/hw/vnc/httpd.c b/Xserver/programs/Xserver/hw/vnc/httpd.c
new file mode 100644 (file)
index 0000000..4a84f71
--- /dev/null
@@ -0,0 +1,392 @@
+/*
+ * httpd.c - a simple HTTP server
+ */
+
+/*
+ *  Copyright (C) 2002 RealVNC Ltd.
+ *  Copyright (C) 1999 AT&T Laboratories Cambridge.  All Rights Reserved.
+ *
+ *  This is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This software is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this software; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,
+ *  USA.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/time.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <netinet/tcp.h>
+#include <arpa/inet.h>
+#include <netdb.h>
+#include <fcntl.h>
+#include <errno.h>
+#include <pwd.h>
+
+#include "rfb.h"
+
+#define NOT_FOUND_STR "HTTP/1.0 404 Not found\r\n\r\n" \
+    "<HEAD><TITLE>File Not Found</TITLE></HEAD>\n" \
+    "<BODY><H1>File Not Found</H1></BODY>\n"
+
+#define OK_STR "HTTP/1.0 200 OK\r\n\r\n"
+
+static void httpProcessInput();
+static Bool compareAndSkip(char **ptr, const char *str);
+
+int httpPort = 0;
+char *httpDir = NULL;
+
+int httpListenSock = -1;
+int httpSock = -1;
+
+#define BUF_SIZE 32768
+
+static char buf[BUF_SIZE];
+static int bufLen;
+
+
+/*
+ * httpInitSockets sets up the TCP socket to listen for HTTP connections.
+ */
+
+void httpInitSockets()
+{
+    static Bool done = FALSE;
+
+    if (done)
+       return;
+
+    done = TRUE;
+
+    if (!httpDir)
+       return;
+
+    if (httpPort == 0) {
+       httpPort = 5800 + atoi(display);
+    }
+
+    rfbLog("Listening for HTTP connections on TCP port %d\n", httpPort);
+
+    rfbLog("  URL http://%s:%d\n",rfbThisHost,httpPort);
+
+    if ((httpListenSock = ListenOnTCPPort(httpPort)) < 0) {
+       rfbLogPerror("ListenOnTCPPort");
+       exit(1);
+    }
+
+    AddEnabledDevice(httpListenSock);
+}
+
+
+/*
+ * httpCheckFds is called from ProcessInputEvents to check for input on the
+ * HTTP socket(s).  If there is input to process, httpProcessInput is called.
+ */
+
+void httpCheckFds()
+{
+    int nfds;
+    fd_set fds;
+    struct timeval tv;
+    struct sockaddr_in addr;
+    unsigned int addrlen = sizeof(addr);
+    int flags;
+
+    if (!httpDir)
+       return;
+
+    FD_ZERO(&fds);
+    FD_SET(httpListenSock, &fds);
+    if (httpSock >= 0) {
+       FD_SET(httpSock, &fds);
+    }
+    tv.tv_sec = 0;
+    tv.tv_usec = 0;
+    nfds = select(max(httpSock,httpListenSock) + 1, &fds, NULL, NULL, &tv);
+    if (nfds == 0) {
+       return;
+    }
+    if (nfds < 0) {
+       rfbLogPerror("httpCheckFds: select");
+       return;
+    }
+
+    if ((httpSock >= 0) && FD_ISSET(httpSock, &fds)) {
+       httpProcessInput();
+    }
+
+    if (FD_ISSET(httpListenSock, &fds)) {
+
+       if (httpSock >= 0) close(httpSock);
+
+       if ((httpSock = accept(httpListenSock,
+                              (struct sockaddr *)&addr, &addrlen)) < 0) {
+           rfbLogPerror("httpCheckFds: accept");
+           return;
+       }
+
+       flags = fcntl(httpSock, F_GETFL);
+
+       if (flags < 0 || fcntl(httpSock, F_SETFL, flags | O_NONBLOCK) == -1) {
+           rfbLogPerror("httpCheckFds: fcntl");
+           close(httpSock);
+           httpSock = -1;
+           return;
+       }
+
+       AddEnabledDevice(httpSock);
+        bufLen = 0;
+    }
+}
+
+
+static void httpCloseSock()
+{
+    close(httpSock);
+    RemoveEnabledDevice(httpSock);
+    httpSock = -1;
+}
+
+
+/*
+ * httpProcessInput is called when input is received on the HTTP socket.  We
+ * read lines from the HTTP client until we get a blank line (the end of an
+ * HTTP request).  The socket is non-blocking so we return if there's no more
+ * to read and will carry on where we left off when more data is available.
+ */
+
+static void httpProcessInput()
+{
+    struct sockaddr_in addr;
+    unsigned int addrlen = sizeof(addr);
+    char fullFname[256];
+    char *fname;
+    int maxFnameLen;
+    int fd;
+    Bool performSubstitutions = FALSE;
+    char str[256];
+    struct passwd *user = getpwuid(getuid());
+    int n;
+
+    if (strlen(httpDir) > 200) {
+       rfbLog("-httpd directory too long\n");
+       httpCloseSock();
+       return;
+    }
+    strcpy(fullFname, httpDir);
+    fname = &fullFname[strlen(fullFname)];
+    maxFnameLen = 255 - strlen(fullFname);
+
+    while (1) {
+        if (bufLen >= BUF_SIZE-1) {
+            rfbLog("httpProcessInput: HTTP request is too long\n");
+            httpCloseSock();
+            return;
+        }
+
+        n = read(httpSock, buf + bufLen, BUF_SIZE - bufLen - 1);
+
+        if (n <= 0) {
+            if (n < 0) {
+                if (errno == EAGAIN) return;
+                rfbLogPerror("httpProcessInput: read");
+            } else {
+                rfbLog("httpProcessInput: connection closed\n");
+            }
+            httpCloseSock();
+            return;
+        }
+
+        bufLen += n;
+        buf[bufLen] = 0;
+
+       if (strstr(buf, "\r\r") || strstr(buf, "\n\n") ||
+           strstr(buf, "\r\n\r\n") || strstr(buf, "\n\r\n\r"))
+            break;
+    }
+
+    if (strncmp(buf, "GET ", 4) != 0) {
+       rfbLog("httpProcessInput: first line wasn't a GET?\n");
+       httpCloseSock();
+       return;
+    }
+
+    buf[strcspn(buf, "\r\n")] = 0; /* only want first line */
+
+    if (strlen(buf) > maxFnameLen) {
+       rfbLog("httpProcessInput: GET line too long\n");
+       httpCloseSock();
+       return;
+    }
+
+    if (sscanf(buf, "GET %s HTTP", fname) != 1) {
+       rfbLog("httpProcessInput: couldn't parse GET line\n");
+       httpCloseSock();
+       return;
+    }
+
+    if (fname[0] != '/') {
+       rfbLog("httpProcessInput: filename didn't begin with '/'\n");
+       WriteExact(httpSock, NOT_FOUND_STR, strlen(NOT_FOUND_STR));
+       httpCloseSock();
+       return;
+    }
+
+    if (strchr(fname+1, '/') != NULL) {
+       rfbLog("httpProcessInput: asking for file in other directory\n");
+       WriteExact(httpSock, NOT_FOUND_STR, strlen(NOT_FOUND_STR));
+       httpCloseSock();
+       return;
+    }
+
+    getpeername(httpSock, (struct sockaddr *)&addr, &addrlen);
+    rfbLog("httpd: get '%s' for %s\n", fname+1,
+          inet_ntoa(addr.sin_addr));
+
+    /* If we were asked for '/', actually read the file index.vnc */
+
+    if (strcmp(fname, "/") == 0) {
+       strcpy(fname, "/index.vnc");
+       rfbLog("httpd: defaulting to '%s'\n", fname+1);
+    }
+
+    /* Substitutions are performed on files ending .vnc */
+
+    if (strlen(fname) >= 4 && strcmp(&fname[strlen(fname)-4], ".vnc") == 0) {
+       performSubstitutions = TRUE;
+    }
+
+    /* Open the file */
+
+    if ((fd = open(fullFname, O_RDONLY)) < 0) {
+       rfbLogPerror("httpProcessInput: open");
+       WriteExact(httpSock, NOT_FOUND_STR, strlen(NOT_FOUND_STR));
+       httpCloseSock();
+       return;
+    }
+
+    WriteExact(httpSock, OK_STR, strlen(OK_STR));
+
+    while (1) {
+       int n = read(fd, buf, BUF_SIZE-1);
+       if (n < 0) {
+           rfbLogPerror("httpProcessInput: read");
+           close(fd);
+           httpCloseSock();
+           return;
+       }
+
+       if (n == 0)
+           break;
+
+       if (performSubstitutions) {
+
+           /* Substitute $WIDTH, $HEIGHT, etc with the appropriate values.
+              This won't quite work properly if the .vnc file is longer than
+              BUF_SIZE, but it's reasonable to assume that .vnc files will
+              always be short. */
+
+           char *ptr = buf;
+           char *dollar;
+           buf[n] = 0; /* make sure it's null-terminated */
+
+           while ((dollar = strchr(ptr, '$'))) {
+               WriteExact(httpSock, ptr, (dollar - ptr));
+
+               ptr = dollar;
+
+               if (compareAndSkip(&ptr, "$WIDTH")) {
+
+                   sprintf(str, "%d", rfbScreen.width);
+                   WriteExact(httpSock, str, strlen(str));
+
+               } else if (compareAndSkip(&ptr, "$HEIGHT")) {
+
+                   sprintf(str, "%d", rfbScreen.height);
+                   WriteExact(httpSock, str, strlen(str));
+
+               } else if (compareAndSkip(&ptr, "$APPLETWIDTH")) {
+
+                   sprintf(str, "%d", rfbScreen.width);
+                   WriteExact(httpSock, str, strlen(str));
+
+               } else if (compareAndSkip(&ptr, "$APPLETHEIGHT")) {
+
+                   sprintf(str, "%d", rfbScreen.height + 32);
+                   WriteExact(httpSock, str, strlen(str));
+
+               } else if (compareAndSkip(&ptr, "$PORT")) {
+
+                   sprintf(str, "%d", rfbPort);
+                   WriteExact(httpSock, str, strlen(str));
+
+               } else if (compareAndSkip(&ptr, "$DESKTOP")) {
+
+                   WriteExact(httpSock, desktopName, strlen(desktopName));
+
+               } else if (compareAndSkip(&ptr, "$DISPLAY")) {
+
+                   sprintf(str, "%s:%s", rfbThisHost, display);
+                   WriteExact(httpSock, str, strlen(str));
+
+               } else if (compareAndSkip(&ptr, "$USER")) {
+
+                   if (user) {
+                       WriteExact(httpSock, user->pw_name,
+                                  strlen(user->pw_name));
+                   } else {
+                       WriteExact(httpSock, "?", 1);
+                   }
+
+               } else {
+                   if (!compareAndSkip(&ptr, "$$"))
+                       ptr++;
+
+                   if (WriteExact(httpSock, "$", 1) < 0) {
+                       close(fd);
+                       httpCloseSock();
+                       return;
+                   }
+               }
+           }
+           if (WriteExact(httpSock, ptr, (&buf[n] - ptr)) < 0)
+               break;
+
+       } else {
+
+           /* For files not ending .vnc, just write out the buffer */
+
+           if (WriteExact(httpSock, buf, n) < 0)
+               break;
+       }
+    }
+
+    close(fd);
+    httpCloseSock();
+}
+
+
+static Bool
+compareAndSkip(char **ptr, const char *str)
+{
+    if (strncmp(*ptr, str, strlen(str)) == 0) {
+       *ptr += strlen(str);
+       return TRUE;
+    }
+
+    return FALSE;
+}
diff --git a/Xserver/programs/Xserver/hw/vnc/init.c b/Xserver/programs/Xserver/hw/vnc/init.c
new file mode 100644 (file)
index 0000000..a55b715
--- /dev/null
@@ -0,0 +1,921 @@
+/*
+ * init.c
+ */
+
+/*
+ *  Copyright (C) 2002-2003 RealVNC Ltd.
+ *  Copyright (C) 1999 AT&T Laboratories Cambridge.  All Rights Reserved.
+ *
+ *  This is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This software is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this software; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,
+ *  USA.
+ */
+
+/*
+
+Copyright (c) 1993  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be included
+in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR
+OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall
+not be used in advertising or otherwise to promote the sale, use or
+other dealings in this Software without prior written authorization
+from the X Consortium.
+
+*/
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdarg.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <netdb.h>
+#include "X11/X.h"
+#define NEED_EVENTS
+#include "X11/Xproto.h"
+#include "X11/Xos.h"
+#include "scrnintstr.h"
+#include "servermd.h"
+#define PSZ 8
+#include "cfb.h"
+#include "mi.h"
+#include "mibstore.h"
+#include "colormapst.h"
+#include "gcstruct.h"
+#include "input.h"
+#include "mipointer.h"
+#include "dixstruct.h"
+#include "propertyst.h"
+#include <Xatom.h>
+#include <errno.h>
+#include <sys/param.h>
+#include "dix.h"
+#include "rfb.h"
+#include "dispcur.h"
+
+extern Bool cfb16ScreenInit(ScreenPtr, pointer, int, int, int, int, int);
+extern Bool cfb32ScreenInit(ScreenPtr, pointer, int, int, int, int, int);
+
+#define RFB_DEFAULT_WIDTH  640
+#define RFB_DEFAULT_HEIGHT 480
+#define RFB_DEFAULT_DEPTH  8
+#define RFB_DEFAULT_WHITEPIXEL 0
+#define RFB_DEFAULT_BLACKPIXEL 1
+
+rfbScreenInfo rfbScreen;
+int rfbGCIndex;
+
+static Bool initOutputCalled = FALSE;
+static Bool noCursor = FALSE;
+char *desktopName = "x11";
+Bool rfbTrace = FALSE;
+
+char rfbThisHost[256];
+
+Atom VNC_LAST_CLIENT_ID;
+Atom VNC_CONNECT;
+Atom VNC_DEFER_UPDATE;
+
+static HWEventQueueType alwaysCheckForInput[2] = { 0, 1 };
+static HWEventQueueType *mieqCheckForInput[2];
+
+static char primaryOrder[4] = "";
+static int redBits, greenBits, blueBits;
+
+
+static Bool rfbScreenInit(int index, ScreenPtr pScreen, int argc,
+                         char **argv);
+static int rfbKeybdProc(DeviceIntPtr pDevice, int onoff);
+static int rfbMouseProc(DeviceIntPtr pDevice, int onoff);
+static Bool CheckDisplayNumber(int n);
+
+static Bool rfbAlwaysTrue();
+static char *rfbAllocateFramebufferMemory(rfbScreenInfoPtr prfb);
+static Bool rfbCursorOffScreen(ScreenPtr *ppScreen, int *x, int *y);
+static void rfbCrossScreen(ScreenPtr pScreen, Bool entering);
+static void rfbClientStateChange(CallbackListPtr *, pointer myData,
+                                pointer client);
+
+static miPointerScreenFuncRec rfbPointerCursorFuncs = {
+    rfbCursorOffScreen,
+    rfbCrossScreen,
+    miPointerWarpCursor
+};
+
+
+int inetdSock = -1;
+static char inetdDisplayNumStr[10];
+
+extern char buildtime[];
+
+
+/*
+ * ddxProcessArgument is our first entry point and will be called at the
+ * very start for each argument.  It is not called again on server reset.
+ */
+
+int
+ddxProcessArgument (argc, argv, i)
+    int argc;
+    char *argv[];
+    int i;
+{
+    static Bool firstTime = TRUE;
+
+    if (firstTime)
+    {
+       rfbScreen.width  = RFB_DEFAULT_WIDTH;
+       rfbScreen.height = RFB_DEFAULT_HEIGHT;
+       rfbScreen.depth  = RFB_DEFAULT_DEPTH;
+       rfbScreen.blackPixel = RFB_DEFAULT_BLACKPIXEL;
+       rfbScreen.whitePixel = RFB_DEFAULT_WHITEPIXEL;
+       rfbScreen.pfbMemory = NULL;
+       gethostname(rfbThisHost, 255);
+        firstTime = FALSE;
+    }
+
+    if (strcasecmp (argv[i], "-geometry") == 0)        /* -geometry WxH */
+    {
+       if (i + 1 >= argc) UseMsg();
+       if (sscanf(argv[i+1],"%dx%d",
+                  &rfbScreen.width,&rfbScreen.height) != 2) {
+           ErrorF("Invalid geometry %s\n", argv[i+1]);
+           UseMsg();
+       }
+       return 2;
+    }
+
+    if (strcasecmp (argv[i], "-depth") == 0)   /* -depth D */
+    {
+       if (i + 1 >= argc) UseMsg();
+       rfbScreen.depth = atoi(argv[i+1]);
+       return 2;
+    }
+
+    if (strcasecmp (argv[i], "-pixelformat") == 0) {
+       if (i + 1 >= argc) UseMsg();
+       if (sscanf(argv[i+1], "%3s%1d%1d%1d", primaryOrder,
+                  &redBits, &greenBits, &blueBits) < 4) {
+           ErrorF("Invalid pixel format %s\n", argv[i+1]);
+           UseMsg();
+       }
+
+       if (strcasecmp(primaryOrder, "bgr") == 0) {
+           int tmp = redBits;
+           redBits = blueBits;
+           blueBits = tmp;
+       } else if (strcasecmp(primaryOrder, "rgb") != 0) {
+           ErrorF("Invalid pixel format %s\n", argv[i+1]);
+           UseMsg();
+       }
+
+       return 2;
+    }
+
+    if (strcasecmp (argv[i], "-blackpixel") == 0) {    /* -blackpixel n */
+       if (i + 1 >= argc) UseMsg();
+       rfbScreen.blackPixel = atoi(argv[i+1]);
+       return 2;
+    }
+
+    if (strcasecmp (argv[i], "-whitepixel") == 0) {    /* -whitepixel n */
+       if (i + 1 >= argc) UseMsg();
+       rfbScreen.whitePixel = atoi(argv[i+1]);
+       return 2;
+    }
+
+    if (strcasecmp(argv[i], "-rfbport") == 0) {        /* -rfbport port */
+       if (i + 1 >= argc) UseMsg();
+       rfbPort = atoi(argv[i+1]);
+       return 2;
+    }
+
+    if (strcasecmp(argv[i], "-rfbwait") == 0) {        /* -rfbwait ms */
+       if (i + 1 >= argc) UseMsg();
+       rfbMaxClientWait = atoi(argv[i+1]);
+       return 2;
+    }
+
+    if (strcasecmp(argv[i], "-nocursor") == 0) {
+       noCursor = TRUE;
+       return 1;
+    }
+
+    if (strcasecmp(argv[i], "-rfbauth") == 0) {        /* -rfbauth passwd-file */
+       if (i + 1 >= argc) UseMsg();
+       rfbAuthPasswdFile = argv[i+1];
+       return 2;
+    }
+
+    if (strcasecmp(argv[i], "-httpd") == 0) {
+       if (i + 1 >= argc) UseMsg();
+       httpDir = argv[i+1];
+       return 2;
+    }
+
+    if (strcasecmp(argv[i], "-httpport") == 0) {
+       if (i + 1 >= argc) UseMsg();
+       httpPort = atoi(argv[i+1]);
+       return 2;
+    }
+
+    if (strcasecmp(argv[i], "-deferupdate") == 0) {    /* -deferupdate ms */
+       if (i + 1 >= argc) UseMsg();
+       rfbDeferUpdateTime = atoi(argv[i+1]);
+       return 2;
+    }
+
+    if (strcasecmp(argv[i], "-economictranslate") == 0) {
+       rfbEconomicTranslate = TRUE;
+       return 1;
+    }
+
+    if (strcasecmp(argv[i], "-maxrects") == 0) {
+       if (i + 1 >= argc) UseMsg();
+       rfbMaxRects = atoi(argv[i+1]);
+       return 2;
+    }
+
+    if (strcasecmp(argv[i], "-trace") == 0) {
+        rfbTrace = TRUE;
+       return 1;
+    }
+
+    if (strcasecmp(argv[i], "-desktop") == 0) {        /* -desktop desktop-name */
+       if (i + 1 >= argc) UseMsg();
+       desktopName = argv[i+1];
+       return 2;
+    }
+
+    if (strcasecmp(argv[i], "-alwaysshared") == 0) {
+       rfbAlwaysShared = TRUE;
+       return 1;
+    }
+
+    if (strcasecmp(argv[i], "-nevershared") == 0) {
+       rfbNeverShared = TRUE;
+       return 1;
+    }
+
+    if (strcasecmp(argv[i], "-dontdisconnect") == 0) {
+       rfbDontDisconnect = TRUE;
+       return 1;
+    }
+
+    if (strcasecmp(argv[i], "-localhost") == 0) {
+       rfbLocalhostOnly = TRUE;
+       return 1;
+    }
+
+    if (strcasecmp(argv[i], "-inetd") == 0) {  /* -inetd */ 
+       int n;
+       for (n = 1; n < 100; n++) {
+           if (CheckDisplayNumber(n))
+               break;
+       }
+
+       if (n >= 100)
+           FatalError("-inetd: couldn't find free display number");
+
+       sprintf(inetdDisplayNumStr, "%d", n);
+       display = inetdDisplayNumStr;
+
+       /* fds 0, 1 and 2 (stdin, out and err) are all the same socket to the
+           RFB client.  OsInit() closes stdout and stdin, and we don't want
+           stderr to go to the RFB client, so make the client socket 3 and
+           close stderr.  OsInit() will redirect stderr logging to an
+           appropriate log file or /dev/null if that doesn't work. */
+
+       dup2(0,3);
+       inetdSock = 3;
+       close(2);
+
+       return 1;
+    }
+
+    if (inetdSock != -1 && argv[i][0] == ':') {
+       FatalError("can't specify both -inetd and :displaynumber");
+    }
+
+    return 0;
+}
+
+
+/*
+ * InitOutput is called every time the server resets.  It should call
+ * AddScreen for each screen (but we only ever have one), and in turn this
+ * will call rfbScreenInit.
+ */
+
+void
+InitOutput(screenInfo, argc, argv)
+    ScreenInfo *screenInfo;
+    int argc;
+    char **argv;
+{
+    initOutputCalled = TRUE;
+
+    rfbLog("Xvnc version %s - built %s\n", XVNCRELEASE, buildtime);
+    rfbLog("Copyright (C) 2002-2003 RealVNC Ltd.\n");
+    rfbLog("Copyright (C) 1994-2000 AT&T Laboratories Cambridge.\n");
+    rfbLog("All Rights Reserved.\n");
+    rfbLog("See http://www.realvnc.com for information on VNC\n");
+    rfbLog("Desktop name '%s' (%s:%s)\n",desktopName,rfbThisHost,display);
+    rfbLog("Protocol version supported %d.%d\n", rfbProtocolMajorVersion,
+          rfbProtocolMinorVersion);
+
+    VNC_LAST_CLIENT_ID = MakeAtom("VNC_LAST_CLIENT_ID",
+                                 strlen("VNC_LAST_CLIENT_ID"), TRUE);
+    VNC_CONNECT = MakeAtom("VNC_CONNECT", strlen("VNC_CONNECT"), TRUE);
+    VNC_DEFER_UPDATE = MakeAtom("VNC_DEFER_UPDATE",
+                                strlen("VNC_DEFER_UPDATE"), TRUE);
+    rfbInitSockets();
+    if (inetdSock == -1)
+       httpInitSockets();
+   
+
+    /* initialize pixmap formats */
+
+    screenInfo->imageByteOrder = IMAGE_BYTE_ORDER;
+    screenInfo->bitmapScanlineUnit = BITMAP_SCANLINE_UNIT;
+    screenInfo->bitmapScanlinePad = BITMAP_SCANLINE_PAD;
+    screenInfo->bitmapBitOrder = BITMAP_BIT_ORDER;
+    screenInfo->numPixmapFormats = 2;
+
+    screenInfo->formats[0].depth = 1;
+    screenInfo->formats[0].bitsPerPixel = 1;
+    screenInfo->formats[0].scanlinePad = BITMAP_SCANLINE_PAD;
+
+    screenInfo->formats[1].depth = rfbScreen.depth;
+    screenInfo->formats[1].bitsPerPixel = rfbBitsPerPixel(rfbScreen.depth);
+    screenInfo->formats[1].scanlinePad = BITMAP_SCANLINE_PAD;
+
+    rfbGCIndex = AllocateGCPrivateIndex();
+    if (rfbGCIndex < 0) {
+       FatalError("InitOutput: AllocateGCPrivateIndex failed\n");
+    }
+
+    if (!AddCallback(&ClientStateCallback, rfbClientStateChange, NULL)) {
+       rfbLog("InitOutput: AddCallback failed\n");
+       return;
+    }
+
+    /* initialize screen */
+
+    if (AddScreen(rfbScreenInit, argc, argv) == -1) {
+       FatalError("Couldn't add screen");
+    }
+}
+
+
+static Bool
+rfbScreenInit(index, pScreen, argc, argv)
+    int index;
+    ScreenPtr pScreen;
+    int argc;
+    char ** argv;
+{
+    rfbScreenInfoPtr prfb = &rfbScreen;
+    int dpix = 75, dpiy = 75;
+    int ret;
+    char *pbits;
+    VisualPtr vis;
+    extern int monitorResolution;
+
+    if (monitorResolution != 0) {
+       dpix = monitorResolution;
+       dpiy = monitorResolution;
+    }
+
+    prfb->paddedWidthInBytes = PixmapBytePad(prfb->width, prfb->depth);
+    prfb->bitsPerPixel = rfbBitsPerPixel(prfb->depth);
+    pbits = rfbAllocateFramebufferMemory(prfb);
+    if (!pbits) return FALSE;
+
+    if (prfb->bitsPerPixel > 1) {
+       extern int defaultColorVisualClass;
+       if (defaultColorVisualClass != -1) {
+           cfbSetVisualTypes(prfb->depth, (1 << defaultColorVisualClass), 8);
+       } else {
+           cfbSetVisualTypes(prfb->depth, (1 << TrueColor), 8);
+       }
+    }
+
+    switch (prfb->bitsPerPixel)
+    {
+    case 1:
+       ret = mfbScreenInit(pScreen, pbits, prfb->width, prfb->height,
+                           dpix, dpiy, prfb->paddedWidthInBytes * 8);
+       break;
+    case 8:
+       ret = cfbScreenInit(pScreen, pbits, prfb->width, prfb->height,
+                           dpix, dpiy, prfb->paddedWidthInBytes);
+       break;
+    case 16:
+       ret = cfb16ScreenInit(pScreen, pbits, prfb->width, prfb->height,
+                             dpix, dpiy, prfb->paddedWidthInBytes / 2);
+       break;
+    case 32:
+       ret = cfb32ScreenInit(pScreen, pbits, prfb->width, prfb->height,
+                             dpix, dpiy, prfb->paddedWidthInBytes / 4);
+       break;
+    default:
+       return FALSE;
+    }
+
+    if (!ret) return FALSE;
+
+    if (!AllocateGCPrivate(pScreen, rfbGCIndex, sizeof(rfbGCRec))) {
+       FatalError("rfbScreenInit: AllocateGCPrivate failed\n");
+    }
+
+    prfb->cursorIsDrawn = FALSE;
+    prfb->dontSendFramebufferUpdate = FALSE;
+
+    prfb->CloseScreen = pScreen->CloseScreen;
+    prfb->CreateGC = pScreen->CreateGC;
+    prfb->PaintWindowBackground = pScreen->PaintWindowBackground;
+    prfb->PaintWindowBorder = pScreen->PaintWindowBorder;
+    prfb->CopyWindow = pScreen->CopyWindow;
+    prfb->ClearToBackground = pScreen->ClearToBackground;
+    prfb->RestoreAreas = pScreen->RestoreAreas;
+
+    pScreen->CloseScreen = rfbCloseScreen;
+    pScreen->CreateGC = rfbCreateGC;
+    pScreen->PaintWindowBackground = rfbPaintWindowBackground;
+    pScreen->PaintWindowBorder = rfbPaintWindowBorder;
+    pScreen->CopyWindow = rfbCopyWindow;
+    pScreen->ClearToBackground = rfbClearToBackground;
+    pScreen->RestoreAreas = rfbRestoreAreas;
+
+    pScreen->InstallColormap = rfbInstallColormap;
+    pScreen->UninstallColormap = rfbUninstallColormap;
+    pScreen->ListInstalledColormaps = rfbListInstalledColormaps;
+    pScreen->StoreColors = rfbStoreColors;
+
+    pScreen->SaveScreen = rfbAlwaysTrue;
+
+    rfbDCInitialize(pScreen, &rfbPointerCursorFuncs);
+
+    if (noCursor) {
+       pScreen->DisplayCursor = rfbAlwaysTrue;
+       prfb->cursorIsDrawn = TRUE;
+    }
+
+    pScreen->blackPixel = prfb->blackPixel;
+    pScreen->whitePixel = prfb->whitePixel;
+
+    for (vis = pScreen->visuals; vis->vid != pScreen->rootVisual; vis++)
+       ;
+
+    if (!vis) {
+       rfbLog("rfbScreenInit: couldn't find root visual\n");
+       exit(1);
+    }
+
+    if (strcmp(primaryOrder, "") == 0) {
+      if (prfb->depth == 16) { /* use rgb565 for depth 16 */
+        strcpy(primaryOrder, "rgb");
+        redBits = 5;
+        greenBits = 6;
+        blueBits = 5;
+      } else if (prfb->depth == 24) { /* use rgb888 for depth 24 */
+        strcpy(primaryOrder, "rgb");
+        redBits = 8;
+        greenBits = 8;
+        blueBits = 8;
+      }
+    }
+
+    if (strcasecmp(primaryOrder, "rgb") == 0) {
+       vis->offsetBlue = 0;
+       vis->blueMask = (1 << blueBits) - 1;
+       vis->offsetGreen = blueBits;
+       vis->greenMask = ((1 << greenBits) - 1) << vis->offsetGreen;
+       vis->offsetRed = vis->offsetGreen + greenBits;
+       vis->redMask = ((1 << redBits) - 1) << vis->offsetRed;
+    } else if (strcasecmp(primaryOrder, "bgr") == 0) {
+       rfbLog("BGR format %d %d %d\n", blueBits, greenBits, redBits);
+       vis->offsetRed = 0;
+       vis->redMask = (1 << redBits) - 1;
+       vis->offsetGreen = redBits;
+       vis->greenMask = ((1 << greenBits) - 1) << vis->offsetGreen;
+       vis->offsetBlue = vis->offsetGreen + greenBits;
+       vis->blueMask = ((1 << blueBits) - 1) << vis->offsetBlue;
+    }
+
+    rfbServerFormat.bitsPerPixel = prfb->bitsPerPixel;
+    rfbServerFormat.depth = prfb->depth;
+    rfbServerFormat.bigEndian = !(*(char *)&rfbEndianTest);
+    rfbServerFormat.trueColour = (vis->class == TrueColor);
+    if (rfbServerFormat.trueColour) {
+       rfbServerFormat.redMax = vis->redMask >> vis->offsetRed;
+       rfbServerFormat.greenMax = vis->greenMask >> vis->offsetGreen;
+       rfbServerFormat.blueMax = vis->blueMask >> vis->offsetBlue;
+       rfbServerFormat.redShift = vis->offsetRed;
+       rfbServerFormat.greenShift = vis->offsetGreen;
+       rfbServerFormat.blueShift = vis->offsetBlue;
+    } else {
+       rfbServerFormat.redMax
+           = rfbServerFormat.greenMax = rfbServerFormat.blueMax = 0;
+       rfbServerFormat.redShift
+           = rfbServerFormat.greenShift = rfbServerFormat.blueShift = 0;
+    }
+
+    if (prfb->bitsPerPixel == 1)
+    {
+       ret = mfbCreateDefColormap(pScreen);
+    }
+    else
+    {
+       ret = cfbCreateDefColormap(pScreen);
+    }
+
+    return ret;
+
+} /* end rfbScreenInit */
+
+
+
+/*
+ * InitInput is also called every time the server resets.  It is called after
+ * InitOutput so we can assume that rfbInitSockets has already been called.
+ */
+
+void
+InitInput(argc, argv)
+    int argc;
+    char *argv[];
+{
+    DeviceIntPtr p, k;
+    k = AddInputDevice(rfbKeybdProc, TRUE);
+    p = AddInputDevice(rfbMouseProc, TRUE);
+    RegisterKeyboardDevice(k);
+    RegisterPointerDevice(p);
+    miRegisterPointerDevice(screenInfo.screens[0], p);
+    mieqInit((DevicePtr)k, (DevicePtr)p);
+    mieqCheckForInput[0] = checkForInput[0];
+    mieqCheckForInput[1] = checkForInput[1];
+    SetInputCheck(&alwaysCheckForInput[0], &alwaysCheckForInput[1]);
+}
+
+
+static int
+rfbKeybdProc(pDevice, onoff)
+    DeviceIntPtr pDevice;
+    int onoff;
+{
+    KeySymsRec         keySyms;
+    CARD8              modMap[MAP_LENGTH];
+    DevicePtr pDev = (DevicePtr)pDevice;
+
+    switch (onoff)
+    {
+    case DEVICE_INIT: 
+       KbdDeviceInit(pDevice, &keySyms, modMap);
+       InitKeyboardDeviceStruct(pDev, &keySyms, modMap,
+                                (BellProcPtr)rfbSendBell,
+                                (KbdCtrlProcPtr)NoopDDA);
+           break;
+    case DEVICE_ON: 
+       pDev->on = TRUE;
+       KbdDeviceOn();
+       break;
+    case DEVICE_OFF: 
+       pDev->on = FALSE;
+       KbdDeviceOff();
+       break;
+    case DEVICE_CLOSE:
+       if (pDev->on)
+           KbdDeviceOff();
+       break;
+    }
+    return Success;
+}
+
+static int
+rfbMouseProc(pDevice, onoff)
+    DeviceIntPtr pDevice;
+    int onoff;
+{
+    BYTE map[6];
+    DevicePtr pDev = (DevicePtr)pDevice;
+
+    switch (onoff)
+    {
+    case DEVICE_INIT:
+       PtrDeviceInit();
+       map[1] = 1;
+       map[2] = 2;
+       map[3] = 3;
+       map[4] = 4;
+       map[5] = 5;
+       InitPointerDeviceStruct(pDev, map, 5, miPointerGetMotionEvents,
+                               PtrDeviceControl,
+                               miPointerGetMotionBufferSize());
+       break;
+
+    case DEVICE_ON:
+       pDev->on = TRUE;
+       PtrDeviceOn(pDevice);
+        break;
+
+    case DEVICE_OFF:
+       pDev->on = FALSE;
+       PtrDeviceOff();
+       break;
+
+    case DEVICE_CLOSE:
+       if (pDev->on)
+           PtrDeviceOff();
+       break;
+    }
+    return Success;
+}
+
+
+Bool
+LegalModifier(key, pDev)
+    unsigned int key;
+    DevicePtr  pDev;
+{
+    return TRUE;
+}
+
+
+void
+ProcessInputEvents()
+{
+    rfbCheckFds();
+    httpCheckFds();
+    if (*mieqCheckForInput[0] != *mieqCheckForInput[1]) {
+       mieqProcessInputEvents();
+       miPointerUpdate();
+    }
+}
+
+
+static Bool CheckDisplayNumber(int n)
+{
+    char fname[32];
+    int sock;
+    struct sockaddr_in addr;
+
+    sock = socket(AF_INET, SOCK_STREAM, 0);
+    addr.sin_family = AF_INET;
+    addr.sin_addr.s_addr = htonl(INADDR_ANY);
+    addr.sin_port = htons(6000+n);
+    if (bind(sock, (struct sockaddr *)&addr, sizeof(addr)) < 0) {
+       close(sock);
+       return FALSE;
+    }
+    close(sock);
+
+    sprintf(fname, "/tmp/.X%d-lock", n);
+    if (access(fname, F_OK) == 0)
+       return FALSE;
+
+    sprintf(fname, "/tmp/.X11-unix/X%d", n);
+    if (access(fname, F_OK) == 0)
+       return FALSE;
+
+    sprintf(fname, "/usr/spool/sockets/X11/%d", n);
+    if (access(fname, F_OK) == 0)
+       return FALSE;
+
+    return TRUE;
+}
+
+
+void
+rfbRootPropertyChange(PropertyPtr pProp)
+{
+    if ((pProp->propertyName == XA_CUT_BUFFER0) && (pProp->type == XA_STRING)
+       && (pProp->format == 8))
+    {
+       rfbGotXCutText(pProp->data, pProp->size);
+    }
+    else if ((pProp->propertyName == VNC_CONNECT) && (pProp->type == XA_STRING)
+             && (pProp->format == 8))
+    {
+       if (pProp->size == 0) {
+          rfbClientPtr cl, nextCl;
+          rfbLog("VNC_CONNECT message: disconnecting all clients\n");
+          for (cl = rfbClientHead; cl; cl = nextCl) {
+            nextCl = cl->next;
+            rfbCloseSock(cl->sock);
+          }
+        } else {
+          int i;
+          rfbClientPtr cl;
+          int port = 5500;
+          char *host = (char *)Xalloc(pProp->size+1);
+          memcpy(host, pProp->data, pProp->size);
+          host[pProp->size] = 0;
+          for (i = 0; i < pProp->size; i++) {
+           if (host[i] == ':') {
+              port = atoi(&host[i+1]);
+              host[i] = 0;
+           }
+          }
+
+          cl = rfbReverseConnection(host, port);
+
+          free(host);
+        }
+        return;
+    }
+    else if ((pProp->propertyName == VNC_DEFER_UPDATE) &&
+             (pProp->type == XA_STRING) && (pProp->format == 8))
+    {
+      char *str = (char *)Xalloc(pProp->size+1);
+      memcpy(str, pProp->data, pProp->size);
+      str[pProp->size] = 0;
+      rfbDeferUpdateTime = atoi(str);
+      free(str);
+    }
+}
+
+
+int
+rfbBitsPerPixel(depth)
+    int depth;
+{
+    if (depth == 1) return 1;
+    else if (depth <= 8) return 8;
+    else if (depth <= 16) return 16;
+    else return 32;
+}
+
+
+static Bool
+rfbAlwaysTrue()
+{
+    return TRUE;
+}
+
+
+static char *
+rfbAllocateFramebufferMemory(prfb)
+    rfbScreenInfoPtr prfb;
+{
+    if (prfb->pfbMemory) return prfb->pfbMemory; /* already done */
+
+    prfb->sizeInBytes = (prfb->paddedWidthInBytes * prfb->height);
+
+    prfb->pfbMemory = (char *)Xalloc(prfb->sizeInBytes);
+
+    return prfb->pfbMemory;
+}
+
+
+static Bool
+rfbCursorOffScreen (ppScreen, x, y)
+    ScreenPtr   *ppScreen;
+    int         *x, *y;
+{
+    return FALSE;
+}
+
+static void
+rfbCrossScreen (pScreen, entering)
+    ScreenPtr   pScreen;
+    Bool        entering;
+{
+}
+
+static void
+rfbClientStateChange(cbl, myData, clt)
+    CallbackListPtr *cbl;
+    pointer myData;
+    pointer clt;
+{
+    dispatchException &= ~DE_RESET;    /* hack - force server not to reset */
+}
+
+void
+ddxGiveUp()
+{
+    Xfree(rfbScreen.pfbMemory);
+    if (initOutputCalled) {
+       char unixSocketName[256];
+       sprintf(unixSocketName,"/tmp/.X11-unix/X%s",display);
+       unlink(unixSocketName);
+       sprintf(unixSocketName,"/usr/spool/sockets/X11/%s",display);
+       unlink(unixSocketName);
+    }
+}
+
+void
+AbortDDX()
+{
+    ddxGiveUp();
+}
+
+void
+OsVendorInit()
+{
+}
+
+void
+OsVendorFatalError()
+{
+}
+
+#ifdef DDXTIME /* from ServerOSDefines */
+CARD32
+GetTimeInMillis()
+{
+    struct timeval  tp;
+
+    X_GETTIMEOFDAY(&tp);
+    return(tp.tv_sec * 1000) + (tp.tv_usec / 1000);
+}
+#endif
+
+void
+ddxUseMsg()
+{
+    ErrorF("\nXvnc version %s - built %s\n\n", XVNCRELEASE, buildtime);
+    ErrorF("-geometry WxH          set framebuffer width & height\n");
+    ErrorF("-depth D               set framebuffer depth\n");
+    ErrorF("-pixelformat format    set pixel format (BGRnnn or RGBnnn)\n");
+    ErrorF("-rfbport port          TCP port for RFB protocol\n");
+    ErrorF("-rfbwait time          max time in ms to wait for RFB client\n");
+    ErrorF("-nocursor              don't put up a cursor\n");
+    ErrorF("-rfbauth passwd-file   use authentication on RFB protocol\n");
+    ErrorF("-httpd dir             serve files via HTTP from here\n");
+    ErrorF("-httpport port         port for HTTP\n");
+    ErrorF("-deferupdate time      time in ms to defer updates "
+                                                            "(default 40)\n");
+    ErrorF("-economictranslate     less memory-hungry translation\n");
+    ErrorF("-maxrects num          max number of rectangles in an update "
+                                                            "(default 50)\n");
+    ErrorF("-desktop name          VNC desktop name (default x11)\n");
+    ErrorF("-alwaysshared          always treat new clients as shared\n");
+    ErrorF("-nevershared           never treat new clients as shared\n");
+    ErrorF("-dontdisconnect        don't disconnect existing clients when a "
+                                                             "new non-shared\n"
+          "                       connection comes in (refuse new connection "
+                                                                "instead)\n");
+    ErrorF("-localhost             only allow connections from localhost\n");
+    ErrorF("-inetd                 Xvnc is launched by inetd\n");
+    exit(1);
+}
+
+/*
+ * rfbLog prints a time-stamped message to the log file (stderr).
+ */
+
+void rfbLog(char *format, ...)
+{
+    va_list args;
+    char buf[256];
+    time_t clock;
+
+    va_start(args, format);
+
+    time(&clock);
+    strftime(buf, 255, "%d/%m/%y %T ", localtime(&clock));
+    fprintf(stderr, buf);
+
+    vfprintf(stderr, format, args);
+    fflush(stderr);
+
+    va_end(args);
+}
+
+void rfbLogPerror(char *str)
+{
+    rfbLog("");
+    perror(str);
+}
diff --git a/Xserver/programs/Xserver/hw/vnc/kbdptr.c b/Xserver/programs/Xserver/hw/vnc/kbdptr.c
new file mode 100644 (file)
index 0000000..707755d
--- /dev/null
@@ -0,0 +1,600 @@
+/*
+ * kbdptr.c - deal with keyboard and pointer device over TCP & UDP.
+ *
+ *
+ */
+
+/*
+ *  Copyright (C) 2002-2003 RealVNC Ltd.
+ *  Copyright (C) 1999 AT&T Laboratories Cambridge.  All Rights Reserved.
+ *
+ *  This is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This software is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this software; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,
+ *  USA.
+ */
+
+#include <stdio.h>
+
+#include "X11/X.h"
+#define NEED_EVENTS
+#include "X11/Xproto.h"
+#include "inputstr.h"
+#define XK_CYRILLIC
+#include <X11/keysym.h>
+#include <mi.h>
+#include <mipointer.h>
+#include <property.h>
+#include <Xatom.h>
+#include "rfb.h"
+
+extern WindowPtr *WindowTable; /* Why isn't this in a header file? */
+
+#define KEY_IS_PRESSED(keycode) \
+    (kbdDevice->key->down[(keycode) >> 3] & (1 << ((keycode) & 7)))
+
+
+static void XConvertCase(KeySym sym, KeySym *lower, KeySym *upper);
+
+static DeviceIntPtr kbdDevice;
+
+#define MIN_KEY_CODE           8
+#define MAX_KEY_CODE           255
+#define NO_OF_KEYS             (MAX_KEY_CODE - MIN_KEY_CODE + 1)
+#define GLYPHS_PER_KEY         2
+
+static KeySym kbdMap[] = {
+
+    /* Modifiers */
+
+    XK_Control_L,      NoSymbol,
+#define CONTROL_L_KEY_CODE     MIN_KEY_CODE
+
+    XK_Control_R,      NoSymbol,
+#define CONTROL_R_KEY_CODE     (MIN_KEY_CODE + 1)
+
+    XK_Shift_L,                NoSymbol,
+#define SHIFT_L_KEY_CODE       (MIN_KEY_CODE + 2)
+
+    XK_Shift_R,                NoSymbol,
+#define SHIFT_R_KEY_CODE       (MIN_KEY_CODE + 3)
+
+    XK_Meta_L,         NoSymbol,
+#define META_L_KEY_CODE                (MIN_KEY_CODE + 4)
+
+    XK_Meta_R,         NoSymbol,
+#define META_R_KEY_CODE                (MIN_KEY_CODE + 5)
+
+    XK_Alt_L,          NoSymbol,
+#define ALT_L_KEY_CODE         (MIN_KEY_CODE + 6)
+
+    XK_Alt_R,          NoSymbol,
+#define ALT_R_KEY_CODE         (MIN_KEY_CODE + 7)
+
+    /* Standard US keyboard */
+
+    XK_space,          NoSymbol,
+    XK_0,              XK_parenright,
+    XK_1,              XK_exclam,
+    XK_2,              XK_at,
+    XK_3,              XK_numbersign,
+    XK_4,              XK_dollar,
+    XK_5,              XK_percent,
+    XK_6,              XK_asciicircum,
+    XK_7,              XK_ampersand,
+    XK_8,              XK_asterisk,
+    XK_9,              XK_parenleft,
+
+    XK_minus,          XK_underscore,
+    XK_equal,          XK_plus,
+    XK_bracketleft,    XK_braceleft,
+    XK_bracketright,   XK_braceright,
+    XK_semicolon,      XK_colon,
+    XK_apostrophe,     XK_quotedbl,
+    XK_grave,          XK_asciitilde,
+    XK_comma,          XK_less,
+    XK_period,         XK_greater,
+    XK_slash,          XK_question,
+    XK_backslash,      XK_bar,
+
+    XK_a,              XK_A,
+    XK_b,              XK_B,
+    XK_c,              XK_C,
+    XK_d,              XK_D,
+    XK_e,              XK_E,
+    XK_f,              XK_F,
+    XK_g,              XK_G,
+    XK_h,              XK_H,
+    XK_i,              XK_I,
+    XK_j,              XK_J,
+    XK_k,              XK_K,
+    XK_l,              XK_L,
+    XK_m,              XK_M,
+    XK_n,              XK_N,
+    XK_o,              XK_O,
+    XK_p,              XK_P,
+    XK_q,              XK_Q,
+    XK_r,              XK_R,
+    XK_s,              XK_S,
+    XK_t,              XK_T,
+    XK_u,              XK_U,
+    XK_v,              XK_V,
+    XK_w,              XK_W,
+    XK_x,              XK_X,
+    XK_y,              XK_Y,
+    XK_z,              XK_Z,
+
+    /* Other useful keys */
+
+    XK_BackSpace,      NoSymbol,
+    XK_Return,         NoSymbol,
+    XK_Tab,            NoSymbol,
+    XK_Escape,         NoSymbol,
+    XK_Delete,         NoSymbol,
+
+    XK_Home,           NoSymbol,
+    XK_End,            NoSymbol,
+    XK_Page_Up,                NoSymbol,
+    XK_Page_Down,      NoSymbol,
+    XK_Up,             NoSymbol,
+    XK_Down,           NoSymbol,
+    XK_Left,           NoSymbol,
+    XK_Right,          NoSymbol,
+
+    XK_F1,             NoSymbol,
+    XK_F2,             NoSymbol,
+    XK_F3,             NoSymbol,
+    XK_F4,             NoSymbol,
+    XK_F5,             NoSymbol,
+    XK_F6,             NoSymbol,
+    XK_F7,             NoSymbol,
+    XK_F8,             NoSymbol,
+    XK_F9,             NoSymbol,
+    XK_F10,            NoSymbol,
+    XK_F11,            NoSymbol,
+    XK_F12,            NoSymbol,
+
+    /* Plus blank ones which can be filled in using xmodmap */
+
+};
+
+#define N_PREDEFINED_KEYS (sizeof(kbdMap) / (sizeof(KeySym) * GLYPHS_PER_KEY))
+
+
+void
+PtrDeviceInit()
+{
+}
+
+
+void
+KbdDeviceInit(pDevice, pKeySyms, pModMap)
+    DeviceIntPtr pDevice;
+    KeySymsPtr pKeySyms;
+    CARD8 *pModMap;
+{
+    int i;
+
+    kbdDevice = pDevice;
+
+    for (i = 0; i < MAP_LENGTH; i++)
+       pModMap[i] = NoSymbol;
+
+    pModMap[CONTROL_L_KEY_CODE] = ControlMask;
+    pModMap[CONTROL_R_KEY_CODE] = ControlMask;
+    pModMap[SHIFT_L_KEY_CODE] = ShiftMask;
+    pModMap[SHIFT_R_KEY_CODE] = ShiftMask;
+    pModMap[META_L_KEY_CODE] = Mod1Mask;
+    pModMap[META_R_KEY_CODE] = Mod1Mask;
+    pModMap[ALT_L_KEY_CODE] = Mod1Mask;
+    pModMap[ALT_R_KEY_CODE] = Mod1Mask;
+
+    pKeySyms->minKeyCode = MIN_KEY_CODE;
+    pKeySyms->maxKeyCode = MAX_KEY_CODE;
+    pKeySyms->mapWidth = GLYPHS_PER_KEY;
+
+    pKeySyms->map = (KeySym *)xalloc(sizeof(KeySym)
+                                    * MAP_LENGTH * GLYPHS_PER_KEY);
+
+    if (!pKeySyms->map) {
+       rfbLog("xalloc failed\n");
+       exit(1);
+    }
+
+    for (i = 0; i < MAP_LENGTH * GLYPHS_PER_KEY; i++)
+       pKeySyms->map[i] = NoSymbol;
+
+    for (i = 0; i < N_PREDEFINED_KEYS * GLYPHS_PER_KEY; i++) {
+       pKeySyms->map[i] = kbdMap[i];
+    }
+}
+
+
+
+void
+KbdDeviceOn()
+{
+}
+
+
+void
+KbdDeviceOff()
+{
+}
+
+
+void
+PtrDeviceOn(pDev)
+    DeviceIntPtr pDev;
+{
+}
+
+
+void
+PtrDeviceOff()
+{
+}
+
+
+void
+PtrDeviceControl(dev, ctrl)
+    DevicePtr dev;
+    PtrCtrl *ctrl;
+{
+}
+
+
+void
+KbdAddEvent(down, keySym, cl)
+    Bool down;
+    KeySym keySym;
+    rfbClientPtr cl;
+{
+    xEvent ev, fake;
+    KeySymsPtr keySyms = &kbdDevice->key->curKeySyms;
+    int i;
+    int keyCode = 0;
+    int freeIndex = -1;
+    unsigned long time;
+    Bool fakeShiftPress = FALSE;
+    Bool fakeShiftLRelease = FALSE;
+    Bool fakeShiftRRelease = FALSE;
+    Bool shiftMustBeReleased = FALSE;
+    Bool shiftMustBePressed = FALSE;
+
+    if (cl) {
+       CARD32 clientId = cl->sock;
+       ChangeWindowProperty(WindowTable[0], VNC_LAST_CLIENT_ID, XA_INTEGER,
+                            32, PropModeReplace, 1, (pointer)&clientId, TRUE);
+    }
+
+    if (down) {
+        if (rfbTrace) rfbLog("KeyPress: 0x%x\n",keySym);
+       ev.u.u.type = KeyPress;
+    } else {
+       ev.u.u.type = KeyRelease;
+    }
+
+    /* First check if it's one of our predefined keys.  If so then we can make
+       some attempt at allowing an xmodmap inside a VNC desktop behave
+       something like you'd expect - e.g. if keys A & B are swapped over and
+       the VNC client sends an A, then map it to a B when generating the X
+       event.  We don't attempt to do this for keycodes which we make up on the
+       fly because it's too hard... */
+
+    for (i = 0; i < N_PREDEFINED_KEYS * GLYPHS_PER_KEY; i++) {
+       if (keySym == kbdMap[i]) {
+           keyCode = MIN_KEY_CODE + i / GLYPHS_PER_KEY;
+
+           if (kbdMap[(i/GLYPHS_PER_KEY) * GLYPHS_PER_KEY + 1] != NoSymbol) {
+
+               /* this keycode has more than one symbol associated with it,
+                  so shift state is important */
+
+               if ((i % GLYPHS_PER_KEY) == 0)
+                   shiftMustBeReleased = TRUE;
+               else
+                   shiftMustBePressed = TRUE;
+           }
+           break;
+       }
+    }
+
+    if (!keyCode) {
+
+       /* not one of our predefined keys - see if it's in the current keyboard
+           mapping (i.e. we've already allocated an extra keycode for it) */
+
+       if (keySyms->mapWidth < 2) {
+           rfbLog("KbdAddEvent: Sanity check failed - Keyboard mapping has "
+                  "less than 2 keysyms per keycode (KeySym 0x%x)\n", keySym);
+           return;
+       }
+
+       for (i = 0; i < NO_OF_KEYS * keySyms->mapWidth; i++) {
+           if (keySym == keySyms->map[i]) {
+               keyCode = MIN_KEY_CODE + i / keySyms->mapWidth;
+
+               if (keySyms->map[(i / keySyms->mapWidth)
+                                       * keySyms->mapWidth + 1] != NoSymbol) {
+
+                   /* this keycode has more than one symbol associated with
+                      it, so shift state is important */
+
+                   if ((i % keySyms->mapWidth) == 0)
+                       shiftMustBeReleased = TRUE;
+                   else
+                       shiftMustBePressed = TRUE;
+               }
+               break;
+           }
+           if ((freeIndex == -1) && (keySyms->map[i] == NoSymbol)
+               && (i % keySyms->mapWidth) == 0)
+           {
+               freeIndex = i;
+           }
+       }
+    }
+
+    if (!keyCode) {
+       KeySym lower, upper;
+
+       /* we don't have an existing keycode - make one up on the fly and add
+          it to the keyboard mapping.  Thanks to Vlad Harchev for pointing
+          out problems with non-ascii capitalisation. */
+
+       if (freeIndex == -1) {
+           rfbLog("KbdAddEvent: ignoring KeySym 0x%x - no free KeyCodes\n",
+                  keySym);
+           return;
+       }
+
+       keyCode = MIN_KEY_CODE + freeIndex / keySyms->mapWidth;
+
+       XConvertCase(keySym, &lower, &upper);
+
+       if (lower == upper) {
+           keySyms->map[freeIndex] = keySym;
+
+       } else {
+           keySyms->map[freeIndex] = lower;
+           keySyms->map[freeIndex+1] = upper;
+
+           if (keySym == lower)
+               shiftMustBeReleased = TRUE;
+           else
+               shiftMustBePressed = TRUE;
+       }
+
+       SendMappingNotify(MappingKeyboard, keyCode, 1, serverClient);
+
+       rfbLog("KbdAddEvent: unknown KeySym 0x%x - allocating KeyCode %d\n",
+              keySym, keyCode);
+    }
+
+    time = GetTimeInMillis();
+
+    if (down) {
+       if (shiftMustBePressed && !(kbdDevice->key->state & ShiftMask)) {
+           fakeShiftPress = TRUE;
+           fake.u.u.type = KeyPress;
+           fake.u.u.detail = SHIFT_L_KEY_CODE;
+           fake.u.keyButtonPointer.time = time;
+           mieqEnqueue(&fake);
+       }
+       if (shiftMustBeReleased && (kbdDevice->key->state & ShiftMask)) {
+           if (KEY_IS_PRESSED(SHIFT_L_KEY_CODE)) {
+               fakeShiftLRelease = TRUE;
+               fake.u.u.type = KeyRelease;
+               fake.u.u.detail = SHIFT_L_KEY_CODE;
+               fake.u.keyButtonPointer.time = time;
+               mieqEnqueue(&fake);
+           }
+           if (KEY_IS_PRESSED(SHIFT_R_KEY_CODE)) {
+               fakeShiftRRelease = TRUE;
+               fake.u.u.type = KeyRelease;
+               fake.u.u.detail = SHIFT_R_KEY_CODE;
+               fake.u.keyButtonPointer.time = time;
+               mieqEnqueue(&fake);
+           }
+       }
+    }
+
+    ev.u.u.detail = keyCode;
+    ev.u.keyButtonPointer.time = time;
+    mieqEnqueue(&ev);
+
+    if (fakeShiftPress) {
+       fake.u.u.type = KeyRelease;
+       fake.u.u.detail = SHIFT_L_KEY_CODE;
+       fake.u.keyButtonPointer.time = time;
+       mieqEnqueue(&fake);
+    }
+    if (fakeShiftLRelease) {
+       fake.u.u.type = KeyPress;
+       fake.u.u.detail = SHIFT_L_KEY_CODE;
+       fake.u.keyButtonPointer.time = time;
+       mieqEnqueue(&fake);
+    }
+    if (fakeShiftRRelease) {
+       fake.u.u.type = KeyPress;
+       fake.u.u.detail = SHIFT_R_KEY_CODE;
+       fake.u.keyButtonPointer.time = time;
+       mieqEnqueue(&fake);
+    }
+}
+
+void
+PtrAddEvent(buttonMask, x, y, cl)
+    int buttonMask;
+    int x;
+    int y;
+    rfbClientPtr cl;
+{
+    xEvent ev;
+    int i;
+    unsigned long time;
+    static int oldButtonMask = 0;
+
+    if (cl) {
+       CARD32 clientId = cl->sock;
+       ChangeWindowProperty(WindowTable[0], VNC_LAST_CLIENT_ID, XA_INTEGER,
+                            32, PropModeReplace, 1, (pointer)&clientId, TRUE);
+    }
+
+    time = GetTimeInMillis();
+
+    miPointerAbsoluteCursor(x, y, time);
+
+    for (i = 0; i < 5; i++) {
+       if ((buttonMask ^ oldButtonMask) & (1<<i)) {
+           if (buttonMask & (1<<i)) {
+               ev.u.u.type = ButtonPress;
+               ev.u.u.detail = i + 1;
+               ev.u.keyButtonPointer.time = time;
+               mieqEnqueue(&ev);
+           } else {
+               ev.u.u.type = ButtonRelease;
+               ev.u.u.detail = i + 1;
+               ev.u.keyButtonPointer.time = time;
+               mieqEnqueue(&ev);
+           }
+       }
+    }
+
+    oldButtonMask = buttonMask;
+}
+
+void
+KbdReleaseAllKeys()
+{
+    int i, j;
+    xEvent ev;
+    unsigned long time = GetTimeInMillis();
+
+    for (i = 0; i < DOWN_LENGTH; i++) {
+       if (kbdDevice->key->down[i] != 0) {
+           for (j = 0; j < 8; j++) {
+               if (kbdDevice->key->down[i] & (1 << j)) {
+                   ev.u.u.type = KeyRelease;
+                   ev.u.u.detail = (i << 3) | j;
+                   ev.u.keyButtonPointer.time = time;
+                   mieqEnqueue(&ev);
+               }
+           }
+       }
+    }
+}
+
+
+/* copied from Xlib source */
+
+static void XConvertCase(KeySym sym, KeySym *lower, KeySym *upper)
+{
+    *lower = sym;
+    *upper = sym;
+    switch(sym >> 8) {
+    case 0: /* Latin 1 */
+       if ((sym >= XK_A) && (sym <= XK_Z))
+           *lower += (XK_a - XK_A);
+       else if ((sym >= XK_a) && (sym <= XK_z))
+           *upper -= (XK_a - XK_A);
+       else if ((sym >= XK_Agrave) && (sym <= XK_Odiaeresis))
+           *lower += (XK_agrave - XK_Agrave);
+       else if ((sym >= XK_agrave) && (sym <= XK_odiaeresis))
+           *upper -= (XK_agrave - XK_Agrave);
+       else if ((sym >= XK_Ooblique) && (sym <= XK_Thorn))
+           *lower += (XK_oslash - XK_Ooblique);
+       else if ((sym >= XK_oslash) && (sym <= XK_thorn))
+           *upper -= (XK_oslash - XK_Ooblique);
+       break;
+    case 1: /* Latin 2 */
+       /* Assume the KeySym is a legal value (ignore discontinuities) */
+       if (sym == XK_Aogonek)
+           *lower = XK_aogonek;
+       else if (sym >= XK_Lstroke && sym <= XK_Sacute)
+           *lower += (XK_lstroke - XK_Lstroke);
+       else if (sym >= XK_Scaron && sym <= XK_Zacute)
+           *lower += (XK_scaron - XK_Scaron);
+       else if (sym >= XK_Zcaron && sym <= XK_Zabovedot)
+           *lower += (XK_zcaron - XK_Zcaron);
+       else if (sym == XK_aogonek)
+           *upper = XK_Aogonek;
+       else if (sym >= XK_lstroke && sym <= XK_sacute)
+           *upper -= (XK_lstroke - XK_Lstroke);
+       else if (sym >= XK_scaron && sym <= XK_zacute)
+           *upper -= (XK_scaron - XK_Scaron);
+       else if (sym >= XK_zcaron && sym <= XK_zabovedot)
+           *upper -= (XK_zcaron - XK_Zcaron);
+       else if (sym >= XK_Racute && sym <= XK_Tcedilla)
+           *lower += (XK_racute - XK_Racute);
+       else if (sym >= XK_racute && sym <= XK_tcedilla)
+           *upper -= (XK_racute - XK_Racute);
+       break;
+    case 2: /* Latin 3 */
+       /* Assume the KeySym is a legal value (ignore discontinuities) */
+       if (sym >= XK_Hstroke && sym <= XK_Hcircumflex)
+           *lower += (XK_hstroke - XK_Hstroke);
+       else if (sym >= XK_Gbreve && sym <= XK_Jcircumflex)
+           *lower += (XK_gbreve - XK_Gbreve);
+       else if (sym >= XK_hstroke && sym <= XK_hcircumflex)
+           *upper -= (XK_hstroke - XK_Hstroke);
+       else if (sym >= XK_gbreve && sym <= XK_jcircumflex)
+           *upper -= (XK_gbreve - XK_Gbreve);
+       else if (sym >= XK_Cabovedot && sym <= XK_Scircumflex)
+           *lower += (XK_cabovedot - XK_Cabovedot);
+       else if (sym >= XK_cabovedot && sym <= XK_scircumflex)
+           *upper -= (XK_cabovedot - XK_Cabovedot);
+       break;
+    case 3: /* Latin 4 */
+       /* Assume the KeySym is a legal value (ignore discontinuities) */
+       if (sym >= XK_Rcedilla && sym <= XK_Tslash)
+           *lower += (XK_rcedilla - XK_Rcedilla);
+       else if (sym >= XK_rcedilla && sym <= XK_tslash)
+           *upper -= (XK_rcedilla - XK_Rcedilla);
+       else if (sym == XK_ENG)
+           *lower = XK_eng;
+       else if (sym == XK_eng)
+           *upper = XK_ENG;
+       else if (sym >= XK_Amacron && sym <= XK_Umacron)
+           *lower += (XK_amacron - XK_Amacron);
+       else if (sym >= XK_amacron && sym <= XK_umacron)
+           *upper -= (XK_amacron - XK_Amacron);
+       break;
+    case 6: /* Cyrillic */
+       /* Assume the KeySym is a legal value (ignore discontinuities) */
+       if (sym >= XK_Serbian_DJE && sym <= XK_Serbian_DZE)
+           *lower -= (XK_Serbian_DJE - XK_Serbian_dje);
+       else if (sym >= XK_Serbian_dje && sym <= XK_Serbian_dze)
+           *upper += (XK_Serbian_DJE - XK_Serbian_dje);
+       else if (sym >= XK_Cyrillic_YU && sym <= XK_Cyrillic_HARDSIGN)
+           *lower -= (XK_Cyrillic_YU - XK_Cyrillic_yu);
+       else if (sym >= XK_Cyrillic_yu && sym <= XK_Cyrillic_hardsign)
+           *upper += (XK_Cyrillic_YU - XK_Cyrillic_yu);
+        break;
+    case 7: /* Greek */
+       /* Assume the KeySym is a legal value (ignore discontinuities) */
+       if (sym >= XK_Greek_ALPHAaccent && sym <= XK_Greek_OMEGAaccent)
+           *lower += (XK_Greek_alphaaccent - XK_Greek_ALPHAaccent);
+       else if (sym >= XK_Greek_alphaaccent && sym <= XK_Greek_omegaaccent &&
+                sym != XK_Greek_iotaaccentdieresis &&
+                sym != XK_Greek_upsilonaccentdieresis)
+           *upper -= (XK_Greek_alphaaccent - XK_Greek_ALPHAaccent);
+       else if (sym >= XK_Greek_ALPHA && sym <= XK_Greek_OMEGA)
+           *lower += (XK_Greek_alpha - XK_Greek_ALPHA);
+       else if (sym >= XK_Greek_alpha && sym <= XK_Greek_omega &&
+                sym != XK_Greek_finalsmallsigma)
+           *upper -= (XK_Greek_alpha - XK_Greek_ALPHA);
+        break;
+    }
+}
diff --git a/Xserver/programs/Xserver/hw/vnc/rfb.h b/Xserver/programs/Xserver/hw/vnc/rfb.h
new file mode 100644 (file)
index 0000000..ebc70a0
--- /dev/null
@@ -0,0 +1,451 @@
+/*
+ * rfb.h - header file for RFB DDX implementation.
+ */
+
+/*
+ *  Copyright (C) 2002-2003 RealVNC Ltd.
+ *  Copyright (C) 1999 AT&T Laboratories Cambridge.  All Rights Reserved.
+ *
+ *  This is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This software is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this software; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,
+ *  USA.
+ */
+
+#include "scrnintstr.h"
+#include "colormapst.h"
+#include "gcstruct.h"
+#include "osdep.h"
+#include <rfb/rfbproto.h>
+#include <rfb/vncauth.h>
+
+#define MAX_ENCODINGS 20
+
+extern char *display;
+
+
+/*
+ * Per-screen (framebuffer) structure.  There is only one of these, since we
+ * don't allow the X server to have multiple screens.
+ */
+
+typedef struct
+{
+    int width;
+    int paddedWidthInBytes;
+    int height;
+    int depth;
+    int bitsPerPixel;
+    int sizeInBytes;
+    char *pfbMemory;
+    Pixel blackPixel;
+    Pixel whitePixel;
+
+    /* The following two members are used to minimise the amount of unnecessary
+       drawing caused by cursor movement.  Whenever any drawing affects the
+       part of the screen where the cursor is, the cursor is removed first and
+       then the drawing is done (this is what the sprite routines test for).
+       Afterwards, however, we do not replace the cursor, even when the cursor
+       is logically being moved across the screen.  We only draw the cursor
+       again just as we are about to send the client a framebuffer update.
+
+       We need to be careful when removing and drawing the cursor because of
+       their relationship with the normal drawing routines.  The drawing
+       routines can invoke the cursor routines, but also the cursor routines
+       themselves end up invoking drawing routines.
+
+       Removing the cursor (rfbSpriteRemoveCursor) is eventually achieved by
+       doing a CopyArea from a pixmap to the screen, where the pixmap contains
+       the saved contents of the screen under the cursor.  Before doing this,
+       however, we set cursorIsDrawn to FALSE.  Then, when CopyArea is called,
+       it sees that cursorIsDrawn is FALSE and so doesn't feel the need to
+       (recursively!) remove the cursor before doing it.
+
+       Putting up the cursor (rfbSpriteRestoreCursor) involves a call to
+       PushPixels.  While this is happening, cursorIsDrawn must be FALSE so
+       that PushPixels doesn't think it has to remove the cursor first.
+       Obviously cursorIsDrawn is set to TRUE afterwards.
+
+       Another problem we face is that drawing routines sometimes cause a
+       framebuffer update to be sent to the RFB client.  When the RFB client is
+       already waiting for a framebuffer update and some drawing to the
+       framebuffer then happens, the drawing routine sees that the client is
+       ready, so it calls rfbSendFramebufferUpdate.  If the cursor is not drawn
+       at this stage, it must be put up, and so rfbSpriteRestoreCursor is
+       called.  However, if the original drawing routine was actually called
+       from within rfbSpriteRestoreCursor or rfbSpriteRemoveCursor we don't
+       want this to happen.  So both the cursor routines set
+       dontSendFramebufferUpdate to TRUE, and all the drawing routines check
+       this before calling rfbSendFramebufferUpdate. */
+
+    Bool cursorIsDrawn;                    /* TRUE if the cursor is currently drawn */
+    Bool dontSendFramebufferUpdate; /* TRUE while removing or drawing the
+                                      cursor */
+
+    /* wrapped screen functions */
+
+    CloseScreenProcPtr                 CloseScreen;
+    CreateGCProcPtr                    CreateGC;
+    PaintWindowBackgroundProcPtr       PaintWindowBackground;
+    PaintWindowBorderProcPtr           PaintWindowBorder;
+    CopyWindowProcPtr                  CopyWindow;
+    ClearToBackgroundProcPtr           ClearToBackground;
+    RestoreAreasProcPtr                        RestoreAreas;
+
+} rfbScreenInfo, *rfbScreenInfoPtr;
+
+
+/*
+ * rfbTranslateFnType is the type of translation functions.
+ */
+
+struct rfbClientRec;
+typedef void (*rfbTranslateFnType)(char *table, rfbPixelFormat *in,
+                                  rfbPixelFormat *out,
+                                  char *iptr, char *optr,
+                                  int bytesBetweenInputLines,
+                                  int width, int height);
+
+
+/*
+ * Per-client structure.
+ */
+
+typedef struct rfbClientRec {
+
+    int sock;
+    char *host;
+                               /* Possible client states: */
+    enum {
+       RFB_PROTOCOL_VERSION,   /* establishing protocol version */
+       RFB_AUTHENTICATION,     /* authenticating */
+       RFB_INITIALISATION,     /* sending initialisation messages */
+       RFB_NORMAL              /* normal protocol messages */
+    } state;
+
+    Bool reverseConnection;
+
+    Bool readyForSetColourMapEntries;
+
+    Bool useCopyRect;
+    int preferredEncoding;
+    int correMaxWidth, correMaxHeight;
+    void* zrleData;
+
+    /* The following member is only used during VNC authentication */
+
+    CARD8 authChallenge[CHALLENGESIZE];
+
+    /* The following members represent the update needed to get the client's
+       framebuffer from its present state to the current state of our
+       framebuffer.
+
+       If the client does not accept CopyRect encoding then the update is
+       simply represented as the region of the screen which has been modified
+       (modifiedRegion).
+
+       If the client does accept CopyRect encoding, then the update consists of
+       two parts.  First we have a single copy from one region of the screen to
+       another (the destination of the copy is copyRegion), and second we have
+       the region of the screen which has been modified in some other way
+       (modifiedRegion).
+
+       Although the copy is of a single region, this region may have many
+       rectangles.  When sending an update, the copyRegion is always sent
+       before the modifiedRegion.  This is because the modifiedRegion may
+       overlap parts of the screen which are in the source of the copy.
+
+       In fact during normal processing, the modifiedRegion may even overlap
+       the destination copyRegion.  Just before an update is sent we remove
+       from the copyRegion anything in the modifiedRegion. */
+
+    RegionRec copyRegion;      /* the destination region of the copy */
+    int copyDX, copyDY;                /* the translation by which the copy happens */
+
+    RegionRec modifiedRegion;  /* the region of the screen modified in any
+                                  other way */
+
+    /* As part of the FramebufferUpdateRequest, a client can express interest
+       in a subrectangle of the whole framebuffer.  This is stored in the
+       requestedRegion member.  In the normal case this is the whole
+       framebuffer if the client is ready, empty if it's not. */
+
+    RegionRec requestedRegion;
+
+    /* The following members represent the state of the "deferred update" timer
+       - when the framebuffer is modified and the client is ready, in most
+       cases it is more efficient to defer sending the update by a few
+       milliseconds so that several changes to the framebuffer can be combined
+       into a single update. */
+
+    Bool deferredUpdateScheduled;
+    OsTimerPtr deferredUpdateTimer;
+
+    /* translateFn points to the translation function which is used to copy
+       and translate a rectangle from the framebuffer to an output buffer. */
+
+    rfbTranslateFnType translateFn;
+
+    char *translateLookupTable;
+
+    rfbPixelFormat format;
+
+    /* statistics */
+
+    int rfbBytesSent[MAX_ENCODINGS];
+    int rfbRectanglesSent[MAX_ENCODINGS];
+    int rfbFramebufferUpdateMessagesSent;
+    int rfbRawBytesEquivalent;
+    int rfbKeyEventsRcvd;
+    int rfbPointerEventsRcvd;
+
+    struct rfbClientRec *next;
+
+} rfbClientRec, *rfbClientPtr;
+
+
+/*
+ * This macro is used to test whether there is a framebuffer update needing to
+ * be sent to the client.
+ */
+
+#define FB_UPDATE_PENDING(cl)                          \
+    (!rfbScreen.cursorIsDrawn ||                       \
+     REGION_NOTEMPTY((pScreen),&(cl)->copyRegion) ||   \
+     REGION_NOTEMPTY((pScreen),&(cl)->modifiedRegion))
+
+/*
+ * This macro creates an empty region (ie. a region with no areas) if it is
+ * given a rectangle with a width or height of zero. It appears that 
+ * REGION_INTERSECT does not quite do the right thing with zero-width
+ * rectangles, but it should with completely empty regions.
+ */
+
+#define SAFE_REGION_INIT(pscreen, preg, rect, size)          \
+{                                                            \
+      if ( ( (rect) ) &&                                     \
+           ( ( (rect)->x2 == (rect)->x1 ) ||                 \
+            ( (rect)->y2 == (rect)->y1 ) ) ) {              \
+         REGION_INIT( (pscreen), (preg), NullBox, 0 );      \
+      } else {                                               \
+         REGION_INIT( (pscreen), (preg), (rect), (size) );  \
+      }                                                      \
+}
+
+/*
+ * An rfbGCRec is where we store the pointers to the original GC funcs and ops
+ * which we wrap (NULL means not wrapped).
+ */
+
+typedef struct {
+    GCFuncs *wrapFuncs;
+    GCOps *wrapOps;
+} rfbGCRec, *rfbGCPtr;
+
+
+
+/*
+ * Macros for endian swapping.
+ */
+
+#define Swap16(s) ((((s) & 0xff) << 8) | (((s) >> 8) & 0xff))
+
+#define Swap32(l) (((l) >> 24) | \
+                  (((l) & 0x00ff0000) >> 8)  | \
+                  (((l) & 0x0000ff00) << 8)  | \
+                  ((l) << 24))
+
+
+/* init.c */
+
+static const int rfbEndianTest = 1;
+
+#define Swap16IfLE(s) (*(const char *)&rfbEndianTest ? Swap16(s) : (s))
+
+#define Swap32IfLE(l) (*(const char *)&rfbEndianTest ? Swap32(l) : (l))
+
+extern char *desktopName;
+extern Bool rfbTrace;
+extern char rfbThisHost[];
+extern Atom VNC_LAST_CLIENT_ID;
+
+extern rfbScreenInfo rfbScreen;
+extern int rfbGCIndex;
+
+extern int inetdSock;
+
+extern int rfbBitsPerPixel(int depth);
+extern void rfbLog(char *format, ...);
+extern void rfbLogPerror(char *str);
+
+
+/* sockets.c */
+
+extern int rfbMaxClientWait;
+
+extern int rfbPort;
+extern int rfbListenSock;
+extern Bool rfbLocalhostOnly;
+
+extern void rfbInitSockets();
+extern void rfbCloseSock();
+extern void rfbCheckFds();
+extern void rfbWaitForClient(int sock);
+extern int rfbConnect(char *host, int port);
+
+extern int ReadExact(int sock, char *buf, int len);
+extern int WriteExact(int sock, char *buf, int len);
+extern int ListenOnTCPPort(int port);
+extern int ConnectToTcpAddr(char *host, int port);
+
+
+/* cmap.c */
+
+extern ColormapPtr rfbInstalledColormap;
+
+extern int rfbListInstalledColormaps(ScreenPtr pScreen, Colormap *pmaps);
+extern void rfbInstallColormap(ColormapPtr pmap);
+extern void rfbUninstallColormap(ColormapPtr pmap);
+extern void rfbStoreColors(ColormapPtr pmap, int ndef, xColorItem *pdefs);
+
+
+/* draw.c */
+
+extern int rfbDeferUpdateTime;
+
+extern Bool rfbCloseScreen(int,ScreenPtr);
+extern Bool rfbCreateGC(GCPtr);
+extern void rfbPaintWindowBackground(WindowPtr, RegionPtr, int what);
+extern void rfbPaintWindowBorder(WindowPtr, RegionPtr, int what);
+extern void rfbCopyWindow(WindowPtr, DDXPointRec, RegionPtr);
+extern void rfbClearToBackground(WindowPtr, int x, int y, int w,
+                                int h, Bool generateExposures);
+extern RegionPtr rfbRestoreAreas(WindowPtr, RegionPtr);
+extern void rfbScheduleDeferredUpdate(rfbClientPtr cl);
+
+
+/* cutpaste.c */
+
+extern void rfbSetXCutText(char *str, int len);
+extern void rfbGotXCutText(char *str, int len);
+
+
+/* kbdptr.c */
+
+extern void PtrDeviceInit();
+extern void PtrDeviceOn();
+extern void PtrDeviceOff();
+extern void PtrDeviceControl();
+extern void PtrAddEvent(int buttonMask, int x, int y, rfbClientPtr cl);
+
+extern void KbdDeviceInit();
+extern void KbdDeviceOn();
+extern void KbdDeviceOff();
+extern void KbdAddEvent(Bool down, KeySym keySym, rfbClientPtr cl);
+extern void KbdReleaseAllKeys();
+
+
+/* rfbserver.c */
+
+/*
+ * UPDATE_BUF_SIZE must be big enough to send at least one whole line of the
+ * framebuffer.  So for a max screen width of say 2K with 32-bit pixels this
+ * means 8K minimum.
+ */
+
+#define UPDATE_BUF_SIZE 30000
+extern char updateBuf[UPDATE_BUF_SIZE];
+extern int ublen;
+
+extern rfbClientPtr rfbClientHead;
+extern rfbClientPtr pointerClient;
+
+extern Bool rfbAlwaysShared;
+extern Bool rfbNeverShared;
+extern Bool rfbDontDisconnect;
+extern int rfbMaxRects;
+
+extern void rfbNewClientConnection(int sock);
+extern rfbClientPtr rfbReverseConnection(char *host, int port);
+extern void rfbClientConnectionGone(int sock);
+extern void rfbProcessClientMessage(int sock);
+extern void rfbClientConnFailed(rfbClientPtr cl, char *reason);
+extern Bool rfbSendFramebufferUpdate(rfbClientPtr cl);
+extern Bool rfbSendRectEncodingRaw(rfbClientPtr cl, int x,int y,int w,int h);
+extern Bool rfbSendUpdateBuf(rfbClientPtr cl);
+extern Bool rfbSendSetColourMapEntries(rfbClientPtr cl, int firstColour,
+                                      int nColours);
+extern void rfbSendBell();
+extern void rfbSendServerCutText(char *str, int len);
+
+
+/* translate.c */
+
+extern Bool rfbEconomicTranslate;
+extern rfbPixelFormat rfbServerFormat;
+
+extern void rfbTranslateNone(char *table, rfbPixelFormat *in,
+                            rfbPixelFormat *out,
+                            char *iptr, char *optr,
+                            int bytesBetweenInputLines,
+                            int width, int height);
+extern Bool rfbSetTranslateFunction(rfbClientPtr cl);
+extern void rfbSetClientColourMaps(int firstColour, int nColours);
+extern Bool rfbSetClientColourMap(rfbClientPtr cl, int firstColour,
+                                 int nColours);
+
+
+/* httpd.c */
+
+extern int httpPort;
+extern char *httpDir;
+
+extern void httpInitSockets();
+extern void httpCheckFds();
+
+
+
+/* auth.c */
+
+extern char *rfbAuthPasswdFile;
+extern Bool rfbAuthenticating;
+
+extern void rfbAuthNewClient(rfbClientPtr cl);
+extern void rfbAuthProcessClientMessage(rfbClientPtr cl);
+
+
+/* rre.c */
+
+extern Bool rfbSendRectEncodingRRE(rfbClientPtr cl, int x,int y,int w,int h);
+
+
+/* corre.c */
+
+extern Bool rfbSendRectEncodingCoRRE(rfbClientPtr cl, int x,int y,int w,int h);
+
+
+/* hextile.c */
+
+extern Bool rfbSendRectEncodingHextile(rfbClientPtr cl, int x, int y, int w,
+                                      int h);
+
+/* zrle.c */
+
+extern Bool rfbSendRectEncodingZRLE(rfbClientPtr cl, int x, int y, int w,
+                                    int h);
+extern void FreeZrleData(rfbClientPtr cl);
+
+/* stats.c */
+
+extern void rfbResetStats(rfbClientPtr cl);
+extern void rfbPrintStats(rfbClientPtr cl);
diff --git a/Xserver/programs/Xserver/hw/vnc/rfbserver.c b/Xserver/programs/Xserver/hw/vnc/rfbserver.c
new file mode 100644 (file)
index 0000000..b959d0a
--- /dev/null
@@ -0,0 +1,1221 @@
+/*
+ * rfbserver.c - deal with server-side of the RFB protocol.
+ */
+
+/*
+ *  Copyright (C) 2002-2003 RealVNC Ltd.
+ *  Copyright (C) 1999 AT&T Laboratories Cambridge.  All Rights Reserved.
+ *
+ *  This is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This software is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this software; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,
+ *  USA.
+ */
+
+/* Use ``#define CORBA'' to enable CORBA control interface */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <pwd.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include "windowstr.h"
+#include "rfb.h"
+#include "input.h"
+#include "mipointer.h"
+#include "sprite.h"
+
+#ifdef CORBA
+#include <vncserverctrl.h>
+#endif
+
+char updateBuf[UPDATE_BUF_SIZE];
+int ublen;
+
+rfbClientPtr rfbClientHead = NULL;
+rfbClientPtr pointerClient = NULL;  /* Mutex for pointer events */
+
+Bool rfbAlwaysShared = FALSE;
+Bool rfbNeverShared = FALSE;
+Bool rfbDontDisconnect = FALSE;
+int rfbMaxRects = 50;
+
+static rfbClientPtr rfbNewClient(int sock);
+static void rfbProcessClientProtocolVersion(rfbClientPtr cl);
+static void rfbProcessClientNormalMessage(rfbClientPtr cl);
+static void rfbProcessClientInitMessage(rfbClientPtr cl);
+static Bool rfbSendCopyRegion(rfbClientPtr cl, RegionPtr reg, int dx, int dy);
+
+
+/*
+ * rfbNewClientConnection is called from sockets.c when a new connection
+ * comes in.
+ */
+
+void
+rfbNewClientConnection(sock)
+    int sock;
+{
+    rfbClientPtr cl;
+
+    cl = rfbNewClient(sock);
+
+#ifdef CORBA
+    if (cl != NULL)
+       newConnection(cl, (KEYBOARD_DEVICE|POINTER_DEVICE), 1, 1, 1);
+#endif
+}
+
+
+/*
+ * rfbReverseConnection is called by the CORBA stuff to make an outward
+ * connection to a "listening" RFB client.
+ */
+
+rfbClientPtr
+rfbReverseConnection(host, port)
+    char *host;
+    int port;
+{
+    int sock;
+    rfbClientPtr cl;
+
+    if ((sock = rfbConnect(host, port)) < 0)
+       return (rfbClientPtr)NULL;
+
+    cl = rfbNewClient(sock);
+
+    if (cl) {
+       cl->reverseConnection = TRUE;
+    }
+
+    return cl;
+}
+
+
+/*
+ * rfbNewClient is called when a new connection has been made by whatever
+ * means.
+ */
+
+static rfbClientPtr
+rfbNewClient(sock)
+    int sock;
+{
+    rfbProtocolVersionMsg pv;
+    rfbClientPtr cl;
+    BoxRec box;
+    struct sockaddr_in addr;
+    unsigned int addrlen = sizeof(struct sockaddr_in);
+
+    if (rfbClientHead == NULL) {
+       /* no other clients - make sure we don't think any keys are pressed */
+       KbdReleaseAllKeys();
+    } else {
+       rfbLog("  (other clients");
+       for (cl = rfbClientHead; cl; cl = cl->next) {
+           fprintf(stderr," %s",cl->host);
+       }
+       fprintf(stderr,")\n");
+    }
+
+    cl = (rfbClientPtr)xalloc(sizeof(rfbClientRec));
+
+    cl->sock = sock;
+    getpeername(sock, (struct sockaddr *)&addr, &addrlen);
+    cl->host = strdup(inet_ntoa(addr.sin_addr));
+
+    cl->state = RFB_PROTOCOL_VERSION;
+
+    cl->reverseConnection = FALSE;
+    cl->readyForSetColourMapEntries = FALSE;
+    cl->useCopyRect = FALSE;
+    cl->preferredEncoding = rfbEncodingRaw;
+    cl->correMaxWidth = 48;
+    cl->correMaxHeight = 48;
+    cl->zrleData = 0;
+
+    REGION_INIT(pScreen,&cl->copyRegion,NullBox,0);
+    cl->copyDX = 0;
+    cl->copyDY = 0;
+
+    box.x1 = box.y1 = 0;
+    box.x2 = rfbScreen.width;
+    box.y2 = rfbScreen.height;
+    REGION_INIT(pScreen,&cl->modifiedRegion,&box,0);
+
+    REGION_INIT(pScreen,&cl->requestedRegion,NullBox,0);
+
+    cl->deferredUpdateScheduled = FALSE;
+    cl->deferredUpdateTimer = NULL;
+
+    cl->format = rfbServerFormat;
+    cl->translateFn = rfbTranslateNone;
+    cl->translateLookupTable = NULL;
+
+    cl->next = rfbClientHead;
+    rfbClientHead = cl;
+
+    rfbResetStats(cl);
+
+    sprintf(pv,rfbProtocolVersionFormat,rfbProtocolMajorVersion,
+           rfbProtocolMinorVersion);
+
+    if (WriteExact(sock, pv, sz_rfbProtocolVersionMsg) < 0) {
+       rfbLogPerror("rfbNewClient: write");
+       rfbCloseSock(sock);
+       return NULL;
+    }
+
+    return cl;
+}
+
+
+/*
+ * rfbClientConnectionGone is called from sockets.c just after a connection
+ * has gone away.
+ */
+
+void
+rfbClientConnectionGone(sock)
+    int sock;
+{
+    rfbClientPtr cl, prev;
+
+    for (prev = NULL, cl = rfbClientHead; cl; prev = cl, cl = cl->next) {
+       if (sock == cl->sock)
+           break;
+    }
+
+    if (!cl) {
+       rfbLog("rfbClientConnectionGone: unknown socket %d\n",sock);
+       return;
+    }
+
+    rfbLog("Client %s gone\n",cl->host);
+    free(cl->host);
+
+    if (pointerClient == cl)
+       pointerClient = NULL;
+
+#ifdef CORBA
+    destroyConnection(cl);
+#endif
+
+    if (prev)
+       prev->next = cl->next;
+    else
+       rfbClientHead = cl->next;
+
+    FreeZrleData(cl);
+    REGION_UNINIT(pScreen,&cl->copyRegion);
+    REGION_UNINIT(pScreen,&cl->modifiedRegion);
+    TimerFree(cl->deferredUpdateTimer);
+
+    rfbPrintStats(cl);
+
+    if (cl->translateLookupTable) free(cl->translateLookupTable);
+
+    xfree(cl);
+}
+
+
+/*
+ * rfbProcessClientMessage is called when there is data to read from a client.
+ */
+
+void
+rfbProcessClientMessage(sock)
+    int sock;
+{
+    rfbClientPtr cl;
+
+    for (cl = rfbClientHead; cl; cl = cl->next) {
+       if (sock == cl->sock)
+           break;
+    }
+
+    if (!cl) {
+       rfbLog("rfbProcessClientMessage: unknown socket %d\n",sock);
+       rfbCloseSock(sock);
+       return;
+    }
+
+#ifdef CORBA
+    if (isClosePending(cl)) {
+       rfbLog("Closing connection to client %s\n", cl->host);
+       rfbCloseSock(sock);
+       return;
+    }
+#endif
+
+    switch (cl->state) {
+    case RFB_PROTOCOL_VERSION:
+       rfbProcessClientProtocolVersion(cl);
+       return;
+    case RFB_AUTHENTICATION:
+       rfbAuthProcessClientMessage(cl);
+       return;
+    case RFB_INITIALISATION:
+       rfbProcessClientInitMessage(cl);
+       return;
+    default:
+       rfbProcessClientNormalMessage(cl);
+       return;
+    }
+}
+
+
+/*
+ * rfbProcessClientProtocolVersion is called when the client sends its
+ * protocol version.
+ */
+
+static void
+rfbProcessClientProtocolVersion(cl)
+    rfbClientPtr cl;
+{
+    rfbProtocolVersionMsg pv;
+    int n, major, minor;
+    char failureReason[256];
+
+    if ((n = ReadExact(cl->sock, pv, sz_rfbProtocolVersionMsg)) <= 0) {
+       if (n == 0)
+           rfbLog("rfbProcessClientProtocolVersion: client gone\n");
+       else
+           rfbLogPerror("rfbProcessClientProtocolVersion: read");
+       rfbCloseSock(cl->sock);
+       return;
+    }
+
+    pv[sz_rfbProtocolVersionMsg] = 0;
+    if (sscanf(pv,rfbProtocolVersionFormat,&major,&minor) != 2) {
+       rfbLog("rfbProcessClientProtocolVersion: not a valid RFB client\n");
+       rfbCloseSock(cl->sock);
+       return;
+    }
+    rfbLog("Protocol version %d.%d\n", major, minor);
+
+    if (major != rfbProtocolMajorVersion) {
+       /* Major version mismatch - send a ConnFailed message */
+
+       rfbLog("Major version mismatch\n");
+       sprintf(failureReason,
+               "RFB protocol version mismatch - server %d.%d, client %d.%d",
+               rfbProtocolMajorVersion,rfbProtocolMinorVersion,major,minor);
+       rfbClientConnFailed(cl, failureReason);
+       return;
+    }
+
+    if (minor != rfbProtocolMinorVersion) {
+       /* Minor version mismatch - warn but try to continue */
+       rfbLog("Ignoring minor version mismatch\n");
+    }
+
+    rfbAuthNewClient(cl);
+}
+
+
+/*
+ * rfbClientConnFailed is called when a client connection has failed either
+ * because it talks the wrong protocol or it has failed authentication.
+ */
+
+void
+rfbClientConnFailed(cl, reason)
+    rfbClientPtr cl;
+    char *reason;
+{
+    char *buf;
+    int len = strlen(reason);
+
+    buf = (char *)xalloc(8 + len);
+    ((CARD32 *)buf)[0] = Swap32IfLE(rfbConnFailed);
+    ((CARD32 *)buf)[1] = Swap32IfLE(len);
+    memcpy(buf + 8, reason, len);
+
+    if (WriteExact(cl->sock, buf, 8 + len) < 0)
+       rfbLogPerror("rfbClientConnFailed: write");
+    xfree(buf);
+    rfbCloseSock(cl->sock);
+}
+
+
+/*
+ * rfbProcessClientInitMessage is called when the client sends its
+ * initialisation message.
+ */
+
+static void
+rfbProcessClientInitMessage(cl)
+    rfbClientPtr cl;
+{
+    rfbClientInitMsg ci;
+    char buf[256];
+    rfbServerInitMsg *si = (rfbServerInitMsg *)buf;
+    struct passwd *user;
+    int len, n;
+    rfbClientPtr otherCl, nextCl;
+
+    if ((n = ReadExact(cl->sock, (char *)&ci,sz_rfbClientInitMsg)) <= 0) {
+       if (n == 0)
+           rfbLog("rfbProcessClientInitMessage: client gone\n");
+       else
+           rfbLogPerror("rfbProcessClientInitMessage: read");
+       rfbCloseSock(cl->sock);
+       return;
+    }
+
+    si->framebufferWidth = Swap16IfLE(rfbScreen.width);
+    si->framebufferHeight = Swap16IfLE(rfbScreen.height);
+    si->format = rfbServerFormat;
+    si->format.redMax = Swap16IfLE(si->format.redMax);
+    si->format.greenMax = Swap16IfLE(si->format.greenMax);
+    si->format.blueMax = Swap16IfLE(si->format.blueMax);
+
+    user = getpwuid(getuid());
+
+    if (strlen(desktopName) > 128)     /* sanity check on desktop name len */
+       desktopName[128] = 0;
+
+    if (user) {
+       sprintf(buf + sz_rfbServerInitMsg, "%s's %s desktop (%s:%s)",
+               user->pw_name, desktopName, rfbThisHost, display);
+    } else {
+       sprintf(buf + sz_rfbServerInitMsg, "%s desktop (%s:%s)",
+               desktopName, rfbThisHost, display);
+    }
+    len = strlen(buf + sz_rfbServerInitMsg);
+    si->nameLength = Swap32IfLE(len);
+
+    if (WriteExact(cl->sock, buf, sz_rfbServerInitMsg + len) < 0) {
+       rfbLogPerror("rfbProcessClientInitMessage: write");
+       rfbCloseSock(cl->sock);
+       return;
+    }
+
+    cl->state = RFB_NORMAL;
+
+    if (!cl->reverseConnection &&
+                       (rfbNeverShared || (!rfbAlwaysShared && !ci.shared))) {
+
+       if (rfbDontDisconnect) {
+           for (otherCl = rfbClientHead; otherCl; otherCl = otherCl->next) {
+               if ((otherCl != cl) && (otherCl->state == RFB_NORMAL)) {
+                   rfbLog("-dontdisconnect: Not shared & existing client\n");
+                   rfbLog("  refusing new client %s\n", cl->host);
+                   rfbCloseSock(cl->sock);
+                   return;
+               }
+           }
+       } else {
+           for (otherCl = rfbClientHead; otherCl; otherCl = nextCl) {
+               nextCl = otherCl->next;
+               if ((otherCl != cl) && (otherCl->state == RFB_NORMAL)) {
+                   rfbLog("Not shared - closing connection to client %s\n",
+                          otherCl->host);
+                   rfbCloseSock(otherCl->sock);
+               }
+           }
+       }
+    }
+}
+
+
+/*
+ * rfbProcessClientNormalMessage is called when the client has sent a normal
+ * protocol message.
+ */
+
+static void
+rfbProcessClientNormalMessage(cl)
+    rfbClientPtr cl;
+{
+    int n;
+    rfbClientToServerMsg msg;
+    char *str;
+
+    if ((n = ReadExact(cl->sock, (char *)&msg, 1)) <= 0) {
+       if (n != 0)
+           rfbLogPerror("rfbProcessClientNormalMessage: read");
+       rfbCloseSock(cl->sock);
+       return;
+    }
+
+    switch (msg.type) {
+
+    case rfbSetPixelFormat:
+
+       if ((n = ReadExact(cl->sock, ((char *)&msg) + 1,
+                          sz_rfbSetPixelFormatMsg - 1)) <= 0) {
+           if (n != 0)
+               rfbLogPerror("rfbProcessClientNormalMessage: read");
+           rfbCloseSock(cl->sock);
+           return;
+       }
+
+       cl->format.bitsPerPixel = msg.spf.format.bitsPerPixel;
+       cl->format.depth = msg.spf.format.depth;
+       cl->format.bigEndian = (msg.spf.format.bigEndian ? 1 : 0);
+       cl->format.trueColour = (msg.spf.format.trueColour ? 1 : 0);
+       cl->format.redMax = Swap16IfLE(msg.spf.format.redMax);
+       cl->format.greenMax = Swap16IfLE(msg.spf.format.greenMax);
+       cl->format.blueMax = Swap16IfLE(msg.spf.format.blueMax);
+       cl->format.redShift = msg.spf.format.redShift;
+       cl->format.greenShift = msg.spf.format.greenShift;
+       cl->format.blueShift = msg.spf.format.blueShift;
+
+       cl->readyForSetColourMapEntries = TRUE;
+
+       rfbSetTranslateFunction(cl);
+       return;
+
+
+    case rfbFixColourMapEntries:
+       if ((n = ReadExact(cl->sock, ((char *)&msg) + 1,
+                          sz_rfbFixColourMapEntriesMsg - 1)) <= 0) {
+           if (n != 0)
+               rfbLogPerror("rfbProcessClientNormalMessage: read");
+           rfbCloseSock(cl->sock);
+           return;
+       }
+       rfbLog("rfbProcessClientNormalMessage: %s",
+               "FixColourMapEntries unsupported\n");
+       rfbCloseSock(cl->sock);
+       return;
+
+
+    case rfbSetEncodings:
+    {
+       int i;
+       CARD32 enc;
+
+       if ((n = ReadExact(cl->sock, ((char *)&msg) + 1,
+                          sz_rfbSetEncodingsMsg - 1)) <= 0) {
+           if (n != 0)
+               rfbLogPerror("rfbProcessClientNormalMessage: read");
+           rfbCloseSock(cl->sock);
+           return;
+       }
+
+       msg.se.nEncodings = Swap16IfLE(msg.se.nEncodings);
+
+       cl->preferredEncoding = -1;
+       cl->useCopyRect = FALSE;
+
+       for (i = 0; i < msg.se.nEncodings; i++) {
+           if ((n = ReadExact(cl->sock, (char *)&enc, 4)) <= 0) {
+               if (n != 0)
+                   rfbLogPerror("rfbProcessClientNormalMessage: read");
+               rfbCloseSock(cl->sock);
+               return;
+           }
+           enc = Swap32IfLE(enc);
+
+           switch (enc) {
+
+           case rfbEncodingCopyRect:
+               cl->useCopyRect = TRUE;
+               break;
+           case rfbEncodingRaw:
+               if (cl->preferredEncoding == -1) {
+                   cl->preferredEncoding = enc;
+                   rfbLog("Using raw encoding for client %s\n",
+                          cl->host);
+               }
+               break;
+           case rfbEncodingRRE:
+               if (cl->preferredEncoding == -1) {
+                   cl->preferredEncoding = enc;
+                   rfbLog("Using rre encoding for client %s\n",
+                          cl->host);
+               }
+               break;
+           case rfbEncodingCoRRE:
+               if (cl->preferredEncoding == -1) {
+                   cl->preferredEncoding = enc;
+                   rfbLog("Using CoRRE encoding for client %s\n",
+                          cl->host);
+               }
+               break;
+           case rfbEncodingHextile:
+               if (cl->preferredEncoding == -1) {
+                   cl->preferredEncoding = enc;
+                   rfbLog("Using hextile encoding for client %s\n",
+                          cl->host);
+               }
+               break;
+           case rfbEncodingZRLE:
+               if (cl->preferredEncoding == -1) {
+                   cl->preferredEncoding = enc;
+                   rfbLog("Using ZRLE encoding for client %s\n",
+                          cl->host);
+               }
+               break;
+           default:
+               rfbLog("rfbProcessClientNormalMessage: ignoring unknown "
+                      "encoding type %d\n", (int)enc);
+           }
+       }
+
+       if (cl->preferredEncoding == -1) {
+           cl->preferredEncoding = rfbEncodingRaw;
+       }
+
+       return;
+    }
+
+
+    case rfbFramebufferUpdateRequest:
+    {
+       RegionRec tmpRegion;
+       BoxRec box;
+
+#ifdef CORBA
+       addCapability(cl, DISPLAY_DEVICE);
+#endif
+
+       if ((n = ReadExact(cl->sock, ((char *)&msg) + 1,
+                          sz_rfbFramebufferUpdateRequestMsg-1)) <= 0) {
+           if (n != 0)
+               rfbLogPerror("rfbProcessClientNormalMessage: read");
+           rfbCloseSock(cl->sock);
+           return;
+       }
+
+       box.x1 = Swap16IfLE(msg.fur.x);
+       box.y1 = Swap16IfLE(msg.fur.y);
+       box.x2 = box.x1 + Swap16IfLE(msg.fur.w);
+       box.y2 = box.y1 + Swap16IfLE(msg.fur.h);
+       SAFE_REGION_INIT(pScreen,&tmpRegion,&box,0);
+
+       REGION_UNION(pScreen, &cl->requestedRegion, &cl->requestedRegion,
+                    &tmpRegion);
+
+       if (!cl->readyForSetColourMapEntries) {
+           /* client hasn't sent a SetPixelFormat so is using server's */
+           cl->readyForSetColourMapEntries = TRUE;
+           if (!cl->format.trueColour) {
+               if (!rfbSetClientColourMap(cl, 0, 0)) {
+                   REGION_UNINIT(pScreen,&tmpRegion);
+                   return;
+               }
+           }
+       }
+
+       if (!msg.fur.incremental) {
+           REGION_UNION(pScreen,&cl->modifiedRegion,&cl->modifiedRegion,
+                        &tmpRegion);
+           REGION_SUBTRACT(pScreen,&cl->copyRegion,&cl->copyRegion,
+                           &tmpRegion);
+       }
+
+       if (FB_UPDATE_PENDING(cl)) {
+         if (!cl->deferredUpdateScheduled)
+            rfbScheduleDeferredUpdate(cl);
+       }
+
+       REGION_UNINIT(pScreen,&tmpRegion);
+       return;
+    }
+
+    case rfbKeyEvent:
+
+       cl->rfbKeyEventsRcvd++;
+
+       if ((n = ReadExact(cl->sock, ((char *)&msg) + 1,
+                          sz_rfbKeyEventMsg - 1)) <= 0) {
+           if (n != 0)
+               rfbLogPerror("rfbProcessClientNormalMessage: read");
+           rfbCloseSock(cl->sock);
+           return;
+       }
+
+#ifdef CORBA
+       addCapability(cl, KEYBOARD_DEVICE);
+
+       if (!isKeyboardEnabled(cl))
+           return;
+#endif
+       KbdAddEvent(msg.ke.down, (KeySym)Swap32IfLE(msg.ke.key), cl);
+       return;
+
+
+    case rfbPointerEvent:
+
+       cl->rfbPointerEventsRcvd++;
+
+       if ((n = ReadExact(cl->sock, ((char *)&msg) + 1,
+                          sz_rfbPointerEventMsg - 1)) <= 0) {
+           if (n != 0)
+               rfbLogPerror("rfbProcessClientNormalMessage: read");
+           rfbCloseSock(cl->sock);
+           return;
+       }
+
+#ifdef CORBA
+       addCapability(cl, POINTER_DEVICE);
+
+       if (!isPointerEnabled(cl))
+           return;
+#endif
+
+       if (pointerClient && (pointerClient != cl))
+           return;
+
+       if (msg.pe.buttonMask == 0)
+           pointerClient = NULL;
+       else
+           pointerClient = cl;
+
+       PtrAddEvent(msg.pe.buttonMask,
+                   Swap16IfLE(msg.pe.x), Swap16IfLE(msg.pe.y), cl);
+       return;
+
+
+    case rfbClientCutText:
+
+       if ((n = ReadExact(cl->sock, ((char *)&msg) + 1,
+                          sz_rfbClientCutTextMsg - 1)) <= 0) {
+           if (n != 0)
+               rfbLogPerror("rfbProcessClientNormalMessage: read");
+           rfbCloseSock(cl->sock);
+           return;
+       }
+
+       msg.cct.length = Swap32IfLE(msg.cct.length);
+
+       str = (char *)xalloc(msg.cct.length);
+
+       if ((n = ReadExact(cl->sock, str, msg.cct.length)) <= 0) {
+           if (n != 0)
+               rfbLogPerror("rfbProcessClientNormalMessage: read");
+           xfree(str);
+           rfbCloseSock(cl->sock);
+           return;
+       }
+
+       rfbSetXCutText(str, msg.cct.length);
+
+       xfree(str);
+       return;
+
+
+    default:
+
+       rfbLog("rfbProcessClientNormalMessage: unknown message type %d\n",
+               msg.type);
+       rfbLog(" ... closing connection\n");
+       rfbCloseSock(cl->sock);
+       return;
+    }
+}
+
+
+
+/*
+ * rfbSendFramebufferUpdate - send the currently pending framebuffer update to
+ * the RFB client.
+ */
+
+Bool
+rfbSendFramebufferUpdate(cl)
+    rfbClientPtr cl;
+{
+    ScreenPtr pScreen = screenInfo.screens[0];
+    int i;
+    int nUpdateRegionRects;
+    rfbFramebufferUpdateMsg *fu = (rfbFramebufferUpdateMsg *)updateBuf;
+    RegionRec updateRegion, updateCopyRegion;
+    int dx, dy;
+    int bytesSent, rectsSent;
+
+    /*
+     * If the cursor isn't drawn, make sure it's put up.
+     */
+
+    if (!rfbScreen.cursorIsDrawn) {
+       rfbSpriteRestoreCursor(pScreen);
+    }
+
+    /*
+     * The modifiedRegion may overlap the destination copyRegion.  We remove
+     * any overlapping bits from the copyRegion (since they'd only be
+     * overwritten anyway).
+     */
+
+    REGION_SUBTRACT(pScreen, &cl->copyRegion, &cl->copyRegion,
+                   &cl->modifiedRegion);
+
+    /*
+     * The client is interested in the region requestedRegion.  The region
+     * which should be updated now is the intersection of requestedRegion
+     * and the union of modifiedRegion and copyRegion.  If it's empty then
+     * no update is needed.
+     */
+
+    REGION_INIT(pScreen,&updateRegion,NullBox,0);
+    REGION_UNION(pScreen, &updateRegion, &cl->copyRegion,
+                &cl->modifiedRegion);
+    REGION_INTERSECT(pScreen, &updateRegion, &cl->requestedRegion,
+                    &updateRegion);
+
+    if (!REGION_NOTEMPTY(pScreen,&updateRegion)) {
+       REGION_UNINIT(pScreen,&updateRegion);
+       return TRUE;
+    }
+
+    if (rfbTrace) {
+      rfbLog("Sending update...\n");
+      bytesSent = cl->rfbBytesSent[cl->preferredEncoding];
+      rectsSent = cl->rfbRectanglesSent[cl->preferredEncoding];
+    }
+
+    /*
+     * We assume that the client doesn't have any pixel data outside the
+     * requestedRegion.  In other words, both the source and destination of a
+     * copy must lie within requestedRegion.  So the region we can send as a
+     * copy is the intersection of the copyRegion with both the requestedRegion
+     * and the requestedRegion translated by the amount of the copy.  We set
+     * updateCopyRegion to this.
+     */
+
+    REGION_INIT(pScreen,&updateCopyRegion,NullBox,0);
+    REGION_INTERSECT(pScreen, &updateCopyRegion, &cl->copyRegion,
+                    &cl->requestedRegion);
+    REGION_TRANSLATE(pScreen, &cl->requestedRegion, cl->copyDX, cl->copyDY);
+    REGION_INTERSECT(pScreen, &updateCopyRegion, &updateCopyRegion,
+                    &cl->requestedRegion);
+    dx = cl->copyDX;
+    dy = cl->copyDY;
+
+    /*
+     * Next we remove updateCopyRegion from updateRegion so that updateRegion
+     * is the part of this update which is sent as ordinary pixel data (i.e not
+     * a copy).
+     */
+
+    REGION_SUBTRACT(pScreen, &updateRegion, &updateRegion, &updateCopyRegion);
+
+    /*
+     * Finally we leave modifiedRegion to be the remainder (if any) of parts of
+     * the screen which are modified but outside the requestedRegion.  We also
+     * empty both the requestedRegion and the copyRegion - note that we never
+     * carry over a copyRegion for a future update.
+     */
+
+    REGION_UNION(pScreen, &cl->modifiedRegion, &cl->modifiedRegion,
+                &cl->copyRegion);
+    REGION_SUBTRACT(pScreen, &cl->modifiedRegion, &cl->modifiedRegion,
+                   &updateRegion);
+    REGION_SUBTRACT(pScreen, &cl->modifiedRegion, &cl->modifiedRegion,
+                   &updateCopyRegion);
+
+    REGION_EMPTY(pScreen, &cl->requestedRegion);
+    REGION_EMPTY(pScreen, &cl->copyRegion);
+    cl->copyDX = 0;
+    cl->copyDY = 0;
+
+    /*
+     * Now send the update.
+     */
+
+    cl->rfbFramebufferUpdateMessagesSent++;
+
+    if (cl->preferredEncoding == rfbEncodingCoRRE) {
+       nUpdateRegionRects = 0;
+
+       for (i = 0; i < REGION_NUM_RECTS(&updateRegion); i++) {
+           int x = REGION_RECTS(&updateRegion)[i].x1;
+           int y = REGION_RECTS(&updateRegion)[i].y1;
+           int w = REGION_RECTS(&updateRegion)[i].x2 - x;
+           int h = REGION_RECTS(&updateRegion)[i].y2 - y;
+           nUpdateRegionRects += (((w-1) / cl->correMaxWidth + 1)
+                                    * ((h-1) / cl->correMaxHeight + 1));
+       }
+    } else {
+       nUpdateRegionRects = REGION_NUM_RECTS(&updateRegion);
+    }
+
+    if (nUpdateRegionRects > rfbMaxRects) {
+      BoxRec boundingBox = *(REGION_EXTENTS(pScreen, &updateRegion));
+      REGION_RESET(pScreen, &updateRegion, &boundingBox);
+      nUpdateRegionRects = 1;
+    }
+
+    fu->type = rfbFramebufferUpdate;
+    fu->nRects = Swap16IfLE(REGION_NUM_RECTS(&updateCopyRegion)
+                           + nUpdateRegionRects);
+    ublen = sz_rfbFramebufferUpdateMsg;
+
+    if (REGION_NOTEMPTY(pScreen,&updateCopyRegion)) {
+       if (!rfbSendCopyRegion(cl,&updateCopyRegion,dx,dy)) {
+           REGION_UNINIT(pScreen,&updateRegion);
+           REGION_UNINIT(pScreen,&updateCopyRegion);
+           return FALSE;
+       }
+    }
+
+    REGION_UNINIT(pScreen,&updateCopyRegion);
+
+    for (i = 0; i < REGION_NUM_RECTS(&updateRegion); i++) {
+       int x = REGION_RECTS(&updateRegion)[i].x1;
+       int y = REGION_RECTS(&updateRegion)[i].y1;
+       int w = REGION_RECTS(&updateRegion)[i].x2 - x;
+       int h = REGION_RECTS(&updateRegion)[i].y2 - y;
+
+       cl->rfbRawBytesEquivalent += (sz_rfbFramebufferUpdateRectHeader
+                                     + w * (cl->format.bitsPerPixel / 8) * h);
+
+       switch (cl->preferredEncoding) {
+       case rfbEncodingRaw:
+           if (!rfbSendRectEncodingRaw(cl, x, y, w, h)) {
+               REGION_UNINIT(pScreen,&updateRegion);
+               return FALSE;
+           }
+           break;
+       case rfbEncodingRRE:
+           if (!rfbSendRectEncodingRRE(cl, x, y, w, h)) {
+               REGION_UNINIT(pScreen,&updateRegion);
+               return FALSE;
+           }
+           break;
+       case rfbEncodingCoRRE:
+           if (!rfbSendRectEncodingCoRRE(cl, x, y, w, h)) {
+               REGION_UNINIT(pScreen,&updateRegion);
+               return FALSE;
+           }
+           break;
+       case rfbEncodingHextile:
+           if (!rfbSendRectEncodingHextile(cl, x, y, w, h)) {
+               REGION_UNINIT(pScreen,&updateRegion);
+               return FALSE;
+           }
+           break;
+       case rfbEncodingZRLE:
+           if (!rfbSendRectEncodingZRLE(cl, x, y, w, h)) {
+               REGION_UNINIT(pScreen,&updateRegion);
+               return FALSE;
+           }
+           break;
+       }
+    }
+
+    REGION_UNINIT(pScreen,&updateRegion);
+
+    if (!rfbSendUpdateBuf(cl))
+       return FALSE;
+
+    if (rfbTrace) {
+      bytesSent = cl->rfbBytesSent[cl->preferredEncoding] - bytesSent;
+      rectsSent = cl->rfbRectanglesSent[cl->preferredEncoding] - rectsSent;
+      rfbLog("...sent %d bytes, %d rects\n",bytesSent,rectsSent);
+    }
+
+    return TRUE;
+}
+
+
+
+/*
+ * Send the copy region as a string of CopyRect encoded rectangles.
+ * The only slightly tricky thing is that we should send the messages in
+ * the correct order so that an earlier CopyRect will not corrupt the source
+ * of a later one.
+ */
+
+static Bool
+rfbSendCopyRegion(cl, reg, dx, dy)
+    rfbClientPtr cl;
+    RegionPtr reg;
+    int dx, dy;
+{
+    int nrects, nrectsInBand, x_inc, y_inc, thisRect, firstInNextBand;
+    int x, y, w, h;
+    rfbFramebufferUpdateRectHeader rect;
+    rfbCopyRect cr;
+
+    nrects = REGION_NUM_RECTS(reg);
+
+    if (dx <= 0) {
+       x_inc = 1;
+    } else {
+       x_inc = -1;
+    }
+
+    if (dy <= 0) {
+       thisRect = 0;
+       y_inc = 1;
+    } else {
+       thisRect = nrects - 1;
+       y_inc = -1;
+    }
+
+    while (nrects > 0) {
+
+       firstInNextBand = thisRect;
+       nrectsInBand = 0;
+
+       while ((nrects > 0) &&
+              (REGION_RECTS(reg)[firstInNextBand].y1
+               == REGION_RECTS(reg)[thisRect].y1))
+       {
+           firstInNextBand += y_inc;
+           nrects--;
+           nrectsInBand++;
+       }
+
+       if (x_inc != y_inc) {
+           thisRect = firstInNextBand - y_inc;
+       }
+
+       while (nrectsInBand > 0) {
+           if ((ublen + sz_rfbFramebufferUpdateRectHeader
+                + sz_rfbCopyRect) > UPDATE_BUF_SIZE)
+           {
+               if (!rfbSendUpdateBuf(cl))
+                   return FALSE;
+           }
+
+           x = REGION_RECTS(reg)[thisRect].x1;
+           y = REGION_RECTS(reg)[thisRect].y1;
+           w = REGION_RECTS(reg)[thisRect].x2 - x;
+           h = REGION_RECTS(reg)[thisRect].y2 - y;
+
+           rect.r.x = Swap16IfLE(x);
+           rect.r.y = Swap16IfLE(y);
+           rect.r.w = Swap16IfLE(w);
+           rect.r.h = Swap16IfLE(h);
+           rect.encoding = Swap32IfLE(rfbEncodingCopyRect);
+
+           memcpy(&updateBuf[ublen], (char *)&rect,
+                  sz_rfbFramebufferUpdateRectHeader);
+           ublen += sz_rfbFramebufferUpdateRectHeader;
+
+           cr.srcX = Swap16IfLE(x - dx);
+           cr.srcY = Swap16IfLE(y - dy);
+
+           memcpy(&updateBuf[ublen], (char *)&cr, sz_rfbCopyRect);
+           ublen += sz_rfbCopyRect;
+
+           cl->rfbRectanglesSent[rfbEncodingCopyRect]++;
+           cl->rfbBytesSent[rfbEncodingCopyRect]
+               += sz_rfbFramebufferUpdateRectHeader + sz_rfbCopyRect;
+
+           thisRect += x_inc;
+           nrectsInBand--;
+       }
+
+       thisRect = firstInNextBand;
+    }
+
+    return TRUE;
+}
+
+
+/*
+ * Send a given rectangle in raw encoding (rfbEncodingRaw).
+ */
+
+Bool
+rfbSendRectEncodingRaw(cl, x, y, w, h)
+    rfbClientPtr cl;
+    int x, y, w, h;
+{
+    rfbFramebufferUpdateRectHeader rect;
+    int nlines;
+    int bytesPerLine = w * (cl->format.bitsPerPixel / 8);
+    char *fbptr = (rfbScreen.pfbMemory + (rfbScreen.paddedWidthInBytes * y)
+                  + (x * (rfbScreen.bitsPerPixel / 8)));
+
+    if (ublen + sz_rfbFramebufferUpdateRectHeader > UPDATE_BUF_SIZE) {
+       if (!rfbSendUpdateBuf(cl))
+           return FALSE;
+    }
+
+    rect.r.x = Swap16IfLE(x);
+    rect.r.y = Swap16IfLE(y);
+    rect.r.w = Swap16IfLE(w);
+    rect.r.h = Swap16IfLE(h);
+    rect.encoding = Swap32IfLE(rfbEncodingRaw);
+
+    memcpy(&updateBuf[ublen], (char *)&rect,sz_rfbFramebufferUpdateRectHeader);
+    ublen += sz_rfbFramebufferUpdateRectHeader;
+
+    cl->rfbRectanglesSent[rfbEncodingRaw]++;
+    cl->rfbBytesSent[rfbEncodingRaw]
+       += sz_rfbFramebufferUpdateRectHeader + bytesPerLine * h;
+
+    nlines = (UPDATE_BUF_SIZE - ublen) / bytesPerLine;
+
+    while (TRUE) {
+       if (nlines > h)
+           nlines = h;
+
+       (*cl->translateFn)(cl->translateLookupTable, &rfbServerFormat,
+                          &cl->format, fbptr, &updateBuf[ublen],
+                          rfbScreen.paddedWidthInBytes, w, nlines);
+
+       ublen += nlines * bytesPerLine;
+       h -= nlines;
+
+       if (h == 0)     /* rect fitted in buffer, do next one */
+           return TRUE;
+
+       /* buffer full - flush partial rect and do another nlines */
+
+       if (!rfbSendUpdateBuf(cl))
+           return FALSE;
+
+       fbptr += (rfbScreen.paddedWidthInBytes * nlines);
+
+       nlines = (UPDATE_BUF_SIZE - ublen) / bytesPerLine;
+       if (nlines == 0) {
+           rfbLog("rfbSendRectEncodingRaw: send buffer too small for %d "
+                  "bytes per line\n", bytesPerLine);
+           rfbCloseSock(cl->sock);
+           return FALSE;
+       }
+    }
+}
+
+
+
+/*
+ * Send the contents of updateBuf.  Returns 1 if successful, -1 if
+ * not (errno should be set).
+ */
+
+Bool
+rfbSendUpdateBuf(cl)
+    rfbClientPtr cl;
+{
+    /*
+    int i;
+    for (i = 0; i < ublen; i++) {
+       fprintf(stderr,"%02x ",((unsigned char *)updateBuf)[i]);
+    }
+    fprintf(stderr,"\n");
+    */
+
+    if (WriteExact(cl->sock, updateBuf, ublen) < 0) {
+       rfbLogPerror("rfbSendUpdateBuf: write");
+       rfbCloseSock(cl->sock);
+       return FALSE;
+    }
+
+    ublen = 0;
+    return TRUE;
+}
+
+
+
+/*
+ * rfbSendSetColourMapEntries sends a SetColourMapEntries message to the
+ * client, using values from the currently installed colormap.
+ */
+
+Bool
+rfbSendSetColourMapEntries(cl, firstColour, nColours)
+    rfbClientPtr cl;
+    int firstColour;
+    int nColours;
+{
+    char buf[sz_rfbSetColourMapEntriesMsg + 256 * 3 * 2];
+    rfbSetColourMapEntriesMsg *scme = (rfbSetColourMapEntriesMsg *)buf;
+    CARD16 *rgb = (CARD16 *)(&buf[sz_rfbSetColourMapEntriesMsg]);
+    EntryPtr pent;
+    int i, len;
+
+    scme->type = rfbSetColourMapEntries;
+
+    scme->firstColour = Swap16IfLE(firstColour);
+    scme->nColours = Swap16IfLE(nColours);
+
+    len = sz_rfbSetColourMapEntriesMsg;
+
+    pent = (EntryPtr)&rfbInstalledColormap->red[firstColour];
+    for (i = 0; i < nColours; i++) {
+       if (pent->fShared) {
+           rgb[i*3] = Swap16IfLE(pent->co.shco.red->color);
+           rgb[i*3+1] = Swap16IfLE(pent->co.shco.green->color);
+           rgb[i*3+2] = Swap16IfLE(pent->co.shco.blue->color);
+       } else {
+           rgb[i*3] = Swap16IfLE(pent->co.local.red);
+           rgb[i*3+1] = Swap16IfLE(pent->co.local.green);
+           rgb[i*3+2] = Swap16IfLE(pent->co.local.blue);
+       }
+       pent++;
+    }
+
+    len += nColours * 3 * 2;
+
+    if (WriteExact(cl->sock, buf, len) < 0) {
+       rfbLogPerror("rfbSendSetColourMapEntries: write");
+       rfbCloseSock(cl->sock);
+       return FALSE;
+    }
+    return TRUE;
+}
+
+
+/*
+ * rfbSendBell sends a Bell message to all the clients.
+ */
+
+void
+rfbSendBell()
+{
+    rfbClientPtr cl, nextCl;
+    rfbBellMsg b;
+
+    for (cl = rfbClientHead; cl; cl = nextCl) {
+       nextCl = cl->next;
+       b.type = rfbBell;
+       if (WriteExact(cl->sock, (char *)&b, sz_rfbBellMsg) < 0) {
+           rfbLogPerror("rfbSendBell: write");
+           rfbCloseSock(cl->sock);
+       }
+    }
+}
+
+
+/*
+ * rfbSendServerCutText sends a ServerCutText message to all the clients.
+ */
+
+void
+rfbSendServerCutText(char *str, int len)
+{
+    rfbClientPtr cl, nextCl;
+    rfbServerCutTextMsg sct;
+
+    for (cl = rfbClientHead; cl; cl = nextCl) {
+       nextCl = cl->next;
+       sct.type = rfbServerCutText;
+       sct.length = Swap32IfLE(len);
+       if (WriteExact(cl->sock, (char *)&sct,
+                      sz_rfbServerCutTextMsg) < 0) {
+           rfbLogPerror("rfbSendServerCutText: write");
+           rfbCloseSock(cl->sock);
+           continue;
+       }
+       if (WriteExact(cl->sock, str, len) < 0) {
+           rfbLogPerror("rfbSendServerCutText: write");
+           rfbCloseSock(cl->sock);
+       }
+    }
+}
diff --git a/Xserver/programs/Xserver/hw/vnc/rre.c b/Xserver/programs/Xserver/hw/vnc/rre.c
new file mode 100644 (file)
index 0000000..c47dafa
--- /dev/null
@@ -0,0 +1,319 @@
+/*
+ * rre.c
+ *
+ * Routines to implement Rise-and-Run-length Encoding (RRE).  This
+ * code is based on krw's original javatel rfbserver.
+ */
+
+/*
+ *  Copyright (C) 1999 AT&T Laboratories Cambridge.  All Rights Reserved.
+ *
+ *  This is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This software is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this software; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,
+ *  USA.
+ */
+
+#include <stdio.h>
+#include "rfb.h"
+
+/*
+ * rreBeforeBuf contains pixel data in the client's format.
+ * rreAfterBuf contains the RRE encoded version.  If the RRE encoded version is
+ * larger than the raw data or if it exceeds rreAfterBufSize then
+ * raw encoding is used instead.
+ */
+
+static int rreBeforeBufSize = 0;
+static char *rreBeforeBuf = NULL;
+
+static int rreAfterBufSize = 0;
+static char *rreAfterBuf = NULL;
+static int rreAfterBufLen;
+
+static int subrectEncode8(CARD8 *data, int w, int h);
+static int subrectEncode16(CARD16 *data, int w, int h);
+static int subrectEncode32(CARD32 *data, int w, int h);
+static CARD32 getBgColour(char *data, int size, int bpp);
+
+
+/*
+ * rfbSendRectEncodingRRE - send a given rectangle using RRE encoding.
+ */
+
+Bool
+rfbSendRectEncodingRRE(cl, x, y, w, h)
+    rfbClientPtr cl;
+    int x, y, w, h;
+{
+    rfbFramebufferUpdateRectHeader rect;
+    rfbRREHeader hdr;
+    int nSubrects;
+    int i;
+    char *fbptr = (rfbScreen.pfbMemory + (rfbScreen.paddedWidthInBytes * y)
+                  + (x * (rfbScreen.bitsPerPixel / 8)));
+
+    int maxRawSize = (rfbScreen.width * rfbScreen.height
+                     * (cl->format.bitsPerPixel / 8));
+
+    if (rreBeforeBufSize < maxRawSize) {
+       rreBeforeBufSize = maxRawSize;
+       if (rreBeforeBuf == NULL)
+           rreBeforeBuf = (char *)xalloc(rreBeforeBufSize);
+       else
+           rreBeforeBuf = (char *)xrealloc(rreBeforeBuf, rreBeforeBufSize);
+    }
+
+    if (rreAfterBufSize < maxRawSize) {
+       rreAfterBufSize = maxRawSize;
+       if (rreAfterBuf == NULL)
+           rreAfterBuf = (char *)xalloc(rreAfterBufSize);
+       else
+           rreAfterBuf = (char *)xrealloc(rreAfterBuf, rreAfterBufSize);
+    }
+
+    (*cl->translateFn)(cl->translateLookupTable, &rfbServerFormat,
+                      &cl->format, fbptr, rreBeforeBuf,
+                      rfbScreen.paddedWidthInBytes, w, h);
+
+    switch (cl->format.bitsPerPixel) {
+    case 8:
+       nSubrects = subrectEncode8((CARD8 *)rreBeforeBuf, w, h);
+       break;
+    case 16:
+       nSubrects = subrectEncode16((CARD16 *)rreBeforeBuf, w, h);
+       break;
+    case 32:
+       nSubrects = subrectEncode32((CARD32 *)rreBeforeBuf, w, h);
+       break;
+    default:
+       rfbLog("getBgColour: bpp %d?\n",cl->format.bitsPerPixel);
+       exit(1);
+    }
+       
+    if (nSubrects < 0) {
+
+       /* RRE encoding was too large, use raw */
+
+       return rfbSendRectEncodingRaw(cl, x, y, w, h);
+    }
+
+    cl->rfbRectanglesSent[rfbEncodingRRE]++;
+    cl->rfbBytesSent[rfbEncodingRRE] += (sz_rfbFramebufferUpdateRectHeader
+                                        + sz_rfbRREHeader + rreAfterBufLen);
+
+    if (ublen + sz_rfbFramebufferUpdateRectHeader + sz_rfbRREHeader
+       > UPDATE_BUF_SIZE)
+    {
+       if (!rfbSendUpdateBuf(cl))
+           return FALSE;
+    }
+
+    rect.r.x = Swap16IfLE(x);
+    rect.r.y = Swap16IfLE(y);
+    rect.r.w = Swap16IfLE(w);
+    rect.r.h = Swap16IfLE(h);
+    rect.encoding = Swap32IfLE(rfbEncodingRRE);
+
+    memcpy(&updateBuf[ublen], (char *)&rect,
+          sz_rfbFramebufferUpdateRectHeader);
+    ublen += sz_rfbFramebufferUpdateRectHeader;
+
+    hdr.nSubrects = Swap32IfLE(nSubrects);
+
+    memcpy(&updateBuf[ublen], (char *)&hdr, sz_rfbRREHeader);
+    ublen += sz_rfbRREHeader;
+
+    for (i = 0; i < rreAfterBufLen;) {
+
+       int bytesToCopy = UPDATE_BUF_SIZE - ublen;
+
+       if (i + bytesToCopy > rreAfterBufLen) {
+           bytesToCopy = rreAfterBufLen - i;
+       }
+
+       memcpy(&updateBuf[ublen], &rreAfterBuf[i], bytesToCopy);
+
+       ublen += bytesToCopy;
+       i += bytesToCopy;
+
+       if (ublen == UPDATE_BUF_SIZE) {
+           if (!rfbSendUpdateBuf(cl))
+               return FALSE;
+       }
+    }
+
+    return TRUE;
+}
+
+
+
+/*
+ * subrectEncode() encodes the given multicoloured rectangle as a background 
+ * colour overwritten by single-coloured rectangles.  It returns the number 
+ * of subrectangles in the encoded buffer, or -1 if subrect encoding won't
+ * fit in the buffer.  It puts the encoded rectangles in rreAfterBuf.  The
+ * single-colour rectangle partition is not optimal, but does find the biggest
+ * horizontal or vertical rectangle top-left anchored to each consecutive 
+ * coordinate position.
+ *
+ * The coding scheme is simply [<bgcolour><subrect><subrect>...] where each 
+ * <subrect> is [<colour><x><y><w><h>].
+ */
+
+#define DEFINE_SUBRECT_ENCODE(bpp)                                           \
+static int                                                                   \
+subrectEncode##bpp(data,w,h)                                                 \
+    CARD##bpp *data;                                                         \
+    int w;                                                                   \
+    int h;                                                                   \
+{                                                                            \
+    CARD##bpp cl;                                                            \
+    rfbRectangle subrect;                                                    \
+    int x,y;                                                                 \
+    int i,j;                                                                 \
+    int hx=0,hy,vx=0,vy;                                                     \
+    int hyflag;                                                                      \
+    CARD##bpp *seg;                                                          \
+    CARD##bpp *line;                                                         \
+    int hw,hh,vw,vh;                                                         \
+    int thex,they,thew,theh;                                                 \
+    int numsubs = 0;                                                         \
+    int newLen;                                                                      \
+    CARD##bpp bg = (CARD##bpp)getBgColour((char*)data,w*h,bpp);                      \
+                                                                             \
+    *((CARD##bpp*)rreAfterBuf) = bg;                                         \
+                                                                             \
+    rreAfterBufLen = (bpp/8);                                                \
+                                                                             \
+    for (y=0; y<h; y++) {                                                    \
+      line = data+(y*w);                                                     \
+      for (x=0; x<w; x++) {                                                  \
+        if (line[x] != bg) {                                                 \
+          cl = line[x];                                                              \
+          hy = y-1;                                                          \
+          hyflag = 1;                                                        \
+          for (j=y; j<h; j++) {                                                      \
+            seg = data+(j*w);                                                \
+            if (seg[x] != cl) {break;}                                       \
+            i = x;                                                           \
+            while ((seg[i] == cl) && (i < w)) i += 1;                        \
+            i -= 1;                                                          \
+            if (j == y) vx = hx = i;                                         \
+            if (i < vx) vx = i;                                                      \
+            if ((hyflag > 0) && (i >= hx)) {hy += 1;} else {hyflag = 0;}      \
+          }                                                                  \
+          vy = j-1;                                                          \
+                                                                             \
+          /*  We now have two possible subrects: (x,y,hx,hy) and (x,y,vx,vy)  \
+           *  We'll choose the bigger of the two.                            \
+           */                                                                \
+          hw = hx-x+1;                                                       \
+          hh = hy-y+1;                                                       \
+          vw = vx-x+1;                                                       \
+          vh = vy-y+1;                                                       \
+                                                                             \
+          thex = x;                                                          \
+          they = y;                                                          \
+                                                                             \
+          if ((hw*hh) > (vw*vh)) {                                           \
+            thew = hw;                                                       \
+            theh = hh;                                                       \
+          } else {                                                           \
+            thew = vw;                                                       \
+            theh = vh;                                                       \
+          }                                                                  \
+                                                                             \
+          subrect.x = Swap16IfLE(thex);                                              \
+          subrect.y = Swap16IfLE(they);                                              \
+          subrect.w = Swap16IfLE(thew);                                              \
+          subrect.h = Swap16IfLE(theh);                                              \
+                                                                             \
+         newLen = rreAfterBufLen + (bpp/8) + sz_rfbRectangle;                \
+          if ((newLen > (w * h * (bpp/8))) || (newLen > rreAfterBufSize))     \
+           return -1;                                                        \
+                                                                             \
+         numsubs += 1;                                                       \
+         *((CARD##bpp*)(rreAfterBuf + rreAfterBufLen)) = cl;                 \
+         rreAfterBufLen += (bpp/8);                                          \
+         memcpy(&rreAfterBuf[rreAfterBufLen],&subrect,sz_rfbRectangle);      \
+         rreAfterBufLen += sz_rfbRectangle;                                  \
+                                                                             \
+          /*                                                                 \
+           * Now mark the subrect as done.                                   \
+           */                                                                \
+          for (j=they; j < (they+theh); j++) {                               \
+            for (i=thex; i < (thex+thew); i++) {                             \
+              data[j*w+i] = bg;                                                      \
+            }                                                                \
+          }                                                                  \
+        }                                                                    \
+      }                                                                              \
+    }                                                                        \
+                                                                             \
+    return numsubs;                                                          \
+}
+
+DEFINE_SUBRECT_ENCODE(8)
+DEFINE_SUBRECT_ENCODE(16)
+DEFINE_SUBRECT_ENCODE(32)
+
+
+/*
+ * getBgColour() gets the most prevalent colour in a byte array.
+ */
+static CARD32
+getBgColour(data,size,bpp)
+    char *data;
+    int size;
+    int bpp;
+{
+    
+#define NUMCLRS 256
+  
+  static int counts[NUMCLRS];
+  int i,j,k;
+
+  int maxcount = 0;
+  CARD8 maxclr = 0;
+
+  if (bpp != 8) {
+    if (bpp == 16) {
+      return ((CARD16 *)data)[0];
+    } else if (bpp == 32) {
+      return ((CARD32 *)data)[0];
+    } else {
+      rfbLog("getBgColour: bpp %d?\n",bpp);
+      exit(1);
+    }
+  }
+
+  for (i=0; i<NUMCLRS; i++) {
+    counts[i] = 0;
+  }
+
+  for (j=0; j<size; j++) {
+    k = (int)(((CARD8 *)data)[j]);
+    if (k >= NUMCLRS) {
+      rfbLog("getBgColour: unusual colour = %d\n", k);
+      exit(1);
+    }
+    counts[k] += 1;
+    if (counts[k] > maxcount) {
+      maxcount = counts[k];
+      maxclr = ((CARD8 *)data)[j];
+    }
+  }
+  
+  return maxclr;
+}
diff --git a/Xserver/programs/Xserver/hw/vnc/sockets.c b/Xserver/programs/Xserver/hw/vnc/sockets.c
new file mode 100644 (file)
index 0000000..370a46a
--- /dev/null
@@ -0,0 +1,510 @@
+/*
+ * sockets.c - deal with TCP sockets.
+ *
+ * This code should be independent of any changes in the RFB protocol.  It just
+ * deals with the X server scheduling stuff, calling rfbNewClientConnection and
+ * rfbProcessClientMessage to actually deal with the protocol.  If a socket
+ * needs to be closed for any reason then rfbCloseSock should be called, and
+ * this in turn will call rfbClientConnectionGone.  To make an active
+ * connection out, call rfbConnect - note that this does _not_ call
+ * rfbNewClientConnection.
+ *
+ * This file is divided into two types of function.  Those beginning with
+ * "rfb" are specific to sockets using the RFB protocol.  Those without the
+ * "rfb" prefix are more general socket routines (which are used by the http
+ * code).
+ *
+ * Thanks to Karl Hakimian for pointing out that some platforms return EAGAIN
+ * not EWOULDBLOCK.
+ */
+
+/*
+ *  Copyright (C) 2002 RealVNC Ltd.
+ *  Copyright (C) 1999 AT&T Laboratories Cambridge.  All Rights Reserved.
+ *
+ *  This is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This software is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this software; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,
+ *  USA.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/time.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <netinet/tcp.h>
+#include <arpa/inet.h>
+#include <netdb.h>
+#include <fcntl.h>
+#include <errno.h>
+
+#include "rfb.h"
+
+
+int rfbMaxClientWait = 20000;  /* time (ms) after which we decide client has
+                                  gone away - needed to stop us hanging */
+
+int rfbPort = 0;
+int rfbListenSock = -1;
+Bool rfbLocalhostOnly = FALSE;
+
+static fd_set allFds;
+static int maxFd = 0;
+
+
+/*
+ * rfbInitSockets sets up the TCP sockets to listen for RFB
+ * connections.  It does nothing if called again.
+ */
+
+void
+rfbInitSockets()
+{
+    static Bool done = FALSE;
+
+    if (done)
+       return;
+
+    done = TRUE;
+
+    if (inetdSock != -1) {
+       const int one = 1;
+
+       if (fcntl(inetdSock, F_SETFL, O_NONBLOCK) < 0) {
+           rfbLogPerror("fcntl");
+           exit(1);
+       }
+
+       if (setsockopt(inetdSock, IPPROTO_TCP, TCP_NODELAY,
+                      (char *)&one, sizeof(one)) < 0) {
+           rfbLogPerror("setsockopt");
+           exit(1);
+       }
+
+       AddEnabledDevice(inetdSock);
+       FD_ZERO(&allFds);
+       FD_SET(inetdSock, &allFds);
+       maxFd = inetdSock;
+       return;
+    }
+
+    if (rfbPort == 0) {
+       rfbPort = 5900 + atoi(display);
+    }
+
+    rfbLog("Listening for VNC connections on TCP port %d\n", rfbPort);
+
+    if ((rfbListenSock = ListenOnTCPPort(rfbPort)) < 0) {
+       rfbLogPerror("ListenOnTCPPort");
+       exit(1);
+    }
+
+    AddEnabledDevice(rfbListenSock);
+
+    FD_ZERO(&allFds);
+    FD_SET(rfbListenSock, &allFds);
+    maxFd = rfbListenSock;
+}
+
+
+/*
+ * rfbCheckFds is called from ProcessInputEvents to check for input on the RFB
+ * socket(s).  If there is input to process, the appropriate function in the
+ * RFB server code will be called (rfbNewClientConnection,
+ * rfbProcessClientMessage, etc).
+ */
+
+void
+rfbCheckFds()
+{
+    int nfds;
+    fd_set fds;
+    struct timeval tv;
+    struct sockaddr_in addr;
+    unsigned int addrlen = sizeof(addr);
+    const int one = 1;
+    int sock;
+    static Bool inetdInitDone = FALSE;
+
+    if (!inetdInitDone && inetdSock != -1) {
+       rfbNewClientConnection(inetdSock); 
+       inetdInitDone = TRUE;
+    }
+
+    memcpy((char *)&fds, (char *)&allFds, sizeof(fd_set));
+    tv.tv_sec = 0;
+    tv.tv_usec = 0;
+    nfds = select(maxFd + 1, &fds, NULL, NULL, &tv);
+    if (nfds == 0) {
+       return;
+    }
+    if (nfds < 0) {
+       rfbLogPerror("rfbCheckFds: select");
+       return;
+    }
+
+    if (rfbListenSock != -1 && FD_ISSET(rfbListenSock, &fds)) {
+
+       if ((sock = accept(rfbListenSock,
+                          (struct sockaddr *)&addr, &addrlen)) < 0) {
+           rfbLogPerror("rfbCheckFds: accept");
+           return;
+       }
+
+       if (fcntl(sock, F_SETFL, O_NONBLOCK) < 0) {
+           rfbLogPerror("rfbCheckFds: fcntl");
+           close(sock);
+           return;
+       }
+
+       if (setsockopt(sock, IPPROTO_TCP, TCP_NODELAY,
+                      (char *)&one, sizeof(one)) < 0) {
+           rfbLogPerror("rfbCheckFds: setsockopt");
+           close(sock);
+           return;
+       }
+
+       fprintf(stderr,"\n");
+       rfbLog("Got connection from client %s\n", inet_ntoa(addr.sin_addr));
+
+       AddEnabledDevice(sock);
+       FD_SET(sock, &allFds);
+       maxFd = max(sock,maxFd);
+
+       rfbNewClientConnection(sock);
+
+       FD_CLR(rfbListenSock, &fds);
+       if (--nfds == 0)
+           return;
+    }
+
+    for (sock = 0; sock <= maxFd; sock++) {
+       if (FD_ISSET(sock, &fds) && FD_ISSET(sock, &allFds)) {
+           rfbProcessClientMessage(sock);
+       }
+    }
+}
+
+
+void
+rfbCloseSock(sock)
+    int sock;
+{
+    close(sock);
+    RemoveEnabledDevice(sock);
+    FD_CLR(sock, &allFds);
+    rfbClientConnectionGone(sock);
+    if (sock == inetdSock)
+       GiveUp(0);
+}
+
+
+/*
+ * rfbWaitForClient can be called to wait for the RFB client to send us a
+ * message.  When one is received it is processed by calling
+ * rfbProcessClientMessage().
+ */
+
+void
+rfbWaitForClient(sock)
+    int sock;
+{
+    int n;
+    fd_set fds;
+    struct timeval tv;
+
+    FD_ZERO(&fds);
+    FD_SET(sock, &fds);
+    tv.tv_sec = rfbMaxClientWait / 1000;
+    tv.tv_usec = (rfbMaxClientWait % 1000) * 1000;
+    n = select(sock+1, &fds, NULL, NULL, &tv);
+    if (n < 0) {
+       rfbLogPerror("rfbWaitForClient: select");
+       exit(1);
+    }
+    if (n == 0) {
+       rfbCloseSock(sock);
+       return;
+    }
+
+    rfbProcessClientMessage(sock);
+}
+
+
+/*
+ * rfbConnect is called to make a connection out to a given TCP address.
+ */
+
+int
+rfbConnect(host, port)
+    char *host;
+    int port;
+{
+    int sock;
+    int one = 1;
+
+    fprintf(stderr,"\n");
+    rfbLog("Making connection to client on host %s port %d\n",
+          host,port);
+
+    if ((sock = ConnectToTcpAddr(host, port)) < 0) {
+       rfbLogPerror("connection failed");
+       return -1;
+    }
+
+    if (fcntl(sock, F_SETFL, O_NONBLOCK) < 0) {
+       rfbLogPerror("fcntl failed");
+       close(sock);
+       return -1;
+    }
+
+    if (setsockopt(sock, IPPROTO_TCP, TCP_NODELAY,
+                  (char *)&one, sizeof(one)) < 0) {
+       rfbLogPerror("setsockopt failed");
+       close(sock);
+       return -1;
+    }
+
+    AddEnabledDevice(sock);
+    FD_SET(sock, &allFds);
+    maxFd = max(sock,maxFd);
+
+    return sock;
+}
+
+
+
+
+/*
+ * ReadExact reads an exact number of bytes on a TCP socket.  Returns 1 if
+ * those bytes have been read, 0 if the other end has closed, or -1 if an error
+ * occurred (errno is set to ETIMEDOUT if it timed out).
+ */
+
+int
+ReadExact(sock, buf, len)
+    int sock;
+    char *buf;
+    int len;
+{
+    int n;
+    fd_set fds;
+    struct timeval tv;
+
+    while (len > 0) {
+       n = read(sock, buf, len);
+
+       if (n > 0) {
+
+           buf += n;
+           len -= n;
+
+       } else if (n == 0) {
+
+           return 0;
+
+       } else {
+           if (errno != EWOULDBLOCK && errno != EAGAIN) {
+               return n;
+           }
+
+           FD_ZERO(&fds);
+           FD_SET(sock, &fds);
+           tv.tv_sec = rfbMaxClientWait / 1000;
+           tv.tv_usec = (rfbMaxClientWait % 1000) * 1000;
+           n = select(sock+1, &fds, NULL, NULL, &tv);
+           if (n < 0) {
+               rfbLogPerror("ReadExact: select");
+               return n;
+           }
+           if (n == 0) {
+               errno = ETIMEDOUT;
+               return -1;
+           }
+       }
+    }
+    return 1;
+}
+
+
+
+/*
+ * WriteExact writes an exact number of bytes on a TCP socket.  Returns 1 if
+ * those bytes have been written, or -1 if an error occurred (errno is set to
+ * ETIMEDOUT if it timed out).
+ */
+
+int
+WriteExact(sock, buf, len)
+    int sock;
+    char *buf;
+    int len;
+{
+    int n;
+    fd_set fds;
+    struct timeval tv;
+    int totalTimeWaited = 0;
+
+
+    while (len > 0) {
+       n = write(sock, buf, len);
+
+       if (n > 0) {
+
+           buf += n;
+           len -= n;
+
+       } else if (n == 0) {
+
+           rfbLog("WriteExact: write returned 0?\n");
+           exit(1);
+
+       } else {
+           if (errno != EWOULDBLOCK && errno != EAGAIN) {
+               return n;
+           }
+
+           /* Retry every 5 seconds until we exceed rfbMaxClientWait.  We
+              need to do this because select doesn't necessarily return
+              immediately when the other end has gone away */
+
+           FD_ZERO(&fds);
+           FD_SET(sock, &fds);
+           tv.tv_sec = 5;
+           tv.tv_usec = 0;
+           n = select(sock+1, NULL, &fds, NULL, &tv);
+           if (n < 0) {
+               rfbLogPerror("WriteExact: select");
+               return n;
+           }
+           if (n == 0) {
+               totalTimeWaited += 5000;
+               if (totalTimeWaited >= rfbMaxClientWait) {
+                   errno = ETIMEDOUT;
+                   return -1;
+               }
+           } else {
+               totalTimeWaited = 0;
+           }
+       }
+    }
+    return 1;
+}
+
+
+int
+ListenOnTCPPort(port)
+    int port;
+{
+    int sock;
+    int one = 1;
+#ifdef AF_INET6
+    int ipv = 4;
+    struct sockaddr_in6 addr6;
+#endif
+    struct sockaddr_in addr;
+
+    memset(&addr, 0, sizeof(addr));
+#ifdef AF_INET6
+    ipv = 6;
+    addr6.sin6_family = AF_INET6;
+    addr6.sin6_port = htons(port);
+    if (rfbLocalhostOnly)
+       addr6.sin6_addr = in6addr_loopback;
+    else
+        addr6.sin6_addr = in6addr_any;
+
+    /* Don't fail if an IPv6 socket cannot be established, but fall back to
+       IPv4 */
+    if ((sock = socket(AF_INET6, SOCK_STREAM, 0)) < 0)
+    {
+        ipv = 4;
+#endif
+        addr.sin_family = AF_INET;
+        addr.sin_port = htons(port);
+        if (rfbLocalhostOnly)
+            addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
+        else
+            addr.sin_addr.s_addr = htonl(INADDR_ANY);
+
+        if ((sock = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
+            return -1;
+        }
+#ifdef AF_INET6
+    }
+#endif
+    if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR,
+                  (char *)&one, sizeof(one)) < 0) {
+       close(sock);
+       return -1;
+    }
+#ifdef AF_INET6
+    if (ipv == 6) {
+      if (bind(sock, (struct sockaddr *)&addr6, sizeof(addr6)) < 0) {
+       close(sock);
+       return -1;
+      }
+    }
+    else if (ipv == 4) {
+#endif
+      if (bind(sock, (struct sockaddr *)&addr, sizeof(addr)) < 0) {
+       close(sock);
+       return -1;
+      }      
+#ifdef AF_INET6
+    }
+#endif
+    if (listen(sock, 5) < 0) {
+       close(sock);
+       return -1;
+    }
+
+    return sock;
+}
+
+
+int
+ConnectToTcpAddr(host, port)
+    char *host;
+    int port;
+{
+    struct hostent *hp;
+    int sock;
+    struct sockaddr_in addr;
+
+    addr.sin_family = AF_INET;
+    addr.sin_port = htons(port);
+
+    if ((addr.sin_addr.s_addr = inet_addr(host)) == -1)
+    {
+       if (!(hp = gethostbyname(host))) {
+           errno = EINVAL;
+           return -1;
+       }
+       addr.sin_addr.s_addr = *(unsigned long *)hp->h_addr;
+    }
+
+    if ((sock = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
+       return -1;
+    }
+
+    if (connect(sock, (struct sockaddr *)&addr, (sizeof(addr))) < 0) {
+       close(sock);
+       return -1;
+    }
+
+    return sock;
+}
diff --git a/Xserver/programs/Xserver/hw/vnc/sprite.c b/Xserver/programs/Xserver/hw/vnc/sprite.c
new file mode 100644 (file)
index 0000000..bfe6909
--- /dev/null
@@ -0,0 +1,2009 @@
+/*
+ * sprite.c
+ *
+ * software sprite routines - based on misprite
+ */
+
+/*
+ *  Copyright (C) 2002-2003 RealVNC Ltd.
+ *  Copyright (C) 1999 AT&T Laboratories Cambridge.  All Rights Reserved.
+ *
+ *  This is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This software is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this software; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,
+ *  USA.
+ */
+
+/* $XConsortium: misprite.c,v 5.47 94/04/17 20:27:53 dpw Exp $ */
+
+/*
+
+Copyright (c) 1989  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+*/
+
+# include   "X.h"
+# include   "Xproto.h"
+# include   "misc.h"
+# include   "pixmapstr.h"
+# include   "input.h"
+# include   "mi.h"
+# include   "cursorstr.h"
+# include   "font.h"
+# include   "scrnintstr.h"
+# include   "colormapst.h"
+# include   "windowstr.h"
+# include   "gcstruct.h"
+# include   "mipointer.h"
+# include   "spritest.h"
+# include   "dixfontstr.h"
+# include   "fontstruct.h"
+#include "rfb.h"
+
+/*
+ * screen wrappers
+ */
+
+static int  rfbSpriteScreenIndex;
+static unsigned long rfbSpriteGeneration = 0;
+
+static Bool        rfbSpriteCloseScreen();
+static void        rfbSpriteGetImage();
+static void        rfbSpriteGetSpans();
+static void        rfbSpriteSourceValidate();
+static Bool        rfbSpriteCreateGC();
+static void        rfbSpriteInstallColormap();
+static void        rfbSpriteStoreColors();
+
+static void        rfbSpritePaintWindowBackground();
+static void        rfbSpritePaintWindowBorder();
+static void        rfbSpriteCopyWindow();
+static void        rfbSpriteClearToBackground();
+
+static void        rfbSpriteSaveDoomedAreas();
+static RegionPtr    rfbSpriteRestoreAreas();
+static void        rfbSpriteComputeSaved();
+
+#define SCREEN_PROLOGUE(pScreen, field)\
+  ((pScreen)->field = \
+   ((rfbSpriteScreenPtr) (pScreen)->devPrivates[rfbSpriteScreenIndex].ptr)->field)
+
+#define SCREEN_EPILOGUE(pScreen, field, wrapper)\
+    ((pScreen)->field = wrapper)
+
+/*
+ * GC func wrappers
+ */
+
+static int  rfbSpriteGCIndex;
+
+static void rfbSpriteValidateGC (),  rfbSpriteCopyGC ();
+static void rfbSpriteDestroyGC(),    rfbSpriteChangeGC();
+static void rfbSpriteChangeClip(),   rfbSpriteDestroyClip();
+static void rfbSpriteCopyClip();
+
+static GCFuncs rfbSpriteGCFuncs = {
+    rfbSpriteValidateGC,
+    rfbSpriteChangeGC,
+    rfbSpriteCopyGC,
+    rfbSpriteDestroyGC,
+    rfbSpriteChangeClip,
+    rfbSpriteDestroyClip,
+    rfbSpriteCopyClip,
+};
+
+#define GC_FUNC_PROLOGUE(pGC)                                  \
+    rfbSpriteGCPtr   pGCPriv =                                 \
+       (rfbSpriteGCPtr) (pGC)->devPrivates[rfbSpriteGCIndex].ptr;\
+    (pGC)->funcs = pGCPriv->wrapFuncs;                         \
+    if (pGCPriv->wrapOps)                                      \
+       (pGC)->ops = pGCPriv->wrapOps;
+
+#define GC_FUNC_EPILOGUE(pGC)                                  \
+    pGCPriv->wrapFuncs = (pGC)->funcs;                         \
+    (pGC)->funcs = &rfbSpriteGCFuncs;                          \
+    if (pGCPriv->wrapOps)                                      \
+    {                                                          \
+       pGCPriv->wrapOps = (pGC)->ops;                          \
+       (pGC)->ops = &rfbSpriteGCOps;                           \
+    }
+
+/*
+ * GC op wrappers
+ */
+
+static void        rfbSpriteFillSpans(),       rfbSpriteSetSpans();
+static void        rfbSpritePutImage();
+static RegionPtr    rfbSpriteCopyArea(),               rfbSpriteCopyPlane();
+static void        rfbSpritePolyPoint(),       rfbSpritePolylines();
+static void        rfbSpritePolySegment(),     rfbSpritePolyRectangle();
+static void        rfbSpritePolyArc(),         rfbSpriteFillPolygon();
+static void        rfbSpritePolyFillRect(),    rfbSpritePolyFillArc();
+static int         rfbSpritePolyText8(),       rfbSpritePolyText16();
+static void        rfbSpriteImageText8(),      rfbSpriteImageText16();
+static void        rfbSpriteImageGlyphBlt(),   rfbSpritePolyGlyphBlt();
+static void        rfbSpritePushPixels();
+#ifdef NEED_LINEHELPER
+static void        rfbSpriteLineHelper();
+#endif
+
+static GCOps rfbSpriteGCOps = {
+    rfbSpriteFillSpans,            rfbSpriteSetSpans,      rfbSpritePutImage,  
+    rfbSpriteCopyArea,     rfbSpriteCopyPlane,     rfbSpritePolyPoint,
+    rfbSpritePolylines,            rfbSpritePolySegment,    rfbSpritePolyRectangle,
+    rfbSpritePolyArc,      rfbSpriteFillPolygon,    rfbSpritePolyFillRect,
+    rfbSpritePolyFillArc,    rfbSpritePolyText8,           rfbSpritePolyText16,
+    rfbSpriteImageText8,           rfbSpriteImageText16,    rfbSpriteImageGlyphBlt,
+    rfbSpritePolyGlyphBlt,   rfbSpritePushPixels
+#ifdef NEED_LINEHELPER
+    , rfbSpriteLineHelper
+#endif
+};
+
+/*
+ * testing only -- remove cursor for every draw.  Eventually,
+ * each draw operation will perform a bounding box check against
+ * the saved cursor area
+ */
+
+#define GC_SETUP_CHEAP(pDrawable)                                  \
+    rfbSpriteScreenPtr pScreenPriv = (rfbSpriteScreenPtr)          \
+       (pDrawable)->pScreen->devPrivates[rfbSpriteScreenIndex].ptr; \
+
+#define GC_SETUP(pDrawable, pGC)                                   \
+    GC_SETUP_CHEAP(pDrawable)                                      \
+    rfbSpriteGCPtr     pGCPrivate = (rfbSpriteGCPtr)               \
+       (pGC)->devPrivates[rfbSpriteGCIndex].ptr;                   \
+    GCFuncs *oldFuncs = pGC->funcs;
+
+#define GC_SETUP_AND_CHECK(pDrawable, pGC)                         \
+    GC_SETUP(pDrawable, pGC);                                      \
+    if (GC_CHECK((WindowPtr)pDrawable))                                    \
+       rfbSpriteRemoveCursor (pDrawable->pScreen);
+    
+#define GC_CHECK(pWin)                                             \
+    (rfbScreen.cursorIsDrawn &&                                            \
+        (pScreenPriv->pCacheWin == pWin ?                          \
+           pScreenPriv->isInCacheWin : (                           \
+           ((int) (pScreenPriv->pCacheWin = (pWin))) ,             \
+           (pScreenPriv->isInCacheWin =                            \
+               (pWin)->drawable.x < pScreenPriv->saved.x2 &&       \
+               pScreenPriv->saved.x1 < (pWin)->drawable.x +        \
+                                   (int) (pWin)->drawable.width && \
+               (pWin)->drawable.y < pScreenPriv->saved.y2 &&       \
+               pScreenPriv->saved.y1 < (pWin)->drawable.y +        \
+                                   (int) (pWin)->drawable.height &&\
+               RECT_IN_REGION((pWin)->drawable.pScreen, &(pWin)->borderClip, \
+                       &pScreenPriv->saved) != rgnOUT))))
+
+#define GC_OP_PROLOGUE(pGC) { \
+    (pGC)->funcs = pGCPrivate->wrapFuncs; \
+    (pGC)->ops = pGCPrivate->wrapOps; \
+    }
+
+#define GC_OP_EPILOGUE(pGC) { \
+    pGCPrivate->wrapOps = (pGC)->ops; \
+    (pGC)->funcs = oldFuncs; \
+    (pGC)->ops = &rfbSpriteGCOps; \
+    }
+
+/*
+ * pointer-sprite method table
+ */
+
+static Bool rfbSpriteRealizeCursor (), rfbSpriteUnrealizeCursor ();
+static void rfbSpriteSetCursor (),     rfbSpriteMoveCursor ();
+
+miPointerSpriteFuncRec rfbSpritePointerFuncs = {
+    rfbSpriteRealizeCursor,
+    rfbSpriteUnrealizeCursor,
+    rfbSpriteSetCursor,
+    rfbSpriteMoveCursor,
+};
+
+/*
+ * other misc functions
+ */
+
+static void rfbSpriteRemoveCursor ();
+
+/*
+ * rfbSpriteInitialize -- called from device-dependent screen
+ * initialization proc after all of the function pointers have
+ * been stored in the screen structure.
+ */
+
+Bool
+rfbSpriteInitialize (pScreen, cursorFuncs, screenFuncs)
+    ScreenPtr              pScreen;
+    rfbSpriteCursorFuncPtr   cursorFuncs;
+    miPointerScreenFuncPtr  screenFuncs;
+{
+    rfbSpriteScreenPtr pPriv;
+    VisualPtr          pVisual;
+    
+    if (rfbSpriteGeneration != serverGeneration)
+    {
+       rfbSpriteScreenIndex = AllocateScreenPrivateIndex ();
+       if (rfbSpriteScreenIndex < 0)
+           return FALSE;
+       rfbSpriteGeneration = serverGeneration;
+       rfbSpriteGCIndex = AllocateGCPrivateIndex ();
+    }
+    if (!AllocateGCPrivate(pScreen, rfbSpriteGCIndex, sizeof(rfbSpriteGCRec)))
+       return FALSE;
+    pPriv = (rfbSpriteScreenPtr) xalloc (sizeof (rfbSpriteScreenRec));
+    if (!pPriv)
+       return FALSE;
+    if (!miPointerInitialize (pScreen, &rfbSpritePointerFuncs, screenFuncs,TRUE))
+    {
+       xfree ((pointer) pPriv);
+       return FALSE;
+    }
+    for (pVisual = pScreen->visuals;
+        pVisual->vid != pScreen->rootVisual;
+        pVisual++)
+       ;
+    pPriv->pVisual = pVisual;
+    pPriv->CloseScreen = pScreen->CloseScreen;
+    pPriv->GetImage = pScreen->GetImage;
+    pPriv->GetSpans = pScreen->GetSpans;
+    pPriv->SourceValidate = pScreen->SourceValidate;
+    pPriv->CreateGC = pScreen->CreateGC;
+    pPriv->InstallColormap = pScreen->InstallColormap;
+    pPriv->StoreColors = pScreen->StoreColors;
+
+    pPriv->PaintWindowBackground = pScreen->PaintWindowBackground;
+    pPriv->PaintWindowBorder = pScreen->PaintWindowBorder;
+    pPriv->CopyWindow = pScreen->CopyWindow;
+    pPriv->ClearToBackground = pScreen->ClearToBackground;
+
+    pPriv->SaveDoomedAreas = pScreen->SaveDoomedAreas;
+    pPriv->RestoreAreas = pScreen->RestoreAreas;
+
+    pPriv->pCursor = NULL;
+    pPriv->x = 0;
+    pPriv->y = 0;
+    pPriv->pCacheWin = NullWindow;
+    pPriv->isInCacheWin = FALSE;
+    pPriv->checkPixels = TRUE;
+    pPriv->pInstalledMap = NULL;
+    pPriv->pColormap = NULL;
+    pPriv->funcs = cursorFuncs;
+    pPriv->colors[SOURCE_COLOR].red = 0;
+    pPriv->colors[SOURCE_COLOR].green = 0;
+    pPriv->colors[SOURCE_COLOR].blue = 0;
+    pPriv->colors[MASK_COLOR].red = 0;
+    pPriv->colors[MASK_COLOR].green = 0;
+    pPriv->colors[MASK_COLOR].blue = 0;
+    pScreen->devPrivates[rfbSpriteScreenIndex].ptr = (pointer) pPriv;
+    pScreen->CloseScreen = rfbSpriteCloseScreen;
+    pScreen->GetImage = rfbSpriteGetImage;
+    pScreen->GetSpans = rfbSpriteGetSpans;
+    pScreen->SourceValidate = rfbSpriteSourceValidate;
+    pScreen->CreateGC = rfbSpriteCreateGC;
+    pScreen->InstallColormap = rfbSpriteInstallColormap;
+    pScreen->StoreColors = rfbSpriteStoreColors;
+
+    pScreen->PaintWindowBackground = rfbSpritePaintWindowBackground;
+    pScreen->PaintWindowBorder = rfbSpritePaintWindowBorder;
+    pScreen->CopyWindow = rfbSpriteCopyWindow;
+    pScreen->ClearToBackground = rfbSpriteClearToBackground;
+
+    pScreen->SaveDoomedAreas = rfbSpriteSaveDoomedAreas;
+    pScreen->RestoreAreas = rfbSpriteRestoreAreas;
+
+    return TRUE;
+}
+
+/*
+ * Screen wrappers
+ */
+
+/*
+ * CloseScreen wrapper -- unwrap everything, free the private data
+ * and call the wrapped function
+ */
+
+static Bool
+rfbSpriteCloseScreen (i, pScreen)
+    ScreenPtr  pScreen;
+{
+    rfbSpriteScreenPtr   pScreenPriv;
+
+    pScreenPriv = (rfbSpriteScreenPtr) pScreen->devPrivates[rfbSpriteScreenIndex].ptr;
+
+    pScreen->CloseScreen = pScreenPriv->CloseScreen;
+    pScreen->GetImage = pScreenPriv->GetImage;
+    pScreen->GetSpans = pScreenPriv->GetSpans;
+    pScreen->SourceValidate = pScreenPriv->SourceValidate;
+    pScreen->CreateGC = pScreenPriv->CreateGC;
+    pScreen->InstallColormap = pScreenPriv->InstallColormap;
+    pScreen->StoreColors = pScreenPriv->StoreColors;
+
+    pScreen->PaintWindowBackground = pScreenPriv->PaintWindowBackground;
+    pScreen->PaintWindowBorder = pScreenPriv->PaintWindowBorder;
+    pScreen->CopyWindow = pScreenPriv->CopyWindow;
+    pScreen->ClearToBackground = pScreenPriv->ClearToBackground;
+
+    pScreen->SaveDoomedAreas = pScreenPriv->SaveDoomedAreas;
+    pScreen->RestoreAreas = pScreenPriv->RestoreAreas;
+
+    xfree ((pointer) pScreenPriv);
+
+    return (*pScreen->CloseScreen) (i, pScreen);
+}
+
+static void
+rfbSpriteGetImage (pDrawable, sx, sy, w, h, format, planemask, pdstLine)
+    DrawablePtr            pDrawable;
+    int                    sx, sy, w, h;
+    unsigned int    format;
+    unsigned long   planemask;
+    char           *pdstLine;
+{
+    ScreenPtr      pScreen = pDrawable->pScreen;
+    rfbSpriteScreenPtr    pScreenPriv;
+    
+    SCREEN_PROLOGUE (pScreen, GetImage);
+
+    pScreenPriv = (rfbSpriteScreenPtr) pScreen->devPrivates[rfbSpriteScreenIndex].ptr;
+
+    if (pDrawable->type == DRAWABLE_WINDOW &&
+        rfbScreen.cursorIsDrawn &&
+       ORG_OVERLAP(&pScreenPriv->saved,pDrawable->x,pDrawable->y, sx, sy, w, h))
+    {
+       rfbSpriteRemoveCursor (pScreen);
+    }
+
+    (*pScreen->GetImage) (pDrawable, sx, sy, w, h,
+                         format, planemask, pdstLine);
+
+    SCREEN_EPILOGUE (pScreen, GetImage, rfbSpriteGetImage);
+}
+
+static void
+rfbSpriteGetSpans (pDrawable, wMax, ppt, pwidth, nspans, pdstStart)
+    DrawablePtr        pDrawable;
+    int                wMax;
+    DDXPointPtr        ppt;
+    int                *pwidth;
+    int                nspans;
+    char       *pdstStart;
+{
+    ScreenPtr              pScreen = pDrawable->pScreen;
+    rfbSpriteScreenPtr     pScreenPriv;
+    
+    SCREEN_PROLOGUE (pScreen, GetSpans);
+
+    pScreenPriv = (rfbSpriteScreenPtr) pScreen->devPrivates[rfbSpriteScreenIndex].ptr;
+
+    if (pDrawable->type == DRAWABLE_WINDOW && rfbScreen.cursorIsDrawn)
+    {
+       register DDXPointPtr    pts;
+       register int            *widths;
+       register int            nPts;
+       register int            xorg,
+                               yorg;
+
+       xorg = pDrawable->x;
+       yorg = pDrawable->y;
+
+       for (pts = ppt, widths = pwidth, nPts = nspans;
+            nPts--;
+            pts++, widths++)
+       {
+           if (SPN_OVERLAP(&pScreenPriv->saved,pts->y+yorg,
+                            pts->x+xorg,*widths))
+           {
+               rfbSpriteRemoveCursor (pScreen);
+               break;
+           }
+       }
+    }
+
+    (*pScreen->GetSpans) (pDrawable, wMax, ppt, pwidth, nspans, pdstStart);
+
+    SCREEN_EPILOGUE (pScreen, GetSpans, rfbSpriteGetSpans);
+}
+
+static void
+rfbSpriteSourceValidate (pDrawable, x, y, width, height)
+    DrawablePtr        pDrawable;
+    int                x, y, width, height;
+{
+    ScreenPtr              pScreen = pDrawable->pScreen;
+    rfbSpriteScreenPtr     pScreenPriv;
+    
+    SCREEN_PROLOGUE (pScreen, SourceValidate);
+
+    pScreenPriv = (rfbSpriteScreenPtr) pScreen->devPrivates[rfbSpriteScreenIndex].ptr;
+
+    if (pDrawable->type == DRAWABLE_WINDOW && rfbScreen.cursorIsDrawn &&
+       ORG_OVERLAP(&pScreenPriv->saved, pDrawable->x, pDrawable->y,
+                   x, y, width, height))
+    {
+       rfbSpriteRemoveCursor (pScreen);
+    }
+
+    if (pScreen->SourceValidate)
+       (*pScreen->SourceValidate) (pDrawable, x, y, width, height);
+
+    SCREEN_EPILOGUE (pScreen, SourceValidate, rfbSpriteSourceValidate);
+}
+
+static Bool
+rfbSpriteCreateGC (pGC)
+    GCPtr   pGC;
+{
+    ScreenPtr      pScreen = pGC->pScreen;
+    Bool           ret;
+    rfbSpriteGCPtr   pPriv;
+
+    SCREEN_PROLOGUE (pScreen, CreateGC);
+    
+    pPriv = (rfbSpriteGCPtr)pGC->devPrivates[rfbSpriteGCIndex].ptr;
+
+    ret = (*pScreen->CreateGC) (pGC);
+
+    pPriv->wrapOps = NULL;
+    pPriv->wrapFuncs = pGC->funcs;
+    pGC->funcs = &rfbSpriteGCFuncs;
+
+    SCREEN_EPILOGUE (pScreen, CreateGC, rfbSpriteCreateGC);
+
+    return ret;
+}
+
+static void
+rfbSpriteInstallColormap (pMap)
+    ColormapPtr        pMap;
+{
+    ScreenPtr          pScreen = pMap->pScreen;
+    rfbSpriteScreenPtr pPriv;
+
+    pPriv = (rfbSpriteScreenPtr) pScreen->devPrivates[rfbSpriteScreenIndex].ptr;
+
+    SCREEN_PROLOGUE(pScreen, InstallColormap);
+    
+    (*pScreen->InstallColormap) (pMap);
+
+    SCREEN_EPILOGUE(pScreen, InstallColormap, rfbSpriteInstallColormap);
+
+    pPriv->pInstalledMap = pMap;
+    if (pPriv->pColormap != pMap)
+    {
+       pPriv->checkPixels = TRUE;
+       if (rfbScreen.cursorIsDrawn)
+           rfbSpriteRemoveCursor (pScreen);
+    }
+}
+
+static void
+rfbSpriteStoreColors (pMap, ndef, pdef)
+    ColormapPtr        pMap;
+    int                ndef;
+    xColorItem *pdef;
+{
+    ScreenPtr          pScreen = pMap->pScreen;
+    rfbSpriteScreenPtr pPriv;
+    int                        i;
+    int                        updated;
+    VisualPtr          pVisual;
+
+    pPriv = (rfbSpriteScreenPtr) pScreen->devPrivates[rfbSpriteScreenIndex].ptr;
+
+    SCREEN_PROLOGUE(pScreen, StoreColors);
+    
+    (*pScreen->StoreColors) (pMap, ndef, pdef);
+
+    SCREEN_EPILOGUE(pScreen, StoreColors, rfbSpriteStoreColors);
+
+    if (pPriv->pColormap == pMap)
+    {
+       updated = 0;
+       pVisual = pMap->pVisual;
+       if (pVisual->class == DirectColor)
+       {
+           /* Direct color - match on any of the subfields */
+
+#define MaskMatch(a,b,mask) (((a) & (pVisual->mask)) == ((b) & (pVisual->mask)))
+
+#define UpdateDAC(plane,dac,mask) {\
+    if (MaskMatch (pPriv->colors[plane].pixel,pdef[i].pixel,mask)) {\
+       pPriv->colors[plane].dac = pdef[i].dac; \
+       updated = 1; \
+    } \
+}
+
+#define CheckDirect(plane) \
+           UpdateDAC(plane,red,redMask) \
+           UpdateDAC(plane,green,greenMask) \
+           UpdateDAC(plane,blue,blueMask)
+
+           for (i = 0; i < ndef; i++)
+           {
+               CheckDirect (SOURCE_COLOR)
+               CheckDirect (MASK_COLOR)
+           }
+       }
+       else
+       {
+           /* PseudoColor/GrayScale - match on exact pixel */
+           for (i = 0; i < ndef; i++)
+           {
+               if (pdef[i].pixel == pPriv->colors[SOURCE_COLOR].pixel)
+               {
+                   pPriv->colors[SOURCE_COLOR] = pdef[i];
+                   if (++updated == 2)
+                       break;
+               }
+               if (pdef[i].pixel == pPriv->colors[MASK_COLOR].pixel)
+               {
+                   pPriv->colors[MASK_COLOR] = pdef[i];
+                   if (++updated == 2)
+                       break;
+               }
+           }
+       }
+       if (updated)
+       {
+           pPriv->checkPixels = TRUE;
+           if (rfbScreen.cursorIsDrawn)
+               rfbSpriteRemoveCursor (pScreen);
+       }
+    }
+}
+
+static void
+rfbSpriteFindColors (pScreen)
+    ScreenPtr  pScreen;
+{
+    rfbSpriteScreenPtr pScreenPriv = (rfbSpriteScreenPtr)
+                           pScreen->devPrivates[rfbSpriteScreenIndex].ptr;
+    CursorPtr          pCursor;
+    xColorItem         *sourceColor, *maskColor;
+
+    pCursor = pScreenPriv->pCursor;
+    sourceColor = &pScreenPriv->colors[SOURCE_COLOR];
+    maskColor = &pScreenPriv->colors[MASK_COLOR];
+    if (pScreenPriv->pColormap != pScreenPriv->pInstalledMap ||
+       !(pCursor->foreRed == sourceColor->red &&
+         pCursor->foreGreen == sourceColor->green &&
+          pCursor->foreBlue == sourceColor->blue &&
+         pCursor->backRed == maskColor->red &&
+         pCursor->backGreen == maskColor->green &&
+         pCursor->backBlue == maskColor->blue))
+    {
+       pScreenPriv->pColormap = pScreenPriv->pInstalledMap;
+       sourceColor->red = pCursor->foreRed;
+       sourceColor->green = pCursor->foreGreen;
+       sourceColor->blue = pCursor->foreBlue;
+       FakeAllocColor (pScreenPriv->pColormap, sourceColor);
+       maskColor->red = pCursor->backRed;
+       maskColor->green = pCursor->backGreen;
+       maskColor->blue = pCursor->backBlue;
+       FakeAllocColor (pScreenPriv->pColormap, maskColor);
+       /* "free" the pixels right away, don't let this confuse you */
+       FakeFreeColor(pScreenPriv->pColormap, sourceColor->pixel);
+       FakeFreeColor(pScreenPriv->pColormap, maskColor->pixel);
+    }
+    pScreenPriv->checkPixels = FALSE;
+}
+
+/*
+ * BackingStore wrappers
+ */
+
+static void
+rfbSpriteSaveDoomedAreas (pWin, pObscured, dx, dy)
+    WindowPtr  pWin;
+    RegionPtr  pObscured;
+    int                dx, dy;
+{
+    ScreenPtr          pScreen;
+    rfbSpriteScreenPtr   pScreenPriv;
+    BoxRec             cursorBox;
+
+    pScreen = pWin->drawable.pScreen;
+    
+    SCREEN_PROLOGUE (pScreen, SaveDoomedAreas);
+
+    pScreenPriv = (rfbSpriteScreenPtr) pScreen->devPrivates[rfbSpriteScreenIndex].ptr;
+    if (rfbScreen.cursorIsDrawn)
+    {
+       cursorBox = pScreenPriv->saved;
+
+       if (dx || dy)
+       {
+           cursorBox.x1 += dx;
+           cursorBox.y1 += dy;
+           cursorBox.x2 += dx;
+           cursorBox.y2 += dy;
+       }
+       if (RECT_IN_REGION( pScreen, pObscured, &cursorBox) != rgnOUT)
+           rfbSpriteRemoveCursor (pScreen);
+    }
+
+    (*pScreen->SaveDoomedAreas) (pWin, pObscured, dx, dy);
+
+    SCREEN_EPILOGUE (pScreen, SaveDoomedAreas, rfbSpriteSaveDoomedAreas);
+}
+
+static RegionPtr
+rfbSpriteRestoreAreas (pWin, prgnExposed)
+    WindowPtr  pWin;
+    RegionPtr  prgnExposed;
+{
+    ScreenPtr          pScreen;
+    rfbSpriteScreenPtr   pScreenPriv;
+    RegionPtr          result;
+
+    pScreen = pWin->drawable.pScreen;
+    
+    SCREEN_PROLOGUE (pScreen, RestoreAreas);
+
+    pScreenPriv = (rfbSpriteScreenPtr) pScreen->devPrivates[rfbSpriteScreenIndex].ptr;
+    if (rfbScreen.cursorIsDrawn)
+    {
+       if (RECT_IN_REGION( pScreen, prgnExposed, &pScreenPriv->saved) != rgnOUT)
+           rfbSpriteRemoveCursor (pScreen);
+    }
+
+    result = (*pScreen->RestoreAreas) (pWin, prgnExposed);
+
+    SCREEN_EPILOGUE (pScreen, RestoreAreas, rfbSpriteRestoreAreas);
+
+    return result;
+}
+
+/*
+ * Window wrappers
+ */
+
+static void
+rfbSpritePaintWindowBackground (pWin, pRegion, what)
+    WindowPtr  pWin;
+    RegionPtr  pRegion;
+    int                what;
+{
+    ScreenPtr      pScreen;
+    rfbSpriteScreenPtr    pScreenPriv;
+
+    pScreen = pWin->drawable.pScreen;
+
+    SCREEN_PROLOGUE (pScreen, PaintWindowBackground);
+
+    pScreenPriv = (rfbSpriteScreenPtr) pScreen->devPrivates[rfbSpriteScreenIndex].ptr;
+    if (rfbScreen.cursorIsDrawn)
+    {
+       /*
+        * If the cursor is on the same screen as the window, check the
+        * region to paint for the cursor and remove it as necessary
+        */
+       if (RECT_IN_REGION( pScreen, pRegion, &pScreenPriv->saved) != rgnOUT)
+           rfbSpriteRemoveCursor (pScreen);
+    }
+
+    (*pScreen->PaintWindowBackground) (pWin, pRegion, what);
+
+    SCREEN_EPILOGUE (pScreen, PaintWindowBackground, rfbSpritePaintWindowBackground);
+}
+
+static void
+rfbSpritePaintWindowBorder (pWin, pRegion, what)
+    WindowPtr  pWin;
+    RegionPtr  pRegion;
+    int                what;
+{
+    ScreenPtr      pScreen;
+    rfbSpriteScreenPtr    pScreenPriv;
+
+    pScreen = pWin->drawable.pScreen;
+
+    SCREEN_PROLOGUE (pScreen, PaintWindowBorder);
+
+    pScreenPriv = (rfbSpriteScreenPtr) pScreen->devPrivates[rfbSpriteScreenIndex].ptr;
+    if (rfbScreen.cursorIsDrawn)
+    {
+       /*
+        * If the cursor is on the same screen as the window, check the
+        * region to paint for the cursor and remove it as necessary
+        */
+       if (RECT_IN_REGION( pScreen, pRegion, &pScreenPriv->saved) != rgnOUT)
+           rfbSpriteRemoveCursor (pScreen);
+    }
+
+    (*pScreen->PaintWindowBorder) (pWin, pRegion, what);
+
+    SCREEN_EPILOGUE (pScreen, PaintWindowBorder, rfbSpritePaintWindowBorder);
+}
+
+static void
+rfbSpriteCopyWindow (pWin, ptOldOrg, pRegion)
+    WindowPtr  pWin;
+    DDXPointRec        ptOldOrg;
+    RegionPtr  pRegion;
+{
+    ScreenPtr      pScreen;
+    rfbSpriteScreenPtr    pScreenPriv;
+    BoxRec         cursorBox;
+    int                    dx, dy;
+
+    pScreen = pWin->drawable.pScreen;
+
+    SCREEN_PROLOGUE (pScreen, CopyWindow);
+
+    pScreenPriv = (rfbSpriteScreenPtr) pScreen->devPrivates[rfbSpriteScreenIndex].ptr;
+    if (rfbScreen.cursorIsDrawn)
+    {
+       /*
+        * check both the source and the destination areas.  The given
+        * region is source relative, so offset the cursor box by
+        * the delta position
+        */
+       cursorBox = pScreenPriv->saved;
+       dx = pWin->drawable.x - ptOldOrg.x;
+       dy = pWin->drawable.y - ptOldOrg.y;
+       cursorBox.x1 -= dx;
+       cursorBox.x2 -= dx;
+       cursorBox.y1 -= dy;
+       cursorBox.y2 -= dy;
+       if (RECT_IN_REGION( pScreen, pRegion, &pScreenPriv->saved) != rgnOUT ||
+           RECT_IN_REGION( pScreen, pRegion, &cursorBox) != rgnOUT)
+           rfbSpriteRemoveCursor (pScreen);
+    }
+
+    (*pScreen->CopyWindow) (pWin, ptOldOrg, pRegion);
+
+    SCREEN_EPILOGUE (pScreen, CopyWindow, rfbSpriteCopyWindow);
+}
+
+static void
+rfbSpriteClearToBackground (pWin, x, y, w, h, generateExposures)
+    WindowPtr pWin;
+    short x,y;
+    unsigned short w,h;
+    Bool generateExposures;
+{
+    ScreenPtr          pScreen;
+    rfbSpriteScreenPtr pScreenPriv;
+    int                        realw, realh;
+
+    pScreen = pWin->drawable.pScreen;
+
+    SCREEN_PROLOGUE (pScreen, ClearToBackground);
+
+    pScreenPriv = (rfbSpriteScreenPtr) pScreen->devPrivates[rfbSpriteScreenIndex].ptr;
+    if (GC_CHECK(pWin))
+    {
+       if (!(realw = w))
+           realw = (int) pWin->drawable.width - x;
+       if (!(realh = h))
+           realh = (int) pWin->drawable.height - y;
+       if (ORG_OVERLAP(&pScreenPriv->saved, pWin->drawable.x, pWin->drawable.y,
+                       x, y, realw, realh))
+       {
+           rfbSpriteRemoveCursor (pScreen);
+       }
+    }
+
+    (*pScreen->ClearToBackground) (pWin, x, y, w, h, generateExposures);
+
+    SCREEN_EPILOGUE (pScreen, ClearToBackground, rfbSpriteClearToBackground);
+}
+
+/*
+ * GC Func wrappers
+ */
+
+static void
+rfbSpriteValidateGC (pGC, changes, pDrawable)
+    GCPtr      pGC;
+    Mask       changes;
+    DrawablePtr        pDrawable;
+{
+    GC_FUNC_PROLOGUE (pGC);
+
+    (*pGC->funcs->ValidateGC) (pGC, changes, pDrawable);
+    
+    pGCPriv->wrapOps = NULL;
+    if (pDrawable->type == DRAWABLE_WINDOW && ((WindowPtr) pDrawable)->viewable)
+    {
+       WindowPtr   pWin;
+       RegionPtr   pRegion;
+
+       pWin = (WindowPtr) pDrawable;
+       pRegion = &pWin->clipList;
+       if (pGC->subWindowMode == IncludeInferiors)
+           pRegion = &pWin->borderClip;
+       if (REGION_NOTEMPTY(pDrawable->pScreen, pRegion))
+           pGCPriv->wrapOps = pGC->ops;
+    }
+
+    GC_FUNC_EPILOGUE (pGC);
+}
+
+static void
+rfbSpriteChangeGC (pGC, mask)
+    GCPtr          pGC;
+    unsigned long   mask;
+{
+    GC_FUNC_PROLOGUE (pGC);
+
+    (*pGC->funcs->ChangeGC) (pGC, mask);
+    
+    GC_FUNC_EPILOGUE (pGC);
+}
+
+static void
+rfbSpriteCopyGC (pGCSrc, mask, pGCDst)
+    GCPtr          pGCSrc, pGCDst;
+    unsigned long   mask;
+{
+    GC_FUNC_PROLOGUE (pGCDst);
+
+    (*pGCDst->funcs->CopyGC) (pGCSrc, mask, pGCDst);
+    
+    GC_FUNC_EPILOGUE (pGCDst);
+}
+
+static void
+rfbSpriteDestroyGC (pGC)
+    GCPtr   pGC;
+{
+    GC_FUNC_PROLOGUE (pGC);
+
+    (*pGC->funcs->DestroyGC) (pGC);
+    
+    GC_FUNC_EPILOGUE (pGC);
+}
+
+static void
+rfbSpriteChangeClip (pGC, type, pvalue, nrects)
+    GCPtr   pGC;
+    int                type;
+    pointer    pvalue;
+    int                nrects;
+{
+    GC_FUNC_PROLOGUE (pGC);
+
+    (*pGC->funcs->ChangeClip) (pGC, type, pvalue, nrects);
+
+    GC_FUNC_EPILOGUE (pGC);
+}
+
+static void
+rfbSpriteCopyClip(pgcDst, pgcSrc)
+    GCPtr pgcDst, pgcSrc;
+{
+    GC_FUNC_PROLOGUE (pgcDst);
+
+    (* pgcDst->funcs->CopyClip)(pgcDst, pgcSrc);
+
+    GC_FUNC_EPILOGUE (pgcDst);
+}
+
+static void
+rfbSpriteDestroyClip(pGC)
+    GCPtr      pGC;
+{
+    GC_FUNC_PROLOGUE (pGC);
+
+    (* pGC->funcs->DestroyClip)(pGC);
+
+    GC_FUNC_EPILOGUE (pGC);
+}
+
+/*
+ * GC Op wrappers
+ */
+
+static void
+rfbSpriteFillSpans(pDrawable, pGC, nInit, pptInit, pwidthInit, fSorted)
+    DrawablePtr pDrawable;
+    GCPtr      pGC;
+    int                nInit;                  /* number of spans to fill */
+    DDXPointPtr pptInit;               /* pointer to list of start points */
+    int                *pwidthInit;            /* pointer to list of n widths */
+    int        fSorted;
+{
+    GC_SETUP(pDrawable, pGC);
+
+    if (GC_CHECK((WindowPtr) pDrawable))
+    {
+       register DDXPointPtr    pts;
+       register int            *widths;
+       register int            nPts;
+
+       for (pts = pptInit, widths = pwidthInit, nPts = nInit;
+            nPts--;
+            pts++, widths++)
+       {
+            if (SPN_OVERLAP(&pScreenPriv->saved,pts->y,pts->x,*widths))
+            {
+                rfbSpriteRemoveCursor (pDrawable->pScreen);
+                break;
+            }
+       }
+    }
+
+    GC_OP_PROLOGUE (pGC);
+
+    (*pGC->ops->FillSpans) (pDrawable, pGC, nInit, pptInit, pwidthInit, fSorted);
+
+    GC_OP_EPILOGUE (pGC);
+}
+
+static void
+rfbSpriteSetSpans(pDrawable, pGC, psrc, ppt, pwidth, nspans, fSorted)
+    DrawablePtr                pDrawable;
+    GCPtr              pGC;
+    char               *psrc;
+    register DDXPointPtr ppt;
+    int                        *pwidth;
+    int                        nspans;
+    int                        fSorted;
+{
+    GC_SETUP(pDrawable, pGC);
+
+    if (GC_CHECK((WindowPtr) pDrawable))
+    {
+       register DDXPointPtr    pts;
+       register int            *widths;
+       register int            nPts;
+
+       for (pts = ppt, widths = pwidth, nPts = nspans;
+            nPts--;
+            pts++, widths++)
+       {
+            if (SPN_OVERLAP(&pScreenPriv->saved,pts->y,pts->x,*widths))
+            {
+                rfbSpriteRemoveCursor(pDrawable->pScreen);
+                break;
+            }
+       }
+    }
+
+    GC_OP_PROLOGUE (pGC);
+
+    (*pGC->ops->SetSpans) (pDrawable, pGC, psrc, ppt, pwidth, nspans, fSorted);
+
+    GC_OP_EPILOGUE (pGC);
+}
+
+static void
+rfbSpritePutImage(pDrawable, pGC, depth, x, y, w, h, leftPad, format, pBits)
+    DrawablePtr          pDrawable;
+    GCPtr        pGC;
+    int                  depth;
+    int                  x;
+    int                  y;
+    int                  w;
+    int                  h;
+    int                  format;
+    char         *pBits;
+{
+    GC_SETUP(pDrawable, pGC);
+
+    if (GC_CHECK((WindowPtr) pDrawable))
+    {
+       if (ORG_OVERLAP(&pScreenPriv->saved,pDrawable->x,pDrawable->y,
+                       x,y,w,h))
+       {
+           rfbSpriteRemoveCursor (pDrawable->pScreen);
+       }
+    }
+
+    GC_OP_PROLOGUE (pGC);
+
+    (*pGC->ops->PutImage) (pDrawable, pGC, depth, x, y, w, h, leftPad, format, pBits);
+
+    GC_OP_EPILOGUE (pGC);
+}
+
+static RegionPtr
+rfbSpriteCopyArea (pSrc, pDst, pGC, srcx, srcy, w, h, dstx, dsty)
+    DrawablePtr          pSrc;
+    DrawablePtr          pDst;
+    GCPtr        pGC;
+    int                  srcx;
+    int                  srcy;
+    int                  w;
+    int                  h;
+    int                  dstx;
+    int                  dsty;
+{
+    RegionPtr rgn;
+
+    GC_SETUP(pDst, pGC);
+
+    /* check destination/source overlap. */
+    if (GC_CHECK((WindowPtr) pDst) &&
+        (ORG_OVERLAP(&pScreenPriv->saved,pDst->x,pDst->y,dstx,dsty,w,h) ||
+         ((pDst == pSrc) &&
+          ORG_OVERLAP(&pScreenPriv->saved,pSrc->x,pSrc->y,srcx,srcy,w,h))))
+    {
+       rfbSpriteRemoveCursor (pDst->pScreen);
+    }
+    GC_OP_PROLOGUE (pGC);
+
+    rgn = (*pGC->ops->CopyArea) (pSrc, pDst, pGC, srcx, srcy, w, h,
+                                dstx, dsty);
+
+    GC_OP_EPILOGUE (pGC);
+
+    return rgn;
+}
+
+static RegionPtr
+rfbSpriteCopyPlane (pSrc, pDst, pGC, srcx, srcy, w, h, dstx, dsty, plane)
+    DrawablePtr          pSrc;
+    DrawablePtr          pDst;
+    register GCPtr pGC;
+    int          srcx,
+                 srcy;
+    int          w,
+                 h;
+    int          dstx,
+                 dsty;
+    unsigned long  plane;
+{
+    RegionPtr rgn;
+
+    GC_SETUP(pDst, pGC);
+
+    /*
+     * check destination/source for overlap.
+     */
+    if (GC_CHECK((WindowPtr) pDst) &&
+       (ORG_OVERLAP(&pScreenPriv->saved,pDst->x,pDst->y,dstx,dsty,w,h) ||
+        ((pDst == pSrc) &&
+         ORG_OVERLAP(&pScreenPriv->saved,pSrc->x,pSrc->y,srcx,srcy,w,h))))
+    {
+       rfbSpriteRemoveCursor (pDst->pScreen);
+    }
+
+    GC_OP_PROLOGUE (pGC);
+
+    rgn = (*pGC->ops->CopyPlane) (pSrc, pDst, pGC, srcx, srcy, w, h,
+                                 dstx, dsty, plane);
+
+    GC_OP_EPILOGUE (pGC);
+
+    return rgn;
+}
+
+static void
+rfbSpritePolyPoint (pDrawable, pGC, mode, npt, pptInit)
+    DrawablePtr pDrawable;
+    GCPtr      pGC;
+    int                mode;           /* Origin or Previous */
+    int                npt;
+    xPoint     *pptInit;
+{
+    xPoint     t;
+    int                n;
+    BoxRec     cursor;
+    register xPoint *pts;
+
+    GC_SETUP (pDrawable, pGC);
+
+    if (npt && GC_CHECK((WindowPtr) pDrawable))
+    {
+       cursor.x1 = pScreenPriv->saved.x1 - pDrawable->x;
+       cursor.y1 = pScreenPriv->saved.y1 - pDrawable->y;
+       cursor.x2 = pScreenPriv->saved.x2 - pDrawable->x;
+       cursor.y2 = pScreenPriv->saved.y2 - pDrawable->y;
+
+       if (mode == CoordModePrevious)
+       {
+           t.x = 0;
+           t.y = 0;
+           for (pts = pptInit, n = npt; n--; pts++)
+           {
+               t.x += pts->x;
+               t.y += pts->y;
+               if (cursor.x1 <= t.x && t.x <= cursor.x2 &&
+                   cursor.y1 <= t.y && t.y <= cursor.y2)
+               {
+                   rfbSpriteRemoveCursor (pDrawable->pScreen);
+                   break;
+               }
+           }
+       }
+       else
+       {
+           for (pts = pptInit, n = npt; n--; pts++)
+           {
+               if (cursor.x1 <= pts->x && pts->x <= cursor.x2 &&
+                   cursor.y1 <= pts->y && pts->y <= cursor.y2)
+               {
+                   rfbSpriteRemoveCursor (pDrawable->pScreen);
+                   break;
+               }
+           }
+       }
+    }
+
+    GC_OP_PROLOGUE (pGC);
+
+    (*pGC->ops->PolyPoint) (pDrawable, pGC, mode, npt, pptInit);
+
+    GC_OP_EPILOGUE (pGC);
+}
+
+static void
+rfbSpritePolylines (pDrawable, pGC, mode, npt, pptInit)
+    DrawablePtr          pDrawable;
+    GCPtr        pGC;
+    int                  mode;
+    int                  npt;
+    DDXPointPtr          pptInit;
+{
+    BoxPtr  cursor;
+    register DDXPointPtr pts;
+    int            n;
+    int            x, y, x1, y1, x2, y2;
+    int            lw;
+    int            extra;
+
+    GC_SETUP (pDrawable, pGC);
+
+    if (npt && GC_CHECK((WindowPtr) pDrawable))
+    {
+       cursor = &pScreenPriv->saved;
+       lw = pGC->lineWidth;
+       x = pptInit->x + pDrawable->x;
+       y = pptInit->y + pDrawable->y;
+
+       if (npt == 1)
+       {
+           extra = lw >> 1;
+           if (LINE_OVERLAP(cursor, x, y, x, y, extra))
+               rfbSpriteRemoveCursor (pDrawable->pScreen);
+       }
+       else
+       {
+           extra = lw >> 1;
+           /*
+            * mitered joins can project quite a way from
+            * the line end; the 11 degree miter limit limits
+            * this extension to 10.43 * lw / 2, rounded up
+            * and converted to int yields 6 * lw
+            */
+           if (pGC->joinStyle == JoinMiter)
+               extra = 6 * lw;
+           else if (pGC->capStyle == CapProjecting)
+               extra = lw;
+           for (pts = pptInit + 1, n = npt - 1; n--; pts++)
+           {
+               x1 = x;
+               y1 = y;
+               if (mode == CoordModeOrigin)
+               {
+                   x2 = pDrawable->x + pts->x;
+                   y2 = pDrawable->y + pts->y;
+               }
+               else
+               {
+                   x2 = x + pts->x;
+                   y2 = y + pts->y;
+               }
+               x = x2;
+               y = y2;
+               LINE_SORT(x1, y1, x2, y2);
+               if (LINE_OVERLAP(cursor, x1, y1, x2, y2, extra))
+               {
+                   rfbSpriteRemoveCursor (pDrawable->pScreen);
+                   break;
+               }
+           }
+       }
+    }
+    GC_OP_PROLOGUE (pGC);
+
+    (*pGC->ops->Polylines) (pDrawable, pGC, mode, npt, pptInit);
+
+    GC_OP_EPILOGUE (pGC);
+}
+
+static void
+rfbSpritePolySegment(pDrawable, pGC, nseg, pSegs)
+    DrawablePtr pDrawable;
+    GCPtr      pGC;
+    int                nseg;
+    xSegment   *pSegs;
+{
+    int            n;
+    register xSegment *segs;
+    BoxPtr  cursor;
+    int            x1, y1, x2, y2;
+    int            extra;
+
+    GC_SETUP(pDrawable, pGC);
+
+    if (nseg && GC_CHECK((WindowPtr) pDrawable))
+    {
+       cursor = &pScreenPriv->saved;
+       extra = pGC->lineWidth >> 1;
+       if (pGC->capStyle == CapProjecting)
+           extra = pGC->lineWidth;
+       for (segs = pSegs, n = nseg; n--; segs++)
+       {
+           x1 = segs->x1 + pDrawable->x;
+           y1 = segs->y1 + pDrawable->y;
+           x2 = segs->x2 + pDrawable->x;
+           y2 = segs->y2 + pDrawable->y;
+           LINE_SORT(x1, y1, x2, y2);
+           if (LINE_OVERLAP(cursor, x1, y1, x2, y2, extra))
+           {
+               rfbSpriteRemoveCursor (pDrawable->pScreen);
+               break;
+           }
+       }
+    }
+
+    GC_OP_PROLOGUE (pGC);
+
+    (*pGC->ops->PolySegment) (pDrawable, pGC, nseg, pSegs);
+
+    GC_OP_EPILOGUE (pGC);
+}
+
+static void
+rfbSpritePolyRectangle(pDrawable, pGC, nrects, pRects)
+    DrawablePtr        pDrawable;
+    GCPtr      pGC;
+    int                nrects;
+    xRectangle *pRects;
+{
+    register xRectangle *rects;
+    BoxPtr  cursor;
+    int            lw;
+    int            n;
+    int     x1, y1, x2, y2;
+    
+    GC_SETUP (pDrawable, pGC);
+
+    if (GC_CHECK((WindowPtr) pDrawable))
+    {
+       lw = pGC->lineWidth >> 1;
+       cursor = &pScreenPriv->saved;
+       for (rects = pRects, n = nrects; n--; rects++)
+       {
+           x1 = rects->x + pDrawable->x;
+           y1 = rects->y + pDrawable->y;
+           x2 = x1 + (int)rects->width;
+           y2 = y1 + (int)rects->height;
+           if (LINE_OVERLAP(cursor, x1, y1, x2, y1, lw) ||
+               LINE_OVERLAP(cursor, x2, y1, x2, y2, lw) ||
+               LINE_OVERLAP(cursor, x1, y2, x2, y2, lw) ||
+               LINE_OVERLAP(cursor, x1, y1, x1, y2, lw))
+           {
+               rfbSpriteRemoveCursor (pDrawable->pScreen);
+               break;
+           }
+       }
+    }
+
+    GC_OP_PROLOGUE (pGC);
+
+    (*pGC->ops->PolyRectangle) (pDrawable, pGC, nrects, pRects);
+
+    GC_OP_EPILOGUE (pGC);
+}
+
+static void
+rfbSpritePolyArc(pDrawable, pGC, narcs, parcs)
+    DrawablePtr        pDrawable;
+    register GCPtr     pGC;
+    int                narcs;
+    xArc       *parcs;
+{
+    BoxPtr  cursor;
+    int            lw;
+    int            n;
+    register xArc *arcs;
+    
+    GC_SETUP (pDrawable, pGC);
+
+    if (GC_CHECK((WindowPtr) pDrawable))
+    {
+       lw = pGC->lineWidth >> 1;
+       cursor = &pScreenPriv->saved;
+       for (arcs = parcs, n = narcs; n--; arcs++)
+       {
+           if (ORG_OVERLAP (cursor, pDrawable->x, pDrawable->y,
+                            arcs->x - lw, arcs->y - lw,
+                            (int) arcs->width + pGC->lineWidth,
+                            (int) arcs->height + pGC->lineWidth))
+           {
+               rfbSpriteRemoveCursor (pDrawable->pScreen);
+               break;
+           }
+       }
+    }
+
+    GC_OP_PROLOGUE (pGC);
+
+    (*pGC->ops->PolyArc) (pDrawable, pGC, narcs, parcs);
+
+    GC_OP_EPILOGUE (pGC);
+}
+
+static void
+rfbSpriteFillPolygon(pDrawable, pGC, shape, mode, count, pPts)
+    register DrawablePtr pDrawable;
+    register GCPtr     pGC;
+    int                        shape, mode;
+    int                        count;
+    DDXPointPtr                pPts;
+{
+    int x, y, minx, miny, maxx, maxy;
+    register DDXPointPtr pts;
+    int n;
+
+    GC_SETUP (pDrawable, pGC);
+
+    if (count && GC_CHECK((WindowPtr) pDrawable))
+    {
+       x = pDrawable->x;
+       y = pDrawable->y;
+       pts = pPts;
+       minx = maxx = pts->x;
+       miny = maxy = pts->y;
+       pts++;
+       n = count - 1;
+
+       if (mode == CoordModeOrigin)
+       {
+           for (; n--; pts++)
+           {
+               if (pts->x < minx)
+                   minx = pts->x;
+               else if (pts->x > maxx)
+                   maxx = pts->x;
+               if (pts->y < miny)
+                   miny = pts->y;
+               else if (pts->y > maxy)
+                   maxy = pts->y;
+           }
+           minx += x;
+           miny += y;
+           maxx += x;
+           maxy += y;
+       }
+       else
+       {
+           x += minx;
+           y += miny;
+           minx = maxx = x;
+           miny = maxy = y;
+           for (; n--; pts++)
+           {
+               x += pts->x;
+               y += pts->y;
+               if (x < minx)
+                   minx = x;
+               else if (x > maxx)
+                   maxx = x;
+               if (y < miny)
+                   miny = y;
+               else if (y > maxy)
+                   maxy = y;
+           }
+       }
+       if (BOX_OVERLAP(&pScreenPriv->saved,minx,miny,maxx,maxy))
+           rfbSpriteRemoveCursor (pDrawable->pScreen);
+    }
+
+    GC_OP_PROLOGUE (pGC);
+
+    (*pGC->ops->FillPolygon) (pDrawable, pGC, shape, mode, count, pPts);
+
+    GC_OP_EPILOGUE (pGC);
+}
+
+static void
+rfbSpritePolyFillRect(pDrawable, pGC, nrectFill, prectInit)
+    DrawablePtr pDrawable;
+    GCPtr      pGC;
+    int                nrectFill;      /* number of rectangles to fill */
+    xRectangle *prectInit;     /* Pointer to first rectangle to fill */
+{
+    GC_SETUP(pDrawable, pGC);
+
+    if (GC_CHECK((WindowPtr) pDrawable))
+    {
+       register int        nRect;
+       register xRectangle *pRect;
+       register int        xorg, yorg;
+
+       xorg = pDrawable->x;
+       yorg = pDrawable->y;
+
+       for (nRect = nrectFill, pRect = prectInit; nRect--; pRect++) {
+           if (ORGRECT_OVERLAP(&pScreenPriv->saved,xorg,yorg,pRect)){
+               rfbSpriteRemoveCursor(pDrawable->pScreen);
+               break;
+           }
+       }
+    }
+
+    GC_OP_PROLOGUE (pGC);
+
+    (*pGC->ops->PolyFillRect) (pDrawable, pGC, nrectFill, prectInit);
+
+    GC_OP_EPILOGUE (pGC);
+}
+
+static void
+rfbSpritePolyFillArc(pDrawable, pGC, narcs, parcs)
+    DrawablePtr        pDrawable;
+    GCPtr      pGC;
+    int                narcs;
+    xArc       *parcs;
+{
+    GC_SETUP(pDrawable, pGC);
+
+    if (GC_CHECK((WindowPtr) pDrawable))
+    {
+       register int    n;
+       BoxPtr          cursor;
+       register xArc *arcs;
+
+       cursor = &pScreenPriv->saved;
+
+       for (arcs = parcs, n = narcs; n--; arcs++)
+       {
+           if (ORG_OVERLAP(cursor, pDrawable->x, pDrawable->y,
+                           arcs->x, arcs->y,
+                           (int) arcs->width, (int) arcs->height))
+           {
+               rfbSpriteRemoveCursor (pDrawable->pScreen);
+               break;
+           }
+       }
+    }
+
+    GC_OP_PROLOGUE (pGC);
+
+    (*pGC->ops->PolyFillArc) (pDrawable, pGC, narcs, parcs);
+
+    GC_OP_EPILOGUE (pGC);
+}
+
+/*
+ * general Poly/Image text function.  Extract glyph information,
+ * compute bounding box and remove cursor if it is overlapped.
+ */
+
+static Bool
+rfbSpriteTextOverlap (pDraw, font, x, y, n, charinfo, imageblt, w, cursorBox)
+    DrawablePtr   pDraw;
+    FontPtr      font;
+    int                  x, y;
+    unsigned int  n;
+    CharInfoPtr   *charinfo;
+    Bool         imageblt;
+    unsigned int  w;
+    BoxPtr       cursorBox;
+{
+    ExtentInfoRec extents;
+
+    x += pDraw->x;
+    y += pDraw->y;
+
+    if (FONTMINBOUNDS(font,characterWidth) >= 0)
+    {
+       /* compute an approximate (but covering) bounding box */
+       if (!imageblt || (charinfo[0]->metrics.leftSideBearing < 0))
+           extents.overallLeft = charinfo[0]->metrics.leftSideBearing;
+       else
+           extents.overallLeft = 0;
+       if (w)
+           extents.overallRight = w - charinfo[n-1]->metrics.characterWidth;
+       else
+           extents.overallRight = FONTMAXBOUNDS(font,characterWidth)
+                                   * (n - 1);
+       if (imageblt && (charinfo[n-1]->metrics.characterWidth >
+                        charinfo[n-1]->metrics.rightSideBearing))
+           extents.overallRight += charinfo[n-1]->metrics.characterWidth;
+       else
+           extents.overallRight += charinfo[n-1]->metrics.rightSideBearing;
+       if (imageblt && FONTASCENT(font) > FONTMAXBOUNDS(font,ascent))
+           extents.overallAscent = FONTASCENT(font);
+       else
+           extents.overallAscent = FONTMAXBOUNDS(font, ascent);
+       if (imageblt && FONTDESCENT(font) > FONTMAXBOUNDS(font,descent))
+           extents.overallDescent = FONTDESCENT(font);
+       else
+           extents.overallDescent = FONTMAXBOUNDS(font,descent);
+       if (!BOX_OVERLAP(cursorBox,
+                        x + extents.overallLeft,
+                        y - extents.overallAscent,
+                        x + extents.overallRight,
+                        y + extents.overallDescent))
+           return FALSE;
+       else if (imageblt && w)
+           return TRUE;
+       /* if it does overlap, fall through and compute exactly, because
+        * taking down the cursor is expensive enough to make this worth it
+        */
+    }
+    QueryGlyphExtents(font, charinfo, n, &extents);
+    if (imageblt)
+    {
+       if (extents.overallWidth > extents.overallRight)
+           extents.overallRight = extents.overallWidth;
+       if (extents.overallWidth < extents.overallLeft)
+           extents.overallLeft = extents.overallWidth;
+       if (extents.overallLeft > 0)
+           extents.overallLeft = 0;
+       if (extents.fontAscent > extents.overallAscent)
+           extents.overallAscent = extents.fontAscent;
+       if (extents.fontDescent > extents.overallDescent)
+           extents.overallDescent = extents.fontDescent;
+    }
+    return (BOX_OVERLAP(cursorBox,
+                       x + extents.overallLeft,
+                       y - extents.overallAscent,
+                       x + extents.overallRight,
+                       y + extents.overallDescent));
+}
+
+/*
+ * values for textType:
+ */
+#define TT_POLY8   0
+#define TT_IMAGE8  1
+#define TT_POLY16  2
+#define TT_IMAGE16 3
+
+static int 
+rfbSpriteText (pDraw, pGC, x, y, count, chars, fontEncoding, textType, cursorBox)
+    DrawablePtr            pDraw;
+    GCPtr          pGC;
+    int                    x,
+                   y;
+    unsigned long    count;
+    char           *chars;
+    FontEncoding    fontEncoding;
+    Bool           textType;
+    BoxPtr         cursorBox;
+{
+    CharInfoPtr *charinfo;
+    register CharInfoPtr *info;
+    unsigned long i;
+    unsigned int  n;
+    int                  w;
+    void         (*drawFunc)() = 0;
+
+    Bool imageblt;
+
+    imageblt = (textType == TT_IMAGE8) || (textType == TT_IMAGE16);
+
+    charinfo = (CharInfoPtr *) ALLOCATE_LOCAL(count * sizeof(CharInfoPtr));
+    if (!charinfo)
+       return x;
+
+    GetGlyphs(pGC->font, count, (unsigned char *)chars,
+             fontEncoding, &i, charinfo);
+    n = (unsigned int)i;
+    w = 0;
+    if (!imageblt)
+       for (info = charinfo; i--; info++)
+           w += (*info)->metrics.characterWidth;
+
+    if (n != 0) {
+       if (rfbSpriteTextOverlap(pDraw, pGC->font, x, y, n, charinfo, imageblt, w, cursorBox))
+           rfbSpriteRemoveCursor(pDraw->pScreen);
+
+#ifdef AVOID_GLYPHBLT
+       /*
+        * On displays like Apollos, which do not optimize the GlyphBlt functions because they
+        * convert fonts to their internal form in RealizeFont and optimize text directly, we
+        * want to invoke the text functions here, not the GlyphBlt functions.
+        */
+       switch (textType)
+       {
+       case TT_POLY8:
+           drawFunc = (void (*)())pGC->ops->PolyText8;
+           break;
+       case TT_IMAGE8:
+           drawFunc = pGC->ops->ImageText8;
+           break;
+       case TT_POLY16:
+           drawFunc = (void (*)())pGC->ops->PolyText16;
+           break;
+       case TT_IMAGE16:
+           drawFunc = pGC->ops->ImageText16;
+           break;
+       }
+       (*drawFunc) (pDraw, pGC, x, y, (int) count, chars);
+#else /* don't AVOID_GLYPHBLT */
+       /*
+        * On the other hand, if the device does use GlyphBlt ultimately to do text, we
+        * don't want to slow it down by invoking the text functions and having them call
+        * GetGlyphs all over again, so we go directly to the GlyphBlt functions here.
+        */
+       drawFunc = imageblt ? pGC->ops->ImageGlyphBlt : pGC->ops->PolyGlyphBlt;
+       (*drawFunc) (pDraw, pGC, x, y, n, charinfo, FONTGLYPHS(pGC->font));
+#endif /* AVOID_GLYPHBLT */
+    }
+    DEALLOCATE_LOCAL(charinfo);
+    return x + w;
+}
+
+static int
+rfbSpritePolyText8(pDrawable, pGC, x, y, count, chars)
+    DrawablePtr pDrawable;
+    GCPtr      pGC;
+    int                x, y;
+    int        count;
+    char       *chars;
+{
+    int        ret;
+
+    GC_SETUP (pDrawable, pGC);
+
+    GC_OP_PROLOGUE (pGC);
+
+    if (GC_CHECK((WindowPtr) pDrawable))
+       ret = rfbSpriteText (pDrawable, pGC, x, y, (unsigned long)count, chars,
+                           Linear8Bit, TT_POLY8, &pScreenPriv->saved);
+    else
+       ret = (*pGC->ops->PolyText8) (pDrawable, pGC, x, y, count, chars);
+
+    GC_OP_EPILOGUE (pGC);
+    return ret;
+}
+
+static int
+rfbSpritePolyText16(pDrawable, pGC, x, y, count, chars)
+    DrawablePtr pDrawable;
+    GCPtr      pGC;
+    int                x, y;
+    int                count;
+    unsigned short *chars;
+{
+    int        ret;
+
+    GC_SETUP(pDrawable, pGC);
+
+    GC_OP_PROLOGUE (pGC);
+
+    if (GC_CHECK((WindowPtr) pDrawable))
+       ret = rfbSpriteText (pDrawable, pGC, x, y, (unsigned long)count,
+                           (char *)chars,
+                           FONTLASTROW(pGC->font) == 0 ?
+                           Linear16Bit : TwoD16Bit, TT_POLY16, &pScreenPriv->saved);
+    else
+       ret = (*pGC->ops->PolyText16) (pDrawable, pGC, x, y, count, chars);
+
+    GC_OP_EPILOGUE (pGC);
+    return ret;
+}
+
+static void
+rfbSpriteImageText8(pDrawable, pGC, x, y, count, chars)
+    DrawablePtr pDrawable;
+    GCPtr      pGC;
+    int                x, y;
+    int                count;
+    char       *chars;
+{
+    GC_SETUP(pDrawable, pGC);
+
+    GC_OP_PROLOGUE (pGC);
+
+    if (GC_CHECK((WindowPtr) pDrawable))
+       (void) rfbSpriteText (pDrawable, pGC, x, y, (unsigned long)count,
+                            chars, Linear8Bit, TT_IMAGE8, &pScreenPriv->saved);
+    else
+       (*pGC->ops->ImageText8) (pDrawable, pGC, x, y, count, chars);
+
+    GC_OP_EPILOGUE (pGC);
+}
+
+static void
+rfbSpriteImageText16(pDrawable, pGC, x, y, count, chars)
+    DrawablePtr pDrawable;
+    GCPtr      pGC;
+    int                x, y;
+    int                count;
+    unsigned short *chars;
+{
+    GC_SETUP(pDrawable, pGC);
+
+    GC_OP_PROLOGUE (pGC);
+
+    if (GC_CHECK((WindowPtr) pDrawable))
+       (void) rfbSpriteText (pDrawable, pGC, x, y, (unsigned long)count,
+                            (char *)chars,
+                           FONTLASTROW(pGC->font) == 0 ?
+                           Linear16Bit : TwoD16Bit, TT_IMAGE16, &pScreenPriv->saved);
+    else
+       (*pGC->ops->ImageText16) (pDrawable, pGC, x, y, count, chars);
+
+    GC_OP_EPILOGUE (pGC);
+}
+
+static void
+rfbSpriteImageGlyphBlt(pDrawable, pGC, x, y, nglyph, ppci, pglyphBase)
+    DrawablePtr pDrawable;
+    GCPtr      pGC;
+    int        x, y;
+    unsigned int nglyph;
+    CharInfoPtr *ppci;         /* array of character info */
+    pointer    pglyphBase;     /* start of array of glyphs */
+{
+    GC_SETUP(pDrawable, pGC);
+
+    GC_OP_PROLOGUE (pGC);
+
+    if (GC_CHECK((WindowPtr) pDrawable) &&
+       rfbSpriteTextOverlap (pDrawable, pGC->font, x, y, nglyph, ppci, TRUE, 0, &pScreenPriv->saved))
+    {
+       rfbSpriteRemoveCursor(pDrawable->pScreen);
+    }
+    (*pGC->ops->ImageGlyphBlt) (pDrawable, pGC, x, y, nglyph, ppci, pglyphBase);
+
+    GC_OP_EPILOGUE (pGC);
+}
+
+static void
+rfbSpritePolyGlyphBlt(pDrawable, pGC, x, y, nglyph, ppci, pglyphBase)
+    DrawablePtr pDrawable;
+    GCPtr      pGC;
+    int        x, y;
+    unsigned int nglyph;
+    CharInfoPtr *ppci;         /* array of character info */
+    pointer    pglyphBase;     /* start of array of glyphs */
+{
+    GC_SETUP (pDrawable, pGC);
+
+    GC_OP_PROLOGUE (pGC);
+
+    if (GC_CHECK((WindowPtr) pDrawable) &&
+       rfbSpriteTextOverlap (pDrawable, pGC->font, x, y, nglyph, ppci, FALSE, 0, &pScreenPriv->saved))
+    {
+       rfbSpriteRemoveCursor(pDrawable->pScreen);
+    }
+    (*pGC->ops->PolyGlyphBlt) (pDrawable, pGC, x, y, nglyph, ppci, pglyphBase);
+
+    GC_OP_EPILOGUE (pGC);
+}
+
+static void
+rfbSpritePushPixels(pGC, pBitMap, pDrawable, w, h, x, y)
+    GCPtr      pGC;
+    PixmapPtr  pBitMap;
+    DrawablePtr pDrawable;
+    int                w, h, x, y;
+{
+    GC_SETUP(pDrawable, pGC);
+
+    if (GC_CHECK((WindowPtr) pDrawable) &&
+       ORG_OVERLAP(&pScreenPriv->saved,pDrawable->x,pDrawable->y,x,y,w,h))
+    {
+       rfbSpriteRemoveCursor (pDrawable->pScreen);
+    }
+
+    GC_OP_PROLOGUE (pGC);
+
+    (*pGC->ops->PushPixels) (pGC, pBitMap, pDrawable, w, h, x, y);
+
+    GC_OP_EPILOGUE (pGC);
+}
+
+#ifdef NEED_LINEHELPER
+/*
+ * I don't expect this routine will ever be called, as the GC
+ * will have been unwrapped for the line drawing
+ */
+
+static void
+rfbSpriteLineHelper()
+{
+    FatalError("rfbSpriteLineHelper called\n");
+}
+#endif
+
+/*
+ * miPointer interface routines
+ */
+
+static Bool
+rfbSpriteRealizeCursor (pScreen, pCursor)
+    ScreenPtr  pScreen;
+    CursorPtr  pCursor;
+{
+    rfbSpriteScreenPtr pScreenPriv;
+
+    pScreenPriv = (rfbSpriteScreenPtr) pScreen->devPrivates[rfbSpriteScreenIndex].ptr;
+    if (pCursor == pScreenPriv->pCursor)
+       pScreenPriv->checkPixels = TRUE;
+    return (*pScreenPriv->funcs->RealizeCursor) (pScreen, pCursor);
+}
+
+static Bool
+rfbSpriteUnrealizeCursor (pScreen, pCursor)
+    ScreenPtr  pScreen;
+    CursorPtr  pCursor;
+{
+    rfbSpriteScreenPtr pScreenPriv;
+
+    pScreenPriv = (rfbSpriteScreenPtr) pScreen->devPrivates[rfbSpriteScreenIndex].ptr;
+    return (*pScreenPriv->funcs->UnrealizeCursor) (pScreen, pCursor);
+}
+
+static void
+rfbSpriteSetCursor (pScreen, pCursor, x, y)
+    ScreenPtr  pScreen;
+    CursorPtr  pCursor;
+{
+    rfbSpriteScreenPtr pScreenPriv;
+    rfbClientPtr cl, nextCl;
+
+    pScreenPriv
+       = (rfbSpriteScreenPtr) pScreen->devPrivates[rfbSpriteScreenIndex].ptr;
+
+    if (pScreenPriv->x == x &&
+       pScreenPriv->y == y &&
+       pScreenPriv->pCursor == pCursor &&
+       !pScreenPriv->checkPixels)
+    {
+       return;
+    }
+
+    if (rfbScreen.cursorIsDrawn)
+       rfbSpriteRemoveCursor (pScreen);
+
+    pScreenPriv->x = x;
+    pScreenPriv->y = y;
+    pScreenPriv->pCursor = pCursor;
+
+    for (cl = rfbClientHead; cl; cl = nextCl) {
+       nextCl = cl->next;
+       if (REGION_NOTEMPTY(pScreen,&cl->requestedRegion)) {
+           /* cursorIsDrawn is guaranteed to be FALSE here, so we definitely
+              want to send a screen update to the client, even if that's only
+              putting up the cursor */
+           rfbSendFramebufferUpdate(cl);
+       }
+    }
+}
+
+static void
+rfbSpriteMoveCursor (pScreen, x, y)
+    ScreenPtr  pScreen;
+    int                x, y;
+{
+    rfbSpriteScreenPtr pScreenPriv;
+
+    pScreenPriv = (rfbSpriteScreenPtr) pScreen->devPrivates[rfbSpriteScreenIndex].ptr;
+    rfbSpriteSetCursor (pScreen, pScreenPriv->pCursor, x, y);
+}
+
+/*
+ * undraw/draw cursor
+ */
+
+static void
+rfbSpriteRemoveCursor (pScreen)
+    ScreenPtr  pScreen;
+{
+    rfbSpriteScreenPtr   pScreenPriv;
+
+    pScreenPriv
+       = (rfbSpriteScreenPtr) pScreen->devPrivates[rfbSpriteScreenIndex].ptr;
+
+    rfbScreen.dontSendFramebufferUpdate = TRUE;
+    rfbScreen.cursorIsDrawn = FALSE;
+    pScreenPriv->pCacheWin = NullWindow;
+    if (!(*pScreenPriv->funcs->RestoreUnderCursor) (pScreen,
+                                        pScreenPriv->saved.x1,
+                                        pScreenPriv->saved.y1,
+                                        pScreenPriv->saved.x2 - pScreenPriv->saved.x1,
+                                        pScreenPriv->saved.y2 - pScreenPriv->saved.y1))
+    {
+       rfbScreen.cursorIsDrawn = TRUE;
+    }
+    rfbScreen.dontSendFramebufferUpdate = FALSE;
+}
+
+
+void
+rfbSpriteRestoreCursor (pScreen)
+    ScreenPtr  pScreen;
+{
+    rfbSpriteScreenPtr   pScreenPriv;
+    int                        x, y;
+    CursorPtr          pCursor;
+
+    pScreenPriv
+       = (rfbSpriteScreenPtr) pScreen->devPrivates[rfbSpriteScreenIndex].ptr;
+    pCursor = pScreenPriv->pCursor;
+
+    if (rfbScreen.cursorIsDrawn || !pCursor)
+       return;
+
+    rfbScreen.dontSendFramebufferUpdate = TRUE;
+
+    rfbSpriteComputeSaved (pScreen);
+
+    x = pScreenPriv->x - (int)pCursor->bits->xhot;
+    y = pScreenPriv->y - (int)pCursor->bits->yhot;
+    if ((*pScreenPriv->funcs->SaveUnderCursor) (pScreen,
+                                     pScreenPriv->saved.x1,
+                                     pScreenPriv->saved.y1,
+                                     pScreenPriv->saved.x2 - pScreenPriv->saved.x1,
+                                     pScreenPriv->saved.y2 - pScreenPriv->saved.y1))
+    {
+       if (pScreenPriv->checkPixels)
+           rfbSpriteFindColors (pScreen);
+       if ((*pScreenPriv->funcs->PutUpCursor) (pScreen, pCursor, x, y,
+                                 pScreenPriv->colors[SOURCE_COLOR].pixel,
+                                 pScreenPriv->colors[MASK_COLOR].pixel))
+           rfbScreen.cursorIsDrawn = TRUE;
+    }
+
+    rfbScreen.dontSendFramebufferUpdate = FALSE;
+}
+
+/*
+ * compute the desired area of the screen to save
+ */
+
+static void
+rfbSpriteComputeSaved (pScreen)
+    ScreenPtr  pScreen;
+{
+    rfbSpriteScreenPtr   pScreenPriv;
+    int                    x, y, w, h;
+    CursorPtr      pCursor;
+
+    pScreenPriv = (rfbSpriteScreenPtr) pScreen->devPrivates[rfbSpriteScreenIndex].ptr;
+    pCursor = pScreenPriv->pCursor;
+    x = pScreenPriv->x - (int)pCursor->bits->xhot;
+    y = pScreenPriv->y - (int)pCursor->bits->yhot;
+    w = pCursor->bits->width;
+    h = pCursor->bits->height;
+    pScreenPriv->saved.x1 = x;
+    pScreenPriv->saved.y1 = y;
+    pScreenPriv->saved.x2 = pScreenPriv->saved.x1 + w;
+    pScreenPriv->saved.y2 = pScreenPriv->saved.y1 + h;
+}
diff --git a/Xserver/programs/Xserver/hw/vnc/sprite.h b/Xserver/programs/Xserver/hw/vnc/sprite.h
new file mode 100644 (file)
index 0000000..39690a5
--- /dev/null
@@ -0,0 +1,108 @@
+/*
+ * sprite.h
+ *
+ * software-sprite/sprite drawing - based on misprite
+ */
+
+/*
+ *  Copyright (C) 1999 AT&T Laboratories Cambridge.  All Rights Reserved.
+ *
+ *  This is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This software is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this software; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,
+ *  USA.
+ */
+
+/*
+
+Copyright (c) 1989  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+*/
+
+typedef struct {
+    Bool       (*RealizeCursor)(
+#if NeedNestedPrototypes
+               ScreenPtr /*pScreen*/,
+               CursorPtr /*pCursor*/
+#endif
+);
+    Bool       (*UnrealizeCursor)(
+#if NeedNestedPrototypes
+               ScreenPtr /*pScreen*/,
+               CursorPtr /*pCursor*/
+#endif
+);
+    Bool       (*PutUpCursor)(
+#if NeedNestedPrototypes
+               ScreenPtr /*pScreen*/,
+               CursorPtr /*pCursor*/,
+               int /*x*/,
+               int /*y*/,
+               unsigned long /*source*/,
+               unsigned long /*mask*/
+#endif
+);
+    Bool       (*SaveUnderCursor)(
+#if NeedNestedPrototypes
+               ScreenPtr /*pScreen*/,
+               int /*x*/,
+               int /*y*/,
+               int /*w*/,
+               int /*h*/
+#endif
+);
+    Bool       (*RestoreUnderCursor)(
+#if NeedNestedPrototypes
+               ScreenPtr /*pScreen*/,
+               int /*x*/,
+               int /*y*/,
+               int /*w*/,
+               int /*h*/
+#endif
+);
+
+} rfbSpriteCursorFuncRec, *rfbSpriteCursorFuncPtr;
+
+extern Bool rfbSpriteInitialize(
+#if NeedFunctionPrototypes
+    ScreenPtr /*pScreen*/,
+    rfbSpriteCursorFuncPtr /*cursorFuncs*/,
+    miPointerScreenFuncPtr /*screenFuncs*/
+#endif
+);
+
+extern void rfbSpriteRestoreCursor(
+#if NeedFunctionPrototypes
+    ScreenPtr  /*pScreen*/
+#endif
+);
diff --git a/Xserver/programs/Xserver/hw/vnc/spritest.h b/Xserver/programs/Xserver/hw/vnc/spritest.h
new file mode 100644 (file)
index 0000000..dc072a8
--- /dev/null
@@ -0,0 +1,125 @@
+/*
+ * spritest.h
+ *
+ * sprite structures - based on misprite
+ */
+
+/*
+ *  Copyright (C) 1999 AT&T Laboratories Cambridge.  All Rights Reserved.
+ *
+ *  This is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This software is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this software; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,
+ *  USA.
+ */
+
+/*
+
+Copyright (c) 1989  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+*/
+
+# include   "sprite.h"
+
+/*
+ * per screen information
+ */
+
+typedef struct {
+    CloseScreenProcPtr                 CloseScreen;
+    GetImageProcPtr                    GetImage;
+    GetSpansProcPtr                    GetSpans;
+    SourceValidateProcPtr              SourceValidate;
+    CreateGCProcPtr                    CreateGC;
+    InstallColormapProcPtr             InstallColormap;
+    StoreColorsProcPtr                 StoreColors;
+    PaintWindowBackgroundProcPtr       PaintWindowBackground;
+    PaintWindowBorderProcPtr           PaintWindowBorder;
+    CopyWindowProcPtr                  CopyWindow;
+    ClearToBackgroundProcPtr           ClearToBackground;
+    SaveDoomedAreasProcPtr             SaveDoomedAreas;
+    RestoreAreasProcPtr                        RestoreAreas;
+
+    CursorPtr      pCursor;
+    int                    x;
+    int                    y;
+    BoxRec         saved;
+    WindowPtr      pCacheWin;
+    Bool           isInCacheWin;
+    Bool           checkPixels;
+    xColorItem     colors[2];
+    ColormapPtr            pInstalledMap;
+    ColormapPtr            pColormap;
+    VisualPtr      pVisual;
+    rfbSpriteCursorFuncPtr    funcs;
+} rfbSpriteScreenRec, *rfbSpriteScreenPtr;
+
+#define SOURCE_COLOR   0
+#define MASK_COLOR     1
+
+typedef struct {
+    GCFuncs            *wrapFuncs;
+    GCOps              *wrapOps;
+} rfbSpriteGCRec, *rfbSpriteGCPtr;
+
+/*
+ * Overlap BoxPtr and Box elements
+ */
+#define BOX_OVERLAP(pCbox,X1,Y1,X2,Y2) \
+       (((pCbox)->x1 <= (X2)) && ((X1) <= (pCbox)->x2) && \
+        ((pCbox)->y1 <= (Y2)) && ((Y1) <= (pCbox)->y2))
+
+/*
+ * Overlap BoxPtr, origins, and rectangle
+ */
+#define ORG_OVERLAP(pCbox,xorg,yorg,x,y,w,h) \
+    BOX_OVERLAP((pCbox),(x)+(xorg),(y)+(yorg),(x)+(xorg)+(w),(y)+(yorg)+(h))
+
+/*
+ * Overlap BoxPtr, origins and RectPtr
+ */
+#define ORGRECT_OVERLAP(pCbox,xorg,yorg,pRect) \
+    ORG_OVERLAP((pCbox),(xorg),(yorg),(pRect)->x,(pRect)->y, \
+               (int)((pRect)->width), (int)((pRect)->height))
+/*
+ * Overlap BoxPtr and horizontal span
+ */
+#define SPN_OVERLAP(pCbox,y,x,w) BOX_OVERLAP((pCbox),(x),(y),(x)+(w),(y))
+
+#define LINE_SORT(x1,y1,x2,y2) \
+{ int _t; \
+  if (x1 > x2) { _t = x1; x1 = x2; x2 = _t; } \
+  if (y1 > y2) { _t = y1; y1 = y2; y2 = _t; } }
+
+#define LINE_OVERLAP(pCbox,x1,y1,x2,y2,lw2) \
+    BOX_OVERLAP((pCbox), (x1)-(lw2), (y1)-(lw2), (x2)+(lw2), (y2)+(lw2))
diff --git a/Xserver/programs/Xserver/hw/vnc/stats.c b/Xserver/programs/Xserver/hw/vnc/stats.c
new file mode 100644 (file)
index 0000000..e5baf66
--- /dev/null
@@ -0,0 +1,87 @@
+/*
+ * stats.c
+ */
+
+/*
+ *  Copyright (C) 2002 RealVNC Ltd.
+ *  Copyright (C) 1999 AT&T Laboratories Cambridge.  All Rights Reserved.
+ *
+ *  This is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This software is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this software; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,
+ *  USA.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include "rfb.h"
+
+static char* encNames[] = {
+    "raw", "copyRect", "RRE", "[encoding 3]", "CoRRE", "hextile",
+    "[encoding 6]", "[encoding 7]", "[encoding 8]", "[encoding 9]",
+    "[encoding 10]", "[encoding 11]", "[encoding 12]", "[encoding 13]",
+    "[encoding 14]", "[encoding 15]", "ZRLE", "[encoding 17]",
+    "[encoding 18]", "[encoding 19]", "[encoding 20]"
+};
+
+
+void
+rfbResetStats(rfbClientPtr cl)
+{
+    int i;
+    for (i = 0; i < MAX_ENCODINGS; i++) {
+       cl->rfbBytesSent[i] = 0;
+       cl->rfbRectanglesSent[i] = 0;
+    }
+    cl->rfbFramebufferUpdateMessagesSent = 0;
+    cl->rfbRawBytesEquivalent = 0;
+    cl->rfbKeyEventsRcvd = 0;
+    cl->rfbPointerEventsRcvd = 0;
+}
+
+void
+rfbPrintStats(rfbClientPtr cl)
+{
+    int i;
+    int totalRectanglesSent = 0;
+    int totalBytesSent = 0;
+
+    rfbLog("Statistics:\n");
+
+    if ((cl->rfbKeyEventsRcvd != 0) || (cl->rfbPointerEventsRcvd != 0))
+       rfbLog("  key events received %d, pointer events %d\n",
+               cl->rfbKeyEventsRcvd, cl->rfbPointerEventsRcvd);
+
+    for (i = 0; i < MAX_ENCODINGS; i++) {
+       totalRectanglesSent += cl->rfbRectanglesSent[i];
+       totalBytesSent += cl->rfbBytesSent[i];
+    }
+
+    rfbLog("  framebuffer updates %d, rectangles %d, bytes %d\n",
+           cl->rfbFramebufferUpdateMessagesSent, totalRectanglesSent,
+           totalBytesSent);
+
+    for (i = 0; i < MAX_ENCODINGS; i++) {
+       if (cl->rfbRectanglesSent[i] != 0)
+           rfbLog("    %s rectangles %d, bytes %d\n",
+                  encNames[i], cl->rfbRectanglesSent[i], cl->rfbBytesSent[i]);
+    }
+
+    if ((totalBytesSent - cl->rfbBytesSent[rfbEncodingCopyRect]) != 0) {
+       rfbLog("  raw bytes equivalent %d, compression ratio %f\n",
+               cl->rfbRawBytesEquivalent,
+               (double)cl->rfbRawBytesEquivalent
+               / (double)(totalBytesSent
+                          - cl->rfbBytesSent[rfbEncodingCopyRect]));
+    }
+}
diff --git a/Xserver/programs/Xserver/hw/vnc/tableinitcmtemplate.c b/Xserver/programs/Xserver/hw/vnc/tableinitcmtemplate.c
new file mode 100644 (file)
index 0000000..a148f2c
--- /dev/null
@@ -0,0 +1,82 @@
+/*
+ * tableinitcmtemplate.c - template for initialising lookup tables for
+ * translation from a colour map to true colour.
+ *
+ * This file shouldn't be compiled.  It is included multiple times by
+ * translate.c, each time with a different definition of the macro OUT.
+ * For each value of OUT, this file defines a function which allocates an
+ * appropriately sized lookup table and initialises it.
+ *
+ * I know this code isn't nice to read because of all the macros, but
+ * efficiency is important here.
+ */
+
+/*
+ *  Copyright (C) 1999 AT&T Laboratories Cambridge.  All Rights Reserved.
+ *
+ *  This is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This software is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this software; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,
+ *  USA.
+ */
+
+#if !defined(OUT)
+#error "This file shouldn't be compiled."
+#error "It is included as part of translate.c"
+#endif
+
+#define OUT_T CONCAT2E(CARD,OUT)
+#define SwapOUT(x) CONCAT2E(Swap,OUT(x))
+#define rfbInitColourMapSingleTableOUT \
+                               CONCAT2E(rfbInitColourMapSingleTable,OUT)
+
+static void
+rfbInitColourMapSingleTableOUT (char **table, rfbPixelFormat *in,
+                               rfbPixelFormat *out)
+{
+    int i, r, g, b;
+    OUT_T *t;
+    EntryPtr pent;
+    int nEntries = 1 << in->bitsPerPixel;
+
+    if (*table) free(*table);
+    *table = (char *)malloc(nEntries * sizeof(OUT_T));
+    t = (OUT_T *)*table;
+
+    pent = (EntryPtr)&rfbInstalledColormap->red[0];
+
+    for (i = 0; i < nEntries; i++) {
+       if (pent->fShared) {
+           r = pent->co.shco.red->color;
+           g = pent->co.shco.green->color;
+           b = pent->co.shco.blue->color;
+       } else {
+           r = pent->co.local.red;
+           g = pent->co.local.green;
+           b = pent->co.local.blue;
+       }
+       t[i] = ((((r * out->redMax + 32767) / 65535) << out->redShift) |
+               (((g * out->greenMax + 32767) / 65535) << out->greenShift) |
+               (((b * out->blueMax + 32767) / 65535) << out->blueShift));
+#if (OUT != 8)
+       if (out->bigEndian != in->bigEndian) {
+           t[i] = SwapOUT(t[i]);
+       }
+#endif
+       pent++;
+    }
+}
+
+#undef OUT_T
+#undef SwapOUT
+#undef rfbInitColourMapSingleTableOUT
diff --git a/Xserver/programs/Xserver/hw/vnc/tableinittctemplate.c b/Xserver/programs/Xserver/hw/vnc/tableinittctemplate.c
new file mode 100644 (file)
index 0000000..18ff0ef
--- /dev/null
@@ -0,0 +1,140 @@
+/*
+ * tableinittctemplate.c - template for initialising lookup tables for
+ * truecolour to truecolour translation.
+ *
+ * This file shouldn't be compiled.  It is included multiple times by
+ * translate.c, each time with a different definition of the macro OUT.
+ * For each value of OUT, this file defines two functions for initialising
+ * lookup tables.  One is for truecolour translation using a single lookup
+ * table, the other is for truecolour translation using three separate
+ * lookup tables for the red, green and blue values.
+ *
+ * I know this code isn't nice to read because of all the macros, but
+ * efficiency is important here.
+ */
+
+/*
+ *  Copyright (C) 1999 AT&T Laboratories Cambridge.  All Rights Reserved.
+ *
+ *  This is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This software is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this software; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,
+ *  USA.
+ */
+
+#if !defined(OUT)
+#error "This file shouldn't be compiled."
+#error "It is included as part of translate.c"
+#endif
+
+#define OUT_T CONCAT2E(CARD,OUT)
+#define SwapOUT(x) CONCAT2E(Swap,OUT(x))
+#define rfbInitTrueColourSingleTableOUT \
+                               CONCAT2E(rfbInitTrueColourSingleTable,OUT)
+#define rfbInitTrueColourRGBTablesOUT CONCAT2E(rfbInitTrueColourRGBTables,OUT)
+#define rfbInitOneRGBTableOUT CONCAT2E(rfbInitOneRGBTable,OUT)
+
+static void
+rfbInitOneRGBTableOUT (OUT_T *table, int inMax, int outMax, int outShift,
+                      int swap);
+
+
+/*
+ * rfbInitTrueColourSingleTable sets up a single lookup table for truecolour
+ * translation.
+ */
+
+static void
+rfbInitTrueColourSingleTableOUT (char **table, rfbPixelFormat *in,
+                                rfbPixelFormat *out)
+{
+    int i;
+    int inRed, inGreen, inBlue, outRed, outGreen, outBlue;
+    OUT_T *t;
+    int nEntries = 1 << in->bitsPerPixel;
+
+    if (*table) free(*table);
+    *table = (char *)malloc(nEntries * sizeof(OUT_T));
+    t = (OUT_T *)*table;
+
+    for (i = 0; i < nEntries; i++) {
+       inRed   = (i >> in->redShift)   & in->redMax;
+       inGreen = (i >> in->greenShift) & in->greenMax;
+       inBlue  = (i >> in->blueShift)  & in->blueMax;
+
+       outRed   = (inRed   * out->redMax   + in->redMax / 2)   / in->redMax;
+       outGreen = (inGreen * out->greenMax + in->greenMax / 2) / in->greenMax;
+       outBlue  = (inBlue  * out->blueMax  + in->blueMax / 2)  / in->blueMax;
+
+       t[i] = ((outRed   << out->redShift)   |
+               (outGreen << out->greenShift) |
+               (outBlue  << out->blueShift));
+#if (OUT != 8)
+       if (out->bigEndian != in->bigEndian) {
+           t[i] = SwapOUT(t[i]);
+       }
+#endif
+    }
+}
+
+
+/*
+ * rfbInitTrueColourRGBTables sets up three separate lookup tables for the
+ * red, green and blue values.
+ */
+
+static void
+rfbInitTrueColourRGBTablesOUT (char **table, rfbPixelFormat *in,
+                              rfbPixelFormat *out)
+{
+    OUT_T *redTable;
+    OUT_T *greenTable;
+    OUT_T *blueTable;
+
+    if (*table) free(*table);
+    *table = (char *)malloc((in->redMax + in->greenMax + in->blueMax + 3)
+                           * sizeof(OUT_T));
+    redTable = (OUT_T *)*table;
+    greenTable = redTable + in->redMax + 1;
+    blueTable = greenTable + in->greenMax + 1;
+
+    rfbInitOneRGBTableOUT (redTable, in->redMax, out->redMax,
+                          out->redShift, (out->bigEndian != in->bigEndian));
+    rfbInitOneRGBTableOUT (greenTable, in->greenMax, out->greenMax,
+                          out->greenShift, (out->bigEndian != in->bigEndian));
+    rfbInitOneRGBTableOUT (blueTable, in->blueMax, out->blueMax,
+                          out->blueShift, (out->bigEndian != in->bigEndian));
+}
+
+static void
+rfbInitOneRGBTableOUT (OUT_T *table, int inMax, int outMax, int outShift,
+                      int swap)
+{
+    int i;
+    int nEntries = inMax + 1;
+
+    for (i = 0; i < nEntries; i++) {
+       table[i] = ((i * outMax + inMax / 2) / inMax) << outShift;
+#if (OUT != 8)
+       if (swap) {
+           table[i] = SwapOUT(table[i]);
+       }
+#endif
+    }
+}
+
+#undef OUT_T
+#undef SwapOUT
+#undef rfbInitTrueColourSingleTableOUT
+#undef rfbInitTrueColourRGBTablesOUT
+#undef rfbInitOneRGBTableOUT
diff --git a/Xserver/programs/Xserver/hw/vnc/tabletranstemplate.c b/Xserver/programs/Xserver/hw/vnc/tabletranstemplate.c
new file mode 100644 (file)
index 0000000..2481ee5
--- /dev/null
@@ -0,0 +1,115 @@
+/*
+ * tabletranstemplate.c - template for translation using lookup tables.
+ *
+ * This file shouldn't be compiled.  It is included multiple times by
+ * translate.c, each time with different definitions of the macros IN and OUT.
+ *
+ * For each pair of values IN and OUT, this file defines two functions for
+ * translating a given rectangle of pixel data.  One uses a single lookup
+ * table, and the other uses three separate lookup tables for the red, green
+ * and blue values.
+ *
+ * I know this code isn't nice to read because of all the macros, but
+ * efficiency is important here.
+ */
+
+/*
+ *  Copyright (C) 1999 AT&T Laboratories Cambridge.  All Rights Reserved.
+ *
+ *  This is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This software is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this software; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,
+ *  USA.
+ */
+
+#if !defined(IN) || !defined(OUT)
+#error "This file shouldn't be compiled."
+#error "It is included as part of translate.c"
+#endif
+
+#define IN_T CONCAT2E(CARD,IN)
+#define OUT_T CONCAT2E(CARD,OUT)
+#define rfbTranslateWithSingleTableINtoOUT \
+                               CONCAT4E(rfbTranslateWithSingleTable,IN,to,OUT)
+#define rfbTranslateWithRGBTablesINtoOUT \
+                               CONCAT4E(rfbTranslateWithRGBTables,IN,to,OUT)
+
+/*
+ * rfbTranslateWithSingleTableINtoOUT translates a rectangle of pixel data
+ * using a single lookup table.
+ */
+
+static void
+rfbTranslateWithSingleTableINtoOUT (char *table, rfbPixelFormat *in,
+                                   rfbPixelFormat *out,
+                                   char *iptr, char *optr,
+                                   int bytesBetweenInputLines,
+                                   int width, int height)
+{
+    IN_T *ip = (IN_T *)iptr;
+    OUT_T *op = (OUT_T *)optr;
+    int ipextra = bytesBetweenInputLines / sizeof(IN_T) - width;
+    OUT_T *opLineEnd;
+    OUT_T *t = (OUT_T *)table;
+
+    while (height > 0) {
+       opLineEnd = op + width;
+
+       while (op < opLineEnd) {
+           *(op++) = t[*(ip++)];
+       }
+
+       ip += ipextra;
+       height--;
+    }
+}
+
+
+/*
+ * rfbTranslateWithRGBTablesINtoOUT translates a rectangle of pixel data
+ * using three separate lookup tables for the red, green and blue values.
+ */
+
+static void
+rfbTranslateWithRGBTablesINtoOUT (char *table, rfbPixelFormat *in,
+                                 rfbPixelFormat *out,
+                                 char *iptr, char *optr,
+                                 int bytesBetweenInputLines,
+                                 int width, int height)
+{
+    IN_T *ip = (IN_T *)iptr;
+    OUT_T *op = (OUT_T *)optr;
+    int ipextra = bytesBetweenInputLines / sizeof(IN_T) - width;
+    OUT_T *opLineEnd;
+    OUT_T *redTable = (OUT_T *)table;
+    OUT_T *greenTable = redTable + in->redMax + 1;
+    OUT_T *blueTable = greenTable + in->greenMax + 1;
+
+    while (height > 0) {
+       opLineEnd = op + width;
+
+       while (op < opLineEnd) {
+           *(op++) = (redTable[(*ip >> in->redShift) & in->redMax] |
+                      greenTable[(*ip >> in->greenShift) & in->greenMax] |
+                      blueTable[(*ip >> in->blueShift) & in->blueMax]);
+           ip++;
+       }
+       ip += ipextra;
+       height--;
+    }
+}
+
+#undef IN_T
+#undef OUT_T
+#undef rfbTranslateWithSingleTableINtoOUT
+#undef rfbTranslateWithRGBTablesINtoOUT
diff --git a/Xserver/programs/Xserver/hw/vnc/translate.c b/Xserver/programs/Xserver/hw/vnc/translate.c
new file mode 100644 (file)
index 0000000..acbc8b1
--- /dev/null
@@ -0,0 +1,449 @@
+/*
+ * translate.c - translate between different pixel formats
+ */
+
+/*
+ *  Copyright (C) 2002 RealVNC Ltd.
+ *  Copyright (C) 1999 AT&T Laboratories Cambridge.  All Rights Reserved.
+ *
+ *  This is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This software is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this software; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,
+ *  USA.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include "rfb.h"
+
+static void PrintPixelFormat(rfbPixelFormat *pf);
+static Bool rfbSetClientColourMapBGR233();
+
+Bool rfbEconomicTranslate = FALSE;
+
+/*
+ * Structure representing pixel format for RFB server (i.e. us).
+ */
+
+rfbPixelFormat rfbServerFormat;
+
+
+/*
+ * Some standard pixel formats.
+ */
+
+static const rfbPixelFormat BGR233Format = {
+    8, 8, 0, 1, 7, 7, 3, 0, 3, 6
+};
+
+
+/*
+ * Macro to compare pixel formats.
+ */
+
+#define PF_EQ(x,y)                                                     \
+       ((x.bitsPerPixel == y.bitsPerPixel) &&                          \
+        (x.depth == y.depth) &&                                        \
+        ((x.bigEndian == y.bigEndian) || (x.bitsPerPixel == 8)) &&     \
+        (x.trueColour == y.trueColour) &&                              \
+        (!x.trueColour || ((x.redMax == y.redMax) &&                   \
+                           (x.greenMax == y.greenMax) &&               \
+                           (x.blueMax == y.blueMax) &&                 \
+                           (x.redShift == y.redShift) &&               \
+                           (x.greenShift == y.greenShift) &&           \
+                           (x.blueShift == y.blueShift))))
+
+#define CONCAT2(a,b) a##b
+#define CONCAT2E(a,b) CONCAT2(a,b)
+#define CONCAT4(a,b,c,d) a##b##c##d
+#define CONCAT4E(a,b,c,d) CONCAT4(a,b,c,d)
+
+#define OUT 8
+#include "tableinittctemplate.c"
+#include "tableinitcmtemplate.c"
+#define IN 8
+#include "tabletranstemplate.c"
+#undef IN
+#define IN 16
+#include "tabletranstemplate.c"
+#undef IN
+#define IN 32
+#include "tabletranstemplate.c"
+#undef IN
+#undef OUT
+
+#define OUT 16
+#include "tableinittctemplate.c"
+#include "tableinitcmtemplate.c"
+#define IN 8
+#include "tabletranstemplate.c"
+#undef IN
+#define IN 16
+#include "tabletranstemplate.c"
+#undef IN
+#define IN 32
+#include "tabletranstemplate.c"
+#undef IN
+#undef OUT
+
+#define OUT 32
+#include "tableinittctemplate.c"
+#include "tableinitcmtemplate.c"
+#define IN 8
+#include "tabletranstemplate.c"
+#undef IN
+#define IN 16
+#include "tabletranstemplate.c"
+#undef IN
+#define IN 32
+#include "tabletranstemplate.c"
+#undef IN
+#undef OUT
+
+typedef void (*rfbInitTableFnType)(char **table, rfbPixelFormat *in,
+                                  rfbPixelFormat *out);
+
+rfbInitTableFnType rfbInitTrueColourSingleTableFns[3] = {
+    rfbInitTrueColourSingleTable8,
+    rfbInitTrueColourSingleTable16,
+    rfbInitTrueColourSingleTable32
+};
+
+rfbInitTableFnType rfbInitColourMapSingleTableFns[3] = {
+    rfbInitColourMapSingleTable8,
+    rfbInitColourMapSingleTable16,
+    rfbInitColourMapSingleTable32
+};
+
+rfbInitTableFnType rfbInitTrueColourRGBTablesFns[3] = {
+    rfbInitTrueColourRGBTables8,
+    rfbInitTrueColourRGBTables16,
+    rfbInitTrueColourRGBTables32
+};
+
+rfbTranslateFnType rfbTranslateWithSingleTableFns[3][3] = {
+    { rfbTranslateWithSingleTable8to8,
+      rfbTranslateWithSingleTable8to16,
+      rfbTranslateWithSingleTable8to32 },
+    { rfbTranslateWithSingleTable16to8,
+      rfbTranslateWithSingleTable16to16,
+      rfbTranslateWithSingleTable16to32 },
+    { rfbTranslateWithSingleTable32to8,
+      rfbTranslateWithSingleTable32to16,
+      rfbTranslateWithSingleTable32to32 }
+};
+
+rfbTranslateFnType rfbTranslateWithRGBTablesFns[3][3] = {
+    { rfbTranslateWithRGBTables8to8,
+      rfbTranslateWithRGBTables8to16,
+      rfbTranslateWithRGBTables8to32 },
+    { rfbTranslateWithRGBTables16to8,
+      rfbTranslateWithRGBTables16to16,
+      rfbTranslateWithRGBTables16to32 },
+    { rfbTranslateWithRGBTables32to8,
+      rfbTranslateWithRGBTables32to16,
+      rfbTranslateWithRGBTables32to32 }
+};
+
+
+
+/*
+ * rfbTranslateNone is used when no translation is required.
+ */
+
+void
+rfbTranslateNone(char *table, rfbPixelFormat *in, rfbPixelFormat *out,
+                char *iptr, char *optr, int bytesBetweenInputLines,
+                int width, int height)
+{
+    int bytesPerOutputLine = width * (out->bitsPerPixel / 8);
+
+    while (height > 0) {
+       memcpy(optr, iptr, bytesPerOutputLine);
+       iptr += bytesBetweenInputLines;
+       optr += bytesPerOutputLine;
+       height--;
+    }
+}
+
+
+/*
+ * rfbSetTranslateFunction sets the translation function.
+ */
+
+Bool
+rfbSetTranslateFunction(cl)
+    rfbClientPtr cl;
+{
+    rfbLog("Pixel format for client %s:\n",cl->host);
+    PrintPixelFormat(&cl->format);
+
+    /*
+     * Check that bits per pixel values are valid
+     */
+
+    if ((rfbServerFormat.bitsPerPixel != 8) &&
+       (rfbServerFormat.bitsPerPixel != 16) &&
+       (rfbServerFormat.bitsPerPixel != 32))
+    {
+       rfbLog("%s: server bits per pixel not 8, 16 or 32\n",
+               "rfbSetTranslateFunction");
+       rfbCloseSock(cl->sock);
+       return FALSE;
+    }
+
+    if ((cl->format.bitsPerPixel != 8) &&
+       (cl->format.bitsPerPixel != 16) &&
+       (cl->format.bitsPerPixel != 32))
+    {
+       rfbLog("%s: client bits per pixel not 8, 16 or 32\n",
+               "rfbSetTranslateFunction");
+       rfbCloseSock(cl->sock);
+       return FALSE;
+    }
+
+    if (!rfbServerFormat.trueColour && (rfbServerFormat.bitsPerPixel != 8)) {
+       rfbLog("rfbSetTranslateFunction: server has colour map "
+               "but %d-bit - can only cope with 8-bit colour maps\n",
+               rfbServerFormat.bitsPerPixel);
+       rfbCloseSock(cl->sock);
+       return FALSE;
+    }
+
+    if (!cl->format.trueColour && (cl->format.bitsPerPixel != 8)) {
+       rfbLog("rfbSetTranslateFunction: client has colour map "
+               "but %d-bit - can only cope with 8-bit colour maps\n",
+               cl->format.bitsPerPixel);
+       rfbCloseSock(cl->sock);
+       return FALSE;
+    }
+
+    /*
+     * bpp is valid, now work out how to translate
+     */
+
+    if (!cl->format.trueColour) {
+
+       /* ? -> colour map */
+
+       if (!rfbServerFormat.trueColour) {
+
+           /* colour map -> colour map */
+
+           rfbLog("rfbSetTranslateFunction: both 8-bit colour map: "
+                   "no translation needed\n");
+           cl->translateFn = rfbTranslateNone;
+           return rfbSetClientColourMap(cl, 0, 0);
+       }
+
+       /*
+        * truecolour -> colour map
+        *
+        * Set client's colour map to BGR233, then effectively it's
+        * truecolour as well
+        */
+
+       if (!rfbSetClientColourMapBGR233(cl))
+           return FALSE;
+
+       cl->format = BGR233Format;
+    }
+
+    /* ? -> truecolour */
+
+    if (!rfbServerFormat.trueColour) {
+
+       /* colour map -> truecolour */
+
+       rfbLog("rfbSetTranslateFunction: client is %d-bit trueColour,"
+               " server has colour map\n",cl->format.bitsPerPixel);
+
+       cl->translateFn = rfbTranslateWithSingleTableFns
+                             [rfbServerFormat.bitsPerPixel / 16]
+                                 [cl->format.bitsPerPixel / 16];
+
+       return rfbSetClientColourMap(cl, 0, 0);
+    }
+
+    /* truecolour -> truecolour */
+
+    if (PF_EQ(cl->format,rfbServerFormat)) {
+
+       /* client & server the same */
+
+       rfbLog("no translation needed\n");
+       cl->translateFn = rfbTranslateNone;
+       return TRUE;
+    }
+
+    if ((rfbServerFormat.bitsPerPixel < 16) ||
+       (!rfbEconomicTranslate && (rfbServerFormat.bitsPerPixel == 16))) {
+
+       /* we can use a single lookup table for <= 16 bpp */
+
+       cl->translateFn = rfbTranslateWithSingleTableFns
+                             [rfbServerFormat.bitsPerPixel / 16]
+                                 [cl->format.bitsPerPixel / 16];
+
+       (*rfbInitTrueColourSingleTableFns
+           [cl->format.bitsPerPixel / 16]) (&cl->translateLookupTable,
+                                            &rfbServerFormat, &cl->format);
+
+    } else {
+
+       /* otherwise we use three separate tables for red, green and blue */
+
+       cl->translateFn = rfbTranslateWithRGBTablesFns
+                             [rfbServerFormat.bitsPerPixel / 16]
+                                 [cl->format.bitsPerPixel / 16];
+
+       (*rfbInitTrueColourRGBTablesFns
+           [cl->format.bitsPerPixel / 16]) (&cl->translateLookupTable,
+                                            &rfbServerFormat, &cl->format);
+    }
+
+    return TRUE;
+}
+
+
+
+/*
+ * rfbSetClientColourMapBGR233 sets the client's colour map so that it's
+ * just like an 8-bit BGR233 true colour client.
+ */
+
+static Bool
+rfbSetClientColourMapBGR233(cl)
+    rfbClientPtr cl;
+{
+    char buf[sz_rfbSetColourMapEntriesMsg + 256 * 3 * 2];
+    rfbSetColourMapEntriesMsg *scme = (rfbSetColourMapEntriesMsg *)buf;
+    CARD16 *rgb = (CARD16 *)(&buf[sz_rfbSetColourMapEntriesMsg]);
+    int i, len;
+    int r, g, b;
+
+    if (cl->format.bitsPerPixel != 8) {
+       rfbLog("%s: client not 8 bits per pixel\n",
+               "rfbSetClientColourMapBGR233");
+       rfbCloseSock(cl->sock);
+       return FALSE;
+    }
+
+    scme->type = rfbSetColourMapEntries;
+
+    scme->firstColour = Swap16IfLE(0);
+    scme->nColours = Swap16IfLE(256);
+
+    len = sz_rfbSetColourMapEntriesMsg;
+
+    i = 0;
+
+    for (b = 0; b < 4; b++) {
+       for (g = 0; g < 8; g++) {
+           for (r = 0; r < 8; r++) {
+               rgb[i++] = Swap16IfLE(r * 65535 / 7);
+               rgb[i++] = Swap16IfLE(g * 65535 / 7);
+               rgb[i++] = Swap16IfLE(b * 65535 / 3);
+           }
+       }
+    }
+
+    len += 256 * 3 * 2;
+
+    if (WriteExact(cl->sock, buf, len) < 0) {
+       rfbLogPerror("rfbSetClientColourMapBGR233: write");
+       rfbCloseSock(cl->sock);
+       return FALSE;
+    }
+    return TRUE;
+}
+
+
+/*
+ * rfbSetClientColourMap is called to set the client's colour map.  If the
+ * client is a true colour client, we simply update our own translation table
+ * and mark the whole screen as having been modified.
+ */
+
+Bool
+rfbSetClientColourMap(cl, firstColour, nColours)
+    rfbClientPtr cl;
+    int firstColour;
+    int nColours;
+{
+    BoxRec box;
+
+    if (nColours == 0) {
+       nColours = rfbInstalledColormap->pVisual->ColormapEntries;
+    }
+
+    if (rfbServerFormat.trueColour || !cl->readyForSetColourMapEntries) {
+       return TRUE;
+    }
+
+    if (cl->format.trueColour) {
+       (*rfbInitColourMapSingleTableFns
+           [cl->format.bitsPerPixel / 16]) (&cl->translateLookupTable,
+                                            &rfbServerFormat, &cl->format);
+
+       REGION_UNINIT(pScreen,&cl->modifiedRegion);
+       box.x1 = box.y1 = 0;
+       box.x2 = rfbScreen.width;
+       box.y2 = rfbScreen.height;
+       REGION_INIT(pScreen,&cl->modifiedRegion,&box,0);
+
+       return TRUE;
+    }
+
+    return rfbSendSetColourMapEntries(cl, firstColour, nColours);
+}
+
+
+/*
+ * rfbSetClientColourMaps sets the colour map for each RFB client.
+ */
+
+void
+rfbSetClientColourMaps(firstColour, nColours)
+    int firstColour;
+    int nColours;
+{
+    rfbClientPtr cl, nextCl;
+
+    for (cl = rfbClientHead; cl; cl = nextCl) {
+       nextCl = cl->next;
+       rfbSetClientColourMap(cl, firstColour, nColours);
+    }
+}
+
+
+static void
+PrintPixelFormat(pf)
+    rfbPixelFormat *pf;
+{
+    if (pf->bitsPerPixel == 1) {
+       rfbLog("  1 bpp, %s sig bit in each byte is leftmost on the screen.\n",
+              (pf->bigEndian ? "most" : "least"));
+    } else {
+       rfbLog("  %d bpp, depth %d%s\n",pf->bitsPerPixel,pf->depth,
+              ((pf->bitsPerPixel == 8) ? ""
+               : (pf->bigEndian ? ", big endian" : ", little endian")));
+       if (pf->trueColour) {
+           rfbLog("  true colour: max r %d g %d b %d, shift r %d g %d b %d\n",
+                  pf->redMax, pf->greenMax, pf->blueMax,
+                  pf->redShift, pf->greenShift, pf->blueShift);
+       } else {
+           rfbLog("  uses a colour map (not true colour).\n");
+       }
+    }
+}
diff --git a/Xserver/programs/Xserver/hw/vnc/zrle.cc b/Xserver/programs/Xserver/hw/vnc/zrle.cc
new file mode 100644 (file)
index 0000000..d074f55
--- /dev/null
@@ -0,0 +1,179 @@
+//
+// Copyright (C) 2002 RealVNC Ltd.  All Rights Reserved.
+//
+// This is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This software is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this software; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,
+// USA.
+//
+
+//
+// zrle.cc
+//
+// Routines to implement Zlib Run-length Encoding (ZRLE).
+//
+
+#include <stdio.h>
+extern "C" {
+#include "rfb.h"
+}
+#include <rdr/MemOutStream.h>
+#include <rdr/ZlibOutStream.h>
+
+
+#define GET_IMAGE_INTO_BUF(tx,ty,tw,th,buf)                                \
+  char *fbptr = (rfbScreen.pfbMemory + (rfbScreen.paddedWidthInBytes * ty) \
+                 + (tx * (rfbScreen.bitsPerPixel / 8)));                   \
+                                                                           \
+  (*cl->translateFn)(cl->translateLookupTable, &rfbServerFormat,           \
+                     &cl->format, fbptr, (char*)buf,                       \
+                     rfbScreen.paddedWidthInBytes, tw, th);
+
+#define EXTRA_ARGS , rfbClientPtr cl
+
+#define BPP 8
+#include <rfb/zrleEncode.h>
+#undef BPP
+#define BPP 16
+#include <rfb/zrleEncode.h>
+#undef BPP
+#define BPP 32
+#include <rfb/zrleEncode.h>
+#define CPIXEL 24A
+#include <rfb/zrleEncode.h>
+#undef CPIXEL
+#define CPIXEL 24B
+#include <rfb/zrleEncode.h>
+#undef CPIXEL
+#undef BPP
+
+
+/*
+ * zrleBeforeBuf contains pixel data in the client's format.  It must be at
+ * least one pixel bigger than the largest tile of pixel data, since the
+ * ZRLE encoding algorithm writes to the position one past the end of the pixel
+ * data.
+ */
+
+static char zrleBeforeBuf[rfbZRLETileWidth * rfbZRLETileHeight * 4 + 4];
+
+static rdr::MemOutStream mos;
+
+
+/*
+ * rfbSendRectEncodingZRLE - send a given rectangle using ZRLE encoding.
+ */
+
+
+Bool rfbSendRectEncodingZRLE(rfbClientPtr cl, int x, int y, int w, int h)
+{
+  if (!cl->zrleData) cl->zrleData = new rdr::ZlibOutStream;
+  rdr::ZlibOutStream* zos = (rdr::ZlibOutStream*)cl->zrleData;
+  mos.clear();
+
+  switch (cl->format.bitsPerPixel) {
+
+  case 8:
+    zrleEncode8( x, y, w, h, &mos, zos, zrleBeforeBuf, cl);
+    break;
+
+  case 16:
+    zrleEncode16(x, y, w, h, &mos, zos, zrleBeforeBuf, cl);
+    break;
+
+  case 32:
+    bool fitsInLS3Bytes
+      = ((cl->format.redMax   << cl->format.redShift)   < (1<<24) &&
+         (cl->format.greenMax << cl->format.greenShift) < (1<<24) &&
+         (cl->format.blueMax  << cl->format.blueShift)  < (1<<24));
+
+    bool fitsInMS3Bytes = (cl->format.redShift   > 7  &&
+                           cl->format.greenShift > 7  &&
+                           cl->format.blueShift  > 7);
+
+    if ((fitsInLS3Bytes && !cl->format.bigEndian) ||
+        (fitsInMS3Bytes && cl->format.bigEndian))
+    {
+      zrleEncode24A(x, y, w, h, &mos, zos, zrleBeforeBuf, cl);
+    }
+    else if ((fitsInLS3Bytes && cl->format.bigEndian) ||
+             (fitsInMS3Bytes && !cl->format.bigEndian))
+    {
+      zrleEncode24B(x, y, w, h, &mos, zos, zrleBeforeBuf, cl);
+    }
+    else
+    {
+      zrleEncode32(x, y, w, h, &mos, zos, zrleBeforeBuf, cl);
+    }
+    break;
+  }
+
+  cl->rfbRectanglesSent[rfbEncodingZRLE]++;
+  cl->rfbBytesSent[rfbEncodingZRLE] += (sz_rfbFramebufferUpdateRectHeader
+                                        + sz_rfbZRLEHeader + mos.length());
+
+  if (ublen + sz_rfbFramebufferUpdateRectHeader + sz_rfbZRLEHeader
+      > UPDATE_BUF_SIZE)
+    {
+      if (!rfbSendUpdateBuf(cl))
+        return FALSE;
+    }
+
+  rfbFramebufferUpdateRectHeader rect;
+  rect.r.x = Swap16IfLE(x);
+  rect.r.y = Swap16IfLE(y);
+  rect.r.w = Swap16IfLE(w);
+  rect.r.h = Swap16IfLE(h);
+  rect.encoding = Swap32IfLE(rfbEncodingZRLE);
+
+  memcpy(&updateBuf[ublen], (char *)&rect,
+         sz_rfbFramebufferUpdateRectHeader);
+  ublen += sz_rfbFramebufferUpdateRectHeader;
+
+  rfbZRLEHeader hdr;
+
+  hdr.length = Swap32IfLE(mos.length());
+
+  memcpy(&updateBuf[ublen], (char *)&hdr, sz_rfbZRLEHeader);
+  ublen += sz_rfbZRLEHeader;
+
+  // copy into updateBuf and send from there.  Maybe should send directly?
+
+  for (int i = 0; i < mos.length();) {
+
+    int bytesToCopy = UPDATE_BUF_SIZE - ublen;
+
+    if (i + bytesToCopy > mos.length()) {
+      bytesToCopy = mos.length() - i;
+    }
+
+    memcpy(&updateBuf[ublen], (CARD8*)mos.data() + i, bytesToCopy);
+
+    ublen += bytesToCopy;
+    i += bytesToCopy;
+
+    if (ublen == UPDATE_BUF_SIZE) {
+      if (!rfbSendUpdateBuf(cl))
+        return FALSE;
+    }
+  }
+
+  return TRUE;
+}
+
+
+void FreeZrleData(rfbClientPtr cl)
+{
+  delete (rdr::ZlibOutStream*)cl->zrleData;
+}
+
diff --git a/Xserver/programs/Xserver/hw/xfree86/common/compiler.h b/Xserver/programs/Xserver/hw/xfree86/common/compiler.h
new file mode 100644 (file)
index 0000000..8f5cd30
--- /dev/null
@@ -0,0 +1,1460 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/common/compiler.h,v 3.24.2.2 1998/02/07 00:44:37 dawes Exp $ */
+/*
+ * Copyright 1990,91 by Thomas Roell, Dinkelscherben, Germany.
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the name of Thomas Roell not be used in
+ * advertising or publicity pertaining to distribution of the software without
+ * specific, written prior permission.  Thomas Roell makes no representations
+ * about the suitability of this software for any purpose.  It is provided
+ * "as is" without express or implied warranty.
+ *
+ * THOMAS ROELL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+ * EVENT SHALL THOMAS ROELL BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
+ * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
+ * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+ * PERFORMANCE OF THIS SOFTWARE.
+ *
+ */
+/* $XConsortium: compiler.h /main/16 1996/10/25 15:38:34 kaleb $ */
+
+#ifndef _COMPILER_H
+#define _COMPILER_H
+
+#ifndef __STDC__
+# ifdef signed
+#  undef signed
+# endif
+# ifdef volatile
+#  undef volatile
+# endif
+# ifdef const
+#  undef const
+# endif
+# define signed /**/
+# ifdef __GNUC__
+#  define volatile __volatile__
+#  define const __const__
+#  ifdef PC98
+#   undef NO_INLINE
+#  endif
+# else
+#  define const /**/
+#  ifdef PC98
+#   define __inline__ /**/
+#  endif
+# endif /* __GNUC__ */
+#endif /* !__STDC__ */
+
+#if defined(IODEBUG) && defined(__GNUC__)
+#define outb RealOutb
+#define outw RealOutw
+#define outl RealOutl
+#define inb RealInb
+#define inw RealInw
+#define inl RealInl
+#endif
+
+#ifdef NO_INLINE
+
+extern void outb();
+extern void outw();
+extern void outl();
+extern unsigned int inb();
+extern unsigned int inw();
+extern unsigned int inl();
+#if NeedFunctionPrototypes
+extern unsigned char rdinx(unsigned short int, unsigned char);
+extern void wrinx(unsigned short int, unsigned char, unsigned char);
+extern void modinx(unsigned short int, unsigned char, unsigned char, unsigned char);
+extern int testrg(unsigned short int, unsigned char);
+extern int testinx2(unsigned short int, unsigned char, unsigned char);
+extern int testinx(unsigned short int, unsigned char);
+#else /* NeedFunctionProtoypes */
+extern unsigned char rdinx();
+extern void wrinx();
+extern void modinx();
+extern int testrg();
+extern int testinx2();
+extern int testinx();
+#endif /* NeedFunctionProtoypes */
+
+#else /* NO_INLINE */
+
+#ifdef __GNUC__
+
+#if defined(linux) && defined(__alpha__)
+/* for Linux on Alpha, we use the LIBC _inx/_outx routines */
+/* note that the appropriate setup via "ioperm" needs to be done */
+/*  *before* any inx/outx is done. */
+
+static __inline__ void
+outb(port, val)
+     unsigned short port;
+     char val;
+{
+    extern void _outb(char val, unsigned short port);
+    _outb(val, port);
+}
+
+static __inline__ void
+outw(port, val)
+     unsigned short port;
+     short val;
+{
+    extern void _outw(short val, unsigned short port);
+    _outw(val, port);
+}
+
+static __inline__ void
+outl(port, val)
+     unsigned short port;
+     int val;
+{
+    extern void _outl(int val, unsigned short port);
+    _outl(val, port);
+}
+
+static __inline__ unsigned int
+inb(port)
+     unsigned short port;
+{
+  extern unsigned int _inb(unsigned short port);
+  return _inb(port);
+}
+
+static __inline__ unsigned int
+inw(port)
+     unsigned short port;
+{
+  extern unsigned int _inw(unsigned short port);
+  return _inw(port);
+}
+
+static __inline__ unsigned int
+inl(port)
+     unsigned short port;
+{
+  extern unsigned int _inl(unsigned short port);
+  return _inl(port);
+}
+
+
+/*
+ * inline functions to do unaligned accesses
+ * from linux/include/asm-alpha/unaligned.h
+ */
+
+static __inline__ unsigned long ldq_u(unsigned long * r11)
+{
+       unsigned long r1,r2;
+       __asm__("ldq_u %0,%3\n\t"
+               "ldq_u %1,%4\n\t"
+               "extql %0,%2,%0\n\t"
+               "extqh %1,%2,%1\n\t"
+               "bis %1,%0,%0"
+               :"=&r" (r1), "=&r" (r2)
+               :"r" (r11),
+                "m" (*r11),
+                "m" (*(unsigned long *)(7+(char *) r11)));
+       return r1;
+}
+
+static __inline__ unsigned long ldl_u(unsigned int * r11)
+{
+       unsigned long r1,r2;
+       __asm__("ldq_u %0,%3\n\t"
+               "ldq_u %1,%4\n\t"
+               "extll %0,%2,%0\n\t"
+               "extlh %1,%2,%1\n\t"
+               "bis %1,%0,%0"
+               :"=&r" (r1), "=&r" (r2)
+               :"r" (r11),
+                "m" (*r11),
+                "m" (*(unsigned long *)(3+(char *) r11)));
+       return r1;
+}
+
+static __inline__ unsigned long ldw_u(unsigned short * r11)
+{
+       unsigned long r1,r2;
+       __asm__("ldq_u %0,%3\n\t"
+               "ldq_u %1,%4\n\t"
+               "extwl %0,%2,%0\n\t"
+               "extwh %1,%2,%1\n\t"
+               "bis %1,%0,%0"
+               :"=&r" (r1), "=&r" (r2)
+               :"r" (r11),
+                "m" (*r11),
+                "m" (*(unsigned long *)(1+(char *) r11)));
+       return r1;
+}
+
+static __inline__ void stq_u(unsigned long r5, unsigned long * r11)
+{
+       unsigned long r1,r2,r3,r4;
+
+       __asm__("ldq_u %3,%1\n\t"
+               "ldq_u %2,%0\n\t"
+               "insqh %6,%7,%5\n\t"
+               "insql %6,%7,%4\n\t"
+               "mskqh %3,%7,%3\n\t"
+               "mskql %2,%7,%2\n\t"
+               "bis %3,%5,%3\n\t"
+               "bis %2,%4,%2\n\t"
+               "stq_u %3,%1\n\t"
+               "stq_u %2,%0"
+               :"=m" (*r11),
+                "=m" (*(unsigned long *)(7+(char *) r11)),
+                "=&r" (r1), "=&r" (r2), "=&r" (r3), "=&r" (r4)
+               :"r" (r5), "r" (r11));
+}
+
+static __inline__ void stl_u(unsigned long r5, unsigned int * r11)
+{
+       unsigned long r1,r2,r3,r4;
+
+       __asm__("ldq_u %3,%1\n\t"
+               "ldq_u %2,%0\n\t"
+               "inslh %6,%7,%5\n\t"
+               "insll %6,%7,%4\n\t"
+               "msklh %3,%7,%3\n\t"
+               "mskll %2,%7,%2\n\t"
+               "bis %3,%5,%3\n\t"
+               "bis %2,%4,%2\n\t"
+               "stq_u %3,%1\n\t"
+               "stq_u %2,%0"
+               :"=m" (*r11),
+                "=m" (*(unsigned long *)(3+(char *) r11)),
+                "=&r" (r1), "=&r" (r2), "=&r" (r3), "=&r" (r4)
+               :"r" (r5), "r" (r11));
+}
+
+static __inline__ void stw_u(unsigned long r5, unsigned short * r11)
+{
+       unsigned long r1,r2,r3,r4;
+
+       __asm__("ldq_u %3,%1\n\t"
+               "ldq_u %2,%0\n\t"
+               "inswh %6,%7,%5\n\t"
+               "inswl %6,%7,%4\n\t"
+               "mskwh %3,%7,%3\n\t"
+               "mskwl %2,%7,%2\n\t"
+               "bis %3,%5,%3\n\t"
+               "bis %2,%4,%2\n\t"
+               "stq_u %3,%1\n\t"
+               "stq_u %2,%0"
+               :"=m" (*r11),
+                "=m" (*(unsigned long *)(1+(char *) r11)),
+                "=&r" (r1), "=&r" (r2), "=&r" (r3), "=&r" (r4)
+               :"r" (r5), "r" (r11));
+}
+
+#define mem_barrier()        __asm__ __volatile__("mb"  : : : "memory")
+#ifdef __ELF__
+#define write_mem_barrier()  __asm__ __volatile__("wmb" : : : "memory")
+#else  /*  ECOFF gas 2.6 doesn't know "wmb" :-(  */
+#define write_mem_barrier()  mem_barrier()
+#endif
+
+#else /* defined(linux) && defined(__alpha__) */
+#if defined(__mips__)
+
+unsigned int IOPortBase;  /* Memory mapped I/O port area */
+
+static __inline__ void
+outb(port, val)
+     short port;
+     char val;
+{
+       *(volatile unsigned char*)(((unsigned short)(port))+IOPortBase) = val;
+}
+
+static __inline__ void
+outw(port, val)
+     short port;
+     short val;
+{
+       *(volatile unsigned short*)(((unsigned short)(port))+IOPortBase) = val;
+}
+
+static __inline__ void
+outl(port, val)
+     short port;
+     int val;
+{
+       *(volatile unsigned long*)(((unsigned short)(port))+IOPortBase) = val;
+}
+
+static __inline__ unsigned int
+inb(port)
+     short port;
+{
+       return(*(volatile unsigned char*)(((unsigned short)(port))+IOPortBase));
+}
+
+static __inline__ unsigned int
+inw(port)
+     short port;
+{
+       return(*(volatile unsigned short*)(((unsigned short)(port))+IOPortBase));
+}
+
+static __inline__ unsigned int
+inl(port)
+     short port;
+{
+       return(*(volatile unsigned long*)(((unsigned short)(port))+IOPortBase));
+}
+
+
+static __inline__ unsigned long ldq_u(unsigned long * r11)
+{
+       unsigned long r1;
+       __asm__("lwr %0,%2\n\t"
+               "lwl %0,%3\n\t"
+               :"=&r" (r1)
+               :"r" (r11),
+                "m" (*r11),
+                "m" (*(unsigned long *)(3+(char *) r11)));
+       return r1;
+}
+
+static __inline__ unsigned long ldl_u(unsigned int * r11)
+{
+       unsigned long r1;
+       __asm__("lwr %0,%2\n\t"
+               "lwl %0,%3\n\t"
+               :"=&r" (r1)
+               :"r" (r11),
+                "m" (*r11),
+                "m" (*(unsigned long *)(3+(char *) r11)));
+       return r1;
+}
+
+static __inline__ unsigned long ldw_u(unsigned short * r11)
+{
+       unsigned long r1;
+       __asm__("lwr %0,%2\n\t"
+               "lwl %0,%3\n\t"
+               :"=&r" (r1)
+               :"r" (r11),
+                "m" (*r11),
+                "m" (*(unsigned long *)(1+(char *) r11)));
+       return r1;
+}
+
+#define stq_u(v,p)     stl_u(v,p)
+#define stl_u(v,p)     ((unsigned char *)(p)) = (v); \
+                       ((unsigned char *)(p)+1) = ((v) >> 8);  \
+                       ((unsigned char *)(p)+2) = ((v) >> 16); \
+                       ((unsigned char *)(p)+3) = ((v) >> 24)
+
+#define stw_u(v,p)     ((unsigned char *)(p)) = (v); \
+                       ((unsigned char *)(p)+1) = ((v) >> 8)
+
+#define mem_barrier()   /* NOP */
+
+#else /* defined(mips) */
+
+#define ldq_u(p)       (*((unsigned long  *)(p)))
+#define ldl_u(p)       (*((unsigned int   *)(p)))
+#define ldw_u(p)       (*((unsigned short *)(p)))
+#define stq_u(v,p)     ((unsigned long  *)(p)) = (v)
+#define stl_u(v,p)     ((unsigned int   *)(p)) = (v)
+#define stw_u(v,p)     ((unsigned short *)(p)) = (v)
+#define mem_barrier()   /* NOP */
+#define write_mem_barrier()   /* NOP */
+
+#if !defined(FAKEIT) && !defined(__mc68000__)
+#ifdef GCCUSESGAS
+
+/*
+ * If gcc uses gas rather than the native assembler, the syntax of these
+ * inlines has to be different.                DHD
+ */
+#ifndef PC98
+
+static __inline__ void
+#if NeedFunctionPrototypes
+outb(
+unsigned short int port,
+unsigned char val)
+#else
+outb(port, val)
+unsigned short int port;
+unsigned char val;
+#endif /* NeedFunctionPrototypes */
+{
+   __asm__ __volatile__("outb %0,%1" : :"a" (val), "d" (port));
+}
+
+
+static __inline__ void
+#if NeedFunctionPrototypes
+outw(
+unsigned short int port,
+unsigned short int val)
+#else
+outw(port, val)
+unsigned short int port;
+unsigned short int val;
+#endif /* NeedFunctionPrototypes */
+{
+   __asm__ __volatile__("outw %0,%1" : :"a" (val), "d" (port));
+}
+
+static __inline__ void
+#if NeedFunctionPrototypes
+outl(
+unsigned short int port,
+unsigned int val)
+#else
+outl(port, val)
+unsigned short int port;
+unsigned int val;
+#endif /* NeedFunctionPrototypes */
+{
+   __asm__ __volatile__("outl %0,%1" : :"a" (val), "d" (port));
+}
+
+static __inline__ unsigned int
+#if NeedFunctionPrototypes
+inb(
+unsigned short int port)
+#else
+inb(port)
+unsigned short int port;
+#endif /* NeedFunctionPrototypes */
+{
+   unsigned char ret;
+   __asm__ __volatile__("inb %1,%0" :
+       "=a" (ret) :
+       "d" (port));
+   return ret;
+}
+
+static __inline__ unsigned int
+#if NeedFunctionPrototypes
+inw(
+unsigned short int port)
+#else
+inw(port)
+unsigned short int port;
+#endif /* NeedFunctionPrototypes */
+{
+   unsigned short int ret;
+   __asm__ __volatile__("inw %1,%0" :
+       "=a" (ret) :
+       "d" (port));
+   return ret;
+}
+
+static __inline__ unsigned int
+#if NeedFunctionPrototypes
+inl(
+unsigned short int port)
+#else
+inl(port)
+unsigned short int port;
+#endif /* NeedFunctionPrototypes */
+{
+   unsigned int ret;
+   __asm__ __volatile__("inl %1,%0" :
+       "=a" (ret) :
+       "d" (port));
+   return ret;
+}
+
+#else /* PC98 */
+
+static __inline__ void
+#if NeedFunctionPrototypes
+_outb(
+unsigned short int port,
+unsigned char val)
+#else
+_outb(port, val)
+unsigned short int port;
+unsigned char val;
+#endif /* NeedFunctionPrototypes */
+{
+     __asm__ __volatile__("outb %0,%1" ::"a" (val), "d" (port));
+}
+
+static __inline__ void
+#if NeedFunctionPrototypes
+_outw(
+unsigned short int port,
+unsigned short int val)
+#else
+_outw(port, val)
+unsigned short int port;
+unsigned short int val;
+#endif /* NeedFunctionPrototypes */
+{
+     __asm__ __volatile__("outw %0,%1" ::"a" (val), "d" (port));
+}
+static __inline__ void
+#if NeedFunctionPrototypes
+_outl(
+unsigned short int port,
+unsigned int val)
+#else
+_outl(port, val)
+unsigned short int port;
+unsigned int val;
+#endif /* NeedFunctionPrototypes */
+{
+   __asm__ __volatile__("outl %0,%1" : :"a" (val), "d" (port));
+}
+
+
+static __inline__ unsigned int
+#if NeedFunctionPrototypes
+_inb(
+unsigned short int port)
+#else
+_inb(port)
+unsigned short int port;
+#endif /* NeedFunctionPrototypes */
+{
+     unsigned char ret;
+     __asm__ __volatile__("inb %1,%0" :
+                          "=a" (ret) :
+                          "d" (port));
+     return ret;
+}
+
+static __inline__ unsigned int
+#if NeedFunctionPrototypes
+_inw(
+unsigned short int port)
+#else
+_inw(port)
+unsigned short int port;
+#endif /* NeedFunctionPrototypes */
+{
+     unsigned short ret;
+     __asm__ __volatile__("inw %1,%0" :
+                          "=a" (ret) :
+                          "d" (port));
+     return ret;
+}
+
+static __inline__ unsigned int
+#if NeedFunctionPrototypes
+_inl(
+unsigned short int port)
+#else
+_inl(port)
+unsigned short int port;
+#endif /* NeedFunctionPrototypes */
+{
+   unsigned int ret;
+   __asm__ __volatile__("inl %1,%0" :
+       "=a" (ret) :
+       "d" (port));
+   return ret;
+}
+
+
+#if defined(PC98_PW) || defined(PC98_XKB) || defined(PC98_NEC) || defined(PC98_PWLB) || defined(PC98_GA968)
+#define PW_PORT 0x600
+extern short chipID;
+#if NeedFunctionPrototypes
+extern void *mmioBase;
+#else
+extern unsigned char *mmioBase;
+#endif
+extern unsigned short _port_tbl[];
+#define        port_convert(x) _port_tbl[(unsigned short)x]
+#endif 
+
+#if defined(PC98_WAB) ||  defined(PC98_GANB_WAP)
+static __inline__ unsigned short
+port_convert(unsigned short port)
+{
+     port <<= 8;
+     port &= 0x7f00; /* Mask 0111 1111 0000 0000 */
+     port |= 0xE0;
+     return port;
+}
+#endif /* PC98_WAB || PC98_GANB_WAP */
+#if defined(PC98_WABEP)
+static __inline__ unsigned short
+port_convert(unsigned short port)
+{
+     port &= 0x7f; /* Mask 0000 0000 0111 1111 */
+     port |= 0x0f00;
+     return port;
+}
+#endif /* PC98_WABEP */
+
+#ifdef PC98_WSNA
+static __inline__ unsigned short
+port_convert(unsigned short port)
+{
+     port <<= 8;
+     port &= 0x7f00; /* Mask 0111 1111 0000 0000 */
+     port |= 0xE2;
+     return port;
+}
+#endif /* PC98_WSNA */
+
+#ifdef PC98_NKVNEC
+#ifdef PC98_NEC_CIRRUS2
+static __inline__ unsigned short
+port_convert(unsigned short port)
+{
+     port = (port & 0xf) + ((port & 0xf0) << 4) + 0x0050;
+     return port;
+}
+#else
+static __inline__ unsigned short
+port_convert(unsigned short port)
+{
+     port = (port & 0xf) + ((port & 0xf0) << 4) + 0x00a0;
+     return port;
+}
+#endif /* PC98_NEC_CIRRUS2 */
+#endif /* PC98_NKVNEC */
+
+#if defined(PC98_TGUI) || defined(PC98_MGA)
+#if NeedFunctionPrototypes
+extern void *mmioBase;
+#else
+extern unsigned char *mmioBase;
+#endif
+#endif
+
+static __inline__ void
+#if NeedFunctionPrototypes
+outb(
+unsigned short port,
+unsigned char val)
+#else
+outb(port, val)
+unsigned short port;
+unsigned char val;
+#endif /* NeedFunctionPrototypes */
+{
+#if defined(PC98_GANB_WAP) || defined(PC98_NKVNEC) || defined(PC98_WAB) || \
+    defined(PC98_WABEP) || defined(PC98_WSNA) || defined(PC98_PW) || \
+    defined(PC98_XKB) || defined(PC98_NEC)
+   unsigned short tmp;
+   tmp=port_convert(port);
+   port=tmp;
+#endif
+
+#if defined(PC98_NEC)||defined(PC98_PWLB)||defined(PC98_TGUI)||defined(PC98_MGA)
+   *(volatile unsigned char *)((char *)mmioBase+(port)) = (unsigned char)(val);
+#else
+   __asm__ __volatile__("outb %0,%1" : :"a" (val), "d" (port));
+#endif
+}
+
+static __inline__ void
+#if NeedFunctionPrototypes
+outw(
+unsigned short port,
+unsigned short val)
+#else
+outw(port, val)
+unsigned short port;
+unsigned short val;
+#endif /* NeedFunctionPrototypes */
+{
+#if defined(PC98_GANB_WAP) || defined(PC98_NKVNEC) || defined(PC98_WAB) || \
+    defined(PC98_WABEP) || defined(PC98_WSNA) || defined(PC98_PW) || \
+    defined(PC98_XKB) || defined(PC98_NEC)
+   unsigned short tmp;
+   tmp=port_convert(port);
+   port=tmp;
+#endif
+
+#if defined(PC98_NEC)||defined(PC98_PWLB)||defined(PC98_TGUI)||defined(PC98_MGA)
+   *(volatile unsigned short *)((char *)mmioBase+(port)) = (unsigned short)(val);
+#else
+   __asm__ __volatile__("outw %0,%1" : :"a" (val), "d" (port));
+#endif
+}
+
+static __inline__ void
+#if NeedFunctionPrototypes
+outl(
+unsigned short port,
+unsigned int val)
+#else
+outl(port, val)
+unsigned short port;
+unsigned int val;
+#endif /* NeedFunctionPrototypes */
+{
+#if defined(PC98_GANB_WAP) || defined(PC98_NKVNEC) || defined(PC98_WAB) || \
+    defined(PC98_WABEP) || defined(PC98_WSNA) || defined(PC98_PW) || \
+    defined(PC98_XKB) || defined(PC98_NEC)
+   unsigned short tmp;
+   tmp=port_convert(port);
+   port=tmp;
+#endif
+
+#if defined(PC98_NEC)||defined(PC98_PWLB)||defined(PC98_TGUI)||defined(PC98_MGA)
+   *(volatile unsigned int *)((char *)mmioBase+(port)) = (unsigned int)(val);
+#else
+   __asm__ __volatile__("outl %0,%1" : :"a" (val), "d" (port));
+#endif
+}
+
+static __inline__ unsigned int
+#if NeedFunctionPrototypes
+inb(
+unsigned short port)
+#else
+inb(port)
+unsigned short port;
+#endif /* NeedFunctionPrototypes */
+{
+   unsigned char ret;
+
+#if defined(PC98_GANB_WAP) || defined(PC98_NKVNEC) || defined(PC98_WAB) || \
+    defined(PC98_WABEP) || defined(PC98_WSNA) || defined(PC98_PW) || \
+    defined(PC98_XKB) || defined(PC98_NEC)
+   unsigned short tmp;
+   tmp=port_convert(port);
+   port=tmp;
+#endif
+
+#if defined(PC98_NEC)||defined(PC98_PWLB)||defined(PC98_TGUI)||defined(PC98_MGA)
+   ret =*(volatile unsigned char *)((char *)mmioBase+(port));
+#else
+   __asm__ __volatile__("inb %1,%0" :
+       "=a" (ret) :
+       "d" (port));
+#endif
+   return ret;
+}
+
+static __inline__ unsigned int
+#if NeedFunctionPrototypes
+inw(
+unsigned short port)
+#else
+inw(port)
+unsigned short port;
+#endif /* NeedFunctionPrototypes */
+{
+   unsigned short ret;
+
+#if defined(PC98_GANB_WAP) || defined(PC98_NKVNEC) || defined(PC98_WAB) || \
+    defined(PC98_WABEP) || defined(PC98_WSNA) || defined(PC98_PW) || \
+    defined(PC98_XKB) || defined(PC98_NEC)
+   unsigned short tmp;
+   tmp=port_convert(port);
+   port=tmp;
+#endif
+
+#if defined(PC98_NEC)||defined(PC98_PWLB)||defined(PC98_TGUI)||defined(PC98_MGA)
+   ret =*(volatile unsigned short *)((char *)mmioBase+(port));
+#else
+   __asm__ __volatile__("inw %1,%0" :
+       "=a" (ret) :
+       "d" (port));
+#endif
+   return ret;
+}
+
+static __inline__ unsigned int
+#if NeedFunctionPrototypes
+inl(
+unsigned short port)
+#else
+inl(port)
+unsigned short port;
+#endif /* NeedFunctionPrototypes */
+{
+   unsigned int ret;
+
+#if defined(PC98_GANB_WAP) || defined(PC98_NKVNEC) || defined(PC98_WAB) || \
+    defined(PC98_WABEP) || defined(PC98_WSNA) || defined(PC98_PW) || \
+    defined(PC98_XKB) || defined(PC98_NEC)
+   unsigned short tmp;
+   tmp=port_convert(port);
+   port=tmp;
+#endif
+
+#if defined(PC98_NEC)||defined(PC98_PWLB)||defined(PC98_TGUI)||defined(PC98_MGA)
+   ret =*(volatile unsigned int *)((char *)mmioBase+(port));
+#else
+   __asm__ __volatile__("inl %1,%0" :
+       "=a" (ret) :
+       "d" (port));
+#endif
+   return ret;
+}
+
+#endif /* PC98 */
+
+#else  /* GCCUSESGAS */
+
+static __inline__ void
+#if NeedFunctionPrototypes
+outb(
+unsigned short int port,
+unsigned char val)
+#else
+outb(port, val)
+unsigned short int port;
+unsigned char val;
+#endif /* NeedFunctionPrototypes */
+{
+  __asm__ __volatile__("out%B0 (%1)" : :"a" (val), "d" (port));
+}
+
+static __inline__ void
+#if NeedFunctionPrototypes
+outw(
+unsigned short int port,
+unsigned short int val)
+#else
+outw(port, val)
+unsigned short int port;
+unsigned short int val;
+#endif /* NeedFunctionPrototypes */
+{
+  __asm__ __volatile__("out%W0 (%1)" : :"a" (val), "d" (port));
+}
+
+static __inline__ void
+#if NeedFunctionPrototypes
+outl(
+unsigned short int port,
+unsigned int val)
+#else
+outl(port, val)
+unsigned short int port;
+unsigned int val;
+#endif /* NeedFunctionPrototypes */
+{
+  __asm__ __volatile__("out%L0 (%1)" : :"a" (val), "d" (port));
+}
+
+static __inline__ unsigned int
+#if NeedFunctionPrototypes
+inb(
+unsigned short int port)
+#else
+inb(port)
+unsigned short int port;
+#endif /* NeedFunctionPrototypes */
+{
+  unsigned char ret;
+  __asm__ __volatile__("in%B0 (%1)" :
+                  "=a" (ret) :
+                  "d" (port));
+  return ret;
+}
+
+static __inline__ unsigned int
+#if NeedFunctionPrototypes
+inw(
+unsigned short int port)
+#else
+inw(port)
+unsigned short int port;
+#endif /* NeedFunctionPrototypes */
+{
+  unsigned short int ret;
+  __asm__ __volatile__("in%W0 (%1)" :
+                  "=a" (ret) :
+                  "d" (port));
+  return ret;
+}
+
+static __inline__ unsigned int
+#if NeedFunctionPrototypes
+inl(
+unsigned short int port)
+#else
+inl(port)
+unsigned short int port;
+#endif /* NeedFunctionPrototypes */
+{
+  unsigned int ret;
+  __asm__ __volatile__("in%L0 (%1)" :
+                   "=a" (ret) :
+                   "d" (port));
+  return ret;
+}
+
+#endif /* GCCUSESGAS */
+
+#else /* !defined(FAKEIT) && !defined(__mc68000__) */
+
+static __inline__ void
+#if NeedFunctionPrototypes
+outb(
+unsigned short int port,
+unsigned char val)
+#else
+outb(port, val)
+unsigned short int port;
+unsigned char val;
+#endif /* NeedFunctionPrototypes */
+{
+}
+
+static __inline__ void
+#if NeedFunctionPrototypes
+outw(
+unsigned short int port,
+unsigned short int val)
+#else
+outw(port, val)
+unsigned short int port;
+unsigned short int val;
+#endif /* NeedFunctionPrototypes */
+{
+}
+
+static __inline__ void
+#if NeedFunctionPrototypes
+outl(
+unsigned short int port,
+unsigned int val)
+#else
+outl(port, val)
+unsigned short int port;
+unsigned int val;
+#endif /* NeedFunctionPrototypes */
+{
+}
+
+static __inline__ unsigned int
+#if NeedFunctionPrototypes
+inb(
+unsigned short int port)
+#else
+inb(port)
+unsigned short int port;
+#endif /* NeedFunctionPrototypes */
+{
+  return 0;
+}
+
+static __inline__ unsigned int
+#if NeedFunctionPrototypes
+inw(
+unsigned short int port)
+#else
+inw(port)
+unsigned short int port;
+#endif /* NeedFunctionPrototypes */
+{
+  return 0;
+}
+
+static __inline__ unsigned int
+#if NeedFunctionPrototypes
+inl(
+unsigned short int port)
+#else
+inl(port)
+unsigned short int port;
+#endif /* NeedFunctionPrototypes */
+{
+  return 0;
+}
+
+#endif /* FAKEIT */
+
+#endif /* defined(mips) */
+#endif /* defined(AlphaArchitecture) && defined(LinuxArchitecture) */
+
+#else /* __GNUC__ */
+#if !defined(AMOEBA) && !defined(MINIX)
+# if defined(__STDC__) && (__STDC__ == 1)
+#  ifndef asm
+#   define asm __asm
+#  endif
+# endif
+# ifdef SVR4
+#  include <sys/types.h>
+#  ifndef __HIGHC__
+#   ifndef __USLC__
+#    define __USLC__
+#   endif
+#  endif
+# endif
+# ifndef PC98
+#  ifndef SCO325
+#   include <sys/inline.h>
+#  else
+#   include "scoasm.h"
+#  endif
+# else
+#if defined(PC98_PW) || defined(PC98_XKB) || defined(PC98_NEC) || defined(PC98_PWLB) || defined(PC98_GA968)
+#define PW_PORT 0x600
+extern short chipID;
+#if NeedFunctionPrototypes
+extern void *mmioBase;
+#else
+extern unsigned char *mmioBase;
+#endif
+extern unsigned short _port_tbl[];
+#define        port_convert(x) _port_tbl[(unsigned short)x]
+#endif 
+
+#if defined(PC98_TGUI) || defined(PC98_MGA)
+#if NeedFunctionPrototypes
+extern void *mmioBase;
+#else
+extern unsigned char *mmioBase;
+#endif
+#endif
+
+asm     void _outl(port,val)
+{
+%reg   port,val;
+       movl    port, %edx
+       movl    val, %eax
+       outl    (%dx)
+%reg   port; mem       val;
+       movl    port, %edx
+       movl    val, %eax
+       outl    (%dx)
+%mem   port; reg       val;
+       movw    port, %dx
+       movl    val, %eax
+       outl    (%dx)
+%mem   port,val;
+       movw    port, %dx
+       movl    val, %eax
+       outl    (%dx)
+}
+
+asm    void _outw(port,val)
+{
+%reg   port,val;
+       movl    port, %edx
+       movl    val, %eax
+       data16
+       outl    (%dx)
+%reg   port; mem       val;
+       movl    port, %edx
+       movw    val, %ax
+       data16
+       outl    (%dx)
+%mem   port; reg       val;
+       movw    port, %dx
+       movl    val, %eax
+       data16
+       outl    (%dx)
+%mem   port,val;
+       movw    port, %dx
+       movw    val, %ax
+       data16
+       outl    (%dx)
+}
+
+asm    void _outb(port,val)
+{
+%reg   port,val;
+       movl    port, %edx
+       movl    val, %eax
+       outb    (%dx)
+%reg   port; mem       val;
+       movl    port, %edx
+       movb    val, %al
+       outb    (%dx)
+%mem   port; reg       val;
+       movw    port, %dx
+       movl    val, %eax
+       outb    (%dx)
+%mem   port,val;
+       movw    port, %dx
+       movb    val, %al
+       outb    (%dx)
+}
+
+asm     int _inl(port)
+{
+%reg   port;
+       movl    port, %edx
+       inl     (%dx)
+%mem   port;
+       movw    port, %dx
+       inl     (%dx)
+}
+
+asm    int _inw(port)
+{
+%reg   port;
+       subl    %eax, %eax
+       movl    port, %edx
+       data16
+       inl     (%dx)
+%mem   port;
+       subl    %eax, %eax
+       movw    port, %dx
+       data16
+       inl     (%dx)
+}
+
+asm    int _inb(port)
+{
+%reg   port;
+       subl    %eax, %eax
+       movl    port, %edx
+       inb     (%dx)
+%mem   port;
+       subl    %eax, %eax
+       movw    port, %dx
+       inb     (%dx)
+}
+
+#if defined(PC98_WAB) ||  defined(PC98_GANB_WAP)
+static unsigned short
+port_convert(unsigned short port)
+{
+     port <<= 8;
+     port &= 0x7f00; /* Mask 0111 1111 0000 0000 */
+     port |= 0xE0;
+     return port;
+}
+#endif /* PC98_WAB || PC98_GANB_WAP */
+
+#if defined(PC98_WABEP)
+static unsigned short
+port_convert(unsigned short port)
+{
+     port &= 0x7f; /* Mask 0000 0000 0111 1111 */
+     port |= 0x0f00;
+     return port;
+}
+#endif /* PC98_WABEP */
+
+#ifdef PC98_WSNA
+static unsigned short
+port_convert(unsigned short port)
+{
+     port <<= 8;
+     port &= 0x7f00; /* Mask 0111 1111 0000 0000 */
+     port |= 0xE2;
+     return port;
+}
+#endif /* PC98_WSNA */
+
+#ifdef PC98_NKVNEC
+#ifdef PC98_NEC_CIRRUS2
+static unsigned short
+port_convert(unsigned short port)
+{
+     port = (port & 0xf) + ((port & 0xf0) << 4) + 0x0050;
+     return port;
+}
+#else
+static unsigned short
+port_convert(unsigned short port)
+{
+     port = (port & 0xf) + ((port & 0xf0) << 4) + 0x00a0;
+     return port;
+}
+#endif /* PC98_NEC_CIRRUS2 */
+#endif /* PC98_NKVNEC */
+
+static void outl(port,val)
+{
+#if defined(PC98_GANB_WAP) || defined(PC98_NKVNEC) || defined(PC98_WAB) || \
+    defined(PC98_WABEP) || defined(PC98_WSNA) || defined(PC98_PW) || \
+    defined(PC98_XKB) || defined(PC98_NEC)
+   unsigned short tmp;
+   tmp=port_convert(port);
+   port=tmp;
+#endif
+
+#if defined(PC98_NEC)||defined(PC98_PWLB)||defined(PC98_TGUI)||defined(PC98_MGA)
+   *(volatile unsigned int *)((char *)mmioBase+(port)) = (unsigned int)(val);
+#else
+   _outl(port,val);
+#endif
+}
+
+static void outw(port,val)
+{
+#if defined(PC98_GANB_WAP) || defined(PC98_NKVNEC) || defined(PC98_WAB) || \
+    defined(PC98_WABEP) || defined(PC98_WSNA) || defined(PC98_PW) || \
+    defined(PC98_XKB) || defined(PC98_NEC)
+   unsigned short tmp;
+   tmp=port_convert(port);
+   port=tmp;
+#endif
+
+#if defined(PC98_NEC)||defined(PC98_PWLB)||defined(PC98_TGUI)||defined(PC98_MGA)
+   *(volatile unsigned short *)((char *)mmioBase+(port)) = (unsigned short)(val);
+#else
+   _outw(port,val);
+#endif
+}
+
+static void outb(port,val)
+{
+#if defined(PC98_GANB_WAP) || defined(PC98_NKVNEC) || defined(PC98_WAB) || \
+    defined(PC98_WABEP) || defined(PC98_WSNA) || defined(PC98_PW) || \
+    defined(PC98_XKB) || defined(PC98_NEC)
+   unsigned short tmp;
+   tmp=port_convert(port);
+   port=tmp;
+#endif
+
+#if defined(PC98_NEC)||defined(PC98_PWLB)||defined(PC98_TGUI)||defined(PC98_MGA)
+   *(volatile unsigned char *)((char *)mmioBase+(port)) = (unsigned char)(val);
+#else
+   _outb(port,val);
+#endif
+}
+
+static int inl(port)
+{
+   unsigned int ret;
+
+#if defined(PC98_GANB_WAP) || defined(PC98_NKVNEC) || defined(PC98_WAB) || \
+    defined(PC98_WABEP) || defined(PC98_WSNA) || defined(PC98_PW) || \
+    defined(PC98_XKB) || defined(PC98_NEC)
+   unsigned short tmp;
+   tmp=port_convert(port);
+   port=tmp;
+#endif
+
+#if defined(PC98_NEC)||defined(PC98_PWLB)||defined(PC98_TGUI)||defined(PC98_MGA)
+   ret =*(volatile unsigned int *)((char *)mmioBase+(port));
+#else
+   ret = _inl(port);
+#endif
+   return ret;
+}
+
+static int inw(port)
+{
+   unsigned short ret;
+
+#if defined(PC98_GANB_WAP) || defined(PC98_NKVNEC) || defined(PC98_WAB) || \
+    defined(PC98_WABEP) || defined(PC98_WSNA) || defined(PC98_PW) || \
+    defined(PC98_XKB) || defined(PC98_NEC)
+   unsigned short tmp;
+   tmp=port_convert(port);
+   port=tmp;
+#endif
+
+#if defined(PC98_NEC)||defined(PC98_PWLB)||defined(PC98_TGUI)||defined(PC98_MGA)
+   ret =*(volatile unsigned short *)((char *)mmioBase+(port));
+#else
+   ret = _inw(port);
+#endif
+   return ret;
+}
+
+static int inb(port)
+{
+   unsigned char ret;
+
+#if defined(PC98_GANB_WAP) || defined(PC98_NKVNEC) || defined(PC98_WAB) || \
+    defined(PC98_WABEP) || defined(PC98_WSNA) || defined(PC98_PW) || \
+    defined(PC98_XKB) || defined(PC98_NEC)
+   unsigned short tmp;
+   tmp=port_convert(port);
+   port=tmp;
+#endif
+
+#if defined(PC98_NEC)||defined(PC98_PWLB)||defined(PC98_TGUI)||defined(PC98_MGA)
+   ret =*(volatile unsigned char *)((char *)mmioBase+(port));
+#else
+   ret = _inb(port);
+#endif
+   return ret;
+}
+
+
+# endif /* PC98 */
+# if !defined(__HIGHC__) && !defined(SCO325)
+#  pragma asm partial_optimization outl
+#  pragma asm partial_optimization outw
+#  pragma asm partial_optimization outb
+#  pragma asm partial_optimization inl
+#  pragma asm partial_optimization inw
+#  pragma asm partial_optimization inb
+# endif
+#endif
+#define ldq_u(p)       (*((unsigned long  *)(p)))
+#define ldl_u(p)       (*((unsigned int   *)(p)))
+#define ldw_u(p)       (*((unsigned short *)(p)))
+#define stq_u(v,p)     ((unsigned long  *)(p)) = (v)
+#define stl_u(v,p)     ((unsigned int   *)(p)) = (v)
+#define stw_u(v,p)     ((unsigned short *)(p)) = (v)
+#define mem_barrier()   /* NOP */
+#define write_mem_barrier()   /* NOP */
+#endif /* __GNUC__ */
+
+#if defined(IODEBUG) && defined(__GNUC__)
+#undef inb
+#undef inw
+#undef inl
+#undef outb
+#undef outw
+#undef outl
+#define inb(a) __extension__ ({unsigned char __c=RealInb(a); ErrorF("inb(0x%03x) = 0x%02x\t@ line %4d, file %s\n", a, __c, __LINE__, __FILE__);__c;})
+#define inw(a) __extension__ ({unsigned short __c=RealInw(a); ErrorF("inw(0x%03x) = 0x%04x\t@ line %4d, file %s\n", a, __c, __LINE__, __FILE__);__c;})
+#define inl(a) __extension__ ({unsigned long __c=RealInl(a); ErrorF("inl(0x%03x) = 0x%08x\t@ line %4d, file %s\n", a, __c, __LINE__, __FILE__);__c;})
+
+#define outb(a,b) (ErrorF("outb(0x%03x, 0x%02x)\t@ line %4d, file %s\n", a, b, __LINE__, __FILE__),RealOutb(a,b))
+#define outw(a,b) (ErrorF("outw(0x%03x, 0x%04x)\t@ line %4d, file %s\n", a, b, __LINE__, __FILE__),RealOutw(a,b))
+#define outl(a,b) (ErrorF("outl(0x%03x, 0x%08x)\t@ line %4d, file %s\n", a, b, __LINE__, __FILE__),RealOutl(a,b))
+#endif
+
+/*
+ * This header sometimes gets included where is isn't needed, and on some
+ * OSs this causes problems because the following functions generate
+ * references to inb() and outb() which can't be resolved.  Defining
+ * NO_COMPILER_H_EXTRAS avoids this problem.
+ */
+
+#ifndef NO_COMPILER_H_EXTRAS
+/*
+ *-----------------------------------------------------------------------
+ * Port manipulation convenience functions
+ *-----------------------------------------------------------------------
+ */
+
+#ifndef __GNUC__
+#define __inline__ /**/
+#endif
+
+/*
+ * rdinx - read the indexed byte port 'port', index 'ind', and return its value
+ */
+static __inline__ unsigned char 
+#ifdef __STDC__
+rdinx(unsigned short int port, unsigned char ind)
+#else
+rdinx(port, ind)
+unsigned short int port;
+unsigned char ind;
+#endif
+{
+       if (port == 0x3C0)              /* reset attribute flip-flop */
+               (void) inb(0x3DA);
+       outb(port, ind);
+       return(inb(port+1));
+}
+
+/*
+ * wrinx - write 'val' to port 'port', index 'ind'
+ */
+static __inline__ void 
+#ifdef __STDC__
+wrinx(unsigned short int port, unsigned char ind, unsigned char val)
+#else
+wrinx(port, ind, val)
+unsigned short int port;
+unsigned char ind, val;
+#endif
+{
+       outb(port, ind);
+       outb(port+1, val);
+}
+
+/*
+ * modinx - in register 'port', index 'ind', set the bits in 'mask' as in 'new';
+ *         the other bits are unchanged.
+ */
+static __inline__ void
+#ifdef __STDC__
+modinx(unsigned short int port, unsigned char ind, 
+       unsigned char mask, unsigned char new)
+#else
+modinx(port, ind, mask, new)
+unsigned short int port;
+unsigned char ind, mask, new;
+#endif
+{
+       unsigned char tmp;
+
+       tmp = (rdinx(port, ind) & ~mask) | (new & mask);
+       wrinx(port, ind, tmp);
+}
+
+/*
+ * tstrg - returns true iff the bits in 'mask' of register 'port' are
+ *        readable & writable.
+ */
+
+static __inline__ int
+#ifdef __STDC__
+testrg(unsigned short int port, unsigned char mask)
+#else
+tstrg(port, mask)
+unsigned short int port;
+unsigned char mask;
+#endif
+{
+       unsigned char old, new1, new2;
+
+       old = inb(port);
+       outb(port, old & ~mask);
+       new1 = inb(port) & mask;
+       outb(port, old | mask);
+       new2 = inb(port) & mask;
+       outb(port, old);
+       return((new1 == 0) && (new2 == mask));
+}
+
+/*
+ * testinx2 - returns true iff the bits in 'mask' of register 'port', index
+ *           'ind' are readable & writable.
+ */
+static __inline__ int
+#ifdef __STDC__
+testinx2(unsigned short int port, unsigned char ind, unsigned char mask)
+#else
+testinx2(port, ind, mask)
+unsigned short int port;
+unsigned char ind, mask;
+#endif
+{
+       unsigned char old, new1, new2;
+
+       old = rdinx(port, ind);
+       wrinx(port, ind, old & ~mask);
+       new1 = rdinx(port, ind) & mask;
+       wrinx(port, ind, old | mask);
+       new2 = rdinx(port, ind) & mask;
+       wrinx(port, ind, old);
+       return((new1 == 0) && (new2 == mask));
+}
+
+/*
+ * testinx - returns true iff all bits of register 'port', index 'ind' are 
+ *                  readable & writable.
+ */
+static __inline__ int
+#ifdef __STDC__
+testinx(unsigned short int port, unsigned char ind)
+#else
+testinx(port, ind, mask)
+unsigned short int port;
+unsigned char ind;
+#endif
+{
+       return(testinx2(port, ind, 0xFF));
+}
+#endif /* NO_COMPILER_H_EXTRAS */
+
+#endif /* NO_INLINE */
+#endif /* _COMPILER_H */
diff --git a/Xserver/programs/Xserver/hw/xfree86/common/scoasm.h b/Xserver/programs/Xserver/hw/xfree86/common/scoasm.h
new file mode 100644 (file)
index 0000000..12fe466
--- /dev/null
@@ -0,0 +1,112 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/common/scoasm.h,v 3.0 1996/10/03 08:34:06 dawes Exp $ */
+
+/*
+ * scoasm.h - used to define inline versions of certain functions which
+ * do NOT appear in sys/inline.h.
+ */
+#ifdef SCO325
+#ifndef _SCOASM_HDR_INC
+#define _SCOASM_HDR_INC
+
+asm     void outl(port,val)
+{
+%reg   port,val;
+       movl    port, %edx
+       movl    val, %eax
+       outl    (%dx)
+%reg   port; mem       val;
+       movl    port, %edx
+       movl    val, %eax
+       outl    (%dx)
+%mem   port; reg       val;
+       movw    port, %dx
+       movl    val, %eax
+       outl    (%dx)
+%mem   port,val;
+       movw    port, %dx
+       movl    val, %eax
+       outl    (%dx)
+}
+
+asm    void outw(port,val)
+{
+%reg   port,val;
+       movl    port, %edx
+       movl    val, %eax
+       data16
+       outl    (%dx)
+%reg   port; mem       val;
+       movl    port, %edx
+       movw    val, %ax
+       data16
+       outl    (%dx)
+%mem   port; reg       val;
+       movw    port, %dx
+       movl    val, %eax
+       data16
+       outl    (%dx)
+%mem   port,val;
+       movw    port, %dx
+       movw    val, %ax
+       data16
+       outl    (%dx)
+}
+
+asm    void outb(port,val)
+{
+%reg   port,val;
+       movl    port, %edx
+       movl    val, %eax
+       outb    (%dx)
+%reg   port; mem       val;
+       movl    port, %edx
+       movb    val, %al
+       outb    (%dx)
+%mem   port; reg       val;
+       movw    port, %dx
+       movl    val, %eax
+       outb    (%dx)
+%mem   port,val;
+       movw    port, %dx
+       movb    val, %al
+       outb    (%dx)
+}
+
+asm     int inl(port)
+{
+%reg   port;
+       movl    port, %edx
+       inl     (%dx)
+%mem   port;
+       movw    port, %dx
+       inl     (%dx)
+}
+
+asm    int inw(port)
+{
+%reg   port;
+       subl    %eax, %eax
+       movl    port, %edx
+       data16
+       inl     (%dx)
+%mem   port;
+       subl    %eax, %eax
+       movw    port, %dx
+       data16
+       inl     (%dx)
+}
+
+asm    int inb(port)
+{
+%reg   port;
+       subl    %eax, %eax
+       movl    port, %edx
+       inb     (%dx)
+%mem   port;
+       subl    %eax, %eax
+       movw    port, %dx
+       inb     (%dx)
+}
+
+#endif /* _SCOASM_HDR_INC */
+#endif /* SCO325 */
diff --git a/Xserver/programs/Xserver/include/Imakefile b/Xserver/programs/Xserver/include/Imakefile
new file mode 100644 (file)
index 0000000..5b7d738
--- /dev/null
@@ -0,0 +1,40 @@
+XCOMM $XConsortium: Imakefile,v 1.2 95/01/13 20:28:14 kaleb Exp $
+XCOMM $XFree86: xc/programs/Xserver/include/Imakefile,v 3.5.4.1 1997/05/12 12:52:39 hohndel Exp $
+
+all::
+
+InstallLinkKitNonExecFile(closure.h,$(LINKKITDIR)/include)
+InstallLinkKitNonExecFile(colormap.h,$(LINKKITDIR)/include)
+InstallLinkKitNonExecFile(colormapst.h,$(LINKKITDIR)/include)
+InstallLinkKitNonExecFile(cursor.h,$(LINKKITDIR)/include)
+InstallLinkKitNonExecFile(cursorstr.h,$(LINKKITDIR)/include)
+InstallLinkKitNonExecFile(dix.h,$(LINKKITDIR)/include)
+InstallLinkKitNonExecFile(dixfont.h,$(LINKKITDIR)/include)
+InstallLinkKitNonExecFile(dixfontstr.h,$(LINKKITDIR)/include)
+InstallLinkKitNonExecFile(dixstruct.h,$(LINKKITDIR)/include)
+InstallLinkKitNonExecFile(extension.h,$(LINKKITDIR)/include)
+InstallLinkKitNonExecFile(extnsionst.h,$(LINKKITDIR)/include)
+InstallLinkKitNonExecFile(gc.h,$(LINKKITDIR)/include)
+InstallLinkKitNonExecFile(gcstruct.h,$(LINKKITDIR)/include)
+InstallLinkKitNonExecFile(input.h,$(LINKKITDIR)/include)
+InstallLinkKitNonExecFile(inputstr.h,$(LINKKITDIR)/include)
+InstallLinkKitNonExecFile(misc.h,$(LINKKITDIR)/include)
+InstallLinkKitNonExecFile(miscstruct.h,$(LINKKITDIR)/include)
+InstallLinkKitNonExecFile(opaque.h,$(LINKKITDIR)/include)
+InstallLinkKitNonExecFile(os.h,$(LINKKITDIR)/include)
+InstallLinkKitNonExecFile(pixmap.h,$(LINKKITDIR)/include)
+InstallLinkKitNonExecFile(pixmapstr.h,$(LINKKITDIR)/include)
+InstallLinkKitNonExecFile(property.h,$(LINKKITDIR)/include)
+InstallLinkKitNonExecFile(resource.h,$(LINKKITDIR)/include)
+InstallLinkKitNonExecFile(region.h,$(LINKKITDIR)/include)
+InstallLinkKitNonExecFile(regionstr.h,$(LINKKITDIR)/include)
+InstallLinkKitNonExecFile(screenint.h,$(LINKKITDIR)/include)
+InstallLinkKitNonExecFile(scrnintstr.h,$(LINKKITDIR)/include)
+InstallLinkKitNonExecFile(servermd.h,$(LINKKITDIR)/include)
+InstallLinkKitNonExecFile(site.h,$(LINKKITDIR)/include)
+InstallLinkKitNonExecFile(validate.h,$(LINKKITDIR)/include)
+InstallLinkKitNonExecFile(window.h,$(LINKKITDIR)/include)
+InstallLinkKitNonExecFile(windowstr.h,$(LINKKITDIR)/include)
+
+depend::
+
diff --git a/Xserver/programs/Xserver/include/XIstubs.h b/Xserver/programs/Xserver/include/XIstubs.h
new file mode 100644 (file)
index 0000000..156c4e3
--- /dev/null
@@ -0,0 +1,101 @@
+/* $XFree86: xc/programs/Xserver/include/XIstubs.h,v 3.1 1996/04/15 11:34:22 dawes Exp $ */
+/************************************************************
+
+Copyright 1996 by Thomas E. Dickey <dickey@clark.net>
+
+                        All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and its
+documentation for any purpose and without fee is hereby granted,
+provided that the above copyright notice appear in all copies and that
+both that copyright notice and this permission notice appear in
+supporting documentation, and that the name of the above listed
+copyright holder(s) not be used in advertising or publicity pertaining
+to distribution of the software without specific, written prior
+permission.
+
+THE ABOVE LISTED COPYRIGHT HOLDER(S) DISCLAIM ALL WARRANTIES WITH REGARD
+TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+AND FITNESS, IN NO EVENT SHALL THE ABOVE LISTED COPYRIGHT HOLDER(S) BE
+LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+
+********************************************************/
+
+#ifndef XI_STUBS_H
+#define XI_STUBS_H 1
+
+int
+ChangeKeyboardDevice (
+#if NeedFunctionPrototypes
+       DeviceIntPtr           /* old_dev */,
+       DeviceIntPtr           /* new_dev */
+#endif
+       );
+
+int
+ChangePointerDevice (
+#if NeedFunctionPrototypes
+       DeviceIntPtr           /* old_dev */,
+       DeviceIntPtr           /* new_dev */,
+       unsigned char          /* x */,
+       unsigned char          /* y */
+#endif
+       );
+
+void
+CloseInputDevice (
+#if NeedFunctionPrototypes
+       DeviceIntPtr           /* d */,
+       ClientPtr              /* client */
+#endif
+       );
+
+void
+AddOtherInputDevices (
+#if NeedFunctionPrototypes
+       void
+#endif
+       );
+
+void
+OpenInputDevice (
+#if NeedFunctionPrototypes
+       DeviceIntPtr           /* dev */,
+       ClientPtr              /* client */,
+       int *                  /* status */
+#endif
+       );
+
+int
+SetDeviceMode (
+#if NeedFunctionPrototypes
+       ClientPtr              /* client */,
+       DeviceIntPtr           /* dev */,
+       int                    /* mode */
+#endif
+       );
+
+int
+SetDeviceValuators (
+#if NeedFunctionPrototypes
+       ClientPtr              /* client */,
+       DeviceIntPtr           /* dev */,
+       int *                  /* valuators */,
+       int                    /* first_valuator */,
+       int                    /* num_valuators */
+#endif
+       );
+
+int
+ChangeDeviceControl (
+#if NeedFunctionPrototypes
+       ClientPtr             /* client */,
+       DeviceIntPtr          /* dev */,
+       xDeviceCtl *          /* control */
+#endif
+       );
+
+#endif /* XI_STUBS_H */
diff --git a/Xserver/programs/Xserver/include/closestr.h b/Xserver/programs/Xserver/include/closestr.h
new file mode 100644 (file)
index 0000000..5f481fe
--- /dev/null
@@ -0,0 +1,164 @@
+/* $XConsortium: closestr.h,v 1.10 95/05/19 19:18:55 dpw Exp $ */
+/* $XFree86: xc/programs/Xserver/include/closestr.h,v 3.0 1996/04/15 11:34:23 dawes Exp $ */
+/*
+
+Copyright (c) 1991  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be included
+in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR
+OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall
+not be used in advertising or otherwise to promote the sale, use or
+other dealings in this Software without prior written authorization
+from the X Consortium.
+
+*/
+
+
+#ifndef CLOSESTR_H
+#define CLOSESTR_H
+
+#define        NEED_REPLIES
+#include "Xproto.h"
+#include "closure.h"
+#include "dix.h"
+#include "misc.h"
+#include "gcstruct.h"
+
+/* closure structures */
+
+/* OpenFont */
+
+typedef struct _OFclosure {
+    ClientPtr   client;
+    short       current_fpe;
+    short       num_fpes;
+    FontPathElementPtr *fpe_list;
+    Mask        flags;
+    Bool        slept;
+
+/* XXX -- get these from request buffer instead? */
+    char       *origFontName;
+    int                origFontNameLen;
+    XID         fontid;
+    char       *fontname;
+    int         fnamelen;
+    FontPtr    non_cachable_font;
+}           OFclosureRec;
+
+/* ListFontsWithInfo */
+
+typedef struct _LFWIstate {
+    char       pattern[256];  /* max len of font name */
+    int                patlen;
+    int                current_fpe;
+    int                max_names;
+    Bool       list_started;
+    pointer    private;
+} LFWIstateRec, *LFWIstatePtr;
+
+typedef struct _LFWIclosure {
+    ClientPtr          client;
+    int                        num_fpes;
+    FontPathElementPtr *fpe_list;
+    xListFontsWithInfoReply *reply;
+    int                        length;
+    LFWIstateRec       current;
+    LFWIstateRec       saved;
+    int                        savedNumFonts;
+    Bool               haveSaved;
+    Bool               slept;
+    char               *savedName;
+} LFWIclosureRec;
+
+/* ListFonts */
+
+typedef struct _LFclosure {
+    ClientPtr   client;
+    int         num_fpes;
+    FontPathElementPtr *fpe_list;
+    FontNamesPtr names;
+    LFWIstateRec current;
+    LFWIstateRec saved;
+    Bool        haveSaved;
+    Bool        slept;
+    char       *savedName;
+    int                savedNameLen;
+}      LFclosureRec;
+
+/* PolyText */
+
+typedef
+    int                        (* PolyTextPtr)(
+#if NeedNestedPrototypes
+                       DrawablePtr /* pDraw */,
+                       GCPtr /* pGC */,
+                       int /* x */,
+                       int /* y */,
+                       int /* count */,
+                       void * /* chars or shorts */
+#endif
+                       );
+
+typedef struct _PTclosure {
+    ClientPtr          client;
+    DrawablePtr                pDraw;
+    GC                 *pGC;
+    unsigned char      *pElt;
+    unsigned char      *endReq;
+    unsigned char      *data;
+    int                        xorg;
+    int                        yorg;
+    CARD8              reqType;
+    PolyTextPtr                polyText;
+    int                        itemSize;
+    XID                        did;
+    int                        err;
+    Bool               slept;
+} PTclosureRec;
+
+/* ImageText */
+
+typedef
+    void               (* ImageTextPtr)(
+#if NeedNestedPrototypes
+                       DrawablePtr /* pDraw */,
+                       GCPtr /* pGC */,
+                       int /* x */,
+                       int /* y */,
+                       int /* count */,
+                       void * /* chars or shorts */
+#endif
+                       );
+
+typedef struct _ITclosure {
+    ClientPtr          client;
+    DrawablePtr                pDraw;
+    GC                 *pGC;
+    BYTE               nChars;
+    unsigned char      *data;
+    int                        xorg;
+    int                        yorg;
+    CARD8              reqType;
+    ImageTextPtr       imageText;
+    int                        itemSize;
+    XID                        did;
+    Bool               slept;
+} ITclosureRec;
+#endif                         /* CLOSESTR_H */
diff --git a/Xserver/programs/Xserver/include/closure.h b/Xserver/programs/Xserver/include/closure.h
new file mode 100644 (file)
index 0000000..f834655
--- /dev/null
@@ -0,0 +1,58 @@
+/* $XConsortium: closure.h,v 1.3 94/04/17 20:25:31 gildea Exp $ */
+/***********************************************************
+
+Copyright (c) 1987  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+
+Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
+
+                        All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and its 
+documentation for any purpose and without fee is hereby granted, 
+provided that the above copyright notice appear in all copies and that
+both that copyright notice and this permission notice appear in 
+supporting documentation, and that the name of Digital not be
+used in advertising or publicity pertaining to distribution of the
+software without specific, written prior permission.  
+
+DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
+ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
+DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
+ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+SOFTWARE.
+
+******************************************************************/
+#ifndef CLOSURE_H
+#define CLOSURE_H 1
+
+typedef struct _LFclosure      *LFclosurePtr;
+typedef struct _LFWIclosure    *LFWIclosurePtr;
+typedef struct _OFclosure      *OFclosurePtr;
+typedef struct _PTclosure      *PTclosurePtr;
+typedef struct _ITclosure      *ITclosurePtr;
+
+#endif /* CLOSURE_H */
diff --git a/Xserver/programs/Xserver/include/colormap.h b/Xserver/programs/Xserver/include/colormap.h
new file mode 100644 (file)
index 0000000..a8ced99
--- /dev/null
@@ -0,0 +1,239 @@
+/*
+
+Copyright (c) 1987  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+
+Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
+
+                        All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and its 
+documentation for any purpose and without fee is hereby granted, 
+provided that the above copyright notice appear in all copies and that
+both that copyright notice and this permission notice appear in 
+supporting documentation, and that the name of Digital not be
+used in advertising or publicity pertaining to distribution of the
+software without specific, written prior permission.  
+
+DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
+ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
+DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
+ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+SOFTWARE.
+
+*/
+/* $XConsortium: colormap.h,v 1.28 94/04/17 20:25:32 dpw Exp $ */
+
+
+
+
+/* $XFree86: xc/programs/Xserver/include/colormap.h,v 1.2 1997/01/14 22:22:38 dawes Exp $ */
+#ifndef CMAP_H
+#define CMAP_H 1
+
+#include "X11/Xproto.h"
+#include "screenint.h"
+#include "window.h"
+
+/* these follow X.h's AllocNone and AllocAll */
+#define CM_PSCREEN 2
+#define CM_PWIN           3
+/* Passed internally in colormap.c */
+#define REDMAP 0
+#define GREENMAP 1
+#define BLUEMAP 2
+#define PSEUDOMAP 3
+#define AllocPrivate (-1)
+#define AllocTemporary (-2)
+#define DynamicClass  1
+
+/* Values for the flags field of a colormap. These should have 1 bit set
+ * and not overlap */
+#define IsDefault 1
+#define AllAllocated 2
+#define BeingCreated 4
+
+
+typedef CARD32 Pixel;
+typedef struct _CMEntry *EntryPtr;
+/* moved to screenint.h: typedef struct _ColormapRec *ColormapPtr */
+typedef struct _colorResource *colorResourcePtr;
+
+extern int CreateColormap(
+#if NeedFunctionPrototypes
+    Colormap /*mid*/,
+    ScreenPtr /*pScreen*/,
+    VisualPtr /*pVisual*/,
+    ColormapPtr* /*ppcmap*/,
+    int /*alloc*/,
+    int /*client*/
+#endif
+);
+
+extern int FreeColormap(
+#if NeedFunctionPrototypes
+    pointer /*pmap*/,
+    XID /*mid*/
+#endif
+);
+
+extern int TellLostMap(
+#if NeedFunctionPrototypes
+    WindowPtr /*pwin*/,
+    pointer /* Colormap *pmid */
+#endif
+);
+
+extern int TellGainedMap(
+#if NeedFunctionPrototypes
+    WindowPtr /*pwin*/,
+    pointer /* Colormap *pmid */
+#endif
+);
+
+extern int CopyColormapAndFree(
+#if NeedFunctionPrototypes
+    Colormap /*mid*/,
+    ColormapPtr /*pSrc*/,
+    int /*client*/
+#endif
+);
+
+extern int AllocColor(
+#if NeedFunctionPrototypes
+    ColormapPtr /*pmap*/,
+    unsigned short* /*pred*/,
+    unsigned short* /*pgreen*/,
+    unsigned short* /*pblue*/,
+    Pixel* /*pPix*/,
+    int /*client*/
+#endif
+);
+
+extern void FakeAllocColor(
+#if NeedFunctionPrototypes
+    ColormapPtr /*pmap*/,
+    xColorItem * /*item*/
+#endif
+);
+
+extern void FakeFreeColor(
+#if NeedFunctionPrototypes
+    ColormapPtr /*pmap*/,
+    Pixel /*pixel*/
+#endif
+);
+
+typedef int (*ColorCompareProcPtr)(
+#if NeedNestedPrototypes
+    EntryPtr /*pent*/,
+    xrgb * /*prgb*/
+#endif
+);
+
+extern int FindColor(
+#if NeedFunctionPrototypes
+    ColormapPtr /*pmap*/,
+    EntryPtr /*pentFirst*/,
+    int /*size*/,
+    xrgb* /*prgb*/,
+    Pixel* /*pPixel*/,
+    int /*channel*/,
+    int /*client*/,
+    ColorCompareProcPtr /*comp*/
+#endif
+);
+
+extern int QueryColors(
+#if NeedFunctionPrototypes
+    ColormapPtr /*pmap*/,
+    int /*count*/,
+    Pixel* /*ppixIn*/,
+    xrgb* /*prgbList*/
+#endif
+);
+
+extern int FreeClientPixels(
+#if NeedFunctionPrototypes
+    pointer /*pcr*/,
+    XID /*fakeid*/
+#endif
+);
+
+extern int AllocColorCells(
+#if NeedFunctionPrototypes
+    int /*client*/,
+    ColormapPtr /*pmap*/,
+    int /*colors*/,
+    int /*planes*/,
+    Bool /*contig*/,
+    Pixel* /*ppix*/,
+    Pixel* /*masks*/
+#endif
+);
+
+extern int AllocColorPlanes(
+#if NeedFunctionPrototypes
+    int /*client*/,
+    ColormapPtr /*pmap*/,
+    int /*colors*/,
+    int /*r*/,
+    int /*g*/,
+    int /*b*/,
+    Bool /*contig*/,
+    Pixel* /*pixels*/,
+    Pixel* /*prmask*/,
+    Pixel* /*pgmask*/,
+    Pixel* /*pbmask*/
+#endif
+);
+
+extern int FreeColors(
+#if NeedFunctionPrototypes
+    ColormapPtr /*pmap*/,
+    int /*client*/,
+    int /*count*/,
+    Pixel* /*pixels*/,
+    Pixel /*mask*/
+#endif
+);
+
+extern int StoreColors(
+#if NeedFunctionPrototypes
+    ColormapPtr /*pmap*/,
+    int /*count*/,
+    xColorItem* /*defs*/
+#endif
+);
+
+extern int IsMapInstalled(
+#if NeedFunctionPrototypes
+    Colormap /*map*/,
+    WindowPtr /*pWin*/
+#endif
+);
+
+#endif /* CMAP_H */
diff --git a/Xserver/programs/Xserver/include/colormapst.h b/Xserver/programs/Xserver/include/colormapst.h
new file mode 100644 (file)
index 0000000..d160a69
--- /dev/null
@@ -0,0 +1,125 @@
+/*
+
+Copyright (c) 1987  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+
+Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
+
+                        All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and its 
+documentation for any purpose and without fee is hereby granted, 
+provided that the above copyright notice appear in all copies and that
+both that copyright notice and this permission notice appear in 
+supporting documentation, and that the name of Digital not be
+used in advertising or publicity pertaining to distribution of the
+software without specific, written prior permission.  
+
+DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
+ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
+DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
+ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+SOFTWARE.
+
+*/
+/* $XConsortium: colormapst.h /main/4 1996/06/17 10:54:31 mor $ */
+#ifndef CMAPSTRUCT_H
+#define CMAPSTRUCT_H 1
+
+#include "colormap.h"
+#include "screenint.h"
+
+/* Shared color -- the color is used by AllocColorPlanes */
+typedef struct
+{
+    unsigned short color;
+    short  refcnt;
+} SHAREDCOLOR;
+
+/* LOCO -- a local color for a PseudoColor cell. DirectColor maps always
+ * use the first value (called red) in the structure.  What channel they
+ * are really talking about depends on which map they are in. */
+typedef struct
+{
+    unsigned short     red, green, blue;
+} LOCO;
+
+/* SHCO -- a shared color for a PseudoColor cell. Used with AllocColorPlanes.
+ * DirectColor maps always use the first value (called red) in the structure.
+ * What channel they are really talking about depends on which map they
+ * are in. */
+typedef struct 
+{
+    SHAREDCOLOR *red, *green, *blue;
+} SHCO;
+
+
+/* color map entry */
+typedef struct _CMEntry
+{
+    union
+    {
+       LOCO    local;
+       SHCO    shco;
+    } co;
+    short      refcnt;
+    Bool       fShared;
+} Entry;
+
+/* COLORMAPs can be used for either Direct or Pseudo color.  PseudoColor
+ * only needs one cell table, we arbitrarily pick red.  We keep track
+ * of that table with freeRed, numPixelsRed, and clientPixelsRed */
+
+typedef struct _ColormapRec
+{
+    VisualPtr  pVisual;
+#if defined(__cplusplus) || defined(c_plusplus)
+    short       c_class;
+#else
+    short      class;          /* PseudoColor or DirectColor */
+#endif
+    long       mid;            /* client's name for colormap */
+    ScreenPtr  pScreen;        /* screen map is associated with */
+    short      flags;          /* 1 = IsDefault
+                                * 2 = AllAllocated */
+    int                freeRed;
+    int                freeGreen;
+    int                freeBlue;
+    int                *numPixelsRed;  
+    int                *numPixelsGreen;        
+    int                *numPixelsBlue; 
+    Pixel      **clientPixelsRed;
+    Pixel      **clientPixelsGreen;
+    Pixel      **clientPixelsBlue;
+    Entry      *red;
+    Entry      *green;
+    Entry      *blue;
+    pointer    devPriv;
+    DevUnion   *devPrivates;   /* dynamic devPrivates added after devPriv
+                                  already existed - must keep devPriv */
+} ColormapRec;
+             
+#endif /* COLORMAP_H */
diff --git a/Xserver/programs/Xserver/include/cursor.h b/Xserver/programs/Xserver/include/cursor.h
new file mode 100644 (file)
index 0000000..c583a37
--- /dev/null
@@ -0,0 +1,152 @@
+/***********************************************************
+
+Copyright (c) 1987  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+
+Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
+
+                        All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and its 
+documentation for any purpose and without fee is hereby granted, 
+provided that the above copyright notice appear in all copies and that
+both that copyright notice and this permission notice appear in 
+supporting documentation, and that the name of Digital not be
+used in advertising or publicity pertaining to distribution of the
+software without specific, written prior permission.  
+
+DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
+ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
+DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
+ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+SOFTWARE.
+
+******************************************************************/
+/* $XConsortium: cursor.h,v 1.22 94/04/17 20:25:34 dpw Exp $ */
+#ifndef CURSOR_H
+#define CURSOR_H 
+
+#include "misc.h"
+#include "screenint.h"
+#include "window.h"
+
+#define NullCursor ((CursorPtr)NULL)
+
+typedef struct _Cursor *CursorPtr;
+typedef struct _CursorMetric *CursorMetricPtr;
+
+extern CursorPtr rootCursor;
+
+extern int FreeCursor(
+#if NeedFunctionPrototypes
+    pointer /*pCurs*/,
+    XID /*cid*/
+#endif
+);
+
+extern CursorPtr AllocCursor(
+#if NeedFunctionPrototypes
+    unsigned char* /*psrcbits*/,
+    unsigned char* /*pmaskbits*/,
+    CursorMetricPtr /*cm*/,
+    unsigned /*foreRed*/,
+    unsigned /*foreGreen*/,
+    unsigned /*foreBlue*/,
+    unsigned /*backRed*/,
+    unsigned /*backGreen*/,
+    unsigned /*backBlue*/
+#endif
+);
+
+extern int AllocGlyphCursor(
+#if NeedFunctionPrototypes
+    Font /*source*/,
+    unsigned int /*sourceChar*/,
+    Font /*mask*/,
+    unsigned int /*maskChar*/,
+    unsigned /*foreRed*/,
+    unsigned /*foreGreen*/,
+    unsigned /*foreBlue*/,
+    unsigned /*backRed*/,
+    unsigned /*backGreen*/,
+    unsigned /*backBlue*/,
+    CursorPtr* /*ppCurs*/,
+    ClientPtr /*client*/
+#endif
+);
+
+extern CursorPtr CreateRootCursor(
+#if NeedFunctionPrototypes
+    char* /*pfilename*/,
+    unsigned int /*glyph*/
+#endif
+);
+
+extern int ServerBitsFromGlyph(
+#if NeedFunctionPrototypes
+    FontPtr /*pfont*/,
+    unsigned int /*ch*/,
+    register CursorMetricPtr /*cm*/,
+    unsigned char ** /*ppbits*/
+#endif
+);
+
+extern Bool CursorMetricsFromGlyph(
+#if NeedFunctionPrototypes
+    FontPtr /*pfont*/,
+    unsigned /*ch*/,
+    CursorMetricPtr /*cm*/
+#endif
+);
+
+extern void CheckCursorConfinement(
+#if NeedFunctionPrototypes
+    WindowPtr /*pWin*/
+#endif
+);
+
+extern void NewCurrentScreen(
+#if NeedFunctionPrototypes
+    ScreenPtr /*newScreen*/,
+    int /*x*/,
+    int /*y*/
+#endif
+);
+
+extern Bool PointerConfinedToScreen(
+#if NeedFunctionPrototypes
+    void
+#endif
+);
+
+extern void GetSpritePosition(
+#if NeedFunctionPrototypes
+    int * /*px*/,
+    int * /*py*/
+#endif
+);
+
+#endif /* CURSOR_H */
diff --git a/Xserver/programs/Xserver/include/cursorstr.h b/Xserver/programs/Xserver/include/cursorstr.h
new file mode 100644 (file)
index 0000000..83b3ab6
--- /dev/null
@@ -0,0 +1,81 @@
+/* $XConsortium: cursorstr.h,v 1.8 94/04/17 20:25:35 dpw Exp $ */
+/***********************************************************
+
+Copyright (c) 1987  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+
+Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
+
+                        All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and its 
+documentation for any purpose and without fee is hereby granted, 
+provided that the above copyright notice appear in all copies and that
+both that copyright notice and this permission notice appear in 
+supporting documentation, and that the name of Digital not be
+used in advertising or publicity pertaining to distribution of the
+software without specific, written prior permission.  
+
+DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
+ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
+DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
+ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+SOFTWARE.
+
+******************************************************************/
+#ifndef CURSORSTRUCT_H
+#define CURSORSTRUCT_H 
+
+#include "cursor.h"
+/* 
+ * device-independent cursor storage
+ */
+
+/*
+ * source and mask point directly to the bits, which are in the server-defined
+ * bitmap format.
+ */
+typedef struct _CursorBits {
+    unsigned char *source;                     /* points to bits */
+    unsigned char *mask;                       /* points to bits */
+    unsigned short width, height, xhot, yhot;  /* metrics */
+    int refcnt;                                        /* can be shared */
+    pointer devPriv[MAXSCREENS];               /* set by pScr->RealizeCursor*/
+} CursorBits, *CursorBitsPtr;
+
+typedef struct _Cursor {
+    CursorBitsPtr bits;
+    unsigned short foreRed, foreGreen, foreBlue; /* device-independent color */
+    unsigned short backRed, backGreen, backBlue; /* device-independent color */
+    int refcnt;
+    pointer devPriv[MAXSCREENS];               /* set by pScr->RealizeCursor*/
+} CursorRec;
+
+typedef struct _CursorMetric {
+    unsigned short width, height, xhot, yhot;
+} CursorMetricRec;
+
+#endif /* CURSORSTRUCT_H */
diff --git a/Xserver/programs/Xserver/include/dix.h b/Xserver/programs/Xserver/include/dix.h
new file mode 100644 (file)
index 0000000..9c7d69f
--- /dev/null
@@ -0,0 +1,1103 @@
+/***********************************************************
+
+Copyright (c) 1987  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+
+Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
+
+                        All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and its 
+documentation for any purpose and without fee is hereby granted, 
+provided that the above copyright notice appear in all copies and that
+both that copyright notice and this permission notice appear in 
+supporting documentation, and that the name of Digital not be
+used in advertising or publicity pertaining to distribution of the
+software without specific, written prior permission.  
+
+DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
+ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
+DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
+ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+SOFTWARE.
+
+******************************************************************/
+/* $XConsortium: dix.h /main/44 1996/12/15 21:24:57 rws $ */
+/* $XFree86: xc/programs/Xserver/include/dix.h,v 3.7 1996/12/31 04:17:46 dawes Exp $ */
+
+#ifndef DIX_H
+#define DIX_H
+
+#include "gc.h"
+#include "window.h"
+#include "input.h"
+
+#define EARLIER -1
+#define SAMETIME 0
+#define LATER 1
+
+#define NullClient ((ClientPtr) 0)
+#define REQUEST(type) \
+       register type *stuff = (type *)client->requestBuffer
+
+
+#define REQUEST_SIZE_MATCH(req)\
+    if ((sizeof(req) >> 2) != client->req_len)\
+         return(BadLength)
+
+#define REQUEST_AT_LEAST_SIZE(req) \
+    if ((sizeof(req) >> 2) > client->req_len )\
+         return(BadLength)
+
+#define REQUEST_FIXED_SIZE(req, n)\
+    if (((sizeof(req) >> 2) > client->req_len) || \
+        (((sizeof(req) + (n) + 3) >> 2) != client->req_len)) \
+         return(BadLength)
+
+#define LEGAL_NEW_RESOURCE(id,client)\
+    if (!LegalNewID(id,client)) \
+    {\
+       client->errorValue = id;\
+        return(BadIDChoice);\
+    }
+
+/* XXX if you are using this macro, you are probably not generating Match
+ * errors where appropriate */
+#define LOOKUP_DRAWABLE(did, client)\
+    ((client->lastDrawableID == did) ? \
+     client->lastDrawable : (DrawablePtr)LookupDrawable(did, client))
+
+#ifdef XCSECURITY
+
+#define SECURITY_VERIFY_DRAWABLE(pDraw, did, client, mode)\
+    if (client->lastDrawableID == did && !client->trustLevel)\
+       pDraw = client->lastDrawable;\
+    else \
+    {\
+       pDraw = (DrawablePtr) SecurityLookupIDByClass(client, did, \
+                                                     RC_DRAWABLE, mode);\
+       if (!pDraw) \
+       {\
+           client->errorValue = did; \
+           return BadDrawable;\
+       }\
+       if (pDraw->type == UNDRAWABLE_WINDOW)\
+           return BadMatch;\
+    }
+
+#define SECURITY_VERIFY_GEOMETRABLE(pDraw, did, client, mode)\
+    if (client->lastDrawableID == did && !client->trustLevel)\
+       pDraw = client->lastDrawable;\
+    else \
+    {\
+       pDraw = (DrawablePtr) SecurityLookupIDByClass(client, did, \
+                                                     RC_DRAWABLE, mode);\
+       if (!pDraw) \
+       {\
+           client->errorValue = did; \
+           return BadDrawable;\
+       }\
+    }
+
+#define SECURITY_VERIFY_GC(pGC, rid, client, mode)\
+    if (client->lastGCID == rid && !client->trustLevel)\
+        pGC = client->lastGC;\
+    else\
+       pGC = (GC *) SecurityLookupIDByType(client, rid, RT_GC, mode);\
+    if (!pGC)\
+    {\
+       client->errorValue = rid;\
+       return (BadGC);\
+    }
+
+#define VERIFY_DRAWABLE(pDraw, did, client)\
+       SECURITY_VERIFY_DRAWABLE(pDraw, did, client, SecurityUnknownAccess)
+
+#define VERIFY_GEOMETRABLE(pDraw, did, client)\
+       SECURITY_VERIFY_GEOMETRABLE(pDraw, did, client, SecurityUnknownAccess)
+
+#define VERIFY_GC(pGC, rid, client)\
+       SECURITY_VERIFY_GC(pGC, rid, client, SecurityUnknownAccess)
+
+#else /* not XCSECURITY */
+
+#define VERIFY_DRAWABLE(pDraw, did, client)\
+    if (client->lastDrawableID == did)\
+       pDraw = client->lastDrawable;\
+    else \
+    {\
+       pDraw = (DrawablePtr) LookupIDByClass(did, RC_DRAWABLE);\
+       if (!pDraw) \
+       {\
+           client->errorValue = did; \
+           return BadDrawable;\
+       }\
+       if (pDraw->type == UNDRAWABLE_WINDOW)\
+           return BadMatch;\
+    }
+
+#define VERIFY_GEOMETRABLE(pDraw, did, client)\
+    if (client->lastDrawableID == did)\
+       pDraw = client->lastDrawable;\
+    else \
+    {\
+       pDraw = (DrawablePtr) LookupIDByClass(did, RC_DRAWABLE);\
+       if (!pDraw) \
+       {\
+           client->errorValue = did; \
+           return BadDrawable;\
+       }\
+    }
+
+#define VERIFY_GC(pGC, rid, client)\
+    if (client->lastGCID == rid)\
+        pGC = client->lastGC;\
+    else\
+       pGC = (GC *)LookupIDByType(rid, RT_GC);\
+    if (!pGC)\
+    {\
+       client->errorValue = rid;\
+       return (BadGC);\
+    }
+
+#define SECURITY_VERIFY_DRAWABLE(pDraw, did, client, mode)\
+       VERIFY_DRAWABLE(pDraw, did, client)
+
+#define SECURITY_VERIFY_GEOMETRABLE(pDraw, did, client, mode)\
+       VERIFY_GEOMETRABLE(pDraw, did, client)
+
+#define SECURITY_VERIFY_GC(pGC, rid, client, mode)\
+       VERIFY_GC(pGC, rid, client)
+
+#endif /* XCSECURITY */
+
+/*
+ * We think that most hardware implementations of DBE will want
+ * LookupID*(dbe_back_buffer_id) to return the window structure that the
+ * id is a back buffer for.  Since both front and back buffers will
+ * return the same structure, you need to be able to distinguish
+ * somewhere what kind of buffer (front/back) was being asked for, so
+ * that ddx can render to the right place.  That's the problem that the
+ * following code solves.  Note: we couldn't embed this in the LookupID*
+ * functions because the VALIDATE_DRAWABLE_AND_GC macro often circumvents
+ * those functions by checking a one-element cache.  That's why we're
+ * mucking with VALIDATE_DRAWABLE_AND_GC.
+ * 
+ * If you put -DNEED_DBE_BUF_BITS into PervasiveDBEDefines, the window
+ * structure will have two additional bits defined, srcBuffer and
+ * dstBuffer, and their values will be maintained via the macros
+ * SET_DBE_DSTBUF and SET_DBE_SRCBUF (below).  If you also
+ * put -DNEED_DBE_BUF_VALIDATE into PervasiveDBEDefines, the function
+ * DbeValidateBuffer will be called any time the bits change to give you
+ * a chance to do some setup.  See the DBE code for more details on this
+ * function.  We put in these levels of conditionality so that you can do
+ * just what you need to do, and no more.  If neither of these defines
+ * are used, the bits won't be there, and VALIDATE_DRAWABLE_AND_GC will
+ * be unchanged.       dpw
+ */
+
+#if defined(NEED_DBE_BUF_BITS)
+#define SET_DBE_DSTBUF(_pDraw, _drawID) \
+        SET_DBE_BUF(_pDraw, _drawID, dstBuffer, TRUE)
+#define SET_DBE_SRCBUF(_pDraw, _drawID) \
+        SET_DBE_BUF(_pDraw, _drawID, srcBuffer, FALSE)
+#if defined (NEED_DBE_BUF_VALIDATE)
+#define SET_DBE_BUF(_pDraw, _drawID, _whichBuffer, _dstbuf) \
+    if (_pDraw->type == DRAWABLE_WINDOW)\
+    {\
+       int thisbuf = (_pDraw->id == _drawID);\
+       if (thisbuf != ((WindowPtr)_pDraw)->_whichBuffer)\
+       {\
+            ((WindowPtr)_pDraw)->_whichBuffer = thisbuf;\
+            DbeValidateBuffer((WindowPtr)_pDraw, _drawID, _dstbuf);\
+       }\
+     }
+#else /* want buffer bits, but don't need to call DbeValidateBuffer */
+#define SET_DBE_BUF(_pDraw, _drawID, _whichBuffer, _dstbuf) \
+    if (_pDraw->type == DRAWABLE_WINDOW)\
+    {\
+       ((WindowPtr)_pDraw)->_whichBuffer = (_pDraw->id == _drawID);\
+    }
+#endif /* NEED_DBE_BUF_VALIDATE */
+#else /* don't want buffer bits in window */
+#define SET_DBE_DSTBUF(_pDraw, _drawID) /**/
+#define SET_DBE_SRCBUF(_pDraw, _drawID) /**/
+#endif /* NEED_DBE_BUF_BITS */
+
+#define VALIDATE_DRAWABLE_AND_GC(drawID, pDraw, pGC, client)\
+    if ((stuff->gc == INVALID) || (client->lastGCID != stuff->gc) ||\
+       (client->lastDrawableID != drawID))\
+    {\
+       SECURITY_VERIFY_GEOMETRABLE(pDraw, drawID, client, SecurityWriteAccess);\
+       SECURITY_VERIFY_GC(pGC, stuff->gc, client, SecurityReadAccess);\
+       if ((pGC->depth != pDraw->depth) ||\
+           (pGC->pScreen != pDraw->pScreen))\
+           return (BadMatch);\
+       client->lastDrawable = pDraw;\
+       client->lastDrawableID = drawID;\
+       client->lastGC = pGC;\
+       client->lastGCID = stuff->gc;\
+    }\
+    else\
+    {\
+        pGC = client->lastGC;\
+        pDraw = client->lastDrawable;\
+    }\
+    SET_DBE_DSTBUF(pDraw, drawID);\
+    if (pGC->serialNumber != pDraw->serialNumber)\
+       ValidateGC(pDraw, pGC);
+
+
+#define WriteReplyToClient(pClient, size, pReply) \
+   if ((pClient)->swapped) \
+      (*ReplySwapVector[((xReq *)(pClient)->requestBuffer)->reqType]) \
+           (pClient, (int)(size), pReply); \
+      else (void) WriteToClient(pClient, (int)(size), (char *)(pReply));
+
+#define WriteSwappedDataToClient(pClient, size, pbuf) \
+   if ((pClient)->swapped) \
+      (*(pClient)->pSwapReplyFunc)(pClient, (int)(size), pbuf); \
+   else (void) WriteToClient (pClient, (int)(size), (char *)(pbuf));
+
+typedef struct _TimeStamp *TimeStampPtr;
+
+#ifndef _XTYPEDEF_CLIENTPTR
+typedef struct _Client *ClientPtr; /* also in misc.h */
+#define _XTYPEDEF_CLIENTPTR
+#endif
+
+typedef struct _WorkQueue      *WorkQueuePtr;
+
+extern ClientPtr requestingClient;
+extern ClientPtr *clients;
+extern ClientPtr serverClient;
+extern int currentMaxClients;
+
+#if !(defined(__alpha) || defined(__alpha__))
+typedef long HWEventQueueType;
+#else
+typedef int HWEventQueueType;
+#endif
+typedef HWEventQueueType* HWEventQueuePtr;
+
+extern HWEventQueuePtr checkForInput[2];
+
+typedef struct _TimeStamp {
+    CARD32 months;     /* really ~49.7 days */
+    CARD32 milliseconds;
+}           TimeStamp;
+
+/* dispatch.c */
+
+extern void SetInputCheck(
+#if NeedFunctionPrototypes
+    HWEventQueuePtr /*c0*/,
+    HWEventQueuePtr /*c1*/
+#endif
+);
+
+extern void CloseDownClient(
+#if NeedFunctionPrototypes
+    ClientPtr /*client*/
+#endif
+);
+
+extern void UpdateCurrentTime(
+#if NeedFunctionPrototypes
+    void
+#endif
+);
+
+extern void UpdateCurrentTimeIf(
+#if NeedFunctionPrototypes
+    void
+#endif
+);
+
+extern void InitSelections(
+#if NeedFunctionPrototypes
+    void
+#endif
+);
+
+extern void FlushClientCaches(
+#if NeedFunctionPrototypes
+    XID /*id*/
+#endif
+);
+
+extern int dixDestroyPixmap(
+#if NeedFunctionPrototypes
+    pointer /*value*/,
+    XID /*pid*/
+#endif
+);
+
+extern void CloseDownRetainedResources(
+#if NeedFunctionPrototypes
+    void
+#endif
+);
+
+extern void InitClient(
+#if NeedFunctionPrototypes
+    ClientPtr /*client*/,
+    int /*i*/,
+    pointer /*ospriv*/
+#endif
+);
+
+extern ClientPtr NextAvailableClient(
+#if NeedFunctionPrototypes
+    pointer /*ospriv*/
+#endif
+);
+
+extern void SendErrorToClient(
+#if NeedFunctionPrototypes
+    ClientPtr /*client*/,
+    unsigned int /*majorCode*/,
+    unsigned int /*minorCode*/,
+    XID /*resId*/,
+    int /*errorCode*/
+#endif
+);
+
+extern void DeleteWindowFromAnySelections(
+#if NeedFunctionPrototypes
+    WindowPtr /*pWin*/
+#endif
+);
+
+extern void MarkClientException(
+#if NeedFunctionPrototypes
+    ClientPtr /*client*/
+#endif
+);
+
+extern int GetGeometry(
+#if NeedFunctionPrototypes
+    ClientPtr /*client*/,
+    xGetGeometryReply* /* wa */
+#endif
+);
+
+/* dixutils.c */
+
+extern void CopyISOLatin1Lowered(
+#if NeedFunctionPrototypes
+    unsigned char * /*dest*/,
+    unsigned char * /*source*/,
+    int /*length*/
+#endif
+);
+
+#ifdef XCSECURITY
+
+extern WindowPtr SecurityLookupWindow(
+#if NeedFunctionPrototypes
+    XID /*rid*/,
+    ClientPtr /*client*/,
+    Mask /*access_mode*/
+#endif
+);
+
+extern pointer SecurityLookupDrawable(
+#if NeedFunctionPrototypes
+    XID /*rid*/,
+    ClientPtr /*client*/,
+    Mask /*access_mode*/
+#endif
+);
+
+extern WindowPtr LookupWindow(
+#if NeedFunctionPrototypes
+    XID /*rid*/,
+    ClientPtr /*client*/
+#endif
+);
+
+extern pointer LookupDrawable(
+#if NeedFunctionPrototypes
+    XID /*rid*/,
+    ClientPtr /*client*/
+#endif
+);
+
+#else
+
+extern WindowPtr LookupWindow(
+#if NeedFunctionPrototypes
+    XID /*rid*/,
+    ClientPtr /*client*/
+#endif
+);
+
+extern pointer LookupDrawable(
+#if NeedFunctionPrototypes
+    XID /*rid*/,
+    ClientPtr /*client*/
+#endif
+);
+
+#define SecurityLookupWindow(rid, client, access_mode) \
+       LookupWindow(rid, client)
+
+#define SecurityLookupDrawable(rid, client, access_mode) \
+       LookupDrawable(rid, client)
+
+#endif /* XCSECURITY */
+
+extern ClientPtr LookupClient(
+#if NeedFunctionPrototypes
+    XID /*rid*/,
+    ClientPtr /*client*/
+#endif
+);
+
+extern void NoopDDA(
+#if NeedVarargsPrototypes
+    void *,
+    ...
+#endif
+);
+
+extern int AlterSaveSetForClient(
+#if NeedFunctionPrototypes
+    ClientPtr /*client*/,
+    WindowPtr /*pWin*/,
+    unsigned /*mode*/
+#endif
+);
+
+extern void DeleteWindowFromAnySaveSet(
+#if NeedFunctionPrototypes
+    WindowPtr /*pWin*/
+#endif
+);
+
+extern void BlockHandler(
+#if NeedFunctionPrototypes
+    pointer /*pTimeout*/,
+    pointer /*pReadmask*/
+#endif
+);
+
+extern void WakeupHandler(
+#if NeedFunctionPrototypes
+    int /*result*/,
+    pointer /*pReadmask*/
+#endif
+);
+
+typedef struct timeval ** OSTimePtr;
+
+typedef void (* BlockHandlerProcPtr)(
+#if NeedNestedPrototypes
+    pointer /* blockData */,
+    OSTimePtr /* pTimeout */,
+    pointer /* pReadmask */
+#endif
+);
+
+typedef void (* WakeupHandlerProcPtr)(
+#if NeedNestedPrototypes
+    pointer /* blockData */,
+    int /* result */,
+    pointer /* pReadmask */
+#endif
+);
+
+extern Bool RegisterBlockAndWakeupHandlers(
+#if NeedFunctionPrototypes
+    BlockHandlerProcPtr /*blockHandler*/,
+    WakeupHandlerProcPtr /*wakeupHandler*/,
+    pointer /*blockData*/
+#endif
+);
+
+extern void RemoveBlockAndWakeupHandlers(
+#if NeedFunctionPrototypes
+    BlockHandlerProcPtr /*blockHandler*/,
+    WakeupHandlerProcPtr /*wakeupHandler*/,
+    pointer /*blockData*/
+#endif
+);
+
+extern void InitBlockAndWakeupHandlers(
+#if NeedFunctionPrototypes
+    void
+#endif
+);
+
+extern void ProcessWorkQueue(
+#if NeedFunctionPrototypes
+    void
+#endif
+);
+
+extern Bool QueueWorkProc(
+#if NeedFunctionPrototypes
+    Bool (* /*function*/)(
+#if NeedNestedPrototypes
+        ClientPtr /*clientUnused*/,
+        pointer /*closure*/
+#endif
+        ),
+    ClientPtr /*client*/,
+    pointer /*closure*/
+#endif
+);
+
+typedef Bool (* ClientSleepProcPtr)(
+#if NeedFunctionPrototypes
+    ClientPtr /*client*/,
+    pointer /*closure*/
+#endif
+);
+
+extern Bool ClientSleep(
+#if NeedFunctionPrototypes
+    ClientPtr /*client*/,
+    ClientSleepProcPtr /* function */,
+    pointer /*closure*/
+#endif
+);
+
+extern Bool ClientSignal(
+#if NeedFunctionPrototypes
+    ClientPtr /*client*/
+#endif
+);
+
+extern void ClientWakeup(
+#if NeedFunctionPrototypes
+    ClientPtr /*client*/
+#endif
+);
+
+extern Bool ClientIsAsleep(
+#if NeedFunctionPrototypes
+    ClientPtr /*client*/
+#endif
+);
+
+/* atom.c */
+
+extern Atom MakeAtom(
+#if NeedFunctionPrototypes
+    char * /*string*/,
+    unsigned /*len*/,
+    Bool /*makeit*/
+#endif
+);
+
+extern Bool ValidAtom(
+#if NeedFunctionPrototypes
+    Atom /*atom*/
+#endif
+);
+
+extern char *NameForAtom(
+#if NeedFunctionPrototypes
+    Atom /*atom*/
+#endif
+);
+
+extern void AtomError(
+#if NeedFunctionPrototypes
+    void
+#endif
+);
+
+extern void FreeAllAtoms(
+#if NeedFunctionPrototypes
+    void
+#endif
+);
+
+extern void InitAtoms(
+#if NeedFunctionPrototypes
+    void
+#endif
+);
+
+/* events.c */
+
+extern void SetMaskForEvent(
+#if NeedFunctionPrototypes
+    Mask /* mask */,
+    int /* event */
+#endif
+);
+
+extern Bool PointerConfinedToScreen(
+#if NeedFunctionPrototypes
+    void
+#endif
+);
+
+extern Bool IsParent(
+#if NeedFunctionPrototypes
+    WindowPtr /* maybeparent */,
+    WindowPtr /* child */
+#endif
+);
+
+extern WindowPtr GetCurrentRootWindow(
+#if NeedFunctionPrototypes
+    void
+#endif
+);
+
+extern WindowPtr GetSpriteWindow(
+#if NeedFunctionPrototypes
+    void
+#endif
+);
+
+extern void GetSpritePosition(
+#if NeedFunctionPrototypes
+    int * /* px */,
+    int * /* py */
+#endif
+);
+
+extern void NoticeEventTime(
+#if NeedFunctionPrototypes
+    xEventPtr /* xE */
+#endif
+);
+
+extern void EnqueueEvent(
+#if NeedFunctionPrototypes
+    xEventPtr /* xE */,
+    DeviceIntPtr /* device */,
+    int        /* count */
+#endif
+);
+
+extern void ComputeFreezes(
+#if NeedFunctionPrototypes
+    void
+#endif
+);
+
+extern void CheckGrabForSyncs(
+#if NeedFunctionPrototypes
+    DeviceIntPtr /* dev */,
+    Bool /* thisMode */,
+    Bool /* otherMode */
+#endif
+);
+
+extern void ActivatePointerGrab(
+#if NeedFunctionPrototypes
+    DeviceIntPtr /* mouse */,
+    GrabPtr /* grab */,
+    TimeStamp /* time */,
+    Bool /* autoGrab */
+#endif
+);
+
+extern void DeactivatePointerGrab(
+#if NeedFunctionPrototypes
+    DeviceIntPtr /* mouse */
+#endif
+);
+
+extern void ActivateKeyboardGrab(
+#if NeedFunctionPrototypes
+    DeviceIntPtr /* keybd */,
+    GrabPtr /* grab */,
+    TimeStamp /* time */,
+    Bool /* passive */
+#endif
+);
+
+extern void DeactivateKeyboardGrab(
+#if NeedFunctionPrototypes
+    DeviceIntPtr /* keybd */
+#endif
+);
+
+extern void AllowSome(
+#if NeedFunctionPrototypes
+    ClientPtr  /* client */,
+    TimeStamp /* time */,
+    DeviceIntPtr /* thisDev */,
+    int /* newState */
+#endif
+);
+
+extern void ReleaseActiveGrabs(
+#if NeedFunctionPrototypes
+ClientPtr client
+#endif
+);
+
+extern int DeliverEventsToWindow(
+#if NeedFunctionPrototypes
+    WindowPtr /* pWin */,
+    xEventPtr /* pEvents */,
+    int /* count */,
+    Mask /* filter */,
+    GrabPtr /* grab */,
+    int /* mskidx */
+#endif
+);
+
+extern int DeliverDeviceEvents(
+#if NeedFunctionPrototypes
+    WindowPtr /* pWin */,
+    xEventPtr /* xE */,
+    GrabPtr /* grab */,
+    WindowPtr /* stopAt */,
+    DeviceIntPtr /* dev */,
+    int /* count */
+#endif
+);
+
+extern void DefineInitialRootWindow(
+#if NeedFunctionPrototypes
+    WindowPtr /* win */
+#endif
+);
+
+extern void WindowHasNewCursor(
+#if NeedFunctionPrototypes
+    WindowPtr /* pWin */
+#endif
+);
+
+extern Bool CheckDeviceGrabs(
+#if NeedFunctionPrototypes
+    DeviceIntPtr /* device */,
+    xEventPtr /* xE */,
+    int /* checkFirst */,
+    int /* count */
+#endif
+);
+
+extern void DeliverFocusedEvent(
+#if NeedFunctionPrototypes
+    DeviceIntPtr /* keybd */,
+    xEventPtr /* xE */,
+    WindowPtr /* window */,
+    int /* count */
+#endif
+);
+
+extern void DeliverGrabbedEvent(
+#if NeedFunctionPrototypes
+    xEventPtr /* xE */,
+    DeviceIntPtr /* thisDev */,
+    Bool /* deactivateGrab */,
+    int /* count */
+#endif
+);
+
+extern void RecalculateDeliverableEvents(
+#if NeedFunctionPrototypes
+    WindowPtr /* pWin */
+#endif
+);
+
+extern int OtherClientGone(
+#if NeedFunctionPrototypes
+    pointer /* value */,
+    XID /* id */
+#endif
+);
+
+extern void DoFocusEvents(
+#if NeedFunctionPrototypes
+    DeviceIntPtr /* dev */,
+    WindowPtr /* fromWin */,
+    WindowPtr /* toWin */,
+    int /* mode */
+#endif
+);
+
+extern int SetInputFocus(
+#if NeedFunctionPrototypes
+    ClientPtr /* client */,
+    DeviceIntPtr /* dev */,
+    Window /* focusID */,
+    CARD8 /* revertTo */,
+    Time /* ctime */,
+    Bool /* followOK */
+#endif
+);
+
+extern int GrabDevice(
+#if NeedFunctionPrototypes
+    ClientPtr /* client */,
+    DeviceIntPtr /* dev */,
+    unsigned /* this_mode */,
+    unsigned /* other_mode */,
+    Window /* grabWindow */,
+    unsigned /* ownerEvents */,
+    Time /* ctime */,
+    Mask /* mask */,
+    CARD8 * /* status */
+#endif
+);
+
+extern void InitEvents(
+#if NeedFunctionPrototypes
+    void
+#endif
+);
+
+extern void DeleteWindowFromAnyEvents(
+#if NeedFunctionPrototypes
+    WindowPtr  /* pWin */,
+    Bool /* freeResources */
+#endif
+);
+
+extern void CheckCursorConfinement(
+#if NeedFunctionPrototypes
+    WindowPtr /* pWin */
+#endif
+);
+
+extern Mask EventMaskForClient(
+#if NeedFunctionPrototypes
+    WindowPtr /* pWin */,
+    ClientPtr /* client */
+#endif
+);
+
+
+
+extern int DeliverEvents(
+#if NeedFunctionPrototypes
+    WindowPtr /*pWin*/,
+    xEventPtr /*xE*/,
+    int /*count*/,
+    WindowPtr /*otherParent*/
+#endif
+);
+
+extern void WriteEventsToClient(
+#if NeedFunctionPrototypes
+    ClientPtr /*pClient*/,
+    int             /*count*/,
+    xEventPtr /*events*/
+#endif
+);
+
+extern int TryClientEvents(
+#if NeedFunctionPrototypes
+    ClientPtr /*client*/,
+    xEventPtr /*pEvents*/,
+    int /*count*/,
+    Mask /*mask*/,
+    Mask /*filter*/,
+    GrabPtr /*grab*/
+#endif
+);
+
+extern int EventSelectForWindow(
+#if NeedFunctionPrototypes
+    WindowPtr /*pWin*/,
+    ClientPtr /*client*/,
+    Mask /*mask*/
+#endif
+);
+
+extern int EventSuppressForWindow(
+#if NeedFunctionPrototypes
+    WindowPtr /*pWin*/,
+    ClientPtr /*client*/,
+    Mask /*mask*/,
+    Bool * /*checkOptional*/
+#endif
+);
+
+extern int MaybeDeliverEventsToClient(
+#if NeedFunctionPrototypes
+    WindowPtr /*pWin*/,
+    xEventPtr /*pEvents*/,
+    int /*count*/,
+    Mask /*filter*/,
+    ClientPtr /*dontClient*/
+#endif
+);
+
+extern void WindowsRestructured(
+#if NeedFunctionPrototypes
+    void
+#endif
+);
+
+extern void ResetClientPrivates(
+#if NeedFunctionPrototypes
+    void
+#endif
+);
+
+extern int AllocateClientPrivateIndex(
+#if NeedFunctionPrototypes
+    void
+#endif
+);
+
+extern Bool AllocateClientPrivate(
+#if NeedFunctionPrototypes
+    int /*index*/,
+    unsigned /*amount*/
+#endif
+);
+
+/*
+ *  callback manager stuff
+ */
+
+#ifndef _XTYPEDEF_CALLBACKLISTPTR
+typedef struct _CallbackList *CallbackListPtr; /* also in misc.h */
+#define _XTYPEDEF_CALLBACKLISTPTR
+#endif
+
+typedef void (*CallbackProcPtr) (
+#if NeedNestedPrototypes
+    CallbackListPtr *, pointer, pointer
+#endif
+);
+
+typedef Bool (*AddCallbackProcPtr) (
+#if NeedNestedPrototypes
+    CallbackListPtr *, CallbackProcPtr, pointer
+#endif
+);
+
+typedef Bool (*DeleteCallbackProcPtr) (
+#if NeedNestedPrototypes
+    CallbackListPtr *, CallbackProcPtr, pointer
+#endif
+);
+
+typedef void (*CallCallbacksProcPtr) (
+#if NeedNestedPrototypes
+    CallbackListPtr *, pointer
+#endif
+);
+
+typedef void (*DeleteCallbackListProcPtr) (
+#if NeedNestedPrototypes
+    CallbackListPtr *
+#endif
+);
+
+typedef struct _CallbackProcs {
+    AddCallbackProcPtr         AddCallback;
+    DeleteCallbackProcPtr      DeleteCallback;
+    CallCallbacksProcPtr       CallCallbacks;
+    DeleteCallbackListProcPtr  DeleteCallbackList;
+} CallbackFuncsRec, *CallbackFuncsPtr;
+
+extern Bool CreateCallbackList(
+#if NeedFunctionPrototypes
+    CallbackListPtr * /*pcbl*/,
+    CallbackFuncsPtr /*cbfuncs*/
+#endif
+);
+
+extern Bool AddCallback(
+#if NeedFunctionPrototypes
+    CallbackListPtr * /*pcbl*/,
+    CallbackProcPtr /*callback*/,
+    pointer /*data*/
+#endif
+);
+
+extern Bool DeleteCallback(
+#if NeedFunctionPrototypes
+    CallbackListPtr * /*pcbl*/,
+    CallbackProcPtr /*callback*/,
+    pointer /*data*/
+#endif
+);
+
+extern void CallCallbacks(
+#if NeedFunctionPrototypes
+    CallbackListPtr * /*pcbl*/,
+    pointer /*call_data*/
+#endif
+);
+
+extern void DeleteCallbackList(
+#if NeedFunctionPrototypes
+    CallbackListPtr * /*pcbl*/
+#endif
+);
+
+extern void InitCallbackManager(
+#if NeedFunctionPrototypes
+    void
+#endif
+);
+
+/*
+ *  ServerGrabCallback stuff
+ */
+
+extern CallbackListPtr ServerGrabCallback;
+
+typedef enum {SERVER_GRABBED, SERVER_UNGRABBED,
+             CLIENT_PERVIOUS, CLIENT_IMPERVIOUS } ServerGrabState;
+
+typedef struct {
+    ClientPtr client;
+    ServerGrabState grabstate;
+} ServerGrabInfoRec;
+
+/*
+ *  EventCallback stuff
+ */
+
+extern CallbackListPtr EventCallback;
+
+typedef struct {
+    ClientPtr client;
+    xEventPtr events;
+    int count;
+} EventInfoRec;
+
+/*
+ *  DeviceEventCallback stuff
+ */
+
+extern CallbackListPtr DeviceEventCallback;
+
+typedef struct {
+    xEventPtr events;
+    int count;
+} DeviceEventInfoRec;
+
+#endif /* DIX_H */
diff --git a/Xserver/programs/Xserver/include/dixevents.h b/Xserver/programs/Xserver/include/dixevents.h
new file mode 100644 (file)
index 0000000..957091b
--- /dev/null
@@ -0,0 +1,256 @@
+/* $XFree86: xc/programs/Xserver/include/dixevents.h,v 3.2 1996/12/24 02:27:27 dawes Exp $ */
+/************************************************************
+
+Copyright 1996 by Thomas E. Dickey <dickey@clark.net>
+
+                        All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and its
+documentation for any purpose and without fee is hereby granted,
+provided that the above copyright notice appear in all copies and that
+both that copyright notice and this permission notice appear in
+supporting documentation, and that the name of the above listed
+copyright holder(s) not be used in advertising or publicity pertaining
+to distribution of the software without specific, written prior
+permission.
+
+THE ABOVE LISTED COPYRIGHT HOLDER(S) DISCLAIM ALL WARRANTIES WITH REGARD
+TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+AND FITNESS, IN NO EVENT SHALL THE ABOVE LISTED COPYRIGHT HOLDER(S) BE
+LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+
+********************************************************/
+
+#ifndef DIXEVENTS_H
+#define DIXEVENTS_H
+
+extern Mask
+GetNextEventMask(
+#if NeedFunctionPrototypes
+       void
+#endif
+       );
+
+extern void
+SetCriticalEvent(
+#if NeedFunctionPrototypes
+       int                    /* event */
+#endif
+       );
+
+extern void
+ConfineCursorToWindow(
+#if NeedFunctionPrototypes
+       WindowPtr              /* pWin */,
+       Bool                   /* generateEvents */,
+       Bool                   /* confineToScreen */
+#endif
+       );
+
+extern CursorPtr
+GetSpriteCursor(
+#if NeedFunctionPrototypes
+       void
+#endif
+       );
+
+extern int
+ProcAllowEvents(
+#if NeedFunctionPrototypes
+       ClientPtr              /* client */
+#endif
+       );
+
+extern int
+TryClientEvents (
+#if NeedFunctionPrototypes
+       ClientPtr              /* client */,
+       xEvent *               /* pEvents */,
+       int                    /* count */,
+       Mask                   /* mask */,
+       Mask                   /* filter */,
+       GrabPtr                /* grab */
+#endif
+       );
+
+extern int
+MaybeDeliverEventsToClient(
+#if NeedFunctionPrototypes
+       WindowPtr              /* pWin */,
+       xEvent *               /* pEvents */,
+       int                    /* count */,
+       Mask                   /* filter */,
+       ClientPtr              /* dontClient */
+#endif
+       );
+
+extern void
+WindowsRestructured(
+#if NeedFunctionPrototypes
+       void
+#endif
+       );
+
+extern void
+NewCurrentScreen(
+#if NeedFunctionPrototypes
+       ScreenPtr              /* newScreen */,
+       int                    /* x */,
+       int                    /* y */
+#endif
+       );
+
+extern int
+ProcWarpPointer(
+#if NeedFunctionPrototypes
+       ClientPtr              /* client */
+#endif
+       );
+
+extern void
+#ifdef XKB
+CoreProcessKeyboardEvent (
+#else
+ProcessKeyboardEvent (
+#endif
+#if NeedFunctionPrototypes
+       xEvent *               /* xE */,
+       DeviceIntPtr           /* keybd */,
+       int                    /* count */
+#endif
+       );
+
+extern void
+#ifdef XKB
+CoreProcessPointerEvent (
+#else
+ProcessPointerEvent (
+#endif
+#if NeedFunctionPrototypes
+       xEvent *               /* xE */,
+       DeviceIntPtr           /* mouse */,
+       int                    /* count */
+#endif
+       );
+
+extern int
+EventSelectForWindow(
+#if NeedFunctionPrototypes
+       WindowPtr              /* pWin */,
+       ClientPtr              /* client */,
+       Mask                   /* mask */
+#endif
+       );
+
+extern int
+EventSuppressForWindow(
+#if NeedFunctionPrototypes
+       WindowPtr              /* pWin */,
+       ClientPtr              /* client */,
+       Mask                   /* mask */,
+       Bool *                 /* checkOptional */
+#endif
+       );
+
+extern int
+ProcSetInputFocus(
+#if NeedFunctionPrototypes
+       ClientPtr              /* client */
+#endif
+       );
+
+extern int
+ProcGetInputFocus(
+#if NeedFunctionPrototypes
+       ClientPtr              /* client */
+#endif
+       );
+
+extern int
+ProcGrabPointer(
+#if NeedFunctionPrototypes
+       ClientPtr              /* client */
+#endif
+       );
+
+extern int
+ProcChangeActivePointerGrab(
+#if NeedFunctionPrototypes
+       ClientPtr              /* client */
+#endif
+       );
+
+extern int
+ProcUngrabPointer(
+#if NeedFunctionPrototypes
+       ClientPtr              /* client */
+#endif
+       );
+
+extern int
+ProcGrabKeyboard(
+#if NeedFunctionPrototypes
+       ClientPtr              /* client */
+#endif
+       );
+
+extern int
+ProcUngrabKeyboard(
+#if NeedFunctionPrototypes
+       ClientPtr              /* client */
+#endif
+       );
+
+extern int
+ProcQueryPointer(
+#if NeedFunctionPrototypes
+       ClientPtr              /* client */
+#endif
+       );
+
+extern int
+ProcSendEvent(
+#if NeedFunctionPrototypes
+       ClientPtr              /* client */
+#endif
+       );
+
+extern int
+ProcUngrabKey(
+#if NeedFunctionPrototypes
+       ClientPtr              /* client */
+#endif
+       );
+
+extern int
+ProcGrabKey(
+#if NeedFunctionPrototypes
+       ClientPtr              /* client */
+#endif
+       );
+
+extern int
+ProcGrabButton(
+#if NeedFunctionPrototypes
+       ClientPtr              /* client */
+#endif
+       );
+
+extern int
+ProcUngrabButton(
+#if NeedFunctionPrototypes
+       ClientPtr              /* client */
+#endif
+       );
+
+extern int
+ProcRecolorCursor(
+#if NeedFunctionPrototypes
+       ClientPtr              /* client */
+#endif
+       );
+
+#endif /* DIXEVENTS_H */
diff --git a/Xserver/programs/Xserver/include/dixfont.h b/Xserver/programs/Xserver/include/dixfont.h
new file mode 100644 (file)
index 0000000..dedd50c
--- /dev/null
@@ -0,0 +1,444 @@
+/* $XConsortium: dixfont.h /main/21 1996/09/28 17:14:16 rws $ */
+/* $XFree86: xc/programs/Xserver/include/dixfont.h,v 3.1 1996/12/23 07:09:25 dawes Exp $ */
+/***********************************************************
+Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
+
+                        All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and its
+documentation for any purpose and without fee is hereby granted,
+provided that the above copyright notice appear in all copies and that
+both that copyright notice and this permission notice appear in
+supporting documentation, and that the name of Digital not be
+used in advertising or publicity pertaining to distribution of the
+software without specific, written prior permission.
+
+DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
+ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
+DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
+ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+SOFTWARE.
+
+******************************************************************/
+
+#ifndef DIXFONT_H
+#define DIXFONT_H 1
+
+#include <dix.h>
+#include <font.h>
+#include <closure.h>
+
+#define NullDIXFontProp ((DIXFontPropPtr)0)
+
+typedef struct _DIXFontProp *DIXFontPropPtr;
+
+extern int FontToXError(
+#if NeedFunctionPrototypes
+    int /*err*/
+#endif
+);
+
+extern Bool SetDefaultFont(
+#if NeedFunctionPrototypes
+    char * /*defaultfontname*/
+#endif
+);
+
+extern void QueueFontWakeup(
+#if NeedFunctionPrototypes
+    FontPathElementPtr /*fpe*/
+#endif
+);
+
+extern void RemoveFontWakeup(
+#if NeedFunctionPrototypes
+    FontPathElementPtr /*fpe*/
+#endif
+);
+
+extern void FontWakeup(
+#if NeedFunctionPrototypes
+    pointer /*data*/,
+    int /*count*/,
+    pointer /*LastSelectMask*/
+#endif
+);
+
+extern int OpenFont(
+#if NeedFunctionPrototypes
+    ClientPtr /*client*/,
+    XID /*fid*/,
+    Mask /*flags*/,
+    unsigned /*lenfname*/,
+    char * /*pfontname*/
+#endif
+);
+
+extern int CloseFont(
+#if NeedFunctionPrototypes
+    pointer /*pfont*/,
+    XID /*fid*/
+#endif
+);
+
+typedef struct _xQueryFontReply *xQueryFontReplyPtr;
+
+extern void QueryFont(
+#if NeedFunctionPrototypes
+    FontPtr /*pFont*/,
+    xQueryFontReplyPtr /*pReply*/,
+    int /*nProtoCCIStructs*/
+#endif
+);
+
+extern int ListFonts(
+#if NeedFunctionPrototypes
+    ClientPtr /*client*/,
+    unsigned char * /*pattern*/,
+    unsigned int /*length*/,
+    unsigned int /*max_names*/
+#endif
+);
+
+int
+doListFontsWithInfo(
+#if NeedFunctionPrototypes
+    ClientPtr /*client*/,
+    LFWIclosurePtr /*c*/
+#endif
+);
+
+extern int doPolyText(
+#if NeedFunctionPrototypes
+    ClientPtr /*client*/,
+    PTclosurePtr /*c*/
+#endif
+);
+
+extern int PolyText(
+#if NeedFunctionPrototypes
+    ClientPtr /*client*/,
+    DrawablePtr /*pDraw*/,
+    GCPtr /*pGC*/,
+    unsigned char * /*pElt*/,
+    unsigned char * /*endReq*/,
+    int /*xorg*/,
+    int /*yorg*/,
+    int /*reqType*/,
+    XID /*did*/
+#endif
+);
+
+extern int doImageText(
+#if NeedFunctionPrototypes
+    ClientPtr /*client*/,
+    ITclosurePtr /*c*/
+#endif
+);
+
+extern int ImageText(
+#if NeedFunctionPrototypes
+    ClientPtr /*client*/,
+    DrawablePtr /*pDraw*/,
+    GCPtr /*pGC*/,
+    int /*nChars*/,
+    unsigned char * /*data*/,
+    int /*xorg*/,
+    int /*yorg*/,
+    int /*reqType*/,
+    XID /*did*/
+#endif
+);
+
+extern int SetFontPath(
+#if NeedFunctionPrototypes
+    ClientPtr /*client*/,
+    int /*npaths*/,
+    unsigned char * /*paths*/,
+    int * /*error*/
+#endif
+);
+
+extern int SetDefaultFontPath(
+#if NeedFunctionPrototypes
+    char * /*path*/
+#endif
+);
+
+extern unsigned char *GetFontPath(
+#if NeedFunctionPrototypes
+    int * /*count*/,
+    int * /*length*/
+#endif
+);
+
+extern int LoadGlyphs(
+#if NeedFunctionPrototypes
+    ClientPtr /*client*/,
+    FontPtr /*pfont*/,
+    unsigned /*nchars*/,
+    int /*item_size*/,
+    unsigned char * /*data*/
+#endif
+);
+
+extern void DeleteClientFontStuff(
+#if NeedFunctionPrototypes
+    ClientPtr /*client*/
+#endif
+);
+
+extern void InitFonts(
+#if NeedFunctionPrototypes
+    void
+#endif
+);
+
+extern int GetDefaultPointSize(
+#if NeedFunctionPrototypes
+    void
+#endif
+);
+
+extern FontResolutionPtr GetClientResolutions(
+#if NeedFunctionPrototypes
+    int * /*num*/
+#endif
+);
+
+/* This is related to 'struct _FPEFunctions' in fonts/include/fontstruct.h
+ */
+extern int RegisterFPEFunctions(
+#if NeedFunctionPrototypes
+    int (* /*name_func*/)(
+#if NeedNestedPrototypes
+               char* /* name */
+#endif
+               ),
+    int (* /*init_func*/)(
+#if NeedNestedPrototypes
+               FontPathElementPtr /* fpe */
+#endif
+               ),
+    int (* /*free_func*/)(
+#if NeedNestedPrototypes
+               FontPathElementPtr /* fpe */
+#endif
+               ),
+    int (* /*reset_func*/)(
+#if NeedNestedPrototypes
+               FontPathElementPtr /* fpe */
+#endif
+               ),
+    int (* /*open_func*/)(
+#if NeedNestedPrototypes
+               pointer /* client */,
+               FontPathElementPtr /* fpe */,
+               int /* flags */,
+               char* /* name */,
+               int /* namelen */,
+               fsBitmapFormat /* format */,
+               fsBitmapFormatMask /* fmask */,
+               unsigned long /* id (type XID or FSID) */,
+               FontPtr* /* pFont */,
+               char** /* aliasName */,
+               FontPtr /* non_cachable_font */
+#endif
+               ),
+    int (* /*close_func*/)(
+#if NeedNestedPrototypes
+               FontPathElementPtr /* fpe */,
+               FontPtr /* pFont */
+#endif
+               ),
+    int (* /*list_func*/)(
+#if NeedNestedPrototypes
+               pointer /* client */,
+               FontPathElementPtr /* fpe */,
+               char* /* pat */,
+               int /* len */,
+               int /* max */,
+               FontNamesPtr /* names */
+#endif
+               ),
+    int (* /*start_lfwi_func*/)(
+#if NeedNestedPrototypes
+               pointer /* client */,
+               FontPathElementPtr /* fpe */,
+               char* /* pat */,
+               int /* patlen */,
+               int /* maxnames */,
+               pointer* /* privatep */
+#endif
+               ),
+    int (* /*next_lfwi_func*/)(
+#if NeedNestedPrototypes
+               pointer /* client */,
+               FontPathElementPtr /* fpe */,
+               char** /* name */,
+               int* /* namelen */,
+               FontInfoPtr* /* info */,
+               int* /* numFonts */,
+               pointer /* private */
+#endif
+               ),
+    int (* /*wakeup_func*/)(
+#if NeedNestedPrototypes
+               FontPathElementPtr /* fpe */,
+               unsigned long* /* LastSelectMask */
+#endif
+               ),
+    int (* /*client_died*/)(
+#if NeedNestedPrototypes
+               pointer /* client */,
+               FontPathElementPtr /* fpe */
+#endif
+               ),
+    int (* /*load_glyphs*/)(
+#if NeedNestedPrototypes
+               pointer /* client */,
+               FontPtr /* pfont */,
+               Bool /* range_flag */,
+               unsigned int /* nchars */,
+               int /* item_size */,
+               unsigned char* /* data */
+#endif
+               ),
+    int (* /*start_list_alias_func*/)(
+#if NeedNestedPrototypes
+               pointer /* client */,
+               FontPathElementPtr /* fpe */,
+               char* /* pat */,
+               int /* len */,
+               int /* max */,
+               pointer* /* privatep */
+#endif
+               ),
+    int (* /*next_list_alias_func*/)(
+#if NeedNestedPrototypes
+               pointer /* client */,
+               FontPathElementPtr /* fpe */,
+               char** /* namep */,
+               int* /* namelenp */,
+               char** /* resolvedp */,
+               int* /* resolvedlenp */,
+               pointer /* private */
+#endif
+               ),
+    void (* /* set_path_func*/)(
+#if NeedFunctionPrototypes
+               void
+#endif
+               )
+#endif
+);
+
+extern void FreeFonts(
+#if NeedFunctionPrototypes
+    void
+#endif
+);
+
+extern FontPtr find_old_font(
+#if NeedFunctionPrototypes
+    XID /*id*/
+#endif
+);
+
+extern Font GetNewFontClientID(
+#if NeedFunctionPrototypes
+    void
+#endif
+);
+
+extern int StoreFontClientFont(
+#if NeedFunctionPrototypes
+    FontPtr /*pfont*/,
+    Font /*id*/
+#endif
+);
+
+extern void DeleteFontClientID(
+#if NeedFunctionPrototypes
+    Font /*id*/
+#endif
+);
+
+extern int client_auth_generation(
+#if NeedFunctionPrototypes
+    ClientPtr /*client*/
+#endif
+);
+
+extern int init_fs_handlers(
+#if NeedFunctionPrototypes
+    FontPathElementPtr /*fpe*/,
+    BlockHandlerProcPtr /*block_handler*/
+#endif
+);
+
+extern void remove_fs_handlers(
+#if NeedFunctionPrototypes
+    FontPathElementPtr /*fpe*/,
+    BlockHandlerProcPtr /*block_handler*/,
+    Bool /*all*/
+#endif
+);
+
+extern void GetGlyphs(
+#if NeedFunctionPrototypes
+    FontPtr     /*font*/,
+    unsigned long /*count*/,
+    unsigned char * /*chars*/,
+    FontEncoding /*fontEncoding*/,
+    unsigned long * /*glyphcount*/,
+    CharInfoPtr * /*glyphs*/
+#endif
+);
+
+extern void QueryGlyphExtents(
+#if NeedFunctionPrototypes
+    FontPtr     /*pFont*/,
+    CharInfoPtr * /*charinfo*/,
+    unsigned long /*count*/,
+    ExtentInfoPtr /*info*/
+#endif
+);
+
+extern Bool QueryTextExtents(
+#if NeedFunctionPrototypes
+    FontPtr     /*pFont*/,
+    unsigned long /*count*/,
+    unsigned char * /*chars*/,
+    ExtentInfoPtr /*info*/
+#endif
+);
+
+extern Bool ParseGlyphCachingMode(
+#if NeedFunctionPrototypes
+    char * /*str*/
+#endif
+);
+
+extern void InitGlyphCaching(
+#if NeedFunctionPrototypes
+    void
+#endif
+);
+
+extern void SetGlyphCachingMode(
+#if NeedFunctionPrototypes
+    int /*newmode*/
+#endif
+);
+
+void
+ResetFontPrivateIndex(
+#if NeedFunctionPrototypes
+    void
+#endif
+);
+
+#endif                         /* DIXFONT_H */
diff --git a/Xserver/programs/Xserver/include/dixfontstr.h b/Xserver/programs/Xserver/include/dixfontstr.h
new file mode 100644 (file)
index 0000000..2800204
--- /dev/null
@@ -0,0 +1,95 @@
+/* $XConsortium: dixfontstr.h,v 1.15 94/04/17 20:25:39 dpw Exp $ */
+/***********************************************************
+Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
+
+                        All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and its
+documentation for any purpose and without fee is hereby granted,
+provided that the above copyright notice appear in all copies and that
+both that copyright notice and this permission notice appear in
+supporting documentation, and that the name of Digital not be
+used in advertising or publicity pertaining to distribution of the
+software without specific, written prior permission.
+
+DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
+ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
+DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
+ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+SOFTWARE.
+
+******************************************************************/
+
+#ifndef DIXFONTSTRUCT_H
+#define DIXFONTSTRUCT_H
+
+#include "servermd.h"
+#include "dixfont.h"
+#include "fontstruct.h"
+#include "closure.h"
+#define NEED_REPLIES
+#include "X11/Xproto.h" /* for xQueryFontReply */
+
+#define FONTCHARSET(font)        (font)
+#define FONTMAXBOUNDS(font,field) (font)->info.maxbounds.field
+#define FONTMINBOUNDS(font,field) (font)->info.minbounds.field
+#define TERMINALFONT(font)       (font)->info.terminalFont
+#define FONTASCENT(font)         (font)->info.fontAscent
+#define FONTDESCENT(font)        (font)->info.fontDescent
+#define FONTGLYPHS(font)         0
+#define FONTCONSTMETRICS(font)   (font)->info.constantMetrics
+#define FONTCONSTWIDTH(font)     (font)->info.constantWidth
+#define FONTALLEXIST(font)       (font)->info.allExist
+#define FONTFIRSTCOL(font)       (font)->info.firstCol
+#define FONTLASTCOL(font)        (font)->info.lastCol
+#define FONTFIRSTROW(font)       (font)->info.firstRow
+#define FONTLASTROW(font)        (font)->info.lastRow
+#define FONTDEFAULTCH(font)      (font)->info.defaultCh
+#define FONTINKMIN(font)         (&((font)->info.ink_minbounds))
+#define FONTINKMAX(font)         (&((font)->info.ink_maxbounds))
+#define FONTPROPS(font)                  (font)->info.props
+#define FONTGLYPHBITS(base,pci)          ((unsigned char *) (pci)->bits)
+#define FONTINFONPROPS(font)     (font)->info.nprops
+
+/* some things haven't changed names, but we'll be careful anyway */
+
+#define FONTREFCNT(font)         (font)->refcnt
+
+/*
+ * for linear char sets
+ */
+#define N1dChars(pfont)        (FONTLASTCOL(pfont) - FONTFIRSTCOL(pfont) + 1)
+
+/*
+ * for 2D char sets
+ */
+#define N2dChars(pfont)        (N1dChars(pfont) * \
+                        (FONTLASTROW(pfont) - FONTFIRSTROW(pfont) + 1))
+
+#ifndef GLYPHPADBYTES
+#define GLYPHPADBYTES -1
+#endif
+
+#if GLYPHPADBYTES == 0 || GLYPHPADBYTES == 1
+#define        GLYPHWIDTHBYTESPADDED(pci)      (GLYPHWIDTHBYTES(pci))
+#define        PADGLYPHWIDTHBYTES(w)           (((w)+7)>>3)
+#endif
+
+#if GLYPHPADBYTES == 2
+#define        GLYPHWIDTHBYTESPADDED(pci)      ((GLYPHWIDTHBYTES(pci)+1) & ~0x1)
+#define        PADGLYPHWIDTHBYTES(w)           (((((w)+7)>>3)+1) & ~0x1)
+#endif
+
+#if GLYPHPADBYTES == 4
+#define        GLYPHWIDTHBYTESPADDED(pci)      ((GLYPHWIDTHBYTES(pci)+3) & ~0x3)
+#define        PADGLYPHWIDTHBYTES(w)           (((((w)+7)>>3)+3) & ~0x3)
+#endif
+
+#if GLYPHPADBYTES == 8 /* for a cray? */
+#define        GLYPHWIDTHBYTESPADDED(pci)      ((GLYPHWIDTHBYTES(pci)+7) & ~0x7)
+#define        PADGLYPHWIDTHBYTES(w)           (((((w)+7)>>3)+7) & ~0x7)
+#endif
+
+#endif                         /* DIXFONTSTRUCT_H */
diff --git a/Xserver/programs/Xserver/include/dixgrabs.h b/Xserver/programs/Xserver/include/dixgrabs.h
new file mode 100644 (file)
index 0000000..5c3fc7f
--- /dev/null
@@ -0,0 +1,79 @@
+/* $XFree86: xc/programs/Xserver/include/dixgrabs.h,v 3.0 1996/04/15 11:34:27 dawes Exp $ */
+/************************************************************
+
+Copyright 1996 by Thomas E. Dickey <dickey@clark.net>
+
+                        All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and its
+documentation for any purpose and without fee is hereby granted,
+provided that the above copyright notice appear in all copies and that
+both that copyright notice and this permission notice appear in
+supporting documentation, and that the name of the above listed
+copyright holder(s) not be used in advertising or publicity pertaining
+to distribution of the software without specific, written prior
+permission.
+
+THE ABOVE LISTED COPYRIGHT HOLDER(S) DISCLAIM ALL WARRANTIES WITH REGARD
+TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+AND FITNESS, IN NO EVENT SHALL THE ABOVE LISTED COPYRIGHT HOLDER(S) BE
+LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+
+********************************************************/
+
+#ifndef DIXGRABS_H
+#define DIXGRABS_H 1
+
+GrabPtr
+CreateGrab(
+#if NeedFunctionPrototypes
+       int /* client */,
+       DeviceIntPtr /* device */,
+       WindowPtr /* window */,
+       Mask /* eventMask */,
+       Bool /* ownerEvents */,
+       Bool /* keyboardMode */,
+       Bool /* pointerMode */,
+       DeviceIntPtr /* modDevice */,
+       unsigned short /* modifiers */,
+       int /* type */,
+       KeyCode /* keybut */,
+       WindowPtr /* confineTo */,
+       CursorPtr /* cursor */
+#endif
+       );
+
+int
+DeletePassiveGrab(
+#if NeedFunctionPrototypes
+       pointer /* value */,
+       XID /* id */
+#endif
+       );
+
+Bool
+GrabMatchesSecond(
+#if NeedFunctionPrototypes
+       GrabPtr /* pFirstGrab */,
+       GrabPtr /* pSecondGrab */
+#endif
+       );
+
+int
+AddPassiveGrabToList(
+#if NeedFunctionPrototypes
+       GrabPtr /* pGrab */
+#endif
+       );
+
+Bool
+DeletePassiveGrabFromList(
+#if NeedFunctionPrototypes
+       GrabPtr /* pMinuendGrab */
+#endif
+       );
+
+#endif /* DIXGRABS_H */
diff --git a/Xserver/programs/Xserver/include/dixstruct.h b/Xserver/programs/Xserver/include/dixstruct.h
new file mode 100644 (file)
index 0000000..61c25d3
--- /dev/null
@@ -0,0 +1,237 @@
+/***********************************************************
+Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
+
+                        All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and its
+documentation for any purpose and without fee is hereby granted,
+provided that the above copyright notice appear in all copies and that
+both that copyright notice and this permission notice appear in
+supporting documentation, and that the name of Digital not be
+used in advertising or publicity pertaining to distribution of the
+software without specific, written prior permission.
+
+DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
+ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
+DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
+ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+SOFTWARE.
+
+******************************************************************/
+/* $XConsortium: dixstruct.h /main/43 1996/12/15 21:25:06 rws $ */
+/* $XFree86: xc/programs/Xserver/include/dixstruct.h,v 3.8 1996/12/24 02:27:28 dawes Exp $ */
+
+#ifndef DIXSTRUCT_H
+#define DIXSTRUCT_H
+
+#include "dix.h"
+#include "resource.h"
+#include "cursor.h"
+#include "gc.h"
+#include "pixmap.h"
+#include <X11/Xmd.h>
+
+/*
+ *     direct-mapped hash table, used by resource manager to store
+ *      translation from client ids to server addresses.
+ */
+
+#ifdef DEBUG
+#define MAX_REQUEST_LOG 100
+#endif
+
+extern CallbackListPtr ClientStateCallback;
+
+typedef struct {
+    ClientPtr          client;
+    xConnSetupPrefix   *prefix; 
+    xConnSetup         *setup;
+} NewClientInfoRec;
+
+typedef void (*ReplySwapPtr) (
+#if NeedNestedPrototypes
+               ClientPtr       /* pClient */,
+               int             /* size */,
+               void *          /* pbuf */
+#endif
+);
+
+extern void ReplyNotSwappd (
+#if NeedNestedPrototypes
+               ClientPtr       /* pClient */,
+               int             /* size */,
+               void *          /* pbuf */
+#endif
+);
+
+typedef enum {ClientStateInitial,
+             ClientStateAuthenticating,
+             ClientStateRunning,
+             ClientStateRetained,
+             ClientStateGone,
+             ClientStateCheckingSecurity,
+             ClientStateCheckedSecurity} ClientState;
+
+typedef struct _Client {
+    int         index;
+    Mask        clientAsMask;
+    pointer     requestBuffer;
+    pointer     osPrivate;     /* for OS layer, including scheduler */
+    Bool        swapped;
+    ReplySwapPtr pSwapReplyFunc;
+    XID         errorValue;
+    int         sequence;
+    int         closeDownMode;
+    int         clientGone;
+    int         noClientException;     /* this client died or needs to be
+                                        * killed */
+    DrawablePtr lastDrawable;
+    Drawable    lastDrawableID;
+    GCPtr       lastGC;
+    GContext    lastGCID;
+    pointer    *saveSet;
+    int         numSaved;
+    pointer     screenPrivate[MAXSCREENS];
+    int         (**requestVector) (
+#if NeedNestedPrototypes
+               ClientPtr /* pClient */
+#endif
+);
+    CARD32     req_len;                /* length of current request */
+    Bool       big_requests;           /* supports large requests */
+    int                priority;
+    ClientState clientState;
+    DevUnion   *devPrivates;
+#ifdef XKB
+    unsigned short     xkbClientFlags;
+    unsigned short     mapNotifyMask;
+    unsigned short     newKeyboardNotifyMask;
+    unsigned short     vMajor,vMinor;
+    KeyCode            minKC,maxKC;
+#endif
+
+#ifdef DEBUG
+    unsigned char requestLog[MAX_REQUEST_LOG];
+    int         requestLogIndex;
+#endif
+#ifdef LBX
+    int                (*readRequest)(
+#if NeedNestedPrototypes
+       ClientPtr /*client*/
+#endif
+);
+#endif
+    unsigned long replyBytesRemaining;
+#ifdef XCSECURITY
+    XID                authId;
+    unsigned int trustLevel;
+    pointer (* CheckAccess)(
+#if NeedNestedPrototypes
+           ClientPtr /*pClient*/,
+           XID /*id*/,
+           RESTYPE /*classes*/,
+           Mask /*access_mode*/,
+           pointer /*resourceval*/
+#endif
+);
+#endif
+#ifdef XAPPGROUP
+    struct _AppGroupRec*       appgroup;
+#endif
+    struct _FontResolution * (*fontResFunc) (    /* no need for font.h */
+#if NeedNestedPrototypes
+               ClientPtr       /* pClient */,
+               int *           /* num */
+#endif
+);
+}           ClientRec;
+
+/* This prototype is used pervasively in Xext, dix */
+#if NeedFunctionPrototypes
+#define DISPATCH_PROC(func) int func(ClientPtr /* client */)
+#else
+#define DISPATCH_PROC(func) int func(/* ClientPtr client */)
+#endif
+
+typedef struct _WorkQueue {
+    struct _WorkQueue *next;
+    Bool        (*function) (
+#if NeedNestedPrototypes
+               ClientPtr       /* pClient */,
+               pointer         /* closure */
+#endif
+);
+    ClientPtr   client;
+    pointer     closure;
+}           WorkQueueRec;
+
+extern TimeStamp currentTime;
+extern TimeStamp lastDeviceEventTime;
+
+extern int CompareTimeStamps(
+#if NeedFunctionPrototypes
+    TimeStamp /*a*/,
+    TimeStamp /*b*/
+#endif
+);
+
+extern TimeStamp ClientTimeToServerTime(
+#if NeedFunctionPrototypes
+    CARD32 /*c*/
+#endif
+);
+
+typedef struct _CallbackRec {
+  CallbackProcPtr proc;
+  pointer data;
+  Bool deleted;
+  struct _CallbackRec *next;
+} CallbackRec, *CallbackPtr;
+
+typedef struct _CallbackList {
+  CallbackFuncsRec funcs;
+  int inCallback;
+  Bool deleted;
+  int numDeleted;
+  CallbackPtr list;
+} CallbackListRec;
+
+/* proc vectors */
+
+extern int (* InitialVector[3]) (
+#if NeedNestedPrototypes
+    ClientPtr /*client*/
+#endif
+);
+
+extern int (* ProcVector[256]) (
+#if NeedNestedPrototypes
+    ClientPtr /*client*/
+#endif
+);
+
+extern int (* SwappedProcVector[256]) (
+#if NeedNestedPrototypes
+    ClientPtr /*client*/
+#endif
+);
+
+#ifdef K5AUTH
+extern int (*k5_Vector[256])() =
+#if NeedNestedPrototypes
+    ClientPtr /*client*/
+#endif
+);
+#endif
+
+extern void (* ReplySwapVector[256]) ();
+
+extern int ProcBadRequest(
+#if NeedFunctionPrototypes
+    ClientPtr /*client*/
+#endif
+);
+
+#endif                         /* DIXSTRUCT_H */
diff --git a/Xserver/programs/Xserver/include/exevents.h b/Xserver/programs/Xserver/include/exevents.h
new file mode 100644 (file)
index 0000000..2ad79aa
--- /dev/null
@@ -0,0 +1,275 @@
+/* $XFree86: xc/programs/Xserver/include/exevents.h,v 3.1 1996/04/15 11:34:29 dawes Exp $ */
+/************************************************************
+
+Copyright 1996 by Thomas E. Dickey <dickey@clark.net>
+
+                        All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and its
+documentation for any purpose and without fee is hereby granted,
+provided that the above copyright notice appear in all copies and that
+both that copyright notice and this permission notice appear in
+supporting documentation, and that the name of the above listed
+copyright holder(s) not be used in advertising or publicity pertaining
+to distribution of the software without specific, written prior
+permission.
+
+THE ABOVE LISTED COPYRIGHT HOLDER(S) DISCLAIM ALL WARRANTIES WITH REGARD
+TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+AND FITNESS, IN NO EVENT SHALL THE ABOVE LISTED COPYRIGHT HOLDER(S) BE
+LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+
+********************************************************/
+
+/********************************************************************
+ * Interface of 'exevents.c'
+ */
+
+#ifndef EXEVENTS_H
+#define EXEVENTS_H
+
+void
+RegisterOtherDevice (
+#if NeedFunctionPrototypes
+       DeviceIntPtr           /* device */
+#endif
+       );
+
+void
+ProcessOtherEvent (
+#if NeedFunctionPrototypes
+       xEventPtr /* FIXME deviceKeyButtonPointer * xE */,
+       DeviceIntPtr           /* other */,
+       int                    /* count */
+#endif
+       );
+
+int
+InitProximityClassDeviceStruct(
+#if NeedFunctionPrototypes
+       DeviceIntPtr           /* dev */
+#endif
+       );
+
+void
+InitValuatorAxisStruct(
+#if NeedFunctionPrototypes
+       DeviceIntPtr           /* dev */,
+       int                    /* axnum */,
+       int                    /* minval */,
+       int                    /* maxval */,
+       int                    /* resolution */,
+       int                    /* min_res */,
+       int                    /* max_res */
+#endif
+       );
+
+void
+DeviceFocusEvent(
+#if NeedFunctionPrototypes
+       DeviceIntPtr           /* dev */,
+       int                    /* type */,
+       int                    /* mode */,
+       int                    /* detail */,
+       WindowPtr              /* pWin */
+#endif
+       );
+
+int
+GrabButton(
+#if NeedFunctionPrototypes
+       ClientPtr              /* client */,
+       DeviceIntPtr           /* dev */,
+       BYTE                   /* this_device_mode */,
+       BYTE                   /* other_devices_mode */,
+       CARD16                 /* modifiers */,
+       DeviceIntPtr           /* modifier_device */,
+       CARD8                  /* button */,
+       Window                 /* grabWindow */,
+       BOOL                   /* ownerEvents */,
+       Cursor                 /* rcursor */,
+       Window                 /* rconfineTo */,
+       Mask                   /* eventMask */
+#endif
+       );
+
+int
+GrabKey(
+#if NeedFunctionPrototypes
+       ClientPtr              /* client */,
+       DeviceIntPtr           /* dev */,
+       BYTE                   /* this_device_mode */,
+       BYTE                   /* other_devices_mode */,
+       CARD16                 /* modifiers */,
+       DeviceIntPtr           /* modifier_device */,
+       CARD8                  /* key */,
+       Window                 /* grabWindow */,
+       BOOL                   /* ownerEvents */,
+       Mask                   /* mask */
+#endif
+       );
+
+int
+SelectForWindow(
+#if NeedFunctionPrototypes
+       DeviceIntPtr           /* dev */,
+       WindowPtr              /* pWin */,
+       ClientPtr              /* client */,
+       Mask                   /* mask */,
+       Mask                   /* exclusivemasks */,
+       Mask                   /* validmasks */
+#endif
+       );
+
+int 
+AddExtensionClient (
+#if NeedFunctionPrototypes
+       WindowPtr              /* pWin */,
+       ClientPtr              /* client */,
+       Mask                   /* mask */,
+       int                    /* mskidx */
+#endif
+       );
+
+void
+RecalculateDeviceDeliverableEvents(
+#if NeedFunctionPrototypes
+       WindowPtr              /* pWin */
+#endif
+       );
+
+int
+InputClientGone(
+#if NeedFunctionPrototypes
+       WindowPtr              /* pWin */,
+       XID                    /* id */
+#endif
+       );
+
+int
+SendEvent (
+#if NeedFunctionPrototypes
+       ClientPtr              /* client */,
+       DeviceIntPtr           /* d */,
+       Window                 /* dest */,
+       Bool                   /* propagate */,
+       xEvent *               /* ev */,
+       Mask                   /* mask */,
+       int                    /* count */
+#endif
+       );
+
+int
+SetButtonMapping (
+#if NeedFunctionPrototypes
+       ClientPtr              /* client */,
+       DeviceIntPtr           /* dev */,
+       int                    /* nElts */,
+       BYTE *                 /* map */
+#endif
+       );
+
+int 
+SetModifierMapping(
+#if NeedFunctionPrototypes
+       ClientPtr              /* client */,
+       DeviceIntPtr           /* dev */,
+       int                    /* len */,
+       int                    /* rlen */,
+       int                    /* numKeyPerModifier */,
+       KeyCode *              /* inputMap */,
+       KeyClassPtr *          /* k */
+#endif
+       );
+
+void
+SendDeviceMappingNotify(
+#if NeedFunctionPrototypes
+       CARD8                  /* request, */,
+       KeyCode                /* firstKeyCode */,
+       CARD8                  /* count */,
+       DeviceIntPtr           /* dev */
+#endif
+);
+
+int
+ChangeKeyMapping(
+#if NeedFunctionPrototypes
+       ClientPtr              /* client */,
+       DeviceIntPtr           /* dev */,
+       unsigned               /* len */,
+       int                    /* type */,
+       KeyCode                /* firstKeyCode */,
+       CARD8                  /* keyCodes */,
+       CARD8                  /* keySymsPerKeyCode */,
+       KeySym *               /* map */
+#endif
+       );
+
+void
+DeleteWindowFromAnyExtEvents(
+#if NeedFunctionPrototypes
+       WindowPtr              /* pWin */,
+       Bool                   /* freeResources */
+#endif
+);
+
+void
+DeleteDeviceFromAnyExtEvents(
+#if NeedFunctionPrototypes
+       WindowPtr              /* pWin */,
+       DeviceIntPtr           /* dev */
+#endif
+       );
+
+int
+MaybeSendDeviceMotionNotifyHint (
+#if NeedFunctionPrototypes
+       deviceKeyButtonPointer * /* pEvents */,
+       Mask                   /* mask */
+#endif
+);
+
+void
+CheckDeviceGrabAndHintWindow (
+#if NeedFunctionPrototypes
+       WindowPtr              /* pWin */,
+       int                    /* type */,
+       deviceKeyButtonPointer * /* xE */,
+       GrabPtr                /* grab */,
+       ClientPtr              /* client */,
+       Mask                   /* deliveryMask */
+#endif
+       );
+
+Mask
+DeviceEventMaskForClient(
+#if NeedFunctionPrototypes
+       DeviceIntPtr           /* dev */,
+       WindowPtr              /* pWin */,
+       ClientPtr              /* client */
+#endif
+);
+
+void
+MaybeStopDeviceHint(
+#if NeedFunctionPrototypes
+       DeviceIntPtr           /* dev */,
+       ClientPtr              /* client */
+#endif
+       );
+
+int
+DeviceEventSuppressForWindow(
+#if NeedFunctionPrototypes
+       WindowPtr              /* pWin */,
+       ClientPtr              /* client */,
+       Mask                   /* mask */,
+       int                    /* maskndx */
+#endif
+       );
+
+#endif /* EXEVENTS_H */
diff --git a/Xserver/programs/Xserver/include/extension.h b/Xserver/programs/Xserver/include/extension.h
new file mode 100644 (file)
index 0000000..454e5d7
--- /dev/null
@@ -0,0 +1,81 @@
+/* $XConsortium: extension.h /main/9 1995/09/22 10:23:04 dpw $ */
+/***********************************************************
+
+Copyright (c) 1987  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+
+Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
+
+                        All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and its 
+documentation for any purpose and without fee is hereby granted, 
+provided that the above copyright notice appear in all copies and that
+both that copyright notice and this permission notice appear in 
+supporting documentation, and that the name of Digital not be
+used in advertising or publicity pertaining to distribution of the
+software without specific, written prior permission.  
+
+DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
+ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
+DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
+ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+SOFTWARE.
+
+******************************************************************/
+#ifndef EXTENSION_H
+#define EXTENSION_H 
+
+_XFUNCPROTOBEGIN
+
+extern unsigned short StandardMinorOpcode(
+#if NeedFunctionPrototypes
+    ClientPtr /*client*/
+#endif
+);
+
+extern unsigned short MinorOpcodeOfRequest(
+#if NeedFunctionPrototypes
+    ClientPtr /*client*/
+#endif
+);
+
+extern void InitExtensions(
+#if NeedFunctionPrototypes
+    int argc,
+    char **argv
+#endif
+);
+
+extern void CloseDownExtensions(
+#if NeedFunctionPrototypes
+    void
+#endif
+);
+
+_XFUNCPROTOEND
+
+#endif /* EXTENSION_H */
diff --git a/Xserver/programs/Xserver/include/extinit.h b/Xserver/programs/Xserver/include/extinit.h
new file mode 100644 (file)
index 0000000..6364f18
--- /dev/null
@@ -0,0 +1,210 @@
+/* $XFree86: xc/programs/Xserver/include/extinit.h,v 3.1 1996/04/15 11:34:30 dawes Exp $ */
+/************************************************************
+
+Copyright 1996 by Thomas E. Dickey <dickey@clark.net>
+
+                        All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and its
+documentation for any purpose and without fee is hereby granted,
+provided that the above copyright notice appear in all copies and that
+both that copyright notice and this permission notice appear in
+supporting documentation, and that the name of the above listed
+copyright holder(s) not be used in advertising or publicity pertaining
+to distribution of the software without specific, written prior
+permission.
+
+THE ABOVE LISTED COPYRIGHT HOLDER(S) DISCLAIM ALL WARRANTIES WITH REGARD
+TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+AND FITNESS, IN NO EVENT SHALL THE ABOVE LISTED COPYRIGHT HOLDER(S) BE
+LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+
+********************************************************/
+
+/********************************************************************
+ * Interface of extinit.c
+ */
+
+#ifndef EXTINIT_H
+#define EXTINIT_H
+
+void
+XInputExtensionInit(
+#if NeedFunctionPrototypes
+       void
+#endif
+       );
+
+
+int
+ProcIDispatch (
+#if NeedFunctionPrototypes
+       ClientPtr              /* client */
+#endif
+       );
+
+int
+SProcIDispatch(
+#if NeedFunctionPrototypes
+       ClientPtr              /* client */
+#endif
+       );
+
+void
+SReplyIDispatch (
+#if NeedFunctionPrototypes
+       ClientPtr              /* client */,
+       int                    /* len */,
+       xGrabDeviceReply *     /* rep */
+#endif
+       );
+
+void
+SEventIDispatch (
+#if NeedFunctionPrototypes
+       xEvent *               /* from */,
+       xEvent *               /* to */
+#endif
+       );
+
+void
+SEventDeviceValuator (
+#if NeedFunctionPrototypes
+       deviceValuator *       /* from */,
+       deviceValuator *       /* to */
+#endif
+       );
+
+void
+SEventFocus (
+#if NeedFunctionPrototypes
+       deviceFocus *          /* from */,
+       deviceFocus *          /* to */
+#endif
+       );
+
+void
+SDeviceStateNotifyEvent (
+#if NeedFunctionPrototypes
+       deviceStateNotify *    /* from */,
+       deviceStateNotify *    /* to */
+#endif
+       );
+
+void
+SDeviceKeyStateNotifyEvent (
+#if NeedFunctionPrototypes
+       deviceKeyStateNotify * /* from */,
+       deviceKeyStateNotify * /* to */
+#endif
+       );
+
+void
+SDeviceButtonStateNotifyEvent (
+#if NeedFunctionPrototypes
+       deviceButtonStateNotify * /* from */,
+       deviceButtonStateNotify * /* to */
+#endif
+       );
+
+void
+SChangeDeviceNotifyEvent (
+#if NeedFunctionPrototypes
+       changeDeviceNotify *   /* from */,
+       changeDeviceNotify *   /* to */
+#endif
+       );
+
+void
+SDeviceMappingNotifyEvent (
+#if NeedFunctionPrototypes
+       deviceMappingNotify *  /* from */,
+       deviceMappingNotify *  /* to */
+#endif
+       );
+
+void
+FixExtensionEvents (
+#if NeedFunctionPrototypes
+       ExtensionEntry  *      /* extEntry */
+#endif
+       );
+
+void
+RestoreExtensionEvents (
+#if NeedFunctionPrototypes
+       void
+#endif
+       );
+
+void
+IResetProc(
+#if NeedFunctionPrototypes
+       ExtensionEntry *       /* unused */
+#endif
+       );
+
+void
+AssignTypeAndName (
+#if NeedFunctionPrototypes
+       DeviceIntPtr           /* dev */,
+       Atom                   /* type */,
+       char *                 /* name */
+#endif
+       );
+
+void
+MakeDeviceTypeAtoms (
+#if NeedFunctionPrototypes
+       void
+#endif
+);
+
+DeviceIntPtr
+LookupDeviceIntRec (
+#if NeedFunctionPrototypes
+       CARD8                  /* id */
+#endif
+       );
+
+void
+SetExclusiveAccess (
+#if NeedFunctionPrototypes
+       Mask                   /* mask */
+#endif
+       );
+
+void
+AllowPropagateSuppress (
+#if NeedFunctionPrototypes
+       Mask                   /* mask */
+#endif
+       );
+
+Mask
+GetNextExtEventMask (
+#if NeedFunctionPrototypes
+       void
+#endif
+);
+
+void
+SetMaskForExtEvent(
+#if NeedFunctionPrototypes
+       Mask                   /* mask */,
+       int                    /* event */
+#endif
+       );
+
+void
+SetEventInfo(
+#if NeedFunctionPrototypes
+       Mask                   /* mask */,
+       int                    /* constant */
+#endif
+       );
+
+#endif /* EXTINIT_H */
diff --git a/Xserver/programs/Xserver/include/extnsionst.h b/Xserver/programs/Xserver/include/extnsionst.h
new file mode 100644 (file)
index 0000000..b21ac19
--- /dev/null
@@ -0,0 +1,194 @@
+/* $XConsortium: extnsionst.h /main/15 1996/08/01 19:18:11 dpw $ */
+/* $XFree86: xc/programs/Xserver/include/extnsionst.h,v 3.2 1996/12/23 07:09:27 dawes Exp $ */
+/***********************************************************
+
+Copyright (c) 1987  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+
+Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
+
+                        All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and its 
+documentation for any purpose and without fee is hereby granted, 
+provided that the above copyright notice appear in all copies and that
+both that copyright notice and this permission notice appear in 
+supporting documentation, and that the name of Digital not be
+used in advertising or publicity pertaining to distribution of the
+software without specific, written prior permission.  
+
+DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
+ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
+DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
+ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+SOFTWARE.
+
+******************************************************************/
+#ifndef EXTENSIONSTRUCT_H
+#define EXTENSIONSTRUCT_H 
+
+#include "misc.h"
+#include "screenint.h"
+#include "extension.h"
+#include "gc.h"
+
+typedef struct _ExtensionEntry {
+    int index;
+    void (* CloseDown)(        /* called at server shutdown */
+#if NeedNestedPrototypes
+       struct _ExtensionEntry * /* extension */
+#endif
+);
+    char *name;               /* extension name */
+    int base;                 /* base request number */
+    int eventBase;            
+    int eventLast;
+    int errorBase;
+    int errorLast;
+    int num_aliases;
+    char **aliases;
+    pointer extPrivate;
+    unsigned short (* MinorOpcode)(    /* called for errors */
+#if NeedNestedPrototypes
+       ClientPtr /* client */
+#endif
+);
+#ifdef XCSECURITY
+    Bool secure;               /* extension visible to untrusted clients? */
+#endif
+} ExtensionEntry;
+
+/* any attempt to declare the types of the parameters to the functions
+ * in EventSwapVector fails.  The functions take pointers to two events,
+ * but the exact event types that are declared vary from one function 
+ * to another.  You can't even put void *, void * (the ibm compiler
+ * complains, anyway).
+ */
+typedef void (*EventSwapPtr) (
+#if NeedFunctionPrototypes && defined(EVENT_SWAP_PTR)
+       xEvent *,
+       xEvent *
+#endif
+);
+
+extern EventSwapPtr EventSwapVector[128];
+
+extern void NotImplemented (   /* FIXME: this may move to another file... */
+#if NeedFunctionPrototypes && defined(EVENT_SWAP_PTR)
+       xEvent *,
+       xEvent *
+#endif
+);
+
+typedef void (* ExtensionLookupProc)(  /*args indeterminate*/
+#ifdef EXTENSION_PROC_ARGS
+       EXTENSION_PROC_ARGS
+#endif
+);
+
+typedef struct _ProcEntry {
+    char *name;
+    ExtensionLookupProc proc;
+} ProcEntryRec, *ProcEntryPtr;
+
+typedef struct _ScreenProcEntry {
+    int num;
+    ProcEntryPtr procList;
+} ScreenProcEntry;
+
+#define    SetGCVector(pGC, VectorElement, NewRoutineAddress, Atom)    \
+    pGC->VectorElement = NewRoutineAddress;
+
+#define    GetGCValue(pGC, GCElement)    (pGC->GCElement)
+
+
+extern ExtensionEntry *AddExtension(
+#if NeedFunctionPrototypes
+    char* /*name*/,
+    int /*NumEvents*/,
+    int /*NumErrors*/,
+    int (* /*MainProc*/)(
+#if NeedNestedPrototypes
+       ClientPtr /*client*/
+#endif
+),
+    int (* /*SwappedMainProc*/)(
+#if NeedNestedPrototypes
+       ClientPtr /*client*/
+#endif
+),
+    void (* /*CloseDownProc*/)(
+#if NeedNestedPrototypes
+       ExtensionEntry * /*extension*/
+#endif
+),
+    unsigned short (* /*MinorOpcodeProc*/)(
+#if NeedNestedPrototypes
+       ClientPtr /*client*/
+#endif
+       )
+#endif /* NeedFunctionPrototypes */
+);
+
+extern Bool AddExtensionAlias(
+#if NeedFunctionPrototypes
+    char* /*alias*/,
+    ExtensionEntry * /*extension*/
+#endif
+);
+
+extern ExtensionLookupProc LookupProc(
+#if NeedFunctionPrototypes
+    char* /*name*/,
+    GCPtr /*pGC*/
+#endif
+);
+
+extern Bool RegisterProc(
+#if NeedFunctionPrototypes
+    char* /*name*/,
+    GCPtr /*pGC*/,
+    ExtensionLookupProc /*proc*/
+#endif
+);
+
+extern Bool RegisterScreenProc(
+#if NeedFunctionPrototypes
+    char* /*name*/,
+    ScreenPtr /*pScreen*/,
+    ExtensionLookupProc /*proc*/
+#endif
+);
+
+extern void DeclareExtensionSecurity(
+#if NeedFunctionPrototypes
+    char * /*extname*/,
+    Bool /*secure*/
+#endif
+);
+
+#endif /* EXTENSIONSTRUCT_H */
+
diff --git a/Xserver/programs/Xserver/include/gc.h b/Xserver/programs/Xserver/include/gc.h
new file mode 100644 (file)
index 0000000..37e362d
--- /dev/null
@@ -0,0 +1,232 @@
+/***********************************************************
+
+Copyright (c) 1987  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+
+Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
+
+                        All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and its 
+documentation for any purpose and without fee is hereby granted, 
+provided that the above copyright notice appear in all copies and that
+both that copyright notice and this permission notice appear in 
+supporting documentation, and that the name of Digital not be
+used in advertising or publicity pertaining to distribution of the
+software without specific, written prior permission.  
+
+DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
+ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
+DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
+ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+SOFTWARE.
+
+******************************************************************/
+/* $XConsortium: gc.h /main/16 1996/08/01 19:18:17 dpw $ */
+
+#ifndef GC_H
+#define GC_H 
+
+#include "misc.h"      /* for Bool */
+#include "X11/X.h"     /* for GContext, Mask */
+#include "X11/Xproto.h"
+#include "screenint.h" /* for ScreenPtr */
+#include "pixmap.h"    /* for DrawablePtr */
+
+/* clientClipType field in GC */
+#define CT_NONE                        0
+#define CT_PIXMAP              1
+#define CT_REGION              2
+#define CT_UNSORTED            6
+#define CT_YSORTED             10
+#define CT_YXSORTED            14
+#define CT_YXBANDED            18
+
+#define GCQREASON_VALIDATE     1
+#define GCQREASON_CHANGE       2
+#define GCQREASON_COPY_SRC     3
+#define GCQREASON_COPY_DST     4
+#define GCQREASON_DESTROY      5
+
+#define GC_CHANGE_SERIAL_BIT        (((unsigned long)1)<<31)
+#define GC_CALL_VALIDATE_BIT        (1L<<30)
+#define GCExtensionInterest   (1L<<29)
+
+#define DRAWABLE_SERIAL_BITS        (~(GC_CHANGE_SERIAL_BIT))
+
+#define MAX_SERIAL_NUM     (1L<<28)
+
+#define NEXT_SERIAL_NUMBER ((++globalSerialNumber) > MAX_SERIAL_NUM ? \
+           (globalSerialNumber  = 1): globalSerialNumber)
+
+typedef struct _GCInterest *GCInterestPtr;
+typedef struct _GC    *GCPtr;
+typedef struct _GCOps *GCOpsPtr;
+
+extern void ValidateGC(
+#if NeedFunctionPrototypes
+    DrawablePtr /*pDraw*/,
+    GCPtr /*pGC*/
+#endif
+);
+
+extern int ChangeGC(
+#if NeedFunctionPrototypes
+    GCPtr/*pGC*/,
+    BITS32 /*mask*/,
+    XID* /*pval*/
+#endif
+);
+
+extern int DoChangeGC(
+#if NeedFunctionPrototypes
+    GCPtr/*pGC*/,
+    BITS32 /*mask*/,
+    XID* /*pval*/,
+    int /*fPointer*/
+#endif
+);
+
+typedef union {
+    CARD32 val;
+    pointer ptr;
+} ChangeGCVal, *ChangeGCValPtr;
+
+extern int dixChangeGC(
+#if NeedFunctionPrototypes
+    ClientPtr /*client*/,
+    GCPtr /*pGC*/,
+    BITS32 /*mask*/,
+    CARD32 * /*pval*/,
+    ChangeGCValPtr /*pCGCV*/
+#endif
+);
+
+extern GCPtr CreateGC(
+#if NeedFunctionPrototypes
+    DrawablePtr /*pDrawable*/,
+    BITS32 /*mask*/,
+    XID* /*pval*/,
+    int* /*pStatus*/
+#endif
+);
+
+extern int CopyGC(
+#if NeedFunctionPrototypes
+    GCPtr/*pgcSrc*/,
+    GCPtr/*pgcDst*/,
+    BITS32 /*mask*/
+#endif
+);
+
+extern int FreeGC(
+#if NeedFunctionPrototypes
+    pointer /*pGC*/,
+    XID /*gid*/
+#endif
+);
+
+extern void SetGCMask(
+#if NeedFunctionPrototypes
+    GCPtr /*pGC*/,
+    Mask /*selectMask*/,
+    Mask /*newDataMask*/
+#endif
+);
+
+extern GCPtr CreateScratchGC(
+#if NeedFunctionPrototypes
+    ScreenPtr /*pScreen*/,
+    unsigned /*depth*/
+#endif
+);
+
+extern void FreeGCperDepth(
+#if NeedFunctionPrototypes
+    int /*screenNum*/
+#endif
+);
+
+extern Bool CreateGCperDepth(
+#if NeedFunctionPrototypes
+    int /*screenNum*/
+#endif
+);
+
+extern Bool CreateDefaultStipple(
+#if NeedFunctionPrototypes
+    int /*screenNum*/
+#endif
+);
+
+extern void FreeDefaultStipple(
+#if NeedFunctionPrototypes
+    int /*screenNum*/
+#endif
+);
+
+extern int SetDashes(
+#if NeedFunctionPrototypes
+    GCPtr /*pGC*/,
+    unsigned /*offset*/,
+    unsigned /*ndash*/,
+    unsigned char* /*pdash*/
+#endif
+);
+
+extern int VerifyRectOrder(
+#if NeedFunctionPrototypes
+    int /*nrects*/,
+    xRectangle* /*prects*/,
+    int /*ordering*/
+#endif
+);
+
+extern int SetClipRects(
+#if NeedFunctionPrototypes
+    GCPtr /*pGC*/,
+    int /*xOrigin*/,
+    int /*yOrigin*/,
+    int /*nrects*/,
+    xRectangle* /*prects*/,
+    int /*ordering*/
+#endif
+);
+
+extern GCPtr GetScratchGC(
+#if NeedFunctionPrototypes
+    unsigned /*depth*/,
+    ScreenPtr /*pScreen*/
+#endif
+);
+
+extern void FreeScratchGC(
+#if NeedFunctionPrototypes
+    GCPtr /*pGC*/
+#endif
+);
+
+#endif /* GC_H */
diff --git a/Xserver/programs/Xserver/include/gcstruct.h b/Xserver/programs/Xserver/include/gcstruct.h
new file mode 100644 (file)
index 0000000..34fa943
--- /dev/null
@@ -0,0 +1,397 @@
+/* $XConsortium: gcstruct.h,v 5.10 94/04/17 20:25:45 dpw Exp $ */
+/***********************************************************
+
+Copyright (c) 1987  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+
+Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
+
+                        All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and its 
+documentation for any purpose and without fee is hereby granted, 
+provided that the above copyright notice appear in all copies and that
+both that copyright notice and this permission notice appear in 
+supporting documentation, and that the name of Digital not be
+used in advertising or publicity pertaining to distribution of the
+software without specific, written prior permission.  
+
+DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
+ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
+DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
+ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+SOFTWARE.
+
+******************************************************************/
+
+#ifndef GCSTRUCT_H
+#define GCSTRUCT_H
+
+#include "gc.h"
+
+#include "miscstruct.h"
+#include "region.h"
+#include "pixmap.h"
+#include "screenint.h"
+#include "Xprotostr.h"
+
+/*
+ * functions which modify the state of the GC
+ */
+
+typedef struct _GCFuncs {
+    void       (* ValidateGC)(
+#if NeedNestedPrototypes
+               GCPtr /*pGC*/,
+               unsigned long /*stateChanges*/,
+               DrawablePtr /*pDrawable*/
+#endif
+);
+
+    void       (* ChangeGC)(
+#if NeedNestedPrototypes
+               GCPtr /*pGC*/,
+               unsigned long /*mask*/
+#endif
+);
+
+    void       (* CopyGC)(
+#if NeedNestedPrototypes
+               GCPtr /*pGCSrc*/,
+               unsigned long /*mask*/,
+               GCPtr /*pGCDst*/
+#endif
+);
+
+    void       (* DestroyGC)(
+#if NeedNestedPrototypes
+               GCPtr /*pGC*/
+#endif
+);
+
+    void       (* ChangeClip)(
+#if NeedNestedPrototypes
+               GCPtr /*pGC*/,
+               int /*type*/,
+               pointer /*pvalue*/,
+               int /*nrects*/
+#endif
+);
+
+    void       (* DestroyClip)(
+#if NeedNestedPrototypes
+               GCPtr /*pGC*/
+#endif
+);
+
+    void       (* CopyClip)(
+#if NeedNestedPrototypes
+               GCPtr /*pgcDst*/,
+               GCPtr /*pgcSrc*/
+#endif
+);
+    DevUnion   devPrivate;
+} GCFuncs;
+
+/*
+ * graphics operations invoked through a GC
+ */
+
+typedef struct _GCOps {
+    void       (* FillSpans)(
+#if NeedNestedPrototypes
+               DrawablePtr /*pDrawable*/,
+               GCPtr /*pGC*/,
+               int /*nInit*/,
+               DDXPointPtr /*pptInit*/,
+               int * /*pwidthInit*/,
+               int /*fSorted*/
+#endif
+);
+
+    void       (* SetSpans)(
+#if NeedNestedPrototypes
+               DrawablePtr /*pDrawable*/,
+               GCPtr /*pGC*/,
+               char * /*psrc*/,
+               DDXPointPtr /*ppt*/,
+               int * /*pwidth*/,
+               int /*nspans*/,
+               int /*fSorted*/
+#endif
+);
+
+    void       (* PutImage)(
+#if NeedNestedPrototypes
+               DrawablePtr /*pDrawable*/,
+               GCPtr /*pGC*/,
+               int /*depth*/,
+               int /*x*/,
+               int /*y*/,
+               int /*w*/,
+               int /*h*/,
+               int /*leftPad*/,
+               int /*format*/,
+               char * /*pBits*/
+#endif
+);
+
+    RegionPtr  (* CopyArea)(
+#if NeedNestedPrototypes
+               DrawablePtr /*pSrc*/,
+               DrawablePtr /*pDst*/,
+               GCPtr /*pGC*/,
+               int /*srcx*/,
+               int /*srcy*/,
+               int /*w*/,
+               int /*h*/,
+               int /*dstx*/,
+               int /*dsty*/
+#endif
+);
+
+    RegionPtr  (* CopyPlane)(
+#if NeedNestedPrototypes
+               DrawablePtr /*pSrcDrawable*/,
+               DrawablePtr /*pDstDrawable*/,
+               GCPtr /*pGC*/,
+               int /*srcx*/,
+               int /*srcy*/,
+               int /*width*/,
+               int /*height*/,
+               int /*dstx*/,
+               int /*dsty*/,
+               unsigned long /*bitPlane*/
+#endif
+);
+    void       (* PolyPoint)(
+#if NeedNestedPrototypes
+               DrawablePtr /*pDrawable*/,
+               GCPtr /*pGC*/,
+               int /*mode*/,
+               int /*npt*/,
+               DDXPointPtr /*pptInit*/
+#endif
+);
+
+    void       (* Polylines)(
+#if NeedNestedPrototypes
+               DrawablePtr /*pDrawable*/,
+               GCPtr /*pGC*/,
+               int /*mode*/,
+               int /*npt*/,
+               DDXPointPtr /*pptInit*/
+#endif
+);
+
+    void       (* PolySegment)(
+#if NeedNestedPrototypes
+               DrawablePtr /*pDrawable*/,
+               GCPtr /*pGC*/,
+               int /*nseg*/,
+               xSegment * /*pSegs*/
+#endif
+);
+
+    void       (* PolyRectangle)(
+#if NeedNestedPrototypes
+               DrawablePtr /*pDrawable*/,
+               GCPtr /*pGC*/,
+               int /*nrects*/,
+               xRectangle * /*pRects*/
+#endif
+);
+
+    void       (* PolyArc)(
+#if NeedNestedPrototypes
+               DrawablePtr /*pDrawable*/,
+               GCPtr /*pGC*/,
+               int /*narcs*/,
+               xArc * /*parcs*/
+#endif
+);
+
+    void       (* FillPolygon)(
+#if NeedNestedPrototypes
+               DrawablePtr /*pDrawable*/,
+               GCPtr /*pGC*/,
+               int /*shape*/,
+               int /*mode*/,
+               int /*count*/,
+               DDXPointPtr /*pPts*/
+#endif
+);
+
+    void       (* PolyFillRect)(
+#if NeedNestedPrototypes
+               DrawablePtr /*pDrawable*/,
+               GCPtr /*pGC*/,
+               int /*nrectFill*/,
+               xRectangle * /*prectInit*/
+#endif
+);
+
+    void       (* PolyFillArc)(
+#if NeedNestedPrototypes
+               DrawablePtr /*pDrawable*/,
+               GCPtr /*pGC*/,
+               int /*narcs*/,
+               xArc * /*parcs*/
+#endif
+);
+
+    int                (* PolyText8)(
+#if NeedNestedPrototypes
+               DrawablePtr /*pDrawable*/,
+               GCPtr /*pGC*/,
+               int /*x*/,
+               int /*y*/,
+               int /*count*/,
+               char * /*chars*/
+#endif
+);
+
+    int                (* PolyText16)(
+#if NeedNestedPrototypes
+               DrawablePtr /*pDrawable*/,
+               GCPtr /*pGC*/,
+               int /*x*/,
+               int /*y*/,
+               int /*count*/,
+               unsigned short * /*chars*/
+#endif
+);
+
+    void       (* ImageText8)(
+#if NeedNestedPrototypes
+               DrawablePtr /*pDrawable*/,
+               GCPtr /*pGC*/,
+               int /*x*/,
+               int /*y*/,
+               int /*count*/,
+               char * /*chars*/
+#endif
+);
+
+    void       (* ImageText16)(
+#if NeedNestedPrototypes
+               DrawablePtr /*pDrawable*/,
+               GCPtr /*pGC*/,
+               int /*x*/,
+               int /*y*/,
+               int /*count*/,
+               unsigned short * /*chars*/
+#endif
+);
+
+    void       (* ImageGlyphBlt)(
+#if NeedNestedPrototypes
+               DrawablePtr /*pDrawable*/,
+               GCPtr /*pGC*/,
+               int /*x*/,
+               int /*y*/,
+               unsigned int /*nglyph*/,
+               CharInfoPtr * /*ppci*/,
+               pointer /*pglyphBase*/
+#endif
+);
+
+    void       (* PolyGlyphBlt)(
+#if NeedNestedPrototypes
+               DrawablePtr /*pDrawable*/,
+               GCPtr /*pGC*/,
+               int /*x*/,
+               int /*y*/,
+               unsigned int /*nglyph*/,
+               CharInfoPtr * /*ppci*/,
+               pointer /*pglyphBase*/
+#endif
+);
+
+    void       (* PushPixels)(
+#if NeedNestedPrototypes
+               GCPtr /*pGC*/,
+               PixmapPtr /*pBitMap*/,
+               DrawablePtr /*pDst*/,
+               int /*w*/,
+               int /*h*/,
+               int /*x*/,
+               int /*y*/
+#endif
+);
+
+#ifdef NEED_LINEHELPER
+    void       (* LineHelper)();
+#endif
+
+    DevUnion   devPrivate;
+} GCOps;
+
+/* there is padding in the bit fields because the Sun compiler doesn't
+ * force alignment to 32-bit boundaries.  losers.
+ */
+typedef struct _GC {
+    ScreenPtr          pScreen;                
+    unsigned char      depth;    
+    unsigned char      alu;
+    unsigned short     lineWidth;          
+    unsigned short     dashOffset;
+    unsigned short     numInDashList;
+    unsigned char      *dash;
+    unsigned int       lineStyle : 2;
+    unsigned int       capStyle : 2;
+    unsigned int       joinStyle : 2;
+    unsigned int       fillStyle : 2;
+    unsigned int       fillRule : 1;
+    unsigned int       arcMode : 1;
+    unsigned int       subWindowMode : 1;
+    unsigned int       graphicsExposures : 1;
+    unsigned int       clientClipType : 2; /* CT_<kind> */
+    unsigned int       miTranslate:1; /* should mi things translate? */
+    unsigned int       tileIsPixel:1; /* tile is solid pixel */
+    unsigned int       unused:16; /* see comment above */
+    unsigned long      planemask;
+    unsigned long      fgPixel;
+    unsigned long      bgPixel;
+    /*
+     * alas -- both tile and stipple must be here as they
+     * are independently specifiable
+     */
+    PixUnion           tile;
+    PixmapPtr          stipple;
+    DDXPointRec                patOrg;         /* origin for (tile, stipple) */
+    struct _Font       *font;
+    DDXPointRec                clipOrg;
+    DDXPointRec                lastWinOrg;     /* position of window last validated */
+    pointer            clientClip;
+    unsigned long      stateChanges;   /* masked with GC_<kind> */
+    unsigned long       serialNumber;
+    GCFuncs            *funcs;
+    GCOps              *ops;
+    DevUnion           *devPrivates;
+} GC;
+
+#endif /* GCSTRUCT_H */
diff --git a/Xserver/programs/Xserver/include/input.h b/Xserver/programs/Xserver/include/input.h
new file mode 100644 (file)
index 0000000..63421de
--- /dev/null
@@ -0,0 +1,535 @@
+/* $XConsortium: input.h /main/22 1996/09/25 00:50:39 dpw $ */
+/* $XFree86: xc/programs/Xserver/include/input.h,v 3.4 1996/12/23 07:09:28 dawes Exp $ */
+/************************************************************
+
+Copyright (c) 1987  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+
+Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
+
+                        All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and its 
+documentation for any purpose and without fee is hereby granted, 
+provided that the above copyright notice appear in all copies and that
+both that copyright notice and this permission notice appear in 
+supporting documentation, and that the name of Digital not be
+used in advertising or publicity pertaining to distribution of the
+software without specific, written prior permission.  
+
+DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
+ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
+DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
+ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+SOFTWARE.
+
+********************************************************/
+#ifndef INPUT_H
+#define INPUT_H
+
+#include "misc.h"
+#include "screenint.h"
+#include "X11/Xmd.h"
+#include "X11/Xproto.h"
+#include "window.h"     /* for WindowPtr */
+
+#define DEVICE_INIT    0
+#define DEVICE_ON      1
+#define DEVICE_OFF     2
+#define DEVICE_CLOSE   3
+
+#define MAP_LENGTH     256
+#define DOWN_LENGTH    32      /* 256/8 => number of bytes to hold 256 bits */
+#define NullGrab ((GrabPtr)NULL)
+#define PointerRootWin ((WindowPtr)PointerRoot)
+#define NoneWin ((WindowPtr)None)
+#define NullDevice ((DevicePtr)NULL)
+
+#ifndef FollowKeyboard
+#define FollowKeyboard                 3
+#endif
+#ifndef FollowKeyboardWin
+#define FollowKeyboardWin  ((WindowPtr) FollowKeyboard)
+#endif
+#ifndef RevertToFollowKeyboard
+#define RevertToFollowKeyboard 3
+#endif
+
+typedef unsigned long Leds;
+typedef struct _OtherClients *OtherClientsPtr;
+typedef struct _InputClients *InputClientsPtr;
+typedef struct _DeviceIntRec *DeviceIntPtr;
+
+typedef int (*DeviceProc)(
+#if NeedNestedPrototypes
+    DeviceIntPtr /*device*/,
+    int /*what*/
+#endif
+);
+
+typedef void (*ProcessInputProc)(
+#if NeedNestedPrototypes
+    xEventPtr /*events*/,
+    DeviceIntPtr /*device*/,
+    int /*count*/
+#endif
+);
+
+typedef struct _DeviceRec {
+    pointer    devicePrivate;
+    ProcessInputProc processInputProc; /* current */
+    ProcessInputProc realInputProc;    /* deliver */
+    ProcessInputProc enqueueInputProc; /* enqueue */
+    Bool       on;                     /* used by DDX to keep state */
+} DeviceRec, *DevicePtr;
+
+typedef struct {
+    int                        click, bell, bell_pitch, bell_duration;
+    Bool               autoRepeat;
+    unsigned char      autoRepeats[32];
+    Leds               leds;
+    unsigned char      id;
+} KeybdCtrl;
+
+typedef struct {
+    KeySym  *map;
+    KeyCode minKeyCode,
+           maxKeyCode;
+    int     mapWidth;
+} KeySymsRec, *KeySymsPtr;
+
+typedef struct {
+    int                num, den, threshold;
+    unsigned char id;
+} PtrCtrl;
+
+typedef struct {
+    int         resolution, min_value, max_value;
+    int         integer_displayed;
+    unsigned char id;
+} IntegerCtrl;
+
+typedef struct {
+    int         max_symbols, num_symbols_supported;
+    int         num_symbols_displayed;
+    KeySym      *symbols_supported;
+    KeySym      *symbols_displayed;
+    unsigned char id;
+} StringCtrl;
+
+typedef struct {
+    int         percent, pitch, duration;
+    unsigned char id;
+} BellCtrl;
+
+typedef struct {
+    Leds        led_values;
+    Mask        led_mask;
+    unsigned char id;
+} LedCtrl;
+
+extern KeybdCtrl       defaultKeyboardControl;
+extern PtrCtrl         defaultPointerControl;
+
+#undef  AddInputDevice
+extern DevicePtr AddInputDevice(
+#if NeedFunctionPrototypes
+    DeviceProc /*deviceProc*/,
+    Bool /*autoStart*/
+#endif
+);
+
+#define AddInputDevice(deviceProc, autoStart) \
+       _AddInputDevice(deviceProc, autoStart)
+
+extern DeviceIntPtr _AddInputDevice(
+#if NeedFunctionPrototypes
+    DeviceProc /*deviceProc*/,
+    Bool /*autoStart*/
+#endif
+);
+
+extern Bool EnableDevice(
+#if NeedFunctionPrototypes
+    DeviceIntPtr /*device*/
+#endif
+);
+
+extern Bool DisableDevice(
+#if NeedFunctionPrototypes
+    DeviceIntPtr /*device*/
+#endif
+);
+
+extern int InitAndStartDevices(
+#if NeedFunctionPrototypes
+    void
+#endif
+);
+
+extern void CloseDownDevices(
+#if NeedFunctionPrototypes
+    void
+#endif
+);
+
+extern void RemoveDevice(
+#if NeedFunctionPrototypes
+    DeviceIntPtr /*dev*/
+#endif
+);
+
+extern int NumMotionEvents(
+#if NeedFunctionPrototypes
+    void
+#endif
+);
+
+#undef  RegisterPointerDevice
+extern void RegisterPointerDevice(
+#if NeedFunctionPrototypes
+    DevicePtr /*device*/
+#endif
+);
+
+#define RegisterPointerDevice(device) \
+       _RegisterPointerDevice(device)
+
+extern void _RegisterPointerDevice(
+#if NeedFunctionPrototypes
+    DeviceIntPtr /*device*/
+#endif
+);
+
+#undef  RegisterKeyboardDevice
+extern void RegisterKeyboardDevice(
+#if NeedFunctionPrototypes
+    DevicePtr /*device*/
+#endif
+);
+
+#define RegisterKeyboardDevice(device) \
+       _RegisterKeyboardDevice(device)
+
+extern void _RegisterKeyboardDevice(
+#if NeedFunctionPrototypes
+    DeviceIntPtr /*device*/
+#endif
+);
+
+extern DevicePtr LookupKeyboardDevice(
+#if NeedFunctionPrototypes
+    void
+#endif
+);
+
+extern DevicePtr LookupPointerDevice(
+#if NeedFunctionPrototypes
+    void
+#endif
+);
+
+extern DevicePtr LookupDevice(
+#if NeedFunctionPrototypes
+    int /* id */
+#endif
+);
+
+extern void QueryMinMaxKeyCodes(
+#if NeedFunctionPrototypes
+    KeyCode* /*minCode*/,
+    KeyCode* /*maxCode*/
+#endif
+);
+
+extern Bool SetKeySymsMap(
+#if NeedFunctionPrototypes
+    KeySymsPtr /*dst*/,
+    KeySymsPtr /*src*/
+#endif
+);
+
+extern Bool InitKeyClassDeviceStruct(
+#if NeedFunctionPrototypes
+    DeviceIntPtr /*device*/,
+    KeySymsPtr /*pKeySyms*/,
+    CARD8 /*pModifiers*/[]
+#endif
+);
+
+extern Bool InitButtonClassDeviceStruct(
+#if NeedFunctionPrototypes
+    DeviceIntPtr /*device*/,
+    int /*numButtons*/,
+    CARD8* /*map*/
+#endif
+);
+
+typedef int (*ValuatorMotionProcPtr)(
+#if NeedNestedPrototypes
+               DeviceIntPtr /*pdevice*/,
+               xTimecoord * /*coords*/,
+               unsigned long /*start*/,
+               unsigned long /*stop*/,
+               ScreenPtr /*pScreen*/
+#endif
+);
+
+extern Bool InitValuatorClassDeviceStruct(
+#if NeedFunctionPrototypes
+    DeviceIntPtr /*device*/,
+    int /*numAxes*/,
+    ValuatorMotionProcPtr /* motionProc */,
+    int /*numMotionEvents*/,
+    int /*mode*/
+#endif
+);
+
+extern Bool InitFocusClassDeviceStruct(
+#if NeedFunctionPrototypes
+    DeviceIntPtr /*device*/
+#endif
+);
+
+typedef void (*BellProcPtr)(
+#if NeedNestedPrototypes
+    int /*percent*/,
+    DeviceIntPtr /*device*/,
+    pointer /*ctrl*/,
+    int
+#endif
+);
+
+typedef void (*KbdCtrlProcPtr)(
+#if NeedNestedPrototypes
+    DeviceIntPtr /*device*/,
+    KeybdCtrl * /*ctrl*/
+#endif                              
+);
+
+extern Bool InitKbdFeedbackClassDeviceStruct(
+#if NeedFunctionPrototypes
+    DeviceIntPtr /*device*/,
+    BellProcPtr /*bellProc*/,
+    KbdCtrlProcPtr /*controlProc*/
+#endif
+);
+
+typedef void (*PtrCtrlProcPtr)(
+#if NeedNestedPrototypes
+    DeviceIntPtr /*device*/,
+    PtrCtrl * /*ctrl*/
+#endif                              
+);
+
+extern Bool InitPtrFeedbackClassDeviceStruct(
+#if NeedFunctionPrototypes
+    DeviceIntPtr /*device*/,
+    PtrCtrlProcPtr /*controlProc*/
+#endif
+);
+
+typedef void (*StringCtrlProcPtr)(
+#if NeedNestedPrototypes
+    DeviceIntPtr /*device*/,
+    StringCtrl * /*ctrl*/
+#endif                              
+);
+
+extern Bool InitStringFeedbackClassDeviceStruct(
+#if NeedFunctionPrototypes
+    DeviceIntPtr /*device*/,
+    StringCtrlProcPtr /*controlProc*/,
+    int /*max_symbols*/,
+    int /*num_symbols_supported*/,
+    KeySym* /*symbols*/
+#endif
+);
+
+typedef void (*BellCtrlProcPtr)(
+#if NeedNestedPrototypes
+    DeviceIntPtr /*device*/,
+    BellCtrl * /*ctrl*/
+#endif                              
+);
+
+extern Bool InitBellFeedbackClassDeviceStruct(
+#if NeedFunctionPrototypes
+    DeviceIntPtr /*device*/,
+    BellProcPtr /*bellProc*/,
+    BellCtrlProcPtr /*controlProc*/
+#endif
+);
+
+typedef void (*LedCtrlProcPtr)(
+#if NeedNestedPrototypes
+    DeviceIntPtr /*device*/,
+    LedCtrl * /*ctrl*/
+#endif                              
+);
+
+extern Bool InitLedFeedbackClassDeviceStruct(
+#if NeedFunctionPrototypes
+    DeviceIntPtr /*device*/,
+    LedCtrlProcPtr /*controlProc*/
+#endif
+);
+
+typedef void (*IntegerCtrlProcPtr)(
+#if NeedNestedPrototypes
+    DeviceIntPtr /*device*/,
+    IntegerCtrl * /*ctrl*/
+#endif
+);
+
+
+extern Bool InitIntegerFeedbackClassDeviceStruct(
+#if NeedFunctionPrototypes
+    DeviceIntPtr /*device*/,
+    IntegerCtrlProcPtr /*controlProc*/
+#endif
+);
+
+extern Bool InitPointerDeviceStruct(
+#if NeedFunctionPrototypes
+    DevicePtr /*device*/,
+    CARD8* /*map*/,
+    int /*numButtons*/,
+    ValuatorMotionProcPtr /*motionProc*/,
+    PtrCtrlProcPtr /*controlProc*/,
+    int /*numMotionEvents*/
+#endif
+);
+
+extern Bool InitKeyboardDeviceStruct(
+#if NeedFunctionPrototypes
+    DevicePtr /*device*/,
+    KeySymsPtr /*pKeySyms*/,
+    CARD8 /*pModifiers*/[],
+    BellProcPtr /*bellProc*/,
+    KbdCtrlProcPtr /*controlProc*/
+#endif
+);
+
+extern void SendMappingNotify(
+#if NeedFunctionPrototypes
+    unsigned int /*request*/,
+    unsigned int /*firstKeyCode*/,
+    unsigned int /*count*/,
+    ClientPtr  /* client */
+#endif
+);
+
+extern Bool BadDeviceMap(
+#if NeedFunctionPrototypes
+    BYTE* /*buff*/,
+    int /*length*/,
+    unsigned /*low*/,
+    unsigned /*high*/,
+    XID* /*errval*/
+#endif
+);
+
+extern Bool AllModifierKeysAreUp(
+#if NeedFunctionPrototypes
+    DeviceIntPtr /*device*/,
+    CARD8* /*map1*/,
+    int /*per1*/,
+    CARD8* /*map2*/,
+    int /*per2*/
+#endif
+);
+
+extern void NoteLedState(
+#if NeedFunctionPrototypes
+    DeviceIntPtr /*keybd*/,
+    int /*led*/,
+    Bool /*on*/
+#endif
+);
+
+extern void MaybeStopHint(
+#if NeedFunctionPrototypes
+    DeviceIntPtr /*device*/,
+    ClientPtr /*client*/
+#endif
+);
+
+extern void ProcessPointerEvent(
+#if NeedFunctionPrototypes
+    xEventPtr /*xE*/,
+    DeviceIntPtr /*mouse*/,
+    int /*count*/
+#endif
+);
+
+extern void ProcessKeyboardEvent(
+#if NeedFunctionPrototypes
+    xEventPtr /*xE*/,
+    DeviceIntPtr /*keybd*/,
+    int /*count*/
+#endif
+);
+
+#ifdef XKB
+extern void CoreProcessPointerEvent(
+#if NeedFunctionPrototypes
+    xEventPtr /*xE*/,
+    DeviceIntPtr /*mouse*/,
+    int /*count*/
+#endif
+);
+
+extern void CoreProcessKeyboardEvent(
+#if NeedFunctionPrototypes
+    xEventPtr /*xE*/,
+    DeviceIntPtr /*keybd*/,
+    int /*count*/
+#endif
+);
+#endif
+
+extern Bool LegalModifier(
+#if NeedFunctionPrototypes
+    unsigned int /*key*/, 
+    DevicePtr /*pDev*/
+#endif
+);
+
+extern void ProcessInputEvents(
+#if NeedFunctionPrototypes
+    void
+#endif
+);
+
+extern void InitInput(
+#if NeedFunctionPrototypes
+    int  /*argc*/,
+    char ** /*argv*/
+#endif
+);
+
+#endif /* INPUT_H */
diff --git a/Xserver/programs/Xserver/include/inputstr.h b/Xserver/programs/Xserver/include/inputstr.h
new file mode 100644 (file)
index 0000000..247c71c
--- /dev/null
@@ -0,0 +1,317 @@
+/************************************************************
+
+Copyright (c) 1987  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+
+Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
+
+                        All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and its 
+documentation for any purpose and without fee is hereby granted, 
+provided that the above copyright notice appear in all copies and that
+both that copyright notice and this permission notice appear in 
+supporting documentation, and that the name of Digital not be
+used in advertising or publicity pertaining to distribution of the
+software without specific, written prior permission.  
+
+DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
+ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
+DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
+ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+SOFTWARE.
+
+********************************************************/
+
+/* $XConsortium: inputstr.h /main/28 1996/09/25 00:51:24 dpw $ */
+
+#ifndef INPUTSTRUCT_H
+#define INPUTSTRUCT_H
+
+#include "input.h"
+#include "window.h"
+#include "dixstruct.h"
+
+#define BitIsOn(ptr, bit) (((BYTE *) (ptr))[(bit)>>3] & (1 << ((bit) & 7)))
+
+#define SameClient(obj,client) \
+       (CLIENT_BITS((obj)->resource) == (client)->clientAsMask)
+
+#define MAX_DEVICES    9
+
+#define EMASKSIZE      MAX_DEVICES
+
+/* Kludge: OtherClients and InputClients must be compatible, see code */
+
+typedef struct _OtherClients {
+    OtherClientsPtr    next;
+    XID                        resource; /* id for putting into resource manager */
+    Mask               mask;
+} OtherClients;
+
+typedef struct _InputClients {
+    InputClientsPtr    next;
+    XID                        resource; /* id for putting into resource manager */
+    Mask               mask[EMASKSIZE];
+} InputClients;
+
+typedef struct _OtherInputMasks {
+    Mask               deliverableEvents[EMASKSIZE];
+    Mask               inputEvents[EMASKSIZE];
+    Mask               dontPropagateMask[EMASKSIZE];
+    InputClientsPtr    inputClients;
+} OtherInputMasks;
+
+/*
+ * The following structure gets used for both active and passive grabs. For
+ * active grabs some of the fields (e.g. modifiers) are not used. However,
+ * that is not much waste since there aren't many active grabs (one per
+ * keyboard/pointer device) going at once in the server.
+ */
+
+#define MasksPerDetailMask 8           /* 256 keycodes and 256 possible
+                                               modifier combinations, but only 
+                                               3 buttons. */
+
+  typedef struct _DetailRec {          /* Grab details may be bit masks */
+       unsigned short exact;
+       Mask *pMask;
+  } DetailRec;
+
+  typedef struct _GrabRec {
+    GrabPtr            next;           /* for chain of passive grabs */
+    XID                        resource;
+    DeviceIntPtr       device;
+    WindowPtr          window;
+    unsigned           ownerEvents:1;
+    unsigned           keyboardMode:1;
+    unsigned           pointerMode:1;
+    unsigned           coreGrab:1;     /* grab is on core device */
+    unsigned           coreMods:1;     /* modifiers are on core keyboard */
+    CARD8              type;           /* event type */
+    DetailRec          modifiersDetail;
+    DeviceIntPtr       modifierDevice;
+    DetailRec          detail;         /* key or button */
+    WindowPtr          confineTo;      /* always NULL for keyboards */
+    CursorPtr          cursor;         /* always NULL for keyboards */
+    Mask               eventMask;
+} GrabRec;
+
+typedef struct _KeyClassRec {
+    CARD8              down[DOWN_LENGTH];
+    KeyCode            *modifierKeyMap;
+    KeySymsRec         curKeySyms;
+    int                        modifierKeyCount[8];
+    CARD8              modifierMap[MAP_LENGTH];
+    CARD8              maxKeysPerModifier;
+    unsigned short     state;
+    unsigned short     prev_state;
+#ifdef XKB
+    struct _XkbSrvInfo *xkbInfo;
+#endif
+} KeyClassRec, *KeyClassPtr;
+
+typedef struct _AxisInfo {
+    int                resolution;
+    int                min_resolution;
+    int                max_resolution;
+    int                min_value;
+    int                max_value;
+} AxisInfo, *AxisInfoPtr;
+
+typedef struct _ValuatorClassRec {
+    ValuatorMotionProcPtr GetMotionProc;
+    int                        numMotionEvents;
+    WindowPtr          motionHintWindow;
+    AxisInfoPtr        axes;
+    unsigned short     numAxes;
+    int                        *axisVal;
+    CARD8              mode;
+} ValuatorClassRec, *ValuatorClassPtr;
+
+typedef struct _ButtonClassRec {
+    CARD8              numButtons;
+    CARD8              buttonsDown;    /* number of buttons currently down */
+    unsigned short     state;
+    Mask               motionMask;
+    CARD8              down[DOWN_LENGTH];
+    CARD8              map[MAP_LENGTH];
+#ifdef XKB
+    union _XkbAction * xkb_acts;
+#endif
+} ButtonClassRec, *ButtonClassPtr;
+
+typedef struct _FocusClassRec {
+    WindowPtr  win;
+    int                revert;
+    TimeStamp  time;
+    WindowPtr  *trace;
+    int                traceSize;
+    int                traceGood;
+} FocusClassRec, *FocusClassPtr;
+
+typedef struct _ProximityClassRec {
+    char       pad;
+} ProximityClassRec, *ProximityClassPtr;
+
+typedef struct _KbdFeedbackClassRec *KbdFeedbackPtr;
+typedef struct _PtrFeedbackClassRec *PtrFeedbackPtr;
+typedef struct _IntegerFeedbackClassRec *IntegerFeedbackPtr;
+typedef struct _StringFeedbackClassRec *StringFeedbackPtr;
+typedef struct _BellFeedbackClassRec *BellFeedbackPtr;
+typedef struct _LedFeedbackClassRec *LedFeedbackPtr;
+
+typedef struct _KbdFeedbackClassRec {
+    BellProcPtr                BellProc;
+    KbdCtrlProcPtr     CtrlProc;
+    KeybdCtrl          ctrl;
+    KbdFeedbackPtr     next;
+#ifdef XKB
+    struct _XkbSrvLedInfo *xkb_sli;
+#endif
+} KbdFeedbackClassRec;
+
+typedef struct _PtrFeedbackClassRec {
+    PtrCtrlProcPtr     CtrlProc;
+    PtrCtrl            ctrl;
+    PtrFeedbackPtr     next;
+} PtrFeedbackClassRec;
+
+typedef struct _IntegerFeedbackClassRec {
+    IntegerCtrlProcPtr CtrlProc;
+    IntegerCtrl                ctrl;
+    IntegerFeedbackPtr next;
+} IntegerFeedbackClassRec;
+
+typedef struct _StringFeedbackClassRec {
+    StringCtrlProcPtr  CtrlProc;
+    StringCtrl         ctrl;
+    StringFeedbackPtr  next;
+} StringFeedbackClassRec;
+
+typedef struct _BellFeedbackClassRec {
+    BellProcPtr                BellProc;
+    BellCtrlProcPtr    CtrlProc;
+    BellCtrl           ctrl;
+    BellFeedbackPtr    next;
+} BellFeedbackClassRec;
+
+typedef struct _LedFeedbackClassRec {
+    LedCtrlProcPtr     CtrlProc;
+    LedCtrl            ctrl;
+    LedFeedbackPtr     next;
+#ifdef XKB
+    struct _XkbSrvLedInfo *xkb_sli;
+#endif
+} LedFeedbackClassRec;
+
+/* states for devices */
+
+#define NOT_GRABBED            0
+#define THAWED                 1
+#define THAWED_BOTH            2       /* not a real state */
+#define FREEZE_NEXT_EVENT      3
+#define FREEZE_BOTH_NEXT_EVENT 4
+#define FROZEN                 5       /* any state >= has device frozen */
+#define FROZEN_NO_EVENT                5
+#define FROZEN_WITH_EVENT      6
+#define THAW_OTHERS            7
+
+typedef struct _DeviceIntRec {
+    DeviceRec  public;
+    DeviceIntPtr next;
+    TimeStamp  grabTime;
+    Bool       startup;                /* true if needs to be turned on at
+                                         server intialization time */
+    DeviceProc deviceProc;             /* proc(DevicePtr, DEVICE_xx). It is
+                                         used to initialize, turn on, or
+                                         turn off the device */
+    Bool       inited;                 /* TRUE if INIT returns Success */
+    GrabPtr    grab;                   /* the grabber - used by DIX */
+    struct {
+       Bool            frozen;
+       int             state;
+       GrabPtr         other;          /* if other grab has this frozen */
+       xEvent          *event;         /* saved to be replayed */
+       int             evcount;
+    } sync;
+    Atom               type;
+    char               *name;
+    CARD8              id;
+    CARD8              activatingKey;
+    Bool               fromPassiveGrab;
+    GrabRec            activeGrab;
+    void               (*ActivateGrab) (
+#if NeedNestedPrototypes
+                       DeviceIntPtr /*device*/,
+                       GrabPtr /*grab*/,
+                       TimeStamp /*time*/,
+                       Bool /*autoGrab*/
+#endif
+);
+    void               (*DeactivateGrab)(
+#if NeedNestedPrototypes
+                       DeviceIntPtr /*device*/
+#endif
+);
+    KeyClassPtr                key;
+    ValuatorClassPtr   valuator;
+    ButtonClassPtr     button;
+    FocusClassPtr      focus;
+    ProximityClassPtr  proximity;
+    KbdFeedbackPtr     kbdfeed;
+    PtrFeedbackPtr     ptrfeed;
+    IntegerFeedbackPtr intfeed;
+    StringFeedbackPtr  stringfeed;
+    BellFeedbackPtr    bell;
+    LedFeedbackPtr     leds;
+#ifdef XKB
+    struct _XkbInterest *      xkb_interest;
+#endif
+} DeviceIntRec;
+
+typedef struct {
+    int                        numDevices;     /* total number of devices */
+    DeviceIntPtr       devices;        /* all devices turned on */
+    DeviceIntPtr       off_devices;    /* all devices turned off */
+    DeviceIntPtr       keyboard;       /* the main one for the server */
+    DeviceIntPtr       pointer;
+} InputInfo;
+
+extern InputInfo inputInfo;
+
+/* for keeping the events for devices grabbed synchronously */
+typedef struct _QdEvent *QdEventPtr;
+typedef struct _QdEvent {
+    QdEventPtr         next;
+    DeviceIntPtr       device;
+    ScreenPtr          pScreen;        /* what screen the pointer was on */
+    unsigned long      months;         /* milliseconds is in the event */
+    xEvent             *event;
+    int                        evcount;
+} QdEventRec;    
+
+#endif /* INPUTSTRUCT_H */
diff --git a/Xserver/programs/Xserver/include/misc.h b/Xserver/programs/Xserver/include/misc.h
new file mode 100644 (file)
index 0000000..f01f3e9
--- /dev/null
@@ -0,0 +1,280 @@
+/***********************************************************
+
+Copyright (c) 1987  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+
+Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
+
+                        All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and its 
+documentation for any purpose and without fee is hereby granted, 
+provided that the above copyright notice appear in all copies and that
+both that copyright notice and this permission notice appear in 
+supporting documentation, and that the name of Digital not be
+used in advertising or publicity pertaining to distribution of the
+software without specific, written prior permission.  
+
+DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
+ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
+DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
+ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+SOFTWARE.
+
+Copyright 1992, 1993 Data General Corporation;
+Copyright 1992, 1993 OMRON Corporation  
+
+Permission to use, copy, modify, distribute, and sell this software and its
+documentation for any purpose is hereby granted without fee, provided that the
+above copyright notice appear in all copies and that both that copyright
+notice and this permission notice appear in supporting documentation, and that
+neither the name OMRON or DATA GENERAL be used in advertising or publicity
+pertaining to distribution of the software without specific, written prior
+permission of the party whose name is to be used.  Neither OMRON or 
+DATA GENERAL make any representation about the suitability of this software
+for any purpose.  It is provided "as is" without express or implied warranty.  
+
+OMRON AND DATA GENERAL EACH DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
+SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS,
+IN NO EVENT SHALL OMRON OR DATA GENERAL BE LIABLE FOR ANY SPECIAL, INDIRECT
+OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
+DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
+TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
+OF THIS SOFTWARE.
+
+******************************************************************/
+/* $XConsortium: misc.h /main/28 1996/12/02 10:22:01 lehors $ */
+/* $XFree86: xc/programs/Xserver/include/misc.h,v 3.5 1996/12/23 07:09:29 dawes Exp $ */
+#ifndef MISC_H
+#define MISC_H 1
+/*
+ *  X internal definitions 
+ *
+ */
+
+extern unsigned long globalSerialNumber;
+extern unsigned long serverGeneration;
+
+#include <X11/Xosdefs.h>
+#include <X11/Xfuncproto.h>
+#include <X11/Xmd.h>
+#include <X11/X.h>
+
+#ifndef NULL
+#ifndef X_NOT_STDC_ENV
+#include <stddef.h>
+#else
+#define NULL            0
+#endif
+#endif
+
+#ifndef MAXSCREENS
+#define MAXSCREENS     3
+#endif
+#define MAXCLIENTS     128
+#define MAXDITS                1
+#define MAXEXTENSIONS  128
+#define MAXFORMATS     8
+#define MAXVISUALS_PER_SCREEN 50
+
+#if NeedFunctionPrototypes
+typedef void *pointer;
+#else
+typedef unsigned char *pointer;
+#endif
+typedef int Bool;
+typedef unsigned long PIXEL;
+typedef unsigned long ATOM;
+
+
+#ifndef TRUE
+#define TRUE 1
+#define FALSE 0
+#endif
+
+#ifndef _XTYPEDEF_FONTPTR
+typedef struct _Font *FontPtr; /* also in fonts/include/font.h */
+#define _XTYPEDEF_FONTPTR
+#endif
+
+#ifndef _XTYPEDEF_CLIENTPTR
+typedef struct _Client *ClientPtr; /* also in dix.h */
+#define _XTYPEDEF_CLIENTPTR
+#endif
+
+#ifndef _XTYPEDEF_CALLBACKLISTPTR
+typedef struct _CallbackList *CallbackListPtr; /* also in dix.h */
+#define _XTYPEDEF_CALLBACKLISTPTR
+#endif
+
+typedef struct _xReq *xReqPtr;
+
+#include "os.h"        /* for ALLOCATE_LOCAL and DEALLOCATE_LOCAL */
+#include <X11/Xfuncs.h> /* for bcopy, bzero, and bcmp */
+
+#define NullBox ((BoxPtr)0)
+#define MILLI_PER_MIN (1000 * 60)
+#define MILLI_PER_SECOND (1000)
+
+    /* this next is used with None and ParentRelative to tell
+       PaintWin() what to use to paint the background. Also used
+       in the macro IS_VALID_PIXMAP */
+
+#define USE_BACKGROUND_PIXEL 3
+#define USE_BORDER_PIXEL 3
+
+
+/* byte swap a 32-bit literal */
+#define lswapl(x) ((((x) & 0xff) << 24) |\
+                  (((x) & 0xff00) << 8) |\
+                  (((x) & 0xff0000) >> 8) |\
+                  (((x) >> 24) & 0xff))
+
+/* byte swap a short literal */
+#define lswaps(x) ((((x) & 0xff) << 8) | (((x) >> 8) & 0xff))
+
+#define min(a, b) (((a) < (b)) ? (a) : (b))
+#define max(a, b) (((a) > (b)) ? (a) : (b))
+#if !defined(AMOEBA) && !defined(__EMX__)
+#ifndef abs
+#define abs(a) ((a) > 0 ? (a) : -(a))
+#endif
+#else /* AMOEBA || __EMX__ */
+/* abs() is a function, not a macro; include the file declaring
+ * it in case we haven't done that yet.
+ */  
+#include <stdlib.h>
+#endif /* AMOEBA */
+#ifndef Fabs
+#define Fabs(a) ((a) > 0.0 ? (a) : -(a))       /* floating absolute value */
+#endif
+#define sign(x) ((x) < 0 ? -1 : ((x) > 0 ? 1 : 0))
+/* this assumes b > 0 */
+#define modulus(a, b, d)    if (((d) = (a) % (b)) < 0) (d) += (b)
+/*
+ * return the least significant bit in x which is set
+ *
+ * This works on 1's complement and 2's complement machines.
+ * If you care about the extra instruction on 2's complement
+ * machines, change to ((x) & (-(x)))
+ */
+#define lowbit(x) ((x) & (~(x) + 1))
+
+#ifndef MAXSHORT
+#define MAXSHORT 32767
+#endif
+#ifndef MINSHORT
+#define MINSHORT -MAXSHORT 
+#endif
+
+
+/* some macros to help swap requests, replies, and events */
+
+#define LengthRestB(stuff) \
+    ((client->req_len << 2) - sizeof(*stuff))
+
+#define LengthRestS(stuff) \
+    ((client->req_len << 1) - (sizeof(*stuff) >> 1))
+
+#define LengthRestL(stuff) \
+    (client->req_len - (sizeof(*stuff) >> 2))
+
+#define SwapRestS(stuff) \
+    SwapShorts((short *)(stuff + 1), LengthRestS(stuff))
+
+#define SwapRestL(stuff) \
+    SwapLongs((CARD32 *)(stuff + 1), LengthRestL(stuff))
+
+/* byte swap a 32-bit value */
+#define swapl(x, n) { \
+                n = ((char *) (x))[0];\
+                ((char *) (x))[0] = ((char *) (x))[3];\
+                ((char *) (x))[3] = n;\
+                n = ((char *) (x))[1];\
+                ((char *) (x))[1] = ((char *) (x))[2];\
+                ((char *) (x))[2] = n; }
+
+/* byte swap a short */
+#define swaps(x, n) { \
+                n = ((char *) (x))[0];\
+                ((char *) (x))[0] = ((char *) (x))[1];\
+                ((char *) (x))[1] = n; }
+
+/* copy 32-bit value from src to dst byteswapping on the way */
+#define cpswapl(src, dst) { \
+                 ((char *)&(dst))[0] = ((char *) &(src))[3];\
+                 ((char *)&(dst))[1] = ((char *) &(src))[2];\
+                 ((char *)&(dst))[2] = ((char *) &(src))[1];\
+                 ((char *)&(dst))[3] = ((char *) &(src))[0]; }
+
+/* copy short from src to dst byteswapping on the way */
+#define cpswaps(src, dst) { \
+                ((char *) &(dst))[0] = ((char *) &(src))[1];\
+                ((char *) &(dst))[1] = ((char *) &(src))[0]; }
+
+extern void SwapLongs(
+#if NeedFunctionPrototypes
+    CARD32 *list,
+    unsigned long count
+#endif
+);
+
+extern void SwapShorts(
+#if NeedFunctionPrototypes
+    short *list,
+    unsigned long count
+#endif
+);
+
+extern void MakePredeclaredAtoms(
+#if NeedFunctionPrototypes
+    void
+#endif
+);
+
+extern int Ones(
+#if NeedFunctionPrototypes
+    unsigned long /*mask*/
+#endif
+);
+
+typedef struct _xPoint *DDXPointPtr;
+typedef struct _Box *BoxPtr;
+typedef struct _xEvent *xEventPtr;
+typedef struct _xRectangle *xRectanglePtr;
+typedef struct _GrabRec *GrabPtr;
+
+/*  typedefs from other places - duplicated here to minimize the amount
+ *  of unnecessary junk that one would normally have to include to get
+ *  these symbols defined
+ */
+
+#ifndef _XTYPEDEF_CHARINFOPTR
+typedef struct _CharInfo *CharInfoPtr; /* also in fonts/include/font.h */
+#define _XTYPEDEF_CHARINFOPTR
+#endif
+
+#endif /* MISC_H */
diff --git a/Xserver/programs/Xserver/include/miscstruct.h b/Xserver/programs/Xserver/include/miscstruct.h
new file mode 100644 (file)
index 0000000..d99595f
--- /dev/null
@@ -0,0 +1,73 @@
+/* $XConsortium: miscstruct.h,v 5.5 94/04/17 20:25:50 dpw Exp $ */
+/* $XFree86: xc/programs/Xserver/include/miscstruct.h,v 3.0 1996/02/18 03:45:10 dawes Exp $ */
+/***********************************************************
+
+Copyright (c) 1987  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+
+Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
+
+                        All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and its 
+documentation for any purpose and without fee is hereby granted, 
+provided that the above copyright notice appear in all copies and that
+both that copyright notice and this permission notice appear in 
+supporting documentation, and that the name of Digital not be
+used in advertising or publicity pertaining to distribution of the
+software without specific, written prior permission.  
+
+DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
+ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
+DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
+ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+SOFTWARE.
+
+******************************************************************/
+#ifndef MISCSTRUCT_H
+#define MISCSTRUCT_H 1
+
+#include "misc.h"
+#include "X11/Xprotostr.h"
+
+typedef xPoint DDXPointRec;
+
+typedef struct _Box {
+    short x1, y1, x2, y2;
+} BoxRec;
+
+typedef union _DevUnion {
+    pointer            ptr;
+    long               val;
+    unsigned long      uval;
+    pointer            (*fptr)(
+#if NeedFunctionPrototypes
+                        void
+#endif
+                        );
+} DevUnion;
+
+#endif /* MISCSTRUCT_H */
diff --git a/Xserver/programs/Xserver/include/opaque.h b/Xserver/programs/Xserver/include/opaque.h
new file mode 100644 (file)
index 0000000..7de1ad3
--- /dev/null
@@ -0,0 +1,74 @@
+/* $XConsortium: opaque.h,v 1.19 94/04/17 20:25:51 dpw Exp $ */
+/*
+
+Copyright (c) 1987  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be included
+in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR
+OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall
+not be used in advertising or otherwise to promote the sale, use or
+other dealings in this Software without prior written authorization
+from the X Consortium.
+
+*/
+/* $XFree86: xc/programs/Xserver/include/opaque.h,v 1.2.2.1 1997/06/01 12:33:43 dawes Exp $ */
+
+#ifndef OPAQUE_H
+#define OPAQUE_H
+
+#include <X11/Xmd.h>
+
+extern char *defaultFontPath;
+extern char *defaultTextFont;
+extern char *defaultCursorFont;
+extern char *rgbPath;
+extern int MaxClients;
+extern char isItTimeToYield;
+extern char dispatchException;
+
+/* bit values for dispatchException */
+#define DE_RESET     1
+#define DE_TERMINATE 2
+#define DE_PRIORITYCHANGE 4  /* set when a client's priority changes */
+
+extern CARD32 TimeOutValue;
+extern CARD32 ScreenSaverTime;
+extern CARD32 ScreenSaverInterval;
+extern int  ScreenSaverBlanking;
+extern int  ScreenSaverAllowExposures;
+extern int argcGlobal;
+extern char **argvGlobal;
+
+#if DPMSExtension
+extern CARD32 defaultDPMSStandbyTime;
+extern CARD32 defaultDPMSSuspendTime;
+extern CARD32 defaultDPMSOffTime;
+extern CARD32 DPMSStandbyTime;
+extern CARD32 DPMSSuspendTime;
+extern CARD32 DPMSOffTime;
+extern CARD16 DPMSPowerLevel;
+extern Bool defaultDPMSEnabled;
+extern Bool DPMSEnabled;
+extern Bool DPMSEnabledSwitch;
+extern Bool DPMSDisabledSwitch;
+extern Bool DPMSCapableFlag;
+#endif
+
+#endif /* OPAQUE_H */
diff --git a/Xserver/programs/Xserver/include/os.h b/Xserver/programs/Xserver/include/os.h
new file mode 100644 (file)
index 0000000..abeac7e
--- /dev/null
@@ -0,0 +1,776 @@
+/***********************************************************
+
+Copyright (c) 1987  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+
+Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
+
+                        All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and its 
+documentation for any purpose and without fee is hereby granted, 
+provided that the above copyright notice appear in all copies and that
+both that copyright notice and this permission notice appear in 
+supporting documentation, and that the name of Digital not be
+used in advertising or publicity pertaining to distribution of the
+software without specific, written prior permission.  
+
+DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
+ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
+DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
+ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+SOFTWARE.
+
+******************************************************************/
+
+/* $XConsortium: os.h /main/60 1996/12/15 21:25:13 rws $ */
+/* $XFree86: xc/programs/Xserver/include/os.h,v 3.16.2.1 1998/01/22 10:47:13 dawes Exp $ */
+
+#ifndef OS_H
+#define OS_H
+#include "misc.h"
+#define ALLOCATE_LOCAL_FALLBACK(_size) Xalloc((unsigned long)(_size))
+#define DEALLOCATE_LOCAL_FALLBACK(_ptr) Xfree((pointer)(_ptr))
+#include "Xalloca.h"
+
+#define NullFID ((FID) 0)
+
+#define SCREEN_SAVER_ON   0
+#define SCREEN_SAVER_OFF  1
+#define SCREEN_SAVER_FORCER 2
+#define SCREEN_SAVER_CYCLE  3
+
+#ifndef MAX_REQUEST_SIZE
+#define MAX_REQUEST_SIZE 65535
+#endif
+#ifndef MAX_BIG_REQUEST_SIZE
+#define MAX_BIG_REQUEST_SIZE 1048575
+#endif
+
+typedef pointer        FID;
+typedef struct _FontPathRec *FontPathPtr;
+typedef struct _NewClientRec *NewClientPtr;
+
+#define xnfalloc(size) XNFalloc((unsigned long)(size))
+#define xnfrealloc(ptr, size) XNFrealloc((pointer)(ptr), (unsigned long)(size))
+
+#define xalloc(size) Xalloc((unsigned long)(size))
+#define xnfalloc(size) XNFalloc((unsigned long)(size))
+#define xcalloc(_num, _size) Xcalloc((unsigned long)(_num)*(unsigned long)(_size))
+#define xrealloc(ptr, size) Xrealloc((pointer)(ptr), (unsigned long)(size))
+#define xnfrealloc(ptr, size) XNFrealloc((pointer)(ptr), (unsigned long)(size))
+#define xfree(ptr) Xfree((pointer)(ptr))
+
+#ifdef SCO
+#include <stdio.h>
+#endif
+#ifndef X_NOT_STDC_ENV
+#include <string.h>
+#else
+#ifdef SYSV
+#include <string.h>
+#else
+#include <strings.h>
+#endif
+#endif
+
+/* have to put $(SIGNAL_DEFINES) in DEFINES in Imakefile to get this right */
+#ifdef SIGNALRETURNSINT
+#define SIGVAL int
+#else
+#define SIGVAL void
+#endif
+
+extern Bool OsDelayInitColors;
+
+extern int WaitForSomething(
+#if NeedFunctionPrototypes
+    int* /*pClientsReady*/
+#endif
+);
+
+#ifdef LBX
+#define ReadRequestFromClient(client)   ((client)->readRequest(client))
+extern int StandardReadRequestFromClient(
+#if NeedFunctionPrototypes
+    ClientPtr /*client*/
+#endif
+);
+#else
+extern int ReadRequestFromClient(
+#if NeedFunctionPrototypes
+    ClientPtr /*client*/
+#endif
+);
+#endif /* LBX */
+
+extern Bool InsertFakeRequest(
+#if NeedFunctionPrototypes
+    ClientPtr /*client*/,
+    char* /*data*/,
+    int /*count*/
+#endif
+);
+
+extern int ResetCurrentRequest(
+#if NeedFunctionPrototypes
+    ClientPtr /*client*/
+#endif
+);
+
+extern void FlushAllOutput(
+#if NeedFunctionPrototypes
+    void
+#endif
+);
+
+extern void FlushIfCriticalOutputPending(
+#if NeedFunctionPrototypes
+    void
+#endif
+);
+
+extern void SetCriticalOutputPending(
+#if NeedFunctionPrototypes
+    void
+#endif
+);
+
+extern int WriteToClient(
+#if NeedFunctionPrototypes
+    ClientPtr /*who*/,
+    int /*count*/,
+    char* /*buf*/
+#endif
+);
+
+extern void ResetOsBuffers(
+#if NeedFunctionPrototypes
+    void
+#endif
+);
+
+extern void CreateWellKnownSockets(
+#if NeedFunctionPrototypes
+    void
+#endif
+);
+
+extern void ResetWellKnownSockets(
+#if NeedFunctionPrototypes
+    void
+#endif
+);
+
+extern XID
+AuthorizationIDOfClient(
+#if NeedFunctionPrototypes
+    ClientPtr /*client*/
+#endif
+);
+
+extern char *ClientAuthorized(
+#if NeedFunctionPrototypes
+    ClientPtr /*client*/,
+    unsigned int /*proto_n*/,
+    char* /*auth_proto*/,
+    unsigned int /*string_n*/,
+    char* /*auth_string*/
+#endif
+);
+
+extern Bool EstablishNewConnections(
+#if NeedFunctionPrototypes
+    ClientPtr /*clientUnused*/,
+    pointer /*closure*/
+#endif
+);
+
+extern void CheckConnections(
+#if NeedFunctionPrototypes
+    void
+#endif
+);
+
+extern void CloseDownConnection(
+#if NeedFunctionPrototypes
+    ClientPtr /*client*/
+#endif
+);
+
+extern int AddEnabledDevice(
+#if NeedFunctionPrototypes
+    int /*fd*/
+#endif
+);
+
+extern int RemoveEnabledDevice(
+#if NeedFunctionPrototypes
+    int /*fd*/
+#endif
+);
+
+extern int OnlyListenToOneClient(
+#if NeedFunctionPrototypes
+    ClientPtr /*client*/
+#endif
+);
+
+extern int ListenToAllClients(
+#if NeedFunctionPrototypes
+    void
+#endif
+);
+
+extern int IgnoreClient(
+#if NeedFunctionPrototypes
+    ClientPtr /*client*/
+#endif
+);
+
+extern int AttendClient(
+#if NeedFunctionPrototypes
+    ClientPtr /*client*/
+#endif
+);
+
+extern int MakeClientGrabImpervious(
+#if NeedFunctionPrototypes
+    ClientPtr /*client*/
+#endif
+);
+
+extern int MakeClientGrabPervious(
+#if NeedFunctionPrototypes
+    ClientPtr /*client*/
+#endif
+);
+
+extern void Error(
+#if NeedFunctionPrototypes
+    char* /*str*/
+#endif
+);
+
+extern CARD32 GetTimeInMillis(
+#if NeedFunctionPrototypes
+    void
+#endif
+);
+
+extern int AdjustWaitForDelay(
+#if NeedFunctionPrototypes
+    pointer /*waitTime*/,
+    unsigned long /*newdelay*/
+#endif
+);
+
+typedef        struct _OsTimerRec *OsTimerPtr;
+
+typedef CARD32 (*OsTimerCallback)(
+#if NeedFunctionPrototypes
+    OsTimerPtr /* timer */,
+    CARD32 /* time */,
+    pointer /* arg */
+#endif
+);
+
+extern void TimerInit(
+#if NeedFunctionPrototypes
+    void
+#endif
+);
+
+extern Bool TimerForce(
+#if NeedFunctionPrototypes
+    OsTimerPtr /* timer */
+#endif
+);
+
+#define TimerAbsolute (1<<0)
+#define TimerForceOld (1<<1)
+
+extern OsTimerPtr TimerSet(
+#if NeedFunctionPrototypes
+    OsTimerPtr /* timer */,
+    int /* flags */,
+    CARD32 /* millis */,
+    OsTimerCallback /* func */,
+    pointer /* arg */
+#endif
+);
+
+extern void TimerCheck(
+#if NeedFunctionPrototypes
+    void
+#endif
+);
+
+extern void TimerCancel(
+#if NeedFunctionPrototypes
+    OsTimerPtr /* pTimer */
+#endif
+);
+
+extern void TimerFree(
+#if NeedFunctionPrototypes
+    OsTimerPtr /* pTimer */
+#endif
+);
+
+extern SIGVAL AutoResetServer(
+#if NeedFunctionPrototypes
+    int /*sig*/
+#endif
+);
+
+extern SIGVAL GiveUp(
+#if NeedFunctionPrototypes
+    int /*sig*/
+#endif
+);
+
+extern void UseMsg(
+#if NeedFunctionPrototypes
+    void
+#endif
+);
+
+extern void ProcessCommandLine(
+#if NeedFunctionPrototypes
+    int /*argc*/,
+    char* /*argv*/[]
+#endif
+);
+
+extern unsigned long *Xalloc(
+#if NeedFunctionPrototypes
+    unsigned long /*amount*/
+#endif
+);
+
+extern unsigned long *XNFalloc(
+#if NeedFunctionPrototypes
+    unsigned long /*amount*/
+#endif
+);
+
+extern unsigned long *Xcalloc(
+#if NeedFunctionPrototypes
+    unsigned long /*amount*/
+#endif
+);
+
+extern unsigned long *Xrealloc(
+#if NeedFunctionPrototypes
+    pointer /*ptr*/,
+    unsigned long /*amount*/
+#endif
+);
+
+extern unsigned long *XNFrealloc(
+#if NeedFunctionPrototypes
+    pointer /*ptr*/,
+    unsigned long /*amount*/
+#endif
+);
+
+extern void Xfree(
+#if NeedFunctionPrototypes
+    pointer /*ptr*/
+#endif
+);
+
+extern void OsInitAllocator(
+#if NeedFunctionPrototypes
+    void
+#endif
+);
+
+typedef SIGVAL (*OsSigHandlerPtr)(
+#if NeedFunctionPrototypes
+    int /* sig */
+#endif
+);
+
+extern OsSigHandlerPtr OsSignal(
+#if NeedFunctionPrototypes
+    int /* sig */,
+    OsSigHandlerPtr /* handler */
+#endif
+);
+
+extern int auditTrailLevel;
+
+extern void AuditF(
+#if NeedVarargsPrototypes
+    char* /*f*/,
+    ...
+#endif
+);
+
+extern void FatalError(
+#if NeedVarargsPrototypes
+    char* /*f*/,
+    ...
+#endif
+)
+#if __GNUC__ == 2 && __GNUC_MINOR__ > 4 
+__attribute((noreturn))
+#endif
+;
+
+extern void ErrorF(
+#if NeedVarargsPrototypes
+    char* /*f*/,
+    ...
+#endif
+);
+
+#ifdef SERVER_LOCK
+extern void LockServer(
+#if NeedFunctionPrototypes
+    void
+#endif
+);
+
+extern void UnlockServer(
+#if NeedFunctionPrototypes
+    void
+#endif
+);
+#endif
+
+extern int OsLookupColor(
+#if NeedFunctionPrototypes
+    int        /*screen*/,
+    char * /*name*/,
+    unsigned /*len*/,
+    unsigned short * /*pred*/,
+    unsigned short * /*pgreen*/,
+    unsigned short * /*pblue*/
+#endif
+);
+
+extern void OsInit(
+#if NeedFunctionPrototypes
+    void
+#endif
+);
+
+extern void OsCleanup(
+#if NeedFunctionPrototypes
+    void
+#endif
+);
+
+extern void OsVendorFatalError(
+#if NeedFunctionPrototypes
+    void
+#endif
+);
+
+extern void OsVendorInit(
+#if NeedFunctionPrototypes
+    void
+#endif
+);
+
+extern int OsInitColors(
+#if NeedFunctionPrototypes
+    void
+#endif
+);
+
+#if !defined(WIN32) && !defined(__EMX__)
+extern int System(
+#if NeedFunctionPrototypes
+    char *
+#endif
+);
+
+extern pointer Popen(
+#if NeedFunctionPrototypes
+    char *,
+    char *
+#endif
+);
+
+extern int Pclose(
+#if NeedFunctionPrototypes
+    pointer
+#endif
+);
+#else
+#define System(a) system(a)
+#define Popen(a,b) popen(a,b)
+#define Pclose(a) pclose(a)
+#endif
+
+extern int AddHost(
+#if NeedFunctionPrototypes
+    ClientPtr  /*client*/,
+    int         /*family*/,
+    unsigned    /*length*/,
+    pointer     /*pAddr*/
+#endif
+);
+
+extern Bool ForEachHostInFamily (
+#if NeedFunctionPrototypes
+    int            /*family*/,
+    Bool    (* /*func*/ )(
+#if NeedNestedPrototypes
+            unsigned char * /* addr */,
+            short           /* len */,
+            pointer         /* closure */
+#endif
+            ),
+    pointer /*closure*/
+#endif
+);
+
+extern int RemoveHost(
+#if NeedFunctionPrototypes
+    ClientPtr  /*client*/,
+    int         /*family*/,
+    unsigned    /*length*/,
+    pointer     /*pAddr*/
+#endif
+);
+
+extern int GetHosts(
+#if NeedFunctionPrototypes
+    pointer * /*data*/,
+    int            * /*pnHosts*/,
+    int            * /*pLen*/,
+    BOOL    * /*pEnabled*/
+#endif
+);
+
+typedef struct sockaddr * sockaddrPtr;
+
+extern int InvalidHost(
+#if NeedFunctionPrototypes
+    sockaddrPtr /*saddr*/,
+    int                /*len*/
+#endif
+);
+
+extern int LocalClient(
+#if NeedFunctionPrototypes
+    ClientPtr /* client */
+#endif
+);
+
+extern int ChangeAccessControl(
+#if NeedFunctionPrototypes
+    ClientPtr /*client*/,
+    int /*fEnabled*/
+#endif
+);
+
+extern int GetAccessControl(
+#if NeedFunctionPrototypes
+    void
+#endif
+);
+
+
+extern void AddLocalHosts(
+#if NeedFunctionPrototypes
+    void
+#endif
+);
+
+extern void ResetHosts(
+#if NeedFunctionPrototypes
+    char *display
+#endif
+);
+
+extern void EnableLocalHost(
+#if NeedFunctionPrototypes
+    void
+#endif
+);
+
+extern void DisableLocalHost(
+#if NeedFunctionPrototypes
+    void
+#endif
+);
+
+extern void AccessUsingXdmcp(
+#if NeedFunctionPrototypes
+    void
+#endif
+);
+
+extern void DefineSelf(
+#if NeedFunctionPrototypes
+    int /*fd*/
+#endif
+);
+
+extern void AugmentSelf(
+#if NeedFunctionPrototypes
+    pointer /*from*/,
+    int /*len*/
+#endif
+);
+
+extern void InitAuthorization(
+#if NeedFunctionPrototypes
+    char * /*filename*/
+#endif
+);
+
+extern int LoadAuthorization(
+#if NeedFunctionPrototypes
+    void
+#endif
+);
+
+extern void RegisterAuthorizations(
+#if NeedFunctionPrototypes
+    void
+#endif
+);
+
+extern XID CheckAuthorization(
+#if NeedFunctionPrototypes
+    unsigned int /*namelength*/,
+    char * /*name*/,
+    unsigned int /*datalength*/,
+    char * /*data*/,
+    ClientPtr /*client*/,
+    char ** /*reason*/
+#endif
+);
+
+extern void ResetAuthorization(
+#if NeedFunctionPrototypes
+    void
+#endif
+);
+
+extern int AddAuthorization(
+#if NeedFunctionPrototypes
+    unsigned int /*name_length*/,
+    char * /*name*/,
+    unsigned int /*data_length*/,
+    char * /*data*/
+#endif
+);
+
+extern XID GenerateAuthorization(
+#if NeedFunctionPrototypes
+    unsigned int   /* name_length */,
+    char       *  /* name */,
+    unsigned int   /* data_length */,
+    char       *  /* data */,
+    unsigned int * /* data_length_return */,
+    char       ** /* data_return */
+#endif
+);
+
+extern void ExpandCommandLine(
+#if NeedFunctionPrototypes
+    int * /*pargc*/,
+    char *** /*pargv*/
+#endif
+);
+
+extern int ddxProcessArgument(
+#if NeedFunctionPrototypes
+    int /*argc*/,
+    char * /*argv*/ [],
+    int /*i*/
+#endif
+);
+
+/*
+ *  idiom processing stuff
+ */
+
+xReqPtr PeekNextRequest(
+#if NeedFunctionPrototypes
+    xReqPtr req, ClientPtr client, Bool readmore
+#endif
+);
+
+void SkipRequests(
+#if NeedFunctionPrototypes
+    xReqPtr req, ClientPtr client, int numskipped
+#endif
+);
+
+/* int ReqLen(xReq *req, ClientPtr client)
+ * Given a pointer to a *complete* request, return its length in bytes.
+ * Note that if the request is a big request (as defined in the Big
+ * Requests extension), the macro lies by returning 4 less than the
+ * length that it actually occupies in the request buffer.  This is so you
+ * can blindly compare the length with the various sz_<request> constants
+ * in Xproto.h without having to know/care about big requests.
+ */
+#define ReqLen(_pxReq, _client) \
+ ((_pxReq->length ? \
+     (_client->swapped ? lswaps(_pxReq->length) : _pxReq->length) \
+  : ((_client->swapped ? \
+       lswapl(((CARD32*)_pxReq)[1]) : ((CARD32*)_pxReq)[1])-1) \
+  ) << 2)
+
+/* otherReqTypePtr CastxReq(xReq *req, otherReqTypePtr)
+ * Cast the given request to one of type otherReqTypePtr to access
+ * fields beyond the length field.
+ */
+#define CastxReq(_pxReq, otherReqTypePtr) \
+    (_pxReq->length ? (otherReqTypePtr)_pxReq \
+                   : (otherReqTypePtr)(((CARD32*)_pxReq)+1))
+
+/* stuff for SkippedRequestsCallback */
+extern CallbackListPtr SkippedRequestsCallback;
+typedef struct {
+    xReqPtr req;
+    ClientPtr client;
+    int numskipped;
+} SkippedRequestInfoRec;
+
+/* stuff for ReplyCallback */
+extern CallbackListPtr ReplyCallback;
+typedef struct {
+    ClientPtr client;
+    pointer replyData;
+    unsigned long dataLenBytes;
+    unsigned long bytesRemaining;
+    Bool startOfReply;
+} ReplyInfoRec;
+
+/* stuff for FlushCallback */
+extern CallbackListPtr FlushCallback;
+
+#endif /* OS_H */
diff --git a/Xserver/programs/Xserver/include/pixmap.h b/Xserver/programs/Xserver/include/pixmap.h
new file mode 100644 (file)
index 0000000..5fdc2d0
--- /dev/null
@@ -0,0 +1,124 @@
+/* $XConsortium: pixmap.h,v 5.6 94/04/17 20:25:53 dpw Exp $ */
+/***********************************************************
+
+Copyright (c) 1987  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+
+Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
+
+                        All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and its 
+documentation for any purpose and without fee is hereby granted, 
+provided that the above copyright notice appear in all copies and that
+both that copyright notice and this permission notice appear in 
+supporting documentation, and that the name of Digital not be
+used in advertising or publicity pertaining to distribution of the
+software without specific, written prior permission.  
+
+DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
+ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
+DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
+ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+SOFTWARE.
+
+******************************************************************/
+#ifndef PIXMAP_H
+#define PIXMAP_H
+
+#include "misc.h"
+#include "screenint.h"
+
+/* types for Drawable */
+#define DRAWABLE_WINDOW 0
+#define DRAWABLE_PIXMAP 1
+#define UNDRAWABLE_WINDOW 2
+#define DRAWABLE_BUFFER 3
+
+/* flags to PaintWindow() */
+#define PW_BACKGROUND 0
+#define PW_BORDER 1
+
+#define NullPixmap ((PixmapPtr)0)
+
+typedef struct _Drawable *DrawablePtr; 
+typedef struct _Pixmap *PixmapPtr;
+
+typedef union _PixUnion {
+    PixmapPtr          pixmap;
+    unsigned long      pixel;
+} PixUnion;
+
+#define SamePixUnion(a,b,isPixel)\
+    ((isPixel) ? (a).pixel == (b).pixel : (a).pixmap == (b).pixmap)
+
+#define EqualPixUnion(as, a, bs, b)                            \
+    ((as) == (bs) && (SamePixUnion (a, b, as)))
+
+#define OnScreenDrawable(type) \
+       ((type == DRAWABLE_WINDOW) || (type == DRAWABLE_BUFFER))
+
+#define WindowDrawable(type) \
+       ((type == DRAWABLE_WINDOW) || (type == UNDRAWABLE_WINDOW))
+
+extern PixmapPtr GetScratchPixmapHeader(
+#if NeedFunctionPrototypes
+    ScreenPtr /*pScreen*/,
+    int /*width*/,
+    int /*height*/,
+    int /*depth*/,
+    int /*bitsPerPixel*/,
+    int /*devKind*/,
+    pointer /*pPixData*/
+#endif
+);
+
+extern void FreeScratchPixmapHeader(
+#if NeedFunctionPrototypes
+    PixmapPtr /*pPixmap*/
+#endif
+);
+
+extern Bool CreateScratchPixmapsForScreen(
+#if NeedFunctionPrototypes
+    int /*scrnum*/
+#endif
+);
+
+extern void FreeScratchPixmapsForScreen(
+#if NeedFunctionPrototypes
+    int /*scrnum*/
+#endif
+);
+
+extern PixmapPtr AllocatePixmap(
+#if NeedFunctionPrototypes
+    ScreenPtr /*pScreen*/,
+    int /*pixDataSize*/
+#endif
+);
+
+#endif /* PIXMAP_H */
diff --git a/Xserver/programs/Xserver/include/pixmapstr.h b/Xserver/programs/Xserver/include/pixmapstr.h
new file mode 100644 (file)
index 0000000..4ca5294
--- /dev/null
@@ -0,0 +1,88 @@
+/* $XConsortium: pixmapstr.h,v 5.6 94/04/17 20:25:54 dpw Exp $ */
+/***********************************************************
+
+Copyright (c) 1987  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+
+Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
+
+                        All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and its 
+documentation for any purpose and without fee is hereby granted, 
+provided that the above copyright notice appear in all copies and that
+both that copyright notice and this permission notice appear in 
+supporting documentation, and that the name of Digital not be
+used in advertising or publicity pertaining to distribution of the
+software without specific, written prior permission.  
+
+DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
+ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
+DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
+ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+SOFTWARE.
+
+******************************************************************/
+
+#ifndef PIXMAPSTRUCT_H
+#define PIXMAPSTRUCT_H
+#include "pixmap.h"
+#include "screenint.h"
+#include "miscstruct.h"
+
+typedef struct _Drawable {
+    unsigned char      type;   /* DRAWABLE_<type> */
+#if defined(__cplusplus) || defined(c_plusplus)
+    unsigned char       c_class;
+#else
+    unsigned char      class;  /* specific to type */
+#endif
+    unsigned char      depth;
+    unsigned char      bitsPerPixel;
+    unsigned long      id;     /* resource id */
+    short              x;      /* window: screen absolute, pixmap: 0 */
+    short              y;      /* window: screen absolute, pixmap: 0 */
+    unsigned short     width;
+    unsigned short     height;
+    ScreenPtr          pScreen;
+    unsigned long      serialNumber;
+} DrawableRec;
+
+/*
+ * PIXMAP -- device dependent 
+ */
+
+typedef struct _Pixmap {
+    DrawableRec                drawable;
+    int                        refcnt;
+    int                        devKind;
+    DevUnion           devPrivate;
+#ifdef PIXPRIV
+    DevUnion           *devPrivates; /* real devPrivates like gcs & windows */
+#endif
+} PixmapRec;
+
+#endif /* PIXMAPSTRUCT_H */
diff --git a/Xserver/programs/Xserver/include/property.h b/Xserver/programs/Xserver/include/property.h
new file mode 100644 (file)
index 0000000..2c039c5
--- /dev/null
@@ -0,0 +1,79 @@
+/* $XConsortium: property.h,v 1.5 94/04/17 20:25:55 dpw Exp $ */
+/***********************************************************
+
+Copyright (c) 1987  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+
+Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
+
+                        All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and its 
+documentation for any purpose and without fee is hereby granted, 
+provided that the above copyright notice appear in all copies and that
+both that copyright notice and this permission notice appear in 
+supporting documentation, and that the name of Digital not be
+used in advertising or publicity pertaining to distribution of the
+software without specific, written prior permission.  
+
+DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
+ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
+DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
+ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+SOFTWARE.
+
+******************************************************************/
+#ifndef PROPERTY_H
+#define PROPERTY_H 
+typedef struct _Property *PropertyPtr;
+
+extern int ChangeWindowProperty(
+#if NeedFunctionPrototypes
+    WindowPtr /*pWin*/,
+    Atom /*property*/,
+    Atom /*type*/,
+    int /*format*/,
+    int /*mode*/,
+    unsigned long /*len*/,
+    pointer /*value*/,
+    Bool /*sendevent*/
+#endif
+);
+
+extern int DeleteProperty(
+#if NeedFunctionPrototypes
+    WindowPtr /*pWin*/,
+    Atom /*propName*/
+#endif
+);
+
+extern void DeleteAllWindowProperties(
+#if NeedFunctionPrototypes
+    WindowPtr /*pWin*/
+#endif
+);
+
+#endif  /* PROPERTY_H */
diff --git a/Xserver/programs/Xserver/include/propertyst.h b/Xserver/programs/Xserver/include/propertyst.h
new file mode 100644 (file)
index 0000000..1d47bba
--- /dev/null
@@ -0,0 +1,76 @@
+/* $XConsortium: propertyst.h,v 1.5 94/04/17 20:25:56 dpw Exp $ */
+/* $XFree86: xc/programs/Xserver/include/propertyst.h,v 3.0 1994/12/25 12:36:44 dawes Exp $ */
+/***********************************************************
+
+Copyright (c) 1987  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+
+Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
+
+                        All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and its 
+documentation for any purpose and without fee is hereby granted, 
+provided that the above copyright notice appear in all copies and that
+both that copyright notice and this permission notice appear in 
+supporting documentation, and that the name of Digital not be
+used in advertising or publicity pertaining to distribution of the
+software without specific, written prior permission.  
+
+DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
+ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
+DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
+ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+SOFTWARE.
+
+******************************************************************/
+#ifndef PROPERTYSTRUCT_H
+#define PROPERTYSTRUCT_H 
+#include "misc.h"
+#include "property.h"
+/* 
+ *   PROPERTY -- property element
+ */
+
+typedef struct _Property {
+        struct _Property       *next;
+       ATOM            propertyName;
+       ATOM            type;       /* ignored by server */
+       short           format;     /* format of data for swapping - 8,16,32 */
+       long            size;       /* size of data in (format/8) bytes */
+       pointer         data;       /* private to client */
+#if defined(LBX) || defined(LBX_COMPAT)
+       /*  If space is at a premium and binary compatibility is not
+        *  an issue, you may want to put the owner_pid next to format
+        *  so that the two shorts pack together without padding.
+        */
+       short           owner_pid;      /* proxy that has the data */
+       XID             tag_id;
+#endif
+} PropertyRec;
+
+#endif /* PROPERTYSTRUCT_H */
+
diff --git a/Xserver/programs/Xserver/include/region.h b/Xserver/programs/Xserver/include/region.h
new file mode 100644 (file)
index 0000000..b12de29
--- /dev/null
@@ -0,0 +1,54 @@
+/* $XConsortium: region.h,v 1.5 94/04/17 20:25:59 dpw Exp $ */
+/***********************************************************
+
+Copyright (c) 1987  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+
+Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
+
+                        All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and its 
+documentation for any purpose and without fee is hereby granted, 
+provided that the above copyright notice appear in all copies and that
+both that copyright notice and this permission notice appear in 
+supporting documentation, and that the name of Digital not be
+used in advertising or publicity pertaining to distribution of the
+software without specific, written prior permission.  
+
+DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
+ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
+DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
+ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+SOFTWARE.
+
+******************************************************************/
+#ifndef REGION_H
+#define REGION_H
+
+#include "regionstr.h"
+
+#endif /* REGION_H */
diff --git a/Xserver/programs/Xserver/include/regionstr.h b/Xserver/programs/Xserver/include/regionstr.h
new file mode 100644 (file)
index 0000000..0efd965
--- /dev/null
@@ -0,0 +1,409 @@
+/* $XConsortium: regionstr.h,v 1.8 94/04/17 20:26:01 dpw Exp $ */
+/***********************************************************
+
+Copyright (c) 1987  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+
+Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
+
+                        All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and its 
+documentation for any purpose and without fee is hereby granted, 
+provided that the above copyright notice appear in all copies and that
+both that copyright notice and this permission notice appear in 
+supporting documentation, and that the name of Digital not be
+used in advertising or publicity pertaining to distribution of the
+software without specific, written prior permission.  
+
+DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
+ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
+DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
+ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+SOFTWARE.
+
+******************************************************************/
+#ifndef REGIONSTRUCT_H
+#define REGIONSTRUCT_H
+
+#include "miscstruct.h"
+
+/* Return values from RectIn() */
+
+#define rgnOUT 0
+#define rgnIN  1
+#define rgnPART 2
+
+#define NullRegion ((RegionPtr)0)
+
+/* 
+ *   clip region
+ */
+
+typedef struct _RegData {
+    long       size;
+    long       numRects;
+/*  BoxRec     rects[size];   in memory but not explicitly declared */
+} RegDataRec, *RegDataPtr;
+
+typedef struct _Region {
+    BoxRec     extents;
+    RegDataPtr data;
+} RegionRec, *RegionPtr;
+
+extern BoxRec miEmptyBox;
+extern RegDataRec miEmptyData;
+
+#define REGION_NIL(reg) ((reg)->data && !(reg)->data->numRects)
+#define REGION_NUM_RECTS(reg) ((reg)->data ? (reg)->data->numRects : 1)
+#define REGION_SIZE(reg) ((reg)->data ? (reg)->data->size : 0)
+#define REGION_RECTS(reg) ((reg)->data ? (BoxPtr)((reg)->data + 1) \
+                                      : &(reg)->extents)
+#define REGION_BOXPTR(reg) ((BoxPtr)((reg)->data + 1))
+#define REGION_BOX(reg,i) (&REGION_BOXPTR(reg)[i])
+#define REGION_TOP(reg) REGION_BOX(reg, (reg)->data->numRects)
+#define REGION_END(reg) REGION_BOX(reg, (reg)->data->numRects - 1)
+#define REGION_SZOF(n) (sizeof(RegDataRec) + ((n) * sizeof(BoxRec)))
+
+#ifdef NEED_SCREEN_REGIONS
+
+#define REGION_CREATE(_pScreen, _rect, _size) \
+    (*(_pScreen)->RegionCreate)(_rect, _size)
+
+#define REGION_INIT(_pScreen, _pReg, _rect, _size) \
+    (*(_pScreen)->RegionInit)(_pReg, _rect, _size)
+
+#define REGION_COPY(_pScreen, dst, src) \
+    (*(_pScreen)->RegionCopy)(dst, src)
+
+#define REGION_DESTROY(_pScreen, _pReg) \
+    (*(_pScreen)->RegionDestroy)(_pReg)
+
+#define REGION_UNINIT(_pScreen, _pReg) \
+    (*(_pScreen)->RegionUninit)(_pReg)
+
+#define REGION_INTERSECT(_pScreen, newReg, reg1, reg2) \
+    (*(_pScreen)->Intersect)(newReg, reg1, reg2)
+
+#define REGION_UNION(_pScreen, newReg, reg1, reg2) \
+    (*(_pScreen)->Union)(newReg, reg1, reg2)
+
+#define REGION_SUBTRACT(_pScreen, newReg, reg1, reg2) \
+    (*(_pScreen)->Subtract)(newReg, reg1, reg2)
+
+#define REGION_INVERSE(_pScreen, newReg, reg1, invRect) \
+    (*(_pScreen)->Inverse)(newReg, reg1, invRect)
+
+#define REGION_RESET(_pScreen, _pReg, _pBox) \
+    (*(_pScreen)->RegionReset)(_pReg, _pBox)
+
+#define REGION_TRANSLATE(_pScreen, _pReg, _x, _y) \
+    (*(_pScreen)->TranslateRegion)(_pReg, _x, _y)
+
+#define RECT_IN_REGION(_pScreen, _pReg, prect) \
+    (*(_pScreen)->RectIn)(_pReg, prect)
+
+#define POINT_IN_REGION(_pScreen, _pReg, _x, _y, prect) \
+    (*(_pScreen)->PointInRegion)(_pReg, _x, _y, prect)
+
+#define REGION_NOTEMPTY(_pScreen, _pReg) \
+    (*(_pScreen)->RegionNotEmpty)(_pReg)
+
+#define REGION_EMPTY(_pScreen, _pReg) \
+    (*(_pScreen)->RegionEmpty)(_pReg)
+
+#define REGION_EXTENTS(_pScreen, _pReg) \
+    (*(_pScreen)->RegionExtents)(_pReg)
+
+#define REGION_APPEND(_pScreen, dstrgn, rgn) \
+    (*(_pScreen)->RegionAppend)(dstrgn, rgn)
+
+#define REGION_VALIDATE(_pScreen, badreg, pOverlap) \
+    (*(_pScreen)->RegionValidate)(badreg, pOverlap)
+
+#define BITMAP_TO_REGION(_pScreen, pPix) \
+    (*(_pScreen)->BitmapToRegion)(pPix)
+
+#define RECTS_TO_REGION(_pScreen, nrects, prect, ctype) \
+    (*(_pScreen)->RectsToRegion)(nrects, prect, ctype)
+
+#else /* !NEED_SCREEN_REGIONS */
+
+#define REGION_CREATE(_pScreen, _rect, _size) \
+    miRegionCreate(_rect, _size)
+
+#define REGION_COPY(_pScreen, dst, src) \
+    miRegionCopy(dst, src)
+
+#define REGION_DESTROY(_pScreen, _pReg) \
+    miRegionDestroy(_pReg)
+
+#define REGION_INTERSECT(_pScreen, newReg, reg1, reg2) \
+    miIntersect(newReg, reg1, reg2)
+
+#define REGION_UNION(_pScreen, newReg, reg1, reg2) \
+    miUnion(newReg, reg1, reg2)
+
+#define REGION_SUBTRACT(_pScreen, newReg, reg1, reg2) \
+    miSubtract(newReg, reg1, reg2)
+
+#define REGION_INVERSE(_pScreen, newReg, reg1, invRect) \
+    miInverse(newReg, reg1, invRect)
+
+#define REGION_TRANSLATE(_pScreen, _pReg, _x, _y) \
+    miTranslateRegion(_pReg, _x, _y)
+
+#define RECT_IN_REGION(_pScreen, _pReg, prect) \
+    miRectIn(_pReg, prect)
+
+#define POINT_IN_REGION(_pScreen, _pReg, _x, _y, prect) \
+    miPointInRegion(_pReg, _x, _y, prect)
+
+#define REGION_APPEND(_pScreen, dstrgn, rgn) \
+    miRegionAppend(dstrgn, rgn)
+
+#define REGION_VALIDATE(_pScreen, badreg, pOverlap) \
+    miRegionValidate(badreg, pOverlap)
+
+#define BITMAP_TO_REGION(_pScreen, pPix) \
+    (*(_pScreen)->BitmapToRegion)(pPix) /* no mi version?! */
+
+#define RECTS_TO_REGION(_pScreen, nrects, prect, ctype) \
+    miRectsToRegion(nrects, prect, ctype)
+
+#ifdef DONT_INLINE_REGION_OPS
+
+#define REGION_INIT(_pScreen, _pReg, _rect, _size) \
+    miRegionInit(_pReg, _rect, _size)
+
+#define REGION_UNINIT(_pScreen, _pReg) \
+    miRegionUninit(_pReg)
+
+#define REGION_RESET(_pScreen, _pReg, _pBox) \
+    miRegionReset(_pReg, _pBox)
+
+#define REGION_NOTEMPTY(_pScreen, _pReg) \
+    miRegionNotEmpty(_pReg)
+
+#define REGION_EMPTY(_pScreen, _pReg) \
+    miRegionEmpty(_pReg)
+
+#define REGION_EXTENTS(_pScreen, _pReg) \
+    miRegionExtents(_pReg)
+
+#else /* inline certain simple region ops for performance */
+
+#define REGION_INIT(_pScreen, _pReg, _rect, _size) \
+{ \
+    if (_rect) \
+    { \
+       (_pReg)->extents = *(_rect); \
+       (_pReg)->data = (RegDataPtr)NULL; \
+    } \
+    else \
+    { \
+       (_pReg)->extents = miEmptyBox; \
+       if (((_size) > 1) && ((_pReg)->data = \
+                            (RegDataPtr)xalloc(REGION_SZOF(_size)))) \
+       { \
+           (_pReg)->data->size = (_size); \
+           (_pReg)->data->numRects = 0; \
+       } \
+       else \
+           (_pReg)->data = &miEmptyData; \
+    } \
+}
+
+#define REGION_UNINIT(_pScreen, _pReg) \
+{ \
+    if ((_pReg)->data && (_pReg)->data->size) xfree((_pReg)->data); \
+}
+
+#define REGION_RESET(_pScreen, _pReg, _pBox) \
+{ \
+    (_pReg)->extents = *(_pBox); \
+    REGION_UNINIT(_pScreen, _pReg); \
+    (_pReg)->data = (RegDataPtr)NULL; \
+}
+
+#define REGION_NOTEMPTY(_pScreen, _pReg) \
+    !REGION_NIL(_pReg)
+
+#define REGION_EMPTY(_pScreen, _pReg) \
+{ \
+    REGION_UNINIT(_pScreen, _pReg); \
+    (_pReg)->extents.x2 = (_pReg)->extents.x1; \
+    (_pReg)->extents.y2 = (_pReg)->extents.y1; \
+    (_pReg)->data = &miEmptyData; \
+}
+
+#define REGION_EXTENTS(_pScreen, _pReg) \
+    &(_pReg)->extents
+
+#endif /* DONT_INLINE_REGION_OPS */
+
+#endif /* NEED_SCREEN_REGIONS */
+
+/* moved from mi.h */
+
+extern RegionPtr miRegionCreate(
+#if NeedFunctionPrototypes
+    BoxPtr /*rect*/,
+    int /*size*/
+#endif
+);
+
+extern void miRegionInit(
+#if NeedFunctionPrototypes
+    RegionPtr /*pReg*/,
+    BoxPtr /*rect*/,
+    int /*size*/
+#endif
+);
+
+extern void miRegionDestroy(
+#if NeedFunctionPrototypes
+    RegionPtr /*pReg*/
+#endif
+);
+
+extern void miRegionUninit(
+#if NeedFunctionPrototypes
+    RegionPtr /*pReg*/
+#endif
+);
+
+extern Bool miRegionCopy(
+#if NeedFunctionPrototypes
+    RegionPtr /*dst*/,
+    RegionPtr /*src*/
+#endif
+);
+
+extern Bool miIntersect(
+#if NeedFunctionPrototypes
+    RegionPtr /*newReg*/,
+    RegionPtr /*reg1*/,
+    RegionPtr /*reg2*/
+#endif
+);
+
+extern Bool miUnion(
+#if NeedFunctionPrototypes
+    RegionPtr /*newReg*/,
+    RegionPtr /*reg1*/,
+    RegionPtr /*reg2*/
+#endif
+);
+
+extern Bool miRegionAppend(
+#if NeedFunctionPrototypes
+    RegionPtr /*dstrgn*/,
+    RegionPtr /*rgn*/
+#endif
+);
+
+extern Bool miRegionValidate(
+#if NeedFunctionPrototypes
+    RegionPtr /*badreg*/,
+    Bool * /*pOverlap*/
+#endif
+);
+
+extern RegionPtr miRectsToRegion(
+#if NeedFunctionPrototypes
+    int /*nrects*/,
+    xRectanglePtr /*prect*/,
+    int /*ctype*/
+#endif
+);
+
+extern Bool miSubtract(
+#if NeedFunctionPrototypes
+    RegionPtr /*regD*/,
+    RegionPtr /*regM*/,
+    RegionPtr /*regS*/
+#endif
+);
+
+extern Bool miInverse(
+#if NeedFunctionPrototypes
+    RegionPtr /*newReg*/,
+    RegionPtr /*reg1*/,
+    BoxPtr /*invRect*/
+#endif
+);
+
+extern int miRectIn(
+#if NeedFunctionPrototypes
+    RegionPtr /*region*/,
+    BoxPtr /*prect*/
+#endif
+);
+
+extern void miTranslateRegion(
+#if NeedFunctionPrototypes
+    RegionPtr /*pReg*/,
+    int /*x*/,
+    int /*y*/
+#endif
+);
+
+extern void miRegionReset(
+#if NeedFunctionPrototypes
+    RegionPtr /*pReg*/,
+    BoxPtr /*pBox*/
+#endif
+);
+
+extern Bool miPointInRegion(
+#if NeedFunctionPrototypes
+    RegionPtr /*pReg*/,
+    int /*x*/,
+    int /*y*/,
+    BoxPtr /*box*/
+#endif
+);
+
+extern Bool miRegionNotEmpty(
+#if NeedFunctionPrototypes
+    RegionPtr /*pReg*/
+#endif
+);
+
+extern void miRegionEmpty(
+#if NeedFunctionPrototypes
+    RegionPtr /*pReg*/
+#endif
+);
+
+extern BoxPtr miRegionExtents(
+#if NeedFunctionPrototypes
+    RegionPtr /*pReg*/
+#endif
+);
+
+#endif /* REGIONSTRUCT_H */
diff --git a/Xserver/programs/Xserver/include/resource.h b/Xserver/programs/Xserver/include/resource.h
new file mode 100644 (file)
index 0000000..1095762
--- /dev/null
@@ -0,0 +1,282 @@
+/* $XConsortium: resource.h /main/23 1996/10/30 11:18:23 rws $ */
+/***********************************************************
+
+Copyright (c) 1987, 1989  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+
+Copyright 1987, 1989 by Digital Equipment Corporation, Maynard, Massachusetts.
+
+                        All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and its 
+documentation for any purpose and without fee is hereby granted, 
+provided that the above copyright notice appear in all copies and that
+both that copyright notice and this permission notice appear in 
+supporting documentation, and that the name of Digital not be
+used in advertising or publicity pertaining to distribution of the
+software without specific, written prior permission.  
+
+DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
+ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
+DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
+ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+SOFTWARE.
+
+******************************************************************/
+#ifndef RESOURCE_H
+#define RESOURCE_H 1
+#include "misc.h"
+
+/*****************************************************************
+ * STUFF FOR RESOURCES 
+ *****************************************************************/
+
+/* classes for Resource routines */
+
+typedef unsigned long RESTYPE;
+
+#define RC_VANILLA     ((RESTYPE)0)
+#define RC_CACHED      ((RESTYPE)1<<31)
+#define RC_DRAWABLE    ((RESTYPE)1<<30)
+/*  Use class RC_NEVERRETAIN for resources that should not be retained
+ *  regardless of the close down mode when the client dies.  (A client's
+ *  event selections on objects that it doesn't own are good candidates.)
+ *  Extensions can use this too!
+ */
+#define RC_NEVERRETAIN ((RESTYPE)1<<29)
+#define RC_LASTPREDEF  RC_NEVERRETAIN
+#define RC_ANY         (~(RESTYPE)0)
+
+/* types for Resource routines */
+
+#define RT_WINDOW      ((RESTYPE)1|RC_CACHED|RC_DRAWABLE)
+#define RT_PIXMAP      ((RESTYPE)2|RC_CACHED|RC_DRAWABLE)
+#define RT_GC          ((RESTYPE)3|RC_CACHED)
+#define RT_FONT                ((RESTYPE)4)
+#define RT_CURSOR      ((RESTYPE)5)
+#define RT_COLORMAP    ((RESTYPE)6)
+#define RT_CMAPENTRY   ((RESTYPE)7)
+#define RT_OTHERCLIENT ((RESTYPE)8|RC_NEVERRETAIN)
+#define RT_PASSIVEGRAB ((RESTYPE)9|RC_NEVERRETAIN)
+#define RT_LASTPREDEF  ((RESTYPE)9)
+#define RT_NONE                ((RESTYPE)0)
+
+/* bits and fields within a resource id */
+#define CLIENTOFFSET 22                                        /* client field */
+#define RESOURCE_ID_MASK       0x3FFFFF                /* low 22 bits */
+#define CLIENT_BITS(id) ((id) & 0x1fc00000)            /* hi 7 bits */
+#define CLIENT_ID(id) ((int)(CLIENT_BITS(id) >> CLIENTOFFSET))
+#define SERVER_BIT             0x20000000              /* use illegal bit */
+
+#ifdef INVALID
+#undef INVALID /* needed on HP/UX */
+#endif
+
+/* Invalid resource id */
+#define INVALID        (0)
+
+#define BAD_RESOURCE 0xe0000000
+
+typedef int (*DeleteType)(
+#if NeedNestedPrototypes
+    pointer /*value*/,
+    XID /*id*/
+#endif
+);
+
+typedef void (*FindResType)(
+#if NeedNestedPrototypes
+    pointer /*value*/,
+    XID /*id*/,
+    pointer /*cdata*/
+#endif
+);
+
+extern RESTYPE CreateNewResourceType(
+#if NeedFunctionPrototypes
+    DeleteType /*deleteFunc*/
+#endif
+);
+
+extern RESTYPE CreateNewResourceClass(
+#if NeedFunctionPrototypes
+void
+#endif
+);
+
+extern Bool InitClientResources(
+#if NeedFunctionPrototypes
+    ClientPtr /*client*/
+#endif
+);
+
+extern XID FakeClientID(
+#if NeedFunctionPrototypes
+    int /*client*/
+#endif
+);
+
+extern Bool AddResource(
+#if NeedFunctionPrototypes
+    XID /*id*/,
+    RESTYPE /*type*/,
+    pointer /*value*/
+#endif
+);
+
+extern void FreeResource(
+#if NeedFunctionPrototypes
+    XID /*id*/,
+    RESTYPE /*skipDeleteFuncType*/
+#endif
+);
+
+extern void FreeResourceByType(
+#if NeedFunctionPrototypes
+    XID /*id*/,
+    RESTYPE /*type*/,
+    Bool /*skipFree*/
+#endif
+);
+
+extern Bool ChangeResourceValue(
+#if NeedFunctionPrototypes
+    XID /*id*/,
+    RESTYPE /*rtype*/,
+    pointer /*value*/
+#endif
+);
+
+extern void FindClientResourcesByType(
+#if NeedFunctionPrototypes
+    ClientPtr /*client*/,
+    RESTYPE /*type*/,
+    FindResType /*func*/,
+    pointer /*cdata*/
+#endif
+);
+
+extern void FreeClientNeverRetainResources(
+#if NeedFunctionPrototypes
+    ClientPtr /*client*/
+#endif
+);
+
+extern void FreeClientResources(
+#if NeedFunctionPrototypes
+    ClientPtr /*client*/
+#endif
+);
+
+extern void FreeAllResources(
+#if NeedFunctionPrototypes
+void
+#endif
+);
+
+extern Bool LegalNewID(
+#if NeedFunctionPrototypes
+    XID /*id*/,
+    ClientPtr /*client*/
+#endif
+);
+
+extern pointer LookupIDByType(
+#if NeedFunctionPrototypes
+    XID /*id*/,
+    RESTYPE /*rtype*/
+#endif
+);
+
+extern pointer LookupIDByClass(
+#if NeedFunctionPrototypes
+    XID /*id*/,
+    RESTYPE /*classes*/
+#endif
+);
+
+/* These are the access modes that can be passed in the last parameter
+ * to SecurityLookupIDByType/Class.  The Security extension doesn't
+ * currently make much use of these; they're mainly provided as an
+ * example of what you might need for discretionary access control.
+ * You can or these values together to indicate multiple modes
+ * simultaneously.
+ */
+
+#define SecurityUnknownAccess  0       /* don't know intentions */
+#define SecurityReadAccess     (1<<0)  /* inspecting the object */
+#define SecurityWriteAccess    (1<<1)  /* changing the object */
+#define SecurityDestroyAccess  (1<<2)  /* destroying the object */
+
+#ifdef XCSECURITY
+
+extern pointer SecurityLookupIDByType(
+#if NeedFunctionPrototypes
+    ClientPtr /*client*/,
+    XID /*id*/,
+    RESTYPE /*rtype*/,
+    Mask /*access_mode*/
+#endif
+);
+
+extern pointer SecurityLookupIDByClass(
+#if NeedFunctionPrototypes
+    ClientPtr /*client*/,
+    XID /*id*/,
+    RESTYPE /*classes*/,
+    Mask /*access_mode*/
+#endif
+);
+
+#else /* not XCSECURITY */
+
+#define SecurityLookupIDByType(client, id, rtype, access_mode) \
+        LookupIDByType(id, rtype)
+
+#define SecurityLookupIDByClass(client, id, classes, access_mode) \
+        LookupIDByClass(id, classes)
+
+#endif /* XCSECURITY */
+
+extern void GetXIDRange(
+#if NeedFunctionPrototypes
+    int /*client*/,
+    Bool /*server*/,
+    XID * /*minp*/,
+    XID * /*maxp*/
+#endif
+);
+
+extern unsigned int GetXIDList(
+#if NeedFunctionPrototypes
+    ClientPtr /*client*/,
+    unsigned int /*count*/,
+    XID * /*pids*/
+#endif
+);
+
+#endif /* RESOURCE_H */
+
diff --git a/Xserver/programs/Xserver/include/rgb.h b/Xserver/programs/Xserver/include/rgb.h
new file mode 100644 (file)
index 0000000..e72e82a
--- /dev/null
@@ -0,0 +1,55 @@
+/***********************************************************
+
+Copyright (c) 1987  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+
+Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
+
+                        All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and its 
+documentation for any purpose and without fee is hereby granted, 
+provided that the above copyright notice appear in all copies and that
+both that copyright notice and this permission notice appear in 
+supporting documentation, and that the name of Digital not be
+used in advertising or publicity pertaining to distribution of the
+software without specific, written prior permission.  
+
+DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
+ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
+DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
+ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+SOFTWARE.
+
+******************************************************************/
+/* $XConsortium: rgb.h,v 1.4 94/04/17 20:26:04 jim Exp $ */
+
+#ifndef RGB_H
+#define RGB_H
+typedef struct _RGB {
+       unsigned short red, green, blue;
+       } RGB;
+#endif /* RGB_H */
diff --git a/Xserver/programs/Xserver/include/screenint.h b/Xserver/programs/Xserver/include/screenint.h
new file mode 100644 (file)
index 0000000..ebeac39
--- /dev/null
@@ -0,0 +1,171 @@
+/* $XConsortium: screenint.h /main/6 1996/06/17 10:55:15 mor $ */
+/***********************************************************
+
+Copyright (c) 1987  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+
+Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
+
+                        All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and its 
+documentation for any purpose and without fee is hereby granted, 
+provided that the above copyright notice appear in all copies and that
+both that copyright notice and this permission notice appear in 
+supporting documentation, and that the name of Digital not be
+used in advertising or publicity pertaining to distribution of the
+software without specific, written prior permission.  
+
+DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
+ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
+DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
+ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+SOFTWARE.
+
+******************************************************************/
+/* $XFree86: xc/programs/Xserver/include/screenint.h,v 1.2 1997/01/14 22:22:40 dawes Exp $ */
+#ifndef SCREENINT_H
+#define SCREENINT_H
+
+#include "misc.h"
+
+typedef struct _PixmapFormat *PixmapFormatPtr;
+typedef struct _Visual *VisualPtr;
+typedef struct _Depth  *DepthPtr;
+typedef struct _Screen *ScreenPtr;
+
+extern void ResetScreenPrivates(
+#if NeedFunctionPrototypes
+    void
+#endif
+);
+
+extern int AllocateScreenPrivateIndex(
+#if NeedFunctionPrototypes
+    void
+#endif
+);
+
+extern void ResetWindowPrivates(
+#if NeedFunctionPrototypes
+    void
+#endif
+);
+
+extern int AllocateWindowPrivateIndex(
+#if NeedFunctionPrototypes
+    void
+#endif
+);
+
+extern Bool AllocateWindowPrivate(
+#if NeedFunctionPrototypes
+    ScreenPtr /* pScreen */,
+    int /* index */,
+    unsigned /* amount */
+#endif
+);
+
+extern void ResetGCPrivates(
+#if NeedFunctionPrototypes
+    void
+#endif
+);
+
+extern int AllocateGCPrivateIndex(
+#if NeedFunctionPrototypes
+    void
+#endif
+);
+
+extern Bool AllocateGCPrivate(
+#if NeedFunctionPrototypes
+    ScreenPtr /* pScreen */,
+    int /* index */,
+    unsigned /* amount */
+#endif
+);
+
+extern int AddScreen(
+#if NeedFunctionPrototypes
+    Bool (* /*pfnInit*/)(
+#if NeedNestedPrototypes
+       int /*index*/,
+       ScreenPtr /*pScreen*/,
+       int /*argc*/,
+       char ** /*argv*/
+#endif
+    ),
+    int /*argc*/,
+    char** /*argv*/
+#endif
+);
+
+#ifdef PIXPRIV
+
+extern void ResetPixmapPrivates(
+#if NeedFunctionPrototypes
+    void
+#endif
+);
+
+extern int AllocatePixmapPrivateIndex(
+#if NeedFunctionPrototypes
+    void
+#endif
+);
+
+extern Bool AllocatePixmapPrivate(
+#if NeedFunctionPrototypes
+    ScreenPtr /* pScreen */,
+    int /* index */,
+    unsigned /* amount */
+#endif
+);
+
+#endif /* PIXPRIV */
+
+extern void ResetColormapPrivates(
+#if NeedFunctionPrototypes
+    void
+#endif
+);
+
+
+typedef struct _ColormapRec *ColormapPtr;
+typedef int (*InitCmapPrivFunc)(
+#if NeedNestedPrototypes
+       ColormapPtr
+#endif
+);
+
+extern int AllocateColormapPrivateIndex(
+#if NeedFunctionPrototypes
+    InitCmapPrivFunc /* initPrivFunc */
+#endif
+);
+
+#endif /* SCREENINT_H */
diff --git a/Xserver/programs/Xserver/include/scrnintstr.h b/Xserver/programs/Xserver/include/scrnintstr.h
new file mode 100644 (file)
index 0000000..c8c1a9b
--- /dev/null
@@ -0,0 +1,938 @@
+/* $XConsortium: scrnintstr.h /main/32 1996/09/28 17:14:32 rws $ */
+/***********************************************************
+
+Copyright (c) 1987  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+
+Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
+
+                        All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and its 
+documentation for any purpose and without fee is hereby granted, 
+provided that the above copyright notice appear in all copies and that
+both that copyright notice and this permission notice appear in 
+supporting documentation, and that the name of Digital not be
+used in advertising or publicity pertaining to distribution of the
+software without specific, written prior permission.  
+
+DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
+ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
+DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
+ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+SOFTWARE.
+
+******************************************************************/
+#ifndef SCREENINTSTRUCT_H
+#define SCREENINTSTRUCT_H
+
+#include "screenint.h"
+#include "miscstruct.h"
+#include "region.h"
+#include "pixmap.h"
+#include "gc.h"
+#include "colormap.h"
+#include "cursor.h"
+#include "validate.h"
+#include "window.h"
+#include "X11/Xproto.h"
+#include "dix.h"
+
+typedef struct _PixmapFormat {
+    unsigned char      depth;
+    unsigned char      bitsPerPixel;
+    unsigned char      scanlinePad;
+    } PixmapFormatRec;
+    
+typedef struct _Visual {
+    VisualID           vid;
+#if defined(__cplusplus) || defined(c_plusplus)
+    short               c_class;
+#else
+    short              class;
+#endif
+    short              bitsPerRGBValue;
+    short              ColormapEntries;
+    short              nplanes;/* = log2 (ColormapEntries). This does not
+                                * imply that the screen has this many planes.
+                                * it may have more or fewer */
+    unsigned long      redMask, greenMask, blueMask;
+    int                        offsetRed, offsetGreen, offsetBlue;
+  } VisualRec;
+
+typedef struct _Depth {
+    unsigned char      depth;
+    short              numVids;
+    VisualID           *vids;    /* block of visual ids for this depth */
+  } DepthRec;
+
+
+/*
+ *  There is a typedef for each screen function pointer so that code that
+ *  needs to declare a screen function pointer (e.g. in a screen private
+ *  or as a local variable) can easily do so and retain full type checking.
+ */
+
+typedef    Bool (* CloseScreenProcPtr)(
+#if NeedNestedPrototypes
+       int /*index*/,
+       ScreenPtr /*pScreen*/
+#endif
+);
+
+typedef    void (* QueryBestSizeProcPtr)(
+#if NeedNestedPrototypes
+       int /*class*/,
+       unsigned short * /*pwidth*/,
+       unsigned short * /*pheight*/,
+       ScreenPtr /*pScreen*/
+#endif
+);
+
+typedef    Bool (* SaveScreenProcPtr)(
+#if NeedNestedPrototypes
+        ScreenPtr /*pScreen*/,
+        int /*on*/
+#endif
+);
+
+typedef    void (* GetImageProcPtr)(
+#if NeedNestedPrototypes
+       DrawablePtr /*pDrawable*/,
+       int /*sx*/,
+       int /*sy*/,
+       int /*w*/,
+       int /*h*/,
+       unsigned int /*format*/,
+       unsigned long /*planeMask*/,
+       char * /*pdstLine*/
+#endif
+);
+
+typedef    void (* GetSpansProcPtr)(
+#if NeedNestedPrototypes
+       DrawablePtr /*pDrawable*/,
+       int /*wMax*/,
+       DDXPointPtr /*ppt*/,
+       int* /*pwidth*/,
+       int /*nspans*/,
+       char * /*pdstStart*/
+#endif
+);
+
+typedef    void (* PointerNonInterestBoxProcPtr)(
+#if NeedNestedPrototypes
+       ScreenPtr /*pScreen*/,
+       BoxPtr /*pBox*/
+#endif
+);
+
+typedef    void (* SourceValidateProcPtr)(
+#if NeedNestedPrototypes
+       DrawablePtr /*pDrawable*/,
+       int /*x*/,
+       int /*y*/,
+       int /*width*/,
+       int /*height*/
+#endif
+);
+
+typedef    Bool (* CreateWindowProcPtr)(
+#if NeedNestedPrototypes
+       WindowPtr /*pWindow*/
+#endif
+);
+
+typedef    Bool (* DestroyWindowProcPtr)(
+#if NeedNestedPrototypes
+       WindowPtr /*pWindow*/
+#endif
+);
+
+typedef    Bool (* PositionWindowProcPtr)(
+#if NeedNestedPrototypes
+       WindowPtr /*pWindow*/,
+       int /*x*/,
+       int /*y*/
+#endif
+);
+
+typedef    Bool (* ChangeWindowAttributesProcPtr)(
+#if NeedNestedPrototypes
+       WindowPtr /*pWindow*/,
+       unsigned long /*mask*/
+#endif
+);
+
+typedef    Bool (* RealizeWindowProcPtr)(
+#if NeedNestedPrototypes
+       WindowPtr /*pWindow*/
+#endif
+);
+
+typedef    Bool (* UnrealizeWindowProcPtr)(
+#if NeedNestedPrototypes
+       WindowPtr /*pWindow*/
+#endif
+);
+
+typedef    int  (* ValidateTreeProcPtr)(
+#if NeedNestedPrototypes
+       WindowPtr /*pParent*/,
+       WindowPtr /*pChild*/,
+       VTKind /*kind*/
+#endif
+);
+
+typedef    void (* PostValidateTreeProcPtr)(
+#if NeedNestedPrototypes
+       WindowPtr /*pParent*/,
+       WindowPtr /*pChild*/,
+       VTKind /*kind*/
+#endif
+);
+
+typedef    void (* WindowExposuresProcPtr)(
+#if NeedNestedPrototypes
+       WindowPtr /*pWindow*/,
+       RegionPtr /*prgn*/,
+       RegionPtr /*other_exposed*/
+#endif
+);
+
+typedef    void (* PaintWindowBackgroundProcPtr)(
+#if NeedNestedPrototypes
+       WindowPtr /*pWindow*/,
+       RegionPtr /*pRegion*/,
+       int /*what*/
+#endif
+);
+
+typedef    void (* PaintWindowBorderProcPtr)(
+#if NeedNestedPrototypes
+       WindowPtr /*pWindow*/,
+       RegionPtr /*pRegion*/,
+       int /*what*/
+#endif
+);
+
+typedef    void (* CopyWindowProcPtr)(
+#if NeedNestedPrototypes
+       WindowPtr /*pWindow*/,
+       DDXPointRec /*ptOldOrg*/,
+       RegionPtr /*prgnSrc*/
+#endif
+);
+
+typedef    void (* ClearToBackgroundProcPtr)(
+#if NeedNestedPrototypes
+       WindowPtr /*pWindow*/,
+       int /*x*/,
+       int /*y*/,
+       int /*w*/,
+       int /*h*/,
+       Bool /*generateExposures*/
+#endif
+);
+
+typedef    void (* ClipNotifyProcPtr)(
+#if NeedNestedPrototypes
+       WindowPtr /*pWindow*/,
+       int /*dx*/,
+       int /*dy*/
+#endif
+);
+
+typedef    PixmapPtr (* CreatePixmapProcPtr)(
+#if NeedNestedPrototypes
+       ScreenPtr /*pScreen*/,
+       int /*width*/,
+       int /*height*/,
+       int /*depth*/
+#endif
+);
+
+typedef    Bool (* DestroyPixmapProcPtr)(
+#if NeedNestedPrototypes
+       PixmapPtr /*pPixmap*/
+#endif
+);
+
+typedef    void (* SaveDoomedAreasProcPtr)(
+#if NeedNestedPrototypes
+       WindowPtr /*pWindow*/,
+       RegionPtr /*prgnSave*/,
+       int /*xorg*/,
+       int /*yorg*/
+#endif
+);
+
+typedef    RegionPtr (* RestoreAreasProcPtr)(
+#if NeedNestedPrototypes
+       WindowPtr /*pWindow*/,
+       RegionPtr /*prgnRestore*/
+#endif
+);
+
+typedef    void (* ExposeCopyProcPtr)(
+#if NeedNestedPrototypes
+       WindowPtr /*pSrc*/,
+       DrawablePtr /*pDst*/,
+       GCPtr /*pGC*/,
+       RegionPtr /*prgnExposed*/,
+       int /*srcx*/,
+       int /*srcy*/,
+       int /*dstx*/,
+       int /*dsty*/,
+       unsigned long /*plane*/
+#endif
+);
+
+typedef    RegionPtr (* TranslateBackingStoreProcPtr)(
+#if NeedNestedPrototypes
+       WindowPtr /*pWindow*/,
+       int /*windx*/,
+       int /*windy*/,
+       RegionPtr /*oldClip*/,
+       int /*oldx*/,
+       int /*oldy*/
+#endif
+);
+
+typedef    RegionPtr (* ClearBackingStoreProcPtr)(
+#if NeedNestedPrototypes
+       WindowPtr /*pWindow*/,
+       int /*x*/,
+       int /*y*/,
+       int /*w*/,
+       int /*h*/,
+       Bool /*generateExposures*/
+#endif
+);
+
+typedef    void (* DrawGuaranteeProcPtr)(
+#if NeedNestedPrototypes
+       WindowPtr /*pWindow*/,
+       GCPtr /*pGC*/,
+       int /*guarantee*/
+#endif
+);
+    
+typedef    Bool (* RealizeFontProcPtr)(
+#if NeedNestedPrototypes
+       ScreenPtr /*pScreen*/,
+       FontPtr /*pFont*/
+#endif
+);
+
+typedef    Bool (* UnrealizeFontProcPtr)(
+#if NeedNestedPrototypes
+       ScreenPtr /*pScreen*/,
+       FontPtr /*pFont*/
+#endif
+);
+
+typedef    void (* ConstrainCursorProcPtr)(
+#if NeedNestedPrototypes
+       ScreenPtr /*pScreen*/,
+       BoxPtr /*pBox*/
+#endif
+);
+
+typedef    void (* CursorLimitsProcPtr)(
+#if NeedNestedPrototypes
+       ScreenPtr /*pScreen*/,
+       CursorPtr /*pCursor*/,
+       BoxPtr /*pHotBox*/,
+       BoxPtr /*pTopLeftBox*/
+#endif
+);
+
+typedef    Bool (* DisplayCursorProcPtr)(
+#if NeedNestedPrototypes
+       ScreenPtr /*pScreen*/,
+       CursorPtr /*pCursor*/
+#endif
+);
+
+typedef    Bool (* RealizeCursorProcPtr)(
+#if NeedNestedPrototypes
+       ScreenPtr /*pScreen*/,
+       CursorPtr /*pCursor*/
+#endif
+);
+
+typedef    Bool (* UnrealizeCursorProcPtr)(
+#if NeedNestedPrototypes
+       ScreenPtr /*pScreen*/,
+       CursorPtr /*pCursor*/
+#endif
+);
+
+typedef    void (* RecolorCursorProcPtr)(
+#if NeedNestedPrototypes
+       ScreenPtr /*pScreen*/,
+       CursorPtr /*pCursor*/,
+       Bool /*displayed*/
+#endif
+);
+
+typedef    Bool (* SetCursorPositionProcPtr)(
+#if NeedNestedPrototypes
+       ScreenPtr /*pScreen*/,
+       int /*x*/,
+       int /*y*/,
+       Bool /*generateEvent*/
+#endif
+);
+
+typedef    Bool (* CreateGCProcPtr)(
+#if NeedNestedPrototypes
+       GCPtr /*pGC*/
+#endif
+);
+
+typedef    Bool (* CreateColormapProcPtr)(
+#if NeedNestedPrototypes
+       ColormapPtr /*pColormap*/
+#endif
+);
+
+typedef    void (* DestroyColormapProcPtr)(
+#if NeedNestedPrototypes
+       ColormapPtr /*pColormap*/
+#endif
+);
+
+typedef    void (* InstallColormapProcPtr)(
+#if NeedNestedPrototypes
+       ColormapPtr /*pColormap*/
+#endif
+);
+
+typedef    void (* UninstallColormapProcPtr)(
+#if NeedNestedPrototypes
+       ColormapPtr /*pColormap*/
+#endif
+);
+
+typedef    int (* ListInstalledColormapsProcPtr) (
+#if NeedNestedPrototypes
+       ScreenPtr /*pScreen*/,
+       XID* /*pmaps */
+#endif
+);
+
+typedef    void (* StoreColorsProcPtr)(
+#if NeedNestedPrototypes
+       ColormapPtr /*pColormap*/,
+       int /*ndef*/,
+       xColorItem * /*pdef*/
+#endif
+);
+
+typedef    void (* ResolveColorProcPtr)(
+#if NeedNestedPrototypes
+       unsigned short* /*pred*/,
+       unsigned short* /*pgreen*/,
+       unsigned short* /*pblue*/,
+       VisualPtr /*pVisual*/
+#endif
+);
+
+typedef    RegionPtr (* RegionCreateProcPtr)(
+#if NeedNestedPrototypes
+       BoxPtr /*rect*/,
+       int /*size*/
+#endif
+);
+
+typedef    void (* RegionInitProcPtr)(
+#if NeedNestedPrototypes
+       RegionPtr /*pReg*/,
+       BoxPtr /*rect*/,
+       int /*size*/
+#endif
+);
+
+typedef    Bool (* RegionCopyProcPtr)(
+#if NeedNestedPrototypes
+       RegionPtr /*dst*/,
+       RegionPtr /*src*/
+#endif
+);
+
+typedef    void (* RegionDestroyProcPtr)(
+#if NeedNestedPrototypes
+       RegionPtr /*pReg*/
+#endif
+);
+
+typedef    void (* RegionUninitProcPtr)(
+#if NeedNestedPrototypes
+       RegionPtr /*pReg*/
+#endif
+);
+
+typedef    Bool (* IntersectProcPtr)(
+#if NeedNestedPrototypes
+       RegionPtr /*newReg*/,
+       RegionPtr /*reg1*/,
+       RegionPtr /*reg2*/
+#endif
+);
+
+typedef    Bool (* UnionProcPtr)(
+#if NeedNestedPrototypes
+       RegionPtr /*newReg*/,
+       RegionPtr /*reg1*/,
+       RegionPtr /*reg2*/
+#endif
+);
+
+typedef    Bool (* SubtractProcPtr)(
+#if NeedNestedPrototypes
+       RegionPtr /*regD*/,
+       RegionPtr /*regM*/,
+       RegionPtr /*regS*/
+#endif
+);
+
+typedef    Bool (* InverseProcPtr)(
+#if NeedNestedPrototypes
+       RegionPtr /*newReg*/,
+       RegionPtr /*reg1*/,
+       BoxPtr /*invRect*/
+#endif
+);
+
+typedef    void (* RegionResetProcPtr)(
+#if NeedNestedPrototypes
+       RegionPtr /*pReg*/,
+       BoxPtr /*pBox*/
+#endif
+);
+
+typedef    void (* TranslateRegionProcPtr)(
+#if NeedNestedPrototypes
+       RegionPtr /*pReg*/,
+       int /*x*/,
+       int /*y*/
+#endif
+);
+
+typedef    int (* RectInProcPtr)(
+#if NeedNestedPrototypes
+       RegionPtr /*region*/,
+       BoxPtr /*prect*/
+#endif
+);
+
+typedef    Bool (* PointInRegionProcPtr)(
+#if NeedNestedPrototypes
+       RegionPtr /*pReg*/,
+       int /*x*/,
+       int /*y*/,
+       BoxPtr /*box*/
+#endif
+);
+
+typedef    Bool (* RegionNotEmptyProcPtr)(
+#if NeedNestedPrototypes
+       RegionPtr /*pReg*/
+#endif
+);
+
+typedef    void (* RegionEmptyProcPtr)(
+#if NeedNestedPrototypes
+       RegionPtr /*pReg*/
+#endif
+);
+
+typedef    BoxPtr (* RegionExtentsProcPtr)(
+#if NeedNestedPrototypes
+       RegionPtr /*pReg*/
+#endif
+);
+
+typedef    Bool (* RegionAppendProcPtr)(
+#if NeedNestedPrototypes
+       RegionPtr /*dstrgn*/,
+       RegionPtr /*rgn*/
+#endif
+);
+
+typedef    Bool (* RegionValidateProcPtr)(
+#if NeedNestedPrototypes
+       RegionPtr /*badreg*/,
+       Bool* /*pOverlap*/
+#endif
+);
+
+typedef    RegionPtr (* BitmapToRegionProcPtr)(
+#if NeedNestedPrototypes
+       PixmapPtr /*pPix*/
+#endif
+);
+
+typedef    RegionPtr (* RectsToRegionProcPtr)(
+#if NeedNestedPrototypes
+       int /*nrects*/,
+       xRectangle* /*prect*/,
+       int /*ctype*/
+#endif
+);
+
+typedef    void (* SendGraphicsExposeProcPtr)(
+#if NeedNestedPrototypes
+       ClientPtr /*client*/,
+       RegionPtr /*pRgn*/,
+       XID /*drawable*/,
+       int /*major*/,
+       int /*minor*/
+#endif
+);
+
+typedef    void (* ScreenBlockHandlerProcPtr)(
+#if NeedNestedPrototypes
+       int /*screenNum*/,
+       pointer /*blockData*/,
+       struct timeval ** /*pTimeout*/,
+       pointer /*pReadmask*/
+#endif
+);
+
+typedef    void (* ScreenWakeupHandlerProcPtr)(
+#if NeedNestedPrototypes
+        int /*screenNum*/,
+        pointer /*wakeupData*/,
+        unsigned long /*result*/,
+        pointer /*pReadMask*/
+#endif
+);
+
+typedef    Bool (* CreateScreenResourcesProcPtr)(
+#if NeedNestedPrototypes
+       ScreenPtr /*pScreen*/
+#endif
+);
+
+typedef    Bool (* ModifyPixmapHeaderProcPtr)(
+#if NeedNestedPrototypes
+       PixmapPtr /*pPixmap*/,
+       int /*width*/,
+       int /*height*/,
+       int /*depth*/,
+       int /*bitsPerPixel*/,
+       int /*devKind*/,
+       pointer /*pPixData*/
+#endif
+);
+
+typedef    void (* MarkWindowProcPtr)(
+#if NeedNestedPrototypes
+       WindowPtr /*pWin*/
+#endif
+);
+
+typedef    Bool (* MarkOverlappedWindowsProcPtr)(
+#if NeedNestedPrototypes
+       WindowPtr /*parent*/,
+       WindowPtr /*firstChild*/,
+       WindowPtr * /*pLayerWin*/
+#endif
+);
+
+typedef    Bool (* ChangeSaveUnderProcPtr)(
+#if NeedNestedPrototypes
+       WindowPtr /*pLayerWin*/,
+       WindowPtr /*firstChild*/
+#endif
+);
+
+typedef    void (* PostChangeSaveUnderProcPtr)(
+#if NeedNestedPrototypes
+       WindowPtr /*pLayerWin*/,
+       WindowPtr /*firstChild*/
+#endif
+);
+
+typedef    void (* MoveWindowProcPtr)(
+#if NeedNestedPrototypes
+       WindowPtr /*pWin*/,
+       int /*x*/,
+       int /*y*/,
+       WindowPtr /*pSib*/,
+       VTKind /*kind*/
+#endif
+);
+
+typedef    void (* ResizeWindowProcPtr)(
+#if NeedNestedPrototypes
+    WindowPtr /*pWin*/,
+    int /*x*/,
+    int /*y*/, 
+    unsigned int /*w*/,
+    unsigned int /*h*/,
+    WindowPtr /*pSib*/
+#endif
+);
+
+typedef    WindowPtr (* GetLayerWindowProcPtr)(
+#if NeedNestedPrototypes
+    WindowPtr /*pWin*/
+#endif
+);
+
+typedef    void (* HandleExposuresProcPtr)(
+#if NeedNestedPrototypes
+    WindowPtr /*pWin*/
+#endif
+);
+
+typedef    void (* ReparentWindowProcPtr)(
+#if NeedNestedPrototypes
+    WindowPtr /*pWin*/,
+    WindowPtr /*pPriorParent*/
+#endif
+);
+
+#ifdef SHAPE
+typedef    void (* SetShapeProcPtr)(
+#if NeedFunctionPrototypes
+       WindowPtr /*pWin*/
+#endif
+);
+#endif /* SHAPE */
+
+typedef    void (* ChangeBorderWidthProcPtr)(
+#if NeedFunctionPrototypes
+       WindowPtr /*pWin*/,
+       unsigned int /*width*/
+#endif
+);
+
+typedef    void (* MarkUnrealizedWindowProcPtr)(
+#if NeedFunctionPrototypes
+       WindowPtr /*pChild*/,
+       WindowPtr /*pWin*/,
+       Bool /*fromConfigure*/
+#endif
+);
+
+typedef struct _Screen {
+    int                        myNum;  /* index of this instance in Screens[] */
+    ATOM               id;
+    short              width, height;
+    short              mmWidth, mmHeight;
+    short              numDepths;
+    unsigned char              rootDepth;
+    DepthPtr           allowedDepths;
+    unsigned long              rootVisual;
+    unsigned long      defColormap;
+    short              minInstalledCmaps, maxInstalledCmaps;
+    char                backingStoreSupport, saveUnderSupport;
+    unsigned long      whitePixel, blackPixel;
+    unsigned long      rgf;    /* array of flags; she's -- HUNGARIAN */
+    GCPtr              GCperDepth[MAXFORMATS+1];
+                       /* next field is a stipple to use as default in
+                          a GC.  we don't build default tiles of all depths
+                          because they are likely to be of a color
+                          different from the default fg pixel, so
+                          we don't win anything by building
+                          a standard one.
+                       */
+    PixmapPtr          PixmapPerDepth[1];
+    pointer            devPrivate;
+    short              numVisuals;
+    VisualPtr          visuals;
+    int                        WindowPrivateLen;
+    unsigned           *WindowPrivateSizes;
+    unsigned           totalWindowSize;
+    int                        GCPrivateLen;
+    unsigned           *GCPrivateSizes;
+    unsigned           totalGCSize;
+
+    /* Random screen procedures */
+
+    CloseScreenProcPtr         CloseScreen;
+    QueryBestSizeProcPtr       QueryBestSize;
+    SaveScreenProcPtr          SaveScreen;
+    GetImageProcPtr            GetImage;
+    GetSpansProcPtr            GetSpans;
+    PointerNonInterestBoxProcPtr PointerNonInterestBox;
+    SourceValidateProcPtr      SourceValidate;
+
+    /* Window Procedures */
+
+    CreateWindowProcPtr                CreateWindow;
+    DestroyWindowProcPtr       DestroyWindow;
+    PositionWindowProcPtr      PositionWindow;
+    ChangeWindowAttributesProcPtr ChangeWindowAttributes;
+    RealizeWindowProcPtr       RealizeWindow;
+    UnrealizeWindowProcPtr     UnrealizeWindow;
+    ValidateTreeProcPtr                ValidateTree;
+    PostValidateTreeProcPtr    PostValidateTree;
+    WindowExposuresProcPtr     WindowExposures;
+    PaintWindowBackgroundProcPtr PaintWindowBackground;
+    PaintWindowBorderProcPtr   PaintWindowBorder;
+    CopyWindowProcPtr          CopyWindow;
+    ClearToBackgroundProcPtr   ClearToBackground;
+    ClipNotifyProcPtr          ClipNotify;
+
+    /* Pixmap procedures */
+
+    CreatePixmapProcPtr                CreatePixmap;
+    DestroyPixmapProcPtr       DestroyPixmap;
+
+    /* Backing store procedures */
+
+    SaveDoomedAreasProcPtr     SaveDoomedAreas;
+    RestoreAreasProcPtr                RestoreAreas;
+    ExposeCopyProcPtr          ExposeCopy;
+    TranslateBackingStoreProcPtr TranslateBackingStore;
+    ClearBackingStoreProcPtr   ClearBackingStore;
+    DrawGuaranteeProcPtr       DrawGuarantee;
+    
+    /* Font procedures */
+
+    RealizeFontProcPtr         RealizeFont;
+    UnrealizeFontProcPtr       UnrealizeFont;
+
+    /* Cursor Procedures */
+
+    ConstrainCursorProcPtr     ConstrainCursor;
+    CursorLimitsProcPtr                CursorLimits;
+    DisplayCursorProcPtr       DisplayCursor;
+    RealizeCursorProcPtr       RealizeCursor;
+    UnrealizeCursorProcPtr     UnrealizeCursor;
+    RecolorCursorProcPtr       RecolorCursor;
+    SetCursorPositionProcPtr   SetCursorPosition;
+
+    /* GC procedures */
+
+    CreateGCProcPtr            CreateGC;
+
+    /* Colormap procedures */
+
+    CreateColormapProcPtr      CreateColormap;
+    DestroyColormapProcPtr     DestroyColormap;
+    InstallColormapProcPtr     InstallColormap;
+    UninstallColormapProcPtr   UninstallColormap;
+    ListInstalledColormapsProcPtr ListInstalledColormaps;
+    StoreColorsProcPtr         StoreColors;
+    ResolveColorProcPtr                ResolveColor;
+
+    /* Region procedures */
+
+    RegionCreateProcPtr                RegionCreate;
+    RegionInitProcPtr          RegionInit;
+    RegionCopyProcPtr          RegionCopy;
+    RegionDestroyProcPtr       RegionDestroy;
+    RegionUninitProcPtr                RegionUninit;
+    IntersectProcPtr           Intersect;
+    UnionProcPtr               Union;
+    SubtractProcPtr            Subtract;
+    InverseProcPtr             Inverse;
+    RegionResetProcPtr         RegionReset;
+    TranslateRegionProcPtr     TranslateRegion;
+    RectInProcPtr              RectIn;
+    PointInRegionProcPtr       PointInRegion;
+    RegionNotEmptyProcPtr      RegionNotEmpty;
+    RegionEmptyProcPtr         RegionEmpty;
+    RegionExtentsProcPtr       RegionExtents;
+    RegionAppendProcPtr                RegionAppend;
+    RegionValidateProcPtr      RegionValidate;
+    BitmapToRegionProcPtr      BitmapToRegion;
+    RectsToRegionProcPtr       RectsToRegion;
+    SendGraphicsExposeProcPtr  SendGraphicsExpose;
+
+    /* os layer procedures */
+
+    ScreenBlockHandlerProcPtr  BlockHandler;
+    ScreenWakeupHandlerProcPtr WakeupHandler;
+
+    pointer blockData;
+    pointer wakeupData;
+
+    /* anybody can get a piece of this array */
+    DevUnion   *devPrivates;
+
+    CreateScreenResourcesProcPtr CreateScreenResources;
+    ModifyPixmapHeaderProcPtr  ModifyPixmapHeader;
+
+    PixmapPtr pScratchPixmap;          /* scratch pixmap "pool" */
+
+#ifdef PIXPRIV
+    int                        PixmapPrivateLen;
+    unsigned           *PixmapPrivateSizes;
+    unsigned           totalPixmapSize;
+#endif
+
+    MarkWindowProcPtr          MarkWindow;
+    MarkOverlappedWindowsProcPtr MarkOverlappedWindows;
+    ChangeSaveUnderProcPtr     ChangeSaveUnder;
+    PostChangeSaveUnderProcPtr PostChangeSaveUnder;
+    MoveWindowProcPtr          MoveWindow;
+    ResizeWindowProcPtr                ResizeWindow;
+    GetLayerWindowProcPtr      GetLayerWindow;
+    HandleExposuresProcPtr     HandleExposures;
+    ReparentWindowProcPtr      ReparentWindow;
+
+#ifdef SHAPE
+    SetShapeProcPtr            SetShape;
+#endif /* SHAPE */
+
+    ChangeBorderWidthProcPtr   ChangeBorderWidth;
+    MarkUnrealizedWindowProcPtr        MarkUnrealizedWindow;
+
+} ScreenRec;
+
+typedef struct _ScreenInfo {
+    int                imageByteOrder;
+    int                bitmapScanlineUnit;
+    int                bitmapScanlinePad;
+    int                bitmapBitOrder;
+    int                numPixmapFormats;
+    PixmapFormatRec
+               formats[MAXFORMATS];
+    int                arraySize;
+    int                numScreens;
+    ScreenPtr  screens[MAXSCREENS];
+    int                numVideoScreens;
+} ScreenInfo;
+
+extern ScreenInfo screenInfo;
+
+extern void InitOutput(
+#if NeedFunctionPrototypes
+    ScreenInfo         * /*pScreenInfo*/,
+    int        /*argc*/,
+    char       ** /*argv*/
+#endif
+);
+
+#endif /* SCREENINTSTRUCT_H */
diff --git a/Xserver/programs/Xserver/include/selection.h b/Xserver/programs/Xserver/include/selection.h
new file mode 100644 (file)
index 0000000..6346e24
--- /dev/null
@@ -0,0 +1,69 @@
+/* $XConsortium: selection.h,v 1.3 94/04/17 20:26:07 jim Exp $ */
+#ifndef SELECTION_H
+#define SELECTION_H 1
+
+/***********************************************************
+
+Copyright (c) 1987  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+
+Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
+
+                        All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and its 
+documentation for any purpose and without fee is hereby granted, 
+provided that the above copyright notice appear in all copies and that
+both that copyright notice and this permission notice appear in 
+supporting documentation, and that the name of Digital not be
+used in advertising or publicity pertaining to distribution of the
+software without specific, written prior permission.  
+
+DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
+ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
+DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
+ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+SOFTWARE.
+
+******************************************************************/
+
+#include "dixstruct.h"
+/*
+ *
+ *  Selection data structures 
+ */
+
+typedef struct _Selection {
+    Atom selection;
+    TimeStamp lastTimeChanged;
+    Window window;
+    WindowPtr pWin;
+    ClientPtr client;
+} Selection;
+
+#endif /* SELECTION_H */
+
+
diff --git a/Xserver/programs/Xserver/include/servermd.h b/Xserver/programs/Xserver/include/servermd.h
new file mode 100644 (file)
index 0000000..744c295
--- /dev/null
@@ -0,0 +1,562 @@
+/***********************************************************
+
+Copyright (c) 1987  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+
+Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
+
+                        All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and its 
+documentation for any purpose and without fee is hereby granted, 
+provided that the above copyright notice appear in all copies and that
+both that copyright notice and this permission notice appear in 
+supporting documentation, and that the name of Digital not be
+used in advertising or publicity pertaining to distribution of the
+software without specific, written prior permission.  
+
+DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
+ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
+DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
+ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+SOFTWARE.
+
+******************************************************************/
+#ifndef SERVERMD_H
+#define SERVERMD_H 1
+/* $XConsortium: servermd.h /main/58 1996/12/02 10:22:09 lehors $ */
+/* $XFree86: xc/programs/Xserver/include/servermd.h,v 3.19.2.3 1997/07/28 14:17:34 dawes Exp $ */
+
+/*
+ * Machine dependent values:
+ * GLYPHPADBYTES should be chosen with consideration for the space-time
+ * trade-off.  Padding to 0 bytes means that there is no wasted space
+ * in the font bitmaps (both on disk and in memory), but that access of
+ * the bitmaps will cause odd-address memory references.  Padding to
+ * 2 bytes would ensure even address memory references and would
+ * be suitable for a 68010-class machine, but at the expense of wasted
+ * space in the font bitmaps.  Padding to 4 bytes would be good
+ * for real 32 bit machines, etc.  Be sure that you tell the font
+ * compiler what kind of padding you want because its defines are
+ * kept separate from this.  See server/include/font.h for how
+ * GLYPHPADBYTES is used.
+ *
+ * Along with this, you should choose an appropriate value for
+ * GETLEFTBITS_ALIGNMENT, which is used in ddx/mfb/maskbits.h.  This
+ * constant choses what kind of memory references are guarenteed during
+ * font access; either 1, 2 or 4, for byte, word or longword access,
+ * respectively.  For instance, if you have decided to to have
+ * GLYPHPADBYTES == 4, then it is pointless for you to have a
+ * GETLEFTBITS_ALIGNMENT > 1, because the padding of the fonts has already
+ * guarenteed you that your fonts are longword aligned.  On the other
+ * hand, even if you have chosen GLYPHPADBYTES == 1 to save space, you may
+ * also decide that the computing involved in aligning the pointer is more
+ * costly than an odd-address access; you choose GETLEFTBITS_ALIGNMENT == 1.
+ *
+ * Next, choose the tuning parameters which are appropriate for your
+ * hardware; these modify the behaviour of the raw frame buffer code
+ * in ddx/mfb and ddx/cfb.  Defining these incorrectly will not cause
+ * the server to run incorrectly, but defining these correctly will
+ * cause some noticeable speed improvements:
+ *
+ *  AVOID_MEMORY_READ - (8-bit cfb only)
+ *     When stippling pixels on the screen (polytext and pushpixels),
+ *     don't read long words from the display and mask in the
+ *     appropriate values.  Rather, perform multiple byte/short/long
+ *     writes as appropriate.  This option uses many more instructions
+ *     but runs much faster when the destination is much slower than
+ *     the CPU and at least 1 level of write buffer is availible (2
+ *     is much better).  Defined currently for SPARC and MIPS.
+ *
+ *  FAST_CONSTANT_OFFSET_MODE - (cfb and mfb)
+ *     This define is used on machines which have no auto-increment
+ *     addressing mode, but do have an effectively free constant-offset
+ *     addressing mode.  Currently defined for MIPS and SPARC, even though
+ *     I remember the cg6 as performing better without it (cg3 definitely
+ *     performs better with it).
+ *     
+ *  LARGE_INSTRUCTION_CACHE -
+ *     This define increases the number of times some loops are
+ *     unrolled.  On 68020 machines (with 256 bytes of i-cache),
+ *     this define will slow execution down as instructions miss
+ *     the cache frequently.  On machines with real i-caches, this
+ *     reduces loop overhead, causing a slight performance improvement.
+ *     Currently defined for MIPS and SPARC
+ *
+ *  FAST_UNALIGNED_READS -
+ *     For machines with more memory bandwidth than CPU, this
+ *     define uses unaligned reads for 8-bit BitBLT instead of doing
+ *     aligned reads and combining the results with shifts and
+ *     logical-ors.  Currently defined for 68020 and vax.
+ *  PLENTIFUL_REGISTERS -
+ *     For machines with > 20 registers.  Currently used for
+ *     unrolling the text painting code a bit more.  Currently
+ *     defined for MIPS.
+ *  SHARED_IDCACHE -
+ *     For non-Harvard RISC machines, those which share the same
+ *     CPU memory bus for instructions and data.  This unrolls some
+ *     solid fill loops which are otherwise best left rolled up.
+ *     Currently defined for SPARC.
+ */
+
+#ifdef vax
+
+#define IMAGE_BYTE_ORDER       LSBFirst        /* Values for the VAX only */
+#define BITMAP_BIT_ORDER       LSBFirst
+#define        GLYPHPADBYTES           1
+#define GETLEFTBITS_ALIGNMENT  4
+#define FAST_UNALIGNED_READS
+
+#endif /* vax */
+
+#if (defined(Lynx) && defined(__powerpc__))
+
+/* For now this is for Xvfb only */
+#define IMAGE_BYTE_ORDER        MSBFirst
+#define BITMAP_BIT_ORDER        MSBFirst
+#define GLYPHPADBYTES           4
+#define GETLEFTBITS_ALIGNMENT   1
+
+#define LARGE_INSTRUCTION_CACHE
+#define FAST_CONSTANT_OFFSET_MODE
+#define PLENTIFUL_REGISTERS
+#define AVOID_MEMORY_READ
+
+#define FAST_MEMCPY
+
+#endif /* LynxOS PowerPC */
+
+#if (defined(sun) && !(defined(i386) && defined(SVR4))) || \
+    (defined(AMOEBA) && (defined(sparc) || defined(mc68000))) || \
+    (defined(__uxp__) && (defined(sparc) || defined(mc68000))) || \
+    (defined(Lynx) && defined(__sparc__)) || \
+    ((defined(__NetBSD__) || defined(__OpenBSD__)) && \
+     (defined(__sparc__) || defined(__mc68000__)))
+
+#if defined(sun386) || defined(sun5)
+# define IMAGE_BYTE_ORDER      LSBFirst        /* Values for the SUN only */
+# define BITMAP_BIT_ORDER      LSBFirst
+#else
+# define IMAGE_BYTE_ORDER      MSBFirst        /* Values for the SUN only */
+# define BITMAP_BIT_ORDER      MSBFirst
+#endif
+
+#ifdef sparc
+# define AVOID_MEMORY_READ
+# define LARGE_INSTRUCTION_CACHE
+# define FAST_CONSTANT_OFFSET_MODE
+# define SHARED_IDCACHE
+#endif
+
+#ifdef mc68020
+#define FAST_UNALIGNED_READS
+#endif
+
+#define        GLYPHPADBYTES           4
+#define GETLEFTBITS_ALIGNMENT  1
+
+#endif /* sun && !(i386 && SVR4) */
+
+
+#if defined(AIXV3)
+
+#define IMAGE_BYTE_ORDER        MSBFirst        /* Values for the RISC/6000 */
+#define BITMAP_BIT_ORDER        MSBFirst
+#define GLYPHPADBYTES           4
+#define GETLEFTBITS_ALIGNMENT   1
+
+#define LARGE_INSTRUCTION_CACHE
+#define FAST_CONSTANT_OFFSET_MODE
+#define PLENTIFUL_REGISTERS
+#define AVOID_MEMORY_READ
+
+#define FAST_MEMCPY
+#endif /* AIXV3 */
+
+#if defined(ibm032) || defined (ibm)
+
+#ifdef i386
+# define IMAGE_BYTE_ORDER      LSBFirst        /* Value for PS/2 only */
+#else
+# define IMAGE_BYTE_ORDER      MSBFirst        /* Values for the RT only*/
+#endif
+#define BITMAP_BIT_ORDER       MSBFirst
+#define        GLYPHPADBYTES           1
+#define GETLEFTBITS_ALIGNMENT  4
+/* ibm pcc doesn't understand pragmas. */
+
+#ifdef i386
+#define BITMAP_SCANLINE_UNIT   8
+#endif
+
+#endif /* ibm */
+
+#ifdef hpux
+
+#define IMAGE_BYTE_ORDER       MSBFirst        /* Values for the HP only */
+#define BITMAP_BIT_ORDER       MSBFirst
+#define        GLYPHPADBYTES           2               /* to match product server */
+#define        GETLEFTBITS_ALIGNMENT   4               /* PA forces longs to 4 */
+                                               /* byte boundries */
+#define AVOID_MEMORY_READ
+#define FAST_CONSTANT_OFFSET_MODE
+#define LARGE_INSTRUCTION_CACHE
+#define PLENTIFUL_REGISTERS
+
+#endif /* hpux */
+
+#if defined (M4310) || defined(M4315) || defined(M4317) || defined(M4319) || defined(M4330)
+
+#define IMAGE_BYTE_ORDER       MSBFirst        /* Values for Pegasus only */
+#define BITMAP_BIT_ORDER       MSBFirst
+#define GLYPHPADBYTES          4
+#define GETLEFTBITS_ALIGNMENT  1
+
+#define FAST_UNALIGNED_READS
+
+#endif /* tektronix */
+
+#ifdef macII
+
+#define IMAGE_BYTE_ORDER       MSBFirst        /* Values for the MacII only */
+#define BITMAP_BIT_ORDER       MSBFirst
+#define GLYPHPADBYTES          4
+#define GETLEFTBITS_ALIGNMENT  1
+
+/* might want FAST_UNALIGNED_READS for frame buffers with < 1us latency */
+
+#endif /* macII */
+
+#if (defined(mips) || defined(__mips)) && !defined(sgi)
+
+#if defined(MIPSEL) || defined(__MIPSEL__)
+# define IMAGE_BYTE_ORDER      LSBFirst        /* Values for the PMAX only */
+# define BITMAP_BIT_ORDER      LSBFirst
+# define GLYPHPADBYTES         4
+# define GETLEFTBITS_ALIGNMENT 1
+#else
+# define IMAGE_BYTE_ORDER      MSBFirst        /* Values for the MIPS only */
+# define BITMAP_BIT_ORDER      MSBFirst
+# define GLYPHPADBYTES         4
+# define GETLEFTBITS_ALIGNMENT 1
+#endif
+
+#define AVOID_MEMORY_READ
+#define FAST_CONSTANT_OFFSET_MODE
+#define LARGE_INSTRUCTION_CACHE
+#define PLENTIFUL_REGISTERS
+
+#endif /* mips */
+
+#if defined(__alpha) || defined(__alpha__) || defined(__alphaCross)
+# define IMAGE_BYTE_ORDER      LSBFirst        /* Values for the Alpha only */
+
+# if defined(XF86MONOVGA) || defined(XF86VGA16) || defined(XF86MONO)
+#  define BITMAP_BIT_ORDER      MSBFirst
+# else
+#  define BITMAP_BIT_ORDER      LSBFirst
+# endif
+
+# if defined(XF86MONOVGA) || defined(XF86VGA16)
+#  define BITMAP_SCANLINE_UNIT  8
+# else
+   /* pad scanline to a longword */
+#  define BITMAP_SCANLINE_UNIT                 64
+# endif
+
+# define BITMAP_SCANLINE_PAD                   64
+# define LOG2_BITMAP_PAD                       6
+# define LOG2_BYTES_PER_SCANLINE_PAD           3
+# define GLYPHPADBYTES         4
+# define GETLEFTBITS_ALIGNMENT 1
+# define FAST_CONSTANT_OFFSET_MODE
+# define LARGE_INSTRUCTION_CACHE
+# define PLENTIFUL_REGISTERS
+
+/* Add for handling protocol XPutImage and XGetImage; see comment below */
+#define INTERNAL_VS_EXTERNAL_PADDING
+#define BITMAP_SCANLINE_UNIT_PROTO             32
+
+#define BITMAP_SCANLINE_PAD_PROTO              32
+#define LOG2_BITMAP_PAD_PROTO                  5
+#define LOG2_BYTES_PER_SCANLINE_PAD_PROTO      2
+
+#endif /* alpha */
+
+#ifdef stellar
+
+#define IMAGE_BYTE_ORDER       MSBFirst       /* Values for the stellar only*/
+#define BITMAP_BIT_ORDER       MSBFirst
+#define        GLYPHPADBYTES           4
+#define GETLEFTBITS_ALIGNMENT  4
+#define IMAGE_BUFSIZE          (64*1024)
+/*
+ * Use SysV random number generator.
+ */
+#define random rand
+
+#endif /* stellar */
+
+#ifdef luna
+
+#define IMAGE_BYTE_ORDER        MSBFirst       /* Values for the OMRON only*/
+#define BITMAP_BIT_ORDER       MSBFirst
+#define        GLYPHPADBYTES           4
+#define GETLEFTBITS_ALIGNMENT  1
+
+#ifndef mc68000
+#define FAST_CONSTANT_OFFSET_MODE
+#define AVOID_MEMORY_READ
+#define LARGE_INSTRUCTION_CACHE
+#define PLENTIFUL_REGISTERS
+#endif
+
+#endif /* luna */
+
+#if (defined(i386) && (defined(SVR4) || defined(SYSV) || (defined(sun) && defined(SVR4))) || defined(__bsdi__) || (defined(__NetBSD__) && defined(__i386__)) || (defined(__OpenBSD__) && defined(__i386__)) || defined(__FreeBSD__) || defined(MACH386) || (defined(linux) && !(defined(__mc68000__) || defined(PPC) || defined(__sparc__) || defined(__s390__))) || (defined(AMOEBA) && defined(i80386)) || defined(MINIX) || defined(__EMX__) || (defined(Lynx) && defined(__i386__)))
+
+#ifndef IMAGE_BYTE_ORDER
+#define IMAGE_BYTE_ORDER       LSBFirst
+#endif
+
+#ifndef BITMAP_BIT_ORDER
+# if defined(XF86MONOVGA) || defined(XF86VGA16) || defined(XF86MONO)
+#  define BITMAP_BIT_ORDER      MSBFirst
+# else
+#  define BITMAP_BIT_ORDER      LSBFirst
+# endif
+#endif
+
+#ifndef BITMAP_SCANLINE_UNIT
+# if defined(XF86MONOVGA) || defined(XF86VGA16)
+#  define BITMAP_SCANLINE_UNIT  8
+# endif
+#endif
+
+#ifndef GLYPHPADBYTES
+#define GLYPHPADBYTES           4
+#endif
+
+#define GETLEFTBITS_ALIGNMENT  1
+#define AVOID_MEMORY_READ
+#ifdef XSVGA
+#define AVOID_GLYPHBLT
+#define FAST_CONSTANT_OFFSET_MODE
+#define FAST_MEMCPY
+#define NO_ONE_RECT
+#endif
+
+#endif /* SVR4 / BSD / i386 */
+
+#if defined (linux) && defined (__mc68000__)
+
+#define IMAGE_BYTE_ORDER       MSBFirst
+#define BITMAP_BIT_ORDER       MSBFirst
+#define FAST_UNALIGNED_READS
+#define GLYPHPADBYTES          4
+#define GETLEFTBITS_ALIGNMENT  1
+
+#endif /* linux/m68k */
+
+#if defined (linux) && defined (PPC)
+
+#define IMAGE_BYTE_ORDER       MSBFirst
+#define BITMAP_BIT_ORDER       MSBFirst
+#define GLYPHPADBYTES          4
+#define GETLEFTBITS_ALIGNMENT  1
+
+#define LARGE_INSTRUCTION_CACHE
+#define FAST_CONSTANT_OFFSET_MODE
+
+#endif /* linux/PPC */
+
+#if defined (linux) && defined (__sparc__)
+
+#define IMAGE_BYTE_ORDER       MSBFirst
+#define BITMAP_BIT_ORDER       MSBFirst
+#define GLYPHPADBYTES          4
+#define GETLEFTBITS_ALIGNMENT  1
+
+#endif /* linux/__sparc__ */
+
+#if defined (linux) && defined (__s390__)
+
+#define IMAGE_BYTE_ORDER       MSBFirst
+#define BITMAP_BIT_ORDER       MSBFirst
+#define GLYPHPADBYTES          4
+#define GETLEFTBITS_ALIGNMENT  1
+
+#endif /* linux/__s390__ */
+
+#if defined (linux) && defined (PPC)
+
+#define IMAGE_BYTE_ORDER       MSBFirst
+#define BITMAP_BIT_ORDER       MSBFirst
+#define GLYPHPADBYTES          4
+#define GETLEFTBITS_ALIGNMENT  1
+
+#define LARGE_INSTRUCTION_CACHE
+#define FAST_CONSTANT_OFFSET_MODE
+
+#endif /* linux/PPC */
+
+#ifdef sgi
+
+#define IMAGE_BYTE_ORDER       MSBFirst
+#define BITMAP_BIT_ORDER       MSBFirst
+
+#if (_MIPS_SZLONG == 64)
+
+# define GLYPHPADBYTES         4
+# define GETLEFTBITS_ALIGNMENT 1
+
+/* pad scanline to a longword */
+#define BITMAP_SCANLINE_UNIT                   64
+
+#define BITMAP_SCANLINE_PAD                    64
+#define LOG2_BITMAP_PAD                                6
+#define LOG2_BYTES_PER_SCANLINE_PAD            3
+
+/* Add for handling protocol XPutImage and XGetImage; see comment below */
+#define INTERNAL_VS_EXTERNAL_PADDING
+#define BITMAP_SCANLINE_UNIT_PROTO             32
+
+#define BITMAP_SCANLINE_PAD_PROTO              32
+#define LOG2_BITMAP_PAD_PROTO                  5
+#define LOG2_BYTES_PER_SCANLINE_PAD_PROTO      2
+
+#else
+
+#define GLYPHPADBYTES          2
+#define GETLEFTBITS_ALIGNMENT  4
+
+#endif
+
+#define AVOID_MEMORY_READ
+#define FAST_CONSTANT_OFFSET_MODE
+#define LARGE_INSTRUCTION_CACHE
+#define PLENTIFUL_REGISTERS
+
+#endif
+
+/* size of buffer to use with GetImage, measured in bytes. There's obviously
+ * a trade-off between the amount of stack (or whatever ALLOCATE_LOCAL gives
+ * you) used and the number of times the ddx routine has to be called.
+ * 
+ * for a 1024 x 864 bit monochrome screen  with a 32 bit word we get 
+ * 8192/4 words per buffer 
+ * (1024/32) = 32 words per scanline
+ * 2048 words per buffer / 32 words per scanline = 64 scanlines per buffer
+ * 864 scanlines / 64 scanlines = 14 buffers to draw a full screen
+ */
+#ifndef IMAGE_BUFSIZE
+#define IMAGE_BUFSIZE          8192
+#endif
+
+/* pad scanline to a longword */
+#ifndef BITMAP_SCANLINE_UNIT
+#define BITMAP_SCANLINE_UNIT   32
+#endif
+
+#ifndef BITMAP_SCANLINE_PAD
+#define BITMAP_SCANLINE_PAD  32
+#define LOG2_BITMAP_PAD                5
+#define LOG2_BYTES_PER_SCANLINE_PAD    2
+#endif
+
+/* 
+ *   This returns the number of padding units, for depth d and width w.
+ * For bitmaps this can be calculated with the macros above.
+ * Other depths require either grovelling over the formats field of the
+ * screenInfo or hardwired constants.
+ */
+
+typedef struct _PaddingInfo {
+       int     padRoundUp;     /* pixels per pad unit - 1 */
+       int     padPixelsLog2;  /* log 2 (pixels per pad unit) */
+       int     padBytesLog2;   /* log 2 (bytes per pad unit) */
+       int     notPower2;      /* bitsPerPixel not a power of 2 */
+       int     bytesPerPixel;  /* only set when notPower2 is TRUE */
+} PaddingInfo;
+extern PaddingInfo PixmapWidthPaddingInfo[];
+
+#define PixmapWidthInPadUnits(w, d) \
+    (PixmapWidthPaddingInfo[d].notPower2 ? \
+    (((int)(w) * PixmapWidthPaddingInfo[d].bytesPerPixel +  \
+                PixmapWidthPaddingInfo[d].bytesPerPixel) >> \
+       PixmapWidthPaddingInfo[d].padBytesLog2) : \
+    ((int)((w) + PixmapWidthPaddingInfo[d].padRoundUp) >> \
+       PixmapWidthPaddingInfo[d].padPixelsLog2))
+
+/*
+ *     Return the number of bytes to which a scanline of the given
+ * depth and width will be padded.
+ */
+#define PixmapBytePad(w, d) \
+    (PixmapWidthInPadUnits(w, d) << PixmapWidthPaddingInfo[d].padBytesLog2)
+
+#define BitmapBytePad(w) \
+    (((int)((w) + BITMAP_SCANLINE_PAD - 1) >> LOG2_BITMAP_PAD) << LOG2_BYTES_PER_SCANLINE_PAD)
+
+#ifdef INTERNAL_VS_EXTERNAL_PADDING
+
+/*  This is defined if the server's internal padding is different from the padding
+ *  advertised in the protocol.  The protocol does not allow for padding to
+ *  64 bits, for example, so if the server wants to use 64 bit padding internally,
+ *  it has to advertise 32 bit padding and do padding fixups whenever images
+ *  cross the wire.  (See ProcGetImage and ProcPutImage.)
+ *
+ *  The macros and constants that end in Proto or PROTO refer to the advertised
+ *  padding, and the ones without Proto are for internal padding.
+ */
+
+extern PaddingInfo PixmapWidthPaddingInfoProto[];
+
+#define PixmapWidthInPadUnitsProto(w, d) \
+    (PixmapWidthPaddingInfoProto[d].notPower2 ? \
+    (((int)(w) * PixmapWidthPaddingInfoProto[d].bytesPerPixel +  \
+                PixmapWidthPaddingInfoProto[d].bytesPerPixel) >> \
+       PixmapWidthPaddingInfoProto[d].padBytesLog2) : \
+    ((int)((w) + PixmapWidthPaddingInfoProto[d].padRoundUp) >> \
+       PixmapWidthPaddingInfoProto[d].padPixelsLog2))
+
+#define PixmapBytePadProto(w, d) \
+    (PixmapWidthInPadUnitsProto(w, d) << \
+    PixmapWidthPaddingInfoProto[d].padBytesLog2)
+
+#define BitmapBytePadProto(w) \
+    ((((w) + BITMAP_SCANLINE_PAD_PROTO - 1) >> LOG2_BITMAP_PAD_PROTO) \
+    << LOG2_BYTES_PER_SCANLINE_PAD_PROTO)
+
+#else /* protocol and internal padding is the same */
+
+#define PixmapWidthInPadUnitsProto(w, d) PixmapWidthInPadUnits(w, d)
+#define PixmapBytePadProto(w, d) PixmapBytePad(w, d)
+#define BitmapBytePadProto(w) BitmapBytePad(w)
+
+#endif /* protocol vs. internal padding  */
+
+#endif /* SERVERMD_H */
diff --git a/Xserver/programs/Xserver/include/site.h b/Xserver/programs/Xserver/include/site.h
new file mode 100644 (file)
index 0000000..1ef024d
--- /dev/null
@@ -0,0 +1,138 @@
+/* $XConsortium: site.h /main/27 1996/12/09 17:52:19 kaleb $ */
+/************************************************************
+
+Copyright (c) 1987  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+
+Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
+
+                        All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and its 
+documentation for any purpose and without fee is hereby granted, 
+provided that the above copyright notice appear in all copies and that
+both that copyright notice and this permission notice appear in 
+supporting documentation, and that the name of Digital not be
+used in advertising or publicity pertaining to distribution of the
+software without specific, written prior permission.  
+
+DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
+ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
+DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
+ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+SOFTWARE.
+
+********************************************************/
+
+#ifndef SITE_H
+#define SITE_H
+/*
+ * The vendor string identifies the vendor responsible for the
+ * server executable.
+ */
+#ifndef VENDOR_STRING
+#define VENDOR_STRING "X Consortium"
+#endif
+
+/*
+ * The vendor release number identifies, for the purpose of submitting
+ * traceable bug reports, the release number of software produced
+ * by the vendor.
+ */
+#ifndef VENDOR_RELEASE
+#define VENDOR_RELEASE 6300
+#endif
+
+/*
+ * The following constants are provided solely as a last line of defense.  The
+ * normal build ALWAYS overrides them using a special rule given in
+ * server/dix/Imakefile.  If you want to change either of these constants, 
+ * you should set the DefaultFontPath or DefaultRGBDatabase configuration 
+ * parameters.
+ * DO NOT CHANGE THESE VALUES OR THE DIX IMAKEFILE!
+ */
+#ifndef COMPILEDDEFAULTFONTPATH
+#define COMPILEDDEFAULTFONTPATH        "/usr/lib/X11/fonts/misc/"
+#endif
+#ifndef RGB_DB
+#define RGB_DB                 "/usr/lib/X11/rgb"
+#endif
+
+/*
+ * The following constants contain default values for all of the variables 
+ * that can be initialized on the server command line or in the environment.
+ */
+#define COMPILEDDEFAULTFONT    "fixed"
+#define COMPILEDCURSORFONT     "cursor"
+#ifndef COMPILEDDISPLAYCLASS
+#define COMPILEDDISPLAYCLASS   "MIT-unspecified"
+#endif
+#define DEFAULT_TIMEOUT                60      /* seconds */
+#define DEFAULT_KEYBOARD_CLICK         0
+#define DEFAULT_BELL           50
+#define DEFAULT_BELL_PITCH     400
+#define DEFAULT_BELL_DURATION  100
+#ifdef XKB
+#define DEFAULT_AUTOREPEAT     TRUE
+#else
+#define DEFAULT_AUTOREPEAT     FALSE
+#endif
+#ifdef hpux
+#define DEFAULT_AUTOREPEATS    {\
+        0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,\
+        0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,\
+        0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
+        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
+#else
+#define DEFAULT_AUTOREPEATS    {\
+       0, 0, 0, 0, 0, 0, 0, 0,\
+       0, 0, 0, 0, 0, 0, 0, 0,\
+       0, 0, 0, 0, 0, 0, 0, 0,\
+       0, 0, 0, 0, 0, 0, 0, 0 }
+#endif
+#define DEFAULT_LEDS           0x0        /* all off */
+#define DEFAULT_LEDS_MASK      0xffffffff /* 32 */
+#define DEFAULT_INT_RESOLUTION         1000
+#define DEFAULT_INT_MIN_VALUE          0
+#define DEFAULT_INT_MAX_VALUE          100
+#define DEFAULT_INT_DISPLAYED          0
+
+#define DEFAULT_PTR_NUMERATOR  2
+#define DEFAULT_PTR_DENOMINATOR        1
+#define DEFAULT_PTR_THRESHOLD  4
+
+#define DEFAULT_SCREEN_SAVER_TIME (10 * (60 * 1000))
+#define DEFAULT_SCREEN_SAVER_INTERVAL (10 * (60 * 1000))
+#define DEFAULT_SCREEN_SAVER_BLANKING PreferBlanking
+#define DEFAULT_SCREEN_SAVER_EXPOSURES AllowExposures
+#ifndef NOLOGOHACK
+#define DEFAULT_LOGO_SCREEN_SAVER 1
+#endif
+#ifndef DEFAULT_ACCESS_CONTROL
+#define DEFAULT_ACCESS_CONTROL TRUE
+#endif
+
+#endif /* SITE_H */
diff --git a/Xserver/programs/Xserver/include/swaprep.h b/Xserver/programs/Xserver/include/swaprep.h
new file mode 100644 (file)
index 0000000..a8453db
--- /dev/null
@@ -0,0 +1,542 @@
+/* $XFree86: xc/programs/Xserver/include/swaprep.h,v 3.0 1996/04/15 11:34:34 dawes Exp $ */
+/************************************************************
+
+Copyright 1996 by Thomas E. Dickey <dickey@clark.net>
+
+                        All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and its
+documentation for any purpose and without fee is hereby granted,
+provided that the above copyright notice appear in all copies and that
+both that copyright notice and this permission notice appear in
+supporting documentation, and that the name of the above listed
+copyright holder(s) not be used in advertising or publicity pertaining
+to distribution of the software without specific, written prior
+permission.
+
+THE ABOVE LISTED COPYRIGHT HOLDER(S) DISCLAIM ALL WARRANTIES WITH REGARD
+TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+AND FITNESS, IN NO EVENT SHALL THE ABOVE LISTED COPYRIGHT HOLDER(S) BE
+LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+
+********************************************************/
+
+#ifndef SWAPREP_H
+#define SWAPREP_H 1
+
+void
+Swap32Write(
+#if NeedFunctionPrototypes
+    ClientPtr /* pClient */,
+    int /* size */,
+    CARD32 * /* pbuf */
+#endif
+);
+
+void
+CopySwap32Write(
+#if NeedFunctionPrototypes
+    ClientPtr /* pClient */,
+    int /* size */,
+    CARD32 * /* pbuf */
+#endif
+);
+
+void
+CopySwap16Write(
+#if NeedFunctionPrototypes
+    ClientPtr /* pClient */,
+    int /* size */,
+    short * /* pbuf */
+#endif
+);
+
+void
+SGenericReply(
+#if NeedFunctionPrototypes
+    ClientPtr /* pClient */,
+    int /* size */,
+    xGenericReply * /* pRep */
+#endif
+);
+
+void
+SGetWindowAttributesReply(
+#if NeedFunctionPrototypes
+    ClientPtr /* pClient */,
+    int /* size */,
+    xGetWindowAttributesReply * /* pRep */
+#endif
+);
+
+void
+SGetGeometryReply(
+#if NeedFunctionPrototypes
+    ClientPtr /* pClient */,
+    int /* size */,
+    xGetGeometryReply * /* pRep */
+#endif
+);
+
+void
+SQueryTreeReply(
+#if NeedFunctionPrototypes
+    ClientPtr /* pClient */,
+    int /* size */,
+    xQueryTreeReply * /* pRep */
+#endif
+);
+
+void
+SInternAtomReply(
+#if NeedFunctionPrototypes
+    ClientPtr /* pClient */,
+    int /* size */,
+    xInternAtomReply * /* pRep */
+#endif
+);
+
+void
+SGetAtomNameReply(
+#if NeedFunctionPrototypes
+    ClientPtr /* pClient */,
+    int /* size */,
+    xGetAtomNameReply * /* pRep */
+#endif
+);
+
+void
+SGetPropertyReply(
+#if NeedFunctionPrototypes
+    ClientPtr /* pClient */,
+    int /* size */,
+    xGetPropertyReply * /* pRep */
+#endif
+);
+
+void
+SListPropertiesReply(
+#if NeedFunctionPrototypes
+    ClientPtr /* pClient */,
+    int /* size */,
+    xListPropertiesReply * /* pRep */
+#endif
+);
+
+void
+SGetSelectionOwnerReply(
+#if NeedFunctionPrototypes
+    ClientPtr /* pClient */,
+    int /* size */,
+    xGetSelectionOwnerReply * /* pRep */
+#endif
+);
+
+void
+SQueryPointerReply(
+#if NeedFunctionPrototypes
+    ClientPtr /* pClient */,
+    int /* size */,
+    xQueryPointerReply * /* pRep */
+#endif
+);
+
+void
+SwapTimecoord(
+#if NeedFunctionPrototypes
+    xTimecoord * /* pCoord */
+#endif
+);
+
+void
+SwapTimeCoordWrite(
+#if NeedFunctionPrototypes
+    ClientPtr /* pClient */,
+    int /* size */,
+    xTimecoord * /* pRep */
+#endif
+);
+
+void
+SGetMotionEventsReply(
+#if NeedFunctionPrototypes
+    ClientPtr /* pClient */,
+    int /* size */,
+    xGetMotionEventsReply * /* pRep */
+#endif
+);
+
+void
+STranslateCoordsReply(
+#if NeedFunctionPrototypes
+    ClientPtr /* pClient */,
+    int /* size */,
+    xTranslateCoordsReply * /* pRep */
+#endif
+);
+
+void
+SGetInputFocusReply(
+#if NeedFunctionPrototypes
+    ClientPtr /* pClient */,
+    int /* size */,
+    xGetInputFocusReply * /* pRep */
+#endif
+);
+
+void
+SQueryKeymapReply(
+#if NeedFunctionPrototypes
+    ClientPtr /* pClient */,
+    int /* size */,
+    xQueryKeymapReply * /* pRep */
+#endif
+);
+
+#ifdef LBX
+void
+SwapCharInfo(
+#if NeedFunctionPrototypes
+    xCharInfo * /* pInfo */
+#endif
+);
+#endif
+
+#ifdef LBX
+void
+SwapFont(
+#if NeedFunctionPrototypes
+    xQueryFontReply * /* pr */,
+    Bool /* hasGlyphs */
+#endif
+);
+#endif
+
+void
+SQueryFontReply(
+#if NeedFunctionPrototypes
+    ClientPtr /* pClient */,
+    int /* size */,
+    xQueryFontReply * /* pRep */
+#endif
+);
+
+void
+SQueryTextExtentsReply(
+#if NeedFunctionPrototypes
+    ClientPtr /* pClient */,
+    int /* size */,
+    xQueryTextExtentsReply * /* pRep */
+#endif
+);
+
+void
+SListFontsReply(
+#if NeedFunctionPrototypes
+    ClientPtr /* pClient */,
+    int /* size */,
+    xListFontsReply * /* pRep */
+#endif
+);
+
+void
+SListFontsWithInfoReply(
+#if NeedFunctionPrototypes
+    ClientPtr /* pClient */,
+    int /* size */,
+    xListFontsWithInfoReply * /* pRep */
+#endif
+);
+
+void
+SGetFontPathReply(
+#if NeedFunctionPrototypes
+    ClientPtr /* pClient */,
+    int /* size */,
+    xGetFontPathReply * /* pRep */
+#endif
+);
+
+void
+SGetImageReply(
+#if NeedFunctionPrototypes
+    ClientPtr /* pClient */,
+    int /* size */,
+    xGetImageReply * /* pRep */
+#endif
+);
+
+void
+SListInstalledColormapsReply(
+#if NeedFunctionPrototypes
+    ClientPtr /* pClient */,
+    int /* size */,
+    xListInstalledColormapsReply * /* pRep */
+#endif
+);
+
+void
+SAllocColorReply(
+#if NeedFunctionPrototypes
+    ClientPtr /* pClient */,
+    int /* size */,
+    xAllocColorReply * /* pRep */
+#endif
+);
+
+void
+SAllocNamedColorReply(
+#if NeedFunctionPrototypes
+    ClientPtr /* pClient */,
+    int /* size */,
+    xAllocNamedColorReply * /* pRep */
+#endif
+);
+
+void
+SAllocColorCellsReply(
+#if NeedFunctionPrototypes
+    ClientPtr /* pClient */,
+    int /* size */,
+    xAllocColorCellsReply * /* pRep */
+#endif
+);
+
+void
+SAllocColorPlanesReply(
+#if NeedFunctionPrototypes
+    ClientPtr /* pClient */,
+    int /* size */,
+    xAllocColorPlanesReply * /* pRep */
+#endif
+);
+
+void
+SwapRGB(
+#if NeedFunctionPrototypes
+    xrgb * /* prgb */
+#endif
+);
+
+void
+SQColorsExtend(
+#if NeedFunctionPrototypes
+    ClientPtr /* pClient */,
+    int /* size */,
+    xrgb * /* prgb */
+#endif
+);
+
+void
+SQueryColorsReply(
+#if NeedFunctionPrototypes
+    ClientPtr /* pClient */,
+    int /* size */,
+    xQueryColorsReply * /* pRep */
+#endif
+);
+
+void
+SLookupColorReply(
+#if NeedFunctionPrototypes
+    ClientPtr /* pClient */,
+    int /* size */,
+    xLookupColorReply * /* pRep */
+#endif
+);
+
+void
+SQueryBestSizeReply(
+#if NeedFunctionPrototypes
+    ClientPtr /* pClient */,
+    int /* size */,
+    xQueryBestSizeReply * /* pRep */
+#endif
+);
+
+void
+SListExtensionsReply(
+#if NeedFunctionPrototypes
+    ClientPtr /* pClient */,
+    int /* size */,
+    xListExtensionsReply * /* pRep */
+#endif
+);
+
+void
+SGetKeyboardMappingReply(
+#if NeedFunctionPrototypes
+    ClientPtr /* pClient */,
+    int /* size */,
+    xGetKeyboardMappingReply * /* pRep */
+#endif
+);
+
+void
+SGetPointerMappingReply(
+#if NeedFunctionPrototypes
+    ClientPtr /* pClient */,
+    int /* size */,
+    xGetPointerMappingReply * /* pRep */
+#endif
+);
+
+void
+SGetModifierMappingReply(
+#if NeedFunctionPrototypes
+    ClientPtr /* pClient */,
+    int /* size */,
+    xGetModifierMappingReply * /* pRep */
+#endif
+);
+
+void
+SGetKeyboardControlReply(
+#if NeedFunctionPrototypes
+    ClientPtr /* pClient */,
+    int /* size */,
+    xGetKeyboardControlReply * /* pRep */
+#endif
+);
+
+void
+SGetPointerControlReply(
+#if NeedFunctionPrototypes
+    ClientPtr /* pClient */,
+    int /* size */,
+    xGetPointerControlReply * /* pRep */
+#endif
+);
+
+void
+SGetScreenSaverReply(
+#if NeedFunctionPrototypes
+    ClientPtr /* pClient */,
+    int /* size */,
+    xGetScreenSaverReply * /* pRep */
+#endif
+);
+
+void
+SLHostsExtend(
+#if NeedFunctionPrototypes
+    ClientPtr /* pClient */,
+    int /* size */,
+    char * /* buf */
+#endif
+);
+
+void
+SListHostsReply(
+#if NeedFunctionPrototypes
+    ClientPtr /* pClient */,
+    int /* size */,
+    xListHostsReply * /* pRep */
+#endif
+);
+
+void
+SErrorEvent(
+#if NeedFunctionPrototypes
+    xError * /* from */,
+    xError * /* to */
+#endif
+);
+
+void
+SwapConnSetupInfo(
+#if NeedFunctionPrototypes
+    char * /* pInfo */,
+    char * /* pInfoTBase */
+#endif
+);
+
+void
+WriteSConnectionInfo(
+#if NeedFunctionPrototypes
+    ClientPtr /* pClient */,
+    unsigned long /* size */,
+    char * /* pInfo */
+#endif
+);
+
+void
+SwapConnSetup(
+#if NeedFunctionPrototypes
+    xConnSetup * /* pConnSetup */,
+    xConnSetup * /* pConnSetupT */
+#endif
+);
+
+void
+SwapWinRoot(
+#if NeedFunctionPrototypes
+    xWindowRoot * /* pRoot */,
+    xWindowRoot * /* pRootT */
+#endif
+);
+
+void
+SwapVisual(
+#if NeedFunctionPrototypes
+    xVisualType * /* pVis */,
+    xVisualType * /* pVisT */
+#endif
+);
+
+void
+SwapConnSetupPrefix(
+#if NeedFunctionPrototypes
+    xConnSetupPrefix * /* pcspFrom */,
+    xConnSetupPrefix * /* pcspTo */
+#endif
+);
+
+void
+WriteSConnSetupPrefix(
+#if NeedFunctionPrototypes
+    ClientPtr /* pClient */,
+    xConnSetupPrefix * /* pcsp */
+#endif
+);
+
+#undef SWAPREP_PROC
+#if NeedFunctionPrototypes
+#define SWAPREP_PROC(func) void func(xEvent * /* from */, xEvent * /* to */)
+#else
+#define SWAPREP_PROC(func) void func(/* xEvent * from,    xEvent *    to */)
+#endif
+
+SWAPREP_PROC(SCirculateEvent);
+SWAPREP_PROC(SClientMessageEvent);
+SWAPREP_PROC(SColormapEvent);
+SWAPREP_PROC(SConfigureNotifyEvent);
+SWAPREP_PROC(SConfigureRequestEvent);
+SWAPREP_PROC(SCreateNotifyEvent);
+SWAPREP_PROC(SDestroyNotifyEvent);
+SWAPREP_PROC(SEnterLeaveEvent);
+SWAPREP_PROC(SExposeEvent);
+SWAPREP_PROC(SFocusEvent);
+SWAPREP_PROC(SGraphicsExposureEvent);
+SWAPREP_PROC(SGravityEvent);
+SWAPREP_PROC(SKeyButtonPtrEvent);
+SWAPREP_PROC(SKeymapNotifyEvent);
+SWAPREP_PROC(SMapNotifyEvent);
+SWAPREP_PROC(SMapRequestEvent);
+SWAPREP_PROC(SMappingEvent);
+SWAPREP_PROC(SNoExposureEvent);
+SWAPREP_PROC(SPropertyEvent);
+SWAPREP_PROC(SReparentEvent);
+SWAPREP_PROC(SResizeRequestEvent);
+SWAPREP_PROC(SSelectionClearEvent);
+SWAPREP_PROC(SSelectionNotifyEvent);
+SWAPREP_PROC(SSelectionRequestEvent);
+SWAPREP_PROC(SUnmapNotifyEvent);
+SWAPREP_PROC(SVisibilityEvent);
+
+#undef SWAPREP_PROC
+
+#endif /* SWAPREP_H */
diff --git a/Xserver/programs/Xserver/include/validate.h b/Xserver/programs/Xserver/include/validate.h
new file mode 100644 (file)
index 0000000..756ad89
--- /dev/null
@@ -0,0 +1,42 @@
+/* $XConsortium: validate.h,v 5.4 94/04/17 20:26:11 dpw Exp $ */
+
+/*
+
+Copyright (c) 1989  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+*/
+
+#ifndef VALIDATE_H
+#define VALIDATE_H
+
+#include "miscstruct.h"
+#include "regionstr.h"
+
+typedef enum { VTOther, VTStack, VTMove, VTUnmap, VTMap } VTKind;
+
+/* union _Validate is now device dependent; see mivalidate.h for an example */
+typedef union _Validate *ValidatePtr;
+
+#define UnmapValData ((ValidatePtr)1)
+
+#endif /* VALIDATE_H */
diff --git a/Xserver/programs/Xserver/include/window.h b/Xserver/programs/Xserver/include/window.h
new file mode 100644 (file)
index 0000000..462d0b9
--- /dev/null
@@ -0,0 +1,351 @@
+/* $XConsortium: window.h /main/8 1996/03/21 13:35:33 mor $ */
+/***********************************************************
+
+Copyright (c) 1987  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+
+Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
+
+                        All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and its 
+documentation for any purpose and without fee is hereby granted, 
+provided that the above copyright notice appear in all copies and that
+both that copyright notice and this permission notice appear in 
+supporting documentation, and that the name of Digital not be
+used in advertising or publicity pertaining to distribution of the
+software without specific, written prior permission.  
+
+DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
+ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
+DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
+ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+SOFTWARE.
+
+******************************************************************/
+
+#ifndef WINDOW_H
+#define WINDOW_H
+
+#include "misc.h"
+#include "region.h"
+#include "screenint.h"
+#include "X11/Xproto.h"
+
+#define TOTALLY_OBSCURED 0
+#define UNOBSCURED 1
+#define OBSCURED 2
+
+#define VisibilityNotViewable  3
+
+/* return values for tree-walking callback procedures */
+#define WT_STOPWALKING         0
+#define WT_WALKCHILDREN                1
+#define WT_DONTWALKCHILDREN    2
+#define WT_NOMATCH 3
+#define NullWindow ((WindowPtr) 0)
+
+typedef struct _BackingStore *BackingStorePtr;
+typedef struct _Window *WindowPtr;
+
+typedef int (*VisitWindowProcPtr)(
+#if NeedNestedPrototypes
+    WindowPtr /*pWin*/,
+    pointer /*data*/
+#endif
+);
+
+extern int TraverseTree(
+#if NeedFunctionPrototypes
+    WindowPtr /*pWin*/,
+    VisitWindowProcPtr /*func*/,
+    pointer /*data*/
+#endif
+);
+
+extern int WalkTree(
+#if NeedFunctionPrototypes
+    ScreenPtr /*pScreen*/,
+    VisitWindowProcPtr /*func*/,
+    pointer /*data*/
+#endif
+);
+
+extern WindowPtr AllocateWindow(
+#if NeedFunctionPrototypes
+    ScreenPtr /*pScreen*/
+#endif
+);
+
+extern Bool CreateRootWindow(
+#if NeedFunctionPrototypes
+    ScreenPtr /*pScreen*/
+#endif
+);
+
+extern void InitRootWindow(
+#if NeedFunctionPrototypes
+    WindowPtr /*pWin*/
+#endif
+);
+
+extern void ClippedRegionFromBox(
+#if NeedFunctionPrototypes
+    WindowPtr /*pWin*/,
+    RegionPtr /*Rgn*/,
+    int /*x*/,
+    int /*y*/,
+    int /*w*/,
+    int /*h*/
+#endif
+);
+
+extern WindowPtr RealChildHead(
+#if NeedFunctionPrototypes
+    WindowPtr /*pWin*/
+#endif
+);
+
+extern WindowPtr CreateWindow(
+#if NeedFunctionPrototypes
+    Window /*wid*/,
+    WindowPtr /*pParent*/,
+    int /*x*/,
+    int /*y*/,
+    unsigned int /*w*/,
+    unsigned int /*h*/,
+    unsigned int /*bw*/,
+    unsigned int /*class*/,
+    Mask /*vmask*/,
+    XID* /*vlist*/,
+    int /*depth*/,
+    ClientPtr /*client*/,
+    VisualID /*visual*/,
+    int* /*error*/
+#endif
+);
+
+extern int DeleteWindow(
+#if NeedFunctionPrototypes
+    pointer /*pWin*/,
+    XID /*wid*/
+#endif
+);
+
+extern void DestroySubwindows(
+#if NeedFunctionPrototypes
+    WindowPtr /*pWin*/,
+    ClientPtr /*client*/
+#endif
+);
+
+extern int ChangeWindowAttributes(
+#if NeedFunctionPrototypes
+    WindowPtr /*pWin*/,
+    Mask /*vmask*/,
+    XID* /*vlist*/,
+    ClientPtr /*client*/
+#endif
+);
+
+extern void GetWindowAttributes(
+#if NeedFunctionPrototypes
+    WindowPtr /*pWin*/,
+    ClientPtr /*client*/,
+    xGetWindowAttributesReply* /* wa */
+#endif
+);
+
+extern RegionPtr CreateUnclippedWinSize(
+#if NeedFunctionPrototypes
+    WindowPtr /*pWin*/
+#endif
+);
+
+extern void GravityTranslate(
+#if NeedFunctionPrototypes
+    int /*x*/,
+    int /*y*/,
+    int /*oldx*/,
+    int /*oldy*/,
+    int /*dw*/,
+    int /*dh*/,
+    unsigned /*gravity*/,
+    int* /*destx*/,
+    int* /*desty*/
+#endif
+);
+
+extern int ConfigureWindow(
+#if NeedFunctionPrototypes
+    WindowPtr /*pWin*/,
+    Mask /*mask*/,
+    XID* /*vlist*/,
+    ClientPtr /*client*/
+#endif
+);
+
+extern int CirculateWindow(
+#if NeedFunctionPrototypes
+    WindowPtr /*pParent*/,
+    int /*direction*/,
+    ClientPtr /*client*/
+#endif
+);
+
+extern int ReparentWindow(
+#if NeedFunctionPrototypes
+    WindowPtr /*pWin*/,
+    WindowPtr /*pParent*/,
+    int /*x*/,
+    int /*y*/,
+    ClientPtr /*client*/
+#endif
+);
+
+extern int MapWindow(
+#if NeedFunctionPrototypes
+    WindowPtr /*pWin*/,
+    ClientPtr /*client*/
+#endif
+);
+
+extern void MapSubwindows(
+#if NeedFunctionPrototypes
+    WindowPtr /*pParent*/,
+    ClientPtr /*client*/
+#endif
+);
+
+extern int UnmapWindow(
+#if NeedFunctionPrototypes
+    WindowPtr /*pWin*/,
+    Bool /*fromConfigure*/
+#endif
+);
+
+extern void UnmapSubwindows(
+#if NeedFunctionPrototypes
+    WindowPtr /*pWin*/
+#endif
+);
+
+extern void HandleSaveSet(
+#if NeedFunctionPrototypes
+    ClientPtr /*client*/
+#endif
+);
+
+extern Bool VisibleBoundingBoxFromPoint(
+#if NeedFunctionPrototypes
+    WindowPtr /*pWin*/,
+    int /*x*/,
+    int /*y*/,
+    BoxPtr /*box*/
+#endif
+);
+
+extern Bool PointInWindowIsVisible(
+#if NeedFunctionPrototypes
+    WindowPtr /*pWin*/,
+    int /*x*/,
+    int /*y*/
+#endif
+);
+
+extern RegionPtr NotClippedByChildren(
+#if NeedFunctionPrototypes
+    WindowPtr /*pWin*/
+#endif
+);
+
+extern void SendVisibilityNotify(
+#if NeedFunctionPrototypes
+    WindowPtr /*pWin*/
+#endif
+);
+
+extern void SaveScreens(
+#if NeedFunctionPrototypes
+    int /*on*/,
+    int /*mode*/
+#endif
+);
+
+extern WindowPtr FindWindowWithOptional(
+#if NeedFunctionPrototypes
+    WindowPtr /*w*/
+#endif
+);
+
+extern void CheckWindowOptionalNeed(
+#if NeedFunctionPrototypes
+    WindowPtr /*w*/
+#endif
+);
+
+extern Bool MakeWindowOptional(
+#if NeedFunctionPrototypes
+    WindowPtr /*pWin*/
+#endif
+);
+
+extern void DisposeWindowOptional(
+#if NeedFunctionPrototypes
+    WindowPtr /*pWin*/
+#endif
+);
+
+extern WindowPtr MoveWindowInStack(
+#if NeedFunctionPrototypes
+    WindowPtr /*pWin*/,
+    WindowPtr /*pNextSib*/
+#endif
+);
+
+void SetWinSize(
+#if NeedFunctionPrototypes
+    WindowPtr /*pWin*/
+#endif
+);
+
+void SetBorderSize(
+#if NeedFunctionPrototypes
+    WindowPtr /*pWin*/
+#endif
+);
+
+void ResizeChildrenWinSize(
+#if NeedFunctionPrototypes
+    WindowPtr /*pWin*/,
+    int /*dx*/,
+    int /*dy*/,
+    int /*dw*/,
+    int /*dh*/
+#endif
+);
+
+#endif /* WINDOW_H */
diff --git a/Xserver/programs/Xserver/include/windowstr.h b/Xserver/programs/Xserver/include/windowstr.h
new file mode 100644 (file)
index 0000000..e39ef5a
--- /dev/null
@@ -0,0 +1,228 @@
+/* $XConsortium: windowstr.h /main/36 1995/09/22 10:23:19 dpw $ */
+/***********************************************************
+
+Copyright (c) 1987  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+
+Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
+
+                        All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and its 
+documentation for any purpose and without fee is hereby granted, 
+provided that the above copyright notice appear in all copies and that
+both that copyright notice and this permission notice appear in 
+supporting documentation, and that the name of Digital not be
+used in advertising or publicity pertaining to distribution of the
+software without specific, written prior permission.  
+
+DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
+ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
+DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
+ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+SOFTWARE.
+
+******************************************************************/
+
+#ifndef WINDOWSTRUCT_H
+#define WINDOWSTRUCT_H
+
+#include "window.h"
+#include "pixmapstr.h"
+#include "regionstr.h"
+#include "cursor.h"
+#include "property.h"
+#include "resource.h"  /* for ROOT_WINDOW_ID_BASE */
+#include "dix.h"
+#include "miscstruct.h"
+#include "X11/Xprotostr.h"
+#include "opaque.h"
+
+#define GuaranteeNothing       0
+#define GuaranteeVisBack       1
+
+#define SameBackground(as, a, bs, b)                           \
+    ((as) == (bs) && ((as) == None ||                          \
+                     (as) == ParentRelative ||                 \
+                     SamePixUnion(a,b,as == BackgroundPixel)))
+
+#define SameBorder(as, a, bs, b)                               \
+    EqualPixUnion(as, a, bs, b)
+
+typedef struct _WindowOpt {
+    VisualID           visual;            /* default: same as parent */
+    CursorPtr          cursor;            /* default: window.cursorNone */
+    Colormap           colormap;          /* default: same as parent */
+    Mask               dontPropagateMask; /* default: window.dontPropagate */
+    Mask               otherEventMasks;   /* default: 0 */
+    struct _OtherClients *otherClients;           /* default: NULL */
+    struct _GrabRec    *passiveGrabs;     /* default: NULL */
+    PropertyPtr                userProps;         /* default: NULL */
+    unsigned long      backingBitPlanes;  /* default: ~0L */
+    unsigned long      backingPixel;      /* default: 0 */
+#ifdef SHAPE
+    RegionPtr          boundingShape;     /* default: NULL */
+    RegionPtr          clipShape;         /* default: NULL */
+#endif
+#ifdef XINPUT
+    struct _OtherInputMasks *inputMasks;   /* default: NULL */
+#endif
+} WindowOptRec, *WindowOptPtr;
+
+#define BackgroundPixel            2L
+#define BackgroundPixmap    3L
+
+typedef struct _Window {
+    DrawableRec                drawable;
+    WindowPtr          parent;         /* ancestor chain */
+    WindowPtr          nextSib;        /* next lower sibling */
+    WindowPtr          prevSib;        /* next higher sibling */
+    WindowPtr          firstChild;     /* top-most child */
+    WindowPtr          lastChild;      /* bottom-most child */
+    RegionRec          clipList;       /* clipping rectangle for output */
+    RegionRec          borderClip;     /* NotClippedByChildren + border */
+    union _Validate    *valdata;
+    RegionRec          winSize;
+    RegionRec          borderSize;
+    DDXPointRec                origin;         /* position relative to parent */
+    unsigned short     borderWidth;
+    unsigned short     deliverableEvents;
+    Mask               eventMask;
+    PixUnion           background;
+    PixUnion           border;
+    pointer            backStorage;    /* null when BS disabled */
+    WindowOptPtr       optional;
+    unsigned           backgroundState:2; /* None, Relative, Pixel, Pixmap */
+    unsigned           borderIsPixel:1;
+    unsigned           cursorIsNone:1; /* else real cursor (might inherit) */
+    unsigned           backingStore:2;
+    unsigned           saveUnder:1;
+    unsigned           DIXsaveUnder:1;
+    unsigned           bitGravity:4;
+    unsigned           winGravity:4;
+    unsigned           overrideRedirect:1;
+    unsigned           visibility:2;
+    unsigned           mapped:1;
+    unsigned           realized:1;     /* ancestors are all mapped */
+    unsigned           viewable:1;     /* realized && InputOutput */
+    unsigned           dontPropagate:3;/* index into DontPropagateMasks */
+    unsigned           forcedBS:1;     /* system-supplied backingStore */
+#ifdef NEED_DBE_BUF_BITS
+#define DBE_FRONT_BUFFER 1
+#define DBE_BACK_BUFFER  0
+    unsigned           dstBuffer:1;    /* destination buffer for rendering */
+    unsigned           srcBuffer:1;    /* source buffer for rendering */
+#endif
+    DevUnion           *devPrivates;
+} WindowRec;
+
+/*
+ * Ok, a bunch of macros for accessing the optional record
+ * fields (or filling the appropriate default value)
+ */
+
+extern Mask        DontPropagateMasks[];
+
+#define wTrackParent(w,field)  ((w)->optional ? \
+                                   (w)->optional->field \
+                                : FindWindowWithOptional(w)->optional->field)
+#define wUseDefault(w,field,def)       ((w)->optional ? \
+                                   (w)->optional->field \
+                                : def)
+
+#define wVisual(w)             wTrackParent(w, visual)
+#define wCursor(w)             ((w)->cursorIsNone ? None : wTrackParent(w, cursor))
+#define wColormap(w)           ((w)->drawable.class == InputOnly ? None : wTrackParent(w, colormap))
+#define wDontPropagateMask(w)  wUseDefault(w, dontPropagateMask, DontPropagateMasks[(w)->dontPropagate])
+#define wOtherEventMasks(w)    wUseDefault(w, otherEventMasks, 0)
+#define wOtherClients(w)       wUseDefault(w, otherClients, NULL)
+#ifdef XINPUT
+#define wOtherInputMasks(w)    wUseDefault(w, inputMasks, NULL)
+#else
+#define wOtherInputMasks(w)    NULL
+#endif
+#define wPassiveGrabs(w)       wUseDefault(w, passiveGrabs, NULL)
+#define wUserProps(w)          wUseDefault(w, userProps, NULL)
+#define wBackingBitPlanes(w)   wUseDefault(w, backingBitPlanes, ~0L)
+#define wBackingPixel(w)       wUseDefault(w, backingPixel, 0)
+#ifdef SHAPE
+#define wBoundingShape(w)      wUseDefault(w, boundingShape, NULL)
+#define wClipShape(w)          wUseDefault(w, clipShape, NULL)
+#endif
+#define wClient(w)             (clients[CLIENT_ID((w)->drawable.id)])
+#define wBorderWidth(w)                ((int) (w)->borderWidth)
+
+/* true when w needs a border drawn. */
+
+#ifdef SHAPE
+#define HasBorder(w)   ((w)->borderWidth || wClipShape(w))
+#else
+#define HasBorder(w)   ((w)->borderWidth)
+#endif
+
+typedef struct _ScreenSaverStuff {
+    WindowPtr pWindow;
+    XID       wid;
+    char      blanked;
+    Bool      (*ExternalScreenSaver)(
+#if NeedNestedPrototypes
+       ScreenPtr       /*pScreen*/,
+       int             /*xstate*/,
+       Bool            /*force*/
+#endif
+    );
+} ScreenSaverStuffRec, *ScreenSaverStuffPtr;
+
+#define SCREEN_IS_BLANKED   0
+#define SCREEN_ISNT_SAVED   1
+#define SCREEN_IS_TILED     2
+#define SCREEN_IS_BLACK            3
+
+#define HasSaverWindow(i)   (savedScreenInfo[i].pWindow != NullWindow)
+
+extern int screenIsSaved;
+extern ScreenSaverStuffRec savedScreenInfo[MAXSCREENS];
+
+/*
+ * this is the configuration parameter "NO_BACK_SAVE"
+ * it means that any existant backing store should not 
+ * be used to implement save unders.
+ */
+
+#ifndef NO_BACK_SAVE
+#define DO_SAVE_UNDERS(pWin)   ((pWin)->drawable.pScreen->saveUnderSupport ==\
+                                USE_DIX_SAVE_UNDERS)
+/*
+ * saveUnderSupport is set to this magic value when using DIXsaveUnders
+ */
+
+#define USE_DIX_SAVE_UNDERS    0x40
+#endif
+
+extern int numSaveUndersViewable;
+extern int deltaSaveUndersViewable;
+
+#endif /* WINDOWSTRUCT_H */
diff --git a/Xserver/programs/Xserver/mfb/Imakefile b/Xserver/programs/Xserver/mfb/Imakefile
new file mode 100644 (file)
index 0000000..24da0a4
--- /dev/null
@@ -0,0 +1,93 @@
+XCOMM $XConsortium: Imakefile /main/42 1996/11/04 16:09:42 kaleb $
+XCOMM $XFree86: xc/programs/Xserver/mfb/Imakefile,v 3.2 1996/12/23 07:09:36 dawes Exp $
+#include <Server.tmpl>
+
+SRCS1 =         mfbgc.c mfbwindow.c mfbfont.c \
+        mfbfillrct.c mfbpntwin.c maskbits.c mfbpixmap.c \
+        mfbimage.c mfbline.c mfbbres.c mfbhrzvert.c mfbbresd.c \
+        mfbpushpxl.c mfbzerarc.c mfbfillarc.c \
+         mfbfillsp.c mfbsetsp.c mfbscrinit.c mfbscrclse.c mfbclip.c \
+         mfbbitblt.c mfbgetsp.c mfbpolypnt.c \
+        mfbbltC.c mfbbltX.c mfbbltCI.c mfbbltO.c mfbbltG.c \
+        mfbcmap.c mfbtileC.c mfbtileG.c mfbmisc.c mfbbstore.c
+
+SRCS =  $(SRCS1) mfbseg.c mfbpgbwht.c mfbpgbblak.c mfbpgbinv.c mfbigbwht.c \
+        mfbigbblak.c mfbpawhite.c mfbpablack.c mfbpainv.c mfbtewhite.c \
+        mfbteblack.c mfbbltC.c mfbbltX.c mfbbltCI.c mfbbltO.c mfbbltG.c \
+        mfbtileC.c mfbtileG.c mfbplywhite.c mfbplyblack.c mfbplyinv.c
+
+OBJS =   mfbgc.o mfbwindow.o mfbfont.o \
+        mfbfillrct.o mfbpntwin.o maskbits.o mfbpixmap.o \
+        mfbimage.o mfbline.o mfbbres.o mfbhrzvert.o mfbbresd.o mfbseg.o \
+        mfbpushpxl.o mfbzerarc.o mfbfillarc.o \
+        mfbfillsp.o mfbsetsp.o mfbscrinit.o mfbscrclse.o mfbclip.o \
+         mfbbitblt.o mfbgetsp.o mfbpolypnt.o \
+        mfbbltC.o mfbbltX.o mfbbltCI.o mfbbltO.o mfbbltG.o \
+        mfbpgbwht.o mfbpgbblak.o mfbpgbinv.o \
+        mfbigbwht.o mfbigbblak.o mfbcmap.o \
+        mfbpawhite.o mfbpablack.o mfbpainv.o mfbtileC.o mfbtileG.o \
+         mfbtewhite.o mfbteblack.o mfbmisc.o mfbbstore.o \
+         mfbplywhite.o mfbplyblack.o mfbplyinv.o
+
+INCLUDES = -I. -I../mi -I../include -I$(XINCLUDESRC) -I$(FONTINCSRC)
+LINTDEFS = -DMFBPOLYGLYPHBLT=mfbPolyGlyphBltWhite \
+          -DMFBIMAGEGLYPHBLT=mfbImageGlyphBltWhite \
+          -DEQWHOLEWORD=MFB_EQWHOLEWORD_WHITE -DOPEQ=MFB_OPEQ_WHITE
+
+LINTLIBS = ../dix/llib-ldix.ln ../os/llib-los.ln ../mi/llib-lmi.ln
+
+NormalLibraryObjectRule()
+NormalLibraryTarget(mfb,$(OBJS))
+LintLibraryTarget(mfb,$(SRCS1))
+NormalLintTarget($(LINTDEFS) $(SRCS1))
+
+ObjectFromSpecialSource(mfbseg,mfbline,-DPOLYSEGMENT)
+
+ObjectFromSpecialSource(mfbpgbwht,mfbplygblt,-DMFBPOLYGLYPHBLT=mfbPolyGlyphBltWhite -DOPEQ=MFB_OPEQ_WHITE)
+
+ObjectFromSpecialSource(mfbpgbblak,mfbplygblt,-DMFBPOLYGLYPHBLT=mfbPolyGlyphBltBlack -DOPEQ=MFB_OPEQ_BLACK)
+
+ObjectFromSpecialSource(mfbpgbinv,mfbplygblt,-DMFBPOLYGLYPHBLT=mfbPolyGlyphBltInvert -DOPEQ=MFB_OPEQ_INVERT)
+
+ObjectFromSpecialSource(mfbigbwht,mfbimggblt,-DMFBIMAGEGLYPHBLT=mfbImageGlyphBltWhite -DOPEQ=MFB_OPEQ_WHITE)
+
+ObjectFromSpecialSource(mfbigbblak,mfbimggblt,-DMFBIMAGEGLYPHBLT=mfbImageGlyphBltBlack -DOPEQ=MFB_OPEQ_BLACK)
+
+ObjectFromSpecialSource(mfbpawhite,mfbpntarea,-DMFBSOLIDFILLAREA=mfbSolidWhiteArea -DMFBSTIPPLEFILLAREA=mfbStippleWhiteArea -DOPEQ=MFB_OPEQ_WHITE -DEQWHOLEWORD=MFB_EQWHOLEWORD_WHITE)
+
+ObjectFromSpecialSource(mfbpablack,mfbpntarea,-DMFBSOLIDFILLAREA=mfbSolidBlackArea -DMFBSTIPPLEFILLAREA=mfbStippleBlackArea -DOPEQ=MFB_OPEQ_BLACK -DEQWHOLEWORD=MFB_EQWHOLEWORD_BLACK)
+
+ObjectFromSpecialSource(mfbpainv,mfbpntarea,-DMFBSOLIDFILLAREA=mfbSolidInvertArea -DMFBSTIPPLEFILLAREA=mfbStippleInvertArea -DOPEQ=MFB_OPEQ_INVERT -DEQWHOLEWORD=MFB_EQWHOLEWORD_INVERT)
+
+ObjectFromSpecialSource(mfbtewhite,mfbtegblt,-DMFBTEGLYPHBLT=mfbTEGlyphBltWhite -DOP=MFB_OP_WHITE -DCLIPTETEXT=mfbImageGlyphBltWhite)
+
+ObjectFromSpecialSource(mfbteblack,mfbtegblt,-DMFBTEGLYPHBLT=mfbTEGlyphBltBlack -DOP=MFB_OP_BLACK -DCLIPTETEXT=mfbImageGlyphBltBlack)
+
+ObjectFromSpecialSource(mfbplywhite,mfbply1rct,-DMFBFILLPOLY1RECT=mfbFillPolyWhite -DOPEQ=MFB_OPEQ_WHITE -DEQWHOLEWORD=MFB_EQWHOLEWORD_WHITE)
+
+ObjectFromSpecialSource(mfbplyblack,mfbply1rct,-DMFBFILLPOLY1RECT=mfbFillPolyBlack -DOPEQ=MFB_OPEQ_BLACK -DEQWHOLEWORD=MFB_EQWHOLEWORD_BLACK)
+
+ObjectFromSpecialSource(mfbplyinv,mfbply1rct,-DMFBFILLPOLY1RECT=mfbFillPolyInvert -DOPEQ=MFB_OPEQ_INVERT -DEQWHOLEWORD=MFB_EQWHOLEWORD_INVERT)
+
+ObjectFromSpecialSource(mfbbltC,mfbblt,-DMROP=Mcopy)
+
+ObjectFromSpecialSource(mfbbltX,mfbblt,-DMROP=Mxor)
+
+ObjectFromSpecialSource(mfbbltCI,mfbblt,-DMROP=McopyInverted)
+
+ObjectFromSpecialSource(mfbbltO,mfbblt,-DMROP=Mor)
+
+ObjectFromSpecialSource(mfbbltG,mfbblt,-DMROP=0)
+
+ObjectFromSpecialSource(mfbtileC,mfbtile,-DMROP=Mcopy)
+
+ObjectFromSpecialSource(mfbtileG,mfbtile,-DMROP=0)
+
+SpecialCObjectRule(mfbpixmap,$(ICONFIGFILES),$(_NOOP_))
+
+InstallLinkKitLibrary(mfb,$(LINKKITDIR)/lib)
+InstallLinkKitNonExecFile(fastblt.h,$(LINKKITDIR)/include)
+InstallLinkKitNonExecFile(mfb.h,$(LINKKITDIR)/include)
+InstallLinkKitNonExecFile(mergerop.h,$(LINKKITDIR)/include)
+
+DependTarget()
diff --git a/Xserver/programs/Xserver/mfb/fastblt.h b/Xserver/programs/Xserver/mfb/fastblt.h
new file mode 100644 (file)
index 0000000..0ca295d
--- /dev/null
@@ -0,0 +1,120 @@
+/* $XConsortium: fastblt.h,v 1.7 94/04/17 20:28:07 dpw Exp $ */
+/*
+
+Copyright (c) 1989  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be included
+in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR
+OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall
+not be used in advertising or otherwise to promote the sale, use or
+other dealings in this Software without prior written authorization
+from the X Consortium.
+
+*/
+
+/*
+ * Fast bitblt macros for certain hardware.  If your machine has an addressing
+ * mode of small constant + register, you'll probably want this magic specific
+ * code.  It's 25% faster for the R2000.  I haven't studied the Sparc
+ * instruction set, but I suspect it also has this addressing mode.  Also,
+ * unrolling the loop by 32 is possibly excessive for mfb. The number of times
+ * the loop is actually looped through is pretty small.
+ */
+
+/*
+ * WARNING:  These macros make *a lot* of assumptions about
+ * the environment they are invoked in.  Plenty of implicit
+ * arguments, lots of side effects.  Don't use them casually.
+ */
+
+#define SwitchOdd(n) case n: BodyOdd(n)
+#define SwitchEven(n) case n: BodyEven(n)
+
+/* to allow mfb and cfb to share code... */
+#ifndef BitRight
+#define BitRight(a,b) SCRRIGHT(a,b)
+#define BitLeft(a,b) SCRLEFT(a,b)
+#endif
+
+#ifdef LARGE_INSTRUCTION_CACHE
+#define UNROLL 8
+#define PackedLoop \
+    switch (nl & (UNROLL-1)) { \
+    SwitchOdd( 7) SwitchEven( 6) SwitchOdd( 5) SwitchEven( 4) \
+    SwitchOdd( 3) SwitchEven( 2) SwitchOdd( 1) \
+    } \
+    while ((nl -= UNROLL) >= 0) { \
+       LoopReset \
+       BodyEven( 8) \
+       BodyOdd( 7) BodyEven( 6) BodyOdd( 5) BodyEven( 4) \
+       BodyOdd( 3) BodyEven( 2) BodyOdd( 1) \
+    }
+#else
+#define UNROLL 4
+#define PackedLoop \
+    switch (nl & (UNROLL-1)) { \
+    SwitchOdd( 3) SwitchEven( 2) SwitchOdd( 1) \
+    } \
+    while ((nl -= UNROLL) >= 0) { \
+       LoopReset \
+       BodyEven( 4) \
+       BodyOdd( 3) BodyEven( 2) BodyOdd( 1) \
+    }
+#endif
+
+#if PPW == 32
+#define DuffL(counter,label,body) \
+    switch (counter & 3) { \
+    label: \
+        body \
+    case 3: \
+       body \
+    case 2: \
+       body \
+    case 1: \
+       body \
+    case 0: \
+       if ((counter -= 4) >= 0) \
+           goto label; \
+    }
+#else /* PPW == 64 */
+#define DuffL(counter,label,body) \
+    switch (counter & 7) { \
+    label: \
+        body \
+    case 7: \
+       body \
+    case 6: \
+       body \
+    case 5: \
+       body \
+    case 4: \
+       body \
+    case 3: \
+       body \
+    case 2: \
+       body \
+    case 1: \
+       body \
+    case 0: \
+       if ((counter -= 8) >= 0) \
+           goto label; \
+    }
+#endif /* PPW */
diff --git a/Xserver/programs/Xserver/mfb/maskbits.c b/Xserver/programs/Xserver/mfb/maskbits.c
new file mode 100644 (file)
index 0000000..9d0a2b9
--- /dev/null
@@ -0,0 +1,9865 @@
+/* $XConsortium: maskbits.c,v 1.16 95/04/07 18:59:14 kaleb Exp $ */
+/* Combined Purdue/PurduePlus patches, level 2.0, 1/17/89 */
+/*
+
+Copyright (c) 1987  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be included
+in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR
+OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall
+not be used in advertising or otherwise to promote the sale, use or
+other dealings in this Software without prior written authorization
+from the X Consortium.
+
+
+Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts,
+
+       All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and its 
+documentation for any purpose and without fee is hereby granted, 
+provided that the above copyright notice appear in all copies and that
+both that copyright notice and this permission notice appear in 
+supporting documentation, and that the name of Digital not be
+used in advertising or publicity pertaining to distribution of the
+software without specific, written prior permission.  
+
+DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
+ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
+DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
+ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+SOFTWARE.
+
+*/
+
+#include "maskbits.h"
+#include "servermd.h"
+
+/*
+these tables are used by several macros in the mfb code.
+
+   the vax numbers everything left to right, so bit indices on the
+screen match bit indices in longwords.  the pc-rt and Sun number
+bits on the screen the way they would be written on paper,
+(i.e. msb to the left), and so a bit index n on the screen is
+bit index PPW-n in a longword
+
+   see also maskbits.h
+*/
+
+#if (BITMAP_BIT_ORDER == MSBFirst)
+/* NOTE:
+the first element in starttab could be 0xffffffff.  making it 0
+lets us deal with a full first word in the middle loop, rather
+than having to do the multiple reads and masks that we'd
+have to do if we thought it was partial.
+*/
+PixelType starttab[PPW+1] =
+    {
+       LONG2CHARS( 0x00000000 ),
+#if PPW == 64
+       LONG2CHARS( 0x7FFFFFFFFFFFFFFF ),
+       LONG2CHARS( 0x3FFFFFFFFFFFFFFF ),
+       LONG2CHARS( 0x1FFFFFFFFFFFFFFF ),
+       LONG2CHARS( 0x0FFFFFFFFFFFFFFF ),
+       LONG2CHARS( 0x07FFFFFFFFFFFFFF ),
+       LONG2CHARS( 0x03FFFFFFFFFFFFFF ),
+       LONG2CHARS( 0x01FFFFFFFFFFFFFF ),
+       LONG2CHARS( 0x00FFFFFFFFFFFFFF ),
+       LONG2CHARS( 0x007FFFFFFFFFFFFF ),
+       LONG2CHARS( 0x003FFFFFFFFFFFFF ),
+       LONG2CHARS( 0x001FFFFFFFFFFFFF ),
+       LONG2CHARS( 0x000FFFFFFFFFFFFF ),
+       LONG2CHARS( 0x0007FFFFFFFFFFFF ),
+       LONG2CHARS( 0x0003FFFFFFFFFFFF ),
+       LONG2CHARS( 0x0001FFFFFFFFFFFF ),
+       LONG2CHARS( 0x0000FFFFFFFFFFFF ),
+       LONG2CHARS( 0x00007FFFFFFFFFFF ),
+       LONG2CHARS( 0x00003FFFFFFFFFFF ),
+       LONG2CHARS( 0x00001FFFFFFFFFFF ),
+       LONG2CHARS( 0x00000FFFFFFFFFFF ),
+       LONG2CHARS( 0x000007FFFFFFFFFF ),
+       LONG2CHARS( 0x000003FFFFFFFFFF ),
+       LONG2CHARS( 0x000001FFFFFFFFFF ),
+       LONG2CHARS( 0x000000FFFFFFFFFF ),
+       LONG2CHARS( 0x0000007FFFFFFFFF ),
+       LONG2CHARS( 0x0000003FFFFFFFFF ),
+       LONG2CHARS( 0x0000001FFFFFFFFF ),
+       LONG2CHARS( 0x0000000FFFFFFFFF ),
+       LONG2CHARS( 0x00000007FFFFFFFF ),
+       LONG2CHARS( 0x00000003FFFFFFFF ),
+       LONG2CHARS( 0x00000001FFFFFFFF ),
+       LONG2CHARS( 0x00000000FFFFFFFF ),
+#endif /* PPW == 64 */
+       LONG2CHARS( 0x7FFFFFFF ),
+       LONG2CHARS( 0x3FFFFFFF ),
+       LONG2CHARS( 0x1FFFFFFF ),
+       LONG2CHARS( 0x0FFFFFFF ),
+       LONG2CHARS( 0x07FFFFFF ),
+       LONG2CHARS( 0x03FFFFFF ),
+       LONG2CHARS( 0x01FFFFFF ),
+       LONG2CHARS( 0x00FFFFFF ),
+       LONG2CHARS( 0x007FFFFF ),
+       LONG2CHARS( 0x003FFFFF ),
+       LONG2CHARS( 0x001FFFFF ),
+       LONG2CHARS( 0x000FFFFF ),
+       LONG2CHARS( 0x0007FFFF ),
+       LONG2CHARS( 0x0003FFFF ),
+       LONG2CHARS( 0x0001FFFF ),
+       LONG2CHARS( 0x0000FFFF ),
+       LONG2CHARS( 0x00007FFF ),
+       LONG2CHARS( 0x00003FFF ),
+       LONG2CHARS( 0x00001FFF ),
+       LONG2CHARS( 0x00000FFF ),
+       LONG2CHARS( 0x000007FF ),
+       LONG2CHARS( 0x000003FF ),
+       LONG2CHARS( 0x000001FF ),
+       LONG2CHARS( 0x000000FF ),
+       LONG2CHARS( 0x0000007F ),
+       LONG2CHARS( 0x0000003F ),
+       LONG2CHARS( 0x0000001F ),
+       LONG2CHARS( 0x0000000F ),
+       LONG2CHARS( 0x00000007 ),
+       LONG2CHARS( 0x00000003 ),
+       LONG2CHARS( 0x00000001 ),
+       LONG2CHARS( 0x00000000 )
+    };
+
+PixelType endtab[PPW+1] =
+    {
+#if PPW == 32
+       LONG2CHARS( 0x00000000 ),
+       LONG2CHARS( 0x80000000 ),
+       LONG2CHARS( 0xC0000000 ),
+       LONG2CHARS( 0xE0000000 ),
+       LONG2CHARS( 0xF0000000 ),
+       LONG2CHARS( 0xF8000000 ),
+       LONG2CHARS( 0xFC000000 ),
+       LONG2CHARS( 0xFE000000 ),
+       LONG2CHARS( 0xFF000000 ),
+       LONG2CHARS( 0xFF800000 ),
+       LONG2CHARS( 0xFFC00000 ),
+       LONG2CHARS( 0xFFE00000 ),
+       LONG2CHARS( 0xFFF00000 ),
+       LONG2CHARS( 0xFFF80000 ),
+       LONG2CHARS( 0xFFFC0000 ),
+       LONG2CHARS( 0xFFFE0000 ),
+       LONG2CHARS( 0xFFFF0000 ),
+       LONG2CHARS( 0xFFFF8000 ),
+       LONG2CHARS( 0xFFFFC000 ),
+       LONG2CHARS( 0xFFFFE000 ),
+       LONG2CHARS( 0xFFFFF000 ),
+       LONG2CHARS( 0xFFFFF800 ),
+       LONG2CHARS( 0xFFFFFC00 ),
+       LONG2CHARS( 0xFFFFFE00 ),
+       LONG2CHARS( 0xFFFFFF00 ),
+       LONG2CHARS( 0xFFFFFF80 ),
+       LONG2CHARS( 0xFFFFFFC0 ),
+       LONG2CHARS( 0xFFFFFFE0 ),
+       LONG2CHARS( 0xFFFFFFF0 ),
+       LONG2CHARS( 0xFFFFFFF8 ),
+       LONG2CHARS( 0xFFFFFFFC ),
+       LONG2CHARS( 0xFFFFFFFE ),
+       LONG2CHARS( 0xFFFFFFFF )
+#else /* PPW */
+       LONG2CHARS( 0x0000000000000000 ),
+       LONG2CHARS( 0x8000000000000000 ),
+       LONG2CHARS( 0xC000000000000000 ),
+       LONG2CHARS( 0xE000000000000000 ),
+       LONG2CHARS( 0xF000000000000000 ),
+       LONG2CHARS( 0xF800000000000000 ),
+       LONG2CHARS( 0xFC00000000000000 ),
+       LONG2CHARS( 0xFE00000000000000 ),
+       LONG2CHARS( 0xFF00000000000000 ),
+       LONG2CHARS( 0xFF80000000000000 ),
+       LONG2CHARS( 0xFFC0000000000000 ),
+       LONG2CHARS( 0xFFE0000000000000 ),
+       LONG2CHARS( 0xFFF0000000000000 ),
+       LONG2CHARS( 0xFFF8000000000000 ),
+       LONG2CHARS( 0xFFFC000000000000 ),
+       LONG2CHARS( 0xFFFE000000000000 ),
+       LONG2CHARS( 0xFFFF000000000000 ),
+       LONG2CHARS( 0xFFFF800000000000 ),
+       LONG2CHARS( 0xFFFFC00000000000 ),
+       LONG2CHARS( 0xFFFFE00000000000 ),
+       LONG2CHARS( 0xFFFFF00000000000 ),
+       LONG2CHARS( 0xFFFFF80000000000 ),
+       LONG2CHARS( 0xFFFFFC0000000000 ),
+       LONG2CHARS( 0xFFFFFE0000000000 ),
+       LONG2CHARS( 0xFFFFFF0000000000 ),
+       LONG2CHARS( 0xFFFFFF8000000000 ),
+       LONG2CHARS( 0xFFFFFFC000000000 ),
+       LONG2CHARS( 0xFFFFFFE000000000 ),
+       LONG2CHARS( 0xFFFFFFF000000000 ),
+       LONG2CHARS( 0xFFFFFFF800000000 ),
+       LONG2CHARS( 0xFFFFFFFC00000000 ),
+       LONG2CHARS( 0xFFFFFFFE00000000 ),
+       LONG2CHARS( 0xFFFFFFFF00000000 ),
+       LONG2CHARS( 0xFFFFFFFF80000000 ),
+       LONG2CHARS( 0xFFFFFFFFC0000000 ),
+       LONG2CHARS( 0xFFFFFFFFE0000000 ),
+       LONG2CHARS( 0xFFFFFFFFF0000000 ),
+       LONG2CHARS( 0xFFFFFFFFF8000000 ),
+       LONG2CHARS( 0xFFFFFFFFFC000000 ),
+       LONG2CHARS( 0xFFFFFFFFFE000000 ),
+       LONG2CHARS( 0xFFFFFFFFFF000000 ),
+       LONG2CHARS( 0xFFFFFFFFFF800000 ),
+       LONG2CHARS( 0xFFFFFFFFFFC00000 ),
+       LONG2CHARS( 0xFFFFFFFFFFE00000 ),
+       LONG2CHARS( 0xFFFFFFFFFFF00000 ),
+       LONG2CHARS( 0xFFFFFFFFFFF80000 ),
+       LONG2CHARS( 0xFFFFFFFFFFFC0000 ),
+       LONG2CHARS( 0xFFFFFFFFFFFE0000 ),
+       LONG2CHARS( 0xFFFFFFFFFFFF0000 ),
+       LONG2CHARS( 0xFFFFFFFFFFFF8000 ),
+       LONG2CHARS( 0xFFFFFFFFFFFFC000 ),
+       LONG2CHARS( 0xFFFFFFFFFFFFE000 ),
+       LONG2CHARS( 0xFFFFFFFFFFFFF000 ),
+       LONG2CHARS( 0xFFFFFFFFFFFFF800 ),
+       LONG2CHARS( 0xFFFFFFFFFFFFFC00 ),
+       LONG2CHARS( 0xFFFFFFFFFFFFFE00 ),
+       LONG2CHARS( 0xFFFFFFFFFFFFFF00 ),
+       LONG2CHARS( 0xFFFFFFFFFFFFFF80 ),
+       LONG2CHARS( 0xFFFFFFFFFFFFFFC0 ),
+       LONG2CHARS( 0xFFFFFFFFFFFFFFE0 ),
+       LONG2CHARS( 0xFFFFFFFFFFFFFFF0 ),
+       LONG2CHARS( 0xFFFFFFFFFFFFFFF8 ),
+       LONG2CHARS( 0xFFFFFFFFFFFFFFFC ),
+       LONG2CHARS( 0xFFFFFFFFFFFFFFFE ),
+       LONG2CHARS( 0xFFFFFFFFFFFFFFFF )
+#endif /* PPW */
+    };
+
+#if NEED_OLD_MFB_MASKS
+/* a hack, for now, since the entries for 0 need to be all
+   1 bits, not all zeros.
+   this means the code DOES NOT WORK for segments of length
+   0 (which is only a problem in the horizontal line code.)
+*/
+PixelType startpartial[33] =
+    {
+       LONG2CHARS( 0xFFFFFFFF ),
+       LONG2CHARS( 0x7FFFFFFF ),
+       LONG2CHARS( 0x3FFFFFFF ),
+       LONG2CHARS( 0x1FFFFFFF ),
+       LONG2CHARS( 0x0FFFFFFF ),
+       LONG2CHARS( 0x07FFFFFF ),
+       LONG2CHARS( 0x03FFFFFF ),
+       LONG2CHARS( 0x01FFFFFF ),
+       LONG2CHARS( 0x00FFFFFF ),
+       LONG2CHARS( 0x007FFFFF ),
+       LONG2CHARS( 0x003FFFFF ),
+       LONG2CHARS( 0x001FFFFF ),
+       LONG2CHARS( 0x000FFFFF ),
+       LONG2CHARS( 0x0007FFFF ),
+       LONG2CHARS( 0x0003FFFF ),
+       LONG2CHARS( 0x0001FFFF ),
+       LONG2CHARS( 0x0000FFFF ),
+       LONG2CHARS( 0x00007FFF ),
+       LONG2CHARS( 0x00003FFF ),
+       LONG2CHARS( 0x00001FFF ),
+       LONG2CHARS( 0x00000FFF ),
+       LONG2CHARS( 0x000007FF ),
+       LONG2CHARS( 0x000003FF ),
+       LONG2CHARS( 0x000001FF ),
+       LONG2CHARS( 0x000000FF ),
+       LONG2CHARS( 0x0000007F ),
+       LONG2CHARS( 0x0000003F ),
+       LONG2CHARS( 0x0000001F ),
+       LONG2CHARS( 0x0000000F ),
+       LONG2CHARS( 0x00000007 ),
+       LONG2CHARS( 0x00000003 ),
+       LONG2CHARS( 0x00000001 ),
+       LONG2CHARS( 0x00000000 )
+    };
+
+PixelType endpartial[33] =
+    {
+       LONG2CHARS( 0xFFFFFFFF ),
+       LONG2CHARS( 0x80000000 ),
+       LONG2CHARS( 0xC0000000 ),
+       LONG2CHARS( 0xE0000000 ),
+       LONG2CHARS( 0xF0000000 ),
+       LONG2CHARS( 0xF8000000 ),
+       LONG2CHARS( 0xFC000000 ),
+       LONG2CHARS( 0xFE000000 ),
+       LONG2CHARS( 0xFF000000 ),
+       LONG2CHARS( 0xFF800000 ),
+       LONG2CHARS( 0xFFC00000 ),
+       LONG2CHARS( 0xFFE00000 ),
+       LONG2CHARS( 0xFFF00000 ),
+       LONG2CHARS( 0xFFF80000 ),
+       LONG2CHARS( 0xFFFC0000 ),
+       LONG2CHARS( 0xFFFE0000 ),
+       LONG2CHARS( 0xFFFF0000 ),
+       LONG2CHARS( 0xFFFF8000 ),
+       LONG2CHARS( 0xFFFFC000 ),
+       LONG2CHARS( 0xFFFFE000 ),
+       LONG2CHARS( 0xFFFFF000 ),
+       LONG2CHARS( 0xFFFFF800 ),
+       LONG2CHARS( 0xFFFFFC00 ),
+       LONG2CHARS( 0xFFFFFE00 ),
+       LONG2CHARS( 0xFFFFFF00 ),
+       LONG2CHARS( 0xFFFFFF80 ),
+       LONG2CHARS( 0xFFFFFFC0 ),
+       LONG2CHARS( 0xFFFFFFE0 ),
+       LONG2CHARS( 0xFFFFFFF0 ),
+       LONG2CHARS( 0xFFFFFFF8 ),
+       LONG2CHARS( 0xFFFFFFFC ),
+       LONG2CHARS( 0xFFFFFFFE ),
+       LONG2CHARS( 0xFFFFFFFF )
+    };
+#endif /* NEED_OLD_MFB_MASKS */
+
+#if PPW == 32
+PixelType partmasks[PPW][PPW] = {
+     {LONG2CHARS( 0xFFFFFFFF ), LONG2CHARS( 0x80000000 ), LONG2CHARS( 0xC0000000 ), LONG2CHARS( 0xE0000000 ),
+      LONG2CHARS( 0xF0000000 ), LONG2CHARS( 0xF8000000 ), LONG2CHARS( 0xFC000000 ), LONG2CHARS( 0xFE000000 ),
+      LONG2CHARS( 0xFF000000 ), LONG2CHARS( 0xFF800000 ), LONG2CHARS( 0xFFC00000 ), LONG2CHARS( 0xFFE00000 ),
+      LONG2CHARS( 0xFFF00000 ), LONG2CHARS( 0xFFF80000 ), LONG2CHARS( 0xFFFC0000 ), LONG2CHARS( 0xFFFE0000 ),
+      LONG2CHARS( 0xFFFF0000 ), LONG2CHARS( 0xFFFF8000 ), LONG2CHARS( 0xFFFFC000 ), LONG2CHARS( 0xFFFFE000 ),
+      LONG2CHARS( 0xFFFFF000 ), LONG2CHARS( 0xFFFFF800 ), LONG2CHARS( 0xFFFFFC00 ), LONG2CHARS( 0xFFFFFE00 ),
+      LONG2CHARS( 0xFFFFFF00 ), LONG2CHARS( 0xFFFFFF80 ), LONG2CHARS( 0xFFFFFFC0 ), LONG2CHARS( 0xFFFFFFE0 ),
+      LONG2CHARS( 0xFFFFFFF0 ), LONG2CHARS( 0xFFFFFFF8 ), LONG2CHARS( 0xFFFFFFFC ), LONG2CHARS( 0xFFFFFFFE )},
+     {LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x40000000 ), LONG2CHARS( 0x60000000 ), LONG2CHARS( 0x70000000 ),
+      LONG2CHARS( 0x78000000 ), LONG2CHARS( 0x7C000000 ), LONG2CHARS( 0x7E000000 ), LONG2CHARS( 0x7F000000 ),
+      LONG2CHARS( 0x7F800000 ), LONG2CHARS( 0x7FC00000 ), LONG2CHARS( 0x7FE00000 ), LONG2CHARS( 0x7FF00000 ),
+      LONG2CHARS( 0x7FF80000 ), LONG2CHARS( 0x7FFC0000 ), LONG2CHARS( 0x7FFE0000 ), LONG2CHARS( 0x7FFF0000 ),
+      LONG2CHARS( 0x7FFF8000 ), LONG2CHARS( 0x7FFFC000 ), LONG2CHARS( 0x7FFFE000 ), LONG2CHARS( 0x7FFFF000 ),
+      LONG2CHARS( 0x7FFFF800 ), LONG2CHARS( 0x7FFFFC00 ), LONG2CHARS( 0x7FFFFE00 ), LONG2CHARS( 0x7FFFFF00 ),
+      LONG2CHARS( 0x7FFFFF80 ), LONG2CHARS( 0x7FFFFFC0 ), LONG2CHARS( 0x7FFFFFE0 ), LONG2CHARS( 0x7FFFFFF0 ),
+      LONG2CHARS( 0x7FFFFFF8 ), LONG2CHARS( 0x7FFFFFFC ), LONG2CHARS( 0x7FFFFFFE ), LONG2CHARS( 0x7FFFFFFF )},
+     {LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x20000000 ), LONG2CHARS( 0x30000000 ), LONG2CHARS( 0x38000000 ),
+      LONG2CHARS( 0x3C000000 ), LONG2CHARS( 0x3E000000 ), LONG2CHARS( 0x3F000000 ), LONG2CHARS( 0x3F800000 ),
+      LONG2CHARS( 0x3FC00000 ), LONG2CHARS( 0x3FE00000 ), LONG2CHARS( 0x3FF00000 ), LONG2CHARS( 0x3FF80000 ),
+      LONG2CHARS( 0x3FFC0000 ), LONG2CHARS( 0x3FFE0000 ), LONG2CHARS( 0x3FFF0000 ), LONG2CHARS( 0x3FFF8000 ),
+      LONG2CHARS( 0x3FFFC000 ), LONG2CHARS( 0x3FFFE000 ), LONG2CHARS( 0x3FFFF000 ), LONG2CHARS( 0x3FFFF800 ),
+      LONG2CHARS( 0x3FFFFC00 ), LONG2CHARS( 0x3FFFFE00 ), LONG2CHARS( 0x3FFFFF00 ), LONG2CHARS( 0x3FFFFF80 ),
+      LONG2CHARS( 0x3FFFFFC0 ), LONG2CHARS( 0x3FFFFFE0 ), LONG2CHARS( 0x3FFFFFF0 ), LONG2CHARS( 0x3FFFFFF8 ),
+      LONG2CHARS( 0x3FFFFFFC ), LONG2CHARS( 0x3FFFFFFE ), LONG2CHARS( 0x3FFFFFFF ), LONG2CHARS( 0x00000000 )},
+     {LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x10000000 ), LONG2CHARS( 0x18000000 ), LONG2CHARS( 0x1C000000 ),
+      LONG2CHARS( 0x1E000000 ), LONG2CHARS( 0x1F000000 ), LONG2CHARS( 0x1F800000 ), LONG2CHARS( 0x1FC00000 ),
+      LONG2CHARS( 0x1FE00000 ), LONG2CHARS( 0x1FF00000 ), LONG2CHARS( 0x1FF80000 ), LONG2CHARS( 0x1FFC0000 ),
+      LONG2CHARS( 0x1FFE0000 ), LONG2CHARS( 0x1FFF0000 ), LONG2CHARS( 0x1FFF8000 ), LONG2CHARS( 0x1FFFC000 ),
+      LONG2CHARS( 0x1FFFE000 ), LONG2CHARS( 0x1FFFF000 ), LONG2CHARS( 0x1FFFF800 ), LONG2CHARS( 0x1FFFFC00 ),
+      LONG2CHARS( 0x1FFFFE00 ), LONG2CHARS( 0x1FFFFF00 ), LONG2CHARS( 0x1FFFFF80 ), LONG2CHARS( 0x1FFFFFC0 ),
+      LONG2CHARS( 0x1FFFFFE0 ), LONG2CHARS( 0x1FFFFFF0 ), LONG2CHARS( 0x1FFFFFF8 ), LONG2CHARS( 0x1FFFFFFC ),
+      LONG2CHARS( 0x1FFFFFFE ), LONG2CHARS( 0x1FFFFFFF ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 )},
+     {LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x08000000 ), LONG2CHARS( 0x0C000000 ), LONG2CHARS( 0x0E000000 ),
+      LONG2CHARS( 0x0F000000 ), LONG2CHARS( 0x0F800000 ), LONG2CHARS( 0x0FC00000 ), LONG2CHARS( 0x0FE00000 ),
+      LONG2CHARS( 0x0FF00000 ), LONG2CHARS( 0x0FF80000 ), LONG2CHARS( 0x0FFC0000 ), LONG2CHARS( 0x0FFE0000 ),
+      LONG2CHARS( 0x0FFF0000 ), LONG2CHARS( 0x0FFF8000 ), LONG2CHARS( 0x0FFFC000 ), LONG2CHARS( 0x0FFFE000 ),
+      LONG2CHARS( 0x0FFFF000 ), LONG2CHARS( 0x0FFFF800 ), LONG2CHARS( 0x0FFFFC00 ), LONG2CHARS( 0x0FFFFE00 ),
+      LONG2CHARS( 0x0FFFFF00 ), LONG2CHARS( 0x0FFFFF80 ), LONG2CHARS( 0x0FFFFFC0 ), LONG2CHARS( 0x0FFFFFE0 ),
+      LONG2CHARS( 0x0FFFFFF0 ), LONG2CHARS( 0x0FFFFFF8 ), LONG2CHARS( 0x0FFFFFFC ), LONG2CHARS( 0x0FFFFFFE ),
+      LONG2CHARS( 0x0FFFFFFF ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 )},
+     {LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x04000000 ), LONG2CHARS( 0x06000000 ), LONG2CHARS( 0x07000000 ),
+      LONG2CHARS( 0x07800000 ), LONG2CHARS( 0x07C00000 ), LONG2CHARS( 0x07E00000 ), LONG2CHARS( 0x07F00000 ),
+      LONG2CHARS( 0x07F80000 ), LONG2CHARS( 0x07FC0000 ), LONG2CHARS( 0x07FE0000 ), LONG2CHARS( 0x07FF0000 ),
+      LONG2CHARS( 0x07FF8000 ), LONG2CHARS( 0x07FFC000 ), LONG2CHARS( 0x07FFE000 ), LONG2CHARS( 0x07FFF000 ),
+      LONG2CHARS( 0x07FFF800 ), LONG2CHARS( 0x07FFFC00 ), LONG2CHARS( 0x07FFFE00 ), LONG2CHARS( 0x07FFFF00 ),
+      LONG2CHARS( 0x07FFFF80 ), LONG2CHARS( 0x07FFFFC0 ), LONG2CHARS( 0x07FFFFE0 ), LONG2CHARS( 0x07FFFFF0 ),
+      LONG2CHARS( 0x07FFFFF8 ), LONG2CHARS( 0x07FFFFFC ), LONG2CHARS( 0x07FFFFFE ), LONG2CHARS( 0x07FFFFFF ),
+      LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 )},
+     {LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x02000000 ), LONG2CHARS( 0x03000000 ), LONG2CHARS( 0x03800000 ),
+      LONG2CHARS( 0x03C00000 ), LONG2CHARS( 0x03E00000 ), LONG2CHARS( 0x03F00000 ), LONG2CHARS( 0x03F80000 ),
+      LONG2CHARS( 0x03FC0000 ), LONG2CHARS( 0x03FE0000 ), LONG2CHARS( 0x03FF0000 ), LONG2CHARS( 0x03FF8000 ),
+      LONG2CHARS( 0x03FFC000 ), LONG2CHARS( 0x03FFE000 ), LONG2CHARS( 0x03FFF000 ), LONG2CHARS( 0x03FFF800 ),
+      LONG2CHARS( 0x03FFFC00 ), LONG2CHARS( 0x03FFFE00 ), LONG2CHARS( 0x03FFFF00 ), LONG2CHARS( 0x03FFFF80 ),
+      LONG2CHARS( 0x03FFFFC0 ), LONG2CHARS( 0x03FFFFE0 ), LONG2CHARS( 0x03FFFFF0 ), LONG2CHARS( 0x03FFFFF8 ),
+      LONG2CHARS( 0x03FFFFFC ), LONG2CHARS( 0x03FFFFFE ), LONG2CHARS( 0x03FFFFFF ), LONG2CHARS( 0x00000000 ),
+      LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 )},
+     {LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x01000000 ), LONG2CHARS( 0x01800000 ), LONG2CHARS( 0x01C00000 ),
+      LONG2CHARS( 0x01E00000 ), LONG2CHARS( 0x01F00000 ), LONG2CHARS( 0x01F80000 ), LONG2CHARS( 0x01FC0000 ),
+      LONG2CHARS( 0x01FE0000 ), LONG2CHARS( 0x01FF0000 ), LONG2CHARS( 0x01FF8000 ), LONG2CHARS( 0x01FFC000 ),
+      LONG2CHARS( 0x01FFE000 ), LONG2CHARS( 0x01FFF000 ), LONG2CHARS( 0x01FFF800 ), LONG2CHARS( 0x01FFFC00 ),
+      LONG2CHARS( 0x01FFFE00 ), LONG2CHARS( 0x01FFFF00 ), LONG2CHARS( 0x01FFFF80 ), LONG2CHARS( 0x01FFFFC0 ),
+      LONG2CHARS( 0x01FFFFE0 ), LONG2CHARS( 0x01FFFFF0 ), LONG2CHARS( 0x01FFFFF8 ), LONG2CHARS( 0x01FFFFFC ),
+      LONG2CHARS( 0x01FFFFFE ), LONG2CHARS( 0x01FFFFFF ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ),
+      LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 )},
+     {LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00800000 ), LONG2CHARS( 0x00C00000 ), LONG2CHARS( 0x00E00000 ),
+      LONG2CHARS( 0x00F00000 ), LONG2CHARS( 0x00F80000 ), LONG2CHARS( 0x00FC0000 ), LONG2CHARS( 0x00FE0000 ),
+      LONG2CHARS( 0x00FF0000 ), LONG2CHARS( 0x00FF8000 ), LONG2CHARS( 0x00FFC000 ), LONG2CHARS( 0x00FFE000 ),
+      LONG2CHARS( 0x00FFF000 ), LONG2CHARS( 0x00FFF800 ), LONG2CHARS( 0x00FFFC00 ), LONG2CHARS( 0x00FFFE00 ),
+      LONG2CHARS( 0x00FFFF00 ), LONG2CHARS( 0x00FFFF80 ), LONG2CHARS( 0x00FFFFC0 ), LONG2CHARS( 0x00FFFFE0 ),
+      LONG2CHARS( 0x00FFFFF0 ), LONG2CHARS( 0x00FFFFF8 ), LONG2CHARS( 0x00FFFFFC ), LONG2CHARS( 0x00FFFFFE ),
+      LONG2CHARS( 0x00FFFFFF ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ),
+      LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 )},
+     {LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00400000 ), LONG2CHARS( 0x00600000 ), LONG2CHARS( 0x00700000 ),
+      LONG2CHARS( 0x00780000 ), LONG2CHARS( 0x007C0000 ), LONG2CHARS( 0x007E0000 ), LONG2CHARS( 0x007F0000 ),
+      LONG2CHARS( 0x007F8000 ), LONG2CHARS( 0x007FC000 ), LONG2CHARS( 0x007FE000 ), LONG2CHARS( 0x007FF000 ),
+      LONG2CHARS( 0x007FF800 ), LONG2CHARS( 0x007FFC00 ), LONG2CHARS( 0x007FFE00 ), LONG2CHARS( 0x007FFF00 ),
+      LONG2CHARS( 0x007FFF80 ), LONG2CHARS( 0x007FFFC0 ), LONG2CHARS( 0x007FFFE0 ), LONG2CHARS( 0x007FFFF0 ),
+      LONG2CHARS( 0x007FFFF8 ), LONG2CHARS( 0x007FFFFC ), LONG2CHARS( 0x007FFFFE ), LONG2CHARS( 0x007FFFFF ),
+      LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ),
+      LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 )},
+     {LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00200000 ), LONG2CHARS( 0x00300000 ), LONG2CHARS( 0x00380000 ),
+      LONG2CHARS( 0x003C0000 ), LONG2CHARS( 0x003E0000 ), LONG2CHARS( 0x003F0000 ), LONG2CHARS( 0x003F8000 ),
+      LONG2CHARS( 0x003FC000 ), LONG2CHARS( 0x003FE000 ), LONG2CHARS( 0x003FF000 ), LONG2CHARS( 0x003FF800 ),
+      LONG2CHARS( 0x003FFC00 ), LONG2CHARS( 0x003FFE00 ), LONG2CHARS( 0x003FFF00 ), LONG2CHARS( 0x003FFF80 ),
+      LONG2CHARS( 0x003FFFC0 ), LONG2CHARS( 0x003FFFE0 ), LONG2CHARS( 0x003FFFF0 ), LONG2CHARS( 0x003FFFF8 ),
+      LONG2CHARS( 0x003FFFFC ), LONG2CHARS( 0x003FFFFE ), LONG2CHARS( 0x003FFFFF ), LONG2CHARS( 0x00000000 ),
+      LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ),
+      LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 )},
+     {LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00100000 ), LONG2CHARS( 0x00180000 ), LONG2CHARS( 0x001C0000 ),
+      LONG2CHARS( 0x001E0000 ), LONG2CHARS( 0x001F0000 ), LONG2CHARS( 0x001F8000 ), LONG2CHARS( 0x001FC000 ),
+      LONG2CHARS( 0x001FE000 ), LONG2CHARS( 0x001FF000 ), LONG2CHARS( 0x001FF800 ), LONG2CHARS( 0x001FFC00 ),
+      LONG2CHARS( 0x001FFE00 ), LONG2CHARS( 0x001FFF00 ), LONG2CHARS( 0x001FFF80 ), LONG2CHARS( 0x001FFFC0 ),
+      LONG2CHARS( 0x001FFFE0 ), LONG2CHARS( 0x001FFFF0 ), LONG2CHARS( 0x001FFFF8 ), LONG2CHARS( 0x001FFFFC ),
+      LONG2CHARS( 0x001FFFFE ), LONG2CHARS( 0x001FFFFF ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ),
+      LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ),
+      LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 )},
+     {LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00080000 ), LONG2CHARS( 0x000C0000 ), LONG2CHARS( 0x000E0000 ),
+      LONG2CHARS( 0x000F0000 ), LONG2CHARS( 0x000F8000 ), LONG2CHARS( 0x000FC000 ), LONG2CHARS( 0x000FE000 ),
+      LONG2CHARS( 0x000FF000 ), LONG2CHARS( 0x000FF800 ), LONG2CHARS( 0x000FFC00 ), LONG2CHARS( 0x000FFE00 ),
+      LONG2CHARS( 0x000FFF00 ), LONG2CHARS( 0x000FFF80 ), LONG2CHARS( 0x000FFFC0 ), LONG2CHARS( 0x000FFFE0 ),
+      LONG2CHARS( 0x000FFFF0 ), LONG2CHARS( 0x000FFFF8 ), LONG2CHARS( 0x000FFFFC ), LONG2CHARS( 0x000FFFFE ),
+      LONG2CHARS( 0x000FFFFF ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ),
+      LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ),
+      LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 )},
+     {LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00040000 ), LONG2CHARS( 0x00060000 ), LONG2CHARS( 0x00070000 ),
+      LONG2CHARS( 0x00078000 ), LONG2CHARS( 0x0007C000 ), LONG2CHARS( 0x0007E000 ), LONG2CHARS( 0x0007F000 ),
+      LONG2CHARS( 0x0007F800 ), LONG2CHARS( 0x0007FC00 ), LONG2CHARS( 0x0007FE00 ), LONG2CHARS( 0x0007FF00 ),
+      LONG2CHARS( 0x0007FF80 ), LONG2CHARS( 0x0007FFC0 ), LONG2CHARS( 0x0007FFE0 ), LONG2CHARS( 0x0007FFF0 ),
+      LONG2CHARS( 0x0007FFF8 ), LONG2CHARS( 0x0007FFFC ), LONG2CHARS( 0x0007FFFE ), LONG2CHARS( 0x0007FFFF ),
+      LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ),
+      LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ),
+      LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 )},
+     {LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00020000 ), LONG2CHARS( 0x00030000 ), LONG2CHARS( 0x00038000 ),
+      LONG2CHARS( 0x0003C000 ), LONG2CHARS( 0x0003E000 ), LONG2CHARS( 0x0003F000 ), LONG2CHARS( 0x0003F800 ),
+      LONG2CHARS( 0x0003FC00 ), LONG2CHARS( 0x0003FE00 ), LONG2CHARS( 0x0003FF00 ), LONG2CHARS( 0x0003FF80 ),
+      LONG2CHARS( 0x0003FFC0 ), LONG2CHARS( 0x0003FFE0 ), LONG2CHARS( 0x0003FFF0 ), LONG2CHARS( 0x0003FFF8 ),
+      LONG2CHARS( 0x0003FFFC ), LONG2CHARS( 0x0003FFFE ), LONG2CHARS( 0x0003FFFF ), LONG2CHARS( 0x00000000 ),
+      LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ),
+      LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ),
+      LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 )},
+     {LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00010000 ), LONG2CHARS( 0x00018000 ), LONG2CHARS( 0x0001C000 ),
+      LONG2CHARS( 0x0001E000 ), LONG2CHARS( 0x0001F000 ), LONG2CHARS( 0x0001F800 ), LONG2CHARS( 0x0001FC00 ),
+      LONG2CHARS( 0x0001FE00 ), LONG2CHARS( 0x0001FF00 ), LONG2CHARS( 0x0001FF80 ), LONG2CHARS( 0x0001FFC0 ),
+      LONG2CHARS( 0x0001FFE0 ), LONG2CHARS( 0x0001FFF0 ), LONG2CHARS( 0x0001FFF8 ), LONG2CHARS( 0x0001FFFC ),
+      LONG2CHARS( 0x0001FFFE ), LONG2CHARS( 0x0001FFFF ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ),
+      LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ),
+      LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ),
+      LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 )},
+     {LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00008000 ), LONG2CHARS( 0x0000C000 ), LONG2CHARS( 0x0000E000 ),
+      LONG2CHARS( 0x0000F000 ), LONG2CHARS( 0x0000F800 ), LONG2CHARS( 0x0000FC00 ), LONG2CHARS( 0x0000FE00 ),
+      LONG2CHARS( 0x0000FF00 ), LONG2CHARS( 0x0000FF80 ), LONG2CHARS( 0x0000FFC0 ), LONG2CHARS( 0x0000FFE0 ),
+      LONG2CHARS( 0x0000FFF0 ), LONG2CHARS( 0x0000FFF8 ), LONG2CHARS( 0x0000FFFC ), LONG2CHARS( 0x0000FFFE ),
+      LONG2CHARS( 0x0000FFFF ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ),
+      LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ),
+      LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ),
+      LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 )},
+     {LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00004000 ), LONG2CHARS( 0x00006000 ), LONG2CHARS( 0x00007000 ),
+      LONG2CHARS( 0x00007800 ), LONG2CHARS( 0x00007C00 ), LONG2CHARS( 0x00007E00 ), LONG2CHARS( 0x00007F00 ),
+      LONG2CHARS( 0x00007F80 ), LONG2CHARS( 0x00007FC0 ), LONG2CHARS( 0x00007FE0 ), LONG2CHARS( 0x00007FF0 ),
+      LONG2CHARS( 0x00007FF8 ), LONG2CHARS( 0x00007FFC ), LONG2CHARS( 0x00007FFE ), LONG2CHARS( 0x00007FFF ),
+      LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ),
+      LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ),
+      LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ),
+      LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 )},
+     {LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00002000 ), LONG2CHARS( 0x00003000 ), LONG2CHARS( 0x00003800 ),
+      LONG2CHARS( 0x00003C00 ), LONG2CHARS( 0x00003E00 ), LONG2CHARS( 0x00003F00 ), LONG2CHARS( 0x00003F80 ),
+      LONG2CHARS( 0x00003FC0 ), LONG2CHARS( 0x00003FE0 ), LONG2CHARS( 0x00003FF0 ), LONG2CHARS( 0x00003FF8 ),
+      LONG2CHARS( 0x00003FFC ), LONG2CHARS( 0x00003FFE ), LONG2CHARS( 0x00003FFF ), LONG2CHARS( 0x00000000 ),
+      LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ),
+      LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ),
+      LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ),
+      LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 )},
+     {LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00001000 ), LONG2CHARS( 0x00001800 ), LONG2CHARS( 0x00001C00 ),
+      LONG2CHARS( 0x00001E00 ), LONG2CHARS( 0x00001F00 ), LONG2CHARS( 0x00001F80 ), LONG2CHARS( 0x00001FC0 ),
+      LONG2CHARS( 0x00001FE0 ), LONG2CHARS( 0x00001FF0 ), LONG2CHARS( 0x00001FF8 ), LONG2CHARS( 0x00001FFC ),
+      LONG2CHARS( 0x00001FFE ), LONG2CHARS( 0x00001FFF ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ),
+      LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ),
+      LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ),
+      LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ),
+      LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 )},
+     {LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000800 ), LONG2CHARS( 0x00000C00 ), LONG2CHARS( 0x00000E00 ),
+      LONG2CHARS( 0x00000F00 ), LONG2CHARS( 0x00000F80 ), LONG2CHARS( 0x00000FC0 ), LONG2CHARS( 0x00000FE0 ),
+      LONG2CHARS( 0x00000FF0 ), LONG2CHARS( 0x00000FF8 ), LONG2CHARS( 0x00000FFC ), LONG2CHARS( 0x00000FFE ),
+      LONG2CHARS( 0x00000FFF ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ),
+      LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ),
+      LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ),
+      LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ),
+      LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 )},
+     {LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000400 ), LONG2CHARS( 0x00000600 ), LONG2CHARS( 0x00000700 ),
+      LONG2CHARS( 0x00000780 ), LONG2CHARS( 0x000007C0 ), LONG2CHARS( 0x000007E0 ), LONG2CHARS( 0x000007F0 ),
+      LONG2CHARS( 0x000007F8 ), LONG2CHARS( 0x000007FC ), LONG2CHARS( 0x000007FE ), LONG2CHARS( 0x000007FF ),
+      LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ),
+      LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ),
+      LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ),
+      LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ),
+      LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 )},
+     {LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000200 ), LONG2CHARS( 0x00000300 ), LONG2CHARS( 0x00000380 ),
+      LONG2CHARS( 0x000003C0 ), LONG2CHARS( 0x000003E0 ), LONG2CHARS( 0x000003F0 ), LONG2CHARS( 0x000003F8 ),
+      LONG2CHARS( 0x000003FC ), LONG2CHARS( 0x000003FE ), LONG2CHARS( 0x000003FF ), LONG2CHARS( 0x00000000 ),
+      LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ),
+      LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ),
+      LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ),
+      LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ),
+      LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 )},
+     {LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000100 ), LONG2CHARS( 0x00000180 ), LONG2CHARS( 0x000001C0 ),
+      LONG2CHARS( 0x000001E0 ), LONG2CHARS( 0x000001F0 ), LONG2CHARS( 0x000001F8 ), LONG2CHARS( 0x000001FC ),
+      LONG2CHARS( 0x000001FE ), LONG2CHARS( 0x000001FF ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ),
+      LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ),
+      LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ),
+      LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ),
+      LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ),
+      LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 )},
+     {LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000080 ), LONG2CHARS( 0x000000C0 ), LONG2CHARS( 0x000000E0 ),
+      LONG2CHARS( 0x000000F0 ), LONG2CHARS( 0x000000F8 ), LONG2CHARS( 0x000000FC ), LONG2CHARS( 0x000000FE ),
+      LONG2CHARS( 0x000000FF ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ),
+      LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ),
+      LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ),
+      LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ),
+      LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ),
+      LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 )},
+     {LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000040 ), LONG2CHARS( 0x00000060 ), LONG2CHARS( 0x00000070 ),
+      LONG2CHARS( 0x00000078 ), LONG2CHARS( 0x0000007C ), LONG2CHARS( 0x0000007E ), LONG2CHARS( 0x0000007F ),
+      LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ),
+      LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ),
+      LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ),
+      LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ),
+      LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ),
+      LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 )},
+     {LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000020 ), LONG2CHARS( 0x00000030 ), LONG2CHARS( 0x00000038 ),
+      LONG2CHARS( 0x0000003C ), LONG2CHARS( 0x0000003E ), LONG2CHARS( 0x0000003F ), LONG2CHARS( 0x00000000 ),
+      LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ),
+      LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ),
+      LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ),
+      LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ),
+      LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ),
+      LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 )},
+     {LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000010 ), LONG2CHARS( 0x00000018 ), LONG2CHARS( 0x0000001C ),
+      LONG2CHARS( 0x0000001E ), LONG2CHARS( 0x0000001F ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ),
+      LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ),
+      LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ),
+      LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ),
+      LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ),
+      LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ),
+      LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 )},
+     {LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000008 ), LONG2CHARS( 0x0000000C ), LONG2CHARS( 0x0000000E ),
+      LONG2CHARS( 0x0000000F ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ),
+      LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ),
+      LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ),
+      LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ),
+      LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ),
+      LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ),
+      LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 )},
+     {LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000004 ), LONG2CHARS( 0x00000006 ), LONG2CHARS( 0x00000007 ),
+      LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ),
+      LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ),
+      LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ),
+      LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ),
+      LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ),
+      LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ),
+      LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 )},
+     {LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000002 ), LONG2CHARS( 0x00000003 ), LONG2CHARS( 0x00000000 ),
+      LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ),
+      LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ),
+      LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ),
+      LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ),
+      LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ),
+      LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ),
+      LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 )},
+     {LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000001 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ),
+      LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ),
+      LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ),
+      LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ),
+      LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ),
+      LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ),
+      LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ),
+      LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 )},
+};
+#else /* PPW == 64 */
+unsigned long partmasks[PPW][PPW] = {
+       {
+               LONG2CHARS( 0xFFFFFFFFFFFFFFFF ),
+               LONG2CHARS( 0x8000000000000000 ),
+               LONG2CHARS( 0xC000000000000000 ),
+               LONG2CHARS( 0xE000000000000000 ),
+               LONG2CHARS( 0xF000000000000000 ),
+               LONG2CHARS( 0xF800000000000000 ),
+               LONG2CHARS( 0xFC00000000000000 ),
+               LONG2CHARS( 0xFE00000000000000 ),
+               LONG2CHARS( 0xFF00000000000000 ),
+               LONG2CHARS( 0xFF80000000000000 ),
+               LONG2CHARS( 0xFFC0000000000000 ),
+               LONG2CHARS( 0xFFE0000000000000 ),
+               LONG2CHARS( 0xFFF0000000000000 ),
+               LONG2CHARS( 0xFFF8000000000000 ),
+               LONG2CHARS( 0xFFFC000000000000 ),
+               LONG2CHARS( 0xFFFE000000000000 ),
+               LONG2CHARS( 0xFFFF000000000000 ),
+               LONG2CHARS( 0xFFFF800000000000 ),
+               LONG2CHARS( 0xFFFFC00000000000 ),
+               LONG2CHARS( 0xFFFFE00000000000 ),
+               LONG2CHARS( 0xFFFFF00000000000 ),
+               LONG2CHARS( 0xFFFFF80000000000 ),
+               LONG2CHARS( 0xFFFFFC0000000000 ),
+               LONG2CHARS( 0xFFFFFE0000000000 ),
+               LONG2CHARS( 0xFFFFFF0000000000 ),
+               LONG2CHARS( 0xFFFFFF8000000000 ),
+               LONG2CHARS( 0xFFFFFFC000000000 ),
+               LONG2CHARS( 0xFFFFFFE000000000 ),
+               LONG2CHARS( 0xFFFFFFF000000000 ),
+               LONG2CHARS( 0xFFFFFFF800000000 ),
+               LONG2CHARS( 0xFFFFFFFC00000000 ),
+               LONG2CHARS( 0xFFFFFFFE00000000 ),
+               LONG2CHARS( 0xFFFFFFFF00000000 ),
+               LONG2CHARS( 0xFFFFFFFF80000000 ),
+               LONG2CHARS( 0xFFFFFFFFC0000000 ),
+               LONG2CHARS( 0xFFFFFFFFE0000000 ),
+               LONG2CHARS( 0xFFFFFFFFF0000000 ),
+               LONG2CHARS( 0xFFFFFFFFF8000000 ),
+               LONG2CHARS( 0xFFFFFFFFFC000000 ),
+               LONG2CHARS( 0xFFFFFFFFFE000000 ),
+               LONG2CHARS( 0xFFFFFFFFFF000000 ),
+               LONG2CHARS( 0xFFFFFFFFFF800000 ),
+               LONG2CHARS( 0xFFFFFFFFFFC00000 ),
+               LONG2CHARS( 0xFFFFFFFFFFE00000 ),
+               LONG2CHARS( 0xFFFFFFFFFFF00000 ),
+               LONG2CHARS( 0xFFFFFFFFFFF80000 ),
+               LONG2CHARS( 0xFFFFFFFFFFFC0000 ),
+               LONG2CHARS( 0xFFFFFFFFFFFE0000 ),
+               LONG2CHARS( 0xFFFFFFFFFFFF0000 ),
+               LONG2CHARS( 0xFFFFFFFFFFFF8000 ),
+               LONG2CHARS( 0xFFFFFFFFFFFFC000 ),
+               LONG2CHARS( 0xFFFFFFFFFFFFE000 ),
+               LONG2CHARS( 0xFFFFFFFFFFFFF000 ),
+               LONG2CHARS( 0xFFFFFFFFFFFFF800 ),
+               LONG2CHARS( 0xFFFFFFFFFFFFFC00 ),
+               LONG2CHARS( 0xFFFFFFFFFFFFFE00 ),
+               LONG2CHARS( 0xFFFFFFFFFFFFFF00 ),
+               LONG2CHARS( 0xFFFFFFFFFFFFFF80 ),
+               LONG2CHARS( 0xFFFFFFFFFFFFFFC0 ),
+               LONG2CHARS( 0xFFFFFFFFFFFFFFE0 ),
+               LONG2CHARS( 0xFFFFFFFFFFFFFFF0 ),
+               LONG2CHARS( 0xFFFFFFFFFFFFFFF8 ),
+               LONG2CHARS( 0xFFFFFFFFFFFFFFFC ),
+               LONG2CHARS( 0xFFFFFFFFFFFFFFFE ),
+       },
+       {
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x4000000000000000 ),
+               LONG2CHARS( 0x6000000000000000 ),
+               LONG2CHARS( 0x7000000000000000 ),
+               LONG2CHARS( 0x7800000000000000 ),
+               LONG2CHARS( 0x7C00000000000000 ),
+               LONG2CHARS( 0x7E00000000000000 ),
+               LONG2CHARS( 0x7F00000000000000 ),
+               LONG2CHARS( 0x7F80000000000000 ),
+               LONG2CHARS( 0x7FC0000000000000 ),
+               LONG2CHARS( 0x7FE0000000000000 ),
+               LONG2CHARS( 0x7FF0000000000000 ),
+               LONG2CHARS( 0x7FF8000000000000 ),
+               LONG2CHARS( 0x7FFC000000000000 ),
+               LONG2CHARS( 0x7FFE000000000000 ),
+               LONG2CHARS( 0x7FFF000000000000 ),
+               LONG2CHARS( 0x7FFF800000000000 ),
+               LONG2CHARS( 0x7FFFC00000000000 ),
+               LONG2CHARS( 0x7FFFE00000000000 ),
+               LONG2CHARS( 0x7FFFF00000000000 ),
+               LONG2CHARS( 0x7FFFF80000000000 ),
+               LONG2CHARS( 0x7FFFFC0000000000 ),
+               LONG2CHARS( 0x7FFFFE0000000000 ),
+               LONG2CHARS( 0x7FFFFF0000000000 ),
+               LONG2CHARS( 0x7FFFFF8000000000 ),
+               LONG2CHARS( 0x7FFFFFC000000000 ),
+               LONG2CHARS( 0x7FFFFFE000000000 ),
+               LONG2CHARS( 0x7FFFFFF000000000 ),
+               LONG2CHARS( 0x7FFFFFF800000000 ),
+               LONG2CHARS( 0x7FFFFFFC00000000 ),
+               LONG2CHARS( 0x7FFFFFFE00000000 ),
+               LONG2CHARS( 0x7FFFFFFF00000000 ),
+               LONG2CHARS( 0x7FFFFFFF80000000 ),
+               LONG2CHARS( 0x7FFFFFFFC0000000 ),
+               LONG2CHARS( 0x7FFFFFFFE0000000 ),
+               LONG2CHARS( 0x7FFFFFFFF0000000 ),
+               LONG2CHARS( 0x7FFFFFFFF8000000 ),
+               LONG2CHARS( 0x7FFFFFFFFC000000 ),
+               LONG2CHARS( 0x7FFFFFFFFE000000 ),
+               LONG2CHARS( 0x7FFFFFFFFF000000 ),
+               LONG2CHARS( 0x7FFFFFFFFF800000 ),
+               LONG2CHARS( 0x7FFFFFFFFFC00000 ),
+               LONG2CHARS( 0x7FFFFFFFFFE00000 ),
+               LONG2CHARS( 0x7FFFFFFFFFF00000 ),
+               LONG2CHARS( 0x7FFFFFFFFFF80000 ),
+               LONG2CHARS( 0x7FFFFFFFFFFC0000 ),
+               LONG2CHARS( 0x7FFFFFFFFFFE0000 ),
+               LONG2CHARS( 0x7FFFFFFFFFFF0000 ),
+               LONG2CHARS( 0x7FFFFFFFFFFF8000 ),
+               LONG2CHARS( 0x7FFFFFFFFFFFC000 ),
+               LONG2CHARS( 0x7FFFFFFFFFFFE000 ),
+               LONG2CHARS( 0x7FFFFFFFFFFFF000 ),
+               LONG2CHARS( 0x7FFFFFFFFFFFF800 ),
+               LONG2CHARS( 0x7FFFFFFFFFFFFC00 ),
+               LONG2CHARS( 0x7FFFFFFFFFFFFE00 ),
+               LONG2CHARS( 0x7FFFFFFFFFFFFF00 ),
+               LONG2CHARS( 0x7FFFFFFFFFFFFF80 ),
+               LONG2CHARS( 0x7FFFFFFFFFFFFFC0 ),
+               LONG2CHARS( 0x7FFFFFFFFFFFFFE0 ),
+               LONG2CHARS( 0x7FFFFFFFFFFFFFF0 ),
+               LONG2CHARS( 0x7FFFFFFFFFFFFFF8 ),
+               LONG2CHARS( 0x7FFFFFFFFFFFFFFC ),
+               LONG2CHARS( 0x7FFFFFFFFFFFFFFE ),
+               LONG2CHARS( 0x7FFFFFFFFFFFFFFF ),
+       },
+       {
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x2000000000000000 ),
+               LONG2CHARS( 0x3000000000000000 ),
+               LONG2CHARS( 0x3800000000000000 ),
+               LONG2CHARS( 0x3C00000000000000 ),
+               LONG2CHARS( 0x3E00000000000000 ),
+               LONG2CHARS( 0x3F00000000000000 ),
+               LONG2CHARS( 0x3F80000000000000 ),
+               LONG2CHARS( 0x3FC0000000000000 ),
+               LONG2CHARS( 0x3FE0000000000000 ),
+               LONG2CHARS( 0x3FF0000000000000 ),
+               LONG2CHARS( 0x3FF8000000000000 ),
+               LONG2CHARS( 0x3FFC000000000000 ),
+               LONG2CHARS( 0x3FFE000000000000 ),
+               LONG2CHARS( 0x3FFF000000000000 ),
+               LONG2CHARS( 0x3FFF800000000000 ),
+               LONG2CHARS( 0x3FFFC00000000000 ),
+               LONG2CHARS( 0x3FFFE00000000000 ),
+               LONG2CHARS( 0x3FFFF00000000000 ),
+               LONG2CHARS( 0x3FFFF80000000000 ),
+               LONG2CHARS( 0x3FFFFC0000000000 ),
+               LONG2CHARS( 0x3FFFFE0000000000 ),
+               LONG2CHARS( 0x3FFFFF0000000000 ),
+               LONG2CHARS( 0x3FFFFF8000000000 ),
+               LONG2CHARS( 0x3FFFFFC000000000 ),
+               LONG2CHARS( 0x3FFFFFE000000000 ),
+               LONG2CHARS( 0x3FFFFFF000000000 ),
+               LONG2CHARS( 0x3FFFFFF800000000 ),
+               LONG2CHARS( 0x3FFFFFFC00000000 ),
+               LONG2CHARS( 0x3FFFFFFE00000000 ),
+               LONG2CHARS( 0x3FFFFFFF00000000 ),
+               LONG2CHARS( 0x3FFFFFFF80000000 ),
+               LONG2CHARS( 0x3FFFFFFFC0000000 ),
+               LONG2CHARS( 0x3FFFFFFFE0000000 ),
+               LONG2CHARS( 0x3FFFFFFFF0000000 ),
+               LONG2CHARS( 0x3FFFFFFFF8000000 ),
+               LONG2CHARS( 0x3FFFFFFFFC000000 ),
+               LONG2CHARS( 0x3FFFFFFFFE000000 ),
+               LONG2CHARS( 0x3FFFFFFFFF000000 ),
+               LONG2CHARS( 0x3FFFFFFFFF800000 ),
+               LONG2CHARS( 0x3FFFFFFFFFC00000 ),
+               LONG2CHARS( 0x3FFFFFFFFFE00000 ),
+               LONG2CHARS( 0x3FFFFFFFFFF00000 ),
+               LONG2CHARS( 0x3FFFFFFFFFF80000 ),
+               LONG2CHARS( 0x3FFFFFFFFFFC0000 ),
+               LONG2CHARS( 0x3FFFFFFFFFFE0000 ),
+               LONG2CHARS( 0x3FFFFFFFFFFF0000 ),
+               LONG2CHARS( 0x3FFFFFFFFFFF8000 ),
+               LONG2CHARS( 0x3FFFFFFFFFFFC000 ),
+               LONG2CHARS( 0x3FFFFFFFFFFFE000 ),
+               LONG2CHARS( 0x3FFFFFFFFFFFF000 ),
+               LONG2CHARS( 0x3FFFFFFFFFFFF800 ),
+               LONG2CHARS( 0x3FFFFFFFFFFFFC00 ),
+               LONG2CHARS( 0x3FFFFFFFFFFFFE00 ),
+               LONG2CHARS( 0x3FFFFFFFFFFFFF00 ),
+               LONG2CHARS( 0x3FFFFFFFFFFFFF80 ),
+               LONG2CHARS( 0x3FFFFFFFFFFFFFC0 ),
+               LONG2CHARS( 0x3FFFFFFFFFFFFFE0 ),
+               LONG2CHARS( 0x3FFFFFFFFFFFFFF0 ),
+               LONG2CHARS( 0x3FFFFFFFFFFFFFF8 ),
+               LONG2CHARS( 0x3FFFFFFFFFFFFFFC ),
+               LONG2CHARS( 0x3FFFFFFFFFFFFFFE ),
+               LONG2CHARS( 0x3FFFFFFFFFFFFFFF ),
+               LONG2CHARS( 0x0000000000000000 ),
+       },
+       {
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x1000000000000000 ),
+               LONG2CHARS( 0x1800000000000000 ),
+               LONG2CHARS( 0x1C00000000000000 ),
+               LONG2CHARS( 0x1E00000000000000 ),
+               LONG2CHARS( 0x1F00000000000000 ),
+               LONG2CHARS( 0x1F80000000000000 ),
+               LONG2CHARS( 0x1FC0000000000000 ),
+               LONG2CHARS( 0x1FE0000000000000 ),
+               LONG2CHARS( 0x1FF0000000000000 ),
+               LONG2CHARS( 0x1FF8000000000000 ),
+               LONG2CHARS( 0x1FFC000000000000 ),
+               LONG2CHARS( 0x1FFE000000000000 ),
+               LONG2CHARS( 0x1FFF000000000000 ),
+               LONG2CHARS( 0x1FFF800000000000 ),
+               LONG2CHARS( 0x1FFFC00000000000 ),
+               LONG2CHARS( 0x1FFFE00000000000 ),
+               LONG2CHARS( 0x1FFFF00000000000 ),
+               LONG2CHARS( 0x1FFFF80000000000 ),
+               LONG2CHARS( 0x1FFFFC0000000000 ),
+               LONG2CHARS( 0x1FFFFE0000000000 ),
+               LONG2CHARS( 0x1FFFFF0000000000 ),
+               LONG2CHARS( 0x1FFFFF8000000000 ),
+               LONG2CHARS( 0x1FFFFFC000000000 ),
+               LONG2CHARS( 0x1FFFFFE000000000 ),
+               LONG2CHARS( 0x1FFFFFF000000000 ),
+               LONG2CHARS( 0x1FFFFFF800000000 ),
+               LONG2CHARS( 0x1FFFFFFC00000000 ),
+               LONG2CHARS( 0x1FFFFFFE00000000 ),
+               LONG2CHARS( 0x1FFFFFFF00000000 ),
+               LONG2CHARS( 0x1FFFFFFF80000000 ),
+               LONG2CHARS( 0x1FFFFFFFC0000000 ),
+               LONG2CHARS( 0x1FFFFFFFE0000000 ),
+               LONG2CHARS( 0x1FFFFFFFF0000000 ),
+               LONG2CHARS( 0x1FFFFFFFF8000000 ),
+               LONG2CHARS( 0x1FFFFFFFFC000000 ),
+               LONG2CHARS( 0x1FFFFFFFFE000000 ),
+               LONG2CHARS( 0x1FFFFFFFFF000000 ),
+               LONG2CHARS( 0x1FFFFFFFFF800000 ),
+               LONG2CHARS( 0x1FFFFFFFFFC00000 ),
+               LONG2CHARS( 0x1FFFFFFFFFE00000 ),
+               LONG2CHARS( 0x1FFFFFFFFFF00000 ),
+               LONG2CHARS( 0x1FFFFFFFFFF80000 ),
+               LONG2CHARS( 0x1FFFFFFFFFFC0000 ),
+               LONG2CHARS( 0x1FFFFFFFFFFE0000 ),
+               LONG2CHARS( 0x1FFFFFFFFFFF0000 ),
+               LONG2CHARS( 0x1FFFFFFFFFFF8000 ),
+               LONG2CHARS( 0x1FFFFFFFFFFFC000 ),
+               LONG2CHARS( 0x1FFFFFFFFFFFE000 ),
+               LONG2CHARS( 0x1FFFFFFFFFFFF000 ),
+               LONG2CHARS( 0x1FFFFFFFFFFFF800 ),
+               LONG2CHARS( 0x1FFFFFFFFFFFFC00 ),
+               LONG2CHARS( 0x1FFFFFFFFFFFFE00 ),
+               LONG2CHARS( 0x1FFFFFFFFFFFFF00 ),
+               LONG2CHARS( 0x1FFFFFFFFFFFFF80 ),
+               LONG2CHARS( 0x1FFFFFFFFFFFFFC0 ),
+               LONG2CHARS( 0x1FFFFFFFFFFFFFE0 ),
+               LONG2CHARS( 0x1FFFFFFFFFFFFFF0 ),
+               LONG2CHARS( 0x1FFFFFFFFFFFFFF8 ),
+               LONG2CHARS( 0x1FFFFFFFFFFFFFFC ),
+               LONG2CHARS( 0x1FFFFFFFFFFFFFFE ),
+               LONG2CHARS( 0x1FFFFFFFFFFFFFFF ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+       },
+       {
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0800000000000000 ),
+               LONG2CHARS( 0x0C00000000000000 ),
+               LONG2CHARS( 0x0E00000000000000 ),
+               LONG2CHARS( 0x0F00000000000000 ),
+               LONG2CHARS( 0x0F80000000000000 ),
+               LONG2CHARS( 0x0FC0000000000000 ),
+               LONG2CHARS( 0x0FE0000000000000 ),
+               LONG2CHARS( 0x0FF0000000000000 ),
+               LONG2CHARS( 0x0FF8000000000000 ),
+               LONG2CHARS( 0x0FFC000000000000 ),
+               LONG2CHARS( 0x0FFE000000000000 ),
+               LONG2CHARS( 0x0FFF000000000000 ),
+               LONG2CHARS( 0x0FFF800000000000 ),
+               LONG2CHARS( 0x0FFFC00000000000 ),
+               LONG2CHARS( 0x0FFFE00000000000 ),
+               LONG2CHARS( 0x0FFFF00000000000 ),
+               LONG2CHARS( 0x0FFFF80000000000 ),
+               LONG2CHARS( 0x0FFFFC0000000000 ),
+               LONG2CHARS( 0x0FFFFE0000000000 ),
+               LONG2CHARS( 0x0FFFFF0000000000 ),
+               LONG2CHARS( 0x0FFFFF8000000000 ),
+               LONG2CHARS( 0x0FFFFFC000000000 ),
+               LONG2CHARS( 0x0FFFFFE000000000 ),
+               LONG2CHARS( 0x0FFFFFF000000000 ),
+               LONG2CHARS( 0x0FFFFFF800000000 ),
+               LONG2CHARS( 0x0FFFFFFC00000000 ),
+               LONG2CHARS( 0x0FFFFFFE00000000 ),
+               LONG2CHARS( 0x0FFFFFFF00000000 ),
+               LONG2CHARS( 0x0FFFFFFF80000000 ),
+               LONG2CHARS( 0x0FFFFFFFC0000000 ),
+               LONG2CHARS( 0x0FFFFFFFE0000000 ),
+               LONG2CHARS( 0x0FFFFFFFF0000000 ),
+               LONG2CHARS( 0x0FFFFFFFF8000000 ),
+               LONG2CHARS( 0x0FFFFFFFFC000000 ),
+               LONG2CHARS( 0x0FFFFFFFFE000000 ),
+               LONG2CHARS( 0x0FFFFFFFFF000000 ),
+               LONG2CHARS( 0x0FFFFFFFFF800000 ),
+               LONG2CHARS( 0x0FFFFFFFFFC00000 ),
+               LONG2CHARS( 0x0FFFFFFFFFE00000 ),
+               LONG2CHARS( 0x0FFFFFFFFFF00000 ),
+               LONG2CHARS( 0x0FFFFFFFFFF80000 ),
+               LONG2CHARS( 0x0FFFFFFFFFFC0000 ),
+               LONG2CHARS( 0x0FFFFFFFFFFE0000 ),
+               LONG2CHARS( 0x0FFFFFFFFFFF0000 ),
+               LONG2CHARS( 0x0FFFFFFFFFFF8000 ),
+               LONG2CHARS( 0x0FFFFFFFFFFFC000 ),
+               LONG2CHARS( 0x0FFFFFFFFFFFE000 ),
+               LONG2CHARS( 0x0FFFFFFFFFFFF000 ),
+               LONG2CHARS( 0x0FFFFFFFFFFFF800 ),
+               LONG2CHARS( 0x0FFFFFFFFFFFFC00 ),
+               LONG2CHARS( 0x0FFFFFFFFFFFFE00 ),
+               LONG2CHARS( 0x0FFFFFFFFFFFFF00 ),
+               LONG2CHARS( 0x0FFFFFFFFFFFFF80 ),
+               LONG2CHARS( 0x0FFFFFFFFFFFFFC0 ),
+               LONG2CHARS( 0x0FFFFFFFFFFFFFE0 ),
+               LONG2CHARS( 0x0FFFFFFFFFFFFFF0 ),
+               LONG2CHARS( 0x0FFFFFFFFFFFFFF8 ),
+               LONG2CHARS( 0x0FFFFFFFFFFFFFFC ),
+               LONG2CHARS( 0x0FFFFFFFFFFFFFFE ),
+               LONG2CHARS( 0x0FFFFFFFFFFFFFFF ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+       },
+       {
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0400000000000000 ),
+               LONG2CHARS( 0x0600000000000000 ),
+               LONG2CHARS( 0x0700000000000000 ),
+               LONG2CHARS( 0x0780000000000000 ),
+               LONG2CHARS( 0x07C0000000000000 ),
+               LONG2CHARS( 0x07E0000000000000 ),
+               LONG2CHARS( 0x07F0000000000000 ),
+               LONG2CHARS( 0x07F8000000000000 ),
+               LONG2CHARS( 0x07FC000000000000 ),
+               LONG2CHARS( 0x07FE000000000000 ),
+               LONG2CHARS( 0x07FF000000000000 ),
+               LONG2CHARS( 0x07FF800000000000 ),
+               LONG2CHARS( 0x07FFC00000000000 ),
+               LONG2CHARS( 0x07FFE00000000000 ),
+               LONG2CHARS( 0x07FFF00000000000 ),
+               LONG2CHARS( 0x07FFF80000000000 ),
+               LONG2CHARS( 0x07FFFC0000000000 ),
+               LONG2CHARS( 0x07FFFE0000000000 ),
+               LONG2CHARS( 0x07FFFF0000000000 ),
+               LONG2CHARS( 0x07FFFF8000000000 ),
+               LONG2CHARS( 0x07FFFFC000000000 ),
+               LONG2CHARS( 0x07FFFFE000000000 ),
+               LONG2CHARS( 0x07FFFFF000000000 ),
+               LONG2CHARS( 0x07FFFFF800000000 ),
+               LONG2CHARS( 0x07FFFFFC00000000 ),
+               LONG2CHARS( 0x07FFFFFE00000000 ),
+               LONG2CHARS( 0x07FFFFFF00000000 ),
+               LONG2CHARS( 0x07FFFFFF80000000 ),
+               LONG2CHARS( 0x07FFFFFFC0000000 ),
+               LONG2CHARS( 0x07FFFFFFE0000000 ),
+               LONG2CHARS( 0x07FFFFFFF0000000 ),
+               LONG2CHARS( 0x07FFFFFFF8000000 ),
+               LONG2CHARS( 0x07FFFFFFFC000000 ),
+               LONG2CHARS( 0x07FFFFFFFE000000 ),
+               LONG2CHARS( 0x07FFFFFFFF000000 ),
+               LONG2CHARS( 0x07FFFFFFFF800000 ),
+               LONG2CHARS( 0x07FFFFFFFFC00000 ),
+               LONG2CHARS( 0x07FFFFFFFFE00000 ),
+               LONG2CHARS( 0x07FFFFFFFFF00000 ),
+               LONG2CHARS( 0x07FFFFFFFFF80000 ),
+               LONG2CHARS( 0x07FFFFFFFFFC0000 ),
+               LONG2CHARS( 0x07FFFFFFFFFE0000 ),
+               LONG2CHARS( 0x07FFFFFFFFFF0000 ),
+               LONG2CHARS( 0x07FFFFFFFFFF8000 ),
+               LONG2CHARS( 0x07FFFFFFFFFFC000 ),
+               LONG2CHARS( 0x07FFFFFFFFFFE000 ),
+               LONG2CHARS( 0x07FFFFFFFFFFF000 ),
+               LONG2CHARS( 0x07FFFFFFFFFFF800 ),
+               LONG2CHARS( 0x07FFFFFFFFFFFC00 ),
+               LONG2CHARS( 0x07FFFFFFFFFFFE00 ),
+               LONG2CHARS( 0x07FFFFFFFFFFFF00 ),
+               LONG2CHARS( 0x07FFFFFFFFFFFF80 ),
+               LONG2CHARS( 0x07FFFFFFFFFFFFC0 ),
+               LONG2CHARS( 0x07FFFFFFFFFFFFE0 ),
+               LONG2CHARS( 0x07FFFFFFFFFFFFF0 ),
+               LONG2CHARS( 0x07FFFFFFFFFFFFF8 ),
+               LONG2CHARS( 0x07FFFFFFFFFFFFFC ),
+               LONG2CHARS( 0x07FFFFFFFFFFFFFE ),
+               LONG2CHARS( 0x07FFFFFFFFFFFFFF ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+       },
+       {
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0200000000000000 ),
+               LONG2CHARS( 0x0300000000000000 ),
+               LONG2CHARS( 0x0380000000000000 ),
+               LONG2CHARS( 0x03C0000000000000 ),
+               LONG2CHARS( 0x03E0000000000000 ),
+               LONG2CHARS( 0x03F0000000000000 ),
+               LONG2CHARS( 0x03F8000000000000 ),
+               LONG2CHARS( 0x03FC000000000000 ),
+               LONG2CHARS( 0x03FE000000000000 ),
+               LONG2CHARS( 0x03FF000000000000 ),
+               LONG2CHARS( 0x03FF800000000000 ),
+               LONG2CHARS( 0x03FFC00000000000 ),
+               LONG2CHARS( 0x03FFE00000000000 ),
+               LONG2CHARS( 0x03FFF00000000000 ),
+               LONG2CHARS( 0x03FFF80000000000 ),
+               LONG2CHARS( 0x03FFFC0000000000 ),
+               LONG2CHARS( 0x03FFFE0000000000 ),
+               LONG2CHARS( 0x03FFFF0000000000 ),
+               LONG2CHARS( 0x03FFFF8000000000 ),
+               LONG2CHARS( 0x03FFFFC000000000 ),
+               LONG2CHARS( 0x03FFFFE000000000 ),
+               LONG2CHARS( 0x03FFFFF000000000 ),
+               LONG2CHARS( 0x03FFFFF800000000 ),
+               LONG2CHARS( 0x03FFFFFC00000000 ),
+               LONG2CHARS( 0x03FFFFFE00000000 ),
+               LONG2CHARS( 0x03FFFFFF00000000 ),
+               LONG2CHARS( 0x03FFFFFF80000000 ),
+               LONG2CHARS( 0x03FFFFFFC0000000 ),
+               LONG2CHARS( 0x03FFFFFFE0000000 ),
+               LONG2CHARS( 0x03FFFFFFF0000000 ),
+               LONG2CHARS( 0x03FFFFFFF8000000 ),
+               LONG2CHARS( 0x03FFFFFFFC000000 ),
+               LONG2CHARS( 0x03FFFFFFFE000000 ),
+               LONG2CHARS( 0x03FFFFFFFF000000 ),
+               LONG2CHARS( 0x03FFFFFFFF800000 ),
+               LONG2CHARS( 0x03FFFFFFFFC00000 ),
+               LONG2CHARS( 0x03FFFFFFFFE00000 ),
+               LONG2CHARS( 0x03FFFFFFFFF00000 ),
+               LONG2CHARS( 0x03FFFFFFFFF80000 ),
+               LONG2CHARS( 0x03FFFFFFFFFC0000 ),
+               LONG2CHARS( 0x03FFFFFFFFFE0000 ),
+               LONG2CHARS( 0x03FFFFFFFFFF0000 ),
+               LONG2CHARS( 0x03FFFFFFFFFF8000 ),
+               LONG2CHARS( 0x03FFFFFFFFFFC000 ),
+               LONG2CHARS( 0x03FFFFFFFFFFE000 ),
+               LONG2CHARS( 0x03FFFFFFFFFFF000 ),
+               LONG2CHARS( 0x03FFFFFFFFFFF800 ),
+               LONG2CHARS( 0x03FFFFFFFFFFFC00 ),
+               LONG2CHARS( 0x03FFFFFFFFFFFE00 ),
+               LONG2CHARS( 0x03FFFFFFFFFFFF00 ),
+               LONG2CHARS( 0x03FFFFFFFFFFFF80 ),
+               LONG2CHARS( 0x03FFFFFFFFFFFFC0 ),
+               LONG2CHARS( 0x03FFFFFFFFFFFFE0 ),
+               LONG2CHARS( 0x03FFFFFFFFFFFFF0 ),
+               LONG2CHARS( 0x03FFFFFFFFFFFFF8 ),
+               LONG2CHARS( 0x03FFFFFFFFFFFFFC ),
+               LONG2CHARS( 0x03FFFFFFFFFFFFFE ),
+               LONG2CHARS( 0x03FFFFFFFFFFFFFF ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+       },
+       {
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0100000000000000 ),
+               LONG2CHARS( 0x0180000000000000 ),
+               LONG2CHARS( 0x01C0000000000000 ),
+               LONG2CHARS( 0x01E0000000000000 ),
+               LONG2CHARS( 0x01F0000000000000 ),
+               LONG2CHARS( 0x01F8000000000000 ),
+               LONG2CHARS( 0x01FC000000000000 ),
+               LONG2CHARS( 0x01FE000000000000 ),
+               LONG2CHARS( 0x01FF000000000000 ),
+               LONG2CHARS( 0x01FF800000000000 ),
+               LONG2CHARS( 0x01FFC00000000000 ),
+               LONG2CHARS( 0x01FFE00000000000 ),
+               LONG2CHARS( 0x01FFF00000000000 ),
+               LONG2CHARS( 0x01FFF80000000000 ),
+               LONG2CHARS( 0x01FFFC0000000000 ),
+               LONG2CHARS( 0x01FFFE0000000000 ),
+               LONG2CHARS( 0x01FFFF0000000000 ),
+               LONG2CHARS( 0x01FFFF8000000000 ),
+               LONG2CHARS( 0x01FFFFC000000000 ),
+               LONG2CHARS( 0x01FFFFE000000000 ),
+               LONG2CHARS( 0x01FFFFF000000000 ),
+               LONG2CHARS( 0x01FFFFF800000000 ),
+               LONG2CHARS( 0x01FFFFFC00000000 ),
+               LONG2CHARS( 0x01FFFFFE00000000 ),
+               LONG2CHARS( 0x01FFFFFF00000000 ),
+               LONG2CHARS( 0x01FFFFFF80000000 ),
+               LONG2CHARS( 0x01FFFFFFC0000000 ),
+               LONG2CHARS( 0x01FFFFFFE0000000 ),
+               LONG2CHARS( 0x01FFFFFFF0000000 ),
+               LONG2CHARS( 0x01FFFFFFF8000000 ),
+               LONG2CHARS( 0x01FFFFFFFC000000 ),
+               LONG2CHARS( 0x01FFFFFFFE000000 ),
+               LONG2CHARS( 0x01FFFFFFFF000000 ),
+               LONG2CHARS( 0x01FFFFFFFF800000 ),
+               LONG2CHARS( 0x01FFFFFFFFC00000 ),
+               LONG2CHARS( 0x01FFFFFFFFE00000 ),
+               LONG2CHARS( 0x01FFFFFFFFF00000 ),
+               LONG2CHARS( 0x01FFFFFFFFF80000 ),
+               LONG2CHARS( 0x01FFFFFFFFFC0000 ),
+               LONG2CHARS( 0x01FFFFFFFFFE0000 ),
+               LONG2CHARS( 0x01FFFFFFFFFF0000 ),
+               LONG2CHARS( 0x01FFFFFFFFFF8000 ),
+               LONG2CHARS( 0x01FFFFFFFFFFC000 ),
+               LONG2CHARS( 0x01FFFFFFFFFFE000 ),
+               LONG2CHARS( 0x01FFFFFFFFFFF000 ),
+               LONG2CHARS( 0x01FFFFFFFFFFF800 ),
+               LONG2CHARS( 0x01FFFFFFFFFFFC00 ),
+               LONG2CHARS( 0x01FFFFFFFFFFFE00 ),
+               LONG2CHARS( 0x01FFFFFFFFFFFF00 ),
+               LONG2CHARS( 0x01FFFFFFFFFFFF80 ),
+               LONG2CHARS( 0x01FFFFFFFFFFFFC0 ),
+               LONG2CHARS( 0x01FFFFFFFFFFFFE0 ),
+               LONG2CHARS( 0x01FFFFFFFFFFFFF0 ),
+               LONG2CHARS( 0x01FFFFFFFFFFFFF8 ),
+               LONG2CHARS( 0x01FFFFFFFFFFFFFC ),
+               LONG2CHARS( 0x01FFFFFFFFFFFFFE ),
+               LONG2CHARS( 0x01FFFFFFFFFFFFFF ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+       },
+       {
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0080000000000000 ),
+               LONG2CHARS( 0x00C0000000000000 ),
+               LONG2CHARS( 0x00E0000000000000 ),
+               LONG2CHARS( 0x00F0000000000000 ),
+               LONG2CHARS( 0x00F8000000000000 ),
+               LONG2CHARS( 0x00FC000000000000 ),
+               LONG2CHARS( 0x00FE000000000000 ),
+               LONG2CHARS( 0x00FF000000000000 ),
+               LONG2CHARS( 0x00FF800000000000 ),
+               LONG2CHARS( 0x00FFC00000000000 ),
+               LONG2CHARS( 0x00FFE00000000000 ),
+               LONG2CHARS( 0x00FFF00000000000 ),
+               LONG2CHARS( 0x00FFF80000000000 ),
+               LONG2CHARS( 0x00FFFC0000000000 ),
+               LONG2CHARS( 0x00FFFE0000000000 ),
+               LONG2CHARS( 0x00FFFF0000000000 ),
+               LONG2CHARS( 0x00FFFF8000000000 ),
+               LONG2CHARS( 0x00FFFFC000000000 ),
+               LONG2CHARS( 0x00FFFFE000000000 ),
+               LONG2CHARS( 0x00FFFFF000000000 ),
+               LONG2CHARS( 0x00FFFFF800000000 ),
+               LONG2CHARS( 0x00FFFFFC00000000 ),
+               LONG2CHARS( 0x00FFFFFE00000000 ),
+               LONG2CHARS( 0x00FFFFFF00000000 ),
+               LONG2CHARS( 0x00FFFFFF80000000 ),
+               LONG2CHARS( 0x00FFFFFFC0000000 ),
+               LONG2CHARS( 0x00FFFFFFE0000000 ),
+               LONG2CHARS( 0x00FFFFFFF0000000 ),
+               LONG2CHARS( 0x00FFFFFFF8000000 ),
+               LONG2CHARS( 0x00FFFFFFFC000000 ),
+               LONG2CHARS( 0x00FFFFFFFE000000 ),
+               LONG2CHARS( 0x00FFFFFFFF000000 ),
+               LONG2CHARS( 0x00FFFFFFFF800000 ),
+               LONG2CHARS( 0x00FFFFFFFFC00000 ),
+               LONG2CHARS( 0x00FFFFFFFFE00000 ),
+               LONG2CHARS( 0x00FFFFFFFFF00000 ),
+               LONG2CHARS( 0x00FFFFFFFFF80000 ),
+               LONG2CHARS( 0x00FFFFFFFFFC0000 ),
+               LONG2CHARS( 0x00FFFFFFFFFE0000 ),
+               LONG2CHARS( 0x00FFFFFFFFFF0000 ),
+               LONG2CHARS( 0x00FFFFFFFFFF8000 ),
+               LONG2CHARS( 0x00FFFFFFFFFFC000 ),
+               LONG2CHARS( 0x00FFFFFFFFFFE000 ),
+               LONG2CHARS( 0x00FFFFFFFFFFF000 ),
+               LONG2CHARS( 0x00FFFFFFFFFFF800 ),
+               LONG2CHARS( 0x00FFFFFFFFFFFC00 ),
+               LONG2CHARS( 0x00FFFFFFFFFFFE00 ),
+               LONG2CHARS( 0x00FFFFFFFFFFFF00 ),
+               LONG2CHARS( 0x00FFFFFFFFFFFF80 ),
+               LONG2CHARS( 0x00FFFFFFFFFFFFC0 ),
+               LONG2CHARS( 0x00FFFFFFFFFFFFE0 ),
+               LONG2CHARS( 0x00FFFFFFFFFFFFF0 ),
+               LONG2CHARS( 0x00FFFFFFFFFFFFF8 ),
+               LONG2CHARS( 0x00FFFFFFFFFFFFFC ),
+               LONG2CHARS( 0x00FFFFFFFFFFFFFE ),
+               LONG2CHARS( 0x00FFFFFFFFFFFFFF ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+       },
+       {
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0040000000000000 ),
+               LONG2CHARS( 0x0060000000000000 ),
+               LONG2CHARS( 0x0070000000000000 ),
+               LONG2CHARS( 0x0078000000000000 ),
+               LONG2CHARS( 0x007C000000000000 ),
+               LONG2CHARS( 0x007E000000000000 ),
+               LONG2CHARS( 0x007F000000000000 ),
+               LONG2CHARS( 0x007F800000000000 ),
+               LONG2CHARS( 0x007FC00000000000 ),
+               LONG2CHARS( 0x007FE00000000000 ),
+               LONG2CHARS( 0x007FF00000000000 ),
+               LONG2CHARS( 0x007FF80000000000 ),
+               LONG2CHARS( 0x007FFC0000000000 ),
+               LONG2CHARS( 0x007FFE0000000000 ),
+               LONG2CHARS( 0x007FFF0000000000 ),
+               LONG2CHARS( 0x007FFF8000000000 ),
+               LONG2CHARS( 0x007FFFC000000000 ),
+               LONG2CHARS( 0x007FFFE000000000 ),
+               LONG2CHARS( 0x007FFFF000000000 ),
+               LONG2CHARS( 0x007FFFF800000000 ),
+               LONG2CHARS( 0x007FFFFC00000000 ),
+               LONG2CHARS( 0x007FFFFE00000000 ),
+               LONG2CHARS( 0x007FFFFF00000000 ),
+               LONG2CHARS( 0x007FFFFF80000000 ),
+               LONG2CHARS( 0x007FFFFFC0000000 ),
+               LONG2CHARS( 0x007FFFFFE0000000 ),
+               LONG2CHARS( 0x007FFFFFF0000000 ),
+               LONG2CHARS( 0x007FFFFFF8000000 ),
+               LONG2CHARS( 0x007FFFFFFC000000 ),
+               LONG2CHARS( 0x007FFFFFFE000000 ),
+               LONG2CHARS( 0x007FFFFFFF000000 ),
+               LONG2CHARS( 0x007FFFFFFF800000 ),
+               LONG2CHARS( 0x007FFFFFFFC00000 ),
+               LONG2CHARS( 0x007FFFFFFFE00000 ),
+               LONG2CHARS( 0x007FFFFFFFF00000 ),
+               LONG2CHARS( 0x007FFFFFFFF80000 ),
+               LONG2CHARS( 0x007FFFFFFFFC0000 ),
+               LONG2CHARS( 0x007FFFFFFFFE0000 ),
+               LONG2CHARS( 0x007FFFFFFFFF0000 ),
+               LONG2CHARS( 0x007FFFFFFFFF8000 ),
+               LONG2CHARS( 0x007FFFFFFFFFC000 ),
+               LONG2CHARS( 0x007FFFFFFFFFE000 ),
+               LONG2CHARS( 0x007FFFFFFFFFF000 ),
+               LONG2CHARS( 0x007FFFFFFFFFF800 ),
+               LONG2CHARS( 0x007FFFFFFFFFFC00 ),
+               LONG2CHARS( 0x007FFFFFFFFFFE00 ),
+               LONG2CHARS( 0x007FFFFFFFFFFF00 ),
+               LONG2CHARS( 0x007FFFFFFFFFFF80 ),
+               LONG2CHARS( 0x007FFFFFFFFFFFC0 ),
+               LONG2CHARS( 0x007FFFFFFFFFFFE0 ),
+               LONG2CHARS( 0x007FFFFFFFFFFFF0 ),
+               LONG2CHARS( 0x007FFFFFFFFFFFF8 ),
+               LONG2CHARS( 0x007FFFFFFFFFFFFC ),
+               LONG2CHARS( 0x007FFFFFFFFFFFFE ),
+               LONG2CHARS( 0x007FFFFFFFFFFFFF ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+       },
+       {
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0020000000000000 ),
+               LONG2CHARS( 0x0030000000000000 ),
+               LONG2CHARS( 0x0038000000000000 ),
+               LONG2CHARS( 0x003C000000000000 ),
+               LONG2CHARS( 0x003E000000000000 ),
+               LONG2CHARS( 0x003F000000000000 ),
+               LONG2CHARS( 0x003F800000000000 ),
+               LONG2CHARS( 0x003FC00000000000 ),
+               LONG2CHARS( 0x003FE00000000000 ),
+               LONG2CHARS( 0x003FF00000000000 ),
+               LONG2CHARS( 0x003FF80000000000 ),
+               LONG2CHARS( 0x003FFC0000000000 ),
+               LONG2CHARS( 0x003FFE0000000000 ),
+               LONG2CHARS( 0x003FFF0000000000 ),
+               LONG2CHARS( 0x003FFF8000000000 ),
+               LONG2CHARS( 0x003FFFC000000000 ),
+               LONG2CHARS( 0x003FFFE000000000 ),
+               LONG2CHARS( 0x003FFFF000000000 ),
+               LONG2CHARS( 0x003FFFF800000000 ),
+               LONG2CHARS( 0x003FFFFC00000000 ),
+               LONG2CHARS( 0x003FFFFE00000000 ),
+               LONG2CHARS( 0x003FFFFF00000000 ),
+               LONG2CHARS( 0x003FFFFF80000000 ),
+               LONG2CHARS( 0x003FFFFFC0000000 ),
+               LONG2CHARS( 0x003FFFFFE0000000 ),
+               LONG2CHARS( 0x003FFFFFF0000000 ),
+               LONG2CHARS( 0x003FFFFFF8000000 ),
+               LONG2CHARS( 0x003FFFFFFC000000 ),
+               LONG2CHARS( 0x003FFFFFFE000000 ),
+               LONG2CHARS( 0x003FFFFFFF000000 ),
+               LONG2CHARS( 0x003FFFFFFF800000 ),
+               LONG2CHARS( 0x003FFFFFFFC00000 ),
+               LONG2CHARS( 0x003FFFFFFFE00000 ),
+               LONG2CHARS( 0x003FFFFFFFF00000 ),
+               LONG2CHARS( 0x003FFFFFFFF80000 ),
+               LONG2CHARS( 0x003FFFFFFFFC0000 ),
+               LONG2CHARS( 0x003FFFFFFFFE0000 ),
+               LONG2CHARS( 0x003FFFFFFFFF0000 ),
+               LONG2CHARS( 0x003FFFFFFFFF8000 ),
+               LONG2CHARS( 0x003FFFFFFFFFC000 ),
+               LONG2CHARS( 0x003FFFFFFFFFE000 ),
+               LONG2CHARS( 0x003FFFFFFFFFF000 ),
+               LONG2CHARS( 0x003FFFFFFFFFF800 ),
+               LONG2CHARS( 0x003FFFFFFFFFFC00 ),
+               LONG2CHARS( 0x003FFFFFFFFFFE00 ),
+               LONG2CHARS( 0x003FFFFFFFFFFF00 ),
+               LONG2CHARS( 0x003FFFFFFFFFFF80 ),
+               LONG2CHARS( 0x003FFFFFFFFFFFC0 ),
+               LONG2CHARS( 0x003FFFFFFFFFFFE0 ),
+               LONG2CHARS( 0x003FFFFFFFFFFFF0 ),
+               LONG2CHARS( 0x003FFFFFFFFFFFF8 ),
+               LONG2CHARS( 0x003FFFFFFFFFFFFC ),
+               LONG2CHARS( 0x003FFFFFFFFFFFFE ),
+               LONG2CHARS( 0x003FFFFFFFFFFFFF ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+       },
+       {
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0010000000000000 ),
+               LONG2CHARS( 0x0018000000000000 ),
+               LONG2CHARS( 0x001C000000000000 ),
+               LONG2CHARS( 0x001E000000000000 ),
+               LONG2CHARS( 0x001F000000000000 ),
+               LONG2CHARS( 0x001F800000000000 ),
+               LONG2CHARS( 0x001FC00000000000 ),
+               LONG2CHARS( 0x001FE00000000000 ),
+               LONG2CHARS( 0x001FF00000000000 ),
+               LONG2CHARS( 0x001FF80000000000 ),
+               LONG2CHARS( 0x001FFC0000000000 ),
+               LONG2CHARS( 0x001FFE0000000000 ),
+               LONG2CHARS( 0x001FFF0000000000 ),
+               LONG2CHARS( 0x001FFF8000000000 ),
+               LONG2CHARS( 0x001FFFC000000000 ),
+               LONG2CHARS( 0x001FFFE000000000 ),
+               LONG2CHARS( 0x001FFFF000000000 ),
+               LONG2CHARS( 0x001FFFF800000000 ),
+               LONG2CHARS( 0x001FFFFC00000000 ),
+               LONG2CHARS( 0x001FFFFE00000000 ),
+               LONG2CHARS( 0x001FFFFF00000000 ),
+               LONG2CHARS( 0x001FFFFF80000000 ),
+               LONG2CHARS( 0x001FFFFFC0000000 ),
+               LONG2CHARS( 0x001FFFFFE0000000 ),
+               LONG2CHARS( 0x001FFFFFF0000000 ),
+               LONG2CHARS( 0x001FFFFFF8000000 ),
+               LONG2CHARS( 0x001FFFFFFC000000 ),
+               LONG2CHARS( 0x001FFFFFFE000000 ),
+               LONG2CHARS( 0x001FFFFFFF000000 ),
+               LONG2CHARS( 0x001FFFFFFF800000 ),
+               LONG2CHARS( 0x001FFFFFFFC00000 ),
+               LONG2CHARS( 0x001FFFFFFFE00000 ),
+               LONG2CHARS( 0x001FFFFFFFF00000 ),
+               LONG2CHARS( 0x001FFFFFFFF80000 ),
+               LONG2CHARS( 0x001FFFFFFFFC0000 ),
+               LONG2CHARS( 0x001FFFFFFFFE0000 ),
+               LONG2CHARS( 0x001FFFFFFFFF0000 ),
+               LONG2CHARS( 0x001FFFFFFFFF8000 ),
+               LONG2CHARS( 0x001FFFFFFFFFC000 ),
+               LONG2CHARS( 0x001FFFFFFFFFE000 ),
+               LONG2CHARS( 0x001FFFFFFFFFF000 ),
+               LONG2CHARS( 0x001FFFFFFFFFF800 ),
+               LONG2CHARS( 0x001FFFFFFFFFFC00 ),
+               LONG2CHARS( 0x001FFFFFFFFFFE00 ),
+               LONG2CHARS( 0x001FFFFFFFFFFF00 ),
+               LONG2CHARS( 0x001FFFFFFFFFFF80 ),
+               LONG2CHARS( 0x001FFFFFFFFFFFC0 ),
+               LONG2CHARS( 0x001FFFFFFFFFFFE0 ),
+               LONG2CHARS( 0x001FFFFFFFFFFFF0 ),
+               LONG2CHARS( 0x001FFFFFFFFFFFF8 ),
+               LONG2CHARS( 0x001FFFFFFFFFFFFC ),
+               LONG2CHARS( 0x001FFFFFFFFFFFFE ),
+               LONG2CHARS( 0x001FFFFFFFFFFFFF ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+       },
+       {
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0008000000000000 ),
+               LONG2CHARS( 0x000C000000000000 ),
+               LONG2CHARS( 0x000E000000000000 ),
+               LONG2CHARS( 0x000F000000000000 ),
+               LONG2CHARS( 0x000F800000000000 ),
+               LONG2CHARS( 0x000FC00000000000 ),
+               LONG2CHARS( 0x000FE00000000000 ),
+               LONG2CHARS( 0x000FF00000000000 ),
+               LONG2CHARS( 0x000FF80000000000 ),
+               LONG2CHARS( 0x000FFC0000000000 ),
+               LONG2CHARS( 0x000FFE0000000000 ),
+               LONG2CHARS( 0x000FFF0000000000 ),
+               LONG2CHARS( 0x000FFF8000000000 ),
+               LONG2CHARS( 0x000FFFC000000000 ),
+               LONG2CHARS( 0x000FFFE000000000 ),
+               LONG2CHARS( 0x000FFFF000000000 ),
+               LONG2CHARS( 0x000FFFF800000000 ),
+               LONG2CHARS( 0x000FFFFC00000000 ),
+               LONG2CHARS( 0x000FFFFE00000000 ),
+               LONG2CHARS( 0x000FFFFF00000000 ),
+               LONG2CHARS( 0x000FFFFF80000000 ),
+               LONG2CHARS( 0x000FFFFFC0000000 ),
+               LONG2CHARS( 0x000FFFFFE0000000 ),
+               LONG2CHARS( 0x000FFFFFF0000000 ),
+               LONG2CHARS( 0x000FFFFFF8000000 ),
+               LONG2CHARS( 0x000FFFFFFC000000 ),
+               LONG2CHARS( 0x000FFFFFFE000000 ),
+               LONG2CHARS( 0x000FFFFFFF000000 ),
+               LONG2CHARS( 0x000FFFFFFF800000 ),
+               LONG2CHARS( 0x000FFFFFFFC00000 ),
+               LONG2CHARS( 0x000FFFFFFFE00000 ),
+               LONG2CHARS( 0x000FFFFFFFF00000 ),
+               LONG2CHARS( 0x000FFFFFFFF80000 ),
+               LONG2CHARS( 0x000FFFFFFFFC0000 ),
+               LONG2CHARS( 0x000FFFFFFFFE0000 ),
+               LONG2CHARS( 0x000FFFFFFFFF0000 ),
+               LONG2CHARS( 0x000FFFFFFFFF8000 ),
+               LONG2CHARS( 0x000FFFFFFFFFC000 ),
+               LONG2CHARS( 0x000FFFFFFFFFE000 ),
+               LONG2CHARS( 0x000FFFFFFFFFF000 ),
+               LONG2CHARS( 0x000FFFFFFFFFF800 ),
+               LONG2CHARS( 0x000FFFFFFFFFFC00 ),
+               LONG2CHARS( 0x000FFFFFFFFFFE00 ),
+               LONG2CHARS( 0x000FFFFFFFFFFF00 ),
+               LONG2CHARS( 0x000FFFFFFFFFFF80 ),
+               LONG2CHARS( 0x000FFFFFFFFFFFC0 ),
+               LONG2CHARS( 0x000FFFFFFFFFFFE0 ),
+               LONG2CHARS( 0x000FFFFFFFFFFFF0 ),
+               LONG2CHARS( 0x000FFFFFFFFFFFF8 ),
+               LONG2CHARS( 0x000FFFFFFFFFFFFC ),
+               LONG2CHARS( 0x000FFFFFFFFFFFFE ),
+               LONG2CHARS( 0x000FFFFFFFFFFFFF ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+       },
+       {
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0004000000000000 ),
+               LONG2CHARS( 0x0006000000000000 ),
+               LONG2CHARS( 0x0007000000000000 ),
+               LONG2CHARS( 0x0007800000000000 ),
+               LONG2CHARS( 0x0007C00000000000 ),
+               LONG2CHARS( 0x0007E00000000000 ),
+               LONG2CHARS( 0x0007F00000000000 ),
+               LONG2CHARS( 0x0007F80000000000 ),
+               LONG2CHARS( 0x0007FC0000000000 ),
+               LONG2CHARS( 0x0007FE0000000000 ),
+               LONG2CHARS( 0x0007FF0000000000 ),
+               LONG2CHARS( 0x0007FF8000000000 ),
+               LONG2CHARS( 0x0007FFC000000000 ),
+               LONG2CHARS( 0x0007FFE000000000 ),
+               LONG2CHARS( 0x0007FFF000000000 ),
+               LONG2CHARS( 0x0007FFF800000000 ),
+               LONG2CHARS( 0x0007FFFC00000000 ),
+               LONG2CHARS( 0x0007FFFE00000000 ),
+               LONG2CHARS( 0x0007FFFF00000000 ),
+               LONG2CHARS( 0x0007FFFF80000000 ),
+               LONG2CHARS( 0x0007FFFFC0000000 ),
+               LONG2CHARS( 0x0007FFFFE0000000 ),
+               LONG2CHARS( 0x0007FFFFF0000000 ),
+               LONG2CHARS( 0x0007FFFFF8000000 ),
+               LONG2CHARS( 0x0007FFFFFC000000 ),
+               LONG2CHARS( 0x0007FFFFFE000000 ),
+               LONG2CHARS( 0x0007FFFFFF000000 ),
+               LONG2CHARS( 0x0007FFFFFF800000 ),
+               LONG2CHARS( 0x0007FFFFFFC00000 ),
+               LONG2CHARS( 0x0007FFFFFFE00000 ),
+               LONG2CHARS( 0x0007FFFFFFF00000 ),
+               LONG2CHARS( 0x0007FFFFFFF80000 ),
+               LONG2CHARS( 0x0007FFFFFFFC0000 ),
+               LONG2CHARS( 0x0007FFFFFFFE0000 ),
+               LONG2CHARS( 0x0007FFFFFFFF0000 ),
+               LONG2CHARS( 0x0007FFFFFFFF8000 ),
+               LONG2CHARS( 0x0007FFFFFFFFC000 ),
+               LONG2CHARS( 0x0007FFFFFFFFE000 ),
+               LONG2CHARS( 0x0007FFFFFFFFF000 ),
+               LONG2CHARS( 0x0007FFFFFFFFF800 ),
+               LONG2CHARS( 0x0007FFFFFFFFFC00 ),
+               LONG2CHARS( 0x0007FFFFFFFFFE00 ),
+               LONG2CHARS( 0x0007FFFFFFFFFF00 ),
+               LONG2CHARS( 0x0007FFFFFFFFFF80 ),
+               LONG2CHARS( 0x0007FFFFFFFFFFC0 ),
+               LONG2CHARS( 0x0007FFFFFFFFFFE0 ),
+               LONG2CHARS( 0x0007FFFFFFFFFFF0 ),
+               LONG2CHARS( 0x0007FFFFFFFFFFF8 ),
+               LONG2CHARS( 0x0007FFFFFFFFFFFC ),
+               LONG2CHARS( 0x0007FFFFFFFFFFFE ),
+               LONG2CHARS( 0x0007FFFFFFFFFFFF ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+       },
+       {
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0002000000000000 ),
+               LONG2CHARS( 0x0003000000000000 ),
+               LONG2CHARS( 0x0003800000000000 ),
+               LONG2CHARS( 0x0003C00000000000 ),
+               LONG2CHARS( 0x0003E00000000000 ),
+               LONG2CHARS( 0x0003F00000000000 ),
+               LONG2CHARS( 0x0003F80000000000 ),
+               LONG2CHARS( 0x0003FC0000000000 ),
+               LONG2CHARS( 0x0003FE0000000000 ),
+               LONG2CHARS( 0x0003FF0000000000 ),
+               LONG2CHARS( 0x0003FF8000000000 ),
+               LONG2CHARS( 0x0003FFC000000000 ),
+               LONG2CHARS( 0x0003FFE000000000 ),
+               LONG2CHARS( 0x0003FFF000000000 ),
+               LONG2CHARS( 0x0003FFF800000000 ),
+               LONG2CHARS( 0x0003FFFC00000000 ),
+               LONG2CHARS( 0x0003FFFE00000000 ),
+               LONG2CHARS( 0x0003FFFF00000000 ),
+               LONG2CHARS( 0x0003FFFF80000000 ),
+               LONG2CHARS( 0x0003FFFFC0000000 ),
+               LONG2CHARS( 0x0003FFFFE0000000 ),
+               LONG2CHARS( 0x0003FFFFF0000000 ),
+               LONG2CHARS( 0x0003FFFFF8000000 ),
+               LONG2CHARS( 0x0003FFFFFC000000 ),
+               LONG2CHARS( 0x0003FFFFFE000000 ),
+               LONG2CHARS( 0x0003FFFFFF000000 ),
+               LONG2CHARS( 0x0003FFFFFF800000 ),
+               LONG2CHARS( 0x0003FFFFFFC00000 ),
+               LONG2CHARS( 0x0003FFFFFFE00000 ),
+               LONG2CHARS( 0x0003FFFFFFF00000 ),
+               LONG2CHARS( 0x0003FFFFFFF80000 ),
+               LONG2CHARS( 0x0003FFFFFFFC0000 ),
+               LONG2CHARS( 0x0003FFFFFFFE0000 ),
+               LONG2CHARS( 0x0003FFFFFFFF0000 ),
+               LONG2CHARS( 0x0003FFFFFFFF8000 ),
+               LONG2CHARS( 0x0003FFFFFFFFC000 ),
+               LONG2CHARS( 0x0003FFFFFFFFE000 ),
+               LONG2CHARS( 0x0003FFFFFFFFF000 ),
+               LONG2CHARS( 0x0003FFFFFFFFF800 ),
+               LONG2CHARS( 0x0003FFFFFFFFFC00 ),
+               LONG2CHARS( 0x0003FFFFFFFFFE00 ),
+               LONG2CHARS( 0x0003FFFFFFFFFF00 ),
+               LONG2CHARS( 0x0003FFFFFFFFFF80 ),
+               LONG2CHARS( 0x0003FFFFFFFFFFC0 ),
+               LONG2CHARS( 0x0003FFFFFFFFFFE0 ),
+               LONG2CHARS( 0x0003FFFFFFFFFFF0 ),
+               LONG2CHARS( 0x0003FFFFFFFFFFF8 ),
+               LONG2CHARS( 0x0003FFFFFFFFFFFC ),
+               LONG2CHARS( 0x0003FFFFFFFFFFFE ),
+               LONG2CHARS( 0x0003FFFFFFFFFFFF ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+       },
+       {
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0001000000000000 ),
+               LONG2CHARS( 0x0001800000000000 ),
+               LONG2CHARS( 0x0001C00000000000 ),
+               LONG2CHARS( 0x0001E00000000000 ),
+               LONG2CHARS( 0x0001F00000000000 ),
+               LONG2CHARS( 0x0001F80000000000 ),
+               LONG2CHARS( 0x0001FC0000000000 ),
+               LONG2CHARS( 0x0001FE0000000000 ),
+               LONG2CHARS( 0x0001FF0000000000 ),
+               LONG2CHARS( 0x0001FF8000000000 ),
+               LONG2CHARS( 0x0001FFC000000000 ),
+               LONG2CHARS( 0x0001FFE000000000 ),
+               LONG2CHARS( 0x0001FFF000000000 ),
+               LONG2CHARS( 0x0001FFF800000000 ),
+               LONG2CHARS( 0x0001FFFC00000000 ),
+               LONG2CHARS( 0x0001FFFE00000000 ),
+               LONG2CHARS( 0x0001FFFF00000000 ),
+               LONG2CHARS( 0x0001FFFF80000000 ),
+               LONG2CHARS( 0x0001FFFFC0000000 ),
+               LONG2CHARS( 0x0001FFFFE0000000 ),
+               LONG2CHARS( 0x0001FFFFF0000000 ),
+               LONG2CHARS( 0x0001FFFFF8000000 ),
+               LONG2CHARS( 0x0001FFFFFC000000 ),
+               LONG2CHARS( 0x0001FFFFFE000000 ),
+               LONG2CHARS( 0x0001FFFFFF000000 ),
+               LONG2CHARS( 0x0001FFFFFF800000 ),
+               LONG2CHARS( 0x0001FFFFFFC00000 ),
+               LONG2CHARS( 0x0001FFFFFFE00000 ),
+               LONG2CHARS( 0x0001FFFFFFF00000 ),
+               LONG2CHARS( 0x0001FFFFFFF80000 ),
+               LONG2CHARS( 0x0001FFFFFFFC0000 ),
+               LONG2CHARS( 0x0001FFFFFFFE0000 ),
+               LONG2CHARS( 0x0001FFFFFFFF0000 ),
+               LONG2CHARS( 0x0001FFFFFFFF8000 ),
+               LONG2CHARS( 0x0001FFFFFFFFC000 ),
+               LONG2CHARS( 0x0001FFFFFFFFE000 ),
+               LONG2CHARS( 0x0001FFFFFFFFF000 ),
+               LONG2CHARS( 0x0001FFFFFFFFF800 ),
+               LONG2CHARS( 0x0001FFFFFFFFFC00 ),
+               LONG2CHARS( 0x0001FFFFFFFFFE00 ),
+               LONG2CHARS( 0x0001FFFFFFFFFF00 ),
+               LONG2CHARS( 0x0001FFFFFFFFFF80 ),
+               LONG2CHARS( 0x0001FFFFFFFFFFC0 ),
+               LONG2CHARS( 0x0001FFFFFFFFFFE0 ),
+               LONG2CHARS( 0x0001FFFFFFFFFFF0 ),
+               LONG2CHARS( 0x0001FFFFFFFFFFF8 ),
+               LONG2CHARS( 0x0001FFFFFFFFFFFC ),
+               LONG2CHARS( 0x0001FFFFFFFFFFFE ),
+               LONG2CHARS( 0x0001FFFFFFFFFFFF ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+       },
+       {
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000800000000000 ),
+               LONG2CHARS( 0x0000C00000000000 ),
+               LONG2CHARS( 0x0000E00000000000 ),
+               LONG2CHARS( 0x0000F00000000000 ),
+               LONG2CHARS( 0x0000F80000000000 ),
+               LONG2CHARS( 0x0000FC0000000000 ),
+               LONG2CHARS( 0x0000FE0000000000 ),
+               LONG2CHARS( 0x0000FF0000000000 ),
+               LONG2CHARS( 0x0000FF8000000000 ),
+               LONG2CHARS( 0x0000FFC000000000 ),
+               LONG2CHARS( 0x0000FFE000000000 ),
+               LONG2CHARS( 0x0000FFF000000000 ),
+               LONG2CHARS( 0x0000FFF800000000 ),
+               LONG2CHARS( 0x0000FFFC00000000 ),
+               LONG2CHARS( 0x0000FFFE00000000 ),
+               LONG2CHARS( 0x0000FFFF00000000 ),
+               LONG2CHARS( 0x0000FFFF80000000 ),
+               LONG2CHARS( 0x0000FFFFC0000000 ),
+               LONG2CHARS( 0x0000FFFFE0000000 ),
+               LONG2CHARS( 0x0000FFFFF0000000 ),
+               LONG2CHARS( 0x0000FFFFF8000000 ),
+               LONG2CHARS( 0x0000FFFFFC000000 ),
+               LONG2CHARS( 0x0000FFFFFE000000 ),
+               LONG2CHARS( 0x0000FFFFFF000000 ),
+               LONG2CHARS( 0x0000FFFFFF800000 ),
+               LONG2CHARS( 0x0000FFFFFFC00000 ),
+               LONG2CHARS( 0x0000FFFFFFE00000 ),
+               LONG2CHARS( 0x0000FFFFFFF00000 ),
+               LONG2CHARS( 0x0000FFFFFFF80000 ),
+               LONG2CHARS( 0x0000FFFFFFFC0000 ),
+               LONG2CHARS( 0x0000FFFFFFFE0000 ),
+               LONG2CHARS( 0x0000FFFFFFFF0000 ),
+               LONG2CHARS( 0x0000FFFFFFFF8000 ),
+               LONG2CHARS( 0x0000FFFFFFFFC000 ),
+               LONG2CHARS( 0x0000FFFFFFFFE000 ),
+               LONG2CHARS( 0x0000FFFFFFFFF000 ),
+               LONG2CHARS( 0x0000FFFFFFFFF800 ),
+               LONG2CHARS( 0x0000FFFFFFFFFC00 ),
+               LONG2CHARS( 0x0000FFFFFFFFFE00 ),
+               LONG2CHARS( 0x0000FFFFFFFFFF00 ),
+               LONG2CHARS( 0x0000FFFFFFFFFF80 ),
+               LONG2CHARS( 0x0000FFFFFFFFFFC0 ),
+               LONG2CHARS( 0x0000FFFFFFFFFFE0 ),
+               LONG2CHARS( 0x0000FFFFFFFFFFF0 ),
+               LONG2CHARS( 0x0000FFFFFFFFFFF8 ),
+               LONG2CHARS( 0x0000FFFFFFFFFFFC ),
+               LONG2CHARS( 0x0000FFFFFFFFFFFE ),
+               LONG2CHARS( 0x0000FFFFFFFFFFFF ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+       },
+       {
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000400000000000 ),
+               LONG2CHARS( 0x0000600000000000 ),
+               LONG2CHARS( 0x0000700000000000 ),
+               LONG2CHARS( 0x0000780000000000 ),
+               LONG2CHARS( 0x00007C0000000000 ),
+               LONG2CHARS( 0x00007E0000000000 ),
+               LONG2CHARS( 0x00007F0000000000 ),
+               LONG2CHARS( 0x00007F8000000000 ),
+               LONG2CHARS( 0x00007FC000000000 ),
+               LONG2CHARS( 0x00007FE000000000 ),
+               LONG2CHARS( 0x00007FF000000000 ),
+               LONG2CHARS( 0x00007FF800000000 ),
+               LONG2CHARS( 0x00007FFC00000000 ),
+               LONG2CHARS( 0x00007FFE00000000 ),
+               LONG2CHARS( 0x00007FFF00000000 ),
+               LONG2CHARS( 0x00007FFF80000000 ),
+               LONG2CHARS( 0x00007FFFC0000000 ),
+               LONG2CHARS( 0x00007FFFE0000000 ),
+               LONG2CHARS( 0x00007FFFF0000000 ),
+               LONG2CHARS( 0x00007FFFF8000000 ),
+               LONG2CHARS( 0x00007FFFFC000000 ),
+               LONG2CHARS( 0x00007FFFFE000000 ),
+               LONG2CHARS( 0x00007FFFFF000000 ),
+               LONG2CHARS( 0x00007FFFFF800000 ),
+               LONG2CHARS( 0x00007FFFFFC00000 ),
+               LONG2CHARS( 0x00007FFFFFE00000 ),
+               LONG2CHARS( 0x00007FFFFFF00000 ),
+               LONG2CHARS( 0x00007FFFFFF80000 ),
+               LONG2CHARS( 0x00007FFFFFFC0000 ),
+               LONG2CHARS( 0x00007FFFFFFE0000 ),
+               LONG2CHARS( 0x00007FFFFFFF0000 ),
+               LONG2CHARS( 0x00007FFFFFFF8000 ),
+               LONG2CHARS( 0x00007FFFFFFFC000 ),
+               LONG2CHARS( 0x00007FFFFFFFE000 ),
+               LONG2CHARS( 0x00007FFFFFFFF000 ),
+               LONG2CHARS( 0x00007FFFFFFFF800 ),
+               LONG2CHARS( 0x00007FFFFFFFFC00 ),
+               LONG2CHARS( 0x00007FFFFFFFFE00 ),
+               LONG2CHARS( 0x00007FFFFFFFFF00 ),
+               LONG2CHARS( 0x00007FFFFFFFFF80 ),
+               LONG2CHARS( 0x00007FFFFFFFFFC0 ),
+               LONG2CHARS( 0x00007FFFFFFFFFE0 ),
+               LONG2CHARS( 0x00007FFFFFFFFFF0 ),
+               LONG2CHARS( 0x00007FFFFFFFFFF8 ),
+               LONG2CHARS( 0x00007FFFFFFFFFFC ),
+               LONG2CHARS( 0x00007FFFFFFFFFFE ),
+               LONG2CHARS( 0x00007FFFFFFFFFFF ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+       },
+       {
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000200000000000 ),
+               LONG2CHARS( 0x0000300000000000 ),
+               LONG2CHARS( 0x0000380000000000 ),
+               LONG2CHARS( 0x00003C0000000000 ),
+               LONG2CHARS( 0x00003E0000000000 ),
+               LONG2CHARS( 0x00003F0000000000 ),
+               LONG2CHARS( 0x00003F8000000000 ),
+               LONG2CHARS( 0x00003FC000000000 ),
+               LONG2CHARS( 0x00003FE000000000 ),
+               LONG2CHARS( 0x00003FF000000000 ),
+               LONG2CHARS( 0x00003FF800000000 ),
+               LONG2CHARS( 0x00003FFC00000000 ),
+               LONG2CHARS( 0x00003FFE00000000 ),
+               LONG2CHARS( 0x00003FFF00000000 ),
+               LONG2CHARS( 0x00003FFF80000000 ),
+               LONG2CHARS( 0x00003FFFC0000000 ),
+               LONG2CHARS( 0x00003FFFE0000000 ),
+               LONG2CHARS( 0x00003FFFF0000000 ),
+               LONG2CHARS( 0x00003FFFF8000000 ),
+               LONG2CHARS( 0x00003FFFFC000000 ),
+               LONG2CHARS( 0x00003FFFFE000000 ),
+               LONG2CHARS( 0x00003FFFFF000000 ),
+               LONG2CHARS( 0x00003FFFFF800000 ),
+               LONG2CHARS( 0x00003FFFFFC00000 ),
+               LONG2CHARS( 0x00003FFFFFE00000 ),
+               LONG2CHARS( 0x00003FFFFFF00000 ),
+               LONG2CHARS( 0x00003FFFFFF80000 ),
+               LONG2CHARS( 0x00003FFFFFFC0000 ),
+               LONG2CHARS( 0x00003FFFFFFE0000 ),
+               LONG2CHARS( 0x00003FFFFFFF0000 ),
+               LONG2CHARS( 0x00003FFFFFFF8000 ),
+               LONG2CHARS( 0x00003FFFFFFFC000 ),
+               LONG2CHARS( 0x00003FFFFFFFE000 ),
+               LONG2CHARS( 0x00003FFFFFFFF000 ),
+               LONG2CHARS( 0x00003FFFFFFFF800 ),
+               LONG2CHARS( 0x00003FFFFFFFFC00 ),
+               LONG2CHARS( 0x00003FFFFFFFFE00 ),
+               LONG2CHARS( 0x00003FFFFFFFFF00 ),
+               LONG2CHARS( 0x00003FFFFFFFFF80 ),
+               LONG2CHARS( 0x00003FFFFFFFFFC0 ),
+               LONG2CHARS( 0x00003FFFFFFFFFE0 ),
+               LONG2CHARS( 0x00003FFFFFFFFFF0 ),
+               LONG2CHARS( 0x00003FFFFFFFFFF8 ),
+               LONG2CHARS( 0x00003FFFFFFFFFFC ),
+               LONG2CHARS( 0x00003FFFFFFFFFFE ),
+               LONG2CHARS( 0x00003FFFFFFFFFFF ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+       },
+       {
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000100000000000 ),
+               LONG2CHARS( 0x0000180000000000 ),
+               LONG2CHARS( 0x00001C0000000000 ),
+               LONG2CHARS( 0x00001E0000000000 ),
+               LONG2CHARS( 0x00001F0000000000 ),
+               LONG2CHARS( 0x00001F8000000000 ),
+               LONG2CHARS( 0x00001FC000000000 ),
+               LONG2CHARS( 0x00001FE000000000 ),
+               LONG2CHARS( 0x00001FF000000000 ),
+               LONG2CHARS( 0x00001FF800000000 ),
+               LONG2CHARS( 0x00001FFC00000000 ),
+               LONG2CHARS( 0x00001FFE00000000 ),
+               LONG2CHARS( 0x00001FFF00000000 ),
+               LONG2CHARS( 0x00001FFF80000000 ),
+               LONG2CHARS( 0x00001FFFC0000000 ),
+               LONG2CHARS( 0x00001FFFE0000000 ),
+               LONG2CHARS( 0x00001FFFF0000000 ),
+               LONG2CHARS( 0x00001FFFF8000000 ),
+               LONG2CHARS( 0x00001FFFFC000000 ),
+               LONG2CHARS( 0x00001FFFFE000000 ),
+               LONG2CHARS( 0x00001FFFFF000000 ),
+               LONG2CHARS( 0x00001FFFFF800000 ),
+               LONG2CHARS( 0x00001FFFFFC00000 ),
+               LONG2CHARS( 0x00001FFFFFE00000 ),
+               LONG2CHARS( 0x00001FFFFFF00000 ),
+               LONG2CHARS( 0x00001FFFFFF80000 ),
+               LONG2CHARS( 0x00001FFFFFFC0000 ),
+               LONG2CHARS( 0x00001FFFFFFE0000 ),
+               LONG2CHARS( 0x00001FFFFFFF0000 ),
+               LONG2CHARS( 0x00001FFFFFFF8000 ),
+               LONG2CHARS( 0x00001FFFFFFFC000 ),
+               LONG2CHARS( 0x00001FFFFFFFE000 ),
+               LONG2CHARS( 0x00001FFFFFFFF000 ),
+               LONG2CHARS( 0x00001FFFFFFFF800 ),
+               LONG2CHARS( 0x00001FFFFFFFFC00 ),
+               LONG2CHARS( 0x00001FFFFFFFFE00 ),
+               LONG2CHARS( 0x00001FFFFFFFFF00 ),
+               LONG2CHARS( 0x00001FFFFFFFFF80 ),
+               LONG2CHARS( 0x00001FFFFFFFFFC0 ),
+               LONG2CHARS( 0x00001FFFFFFFFFE0 ),
+               LONG2CHARS( 0x00001FFFFFFFFFF0 ),
+               LONG2CHARS( 0x00001FFFFFFFFFF8 ),
+               LONG2CHARS( 0x00001FFFFFFFFFFC ),
+               LONG2CHARS( 0x00001FFFFFFFFFFE ),
+               LONG2CHARS( 0x00001FFFFFFFFFFF ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+       },
+       {
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000080000000000 ),
+               LONG2CHARS( 0x00000C0000000000 ),
+               LONG2CHARS( 0x00000E0000000000 ),
+               LONG2CHARS( 0x00000F0000000000 ),
+               LONG2CHARS( 0x00000F8000000000 ),
+               LONG2CHARS( 0x00000FC000000000 ),
+               LONG2CHARS( 0x00000FE000000000 ),
+               LONG2CHARS( 0x00000FF000000000 ),
+               LONG2CHARS( 0x00000FF800000000 ),
+               LONG2CHARS( 0x00000FFC00000000 ),
+               LONG2CHARS( 0x00000FFE00000000 ),
+               LONG2CHARS( 0x00000FFF00000000 ),
+               LONG2CHARS( 0x00000FFF80000000 ),
+               LONG2CHARS( 0x00000FFFC0000000 ),
+               LONG2CHARS( 0x00000FFFE0000000 ),
+               LONG2CHARS( 0x00000FFFF0000000 ),
+               LONG2CHARS( 0x00000FFFF8000000 ),
+               LONG2CHARS( 0x00000FFFFC000000 ),
+               LONG2CHARS( 0x00000FFFFE000000 ),
+               LONG2CHARS( 0x00000FFFFF000000 ),
+               LONG2CHARS( 0x00000FFFFF800000 ),
+               LONG2CHARS( 0x00000FFFFFC00000 ),
+               LONG2CHARS( 0x00000FFFFFE00000 ),
+               LONG2CHARS( 0x00000FFFFFF00000 ),
+               LONG2CHARS( 0x00000FFFFFF80000 ),
+               LONG2CHARS( 0x00000FFFFFFC0000 ),
+               LONG2CHARS( 0x00000FFFFFFE0000 ),
+               LONG2CHARS( 0x00000FFFFFFF0000 ),
+               LONG2CHARS( 0x00000FFFFFFF8000 ),
+               LONG2CHARS( 0x00000FFFFFFFC000 ),
+               LONG2CHARS( 0x00000FFFFFFFE000 ),
+               LONG2CHARS( 0x00000FFFFFFFF000 ),
+               LONG2CHARS( 0x00000FFFFFFFF800 ),
+               LONG2CHARS( 0x00000FFFFFFFFC00 ),
+               LONG2CHARS( 0x00000FFFFFFFFE00 ),
+               LONG2CHARS( 0x00000FFFFFFFFF00 ),
+               LONG2CHARS( 0x00000FFFFFFFFF80 ),
+               LONG2CHARS( 0x00000FFFFFFFFFC0 ),
+               LONG2CHARS( 0x00000FFFFFFFFFE0 ),
+               LONG2CHARS( 0x00000FFFFFFFFFF0 ),
+               LONG2CHARS( 0x00000FFFFFFFFFF8 ),
+               LONG2CHARS( 0x00000FFFFFFFFFFC ),
+               LONG2CHARS( 0x00000FFFFFFFFFFE ),
+               LONG2CHARS( 0x00000FFFFFFFFFFF ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+       },
+       {
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000040000000000 ),
+               LONG2CHARS( 0x0000060000000000 ),
+               LONG2CHARS( 0x0000070000000000 ),
+               LONG2CHARS( 0x0000078000000000 ),
+               LONG2CHARS( 0x000007C000000000 ),
+               LONG2CHARS( 0x000007E000000000 ),
+               LONG2CHARS( 0x000007F000000000 ),
+               LONG2CHARS( 0x000007F800000000 ),
+               LONG2CHARS( 0x000007FC00000000 ),
+               LONG2CHARS( 0x000007FE00000000 ),
+               LONG2CHARS( 0x000007FF00000000 ),
+               LONG2CHARS( 0x000007FF80000000 ),
+               LONG2CHARS( 0x000007FFC0000000 ),
+               LONG2CHARS( 0x000007FFE0000000 ),
+               LONG2CHARS( 0x000007FFF0000000 ),
+               LONG2CHARS( 0x000007FFF8000000 ),
+               LONG2CHARS( 0x000007FFFC000000 ),
+               LONG2CHARS( 0x000007FFFE000000 ),
+               LONG2CHARS( 0x000007FFFF000000 ),
+               LONG2CHARS( 0x000007FFFF800000 ),
+               LONG2CHARS( 0x000007FFFFC00000 ),
+               LONG2CHARS( 0x000007FFFFE00000 ),
+               LONG2CHARS( 0x000007FFFFF00000 ),
+               LONG2CHARS( 0x000007FFFFF80000 ),
+               LONG2CHARS( 0x000007FFFFFC0000 ),
+               LONG2CHARS( 0x000007FFFFFE0000 ),
+               LONG2CHARS( 0x000007FFFFFF0000 ),
+               LONG2CHARS( 0x000007FFFFFF8000 ),
+               LONG2CHARS( 0x000007FFFFFFC000 ),
+               LONG2CHARS( 0x000007FFFFFFE000 ),
+               LONG2CHARS( 0x000007FFFFFFF000 ),
+               LONG2CHARS( 0x000007FFFFFFF800 ),
+               LONG2CHARS( 0x000007FFFFFFFC00 ),
+               LONG2CHARS( 0x000007FFFFFFFE00 ),
+               LONG2CHARS( 0x000007FFFFFFFF00 ),
+               LONG2CHARS( 0x000007FFFFFFFF80 ),
+               LONG2CHARS( 0x000007FFFFFFFFC0 ),
+               LONG2CHARS( 0x000007FFFFFFFFE0 ),
+               LONG2CHARS( 0x000007FFFFFFFFF0 ),
+               LONG2CHARS( 0x000007FFFFFFFFF8 ),
+               LONG2CHARS( 0x000007FFFFFFFFFC ),
+               LONG2CHARS( 0x000007FFFFFFFFFE ),
+               LONG2CHARS( 0x000007FFFFFFFFFF ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+       },
+       {
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000020000000000 ),
+               LONG2CHARS( 0x0000030000000000 ),
+               LONG2CHARS( 0x0000038000000000 ),
+               LONG2CHARS( 0x000003C000000000 ),
+               LONG2CHARS( 0x000003E000000000 ),
+               LONG2CHARS( 0x000003F000000000 ),
+               LONG2CHARS( 0x000003F800000000 ),
+               LONG2CHARS( 0x000003FC00000000 ),
+               LONG2CHARS( 0x000003FE00000000 ),
+               LONG2CHARS( 0x000003FF00000000 ),
+               LONG2CHARS( 0x000003FF80000000 ),
+               LONG2CHARS( 0x000003FFC0000000 ),
+               LONG2CHARS( 0x000003FFE0000000 ),
+               LONG2CHARS( 0x000003FFF0000000 ),
+               LONG2CHARS( 0x000003FFF8000000 ),
+               LONG2CHARS( 0x000003FFFC000000 ),
+               LONG2CHARS( 0x000003FFFE000000 ),
+               LONG2CHARS( 0x000003FFFF000000 ),
+               LONG2CHARS( 0x000003FFFF800000 ),
+               LONG2CHARS( 0x000003FFFFC00000 ),
+               LONG2CHARS( 0x000003FFFFE00000 ),
+               LONG2CHARS( 0x000003FFFFF00000 ),
+               LONG2CHARS( 0x000003FFFFF80000 ),
+               LONG2CHARS( 0x000003FFFFFC0000 ),
+               LONG2CHARS( 0x000003FFFFFE0000 ),
+               LONG2CHARS( 0x000003FFFFFF0000 ),
+               LONG2CHARS( 0x000003FFFFFF8000 ),
+               LONG2CHARS( 0x000003FFFFFFC000 ),
+               LONG2CHARS( 0x000003FFFFFFE000 ),
+               LONG2CHARS( 0x000003FFFFFFF000 ),
+               LONG2CHARS( 0x000003FFFFFFF800 ),
+               LONG2CHARS( 0x000003FFFFFFFC00 ),
+               LONG2CHARS( 0x000003FFFFFFFE00 ),
+               LONG2CHARS( 0x000003FFFFFFFF00 ),
+               LONG2CHARS( 0x000003FFFFFFFF80 ),
+               LONG2CHARS( 0x000003FFFFFFFFC0 ),
+               LONG2CHARS( 0x000003FFFFFFFFE0 ),
+               LONG2CHARS( 0x000003FFFFFFFFF0 ),
+               LONG2CHARS( 0x000003FFFFFFFFF8 ),
+               LONG2CHARS( 0x000003FFFFFFFFFC ),
+               LONG2CHARS( 0x000003FFFFFFFFFE ),
+               LONG2CHARS( 0x000003FFFFFFFFFF ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+       },
+       {
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000010000000000 ),
+               LONG2CHARS( 0x0000018000000000 ),
+               LONG2CHARS( 0x000001C000000000 ),
+               LONG2CHARS( 0x000001E000000000 ),
+               LONG2CHARS( 0x000001F000000000 ),
+               LONG2CHARS( 0x000001F800000000 ),
+               LONG2CHARS( 0x000001FC00000000 ),
+               LONG2CHARS( 0x000001FE00000000 ),
+               LONG2CHARS( 0x000001FF00000000 ),
+               LONG2CHARS( 0x000001FF80000000 ),
+               LONG2CHARS( 0x000001FFC0000000 ),
+               LONG2CHARS( 0x000001FFE0000000 ),
+               LONG2CHARS( 0x000001FFF0000000 ),
+               LONG2CHARS( 0x000001FFF8000000 ),
+               LONG2CHARS( 0x000001FFFC000000 ),
+               LONG2CHARS( 0x000001FFFE000000 ),
+               LONG2CHARS( 0x000001FFFF000000 ),
+               LONG2CHARS( 0x000001FFFF800000 ),
+               LONG2CHARS( 0x000001FFFFC00000 ),
+               LONG2CHARS( 0x000001FFFFE00000 ),
+               LONG2CHARS( 0x000001FFFFF00000 ),
+               LONG2CHARS( 0x000001FFFFF80000 ),
+               LONG2CHARS( 0x000001FFFFFC0000 ),
+               LONG2CHARS( 0x000001FFFFFE0000 ),
+               LONG2CHARS( 0x000001FFFFFF0000 ),
+               LONG2CHARS( 0x000001FFFFFF8000 ),
+               LONG2CHARS( 0x000001FFFFFFC000 ),
+               LONG2CHARS( 0x000001FFFFFFE000 ),
+               LONG2CHARS( 0x000001FFFFFFF000 ),
+               LONG2CHARS( 0x000001FFFFFFF800 ),
+               LONG2CHARS( 0x000001FFFFFFFC00 ),
+               LONG2CHARS( 0x000001FFFFFFFE00 ),
+               LONG2CHARS( 0x000001FFFFFFFF00 ),
+               LONG2CHARS( 0x000001FFFFFFFF80 ),
+               LONG2CHARS( 0x000001FFFFFFFFC0 ),
+               LONG2CHARS( 0x000001FFFFFFFFE0 ),
+               LONG2CHARS( 0x000001FFFFFFFFF0 ),
+               LONG2CHARS( 0x000001FFFFFFFFF8 ),
+               LONG2CHARS( 0x000001FFFFFFFFFC ),
+               LONG2CHARS( 0x000001FFFFFFFFFE ),
+               LONG2CHARS( 0x000001FFFFFFFFFF ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+       },
+       {
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000008000000000 ),
+               LONG2CHARS( 0x000000C000000000 ),
+               LONG2CHARS( 0x000000E000000000 ),
+               LONG2CHARS( 0x000000F000000000 ),
+               LONG2CHARS( 0x000000F800000000 ),
+               LONG2CHARS( 0x000000FC00000000 ),
+               LONG2CHARS( 0x000000FE00000000 ),
+               LONG2CHARS( 0x000000FF00000000 ),
+               LONG2CHARS( 0x000000FF80000000 ),
+               LONG2CHARS( 0x000000FFC0000000 ),
+               LONG2CHARS( 0x000000FFE0000000 ),
+               LONG2CHARS( 0x000000FFF0000000 ),
+               LONG2CHARS( 0x000000FFF8000000 ),
+               LONG2CHARS( 0x000000FFFC000000 ),
+               LONG2CHARS( 0x000000FFFE000000 ),
+               LONG2CHARS( 0x000000FFFF000000 ),
+               LONG2CHARS( 0x000000FFFF800000 ),
+               LONG2CHARS( 0x000000FFFFC00000 ),
+               LONG2CHARS( 0x000000FFFFE00000 ),
+               LONG2CHARS( 0x000000FFFFF00000 ),
+               LONG2CHARS( 0x000000FFFFF80000 ),
+               LONG2CHARS( 0x000000FFFFFC0000 ),
+               LONG2CHARS( 0x000000FFFFFE0000 ),
+               LONG2CHARS( 0x000000FFFFFF0000 ),
+               LONG2CHARS( 0x000000FFFFFF8000 ),
+               LONG2CHARS( 0x000000FFFFFFC000 ),
+               LONG2CHARS( 0x000000FFFFFFE000 ),
+               LONG2CHARS( 0x000000FFFFFFF000 ),
+               LONG2CHARS( 0x000000FFFFFFF800 ),
+               LONG2CHARS( 0x000000FFFFFFFC00 ),
+               LONG2CHARS( 0x000000FFFFFFFE00 ),
+               LONG2CHARS( 0x000000FFFFFFFF00 ),
+               LONG2CHARS( 0x000000FFFFFFFF80 ),
+               LONG2CHARS( 0x000000FFFFFFFFC0 ),
+               LONG2CHARS( 0x000000FFFFFFFFE0 ),
+               LONG2CHARS( 0x000000FFFFFFFFF0 ),
+               LONG2CHARS( 0x000000FFFFFFFFF8 ),
+               LONG2CHARS( 0x000000FFFFFFFFFC ),
+               LONG2CHARS( 0x000000FFFFFFFFFE ),
+               LONG2CHARS( 0x000000FFFFFFFFFF ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+       },
+       {
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000004000000000 ),
+               LONG2CHARS( 0x0000006000000000 ),
+               LONG2CHARS( 0x0000007000000000 ),
+               LONG2CHARS( 0x0000007800000000 ),
+               LONG2CHARS( 0x0000007C00000000 ),
+               LONG2CHARS( 0x0000007E00000000 ),
+               LONG2CHARS( 0x0000007F00000000 ),
+               LONG2CHARS( 0x0000007F80000000 ),
+               LONG2CHARS( 0x0000007FC0000000 ),
+               LONG2CHARS( 0x0000007FE0000000 ),
+               LONG2CHARS( 0x0000007FF0000000 ),
+               LONG2CHARS( 0x0000007FF8000000 ),
+               LONG2CHARS( 0x0000007FFC000000 ),
+               LONG2CHARS( 0x0000007FFE000000 ),
+               LONG2CHARS( 0x0000007FFF000000 ),
+               LONG2CHARS( 0x0000007FFF800000 ),
+               LONG2CHARS( 0x0000007FFFC00000 ),
+               LONG2CHARS( 0x0000007FFFE00000 ),
+               LONG2CHARS( 0x0000007FFFF00000 ),
+               LONG2CHARS( 0x0000007FFFF80000 ),
+               LONG2CHARS( 0x0000007FFFFC0000 ),
+               LONG2CHARS( 0x0000007FFFFE0000 ),
+               LONG2CHARS( 0x0000007FFFFF0000 ),
+               LONG2CHARS( 0x0000007FFFFF8000 ),
+               LONG2CHARS( 0x0000007FFFFFC000 ),
+               LONG2CHARS( 0x0000007FFFFFE000 ),
+               LONG2CHARS( 0x0000007FFFFFF000 ),
+               LONG2CHARS( 0x0000007FFFFFF800 ),
+               LONG2CHARS( 0x0000007FFFFFFC00 ),
+               LONG2CHARS( 0x0000007FFFFFFE00 ),
+               LONG2CHARS( 0x0000007FFFFFFF00 ),
+               LONG2CHARS( 0x0000007FFFFFFF80 ),
+               LONG2CHARS( 0x0000007FFFFFFFC0 ),
+               LONG2CHARS( 0x0000007FFFFFFFE0 ),
+               LONG2CHARS( 0x0000007FFFFFFFF0 ),
+               LONG2CHARS( 0x0000007FFFFFFFF8 ),
+               LONG2CHARS( 0x0000007FFFFFFFFC ),
+               LONG2CHARS( 0x0000007FFFFFFFFE ),
+               LONG2CHARS( 0x0000007FFFFFFFFF ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+       },
+       {
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000002000000000 ),
+               LONG2CHARS( 0x0000003000000000 ),
+               LONG2CHARS( 0x0000003800000000 ),
+               LONG2CHARS( 0x0000003C00000000 ),
+               LONG2CHARS( 0x0000003E00000000 ),
+               LONG2CHARS( 0x0000003F00000000 ),
+               LONG2CHARS( 0x0000003F80000000 ),
+               LONG2CHARS( 0x0000003FC0000000 ),
+               LONG2CHARS( 0x0000003FE0000000 ),
+               LONG2CHARS( 0x0000003FF0000000 ),
+               LONG2CHARS( 0x0000003FF8000000 ),
+               LONG2CHARS( 0x0000003FFC000000 ),
+               LONG2CHARS( 0x0000003FFE000000 ),
+               LONG2CHARS( 0x0000003FFF000000 ),
+               LONG2CHARS( 0x0000003FFF800000 ),
+               LONG2CHARS( 0x0000003FFFC00000 ),
+               LONG2CHARS( 0x0000003FFFE00000 ),
+               LONG2CHARS( 0x0000003FFFF00000 ),
+               LONG2CHARS( 0x0000003FFFF80000 ),
+               LONG2CHARS( 0x0000003FFFFC0000 ),
+               LONG2CHARS( 0x0000003FFFFE0000 ),
+               LONG2CHARS( 0x0000003FFFFF0000 ),
+               LONG2CHARS( 0x0000003FFFFF8000 ),
+               LONG2CHARS( 0x0000003FFFFFC000 ),
+               LONG2CHARS( 0x0000003FFFFFE000 ),
+               LONG2CHARS( 0x0000003FFFFFF000 ),
+               LONG2CHARS( 0x0000003FFFFFF800 ),
+               LONG2CHARS( 0x0000003FFFFFFC00 ),
+               LONG2CHARS( 0x0000003FFFFFFE00 ),
+               LONG2CHARS( 0x0000003FFFFFFF00 ),
+               LONG2CHARS( 0x0000003FFFFFFF80 ),
+               LONG2CHARS( 0x0000003FFFFFFFC0 ),
+               LONG2CHARS( 0x0000003FFFFFFFE0 ),
+               LONG2CHARS( 0x0000003FFFFFFFF0 ),
+               LONG2CHARS( 0x0000003FFFFFFFF8 ),
+               LONG2CHARS( 0x0000003FFFFFFFFC ),
+               LONG2CHARS( 0x0000003FFFFFFFFE ),
+               LONG2CHARS( 0x0000003FFFFFFFFF ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+       },
+       {
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000001000000000 ),
+               LONG2CHARS( 0x0000001800000000 ),
+               LONG2CHARS( 0x0000001C00000000 ),
+               LONG2CHARS( 0x0000001E00000000 ),
+               LONG2CHARS( 0x0000001F00000000 ),
+               LONG2CHARS( 0x0000001F80000000 ),
+               LONG2CHARS( 0x0000001FC0000000 ),
+               LONG2CHARS( 0x0000001FE0000000 ),
+               LONG2CHARS( 0x0000001FF0000000 ),
+               LONG2CHARS( 0x0000001FF8000000 ),
+               LONG2CHARS( 0x0000001FFC000000 ),
+               LONG2CHARS( 0x0000001FFE000000 ),
+               LONG2CHARS( 0x0000001FFF000000 ),
+               LONG2CHARS( 0x0000001FFF800000 ),
+               LONG2CHARS( 0x0000001FFFC00000 ),
+               LONG2CHARS( 0x0000001FFFE00000 ),
+               LONG2CHARS( 0x0000001FFFF00000 ),
+               LONG2CHARS( 0x0000001FFFF80000 ),
+               LONG2CHARS( 0x0000001FFFFC0000 ),
+               LONG2CHARS( 0x0000001FFFFE0000 ),
+               LONG2CHARS( 0x0000001FFFFF0000 ),
+               LONG2CHARS( 0x0000001FFFFF8000 ),
+               LONG2CHARS( 0x0000001FFFFFC000 ),
+               LONG2CHARS( 0x0000001FFFFFE000 ),
+               LONG2CHARS( 0x0000001FFFFFF000 ),
+               LONG2CHARS( 0x0000001FFFFFF800 ),
+               LONG2CHARS( 0x0000001FFFFFFC00 ),
+               LONG2CHARS( 0x0000001FFFFFFE00 ),
+               LONG2CHARS( 0x0000001FFFFFFF00 ),
+               LONG2CHARS( 0x0000001FFFFFFF80 ),
+               LONG2CHARS( 0x0000001FFFFFFFC0 ),
+               LONG2CHARS( 0x0000001FFFFFFFE0 ),
+               LONG2CHARS( 0x0000001FFFFFFFF0 ),
+               LONG2CHARS( 0x0000001FFFFFFFF8 ),
+               LONG2CHARS( 0x0000001FFFFFFFFC ),
+               LONG2CHARS( 0x0000001FFFFFFFFE ),
+               LONG2CHARS( 0x0000001FFFFFFFFF ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+       },
+       {
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000800000000 ),
+               LONG2CHARS( 0x0000000C00000000 ),
+               LONG2CHARS( 0x0000000E00000000 ),
+               LONG2CHARS( 0x0000000F00000000 ),
+               LONG2CHARS( 0x0000000F80000000 ),
+               LONG2CHARS( 0x0000000FC0000000 ),
+               LONG2CHARS( 0x0000000FE0000000 ),
+               LONG2CHARS( 0x0000000FF0000000 ),
+               LONG2CHARS( 0x0000000FF8000000 ),
+               LONG2CHARS( 0x0000000FFC000000 ),
+               LONG2CHARS( 0x0000000FFE000000 ),
+               LONG2CHARS( 0x0000000FFF000000 ),
+               LONG2CHARS( 0x0000000FFF800000 ),
+               LONG2CHARS( 0x0000000FFFC00000 ),
+               LONG2CHARS( 0x0000000FFFE00000 ),
+               LONG2CHARS( 0x0000000FFFF00000 ),
+               LONG2CHARS( 0x0000000FFFF80000 ),
+               LONG2CHARS( 0x0000000FFFFC0000 ),
+               LONG2CHARS( 0x0000000FFFFE0000 ),
+               LONG2CHARS( 0x0000000FFFFF0000 ),
+               LONG2CHARS( 0x0000000FFFFF8000 ),
+               LONG2CHARS( 0x0000000FFFFFC000 ),
+               LONG2CHARS( 0x0000000FFFFFE000 ),
+               LONG2CHARS( 0x0000000FFFFFF000 ),
+               LONG2CHARS( 0x0000000FFFFFF800 ),
+               LONG2CHARS( 0x0000000FFFFFFC00 ),
+               LONG2CHARS( 0x0000000FFFFFFE00 ),
+               LONG2CHARS( 0x0000000FFFFFFF00 ),
+               LONG2CHARS( 0x0000000FFFFFFF80 ),
+               LONG2CHARS( 0x0000000FFFFFFFC0 ),
+               LONG2CHARS( 0x0000000FFFFFFFE0 ),
+               LONG2CHARS( 0x0000000FFFFFFFF0 ),
+               LONG2CHARS( 0x0000000FFFFFFFF8 ),
+               LONG2CHARS( 0x0000000FFFFFFFFC ),
+               LONG2CHARS( 0x0000000FFFFFFFFE ),
+               LONG2CHARS( 0x0000000FFFFFFFFF ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+       },
+       {
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000400000000 ),
+               LONG2CHARS( 0x0000000600000000 ),
+               LONG2CHARS( 0x0000000700000000 ),
+               LONG2CHARS( 0x0000000780000000 ),
+               LONG2CHARS( 0x00000007C0000000 ),
+               LONG2CHARS( 0x00000007E0000000 ),
+               LONG2CHARS( 0x00000007F0000000 ),
+               LONG2CHARS( 0x00000007F8000000 ),
+               LONG2CHARS( 0x00000007FC000000 ),
+               LONG2CHARS( 0x00000007FE000000 ),
+               LONG2CHARS( 0x00000007FF000000 ),
+               LONG2CHARS( 0x00000007FF800000 ),
+               LONG2CHARS( 0x00000007FFC00000 ),
+               LONG2CHARS( 0x00000007FFE00000 ),
+               LONG2CHARS( 0x00000007FFF00000 ),
+               LONG2CHARS( 0x00000007FFF80000 ),
+               LONG2CHARS( 0x00000007FFFC0000 ),
+               LONG2CHARS( 0x00000007FFFE0000 ),
+               LONG2CHARS( 0x00000007FFFF0000 ),
+               LONG2CHARS( 0x00000007FFFF8000 ),
+               LONG2CHARS( 0x00000007FFFFC000 ),
+               LONG2CHARS( 0x00000007FFFFE000 ),
+               LONG2CHARS( 0x00000007FFFFF000 ),
+               LONG2CHARS( 0x00000007FFFFF800 ),
+               LONG2CHARS( 0x00000007FFFFFC00 ),
+               LONG2CHARS( 0x00000007FFFFFE00 ),
+               LONG2CHARS( 0x00000007FFFFFF00 ),
+               LONG2CHARS( 0x00000007FFFFFF80 ),
+               LONG2CHARS( 0x00000007FFFFFFC0 ),
+               LONG2CHARS( 0x00000007FFFFFFE0 ),
+               LONG2CHARS( 0x00000007FFFFFFF0 ),
+               LONG2CHARS( 0x00000007FFFFFFF8 ),
+               LONG2CHARS( 0x00000007FFFFFFFC ),
+               LONG2CHARS( 0x00000007FFFFFFFE ),
+               LONG2CHARS( 0x00000007FFFFFFFF ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+       },
+       {
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000200000000 ),
+               LONG2CHARS( 0x0000000300000000 ),
+               LONG2CHARS( 0x0000000380000000 ),
+               LONG2CHARS( 0x00000003C0000000 ),
+               LONG2CHARS( 0x00000003E0000000 ),
+               LONG2CHARS( 0x00000003F0000000 ),
+               LONG2CHARS( 0x00000003F8000000 ),
+               LONG2CHARS( 0x00000003FC000000 ),
+               LONG2CHARS( 0x00000003FE000000 ),
+               LONG2CHARS( 0x00000003FF000000 ),
+               LONG2CHARS( 0x00000003FF800000 ),
+               LONG2CHARS( 0x00000003FFC00000 ),
+               LONG2CHARS( 0x00000003FFE00000 ),
+               LONG2CHARS( 0x00000003FFF00000 ),
+               LONG2CHARS( 0x00000003FFF80000 ),
+               LONG2CHARS( 0x00000003FFFC0000 ),
+               LONG2CHARS( 0x00000003FFFE0000 ),
+               LONG2CHARS( 0x00000003FFFF0000 ),
+               LONG2CHARS( 0x00000003FFFF8000 ),
+               LONG2CHARS( 0x00000003FFFFC000 ),
+               LONG2CHARS( 0x00000003FFFFE000 ),
+               LONG2CHARS( 0x00000003FFFFF000 ),
+               LONG2CHARS( 0x00000003FFFFF800 ),
+               LONG2CHARS( 0x00000003FFFFFC00 ),
+               LONG2CHARS( 0x00000003FFFFFE00 ),
+               LONG2CHARS( 0x00000003FFFFFF00 ),
+               LONG2CHARS( 0x00000003FFFFFF80 ),
+               LONG2CHARS( 0x00000003FFFFFFC0 ),
+               LONG2CHARS( 0x00000003FFFFFFE0 ),
+               LONG2CHARS( 0x00000003FFFFFFF0 ),
+               LONG2CHARS( 0x00000003FFFFFFF8 ),
+               LONG2CHARS( 0x00000003FFFFFFFC ),
+               LONG2CHARS( 0x00000003FFFFFFFE ),
+               LONG2CHARS( 0x00000003FFFFFFFF ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+       },
+       {
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000100000000 ),
+               LONG2CHARS( 0x0000000180000000 ),
+               LONG2CHARS( 0x00000001C0000000 ),
+               LONG2CHARS( 0x00000001E0000000 ),
+               LONG2CHARS( 0x00000001F0000000 ),
+               LONG2CHARS( 0x00000001F8000000 ),
+               LONG2CHARS( 0x00000001FC000000 ),
+               LONG2CHARS( 0x00000001FE000000 ),
+               LONG2CHARS( 0x00000001FF000000 ),
+               LONG2CHARS( 0x00000001FF800000 ),
+               LONG2CHARS( 0x00000001FFC00000 ),
+               LONG2CHARS( 0x00000001FFE00000 ),
+               LONG2CHARS( 0x00000001FFF00000 ),
+               LONG2CHARS( 0x00000001FFF80000 ),
+               LONG2CHARS( 0x00000001FFFC0000 ),
+               LONG2CHARS( 0x00000001FFFE0000 ),
+               LONG2CHARS( 0x00000001FFFF0000 ),
+               LONG2CHARS( 0x00000001FFFF8000 ),
+               LONG2CHARS( 0x00000001FFFFC000 ),
+               LONG2CHARS( 0x00000001FFFFE000 ),
+               LONG2CHARS( 0x00000001FFFFF000 ),
+               LONG2CHARS( 0x00000001FFFFF800 ),
+               LONG2CHARS( 0x00000001FFFFFC00 ),
+               LONG2CHARS( 0x00000001FFFFFE00 ),
+               LONG2CHARS( 0x00000001FFFFFF00 ),
+               LONG2CHARS( 0x00000001FFFFFF80 ),
+               LONG2CHARS( 0x00000001FFFFFFC0 ),
+               LONG2CHARS( 0x00000001FFFFFFE0 ),
+               LONG2CHARS( 0x00000001FFFFFFF0 ),
+               LONG2CHARS( 0x00000001FFFFFFF8 ),
+               LONG2CHARS( 0x00000001FFFFFFFC ),
+               LONG2CHARS( 0x00000001FFFFFFFE ),
+               LONG2CHARS( 0x00000001FFFFFFFF ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+       },
+       {
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000080000000 ),
+               LONG2CHARS( 0x00000000C0000000 ),
+               LONG2CHARS( 0x00000000E0000000 ),
+               LONG2CHARS( 0x00000000F0000000 ),
+               LONG2CHARS( 0x00000000F8000000 ),
+               LONG2CHARS( 0x00000000FC000000 ),
+               LONG2CHARS( 0x00000000FE000000 ),
+               LONG2CHARS( 0x00000000FF000000 ),
+               LONG2CHARS( 0x00000000FF800000 ),
+               LONG2CHARS( 0x00000000FFC00000 ),
+               LONG2CHARS( 0x00000000FFE00000 ),
+               LONG2CHARS( 0x00000000FFF00000 ),
+               LONG2CHARS( 0x00000000FFF80000 ),
+               LONG2CHARS( 0x00000000FFFC0000 ),
+               LONG2CHARS( 0x00000000FFFE0000 ),
+               LONG2CHARS( 0x00000000FFFF0000 ),
+               LONG2CHARS( 0x00000000FFFF8000 ),
+               LONG2CHARS( 0x00000000FFFFC000 ),
+               LONG2CHARS( 0x00000000FFFFE000 ),
+               LONG2CHARS( 0x00000000FFFFF000 ),
+               LONG2CHARS( 0x00000000FFFFF800 ),
+               LONG2CHARS( 0x00000000FFFFFC00 ),
+               LONG2CHARS( 0x00000000FFFFFE00 ),
+               LONG2CHARS( 0x00000000FFFFFF00 ),
+               LONG2CHARS( 0x00000000FFFFFF80 ),
+               LONG2CHARS( 0x00000000FFFFFFC0 ),
+               LONG2CHARS( 0x00000000FFFFFFE0 ),
+               LONG2CHARS( 0x00000000FFFFFFF0 ),
+               LONG2CHARS( 0x00000000FFFFFFF8 ),
+               LONG2CHARS( 0x00000000FFFFFFFC ),
+               LONG2CHARS( 0x00000000FFFFFFFE ),
+               LONG2CHARS( 0x00000000FFFFFFFF ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+       },
+       {
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000040000000 ),
+               LONG2CHARS( 0x0000000060000000 ),
+               LONG2CHARS( 0x0000000070000000 ),
+               LONG2CHARS( 0x0000000078000000 ),
+               LONG2CHARS( 0x000000007C000000 ),
+               LONG2CHARS( 0x000000007E000000 ),
+               LONG2CHARS( 0x000000007F000000 ),
+               LONG2CHARS( 0x000000007F800000 ),
+               LONG2CHARS( 0x000000007FC00000 ),
+               LONG2CHARS( 0x000000007FE00000 ),
+               LONG2CHARS( 0x000000007FF00000 ),
+               LONG2CHARS( 0x000000007FF80000 ),
+               LONG2CHARS( 0x000000007FFC0000 ),
+               LONG2CHARS( 0x000000007FFE0000 ),
+               LONG2CHARS( 0x000000007FFF0000 ),
+               LONG2CHARS( 0x000000007FFF8000 ),
+               LONG2CHARS( 0x000000007FFFC000 ),
+               LONG2CHARS( 0x000000007FFFE000 ),
+               LONG2CHARS( 0x000000007FFFF000 ),
+               LONG2CHARS( 0x000000007FFFF800 ),
+               LONG2CHARS( 0x000000007FFFFC00 ),
+               LONG2CHARS( 0x000000007FFFFE00 ),
+               LONG2CHARS( 0x000000007FFFFF00 ),
+               LONG2CHARS( 0x000000007FFFFF80 ),
+               LONG2CHARS( 0x000000007FFFFFC0 ),
+               LONG2CHARS( 0x000000007FFFFFE0 ),
+               LONG2CHARS( 0x000000007FFFFFF0 ),
+               LONG2CHARS( 0x000000007FFFFFF8 ),
+               LONG2CHARS( 0x000000007FFFFFFC ),
+               LONG2CHARS( 0x000000007FFFFFFE ),
+               LONG2CHARS( 0x000000007FFFFFFF ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+       },
+       {
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000020000000 ),
+               LONG2CHARS( 0x0000000030000000 ),
+               LONG2CHARS( 0x0000000038000000 ),
+               LONG2CHARS( 0x000000003C000000 ),
+               LONG2CHARS( 0x000000003E000000 ),
+               LONG2CHARS( 0x000000003F000000 ),
+               LONG2CHARS( 0x000000003F800000 ),
+               LONG2CHARS( 0x000000003FC00000 ),
+               LONG2CHARS( 0x000000003FE00000 ),
+               LONG2CHARS( 0x000000003FF00000 ),
+               LONG2CHARS( 0x000000003FF80000 ),
+               LONG2CHARS( 0x000000003FFC0000 ),
+               LONG2CHARS( 0x000000003FFE0000 ),
+               LONG2CHARS( 0x000000003FFF0000 ),
+               LONG2CHARS( 0x000000003FFF8000 ),
+               LONG2CHARS( 0x000000003FFFC000 ),
+               LONG2CHARS( 0x000000003FFFE000 ),
+               LONG2CHARS( 0x000000003FFFF000 ),
+               LONG2CHARS( 0x000000003FFFF800 ),
+               LONG2CHARS( 0x000000003FFFFC00 ),
+               LONG2CHARS( 0x000000003FFFFE00 ),
+               LONG2CHARS( 0x000000003FFFFF00 ),
+               LONG2CHARS( 0x000000003FFFFF80 ),
+               LONG2CHARS( 0x000000003FFFFFC0 ),
+               LONG2CHARS( 0x000000003FFFFFE0 ),
+               LONG2CHARS( 0x000000003FFFFFF0 ),
+               LONG2CHARS( 0x000000003FFFFFF8 ),
+               LONG2CHARS( 0x000000003FFFFFFC ),
+               LONG2CHARS( 0x000000003FFFFFFE ),
+               LONG2CHARS( 0x000000003FFFFFFF ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+       },
+       {
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000010000000 ),
+               LONG2CHARS( 0x0000000018000000 ),
+               LONG2CHARS( 0x000000001C000000 ),
+               LONG2CHARS( 0x000000001E000000 ),
+               LONG2CHARS( 0x000000001F000000 ),
+               LONG2CHARS( 0x000000001F800000 ),
+               LONG2CHARS( 0x000000001FC00000 ),
+               LONG2CHARS( 0x000000001FE00000 ),
+               LONG2CHARS( 0x000000001FF00000 ),
+               LONG2CHARS( 0x000000001FF80000 ),
+               LONG2CHARS( 0x000000001FFC0000 ),
+               LONG2CHARS( 0x000000001FFE0000 ),
+               LONG2CHARS( 0x000000001FFF0000 ),
+               LONG2CHARS( 0x000000001FFF8000 ),
+               LONG2CHARS( 0x000000001FFFC000 ),
+               LONG2CHARS( 0x000000001FFFE000 ),
+               LONG2CHARS( 0x000000001FFFF000 ),
+               LONG2CHARS( 0x000000001FFFF800 ),
+               LONG2CHARS( 0x000000001FFFFC00 ),
+               LONG2CHARS( 0x000000001FFFFE00 ),
+               LONG2CHARS( 0x000000001FFFFF00 ),
+               LONG2CHARS( 0x000000001FFFFF80 ),
+               LONG2CHARS( 0x000000001FFFFFC0 ),
+               LONG2CHARS( 0x000000001FFFFFE0 ),
+               LONG2CHARS( 0x000000001FFFFFF0 ),
+               LONG2CHARS( 0x000000001FFFFFF8 ),
+               LONG2CHARS( 0x000000001FFFFFFC ),
+               LONG2CHARS( 0x000000001FFFFFFE ),
+               LONG2CHARS( 0x000000001FFFFFFF ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+       },
+       {
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000008000000 ),
+               LONG2CHARS( 0x000000000C000000 ),
+               LONG2CHARS( 0x000000000E000000 ),
+               LONG2CHARS( 0x000000000F000000 ),
+               LONG2CHARS( 0x000000000F800000 ),
+               LONG2CHARS( 0x000000000FC00000 ),
+               LONG2CHARS( 0x000000000FE00000 ),
+               LONG2CHARS( 0x000000000FF00000 ),
+               LONG2CHARS( 0x000000000FF80000 ),
+               LONG2CHARS( 0x000000000FFC0000 ),
+               LONG2CHARS( 0x000000000FFE0000 ),
+               LONG2CHARS( 0x000000000FFF0000 ),
+               LONG2CHARS( 0x000000000FFF8000 ),
+               LONG2CHARS( 0x000000000FFFC000 ),
+               LONG2CHARS( 0x000000000FFFE000 ),
+               LONG2CHARS( 0x000000000FFFF000 ),
+               LONG2CHARS( 0x000000000FFFF800 ),
+               LONG2CHARS( 0x000000000FFFFC00 ),
+               LONG2CHARS( 0x000000000FFFFE00 ),
+               LONG2CHARS( 0x000000000FFFFF00 ),
+               LONG2CHARS( 0x000000000FFFFF80 ),
+               LONG2CHARS( 0x000000000FFFFFC0 ),
+               LONG2CHARS( 0x000000000FFFFFE0 ),
+               LONG2CHARS( 0x000000000FFFFFF0 ),
+               LONG2CHARS( 0x000000000FFFFFF8 ),
+               LONG2CHARS( 0x000000000FFFFFFC ),
+               LONG2CHARS( 0x000000000FFFFFFE ),
+               LONG2CHARS( 0x000000000FFFFFFF ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+       },
+       {
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000004000000 ),
+               LONG2CHARS( 0x0000000006000000 ),
+               LONG2CHARS( 0x0000000007000000 ),
+               LONG2CHARS( 0x0000000007800000 ),
+               LONG2CHARS( 0x0000000007C00000 ),
+               LONG2CHARS( 0x0000000007E00000 ),
+               LONG2CHARS( 0x0000000007F00000 ),
+               LONG2CHARS( 0x0000000007F80000 ),
+               LONG2CHARS( 0x0000000007FC0000 ),
+               LONG2CHARS( 0x0000000007FE0000 ),
+               LONG2CHARS( 0x0000000007FF0000 ),
+               LONG2CHARS( 0x0000000007FF8000 ),
+               LONG2CHARS( 0x0000000007FFC000 ),
+               LONG2CHARS( 0x0000000007FFE000 ),
+               LONG2CHARS( 0x0000000007FFF000 ),
+               LONG2CHARS( 0x0000000007FFF800 ),
+               LONG2CHARS( 0x0000000007FFFC00 ),
+               LONG2CHARS( 0x0000000007FFFE00 ),
+               LONG2CHARS( 0x0000000007FFFF00 ),
+               LONG2CHARS( 0x0000000007FFFF80 ),
+               LONG2CHARS( 0x0000000007FFFFC0 ),
+               LONG2CHARS( 0x0000000007FFFFE0 ),
+               LONG2CHARS( 0x0000000007FFFFF0 ),
+               LONG2CHARS( 0x0000000007FFFFF8 ),
+               LONG2CHARS( 0x0000000007FFFFFC ),
+               LONG2CHARS( 0x0000000007FFFFFE ),
+               LONG2CHARS( 0x0000000007FFFFFF ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+       },
+       {
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000002000000 ),
+               LONG2CHARS( 0x0000000003000000 ),
+               LONG2CHARS( 0x0000000003800000 ),
+               LONG2CHARS( 0x0000000003C00000 ),
+               LONG2CHARS( 0x0000000003E00000 ),
+               LONG2CHARS( 0x0000000003F00000 ),
+               LONG2CHARS( 0x0000000003F80000 ),
+               LONG2CHARS( 0x0000000003FC0000 ),
+               LONG2CHARS( 0x0000000003FE0000 ),
+               LONG2CHARS( 0x0000000003FF0000 ),
+               LONG2CHARS( 0x0000000003FF8000 ),
+               LONG2CHARS( 0x0000000003FFC000 ),
+               LONG2CHARS( 0x0000000003FFE000 ),
+               LONG2CHARS( 0x0000000003FFF000 ),
+               LONG2CHARS( 0x0000000003FFF800 ),
+               LONG2CHARS( 0x0000000003FFFC00 ),
+               LONG2CHARS( 0x0000000003FFFE00 ),
+               LONG2CHARS( 0x0000000003FFFF00 ),
+               LONG2CHARS( 0x0000000003FFFF80 ),
+               LONG2CHARS( 0x0000000003FFFFC0 ),
+               LONG2CHARS( 0x0000000003FFFFE0 ),
+               LONG2CHARS( 0x0000000003FFFFF0 ),
+               LONG2CHARS( 0x0000000003FFFFF8 ),
+               LONG2CHARS( 0x0000000003FFFFFC ),
+               LONG2CHARS( 0x0000000003FFFFFE ),
+               LONG2CHARS( 0x0000000003FFFFFF ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+       },
+       {
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000001000000 ),
+               LONG2CHARS( 0x0000000001800000 ),
+               LONG2CHARS( 0x0000000001C00000 ),
+               LONG2CHARS( 0x0000000001E00000 ),
+               LONG2CHARS( 0x0000000001F00000 ),
+               LONG2CHARS( 0x0000000001F80000 ),
+               LONG2CHARS( 0x0000000001FC0000 ),
+               LONG2CHARS( 0x0000000001FE0000 ),
+               LONG2CHARS( 0x0000000001FF0000 ),
+               LONG2CHARS( 0x0000000001FF8000 ),
+               LONG2CHARS( 0x0000000001FFC000 ),
+               LONG2CHARS( 0x0000000001FFE000 ),
+               LONG2CHARS( 0x0000000001FFF000 ),
+               LONG2CHARS( 0x0000000001FFF800 ),
+               LONG2CHARS( 0x0000000001FFFC00 ),
+               LONG2CHARS( 0x0000000001FFFE00 ),
+               LONG2CHARS( 0x0000000001FFFF00 ),
+               LONG2CHARS( 0x0000000001FFFF80 ),
+               LONG2CHARS( 0x0000000001FFFFC0 ),
+               LONG2CHARS( 0x0000000001FFFFE0 ),
+               LONG2CHARS( 0x0000000001FFFFF0 ),
+               LONG2CHARS( 0x0000000001FFFFF8 ),
+               LONG2CHARS( 0x0000000001FFFFFC ),
+               LONG2CHARS( 0x0000000001FFFFFE ),
+               LONG2CHARS( 0x0000000001FFFFFF ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+       },
+       {
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000800000 ),
+               LONG2CHARS( 0x0000000000C00000 ),
+               LONG2CHARS( 0x0000000000E00000 ),
+               LONG2CHARS( 0x0000000000F00000 ),
+               LONG2CHARS( 0x0000000000F80000 ),
+               LONG2CHARS( 0x0000000000FC0000 ),
+               LONG2CHARS( 0x0000000000FE0000 ),
+               LONG2CHARS( 0x0000000000FF0000 ),
+               LONG2CHARS( 0x0000000000FF8000 ),
+               LONG2CHARS( 0x0000000000FFC000 ),
+               LONG2CHARS( 0x0000000000FFE000 ),
+               LONG2CHARS( 0x0000000000FFF000 ),
+               LONG2CHARS( 0x0000000000FFF800 ),
+               LONG2CHARS( 0x0000000000FFFC00 ),
+               LONG2CHARS( 0x0000000000FFFE00 ),
+               LONG2CHARS( 0x0000000000FFFF00 ),
+               LONG2CHARS( 0x0000000000FFFF80 ),
+               LONG2CHARS( 0x0000000000FFFFC0 ),
+               LONG2CHARS( 0x0000000000FFFFE0 ),
+               LONG2CHARS( 0x0000000000FFFFF0 ),
+               LONG2CHARS( 0x0000000000FFFFF8 ),
+               LONG2CHARS( 0x0000000000FFFFFC ),
+               LONG2CHARS( 0x0000000000FFFFFE ),
+               LONG2CHARS( 0x0000000000FFFFFF ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+       },
+       {
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000400000 ),
+               LONG2CHARS( 0x0000000000600000 ),
+               LONG2CHARS( 0x0000000000700000 ),
+               LONG2CHARS( 0x0000000000780000 ),
+               LONG2CHARS( 0x00000000007C0000 ),
+               LONG2CHARS( 0x00000000007E0000 ),
+               LONG2CHARS( 0x00000000007F0000 ),
+               LONG2CHARS( 0x00000000007F8000 ),
+               LONG2CHARS( 0x00000000007FC000 ),
+               LONG2CHARS( 0x00000000007FE000 ),
+               LONG2CHARS( 0x00000000007FF000 ),
+               LONG2CHARS( 0x00000000007FF800 ),
+               LONG2CHARS( 0x00000000007FFC00 ),
+               LONG2CHARS( 0x00000000007FFE00 ),
+               LONG2CHARS( 0x00000000007FFF00 ),
+               LONG2CHARS( 0x00000000007FFF80 ),
+               LONG2CHARS( 0x00000000007FFFC0 ),
+               LONG2CHARS( 0x00000000007FFFE0 ),
+               LONG2CHARS( 0x00000000007FFFF0 ),
+               LONG2CHARS( 0x00000000007FFFF8 ),
+               LONG2CHARS( 0x00000000007FFFFC ),
+               LONG2CHARS( 0x00000000007FFFFE ),
+               LONG2CHARS( 0x00000000007FFFFF ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+       },
+       {
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000200000 ),
+               LONG2CHARS( 0x0000000000300000 ),
+               LONG2CHARS( 0x0000000000380000 ),
+               LONG2CHARS( 0x00000000003C0000 ),
+               LONG2CHARS( 0x00000000003E0000 ),
+               LONG2CHARS( 0x00000000003F0000 ),
+               LONG2CHARS( 0x00000000003F8000 ),
+               LONG2CHARS( 0x00000000003FC000 ),
+               LONG2CHARS( 0x00000000003FE000 ),
+               LONG2CHARS( 0x00000000003FF000 ),
+               LONG2CHARS( 0x00000000003FF800 ),
+               LONG2CHARS( 0x00000000003FFC00 ),
+               LONG2CHARS( 0x00000000003FFE00 ),
+               LONG2CHARS( 0x00000000003FFF00 ),
+               LONG2CHARS( 0x00000000003FFF80 ),
+               LONG2CHARS( 0x00000000003FFFC0 ),
+               LONG2CHARS( 0x00000000003FFFE0 ),
+               LONG2CHARS( 0x00000000003FFFF0 ),
+               LONG2CHARS( 0x00000000003FFFF8 ),
+               LONG2CHARS( 0x00000000003FFFFC ),
+               LONG2CHARS( 0x00000000003FFFFE ),
+               LONG2CHARS( 0x00000000003FFFFF ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+       },
+       {
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000100000 ),
+               LONG2CHARS( 0x0000000000180000 ),
+               LONG2CHARS( 0x00000000001C0000 ),
+               LONG2CHARS( 0x00000000001E0000 ),
+               LONG2CHARS( 0x00000000001F0000 ),
+               LONG2CHARS( 0x00000000001F8000 ),
+               LONG2CHARS( 0x00000000001FC000 ),
+               LONG2CHARS( 0x00000000001FE000 ),
+               LONG2CHARS( 0x00000000001FF000 ),
+               LONG2CHARS( 0x00000000001FF800 ),
+               LONG2CHARS( 0x00000000001FFC00 ),
+               LONG2CHARS( 0x00000000001FFE00 ),
+               LONG2CHARS( 0x00000000001FFF00 ),
+               LONG2CHARS( 0x00000000001FFF80 ),
+               LONG2CHARS( 0x00000000001FFFC0 ),
+               LONG2CHARS( 0x00000000001FFFE0 ),
+               LONG2CHARS( 0x00000000001FFFF0 ),
+               LONG2CHARS( 0x00000000001FFFF8 ),
+               LONG2CHARS( 0x00000000001FFFFC ),
+               LONG2CHARS( 0x00000000001FFFFE ),
+               LONG2CHARS( 0x00000000001FFFFF ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+       },
+       {
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000080000 ),
+               LONG2CHARS( 0x00000000000C0000 ),
+               LONG2CHARS( 0x00000000000E0000 ),
+               LONG2CHARS( 0x00000000000F0000 ),
+               LONG2CHARS( 0x00000000000F8000 ),
+               LONG2CHARS( 0x00000000000FC000 ),
+               LONG2CHARS( 0x00000000000FE000 ),
+               LONG2CHARS( 0x00000000000FF000 ),
+               LONG2CHARS( 0x00000000000FF800 ),
+               LONG2CHARS( 0x00000000000FFC00 ),
+               LONG2CHARS( 0x00000000000FFE00 ),
+               LONG2CHARS( 0x00000000000FFF00 ),
+               LONG2CHARS( 0x00000000000FFF80 ),
+               LONG2CHARS( 0x00000000000FFFC0 ),
+               LONG2CHARS( 0x00000000000FFFE0 ),
+               LONG2CHARS( 0x00000000000FFFF0 ),
+               LONG2CHARS( 0x00000000000FFFF8 ),
+               LONG2CHARS( 0x00000000000FFFFC ),
+               LONG2CHARS( 0x00000000000FFFFE ),
+               LONG2CHARS( 0x00000000000FFFFF ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+       },
+       {
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000040000 ),
+               LONG2CHARS( 0x0000000000060000 ),
+               LONG2CHARS( 0x0000000000070000 ),
+               LONG2CHARS( 0x0000000000078000 ),
+               LONG2CHARS( 0x000000000007C000 ),
+               LONG2CHARS( 0x000000000007E000 ),
+               LONG2CHARS( 0x000000000007F000 ),
+               LONG2CHARS( 0x000000000007F800 ),
+               LONG2CHARS( 0x000000000007FC00 ),
+               LONG2CHARS( 0x000000000007FE00 ),
+               LONG2CHARS( 0x000000000007FF00 ),
+               LONG2CHARS( 0x000000000007FF80 ),
+               LONG2CHARS( 0x000000000007FFC0 ),
+               LONG2CHARS( 0x000000000007FFE0 ),
+               LONG2CHARS( 0x000000000007FFF0 ),
+               LONG2CHARS( 0x000000000007FFF8 ),
+               LONG2CHARS( 0x000000000007FFFC ),
+               LONG2CHARS( 0x000000000007FFFE ),
+               LONG2CHARS( 0x000000000007FFFF ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+       },
+       {
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000020000 ),
+               LONG2CHARS( 0x0000000000030000 ),
+               LONG2CHARS( 0x0000000000038000 ),
+               LONG2CHARS( 0x000000000003C000 ),
+               LONG2CHARS( 0x000000000003E000 ),
+               LONG2CHARS( 0x000000000003F000 ),
+               LONG2CHARS( 0x000000000003F800 ),
+               LONG2CHARS( 0x000000000003FC00 ),
+               LONG2CHARS( 0x000000000003FE00 ),
+               LONG2CHARS( 0x000000000003FF00 ),
+               LONG2CHARS( 0x000000000003FF80 ),
+               LONG2CHARS( 0x000000000003FFC0 ),
+               LONG2CHARS( 0x000000000003FFE0 ),
+               LONG2CHARS( 0x000000000003FFF0 ),
+               LONG2CHARS( 0x000000000003FFF8 ),
+               LONG2CHARS( 0x000000000003FFFC ),
+               LONG2CHARS( 0x000000000003FFFE ),
+               LONG2CHARS( 0x000000000003FFFF ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+       },
+       {
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000010000 ),
+               LONG2CHARS( 0x0000000000018000 ),
+               LONG2CHARS( 0x000000000001C000 ),
+               LONG2CHARS( 0x000000000001E000 ),
+               LONG2CHARS( 0x000000000001F000 ),
+               LONG2CHARS( 0x000000000001F800 ),
+               LONG2CHARS( 0x000000000001FC00 ),
+               LONG2CHARS( 0x000000000001FE00 ),
+               LONG2CHARS( 0x000000000001FF00 ),
+               LONG2CHARS( 0x000000000001FF80 ),
+               LONG2CHARS( 0x000000000001FFC0 ),
+               LONG2CHARS( 0x000000000001FFE0 ),
+               LONG2CHARS( 0x000000000001FFF0 ),
+               LONG2CHARS( 0x000000000001FFF8 ),
+               LONG2CHARS( 0x000000000001FFFC ),
+               LONG2CHARS( 0x000000000001FFFE ),
+               LONG2CHARS( 0x000000000001FFFF ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+       },
+       {
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000008000 ),
+               LONG2CHARS( 0x000000000000C000 ),
+               LONG2CHARS( 0x000000000000E000 ),
+               LONG2CHARS( 0x000000000000F000 ),
+               LONG2CHARS( 0x000000000000F800 ),
+               LONG2CHARS( 0x000000000000FC00 ),
+               LONG2CHARS( 0x000000000000FE00 ),
+               LONG2CHARS( 0x000000000000FF00 ),
+               LONG2CHARS( 0x000000000000FF80 ),
+               LONG2CHARS( 0x000000000000FFC0 ),
+               LONG2CHARS( 0x000000000000FFE0 ),
+               LONG2CHARS( 0x000000000000FFF0 ),
+               LONG2CHARS( 0x000000000000FFF8 ),
+               LONG2CHARS( 0x000000000000FFFC ),
+               LONG2CHARS( 0x000000000000FFFE ),
+               LONG2CHARS( 0x000000000000FFFF ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+       },
+       {
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000004000 ),
+               LONG2CHARS( 0x0000000000006000 ),
+               LONG2CHARS( 0x0000000000007000 ),
+               LONG2CHARS( 0x0000000000007800 ),
+               LONG2CHARS( 0x0000000000007C00 ),
+               LONG2CHARS( 0x0000000000007E00 ),
+               LONG2CHARS( 0x0000000000007F00 ),
+               LONG2CHARS( 0x0000000000007F80 ),
+               LONG2CHARS( 0x0000000000007FC0 ),
+               LONG2CHARS( 0x0000000000007FE0 ),
+               LONG2CHARS( 0x0000000000007FF0 ),
+               LONG2CHARS( 0x0000000000007FF8 ),
+               LONG2CHARS( 0x0000000000007FFC ),
+               LONG2CHARS( 0x0000000000007FFE ),
+               LONG2CHARS( 0x0000000000007FFF ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+       },
+       {
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000002000 ),
+               LONG2CHARS( 0x0000000000003000 ),
+               LONG2CHARS( 0x0000000000003800 ),
+               LONG2CHARS( 0x0000000000003C00 ),
+               LONG2CHARS( 0x0000000000003E00 ),
+               LONG2CHARS( 0x0000000000003F00 ),
+               LONG2CHARS( 0x0000000000003F80 ),
+               LONG2CHARS( 0x0000000000003FC0 ),
+               LONG2CHARS( 0x0000000000003FE0 ),
+               LONG2CHARS( 0x0000000000003FF0 ),
+               LONG2CHARS( 0x0000000000003FF8 ),
+               LONG2CHARS( 0x0000000000003FFC ),
+               LONG2CHARS( 0x0000000000003FFE ),
+               LONG2CHARS( 0x0000000000003FFF ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+       },
+       {
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000001000 ),
+               LONG2CHARS( 0x0000000000001800 ),
+               LONG2CHARS( 0x0000000000001C00 ),
+               LONG2CHARS( 0x0000000000001E00 ),
+               LONG2CHARS( 0x0000000000001F00 ),
+               LONG2CHARS( 0x0000000000001F80 ),
+               LONG2CHARS( 0x0000000000001FC0 ),
+               LONG2CHARS( 0x0000000000001FE0 ),
+               LONG2CHARS( 0x0000000000001FF0 ),
+               LONG2CHARS( 0x0000000000001FF8 ),
+               LONG2CHARS( 0x0000000000001FFC ),
+               LONG2CHARS( 0x0000000000001FFE ),
+               LONG2CHARS( 0x0000000000001FFF ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+       },
+       {
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000800 ),
+               LONG2CHARS( 0x0000000000000C00 ),
+               LONG2CHARS( 0x0000000000000E00 ),
+               LONG2CHARS( 0x0000000000000F00 ),
+               LONG2CHARS( 0x0000000000000F80 ),
+               LONG2CHARS( 0x0000000000000FC0 ),
+               LONG2CHARS( 0x0000000000000FE0 ),
+               LONG2CHARS( 0x0000000000000FF0 ),
+               LONG2CHARS( 0x0000000000000FF8 ),
+               LONG2CHARS( 0x0000000000000FFC ),
+               LONG2CHARS( 0x0000000000000FFE ),
+               LONG2CHARS( 0x0000000000000FFF ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+       },
+       {
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000400 ),
+               LONG2CHARS( 0x0000000000000600 ),
+               LONG2CHARS( 0x0000000000000700 ),
+               LONG2CHARS( 0x0000000000000780 ),
+               LONG2CHARS( 0x00000000000007C0 ),
+               LONG2CHARS( 0x00000000000007E0 ),
+               LONG2CHARS( 0x00000000000007F0 ),
+               LONG2CHARS( 0x00000000000007F8 ),
+               LONG2CHARS( 0x00000000000007FC ),
+               LONG2CHARS( 0x00000000000007FE ),
+               LONG2CHARS( 0x00000000000007FF ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+       },
+       {
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000200 ),
+               LONG2CHARS( 0x0000000000000300 ),
+               LONG2CHARS( 0x0000000000000380 ),
+               LONG2CHARS( 0x00000000000003C0 ),
+               LONG2CHARS( 0x00000000000003E0 ),
+               LONG2CHARS( 0x00000000000003F0 ),
+               LONG2CHARS( 0x00000000000003F8 ),
+               LONG2CHARS( 0x00000000000003FC ),
+               LONG2CHARS( 0x00000000000003FE ),
+               LONG2CHARS( 0x00000000000003FF ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+       },
+       {
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000100 ),
+               LONG2CHARS( 0x0000000000000180 ),
+               LONG2CHARS( 0x00000000000001C0 ),
+               LONG2CHARS( 0x00000000000001E0 ),
+               LONG2CHARS( 0x00000000000001F0 ),
+               LONG2CHARS( 0x00000000000001F8 ),
+               LONG2CHARS( 0x00000000000001FC ),
+               LONG2CHARS( 0x00000000000001FE ),
+               LONG2CHARS( 0x00000000000001FF ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+       },
+       {
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000080 ),
+               LONG2CHARS( 0x00000000000000C0 ),
+               LONG2CHARS( 0x00000000000000E0 ),
+               LONG2CHARS( 0x00000000000000F0 ),
+               LONG2CHARS( 0x00000000000000F8 ),
+               LONG2CHARS( 0x00000000000000FC ),
+               LONG2CHARS( 0x00000000000000FE ),
+               LONG2CHARS( 0x00000000000000FF ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+       },
+       {
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000040 ),
+               LONG2CHARS( 0x0000000000000060 ),
+               LONG2CHARS( 0x0000000000000070 ),
+               LONG2CHARS( 0x0000000000000078 ),
+               LONG2CHARS( 0x000000000000007C ),
+               LONG2CHARS( 0x000000000000007E ),
+               LONG2CHARS( 0x000000000000007F ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+       },
+       {
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000020 ),
+               LONG2CHARS( 0x0000000000000030 ),
+               LONG2CHARS( 0x0000000000000038 ),
+               LONG2CHARS( 0x000000000000003C ),
+               LONG2CHARS( 0x000000000000003E ),
+               LONG2CHARS( 0x000000000000003F ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+       },
+       {
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000010 ),
+               LONG2CHARS( 0x0000000000000018 ),
+               LONG2CHARS( 0x000000000000001C ),
+               LONG2CHARS( 0x000000000000001E ),
+               LONG2CHARS( 0x000000000000001F ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+       },
+       {
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000008 ),
+               LONG2CHARS( 0x000000000000000C ),
+               LONG2CHARS( 0x000000000000000E ),
+               LONG2CHARS( 0x000000000000000F ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+       },
+       {
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000004 ),
+               LONG2CHARS( 0x0000000000000006 ),
+               LONG2CHARS( 0x0000000000000007 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+       },
+       {
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000002 ),
+               LONG2CHARS( 0x0000000000000003 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+       },
+       {
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000001 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+       },
+};
+#endif /* PPW */
+
+#else          /* LSBFirst */
+/* NOTE:
+the first element in starttab could be LONG2CHARS( 0xffffffff.  making it 0
+lets us deal with a full first word in the middle loop ), rather
+than having to do the multiple reads and masks that we'd
+have to do if we thought it was partial.
+*/
+PixelType starttab[PPW+1] = 
+       {
+#if PPW == 32
+       LONG2CHARS( 0x00000000 ),
+       LONG2CHARS( 0xFFFFFFFE ),
+       LONG2CHARS( 0xFFFFFFFC ),
+       LONG2CHARS( 0xFFFFFFF8 ),
+       LONG2CHARS( 0xFFFFFFF0 ),
+       LONG2CHARS( 0xFFFFFFE0 ),
+       LONG2CHARS( 0xFFFFFFC0 ),
+       LONG2CHARS( 0xFFFFFF80 ),
+       LONG2CHARS( 0xFFFFFF00 ),
+       LONG2CHARS( 0xFFFFFE00 ),
+       LONG2CHARS( 0xFFFFFC00 ),
+       LONG2CHARS( 0xFFFFF800 ),
+       LONG2CHARS( 0xFFFFF000 ),
+       LONG2CHARS( 0xFFFFE000 ),
+       LONG2CHARS( 0xFFFFC000 ),
+       LONG2CHARS( 0xFFFF8000 ),
+       LONG2CHARS( 0xFFFF0000 ),
+       LONG2CHARS( 0xFFFE0000 ),
+       LONG2CHARS( 0xFFFC0000 ),
+       LONG2CHARS( 0xFFF80000 ),
+       LONG2CHARS( 0xFFF00000 ),
+       LONG2CHARS( 0xFFE00000 ),
+       LONG2CHARS( 0xFFC00000 ),
+       LONG2CHARS( 0xFF800000 ),
+       LONG2CHARS( 0xFF000000 ),
+       LONG2CHARS( 0xFE000000 ),
+       LONG2CHARS( 0xFC000000 ),
+       LONG2CHARS( 0xF8000000 ),
+       LONG2CHARS( 0xF0000000 ),
+       LONG2CHARS( 0xE0000000 ),
+       LONG2CHARS( 0xC0000000 ),
+       LONG2CHARS( 0x80000000 ),
+       LONG2CHARS( 0x00000000 )
+#else /* PPW == 64 */
+       LONG2CHARS( 0x0000000000000000 ),
+       LONG2CHARS( 0xFFFFFFFFFFFFFFFE ),
+       LONG2CHARS( 0xFFFFFFFFFFFFFFFC ),
+       LONG2CHARS( 0xFFFFFFFFFFFFFFF8 ),
+       LONG2CHARS( 0xFFFFFFFFFFFFFFF0 ),
+       LONG2CHARS( 0xFFFFFFFFFFFFFFE0 ),
+       LONG2CHARS( 0xFFFFFFFFFFFFFFC0 ),
+       LONG2CHARS( 0xFFFFFFFFFFFFFF80 ),
+       LONG2CHARS( 0xFFFFFFFFFFFFFF00 ),
+       LONG2CHARS( 0xFFFFFFFFFFFFFE00 ),
+       LONG2CHARS( 0xFFFFFFFFFFFFFC00 ),
+       LONG2CHARS( 0xFFFFFFFFFFFFF800 ),
+       LONG2CHARS( 0xFFFFFFFFFFFFF000 ),
+       LONG2CHARS( 0xFFFFFFFFFFFFE000 ),
+       LONG2CHARS( 0xFFFFFFFFFFFFC000 ),
+       LONG2CHARS( 0xFFFFFFFFFFFF8000 ),
+       LONG2CHARS( 0xFFFFFFFFFFFF0000 ),
+       LONG2CHARS( 0xFFFFFFFFFFFE0000 ),
+       LONG2CHARS( 0xFFFFFFFFFFFC0000 ),
+       LONG2CHARS( 0xFFFFFFFFFFF80000 ),
+       LONG2CHARS( 0xFFFFFFFFFFF00000 ),
+       LONG2CHARS( 0xFFFFFFFFFFE00000 ),
+       LONG2CHARS( 0xFFFFFFFFFFC00000 ),
+       LONG2CHARS( 0xFFFFFFFFFF800000 ),
+       LONG2CHARS( 0xFFFFFFFFFF000000 ),
+       LONG2CHARS( 0xFFFFFFFFFE000000 ),
+       LONG2CHARS( 0xFFFFFFFFFC000000 ),
+       LONG2CHARS( 0xFFFFFFFFF8000000 ),
+       LONG2CHARS( 0xFFFFFFFFF0000000 ),
+       LONG2CHARS( 0xFFFFFFFFE0000000 ),
+       LONG2CHARS( 0xFFFFFFFFC0000000 ),
+       LONG2CHARS( 0xFFFFFFFF80000000 ),
+       LONG2CHARS( 0xFFFFFFFF00000000 ),
+       LONG2CHARS( 0xFFFFFFFE00000000 ),
+       LONG2CHARS( 0xFFFFFFFC00000000 ),
+       LONG2CHARS( 0xFFFFFFF800000000 ),
+       LONG2CHARS( 0xFFFFFFF000000000 ),
+       LONG2CHARS( 0xFFFFFFE000000000 ),
+       LONG2CHARS( 0xFFFFFFC000000000 ),
+       LONG2CHARS( 0xFFFFFF8000000000 ),
+       LONG2CHARS( 0xFFFFFF0000000000 ),
+       LONG2CHARS( 0xFFFFFE0000000000 ),
+       LONG2CHARS( 0xFFFFFC0000000000 ),
+       LONG2CHARS( 0xFFFFF80000000000 ),
+       LONG2CHARS( 0xFFFFF00000000000 ),
+       LONG2CHARS( 0xFFFFE00000000000 ),
+       LONG2CHARS( 0xFFFFC00000000000 ),
+       LONG2CHARS( 0xFFFF800000000000 ),
+       LONG2CHARS( 0xFFFF000000000000 ),
+       LONG2CHARS( 0xFFFE000000000000 ),
+       LONG2CHARS( 0xFFFC000000000000 ),
+       LONG2CHARS( 0xFFF8000000000000 ),
+       LONG2CHARS( 0xFFF0000000000000 ),
+       LONG2CHARS( 0xFFE0000000000000 ),
+       LONG2CHARS( 0xFFC0000000000000 ),
+       LONG2CHARS( 0xFF80000000000000 ),
+       LONG2CHARS( 0xFF00000000000000 ),
+       LONG2CHARS( 0xFE00000000000000 ),
+       LONG2CHARS( 0xFC00000000000000 ),
+       LONG2CHARS( 0xF800000000000000 ),
+       LONG2CHARS( 0xF000000000000000 ),
+       LONG2CHARS( 0xE000000000000000 ),
+       LONG2CHARS( 0xC000000000000000 ),
+       LONG2CHARS( 0x8000000000000000 ),
+       LONG2CHARS( 0x0000000000000000 )
+#endif /* PPW */
+       };
+
+PixelType endtab[PPW+1] = 
+       {
+       LONG2CHARS( 0x00000000 ),
+       LONG2CHARS( 0x00000001 ),
+       LONG2CHARS( 0x00000003 ),
+       LONG2CHARS( 0x00000007 ),
+       LONG2CHARS( 0x0000000F ),
+       LONG2CHARS( 0x0000001F ),
+       LONG2CHARS( 0x0000003F ),
+       LONG2CHARS( 0x0000007F ),
+       LONG2CHARS( 0x000000FF ),
+       LONG2CHARS( 0x000001FF ),
+       LONG2CHARS( 0x000003FF ),
+       LONG2CHARS( 0x000007FF ),
+       LONG2CHARS( 0x00000FFF ),
+       LONG2CHARS( 0x00001FFF ),
+       LONG2CHARS( 0x00003FFF ),
+       LONG2CHARS( 0x00007FFF ),
+       LONG2CHARS( 0x0000FFFF ),
+       LONG2CHARS( 0x0001FFFF ),
+       LONG2CHARS( 0x0003FFFF ),
+       LONG2CHARS( 0x0007FFFF ),
+       LONG2CHARS( 0x000FFFFF ),
+       LONG2CHARS( 0x001FFFFF ),
+       LONG2CHARS( 0x003FFFFF ),
+       LONG2CHARS( 0x007FFFFF ),
+       LONG2CHARS( 0x00FFFFFF ),
+       LONG2CHARS( 0x01FFFFFF ),
+       LONG2CHARS( 0x03FFFFFF ),
+       LONG2CHARS( 0x07FFFFFF ),
+       LONG2CHARS( 0x0FFFFFFF ),
+       LONG2CHARS( 0x1FFFFFFF ),
+       LONG2CHARS( 0x3FFFFFFF ),
+       LONG2CHARS( 0x7FFFFFFF ),
+       LONG2CHARS( 0xFFFFFFFF )
+#if PPW == 64
+       ,
+       LONG2CHARS( 0x00000001FFFFFFFF ),
+       LONG2CHARS( 0x00000003FFFFFFFF ),
+       LONG2CHARS( 0x00000007FFFFFFFF ),
+       LONG2CHARS( 0x0000000FFFFFFFFF ),
+       LONG2CHARS( 0x0000001FFFFFFFFF ),
+       LONG2CHARS( 0x0000003FFFFFFFFF ),
+       LONG2CHARS( 0x0000007FFFFFFFFF ),
+       LONG2CHARS( 0x000000FFFFFFFFFF ),
+       LONG2CHARS( 0x000001FFFFFFFFFF ),
+       LONG2CHARS( 0x000003FFFFFFFFFF ),
+       LONG2CHARS( 0x000007FFFFFFFFFF ),
+       LONG2CHARS( 0x00000FFFFFFFFFFF ),
+       LONG2CHARS( 0x00001FFFFFFFFFFF ),
+       LONG2CHARS( 0x00003FFFFFFFFFFF ),
+       LONG2CHARS( 0x00007FFFFFFFFFFF ),
+       LONG2CHARS( 0x0000FFFFFFFFFFFF ),
+       LONG2CHARS( 0x0001FFFFFFFFFFFF ),
+       LONG2CHARS( 0x0003FFFFFFFFFFFF ),
+       LONG2CHARS( 0x0007FFFFFFFFFFFF ),
+       LONG2CHARS( 0x000FFFFFFFFFFFFF ),
+       LONG2CHARS( 0x001FFFFFFFFFFFFF ),
+       LONG2CHARS( 0x003FFFFFFFFFFFFF ),
+       LONG2CHARS( 0x007FFFFFFFFFFFFF ),
+       LONG2CHARS( 0x00FFFFFFFFFFFFFF ),
+       LONG2CHARS( 0x01FFFFFFFFFFFFFF ),
+       LONG2CHARS( 0x03FFFFFFFFFFFFFF ),
+       LONG2CHARS( 0x07FFFFFFFFFFFFFF ),
+       LONG2CHARS( 0x0FFFFFFFFFFFFFFF ),
+       LONG2CHARS( 0x1FFFFFFFFFFFFFFF ),
+       LONG2CHARS( 0x3FFFFFFFFFFFFFFF ),
+       LONG2CHARS( 0x7FFFFFFFFFFFFFFF ),
+       LONG2CHARS( 0xFFFFFFFFFFFFFFFF )
+#endif /* PPW */
+       };
+
+#ifdef NEED_OLD_MFB_MASKS
+/* a hack ), for now, since the entries for 0 need to be all
+   1 bits ), not all zeros.
+   this means the code DOES NOT WORK for segments of length
+   0 (which is only a problem in the horizontal line code.)
+*/
+PixelType startpartial[33] = 
+       {
+       LONG2CHARS( 0xFFFFFFFF ),
+       LONG2CHARS( 0xFFFFFFFE ),
+       LONG2CHARS( 0xFFFFFFFC ),
+       LONG2CHARS( 0xFFFFFFF8 ),
+       LONG2CHARS( 0xFFFFFFF0 ),
+       LONG2CHARS( 0xFFFFFFE0 ),
+       LONG2CHARS( 0xFFFFFFC0 ),
+       LONG2CHARS( 0xFFFFFF80 ),
+       LONG2CHARS( 0xFFFFFF00 ),
+       LONG2CHARS( 0xFFFFFE00 ),
+       LONG2CHARS( 0xFFFFFC00 ),
+       LONG2CHARS( 0xFFFFF800 ),
+       LONG2CHARS( 0xFFFFF000 ),
+       LONG2CHARS( 0xFFFFE000 ),
+       LONG2CHARS( 0xFFFFC000 ),
+       LONG2CHARS( 0xFFFF8000 ),
+       LONG2CHARS( 0xFFFF0000 ),
+       LONG2CHARS( 0xFFFE0000 ),
+       LONG2CHARS( 0xFFFC0000 ),
+       LONG2CHARS( 0xFFF80000 ),
+       LONG2CHARS( 0xFFF00000 ),
+       LONG2CHARS( 0xFFE00000 ),
+       LONG2CHARS( 0xFFC00000 ),
+       LONG2CHARS( 0xFF800000 ),
+       LONG2CHARS( 0xFF000000 ),
+       LONG2CHARS( 0xFE000000 ),
+       LONG2CHARS( 0xFC000000 ),
+       LONG2CHARS( 0xF8000000 ),
+       LONG2CHARS( 0xF0000000 ),
+       LONG2CHARS( 0xE0000000 ),
+       LONG2CHARS( 0xC0000000 ),
+       LONG2CHARS( 0x80000000 ),
+       LONG2CHARS( 0x00000000 )
+       };
+
+PixelType endpartial[33] = 
+       {
+       LONG2CHARS( 0xFFFFFFFF ),
+       LONG2CHARS( 0x00000001 ),
+       LONG2CHARS( 0x00000003 ),
+       LONG2CHARS( 0x00000007 ),
+       LONG2CHARS( 0x0000000F ),
+       LONG2CHARS( 0x0000001F ),
+       LONG2CHARS( 0x0000003F ),
+       LONG2CHARS( 0x0000007F ),
+       LONG2CHARS( 0x000000FF ),
+       LONG2CHARS( 0x000001FF ),
+       LONG2CHARS( 0x000003FF ),
+       LONG2CHARS( 0x000007FF ),
+       LONG2CHARS( 0x00000FFF ),
+       LONG2CHARS( 0x00001FFF ),
+       LONG2CHARS( 0x00003FFF ),
+       LONG2CHARS( 0x00007FFF ),
+       LONG2CHARS( 0x0000FFFF ),
+       LONG2CHARS( 0x0001FFFF ),
+       LONG2CHARS( 0x0003FFFF ),
+       LONG2CHARS( 0x0007FFFF ),
+       LONG2CHARS( 0x000FFFFF ),
+       LONG2CHARS( 0x001FFFFF ),
+       LONG2CHARS( 0x003FFFFF ),
+       LONG2CHARS( 0x007FFFFF ),
+       LONG2CHARS( 0x00FFFFFF ),
+       LONG2CHARS( 0x01FFFFFF ),
+       LONG2CHARS( 0x03FFFFFF ),
+       LONG2CHARS( 0x07FFFFFF ),
+       LONG2CHARS( 0x0FFFFFFF ),
+       LONG2CHARS( 0x1FFFFFFF ),
+       LONG2CHARS( 0x3FFFFFFF ),
+       LONG2CHARS( 0x7FFFFFFF ),
+       LONG2CHARS( 0xFFFFFFFF )
+       };
+#endif
+
+#if PPW == 32
+PixelType partmasks[PPW][PPW] = {
+     {LONG2CHARS( 0xFFFFFFFF ), LONG2CHARS( 0x00000001 ), LONG2CHARS( 0x00000003 ), LONG2CHARS( 0x00000007 ),
+      LONG2CHARS( 0x0000000F ), LONG2CHARS( 0x0000001F ), LONG2CHARS( 0x0000003F ), LONG2CHARS( 0x0000007F ),
+      LONG2CHARS( 0x000000FF ), LONG2CHARS( 0x000001FF ), LONG2CHARS( 0x000003FF ), LONG2CHARS( 0x000007FF ),
+      LONG2CHARS( 0x00000FFF ), LONG2CHARS( 0x00001FFF ), LONG2CHARS( 0x00003FFF ), LONG2CHARS( 0x00007FFF ),
+      LONG2CHARS( 0x0000FFFF ), LONG2CHARS( 0x0001FFFF ), LONG2CHARS( 0x0003FFFF ), LONG2CHARS( 0x0007FFFF ),
+      LONG2CHARS( 0x000FFFFF ), LONG2CHARS( 0x001FFFFF ), LONG2CHARS( 0x003FFFFF ), LONG2CHARS( 0x007FFFFF ),
+      LONG2CHARS( 0x00FFFFFF ), LONG2CHARS( 0x01FFFFFF ), LONG2CHARS( 0x03FFFFFF ), LONG2CHARS( 0x07FFFFFF ),
+      LONG2CHARS( 0x0FFFFFFF ), LONG2CHARS( 0x1FFFFFFF ), LONG2CHARS( 0x3FFFFFFF ), LONG2CHARS( 0x7FFFFFFF )},
+     {LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000002 ), LONG2CHARS( 0x00000006 ), LONG2CHARS( 0x0000000E ),
+      LONG2CHARS( 0x0000001E ), LONG2CHARS( 0x0000003E ), LONG2CHARS( 0x0000007E ), LONG2CHARS( 0x000000FE ),
+      LONG2CHARS( 0x000001FE ), LONG2CHARS( 0x000003FE ), LONG2CHARS( 0x000007FE ), LONG2CHARS( 0x00000FFE ),
+      LONG2CHARS( 0x00001FFE ), LONG2CHARS( 0x00003FFE ), LONG2CHARS( 0x00007FFE ), LONG2CHARS( 0x0000FFFE ),
+      LONG2CHARS( 0x0001FFFE ), LONG2CHARS( 0x0003FFFE ), LONG2CHARS( 0x0007FFFE ), LONG2CHARS( 0x000FFFFE ),
+      LONG2CHARS( 0x001FFFFE ), LONG2CHARS( 0x003FFFFE ), LONG2CHARS( 0x007FFFFE ), LONG2CHARS( 0x00FFFFFE ),
+      LONG2CHARS( 0x01FFFFFE ), LONG2CHARS( 0x03FFFFFE ), LONG2CHARS( 0x07FFFFFE ), LONG2CHARS( 0x0FFFFFFE ),
+      LONG2CHARS( 0x1FFFFFFE ), LONG2CHARS( 0x3FFFFFFE ), LONG2CHARS( 0x7FFFFFFE ), LONG2CHARS( 0xFFFFFFFE )},
+     {LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000004 ), LONG2CHARS( 0x0000000C ), LONG2CHARS( 0x0000001C ),
+      LONG2CHARS( 0x0000003C ), LONG2CHARS( 0x0000007C ), LONG2CHARS( 0x000000FC ), LONG2CHARS( 0x000001FC ),
+      LONG2CHARS( 0x000003FC ), LONG2CHARS( 0x000007FC ), LONG2CHARS( 0x00000FFC ), LONG2CHARS( 0x00001FFC ),
+      LONG2CHARS( 0x00003FFC ), LONG2CHARS( 0x00007FFC ), LONG2CHARS( 0x0000FFFC ), LONG2CHARS( 0x0001FFFC ),
+      LONG2CHARS( 0x0003FFFC ), LONG2CHARS( 0x0007FFFC ), LONG2CHARS( 0x000FFFFC ), LONG2CHARS( 0x001FFFFC ),
+      LONG2CHARS( 0x003FFFFC ), LONG2CHARS( 0x007FFFFC ), LONG2CHARS( 0x00FFFFFC ), LONG2CHARS( 0x01FFFFFC ),
+      LONG2CHARS( 0x03FFFFFC ), LONG2CHARS( 0x07FFFFFC ), LONG2CHARS( 0x0FFFFFFC ), LONG2CHARS( 0x1FFFFFFC ),
+      LONG2CHARS( 0x3FFFFFFC ), LONG2CHARS( 0x7FFFFFFC ), LONG2CHARS( 0xFFFFFFFC ), LONG2CHARS( 0x00000000 )},
+     {LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000008 ), LONG2CHARS( 0x00000018 ), LONG2CHARS( 0x00000038 ),
+      LONG2CHARS( 0x00000078 ), LONG2CHARS( 0x000000F8 ), LONG2CHARS( 0x000001F8 ), LONG2CHARS( 0x000003F8 ),
+      LONG2CHARS( 0x000007F8 ), LONG2CHARS( 0x00000FF8 ), LONG2CHARS( 0x00001FF8 ), LONG2CHARS( 0x00003FF8 ),
+      LONG2CHARS( 0X00007FF8 ), LONG2CHARS( 0x0000FFF8 ), LONG2CHARS( 0x0001FFF8 ), LONG2CHARS( 0x0003FFF8 ),
+      LONG2CHARS( 0X0007FFF8 ), LONG2CHARS( 0x000FFFF8 ), LONG2CHARS( 0x001FFFF8 ), LONG2CHARS( 0x003FFFF8 ),
+      LONG2CHARS( 0X007FFFF8 ), LONG2CHARS( 0x00FFFFF8 ), LONG2CHARS( 0x01FFFFF8 ), LONG2CHARS( 0x03FFFFF8 ),
+      LONG2CHARS( 0X07FFFFF8 ), LONG2CHARS( 0x0FFFFFF8 ), LONG2CHARS( 0x1FFFFFF8 ), LONG2CHARS( 0x3FFFFFF8 ),
+      LONG2CHARS( 0X7FFFFFF8 ), LONG2CHARS( 0xFFFFFFF8 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 )},
+     {LONG2CHARS( 0X00000000 ), LONG2CHARS( 0x00000010 ), LONG2CHARS( 0x00000030 ), LONG2CHARS( 0x00000070 ),
+      LONG2CHARS( 0X000000F0 ), LONG2CHARS( 0x000001F0 ), LONG2CHARS( 0x000003F0 ), LONG2CHARS( 0x000007F0 ),
+      LONG2CHARS( 0X00000FF0 ), LONG2CHARS( 0x00001FF0 ), LONG2CHARS( 0x00003FF0 ), LONG2CHARS( 0x00007FF0 ),
+      LONG2CHARS( 0X0000FFF0 ), LONG2CHARS( 0x0001FFF0 ), LONG2CHARS( 0x0003FFF0 ), LONG2CHARS( 0x0007FFF0 ),
+      LONG2CHARS( 0X000FFFF0 ), LONG2CHARS( 0x001FFFF0 ), LONG2CHARS( 0x003FFFF0 ), LONG2CHARS( 0x007FFFF0 ),
+      LONG2CHARS( 0X00FFFFF0 ), LONG2CHARS( 0x01FFFFF0 ), LONG2CHARS( 0x03FFFFF0 ), LONG2CHARS( 0x07FFFFF0 ),
+      LONG2CHARS( 0X0FFFFFF0 ), LONG2CHARS( 0x1FFFFFF0 ), LONG2CHARS( 0x3FFFFFF0 ), LONG2CHARS( 0x7FFFFFF0 ),
+      LONG2CHARS( 0XFFFFFFF0 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 )},
+     {LONG2CHARS( 0X00000000 ), LONG2CHARS( 0x00000020 ), LONG2CHARS( 0x00000060 ), LONG2CHARS( 0x000000E0 ),
+      LONG2CHARS( 0X000001E0 ), LONG2CHARS( 0x000003E0 ), LONG2CHARS( 0x000007E0 ), LONG2CHARS( 0x00000FE0 ),
+      LONG2CHARS( 0X00001FE0 ), LONG2CHARS( 0x00003FE0 ), LONG2CHARS( 0x00007FE0 ), LONG2CHARS( 0x0000FFE0 ),
+      LONG2CHARS( 0X0001FFE0 ), LONG2CHARS( 0x0003FFE0 ), LONG2CHARS( 0x0007FFE0 ), LONG2CHARS( 0x000FFFE0 ),
+      LONG2CHARS( 0X001FFFE0 ), LONG2CHARS( 0x003FFFE0 ), LONG2CHARS( 0x007FFFE0 ), LONG2CHARS( 0x00FFFFE0 ),
+      LONG2CHARS( 0X01FFFFE0 ), LONG2CHARS( 0x03FFFFE0 ), LONG2CHARS( 0x07FFFFE0 ), LONG2CHARS( 0x0FFFFFE0 ),
+      LONG2CHARS( 0X1FFFFFE0 ), LONG2CHARS( 0x3FFFFFE0 ), LONG2CHARS( 0x7FFFFFE0 ), LONG2CHARS( 0xFFFFFFE0 ),
+      LONG2CHARS( 0X00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 )},
+     {LONG2CHARS( 0X00000000 ), LONG2CHARS( 0x00000040 ), LONG2CHARS( 0x000000C0 ), LONG2CHARS( 0x000001C0 ),
+      LONG2CHARS( 0X000003C0 ), LONG2CHARS( 0x000007C0 ), LONG2CHARS( 0x00000FC0 ), LONG2CHARS( 0x00001FC0 ),
+      LONG2CHARS( 0X00003FC0 ), LONG2CHARS( 0x00007FC0 ), LONG2CHARS( 0x0000FFC0 ), LONG2CHARS( 0x0001FFC0 ),
+      LONG2CHARS( 0X0003FFC0 ), LONG2CHARS( 0x0007FFC0 ), LONG2CHARS( 0x000FFFC0 ), LONG2CHARS( 0x001FFFC0 ),
+      LONG2CHARS( 0X003FFFC0 ), LONG2CHARS( 0x007FFFC0 ), LONG2CHARS( 0x00FFFFC0 ), LONG2CHARS( 0x01FFFFC0 ),
+      LONG2CHARS( 0X03FFFFC0 ), LONG2CHARS( 0x07FFFFC0 ), LONG2CHARS( 0x0FFFFFC0 ), LONG2CHARS( 0x1FFFFFC0 ),
+      LONG2CHARS( 0X3FFFFFC0 ), LONG2CHARS( 0x7FFFFFC0 ), LONG2CHARS( 0xFFFFFFC0 ), LONG2CHARS( 0x00000000 ),
+      LONG2CHARS( 0X00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 )},
+     {LONG2CHARS( 0X00000000 ), LONG2CHARS( 0x00000080 ), LONG2CHARS( 0x00000180 ), LONG2CHARS( 0x00000380 ),
+      LONG2CHARS( 0X00000780 ), LONG2CHARS( 0x00000F80 ), LONG2CHARS( 0x00001F80 ), LONG2CHARS( 0x00003F80 ),
+      LONG2CHARS( 0X00007F80 ), LONG2CHARS( 0x0000FF80 ), LONG2CHARS( 0x0001FF80 ), LONG2CHARS( 0x0003FF80 ),
+      LONG2CHARS( 0X0007FF80 ), LONG2CHARS( 0x000FFF80 ), LONG2CHARS( 0x001FFF80 ), LONG2CHARS( 0x003FFF80 ),
+      LONG2CHARS( 0X007FFF80 ), LONG2CHARS( 0x00FFFF80 ), LONG2CHARS( 0x01FFFF80 ), LONG2CHARS( 0x03FFFF80 ),
+      LONG2CHARS( 0X07FFFF80 ), LONG2CHARS( 0x0FFFFF80 ), LONG2CHARS( 0x1FFFFF80 ), LONG2CHARS( 0x3FFFFF80 ),
+      LONG2CHARS( 0X7FFFFF80 ), LONG2CHARS( 0xFFFFFF80 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ),
+      LONG2CHARS( 0X00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 )},
+     {LONG2CHARS( 0X00000000 ), LONG2CHARS( 0x00000100 ), LONG2CHARS( 0x00000300 ), LONG2CHARS( 0x00000700 ),
+      LONG2CHARS( 0X00000F00 ), LONG2CHARS( 0x00001F00 ), LONG2CHARS( 0x00003F00 ), LONG2CHARS( 0x00007F00 ),
+      LONG2CHARS( 0X0000FF00 ), LONG2CHARS( 0x0001FF00 ), LONG2CHARS( 0x0003FF00 ), LONG2CHARS( 0x0007FF00 ),
+      LONG2CHARS( 0X000FFF00 ), LONG2CHARS( 0x001FFF00 ), LONG2CHARS( 0x003FFF00 ), LONG2CHARS( 0x007FFF00 ),
+      LONG2CHARS( 0X00FFFF00 ), LONG2CHARS( 0x01FFFF00 ), LONG2CHARS( 0x03FFFF00 ), LONG2CHARS( 0x07FFFF00 ),
+      LONG2CHARS( 0X0FFFFF00 ), LONG2CHARS( 0x1FFFFF00 ), LONG2CHARS( 0x3FFFFF00 ), LONG2CHARS( 0x7FFFFF00 ),
+      LONG2CHARS( 0XFFFFFF00 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ),
+      LONG2CHARS( 0X00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 )},
+     {LONG2CHARS( 0X00000000 ), LONG2CHARS( 0x00000200 ), LONG2CHARS( 0x00000600 ), LONG2CHARS( 0x00000E00 ),
+      LONG2CHARS( 0X00001E00 ), LONG2CHARS( 0x00003E00 ), LONG2CHARS( 0x00007E00 ), LONG2CHARS( 0x0000FE00 ),
+      LONG2CHARS( 0X0001FE00 ), LONG2CHARS( 0x0003FE00 ), LONG2CHARS( 0x0007FE00 ), LONG2CHARS( 0x000FFE00 ),
+      LONG2CHARS( 0X001FFE00 ), LONG2CHARS( 0x003FFE00 ), LONG2CHARS( 0x007FFE00 ), LONG2CHARS( 0x00FFFE00 ),
+      LONG2CHARS( 0X01FFFE00 ), LONG2CHARS( 0x03FFFE00 ), LONG2CHARS( 0x07FFFE00 ), LONG2CHARS( 0x0FFFFE00 ),
+      LONG2CHARS( 0X1FFFFE00 ), LONG2CHARS( 0x3FFFFE00 ), LONG2CHARS( 0x7FFFFE00 ), LONG2CHARS( 0xFFFFFE00 ),
+      LONG2CHARS( 0X00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ),
+      LONG2CHARS( 0X00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 )},
+     {LONG2CHARS( 0X00000000 ), LONG2CHARS( 0x00000400 ), LONG2CHARS( 0x00000C00 ), LONG2CHARS( 0x00001C00 ),
+      LONG2CHARS( 0X00003C00 ), LONG2CHARS( 0x00007C00 ), LONG2CHARS( 0x0000FC00 ), LONG2CHARS( 0x0001FC00 ),
+      LONG2CHARS( 0X0003FC00 ), LONG2CHARS( 0x0007FC00 ), LONG2CHARS( 0x000FFC00 ), LONG2CHARS( 0x001FFC00 ),
+      LONG2CHARS( 0X003FFC00 ), LONG2CHARS( 0x007FFC00 ), LONG2CHARS( 0x00FFFC00 ), LONG2CHARS( 0x01FFFC00 ),
+      LONG2CHARS( 0X03FFFC00 ), LONG2CHARS( 0x07FFFC00 ), LONG2CHARS( 0x0FFFFC00 ), LONG2CHARS( 0x1FFFFC00 ),
+      LONG2CHARS( 0X3FFFFC00 ), LONG2CHARS( 0x7FFFFC00 ), LONG2CHARS( 0xFFFFFC00 ), LONG2CHARS( 0x00000000 ),
+      LONG2CHARS( 0X00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ),
+      LONG2CHARS( 0X00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 )},
+     {LONG2CHARS( 0X00000000 ), LONG2CHARS( 0x00000800 ), LONG2CHARS( 0x00001800 ), LONG2CHARS( 0x00003800 ),
+      LONG2CHARS( 0X00007800 ), LONG2CHARS( 0x0000F800 ), LONG2CHARS( 0x0001F800 ), LONG2CHARS( 0x0003F800 ),
+      LONG2CHARS( 0X0007F800 ), LONG2CHARS( 0x000FF800 ), LONG2CHARS( 0x001FF800 ), LONG2CHARS( 0x003FF800 ),
+      LONG2CHARS( 0X007FF800 ), LONG2CHARS( 0x00FFF800 ), LONG2CHARS( 0x01FFF800 ), LONG2CHARS( 0x03FFF800 ),
+      LONG2CHARS( 0X07FFF800 ), LONG2CHARS( 0x0FFFF800 ), LONG2CHARS( 0x1FFFF800 ), LONG2CHARS( 0x3FFFF800 ),
+      LONG2CHARS( 0X7FFFF800 ), LONG2CHARS( 0xFFFFF800 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ),
+      LONG2CHARS( 0X00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ),
+      LONG2CHARS( 0X00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 )},
+     {LONG2CHARS( 0X00000000 ), LONG2CHARS( 0x00001000 ), LONG2CHARS( 0x00003000 ), LONG2CHARS( 0x00007000 ),
+      LONG2CHARS( 0X0000F000 ), LONG2CHARS( 0x0001F000 ), LONG2CHARS( 0x0003F000 ), LONG2CHARS( 0x0007F000 ),
+      LONG2CHARS( 0X000FF000 ), LONG2CHARS( 0x001FF000 ), LONG2CHARS( 0x003FF000 ), LONG2CHARS( 0x007FF000 ),
+      LONG2CHARS( 0X00FFF000 ), LONG2CHARS( 0x01FFF000 ), LONG2CHARS( 0x03FFF000 ), LONG2CHARS( 0x07FFF000 ),
+      LONG2CHARS( 0X0FFFF000 ), LONG2CHARS( 0x1FFFF000 ), LONG2CHARS( 0x3FFFF000 ), LONG2CHARS( 0x7FFFF000 ),
+      LONG2CHARS( 0XFFFFF000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ),
+      LONG2CHARS( 0X00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ),
+      LONG2CHARS( 0X00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 )},
+     {LONG2CHARS( 0X00000000 ), LONG2CHARS( 0x00002000 ), LONG2CHARS( 0x00006000 ), LONG2CHARS( 0x0000E000 ),
+      LONG2CHARS( 0X0001E000 ), LONG2CHARS( 0x0003E000 ), LONG2CHARS( 0x0007E000 ), LONG2CHARS( 0x000FE000 ),
+      LONG2CHARS( 0X001FE000 ), LONG2CHARS( 0x003FE000 ), LONG2CHARS( 0x007FE000 ), LONG2CHARS( 0x00FFE000 ),
+      LONG2CHARS( 0X01FFE000 ), LONG2CHARS( 0x03FFE000 ), LONG2CHARS( 0x07FFE000 ), LONG2CHARS( 0x0FFFE000 ),
+      LONG2CHARS( 0X1FFFE000 ), LONG2CHARS( 0x3FFFE000 ), LONG2CHARS( 0x7FFFE000 ), LONG2CHARS( 0xFFFFE000 ),
+      LONG2CHARS( 0X00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ),
+      LONG2CHARS( 0X00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ),
+      LONG2CHARS( 0X00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 )},
+     {LONG2CHARS( 0X00000000 ), LONG2CHARS( 0x00004000 ), LONG2CHARS( 0x0000C000 ), LONG2CHARS( 0x0001C000 ),
+      LONG2CHARS( 0X0003C000 ), LONG2CHARS( 0x0007C000 ), LONG2CHARS( 0x000FC000 ), LONG2CHARS( 0x001FC000 ),
+      LONG2CHARS( 0X003FC000 ), LONG2CHARS( 0x007FC000 ), LONG2CHARS( 0x00FFC000 ), LONG2CHARS( 0x01FFC000 ),
+      LONG2CHARS( 0X03FFC000 ), LONG2CHARS( 0x07FFC000 ), LONG2CHARS( 0x0FFFC000 ), LONG2CHARS( 0x1FFFC000 ),
+      LONG2CHARS( 0X3FFFC000 ), LONG2CHARS( 0x7FFFC000 ), LONG2CHARS( 0xFFFFC000 ), LONG2CHARS( 0x00000000 ),
+      LONG2CHARS( 0X00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ),
+      LONG2CHARS( 0X00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ),
+      LONG2CHARS( 0X00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 )},
+     {LONG2CHARS( 0X00000000 ), LONG2CHARS( 0x00008000 ), LONG2CHARS( 0x00018000 ), LONG2CHARS( 0x00038000 ),
+      LONG2CHARS( 0X00078000 ), LONG2CHARS( 0x000F8000 ), LONG2CHARS( 0x001F8000 ), LONG2CHARS( 0x003F8000 ),
+      LONG2CHARS( 0X007F8000 ), LONG2CHARS( 0x00FF8000 ), LONG2CHARS( 0x01FF8000 ), LONG2CHARS( 0x03FF8000 ),
+      LONG2CHARS( 0X07FF8000 ), LONG2CHARS( 0x0FFF8000 ), LONG2CHARS( 0x1FFF8000 ), LONG2CHARS( 0x3FFF8000 ),
+      LONG2CHARS( 0X7FFF8000 ), LONG2CHARS( 0xFFFF8000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ),
+      LONG2CHARS( 0X00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ),
+      LONG2CHARS( 0X00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ),
+      LONG2CHARS( 0X00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 )},
+     {LONG2CHARS( 0X00000000 ), LONG2CHARS( 0x00010000 ), LONG2CHARS( 0x00030000 ), LONG2CHARS( 0x00070000 ),
+      LONG2CHARS( 0X000F0000 ), LONG2CHARS( 0x001F0000 ), LONG2CHARS( 0x003F0000 ), LONG2CHARS( 0x007F0000 ),
+      LONG2CHARS( 0X00FF0000 ), LONG2CHARS( 0x01FF0000 ), LONG2CHARS( 0x03FF0000 ), LONG2CHARS( 0x07FF0000 ),
+      LONG2CHARS( 0X0FFF0000 ), LONG2CHARS( 0x1FFF0000 ), LONG2CHARS( 0x3FFF0000 ), LONG2CHARS( 0x7FFF0000 ),
+      LONG2CHARS( 0XFFFF0000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ),
+      LONG2CHARS( 0X00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ),
+      LONG2CHARS( 0X00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ),
+      LONG2CHARS( 0X00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 )},
+     {LONG2CHARS( 0X00000000 ), LONG2CHARS( 0x00020000 ), LONG2CHARS( 0x00060000 ), LONG2CHARS( 0x000E0000 ),
+      LONG2CHARS( 0X001E0000 ), LONG2CHARS( 0x003E0000 ), LONG2CHARS( 0x007E0000 ), LONG2CHARS( 0x00FE0000 ),
+      LONG2CHARS( 0X01FE0000 ), LONG2CHARS( 0x03FE0000 ), LONG2CHARS( 0x07FE0000 ), LONG2CHARS( 0x0FFE0000 ),
+      LONG2CHARS( 0X1FFE0000 ), LONG2CHARS( 0x3FFE0000 ), LONG2CHARS( 0x7FFE0000 ), LONG2CHARS( 0xFFFE0000 ),
+      LONG2CHARS( 0X00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ),
+      LONG2CHARS( 0X00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ),
+      LONG2CHARS( 0X00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ),
+      LONG2CHARS( 0X00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 )},
+     {LONG2CHARS( 0X00000000 ), LONG2CHARS( 0x00040000 ), LONG2CHARS( 0x000C0000 ), LONG2CHARS( 0x001C0000 ),
+      LONG2CHARS( 0X003C0000 ), LONG2CHARS( 0x007C0000 ), LONG2CHARS( 0x00FC0000 ), LONG2CHARS( 0x01FC0000 ),
+      LONG2CHARS( 0X03FC0000 ), LONG2CHARS( 0x07FC0000 ), LONG2CHARS( 0x0FFC0000 ), LONG2CHARS( 0x1FFC0000 ),
+      LONG2CHARS( 0X3FFC0000 ), LONG2CHARS( 0x7FFC0000 ), LONG2CHARS( 0xFFFC0000 ), LONG2CHARS( 0x00000000 ),
+      LONG2CHARS( 0X00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ),
+      LONG2CHARS( 0X00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ),
+      LONG2CHARS( 0X00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ),
+      LONG2CHARS( 0X00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 )},
+     {LONG2CHARS( 0X00000000 ), LONG2CHARS( 0x00080000 ), LONG2CHARS( 0x00180000 ), LONG2CHARS( 0x00380000 ),
+      LONG2CHARS( 0X00780000 ), LONG2CHARS( 0x00F80000 ), LONG2CHARS( 0x01F80000 ), LONG2CHARS( 0x03F80000 ),
+      LONG2CHARS( 0X07F80000 ), LONG2CHARS( 0x0FF80000 ), LONG2CHARS( 0x1FF80000 ), LONG2CHARS( 0x3FF80000 ),
+      LONG2CHARS( 0X7FF80000 ), LONG2CHARS( 0xFFF80000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ),
+      LONG2CHARS( 0X00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ),
+      LONG2CHARS( 0X00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ),
+      LONG2CHARS( 0X00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ),
+      LONG2CHARS( 0X00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 )},
+     {LONG2CHARS( 0X00000000 ), LONG2CHARS( 0x00100000 ), LONG2CHARS( 0x00300000 ), LONG2CHARS( 0x00700000 ),
+      LONG2CHARS( 0X00F00000 ), LONG2CHARS( 0x01F00000 ), LONG2CHARS( 0x03F00000 ), LONG2CHARS( 0x07F00000 ),
+      LONG2CHARS( 0X0FF00000 ), LONG2CHARS( 0x1FF00000 ), LONG2CHARS( 0x3FF00000 ), LONG2CHARS( 0x7FF00000 ),
+      LONG2CHARS( 0XFFF00000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ),
+      LONG2CHARS( 0X00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ),
+      LONG2CHARS( 0X00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ),
+      LONG2CHARS( 0X00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ),
+      LONG2CHARS( 0X00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 )},
+     {LONG2CHARS( 0X00000000 ), LONG2CHARS( 0x00200000 ), LONG2CHARS( 0x00600000 ), LONG2CHARS( 0x00E00000 ),
+      LONG2CHARS( 0X01E00000 ), LONG2CHARS( 0x03E00000 ), LONG2CHARS( 0x07E00000 ), LONG2CHARS( 0x0FE00000 ),
+      LONG2CHARS( 0X1FE00000 ), LONG2CHARS( 0x3FE00000 ), LONG2CHARS( 0x7FE00000 ), LONG2CHARS( 0xFFE00000 ),
+      LONG2CHARS( 0X00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ),
+      LONG2CHARS( 0X00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ),
+      LONG2CHARS( 0X00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ),
+      LONG2CHARS( 0X00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ),
+      LONG2CHARS( 0X00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 )},
+     {LONG2CHARS( 0X00000000 ), LONG2CHARS( 0x00400000 ), LONG2CHARS( 0x00C00000 ), LONG2CHARS( 0x01C00000 ),
+      LONG2CHARS( 0X03C00000 ), LONG2CHARS( 0x07C00000 ), LONG2CHARS( 0x0FC00000 ), LONG2CHARS( 0x1FC00000 ),
+      LONG2CHARS( 0X3FC00000 ), LONG2CHARS( 0x7FC00000 ), LONG2CHARS( 0xFFC00000 ), LONG2CHARS( 0x00000000 ),
+      LONG2CHARS( 0X00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ),
+      LONG2CHARS( 0X00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ),
+      LONG2CHARS( 0X00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ),
+      LONG2CHARS( 0X00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ),
+      LONG2CHARS( 0X00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 )},
+     {LONG2CHARS( 0X00000000 ), LONG2CHARS( 0x00800000 ), LONG2CHARS( 0x01800000 ), LONG2CHARS( 0x03800000 ),
+      LONG2CHARS( 0X07800000 ), LONG2CHARS( 0x0F800000 ), LONG2CHARS( 0x1F800000 ), LONG2CHARS( 0x3F800000 ),
+      LONG2CHARS( 0X7F800000 ), LONG2CHARS( 0xFF800000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ),
+      LONG2CHARS( 0X00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ),
+      LONG2CHARS( 0X00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ),
+      LONG2CHARS( 0X00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ),
+      LONG2CHARS( 0X00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ),
+      LONG2CHARS( 0X00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 )},
+     {LONG2CHARS( 0X00000000 ), LONG2CHARS( 0x01000000 ), LONG2CHARS( 0x03000000 ), LONG2CHARS( 0x07000000 ),
+      LONG2CHARS( 0X0F000000 ), LONG2CHARS( 0x1F000000 ), LONG2CHARS( 0x3F000000 ), LONG2CHARS( 0x7F000000 ),
+      LONG2CHARS( 0XFF000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ),
+      LONG2CHARS( 0X00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ),
+      LONG2CHARS( 0X00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ),
+      LONG2CHARS( 0X00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ),
+      LONG2CHARS( 0X00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ),
+      LONG2CHARS( 0X00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 )},
+     {LONG2CHARS( 0X00000000 ), LONG2CHARS( 0x02000000 ), LONG2CHARS( 0x06000000 ), LONG2CHARS( 0x0E000000 ),
+      LONG2CHARS( 0X1E000000 ), LONG2CHARS( 0x3E000000 ), LONG2CHARS( 0x7E000000 ), LONG2CHARS( 0xFE000000 ),
+      LONG2CHARS( 0X00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ),
+      LONG2CHARS( 0X00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ),
+      LONG2CHARS( 0X00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ),
+      LONG2CHARS( 0X00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ),
+      LONG2CHARS( 0X00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ),
+      LONG2CHARS( 0X00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 )},
+     {LONG2CHARS( 0X00000000 ), LONG2CHARS( 0x04000000 ), LONG2CHARS( 0x0C000000 ), LONG2CHARS( 0x1C000000 ),
+      LONG2CHARS( 0X3C000000 ), LONG2CHARS( 0x7C000000 ), LONG2CHARS( 0xFC000000 ), LONG2CHARS( 0x00000000 ),
+      LONG2CHARS( 0X00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ),
+      LONG2CHARS( 0X00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ),
+      LONG2CHARS( 0X00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ),
+      LONG2CHARS( 0X00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ),
+      LONG2CHARS( 0X00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ),
+      LONG2CHARS( 0X00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 )},
+     {LONG2CHARS( 0X00000000 ), LONG2CHARS( 0x08000000 ), LONG2CHARS( 0x18000000 ), LONG2CHARS( 0x38000000 ),
+      LONG2CHARS( 0X78000000 ), LONG2CHARS( 0xF8000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ),
+      LONG2CHARS( 0X00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ),
+      LONG2CHARS( 0X00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ),
+      LONG2CHARS( 0X00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ),
+      LONG2CHARS( 0X00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ),
+      LONG2CHARS( 0X00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ),
+      LONG2CHARS( 0X00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 )},
+     {LONG2CHARS( 0X00000000 ), LONG2CHARS( 0x10000000 ), LONG2CHARS( 0x30000000 ), LONG2CHARS( 0x70000000 ),
+      LONG2CHARS( 0XF0000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ),
+      LONG2CHARS( 0X00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ),
+      LONG2CHARS( 0X00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ),
+      LONG2CHARS( 0X00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ),
+      LONG2CHARS( 0X00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ),
+      LONG2CHARS( 0X00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ),
+      LONG2CHARS( 0X00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 )},
+     {LONG2CHARS( 0X00000000 ), LONG2CHARS( 0x20000000 ), LONG2CHARS( 0x60000000 ), LONG2CHARS( 0xE0000000 ),
+      LONG2CHARS( 0X00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ),
+      LONG2CHARS( 0X00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ),
+      LONG2CHARS( 0X00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ),
+      LONG2CHARS( 0X00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ),
+      LONG2CHARS( 0X00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ),
+      LONG2CHARS( 0X00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ),
+      LONG2CHARS( 0X00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 )},
+     {LONG2CHARS( 0X00000000 ), LONG2CHARS( 0x40000000 ), LONG2CHARS( 0xC0000000 ), LONG2CHARS( 0x00000000 ),
+      LONG2CHARS( 0X00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ),
+      LONG2CHARS( 0X00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ),
+      LONG2CHARS( 0X00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ),
+      LONG2CHARS( 0X00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ),
+      LONG2CHARS( 0X00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ),
+      LONG2CHARS( 0X00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ),
+      LONG2CHARS( 0X00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 )},
+     {LONG2CHARS( 0X00000000 ), LONG2CHARS( 0x80000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ),
+      LONG2CHARS( 0X00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ),
+      LONG2CHARS( 0X00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ),
+      LONG2CHARS( 0X00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ),
+      LONG2CHARS( 0X00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ),
+      LONG2CHARS( 0X00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ),
+      LONG2CHARS( 0X00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ),
+      LONG2CHARS( 0X00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 ), LONG2CHARS( 0x00000000 )},
+};
+#else /* PPW == 64 */
+unsigned long partmasks[PPW][PPW] = {
+       {
+               LONG2CHARS( 0xFFFFFFFFFFFFFFFF ),
+               LONG2CHARS( 0x0000000000000001 ),
+               LONG2CHARS( 0x0000000000000003 ),
+               LONG2CHARS( 0x0000000000000007 ),
+               LONG2CHARS( 0x000000000000000F ),
+               LONG2CHARS( 0x000000000000001F ),
+               LONG2CHARS( 0x000000000000003F ),
+               LONG2CHARS( 0x000000000000007F ),
+               LONG2CHARS( 0x00000000000000FF ),
+               LONG2CHARS( 0x00000000000001FF ),
+               LONG2CHARS( 0x00000000000003FF ),
+               LONG2CHARS( 0x00000000000007FF ),
+               LONG2CHARS( 0x0000000000000FFF ),
+               LONG2CHARS( 0x0000000000001FFF ),
+               LONG2CHARS( 0x0000000000003FFF ),
+               LONG2CHARS( 0x0000000000007FFF ),
+               LONG2CHARS( 0x000000000000FFFF ),
+               LONG2CHARS( 0x000000000001FFFF ),
+               LONG2CHARS( 0x000000000003FFFF ),
+               LONG2CHARS( 0x000000000007FFFF ),
+               LONG2CHARS( 0x00000000000FFFFF ),
+               LONG2CHARS( 0x00000000001FFFFF ),
+               LONG2CHARS( 0x00000000003FFFFF ),
+               LONG2CHARS( 0x00000000007FFFFF ),
+               LONG2CHARS( 0x0000000000FFFFFF ),
+               LONG2CHARS( 0x0000000001FFFFFF ),
+               LONG2CHARS( 0x0000000003FFFFFF ),
+               LONG2CHARS( 0x0000000007FFFFFF ),
+               LONG2CHARS( 0x000000000FFFFFFF ),
+               LONG2CHARS( 0x000000001FFFFFFF ),
+               LONG2CHARS( 0x000000003FFFFFFF ),
+               LONG2CHARS( 0x000000007FFFFFFF ),
+               LONG2CHARS( 0x00000000FFFFFFFF ),
+               LONG2CHARS( 0x00000001FFFFFFFF ),
+               LONG2CHARS( 0x00000003FFFFFFFF ),
+               LONG2CHARS( 0x00000007FFFFFFFF ),
+               LONG2CHARS( 0x0000000FFFFFFFFF ),
+               LONG2CHARS( 0x0000001FFFFFFFFF ),
+               LONG2CHARS( 0x0000003FFFFFFFFF ),
+               LONG2CHARS( 0x0000007FFFFFFFFF ),
+               LONG2CHARS( 0x000000FFFFFFFFFF ),
+               LONG2CHARS( 0x000001FFFFFFFFFF ),
+               LONG2CHARS( 0x000003FFFFFFFFFF ),
+               LONG2CHARS( 0x000007FFFFFFFFFF ),
+               LONG2CHARS( 0x00000FFFFFFFFFFF ),
+               LONG2CHARS( 0x00001FFFFFFFFFFF ),
+               LONG2CHARS( 0x00003FFFFFFFFFFF ),
+               LONG2CHARS( 0x00007FFFFFFFFFFF ),
+               LONG2CHARS( 0x0000FFFFFFFFFFFF ),
+               LONG2CHARS( 0x0001FFFFFFFFFFFF ),
+               LONG2CHARS( 0x0003FFFFFFFFFFFF ),
+               LONG2CHARS( 0x0007FFFFFFFFFFFF ),
+               LONG2CHARS( 0x000FFFFFFFFFFFFF ),
+               LONG2CHARS( 0x001FFFFFFFFFFFFF ),
+               LONG2CHARS( 0x003FFFFFFFFFFFFF ),
+               LONG2CHARS( 0x007FFFFFFFFFFFFF ),
+               LONG2CHARS( 0x00FFFFFFFFFFFFFF ),
+               LONG2CHARS( 0x01FFFFFFFFFFFFFF ),
+               LONG2CHARS( 0x03FFFFFFFFFFFFFF ),
+               LONG2CHARS( 0x07FFFFFFFFFFFFFF ),
+               LONG2CHARS( 0x0FFFFFFFFFFFFFFF ),
+               LONG2CHARS( 0x1FFFFFFFFFFFFFFF ),
+               LONG2CHARS( 0x3FFFFFFFFFFFFFFF ),
+               LONG2CHARS( 0x7FFFFFFFFFFFFFFF ),
+       },
+       {
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000002 ),
+               LONG2CHARS( 0x0000000000000006 ),
+               LONG2CHARS( 0x000000000000000E ),
+               LONG2CHARS( 0x000000000000001E ),
+               LONG2CHARS( 0x000000000000003E ),
+               LONG2CHARS( 0x000000000000007E ),
+               LONG2CHARS( 0x00000000000000FE ),
+               LONG2CHARS( 0x00000000000001FE ),
+               LONG2CHARS( 0x00000000000003FE ),
+               LONG2CHARS( 0x00000000000007FE ),
+               LONG2CHARS( 0x0000000000000FFE ),
+               LONG2CHARS( 0x0000000000001FFE ),
+               LONG2CHARS( 0x0000000000003FFE ),
+               LONG2CHARS( 0x0000000000007FFE ),
+               LONG2CHARS( 0x000000000000FFFE ),
+               LONG2CHARS( 0x000000000001FFFE ),
+               LONG2CHARS( 0x000000000003FFFE ),
+               LONG2CHARS( 0x000000000007FFFE ),
+               LONG2CHARS( 0x00000000000FFFFE ),
+               LONG2CHARS( 0x00000000001FFFFE ),
+               LONG2CHARS( 0x00000000003FFFFE ),
+               LONG2CHARS( 0x00000000007FFFFE ),
+               LONG2CHARS( 0x0000000000FFFFFE ),
+               LONG2CHARS( 0x0000000001FFFFFE ),
+               LONG2CHARS( 0x0000000003FFFFFE ),
+               LONG2CHARS( 0x0000000007FFFFFE ),
+               LONG2CHARS( 0x000000000FFFFFFE ),
+               LONG2CHARS( 0x000000001FFFFFFE ),
+               LONG2CHARS( 0x000000003FFFFFFE ),
+               LONG2CHARS( 0x000000007FFFFFFE ),
+               LONG2CHARS( 0x00000000FFFFFFFE ),
+               LONG2CHARS( 0x00000001FFFFFFFE ),
+               LONG2CHARS( 0x00000003FFFFFFFE ),
+               LONG2CHARS( 0x00000007FFFFFFFE ),
+               LONG2CHARS( 0x0000000FFFFFFFFE ),
+               LONG2CHARS( 0x0000001FFFFFFFFE ),
+               LONG2CHARS( 0x0000003FFFFFFFFE ),
+               LONG2CHARS( 0x0000007FFFFFFFFE ),
+               LONG2CHARS( 0x000000FFFFFFFFFE ),
+               LONG2CHARS( 0x000001FFFFFFFFFE ),
+               LONG2CHARS( 0x000003FFFFFFFFFE ),
+               LONG2CHARS( 0x000007FFFFFFFFFE ),
+               LONG2CHARS( 0x00000FFFFFFFFFFE ),
+               LONG2CHARS( 0x00001FFFFFFFFFFE ),
+               LONG2CHARS( 0x00003FFFFFFFFFFE ),
+               LONG2CHARS( 0x00007FFFFFFFFFFE ),
+               LONG2CHARS( 0x0000FFFFFFFFFFFE ),
+               LONG2CHARS( 0x0001FFFFFFFFFFFE ),
+               LONG2CHARS( 0x0003FFFFFFFFFFFE ),
+               LONG2CHARS( 0x0007FFFFFFFFFFFE ),
+               LONG2CHARS( 0x000FFFFFFFFFFFFE ),
+               LONG2CHARS( 0x001FFFFFFFFFFFFE ),
+               LONG2CHARS( 0x003FFFFFFFFFFFFE ),
+               LONG2CHARS( 0x007FFFFFFFFFFFFE ),
+               LONG2CHARS( 0x00FFFFFFFFFFFFFE ),
+               LONG2CHARS( 0x01FFFFFFFFFFFFFE ),
+               LONG2CHARS( 0x03FFFFFFFFFFFFFE ),
+               LONG2CHARS( 0x07FFFFFFFFFFFFFE ),
+               LONG2CHARS( 0x0FFFFFFFFFFFFFFE ),
+               LONG2CHARS( 0x1FFFFFFFFFFFFFFE ),
+               LONG2CHARS( 0x3FFFFFFFFFFFFFFE ),
+               LONG2CHARS( 0x7FFFFFFFFFFFFFFE ),
+               LONG2CHARS( 0xFFFFFFFFFFFFFFFE ),
+       },
+       {
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000004 ),
+               LONG2CHARS( 0x000000000000000C ),
+               LONG2CHARS( 0x000000000000001C ),
+               LONG2CHARS( 0x000000000000003C ),
+               LONG2CHARS( 0x000000000000007C ),
+               LONG2CHARS( 0x00000000000000FC ),
+               LONG2CHARS( 0x00000000000001FC ),
+               LONG2CHARS( 0x00000000000003FC ),
+               LONG2CHARS( 0x00000000000007FC ),
+               LONG2CHARS( 0x0000000000000FFC ),
+               LONG2CHARS( 0x0000000000001FFC ),
+               LONG2CHARS( 0x0000000000003FFC ),
+               LONG2CHARS( 0x0000000000007FFC ),
+               LONG2CHARS( 0x000000000000FFFC ),
+               LONG2CHARS( 0x000000000001FFFC ),
+               LONG2CHARS( 0x000000000003FFFC ),
+               LONG2CHARS( 0x000000000007FFFC ),
+               LONG2CHARS( 0x00000000000FFFFC ),
+               LONG2CHARS( 0x00000000001FFFFC ),
+               LONG2CHARS( 0x00000000003FFFFC ),
+               LONG2CHARS( 0x00000000007FFFFC ),
+               LONG2CHARS( 0x0000000000FFFFFC ),
+               LONG2CHARS( 0x0000000001FFFFFC ),
+               LONG2CHARS( 0x0000000003FFFFFC ),
+               LONG2CHARS( 0x0000000007FFFFFC ),
+               LONG2CHARS( 0x000000000FFFFFFC ),
+               LONG2CHARS( 0x000000001FFFFFFC ),
+               LONG2CHARS( 0x000000003FFFFFFC ),
+               LONG2CHARS( 0x000000007FFFFFFC ),
+               LONG2CHARS( 0x00000000FFFFFFFC ),
+               LONG2CHARS( 0x00000001FFFFFFFC ),
+               LONG2CHARS( 0x00000003FFFFFFFC ),
+               LONG2CHARS( 0x00000007FFFFFFFC ),
+               LONG2CHARS( 0x0000000FFFFFFFFC ),
+               LONG2CHARS( 0x0000001FFFFFFFFC ),
+               LONG2CHARS( 0x0000003FFFFFFFFC ),
+               LONG2CHARS( 0x0000007FFFFFFFFC ),
+               LONG2CHARS( 0x000000FFFFFFFFFC ),
+               LONG2CHARS( 0x000001FFFFFFFFFC ),
+               LONG2CHARS( 0x000003FFFFFFFFFC ),
+               LONG2CHARS( 0x000007FFFFFFFFFC ),
+               LONG2CHARS( 0x00000FFFFFFFFFFC ),
+               LONG2CHARS( 0x00001FFFFFFFFFFC ),
+               LONG2CHARS( 0x00003FFFFFFFFFFC ),
+               LONG2CHARS( 0x00007FFFFFFFFFFC ),
+               LONG2CHARS( 0x0000FFFFFFFFFFFC ),
+               LONG2CHARS( 0x0001FFFFFFFFFFFC ),
+               LONG2CHARS( 0x0003FFFFFFFFFFFC ),
+               LONG2CHARS( 0x0007FFFFFFFFFFFC ),
+               LONG2CHARS( 0x000FFFFFFFFFFFFC ),
+               LONG2CHARS( 0x001FFFFFFFFFFFFC ),
+               LONG2CHARS( 0x003FFFFFFFFFFFFC ),
+               LONG2CHARS( 0x007FFFFFFFFFFFFC ),
+               LONG2CHARS( 0x00FFFFFFFFFFFFFC ),
+               LONG2CHARS( 0x01FFFFFFFFFFFFFC ),
+               LONG2CHARS( 0x03FFFFFFFFFFFFFC ),
+               LONG2CHARS( 0x07FFFFFFFFFFFFFC ),
+               LONG2CHARS( 0x0FFFFFFFFFFFFFFC ),
+               LONG2CHARS( 0x1FFFFFFFFFFFFFFC ),
+               LONG2CHARS( 0x3FFFFFFFFFFFFFFC ),
+               LONG2CHARS( 0x7FFFFFFFFFFFFFFC ),
+               LONG2CHARS( 0xFFFFFFFFFFFFFFFC ),
+               LONG2CHARS( 0x0000000000000000 ),
+       },
+       {
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000008 ),
+               LONG2CHARS( 0x0000000000000018 ),
+               LONG2CHARS( 0x0000000000000038 ),
+               LONG2CHARS( 0x0000000000000078 ),
+               LONG2CHARS( 0x00000000000000F8 ),
+               LONG2CHARS( 0x00000000000001F8 ),
+               LONG2CHARS( 0x00000000000003F8 ),
+               LONG2CHARS( 0x00000000000007F8 ),
+               LONG2CHARS( 0x0000000000000FF8 ),
+               LONG2CHARS( 0x0000000000001FF8 ),
+               LONG2CHARS( 0x0000000000003FF8 ),
+               LONG2CHARS( 0x0000000000007FF8 ),
+               LONG2CHARS( 0x000000000000FFF8 ),
+               LONG2CHARS( 0x000000000001FFF8 ),
+               LONG2CHARS( 0x000000000003FFF8 ),
+               LONG2CHARS( 0x000000000007FFF8 ),
+               LONG2CHARS( 0x00000000000FFFF8 ),
+               LONG2CHARS( 0x00000000001FFFF8 ),
+               LONG2CHARS( 0x00000000003FFFF8 ),
+               LONG2CHARS( 0x00000000007FFFF8 ),
+               LONG2CHARS( 0x0000000000FFFFF8 ),
+               LONG2CHARS( 0x0000000001FFFFF8 ),
+               LONG2CHARS( 0x0000000003FFFFF8 ),
+               LONG2CHARS( 0x0000000007FFFFF8 ),
+               LONG2CHARS( 0x000000000FFFFFF8 ),
+               LONG2CHARS( 0x000000001FFFFFF8 ),
+               LONG2CHARS( 0x000000003FFFFFF8 ),
+               LONG2CHARS( 0x000000007FFFFFF8 ),
+               LONG2CHARS( 0x00000000FFFFFFF8 ),
+               LONG2CHARS( 0x00000001FFFFFFF8 ),
+               LONG2CHARS( 0x00000003FFFFFFF8 ),
+               LONG2CHARS( 0x00000007FFFFFFF8 ),
+               LONG2CHARS( 0x0000000FFFFFFFF8 ),
+               LONG2CHARS( 0x0000001FFFFFFFF8 ),
+               LONG2CHARS( 0x0000003FFFFFFFF8 ),
+               LONG2CHARS( 0x0000007FFFFFFFF8 ),
+               LONG2CHARS( 0x000000FFFFFFFFF8 ),
+               LONG2CHARS( 0x000001FFFFFFFFF8 ),
+               LONG2CHARS( 0x000003FFFFFFFFF8 ),
+               LONG2CHARS( 0x000007FFFFFFFFF8 ),
+               LONG2CHARS( 0x00000FFFFFFFFFF8 ),
+               LONG2CHARS( 0x00001FFFFFFFFFF8 ),
+               LONG2CHARS( 0x00003FFFFFFFFFF8 ),
+               LONG2CHARS( 0x00007FFFFFFFFFF8 ),
+               LONG2CHARS( 0x0000FFFFFFFFFFF8 ),
+               LONG2CHARS( 0x0001FFFFFFFFFFF8 ),
+               LONG2CHARS( 0x0003FFFFFFFFFFF8 ),
+               LONG2CHARS( 0x0007FFFFFFFFFFF8 ),
+               LONG2CHARS( 0x000FFFFFFFFFFFF8 ),
+               LONG2CHARS( 0x001FFFFFFFFFFFF8 ),
+               LONG2CHARS( 0x003FFFFFFFFFFFF8 ),
+               LONG2CHARS( 0x007FFFFFFFFFFFF8 ),
+               LONG2CHARS( 0x00FFFFFFFFFFFFF8 ),
+               LONG2CHARS( 0x01FFFFFFFFFFFFF8 ),
+               LONG2CHARS( 0x03FFFFFFFFFFFFF8 ),
+               LONG2CHARS( 0x07FFFFFFFFFFFFF8 ),
+               LONG2CHARS( 0x0FFFFFFFFFFFFFF8 ),
+               LONG2CHARS( 0x1FFFFFFFFFFFFFF8 ),
+               LONG2CHARS( 0x3FFFFFFFFFFFFFF8 ),
+               LONG2CHARS( 0x7FFFFFFFFFFFFFF8 ),
+               LONG2CHARS( 0xFFFFFFFFFFFFFFF8 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+       },
+       {
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000010 ),
+               LONG2CHARS( 0x0000000000000030 ),
+               LONG2CHARS( 0x0000000000000070 ),
+               LONG2CHARS( 0x00000000000000F0 ),
+               LONG2CHARS( 0x00000000000001F0 ),
+               LONG2CHARS( 0x00000000000003F0 ),
+               LONG2CHARS( 0x00000000000007F0 ),
+               LONG2CHARS( 0x0000000000000FF0 ),
+               LONG2CHARS( 0x0000000000001FF0 ),
+               LONG2CHARS( 0x0000000000003FF0 ),
+               LONG2CHARS( 0x0000000000007FF0 ),
+               LONG2CHARS( 0x000000000000FFF0 ),
+               LONG2CHARS( 0x000000000001FFF0 ),
+               LONG2CHARS( 0x000000000003FFF0 ),
+               LONG2CHARS( 0x000000000007FFF0 ),
+               LONG2CHARS( 0x00000000000FFFF0 ),
+               LONG2CHARS( 0x00000000001FFFF0 ),
+               LONG2CHARS( 0x00000000003FFFF0 ),
+               LONG2CHARS( 0x00000000007FFFF0 ),
+               LONG2CHARS( 0x0000000000FFFFF0 ),
+               LONG2CHARS( 0x0000000001FFFFF0 ),
+               LONG2CHARS( 0x0000000003FFFFF0 ),
+               LONG2CHARS( 0x0000000007FFFFF0 ),
+               LONG2CHARS( 0x000000000FFFFFF0 ),
+               LONG2CHARS( 0x000000001FFFFFF0 ),
+               LONG2CHARS( 0x000000003FFFFFF0 ),
+               LONG2CHARS( 0x000000007FFFFFF0 ),
+               LONG2CHARS( 0x00000000FFFFFFF0 ),
+               LONG2CHARS( 0x00000001FFFFFFF0 ),
+               LONG2CHARS( 0x00000003FFFFFFF0 ),
+               LONG2CHARS( 0x00000007FFFFFFF0 ),
+               LONG2CHARS( 0x0000000FFFFFFFF0 ),
+               LONG2CHARS( 0x0000001FFFFFFFF0 ),
+               LONG2CHARS( 0x0000003FFFFFFFF0 ),
+               LONG2CHARS( 0x0000007FFFFFFFF0 ),
+               LONG2CHARS( 0x000000FFFFFFFFF0 ),
+               LONG2CHARS( 0x000001FFFFFFFFF0 ),
+               LONG2CHARS( 0x000003FFFFFFFFF0 ),
+               LONG2CHARS( 0x000007FFFFFFFFF0 ),
+               LONG2CHARS( 0x00000FFFFFFFFFF0 ),
+               LONG2CHARS( 0x00001FFFFFFFFFF0 ),
+               LONG2CHARS( 0x00003FFFFFFFFFF0 ),
+               LONG2CHARS( 0x00007FFFFFFFFFF0 ),
+               LONG2CHARS( 0x0000FFFFFFFFFFF0 ),
+               LONG2CHARS( 0x0001FFFFFFFFFFF0 ),
+               LONG2CHARS( 0x0003FFFFFFFFFFF0 ),
+               LONG2CHARS( 0x0007FFFFFFFFFFF0 ),
+               LONG2CHARS( 0x000FFFFFFFFFFFF0 ),
+               LONG2CHARS( 0x001FFFFFFFFFFFF0 ),
+               LONG2CHARS( 0x003FFFFFFFFFFFF0 ),
+               LONG2CHARS( 0x007FFFFFFFFFFFF0 ),
+               LONG2CHARS( 0x00FFFFFFFFFFFFF0 ),
+               LONG2CHARS( 0x01FFFFFFFFFFFFF0 ),
+               LONG2CHARS( 0x03FFFFFFFFFFFFF0 ),
+               LONG2CHARS( 0x07FFFFFFFFFFFFF0 ),
+               LONG2CHARS( 0x0FFFFFFFFFFFFFF0 ),
+               LONG2CHARS( 0x1FFFFFFFFFFFFFF0 ),
+               LONG2CHARS( 0x3FFFFFFFFFFFFFF0 ),
+               LONG2CHARS( 0x7FFFFFFFFFFFFFF0 ),
+               LONG2CHARS( 0xFFFFFFFFFFFFFFF0 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+       },
+       {
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000020 ),
+               LONG2CHARS( 0x0000000000000060 ),
+               LONG2CHARS( 0x00000000000000E0 ),
+               LONG2CHARS( 0x00000000000001E0 ),
+               LONG2CHARS( 0x00000000000003E0 ),
+               LONG2CHARS( 0x00000000000007E0 ),
+               LONG2CHARS( 0x0000000000000FE0 ),
+               LONG2CHARS( 0x0000000000001FE0 ),
+               LONG2CHARS( 0x0000000000003FE0 ),
+               LONG2CHARS( 0x0000000000007FE0 ),
+               LONG2CHARS( 0x000000000000FFE0 ),
+               LONG2CHARS( 0x000000000001FFE0 ),
+               LONG2CHARS( 0x000000000003FFE0 ),
+               LONG2CHARS( 0x000000000007FFE0 ),
+               LONG2CHARS( 0x00000000000FFFE0 ),
+               LONG2CHARS( 0x00000000001FFFE0 ),
+               LONG2CHARS( 0x00000000003FFFE0 ),
+               LONG2CHARS( 0x00000000007FFFE0 ),
+               LONG2CHARS( 0x0000000000FFFFE0 ),
+               LONG2CHARS( 0x0000000001FFFFE0 ),
+               LONG2CHARS( 0x0000000003FFFFE0 ),
+               LONG2CHARS( 0x0000000007FFFFE0 ),
+               LONG2CHARS( 0x000000000FFFFFE0 ),
+               LONG2CHARS( 0x000000001FFFFFE0 ),
+               LONG2CHARS( 0x000000003FFFFFE0 ),
+               LONG2CHARS( 0x000000007FFFFFE0 ),
+               LONG2CHARS( 0x00000000FFFFFFE0 ),
+               LONG2CHARS( 0x00000001FFFFFFE0 ),
+               LONG2CHARS( 0x00000003FFFFFFE0 ),
+               LONG2CHARS( 0x00000007FFFFFFE0 ),
+               LONG2CHARS( 0x0000000FFFFFFFE0 ),
+               LONG2CHARS( 0x0000001FFFFFFFE0 ),
+               LONG2CHARS( 0x0000003FFFFFFFE0 ),
+               LONG2CHARS( 0x0000007FFFFFFFE0 ),
+               LONG2CHARS( 0x000000FFFFFFFFE0 ),
+               LONG2CHARS( 0x000001FFFFFFFFE0 ),
+               LONG2CHARS( 0x000003FFFFFFFFE0 ),
+               LONG2CHARS( 0x000007FFFFFFFFE0 ),
+               LONG2CHARS( 0x00000FFFFFFFFFE0 ),
+               LONG2CHARS( 0x00001FFFFFFFFFE0 ),
+               LONG2CHARS( 0x00003FFFFFFFFFE0 ),
+               LONG2CHARS( 0x00007FFFFFFFFFE0 ),
+               LONG2CHARS( 0x0000FFFFFFFFFFE0 ),
+               LONG2CHARS( 0x0001FFFFFFFFFFE0 ),
+               LONG2CHARS( 0x0003FFFFFFFFFFE0 ),
+               LONG2CHARS( 0x0007FFFFFFFFFFE0 ),
+               LONG2CHARS( 0x000FFFFFFFFFFFE0 ),
+               LONG2CHARS( 0x001FFFFFFFFFFFE0 ),
+               LONG2CHARS( 0x003FFFFFFFFFFFE0 ),
+               LONG2CHARS( 0x007FFFFFFFFFFFE0 ),
+               LONG2CHARS( 0x00FFFFFFFFFFFFE0 ),
+               LONG2CHARS( 0x01FFFFFFFFFFFFE0 ),
+               LONG2CHARS( 0x03FFFFFFFFFFFFE0 ),
+               LONG2CHARS( 0x07FFFFFFFFFFFFE0 ),
+               LONG2CHARS( 0x0FFFFFFFFFFFFFE0 ),
+               LONG2CHARS( 0x1FFFFFFFFFFFFFE0 ),
+               LONG2CHARS( 0x3FFFFFFFFFFFFFE0 ),
+               LONG2CHARS( 0x7FFFFFFFFFFFFFE0 ),
+               LONG2CHARS( 0xFFFFFFFFFFFFFFE0 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+       },
+       {
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000040 ),
+               LONG2CHARS( 0x00000000000000C0 ),
+               LONG2CHARS( 0x00000000000001C0 ),
+               LONG2CHARS( 0x00000000000003C0 ),
+               LONG2CHARS( 0x00000000000007C0 ),
+               LONG2CHARS( 0x0000000000000FC0 ),
+               LONG2CHARS( 0x0000000000001FC0 ),
+               LONG2CHARS( 0x0000000000003FC0 ),
+               LONG2CHARS( 0x0000000000007FC0 ),
+               LONG2CHARS( 0x000000000000FFC0 ),
+               LONG2CHARS( 0x000000000001FFC0 ),
+               LONG2CHARS( 0x000000000003FFC0 ),
+               LONG2CHARS( 0x000000000007FFC0 ),
+               LONG2CHARS( 0x00000000000FFFC0 ),
+               LONG2CHARS( 0x00000000001FFFC0 ),
+               LONG2CHARS( 0x00000000003FFFC0 ),
+               LONG2CHARS( 0x00000000007FFFC0 ),
+               LONG2CHARS( 0x0000000000FFFFC0 ),
+               LONG2CHARS( 0x0000000001FFFFC0 ),
+               LONG2CHARS( 0x0000000003FFFFC0 ),
+               LONG2CHARS( 0x0000000007FFFFC0 ),
+               LONG2CHARS( 0x000000000FFFFFC0 ),
+               LONG2CHARS( 0x000000001FFFFFC0 ),
+               LONG2CHARS( 0x000000003FFFFFC0 ),
+               LONG2CHARS( 0x000000007FFFFFC0 ),
+               LONG2CHARS( 0x00000000FFFFFFC0 ),
+               LONG2CHARS( 0x00000001FFFFFFC0 ),
+               LONG2CHARS( 0x00000003FFFFFFC0 ),
+               LONG2CHARS( 0x00000007FFFFFFC0 ),
+               LONG2CHARS( 0x0000000FFFFFFFC0 ),
+               LONG2CHARS( 0x0000001FFFFFFFC0 ),
+               LONG2CHARS( 0x0000003FFFFFFFC0 ),
+               LONG2CHARS( 0x0000007FFFFFFFC0 ),
+               LONG2CHARS( 0x000000FFFFFFFFC0 ),
+               LONG2CHARS( 0x000001FFFFFFFFC0 ),
+               LONG2CHARS( 0x000003FFFFFFFFC0 ),
+               LONG2CHARS( 0x000007FFFFFFFFC0 ),
+               LONG2CHARS( 0x00000FFFFFFFFFC0 ),
+               LONG2CHARS( 0x00001FFFFFFFFFC0 ),
+               LONG2CHARS( 0x00003FFFFFFFFFC0 ),
+               LONG2CHARS( 0x00007FFFFFFFFFC0 ),
+               LONG2CHARS( 0x0000FFFFFFFFFFC0 ),
+               LONG2CHARS( 0x0001FFFFFFFFFFC0 ),
+               LONG2CHARS( 0x0003FFFFFFFFFFC0 ),
+               LONG2CHARS( 0x0007FFFFFFFFFFC0 ),
+               LONG2CHARS( 0x000FFFFFFFFFFFC0 ),
+               LONG2CHARS( 0x001FFFFFFFFFFFC0 ),
+               LONG2CHARS( 0x003FFFFFFFFFFFC0 ),
+               LONG2CHARS( 0x007FFFFFFFFFFFC0 ),
+               LONG2CHARS( 0x00FFFFFFFFFFFFC0 ),
+               LONG2CHARS( 0x01FFFFFFFFFFFFC0 ),
+               LONG2CHARS( 0x03FFFFFFFFFFFFC0 ),
+               LONG2CHARS( 0x07FFFFFFFFFFFFC0 ),
+               LONG2CHARS( 0x0FFFFFFFFFFFFFC0 ),
+               LONG2CHARS( 0x1FFFFFFFFFFFFFC0 ),
+               LONG2CHARS( 0x3FFFFFFFFFFFFFC0 ),
+               LONG2CHARS( 0x7FFFFFFFFFFFFFC0 ),
+               LONG2CHARS( 0xFFFFFFFFFFFFFFC0 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+       },
+       {
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000080 ),
+               LONG2CHARS( 0x0000000000000180 ),
+               LONG2CHARS( 0x0000000000000380 ),
+               LONG2CHARS( 0x0000000000000780 ),
+               LONG2CHARS( 0x0000000000000F80 ),
+               LONG2CHARS( 0x0000000000001F80 ),
+               LONG2CHARS( 0x0000000000003F80 ),
+               LONG2CHARS( 0x0000000000007F80 ),
+               LONG2CHARS( 0x000000000000FF80 ),
+               LONG2CHARS( 0x000000000001FF80 ),
+               LONG2CHARS( 0x000000000003FF80 ),
+               LONG2CHARS( 0x000000000007FF80 ),
+               LONG2CHARS( 0x00000000000FFF80 ),
+               LONG2CHARS( 0x00000000001FFF80 ),
+               LONG2CHARS( 0x00000000003FFF80 ),
+               LONG2CHARS( 0x00000000007FFF80 ),
+               LONG2CHARS( 0x0000000000FFFF80 ),
+               LONG2CHARS( 0x0000000001FFFF80 ),
+               LONG2CHARS( 0x0000000003FFFF80 ),
+               LONG2CHARS( 0x0000000007FFFF80 ),
+               LONG2CHARS( 0x000000000FFFFF80 ),
+               LONG2CHARS( 0x000000001FFFFF80 ),
+               LONG2CHARS( 0x000000003FFFFF80 ),
+               LONG2CHARS( 0x000000007FFFFF80 ),
+               LONG2CHARS( 0x00000000FFFFFF80 ),
+               LONG2CHARS( 0x00000001FFFFFF80 ),
+               LONG2CHARS( 0x00000003FFFFFF80 ),
+               LONG2CHARS( 0x00000007FFFFFF80 ),
+               LONG2CHARS( 0x0000000FFFFFFF80 ),
+               LONG2CHARS( 0x0000001FFFFFFF80 ),
+               LONG2CHARS( 0x0000003FFFFFFF80 ),
+               LONG2CHARS( 0x0000007FFFFFFF80 ),
+               LONG2CHARS( 0x000000FFFFFFFF80 ),
+               LONG2CHARS( 0x000001FFFFFFFF80 ),
+               LONG2CHARS( 0x000003FFFFFFFF80 ),
+               LONG2CHARS( 0x000007FFFFFFFF80 ),
+               LONG2CHARS( 0x00000FFFFFFFFF80 ),
+               LONG2CHARS( 0x00001FFFFFFFFF80 ),
+               LONG2CHARS( 0x00003FFFFFFFFF80 ),
+               LONG2CHARS( 0x00007FFFFFFFFF80 ),
+               LONG2CHARS( 0x0000FFFFFFFFFF80 ),
+               LONG2CHARS( 0x0001FFFFFFFFFF80 ),
+               LONG2CHARS( 0x0003FFFFFFFFFF80 ),
+               LONG2CHARS( 0x0007FFFFFFFFFF80 ),
+               LONG2CHARS( 0x000FFFFFFFFFFF80 ),
+               LONG2CHARS( 0x001FFFFFFFFFFF80 ),
+               LONG2CHARS( 0x003FFFFFFFFFFF80 ),
+               LONG2CHARS( 0x007FFFFFFFFFFF80 ),
+               LONG2CHARS( 0x00FFFFFFFFFFFF80 ),
+               LONG2CHARS( 0x01FFFFFFFFFFFF80 ),
+               LONG2CHARS( 0x03FFFFFFFFFFFF80 ),
+               LONG2CHARS( 0x07FFFFFFFFFFFF80 ),
+               LONG2CHARS( 0x0FFFFFFFFFFFFF80 ),
+               LONG2CHARS( 0x1FFFFFFFFFFFFF80 ),
+               LONG2CHARS( 0x3FFFFFFFFFFFFF80 ),
+               LONG2CHARS( 0x7FFFFFFFFFFFFF80 ),
+               LONG2CHARS( 0xFFFFFFFFFFFFFF80 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+       },
+       {
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000100 ),
+               LONG2CHARS( 0x0000000000000300 ),
+               LONG2CHARS( 0x0000000000000700 ),
+               LONG2CHARS( 0x0000000000000F00 ),
+               LONG2CHARS( 0x0000000000001F00 ),
+               LONG2CHARS( 0x0000000000003F00 ),
+               LONG2CHARS( 0x0000000000007F00 ),
+               LONG2CHARS( 0x000000000000FF00 ),
+               LONG2CHARS( 0x000000000001FF00 ),
+               LONG2CHARS( 0x000000000003FF00 ),
+               LONG2CHARS( 0x000000000007FF00 ),
+               LONG2CHARS( 0x00000000000FFF00 ),
+               LONG2CHARS( 0x00000000001FFF00 ),
+               LONG2CHARS( 0x00000000003FFF00 ),
+               LONG2CHARS( 0x00000000007FFF00 ),
+               LONG2CHARS( 0x0000000000FFFF00 ),
+               LONG2CHARS( 0x0000000001FFFF00 ),
+               LONG2CHARS( 0x0000000003FFFF00 ),
+               LONG2CHARS( 0x0000000007FFFF00 ),
+               LONG2CHARS( 0x000000000FFFFF00 ),
+               LONG2CHARS( 0x000000001FFFFF00 ),
+               LONG2CHARS( 0x000000003FFFFF00 ),
+               LONG2CHARS( 0x000000007FFFFF00 ),
+               LONG2CHARS( 0x00000000FFFFFF00 ),
+               LONG2CHARS( 0x00000001FFFFFF00 ),
+               LONG2CHARS( 0x00000003FFFFFF00 ),
+               LONG2CHARS( 0x00000007FFFFFF00 ),
+               LONG2CHARS( 0x0000000FFFFFFF00 ),
+               LONG2CHARS( 0x0000001FFFFFFF00 ),
+               LONG2CHARS( 0x0000003FFFFFFF00 ),
+               LONG2CHARS( 0x0000007FFFFFFF00 ),
+               LONG2CHARS( 0x000000FFFFFFFF00 ),
+               LONG2CHARS( 0x000001FFFFFFFF00 ),
+               LONG2CHARS( 0x000003FFFFFFFF00 ),
+               LONG2CHARS( 0x000007FFFFFFFF00 ),
+               LONG2CHARS( 0x00000FFFFFFFFF00 ),
+               LONG2CHARS( 0x00001FFFFFFFFF00 ),
+               LONG2CHARS( 0x00003FFFFFFFFF00 ),
+               LONG2CHARS( 0x00007FFFFFFFFF00 ),
+               LONG2CHARS( 0x0000FFFFFFFFFF00 ),
+               LONG2CHARS( 0x0001FFFFFFFFFF00 ),
+               LONG2CHARS( 0x0003FFFFFFFFFF00 ),
+               LONG2CHARS( 0x0007FFFFFFFFFF00 ),
+               LONG2CHARS( 0x000FFFFFFFFFFF00 ),
+               LONG2CHARS( 0x001FFFFFFFFFFF00 ),
+               LONG2CHARS( 0x003FFFFFFFFFFF00 ),
+               LONG2CHARS( 0x007FFFFFFFFFFF00 ),
+               LONG2CHARS( 0x00FFFFFFFFFFFF00 ),
+               LONG2CHARS( 0x01FFFFFFFFFFFF00 ),
+               LONG2CHARS( 0x03FFFFFFFFFFFF00 ),
+               LONG2CHARS( 0x07FFFFFFFFFFFF00 ),
+               LONG2CHARS( 0x0FFFFFFFFFFFFF00 ),
+               LONG2CHARS( 0x1FFFFFFFFFFFFF00 ),
+               LONG2CHARS( 0x3FFFFFFFFFFFFF00 ),
+               LONG2CHARS( 0x7FFFFFFFFFFFFF00 ),
+               LONG2CHARS( 0xFFFFFFFFFFFFFF00 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+       },
+       {
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000200 ),
+               LONG2CHARS( 0x0000000000000600 ),
+               LONG2CHARS( 0x0000000000000E00 ),
+               LONG2CHARS( 0x0000000000001E00 ),
+               LONG2CHARS( 0x0000000000003E00 ),
+               LONG2CHARS( 0x0000000000007E00 ),
+               LONG2CHARS( 0x000000000000FE00 ),
+               LONG2CHARS( 0x000000000001FE00 ),
+               LONG2CHARS( 0x000000000003FE00 ),
+               LONG2CHARS( 0x000000000007FE00 ),
+               LONG2CHARS( 0x00000000000FFE00 ),
+               LONG2CHARS( 0x00000000001FFE00 ),
+               LONG2CHARS( 0x00000000003FFE00 ),
+               LONG2CHARS( 0x00000000007FFE00 ),
+               LONG2CHARS( 0x0000000000FFFE00 ),
+               LONG2CHARS( 0x0000000001FFFE00 ),
+               LONG2CHARS( 0x0000000003FFFE00 ),
+               LONG2CHARS( 0x0000000007FFFE00 ),
+               LONG2CHARS( 0x000000000FFFFE00 ),
+               LONG2CHARS( 0x000000001FFFFE00 ),
+               LONG2CHARS( 0x000000003FFFFE00 ),
+               LONG2CHARS( 0x000000007FFFFE00 ),
+               LONG2CHARS( 0x00000000FFFFFE00 ),
+               LONG2CHARS( 0x00000001FFFFFE00 ),
+               LONG2CHARS( 0x00000003FFFFFE00 ),
+               LONG2CHARS( 0x00000007FFFFFE00 ),
+               LONG2CHARS( 0x0000000FFFFFFE00 ),
+               LONG2CHARS( 0x0000001FFFFFFE00 ),
+               LONG2CHARS( 0x0000003FFFFFFE00 ),
+               LONG2CHARS( 0x0000007FFFFFFE00 ),
+               LONG2CHARS( 0x000000FFFFFFFE00 ),
+               LONG2CHARS( 0x000001FFFFFFFE00 ),
+               LONG2CHARS( 0x000003FFFFFFFE00 ),
+               LONG2CHARS( 0x000007FFFFFFFE00 ),
+               LONG2CHARS( 0x00000FFFFFFFFE00 ),
+               LONG2CHARS( 0x00001FFFFFFFFE00 ),
+               LONG2CHARS( 0x00003FFFFFFFFE00 ),
+               LONG2CHARS( 0x00007FFFFFFFFE00 ),
+               LONG2CHARS( 0x0000FFFFFFFFFE00 ),
+               LONG2CHARS( 0x0001FFFFFFFFFE00 ),
+               LONG2CHARS( 0x0003FFFFFFFFFE00 ),
+               LONG2CHARS( 0x0007FFFFFFFFFE00 ),
+               LONG2CHARS( 0x000FFFFFFFFFFE00 ),
+               LONG2CHARS( 0x001FFFFFFFFFFE00 ),
+               LONG2CHARS( 0x003FFFFFFFFFFE00 ),
+               LONG2CHARS( 0x007FFFFFFFFFFE00 ),
+               LONG2CHARS( 0x00FFFFFFFFFFFE00 ),
+               LONG2CHARS( 0x01FFFFFFFFFFFE00 ),
+               LONG2CHARS( 0x03FFFFFFFFFFFE00 ),
+               LONG2CHARS( 0x07FFFFFFFFFFFE00 ),
+               LONG2CHARS( 0x0FFFFFFFFFFFFE00 ),
+               LONG2CHARS( 0x1FFFFFFFFFFFFE00 ),
+               LONG2CHARS( 0x3FFFFFFFFFFFFE00 ),
+               LONG2CHARS( 0x7FFFFFFFFFFFFE00 ),
+               LONG2CHARS( 0xFFFFFFFFFFFFFE00 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+       },
+       {
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000400 ),
+               LONG2CHARS( 0x0000000000000C00 ),
+               LONG2CHARS( 0x0000000000001C00 ),
+               LONG2CHARS( 0x0000000000003C00 ),
+               LONG2CHARS( 0x0000000000007C00 ),
+               LONG2CHARS( 0x000000000000FC00 ),
+               LONG2CHARS( 0x000000000001FC00 ),
+               LONG2CHARS( 0x000000000003FC00 ),
+               LONG2CHARS( 0x000000000007FC00 ),
+               LONG2CHARS( 0x00000000000FFC00 ),
+               LONG2CHARS( 0x00000000001FFC00 ),
+               LONG2CHARS( 0x00000000003FFC00 ),
+               LONG2CHARS( 0x00000000007FFC00 ),
+               LONG2CHARS( 0x0000000000FFFC00 ),
+               LONG2CHARS( 0x0000000001FFFC00 ),
+               LONG2CHARS( 0x0000000003FFFC00 ),
+               LONG2CHARS( 0x0000000007FFFC00 ),
+               LONG2CHARS( 0x000000000FFFFC00 ),
+               LONG2CHARS( 0x000000001FFFFC00 ),
+               LONG2CHARS( 0x000000003FFFFC00 ),
+               LONG2CHARS( 0x000000007FFFFC00 ),
+               LONG2CHARS( 0x00000000FFFFFC00 ),
+               LONG2CHARS( 0x00000001FFFFFC00 ),
+               LONG2CHARS( 0x00000003FFFFFC00 ),
+               LONG2CHARS( 0x00000007FFFFFC00 ),
+               LONG2CHARS( 0x0000000FFFFFFC00 ),
+               LONG2CHARS( 0x0000001FFFFFFC00 ),
+               LONG2CHARS( 0x0000003FFFFFFC00 ),
+               LONG2CHARS( 0x0000007FFFFFFC00 ),
+               LONG2CHARS( 0x000000FFFFFFFC00 ),
+               LONG2CHARS( 0x000001FFFFFFFC00 ),
+               LONG2CHARS( 0x000003FFFFFFFC00 ),
+               LONG2CHARS( 0x000007FFFFFFFC00 ),
+               LONG2CHARS( 0x00000FFFFFFFFC00 ),
+               LONG2CHARS( 0x00001FFFFFFFFC00 ),
+               LONG2CHARS( 0x00003FFFFFFFFC00 ),
+               LONG2CHARS( 0x00007FFFFFFFFC00 ),
+               LONG2CHARS( 0x0000FFFFFFFFFC00 ),
+               LONG2CHARS( 0x0001FFFFFFFFFC00 ),
+               LONG2CHARS( 0x0003FFFFFFFFFC00 ),
+               LONG2CHARS( 0x0007FFFFFFFFFC00 ),
+               LONG2CHARS( 0x000FFFFFFFFFFC00 ),
+               LONG2CHARS( 0x001FFFFFFFFFFC00 ),
+               LONG2CHARS( 0x003FFFFFFFFFFC00 ),
+               LONG2CHARS( 0x007FFFFFFFFFFC00 ),
+               LONG2CHARS( 0x00FFFFFFFFFFFC00 ),
+               LONG2CHARS( 0x01FFFFFFFFFFFC00 ),
+               LONG2CHARS( 0x03FFFFFFFFFFFC00 ),
+               LONG2CHARS( 0x07FFFFFFFFFFFC00 ),
+               LONG2CHARS( 0x0FFFFFFFFFFFFC00 ),
+               LONG2CHARS( 0x1FFFFFFFFFFFFC00 ),
+               LONG2CHARS( 0x3FFFFFFFFFFFFC00 ),
+               LONG2CHARS( 0x7FFFFFFFFFFFFC00 ),
+               LONG2CHARS( 0xFFFFFFFFFFFFFC00 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+       },
+       {
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000800 ),
+               LONG2CHARS( 0x0000000000001800 ),
+               LONG2CHARS( 0x0000000000003800 ),
+               LONG2CHARS( 0x0000000000007800 ),
+               LONG2CHARS( 0x000000000000F800 ),
+               LONG2CHARS( 0x000000000001F800 ),
+               LONG2CHARS( 0x000000000003F800 ),
+               LONG2CHARS( 0x000000000007F800 ),
+               LONG2CHARS( 0x00000000000FF800 ),
+               LONG2CHARS( 0x00000000001FF800 ),
+               LONG2CHARS( 0x00000000003FF800 ),
+               LONG2CHARS( 0x00000000007FF800 ),
+               LONG2CHARS( 0x0000000000FFF800 ),
+               LONG2CHARS( 0x0000000001FFF800 ),
+               LONG2CHARS( 0x0000000003FFF800 ),
+               LONG2CHARS( 0x0000000007FFF800 ),
+               LONG2CHARS( 0x000000000FFFF800 ),
+               LONG2CHARS( 0x000000001FFFF800 ),
+               LONG2CHARS( 0x000000003FFFF800 ),
+               LONG2CHARS( 0x000000007FFFF800 ),
+               LONG2CHARS( 0x00000000FFFFF800 ),
+               LONG2CHARS( 0x00000001FFFFF800 ),
+               LONG2CHARS( 0x00000003FFFFF800 ),
+               LONG2CHARS( 0x00000007FFFFF800 ),
+               LONG2CHARS( 0x0000000FFFFFF800 ),
+               LONG2CHARS( 0x0000001FFFFFF800 ),
+               LONG2CHARS( 0x0000003FFFFFF800 ),
+               LONG2CHARS( 0x0000007FFFFFF800 ),
+               LONG2CHARS( 0x000000FFFFFFF800 ),
+               LONG2CHARS( 0x000001FFFFFFF800 ),
+               LONG2CHARS( 0x000003FFFFFFF800 ),
+               LONG2CHARS( 0x000007FFFFFFF800 ),
+               LONG2CHARS( 0x00000FFFFFFFF800 ),
+               LONG2CHARS( 0x00001FFFFFFFF800 ),
+               LONG2CHARS( 0x00003FFFFFFFF800 ),
+               LONG2CHARS( 0x00007FFFFFFFF800 ),
+               LONG2CHARS( 0x0000FFFFFFFFF800 ),
+               LONG2CHARS( 0x0001FFFFFFFFF800 ),
+               LONG2CHARS( 0x0003FFFFFFFFF800 ),
+               LONG2CHARS( 0x0007FFFFFFFFF800 ),
+               LONG2CHARS( 0x000FFFFFFFFFF800 ),
+               LONG2CHARS( 0x001FFFFFFFFFF800 ),
+               LONG2CHARS( 0x003FFFFFFFFFF800 ),
+               LONG2CHARS( 0x007FFFFFFFFFF800 ),
+               LONG2CHARS( 0x00FFFFFFFFFFF800 ),
+               LONG2CHARS( 0x01FFFFFFFFFFF800 ),
+               LONG2CHARS( 0x03FFFFFFFFFFF800 ),
+               LONG2CHARS( 0x07FFFFFFFFFFF800 ),
+               LONG2CHARS( 0x0FFFFFFFFFFFF800 ),
+               LONG2CHARS( 0x1FFFFFFFFFFFF800 ),
+               LONG2CHARS( 0x3FFFFFFFFFFFF800 ),
+               LONG2CHARS( 0x7FFFFFFFFFFFF800 ),
+               LONG2CHARS( 0xFFFFFFFFFFFFF800 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+       },
+       {
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000001000 ),
+               LONG2CHARS( 0x0000000000003000 ),
+               LONG2CHARS( 0x0000000000007000 ),
+               LONG2CHARS( 0x000000000000F000 ),
+               LONG2CHARS( 0x000000000001F000 ),
+               LONG2CHARS( 0x000000000003F000 ),
+               LONG2CHARS( 0x000000000007F000 ),
+               LONG2CHARS( 0x00000000000FF000 ),
+               LONG2CHARS( 0x00000000001FF000 ),
+               LONG2CHARS( 0x00000000003FF000 ),
+               LONG2CHARS( 0x00000000007FF000 ),
+               LONG2CHARS( 0x0000000000FFF000 ),
+               LONG2CHARS( 0x0000000001FFF000 ),
+               LONG2CHARS( 0x0000000003FFF000 ),
+               LONG2CHARS( 0x0000000007FFF000 ),
+               LONG2CHARS( 0x000000000FFFF000 ),
+               LONG2CHARS( 0x000000001FFFF000 ),
+               LONG2CHARS( 0x000000003FFFF000 ),
+               LONG2CHARS( 0x000000007FFFF000 ),
+               LONG2CHARS( 0x00000000FFFFF000 ),
+               LONG2CHARS( 0x00000001FFFFF000 ),
+               LONG2CHARS( 0x00000003FFFFF000 ),
+               LONG2CHARS( 0x00000007FFFFF000 ),
+               LONG2CHARS( 0x0000000FFFFFF000 ),
+               LONG2CHARS( 0x0000001FFFFFF000 ),
+               LONG2CHARS( 0x0000003FFFFFF000 ),
+               LONG2CHARS( 0x0000007FFFFFF000 ),
+               LONG2CHARS( 0x000000FFFFFFF000 ),
+               LONG2CHARS( 0x000001FFFFFFF000 ),
+               LONG2CHARS( 0x000003FFFFFFF000 ),
+               LONG2CHARS( 0x000007FFFFFFF000 ),
+               LONG2CHARS( 0x00000FFFFFFFF000 ),
+               LONG2CHARS( 0x00001FFFFFFFF000 ),
+               LONG2CHARS( 0x00003FFFFFFFF000 ),
+               LONG2CHARS( 0x00007FFFFFFFF000 ),
+               LONG2CHARS( 0x0000FFFFFFFFF000 ),
+               LONG2CHARS( 0x0001FFFFFFFFF000 ),
+               LONG2CHARS( 0x0003FFFFFFFFF000 ),
+               LONG2CHARS( 0x0007FFFFFFFFF000 ),
+               LONG2CHARS( 0x000FFFFFFFFFF000 ),
+               LONG2CHARS( 0x001FFFFFFFFFF000 ),
+               LONG2CHARS( 0x003FFFFFFFFFF000 ),
+               LONG2CHARS( 0x007FFFFFFFFFF000 ),
+               LONG2CHARS( 0x00FFFFFFFFFFF000 ),
+               LONG2CHARS( 0x01FFFFFFFFFFF000 ),
+               LONG2CHARS( 0x03FFFFFFFFFFF000 ),
+               LONG2CHARS( 0x07FFFFFFFFFFF000 ),
+               LONG2CHARS( 0x0FFFFFFFFFFFF000 ),
+               LONG2CHARS( 0x1FFFFFFFFFFFF000 ),
+               LONG2CHARS( 0x3FFFFFFFFFFFF000 ),
+               LONG2CHARS( 0x7FFFFFFFFFFFF000 ),
+               LONG2CHARS( 0xFFFFFFFFFFFFF000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+       },
+       {
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000002000 ),
+               LONG2CHARS( 0x0000000000006000 ),
+               LONG2CHARS( 0x000000000000E000 ),
+               LONG2CHARS( 0x000000000001E000 ),
+               LONG2CHARS( 0x000000000003E000 ),
+               LONG2CHARS( 0x000000000007E000 ),
+               LONG2CHARS( 0x00000000000FE000 ),
+               LONG2CHARS( 0x00000000001FE000 ),
+               LONG2CHARS( 0x00000000003FE000 ),
+               LONG2CHARS( 0x00000000007FE000 ),
+               LONG2CHARS( 0x0000000000FFE000 ),
+               LONG2CHARS( 0x0000000001FFE000 ),
+               LONG2CHARS( 0x0000000003FFE000 ),
+               LONG2CHARS( 0x0000000007FFE000 ),
+               LONG2CHARS( 0x000000000FFFE000 ),
+               LONG2CHARS( 0x000000001FFFE000 ),
+               LONG2CHARS( 0x000000003FFFE000 ),
+               LONG2CHARS( 0x000000007FFFE000 ),
+               LONG2CHARS( 0x00000000FFFFE000 ),
+               LONG2CHARS( 0x00000001FFFFE000 ),
+               LONG2CHARS( 0x00000003FFFFE000 ),
+               LONG2CHARS( 0x00000007FFFFE000 ),
+               LONG2CHARS( 0x0000000FFFFFE000 ),
+               LONG2CHARS( 0x0000001FFFFFE000 ),
+               LONG2CHARS( 0x0000003FFFFFE000 ),
+               LONG2CHARS( 0x0000007FFFFFE000 ),
+               LONG2CHARS( 0x000000FFFFFFE000 ),
+               LONG2CHARS( 0x000001FFFFFFE000 ),
+               LONG2CHARS( 0x000003FFFFFFE000 ),
+               LONG2CHARS( 0x000007FFFFFFE000 ),
+               LONG2CHARS( 0x00000FFFFFFFE000 ),
+               LONG2CHARS( 0x00001FFFFFFFE000 ),
+               LONG2CHARS( 0x00003FFFFFFFE000 ),
+               LONG2CHARS( 0x00007FFFFFFFE000 ),
+               LONG2CHARS( 0x0000FFFFFFFFE000 ),
+               LONG2CHARS( 0x0001FFFFFFFFE000 ),
+               LONG2CHARS( 0x0003FFFFFFFFE000 ),
+               LONG2CHARS( 0x0007FFFFFFFFE000 ),
+               LONG2CHARS( 0x000FFFFFFFFFE000 ),
+               LONG2CHARS( 0x001FFFFFFFFFE000 ),
+               LONG2CHARS( 0x003FFFFFFFFFE000 ),
+               LONG2CHARS( 0x007FFFFFFFFFE000 ),
+               LONG2CHARS( 0x00FFFFFFFFFFE000 ),
+               LONG2CHARS( 0x01FFFFFFFFFFE000 ),
+               LONG2CHARS( 0x03FFFFFFFFFFE000 ),
+               LONG2CHARS( 0x07FFFFFFFFFFE000 ),
+               LONG2CHARS( 0x0FFFFFFFFFFFE000 ),
+               LONG2CHARS( 0x1FFFFFFFFFFFE000 ),
+               LONG2CHARS( 0x3FFFFFFFFFFFE000 ),
+               LONG2CHARS( 0x7FFFFFFFFFFFE000 ),
+               LONG2CHARS( 0xFFFFFFFFFFFFE000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+       },
+       {
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000004000 ),
+               LONG2CHARS( 0x000000000000C000 ),
+               LONG2CHARS( 0x000000000001C000 ),
+               LONG2CHARS( 0x000000000003C000 ),
+               LONG2CHARS( 0x000000000007C000 ),
+               LONG2CHARS( 0x00000000000FC000 ),
+               LONG2CHARS( 0x00000000001FC000 ),
+               LONG2CHARS( 0x00000000003FC000 ),
+               LONG2CHARS( 0x00000000007FC000 ),
+               LONG2CHARS( 0x0000000000FFC000 ),
+               LONG2CHARS( 0x0000000001FFC000 ),
+               LONG2CHARS( 0x0000000003FFC000 ),
+               LONG2CHARS( 0x0000000007FFC000 ),
+               LONG2CHARS( 0x000000000FFFC000 ),
+               LONG2CHARS( 0x000000001FFFC000 ),
+               LONG2CHARS( 0x000000003FFFC000 ),
+               LONG2CHARS( 0x000000007FFFC000 ),
+               LONG2CHARS( 0x00000000FFFFC000 ),
+               LONG2CHARS( 0x00000001FFFFC000 ),
+               LONG2CHARS( 0x00000003FFFFC000 ),
+               LONG2CHARS( 0x00000007FFFFC000 ),
+               LONG2CHARS( 0x0000000FFFFFC000 ),
+               LONG2CHARS( 0x0000001FFFFFC000 ),
+               LONG2CHARS( 0x0000003FFFFFC000 ),
+               LONG2CHARS( 0x0000007FFFFFC000 ),
+               LONG2CHARS( 0x000000FFFFFFC000 ),
+               LONG2CHARS( 0x000001FFFFFFC000 ),
+               LONG2CHARS( 0x000003FFFFFFC000 ),
+               LONG2CHARS( 0x000007FFFFFFC000 ),
+               LONG2CHARS( 0x00000FFFFFFFC000 ),
+               LONG2CHARS( 0x00001FFFFFFFC000 ),
+               LONG2CHARS( 0x00003FFFFFFFC000 ),
+               LONG2CHARS( 0x00007FFFFFFFC000 ),
+               LONG2CHARS( 0x0000FFFFFFFFC000 ),
+               LONG2CHARS( 0x0001FFFFFFFFC000 ),
+               LONG2CHARS( 0x0003FFFFFFFFC000 ),
+               LONG2CHARS( 0x0007FFFFFFFFC000 ),
+               LONG2CHARS( 0x000FFFFFFFFFC000 ),
+               LONG2CHARS( 0x001FFFFFFFFFC000 ),
+               LONG2CHARS( 0x003FFFFFFFFFC000 ),
+               LONG2CHARS( 0x007FFFFFFFFFC000 ),
+               LONG2CHARS( 0x00FFFFFFFFFFC000 ),
+               LONG2CHARS( 0x01FFFFFFFFFFC000 ),
+               LONG2CHARS( 0x03FFFFFFFFFFC000 ),
+               LONG2CHARS( 0x07FFFFFFFFFFC000 ),
+               LONG2CHARS( 0x0FFFFFFFFFFFC000 ),
+               LONG2CHARS( 0x1FFFFFFFFFFFC000 ),
+               LONG2CHARS( 0x3FFFFFFFFFFFC000 ),
+               LONG2CHARS( 0x7FFFFFFFFFFFC000 ),
+               LONG2CHARS( 0xFFFFFFFFFFFFC000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+       },
+       {
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000008000 ),
+               LONG2CHARS( 0x0000000000018000 ),
+               LONG2CHARS( 0x0000000000038000 ),
+               LONG2CHARS( 0x0000000000078000 ),
+               LONG2CHARS( 0x00000000000F8000 ),
+               LONG2CHARS( 0x00000000001F8000 ),
+               LONG2CHARS( 0x00000000003F8000 ),
+               LONG2CHARS( 0x00000000007F8000 ),
+               LONG2CHARS( 0x0000000000FF8000 ),
+               LONG2CHARS( 0x0000000001FF8000 ),
+               LONG2CHARS( 0x0000000003FF8000 ),
+               LONG2CHARS( 0x0000000007FF8000 ),
+               LONG2CHARS( 0x000000000FFF8000 ),
+               LONG2CHARS( 0x000000001FFF8000 ),
+               LONG2CHARS( 0x000000003FFF8000 ),
+               LONG2CHARS( 0x000000007FFF8000 ),
+               LONG2CHARS( 0x00000000FFFF8000 ),
+               LONG2CHARS( 0x00000001FFFF8000 ),
+               LONG2CHARS( 0x00000003FFFF8000 ),
+               LONG2CHARS( 0x00000007FFFF8000 ),
+               LONG2CHARS( 0x0000000FFFFF8000 ),
+               LONG2CHARS( 0x0000001FFFFF8000 ),
+               LONG2CHARS( 0x0000003FFFFF8000 ),
+               LONG2CHARS( 0x0000007FFFFF8000 ),
+               LONG2CHARS( 0x000000FFFFFF8000 ),
+               LONG2CHARS( 0x000001FFFFFF8000 ),
+               LONG2CHARS( 0x000003FFFFFF8000 ),
+               LONG2CHARS( 0x000007FFFFFF8000 ),
+               LONG2CHARS( 0x00000FFFFFFF8000 ),
+               LONG2CHARS( 0x00001FFFFFFF8000 ),
+               LONG2CHARS( 0x00003FFFFFFF8000 ),
+               LONG2CHARS( 0x00007FFFFFFF8000 ),
+               LONG2CHARS( 0x0000FFFFFFFF8000 ),
+               LONG2CHARS( 0x0001FFFFFFFF8000 ),
+               LONG2CHARS( 0x0003FFFFFFFF8000 ),
+               LONG2CHARS( 0x0007FFFFFFFF8000 ),
+               LONG2CHARS( 0x000FFFFFFFFF8000 ),
+               LONG2CHARS( 0x001FFFFFFFFF8000 ),
+               LONG2CHARS( 0x003FFFFFFFFF8000 ),
+               LONG2CHARS( 0x007FFFFFFFFF8000 ),
+               LONG2CHARS( 0x00FFFFFFFFFF8000 ),
+               LONG2CHARS( 0x01FFFFFFFFFF8000 ),
+               LONG2CHARS( 0x03FFFFFFFFFF8000 ),
+               LONG2CHARS( 0x07FFFFFFFFFF8000 ),
+               LONG2CHARS( 0x0FFFFFFFFFFF8000 ),
+               LONG2CHARS( 0x1FFFFFFFFFFF8000 ),
+               LONG2CHARS( 0x3FFFFFFFFFFF8000 ),
+               LONG2CHARS( 0x7FFFFFFFFFFF8000 ),
+               LONG2CHARS( 0xFFFFFFFFFFFF8000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+       },
+       {
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000010000 ),
+               LONG2CHARS( 0x0000000000030000 ),
+               LONG2CHARS( 0x0000000000070000 ),
+               LONG2CHARS( 0x00000000000F0000 ),
+               LONG2CHARS( 0x00000000001F0000 ),
+               LONG2CHARS( 0x00000000003F0000 ),
+               LONG2CHARS( 0x00000000007F0000 ),
+               LONG2CHARS( 0x0000000000FF0000 ),
+               LONG2CHARS( 0x0000000001FF0000 ),
+               LONG2CHARS( 0x0000000003FF0000 ),
+               LONG2CHARS( 0x0000000007FF0000 ),
+               LONG2CHARS( 0x000000000FFF0000 ),
+               LONG2CHARS( 0x000000001FFF0000 ),
+               LONG2CHARS( 0x000000003FFF0000 ),
+               LONG2CHARS( 0x000000007FFF0000 ),
+               LONG2CHARS( 0x00000000FFFF0000 ),
+               LONG2CHARS( 0x00000001FFFF0000 ),
+               LONG2CHARS( 0x00000003FFFF0000 ),
+               LONG2CHARS( 0x00000007FFFF0000 ),
+               LONG2CHARS( 0x0000000FFFFF0000 ),
+               LONG2CHARS( 0x0000001FFFFF0000 ),
+               LONG2CHARS( 0x0000003FFFFF0000 ),
+               LONG2CHARS( 0x0000007FFFFF0000 ),
+               LONG2CHARS( 0x000000FFFFFF0000 ),
+               LONG2CHARS( 0x000001FFFFFF0000 ),
+               LONG2CHARS( 0x000003FFFFFF0000 ),
+               LONG2CHARS( 0x000007FFFFFF0000 ),
+               LONG2CHARS( 0x00000FFFFFFF0000 ),
+               LONG2CHARS( 0x00001FFFFFFF0000 ),
+               LONG2CHARS( 0x00003FFFFFFF0000 ),
+               LONG2CHARS( 0x00007FFFFFFF0000 ),
+               LONG2CHARS( 0x0000FFFFFFFF0000 ),
+               LONG2CHARS( 0x0001FFFFFFFF0000 ),
+               LONG2CHARS( 0x0003FFFFFFFF0000 ),
+               LONG2CHARS( 0x0007FFFFFFFF0000 ),
+               LONG2CHARS( 0x000FFFFFFFFF0000 ),
+               LONG2CHARS( 0x001FFFFFFFFF0000 ),
+               LONG2CHARS( 0x003FFFFFFFFF0000 ),
+               LONG2CHARS( 0x007FFFFFFFFF0000 ),
+               LONG2CHARS( 0x00FFFFFFFFFF0000 ),
+               LONG2CHARS( 0x01FFFFFFFFFF0000 ),
+               LONG2CHARS( 0x03FFFFFFFFFF0000 ),
+               LONG2CHARS( 0x07FFFFFFFFFF0000 ),
+               LONG2CHARS( 0x0FFFFFFFFFFF0000 ),
+               LONG2CHARS( 0x1FFFFFFFFFFF0000 ),
+               LONG2CHARS( 0x3FFFFFFFFFFF0000 ),
+               LONG2CHARS( 0x7FFFFFFFFFFF0000 ),
+               LONG2CHARS( 0xFFFFFFFFFFFF0000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+       },
+       {
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000020000 ),
+               LONG2CHARS( 0x0000000000060000 ),
+               LONG2CHARS( 0x00000000000E0000 ),
+               LONG2CHARS( 0x00000000001E0000 ),
+               LONG2CHARS( 0x00000000003E0000 ),
+               LONG2CHARS( 0x00000000007E0000 ),
+               LONG2CHARS( 0x0000000000FE0000 ),
+               LONG2CHARS( 0x0000000001FE0000 ),
+               LONG2CHARS( 0x0000000003FE0000 ),
+               LONG2CHARS( 0x0000000007FE0000 ),
+               LONG2CHARS( 0x000000000FFE0000 ),
+               LONG2CHARS( 0x000000001FFE0000 ),
+               LONG2CHARS( 0x000000003FFE0000 ),
+               LONG2CHARS( 0x000000007FFE0000 ),
+               LONG2CHARS( 0x00000000FFFE0000 ),
+               LONG2CHARS( 0x00000001FFFE0000 ),
+               LONG2CHARS( 0x00000003FFFE0000 ),
+               LONG2CHARS( 0x00000007FFFE0000 ),
+               LONG2CHARS( 0x0000000FFFFE0000 ),
+               LONG2CHARS( 0x0000001FFFFE0000 ),
+               LONG2CHARS( 0x0000003FFFFE0000 ),
+               LONG2CHARS( 0x0000007FFFFE0000 ),
+               LONG2CHARS( 0x000000FFFFFE0000 ),
+               LONG2CHARS( 0x000001FFFFFE0000 ),
+               LONG2CHARS( 0x000003FFFFFE0000 ),
+               LONG2CHARS( 0x000007FFFFFE0000 ),
+               LONG2CHARS( 0x00000FFFFFFE0000 ),
+               LONG2CHARS( 0x00001FFFFFFE0000 ),
+               LONG2CHARS( 0x00003FFFFFFE0000 ),
+               LONG2CHARS( 0x00007FFFFFFE0000 ),
+               LONG2CHARS( 0x0000FFFFFFFE0000 ),
+               LONG2CHARS( 0x0001FFFFFFFE0000 ),
+               LONG2CHARS( 0x0003FFFFFFFE0000 ),
+               LONG2CHARS( 0x0007FFFFFFFE0000 ),
+               LONG2CHARS( 0x000FFFFFFFFE0000 ),
+               LONG2CHARS( 0x001FFFFFFFFE0000 ),
+               LONG2CHARS( 0x003FFFFFFFFE0000 ),
+               LONG2CHARS( 0x007FFFFFFFFE0000 ),
+               LONG2CHARS( 0x00FFFFFFFFFE0000 ),
+               LONG2CHARS( 0x01FFFFFFFFFE0000 ),
+               LONG2CHARS( 0x03FFFFFFFFFE0000 ),
+               LONG2CHARS( 0x07FFFFFFFFFE0000 ),
+               LONG2CHARS( 0x0FFFFFFFFFFE0000 ),
+               LONG2CHARS( 0x1FFFFFFFFFFE0000 ),
+               LONG2CHARS( 0x3FFFFFFFFFFE0000 ),
+               LONG2CHARS( 0x7FFFFFFFFFFE0000 ),
+               LONG2CHARS( 0xFFFFFFFFFFFE0000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+       },
+       {
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000040000 ),
+               LONG2CHARS( 0x00000000000C0000 ),
+               LONG2CHARS( 0x00000000001C0000 ),
+               LONG2CHARS( 0x00000000003C0000 ),
+               LONG2CHARS( 0x00000000007C0000 ),
+               LONG2CHARS( 0x0000000000FC0000 ),
+               LONG2CHARS( 0x0000000001FC0000 ),
+               LONG2CHARS( 0x0000000003FC0000 ),
+               LONG2CHARS( 0x0000000007FC0000 ),
+               LONG2CHARS( 0x000000000FFC0000 ),
+               LONG2CHARS( 0x000000001FFC0000 ),
+               LONG2CHARS( 0x000000003FFC0000 ),
+               LONG2CHARS( 0x000000007FFC0000 ),
+               LONG2CHARS( 0x00000000FFFC0000 ),
+               LONG2CHARS( 0x00000001FFFC0000 ),
+               LONG2CHARS( 0x00000003FFFC0000 ),
+               LONG2CHARS( 0x00000007FFFC0000 ),
+               LONG2CHARS( 0x0000000FFFFC0000 ),
+               LONG2CHARS( 0x0000001FFFFC0000 ),
+               LONG2CHARS( 0x0000003FFFFC0000 ),
+               LONG2CHARS( 0x0000007FFFFC0000 ),
+               LONG2CHARS( 0x000000FFFFFC0000 ),
+               LONG2CHARS( 0x000001FFFFFC0000 ),
+               LONG2CHARS( 0x000003FFFFFC0000 ),
+               LONG2CHARS( 0x000007FFFFFC0000 ),
+               LONG2CHARS( 0x00000FFFFFFC0000 ),
+               LONG2CHARS( 0x00001FFFFFFC0000 ),
+               LONG2CHARS( 0x00003FFFFFFC0000 ),
+               LONG2CHARS( 0x00007FFFFFFC0000 ),
+               LONG2CHARS( 0x0000FFFFFFFC0000 ),
+               LONG2CHARS( 0x0001FFFFFFFC0000 ),
+               LONG2CHARS( 0x0003FFFFFFFC0000 ),
+               LONG2CHARS( 0x0007FFFFFFFC0000 ),
+               LONG2CHARS( 0x000FFFFFFFFC0000 ),
+               LONG2CHARS( 0x001FFFFFFFFC0000 ),
+               LONG2CHARS( 0x003FFFFFFFFC0000 ),
+               LONG2CHARS( 0x007FFFFFFFFC0000 ),
+               LONG2CHARS( 0x00FFFFFFFFFC0000 ),
+               LONG2CHARS( 0x01FFFFFFFFFC0000 ),
+               LONG2CHARS( 0x03FFFFFFFFFC0000 ),
+               LONG2CHARS( 0x07FFFFFFFFFC0000 ),
+               LONG2CHARS( 0x0FFFFFFFFFFC0000 ),
+               LONG2CHARS( 0x1FFFFFFFFFFC0000 ),
+               LONG2CHARS( 0x3FFFFFFFFFFC0000 ),
+               LONG2CHARS( 0x7FFFFFFFFFFC0000 ),
+               LONG2CHARS( 0xFFFFFFFFFFFC0000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+       },
+       {
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000080000 ),
+               LONG2CHARS( 0x0000000000180000 ),
+               LONG2CHARS( 0x0000000000380000 ),
+               LONG2CHARS( 0x0000000000780000 ),
+               LONG2CHARS( 0x0000000000F80000 ),
+               LONG2CHARS( 0x0000000001F80000 ),
+               LONG2CHARS( 0x0000000003F80000 ),
+               LONG2CHARS( 0x0000000007F80000 ),
+               LONG2CHARS( 0x000000000FF80000 ),
+               LONG2CHARS( 0x000000001FF80000 ),
+               LONG2CHARS( 0x000000003FF80000 ),
+               LONG2CHARS( 0x000000007FF80000 ),
+               LONG2CHARS( 0x00000000FFF80000 ),
+               LONG2CHARS( 0x00000001FFF80000 ),
+               LONG2CHARS( 0x00000003FFF80000 ),
+               LONG2CHARS( 0x00000007FFF80000 ),
+               LONG2CHARS( 0x0000000FFFF80000 ),
+               LONG2CHARS( 0x0000001FFFF80000 ),
+               LONG2CHARS( 0x0000003FFFF80000 ),
+               LONG2CHARS( 0x0000007FFFF80000 ),
+               LONG2CHARS( 0x000000FFFFF80000 ),
+               LONG2CHARS( 0x000001FFFFF80000 ),
+               LONG2CHARS( 0x000003FFFFF80000 ),
+               LONG2CHARS( 0x000007FFFFF80000 ),
+               LONG2CHARS( 0x00000FFFFFF80000 ),
+               LONG2CHARS( 0x00001FFFFFF80000 ),
+               LONG2CHARS( 0x00003FFFFFF80000 ),
+               LONG2CHARS( 0x00007FFFFFF80000 ),
+               LONG2CHARS( 0x0000FFFFFFF80000 ),
+               LONG2CHARS( 0x0001FFFFFFF80000 ),
+               LONG2CHARS( 0x0003FFFFFFF80000 ),
+               LONG2CHARS( 0x0007FFFFFFF80000 ),
+               LONG2CHARS( 0x000FFFFFFFF80000 ),
+               LONG2CHARS( 0x001FFFFFFFF80000 ),
+               LONG2CHARS( 0x003FFFFFFFF80000 ),
+               LONG2CHARS( 0x007FFFFFFFF80000 ),
+               LONG2CHARS( 0x00FFFFFFFFF80000 ),
+               LONG2CHARS( 0x01FFFFFFFFF80000 ),
+               LONG2CHARS( 0x03FFFFFFFFF80000 ),
+               LONG2CHARS( 0x07FFFFFFFFF80000 ),
+               LONG2CHARS( 0x0FFFFFFFFFF80000 ),
+               LONG2CHARS( 0x1FFFFFFFFFF80000 ),
+               LONG2CHARS( 0x3FFFFFFFFFF80000 ),
+               LONG2CHARS( 0x7FFFFFFFFFF80000 ),
+               LONG2CHARS( 0xFFFFFFFFFFF80000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+       },
+       {
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000100000 ),
+               LONG2CHARS( 0x0000000000300000 ),
+               LONG2CHARS( 0x0000000000700000 ),
+               LONG2CHARS( 0x0000000000F00000 ),
+               LONG2CHARS( 0x0000000001F00000 ),
+               LONG2CHARS( 0x0000000003F00000 ),
+               LONG2CHARS( 0x0000000007F00000 ),
+               LONG2CHARS( 0x000000000FF00000 ),
+               LONG2CHARS( 0x000000001FF00000 ),
+               LONG2CHARS( 0x000000003FF00000 ),
+               LONG2CHARS( 0x000000007FF00000 ),
+               LONG2CHARS( 0x00000000FFF00000 ),
+               LONG2CHARS( 0x00000001FFF00000 ),
+               LONG2CHARS( 0x00000003FFF00000 ),
+               LONG2CHARS( 0x00000007FFF00000 ),
+               LONG2CHARS( 0x0000000FFFF00000 ),
+               LONG2CHARS( 0x0000001FFFF00000 ),
+               LONG2CHARS( 0x0000003FFFF00000 ),
+               LONG2CHARS( 0x0000007FFFF00000 ),
+               LONG2CHARS( 0x000000FFFFF00000 ),
+               LONG2CHARS( 0x000001FFFFF00000 ),
+               LONG2CHARS( 0x000003FFFFF00000 ),
+               LONG2CHARS( 0x000007FFFFF00000 ),
+               LONG2CHARS( 0x00000FFFFFF00000 ),
+               LONG2CHARS( 0x00001FFFFFF00000 ),
+               LONG2CHARS( 0x00003FFFFFF00000 ),
+               LONG2CHARS( 0x00007FFFFFF00000 ),
+               LONG2CHARS( 0x0000FFFFFFF00000 ),
+               LONG2CHARS( 0x0001FFFFFFF00000 ),
+               LONG2CHARS( 0x0003FFFFFFF00000 ),
+               LONG2CHARS( 0x0007FFFFFFF00000 ),
+               LONG2CHARS( 0x000FFFFFFFF00000 ),
+               LONG2CHARS( 0x001FFFFFFFF00000 ),
+               LONG2CHARS( 0x003FFFFFFFF00000 ),
+               LONG2CHARS( 0x007FFFFFFFF00000 ),
+               LONG2CHARS( 0x00FFFFFFFFF00000 ),
+               LONG2CHARS( 0x01FFFFFFFFF00000 ),
+               LONG2CHARS( 0x03FFFFFFFFF00000 ),
+               LONG2CHARS( 0x07FFFFFFFFF00000 ),
+               LONG2CHARS( 0x0FFFFFFFFFF00000 ),
+               LONG2CHARS( 0x1FFFFFFFFFF00000 ),
+               LONG2CHARS( 0x3FFFFFFFFFF00000 ),
+               LONG2CHARS( 0x7FFFFFFFFFF00000 ),
+               LONG2CHARS( 0xFFFFFFFFFFF00000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+       },
+       {
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000200000 ),
+               LONG2CHARS( 0x0000000000600000 ),
+               LONG2CHARS( 0x0000000000E00000 ),
+               LONG2CHARS( 0x0000000001E00000 ),
+               LONG2CHARS( 0x0000000003E00000 ),
+               LONG2CHARS( 0x0000000007E00000 ),
+               LONG2CHARS( 0x000000000FE00000 ),
+               LONG2CHARS( 0x000000001FE00000 ),
+               LONG2CHARS( 0x000000003FE00000 ),
+               LONG2CHARS( 0x000000007FE00000 ),
+               LONG2CHARS( 0x00000000FFE00000 ),
+               LONG2CHARS( 0x00000001FFE00000 ),
+               LONG2CHARS( 0x00000003FFE00000 ),
+               LONG2CHARS( 0x00000007FFE00000 ),
+               LONG2CHARS( 0x0000000FFFE00000 ),
+               LONG2CHARS( 0x0000001FFFE00000 ),
+               LONG2CHARS( 0x0000003FFFE00000 ),
+               LONG2CHARS( 0x0000007FFFE00000 ),
+               LONG2CHARS( 0x000000FFFFE00000 ),
+               LONG2CHARS( 0x000001FFFFE00000 ),
+               LONG2CHARS( 0x000003FFFFE00000 ),
+               LONG2CHARS( 0x000007FFFFE00000 ),
+               LONG2CHARS( 0x00000FFFFFE00000 ),
+               LONG2CHARS( 0x00001FFFFFE00000 ),
+               LONG2CHARS( 0x00003FFFFFE00000 ),
+               LONG2CHARS( 0x00007FFFFFE00000 ),
+               LONG2CHARS( 0x0000FFFFFFE00000 ),
+               LONG2CHARS( 0x0001FFFFFFE00000 ),
+               LONG2CHARS( 0x0003FFFFFFE00000 ),
+               LONG2CHARS( 0x0007FFFFFFE00000 ),
+               LONG2CHARS( 0x000FFFFFFFE00000 ),
+               LONG2CHARS( 0x001FFFFFFFE00000 ),
+               LONG2CHARS( 0x003FFFFFFFE00000 ),
+               LONG2CHARS( 0x007FFFFFFFE00000 ),
+               LONG2CHARS( 0x00FFFFFFFFE00000 ),
+               LONG2CHARS( 0x01FFFFFFFFE00000 ),
+               LONG2CHARS( 0x03FFFFFFFFE00000 ),
+               LONG2CHARS( 0x07FFFFFFFFE00000 ),
+               LONG2CHARS( 0x0FFFFFFFFFE00000 ),
+               LONG2CHARS( 0x1FFFFFFFFFE00000 ),
+               LONG2CHARS( 0x3FFFFFFFFFE00000 ),
+               LONG2CHARS( 0x7FFFFFFFFFE00000 ),
+               LONG2CHARS( 0xFFFFFFFFFFE00000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+       },
+       {
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000400000 ),
+               LONG2CHARS( 0x0000000000C00000 ),
+               LONG2CHARS( 0x0000000001C00000 ),
+               LONG2CHARS( 0x0000000003C00000 ),
+               LONG2CHARS( 0x0000000007C00000 ),
+               LONG2CHARS( 0x000000000FC00000 ),
+               LONG2CHARS( 0x000000001FC00000 ),
+               LONG2CHARS( 0x000000003FC00000 ),
+               LONG2CHARS( 0x000000007FC00000 ),
+               LONG2CHARS( 0x00000000FFC00000 ),
+               LONG2CHARS( 0x00000001FFC00000 ),
+               LONG2CHARS( 0x00000003FFC00000 ),
+               LONG2CHARS( 0x00000007FFC00000 ),
+               LONG2CHARS( 0x0000000FFFC00000 ),
+               LONG2CHARS( 0x0000001FFFC00000 ),
+               LONG2CHARS( 0x0000003FFFC00000 ),
+               LONG2CHARS( 0x0000007FFFC00000 ),
+               LONG2CHARS( 0x000000FFFFC00000 ),
+               LONG2CHARS( 0x000001FFFFC00000 ),
+               LONG2CHARS( 0x000003FFFFC00000 ),
+               LONG2CHARS( 0x000007FFFFC00000 ),
+               LONG2CHARS( 0x00000FFFFFC00000 ),
+               LONG2CHARS( 0x00001FFFFFC00000 ),
+               LONG2CHARS( 0x00003FFFFFC00000 ),
+               LONG2CHARS( 0x00007FFFFFC00000 ),
+               LONG2CHARS( 0x0000FFFFFFC00000 ),
+               LONG2CHARS( 0x0001FFFFFFC00000 ),
+               LONG2CHARS( 0x0003FFFFFFC00000 ),
+               LONG2CHARS( 0x0007FFFFFFC00000 ),
+               LONG2CHARS( 0x000FFFFFFFC00000 ),
+               LONG2CHARS( 0x001FFFFFFFC00000 ),
+               LONG2CHARS( 0x003FFFFFFFC00000 ),
+               LONG2CHARS( 0x007FFFFFFFC00000 ),
+               LONG2CHARS( 0x00FFFFFFFFC00000 ),
+               LONG2CHARS( 0x01FFFFFFFFC00000 ),
+               LONG2CHARS( 0x03FFFFFFFFC00000 ),
+               LONG2CHARS( 0x07FFFFFFFFC00000 ),
+               LONG2CHARS( 0x0FFFFFFFFFC00000 ),
+               LONG2CHARS( 0x1FFFFFFFFFC00000 ),
+               LONG2CHARS( 0x3FFFFFFFFFC00000 ),
+               LONG2CHARS( 0x7FFFFFFFFFC00000 ),
+               LONG2CHARS( 0xFFFFFFFFFFC00000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+       },
+       {
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000800000 ),
+               LONG2CHARS( 0x0000000001800000 ),
+               LONG2CHARS( 0x0000000003800000 ),
+               LONG2CHARS( 0x0000000007800000 ),
+               LONG2CHARS( 0x000000000F800000 ),
+               LONG2CHARS( 0x000000001F800000 ),
+               LONG2CHARS( 0x000000003F800000 ),
+               LONG2CHARS( 0x000000007F800000 ),
+               LONG2CHARS( 0x00000000FF800000 ),
+               LONG2CHARS( 0x00000001FF800000 ),
+               LONG2CHARS( 0x00000003FF800000 ),
+               LONG2CHARS( 0x00000007FF800000 ),
+               LONG2CHARS( 0x0000000FFF800000 ),
+               LONG2CHARS( 0x0000001FFF800000 ),
+               LONG2CHARS( 0x0000003FFF800000 ),
+               LONG2CHARS( 0x0000007FFF800000 ),
+               LONG2CHARS( 0x000000FFFF800000 ),
+               LONG2CHARS( 0x000001FFFF800000 ),
+               LONG2CHARS( 0x000003FFFF800000 ),
+               LONG2CHARS( 0x000007FFFF800000 ),
+               LONG2CHARS( 0x00000FFFFF800000 ),
+               LONG2CHARS( 0x00001FFFFF800000 ),
+               LONG2CHARS( 0x00003FFFFF800000 ),
+               LONG2CHARS( 0x00007FFFFF800000 ),
+               LONG2CHARS( 0x0000FFFFFF800000 ),
+               LONG2CHARS( 0x0001FFFFFF800000 ),
+               LONG2CHARS( 0x0003FFFFFF800000 ),
+               LONG2CHARS( 0x0007FFFFFF800000 ),
+               LONG2CHARS( 0x000FFFFFFF800000 ),
+               LONG2CHARS( 0x001FFFFFFF800000 ),
+               LONG2CHARS( 0x003FFFFFFF800000 ),
+               LONG2CHARS( 0x007FFFFFFF800000 ),
+               LONG2CHARS( 0x00FFFFFFFF800000 ),
+               LONG2CHARS( 0x01FFFFFFFF800000 ),
+               LONG2CHARS( 0x03FFFFFFFF800000 ),
+               LONG2CHARS( 0x07FFFFFFFF800000 ),
+               LONG2CHARS( 0x0FFFFFFFFF800000 ),
+               LONG2CHARS( 0x1FFFFFFFFF800000 ),
+               LONG2CHARS( 0x3FFFFFFFFF800000 ),
+               LONG2CHARS( 0x7FFFFFFFFF800000 ),
+               LONG2CHARS( 0xFFFFFFFFFF800000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+       },
+       {
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000001000000 ),
+               LONG2CHARS( 0x0000000003000000 ),
+               LONG2CHARS( 0x0000000007000000 ),
+               LONG2CHARS( 0x000000000F000000 ),
+               LONG2CHARS( 0x000000001F000000 ),
+               LONG2CHARS( 0x000000003F000000 ),
+               LONG2CHARS( 0x000000007F000000 ),
+               LONG2CHARS( 0x00000000FF000000 ),
+               LONG2CHARS( 0x00000001FF000000 ),
+               LONG2CHARS( 0x00000003FF000000 ),
+               LONG2CHARS( 0x00000007FF000000 ),
+               LONG2CHARS( 0x0000000FFF000000 ),
+               LONG2CHARS( 0x0000001FFF000000 ),
+               LONG2CHARS( 0x0000003FFF000000 ),
+               LONG2CHARS( 0x0000007FFF000000 ),
+               LONG2CHARS( 0x000000FFFF000000 ),
+               LONG2CHARS( 0x000001FFFF000000 ),
+               LONG2CHARS( 0x000003FFFF000000 ),
+               LONG2CHARS( 0x000007FFFF000000 ),
+               LONG2CHARS( 0x00000FFFFF000000 ),
+               LONG2CHARS( 0x00001FFFFF000000 ),
+               LONG2CHARS( 0x00003FFFFF000000 ),
+               LONG2CHARS( 0x00007FFFFF000000 ),
+               LONG2CHARS( 0x0000FFFFFF000000 ),
+               LONG2CHARS( 0x0001FFFFFF000000 ),
+               LONG2CHARS( 0x0003FFFFFF000000 ),
+               LONG2CHARS( 0x0007FFFFFF000000 ),
+               LONG2CHARS( 0x000FFFFFFF000000 ),
+               LONG2CHARS( 0x001FFFFFFF000000 ),
+               LONG2CHARS( 0x003FFFFFFF000000 ),
+               LONG2CHARS( 0x007FFFFFFF000000 ),
+               LONG2CHARS( 0x00FFFFFFFF000000 ),
+               LONG2CHARS( 0x01FFFFFFFF000000 ),
+               LONG2CHARS( 0x03FFFFFFFF000000 ),
+               LONG2CHARS( 0x07FFFFFFFF000000 ),
+               LONG2CHARS( 0x0FFFFFFFFF000000 ),
+               LONG2CHARS( 0x1FFFFFFFFF000000 ),
+               LONG2CHARS( 0x3FFFFFFFFF000000 ),
+               LONG2CHARS( 0x7FFFFFFFFF000000 ),
+               LONG2CHARS( 0xFFFFFFFFFF000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+       },
+       {
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000002000000 ),
+               LONG2CHARS( 0x0000000006000000 ),
+               LONG2CHARS( 0x000000000E000000 ),
+               LONG2CHARS( 0x000000001E000000 ),
+               LONG2CHARS( 0x000000003E000000 ),
+               LONG2CHARS( 0x000000007E000000 ),
+               LONG2CHARS( 0x00000000FE000000 ),
+               LONG2CHARS( 0x00000001FE000000 ),
+               LONG2CHARS( 0x00000003FE000000 ),
+               LONG2CHARS( 0x00000007FE000000 ),
+               LONG2CHARS( 0x0000000FFE000000 ),
+               LONG2CHARS( 0x0000001FFE000000 ),
+               LONG2CHARS( 0x0000003FFE000000 ),
+               LONG2CHARS( 0x0000007FFE000000 ),
+               LONG2CHARS( 0x000000FFFE000000 ),
+               LONG2CHARS( 0x000001FFFE000000 ),
+               LONG2CHARS( 0x000003FFFE000000 ),
+               LONG2CHARS( 0x000007FFFE000000 ),
+               LONG2CHARS( 0x00000FFFFE000000 ),
+               LONG2CHARS( 0x00001FFFFE000000 ),
+               LONG2CHARS( 0x00003FFFFE000000 ),
+               LONG2CHARS( 0x00007FFFFE000000 ),
+               LONG2CHARS( 0x0000FFFFFE000000 ),
+               LONG2CHARS( 0x0001FFFFFE000000 ),
+               LONG2CHARS( 0x0003FFFFFE000000 ),
+               LONG2CHARS( 0x0007FFFFFE000000 ),
+               LONG2CHARS( 0x000FFFFFFE000000 ),
+               LONG2CHARS( 0x001FFFFFFE000000 ),
+               LONG2CHARS( 0x003FFFFFFE000000 ),
+               LONG2CHARS( 0x007FFFFFFE000000 ),
+               LONG2CHARS( 0x00FFFFFFFE000000 ),
+               LONG2CHARS( 0x01FFFFFFFE000000 ),
+               LONG2CHARS( 0x03FFFFFFFE000000 ),
+               LONG2CHARS( 0x07FFFFFFFE000000 ),
+               LONG2CHARS( 0x0FFFFFFFFE000000 ),
+               LONG2CHARS( 0x1FFFFFFFFE000000 ),
+               LONG2CHARS( 0x3FFFFFFFFE000000 ),
+               LONG2CHARS( 0x7FFFFFFFFE000000 ),
+               LONG2CHARS( 0xFFFFFFFFFE000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+       },
+       {
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000004000000 ),
+               LONG2CHARS( 0x000000000C000000 ),
+               LONG2CHARS( 0x000000001C000000 ),
+               LONG2CHARS( 0x000000003C000000 ),
+               LONG2CHARS( 0x000000007C000000 ),
+               LONG2CHARS( 0x00000000FC000000 ),
+               LONG2CHARS( 0x00000001FC000000 ),
+               LONG2CHARS( 0x00000003FC000000 ),
+               LONG2CHARS( 0x00000007FC000000 ),
+               LONG2CHARS( 0x0000000FFC000000 ),
+               LONG2CHARS( 0x0000001FFC000000 ),
+               LONG2CHARS( 0x0000003FFC000000 ),
+               LONG2CHARS( 0x0000007FFC000000 ),
+               LONG2CHARS( 0x000000FFFC000000 ),
+               LONG2CHARS( 0x000001FFFC000000 ),
+               LONG2CHARS( 0x000003FFFC000000 ),
+               LONG2CHARS( 0x000007FFFC000000 ),
+               LONG2CHARS( 0x00000FFFFC000000 ),
+               LONG2CHARS( 0x00001FFFFC000000 ),
+               LONG2CHARS( 0x00003FFFFC000000 ),
+               LONG2CHARS( 0x00007FFFFC000000 ),
+               LONG2CHARS( 0x0000FFFFFC000000 ),
+               LONG2CHARS( 0x0001FFFFFC000000 ),
+               LONG2CHARS( 0x0003FFFFFC000000 ),
+               LONG2CHARS( 0x0007FFFFFC000000 ),
+               LONG2CHARS( 0x000FFFFFFC000000 ),
+               LONG2CHARS( 0x001FFFFFFC000000 ),
+               LONG2CHARS( 0x003FFFFFFC000000 ),
+               LONG2CHARS( 0x007FFFFFFC000000 ),
+               LONG2CHARS( 0x00FFFFFFFC000000 ),
+               LONG2CHARS( 0x01FFFFFFFC000000 ),
+               LONG2CHARS( 0x03FFFFFFFC000000 ),
+               LONG2CHARS( 0x07FFFFFFFC000000 ),
+               LONG2CHARS( 0x0FFFFFFFFC000000 ),
+               LONG2CHARS( 0x1FFFFFFFFC000000 ),
+               LONG2CHARS( 0x3FFFFFFFFC000000 ),
+               LONG2CHARS( 0x7FFFFFFFFC000000 ),
+               LONG2CHARS( 0xFFFFFFFFFC000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+       },
+       {
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000008000000 ),
+               LONG2CHARS( 0x0000000018000000 ),
+               LONG2CHARS( 0x0000000038000000 ),
+               LONG2CHARS( 0x0000000078000000 ),
+               LONG2CHARS( 0x00000000F8000000 ),
+               LONG2CHARS( 0x00000001F8000000 ),
+               LONG2CHARS( 0x00000003F8000000 ),
+               LONG2CHARS( 0x00000007F8000000 ),
+               LONG2CHARS( 0x0000000FF8000000 ),
+               LONG2CHARS( 0x0000001FF8000000 ),
+               LONG2CHARS( 0x0000003FF8000000 ),
+               LONG2CHARS( 0x0000007FF8000000 ),
+               LONG2CHARS( 0x000000FFF8000000 ),
+               LONG2CHARS( 0x000001FFF8000000 ),
+               LONG2CHARS( 0x000003FFF8000000 ),
+               LONG2CHARS( 0x000007FFF8000000 ),
+               LONG2CHARS( 0x00000FFFF8000000 ),
+               LONG2CHARS( 0x00001FFFF8000000 ),
+               LONG2CHARS( 0x00003FFFF8000000 ),
+               LONG2CHARS( 0x00007FFFF8000000 ),
+               LONG2CHARS( 0x0000FFFFF8000000 ),
+               LONG2CHARS( 0x0001FFFFF8000000 ),
+               LONG2CHARS( 0x0003FFFFF8000000 ),
+               LONG2CHARS( 0x0007FFFFF8000000 ),
+               LONG2CHARS( 0x000FFFFFF8000000 ),
+               LONG2CHARS( 0x001FFFFFF8000000 ),
+               LONG2CHARS( 0x003FFFFFF8000000 ),
+               LONG2CHARS( 0x007FFFFFF8000000 ),
+               LONG2CHARS( 0x00FFFFFFF8000000 ),
+               LONG2CHARS( 0x01FFFFFFF8000000 ),
+               LONG2CHARS( 0x03FFFFFFF8000000 ),
+               LONG2CHARS( 0x07FFFFFFF8000000 ),
+               LONG2CHARS( 0x0FFFFFFFF8000000 ),
+               LONG2CHARS( 0x1FFFFFFFF8000000 ),
+               LONG2CHARS( 0x3FFFFFFFF8000000 ),
+               LONG2CHARS( 0x7FFFFFFFF8000000 ),
+               LONG2CHARS( 0xFFFFFFFFF8000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+       },
+       {
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000010000000 ),
+               LONG2CHARS( 0x0000000030000000 ),
+               LONG2CHARS( 0x0000000070000000 ),
+               LONG2CHARS( 0x00000000F0000000 ),
+               LONG2CHARS( 0x00000001F0000000 ),
+               LONG2CHARS( 0x00000003F0000000 ),
+               LONG2CHARS( 0x00000007F0000000 ),
+               LONG2CHARS( 0x0000000FF0000000 ),
+               LONG2CHARS( 0x0000001FF0000000 ),
+               LONG2CHARS( 0x0000003FF0000000 ),
+               LONG2CHARS( 0x0000007FF0000000 ),
+               LONG2CHARS( 0x000000FFF0000000 ),
+               LONG2CHARS( 0x000001FFF0000000 ),
+               LONG2CHARS( 0x000003FFF0000000 ),
+               LONG2CHARS( 0x000007FFF0000000 ),
+               LONG2CHARS( 0x00000FFFF0000000 ),
+               LONG2CHARS( 0x00001FFFF0000000 ),
+               LONG2CHARS( 0x00003FFFF0000000 ),
+               LONG2CHARS( 0x00007FFFF0000000 ),
+               LONG2CHARS( 0x0000FFFFF0000000 ),
+               LONG2CHARS( 0x0001FFFFF0000000 ),
+               LONG2CHARS( 0x0003FFFFF0000000 ),
+               LONG2CHARS( 0x0007FFFFF0000000 ),
+               LONG2CHARS( 0x000FFFFFF0000000 ),
+               LONG2CHARS( 0x001FFFFFF0000000 ),
+               LONG2CHARS( 0x003FFFFFF0000000 ),
+               LONG2CHARS( 0x007FFFFFF0000000 ),
+               LONG2CHARS( 0x00FFFFFFF0000000 ),
+               LONG2CHARS( 0x01FFFFFFF0000000 ),
+               LONG2CHARS( 0x03FFFFFFF0000000 ),
+               LONG2CHARS( 0x07FFFFFFF0000000 ),
+               LONG2CHARS( 0x0FFFFFFFF0000000 ),
+               LONG2CHARS( 0x1FFFFFFFF0000000 ),
+               LONG2CHARS( 0x3FFFFFFFF0000000 ),
+               LONG2CHARS( 0x7FFFFFFFF0000000 ),
+               LONG2CHARS( 0xFFFFFFFFF0000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+       },
+       {
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000020000000 ),
+               LONG2CHARS( 0x0000000060000000 ),
+               LONG2CHARS( 0x00000000E0000000 ),
+               LONG2CHARS( 0x00000001E0000000 ),
+               LONG2CHARS( 0x00000003E0000000 ),
+               LONG2CHARS( 0x00000007E0000000 ),
+               LONG2CHARS( 0x0000000FE0000000 ),
+               LONG2CHARS( 0x0000001FE0000000 ),
+               LONG2CHARS( 0x0000003FE0000000 ),
+               LONG2CHARS( 0x0000007FE0000000 ),
+               LONG2CHARS( 0x000000FFE0000000 ),
+               LONG2CHARS( 0x000001FFE0000000 ),
+               LONG2CHARS( 0x000003FFE0000000 ),
+               LONG2CHARS( 0x000007FFE0000000 ),
+               LONG2CHARS( 0x00000FFFE0000000 ),
+               LONG2CHARS( 0x00001FFFE0000000 ),
+               LONG2CHARS( 0x00003FFFE0000000 ),
+               LONG2CHARS( 0x00007FFFE0000000 ),
+               LONG2CHARS( 0x0000FFFFE0000000 ),
+               LONG2CHARS( 0x0001FFFFE0000000 ),
+               LONG2CHARS( 0x0003FFFFE0000000 ),
+               LONG2CHARS( 0x0007FFFFE0000000 ),
+               LONG2CHARS( 0x000FFFFFE0000000 ),
+               LONG2CHARS( 0x001FFFFFE0000000 ),
+               LONG2CHARS( 0x003FFFFFE0000000 ),
+               LONG2CHARS( 0x007FFFFFE0000000 ),
+               LONG2CHARS( 0x00FFFFFFE0000000 ),
+               LONG2CHARS( 0x01FFFFFFE0000000 ),
+               LONG2CHARS( 0x03FFFFFFE0000000 ),
+               LONG2CHARS( 0x07FFFFFFE0000000 ),
+               LONG2CHARS( 0x0FFFFFFFE0000000 ),
+               LONG2CHARS( 0x1FFFFFFFE0000000 ),
+               LONG2CHARS( 0x3FFFFFFFE0000000 ),
+               LONG2CHARS( 0x7FFFFFFFE0000000 ),
+               LONG2CHARS( 0xFFFFFFFFE0000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+       },
+       {
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000040000000 ),
+               LONG2CHARS( 0x00000000C0000000 ),
+               LONG2CHARS( 0x00000001C0000000 ),
+               LONG2CHARS( 0x00000003C0000000 ),
+               LONG2CHARS( 0x00000007C0000000 ),
+               LONG2CHARS( 0x0000000FC0000000 ),
+               LONG2CHARS( 0x0000001FC0000000 ),
+               LONG2CHARS( 0x0000003FC0000000 ),
+               LONG2CHARS( 0x0000007FC0000000 ),
+               LONG2CHARS( 0x000000FFC0000000 ),
+               LONG2CHARS( 0x000001FFC0000000 ),
+               LONG2CHARS( 0x000003FFC0000000 ),
+               LONG2CHARS( 0x000007FFC0000000 ),
+               LONG2CHARS( 0x00000FFFC0000000 ),
+               LONG2CHARS( 0x00001FFFC0000000 ),
+               LONG2CHARS( 0x00003FFFC0000000 ),
+               LONG2CHARS( 0x00007FFFC0000000 ),
+               LONG2CHARS( 0x0000FFFFC0000000 ),
+               LONG2CHARS( 0x0001FFFFC0000000 ),
+               LONG2CHARS( 0x0003FFFFC0000000 ),
+               LONG2CHARS( 0x0007FFFFC0000000 ),
+               LONG2CHARS( 0x000FFFFFC0000000 ),
+               LONG2CHARS( 0x001FFFFFC0000000 ),
+               LONG2CHARS( 0x003FFFFFC0000000 ),
+               LONG2CHARS( 0x007FFFFFC0000000 ),
+               LONG2CHARS( 0x00FFFFFFC0000000 ),
+               LONG2CHARS( 0x01FFFFFFC0000000 ),
+               LONG2CHARS( 0x03FFFFFFC0000000 ),
+               LONG2CHARS( 0x07FFFFFFC0000000 ),
+               LONG2CHARS( 0x0FFFFFFFC0000000 ),
+               LONG2CHARS( 0x1FFFFFFFC0000000 ),
+               LONG2CHARS( 0x3FFFFFFFC0000000 ),
+               LONG2CHARS( 0x7FFFFFFFC0000000 ),
+               LONG2CHARS( 0xFFFFFFFFC0000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+       },
+       {
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000080000000 ),
+               LONG2CHARS( 0x0000000180000000 ),
+               LONG2CHARS( 0x0000000380000000 ),
+               LONG2CHARS( 0x0000000780000000 ),
+               LONG2CHARS( 0x0000000F80000000 ),
+               LONG2CHARS( 0x0000001F80000000 ),
+               LONG2CHARS( 0x0000003F80000000 ),
+               LONG2CHARS( 0x0000007F80000000 ),
+               LONG2CHARS( 0x000000FF80000000 ),
+               LONG2CHARS( 0x000001FF80000000 ),
+               LONG2CHARS( 0x000003FF80000000 ),
+               LONG2CHARS( 0x000007FF80000000 ),
+               LONG2CHARS( 0x00000FFF80000000 ),
+               LONG2CHARS( 0x00001FFF80000000 ),
+               LONG2CHARS( 0x00003FFF80000000 ),
+               LONG2CHARS( 0x00007FFF80000000 ),
+               LONG2CHARS( 0x0000FFFF80000000 ),
+               LONG2CHARS( 0x0001FFFF80000000 ),
+               LONG2CHARS( 0x0003FFFF80000000 ),
+               LONG2CHARS( 0x0007FFFF80000000 ),
+               LONG2CHARS( 0x000FFFFF80000000 ),
+               LONG2CHARS( 0x001FFFFF80000000 ),
+               LONG2CHARS( 0x003FFFFF80000000 ),
+               LONG2CHARS( 0x007FFFFF80000000 ),
+               LONG2CHARS( 0x00FFFFFF80000000 ),
+               LONG2CHARS( 0x01FFFFFF80000000 ),
+               LONG2CHARS( 0x03FFFFFF80000000 ),
+               LONG2CHARS( 0x07FFFFFF80000000 ),
+               LONG2CHARS( 0x0FFFFFFF80000000 ),
+               LONG2CHARS( 0x1FFFFFFF80000000 ),
+               LONG2CHARS( 0x3FFFFFFF80000000 ),
+               LONG2CHARS( 0x7FFFFFFF80000000 ),
+               LONG2CHARS( 0xFFFFFFFF80000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+       },
+       {
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000100000000 ),
+               LONG2CHARS( 0x0000000300000000 ),
+               LONG2CHARS( 0x0000000700000000 ),
+               LONG2CHARS( 0x0000000F00000000 ),
+               LONG2CHARS( 0x0000001F00000000 ),
+               LONG2CHARS( 0x0000003F00000000 ),
+               LONG2CHARS( 0x0000007F00000000 ),
+               LONG2CHARS( 0x000000FF00000000 ),
+               LONG2CHARS( 0x000001FF00000000 ),
+               LONG2CHARS( 0x000003FF00000000 ),
+               LONG2CHARS( 0x000007FF00000000 ),
+               LONG2CHARS( 0x00000FFF00000000 ),
+               LONG2CHARS( 0x00001FFF00000000 ),
+               LONG2CHARS( 0x00003FFF00000000 ),
+               LONG2CHARS( 0x00007FFF00000000 ),
+               LONG2CHARS( 0x0000FFFF00000000 ),
+               LONG2CHARS( 0x0001FFFF00000000 ),
+               LONG2CHARS( 0x0003FFFF00000000 ),
+               LONG2CHARS( 0x0007FFFF00000000 ),
+               LONG2CHARS( 0x000FFFFF00000000 ),
+               LONG2CHARS( 0x001FFFFF00000000 ),
+               LONG2CHARS( 0x003FFFFF00000000 ),
+               LONG2CHARS( 0x007FFFFF00000000 ),
+               LONG2CHARS( 0x00FFFFFF00000000 ),
+               LONG2CHARS( 0x01FFFFFF00000000 ),
+               LONG2CHARS( 0x03FFFFFF00000000 ),
+               LONG2CHARS( 0x07FFFFFF00000000 ),
+               LONG2CHARS( 0x0FFFFFFF00000000 ),
+               LONG2CHARS( 0x1FFFFFFF00000000 ),
+               LONG2CHARS( 0x3FFFFFFF00000000 ),
+               LONG2CHARS( 0x7FFFFFFF00000000 ),
+               LONG2CHARS( 0xFFFFFFFF00000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+       },
+       {
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000200000000 ),
+               LONG2CHARS( 0x0000000600000000 ),
+               LONG2CHARS( 0x0000000E00000000 ),
+               LONG2CHARS( 0x0000001E00000000 ),
+               LONG2CHARS( 0x0000003E00000000 ),
+               LONG2CHARS( 0x0000007E00000000 ),
+               LONG2CHARS( 0x000000FE00000000 ),
+               LONG2CHARS( 0x000001FE00000000 ),
+               LONG2CHARS( 0x000003FE00000000 ),
+               LONG2CHARS( 0x000007FE00000000 ),
+               LONG2CHARS( 0x00000FFE00000000 ),
+               LONG2CHARS( 0x00001FFE00000000 ),
+               LONG2CHARS( 0x00003FFE00000000 ),
+               LONG2CHARS( 0x00007FFE00000000 ),
+               LONG2CHARS( 0x0000FFFE00000000 ),
+               LONG2CHARS( 0x0001FFFE00000000 ),
+               LONG2CHARS( 0x0003FFFE00000000 ),
+               LONG2CHARS( 0x0007FFFE00000000 ),
+               LONG2CHARS( 0x000FFFFE00000000 ),
+               LONG2CHARS( 0x001FFFFE00000000 ),
+               LONG2CHARS( 0x003FFFFE00000000 ),
+               LONG2CHARS( 0x007FFFFE00000000 ),
+               LONG2CHARS( 0x00FFFFFE00000000 ),
+               LONG2CHARS( 0x01FFFFFE00000000 ),
+               LONG2CHARS( 0x03FFFFFE00000000 ),
+               LONG2CHARS( 0x07FFFFFE00000000 ),
+               LONG2CHARS( 0x0FFFFFFE00000000 ),
+               LONG2CHARS( 0x1FFFFFFE00000000 ),
+               LONG2CHARS( 0x3FFFFFFE00000000 ),
+               LONG2CHARS( 0x7FFFFFFE00000000 ),
+               LONG2CHARS( 0xFFFFFFFE00000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+       },
+       {
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000400000000 ),
+               LONG2CHARS( 0x0000000C00000000 ),
+               LONG2CHARS( 0x0000001C00000000 ),
+               LONG2CHARS( 0x0000003C00000000 ),
+               LONG2CHARS( 0x0000007C00000000 ),
+               LONG2CHARS( 0x000000FC00000000 ),
+               LONG2CHARS( 0x000001FC00000000 ),
+               LONG2CHARS( 0x000003FC00000000 ),
+               LONG2CHARS( 0x000007FC00000000 ),
+               LONG2CHARS( 0x00000FFC00000000 ),
+               LONG2CHARS( 0x00001FFC00000000 ),
+               LONG2CHARS( 0x00003FFC00000000 ),
+               LONG2CHARS( 0x00007FFC00000000 ),
+               LONG2CHARS( 0x0000FFFC00000000 ),
+               LONG2CHARS( 0x0001FFFC00000000 ),
+               LONG2CHARS( 0x0003FFFC00000000 ),
+               LONG2CHARS( 0x0007FFFC00000000 ),
+               LONG2CHARS( 0x000FFFFC00000000 ),
+               LONG2CHARS( 0x001FFFFC00000000 ),
+               LONG2CHARS( 0x003FFFFC00000000 ),
+               LONG2CHARS( 0x007FFFFC00000000 ),
+               LONG2CHARS( 0x00FFFFFC00000000 ),
+               LONG2CHARS( 0x01FFFFFC00000000 ),
+               LONG2CHARS( 0x03FFFFFC00000000 ),
+               LONG2CHARS( 0x07FFFFFC00000000 ),
+               LONG2CHARS( 0x0FFFFFFC00000000 ),
+               LONG2CHARS( 0x1FFFFFFC00000000 ),
+               LONG2CHARS( 0x3FFFFFFC00000000 ),
+               LONG2CHARS( 0x7FFFFFFC00000000 ),
+               LONG2CHARS( 0xFFFFFFFC00000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+       },
+       {
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000800000000 ),
+               LONG2CHARS( 0x0000001800000000 ),
+               LONG2CHARS( 0x0000003800000000 ),
+               LONG2CHARS( 0x0000007800000000 ),
+               LONG2CHARS( 0x000000F800000000 ),
+               LONG2CHARS( 0x000001F800000000 ),
+               LONG2CHARS( 0x000003F800000000 ),
+               LONG2CHARS( 0x000007F800000000 ),
+               LONG2CHARS( 0x00000FF800000000 ),
+               LONG2CHARS( 0x00001FF800000000 ),
+               LONG2CHARS( 0x00003FF800000000 ),
+               LONG2CHARS( 0x00007FF800000000 ),
+               LONG2CHARS( 0x0000FFF800000000 ),
+               LONG2CHARS( 0x0001FFF800000000 ),
+               LONG2CHARS( 0x0003FFF800000000 ),
+               LONG2CHARS( 0x0007FFF800000000 ),
+               LONG2CHARS( 0x000FFFF800000000 ),
+               LONG2CHARS( 0x001FFFF800000000 ),
+               LONG2CHARS( 0x003FFFF800000000 ),
+               LONG2CHARS( 0x007FFFF800000000 ),
+               LONG2CHARS( 0x00FFFFF800000000 ),
+               LONG2CHARS( 0x01FFFFF800000000 ),
+               LONG2CHARS( 0x03FFFFF800000000 ),
+               LONG2CHARS( 0x07FFFFF800000000 ),
+               LONG2CHARS( 0x0FFFFFF800000000 ),
+               LONG2CHARS( 0x1FFFFFF800000000 ),
+               LONG2CHARS( 0x3FFFFFF800000000 ),
+               LONG2CHARS( 0x7FFFFFF800000000 ),
+               LONG2CHARS( 0xFFFFFFF800000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+       },
+       {
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000001000000000 ),
+               LONG2CHARS( 0x0000003000000000 ),
+               LONG2CHARS( 0x0000007000000000 ),
+               LONG2CHARS( 0x000000F000000000 ),
+               LONG2CHARS( 0x000001F000000000 ),
+               LONG2CHARS( 0x000003F000000000 ),
+               LONG2CHARS( 0x000007F000000000 ),
+               LONG2CHARS( 0x00000FF000000000 ),
+               LONG2CHARS( 0x00001FF000000000 ),
+               LONG2CHARS( 0x00003FF000000000 ),
+               LONG2CHARS( 0x00007FF000000000 ),
+               LONG2CHARS( 0x0000FFF000000000 ),
+               LONG2CHARS( 0x0001FFF000000000 ),
+               LONG2CHARS( 0x0003FFF000000000 ),
+               LONG2CHARS( 0x0007FFF000000000 ),
+               LONG2CHARS( 0x000FFFF000000000 ),
+               LONG2CHARS( 0x001FFFF000000000 ),
+               LONG2CHARS( 0x003FFFF000000000 ),
+               LONG2CHARS( 0x007FFFF000000000 ),
+               LONG2CHARS( 0x00FFFFF000000000 ),
+               LONG2CHARS( 0x01FFFFF000000000 ),
+               LONG2CHARS( 0x03FFFFF000000000 ),
+               LONG2CHARS( 0x07FFFFF000000000 ),
+               LONG2CHARS( 0x0FFFFFF000000000 ),
+               LONG2CHARS( 0x1FFFFFF000000000 ),
+               LONG2CHARS( 0x3FFFFFF000000000 ),
+               LONG2CHARS( 0x7FFFFFF000000000 ),
+               LONG2CHARS( 0xFFFFFFF000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+       },
+       {
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000002000000000 ),
+               LONG2CHARS( 0x0000006000000000 ),
+               LONG2CHARS( 0x000000E000000000 ),
+               LONG2CHARS( 0x000001E000000000 ),
+               LONG2CHARS( 0x000003E000000000 ),
+               LONG2CHARS( 0x000007E000000000 ),
+               LONG2CHARS( 0x00000FE000000000 ),
+               LONG2CHARS( 0x00001FE000000000 ),
+               LONG2CHARS( 0x00003FE000000000 ),
+               LONG2CHARS( 0x00007FE000000000 ),
+               LONG2CHARS( 0x0000FFE000000000 ),
+               LONG2CHARS( 0x0001FFE000000000 ),
+               LONG2CHARS( 0x0003FFE000000000 ),
+               LONG2CHARS( 0x0007FFE000000000 ),
+               LONG2CHARS( 0x000FFFE000000000 ),
+               LONG2CHARS( 0x001FFFE000000000 ),
+               LONG2CHARS( 0x003FFFE000000000 ),
+               LONG2CHARS( 0x007FFFE000000000 ),
+               LONG2CHARS( 0x00FFFFE000000000 ),
+               LONG2CHARS( 0x01FFFFE000000000 ),
+               LONG2CHARS( 0x03FFFFE000000000 ),
+               LONG2CHARS( 0x07FFFFE000000000 ),
+               LONG2CHARS( 0x0FFFFFE000000000 ),
+               LONG2CHARS( 0x1FFFFFE000000000 ),
+               LONG2CHARS( 0x3FFFFFE000000000 ),
+               LONG2CHARS( 0x7FFFFFE000000000 ),
+               LONG2CHARS( 0xFFFFFFE000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+       },
+       {
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000004000000000 ),
+               LONG2CHARS( 0x000000C000000000 ),
+               LONG2CHARS( 0x000001C000000000 ),
+               LONG2CHARS( 0x000003C000000000 ),
+               LONG2CHARS( 0x000007C000000000 ),
+               LONG2CHARS( 0x00000FC000000000 ),
+               LONG2CHARS( 0x00001FC000000000 ),
+               LONG2CHARS( 0x00003FC000000000 ),
+               LONG2CHARS( 0x00007FC000000000 ),
+               LONG2CHARS( 0x0000FFC000000000 ),
+               LONG2CHARS( 0x0001FFC000000000 ),
+               LONG2CHARS( 0x0003FFC000000000 ),
+               LONG2CHARS( 0x0007FFC000000000 ),
+               LONG2CHARS( 0x000FFFC000000000 ),
+               LONG2CHARS( 0x001FFFC000000000 ),
+               LONG2CHARS( 0x003FFFC000000000 ),
+               LONG2CHARS( 0x007FFFC000000000 ),
+               LONG2CHARS( 0x00FFFFC000000000 ),
+               LONG2CHARS( 0x01FFFFC000000000 ),
+               LONG2CHARS( 0x03FFFFC000000000 ),
+               LONG2CHARS( 0x07FFFFC000000000 ),
+               LONG2CHARS( 0x0FFFFFC000000000 ),
+               LONG2CHARS( 0x1FFFFFC000000000 ),
+               LONG2CHARS( 0x3FFFFFC000000000 ),
+               LONG2CHARS( 0x7FFFFFC000000000 ),
+               LONG2CHARS( 0xFFFFFFC000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+       },
+       {
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000008000000000 ),
+               LONG2CHARS( 0x0000018000000000 ),
+               LONG2CHARS( 0x0000038000000000 ),
+               LONG2CHARS( 0x0000078000000000 ),
+               LONG2CHARS( 0x00000F8000000000 ),
+               LONG2CHARS( 0x00001F8000000000 ),
+               LONG2CHARS( 0x00003F8000000000 ),
+               LONG2CHARS( 0x00007F8000000000 ),
+               LONG2CHARS( 0x0000FF8000000000 ),
+               LONG2CHARS( 0x0001FF8000000000 ),
+               LONG2CHARS( 0x0003FF8000000000 ),
+               LONG2CHARS( 0x0007FF8000000000 ),
+               LONG2CHARS( 0x000FFF8000000000 ),
+               LONG2CHARS( 0x001FFF8000000000 ),
+               LONG2CHARS( 0x003FFF8000000000 ),
+               LONG2CHARS( 0x007FFF8000000000 ),
+               LONG2CHARS( 0x00FFFF8000000000 ),
+               LONG2CHARS( 0x01FFFF8000000000 ),
+               LONG2CHARS( 0x03FFFF8000000000 ),
+               LONG2CHARS( 0x07FFFF8000000000 ),
+               LONG2CHARS( 0x0FFFFF8000000000 ),
+               LONG2CHARS( 0x1FFFFF8000000000 ),
+               LONG2CHARS( 0x3FFFFF8000000000 ),
+               LONG2CHARS( 0x7FFFFF8000000000 ),
+               LONG2CHARS( 0xFFFFFF8000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+       },
+       {
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000010000000000 ),
+               LONG2CHARS( 0x0000030000000000 ),
+               LONG2CHARS( 0x0000070000000000 ),
+               LONG2CHARS( 0x00000F0000000000 ),
+               LONG2CHARS( 0x00001F0000000000 ),
+               LONG2CHARS( 0x00003F0000000000 ),
+               LONG2CHARS( 0x00007F0000000000 ),
+               LONG2CHARS( 0x0000FF0000000000 ),
+               LONG2CHARS( 0x0001FF0000000000 ),
+               LONG2CHARS( 0x0003FF0000000000 ),
+               LONG2CHARS( 0x0007FF0000000000 ),
+               LONG2CHARS( 0x000FFF0000000000 ),
+               LONG2CHARS( 0x001FFF0000000000 ),
+               LONG2CHARS( 0x003FFF0000000000 ),
+               LONG2CHARS( 0x007FFF0000000000 ),
+               LONG2CHARS( 0x00FFFF0000000000 ),
+               LONG2CHARS( 0x01FFFF0000000000 ),
+               LONG2CHARS( 0x03FFFF0000000000 ),
+               LONG2CHARS( 0x07FFFF0000000000 ),
+               LONG2CHARS( 0x0FFFFF0000000000 ),
+               LONG2CHARS( 0x1FFFFF0000000000 ),
+               LONG2CHARS( 0x3FFFFF0000000000 ),
+               LONG2CHARS( 0x7FFFFF0000000000 ),
+               LONG2CHARS( 0xFFFFFF0000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+       },
+       {
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000020000000000 ),
+               LONG2CHARS( 0x0000060000000000 ),
+               LONG2CHARS( 0x00000E0000000000 ),
+               LONG2CHARS( 0x00001E0000000000 ),
+               LONG2CHARS( 0x00003E0000000000 ),
+               LONG2CHARS( 0x00007E0000000000 ),
+               LONG2CHARS( 0x0000FE0000000000 ),
+               LONG2CHARS( 0x0001FE0000000000 ),
+               LONG2CHARS( 0x0003FE0000000000 ),
+               LONG2CHARS( 0x0007FE0000000000 ),
+               LONG2CHARS( 0x000FFE0000000000 ),
+               LONG2CHARS( 0x001FFE0000000000 ),
+               LONG2CHARS( 0x003FFE0000000000 ),
+               LONG2CHARS( 0x007FFE0000000000 ),
+               LONG2CHARS( 0x00FFFE0000000000 ),
+               LONG2CHARS( 0x01FFFE0000000000 ),
+               LONG2CHARS( 0x03FFFE0000000000 ),
+               LONG2CHARS( 0x07FFFE0000000000 ),
+               LONG2CHARS( 0x0FFFFE0000000000 ),
+               LONG2CHARS( 0x1FFFFE0000000000 ),
+               LONG2CHARS( 0x3FFFFE0000000000 ),
+               LONG2CHARS( 0x7FFFFE0000000000 ),
+               LONG2CHARS( 0xFFFFFE0000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+       },
+       {
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000040000000000 ),
+               LONG2CHARS( 0x00000C0000000000 ),
+               LONG2CHARS( 0x00001C0000000000 ),
+               LONG2CHARS( 0x00003C0000000000 ),
+               LONG2CHARS( 0x00007C0000000000 ),
+               LONG2CHARS( 0x0000FC0000000000 ),
+               LONG2CHARS( 0x0001FC0000000000 ),
+               LONG2CHARS( 0x0003FC0000000000 ),
+               LONG2CHARS( 0x0007FC0000000000 ),
+               LONG2CHARS( 0x000FFC0000000000 ),
+               LONG2CHARS( 0x001FFC0000000000 ),
+               LONG2CHARS( 0x003FFC0000000000 ),
+               LONG2CHARS( 0x007FFC0000000000 ),
+               LONG2CHARS( 0x00FFFC0000000000 ),
+               LONG2CHARS( 0x01FFFC0000000000 ),
+               LONG2CHARS( 0x03FFFC0000000000 ),
+               LONG2CHARS( 0x07FFFC0000000000 ),
+               LONG2CHARS( 0x0FFFFC0000000000 ),
+               LONG2CHARS( 0x1FFFFC0000000000 ),
+               LONG2CHARS( 0x3FFFFC0000000000 ),
+               LONG2CHARS( 0x7FFFFC0000000000 ),
+               LONG2CHARS( 0xFFFFFC0000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+       },
+       {
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000080000000000 ),
+               LONG2CHARS( 0x0000180000000000 ),
+               LONG2CHARS( 0x0000380000000000 ),
+               LONG2CHARS( 0x0000780000000000 ),
+               LONG2CHARS( 0x0000F80000000000 ),
+               LONG2CHARS( 0x0001F80000000000 ),
+               LONG2CHARS( 0x0003F80000000000 ),
+               LONG2CHARS( 0x0007F80000000000 ),
+               LONG2CHARS( 0x000FF80000000000 ),
+               LONG2CHARS( 0x001FF80000000000 ),
+               LONG2CHARS( 0x003FF80000000000 ),
+               LONG2CHARS( 0x007FF80000000000 ),
+               LONG2CHARS( 0x00FFF80000000000 ),
+               LONG2CHARS( 0x01FFF80000000000 ),
+               LONG2CHARS( 0x03FFF80000000000 ),
+               LONG2CHARS( 0x07FFF80000000000 ),
+               LONG2CHARS( 0x0FFFF80000000000 ),
+               LONG2CHARS( 0x1FFFF80000000000 ),
+               LONG2CHARS( 0x3FFFF80000000000 ),
+               LONG2CHARS( 0x7FFFF80000000000 ),
+               LONG2CHARS( 0xFFFFF80000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+       },
+       {
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000100000000000 ),
+               LONG2CHARS( 0x0000300000000000 ),
+               LONG2CHARS( 0x0000700000000000 ),
+               LONG2CHARS( 0x0000F00000000000 ),
+               LONG2CHARS( 0x0001F00000000000 ),
+               LONG2CHARS( 0x0003F00000000000 ),
+               LONG2CHARS( 0x0007F00000000000 ),
+               LONG2CHARS( 0x000FF00000000000 ),
+               LONG2CHARS( 0x001FF00000000000 ),
+               LONG2CHARS( 0x003FF00000000000 ),
+               LONG2CHARS( 0x007FF00000000000 ),
+               LONG2CHARS( 0x00FFF00000000000 ),
+               LONG2CHARS( 0x01FFF00000000000 ),
+               LONG2CHARS( 0x03FFF00000000000 ),
+               LONG2CHARS( 0x07FFF00000000000 ),
+               LONG2CHARS( 0x0FFFF00000000000 ),
+               LONG2CHARS( 0x1FFFF00000000000 ),
+               LONG2CHARS( 0x3FFFF00000000000 ),
+               LONG2CHARS( 0x7FFFF00000000000 ),
+               LONG2CHARS( 0xFFFFF00000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+       },
+       {
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000200000000000 ),
+               LONG2CHARS( 0x0000600000000000 ),
+               LONG2CHARS( 0x0000E00000000000 ),
+               LONG2CHARS( 0x0001E00000000000 ),
+               LONG2CHARS( 0x0003E00000000000 ),
+               LONG2CHARS( 0x0007E00000000000 ),
+               LONG2CHARS( 0x000FE00000000000 ),
+               LONG2CHARS( 0x001FE00000000000 ),
+               LONG2CHARS( 0x003FE00000000000 ),
+               LONG2CHARS( 0x007FE00000000000 ),
+               LONG2CHARS( 0x00FFE00000000000 ),
+               LONG2CHARS( 0x01FFE00000000000 ),
+               LONG2CHARS( 0x03FFE00000000000 ),
+               LONG2CHARS( 0x07FFE00000000000 ),
+               LONG2CHARS( 0x0FFFE00000000000 ),
+               LONG2CHARS( 0x1FFFE00000000000 ),
+               LONG2CHARS( 0x3FFFE00000000000 ),
+               LONG2CHARS( 0x7FFFE00000000000 ),
+               LONG2CHARS( 0xFFFFE00000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+       },
+       {
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000400000000000 ),
+               LONG2CHARS( 0x0000C00000000000 ),
+               LONG2CHARS( 0x0001C00000000000 ),
+               LONG2CHARS( 0x0003C00000000000 ),
+               LONG2CHARS( 0x0007C00000000000 ),
+               LONG2CHARS( 0x000FC00000000000 ),
+               LONG2CHARS( 0x001FC00000000000 ),
+               LONG2CHARS( 0x003FC00000000000 ),
+               LONG2CHARS( 0x007FC00000000000 ),
+               LONG2CHARS( 0x00FFC00000000000 ),
+               LONG2CHARS( 0x01FFC00000000000 ),
+               LONG2CHARS( 0x03FFC00000000000 ),
+               LONG2CHARS( 0x07FFC00000000000 ),
+               LONG2CHARS( 0x0FFFC00000000000 ),
+               LONG2CHARS( 0x1FFFC00000000000 ),
+               LONG2CHARS( 0x3FFFC00000000000 ),
+               LONG2CHARS( 0x7FFFC00000000000 ),
+               LONG2CHARS( 0xFFFFC00000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+       },
+       {
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000800000000000 ),
+               LONG2CHARS( 0x0001800000000000 ),
+               LONG2CHARS( 0x0003800000000000 ),
+               LONG2CHARS( 0x0007800000000000 ),
+               LONG2CHARS( 0x000F800000000000 ),
+               LONG2CHARS( 0x001F800000000000 ),
+               LONG2CHARS( 0x003F800000000000 ),
+               LONG2CHARS( 0x007F800000000000 ),
+               LONG2CHARS( 0x00FF800000000000 ),
+               LONG2CHARS( 0x01FF800000000000 ),
+               LONG2CHARS( 0x03FF800000000000 ),
+               LONG2CHARS( 0x07FF800000000000 ),
+               LONG2CHARS( 0x0FFF800000000000 ),
+               LONG2CHARS( 0x1FFF800000000000 ),
+               LONG2CHARS( 0x3FFF800000000000 ),
+               LONG2CHARS( 0x7FFF800000000000 ),
+               LONG2CHARS( 0xFFFF800000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+       },
+       {
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0001000000000000 ),
+               LONG2CHARS( 0x0003000000000000 ),
+               LONG2CHARS( 0x0007000000000000 ),
+               LONG2CHARS( 0x000F000000000000 ),
+               LONG2CHARS( 0x001F000000000000 ),
+               LONG2CHARS( 0x003F000000000000 ),
+               LONG2CHARS( 0x007F000000000000 ),
+               LONG2CHARS( 0x00FF000000000000 ),
+               LONG2CHARS( 0x01FF000000000000 ),
+               LONG2CHARS( 0x03FF000000000000 ),
+               LONG2CHARS( 0x07FF000000000000 ),
+               LONG2CHARS( 0x0FFF000000000000 ),
+               LONG2CHARS( 0x1FFF000000000000 ),
+               LONG2CHARS( 0x3FFF000000000000 ),
+               LONG2CHARS( 0x7FFF000000000000 ),
+               LONG2CHARS( 0xFFFF000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+       },
+       {
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0002000000000000 ),
+               LONG2CHARS( 0x0006000000000000 ),
+               LONG2CHARS( 0x000E000000000000 ),
+               LONG2CHARS( 0x001E000000000000 ),
+               LONG2CHARS( 0x003E000000000000 ),
+               LONG2CHARS( 0x007E000000000000 ),
+               LONG2CHARS( 0x00FE000000000000 ),
+               LONG2CHARS( 0x01FE000000000000 ),
+               LONG2CHARS( 0x03FE000000000000 ),
+               LONG2CHARS( 0x07FE000000000000 ),
+               LONG2CHARS( 0x0FFE000000000000 ),
+               LONG2CHARS( 0x1FFE000000000000 ),
+               LONG2CHARS( 0x3FFE000000000000 ),
+               LONG2CHARS( 0x7FFE000000000000 ),
+               LONG2CHARS( 0xFFFE000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+       },
+       {
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0004000000000000 ),
+               LONG2CHARS( 0x000C000000000000 ),
+               LONG2CHARS( 0x001C000000000000 ),
+               LONG2CHARS( 0x003C000000000000 ),
+               LONG2CHARS( 0x007C000000000000 ),
+               LONG2CHARS( 0x00FC000000000000 ),
+               LONG2CHARS( 0x01FC000000000000 ),
+               LONG2CHARS( 0x03FC000000000000 ),
+               LONG2CHARS( 0x07FC000000000000 ),
+               LONG2CHARS( 0x0FFC000000000000 ),
+               LONG2CHARS( 0x1FFC000000000000 ),
+               LONG2CHARS( 0x3FFC000000000000 ),
+               LONG2CHARS( 0x7FFC000000000000 ),
+               LONG2CHARS( 0xFFFC000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+       },
+       {
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0008000000000000 ),
+               LONG2CHARS( 0x0018000000000000 ),
+               LONG2CHARS( 0x0038000000000000 ),
+               LONG2CHARS( 0x0078000000000000 ),
+               LONG2CHARS( 0x00F8000000000000 ),
+               LONG2CHARS( 0x01F8000000000000 ),
+               LONG2CHARS( 0x03F8000000000000 ),
+               LONG2CHARS( 0x07F8000000000000 ),
+               LONG2CHARS( 0x0FF8000000000000 ),
+               LONG2CHARS( 0x1FF8000000000000 ),
+               LONG2CHARS( 0x3FF8000000000000 ),
+               LONG2CHARS( 0x7FF8000000000000 ),
+               LONG2CHARS( 0xFFF8000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+       },
+       {
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0010000000000000 ),
+               LONG2CHARS( 0x0030000000000000 ),
+               LONG2CHARS( 0x0070000000000000 ),
+               LONG2CHARS( 0x00F0000000000000 ),
+               LONG2CHARS( 0x01F0000000000000 ),
+               LONG2CHARS( 0x03F0000000000000 ),
+               LONG2CHARS( 0x07F0000000000000 ),
+               LONG2CHARS( 0x0FF0000000000000 ),
+               LONG2CHARS( 0x1FF0000000000000 ),
+               LONG2CHARS( 0x3FF0000000000000 ),
+               LONG2CHARS( 0x7FF0000000000000 ),
+               LONG2CHARS( 0xFFF0000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+       },
+       {
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0020000000000000 ),
+               LONG2CHARS( 0x0060000000000000 ),
+               LONG2CHARS( 0x00E0000000000000 ),
+               LONG2CHARS( 0x01E0000000000000 ),
+               LONG2CHARS( 0x03E0000000000000 ),
+               LONG2CHARS( 0x07E0000000000000 ),
+               LONG2CHARS( 0x0FE0000000000000 ),
+               LONG2CHARS( 0x1FE0000000000000 ),
+               LONG2CHARS( 0x3FE0000000000000 ),
+               LONG2CHARS( 0x7FE0000000000000 ),
+               LONG2CHARS( 0xFFE0000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+       },
+       {
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0040000000000000 ),
+               LONG2CHARS( 0x00C0000000000000 ),
+               LONG2CHARS( 0x01C0000000000000 ),
+               LONG2CHARS( 0x03C0000000000000 ),
+               LONG2CHARS( 0x07C0000000000000 ),
+               LONG2CHARS( 0x0FC0000000000000 ),
+               LONG2CHARS( 0x1FC0000000000000 ),
+               LONG2CHARS( 0x3FC0000000000000 ),
+               LONG2CHARS( 0x7FC0000000000000 ),
+               LONG2CHARS( 0xFFC0000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+       },
+       {
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0080000000000000 ),
+               LONG2CHARS( 0x0180000000000000 ),
+               LONG2CHARS( 0x0380000000000000 ),
+               LONG2CHARS( 0x0780000000000000 ),
+               LONG2CHARS( 0x0F80000000000000 ),
+               LONG2CHARS( 0x1F80000000000000 ),
+               LONG2CHARS( 0x3F80000000000000 ),
+               LONG2CHARS( 0x7F80000000000000 ),
+               LONG2CHARS( 0xFF80000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+       },
+       {
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0100000000000000 ),
+               LONG2CHARS( 0x0300000000000000 ),
+               LONG2CHARS( 0x0700000000000000 ),
+               LONG2CHARS( 0x0F00000000000000 ),
+               LONG2CHARS( 0x1F00000000000000 ),
+               LONG2CHARS( 0x3F00000000000000 ),
+               LONG2CHARS( 0x7F00000000000000 ),
+               LONG2CHARS( 0xFF00000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+       },
+       {
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0200000000000000 ),
+               LONG2CHARS( 0x0600000000000000 ),
+               LONG2CHARS( 0x0E00000000000000 ),
+               LONG2CHARS( 0x1E00000000000000 ),
+               LONG2CHARS( 0x3E00000000000000 ),
+               LONG2CHARS( 0x7E00000000000000 ),
+               LONG2CHARS( 0xFE00000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+       },
+       {
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0400000000000000 ),
+               LONG2CHARS( 0x0C00000000000000 ),
+               LONG2CHARS( 0x1C00000000000000 ),
+               LONG2CHARS( 0x3C00000000000000 ),
+               LONG2CHARS( 0x7C00000000000000 ),
+               LONG2CHARS( 0xFC00000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+       },
+       {
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0800000000000000 ),
+               LONG2CHARS( 0x1800000000000000 ),
+               LONG2CHARS( 0x3800000000000000 ),
+               LONG2CHARS( 0x7800000000000000 ),
+               LONG2CHARS( 0xF800000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+       },
+       {
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x1000000000000000 ),
+               LONG2CHARS( 0x3000000000000000 ),
+               LONG2CHARS( 0x7000000000000000 ),
+               LONG2CHARS( 0xF000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+       },
+       {
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x2000000000000000 ),
+               LONG2CHARS( 0x6000000000000000 ),
+               LONG2CHARS( 0xE000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+       },
+       {
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x4000000000000000 ),
+               LONG2CHARS( 0xC000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+       },
+       {
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x8000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+               LONG2CHARS( 0x0000000000000000 ),
+       },
+};
+#endif /* PPW */
+#endif
+
+
+/* used for masking bits in bresenham lines
+   mask[n] is used to mask out all but bit n in a longword (n is a
+screen position).
+   rmask[n] is used to mask out the single bit at position n (n
+is a screen posiotion.)
+*/
+
+#define _1_ ((PixelType)1)
+
+#if (BITMAP_BIT_ORDER == MSBFirst)
+PixelType mask[PPW] =
+    {
+#if PPW == 64
+    LONG2CHARS( _1_<<63 ), LONG2CHARS( 1L<<62 ), LONG2CHARS( 1L<<61 ), 
+    LONG2CHARS( 1L<<60 ), LONG2CHARS( 1L<<59 ),
+    LONG2CHARS( 1L<<58 ), LONG2CHARS( 1L<<57 ), LONG2CHARS( 1L<<56 ), 
+    LONG2CHARS( 1L<<55 ), LONG2CHARS( 1L<<54 ), LONG2CHARS( 1L<<53 ), 
+    LONG2CHARS( 1L<<52 ), LONG2CHARS( 1L<<51 ), LONG2CHARS( 1L<<50 ), 
+    LONG2CHARS( 1L<<49 ), LONG2CHARS( 1L<<48 ), LONG2CHARS( 1L<<47 ), 
+    LONG2CHARS( 1L<<46 ), LONG2CHARS( 1L<<45 ), LONG2CHARS( 1L<<44 ), 
+    LONG2CHARS( 1L<<43 ), LONG2CHARS( 1L<<42 ), LONG2CHARS( 1L<<41 ), 
+    LONG2CHARS( 1L<<40 ), LONG2CHARS( 1L<<39 ), LONG2CHARS( 1L<<38 ),
+    LONG2CHARS( 1L<<37 ), LONG2CHARS( 1L<<36 ), LONG2CHARS( 1L<<35 ), 
+    LONG2CHARS( 1L<<34 ), LONG2CHARS( 1L<<33 ), LONG2CHARS( 1L<<32 ), 
+#endif /* PPW */
+    LONG2CHARS( _1_<<31 ), LONG2CHARS( 1<<30 ), LONG2CHARS( 1<<29 ), 
+    LONG2CHARS( 1<<28 ), LONG2CHARS( 1<<27 ), LONG2CHARS( 1<<26 ), 
+    LONG2CHARS( 1<<25 ), LONG2CHARS( 1<<24 ), LONG2CHARS( 1<<23 ), 
+    LONG2CHARS( 1<<22 ), LONG2CHARS( 1<<21 ), LONG2CHARS( 1<<20 ), 
+    LONG2CHARS( 1<<19 ), LONG2CHARS( 1<<18 ), LONG2CHARS( 1<<17 ), 
+    LONG2CHARS( 1<<16 ), LONG2CHARS( 1<<15 ), LONG2CHARS( 1<<14 ), 
+    LONG2CHARS( 1<<13 ), LONG2CHARS( 1<<12 ), LONG2CHARS( 1<<11 ), 
+    LONG2CHARS( 1<<10 ), LONG2CHARS( 1<<9 ), LONG2CHARS( 1<<8 ),
+    LONG2CHARS( 1<<7 ), LONG2CHARS( 1<<6 ), LONG2CHARS( 1<<5 ), 
+    LONG2CHARS( 1<<4 ), LONG2CHARS( 1<<3 ), LONG2CHARS( 1<<2 ), 
+    LONG2CHARS( 1<<1 ), LONG2CHARS( 1<<0 )
+    };
+
+PixelType rmask[] = 
+    {
+#if PPW == 64
+    0xffffffffffffffff ^ LONG2CHARS( _1_<<63 ),  
+    0xffffffffffffffff ^ LONG2CHARS( 1L<<62 ),
+    0xffffffffffffffff ^ LONG2CHARS( 1L<<61 ), 
+    0xffffffffffffffff ^ LONG2CHARS( 1L<<60 ), 
+    0xffffffffffffffff ^ LONG2CHARS( 1L<<59 ), 
+    0xffffffffffffffff ^ LONG2CHARS( 1L<<58 ), 
+    0xffffffffffffffff ^ LONG2CHARS( 1L<<57 ), 
+    0xffffffffffffffff ^ LONG2CHARS( 1L<<56 ),
+    0xffffffffffffffff ^ LONG2CHARS( 1L<<55 ), 
+    0xffffffffffffffff ^ LONG2CHARS( 1L<<54 ), 
+    0xffffffffffffffff ^ LONG2CHARS( 1L<<53 ), 
+    0xffffffffffffffff ^ LONG2CHARS( 1L<<52 ), 
+    0xffffffffffffffff ^ LONG2CHARS( 1L<<51 ), 
+    0xffffffffffffffff ^ LONG2CHARS( 1L<<50 ),
+    0xffffffffffffffff ^ LONG2CHARS( 1L<<49 ), 
+    0xffffffffffffffff ^ LONG2CHARS( 1L<<48 ), 
+    0xffffffffffffffff ^ LONG2CHARS( 1L<<47 ), 
+    0xffffffffffffffff ^ LONG2CHARS( 1L<<46 ),
+    0xffffffffffffffff ^ LONG2CHARS( 1L<<45 ), 
+    0xffffffffffffffff ^ LONG2CHARS( 1L<<44 ),
+    0xffffffffffffffff ^ LONG2CHARS( 1L<<43 ), 
+    0xffffffffffffffff ^ LONG2CHARS( 1L<<42 ),
+    0xffffffffffffffff ^ LONG2CHARS( 1L<<41 ), 
+    0xffffffffffffffff ^ LONG2CHARS( 1L<<40 ), 
+    0xffffffffffffffff ^ LONG2CHARS( 1L<<39 ),  
+    0xffffffffffffffff ^ LONG2CHARS( 1L<<38 ),
+    0xffffffffffffffff ^ LONG2CHARS( 1L<<37 ),  
+    0xffffffffffffffff ^ LONG2CHARS( 1L<<36 ),  
+    0xffffffffffffffff ^ LONG2CHARS( 1L<<35 ),  
+    0xffffffffffffffff ^ LONG2CHARS( 1L<<34 ),  
+    0xffffffffffffffff ^ LONG2CHARS( 1L<<33 ),  
+    0xffffffffffffffff ^ LONG2CHARS( 1L<<32 ),
+    0xffffffffffffffff ^ LONG2CHARS( 1L<<31 ), 
+    0xffffffffffffffff ^ LONG2CHARS( 1L<<30 ), 
+    0xffffffffffffffff ^ LONG2CHARS( 1L<<29 ), 
+    0xffffffffffffffff ^ LONG2CHARS( 1L<<28 ), 
+    0xffffffffffffffff ^ LONG2CHARS( 1L<<27 ), 
+    0xffffffffffffffff ^ LONG2CHARS( 1L<<26 ),
+    0xffffffffffffffff ^ LONG2CHARS( 1L<<25 ), 
+    0xffffffffffffffff ^ LONG2CHARS( 1L<<24 ), 
+    0xffffffffffffffff ^ LONG2CHARS( 1L<<23 ), 
+    0xffffffffffffffff ^ LONG2CHARS( 1L<<22 ), 
+    0xffffffffffffffff ^ LONG2CHARS( 1L<<21 ), 
+    0xffffffffffffffff ^ LONG2CHARS( 1L<<20 ),
+    0xffffffffffffffff ^ LONG2CHARS( 1L<<19 ), 
+    0xffffffffffffffff ^ LONG2CHARS( 1L<<18 ), 
+    0xffffffffffffffff ^ LONG2CHARS( 1L<<17 ), 
+    0xffffffffffffffff ^ LONG2CHARS( 1L<<16 ),
+    0xffffffffffffffff ^ LONG2CHARS( 1L<<15 ), 
+    0xffffffffffffffff ^ LONG2CHARS( 1L<<14 ),
+    0xffffffffffffffff ^ LONG2CHARS( 1L<<13 ), 
+    0xffffffffffffffff ^ LONG2CHARS( 1L<<12 ),
+    0xffffffffffffffff ^ LONG2CHARS( 1L<<11 ), 
+    0xffffffffffffffff ^ LONG2CHARS( 1L<<10 ), 
+    0xffffffffffffffff ^ LONG2CHARS( 1L<<9 ),  
+    0xffffffffffffffff ^ LONG2CHARS( 1L<<8 ),
+    0xffffffffffffffff ^ LONG2CHARS( 1L<<7 ),  
+    0xffffffffffffffff ^ LONG2CHARS( 1L<<6 ),  
+    0xffffffffffffffff ^ LONG2CHARS( 1L<<5 ),  
+    0xffffffffffffffff ^ LONG2CHARS( 1L<<4 ),  
+    0xffffffffffffffff ^ LONG2CHARS( 1L<<3 ),  
+    0xffffffffffffffff ^ LONG2CHARS( 1L<<2 ),
+    0xffffffffffffffff ^ LONG2CHARS( 1L<<1 ),  
+    0xffffffffffffffff ^ LONG2CHARS( 1L<<0 )
+#else /* PPW */
+    0xffffffff ^ LONG2CHARS( _1_<<31 ), 0xffffffff ^ LONG2CHARS( 1<<30 ), 
+    0xffffffff ^ LONG2CHARS( 1<<29 ), 0xffffffff ^ LONG2CHARS( 1<<28), 
+    0xffffffff ^ LONG2CHARS( 1<<27 ), 0xffffffff ^ LONG2CHARS( 1<<26),
+    0xffffffff ^ LONG2CHARS( 1<<25 ), 0xffffffff ^ LONG2CHARS( 1<<24 ), 
+    0xffffffff ^ LONG2CHARS( 1<<23 ), 0xffffffff ^ LONG2CHARS( 1<<22), 
+    0xffffffff ^ LONG2CHARS( 1<<21 ), 0xffffffff ^ LONG2CHARS( 1<<20),
+    0xffffffff ^ LONG2CHARS( 1<<19 ), 0xffffffff ^ LONG2CHARS( 1<<18 ), 
+    0xffffffff ^ LONG2CHARS( 1<<17 ), 0xffffffff ^ LONG2CHARS( 1<<16),
+    0xffffffff ^ LONG2CHARS( 1<<15 ), 0xffffffff ^ LONG2CHARS( 1<<14),
+    0xffffffff ^ LONG2CHARS( 1<<13 ), 0xffffffff ^ LONG2CHARS( 1<<12 ),
+    0xffffffff ^ LONG2CHARS( 1<<11 ), 0xffffffff ^ LONG2CHARS( 1<<10), 
+    0xffffffff ^ LONG2CHARS( 1<<9 ),  0xffffffff ^ LONG2CHARS( 1<<8),
+    0xffffffff ^ LONG2CHARS( 1<<7 ),  0xffffffff ^ LONG2CHARS( 1<<6),  
+    0xffffffff ^ LONG2CHARS( 1<<5 ),  0xffffffff ^ LONG2CHARS( 1<<4),  
+    0xffffffff ^ LONG2CHARS( 1<<3 ),  0xffffffff ^ LONG2CHARS( 1<<2),
+    0xffffffff ^ LONG2CHARS( 1<<1 ),  0xffffffff ^ LONG2CHARS( 1<<0)
+#endif /* PPW */
+    };
+#else  /* LSBFirst */
+PixelType mask[] =
+    {
+    LONG2CHARS( 1<<0 ), LONG2CHARS( 1<<1 ), LONG2CHARS( 1<<2), 
+    LONG2CHARS( 1<<3 ), LONG2CHARS( 1<<4 ), LONG2CHARS( 1<<5), 
+    LONG2CHARS( 1<<6 ), LONG2CHARS( 1<<7 ), LONG2CHARS( 1<<8), 
+    LONG2CHARS( 1<<9 ), LONG2CHARS( 1<<10 ), LONG2CHARS( 1<<11), 
+    LONG2CHARS( 1<<12 ), LONG2CHARS( 1<<13 ), LONG2CHARS( 1<<14), 
+    LONG2CHARS( 1<<15 ), LONG2CHARS( 1<<16 ), LONG2CHARS( 1<<17), 
+    LONG2CHARS( 1<<18 ), LONG2CHARS( 1<<19 ), LONG2CHARS( 1<<20), 
+    LONG2CHARS( 1<<21 ), LONG2CHARS( 1<<22 ), LONG2CHARS( 1<<23),
+    LONG2CHARS( 1<<24 ), LONG2CHARS( 1<<25 ), LONG2CHARS( 1<<26), 
+    LONG2CHARS( 1<<27 ), LONG2CHARS( 1<<28 ), LONG2CHARS( 1<<29), 
+    LONG2CHARS( 1<<30 ), LONG2CHARS( _1_<<31 )
+#if PPW == 64
+    ,
+    LONG2CHARS( 1L<<32), 
+    LONG2CHARS( 1L<<33 ), LONG2CHARS( 1L<<34 ), LONG2CHARS( 1L<<35), 
+    LONG2CHARS( 1L<<36 ), LONG2CHARS( 1L<<37 ), LONG2CHARS( 1L<<38), 
+    LONG2CHARS( 1L<<39 ), LONG2CHARS( 1L<<40 ), LONG2CHARS( 1L<<41), 
+    LONG2CHARS( 1L<<42 ), LONG2CHARS( 1L<<43 ), LONG2CHARS( 1L<<44), 
+    LONG2CHARS( 1L<<45 ), LONG2CHARS( 1L<<46 ), LONG2CHARS( 1L<<47), 
+    LONG2CHARS( 1L<<48 ), LONG2CHARS( 1L<<49 ), LONG2CHARS( 1L<<50), 
+    LONG2CHARS( 1L<<51 ), LONG2CHARS( 1L<<52 ), LONG2CHARS( 1L<<53),
+    LONG2CHARS( 1L<<54 ), LONG2CHARS( 1L<<55 ), LONG2CHARS( 1L<<56), 
+    LONG2CHARS( 1L<<57 ), LONG2CHARS( 1L<<58 ), LONG2CHARS( 1L<<59), 
+    LONG2CHARS( 1L<<60 ), LONG2CHARS( 1L<<61 ),
+    LONG2CHARS( 1L<<62 ), LONG2CHARS( _1_<<63 ), 
+#endif /* PPW */
+    }; 
+PixelType rmask[] = 
+    {
+#if PPW == 32
+    0xffffffff ^ LONG2CHARS( 1<<0), 0xffffffff ^ LONG2CHARS( 1<<1), 
+    0xffffffff ^ LONG2CHARS( 1<<2), 0xffffffff ^ LONG2CHARS( 1<<3), 
+    0xffffffff ^ LONG2CHARS( 1<<4), 0xffffffff ^ LONG2CHARS( 1<<5),
+    0xffffffff ^ LONG2CHARS( 1<<6), 0xffffffff ^ LONG2CHARS( 1<<7), 
+    0xffffffff ^ LONG2CHARS( 1<<8), 0xffffffff ^ LONG2CHARS( 1<<9), 
+    0xffffffff ^ LONG2CHARS( 1<<10), 0xffffffff ^ LONG2CHARS( 1<<11),
+    0xffffffff ^ LONG2CHARS( 1<<12), 0xffffffff ^ LONG2CHARS( 1<<13), 
+    0xffffffff ^ LONG2CHARS( 1<<14), 0xffffffff ^ LONG2CHARS( 1<<15), 
+    0xffffffff ^ LONG2CHARS( 1<<16), 0xffffffff ^ LONG2CHARS( 1<<17),
+    0xffffffff ^ LONG2CHARS( 1<<18), 0xffffffff ^ LONG2CHARS( 1<<19), 
+    0xffffffff ^ LONG2CHARS( 1<<20), 0xffffffff ^ LONG2CHARS( 1<<21), 
+    0xffffffff ^ LONG2CHARS( 1<<22), 0xffffffff ^ LONG2CHARS( 1<<23),
+    0xffffffff ^ LONG2CHARS( 1<<24), 0xffffffff ^ LONG2CHARS( 1<<25), 
+    0xffffffff ^ LONG2CHARS( 1<<26), 0xffffffff ^ LONG2CHARS( 1<<27), 
+    0xffffffff ^ LONG2CHARS( 1<<28), 0xffffffff ^ LONG2CHARS( 1<<29),
+    0xffffffff ^ LONG2CHARS( 1<<30), 0xffffffff ^ LONG2CHARS( _1_<<31)
+#else /* PPW */
+    0xffffffffffffffff ^ LONG2CHARS( 1L<<0), 
+    0xffffffffffffffff ^ LONG2CHARS( 1L<<1), 
+    0xffffffffffffffff ^ LONG2CHARS( 1L<<2), 
+    0xffffffffffffffff ^ LONG2CHARS( 1L<<3), 
+    0xffffffffffffffff ^ LONG2CHARS( 1L<<4), 
+    0xffffffffffffffff ^ LONG2CHARS( 1L<<5),
+    0xffffffffffffffff ^ LONG2CHARS( 1L<<6), 
+    0xffffffffffffffff ^ LONG2CHARS( 1L<<7), 
+    0xffffffffffffffff ^ LONG2CHARS( 1L<<8), 
+    0xffffffffffffffff ^ LONG2CHARS( 1L<<9), 
+    0xffffffffffffffff ^ LONG2CHARS( 1L<<10), 
+    0xffffffffffffffff ^ LONG2CHARS( 1L<<11),
+    0xffffffffffffffff ^ LONG2CHARS( 1L<<12), 
+    0xffffffffffffffff ^ LONG2CHARS( 1L<<13), 
+    0xffffffffffffffff ^ LONG2CHARS( 1L<<14), 
+    0xffffffffffffffff ^ LONG2CHARS( 1L<<15), 
+    0xffffffffffffffff ^ LONG2CHARS( 1L<<16), 
+    0xffffffffffffffff ^ LONG2CHARS( 1L<<17),
+    0xffffffffffffffff ^ LONG2CHARS( 1L<<18), 
+    0xffffffffffffffff ^ LONG2CHARS( 1L<<19), 
+    0xffffffffffffffff ^ LONG2CHARS( 1L<<20), 
+    0xffffffffffffffff ^ LONG2CHARS( 1L<<21), 
+    0xffffffffffffffff ^ LONG2CHARS( 1L<<22), 
+    0xffffffffffffffff ^ LONG2CHARS( 1L<<23),
+    0xffffffffffffffff ^ LONG2CHARS( 1L<<24), 
+    0xffffffffffffffff ^ LONG2CHARS( 1L<<25), 
+    0xffffffffffffffff ^ LONG2CHARS( 1L<<26), 
+    0xffffffffffffffff ^ LONG2CHARS( 1L<<27), 
+    0xffffffffffffffff ^ LONG2CHARS( 1L<<28), 
+    0xffffffffffffffff ^ LONG2CHARS( 1L<<29),
+    0xffffffffffffffff ^ LONG2CHARS( 1L<<30), 
+    0xffffffffffffffff ^ LONG2CHARS( 1L<<31),
+    0xffffffffffffffff ^ LONG2CHARS( 1L<<32), 
+    0xffffffffffffffff ^ LONG2CHARS( 1L<<33), 
+    0xffffffffffffffff ^ LONG2CHARS( 1L<<34), 
+    0xffffffffffffffff ^ LONG2CHARS( 1L<<35),
+    0xffffffffffffffff ^ LONG2CHARS( 1L<<36), 
+    0xffffffffffffffff ^ LONG2CHARS( 1L<<37), 
+    0xffffffffffffffff ^ LONG2CHARS( 1L<<38), 
+    0xffffffffffffffff ^ LONG2CHARS( 1L<<39), 
+    0xffffffffffffffff ^ LONG2CHARS( 1L<<40), 
+    0xffffffffffffffff ^ LONG2CHARS( 1L<<41),
+    0xffffffffffffffff ^ LONG2CHARS( 1L<<42), 
+    0xffffffffffffffff ^ LONG2CHARS( 1L<<43), 
+    0xffffffffffffffff ^ LONG2CHARS( 1L<<44), 
+    0xffffffffffffffff ^ LONG2CHARS( 1L<<45), 
+    0xffffffffffffffff ^ LONG2CHARS( 1L<<46), 
+    0xffffffffffffffff ^ LONG2CHARS( 1L<<47),
+    0xffffffffffffffff ^ LONG2CHARS( 1L<<48), 
+    0xffffffffffffffff ^ LONG2CHARS( 1L<<49), 
+    0xffffffffffffffff ^ LONG2CHARS( 1L<<50), 
+    0xffffffffffffffff ^ LONG2CHARS( 1L<<51), 
+    0xffffffffffffffff ^ LONG2CHARS( 1L<<52), 
+    0xffffffffffffffff ^ LONG2CHARS( 1L<<53),
+    0xffffffffffffffff ^ LONG2CHARS( 1L<<54), 
+    0xffffffffffffffff ^ LONG2CHARS( 1L<<55), 
+    0xffffffffffffffff ^ LONG2CHARS( 1L<<56), 
+    0xffffffffffffffff ^ LONG2CHARS( 1L<<57), 
+    0xffffffffffffffff ^ LONG2CHARS( 1L<<58), 
+    0xffffffffffffffff ^ LONG2CHARS( 1L<<59),
+    0xffffffffffffffff ^ LONG2CHARS( 1L<<60), 
+    0xffffffffffffffff ^ LONG2CHARS( 1L<<61),
+    0xffffffffffffffff ^ LONG2CHARS( 1L<<62), 
+    0xffffffffffffffff ^ LONG2CHARS( _1_<<63), 
+#endif /* PPW */
+    };
+#endif /* BITMAP_BIT_ORDER */
+
+#undef _1_
+
+/*
+ * Merge raster ops for full src + dest + plane mask
+ *
+ * More clever usage of boolean arithmetic to reduce the
+ * cost of complex raster ops.  This is for bitblt and
+ * reduces all 16 raster ops + planemask to a single
+ * expression:
+ *
+ *  dst = dst & (src & ca1 ^ cx1) ^ (src & ca2 ^ cx2)
+ *
+ * The array below contains the values for c?? for each
+ * raster op.  Those values are further modified by
+ * planemasks on multi-plane displays as follows:
+ *
+ *  ca1 &= pm;
+ *  cx1 |= ~pm;
+ *  ca2 &= pm;
+ *  cx2 &= pm;
+ */
+
+#include "mergerop.h"
+
+#define O 0
+#define I ~((unsigned long)0)
+
+mergeRopRec mergeRopBits[16] = {
+O,O,O,O,       /* clear        0x0             0 */
+I,O,O,O,       /* and          0x1             src AND dst */
+I,O,I,O,       /* andReverse   0x2             src AND NOT dst */
+O,O,I,O,       /* copy         0x3             src */
+I,I,O,O,       /* andInverted  0x4             NOT src AND dst */
+O,I,O,O,       /* noop         0x5             dst */
+O,I,I,O,       /* xor          0x6             src XOR dst */
+I,I,I,O,       /* or           0x7             src OR dst */
+I,I,I,I,       /* nor          0x8             NOT src AND NOT dst */
+O,I,I,I,       /* equiv        0x9             NOT src XOR dst */
+O,I,O,I,       /* invert       0xa             NOT dst */
+I,I,O,I,       /* orReverse    0xb             src OR NOT dst */
+O,O,I,I,       /* copyInverted 0xc             NOT src */
+I,O,I,I,       /* orInverted   0xd             NOT src OR dst */
+I,O,O,I,       /* nand         0xe             NOT src OR NOT dst */
+O,O,O,I,       /* set          0xf             1 */
+};
+
+#undef O
+#undef I
diff --git a/Xserver/programs/Xserver/mfb/maskbits.h b/Xserver/programs/Xserver/mfb/maskbits.h
new file mode 100644 (file)
index 0000000..cab946a
--- /dev/null
@@ -0,0 +1,719 @@
+/* Combined Purdue/PurduePlus patches, level 2.1, 1/24/89 */
+/***********************************************************
+Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
+
+                        All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and its
+documentation for any purpose and without fee is hereby granted,
+provided that the above copyright notice appear in all copies and that
+both that copyright notice and this permission notice appear in
+supporting documentation, and that the name of Digital not be
+used in advertising or publicity pertaining to distribution of the
+software without specific, written prior permission.
+
+DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
+ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
+DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
+ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+SOFTWARE.
+
+******************************************************************/
+/* $XConsortium: maskbits.h,v 1.33 94/04/17 20:28:13 dpw Exp $ */
+/* $XFree86: xc/programs/Xserver/mfb/maskbits.h,v 3.3 1996/12/09 11:56:33 dawes Exp $ */
+#include "X.h"
+#include "Xmd.h"
+#include "servermd.h"
+
+
+/* the following notes use the following conventions:
+SCREEN LEFT                            SCREEN RIGHT
+in this file and maskbits.c, left and right refer to screen coordinates,
+NOT bit numbering in registers.
+
+starttab[n]
+       bits[0,n-1] = 0 bits[n,PLST] = 1
+endtab[n] =
+       bits[0,n-1] = 1 bits[n,PLST] = 0
+
+startpartial[], endpartial[]
+       these are used as accelerators for doing putbits and masking out
+bits that are all contained between longword boudaries.  the extra
+256 bytes of data seems a small price to pay -- code is smaller,
+and narrow things (e.g. window borders) go faster.
+
+the names may seem misleading; they are derived not from which end
+of the word the bits are turned on, but at which end of a scanline
+the table tends to be used.
+
+look at the tables and macros to understand boundary conditions.
+(careful readers will note that starttab[n] = ~endtab[n] for n != 0)
+
+-----------------------------------------------------------------------
+these two macros depend on the screen's bit ordering.
+in both of them x is a screen position.  they are used to
+combine bits collected from multiple longwords into a
+single destination longword, and to unpack a single
+source longword into multiple destinations.
+
+SCRLEFT(dst, x)
+       takes dst[x, PPW] and moves them to dst[0, PPW-x]
+       the contents of the rest of dst are 0.
+       this is a right shift on LSBFirst (forward-thinking)
+       machines like the VAX, and left shift on MSBFirst
+       (backwards) machines like the 680x0 and pc/rt.
+
+SCRRIGHT(dst, x)
+       takes dst[0,x] and moves them to dst[PPW-x, PPW]
+       the contents of the rest of dst are 0.
+       this is a left shift on LSBFirst, right shift
+       on MSBFirst.
+
+
+the remaining macros are cpu-independent; all bit order dependencies
+are built into the tables and the two macros above.
+
+maskbits(x, w, startmask, endmask, nlw)
+       for a span of width w starting at position x, returns
+a mask for ragged bits at start, mask for ragged bits at end,
+and the number of whole longwords between the ends.
+
+maskpartialbits(x, w, mask)
+       works like maskbits(), except all the bits are in the
+       same longword (i.e. (x&PIM + w) <= PPW)
+
+maskPPWbits(x, w, startmask, endmask, nlw)
+       as maskbits, but does not calculate nlw.  it is used by
+       mfbGlyphBlt to put down glyphs <= PPW bits wide.
+
+-------------------------------------------------------------------
+
+NOTE
+       any pointers passed to the following 4 macros are
+       guranteed to be PPW-bit aligned.
+       The only non-PPW-bit-aligned references ever made are
+       to font glyphs, and those are made with getleftbits()
+       and getshiftedleftbits (qq.v.)
+
+       For 64-bit server, it is assumed that we will never have font padding
+       of more than 4 bytes. The code uses int's to access the fonts
+       intead of longs.
+
+getbits(psrc, x, w, dst)
+       starting at position x in psrc (x < PPW), collect w
+       bits and put them in the screen left portion of dst.
+       psrc is a longword pointer.  this may span longword boundaries.
+       it special-cases fetching all w bits from one longword.
+
+       +--------+--------+             +--------+
+       |    | m |n|      |     ==>     | m |n|  |
+       +--------+--------+             +--------+
+           x      x+w                  0     w
+       psrc     psrc+1                 dst
+                       m = PPW - x
+                       n = w - m
+
+       implementation:
+       get m bits, move to screen-left of dst, zeroing rest of dst;
+       get n bits from next word, move screen-right by m, zeroing
+                lower m bits of word.
+       OR the two things together.
+
+putbits(src, x, w, pdst)
+       starting at position x in pdst, put down the screen-leftmost
+       w bits of src.  pdst is a longword pointer.  this may
+       span longword boundaries.
+       it special-cases putting all w bits into the same longword.
+
+       +--------+                      +--------+--------+
+       | m |n|  |              ==>     |    | m |n|      |
+       +--------+                      +--------+--------+
+       0     w                              x     x+w
+       dst                             pdst     pdst+1
+                       m = PPW - x
+                       n = w - m
+
+       implementation:
+       get m bits, shift screen-right by x, zero screen-leftmost x
+               bits; zero rightmost m bits of *pdst and OR in stuff
+               from before the semicolon.
+       shift src screen-left by m, zero bits n-PPW;
+               zero leftmost n bits of *(pdst+1) and OR in the
+               stuff from before the semicolon.
+
+putbitsrop(src, x, w, pdst, ROP)
+       like putbits but calls DoRop with the rasterop ROP (see mfb.h for
+       DoRop)
+
+putbitsrrop(src, x, w, pdst, ROP)
+       like putbits but calls DoRRop with the reduced rasterop ROP
+       (see mfb.h for DoRRop)
+
+-----------------------------------------------------------------------
+       The two macros below are used only for getting bits from glyphs
+in fonts, and glyphs in fonts are gotten only with the following two
+mcros.
+       You should tune these macros toyour font format and cpu
+byte ordering.
+
+NOTE
+getleftbits(psrc, w, dst)
+       get the leftmost w (w<=32) bits from *psrc and put them
+       in dst.  this is used by the mfbGlyphBlt code for glyphs
+       <=PPW bits wide.
+       psrc is declared (unsigned char *)
+
+       psrc is NOT guaranteed to be PPW-bit aligned.  on  many
+       machines this will cause problems, so there are several
+       versions of this macro.
+
+       this macro is called ONLY for getting bits from font glyphs,
+       and depends on the server-natural font padding.
+
+       for blazing text performance, you want this macro
+       to touch memory as infrequently as possible (e.g.
+       fetch longwords) and as efficiently as possible
+       (e.g. don't fetch misaligned longwords)
+
+getshiftedleftbits(psrc, offset, w, dst)
+       used by the font code; like getleftbits, but shifts the
+       bits SCRLEFT by offset.
+       this is implemented portably, calling getleftbits()
+       and SCRLEFT().
+       psrc is declared (unsigned char *).
+*/
+
+/* to match CFB and allow algorithm sharing ...
+ * name           mfb32  mfb64  explanation
+ * ----           ------ -----  -----------
+ * PGSZ    32      64    pixel group size (in bits; same as PPW for mfb)
+ * PGSZB    4      8     pixel group size (in bytes)
+ * PPW    32     64     pixels per word (pixels per pixel group)
+ * PLST           31     63     index of last pixel in a word (should be PPW-1)
+ * PIM    0x1f   0x3f   pixel index mask (index within a pixel group)
+ * PWSH           5       6     pixel-to-word shift (should be log2(PPW))
+ *
+ * The MFB_ versions are here so that cfb can include maskbits.h to get
+ * the bitmap constants without conflicting with its own P* constants.
+ */        
+
+/* warning: PixelType definition duplicated in mfb.h */
+#ifndef PixelType
+#define PixelType unsigned long
+#endif /* PixelType */
+
+#ifdef LONG64
+#define MFB_PGSZB 8
+#else
+#define MFB_PGSZB 4
+#endif /* LONG64 */
+#define MFB_PPW                (MFB_PGSZB<<3) /* assuming 8 bits per byte */
+#define MFB_PGSZ       MFB_PPW
+#define MFB_PLST       (MFB_PPW-1)
+#define MFB_PIM                MFB_PLST
+
+/* set PWSH = log2(PPW) using brute force */
+
+#if MFB_PPW == 32
+#define MFB_PWSH 5
+#else
+#if MFB_PPW == 64
+#define MFB_PWSH 6
+#endif /* MFB_PPW == 64 */
+#endif /* MFB_PPW == 32 */
+
+extern PixelType starttab[];
+extern PixelType endtab[];
+extern PixelType partmasks[MFB_PPW][MFB_PPW];
+extern PixelType rmask[];
+extern PixelType mask[];
+
+#ifndef MFB_CONSTS_ONLY
+
+#define PGSZB  MFB_PGSZB
+#define PPW    MFB_PPW
+#define PGSZ   MFB_PGSZ
+#define PLST   MFB_PLST
+#define PIM    MFB_PIM
+#define PWSH   MFB_PWSH
+
+#define BitLeft(b,s)   SCRLEFT(b,s)
+#define BitRight(b,s)  SCRRIGHT(b,s)
+
+#if (BITMAP_BIT_ORDER == IMAGE_BYTE_ORDER)
+#define LONG2CHARS(x) ((unsigned long)(x))
+#else
+/*
+ *  the unsigned case below is for compilers like
+ *  the Danbury C and i386cc
+ */
+#if PPW == 32
+#define LONG2CHARS( x ) ( ( ( ( x ) & (unsigned long)0x000000FF ) << 0x18 ) \
+                        | ( ( ( x ) & (unsigned long)0x0000FF00 ) << 0x08 ) \
+                        | ( ( ( x ) & (unsigned long)0x00FF0000 ) >> 0x08 ) \
+                        | ( ( ( x ) & (unsigned long)0xFF000000 ) >> 0x18 ) )
+#else /* PPW == 64 */
+#if defined( __alpha__)
+#define LONG2CHARS( x ) \
+      ( ( ( ( x ) & 0x000000FFUL) << 0x38 ) \
+      | ( ( ( x ) & 0x0000FF00UL) << 0x28 ) \
+      | ( ( ( x ) & 0x00FF0000UL) << 0x18 ) \
+      | ( ( ( x ) & 0xFF000000UL) << 0x08 ) \
+      | ( ( ( x ) & 0x000000FF00000000UL) >> 0x08 ) \
+      | ( ( ( x ) & 0x0000FF0000000000UL) >> 0x18 ) \
+      | ( ( ( x ) & 0x00FF000000000000UL) >> 0x28 ) \
+      | ( ( ( x ) & 0xFF00000000000000UL) >> 0x38 ) )
+#else /* __alpha__ */
+#define LONG2CHARS( x ) ( ( ( ( x ) & 0x000000FF000000FFUL) << 0x18 ) \
+                       | ( ( ( x ) & 0x0000FF000000FF00UL) << 0x08 ) \
+                       | ( ( ( x ) & 0x00FF000000FF0000UL) >> 0x08 ) \
+                       | ( ( ( x ) & 0xFF000000FF000000UL) >> 0x18 ) )
+#endif /* __alpha__ */
+#endif /* PPW */
+#endif /* BITMAP_BIT_ORDER */
+
+#ifdef STRICT_ANSI_SHIFT
+#define SHL(x,y)    ((y) >= PPW ? 0 : LONG2CHARS(LONG2CHARS(x) << (y)))
+#define SHR(x,y)    ((y) >= PPW ? 0 : LONG2CHARS(LONG2CHARS(x) >> (y)))
+#else
+#define SHL(x,y)    LONG2CHARS(LONG2CHARS(x) << (y))
+#define SHR(x,y)    LONG2CHARS(LONG2CHARS(x) >> (y))
+#endif
+
+#if (BITMAP_BIT_ORDER == MSBFirst)     /* pc/rt, 680x0 */
+#define SCRLEFT(lw, n) SHL((PixelType)(lw),(n))
+#define SCRRIGHT(lw, n)        SHR((PixelType)(lw),(n))
+#else                                  /* vax, intel */
+#define SCRLEFT(lw, n) SHR((PixelType)(lw),(n))
+#define SCRRIGHT(lw, n)        SHL((PixelType)(lw),(n))
+#endif
+
+#define DoRRop(alu, src, dst) \
+(((alu) == RROP_BLACK) ? ((dst) & ~(src)) : \
+ ((alu) == RROP_WHITE) ? ((dst) | (src)) : \
+ ((alu) == RROP_INVERT) ? ((dst) ^ (src)) : \
+  (dst))
+
+#if PPW == 32
+/* A generalized form of a x4 Duff's Device */
+#define Duff(counter, block) { \
+  while (counter >= 4) {\
+     { block; } \
+     { block; } \
+     { block; } \
+     { block; } \
+     counter -= 4; \
+  } \
+     switch (counter & 3) { \
+     case 3:   { block; } \
+     case 2:   { block; } \
+     case 1:   { block; } \
+     case 0: \
+     counter = 0; \
+   } \
+}
+#else /* PPW == 64 */
+/* A generalized form of a x8 Duff's Device */
+#define Duff(counter, block) { \
+  while (counter >= 8) {\
+     { block; } \
+     { block; } \
+     { block; } \
+     { block; } \
+     { block; } \
+     { block; } \
+     { block; } \
+     { block; } \
+     counter -= 8; \
+  } \
+     switch (counter & 7) { \
+     case 7:   { block; } \
+     case 6:   { block; } \
+     case 5:   { block; } \
+     case 4:   { block; } \
+     case 3:   { block; } \
+     case 2:   { block; } \
+     case 1:   { block; } \
+     case 0: \
+     counter = 0; \
+   } \
+}
+#endif /* PPW */
+
+
+#define maskbits(x, w, startmask, endmask, nlw) \
+    startmask = starttab[(x) & PIM]; \
+    endmask = endtab[((x)+(w)) & PIM]; \
+    if (startmask) \
+       nlw = (((w) - (PPW - ((x) & PIM))) >> PWSH); \
+    else \
+       nlw = (w) >> PWSH;
+
+#define maskpartialbits(x, w, mask) \
+    mask = partmasks[(x) & PIM][(w) & PIM];
+
+#define maskPPWbits(x, w, startmask, endmask) \
+    startmask = starttab[(x) & PIM]; \
+    endmask = endtab[((x)+(w)) & PIM];
+
+#ifdef __GNUC__ /* XXX don't want for Alpha? */
+#ifdef vax
+#define FASTGETBITS(psrc,x,w,dst) \
+    __asm ("extzv %1,%2,%3,%0" \
+        : "=g" (dst) \
+        : "g" (x), "g" (w), "m" (*(char *)(psrc)))
+#define getbits(psrc,x,w,dst) FASTGETBITS(psrc,x,w,dst)
+
+#define FASTPUTBITS(src, x, w, pdst) \
+    __asm ("insv %3,%1,%2,%0" \
+        : "=m" (*(char *)(pdst)) \
+        : "g" (x), "g" (w), "g" (src))
+#define putbits(src, x, w, pdst) FASTPUTBITS(src, x, w, pdst)
+#endif /* vax */
+#ifdef mc68020
+#define FASTGETBITS(psrc, x, w, dst) \
+    __asm ("bfextu %3{%1:%2},%0" \
+    : "=d" (dst) : "di" (x), "di" (w), "o" (*(char *)(psrc)))
+
+#define getbits(psrc,x,w,dst) \
+{ \
+    FASTGETBITS(psrc, x, w, dst);\
+    dst = SHL(dst,(32-(w))); \
+}
+
+#define FASTPUTBITS(src, x, w, pdst) \
+    __asm ("bfins %3,%0{%1:%2}" \
+        : "=o" (*(char *)(pdst)) \
+        : "di" (x), "di" (w), "d" (src), "0" (*(char *) (pdst)))
+
+#define putbits(src, x, w, pdst) FASTPUTBITS(SHR((src),32-(w)), x, w, pdst)
+
+#endif /* mc68020 */
+#endif /* __GNUC__ */
+
+/*  The following flag is used to override a bugfix for sun 3/60+CG4 machines,
+ */
+
+/*  We don't need to be careful about this unless we're dealing with sun3's 
+ *  We will default its usage for those who do not know anything, but will
+ *  override its effect if the machine doesn't look like a sun3 
+ */
+#if !defined(mc68020) || !defined(sun)
+#define NO_3_60_CG4
+#endif
+
+/* This is gross.  We want to #define u_putbits as something which can be used
+ * in the case of the 3/60+CG4, but if we use /bin/cc or are on another
+ * machine type, we want nothing to do with u_putbits.  What a hastle.  Here
+ * I used slo_putbits as something which either u_putbits or putbits could be
+ * defined as.
+ *
+ * putbits gets it iff it is not already defined with FASTPUTBITS above.
+ * u_putbits gets it if we have FASTPUTBITS (putbits) from above and have not
+ *     overridden the NO_3_60_CG4 flag.
+ */
+
+#define slo_putbits(src, x, w, pdst) \
+{ \
+    register int n = (x)+(w)-PPW; \
+    \
+    if (n <= 0) \
+    { \
+       register PixelType tmpmask; \
+       maskpartialbits((x), (w), tmpmask); \
+       *(pdst) = (*(pdst) & ~tmpmask) | \
+               (SCRRIGHT(src, x) & tmpmask); \
+    } \
+    else \
+    { \
+       *(pdst) = (*(pdst) & endtab[x]) | (SCRRIGHT((src), x)); \
+       (pdst)[1] = ((pdst)[1] & starttab[n]) | \
+               (SCRLEFT(src, PPW-(x)) & endtab[n]); \
+    } \
+}
+
+#if defined(putbits) && !defined(NO_3_60_CG4)
+#define u_putbits(src, x, w, pdst) slo_putbits(src, x, w, pdst)
+#else
+#define u_putbits(src, x, w, pdst) putbits(src, x, w, pdst)
+#endif
+
+#if !defined(putbits) 
+#define putbits(src, x, w, pdst) slo_putbits(src, x, w, pdst)
+#endif
+
+/* Now if we have not gotten any really good bitfield macros, try some
+ * moderately fast macros.  Alas, I don't know how to do asm instructions
+ * without gcc.
+ */
+
+#ifndef getbits
+#define getbits(psrc, x, w, dst) \
+{ \
+    dst = SCRLEFT(*(psrc), (x)); \
+    if ( ((x) + (w)) > PPW) \
+       dst |= (SCRRIGHT(*((psrc)+1), PPW-(x))); \
+}
+#endif
+
+/*  We have to special-case putbitsrop because of 3/60+CG4 combos
+ */
+
+#define u_putbitsrop(src, x, w, pdst, rop) \
+{\
+       register PixelType t1, t2; \
+       register int n = (x)+(w)-PPW; \
+       \
+       t1 = SCRRIGHT((src), (x)); \
+       DoRop(t2, rop, t1, *(pdst)); \
+       \
+    if (n <= 0) \
+    { \
+       register PixelType tmpmask; \
+       \
+       maskpartialbits((x), (w), tmpmask); \
+       *(pdst) = (*(pdst) & ~tmpmask) | (t2 & tmpmask); \
+    } \
+    else \
+    { \
+       int m = PPW-(x); \
+       *(pdst) = (*(pdst) & endtab[x]) | (t2 & starttab[x]); \
+       t1 = SCRLEFT((src), m); \
+       DoRop(t2, rop, t1, (pdst)[1]); \
+       (pdst)[1] = ((pdst)[1] & starttab[n]) | (t2 & endtab[n]); \
+    } \
+}
+
+/* If our getbits and putbits are FAST enough,
+ * do this brute force, it's faster
+ */
+
+#if defined(FASTPUTBITS) && defined(FASTGETBITS) && defined(NO_3_60_CG4)
+#if (BITMAP_BIT_ORDER == MSBFirst)
+#define putbitsrop(src, x, w, pdst, rop) \
+{ \
+  register PixelType _tmp, _tmp2; \
+  FASTGETBITS(pdst, x, w, _tmp); \
+  _tmp2 = SCRRIGHT(src, PPW-(w)); \
+  DoRop(_tmp, rop, _tmp2, _tmp) \
+  FASTPUTBITS(_tmp, x, w, pdst); \
+}
+#define putbitsrrop(src, x, w, pdst, rop) \
+{ \
+  register PixelType _tmp, _tmp2; \
+ \
+  FASTGETBITS(pdst, x, w, _tmp); \
+  _tmp2 = SCRRIGHT(src, PPW-(w)); \
+  _tmp= DoRRop(rop, _tmp2, _tmp); \
+  FASTPUTBITS(_tmp, x, w, pdst); \
+}
+#undef u_putbitsrop
+#else
+#define putbitsrop(src, x, w, pdst, rop) \
+{ \
+  register PixelType _tmp; \
+  FASTGETBITS(pdst, x, w, _tmp); \
+  DoRop(_tmp, rop, src, _tmp) \
+  FASTPUTBITS(_tmp, x, w, pdst); \
+}
+#define putbitsrrop(src, x, w, pdst, rop) \
+{ \
+  register PixelType _tmp; \
+ \
+  FASTGETBITS(pdst, x, w, _tmp); \
+  _tmp= DoRRop(rop, src, _tmp); \
+  FASTPUTBITS(_tmp, x, w, pdst); \
+}
+#undef u_putbitsrop
+#endif
+#endif
+
+#ifndef putbitsrop
+#define putbitsrop(src, x, w, pdst, rop)  u_putbitsrop(src, x, w, pdst, rop)
+#endif 
+
+#ifndef putbitsrrop
+#define putbitsrrop(src, x, w, pdst, rop) \
+{\
+       register PixelType t1, t2; \
+       register int n = (x)+(w)-PPW; \
+       \
+       t1 = SCRRIGHT((src), (x)); \
+       t2 = DoRRop(rop, t1, *(pdst)); \
+       \
+    if (n <= 0) \
+    { \
+       register PixelType tmpmask; \
+       \
+       maskpartialbits((x), (w), tmpmask); \
+       *(pdst) = (*(pdst) & ~tmpmask) | (t2 & tmpmask); \
+    } \
+    else \
+    { \
+       int m = PPW-(x); \
+       *(pdst) = (*(pdst) & endtab[x]) | (t2 & starttab[x]); \
+       t1 = SCRLEFT((src), m); \
+       t2 = DoRRop(rop, t1, (pdst)[1]); \
+       (pdst)[1] = ((pdst)[1] & starttab[n]) | (t2 & endtab[n]); \
+    } \
+}
+#endif
+
+#if GETLEFTBITS_ALIGNMENT == 1
+#define getleftbits(psrc, w, dst)      dst = *((CARD32 *) psrc)
+#endif /* GETLEFTBITS_ALIGNMENT == 1 */
+
+#if GETLEFTBITS_ALIGNMENT == 2
+#define getleftbits(psrc, w, dst) \
+    { \
+       if ( ((int)(psrc)) & 0x01 ) \
+               getbits( ((CARD32 *)(((char *)(psrc))-1)), 8, (w), (dst) ); \
+       else \
+               getbits(psrc, 0, w, dst); \
+    }
+#endif /* GETLEFTBITS_ALIGNMENT == 2 */
+
+#if GETLEFTBITS_ALIGNMENT == 4
+#define getleftbits(psrc, w, dst) \
+    { \
+       int off, off_b; \
+       off_b = (off = ( ((int)(psrc)) & 0x03)) << 3; \
+       getbits( \
+               (CARD32 *)( ((char *)(psrc)) - off), \
+               (off_b), (w), (dst) \
+              ); \
+    }
+#endif /* GETLEFTBITS_ALIGNMENT == 4 */
+
+
+#define getshiftedleftbits(psrc, offset, w, dst) \
+       getleftbits((psrc), (w), (dst)); \
+       dst = SCRLEFT((dst), (offset));
+
+/* FASTGETBITS and FASTPUTBITS are not necessarily correct implementations of
+ * getbits and putbits, but they work if used together.
+ *
+ * On a MSBFirst machine, a cpu bitfield extract instruction (like bfextu)
+ * could normally assign its result to a long word register in the screen
+ * right position.  This saves canceling register shifts by not fighting the
+ * natural cpu byte order.
+ *
+ * Unfortunately, these fail on a 3/60+CG4 and cannot be used unmodified. Sigh.
+ */
+#if defined(FASTGETBITS) && defined(FASTPUTBITS)
+#ifdef NO_3_60_CG4
+#define u_FASTPUT(aa, bb, cc, dd)  FASTPUTBITS(aa, bb, cc, dd)
+#else
+#define u_FASTPUT(aa, bb, cc, dd)  u_putbits(SCRLEFT(aa, PPW-(cc)), bb, cc, dd)
+#endif
+
+#define getandputbits(psrc, srcbit, dstbit, width, pdst) \
+{ \
+    register PixelType _tmpbits; \
+    FASTGETBITS(psrc, srcbit, width, _tmpbits); \
+    u_FASTPUT(_tmpbits, dstbit, width, pdst); \
+}
+
+#define getandputrop(psrc, srcbit, dstbit, width, pdst, rop) \
+{ \
+  register PixelType _tmpsrc, _tmpdst; \
+  FASTGETBITS(pdst, dstbit, width, _tmpdst); \
+  FASTGETBITS(psrc, srcbit, width, _tmpsrc); \
+  DoRop(_tmpdst, rop, _tmpsrc, _tmpdst); \
+  u_FASTPUT(_tmpdst, dstbit, width, pdst); \
+}
+
+#define getandputrrop(psrc, srcbit, dstbit, width, pdst, rop) \
+{ \
+  register PixelType _tmpsrc, _tmpdst; \
+  FASTGETBITS(pdst, dstbit, width, _tmpdst); \
+  FASTGETBITS(psrc, srcbit, width, _tmpsrc); \
+  _tmpdst = DoRRop(rop, _tmpsrc, _tmpdst); \
+  u_FASTPUT(_tmpdst, dstbit, width, pdst); \
+}
+
+#define getandputbits0(psrc, srcbit, width, pdst) \
+       getandputbits(psrc, srcbit, 0, width, pdst)
+
+#define getandputrop0(psrc, srcbit, width, pdst, rop) \
+       getandputrop(psrc, srcbit, 0, width, pdst, rop)
+
+#define getandputrrop0(psrc, srcbit, width, pdst, rop) \
+       getandputrrop(psrc, srcbit, 0, width, pdst, rop)
+
+
+#else /* Slow poke */
+
+/* pairs of getbits/putbits happen frequently. Some of the code can
+ * be shared or avoided in a few specific instances.  It gets us a
+ * small advantage, so we do it.  The getandput...0 macros are the only ones
+ * which speed things here.  The others are here for compatibility w/the above
+ * FAST ones
+ */
+
+#define getandputbits(psrc, srcbit, dstbit, width, pdst) \
+{ \
+    register PixelType _tmpbits; \
+    getbits(psrc, srcbit, width, _tmpbits); \
+    putbits(_tmpbits, dstbit, width, pdst); \
+}
+
+#define getandputrop(psrc, srcbit, dstbit, width, pdst, rop) \
+{ \
+    register PixelType _tmpbits; \
+    getbits(psrc, srcbit, width, _tmpbits) \
+    putbitsrop(_tmpbits, dstbit, width, pdst, rop) \
+}
+
+#define getandputrrop(psrc, srcbit, dstbit, width, pdst, rop) \
+{ \
+    register PixelType _tmpbits; \
+    getbits(psrc, srcbit, width, _tmpbits) \
+    putbitsrrop(_tmpbits, dstbit, width, pdst, rop) \
+}
+
+
+#define getandputbits0(psrc, sbindex, width, pdst) \
+{                      /* unroll the whole damn thing to see how it * behaves */ \
+    register int          _flag = PPW - (sbindex); \
+    register PixelType _src; \
+ \
+    _src = SCRLEFT (*(psrc), (sbindex)); \
+    if ((width) > _flag) \
+       _src |=  SCRRIGHT (*((psrc) + 1), _flag); \
+ \
+    *(pdst) = (*(pdst) & starttab[(width)]) | (_src & endtab[(width)]); \
+}
+
+
+#define getandputrop0(psrc, sbindex, width, pdst, rop) \
+{                      \
+    register int          _flag = PPW - (sbindex); \
+    register PixelType _src; \
+ \
+    _src = SCRLEFT (*(psrc), (sbindex)); \
+    if ((width) > _flag) \
+       _src |=  SCRRIGHT (*((psrc) + 1), _flag); \
+    DoRop(_src, rop, _src, *(pdst)); \
+ \
+    *(pdst) = (*(pdst) & starttab[(width)]) | (_src & endtab[(width)]); \
+}
+
+#define getandputrrop0(psrc, sbindex, width, pdst, rop) \
+{ \
+    int             _flag = PPW - (sbindex); \
+    register PixelType _src; \
+ \
+    _src = SCRLEFT (*(psrc), (sbindex)); \
+    if ((width) > _flag) \
+       _src |=  SCRRIGHT (*((psrc) + 1), _flag); \
+    _src = DoRRop(rop, _src, *(pdst)); \
+ \
+    *(pdst) = (*(pdst) & starttab[(width)]) | (_src & endtab[(width)]); \
+}
+
+#endif  /* FASTGETBITS && FASTPUTBITS */
+
+#endif /* MFB_CONSTS_ONLY */
diff --git a/Xserver/programs/Xserver/mfb/mergerop.h b/Xserver/programs/Xserver/mfb/mergerop.h
new file mode 100644 (file)
index 0000000..a622c6d
--- /dev/null
@@ -0,0 +1,314 @@
+/*
+ * $XConsortium: mergerop.h,v 1.11 95/06/08 23:20:39 gildea Exp $
+ * $XFree86: xc/programs/Xserver/mfb/mergerop.h,v 3.1 1996/06/29 09:10:20 dawes Exp $
+ *
+Copyright (c) 1989  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+ *
+ * Author:  Keith Packard, MIT X Consortium
+ */
+
+#ifndef _MERGEROP_H_
+#define _MERGEROP_H_
+
+#ifndef GXcopy
+#include "X.h"
+#endif
+
+typedef struct _mergeRopBits {
+    unsigned long   ca1, cx1, ca2, cx2;
+} mergeRopRec, *mergeRopPtr;
+
+extern mergeRopRec     mergeRopBits[16];
+
+#if PPW != PGSZ        /* cfb */
+#define DeclareMergeRop() unsigned long   _ca1, _cx1, _ca2, _cx2;
+#define DeclarePrebuiltMergeRop()      unsigned long   _cca, _ccx;
+#else /* mfb */
+#define DeclareMergeRop() unsigned long   _ca1, _cx1, _ca2, _cx2;
+#define DeclarePrebuiltMergeRop()      unsigned long   _cca, _ccx;
+#endif
+
+#if PPW != PGSZ        /* cfb */
+#define InitializeMergeRop(alu,pm) {\
+    unsigned long   _pm; \
+    mergeRopPtr  _bits; \
+    _pm = PFILL(pm); \
+    _bits = &mergeRopBits[alu]; \
+    _ca1 = _bits->ca1 &  _pm; \
+    _cx1 = _bits->cx1 | ~_pm; \
+    _ca2 = _bits->ca2 &  _pm; \
+    _cx2 = _bits->cx2 &  _pm; \
+}
+#else /* mfb */
+#define InitializeMergeRop(alu,pm) {\
+    mergeRopPtr  _bits; \
+    _bits = &mergeRopBits[alu]; \
+    _ca1 = _bits->ca1; \
+    _cx1 = _bits->cx1; \
+    _ca2 = _bits->ca2; \
+    _cx2 = _bits->cx2; \
+}
+#endif
+
+/* AND has higher precedence than XOR */
+
+#define DoMergeRop(src, dst) \
+    ((dst) & ((src) & _ca1 ^ _cx1) ^ ((src) & _ca2 ^ _cx2))
+
+#define DoMergeRop24(src,dst,index) {\
+       register int idx = ((index) & 3)<< 1; \
+       *(dst) = (((*(dst)) & cfbrmask[idx]) | (((*(dst)) & cfbmask[idx]) & \
+       ((((src) & _ca1 ^ _cx1)<<cfb24Shift[idx])&cfbmask[idx]) ^ \
+       ((((src) & _ca2 ^ _cx2)<<cfb24Shift[idx])&cfbmask[idx]))); \
+       idx++; \
+       (dst)++; \
+       *(dst) = (((*(dst)) & cfbrmask[idx]) | (((*(dst)) & cfbmask[idx]) & \
+       ((((src) & _ca1 ^ _cx1)>>cfb24Shift[idx])&cfbmask[idx]) ^ \
+       ((((src) & _ca2 ^ _cx2)>>cfb24Shift[idx])&cfbmask[idx]))); \
+       (dst)--; \
+       }
+
+#define DoPrebuiltMergeRop(dst) ((dst) & _cca ^ _ccx)
+
+#define DoPrebuiltMergeRop24(dst,index) { \
+       register int idx = ((index) & 3)<< 1; \
+       *(dst) = (((*(dst)) & cfbrmask[idx]) | (((*(dst)) & cfbmask[idx]) &\
+       (( _cca <<cfb24Shift[idx])&cfbmask[idx]) ^ \
+       (( _ccx <<cfb24Shift[idx])&cfbmask[idx]))); \
+       idx++; \
+       (dst)++; \
+       *(dst) = (((*(dst)) & cfbrmask[idx]) | (((*(dst)) & cfbmask[idx]) &\
+       (( _cca >>cfb24Shift[idx])&cfbmask[idx]) ^ \
+       (( _ccx >>cfb24Shift[idx])&cfbmask[idx]))); \
+       (dst)--; \
+       }
+
+#define DoMaskPrebuiltMergeRop(dst,mask) \
+    ((dst) & (_cca | ~(mask)) ^ (_ccx & (mask)))
+
+#define PrebuildMergeRop(src) ((_cca = (src) & _ca1 ^ _cx1), \
+                              (_ccx = (src) & _ca2 ^ _cx2))
+
+#define DoMaskMergeRop(src, dst, mask) \
+    ((dst) & (((src) & _ca1 ^ _cx1) | ~(mask)) ^ (((src) & _ca2 ^ _cx2) & (mask)))
+
+#define DoMaskMergeRop24(src, dst, mask, index)  {\
+       register int idx = ((index) & 3)<< 1; \
+       *(dst) = (((*(dst)) & cfbrmask[idx]) | (((*(dst)) & cfbmask[idx]) & \
+       ((((((src) & _ca1 ^ _cx1) |(~mask))<<cfb24Shift[idx])&cfbmask[idx]) ^ \
+       (((((src) & _ca2 ^ _cx2)&(mask))<<cfb24Shift[idx])&cfbmask[idx])))); \
+       idx++; \
+       (dst)++; \
+       *(dst) = (((*(dst)) & cfbrmask[idx]) | (((*(dst)) & cfbmask[idx]) & \
+       ((((((src) & _ca1 ^ _cx1) |(~mask))>>cfb24Shift[idx])&cfbmask[idx]) ^ \
+       (((((src) & _ca2 ^ _cx2)&(mask))>>cfb24Shift[idx])&cfbmask[idx])))); \
+       (dst)--; \
+       }
+
+#ifndef MROP
+#define MROP 0
+#endif
+
+#define Mclear         (1<<GXclear)
+#define Mand           (1<<GXand)
+#define MandReverse    (1<<GXandReverse)
+#define Mcopy          (1<<GXcopy)
+#define MandInverted   (1<<GXandInverted)
+#define Mnoop          (1<<GXnoop)
+#define Mxor           (1<<GXxor)
+#define Mor            (1<<GXor)
+#define Mnor           (1<<GXnor)
+#define Mequiv         (1<<GXequiv)
+#define Minvert                (1<<GXinvert)
+#define MorReverse     (1<<GXorReverse)
+#define McopyInverted  (1<<GXcopyInverted)
+#define MorInverted    (1<<GXorInverted)
+#define Mnand          (1<<GXnand)
+#define Mset           (1<<GXset)
+
+#define MROP_PIXEL24(pix, idx) \
+       (((*(pix) & cfbmask[(idx)<<1]) >> cfb24Shift[(idx)<<1])| \
+       ((*((pix)+1) & cfbmask[((idx)<<1)+1]) << cfb24Shift[((idx)<<1)+1]))
+
+#define MROP_SOLID24P(src,dst,sindex, index) \
+       MROP_SOLID24(MROP_PIXEL24(src,sindex),dst,index)
+#define MROP_MASK24P(src,dst,mask,sindex,index)        \
+       MROP_MASK24(MROP_PIXEL24(src,sindex),dst,mask,index)
+
+#if (MROP) == Mcopy
+#define MROP_DECLARE()
+#define MROP_DECLARE_REG()
+#define MROP_INITIALIZE(alu,pm)
+#define MROP_SOLID(src,dst)    (src)
+#define MROP_SOLID24(src,dst,index)        {\
+       register int idx = ((index) & 3)<< 1; \
+       *(dst) = (*(dst) & cfbrmask[idx])|(((src)<<cfb24Shift[idx])&cfbmask[idx]); \
+       idx++; \
+       *((dst)+1) = (*((dst)+1) & cfbrmask[idx])|(((src)>>cfb24Shift[idx])&cfbmask[idx]); \
+       }
+#define MROP_MASK(src,dst,mask)        ((dst) & ~(mask) | (src) & (mask))
+#define MROP_MASK24(src,dst,mask,index)        {\
+       register int idx = ((index) & 3)<< 1; \
+       *(dst) = (*(dst) & cfbrmask[idx] &(~(((mask)<< cfb24Shift[idx])&cfbmask[idx])) | \
+               ((((src)&(mask))<<cfb24Shift[idx])&cfbmask[idx])); \
+       idx++; \
+       *((dst)+1) = (*((dst)+1) & cfbrmask[idx] &(~(((mask)>>cfb24Shift[idx])&cfbmask[idx])) | \
+               ((((src)&(mask))>>cfb24Shift[idx])&cfbmask[idx])); \
+       }
+#define MROP_NAME(prefix)      MROP_NAME_CAT(prefix,Copy)
+#endif
+
+#if (MROP) == McopyInverted
+#define MROP_DECLARE()
+#define MROP_DECLARE_REG()
+#define MROP_INITIALIZE(alu,pm)
+#define MROP_SOLID(src,dst)    (~(src))
+#define MROP_SOLID24(src,dst,index)        {\
+       register int idx = ((index) & 3)<< 1; \
+       *(dst) = (*(dst) & cfbrmask[idx])|(((~(src))<<cfb24Shift[idx])&cfbmask[idx]); \
+       idx++; \
+       (dst)++; \
+       *(dst) = (*(dst) & cfbrmask[idx])|(((~(src))>>cfb24Shift[idx])&cfbmask[idx]); \
+       (dst)--; \
+       }
+#define MROP_MASK(src,dst,mask)        ((dst) & ~(mask) | (~(src)) & (mask))
+#define MROP_MASK24(src,dst,mask,index)        {\
+       register int idx = ((index) & 3)<< 1; \
+       *(dst) = (*(dst) & cfbrmask[idx] &(~(((mask)<< cfb24Shift[idx])&cfbmask[idx])) | \
+               ((((~(src))&(mask))<<cfb24Shift[idx])&cfbmask[idx])); \
+       idx++; \
+       (dst)++; \
+       *(dst) = (*(dst) & cfbrmask[idx] &(~(((mask)>>cfb24Shift[idx])&cfbmask[idx])) | \
+               ((((~(src))&(mask))>>cfb24Shift[idx])&cfbmask[idx])); \
+       (dst)--; \
+       }
+#define MROP_NAME(prefix)      MROP_NAME_CAT(prefix,CopyInverted)
+#endif
+
+#if (MROP) == Mxor
+#define MROP_DECLARE()
+#define MROP_DECLARE_REG()
+#define MROP_INITIALIZE(alu,pm)
+#define MROP_SOLID(src,dst)    ((src) ^ (dst))
+#define MROP_SOLID24(src,dst,index)        {\
+       register int idx = ((index) & 3)<< 1; \
+       *(dst) ^= (((src)<<cfb24Shift[idx])&cfbmask[idx]); \
+       idx++; \
+       (dst)++; \
+       *(dst) ^= (((src)>>cfb24Shift[idx])&cfbmask[idx]); \
+       (dst)--; \
+       }
+#define MROP_MASK(src,dst,mask)        (((src) & (mask)) ^ (dst))
+#define MROP_MASK24(src,dst,mask,index)        {\
+       register int idx = ((index) & 3)<< 1; \
+       *(dst) ^= ((((src)&(mask))<<cfb24Shift[idx])&cfbmask[idx]); \
+       idx++; \
+       (dst)++; \
+       *(dst) ^= ((((src)&(mask))>>cfb24Shift[idx])&cfbmask[idx]); \
+       (dst)--; \
+       }
+#define MROP_NAME(prefix)      MROP_NAME_CAT(prefix,Xor)
+#endif
+
+#if (MROP) == Mor
+#define MROP_DECLARE()
+#define MROP_DECLARE_REG()
+#define MROP_INITIALIZE(alu,pm)
+#define MROP_SOLID(src,dst)    ((src) | (dst))
+#define MROP_SOLID24(src,dst,index)        {\
+       register int idx = ((index) & 3)<< 1; \
+       *(dst) |= (((src)<<cfb24Shift[idx])&cfbmask[idx]); \
+       idx++; \
+       (dst)++; \
+       *(dst) |= (((src)>>cfb24Shift[idx])&cfbmask[idx]); \
+       (dst)--; \
+       }
+#define MROP_MASK(src,dst,mask)        (((src) & (mask)) | (dst))
+#define MROP_MASK24(src,dst,mask,index)        {\
+       register int idx = ((index) & 3)<< 1; \
+       *(dst) |= ((((src)&(mask))<<cfb24Shift[idx])&cfbmask[idx]); \
+       idx++; \
+       (dst)++; \
+       *(dst) |= ((((src)&(mask))>>cfb24Shift[idx])&cfbmask[idx]); \
+       (dst)--; \
+       }
+#define MROP_NAME(prefix)      MROP_NAME_CAT(prefix,Or)
+#endif
+
+#if (MROP) == (Mcopy|Mxor|MandReverse|Mor)
+#define MROP_DECLARE() unsigned long _ca1, _cx1;
+#define MROP_DECLARE_REG()     register MROP_DECLARE()
+#define MROP_INITIALIZE(alu,pm)        { \
+    mergeRopPtr  _bits; \
+    _bits = &mergeRopBits[alu]; \
+    _ca1 = _bits->ca1; \
+    _cx1 = _bits->cx1; \
+}
+#define MROP_SOLID(src,dst) \
+    ((dst) & ((src) & _ca1 ^ _cx1) ^ (src))
+#define MROP_MASK(src,dst,mask)        \
+    ((dst) & (((src) & _ca1 ^ _cx1) | ~(mask)) ^ ((src) & (mask)))
+#define MROP_NAME(prefix)      MROP_NAME_CAT(prefix,CopyXorAndReverseOr)
+#define MROP_PREBUILD(src)     PrebuildMergeRop(src)
+#define MROP_PREBUILT_DECLARE()        DeclarePrebuiltMergeRop()
+#define MROP_PREBUILT_SOLID(src,dst)   DoPrebuiltMergeRop(dst)
+#define MROP_PREBUILT_SOLID24(src,dst,index)   DoPrebuiltMergeRop24(dst,index)
+#define MROP_PREBUILT_MASK(src,dst,mask)    DoMaskPrebuiltMergeRop(dst,mask)
+#define MROP_PREBUILT_MASK24(src,dst,mask,index)    DoMaskPrebuiltMergeRop24(dst,mask,index)
+#endif
+
+#if (MROP) == 0
+#define MROP_DECLARE() DeclareMergeRop()
+#define MROP_DECLARE_REG()     register DeclareMergeRop()
+#define MROP_INITIALIZE(alu,pm)        InitializeMergeRop(alu,pm)
+#define MROP_SOLID(src,dst)    DoMergeRop(src,dst)
+#define MROP_SOLID24(src,dst,index)    DoMergeRop24(src,dst,index)
+#define MROP_MASK(src,dst,mask)        DoMaskMergeRop(src, dst, mask)
+#define MROP_MASK24(src,dst,mask,index)        DoMaskMergeRop24(src, dst, mask,index)
+#define MROP_NAME(prefix)      MROP_NAME_CAT(prefix,General)
+#define MROP_PREBUILD(src)     PrebuildMergeRop(src)
+#define MROP_PREBUILT_DECLARE()        DeclarePrebuiltMergeRop()
+#define MROP_PREBUILT_SOLID(src,dst)   DoPrebuiltMergeRop(dst)
+#define MROP_PREBUILT_SOLID24(src,dst,index)   DoPrebuiltMergeRop24(dst,index)
+#define MROP_PREBUILT_MASK(src,dst,mask)    DoMaskPrebuiltMergeRop(dst,mask)
+#define MROP_PREBUILT_MASK24(src,dst,mask,index) \
+       DoMaskPrebuiltMergeRop24(dst,mask,index)
+#endif
+
+#ifndef MROP_PREBUILD
+#define MROP_PREBUILD(src)
+#define MROP_PREBUILT_DECLARE()
+#define MROP_PREBUILT_SOLID(src,dst)   MROP_SOLID(src,dst)
+#define MROP_PREBUILT_SOLID24(src,dst,index)   MROP_SOLID24(src,dst,index)
+#define MROP_PREBUILT_MASK(src,dst,mask)    MROP_MASK(src,dst,mask)
+#define MROP_PREBUILT_MASK24(src,dst,mask,index) MROP_MASK24(src,dst,mask,index)
+#endif
+
+#if (defined(__STDC__) && !defined(UNIXCPP)) || defined(ANSICPP)
+#define MROP_NAME_CAT(prefix,suffix)   prefix##suffix
+#else
+#define MROP_NAME_CAT(prefix,suffix)   prefix/**/suffix
+#endif
+
+#endif
diff --git a/Xserver/programs/Xserver/mfb/mfb.h b/Xserver/programs/Xserver/mfb/mfb.h
new file mode 100644 (file)
index 0000000..24ef7b8
--- /dev/null
@@ -0,0 +1,1277 @@
+/* Combined Purdue/PurduePlus patches, level 2.0, 1/17/89 */
+/***********************************************************
+
+Copyright (c) 1987  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+
+Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
+
+                        All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and its 
+documentation for any purpose and without fee is hereby granted, 
+provided that the above copyright notice appear in all copies and that
+both that copyright notice and this permission notice appear in 
+supporting documentation, and that the name of Digital not be
+used in advertising or publicity pertaining to distribution of the
+software without specific, written prior permission.  
+
+DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
+ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
+DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
+ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+SOFTWARE.
+
+******************************************************************/
+/* $XConsortium: mfb.h,v 5.31 94/04/17 20:28:15 dpw Exp $ */
+
+
+
+
+/* $XFree86: xc/programs/Xserver/mfb/mfb.h,v 1.2 1997/01/14 22:22:44 dawes Exp $ */
+/* Monochrome Frame Buffer definitions 
+   written by drewry, september 1986
+*/
+#include "pixmap.h"
+#include "region.h"
+#include "gc.h"
+#include "colormap.h"
+#include "miscstruct.h"
+#include "mibstore.h"
+
+extern int InverseAlu[];
+
+/* warning: PixelType definition duplicated in maskbits.h */
+#ifndef PixelType
+#define PixelType unsigned long
+#endif /* PixelType */
+
+/* mfbbitblt.c */
+
+extern void mfbDoBitblt(
+#if NeedFunctionPrototypes
+    DrawablePtr /*pSrc*/,
+    DrawablePtr /*pDst*/,
+    int /*alu*/,
+    RegionPtr /*prgnDst*/,
+    DDXPointPtr /*pptSrc*/
+#endif
+);
+
+extern RegionPtr mfbCopyArea(
+#if NeedFunctionPrototypes
+    DrawablePtr /*pSrcDrawable*/,
+    DrawablePtr /*pDstDrawable*/,
+    GCPtr/*pGC*/,
+    int /*srcx*/,
+    int /*srcy*/,
+    int /*width*/,
+    int /*height*/,
+    int /*dstx*/,
+    int /*dsty*/
+#endif
+);
+
+extern Bool mfbRegisterCopyPlaneProc(
+#if NeedFunctionPrototypes
+    ScreenPtr /*pScreen*/,
+    RegionPtr (* /*proc*/)(
+#if NeedNestedPrototypes
+       DrawablePtr         /* pSrcDrawable */,
+       DrawablePtr         /* pDstDrawable */,
+       GCPtr               /* pGC */,
+       int                 /* srcx */,
+       int                 /* srcy */,
+       int                 /* width */,
+       int                 /* height */,
+       int                 /* dstx */,
+       int                 /* dsty */,
+       unsigned long       /* bitPlane */
+#endif
+       )
+#endif
+);
+
+extern RegionPtr mfbCopyPlane(
+#if NeedFunctionPrototypes
+    DrawablePtr /*pSrcDrawable*/,
+    DrawablePtr /*pDstDrawable*/,
+    GCPtr/*pGC*/,
+    int /*srcx*/,
+    int /*srcy*/,
+    int /*width*/,
+    int /*height*/,
+    int /*dstx*/,
+    int /*dsty*/,
+    unsigned long /*plane*/
+#endif
+);
+/* mfbbltC.c */
+
+extern void mfbDoBitbltCopy(
+#if NeedFunctionPrototypes
+    DrawablePtr /*pSrc*/,
+    DrawablePtr /*pDst*/,
+    int /*alu*/,
+    RegionPtr /*prgnDst*/,
+    DDXPointPtr /*pptSrc*/
+#endif
+);
+/* mfbbltCI.c */
+
+extern void mfbDoBitbltCopyInverted(
+#if NeedFunctionPrototypes
+    DrawablePtr /*pSrc*/,
+    DrawablePtr /*pDst*/,
+    int /*alu*/,
+    RegionPtr /*prgnDst*/,
+    DDXPointPtr /*pptSrc*/
+#endif
+);
+/* mfbbltG.c */
+
+extern void mfbDoBitbltGeneral(
+#if NeedFunctionPrototypes
+    DrawablePtr /*pSrc*/,
+    DrawablePtr /*pDst*/,
+    int /*alu*/,
+    RegionPtr /*prgnDst*/,
+    DDXPointPtr /*pptSrc*/
+#endif
+);
+/* mfbbltO.c */
+
+extern void mfbDoBitbltOr(
+#if NeedFunctionPrototypes
+    DrawablePtr /*pSrc*/,
+    DrawablePtr /*pDst*/,
+    int /*alu*/,
+    RegionPtr /*prgnDst*/,
+    DDXPointPtr /*pptSrc*/
+#endif
+);
+/* mfbbltX.c */
+
+extern void mfbDoBitbltXor(
+#if NeedFunctionPrototypes
+    DrawablePtr /*pSrc*/,
+    DrawablePtr /*pDst*/,
+    int /*alu*/,
+    RegionPtr /*prgnDst*/,
+    DDXPointPtr /*pptSrc*/
+#endif
+);
+/* mfbbres.c */
+
+extern void mfbBresS(
+#if NeedFunctionPrototypes
+    int /*rop*/,
+    PixelType * /*addrl*/,
+    int /*nlwidth*/,
+    int /*signdx*/,
+    int /*signdy*/,
+    int /*axis*/,
+    int /*x1*/,
+    int /*y1*/,
+    int /*e*/,
+    int /*e1*/,
+    int /*e2*/,
+    int /*len*/
+#endif
+);
+/* mfbbresd.c */
+
+extern void mfbBresD(
+#if NeedFunctionPrototypes
+    int /*fgrop*/,
+    int /*bgrop*/,
+    int * /*pdashIndex*/,
+    unsigned char * /*pDash*/,
+    int /*numInDashList*/,
+    int * /*pdashOffset*/,
+    int /*isDoubleDash*/,
+    PixelType * /*addrl*/,
+    int /*nlwidth*/,
+    int /*signdx*/,
+    int /*signdy*/,
+    int /*axis*/,
+    int /*x1*/,
+    int /*y1*/,
+    int /*e*/,
+    int /*e1*/,
+    int /*e2*/,
+    int /*len*/
+#endif
+);
+/* mfbbstore.c */
+
+extern void mfbSaveAreas(
+#if NeedFunctionPrototypes
+    PixmapPtr /*pPixmap*/,
+    RegionPtr /*prgnSave*/,
+    int /*xorg*/,
+    int /*yorg*/,
+    WindowPtr /*pWin*/
+#endif
+);
+
+extern void mfbRestoreAreas(
+#if NeedFunctionPrototypes
+    PixmapPtr /*pPixmap*/,
+    RegionPtr /*prgnRestore*/,
+    int /*xorg*/,
+    int /*yorg*/,
+    WindowPtr /*pWin*/
+#endif
+);
+/* mfbclip.c */
+
+extern RegionPtr mfbPixmapToRegion(
+#if NeedFunctionPrototypes
+    PixmapPtr /*pPix*/
+#endif
+);
+/* mfbcmap.c */
+
+extern int mfbListInstalledColormaps(
+#if NeedFunctionPrototypes
+    ScreenPtr /*pScreen*/,
+    Colormap * /*pmaps*/
+#endif
+);
+
+extern void mfbInstallColormap(
+#if NeedFunctionPrototypes
+    ColormapPtr /*pmap*/
+#endif
+);
+
+extern void mfbUninstallColormap(
+#if NeedFunctionPrototypes
+    ColormapPtr /*pmap*/
+#endif
+);
+
+extern void mfbResolveColor(
+#if NeedFunctionPrototypes
+    unsigned short * /*pred*/,
+    unsigned short * /*pgreen*/,
+    unsigned short * /*pblue*/,
+    VisualPtr /*pVisual*/
+#endif
+);
+
+extern Bool mfbCreateColormap(
+#if NeedFunctionPrototypes
+    ColormapPtr /*pMap*/
+#endif
+);
+
+extern void mfbDestroyColormap(
+#if NeedFunctionPrototypes
+    ColormapPtr /*pMap*/
+#endif
+);
+
+extern Bool mfbCreateDefColormap(
+#if NeedFunctionPrototypes
+    ScreenPtr /*pScreen*/
+#endif
+);
+/* mfbfillarc.c */
+
+extern void mfbPolyFillArcSolid(
+#if NeedFunctionPrototypes
+    DrawablePtr /*pDraw*/,
+    GCPtr /*pGC*/,
+    int /*narcs*/,
+    xArc * /*parcs*/
+#endif
+);
+/* mfbfillrct.c */
+
+extern void mfbPolyFillRect(
+#if NeedFunctionPrototypes
+    DrawablePtr /*pDrawable*/,
+    GCPtr /*pGC*/,
+    int /*nrectFill*/,
+    xRectangle * /*prectInit*/
+#endif
+);
+/* mfbfillsp.c */
+
+extern void mfbBlackSolidFS(
+#if NeedFunctionPrototypes
+    DrawablePtr /*pDrawable*/,
+    GCPtr /*pGC*/,
+    int /*nInit*/,
+    DDXPointPtr /*pptInit*/,
+    int * /*pwidthInit*/,
+    int /*fSorted*/
+#endif
+);
+
+extern void mfbWhiteSolidFS(
+#if NeedFunctionPrototypes
+    DrawablePtr /*pDrawable*/,
+    GCPtr /*pGC*/,
+    int /*nInit*/,
+    DDXPointPtr /*pptInit*/,
+    int * /*pwidthInit*/,
+    int /*fSorted*/
+#endif
+);
+
+extern void mfbInvertSolidFS(
+#if NeedFunctionPrototypes
+    DrawablePtr /*pDrawable*/,
+    GCPtr /*pGC*/,
+    int /*nInit*/,
+    DDXPointPtr /*pptInit*/,
+    int * /*pwidthInit*/,
+    int /*fSorted*/
+#endif
+);
+
+extern void mfbWhiteStippleFS(
+#if NeedFunctionPrototypes
+    DrawablePtr /*pDrawable*/,
+    GCPtr/*pGC*/,
+    int /*nInit*/,
+    DDXPointPtr /*pptInit*/,
+    int * /*pwidthInit*/,
+    int /*fSorted*/
+#endif
+);
+
+extern void mfbBlackStippleFS(
+#if NeedFunctionPrototypes
+    DrawablePtr /*pDrawable*/,
+    GCPtr/*pGC*/,
+    int /*nInit*/,
+    DDXPointPtr /*pptInit*/,
+    int * /*pwidthInit*/,
+    int /*fSorted*/
+#endif
+);
+
+extern void mfbInvertStippleFS(
+#if NeedFunctionPrototypes
+    DrawablePtr /*pDrawable*/,
+    GCPtr/*pGC*/,
+    int /*nInit*/,
+    DDXPointPtr /*pptInit*/,
+    int * /*pwidthInit*/,
+    int /*fSorted*/
+#endif
+);
+
+extern void mfbTileFS(
+#if NeedFunctionPrototypes
+    DrawablePtr /*pDrawable*/,
+    GCPtr/*pGC*/,
+    int /*nInit*/,
+    DDXPointPtr /*pptInit*/,
+    int * /*pwidthInit*/,
+    int /*fSorted*/
+#endif
+);
+
+extern void mfbUnnaturalTileFS(
+#if NeedFunctionPrototypes
+    DrawablePtr /*pDrawable*/,
+    GCPtr/*pGC*/,
+    int /*nInit*/,
+    DDXPointPtr /*pptInit*/,
+    int * /*pwidthInit*/,
+    int /*fSorted*/
+#endif
+);
+
+extern void mfbUnnaturalStippleFS(
+#if NeedFunctionPrototypes
+    DrawablePtr /*pDrawable*/,
+    GCPtr/*pGC*/,
+    int /*nInit*/,
+    DDXPointPtr /*pptInit*/,
+    int * /*pwidthInit*/,
+    int /*fSorted*/
+#endif
+);
+/* mfbfont.c */
+
+extern Bool mfbRealizeFont(
+#if NeedFunctionPrototypes
+    ScreenPtr /*pscr*/,
+    FontPtr /*pFont*/
+#endif
+);
+
+extern Bool mfbUnrealizeFont(
+#if NeedFunctionPrototypes
+    ScreenPtr /*pscr*/,
+    FontPtr /*pFont*/
+#endif
+);
+/* mfbgc.c */
+
+extern Bool mfbCreateGC(
+#if NeedFunctionPrototypes
+    GCPtr /*pGC*/
+#endif
+);
+
+extern void mfbValidateGC(
+#if NeedFunctionPrototypes
+    GCPtr /*pGC*/,
+    unsigned long /*changes*/,
+    DrawablePtr /*pDrawable*/
+#endif
+);
+
+extern int mfbReduceRop(
+#if NeedFunctionPrototypes
+    int /*alu*/,
+    Pixel /*src*/
+#endif
+);
+
+/* mfbgetsp.c */
+
+extern void mfbGetSpans(
+#if NeedFunctionPrototypes
+    DrawablePtr /*pDrawable*/,
+    int /*wMax*/,
+    DDXPointPtr /*ppt*/,
+    int * /*pwidth*/,
+    int /*nspans*/,
+    char * /*pdstStart*/
+#endif
+);
+/* mfbhrzvert.c */
+
+extern int mfbHorzS(
+#if NeedFunctionPrototypes
+    int /*rop*/,
+    PixelType * /*addrl*/,
+    int /*nlwidth*/,
+    int /*x1*/,
+    int /*y1*/,
+    int /*len*/
+#endif
+);
+
+extern int mfbVertS(
+#if NeedFunctionPrototypes
+    int /*rop*/,
+    PixelType * /*addrl*/,
+    int /*nlwidth*/,
+    int /*x1*/,
+    int /*y1*/,
+    int /*len*/
+#endif
+);
+/* mfbigbblak.c */
+
+extern void mfbImageGlyphBltBlack(
+#if NeedFunctionPrototypes
+    DrawablePtr /*pDrawable*/,
+    GCPtr/*pGC*/,
+    int /*x*/,
+    int /*y*/,
+    unsigned int /*nglyph*/,
+    CharInfoPtr * /*ppci*/,
+    pointer /*pglyphBase*/
+#endif
+);
+/* mfbigbwht.c */
+
+extern void mfbImageGlyphBltWhite(
+#if NeedFunctionPrototypes
+    DrawablePtr /*pDrawable*/,
+    GCPtr/*pGC*/,
+    int /*x*/,
+    int /*y*/,
+    unsigned int /*nglyph*/,
+    CharInfoPtr * /*ppci*/,
+    pointer /*pglyphBase*/
+#endif
+);
+/* mfbimage.c */
+
+extern void mfbPutImage(
+#if NeedFunctionPrototypes
+    DrawablePtr /*dst*/,
+    GCPtr /*pGC*/,
+    int /*depth*/,
+    int /*x*/,
+    int /*y*/,
+    int /*w*/,
+    int /*h*/,
+    int /*leftPad*/,
+    int /*format*/,
+    char * /*pImage*/
+#endif
+);
+
+extern void mfbGetImage(
+#if NeedFunctionPrototypes
+    DrawablePtr /*pDrawable*/,
+    int /*sx*/,
+    int /*sy*/,
+    int /*w*/,
+    int /*h*/,
+    unsigned int /*format*/,
+    unsigned long /*planeMask*/,
+    char * /*pdstLine*/
+#endif
+);
+/* mfbline.c */
+
+extern void mfbLineSS(
+#if NeedFunctionPrototypes
+    DrawablePtr /*pDrawable*/,
+    GCPtr /*pGC*/,
+    int /*mode*/,
+    int /*npt*/,
+    DDXPointPtr /*pptInit*/
+#endif
+);
+
+extern void mfbLineSD(
+#if NeedFunctionPrototypes
+    DrawablePtr /*pDrawable*/,
+    GCPtr /*pGC*/,
+    int /*mode*/,
+    int /*npt*/,
+    DDXPointPtr /*pptInit*/
+#endif
+);
+
+/* mfbmisc.c */
+
+extern void mfbQueryBestSize(
+#if NeedFunctionPrototypes
+    int /*class*/,
+    unsigned short * /*pwidth*/,
+    unsigned short * /*pheight*/,
+    ScreenPtr /*pScreen*/
+#endif
+);
+/* mfbpablack.c */
+
+extern void mfbSolidBlackArea(
+#if NeedFunctionPrototypes
+    DrawablePtr /*pDraw*/,
+    int /*nbox*/,
+    BoxPtr /*pbox*/,
+    int /*alu*/,
+    PixmapPtr /*nop*/
+#endif
+);
+
+extern void mfbStippleBlackArea(
+#if NeedFunctionPrototypes
+    DrawablePtr /*pDraw*/,
+    int /*nbox*/,
+    BoxPtr /*pbox*/,
+    int /*alu*/,
+    PixmapPtr /*pstipple*/
+#endif
+);
+/* mfbpainv.c */
+
+extern void mfbSolidInvertArea(
+#if NeedFunctionPrototypes
+    DrawablePtr /*pDraw*/,
+    int /*nbox*/,
+    BoxPtr /*pbox*/,
+    int /*alu*/,
+    PixmapPtr /*nop*/
+#endif
+);
+
+extern void mfbStippleInvertArea(
+#if NeedFunctionPrototypes
+    DrawablePtr /*pDraw*/,
+    int /*nbox*/,
+    BoxPtr /*pbox*/,
+    int /*alu*/,
+    PixmapPtr /*pstipple*/
+#endif
+);
+/* mfbpawhite.c */
+
+extern void mfbSolidWhiteArea(
+#if NeedFunctionPrototypes
+    DrawablePtr /*pDraw*/,
+    int /*nbox*/,
+    BoxPtr /*pbox*/,
+    int /*alu*/,
+    PixmapPtr /*nop*/
+#endif
+);
+
+extern void mfbStippleWhiteArea(
+#if NeedFunctionPrototypes
+    DrawablePtr /*pDraw*/,
+    int /*nbox*/,
+    BoxPtr /*pbox*/,
+    int /*alu*/,
+    PixmapPtr /*pstipple*/
+#endif
+);
+/* mfbpgbblak.c */
+
+extern void mfbPolyGlyphBltBlack(
+#if NeedFunctionPrototypes
+    DrawablePtr /*pDrawable*/,
+    GCPtr /*pGC*/,
+    int /*x*/,
+    int /*y*/,
+    unsigned int /*nglyph*/,
+    CharInfoPtr * /*ppci*/,
+    pointer /*pglyphBase*/
+#endif
+);
+/* mfbpgbinv.c */
+
+extern void mfbPolyGlyphBltInvert(
+#if NeedFunctionPrototypes
+    DrawablePtr /*pDrawable*/,
+    GCPtr /*pGC*/,
+    int /*x*/,
+    int /*y*/,
+    unsigned int /*nglyph*/,
+    CharInfoPtr * /*ppci*/,
+    pointer /*pglyphBase*/
+#endif
+);
+/* mfbpgbwht.c */
+
+extern void mfbPolyGlyphBltWhite(
+#if NeedFunctionPrototypes
+    DrawablePtr /*pDrawable*/,
+    GCPtr /*pGC*/,
+    int /*x*/,
+    int /*y*/,
+    unsigned int /*nglyph*/,
+    CharInfoPtr * /*ppci*/,
+    pointer /*pglyphBase*/
+#endif
+);
+/* mfbpixmap.c */
+
+extern PixmapPtr mfbCreatePixmap(
+#if NeedFunctionPrototypes
+    ScreenPtr /*pScreen*/,
+    int /*width*/,
+    int /*height*/,
+    int /*depth*/
+#endif
+);
+
+extern Bool mfbDestroyPixmap(
+#if NeedFunctionPrototypes
+    PixmapPtr /*pPixmap*/
+#endif
+);
+
+extern PixmapPtr mfbCopyPixmap(
+#if NeedFunctionPrototypes
+    PixmapPtr /*pSrc*/
+#endif
+);
+
+extern void mfbPadPixmap(
+#if NeedFunctionPrototypes
+    PixmapPtr /*pPixmap*/
+#endif
+);
+
+extern void mfbXRotatePixmap(
+#if NeedFunctionPrototypes
+    PixmapPtr /*pPix*/,
+    int /*rw*/
+#endif
+);
+
+extern void mfbYRotatePixmap(
+#if NeedFunctionPrototypes
+    PixmapPtr /*pPix*/,
+    int /*rh*/
+#endif
+);
+
+extern void mfbCopyRotatePixmap(
+#if NeedFunctionPrototypes
+    PixmapPtr /*psrcPix*/,
+    PixmapPtr * /*ppdstPix*/,
+    int /*xrot*/,
+    int /*yrot*/
+#endif
+);
+/* mfbplyblack.c */
+
+extern void mfbFillPolyBlack(
+#if NeedFunctionPrototypes
+    DrawablePtr /*pDrawable*/,
+    GCPtr /*pGC*/,
+    int /*shape*/,
+    int /*mode*/,
+    int /*count*/,
+    DDXPointPtr /*ptsIn*/
+#endif
+);
+/* mfbplyinv.c */
+
+extern void mfbFillPolyInvert(
+#if NeedFunctionPrototypes
+    DrawablePtr /*pDrawable*/,
+    GCPtr /*pGC*/,
+    int /*shape*/,
+    int /*mode*/,
+    int /*count*/,
+    DDXPointPtr /*ptsIn*/
+#endif
+);
+/* mfbplywhite.c */
+
+extern void mfbFillPolyWhite(
+#if NeedFunctionPrototypes
+    DrawablePtr /*pDrawable*/,
+    GCPtr /*pGC*/,
+    int /*shape*/,
+    int /*mode*/,
+    int /*count*/,
+    DDXPointPtr /*ptsIn*/
+#endif
+);
+/* mfbpntwin.c */
+
+extern void mfbPaintWindow(
+#if NeedFunctionPrototypes
+    WindowPtr /*pWin*/,
+    RegionPtr /*pRegion*/,
+    int /*what*/
+#endif
+);
+/* mfbpolypnt.c */
+
+extern void mfbPolyPoint(
+#if NeedFunctionPrototypes
+    DrawablePtr /*pDrawable*/,
+    GCPtr /*pGC*/,
+    int /*mode*/,
+    int /*npt*/,
+    xPoint * /*pptInit*/
+#endif
+);
+/* mfbpushpxl.c */
+
+extern void mfbSolidPP(
+#if NeedFunctionPrototypes
+    GCPtr /*pGC*/,
+    PixmapPtr /*pBitMap*/,
+    DrawablePtr /*pDrawable*/,
+    int /*dx*/,
+    int /*dy*/,
+    int /*xOrg*/,
+    int /*yOrg*/
+#endif
+);
+
+extern void mfbPushPixels(
+#if NeedFunctionPrototypes
+    GCPtr /*pGC*/,
+    PixmapPtr /*pBitMap*/,
+    DrawablePtr /*pDrawable*/,
+    int /*dx*/,
+    int /*dy*/,
+    int /*xOrg*/,
+    int /*yOrg*/
+#endif
+);
+/* mfbscrclse.c */
+
+extern Bool mfbCloseScreen(
+#if NeedFunctionPrototypes
+    int /*index*/,
+    ScreenPtr /*pScreen*/
+#endif
+);
+/* mfbscrinit.c */
+
+extern Bool mfbAllocatePrivates(
+#if NeedFunctionPrototypes
+    ScreenPtr /*pScreen*/,
+    int * /*pWinIndex*/,
+    int * /*pGCIndex*/
+#endif
+);
+
+extern Bool mfbScreenInit(
+#if NeedFunctionPrototypes
+    ScreenPtr /*pScreen*/,
+    pointer /*pbits*/,
+    int /*xsize*/,
+    int /*ysize*/,
+    int /*dpix*/,
+    int /*dpiy*/,
+    int /*width*/
+#endif
+);
+/* mfbseg.c */
+
+extern void mfbSegmentSS(
+#if NeedFunctionPrototypes
+    DrawablePtr /*pDrawable*/,
+    GCPtr /*pGC*/,
+    int /*nseg*/,
+    xSegment * /*pSeg*/
+#endif
+);
+
+extern void mfbSegmentSD(
+#if NeedFunctionPrototypes
+    DrawablePtr /*pDrawable*/,
+    GCPtr /*pGC*/,
+    int /*nseg*/,
+    xSegment * /*pSeg*/
+#endif
+);
+/* mfbsetsp.c */
+
+extern int mfbSetScanline(
+#if NeedFunctionPrototypes
+    int /*y*/,
+    int /*xOrigin*/,
+    int /*xStart*/,
+    int /*xEnd*/,
+    PixelType * /*psrc*/,
+    int /*alu*/,
+    PixelType * /*pdstBase*/,
+    int /*widthDst*/
+#endif
+);
+
+extern void mfbSetSpans(
+#if NeedFunctionPrototypes
+    DrawablePtr /*pDrawable*/,
+    GCPtr /*pGC*/,
+    char * /*psrc*/,
+    DDXPointPtr /*ppt*/,
+    int * /*pwidth*/,
+    int /*nspans*/,
+    int /*fSorted*/
+#endif
+);
+/* mfbteblack.c */
+
+extern void mfbTEGlyphBltBlack(
+#if NeedFunctionPrototypes
+    DrawablePtr /*pDrawable*/,
+    GCPtr/*pGC*/,
+    int /*x*/,
+    int /*y*/,
+    unsigned int /*nglyph*/,
+    CharInfoPtr * /*ppci*/,
+    pointer /*pglyphBase*/
+#endif
+);
+/* mfbtewhite.c */
+
+extern void mfbTEGlyphBltWhite(
+#if NeedFunctionPrototypes
+    DrawablePtr /*pDrawable*/,
+    GCPtr/*pGC*/,
+    int /*x*/,
+    int /*y*/,
+    unsigned int /*nglyph*/,
+    CharInfoPtr * /*ppci*/,
+    pointer /*pglyphBase*/
+#endif
+);
+/* mfbtileC.c */
+
+extern void mfbTileAreaPPWCopy(
+#if NeedFunctionPrototypes
+    DrawablePtr /*pDraw*/,
+    int /*nbox*/,
+    BoxPtr /*pbox*/,
+    int /*alu*/,
+    PixmapPtr /*ptile*/
+#endif
+);
+/* mfbtileG.c */
+
+extern void mfbTileAreaPPWGeneral(
+#if NeedFunctionPrototypes
+    DrawablePtr /*pDraw*/,
+    int /*nbox*/,
+    BoxPtr /*pbox*/,
+    int /*alu*/,
+    PixmapPtr /*ptile*/
+#endif
+);
+
+extern void mfbTileAreaPPW(
+#if NeedFunctionPrototypes
+    DrawablePtr /*pDraw*/,
+    int /*nbox*/,
+    BoxPtr /*pbox*/,
+    int /*alu*/,
+    PixmapPtr /*ptile*/
+#endif
+);
+/* mfbwindow.c */
+
+extern Bool mfbCreateWindow(
+#if NeedFunctionPrototypes
+    WindowPtr /*pWin*/
+#endif
+);
+
+extern Bool mfbDestroyWindow(
+#if NeedFunctionPrototypes
+    WindowPtr /*pWin*/
+#endif
+);
+
+extern Bool mfbMapWindow(
+#if NeedFunctionPrototypes
+    WindowPtr /*pWindow*/
+#endif
+);
+
+extern Bool mfbPositionWindow(
+#if NeedFunctionPrototypes
+    WindowPtr /*pWin*/,
+    int /*x*/,
+    int /*y*/
+#endif
+);
+
+extern Bool mfbUnmapWindow(
+#if NeedFunctionPrototypes
+    WindowPtr /*pWindow*/
+#endif
+);
+
+extern void mfbCopyWindow(
+#if NeedFunctionPrototypes
+    WindowPtr /*pWin*/,
+    DDXPointRec /*ptOldOrg*/,
+    RegionPtr /*prgnSrc*/
+#endif
+);
+
+extern Bool mfbChangeWindowAttributes(
+#if NeedFunctionPrototypes
+    WindowPtr /*pWin*/,
+    unsigned long /*mask*/
+#endif
+);
+/* mfbzerarc.c */
+
+extern void mfbZeroPolyArcSS(
+#if NeedFunctionPrototypes
+    DrawablePtr /*pDraw*/,
+    GCPtr /*pGC*/,
+    int /*narcs*/,
+    xArc * /*parcs*/
+#endif
+);
+
+/*
+   private filed of pixmap
+   pixmap.devPrivate = (PixelType *)pointer_to_bits
+   pixmap.devKind = width_of_pixmap_in_bytes
+
+   private field of screen
+   a pixmap, for which we allocate storage.  devPrivate is a pointer to
+the bits in the hardware framebuffer.  note that devKind can be poked to
+make the code work for framebuffers that are wider than their
+displayable screen (e.g. the early vsII, which displayed 960 pixels
+across, but was 1024 in the hardware.)
+
+   private field of GC 
+       Freeing pCompositeClip is done based on the value of
+freeCompClip; if freeCompClip is not carefully maintained, we will end
+up losing storage or freeing something that isn't ours.
+*/
+
+typedef struct {
+    unsigned char      rop;            /* reduction of rasterop to 1 of 3 */
+    unsigned char      ropOpStip;      /* rop for opaque stipple */
+    unsigned char      ropFillArea;    /*  == alu, rop, or ropOpStip */
+    unsigned   fExpose:1;              /* callexposure handling ? */
+    unsigned   freeCompClip:1;
+    PixmapPtr  pRotatedPixmap;         /* tile/stipple rotated to align */
+    RegionPtr  pCompositeClip;         /* free this based on freeCompClip
+                                          flag rather than NULLness */
+    void       (* FillArea)(           /* fills regions; look at the code */
+#if NeedNestedPrototypes
+               DrawablePtr /*pDraw*/,
+               int /*nbox*/,
+               BoxPtr /*pbox*/,
+               int /*alu*/,
+               PixmapPtr /*nop*/
+#endif
+               );
+    } mfbPrivGC;
+typedef mfbPrivGC      *mfbPrivGCPtr;
+
+extern int  mfbGCPrivateIndex;         /* index into GC private array */
+extern int  mfbWindowPrivateIndex;     /* index into Window private array */
+#ifdef PIXMAP_PER_WINDOW
+extern int  frameWindowPrivateIndex;   /* index into Window private array */
+#endif
+
+/* private field of window */
+typedef struct {
+    unsigned char fastBorder;  /* non-zero if border tile is 32 bits wide */
+    unsigned char fastBackground;
+    unsigned short unused; /* pad for alignment with Sun compiler */
+    DDXPointRec        oldRotate;
+    PixmapPtr  pRotatedBackground;
+    PixmapPtr  pRotatedBorder;
+    } mfbPrivWin;
+
+/* Common macros for extracting drawing information */
+
+#define mfbGetTypedWidth(pDrawable,type) (\
+    (((pDrawable)->type == DRAWABLE_WINDOW) ? \
+     (int) (((PixmapPtr)((pDrawable)->pScreen->devPrivate))->devKind) : \
+     (int)(((PixmapPtr)pDrawable)->devKind)) / sizeof (type))
+
+#define mfbGetByteWidth(pDrawable) mfbGetTypedWidth(pDrawable, unsigned char)
+
+#define mfbGetPixelWidth(pDrawable) mfbGetTypedWidth(pDrawable, PixelType)
+    
+#define mfbGetTypedWidthAndPointer(pDrawable, width, pointer, wtype, ptype) {\
+    PixmapPtr   _pPix; \
+    if ((pDrawable)->type == DRAWABLE_WINDOW) \
+       _pPix = (PixmapPtr) (pDrawable)->pScreen->devPrivate; \
+    else \
+       _pPix = (PixmapPtr) (pDrawable); \
+    (pointer) = (ptype *) _pPix->devPrivate.ptr; \
+    (width) = ((int) _pPix->devKind) / sizeof (wtype); \
+}
+
+#define mfbGetByteWidthAndPointer(pDrawable, width, pointer) \
+    mfbGetTypedWidthAndPointer(pDrawable, width, pointer, unsigned char, unsigned char)
+
+#define mfbGetPixelWidthAndPointer(pDrawable, width, pointer) \
+    mfbGetTypedWidthAndPointer(pDrawable, width, pointer, PixelType, PixelType)
+
+#define mfbGetWindowTypedWidthAndPointer(pWin, width, pointer, wtype, ptype) {\
+    PixmapPtr  _pPix = (PixmapPtr) (pWin)->drawable.pScreen->devPrivate; \
+    (pointer) = (ptype *) _pPix->devPrivate.ptr; \
+    (width) = ((int) _pPix->devKind) / sizeof (wtype); \
+}
+
+#define mfbGetWindowPixelWidthAndPointer(pWin, width, pointer) \
+    mfbGetWindowTypedWidthAndPointer(pWin, width, pointer, PixelType, PixelType)
+
+#define mfbGetWindowByteWidthAndPointer(pWin, width, pointer) \
+    mfbGetWindowTypedWidthAndPointer(pWin, width, pointer, char, char)
+
+/*  mfb uses the following macros to calculate addresses in drawables.
+ *  To support banked framebuffers, the macros come in four flavors.
+ *  All four collapse into the same definition on unbanked devices.
+ *  
+ *  mfbScanlineFoo - calculate address and do bank switching
+ *  mfbScanlineFooNoBankSwitch - calculate address, don't bank switch
+ *  mfbScanlineFooSrc - calculate address, switch source bank
+ *  mfbScanlineFooDst - calculate address, switch destination bank
+ */
+
+/* The NoBankSwitch versions are the same for banked and unbanked cases */
+
+#define mfbScanlineIncNoBankSwitch(_ptr, _off) _ptr += (_off)
+#define mfbScanlineOffsetNoBankSwitch(_ptr, _off) ((_ptr) + (_off))
+#define mfbScanlineDeltaNoBankSwitch(_ptr, _y, _w) \
+    mfbScanlineOffsetNoBankSwitch(_ptr, (_y) * (_w))
+#define mfbScanlineNoBankSwitch(_ptr, _x, _y, _w) \
+    mfbScanlineOffsetNoBankSwitch(_ptr, (_y) * (_w) + ((_x) >> MFB_PWSH))
+
+#ifdef MFB_LINE_BANK
+
+#include "mfblinebank.h" /* get macro definitions from this file */
+
+#else /* !MFB_LINE_BANK - unbanked case */
+
+#define mfbScanlineInc(_ptr, _off)       mfbScanlineIncNoBankSwitch(_ptr, _off)
+#define mfbScanlineIncSrc(_ptr, _off)     mfbScanlineInc(_ptr, _off)
+#define mfbScanlineIncDst(_ptr, _off)     mfbScanlineInc(_ptr, _off)
+
+#define mfbScanlineOffset(_ptr, _off) mfbScanlineOffsetNoBankSwitch(_ptr, _off)
+#define mfbScanlineOffsetSrc(_ptr, _off)  mfbScanlineOffset(_ptr, _off)
+#define mfbScanlineOffsetDst(_ptr, _off)  mfbScanlineOffset(_ptr, _off)
+
+#define mfbScanlineSrc(_ptr, _x, _y, _w)  mfbScanline(_ptr, _x, _y, _w)
+#define mfbScanlineDst(_ptr, _x, _y, _w)  mfbScanline(_ptr, _x, _y, _w)
+
+#define mfbScanlineDeltaSrc(_ptr, _y, _w) mfbScanlineDelta(_ptr, _y, _w)
+#define mfbScanlineDeltaDst(_ptr, _y, _w) mfbScanlineDelta(_ptr, _y, _w)
+
+#endif /* MFB_LINE_BANK */
+
+#define mfbScanlineDelta(_ptr, _y, _w) \
+    mfbScanlineOffset(_ptr, (_y) * (_w))
+
+#define mfbScanline(_ptr, _x, _y, _w) \
+    mfbScanlineOffset(_ptr, (_y) * (_w) + ((_x) >> MFB_PWSH))
+
+
+/* precomputed information about each glyph for GlyphBlt code.
+   this saves recalculating the per glyph information for each box.
+*/
+typedef struct _pos{
+    int xpos;          /* xposition of glyph's origin */
+    int xchar;         /* x position mod 32 */
+    int leftEdge;
+    int rightEdge;
+    int topEdge;
+    int bottomEdge;
+    PixelType *pdstBase;       /* longword with character origin */
+    int widthGlyph;    /* width in bytes of this glyph */
+} TEXTPOS;
+
+/* reduced raster ops for mfb */
+#define RROP_BLACK     GXclear
+#define RROP_WHITE     GXset
+#define RROP_NOP       GXnoop
+#define RROP_INVERT    GXinvert
+
+/* macros for mfbbitblt.c, mfbfillsp.c
+   these let the code do one switch on the rop per call, rather
+than a switch on the rop per item (span or rectangle.)
+*/
+
+#define fnCLEAR(src, dst)      (0)
+#define fnAND(src, dst)        (src & dst)
+#define fnANDREVERSE(src, dst) (src & ~dst)
+#define fnCOPY(src, dst)       (src)
+#define fnANDINVERTED(src, dst)        (~src & dst)
+#define fnNOOP(src, dst)       (dst)
+#define fnXOR(src, dst)                (src ^ dst)
+#define fnOR(src, dst)         (src | dst)
+#define fnNOR(src, dst)                (~(src | dst))
+#define fnEQUIV(src, dst)      (~src ^ dst)
+#define fnINVERT(src, dst)     (~dst)
+#define fnORREVERSE(src, dst)  (src | ~dst)
+#define fnCOPYINVERTED(src, dst)(~src)
+#define fnORINVERTED(src, dst) (~src | dst)
+#define fnNAND(src, dst)       (~(src & dst))
+#define fnSET(src, dst)                (~0)
+
+/*  Using a "switch" statement is much faster in most cases
+ *  since the compiler can do a look-up table or multi-way branch
+ *  instruction, depending on the architecture.  The result on
+ *  A Sun 3/50 is at least 2.5 times faster, assuming a uniform
+ *  distribution of RasterOp operation types.
+ *
+ *  However, doing some profiling on a running system reveals
+ *  GXcopy is the operation over 99.5% of the time and
+ *  GXxor is the next most frequent (about .4%), so we make special
+ *  checks for those first.
+ *
+ *  Note that this requires a change to the "calling sequence"
+ *  since we can't engineer a "switch" statement to have an lvalue.
+ */
+#define DoRop(result, alu, src, dst) \
+{ \
+    if (alu == GXcopy) \
+       result = fnCOPY (src, dst); \
+    else if (alu == GXxor) \
+        result = fnXOR (src, dst); \
+    else \
+       switch (alu) \
+       { \
+         case GXclear: \
+           result = fnCLEAR (src, dst); \
+           break; \
+         case GXand: \
+           result = fnAND (src, dst); \
+           break; \
+         case GXandReverse: \
+           result = fnANDREVERSE (src, dst); \
+           break; \
+         case GXandInverted: \
+           result = fnANDINVERTED (src, dst); \
+           break; \
+         case GXnoop: \
+           result = fnNOOP (src, dst); \
+           break; \
+         case GXor: \
+           result = fnOR (src, dst); \
+           break; \
+         case GXnor: \
+           result = fnNOR (src, dst); \
+           break; \
+         case GXequiv: \
+           result = fnEQUIV (src, dst); \
+           break; \
+         case GXinvert: \
+           result = fnINVERT (src, dst); \
+           break; \
+         case GXorReverse: \
+           result = fnORREVERSE (src, dst); \
+           break; \
+         case GXcopyInverted: \
+           result = fnCOPYINVERTED (src, dst); \
+           break; \
+         case GXorInverted: \
+           result = fnORINVERTED (src, dst); \
+           break; \
+         case GXnand: \
+           result = fnNAND (src, dst); \
+           break; \
+         case GXset: \
+           result = fnSET (src, dst); \
+           break; \
+       } \
+}
+
+
+/*  C expression fragments for various operations.  These get passed in
+ *  as -D's on the compile command line.  See mfb/Imakefile.  This
+ *  fixes XBUG 6319.
+ *
+ *  This seems like a good place to point out that mfb's use of the
+ *  words black and white is an unfortunate misnomer.  In mfb code, black
+ *  means zero, and white means one.
+ */
+#define MFB_OPEQ_WHITE  |=
+#define MFB_OPEQ_BLACK  &=~
+#define MFB_OPEQ_INVERT ^=
+#define MFB_EQWHOLEWORD_WHITE   =~0
+#define MFB_EQWHOLEWORD_BLACK   =0
+#define MFB_EQWHOLEWORD_INVERT  ^=~0
+#define MFB_OP_WHITE    /* nothing */
+#define MFB_OP_BLACK    ~
diff --git a/Xserver/programs/Xserver/mfb/mfbbitblt.c b/Xserver/programs/Xserver/mfb/mfbbitblt.c
new file mode 100644 (file)
index 0000000..91781a7
--- /dev/null
@@ -0,0 +1,478 @@
+/* Combined Purdue/PurduePlus patches, level 2.0, 1/17/89 */
+/***********************************************************
+
+Copyright (c) 1987  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+
+Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
+
+                        All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and its 
+documentation for any purpose and without fee is hereby granted, 
+provided that the above copyright notice appear in all copies and that
+both that copyright notice and this permission notice appear in 
+supporting documentation, and that the name of Digital not be
+used in advertising or publicity pertaining to distribution of the
+software without specific, written prior permission.  
+
+DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
+ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
+DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
+ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+SOFTWARE.
+
+******************************************************************/
+/* $XConsortium: mfbbitblt.c,v 5.25 94/04/17 20:28:16 dpw Exp $ */
+#include "X.h"
+#include "Xprotostr.h"
+
+#include "miscstruct.h"
+#include "regionstr.h"
+#include "gcstruct.h"
+#include "windowstr.h"
+#include "pixmapstr.h"
+#include "scrnintstr.h"
+
+#include "mi.h"
+
+#include "mfb.h"
+#include "maskbits.h"
+
+
+/* CopyArea and CopyPlane for a monchrome frame buffer
+
+
+    clip the source rectangle to the source's available bits.  (this
+avoids copying unnecessary pieces that will just get exposed anyway.)
+this becomes the new shape of the destination.
+    clip the destination region to the composite clip in the
+GC.  this requires translating the destination region to (dstx, dsty).
+    build a list of source points, one for each rectangle in the
+destination.  this is a simple translation.
+    go do the multiple rectangle copies
+    do graphics exposures
+*/
+/** Optimized for drawing pixmaps into windows, especially when drawing into
+ ** unobscured windows.  Calls to the general-purpose region code were
+ ** replaced with rectangle-to-rectangle clipping comparisions.  This is
+ ** possible, since the pixmap is a single rectangle.  In an unobscured
+ ** window, the destination clip is also a single rectangle, and region
+ ** code can be avoided entirely.  This is a big savings, since the region
+ ** code uses XAlloc() and makes many function calls.
+ **
+ ** In addition, if source is a pixmap, there is no need to call the
+ ** expensive miHandleExposures() routine.  Instead, we simply return NULL.
+ **
+ ** Previously, drawing a pixmap into an unobscured window executed at least
+ ** 8 XAlloc()'s, 30 function calls, and hundreds of lines of code.
+ **
+ ** Now, the same operation requires no XAlloc()'s, no region function calls,
+ ** and much less overhead.  Nice for drawing lots of small pixmaps.
+ */
+void
+mfbDoBitblt (pSrc, pDst, alu, prgnDst, pptSrc)
+    DrawablePtr            pSrc, pDst;
+    int                    alu;
+    RegionPtr      prgnDst;
+    DDXPointPtr            pptSrc;
+{
+    switch (alu)
+    {
+    case GXcopy:
+       mfbDoBitbltCopy (pSrc, pDst, alu, prgnDst, pptSrc);
+       break;
+    case GXxor:
+       mfbDoBitbltXor (pSrc, pDst, alu, prgnDst, pptSrc);
+       break;
+    case GXcopyInverted:
+       mfbDoBitbltCopyInverted (pSrc, pDst, alu, prgnDst, pptSrc);
+       break;
+    case GXor:
+       mfbDoBitbltOr (pSrc, pDst, alu, prgnDst, pptSrc);
+       break;
+    default:
+       mfbDoBitbltGeneral (pSrc, pDst, alu, prgnDst, pptSrc);
+       break;
+    }
+}
+
+RegionPtr
+mfbCopyArea(pSrcDrawable, pDstDrawable,
+           pGC, srcx, srcy, width, height, dstx, dsty)
+register DrawablePtr pSrcDrawable;
+register DrawablePtr pDstDrawable;
+register GC *pGC;
+int srcx, srcy;
+int width, height;
+int dstx, dsty;
+{
+    RegionPtr prgnSrcClip;     /* may be a new region, or just a copy */
+    Bool freeSrcClip = FALSE;
+
+    RegionPtr prgnExposed;
+    RegionRec rgnDst;
+    DDXPointPtr pptSrc;
+    register DDXPointPtr ppt;
+    register BoxPtr pbox;
+    int i;
+    register int dx;
+    register int dy;
+    xRectangle origSource;
+    DDXPointRec origDest;
+    int numRects;
+    BoxRec fastBox;
+    int fastClip = 0;          /* for fast clipping with pixmap source */
+    int fastExpose = 0;                /* for fast exposures with pixmap source */
+    void (*localDoBitBlt)();
+
+    origSource.x = srcx;
+    origSource.y = srcy;
+    origSource.width = width;
+    origSource.height = height;
+    origDest.x = dstx;
+    origDest.y = dsty;
+
+    if ((pSrcDrawable != pDstDrawable) &&
+       pSrcDrawable->pScreen->SourceValidate)
+    {
+       (*pSrcDrawable->pScreen->SourceValidate) (pSrcDrawable, srcx, srcy, width, height);
+    }
+
+    switch (pGC->alu) {
+    case GXcopy:
+       localDoBitBlt = mfbDoBitbltCopy;
+       break;
+    case GXcopyInverted:
+       localDoBitBlt = mfbDoBitbltCopyInverted;
+       break;
+    case GXxor:
+       localDoBitBlt = mfbDoBitbltXor;
+       break;
+    case GXor:
+       localDoBitBlt = mfbDoBitbltOr;
+       break;
+    default:
+       localDoBitBlt = mfbDoBitbltGeneral;
+       break;
+    }
+
+    srcx += pSrcDrawable->x;
+    srcy += pSrcDrawable->y;
+
+    /* clip the source */
+
+    if (pSrcDrawable->type == DRAWABLE_PIXMAP)
+    {
+       if ((pSrcDrawable == pDstDrawable) &&
+           (pGC->clientClipType == CT_NONE))
+       {
+           prgnSrcClip = ((mfbPrivGC *)(pGC->devPrivates[mfbGCPrivateIndex].ptr))->pCompositeClip;
+       }
+       else
+       {
+           fastClip = 1;
+       }
+    }
+    else
+    {
+       if (pGC->subWindowMode == IncludeInferiors)
+       {
+           if (!((WindowPtr) pSrcDrawable)->parent)
+           {
+               /*
+                * special case bitblt from root window in
+                * IncludeInferiors mode; just like from a pixmap
+                */
+               fastClip = 1;
+           }
+           else if ((pSrcDrawable == pDstDrawable) &&
+               (pGC->clientClipType == CT_NONE))
+           {
+               prgnSrcClip = ((mfbPrivGC *)(pGC->devPrivates[mfbGCPrivateIndex].ptr))->pCompositeClip;
+           }
+           else
+           {
+               prgnSrcClip = NotClippedByChildren((WindowPtr)pSrcDrawable);
+               freeSrcClip = TRUE;
+           }
+       }
+       else
+       {
+           prgnSrcClip = &((WindowPtr)pSrcDrawable)->clipList;
+       }
+    }
+
+    fastBox.x1 = srcx;
+    fastBox.y1 = srcy;
+    fastBox.x2 = srcx + width;
+    fastBox.y2 = srcy + height;
+
+    /* Don't create a source region if we are doing a fast clip */
+    if (fastClip)
+    {
+       fastExpose = 1;
+       /*
+        * clip the source; if regions extend beyond the source size,
+        * make sure exposure events get sent
+        */
+       if (fastBox.x1 < pSrcDrawable->x)
+       {
+           fastBox.x1 = pSrcDrawable->x;
+           fastExpose = 0;
+       }
+       if (fastBox.y1 < pSrcDrawable->y)
+       {
+           fastBox.y1 = pSrcDrawable->y;
+           fastExpose = 0;
+       }
+       if (fastBox.x2 > pSrcDrawable->x + (int) pSrcDrawable->width)
+       {
+           fastBox.x2 = pSrcDrawable->x + (int) pSrcDrawable->width;
+           fastExpose = 0;
+       }
+       if (fastBox.y2 > pSrcDrawable->y + (int) pSrcDrawable->height)
+       {
+           fastBox.y2 = pSrcDrawable->y + (int) pSrcDrawable->height;
+           fastExpose = 0;
+       }
+    }
+    else
+    {
+       REGION_INIT(pGC->pScreen, &rgnDst, &fastBox, 1);
+       REGION_INTERSECT(pGC->pScreen, &rgnDst, &rgnDst, prgnSrcClip);
+    }
+
+    dstx += pDstDrawable->x;
+    dsty += pDstDrawable->y;
+
+    if (pDstDrawable->type == DRAWABLE_WINDOW)
+    {
+       if (!((WindowPtr)pDstDrawable)->realized)
+       {
+           if (!fastClip)
+               REGION_UNINIT(pGC->pScreen, &rgnDst);
+           if (freeSrcClip)
+               REGION_DESTROY(pGC->pScreen, prgnSrcClip);
+           return NULL;
+       }
+    }
+
+    dx = srcx - dstx;
+    dy = srcy - dsty;
+
+    /* Translate and clip the dst to the destination composite clip */
+    if (fastClip)
+    {
+       RegionPtr cclip;
+
+        /* Translate the region directly */
+        fastBox.x1 -= dx;
+        fastBox.x2 -= dx;
+        fastBox.y1 -= dy;
+        fastBox.y2 -= dy;
+
+       /* If the destination composite clip is one rectangle we can
+          do the clip directly.  Otherwise we have to create a full
+          blown region and call intersect */
+       cclip = ((mfbPrivGC *)(pGC->devPrivates[mfbGCPrivateIndex].ptr))->pCompositeClip;
+        if (REGION_NUM_RECTS(cclip) == 1)
+        {
+           BoxPtr pBox = REGION_RECTS(cclip);
+
+           if (fastBox.x1 < pBox->x1) fastBox.x1 = pBox->x1;
+           if (fastBox.x2 > pBox->x2) fastBox.x2 = pBox->x2;
+           if (fastBox.y1 < pBox->y1) fastBox.y1 = pBox->y1;
+           if (fastBox.y2 > pBox->y2) fastBox.y2 = pBox->y2;
+
+           /* Check to see if the region is empty */
+           if (fastBox.x1 >= fastBox.x2 || fastBox.y1 >= fastBox.y2)
+           {
+               REGION_INIT(pGC->pScreen, &rgnDst, NullBox, 0);
+           }
+           else
+           {
+               REGION_INIT(pGC->pScreen, &rgnDst, &fastBox, 1);
+           }
+       }
+        else
+       {
+           /* We must turn off fastClip now, since we must create
+              a full blown region.  It is intersected with the
+              composite clip below. */
+           fastClip = 0;
+           REGION_INIT(pGC->pScreen, &rgnDst, &fastBox,1);
+       }
+    }
+    else
+    {
+        REGION_TRANSLATE(pGC->pScreen, &rgnDst, -dx, -dy);
+    }
+
+    if (!fastClip)
+    {
+       REGION_INTERSECT(pGC->pScreen, &rgnDst, &rgnDst,
+        ((mfbPrivGC *)(pGC->devPrivates[mfbGCPrivateIndex].ptr))->pCompositeClip);
+    }
+
+    /* Do bit blitting */
+    numRects = REGION_NUM_RECTS(&rgnDst);
+    if (numRects && width && height)
+    {
+       if(!(pptSrc = (DDXPointPtr)ALLOCATE_LOCAL(numRects *
+                                                 sizeof(DDXPointRec))))
+       {
+           REGION_UNINIT(pGC->pScreen, &rgnDst);
+           if (freeSrcClip)
+               REGION_DESTROY(pGC->pScreen, prgnSrcClip);
+           return NULL;
+       }
+       pbox = REGION_RECTS(&rgnDst);
+       ppt = pptSrc;
+       for (i = numRects; --i >= 0; pbox++, ppt++)
+       {
+           ppt->x = pbox->x1 + dx;
+           ppt->y = pbox->y1 + dy;
+       }
+    
+       if (pGC->planemask & 1)
+           (*localDoBitBlt) (pSrcDrawable, pDstDrawable, pGC->alu, &rgnDst, pptSrc);
+
+       DEALLOCATE_LOCAL(pptSrc);
+    }
+
+    prgnExposed = NULL;
+    if (((mfbPrivGC *)(pGC->devPrivates[mfbGCPrivateIndex].ptr))->fExpose) 
+    {
+        /* Pixmap sources generate a NoExposed (we return NULL to do this) */
+        if (!fastExpose)
+           prgnExposed =
+               miHandleExposures(pSrcDrawable, pDstDrawable, pGC,
+                                 origSource.x, origSource.y,
+                                 (int)origSource.width,
+                                 (int)origSource.height,
+                                 origDest.x, origDest.y, (unsigned long)0);
+    }
+    REGION_UNINIT(pGC->pScreen, &rgnDst);
+    if (freeSrcClip)
+       REGION_DESTROY(pGC->pScreen, prgnSrcClip);
+    return prgnExposed;
+}
+
+/*
+ * Devices which use mfb for 1-bit pixmap support
+ * must register a function for n-to-1 copy operations
+ */
+
+static unsigned long   copyPlaneGeneration;
+static int             copyPlaneScreenIndex = -1;
+
+Bool
+mfbRegisterCopyPlaneProc (pScreen, proc)
+    ScreenPtr  pScreen;
+    RegionPtr  (*proc)();
+{
+    if (copyPlaneGeneration != serverGeneration)
+    {
+       copyPlaneScreenIndex = AllocateScreenPrivateIndex();
+       if (copyPlaneScreenIndex < 0)
+           return FALSE;
+       copyPlaneGeneration = serverGeneration;
+    }
+    pScreen->devPrivates[copyPlaneScreenIndex].fptr = (pointer (*)()) proc;
+    return TRUE;
+}
+
+/*
+    if fg == 1 and bg ==0, we can do an ordinary CopyArea.
+    if fg == bg, we can do a CopyArea with alu = mfbReduceRop(alu, fg)
+    if fg == 0 and bg == 1, we use the same rasterop, with
+       source operand inverted.
+
+    CopyArea deals with all of the graphics exposure events.
+    This code depends on knowing that we can change the
+alu in the GC without having to call ValidateGC() before calling
+CopyArea().
+
+*/
+
+RegionPtr
+mfbCopyPlane(pSrcDrawable, pDstDrawable,
+           pGC, srcx, srcy, width, height, dstx, dsty, plane)
+DrawablePtr pSrcDrawable, pDstDrawable;
+register GC *pGC;
+int srcx, srcy;
+int width, height;
+int dstx, dsty;
+unsigned long plane;
+{
+    int alu;
+    RegionPtr  prgnExposed;
+    RegionPtr  (*copyPlane)();
+
+    if (pSrcDrawable->depth != 1)
+    {
+       if (copyPlaneScreenIndex >= 0 &&
+           (copyPlane = (RegionPtr (*)()) 
+               pSrcDrawable->pScreen->devPrivates[copyPlaneScreenIndex].fptr)
+           )
+       {
+           return (*copyPlane) (pSrcDrawable, pDstDrawable,
+                          pGC, srcx, srcy, width, height, dstx, dsty, plane);
+       }  
+       else
+       {
+           FatalError ("No copyPlane proc registered for depth %d\n",
+                       pSrcDrawable->depth);
+       }
+    }
+    if (plane != 1)
+       return NULL;
+
+    if ((pGC->fgPixel & 1) == 1 && (pGC->bgPixel & 1) == 0)
+    {
+       prgnExposed = (*pGC->ops->CopyArea)(pSrcDrawable, pDstDrawable,
+                        pGC, srcx, srcy, width, height, dstx, dsty);
+    }
+    else if ((pGC->fgPixel & 1) == (pGC->bgPixel & 1))
+    {
+       alu = pGC->alu;
+       pGC->alu = mfbReduceRop(pGC->alu, pGC->fgPixel);
+       prgnExposed = (*pGC->ops->CopyArea)(pSrcDrawable, pDstDrawable,
+                        pGC, srcx, srcy, width, height, dstx, dsty);
+       pGC->alu = alu;
+    }
+    else /* need to invert the src */
+    {
+       alu = pGC->alu;
+       pGC->alu = InverseAlu[alu];
+       prgnExposed = (*pGC->ops->CopyArea)(pSrcDrawable, pDstDrawable,
+                        pGC, srcx, srcy, width, height, dstx, dsty);
+       pGC->alu = alu;
+    }
+    return prgnExposed;
+}
diff --git a/Xserver/programs/Xserver/mfb/mfbblt.c b/Xserver/programs/Xserver/mfb/mfbblt.c
new file mode 100644 (file)
index 0000000..d54fb88
--- /dev/null
@@ -0,0 +1,593 @@
+/*
+ * mfb copy area
+ */
+
+/*
+
+Copyright (c) 1989  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+Author: Keith Packard
+
+*/
+/* $XConsortium: mfbblt.c,v 1.11 94/04/17 20:28:16 dpw Exp $ */
+/* $XFree86: xc/programs/Xserver/mfb/mfbblt.c,v 3.0 1994/08/12 14:03:38 dawes Exp $ */
+
+#include       "X.h"
+#include       "Xmd.h"
+#include       "Xproto.h"
+#include       "mfb.h"
+#include       "gcstruct.h"
+#include       "windowstr.h"
+#include       "scrnintstr.h"
+#include       "pixmapstr.h"
+#include       "regionstr.h"
+#include       "maskbits.h"
+#include       "fastblt.h"
+#include       "mergerop.h"
+
+void
+MROP_NAME(mfbDoBitblt)(pSrc, pDst, alu, prgnDst, pptSrc)
+    DrawablePtr            pSrc, pDst;
+    int                    alu;
+    RegionPtr      prgnDst;
+    DDXPointPtr            pptSrc;
+{
+    PixelType *psrcBase, *pdstBase;    
+                               /* start of src and dst bitmaps */
+    int widthSrc, widthDst;    /* add to get to same position in next line */
+
+    BoxPtr pbox;
+    int nbox;
+
+    BoxPtr pboxTmp, pboxNext, pboxBase, pboxNew1, pboxNew2;
+                               /* temporaries for shuffling rectangles */
+    DDXPointPtr pptTmp, pptNew1, pptNew2;
+                               /* shuffling boxes entails shuffling the
+                                  source points too */
+    int w, h;
+    int xdir;                  /* 1 = left right, -1 = right left/ */
+    int ydir;                  /* 1 = top down, -1 = bottom up */
+
+    PixelType *psrcLine, *pdstLine;    
+                               /* pointers to line with current src and dst */
+    register PixelType *psrc;/* pointer to current src longword */
+    register PixelType *pdst;/* pointer to current dst longword */
+
+    MROP_DECLARE_REG()
+
+                               /* following used for looping through a line */
+    PixelType startmask, endmask;      /* masks for writing ends of dst */
+    int nlMiddle;              /* whole longwords in dst */
+    int xoffSrc, xoffDst;
+    register int leftShift, rightShift;
+    register PixelType bits;
+    register PixelType bits1;
+    register int nl;           /* temp copy of nlMiddle */
+
+                               /* place to store full source word */
+    int nstart;                        /* number of ragged bits at start of dst */
+    int nend;                  /* number of ragged bits at end of dst */
+    int srcStartOver;          /* pulling nstart bits from src
+                                  overflows into the next word? */
+    int careful;
+    int tmpSrc;
+
+    MROP_INITIALIZE(alu,0);
+
+    mfbGetPixelWidthAndPointer(pSrc, widthSrc, psrcBase);
+
+    mfbGetPixelWidthAndPointer(pDst, widthDst, pdstBase);
+
+    /* XXX we have to err on the side of safety when both are windows,
+     * because we don't know if IncludeInferiors is being used.
+     */
+    careful = ((pSrc == pDst) ||
+              ((pSrc->type == DRAWABLE_WINDOW) &&
+               (pDst->type == DRAWABLE_WINDOW)));
+
+    pbox = REGION_RECTS(prgnDst);
+    nbox = REGION_NUM_RECTS(prgnDst);
+
+    pboxNew1 = NULL;
+    pptNew1 = NULL;
+    pboxNew2 = NULL;
+    pptNew2 = NULL;
+    if (careful && (pptSrc->y < pbox->y1))
+    {
+        /* walk source botttom to top */
+       ydir = -1;
+       widthSrc = -widthSrc;
+       widthDst = -widthDst;
+
+       if (nbox > 1)
+       {
+           /* keep ordering in each band, reverse order of bands */
+           pboxNew1 = (BoxPtr)ALLOCATE_LOCAL(sizeof(BoxRec) * nbox);
+           if(!pboxNew1)
+               return;
+           pptNew1 = (DDXPointPtr)ALLOCATE_LOCAL(sizeof(DDXPointRec) * nbox);
+           if(!pptNew1)
+           {
+               DEALLOCATE_LOCAL(pboxNew1);
+               return;
+           }
+           pboxBase = pboxNext = pbox+nbox-1;
+           while (pboxBase >= pbox)
+           {
+               while ((pboxNext >= pbox) &&
+                      (pboxBase->y1 == pboxNext->y1))
+                   pboxNext--;
+               pboxTmp = pboxNext+1;
+               pptTmp = pptSrc + (pboxTmp - pbox);
+               while (pboxTmp <= pboxBase)
+               {
+                   *pboxNew1++ = *pboxTmp++;
+                   *pptNew1++ = *pptTmp++;
+               }
+               pboxBase = pboxNext;
+           }
+           pboxNew1 -= nbox;
+           pbox = pboxNew1;
+           pptNew1 -= nbox;
+           pptSrc = pptNew1;
+        }
+    }
+    else
+    {
+       /* walk source top to bottom */
+       ydir = 1;
+    }
+
+    if (careful && (pptSrc->x < pbox->x1))
+    {
+       /* walk source right to left */
+        xdir = -1;
+
+       if (nbox > 1)
+       {
+           /* reverse order of rects in each band */
+           pboxNew2 = (BoxPtr)ALLOCATE_LOCAL(sizeof(BoxRec) * nbox);
+           pptNew2 = (DDXPointPtr)ALLOCATE_LOCAL(sizeof(DDXPointRec) * nbox);
+           if(!pboxNew2 || !pptNew2)
+           {
+               if (pptNew2) DEALLOCATE_LOCAL(pptNew2);
+               if (pboxNew2) DEALLOCATE_LOCAL(pboxNew2);
+               if (pboxNew1)
+               {
+                   DEALLOCATE_LOCAL(pptNew1);
+                   DEALLOCATE_LOCAL(pboxNew1);
+               }
+               return;
+           }
+           pboxBase = pboxNext = pbox;
+           while (pboxBase < pbox+nbox)
+           {
+               while ((pboxNext < pbox+nbox) &&
+                      (pboxNext->y1 == pboxBase->y1))
+                   pboxNext++;
+               pboxTmp = pboxNext;
+               pptTmp = pptSrc + (pboxTmp - pbox);
+               while (pboxTmp != pboxBase)
+               {
+                   *pboxNew2++ = *--pboxTmp;
+                   *pptNew2++ = *--pptTmp;
+               }
+               pboxBase = pboxNext;
+           }
+           pboxNew2 -= nbox;
+           pbox = pboxNew2;
+           pptNew2 -= nbox;
+           pptSrc = pptNew2;
+       }
+    }
+    else
+    {
+       /* walk source left to right */
+        xdir = 1;
+    }
+
+    while(nbox--)
+    {
+       w = pbox->x2 - pbox->x1;
+       h = pbox->y2 - pbox->y1;
+
+       if (ydir == -1) /* start at last scanline of rectangle */
+       {
+           psrcLine = mfbScanlineDeltaSrc(psrcBase, -(pptSrc->y+h-1), widthSrc);
+           pdstLine = mfbScanlineDeltaDst(pdstBase, -(pbox->y2-1), widthDst);
+       }
+       else /* start at first scanline */
+       {
+           psrcLine = mfbScanlineDeltaSrc(psrcBase, pptSrc->y, widthSrc);
+           pdstLine = mfbScanlineDeltaDst(pdstBase, pbox->y1, widthDst);
+       }
+       if ((pbox->x1 & PIM) + w <= PPW)
+       {
+           maskpartialbits (pbox->x1, w, startmask);
+           endmask = 0;
+           nlMiddle = 0;
+       }
+       else
+       {
+           maskbits(pbox->x1, w, startmask, endmask, nlMiddle);
+       }
+       if (xdir == 1)
+       {
+           xoffSrc = pptSrc->x & PIM;
+           xoffDst = pbox->x1 & PIM;
+           pdstLine += (pbox->x1 >> PWSH);
+           psrcLine += (pptSrc->x >> PWSH);
+#ifdef DO_UNALIGNED_BITBLT
+           nl = xoffSrc - xoffDst;
+           psrcLine = (PixelType *)
+                       (((unsigned char *) psrcLine) + nl);
+#else
+           if (xoffSrc == xoffDst)
+#endif
+           {
+               while (h--)
+               {
+                   psrc = psrcLine;
+                   pdst = pdstLine;
+                   if (startmask)
+                   {
+                       *pdst = MROP_MASK(*psrc, *pdst, startmask);
+                       psrc++;
+                       pdst++;
+                   }
+                   nl = nlMiddle;
+
+#ifdef LARGE_INSTRUCTION_CACHE
+#ifdef FAST_CONSTANT_OFFSET_MODE
+
+                   psrc += nl & (UNROLL-1);
+                   pdst += nl & (UNROLL-1);
+
+#define BodyOdd(n) pdst[-n] = MROP_SOLID (psrc[-n], pdst[-n]);
+#define BodyEven(n) pdst[-n] = MROP_SOLID (psrc[-n], pdst[-n]);
+
+#define LoopReset \
+pdst += UNROLL; \
+psrc += UNROLL;
+
+#else
+
+#define BodyOdd(n)  *pdst = MROP_SOLID (*psrc, *pdst); pdst++; psrc++;
+#define BodyEven(n) BodyOdd(n)
+
+#define LoopReset   ;
+
+#endif
+                   PackedLoop
+
+#undef BodyOdd
+#undef BodyEven
+#undef LoopReset
+
+#else
+#ifdef NOTDEF
+                   /* you'd think this would be faster --
+                    * a single instruction instead of 6
+                    * but measurements show it to be ~15% slower
+                    */
+                   while ((nl -= 6) >= 0)
+                   {
+                       asm ("moveml %1+,#0x0c0f;moveml#0x0c0f,%0"
+                            : "=m" (*(char *)pdst)
+                            : "m" (*(char *)psrc)
+                            : "d0", "d1", "d2", "d3",
+                              "a2", "a3");
+                       pdst += 6;
+                   }
+                   nl += 6;
+                   while (nl--)
+                       *pdst++ = *psrc++;
+#endif
+                   DuffL(nl, label1,
+                           *pdst = MROP_SOLID (*psrc, *pdst);
+                           pdst++; psrc++;)
+#endif
+
+                   if (endmask)
+                       *pdst = MROP_MASK(*psrc, *pdst, endmask);
+                   mfbScanlineIncDst(pdstLine, widthDst);
+                   mfbScanlineIncSrc(psrcLine, widthSrc);
+               }
+           }
+#ifndef DO_UNALIGNED_BITBLT
+           else
+           {
+               if (xoffSrc > xoffDst)
+               {
+                   leftShift = (xoffSrc - xoffDst);
+                   rightShift = PPW - leftShift;
+               }
+               else
+               {
+                   rightShift = (xoffDst - xoffSrc);
+                   leftShift = PPW - rightShift;
+               }
+               while (h--)
+               {
+                   psrc = psrcLine;
+                   pdst = pdstLine;
+                   bits = 0;
+                   if (xoffSrc > xoffDst)
+                       bits = *psrc++;
+                   if (startmask)
+                   {
+                       bits1 = BitLeft(bits,leftShift);
+                       if (BitLeft(startmask, rightShift)) {
+                               bits = *psrc++;
+                               bits1 |= BitRight(bits,rightShift);
+                       }
+                       *pdst = MROP_MASK(bits1, *pdst, startmask);
+                       pdst++;
+                   }
+                   nl = nlMiddle;
+
+#ifdef LARGE_INSTRUCTION_CACHE
+                   bits1 = bits;
+
+#ifdef FAST_CONSTANT_OFFSET_MODE
+
+                   psrc += nl & (UNROLL-1);
+                   pdst += nl & (UNROLL-1);
+
+#define BodyOdd(n) \
+bits = psrc[-n]; \
+pdst[-n] = MROP_SOLID(BitLeft(bits1, leftShift) | BitRight(bits, rightShift), pdst[-n]);
+
+#define BodyEven(n) \
+bits1 = psrc[-n]; \
+pdst[-n] = MROP_SOLID(BitLeft(bits, leftShift) | BitRight(bits1, rightShift), pdst[-n]);
+
+#define LoopReset \
+pdst += UNROLL; \
+psrc += UNROLL;
+
+#else
+
+#define BodyOdd(n) \
+bits = *psrc++; \
+*pdst = MROP_SOLID(BitLeft(bits1, leftShift) | BitRight(bits, rightShift), *pdst); \
+pdst++;
+                  
+#define BodyEven(n) \
+bits1 = *psrc++; \
+*pdst = MROP_SOLID(BitLeft(bits, leftShift) | BitRight(bits1, rightShift), *pdst); \
+pdst++;
+
+#define LoopReset   ;
+
+#endif /* !FAST_CONSTANT_OFFSET_MODE */
+
+                   PackedLoop
+
+#undef BodyOdd
+#undef BodyEven
+#undef LoopReset
+
+#else
+                   DuffL (nl,label2,
+                       bits1 = BitLeft(bits, leftShift);
+                       bits = *psrc++;
+                       *pdst = MROP_SOLID (bits1 | BitRight(bits, rightShift), *pdst);
+                       pdst++;
+                   )
+#endif
+
+                   if (endmask)
+                   {
+                       bits1 = BitLeft(bits, leftShift);
+                       if (BitLeft(endmask, rightShift))
+                       {
+                           bits = *psrc;
+                           bits1 |= BitRight(bits, rightShift);
+                       }
+                       *pdst = MROP_MASK (bits1, *pdst, endmask);
+                   }
+                   mfbScanlineIncDst(pdstLine, widthDst);
+                   mfbScanlineIncSrc(psrcLine, widthSrc);
+               }
+           }
+#endif /* DO_UNALIGNED_BITBLT */
+       }
+       else    /* xdir == -1 */
+       {
+           xoffSrc = (pptSrc->x + w - 1) & PIM;
+           xoffDst = (pbox->x2 - 1) & PIM;
+           pdstLine += ((pbox->x2-1) >> PWSH) + 1;
+           psrcLine += ((pptSrc->x+w - 1) >> PWSH) + 1;
+#ifdef DO_UNALIGNED_BITBLT
+           nl = xoffSrc - xoffDst;
+           psrcLine = (PixelType *)
+                       (((unsigned char *) psrcLine) + nl);
+#else
+           if (xoffSrc == xoffDst)
+#endif
+           {
+               while (h--)
+               {
+                   psrc = psrcLine;
+                   pdst = pdstLine;
+                   if (endmask)
+                   {
+                       pdst--;
+                       psrc--;
+                       *pdst = MROP_MASK (*psrc, *pdst, endmask);
+                   }
+                   nl = nlMiddle;
+
+#ifdef LARGE_INSTRUCTION_CACHE
+#ifdef FAST_CONSTANT_OFFSET_MODE
+                   psrc -= nl & (UNROLL - 1);
+                   pdst -= nl & (UNROLL - 1);
+
+#define BodyOdd(n) pdst[n-1] = MROP_SOLID (psrc[n-1], pdst[n-1]);
+
+#define BodyEven(n) BodyOdd(n)
+
+#define LoopReset \
+pdst -= UNROLL;\
+psrc -= UNROLL;
+
+#else
+
+#define BodyOdd(n)  --pdst; --psrc; *pdst = MROP_SOLID(*psrc, *pdst);
+#define BodyEven(n) BodyOdd(n)
+#define LoopReset   ;
+
+#endif
+                   PackedLoop
+
+#undef BodyOdd
+#undef BodyEven
+#undef LoopReset
+
+#else
+                   DuffL(nl,label3,
+                        --pdst; --psrc; *pdst = MROP_SOLID (*psrc, *pdst);)
+#endif
+
+                   if (startmask)
+                   {
+                       --pdst;
+                       --psrc;
+                       *pdst = MROP_MASK(*psrc, *pdst, startmask);
+                   }
+                   mfbScanlineIncDst(pdstLine, widthDst);
+                   mfbScanlineIncSrc(psrcLine, widthSrc);
+               }
+           }
+#ifndef DO_UNALIGNED_BITBLT
+           else
+           {
+               if (xoffDst > xoffSrc)
+               {
+                   rightShift = (xoffDst - xoffSrc);
+                   leftShift = PPW - rightShift;
+               }
+               else
+               {
+                   leftShift = (xoffSrc - xoffDst);
+                   rightShift = PPW - leftShift;
+               }
+               while (h--)
+               {
+                   psrc = psrcLine;
+                   pdst = pdstLine;
+                   bits = 0;
+                   if (xoffDst > xoffSrc)
+                       bits = *--psrc;
+                   if (endmask)
+                   {
+                       bits1 = BitRight(bits, rightShift);
+                       if (BitRight(endmask, leftShift)) {
+                               bits = *--psrc;
+                               bits1 |= BitLeft(bits, leftShift);
+                       }
+                       pdst--;
+                       *pdst = MROP_MASK(bits1, *pdst, endmask);
+                   }
+                   nl = nlMiddle;
+
+#ifdef LARGE_INSTRUCTION_CACHE
+                   bits1 = bits;
+#ifdef FAST_CONSTANT_OFFSET_MODE
+                   psrc -= nl & (UNROLL - 1);
+                   pdst -= nl & (UNROLL - 1);
+
+#define BodyOdd(n) \
+bits = psrc[n-1]; \
+pdst[n-1] = MROP_SOLID(BitRight(bits1, rightShift) | BitLeft(bits, leftShift),pdst[n-1]);
+
+#define BodyEven(n) \
+bits1 = psrc[n-1]; \
+pdst[n-1] = MROP_SOLID(BitRight(bits, rightShift) | BitLeft(bits1, leftShift),pdst[n-1]);
+
+#define LoopReset \
+pdst -= UNROLL; \
+psrc -= UNROLL;
+
+#else
+
+#define BodyOdd(n) \
+bits = *--psrc; --pdst; \
+*pdst = MROP_SOLID(BitRight(bits1, rightShift) | BitLeft(bits, leftShift),*pdst);
+
+#define BodyEven(n) \
+bits1 = *--psrc; --pdst; \
+*pdst = MROP_SOLID(BitRight(bits, rightShift) | BitLeft(bits1, leftShift),*pdst);
+
+#define LoopReset   ;
+
+#endif
+
+                   PackedLoop
+
+#undef BodyOdd
+#undef BodyEven
+#undef LoopReset
+
+#else
+                   DuffL (nl, label4,
+                       bits1 = BitRight(bits, rightShift);
+                       bits = *--psrc;
+                       --pdst;
+                       *pdst = MROP_SOLID(bits1 | BitLeft(bits, leftShift),*pdst);
+                   )
+#endif
+
+                   if (startmask)
+                   {
+                       bits1 = BitRight(bits, rightShift);
+                       if (BitRight (startmask, leftShift))
+                       {
+                           bits = *--psrc;
+                           bits1 |= BitLeft(bits, leftShift);
+                       }
+                       --pdst;
+                       *pdst = MROP_MASK(bits1, *pdst, startmask);
+                   }
+                   mfbScanlineIncDst(pdstLine, widthDst);
+                   mfbScanlineIncSrc(psrcLine, widthSrc);
+               }
+           }
+#endif
+       }
+       pbox++;
+       pptSrc++;
+    }
+    if (pboxNew2)
+    {
+       DEALLOCATE_LOCAL(pptNew2);
+       DEALLOCATE_LOCAL(pboxNew2);
+    }
+    if (pboxNew1)
+    {
+       DEALLOCATE_LOCAL(pptNew1);
+       DEALLOCATE_LOCAL(pboxNew1);
+    }
+}
diff --git a/Xserver/programs/Xserver/mfb/mfbbres.c b/Xserver/programs/Xserver/mfb/mfbbres.c
new file mode 100644 (file)
index 0000000..22d8566
--- /dev/null
@@ -0,0 +1,366 @@
+/* Combined Purdue/PurduePlus patches, level 2.0, 1/17/89 */
+/***********************************************************
+
+Copyright (c) 1987  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+
+Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
+
+                        All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and its 
+documentation for any purpose and without fee is hereby granted, 
+provided that the above copyright notice appear in all copies and that
+both that copyright notice and this permission notice appear in 
+supporting documentation, and that the name of Digital not be
+used in advertising or publicity pertaining to distribution of the
+software without specific, written prior permission.  
+
+DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
+ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
+DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
+ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+SOFTWARE.
+
+******************************************************************/
+/* $XConsortium: mfbbres.c,v 1.22 94/04/17 20:28:17 dpw Exp $ */
+#include "X.h"
+#include "misc.h"
+#include "mfb.h"
+#include "maskbits.h"
+#include "miline.h"
+
+/* Solid bresenham line */
+/* NOTES
+   e2 is used less often than e1, so it's not in a register
+*/
+
+void
+mfbBresS(rop, addrlbase, nlwidth, signdx, signdy, axis, x1, y1, e, e1, e2, len)
+int rop;               /* a reduced rasterop */
+PixelType *addrlbase;  /* pointer to base of bitmap */
+int nlwidth;           /* width in longwords of bitmap */
+int signdx, signdy;    /* signs of directions */
+int axis;              /* major axis (Y_AXIS or X_AXIS) */
+int x1, y1;            /* initial point */
+register int e;                /* error accumulator */
+register int e1;       /* bresenham increments */
+int e2;
+int len;               /* length of line */
+{
+    register int yinc; /* increment to next scanline, in bytes */
+    register PixelType *addrl; /* bitmask long pointer */
+    register PixelType bit;    /* current bit being set/cleared/etc.  */
+    PixelType leftbit = mask[0]; /* leftmost bit to process in new word */
+    PixelType rightbit = mask[PPW-1]; /* rightmost bit to process in new word */
+
+    register int e3 = e2-e1;
+    PixelType  tmp;
+
+    /* point to longword containing first point */
+    addrl = mfbScanline(addrlbase, x1, y1, nlwidth);
+    yinc = signdy * nlwidth;
+    e = e-e1;                  /* to make looping easier */
+    bit = mask[x1 & PIM];
+
+    if (!len)
+       return;
+    if (rop == RROP_BLACK)
+    {
+        if (axis == X_AXIS)
+        {
+           if (signdx > 0)
+           {
+               tmp = *addrl;
+               for (;;)
+               { 
+                   tmp &= ~bit;
+                   if (!--len)
+                       break;
+                   bit = SCRRIGHT(bit,1);
+                   e += e1;
+                   if (e >= 0)
+                   {
+                       *addrl = tmp;
+                       mfbScanlineInc(addrl, yinc);
+                       e += e3;
+                       if (!bit)
+                       {
+                           bit = leftbit;
+                           addrl ++;
+                       }
+                       tmp = *addrl;
+                   }
+                   else if (!bit)
+                   {
+                       *addrl = tmp;
+                       bit = leftbit;
+                       addrl ++;
+                       tmp = *addrl;
+                   }
+               }
+               *addrl = tmp;
+           }
+           else
+           {
+               tmp = *addrl;
+               for (;;)
+               { 
+                   tmp &= ~bit;
+                   if (!--len)
+                       break;
+                   e += e1;
+                   bit = SCRLEFT(bit,1);
+                   if (e >= 0)
+                   {
+                       *addrl = tmp;
+                       mfbScanlineInc(addrl, yinc);
+                       e += e3;
+                       if (!bit)
+                       {
+                           bit = rightbit;
+                           addrl --;
+                       }
+                       tmp = *addrl;
+                   }
+                   else if (!bit)
+                   {
+                       *addrl = tmp;
+                       bit = rightbit;
+                       addrl --;
+                       tmp = *addrl;
+                   }
+               }
+               *addrl = tmp;
+           }
+        } /* if X_AXIS */
+        else
+        {
+           if (signdx > 0)
+           {
+               while(len--)
+               {
+                   *addrl &= ~bit;
+                   e += e1;
+                   if (e >= 0)
+                   {
+                       bit = SCRRIGHT(bit,1);
+                       if (!bit) { bit = leftbit;addrl ++; }
+                       e += e3;
+                   }
+                   mfbScanlineInc(addrl, yinc);
+               }
+           }
+           else
+           {
+               while(len--)
+               {
+                   *addrl &= ~bit;
+                   e += e1;
+                   if (e >= 0)
+                   {
+                       bit = SCRLEFT(bit,1);
+                       if (!bit) { bit = rightbit;addrl --; }
+                       e += e3;
+                   }
+                   mfbScanlineInc(addrl, yinc);
+               }
+           }
+        } /* else Y_AXIS */
+    } 
+    else if (rop == RROP_WHITE)
+    {
+        if (axis == X_AXIS)
+        {
+           if (signdx > 0)
+           {
+               tmp = *addrl;
+               for (;;)
+               {
+                   tmp |= bit;
+                   if (!--len)
+                       break;
+                   e += e1;
+                   bit = SCRRIGHT(bit,1);
+                   if (e >= 0)
+                   {
+                       *addrl = tmp;
+                       mfbScanlineInc(addrl, yinc);
+                       e += e3;
+                       if (!bit)
+                       {
+                           bit = leftbit;
+                           addrl ++;
+                       }
+                       tmp = *addrl;
+                   }
+                   else if (!bit)
+                   {
+                       *addrl = tmp;
+                       bit = leftbit;
+                       addrl ++;
+                       tmp = *addrl;
+                   }
+               }
+               *addrl = tmp;
+           }
+           else
+           {
+               tmp = *addrl;
+               for (;;)
+               {
+                   tmp |= bit;
+                   if (!--len)
+                       break;
+                   e += e1;
+                   bit = SCRLEFT(bit,1);
+                   if (e >= 0)
+                   {
+                       *addrl = tmp;
+                       mfbScanlineInc(addrl, yinc);
+                       e += e3;
+                       if (!bit)
+                       {
+                           bit = rightbit;
+                           addrl --;
+                       }
+                       tmp = *addrl;
+                   }
+                   else if (!bit)
+                   {
+                       *addrl = tmp;
+                       bit = rightbit;
+                       addrl --;
+                       tmp = *addrl;
+                   }
+               }
+               *addrl = tmp;
+           }
+        } /* if X_AXIS */
+        else
+        {
+           if (signdx > 0)
+           {
+               while(len--)
+               {
+                   *addrl |= bit;
+                   e += e1;
+                   if (e >= 0)
+                   {
+                       bit = SCRRIGHT(bit,1);
+                       if (!bit) { bit = leftbit;addrl ++; }
+                       e += e3;
+                   }
+                   mfbScanlineInc(addrl, yinc);
+               }
+           }
+           else
+           {
+               while(len--)
+               {
+                   *addrl |= bit;
+                   e += e1;
+                   if (e >= 0)
+                   {
+                       bit = SCRLEFT(bit,1);
+                       if (!bit) { bit = rightbit;addrl --; }
+                       e += e3;
+                   }
+                   mfbScanlineInc(addrl, yinc);
+               }
+           }
+        } /* else Y_AXIS */
+    }
+    else if (rop == RROP_INVERT)
+    {
+        if (axis == X_AXIS)
+        {
+           if (signdx > 0)
+           {
+               while(len--)
+               {
+                   *addrl ^= bit;
+                   e += e1;
+                   if (e >= 0)
+                   {
+                       mfbScanlineInc(addrl, yinc);
+                       e += e3;
+                   }
+                   bit = SCRRIGHT(bit,1);
+                   if (!bit) { bit = leftbit;addrl ++; }
+               }
+           }
+           else
+           {
+               while(len--)
+               {
+                   *addrl ^= bit;
+                   e += e1;
+                   if (e >= 0)
+                   {
+                       mfbScanlineInc(addrl, yinc);
+                       e += e3;
+                   }
+                   bit = SCRLEFT(bit,1);
+                   if (!bit) { bit = rightbit;addrl --; }
+               }
+           }
+        } /* if X_AXIS */
+        else
+        {
+           if (signdx > 0)
+           {
+               while(len--)
+               {
+                   *addrl ^= bit;
+                   e += e1;
+                   if (e >= 0)
+                   {
+                       bit = SCRRIGHT(bit,1);
+                       if (!bit) { bit = leftbit;addrl ++; }
+                       e += e3;
+                   }
+                   mfbScanlineInc(addrl, yinc);
+               }
+           }
+           else
+           {
+               while(len--)
+               {
+                   *addrl ^= bit;
+                   e += e1;
+                   if (e >= 0)
+                   {
+                       bit = SCRLEFT(bit,1);
+                       if (!bit) { bit = rightbit; addrl --; }
+                       e += e3;
+                   }
+                   mfbScanlineInc(addrl, yinc);
+               }
+           }
+        } /* else Y_AXIS */
+    }
+} 
diff --git a/Xserver/programs/Xserver/mfb/mfbbresd.c b/Xserver/programs/Xserver/mfb/mfbbresd.c
new file mode 100644 (file)
index 0000000..0f37593
--- /dev/null
@@ -0,0 +1,205 @@
+/***********************************************************
+
+Copyright (c) 1987  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+
+Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
+
+                        All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and its 
+documentation for any purpose and without fee is hereby granted, 
+provided that the above copyright notice appear in all copies and that
+both that copyright notice and this permission notice appear in 
+supporting documentation, and that the name of Digital not be
+used in advertising or publicity pertaining to distribution of the
+software without specific, written prior permission.  
+
+DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
+ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
+DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
+ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+SOFTWARE.
+
+******************************************************************/
+/* $XConsortium: mfbbresd.c,v 1.10 94/04/17 20:28:18 dpw Exp $ */
+#include "X.h"
+#include "misc.h"
+#include "mfb.h"
+#include "maskbits.h"
+#include "miline.h"
+
+/* Dashed bresenham line */
+
+#define StepDash\
+    if (!--dashRemaining) { \
+       if (++ dashIndex == numInDashList) \
+           dashIndex = 0; \
+       dashRemaining = pDash[dashIndex]; \
+       rop = fgrop; \
+       if (dashIndex & 1) \
+           rop = bgrop; \
+    }
+
+void
+mfbBresD(fgrop, bgrop,
+        pdashIndex, pDash, numInDashList, pdashOffset, isDoubleDash,
+        addrlbase, nlwidth,
+        signdx, signdy, axis, x1, y1, e, e1, e2, len)
+int fgrop, bgrop;
+int *pdashIndex;       /* current dash */
+unsigned char *pDash;  /* dash list */
+int numInDashList;     /* total length of dash list */
+int *pdashOffset;      /* offset into current dash */
+int isDoubleDash;
+PixelType *addrlbase;  /* pointer to base of bitmap */
+int nlwidth;           /* width in longwords of bitmap */
+int signdx, signdy;    /* signs of directions */
+int axis;              /* major axis (Y_AXIS or X_AXIS) */
+int x1, y1;            /* initial point */
+register int e;                /* error accumulator */
+register int e1;       /* bresenham increments */
+int e2;
+int len;               /* length of line */
+{
+    register int yinc; /* increment to next scanline, in bytes */
+    register PixelType *addrl;
+    register int e3 = e2-e1;
+    register unsigned long bit;
+    PixelType leftbit = mask[0]; /* leftmost bit to process in new word */
+    PixelType rightbit = mask[PPW-1]; /* rightmost bit to process in new word */
+    int dashIndex;
+    int dashOffset;
+    int dashRemaining;
+    int        rop;
+
+    dashOffset = *pdashOffset;
+    dashIndex = *pdashIndex;
+    dashRemaining = pDash[dashIndex] - dashOffset;
+    rop = fgrop;
+    if (!isDoubleDash)
+       bgrop = -1;
+    if (dashIndex & 1)
+       rop = bgrop;
+
+    /* point to longword containing first point */
+    addrl = mfbScanline(addrlbase, x1, y1, nlwidth);
+    yinc = signdy * nlwidth;
+    e = e-e1;                  /* to make looping easier */
+    bit = mask[x1 & PIM];
+    if (axis == X_AXIS)
+    {
+       if (signdx > 0)
+       {
+           while(len--)
+           { 
+               if (rop == RROP_BLACK)
+                   *addrl &= ~bit;
+               else if (rop == RROP_WHITE)
+                   *addrl |= bit;
+               else if (rop == RROP_INVERT)
+                   *addrl ^= bit;
+               e += e1;
+               if (e >= 0)
+               {
+                   mfbScanlineInc(addrl, yinc);
+                   e += e3;
+               }
+               bit = SCRRIGHT(bit,1);
+               if (!bit) { bit = leftbit;addrl ++; }
+               StepDash
+           }
+       }
+       else
+       {
+           while(len--)
+           { 
+               if (rop == RROP_BLACK)
+                   *addrl &= ~bit;
+               else if (rop == RROP_WHITE)
+                   *addrl |= bit;
+               else if (rop == RROP_INVERT)
+                   *addrl ^= bit;
+               e += e1;
+               if (e >= 0)
+               {
+                   mfbScanlineInc(addrl, yinc);
+                   e += e3;
+               }
+               bit = SCRLEFT(bit,1);
+               if (!bit) { bit = rightbit;addrl --; }
+               StepDash
+           }
+       }
+    } /* if X_AXIS */
+    else
+    {
+       if (signdx > 0)
+       {
+           while(len--)
+           {
+               if (rop == RROP_BLACK)
+                   *addrl &= ~bit;
+               else if (rop == RROP_WHITE)
+                   *addrl |= bit;
+               else if (rop == RROP_INVERT)
+                   *addrl ^= bit;
+               e += e1;
+               if (e >= 0)
+               {
+                   bit = SCRRIGHT(bit,1);
+                   if (!bit) { bit = leftbit;addrl ++; }
+                   e += e3;
+               }
+               mfbScanlineInc(addrl, yinc);
+               StepDash
+           }
+       }
+       else
+       {
+           while(len--)
+           {
+               if (rop == RROP_BLACK)
+                   *addrl &= ~bit;
+               else if (rop == RROP_WHITE)
+                   *addrl |= bit;
+               else if (rop == RROP_INVERT)
+                   *addrl ^= bit;
+               e += e1;
+               if (e >= 0)
+               {
+                   bit = SCRLEFT(bit,1);
+                   if (!bit) { bit = rightbit;addrl --; }
+                   e += e3;
+               }
+               mfbScanlineInc(addrl, yinc);
+               StepDash
+           }
+       }
+    } /* else Y_AXIS */
+    *pdashIndex = dashIndex;
+    *pdashOffset = pDash[dashIndex] - dashRemaining;
+} 
diff --git a/Xserver/programs/Xserver/mfb/mfbbstore.c b/Xserver/programs/Xserver/mfb/mfbbstore.c
new file mode 100644 (file)
index 0000000..536525d
--- /dev/null
@@ -0,0 +1,153 @@
+/* $XConsortium: mfbbstore.c,v 5.7 94/04/17 20:28:18 dpw Exp $ */
+/* Combined Purdue/PurduePlus patches, level 2.0, 1/17/89 */
+/*
+
+Copyright (c) 1987  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be included
+in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR
+OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall
+not be used in advertising or otherwise to promote the sale, use or
+other dealings in this Software without prior written authorization
+from the X Consortium.
+
+*/
+
+#include    "mfb.h"
+#include    "X.h"
+#include    "mibstore.h"
+#include    "regionstr.h"
+#include    "scrnintstr.h"
+#include    "pixmapstr.h"
+#include    "windowstr.h"
+
+/*-
+ *-----------------------------------------------------------------------
+ * mfbSaveAreas --
+ *     Function called by miSaveAreas to actually fetch the areas to be
+ *     saved into the backing pixmap. This is very simple to do, since
+ *     mfbDoBitblt is designed for this very thing. The region to save is
+ *     already destination-relative and we're given the offset to the
+ *     window origin, so we have only to create an array of points of the
+ *     u.l. corners of the boxes in the region translated to the screen
+ *     coordinate system and fetch the screen pixmap out of its devPrivate
+ *     field....
+ *
+ * Results:
+ *     None.
+ *
+ * Side Effects:
+ *     Data are copied from the screen into the pixmap.
+ *
+ *-----------------------------------------------------------------------
+ */
+void
+mfbSaveAreas(pPixmap, prgnSave, xorg, yorg, pWin)
+    PixmapPtr          pPixmap;        /* Backing pixmap */
+    RegionPtr          prgnSave;       /* Region to save (pixmap-relative) */
+    int                        xorg;           /* X origin of region */
+    int                        yorg;           /* Y origin of region */
+    WindowPtr          pWin;
+{
+    register DDXPointPtr pPt;
+    DDXPointPtr                pPtsInit;
+    register BoxPtr    pBox;
+    register int       numRects;
+    
+    numRects = REGION_NUM_RECTS(prgnSave);
+    pPtsInit = (DDXPointPtr)ALLOCATE_LOCAL(numRects * sizeof(DDXPointRec));
+    if (!pPtsInit)
+       return;
+    
+    pBox = REGION_RECTS(prgnSave);
+    pPt = pPtsInit;
+    while (numRects--)
+    {
+       pPt->x = pBox->x1 + xorg;
+       pPt->y = pBox->y1 + yorg;
+       pPt++;
+       pBox++;
+    }
+
+    mfbDoBitblt((DrawablePtr)pPixmap->drawable.pScreen->devPrivate,
+               (DrawablePtr)pPixmap,
+               GXcopy,
+               prgnSave,
+               pPtsInit);
+
+    DEALLOCATE_LOCAL(pPtsInit);
+}
+
+/*-
+ *-----------------------------------------------------------------------
+ * mfbRestoreAreas --
+ *     Function called by miRestoreAreas to actually fetch the areas to be
+ *     restored from the backing pixmap. This is very simple to do, since
+ *     mfbDoBitblt is designed for this very thing. The region to restore is
+ *     already destination-relative and we're given the offset to the
+ *     window origin, so we have only to create an array of points of the
+ *     u.l. corners of the boxes in the region translated to the pixmap
+ *     coordinate system and fetch the screen pixmap out of its devPrivate
+ *     field....
+ *
+ * Results:
+ *     None.
+ *
+ * Side Effects:
+ *     Data are copied from the pixmap into the screen.
+ *
+ *-----------------------------------------------------------------------
+ */
+void
+mfbRestoreAreas(pPixmap, prgnRestore, xorg, yorg, pWin)
+    PixmapPtr          pPixmap;        /* Backing pixmap */
+    RegionPtr          prgnRestore;    /* Region to restore (screen-relative)*/
+    int                        xorg;           /* X origin of window */
+    int                        yorg;           /* Y origin of window */
+    WindowPtr          pWin;
+{
+    register DDXPointPtr pPt;
+    DDXPointPtr                pPtsInit;
+    register BoxPtr    pBox;
+    register int       numRects;
+    
+    numRects = REGION_NUM_RECTS(prgnRestore);
+    pPtsInit = (DDXPointPtr)ALLOCATE_LOCAL(numRects*sizeof(DDXPointRec));
+    if (!pPtsInit)
+       return;
+    
+    pBox = REGION_RECTS(prgnRestore);
+    pPt = pPtsInit;
+    while (numRects--)
+    {
+       pPt->x = pBox->x1 - xorg;
+       pPt->y = pBox->y1 - yorg;
+       pPt++;
+       pBox++;
+    }
+
+    mfbDoBitblt((DrawablePtr)pPixmap,
+               (DrawablePtr)pPixmap->drawable.pScreen->devPrivate,
+               GXcopy,
+               prgnRestore,
+               pPtsInit);
+
+    DEALLOCATE_LOCAL(pPtsInit);
+}
diff --git a/Xserver/programs/Xserver/mfb/mfbclip.c b/Xserver/programs/Xserver/mfb/mfbclip.c
new file mode 100644 (file)
index 0000000..47a0280
--- /dev/null
@@ -0,0 +1,269 @@
+/***********************************************************
+
+Copyright (c) 1987  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+
+Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
+
+                        All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and its 
+documentation for any purpose and without fee is hereby granted, 
+provided that the above copyright notice appear in all copies and that
+both that copyright notice and this permission notice appear in 
+supporting documentation, and that the name of Digital not be
+used in advertising or publicity pertaining to distribution of the
+software without specific, written prior permission.  
+
+DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
+ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
+DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
+ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+SOFTWARE.
+
+******************************************************************/
+/* $XConsortium: mfbclip.c,v 5.6 94/04/17 20:28:19 dpw Exp $ */
+#include "X.h"
+#include "miscstruct.h"
+#include "pixmapstr.h"
+#include "scrnintstr.h"
+#include "regionstr.h"
+#include "gc.h"
+#include "maskbits.h"
+#include "mi.h"
+
+#define ADDRECT(reg,r,fr,rx1,ry1,rx2,ry2)                      \
+if (((rx1) < (rx2)) && ((ry1) < (ry2)) &&                      \
+    (!((reg)->data->numRects &&                                        \
+       ((r-1)->y1 == (ry1)) &&                                 \
+       ((r-1)->y2 == (ry2)) &&                                 \
+       ((r-1)->x1 <= (rx1)) &&                                 \
+       ((r-1)->x2 >= (rx2)))))                                 \
+{                                                              \
+    if ((reg)->data->numRects == (reg)->data->size)            \
+    {                                                          \
+       miRectAlloc(reg, 1);                                    \
+       fr = REGION_BOXPTR(reg);                                \
+       r = fr + (reg)->data->numRects;                         \
+    }                                                          \
+    r->x1 = (rx1);                                             \
+    r->y1 = (ry1);                                             \
+    r->x2 = (rx2);                                             \
+    r->y2 = (ry2);                                             \
+    (reg)->data->numRects++;                                   \
+    if(r->x1 < (reg)->extents.x1)                              \
+       (reg)->extents.x1 = r->x1;                              \
+    if(r->x2 > (reg)->extents.x2)                              \
+       (reg)->extents.x2 = r->x2;                              \
+    r++;                                                       \
+}
+
+/* Convert bitmap clip mask into clipping region. 
+ * First, goes through each line and makes boxes by noting the transitions
+ * from 0 to 1 and 1 to 0.
+ * Then it coalesces the current line with the previous if they have boxes
+ * at the same X coordinates.
+ */
+RegionPtr
+mfbPixmapToRegion(pPix)
+    PixmapPtr  pPix;
+{
+    register RegionPtr pReg;
+    register PixelType *pw, w;
+    register int       ib;
+    int                        width, h, base, rx1, crects;
+    PixelType          *pwLineEnd;
+    int                        irectPrevStart, irectLineStart;
+    register BoxPtr    prectO, prectN;
+    BoxPtr             FirstRect, rects, prectLineStart;
+    Bool               fInBox, fSame;
+    register PixelType mask0 = mask[0];
+    PixelType          *pwLine;
+    int                        nWidth;
+
+    pReg = REGION_CREATE(pPix->drawable.pScreen, NULL, 1);
+    if(!pReg)
+       return NullRegion;
+    FirstRect = REGION_BOXPTR(pReg);
+    rects = FirstRect;
+
+    pwLine = (PixelType *) pPix->devPrivate.ptr;
+    nWidth = pPix->devKind / PGSZB;
+
+    width = pPix->drawable.width;
+    pReg->extents.x1 = width - 1;
+    pReg->extents.x2 = 0;
+    irectPrevStart = -1;
+    for(h = 0; h < pPix->drawable.height; h++)
+    {
+       pw = pwLine;
+       pwLine += nWidth;
+       irectLineStart = rects - FirstRect;
+       /* If the Screen left most bit of the word is set, we're starting in
+        * a box */
+       if(*pw & mask0)
+       {
+           fInBox = TRUE;
+           rx1 = 0;
+       }
+       else
+           fInBox = FALSE;
+       /* Process all words which are fully in the pixmap */
+       pwLineEnd = pw + (width >> PWSH);
+       for (base = 0; pw < pwLineEnd; base += PPW)
+       {
+           w = *pw++;
+           if (fInBox)
+           {
+               if (!~w)
+                   continue;
+           }
+           else
+           {
+               if (!w)
+                   continue;
+           }
+           for(ib = 0; ib < PPW; ib++)
+           {
+               /* If the Screen left most bit of the word is set, we're
+                * starting a box */
+               if(w & mask0)
+               {
+                   if(!fInBox)
+                   {
+                       rx1 = base + ib;
+                       /* start new box */
+                       fInBox = TRUE;
+                   }
+               }
+               else
+               {
+                   if(fInBox)
+                   {
+                       /* end box */
+                       ADDRECT(pReg, rects, FirstRect,
+                               rx1, h, base + ib, h + 1);
+                       fInBox = FALSE;
+                   }
+               }
+               /* Shift the word VISUALLY left one. */
+               w = SCRLEFT(w, 1);
+           }
+       }
+       if(width & PIM)
+       {
+           /* Process final partial word on line */
+           w = *pw++;
+           for(ib = 0; ib < (width & PIM); ib++)
+           {
+               /* If the Screen left most bit of the word is set, we're
+                * starting a box */
+               if(w & mask0)
+               {
+                   if(!fInBox)
+                   {
+                       rx1 = base + ib;
+                       /* start new box */
+                       fInBox = TRUE;
+                   }
+               }
+               else
+               {
+                   if(fInBox)
+                   {
+                       /* end box */
+                       ADDRECT(pReg, rects, FirstRect,
+                               rx1, h, base + ib, h + 1);
+                       fInBox = FALSE;
+                   }
+               }
+               /* Shift the word VISUALLY left one. */
+               w = SCRLEFT(w, 1);
+           }
+       }
+       /* If scanline ended with last bit set, end the box */
+       if(fInBox)
+       {
+           ADDRECT(pReg, rects, FirstRect,
+                   rx1, h, base + (width & PIM), h + 1);
+       }
+       /* if all rectangles on this line have the same x-coords as
+        * those on the previous line, then add 1 to all the previous  y2s and 
+        * throw away all the rectangles from this line 
+        */
+       fSame = FALSE;
+       if(irectPrevStart != -1)
+       {
+           crects = irectLineStart - irectPrevStart;
+           if(crects == ((rects - FirstRect) - irectLineStart))
+           {
+               prectO = FirstRect + irectPrevStart;
+               prectN = prectLineStart = FirstRect + irectLineStart;
+               fSame = TRUE;
+               while(prectO < prectLineStart)
+               {
+                   if((prectO->x1 != prectN->x1) || (prectO->x2 != prectN->x2))
+                   {
+                         fSame = FALSE;
+                         break;
+                   }
+                   prectO++;
+                   prectN++;
+               }
+               if (fSame)
+               {
+                   prectO = FirstRect + irectPrevStart;
+                   while(prectO < prectLineStart)
+                   {
+                       prectO->y2 += 1;
+                       prectO++;
+                   }
+                   rects -= crects;
+                   pReg->data->numRects -= crects;
+               }
+           }
+       }
+       if(!fSame)
+           irectPrevStart = irectLineStart;
+    }
+    if (!pReg->data->numRects)
+       pReg->extents.x1 = pReg->extents.x2 = 0;
+    else
+    {
+       pReg->extents.y1 = REGION_BOXPTR(pReg)->y1;
+       pReg->extents.y2 = REGION_END(pReg)->y2;
+       if (pReg->data->numRects == 1)
+       {
+           xfree(pReg->data);
+           pReg->data = (RegDataPtr)NULL;
+       }
+    }
+#ifdef DEBUG
+    if (!miValidRegion(pReg))
+       FatalError("Assertion failed file %s, line %d: expr\n", __FILE__, __LINE__);
+#endif
+    return(pReg);
+}
diff --git a/Xserver/programs/Xserver/mfb/mfbcmap.c b/Xserver/programs/Xserver/mfb/mfbcmap.c
new file mode 100644 (file)
index 0000000..dd08fa0
--- /dev/null
@@ -0,0 +1,199 @@
+/***********************************************************
+
+Copyright (c) 1987  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+
+Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
+
+                        All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and its 
+documentation for any purpose and without fee is hereby granted, 
+provided that the above copyright notice appear in all copies and that
+both that copyright notice and this permission notice appear in 
+supporting documentation, and that the name of Digital not be
+used in advertising or publicity pertaining to distribution of the
+software without specific, written prior permission.  
+
+DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
+ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
+DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
+ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+SOFTWARE.
+
+******************************************************************/
+/* $XConsortium: mfbcmap.c,v 5.6 94/04/17 20:28:19 dpw Exp $ */
+#include "X.h"
+#include "scrnintstr.h"
+#include "colormapst.h"
+#include "resource.h"
+
+/* A monochrome frame buffer is a static gray colormap with two entries.
+ * We have a "required list" of length 1.  Because we can only support 1
+ * colormap, we never have to change it, but we may have to change the 
+ * name we call it.  If someone installs a new colormap, we know it must
+ * look just like the old one (because we've checked in dispatch that it was
+ * a valid colormap identifier, and all the colormap IDs for this device
+ * look the same).  Nevertheless, we still have to uninstall the old colormap
+ * and install the new one.  Similarly, if someone uninstalls a colormap,
+ * we have to install the default map, even though we know those two looked
+ * alike.  
+ * The required list concept is pretty much irrelevant when you can only
+ * have one map installed at a time.  
+ */
+static ColormapPtr InstalledMaps[MAXSCREENS];
+
+int
+mfbListInstalledColormaps(pScreen, pmaps)
+    ScreenPtr  pScreen;
+    Colormap   *pmaps;
+{
+    /* By the time we are processing requests, we can guarantee that there
+     * is always a colormap installed */
+    *pmaps = InstalledMaps[pScreen->myNum]->mid;
+    return (1);
+}
+
+
+void
+mfbInstallColormap(pmap)
+    ColormapPtr        pmap;
+{
+    int index = pmap->pScreen->myNum;
+    ColormapPtr oldpmap = InstalledMaps[index];
+
+    if(pmap != oldpmap)
+    {
+       /* Uninstall pInstalledMap. No hardware changes required, just
+        * notify all interested parties. */
+       if(oldpmap != (ColormapPtr)None)
+           WalkTree(pmap->pScreen, TellLostMap, (pointer)&oldpmap->mid);
+       /* Install pmap */
+       InstalledMaps[index] = pmap;
+       WalkTree(pmap->pScreen, TellGainedMap, (pointer)&pmap->mid);
+
+    }
+}
+
+void
+mfbUninstallColormap(pmap)
+    ColormapPtr        pmap;
+{
+    int index = pmap->pScreen->myNum;
+    ColormapPtr curpmap = InstalledMaps[index];
+
+    if(pmap == curpmap)
+    {
+       if (pmap->mid != pmap->pScreen->defColormap)
+       {
+           curpmap = (ColormapPtr) LookupIDByType(pmap->pScreen->defColormap,
+                                                  RT_COLORMAP);
+           (*pmap->pScreen->InstallColormap)(curpmap);
+       }
+    }
+}
+
+/*ARGSUSED*/
+void
+mfbResolveColor (pred, pgreen, pblue, pVisual)
+    unsigned short     *pred;
+    unsigned short     *pgreen;
+    unsigned short     *pblue;
+    VisualPtr          pVisual;
+{
+    /* 
+     * Gets intensity from RGB.  If intensity is >= half, pick white, else
+     * pick black.  This may well be more trouble than it's worth.
+     */
+    *pred = *pgreen = *pblue = 
+        (((30L * *pred +
+           59L * *pgreen +
+           11L * *pblue) >> 8) >= (((1<<8)-1)*50)) ? ~0 : 0;
+}
+
+Bool
+mfbCreateColormap(pMap)
+    ColormapPtr        pMap;
+{
+    ScreenPtr  pScreen;
+    unsigned short  red0, green0, blue0;
+    unsigned short  red1, green1, blue1;
+    Pixel pix;
+    
+    pScreen = pMap->pScreen;
+    if (pScreen->whitePixel == 0)
+    {
+       red0 = green0 = blue0 = ~0;
+       red1 = green1 = blue1 = 0;
+    }
+    else
+    {
+       red0 = green0 = blue0 = 0;
+       red1 = green1 = blue1 = ~0;
+    }
+
+    /* this is a monochrome colormap, it only has two entries, just fill
+     * them in by hand.  If it were a more complex static map, it would be
+     * worth writing a for loop or three to initialize it */
+
+    /* this will be pixel 0 */
+    pix = 0;
+    if (AllocColor(pMap, &red0, &green0, &blue0, &pix, 0) != Success)
+       return FALSE;
+
+    /* this will be pixel 1 */
+    if (AllocColor(pMap, &red1, &green1, &blue1, &pix, 0) != Success)
+       return FALSE;
+    return TRUE;
+}
+
+/*ARGSUSED*/
+void
+mfbDestroyColormap (pMap)
+    ColormapPtr        pMap;
+{
+    return;
+}
+
+Bool
+mfbCreateDefColormap (pScreen)
+    ScreenPtr  pScreen;
+{
+    VisualPtr  pVisual;
+    ColormapPtr        pColormap;
+    
+    for (pVisual = pScreen->visuals;
+        pVisual->vid != pScreen->rootVisual;
+        pVisual++)
+       ;
+    if (CreateColormap (pScreen->defColormap, pScreen, pVisual,
+                       &pColormap, AllocNone, 0) != Success)
+    {
+       return FALSE;
+    }
+    (*pScreen->InstallColormap) (pColormap);
+    return TRUE;
+}
diff --git a/Xserver/programs/Xserver/mfb/mfbfillarc.c b/Xserver/programs/Xserver/mfb/mfbfillarc.c
new file mode 100644 (file)
index 0000000..57ed885
--- /dev/null
@@ -0,0 +1,329 @@
+/************************************************************
+
+Copyright (c) 1989  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+********************************************************/
+
+/* $XConsortium: mfbfillarc.c /main/16 1995/12/06 16:54:28 dpw $ */
+
+#include "X.h"
+#include "Xprotostr.h"
+#include "miscstruct.h"
+#include "gcstruct.h"
+#include "pixmapstr.h"
+#include "scrnintstr.h"
+#include "mfb.h"
+#include "maskbits.h"
+#include "mifillarc.h"
+#include "mi.h"
+
+static void
+mfbFillEllipseSolid(pDraw, arc, rop)
+    DrawablePtr pDraw;
+    xArc *arc;
+    register int rop;
+{
+    int x, y, e;
+    int yk, xk, ym, xm, dx, dy, xorg, yorg;
+    register int slw;
+    miFillArcRec info;
+    PixelType *addrlt, *addrlb;
+    register PixelType *addrl;
+    register int n;
+    int nlwidth;
+    register int xpos;
+    PixelType startmask, endmask;
+    int nlmiddle;
+
+    mfbGetPixelWidthAndPointer(pDraw, nlwidth, addrlt);
+    miFillArcSetup(arc, &info);
+    MIFILLARCSETUP();
+    xorg += pDraw->x;
+    yorg += pDraw->y;
+    addrlb = addrlt;
+    addrlt += nlwidth * (yorg - y);
+    addrlb += nlwidth * (yorg + y + dy);
+    while (y)
+    {
+       addrlt += nlwidth;
+       addrlb -= nlwidth;
+       MIFILLARCSTEP(slw);
+       if (!slw)
+           continue;
+       xpos = xorg - x;
+       addrl = mfbScanlineOffset(addrlt, (xpos >> PWSH));
+       if (((xpos & PIM) + slw) < PPW)
+       {
+           maskpartialbits(xpos, slw, startmask);
+           if (rop == RROP_BLACK)
+               *addrl &= ~startmask;
+           else if (rop == RROP_WHITE)
+               *addrl |= startmask;
+           else
+               *addrl ^= startmask;
+           if (miFillArcLower(slw))
+           {
+               addrl = mfbScanlineOffset(addrlb, (xpos >> PWSH));
+               if (rop == RROP_BLACK)
+                   *addrl &= ~startmask;
+               else if (rop == RROP_WHITE)
+                   *addrl |= startmask;
+               else
+                   *addrl ^= startmask;
+           }
+           continue;
+       }
+       maskbits(xpos, slw, startmask, endmask, nlmiddle);
+       if (startmask)
+       {
+           if (rop == RROP_BLACK)
+               *addrl++ &= ~startmask;
+           else if (rop == RROP_WHITE)
+               *addrl++ |= startmask;
+           else
+               *addrl++ ^= startmask;
+       }
+       n = nlmiddle;
+       if (rop == RROP_BLACK)
+           while (n--)
+               *addrl++ = 0;
+       else if (rop == RROP_WHITE)
+           while (n--)
+               *addrl++ = ~0;
+       else
+           while (n--)
+               *addrl++ ^= ~0;
+       if (endmask)
+       {
+           if (rop == RROP_BLACK)
+               *addrl &= ~endmask;
+           else if (rop == RROP_WHITE)
+               *addrl |= endmask;
+           else
+               *addrl ^= endmask;
+       }
+       if (!miFillArcLower(slw))
+           continue;
+       addrl = mfbScanlineOffset(addrlb, (xpos >> PWSH));
+       if (startmask)
+       {
+           if (rop == RROP_BLACK)
+               *addrl++ &= ~startmask;
+           else if (rop == RROP_WHITE)
+               *addrl++ |= startmask;
+           else
+               *addrl++ ^= startmask;
+       }
+       n = nlmiddle;
+       if (rop == RROP_BLACK)
+           while (n--)
+               *addrl++ = 0;
+       else if (rop == RROP_WHITE)
+           while (n--)
+               *addrl++ = ~0;
+       else
+           while (n--)
+               *addrl++ ^= ~0;
+       if (endmask)
+       {
+           if (rop == RROP_BLACK)
+               *addrl &= ~endmask;
+           else if (rop == RROP_WHITE)
+               *addrl |= endmask;
+           else
+               *addrl ^= endmask;
+       }
+    }
+}
+
+#define FILLSPAN(xl,xr,addr) \
+    if (xr >= xl) \
+    { \
+       width = xr - xl + 1; \
+       addrl = mfbScanlineOffset(addr, (xl >> PWSH)); \
+       if (((xl & PIM) + width) < PPW) \
+       { \
+           maskpartialbits(xl, width, startmask); \
+           if (rop == RROP_BLACK) \
+               *addrl &= ~startmask; \
+           else if (rop == RROP_WHITE) \
+               *addrl |= startmask; \
+           else \
+               *addrl ^= startmask; \
+       } \
+       else \
+       { \
+           maskbits(xl, width, startmask, endmask, nlmiddle); \
+           if (startmask) \
+           { \
+               if (rop == RROP_BLACK) \
+                   *addrl++ &= ~startmask; \
+               else if (rop == RROP_WHITE) \
+                   *addrl++ |= startmask; \
+               else \
+                   *addrl++ ^= startmask; \
+           } \
+           n = nlmiddle; \
+           if (rop == RROP_BLACK) \
+               while (n--) \
+                   *addrl++ = 0; \
+           else if (rop == RROP_WHITE) \
+               while (n--) \
+                   *addrl++ = ~0; \
+           else \
+               while (n--) \
+                   *addrl++ ^= ~0; \
+           if (endmask) \
+           { \
+               if (rop == RROP_BLACK) \
+                   *addrl &= ~endmask; \
+               else if (rop == RROP_WHITE) \
+                   *addrl |= endmask; \
+               else \
+                   *addrl ^= endmask; \
+           } \
+       } \
+    }
+
+#define FILLSLICESPANS(flip,addr) \
+    if (!flip) \
+    { \
+       FILLSPAN(xl, xr, addr); \
+    } \
+    else \
+    { \
+       xc = xorg - x; \
+       FILLSPAN(xc, xr, addr); \
+       xc += slw - 1; \
+       FILLSPAN(xl, xc, addr); \
+    }
+
+static void
+mfbFillArcSliceSolidCopy(pDraw, pGC, arc, rop)
+    DrawablePtr pDraw;
+    GCPtr pGC;
+    xArc *arc;
+    register int rop;
+{
+    register PixelType *addrl;
+    register int n;
+    int yk, xk, ym, xm, dx, dy, xorg, yorg, slw;
+    register int x, y, e;
+    miFillArcRec info;
+    miArcSliceRec slice;
+    int xl, xr, xc;
+    PixelType *addrlt, *addrlb;
+    int nlwidth;
+    int width;
+    PixelType startmask, endmask;
+    int nlmiddle;
+
+    mfbGetPixelWidthAndPointer(pDraw, nlwidth, addrlt);
+    miFillArcSetup(arc, &info);
+    miFillArcSliceSetup(arc, &slice, pGC);
+    MIFILLARCSETUP();
+    xorg += pDraw->x;
+    yorg += pDraw->y;
+    addrlb = addrlt;
+    addrlt = mfbScanlineDeltaNoBankSwitch(addrlt, yorg - y, nlwidth);
+    addrlb = mfbScanlineDeltaNoBankSwitch(addrlb, yorg + y + dy, nlwidth);
+    slice.edge1.x += pDraw->x;
+    slice.edge2.x += pDraw->x;
+    while (y > 0)
+    {
+       mfbScanlineIncNoBankSwitch(addrlt, nlwidth);
+       mfbScanlineIncNoBankSwitch(addrlb, -nlwidth);
+       MIFILLARCSTEP(slw);
+       MIARCSLICESTEP(slice.edge1);
+       MIARCSLICESTEP(slice.edge2);
+       if (miFillSliceUpper(slice))
+       {
+           MIARCSLICEUPPER(xl, xr, slice, slw);
+           FILLSLICESPANS(slice.flip_top, addrlt);
+       }
+       if (miFillSliceLower(slice))
+       {
+           MIARCSLICELOWER(xl, xr, slice, slw);
+           FILLSLICESPANS(slice.flip_bot, addrlb);
+       }
+    }
+}
+
+void
+mfbPolyFillArcSolid(pDraw, pGC, narcs, parcs)
+    register DrawablePtr pDraw;
+    GCPtr      pGC;
+    int                narcs;
+    xArc       *parcs;
+{
+    mfbPrivGC *priv;
+    register xArc *arc;
+    register int i;
+    BoxRec box;
+    int x2, y2;
+    RegionPtr cclip;
+    int rop;
+
+    priv = (mfbPrivGC *) pGC->devPrivates[mfbGCPrivateIndex].ptr;
+    rop = priv->rop;
+    if ((rop == RROP_NOP) || !(pGC->planemask & 1))
+       return;
+    cclip = priv->pCompositeClip;
+    for (arc = parcs, i = narcs; --i >= 0; arc++)
+    {
+       if (miFillArcEmpty(arc))
+           continue;
+       if (miCanFillArc(arc))
+       {
+           box.x1 = arc->x + pDraw->x;
+           box.y1 = arc->y + pDraw->y;
+           /*
+            * Because box.x2 and box.y2 get truncated to 16 bits, and the
+            * RECT_IN_REGION test treats the resulting number as a signed
+            * integer, the RECT_IN_REGION test alone can go the wrong way.
+            * This can result in a server crash because the rendering
+            * routines in this file deal directly with cpu addresses
+            * of pixels to be stored, and do not clip or otherwise check
+            * that all such addresses are within their respective pixmaps.
+            * So we only allow the RECT_IN_REGION test to be used for
+            * values that can be expressed correctly in a signed short.
+            */
+           x2 = box.x1 + (int)arc->width + 1;
+           box.x2 = x2;
+           y2 = box.y1 + (int)arc->height + 1;
+           box.y2 = y2;
+           if ( (x2 <= MAXSHORT) && (y2 <= MAXSHORT) &&
+                   (RECT_IN_REGION(pDraw->pScreen, cclip, &box) == rgnIN) )
+           {
+               if ((arc->angle2 >= FULLCIRCLE) ||
+                   (arc->angle2 <= -FULLCIRCLE))
+                   mfbFillEllipseSolid(pDraw, arc, rop);
+               else
+                   mfbFillArcSliceSolidCopy(pDraw, pGC, arc, rop);
+               continue;
+           }
+       }
+       miPolyFillArc(pDraw, pGC, 1, arc);
+    }
+}
diff --git a/Xserver/programs/Xserver/mfb/mfbfillrct.c b/Xserver/programs/Xserver/mfb/mfbfillrct.c
new file mode 100644 (file)
index 0000000..ea55f51
--- /dev/null
@@ -0,0 +1,225 @@
+/* Combined Purdue/PurduePlus patches, level 2.0, 1/17/89 */
+/***********************************************************
+
+Copyright (c) 1987  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+
+Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
+
+                        All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and its 
+documentation for any purpose and without fee is hereby granted, 
+provided that the above copyright notice appear in all copies and that
+both that copyright notice and this permission notice appear in 
+supporting documentation, and that the name of Digital not be
+used in advertising or publicity pertaining to distribution of the
+software without specific, written prior permission.  
+
+DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
+ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
+DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
+ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+SOFTWARE.
+
+******************************************************************/
+/* $XConsortium: mfbfillrct.c,v 5.10 94/04/17 20:28:21 dpw Exp $ */
+#include "X.h"
+#include "Xprotostr.h"
+#include "pixmapstr.h"
+#include "gcstruct.h"
+#include "windowstr.h"
+#include "miscstruct.h"
+#include "regionstr.h"
+#include "scrnintstr.h"
+
+#include "mfb.h"
+#include "maskbits.h"
+
+#define MODEQ(a, b) ((a) %= (b))
+void mfbPaintOddSize();
+
+/* 
+    filled rectangles.
+    translate the rectangles, clip them, and call the
+helper function in the GC.
+*/
+
+#define NUM_STACK_RECTS        1024
+
+void
+mfbPolyFillRect(pDrawable, pGC, nrectFill, prectInit)
+    DrawablePtr pDrawable;
+    GCPtr      pGC;
+    int                nrectFill;      /* number of rectangles to fill */
+    xRectangle *prectInit;     /* Pointer to first rectangle to fill */
+{
+    xRectangle     *prect;
+    RegionPtr      prgnClip;
+    register BoxPtr pbox;
+    register BoxPtr pboxClipped;
+    BoxPtr         pboxClippedBase;
+    BoxPtr         pextent;
+    BoxRec         stackRects[NUM_STACK_RECTS];
+    int                    numRects;
+    int                    n;
+    int                    xorg, yorg;
+    mfbPrivGC  *priv;
+    int alu;
+    void (* pfn) ();
+    PixmapPtr ppix;
+
+    if (!(pGC->planemask & 1))
+       return;
+
+    priv = (mfbPrivGC *) pGC->devPrivates[mfbGCPrivateIndex].ptr;
+    alu = priv->ropFillArea;
+    pfn = priv->FillArea;
+    ppix = priv->pRotatedPixmap;
+    prgnClip = priv->pCompositeClip;
+
+    prect = prectInit;
+    xorg = pDrawable->x;
+    yorg = pDrawable->y;
+    if (xorg || yorg)
+    {
+        prect = prectInit;
+       n = nrectFill;
+       Duff (n, prect->x += xorg; prect->y += yorg; prect++);
+    }
+
+
+    prect = prectInit;
+
+    numRects = REGION_NUM_RECTS(prgnClip) * nrectFill;
+    if (numRects > NUM_STACK_RECTS)
+    {
+       pboxClippedBase = (BoxPtr)ALLOCATE_LOCAL(numRects * sizeof(BoxRec));
+       if (!pboxClippedBase)
+           return;
+    }
+    else
+       pboxClippedBase = stackRects;
+
+    pboxClipped = pboxClippedBase;
+       
+    if (REGION_NUM_RECTS(prgnClip) == 1)
+    {
+       int x1, y1, x2, y2, bx2, by2;
+
+       pextent = REGION_RECTS(prgnClip);
+       x1 = pextent->x1;
+       y1 = pextent->y1;
+       x2 = pextent->x2;
+       y2 = pextent->y2;
+       while (nrectFill--)
+       {
+           if ((pboxClipped->x1 = prect->x) < x1)
+               pboxClipped->x1 = x1;
+    
+           if ((pboxClipped->y1 = prect->y) < y1)
+               pboxClipped->y1 = y1;
+    
+           bx2 = (int) prect->x + (int) prect->width;
+           if (bx2 > x2)
+               bx2 = x2;
+           pboxClipped->x2 = bx2;
+    
+           by2 = (int) prect->y + (int) prect->height;
+           if (by2 > y2)
+               by2 = y2;
+           pboxClipped->y2 = by2;
+
+           prect++;
+           if ((pboxClipped->x1 < pboxClipped->x2) &&
+               (pboxClipped->y1 < pboxClipped->y2))
+           {
+               pboxClipped++;
+           }
+       }
+    }
+    else
+    {
+       int x1, y1, x2, y2, bx2, by2;
+
+       pextent = REGION_EXTENTS(pGC->pScreen, prgnClip);
+       x1 = pextent->x1;
+       y1 = pextent->y1;
+       x2 = pextent->x2;
+       y2 = pextent->y2;
+       while (nrectFill--)
+       {
+           BoxRec box;
+    
+           if ((box.x1 = prect->x) < x1)
+               box.x1 = x1;
+    
+           if ((box.y1 = prect->y) < y1)
+               box.y1 = y1;
+    
+           bx2 = (int) prect->x + (int) prect->width;
+           if (bx2 > x2)
+               bx2 = x2;
+           box.x2 = bx2;
+    
+           by2 = (int) prect->y + (int) prect->height;
+           if (by2 > y2)
+               by2 = y2;
+           box.y2 = by2;
+    
+           prect++;
+    
+           if ((box.x1 >= box.x2) || (box.y1 >= box.y2))
+               continue;
+    
+           n = REGION_NUM_RECTS (prgnClip);
+           pbox = REGION_RECTS(prgnClip);
+    
+           /* clip the rectangle to each box in the clip region
+              this is logically equivalent to calling Intersect()
+           */
+           while(n--)
+           {
+               pboxClipped->x1 = max(box.x1, pbox->x1);
+               pboxClipped->y1 = max(box.y1, pbox->y1);
+               pboxClipped->x2 = min(box.x2, pbox->x2);
+               pboxClipped->y2 = min(box.y2, pbox->y2);
+               pbox++;
+
+               /* see if clipping left anything */
+               if(pboxClipped->x1 < pboxClipped->x2 && 
+                  pboxClipped->y1 < pboxClipped->y2)
+               {
+                   pboxClipped++;
+               }
+           }
+       }
+    }
+    if (pboxClipped != pboxClippedBase)
+       (*pfn) (pDrawable,pboxClipped-pboxClippedBase, pboxClippedBase, alu, ppix);
+    if (pboxClippedBase != stackRects)
+       DEALLOCATE_LOCAL(pboxClippedBase);
+}
diff --git a/Xserver/programs/Xserver/mfb/mfbfillsp.c b/Xserver/programs/Xserver/mfb/mfbfillsp.c
new file mode 100644 (file)
index 0000000..4b6b78b
--- /dev/null
@@ -0,0 +1,1025 @@
+/* Combined Purdue/PurduePlus patches, level 2.0, 1/17/89 */
+/***********************************************************
+
+Copyright (c) 1987  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+
+Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
+
+                        All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and its 
+documentation for any purpose and without fee is hereby granted, 
+provided that the above copyright notice appear in all copies and that
+both that copyright notice and this permission notice appear in 
+supporting documentation, and that the name of Digital not be
+used in advertising or publicity pertaining to distribution of the
+software without specific, written prior permission.  
+
+DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
+ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
+DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
+ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+SOFTWARE.
+
+******************************************************************/
+/* $XConsortium: mfbfillsp.c,v 5.13 94/04/17 20:28:21 dpw Exp $ */
+#include "X.h"
+#include "Xmd.h"
+#include "gcstruct.h"
+#include "window.h"
+#include "pixmapstr.h"
+#include "scrnintstr.h"
+#include "windowstr.h"
+#include "mfb.h"
+#include "maskbits.h"
+
+#include "mergerop.h"
+
+#include "servermd.h"
+#include "mi.h"
+#include "mispans.h"
+
+/* scanline filling for monochrome frame buffer
+   written by drewry, oct 1986
+
+   these routines all clip.  they assume that anything that has called
+them has already translated the points (i.e. pGC->miTranslate is
+non-zero, which is howit gets set in mfbCreateGC().)
+
+   the number of new scnalines created by clipping ==
+MaxRectsPerBand * nSpans.
+
+    FillSolid is overloaded to be used for OpaqueStipple as well,
+if fgPixel == bgPixel.  
+
+
+    FillTiled is overloaded to be used for OpaqueStipple, if
+fgPixel != bgPixel.  based on the fill style, it uses
+{RotatedPixmap, gc.alu} or {RotatedPixmap, PrivGC.ropOpStip}
+*/
+
+
+void
+mfbBlackSolidFS(pDrawable, pGC, nInit, pptInit, pwidthInit, fSorted)
+    DrawablePtr pDrawable;
+    GCPtr      pGC;
+    int                nInit;          /* number of spans to fill */
+    DDXPointPtr pptInit;       /* pointer to list of start points */
+    int                *pwidthInit;    /* pointer to list of n widths */
+    int        fSorted;
+{
+                               /* next three parameters are post-clip */
+    int n;                     /* number of spans to fill */
+    register DDXPointPtr ppt;  /* pointer to list of start points */
+    register int *pwidth;      /* pointer to list of n widths */
+    PixelType *addrlBase;      /* pointer to start of bitmap */
+    int nlwidth;               /* width in longwords of bitmap */
+    register PixelType *addrl;/* pointer to current longword in bitmap */
+    register int nlmiddle;
+    register PixelType startmask;
+    register PixelType endmask;
+    int *pwidthFree;           /* copies of the pointers to free */
+    DDXPointPtr pptFree;
+
+    if (!(pGC->planemask & 1))
+       return;
+
+    n = nInit * miFindMaxBand(((mfbPrivGC *)(pGC->devPrivates[mfbGCPrivateIndex].ptr))->pCompositeClip);
+    pwidthFree = (int *)ALLOCATE_LOCAL(n * sizeof(int));
+    pptFree = (DDXPointRec *)ALLOCATE_LOCAL(n * sizeof(DDXPointRec));
+    if(!pptFree || !pwidthFree)
+    {
+       if (pptFree) DEALLOCATE_LOCAL(pptFree);
+       if (pwidthFree) DEALLOCATE_LOCAL(pwidthFree);
+       return;
+    }
+    pwidth = pwidthFree;
+    ppt = pptFree;
+    n = miClipSpans(((mfbPrivGC *)(pGC->devPrivates[mfbGCPrivateIndex].ptr))->pCompositeClip,
+                   pptInit, pwidthInit, nInit,
+                   ppt, pwidth, fSorted);
+
+    mfbGetPixelWidthAndPointer(pDrawable, nlwidth, addrlBase);
+
+    while (n--)
+    {
+        addrl = mfbScanline(addrlBase, ppt->x, ppt->y, nlwidth);
+
+       if (*pwidth)
+       {
+           if ( ((ppt->x & PIM) + *pwidth) < PPW)
+           {
+               /* all bits inside same longword */
+               maskpartialbits(ppt->x, *pwidth, startmask);
+                   *addrl &= ~startmask;
+           }
+           else
+           {
+               maskbits(ppt->x, *pwidth, startmask, endmask, nlmiddle);
+               if (startmask)
+                   *addrl++ &= ~startmask;
+               Duff (nlmiddle, *addrl++ = 0x0);
+               if (endmask)
+                   *addrl &= ~endmask;
+           }
+       }
+       pwidth++;
+       ppt++;
+    }
+    DEALLOCATE_LOCAL(pptFree);
+    DEALLOCATE_LOCAL(pwidthFree);
+}
+
+
+
+void
+mfbWhiteSolidFS(pDrawable, pGC, nInit, pptInit, pwidthInit, fSorted)
+    DrawablePtr pDrawable;
+    GCPtr      pGC;
+    int                nInit;          /* number of spans to fill */
+    DDXPointPtr pptInit;       /* pointer to list of start points */
+    int                *pwidthInit;    /* pointer to list of n widths */
+    int        fSorted;
+{
+                               /* next three parameters are post-clip */
+    int n;                     /* number of spans to fill */
+    register DDXPointPtr ppt;  /* pointer to list of start points */
+    register int *pwidth;      /* pointer to list of n widths */
+    PixelType *addrlBase;      /* pointer to start of bitmap */
+    int nlwidth;               /* width in longwords of bitmap */
+    register PixelType *addrl;/* pointer to current longword in bitmap */
+    register int nlmiddle;
+    register PixelType startmask;
+    register PixelType endmask;
+    int *pwidthFree;           /* copies of the pointers to free */
+    DDXPointPtr pptFree;
+
+    if (!(pGC->planemask & 1))
+       return;
+
+    n = nInit * miFindMaxBand(((mfbPrivGC *)(pGC->devPrivates[mfbGCPrivateIndex].ptr))->pCompositeClip);
+    pwidthFree = (int *)ALLOCATE_LOCAL(n * sizeof(int));
+    pptFree = (DDXPointRec *)ALLOCATE_LOCAL(n * sizeof(DDXPointRec));
+    if(!pptFree || !pwidthFree)
+    {
+       if (pptFree) DEALLOCATE_LOCAL(pptFree);
+       if (pwidthFree) DEALLOCATE_LOCAL(pwidthFree);
+       return;
+    }
+    pwidth = pwidthFree;
+    ppt = pptFree;
+    n = miClipSpans(((mfbPrivGC *)(pGC->devPrivates[mfbGCPrivateIndex].ptr))->pCompositeClip,
+                   pptInit, pwidthInit, nInit,
+                   ppt, pwidth, fSorted);
+
+    mfbGetPixelWidthAndPointer(pDrawable, nlwidth, addrlBase);
+
+    while (n--)
+    {
+        addrl = mfbScanline(addrlBase, ppt->x, ppt->y, nlwidth);
+
+       if (*pwidth)
+       {
+           if ( ((ppt->x & PIM) + *pwidth) < PPW)
+           {
+               /* all bits inside same longword */
+               maskpartialbits(ppt->x, *pwidth, startmask);
+               *addrl |= startmask;
+           }
+           else
+           {
+               maskbits(ppt->x, *pwidth, startmask, endmask, nlmiddle);
+               if (startmask)
+                   *addrl++ |= startmask;
+               Duff (nlmiddle, *addrl++ = ~0);
+               if (endmask)
+                   *addrl |= endmask;
+           }
+       }
+       pwidth++;
+       ppt++;
+    }
+    DEALLOCATE_LOCAL(pptFree);
+    DEALLOCATE_LOCAL(pwidthFree);
+}
+
+
+
+void
+mfbInvertSolidFS(pDrawable, pGC, nInit, pptInit, pwidthInit, fSorted)
+    DrawablePtr pDrawable;
+    GCPtr      pGC;
+    int                nInit;          /* number of spans to fill */
+    DDXPointPtr pptInit;       /* pointer to list of start points */
+    int                *pwidthInit;    /* pointer to list of n widths */
+    int        fSorted;
+{
+                               /* next three parameters are post-clip */
+    int n;                     /* number of spans to fill */
+    register DDXPointPtr ppt;  /* pointer to list of start points */
+    register int *pwidth;      /* pointer to list of n widths */
+    PixelType *addrlBase;      /* pointer to start of bitmap */
+    int nlwidth;               /* width in longwords of bitmap */
+    register PixelType *addrl;/* pointer to current longword in bitmap */
+    register int nlmiddle;
+    register PixelType startmask;
+    register PixelType endmask;
+    int *pwidthFree;           /* copies of the pointers to free */
+    DDXPointPtr pptFree;
+
+    if (!(pGC->planemask & 1))
+       return;
+
+    n = nInit * miFindMaxBand(((mfbPrivGC *)(pGC->devPrivates[mfbGCPrivateIndex].ptr))->pCompositeClip);
+    pwidthFree = (int *)ALLOCATE_LOCAL(n * sizeof(int));
+    pptFree = (DDXPointRec *)ALLOCATE_LOCAL(n * sizeof(DDXPointRec));
+    if(!pptFree || !pwidthFree)
+    {
+       if (pptFree) DEALLOCATE_LOCAL(pptFree);
+       if (pwidthFree) DEALLOCATE_LOCAL(pwidthFree);
+       return;
+    }
+    pwidth = pwidthFree;
+    ppt = pptFree;
+    n = miClipSpans(((mfbPrivGC *)(pGC->devPrivates[mfbGCPrivateIndex].ptr))->pCompositeClip,
+                   pptInit, pwidthInit, nInit,
+                   ppt, pwidth, fSorted);
+
+    mfbGetPixelWidthAndPointer(pDrawable, nlwidth, addrlBase);
+
+    while (n--)
+    {
+        addrl = mfbScanline(addrlBase, ppt->x, ppt->y, nlwidth);
+
+       if (*pwidth)
+       {
+           if ( ((ppt->x & PIM) + *pwidth) < PPW)
+           {
+               /* all bits inside same longword */
+               maskpartialbits(ppt->x, *pwidth, startmask);
+               *addrl ^= startmask;
+           }
+           else
+           {
+               maskbits(ppt->x, *pwidth, startmask, endmask, nlmiddle);
+               if (startmask)
+                   *addrl++ ^= startmask;
+               Duff (nlmiddle, *addrl++ ^= ~0);
+               if (endmask)
+                   *addrl ^= endmask;
+           }
+       }
+       pwidth++;
+       ppt++;
+    }
+    DEALLOCATE_LOCAL(pptFree);
+    DEALLOCATE_LOCAL(pwidthFree);
+}
+
+
+void 
+mfbWhiteStippleFS(pDrawable, pGC, nInit, pptInit, pwidthInit, fSorted)
+    DrawablePtr pDrawable;
+    GC *pGC;
+    int nInit;                 /* number of spans to fill */
+    DDXPointPtr pptInit;       /* pointer to list of start points */
+    int *pwidthInit;           /* pointer to list of n widths */
+    int fSorted;
+{
+                               /* next three parameters are post-clip */
+    int n;                     /* number of spans to fill */
+    register DDXPointPtr ppt;  /* pointer to list of start points */
+    register int *pwidth;      /* pointer to list of n widths */
+    PixelType *addrlBase;      /* pointer to start of bitmap */
+    int nlwidth;               /* width in longwords of bitmap */
+    register PixelType *addrl;/* pointer to current longword in bitmap */
+    register PixelType src;
+    register int nlmiddle;
+    register PixelType startmask;
+    register PixelType endmask;
+    PixmapPtr pStipple;
+    PixelType *psrc;
+    int tileHeight;
+    int *pwidthFree;           /* copies of the pointers to free */
+    DDXPointPtr pptFree;
+
+    if (!(pGC->planemask & 1))
+       return;
+
+    n = nInit * miFindMaxBand(((mfbPrivGC *)(pGC->devPrivates[mfbGCPrivateIndex].ptr))->pCompositeClip);
+    pwidthFree = (int *)ALLOCATE_LOCAL(n * sizeof(int));
+    pptFree = (DDXPointRec *)ALLOCATE_LOCAL(n * sizeof(DDXPointRec));
+    if(!pptFree || !pwidthFree)
+    {
+       if (pptFree) DEALLOCATE_LOCAL(pptFree);
+       if (pwidthFree) DEALLOCATE_LOCAL(pwidthFree);
+       return;
+    }
+    pwidth = pwidthFree;
+    ppt = pptFree;
+    n = miClipSpans(((mfbPrivGC *)(pGC->devPrivates[mfbGCPrivateIndex].ptr))->pCompositeClip,
+                   pptInit, pwidthInit, nInit, 
+                   ppt, pwidth, fSorted);
+
+    mfbGetPixelWidthAndPointer(pDrawable, nlwidth, addrlBase);
+
+    pStipple = ((mfbPrivGC *)(pGC->devPrivates[mfbGCPrivateIndex].ptr))->pRotatedPixmap;
+    tileHeight = pStipple->drawable.height;
+    psrc = (PixelType *)(pStipple->devPrivate.ptr);
+
+    while (n--)
+    {
+        addrl = mfbScanline(addrlBase, ppt->x, ppt->y, nlwidth);
+       src = psrc[ppt->y % tileHeight];
+
+        /* all bits inside same longword */
+        if ( ((ppt->x & PIM) + *pwidth) < PPW)
+        {
+           maskpartialbits(ppt->x, *pwidth, startmask);
+           *addrl |= (src & startmask);
+        }
+        else
+        {
+           maskbits(ppt->x, *pwidth, startmask, endmask, nlmiddle);
+           if (startmask)
+               *addrl++ |= (src & startmask);
+           Duff (nlmiddle, *addrl++ |= src);
+           if (endmask)
+               *addrl |= (src & endmask);
+        }
+       pwidth++;
+       ppt++;
+    }
+    DEALLOCATE_LOCAL(pptFree);
+    DEALLOCATE_LOCAL(pwidthFree);
+}
+
+
+void 
+mfbBlackStippleFS(pDrawable, pGC, nInit, pptInit, pwidthInit, fSorted)
+    DrawablePtr pDrawable;
+    GC *pGC;
+    int nInit;                 /* number of spans to fill */
+    DDXPointPtr pptInit;       /* pointer to list of start points */
+    int *pwidthInit;           /* pointer to list of n widths */
+    int fSorted;
+{
+                               /* next three parameters are post-clip */
+    int n;                     /* number of spans to fill */
+    register DDXPointPtr ppt;  /* pointer to list of start points */
+    register int *pwidth;      /* pointer to list of n widths */
+    PixelType *addrlBase;      /* pointer to start of bitmap */
+    int nlwidth;               /* width in longwords of bitmap */
+    register PixelType *addrl; /* pointer to current longword in bitmap */
+    register PixelType src;
+    register int nlmiddle;
+    register PixelType startmask;
+    register PixelType endmask;
+    PixmapPtr pStipple;
+    PixelType *psrc;
+    int tileHeight;
+    int *pwidthFree;           /* copies of the pointers to free */
+    DDXPointPtr pptFree;
+
+    if (!(pGC->planemask & 1))
+       return;
+
+    n = nInit * miFindMaxBand(((mfbPrivGC *)(pGC->devPrivates[mfbGCPrivateIndex].ptr))->pCompositeClip);
+    pwidthFree = (int *)ALLOCATE_LOCAL(n * sizeof(int));
+    pptFree = (DDXPointRec *)ALLOCATE_LOCAL(n * sizeof(DDXPointRec));
+    if(!pptFree || !pwidthFree)
+    {
+       if (pptFree) DEALLOCATE_LOCAL(pptFree);
+       if (pwidthFree) DEALLOCATE_LOCAL(pwidthFree);
+       return;
+    }
+    pwidth = pwidthFree;
+    ppt = pptFree;
+    n = miClipSpans(((mfbPrivGC *)(pGC->devPrivates[mfbGCPrivateIndex].ptr))->pCompositeClip,
+                   pptInit, pwidthInit, nInit, 
+                   ppt, pwidth, fSorted);
+
+    mfbGetPixelWidthAndPointer(pDrawable, nlwidth, addrlBase);
+
+    pStipple = ((mfbPrivGC *)(pGC->devPrivates[mfbGCPrivateIndex].ptr))->pRotatedPixmap;
+    tileHeight = pStipple->drawable.height;
+    psrc = (PixelType *)(pStipple->devPrivate.ptr);
+
+    while (n--)
+    {
+        addrl = mfbScanline(addrlBase, ppt->x, ppt->y, nlwidth);
+       src = psrc[ppt->y % tileHeight];
+
+        /* all bits inside same longword */
+        if ( ((ppt->x & PIM) + *pwidth) < PPW)
+        {
+           maskpartialbits(ppt->x, *pwidth, startmask);
+           *addrl &= ~(src & startmask);
+        }
+        else
+        {
+           maskbits(ppt->x, *pwidth, startmask, endmask, nlmiddle);
+           if (startmask)
+               *addrl++ &= ~(src & startmask);
+           Duff (nlmiddle, *addrl++ &= ~src);
+           if (endmask)
+               *addrl &= ~(src & endmask);
+        }
+       pwidth++;
+       ppt++;
+    }
+    DEALLOCATE_LOCAL(pptFree);
+    DEALLOCATE_LOCAL(pwidthFree);
+}
+
+
+void 
+mfbInvertStippleFS(pDrawable, pGC, nInit, pptInit, pwidthInit, fSorted)
+    DrawablePtr pDrawable;
+    GC *pGC;
+    int nInit;                 /* number of spans to fill */
+    DDXPointPtr pptInit;       /* pointer to list of start points */
+    int *pwidthInit;           /* pointer to list of n widths */
+    int fSorted;
+{
+                               /* next three parameters are post-clip */
+    int n;                     /* number of spans to fill */
+    register DDXPointPtr ppt;  /* pointer to list of start points */
+    register int *pwidth;      /* pointer to list of n widths */
+    PixelType *addrlBase;      /* pointer to start of bitmap */
+    int nlwidth;               /* width in longwords of bitmap */
+    register PixelType *addrl; /* pointer to current longword in bitmap */
+    register PixelType src;
+    register int nlmiddle;
+    register PixelType startmask;
+    register PixelType endmask;
+    PixmapPtr pStipple;
+    PixelType *psrc;
+    int tileHeight;
+    int *pwidthFree;           /* copies of the pointers to free */
+    DDXPointPtr pptFree;
+
+    if (!(pGC->planemask & 1))
+       return;
+
+    n = nInit * miFindMaxBand(((mfbPrivGC *)(pGC->devPrivates[mfbGCPrivateIndex].ptr))->pCompositeClip);
+    pwidthFree = (int *)ALLOCATE_LOCAL(n * sizeof(int));
+    pptFree = (DDXPointRec *)ALLOCATE_LOCAL(n * sizeof(DDXPointRec));
+    if(!pptFree || !pwidthFree)
+    {
+       if (pptFree) DEALLOCATE_LOCAL(pptFree);
+       if (pwidthFree) DEALLOCATE_LOCAL(pwidthFree);
+       return;
+    }
+    pwidth = pwidthFree;
+    ppt = pptFree;
+    n = miClipSpans(((mfbPrivGC *)(pGC->devPrivates[mfbGCPrivateIndex].ptr))->pCompositeClip,
+                   pptInit, pwidthInit, nInit, 
+                   ppt, pwidth, fSorted);
+
+    mfbGetPixelWidthAndPointer(pDrawable, nlwidth, addrlBase);
+
+    pStipple = ((mfbPrivGC *)(pGC->devPrivates[mfbGCPrivateIndex].ptr))->pRotatedPixmap;
+    tileHeight = pStipple->drawable.height;
+    psrc = (PixelType *)(pStipple->devPrivate.ptr);
+
+    while (n--)
+    {
+        addrl = mfbScanline(addrlBase, ppt->x, ppt->y, nlwidth);
+       src = psrc[ppt->y % tileHeight];
+
+        /* all bits inside same longword */
+        if ( ((ppt->x & PIM) + *pwidth) < PPW)
+        {
+           maskpartialbits(ppt->x, *pwidth, startmask);
+           *addrl ^= (src & startmask);
+        }
+        else
+        {
+           maskbits(ppt->x, *pwidth, startmask, endmask, nlmiddle);
+           if (startmask)
+               *addrl++ ^= (src & startmask);
+           Duff(nlmiddle, *addrl++ ^= src);
+           if (endmask)
+               *addrl ^= (src & endmask);
+        }
+       pwidth++;
+       ppt++;
+    }
+    DEALLOCATE_LOCAL(pptFree);
+    DEALLOCATE_LOCAL(pwidthFree);
+}
+
+
+/* this works with tiles of width == PPW */
+#define FILLSPANPPW(ROP) \
+    while (n--) \
+    { \
+       if (*pwidth) \
+       { \
+            addrl = mfbScanline(addrlBase, ppt->x, ppt->y, nlwidth); \
+           src = psrc[ppt->y % tileHeight]; \
+            if ( ((ppt->x & PIM) + *pwidth) < PPW) \
+            { \
+               maskpartialbits(ppt->x, *pwidth, startmask); \
+               *addrl = (*addrl & ~startmask) | \
+                        (ROP(src, *addrl) & startmask); \
+            } \
+            else \
+            { \
+               maskbits(ppt->x, *pwidth, startmask, endmask, nlmiddle); \
+               if (startmask) \
+               { \
+                   *addrl = (*addrl & ~startmask) | \
+                            (ROP(src, *addrl) & startmask); \
+                   addrl++; \
+               } \
+               while (nlmiddle--) \
+               { \
+                   *addrl = ROP(src, *addrl); \
+                   addrl++; \
+               } \
+               if (endmask) \
+                   *addrl = (*addrl & ~endmask) | \
+                            (ROP(src, *addrl) & endmask); \
+            } \
+       } \
+       pwidth++; \
+       ppt++; \
+    }
+
+
+
+void
+mfbTileFS(pDrawable, pGC, nInit, pptInit, pwidthInit, fSorted)
+    DrawablePtr pDrawable;
+    GC *pGC;
+    int nInit;                 /* number of spans to fill */
+    DDXPointPtr pptInit;       /* pointer to list of start points */
+    int *pwidthInit;           /* pointer to list of n widths */
+    int fSorted;
+{
+                               /* next three parameters are post-clip */
+    int n;                     /* number of spans to fill */
+    register DDXPointPtr ppt;  /* pointer to list of start points */
+    register int *pwidth;      /* pointer to list of n widths */
+    PixelType *addrlBase;      /* pointer to start of bitmap */
+    int nlwidth;               /* width in longwords of bitmap */
+    register PixelType *addrl; /* pointer to current longword in bitmap */
+    register PixelType src;
+    register int nlmiddle;
+    register PixelType startmask;
+    register PixelType endmask;
+    PixmapPtr pTile;
+    PixelType *psrc;
+    int tileHeight;
+    int rop;
+    int *pwidthFree;           /* copies of the pointers to free */
+    DDXPointPtr pptFree;
+    unsigned long   flip;
+
+
+    if (!(pGC->planemask & 1))
+       return;
+
+    n = nInit * miFindMaxBand(((mfbPrivGC *)(pGC->devPrivates[mfbGCPrivateIndex].ptr))->pCompositeClip);
+    pwidthFree = (int *)ALLOCATE_LOCAL(n * sizeof(int));
+    pptFree = (DDXPointRec *)ALLOCATE_LOCAL(n * sizeof(DDXPointRec));
+    if(!pptFree || !pwidthFree)
+    {
+       if (pptFree) DEALLOCATE_LOCAL(pptFree);
+       if (pwidthFree) DEALLOCATE_LOCAL(pwidthFree);
+       return;
+    }
+    pwidth = pwidthFree;
+    ppt = pptFree;
+    n = miClipSpans(((mfbPrivGC *)(pGC->devPrivates[mfbGCPrivateIndex].ptr))->pCompositeClip,
+                   pptInit, pwidthInit, nInit, 
+                   ppt, pwidth, fSorted);
+
+    mfbGetPixelWidthAndPointer(pDrawable, nlwidth, addrlBase);
+
+    pTile = ((mfbPrivGC *)(pGC->devPrivates[mfbGCPrivateIndex].ptr))->pRotatedPixmap;
+    tileHeight = pTile->drawable.height;
+    psrc = (PixelType *)(pTile->devPrivate.ptr);
+    if (pGC->fillStyle == FillTiled)
+       rop = pGC->alu;
+    else
+       rop = ((mfbPrivGC *)(pGC->devPrivates[mfbGCPrivateIndex].ptr))->ropOpStip;
+
+    flip = 0;
+    switch(rop)
+    {
+      case GXcopyInverted:  /* for opaque stipples */
+       flip = ~0;
+      case GXcopy:
+       {
+
+#define DoMaskCopyRop(src,dst,mask)    ((dst) & ~(mask) | (src) & (mask))
+
+           while (n--)
+           {
+               if (*pwidth)
+               {
+                   addrl = mfbScanline(addrlBase, ppt->x, ppt->y, nlwidth);
+                   src = psrc[ppt->y % tileHeight] ^ flip;
+                   if ( ((ppt->x & PIM) + *pwidth) < PPW)
+                   {
+                       maskpartialbits(ppt->x, *pwidth, startmask);
+                       *addrl = DoMaskCopyRop (src, *addrl, startmask);
+                   }
+                   else
+                   {
+                       maskbits(ppt->x, *pwidth, startmask, endmask, nlmiddle);
+                       if (startmask)
+                       {
+                           *addrl = DoMaskCopyRop (src, *addrl, startmask);
+                           addrl++;
+                       }
+                       while (nlmiddle--)
+                       {
+                           *addrl = src;
+                           addrl++;
+                       }
+                       if (endmask)
+                           *addrl = DoMaskCopyRop (src, *addrl, endmask);
+                   }
+               }
+               pwidth++;
+               ppt++;
+           }
+       }
+       break;
+      default:
+       {
+           register DeclareMergeRop ();
+
+           InitializeMergeRop(rop,~0);
+           while (n--)
+           {
+               if (*pwidth)
+               {
+                   addrl = mfbScanline(addrlBase, ppt->x, ppt->y, nlwidth);
+                   src = psrc[ppt->y % tileHeight];
+                   if ( ((ppt->x & PIM) + *pwidth) < PPW)
+                   {
+                       maskpartialbits(ppt->x, *pwidth, startmask);
+                       *addrl = DoMaskMergeRop (src, *addrl, startmask);
+                   }
+                   else
+                   {
+                       maskbits(ppt->x, *pwidth, startmask, endmask, nlmiddle);
+                       if (startmask)
+                       {
+                           *addrl = DoMaskMergeRop (src, *addrl, startmask);
+                           addrl++;
+                       }
+                       while (nlmiddle--)
+                       {
+                           *addrl = DoMergeRop (src, *addrl);
+                           addrl++;
+                       }
+                       if (endmask)
+                           *addrl = DoMaskMergeRop (src, *addrl, endmask);
+                   }
+               }
+               pwidth++;
+               ppt++;
+           }
+       }
+       break;
+    }
+    DEALLOCATE_LOCAL(pptFree);
+    DEALLOCATE_LOCAL(pwidthFree);
+}
+
+
+/* Fill spans with tiles that aren't PPW bits wide */
+void
+mfbUnnaturalTileFS(pDrawable, pGC, nInit, pptInit, pwidthInit, fSorted)
+    DrawablePtr pDrawable;
+    GC         *pGC;
+    int                nInit;          /* number of spans to fill */
+    DDXPointPtr pptInit;       /* pointer to list of start points */
+    int *pwidthInit;           /* pointer to list of n widths */
+    int fSorted;
+{
+    int                iline;          /* first line of tile to use */
+                               /* next three parameters are post-clip */
+    int n;                     /* number of spans to fill */
+    register DDXPointPtr ppt;  /* pointer to list of start points */
+    register int *pwidth;      /* pointer to list of n widths */
+    PixelType *addrlBase;      /* pointer to start of bitmap */
+    int                 nlwidth;       /* width in longwords of bitmap */
+    register PixelType *pdst;/* pointer to current word in bitmap */
+    register PixelType *psrc;/* pointer to current word in tile */
+    register int nlMiddle;
+    register int rop, nstart;
+    PixelType startmask;
+    PixmapPtr  pTile;          /* pointer to tile we want to fill with */
+    int                w, width, x, xSrc, ySrc, srcStartOver, nend;
+    int        tlwidth, rem, tileWidth, tileHeight, endinc;
+    PixelType      endmask, *psrcT;
+    int *pwidthFree;           /* copies of the pointers to free */
+    DDXPointPtr pptFree;
+
+    if (!(pGC->planemask & 1))
+       return;
+
+    n = nInit * miFindMaxBand(((mfbPrivGC *)(pGC->devPrivates[mfbGCPrivateIndex].ptr))->pCompositeClip);
+    pwidthFree = (int *)ALLOCATE_LOCAL(n * sizeof(int));
+    pptFree = (DDXPointRec *)ALLOCATE_LOCAL(n * sizeof(DDXPointRec));
+    if(!pptFree || !pwidthFree)
+    {
+       if (pptFree) DEALLOCATE_LOCAL(pptFree);
+       if (pwidthFree) DEALLOCATE_LOCAL(pwidthFree);
+       return;
+    }
+    pwidth = pwidthFree;
+    ppt = pptFree;
+    n = miClipSpans(((mfbPrivGC *)(pGC->devPrivates[mfbGCPrivateIndex].ptr))->pCompositeClip,
+                   pptInit, pwidthInit, nInit, 
+                   ppt, pwidth, fSorted);
+
+    if (pGC->fillStyle == FillTiled)
+    {
+       pTile = pGC->tile.pixmap;
+       tlwidth = pTile->devKind / PGSZB;
+       rop = pGC->alu;
+    }
+    else
+    {
+       pTile = pGC->stipple;
+       tlwidth = pTile->devKind / PGSZB;
+       rop = ((mfbPrivGC *)(pGC->devPrivates[mfbGCPrivateIndex].ptr))->ropOpStip;
+    }
+
+    xSrc = pDrawable->x;
+    ySrc = pDrawable->y;
+
+    mfbGetPixelWidthAndPointer(pDrawable, nlwidth, addrlBase);
+
+    tileWidth = pTile->drawable.width;
+    tileHeight = pTile->drawable.height;
+
+    /* this replaces rotating the tile. Instead we just adjust the offset
+     * at which we start grabbing bits from the tile.
+     * Ensure that ppt->x - xSrc >= 0 and ppt->y - ySrc >= 0,
+     * so that iline and rem always stay within the tile bounds.
+     */
+    xSrc += (pGC->patOrg.x % tileWidth) - tileWidth;
+    ySrc += (pGC->patOrg.y % tileHeight) - tileHeight;
+
+    while (n--)
+    {
+       iline = (ppt->y - ySrc) % tileHeight;
+        pdst = mfbScanline(addrlBase, ppt->x, ppt->y, nlwidth);
+        psrcT = (PixelType *) pTile->devPrivate.ptr + (iline * tlwidth);
+       x = ppt->x;
+
+       if (*pwidth)
+       {
+           width = *pwidth;
+           while(width > 0)
+           {
+               psrc = psrcT;
+               w = min(tileWidth, width);
+               if((rem = (x - xSrc)  % tileWidth) != 0)
+               {
+                   /* if we're in the middle of the tile, get
+                      as many bits as will finish the span, or
+                      as many as will get to the left edge of the tile,
+                      or a longword worth, starting at the appropriate
+                      offset in the tile.
+                   */
+                   w = min(min(tileWidth - rem, width), BITMAP_SCANLINE_PAD);
+                   endinc = rem / BITMAP_SCANLINE_PAD;
+                   getandputrop((psrc+endinc), (rem&PIM), (x & PIM), w, pdst, rop);
+                   if((x & PIM) + w >= PPW)
+                       pdst++;
+               }
+               else if(((x & PIM) + w) < PPW)
+               {
+                   /* doing < PPW bits is easy, and worth special-casing */
+                   putbitsrop(*psrc, x & PIM, w, pdst, rop);
+               }
+               else
+               {
+                   /* start at the left edge of the tile,
+                      and put down as much as we can
+                   */
+                   maskbits(x, w, startmask, endmask, nlMiddle);
+
+                   if (startmask)
+                       nstart = PPW - (x & PIM);
+                   else
+                       nstart = 0;
+                   if (endmask)
+                       nend = (x + w)  & PIM;
+                   else
+                       nend = 0;
+
+                   srcStartOver = nstart > PLST;
+
+                   if(startmask)
+                   {
+                       putbitsrop(*psrc, (x & PIM), nstart, pdst, rop);
+                       pdst++;
+                       if(srcStartOver)
+                           psrc++;
+                   }
+                    
+                   while(nlMiddle--)
+                   {
+                           getandputrop0(psrc, nstart, PPW, pdst, rop);
+                           pdst++;
+                           psrc++;
+                   }
+                   if(endmask)
+                   {
+                       getandputrop0(psrc, nstart, nend, pdst, rop);
+                   }
+                }
+                x += w;
+                width -= w;
+           }
+       }
+       ppt++;
+       pwidth++;
+    }
+    DEALLOCATE_LOCAL(pptFree);
+    DEALLOCATE_LOCAL(pwidthFree);
+}
+
+
+/* Fill spans with stipples that aren't PPW bits wide */
+void
+mfbUnnaturalStippleFS(pDrawable, pGC, nInit, pptInit, pwidthInit, fSorted)
+    DrawablePtr pDrawable;
+    GC         *pGC;
+    int                nInit;          /* number of spans to fill */
+    DDXPointPtr pptInit;       /* pointer to list of start points */
+    int *pwidthInit;           /* pointer to list of n widths */
+    int fSorted;
+{
+                               /* next three parameters are post-clip */
+    int n;                     /* number of spans to fill */
+    register DDXPointPtr ppt;  /* pointer to list of start points */
+    register int *pwidth;      /* pointer to list of n widths */
+    int                iline;          /* first line of tile to use */
+    PixelType          *addrlBase;     /* pointer to start of bitmap */
+    int                 nlwidth;       /* width in longwords of bitmap */
+    register PixelType *pdst;          /* pointer to current word in bitmap */
+    register PixelType *psrc;          /* pointer to current word in tile */
+    register int nlMiddle;
+    register int rop, nstart;
+    PixelType startmask;
+    PixmapPtr  pTile;          /* pointer to tile we want to fill with */
+    int                w, width,  x, xSrc, ySrc, srcStartOver, nend;
+    PixelType  endmask, *psrcT;
+    int        tlwidth, rem, tileWidth, endinc;
+    int                tileHeight;
+    int *pwidthFree;           /* copies of the pointers to free */
+    DDXPointPtr pptFree;
+
+    if (!(pGC->planemask & 1))
+       return;
+
+    n = nInit * miFindMaxBand(((mfbPrivGC *)(pGC->devPrivates[mfbGCPrivateIndex].ptr))->pCompositeClip);
+    pwidthFree = (int *)ALLOCATE_LOCAL(n * sizeof(int));
+    pptFree = (DDXPointRec *)ALLOCATE_LOCAL(n * sizeof(DDXPointRec));
+    if(!pptFree || !pwidthFree)
+    {
+       if (pptFree) DEALLOCATE_LOCAL(pptFree);
+       if (pwidthFree) DEALLOCATE_LOCAL(pwidthFree);
+       return;
+    }
+    pwidth = pwidthFree;
+    ppt = pptFree;
+    n = miClipSpans(((mfbPrivGC *)(pGC->devPrivates[mfbGCPrivateIndex].ptr))->pCompositeClip,
+                   pptInit, pwidthInit, nInit, 
+                   ppt, pwidth, fSorted);
+
+    pTile = pGC->stipple;
+    rop = ((mfbPrivGC *)(pGC->devPrivates[mfbGCPrivateIndex].ptr))->rop;
+    tlwidth = pTile->devKind / PGSZB;
+    xSrc = pDrawable->x;
+    ySrc = pDrawable->y;
+    mfbGetPixelWidthAndPointer(pDrawable, nlwidth, addrlBase);
+
+    tileWidth = pTile->drawable.width;
+    tileHeight = pTile->drawable.height;
+
+    /* this replaces rotating the stipple.  Instead, we just adjust the offset
+     * at which we start grabbing bits from the stipple.
+     * Ensure that ppt->x - xSrc >= 0 and ppt->y - ySrc >= 0,
+     * so that iline and rem always stay within the tile bounds.
+     */
+    xSrc += (pGC->patOrg.x % tileWidth) - tileWidth;
+    ySrc += (pGC->patOrg.y % tileHeight) - tileHeight;
+    while (n--)
+    {
+       iline = (ppt->y - ySrc) % tileHeight;
+        pdst = mfbScanline(addrlBase, ppt->x, ppt->y, nlwidth);
+        psrcT = (PixelType *) pTile->devPrivate.ptr + (iline * tlwidth);
+       x = ppt->x;
+
+       if (*pwidth)
+       {
+           width = *pwidth;
+           while(width > 0)
+           {
+               psrc = psrcT;
+               w = min(tileWidth, width);
+               if((rem = (x - xSrc) % tileWidth) != 0)
+               {
+                   /* if we're in the middle of the tile, get
+                      as many bits as will finish the span, or
+                      as many as will get to the left edge of the tile,
+                      or a longword worth, starting at the appropriate
+                      offset in the tile.
+                   */
+                   w = min(min(tileWidth - rem, width), BITMAP_SCANLINE_PAD);
+                   endinc = rem / BITMAP_SCANLINE_PAD;
+                   getandputrrop((psrc + endinc), (rem & PIM), (x & PIM),
+                                w, pdst, rop)
+                   if((x & PIM) + w >= PPW)
+                       pdst++;
+               }
+
+               else if(((x & PIM) + w) < PPW)
+               {
+                   /* doing < PPW bits is easy, and worth special-casing */
+                   putbitsrrop(*psrc, x & PIM, w, pdst, rop);
+               }
+               else
+               {
+                   /* start at the left edge of the tile,
+                      and put down as much as we can
+                   */
+                   maskbits(x, w, startmask, endmask, nlMiddle);
+
+                   if (startmask)
+                       nstart = PPW - (x & PIM);
+                   else
+                       nstart = 0;
+                   if (endmask)
+                       nend = (x + w)  & PIM;
+                   else
+                       nend = 0;
+
+                   srcStartOver = nstart > PLST;
+
+                   if(startmask)
+                   {
+                       putbitsrrop(*psrc, (x & PIM), nstart, pdst, rop);
+                       pdst++;
+                       if(srcStartOver)
+                           psrc++;
+                   }
+                    
+                   while(nlMiddle--)
+                   {
+                           getandputrrop0(psrc, nstart, PPW, pdst, rop);
+                           pdst++;
+                           psrc++;
+                   }
+                   if(endmask)
+                   {
+                       getandputrrop0(psrc, nstart, nend, pdst, rop);
+                   }
+                }
+                x += w;
+                width -= w;
+           }
+       }
+       ppt++;
+       pwidth++;
+    }
+    DEALLOCATE_LOCAL(pptFree);
+    DEALLOCATE_LOCAL(pwidthFree);
+}
diff --git a/Xserver/programs/Xserver/mfb/mfbfont.c b/Xserver/programs/Xserver/mfb/mfbfont.c
new file mode 100644 (file)
index 0000000..ffa1db5
--- /dev/null
@@ -0,0 +1,73 @@
+/*
+
+Copyright (c) 1987  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+
+Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
+
+                        All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and its 
+documentation for any purpose and without fee is hereby granted, 
+provided that the above copyright notice appear in all copies and that
+both that copyright notice and this permission notice appear in 
+supporting documentation, and that the name of Digital not be
+used in advertising or publicity pertaining to distribution of the
+software without specific, written prior permission.  
+
+DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
+ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
+DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
+ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+SOFTWARE.
+
+*/
+/* $XConsortium: mfbfont.c,v 1.18 94/04/17 20:28:22 keith Exp $ */
+#include "X.h"
+#include "Xmd.h"
+#include "Xproto.h"
+#include "mfb.h"
+#include "fontstruct.h"
+#include "dixfontstr.h"
+#include "scrnintstr.h"
+
+/*ARGSUSED*/
+Bool
+mfbRealizeFont( pscr, pFont)
+    ScreenPtr  pscr;
+    FontPtr    pFont;
+{
+    return (TRUE);
+}
+
+/*ARGSUSED*/
+Bool
+mfbUnrealizeFont( pscr, pFont)
+    ScreenPtr  pscr;
+    FontPtr    pFont;
+{
+    return (TRUE);
+}
diff --git a/Xserver/programs/Xserver/mfb/mfbgc.c b/Xserver/programs/Xserver/mfb/mfbgc.c
new file mode 100644 (file)
index 0000000..72fbb11
--- /dev/null
@@ -0,0 +1,1086 @@
+/***********************************************************
+
+Copyright (c) 1987  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+
+Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
+
+                        All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and its 
+documentation for any purpose and without fee is hereby granted, 
+provided that the above copyright notice appear in all copies and that
+both that copyright notice and this permission notice appear in 
+supporting documentation, and that the name of Digital not be
+used in advertising or publicity pertaining to distribution of the
+software without specific, written prior permission.  
+
+DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
+ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
+DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
+ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+SOFTWARE.
+
+******************************************************************/
+/* $XConsortium: mfbgc.c,v 5.35 94/04/17 20:28:23 dpw Exp $ */
+#include "X.h"
+#include "Xmd.h"
+#include "Xproto.h"
+#include "mfb.h"
+#include "dixfontstr.h"
+#include "fontstruct.h"
+#include "gcstruct.h"
+#include "windowstr.h"
+#include "pixmapstr.h"
+#include "scrnintstr.h"
+#include "region.h"
+
+#include "mistruct.h"
+#include "migc.h"
+
+#include "maskbits.h"
+
+static GCFuncs mfbFuncs = {
+       mfbValidateGC,
+       miChangeGC,
+       miCopyGC,
+       miDestroyGC,
+       miChangeClip,
+       miDestroyClip,
+       miCopyClip
+};
+
+static GCOps   whiteTECopyOps = {
+       mfbWhiteSolidFS,
+       mfbSetSpans,
+       mfbPutImage,
+       mfbCopyArea,
+       mfbCopyPlane,
+       mfbPolyPoint,
+       mfbLineSS,
+       mfbSegmentSS,
+       miPolyRectangle,
+       mfbZeroPolyArcSS,
+       mfbFillPolyWhite,
+       mfbPolyFillRect,
+       mfbPolyFillArcSolid,
+       miPolyText8,
+       miPolyText16,
+       miImageText8,
+       miImageText16,
+       mfbTEGlyphBltWhite,
+       mfbPolyGlyphBltWhite,
+       mfbSolidPP
+#ifdef NEED_LINEHELPER
+       ,NULL
+#endif
+};
+
+static GCOps   blackTECopyOps = {
+       mfbBlackSolidFS,
+       mfbSetSpans,
+       mfbPutImage,
+       mfbCopyArea,
+       mfbCopyPlane,
+       mfbPolyPoint,
+       mfbLineSS,
+       mfbSegmentSS,
+       miPolyRectangle,
+       mfbZeroPolyArcSS,
+       mfbFillPolyBlack,
+       mfbPolyFillRect,
+       mfbPolyFillArcSolid,
+       miPolyText8,
+       miPolyText16,
+       miImageText8,
+       miImageText16,
+       mfbTEGlyphBltBlack,
+       mfbPolyGlyphBltBlack,
+       mfbSolidPP
+#ifdef NEED_LINEHELPER
+       ,NULL
+#endif
+};
+
+static GCOps   whiteTEInvertOps = {
+       mfbInvertSolidFS,
+       mfbSetSpans,
+       mfbPutImage,
+       mfbCopyArea,
+       mfbCopyPlane,
+       mfbPolyPoint,
+       mfbLineSS,
+       mfbSegmentSS,
+       miPolyRectangle,
+       miZeroPolyArc,
+       mfbFillPolyInvert,
+       mfbPolyFillRect,
+       mfbPolyFillArcSolid,
+       miPolyText8,
+       miPolyText16,
+       miImageText8,
+       miImageText16,
+       mfbTEGlyphBltWhite,
+       mfbPolyGlyphBltInvert,
+       mfbSolidPP
+#ifdef NEED_LINEHELPER
+       ,NULL
+#endif
+};
+
+static GCOps   blackTEInvertOps = {
+       mfbInvertSolidFS,
+       mfbSetSpans,
+       mfbPutImage,
+       mfbCopyArea,
+       mfbCopyPlane,
+       mfbPolyPoint,
+       mfbLineSS,
+       mfbSegmentSS,
+       miPolyRectangle,
+       miZeroPolyArc,
+       mfbFillPolyInvert,
+       mfbPolyFillRect,
+       mfbPolyFillArcSolid,
+       miPolyText8,
+       miPolyText16,
+       miImageText8,
+       miImageText16,
+       mfbTEGlyphBltBlack,
+       mfbPolyGlyphBltInvert,
+       mfbSolidPP
+#ifdef NEED_LINEHELPER
+       ,NULL
+#endif
+};
+
+static GCOps   whiteCopyOps = {
+       mfbWhiteSolidFS,
+       mfbSetSpans,
+       mfbPutImage,
+       mfbCopyArea,
+       mfbCopyPlane,
+       mfbPolyPoint,
+       mfbLineSS,
+       mfbSegmentSS,
+       miPolyRectangle,
+       mfbZeroPolyArcSS,
+       mfbFillPolyWhite,
+       mfbPolyFillRect,
+       mfbPolyFillArcSolid,
+       miPolyText8,
+       miPolyText16,
+       miImageText8,
+       miImageText16,
+       mfbImageGlyphBltWhite,
+       mfbPolyGlyphBltWhite,
+       mfbSolidPP
+#ifdef NEED_LINEHELPER
+       ,NULL
+#endif
+};
+
+static GCOps   blackCopyOps = {
+       mfbBlackSolidFS,
+       mfbSetSpans,
+       mfbPutImage,
+       mfbCopyArea,
+       mfbCopyPlane,
+       mfbPolyPoint,
+       mfbLineSS,
+       mfbSegmentSS,
+       miPolyRectangle,
+       mfbZeroPolyArcSS,
+       mfbFillPolyBlack,
+       mfbPolyFillRect,
+       mfbPolyFillArcSolid,
+       miPolyText8,
+       miPolyText16,
+       miImageText8,
+       miImageText16,
+       mfbImageGlyphBltBlack,
+       mfbPolyGlyphBltBlack,
+       mfbSolidPP
+#ifdef NEED_LINEHELPER
+       ,NULL
+#endif
+};
+
+static GCOps   whiteInvertOps = {
+       mfbInvertSolidFS,
+       mfbSetSpans,
+       mfbPutImage,
+       mfbCopyArea,
+       mfbCopyPlane,
+       mfbPolyPoint,
+       mfbLineSS,
+       mfbSegmentSS,
+       miPolyRectangle,
+       miZeroPolyArc,
+       mfbFillPolyInvert,
+       mfbPolyFillRect,
+       mfbPolyFillArcSolid,
+       miPolyText8,
+       miPolyText16,
+       miImageText8,
+       miImageText16,
+       mfbImageGlyphBltWhite,
+       mfbPolyGlyphBltInvert,
+       mfbSolidPP
+#ifdef NEED_LINEHELPER
+       ,NULL
+#endif
+};
+
+static GCOps   blackInvertOps = {
+       mfbInvertSolidFS,
+       mfbSetSpans,
+       mfbPutImage,
+       mfbCopyArea,
+       mfbCopyPlane,
+       mfbPolyPoint,
+       mfbLineSS,
+       mfbSegmentSS,
+       miPolyRectangle,
+       miZeroPolyArc,
+       mfbFillPolyInvert,
+       mfbPolyFillRect,
+       mfbPolyFillArcSolid,
+       miPolyText8,
+       miPolyText16,
+       miImageText8,
+       miImageText16,
+       mfbImageGlyphBltBlack,
+       mfbPolyGlyphBltInvert,
+       mfbSolidPP
+#ifdef NEED_LINEHELPER
+       ,NULL
+#endif
+};
+
+static GCOps   whiteWhiteCopyOps = {
+       mfbWhiteSolidFS,
+       mfbSetSpans,
+       mfbPutImage,
+       mfbCopyArea,
+       mfbCopyPlane,
+       mfbPolyPoint,
+       mfbLineSS,
+       mfbSegmentSS,
+       miPolyRectangle,
+       mfbZeroPolyArcSS,
+       mfbFillPolyWhite,
+       mfbPolyFillRect,
+       mfbPolyFillArcSolid,
+       miPolyText8,
+       miPolyText16,
+       miImageText8,
+       miImageText16,
+       miImageGlyphBlt,
+       mfbPolyGlyphBltWhite,
+       mfbSolidPP
+#ifdef NEED_LINEHELPER
+       ,NULL
+#endif
+};
+
+static GCOps   blackBlackCopyOps = {
+       mfbBlackSolidFS,
+       mfbSetSpans,
+       mfbPutImage,
+       mfbCopyArea,
+       mfbCopyPlane,
+       mfbPolyPoint,
+       mfbLineSS,
+       mfbSegmentSS,
+       miPolyRectangle,
+       mfbZeroPolyArcSS,
+       mfbFillPolyBlack,
+       mfbPolyFillRect,
+       mfbPolyFillArcSolid,
+       miPolyText8,
+       miPolyText16,
+       miImageText8,
+       miImageText16,
+       miImageGlyphBlt,
+       mfbPolyGlyphBltBlack,
+       mfbSolidPP
+#ifdef NEED_LINEHELPER
+       ,NULL
+#endif
+};
+
+static GCOps   fgEqBgInvertOps = {
+       mfbInvertSolidFS,
+       mfbSetSpans,
+       mfbPutImage,
+       mfbCopyArea,
+       mfbCopyPlane,
+       mfbPolyPoint,
+       mfbLineSS,
+       mfbSegmentSS,
+       miPolyRectangle,
+       miZeroPolyArc,
+       mfbFillPolyInvert,
+       mfbPolyFillRect,
+       mfbPolyFillArcSolid,
+       miPolyText8,
+       miPolyText16,
+       miImageText8,
+       miImageText16,
+       miImageGlyphBlt,
+       mfbPolyGlyphBltInvert,
+       mfbSolidPP
+#ifdef NEED_LINEHELPER
+       ,NULL
+#endif
+};
+
+struct commonOps {
+    int                    fg, bg;
+    int                    rrop;
+    int                    terminalFont;
+    GCOps          *ops;
+    void           (*fillArea)();
+};
+
+static struct commonOps mfbCommonOps[] = {
+    { 1, 0, RROP_WHITE, 1, &whiteTECopyOps, mfbSolidWhiteArea },
+    { 0, 1, RROP_BLACK, 1, &blackTECopyOps, mfbSolidBlackArea },
+    { 1, 0, RROP_INVERT, 1, &whiteTEInvertOps, mfbSolidInvertArea },
+    { 0, 1, RROP_INVERT, 1, &blackTEInvertOps, mfbSolidInvertArea },
+    { 1, 0, RROP_WHITE, 0, &whiteCopyOps, mfbSolidWhiteArea },
+    { 0, 1, RROP_BLACK, 0, &blackCopyOps, mfbSolidBlackArea },
+    { 1, 0, RROP_INVERT, 0, &whiteInvertOps, mfbSolidInvertArea },
+    { 0, 1, RROP_INVERT, 0, &blackInvertOps, mfbSolidInvertArea },
+    { 1, 1, RROP_WHITE, 0, &whiteWhiteCopyOps, mfbSolidWhiteArea },
+    { 0, 0, RROP_BLACK, 0, &blackBlackCopyOps, mfbSolidBlackArea },
+    { 1, 1, RROP_INVERT, 0, &fgEqBgInvertOps, mfbSolidInvertArea },
+    { 0, 0, RROP_INVERT, 0, &fgEqBgInvertOps, mfbSolidInvertArea },
+};
+
+#define numberCommonOps        (sizeof (mfbCommonOps) / sizeof (mfbCommonOps[0]))
+
+static GCOps *
+matchCommon (pGC)
+    GCPtr   pGC;
+{
+    int        i;
+    struct commonOps   *cop;
+    mfbPrivGC          *priv;
+
+    if (pGC->lineWidth != 0)
+       return 0;
+    if (pGC->lineStyle != LineSolid)
+       return 0;
+    if (pGC->fillStyle != FillSolid)
+       return 0;
+    if (!pGC->font ||
+        FONTMAXBOUNDS(pGC->font,rightSideBearing) -
+       FONTMINBOUNDS(pGC->font,leftSideBearing) > 32 ||
+       FONTMINBOUNDS(pGC->font,characterWidth) < 0)
+       return 0;
+    priv = (mfbPrivGC *) pGC->devPrivates[mfbGCPrivateIndex].ptr;
+    for (i = 0; i < numberCommonOps; i++) {
+       cop = &mfbCommonOps[i];
+       if ((pGC->fgPixel & 1) != cop->fg)
+           continue;
+       if ((pGC->bgPixel & 1) != cop->bg)
+           continue;
+       if (priv->rop != cop->rrop)
+           continue;
+       if (cop->terminalFont && !TERMINALFONT(pGC->font))
+           continue;
+       priv->FillArea = cop->fillArea;
+       return cop->ops;
+    }
+    return 0;
+}
+
+Bool
+mfbCreateGC(pGC)
+    register GCPtr pGC;
+{
+    mfbPrivGC  *pPriv;
+
+    pGC->clientClip = NULL;
+    pGC->clientClipType = CT_NONE;
+    
+    /* some of the output primitives aren't really necessary, since
+       they will be filled in ValidateGC because of dix/CreateGC()
+       setting all the change bits.  Others are necessary because although
+       they depend on being a monochrome frame buffer, they don't change 
+    */
+
+    pGC->ops = &whiteCopyOps;
+    pGC->funcs = &mfbFuncs;
+
+    /* mfb wants to translate before scan convesion */
+    pGC->miTranslate = 1;
+
+    pPriv = (mfbPrivGC *)(pGC->devPrivates[mfbGCPrivateIndex].ptr);
+    pPriv->rop = mfbReduceRop(pGC->alu, pGC->fgPixel);
+    pPriv->fExpose = TRUE;
+    pPriv->pRotatedPixmap = NullPixmap;
+    pPriv->freeCompClip = FALSE;
+    pPriv->FillArea = mfbSolidInvertArea;
+    return TRUE;
+}
+
+/* Clipping conventions
+       if the drawable is a window
+           CT_REGION ==> pCompositeClip really is the composite
+           CT_other ==> pCompositeClip is the window clip region
+       if the drawable is a pixmap
+           CT_REGION ==> pCompositeClip is the translated client region
+               clipped to the pixmap boundary
+           CT_other ==> pCompositeClip is the pixmap bounding box
+*/
+
+/*ARGSUSED*/
+void
+mfbValidateGC(pGC, changes, pDrawable)
+    register GCPtr     pGC;
+    unsigned long      changes;
+    DrawablePtr        pDrawable;
+{
+    register mfbPrivGCPtr      devPriv;
+    int mask;                  /* stateChanges */
+    int index;                 /* used for stepping through bitfields */
+    int        xrot, yrot;             /* rotations for tile and stipple pattern */
+    int rrop;                  /* reduced rasterop */
+                               /* flags for changing the proc vector 
+                                  and updating things in devPriv
+                               */
+    int new_rotate, new_rrop,  new_line, new_text, new_fill;
+    DDXPointRec        oldOrg;         /* origin of thing GC was last used with */
+
+    oldOrg = pGC->lastWinOrg;
+
+    pGC->lastWinOrg.x = pDrawable->x;
+    pGC->lastWinOrg.y = pDrawable->y;
+
+    /* we need to re-rotate the tile if the previous window/pixmap
+       origin (oldOrg) differs from the new window/pixmap origin
+       (pGC->lastWinOrg)
+    */
+    new_rotate = (oldOrg.x != pGC->lastWinOrg.x) ||
+                (oldOrg.y != pGC->lastWinOrg.y);
+
+    devPriv = ((mfbPrivGCPtr) (pGC->devPrivates[mfbGCPrivateIndex].ptr));
+
+    /*
+       if the client clip is different or moved OR
+       the subwindowMode has changed OR
+       the window's clip has changed since the last validation
+       we need to recompute the composite clip
+    */
+    if ((changes & (GCClipXOrigin|GCClipYOrigin|GCClipMask|GCSubwindowMode)) ||
+       (pDrawable->serialNumber != (pGC->serialNumber & DRAWABLE_SERIAL_BITS))
+       )
+    {
+       miComputeCompositeClip(pGC, pDrawable);
+    }
+
+    new_rrop = FALSE;
+    new_line = FALSE;
+    new_text = FALSE;
+    new_fill = FALSE;
+
+    mask = changes;
+    while (mask)
+    {
+       index = lowbit (mask);
+       mask &= ~index;
+
+       /* this switch acculmulates a list of which procedures
+          might have to change due to changes in the GC.  in
+          some cases (e.g. changing one 16 bit tile for another)
+          we might not really need a change, but the code is
+          being paranoid.
+          this sort of batching wins if, for example, the alu
+          and the font have been changed, or any other pair
+          of items that both change the same thing.
+       */
+       switch (index)
+       {
+         case GCFunction:
+         case GCForeground:
+           new_rrop = TRUE;
+           break;
+         case GCPlaneMask:
+           break;
+         case GCBackground:
+           new_rrop = TRUE;    /* for opaque stipples */
+           break;
+         case GCLineStyle:
+         case GCLineWidth:
+         case GCJoinStyle:
+           new_line = TRUE;
+           break;
+         case GCCapStyle:
+           break;
+         case GCFillStyle:
+           new_fill = TRUE;
+           break;
+         case GCFillRule:
+           break;
+         case GCTile:
+           if(pGC->tileIsPixel)
+               break;
+           new_rotate = TRUE;
+           new_fill = TRUE;
+           break;
+
+         case GCStipple:
+           if(pGC->stipple == (PixmapPtr)NULL)
+               break;
+           new_rotate = TRUE;
+           new_fill = TRUE;
+           break;
+
+         case GCTileStipXOrigin:
+           new_rotate = TRUE;
+           break;
+
+         case GCTileStipYOrigin:
+           new_rotate = TRUE;
+           break;
+
+         case GCFont:
+           new_text = TRUE;
+           break;
+         case GCSubwindowMode:
+           break;
+         case GCGraphicsExposures:
+           break;
+         case GCClipXOrigin:
+           break;
+         case GCClipYOrigin:
+           break;
+         case GCClipMask:
+           break;
+         case GCDashOffset:
+           break;
+         case GCDashList:
+           break;
+         case GCArcMode:
+           break;
+         default:
+           break;
+       }
+    }
+
+    /* deal with the changes we've collected .
+       new_rrop must be done first because subsequent things
+       depend on it.
+    */
+
+    if(new_rotate || new_fill)
+    {
+       Bool new_pix = FALSE;
+
+       /* figure out how much to rotate */
+       xrot = pGC->patOrg.x;
+       yrot = pGC->patOrg.y;
+       xrot += pDrawable->x;
+       yrot += pDrawable->y;
+
+       switch (pGC->fillStyle)
+       {
+       case FillTiled:
+           /* copy current tile and stipple */
+           if (!pGC->tileIsPixel && (pGC->tile.pixmap->drawable.width <= PPW) &&
+               !(pGC->tile.pixmap->drawable.width & (pGC->tile.pixmap->drawable.width - 1)))
+           {
+               mfbCopyRotatePixmap(pGC->tile.pixmap,
+                                   &devPriv->pRotatedPixmap, xrot, yrot);
+               new_pix = TRUE;
+           }
+           break;
+       case FillStippled:
+       case FillOpaqueStippled:
+           if (pGC->stipple && (pGC->stipple->drawable.width <= PPW) &&
+               !(pGC->stipple->drawable.width & (pGC->stipple->drawable.width - 1)))
+           {
+               mfbCopyRotatePixmap(pGC->stipple,
+                                   &devPriv->pRotatedPixmap, xrot, yrot);
+               new_pix = TRUE;
+           }
+       }
+       /* destroy any previously rotated tile or stipple */
+       if (!new_pix && devPriv->pRotatedPixmap)
+       {
+           (*pDrawable->pScreen->DestroyPixmap)(devPriv->pRotatedPixmap);
+           devPriv->pRotatedPixmap = (PixmapPtr)NULL;
+       }
+    }
+
+    /*
+     * duck out here when the GC is unchanged
+     */
+
+    if (!changes)
+       return;
+
+    if (new_rrop || new_fill)
+    {
+       rrop = mfbReduceRop(pGC->alu, pGC->fgPixel);
+       devPriv->rop = rrop;
+       new_fill = TRUE;
+       /* FillArea raster op is GC's for tile filling,
+          and the reduced rop for solid and stipple
+       */
+       if (pGC->fillStyle == FillTiled)
+           devPriv->ropFillArea = pGC->alu;
+       else
+           devPriv->ropFillArea = rrop;
+
+       /* opaque stipples:
+          fg   bg      ropOpStip       fill style
+          1    0       alu             tile
+          0    1       inverseAlu      tile
+          1    1       rrop(fg, alu)   solid
+          0    0       rrop(fg, alu)   solid
+       Note that rrop(fg, alu) == mfbPrivGC.rop, so we don't really need to
+       compute it.
+       */
+        if (pGC->fillStyle == FillOpaqueStippled)
+        {
+           if ((pGC->fgPixel & 1) != (pGC->bgPixel & 1))
+           {
+               if (pGC->fgPixel & 1)
+                   devPriv->ropOpStip = pGC->alu;
+               else
+                   devPriv->ropOpStip = InverseAlu[pGC->alu];
+           }
+           else
+               devPriv->ropOpStip = rrop;
+           devPriv->ropFillArea = devPriv->ropOpStip;
+        }
+    }
+    else
+       rrop = devPriv->rop;
+
+    if (new_line || new_fill || new_text)
+    {
+       GCOps   *newops;
+
+       if (newops = matchCommon (pGC))
+       {
+           if (pGC->ops->devPrivate.val)
+               miDestroyGCOps (pGC->ops);
+           pGC->ops = newops;
+           new_line = new_fill = new_text = 0;
+       }
+       else
+       {
+           if (!pGC->ops->devPrivate.val)
+           {
+               pGC->ops = miCreateGCOps (pGC->ops);
+               pGC->ops->devPrivate.val = 1;
+           }
+       }
+    }
+
+    if (new_line || new_fill)
+    {
+       if (pGC->lineWidth == 0)
+       {
+           if ((pGC->lineStyle == LineSolid) && (pGC->fillStyle == FillSolid)
+               && ((rrop == RROP_WHITE) || (rrop == RROP_BLACK)))
+               pGC->ops->PolyArc = mfbZeroPolyArcSS;
+           else
+               pGC->ops->PolyArc = miZeroPolyArc;
+       }
+       else
+           pGC->ops->PolyArc = miPolyArc;
+       if (pGC->lineStyle == LineSolid)
+       {
+           if(pGC->lineWidth == 0)
+           {
+               if (pGC->fillStyle == FillSolid)
+               {
+                   pGC->ops->PolySegment = mfbSegmentSS;
+                   pGC->ops->Polylines = mfbLineSS;
+               }
+               else
+               {
+                   pGC->ops->PolySegment = miPolySegment;
+                   pGC->ops->Polylines = miZeroLine;
+               }
+           }
+           else
+           {
+               pGC->ops->PolySegment = miPolySegment;
+               pGC->ops->Polylines = miWideLine;
+           }
+       }
+       else
+       {
+           if(pGC->lineWidth == 0 && pGC->fillStyle == FillSolid)
+           {
+               pGC->ops->Polylines = mfbLineSD;
+               pGC->ops->PolySegment = mfbSegmentSD;
+           }
+           else
+           {
+               pGC->ops->Polylines = miWideDash;
+               pGC->ops->PolySegment = miPolySegment;
+           }
+       }
+    }
+
+    if (new_text || new_fill)
+    {
+       if ((pGC->font) &&
+           (FONTMAXBOUNDS(pGC->font,rightSideBearing) -
+            FONTMINBOUNDS(pGC->font,leftSideBearing) > 32 ||
+            FONTMINBOUNDS(pGC->font,characterWidth) < 0))
+       {
+           pGC->ops->PolyGlyphBlt = miPolyGlyphBlt;
+           pGC->ops->ImageGlyphBlt = miImageGlyphBlt;
+       }
+       else
+       {
+           /* special case ImageGlyphBlt for terminal emulator fonts */
+           if ((pGC->font) &&
+               TERMINALFONT(pGC->font) &&
+               ((pGC->fgPixel & 1) != (pGC->bgPixel & 1)))
+           {
+               /* pcc bug makes this not compile...
+               pGC->ops->ImageGlyphBlt = (pGC->fgPixel & 1) ? mfbTEGlyphBltWhite :
+                                                     mfbTEGlyphBltBlack;
+               */
+               if (pGC->fgPixel & 1)
+                   pGC->ops->ImageGlyphBlt = mfbTEGlyphBltWhite;
+               else
+                   pGC->ops->ImageGlyphBlt = mfbTEGlyphBltBlack;
+           }
+           else
+           {
+               if (pGC->fgPixel & 1)
+                   pGC->ops->ImageGlyphBlt = mfbImageGlyphBltWhite;
+               else
+                   pGC->ops->ImageGlyphBlt = mfbImageGlyphBltBlack;
+           }
+
+           /* now do PolyGlyphBlt */
+           if (pGC->fillStyle == FillSolid ||
+               (pGC->fillStyle == FillOpaqueStippled &&
+                (pGC->fgPixel & 1) == (pGC->bgPixel & 1)
+               )
+              )
+           {
+               if (rrop == RROP_WHITE)
+                   pGC->ops->PolyGlyphBlt = mfbPolyGlyphBltWhite;
+               else if (rrop == RROP_BLACK)
+                   pGC->ops->PolyGlyphBlt = mfbPolyGlyphBltBlack;
+               else if (rrop == RROP_INVERT)
+                   pGC->ops->PolyGlyphBlt = mfbPolyGlyphBltInvert;
+               else
+                   pGC->ops->PolyGlyphBlt = (void (*)())NoopDDA;
+           }
+           else
+           {
+               pGC->ops->PolyGlyphBlt = miPolyGlyphBlt;
+           }
+       }
+    }
+
+    if (new_fill)
+    {
+       /* install a suitable fillspans and pushpixels */
+       pGC->ops->PushPixels = mfbPushPixels;
+       pGC->ops->FillPolygon = miFillPolygon;
+       if ((pGC->fillStyle == FillSolid) ||
+           ((pGC->fillStyle == FillOpaqueStippled) &&
+            ((pGC->fgPixel & 1) == (pGC->bgPixel & 1))))
+       {
+           pGC->ops->PushPixels = mfbSolidPP;
+           switch(devPriv->rop)
+           {
+             case RROP_WHITE:
+               pGC->ops->FillSpans = mfbWhiteSolidFS;
+               pGC->ops->FillPolygon = mfbFillPolyWhite;
+               break;
+             case RROP_BLACK:
+               pGC->ops->FillSpans = mfbBlackSolidFS;
+               pGC->ops->FillPolygon = mfbFillPolyBlack;
+               break;
+             case RROP_INVERT:
+               pGC->ops->FillSpans = mfbInvertSolidFS;
+               pGC->ops->FillPolygon = mfbFillPolyInvert;
+               break;
+             case RROP_NOP:
+               pGC->ops->FillSpans = (void (*)())NoopDDA;
+               pGC->ops->FillPolygon = (void (*)())NoopDDA;
+               break;
+           }
+       }
+       /* beyond this point, opaqueStippled ==> fg != bg */
+       else if (((pGC->fillStyle == FillTiled) ||
+                 (pGC->fillStyle == FillOpaqueStippled)) &&
+                !devPriv->pRotatedPixmap)
+       {
+           pGC->ops->FillSpans = mfbUnnaturalTileFS;
+       }
+       else if ((pGC->fillStyle == FillStippled) && !devPriv->pRotatedPixmap)
+       {
+           pGC->ops->FillSpans = mfbUnnaturalStippleFS;
+       }
+       else if (pGC->fillStyle == FillStippled)
+       {
+           switch(devPriv->rop)
+           {
+             case RROP_WHITE:
+               pGC->ops->FillSpans = mfbWhiteStippleFS;
+               break;
+             case RROP_BLACK:
+               pGC->ops->FillSpans = mfbBlackStippleFS;
+               break;
+             case RROP_INVERT:
+               pGC->ops->FillSpans = mfbInvertStippleFS;
+               break;
+             case RROP_NOP:
+               pGC->ops->FillSpans = (void (*)())NoopDDA;
+               break;
+           }
+       }
+       else /* overload tiles to do parti-colored opaque stipples */
+       {
+           pGC->ops->FillSpans = mfbTileFS;
+       }
+       if (pGC->fillStyle == FillSolid)
+           pGC->ops->PolyFillArc = mfbPolyFillArcSolid;
+       else
+           pGC->ops->PolyFillArc = miPolyFillArc;
+       /* the rectangle code doesn't deal with opaque stipples that
+          are two colors -- we can fool it for fg==bg, though
+        */
+       if ((((pGC->fillStyle == FillTiled) ||
+             (pGC->fillStyle == FillStippled)) &&
+            !devPriv->pRotatedPixmap) ||
+           ((pGC->fillStyle == FillOpaqueStippled) &&
+            ((pGC->fgPixel & 1) != (pGC->bgPixel & 1)))
+          )
+       {
+           pGC->ops->PolyFillRect = miPolyFillRect;
+       }
+       else /* deal with solids and natural stipples and tiles */
+       {
+           pGC->ops->PolyFillRect = mfbPolyFillRect;
+
+           if ((pGC->fillStyle == FillSolid) ||
+               ((pGC->fillStyle == FillOpaqueStippled) &&
+                ((pGC->fgPixel & 1) == (pGC->bgPixel & 1))))
+           {
+               switch(devPriv->rop)
+               {
+                 case RROP_WHITE:
+                   devPriv->FillArea = mfbSolidWhiteArea;
+                   break;
+                 case RROP_BLACK:
+                   devPriv->FillArea = mfbSolidBlackArea;
+                   break;
+                 case RROP_INVERT:
+                   devPriv->FillArea = mfbSolidInvertArea;
+                   break;
+                 case RROP_NOP:
+                   devPriv->FillArea = (void (*)())NoopDDA;
+                   break;
+               }
+           }
+           else if (pGC->fillStyle == FillStippled)
+           {
+               switch(devPriv->rop)
+               {
+                 case RROP_WHITE:
+                   devPriv->FillArea = mfbStippleWhiteArea;
+                   break;
+                 case RROP_BLACK:
+                   devPriv->FillArea = mfbStippleBlackArea;
+                   break;
+                 case RROP_INVERT:
+                   devPriv->FillArea = mfbStippleInvertArea;
+                   break;
+                 case RROP_NOP:
+                   devPriv->FillArea = (void (*)())NoopDDA;
+                   break;
+               }
+           }
+           else /* deal with tiles */
+           {
+               switch (pGC->alu)
+               {
+                 case GXcopy:
+                   devPriv->FillArea = mfbTileAreaPPWCopy;
+                   break;
+                 default:
+                   devPriv->FillArea = mfbTileAreaPPWGeneral;
+                   break;
+               }
+           }
+       } /* end of natural rectangles */
+    } /* end of new_fill */
+}
+
+/* table to map alu(src, dst) to alu(~src, dst) */
+int InverseAlu[16] = {
+       GXclear,
+       GXandInverted,
+       GXnor,
+       GXcopyInverted,
+       GXand,
+       GXnoop,
+       GXequiv,
+       GXorInverted,
+       GXandReverse,
+       GXxor,
+       GXinvert,
+       GXnand,
+       GXcopy,
+       GXor,
+       GXorReverse,
+       GXset
+};
+
+int
+mfbReduceRop(alu, src)
+    register int alu;
+    register Pixel src;
+{
+    int rop;
+    if ((src & 1) == 0)        /* src is black */
+    {
+       switch(alu)
+       {
+         case GXclear:
+           rop = RROP_BLACK;
+           break;
+         case GXand:
+           rop = RROP_BLACK;
+           break;
+         case GXandReverse:
+           rop = RROP_BLACK;
+           break;
+         case GXcopy:
+           rop = RROP_BLACK;
+           break;
+         case GXandInverted:
+           rop = RROP_NOP;
+           break;
+         case GXnoop:
+           rop = RROP_NOP;
+           break;
+         case GXxor:
+           rop = RROP_NOP;
+           break;
+         case GXor:
+           rop = RROP_NOP;
+           break;
+         case GXnor:
+           rop = RROP_INVERT;
+           break;
+         case GXequiv:
+           rop = RROP_INVERT;
+           break;
+         case GXinvert:
+           rop = RROP_INVERT;
+           break;
+         case GXorReverse:
+           rop = RROP_INVERT;
+           break;
+         case GXcopyInverted:
+           rop = RROP_WHITE;
+           break;
+         case GXorInverted:
+           rop = RROP_WHITE;
+           break;
+         case GXnand:
+           rop = RROP_WHITE;
+           break;
+         case GXset:
+           rop = RROP_WHITE;
+           break;
+       }
+    }
+    else /* src is white */
+    {
+       switch(alu)
+       {
+         case GXclear:
+           rop = RROP_BLACK;
+           break;
+         case GXand:
+           rop = RROP_NOP;
+           break;
+         case GXandReverse:
+           rop = RROP_INVERT;
+           break;
+         case GXcopy:
+           rop = RROP_WHITE;
+           break;
+         case GXandInverted:
+           rop = RROP_BLACK;
+           break;
+         case GXnoop:
+           rop = RROP_NOP;
+           break;
+         case GXxor:
+           rop = RROP_INVERT;
+           break;
+         case GXor:
+           rop = RROP_WHITE;
+           break;
+         case GXnor:
+           rop = RROP_BLACK;
+           break;
+         case GXequiv:
+           rop = RROP_NOP;
+           break;
+         case GXinvert:
+           rop = RROP_INVERT;
+           break;
+         case GXorReverse:
+           rop = RROP_WHITE;
+           break;
+         case GXcopyInverted:
+           rop = RROP_BLACK;
+           break;
+         case GXorInverted:
+           rop = RROP_NOP;
+           break;
+         case GXnand:
+           rop = RROP_INVERT;
+           break;
+         case GXset:
+           rop = RROP_WHITE;
+           break;
+       }
+    }
+    return rop;
+}
diff --git a/Xserver/programs/Xserver/mfb/mfbgetsp.c b/Xserver/programs/Xserver/mfb/mfbgetsp.c
new file mode 100644 (file)
index 0000000..0c6639f
--- /dev/null
@@ -0,0 +1,155 @@
+/* Combined Purdue/PurduePlus patches, level 2.0, 1/17/89 */
+/***********************************************************
+
+Copyright (c) 1987  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+
+Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
+
+                        All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and its 
+documentation for any purpose and without fee is hereby granted, 
+provided that the above copyright notice appear in all copies and that
+both that copyright notice and this permission notice appear in 
+supporting documentation, and that the name of Digital not be
+used in advertising or publicity pertaining to distribution of the
+software without specific, written prior permission.  
+
+DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
+ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
+DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
+ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+SOFTWARE.
+
+******************************************************************/
+/* $XConsortium: mfbgetsp.c,v 5.10 94/04/17 20:28:24 dpw Exp $ */
+#include "X.h"
+#include "Xmd.h"
+
+#include "misc.h"
+#include "region.h"
+#include "gc.h"
+#include "windowstr.h"
+#include "pixmapstr.h"
+#include "scrnintstr.h"
+
+#include "mfb.h"
+#include "maskbits.h"
+
+#include "servermd.h"
+
+/* GetSpans -- for each span, gets bits from drawable starting at ppt[i]
+ * and continuing for pwidth[i] bits
+ * Each scanline returned will be server scanline padded, i.e., it will come
+ * out to an integral number of words.
+ */
+/*ARGSUSED*/
+void
+mfbGetSpans(pDrawable, wMax, ppt, pwidth, nspans, pchardstStart)
+    DrawablePtr                pDrawable;      /* drawable from which to get bits */
+    int                        wMax;           /* largest value of all *pwidths */
+    register DDXPointPtr ppt;          /* points to start copying from */
+    int                        *pwidth;        /* list of number of bits to copy */
+    int                        nspans;         /* number of scanlines to copy */
+    char               *pchardstStart; /* where to put the bits */
+{
+    PixelType          *pdstStart = (PixelType *)pchardstStart;
+    register PixelType *pdst;  /* where to put the bits */
+    register PixelType *psrc;  /* where to get the bits */
+    register PixelType tmpSrc; /* scratch buffer for bits */
+    PixelType          *psrcBase;      /* start of src bitmap */
+    int                        widthSrc;       /* width of pixmap in bytes */
+    register DDXPointPtr pptLast;      /* one past last point to get */
+    int                xEnd;           /* last pixel to copy from */
+    register int       nstart; 
+    int                        nend; 
+    int                        srcStartOver; 
+    PixelType          startmask, endmask;
+    unsigned int       srcBit;
+    int                        nlMiddle, nl;
+    int                        w;
+  
+    pptLast = ppt + nspans;
+
+    mfbGetPixelWidthAndPointer(pDrawable, widthSrc, psrcBase);
+    pdst = pdstStart;
+
+    while(ppt < pptLast)
+    {
+       /* XXX should this really be << PWSH, or * 8, or * PGSZB? */
+       xEnd = min(ppt->x + *pwidth, widthSrc << PWSH);
+       pwidth++;
+       psrc = mfbScanline(psrcBase, ppt->x, ppt->y, widthSrc);
+       w = xEnd - ppt->x;
+       srcBit = ppt->x & PIM;
+
+       if (srcBit + w <= PPW) 
+       { 
+           getandputbits0(psrc, srcBit, w, pdst);
+           pdst++;
+       } 
+       else 
+       { 
+
+           maskbits(ppt->x, w, startmask, endmask, nlMiddle);
+           if (startmask) 
+               nstart = PPW - srcBit; 
+           else 
+               nstart = 0; 
+           if (endmask) 
+               nend = xEnd & PIM; 
+           srcStartOver = srcBit + nstart > PLST;
+           if (startmask) 
+           { 
+               getandputbits0(psrc, srcBit, nstart, pdst);
+               if(srcStartOver)
+                   psrc++;
+           } 
+           nl = nlMiddle; 
+#ifdef FASTPUTBITS
+           Duff(nl, putbits(*psrc, nstart, PPW, pdst); psrc++; pdst++;);
+#else
+           while (nl--) 
+           { 
+               tmpSrc = *psrc;
+               putbits(tmpSrc, nstart, PPW, pdst);
+               psrc++;
+               pdst++;
+           } 
+#endif
+           if (endmask) 
+           { 
+               putbits(*psrc, nstart, nend, pdst);
+               if(nstart + nend > PPW)
+                   pdst++;
+           } 
+           if (startmask || endmask)
+               pdst++; 
+       } 
+        ppt++;
+    }
+}
diff --git a/Xserver/programs/Xserver/mfb/mfbhrzvert.c b/Xserver/programs/Xserver/mfb/mfbhrzvert.c
new file mode 100644 (file)
index 0000000..8da14d3
--- /dev/null
@@ -0,0 +1,173 @@
+/* Combined Purdue/PurduePlus patches, level 2.0, 1/17/89 */
+/***********************************************************
+
+Copyright (c) 1987  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+
+Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
+
+                        All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and its 
+documentation for any purpose and without fee is hereby granted, 
+provided that the above copyright notice appear in all copies and that
+both that copyright notice and this permission notice appear in 
+supporting documentation, and that the name of Digital not be
+used in advertising or publicity pertaining to distribution of the
+software without specific, written prior permission.  
+
+DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
+ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
+DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
+ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+SOFTWARE.
+
+******************************************************************/
+/* $XConsortium: mfbhrzvert.c,v 1.15 94/04/17 20:28:24 dpw Exp $ */
+#include "X.h"
+
+#include "gc.h"
+#include "window.h"
+#include "pixmap.h"
+#include "region.h"
+
+#include "mfb.h"
+#include "maskbits.h"
+
+/* horizontal solid line
+   abs(len) > 1
+*/
+mfbHorzS(rop, addrl, nlwidth, x1, y1, len)
+int rop;               /* a reduced rasterop */
+register PixelType *addrl;     /* pointer to base of bitmap */
+register int nlwidth;  /* width in longwords of bitmap */
+int x1;                        /* initial point */ 
+int y1;
+int len;               /* length of line */
+{
+    register PixelType startmask;
+    register PixelType endmask;
+    register int nlmiddle;
+
+
+    /* force the line to go left to right
+       but don't draw the last point
+    */
+    if (len < 0)
+    {
+       x1 += len;
+       x1 += 1;
+       len = -len;
+    }
+
+    addrl = mfbScanline(addrl, x1, y1, nlwidth);
+
+    /* all bits inside same longword */
+    if ( ((x1 & PIM) + len) < PPW)
+    {
+       maskpartialbits(x1, len, startmask);
+        if (rop == RROP_BLACK)
+        {
+           *addrl &= ~startmask;
+        }
+        else if (rop == RROP_WHITE)
+        {
+           *addrl |= startmask;
+        }
+        else if (rop == RROP_INVERT)
+        {
+           *addrl ^= startmask;
+        }
+    }
+    else
+    {
+       maskbits(x1, len, startmask, endmask, nlmiddle);
+        if (rop == RROP_BLACK)
+        {
+           if (startmask)
+               *addrl++ &= ~startmask;
+           Duff (nlmiddle, *addrl++ = 0x0);
+           if (endmask)
+               *addrl &= ~endmask;
+        }
+        else if (rop == RROP_WHITE)
+        {
+           if (startmask)
+               *addrl++ |= startmask;
+           Duff (nlmiddle, *addrl++ = ~0);
+           if (endmask)
+               *addrl |= endmask;
+        }
+        else if (rop == RROP_INVERT)
+        {
+           if (startmask)
+               *addrl++ ^= startmask;
+           Duff (nlmiddle, *addrl++ ^= ~0);
+           if (endmask)
+               *addrl ^= endmask;
+        }
+    }
+}
+
+/* vertical solid line
+   this uses do loops because pcc (Ultrix 1.2, bsd 4.2) generates
+   better code.  sigh.  we know that len will never be 0 or 1, so
+   it's OK to use it.
+*/
+
+mfbVertS(rop, addrl, nlwidth, x1, y1, len)
+int rop;               /* a reduced rasterop */
+register PixelType *addrl;     /* pointer to base of bitmap */
+register int nlwidth;  /* width in longwords of bitmap */
+int x1, y1;            /* initial point */
+register int len;      /* length of line */
+{
+    register PixelType bitmask;
+
+    addrl = mfbScanline(addrl, x1, y1, nlwidth);
+
+    if (len < 0)
+    {
+       nlwidth = -nlwidth;
+       len = -len;
+    }
+    if (rop == RROP_BLACK)
+    {
+       bitmask = rmask[x1 & PIM];
+        Duff(len, *addrl &= bitmask; mfbScanlineInc(addrl, nlwidth) );
+    }
+    else if (rop == RROP_WHITE)
+    {
+       bitmask = mask[x1 & PIM];
+        Duff(len, *addrl |= bitmask; mfbScanlineInc(addrl, nlwidth) );
+    }
+    else if (rop == RROP_INVERT)
+    {
+       bitmask = mask[x1 & PIM];
+        Duff(len, *addrl ^= bitmask; mfbScanlineInc(addrl, nlwidth) );
+    }
+}
diff --git a/Xserver/programs/Xserver/mfb/mfbimage.c b/Xserver/programs/Xserver/mfb/mfbimage.c
new file mode 100644 (file)
index 0000000..77f66f5
--- /dev/null
@@ -0,0 +1,174 @@
+/***********************************************************
+
+Copyright (c) 1987  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+
+Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
+
+                        All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and its 
+documentation for any purpose and without fee is hereby granted, 
+provided that the above copyright notice appear in all copies and that
+both that copyright notice and this permission notice appear in 
+supporting documentation, and that the name of Digital not be
+used in advertising or publicity pertaining to distribution of the
+software without specific, written prior permission.  
+
+DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
+ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
+DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
+ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+SOFTWARE.
+
+******************************************************************/
+/* $XConsortium: mfbimage.c,v 5.10 94/04/17 20:28:25 dpw Exp $ */
+
+#include "X.h"
+
+#include "windowstr.h"
+#include "pixmapstr.h"
+#include "scrnintstr.h"
+#include "gcstruct.h"
+
+#include "mfb.h"
+#include "mi.h"
+#include "Xmd.h"
+
+#include "maskbits.h"
+
+#include "servermd.h"
+
+/* Put and Get images on a monochrome frame buffer
+ *
+ *   we do this by creating a temporary pixmap and making its
+ * pointer to bits point to the buffer read in from the client.
+ * this works because of the padding rules specified at startup
+ *
+ * Note that CopyArea must know how to copy a bitmap into the server-format
+ * temporary pixmap.
+ *
+ * For speed, mfbPutImage should allocate the temporary pixmap on the stack.
+ *
+ *     even though an XYBitmap and an XYPixmap have the same
+ * format (for this device), PutImage has different semantics for the
+ * two.  XYPixmap just does the copy; XYBitmap takes gc.fgPixel for
+ * a 1 bit, gc.bgPixel for a 0 bit, which we notice is exactly
+ * like CopyPlane.
+ *
+ *   written by drewry, september 1986
+ */
+
+
+
+/*ARGSUSED*/
+void
+mfbPutImage(dst, pGC, depth, x, y, w, h, leftPad, format, pImage)
+    DrawablePtr dst;
+    GCPtr      pGC;
+    int                depth, x, y, w, h;
+    int leftPad;
+    int format;
+    char       *pImage;
+{
+    PixmapPtr  pPixmap;
+
+    if (!(pGC->planemask & 1))
+       return;
+
+    /* 0 may confuse CreatePixmap, and will sometimes be
+       passed by the mi text code
+    */
+    if ((w == 0) || (h == 0))
+       return;
+
+    pPixmap = GetScratchPixmapHeader(dst->pScreen, w+leftPad, h, 1, 1,
+                               BitmapBytePad(w+leftPad), (pointer)pImage);
+    if (!pPixmap)
+       return;
+
+    ((mfbPrivGC *)(pGC->devPrivates[mfbGCPrivateIndex].ptr))->fExpose = FALSE;
+    if (format != XYBitmap)
+       (*pGC->ops->CopyArea)((DrawablePtr)pPixmap, dst, pGC, leftPad, 0,
+                             w, h, x, y);
+    else
+       (*pGC->ops->CopyPlane)((DrawablePtr)pPixmap, dst, pGC, leftPad, 0,
+                              w, h, x, y, 1);
+    ((mfbPrivGC*)(pGC->devPrivates[mfbGCPrivateIndex].ptr))->fExpose = TRUE;
+    FreeScratchPixmapHeader(pPixmap);
+}
+
+
+/*
+ * pdstLine points to space allocated by caller, which he can do since
+ * he knows dimensions of the pixmap
+ * we can call mfbDoBitblt because the dispatcher has promised not to send us
+ * anything that would require going over the edge of the screen.
+ *
+ *     XYPixmap and ZPixmap are the same for mfb.
+ *     For any planemask with bit 0 == 0, just fill the dst with 0.
+ */
+/*ARGSUSED*/
+void
+mfbGetImage( pDrawable, sx, sy, w, h, format, planeMask, pdstLine)
+    DrawablePtr pDrawable;
+    int                sx, sy, w, h;
+    unsigned int format;
+    unsigned long planeMask;
+    char       *pdstLine;
+{
+    PixmapPtr pPixmap;
+    BoxRec box;
+    DDXPointRec ptSrc;
+    RegionRec rgnDst;
+
+    if (planeMask & 0x1)
+    {
+       ScreenPtr pScreen = pDrawable->pScreen;
+       PixmapPtr pPixmap;
+
+       pPixmap = GetScratchPixmapHeader(pScreen, w, h, /*depth*/ 1, /*bpp*/ 1,
+                                        BitmapBytePad(w), (pointer)pdstLine);
+       if (!pPixmap)
+           return;
+
+        ptSrc.x = sx + pDrawable->x;
+        ptSrc.y = sy + pDrawable->y;
+        box.x1 = 0;
+        box.y1 = 0;
+        box.x2 = w;
+        box.y2 = h;
+        REGION_INIT(pScreen, &rgnDst, &box, 1);
+        mfbDoBitblt(pDrawable, (DrawablePtr)pPixmap,
+                   GXcopy, &rgnDst, &ptSrc);
+        REGION_UNINIT(pScreen, &rgnDst);
+       FreeScratchPixmapHeader(pPixmap);
+    }
+    else
+    {
+       bzero(pdstLine, BitmapBytePad(w) * h);
+    }
+}
diff --git a/Xserver/programs/Xserver/mfb/mfbimggblt.c b/Xserver/programs/Xserver/mfb/mfbimggblt.c
new file mode 100644 (file)
index 0000000..6c4f10d
--- /dev/null
@@ -0,0 +1,442 @@
+/* Combined Purdue/PurduePlus patches, level 2.0, 1/17/89 */
+/***********************************************************
+
+Copyright (c) 1987  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+
+Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
+
+                        All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and its 
+documentation for any purpose and without fee is hereby granted, 
+provided that the above copyright notice appear in all copies and that
+both that copyright notice and this permission notice appear in 
+supporting documentation, and that the name of Digital not be
+used in advertising or publicity pertaining to distribution of the
+software without specific, written prior permission.  
+
+DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
+ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
+DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
+ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+SOFTWARE.
+
+******************************************************************/
+/* $XConsortium: mfbimggblt.c,v 5.17 94/04/17 20:28:25 dpw Exp $ */
+/* $XFree86: xc/programs/Xserver/mfb/mfbimggblt.c,v 3.0 1995/06/14 12:43:46 dawes Exp $ */
+#include       "X.h"
+#include       "Xmd.h"
+#include       "Xproto.h"
+#include       "mfb.h"
+#include       "fontstruct.h"
+#include       "dixfontstr.h"
+#include       "gcstruct.h"
+#include       "windowstr.h"
+#include       "scrnintstr.h"
+#include       "pixmapstr.h"
+#include       "regionstr.h"
+#include       "maskbits.h"
+
+/*
+    we should eventually special-case fixed-width fonts for ImageText.
+
+    this works for fonts with glyphs <= 32 bits wide.
+
+    the clipping calculations are done for worst-case fonts.
+we make no assumptions about the heights, widths, or bearings
+of the glyphs.  if we knew that the glyphs are all the same height,
+we could clip the tops and bottoms per clipping box, rather
+than per character per clipping box.  if we knew that the glyphs'
+left and right bearings were wlle-behaved, we could clip a single
+character at the start, output until the last unclipped
+character, and then clip the last one.  this is all straightforward
+to determine based on max-bounds and min-bounds from the font.
+    there is some inefficiency introduced in the per-character
+clipping to make what's going on clearer.
+
+    (it is possible, for example, for a font to be defined in which the
+next-to-last character in a font would be clipped out, but the last
+one wouldn't.  the code below deals with this.)
+
+    Image text looks at the bits in the glyph and the fg and bg in the
+GC.  it paints a rectangle, as defined in the protocol dcoument,
+and the paints the characters.
+
+   to avoid source proliferation, this file is compiled
+three times:
+       MFBIMAGEGLYPHBLT        OPEQ
+       mfbImageGlyphBltWhite   |=
+       mfbImageGlyphBltBlack   &=~
+
+    the register allocations for startmask and endmask may not
+be the right thing.  are there two other deserving candidates?
+xoff, pdst, pglyph, and tmpSrc seem like the right things, though.
+*/
+
+void
+MFBIMAGEGLYPHBLT(pDrawable, pGC, x, y, nglyph, ppci, pglyphBase)
+    DrawablePtr pDrawable;
+    GC                 *pGC;
+    int        x, y;
+    unsigned int nglyph;
+    CharInfoPtr *ppci;         /* array of character info */
+    pointer    pglyphBase;     /* start of array of glyphs */
+{
+    ExtentInfoRec info;        /* used by QueryGlyphExtents() */
+    BoxRec bbox;       /* string's bounding box */
+    xRectangle backrect;/* backing rectangle to paint.
+                          in the general case, NOT necessarily
+                          the same as the string's bounding box
+                       */
+
+    CharInfoPtr pci;
+    int xorg, yorg;    /* origin of drawable in bitmap */
+    int widthDst;      /* width of dst in longwords */
+
+                       /* these keep track of the character origin */
+    PixelType *pdstBase;
+                       /* points to longword with character origin */
+    int xchar;         /* xorigin of char (mod 32) */
+
+                       /* these are used for placing the glyph */
+    register int xoff; /* x offset of left edge of glyph (mod 32) */
+    register PixelType *pdst;
+                       /* pointer to current longword in dst */
+
+    int w;             /* width of glyph in bits */
+    int h;             /* height of glyph */
+    int widthGlyph;    /* width of glyph, in bytes */
+    register unsigned char *pglyph;
+                       /* pointer to current row of glyph */
+
+                       /* used for putting down glyph */    
+    register PixelType tmpSrc;
+                       /* for getting bits from glyph */
+    register PixelType startmask;
+    register PixelType endmask;
+
+    register int nFirst;/* bits of glyph in current longword */
+    void (* oldFillArea)();
+                       /* we might temporarily usurp this
+                          field in devPriv */
+
+    if (!(pGC->planemask & 1))
+       return;
+
+    xorg = pDrawable->x;
+    yorg = pDrawable->y;
+    mfbGetPixelWidthAndPointer(pDrawable, widthDst, pdstBase);
+
+    QueryGlyphExtents(pGC->font, ppci, (unsigned long)nglyph, &info);
+
+    backrect.x = x;
+    backrect.y = y - FONTASCENT(pGC->font);
+    backrect.width = info.overallWidth;
+    backrect.height = FONTASCENT(pGC->font) + FONTDESCENT(pGC->font);
+
+    x += xorg;
+    y += yorg;
+
+    bbox.x1 = x + info.overallLeft;
+    bbox.x2 = x + info.overallRight;
+    bbox.y1 = y - info.overallAscent;
+    bbox.y2 = y + info.overallDescent;
+
+    /* UNCLEAN CODE
+       we know the mfbPolyFillRect uses only three fields in
+       devPrivate[mfbGCPrivateIndex].ptr, two of which (the rotated
+       tile/stipple and the ropFillArea) are 
+       irrelevant for solid filling, so we just poke the FillArea
+       field.  the GC is now in an inconsistent state, but we'll fix
+       it as soon as PolyFillRect returns.  fortunately, the server
+       is single threaded.
+
+    NOTE:
+       if you are not using the standard mfbFillRectangle code, you
+       need to poke any fields in the GC the rectangle stuff need
+       (probably alu, fgPixel, and fillStyle) and in devPrivate[mfbGCPrivateIndex].ptr
+       (probably rop or ropFillArea.)  You could just call ValidateGC,
+       but that is usually not a cheap thing to do.
+    */
+
+    oldFillArea = ((mfbPrivGC *)(pGC->devPrivates[mfbGCPrivateIndex].ptr))->FillArea;
+
+/* pcc doesn't like this.  why?
+    ((mfbPrivGC *)(pGC->devPrivates[mfbGCPrivateIndex].ptr))->FillArea = 
+                       ((pGC->bgPixel & 1) ? mfbSolidWhiteArea : mfbSolidBlackArea);
+*/
+    if (pGC->bgPixel & 1)
+        ((mfbPrivGC *)(pGC->devPrivates[mfbGCPrivateIndex].ptr))->FillArea = mfbSolidWhiteArea;
+    else
+        ((mfbPrivGC *)(pGC->devPrivates[mfbGCPrivateIndex].ptr))->FillArea = mfbSolidBlackArea;
+
+    mfbPolyFillRect(pDrawable, pGC, 1, &backrect);
+    ((mfbPrivGC *)(pGC->devPrivates[mfbGCPrivateIndex].ptr))->FillArea = oldFillArea;
+
+    /* the faint-hearted can open their eyes now */
+    switch (RECT_IN_REGION(pGC->pScreen, 
+       ((mfbPrivGC *)(pGC->devPrivates[mfbGCPrivateIndex].ptr))->pCompositeClip, &bbox))
+    {
+      case rgnOUT:
+       break;
+      case rgnIN:
+       pdstBase = mfbScanlineNoBankSwitch(pdstBase, x, y, widthDst);
+        xchar = x & PIM;
+
+        while(nglyph--)
+        {
+           pci = *ppci;
+           pglyph = FONTGLYPHBITS(pglyphBase, pci);
+           w = pci->metrics.rightSideBearing - pci->metrics.leftSideBearing;
+           h = pci->metrics.ascent + pci->metrics.descent;
+           widthGlyph = GLYPHWIDTHBYTESPADDED(pci);
+
+           /* start at top scanline of glyph */
+           pdst = pdstBase;
+
+           /* find correct word in scanline and x offset within it
+              for left edge of glyph
+           */
+           xoff = xchar + pci->metrics.leftSideBearing;
+           if (xoff > PLST)
+           {
+               pdst++;
+               xoff &= PIM;
+           }
+           else if (xoff < 0)
+           {
+               xoff += PPW;
+               pdst--;
+           }
+
+           pdst = mfbScanlineDelta(pdst, -pci->metrics.ascent, widthDst);
+
+           if ((xoff + w) <= PPW)
+           {
+               /* glyph all in one longword */
+               maskpartialbits(xoff, w, startmask);
+               while (h--)
+               {
+                   getleftbits(pglyph, w, tmpSrc);
+                   *pdst OPEQ (SCRRIGHT(tmpSrc, xoff) & startmask);
+                   pglyph += widthGlyph;
+                   mfbScanlineInc(pdst, widthDst);
+               }
+           }
+           else
+           {
+               /* glyph crosses longword boundary */
+               maskPPWbits(xoff, w, startmask, endmask);
+               nFirst = PPW - xoff;
+               while (h--)
+               {
+                   getleftbits(pglyph, w, tmpSrc);
+                   *pdst OPEQ (SCRRIGHT(tmpSrc, xoff) & startmask);
+                   *(pdst+1) OPEQ (SCRLEFT(tmpSrc, nFirst) & endmask);
+                   pglyph += widthGlyph;
+                   mfbScanlineInc(pdst, widthDst);
+               }
+           } /* glyph crosses longwords boundary */
+
+           /* update character origin */
+           x += pci->metrics.characterWidth;
+           xchar += pci->metrics.characterWidth;
+           if (xchar > PLST)
+           {
+               xchar -= PPW;
+               pdstBase++;
+           }
+           else if (xchar < 0)
+           {
+               xchar += PPW;
+               pdstBase--;
+           }
+           ppci++;
+        } /* while nglyph-- */
+       break;
+      case rgnPART:
+      {
+       TEXTPOS *ppos;
+       int nbox;
+       BoxPtr pbox;
+       RegionPtr cclip;
+       int xpos;               /* x position of char origin */
+       int i;
+       BoxRec clip;
+       int leftEdge, rightEdge;
+       int topEdge, bottomEdge;
+       int glyphRow;           /* first row of glyph not wholly
+                                  clipped out */
+       int glyphCol;           /* leftmost visible column of glyph */
+       int getWidth;           /* bits to get from glyph */
+
+       if(!(ppos = (TEXTPOS *)ALLOCATE_LOCAL(nglyph * sizeof(TEXTPOS))))
+           return;
+
+       pdstBase = mfbScanlineNoBankSwitch(pdstBase, x, y, widthDst);
+        xpos = x;
+       xchar = xpos & PIM;
+
+       for (i=0; i<nglyph; i++)
+       {
+           pci = ppci[i];
+
+           ppos[i].xpos = xpos;
+           ppos[i].xchar = xchar;
+           ppos[i].leftEdge = xpos + pci->metrics.leftSideBearing;
+           ppos[i].rightEdge = xpos + pci->metrics.rightSideBearing;
+           ppos[i].topEdge = y - pci->metrics.ascent;
+           ppos[i].bottomEdge = y + pci->metrics.descent;
+           ppos[i].pdstBase = pdstBase;
+           ppos[i].widthGlyph = GLYPHWIDTHBYTESPADDED(pci);
+
+           xpos += pci->metrics.characterWidth;
+           xchar += pci->metrics.characterWidth;
+           if (xchar > PLST)
+           {
+               xchar &= PIM;
+               pdstBase++;
+           }
+           else if (xchar < 0)
+           {
+               xchar += PPW;
+               pdstBase--;
+           }
+       }
+
+       cclip = ((mfbPrivGC *)(pGC->devPrivates[mfbGCPrivateIndex].ptr))->pCompositeClip;
+       pbox = REGION_RECTS(cclip);
+       nbox = REGION_NUM_RECTS(cclip);
+
+       /* HACK ALERT
+          since we continue out of the loop below so often, it
+          is easier to increment pbox at the  top than at the end.
+          don't try this at home.
+       */
+       pbox--;
+       while(nbox--)
+       {
+           pbox++;
+           clip.x1 = max(bbox.x1, pbox->x1);
+           clip.y1 = max(bbox.y1, pbox->y1);
+           clip.x2 = min(bbox.x2, pbox->x2);
+           clip.y2 = min(bbox.y2, pbox->y2);
+           if ((clip.x2<=clip.x1) || (clip.y2<=clip.y1))
+               continue;
+
+           for(i=0; i<nglyph; i++)
+           {
+               pci = ppci[i];
+               xchar = ppos[i].xchar;
+
+               /* clip the left and right edges */
+               if (ppos[i].leftEdge < clip.x1)
+                   leftEdge = clip.x1;
+               else
+                   leftEdge = ppos[i].leftEdge;
+
+               if (ppos[i].rightEdge > clip.x2)
+                   rightEdge = clip.x2;
+               else
+                   rightEdge = ppos[i].rightEdge;
+
+               w = rightEdge - leftEdge;
+               if (w <= 0)
+                   continue;
+
+               /* clip the top and bottom edges */
+               if (ppos[i].topEdge < clip.y1)
+                   topEdge = clip.y1;
+               else
+                   topEdge = ppos[i].topEdge;
+
+               if (ppos[i].bottomEdge > clip.y2)
+                   bottomEdge = clip.y2;
+               else
+                   bottomEdge = ppos[i].bottomEdge;
+
+               h = bottomEdge - topEdge;
+               if (h <= 0)
+                   continue;
+
+               glyphRow = (topEdge - y) + pci->metrics.ascent;
+               widthGlyph = ppos[i].widthGlyph;
+               pglyph = FONTGLYPHBITS(pglyphBase, pci);
+               pglyph += (glyphRow * widthGlyph);
+
+               pdst = ppos[i].pdstBase;
+
+               glyphCol = (leftEdge - ppos[i].xpos) -
+                          (pci->metrics.leftSideBearing);
+               getWidth = w + glyphCol;
+               xoff = xchar + (leftEdge - ppos[i].xpos);
+               if (xoff > PLST)
+               {
+                   xoff &= PIM;
+                   pdst++;
+               }
+               else if (xoff < 0)
+               {
+                   xoff += PPW;
+                   pdst--;
+               }
+
+               pdst = mfbScanlineDelta(pdst, -(y-topEdge), widthDst);
+
+               if ((xoff + w) <= PPW)
+               {
+                   maskpartialbits(xoff, w, startmask);
+                   while (h--)
+                   {
+                       getshiftedleftbits(pglyph, glyphCol, getWidth, tmpSrc);
+                       *pdst OPEQ (SCRRIGHT(tmpSrc, xoff) & startmask);
+                       pglyph += widthGlyph;
+                       mfbScanlineInc(pdst, widthDst);
+                   }
+               }
+               else
+               {
+                   maskPPWbits(xoff, w, startmask, endmask);
+                   nFirst = PPW - xoff;
+                   while (h--)
+                   {
+                       getshiftedleftbits(pglyph, glyphCol, getWidth, tmpSrc);
+                       *pdst OPEQ (SCRRIGHT(tmpSrc, xoff) & startmask);
+                       *(pdst+1) OPEQ (SCRLEFT(tmpSrc, nFirst) & endmask);
+                       pglyph += widthGlyph;
+                       mfbScanlineInc(pdst, widthDst);
+                   }
+               }
+           } /* for each glyph */
+       } /* while nbox-- */
+       DEALLOCATE_LOCAL(ppos);
+       break;
+      }
+      default:
+       break;
+    }
+}
diff --git a/Xserver/programs/Xserver/mfb/mfbline.c b/Xserver/programs/Xserver/mfb/mfbline.c
new file mode 100644 (file)
index 0000000..91a6131
--- /dev/null
@@ -0,0 +1,751 @@
+/***********************************************************
+
+Copyright (c) 1987  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+
+Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
+
+                        All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and its 
+documentation for any purpose and without fee is hereby granted, 
+provided that the above copyright notice appear in all copies and that
+both that copyright notice and this permission notice appear in 
+supporting documentation, and that the name of Digital not be
+used in advertising or publicity pertaining to distribution of the
+software without specific, written prior permission.  
+
+DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
+ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
+DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
+ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+SOFTWARE.
+
+******************************************************************/
+/* $XConsortium: mfbline.c,v 5.19 94/07/28 14:28:21 dpw Exp $ */
+#include "X.h"
+
+#include "gcstruct.h"
+#include "windowstr.h"
+#include "pixmapstr.h"
+#include "regionstr.h"
+#include "scrnintstr.h"
+#include "mistruct.h"
+
+#include "mfb.h"
+#include "maskbits.h"
+#include "miline.h"
+
+/* single-pixel lines on a color frame buffer
+
+   NON-SLOPED LINES
+   horizontal lines are always drawn left to right; we have to
+move the endpoints right by one after they're swapped.
+   horizontal lines will be confined to a single band of a
+region.  the code finds that band (giving up if the lower
+bound of the band is above the line we're drawing); then it
+finds the first box in that band that contains part of the
+line.  we clip the line to subsequent boxes in that band.
+   vertical lines are always drawn top to bottom (y-increasing.)
+this requires adding one to the y-coordinate of each endpoint
+after swapping.
+
+   SLOPED LINES
+   when clipping a sloped line, we bring the second point inside
+the clipping box, rather than one beyond it, and then add 1 to
+the length of the line before drawing it.  this lets us use
+the same box for finding the outcodes for both endpoints.  since
+the equation for clipping the second endpoint to an edge gives us
+1 beyond the edge, we then have to move the point towards the
+first point by one step on the major axis.
+   eventually, there will be a diagram here to explain what's going
+on.  the method uses Cohen-Sutherland outcodes to determine
+outsideness, and a method similar to Pike's layers for doing the
+actual clipping.
+
+*/
+
+void
+#ifdef POLYSEGMENT
+mfbSegmentSS (pDrawable, pGC, nseg, pSeg)
+    DrawablePtr        pDrawable;
+    GCPtr      pGC;
+    int                nseg;
+    register xSegment  *pSeg;
+#else
+mfbLineSS (pDrawable, pGC, mode, npt, pptInit)
+    DrawablePtr pDrawable;
+    GCPtr      pGC;
+    int                mode;           /* Origin or Previous */
+    int                npt;            /* number of points */
+    DDXPointPtr pptInit;
+#endif
+{
+    int nboxInit;
+    register int nbox;
+    BoxPtr pboxInit;
+    register BoxPtr pbox;
+#ifndef POLYSEGMENT
+    register DDXPointPtr ppt;  /* pointer to list of translated points */
+#endif
+
+    unsigned int oc1;          /* outcode of point 1 */
+    unsigned int oc2;          /* outcode of point 2 */
+
+    PixelType *addrlBase;      /* pointer to start of drawable */
+    PixelType *addrl;          /* address of destination pixmap */
+    int nlwidth;               /* width in longwords of destination pixmap */
+    int xorg, yorg;            /* origin of window */
+
+    int adx;           /* abs values of dx and dy */
+    int ady;
+    int signdx;                /* sign of dx and dy */
+    int signdy;
+    int e, e1, e2;             /* bresenham error and increments */
+    int len;                   /* length of segment */
+    int axis;                  /* major axis */
+    int octant;
+    unsigned int bias = miGetZeroLineBias(pDrawable->pScreen);
+
+                               /* a bunch of temporaries */
+    register int y1, y2;
+    register int x1, x2;
+    RegionPtr cclip;
+    int                    alu;
+
+    if (!(pGC->planemask & 1))
+       return;
+
+    cclip = ((mfbPrivGC *)(pGC->devPrivates[mfbGCPrivateIndex].ptr))->pCompositeClip;
+    alu = ((mfbPrivGC *)(pGC->devPrivates[mfbGCPrivateIndex].ptr))->rop;
+    pboxInit = REGION_RECTS(cclip);
+    nboxInit = REGION_NUM_RECTS(cclip);
+
+    mfbGetPixelWidthAndPointer(pDrawable, nlwidth, addrlBase);
+
+    xorg = pDrawable->x;
+    yorg = pDrawable->y;
+#ifdef POLYSEGMENT
+    while (nseg--)
+#else
+    ppt = pptInit;
+    x2 = ppt->x + xorg;
+    y2 = ppt->y + yorg;
+    while(--npt)
+#endif
+    {
+       nbox = nboxInit;
+       pbox = pboxInit;
+
+#ifdef POLYSEGMENT
+       x1 = pSeg->x1 + xorg;
+       y1 = pSeg->y1 + yorg;
+       x2 = pSeg->x2 + xorg;
+       y2 = pSeg->y2 + yorg;
+       pSeg++;
+#else
+       x1 = x2;
+       y1 = y2;
+       ++ppt;
+       if (mode == CoordModePrevious)
+       {
+           xorg = x1;
+           yorg = y1;
+       }
+       x2 = ppt->x + xorg;
+       y2 = ppt->y + yorg;
+#endif
+
+       if (x1 == x2) /* vertical line */
+       {
+           /* make the line go top to bottom of screen, keeping
+              endpoint semantics
+           */
+           if (y1 > y2)
+           {
+               register int tmp;
+
+               tmp = y2;
+               y2 = y1 + 1;
+               y1 = tmp + 1;
+#ifdef POLYSEGMENT
+               if (pGC->capStyle != CapNotLast)
+                   y1--;
+#endif
+           }
+#ifdef POLYSEGMENT
+           else if (pGC->capStyle != CapNotLast)
+               y2++;
+#endif
+           /* get to first band that might contain part of line */
+           while ((nbox) && (pbox->y2 <= y1))
+           {
+               pbox++;
+               nbox--;
+           }
+
+           if (nbox)
+           {
+               /* stop when lower edge of box is beyond end of line */
+               while((nbox) && (y2 >= pbox->y1))
+               {
+                   if ((x1 >= pbox->x1) && (x1 < pbox->x2))
+                   {
+                       int y1t, y2t;
+                       /* this box has part of the line in it */
+                       y1t = max(y1, pbox->y1);
+                       y2t = min(y2, pbox->y2);
+                       if (y1t != y2t)
+                       {
+                           mfbVertS (alu,
+                                     addrlBase, nlwidth, 
+                                     x1, y1t, y2t-y1t);
+                       }
+                   }
+                   nbox--;
+                   pbox++;
+               }
+           }
+#ifndef POLYSEGMENT
+           y2 = ppt->y + yorg;
+#endif
+       }
+       else if (y1 == y2) /* horizontal line */
+       {
+           /* force line from left to right, keeping
+              endpoint semantics
+           */
+           if (x1 > x2)
+           {
+               register int tmp;
+
+               tmp = x2;
+               x2 = x1 + 1;
+               x1 = tmp + 1;
+#ifdef POLYSEGMENT
+               if (pGC->capStyle != CapNotLast)
+                   x1--;
+#endif
+           }
+#ifdef POLYSEGMENT
+           else if (pGC->capStyle != CapNotLast)
+               x2++;
+#endif
+
+           /* find the correct band */
+           while( (nbox) && (pbox->y2 <= y1))
+           {
+               pbox++;
+               nbox--;
+           }
+
+           /* try to draw the line, if we haven't gone beyond it */
+           if ((nbox) && (pbox->y1 <= y1))
+           {
+               int tmp;
+
+               /* when we leave this band, we're done */
+               tmp = pbox->y1;
+               while((nbox) && (pbox->y1 == tmp))
+               {
+                   int x1t, x2t;
+
+                   if (pbox->x2 <= x1)
+                   {
+                       /* skip boxes until one might contain start point */
+                       nbox--;
+                       pbox++;
+                       continue;
+                   }
+
+                   /* stop if left of box is beyond right of line */
+                   if (pbox->x1 >= x2)
+                   {
+                       nbox = 0;
+                       break;
+                   }
+
+                   x1t = max(x1, pbox->x1);
+                   x2t = min(x2, pbox->x2);
+                   if (x1t != x2t)
+                   {
+                       mfbHorzS (alu,
+                                 addrlBase, nlwidth, 
+                                 x1t, y1, x2t-x1t);
+                   }
+                   nbox--;
+                   pbox++;
+               }
+           }
+#ifndef POLYSEGMENT
+           x2 = ppt->x + xorg;
+#endif
+       }
+       else    /* sloped line */
+       {
+           CalcLineDeltas(x1, y1, x2, y2, adx, ady, signdx, signdy,
+                          1, 1, octant);
+
+           if (adx > ady)
+           {
+               axis = X_AXIS;
+               e1 = ady << 1;
+               e2 = e1 - (adx << 1);
+               e = e1 - adx;
+           }
+           else
+           {
+               axis = Y_AXIS;
+               e1 = adx << 1;
+               e2 = e1 - (ady << 1);
+               e = e1 - ady;
+               SetYMajorOctant(octant);
+           }
+
+           FIXUP_ERROR(e, octant, bias);
+
+           /* we have bresenham parameters and two points.
+              all we have to do now is clip and draw.
+           */
+
+           while(nbox--)
+           {
+               oc1 = 0;
+               oc2 = 0;
+               OUTCODES(oc1, x1, y1, pbox);
+               OUTCODES(oc2, x2, y2, pbox);
+               if ((oc1 | oc2) == 0)
+               {
+                   if (axis == X_AXIS)
+                       len = adx;
+                   else
+                       len = ady;
+#ifdef POLYSEGMENT
+                   if (pGC->capStyle != CapNotLast)
+                       len++;
+#endif
+                   mfbBresS (alu,
+                         addrlBase, nlwidth,
+                         signdx, signdy, axis, x1, y1,
+                         e, e1, e2, len);
+                   break;
+               }
+               else if (oc1 & oc2)
+               {
+                   pbox++;
+               }
+               else
+               {
+                   int new_x1 = x1, new_y1 = y1, new_x2 = x2, new_y2 = y2;
+                   int clip1 = 0, clip2 = 0;
+                   int clipdx, clipdy;
+                   int err;
+                   
+                   if (miZeroClipLine(pbox->x1, pbox->y1, pbox->x2-1,
+                                      pbox->y2-1,
+                                      &new_x1, &new_y1, &new_x2, &new_y2,
+                                      adx, ady, &clip1, &clip2,
+                                      octant, bias, oc1, oc2) == -1)
+                   {
+                       pbox++;
+                       continue;
+                   }
+
+                   if (axis == X_AXIS)
+                       len = abs(new_x2 - new_x1);
+                   else
+                       len = abs(new_y2 - new_y1);
+#ifdef POLYSEGMENT
+                   if (clip2 != 0 || pGC->capStyle != CapNotLast)
+                       len++;
+#else
+                   len += (clip2 != 0);
+#endif
+                   if (len)
+                   {
+                       /* unwind bresenham error term to first point */
+                       if (clip1)
+                       {
+                           clipdx = abs(new_x1 - x1);
+                           clipdy = abs(new_y1 - y1);
+                           if (axis == X_AXIS)
+                               err = e+((clipdy*e2) + ((clipdx-clipdy)*e1));
+                           else
+                               err = e+((clipdx*e2) + ((clipdy-clipdx)*e1));
+                       }
+                       else
+                           err = e;
+                       mfbBresS   
+                           (alu,
+                            addrlBase, nlwidth,
+                            signdx, signdy, axis, new_x1, new_y1,
+                            err, e1, e2, len);
+                   }
+                   pbox++;
+               }
+           } /* while (nbox--) */
+       } /* sloped line */
+    } /* while (nline--) */
+
+#ifndef POLYSEGMENT
+
+    /* paint the last point if the end style isn't CapNotLast.
+       (Assume that a projecting, butt, or round cap that is one
+        pixel wide is the same as the single pixel of the endpoint.)
+    */
+
+    if ((pGC->capStyle != CapNotLast) &&
+       ((ppt->x + xorg != pptInit->x + pDrawable->x) ||
+        (ppt->y + yorg != pptInit->y + pDrawable->y) ||
+        (ppt == pptInit + 1)))
+    {
+       PixelType _mask;
+
+       if (alu == RROP_BLACK)
+               _mask = rmask[x2 & PIM];
+       else
+               _mask = mask[x2 & PIM];
+
+       nbox = nboxInit;
+       pbox = pboxInit;
+       while (nbox--)
+       {
+           if ((x2 >= pbox->x1) &&
+               (y2 >= pbox->y1) &&
+               (x2 <  pbox->x2) &&
+               (y2 <  pbox->y2))
+           {
+               addrl = mfbScanline(addrlBase, x2, y2, nlwidth);
+               switch(alu)
+               {
+                   case RROP_BLACK:
+                       *addrl &= _mask;
+                       break;
+                   case RROP_WHITE:
+                       *addrl |= _mask;
+                       break;
+                   case RROP_INVERT:
+                       *addrl ^= _mask;
+                       break;
+               }
+               break;
+           }
+           else
+               pbox++;
+       }
+    }
+#endif
+}
+
+/*
+ * Draw dashed 1-pixel lines.
+ */
+
+void
+#ifdef POLYSEGMENT
+mfbSegmentSD (pDrawable, pGC, nseg, pSeg)
+    DrawablePtr        pDrawable;
+    register GCPtr     pGC;
+    int                nseg;
+    register xSegment  *pSeg;
+#else
+mfbLineSD( pDrawable, pGC, mode, npt, pptInit)
+    DrawablePtr pDrawable;
+    register GCPtr pGC;
+    int mode;          /* Origin or Previous */
+    int npt;           /* number of points */
+    DDXPointPtr pptInit;
+#endif
+{
+    int nboxInit;
+    register int nbox;
+    BoxPtr pboxInit;
+    register BoxPtr pbox;
+#ifndef POLYSEGMENT
+    register DDXPointPtr ppt;  /* pointer to list of translated points */
+#endif
+
+    register unsigned int oc1; /* outcode of point 1 */
+    register unsigned int oc2; /* outcode of point 2 */
+
+    PixelType *addrl;          /* address of destination pixmap */
+    int nlwidth;               /* width in longwords of destination pixmap */
+    int xorg, yorg;            /* origin of window */
+
+    int adx;           /* abs values of dx and dy */
+    int ady;
+    int signdx;                /* sign of dx and dy */
+    int signdy;
+    int e, e1, e2;             /* bresenham error and increments */
+    int len;                   /* length of segment */
+    int axis;                  /* major axis */
+    int octant;
+    unsigned int bias = miGetZeroLineBias(pDrawable->pScreen);
+    int x1, x2, y1, y2;
+    RegionPtr cclip;
+    int                    fgrop, bgrop;
+    unsigned char   *pDash;
+    int                    dashOffset;
+    int                    numInDashList;
+    int                    dashIndex;
+    int                    isDoubleDash;
+    int                    dashIndexTmp, dashOffsetTmp;
+    int                    unclippedlen;
+
+    if (!(pGC->planemask & 1))
+       return;
+
+    cclip = ((mfbPrivGC *)(pGC->devPrivates[mfbGCPrivateIndex].ptr))->pCompositeClip;
+    fgrop = ((mfbPrivGC *)(pGC->devPrivates[mfbGCPrivateIndex].ptr))->rop;
+    pboxInit = REGION_RECTS(cclip);
+    nboxInit = REGION_NUM_RECTS(cclip);
+
+   mfbGetPixelWidthAndPointer(pDrawable, nlwidth, addrl); 
+
+    /* compute initial dash values */
+     
+    pDash = (unsigned char *) pGC->dash;
+    numInDashList = pGC->numInDashList;
+    isDoubleDash = (pGC->lineStyle == LineDoubleDash);
+    dashIndex = 0;
+    dashOffset = 0;
+    miStepDash ((int)pGC->dashOffset, &dashIndex, pDash,
+               numInDashList, &dashOffset);
+
+    if (isDoubleDash)
+       bgrop = mfbReduceRop(pGC->alu, pGC->bgPixel);
+
+    xorg = pDrawable->x;
+    yorg = pDrawable->y;
+#ifdef POLYSEGMENT
+    while (nseg--)
+#else
+    ppt = pptInit;
+    x2 = ppt->x + xorg;
+    y2 = ppt->y + yorg;
+    while(--npt)
+#endif
+    {
+       nbox = nboxInit;
+       pbox = pboxInit;
+
+#ifdef POLYSEGMENT
+       x1 = pSeg->x1 + xorg;
+       y1 = pSeg->y1 + yorg;
+       x2 = pSeg->x2 + xorg;
+       y2 = pSeg->y2 + yorg;
+       pSeg++;
+#else
+       x1 = x2;
+       y1 = y2;
+       ++ppt;
+       if (mode == CoordModePrevious)
+       {
+           xorg = x1;
+           yorg = y1;
+       }
+       x2 = ppt->x + xorg;
+       y2 = ppt->y + yorg;
+#endif
+
+       CalcLineDeltas(x1, y1, x2, y2, adx, ady, signdx, signdy, 1, 1, octant);
+
+       if (adx > ady)
+       {
+           axis = X_AXIS;
+           e1 = ady << 1;
+           e2 = e1 - (adx << 1);
+           e = e1 - adx;
+           unclippedlen = adx;
+       }
+       else
+       {
+           axis = Y_AXIS;
+           e1 = adx << 1;
+           e2 = e1 - (ady << 1);
+           e = e1 - ady;
+           unclippedlen = ady;
+           SetYMajorOctant(octant);
+       }
+
+       FIXUP_ERROR(e, octant, bias);
+
+       /* we have bresenham parameters and two points.
+          all we have to do now is clip and draw.
+       */
+
+       while(nbox--)
+       {
+           oc1 = 0;
+           oc2 = 0;
+           OUTCODES(oc1, x1, y1, pbox);
+           OUTCODES(oc2, x2, y2, pbox);
+           if ((oc1 | oc2) == 0)
+           {
+#ifdef POLYSEGMENT
+               if (pGC->capStyle != CapNotLast)
+                   unclippedlen++;
+               dashIndexTmp = dashIndex;
+               dashOffsetTmp = dashOffset;
+               mfbBresD (fgrop, bgrop,
+                     &dashIndexTmp, pDash, numInDashList,
+                     &dashOffsetTmp, isDoubleDash,
+                     addrl, nlwidth,
+                     signdx, signdy, axis, x1, y1,
+                     e, e1, e2, unclippedlen);
+               break;
+#else
+               mfbBresD (fgrop, bgrop,
+                     &dashIndex, pDash, numInDashList,
+                     &dashOffset, isDoubleDash,
+                     addrl, nlwidth,
+                     signdx, signdy, axis, x1, y1,
+                     e, e1, e2, unclippedlen);
+               goto dontStep;
+#endif
+           }
+           else if (oc1 & oc2)
+           {
+               pbox++;
+           }
+           else /* have to clip */
+           {
+               int new_x1 = x1, new_y1 = y1, new_x2 = x2, new_y2 = y2;
+               int clip1 = 0, clip2 = 0;
+               int clipdx, clipdy;
+               int err;
+               
+               if (miZeroClipLine(pbox->x1, pbox->y1, pbox->x2-1, pbox->y2-1,
+                                  &new_x1, &new_y1, &new_x2, &new_y2,
+                                  adx, ady, &clip1, &clip2,
+                                  octant, bias, oc1, oc2) == -1)
+               {
+                   pbox++;
+                   continue;
+               }
+               dashIndexTmp = dashIndex;
+               dashOffsetTmp = dashOffset;
+               if (clip1)
+               {
+                   int dlen;
+                   
+                   if (axis == X_AXIS)
+                       dlen = abs(new_x1 - x1);
+                   else
+                       dlen = abs(new_y1 - y1);
+                   miStepDash (dlen, &dashIndexTmp, pDash,
+                               numInDashList, &dashOffsetTmp);
+               }
+               if (axis == X_AXIS)
+                   len = abs(new_x2 - new_x1);
+               else
+                   len = abs(new_y2 - new_y1);
+#ifdef POLYSEGMENT
+               if (clip2 != 0 || pGC->capStyle != CapNotLast)
+                   len++;
+#else
+               len += (clip2 != 0);
+#endif
+               if (len)
+               {
+                   /* unwind bresenham error term to first point */
+                   if (clip1)
+                   {
+                       clipdx = abs(new_x1 - x1);
+                       clipdy = abs(new_y1 - y1);
+                       if (axis == X_AXIS)
+                           err = e+((clipdy*e2) + ((clipdx-clipdy)*e1));
+                       else
+                           err = e+((clipdx*e2) + ((clipdy-clipdx)*e1));
+                   }
+                   else
+                       err = e;
+                   mfbBresD (fgrop, bgrop,
+                             &dashIndexTmp, pDash, numInDashList,
+                             &dashOffsetTmp, isDoubleDash,
+                             addrl, nlwidth,
+                             signdx, signdy, axis, new_x1, new_y1,
+                             err, e1, e2, len);
+               }
+               pbox++;
+           }
+       } /* while (nbox--) */
+#ifndef POLYSEGMENT
+       /*
+        * walk the dash list around to the next line
+        */
+       miStepDash (unclippedlen, &dashIndex, pDash,
+                   numInDashList, &dashOffset);
+dontStep:      ;
+#endif
+    } /* while (nline--) */
+
+#ifndef POLYSEGMENT
+    /* paint the last point if the end style isn't CapNotLast.
+       (Assume that a projecting, butt, or round cap that is one
+        pixel wide is the same as the single pixel of the endpoint.)
+    */
+
+    if ((pGC->capStyle != CapNotLast) &&
+        ((dashIndex & 1) == 0 || isDoubleDash) &&
+       ((ppt->x + xorg != pptInit->x + pDrawable->x) ||
+        (ppt->y + yorg != pptInit->y + pDrawable->y) ||
+        (ppt == pptInit + 1)))
+    {
+       nbox = nboxInit;
+       pbox = pboxInit;
+       while (nbox--)
+       {
+           if ((x2 >= pbox->x1) &&
+               (y2 >= pbox->y1) &&
+               (x2 <  pbox->x2) &&
+               (y2 <  pbox->y2))
+           {
+               unsigned long _mask;
+               int rop;
+
+               rop = fgrop;
+               if (dashIndex & 1)
+                   rop = bgrop;
+               if (rop == RROP_BLACK)
+                   _mask = rmask[x2 & PIM];
+               else
+                   _mask = mask[x2 & PIM];
+               addrl = mfbScanline(addrl, x2, y2, nlwidth);
+               if (rop == RROP_BLACK)
+                   *addrl &= _mask;
+               else if (rop == RROP_WHITE)
+                   *addrl |= _mask;
+               else
+                   *addrl ^= _mask;
+               break;
+           }
+           else
+               pbox++;
+       }
+    }
+#endif
+}
diff --git a/Xserver/programs/Xserver/mfb/mfbmisc.c b/Xserver/programs/Xserver/mfb/mfbmisc.c
new file mode 100644 (file)
index 0000000..ced94b3
--- /dev/null
@@ -0,0 +1,92 @@
+/***********************************************************
+
+Copyright (c) 1987  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+
+Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
+
+                        All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and its 
+documentation for any purpose and without fee is hereby granted, 
+provided that the above copyright notice appear in all copies and that
+both that copyright notice and this permission notice appear in 
+supporting documentation, and that the name of Digital not be
+used in advertising or publicity pertaining to distribution of the
+software without specific, written prior permission.  
+
+DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
+ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
+DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
+ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+SOFTWARE.
+
+******************************************************************/
+/* $XConsortium: mfbmisc.c,v 5.4 94/04/17 20:28:27 dpw Exp $ */
+#include "X.h"
+#include "misc.h"
+#include "cursor.h"
+#include "scrnintstr.h"
+
+#include "mfb.h"
+
+/*ARGSUSED*/
+void
+mfbQueryBestSize(class, pwidth, pheight, pScreen)
+int class;
+unsigned short *pwidth;
+unsigned short *pheight;
+ScreenPtr pScreen;
+{
+    unsigned width, test;
+
+    switch(class)
+    {
+      case CursorShape:
+         if (*pwidth > pScreen->width)
+            *pwidth = pScreen->width;
+         if (*pheight > pScreen->height)
+            *pheight = pScreen->height;
+         break;
+      case TileShape:
+      case StippleShape:
+         width = *pwidth;
+         if (!width) break;
+         /* Return the closes power of two not less than what they gave me */
+         test = 0x80000000;
+         /* Find the highest 1 bit in the width given */
+         while(!(test & width))
+            test >>= 1;
+         /* If their number is greater than that, bump up to the next
+          *  power of two */
+         if((test - 1) & width)
+            test <<= 1;
+         *pwidth = test;
+         /* We don't care what height they use */
+         break;
+    }
+}
+
diff --git a/Xserver/programs/Xserver/mfb/mfbpixmap.c b/Xserver/programs/Xserver/mfb/mfbpixmap.c
new file mode 100644 (file)
index 0000000..8feccd1
--- /dev/null
@@ -0,0 +1,291 @@
+/***********************************************************
+
+Copyright (c) 1987  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+
+Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
+
+                        All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and its 
+documentation for any purpose and without fee is hereby granted, 
+provided that the above copyright notice appear in all copies and that
+both that copyright notice and this permission notice appear in 
+supporting documentation, and that the name of Digital not be
+used in advertising or publicity pertaining to distribution of the
+software without specific, written prior permission.  
+
+DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
+ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
+DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
+ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+SOFTWARE.
+
+******************************************************************/
+/* $XConsortium: mfbpixmap.c,v 5.13 94/04/17 20:28:28 dpw Exp $ */
+
+/* pixmap management
+   written by drewry, september 1986
+
+   on a monchrome device, a pixmap is a bitmap.
+*/
+
+#include "Xmd.h"
+#include "scrnintstr.h"
+#include "pixmapstr.h"
+#include "maskbits.h"
+
+#include "mfb.h"
+#include "mi.h"
+
+#include "servermd.h"
+
+PixmapPtr
+mfbCreatePixmap (pScreen, width, height, depth)
+    ScreenPtr  pScreen;
+    int                width;
+    int                height;
+    int                depth;
+{
+    PixmapPtr pPixmap;
+    int datasize;
+    int paddedWidth;
+
+    if (depth != 1)
+       return NullPixmap;
+    paddedWidth = BitmapBytePad(width);
+    datasize = height * paddedWidth;
+    pPixmap = AllocatePixmap(pScreen, datasize);
+    if (!pPixmap)
+       return NullPixmap;
+    pPixmap->drawable.type = DRAWABLE_PIXMAP;
+    pPixmap->drawable.class = 0;
+    pPixmap->drawable.pScreen = pScreen;
+    pPixmap->drawable.depth = depth;
+    pPixmap->drawable.bitsPerPixel = depth;
+    pPixmap->drawable.id = 0;
+    pPixmap->drawable.serialNumber = NEXT_SERIAL_NUMBER;
+    pPixmap->drawable.x = 0;
+    pPixmap->drawable.y = 0;
+    pPixmap->drawable.width = width;
+    pPixmap->drawable.height = height;
+    pPixmap->devKind = paddedWidth;
+    pPixmap->refcnt = 1;
+#ifdef PIXPRIV
+    pPixmap->devPrivate.ptr =  datasize ?
+               (pointer)((char *)pPixmap + pScreen->totalPixmapSize) : NULL;
+#else
+    pPixmap->devPrivate.ptr = (pointer)(pPixmap + 1);
+#endif
+    return pPixmap;
+}
+
+Bool
+mfbDestroyPixmap(pPixmap)
+    PixmapPtr pPixmap;
+{
+    if(--pPixmap->refcnt)
+       return TRUE;
+    xfree(pPixmap);
+    return TRUE;
+}
+
+
+PixmapPtr
+mfbCopyPixmap(pSrc)
+    register PixmapPtr pSrc;
+{
+    register PixmapPtr pDst;
+    int                size;
+    ScreenPtr pScreen;
+
+    size = pSrc->drawable.height * pSrc->devKind;
+    pScreen = pSrc->drawable.pScreen;
+    pDst = (*pScreen->CreatePixmap) (pScreen, pSrc->drawable.width, 
+                               pSrc->drawable.height, pSrc->drawable.depth);
+    if (!pDst)
+       return NullPixmap;
+    memmove((char *)pDst->devPrivate.ptr, (char *)pSrc->devPrivate.ptr, size);
+    return pDst;
+}
+
+
+/* replicates a pattern to be a full 32 bits wide.
+   relies on the fact that each scnaline is longword padded.
+   doesn't do anything if pixmap is not a factor of 32 wide.
+   changes width field of pixmap if successful, so that the fast
+       XRotatePixmap code gets used if we rotate the pixmap later.
+
+   calculate number of times to repeat
+   for each scanline of pattern
+      zero out area to be filled with replicate
+      left shift and or in original as many times as needed
+*/
+void
+mfbPadPixmap(pPixmap)
+    PixmapPtr pPixmap;
+{
+    register int width = pPixmap->drawable.width;
+    register int h;
+    register PixelType mask;
+    register PixelType *p;
+    register PixelType bits;   /* real pattern bits */
+    register int i;
+    int rep;                   /* repeat count for pattern */
+
+    if (width >= PPW)
+       return;
+
+    rep = PPW/width;
+    if (rep*width != PPW)
+       return;
+
+    mask = endtab[width];
+
+    p = (PixelType *)(pPixmap->devPrivate.ptr);
+    for (h=0; h < pPixmap->drawable.height; h++)
+    {
+       *p &= mask;
+       bits = *p;
+       for(i=1; i<rep; i++)
+       {
+           bits = SCRRIGHT(bits, width);
+           *p |= bits;
+       }
+       p++;
+    }
+    pPixmap->drawable.width = PPW;
+}
+
+/* Rotates pixmap pPix by w pixels to the right on the screen. Assumes that
+ * words are PPW bits wide, and that the least significant bit appears on the
+ * left.
+ */
+void
+mfbXRotatePixmap(pPix, rw)
+    PixmapPtr  pPix;
+    register int rw;
+{
+    register PixelType *pw, *pwFinal;
+    register PixelType t;
+
+    if (pPix == NullPixmap)
+        return;
+
+    pw = (PixelType *)pPix->devPrivate.ptr;
+    rw %= (int)pPix->drawable.width;
+    if (rw < 0)
+       rw += (int)pPix->drawable.width;
+    if(pPix->drawable.width == PPW)
+    {
+        pwFinal = pw + pPix->drawable.height;
+       while(pw < pwFinal)
+       {
+           t = *pw;
+           *pw++ = SCRRIGHT(t, rw) | 
+                   (SCRLEFT(t, (PPW-rw)) & endtab[rw]);
+       }
+    }
+    else
+    {
+       /* We no longer do this.  Validate doesn't try to rotate odd-size
+        * tiles or stipples.  mfbUnnatural<tile/stipple>FS works directly off
+        * the unrotate tile/stipple in the GC
+        */
+        ErrorF("X internal error: trying to rotate odd-sized pixmap.\n");
+    }
+
+}
+
+/* Rotates pixmap pPix by h lines.  Assumes that h is always less than
+   pPix->height
+   works on any width.
+ */
+void
+mfbYRotatePixmap(pPix, rh)
+    register PixmapPtr pPix;
+    int        rh;
+{
+    int nbyDown;       /* bytes to move down to row 0; also offset of
+                          row rh */
+    int nbyUp;         /* bytes to move up to line rh; also
+                          offset of first line moved down to 0 */
+    char *pbase;
+    char *ptmp;
+    int        height;
+
+    if (pPix == NullPixmap)
+       return;
+    height = (int) pPix->drawable.height;
+    rh %= height;
+    if (rh < 0)
+       rh += height;
+
+    pbase = (char *)pPix->devPrivate.ptr;
+
+    nbyDown = rh * pPix->devKind;
+    nbyUp = (pPix->devKind * height) - nbyDown;
+    if(!(ptmp = (char *)ALLOCATE_LOCAL(nbyUp)))
+       return;
+
+    memmove(ptmp, pbase, nbyUp);               /* save the low rows */
+    memmove(pbase, pbase+nbyUp, nbyDown);      /* slide the top rows down */
+    memmove(pbase+nbyDown, ptmp, nbyUp);       /* move lower rows up to row rh */
+    DEALLOCATE_LOCAL(ptmp);
+}
+
+void
+mfbCopyRotatePixmap(psrcPix, ppdstPix, xrot, yrot)
+    register PixmapPtr psrcPix, *ppdstPix;
+    int        xrot, yrot;
+{
+    register PixmapPtr pdstPix;
+
+    if ((pdstPix = *ppdstPix) &&
+       (pdstPix->devKind == psrcPix->devKind) &&
+       (pdstPix->drawable.height == psrcPix->drawable.height))
+    {
+       memmove((char *)pdstPix->devPrivate.ptr,
+               (char *)psrcPix->devPrivate.ptr,
+             psrcPix->drawable.height * psrcPix->devKind);
+       pdstPix->drawable.width = psrcPix->drawable.width;
+       pdstPix->drawable.serialNumber = NEXT_SERIAL_NUMBER;
+    }
+    else
+    {
+       if (pdstPix)
+           /* FIX XBUG 6168 */
+           (*pdstPix->drawable.pScreen->DestroyPixmap)(pdstPix);
+       *ppdstPix = pdstPix = mfbCopyPixmap(psrcPix);
+       if (!pdstPix)
+           return;
+    }
+    mfbPadPixmap(pdstPix);
+    if (xrot)
+       mfbXRotatePixmap(pdstPix, xrot);
+    if (yrot)
+       mfbYRotatePixmap(pdstPix, yrot);
+}
diff --git a/Xserver/programs/Xserver/mfb/mfbply1rct.c b/Xserver/programs/Xserver/mfb/mfbply1rct.c
new file mode 100644 (file)
index 0000000..20eb65d
--- /dev/null
@@ -0,0 +1,256 @@
+/*
+ * $XConsortium: mfbply1rct.c /main/10 1996/08/23 10:35:13 dpw $
+ *
+Copyright (c) 1990  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+ *
+ * Author:  Keith Packard, MIT X Consortium
+ */
+
+#include "X.h"
+
+#include "gcstruct.h"
+#include "windowstr.h"
+#include "pixmapstr.h"
+#include "regionstr.h"
+#include "scrnintstr.h"
+#include "mistruct.h"
+
+#include "mfb.h"
+#include "maskbits.h"
+
+#if defined(mips) || defined(sparc)
+#define GetHighWord(x) (((int) (x)) >> 16)
+#else
+#define GetHighWord(x) (((int) (x)) / 65536)
+#endif
+
+#if IMAGE_BYTE_ORDER == MSBFirst
+#define intToCoord(i,x,y)   (((x) = GetHighWord(i)), ((y) = (int) ((short) (i))))
+#define coordToInt(x,y)        (((x) << 16) | (y))
+#define intToX(i)      (GetHighWord(i))
+#define intToY(i)      ((int) ((short) i))
+#else
+#define intToCoord(i,x,y)   (((x) = (int) ((short) (i))), ((y) = GetHighWord(i)))
+#define coordToInt(x,y)        (((y) << 16) | (x))
+#define intToX(i)      ((int) ((short) (i)))
+#define intToY(i)      (GetHighWord(i))
+#endif
+
+void
+MFBFILLPOLY1RECT (pDrawable, pGC, shape, mode, count, ptsIn)
+    DrawablePtr        pDrawable;
+    GCPtr      pGC;
+    int                count;
+    DDXPointPtr        ptsIn;
+{
+    mfbPrivGCPtr    devPriv;
+    int                    nlwidth;
+    PixelType      *addrl, *addr;
+    int                    maxy;
+    int                    origin;
+    register int    vertex1, vertex2;
+    int                    c;
+    BoxPtr         extents;
+    int                    clip;
+    int                    y;
+    int                    *vertex1p, *vertex2p;
+    int                    *endp;
+    int                    x1, x2;
+    int                    dx1, dx2;
+    int                    dy1, dy2;
+    int                    e1, e2;
+    int                    step1, step2;
+    int                    sign1, sign2;
+    int                    h;
+    int                    l, r;
+    PixelType      mask, bits = ~((PixelType)0);
+    int                    nmiddle;
+
+    devPriv = (mfbPrivGC *)(pGC->devPrivates[mfbGCPrivateIndex].ptr);
+    if (mode == CoordModePrevious || shape != Convex ||
+       REGION_NUM_RECTS(devPriv->pCompositeClip) != 1)
+    {
+       miFillPolygon (pDrawable, pGC, shape, mode, count, ptsIn);
+       return;
+    }
+    origin = *((int *) &pDrawable->x);
+    vertex2 = origin - ((origin & 0x8000) << 1);
+    extents = &devPriv->pCompositeClip->extents;
+    vertex1 = *((int *) &extents->x1) - vertex2;
+    vertex2 = *((int *) &extents->x2) - vertex2 - 0x00010001;
+    clip = 0;
+    y = 32767;
+    maxy = 0;
+    vertex2p = (int *) ptsIn;
+    endp = vertex2p + count;
+    while (count--)
+    {
+       c = *vertex2p;
+       clip |= (c - vertex1) | (vertex2 - c);
+       c = intToY(c);
+       if (c < y) 
+       {
+           y = c;
+           vertex1p = vertex2p;
+       }
+       vertex2p++;
+       if (c > maxy)
+           maxy = c;
+    }
+    if (y == maxy)
+       return;
+
+    if (clip & 0x80008000)
+    {
+       miFillPolygon (pDrawable, pGC, shape, mode, vertex2p - (int *) ptsIn, ptsIn);
+       return;
+    }
+
+    mfbGetPixelWidthAndPointer(pDrawable, nlwidth, addrl);
+    addrl = mfbScanlineDelta(addrl, y + pDrawable->y, nlwidth);
+    origin = intToX(origin);
+    vertex2p = vertex1p;
+    vertex2 = vertex1 = *vertex2p++;
+    if (vertex2p == endp)
+       vertex2p = (int *) ptsIn;
+#define Setup(c,x,vertex,dx,dy,e,sign,step) {\
+    x = intToX(vertex); \
+    if (dy = intToY(c) - y) { \
+       dx = intToX(c) - x; \
+       step = 0; \
+       if (dx >= 0) \
+       { \
+           e = 0; \
+           sign = 1; \
+           if (dx >= dy) {\
+               step = dx / dy; \
+               dx = dx % dy; \
+           } \
+       } \
+       else \
+       { \
+           e = 1 - dy; \
+           sign = -1; \
+           dx = -dx; \
+           if (dx >= dy) { \
+               step = - (dx / dy); \
+               dx = dx % dy; \
+           } \
+       } \
+    } \
+    x += origin; \
+    vertex = c; \
+}
+
+#define Step(x,dx,dy,e,sign,step) {\
+    x += step; \
+    if ((e += dx) > 0) \
+    { \
+       x += sign; \
+       e -= dy; \
+    } \
+}
+    for (;;)
+    {
+       if (y == intToY(vertex1))
+       {
+           do
+           {
+               if (vertex1p == (int *) ptsIn)
+                   vertex1p = endp;
+               c = *--vertex1p;
+               Setup (c,x1,vertex1,dx1,dy1,e1,sign1,step1)
+           } while (y >= intToY(vertex1));
+           h = dy1;
+       }
+       else
+       {
+           Step(x1,dx1,dy1,e1,sign1,step1)
+           h = intToY(vertex1) - y;
+       }
+       if (y == intToY(vertex2))
+       {
+           do
+           {
+               c = *vertex2p++;
+               if (vertex2p == endp)
+                   vertex2p = (int *) ptsIn;
+               Setup (c,x2,vertex2,dx2,dy2,e2,sign2,step2)
+           } while (y >= intToY(vertex2));
+           if (dy2 < h)
+               h = dy2;
+       }
+       else
+       {
+           Step(x2,dx2,dy2,e2,sign2,step2)
+           if ((c = (intToY(vertex2) - y)) < h)
+               h = c;
+       }
+       /* fill spans for this segment */
+       y += h;
+       for (;;)
+       {
+           l = x1;
+           r = x2;
+           nmiddle = x2 - x1;
+           if (nmiddle < 0)
+           {
+               nmiddle = -nmiddle;
+               l = x2;
+               r = x1;
+           }
+           c = l & PIM;
+           l -= c;
+           l = l >> PWSH;
+           addr = addrl + l;
+           if (c + nmiddle < PPW)
+           {
+               mask = SCRRIGHT (bits,c) ^ SCRRIGHT (bits,c+nmiddle);
+               *addr OPEQ mask;
+           }
+           else
+           {
+               if (c)
+               {
+                   mask = SCRRIGHT(bits, c);
+                   *addr OPEQ mask;
+                   nmiddle += c - PPW;
+                   addr++;
+               }
+               nmiddle >>= PWSH;
+               Duff (nmiddle, *addr++ EQWHOLEWORD)
+               if (mask = ~SCRRIGHT(bits, r & PIM))
+                   *addr OPEQ mask;
+           }
+           if (!--h)
+               break;
+           mfbScanlineInc(addrl, nlwidth);
+           Step(x1,dx1,dy1,e1,sign1,step1)
+           Step(x2,dx2,dy2,e2,sign2,step2)
+       }
+       if (y == maxy)
+           break;
+       mfbScanlineInc(addrl, nlwidth);
+    }
+}
diff --git a/Xserver/programs/Xserver/mfb/mfbplygblt.c b/Xserver/programs/Xserver/mfb/mfbplygblt.c
new file mode 100644 (file)
index 0000000..3a917dd
--- /dev/null
@@ -0,0 +1,393 @@
+/***********************************************************
+
+Copyright (c) 1987  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+
+Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
+
+                        All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and its 
+documentation for any purpose and without fee is hereby granted, 
+provided that the above copyright notice appear in all copies and that
+both that copyright notice and this permission notice appear in 
+supporting documentation, and that the name of Digital not be
+used in advertising or publicity pertaining to distribution of the
+software without specific, written prior permission.  
+
+DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
+ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
+DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
+ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+SOFTWARE.
+
+******************************************************************/
+/* $XConsortium: mfbplygblt.c,v 5.14 94/04/17 20:28:29 dpw Exp $ */
+/* $XFree86: xc/programs/Xserver/mfb/mfbplygblt.c,v 3.0 1995/06/14 12:43:48 dawes Exp $ */
+
+#include "X.h"
+#include "Xmd.h"
+#include "Xproto.h"
+#include "mfb.h"
+#include "fontstruct.h"
+#include "dixfontstr.h"
+#include "gcstruct.h"
+#include "windowstr.h"
+#include "pixmapstr.h"
+#include "scrnintstr.h"
+#include "regionstr.h"
+#include "maskbits.h"
+#include "miscstruct.h"
+
+/*
+    we should eventually special-case fixed-width fonts, although
+its more important for ImageText, which is meant for terminal
+emulators.
+
+    this works for fonts with glyphs <= 32 bits wide.
+
+    the clipping calculations are done for worst-case fonts.
+we make no assumptions about the heights, widths, or bearings
+of the glyphs.  if we knew that the glyphs are all the same height,
+we could clip the tops and bottoms per clipping box, rather
+than per character per clipping box.  if we knew that the glyphs'
+left and right bearings were well-behaved, we could clip a single
+character at the start, output until the last unclipped
+character, and then clip the last one.  this is all straightforward
+to determine based on max-bounds and min-bounds from the font.
+    there is some inefficiency introduced in the per-character
+clipping to make what's going on clearer.
+
+    (it is possible, for example, for a font to be defined in which the
+next-to-last character in a font would be clipped out, but the last
+one wouldn't.  the code below deals with this.)
+
+    PolyText looks at the fg color and the rasterop; mfbValidateGC
+swaps in the right routine after looking at the reduced ratserop
+in the private field of the GC.  
+
+   the register allocations are provisional; in particualr startmask and
+endmask might not be the right things.  pglyph, xoff, pdst, and tmpSrc
+are fairly obvious, though.
+
+   to avoid source proliferation, this file is compiled
+three times:
+       MFBPOLYGLYPHBLT         OPEQ
+       mfbPolyGlyphBltWhite    |=
+       mfbPolyGlyphBltBlack    &=~
+       mfbPolyGlyphBltInvert   ^=
+*/
+
+void
+MFBPOLYGLYPHBLT(pDrawable, pGC, x, y, nglyph, ppci, pglyphBase)
+    DrawablePtr pDrawable;
+    GCPtr      pGC;
+    int        x, y;
+    unsigned int nglyph;
+    CharInfoPtr *ppci;         /* array of character info */
+    pointer    pglyphBase;     /* start of array of glyphs (unused in R5) */
+{
+    ExtentInfoRec info;        /* used by QueryGlyphExtents() */
+    BoxRec bbox;               /* string's bounding box */
+
+    CharInfoPtr pci;
+    int xorg, yorg;    /* origin of drawable in bitmap */
+    int widthDst;      /* width of dst in longwords */
+
+                       /* these keep track of the character origin */
+    PixelType *pdstBase;
+                       /* points to longword with character origin */
+    int xchar;         /* xorigin of char (mod 32) */
+
+                       /* these are used for placing the glyph */
+    register int xoff; /* x offset of left edge of glyph (mod 32) */
+    register PixelType *pdst;
+                       /* pointer to current longword in dst */
+
+    int w;             /* width of glyph in bits */
+    int h;             /* height of glyph */
+    int widthGlyph;    /* width of glyph, in bytes */
+    register unsigned char *pglyph;
+                       /* pointer to current row of glyph */
+
+                       /* used for putting down glyph */
+    register PixelType tmpSrc;
+                       /* for getting bits from glyph */
+    register PixelType startmask;
+    register PixelType endmask;
+    register int nFirst;/* bits of glyph in current longword */
+
+    if (!(pGC->planemask & 1))
+       return;
+
+    xorg = pDrawable->x;
+    yorg = pDrawable->y;
+    mfbGetPixelWidthAndPointer(pDrawable, widthDst, pdstBase);
+
+    x += xorg;
+    y += yorg;
+
+    QueryGlyphExtents(pGC->font, ppci, (unsigned long)nglyph, &info);
+    bbox.x1 = x + info.overallLeft;
+    bbox.x2 = x + info.overallRight;
+    bbox.y1 = y - info.overallAscent;
+    bbox.y2 = y + info.overallDescent;
+
+    switch (RECT_IN_REGION(pGC->pScreen, 
+           ((mfbPrivGC *)(pGC->devPrivates[mfbGCPrivateIndex].ptr))->pCompositeClip, &bbox))
+    {
+      case rgnOUT:
+       break;
+      case rgnIN:
+        pdstBase = mfbScanlineNoBankSwitch(pdstBase, x, y, widthDst);
+        xchar = x & PIM;
+
+        while(nglyph--)
+        {
+           pci = *ppci;
+           pglyph = FONTGLYPHBITS(pglyphBase, pci);
+           w = pci->metrics.rightSideBearing - pci->metrics.leftSideBearing;
+           h = pci->metrics.ascent + pci->metrics.descent;
+           widthGlyph = GLYPHWIDTHBYTESPADDED(pci);
+
+           /* start at top scanline of glyph */
+           pdst = pdstBase;
+
+           /* find correct word in scanline and x offset within it
+              for left edge of glyph
+           */
+           xoff = xchar + pci->metrics.leftSideBearing;
+           if (xoff > PLST)
+           {
+               pdst++;
+               xoff &= PIM;
+           }
+           else if (xoff < 0)
+           {
+               xoff += PPW;
+               pdst--;
+           }
+
+           pdst = mfbScanlineDelta(pdst, -pci->metrics.ascent, widthDst);
+
+           if ((xoff + w) <= PPW)
+           {
+               /* glyph all in one longword */
+               maskpartialbits(xoff, w, startmask);
+               while (h--)
+               {
+                   getleftbits(pglyph, w, tmpSrc);
+                   *pdst OPEQ (SCRRIGHT(tmpSrc, xoff) & startmask);
+                   pglyph += widthGlyph;
+                   mfbScanlineInc(pdst, widthDst);
+               }
+           }
+           else
+           {
+               /* glyph crosses longword boundary */
+               maskPPWbits(xoff, w, startmask, endmask);
+               nFirst = PPW - xoff;
+               while (h--)
+               {
+                   getleftbits(pglyph, w, tmpSrc);
+                   *pdst OPEQ (SCRRIGHT(tmpSrc, xoff) & startmask);
+                   *(pdst+1) OPEQ (SCRLEFT(tmpSrc, nFirst) & endmask);
+                   pglyph += widthGlyph;
+                   mfbScanlineInc(pdst, widthDst);
+               }
+           } /* glyph crosses longwords boundary */
+
+           /* update character origin */
+           x += pci->metrics.characterWidth;
+           xchar += pci->metrics.characterWidth;
+           if (xchar > PLST)
+           {
+               xchar -= PPW;
+               pdstBase++;
+           }
+           else if (xchar < 0)
+           {
+               xchar += PPW;
+               pdstBase--;
+           }
+           ppci++;
+        } /* while nglyph-- */
+       break;
+      case rgnPART:
+      {
+       TEXTPOS *ppos;
+       RegionPtr cclip;
+       int nbox;
+       BoxPtr pbox;
+       int xpos;               /* x position of char origin */
+       int i;
+       BoxRec clip;
+       int leftEdge, rightEdge;
+       int topEdge, bottomEdge;
+       int glyphRow;           /* first row of glyph not wholly
+                                  clipped out */
+       int glyphCol;           /* leftmost visible column of glyph */
+       int getWidth;           /* bits to get from glyph */
+
+       if(!(ppos = (TEXTPOS *)ALLOCATE_LOCAL(nglyph * sizeof(TEXTPOS))))
+           return;
+
+        pdstBase = mfbScanlineNoBankSwitch(pdstBase, x, y, widthDst);
+        xpos = x;
+       xchar = xpos & PIM;
+
+       for (i=0; i<nglyph; i++)
+       {
+           pci = ppci[i];
+
+           ppos[i].xpos = xpos;
+           ppos[i].xchar = xchar;
+           ppos[i].leftEdge = xpos + pci->metrics.leftSideBearing;
+           ppos[i].rightEdge = xpos + pci->metrics.rightSideBearing;
+           ppos[i].topEdge = y - pci->metrics.ascent;
+           ppos[i].bottomEdge = y + pci->metrics.descent;
+           ppos[i].pdstBase = pdstBase;
+           ppos[i].widthGlyph = GLYPHWIDTHBYTESPADDED(pci);
+
+           xpos += pci->metrics.characterWidth;
+           xchar += pci->metrics.characterWidth;
+           if (xchar > PLST)
+           {
+               xchar &= PIM;
+               pdstBase++;
+           }
+           else if (xchar < 0)
+           {
+               xchar += PPW;
+               pdstBase--;
+           }
+       }
+
+       cclip = ((mfbPrivGC *)(pGC->devPrivates[mfbGCPrivateIndex].ptr))->pCompositeClip;
+       pbox = REGION_RECTS(cclip);
+       nbox = REGION_NUM_RECTS(cclip);
+
+       for (; --nbox >= 0; pbox++)
+       {
+           clip.x1 = max(bbox.x1, pbox->x1);
+           clip.y1 = max(bbox.y1, pbox->y1);
+           clip.x2 = min(bbox.x2, pbox->x2);
+           clip.y2 = min(bbox.y2, pbox->y2);
+           if ((clip.x2<=clip.x1) || (clip.y2<=clip.y1))
+               continue;
+
+           for(i=0; i<nglyph; i++)
+           {
+               pci = ppci[i];
+               xchar = ppos[i].xchar;
+
+               /* clip the left and right edges */
+               if (ppos[i].leftEdge < clip.x1)
+                   leftEdge = clip.x1;
+               else
+                   leftEdge = ppos[i].leftEdge;
+
+               if (ppos[i].rightEdge > clip.x2)
+                   rightEdge = clip.x2;
+               else
+                   rightEdge = ppos[i].rightEdge;
+
+               w = rightEdge - leftEdge;
+               if (w <= 0)
+                   continue;
+
+               /* clip the top and bottom edges */
+               if (ppos[i].topEdge < clip.y1)
+                   topEdge = clip.y1;
+               else
+                   topEdge = ppos[i].topEdge;
+
+               if (ppos[i].bottomEdge > clip.y2)
+                   bottomEdge = clip.y2;
+               else
+                   bottomEdge = ppos[i].bottomEdge;
+
+               h = bottomEdge - topEdge;
+               if (h <= 0)
+                   continue;
+
+               glyphRow = (topEdge - y) + pci->metrics.ascent;
+               widthGlyph = ppos[i].widthGlyph;
+               pglyph = FONTGLYPHBITS(pglyphBase, pci);
+               pglyph += (glyphRow * widthGlyph);
+
+               pdst = ppos[i].pdstBase;
+
+               glyphCol = (leftEdge - ppos[i].xpos) -
+                          (pci->metrics.leftSideBearing);
+               getWidth = w + glyphCol;
+               xoff = xchar + (leftEdge - ppos[i].xpos);
+               if (xoff > PLST)
+               {
+                   xoff &= PIM;
+                   pdst++;
+               }
+               else if (xoff < 0)
+               {
+                   xoff += PPW;
+                   pdst--;
+               }
+
+               pdst = mfbScanlineDelta(pdst, -(y-topEdge), widthDst);
+
+               if ((xoff + w) <= PPW)
+               {
+                   maskpartialbits(xoff, w, startmask);
+                   while (h--)
+                   {
+                       getshiftedleftbits(pglyph, glyphCol, getWidth, tmpSrc);
+                       *pdst OPEQ (SCRRIGHT(tmpSrc, xoff) & startmask);
+                       pglyph += widthGlyph;
+                       mfbScanlineInc(pdst, widthDst);
+                   }
+               }
+               else
+               {
+                   maskPPWbits(xoff, w, startmask, endmask);
+                   nFirst = PPW - xoff;
+                   while (h--)
+                   {
+                       getshiftedleftbits(pglyph, glyphCol, getWidth, tmpSrc);
+                       *pdst OPEQ (SCRRIGHT(tmpSrc, xoff) & startmask);
+                       *(pdst+1) OPEQ (SCRLEFT(tmpSrc, nFirst) & endmask);
+                       pglyph += widthGlyph;
+                       mfbScanlineInc(pdst, widthDst);
+                   }
+               }
+           } /* for each glyph */
+       } /* while nbox-- */
+       DEALLOCATE_LOCAL(ppos);
+       break;
+      }
+      default:
+       break;
+    }
+}
diff --git a/Xserver/programs/Xserver/mfb/mfbpntarea.c b/Xserver/programs/Xserver/mfb/mfbpntarea.c
new file mode 100644 (file)
index 0000000..b8122d1
--- /dev/null
@@ -0,0 +1,297 @@
+/* Combined Purdue/PurduePlus patches, level 2.0, 1/17/89 */
+/***********************************************************
+
+Copyright (c) 1987  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+
+Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
+
+                        All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and its 
+documentation for any purpose and without fee is hereby granted, 
+provided that the above copyright notice appear in all copies and that
+both that copyright notice and this permission notice appear in 
+supporting documentation, and that the name of Digital not be
+used in advertising or publicity pertaining to distribution of the
+software without specific, written prior permission.  
+
+DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
+ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
+DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
+ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+SOFTWARE.
+
+******************************************************************/
+/* $XConsortium: mfbpntarea.c,v 5.7 94/04/17 20:28:29 dpw Exp $ */
+#include "X.h"
+
+#include "windowstr.h"
+#include "regionstr.h"
+#include "pixmapstr.h"
+#include "scrnintstr.h"
+
+#include "mfb.h"
+#include "maskbits.h"
+
+/* 
+   the solid fillers are called for rectangles and window backgrounds.
+   the boxes are already translated.
+   maybe this should always take a pixmap instead of a drawable?
+
+   NOTE:
+   iy = ++iy < tileHeight ? iy : 0
+is equivalent to iy%= tileheight, and saves a division.
+*/
+
+/*
+       MFBSOLIDFILLAREA        OPEQ    EQWHOLEOWRD
+       mfbSolidWhiteArea       |=      = ~0
+       mfbSolidBlackArea       &=~     = 0
+       mfbSolidInvertArea      ^=      ^= ~0
+
+EQWHOLEWORD is used to write whole longwords.  it could use OPEQ,
+but *p++ |= ~0 on at least two compilers generates much
+worse code than *p++ = ~0.  similarly for *p++ &= ~~0
+and *p++ = 0.
+
+*/
+
+/*ARGSUSED*/
+void
+MFBSOLIDFILLAREA(pDraw, nbox, pbox, alu, nop)
+    DrawablePtr pDraw;
+    int nbox;
+    BoxPtr pbox;
+    int alu;
+    PixmapPtr nop;
+{
+    int nlwidth;       /* width in longwords of the drawable */
+    int w;             /* width of current box */
+    register int h;    /* height of current box */
+    register PixelType *p;     /* pointer to bits we're writing */
+    register int nlw;  /* loop version of nlwMiddle */
+    register PixelType startmask;
+    register PixelType endmask;/* masks for reggedy bits at either end of line */
+    register int nlwExtra;     
+                       /* to get from right of box to left of next span */
+    int nlwMiddle;     /* number of longwords between sides of boxes */
+    PixelType *pbits;  /* pointer to start of drawable */
+
+    mfbGetPixelWidthAndPointer(pDraw, nlwidth, pbits);
+
+    while (nbox--)
+    {
+       w = pbox->x2 - pbox->x1;
+       h = pbox->y2 - pbox->y1;
+       p = mfbScanline(pbits, pbox->x1, pbox->y1, nlwidth);
+
+       if ( ((pbox->x1 & PIM) + w) < PPW)
+       {
+           maskpartialbits(pbox->x1, w, startmask);
+           nlwExtra = nlwidth;
+           Duff(h, *p OPEQ startmask; mfbScanlineInc(p, nlwExtra));
+       }
+       else
+       {
+           maskbits(pbox->x1, w, startmask, endmask, nlwMiddle);
+           nlwExtra = nlwidth - nlwMiddle;
+
+           if (startmask && endmask)
+           {
+               nlwExtra -= 1;
+               while (h--)
+               {
+                   nlw = nlwMiddle;
+                   *p OPEQ startmask;
+                   p++;
+                   Duff(nlw, *p++ EQWHOLEWORD);
+                   *p OPEQ endmask;
+                   mfbScanlineInc(p, nlwExtra);
+               }
+           }
+           else if (startmask && !endmask)
+           {
+               nlwExtra -= 1;
+               while (h--)
+               {
+                   nlw = nlwMiddle;
+                   *p OPEQ startmask;
+                   p++;
+                   Duff(nlw, *p++ EQWHOLEWORD);
+                   mfbScanlineInc(p, nlwExtra);
+               }
+           }
+           else if (!startmask && endmask)
+           {
+               while (h--)
+               {
+                   nlw = nlwMiddle;
+                   Duff(nlw, *p++ EQWHOLEWORD);
+                   *p OPEQ endmask;
+                   mfbScanlineInc(p, nlwExtra);
+               }
+           }
+           else /* no ragged bits at either end */
+           {
+               while (h--)
+               {
+                   nlw = nlwMiddle;
+                   Duff(nlw, *p++ EQWHOLEWORD);
+                   mfbScanlineInc(p, nlwExtra);
+               }
+           }
+       }
+        pbox++;
+    }
+}
+
+
+
+/* stipple a list of boxes
+
+you can use the reduced rasterop for stipples.  if rrop is
+black, AND the destination with (not stipple pattern).  if rrop is
+white OR the destination with the stipple pattern.  if rrop is invert,
+XOR the destination with the stipple pattern.
+
+       MFBSTIPPLEFILLAREA      OPEQ
+       mfbStippleWhiteArea     |=
+       mfbStippleBlackArea     &=~
+       mfbStippleInveryArea    ^=
+*/
+
+/*ARGSUSED*/
+void
+MFBSTIPPLEFILLAREA(pDraw, nbox, pbox, alu, pstipple)
+    DrawablePtr pDraw;
+    int nbox;
+    BoxPtr pbox;
+    int alu;
+    PixmapPtr pstipple;
+{
+    register PixelType *psrc;
+                       /* pointer to bits in tile, if needed */
+    int tileHeight;    /* height of the tile */
+    register PixelType srcpix; 
+
+    int nlwidth;       /* width in longwords of the drawable */
+    int w;             /* width of current box */
+    register int nlw;  /* loop version of nlwMiddle */
+    register PixelType *p;     /* pointer to bits we're writing */
+    register int h;    /* height of current box */
+    PixelType startmask;
+    PixelType endmask; /* masks for reggedy bits at either end of line */
+    int nlwMiddle;     /* number of longwords between sides of boxes */
+    int nlwExtra;      /* to get from right of box to left of next span */
+    register int iy;   /* index of current scanline in tile */
+    PixelType *pbits;  /* pointer to start of drawable */
+
+    mfbGetPixelWidthAndPointer(pDraw, nlwidth, pbits);
+
+    tileHeight = pstipple->drawable.height;
+    psrc = (PixelType *)(pstipple->devPrivate.ptr);
+
+    while (nbox--)
+    {
+       w = pbox->x2 - pbox->x1;
+       h = pbox->y2 - pbox->y1;
+       iy = pbox->y1 % tileHeight;
+       p = mfbScanline(pbits, pbox->x1, pbox->y1, nlwidth);
+
+       if ( ((pbox->x1 & PIM) + w) < PPW)
+       {
+           maskpartialbits(pbox->x1, w, startmask);
+           nlwExtra = nlwidth;
+           while (h--)
+           {
+               srcpix = psrc[iy];
+               iy = ++iy < tileHeight ? iy : 0;
+               *p OPEQ (srcpix & startmask);
+               mfbScanlineInc(p, nlwExtra);
+           }
+       }
+       else
+       {
+           maskbits(pbox->x1, w, startmask, endmask, nlwMiddle);
+           nlwExtra = nlwidth - nlwMiddle;
+
+           if (startmask && endmask)
+           {
+               nlwExtra -= 1;
+               while (h--)
+               {
+                   srcpix = psrc[iy];
+                   iy = ++iy < tileHeight ? iy : 0;
+                   nlw = nlwMiddle;
+                   *p OPEQ (srcpix & startmask);
+                   p++;
+                   Duff (nlw, *p++ OPEQ srcpix);
+                   *p OPEQ (srcpix & endmask);
+                   mfbScanlineInc(p, nlwExtra);
+               }
+           }
+           else if (startmask && !endmask)
+           {
+               nlwExtra -= 1;
+               while (h--)
+               {
+                   srcpix = psrc[iy];
+                   iy = ++iy < tileHeight ? iy : 0;
+                   nlw = nlwMiddle;
+                   *p OPEQ (srcpix & startmask);
+                   p++;
+                   Duff(nlw, *p++ OPEQ srcpix);
+                   mfbScanlineInc(p, nlwExtra);
+               }
+           }
+           else if (!startmask && endmask)
+           {
+               while (h--)
+               {
+                   srcpix = psrc[iy];
+                   iy = ++iy < tileHeight ? iy : 0;
+                   nlw = nlwMiddle;
+                   Duff(nlw, *p++ OPEQ srcpix);
+                   *p OPEQ (srcpix & endmask);
+                   mfbScanlineInc(p, nlwExtra);
+               }
+           }
+           else /* no ragged bits at either end */
+           {
+               while (h--)
+               {
+                   srcpix = psrc[iy];
+                   iy = ++iy < tileHeight ? iy : 0;
+                   nlw = nlwMiddle;
+                   Duff(nlw, *p++ OPEQ srcpix);
+                   mfbScanlineInc(p, nlwExtra);
+               }
+           }
+       }
+        pbox++;
+    }
+}
diff --git a/Xserver/programs/Xserver/mfb/mfbpntwin.c b/Xserver/programs/Xserver/mfb/mfbpntwin.c
new file mode 100644 (file)
index 0000000..bccadc0
--- /dev/null
@@ -0,0 +1,124 @@
+/* $XConsortium: mfbpntwin.c,v 5.12 94/04/17 20:28:30 dpw Exp $ */
+/* Combined Purdue/PurduePlus patches, level 2.0, 1/17/89 */
+/***********************************************************
+
+Copyright (c) 1987  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+
+Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
+
+                        All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and its 
+documentation for any purpose and without fee is hereby granted, 
+provided that the above copyright notice appear in all copies and that
+both that copyright notice and this permission notice appear in 
+supporting documentation, and that the name of Digital not be
+used in advertising or publicity pertaining to distribution of the
+software without specific, written prior permission.  
+
+DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
+ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
+DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
+ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+SOFTWARE.
+
+******************************************************************/
+
+#include "X.h"
+
+#include "windowstr.h"
+#include "regionstr.h"
+#include "pixmapstr.h"
+#include "scrnintstr.h"
+
+#include "mfb.h"
+#include "maskbits.h"
+#include "mi.h"
+
+void
+mfbPaintWindow(pWin, pRegion, what)
+    WindowPtr  pWin;
+    RegionPtr  pRegion;
+    int                what;
+{
+    register mfbPrivWin        *pPrivWin;
+
+    pPrivWin = (mfbPrivWin *)(pWin->devPrivates[mfbWindowPrivateIndex].ptr);
+    
+    switch (what) {
+    case PW_BACKGROUND:
+       switch (pWin->backgroundState) {
+       case None:
+           return;
+       case ParentRelative:
+           do {
+               pWin = pWin->parent;
+           } while (pWin->backgroundState == ParentRelative);
+           (*pWin->drawable.pScreen->PaintWindowBackground)(pWin, pRegion,
+                                                            what);
+           return;
+       case BackgroundPixmap:
+           if (pPrivWin->fastBackground)
+           {
+               mfbTileAreaPPWCopy((DrawablePtr)pWin, REGION_NUM_RECTS(pRegion),
+                                 REGION_RECTS(pRegion), GXcopy,
+                                 pPrivWin->pRotatedBackground);
+               return;
+           }
+           break;
+       case BackgroundPixel:
+           if (pWin->background.pixel & 1)
+               mfbSolidWhiteArea((DrawablePtr)pWin, REGION_NUM_RECTS(pRegion),
+                                 REGION_RECTS(pRegion), GXset, NullPixmap);
+           else
+               mfbSolidBlackArea((DrawablePtr)pWin, REGION_NUM_RECTS(pRegion),
+                                 REGION_RECTS(pRegion), GXclear, NullPixmap);
+           return;
+       }
+       break;
+    case PW_BORDER:
+       if (pWin->borderIsPixel)
+       {
+           if (pWin->border.pixel & 1)
+               mfbSolidWhiteArea((DrawablePtr)pWin, REGION_NUM_RECTS(pRegion),
+                                 REGION_RECTS(pRegion), GXset, NullPixmap);
+           else
+               mfbSolidBlackArea((DrawablePtr)pWin, REGION_NUM_RECTS(pRegion),
+                                 REGION_RECTS(pRegion), GXclear, NullPixmap);
+           return;
+       }
+       else if (pPrivWin->fastBorder)
+       {
+           mfbTileAreaPPWCopy((DrawablePtr)pWin, REGION_NUM_RECTS(pRegion),
+                                 REGION_RECTS(pRegion), GXcopy,
+                                 pPrivWin->pRotatedBorder);
+           return;
+       }
+       break;
+    }
+    miPaintWindow(pWin, pRegion, what);
+}
diff --git a/Xserver/programs/Xserver/mfb/mfbpolypnt.c b/Xserver/programs/Xserver/mfb/mfbpolypnt.c
new file mode 100644 (file)
index 0000000..fe9fca3
--- /dev/null
@@ -0,0 +1,141 @@
+/* Combined Purdue/PurduePlus patches, level 2.0, 1/17/89 */
+/***********************************************************
+
+Copyright (c) 1987  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+
+Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
+
+                        All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and its 
+documentation for any purpose and without fee is hereby granted, 
+provided that the above copyright notice appear in all copies and that
+both that copyright notice and this permission notice appear in 
+supporting documentation, and that the name of Digital not be
+used in advertising or publicity pertaining to distribution of the
+software without specific, written prior permission.  
+
+DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
+ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
+DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
+ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+SOFTWARE.
+
+******************************************************************/
+/* $XConsortium: mfbpolypnt.c,v 5.6 94/04/17 20:28:30 dpw Exp $ */
+
+#include "X.h"
+#include "Xprotostr.h"
+#include "pixmapstr.h"
+#include "gcstruct.h"
+#include "windowstr.h"
+#include "miscstruct.h"
+#include "regionstr.h"
+#include "scrnintstr.h"
+
+#include "mfb.h"
+#include "maskbits.h"
+
+void
+mfbPolyPoint(pDrawable, pGC, mode, npt, pptInit)
+    register DrawablePtr pDrawable;
+    GCPtr      pGC;
+    int                mode;           /* Origin or Previous */
+    int                npt;
+    xPoint     *pptInit;
+{
+
+    register BoxPtr pbox;
+    register int nbox;
+
+    register PixelType *addrl;
+    int nlwidth;
+
+    int nptTmp;
+    register xPoint *ppt;
+
+    register int x;
+    register int y;
+    register int rop;
+    mfbPrivGC  *pGCPriv;
+
+    if (!(pGC->planemask & 1))
+       return;
+
+    pGCPriv = (mfbPrivGC *) pGC->devPrivates[mfbGCPrivateIndex].ptr;
+    rop = pGCPriv->rop;
+
+    mfbGetPixelWidthAndPointer(pDrawable, nlwidth, addrl);
+
+    if ((mode == CoordModePrevious) && (npt > 1))
+    {
+       for (ppt = pptInit + 1, nptTmp = npt - 1; --nptTmp >= 0; ppt++)
+       {
+           ppt->x += (ppt-1)->x;
+           ppt->y += (ppt-1)->y;
+       }
+    }
+
+    nbox = REGION_NUM_RECTS(pGCPriv->pCompositeClip);
+    pbox = REGION_RECTS(pGCPriv->pCompositeClip);
+    for (; --nbox >= 0; pbox++)
+    {
+       if (rop == RROP_BLACK)
+       {
+           for (ppt = pptInit, nptTmp = npt; --nptTmp >= 0; ppt++)
+           {
+               x = ppt->x + pDrawable->x;
+               y = ppt->y + pDrawable->y;
+               if ((x >= pbox->x1) && (x < pbox->x2) &&
+                   (y >= pbox->y1) && (y < pbox->y2))
+                   *mfbScanline(addrl, x, y, nlwidth) &= rmask[x & PIM];
+           }
+       }
+       else if (rop == RROP_WHITE)
+       {
+           for (ppt = pptInit, nptTmp = npt; --nptTmp >= 0; ppt++)
+           {
+               x = ppt->x + pDrawable->x;
+               y = ppt->y + pDrawable->y;
+               if ((x >= pbox->x1) && (x < pbox->x2) &&
+                   (y >= pbox->y1) && (y < pbox->y2))
+                   *mfbScanline(addrl, x, y, nlwidth) |= mask[x & PIM];
+           }
+       }
+       else if (rop == RROP_INVERT)
+       {
+           for (ppt = pptInit, nptTmp = npt; --nptTmp >= 0; ppt++)
+           {
+               x = ppt->x + pDrawable->x;
+               y = ppt->y + pDrawable->y;
+               if ((x >= pbox->x1) && (x < pbox->x2) &&
+                   (y >= pbox->y1) && (y < pbox->y2))
+                   *mfbScanline(addrl, x, y, nlwidth) ^= mask[x & PIM];
+           }
+       }
+    }
+}
diff --git a/Xserver/programs/Xserver/mfb/mfbpushpxl.c b/Xserver/programs/Xserver/mfb/mfbpushpxl.c
new file mode 100644 (file)
index 0000000..690c56c
--- /dev/null
@@ -0,0 +1,279 @@
+/***********************************************************
+
+Copyright (c) 1987  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+
+Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
+
+                        All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and its 
+documentation for any purpose and without fee is hereby granted, 
+provided that the above copyright notice appear in all copies and that
+both that copyright notice and this permission notice appear in 
+supporting documentation, and that the name of Digital not be
+used in advertising or publicity pertaining to distribution of the
+software without specific, written prior permission.  
+
+DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
+ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
+DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
+ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+SOFTWARE.
+
+******************************************************************/
+/* $XConsortium: mfbpushpxl.c,v 5.6 94/04/17 20:28:31 dpw Exp $ */
+
+#include "X.h"
+#include "gcstruct.h"
+#include "scrnintstr.h"
+#include "pixmapstr.h"
+#include "miscstruct.h"
+#include "maskbits.h"
+#include "regionstr.h"
+#include "mfb.h"
+
+/*  mfbSolidPP is courtesy of xhacks@csri.toronto.edu
+
+    For fillStyle==FillSolid, a monochrome PushPixels can be reduced to
+    a ROP in the following way:  (Note that the ROP is the same as the
+    result of ROP(src=0x3,dst=0x5))
+
+                       src=0011 0000 0011
+                       dst=0101 0101 0101
+                       rop      fg=0 fg=1
+       GXclear         0x0 0000 0100 0100 0
+       GXand           0x1 0001 0100 0101  s&d
+       GXandReverse    0x2 0010 0100 0110 s&~d
+       GXcopy          0x3 0011 0100 0111 s
+       GXandInverted   0x4 0100 0101 0100 ~s&d
+       GXnoop          0x5 0101 0101 0101 d
+       GXxor           0x6 0110 0101 0110 s^d
+       GXor            0x7 0111 0101 0111 s|d
+       GXnor           0x8 1000 0110 0100 ~s&~d
+       GXequiv         0x9 1001 0110 0101 ~s^d
+       GXinvert        0xa 1010 0110 0110 ~d
+       GXorReverse     0xb 1011 0110 0111 s|~d
+       GXcopyInverted  0xc 1100 0111 0100 ~s
+       GXorInverted    0xd 1101 0111 0101 ~s|d
+       GXnand          0xe 1110 0111 0110 ~s|~d
+       GXset           0xf 1111 0111 0111 1
+
+For src=0: newRop = 0x4|(rop>>2)
+For src=1: newRop = 0x4|(rop&3)
+*/
+
+/* mfbSolidPP -- squeegees the forground color of pGC through pBitMap
+ * into pDrawable.  pBitMap is a stencil (dx by dy of it is used, it may
+ * be bigger) which is placed on the drawable at xOrg, yOrg.  Where a 1 bit
+ * is set in the bitmap, the fill style is put onto the drawable using
+ * the GC's logical function. The drawable is not changed where the bitmap
+ * has a zero bit or outside the area covered by the stencil.
+ */
+void
+mfbSolidPP(pGC, pBitMap, pDrawable, dx, dy, xOrg, yOrg)
+    GCPtr      pGC;
+    PixmapPtr  pBitMap;
+    DrawablePtr pDrawable;
+    int                dx, dy, xOrg, yOrg;
+{
+    unsigned char alu;
+    RegionRec rgnDst;
+    DDXPointPtr pptSrc;
+    BoxRec srcBox;
+    register DDXPointPtr ppt;
+    register BoxPtr pbox;
+    int i;
+
+    if (!pGC->planemask & 1) return;
+
+    /* compute the reduced rop function */
+    alu = pGC->alu;
+    if (!(pGC->fgPixel&1)) alu >>= 2;
+    alu = (alu & 0x3) | 0x4;
+    if (alu == GXnoop) return;
+
+    srcBox.x1 = xOrg;
+    srcBox.y1 = yOrg;
+    srcBox.x2 = xOrg + dx;
+    srcBox.y2 = yOrg + dy;
+    REGION_INIT(pGC->pScreen, &rgnDst, &srcBox, 1);
+
+    /* clip the shape of the dst to the destination composite clip */
+    REGION_INTERSECT(pGC->pScreen, &rgnDst, &rgnDst,
+       ((mfbPrivGC *)(pGC->devPrivates[mfbGCPrivateIndex].ptr))->pCompositeClip);
+
+    if (!REGION_NIL(&rgnDst))
+    {
+       i = REGION_NUM_RECTS(&rgnDst);
+       pptSrc = (DDXPointPtr)ALLOCATE_LOCAL(i * sizeof(DDXPointRec));
+        if(pptSrc)
+        {
+           for (pbox = REGION_RECTS(&rgnDst), ppt = pptSrc;
+                --i >= 0;
+                pbox++, ppt++)
+           {
+               ppt->x = pbox->x1 - xOrg;
+               ppt->y = pbox->y1 - yOrg;
+           }
+           mfbDoBitblt((DrawablePtr)pBitMap, pDrawable, alu, &rgnDst, pptSrc);
+           DEALLOCATE_LOCAL(pptSrc);
+       }
+    }
+    REGION_UNINIT(pGC->pScreen, &rgnDst);
+}
+
+#define NPT 128
+
+/* mfbPushPixels -- squeegees the forground color of pGC through pBitMap
+ * into pDrawable.  pBitMap is a stencil (dx by dy of it is used, it may
+ * be bigger) which is placed on the drawable at xOrg, yOrg.  Where a 1 bit
+ * is set in the bitmap, the fill style is put onto the drawable using
+ * the GC's logical function. The drawable is not changed where the bitmap
+ * has a zero bit or outside the area covered by the stencil.
+ */
+void
+mfbPushPixels(pGC, pBitMap, pDrawable, dx, dy, xOrg, yOrg)
+    GCPtr      pGC;
+    PixmapPtr  pBitMap;
+    DrawablePtr pDrawable;
+    int                dx, dy, xOrg, yOrg;
+{
+    int                h, dxDivPPW, ibEnd;
+    PixelType *pwLineStart;
+    register PixelType *pw, *pwEnd;
+    register PixelType mask;
+    register int ib;
+    register PixelType w;
+    register int ipt;          /* index into above arrays */
+    Bool       fInBox;
+    DDXPointRec        pt[NPT];
+    int                width[NPT];
+
+    /* Now scan convert the pixmap and use the result to call fillspans in
+     * in the drawable with the original GC */
+    ipt = 0;
+    dxDivPPW = dx/PPW;
+    for(h = 0; h < dy; h++)
+    {
+
+       pw = (PixelType *)
+            (((char *)(pBitMap->devPrivate.ptr))+(h * pBitMap->devKind));
+       pwLineStart = pw;
+       /* Process all words which are fully in the pixmap */
+       
+       fInBox = FALSE;
+       pwEnd = pwLineStart + dxDivPPW;
+       while(pw  < pwEnd)
+       {
+           w = *pw;
+           mask = endtab[1];
+           for(ib = 0; ib < PPW; ib++)
+           {
+               if(w & mask)
+               {
+                   if(!fInBox)
+                   {
+                       pt[ipt].x = ((pw - pwLineStart) << PWSH) + ib + xOrg;
+                       pt[ipt].y = h + yOrg;
+                       /* start new box */
+                       fInBox = TRUE;
+                   }
+               }
+               else
+               {
+                   if(fInBox)
+                   {
+                       width[ipt] = ((pw - pwLineStart) << PWSH) + 
+                                    ib + xOrg - pt[ipt].x;
+                       if (++ipt >= NPT)
+                       {
+                           (*pGC->ops->FillSpans)(pDrawable, pGC, NPT, pt,
+                                             width, TRUE);
+                           ipt = 0;
+                       }
+                       /* end box */
+                       fInBox = FALSE;
+                   }
+               }
+               mask = SCRRIGHT(mask, 1);
+           }
+           pw++;
+       }
+       ibEnd = dx & PIM;
+       if(ibEnd)
+       {
+           /* Process final partial word on line */
+           w = *pw;
+           mask = endtab[1];
+           for(ib = 0; ib < ibEnd; ib++)
+           {
+               if(w & mask)
+               {
+                   if(!fInBox)
+                   {
+                       /* start new box */
+                       pt[ipt].x = ((pw - pwLineStart) << PWSH) + ib + xOrg;
+                       pt[ipt].y = h + yOrg;
+                       fInBox = TRUE;
+                   }
+               }
+               else
+               {
+                   if(fInBox)
+                   {
+                       /* end box */
+                       width[ipt] = ((pw - pwLineStart) << PWSH) + 
+                                    ib + xOrg - pt[ipt].x;
+                       if (++ipt >= NPT)
+                       {
+                           (*pGC->ops->FillSpans)(pDrawable, pGC, NPT, pt,
+                                             width, TRUE);
+                           ipt = 0;
+                       }
+                       fInBox = FALSE;
+                   }
+               }
+               mask = SCRRIGHT(mask, 1);
+           }
+       }
+       /* If scanline ended with last bit set, end the box */
+       if(fInBox)
+       {
+           width[ipt] = dx + xOrg - pt[ipt].x;
+           if (++ipt >= NPT)
+           {
+               (*pGC->ops->FillSpans)(pDrawable, pGC, NPT, pt, width, TRUE);
+               ipt = 0;
+           }
+       }
+    }
+    /* Flush any remaining spans */
+    if (ipt)
+    {
+       (*pGC->ops->FillSpans)(pDrawable, pGC, ipt, pt, width, TRUE);
+    }
+}
diff --git a/Xserver/programs/Xserver/mfb/mfbscrclse.c b/Xserver/programs/Xserver/mfb/mfbscrclse.c
new file mode 100644 (file)
index 0000000..3bccf50
--- /dev/null
@@ -0,0 +1,60 @@
+/* $XConsortium: mfbscrclse.c,v 1.8 94/04/17 20:28:33 rws Exp $ */
+/***********************************************************
+
+Copyright (c) 1987  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+
+Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
+
+                        All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and its 
+documentation for any purpose and without fee is hereby granted, 
+provided that the above copyright notice appear in all copies and that
+both that copyright notice and this permission notice appear in 
+supporting documentation, and that the name of Digital not be
+used in advertising or publicity pertaining to distribution of the
+software without specific, written prior permission.  
+
+DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
+ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
+DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
+ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+SOFTWARE.
+
+******************************************************************/
+
+#include "scrnintstr.h"
+
+/*ARGSUSED*/
+Bool
+mfbCloseScreen(index, pScreen)
+    register ScreenPtr pScreen;
+{
+    xfree(pScreen->devPrivate);
+    return TRUE;
+}
+
diff --git a/Xserver/programs/Xserver/mfb/mfbscrinit.c b/Xserver/programs/Xserver/mfb/mfbscrinit.c
new file mode 100644 (file)
index 0000000..5c90c54
--- /dev/null
@@ -0,0 +1,160 @@
+/***********************************************************
+
+Copyright (c) 1987  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+
+Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
+
+                        All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and its 
+documentation for any purpose and without fee is hereby granted, 
+provided that the above copyright notice appear in all copies and that
+both that copyright notice and this permission notice appear in 
+supporting documentation, and that the name of Digital not be
+used in advertising or publicity pertaining to distribution of the
+software without specific, written prior permission.  
+
+DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
+ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
+DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
+ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+SOFTWARE.
+
+******************************************************************/
+/* $XConsortium: mfbscrinit.c,v 5.17 94/04/17 20:28:34 dpw Exp $ */
+/* $XFree86: xc/programs/Xserver/mfb/mfbscrinit.c,v 3.0 1994/06/18 16:29:52 dawes Exp $ */
+
+#include "X.h"
+#include "Xproto.h"    /* for xColorItem */
+#include "Xmd.h"
+#include "scrnintstr.h"
+#include "pixmapstr.h"
+#include "resource.h"
+#include "colormap.h"
+#include "mfb.h"
+#include "mistruct.h"
+#include "dix.h"
+#include "mi.h"
+#include "mibstore.h"
+#include "migc.h"
+#include "servermd.h"
+
+#ifdef PIXMAP_PER_WINDOW
+int frameWindowPrivateIndex;
+#endif
+int mfbWindowPrivateIndex;
+int mfbGCPrivateIndex;
+static unsigned long mfbGeneration = 0;
+
+static VisualRec visual = {
+/* vid  class       bpRGB cmpE nplan rMask gMask bMask oRed oGreen oBlue */
+   0,   StaticGray, 1,    2,   1,    0,    0,    0,    0,   0,     0
+};
+
+static VisualID VID;
+
+static DepthRec depth = {
+/* depth       numVid          vids */
+    1,         1,              &VID
+};
+
+miBSFuncRec mfbBSFuncRec = {
+    mfbSaveAreas,
+    mfbRestoreAreas,
+    (void (*)()) 0,
+    (PixmapPtr (*)()) 0,
+    (PixmapPtr (*)()) 0,
+};
+
+Bool
+mfbAllocatePrivates(pScreen, pWinIndex, pGCIndex)
+    ScreenPtr pScreen;
+    int *pWinIndex, *pGCIndex;
+{
+    if (mfbGeneration != serverGeneration)
+    {
+#ifdef PIXMAP_PER_WINDOW
+       frameWindowPrivateIndex = AllocateWindowPrivateIndex();
+#endif
+       mfbWindowPrivateIndex = AllocateWindowPrivateIndex();
+       mfbGCPrivateIndex = miAllocateGCPrivateIndex();
+       miRegisterGCPrivateIndex(mfbGCPrivateIndex);
+       visual.vid = FakeClientID(0);
+       VID = visual.vid;
+       mfbGeneration = serverGeneration;
+    }
+    if (pWinIndex)
+       *pWinIndex = mfbWindowPrivateIndex;
+    if (pGCIndex)
+       *pGCIndex = mfbGCPrivateIndex;
+    return (AllocateWindowPrivate(pScreen, mfbWindowPrivateIndex,
+                                 sizeof(mfbPrivWin)) &&
+           AllocateGCPrivate(pScreen, mfbGCPrivateIndex, sizeof(mfbPrivGC)));
+}
+
+/* dts * (inch/dot) * (25.4 mm / inch) = mm */
+Bool
+mfbScreenInit(pScreen, pbits, xsize, ysize, dpix, dpiy, width)
+    register ScreenPtr pScreen;
+    pointer pbits;             /* pointer to screen bitmap */
+    int xsize, ysize;          /* in pixels */
+    int dpix, dpiy;            /* dots per inch */
+    int width;                 /* pixel width of frame buffer */
+{
+    if         (!mfbAllocatePrivates(pScreen, (int *)NULL, (int *)NULL))
+       return FALSE;
+    pScreen->defColormap = (Colormap) FakeClientID(0);
+    /* whitePixel, blackPixel */
+    pScreen->QueryBestSize = mfbQueryBestSize;
+    /* SaveScreen */
+    pScreen->GetImage = mfbGetImage;
+    pScreen->GetSpans = mfbGetSpans;
+    pScreen->CreateWindow = mfbCreateWindow;
+    pScreen->DestroyWindow = mfbDestroyWindow;
+    pScreen->PositionWindow = mfbPositionWindow;
+    pScreen->ChangeWindowAttributes = mfbChangeWindowAttributes;
+    pScreen->RealizeWindow = mfbMapWindow;
+    pScreen->UnrealizeWindow = mfbUnmapWindow;
+    pScreen->PaintWindowBackground = mfbPaintWindow;
+    pScreen->PaintWindowBorder = mfbPaintWindow;
+    pScreen->CopyWindow = mfbCopyWindow;
+    pScreen->CreatePixmap = mfbCreatePixmap;
+    pScreen->DestroyPixmap = mfbDestroyPixmap;
+    pScreen->RealizeFont = mfbRealizeFont;
+    pScreen->UnrealizeFont = mfbUnrealizeFont;
+    pScreen->CreateGC = mfbCreateGC;
+    pScreen->CreateColormap = mfbCreateColormap;
+    pScreen->DestroyColormap = mfbDestroyColormap;
+    pScreen->InstallColormap = mfbInstallColormap;
+    pScreen->UninstallColormap = mfbUninstallColormap;
+    pScreen->ListInstalledColormaps = mfbListInstalledColormaps;
+    pScreen->StoreColors = (void (*)())NoopDDA;
+    pScreen->ResolveColor = mfbResolveColor;
+    pScreen->BitmapToRegion = mfbPixmapToRegion;
+    return miScreenInit(pScreen, pbits, xsize, ysize, dpix, dpiy, width,
+                       1, 1, &depth, VID, 1, &visual, &mfbBSFuncRec);
+}
diff --git a/Xserver/programs/Xserver/mfb/mfbsetsp.c b/Xserver/programs/Xserver/mfb/mfbsetsp.c
new file mode 100644 (file)
index 0000000..993ac72
--- /dev/null
@@ -0,0 +1,278 @@
+/* Combined Purdue/PurduePlus patches, level 2.0, 1/17/89 */
+/***********************************************************
+
+Copyright (c) 1987  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+
+Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
+
+                        All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and its 
+documentation for any purpose and without fee is hereby granted, 
+provided that the above copyright notice appear in all copies and that
+both that copyright notice and this permission notice appear in 
+supporting documentation, and that the name of Digital not be
+used in advertising or publicity pertaining to distribution of the
+software without specific, written prior permission.  
+
+DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
+ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
+DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
+ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+SOFTWARE.
+
+******************************************************************/
+/* $XConsortium: mfbsetsp.c,v 5.8 94/04/17 20:28:34 dpw Exp $ */
+
+#include "X.h"
+#include "Xmd.h"
+
+#include "misc.h"
+#include "regionstr.h"
+#include "gcstruct.h"
+#include "windowstr.h"
+#include "pixmapstr.h"
+#include "scrnintstr.h"
+
+#include "mfb.h"
+#include "maskbits.h"
+
+#include "servermd.h"
+
+
+/* mfbSetScanline -- copies the bits from psrc to the drawable starting at
+ * (xStart, y) and continuing to (xEnd, y).  xOrigin tells us where psrc 
+ * starts on the scanline. (I.e., if this scanline passes through multiple
+ * boxes, we may not want to start grabbing bits at psrc but at some offset
+ * further on.) 
+ */
+mfbSetScanline(y, xOrigin, xStart, xEnd, psrc, alu, pdstBase, widthDst)
+    int                        y;
+    int                        xOrigin;        /* where this scanline starts */
+    int                        xStart;         /* first bit to use from scanline */
+    int                        xEnd;           /* last bit to use from scanline + 1 */
+    register PixelType *psrc;
+    register int       alu;            /* raster op */
+    PixelType          *pdstBase;      /* start of the drawable */
+    int                        widthDst;       /* width of drawable in words */
+{
+    int                        w;              /* width of scanline in bits */
+    register PixelType *pdst;          /* where to put the bits */
+    register PixelType tmpSrc;         /* scratch buffer to collect bits in */
+    int                        dstBit;         /* offset in bits from beginning of 
+                                        * word */
+    register int       nstart;         /* number of bits from first partial */
+    register int       nend;           /* " " last partial word */
+    int                offSrc;
+    PixelType  startmask, endmask;
+    int                nlMiddle, nl;
+
+    pdst = mfbScanline(pdstBase, xStart, y, widthDst);
+    psrc += (xStart - xOrigin) >> PWSH;
+    offSrc = (xStart - xOrigin) & PIM;
+    w = xEnd - xStart;
+    dstBit = xStart & PIM;
+
+    if (dstBit + w <= PPW) 
+    { 
+       getandputrop(psrc, offSrc, dstBit, w, pdst, alu)
+    } 
+    else 
+    { 
+
+       maskbits(xStart, w, startmask, endmask, nlMiddle);
+       if (startmask) 
+           nstart = PPW - dstBit; 
+       else 
+           nstart = 0; 
+       if (endmask) 
+           nend = xEnd & PIM; 
+       else 
+           nend = 0; 
+       if (startmask) 
+       { 
+           getandputrop(psrc, offSrc, dstBit, nstart, pdst, alu)
+           pdst++; 
+           offSrc += nstart;
+           if (offSrc > PLST)
+           {
+               psrc++;
+               offSrc -= PPW;
+           }
+       } 
+       nl = nlMiddle; 
+       while (nl--) 
+       { 
+           getbits(psrc, offSrc, PPW, tmpSrc);
+           DoRop(*pdst, alu, tmpSrc, *pdst); 
+           pdst++; 
+           psrc++; 
+       } 
+       if (endmask) 
+       { 
+           getandputrop0(psrc, offSrc, nend, pdst, alu);
+       } 
+        
+    } 
+}
+
+\f
+
+/* SetSpans -- for each span copy pwidth[i] bits from psrc to pDrawable at
+ * ppt[i] using the raster op from the GC.  If fSorted is TRUE, the scanlines
+ * are in increasing Y order.
+ * Source bit lines are server scanline padded so that they always begin
+ * on a word boundary.
+ */ 
+void
+mfbSetSpans(pDrawable, pGC, pcharsrc, ppt, pwidth, nspans, fSorted)
+    DrawablePtr                pDrawable;
+    GCPtr              pGC;
+    char               *pcharsrc;
+    register DDXPointPtr ppt;
+    int                        *pwidth;
+    int                        nspans;
+    int                        fSorted;
+{
+    PixelType          *psrc = (PixelType *)pcharsrc;
+    PixelType          *pdstBase;      /* start of dst bitmap */
+    int                widthDst;       /* width of bitmap in words */
+    register BoxPtr    pbox, pboxLast, pboxTest;
+    register DDXPointPtr pptLast;
+    int                alu;
+    RegionPtr          prgnDst;
+    int                        xStart, xEnd;
+    int                        yMax;
+
+    alu = pGC->alu;
+    prgnDst = ((mfbPrivGC *)(pGC->devPrivates[mfbGCPrivateIndex].ptr))->pCompositeClip;
+
+    pptLast = ppt + nspans;
+
+    yMax = pDrawable->y + (int) pDrawable->height;
+    mfbGetPixelWidthAndPointer(pDrawable, widthDst, pdstBase);
+
+    pbox =  REGION_RECTS(prgnDst);
+    pboxLast = pbox + REGION_NUM_RECTS(prgnDst);
+
+    if(fSorted)
+    {
+    /* scan lines sorted in ascending order. Because they are sorted, we
+     * don't have to check each scanline against each clip box.  We can be
+     * sure that this scanline only has to be clipped to boxes at or after the
+     * beginning of this y-band 
+     */
+       pboxTest = pbox;
+       while(ppt < pptLast)
+       {
+           pbox = pboxTest;
+           if(ppt->y >= yMax)
+               break;
+           while(pbox < pboxLast)
+           {
+               if(pbox->y1 > ppt->y)
+               {
+                   /* scanline is before clip box */
+                   break;
+               }
+               else if(pbox->y2 <= ppt->y)
+               {
+                   /* clip box is before scanline */
+                   pboxTest = ++pbox;
+                   continue;
+               }
+               else if(pbox->x1 > ppt->x + *pwidth) 
+               {
+                   /* clip box is to right of scanline */
+                   break;
+               }
+               else if(pbox->x2 <= ppt->x)
+               {
+                   /* scanline is to right of clip box */
+                   pbox++;
+                   continue;
+               }
+
+               /* at least some of the scanline is in the current clip box */
+               xStart = max(pbox->x1, ppt->x);
+               xEnd = min(ppt->x + *pwidth, pbox->x2);
+               mfbSetScanline(ppt->y, ppt->x, xStart, xEnd, psrc, alu,
+                              pdstBase, widthDst);
+               if(ppt->x + *pwidth <= pbox->x2)
+               {
+                   /* End of the line, as it were */
+                   break;
+               }
+               else
+                   pbox++;
+           }
+           /* We've tried this line against every box; it must be outside them
+            * all.  move on to the next point */
+           ppt++;
+           psrc += PixmapWidthInPadUnits(*pwidth, 1);
+           pwidth++;
+       }
+    }
+    else
+    {
+    /* scan lines not sorted. We must clip each line against all the boxes */
+       while(ppt < pptLast)
+       {
+           if(ppt->y >= 0 && ppt->y < yMax)
+           {
+               
+               for(pbox = REGION_RECTS(prgnDst); pbox< pboxLast; pbox++)
+               {
+                   if(pbox->y1 > ppt->y)
+                   {
+                       /* rest of clip region is above this scanline,
+                        * skip it */
+                       break;
+                   }
+                   if(pbox->y2 <= ppt->y)
+                   {
+                       /* clip box is below scanline */
+                       pbox++;
+                       break;
+                   }
+                   if(pbox->x1 <= ppt->x + *pwidth &&
+                      pbox->x2 > ppt->x)
+                   {
+                       xStart = max(pbox->x1, ppt->x);
+                       xEnd = min(pbox->x2, ppt->x + *pwidth);
+                       mfbSetScanline(ppt->y, ppt->x, xStart, xEnd, 
+                                      psrc, alu, pdstBase, widthDst);
+                   }
+
+               }
+           }
+       psrc += PixmapWidthInPadUnits(*pwidth, 1);
+       ppt++;
+       pwidth++;
+       }
+    }
+}
diff --git a/Xserver/programs/Xserver/mfb/mfbtegblt.c b/Xserver/programs/Xserver/mfb/mfbtegblt.c
new file mode 100644 (file)
index 0000000..8e91c08
--- /dev/null
@@ -0,0 +1,420 @@
+/* $XConsortium: mfbtegblt.c,v 5.14 94/04/17 20:28:35 dpw Exp $ */
+/* Combined Purdue/PurduePlus patches, level 2.0, 1/17/89 */
+/***********************************************************
+
+Copyright (c) 1987  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+
+Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
+
+                        All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and its 
+documentation for any purpose and without fee is hereby granted, 
+provided that the above copyright notice appear in all copies and that
+both that copyright notice and this permission notice appear in 
+supporting documentation, and that the name of Digital not be
+used in advertising or publicity pertaining to distribution of the
+software without specific, written prior permission.  
+
+DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
+ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
+DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
+ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+SOFTWARE.
+
+******************************************************************/
+#include       "X.h"
+#include       "Xmd.h"
+#include       "Xproto.h"
+#include       "mfb.h"
+#include       "fontstruct.h"
+#include       "dixfontstr.h"
+#include       "gcstruct.h"
+#include       "windowstr.h"
+#include       "scrnintstr.h"
+#include       "pixmapstr.h"
+#include       "regionstr.h"
+#include       "maskbits.h"
+
+/*
+    this works for fonts with glyphs <= PPW bits wide.
+
+    This should be called only with a terminal-emulator font;
+this means that the FIXED_METRICS flag is set, and that
+glyphbounds == charbounds.
+
+    in theory, this goes faster; even if it doesn't, it reduces the
+flicker caused by writing a string over itself with image text (since
+the background gets repainted per character instead of per string.)
+this seems to be important for some converted X10 applications.
+
+    Image text looks at the bits in the glyph and the fg and bg in the
+GC.  it paints a rectangle, as defined in the protocol dcoument,
+and the paints the characters.
+
+   to avoid source proliferation, this file is compiled
+two times:
+       MFBTEGLYPHBLT           OP
+       mfbTEGlyphBltWhite              (white text, black bg )
+       mfbTEGlyphBltBlack      ~       (black text, white bg )
+
+*/
+
+#if defined(NO_3_60_CG4) && defined(FASTPUTBITS) && defined(FASTGETBITS)
+#define FASTCHARS
+#endif
+
+/*
+ * this macro "knows" that only characters <= 8 bits wide will
+ * fit this case (which is why it is independent of GLYPHPADBYTES)
+ */
+
+#if (BITMAP_BIT_ORDER == MSBFirst) && (GLYPHPADBYTES != 4)
+#if GLYPHPADBYTES == 1
+#define ShiftAmnt   24
+#else
+#define ShiftAmnt   16
+#endif
+
+/*
+ * Note: for BITMAP_BIT_ORDER != IMAGE_BYTE_ORDER, SCRRIGHT() evaluates its
+ * first argument more than once.  Thus the imbedded char++ have to be moved.
+ * (DHD)
+ */
+#if BITMAP_BIT_ORDER == IMAGE_BYTE_ORDER
+#if PPW == 32
+#define GetBits4    c = (*char1++ << ShiftAmnt) | \
+                       SCRRIGHT (*char2++ << ShiftAmnt, xoff2) | \
+                       SCRRIGHT (*char3++ << ShiftAmnt, xoff3) | \
+                       SCRRIGHT (*char4++ << ShiftAmnt, xoff4);
+#else /* PPW */
+#define GetBits4    c = ((unsigned long)(*char1++ << ShiftAmnt) << 32 )  | \
+                       (SCRRIGHT (*char2++ << ShiftAmnt, xoff2) << 32 ) | \
+                       (SCRRIGHT (*char3++ << ShiftAmnt, xoff3) << 32 ) | \
+                       (SCRRIGHT (*char4++ << ShiftAmnt, xoff4) << 32 ) | \
+                       (*char5++ << ShiftAmnt)                          | \
+                       SCRRIGHT (*char6++ << ShiftAmnt, xoff6)          | \
+                       SCRRIGHT (*char7++ << ShiftAmnt, xoff7)          | \
+                       SCRRIGHT (*char8++ << ShiftAmnt, xoff8);
+#endif /* PPW */
+#else /* BITMAP_BIT_ORDER != IMAGE_BYTE_ORDER */
+#if PPW == 32
+#define GetBits4    c = (*char1++ << ShiftAmnt) | \
+                       SCRRIGHT (*char2 << ShiftAmnt, xoff2) | \
+                       SCRRIGHT (*char3 << ShiftAmnt, xoff3) | \
+                       SCRRIGHT (*char4 << ShiftAmnt, xoff4); \
+                       char2++; char3++; char4++;
+#else /* PPW == 64 */
+#define GetBits4    c = ((unsigned long)(*char1++ << ShiftAmnt) << 32 )  | \
+                       (SCRRIGHT (*char2 << ShiftAmnt, xoff2) << 32 ) | \
+                       (SCRRIGHT (*char3 << ShiftAmnt, xoff3) << 32 ) | \
+                       (SCRRIGHT (*char4 << ShiftAmnt, xoff4) << 32 ) | \
+                       (*char5++ << ShiftAmnt)                          | \
+                       SCRRIGHT (*char6 << ShiftAmnt, xoff6)    | \
+                       SCRRIGHT (*char7 << ShiftAmnt, xoff7)    | \
+                       SCRRIGHT (*char8 << ShiftAmnt, xoff8); \
+                       char2++; char3++; char4++; char6++; char7++; char8++;
+#endif /* PPW */
+#endif /* BITMAP_BIT_ORDER == IMAGE_BYTE_ORDER */
+
+#else /* (BITMAP_BIT_ORDER != MSBFirst) || (GLYPHPADBYTES == 4) */
+
+#if BITMAP_BIT_ORDER == IMAGE_BYTE_ORDER
+#if PPW == 32
+#define GetBits4    c = *char1++ | \
+                       SCRRIGHT (*char2++, xoff2) | \
+                       SCRRIGHT (*char3++, xoff3) | \
+                       SCRRIGHT (*char4++, xoff4);
+#else /* PPW == 64 */
+#define GetBits4    c = (unsigned long)(((*char1++) << 64 ) | \
+                        (SCRRIGHT (*char2++, xoff2) << 64 ) | \
+                        (SCRRIGHT (*char3++, xoff3) << 64 ) | \
+                        (SCRRIGHT (*char4++, xoff4) << 64 ) | \
+                        SCRRIGHT (*char5++, xoff5)          | \
+                        SCRRIGHT (*char6++, xoff6)          | \
+                        SCRRIGHT (*char7++, xoff7)          | \
+                        SCRRIGHT (*char8++, xoff8));
+#endif /* PPW */
+#else /* BITMAP_BIT_ORDER != IMAGE_BYTE_ORDER */
+#if PPW == 32
+#define GetBits4    c = *char1++ | \
+                       SCRRIGHT (*char2, xoff2) | \
+                       SCRRIGHT (*char3, xoff3) | \
+                       SCRRIGHT (*char4, xoff4); \
+                       char2++; char3++; char4++;
+#else /* PPW == 64 */
+#define GetBits4    c = (unsigned long)(((*char1++) << 64 ) | \
+                        (SCRRIGHT (*char2, xoff2) << 64 ) | \
+                        (SCRRIGHT (*char3, xoff3) << 64 ) | \
+                        (SCRRIGHT (*char4, xoff4) << 64 ) | \
+                        SCRRIGHT (*char5, xoff5)          | \
+                        SCRRIGHT (*char6, xoff6)          | \
+                        SCRRIGHT (*char7, xoff7)          | \
+                        SCRRIGHT (*char8, xoff8)); \
+                       char2++; char3++; char4++; \
+                       char5++; char6++; char7++; char8++;
+#endif /* PPW */
+#endif /* BITMAP_BIT_ORDER == IMAGE_BYTE_ORDER */
+
+#endif /* BITMAP_BIT_ORDER && GLYPHPADBYTES */
+
+
+#if GLYPHPADBYTES == 1
+typedef        unsigned char   *glyphPointer;
+#define USE_LEFTBITS
+#endif
+
+#if GLYPHPADBYTES == 2
+typedef unsigned short *glyphPointer;
+#define USE_LEFTBITS
+#endif
+
+#if GLYPHPADBYTES == 4
+typedef unsigned int   *glyphPointer;
+#endif
+
+#ifdef USE_LEFTBITS
+#define GetBits1    getleftbits (char1, widthGlyph, c); \
+                   c &= glyphMask; \
+                   char1 = (glyphPointer) (((char *) char1) + glyphBytes);
+#else
+#define GetBits1    c = *char1++;
+#endif
+
+void
+MFBTEGLYPHBLT(pDrawable, pGC, x, y, nglyph, ppci, pglyphBase)
+    DrawablePtr pDrawable;
+    GC                 *pGC;
+    int        x, y;
+    unsigned int nglyph;
+    CharInfoPtr *ppci;         /* array of character info */
+    pointer    pglyphBase;     /* start of array of glyphs */
+{
+    FontPtr    pfont = pGC->font;
+    int widthDst;
+    PixelType *pdstBase;       /* pointer to longword with top row 
+                                  of current glyph */
+
+    int h;                     /* height of glyph and char */
+    register int xpos;         /* current x  */
+    int ypos;                  /* current y */
+    int widthGlyph;
+
+    int hTmp;                  /* counter for height */
+    register PixelType startmask, endmask;
+    int nfirst;                        /* used if glyphs spans a longword boundary */
+    BoxRec bbox;               /* for clipping */
+    int        widthGlyphs;
+    register PixelType  *dst;
+    register PixelType  c;
+    register int           xoff1, xoff2, xoff3, xoff4;
+    register glyphPointer   char1, char2, char3, char4;
+#if PPW == 64
+    register int           xoff5, xoff6, xoff7, xoff8;
+    register glyphPointer   char5, char6, char7, char8;
+#endif /* PPW */
+
+#ifdef USE_LEFTBITS
+    register PixelType  glyphMask;
+    register PixelType  tmpSrc;
+    register int           glyphBytes;
+#endif
+
+    if (!(pGC->planemask & 1))
+       return;
+
+    mfbGetPixelWidthAndPointer(pDrawable, widthDst, pdstBase);
+
+    xpos = x + pDrawable->x;
+    ypos = y + pDrawable->y;
+
+    widthGlyph = FONTMAXBOUNDS(pfont,characterWidth);
+    h = FONTASCENT(pfont) + FONTDESCENT(pfont);
+
+    xpos += FONTMAXBOUNDS(pfont,leftSideBearing);
+    ypos -= FONTASCENT(pfont);
+
+    bbox.x1 = xpos;
+    bbox.x2 = xpos + (widthGlyph * nglyph);
+    bbox.y1 = ypos;
+    bbox.y2 = ypos + h;
+
+    switch (RECT_IN_REGION(pGC->pScreen, 
+           ((mfbPrivGC *)(pGC->devPrivates[mfbGCPrivateIndex].ptr))->pCompositeClip, &bbox))
+    {
+      case rgnPART:
+       /* this is the WRONG thing to do, but it works.
+          calling the non-terminal text is easy, but slow, given
+          what we know about the font.
+
+          the right thing to do is something like:
+           for each clip rectangle
+               compute at which row the glyph starts to be in it,
+                  and at which row the glyph ceases to be in it
+               compute which is the first glyph inside the left
+                   edge, and the last one inside the right edge
+               draw a fractional first glyph, using only
+                   the rows we know are in
+               draw all the whole glyphs, using the appropriate rows
+               draw any pieces of the last glyph, using the right rows
+
+          this way, the code would take advantage of knowing that
+          all glyphs are the same height and don't overlap.
+
+          one day...
+       */
+       CLIPTETEXT(pDrawable, pGC, x, y, nglyph, ppci, pglyphBase);
+      case rgnOUT:
+       return;
+    }
+    pdstBase = mfbScanlineDeltaNoBankSwitch(pdstBase, ypos, widthDst);
+    widthGlyphs = widthGlyph * PGSZB;
+
+#ifdef USE_LEFTBITS
+    glyphMask = endtab[widthGlyph];
+    glyphBytes = GLYPHWIDTHBYTESPADDED(*ppci);
+#endif
+
+    if (nglyph >= PGSZB && widthGlyphs <= PPW)
+    {
+       while (nglyph >= PGSZB)
+       {
+           nglyph -= PGSZB;
+           xoff1 = xpos & PIM;
+           xoff2 = widthGlyph;
+           xoff3 = xoff2 + widthGlyph;
+           xoff4 = xoff3 + widthGlyph;
+#if PPW == 64
+           xoff5 = xoff4 + widthGlyph;
+           xoff6 = xoff5 + widthGlyph;
+           xoff7 = xoff6 + widthGlyph;
+           xoff8 = xoff7 + widthGlyph;
+#endif /* PPW */
+           char1 = (glyphPointer) FONTGLYPHBITS(pglyphBase,(*ppci++));
+           char2 = (glyphPointer) FONTGLYPHBITS(pglyphBase,(*ppci++));
+           char3 = (glyphPointer) FONTGLYPHBITS(pglyphBase,(*ppci++));
+           char4 = (glyphPointer) FONTGLYPHBITS(pglyphBase,(*ppci++));
+#if PPW == 64
+           char5 = (glyphPointer) FONTGLYPHBITS(pglyphBase,(*ppci++));
+           char6 = (glyphPointer) FONTGLYPHBITS(pglyphBase,(*ppci++));
+           char7 = (glyphPointer) FONTGLYPHBITS(pglyphBase,(*ppci++));
+           char8 = (glyphPointer) FONTGLYPHBITS(pglyphBase,(*ppci++));
+#endif /* PPW */
+
+           hTmp = h;
+           dst = mfbScanlineOffset(pdstBase, (xpos >> PWSH)); /* switch now */
+
+#ifndef FASTCHARS
+           if (xoff1 + widthGlyphs <= PPW)
+           {
+               maskpartialbits (xoff1, widthGlyphs, startmask);
+#endif
+               while (hTmp--)
+               {
+                   GetBits4
+#ifdef FASTCHARS
+# if BITMAP_BIT_ORDER == MSBFirst
+                   c >>= PPW - widthGlyphs;
+# endif
+                   FASTPUTBITS(OP(c), xoff1, widthGlyphs, dst);
+#else
+                   *(dst) = (*dst) & ~startmask | OP(SCRRIGHT(c, xoff1)) & startmask;
+#endif
+                   mfbScanlineInc(dst, widthDst);
+               }
+#ifndef FASTCHARS
+           }
+           else
+           {
+               maskPPWbits (xoff1, widthGlyphs, startmask, endmask);
+               nfirst = PPW - xoff1;
+               while (hTmp--)
+               {
+                   GetBits4
+                   dst[0] = dst[0] & ~startmask |
+                            OP(SCRRIGHT(c,xoff1)) & startmask;
+                   dst[1] = dst[1] & ~endmask |
+                            OP(SCRLEFT(c,nfirst)) & endmask;
+                   mfbScanlineInc(dst, widthDst);
+               }
+           }
+#endif
+           xpos += widthGlyphs;
+       }
+    }
+
+    while(nglyph--)
+    {
+       xoff1 = xpos & PIM;
+       char1 = (glyphPointer) FONTGLYPHBITS(pglyphBase,(*ppci++));
+       hTmp = h;
+       dst = mfbScanlineOffset(pdstBase, (xpos >> PWSH));
+
+#ifndef FASTCHARS
+       if (xoff1 + widthGlyph <= PPW)
+       {
+           maskpartialbits (xoff1, widthGlyph, startmask);
+#endif
+           while (hTmp--)
+           {
+#ifdef FASTCHARS
+#ifdef USE_LEFTBITS
+               FASTGETBITS (char1,0,widthGlyph,c);
+               char1 = (glyphPointer) (((char *) char1) + glyphBytes);
+#else
+               c = *char1++;
+#if BITMAP_BIT_ORDER == MSBFirst
+               c >>= PPW - widthGlyph;
+#endif
+#endif
+               FASTPUTBITS (OP(c),xoff1,widthGlyph,dst);
+#else
+               GetBits1
+               (*dst) = (*dst) & ~startmask | OP(SCRRIGHT(c, xoff1)) & startmask;
+#endif
+               mfbScanlineInc(dst, widthDst);
+           }
+#ifndef FASTCHARS
+       }
+       else
+       {
+           maskPPWbits (xoff1, widthGlyph, startmask, endmask);
+           nfirst = PPW - xoff1;
+           while (hTmp--)
+           {
+               GetBits1
+               dst[0] = dst[0] & ~startmask |
+                        OP(SCRRIGHT(c,xoff1)) & startmask;
+               dst[1] = dst[1] & ~endmask |
+                        OP(SCRLEFT(c,nfirst)) & endmask;
+               mfbScanlineInc(dst, widthDst);
+           }
+       }
+#endif
+       xpos += widthGlyph;
+    }
+}
diff --git a/Xserver/programs/Xserver/mfb/mfbtile.c b/Xserver/programs/Xserver/mfb/mfbtile.c
new file mode 100644 (file)
index 0000000..52cb7a2
--- /dev/null
@@ -0,0 +1,231 @@
+/* Combined Purdue/PurduePlus patches, level 2.0, 1/17/89 */
+/***********************************************************
+
+Copyright (c) 1987  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+
+Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
+
+                        All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and its 
+documentation for any purpose and without fee is hereby granted, 
+provided that the above copyright notice appear in all copies and that
+both that copyright notice and this permission notice appear in 
+supporting documentation, and that the name of Digital not be
+used in advertising or publicity pertaining to distribution of the
+software without specific, written prior permission.  
+
+DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
+ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
+DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
+ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+SOFTWARE.
+
+******************************************************************/
+/* $XConsortium: mfbtile.c,v 5.8 94/04/17 20:28:36 dpw Exp $ */
+#include "X.h"
+
+#include "windowstr.h"
+#include "regionstr.h"
+#include "pixmapstr.h"
+#include "scrnintstr.h"
+
+#include "mfb.h"
+#include "maskbits.h"
+
+#include "mergerop.h"
+/* 
+
+   the boxes are already translated.
+
+   NOTE:
+   iy = ++iy < tileHeight ? iy : 0
+is equivalent to iy%= tileheight, and saves a division.
+*/
+
+/* 
+    tile area with a PPW bit wide pixmap 
+*/
+void
+MROP_NAME(mfbTileAreaPPW)(pDraw, nbox, pbox, alu, ptile)
+    DrawablePtr pDraw;
+    int nbox;
+    BoxPtr pbox;
+    int alu;
+    PixmapPtr ptile;
+{
+    register PixelType *psrc;
+                       /* pointer to bits in tile, if needed */
+    int tileHeight;    /* height of the tile */
+    register PixelType srcpix; 
+    int nlwidth;       /* width in longwords of the drawable */
+    int w;             /* width of current box */
+    MROP_DECLARE_REG ()
+    register int h;    /* height of current box */
+    register int nlw;  /* loop version of nlwMiddle */
+    register PixelType *p;     /* pointer to bits we're writing */
+    PixelType startmask;
+    PixelType endmask; /* masks for reggedy bits at either end of line */
+    int nlwMiddle;     /* number of longwords between sides of boxes */
+    int nlwExtra;      /* to get from right of box to left of next span */
+    register int iy;   /* index of current scanline in tile */
+    PixelType *pbits;  /* pointer to start of drawable */
+
+    mfbGetPixelWidthAndPointer(pDraw, nlwidth, pbits);
+
+    MROP_INITIALIZE(alu,~0)
+
+    tileHeight = ptile->drawable.height;
+    psrc = (PixelType *)(ptile->devPrivate.ptr);
+
+    while (nbox--)
+    {
+       w = pbox->x2 - pbox->x1;
+       h = pbox->y2 - pbox->y1;
+       iy = pbox->y1 % tileHeight;
+       p = mfbScanline(pbits, pbox->x1, pbox->y1, nlwidth);
+
+       if ( ((pbox->x1 & PIM) + w) < PPW)
+       {
+           maskpartialbits(pbox->x1, w, startmask);
+           nlwExtra = nlwidth;
+           while (h--)
+           {
+               srcpix = psrc[iy];
+               iy++;
+               if (iy == tileHeight)
+                   iy = 0;
+               *p = MROP_MASK(srcpix,*p,startmask);
+               mfbScanlineInc(p, nlwExtra);
+           }
+       }
+       else
+       {
+           maskbits(pbox->x1, w, startmask, endmask, nlwMiddle);
+           nlwExtra = nlwidth - nlwMiddle;
+
+           if (startmask && endmask)
+           {
+               nlwExtra -= 1;
+               while (h--)
+               {
+                   srcpix = psrc[iy];
+                   iy++;
+                   if (iy == tileHeight)
+                       iy = 0;
+                   nlw = nlwMiddle;
+                   *p = MROP_MASK (srcpix,*p,startmask);
+                   p++;
+                   while (nlw--)
+                   {
+                       *p = MROP_SOLID(srcpix,*p);
+                       p++;
+                   }
+
+                   *p = MROP_MASK(srcpix,*p,endmask);
+                   mfbScanlineInc(p, nlwExtra);
+               }
+           }
+           else if (startmask && !endmask)
+           {
+               nlwExtra -= 1;
+               while (h--)
+               {
+                   srcpix = psrc[iy];
+                   iy++;
+                   if (iy == tileHeight)
+                       iy = 0;
+                   nlw = nlwMiddle;
+                   *p = MROP_MASK(srcpix,*p,startmask);
+                   p++;
+                   while (nlw--)
+                   {
+                       *p = MROP_SOLID(srcpix,*p);
+                       p++;
+                   }
+                   mfbScanlineInc(p, nlwExtra);
+               }
+           }
+           else if (!startmask && endmask)
+           {
+               while (h--)
+               {
+                   srcpix = psrc[iy];
+                   iy++;
+                   if (iy == tileHeight)
+                       iy = 0;
+                   nlw = nlwMiddle;
+                   while (nlw--)
+                   {
+                       *p = MROP_SOLID(srcpix,*p);
+                       p++;
+                   }
+
+                   *p = MROP_MASK(srcpix,*p,endmask);
+                   mfbScanlineInc(p, nlwExtra);
+               }
+           }
+           else /* no ragged bits at either end */
+           {
+               while (h--)
+               {
+                   srcpix = psrc[iy];
+                   iy++;
+                   if (iy == tileHeight)
+                       iy = 0;
+                   nlw = nlwMiddle;
+                   while (nlw--)
+                   {
+                       *p = MROP_SOLID (srcpix,*p);
+                       p++;
+                   }
+                   mfbScanlineInc(p, nlwExtra);
+               }
+           }
+       }
+        pbox++;
+    }
+}
+
+#if (MROP) == 0
+void
+mfbTileAreaPPW (pDraw, nbox, pbox, alu, ptile)
+    DrawablePtr pDraw;
+    int nbox;
+    BoxPtr pbox;
+    int alu;
+    PixmapPtr ptile;
+{
+    void    (*f)(), mfbTileAreaPPWCopy(), mfbTileAreaPPWGeneral();
+    
+    if (alu == GXcopy)
+       f = mfbTileAreaPPWCopy;
+    else
+       f = mfbTileAreaPPWGeneral;
+    (*f) (pDraw, nbox, pbox, alu, ptile);
+}
+#endif
diff --git a/Xserver/programs/Xserver/mfb/mfbwindow.c b/Xserver/programs/Xserver/mfb/mfbwindow.c
new file mode 100644 (file)
index 0000000..3843d36
--- /dev/null
@@ -0,0 +1,339 @@
+/* $XConsortium: mfbwindow.c,v 5.14 94/04/17 20:28:36 dpw Exp $ */
+/* Combined Purdue/PurduePlus patches, level 2.0, 1/17/89 */
+/***********************************************************
+
+Copyright (c) 1987  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+
+Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
+
+                        All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and its 
+documentation for any purpose and without fee is hereby granted, 
+provided that the above copyright notice appear in all copies and that
+both that copyright notice and this permission notice appear in 
+supporting documentation, and that the name of Digital not be
+used in advertising or publicity pertaining to distribution of the
+software without specific, written prior permission.  
+
+DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
+ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
+DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
+ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+SOFTWARE.
+
+******************************************************************/
+
+#include "X.h"
+#include "scrnintstr.h"
+#include "windowstr.h"
+#include "mfb.h"
+#include "mistruct.h"
+#include "regionstr.h"
+#include "maskbits.h"
+
+extern WindowPtr *WindowTable;
+
+Bool
+mfbCreateWindow(pWin)
+    register WindowPtr pWin;
+{
+    register mfbPrivWin *pPrivWin;
+
+    pPrivWin = (mfbPrivWin *)(pWin->devPrivates[mfbWindowPrivateIndex].ptr);
+    pPrivWin->pRotatedBorder = NullPixmap;
+    pPrivWin->pRotatedBackground = NullPixmap;
+    pPrivWin->fastBackground = FALSE;
+    pPrivWin->fastBorder = FALSE;
+
+    return (TRUE);
+}
+
+/* This always returns true, because Xfree can't fail.  It might be possible
+ * on some devices for Destroy to fail */
+Bool 
+mfbDestroyWindow(pWin)
+    WindowPtr pWin;
+{
+    register mfbPrivWin *pPrivWin;
+
+    pPrivWin = (mfbPrivWin *)(pWin->devPrivates[mfbWindowPrivateIndex].ptr);
+
+    if (pPrivWin->pRotatedBorder)
+       (*pWin->drawable.pScreen->DestroyPixmap)(pPrivWin->pRotatedBorder);
+    if (pPrivWin->pRotatedBackground)
+       (*pWin->drawable.pScreen->DestroyPixmap)(pPrivWin->pRotatedBackground);
+    return (TRUE);
+}
+
+/*ARGSUSED*/
+Bool mfbMapWindow(pWindow)
+    WindowPtr pWindow;
+{
+    return (TRUE);
+}
+
+/* (x, y) is the upper left corner of the window on the screen 
+   do we really need to pass this?  (is it a;ready in pWin->absCorner?)
+   we only do the rotation for pixmaps that are 32 bits wide (padded
+or otherwise.)
+   mfbChangeWindowAttributes() has already put a copy of the pixmap
+in pPrivWin->pRotated*
+*/
+
+/*ARGSUSED*/
+Bool 
+mfbPositionWindow(pWin, x, y)
+    register WindowPtr pWin;
+    int x, y;
+{
+    register mfbPrivWin *pPrivWin;
+    int        reset = 0;
+
+    pPrivWin = (mfbPrivWin *)(pWin->devPrivates[mfbWindowPrivateIndex].ptr);
+    if (pWin->backgroundState == BackgroundPixmap && pPrivWin->fastBackground)
+    {
+       mfbXRotatePixmap(pPrivWin->pRotatedBackground,
+                        pWin->drawable.x - pPrivWin->oldRotate.x);
+       mfbYRotatePixmap(pPrivWin->pRotatedBackground,
+                        pWin->drawable.y - pPrivWin->oldRotate.y);
+       reset = 1;
+    }
+
+    if (!pWin->borderIsPixel && pPrivWin->fastBorder)
+    {
+       while (pWin->backgroundState == ParentRelative)
+           pWin = pWin->parent;
+       mfbXRotatePixmap(pPrivWin->pRotatedBorder,
+                        pWin->drawable.x - pPrivWin->oldRotate.x);
+       mfbYRotatePixmap(pPrivWin->pRotatedBorder,
+                        pWin->drawable.y - pPrivWin->oldRotate.y);
+       reset = 1;
+    }
+    if (reset)
+    {
+       pPrivWin->oldRotate.x = pWin->drawable.x;
+       pPrivWin->oldRotate.y = pWin->drawable.y;
+    }
+
+    /* This is the "wrong" fix to the right problem, but it doesn't really
+     * cost very much.  When the window is moved, we need to invalidate any
+     * RotatedPixmap that exists in any GC currently validated against this
+     * window.
+     */
+    pWin->drawable.serialNumber = NEXT_SERIAL_NUMBER;
+
+    /* Again, we have no failure modes indicated by any of the routines
+     * we've called, so we have to assume it worked */
+    return (TRUE);
+}
+
+/*ARGSUSED*/
+Bool 
+mfbUnmapWindow(pWindow)
+    WindowPtr pWindow;
+{
+    return (TRUE);
+}
+
+/* UNCLEAN!
+   this code calls the bitblt helper code directly.
+
+   mfbCopyWindow copies only the parts of the destination that are
+visible in the source.
+*/
+
+
+void 
+mfbCopyWindow(pWin, ptOldOrg, prgnSrc)
+    WindowPtr pWin;
+    DDXPointRec ptOldOrg;
+    RegionPtr prgnSrc;
+{
+    DDXPointPtr pptSrc;
+    register DDXPointPtr ppt;
+    RegionPtr prgnDst;
+    register BoxPtr pbox;
+    register int dx, dy;
+    register int i, nbox;
+    WindowPtr pwinRoot;
+
+    pwinRoot = WindowTable[pWin->drawable.pScreen->myNum];
+
+    prgnDst = REGION_CREATE(pWin->drawable.pScreen, NULL, 1);
+
+    dx = ptOldOrg.x - pWin->drawable.x;
+    dy = ptOldOrg.y - pWin->drawable.y;
+    REGION_TRANSLATE(pWin->drawable.pScreen, prgnSrc, -dx, -dy);
+    REGION_INTERSECT(pWin->drawable.pScreen, prgnDst, &pWin->borderClip,
+                    prgnSrc);
+
+    pbox = REGION_RECTS(prgnDst);
+    nbox = REGION_NUM_RECTS(prgnDst);
+    if(!(pptSrc = (DDXPointPtr )ALLOCATE_LOCAL(nbox * sizeof(DDXPointRec))))
+       return;
+    ppt = pptSrc;
+
+    for (i=nbox; --i >= 0; ppt++, pbox++)
+    {
+       ppt->x = pbox->x1 + dx;
+       ppt->y = pbox->y1 + dy;
+    }
+
+    mfbDoBitblt((DrawablePtr)pwinRoot, (DrawablePtr)pwinRoot,
+               GXcopy, prgnDst, pptSrc);
+    DEALLOCATE_LOCAL(pptSrc);
+    REGION_DESTROY(pWin->drawable.pScreen, prgnDst);
+}
+
+
+
+/* swap in correct PaintWindow* routine.  If we can use a fast output
+routine (i.e. the pixmap is paddable to 32 bits), also pre-rotate a copy
+of it in devPrivate.
+*/
+Bool
+mfbChangeWindowAttributes(pWin, mask)
+    register WindowPtr pWin;
+    register unsigned long mask;
+{
+    register unsigned long index;
+    register mfbPrivWin *pPrivWin;
+    WindowPtr  pBgWin;
+
+    pPrivWin = (mfbPrivWin *)(pWin->devPrivates[mfbWindowPrivateIndex].ptr);
+    /*
+     * When background state changes from ParentRelative and
+     * we had previously rotated the fast border pixmap to match
+     * the parent relative origin, rerotate to match window
+     */
+    if (mask & (CWBackPixmap | CWBackPixel) &&
+       pWin->backgroundState != ParentRelative &&
+       pPrivWin->fastBorder &&
+       (pPrivWin->oldRotate.x != pWin->drawable.x ||
+        pPrivWin->oldRotate.y != pWin->drawable.y))
+    {
+       mfbXRotatePixmap(pPrivWin->pRotatedBorder,
+                     pWin->drawable.x - pPrivWin->oldRotate.x);
+       mfbYRotatePixmap(pPrivWin->pRotatedBorder,
+                     pWin->drawable.y - pPrivWin->oldRotate.y);
+       pPrivWin->oldRotate.x = pWin->drawable.x;
+       pPrivWin->oldRotate.y = pWin->drawable.y;
+    }
+    while(mask)
+    {
+       index = lowbit (mask);
+       mask &= ~index;
+       switch(index)
+       {
+         case CWBackPixmap:
+             if (pWin->backgroundState == None)
+             {
+                 pPrivWin->fastBackground = FALSE;
+             }
+             else if (pWin->backgroundState == ParentRelative)
+             {
+                 pPrivWin->fastBackground = FALSE;
+                 /* Rotate border to match parent origin */
+                 if (pPrivWin->pRotatedBorder) {
+                     for (pBgWin = pWin->parent;
+                          pBgWin->backgroundState == ParentRelative;
+                          pBgWin = pBgWin->parent);
+                     mfbXRotatePixmap(pPrivWin->pRotatedBorder,
+                                   pBgWin->drawable.x - pPrivWin->oldRotate.x);
+                     mfbYRotatePixmap(pPrivWin->pRotatedBorder,
+                                   pBgWin->drawable.y - pPrivWin->oldRotate.y);
+                     pPrivWin->oldRotate.x = pBgWin->drawable.x;
+                     pPrivWin->oldRotate.y = pBgWin->drawable.y;
+                 }
+             }
+             else if ((pWin->background.pixmap->drawable.width <= PPW) &&
+                      !(pWin->background.pixmap->drawable.width &
+                        (pWin->background.pixmap->drawable.width - 1)))
+             {
+                 mfbCopyRotatePixmap(pWin->background.pixmap,
+                                     &pPrivWin->pRotatedBackground,
+                                     pWin->drawable.x,
+                                     pWin->drawable.y);
+                 if (pPrivWin->pRotatedBackground)
+                 {
+                     pPrivWin->fastBackground = TRUE;
+                     pPrivWin->oldRotate.x = pWin->drawable.x;
+                     pPrivWin->oldRotate.y = pWin->drawable.y;
+                 }
+                 else
+                 {
+                     pPrivWin->fastBackground = FALSE;
+                 }
+             }
+             else
+             {
+                 pPrivWin->fastBackground = FALSE;
+             }
+             break;
+
+         case CWBackPixel:
+             pPrivWin->fastBackground = FALSE;
+             break;
+
+         case CWBorderPixmap:
+             if ((pWin->border.pixmap->drawable.width <= PPW) &&
+                 !(pWin->border.pixmap->drawable.width &
+                   (pWin->border.pixmap->drawable.width - 1)))
+             {
+                 for (pBgWin = pWin;
+                      pBgWin->backgroundState == ParentRelative;
+                      pBgWin = pBgWin->parent);
+                 mfbCopyRotatePixmap(pWin->border.pixmap,
+                                     &pPrivWin->pRotatedBorder,
+                                     pBgWin->drawable.x,
+                                     pBgWin->drawable.y);
+                 if (pPrivWin->pRotatedBorder)
+                 {
+                     pPrivWin->fastBorder = TRUE;
+                     pPrivWin->oldRotate.x = pBgWin->drawable.x;
+                     pPrivWin->oldRotate.y = pBgWin->drawable.y;
+                 }
+                 else
+                 {
+                     pPrivWin->fastBorder = FALSE;
+                 }
+             }
+             else
+             {
+                 pPrivWin->fastBorder = FALSE;
+             }
+             break;
+           case CWBorderPixel:
+             pPrivWin->fastBorder = FALSE;
+             break;
+       }
+    }
+    /* Again, we have no failure modes indicated by any of the routines
+     * we've called, so we have to assume it worked */
+    return (TRUE);
+}
diff --git a/Xserver/programs/Xserver/mfb/mfbzerarc.c b/Xserver/programs/Xserver/mfb/mfbzerarc.c
new file mode 100644 (file)
index 0000000..887e94b
--- /dev/null
@@ -0,0 +1,255 @@
+/************************************************************
+
+Copyright (c) 1989  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+********************************************************/
+
+/* $XConsortium: mfbzerarc.c /main/21 1995/12/06 16:55:48 dpw $ */
+/* $XFree86: xc/programs/Xserver/mfb/mfbzerarc.c,v 3.1 1996/01/05 13:19:46 dawes Exp $ */
+
+/* Derived from:
+ * "Algorithm for drawing ellipses or hyperbolae with a digital plotter"
+ * by M. L. V. Pitteway
+ * The Computer Journal, November 1967, Volume 10, Number 3, pp. 282-289
+ */
+
+#include "X.h"
+#include "Xprotostr.h"
+#include "miscstruct.h"
+#include "gcstruct.h"
+#include "pixmapstr.h"
+#include "scrnintstr.h"
+#include "mfb.h"
+#include "maskbits.h"
+#include "mizerarc.h"
+#include "mi.h"
+
+/*
+ * Note: LEFTMOST must be the bit leftmost in the actual screen
+ * representation.  This depends also on the IMAGE_BYTE_ORDER.
+ * LONG2CHARS() takes care of the re-ordering as required. (DHD)
+ */
+#if (BITMAP_BIT_ORDER == MSBFirst)
+#define LEFTMOST       ((PixelType) LONG2CHARS(((unsigned long)1 << PLST)))
+#else
+#define LEFTMOST       ((PixelType) LONG2CHARS(1))
+#endif
+
+#define PixelateWhite(addr,yoff,xoff) \
+    *mfbScanlineOffset(addr, (yoff)+((xoff)>>PWSH)) |= \
+       SCRRIGHT (LEFTMOST, ((xoff) & PIM))
+#define PixelateBlack(addr,yoff,xoff) \
+    *mfbScanlineOffset(addr, (yoff)+((xoff)>>PWSH)) &= \
+       ~(SCRRIGHT (LEFTMOST, ((xoff) & PIM)))
+
+#define Pixelate(base,yoff,xoff) \
+{ \
+    paddr = mfbScanlineOffset(base, (yoff) + ((xoff)>>PWSH)); \
+    pmask = SCRRIGHT(LEFTMOST, (xoff) & PIM); \
+    *paddr = (*paddr & ~pmask) | (pixel & pmask); \
+}
+
+#define DoPix(bit,base,yoff,xoff) if (mask & bit) Pixelate(base,yoff,xoff);
+
+static void
+mfbZeroArcSS(pDraw, pGC, arc)
+    DrawablePtr pDraw;
+    GCPtr pGC;
+    xArc *arc;
+{
+    miZeroArcRec info;
+    Bool do360;
+    register int x, y, a, b, d, mask;
+    register int k1, k3, dx, dy;
+    PixelType *addrl;
+    PixelType *yorgl, *yorgol;
+    PixelType pixel;
+    int nlwidth, yoffset, dyoffset;
+    PixelType pmask;
+    register PixelType *paddr;
+
+    if (((mfbPrivGC *)(pGC->devPrivates[mfbGCPrivateIndex].ptr))->rop ==
+       RROP_BLACK)
+       pixel = 0;
+    else
+       pixel = ~0;
+
+    mfbGetPixelWidthAndPointer(pDraw, nlwidth, addrl);
+    do360 = miZeroArcSetup(arc, &info, TRUE);
+    yorgl = addrl + ((info.yorg + pDraw->y) * nlwidth);
+    yorgol = addrl + ((info.yorgo + pDraw->y) * nlwidth);
+    info.xorg += pDraw->x;
+    info.xorgo += pDraw->x;
+    MIARCSETUP();
+    yoffset = y ? nlwidth : 0;
+    dyoffset = 0;
+    mask = info.initialMask;
+    if (!(arc->width & 1))
+    {
+       DoPix(2, yorgl, 0, info.xorgo);
+       DoPix(8, yorgol, 0, info.xorgo);
+    }
+    if (!info.end.x || !info.end.y)
+    {
+       mask = info.end.mask;
+       info.end = info.altend;
+    }
+    if (do360 && (arc->width == arc->height) && !(arc->width & 1))
+    {
+       int xoffset = nlwidth;
+       PixelType *yorghl = mfbScanlineDeltaNoBankSwitch(yorgl, info.h, nlwidth);
+       int xorghp = info.xorg + info.h;
+       int xorghn = info.xorg - info.h;
+
+       if (pixel)
+       {
+           while (1)
+           {
+               PixelateWhite(yorgl, yoffset, info.xorg + x);
+               PixelateWhite(yorgl, yoffset, info.xorg - x);
+               PixelateWhite(yorgol, -yoffset, info.xorg - x);
+               PixelateWhite(yorgol, -yoffset, info.xorg + x);
+               if (a < 0)
+                   break;
+               PixelateWhite(yorghl, -xoffset, xorghp - y);
+               PixelateWhite(yorghl, -xoffset, xorghn + y);
+               PixelateWhite(yorghl, xoffset, xorghn + y);
+               PixelateWhite(yorghl, xoffset, xorghp - y);
+               xoffset += nlwidth;
+               MIARCCIRCLESTEP(yoffset += nlwidth;);
+           }
+       }
+       else
+       {
+           while (1)
+           {
+               PixelateBlack(yorgl, yoffset, info.xorg + x);
+               PixelateBlack(yorgl, yoffset, info.xorg - x);
+               PixelateBlack(yorgol, -yoffset, info.xorg - x);
+               PixelateBlack(yorgol, -yoffset, info.xorg + x);
+               if (a < 0)
+                   break;
+               PixelateBlack(yorghl, -xoffset, xorghp - y);
+               PixelateBlack(yorghl, -xoffset, xorghn + y);
+               PixelateBlack(yorghl, xoffset, xorghn + y);
+               PixelateBlack(yorghl, xoffset, xorghp - y);
+               xoffset += nlwidth;
+               MIARCCIRCLESTEP(yoffset += nlwidth;);
+           }
+       }
+       x = info.w;
+       yoffset = info.h * nlwidth;
+    }
+    else if (do360)
+    {
+       while (y < info.h || x < info.w)
+       {
+           MIARCOCTANTSHIFT(dyoffset = nlwidth;);
+           Pixelate(yorgl, yoffset, info.xorg + x);
+           Pixelate(yorgl, yoffset, info.xorgo - x);
+           Pixelate(yorgol, -yoffset, info.xorgo - x);
+           Pixelate(yorgol, -yoffset, info.xorg + x);
+           MIARCSTEP(yoffset += dyoffset;, yoffset += nlwidth;);
+       }
+    }
+    else
+    {
+       while (y < info.h || x < info.w)
+       {
+           MIARCOCTANTSHIFT(dyoffset = nlwidth;);
+           if ((x == info.start.x) || (y == info.start.y))
+           {
+               mask = info.start.mask;
+               info.start = info.altstart;
+           }
+           DoPix(1, yorgl, yoffset, info.xorg + x);
+           DoPix(2, yorgl, yoffset, info.xorgo - x);
+           DoPix(4, yorgol, -yoffset, info.xorgo - x);
+           DoPix(8, yorgol, -yoffset, info.xorg + x);
+           if ((x == info.end.x) || (y == info.end.y))
+           {
+               mask = info.end.mask;
+               info.end = info.altend;
+           }
+           MIARCSTEP(yoffset += dyoffset;, yoffset += nlwidth;);
+       }
+    }
+    if ((x == info.start.x) || (y == info.start.y))
+       mask = info.start.mask;
+    DoPix(1, yorgl, yoffset, info.xorg + x);
+    DoPix(4, yorgol, -yoffset, info.xorgo - x);
+    if (arc->height & 1)
+    {
+       DoPix(2, yorgl, yoffset, info.xorgo - x);
+       DoPix(8, yorgol, -yoffset, info.xorg + x);
+    }
+}
+
+void
+mfbZeroPolyArcSS(pDraw, pGC, narcs, parcs)
+    DrawablePtr        pDraw;
+    GCPtr      pGC;
+    int                narcs;
+    xArc       *parcs;
+{
+    register xArc *arc;
+    register int i;
+    BoxRec box;
+    int x2, y2;
+    RegionPtr cclip;
+
+    if (!pGC->planemask & 1)
+       return;
+    cclip = ((mfbPrivGC *)(pGC->devPrivates[mfbGCPrivateIndex].ptr))->pCompositeClip;
+    for (arc = parcs, i = narcs; --i >= 0; arc++)
+    {
+       if (miCanZeroArc(arc))
+       {
+           box.x1 = arc->x + pDraw->x;
+           box.y1 = arc->y + pDraw->y;
+           /*
+            * Because box.x2 and box.y2 get truncated to 16 bits, and the
+            * RECT_IN_REGION test treats the resulting number as a signed
+            * integer, the RECT_IN_REGION test alone can go the wrong way.
+            * This can result in a server crash because the rendering
+            * routines in this file deal directly with cpu addresses
+            * of pixels to be stored, and do not clip or otherwise check
+            * that all such addresses are within their respective pixmaps.
+            * So we only allow the RECT_IN_REGION test to be used for
+            * values that can be expressed correctly in a signed short.
+            */
+           x2 = box.x1 + (int)arc->width + 1;
+           box.x2 = x2;
+           y2 = box.y1 + (int)arc->height + 1;
+           box.y2 = y2;
+           if ( (x2 <= MAXSHORT) && (y2 <= MAXSHORT) &&
+                   (RECT_IN_REGION(pDraw->pScreen, cclip, &box) == rgnIN) )
+               mfbZeroArcSS(pDraw, pGC, arc);
+           else
+               miZeroPolyArc(pDraw, pGC, 1, arc);
+       }
+       else
+           miPolyArc(pDraw, pGC, 1, arc);
+    }
+}
diff --git a/Xserver/programs/Xserver/mi/Imakefile b/Xserver/programs/Xserver/mi/Imakefile
new file mode 100644 (file)
index 0000000..2d75c45
--- /dev/null
@@ -0,0 +1,74 @@
+XCOMM $XFree86: xc/programs/Xserver/mi/Imakefile,v 3.11.2.1 1997/05/03 09:50:45 dawes Exp $
+XCOMM $XConsortium: Imakefile /main/44 1996/12/02 10:22:16 lehors $
+#include <Server.tmpl>
+
+#if ! HasCbrt
+CBRT_SRC = cbrt.c
+CBRT_OBJ = cbrt.o
+#endif
+
+SRCS =  $(CBRT_SRC) mivaltree.c mipolyseg.c mipolyrect.c \
+       mipoly.c mipolycon.c mipolygen.c mipolyutil.c \
+       mifillrct.c miwideline.c mispans.c \
+       miarc.c mizerarc.c mifillarc.c \
+       miwindow.c micursor.c miregion.c \
+       mipolytext.c mibitblt.c mipolypnt.c mipushpxl.c \
+       miexpose.c miglblt.c mizerline.c mifpolycon.c \
+       midash.c mibstore.c miinitext.c mieq.c \
+       mipointer.c misprite.c midispcur.c miscrinit.c miclipn.c migc.c
+
+OBJS = $(CBRT_OBJ) mivaltree.o mipolyseg.o mipolyrect.o \
+       mipoly.o mipolycon.o mipolygen.o mipolyutil.o \
+       mifillrct.o miwideline.o mispans.o \
+       miarc.o mizerarc.o mifillarc.o \
+       miwindow.o micursor.o miregion.o \
+       mipolytext.o mibitblt.o mipolypnt.o mipushpxl.o \
+       miexpose.o miglblt.o mizerline.o mifpolycon.o \
+       midash.o mibstore.o miinitext.o mieq.o \
+       mipointer.o misprite.o midispcur.o miscrinit.o miclipn.o migc.o
+
+#ifdef XFree86Version
+/* 
+ * Make sure XINPUT, XF86VidTune, etc aren't defined for the miinitext.o 
+ * used by Xnest, Xvfb 
+ */
+EXT_DEFINES = ExtensionDefines -UXINPUT -UXF86VIDMODE -UXFreeXDGA -UXF86MISC
+#else
+EXT_DEFINES = ExtensionDefines
+#endif
+#if PexDynamicModule
+PEX_MODULE_DEFINES = -DPEX_MODULE
+#endif
+#if XieDynamicModule
+XIE_MODULE_DEFINES = -DXIE_MODULE
+#endif
+EXT_MODULES_DEFINES = $(PEX_MODULE_DEFINES) $(XIE_MODULE_DEFINES)
+
+INCLUDES = -I. -I../include -I../../../include/fonts \
+           -I$(XINCLUDESRC) -I$(FONTINCSRC)
+LINTLIBS = ../dix/llib-ldix.ln ../os/llib-los.ln
+
+NormalLibraryObjectRule()
+NormalLibraryTarget(mi,$(OBJS))
+LintLibraryTarget(mi,$(SRCS))
+NormalLintTarget($(SRCS))
+
+#ifndef Win32Architecture
+NormalLibraryTarget(cbrt,cbrt.o)
+#endif
+
+SpecialCObjectRule(miinitext,$(ICONFIGFILES),$(EXT_DEFINES) -UGLXEXT)
+SpecialCObjectRule(miscrinit,$(ICONFIGFILES),$(EXT_DEFINES))
+
+InstallLinkKitLibrary(mi,$(LINKKITDIR)/lib)
+InstallLinkKitLibrary(cbrt,$(LINKKITDIR)/lib)
+InstallLinkKitNonExecFile(mi.h,$(LINKKITDIR)/include)
+InstallLinkKitNonExecFile(mibstore.h,$(LINKKITDIR)/include)
+InstallLinkKitNonExecFile(miline.h,$(LINKKITDIR)/include)
+InstallLinkKitNonExecFile(mipointer.h,$(LINKKITDIR)/include)
+InstallLinkKitNonExecFile(misprite.h,$(LINKKITDIR)/include)
+InstallLinkKitNonExecFile(mispritest.h,$(LINKKITDIR)/include)
+InstallLinkKitNonExecFile(mistruct.h,$(LINKKITDIR)/include)
+InstallLinkKitNonExecFile(miinitext.c,$(LINKKITDIR))
+
+DependTarget()
diff --git a/Xserver/programs/Xserver/mi/cbrt.c b/Xserver/programs/Xserver/mi/cbrt.c
new file mode 100644 (file)
index 0000000..06d8dfb
--- /dev/null
@@ -0,0 +1,45 @@
+/* $XConsortium: cbrt.c,v 1.2 94/04/17 20:27:10 dpw Exp $ */
+/* $XFree86: xc/programs/Xserver/mi/cbrt.c,v 3.0 1994/04/29 14:11:16 dawes Exp $ */
+/*
+
+Copyright (c) 1990  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be included
+in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR
+OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall
+not be used in advertising or otherwise to promote the sale, use or
+other dealings in this Software without prior written authorization
+from the X Consortium.
+
+*/
+
+/* simple cbrt, in case your math library doesn't have a good one */
+
+double pow();
+
+double
+cbrt(x)
+    double x;
+{
+    if (x > 0.0)
+       return pow(x, 1.0/3.0);
+    else
+       return -pow(-x, 1.0/3.0);
+}
diff --git a/Xserver/programs/Xserver/mi/mi.h b/Xserver/programs/Xserver/mi/mi.h
new file mode 100644 (file)
index 0000000..b836fc7
--- /dev/null
@@ -0,0 +1,762 @@
+/* $XConsortium: mi.h,v 1.17 94/04/17 20:27:10 dpw Exp $ */
+/* $XFree86: xc/programs/Xserver/mi/mi.h,v 3.1 1997/01/14 22:22:51 dawes Exp $ */
+/***********************************************************
+
+Copyright (c) 1987  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+
+Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
+
+                        All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and its 
+documentation for any purpose and without fee is hereby granted, 
+provided that the above copyright notice appear in all copies and that
+both that copyright notice and this permission notice appear in 
+supporting documentation, and that the name of Digital not be
+used in advertising or publicity pertaining to distribution of the
+software without specific, written prior permission.  
+
+DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
+ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
+DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
+ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+SOFTWARE.
+
+******************************************************************/
+#ifndef MI_H
+#define MI_H
+#include "X11/X.h"
+#include "region.h"
+#include "validate.h"
+#include "window.h"
+#include "gc.h"
+#include "font.h"
+#include "input.h"
+#include "cursor.h"
+
+typedef struct _miDash *miDashPtr;
+#define EVEN_DASH      0
+#define ODD_DASH       ~0
+
+/* miarc.c */
+
+extern void miPolyArc(
+#if NeedFunctionPrototypes
+    DrawablePtr /*pDraw*/,
+    GCPtr /*pGC*/,
+    int /*narcs*/,
+    xArc * /*parcs*/
+#endif
+);
+
+/* mibitblt.c */
+
+extern RegionPtr miCopyArea(
+#if NeedFunctionPrototypes
+    DrawablePtr /*pSrcDrawable*/,
+    DrawablePtr /*pDstDrawable*/,
+    GCPtr /*pGC*/,
+    int /*xIn*/,
+    int /*yIn*/,
+    int /*widthSrc*/,
+    int /*heightSrc*/,
+    int /*xOut*/,
+    int /*yOut*/
+#endif
+);
+
+extern void miOpqStipDrawable(
+#if NeedFunctionPrototypes
+    DrawablePtr /*pDraw*/,
+    GCPtr /*pGC*/,
+    RegionPtr /*prgnSrc*/,
+    unsigned long * /*pbits*/,
+    int /*srcx*/,
+    int /*w*/,
+    int /*h*/,
+    int /*dstx*/,
+    int /*dsty*/
+#endif
+);
+
+extern RegionPtr miCopyPlane(
+#if NeedFunctionPrototypes
+    DrawablePtr /*pSrcDrawable*/,
+    DrawablePtr /*pDstDrawable*/,
+    GCPtr /*pGC*/,
+    int /*srcx*/,
+    int /*srcy*/,
+    int /*width*/,
+    int /*height*/,
+    int /*dstx*/,
+    int /*dsty*/,
+    unsigned long /*bitPlane*/
+#endif
+);
+
+extern void miGetImage(
+#if NeedFunctionPrototypes
+    DrawablePtr /*pDraw*/,
+    int /*sx*/,
+    int /*sy*/,
+    int /*w*/,
+    int /*h*/,
+    unsigned int /*format*/,
+    unsigned long /*planeMask*/,
+    char * /*pdstLine*/
+#endif
+);
+
+extern void miPutImage(
+#if NeedFunctionPrototypes
+    DrawablePtr /*pDraw*/,
+    GCPtr /*pGC*/,
+    int /*depth*/,
+    int /*x*/,
+    int /*y*/,
+    int /*w*/,
+    int /*h*/,
+    int /*leftPad*/,
+    int /*format*/,
+    char * /*pImage*/
+#endif
+);
+
+/* miclipn.c */
+
+extern void miClipNotify(
+#if NeedFunctionPrototypes
+    void (* /*func*/)(
+#if NeedNestedPrototypes
+       WindowPtr /* pWin */,
+       int /* dx */,
+       int /* dy */
+#endif
+       )
+#endif
+);
+
+/* micursor.c */
+
+extern void miRecolorCursor(
+#if NeedFunctionPrototypes
+    ScreenPtr /*pScr*/,
+    CursorPtr /*pCurs*/,
+    Bool /*displayed*/
+#endif
+);
+
+/* midash.c */
+
+extern miDashPtr miDashLine(
+#if NeedFunctionPrototypes
+    int /*npt*/,
+    DDXPointPtr /*ppt*/,
+    unsigned int /*nDash*/,
+    unsigned char * /*pDash*/,
+    unsigned int /*offset*/,
+    int * /*pnseg*/
+#endif
+);
+
+extern void miStepDash(
+#if NeedFunctionPrototypes
+    int /*dist*/,
+    int * /*pDashIndex*/,
+    unsigned char * /*pDash*/,
+    int /*numInDashList*/,
+    int * /*pDashOffset*/
+#endif
+);
+
+/* mieq.c */
+
+
+#ifndef INPUT_H
+typedef struct _DeviceRec *DevicePtr;
+#endif
+
+extern Bool mieqInit(
+#if NeedFunctionPrototypes
+    DevicePtr /*pKbd*/,
+    DevicePtr /*pPtr*/
+#endif
+);
+
+extern void mieqEnqueue(
+#if NeedFunctionPrototypes
+    xEventPtr /*e*/
+#endif
+);
+
+extern void mieqSwitchScreen(
+#if NeedFunctionPrototypes
+    ScreenPtr /*pScreen*/,
+    Bool /*fromDIX*/
+#endif
+);
+
+extern int mieqProcessInputEvents(
+#if NeedFunctionPrototypes
+    void
+#endif
+);
+
+/* miexpose.c */
+
+extern RegionPtr miHandleExposures(
+#if NeedFunctionPrototypes
+    DrawablePtr /*pSrcDrawable*/,
+    DrawablePtr /*pDstDrawable*/,
+    GCPtr /*pGC*/,
+    int /*srcx*/,
+    int /*srcy*/,
+    int /*width*/,
+    int /*height*/,
+    int /*dstx*/,
+    int /*dsty*/,
+    unsigned long /*plane*/
+#endif
+);
+
+extern void miSendGraphicsExpose(
+#if NeedFunctionPrototypes
+    ClientPtr /*client*/,
+    RegionPtr /*pRgn*/,
+    XID /*drawable*/,
+    int /*major*/,
+    int /*minor*/
+#endif
+);
+
+extern void miSendExposures(
+#if NeedFunctionPrototypes
+    WindowPtr /*pWin*/,
+    RegionPtr /*pRgn*/,
+    int /*dx*/,
+    int /*dy*/
+#endif
+);
+
+extern void miWindowExposures(
+#if NeedFunctionPrototypes
+    WindowPtr /*pWin*/,
+    RegionPtr /*prgn*/,
+    RegionPtr /*other_exposed*/
+#endif
+);
+
+extern void miPaintWindow(
+#if NeedFunctionPrototypes
+    WindowPtr /*pWin*/,
+    RegionPtr /*prgn*/,
+    int /*what*/
+#endif
+);
+
+extern int miClearDrawable(
+#if NeedFunctionPrototypes
+    DrawablePtr /*pDraw*/,
+    GCPtr /*pGC*/
+#endif
+);
+
+/* mifillrct.c */
+
+extern void miPolyFillRect(
+#if NeedFunctionPrototypes
+    DrawablePtr /*pDrawable*/,
+    GCPtr /*pGC*/,
+    int /*nrectFill*/,
+    xRectangle * /*prectInit*/
+#endif
+);
+
+/* miglblt.c */
+
+extern void miPolyGlyphBlt(
+#if NeedFunctionPrototypes
+    DrawablePtr /*pDrawable*/,
+    GCPtr /*pGC*/,
+    int /*x*/,
+    int /*y*/,
+    unsigned int /*nglyph*/,
+    CharInfoPtr * /*ppci*/,
+    pointer /*pglyphBase*/
+#endif
+);
+
+extern void miImageGlyphBlt(
+#if NeedFunctionPrototypes
+    DrawablePtr /*pDrawable*/,
+    GCPtr /*pGC*/,
+    int /*x*/,
+    int /*y*/,
+    unsigned int /*nglyph*/,
+    CharInfoPtr * /*ppci*/,
+    pointer /*pglyphBase*/
+#endif
+);
+
+/* mipoly.c */
+
+extern void miFillPolygon(
+#if NeedFunctionPrototypes
+    DrawablePtr /*dst*/,
+    GCPtr /*pgc*/,
+    int /*shape*/,
+    int /*mode*/,
+    int /*count*/,
+    DDXPointPtr /*pPts*/
+#endif
+);
+
+/* mipolycon.c */
+
+extern Bool miFillConvexPoly(
+#if NeedFunctionPrototypes
+    DrawablePtr /*dst*/,
+    GCPtr /*pgc*/,
+    int /*count*/,
+    DDXPointPtr /*ptsIn*/
+#endif
+);
+
+/* mipolygen.c */
+
+extern Bool miFillGeneralPoly(
+#if NeedFunctionPrototypes
+    DrawablePtr /*dst*/,
+    GCPtr /*pgc*/,
+    int /*count*/,
+    DDXPointPtr /*ptsIn*/
+#endif
+);
+
+/* mipolypnt.c */
+
+extern void miPolyPoint(
+#if NeedFunctionPrototypes
+    DrawablePtr /*pDrawable*/,
+    GCPtr /*pGC*/,
+    int /*mode*/,
+    int /*npt*/,
+    xPoint * /*pptInit*/
+#endif
+);
+
+/* mipolyrect.c */
+
+extern void miPolyRectangle(
+#if NeedFunctionPrototypes
+    DrawablePtr /*pDraw*/,
+    GCPtr /*pGC*/,
+    int /*nrects*/,
+    xRectangle * /*pRects*/
+#endif
+);
+
+/* mipolyseg.c */
+
+extern void miPolySegment(
+#if NeedFunctionPrototypes
+    DrawablePtr /*pDraw*/,
+    GCPtr /*pGC*/,
+    int /*nseg*/,
+    xSegment * /*pSegs*/
+#endif
+);
+
+/* mipolytext.c */
+
+extern int miPolyText(
+#if NeedFunctionPrototypes
+    DrawablePtr /*pDraw*/,
+    GCPtr /*pGC*/,
+    int /*x*/,
+    int /*y*/,
+    int /*count*/,
+    char * /*chars*/,
+    FontEncoding /*fontEncoding*/
+#endif
+);
+
+extern int miPolyText8(
+#if NeedFunctionPrototypes
+    DrawablePtr /*pDraw*/,
+    GCPtr /*pGC*/,
+    int /*x*/,
+    int /*y*/,
+    int /*count*/,
+    char * /*chars*/
+#endif
+);
+
+extern int miPolyText16(
+#if NeedFunctionPrototypes
+    DrawablePtr /*pDraw*/,
+    GCPtr /*pGC*/,
+    int /*x*/,
+    int /*y*/,
+    int /*count*/,
+    unsigned short * /*chars*/
+#endif
+);
+
+extern int miImageText(
+#if NeedFunctionPrototypes
+    DrawablePtr /*pDraw*/,
+    GCPtr /*pGC*/,
+    int /*x*/,
+    int /*y*/,
+    int /*count*/,
+    char * /*chars*/,
+    FontEncoding /*fontEncoding*/
+#endif
+);
+
+extern void miImageText8(
+#if NeedFunctionPrototypes
+    DrawablePtr /*pDraw*/,
+    GCPtr /*pGC*/,
+    int /*x*/,
+    int /*y*/,
+    int /*count*/,
+    char * /*chars*/
+#endif
+);
+
+extern void miImageText16(
+#if NeedFunctionPrototypes
+    DrawablePtr /*pDraw*/,
+    GCPtr /*pGC*/,
+    int /*x*/,
+    int /*y*/,
+    int /*count*/,
+    unsigned short * /*chars*/
+#endif
+);
+
+/* mipushpxl.c */
+
+extern void miPushPixels(
+#if NeedFunctionPrototypes
+    GCPtr /*pGC*/,
+    PixmapPtr /*pBitMap*/,
+    DrawablePtr /*pDrawable*/,
+    int /*dx*/,
+    int /*dy*/,
+    int /*xOrg*/,
+    int /*yOrg*/
+#endif
+);
+
+/* miregion.c */
+
+/* see also region.h */
+
+extern Bool miRectAlloc(
+#if NeedFunctionPrototypes
+    RegionPtr /*pRgn*/,
+    int /*n*/
+#endif
+);
+
+extern void miSetExtents(
+#if NeedFunctionPrototypes
+    RegionPtr /*pReg*/
+#endif
+);
+
+extern int miFindMaxBand(
+#if NeedFunctionPrototypes
+    RegionPtr /*prgn*/
+#endif
+);
+
+#ifdef DEBUG
+extern Bool miValidRegion(
+#if NeedFunctionPrototypes
+    RegionPtr /*prgn*/
+#endif
+);
+#endif
+
+/* miscrinit.c */
+
+extern Bool miModifyPixmapHeader(
+#if NeedFunctionPrototypes
+    PixmapPtr /*pPixmap*/,
+    int /*width*/,
+    int /*height*/,
+    int /*depth*/,
+    int /*bitsPerPixel*/,
+    int /*devKind*/,
+    pointer /*pPixData*/
+#endif
+);
+
+extern Bool miCloseScreen(
+#if NeedFunctionPrototypes
+    int /*index*/,
+    ScreenPtr /*pScreen*/
+#endif
+);
+
+extern Bool miCreateScreenResources(
+#if NeedFunctionPrototypes
+    ScreenPtr /*pScreen*/
+#endif
+);
+
+extern Bool miScreenDevPrivateInit(
+#if NeedFunctionPrototypes
+    ScreenPtr /*pScreen*/,
+    int /*width*/,
+    pointer /*pbits*/
+#endif
+);
+
+#ifndef _XTYPEDEF_MIBSFUNCPTR
+typedef struct _miBSFuncRec *miBSFuncPtr;
+#define _XTYPEDEF_MIBSFUNCPTR
+#endif
+
+extern Bool miScreenInit(
+#if NeedFunctionPrototypes
+    ScreenPtr /*pScreen*/,
+    pointer /*pbits*/,
+    int /*xsize*/,
+    int /*ysize*/,
+    int /*dpix*/,
+    int /*dpiy*/,
+    int /*width*/,
+    int /*rootDepth*/,
+    int /*numDepths*/,
+    DepthPtr /*depths*/,
+    VisualID /*rootVisual*/,
+    int /*numVisuals*/,
+    VisualPtr /*visuals*/,
+    miBSFuncPtr /*bsfuncs*/
+#endif
+);
+
+extern int miAllocateGCPrivateIndex(
+#if NeedFunctionPrototypes
+    void
+#endif
+);
+
+/* mivaltree.c */
+
+extern int miShapedWindowIn(
+#if NeedFunctionPrototypes
+    ScreenPtr /*pScreen*/,
+    RegionPtr /*universe*/,
+    RegionPtr /*bounding*/,
+    BoxPtr /*rect*/,
+    int /*x*/,
+    int /*y*/
+#endif
+);
+
+extern int miValidateTree(
+#if NeedFunctionPrototypes
+    WindowPtr /*pParent*/,
+    WindowPtr /*pChild*/,
+    VTKind /*kind*/
+#endif
+);
+
+extern void miWideLine(
+#if NeedFunctionPrototypes
+    DrawablePtr /*pDrawable*/,
+    GCPtr /*pGC*/,
+    int /*mode*/,
+    int /*npt*/,
+    DDXPointPtr /*pPts*/
+#endif
+);
+
+extern void miWideDash(
+#if NeedFunctionPrototypes
+    DrawablePtr /*pDrawable*/,
+    GCPtr /*pGC*/,
+    int /*mode*/,
+    int /*npt*/,
+    DDXPointPtr /*pPts*/
+#endif
+);
+
+extern void miMiter(
+#if NeedFunctionPrototypes
+    void
+#endif
+);
+
+extern void miNotMiter(
+#if NeedFunctionPrototypes
+    void
+#endif
+);
+
+/* miwindow.c */
+
+extern void miClearToBackground(
+#if NeedFunctionPrototypes
+    WindowPtr /*pWin*/,
+    int /*x*/,
+    int /*y*/,
+    int /*w*/,
+    int /*h*/,
+    Bool /*generateExposures*/
+#endif
+);
+
+extern Bool miChangeSaveUnder(
+#if NeedFunctionPrototypes
+    WindowPtr /*pWin*/,
+    WindowPtr /*first*/
+#endif
+);
+
+extern void miPostChangeSaveUnder(
+#if NeedFunctionPrototypes
+    WindowPtr /*pWin*/,
+    WindowPtr /*pFirst*/
+#endif
+);
+
+extern void miMarkWindow(
+#if NeedFunctionPrototypes
+    WindowPtr /*pWin*/
+#endif
+);
+
+extern Bool miMarkOverlappedWindows(
+#if NeedFunctionPrototypes
+    WindowPtr /*pWin*/,
+    WindowPtr /*pFirst*/,
+    WindowPtr * /*ppLayerWin*/
+#endif
+);
+
+extern void miHandleValidateExposures(
+#if NeedFunctionPrototypes
+    WindowPtr /*pWin*/
+#endif
+);
+
+extern void miMoveWindow(
+#if NeedFunctionPrototypes
+    WindowPtr /*pWin*/,
+    int /*x*/,
+    int /*y*/,
+    WindowPtr /*pNextSib*/,
+    VTKind /*kind*/
+#endif
+);
+
+extern void miSlideAndSizeWindow(
+#if NeedFunctionPrototypes
+    WindowPtr /*pWin*/,
+    int /*x*/,
+    int /*y*/,
+    unsigned int /*w*/,
+    unsigned int /*h*/,
+    WindowPtr /*pSib*/
+#endif
+);
+
+extern WindowPtr miGetLayerWindow(
+#if NeedFunctionPrototypes
+    WindowPtr /*pWin*/
+#endif
+);
+
+extern void miSetShape(
+#if NeedFunctionPrototypes
+    WindowPtr /*pWin*/
+#endif
+);
+
+extern void miChangeBorderWidth(
+#if NeedFunctionPrototypes
+    WindowPtr /*pWin*/,
+    unsigned int /*width*/
+#endif
+);
+
+extern void miMarkUnrealizedWindow(
+#if NeedFunctionPrototypes
+    WindowPtr /*pChild*/,
+    WindowPtr /*pWin*/,
+    Bool /*fromConfigure*/
+#endif
+);
+
+extern void miZeroPolyArc(
+#if NeedFunctionPrototypes
+    DrawablePtr /*pDraw*/,
+    GCPtr /*pGC*/,
+    int /*narcs*/,
+    xArc * /*parcs*/
+#endif
+);
+
+/* mizerline.c */
+
+extern void miZeroLine(
+#if NeedFunctionPrototypes
+    DrawablePtr /*dst*/,
+    GCPtr /*pgc*/,
+    int /*mode*/,
+    int /*nptInit*/,
+    DDXPointRec * /*pptInit*/
+#endif
+);
+
+extern void miZeroDashLine(
+#if NeedFunctionPrototypes
+    DrawablePtr /*dst*/,
+    GCPtr /*pgc*/,
+    int /*mode*/,
+    int /*nptInit*/,
+    DDXPointRec * /*pptInit*/
+#endif
+);
+
+extern void miPolyFillArc(
+#if NeedFunctionPrototypes
+    DrawablePtr /*pDraw*/,
+    GCPtr /*pGC*/,
+    int /*narcs*/,
+    xArc * /*parcs*/
+#endif
+);
+
+#endif /* MI_H */
diff --git a/Xserver/programs/Xserver/mi/miarc.c b/Xserver/programs/Xserver/mi/miarc.c
new file mode 100644 (file)
index 0000000..a1f426c
--- /dev/null
@@ -0,0 +1,3677 @@
+/***********************************************************
+
+Copyright (c) 1987  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+
+Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
+
+                        All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and its 
+documentation for any purpose and without fee is hereby granted, 
+provided that the above copyright notice appear in all copies and that
+both that copyright notice and this permission notice appear in 
+supporting documentation, and that the name of Digital not be
+used in advertising or publicity pertaining to distribution of the
+software without specific, written prior permission.  
+
+DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
+ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
+DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
+ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+SOFTWARE.
+
+******************************************************************/
+/* $XConsortium: miarc.c /main/90 1996/08/01 19:25:10 dpw $ */
+/* Author: Keith Packard and Bob Scheifler */
+/* Warning: this code is toxic, do not dally very long here. */
+
+/* $XFree86: xc/programs/Xserver/mi/miarc.c,v 3.4.2.1 1997/07/13 14:45:05 dawes Exp $ */
+
+#ifdef _XOPEN_SOURCE
+#include <math.h>
+#else
+#define _XOPEN_SOURCE  /* to get prototype for hypot on some systems */
+#include <math.h>
+#undef _XOPEN_SOURCE
+#endif
+#include "X.h"
+#include "Xprotostr.h"
+#include "misc.h"
+#include "gcstruct.h"
+#include "scrnintstr.h"
+#include "pixmapstr.h"
+#include "windowstr.h"
+#include "mifpoly.h"
+#include "mi.h"
+#include "mifillarc.h"
+#include "Xfuncproto.h"
+
+static double miDsin(), miDcos(), miDasin(), miDatan2();
+double cbrt(
+#if NeedFunctionPrototypes
+            double
+#endif
+);
+
+#ifdef ICEILTEMPDECL
+ICEILTEMPDECL
+#endif
+
+/*
+ * some interesting sematic interpretation of the protocol:
+ *
+ * Self intersecting arcs (i.e. those spanning 360 degrees) 
+ *  never join with other arcs, and are drawn without caps
+ *  (unless on/off dashed, in which case each dash segment
+ *  is capped, except when the last segment meets the
+ *  first segment, when no caps are drawn)
+ *
+ * double dash arcs are drawn in two parts, first the
+ *  odd dashes (drawn in background) then the even dashes
+ *  (drawn in foreground).  This means that overlapping
+ *  sections of foreground/background are drawn twice,
+ *  first in background then in foreground.  The double-draw
+ *  occurs even when the function uses the destination values
+ *  (e.g. xor mode).  This is the same way the wide-line
+ *  code works and should be "fixed".
+ *
+ */
+
+#undef max
+#undef min
+
+#if defined (__GNUC__) && defined (__STDC__) && !defined (__STRICT_ANSI__)
+#define USE_INLINE
+#endif
+
+#ifdef USE_INLINE
+inline static const int max (const int x, const int y)
+{
+       return x>y? x:y;
+}
+
+inline static const int min (const int x, const int y)
+{
+       return x<y? x:y;
+}
+
+#else
+
+static int
+max (x, y)
+{
+       return x>y? x:y;
+}
+
+static int
+min (x, y)
+{
+       return x<y? x:y;
+}
+
+#endif
+
+struct bound {
+       double  min, max;
+};
+
+struct ibound {
+       int     min, max;
+};
+
+#define boundedLe(value, bounds)\
+       ((bounds).min <= (value) && (value) <= (bounds).max)
+
+struct line {
+       double  m, b;
+       int     valid;
+};
+
+#define intersectLine(y,line) (line.m * (y) + line.b)
+
+/*
+ * these are all y value bounds
+ */
+
+struct arc_bound {
+       struct bound    ellipse;
+       struct bound    inner;
+       struct bound    outer;
+       struct bound    right;
+       struct bound    left;
+       struct ibound   inneri;
+       struct ibound   outeri;
+};
+
+struct accelerators {
+       double          tail_y;
+       double          h2;
+       double          w2;
+       double          h4;
+       double          w4;
+       double          h2mw2;
+       double          h2l;
+       double          w2l;
+       double          fromIntX;
+       double          fromIntY;
+       struct line     left, right;
+       int             yorgu;
+       int             yorgl;
+       int             xorg;
+};
+
+struct arc_def {
+       double  w, h, l;
+       double  a0, a1;
+};
+
+# define todeg(xAngle) (((double) (xAngle)) / 64.0)
+
+# define RIGHT_END     0
+# define LEFT_END      1
+
+typedef struct _miArcJoin {
+       int     arcIndex0, arcIndex1;
+       int     phase0, phase1;
+       int     end0, end1;
+} miArcJoinRec, *miArcJoinPtr;
+
+typedef struct _miArcCap {
+       int             arcIndex;
+       int             end;            
+} miArcCapRec, *miArcCapPtr;
+
+typedef struct _miArcFace {
+       SppPointRec     clock;
+       SppPointRec     center;
+       SppPointRec     counterClock;
+} miArcFaceRec, *miArcFacePtr;
+
+typedef struct _miArcData {
+       xArc            arc;
+       int             render;         /* non-zero means render after drawing */
+       int             join;           /* related join */
+       int             cap;            /* related cap */
+       int             selfJoin;       /* final dash meets first dash */
+       miArcFaceRec    bounds[2];
+       double          x0, y0, x1, y1;
+} miArcDataRec, *miArcDataPtr;
+
+/*
+ * This is an entire sequence of arcs, computed and categorized according
+ * to operation.  miDashArcs generates either one or two of these.
+ */
+
+typedef struct _miPolyArc {
+       int             narcs;
+       miArcDataPtr    arcs;
+       int             ncaps;
+       miArcCapPtr     caps;
+       int             njoins;
+       miArcJoinPtr    joins;
+} miPolyArcRec, *miPolyArcPtr;
+
+#define GCValsFunction         0
+#define GCValsForeground       1
+#define GCValsBackground       2
+#define GCValsLineWidth        3
+#define GCValsCapStyle                 4
+#define GCValsJoinStyle                5
+#define GCValsMask             (GCFunction | GCForeground | GCBackground | \
+                                GCLineWidth | GCCapStyle | GCJoinStyle)
+static CARD32 gcvals[6];
+
+static void fillSpans(), newFinalSpan();
+static void drawArc(), drawQuadrant(), drawZeroArc();
+static void miArcJoin(), miArcCap(), miRoundCap(), miFreeArcs();
+static int computeAngleFromPath();
+static miPolyArcPtr miComputeArcs ();
+static int miGetArcPts();
+
+# define CUBED_ROOT_2  1.2599210498948732038115849718451499938964
+# define CUBED_ROOT_4  1.5874010519681993173435330390930175781250
+
+/*
+ * draw one segment of the arc using the arc spans generation routines
+ */
+
+static void
+miArcSegment(pDraw, pGC, tarc, right, left)
+    DrawablePtr   pDraw;
+    GCPtr         pGC;
+    xArc          tarc;
+    miArcFacePtr       right, left;
+{
+    int l = pGC->lineWidth;
+    int a0, a1, startAngle, endAngle;
+    miArcFacePtr       temp;
+
+    if (!l)
+       l = 1;
+
+    if (tarc.width == 0 || tarc.height == 0) {
+       drawZeroArc (pDraw, pGC, &tarc, l, left, right);
+       return;
+    }
+
+    if (pGC->miTranslate) {
+       tarc.x += pDraw->x;
+       tarc.y += pDraw->y;
+    }
+
+    a0 = tarc.angle1;
+    a1 = tarc.angle2;
+    if (a1 > FULLCIRCLE)
+       a1 = FULLCIRCLE;
+    else if (a1 < -FULLCIRCLE)
+       a1 = -FULLCIRCLE;
+    if (a1 < 0) {
+       startAngle = a0 + a1;
+       endAngle = a0;
+       temp = right;
+       right = left;
+       left = temp;
+    } else {
+       startAngle = a0;
+       endAngle = a0 + a1;
+    }
+    /*
+     * bounds check the two angles
+     */
+    if (startAngle < 0)
+       startAngle = FULLCIRCLE - (-startAngle) % FULLCIRCLE;
+    if (startAngle >= FULLCIRCLE)
+       startAngle = startAngle % FULLCIRCLE;
+    if (endAngle < 0)
+       endAngle = FULLCIRCLE - (-endAngle) % FULLCIRCLE;
+    if (endAngle > FULLCIRCLE)
+       endAngle = (endAngle-1) % FULLCIRCLE + 1;
+    if ((startAngle == endAngle) && a1) {
+       startAngle = 0;
+       endAngle = FULLCIRCLE;
+    }
+
+    drawArc (&tarc, l, startAngle, endAngle, right, left);
+}
+
+/*
+
+Three equations combine to describe the boundaries of the arc
+
+x^2/w^2 + y^2/h^2 = 1                  ellipse itself
+(X-x)^2 + (Y-y)^2 = r^2                        circle at (x, y) on the ellipse
+(Y-y) = (X-x)*w^2*y/(h^2*x)            normal at (x, y) on the ellipse
+
+These lead to a quartic relating Y and y
+
+y^4 - (2Y)y^3 + (Y^2 + (h^4 - w^2*r^2)/(w^2 - h^2))y^2
+    - (2Y*h^4/(w^2 - h^2))y + (Y^2*h^4)/(w^2 - h^2) = 0
+
+The reducible cubic obtained from this quartic is
+
+z^3 - (3N)z^2 - 2V = 0
+
+where
+
+N = (Y^2 + (h^4 - w^2*r^2/(w^2 - h^2)))/6
+V = w^2*r^2*Y^2*h^4/(4 *(w^2 - h^2)^2)
+
+Let
+
+t = z - N
+p = -N^2
+q = -N^3 - V
+
+Then we get
+
+t^3 + 3pt + 2q = 0
+
+The discriminant of this cubic is
+
+D = q^2 + p^3
+
+When D > 0, a real root is obtained as
+
+z = N + cbrt(-q+sqrt(D)) + cbrt(-q-sqrt(D))
+
+When D < 0, a real root is obtained as
+
+z = N - 2m*cos(acos(-q/m^3)/3)
+
+where
+
+m = sqrt(|p|) * sign(q)
+
+Given a real root Z of the cubic, the roots of the quartic are the roots
+of the two quadratics
+
+y^2 + ((b+A)/2)y + (Z + (bZ - d)/A) = 0
+
+where 
+
+A = +/- sqrt(8Z + b^2 - 4c)
+b, c, d are the cubic, quadratic, and linear coefficients of the quartic
+
+Some experimentation is then required to determine which solutions
+correspond to the inner and outer boundaries.
+
+*/
+
+typedef struct {
+    short lx, lw, rx, rw;
+} miArcSpan;
+
+typedef struct {
+    miArcSpan *spans;
+    int count1, count2, k;
+    char top, bot, hole;
+} miArcSpanData;
+
+typedef struct {
+    unsigned long lrustamp;
+    unsigned short lw;
+    unsigned short width, height;
+    miArcSpanData *spdata;
+} arcCacheRec;
+
+#define CACHESIZE 25
+
+static arcCacheRec arcCache[CACHESIZE];
+static unsigned long lrustamp;
+static arcCacheRec *lastCacheHit = &arcCache[0];
+static RESTYPE cacheType;
+
+/*
+ * External so it can be called when low on memory.
+ * Call with a zero ID in that case.
+ */
+/*ARGSUSED*/
+int
+miFreeArcCache (data, id)
+    pointer        data;
+    XID                    id;
+{
+    int k;
+    arcCacheRec *cent;
+
+    if (id)
+       cacheType = 0;
+
+    for (k = CACHESIZE, cent = &arcCache[0]; --k >= 0; cent++)
+    {
+       if (cent->spdata)
+       {
+           cent->lrustamp = 0;
+           cent->lw = 0;
+           xfree(cent->spdata);
+           cent->spdata = NULL;
+       }
+    }
+    lrustamp = 0;
+    return Success;
+}
+
+static void
+miComputeCircleSpans(lw, parc, spdata)
+    int lw;
+    xArc *parc;
+    miArcSpanData *spdata;
+{
+    register miArcSpan *span;
+    int doinner;
+    register int x, y, e;
+    int xk, yk, xm, ym, dx, dy;
+    register int slw, inslw;
+    int inx, iny, ine;
+    int inxk, inyk, inxm, inym;
+
+    doinner = -lw;
+    slw = parc->width - doinner;
+    y = parc->height >> 1;
+    dy = parc->height & 1;
+    dx = 1 - dy;
+    MIWIDEARCSETUP(x, y, dy, slw, e, xk, xm, yk, ym);
+    inslw = parc->width + doinner;
+    if (inslw > 0)
+    {
+       spdata->hole = spdata->top;
+       MIWIDEARCSETUP(inx, iny, dy, inslw, ine, inxk, inxm, inyk, inym);
+    }
+    else
+    {
+       spdata->hole = FALSE;
+       doinner = -y;
+    }
+    spdata->count1 = -doinner - spdata->top;
+    spdata->count2 = y + doinner;
+    span = spdata->spans;
+    while (y)
+    {
+       MIFILLARCSTEP(slw);
+       span->lx = dy - x;
+       if (++doinner <= 0)
+       {
+           span->lw = slw;
+           span->rx = 0;
+           span->rw = span->lx + slw;
+       }
+       else
+       {
+           MIFILLINARCSTEP(inslw);
+           span->lw = x - inx;
+           span->rx = dy - inx + inslw;
+           span->rw = inx - x + slw - inslw;
+       }
+       span++;
+    }
+    if (spdata->bot)
+    {
+       if (spdata->count2)
+           spdata->count2--;
+       else
+       {
+           if (lw > (int)parc->height)
+               span[-1].rx = span[-1].rw = -((lw - (int)parc->height) >> 1);
+           else
+               span[-1].rw = 0;
+           spdata->count1--;
+       }
+    }
+}
+
+static void
+miComputeEllipseSpans(lw, parc, spdata)
+    int lw;
+    xArc *parc;
+    miArcSpanData *spdata;
+{
+    register miArcSpan *span;
+    double w, h, r, xorg;
+    double Hs, Hf, WH, K, Vk, Nk, Fk, Vr, N, Nc, Z, rs;
+    double A, T, b, d, x, y, t, inx, outx, hepp, hepm;
+    int flip, solution;
+
+    w = (double)parc->width / 2.0;
+    h = (double)parc->height / 2.0;
+    r = lw / 2.0;
+    rs = r * r;
+    Hs = h * h;
+    WH = w * w - Hs;
+    Nk = w * r;
+    Vk = (Nk * Hs) / (WH + WH);
+    Hf = Hs * Hs;
+    Nk = (Hf - Nk * Nk) / WH;
+    Fk = Hf / WH;
+    hepp = h + EPSILON;
+    hepm = h - EPSILON;
+    K = h + ((lw - 1) >> 1);
+    span = spdata->spans;
+    if (parc->width & 1)
+       xorg = .5;
+    else
+       xorg = 0.0;
+    if (spdata->top)
+    {
+       span->lx = 0;
+       span->lw = 1;
+       span++;
+    }
+    spdata->count1 = 0;
+    spdata->count2 = 0;
+    spdata->hole = (spdata->top &&
+                (int)parc->height * lw <= (int)(parc->width * parc->width) &&
+                   lw < (int)parc->height);
+    for (; K > 0.0; K -= 1.0)
+    {
+       N = (K * K + Nk) / 6.0;
+       Nc = N * N * N;
+       Vr = Vk * K;
+       t = Nc + Vr * Vr;
+       d = Nc + t;
+       if (d < 0.0) {
+           d = Nc;
+           b = N;
+           if ( (b < 0.0) == (t < 0.0) )
+           {
+               b = -b;
+               d = -d;
+           }
+           Z = N - 2.0 * b * cos(acos(-t / d) / 3.0);
+           if ( (Z < 0.0) == (Vr < 0.0) )
+               flip = 2;
+           else
+               flip = 1;
+       }
+       else
+       {
+           d = Vr * sqrt(d);
+           Z = N + cbrt(t + d) + cbrt(t - d);
+           flip = 0;
+       }
+       A = sqrt((Z + Z) - Nk);
+       T = (Fk - Z) * K / A;
+       inx = 0.0;
+       solution = FALSE;
+       b = -A + K;
+       d = b * b - 4 * (Z + T);
+       if (d >= 0)
+       {
+           d = sqrt(d);
+           y = (b + d) / 2;
+           if ((y >= 0.0) && (y < hepp))
+           {
+               solution = TRUE;
+               if (y > hepm)
+                   y = h;
+               t = y / h;
+               x = w * sqrt(1 - (t * t));
+               t = K - y;
+               if (rs - (t * t) >= 0)
+                  t = sqrt(rs - (t * t));
+               else
+                  t = 0;
+               if (flip == 2)
+                   inx = x - t;
+               else
+                   outx = x + t;
+           }
+       }
+       b = A + K;
+       d = b * b - 4 * (Z - T);
+       /* Because of the large magnitudes involved, we lose enough precision
+        * that sometimes we end up with a negative value near the axis, when
+        * it should be positive.  This is a workaround.
+        */
+       if (d < 0 && !solution)
+           d = 0.0;
+       if (d >= 0) {
+           d = sqrt(d);
+           y = (b + d) / 2;
+           if (y < hepp)
+           {
+               if (y > hepm)
+                   y = h;
+               t = y / h;
+               x = w * sqrt(1 - (t * t));
+               t = K - y;
+               if (rs - (t * t) >= 0)
+                  inx = x - sqrt(rs - (t * t));
+               else
+                  inx = x;
+           }
+           y = (b - d) / 2;
+           if (y >= 0.0)
+           {
+               if (y > hepm)
+                   y = h;
+               t = y / h;
+               x = w * sqrt(1 - (t * t));
+               t = K - y;
+               if (rs - (t * t) >= 0)
+                  t = sqrt(rs - (t * t));
+               else 
+                  t = 0;
+               if (flip == 1)
+                   inx = x - t;
+               else
+                   outx = x + t;
+           }
+       }
+       span->lx = ICEIL(xorg - outx);
+       if (inx <= 0.0)
+       {
+           spdata->count1++;
+           span->lw = ICEIL(xorg + outx) - span->lx;
+           span->rx = ICEIL(xorg + inx);
+           span->rw = -ICEIL(xorg - inx);
+       }
+       else
+       {
+           spdata->count2++;
+           span->lw = ICEIL(xorg - inx) - span->lx;
+           span->rx = ICEIL(xorg + inx);
+           span->rw = ICEIL(xorg + outx) - span->rx;
+       }
+       span++;
+    }
+    if (spdata->bot)
+    {
+       outx = w + r;
+       if (r >= h && r <= w)
+           inx = 0.0;
+       else if (Nk < 0.0 && -Nk < Hs)
+       {
+           inx = w * sqrt(1 + Nk / Hs) - sqrt(rs + Nk);
+           if (inx > w - r)
+               inx = w - r;
+       }
+       else
+           inx = w - r;
+       span->lx = ICEIL(xorg - outx);
+       if (inx <= 0.0)
+       {
+           span->lw = ICEIL(xorg + outx) - span->lx;
+           span->rx = ICEIL(xorg + inx);
+           span->rw = -ICEIL(xorg - inx);
+       }
+       else
+       {
+           span->lw = ICEIL(xorg - inx) - span->lx;
+           span->rx = ICEIL(xorg + inx);
+           span->rw = ICEIL(xorg + outx) - span->rx;
+       }
+    }
+    if (spdata->hole)
+    {
+       span = &spdata->spans[spdata->count1];
+       span->lw = -span->lx;
+       span->rx = 1;
+       span->rw = span->lw;
+       spdata->count1--;
+       spdata->count2++;
+    }
+}
+
+static double
+tailX(K, def, bounds, acc)
+    double K;
+    struct arc_def *def;
+    struct arc_bound *bounds;
+    struct accelerators *acc;
+{
+    double w, h, r;
+    double Hs, Hf, WH, Vk, Nk, Fk, Vr, N, Nc, Z, rs;
+    double A, T, b, d, x, y, t, hepp, hepm;
+    int flip, solution;
+    double xs[2];
+    double *xp;
+
+    w = def->w;
+    h = def->h;
+    r = def->l;
+    rs = r * r;
+    Hs = acc->h2;
+    WH = -acc->h2mw2;
+    Nk = def->w * r;
+    Vk = (Nk * Hs) / (WH + WH);
+    Hf = acc->h4;
+    Nk = (Hf - Nk * Nk) / WH;
+    if (K == 0.0) {
+       if (Nk < 0.0 && -Nk < Hs) {
+           xs[0] = w * sqrt(1 + Nk / Hs) - sqrt(rs + Nk);
+           xs[1] = w - r;
+           if (acc->left.valid && boundedLe(K, bounds->left) &&
+               !boundedLe(K, bounds->outer) && xs[0] >= 0.0 && xs[1] >= 0.0)
+               return xs[1];
+           if (acc->right.valid && boundedLe(K, bounds->right) &&
+               !boundedLe(K, bounds->inner) && xs[0] <= 0.0 && xs[1] <= 0.0)
+               return xs[1];
+           return xs[0];
+       }
+       return w - r;
+    }
+    Fk = Hf / WH;
+    hepp = h + EPSILON;
+    hepm = h - EPSILON;
+    N = (K * K + Nk) / 6.0;
+    Nc = N * N * N;
+    Vr = Vk * K;
+    xp = xs;
+    xs[0] = 0.0;
+    t = Nc + Vr * Vr;
+    d = Nc + t;
+    if (d < 0.0) {
+       d = Nc;
+       b = N;
+       if ( (b < 0.0) == (t < 0.0) )
+       {
+           b = -b;
+           d = -d;
+       }
+       Z = N - 2.0 * b * cos(acos(-t / d) / 3.0);
+       if ( (Z < 0.0) == (Vr < 0.0) )
+           flip = 2;
+       else
+           flip = 1;
+    }
+    else
+    {
+       d = Vr * sqrt(d);
+       Z = N + cbrt(t + d) + cbrt(t - d);
+       flip = 0;
+    }
+    A = sqrt((Z + Z) - Nk);
+    T = (Fk - Z) * K / A;
+    solution = FALSE;
+    b = -A + K;
+    d = b * b - 4 * (Z + T);
+    if (d >= 0 && flip == 2)
+    {
+       d = sqrt(d);
+       y = (b + d) / 2;
+       if ((y >= 0.0) && (y < hepp))
+       {
+           solution = TRUE;
+           if (y > hepm)
+               y = h;
+           t = y / h;
+           x = w * sqrt(1 - (t * t));
+           t = K - y;
+           if (rs - (t * t) >= 0)
+              t = sqrt(rs - (t * t));
+           else
+              t = 0;
+           *xp++ = x - t;
+       }
+    }
+    b = A + K;
+    d = b * b - 4 * (Z - T);
+    /* Because of the large magnitudes involved, we lose enough precision
+     * that sometimes we end up with a negative value near the axis, when
+     * it should be positive.  This is a workaround.
+     */
+    if (d < 0 && !solution)
+       d = 0.0;
+    if (d >= 0) {
+       d = sqrt(d);
+       y = (b + d) / 2;
+       if (y < hepp)
+       {
+           if (y > hepm)
+               y = h;
+           t = y / h;
+           x = w * sqrt(1 - (t * t));
+           t = K - y;
+           if (rs - (t * t) >= 0)
+              *xp++ = x - sqrt(rs - (t * t));
+           else
+              *xp++ = x;
+       }
+       y = (b - d) / 2;
+       if (y >= 0.0 && flip == 1)
+       {
+           if (y > hepm)
+               y = h;
+           t = y / h;
+           x = w * sqrt(1 - (t * t));
+           t = K - y;
+           if (rs - (t * t) >= 0)
+              t = sqrt(rs - (t * t));
+           else
+              t = 0;
+           *xp++ = x - t;
+       }
+    }
+    if (xp > &xs[1]) {
+       if (acc->left.valid && boundedLe(K, bounds->left) &&
+           !boundedLe(K, bounds->outer) && xs[0] >= 0.0 && xs[1] >= 0.0)
+           return xs[1];
+       if (acc->right.valid && boundedLe(K, bounds->right) &&
+           !boundedLe(K, bounds->inner) && xs[0] <= 0.0 && xs[1] <= 0.0)
+           return xs[1];
+    }
+    return xs[0];
+}
+
+static miArcSpanData *
+miComputeWideEllipse(lw, parc, mustFree)
+    int                   lw;
+    register xArc *parc;
+    Bool         *mustFree;
+{
+    register miArcSpanData *spdata;
+    register arcCacheRec *cent, *lruent;
+    register int k;
+    arcCacheRec fakeent;
+
+    if (!lw)
+       lw = 1;
+    if (parc->height <= 1500)
+    {
+       *mustFree = FALSE;
+       cent = lastCacheHit;
+       if (cent->lw == lw &&
+           cent->width == parc->width && cent->height == parc->height)
+       {
+           cent->lrustamp = ++lrustamp;
+           return cent->spdata;
+       }
+       lruent = &arcCache[0];
+       for (k = CACHESIZE, cent = lruent; --k >= 0; cent++)
+       {
+           if (cent->lw == lw &&
+               cent->width == parc->width && cent->height == parc->height)
+           {
+               cent->lrustamp = ++lrustamp;
+               lastCacheHit = cent;
+               return cent->spdata;
+           }
+           if (cent->lrustamp < lruent->lrustamp)
+               lruent = cent;
+       }
+       if (!cacheType)
+       {
+           cacheType = CreateNewResourceType(miFreeArcCache);
+           (void) AddResource(FakeClientID(0), cacheType, NULL);
+       }
+    } else {
+       lruent = &fakeent;
+       lruent->spdata = NULL;
+       *mustFree = TRUE;
+    }
+    k = (parc->height >> 1) + ((lw - 1) >> 1);
+    spdata = lruent->spdata;
+    if (!spdata || spdata->k != k)
+    {
+       if (spdata)
+           xfree(spdata);
+       spdata = (miArcSpanData *)xalloc(sizeof(miArcSpanData) +
+                                        sizeof(miArcSpan) * (k + 2));
+       lruent->spdata = spdata;
+       if (!spdata)
+       {
+           lruent->lrustamp = 0;
+           lruent->lw = 0;
+           return spdata;
+       }
+       spdata->spans = (miArcSpan *)(spdata + 1);
+       spdata->k = k;
+    }
+    spdata->top = !(lw & 1) && !(parc->width & 1);
+    spdata->bot = !(parc->height & 1);
+    lruent->lrustamp = ++lrustamp;
+    lruent->lw = lw;
+    lruent->width = parc->width;
+    lruent->height = parc->height;
+    if (lruent != &fakeent)
+       lastCacheHit = lruent;
+    if (parc->width == parc->height)
+       miComputeCircleSpans(lw, parc, spdata);
+    else
+       miComputeEllipseSpans(lw, parc, spdata);
+    return spdata;
+}
+
+static void
+miFillWideEllipse(pDraw, pGC, parc)
+    DrawablePtr        pDraw;
+    GCPtr      pGC;
+    xArc       *parc;
+{
+    DDXPointPtr points;
+    register DDXPointPtr pts;
+    int *widths;
+    register int *wids;
+    miArcSpanData *spdata;
+    Bool mustFree;
+    register miArcSpan *span;
+    register int xorg, yorgu, yorgl;
+    register int n;
+
+    yorgu = parc->height + pGC->lineWidth;
+    n = (sizeof(int) * 2) * yorgu;
+    widths = (int *)ALLOCATE_LOCAL(n + (sizeof(DDXPointRec) * 2) * yorgu);
+    if (!widths)
+       return;
+    points = (DDXPointPtr)((char *)widths + n);
+    spdata = miComputeWideEllipse((int)pGC->lineWidth, parc, &mustFree);
+    if (!spdata)
+    {
+       DEALLOCATE_LOCAL(widths);
+       return;
+    }
+    pts = points;
+    wids = widths;
+    span = spdata->spans;
+    xorg = parc->x + (parc->width >> 1);
+    yorgu = parc->y + (parc->height >> 1);
+    yorgl = yorgu + (parc->height & 1);
+    if (pGC->miTranslate)
+    {
+       xorg += pDraw->x;
+       yorgu += pDraw->y;
+       yorgl += pDraw->y;
+    }
+    yorgu -= spdata->k;
+    yorgl += spdata->k;
+    if (spdata->top)
+    {
+       pts->x = xorg;
+       pts->y = yorgu - 1;
+       pts++;
+       *wids++ = 1;
+       span++;
+    }
+    for (n = spdata->count1; --n >= 0; )
+    {
+       pts[0].x = xorg + span->lx;
+       pts[0].y = yorgu;
+       wids[0] = span->lw;
+       pts[1].x = pts[0].x;
+       pts[1].y = yorgl;
+       wids[1] = wids[0];
+       yorgu++;
+       yorgl--;
+       pts += 2;
+       wids += 2;
+       span++;
+    }
+    if (spdata->hole)
+    {
+       pts[0].x = xorg;
+       pts[0].y = yorgl;
+       wids[0] = 1;
+       pts++;
+       wids++;
+    }
+    for (n = spdata->count2; --n >= 0; )
+    {
+       pts[0].x = xorg + span->lx;
+       pts[0].y = yorgu;
+       wids[0] = span->lw;
+       pts[1].x = xorg + span->rx;
+       pts[1].y = pts[0].y;
+       wids[1] = span->rw;
+       pts[2].x = pts[0].x;
+       pts[2].y = yorgl;
+       wids[2] = wids[0];
+       pts[3].x = pts[1].x;
+       pts[3].y = pts[2].y;
+       wids[3] = wids[1];
+       yorgu++;
+       yorgl--;
+       pts += 4;
+       wids += 4;
+       span++;
+    }
+    if (spdata->bot)
+    {
+       if (span->rw <= 0)
+       {
+           pts[0].x = xorg + span->lx;
+           pts[0].y = yorgu;
+           wids[0] = span->lw;
+           pts++;
+           wids++;
+       }       
+       else
+       {
+           pts[0].x = xorg + span->lx;
+           pts[0].y = yorgu;
+           wids[0] = span->lw;
+           pts[1].x = xorg + span->rx;
+           pts[1].y = pts[0].y;
+           wids[1] = span->rw;
+           pts += 2;
+           wids += 2;
+       }
+    }
+    if (mustFree)
+       xfree(spdata);
+    (*pGC->ops->FillSpans)(pDraw, pGC, pts - points, points, widths, FALSE);
+
+    DEALLOCATE_LOCAL(widths);
+}
+
+/*
+ * miPolyArc strategy:
+ *
+ * If arc is zero width and solid, we don't have to worry about the rasterop
+ * or join styles.  For wide solid circles, we use a fast integer algorithm.
+ * For wide solid ellipses, we use special case floating point code.
+ * Otherwise, we set up pDrawTo and pGCTo according to the rasterop, then
+ * draw using pGCTo and pDrawTo.  If the raster-op was "tricky," that is,
+ * if it involves the destination, then we use PushPixels to move the bits
+ * from the scratch drawable to pDraw. (See the wide line code for a
+ * fuller explanation of this.)
+ */
+
+void
+miPolyArc(pDraw, pGC, narcs, parcs)
+    DrawablePtr        pDraw;
+    GCPtr      pGC;
+    int                narcs;
+    xArc       *parcs;
+{
+    register int               i;
+    xArc                       *parc;
+    int                                xMin, xMax, yMin, yMax;
+    int                                pixmapWidth, pixmapHeight;
+    int                                xOrg, yOrg;
+    int                                width;
+    Bool                       fTricky;
+    DrawablePtr                        pDrawTo;
+    CARD32                     fg, bg;
+    GCPtr                      pGCTo;
+    miPolyArcPtr               polyArcs;
+    int                                cap[2], join[2];
+    int                                iphase;
+    int                                halfWidth;
+
+    width = pGC->lineWidth;
+    if(width == 0 && pGC->lineStyle == LineSolid)
+    {
+       for(i = narcs, parc = parcs; --i >= 0; parc++)
+           miArcSegment( pDraw, pGC, *parc,
+           (miArcFacePtr) 0, (miArcFacePtr) 0 );
+       fillSpans (pDraw, pGC);
+    }
+    else 
+    {
+       if ((pGC->lineStyle == LineSolid) && narcs)
+       {
+           while (parcs->width && parcs->height &&
+                  (parcs->angle2 >= FULLCIRCLE ||
+                   parcs->angle2 <= -FULLCIRCLE))
+           {
+               miFillWideEllipse(pDraw, pGC, parcs);
+               if (!--narcs)
+                   return;
+               parcs++;
+           }
+       }
+
+       /* Set up pDrawTo and pGCTo based on the rasterop */
+       switch(pGC->alu)
+       {
+         case GXclear:         /* 0 */
+         case GXcopy:          /* src */
+         case GXcopyInverted:  /* NOT src */
+         case GXset:           /* 1 */
+           fTricky = FALSE;
+           pDrawTo = pDraw;
+           pGCTo = pGC;
+           break;
+         default:
+           fTricky = TRUE;
+
+           /* find bounding box around arcs */
+           xMin = yMin = MAXSHORT;
+           xMax = yMax = MINSHORT;
+
+           for(i = narcs, parc = parcs; --i >= 0; parc++)
+           {
+               xMin = min (xMin, parc->x);
+               yMin = min (yMin, parc->y);
+               xMax = max (xMax, (parc->x + (int) parc->width));
+               yMax = max (yMax, (parc->y + (int) parc->height));
+           }
+
+           /* expand box to deal with line widths */
+           halfWidth = (width + 1)/2;
+           xMin -= halfWidth;
+           yMin -= halfWidth;
+           xMax += halfWidth;
+           yMax += halfWidth;
+
+           /* compute pixmap size; limit it to size of drawable */
+           xOrg = max(xMin, 0);
+           yOrg = max(yMin, 0);
+           pixmapWidth = min(xMax, pDraw->width) - xOrg;
+           pixmapHeight = min(yMax, pDraw->height) - yOrg;
+
+           /* if nothing left, return */
+           if ( (pixmapWidth <= 0) || (pixmapHeight <= 0) ) return;
+
+           for(i = narcs, parc = parcs; --i >= 0; parc++)
+           {
+               parc->x -= xOrg;
+               parc->y -= yOrg;
+           }
+           if (pGC->miTranslate)
+           {
+               xOrg += pDraw->x;
+               yOrg += pDraw->y;
+           }
+
+           /* set up scratch GC */
+
+           pGCTo = GetScratchGC(1, pDraw->pScreen);
+           if (!pGCTo)
+               return;
+           gcvals[GCValsFunction] = GXcopy;
+           gcvals[GCValsForeground] = 1;
+           gcvals[GCValsBackground] = 0;
+           gcvals[GCValsLineWidth] = pGC->lineWidth;
+           gcvals[GCValsCapStyle] = pGC->capStyle;
+           gcvals[GCValsJoinStyle] = pGC->joinStyle;
+           dixChangeGC(NullClient, pGCTo, GCValsMask, gcvals, NULL);
+    
+           /* allocate a 1 bit deep pixmap of the appropriate size, and
+            * validate it */
+           pDrawTo = (DrawablePtr)(*pDraw->pScreen->CreatePixmap)
+                               (pDraw->pScreen, pixmapWidth, pixmapHeight, 1);
+           if (!pDrawTo)
+           {
+               FreeScratchGC(pGCTo);
+               return;
+           }
+           ValidateGC(pDrawTo, pGCTo);
+           miClearDrawable(pDrawTo, pGCTo);
+       }
+
+       fg = pGC->fgPixel;
+       bg = pGC->bgPixel;
+       if ((pGC->fillStyle == FillTiled) ||
+           (pGC->fillStyle == FillOpaqueStippled))
+           bg = fg; /* the protocol sez these don't cause color changes */
+
+       polyArcs = miComputeArcs (parcs, narcs, pGC);
+
+       if (!polyArcs)
+       {
+           if (fTricky) {
+               (*pDraw->pScreen->DestroyPixmap) ((PixmapPtr)pDrawTo);
+               FreeScratchGC (pGCTo);
+           }
+           return;
+       }
+
+       cap[0] = cap[1] = 0;
+       join[0] = join[1] = 0;
+       for (iphase = ((pGC->lineStyle == LineDoubleDash) ? 1 : 0);
+            iphase >= 0;
+            iphase--)
+       {
+           if (iphase == 1) {
+               dixChangeGC (NullClient, pGC, GCForeground, &bg, NULL);
+               ValidateGC (pDraw, pGC);
+           } else if (pGC->lineStyle == LineDoubleDash) {
+               dixChangeGC (NullClient, pGC, GCForeground, &fg, NULL);
+               ValidateGC (pDraw, pGC);
+           }
+           for (i = 0; i < polyArcs[iphase].narcs; i++) {
+               miArcDataPtr    arcData;
+
+               arcData = &polyArcs[iphase].arcs[i];
+               miArcSegment(pDrawTo, pGCTo, arcData->arc,
+                            &arcData->bounds[RIGHT_END],
+                            &arcData->bounds[LEFT_END]);
+               if (polyArcs[iphase].arcs[i].render) {
+                   fillSpans (pDrawTo, pGCTo);
+                   /*
+                    * don't cap self-joining arcs
+                    */
+                   if (polyArcs[iphase].arcs[i].selfJoin &&
+                       cap[iphase] < polyArcs[iphase].arcs[i].cap)
+                       cap[iphase]++;
+                   while (cap[iphase] < polyArcs[iphase].arcs[i].cap) {
+                       int     arcIndex, end;
+                       miArcDataPtr    arcData0;
+
+                       arcIndex = polyArcs[iphase].caps[cap[iphase]].arcIndex;
+                       end = polyArcs[iphase].caps[cap[iphase]].end;
+                       arcData0 = &polyArcs[iphase].arcs[arcIndex];
+                       miArcCap (pDrawTo, pGCTo,
+                                 &arcData0->bounds[end], end,
+                                 arcData0->arc.x, arcData0->arc.y,
+                                 (double) arcData0->arc.width / 2.0,
+                                 (double) arcData0->arc.height / 2.0);
+                       ++cap[iphase];
+                   }
+                   while (join[iphase] < polyArcs[iphase].arcs[i].join) {
+                       int     arcIndex0, arcIndex1, end0, end1;
+                       int     phase0, phase1;
+                       miArcDataPtr    arcData0, arcData1;
+                       miArcJoinPtr    joinp;
+
+                       joinp = &polyArcs[iphase].joins[join[iphase]];
+                       arcIndex0 = joinp->arcIndex0;
+                       end0 = joinp->end0;
+                       arcIndex1 = joinp->arcIndex1;
+                       end1 = joinp->end1;
+                       phase0 = joinp->phase0;
+                       phase1 = joinp->phase1;
+                       arcData0 = &polyArcs[phase0].arcs[arcIndex0];
+                       arcData1 = &polyArcs[phase1].arcs[arcIndex1];
+                       miArcJoin (pDrawTo, pGCTo,
+                                 &arcData0->bounds[end0],
+                                 &arcData1->bounds[end1],
+                                 arcData0->arc.x, arcData0->arc.y,
+                                 (double) arcData0->arc.width / 2.0,
+                                 (double) arcData0->arc.height / 2.0,
+                                 arcData1->arc.x, arcData1->arc.y,
+                                 (double) arcData1->arc.width / 2.0,
+                                 (double) arcData1->arc.height / 2.0);
+                       ++join[iphase];
+                   }
+                   if (fTricky) {
+                       if (pGC->serialNumber != pDraw->serialNumber)
+                           ValidateGC (pDraw, pGC);
+                       (*pGC->ops->PushPixels) (pGC, (PixmapPtr)pDrawTo,
+                                pDraw, pixmapWidth, pixmapHeight, xOrg, yOrg);
+                       miClearDrawable ((DrawablePtr) pDrawTo, pGCTo);
+                   }
+               }
+           }
+       }
+       miFreeArcs(polyArcs, pGC);
+
+       if(fTricky)
+       {
+           (*pGCTo->pScreen->DestroyPixmap)((PixmapPtr)pDrawTo);
+           FreeScratchGC(pGCTo);
+       }
+    }
+}
+
+static double
+angleBetween (center, point1, point2)
+       SppPointRec     center, point1, point2;
+{
+       double  a1, a2, a;
+       
+       /*
+        * reflect from X coordinates back to ellipse
+        * coordinates -- y increasing upwards
+        */
+       a1 = miDatan2 (- (point1.y - center.y), point1.x - center.x);
+       a2 = miDatan2 (- (point2.y - center.y), point2.x - center.x);
+       a = a2 - a1;
+       if (a <= -180.0)
+               a += 360.0;
+       else if (a > 180.0)
+               a -= 360.0;
+       return a;
+}
+
+static void
+translateBounds (b, x, y, fx, fy)
+miArcFacePtr   b;
+int            x, y;
+double         fx, fy;
+{
+       fx += x;
+       fy += y;
+       b->clock.x -= fx;
+       b->clock.y -= fy;
+       b->center.x -= fx;
+       b->center.y -= fy;
+       b->counterClock.x -= fx;
+       b->counterClock.y -= fy;
+}
+
+static void
+miArcJoin (pDraw, pGC, pLeft, pRight,
+          xOrgLeft, yOrgLeft, xFtransLeft, yFtransLeft,
+          xOrgRight, yOrgRight, xFtransRight, yFtransRight)
+       DrawablePtr     pDraw;
+       GCPtr           pGC;
+       miArcFacePtr    pRight, pLeft;
+       int             xOrgRight, yOrgRight;
+       double          xFtransRight, yFtransRight;
+       int             xOrgLeft, yOrgLeft;
+       double          xFtransLeft, yFtransLeft;
+{
+       SppPointRec     center, corner, otherCorner;
+       SppPointRec     poly[5], e;
+       SppPointPtr     pArcPts;
+       int             cpt;
+       SppArcRec       arc;
+       miArcFaceRec    Right, Left;
+       int             polyLen;
+       int             xOrg, yOrg;
+       double          xFtrans, yFtrans;
+       double          a;
+       double          ae, ac2, ec2, bc2, de;
+       double          width;
+       
+       xOrg = (xOrgRight + xOrgLeft) / 2;
+       yOrg = (yOrgRight + yOrgLeft) / 2;
+       xFtrans = (xFtransLeft + xFtransRight) / 2;
+       yFtrans = (yFtransLeft + yFtransRight) / 2;
+       Right = *pRight;
+       translateBounds (&Right, xOrg - xOrgRight, yOrg - yOrgRight,
+                                xFtrans - xFtransRight, yFtrans - yFtransRight);
+       Left = *pLeft;
+       translateBounds (&Left, xOrg - xOrgLeft, yOrg - yOrgLeft,
+                                xFtrans - xFtransLeft, yFtrans - yFtransLeft);
+       pRight = &Right;
+       pLeft = &Left;
+
+       if (pRight->clock.x == pLeft->counterClock.x &&
+           pRight->clock.y == pLeft->counterClock.y)
+               return;
+       center = pRight->center;
+       if (0 <= (a = angleBetween (center, pRight->clock, pLeft->counterClock))
+           && a <= 180.0)
+       {
+               corner = pRight->clock;
+               otherCorner = pLeft->counterClock;
+       } else {
+               a = angleBetween (center, pLeft->clock, pRight->counterClock);
+               corner = pLeft->clock;
+               otherCorner = pRight->counterClock;
+       }
+       switch (pGC->joinStyle) {
+       case JoinRound:
+               width = (pGC->lineWidth ? (double)pGC->lineWidth : (double)1);
+
+               arc.x = center.x - width/2;
+               arc.y = center.y - width/2;
+               arc.width = width;
+               arc.height = width;
+               arc.angle1 = -miDatan2 (corner.y - center.y, corner.x - center.x);
+               arc.angle2 = a;
+               pArcPts = (SppPointPtr) xalloc (3 * sizeof (SppPointRec));
+               if (!pArcPts)
+                   return;
+               pArcPts[0].x = otherCorner.x;
+               pArcPts[0].y = otherCorner.y;
+               pArcPts[1].x = center.x;
+               pArcPts[1].y = center.y;
+               pArcPts[2].x = corner.x;
+               pArcPts[2].y = corner.y;
+               if( (cpt = miGetArcPts(&arc, 3, &pArcPts)) )
+               {
+                       /* by drawing with miFillSppPoly and setting the endpoints of the arc
+                        * to be the corners, we assure that the cap will meet up with the
+                        * rest of the line */
+                       miFillSppPoly(pDraw, pGC, cpt, pArcPts, xOrg, yOrg, xFtrans, yFtrans);
+               }
+               xfree(pArcPts);
+               return;
+       case JoinMiter:
+               /*
+                * don't miter arcs with less than 11 degrees between them
+                */
+               if (a < 169.0) {
+                       poly[0] = corner;
+                       poly[1] = center;
+                       poly[2] = otherCorner;
+                       bc2 = (corner.x - otherCorner.x) * (corner.x - otherCorner.x) +
+                             (corner.y - otherCorner.y) * (corner.y - otherCorner.y);
+                       ec2 = bc2 / 4;
+                       ac2 = (corner.x - center.x) * (corner.x - center.x) +
+                             (corner.y - center.y) * (corner.y - center.y);
+                       ae = sqrt (ac2 - ec2);
+                       de = ec2 / ae;
+                       e.x = (corner.x + otherCorner.x) / 2;
+                       e.y = (corner.y + otherCorner.y) / 2;
+                       poly[3].x = e.x + de * (e.x - center.x) / ae;
+                       poly[3].y = e.y + de * (e.y - center.y) / ae;
+                       poly[4] = corner;
+                       polyLen = 5;
+                       break;
+               }
+       case JoinBevel:
+               poly[0] = corner;
+               poly[1] = center;
+               poly[2] = otherCorner;
+               poly[3] = corner;
+               polyLen = 4;
+               break;
+       }
+       miFillSppPoly (pDraw, pGC, polyLen, poly, xOrg, yOrg, xFtrans, yFtrans);
+}
+
+/*ARGSUSED*/
+static void
+miArcCap (pDraw, pGC, pFace, end, xOrg, yOrg, xFtrans, yFtrans)
+       DrawablePtr     pDraw;
+       GCPtr           pGC;
+       miArcFacePtr    pFace;
+       int             end;
+       int             xOrg, yOrg;
+       double          xFtrans, yFtrans;
+{
+       SppPointRec     corner, otherCorner, center, endPoint, poly[5];
+
+       corner = pFace->clock;
+       otherCorner = pFace->counterClock;
+       center = pFace->center;
+       switch (pGC->capStyle) {
+       case CapProjecting:
+               poly[0].x = otherCorner.x;
+               poly[0].y = otherCorner.y;
+               poly[1].x = corner.x;
+               poly[1].y = corner.y;
+               poly[2].x = corner.x -
+                               (center.y - corner.y);
+               poly[2].y = corner.y +
+                               (center.x - corner.x);
+               poly[3].x = otherCorner.x -
+                               (otherCorner.y - center.y);
+               poly[3].y = otherCorner.y +
+                               (otherCorner.x - center.x);
+               poly[4].x = otherCorner.x;
+               poly[4].y = otherCorner.y;
+               miFillSppPoly (pDraw, pGC, 5, poly, xOrg, yOrg, xFtrans, yFtrans);
+               break;
+       case CapRound:
+               /*
+                * miRoundCap just needs these to be unequal.
+                */
+               endPoint = center;
+               endPoint.x = endPoint.x + 100;
+               miRoundCap (pDraw, pGC, center, endPoint, corner, otherCorner, 0,
+                           -xOrg, -yOrg, xFtrans, yFtrans);
+               break;
+       }
+}
+
+/* MIROUNDCAP -- a private helper function
+ * Put Rounded cap on end. pCenter is the center of this end of the line
+ * pEnd is the center of the other end of the line. pCorner is one of the
+ * two corners at this end of the line.  
+ * NOTE:  pOtherCorner must be counter-clockwise from pCorner.
+ */
+/*ARGSUSED*/
+static void
+miRoundCap(pDraw, pGC, pCenter, pEnd, pCorner, pOtherCorner, fLineEnd,
+     xOrg, yOrg, xFtrans, yFtrans)
+    DrawablePtr        pDraw;
+    GCPtr      pGC;
+    SppPointRec        pCenter, pEnd;
+    SppPointRec        pCorner, pOtherCorner;
+    int                fLineEnd, xOrg, yOrg;
+    double     xFtrans, yFtrans;
+{
+    int                cpt;
+    double     width;
+    double     miDatan2 ();
+    SppArcRec  arc;
+    SppPointPtr        pArcPts;
+
+    width = (pGC->lineWidth ? (double)pGC->lineWidth : (double)1);
+
+    arc.x = pCenter.x - width/2;
+    arc.y = pCenter.y - width/2;
+    arc.width = width;
+    arc.height = width;
+    arc.angle1 = -miDatan2 (pCorner.y - pCenter.y, pCorner.x - pCenter.x);
+    if(PTISEQUAL(pCenter, pEnd))
+       arc.angle2 = - 180.0;
+    else {
+       arc.angle2 = -miDatan2 (pOtherCorner.y - pCenter.y, pOtherCorner.x - pCenter.x) - arc.angle1;
+       if (arc.angle2 < 0)
+           arc.angle2 += 360.0;
+    }
+    pArcPts = (SppPointPtr) NULL;
+    if( (cpt = miGetArcPts(&arc, 0, &pArcPts)) )
+    {
+       /* by drawing with miFillSppPoly and setting the endpoints of the arc
+        * to be the corners, we assure that the cap will meet up with the
+        * rest of the line */
+       miFillSppPoly(pDraw, pGC, cpt, pArcPts, -xOrg, -yOrg, xFtrans, yFtrans);
+    }
+    xfree(pArcPts);
+}
+
+/*
+ * To avoid inaccuracy at the cardinal points, use trig functions
+ * which are exact for those angles
+ */
+
+#ifndef M_PI
+#define M_PI   3.14159265358979323846
+#endif
+#ifndef M_PI_2
+#define M_PI_2 1.57079632679489661923
+#endif
+
+# define Dsin(d)       ((d) == 0.0 ? 0.0 : ((d) == 90.0 ? 1.0 : sin(d*M_PI/180.0)))
+# define Dcos(d)       ((d) == 0.0 ? 1.0 : ((d) == 90.0 ? 0.0 : cos(d*M_PI/180.0)))
+# define mod(a,b)      ((a) >= 0 ? (a) % (b) : (b) - (-a) % (b))
+
+static double
+miDcos (a)
+double a;
+{
+       int     i;
+
+       if (floor (a/90) == a/90) {
+               i = (int) (a/90.0);
+               switch (mod (i, 4)) {
+               case 0: return 1;
+               case 1: return 0;
+               case 2: return -1;
+               case 3: return 0;
+               }
+       }
+       return cos (a * M_PI / 180.0);
+}
+
+static double
+miDsin (a)
+double a;
+{
+       int     i;
+
+       if (floor (a/90) == a/90) {
+               i = (int) (a/90.0);
+               switch (mod (i, 4)) {
+               case 0: return 0;
+               case 1: return 1;
+               case 2: return 0;
+               case 3: return -1;
+               }
+       }
+       return sin (a * M_PI / 180.0);
+}
+
+static double
+miDasin (v)
+double v;
+{
+    if (v == 0)
+       return 0.0;
+    if (v == 1.0)
+       return 90.0;
+    if (v == -1.0)
+       return -90.0;
+    return asin(v) * (180.0 / M_PI);
+}
+
+static double
+miDatan2 (dy, dx)
+double dy, dx;
+{
+    if (dy == 0) {
+       if (dx >= 0)
+           return 0.0;
+       return 180.0;
+    } else if (dx == 0) {
+       if (dy > 0)
+           return 90.0;
+       return -90.0;
+    } else if (Fabs (dy) == Fabs (dx)) {
+       if (dy > 0) {
+           if (dx > 0)
+               return 45.0;
+           return 135.0;
+       } else {
+           if (dx > 0)
+               return 315.0;
+           return 225.0;
+       }
+    } else {
+       return atan2 (dy, dx) * (180.0 / M_PI);
+    }
+}
+
+/* MIGETARCPTS -- Converts an arc into a set of line segments -- a helper
+ * routine for filled arc and line (round cap) code.
+ * Returns the number of points in the arc.  Note that it takes a pointer
+ * to a pointer to where it should put the points and an index (cpt).
+ * This procedure allocates the space necessary to fit the arc points.
+ * Sometimes it's convenient for those points to be at the end of an existing
+ * array. (For example, if we want to leave a spare point to make sectors
+ * instead of segments.)  So we pass in the xalloc()ed chunk that contains the
+ * array and an index saying where we should start stashing the points.
+ * If there isn't an array already, we just pass in a null pointer and 
+ * count on xrealloc() to handle the null pointer correctly.
+ */
+static int
+miGetArcPts(parc, cpt, ppPts)
+    SppArcPtr  parc;   /* points to an arc */
+    int                cpt;    /* number of points already in arc list */
+    SppPointPtr        *ppPts; /* pointer to pointer to arc-list -- modified */
+{
+    double     st,     /* Start Theta, start angle */
+                et,    /* End Theta, offset from start theta */
+               dt,     /* Delta Theta, angle to sweep ellipse */
+               cdt,    /* Cos Delta Theta, actually 2 cos(dt) */
+               x0, y0, /* the recurrence formula needs two points to start */
+               x1, y1,
+               x2, y2, /* this will be the new point generated */
+               xc, yc; /* the center point */
+    int                count, i;
+    SppPointPtr        poly;
+    DDXPointRec last;          /* last point on integer boundaries */
+
+    /* The spec says that positive angles indicate counterclockwise motion.
+     * Given our coordinate system (with 0,0 in the upper left corner), 
+     * the screen appears flipped in Y.  The easiest fix is to negate the
+     * angles given */
+    
+    st = - parc->angle1;
+
+    et = - parc->angle2;
+
+    /* Try to get a delta theta that is within 1/2 pixel.  Then adjust it
+     * so that it divides evenly into the total.
+     * I'm just using cdt 'cause I'm lazy.
+     */
+    cdt = parc->width;
+    if (parc->height > cdt)
+       cdt = parc->height;
+    cdt /= 2.0;
+    if(cdt <= 0)
+       return 0;
+    if (cdt < 1.0)
+       cdt = 1.0;
+    dt = miDasin ( 1.0 / cdt ); /* minimum step necessary */
+    count = et/dt;
+    count = abs(count) + 1;
+    dt = et/count;     
+    count++;
+
+    cdt = 2 * miDcos(dt);
+    if (!(poly = (SppPointPtr) xrealloc((pointer)*ppPts,
+                                       (cpt + count) * sizeof(SppPointRec))))
+       return(0);
+    *ppPts = poly;
+
+    xc = parc->width/2.0;              /* store half width and half height */
+    yc = parc->height/2.0;
+    
+    x0 = xc * miDcos(st);
+    y0 = yc * miDsin(st);
+    x1 = xc * miDcos(st + dt);
+    y1 = yc * miDsin(st + dt);
+    xc += parc->x;             /* by adding initial point, these become */
+    yc += parc->y;             /* the center point */
+
+    poly[cpt].x = (xc + x0);
+    poly[cpt].y = (yc + y0);
+    last.x = ROUNDTOINT( poly[cpt + 1].x = (xc + x1) );
+    last.y = ROUNDTOINT( poly[cpt + 1].y = (yc + y1) );
+
+    for(i = 2; i < count; i++)
+    {
+       x2 = cdt * x1 - x0;
+       y2 = cdt * y1 - y0;
+
+       poly[cpt + i].x = (xc + x2);
+       poly[cpt + i].y = (yc + y2);
+
+       x0 = x1; y0 = y1;
+       x1 = x2; y1 = y2;
+    }
+    /* adjust the last point */
+    if (abs(parc->angle2) >= 360.0)
+       poly[cpt +i -1] = poly[0];
+    else {
+       poly[cpt +i -1].x = (miDcos(st + et) * parc->width/2.0 + xc);
+       poly[cpt +i -1].y = (miDsin(st + et) * parc->height/2.0 + yc);
+    }
+
+    return(count);
+}
+
+struct arcData {
+       double  x0, y0, x1, y1;
+       int     selfJoin;
+};
+
+# define ADD_REALLOC_STEP      20
+
+static void
+addCap (capsp, ncapsp, sizep, end, arcIndex)
+       miArcCapPtr     *capsp;
+       int             *ncapsp, *sizep;
+       int             end, arcIndex;
+{
+       int newsize;
+       miArcCapPtr     cap;
+
+       if (*ncapsp == *sizep)
+       {
+           newsize = *sizep + ADD_REALLOC_STEP;
+           cap = (miArcCapPtr) xrealloc (*capsp,
+                                         newsize * sizeof (**capsp));
+           if (!cap)
+               return;
+           *sizep = newsize;
+           *capsp = cap;
+       }
+       cap = &(*capsp)[*ncapsp];
+       cap->end = end;
+       cap->arcIndex = arcIndex;
+       ++*ncapsp;
+}
+
+static void
+addJoin (joinsp, njoinsp, sizep, end0, index0, phase0, end1, index1, phase1)
+       miArcJoinPtr    *joinsp;
+       int             *njoinsp, *sizep;
+       int             end0, index0, phase0, end1, index1, phase1;
+{
+       int newsize;
+       miArcJoinPtr    join;
+
+       if (*njoinsp == *sizep)
+       {
+           newsize = *sizep + ADD_REALLOC_STEP;
+           join = (miArcJoinPtr) xrealloc (*joinsp,
+                                           newsize * sizeof (**joinsp));
+           if (!join)
+               return;
+           *sizep = newsize;
+           *joinsp = join;
+       }
+       join = &(*joinsp)[*njoinsp];
+       join->end0 = end0;
+       join->arcIndex0 = index0;
+       join->phase0 = phase0;
+       join->end1 = end1;
+       join->arcIndex1 = index1;
+       join->phase1 = phase1;
+       ++*njoinsp;
+}
+
+static miArcDataPtr
+addArc (arcsp, narcsp, sizep, xarc)
+       miArcDataPtr    *arcsp;
+       int             *narcsp, *sizep;
+       xArc            *xarc;
+{
+       int newsize;
+       miArcDataPtr    arc;
+
+       if (*narcsp == *sizep)
+       {
+           newsize = *sizep + ADD_REALLOC_STEP;
+           arc = (miArcDataPtr) xrealloc (*arcsp,
+                                          newsize * sizeof (**arcsp));
+           if (!arc)
+               return (miArcDataPtr)NULL;
+           *sizep = newsize;
+           *arcsp = arc;
+       }
+       arc = &(*arcsp)[*narcsp];
+       arc->arc = *xarc;
+       ++*narcsp;
+       return arc;
+}
+
+static void
+miFreeArcs(arcs, pGC)
+    miPolyArcPtr arcs;
+    GCPtr pGC;
+{
+       int iphase;
+
+       for (iphase = ((pGC->lineStyle == LineDoubleDash) ? 1 : 0);
+            iphase >= 0;
+            iphase--)
+       {
+           if (arcs[iphase].narcs > 0)
+               xfree(arcs[iphase].arcs);
+           if (arcs[iphase].njoins > 0)
+               xfree(arcs[iphase].joins);
+           if (arcs[iphase].ncaps > 0)
+               xfree(arcs[iphase].caps);
+       }
+       xfree(arcs);
+}
+
+/*
+ * map angles to radial distance.  This only deals with the first quadrant
+ */
+
+/*
+ * a polygonal approximation to the arc for computing arc lengths
+ */
+
+# define DASH_MAP_SIZE 91
+
+# define dashIndexToAngle(di)  ((((double) (di)) * 90.0) / ((double) DASH_MAP_SIZE - 1))
+# define xAngleToDashIndex(xa) ((((long) (xa)) * (DASH_MAP_SIZE - 1)) / (90 * 64))
+# define dashIndexToXAngle(di) ((((long) (di)) * (90 * 64)) / (DASH_MAP_SIZE - 1))
+# define dashXAngleStep        (((double) (90 * 64)) / ((double) (DASH_MAP_SIZE - 1)))
+
+typedef struct {
+       double  map[DASH_MAP_SIZE];
+} dashMap;
+
+static void
+computeDashMap (arcp, map)
+       xArc    *arcp;
+       dashMap *map;
+{
+       int     di;
+       double  a, x, y, prevx, prevy, dist;
+
+       for (di = 0; di < DASH_MAP_SIZE; di++) {
+               a = dashIndexToAngle (di);
+               x = ((double) arcp->width / 2.0) * miDcos (a);
+               y = ((double) arcp->height / 2.0) * miDsin (a);
+               if (di == 0) {
+                       map->map[di] = 0.0;
+               } else {
+                       dist = hypot (x - prevx, y - prevy);
+                       map->map[di] = map->map[di - 1] + dist;
+               }
+               prevx = x;
+               prevy = y;
+       }
+}
+
+typedef enum {HORIZONTAL, VERTICAL, OTHER} arcTypes;
+
+/* this routine is a bit gory */
+
+static miPolyArcPtr
+miComputeArcs (parcs, narcs, pGC)
+       xArc    *parcs;
+       int     narcs;
+       GCPtr   pGC;
+{
+       int             isDashed, isDoubleDash;
+       int             dashOffset;
+       miPolyArcPtr    arcs;
+       int             start, i, j, k, nexti, nextk;
+       int             joinSize[2];
+       int             capSize[2];
+       int             arcSize[2];
+       int             angle2;
+       double          a0, a1;
+       struct arcData  *data;
+       miArcDataPtr    arc;
+       xArc            xarc;
+       int             iphase, prevphase, joinphase;
+       int             arcsJoin;
+       int             selfJoin;
+
+       int             iDash, dashRemaining;
+       int             iDashStart, dashRemainingStart, iphaseStart;
+       int             startAngle, spanAngle, endAngle, backwards;
+       int             prevDashAngle, dashAngle;
+       dashMap         map;
+
+       isDashed = !(pGC->lineStyle == LineSolid);
+       isDoubleDash = (pGC->lineStyle == LineDoubleDash);
+       dashOffset = pGC->dashOffset;
+
+       data = (struct arcData *) ALLOCATE_LOCAL (narcs * sizeof (struct arcData));
+       if (!data)
+           return (miPolyArcPtr)NULL;
+       arcs = (miPolyArcPtr) xalloc (sizeof (*arcs) * (isDoubleDash ? 2 : 1));
+       if (!arcs)
+       {
+           DEALLOCATE_LOCAL(data);
+           return (miPolyArcPtr)NULL;
+       }
+       for (i = 0; i < narcs; i++) {
+               a0 = todeg (parcs[i].angle1);
+               angle2 = parcs[i].angle2;
+               if (angle2 > FULLCIRCLE)
+                       angle2 = FULLCIRCLE;
+               else if (angle2 < -FULLCIRCLE)
+                       angle2 = -FULLCIRCLE;
+               data[i].selfJoin = angle2 == FULLCIRCLE || angle2 == -FULLCIRCLE;
+               a1 = todeg (parcs[i].angle1 + angle2);
+               data[i].x0 = parcs[i].x + (double) parcs[i].width / 2 * (1 + miDcos (a0));
+               data[i].y0 = parcs[i].y + (double) parcs[i].height / 2 * (1 - miDsin (a0));
+               data[i].x1 = parcs[i].x + (double) parcs[i].width / 2 * (1 + miDcos (a1));
+               data[i].y1 = parcs[i].y + (double) parcs[i].height / 2 * (1 - miDsin (a1));
+       }
+
+       for (iphase = 0; iphase < (isDoubleDash ? 2 : 1); iphase++) {
+               arcs[iphase].njoins = 0;
+               arcs[iphase].joins = 0;
+               joinSize[iphase] = 0;
+               
+               arcs[iphase].ncaps = 0;
+               arcs[iphase].caps = 0;
+               capSize[iphase] = 0;
+               
+               arcs[iphase].narcs = 0;
+               arcs[iphase].arcs = 0;
+               arcSize[iphase] = 0;
+       }
+
+       iphase = 0;
+       if (isDashed) {
+               iDash = 0;
+               dashRemaining = pGC->dash[0];
+               while (dashOffset > 0) {
+                       if (dashOffset >= dashRemaining) {
+                               dashOffset -= dashRemaining;
+                               iphase = iphase ? 0 : 1;
+                               iDash++;
+                               if (iDash == pGC->numInDashList)
+                                   iDash = 0;
+                               dashRemaining = pGC->dash[iDash];
+                       } else {
+                               dashRemaining -= dashOffset;
+                               dashOffset = 0;
+                       }
+               }
+               iDashStart = iDash;
+               dashRemainingStart = dashRemaining;
+       }
+       iphaseStart = iphase;
+
+       for (i = narcs - 1; i >= 0; i--) {
+               j = i + 1;
+               if (j == narcs)
+                       j = 0;
+               if (data[i].selfJoin || i == j ||
+                    (UNEQUAL (data[i].x1, data[j].x0) ||
+                     UNEQUAL (data[i].y1, data[j].y0)))
+               {
+                       if (iphase == 0 || isDoubleDash)
+                               addCap (&arcs[iphase].caps, &arcs[iphase].ncaps,
+                                       &capSize[iphase], RIGHT_END, 0);
+                       break;
+               }
+       }
+       start = i + 1;
+       if (start == narcs)
+               start = 0;
+       i = start;
+       for (;;) {
+               j = i + 1;
+               if (j == narcs)
+                       j = 0;
+               nexti = i+1;
+               if (nexti == narcs)
+                       nexti = 0;
+               if (isDashed) {
+                       /*
+                       ** deal with dashed arcs.  Use special rules for certain 0 area arcs.
+                       ** Presumably, the other 0 area arcs still aren't done right.
+                       */
+                       arcTypes        arcType = OTHER;
+                       CARD16          thisLength;
+
+                       if (parcs[i].height == 0
+                           && (parcs[i].angle1 % FULLCIRCLE) == 0x2d00
+                           && parcs[i].angle2 == 0x2d00) 
+                               arcType = HORIZONTAL;
+                       else if (parcs[i].width == 0
+                           && (parcs[i].angle1 % FULLCIRCLE) == 0x1680
+                           && parcs[i].angle2 == 0x2d00)
+                               arcType = VERTICAL;
+                       if (arcType == OTHER) {
+                               /*
+                                * precompute an approximation map
+                                */
+                               computeDashMap (&parcs[i], &map);
+                               /*
+                                * compute each individual dash segment using the path
+                                * length function
+                                */
+                               startAngle = parcs[i].angle1;
+                               spanAngle = parcs[i].angle2;
+                               if (spanAngle > FULLCIRCLE)
+                                       spanAngle = FULLCIRCLE;
+                               else if (spanAngle < -FULLCIRCLE)
+                                       spanAngle = -FULLCIRCLE;
+                               if (startAngle < 0)
+                                       startAngle = FULLCIRCLE - (-startAngle) % FULLCIRCLE;
+                               if (startAngle >= FULLCIRCLE)
+                                       startAngle = startAngle % FULLCIRCLE;
+                               endAngle = startAngle + spanAngle;
+                               backwards = spanAngle < 0;
+                       } else {
+                               xarc = parcs[i];
+                               if (arcType == VERTICAL) {
+                                       xarc.angle1 = 0x1680;
+                                       startAngle = parcs[i].y;
+                                       endAngle = startAngle + parcs[i].height;
+                               } else {
+                                       xarc.angle1 = 0x2d00;
+                                       startAngle = parcs[i].x;
+                                       endAngle = startAngle + parcs[i].width;
+                               }
+                       }
+                       dashAngle = startAngle;
+                       selfJoin = data[i].selfJoin &&
+                                   (iphase == 0 || isDoubleDash);
+                       /*
+                        * add dashed arcs to each bucket
+                        */
+                       arc = 0;
+                       while (dashAngle != endAngle) {
+                               prevDashAngle = dashAngle;
+                               if (arcType == OTHER) {
+                                       dashAngle = computeAngleFromPath (prevDashAngle, endAngle,
+                                                               &map, &dashRemaining, backwards);
+                                       /* avoid troubles with huge arcs and small dashes */
+                                       if (dashAngle == prevDashAngle) {
+                                               if (backwards)
+                                                       dashAngle--;
+                                               else
+                                                       dashAngle++;
+                                       }
+                               } else {
+                                       thisLength = (dashAngle + dashRemaining <= endAngle) ? 
+                                           dashRemaining : endAngle - dashAngle;
+                                       if (arcType == VERTICAL) {
+                                               xarc.y = dashAngle;
+                                               xarc.height = thisLength;
+                                       } else {
+                                               xarc.x = dashAngle;
+                                               xarc.width = thisLength;
+                                       }
+                                       dashAngle += thisLength;
+                                       dashRemaining -= thisLength;
+                               }
+                               if (iphase == 0 || isDoubleDash) {
+                                       if (arcType == OTHER) {
+                                               xarc = parcs[i];
+                                               spanAngle = prevDashAngle;
+                                               if (spanAngle < 0)
+                                                   spanAngle = FULLCIRCLE - (-spanAngle) % FULLCIRCLE;
+                                               if (spanAngle >= FULLCIRCLE)
+                                                   spanAngle = spanAngle % FULLCIRCLE;
+                                               xarc.angle1 = spanAngle;
+                                               spanAngle = dashAngle - prevDashAngle;
+                                               if (backwards) {
+                                                       if (dashAngle > prevDashAngle)
+                                                               spanAngle = - FULLCIRCLE + spanAngle;
+                                               } else {
+                                                       if (dashAngle < prevDashAngle)
+                                                               spanAngle = FULLCIRCLE + spanAngle;
+                                               }
+                                               if (spanAngle > FULLCIRCLE)
+                                                   spanAngle = FULLCIRCLE;
+                                               if (spanAngle < -FULLCIRCLE)
+                                                   spanAngle = -FULLCIRCLE;
+                                               xarc.angle2 = spanAngle;
+                                       }
+                                       arc = addArc (&arcs[iphase].arcs, &arcs[iphase].narcs,
+                                                       &arcSize[iphase], &xarc);
+                                       if (!arc)
+                                           goto arcfail;
+                                       /*
+                                        * cap each end of an on/off dash
+                                        */
+                                       if (!isDoubleDash) {
+                                               if (prevDashAngle != startAngle) {
+                                                       addCap (&arcs[iphase].caps,
+                                                               &arcs[iphase].ncaps,
+                                                               &capSize[iphase], RIGHT_END,
+                                                               arc - arcs[iphase].arcs);
+                                                       
+                                               }
+                                               if (dashAngle != endAngle) {
+                                                       addCap (&arcs[iphase].caps,
+                                                               &arcs[iphase].ncaps,
+                                                               &capSize[iphase], LEFT_END,
+                                                               arc - arcs[iphase].arcs);
+                                               }
+                                       }
+                                       arc->cap = arcs[iphase].ncaps;
+                                       arc->join = arcs[iphase].njoins;
+                                       arc->render = 0;
+                                       arc->selfJoin = 0;
+                                       if (dashAngle == endAngle)
+                                               arc->selfJoin = selfJoin;
+                               }
+                               prevphase = iphase;
+                               if (dashRemaining <= 0) {
+                                       ++iDash;
+                                       if (iDash == pGC->numInDashList)
+                                               iDash = 0;
+                                       iphase = iphase ? 0:1;
+                                       dashRemaining = pGC->dash[iDash];
+                               }
+                       }
+                       /*
+                        * make sure a place exists for the position data when
+                        * drawing a zero-length arc
+                        */
+                       if (startAngle == endAngle) {
+                               prevphase = iphase;
+                               if (!isDoubleDash && iphase == 1)
+                                       prevphase = 0;
+                               arc = addArc (&arcs[prevphase].arcs, &arcs[prevphase].narcs,
+                                             &arcSize[prevphase], &parcs[i]);
+                               if (!arc)
+                                   goto arcfail;
+                               arc->join = arcs[prevphase].njoins;
+                               arc->cap = arcs[prevphase].ncaps;
+                               arc->selfJoin = data[i].selfJoin;
+                       }
+               } else {
+                       arc = addArc (&arcs[iphase].arcs, &arcs[iphase].narcs,
+                                     &arcSize[iphase], &parcs[i]);
+                       if (!arc)
+                           goto arcfail;
+                       arc->join = arcs[iphase].njoins;
+                       arc->cap = arcs[iphase].ncaps;
+                       arc->selfJoin = data[i].selfJoin;
+                       prevphase = iphase;
+               }
+               if (prevphase == 0 || isDoubleDash)
+                       k = arcs[prevphase].narcs - 1;
+               if (iphase == 0 || isDoubleDash)
+                       nextk = arcs[iphase].narcs;
+               if (nexti == start) {
+                       nextk = 0;
+                       if (isDashed) {
+                               iDash = iDashStart;
+                               iphase = iphaseStart;
+                               dashRemaining = dashRemainingStart;
+                       }
+               }
+               arcsJoin = narcs > 1 && i != j &&
+                           ISEQUAL (data[i].x1, data[j].x0) &&
+                           ISEQUAL (data[i].y1, data[j].y0) &&
+                           !data[i].selfJoin && !data[j].selfJoin;
+               if (arc)
+               {
+                       if (arcsJoin)
+                               arc->render = 0;
+                       else
+                               arc->render = 1;
+               }
+               if (arcsJoin &&
+                   (prevphase == 0 || isDoubleDash) &&
+                   (iphase == 0 || isDoubleDash))
+               {
+                       joinphase = iphase;
+                       if (isDoubleDash) {
+                               if (nexti == start)
+                                       joinphase = iphaseStart;
+                               /*
+                                * if the join is right at the dash,
+                                * draw the join in foreground
+                                * This is because the foreground
+                                * arcs are computed second, the results
+                                * of which are needed to draw the join
+                                */
+                               if (joinphase != prevphase)
+                                       joinphase = 0;
+                       }
+                       if (joinphase == 0 || isDoubleDash) {
+                               addJoin (&arcs[joinphase].joins,
+                                        &arcs[joinphase].njoins,
+                                        &joinSize[joinphase],
+                                        LEFT_END, k, prevphase,
+                                        RIGHT_END, nextk, iphase);
+                               arc->join = arcs[prevphase].njoins;
+                       }
+               } else {
+                       /*
+                        * cap the left end of this arc
+                        * unless it joins itself
+                        */
+                       if ((prevphase == 0 || isDoubleDash) &&
+                           !arc->selfJoin)
+                       {
+                               addCap (&arcs[prevphase].caps, &arcs[prevphase].ncaps,
+                                       &capSize[prevphase], LEFT_END, k);
+                               arc->cap = arcs[prevphase].ncaps;
+                       }
+                       if (isDashed && !arcsJoin) {
+                               iDash = iDashStart;
+                               iphase = iphaseStart;
+                               dashRemaining = dashRemainingStart;
+                       }
+                       nextk = arcs[iphase].narcs;
+                       if (nexti == start) {
+                               nextk = 0;
+                               iDash = iDashStart;
+                               iphase = iphaseStart;
+                               dashRemaining = dashRemainingStart;
+                       }
+                       /*
+                        * cap the right end of the next arc.  If the
+                        * next arc is actually the first arc, only
+                        * cap it if it joins with this arc.  This
+                        * case will occur when the final dash segment
+                        * of an on/off dash is off.  Of course, this
+                        * cap will be drawn at a strange time, but that
+                        * hardly matters...
+                        */
+                       if ((iphase == 0 || isDoubleDash) &&
+                           (nexti != start || (arcsJoin && isDashed)))
+                               addCap (&arcs[iphase].caps, &arcs[iphase].ncaps,
+                                       &capSize[iphase], RIGHT_END, nextk);
+               }
+               i = nexti;
+               if (i == start)
+                       break;
+       }
+       /*
+        * make sure the last section is rendered
+        */
+       for (iphase = 0; iphase < (isDoubleDash ? 2 : 1); iphase++)
+               if (arcs[iphase].narcs > 0) {
+                       arcs[iphase].arcs[arcs[iphase].narcs-1].render = 1;
+                       arcs[iphase].arcs[arcs[iphase].narcs-1].join =
+                                arcs[iphase].njoins;
+                       arcs[iphase].arcs[arcs[iphase].narcs-1].cap =
+                                arcs[iphase].ncaps;
+               }
+       DEALLOCATE_LOCAL(data);
+       return arcs;
+arcfail:
+       miFreeArcs(arcs, pGC);
+       DEALLOCATE_LOCAL(data);
+       return (miPolyArcPtr)NULL;
+}
+
+static double
+angleToLength (angle, map)
+       int     angle;
+       dashMap *map;
+{
+       double  len, excesslen, sidelen = map->map[DASH_MAP_SIZE - 1], totallen;
+       int     di;
+       int     excess;
+       Bool    oddSide = FALSE;
+
+       totallen = 0;
+       if (angle >= 0) {
+               while (angle >= 90 * 64) {
+                       angle -= 90 * 64;
+                       totallen += sidelen;
+                       oddSide = !oddSide;
+               }
+       } else {
+               while (angle < 0) {
+                       angle += 90 * 64;
+                       totallen -= sidelen;
+                       oddSide = !oddSide;
+               }
+       }
+       if (oddSide)
+               angle = 90 * 64 - angle;
+               
+       di = xAngleToDashIndex (angle);
+       excess = angle - dashIndexToXAngle (di);
+
+       len = map->map[di];
+       /*
+        * linearly interpolate between this point and the next
+        */
+       if (excess > 0) {
+               excesslen = (map->map[di + 1] - map->map[di]) *
+                               ((double) excess) / dashXAngleStep;
+               len += excesslen;
+       }
+       if (oddSide)
+               totallen += (sidelen - len);
+       else
+               totallen += len;
+       return totallen;
+}
+
+/*
+ * len is along the arc, but may be more than one rotation
+ */
+
+static int
+lengthToAngle (len, map)
+       double  len;
+       dashMap *map;
+{
+       double  sidelen = map->map[DASH_MAP_SIZE - 1];
+       int     angle, angleexcess;
+       Bool    oddSide = FALSE;
+       int     a0, a1, a;
+
+       angle = 0;
+       /*
+        * step around the ellipse, subtracting sidelens and
+        * adding 90 degrees.  oddSide will tell if the
+        * map should be interpolated in reverse
+        */
+       if (len >= 0) {
+               if (sidelen == 0)
+                       return 2 * FULLCIRCLE;  /* infinity */
+               while (len >= sidelen) {
+                       angle += 90 * 64;
+                       len -= sidelen;
+                       oddSide = !oddSide;
+               }
+       } else {
+               if (sidelen == 0)
+                       return -2 * FULLCIRCLE; /* infinity */
+               while (len < 0) {
+                       angle -= 90 * 64;
+                       len += sidelen;
+                       oddSide = !oddSide;
+               }
+       }
+       if (oddSide)
+               len = sidelen - len;
+       a0 = 0;
+       a1 = DASH_MAP_SIZE - 1;
+       /*
+        * binary search for the closest pre-computed length
+        */
+       while (a1 - a0 > 1) {
+               a = (a0 + a1) / 2;
+               if (len > map->map[a])
+                       a0 = a;
+               else
+                       a1 = a;
+       }
+       angleexcess = dashIndexToXAngle (a0);
+       /*
+        * linearly interpolate to the next point
+        */
+       angleexcess += (len - map->map[a0]) /
+                       (map->map[a0+1] - map->map[a0]) * dashXAngleStep;
+       if (oddSide)
+               angle += (90 * 64) - angleexcess;
+       else
+               angle += angleexcess;
+       return angle;
+}
+
+/*
+ * compute the angle of an ellipse which cooresponds to
+ * the given path length.  Note that the correct solution
+ * to this problem is an eliptic integral, we'll punt and
+ * approximate (it's only for dashes anyway).  This
+ * approximation uses a polygon.
+ *
+ * The remaining portion of len is stored in *lenp -
+ * this will be negative if the arc extends beyond
+ * len and positive if len extends beyond the arc.
+ */
+
+static int
+computeAngleFromPath (startAngle, endAngle, map, lenp, backwards)
+       int     startAngle, endAngle;   /* normalized absolute angles in *64 degrees */
+       dashMap *map;
+       int     *lenp;
+       int     backwards;
+{
+       int     a0, a1, a;
+       double  len0;
+       int     len;
+
+       a0 = startAngle;
+       a1 = endAngle;
+       len = *lenp;
+       if (backwards) {
+               /*
+                * flip the problem around to always be
+                * forwards
+                */
+               a0 = FULLCIRCLE - a0;
+               a1 = FULLCIRCLE - a1;
+       }
+       if (a1 < a0)
+               a1 += FULLCIRCLE;
+       len0 = angleToLength (a0, map);
+       a = lengthToAngle (len0 + len, map);
+       if (a > a1) {
+               a = a1;
+               len -= angleToLength (a1, map) - len0;
+       } else
+               len = 0;
+       if (backwards)
+               a = FULLCIRCLE - a;
+       *lenp = len;
+       return a;
+}
+
+/*
+ * scan convert wide arcs.
+ */
+
+/*
+ * draw zero width/height arcs
+ */
+
+static void
+drawZeroArc (pDraw, pGC, tarc, lw, left, right)
+    DrawablePtr   pDraw;
+    GCPtr         pGC;
+    xArc          *tarc;
+    int                  lw;
+    miArcFacePtr       right, left;
+{
+       double  x0, y0, x1, y1, w, h, x, y;
+       double  xmax, ymax, xmin, ymin;
+       int     a0, a1;
+       double  a, startAngle, endAngle;
+       double  l, lx, ly;
+
+       l = lw / 2.0;
+       a0 = tarc->angle1;
+       a1 = tarc->angle2;
+       if (a1 > FULLCIRCLE)
+               a1 = FULLCIRCLE;
+       else if (a1 < -FULLCIRCLE)
+               a1 = -FULLCIRCLE;
+       w = (double)tarc->width / 2.0;
+       h = (double)tarc->height / 2.0;
+       /*
+        * play in X coordinates right away
+        */
+       startAngle = - ((double) a0 / 64.0);
+       endAngle = - ((double) (a0 + a1) / 64.0);
+       
+       xmax = -w;
+       xmin = w;
+       ymax = -h;
+       ymin = h;
+       a = startAngle;
+       for (;;)
+       {
+               x = w * miDcos(a);
+               y = h * miDsin(a);
+               if (a == startAngle)
+               {
+                       x0 = x;
+                       y0 = y;
+               }
+               if (a == endAngle)
+               {
+                       x1 = x;
+                       y1 = y;
+               }
+               if (x > xmax)
+                       xmax = x;
+               if (x < xmin)
+                       xmin = x;
+               if (y > ymax)
+                       ymax = y;
+               if (y < ymin)
+                       ymin = y;
+               if (a == endAngle)
+                       break;
+               if (a1 < 0)     /* clockwise */
+               {
+                       if (floor (a / 90.0) == floor (endAngle / 90.0))
+                               a = endAngle;
+                       else
+                               a = 90 * (floor (a/90.0) + 1);
+               }
+               else
+               {
+                       if (ceil (a / 90.0) == ceil (endAngle / 90.0))
+                               a = endAngle;
+                       else
+                               a = 90 * (ceil (a/90.0) - 1);
+               }
+       }
+       lx = ly = l;
+       if ((x1 - x0) + (y1 - y0) < 0)
+           lx = ly = -l;
+       if (h)
+       {
+           ly = 0.0;
+           lx = -lx;
+       }
+       else
+           lx = 0.0;
+       if (right)
+       {
+           right->center.x = x0;
+           right->center.y = y0;
+           right->clock.x = x0 - lx;
+           right->clock.y = y0 - ly;
+           right->counterClock.x = x0 + lx;
+           right->counterClock.y = y0 + ly;
+       }
+       if (left)
+       {
+           left->center.x = x1;
+           left->center.y = y1;
+           left->clock.x = x1 + lx;
+           left->clock.y = y1 + ly;
+           left->counterClock.x = x1 - lx;
+           left->counterClock.y = y1 - ly;
+       }
+       
+       x0 = xmin;
+       x1 = xmax;
+       y0 = ymin;
+       y1 = ymax;
+       if (ymin != y1) {
+               xmin = -l;
+               xmax = l;
+       } else {
+               ymin = -l;
+               ymax = l;
+       }
+       if (xmax != xmin && ymax != ymin) {
+               int     minx, maxx, miny, maxy;
+               xRectangle  rect;
+
+               minx = ICEIL (xmin + w) + tarc->x;
+               maxx = ICEIL (xmax + w) + tarc->x;
+               miny = ICEIL (ymin + h) + tarc->y;
+               maxy = ICEIL (ymax + h) + tarc->y;
+               rect.x = minx;
+               rect.y = miny;
+               rect.width = maxx - minx;
+               rect.height = maxy - miny;
+               (*pGC->ops->PolyFillRect) (pDraw, pGC, 1, &rect);
+       }
+}
+
+/*
+ * this computes the ellipse y value associated with the
+ * bottom of the tail.
+ */
+
+static void
+tailEllipseY (def, acc)
+       struct arc_def          *def;
+       struct accelerators     *acc;
+{
+       double          t;
+
+       acc->tail_y = 0.0;
+       if (def->w == def->h)
+           return;
+       t = def->l * def->w;
+       if (def->w > def->h) {
+           if (t < acc->h2)
+               return;
+       } else {
+           if (t > acc->h2)
+               return;
+       }
+       t = 2.0 * def->h * t;
+       t = (CUBED_ROOT_4 * acc->h2 - cbrt(t * t)) / acc->h2mw2;
+       if (t > 0.0)
+           acc->tail_y = def->h / CUBED_ROOT_2 * sqrt(t);
+}
+
+/*
+ * inverse functions -- compute edge coordinates
+ * from the ellipse
+ */
+
+static double
+outerXfromXY (x, y, def, acc)
+       double                  x, y;
+       struct arc_def          *def;
+       struct accelerators     *acc;
+{
+       return x + (x * acc->h2l) / sqrt (x*x * acc->h4 + y*y * acc->w4);
+}
+
+static double
+outerYfromXY (x, y, def, acc)
+       double          x, y;
+       struct arc_def          *def;
+       struct accelerators     *acc;
+{
+       return y + (y * acc->w2l) / sqrt (x*x * acc->h4 + y*y * acc->w4);
+}
+
+static double
+innerXfromXY (x, y, def, acc)
+       double                  x, y;
+       struct arc_def          *def;
+       struct accelerators     *acc;
+{
+       return x - (x * acc->h2l) / sqrt (x*x * acc->h4 + y*y * acc->w4);
+}
+
+static double
+innerYfromXY (x, y, def, acc)
+       double                  x, y;
+       struct arc_def          *def;
+       struct accelerators     *acc;
+{
+       return y - (y * acc->w2l) / sqrt (x*x * acc->h4 + y*y * acc->w4);
+}
+
+static double
+innerYfromY (y, def, acc)
+       double  y;
+       struct arc_def          *def;
+       struct accelerators     *acc;
+{
+       double  x;
+
+       x = (def->w / def->h) * sqrt (acc->h2 - y*y);
+
+       return y - (y * acc->w2l) / sqrt (x*x * acc->h4 + y*y * acc->w4);
+}
+
+static void
+computeLine (x1, y1, x2, y2, line)
+       double          x1, y1, x2, y2;
+       struct line     *line;
+{
+       if (y1 == y2)
+               line->valid = 0;
+       else {
+               line->m = (x1 - x2) / (y1 - y2);
+               line->b = x1  - y1 * line->m;
+               line->valid = 1;
+       }
+}
+
+/*
+ * compute various accelerators for an ellipse.  These
+ * are simply values that are used repeatedly in
+ * the computations
+ */
+
+static void
+computeAcc (tarc, lw, def, acc)
+       xArc                    *tarc;
+       int                     lw;
+       struct arc_def          *def;
+       struct accelerators     *acc;
+{
+       def->w = ((double) tarc->width) / 2.0;
+       def->h = ((double) tarc->height) / 2.0;
+       def->l = ((double) lw) / 2.0;
+       acc->h2 = def->h * def->h;
+       acc->w2 = def->w * def->w;
+       acc->h4 = acc->h2 * acc->h2;
+       acc->w4 = acc->w2 * acc->w2;
+       acc->h2l = acc->h2 * def->l;
+       acc->w2l = acc->w2 * def->l;
+       acc->h2mw2 = acc->h2 - acc->w2;
+       acc->fromIntX = (tarc->width & 1) ? 0.5 : 0.0;
+       acc->fromIntY = (tarc->height & 1) ? 0.5 : 0.0;
+       acc->xorg = tarc->x + (tarc->width >> 1);
+       acc->yorgu = tarc->y + (tarc->height >> 1);
+       acc->yorgl = acc->yorgu + (tarc->height & 1);
+       tailEllipseY (def, acc);
+}
+               
+/*
+ * compute y value bounds of various portions of the arc,
+ * the outer edge, the ellipse and the inner edge.
+ */
+
+static void
+computeBound (def, bound, acc, right, left)
+       struct arc_def          *def;
+       struct arc_bound        *bound;
+       struct accelerators     *acc;
+       miArcFacePtr            right, left;
+{
+       double          t;
+       double          innerTaily;
+       double          tail_y;
+       struct bound    innerx, outerx;
+       struct bound    ellipsex;
+
+       bound->ellipse.min = Dsin (def->a0) * def->h;
+       bound->ellipse.max = Dsin (def->a1) * def->h;
+       if (def->a0 == 45 && def->w == def->h)
+               ellipsex.min = bound->ellipse.min;
+       else
+               ellipsex.min = Dcos (def->a0) * def->w;
+       if (def->a1 == 45 && def->w == def->h)
+               ellipsex.max = bound->ellipse.max;
+       else
+               ellipsex.max = Dcos (def->a1) * def->w;
+       bound->outer.min = outerYfromXY (ellipsex.min, bound->ellipse.min, def, acc);
+       bound->outer.max = outerYfromXY (ellipsex.max, bound->ellipse.max, def, acc);
+       bound->inner.min = innerYfromXY (ellipsex.min, bound->ellipse.min, def, acc);
+       bound->inner.max = innerYfromXY (ellipsex.max, bound->ellipse.max, def, acc);
+
+       outerx.min = outerXfromXY (ellipsex.min, bound->ellipse.min, def, acc);
+       outerx.max = outerXfromXY (ellipsex.max, bound->ellipse.max, def, acc);
+       innerx.min = innerXfromXY (ellipsex.min, bound->ellipse.min, def, acc);
+       innerx.max = innerXfromXY (ellipsex.max, bound->ellipse.max, def, acc);
+       
+       /*
+        * save the line end points for the
+        * cap code to use.  Careful here, these are
+        * in cartesean coordinates (y increasing upwards)
+        * while the cap code uses inverted coordinates
+        * (y increasing downwards)
+        */
+
+       if (right) {
+               right->counterClock.y = bound->outer.min;
+               right->counterClock.x = outerx.min;
+               right->center.y = bound->ellipse.min;
+               right->center.x = ellipsex.min;
+               right->clock.y = bound->inner.min;
+               right->clock.x = innerx.min;
+       }
+
+       if (left) {
+               left->clock.y = bound->outer.max;
+               left->clock.x = outerx.max;
+               left->center.y = bound->ellipse.max;
+               left->center.x = ellipsex.max;
+               left->counterClock.y = bound->inner.max;
+               left->counterClock.x = innerx.max;
+       }
+
+       bound->left.min = bound->inner.max;
+       bound->left.max = bound->outer.max;
+       bound->right.min = bound->inner.min;
+       bound->right.max = bound->outer.min;
+
+       computeLine (innerx.min, bound->inner.min, outerx.min, bound->outer.min,
+                     &acc->right);
+       computeLine (innerx.max, bound->inner.max, outerx.max, bound->outer.max,
+                    &acc->left);
+
+       if (bound->inner.min > bound->inner.max) {
+               t = bound->inner.min;
+               bound->inner.min = bound->inner.max;
+               bound->inner.max = t;
+       }
+       tail_y = acc->tail_y;
+       if (tail_y > bound->ellipse.max)
+               tail_y = bound->ellipse.max;
+       else if (tail_y < bound->ellipse.min)
+               tail_y = bound->ellipse.min;
+       innerTaily = innerYfromY (tail_y, def, acc);
+       if (bound->inner.min > innerTaily)
+               bound->inner.min = innerTaily;
+       if (bound->inner.max < innerTaily)
+               bound->inner.max = innerTaily;
+       bound->inneri.min = ICEIL(bound->inner.min - acc->fromIntY);
+       bound->inneri.max = floor(bound->inner.max - acc->fromIntY);
+       bound->outeri.min = ICEIL(bound->outer.min - acc->fromIntY);
+       bound->outeri.max = floor(bound->outer.max - acc->fromIntY);
+}
+
+/*
+ * this section computes the x value of the span at y 
+ * intersected with the specified face of the ellipse.
+ *
+ * this is the min/max X value over the set of normal
+ * lines to the entire ellipse,  the equation of the
+ * normal lines is:
+ *
+ *     ellipse_x h^2                   h^2
+ * x = ------------ y + ellipse_x (1 - --- )
+ *     ellipse_y w^2                   w^2
+ *
+ * compute the derivative with-respect-to ellipse_y and solve
+ * for zero:
+ *    
+ *       (w^2 - h^2) ellipse_y^3 + h^4 y
+ * 0 = - ----------------------------------
+ *       h w ellipse_y^2 sqrt (h^2 - ellipse_y^2)
+ *
+ *             (   h^4 y     )
+ * ellipse_y = ( ----------  ) ^ (1/3)
+ *             ( (h^2 - w^2) )
+ *
+ * The other two solutions to the equation are imaginary.
+ *
+ * This gives the position on the ellipse which generates
+ * the normal with the largest/smallest x intersection point.
+ *
+ * Now compute the second derivative to check whether
+ * the intersection is a minimum or maximum:
+ *
+ *    h (y0^3 (w^2 - h^2) + h^2 y (3y0^2 - 2h^2))
+ * -  -------------------------------------------
+ *          w y0^3 (sqrt (h^2 - y^2)) ^ 3
+ *
+ * as we only care about the sign,
+ *
+ * - (y0^3 (w^2 - h^2) + h^2 y (3y0^2 - 2h^2))
+ *
+ * or (to use accelerators),
+ *
+ * y0^3 (h^2 - w^2) - h^2 y (3y0^2 - 2h^2) 
+ *
+ */
+
+/*
+ * computes the position on the ellipse whose normal line
+ * intersects the given scan line maximally
+ */
+
+static double
+hookEllipseY (scan_y, bound, acc, left)
+       double                  scan_y;
+       struct arc_bound        *bound;
+       struct accelerators     *acc;
+       int                     left;
+{
+       double  ret;
+
+       if (acc->h2mw2 == 0) {
+               if ( (scan_y > 0 && !left) || (scan_y < 0 && left) )
+                       return bound->ellipse.min;
+               return bound->ellipse.max;
+       }
+       ret = (acc->h4 * scan_y) / (acc->h2mw2);
+       if (ret >= 0)
+               return cbrt (ret);
+       else
+               return -cbrt (-ret);
+}
+
+/*
+ * computes the X value of the intersection of the
+ * given scan line with the right side of the lower hook
+ */
+
+static double
+hookX (scan_y, def, bound, acc, left)
+       double                  scan_y;
+       struct arc_def          *def;
+       struct arc_bound        *bound;
+       struct accelerators     *acc;
+       int                     left;
+{
+       double  ellipse_y, x;
+       double  maxMin;
+
+       if (def->w != def->h) {
+               ellipse_y = hookEllipseY (scan_y, bound, acc, left);
+               if (boundedLe (ellipse_y, bound->ellipse)) {
+                       /*
+                        * compute the value of the second
+                        * derivative
+                        */
+                       maxMin = ellipse_y*ellipse_y*ellipse_y * acc->h2mw2 -
+                        acc->h2 * scan_y * (3 * ellipse_y*ellipse_y - 2*acc->h2);
+                       if ((left && maxMin > 0) || (!left && maxMin < 0)) {
+                               if (ellipse_y == 0)
+                                       return def->w + left ? -def->l : def->l;
+                               x = (acc->h2 * scan_y - ellipse_y * acc->h2mw2) *
+                                       sqrt (acc->h2 - ellipse_y * ellipse_y) /
+                                       (def->h * def->w * ellipse_y);
+                               return x;
+                       }
+               }
+       }
+       if (left) {
+               if (acc->left.valid && boundedLe (scan_y, bound->left)) {
+                       x = intersectLine (scan_y, acc->left);
+               } else {
+                       if (acc->right.valid)
+                               x = intersectLine (scan_y, acc->right);
+                       else
+                               x = def->w - def->l;
+               }
+       } else {
+               if (acc->right.valid && boundedLe (scan_y, bound->right)) {
+                       x = intersectLine (scan_y, acc->right);
+               } else {
+                       if (acc->left.valid)
+                               x = intersectLine (scan_y, acc->left);
+                       else
+                               x = def->w - def->l;
+               }
+       }
+       return x;
+}
+
+/*
+ * generate the set of spans with
+ * the given y coordinate
+ */
+
+static void
+arcSpan (y, lx, lw, rx, rw, def, bounds, acc, mask)
+       int                     y;
+       int                     lx;
+       int                     lw;
+       int                     rx;
+       int                     rw;
+       struct arc_def          *def;
+       struct arc_bound        *bounds;
+       struct accelerators     *acc;
+       int                     mask;
+{
+       int linx, loutx, rinx, routx;
+       double x, altx;
+
+       if (boundedLe (y, bounds->inneri)) {
+           linx = -(lx + lw);
+           rinx = rx;
+       } else {
+           /*
+            * intersection with left face
+            */
+           x = hookX (y + acc->fromIntY, def, bounds, acc, 1);
+           if (acc->right.valid &&
+               boundedLe (y + acc->fromIntY, bounds->right))
+           {
+               altx = intersectLine (y + acc->fromIntY, acc->right);
+               if (altx < x)
+                   x = altx;
+           }
+           linx = -ICEIL(acc->fromIntX - x);
+           rinx = ICEIL(acc->fromIntX + x);
+       }
+       if (boundedLe (y, bounds->outeri)) {
+           loutx = -lx;
+           routx = rx + rw;
+       } else {
+           /*
+            * intersection with right face
+            */
+           x = hookX (y + acc->fromIntY, def, bounds, acc, 0);
+           if (acc->left.valid &&
+               boundedLe (y + acc->fromIntY, bounds->left))
+           {
+               altx = x;
+               x = intersectLine (y + acc->fromIntY, acc->left);
+               if (x < altx)
+                   x = altx;
+           }
+           loutx = -ICEIL(acc->fromIntX - x);
+           routx = ICEIL(acc->fromIntX + x);
+       }
+       if (routx > rinx) {
+           if (mask & 1)
+               newFinalSpan (acc->yorgu - y,
+                             acc->xorg + rinx, acc->xorg + routx);
+           if (mask & 8)
+               newFinalSpan (acc->yorgl + y,
+                             acc->xorg + rinx, acc->xorg + routx);
+       }
+       if (loutx > linx) {
+           if (mask & 2)
+               newFinalSpan (acc->yorgu - y,
+                             acc->xorg - loutx, acc->xorg - linx);
+           if (mask & 4)
+               newFinalSpan (acc->yorgl + y,
+                             acc->xorg - loutx, acc->xorg - linx);
+       }
+}
+
+static void
+arcSpan0 (lx, lw, rx, rw, def, bounds, acc, mask)
+       int                     lx;
+       int                     lw;
+       int                     rx;
+       int                     rw;
+       struct arc_def          *def;
+       struct arc_bound        *bounds;
+       struct accelerators     *acc;
+       int                     mask;
+{
+    double x;
+
+    if (boundedLe (0, bounds->inneri) &&
+       acc->left.valid && boundedLe (0, bounds->left) &&
+       acc->left.b > 0)
+    {
+       x = def->w - def->l;
+       if (acc->left.b < x)
+           x = acc->left.b;
+       lw = ICEIL(acc->fromIntX - x) - lx;
+       rw += rx;
+       rx = ICEIL(acc->fromIntX + x);
+       rw -= rx;
+    }
+    arcSpan (0, lx, lw, rx, rw, def, bounds, acc, mask);
+}
+
+static void
+tailSpan (y, lw, rw, def, bounds, acc, mask)
+       int                     y;
+       int                     lw;
+       int                     rw;
+       struct arc_def          *def;
+       struct arc_bound        *bounds;
+       struct accelerators     *acc;
+       int                     mask;
+{
+    double yy, xalt, x, lx, rx;
+    int n;
+
+    if (boundedLe(y, bounds->outeri))
+       arcSpan (y, 0, lw, -rw, rw, def, bounds, acc, mask);
+    else if (def->w != def->h) {
+       yy = y + acc->fromIntY;
+       x = tailX(yy, def, bounds, acc);
+       if (yy == 0.0 && x == -rw - acc->fromIntX)
+           return;
+       if (acc->right.valid && boundedLe (yy, bounds->right)) {
+           rx = x;
+           lx = -x;
+           xalt = intersectLine (yy, acc->right);
+           if (xalt >= -rw - acc->fromIntX && xalt <= rx)
+               rx = xalt;
+           n = ICEIL(acc->fromIntX + lx);
+           if (lw > n) {
+               if (mask & 2)
+                   newFinalSpan (acc->yorgu - y,
+                                 acc->xorg + n, acc->xorg + lw);
+               if (mask & 4)
+                   newFinalSpan (acc->yorgl + y,
+                                 acc->xorg + n, acc->xorg + lw);
+           }
+           n = ICEIL(acc->fromIntX + rx);
+           if (n > -rw) {
+               if (mask & 1)
+                   newFinalSpan (acc->yorgu - y,
+                                 acc->xorg - rw, acc->xorg + n);
+               if (mask & 8)
+                   newFinalSpan (acc->yorgl + y,
+                                 acc->xorg - rw, acc->xorg + n);
+           }
+       }
+       arcSpan (y,
+                ICEIL(acc->fromIntX - x), 0,
+                ICEIL(acc->fromIntX + x), 0,
+                def, bounds, acc, mask);
+    }
+}
+
+/*
+ * create whole arcs out of pieces.  This code is
+ * very bad.
+ */
+
+static struct finalSpan        **finalSpans = NULL;
+static int             finalMiny = 0, finalMaxy = -1;
+static int             finalSize = 0;
+
+static int             nspans = 0;     /* total spans, not just y coords */
+
+struct finalSpan {
+       struct finalSpan        *next;
+       int                     min, max;       /* x values */
+};
+
+static struct finalSpan    *freeFinalSpans, *tmpFinalSpan;
+
+# define allocFinalSpan()   (freeFinalSpans ?\
+                               ((tmpFinalSpan = freeFinalSpans), \
+                                (freeFinalSpans = freeFinalSpans->next), \
+                                (tmpFinalSpan->next = 0), \
+                                tmpFinalSpan) : \
+                            realAllocSpan ())
+
+# define SPAN_CHUNK_SIZE    128
+
+struct finalSpanChunk {
+       struct finalSpan        data[SPAN_CHUNK_SIZE];
+       struct finalSpanChunk   *next;
+};
+
+static struct finalSpanChunk   *chunks;
+
+struct finalSpan *
+realAllocSpan ()
+{
+       register struct finalSpanChunk  *newChunk;
+       register struct finalSpan       *span;
+       register int                    i;
+
+       newChunk = (struct finalSpanChunk *) xalloc (sizeof (struct finalSpanChunk));
+       if (!newChunk)
+               return (struct finalSpan *) NULL;
+       newChunk->next = chunks;
+       chunks = newChunk;
+       freeFinalSpans = span = newChunk->data + 1;
+       for (i = 1; i < SPAN_CHUNK_SIZE-1; i++) {
+               span->next = span+1;
+               span++;
+       }
+       span->next = 0;
+       span = newChunk->data;
+       span->next = 0;
+       return span;
+}
+
+static void
+disposeFinalSpans ()
+{
+       struct finalSpanChunk   *chunk, *next;
+
+       for (chunk = chunks; chunk; chunk = next) {
+               next = chunk->next;
+               xfree (chunk);
+       }
+       chunks = 0;
+       freeFinalSpans = 0;
+       xfree(finalSpans);
+       finalSpans = 0;
+}
+
+static void
+fillSpans (pDrawable, pGC)
+    DrawablePtr        pDrawable;
+    GCPtr      pGC;
+{
+       register struct finalSpan       *span;
+       register DDXPointPtr            xSpan;
+       register int                    *xWidth;
+       register int                    i;
+       register struct finalSpan       **f;
+       register int                    spany;
+       DDXPointPtr                     xSpans;
+       int                             *xWidths;
+
+       if (nspans == 0)
+               return;
+       xSpan = xSpans = (DDXPointPtr) ALLOCATE_LOCAL (nspans * sizeof (DDXPointRec));
+       xWidth = xWidths = (int *) ALLOCATE_LOCAL (nspans * sizeof (int));
+       if (xSpans && xWidths)
+       {
+           i = 0;
+           f = finalSpans;
+           for (spany = finalMiny; spany <= finalMaxy; spany++, f++) {
+                   for (span = *f; span; span=span->next) {
+                           if (span->max <= span->min)
+                                   continue;
+                           xSpan->x = span->min;
+                           xSpan->y = spany;
+                           ++xSpan;
+                           *xWidth++ = span->max - span->min;
+                           ++i;
+                   }
+           }
+           (*pGC->ops->FillSpans) (pDrawable, pGC, i, xSpans, xWidths, TRUE);
+       }
+       disposeFinalSpans ();
+       if (xSpans)
+           DEALLOCATE_LOCAL (xSpans);
+       if (xWidths)
+           DEALLOCATE_LOCAL (xWidths);
+       finalMiny = 0;
+       finalMaxy = -1;
+       finalSize = 0;
+       nspans = 0;
+}
+
+# define SPAN_REALLOC  100
+
+# define findSpan(y) ((finalMiny <= (y) && (y) <= finalMaxy) ? \
+                         &finalSpans[(y) - finalMiny] : \
+                         realFindSpan (y))
+
+static struct finalSpan **
+realFindSpan (y)
+    int y;
+{
+       struct finalSpan        **newSpans;
+       int                     newSize, newMiny, newMaxy;
+       int                     change;
+       int                     i;
+
+       if (y < finalMiny || y > finalMaxy) {
+               if (!finalSize) {
+                       finalMiny = y;
+                       finalMaxy = y - 1;
+               }
+               if (y < finalMiny)
+                       change = finalMiny - y;
+               else
+                       change = y - finalMaxy;
+               if (change >= SPAN_REALLOC)
+                       change += SPAN_REALLOC;
+               else
+                       change = SPAN_REALLOC;
+               newSize = finalSize + change;
+               newSpans = (struct finalSpan **) xalloc
+                                       (newSize * sizeof (struct finalSpan *));
+               if (!newSpans)
+                   return (struct finalSpan **)NULL;
+               newMiny = finalMiny;
+               newMaxy = finalMaxy;
+               if (y < finalMiny)
+                       newMiny = finalMiny - change;
+               else
+                       newMaxy = finalMaxy + change;
+               if (finalSpans) {
+                       memmove(((char *) newSpans) + (finalMiny-newMiny) * sizeof (struct finalSpan *),
+                               (char *) finalSpans,
+                              finalSize * sizeof (struct finalSpan *));
+                       xfree (finalSpans);
+               }
+               if ((i = finalMiny - newMiny) > 0)
+                       bzero ((char *)newSpans, i * sizeof (struct finalSpan *));
+               if ((i = newMaxy - finalMaxy) > 0)
+                       bzero ((char *)(newSpans + newSize - i),
+                              i * sizeof (struct finalSpan *));
+               finalSpans = newSpans;
+               finalMaxy = newMaxy;
+               finalMiny = newMiny;
+               finalSize = newSize;
+       }
+       return &finalSpans[y - finalMiny];
+}
+
+static void
+newFinalSpan (y, xmin, xmax)
+    int                y;
+    register int       xmin, xmax;
+{
+       register struct finalSpan       *x;
+       register struct finalSpan       **f;
+       struct finalSpan                *oldx;
+       struct finalSpan                *prev;
+
+       f = findSpan (y);
+       if (!f)
+           return;
+       oldx = 0;
+       for (;;) {
+               prev = 0;
+               for (x = *f; x; x=x->next) {
+                       if (x == oldx) {
+                               prev = x;
+                               continue;
+                       }
+                       if (x->min <= xmax && xmin <= x->max) {
+                               if (oldx) {
+                                       oldx->min = min (x->min, xmin);
+                                       oldx->max = max (x->max, xmax);
+                                       if (prev)
+                                               prev->next = x->next;
+                                       else
+                                               *f = x->next;
+                                       --nspans;
+                               } else {
+                                       x->min = min (x->min, xmin);
+                                       x->max = max (x->max, xmax);
+                                       oldx = x;
+                               }
+                               xmin = oldx->min;
+                               xmax = oldx->max;
+                               break;
+                       }
+                       prev = x;
+               }
+               if (!x)
+                       break;
+       }
+       if (!oldx) {
+               x = allocFinalSpan ();
+               if (x)
+               {
+                   x->min = xmin;
+                   x->max = xmax;
+                   x->next = *f;
+                   *f = x;
+                   ++nspans;
+               }
+       }
+}
+
+static void
+mirrorSppPoint (quadrant, sppPoint)
+       int             quadrant;
+       SppPointPtr     sppPoint;
+{
+       switch (quadrant) {
+       case 0:
+               break;
+       case 1:
+               sppPoint->x = -sppPoint->x;
+               break;
+       case 2:
+               sppPoint->x = -sppPoint->x;
+               sppPoint->y = -sppPoint->y;
+               break;
+       case 3:
+               sppPoint->y = -sppPoint->y;
+               break;
+       }
+       /*
+        * and translate to X coordinate system
+        */
+       sppPoint->y = -sppPoint->y;
+}
+
+/*
+ * split an arc into pieces which are scan-converted
+ * in the first-quadrant and mirrored into position.
+ * This is necessary as the scan-conversion code can
+ * only deal with arcs completely contained in the
+ * first quadrant.
+ */
+
+static void
+drawArc (tarc, l, a0, a1, right, left)
+       xArc *tarc;
+       int     l, a0, a1;
+       miArcFacePtr    right, left;    /* save end line points */
+{
+       struct arc_def          def;
+       struct accelerators     acc;
+       int                     startq, endq, curq;
+       int                     rightq, leftq, righta, lefta;
+       miArcFacePtr            passRight, passLeft;
+       int                     q0, q1, mask;
+       struct band {
+               int     a0, a1;
+               int     mask;
+       }       band[5], sweep[20];
+       int                     bandno, sweepno;
+       int                     i, j;
+       int                     flipRight = 0, flipLeft = 0;                    
+       int                     copyEnd = 0;
+       miArcSpanData           *spdata;
+       Bool                    mustFree;
+
+       spdata = miComputeWideEllipse(l, tarc, &mustFree);
+       if (!spdata)
+           return;
+
+       if (a1 < a0)
+               a1 += 360 * 64;
+       startq = a0 / (90 * 64);
+       if (a0 == a1)
+           endq = startq;
+       else
+           endq = (a1-1) / (90 * 64);
+       bandno = 0;
+       curq = startq;
+       rightq = -1;
+       for (;;) {
+               switch (curq) {
+               case 0:
+                       if (a0 > 90 * 64)
+                               q0 = 0;
+                       else
+                               q0 = a0;
+                       if (a1 < 360 * 64)
+                               q1 = min (a1, 90 * 64);
+                       else
+                               q1 = 90 * 64;
+                       if (curq == startq && a0 == q0 && rightq < 0) {
+                               righta = q0;
+                               rightq = curq;
+                       }
+                       if (curq == endq && a1 == q1) {
+                               lefta = q1;
+                               leftq = curq;
+                       }
+                       break;
+               case 1:
+                       if (a1 < 90 * 64)
+                               q0 = 0;
+                       else
+                               q0 = 180 * 64 - min (a1, 180 * 64);
+                       if (a0 > 180 * 64)
+                               q1 = 90 * 64;
+                       else
+                               q1 = 180 * 64 - max (a0, 90 * 64);
+                       if (curq == startq && 180 * 64 - a0 == q1) {
+                               righta = q1;
+                               rightq = curq;
+                       }
+                       if (curq == endq && 180 * 64 - a1 == q0) {
+                               lefta = q0;
+                               leftq = curq;
+                       }
+                       break;
+               case 2:
+                       if (a0 > 270 * 64)
+                               q0 = 0;
+                       else
+                               q0 = max (a0, 180 * 64) - 180 * 64;
+                       if (a1 < 180 * 64)
+                               q1 = 90 * 64;
+                       else
+                               q1 = min (a1, 270 * 64) - 180 * 64;
+                       if (curq == startq && a0 - 180*64 == q0) {
+                               righta = q0;
+                               rightq = curq;
+                       }
+                       if (curq == endq && a1 - 180 * 64 == q1) {
+                               lefta = q1;
+                               leftq = curq;
+                       }
+                       break;
+               case 3:
+                       if (a1 < 270 * 64)
+                               q0 = 0;
+                       else
+                               q0 = 360 * 64 - min (a1, 360 * 64);
+                       q1 = 360 * 64 - max (a0, 270 * 64);
+                       if (curq == startq && 360 * 64 - a0 == q1) {
+                               righta = q1;
+                               rightq = curq;
+                       }
+                       if (curq == endq && 360 * 64 - a1 == q0) {
+                               lefta = q0;
+                               leftq = curq;
+                       }
+                       break;
+               }
+               band[bandno].a0 = q0;
+               band[bandno].a1 = q1;
+               band[bandno].mask = 1 << curq;
+               bandno++;
+               if (curq == endq)
+                       break;
+               curq++;
+               if (curq == 4) {
+                       a0 = 0;
+                       a1 -= 360 * 64;
+                       curq = 0;
+                       endq -= 4;
+               }
+       }
+       sweepno = 0;
+       for (;;) {
+               q0 = 90 * 64;
+               mask = 0;
+               /*
+                * find left-most point
+                */
+               for (i = 0; i < bandno; i++)
+                       if (band[i].a0 <= q0) {
+                               q0 = band[i].a0;
+                               q1 = band[i].a1;
+                               mask = band[i].mask;
+                       }
+               if (!mask)
+                       break;
+               /*
+                * locate next point of change
+                */
+               for (i = 0; i < bandno; i++)
+                       if (!(mask & band[i].mask)) {
+                               if (band[i].a0 == q0) {
+                                       if (band[i].a1 < q1)
+                                               q1 = band[i].a1;
+                                       mask |= band[i].mask;
+                               } else if (band[i].a0 < q1)
+                                       q1 = band[i].a0;
+                       }
+               /*
+                * create a new sweep
+                */
+               sweep[sweepno].a0 = q0;
+               sweep[sweepno].a1 = q1;
+               sweep[sweepno].mask = mask;
+               sweepno++;
+               /*
+                * subtract the sweep from the affected bands
+                */
+               for (i = 0; i < bandno; i++)
+                       if (band[i].a0 == q0) {
+                               band[i].a0 = q1;
+                               /*
+                                * check if this band is empty
+                                */
+                               if (band[i].a0 == band[i].a1)
+                                       band[i].a1 = band[i].a0 = 90 * 64 + 1;
+                       }
+       }
+       computeAcc (tarc, l, &def, &acc);
+       for (j = 0; j < sweepno; j++) {
+               mask = sweep[j].mask;
+               passRight = passLeft = 0;
+               if (mask & (1 << rightq)) {
+                       if (sweep[j].a0 == righta)
+                               passRight = right;
+                       else if (sweep[j].a1 == righta) {
+                               passLeft = right;
+                               flipRight = 1;
+                       }
+               }
+               if (mask & (1 << leftq)) {
+                       if (sweep[j].a1 == lefta)
+                       {
+                               if (passLeft)
+                                       copyEnd = 1;
+                               passLeft = left;
+                       }
+                       else if (sweep[j].a0 == lefta) {
+                               if (passRight)
+                                       copyEnd = 1;
+                               passRight = left;
+                               flipLeft = 1;
+                       }
+               }
+               drawQuadrant (&def, &acc, sweep[j].a0, sweep[j].a1, mask, 
+                             passRight, passLeft, spdata);
+       }
+       /*
+        * when copyEnd is set, both ends of the arc were computed
+        * at the same time; drawQuadrant only takes one end though,
+        * so the left end will be the only one holding the data.  Copy
+        * it from there.
+        */
+       if (copyEnd)
+               *right = *left;
+       /*
+        * mirror the coordinates generated for the
+        * faces of the arc
+        */
+       if (right) {
+               mirrorSppPoint (rightq, &right->clock);
+               mirrorSppPoint (rightq, &right->center);
+               mirrorSppPoint (rightq, &right->counterClock);
+               if (flipRight) {
+                       SppPointRec     temp;
+
+                       temp = right->clock;
+                       right->clock = right->counterClock;
+                       right->counterClock = temp;
+               }
+       }
+       if (left) {
+               mirrorSppPoint (leftq,  &left->counterClock);
+               mirrorSppPoint (leftq,  &left->center);
+               mirrorSppPoint (leftq,  &left->clock);
+               if (flipLeft) {
+                       SppPointRec     temp;
+
+                       temp = left->clock;
+                       left->clock = left->counterClock;
+                       left->counterClock = temp;
+               }
+       }
+       if (mustFree)
+           xfree(spdata);
+}
+
+static void
+drawQuadrant (def, acc, a0, a1, mask, right, left, spdata)
+       struct arc_def          *def;
+       struct accelerators     *acc;
+       int                     a0, a1;
+       int                     mask;
+       miArcFacePtr            right, left;
+       miArcSpanData           *spdata;
+{
+       struct arc_bound        bound;
+       double                  yy, x, xalt;
+       int                     y, miny, maxy;
+       int                     n;
+       miArcSpan               *span;
+
+       def->a0 = ((double) a0) / 64.0;
+       def->a1 = ((double) a1) / 64.0;
+       computeBound (def, &bound, acc, right, left);
+       yy = bound.inner.min;
+       if (bound.outer.min < yy)
+           yy = bound.outer.min;
+       miny = ICEIL(yy - acc->fromIntY);
+       yy = bound.inner.max;
+       if (bound.outer.max > yy)
+           yy = bound.outer.max;
+       maxy = floor(yy - acc->fromIntY);
+       y = spdata->k;
+       span = spdata->spans;
+       if (spdata->top)
+       {
+           if (a1 == 90 * 64 && (mask & 1))
+               newFinalSpan (acc->yorgu - y - 1, acc->xorg, acc->xorg + 1);
+           span++;
+       }
+       for (n = spdata->count1; --n >= 0; )
+       {
+           if (y < miny)
+               return;
+           if (y <= maxy) {
+               arcSpan (y,
+                        span->lx, -span->lx, 0, span->lx + span->lw,
+                        def, &bound, acc, mask);
+               if (span->rw + span->rx)
+                   tailSpan (y, -span->rw, -span->rx, def, &bound, acc, mask);
+           }
+           y--;
+           span++;
+       }
+       if (y < miny)
+           return;
+       if (spdata->hole)
+       {
+           if (y <= maxy)
+               arcSpan (y, 0, 0, 0, 1, def, &bound, acc, mask & 0xc);
+       }
+       for (n = spdata->count2; --n >= 0; )
+       {
+           if (y < miny)
+               return;
+           if (y <= maxy)
+               arcSpan (y, span->lx, span->lw, span->rx, span->rw,
+                        def, &bound, acc, mask);
+           y--;
+           span++;
+       }
+       if (spdata->bot && miny <= y && y <= maxy)
+       {
+           n = mask;
+           if (y == miny)
+               n &= 0xc;
+           if (span->rw <= 0) {
+               arcSpan0 (span->lx, -span->lx, 0, span->lx + span->lw,
+                         def, &bound, acc, n);
+               if (span->rw + span->rx)
+                   tailSpan (y, -span->rw, -span->rx, def, &bound, acc, n);
+           }
+           else
+               arcSpan0 (span->lx, span->lw, span->rx, span->rw,
+                         def, &bound, acc, n);
+           y--;
+       }
+       while (y >= miny) {
+           yy = y + acc->fromIntY;
+           if (def->w == def->h) {
+               xalt = def->w - def->l;
+               x = -sqrt(xalt * xalt - yy * yy);
+           } else {
+               x = tailX(yy, def, &bound, acc);
+               if (acc->left.valid && boundedLe (yy, bound.left)) {
+                   xalt = intersectLine (yy, acc->left);
+                   if (xalt < x)
+                       x = xalt;
+               }
+               if (acc->right.valid && boundedLe (yy, bound.right)) {
+                   xalt = intersectLine (yy, acc->right);
+                   if (xalt < x)
+                       x = xalt;
+               }
+           }
+           arcSpan (y,
+                    ICEIL(acc->fromIntX - x), 0,
+                    ICEIL(acc->fromIntX + x), 0,
+                    def, &bound, acc, mask);
+           y--;
+       }
+}
diff --git a/Xserver/programs/Xserver/mi/mibitblt.c b/Xserver/programs/Xserver/mi/mibitblt.c
new file mode 100644 (file)
index 0000000..74b467c
--- /dev/null
@@ -0,0 +1,819 @@
+/***********************************************************
+
+Copyright (c) 1987  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+
+Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
+
+                        All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and its 
+documentation for any purpose and without fee is hereby granted, 
+provided that the above copyright notice appear in all copies and that
+both that copyright notice and this permission notice appear in 
+supporting documentation, and that the name of Digital not be
+used in advertising or publicity pertaining to distribution of the
+software without specific, written prior permission.  
+
+DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
+ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
+DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
+ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+SOFTWARE.
+
+******************************************************************/
+/* $XConsortium: mibitblt.c /main/55 1996/08/01 19:25:20 dpw $ */
+/* $XFree86: xc/programs/Xserver/mi/mibitblt.c,v 3.1 1996/12/23 07:09:43 dawes Exp $ */
+/* Author: Todd Newman  (aided and abetted by Mr. Drewry) */
+
+#include "X.h"
+#include "Xprotostr.h"
+
+#include "misc.h"
+#include "gcstruct.h"
+#include "pixmapstr.h"
+#include "windowstr.h"
+#include "scrnintstr.h"
+#include "mi.h"
+#include "regionstr.h"
+#include "Xmd.h"
+#include "servermd.h"
+
+/* MICOPYAREA -- public entry for the CopyArea request 
+ * For each rectangle in the source region
+ *     get the pixels with GetSpans
+ *     set them in the destination with SetSpans
+ * We let SetSpans worry about clipping to the destination.
+ */
+RegionPtr
+miCopyArea(pSrcDrawable, pDstDrawable,
+           pGC, xIn, yIn, widthSrc, heightSrc, xOut, yOut)
+    register DrawablePtr       pSrcDrawable;
+    register DrawablePtr       pDstDrawable;
+    GCPtr                      pGC;
+    int                        xIn, yIn;
+    int                        widthSrc, heightSrc;
+    int                        xOut, yOut;
+{
+    DDXPointPtr                ppt, pptFirst;
+    unsigned int       *pwidthFirst, *pwidth, *pbits;
+    BoxRec             srcBox, *prect;
+                       /* may be a new region, or just a copy */
+    RegionPtr          prgnSrcClip;
+                       /* non-0 if we've created a src clip */
+    RegionPtr          prgnExposed;
+    int                realSrcClip = 0;
+    int                        srcx, srcy, dstx, dsty, i, j, y, width, height,
+                       xMin, xMax, yMin, yMax;
+    unsigned int       *ordering;
+    int                        numRects;
+    BoxPtr             boxes;
+
+    srcx = xIn + pSrcDrawable->x;
+    srcy = yIn + pSrcDrawable->y;
+
+    /* If the destination isn't realized, this is easy */
+    if (pDstDrawable->type == DRAWABLE_WINDOW &&
+       !((WindowPtr)pDstDrawable)->realized)
+       return (RegionPtr)NULL;
+
+    /* clip the source */
+    if (pSrcDrawable->type == DRAWABLE_PIXMAP)
+    {
+       BoxRec box;
+
+       box.x1 = pSrcDrawable->x;
+       box.y1 = pSrcDrawable->y;
+       box.x2 = pSrcDrawable->x + (int) pSrcDrawable->width;
+       box.y2 = pSrcDrawable->y + (int) pSrcDrawable->height;
+
+       prgnSrcClip = REGION_CREATE(pGC->pScreen, &box, 1);
+       realSrcClip = 1;
+    }
+    else
+    {
+       if (pGC->subWindowMode == IncludeInferiors) {
+           prgnSrcClip = NotClippedByChildren ((WindowPtr) pSrcDrawable);
+           realSrcClip = 1;
+       } else
+           prgnSrcClip = &((WindowPtr)pSrcDrawable)->clipList;
+    }
+
+    /* If the src drawable is a window, we need to translate the srcBox so
+     * that we can compare it with the window's clip region later on. */
+    srcBox.x1 = srcx;
+    srcBox.y1 = srcy;
+    srcBox.x2 = srcx  + widthSrc;
+    srcBox.y2 = srcy  + heightSrc;
+
+    dstx = xOut;
+    dsty = yOut;
+    if (pGC->miTranslate)
+    {
+       dstx += pDstDrawable->x;
+       dsty += pDstDrawable->y;
+    }
+
+    pptFirst = ppt = (DDXPointPtr)
+        ALLOCATE_LOCAL(heightSrc * sizeof(DDXPointRec));
+    pwidthFirst = pwidth = (unsigned int *)
+        ALLOCATE_LOCAL(heightSrc * sizeof(unsigned int));
+    numRects = REGION_NUM_RECTS(prgnSrcClip);
+    boxes = REGION_RECTS(prgnSrcClip);
+    ordering = (unsigned int *)
+        ALLOCATE_LOCAL(numRects * sizeof(unsigned int));
+    if(!pptFirst || !pwidthFirst || !ordering)
+    {
+       if (ordering)
+          DEALLOCATE_LOCAL(ordering);
+       if (pwidthFirst)
+           DEALLOCATE_LOCAL(pwidthFirst);
+       if (pptFirst)
+           DEALLOCATE_LOCAL(pptFirst);
+       return (RegionPtr)NULL;
+    }
+
+    /* If not the same drawable then order of move doesn't matter.
+       Following assumes that boxes are sorted from top
+       to bottom and left to right.
+    */
+    if ((pSrcDrawable != pDstDrawable) &&
+       ((pGC->subWindowMode != IncludeInferiors) ||
+        (pSrcDrawable->type == DRAWABLE_PIXMAP) ||
+        (pDstDrawable->type == DRAWABLE_PIXMAP)))
+      for (i=0; i < numRects; i++)
+        ordering[i] = i;
+    else { /* within same drawable, must sequence moves carefully! */
+      if (dsty <= srcBox.y1) { /* Scroll up or stationary vertical.
+                                  Vertical order OK */
+        if (dstx <= srcBox.x1) /* Scroll left or stationary horizontal.
+                                  Horizontal order OK as well */
+          for (i=0; i < numRects; i++)
+            ordering[i] = i;
+        else { /* scroll right. must reverse horizontal banding of rects. */
+          for (i=0, j=1, xMax=0; i < numRects; j=i+1, xMax=i) {
+            /* find extent of current horizontal band */
+            y=boxes[i].y1; /* band has this y coordinate */
+            while ((j < numRects) && (boxes[j].y1 == y))
+              j++;
+            /* reverse the horizontal band in the output ordering */
+            for (j-- ; j >= xMax; j--, i++)
+              ordering[i] = j;
+          }
+        }
+      }
+      else { /* Scroll down. Must reverse vertical banding. */
+        if (dstx < srcBox.x1) { /* Scroll left. Horizontal order OK. */
+          for (i=numRects-1, j=i-1, yMin=i, yMax=0;
+              i >= 0;
+              j=i-1, yMin=i) {
+            /* find extent of current horizontal band */
+            y=boxes[i].y1; /* band has this y coordinate */
+            while ((j >= 0) && (boxes[j].y1 == y))
+              j--;
+            /* reverse the horizontal band in the output ordering */
+            for (j++ ; j <= yMin; j++, i--, yMax++)
+              ordering[yMax] = j;
+          }
+        }
+        else /* Scroll right or horizontal stationary.
+                Reverse horizontal order as well (if stationary, horizontal
+                order can be swapped without penalty and this is faster
+                to compute). */
+          for (i=0, j=numRects-1; i < numRects; i++, j--)
+              ordering[i] = j;
+      }
+    }
+     for(i = 0; i < numRects; i++)
+     {
+        prect = &boxes[ordering[i]];
+       xMin = max(prect->x1, srcBox.x1);
+       xMax = min(prect->x2, srcBox.x2);
+       yMin = max(prect->y1, srcBox.y1);
+       yMax = min(prect->y2, srcBox.y2);
+       /* is there anything visible here? */
+       if(xMax <= xMin || yMax <= yMin)
+           continue;
+
+        ppt = pptFirst;
+       pwidth = pwidthFirst;
+       y = yMin;
+       height = yMax - yMin;
+       width = xMax - xMin;
+
+       for(j = 0; j < height; j++)
+       {
+           /* We must untranslate before calling GetSpans */
+           ppt->x = xMin;
+           ppt++->y = y++;
+           *pwidth++ = width;
+       }
+       pbits = (unsigned int *)xalloc(height * PixmapBytePad(width,
+                                            pSrcDrawable->depth));
+       if (pbits)
+       {
+           (*pSrcDrawable->pScreen->GetSpans)(pSrcDrawable, width, pptFirst,
+                       (int *)pwidthFirst, height, (char *)pbits);
+           ppt = pptFirst;
+           pwidth = pwidthFirst;
+           xMin -= (srcx - dstx);
+           y = yMin - (srcy - dsty);
+           for(j = 0; j < height; j++)
+           {
+               ppt->x = xMin;
+               ppt++->y = y++;
+               *pwidth++ = width;
+           }
+
+           (*pGC->ops->SetSpans)(pDstDrawable, pGC, (char *)pbits, pptFirst,
+                                 (int *)pwidthFirst, height, TRUE);
+           xfree(pbits);
+       }
+    }
+    prgnExposed = miHandleExposures(pSrcDrawable, pDstDrawable, pGC, xIn, yIn,
+                     widthSrc, heightSrc, xOut, yOut, (unsigned long)0);
+    if(realSrcClip)
+       REGION_DESTROY(pGC->pScreen, prgnSrcClip);
+               
+    DEALLOCATE_LOCAL(ordering);
+    DEALLOCATE_LOCAL(pwidthFirst);
+    DEALLOCATE_LOCAL(pptFirst);
+    return prgnExposed;
+}
+
+/* MIGETPLANE -- gets a bitmap representing one plane of pDraw
+ * A helper used for CopyPlane and XY format GetImage 
+ * No clever strategy here, we grab a scanline at a time, pull out the
+ * bits and then stuff them in a 1 bit deep map.
+ */
+static
+unsigned long  *
+miGetPlane(pDraw, planeNum, sx, sy, w, h, result)
+    DrawablePtr                pDraw;
+    int                        planeNum;       /* number of the bitPlane */
+    int                        sx, sy, w, h;
+    unsigned long      *result;
+{
+    int                        i, j, k, width, bitsPerPixel, widthInBytes;
+    DDXPointRec        pt;
+    unsigned long      pixel;
+    unsigned long      bit;
+    unsigned char      *pCharsOut;
+
+#if BITMAP_SCANLINE_UNIT == 8
+#define OUT_TYPE unsigned char
+#endif
+#if BITMAP_SCANLINE_UNIT == 16
+#define OUT_TYPE CARD16
+#endif
+#if BITMAP_SCANLINE_UNIT == 32
+#define OUT_TYPE CARD32
+#endif
+#if BITMAP_SCANLINE_UNIT == 64
+#define OUT_TYPE CARD64
+#endif
+
+    OUT_TYPE           *pOut;
+    int                        delta;
+
+    sx += pDraw->x;
+    sy += pDraw->y;
+    widthInBytes = BitmapBytePad(w);
+    if(!result)
+        result = (unsigned long *)xalloc(h * widthInBytes);
+    if (!result)
+       return (unsigned long *)NULL;
+    bitsPerPixel = pDraw->bitsPerPixel;
+    bzero((char *)result, h * widthInBytes);
+    pOut = (OUT_TYPE *) result;
+    if(bitsPerPixel == 1)
+    {
+       pCharsOut = (unsigned char *) result;
+       width = w;
+    }
+    else
+    {
+       delta = (widthInBytes / (BITMAP_SCANLINE_UNIT / 8)) -
+           (w / BITMAP_SCANLINE_UNIT);
+       width = 1;
+#if IMAGE_BYTE_ORDER == MSBFirst
+       planeNum += (32 - bitsPerPixel);
+#endif
+    }
+    pt.y = sy;
+    for (i = h; --i >= 0; pt.y++)
+    {
+       pt.x = sx;
+       if(bitsPerPixel == 1)
+       {
+           (*pDraw->pScreen->GetSpans)(pDraw, width, &pt, &width, 1,
+                                       (char *)pCharsOut);
+           pCharsOut += widthInBytes;
+       }
+       else
+       {
+           k = 0;
+           for(j = w; --j >= 0; pt.x++)
+           {
+               /* Fetch the next pixel */
+               (*pDraw->pScreen->GetSpans)(pDraw, width, &pt, &width, 1,
+                                           (char *)&pixel);
+               /*
+                * Now get the bit and insert into a bitmap in XY format.
+                */
+               bit = (pixel >> planeNum) & 1;
+               /* XXX assuming bit order == byte order */
+#if BITMAP_BIT_ORDER == LSBFirst
+               bit <<= k;
+#else
+               bit <<= ((BITMAP_SCANLINE_UNIT - 1) - k);
+#endif
+               *pOut |= (OUT_TYPE) bit;
+               k++;
+               if (k == BITMAP_SCANLINE_UNIT)
+               {
+                   pOut++;
+                   k = 0;
+               }
+           }
+           pOut += delta;
+       }
+    }
+    return(result);    
+
+}
+
+/* MIOPQSTIPDRAWABLE -- use pbits as an opaque stipple for pDraw.
+ * Drawing through the clip mask we SetSpans() the bits into a 
+ * bitmap and stipple those bits onto the destination drawable by doing a
+ * PolyFillRect over the whole drawable, 
+ * then we invert the bitmap by copying it onto itself with an alu of
+ * GXinvert, invert the foreground/background colors of the gc, and draw
+ * the background bits.
+ * Note how the clipped out bits of the bitmap are always the background
+ * color so that the stipple never causes FillRect to draw them.
+ */
+void
+miOpqStipDrawable(pDraw, pGC, prgnSrc, pbits, srcx, w, h, dstx, dsty)
+    DrawablePtr pDraw;
+    GCPtr      pGC;
+    RegionPtr  prgnSrc;
+    unsigned long      *pbits;
+    int                srcx, w, h, dstx, dsty;
+{
+    int                oldfill, i;
+    unsigned long oldfg;
+    int                *pwidth, *pwidthFirst;
+    ChangeGCVal        gcv[6];
+    PixmapPtr  pStipple, pPixmap;
+    DDXPointRec        oldOrg;
+    GCPtr      pGCT;
+    DDXPointPtr ppt, pptFirst;
+    xRectangle rect;
+    RegionPtr  prgnSrcClip;
+
+    pPixmap = (*pDraw->pScreen->CreatePixmap)
+                          (pDraw->pScreen, w + srcx, h, 1);
+    if (!pPixmap)
+       return;
+
+    /* Put the image into a 1 bit deep pixmap */
+    pGCT = GetScratchGC(1, pDraw->pScreen);
+    if (!pGCT)
+    {
+       (*pDraw->pScreen->DestroyPixmap)(pPixmap);
+       return;
+    }
+    /* First set the whole pixmap to 0 */
+    gcv[0].val = 0;
+    dixChangeGC(NullClient, pGCT, GCBackground, NULL, gcv);
+    ValidateGC((DrawablePtr)pPixmap, pGCT);
+    miClearDrawable((DrawablePtr)pPixmap, pGCT);
+    ppt = pptFirst = (DDXPointPtr)ALLOCATE_LOCAL(h * sizeof(DDXPointRec));
+    pwidth = pwidthFirst = (int *)ALLOCATE_LOCAL(h * sizeof(int));
+    if(!pptFirst || !pwidthFirst)
+    {
+       if (pwidthFirst) DEALLOCATE_LOCAL(pwidthFirst);
+       if (pptFirst) DEALLOCATE_LOCAL(pptFirst);
+       FreeScratchGC(pGCT);
+       return;
+    }
+
+    /* we need a temporary region because ChangeClip must be assumed
+       to destroy what it's sent.  note that this means we don't
+       have to free prgnSrcClip ourselves.
+    */
+    prgnSrcClip = REGION_CREATE(pGCT->pScreen, NULL, 0);
+    REGION_COPY(pGCT->pScreen, prgnSrcClip, prgnSrc);
+    REGION_TRANSLATE(pGCT->pScreen, prgnSrcClip, srcx, 0);
+    (*pGCT->funcs->ChangeClip)(pGCT, CT_REGION, prgnSrcClip, 0);
+    ValidateGC((DrawablePtr)pPixmap, pGCT);
+
+    /* Since we know pDraw is always a pixmap, we never need to think
+     * about translation here */
+    for(i = 0; i < h; i++)
+    {
+       ppt->x = 0;
+       ppt++->y = i;
+       *pwidth++ = w + srcx;
+    }
+
+    (*pGCT->ops->SetSpans)((DrawablePtr)pPixmap, pGCT, (char *)pbits,
+                          pptFirst, pwidthFirst, h, TRUE);
+    DEALLOCATE_LOCAL(pwidthFirst);
+    DEALLOCATE_LOCAL(pptFirst);
+
+
+    /* Save current values from the client GC */
+    oldfill = pGC->fillStyle;
+    pStipple = pGC->stipple;
+    if(pStipple)
+        pStipple->refcnt++;
+    oldOrg = pGC->patOrg;
+
+    /* Set a new stipple in the drawable */
+    gcv[0].val = FillStippled;
+    gcv[1].ptr = pPixmap;
+    gcv[2].val = dstx - srcx;
+    gcv[3].val = dsty;
+
+    dixChangeGC(NullClient, pGC,
+             GCFillStyle | GCStipple | GCTileStipXOrigin | GCTileStipYOrigin,
+            NULL, gcv);
+    ValidateGC(pDraw, pGC);
+
+    /* Fill the drawable with the stipple.  This will draw the
+     * foreground color whereever 1 bits are set, leaving everything
+     * with 0 bits untouched.  Note that the part outside the clip
+     * region is all 0s.  */
+    rect.x = dstx;
+    rect.y = dsty;
+    rect.width = w;
+    rect.height = h;
+    (*pGC->ops->PolyFillRect)(pDraw, pGC, 1, &rect);
+
+    /* Invert the tiling pixmap. This sets 0s for 1s and 1s for 0s, only
+     * within the clipping region, the part outside is still all 0s */
+    gcv[0].val = GXinvert;
+    dixChangeGC(NullClient, pGCT, GCFunction, NULL, gcv);
+    ValidateGC((DrawablePtr)pPixmap, pGCT);
+    (*pGCT->ops->CopyArea)((DrawablePtr)pPixmap, (DrawablePtr)pPixmap,
+                          pGCT, 0, 0, w + srcx, h, 0, 0);
+
+    /* Swap foreground and background colors on the GC for the drawable.
+     * Now when we fill the drawable, we will fill in the "Background"
+     * values */
+    oldfg = pGC->fgPixel;
+    gcv[0].val = pGC->bgPixel;
+    gcv[1].val = oldfg;
+    gcv[2].ptr = pPixmap;
+    dixChangeGC(NullClient, pGC, GCForeground | GCBackground | GCStipple,
+               NULL, gcv);
+    ValidateGC(pDraw, pGC);
+    /* PolyFillRect might have bashed the rectangle */
+    rect.x = dstx;
+    rect.y = dsty;
+    rect.width = w;
+    rect.height = h;
+    (*pGC->ops->PolyFillRect)(pDraw, pGC, 1, &rect);
+
+    /* Now put things back */
+    if(pStipple)
+        pStipple->refcnt--;
+    gcv[0].val = oldfg;
+    gcv[1].val = pGC->fgPixel;
+    gcv[2].val = oldfill;
+    gcv[3].ptr = pStipple;
+    gcv[4].val = oldOrg.x;
+    gcv[5].val = oldOrg.y;
+    dixChangeGC(NullClient, pGC, 
+        GCForeground | GCBackground | GCFillStyle | GCStipple | 
+       GCTileStipXOrigin | GCTileStipYOrigin, NULL, gcv);
+
+    ValidateGC(pDraw, pGC);
+    /* put what we hope is a smaller clip region back in the scratch gc */
+    (*pGCT->funcs->ChangeClip)(pGCT, CT_NONE, NULL, 0);
+    FreeScratchGC(pGCT);
+    (*pDraw->pScreen->DestroyPixmap)(pPixmap);
+
+}
+
+/* MICOPYPLANE -- public entry for the CopyPlane request.
+ * strategy: 
+ * First build up a bitmap out of the bits requested 
+ * build a source clip
+ * Use the bitmap we've built up as a Stipple for the destination 
+ */
+RegionPtr
+miCopyPlane(pSrcDrawable, pDstDrawable,
+           pGC, srcx, srcy, width, height, dstx, dsty, bitPlane)
+    DrawablePtr        pSrcDrawable;
+    DrawablePtr                pDstDrawable;
+    GCPtr              pGC;
+    int                srcx, srcy;
+    int                width, height;
+    int                dstx, dsty;
+    unsigned long      bitPlane;
+{
+    unsigned long      *ptile;
+    BoxRec             box;
+    RegionPtr          prgnSrc, prgnExposed;
+
+    /* incorporate the source clip */
+
+    box.x1 = srcx + pSrcDrawable->x;
+    box.y1 = srcy + pSrcDrawable->y;
+    box.x2 = box.x1 + width;
+    box.y2 = box.y1 + height;
+    /* clip to visible drawable */
+    if (box.x1 < pSrcDrawable->x)
+       box.x1 = pSrcDrawable->x;
+    if (box.y1 < pSrcDrawable->y)
+       box.y1 = pSrcDrawable->y;
+    if (box.x2 > pSrcDrawable->x + (int) pSrcDrawable->width)
+       box.x2 = pSrcDrawable->x + (int) pSrcDrawable->width;
+    if (box.y2 > pSrcDrawable->y + (int) pSrcDrawable->height)
+       box.y2 = pSrcDrawable->y + (int) pSrcDrawable->height;
+    if (box.x1 > box.x2)
+       box.x2 = box.x1;
+    if (box.y1 > box.y2)
+       box.y2 = box.y1;
+    prgnSrc = REGION_CREATE(pGC->pScreen, &box, 1);
+
+    if (pSrcDrawable->type != DRAWABLE_PIXMAP) {
+       /* clip to visible drawable */
+
+       if (pGC->subWindowMode == IncludeInferiors)
+       {
+           RegionPtr   clipList = NotClippedByChildren ((WindowPtr) pSrcDrawable);
+           REGION_INTERSECT(pGC->pScreen, prgnSrc, prgnSrc, clipList);
+           REGION_DESTROY(pGC->pScreen, clipList);
+       } else
+           REGION_INTERSECT(pGC->pScreen, prgnSrc, prgnSrc,
+                                      &((WindowPtr)pSrcDrawable)->clipList);
+    }
+
+    box = *REGION_EXTENTS(pGC->pScreen, prgnSrc);
+    REGION_TRANSLATE(pGC->pScreen, prgnSrc, -box.x1, -box.y1);
+
+    if ((box.x2 > box.x1) && (box.y2 > box.y1))
+    {
+       /* minimize the size of the data extracted */
+       /* note that we convert the plane mask bitPlane into a plane number */
+       box.x1 -= pSrcDrawable->x;
+       box.x2 -= pSrcDrawable->x;
+       box.y1 -= pSrcDrawable->y;
+       box.y2 -= pSrcDrawable->y;
+       ptile = miGetPlane(pSrcDrawable, ffs(bitPlane) - 1,
+                          box.x1, box.y1,
+                          box.x2 - box.x1, box.y2 - box.y1,
+                          (unsigned long *) NULL);
+       if (ptile)
+       {
+           miOpqStipDrawable(pDstDrawable, pGC, prgnSrc, ptile, 0,
+                             box.x2 - box.x1, box.y2 - box.y1,
+                             dstx + box.x1 - srcx, dsty + box.y1 - srcy);
+           xfree(ptile);
+       }
+    }
+    prgnExposed = miHandleExposures(pSrcDrawable, pDstDrawable, pGC, srcx, srcy,
+                     width, height, dstx, dsty, bitPlane);
+    REGION_DESTROY(pGC->pScreen, prgnSrc);
+    return prgnExposed;
+}
+
+/* MIGETIMAGE -- public entry for the GetImage Request
+ * We're getting the image into a memory buffer. While we have to use GetSpans
+ * to read a line from the device (since we don't know what that looks like),
+ * we can just write into the destination buffer
+ *
+ * two different strategies are used, depending on whether we're getting the
+ * image in Z format or XY format
+ * Z format:
+ * Line at a time, GetSpans a line into the destination buffer, then if the
+ * planemask is not all ones, we do a SetSpans into a temporary buffer (to get
+ * bits turned off) and then another GetSpans to get stuff back (because
+ * pixmaps are opaque, and we are passed in the memory to write into).  This is
+ * pretty ugly and slow but works.  Life is hard.
+ * XY format:
+ * get the single plane specified in planemask
+ */
+void
+miGetImage(pDraw, sx, sy, w, h, format, planeMask, pDst)
+    DrawablePtr        pDraw;
+    int                        sx, sy, w, h;
+    unsigned int       format;
+    unsigned long      planeMask;
+    char *              pDst;
+{
+    unsigned char      depth;
+    int                        i, linelength, width, srcx, srcy;
+    DDXPointRec                pt;
+    XID                        gcv[2];
+    PixmapPtr          pPixmap = (PixmapPtr)NULL;
+    GCPtr              pGC;
+
+    depth = pDraw->depth;
+    if(format == ZPixmap)
+    {
+       if ( (((1<<depth)-1)&planeMask) != (1<<depth)-1 )
+       {
+           xPoint pt;
+
+           pGC = GetScratchGC(depth, pDraw->pScreen);
+           if (!pGC)
+               return;
+            pPixmap = (*pDraw->pScreen->CreatePixmap)
+                              (pDraw->pScreen, w, 1, depth);
+           if (!pPixmap)
+           {
+               FreeScratchGC(pGC);
+               return;
+           }
+           /*
+            * Clear the pixmap before doing anything else
+            */
+           ValidateGC((DrawablePtr)pPixmap, pGC);
+           pt.x = pt.y = 0;
+           (*pGC->ops->FillSpans)((DrawablePtr)pPixmap, pGC, 1, &pt, &width,
+                                  TRUE);
+           /* alu is already GXCopy */
+           gcv[0] = (XID)planeMask;
+           DoChangeGC(pGC, GCPlaneMask, gcv, 0);
+           ValidateGC((DrawablePtr)pPixmap, pGC);
+       }
+
+        linelength = PixmapBytePad(w, depth);
+       srcx = sx + pDraw->x;
+       srcy = sy + pDraw->y;
+       for(i = 0; i < h; i++)
+       {
+           pt.x = srcx;
+           pt.y = srcy + i;
+           width = w;
+           (*pDraw->pScreen->GetSpans)(pDraw, w, &pt, &width, 1, pDst);
+           if (pPixmap)
+           {
+              pt.x = 0;
+              pt.y = 0;
+              width = w;
+              (*pGC->ops->SetSpans)((DrawablePtr)pPixmap, pGC, pDst,
+                                    &pt, &width, 1, TRUE);
+              (*pDraw->pScreen->GetSpans)((DrawablePtr)pPixmap, w, &pt,
+                                          &width, 1, pDst);
+           }
+           pDst += linelength;
+       }
+       if (pPixmap)
+       {
+           (*pGC->pScreen->DestroyPixmap)(pPixmap);
+           FreeScratchGC(pGC);
+       }
+    }
+    else
+    {
+       (void) miGetPlane(pDraw, ffs(planeMask) - 1, sx, sy, w, h,
+                         (unsigned long *)pDst);
+    }
+}
+
+
+/* MIPUTIMAGE -- public entry for the PutImage request
+ * Here we benefit from knowing the format of the bits pointed to by pImage,
+ * even if we don't know how pDraw represents them.  
+ * Three different strategies are used depending on the format 
+ * XYBitmap Format:
+ *     we just use the Opaque Stipple helper function to cover the destination
+ *     Note that this covers all the planes of the drawable with the 
+ *     foreground color (masked with the GC planemask) where there are 1 bits
+ *     and the background color (masked with the GC planemask) where there are
+ *     0 bits
+ * XYPixmap format:
+ *     what we're called with is a series of XYBitmaps, but we only want 
+ *     each XYPixmap to update 1 plane, instead of updating all of them.
+ *     we set the foreground color to be all 1s and the background to all 0s
+ *     then for each plane, we set the plane mask to only effect that one
+ *     plane and recursive call ourself with the format set to XYBitmap
+ *     (This clever idea courtesy of RGD.)
+ * ZPixmap format:
+ *     This part is simple, just call SetSpans
+ */
+void
+miPutImage(pDraw, pGC, depth, x, y, w, h, leftPad, format, pImage)
+    DrawablePtr                pDraw;
+    GCPtr              pGC;
+    int                depth, x, y, w, h, leftPad;
+    int                        format;
+    char               *pImage;
+{
+    DDXPointPtr                pptFirst, ppt;
+    int                        *pwidthFirst, *pwidth;
+    RegionPtr          prgnSrc;
+    BoxRec             box;
+    unsigned long      oldFg, oldBg;
+    XID                        gcv[3];
+    unsigned long      oldPlanemask;
+    unsigned long      i;
+    long               bytesPer;
+
+    if (!w || !h)
+       return;
+    switch(format)
+    {
+      case XYBitmap:
+
+       box.x1 = 0;
+       box.y1 = 0;
+       box.x2 = w;
+       box.y2 = h;
+       prgnSrc = REGION_CREATE(pGC->pScreen, &box, 1);
+
+        miOpqStipDrawable(pDraw, pGC, prgnSrc, (unsigned long *) pImage,
+                         leftPad, w, h, x, y);
+       REGION_DESTROY(pGC->pScreen, prgnSrc);
+       break;
+
+      case XYPixmap:
+       depth = pGC->depth;
+       oldPlanemask = pGC->planemask;
+       oldFg = pGC->fgPixel;
+       oldBg = pGC->bgPixel;
+       gcv[0] = (XID)~0;
+       gcv[1] = (XID)0;
+       DoChangeGC(pGC, GCForeground | GCBackground, gcv, 0);
+       bytesPer = (long)h * BitmapBytePad(w + leftPad);
+
+       for (i = 1 << (depth-1); i != 0; i >>= 1, pImage += bytesPer)
+       {
+           if (i & oldPlanemask)
+           {
+               gcv[0] = (XID)i;
+               DoChangeGC(pGC, GCPlaneMask, gcv, 0);
+               ValidateGC(pDraw, pGC);
+               (*pGC->ops->PutImage)(pDraw, pGC, 1, x, y, w, h, leftPad,
+                                XYBitmap, (char *)pImage);
+           }
+       }
+       gcv[0] = (XID)oldPlanemask;
+       gcv[1] = (XID)oldFg;
+       gcv[2] = (XID)oldBg;
+       DoChangeGC(pGC, GCPlaneMask | GCForeground | GCBackground, gcv, 0);
+       break;
+
+      case ZPixmap:
+       ppt = pptFirst = (DDXPointPtr)ALLOCATE_LOCAL(h * sizeof(DDXPointRec));
+       pwidth = pwidthFirst = (int *)ALLOCATE_LOCAL(h * sizeof(int));
+       if(!pptFirst || !pwidthFirst)
+        {
+          if (pwidthFirst)
+               DEALLOCATE_LOCAL(pwidthFirst);
+           if (pptFirst)
+               DEALLOCATE_LOCAL(pptFirst);
+           return;
+        }
+       if (pGC->miTranslate)
+       {
+           x += pDraw->x;
+           y += pDraw->y;
+       }
+
+       for(i = 0; i < h; i++)
+       {
+           ppt->x = x;
+           ppt->y = y + i;
+           ppt++;
+           *pwidth++ = w;
+       }
+
+       (*pGC->ops->SetSpans)(pDraw, pGC, (char *)pImage, pptFirst,
+                             pwidthFirst, h, TRUE);
+       DEALLOCATE_LOCAL(pwidthFirst);
+       DEALLOCATE_LOCAL(pptFirst);
+       break;
+    }
+}
diff --git a/Xserver/programs/Xserver/mi/mibstore.c b/Xserver/programs/Xserver/mi/mibstore.c
new file mode 100644 (file)
index 0000000..935f758
--- /dev/null
@@ -0,0 +1,3824 @@
+/* $XConsortium: mibstore.c,v 5.63 94/10/21 20:25:08 dpw Exp $ */
+/***********************************************************
+
+Copyright (c) 1987  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+
+Copyright 1987 by the Regents of the University of California
+
+                        All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and its
+documentation for any purpose and without fee is hereby granted, provided
+that the above copyright notice appear in all copies and that both that
+copyright notice and this permission notice appear in supporting
+documentation, and that the name X Consortium not be used in advertising or publicity
+pertaining to distribution of the software without specific, written prior
+permission.  
+
+The University of California makes no representations about the suitability
+of this software for any purpose.  It is provided "as is" without express or
+implied warranty.
+
+******************************************************************/
+
+#define NEED_EVENTS
+#include "X.h"
+#include "Xmd.h"
+#include "Xproto.h"
+#include "misc.h"
+#include "regionstr.h"
+#include "scrnintstr.h"
+#include "gcstruct.h"
+#include "extnsionst.h"
+#include "windowstr.h"
+#include "pixmapstr.h"
+#include "fontstruct.h"
+#include "dixfontstr.h"
+#include "dixstruct.h"         /* For requestingClient */
+#include "mi.h"
+#include "mibstorest.h"
+
+/*
+ * When the server fails to allocate a backing store pixmap, if you want
+ * it to dynamically retry to allocate backing store on every subsequent
+ * graphics op, you can enable BSEAGER; otherwise, backing store will be
+ * disabled on the window until it is unmapped and then remapped.
+ */
+/* #define BSEAGER */
+
+/*-
+ * NOTES ON USAGE:
+ *
+ * The functions in this file implement a machine-independent backing-store
+ * scheme. To use it, the output library must do the following:
+ *     - Provide a SaveAreas function that takes a destination pixmap, a
+ *         region of the areas to save (in the pixmap's coordinate system)
+ *         and the screen origin of the region. It should copy the areas from
+ *         the screen into the pixmap.
+ *     - Provide a RestoreAreas function that takes a source pixmap, a region
+ *         of the areas to restore (in the screen's coordinate system) and the
+ *         origin of the pixmap on the screen. It should copy the areas from
+ *         the pixmap into the screen.
+ *     - Provide a SetClipmaskRgn function that takes a gc and a region
+ *         and merges the region into any CT_PIXMAP client clip that
+ *         is specified in the GC.  This routine is only needed if
+ *         miValidateBackingStore will see CT_PIXMAP clip lists; not
+ *         true for any of the sample servers (which convert the PIXMAP
+ *         clip lists into CT_REGION clip lists; an expensive but simple
+ *         to code option).
+ *     - The function placed in a window's ClearToBackground vector must call
+ *         pScreen->ClearBackingStore with the window, followed by
+ *         the window-relative x and y coordinates, followed by the width and
+ *         height of the area to be cleared, followed by the generateExposures
+ *         flag. This has been taken care of in miClearToBackground.
+ *     - Whatever determines GraphicsExpose events for the CopyArea and
+ *         CopyPlane requests should call pWin->backStorage->ExposeCopy
+ *         with the source and destination drawables, the GC used, a source-
+ *         window-relative region of exposed areas, the source and destination
+ *         coordinates and the bitplane copied, if CopyPlane, or 0, if
+ *         CopyArea.
+ *
+ * JUSTIFICATION
+ *    This is a cross between saving everything and just saving the
+ * obscued areas (as in Pike's layers.)  This method has the advantage
+ * of only doing each output operation once per pixel, visible or
+ * invisible, and avoids having to do all the crufty storage
+ * management of keeping several separate rectangles.  Since the
+ * ddx layer ouput primitives are required to draw through clipping
+ * rectangles anyway, sending multiple drawing requests for each of
+ * several rectangles isn't necessary.  (Of course, it could be argued
+ * that the ddx routines should just take one rectangle each and
+ * get called multiple times, but that would make taking advantage of
+ * smart hardware harder, and probably be slower as well.)
+ */
+
+#define SETUP_BACKING_TERSE(pGC) \
+    miBSGCPtr  pGCPrivate = (miBSGCPtr)(pGC)->devPrivates[miBSGCIndex].ptr; \
+    GCFuncs    *oldFuncs = pGC->funcs;
+
+#define SETUP_BACKING(pDrawable,pGC) \
+    miBSWindowPtr pBackingStore = \
+       (miBSWindowPtr)((WindowPtr)(pDrawable))->backStorage; \
+    DrawablePtr          pBackingDrawable = (DrawablePtr) \
+        pBackingStore->pBackingPixmap; \
+    SETUP_BACKING_TERSE(pGC) \
+    GCPtr      pBackingGC = pGCPrivate->pBackingGC;
+
+#define PROLOGUE(pGC) { \
+    pGC->ops = pGCPrivate->wrapOps;\
+    pGC->funcs = pGCPrivate->wrapFuncs; \
+    }
+
+#define EPILOGUE(pGC) { \
+    pGCPrivate->wrapOps = (pGC)->ops; \
+    (pGC)->ops = &miBSGCOps; \
+    (pGC)->funcs = oldFuncs; \
+    }
+   
+static void        miCreateBSPixmap();
+static void        miDestroyBSPixmap();
+static void        miTileVirtualBS();
+static void        miBSAllocate(), miBSFree();
+static Bool        miBSCreateGCPrivate ();
+static void        miBSClearBackingRegion ();
+
+#define MoreCopy0 ;
+#define MoreCopy2 *dstCopy++ = *srcCopy++; *dstCopy++ = *srcCopy++;
+#define MoreCopy4 MoreCopy2 MoreCopy2
+
+#define copyData(src,dst,n,morecopy) \
+{ \
+    register short *srcCopy = (short *)(src); \
+    register short *dstCopy = (short *)(dst); \
+    register int i; \
+    register int bsx = pBackingStore->x; \
+    register int bsy = pBackingStore->y; \
+    for (i = n; --i >= 0; ) \
+    { \
+       *dstCopy++ = *srcCopy++ - bsx; \
+       *dstCopy++ = *srcCopy++ - bsy; \
+       morecopy \
+    } \
+}
+
+#define copyPoints(src,dst,n,mode) \
+if (mode == CoordModeOrigin) \
+{ \
+    copyData(src,dst,n,MoreCopy0); \
+} \
+else \
+{ \
+    memmove((char *)(dst), (char *)(src), (n) << 2); \
+    *((short *)(dst)) -= pBackingStore->x; \
+    *((short *)(dst) + 1) -= pBackingStore->y; \
+}
+
+/*
+ * wrappers for screen funcs
+ */
+
+static int  miBSScreenIndex;
+static unsigned long miBSGeneration = 0;
+
+static Bool        miBSCloseScreen();
+static void        miBSGetImage();
+static void        miBSGetSpans();
+static Bool        miBSChangeWindowAttributes();
+static Bool        miBSCreateGC();
+static Bool        miBSDestroyWindow();
+
+/*
+ * backing store screen functions
+ */
+
+static void        miBSSaveDoomedAreas();
+static RegionPtr    miBSRestoreAreas();
+static void        miBSExposeCopy();
+static RegionPtr    miBSTranslateBackingStore(), miBSClearBackingStore();
+static void        miBSDrawGuarantee();
+
+/*
+ * wrapper vectors for GC funcs and ops
+ */
+
+static int  miBSGCIndex;
+
+static void miBSValidateGC (), miBSCopyGC (),      miBSDestroyGC();
+static void miBSChangeGC();
+static void miBSChangeClip(),  miBSDestroyClip(),  miBSCopyClip();
+
+static GCFuncs miBSGCFuncs = {
+    miBSValidateGC,
+    miBSChangeGC,
+    miBSCopyGC,
+    miBSDestroyGC,
+    miBSChangeClip,
+    miBSDestroyClip,
+    miBSCopyClip,
+};
+
+static void        miBSFillSpans(),    miBSSetSpans(),     miBSPutImage();
+static RegionPtr    miBSCopyArea(),    miBSCopyPlane();
+static void        miBSPolyPoint(),    miBSPolylines(),    miBSPolySegment();
+static void        miBSPolyRectangle(),miBSPolyArc(),      miBSFillPolygon();
+static void        miBSPolyFillRect(), miBSPolyFillArc();
+static int         miBSPolyText8(),    miBSPolyText16();
+static void        miBSImageText8(),   miBSImageText16();
+static void        miBSImageGlyphBlt(),miBSPolyGlyphBlt();
+static void        miBSPushPixels();
+#ifdef NEED_LINEHELPER
+static void        miBSLineHelper();
+#endif
+
+static GCOps miBSGCOps = {
+    miBSFillSpans,     miBSSetSpans,       miBSPutImage,       
+    miBSCopyArea,      miBSCopyPlane,      miBSPolyPoint,
+    miBSPolylines,     miBSPolySegment,    miBSPolyRectangle,
+    miBSPolyArc,       miBSFillPolygon,    miBSPolyFillRect,
+    miBSPolyFillArc,   miBSPolyText8,      miBSPolyText16,
+    miBSImageText8,    miBSImageText16,    miBSImageGlyphBlt,
+    miBSPolyGlyphBlt,  miBSPushPixels
+#ifdef NEED_LINEHELPER
+    , miBSLineHelper
+#endif
+};
+
+#define FUNC_PROLOGUE(pGC, pPriv) \
+    ((pGC)->funcs = pPriv->wrapFuncs),\
+    ((pGC)->ops = pPriv->wrapOps)
+
+#define FUNC_EPILOGUE(pGC, pPriv) \
+    ((pGC)->funcs = &miBSGCFuncs),\
+    ((pGC)->ops = &miBSGCOps)
+
+/*
+ * every GC in the server is initially wrapped with these
+ * "cheap" functions.  This allocates no memory and is used
+ * to discover GCs used with windows which have backing
+ * store enabled
+ */
+
+static void miBSCheapValidateGC(),  miBSCheapCopyGC(), miBSCheapDestroyGC();
+static void miBSCheapChangeGC ();
+static void miBSCheapChangeClip(),  miBSCheapDestroyClip();
+static void miBSCheapCopyClip();
+
+static GCFuncs miBSCheapGCFuncs = {
+    miBSCheapValidateGC,
+    miBSCheapChangeGC,
+    miBSCheapCopyGC,
+    miBSCheapDestroyGC,
+    miBSCheapChangeClip,
+    miBSCheapDestroyClip,
+    miBSCheapCopyClip,
+};
+
+#define CHEAP_FUNC_PROLOGUE(pGC) \
+    ((pGC)->funcs = (GCFuncs *) (pGC)->devPrivates[miBSGCIndex].ptr)
+
+#define CHEAP_FUNC_EPILOGUE(pGC) \
+    ((pGC)->funcs = &miBSCheapGCFuncs)
+
+/*
+ * called from device screen initialization proc.  Gets a GCPrivateIndex
+ * and wraps appropriate per-screen functions
+ */
+
+void
+miInitializeBackingStore (pScreen, funcs)
+    ScreenPtr  pScreen;
+    miBSFuncPtr        funcs;
+{
+    miBSScreenPtr    pScreenPriv;
+
+    if (miBSGeneration != serverGeneration)
+    {
+       miBSScreenIndex = AllocateScreenPrivateIndex ();
+       if (miBSScreenIndex < 0)
+           return;
+       miBSGCIndex = AllocateGCPrivateIndex ();
+       miBSGeneration = serverGeneration;
+    }
+    if (!AllocateGCPrivate(pScreen, miBSGCIndex, 0))
+       return;
+    pScreenPriv = (miBSScreenPtr) xalloc (sizeof (miBSScreenRec));
+    if (!pScreenPriv)
+       return;
+
+    pScreenPriv->CloseScreen = pScreen->CloseScreen;
+    pScreenPriv->GetImage = pScreen->GetImage;
+    pScreenPriv->GetSpans = pScreen->GetSpans;
+    pScreenPriv->ChangeWindowAttributes = pScreen->ChangeWindowAttributes;
+    pScreenPriv->CreateGC = pScreen->CreateGC;
+    pScreenPriv->DestroyWindow = pScreen->DestroyWindow;
+    pScreenPriv->funcs = funcs;
+
+    pScreen->CloseScreen = miBSCloseScreen;
+    pScreen->GetImage = miBSGetImage;
+    pScreen->GetSpans = miBSGetSpans;
+    pScreen->ChangeWindowAttributes = miBSChangeWindowAttributes;
+    pScreen->CreateGC = miBSCreateGC;
+    pScreen->DestroyWindow = miBSDestroyWindow;
+
+    pScreen->SaveDoomedAreas = miBSSaveDoomedAreas;
+    pScreen->RestoreAreas = miBSRestoreAreas;
+    pScreen->ExposeCopy = miBSExposeCopy;
+    pScreen->TranslateBackingStore = miBSTranslateBackingStore;
+    pScreen->ClearBackingStore = miBSClearBackingStore;
+    pScreen->DrawGuarantee = miBSDrawGuarantee;
+
+    pScreen->devPrivates[miBSScreenIndex].ptr = (pointer) pScreenPriv;
+}
+
+/*
+ * Screen function wrappers
+ */
+
+#define SCREEN_PROLOGUE(pScreen, field)\
+  ((pScreen)->field = \
+   ((miBSScreenPtr) \
+    (pScreen)->devPrivates[miBSScreenIndex].ptr)->field)
+
+#define SCREEN_EPILOGUE(pScreen, field, wrapper)\
+    ((pScreen)->field = wrapper)
+
+/*
+ * CloseScreen wrapper -- unwrap everything, free the private data
+ * and call the wrapped function
+ */
+
+static Bool
+miBSCloseScreen (i, pScreen)
+    int                i;
+    ScreenPtr  pScreen;
+{
+    miBSScreenPtr   pScreenPriv;
+
+    pScreenPriv = (miBSScreenPtr) pScreen->devPrivates[miBSScreenIndex].ptr;
+
+    pScreen->CloseScreen = pScreenPriv->CloseScreen;
+    pScreen->GetImage = pScreenPriv->GetImage;
+    pScreen->GetSpans = pScreenPriv->GetSpans;
+    pScreen->ChangeWindowAttributes = pScreenPriv->ChangeWindowAttributes;
+    pScreen->CreateGC = pScreenPriv->CreateGC;
+
+    xfree ((pointer) pScreenPriv);
+
+    return (*pScreen->CloseScreen) (i, pScreen);
+}
+
+static void miBSFillVirtualBits();
+
+static void
+miBSGetImage (pDrawable, sx, sy, w, h, format, planemask, pdstLine)
+    DrawablePtr            pDrawable;
+    int                    sx, sy, w, h;
+    unsigned int    format;
+    unsigned long   planemask;
+    char           *pdstLine;
+{
+    ScreenPtr              pScreen = pDrawable->pScreen;
+    BoxRec                 bounds;
+    unsigned char          depth;
+    
+    SCREEN_PROLOGUE (pScreen, GetImage);
+
+    if (pDrawable->type != DRAWABLE_PIXMAP &&
+       ((WindowPtr) pDrawable)->visibility != VisibilityUnobscured)
+    {
+       PixmapPtr       pPixmap;
+       miBSWindowPtr   pWindowPriv;
+       GCPtr           pGC;
+       WindowPtr       pWin, pSrcWin;
+       int             xoff, yoff;
+       RegionRec       Remaining;
+       RegionRec       Border;
+       RegionRec       Inside;
+       BoxPtr          pBox;
+       int             n;
+
+       pWin = (WindowPtr) pDrawable;
+       pPixmap = 0;
+       depth = pDrawable->depth;
+       bounds.x1 = sx + pDrawable->x;
+       bounds.y1 = sy + pDrawable->y;
+       bounds.x2 = bounds.x1 + w;
+       bounds.y2 = bounds.y1 + h;
+       REGION_INIT(pScreen, &Remaining, &bounds, 0);
+       for (;;)
+       {
+           bounds.x1 = sx + pDrawable->x - pWin->drawable.x;
+           bounds.y1 = sy + pDrawable->y - pWin->drawable.y;
+           bounds.x2 = bounds.x1 + w;
+           bounds.y2 = bounds.y1 + h;
+           if (pWin->viewable && pWin->backStorage &&
+               pWin->drawable.depth == depth &&
+               (RECT_IN_REGION(pScreen, &(pWindowPriv =
+                   (miBSWindowPtr) pWin->backStorage)->SavedRegion,
+                   &bounds) != rgnOUT ||
+                RECT_IN_REGION(pScreen, &Remaining,
+                 REGION_EXTENTS(pScreen, &pWin->borderSize)) != rgnOUT))
+           {
+               if (!pPixmap)
+               {
+                   XID subWindowMode = IncludeInferiors;
+                   int x, y;
+
+                   pPixmap = (*pScreen->CreatePixmap) (pScreen, w, h, depth);
+                   if (!pPixmap)
+                       goto punt;
+                   pGC = GetScratchGC (depth, pScreen);
+                   if (!pGC)
+                   {
+                       (*pScreen->DestroyPixmap) (pPixmap);
+                       goto punt;
+                   }
+                   ChangeGC (pGC, GCSubwindowMode, &subWindowMode);
+                   ValidateGC ((DrawablePtr)pPixmap, pGC);
+                   REGION_INIT(pScreen, &Border, NullBox, 0);
+                   REGION_INIT(pScreen, &Inside, NullBox, 0);
+                   pSrcWin = (WindowPtr) pDrawable;
+                   x = sx;
+                   y = sy;
+                   if (pSrcWin->parent)
+                   {
+                       x += pSrcWin->origin.x;
+                       y += pSrcWin->origin.y;
+                       pSrcWin = pSrcWin->parent;
+                   }
+                   (*pGC->ops->CopyArea) ((DrawablePtr)pSrcWin,
+                                           (DrawablePtr)pPixmap, pGC,
+                                           x, y, w, h,
+                                           0, 0);
+                   REGION_SUBTRACT(pScreen, &Remaining, &Remaining,
+                                   &((WindowPtr) pDrawable)->borderClip);
+               }
+
+               REGION_INTERSECT(pScreen, &Inside, &Remaining, &pWin->winSize);
+               REGION_TRANSLATE(pScreen, &Inside,
+                                            -pWin->drawable.x,
+                                            -pWin->drawable.y);
+               REGION_INTERSECT(pScreen, &Inside, &Inside,
+                                &pWindowPriv->SavedRegion);
+
+               /* offset of sub-window in GetImage pixmap */
+               xoff = pWin->drawable.x - pDrawable->x - sx;
+               yoff = pWin->drawable.y - pDrawable->y - sy;
+
+               if (REGION_NUM_RECTS(&Inside) > 0)
+               {
+                   switch (pWindowPriv->status)
+                   {
+                   case StatusContents:
+                       pBox = REGION_RECTS(&Inside);
+                       for (n = REGION_NUM_RECTS(&Inside); --n >= 0;)
+                       {
+                           (*pGC->ops->CopyArea) (
+                               (DrawablePtr)pWindowPriv->pBackingPixmap,
+                                                  (DrawablePtr)pPixmap, pGC,
+                                                  pBox->x1 - pWindowPriv->x,
+                                                  pBox->y1 - pWindowPriv->y,
+                                                  pBox->x2 - pBox->x1,
+                                                  pBox->y2 - pBox->y1,
+                                                  pBox->x1 + xoff,
+                                                  pBox->y1 + yoff);
+                           ++pBox;
+                       }
+                       break;
+                   case StatusVirtual:
+                   case StatusVDirty:
+                       if (pWindowPriv->backgroundState == BackgroundPixmap ||
+                           pWindowPriv->backgroundState == BackgroundPixel)
+                       miBSFillVirtualBits ((DrawablePtr) pPixmap, pGC, &Inside,
+                                           xoff, yoff,
+                                           (int) pWindowPriv->backgroundState,
+                                           pWindowPriv->background, ~0L);
+                       break;
+                   }
+               }
+               REGION_SUBTRACT(pScreen, &Border, &pWin->borderSize,
+                               &pWin->winSize);
+               REGION_INTERSECT(pScreen, &Border, &Border, &Remaining);
+               if (REGION_NUM_RECTS(&Border) > 0)
+               {
+                   REGION_TRANSLATE(pScreen, &Border, -pWin->drawable.x,
+                                                 -pWin->drawable.y);
+                   miBSFillVirtualBits ((DrawablePtr) pPixmap, pGC, &Border,
+                                       xoff, yoff,
+                                       pWin->borderIsPixel ? (int)BackgroundPixel : (int)BackgroundPixmap,
+                                       pWin->border, ~0L);
+               }
+           }
+
+           if (pWin->viewable && pWin->firstChild)
+               pWin = pWin->firstChild;
+           else
+           {
+               while (!pWin->nextSib && pWin != (WindowPtr) pDrawable)
+                   pWin = pWin->parent;
+               if (pWin == (WindowPtr) pDrawable)
+                   break;
+               pWin = pWin->nextSib;
+           }
+       }
+
+       REGION_UNINIT(pScreen, &Remaining);
+
+       if (pPixmap)
+       {
+           REGION_UNINIT(pScreen, &Border);
+           REGION_UNINIT(pScreen, &Inside);
+           (*pScreen->GetImage) ((DrawablePtr) pPixmap,
+               0, 0, w, h, format, planemask, pdstLine);
+           (*pScreen->DestroyPixmap) (pPixmap);
+           FreeScratchGC (pGC);
+       }
+       else
+       {
+           goto punt;
+       }
+    }
+    else
+    {
+punt:  ;
+       (*pScreen->GetImage) (pDrawable, sx, sy, w, h,
+                             format, planemask, pdstLine);
+    }
+
+    SCREEN_EPILOGUE (pScreen, GetImage, miBSGetImage);
+}
+
+static void
+miBSGetSpans (pDrawable, wMax, ppt, pwidth, nspans, pdstStart)
+    DrawablePtr        pDrawable;
+    int                wMax;
+    DDXPointPtr        ppt;
+    int                *pwidth;
+    int                nspans;
+    char       *pdstStart;
+{
+    ScreenPtr              pScreen = pDrawable->pScreen;
+    BoxRec                 bounds;
+    int                            i;
+    WindowPtr              pWin;
+    int                            dx, dy;
+    
+    SCREEN_PROLOGUE (pScreen, GetSpans);
+
+    if (pDrawable->type != DRAWABLE_PIXMAP && ((WindowPtr) pDrawable)->backStorage)
+    {
+       PixmapPtr       pPixmap;
+       miBSWindowPtr   pWindowPriv;
+       GCPtr           pGC;
+
+       pWin = (WindowPtr) pDrawable;
+       pWindowPriv = (miBSWindowPtr) pWin->backStorage;
+       pPixmap = pWindowPriv->pBackingPixmap;
+
+       bounds.x1 = ppt->x;
+       bounds.y1 = ppt->y;
+       bounds.x2 = bounds.x1 + *pwidth;
+       bounds.y2 = ppt->y;
+       for (i = 0; i < nspans; i++)
+       {
+           if (ppt[i].x < bounds.x1)
+               bounds.x1 = ppt[i].x;
+           if (ppt[i].x + pwidth[i] > bounds.x2)
+               bounds.x2 = ppt[i].x + pwidth[i];
+           if (ppt[i].y < bounds.y1)
+               bounds.y1 = ppt[i].y;
+           else if (ppt[i].y > bounds.y2)
+               bounds.y2 = ppt[i].y;
+       }
+    
+       switch (RECT_IN_REGION(pScreen, &pWindowPriv->SavedRegion, &bounds))
+       {
+       case rgnPART:
+           if (!pPixmap)
+           {
+               miCreateBSPixmap (pWin, NullBox);
+               if (!(pPixmap = pWindowPriv->pBackingPixmap))
+                   break;
+           }
+           pWindowPriv->status = StatusNoPixmap;
+           pGC = GetScratchGC(pPixmap->drawable.depth,
+                              pPixmap->drawable.pScreen);
+           if (pGC)
+           {
+               ValidateGC ((DrawablePtr) pPixmap, pGC);
+               (*pGC->ops->CopyArea)
+                   (pDrawable, (DrawablePtr) pPixmap, pGC,
+                   bounds.x1, bounds.y1,
+                   bounds.x2 - bounds.x1, bounds.y2 - bounds.y1,
+                   bounds.x1 + pPixmap->drawable.x - pWin->drawable.x -
+                    pWindowPriv->x,
+                   bounds.y1 + pPixmap->drawable.y - pWin->drawable.y -
+                    pWindowPriv->y);
+               FreeScratchGC(pGC);
+           }
+           pWindowPriv->status = StatusContents;
+           /* fall through */
+       case rgnIN:
+           if (!pPixmap)
+           {
+               miCreateBSPixmap (pWin, NullBox);
+               if (!(pPixmap = pWindowPriv->pBackingPixmap))
+                   break;
+           }
+           dx = pPixmap->drawable.x - pWin->drawable.x - pWindowPriv->x;
+           dy = pPixmap->drawable.y - pWin->drawable.y - pWindowPriv->y;
+           for (i = 0; i < nspans; i++)
+           {
+               ppt[i].x += dx;
+               ppt[i].y += dy;
+           }
+           (*pScreen->GetSpans) ((DrawablePtr) pPixmap, wMax, ppt, pwidth,
+                                 nspans, pdstStart);
+           break;
+       case rgnOUT:
+           (*pScreen->GetSpans) (pDrawable, wMax, ppt, pwidth, nspans,
+                                 pdstStart);
+           break;
+       }
+    }
+    else
+    {
+       (*pScreen->GetSpans) (pDrawable, wMax, ppt, pwidth, nspans, pdstStart);
+    }
+
+    SCREEN_EPILOGUE (pScreen, GetSpans, miBSGetSpans);
+}
+
+static Bool
+miBSChangeWindowAttributes (pWin, mask)
+    WindowPtr      pWin;
+    unsigned long   mask;
+{
+    ScreenPtr  pScreen;
+    Bool       ret;
+
+    pScreen = pWin->drawable.pScreen;
+
+    SCREEN_PROLOGUE (pScreen, ChangeWindowAttributes);
+
+    ret = (*pScreen->ChangeWindowAttributes) (pWin, mask);
+
+    if (ret && (mask & CWBackingStore))
+    {
+       if (pWin->backingStore != NotUseful || pWin->DIXsaveUnder)
+           miBSAllocate (pWin);
+       else
+           miBSFree (pWin);
+    }
+
+    SCREEN_EPILOGUE (pScreen, ChangeWindowAttributes, miBSChangeWindowAttributes);
+
+    return ret;
+}
+
+/*
+ * GC Create wrapper.  Set up the cheap GC func wrappers to track
+ * GC validation on BackingStore windows
+ */
+
+static Bool
+miBSCreateGC (pGC)
+    GCPtr   pGC;
+{
+    ScreenPtr  pScreen = pGC->pScreen;
+    Bool       ret;
+
+    SCREEN_PROLOGUE (pScreen, CreateGC);
+    
+    if ( (ret = (*pScreen->CreateGC) (pGC)) )
+    {
+       pGC->devPrivates[miBSGCIndex].ptr = (pointer) pGC->funcs;
+       pGC->funcs = &miBSCheapGCFuncs;
+    }
+
+    SCREEN_EPILOGUE (pScreen, CreateGC, miBSCreateGC);
+
+    return ret;
+}
+
+static Bool
+miBSDestroyWindow (pWin)
+    WindowPtr  pWin;
+{
+    ScreenPtr  pScreen = pWin->drawable.pScreen;
+    Bool       ret;
+
+    SCREEN_PROLOGUE (pScreen, DestroyWindow);
+    
+    ret = (*pScreen->DestroyWindow) (pWin);
+
+    miBSFree (pWin);
+
+    SCREEN_EPILOGUE (pScreen, DestroyWindow, miBSDestroyWindow);
+
+    return ret;
+}
+
+/*
+ * cheap GC func wrappers.  Simply track validation on windows
+ * with backing store to enable the real func/op wrappers
+ */
+
+static void
+miBSCheapValidateGC (pGC, stateChanges, pDrawable)
+    GCPtr          pGC;
+    unsigned long   stateChanges;
+    DrawablePtr            pDrawable;
+{
+    CHEAP_FUNC_PROLOGUE (pGC);
+    
+    if (pDrawable->type != DRAWABLE_PIXMAP &&
+        ((WindowPtr) pDrawable)->backStorage != NULL &&
+       miBSCreateGCPrivate (pGC))
+    {
+       (*pGC->funcs->ValidateGC) (pGC, stateChanges, pDrawable);
+    }
+    else
+    {
+       (*pGC->funcs->ValidateGC) (pGC, stateChanges, pDrawable);
+
+       /* rewrap funcs as Validate may have changed them */
+       pGC->devPrivates[miBSGCIndex].ptr = (pointer) pGC->funcs;
+
+       CHEAP_FUNC_EPILOGUE (pGC);
+    }
+}
+
+static void
+miBSCheapChangeGC (pGC, mask)
+    GCPtr   pGC;
+    unsigned long   mask;
+{
+    CHEAP_FUNC_PROLOGUE (pGC);
+
+    (*pGC->funcs->ChangeGC) (pGC, mask);
+
+    CHEAP_FUNC_EPILOGUE (pGC);
+}
+
+static void
+miBSCheapCopyGC (pGCSrc, mask, pGCDst)
+    GCPtr   pGCSrc, pGCDst;
+    unsigned long   mask;
+{
+    CHEAP_FUNC_PROLOGUE (pGCDst);
+
+    (*pGCDst->funcs->CopyGC) (pGCSrc, mask, pGCDst);
+
+    CHEAP_FUNC_EPILOGUE (pGCDst);
+}
+
+static void
+miBSCheapDestroyGC (pGC)
+    GCPtr   pGC;
+{
+    CHEAP_FUNC_PROLOGUE (pGC);
+
+    (*pGC->funcs->DestroyGC) (pGC);
+
+    /* leave it unwrapped */
+}
+
+static void
+miBSCheapChangeClip (pGC, type, pvalue, nrects)
+    GCPtr   pGC;
+    int                type;
+    pointer    pvalue;
+    int                nrects;
+{
+    CHEAP_FUNC_PROLOGUE (pGC);
+
+    (*pGC->funcs->ChangeClip) (pGC, type, pvalue, nrects);
+
+    CHEAP_FUNC_EPILOGUE (pGC);
+}
+
+static void
+miBSCheapCopyClip(pgcDst, pgcSrc)
+    GCPtr pgcDst, pgcSrc;
+{
+    CHEAP_FUNC_PROLOGUE (pgcDst);
+
+    (* pgcDst->funcs->CopyClip)(pgcDst, pgcSrc);
+
+    CHEAP_FUNC_EPILOGUE (pgcDst);
+}
+
+static void
+miBSCheapDestroyClip(pGC)
+    GCPtr      pGC;
+{
+    CHEAP_FUNC_PROLOGUE (pGC);
+
+    (* pGC->funcs->DestroyClip)(pGC);
+
+    CHEAP_FUNC_EPILOGUE (pGC);
+}
+
+/*
+ * create the full func/op wrappers for a GC
+ */
+
+static Bool
+miBSCreateGCPrivate (pGC)
+    GCPtr   pGC;
+{
+    miBSGCRec  *pPriv;
+
+    pPriv = (miBSGCRec *) xalloc (sizeof (miBSGCRec));
+    if (!pPriv)
+       return FALSE;
+    pPriv->pBackingGC = NULL;
+    pPriv->guarantee = GuaranteeNothing;
+    pPriv->serialNumber = 0;
+    pPriv->stateChanges = (1 << (GCLastBit + 1)) - 1;
+    pPriv->wrapOps = pGC->ops;
+    pPriv->wrapFuncs = pGC->funcs;
+    pGC->funcs = &miBSGCFuncs;
+    pGC->ops = &miBSGCOps;
+    pGC->devPrivates[miBSGCIndex].ptr = (pointer) pPriv;
+    return TRUE;
+}
+
+static void
+miBSDestroyGCPrivate (pGC)
+    GCPtr   pGC;
+{
+    miBSGCRec  *pPriv;
+
+    pPriv = (miBSGCRec *) pGC->devPrivates[miBSGCIndex].ptr;
+    if (pPriv)
+    {
+       pGC->devPrivates[miBSGCIndex].ptr = (pointer) pPriv->wrapFuncs;
+       pGC->funcs = &miBSCheapGCFuncs;
+       pGC->ops = pPriv->wrapOps;
+       if (pPriv->pBackingGC)
+           FreeGC (pPriv->pBackingGC, (GContext) 0);
+       xfree ((pointer) pPriv);
+    }
+}
+
+/*
+ * GC ops -- wrap each GC operation with our own function
+ */
+
+/*-
+ *-----------------------------------------------------------------------
+ * miBSFillSpans --
+ *     Perform a FillSpans, routing output to backing-store as needed.
+ *
+ * Results:
+ *     None.
+ *
+ * Side Effects:
+ *
+ *-----------------------------------------------------------------------
+ */
+static void
+miBSFillSpans(pDrawable, pGC, nInit, pptInit, pwidthInit, fSorted)
+    DrawablePtr pDrawable;
+    GCPtr      pGC;
+    int                nInit;                  /* number of spans to fill */
+    DDXPointPtr pptInit;               /* pointer to list of start points */
+    int                *pwidthInit;            /* pointer to list of n widths */
+    int        fSorted;
+{
+    DDXPointPtr        pptCopy, pptReset;
+    int        *pwidthCopy;
+    SETUP_BACKING (pDrawable, pGC);
+
+    PROLOGUE(pGC);
+
+    pptCopy = (DDXPointPtr)ALLOCATE_LOCAL(nInit*sizeof(DDXPointRec));
+    pwidthCopy=(int *)ALLOCATE_LOCAL(nInit*sizeof(int));
+    if (pptCopy && pwidthCopy)
+    {
+       copyData(pptInit, pptCopy, nInit, MoreCopy0);
+       memmove((char *)pwidthCopy,(char *)pwidthInit,nInit*sizeof(int));
+
+       (* pGC->ops->FillSpans)(pDrawable, pGC, nInit, pptInit,
+                            pwidthInit, fSorted);
+       if (pGC->miTranslate)
+       {
+           int dx, dy;
+           int nReset;
+
+           pptReset = pptCopy;
+           dx = pDrawable->x - pBackingDrawable->x;
+           dy = pDrawable->y - pBackingDrawable->y;
+           nReset = nInit;
+           while (nReset--)
+           {
+               pptReset->x -= dx;
+               pptReset->y -= dy;
+               ++pptReset;
+           }
+       }
+       (* pBackingGC->ops->FillSpans)(pBackingDrawable,
+                                 pBackingGC, nInit, pptCopy, pwidthCopy,
+                                 fSorted);
+    }
+    if (pwidthCopy) DEALLOCATE_LOCAL(pwidthCopy);
+    if (pptCopy) DEALLOCATE_LOCAL(pptCopy);
+
+    EPILOGUE (pGC);
+}
+
+/*-
+ *-----------------------------------------------------------------------
+ * miBSSetSpans --
+ *     Perform a SetSpans, routing output to backing-store as needed.
+ *
+ * Results:
+ *     None.
+ *
+ * Side Effects:
+ *
+ *-----------------------------------------------------------------------
+ */
+static void
+miBSSetSpans(pDrawable, pGC, psrc, ppt, pwidth, nspans, fSorted)
+    DrawablePtr                pDrawable;
+    GCPtr              pGC;
+    char               *psrc;
+    register DDXPointPtr ppt;
+    int                        *pwidth;
+    int                        nspans;
+    int                        fSorted;
+{
+    DDXPointPtr        pptCopy, pptReset;
+    int        *pwidthCopy;
+    SETUP_BACKING (pDrawable, pGC);
+
+    PROLOGUE(pGC);
+
+    pptCopy = (DDXPointPtr)ALLOCATE_LOCAL(nspans*sizeof(DDXPointRec));
+    pwidthCopy=(int *)ALLOCATE_LOCAL(nspans*sizeof(int));
+    if (pptCopy && pwidthCopy)
+    {
+       copyData(ppt, pptCopy, nspans, MoreCopy0);
+       memmove((char *)pwidthCopy,(char *)pwidth,nspans*sizeof(int));
+
+       (* pGC->ops->SetSpans)(pDrawable, pGC, psrc, ppt, pwidth,
+                              nspans, fSorted);
+       if (pGC->miTranslate)
+       {
+           int dx, dy;
+           int nReset;
+
+           pptReset = pptCopy;
+           dx = pDrawable->x - pBackingDrawable->x;
+           dy = pDrawable->y - pBackingDrawable->y;
+           nReset = nspans;
+           while (nReset--)
+           {
+               pptReset->x -= dx;
+               pptReset->y -= dy;
+               ++pptReset;
+           }
+       }
+       (* pBackingGC->ops->SetSpans)(pBackingDrawable, pBackingGC,
+                               psrc, pptCopy, pwidthCopy, nspans, fSorted);
+    }
+    if (pwidthCopy) DEALLOCATE_LOCAL(pwidthCopy);
+    if (pptCopy) DEALLOCATE_LOCAL(pptCopy);
+
+    EPILOGUE (pGC);
+}
+
+/*-
+ *-----------------------------------------------------------------------
+ * miBSPutImage --
+ *     Perform a PutImage, routing output to backing-store as needed.
+ *
+ * Results:
+ *     None.
+ *
+ * Side Effects:
+ *
+ *-----------------------------------------------------------------------
+ */
+static void
+miBSPutImage(pDrawable, pGC, depth, x, y, w, h, leftPad, format, pBits)
+    DrawablePtr          pDrawable;
+    GCPtr        pGC;
+    int                  depth;
+    int                  x;
+    int                  y;
+    int                  w;
+    int                  h;
+    int                  leftPad;
+    int                  format;
+    char         *pBits;
+{
+    SETUP_BACKING (pDrawable, pGC);
+
+    PROLOGUE(pGC);
+
+    (*pGC->ops->PutImage)(pDrawable, pGC,
+                    depth, x, y, w, h, leftPad, format, pBits);
+    (*pBackingGC->ops->PutImage)(pBackingDrawable, pBackingGC,
+                    depth, x - pBackingStore->x, y - pBackingStore->y,
+                    w, h, leftPad, format, pBits);
+
+    EPILOGUE (pGC);
+}
+
+/*-
+ *-----------------------------------------------------------------------
+ * miBSDoCopy --
+ *     Perform a CopyArea or CopyPlane within a window that has backing
+ *     store enabled.
+ *
+ * Results:
+ *     TRUE if the copy was performed or FALSE if a regular one should
+ *     be done.
+ *
+ * Side Effects:
+ *     Things are copied (no s***!)
+ *
+ * Notes:
+ *     The idea here is to form two regions that cover the source box.
+ *     One contains the exposed rectangles while the other contains
+ *     the obscured ones. An array of <box, drawable> pairs is then
+ *     formed where the <box> indicates the area to be copied and the
+ *     <drawable> indicates from where it is to be copied (exposed regions
+ *     come from the screen while obscured ones come from the backing
+ *     pixmap). The array 'sequence' is then filled with the indices of
+ *     the pairs in the order in which they should be copied to prevent
+ *     things from getting screwed up. A call is also made through the
+ *     backingGC to take care of any copying into the backing pixmap.
+ *
+ *-----------------------------------------------------------------------
+ */
+static Bool
+miBSDoCopy(pWin, pGC, srcx, srcy, w, h, dstx, dsty, plane, copyProc, ppRgn)
+    WindowPtr    pWin;             /* Window being scrolled */
+    GCPtr        pGC;              /* GC we're called through */
+    int                  srcx;             /* X of source rectangle */
+    int                  srcy;             /* Y of source rectangle */
+    int                  w;                /* Width of source rectangle */
+    int                  h;                /* Height of source rectangle */
+    int                  dstx;             /* X of destination rectangle */
+    int                  dsty;             /* Y of destination rectangle */
+    unsigned long plane;           /* Plane to copy (0 for CopyArea) */
+    RegionPtr            (*copyProc)();    /* Procedure to call to perform the copy */
+    RegionPtr    *ppRgn;           /* resultant Graphics Expose region */
+{
+    RegionPtr          pRgnExp;    /* Exposed region */
+    RegionPtr          pRgnObs;    /* Obscured region */
+    BoxRec             box;        /* Source box (screen coord) */
+    struct BoxDraw {
+       BoxPtr          pBox;           /* Source box */
+       enum {
+           win, pix
+       }               source;         /* Place from which to copy */
+    }                  *boxes;     /* Array of box/drawable pairs covering
+                                    * source box. */
+    int                *sequence;  /* Sequence of boxes to move */
+    register int       i, j, k, l, y;
+    register BoxPtr    pBox;
+    int                        dx, dy, nrects;
+    Bool               graphicsExposures;
+    RegionPtr          (*pixCopyProc)();
+    int                        numRectsExp, numRectsObs;
+    BoxPtr             pBoxExp, pBoxObs;
+
+    SETUP_BACKING (pWin, pGC);
+
+    /*
+     * Create a region of exposed boxes in pRgnExp.
+     */
+    box.x1 = srcx + pWin->drawable.x;
+    box.x2 = box.x1 + w;
+    box.y1 = srcy + pWin->drawable.y;
+    box.y2 = box.y1 + h;
+    
+    pRgnExp = REGION_CREATE(pGC->pScreen, &box, 1);
+    REGION_INTERSECT(pGC->pScreen, pRgnExp, pRgnExp, &pWin->clipList);
+    pRgnObs = REGION_CREATE(pGC->pScreen, NULL, 1);
+    REGION_INVERSE( pGC->pScreen, pRgnObs, pRgnExp, &box);
+
+    /*
+     * Translate regions into window coordinates for proper calls
+     * to the copyProc, then make sure none of the obscured region sticks
+     * into invalid areas of the backing pixmap.
+     */
+    REGION_TRANSLATE(pGC->pScreen, pRgnExp,
+                                     -pWin->drawable.x,
+                                     -pWin->drawable.y);
+    REGION_TRANSLATE(pGC->pScreen, pRgnObs,
+                                     -pWin->drawable.x,
+                                     -pWin->drawable.y);
+    REGION_INTERSECT(pGC->pScreen, pRgnObs, pRgnObs, &pBackingStore->SavedRegion);
+
+    /*
+     * If the obscured region is empty, there's no point being fancy.
+     */
+    if (!REGION_NOTEMPTY(pGC->pScreen, pRgnObs))
+    {
+       REGION_DESTROY(pGC->pScreen, pRgnExp);
+       REGION_DESTROY(pGC->pScreen, pRgnObs);
+
+       return (FALSE);
+    }
+
+    numRectsExp = REGION_NUM_RECTS(pRgnExp);
+    pBoxExp = REGION_RECTS(pRgnExp);
+    pBoxObs = REGION_RECTS(pRgnObs);
+    numRectsObs = REGION_NUM_RECTS(pRgnObs);
+    nrects = numRectsExp + numRectsObs;
+    
+    boxes = (struct BoxDraw *)ALLOCATE_LOCAL(nrects * sizeof(struct BoxDraw));
+    sequence = (int *) ALLOCATE_LOCAL(nrects * sizeof(int));
+    *ppRgn = NULL;
+
+    if (!boxes || !sequence)
+    {
+       if (sequence) DEALLOCATE_LOCAL(sequence);
+       if (boxes) DEALLOCATE_LOCAL(boxes);
+       REGION_DESTROY(pGC->pScreen, pRgnExp);
+       REGION_DESTROY(pGC->pScreen, pRgnObs);
+
+       return(TRUE);
+    }
+
+    /*
+     * Order the boxes in the two regions so we know from which drawable
+     * to copy which box, storing the result in the boxes array
+     */
+    for (i = 0, j = 0, k = 0;
+        (i < numRectsExp) && (j < numRectsObs);
+        k++)
+    {
+       if (pBoxExp[i].y1 < pBoxObs[j].y1)
+       {
+           boxes[k].pBox = &pBoxExp[i];
+           boxes[k].source = win;
+           i++;
+       }
+       else if ((pBoxObs[j].y1 < pBoxExp[i].y1) ||
+                (pBoxObs[j].x1 < pBoxExp[i].x1))
+       {
+           boxes[k].pBox = &pBoxObs[j];
+           boxes[k].source = pix;
+           j++;
+       }
+       else
+       {
+           boxes[k].pBox = &pBoxExp[i];
+           boxes[k].source = win;
+           i++;
+       }
+    }
+
+    /*
+     * Catch any leftover boxes from either region (note that only
+     * one can have leftover boxes...)
+     */
+    if (i != numRectsExp)
+    {
+       do
+       {
+           boxes[k].pBox = &pBoxExp[i];
+           boxes[k].source = win;
+           i++;
+           k++;
+       } while (i < numRectsExp);
+
+    }
+    else
+    {
+       do
+       {
+           boxes[k].pBox = &pBoxObs[j];
+           boxes[k].source = pix;
+           j++;
+           k++;
+       } while (j < numRectsObs);
+    }
+    
+    if (dsty <= srcy)
+    {
+       /*
+        * Scroll up or vertically stationary, so vertical order is ok.
+        */
+       if (dstx <= srcx)
+       {
+           /*
+            * Scroll left or horizontally stationary, so horizontal order
+            * is ok as well.
+            */
+           for (i = 0; i < nrects; i++)
+           {
+               sequence[i] = i;
+           }
+       }
+       else
+       {
+           /*
+            * Scroll right. Need to reverse the rectangles within each
+            * band.
+            */
+           for (i = 0, j = 1, k = 0;
+                i < nrects;
+                j = i + 1, k = i)
+           {
+               y = boxes[i].pBox->y1;
+               while ((j < nrects) && (boxes[j].pBox->y1 == y))
+               {
+                   j++;
+               }
+               for (j--; j >= k; j--, i++)
+               {
+                   sequence[i] = j;
+               }
+           }
+       }
+    }
+    else
+    {
+       /*
+        * Scroll down. Must reverse vertical banding, at least.
+        */
+       if (dstx < srcx)
+       {
+           /*
+            * Scroll left. Horizontal order is ok.
+            */
+           for (i = nrects - 1, j = i - 1, k = i, l = 0;
+                i >= 0;
+                j = i - 1, k = i)
+           {
+               /*
+                * Find extent of current horizontal band, then reverse
+                * the order of the whole band.
+                */
+               y = boxes[i].pBox->y1;
+               while ((j >= 0) && (boxes[j].pBox->y1 == y))
+               {
+                   j--;
+               }
+               for (j++; j <= k; j++, i--, l++)
+               {
+                   sequence[l] = j;
+               }
+           }
+       }
+       else
+       {
+           /*
+            * Scroll right or horizontal stationary.
+            * Reverse horizontal order as well (if stationary, horizontal
+            * order can be swapped without penalty and this is faster
+             * to compute).
+            */
+           for (i = 0, j = nrects - 1; i < nrects; i++, j--)
+           {
+               sequence[i] = j;
+           }
+       }
+    }
+           
+    /*
+     * XXX: To avoid getting multiple NoExpose events from this operation,
+     * we turn OFF graphicsExposures in the gc and deal with any uncopied
+     * areas later, if there's something not in backing-store.
+     */
+
+    graphicsExposures = pGC->graphicsExposures;
+    pGC->graphicsExposures = FALSE;
+    
+    dx = dstx - srcx;
+    dy = dsty - srcy;
+
+    /*
+     * Figure out which copy procedure to use from the backing GC. Note we
+     * must do this because some implementations (sun's, e.g.) have
+     * pBackingGC a fake GC with the real one below it, thus the devPriv for
+     * pBackingGC won't be what the output library expects.
+     */
+    if (plane != 0)
+    {
+       pixCopyProc = pBackingGC->ops->CopyPlane;
+    }
+    else
+    {
+       pixCopyProc = pBackingGC->ops->CopyArea;
+    }
+    
+    for (i = 0; i < nrects; i++)
+    {
+       pBox = boxes[sequence[i]].pBox;
+       
+       /*
+        * If we're copying from the pixmap, we need to place its contents
+        * onto the screen before scrolling the pixmap itself. If we're copying
+        * from the window, we need to copy its contents into the pixmap before
+        * we scroll the window itself.
+        */
+       if (boxes[sequence[i]].source == pix)
+       {
+           (void) (* copyProc) (pBackingDrawable, pWin, pGC,
+                         pBox->x1 - pBackingStore->x,
+                         pBox->y1 - pBackingStore->y,
+                         pBox->x2 - pBox->x1, pBox->y2 - pBox->y1,
+                         pBox->x1 + dx, pBox->y1 + dy, plane);
+           (void) (* pixCopyProc) (pBackingDrawable, pBackingDrawable, pBackingGC,
+                            pBox->x1 - pBackingStore->x,
+                            pBox->y1 - pBackingStore->y,
+                            pBox->x2 - pBox->x1, pBox->y2 - pBox->y1,
+                            pBox->x1 + dx - pBackingStore->x,
+                            pBox->y1 + dy - pBackingStore->y, plane);
+       }
+       else
+       {
+           (void) (* pixCopyProc) (pWin, pBackingDrawable, pBackingGC,
+                            pBox->x1, pBox->y1,
+                            pBox->x2 - pBox->x1, pBox->y2 - pBox->y1,
+                            pBox->x1 + dx - pBackingStore->x,
+                            pBox->y1 + dy - pBackingStore->y, plane);
+           (void) (* copyProc) (pWin, pWin, pGC,
+                         pBox->x1, pBox->y1,
+                         pBox->x2 - pBox->x1, pBox->y2 - pBox->y1,
+                         pBox->x1 + dx, pBox->y1 + dy, plane);
+       }
+    }
+    DEALLOCATE_LOCAL(sequence);
+    DEALLOCATE_LOCAL(boxes);
+
+    pGC->graphicsExposures = graphicsExposures;
+    /*
+     * Form union of rgnExp and rgnObs and see if covers entire area
+     * to be copied.  Store the resultant region for miBSCopyArea
+     * to return to dispatch which will send the appropriate expose
+     * events.
+     */
+    REGION_UNION(pGC->pScreen, pRgnExp, pRgnExp, pRgnObs);
+    box.x1 = srcx;
+    box.x2 = srcx + w;
+    box.y1 = srcy;
+    box.y2 = srcy + h;
+    if (RECT_IN_REGION(pGC->pScreen, pRgnExp, &box) == rgnIN)
+    {
+       REGION_EMPTY(pGC->pScreen, pRgnExp);
+    }
+    else
+    {
+       REGION_INVERSE( pGC->pScreen, pRgnExp, pRgnExp, &box);
+       REGION_TRANSLATE( pGC->pScreen, pRgnExp,
+                                          dx + pWin->drawable.x,
+                                          dy + pWin->drawable.y);
+       REGION_INTERSECT( pGC->pScreen, pRgnObs, pRgnExp, &pWin->clipList);
+       (*pWin->drawable.pScreen->PaintWindowBackground) (pWin,
+                                               pRgnObs, PW_BACKGROUND);
+       REGION_TRANSLATE( pGC->pScreen, pRgnExp,
+                                          -pWin->drawable.x,
+                                          -pWin->drawable.y);
+       miBSClearBackingRegion (pWin, pRgnExp);
+    }
+    if (graphicsExposures)
+       *ppRgn = pRgnExp;
+    else
+       REGION_DESTROY(pGC->pScreen, pRgnExp);
+    REGION_DESTROY(pGC->pScreen, pRgnObs);
+
+    return (TRUE);
+}
+
+/*-
+ *-----------------------------------------------------------------------
+ * miBSCopyArea --
+ *     Perform a CopyArea from the source to the destination, extracting
+ *     from the source's backing-store and storing into the destination's
+ *     backing-store without messing anything up. If the source and
+ *     destination are different, there's not too much to worry about:
+ *     we can just issue several calls to the regular CopyArea function.
+ *
+ * Results:
+ *     None.
+ *
+ * Side Effects:
+ *
+ *-----------------------------------------------------------------------
+ */
+static RegionPtr
+miBSCopyArea (pSrc, pDst, pGC, srcx, srcy, w, h, dstx, dsty)
+    DrawablePtr          pSrc;
+    DrawablePtr          pDst;
+    GCPtr        pGC;
+    int                  srcx;
+    int                  srcy;
+    int                  w;
+    int                  h;
+    int                  dstx;
+    int                  dsty;
+{
+    BoxPtr     pExtents;
+    long       dx, dy;
+    int                bsrcx, bsrcy, bw, bh, bdstx, bdsty;
+    RegionPtr  pixExposed = 0, winExposed = 0;
+
+    SETUP_BACKING(pDst, pGC);
+
+    PROLOGUE(pGC);
+
+    if ((pSrc != pDst) ||
+       (!miBSDoCopy((WindowPtr)pSrc, pGC, srcx, srcy, w, h, dstx, dsty,
+                    (unsigned long) 0, pGC->ops->CopyArea, &winExposed)))
+    {
+       /*
+        * always copy to the backing store first, miBSDoCopy
+        * returns FALSE if the *source* region is disjoint
+        * from the backing store saved region.  So, copying
+        * *to* the backing store is always safe
+        */
+       if (pGC->clientClipType != CT_PIXMAP)
+       {
+           /*
+            * adjust srcx, srcy, w, h, dstx, dsty to be clipped to
+            * the backing store.  An unnecessary optimisation,
+            * but a useful one when GetSpans is slow.
+            */
+           pExtents = REGION_EXTENTS(pDst->pScreen,
+                                     (RegionPtr)pBackingGC->clientClip);
+           bsrcx = srcx;
+           bsrcy = srcy;
+           bw = w;
+           bh = h;
+           bdstx = dstx;
+           bdsty = dsty;
+           dx = pExtents->x1 - bdstx;
+           if (dx > 0)
+           {
+               bsrcx += dx;
+               bdstx += dx;
+               bw -= dx;
+           }
+           dy = pExtents->y1 - bdsty;
+           if (dy > 0)
+           {
+               bsrcy += dy;
+               bdsty += dy;
+               bh -= dy;
+           }
+           dx = (bdstx + bw) - pExtents->x2;
+           if (dx > 0)
+               bw -= dx;
+           dy = (bdsty + bh) - pExtents->y2;
+           if (dy > 0)
+               bh -= dy;
+           if (bw > 0 && bh > 0)
+               pixExposed = (* pBackingGC->ops->CopyArea) (pSrc, 
+                           pBackingDrawable, pBackingGC, 
+                           bsrcx, bsrcy, bw, bh, bdstx - pBackingStore->x,
+                           bdsty - pBackingStore->y);
+       }
+       else
+           pixExposed = (* pBackingGC->ops->CopyArea) (pSrc, 
+                           pBackingDrawable, pBackingGC,
+                           srcx, srcy, w, h,
+                           dstx - pBackingStore->x, dsty - pBackingStore->y);
+
+       winExposed = (* pGC->ops->CopyArea) (pSrc, pDst, pGC, srcx, srcy, w, h, dstx, dsty);
+    }
+
+    /*
+     * compute the composite graphics exposure region
+     */
+    if (winExposed)
+    {
+       if (pixExposed){
+           REGION_UNION(pDst->pScreen, winExposed, winExposed, pixExposed);
+           REGION_DESTROY(pDst->pScreen, pixExposed);
+       }
+    } else
+       winExposed = pixExposed;
+
+    EPILOGUE (pGC);
+
+    return winExposed;
+}
+
+/*-
+ *-----------------------------------------------------------------------
+ * miBSCopyPlane --
+ *
+ * Results:
+ *     None.
+ *
+ * Side Effects:
+ *
+ *-----------------------------------------------------------------------
+ */
+static RegionPtr
+miBSCopyPlane (pSrc, pDst, pGC, srcx, srcy, w, h, dstx, dsty, plane)
+    DrawablePtr          pSrc;
+    DrawablePtr          pDst;
+    register GC   *pGC;
+    int          srcx,
+                 srcy;
+    int          w,
+                 h;
+    int          dstx,
+                 dsty;
+    unsigned long  plane;
+{
+    BoxPtr     pExtents;
+    long       dx, dy;
+    int                bsrcx, bsrcy, bw, bh, bdstx, bdsty;
+    RegionPtr  winExposed = 0, pixExposed = 0;
+    SETUP_BACKING(pDst, pGC);
+
+    PROLOGUE(pGC);
+
+    if ((pSrc != pDst) ||
+       (!miBSDoCopy((WindowPtr)pSrc, pGC, srcx, srcy, w, h, dstx, dsty,
+                    plane,  pGC->ops->CopyPlane, &winExposed)))
+    {
+       /*
+        * always copy to the backing store first, miBSDoCopy
+        * returns FALSE if the *source* region is disjoint
+        * from the backing store saved region.  So, copying
+        * *to* the backing store is always safe
+        */
+       if (pGC->clientClipType != CT_PIXMAP)
+       {
+           /*
+            * adjust srcx, srcy, w, h, dstx, dsty to be clipped to
+            * the backing store.  An unnecessary optimisation,
+            * but a useful one when GetSpans is slow.
+            */
+           pExtents = REGION_EXTENTS(pDst->pScreen,
+                                     (RegionPtr)pBackingGC->clientClip);
+           bsrcx = srcx;
+           bsrcy = srcy;
+           bw = w;
+           bh = h;
+           bdstx = dstx;
+           bdsty = dsty;
+           dx = pExtents->x1 - bdstx;
+           if (dx > 0)
+           {
+               bsrcx += dx;
+               bdstx += dx;
+               bw -= dx;
+           }
+           dy = pExtents->y1 - bdsty;
+           if (dy > 0)
+           {
+               bsrcy += dy;
+               bdsty += dy;
+               bh -= dy;
+           }
+           dx = (bdstx + bw) - pExtents->x2;
+           if (dx > 0)
+               bw -= dx;
+           dy = (bdsty + bh) - pExtents->y2;
+           if (dy > 0)
+               bh -= dy;
+           if (bw > 0 && bh > 0)
+               pixExposed = (* pBackingGC->ops->CopyPlane) (pSrc, 
+                                   pBackingDrawable,
+                                   pBackingGC, bsrcx, bsrcy, bw, bh,
+                                   bdstx - pBackingStore->x,
+                                   bdsty - pBackingStore->y, plane);
+       }
+       else
+           pixExposed = (* pBackingGC->ops->CopyPlane) (pSrc, 
+                                   pBackingDrawable,
+                                   pBackingGC, srcx, srcy, w, h,
+                                   dstx - pBackingStore->x,
+                                   dsty - pBackingStore->y, plane);
+
+       winExposed = (* pGC->ops->CopyPlane) (pSrc, pDst, pGC, srcx, srcy, w, h,
+                             dstx, dsty, plane);
+       
+    }
+
+    /*
+     * compute the composite graphics exposure region
+     */
+    if (winExposed)
+    {
+       if (pixExposed)
+       {
+           REGION_UNION(pDst->pScreen, winExposed, winExposed, pixExposed);
+           REGION_DESTROY(pDst->pScreen, pixExposed);
+       }
+    } else
+       winExposed = pixExposed;
+
+    EPILOGUE (pGC);
+
+    return winExposed;
+}
+
+/*-
+ *-----------------------------------------------------------------------
+ * miBSPolyPoint --
+ *     Perform a PolyPoint, routing output to backing-store as needed.
+ *
+ * Results:
+ *     None.
+ *
+ * Side Effects:
+ *
+ *-----------------------------------------------------------------------
+ */
+static void
+miBSPolyPoint (pDrawable, pGC, mode, npt, pptInit)
+    DrawablePtr pDrawable;
+    GCPtr      pGC;
+    int                mode;           /* Origin or Previous */
+    int                npt;
+    xPoint     *pptInit;
+{
+    xPoint       *pptCopy;
+    SETUP_BACKING (pDrawable, pGC);
+
+    PROLOGUE(pGC);
+
+    pptCopy = (xPoint *)ALLOCATE_LOCAL(npt*sizeof(xPoint));
+    if (pptCopy)
+    {
+       copyPoints(pptInit, pptCopy, npt, mode);
+
+       (* pGC->ops->PolyPoint) (pDrawable, pGC, mode, npt, pptInit);
+
+       (* pBackingGC->ops->PolyPoint) (pBackingDrawable,
+                                  pBackingGC, mode, npt, pptCopy);
+
+       DEALLOCATE_LOCAL(pptCopy);
+    }
+
+    EPILOGUE (pGC);
+}
+
+/*-
+ *-----------------------------------------------------------------------
+ * miBSPolyLines --
+ *     Perform a Polylines, routing output to backing-store as needed.
+ *
+ * Results:
+ *
+ * Side Effects:
+ *
+ *-----------------------------------------------------------------------
+ */
+static void
+miBSPolylines (pDrawable, pGC, mode, npt, pptInit)
+    DrawablePtr          pDrawable;
+    GCPtr        pGC;
+    int                  mode;
+    int                  npt;
+    DDXPointPtr          pptInit;
+{
+    DDXPointPtr        pptCopy;
+    SETUP_BACKING (pDrawable, pGC);
+
+    PROLOGUE(pGC);
+
+    pptCopy = (DDXPointPtr)ALLOCATE_LOCAL(npt*sizeof(DDXPointRec));
+    if (pptCopy)
+    {
+       copyPoints(pptInit, pptCopy, npt, mode);
+
+       (* pGC->ops->Polylines)(pDrawable, pGC, mode, npt, pptInit);
+       (* pBackingGC->ops->Polylines)(pBackingDrawable,
+                                 pBackingGC, mode, npt, pptCopy);
+       DEALLOCATE_LOCAL(pptCopy);
+    }
+
+    EPILOGUE (pGC);
+}
+
+/*-
+ *-----------------------------------------------------------------------
+ * miBSPolySegment --
+ *     Perform a PolySegment, routing output to backing-store as needed.
+ *
+ * Results:
+ *     None.
+ *
+ * Side Effects:
+ *
+ *-----------------------------------------------------------------------
+ */
+static void
+miBSPolySegment(pDrawable, pGC, nseg, pSegs)
+    DrawablePtr pDrawable;
+    GCPtr      pGC;
+    int                nseg;
+    xSegment   *pSegs;
+{
+    xSegment   *pSegsCopy;
+
+    SETUP_BACKING (pDrawable, pGC);
+
+    PROLOGUE(pGC);
+
+    pSegsCopy = (xSegment *)ALLOCATE_LOCAL(nseg*sizeof(xSegment));
+    if (pSegsCopy)
+    {
+       copyData(pSegs, pSegsCopy, nseg << 1, MoreCopy0);
+
+       (* pGC->ops->PolySegment)(pDrawable, pGC, nseg, pSegs);
+       (* pBackingGC->ops->PolySegment)(pBackingDrawable,
+                                   pBackingGC, nseg, pSegsCopy);
+
+       DEALLOCATE_LOCAL(pSegsCopy);
+    }
+
+    EPILOGUE (pGC);
+}
+
+/*-
+ *-----------------------------------------------------------------------
+ * miBSPolyRectangle --
+ *     Perform a PolyRectangle, routing output to backing-store as needed.
+ *
+ * Results:
+ *     None
+ *
+ * Side Effects:
+ *
+ *-----------------------------------------------------------------------
+ */
+static void
+miBSPolyRectangle(pDrawable, pGC, nrects, pRects)
+    DrawablePtr        pDrawable;
+    GCPtr      pGC;
+    int                nrects;
+    xRectangle *pRects;
+{
+    xRectangle *pRectsCopy;
+    SETUP_BACKING (pDrawable, pGC);
+
+    PROLOGUE(pGC);
+
+    pRectsCopy =(xRectangle *)ALLOCATE_LOCAL(nrects*sizeof(xRectangle));
+    if (pRectsCopy)
+    {
+       copyData(pRects, pRectsCopy, nrects, MoreCopy2);
+
+       (* pGC->ops->PolyRectangle)(pDrawable, pGC, nrects, pRects);
+       (* pBackingGC->ops->PolyRectangle)(pBackingDrawable,
+                                     pBackingGC, nrects, pRectsCopy);
+
+       DEALLOCATE_LOCAL(pRectsCopy);
+    }
+
+    EPILOGUE (pGC);
+}
+
+/*-
+ *-----------------------------------------------------------------------
+ * miBSPolyArc --
+ *     Perform a PolyArc, routing output to backing-store as needed.
+ *
+ * Results:
+ *
+ * Side Effects:
+ *
+ *-----------------------------------------------------------------------
+ */
+static void
+miBSPolyArc(pDrawable, pGC, narcs, parcs)
+    DrawablePtr        pDrawable;
+    GCPtr      pGC;
+    int                narcs;
+    xArc       *parcs;
+{
+    xArc  *pArcsCopy;
+    SETUP_BACKING (pDrawable, pGC);
+
+    PROLOGUE(pGC);
+
+    pArcsCopy = (xArc *)ALLOCATE_LOCAL(narcs*sizeof(xArc));
+    if (pArcsCopy)
+    {
+       copyData(parcs, pArcsCopy, narcs, MoreCopy4);
+
+       (* pGC->ops->PolyArc)(pDrawable, pGC, narcs, parcs);
+       (* pBackingGC->ops->PolyArc)(pBackingDrawable, pBackingGC,
+                               narcs, pArcsCopy);
+
+       DEALLOCATE_LOCAL(pArcsCopy);
+    }
+
+    EPILOGUE (pGC);
+}
+
+/*-
+ *-----------------------------------------------------------------------
+ * miBSFillPolygon --
+ *     Perform a FillPolygon, routing output to backing-store as needed.
+ *
+ * Results:
+ *     None.
+ *
+ * Side Effects:
+ *
+ *-----------------------------------------------------------------------
+ */
+static void
+miBSFillPolygon(pDrawable, pGC, shape, mode, count, pPts)
+    DrawablePtr                pDrawable;
+    register GCPtr     pGC;
+    int                        shape, mode;
+    register int       count;
+    DDXPointPtr                pPts;
+{
+    DDXPointPtr        pPtsCopy;
+    SETUP_BACKING (pDrawable, pGC);
+
+    PROLOGUE(pGC);
+
+    pPtsCopy = (DDXPointPtr)ALLOCATE_LOCAL(count*sizeof(DDXPointRec));
+    if (pPtsCopy)
+    {
+       copyPoints(pPts, pPtsCopy, count, mode);
+       (* pGC->ops->FillPolygon)(pDrawable, pGC, shape, mode, count, pPts);
+       (* pBackingGC->ops->FillPolygon)(pBackingDrawable,
+                                   pBackingGC, shape, mode,
+                                   count, pPtsCopy);
+
+       DEALLOCATE_LOCAL(pPtsCopy);
+    }
+
+    EPILOGUE (pGC);
+}
+
+/*-
+ *-----------------------------------------------------------------------
+ * miBSPolyFillRect --
+ *     Perform a PolyFillRect, routing output to backing-store as needed.
+ *
+ * Results:
+ *     None.
+ *
+ * Side Effects:
+ *
+ *-----------------------------------------------------------------------
+ */
+static void
+miBSPolyFillRect(pDrawable, pGC, nrectFill, prectInit)
+    DrawablePtr pDrawable;
+    GCPtr      pGC;
+    int                nrectFill;      /* number of rectangles to fill */
+    xRectangle *prectInit;     /* Pointer to first rectangle to fill */
+{
+    xRectangle *pRectCopy;
+    SETUP_BACKING (pDrawable, pGC);
+
+    PROLOGUE(pGC);
+
+    pRectCopy =
+       (xRectangle *)ALLOCATE_LOCAL(nrectFill*sizeof(xRectangle));
+    if (pRectCopy)
+    {
+       copyData(prectInit, pRectCopy, nrectFill, MoreCopy2);
+
+       (* pGC->ops->PolyFillRect)(pDrawable, pGC, nrectFill, prectInit);
+       (* pBackingGC->ops->PolyFillRect)(pBackingDrawable,
+                                    pBackingGC, nrectFill, pRectCopy);
+
+       DEALLOCATE_LOCAL(pRectCopy);
+    }
+
+    EPILOGUE (pGC);
+}
+
+/*-
+ *-----------------------------------------------------------------------
+ * miBSPolyFillArc --
+ *     Perform a PolyFillArc, routing output to backing-store as needed.
+ *
+ * Results:
+ *     None.
+ *
+ * Side Effects:
+ *
+ *-----------------------------------------------------------------------
+ */
+static void
+miBSPolyFillArc(pDrawable, pGC, narcs, parcs)
+    DrawablePtr        pDrawable;
+    GCPtr      pGC;
+    int                narcs;
+    xArc       *parcs;
+{
+    xArc  *pArcsCopy;
+    SETUP_BACKING (pDrawable, pGC);
+
+    PROLOGUE(pGC);
+
+    pArcsCopy = (xArc *)ALLOCATE_LOCAL(narcs*sizeof(xArc));
+    if (pArcsCopy)
+    {
+       copyData(parcs, pArcsCopy, narcs, MoreCopy4);
+       (* pGC->ops->PolyFillArc)(pDrawable, pGC, narcs, parcs);
+       (* pBackingGC->ops->PolyFillArc)(pBackingDrawable,
+                                   pBackingGC, narcs, pArcsCopy);
+       DEALLOCATE_LOCAL(pArcsCopy);
+    }
+
+    EPILOGUE (pGC);
+}
+
+
+/*-
+ *-----------------------------------------------------------------------
+ * miBSPolyText8 --
+ *     Perform a PolyText8, routing output to backing-store as needed.
+ *
+ * Results:
+ *
+ * Side Effects:
+ *
+ *-----------------------------------------------------------------------
+ */
+static int
+miBSPolyText8(pDrawable, pGC, x, y, count, chars)
+    DrawablePtr pDrawable;
+    GCPtr      pGC;
+    int                x, y;
+    int        count;
+    char       *chars;
+{
+    int            result;
+    SETUP_BACKING (pDrawable, pGC);
+
+    PROLOGUE(pGC);
+
+    result = (* pGC->ops->PolyText8)(pDrawable, pGC, x, y, count, chars);
+    (* pBackingGC->ops->PolyText8)(pBackingDrawable, pBackingGC,
+                                  x - pBackingStore->x, y - pBackingStore->y,
+                                  count, chars);
+
+    EPILOGUE (pGC);
+    return result;
+}
+
+/*-
+ *-----------------------------------------------------------------------
+ * miBSPolyText16 --
+ *     Perform a PolyText16, routing output to backing-store as needed.
+ *
+ * Results:
+ *
+ * Side Effects:
+ *
+ *-----------------------------------------------------------------------
+ */
+static int
+miBSPolyText16(pDrawable, pGC, x, y, count, chars)
+    DrawablePtr pDrawable;
+    GCPtr      pGC;
+    int                x, y;
+    int                count;
+    unsigned short *chars;
+{
+    int        result;
+    SETUP_BACKING (pDrawable, pGC);
+
+    PROLOGUE(pGC);
+
+    result = (* pGC->ops->PolyText16)(pDrawable, pGC, x, y, count, chars);
+    (* pBackingGC->ops->PolyText16)(pBackingDrawable, pBackingGC,
+                                   x - pBackingStore->x, y - pBackingStore->y,
+                                   count, chars);
+
+    EPILOGUE (pGC);
+
+    return result;
+}
+
+/*-
+ *-----------------------------------------------------------------------
+ * miBSImageText8 --
+ *     Perform a ImageText8, routing output to backing-store as needed.
+ *
+ * Results:
+ *
+ * Side Effects:
+ *
+ *-----------------------------------------------------------------------
+ */
+static void
+miBSImageText8(pDrawable, pGC, x, y, count, chars)
+    DrawablePtr pDrawable;
+    GCPtr      pGC;
+    int                x, y;
+    int                count;
+    char       *chars;
+{
+    SETUP_BACKING (pDrawable, pGC);
+    PROLOGUE(pGC);
+
+    (* pGC->ops->ImageText8)(pDrawable, pGC, x, y, count, chars);
+    (* pBackingGC->ops->ImageText8)(pBackingDrawable, pBackingGC,
+                                   x - pBackingStore->x, y - pBackingStore->y,
+                                   count, chars);
+
+    EPILOGUE (pGC);
+}
+
+/*-
+ *-----------------------------------------------------------------------
+ * miBSImageText16 --
+ *     Perform a ImageText16, routing output to backing-store as needed.
+ *
+ * Results:
+ *
+ * Side Effects:
+ *
+ *-----------------------------------------------------------------------
+ */
+static void
+miBSImageText16(pDrawable, pGC, x, y, count, chars)
+    DrawablePtr pDrawable;
+    GCPtr      pGC;
+    int                x, y;
+    int                count;
+    unsigned short *chars;
+{
+    SETUP_BACKING (pDrawable, pGC);
+    PROLOGUE(pGC);
+
+    (* pGC->ops->ImageText16)(pDrawable, pGC, x, y, count, chars);
+    (* pBackingGC->ops->ImageText16)(pBackingDrawable, pBackingGC,
+                                   x - pBackingStore->x, y - pBackingStore->y,
+                                    count, chars);
+
+    EPILOGUE (pGC);
+}
+
+/*-
+ *-----------------------------------------------------------------------
+ * miBSImageGlyphBlt --
+ *     Perform a ImageGlyphBlt, routing output to backing-store as needed.
+ *
+ * Results:
+ *
+ * Side Effects:
+ *
+ *-----------------------------------------------------------------------
+ */
+static void
+miBSImageGlyphBlt(pDrawable, pGC, x, y, nglyph, ppci, pglyphBase)
+    DrawablePtr pDrawable;
+    GCPtr      pGC;
+    int        x, y;
+    unsigned int nglyph;
+    CharInfoPtr *ppci;         /* array of character info */
+    pointer    pglyphBase;     /* start of array of glyphs */
+{
+    SETUP_BACKING (pDrawable, pGC);
+    PROLOGUE(pGC);
+
+    (* pGC->ops->ImageGlyphBlt)(pDrawable, pGC, x, y, nglyph, ppci,
+                            pglyphBase);
+    (* pBackingGC->ops->ImageGlyphBlt)(pBackingDrawable, pBackingGC,
+                                   x - pBackingStore->x, y - pBackingStore->y,
+                                      nglyph, ppci, pglyphBase);
+
+    EPILOGUE (pGC);
+}
+
+/*-
+ *-----------------------------------------------------------------------
+ * miBSPolyGlyphBlt --
+ *     Perform a PolyGlyphBlt, routing output to backing-store as needed.
+ *
+ * Results:
+ *
+ * Side Effects:
+ *
+ *-----------------------------------------------------------------------
+ */
+static void
+miBSPolyGlyphBlt(pDrawable, pGC, x, y, nglyph, ppci, pglyphBase)
+    DrawablePtr pDrawable;
+    GCPtr      pGC;
+    int        x, y;
+    unsigned int nglyph;
+    CharInfoPtr *ppci;         /* array of character info */
+    pointer    pglyphBase;     /* start of array of glyphs */
+{
+    SETUP_BACKING (pDrawable, pGC);
+    PROLOGUE(pGC);
+
+    (* pGC->ops->PolyGlyphBlt)(pDrawable, pGC, x, y, nglyph,
+                           ppci, pglyphBase);
+    (* pBackingGC->ops->PolyGlyphBlt)(pBackingDrawable, pBackingGC,
+                                   x - pBackingStore->x, y - pBackingStore->y,
+                                     nglyph, ppci, pglyphBase);
+    EPILOGUE (pGC);
+}
+
+/*-
+ *-----------------------------------------------------------------------
+ * miBSPushPixels --
+ *     Perform a PushPixels, routing output to backing-store as needed.
+ *
+ * Results:
+ *
+ * Side Effects:
+ *
+ *-----------------------------------------------------------------------
+ */
+static void
+miBSPushPixels(pGC, pBitMap, pDst, w, h, x, y)
+    GCPtr      pGC;
+    PixmapPtr  pBitMap;
+    DrawablePtr pDst;
+    int                w, h, x, y;
+{
+    SETUP_BACKING (pDst, pGC);
+    PROLOGUE(pGC);
+
+    (* pGC->ops->PushPixels)(pGC, pBitMap, pDst, w, h, x, y);
+    if (pGC->miTranslate) {
+       x -= pDst->x;
+       y -= pDst->y;
+    }
+    (* pBackingGC->ops->PushPixels)(pBackingGC, pBitMap,
+                              pBackingDrawable, w, h,
+                              x - pBackingStore->x, y - pBackingStore->y);
+
+    EPILOGUE (pGC);
+}
+
+#ifdef NEED_LINEHELPER
+/*-
+ *-----------------------------------------------------------------------
+ * miBSLineHelper --
+ *
+ * Results: should never be called
+ *
+ * Side Effects: server dies
+ *
+ *-----------------------------------------------------------------------
+ */
+static void
+miBSLineHelper()
+{
+    FatalError("miBSLineHelper called\n");
+}
+#endif
+
+/*-
+ *-----------------------------------------------------------------------
+ * miBSClearBackingStore --
+ *     Clear the given area of the backing pixmap with the background of
+ *     the window, whatever it is. If generateExposures is TRUE, generate
+ *     exposure events for the area. Note that if the area has any
+ *     part outside the saved portions of the window, we do not allow the
+ *     count in the expose events to be 0, since there will be more
+ *     expose events to come.
+ *
+ * Results:
+ *     None.
+ *
+ * Side Effects:
+ *     Areas of pixmap are cleared and Expose events are generated.
+ *
+ *-----------------------------------------------------------------------
+ */
+static RegionPtr
+miBSClearBackingStore(pWin, x, y, w, h, generateExposures)
+    WindowPtr          pWin;
+    int                        x;
+    int                        y;
+    int                        w;
+    int                        h;
+    Bool               generateExposures;
+{
+    RegionPtr          pRgn;
+    int                        i;
+    miBSWindowPtr      pBackingStore;
+    ScreenPtr          pScreen;
+    GCPtr              pGC;
+    int                        ts_x_origin,
+                       ts_y_origin;
+    pointer                    gcvalues[4];
+    unsigned long      gcmask;
+    xRectangle         *rects;
+    BoxPtr             pBox;
+    BoxRec             box;
+    PixUnion           background;
+    char               backgroundState;
+    int                        numRects;
+
+    pBackingStore = (miBSWindowPtr)pWin->backStorage;
+    pScreen = pWin->drawable.pScreen;
+
+    if ((pBackingStore->status == StatusNoPixmap) ||
+       (pBackingStore->status == StatusBadAlloc))
+       return NullRegion;
+    
+    if (w == 0)
+       w = (int) pWin->drawable.width - x;
+    if (h == 0)
+       h = (int) pWin->drawable.height - y;
+
+    box.x1 = x;
+    box.y1 = y;
+    box.x2 = x + w;
+    box.y2 = y + h;
+    pRgn = REGION_CREATE(pWin->drawable.pScreen, &box, 1);
+    if (!pRgn)
+       return NullRegion;
+    REGION_INTERSECT( pScreen, pRgn, pRgn, &pBackingStore->SavedRegion);
+
+    if (REGION_NOTEMPTY( pScreen, pRgn))
+    {
+       /*
+        * if clearing entire window, simply make new virtual
+        * tile.  For the root window, we also destroy the pixmap
+        * to save a pile of memory
+        */
+       if (x == 0 && y == 0 &&
+           w == pWin->drawable.width &&
+           h == pWin->drawable.height)
+       {
+           if (!pWin->parent)
+               miDestroyBSPixmap (pWin);
+           if (pBackingStore->status != StatusContents)
+                miTileVirtualBS (pWin);
+       }
+
+       ts_x_origin = ts_y_origin = 0;
+
+       backgroundState = pWin->backgroundState;
+       background = pWin->background;
+       if (backgroundState == ParentRelative) {
+           WindowPtr   pParent;
+
+           pParent = pWin;
+           while (pParent->backgroundState == ParentRelative) {
+               ts_x_origin -= pParent->origin.x;
+               ts_y_origin -= pParent->origin.y;
+               pParent = pParent->parent;
+           }
+           backgroundState = pParent->backgroundState;
+           background = pParent->background;
+       }
+
+       if ((backgroundState != None) &&
+           ((pBackingStore->status == StatusContents) ||
+            !SameBackground (pBackingStore->backgroundState,
+                             pBackingStore->background,
+                             backgroundState,
+                             background)))
+       {
+           if (!pBackingStore->pBackingPixmap)
+               miCreateBSPixmap(pWin, NullBox);
+
+           pGC = GetScratchGC(pWin->drawable.depth, pScreen);
+           if (pGC && pBackingStore->pBackingPixmap)
+           {
+               /*
+                * First take care of any ParentRelative stuff by altering the
+                * tile/stipple origin to match the coordinates of the upper-left
+                * corner of the first ancestor without a ParentRelative background.
+                * This coordinate is, of course, negative.
+                */
+           
+               if (backgroundState == BackgroundPixel)
+               {
+                   gcvalues[0] = (pointer) background.pixel;
+                   gcvalues[1] = (pointer)FillSolid;
+                   gcmask = GCForeground|GCFillStyle;
+               }
+               else
+               {
+                   gcvalues[0] = (pointer)FillTiled;
+                   gcvalues[1] = (pointer) background.pixmap;
+                   gcmask = GCFillStyle|GCTile;
+               }
+               gcvalues[2] = (pointer)(ts_x_origin - pBackingStore->x);
+               gcvalues[3] = (pointer)(ts_y_origin - pBackingStore->y);
+               gcmask |= GCTileStipXOrigin|GCTileStipYOrigin;
+               DoChangeGC(pGC, gcmask, (XID *)gcvalues, TRUE);
+               ValidateGC((DrawablePtr)pBackingStore->pBackingPixmap, pGC);
+    
+               /*
+                * Figure out the array of rectangles to fill and fill them with
+                * PolyFillRect in the proper mode, as set in the GC above.
+                */
+               numRects = REGION_NUM_RECTS(pRgn);
+               rects = (xRectangle *)ALLOCATE_LOCAL(numRects*sizeof(xRectangle));
+           
+               if (rects)
+               {
+                   for (i = 0, pBox = REGION_RECTS(pRgn);
+                        i < numRects;
+                        i++, pBox++)
+                   {
+                       rects[i].x = pBox->x1 - pBackingStore->x;
+                       rects[i].y = pBox->y1 - pBackingStore->y;
+                       rects[i].width = pBox->x2 - pBox->x1;
+                       rects[i].height = pBox->y2 - pBox->y1;
+                   }
+                   (* pGC->ops->PolyFillRect) (
+                               (DrawablePtr)pBackingStore->pBackingPixmap,
+                                      pGC, numRects, rects);
+                   DEALLOCATE_LOCAL(rects);
+               }       
+               FreeScratchGC(pGC);
+           }
+       }       
+
+       if (!generateExposures)
+       {
+           REGION_DESTROY(pScreen, pRgn);
+           pRgn = NULL;
+       }
+       else
+       {
+           /*
+            * result must be screen relative, but is currently
+            * drawable relative.
+            */
+           REGION_TRANSLATE(pScreen, pRgn, pWin->drawable.x,
+                            pWin->drawable.y);
+       }
+    }
+    else
+    {
+       REGION_DESTROY( pScreen, pRgn);
+       pRgn = NULL;
+    }
+    return pRgn;
+}
+
+static void
+miBSClearBackingRegion (pWin, pRgn)
+    WindowPtr  pWin;
+    RegionPtr  pRgn;
+{
+    BoxPtr     pBox;
+    int                i;
+
+    i = REGION_NUM_RECTS(pRgn);
+    pBox = REGION_RECTS(pRgn);
+    while (i--)
+    {
+       (void) miBSClearBackingStore(pWin, pBox->x1, pBox->y1,
+                                       pBox->x2 - pBox->x1,
+                                       pBox->y2 - pBox->y1,
+                                       FALSE);
+       pBox++;
+    }
+}
+
+/*
+ * fill a region of the destination with virtual bits
+ *
+ * pRgn is to be translated by (x,y)
+ */
+
+static void
+miBSFillVirtualBits (pDrawable, pGC, pRgn, x, y, state, pixunion, planeMask)
+    DrawablePtr                pDrawable;
+    GCPtr              pGC;
+    RegionPtr          pRgn;
+    int                        x, y;
+    int                        state;
+    PixUnion           pixunion;
+    unsigned long      planeMask;
+{
+    int                i;
+    BITS32     gcmask;
+    pointer    gcval[5];
+    xRectangle *pRect;
+    BoxPtr     pBox;
+    WindowPtr  pWin;
+    int                numRects;
+
+    if (state == None)
+       return;
+    numRects = REGION_NUM_RECTS(pRgn);
+    pRect = (xRectangle *)ALLOCATE_LOCAL(numRects * sizeof(xRectangle));
+    if (!pRect)
+       return;
+    pWin = 0;
+    if (pDrawable->type != DRAWABLE_PIXMAP)
+    {
+       pWin = (WindowPtr) pDrawable;
+       if (!pWin->backStorage)
+           pWin = 0;
+    }
+    i = 0;
+    gcmask = 0;
+    gcval[i++] = (pointer)planeMask;
+    gcmask |= GCPlaneMask;
+    if (state == BackgroundPixel)
+    {
+       if (pGC->fgPixel != pixunion.pixel)
+       {
+           gcval[i++] = (pointer)pixunion.pixel;
+           gcmask |= GCForeground;
+       }
+       if (pGC->fillStyle != FillSolid)
+       {
+           gcval[i++] = (pointer)FillSolid;
+           gcmask |= GCFillStyle;
+       }
+    }
+    else
+    {
+       if (pGC->fillStyle != FillTiled)
+       {
+           gcval[i++] = (pointer)FillTiled;
+           gcmask |= GCFillStyle;
+       }
+       if (pGC->tileIsPixel || pGC->tile.pixmap != pixunion.pixmap)
+       {
+           gcval[i++] = (pointer)pixunion.pixmap;
+           gcmask |= GCTile;
+       }
+       if (pGC->patOrg.x != x)
+       {
+           gcval[i++] = (pointer)x;
+           gcmask |= GCTileStipXOrigin;
+       }
+       if (pGC->patOrg.y != y)
+       {
+           gcval[i++] = (pointer)y;
+           gcmask |= GCTileStipYOrigin;
+       }
+    }
+    if (gcmask)
+       DoChangeGC (pGC, gcmask, (XID *)gcval, 1);
+
+    if (pWin)
+       (*pWin->drawable.pScreen->DrawGuarantee) (pWin, pGC, GuaranteeVisBack);
+
+    if (pDrawable->serialNumber != pGC->serialNumber)
+       ValidateGC (pDrawable, pGC);
+
+    pBox = REGION_RECTS(pRgn);
+    for (i = numRects; --i >= 0; pBox++, pRect++)
+    {
+       pRect->x = pBox->x1 + x;
+       pRect->y = pBox->y1 + y;
+       pRect->width = pBox->x2 - pBox->x1;
+       pRect->height = pBox->y2 - pBox->y1;
+    }
+    pRect -= numRects;
+    (*pGC->ops->PolyFillRect) (pDrawable, pGC, numRects, pRect);
+    if (pWin)
+       (*pWin->drawable.pScreen->DrawGuarantee) (pWin, pGC, GuaranteeNothing);
+    DEALLOCATE_LOCAL (pRect);
+}
+
+/*-
+ *-----------------------------------------------------------------------
+ * miBSAllocate --
+ *     Create and install backing store info for a window
+ *
+ *-----------------------------------------------------------------------
+ */
+
+static void
+miBSAllocate(pWin)
+    WindowPtr    pWin;
+{
+    register miBSWindowPtr  pBackingStore;
+    register ScreenPtr             pScreen;
+       
+    if (pWin->drawable.pScreen->backingStoreSupport == NotUseful)
+       return;
+    pScreen = pWin->drawable.pScreen;
+    if (!(pBackingStore = (miBSWindowPtr)pWin->backStorage))
+    {
+
+       pBackingStore = (miBSWindowPtr)xalloc(sizeof(miBSWindowRec));
+       if (!pBackingStore)
+           return;
+
+       pBackingStore->pBackingPixmap = NullPixmap;
+       pBackingStore->x = 0;
+       pBackingStore->y = 0;
+       REGION_INIT( pScreen, &pBackingStore->SavedRegion, NullBox, 1);
+       pBackingStore->viewable = (char)pWin->viewable;
+       pBackingStore->status = StatusNoPixmap;
+       pBackingStore->backgroundState = None;
+       pWin->backStorage = (pointer) pBackingStore;
+    }
+       
+    /*
+     * Now want to initialize the backing pixmap and SavedRegion if
+     * necessary. The initialization consists of finding all the
+     * currently-obscured regions, by taking the inverse of the window's
+     * clip list, storing the result in SavedRegion, and exposing those
+     * areas of the window.
+     */
+
+    if (pBackingStore->status == StatusNoPixmap &&
+       ((pWin->backingStore == WhenMapped && pWin->viewable) ||
+        (pWin->backingStore == Always)))
+    {
+       BoxRec          box;
+       RegionPtr       pSavedRegion;
+
+       pSavedRegion = &pBackingStore->SavedRegion;
+
+       box.x1 = pWin->drawable.x;
+       box.x2 = box.x1 + (int) pWin->drawable.width;
+       box.y1 = pWin->drawable.y;
+       box.y2 = pWin->drawable.y + (int) pWin->drawable.height;
+
+       REGION_INVERSE( pScreen, pSavedRegion, &pWin->clipList,  &box);
+       REGION_TRANSLATE( pScreen, pSavedRegion,
+                                     -pWin->drawable.x,
+                                     -pWin->drawable.y);
+#ifdef SHAPE
+       if (wBoundingShape (pWin))
+           REGION_INTERSECT(pScreen, pSavedRegion, pSavedRegion,
+                            wBoundingShape (pWin));
+       if (wClipShape (pWin))
+           REGION_INTERSECT(pScreen, pSavedRegion, pSavedRegion,
+                            wClipShape (pWin));
+#endif
+       /* if window is already on-screen, assume it has been drawn to */
+       if (pWin->viewable)
+           pBackingStore->status = StatusVDirty;
+       miTileVirtualBS (pWin);
+       
+       /*
+        * deliver all the newly available regions
+        * as exposure events to the window
+        */
+
+       miSendExposures(pWin, pSavedRegion, 0, 0);
+    }
+    else if (!pWin->viewable)
+    {
+        /*
+         * Turn off backing store when we're not supposed to
+         * be saving anything
+         */
+        if (pBackingStore->status != StatusNoPixmap)
+        {
+            REGION_EMPTY( pScreen, &pBackingStore->SavedRegion);
+            miDestroyBSPixmap (pWin);
+        }
+    }
+}
+
+/*-
+ *-----------------------------------------------------------------------
+ * miBSFree --
+ *     Destroy and free all the stuff associated with the backing-store
+ *     for the given window.
+ *
+ * Results:
+ *     None.
+ *
+ * Side Effects:
+ *     The backing pixmap and all the regions and GC's are destroyed.
+ *
+ *-----------------------------------------------------------------------
+ */
+static void
+miBSFree(pWin)
+    WindowPtr pWin;
+{
+    miBSWindowPtr      pBackingStore;
+    register ScreenPtr pScreen = pWin->drawable.pScreen;
+
+    pBackingStore = (miBSWindowPtr)pWin->backStorage;
+    if (pBackingStore)
+    {
+       miDestroyBSPixmap (pWin);
+
+       REGION_UNINIT( pScreen, &pBackingStore->SavedRegion);
+
+       xfree(pBackingStore);
+       pWin->backStorage = NULL;
+    }
+}
+
+/*-
+ *-----------------------------------------------------------------------
+ * miResizeBackingStore --
+ *     Alter the size of the backing pixmap as necessary when the
+ *     SavedRegion changes size. The contents of the old pixmap are
+ *     copied/shifted into the new/same pixmap.
+ *
+ * Results:
+ *     The new Pixmap is created as necessary.
+ *
+ * Side Effects:
+ *     The old pixmap is destroyed.
+ *
+ *-----------------------------------------------------------------------
+ */
+static void
+miResizeBackingStore(pWin, dx, dy, saveBits)
+    WindowPtr  pWin;
+    int                dx, dy;     /* bits are moving this far */
+    Bool       saveBits;   /* bits are useful */
+{
+    miBSWindowPtr pBackingStore;
+    PixmapPtr pBackingPixmap;
+    ScreenPtr pScreen;
+    GC    *pGC;
+    BoxPtr  extents;
+    PixmapPtr pNewPixmap;
+    int nx, ny;
+    int        nw, nh;
+
+    pBackingStore = (miBSWindowPtr)(pWin->backStorage);
+    pBackingPixmap = pBackingStore->pBackingPixmap;
+    if (!pBackingPixmap)
+       return;
+    pScreen = pWin->drawable.pScreen;
+    extents = REGION_EXTENTS(pScreen, &pBackingStore->SavedRegion);
+    pNewPixmap = pBackingPixmap;
+
+    nw = extents->x2 - extents->x1;
+    nh = extents->y2 - extents->y1;
+
+    /* the policy here could be more sophisticated */
+    if (nw != pBackingPixmap->drawable.width ||
+       nh != pBackingPixmap->drawable.height)
+    {
+       if (!saveBits)
+       {
+           pNewPixmap = NullPixmap;
+           pBackingStore->status = StatusNoPixmap;
+       }
+       else
+       {
+           pNewPixmap = (PixmapPtr)(*pScreen->CreatePixmap)
+                                           (pScreen,
+                                            nw, nh,
+                                            pWin->drawable.depth);
+           if (!pNewPixmap)
+           {
+#ifdef BSEAGER
+               pBackingStore->status = StatusNoPixmap;
+#else
+               pBackingStore->status = StatusBadAlloc;
+#endif
+           }
+       }
+    }
+    if (!pNewPixmap)
+    {
+       pBackingStore->x = 0;
+       pBackingStore->y = 0;
+    }
+    else
+    {
+       nx = pBackingStore->x - extents->x1 + dx;
+       ny = pBackingStore->y - extents->y1 + dy;
+       pBackingStore->x = extents->x1;
+       pBackingStore->y = extents->y1;
+       
+       if (saveBits && (pNewPixmap != pBackingPixmap || nx != 0 || ny != 0))
+       {
+           pGC = GetScratchGC(pNewPixmap->drawable.depth, pScreen);
+           if (pGC)
+           {
+               ValidateGC((DrawablePtr)pNewPixmap, pGC);
+               /* if we implement a policy where the pixmap can be larger than
+                * the region extents, we might want to optimize this copyarea
+                * by only copying the old extents, rather than the entire
+                * pixmap
+                */
+               (*pGC->ops->CopyArea)((DrawablePtr)pBackingPixmap,
+                                     (DrawablePtr)pNewPixmap, pGC,
+                                     0, 0,
+                                     pBackingPixmap->drawable.width,
+                                     pBackingPixmap->drawable.height,
+                                     nx, ny);
+               FreeScratchGC(pGC);
+           }
+       }
+    }
+    /* SavedRegion is used in the backingGC clip; force an update */
+    pWin->drawable.serialNumber = NEXT_SERIAL_NUMBER;
+    if (pNewPixmap != pBackingPixmap)
+    {
+       (* pScreen->DestroyPixmap)(pBackingPixmap);
+       pBackingStore->pBackingPixmap = pNewPixmap;
+    }
+}
+
+/*-
+ *-----------------------------------------------------------------------
+ * miBSSaveDoomedAreas --
+ *     Saved the areas of the given window that are about to be
+ *     obscured.  If the window has moved, pObscured is expected to
+ *     be at the new screen location and (dx,dy) is expected to be the offset
+ *     to the window's previous location.
+ *
+ * Results:
+ *     None.
+ *
+ * Side Effects:
+ *     The region is copied from the screen into pBackingPixmap and
+ *     SavedRegion is updated.
+ *
+ *-----------------------------------------------------------------------
+ */
+static void
+miBSSaveDoomedAreas(pWin, pObscured, dx, dy)
+    register WindowPtr pWin;
+    RegionPtr         pObscured;
+    int                       dx, dy;
+{
+    miBSWindowPtr      pBackingStore;
+    ScreenPtr          pScreen;
+    int                        x, y;
+
+    pBackingStore = (miBSWindowPtr)pWin->backStorage;
+    pScreen = pWin->drawable.pScreen;
+
+    /*
+     * If the window isn't realized, it's being unmapped, thus we don't
+     * want to save anything if backingStore isn't Always.
+     */
+    if (!pWin->realized)
+    {
+       pBackingStore->viewable = (char)pWin->viewable;
+       if (pWin->backingStore != Always)
+       {
+           REGION_EMPTY( pScreen, &pBackingStore->SavedRegion);
+           miDestroyBSPixmap (pWin);
+           return;
+       }
+       if (pBackingStore->status == StatusBadAlloc)
+           pBackingStore->status = StatusNoPixmap;
+    }
+
+    /* Don't even pretend to save anything for a virtual background None */
+    if ((pBackingStore->status == StatusVirtual) &&
+       (pBackingStore->backgroundState == None))
+       return;
+
+    if (REGION_NOTEMPTY(pScreen, pObscured))
+    {
+       BoxRec  oldExtents;
+       x = pWin->drawable.x;
+       y = pWin->drawable.y;
+       REGION_TRANSLATE(pScreen, pObscured, -x, -y);
+       oldExtents = *REGION_EXTENTS(pScreen, &pBackingStore->SavedRegion);
+       REGION_UNION( pScreen, &pBackingStore->SavedRegion,
+                          &pBackingStore->SavedRegion,
+                          pObscured);
+       /*
+        * only save the bits if we've actually
+        * started using backing store
+        */
+       if (pBackingStore->status != StatusVirtual)
+       {
+           miBSScreenPtr       pScreenPriv;
+
+           pScreenPriv = (miBSScreenPtr) pScreen->devPrivates[miBSScreenIndex].ptr;
+           if (!pBackingStore->pBackingPixmap)
+               miCreateBSPixmap (pWin, &oldExtents);
+           else
+               miResizeBackingStore(pWin, 0, 0, TRUE);
+
+           if (pBackingStore->pBackingPixmap) {
+               if (pBackingStore->x | pBackingStore->y)
+               {
+                   REGION_TRANSLATE( pScreen, pObscured,
+                                                 -pBackingStore->x,
+                                                 -pBackingStore->y);
+                   x += pBackingStore->x;
+                   y += pBackingStore->y;
+               }
+               (* pScreenPriv->funcs->SaveAreas) (pBackingStore->pBackingPixmap,
+                                                  pObscured, x - dx, y - dy, pWin);
+           }
+       }
+       REGION_TRANSLATE(pScreen, pObscured, x, y);
+    }
+}
+
+/*-
+ *-----------------------------------------------------------------------
+ * miBSRestoreAreas --
+ *     Restore areas from backing-store that are no longer obscured.
+ *     expects prgnExposed to contain a screen-relative area.
+ *
+ * Results:
+ *     The region to generate exposure events on (which may be
+ *     different from the region to paint).
+ *
+ * Side Effects:
+ *     Areas are copied from pBackingPixmap to the screen. prgnExposed
+ *     is altered to contain the region that could not be restored from
+ *     backing-store.
+ *
+ * Notes:
+ *     This is called before sending any exposure events to the client,
+ *     and so might be called if the window has grown.  Changing the backing
+ *     pixmap doesn't require revalidating the backingGC because the
+ *     client's next output request will result in a call to ValidateGC,
+ *     since the window clip region has changed, which will in turn call
+ *     miValidateBackingStore.
+ *-----------------------------------------------------------------------
+ */
+static RegionPtr
+miBSRestoreAreas(pWin, prgnExposed)
+    register WindowPtr pWin;
+    RegionPtr prgnExposed;
+{
+    PixmapPtr pBackingPixmap;
+    miBSWindowPtr pBackingStore;
+    RegionPtr prgnSaved;
+    RegionPtr prgnRestored;
+    register ScreenPtr pScreen;
+    RegionPtr exposures = prgnExposed;
+
+    pScreen = pWin->drawable.pScreen;
+    pBackingStore = (miBSWindowPtr)pWin->backStorage;
+    pBackingPixmap = pBackingStore->pBackingPixmap;
+
+    prgnSaved = &pBackingStore->SavedRegion;
+
+    if (pBackingStore->status == StatusContents)
+    {
+       REGION_TRANSLATE(pScreen, prgnSaved, pWin->drawable.x,
+                        pWin->drawable.y);
+
+       prgnRestored = REGION_CREATE( pScreen, (BoxPtr)NULL, 1);
+       REGION_INTERSECT( pScreen, prgnRestored, prgnExposed, prgnSaved);
+       
+       /*
+        * Since prgnExposed is no longer obscured, we no longer
+        * will have a valid copy of it in backing-store, but there is a valid
+        * copy of it on screen, so subtract the area we just restored from
+        * from the area to be exposed.
+        */
+
+       if (REGION_NOTEMPTY( pScreen, prgnRestored))
+       {
+           miBSScreenPtr       pScreenPriv;
+
+           REGION_SUBTRACT( pScreen, prgnSaved, prgnSaved, prgnExposed);
+           REGION_SUBTRACT( pScreen, prgnExposed, prgnExposed, prgnRestored);
+
+           /*
+            * Do the actual restoration
+            */
+
+           pScreenPriv = (miBSScreenPtr)
+               pScreen->devPrivates[miBSScreenIndex].ptr;
+           (* pScreenPriv->funcs->RestoreAreas) (pBackingPixmap,
+                                         prgnRestored,
+                                         pWin->drawable.x + pBackingStore->x,
+                                         pWin->drawable.y + pBackingStore->y, pWin);
+           /*
+            * if the saved region is completely empty, dispose of the
+            * backing pixmap, otherwise, retranslate the saved
+            * region to window relative
+            */
+
+           if (REGION_NOTEMPTY(pScreen, prgnSaved))
+           {
+               REGION_TRANSLATE(pScreen, prgnSaved,
+                                            -pWin->drawable.x,
+                                            -pWin->drawable.y);
+               miResizeBackingStore(pWin, 0, 0, TRUE);
+           }
+           else
+               miDestroyBSPixmap (pWin);
+       }
+       else
+           REGION_TRANSLATE(pScreen, prgnSaved,
+                               -pWin->drawable.x, -pWin->drawable.y);
+       REGION_DESTROY( pScreen, prgnRestored);
+
+    }
+    else if ((pBackingStore->status == StatusVirtual) ||
+            (pBackingStore->status == StatusVDirty))
+    {
+       REGION_TRANSLATE(pScreen, prgnSaved,
+                                    pWin->drawable.x, pWin->drawable.y);
+       exposures = REGION_CREATE( pScreen, NullBox, 1);
+       if (SameBackground (pBackingStore->backgroundState,
+                           pBackingStore->background,
+                           pWin->backgroundState,
+                           pWin->background))
+       {
+           REGION_SUBTRACT( pScreen, exposures, prgnExposed, prgnSaved);
+       }
+       else
+       {
+           miTileVirtualBS(pWin);
+
+           /* we need to expose all we have (virtually) retiled */
+           REGION_UNION( pScreen, exposures, prgnExposed, prgnSaved);
+       }
+       REGION_SUBTRACT( pScreen, prgnSaved, prgnSaved, prgnExposed);
+       REGION_TRANSLATE(pScreen, prgnSaved,
+                                    -pWin->drawable.x, -pWin->drawable.y);
+    }
+    else if (pWin->viewable && !pBackingStore->viewable &&
+            pWin->backingStore != Always)
+    {
+       /*
+        * The window was just mapped and nothing has been saved in
+        * backing-store from the last time it was mapped. We want to capture
+        * any output to regions that are already obscured but there are no
+        * bits to snag off the screen, so we initialize things just as we did
+        * in miBSAllocate, above.
+        */
+       BoxRec  box;
+       
+       prgnSaved = &pBackingStore->SavedRegion;
+
+       box.x1 = pWin->drawable.x;
+       box.x2 = box.x1 + (int) pWin->drawable.width;
+       box.y1 = pWin->drawable.y;
+       box.y2 = box.y1 + (int) pWin->drawable.height;
+       
+       REGION_INVERSE( pScreen, prgnSaved, &pWin->clipList,  &box);
+       REGION_TRANSLATE( pScreen, prgnSaved,
+                                     -pWin->drawable.x,
+                                     -pWin->drawable.y);
+#ifdef SHAPE
+       if (wBoundingShape (pWin))
+           REGION_INTERSECT(pScreen, prgnSaved, prgnSaved,
+                            wBoundingShape (pWin));
+       if (wClipShape (pWin))
+           REGION_INTERSECT(pScreen, prgnSaved, prgnSaved,
+                            wClipShape (pWin));
+#endif
+       miTileVirtualBS(pWin);
+
+       exposures = REGION_CREATE( pScreen, &box, 1);
+    }
+    pBackingStore->viewable = (char)pWin->viewable;
+    return exposures;
+}
+
+
+/*-
+ *-----------------------------------------------------------------------
+ * miBSTranslateBackingStore --
+ *     Shift the backing-store in the given direction. Called when bit
+ *     gravity is shifting things around. 
+ *
+ * Results:
+ *     An occluded region of the window which should be sent exposure events.
+ *     This region should be in absolute coordinates (i.e. include
+ *     new window position).
+ *
+ * Side Effects:
+ *     If the window changed size as well as position, the backing pixmap
+ *     is resized. The contents of the backing pixmap are shifted
+ *
+ * Warning:
+ *     Bob and I have rewritten this routine quite a few times, each
+ *     time it gets a few more cases correct, and introducing some
+ *     interesting bugs.  Naturally, I think the code is correct this
+ *     time.
+ *
+ *     Let me try to explain what this routine is for:
+ *
+ *     It's called from SlideAndSizeWindow whenever a window
+ *     with backing store is resized.  There are two separate
+ *     possibilities:
+ *
+ *     a)  The window has ForgetGravity
+ *
+ *         In this case, windx, windy will be 0 and oldClip will
+ *         be NULL.  This indicates that all of the window contents
+ *         currently saved offscreen should be discarded, and the
+ *         entire window exposed.  TranslateBackingStore, then, should
+ *         prepare a completely new backing store region based on the
+ *         new window clipList and return that region for exposure.
+ *
+ *     b)  The window has some other gravity
+ *
+ *         In this case, windx, windy will be set to the distance
+ *         that the bits should move within the window.  oldClip
+ *         will be set to the old visible portion of the window.
+ *         TranslateBackingStore, then, should adjust the backing
+ *         store to accommodate the portion of the existing backing
+ *         store bits which coorespond to backing store bits which
+ *         will still be occluded in the new configuration.  oldx,oldy
+ *         are set to the old position of the window on the screen.
+ *
+ *         Furthermore, in this case any contents of the screen which
+ *         are about to become occluded should be fetched from the screen
+ *         and placed in backing store.  This is to avoid the eventual
+ *         occlusion by the win gravity shifting the child window bits around
+ *         on top of this window, and potentially losing information
+ *
+ *     It's also called from SetShape, but I think (he says not
+ *     really knowing for sure) that this code will even work
+ *     in that case.
+ *-----------------------------------------------------------------------
+ */
+
+static RegionPtr
+miBSTranslateBackingStore(pWin, windx, windy, oldClip, oldx, oldy)
+    WindowPtr    pWin;
+    int          windx;        /* bit translation distance in window */
+    int          windy;
+    RegionPtr    oldClip;      /* Region being copied */
+    int          oldx;         /* old window position */
+    int          oldy;
+{
+    register miBSWindowPtr     pBackingStore;
+    register RegionPtr                 pSavedRegion;
+    register RegionPtr                 newSaved, doomed;
+    register ScreenPtr         pScreen;
+    BoxRec                     extents;
+    int          scrdx;        /* bit translation distance on screen */
+    int          scrdy;
+    int                  dx;           /* distance window moved  on screen */
+    int                  dy;
+
+    pScreen = pWin->drawable.pScreen;
+    pBackingStore = (miBSWindowPtr)(pWin->backStorage);
+    if ((pBackingStore->status == StatusNoPixmap) ||
+       (pBackingStore->status == StatusBadAlloc))
+       return NullRegion;
+
+    /*
+     * Compute the new saved region
+     */
+
+    newSaved = REGION_CREATE( pScreen, NullBox, 1);
+    extents.x1 = pWin->drawable.x;
+    extents.x2 = pWin->drawable.x + (int) pWin->drawable.width;
+    extents.y1 = pWin->drawable.y;
+    extents.y2 = pWin->drawable.y + (int) pWin->drawable.height;
+    REGION_INVERSE( pScreen, newSaved, &pWin->clipList, &extents);
+
+    REGION_TRANSLATE( pScreen, newSaved,
+                       -pWin->drawable.x, -pWin->drawable.y);
+#ifdef SHAPE
+    if (wBoundingShape (pWin) || wClipShape (pWin)) {
+       if (wBoundingShape (pWin))
+           REGION_INTERSECT( pScreen, newSaved, newSaved,
+                               wBoundingShape (pWin));
+       if (wClipShape (pWin))
+           REGION_INTERSECT( pScreen, newSaved, newSaved, wClipShape (pWin));
+    }
+#endif
+    
+    pSavedRegion = &pBackingStore->SavedRegion;
+
+    /* now find any visible areas we can save from the screen */
+    /* and then translate newSaved to old local coordinates */
+    if (oldClip)
+    {
+       /* bit gravity makes things virtually too hard, punt */
+       if (((windx != 0) || (windy != 0)) &&
+           (pBackingStore->status != StatusContents))
+           miCreateBSPixmap(pWin, NullBox);
+    
+       /*
+        * The window is moving this far on the screen
+        */
+       dx = pWin->drawable.x - oldx;
+       dy = pWin->drawable.y - oldy;
+       /*
+        * The bits will be moving on the screen by the
+        * amount the window is moving + the amount the
+        * bits are moving within the window
+        */
+       scrdx = windx + dx;
+       scrdy = windy + dy;
+    
+       /*
+        * intersect at old bit position to discover the
+        * bits on the screen which can be put into the
+        * new backing store
+        */
+       REGION_TRANSLATE( pScreen, oldClip, windx - oldx, windy - oldy);
+       doomed = REGION_CREATE( pScreen, NullBox, 1);
+       REGION_INTERSECT( pScreen, doomed, oldClip, newSaved);
+       REGION_TRANSLATE( pScreen, oldClip, oldx - windx, oldy - windy);
+
+       /*
+        * Translate the old saved region to the position in the
+        * window where it will appear to be
+        */
+       REGION_TRANSLATE( pScreen, pSavedRegion, windx, windy);
+
+       /*
+        * Add the old saved region to the new saved region, so
+        * that calls to RestoreAreas will be able to fetch those
+        * bits back
+        */
+       REGION_UNION( pScreen, newSaved, newSaved, pSavedRegion);
+
+       /*
+        * Swap the new saved region into the window
+        */
+       {
+           RegionRec   tmp;
+
+           tmp = *pSavedRegion;
+           *pSavedRegion = *newSaved;
+           *newSaved = tmp;
+       }
+       miResizeBackingStore (pWin, windx, windy, TRUE);
+
+       /*
+        * Compute the newly enabled region
+        * of backing store.  This region will be
+        * set to background in the backing pixmap and
+        * sent as exposure events to the client.
+        */
+       REGION_SUBTRACT( pScreen, newSaved, pSavedRegion, newSaved);
+
+       /*
+        * Fetch bits which will be obscured from
+        * the screen
+        */
+       if (REGION_NOTEMPTY( pScreen, doomed))
+       {
+           /*
+            * Don't clear regions which have bits on the
+            * screen
+            */
+           REGION_SUBTRACT( pScreen, newSaved, newSaved, doomed);
+
+           /*
+            * Make the region to SaveDoomedAreas absolute, instead
+            * of window relative.
+            */
+           REGION_TRANSLATE( pScreen, doomed,
+                                         pWin->drawable.x, pWin->drawable.y);
+           (* pScreen->SaveDoomedAreas) (pWin, doomed, scrdx, scrdy);
+       }
+       
+       REGION_DESTROY(pScreen, doomed);
+
+       /*
+        * and clear whatever there is that's new
+        */
+       if (REGION_NOTEMPTY( pScreen, newSaved))
+       {
+           miBSClearBackingRegion (pWin, newSaved);
+           /*
+            * Make the exposed region absolute
+            */
+           REGION_TRANSLATE(pScreen, newSaved,
+                                        pWin->drawable.x,
+                                        pWin->drawable.y);
+       }
+       else
+       {
+           REGION_DESTROY(pScreen, newSaved);
+           newSaved = NullRegion;
+       }
+    }
+    else
+    {
+       /*
+        * ForgetGravity: just reset backing store and
+        * expose the whole mess
+        */
+       REGION_COPY( pScreen, pSavedRegion, newSaved);
+       REGION_TRANSLATE( pScreen, newSaved,
+                                     pWin->drawable.x, pWin->drawable.y);
+
+       miResizeBackingStore (pWin, 0, 0, FALSE);
+       (void) miBSClearBackingStore (pWin, 0, 0, 0, 0, FALSE);
+    }
+
+    return newSaved;
+}
+
+/*
+ * Inform the backing store layer that you are about to validate
+ * a gc with a window, and that subsequent output to the window
+ * is (or is not) guaranteed to be already clipped to the visible
+ * regions of the window.
+ */
+
+static void
+miBSDrawGuarantee (pWin, pGC, guarantee)
+    WindowPtr  pWin;
+    GCPtr      pGC;
+    int                guarantee;
+{
+    miBSGCPtr  pPriv;
+
+    if (pWin->backStorage)
+    {
+       pPriv = (miBSGCPtr)pGC->devPrivates[miBSGCIndex].ptr;
+       if (!pPriv)
+           (void) miBSCreateGCPrivate (pGC);
+       pPriv = (miBSGCPtr)pGC->devPrivates[miBSGCIndex].ptr;
+       if (pPriv)
+       {
+           /*
+            * XXX KLUDGE ALERT
+            *
+            * when the GC is Cheap pPriv will point
+            * at some device's gc func structure.  guarantee
+            * will point at the ChangeGC entry of that struct
+            * and will never match a valid guarantee value.
+            */
+           switch (pPriv->guarantee)
+           {
+           case GuaranteeNothing:
+           case GuaranteeVisBack:
+               pPriv->guarantee = guarantee;
+               break;
+           }
+       }
+    }
+}
+
+#define noBackingCopy (GCGraphicsExposures|GCClipXOrigin|GCClipYOrigin| \
+                      GCClipMask|GCSubwindowMode| \
+                      GCTileStipXOrigin|GCTileStipYOrigin)
+
+/*-
+ *-----------------------------------------------------------------------
+ * miBSValidateGC --
+ *     Wrapper around output-library's ValidateGC routine
+ *
+ * Results:
+ *     None.
+ *
+ * Side Effects:
+ *
+ * Notes:
+ *     The idea here is to perform several functions:
+ *         - All the output calls must be intercepted and routed to
+ *           backing-store as necessary.
+ *         - pGC in the window's devBackingStore must be set up with the
+ *           clip list appropriate for writing to pBackingPixmap (i.e.
+ *           the inverse of the window's clipList intersected with the
+ *           clientClip of the GC). Since the destination for this GC is
+ *           a pixmap, it is sufficient to set the clip list as its
+ *           clientClip.
+ *-----------------------------------------------------------------------
+ */
+
+static void
+miBSValidateGC (pGC, stateChanges, pDrawable)
+    GCPtr        pGC;
+    unsigned long stateChanges;
+    DrawablePtr   pDrawable;
+{
+    GCPtr              pBackingGC;
+    miBSWindowPtr      pWindowPriv;
+    miBSGCPtr          pPriv;
+    WindowPtr          pWin;
+    int                        lift_functions;
+    RegionPtr          backingCompositeClip = NULL;
+
+    if (pDrawable->type != DRAWABLE_PIXMAP)
+    {
+        pWin = (WindowPtr) pDrawable;
+       pWindowPriv = (miBSWindowPtr) pWin->backStorage;
+       lift_functions = (pWindowPriv == (miBSWindowPtr) NULL);
+    }
+    else
+    {
+        pWin = (WindowPtr) NULL;
+       lift_functions = TRUE;
+    }
+
+    pPriv = (miBSGCPtr)pGC->devPrivates[miBSGCIndex].ptr;
+
+    FUNC_PROLOGUE (pGC, pPriv);
+
+    (*pGC->funcs->ValidateGC) (pGC, stateChanges, pDrawable);
+
+    /*
+     * rewrap funcs and ops as Validate may have changed them
+     */
+
+    pPriv->wrapFuncs = pGC->funcs;
+    pPriv->wrapOps = pGC->ops;
+
+    if (!lift_functions && ((pPriv->guarantee == GuaranteeVisBack) ||
+                            (pWindowPriv->status == StatusNoPixmap) ||
+                            (pWindowPriv->status == StatusBadAlloc)))
+        lift_functions = TRUE;
+
+    /*
+     * check to see if a new backingCompositeClip region must
+     * be generated
+     */
+
+    if (!lift_functions && 
+        ((pDrawable->serialNumber != pPriv->serialNumber) ||
+        (stateChanges&(GCClipXOrigin|GCClipYOrigin|GCClipMask|GCSubwindowMode))))
+    {
+       if (REGION_NOTEMPTY(pGC->pScreen, &pWindowPriv->SavedRegion))
+       {
+           backingCompositeClip = REGION_CREATE(pGC->pScreen, NULL, 1);
+           if ((pGC->clientClipType == CT_NONE) || 
+               (pGC->clientClipType == CT_PIXMAP))
+           {
+               REGION_COPY(pGC->pScreen, backingCompositeClip,
+                                            &pWindowPriv->SavedRegion); 
+           }
+           else
+           {
+               /*
+                * Make a new copy of the client clip, translated to
+                * its proper origin.
+                */
+
+               REGION_COPY(pGC->pScreen, backingCompositeClip,
+                               pGC->clientClip);
+               REGION_TRANSLATE(pGC->pScreen, backingCompositeClip,
+                                                 pGC->clipOrg.x,
+                                                 pGC->clipOrg.y);
+               REGION_INTERSECT(pGC->pScreen, backingCompositeClip,
+                                       backingCompositeClip,
+                                       &pWindowPriv->SavedRegion);
+           }
+           if (pGC->subWindowMode == IncludeInferiors)
+           {
+               RegionPtr translatedClip;
+
+               /* XXX
+                * any output in IncludeInferiors mode will not
+                * be redirected to Inferiors backing store.  This
+                * can be fixed only at great cost to the shadow routines.
+                */
+               translatedClip = NotClippedByChildren (pWin);
+               REGION_TRANSLATE(pGC->pScreen, translatedClip,
+                                                 -pDrawable->x,
+                                                 -pDrawable->y);
+               REGION_SUBTRACT(pGC->pScreen, backingCompositeClip,
+                               backingCompositeClip, translatedClip);
+               REGION_DESTROY(pGC->pScreen, translatedClip);
+           }
+           if (!REGION_NOTEMPTY(pGC->pScreen, backingCompositeClip))
+               lift_functions = TRUE;
+       }
+       else
+       {
+           lift_functions = TRUE;
+       }
+
+       /* Reset the status when drawing to an unoccluded window so that
+        * future SaveAreas will actually copy bits from the screen.  Note that
+        * output to root window in IncludeInferiors mode will not cause this
+        * to change.  This causes all transient graphics by the window
+        * manager to the root window to not enable backing store.
+        */
+       if (lift_functions && (pWindowPriv->status == StatusVirtual) &&
+           (pWin->parent || pGC->subWindowMode != IncludeInferiors))
+           pWindowPriv->status = StatusVDirty;
+    }
+
+    /*
+     * if no backing store has been allocated, and it's needed,
+     * create it now.
+     */
+
+    if (!lift_functions && !pWindowPriv->pBackingPixmap)
+    {
+       miCreateBSPixmap (pWin, NullBox);
+       if (!pWindowPriv->pBackingPixmap)
+           lift_functions = TRUE;
+    }
+    
+    /*
+     * create the backing GC if needed, lift functions
+     * if the creation fails
+     */
+
+    if (!lift_functions && !pPriv->pBackingGC)
+    {
+       int status;
+       XID noexpose = xFalse;
+
+       /* We never want ops with the backingGC to generate GraphicsExpose */
+       pBackingGC = CreateGC ((DrawablePtr)pWindowPriv->pBackingPixmap,
+                              GCGraphicsExposures, &noexpose, &status);
+       if (status != Success)
+           lift_functions = TRUE;
+       else
+           pPriv->pBackingGC = pBackingGC;
+    }
+
+    pBackingGC = pPriv->pBackingGC;
+
+    pPriv->stateChanges |= stateChanges;
+
+    if (lift_functions)
+    {
+       if (backingCompositeClip)
+           REGION_DESTROY( pGC->pScreen, backingCompositeClip);
+
+       /* unwrap the GC again */
+       miBSDestroyGCPrivate (pGC);
+
+       return;
+    }
+
+    /*
+     * the rest of this function gets the pBackingGC
+     * into shape for possible draws
+     */
+
+    pPriv->stateChanges &= ~noBackingCopy;
+    if (pPriv->stateChanges)
+       CopyGC(pGC, pBackingGC, pPriv->stateChanges);
+    if ((pGC->patOrg.x - pWindowPriv->x) != pBackingGC->patOrg.x ||
+       (pGC->patOrg.y - pWindowPriv->y) != pBackingGC->patOrg.y)
+    {
+       XID vals[2];
+       vals[0] = pGC->patOrg.x - pWindowPriv->x;
+       vals[1] = pGC->patOrg.y - pWindowPriv->y;
+       DoChangeGC(pBackingGC, GCTileStipXOrigin|GCTileStipYOrigin, vals, 0);
+    }
+    pPriv->stateChanges = 0;
+
+    if (backingCompositeClip)
+    {
+       XID vals[2];
+
+       if (pGC->clientClipType == CT_PIXMAP)
+       {
+           miBSScreenPtr   pScreenPriv;
+
+           (*pBackingGC->funcs->CopyClip)(pBackingGC, pGC);
+           REGION_TRANSLATE(pGC->pScreen, backingCompositeClip,
+                                       -pGC->clipOrg.x, -pGC->clipOrg.y);
+           vals[0] = pGC->clipOrg.x - pWindowPriv->x;
+           vals[1] = pGC->clipOrg.y - pWindowPriv->y;
+           DoChangeGC(pBackingGC, GCClipXOrigin|GCClipYOrigin, vals, 0);
+           pScreenPriv = (miBSScreenPtr) 
+               pGC->pScreen->devPrivates[miBSScreenIndex].ptr;
+           (* pScreenPriv->funcs->SetClipmaskRgn)
+               (pBackingGC, backingCompositeClip);
+           REGION_DESTROY( pGC->pScreen, backingCompositeClip);
+       }
+       else
+       {
+           vals[0] = -pWindowPriv->x;
+           vals[1] = -pWindowPriv->y;
+           DoChangeGC(pBackingGC, GCClipXOrigin|GCClipYOrigin, vals, 0);
+           (*pBackingGC->funcs->ChangeClip) (pBackingGC, CT_REGION, backingCompositeClip, 0);
+       }
+       pPriv->serialNumber = pDrawable->serialNumber;
+    }
+    
+    if (pWindowPriv->pBackingPixmap->drawable.serialNumber
+       != pBackingGC->serialNumber)
+    {
+       ValidateGC((DrawablePtr)pWindowPriv->pBackingPixmap, pBackingGC);
+    }
+
+    if (pBackingGC->clientClip == 0)
+       ErrorF ("backing store clip list nil");
+
+    FUNC_EPILOGUE (pGC, pPriv);
+}
+
+static void
+miBSChangeGC (pGC, mask)
+    GCPtr   pGC;
+    unsigned long   mask;
+{
+    miBSGCPtr  pPriv = (miBSGCPtr) (pGC)->devPrivates[miBSGCIndex].ptr;
+
+    FUNC_PROLOGUE (pGC, pPriv);
+
+    (*pGC->funcs->ChangeGC) (pGC, mask);
+
+    FUNC_EPILOGUE (pGC, pPriv);
+}
+
+static void
+miBSCopyGC (pGCSrc, mask, pGCDst)
+    GCPtr   pGCSrc, pGCDst;
+    unsigned long   mask;
+{
+    miBSGCPtr  pPriv = (miBSGCPtr) (pGCDst)->devPrivates[miBSGCIndex].ptr;
+
+    FUNC_PROLOGUE (pGCDst, pPriv);
+
+    (*pGCDst->funcs->CopyGC) (pGCSrc, mask, pGCDst);
+
+    FUNC_EPILOGUE (pGCDst, pPriv);
+}
+
+static void
+miBSDestroyGC (pGC)
+    GCPtr   pGC;
+{
+    miBSGCPtr  pPriv = (miBSGCPtr) (pGC)->devPrivates[miBSGCIndex].ptr;
+
+    FUNC_PROLOGUE (pGC, pPriv);
+
+    if (pPriv->pBackingGC)
+       FreeGC(pPriv->pBackingGC, (GContext)0);
+
+    (*pGC->funcs->DestroyGC) (pGC);
+
+    FUNC_EPILOGUE (pGC, pPriv);
+
+    xfree(pPriv);
+}
+
+static void
+miBSChangeClip(pGC, type, pvalue, nrects)
+    GCPtr      pGC;
+    int                type;
+    pointer    pvalue;
+    int                nrects;
+{
+    miBSGCPtr  pPriv = (miBSGCPtr) (pGC)->devPrivates[miBSGCIndex].ptr;
+
+    FUNC_PROLOGUE (pGC, pPriv);
+
+    (* pGC->funcs->ChangeClip)(pGC, type, pvalue, nrects);
+
+    FUNC_EPILOGUE (pGC, pPriv);
+}
+
+static void
+miBSCopyClip(pgcDst, pgcSrc)
+    GCPtr pgcDst, pgcSrc;
+{
+    miBSGCPtr  pPriv = (miBSGCPtr) (pgcDst)->devPrivates[miBSGCIndex].ptr;
+
+    FUNC_PROLOGUE (pgcDst, pPriv);
+
+    (* pgcDst->funcs->CopyClip)(pgcDst, pgcSrc);
+
+    FUNC_EPILOGUE (pgcDst, pPriv);
+}
+
+static void
+miBSDestroyClip(pGC)
+    GCPtr      pGC;
+{
+    miBSGCPtr  pPriv = (miBSGCPtr) (pGC)->devPrivates[miBSGCIndex].ptr;
+
+    FUNC_PROLOGUE (pGC, pPriv);
+
+    (* pGC->funcs->DestroyClip)(pGC);
+
+    FUNC_EPILOGUE (pGC, pPriv);
+}
+
+static void
+miDestroyBSPixmap (pWin)
+    WindowPtr  pWin;
+{
+    miBSWindowPtr      pBackingStore;
+    ScreenPtr          pScreen;
+    
+    pScreen = pWin->drawable.pScreen;
+    pBackingStore = (miBSWindowPtr) pWin->backStorage;
+    if (pBackingStore->pBackingPixmap)
+       (* pScreen->DestroyPixmap)(pBackingStore->pBackingPixmap);
+    pBackingStore->pBackingPixmap = NullPixmap;
+    pBackingStore->x = 0;
+    pBackingStore->y = 0;
+    if (pBackingStore->backgroundState == BackgroundPixmap)
+       (* pScreen->DestroyPixmap)(pBackingStore->background.pixmap);
+    pBackingStore->backgroundState = None;
+    pBackingStore->status = StatusNoPixmap;
+    pWin->drawable.serialNumber = NEXT_SERIAL_NUMBER;
+}
+
+static void
+miTileVirtualBS (pWin)
+    WindowPtr  pWin;
+{
+    miBSWindowPtr      pBackingStore;
+
+    pBackingStore = (miBSWindowPtr) pWin->backStorage;
+    if (pBackingStore->backgroundState == BackgroundPixmap)
+       (* pWin->drawable.pScreen->DestroyPixmap)
+           (pBackingStore->background.pixmap);
+    pBackingStore->backgroundState = pWin->backgroundState;
+    pBackingStore->background = pWin->background;
+    if (pBackingStore->backgroundState == BackgroundPixmap)
+       pBackingStore->background.pixmap->refcnt++;
+
+    if (pBackingStore->status != StatusVDirty)
+       pBackingStore->status = StatusVirtual;
+
+    /*
+     * punt parent relative tiles and do it now
+     */
+    if (pBackingStore->backgroundState == ParentRelative)
+       miCreateBSPixmap (pWin, NullBox);
+}
+
+#ifdef DEBUG
+static int BSAllocationsFailed = 0;
+#define FAILEDSIZE     32
+static struct { int w, h; } failedRecord[FAILEDSIZE];
+static int failedIndex;
+#endif
+
+static void
+miCreateBSPixmap (pWin, pExtents)
+    WindowPtr  pWin;
+    BoxPtr     pExtents;
+{
+    miBSWindowPtr      pBackingStore;
+    ScreenPtr          pScreen;
+    PixUnion           background;
+    char               backgroundState;
+    BoxPtr             extents;
+    Bool               backSet;
+
+    pScreen = pWin->drawable.pScreen;
+    pBackingStore = (miBSWindowPtr) pWin->backStorage;
+    if (pBackingStore->status == StatusBadAlloc)
+       return;
+    backSet = ((pBackingStore->status == StatusVirtual) ||
+              (pBackingStore->status == StatusVDirty));
+
+    extents = REGION_EXTENTS( pScreen, &pBackingStore->SavedRegion);
+
+    if (!pBackingStore->pBackingPixmap)
+    {
+       /* the policy here could be more sophisticated */
+       pBackingStore->x = extents->x1;
+       pBackingStore->y = extents->y1;
+       pBackingStore->pBackingPixmap =
+           (PixmapPtr)(* pScreen->CreatePixmap)
+                          (pScreen,
+                           extents->x2 - extents->x1,
+                           extents->y2 - extents->y1,
+                           pWin->drawable.depth);
+    }
+    if (!pBackingStore->pBackingPixmap)
+    {
+#ifdef DEBUG
+       BSAllocationsFailed++;
+       /*
+        * record failed allocations
+        */
+       failedRecord[failedIndex].w = pWin->drawable.width;
+       failedRecord[failedIndex].h = pWin->drawable.height;
+       failedIndex++;
+       if (failedIndex == FAILEDSIZE)
+               failedIndex = 0;
+#endif
+#ifdef BSEAGER
+       pBackingStore->status = StatusNoPixmap;
+#else
+       pBackingStore->status = StatusBadAlloc;
+#endif
+       return;
+    }
+
+    pBackingStore->status = StatusContents;
+
+    if (backSet)
+    {
+       backgroundState = pWin->backgroundState;
+       background = pWin->background;
+    
+       pWin->backgroundState = pBackingStore->backgroundState;
+       pWin->background = pBackingStore->background;
+       if (pWin->backgroundState == BackgroundPixmap)
+           pWin->background.pixmap->refcnt++;
+    }
+
+    if (!pExtents)
+       pExtents = extents;
+
+    if (pExtents->y1 != pExtents->y2)
+    {
+       RegionPtr exposed;
+
+       exposed = miBSClearBackingStore(pWin,
+                             pExtents->x1, pExtents->y1,
+                             pExtents->x2 - pExtents->x1,
+                             pExtents->y2 - pExtents->y1,
+                             !backSet);
+       if (exposed)
+       {
+           miSendExposures(pWin, exposed, pWin->drawable.x, pWin->drawable.y);
+           REGION_DESTROY( pScreen, exposed);
+       }
+    }
+
+    if (backSet)
+    {
+       if (pWin->backgroundState == BackgroundPixmap)
+           (* pScreen->DestroyPixmap) (pWin->background.pixmap);
+       pWin->backgroundState = backgroundState;
+       pWin->background = background;
+       if (pBackingStore->backgroundState == BackgroundPixmap)
+           (* pScreen->DestroyPixmap) (pBackingStore->background.pixmap);
+       pBackingStore->backgroundState = None;
+    }
+}
+
+/*-
+ *-----------------------------------------------------------------------
+ * miBSExposeCopy --
+ *     Handle the restoration of areas exposed by graphics operations.
+ *
+ * Results:
+ *     None.
+ *
+ * Side Effects:
+ *     prgnExposed has the areas exposed from backing-store removed
+ *     from it.
+ *
+ *-----------------------------------------------------------------------
+ */
+static void
+miBSExposeCopy (pSrc, pDst, pGC, prgnExposed, srcx, srcy, dstx, dsty, plane)
+    WindowPtr          pSrc;
+    DrawablePtr                pDst;
+    GCPtr              pGC;
+    RegionPtr          prgnExposed;
+    int                        srcx, srcy;
+    int                        dstx, dsty;
+    unsigned long      plane;
+{
+    RegionRec          tempRgn;
+    miBSWindowPtr      pBackingStore;
+    RegionPtr          (*copyProc)();
+    GCPtr              pScratchGC;
+    register BoxPtr    pBox;
+    register int       i;
+    register int       dx, dy;
+    BITS32             gcMask;
+
+    if (!REGION_NOTEMPTY(pGC->pScreen, prgnExposed))
+       return;
+    pBackingStore = (miBSWindowPtr)pSrc->backStorage;
+    
+    if ((pBackingStore->status == StatusNoPixmap) ||
+       (pBackingStore->status == StatusBadAlloc))
+       return;
+
+    REGION_INIT( pGC->pScreen, &tempRgn, NullBox, 0);
+    REGION_INTERSECT( pGC->pScreen, &tempRgn, prgnExposed,
+                                &pBackingStore->SavedRegion);
+    REGION_SUBTRACT( pGC->pScreen, prgnExposed, prgnExposed, &tempRgn);
+
+    if (plane != 0) {
+       copyProc = pGC->ops->CopyPlane;
+    } else {
+       copyProc = pGC->ops->CopyArea;
+    }
+    
+    dx = dstx - srcx;
+    dy = dsty - srcy;
+    
+    switch (pBackingStore->status) {
+    case StatusVirtual:
+    case StatusVDirty:
+       pScratchGC = GetScratchGC (pDst->depth, pDst->pScreen);
+       if (pScratchGC)
+       {
+           gcMask = 0;
+           if (pGC->alu != pScratchGC->alu)
+               gcMask = GCFunction;
+           if (pGC->planemask != pScratchGC->planemask)
+               gcMask |= GCPlaneMask;
+           if (gcMask)
+               CopyGC (pGC, pScratchGC, gcMask);
+           miBSFillVirtualBits (pDst, pScratchGC, &tempRgn, dx, dy,
+                                (int) pBackingStore->backgroundState,
+                                pBackingStore->background,
+                                ~0L);
+           FreeScratchGC (pScratchGC);
+       }
+       break;
+    case StatusContents:
+       for (i = REGION_NUM_RECTS(&tempRgn), pBox = REGION_RECTS(&tempRgn);
+            --i >= 0;
+            pBox++)
+       {
+           (* copyProc) (pBackingStore->pBackingPixmap, pDst, pGC,
+                         pBox->x1 - pBackingStore->x,
+                         pBox->y1 - pBackingStore->y,
+                         pBox->x2 - pBox->x1, pBox->y2 - pBox->y1,
+                         pBox->x1 + dx, pBox->y1 + dy, plane);
+       }
+       break;
+    }
+    REGION_UNINIT( pGC->pScreen, &tempRgn);
+}
diff --git a/Xserver/programs/Xserver/mi/mibstore.h b/Xserver/programs/Xserver/mi/mibstore.h
new file mode 100644 (file)
index 0000000..00fe32e
--- /dev/null
@@ -0,0 +1,73 @@
+/*-
+ * mibstore.h --
+ *     Header file for users of the MI backing-store scheme.
+ *
+ * Copyright (c) 1987 by the Regents of the University of California
+ *
+ * Permission to use, copy, modify, and distribute this
+ * software and its documentation for any purpose and without
+ * fee is hereby granted, provided that the above copyright
+ * notice appear in all copies.  The University of California
+ * makes no representations about the suitability of this
+ * software for any purpose.  It is provided "as is" without
+ * express or implied warranty.
+ *
+ *     "$XConsortium: mibstore.h,v 5.2 93/10/12 11:41:12 dpw Exp $ SPRITE (Berkeley)"
+ */
+
+
+/* $XFree86: xc/programs/Xserver/mi/mibstore.h,v 1.2 1997/01/08 20:52:06 dawes Exp $ */
+
+#ifndef _MIBSTORE_H
+#define _MIBSTORE_H
+
+typedef struct _miBSFuncRec {
+    void           (*SaveAreas)(
+#if NeedNestedPrototypes
+                   PixmapPtr /*pBackingPixmap*/,
+                   RegionPtr /*pObscured*/,
+                   int /*x*/,
+                   int /*y*/,
+                   WindowPtr /*pWin*/
+#endif
+);
+    void           (*RestoreAreas)(
+#if NeedNestedPrototypes
+                   PixmapPtr /*pBackingPixmap*/,
+                   RegionPtr /*pExposed*/,
+                   int /*x*/,
+                   int /*y*/,
+                   WindowPtr /*pWin*/
+#endif
+);
+    void           (*SetClipmaskRgn)(
+#if NeedNestedPrototypes
+                   GCPtr /*pBackingGC*/,
+                   RegionPtr /*pbackingCompositeClip*/
+#endif
+);
+    PixmapPtr      (*GetImagePixmap)(  /* unused */
+#if NeedNestedPrototypes
+                       void
+#endif
+);
+    PixmapPtr      (*GetSpansPixmap)(  /* unused */
+#if NeedNestedPrototypes
+                       void
+#endif
+);
+} miBSFuncRec;
+
+#ifndef _XTYPEDEF_MIBSFUNCPTR
+typedef struct _miBSFuncRec *miBSFuncPtr;
+#define _XTYPEDEF_MIBSFUNCPTR
+#endif
+
+extern void miInitializeBackingStore(
+#if NeedFunctionPrototypes
+    ScreenPtr /*pScreen*/,
+    miBSFuncPtr /*funcs*/
+#endif
+);
+
+#endif /* _MIBSTORE_H */
diff --git a/Xserver/programs/Xserver/mi/mibstorest.h b/Xserver/programs/Xserver/mi/mibstorest.h
new file mode 100644 (file)
index 0000000..bfa457a
--- /dev/null
@@ -0,0 +1,92 @@
+/*
+ * mibstorest.h
+ *
+ * internal structure definitions for mi backing store
+ */
+
+/* $XConsortium: mibstorest.h,v 5.10 94/04/17 20:27:25 dpw Exp $ */
+
+/*
+
+Copyright (c) 1989  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+*/
+
+#include "mibstore.h"
+#include "regionstr.h"
+
+/*
+ * One of these structures is allocated per GC used with a backing-store
+ * drawable.
+ */
+
+typedef struct {
+    GCPtr          pBackingGC;     /* Copy of the GC but with graphicsExposures
+                                    * set FALSE and the clientClip set to
+                                    * clip output to the valid regions of the
+                                    * backing pixmap. */
+    int                    guarantee;      /* GuaranteeNothing, etc. */
+    unsigned long   serialNumber;   /* clientClip computed time */
+    unsigned long   stateChanges;   /* changes in parent gc since last copy */
+    GCOps          *wrapOps;       /* wrapped ops */
+    GCFuncs        *wrapFuncs;     /* wrapped funcs */
+} miBSGCRec, *miBSGCPtr;
+
+/*
+ * one of these structures is allocated per Window with backing store
+ */
+
+typedef struct {
+    PixmapPtr    pBackingPixmap;   /* Pixmap for saved areas */
+    short        x;                /* origin of pixmap relative to window */
+    short        y;
+    RegionRec    SavedRegion;      /* Valid area in pBackingPixmap */
+    char         viewable;         /* Tracks pWin->viewable so SavedRegion may
+                                    * be initialized correctly when the window
+                                    * is first mapped */
+    char         status;           /* StatusNoPixmap, etc. */
+    char         backgroundState;  /* background type */
+    PixUnion     background;       /* background pattern */
+} miBSWindowRec, *miBSWindowPtr;
+
+#define StatusNoPixmap 1       /* pixmap has not been created */
+#define StatusVirtual  2       /* pixmap is virtual, tiled with background */
+#define StatusVDirty   3       /* pixmap is virtual, visiblt has contents */
+#define StatusBadAlloc 4       /* pixmap create failed, do not try again */
+#define StatusContents 5       /* pixmap is created, has valid contents */
+
+typedef struct {
+    /*
+     * screen func wrappers
+     */
+    CloseScreenProcPtr CloseScreen;
+    GetImageProcPtr    GetImage;
+    GetSpansProcPtr    GetSpans;
+    ChangeWindowAttributesProcPtr ChangeWindowAttributes;
+    CreateGCProcPtr    CreateGC;
+    DestroyWindowProcPtr DestroyWindow;
+    /*
+     * pointer to vector of device-specific backing store functions
+     */
+    miBSFuncPtr            funcs;
+} miBSScreenRec, *miBSScreenPtr;
diff --git a/Xserver/programs/Xserver/mi/miclipn.c b/Xserver/programs/Xserver/mi/miclipn.c
new file mode 100644 (file)
index 0000000..9970de5
--- /dev/null
@@ -0,0 +1,75 @@
+/* $XConsortium: miclipn.c,v 5.1 94/04/17 20:27:26 rws Exp $ */
+/*
+
+Copyright (c) 1990  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be included
+in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR
+OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall
+not be used in advertising or otherwise to promote the sale, use or
+other dealings in this Software without prior written authorization
+from the X Consortium.
+
+*/
+
+#include "X.h"
+#include "windowstr.h"
+#include "scrnintstr.h"
+
+static void    (*clipNotify)() = 0;
+static void    (*ClipNotifies[MAXSCREENS])();
+
+static void
+miClipNotifyWrapper(pWin, dx, dy)
+    WindowPtr pWin;
+    int dx, dy;
+{
+    if (clipNotify)
+       (*clipNotify)(pWin, dx, dy);
+    if (ClipNotifies[pWin->drawable.pScreen->myNum])
+       (*ClipNotifies[pWin->drawable.pScreen->myNum])(pWin, dx, dy);
+}
+
+/*
+ * miClipNotify --
+ *     Hook to let DDX request notification when the clipList of
+ *     a window is recomputed on any screen.  For R4 compatibility;
+ *     better if you wrap the ClipNotify screen proc yourself.
+ */
+
+static unsigned long clipGeneration = 0;
+
+void
+miClipNotify (func)
+    void (*func)();
+{
+    int i;
+
+    clipNotify = func;
+    if (clipGeneration != serverGeneration)
+    {
+       clipGeneration = serverGeneration;
+       for (i = 0; i < screenInfo.numScreens; i++)
+       {
+           ClipNotifies[i] = screenInfo.screens[i]->ClipNotify;
+           screenInfo.screens[i]->ClipNotify = miClipNotifyWrapper;
+       }
+    }
+}
diff --git a/Xserver/programs/Xserver/mi/micursor.c b/Xserver/programs/Xserver/mi/micursor.c
new file mode 100644 (file)
index 0000000..1999170
--- /dev/null
@@ -0,0 +1,72 @@
+/***********************************************************
+
+Copyright (c) 1987  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+
+Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
+
+                        All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and its 
+documentation for any purpose and without fee is hereby granted, 
+provided that the above copyright notice appear in all copies and that
+both that copyright notice and this permission notice appear in 
+supporting documentation, and that the name of Digital not be
+used in advertising or publicity pertaining to distribution of the
+software without specific, written prior permission.  
+
+DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
+ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
+DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
+ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+SOFTWARE.
+
+******************************************************************/
+/* $XConsortium: micursor.c,v 1.10 94/04/17 20:27:26 rws Exp $ */
+#include "scrnintstr.h"
+#include "cursor.h"
+#include "misc.h"
+
+extern Bool Must_have_memory;
+
+void
+miRecolorCursor( pScr, pCurs, displayed)
+    ScreenPtr  pScr;
+    CursorPtr  pCurs;
+    Bool       displayed;
+{
+    /*
+     * This is guaranteed to correct any color-dependent state which may have
+     * been bound up in private state created by RealizeCursor
+     */
+    (* pScr->UnrealizeCursor)( pScr, pCurs);
+    Must_have_memory = TRUE; /* XXX */
+    (* pScr->RealizeCursor)( pScr, pCurs);
+    Must_have_memory = FALSE; /* XXX */
+    if ( displayed)
+       (* pScr->DisplayCursor)( pScr, pCurs);
+
+}
diff --git a/Xserver/programs/Xserver/mi/midash.c b/Xserver/programs/Xserver/mi/midash.c
new file mode 100644 (file)
index 0000000..d566ff0
--- /dev/null
@@ -0,0 +1,311 @@
+/***********************************************************
+
+Copyright (c) 1987  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+
+Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
+
+                        All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and its 
+documentation for any purpose and without fee is hereby granted, 
+provided that the above copyright notice appear in all copies and that
+both that copyright notice and this permission notice appear in 
+supporting documentation, and that the name of Digital not be
+used in advertising or publicity pertaining to distribution of the
+software without specific, written prior permission.  
+
+DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
+ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
+DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
+ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+SOFTWARE.
+
+******************************************************************/
+/* $XConsortium: midash.c,v 5.5 94/04/17 20:27:27 dpw Exp $ */
+#include "miscstruct.h"
+#include "mistruct.h"
+#include "mifpoly.h"
+
+static miDashPtr CheckDashStorage();
+
+/* return a list of DashRec.  there will be an extra
+entry at the end holding the last point of the polyline.
+   this means that the code that actually draws dashes can
+get a pair of points for every dash.  only the point in the last
+dash record is useful; the other fields are not used.
+   nseg is the number of segments, not the number of points.
+
+example:
+
+   dash1.start
+   dash2.start
+   dash3.start
+   last-point
+
+defines a list of segments
+   (dash1.pt, dash2.pt)
+   (dash2.pt, dash3.pt)
+   (dash3.pt, last-point)
+and nseg == 3.
+
+NOTE:
+    EVEN_DASH == ~ODD_DASH
+
+NOTE ALSO:
+    miDashLines may return 0 segments, going from pt[0] to pt[0] with one dash.
+*/
+
+miDashPtr
+miDashLine(npt, ppt, nDash, pDash, offset, pnseg)
+int npt;
+DDXPointPtr ppt;
+unsigned int nDash;
+unsigned char *pDash;
+unsigned int offset;
+int *pnseg;
+{
+    DDXPointRec pt1, pt2;
+    int lenCur;                /* npt used from this dash */
+    int lenMax;                /* npt in this dash */
+    int iDash = 0;     /* index of current dash */
+    int which;         /* EVEN_DASH or ODD_DASH */
+    miDashPtr pseg;    /* list of dash segments */
+    miDashPtr psegBase;        /* start of list */
+    int nseg = 0;      /* number of dashes so far */
+    int nsegMax = 0;   /* num segs we can fit in this list */
+
+    int x, y, len;
+    int adx, ady, signdx, signdy;
+    int du, dv, e1, e2, e, base_e = 0;
+
+    lenCur = offset;
+    which = EVEN_DASH;
+    while(lenCur >= pDash[iDash])
+    {
+       lenCur -= pDash[iDash];
+       iDash++;
+       if (iDash >= nDash)
+           iDash = 0;
+       which = ~which;
+    }
+    lenMax = pDash[iDash];
+
+    psegBase = (miDashPtr)NULL;
+    pt2 = ppt[0];              /* just in case there is only one point */
+
+    while(--npt)
+    {
+       if (PtEqual(ppt[0], ppt[1]))
+       {
+           ppt++;
+           continue;           /* no duplicated points in polyline */
+       }
+       pt1 = *ppt++;
+       pt2 = *ppt;
+
+       adx = pt2.x - pt1.x;
+       ady = pt2.y - pt1.y;
+       signdx = sign(adx);
+       signdy = sign(ady);
+       adx = abs(adx);
+       ady = abs(ady);
+
+       if (adx > ady)
+       {
+           du = adx;
+           dv = ady;
+           len = adx;
+       }
+       else
+       {
+           du = ady;
+           dv = adx;
+           len = ady;
+       }
+
+       e1 = dv * 2;
+       e2 = e1 - 2*du;
+       e = e1 - du;
+       x = pt1.x;
+       y = pt1.y;
+
+       nseg++;
+       pseg = CheckDashStorage(&psegBase, nseg, &nsegMax);
+       if (!pseg)
+           return (miDashPtr)NULL;
+       pseg->pt = pt1;
+       pseg->e1 = e1;
+       pseg->e2 = e2;
+       base_e = pseg->e = e;
+       pseg->which = which;
+       pseg->newLine = 1;
+
+       while (len--)
+       {
+           if (adx > ady)
+           {
+               /* X_AXIS */
+               if (((signdx > 0) && (e < 0)) ||
+                   ((signdx <=0) && (e <=0))
+                  )
+               {
+                   e += e1;
+               }
+               else
+               {
+                   y += signdy;
+                   e += e2;
+               }
+               x += signdx;
+           }
+           else
+           {
+               /* Y_AXIS */
+               if (((signdx > 0) && (e < 0)) ||
+                   ((signdx <=0) && (e <=0))
+                  )
+               {
+                   e +=e1;
+               }
+               else
+               {
+                   x += signdx;
+                   e += e2;
+               }
+               y += signdy;
+           }
+
+           lenCur++;
+           if (lenCur >= lenMax && (len || npt <= 1))
+           {
+               nseg++;
+               pseg = CheckDashStorage(&psegBase, nseg, &nsegMax);
+               if (!pseg)
+                   return (miDashPtr)NULL;
+               pseg->pt.x = x;
+               pseg->pt.y = y;
+               pseg->e1 = e1;
+               pseg->e2 = e2;
+               pseg->e = e;
+               which = ~which;
+               pseg->which = which;
+               pseg->newLine = 0;
+
+               /* move on to next dash */
+               iDash++;
+               if (iDash >= nDash)
+                   iDash = 0;
+               lenMax = pDash[iDash];
+               lenCur = 0;
+           }
+       } /* while len-- */
+    } /* while --npt */
+
+    if (lenCur == 0 && nseg != 0)
+    {
+       nseg--;
+       which = ~which;
+    }
+    *pnseg = nseg;
+    pseg = CheckDashStorage(&psegBase, nseg+1, &nsegMax);
+    if (!pseg)
+       return (miDashPtr)NULL;
+    pseg->pt = pt2;
+    pseg->e = base_e;
+    pseg->which = which;
+    pseg->newLine = 0;
+    return psegBase;
+} 
+
+
+#define NSEGDELTA 16
+
+/* returns a pointer to the pseg[nseg-1], growing the storage as
+necessary.  this interface seems unnecessarily cumbersome.
+
+*/
+
+static
+miDashPtr
+CheckDashStorage(ppseg, nseg, pnsegMax)
+miDashPtr *ppseg;              /* base pointer */
+int nseg;                      /* number of segment we want to write to */
+int *pnsegMax;                 /* size (in segments) of list so far */
+{
+    if (nseg > *pnsegMax)
+    {
+       miDashPtr newppseg;
+
+       *pnsegMax += NSEGDELTA;
+       newppseg = (miDashPtr)xrealloc(*ppseg,
+                                      (*pnsegMax)*sizeof(miDashRec));
+       if (!newppseg)
+       {
+           xfree(*ppseg);
+           return (miDashPtr)NULL;
+       }
+       *ppseg = newppseg;
+    }
+    return(*ppseg+(nseg-1));
+}
+
+void
+miStepDash (dist, pDashIndex, pDash, numInDashList, pDashOffset)
+    int dist;                  /* distance to step */
+    int *pDashIndex;           /* current dash */
+    unsigned char *pDash;      /* dash list */
+    int numInDashList;         /* total length of dash list */
+    int *pDashOffset;          /* offset into current dash */
+{
+    int        dashIndex, dashOffset;
+    int totallen;
+    int        i;
+    
+    dashIndex = *pDashIndex;
+    dashOffset = *pDashOffset;
+    if (dist < pDash[dashIndex] - dashOffset)
+    {
+       *pDashOffset = dashOffset + dist;
+       return;
+    }
+    dist -= pDash[dashIndex] - dashOffset;
+    if (++dashIndex == numInDashList)
+       dashIndex = 0;
+    totallen = 0;
+    for (i = 0; i < numInDashList; i++)
+       totallen += pDash[i];
+    if (totallen <= dist)
+       dist = dist % totallen;
+    while (dist >= pDash[dashIndex])
+    {
+       dist -= pDash[dashIndex];
+       if (++dashIndex == numInDashList)
+           dashIndex = 0;
+    }
+    *pDashIndex = dashIndex;
+    *pDashOffset = dist;
+}
diff --git a/Xserver/programs/Xserver/mi/midispcur.c b/Xserver/programs/Xserver/mi/midispcur.c
new file mode 100644 (file)
index 0000000..5ea478e
--- /dev/null
@@ -0,0 +1,615 @@
+/*
+ * midispcur.c
+ *
+ * machine independent cursor display routines
+ */
+
+/* $XConsortium: midispcur.c,v 5.14 94/04/17 20:27:28 dpw Exp $ */
+
+/*
+
+Copyright (c) 1989  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+*/
+
+#define NEED_EVENTS
+# include   "X.h"
+# include   "misc.h"
+# include   "input.h"
+# include   "cursorstr.h"
+# include   "windowstr.h"
+# include   "regionstr.h"
+# include   "dixstruct.h"
+# include   "scrnintstr.h"
+# include   "servermd.h"
+# include   "mipointer.h"
+# include   "misprite.h"
+# include   "gcstruct.h"
+
+extern WindowPtr    *WindowTable;
+
+/* per-screen private data */
+
+static int     miDCScreenIndex;
+static unsigned long miDCGeneration = 0;
+
+static Bool    miDCCloseScreen();
+
+typedef struct {
+    GCPtr          pSourceGC, pMaskGC;
+    GCPtr          pSaveGC, pRestoreGC;
+    GCPtr          pMoveGC;
+    GCPtr          pPixSourceGC, pPixMaskGC;
+    CloseScreenProcPtr CloseScreen;
+    PixmapPtr      pSave, pTemp;
+} miDCScreenRec, *miDCScreenPtr;
+
+/* per-cursor per-screen private data */
+typedef struct {
+    PixmapPtr          sourceBits;         /* source bits */
+    PixmapPtr          maskBits;           /* mask bits */
+} miDCCursorRec, *miDCCursorPtr;
+
+/*
+ * sprite/cursor method table
+ */
+
+static Bool    miDCRealizeCursor(),        miDCUnrealizeCursor();
+static Bool    miDCPutUpCursor(),          miDCSaveUnderCursor();
+static Bool    miDCRestoreUnderCursor(),   miDCMoveCursor();
+static Bool    miDCChangeSave();
+
+static miSpriteCursorFuncRec miDCFuncs = {
+    miDCRealizeCursor,
+    miDCUnrealizeCursor,
+    miDCPutUpCursor,
+    miDCSaveUnderCursor,
+    miDCRestoreUnderCursor,
+    miDCMoveCursor,
+    miDCChangeSave,
+};
+
+Bool
+miDCInitialize (pScreen, screenFuncs)
+    ScreenPtr              pScreen;
+    miPointerScreenFuncPtr  screenFuncs;
+{
+    miDCScreenPtr   pScreenPriv;
+
+    if (miDCGeneration != serverGeneration)
+    {
+       miDCScreenIndex = AllocateScreenPrivateIndex ();
+       if (miDCScreenIndex < 0)
+           return FALSE;
+       miDCGeneration = serverGeneration;
+    }
+    pScreenPriv = (miDCScreenPtr) xalloc (sizeof (miDCScreenRec));
+    if (!pScreenPriv)
+       return FALSE;
+
+    /*
+     * initialize the entire private structure to zeros
+     */
+
+    pScreenPriv->pSourceGC =
+       pScreenPriv->pMaskGC =
+       pScreenPriv->pSaveGC =
+       pScreenPriv->pRestoreGC =
+       pScreenPriv->pMoveGC =
+       pScreenPriv->pPixSourceGC =
+       pScreenPriv->pPixMaskGC = NULL;
+    
+    pScreenPriv->pSave = pScreenPriv->pTemp = NULL;
+
+    pScreenPriv->CloseScreen = pScreen->CloseScreen;
+    pScreen->CloseScreen = miDCCloseScreen;
+    
+    pScreen->devPrivates[miDCScreenIndex].ptr = (pointer) pScreenPriv;
+
+    if (!miSpriteInitialize (pScreen, &miDCFuncs, screenFuncs))
+    {
+       xfree ((pointer) pScreenPriv);
+       return FALSE;
+    }
+    return TRUE;
+}
+
+#define tossGC(gc)  (gc ? FreeGC (gc, (GContext) 0) : 0)
+#define tossPix(pix)   (pix ? (*pScreen->DestroyPixmap) (pix) : TRUE)
+
+static Bool
+miDCCloseScreen (index, pScreen)
+    ScreenPtr  pScreen;
+{
+    miDCScreenPtr   pScreenPriv;
+
+    pScreenPriv = (miDCScreenPtr) pScreen->devPrivates[miDCScreenIndex].ptr;
+    pScreen->CloseScreen = pScreenPriv->CloseScreen;
+    tossGC (pScreenPriv->pSourceGC);
+    tossGC (pScreenPriv->pMaskGC);
+    tossGC (pScreenPriv->pSaveGC);
+    tossGC (pScreenPriv->pRestoreGC);
+    tossGC (pScreenPriv->pMoveGC);
+    tossGC (pScreenPriv->pPixSourceGC);
+    tossGC (pScreenPriv->pPixMaskGC);
+    tossPix (pScreenPriv->pSave);
+    tossPix (pScreenPriv->pTemp);
+    xfree ((pointer) pScreenPriv);
+    return (*pScreen->CloseScreen) (index, pScreen);
+}
+
+static Bool
+miDCRealizeCursor (pScreen, pCursor)
+    ScreenPtr  pScreen;
+    CursorPtr  pCursor;
+{
+    if (pCursor->bits->refcnt <= 1)
+       pCursor->bits->devPriv[pScreen->myNum] = (pointer)NULL;
+    return TRUE;
+}
+
+static miDCCursorPtr
+miDCRealize (pScreen, pCursor)
+    ScreenPtr  pScreen;
+    CursorPtr  pCursor;
+{
+    miDCCursorPtr   pPriv;
+    GCPtr          pGC;
+    XID                    gcvals[3];
+
+    pPriv = (miDCCursorPtr) xalloc (sizeof (miDCCursorRec));
+    if (!pPriv)
+       return (miDCCursorPtr)NULL;
+    pPriv->sourceBits = (*pScreen->CreatePixmap) (pScreen, pCursor->bits->width, pCursor->bits->height, 1);
+    if (!pPriv->sourceBits)
+    {
+       xfree ((pointer) pPriv);
+       return (miDCCursorPtr)NULL;
+    }
+    pPriv->maskBits =  (*pScreen->CreatePixmap) (pScreen, pCursor->bits->width, pCursor->bits->height, 1);
+    if (!pPriv->maskBits)
+    {
+       (*pScreen->DestroyPixmap) (pPriv->sourceBits);
+       xfree ((pointer) pPriv);
+       return (miDCCursorPtr)NULL;
+    }
+    pCursor->bits->devPriv[pScreen->myNum] = (pointer) pPriv;
+
+    /* create the two sets of bits, clipping as appropriate */
+
+    pGC = GetScratchGC (1, pScreen);
+    if (!pGC)
+    {
+       (void) miDCUnrealizeCursor (pScreen, pCursor);
+       return (miDCCursorPtr)NULL;
+    }
+
+    ValidateGC ((DrawablePtr)pPriv->sourceBits, pGC);
+    (*pGC->ops->PutImage) ((DrawablePtr)pPriv->sourceBits, pGC, 1,
+                          0, 0, pCursor->bits->width, pCursor->bits->height,
+                          0, XYPixmap, (char *)pCursor->bits->source);
+    gcvals[0] = GXand;
+    ChangeGC (pGC, GCFunction, gcvals);
+    ValidateGC ((DrawablePtr)pPriv->sourceBits, pGC);
+    (*pGC->ops->PutImage) ((DrawablePtr)pPriv->sourceBits, pGC, 1,
+                          0, 0, pCursor->bits->width, pCursor->bits->height,
+                          0, XYPixmap, (char *)pCursor->bits->mask);
+
+    /* mask bits -- pCursor->mask & ~pCursor->source */
+    gcvals[0] = GXcopy;
+    ChangeGC (pGC, GCFunction, gcvals);
+    ValidateGC ((DrawablePtr)pPriv->maskBits, pGC);
+    (*pGC->ops->PutImage) ((DrawablePtr)pPriv->maskBits, pGC, 1,
+                          0, 0, pCursor->bits->width, pCursor->bits->height,
+                          0, XYPixmap, (char *)pCursor->bits->mask);
+    gcvals[0] = GXandInverted;
+    ChangeGC (pGC, GCFunction, gcvals);
+    ValidateGC ((DrawablePtr)pPriv->maskBits, pGC);
+    (*pGC->ops->PutImage) ((DrawablePtr)pPriv->maskBits, pGC, 1,
+                          0, 0, pCursor->bits->width, pCursor->bits->height,
+                          0, XYPixmap, (char *)pCursor->bits->source);
+    FreeScratchGC (pGC);
+    return pPriv;
+}
+
+static Bool
+miDCUnrealizeCursor (pScreen, pCursor)
+    ScreenPtr  pScreen;
+    CursorPtr  pCursor;
+{
+    miDCCursorPtr   pPriv;
+
+    pPriv = (miDCCursorPtr) pCursor->bits->devPriv[pScreen->myNum];
+    if (pPriv && (pCursor->bits->refcnt <= 1))
+    {
+       (*pScreen->DestroyPixmap) (pPriv->sourceBits);
+       (*pScreen->DestroyPixmap) (pPriv->maskBits);
+       xfree ((pointer) pPriv);
+       pCursor->bits->devPriv[pScreen->myNum] = (pointer)NULL;
+    }
+    return TRUE;
+}
+
+static void
+miDCPutBits (pDrawable, pPriv, sourceGC, maskGC, x, y, w, h, source, mask)
+    DrawablePtr            pDrawable;
+    GCPtr          sourceGC, maskGC;
+    int             x, y;
+    unsigned        w, h;
+    miDCCursorPtr   pPriv;
+    unsigned long   source, mask;
+{
+    XID            gcvals[1];
+
+    if (sourceGC->fgPixel != source)
+    {
+       gcvals[0] = source;
+       DoChangeGC (sourceGC, GCForeground, gcvals, 0);
+    }
+    if (sourceGC->serialNumber != pDrawable->serialNumber)
+       ValidateGC (pDrawable, sourceGC);
+    (*sourceGC->ops->PushPixels) (sourceGC, pPriv->sourceBits, pDrawable, w, h, x, y);
+    if (maskGC->fgPixel != mask)
+    {
+       gcvals[0] = mask;
+       DoChangeGC (maskGC, GCForeground, gcvals, 0);
+    }
+    if (maskGC->serialNumber != pDrawable->serialNumber)
+       ValidateGC (pDrawable, maskGC);
+    (*maskGC->ops->PushPixels) (maskGC, pPriv->maskBits, pDrawable, w, h, x, y);
+}
+
+#define EnsureGC(gc,win) (gc || miDCMakeGC(&gc, win))
+
+static GCPtr
+miDCMakeGC(ppGC, pWin)
+    GCPtr      *ppGC;
+    WindowPtr  pWin;
+{
+    GCPtr pGC;
+    int   status;
+    XID   gcvals[2];
+
+    gcvals[0] = IncludeInferiors;
+    gcvals[1] = FALSE;
+    pGC = CreateGC((DrawablePtr)pWin,
+                  GCSubwindowMode|GCGraphicsExposures, gcvals, &status);
+    if (pGC)
+       (*pWin->drawable.pScreen->DrawGuarantee) (pWin, pGC, GuaranteeVisBack);
+    *ppGC = pGC;
+    return pGC;
+}
+
+static Bool
+miDCPutUpCursor (pScreen, pCursor, x, y, source, mask)
+    ScreenPtr      pScreen;
+    CursorPtr      pCursor;
+    int                    x, y;
+    unsigned long   source, mask;
+{
+    miDCScreenPtr   pScreenPriv;
+    miDCCursorPtr   pPriv;
+    WindowPtr      pWin;
+
+    pPriv = (miDCCursorPtr) pCursor->bits->devPriv[pScreen->myNum];
+    if (!pPriv)
+    {
+       pPriv = miDCRealize(pScreen, pCursor);
+       if (!pPriv)
+           return FALSE;
+    }
+    pScreenPriv = (miDCScreenPtr) pScreen->devPrivates[miDCScreenIndex].ptr;
+    pWin = WindowTable[pScreen->myNum];
+    if (!EnsureGC(pScreenPriv->pSourceGC, pWin))
+       return FALSE;
+    if (!EnsureGC(pScreenPriv->pMaskGC, pWin))
+    {
+       FreeGC (pScreenPriv->pSourceGC, (GContext) 0);
+       pScreenPriv->pSourceGC = 0;
+       return FALSE;
+    }
+    miDCPutBits ((DrawablePtr)pWin, pPriv,
+                pScreenPriv->pSourceGC, pScreenPriv->pMaskGC,
+                x, y, pCursor->bits->width, pCursor->bits->height,
+                source, mask);
+    return TRUE;
+}
+
+static Bool
+miDCSaveUnderCursor (pScreen, x, y, w, h)
+    ScreenPtr  pScreen;
+    int                x, y, w, h;
+{
+    miDCScreenPtr   pScreenPriv;
+    PixmapPtr      pSave;
+    WindowPtr      pWin;
+    GCPtr          pGC;
+
+    pScreenPriv = (miDCScreenPtr) pScreen->devPrivates[miDCScreenIndex].ptr;
+    pSave = pScreenPriv->pSave;
+    pWin = WindowTable[pScreen->myNum];
+    if (!pSave || pSave->drawable.width < w || pSave->drawable.height < h)
+    {
+       if (pSave)
+           (*pScreen->DestroyPixmap) (pSave);
+       pScreenPriv->pSave = pSave =
+               (*pScreen->CreatePixmap) (pScreen, w, h, pScreen->rootDepth);
+       if (!pSave)
+           return FALSE;
+    }
+    if (!EnsureGC(pScreenPriv->pSaveGC, pWin))
+       return FALSE;
+    pGC = pScreenPriv->pSaveGC;
+    if (pSave->drawable.serialNumber != pGC->serialNumber)
+       ValidateGC ((DrawablePtr) pSave, pGC);
+    (*pGC->ops->CopyArea) ((DrawablePtr) pWin, (DrawablePtr) pSave, pGC,
+                           x, y, w, h, 0, 0);
+    return TRUE;
+}
+
+static Bool
+miDCRestoreUnderCursor (pScreen, x, y, w, h)
+    ScreenPtr  pScreen;
+    int                x, y, w, h;
+{
+    miDCScreenPtr   pScreenPriv;
+    PixmapPtr      pSave;
+    WindowPtr      pWin;
+    GCPtr          pGC;
+
+    pScreenPriv = (miDCScreenPtr) pScreen->devPrivates[miDCScreenIndex].ptr;
+    pSave = pScreenPriv->pSave;
+    pWin = WindowTable[pScreen->myNum];
+    if (!pSave)
+       return FALSE;
+    if (!EnsureGC(pScreenPriv->pRestoreGC, pWin))
+       return FALSE;
+    pGC = pScreenPriv->pRestoreGC;
+    if (pWin->drawable.serialNumber != pGC->serialNumber)
+       ValidateGC ((DrawablePtr) pWin, pGC);
+    (*pGC->ops->CopyArea) ((DrawablePtr) pSave, (DrawablePtr) pWin, pGC,
+                           0, 0, w, h, x, y);
+    return TRUE;
+}
+
+static Bool
+miDCChangeSave (pScreen, x, y, w, h, dx, dy)
+    ScreenPtr      pScreen;
+    int                    x, y, w, h, dx, dy;
+{
+    miDCScreenPtr   pScreenPriv;
+    PixmapPtr      pSave;
+    WindowPtr      pWin;
+    GCPtr          pGC;
+    int                    sourcex, sourcey, destx, desty, copyw, copyh;
+
+    pScreenPriv = (miDCScreenPtr) pScreen->devPrivates[miDCScreenIndex].ptr;
+    pSave = pScreenPriv->pSave;
+    pWin = WindowTable[pScreen->myNum];
+    /*
+     * restore the bits which are about to get trashed
+     */
+    if (!pSave)
+       return FALSE;
+    if (!EnsureGC(pScreenPriv->pRestoreGC, pWin))
+       return FALSE;
+    pGC = pScreenPriv->pRestoreGC;
+    if (pWin->drawable.serialNumber != pGC->serialNumber)
+       ValidateGC ((DrawablePtr) pWin, pGC);
+    /*
+     * copy the old bits to the screen.
+     */
+    if (dy > 0)
+    {
+       (*pGC->ops->CopyArea) ((DrawablePtr) pSave, (DrawablePtr) pWin, pGC,
+                              0, h - dy, w, dy, x + dx, y + h);
+    }
+    else if (dy < 0)
+    {
+       (*pGC->ops->CopyArea) ((DrawablePtr) pSave, (DrawablePtr) pWin, pGC,
+                              0, 0, w, -dy, x + dx, y + dy);
+    }
+    if (dy >= 0)
+    {
+       desty = y + dy;
+       sourcey = 0;
+       copyh = h - dy;
+    }
+    else
+    {
+       desty = y;
+       sourcey = - dy;
+       copyh = h + dy;
+    }
+    if (dx > 0)
+    {
+       (*pGC->ops->CopyArea) ((DrawablePtr) pSave, (DrawablePtr) pWin, pGC,
+                              w - dx, sourcey, dx, copyh, x + w, desty);
+    }
+    else if (dx < 0)
+    {
+       (*pGC->ops->CopyArea) ((DrawablePtr) pSave, (DrawablePtr) pWin, pGC,
+                              0, sourcey, -dx, copyh, x + dx, desty);
+    }
+    if (!EnsureGC(pScreenPriv->pSaveGC, pWin))
+       return FALSE;
+    pGC = pScreenPriv->pSaveGC;
+    if (pSave->drawable.serialNumber != pGC->serialNumber)
+       ValidateGC ((DrawablePtr) pSave, pGC);
+    /*
+     * move the bits that are still valid within the pixmap
+     */
+    if (dx >= 0)
+    {
+       sourcex = 0;
+       destx = dx;
+       copyw = w - dx;
+    }
+    else
+    {
+       destx = 0;
+       sourcex = - dx;
+       copyw = w + dx;
+    }
+    if (dy >= 0)
+    {
+       sourcey = 0;
+       desty = dy;
+       copyh = h - dy;
+    }
+    else
+    {
+       desty = 0;
+       sourcey = -dy;
+       copyh = h + dy;
+    }
+    (*pGC->ops->CopyArea) ((DrawablePtr) pSave, (DrawablePtr) pSave, pGC,
+                          sourcex, sourcey, copyw, copyh, destx, desty);
+    /*
+     * copy the new bits from the screen into the remaining areas of the
+     * pixmap
+     */
+    if (dy > 0)
+    {
+       (*pGC->ops->CopyArea) ((DrawablePtr) pWin, (DrawablePtr) pSave, pGC,
+                              x, y, w, dy, 0, 0);
+    }
+    else if (dy < 0)
+    {
+       (*pGC->ops->CopyArea) ((DrawablePtr) pWin, (DrawablePtr) pSave, pGC,
+                              x, y + h + dy, w, -dy, 0, h + dy);
+    }
+    if (dy >= 0)
+    {
+       desty = dy;
+       sourcey = y + dy;
+       copyh = h - dy;
+    }
+    else
+    {
+       desty = 0;
+       sourcey = y;
+       copyh = h + dy;
+    }
+    if (dx > 0)
+    {
+       (*pGC->ops->CopyArea) ((DrawablePtr) pWin, (DrawablePtr) pSave, pGC,
+                              x, sourcey, dx, copyh, 0, desty);
+    }
+    else if (dx < 0)
+    {
+       (*pGC->ops->CopyArea) ((DrawablePtr) pWin, (DrawablePtr) pSave, pGC,
+                              x + w + dx, sourcey, -dx, copyh, w + dx, desty);
+    }
+    return TRUE;
+}
+
+static Bool
+miDCMoveCursor (pScreen, pCursor, x, y, w, h, dx, dy, source, mask)
+    ScreenPtr      pScreen;
+    CursorPtr      pCursor;
+    int                    x, y, w, h, dx, dy;
+    unsigned long   source, mask;
+{
+    miDCCursorPtr   pPriv;
+    miDCScreenPtr   pScreenPriv;
+    int                    status;
+    WindowPtr      pWin;
+    GCPtr          pGC;
+    XID                    gcval = FALSE;
+    PixmapPtr      pTemp;
+
+    pPriv = (miDCCursorPtr) pCursor->bits->devPriv[pScreen->myNum];
+    if (!pPriv)
+    {
+       pPriv = miDCRealize(pScreen, pCursor);
+       if (!pPriv)
+           return FALSE;
+    }
+    pScreenPriv = (miDCScreenPtr) pScreen->devPrivates[miDCScreenIndex].ptr;
+    pWin = WindowTable[pScreen->myNum];
+    pTemp = pScreenPriv->pTemp;
+    if (!pTemp ||
+       pTemp->drawable.width != pScreenPriv->pSave->drawable.width ||
+       pTemp->drawable.height != pScreenPriv->pSave->drawable.height)
+    {
+       if (pTemp)
+           (*pScreen->DestroyPixmap) (pTemp);
+       pScreenPriv->pTemp = pTemp = (*pScreen->CreatePixmap)
+           (pScreen, w, h, pScreenPriv->pSave->drawable.depth);
+       if (!pTemp)
+           return FALSE;
+    }
+    if (!pScreenPriv->pMoveGC)
+    {
+       pScreenPriv->pMoveGC = CreateGC ((DrawablePtr)pTemp,
+           GCGraphicsExposures, &gcval, &status);
+       if (!pScreenPriv->pMoveGC)
+           return FALSE;
+    }
+    /*
+     * copy the saved area to a temporary pixmap
+     */
+    pGC = pScreenPriv->pMoveGC;
+    if (pGC->serialNumber != pTemp->drawable.serialNumber)
+       ValidateGC ((DrawablePtr) pTemp, pGC);
+    (*pGC->ops->CopyArea)((DrawablePtr)pScreenPriv->pSave,
+                         (DrawablePtr)pTemp, pGC, 0, 0, w, h, 0, 0);
+    
+    /*
+     * draw the cursor in the temporary pixmap
+     */
+    if (!pScreenPriv->pPixSourceGC)
+    {
+       pScreenPriv->pPixSourceGC = CreateGC ((DrawablePtr)pTemp,
+           GCGraphicsExposures, &gcval, &status);
+       if (!pScreenPriv->pPixSourceGC)
+           return FALSE;
+    }
+    if (!pScreenPriv->pPixMaskGC)
+    {
+       pScreenPriv->pPixMaskGC = CreateGC ((DrawablePtr)pTemp,
+           GCGraphicsExposures, &gcval, &status);
+       if (!pScreenPriv->pPixMaskGC)
+           return FALSE;
+    }
+    miDCPutBits ((DrawablePtr)pTemp, pPriv,
+                pScreenPriv->pPixSourceGC, pScreenPriv->pPixMaskGC,
+                dx, dy, pCursor->bits->width, pCursor->bits->height,
+                source, mask);
+
+    /*
+     * copy the temporary pixmap onto the screen
+     */
+
+    if (!EnsureGC(pScreenPriv->pRestoreGC, pWin))
+       return FALSE;
+    pGC = pScreenPriv->pRestoreGC;
+    if (pWin->drawable.serialNumber != pGC->serialNumber)
+       ValidateGC ((DrawablePtr) pWin, pGC);
+
+    (*pGC->ops->CopyArea) ((DrawablePtr) pTemp, (DrawablePtr) pWin,
+                           pGC,
+                           0, 0, w, h, x, y);
+    return TRUE;
+}
diff --git a/Xserver/programs/Xserver/mi/mieq.c b/Xserver/programs/Xserver/mi/mieq.c
new file mode 100644 (file)
index 0000000..0f338de
--- /dev/null
@@ -0,0 +1,192 @@
+/*
+ * $XConsortium: mieq.c,v 1.8 94/11/02 15:59:29 kaleb Exp $
+ *
+Copyright (c) 1990  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+ *
+ * Author:  Keith Packard, MIT X Consortium
+ */
+
+/*
+ * mieq.c
+ *
+ * Machine independent event queue
+ *
+ */
+
+# define NEED_EVENTS
+# include   "X.h"
+# include   "Xmd.h"
+# include   "Xproto.h"
+# include   "misc.h"
+# include   "windowstr.h"
+# include   "pixmapstr.h"
+# include   "inputstr.h"
+# include   "mi.h"
+# include   "scrnintstr.h"
+
+#define QUEUE_SIZE  256
+
+typedef struct _Event {
+    xEvent     event;
+    ScreenPtr  pScreen;
+} EventRec, *EventPtr;
+
+typedef struct _EventQueue {
+    HWEventQueueType   head, tail;         /* long for SetInputCheck */
+    CARD32     lastEventTime;      /* to avoid time running backwards */
+    Bool       lastMotion;
+    EventRec   events[QUEUE_SIZE]; /* static allocation for signals */
+    DevicePtr  pKbd, pPtr;         /* device pointer, to get funcs */
+    ScreenPtr  pEnqueueScreen;     /* screen events are being delivered to */
+    ScreenPtr  pDequeueScreen;     /* screen events are being dispatched to */
+} EventQueueRec, *EventQueuePtr;
+
+static EventQueueRec miEventQueue;
+
+Bool
+mieqInit (pKbd, pPtr)
+    DevicePtr  pKbd, pPtr;
+{
+    miEventQueue.head = miEventQueue.tail = 0;
+    miEventQueue.lastEventTime = GetTimeInMillis ();
+    miEventQueue.pKbd = pKbd;
+    miEventQueue.pPtr = pPtr;
+    miEventQueue.lastMotion = FALSE;
+    miEventQueue.pEnqueueScreen = screenInfo.screens[0];
+    miEventQueue.pDequeueScreen = miEventQueue.pEnqueueScreen;
+    SetInputCheck (&miEventQueue.head, &miEventQueue.tail);
+    return TRUE;
+}
+
+/*
+ * Must be reentrant with ProcessInputEvents.  Assumption: mieqEnqueue
+ * will never be interrupted.  If this is called from both signal
+ * handlers and regular code, make sure the signal is suspended when
+ * called from regular code.
+ */
+
+void
+mieqEnqueue (e)
+    xEvent     *e;
+{
+    HWEventQueueType   oldtail, newtail, prevtail;
+    Bool    isMotion;
+
+    oldtail = miEventQueue.tail;
+    isMotion = e->u.u.type == MotionNotify;
+    if (isMotion && miEventQueue.lastMotion && oldtail != miEventQueue.head)
+    {
+       if (oldtail == 0)
+           oldtail = QUEUE_SIZE;
+       oldtail = oldtail - 1;
+    }
+    else
+    {
+       newtail = oldtail + 1;
+       if (newtail == QUEUE_SIZE)
+           newtail = 0;
+       /* Toss events which come in late */
+       if (newtail == miEventQueue.head)
+           return;
+       miEventQueue.tail = newtail;
+    }
+    miEventQueue.lastMotion = isMotion;
+    miEventQueue.events[oldtail].event = *e;
+    /*
+     * Make sure that event times don't go backwards - this
+     * is "unnecessary", but very useful
+     */
+    if (e->u.keyButtonPointer.time < miEventQueue.lastEventTime &&
+       miEventQueue.lastEventTime - e->u.keyButtonPointer.time < 10000)
+    {
+       miEventQueue.events[oldtail].event.u.keyButtonPointer.time =
+           miEventQueue.lastEventTime;
+    }
+    miEventQueue.events[oldtail].pScreen = miEventQueue.pEnqueueScreen;
+}
+
+void
+mieqSwitchScreen (pScreen, fromDIX)
+    ScreenPtr  pScreen;
+    Bool       fromDIX;
+{
+    miEventQueue.pEnqueueScreen = pScreen;
+    if (fromDIX)
+       miEventQueue.pDequeueScreen = pScreen;
+}
+
+/*
+ * Call this from ProcessInputEvents()
+ */
+
+mieqProcessInputEvents ()
+{
+    EventRec   *e;
+    int                x, y;
+    xEvent     xe;
+
+    while (miEventQueue.head != miEventQueue.tail)
+    {
+       extern int  screenIsSaved;
+
+       if (screenIsSaved == SCREEN_SAVER_ON)
+           SaveScreens (SCREEN_SAVER_OFF, ScreenSaverReset);
+
+       e = &miEventQueue.events[miEventQueue.head];
+       /*
+        * Assumption - screen switching can only occur on motion events
+        */
+       if (e->pScreen != miEventQueue.pDequeueScreen)
+       {
+           miEventQueue.pDequeueScreen = e->pScreen;
+           x = e->event.u.keyButtonPointer.rootX;
+           y = e->event.u.keyButtonPointer.rootY;
+           if (miEventQueue.head == QUEUE_SIZE - 1)
+               miEventQueue.head = 0;
+           else
+               ++miEventQueue.head;
+           NewCurrentScreen (miEventQueue.pDequeueScreen, x, y);
+       }
+       else
+       {
+           xe = e->event;
+           if (miEventQueue.head == QUEUE_SIZE - 1)
+               miEventQueue.head = 0;
+           else
+               ++miEventQueue.head;
+           switch (xe.u.u.type) 
+           {
+           case KeyPress:
+           case KeyRelease:
+               (*miEventQueue.pKbd->processInputProc)
+                               (&xe, (DeviceIntPtr)miEventQueue.pKbd, 1);
+               break;
+           default:
+               (*miEventQueue.pPtr->processInputProc)
+                               (&xe, (DeviceIntPtr)miEventQueue.pPtr, 1);
+               break;
+           }
+       }
+    }
+}
diff --git a/Xserver/programs/Xserver/mi/miexpose.c b/Xserver/programs/Xserver/mi/miexpose.c
new file mode 100644 (file)
index 0000000..b1e4d16
--- /dev/null
@@ -0,0 +1,829 @@
+/***********************************************************
+
+Copyright (c) 1987  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+
+Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
+
+                        All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and its 
+documentation for any purpose and without fee is hereby granted, 
+provided that the above copyright notice appear in all copies and that
+both that copyright notice and this permission notice appear in 
+supporting documentation, and that the name of Digital not be
+used in advertising or publicity pertaining to distribution of the
+software without specific, written prior permission.  
+
+DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
+ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
+DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
+ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+SOFTWARE.
+
+******************************************************************/
+
+/* $XConsortium: miexpose.c /main/43 1996/08/01 19:25:26 dpw $ */
+/* $XFree86: xc/programs/Xserver/mi/miexpose.c,v 3.1 1996/12/23 07:09:44 dawes Exp $ */
+
+#include "X.h"
+#define NEED_EVENTS
+#include "Xproto.h"
+#include "Xprotostr.h"
+
+#include "misc.h"
+#include "regionstr.h"
+#include "scrnintstr.h"
+#include "gcstruct.h"
+#include "windowstr.h"
+#include "pixmap.h"
+#include "input.h"
+
+#include "dixstruct.h"
+#include "mi.h"
+#include "Xmd.h"
+
+extern WindowPtr *WindowTable;
+
+/*
+    machine-independent graphics exposure code.  any device that uses
+the region package can call this.
+*/
+
+#ifndef RECTLIMIT
+#define RECTLIMIT 25           /* pick a number, any number > 8 */
+#endif
+
+/* miHandleExposures 
+    generate a region for exposures for areas that were copied from obscured or
+non-existent areas to non-obscured areas of the destination.  Paint the
+background for the region, if the destination is a window.
+
+NOTE:
+     this should generally be called, even if graphicsExposures is false,
+because this is where bits get recovered from backing store.
+
+NOTE:
+     added argument 'plane' is used to indicate how exposures from backing
+store should be accomplished. If plane is 0 (i.e. no bit plane), CopyArea
+should be used, else a CopyPlane of the indicated plane will be used. The
+exposing is done by the backing store's GraphicsExpose function, of course.
+
+*/
+
+RegionPtr
+miHandleExposures(pSrcDrawable, pDstDrawable,
+                 pGC, srcx, srcy, width, height, dstx, dsty, plane)
+    register DrawablePtr       pSrcDrawable;
+    register DrawablePtr       pDstDrawable;
+    GCPtr                      pGC;
+    int                        srcx, srcy;
+    int                        width, height;
+    int                        dstx, dsty;
+    unsigned long              plane;
+{
+    register ScreenPtr pscr = pGC->pScreen;
+    RegionPtr prgnSrcClip;     /* drawable-relative source clip */
+    RegionRec rgnSrcRec;
+    RegionPtr prgnDstClip;     /* drawable-relative dest clip */
+    RegionRec rgnDstRec;
+    BoxRec srcBox;             /* unclipped source */
+    RegionRec rgnExposed;      /* exposed region, calculated source-
+                                  relative, made dst relative to
+                                  intersect with visible parts of
+                                  dest and send events to client, 
+                                  and then screen relative to paint 
+                                  the window background
+                               */
+    WindowPtr pSrcWin;
+    BoxRec expBox;
+    Bool extents;
+
+    /* avoid work if we can */
+    if (!pGC->graphicsExposures &&
+       (pDstDrawable->type == DRAWABLE_PIXMAP) &&
+       ((pSrcDrawable->type == DRAWABLE_PIXMAP) ||
+        (((WindowPtr)pSrcDrawable)->backStorage == NULL)))
+       return NULL;
+       
+    srcBox.x1 = srcx;
+    srcBox.y1 = srcy;
+    srcBox.x2 = srcx+width;
+    srcBox.y2 = srcy+height;
+
+    if (pSrcDrawable->type != DRAWABLE_PIXMAP)
+    {
+       BoxRec TsrcBox;
+
+       TsrcBox.x1 = srcx + pSrcDrawable->x;
+       TsrcBox.y1 = srcy + pSrcDrawable->y;
+       TsrcBox.x2 = TsrcBox.x1 + width;
+       TsrcBox.y2 = TsrcBox.y1 + height;
+       pSrcWin = (WindowPtr) pSrcDrawable;
+       if (pGC->subWindowMode == IncludeInferiors)
+       {
+           prgnSrcClip = NotClippedByChildren (pSrcWin);
+           if ((RECT_IN_REGION(pscr, prgnSrcClip, &TsrcBox)) == rgnIN)
+           {
+               REGION_DESTROY(pscr, prgnSrcClip);
+               return NULL;
+           }
+       }
+       else
+       {
+           if ((RECT_IN_REGION(pscr, &pSrcWin->clipList, &TsrcBox)) == rgnIN)
+               return NULL;
+           prgnSrcClip = &rgnSrcRec;
+           REGION_INIT(pscr, prgnSrcClip, NullBox, 0);
+           REGION_COPY(pscr, prgnSrcClip, &pSrcWin->clipList);
+       }
+       REGION_TRANSLATE(pscr, prgnSrcClip,
+                               -pSrcDrawable->x, -pSrcDrawable->y);
+    }
+    else
+    {
+       BoxRec  box;
+
+       if ((srcBox.x1 >= 0) && (srcBox.y1 >= 0) &&
+           (srcBox.x2 <= pSrcDrawable->width) &&
+           (srcBox.y2 <= pSrcDrawable->height))
+           return NULL;
+
+       box.x1 = 0;
+       box.y1 = 0;
+       box.x2 = pSrcDrawable->width;
+       box.y2 = pSrcDrawable->height;
+       prgnSrcClip = &rgnSrcRec;
+       REGION_INIT(pscr, prgnSrcClip, &box, 1);
+       pSrcWin = (WindowPtr)NULL;
+    }
+
+    if (pDstDrawable == pSrcDrawable)
+    {
+       prgnDstClip = prgnSrcClip;
+    }
+    else if (pDstDrawable->type != DRAWABLE_PIXMAP)
+    {
+       if (pGC->subWindowMode == IncludeInferiors)
+       {
+           prgnDstClip = NotClippedByChildren((WindowPtr)pDstDrawable);
+       }
+       else
+       {
+           prgnDstClip = &rgnDstRec;
+           REGION_INIT(pscr, prgnDstClip, NullBox, 0);
+           REGION_COPY(pscr, prgnDstClip,
+                               &((WindowPtr)pDstDrawable)->clipList);
+       }
+       REGION_TRANSLATE(pscr, prgnDstClip,
+                                -pDstDrawable->x, -pDstDrawable->y);
+    }
+    else
+    {
+       BoxRec  box;
+
+       box.x1 = 0;
+       box.y1 = 0;
+       box.x2 = pDstDrawable->width;
+       box.y2 = pDstDrawable->height;
+       prgnDstClip = &rgnDstRec;
+       REGION_INIT(pscr, prgnDstClip, &box, 1);
+    }
+
+    /* drawable-relative source region */
+    REGION_INIT(pscr, &rgnExposed, &srcBox, 1);
+
+    /* now get the hidden parts of the source box*/
+    REGION_SUBTRACT(pscr, &rgnExposed, &rgnExposed, prgnSrcClip);
+
+    if (pSrcWin && pSrcWin->backStorage)
+    {
+       /*
+        * Copy any areas from the source backing store. Modifies
+        * rgnExposed.
+        */
+       (* pSrcWin->drawable.pScreen->ExposeCopy) ((WindowPtr)pSrcDrawable,
+                                             pDstDrawable,
+                                             pGC,
+                                             &rgnExposed,
+                                             srcx, srcy,
+                                             dstx, dsty,
+                                             plane);
+    }
+    
+    /* move them over the destination */
+    REGION_TRANSLATE(pscr, &rgnExposed, dstx-srcx, dsty-srcy);
+
+    /* intersect with visible areas of dest */
+    REGION_INTERSECT(pscr, &rgnExposed, &rgnExposed, prgnDstClip);
+
+    /*
+     * If we have LOTS of rectangles, we decide to take the extents
+     * and force an exposure on that.  This should require much less
+     * work overall, on both client and server.  This is cheating, but
+     * isn't prohibited by the protocol ("spontaneous combustion" :-)
+     * for windows.
+     */
+    extents = pGC->graphicsExposures &&
+             (REGION_NUM_RECTS(&rgnExposed) > RECTLIMIT) &&
+             (pDstDrawable->type != DRAWABLE_PIXMAP);
+#ifdef SHAPE
+    if (pSrcWin)
+    {
+       RegionPtr       region;
+       if (!(region = wClipShape (pSrcWin)))
+           region = wBoundingShape (pSrcWin);
+       /*
+        * If you try to CopyArea the extents of a shaped window, compacting the
+        * exposed region will undo all our work!
+        */
+       if (extents && pSrcWin && region &&
+           (RECT_IN_REGION(pscr, region, &srcBox) != rgnIN))
+               extents = FALSE;
+    }
+#endif
+    if (extents)
+    {
+       WindowPtr pWin = (WindowPtr)pDstDrawable;
+
+       expBox = *REGION_EXTENTS(pscr, &rgnExposed);
+       REGION_RESET(pscr, &rgnExposed, &expBox);
+       /* need to clear out new areas of backing store */
+       if (pWin->backStorage)
+           (void) (* pWin->drawable.pScreen->ClearBackingStore)(
+                                        pWin,
+                                        expBox.x1,
+                                        expBox.y1,
+                                        expBox.x2 - expBox.x1,
+                                        expBox.y2 - expBox.y1,
+                                        FALSE);
+    }
+    if ((pDstDrawable->type != DRAWABLE_PIXMAP) &&
+       (((WindowPtr)pDstDrawable)->backgroundState != None))
+    {
+       WindowPtr pWin = (WindowPtr)pDstDrawable;
+
+       /* make the exposed area screen-relative */
+       REGION_TRANSLATE(pscr, &rgnExposed, 
+                                pDstDrawable->x, pDstDrawable->y);
+
+       if (extents)
+       {
+           /* PaintWindowBackground doesn't clip, so we have to */
+           REGION_INTERSECT(pscr, &rgnExposed, &rgnExposed, &pWin->clipList);
+       }
+       (*pWin->drawable.pScreen->PaintWindowBackground)(
+                       (WindowPtr)pDstDrawable, &rgnExposed, PW_BACKGROUND);
+
+       if (extents)
+       {
+           REGION_RESET(pscr, &rgnExposed, &expBox);
+       }
+       else
+           REGION_TRANSLATE(pscr, &rgnExposed,
+                                    -pDstDrawable->x, -pDstDrawable->y);
+    }
+    if (prgnDstClip == &rgnDstRec)
+    {
+       REGION_UNINIT(pscr, prgnDstClip);
+    }
+    else if (prgnDstClip != prgnSrcClip)
+    {
+       REGION_DESTROY(pscr, prgnDstClip);
+    }
+
+    if (prgnSrcClip == &rgnSrcRec)
+    {
+       REGION_UNINIT(pscr, prgnSrcClip);
+    }
+    else
+    {
+       REGION_DESTROY(pscr, prgnSrcClip);
+    }
+
+    if (pGC->graphicsExposures)
+    {
+       /* don't look */
+       RegionPtr exposed = REGION_CREATE(pscr, NullBox, 0);
+       *exposed = rgnExposed;
+       return exposed;
+    }
+    else
+    {
+       REGION_UNINIT(pscr, &rgnExposed);
+       return NULL;
+    }
+}
+
+/* send GraphicsExpose events, or a NoExpose event, based on the region */
+
+void
+miSendGraphicsExpose (client, pRgn, drawable, major, minor)
+    ClientPtr  client;
+    RegionPtr  pRgn;
+    XID                drawable;
+    int        major;
+    int        minor;
+{
+    if (pRgn && !REGION_NIL(pRgn))
+    {
+        xEvent *pEvent;
+       register xEvent *pe;
+       register BoxPtr pBox;
+       register int i;
+       int numRects;
+
+       numRects = REGION_NUM_RECTS(pRgn);
+       pBox = REGION_RECTS(pRgn);
+       if(!(pEvent = (xEvent *)ALLOCATE_LOCAL(numRects * sizeof(xEvent))))
+               return;
+       pe = pEvent;
+
+       for (i=1; i<=numRects; i++, pe++, pBox++)
+       {
+           pe->u.u.type = GraphicsExpose;
+           pe->u.graphicsExposure.drawable = drawable;
+           pe->u.graphicsExposure.x = pBox->x1;
+           pe->u.graphicsExposure.y = pBox->y1;
+           pe->u.graphicsExposure.width = pBox->x2 - pBox->x1;
+           pe->u.graphicsExposure.height = pBox->y2 - pBox->y1;
+           pe->u.graphicsExposure.count = numRects - i;
+           pe->u.graphicsExposure.majorEvent = major;
+           pe->u.graphicsExposure.minorEvent = minor;
+       }
+       TryClientEvents(client, pEvent, numRects,
+                           (Mask)0, NoEventMask, NullGrab);
+       DEALLOCATE_LOCAL(pEvent);
+    }
+    else
+    {
+        xEvent event;
+       event.u.u.type = NoExpose;
+       event.u.noExposure.drawable = drawable;
+       event.u.noExposure.majorEvent = major;
+       event.u.noExposure.minorEvent = minor;
+       TryClientEvents(client, &event, 1,
+           (Mask)0, NoEventMask, NullGrab);
+    }
+}
+
+void
+miSendExposures(pWin, pRgn, dx, dy)
+    WindowPtr pWin;
+    RegionPtr pRgn;
+    register int dx, dy;
+{
+    register BoxPtr pBox;
+    int numRects;
+    register xEvent *pEvent, *pe;
+    register int i;
+
+    pBox = REGION_RECTS(pRgn);
+    numRects = REGION_NUM_RECTS(pRgn);
+    if(!(pEvent = (xEvent *) ALLOCATE_LOCAL(numRects * sizeof(xEvent))))
+       return;
+
+    for (i=numRects, pe = pEvent; --i >= 0; pe++, pBox++)
+    {
+       pe->u.u.type = Expose;
+       pe->u.expose.window = pWin->drawable.id;
+       pe->u.expose.x = pBox->x1 - dx;
+       pe->u.expose.y = pBox->y1 - dy;
+       pe->u.expose.width = pBox->x2 - pBox->x1;
+       pe->u.expose.height = pBox->y2 - pBox->y1;
+       pe->u.expose.count = i;
+    }
+    DeliverEvents(pWin, pEvent, numRects, NullWindow);
+    DEALLOCATE_LOCAL(pEvent);
+}
+
+void 
+miWindowExposures(pWin, prgn, other_exposed)
+    WindowPtr pWin;
+    register RegionPtr prgn, other_exposed;
+{
+    RegionPtr   exposures = prgn;
+    if (pWin->backStorage && prgn)
+       /*
+        * in some cases, backing store will cause a different
+        * region to be exposed than needs to be repainted
+        * (like when a window is mapped).  RestoreAreas is
+        * allowed to return a region other than prgn,
+        * in which case this routine will free the resultant
+        * region.  If exposures is null, then no events will
+        * be sent to the client; if prgn is empty
+        * no areas will be repainted.
+        */
+       exposures = (*pWin->drawable.pScreen->RestoreAreas)(pWin, prgn);
+    if ((prgn && !REGION_NIL(prgn)) || 
+       (exposures && !REGION_NIL(exposures)) || other_exposed)
+    {
+       RegionRec   expRec;
+       int         clientInterested;
+
+       /*
+        * Restore from backing-store FIRST.
+        */
+       clientInterested = (pWin->eventMask|wOtherEventMasks(pWin)) & ExposureMask;
+       if (other_exposed)
+       {
+           if (exposures)
+           {
+               REGION_UNION(pWin->drawable.pScreen, other_exposed,
+                                                 exposures,
+                                                 other_exposed);
+               if (exposures != prgn)
+                   REGION_DESTROY(pWin->drawable.pScreen, exposures);
+           }
+           exposures = other_exposed;
+       }
+       if (clientInterested && exposures && (REGION_NUM_RECTS(exposures) > RECTLIMIT))
+       {
+           /*
+            * If we have LOTS of rectangles, we decide to take the extents
+            * and force an exposure on that.  This should require much less
+            * work overall, on both client and server.  This is cheating, but
+            * isn't prohibited by the protocol ("spontaneous combustion" :-).
+            */
+           BoxRec box;
+
+           box = *REGION_EXTENTS( pWin->drawable.pScreen, exposures);
+           if (exposures == prgn) {
+               exposures = &expRec;
+               REGION_INIT( pWin->drawable.pScreen, exposures, &box, 1);
+               REGION_RESET( pWin->drawable.pScreen, prgn, &box);
+           } else {
+               REGION_RESET( pWin->drawable.pScreen, exposures, &box);
+               REGION_UNION( pWin->drawable.pScreen, prgn, prgn, exposures);
+           }
+           /* PaintWindowBackground doesn't clip, so we have to */
+           REGION_INTERSECT( pWin->drawable.pScreen, prgn, prgn, &pWin->clipList);
+           /* need to clear out new areas of backing store, too */
+           if (pWin->backStorage)
+               (void) (* pWin->drawable.pScreen->ClearBackingStore)(
+                                            pWin,
+                                            box.x1 - pWin->drawable.x,
+                                            box.y1 - pWin->drawable.y,
+                                            box.x2 - box.x1,
+                                            box.y2 - box.y1,
+                                            FALSE);
+       }
+       if (prgn && !REGION_NIL(prgn))
+           (*pWin->drawable.pScreen->PaintWindowBackground)(pWin, prgn, PW_BACKGROUND);
+       if (clientInterested && exposures && !REGION_NIL(exposures))
+           miSendExposures(pWin, exposures,
+                           pWin->drawable.x, pWin->drawable.y);
+       if (exposures == &expRec)
+       {
+           REGION_UNINIT( pWin->drawable.pScreen, exposures);
+       }
+       else if (exposures && exposures != prgn && exposures != other_exposed)
+           REGION_DESTROY( pWin->drawable.pScreen, exposures);
+       if (prgn)
+           REGION_EMPTY( pWin->drawable.pScreen, prgn);
+    }
+    else if (exposures && exposures != prgn)
+       REGION_DESTROY( pWin->drawable.pScreen, exposures);
+}
+
+
+/*
+    this code is highly unlikely.  it is not haile selassie.
+
+    there is some hair here.  we can't just use the window's
+clip region as it is, because if we are painting the border,
+the border is not in the client area and so we will be excluded
+when we validate the GC, and if we are painting a parent-relative
+background, the area we want to paint is in some other window.
+since we trust the code calling us to tell us to paint only areas
+that are really ours, we will temporarily give the window a
+clipList the size of the whole screen and an origin at (0,0).
+this more or less assumes that ddX code will do translation
+based on the window's absolute position, and that ValidateGC will
+look at clipList, and that no other fields from the
+window will be used.  it's not possible to just draw
+in the root because it may be a different depth.
+
+to get the tile to align correctly we set the GC's tile origin to
+be the (x,y) of the window's upper left corner, after which we
+get the right bits when drawing into the root.
+
+because the clip_mask is being set to None, we may call DoChangeGC with
+fPointer set true, thus we no longer need to install the background or
+border tile in the resource table.
+*/
+
+static RESTYPE ResType = 0;
+static int numGCs = 0;
+static GCPtr   screenContext[MAXSCREENS];
+
+/*ARGSUSED*/
+static int
+tossGC (value, id)
+pointer value;
+XID id;
+{
+    GCPtr pGC = (GCPtr)value;
+    screenContext[pGC->pScreen->myNum] = (GCPtr)NULL;
+    FreeGC (pGC, id);
+    numGCs--;
+    if (!numGCs)
+       ResType = 0;
+}
+
+
+void
+miPaintWindow(pWin, prgn, what)
+register WindowPtr pWin;
+RegionPtr prgn;
+int what;
+{
+    int        status;
+
+    Bool usingScratchGC = FALSE;
+    WindowPtr pRoot;
+       
+#define FUNCTION       0
+#define FOREGROUND     1
+#define TILE           2
+#define FILLSTYLE      3
+#define ABSX           4
+#define ABSY           5
+#define CLIPMASK       6
+#define SUBWINDOW      7
+#define COUNT_BITS     8
+
+    ChangeGCVal gcval[7];
+    ChangeGCVal newValues [COUNT_BITS];
+
+    BITS32 gcmask, index, mask;
+    RegionRec prgnWin;
+    DDXPointRec oldCorner;
+    BoxRec box;
+    WindowPtr  pBgWin;
+    GCPtr pGC;
+    register int i;
+    register BoxPtr pbox;
+    register ScreenPtr pScreen = pWin->drawable.pScreen;
+    register xRectangle *prect;
+    int numRects;
+
+    gcmask = 0;
+
+    if (what == PW_BACKGROUND)
+    {
+       switch (pWin->backgroundState) {
+       case None:
+           return;
+       case ParentRelative:
+           (*pWin->parent->drawable.pScreen->PaintWindowBackground)(pWin->parent, prgn, what);
+           return;
+       case BackgroundPixel:
+           newValues[FOREGROUND].val = pWin->background.pixel;
+           newValues[FILLSTYLE].val  = FillSolid;
+           gcmask |= GCForeground | GCFillStyle;
+           break;
+       case BackgroundPixmap:
+           newValues[TILE].ptr = (pointer)pWin->background.pixmap;
+           newValues[FILLSTYLE].val = FillTiled;
+           gcmask |= GCTile | GCFillStyle | GCTileStipXOrigin | GCTileStipYOrigin;
+           break;
+       }
+    }
+    else
+    {
+       if (pWin->borderIsPixel)
+       {
+           newValues[FOREGROUND].val = pWin->border.pixel;
+           newValues[FILLSTYLE].val  = FillSolid;
+           gcmask |= GCForeground | GCFillStyle;
+       }
+       else
+       {
+           newValues[TILE].ptr = (pointer)pWin->border.pixmap;
+           newValues[FILLSTYLE].val = FillTiled;
+           gcmask |= GCTile | GCFillStyle | GCTileStipXOrigin | GCTileStipYOrigin;
+       }
+    }
+
+    prect = (xRectangle *)ALLOCATE_LOCAL(REGION_NUM_RECTS(prgn) *
+                                        sizeof(xRectangle));
+    if (!prect)
+       return;
+
+    newValues[FUNCTION].val = GXcopy;
+    gcmask |= GCFunction | GCClipMask;
+
+    i = pScreen->myNum;
+    pRoot = WindowTable[i];
+
+    pBgWin = pWin;
+    if (what == PW_BORDER)
+    {
+       while (pBgWin->backgroundState == ParentRelative)
+           pBgWin = pBgWin->parent;
+    }
+
+    if ((pWin->drawable.depth != pRoot->drawable.depth) ||
+       (pWin->drawable.bitsPerPixel != pRoot->drawable.bitsPerPixel))
+    {
+       usingScratchGC = TRUE;
+       pGC = GetScratchGC(pWin->drawable.depth, pWin->drawable.pScreen);
+       if (!pGC)
+       {
+           DEALLOCATE_LOCAL(prect);
+           return;
+       }
+       /*
+        * mash the clip list so we can paint the border by
+        * mangling the window in place, pretending it
+        * spans the entire screen
+        */
+       if (what == PW_BORDER)
+       {
+           prgnWin = pWin->clipList;
+           oldCorner.x = pWin->drawable.x;
+           oldCorner.y = pWin->drawable.y;
+           pWin->drawable.x = pWin->drawable.y = 0;
+           box.x1 = 0;
+           box.y1 = 0;
+           box.x2 = pScreen->width;
+           box.y2 = pScreen->height;
+           REGION_INIT(pScreen, &pWin->clipList, &box, 1);
+           pWin->drawable.serialNumber = NEXT_SERIAL_NUMBER;
+           newValues[ABSX].val = pBgWin->drawable.x;
+           newValues[ABSY].val = pBgWin->drawable.y;
+       }
+       else
+       {
+           newValues[ABSX].val = 0;
+           newValues[ABSY].val = 0;
+       }
+    } else {
+       /*
+        * draw the background to the root window
+        */
+       if (screenContext[i] == (GCPtr)NULL)
+       {
+           if (!ResType && !(ResType = CreateNewResourceType(tossGC)))
+               return;
+           screenContext[i] = CreateGC((DrawablePtr)pWin, (BITS32) 0,
+                                       (XID *)NULL, &status);
+           if (!screenContext[i])
+               return;
+           numGCs++;
+           if (!AddResource(FakeClientID(0), ResType,
+                            (pointer)screenContext[i]))
+               return;
+       }
+       pGC = screenContext[i];
+       newValues[SUBWINDOW].val = IncludeInferiors;
+       newValues[ABSX].val = pBgWin->drawable.x;
+       newValues[ABSY].val = pBgWin->drawable.y;
+       gcmask |= GCSubwindowMode;
+       pWin = pRoot;
+    }
+    
+    if (pWin->backStorage)
+       (*pWin->drawable.pScreen->DrawGuarantee) (pWin, pGC, GuaranteeVisBack);
+
+    mask = gcmask;
+    gcmask = 0;
+    i = 0;
+    while (mask) {
+       index = lowbit (mask);
+       mask &= ~index;
+       switch (index) {
+       case GCFunction:
+           if (pGC->alu != newValues[FUNCTION].val) {
+               gcmask |= index;
+               gcval[i++].val = newValues[FUNCTION].val;
+           }
+           break;
+       case GCTileStipXOrigin:
+           if ( pGC->patOrg.x != newValues[ABSX].val) {
+               gcmask |= index;
+               gcval[i++].val = newValues[ABSX].val;
+           }
+           break;
+       case GCTileStipYOrigin:
+           if ( pGC->patOrg.y != newValues[ABSY].val) {
+               gcmask |= index;
+               gcval[i++].val = newValues[ABSY].val;
+           }
+           break;
+       case GCClipMask:
+           if ( pGC->clientClipType != CT_NONE) {
+               gcmask |= index;
+               gcval[i++].val = CT_NONE;
+           }
+           break;
+       case GCSubwindowMode:
+           if ( pGC->subWindowMode != newValues[SUBWINDOW].val) {
+               gcmask |= index;
+               gcval[i++].val = newValues[SUBWINDOW].val;
+           }
+           break;
+       case GCTile:
+           if (pGC->tileIsPixel || pGC->tile.pixmap != newValues[TILE].ptr)
+           {
+               gcmask |= index;
+               gcval[i++].ptr = newValues[TILE].ptr;
+           }
+           break;
+       case GCFillStyle:
+           if ( pGC->fillStyle != newValues[FILLSTYLE].val) {
+               gcmask |= index;
+               gcval[i++].val = newValues[FILLSTYLE].val;
+           }
+           break;
+       case GCForeground:
+           if ( pGC->fgPixel != newValues[FOREGROUND].val) {
+               gcmask |= index;
+               gcval[i++].val = newValues[FOREGROUND].val;
+           }
+           break;
+       }
+    }
+
+    if (gcmask)
+        dixChangeGC(NullClient, pGC, gcmask, NULL, gcval);
+
+    if (pWin->drawable.serialNumber != pGC->serialNumber)
+       ValidateGC((DrawablePtr)pWin, pGC);
+
+    numRects = REGION_NUM_RECTS(prgn);
+    pbox = REGION_RECTS(prgn);
+    for (i= numRects; --i >= 0; pbox++, prect++)
+    {
+       prect->x = pbox->x1 - pWin->drawable.x;
+       prect->y = pbox->y1 - pWin->drawable.y;
+       prect->width = pbox->x2 - pbox->x1;
+       prect->height = pbox->y2 - pbox->y1;
+    }
+    prect -= numRects;
+    (*pGC->ops->PolyFillRect)((DrawablePtr)pWin, pGC, numRects, prect);
+    DEALLOCATE_LOCAL(prect);
+
+    if (pWin->backStorage)
+       (*pWin->drawable.pScreen->DrawGuarantee) (pWin, pGC, GuaranteeNothing);
+
+    if (usingScratchGC)
+    {
+       if (what == PW_BORDER)
+       {
+           REGION_UNINIT(pScreen, &pWin->clipList);
+           pWin->clipList = prgnWin;
+           pWin->drawable.x = oldCorner.x;
+           pWin->drawable.y = oldCorner.y;
+           pWin->drawable.serialNumber = NEXT_SERIAL_NUMBER;
+       }
+       FreeScratchGC(pGC);
+    }
+}
+
+
+/* MICLEARDRAWABLE -- sets the entire drawable to the background color of
+ * the GC.  Useful when we have a scratch drawable and need to initialize 
+ * it. */
+miClearDrawable(pDraw, pGC)
+    DrawablePtr        pDraw;
+    GCPtr      pGC;
+{
+    XID fg = pGC->fgPixel;
+    XID bg = pGC->bgPixel;
+    xRectangle rect;
+
+    rect.x = 0;
+    rect.y = 0;
+    rect.width = pDraw->width;
+    rect.height = pDraw->height;
+    DoChangeGC(pGC, GCForeground, &bg, 0);
+    ValidateGC(pDraw, pGC);
+    (*pGC->ops->PolyFillRect)(pDraw, pGC, 1, &rect);
+    DoChangeGC(pGC, GCForeground, &fg, 0);
+    ValidateGC(pDraw, pGC);
+}
diff --git a/Xserver/programs/Xserver/mi/mifillarc.c b/Xserver/programs/Xserver/mi/mifillarc.c
new file mode 100644 (file)
index 0000000..e267507
--- /dev/null
@@ -0,0 +1,812 @@
+/************************************************************
+
+Copyright (c) 1989  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+Author:  Bob Scheifler, MIT X Consortium
+
+********************************************************/
+
+/* $XConsortium: mifillarc.c,v 5.18 95/01/10 20:59:49 kaleb Exp $ */
+/* $XFree86: xc/programs/Xserver/mi/mifillarc.c,v 3.2 1995/01/28 16:15:52 dawes Exp $ */
+
+#include <math.h>
+#include "X.h"
+#include "Xprotostr.h"
+#include "miscstruct.h"
+#include "gcstruct.h"
+#include "pixmapstr.h"
+#include "mifpoly.h"
+#include "mi.h"
+#include "mifillarc.h"
+
+#define QUADRANT (90 * 64)
+#define HALFCIRCLE (180 * 64)
+#define QUADRANT3 (270 * 64)
+
+#ifndef M_PI
+#define M_PI   3.14159265358979323846
+#endif
+
+#define Dsin(d)        sin((double)d*(M_PI/11520.0))
+#define Dcos(d)        cos((double)d*(M_PI/11520.0))
+
+void
+miFillArcSetup(arc, info)
+    register xArc *arc;
+    register miFillArcRec *info;
+{
+    info->y = arc->height >> 1;
+    info->dy = arc->height & 1;
+    info->yorg = arc->y + info->y;
+    info->dx = arc->width & 1;
+    info->xorg = arc->x + (arc->width >> 1) + info->dx;
+    info->dx = 1 - info->dx;
+    if (arc->width == arc->height)
+    {
+       /* (2x - 2xorg)^2 = d^2 - (2y - 2yorg)^2 */
+       /* even: xorg = yorg = 0   odd:  xorg = .5, yorg = -.5 */
+       info->ym = 8;
+       info->xm = 8;
+       info->yk = info->y << 3;
+       if (!info->dx)
+       {
+           info->xk = 0;
+           info->e = -1;
+       }
+       else
+       {
+           info->y++;
+           info->yk += 4;
+           info->xk = -4;
+           info->e = - (info->y << 3);
+       }
+    }
+    else
+    {
+       /* h^2 * (2x - 2xorg)^2 = w^2 * h^2 - w^2 * (2y - 2yorg)^2 */
+       /* even: xorg = yorg = 0   odd:  xorg = .5, yorg = -.5 */
+       info->ym = (arc->width * arc->width) << 3;
+       info->xm = (arc->height * arc->height) << 3;
+       info->yk = info->y * info->ym;
+       if (!info->dy)
+           info->yk -= info->ym >> 1;
+       if (!info->dx)
+       {
+           info->xk = 0;
+           info->e = - (info->xm >> 3);
+       }
+       else
+       {
+           info->y++;
+           info->yk += info->ym;
+           info->xk = -(info->xm >> 1);
+           info->e = info->xk - info->yk;
+       }
+    }
+}
+
+void
+miFillArcDSetup(arc, info)
+    register xArc *arc;
+    register miFillArcDRec *info;
+{
+    /* h^2 * (2x - 2xorg)^2 = w^2 * h^2 - w^2 * (2y - 2yorg)^2 */
+    /* even: xorg = yorg = 0   odd:  xorg = .5, yorg = -.5 */
+    info->y = arc->height >> 1;
+    info->dy = arc->height & 1;
+    info->yorg = arc->y + info->y;
+    info->dx = arc->width & 1;
+    info->xorg = arc->x + (arc->width >> 1) + info->dx;
+    info->dx = 1 - info->dx;
+    info->ym = ((double)arc->width) * (arc->width * 8);
+    info->xm = ((double)arc->height) * (arc->height * 8);
+    info->yk = info->y * info->ym;
+    if (!info->dy)
+       info->yk -= info->ym / 2.0;
+    if (!info->dx)
+    {
+       info->xk = 0;
+       info->e = - (info->xm / 8.0);
+    }
+    else
+    {
+       info->y++;
+       info->yk += info->ym;
+       info->xk = -info->xm / 2.0;
+       info->e = info->xk - info->yk;
+    }
+}
+
+static void
+miGetArcEdge(arc, edge, k, top, left)
+    register xArc *arc;
+    register miSliceEdgePtr edge;
+    int k;
+    Bool top, left;
+{
+    register int xady, y;
+
+    y = arc->height >> 1;
+    if (!(arc->width & 1))
+       y++;
+    if (!top)
+    {
+       y = -y;
+       if (arc->height & 1)
+           y--;
+    }
+    xady = k + y * edge->dx;
+    if (xady <= 0)
+       edge->x = - ((-xady) / edge->dy + 1);
+    else
+       edge->x = (xady - 1) / edge->dy;
+    edge->e = xady - edge->x * edge->dy;
+    if ((top && (edge->dx < 0)) || (!top && (edge->dx > 0)))
+       edge->e = edge->dy - edge->e + 1;
+    if (left)
+       edge->x++;
+    edge->x += arc->x + (arc->width >> 1);
+    if (edge->dx > 0)
+    {
+       edge->deltax = 1;
+       edge->stepx = edge->dx / edge->dy;
+       edge->dx = edge->dx % edge->dy;
+    }
+    else
+    {
+       edge->deltax = -1;
+       edge->stepx = - ((-edge->dx) / edge->dy);
+       edge->dx = (-edge->dx) % edge->dy;
+    }
+    if (!top)
+    {
+       edge->deltax = -edge->deltax;
+       edge->stepx = -edge->stepx;
+    }
+}
+
+void
+miEllipseAngleToSlope (angle, width, height, dxp, dyp, d_dxp, d_dyp)
+    int            angle;
+    int            width;
+    int            height;
+    int            *dxp;
+    int            *dyp;
+    double  *d_dxp;
+    double  *d_dyp;
+{
+    int            dx, dy;
+    double  d_dx, d_dy, scale;
+    Bool    negative_dx, negative_dy;
+
+    switch (angle) {
+    case 0:
+       *dxp = -1;
+       *dyp = 0;
+       if (d_dxp) {
+           *d_dxp = width / 2.0;
+           *d_dyp = 0;
+       }
+       break;
+    case QUADRANT:
+       *dxp = 0;
+       *dyp = 1;
+       if (d_dxp) {
+           *d_dxp = 0;
+           *d_dyp = - height / 2.0;
+       }
+       break;
+    case HALFCIRCLE:
+       *dxp = 1;
+       *dyp = 0;
+       if (d_dxp) {
+           *d_dxp = - width / 2.0;
+           *d_dyp = 0;
+       }
+       break;
+    case QUADRANT3:
+       *dxp = 0;
+       *dyp = -1;
+       if (d_dxp) {
+           *d_dxp = 0;
+           *d_dyp = height / 2.0;
+       }
+       break;
+    default:
+       d_dx = Dcos(angle) * width;
+       d_dy = Dsin(angle) * height;
+       if (d_dxp) {
+           *d_dxp = d_dx / 2.0;
+           *d_dyp = - d_dy / 2.0;
+       }
+       negative_dx = FALSE;
+       if (d_dx < 0.0)
+       {
+           d_dx = -d_dx;
+           negative_dx = TRUE;
+       }
+       negative_dy = FALSE;
+       if (d_dy < 0.0)
+       {
+           d_dy = -d_dy;
+           negative_dy = TRUE;
+       }
+       scale = d_dx;
+       if (d_dy > d_dx)
+           scale = d_dy;
+       dx = floor ((d_dx * 32768) / scale + 0.5);
+       if (negative_dx)
+           dx = -dx;
+       *dxp = dx;
+       dy = floor ((d_dy * 32768) / scale + 0.5);
+       if (negative_dy)
+           dy = -dy;
+       *dyp = dy;
+       break;
+    }
+}
+
+static void
+miGetPieEdge(arc, angle, edge, top, left)
+    register xArc *arc;
+    register int angle;
+    register miSliceEdgePtr edge;
+    Bool top, left;
+{
+    register int k, signdx, signdy;
+    int        dx, dy;
+
+    miEllipseAngleToSlope (angle, arc->width, arc->height, &dx, &dy, 0, 0);
+
+    if (dy == 0)
+    {
+       edge->x = left ? -65536 : 65536;
+       edge->stepx = 0;
+       edge->e = 0;
+       edge->dx = -1;
+       return;
+    }
+    if (dx == 0)
+    {
+       edge->x = arc->x + (arc->width >> 1);
+       if (left && (arc->width & 1))
+           edge->x++;
+       else if (!left && !(arc->width & 1))
+           edge->x--;
+       edge->stepx = 0;
+       edge->e = 0;
+       edge->dx = -1;
+       return;
+    }
+    if (dy < 0) {
+       dx = -dx;
+       dy = -dy;
+    }
+    k = (arc->height & 1) ? dx : 0;
+    if (arc->width & 1)
+       k += dy;
+    edge->dx = dx << 1;
+    edge->dy = dy << 1;
+    miGetArcEdge(arc, edge, k, top, left);
+}
+
+void
+miFillArcSliceSetup(arc, slice, pGC)
+    register xArc *arc;
+    register miArcSliceRec *slice;
+    GCPtr pGC;
+{
+    register int angle1, angle2;
+
+    angle1 = arc->angle1;
+    if (arc->angle2 < 0)
+    {
+       angle2 = angle1;
+       angle1 += arc->angle2;
+    }
+    else
+       angle2 = angle1 + arc->angle2;
+    while (angle1 < 0)
+       angle1 += FULLCIRCLE;
+    while (angle1 >= FULLCIRCLE)
+       angle1 -= FULLCIRCLE;
+    while (angle2 < 0)
+       angle2 += FULLCIRCLE;
+    while (angle2 >= FULLCIRCLE)
+       angle2 -= FULLCIRCLE;
+    slice->min_top_y = 0;
+    slice->max_top_y = arc->height >> 1;
+    slice->min_bot_y = 1 - (arc->height & 1);
+    slice->max_bot_y = slice->max_top_y - 1;
+    slice->flip_top = FALSE;
+    slice->flip_bot = FALSE;
+    if (pGC->arcMode == ArcPieSlice)
+    {
+       slice->edge1_top = (angle1 < HALFCIRCLE);
+       slice->edge2_top = (angle2 <= HALFCIRCLE);
+       if ((angle2 == 0) || (angle1 == HALFCIRCLE))
+       {
+           if (angle2 ? slice->edge2_top : slice->edge1_top)
+               slice->min_top_y = slice->min_bot_y;
+           else
+               slice->min_top_y = arc->height;
+           slice->min_bot_y = 0;
+       }
+       else if ((angle1 == 0) || (angle2 == HALFCIRCLE))
+       {
+           slice->min_top_y = slice->min_bot_y;
+           if (angle1 ? slice->edge1_top : slice->edge2_top)
+               slice->min_bot_y = arc->height;
+           else
+               slice->min_bot_y = 0;
+       }
+       else if (slice->edge1_top == slice->edge2_top)
+       {
+           if (angle2 < angle1)
+           {
+               slice->flip_top = slice->edge1_top;
+               slice->flip_bot = !slice->edge1_top;
+           }
+           else if (slice->edge1_top)
+           {
+               slice->min_top_y = 1;
+               slice->min_bot_y = arc->height;
+           }
+           else
+           {
+               slice->min_bot_y = 0;
+               slice->min_top_y = arc->height;
+           }
+       }
+       miGetPieEdge(arc, angle1, &slice->edge1,
+                    slice->edge1_top, !slice->edge1_top);
+       miGetPieEdge(arc, angle2, &slice->edge2,
+                    slice->edge2_top, slice->edge2_top);
+    }
+    else
+    {
+       double w2, h2, x1, y1, x2, y2, dx, dy, scale;
+       int signdx, signdy, y, k;
+       Bool isInt1 = TRUE, isInt2 = TRUE;
+
+       w2 = (double)arc->width / 2.0;
+       h2 = (double)arc->height / 2.0;
+       if ((angle1 == 0) || (angle1 == HALFCIRCLE))
+       {
+           x1 = angle1 ? -w2 : w2;
+           y1 = 0.0;
+       }
+       else if ((angle1 == QUADRANT) || (angle1 == QUADRANT3))
+       {
+           x1 = 0.0;
+           y1 = (angle1 == QUADRANT) ? h2 : -h2;
+       }
+       else
+       {
+           isInt1 = FALSE;
+           x1 = Dcos(angle1) * w2;
+           y1 = Dsin(angle1) * h2;
+       }
+       if ((angle2 == 0) || (angle2 == HALFCIRCLE))
+       {
+           x2 = angle2 ? -w2 : w2;
+           y2 = 0.0;
+       }
+       else if ((angle2 == QUADRANT) || (angle2 == QUADRANT3))
+       {
+           x2 = 0.0;
+           y2 = (angle2 == QUADRANT) ? h2 : -h2;
+       }
+       else
+       {
+           isInt2 = FALSE;
+           x2 = Dcos(angle2) * w2;
+           y2 = Dsin(angle2) * h2;
+       }
+       dx = x2 - x1;
+       dy = y2 - y1;
+       if (arc->height & 1)
+       {
+           y1 -= 0.5;
+           y2 -= 0.5;
+       }
+       if (arc->width & 1)
+       {
+           x1 += 0.5;
+           x2 += 0.5;
+       }
+       if (dy < 0.0)
+       {
+           dy = -dy;
+           signdy = -1;
+       }
+       else
+           signdy = 1;
+       if (dx < 0.0)
+       {
+           dx = -dx;
+           signdx = -1;
+       }
+       else
+           signdx = 1;
+       if (isInt1 && isInt2)
+       {
+           slice->edge1.dx = dx * 2;
+           slice->edge1.dy = dy * 2;
+       }
+       else
+       {
+           scale = (dx > dy) ? dx : dy;
+           slice->edge1.dx = floor((dx * 32768) / scale + .5);
+           slice->edge1.dy = floor((dy * 32768) / scale + .5);
+       }
+       if (!slice->edge1.dy)
+       {
+           if (signdx < 0)
+           {
+               y = floor(y1 + 1.0);
+               if (y >= 0)
+               {
+                   slice->min_top_y = y;
+                   slice->min_bot_y = arc->height;
+               }
+               else
+               {
+                   slice->max_bot_y = -y - (arc->height & 1);
+               }
+           }
+           else
+           {
+               y = floor(y1);
+               if (y >= 0)
+                   slice->max_top_y = y;
+               else
+               {
+                   slice->min_top_y = arc->height;
+                   slice->min_bot_y = -y - (arc->height & 1);
+               }
+           }
+           slice->edge1_top = TRUE;
+           slice->edge1.x = 65536;
+           slice->edge1.stepx = 0;
+           slice->edge1.e = 0;
+           slice->edge1.dx = -1;
+           slice->edge2 = slice->edge1;
+           slice->edge2_top = FALSE;
+       }
+       else if (!slice->edge1.dx)
+       {
+           if (signdy < 0)
+               x1 -= 1.0;
+           slice->edge1.x = ceil(x1);
+           slice->edge1_top = signdy < 0;
+           slice->edge1.x += arc->x + (arc->width >> 1);
+           slice->edge1.stepx = 0;
+           slice->edge1.e = 0;
+           slice->edge1.dx = -1;
+           slice->edge2_top = !slice->edge1_top;
+           slice->edge2 = slice->edge1;
+       }
+       else
+       {
+           if (signdx < 0)
+               slice->edge1.dx = -slice->edge1.dx;
+           if (signdy < 0)
+               slice->edge1.dx = -slice->edge1.dx;
+           k = ceil(((x1 + x2) * slice->edge1.dy - (y1 + y2) * slice->edge1.dx) / 2.0);
+           slice->edge2.dx = slice->edge1.dx;
+           slice->edge2.dy = slice->edge1.dy;
+           slice->edge1_top = signdy < 0;
+           slice->edge2_top = !slice->edge1_top;
+           miGetArcEdge(arc, &slice->edge1, k,
+                        slice->edge1_top, !slice->edge1_top);
+           miGetArcEdge(arc, &slice->edge2, k,
+                        slice->edge2_top, slice->edge2_top);
+       }
+    }
+}
+
+#define ADDSPANS() \
+    pts->x = xorg - x; \
+    pts->y = yorg - y; \
+    *wids = slw; \
+    pts++; \
+    wids++; \
+    if (miFillArcLower(slw)) \
+    { \
+       pts->x = xorg - x; \
+       pts->y = yorg + y + dy; \
+       pts++; \
+       *wids++ = slw; \
+    }
+
+static void
+miFillEllipseI(pDraw, pGC, arc)
+    DrawablePtr pDraw;
+    GCPtr pGC;
+    xArc *arc;
+{
+    register int x, y, e;
+    int yk, xk, ym, xm, dx, dy, xorg, yorg;
+    int slw;
+    miFillArcRec info;
+    DDXPointPtr points;
+    register DDXPointPtr pts;
+    int *widths;
+    register int *wids;
+
+    points = (DDXPointPtr)ALLOCATE_LOCAL(sizeof(DDXPointRec) * arc->height);
+    if (!points)
+       return;
+    widths = (int *)ALLOCATE_LOCAL(sizeof(int) * arc->height);
+    if (!widths)
+    {
+       DEALLOCATE_LOCAL(points);
+       return;
+    }
+    miFillArcSetup(arc, &info);
+    MIFILLARCSETUP();
+    if (pGC->miTranslate)
+    {
+       xorg += pDraw->x;
+       yorg += pDraw->y;
+    }
+    pts = points;
+    wids = widths;
+    while (y > 0)
+    {
+       MIFILLARCSTEP(slw);
+       ADDSPANS();
+    }
+    (*pGC->ops->FillSpans)(pDraw, pGC, pts - points, points, widths, FALSE);
+    DEALLOCATE_LOCAL(widths);
+    DEALLOCATE_LOCAL(points);
+}
+
+static void
+miFillEllipseD(pDraw, pGC, arc)
+    DrawablePtr pDraw;
+    GCPtr pGC;
+    xArc *arc;
+{
+    register int x, y;
+    int xorg, yorg, dx, dy, slw;
+    double e, yk, xk, ym, xm;
+    miFillArcDRec info;
+    DDXPointPtr points;
+    register DDXPointPtr pts;
+    int *widths;
+    register int *wids;
+
+    points = (DDXPointPtr)ALLOCATE_LOCAL(sizeof(DDXPointRec) * arc->height);
+    if (!points)
+       return;
+    widths = (int *)ALLOCATE_LOCAL(sizeof(int) * arc->height);
+    if (!widths)
+    {
+       DEALLOCATE_LOCAL(points);
+       return;
+    }
+    miFillArcDSetup(arc, &info);
+    MIFILLARCSETUP();
+    if (pGC->miTranslate)
+    {
+       xorg += pDraw->x;
+       yorg += pDraw->y;
+    }
+    pts = points;
+    wids = widths;
+    while (y > 0)
+    {
+       MIFILLARCSTEP(slw);
+       ADDSPANS();
+    }
+    (*pGC->ops->FillSpans)(pDraw, pGC, pts - points, points, widths, FALSE);
+    DEALLOCATE_LOCAL(widths);
+    DEALLOCATE_LOCAL(points);
+}
+
+#define ADDSPAN(l,r) \
+    if (r >= l) \
+    { \
+       pts->x = l; \
+       pts->y = ya; \
+       pts++; \
+       *wids++ = r - l + 1; \
+    }
+
+#define ADDSLICESPANS(flip) \
+    if (!flip) \
+    { \
+       ADDSPAN(xl, xr); \
+    } \
+    else \
+    { \
+       xc = xorg - x; \
+       ADDSPAN(xc, xr); \
+       xc += slw - 1; \
+       ADDSPAN(xl, xc); \
+    }
+
+static void
+miFillArcSliceI(pDraw, pGC, arc)
+    DrawablePtr pDraw;
+    GCPtr pGC;
+    xArc *arc;
+{
+    int yk, xk, ym, xm, dx, dy, xorg, yorg, slw;
+    register int x, y, e;
+    miFillArcRec info;
+    miArcSliceRec slice;
+    int ya, xl, xr, xc;
+    DDXPointPtr points;
+    register DDXPointPtr pts;
+    int *widths;
+    register int *wids;
+
+    miFillArcSetup(arc, &info);
+    miFillArcSliceSetup(arc, &slice, pGC);
+    MIFILLARCSETUP();
+    slw = arc->height;
+    if (slice.flip_top || slice.flip_bot)
+       slw += (arc->height >> 1) + 1;
+    points = (DDXPointPtr)ALLOCATE_LOCAL(sizeof(DDXPointRec) * slw);
+    if (!points)
+       return;
+    widths = (int *)ALLOCATE_LOCAL(sizeof(int) * slw);
+    if (!widths)
+    {
+       DEALLOCATE_LOCAL(points);
+       return;
+    }
+    if (pGC->miTranslate)
+    {
+       xorg += pDraw->x;
+       yorg += pDraw->y;
+       slice.edge1.x += pDraw->x;
+       slice.edge2.x += pDraw->x;
+    }
+    pts = points;
+    wids = widths;
+    while (y > 0)
+    {
+       MIFILLARCSTEP(slw);
+       MIARCSLICESTEP(slice.edge1);
+       MIARCSLICESTEP(slice.edge2);
+       if (miFillSliceUpper(slice))
+       {
+           ya = yorg - y;
+           MIARCSLICEUPPER(xl, xr, slice, slw);
+           ADDSLICESPANS(slice.flip_top);
+       }
+       if (miFillSliceLower(slice))
+       {
+           ya = yorg + y + dy;
+           MIARCSLICELOWER(xl, xr, slice, slw);
+           ADDSLICESPANS(slice.flip_bot);
+       }
+    }
+    (*pGC->ops->FillSpans)(pDraw, pGC, pts - points, points, widths, FALSE);
+    DEALLOCATE_LOCAL(widths);
+    DEALLOCATE_LOCAL(points);
+}
+
+static void
+miFillArcSliceD(pDraw, pGC, arc)
+    DrawablePtr pDraw;
+    GCPtr pGC;
+    xArc *arc;
+{
+    register int x, y;
+    int dx, dy, xorg, yorg, slw;
+    double e, yk, xk, ym, xm;
+    miFillArcDRec info;
+    miArcSliceRec slice;
+    int ya, xl, xr, xc;
+    DDXPointPtr points;
+    register DDXPointPtr pts;
+    int *widths;
+    register int *wids;
+
+    miFillArcDSetup(arc, &info);
+    miFillArcSliceSetup(arc, &slice, pGC);
+    MIFILLARCSETUP();
+    slw = arc->height;
+    if (slice.flip_top || slice.flip_bot)
+       slw += (arc->height >> 1) + 1;
+    points = (DDXPointPtr)ALLOCATE_LOCAL(sizeof(DDXPointRec) * slw);
+    if (!points)
+       return;
+    widths = (int *)ALLOCATE_LOCAL(sizeof(int) * slw);
+    if (!widths)
+    {
+       DEALLOCATE_LOCAL(points);
+       return;
+    }
+    if (pGC->miTranslate)
+    {
+       xorg += pDraw->x;
+       yorg += pDraw->y;
+       slice.edge1.x += pDraw->x;
+       slice.edge2.x += pDraw->x;
+    }
+    pts = points;
+    wids = widths;
+    while (y > 0)
+    {
+       MIFILLARCSTEP(slw);
+       MIARCSLICESTEP(slice.edge1);
+       MIARCSLICESTEP(slice.edge2);
+       if (miFillSliceUpper(slice))
+       {
+           ya = yorg - y;
+           MIARCSLICEUPPER(xl, xr, slice, slw);
+           ADDSLICESPANS(slice.flip_top);
+       }
+       if (miFillSliceLower(slice))
+       {
+           ya = yorg + y + dy;
+           MIARCSLICELOWER(xl, xr, slice, slw);
+           ADDSLICESPANS(slice.flip_bot);
+       }
+    }
+    (*pGC->ops->FillSpans)(pDraw, pGC, pts - points, points, widths, FALSE);
+    DEALLOCATE_LOCAL(widths);
+    DEALLOCATE_LOCAL(points);
+}
+
+/* MIPOLYFILLARC -- The public entry for the PolyFillArc request.
+ * Since we don't have to worry about overlapping segments, we can just
+ * fill each arc as it comes.
+ */
+void
+miPolyFillArc(pDraw, pGC, narcs, parcs)
+    DrawablePtr        pDraw;
+    GCPtr      pGC;
+    int                narcs;
+    xArc       *parcs;
+{
+    register int i;
+    register xArc *arc;
+
+    for(i = narcs, arc = parcs; --i >= 0; arc++)
+    {
+       if (miFillArcEmpty(arc))
+           continue;;
+       if ((arc->angle2 >= FULLCIRCLE) || (arc->angle2 <= -FULLCIRCLE))
+       {
+           if (miCanFillArc(arc))
+               miFillEllipseI(pDraw, pGC, arc);
+           else
+               miFillEllipseD(pDraw, pGC, arc);
+       }
+       else
+       {
+           if (miCanFillArc(arc))
+               miFillArcSliceI(pDraw, pGC, arc);
+           else
+               miFillArcSliceD(pDraw, pGC, arc);
+       }
+    }
+}
diff --git a/Xserver/programs/Xserver/mi/mifillarc.h b/Xserver/programs/Xserver/mi/mifillarc.h
new file mode 100644 (file)
index 0000000..f4692de
--- /dev/null
@@ -0,0 +1,225 @@
+/************************************************************
+
+Copyright (c) 1989  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+********************************************************/
+
+/* $XConsortium: mifillarc.h,v 5.9 95/01/11 16:19:24 dpw Exp $ */
+/* $XFree86: xc/programs/Xserver/mi/mifillarc.h,v 3.2 1995/01/28 16:15:53 dawes Exp $ */
+
+#define FULLCIRCLE (360 * 64)
+
+typedef struct _miFillArc {
+    int xorg, yorg;
+    int y;
+    int dx, dy;
+    int e;
+    int ym, yk, xm, xk;
+} miFillArcRec;
+
+/* could use 64-bit integers */
+typedef struct _miFillArcD {
+    int xorg, yorg;
+    int y;
+    int dx, dy;
+    double e;
+    double ym, yk, xm, xk;
+} miFillArcDRec;
+
+#define miFillArcEmpty(arc) (!(arc)->angle2 || \
+                            !(arc)->width || !(arc)->height || \
+                            (((arc)->width == 1) && ((arc)->height & 1)))
+
+#define miCanFillArc(arc) (((arc)->width == (arc)->height) || \
+                          (((arc)->width <= 800) && ((arc)->height <= 800)))
+
+#define MIFILLARCSETUP() \
+    x = 0; \
+    y = info.y; \
+    e = info.e; \
+    xk = info.xk; \
+    xm = info.xm; \
+    yk = info.yk; \
+    ym = info.ym; \
+    dx = info.dx; \
+    dy = info.dy; \
+    xorg = info.xorg; \
+    yorg = info.yorg
+
+#define MIFILLARCSTEP(slw) \
+    e += yk; \
+    while (e >= 0) \
+    { \
+       x++; \
+       xk -= xm; \
+       e += xk; \
+    } \
+    y--; \
+    yk -= ym; \
+    slw = (x << 1) + dx; \
+    if ((e == xk) && (slw > 1)) \
+       slw--
+
+#define MIFILLCIRCSTEP(slw) MIFILLARCSTEP(slw)
+#define MIFILLELLSTEP(slw) MIFILLARCSTEP(slw)
+
+#define miFillArcLower(slw) (((y + dy) != 0) && ((slw > 1) || (e != xk)))
+
+typedef struct _miSliceEdge {
+    int            x;
+    int     stepx;
+    int            deltax;
+    int            e;
+    int            dy;
+    int            dx;
+} miSliceEdgeRec, *miSliceEdgePtr;
+
+typedef struct _miArcSlice {
+    miSliceEdgeRec edge1, edge2;
+    int min_top_y, max_top_y;
+    int min_bot_y, max_bot_y;
+    Bool edge1_top, edge2_top;
+    Bool flip_top, flip_bot;
+} miArcSliceRec;
+
+#define MIARCSLICESTEP(edge) \
+    edge.x -= edge.stepx; \
+    edge.e -= edge.dx; \
+    if (edge.e <= 0) \
+    { \
+       edge.x -= edge.deltax; \
+       edge.e += edge.dy; \
+    }
+
+#define miFillSliceUpper(slice) \
+               ((y >= slice.min_top_y) && (y <= slice.max_top_y))
+
+#define miFillSliceLower(slice) \
+               ((y >= slice.min_bot_y) && (y <= slice.max_bot_y))
+
+#define MIARCSLICEUPPER(xl,xr,slice,slw) \
+    xl = xorg - x; \
+    xr = xl + slw - 1; \
+    if (slice.edge1_top && (slice.edge1.x < xr)) \
+       xr = slice.edge1.x; \
+    if (slice.edge2_top && (slice.edge2.x > xl)) \
+       xl = slice.edge2.x;
+
+#define MIARCSLICELOWER(xl,xr,slice,slw) \
+    xl = xorg - x; \
+    xr = xl + slw - 1; \
+    if (!slice.edge1_top && (slice.edge1.x > xl)) \
+       xl = slice.edge1.x; \
+    if (!slice.edge2_top && (slice.edge2.x < xr)) \
+       xr = slice.edge2.x;
+
+#define MIWIDEARCSETUP(x,y,dy,slw,e,xk,xm,yk,ym) \
+    x = 0; \
+    y = slw >> 1; \
+    yk = y << 3; \
+    xm = 8; \
+    ym = 8; \
+    if (dy) \
+    { \
+       xk = 0; \
+       if (slw & 1) \
+           e = -1; \
+       else \
+           e = -(y << 2) - 2; \
+    } \
+    else \
+    { \
+       y++; \
+       yk += 4; \
+       xk = -4; \
+       if (slw & 1) \
+           e = -(y << 2) - 3; \
+       else \
+           e = - (y << 3); \
+    }
+
+#define MIFILLINARCSTEP(slw) \
+    ine += inyk; \
+    while (ine >= 0) \
+    { \
+       inx++; \
+       inxk -= inxm; \
+       ine += inxk; \
+    } \
+    iny--; \
+    inyk -= inym; \
+    slw = (inx << 1) + dx; \
+    if ((ine == inxk) && (slw > 1)) \
+       slw--
+
+#define miFillInArcLower(slw) (((iny + dy) != 0) && \
+                              ((slw > 1) || (ine != inxk)))
+
+extern int miFreeArcCache(
+#if NeedFunctionPrototypes
+    pointer /*data*/,
+    XID /*id*/
+#endif
+);
+
+extern struct finalSpan *realAllocSpan(
+#if NeedFunctionPrototypes
+    void
+#endif
+);
+
+extern void miFillArcSetup(
+#if NeedFunctionPrototypes
+    xArc * /*arc*/,
+    miFillArcRec * /*info*/
+#endif
+);
+
+extern void miFillArcDSetup(
+#if NeedFunctionPrototypes
+    xArc * /*arc*/,
+    miFillArcDRec * /*info*/
+#endif
+);
+
+extern void miEllipseAngleToSlope(
+#if NeedFunctionPrototypes
+    int /*angle*/,
+    int /*width*/,
+    int /*height*/,
+    int * /*dxp*/,
+    int * /*dyp*/,
+    double * /*d_dxp*/,
+    double * /*d_dyp*/
+#endif
+);
+
+extern void miFillArcSliceSetup(
+#if NeedFunctionPrototypes
+    xArc * /*arc*/,
+    miArcSliceRec * /*slice*/,
+    GCPtr /*pGC*/
+#endif
+);
+
diff --git a/Xserver/programs/Xserver/mi/mifillrct.c b/Xserver/programs/Xserver/mi/mifillrct.c
new file mode 100644 (file)
index 0000000..761d12d
--- /dev/null
@@ -0,0 +1,140 @@
+/***********************************************************
+
+Copyright (c) 1987  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+
+Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
+
+                        All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and its 
+documentation for any purpose and without fee is hereby granted, 
+provided that the above copyright notice appear in all copies and that
+both that copyright notice and this permission notice appear in 
+supporting documentation, and that the name of Digital not be
+used in advertising or publicity pertaining to distribution of the
+software without specific, written prior permission.  
+
+DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
+ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
+DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
+ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+SOFTWARE.
+
+******************************************************************/
+/* $XConsortium: mifillrct.c,v 5.1 94/04/17 20:27:34 keith Exp $ */
+
+#include "X.h"
+#include "Xprotostr.h"
+#include "gcstruct.h"
+#include "windowstr.h"
+#include "pixmap.h"
+
+#include "misc.h"
+
+/* mi rectangles
+   written by newman, with debts to all and sundry
+*/
+
+/* MIPOLYFILLRECT -- public entry for PolyFillRect request
+ * very straight forward: translate rectangles if necessary
+ * then call FillSpans to fill each rectangle.  We let FillSpans worry about
+ * clipping to the destination
+ */
+void
+miPolyFillRect(pDrawable, pGC, nrectFill, prectInit)
+    DrawablePtr        pDrawable;
+    GCPtr      pGC;
+    int                nrectFill;      /* number of rectangles to fill */
+    xRectangle *prectInit;     /* Pointer to first rectangle to fill */
+{
+    int i;
+    register int       height;
+    register int       width;
+    register xRectangle *prect; 
+    int                        xorg;
+    register int       yorg;
+    int                        maxheight;
+    DDXPointPtr                pptFirst;
+    register DDXPointPtr ppt;
+    int                        *pwFirst;
+    register int       *pw;
+
+    if (pGC->miTranslate)
+    {
+       xorg = pDrawable->x;
+       yorg = pDrawable->y;
+        prect = prectInit;
+        maxheight = 0;
+        for (i = 0; i<nrectFill; i++, prect++)
+        {
+           prect->x += xorg;
+           prect->y += yorg;
+           maxheight = max(maxheight, prect->height);
+        }
+    }
+    else
+    {
+        prect = prectInit;
+        maxheight = 0;
+        for (i = 0; i<nrectFill; i++, prect++)
+           maxheight = max(maxheight, prect->height);
+    }
+
+    pptFirst = (DDXPointPtr) ALLOCATE_LOCAL(maxheight * sizeof(DDXPointRec));
+    pwFirst = (int *) ALLOCATE_LOCAL(maxheight * sizeof(int));
+    if(!pptFirst || !pwFirst)
+    {
+       if (pwFirst) DEALLOCATE_LOCAL(pwFirst);
+       if (pptFirst) DEALLOCATE_LOCAL(pptFirst);
+       return;
+    }
+
+    prect = prectInit;
+    while(nrectFill--)
+    {
+       ppt = pptFirst;
+       pw = pwFirst;
+       height = prect->height;
+       width = prect->width;
+       xorg = prect->x;
+       yorg = prect->y;
+       while(height--)
+       {
+           *pw++ = width;
+           ppt->x = xorg;
+           ppt->y = yorg;
+           ppt++;
+           yorg++;
+       }
+       (* pGC->ops->FillSpans)(pDrawable, pGC, 
+                          prect->height, pptFirst, pwFirst,
+                          1);
+       prect++;
+    }
+    DEALLOCATE_LOCAL(pwFirst);
+    DEALLOCATE_LOCAL(pptFirst);
+}
diff --git a/Xserver/programs/Xserver/mi/mifpoly.h b/Xserver/programs/Xserver/mi/mifpoly.h
new file mode 100644 (file)
index 0000000..44be2ad
--- /dev/null
@@ -0,0 +1,109 @@
+/* $XConsortium: mifpoly.h,v 1.9 94/04/17 20:27:35 dpw Exp $ */
+/***********************************************************
+
+Copyright (c) 1987  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+
+Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
+
+                        All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and its 
+documentation for any purpose and without fee is hereby granted, 
+provided that the above copyright notice appear in all copies and that
+both that copyright notice and this permission notice appear in 
+supporting documentation, and that the name of Digital not be
+used in advertising or publicity pertaining to distribution of the
+software without specific, written prior permission.  
+
+DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
+ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
+DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
+ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+SOFTWARE.
+
+******************************************************************/
+
+#define EPSILON        0.000001
+#define ISEQUAL(a,b) (Fabs((a) - (b)) <= EPSILON)
+#define UNEQUAL(a,b) (Fabs((a) - (b)) > EPSILON)
+#define WITHINHALF(a, b) (((a) - (b) > 0.0) ? (a) - (b) < 0.5 : \
+                                            (b) - (a) <= 0.5)
+#define ROUNDTOINT(x)   ((int) (((x) > 0.0) ? ((x) + 0.5) : ((x) - 0.5)))
+#define ISZERO(x)      (Fabs((x)) <= EPSILON)
+#define PTISEQUAL(a,b) (ISEQUAL(a.x,b.x) && ISEQUAL(a.y,b.y))
+#define PTUNEQUAL(a,b) (UNEQUAL(a.x,b.x) || UNEQUAL(a.y,b.y))
+#define PtEqual(a, b) (((a).x == (b).x) && ((a).y == (b).y))
+
+#define NotEnd         0
+#define FirstEnd       1
+#define SecondEnd      2
+
+#define SQSECANT 108.856472512142 /* 1/sin^2(11/2) - for 11o miter cutoff */
+#define D2SECANT 5.21671526231167 /* 1/2*sin(11/2) - max extension per width */
+
+#ifdef NOINLINEICEIL
+#define ICEIL(x) ((int)ceil(x))
+#else
+#ifdef __GNUC__
+static __inline int ICEIL(x)
+    double x;
+{
+    int _cTmp = x;
+    return ((x == _cTmp) || (x < 0.0)) ? _cTmp : _cTmp+1;
+}
+#else
+#define ICEIL(x) ((((x) == (_cTmp = (x))) || ((x) < 0.0)) ? _cTmp : _cTmp+1)
+#define ICEILTEMPDECL static int _cTmp;
+#endif
+#endif
+
+/* Point with sub-pixel positioning.  In this case we use doubles, but
+ * see mifpolycon.c for other suggestions 
+ */
+typedef struct _SppPoint {
+       double  x, y;
+} SppPointRec, *SppPointPtr;
+
+typedef struct _SppArc {
+       double  x, y, width, height;
+       double  angle1, angle2;
+} SppArcRec, *SppArcPtr;
+
+/* mifpolycon.c */
+
+extern void miFillSppPoly(
+#if NeedFunctionPrototypes
+    DrawablePtr /*dst*/,
+    GCPtr /*pgc*/,
+    int /*count*/,
+    SppPointPtr /*ptsIn*/,
+    int /*xTrans*/,
+    int /*yTrans*/,
+    double /*xFtrans*/,
+    double /*yFtrans*/
+#endif
+);
diff --git a/Xserver/programs/Xserver/mi/mifpolycon.c b/Xserver/programs/Xserver/mi/mifpolycon.c
new file mode 100644 (file)
index 0000000..5ccd3ac
--- /dev/null
@@ -0,0 +1,278 @@
+/***********************************************************
+
+Copyright (c) 1987  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+
+Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
+
+                        All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and its 
+documentation for any purpose and without fee is hereby granted, 
+provided that the above copyright notice appear in all copies and that
+both that copyright notice and this permission notice appear in 
+supporting documentation, and that the name of Digital not be
+used in advertising or publicity pertaining to distribution of the
+software without specific, written prior permission.  
+
+DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
+ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
+DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
+ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+SOFTWARE.
+
+******************************************************************/
+/* $XConsortium: mifpolycon.c,v 5.4 94/04/17 20:27:36 rws Exp $ */
+#include <math.h>
+#include "X.h"
+#include "gcstruct.h"
+#include "windowstr.h"
+#include "pixmapstr.h"
+#include "mifpoly.h"
+
+static int GetFPolyYBounds();
+
+#ifdef ICEILTEMPDECL
+ICEILTEMPDECL
+#endif
+
+/*
+ *     Written by Todd Newman; April. 1987.
+ *
+ *     Fill a convex polygon.  If the given polygon
+ *     is not convex, then the result is undefined.
+ *     The algorithm is to order the edges from smallest
+ *     y to largest by partitioning the array into a left
+ *     edge list and a right edge list.  The algorithm used
+ *     to traverse each edge is digital differencing analyzer
+ *     line algorithm with y as the major axis. There's some funny linear
+ *     interpolation involved because of the subpixel postioning.
+ */
+void
+miFillSppPoly(dst, pgc, count, ptsIn, xTrans, yTrans, xFtrans, yFtrans)
+    DrawablePtr        dst;
+    GCPtr              pgc;
+    int                        count;          /* number of points */
+    SppPointPtr        ptsIn;          /* the points */
+    int                        xTrans, yTrans; /* Translate each point by this */
+    double             xFtrans, yFtrans;       /* translate before conversion
+                                                  by this amount.  This provides
+                                                  a mechanism to match rounding
+                                                  errors with any shape that must
+                                                  meet the polygon exactly.
+                                                */
+{
+    double             xl, xr,         /* x vals of left and right edges */
+                       ml,             /* left edge slope */
+                       mr,             /* right edge slope */
+                       dy,             /* delta y */
+                       i;              /* loop counter */
+    int                        y,              /* current scanline */
+                       j,
+                       imin,           /* index of vertex with smallest y */
+                       ymin,           /* y-extents of polygon */
+                       ymax,
+                       *width,
+                       *FirstWidth,    /* output buffer */
+                       *Marked;        /* set if this vertex has been used */
+    register int       left, right,    /* indices to first endpoints */
+                       nextleft,
+                       nextright;      /* indices to second endpoints */
+    DDXPointPtr        ptsOut,
+                       FirstPoint;     /* output buffer */
+
+    if (pgc->miTranslate)
+    {
+       xTrans += dst->x;
+       yTrans += dst->y;
+    }
+
+    imin = GetFPolyYBounds(ptsIn, count, yFtrans, &ymin, &ymax);
+
+    y = ymax - ymin + 1;
+    if ((count < 3) || (y <= 0))
+       return;
+    ptsOut = FirstPoint = (DDXPointPtr)ALLOCATE_LOCAL(sizeof(DDXPointRec) * y);
+    width = FirstWidth = (int *) ALLOCATE_LOCAL(sizeof(int) * y);
+    Marked = (int *) ALLOCATE_LOCAL(sizeof(int) * count);
+
+    if(!ptsOut || !width || !Marked)
+    {
+       if (Marked) DEALLOCATE_LOCAL(Marked);
+       if (width) DEALLOCATE_LOCAL(width);
+       if (ptsOut) DEALLOCATE_LOCAL(ptsOut);
+       return;
+    }
+
+    for(j = 0; j < count; j++)
+       Marked[j] = 0;
+    nextleft = nextright = imin;
+    Marked[imin] = -1;
+    y = ICEIL(ptsIn[nextleft].y + yFtrans);
+
+    /*
+     *  loop through all edges of the polygon
+     */
+    do
+    {
+        /* add a left edge if we need to */
+        if ((y > (ptsIn[nextleft].y + yFtrans) ||
+            ISEQUAL(y, ptsIn[nextleft].y + yFtrans)) &&
+            Marked[nextleft] != 1)
+       {
+           Marked[nextleft]++;
+            left = nextleft++;
+
+            /* find the next edge, considering the end conditions */
+            if (nextleft >= count)
+                nextleft = 0;
+
+            /* now compute the starting point and slope */
+           dy = ptsIn[nextleft].y - ptsIn[left].y;
+           if (dy != 0.0)
+           { 
+               ml = (ptsIn[nextleft].x - ptsIn[left].x) / dy;
+               dy = y - (ptsIn[left].y + yFtrans);
+               xl = (ptsIn[left].x + xFtrans) + ml * max(dy, 0); 
+           }
+        }
+
+        /* add a right edge if we need to */
+        if ((y > ptsIn[nextright].y + yFtrans) ||
+            ISEQUAL(y, ptsIn[nextright].y + yFtrans)
+            && Marked[nextright] != 1)
+       {
+           Marked[nextright]++;
+            right = nextright--;
+
+            /* find the next edge, considering the end conditions */
+            if (nextright < 0)
+                nextright = count - 1;
+
+            /* now compute the starting point and slope */
+           dy = ptsIn[nextright].y - ptsIn[right].y;
+           if (dy != 0.0) 
+           { 
+               mr = (ptsIn[nextright].x - ptsIn[right].x) / dy;
+               dy = y - (ptsIn[right].y + yFtrans); 
+               xr = (ptsIn[right].x + xFtrans) + mr * max(dy, 0);
+           }
+        }
+
+
+        /*
+         *  generate scans to fill while we still have
+         *  a right edge as well as a left edge.
+         */
+        i = (min(ptsIn[nextleft].y, ptsIn[nextright].y) + yFtrans) - y;
+
+       if (i < EPSILON)
+       {
+           if(Marked[nextleft] && Marked[nextright])
+           {
+               /* Arrgh, we're trapped! (no more points) 
+                * Out, we've got to get out of here before this decadence saps
+                * our will completely! */
+               break;
+           }
+           continue;
+       }
+       else
+       {
+               j = (int) i;
+               if(!j)
+                   j++;
+       }
+        while (j > 0) 
+        {
+           int cxl, cxr;
+
+            ptsOut->y = (y) + yTrans;
+
+           cxl = ICEIL(xl);
+           cxr = ICEIL(xr);
+            /* reverse the edges if necessary */
+            if (xl < xr) 
+            {
+                *(width++) = cxr - cxl;
+                (ptsOut++)->x = cxl + xTrans;
+            }
+            else 
+            {
+                *(width++) = cxl - cxr;
+                (ptsOut++)->x = cxr + xTrans;
+            }
+            y++;
+
+            /* increment down the edges */
+           xl += ml;
+           xr += mr;
+           j--;
+        }
+    }  while (y <= ymax);
+
+    /* Finally, fill the spans we've collected */
+    (*pgc->ops->FillSpans)(dst, pgc, 
+                     ptsOut-FirstPoint, FirstPoint, FirstWidth, 1);
+    DEALLOCATE_LOCAL(Marked);
+    DEALLOCATE_LOCAL(FirstWidth);
+    DEALLOCATE_LOCAL(FirstPoint);
+}
+
+\f
+/* Find the index of the point with the smallest y.also return the
+ * smallest and largest y */
+static
+int
+GetFPolyYBounds(pts, n, yFtrans, by, ty)
+    register SppPointPtr       pts;
+    int                        n;
+    double                     yFtrans;
+    int                        *by, *ty;
+{
+    register SppPointPtr       ptMin;
+    double                     ymin, ymax;
+    SppPointPtr                        ptsStart = pts;
+
+    ptMin = pts;
+    ymin = ymax = (pts++)->y;
+
+    while (--n > 0) {
+        if (pts->y < ymin)
+       {
+            ptMin = pts;
+            ymin = pts->y;
+        }
+       if(pts->y > ymax)
+            ymax = pts->y;
+
+        pts++;
+    }
+
+    *by = ICEIL(ymin + yFtrans);
+    *ty = ICEIL(ymax + yFtrans - 1);
+    return(ptMin-ptsStart);
+}
diff --git a/Xserver/programs/Xserver/mi/migc.c b/Xserver/programs/Xserver/mi/migc.c
new file mode 100644 (file)
index 0000000..b96639b
--- /dev/null
@@ -0,0 +1,312 @@
+/* $XConsortium: migc.c,v 1.4 94/04/17 20:27:36 dpw Exp $ */
+/*
+
+Copyright (c) 1993  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be included
+in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR
+OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall
+not be used in advertising or otherwise to promote the sale, use or
+other dealings in this Software without prior written authorization
+from the X Consortium.
+
+*/
+
+
+#include "scrnintstr.h"
+#include "gcstruct.h"
+#include "pixmapstr.h"
+#include "windowstr.h"
+#include "migc.h"
+
+/* This structure has to line up with the mfb and cfb gc private structures so
+ * that when it is superimposed on them, the three fields that migc.c needs to
+ * see will be accessed correctly.  I know this is not beautiful, but it seemed
+ * better than all the code duplication in cfb and mfb.
+ */
+typedef struct {
+    unsigned char       pad1;
+    unsigned char       pad2;
+    unsigned char       pad3;
+    unsigned           pad4:1;
+    unsigned           freeCompClip:1;
+    PixmapPtr          pRotatedPixmap;
+    RegionPtr          pCompositeClip;
+} miPrivGC;
+
+static int miGCPrivateIndex;
+
+void
+miRegisterGCPrivateIndex(gcindex)
+    int gcindex;
+{
+    miGCPrivateIndex = gcindex;
+}
+
+/* ARGSUSED */
+void
+miChangeGC(pGC, mask)
+    GCPtr           pGC;
+    unsigned long   mask;
+{
+    return;
+}
+
+void
+miDestroyGC(pGC)
+    GCPtr           pGC;
+{
+    miPrivGC       *pPriv;
+
+    pPriv = (miPrivGC *) (pGC->devPrivates[miGCPrivateIndex].ptr);
+    if (pPriv->pRotatedPixmap)
+       (*pGC->pScreen->DestroyPixmap) (pPriv->pRotatedPixmap);
+    if (pPriv->freeCompClip)
+       REGION_DESTROY(pGC->pScreen, pPriv->pCompositeClip);
+    miDestroyGCOps(pGC->ops);
+}
+
+/*
+ * create a private op array for a gc
+ */
+
+GCOpsPtr
+miCreateGCOps(prototype)
+    GCOpsPtr        prototype;
+{
+    GCOpsPtr        ret;
+    extern Bool     Must_have_memory;
+
+     /* XXX */ Must_have_memory = TRUE;
+    ret = (GCOpsPtr) xalloc(sizeof(GCOps));
+     /* XXX */ Must_have_memory = FALSE;
+    if (!ret)
+       return 0;
+    *ret = *prototype;
+    ret->devPrivate.val = 1;
+    return ret;
+}
+
+void
+miDestroyGCOps(ops)
+    GCOpsPtr        ops;
+{
+    if (ops->devPrivate.val)
+       xfree(ops);
+}
+
+
+void
+miDestroyClip(pGC)
+    GCPtr           pGC;
+{
+    if (pGC->clientClipType == CT_NONE)
+       return;
+    else if (pGC->clientClipType == CT_PIXMAP)
+    {
+       (*pGC->pScreen->DestroyPixmap) ((PixmapPtr) (pGC->clientClip));
+    }
+    else
+    {
+       /*
+        * we know we'll never have a list of rectangles, since ChangeClip
+        * immediately turns them into a region
+        */
+       REGION_DESTROY(pGC->pScreen, pGC->clientClip);
+    }
+    pGC->clientClip = NULL;
+    pGC->clientClipType = CT_NONE;
+}
+
+void
+miChangeClip(pGC, type, pvalue, nrects)
+    GCPtr           pGC;
+    int             type;
+    pointer         pvalue;
+    int             nrects;
+{
+    (*pGC->funcs->DestroyClip) (pGC);
+    if (type == CT_PIXMAP)
+    {
+       /* convert the pixmap to a region */
+       pGC->clientClip = (pointer) BITMAP_TO_REGION(pGC->pScreen,
+                                                       (PixmapPtr) pvalue);
+       (*pGC->pScreen->DestroyPixmap) (pvalue);
+    }
+    else if (type == CT_REGION)
+    {
+       /* stuff the region in the GC */
+       pGC->clientClip = pvalue;
+    }
+    else if (type != CT_NONE)
+    {
+       pGC->clientClip = (pointer) RECTS_TO_REGION(pGC->pScreen, nrects,
+                                                     (xRectangle *) pvalue,
+                                                                   type);
+       xfree(pvalue);
+    }
+    pGC->clientClipType = (type != CT_NONE && pGC->clientClip) ? CT_REGION : CT_NONE;
+    pGC->stateChanges |= GCClipMask;
+}
+
+void
+miCopyClip(pgcDst, pgcSrc)
+    GCPtr           pgcDst, pgcSrc;
+{
+    RegionPtr       prgnNew;
+
+    switch (pgcSrc->clientClipType)
+    {
+      case CT_PIXMAP:
+       ((PixmapPtr) pgcSrc->clientClip)->refcnt++;
+       /* Fall through !! */
+      case CT_NONE:
+       (*pgcDst->funcs->ChangeClip) (pgcDst, (int) pgcSrc->clientClipType,
+                                  pgcSrc->clientClip, 0);
+       break;
+      case CT_REGION:
+       prgnNew = REGION_CREATE(pgcSrc->pScreen, NULL, 1);
+       REGION_COPY(pgcDst->pScreen, prgnNew,
+                                       (RegionPtr) (pgcSrc->clientClip));
+       (*pgcDst->funcs->ChangeClip) (pgcDst, CT_REGION, (pointer) prgnNew, 0);
+       break;
+    }
+}
+
+/* ARGSUSED */
+void
+miCopyGC(pGCSrc, changes, pGCDst)
+    GCPtr           pGCSrc;
+    unsigned long   changes;
+    GCPtr           pGCDst;
+{
+    return;
+}
+
+void
+miComputeCompositeClip(pGC, pDrawable)
+    GCPtr           pGC;
+    DrawablePtr     pDrawable;
+{
+    ScreenPtr       pScreen = pGC->pScreen;
+    miPrivGC *devPriv = (miPrivGC *) (pGC->devPrivates[miGCPrivateIndex].ptr);
+
+    if (pDrawable->type == DRAWABLE_WINDOW)
+    {
+       WindowPtr       pWin = (WindowPtr) pDrawable;
+       RegionPtr       pregWin;
+       Bool            freeTmpClip, freeCompClip;
+
+       if (pGC->subWindowMode == IncludeInferiors)
+       {
+           pregWin = NotClippedByChildren(pWin);
+           freeTmpClip = TRUE;
+       }
+       else
+       {
+           pregWin = &pWin->clipList;
+           freeTmpClip = FALSE;
+       }
+       freeCompClip = devPriv->freeCompClip;
+
+       /*
+        * if there is no client clip, we can get by with just keeping the
+        * pointer we got, and remembering whether or not should destroy (or
+        * maybe re-use) it later.  this way, we avoid unnecessary copying of
+        * regions.  (this wins especially if many clients clip by children
+        * and have no client clip.)
+        */
+       if (pGC->clientClipType == CT_NONE)
+       {
+           if (freeCompClip)
+               REGION_DESTROY(pScreen, devPriv->pCompositeClip);
+           devPriv->pCompositeClip = pregWin;
+           devPriv->freeCompClip = freeTmpClip;
+       }
+       else
+       {
+           /*
+            * we need one 'real' region to put into the composite clip. if
+            * pregWin the current composite clip are real, we can get rid of
+            * one. if pregWin is real and the current composite clip isn't,
+            * use pregWin for the composite clip. if the current composite
+            * clip is real and pregWin isn't, use the current composite
+            * clip. if neither is real, create a new region.
+            */
+
+           REGION_TRANSLATE(pScreen, pGC->clientClip,
+                                        pDrawable->x + pGC->clipOrg.x,
+                                        pDrawable->y + pGC->clipOrg.y);
+
+           if (freeCompClip)
+           {
+               REGION_INTERSECT(pGC->pScreen, devPriv->pCompositeClip,
+                                           pregWin, pGC->clientClip);
+               if (freeTmpClip)
+                   REGION_DESTROY(pScreen, pregWin);
+           }
+           else if (freeTmpClip)
+           {
+               REGION_INTERSECT(pScreen, pregWin, pregWin, pGC->clientClip);
+               devPriv->pCompositeClip = pregWin;
+           }
+           else
+           {
+               devPriv->pCompositeClip = REGION_CREATE(pScreen, NullBox, 0);
+               REGION_INTERSECT(pScreen, devPriv->pCompositeClip,
+                                      pregWin, pGC->clientClip);
+           }
+           devPriv->freeCompClip = TRUE;
+           REGION_TRANSLATE(pScreen, pGC->clientClip,
+                                        -(pDrawable->x + pGC->clipOrg.x),
+                                        -(pDrawable->y + pGC->clipOrg.y));
+       }
+    }  /* end of composite clip for a window */
+    else
+    {
+       BoxRec          pixbounds;
+
+       /* XXX should we translate by drawable.x/y here ? */
+       pixbounds.x1 = 0;
+       pixbounds.y1 = 0;
+       pixbounds.x2 = pDrawable->width;
+       pixbounds.y2 = pDrawable->height;
+
+       if (devPriv->freeCompClip)
+       {
+           REGION_RESET(pScreen, devPriv->pCompositeClip, &pixbounds);
+       }
+       else
+       {
+           devPriv->freeCompClip = TRUE;
+           devPriv->pCompositeClip = REGION_CREATE(pScreen, &pixbounds, 1);
+       }
+
+       if (pGC->clientClipType == CT_REGION)
+       {
+           REGION_TRANSLATE(pScreen, devPriv->pCompositeClip,
+                                        -pGC->clipOrg.x, -pGC->clipOrg.y);
+           REGION_INTERSECT(pScreen, devPriv->pCompositeClip,
+                               devPriv->pCompositeClip, pGC->clientClip);
+           REGION_TRANSLATE(pScreen, devPriv->pCompositeClip,
+                                        pGC->clipOrg.x, pGC->clipOrg.y);
+       }
+    }  /* end of composite clip for pixmap */
+} /* end miComputeCompositeClip */
diff --git a/Xserver/programs/Xserver/mi/migc.h b/Xserver/programs/Xserver/mi/migc.h
new file mode 100644 (file)
index 0000000..d6cfe95
--- /dev/null
@@ -0,0 +1,99 @@
+/* $XConsortium: migc.h,v 1.3 94/04/17 20:27:37 dpw Exp $ */
+/*
+
+Copyright (c) 1993  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be included
+in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR
+OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall
+not be used in advertising or otherwise to promote the sale, use or
+other dealings in this Software without prior written authorization
+from the X Consortium.
+
+*/
+
+
+extern void miRegisterGCPrivateIndex(
+#if NeedFunctionPrototypes
+    int /*gcindex*/
+#endif
+);
+
+extern void miChangeGC(
+#if NeedFunctionPrototypes
+    GCPtr  /*pGC*/,
+    unsigned long /*mask*/
+#endif
+);
+
+extern void miDestroyGC(
+#if NeedFunctionPrototypes
+    GCPtr  /*pGC*/
+#endif
+);
+
+extern GCOpsPtr miCreateGCOps(
+#if NeedFunctionPrototypes
+    GCOpsPtr /*prototype*/
+#endif
+);
+
+extern void miDestroyGCOps(
+#if NeedFunctionPrototypes
+    GCOpsPtr /*ops*/
+#endif
+);
+
+extern void miDestroyClip(
+#if NeedFunctionPrototypes
+    GCPtr /*pGC*/
+#endif
+);
+
+extern void miChangeClip(
+#if NeedFunctionPrototypes
+    GCPtr   /*pGC*/,
+    int     /*type*/,
+    pointer /*pvalue*/,
+    int     /*nrects*/
+#endif
+);
+
+extern void miCopyClip(
+#if NeedFunctionPrototypes
+    GCPtr /*pgcDst*/,
+    GCPtr /*pgcSrc*/
+#endif
+);
+
+extern void miCopyGC(
+#if NeedFunctionPrototypes
+    GCPtr /*pGCSrc*/,
+    unsigned long /*changes*/,
+    GCPtr /*pGCDst*/
+#endif
+);
+
+extern void miComputeCompositeClip(
+#if NeedFunctionPrototypes
+    GCPtr       /*pGC*/,
+    DrawablePtr /*pDrawable*/
+#endif
+);
diff --git a/Xserver/programs/Xserver/mi/miglblt.c b/Xserver/programs/Xserver/mi/miglblt.c
new file mode 100644 (file)
index 0000000..63a3679
--- /dev/null
@@ -0,0 +1,249 @@
+/***********************************************************
+
+Copyright (c) 1987  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+
+Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
+
+                        All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and its 
+documentation for any purpose and without fee is hereby granted, 
+provided that the above copyright notice appear in all copies and that
+both that copyright notice and this permission notice appear in 
+supporting documentation, and that the name of Digital not be
+used in advertising or publicity pertaining to distribution of the
+software without specific, written prior permission.  
+
+DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
+ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
+DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
+ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+SOFTWARE.
+
+******************************************************************/
+
+/* $XConsortium: miglblt.c,v 5.9 94/04/17 20:27:37 dpw Exp $ */
+
+#include       "X.h"
+#include       "Xmd.h"
+#include       "Xproto.h"
+#include       "misc.h"
+#include       "fontstruct.h"
+#include       "dixfontstr.h"
+#include       "gcstruct.h"
+#include       "windowstr.h"
+#include       "scrnintstr.h"
+#include       "pixmap.h"
+#include       "servermd.h"
+
+/*
+    machine-independent glyph blt.
+    assumes that glyph bits in snf are written in bytes,
+have same bit order as the server's bitmap format,
+and are byte padded.  this corresponds to the snf distributed
+with the sample server.
+
+    get a scratch GC.
+    in the scratch GC set alu = GXcopy, fg = 1, bg = 0
+    allocate a bitmap big enough to hold the largest glyph in the font
+    validate the scratch gc with the bitmap
+    for each glyph
+       carefully put the bits of the glyph in a buffer,
+           padded to the server pixmap scanline padding rules
+       fake a call to PutImage from the buffer into the bitmap
+       use the bitmap in a call to PushPixels
+*/
+
+void
+miPolyGlyphBlt(pDrawable, pGC, x, y, nglyph, ppci, pglyphBase)
+    DrawablePtr pDrawable;
+    GC                 *pGC;
+    int        x, y;
+    unsigned int nglyph;
+    CharInfoPtr *ppci;         /* array of character info */
+    unsigned char *pglyphBase; /* start of array of glyphs */
+{
+    int width, height;
+    PixmapPtr pPixmap;
+    int nbyLine;                       /* bytes per line of padded pixmap */
+    FontPtr pfont;
+    GCPtr pGCtmp;
+    register int i;
+    register int j;
+    unsigned char *pbits;              /* buffer for PutImage */
+    register unsigned char *pb;                /* temp pointer into buffer */
+    register CharInfoPtr pci;          /* currect char info */
+    register unsigned char *pglyph;    /* pointer bits in glyph */
+    int gWidth, gHeight;               /* width and height of glyph */
+    register int nbyGlyphWidth;                /* bytes per scanline of glyph */
+    int nbyPadGlyph;                   /* server padded line of glyph */
+
+    XID gcvals[3];
+
+    if (pGC->miTranslate)
+    {
+       x += pDrawable->x;
+       y += pDrawable->y;
+    }
+
+    pfont = pGC->font;
+    width = FONTMAXBOUNDS(pfont,rightSideBearing) - 
+           FONTMINBOUNDS(pfont,leftSideBearing);
+    height = FONTMAXBOUNDS(pfont,ascent) +
+            FONTMAXBOUNDS(pfont,descent);
+
+    pPixmap = (*pDrawable->pScreen->CreatePixmap)(pDrawable->pScreen,
+                                                 width, height, 1);
+    if (!pPixmap)
+       return;
+
+    pGCtmp = GetScratchGC(1, pDrawable->pScreen);
+    if (!pGCtmp)
+    {
+       (*pDrawable->pScreen->DestroyPixmap)(pPixmap);
+       return;
+    }
+
+    gcvals[0] = GXcopy;
+    gcvals[1] = 1;
+    gcvals[2] = 0;
+
+    DoChangeGC(pGCtmp, GCFunction|GCForeground|GCBackground, gcvals, 0);
+
+    nbyLine = BitmapBytePad(width);
+    pbits = (unsigned char *)ALLOCATE_LOCAL(height*nbyLine);
+    if (!pbits)
+    {
+       (*pDrawable->pScreen->DestroyPixmap)(pPixmap);
+       FreeScratchGC(pGCtmp);
+        return;
+    }
+    while(nglyph--)
+    {
+       pci = *ppci++;
+       pglyph = FONTGLYPHBITS(pglyphBase, pci);
+       gWidth = GLYPHWIDTHPIXELS(pci);
+       gHeight = GLYPHHEIGHTPIXELS(pci);
+       if (gWidth && gHeight)
+       {
+           nbyGlyphWidth = GLYPHWIDTHBYTESPADDED(pci);
+           nbyPadGlyph = BitmapBytePad(gWidth);
+
+           if (nbyGlyphWidth == nbyPadGlyph
+#if GLYPHPADBYTES != 4
+               && (((int) pglyph) & 3) == 0
+#endif
+               )
+           {
+               pb = pglyph;
+           }
+           else
+           {
+               for (i=0, pb = pbits; i<gHeight; i++, pb = pbits+(i*nbyPadGlyph))
+                   for (j = 0; j < nbyGlyphWidth; j++)
+                       *pb++ = *pglyph++;
+               pb = pbits;
+           }
+
+           if ((pGCtmp->serialNumber) != (pPixmap->drawable.serialNumber))
+               ValidateGC((DrawablePtr)pPixmap, pGCtmp);
+           (*pGCtmp->ops->PutImage)((DrawablePtr)pPixmap, pGCtmp,
+                               pPixmap->drawable.depth,
+                               0, 0, gWidth, gHeight, 
+                               0, XYBitmap, (char *)pb);
+
+           if ((pGC->serialNumber) != (pDrawable->serialNumber))
+               ValidateGC(pDrawable, pGC);
+           (*pGC->ops->PushPixels)(pGC, pPixmap, pDrawable,
+                              gWidth, gHeight,
+                              x + pci->metrics.leftSideBearing,
+                              y - pci->metrics.ascent);
+       }
+       x += pci->metrics.characterWidth;
+    }
+    (*pDrawable->pScreen->DestroyPixmap)(pPixmap);
+    DEALLOCATE_LOCAL(pbits);
+    FreeScratchGC(pGCtmp);
+}
+
+
+void
+miImageGlyphBlt(pDrawable, pGC, x, y, nglyph, ppci, pglyphBase)
+    DrawablePtr pDrawable;
+    GC                 *pGC;
+    int        x, y;
+    unsigned int nglyph;
+    CharInfoPtr *ppci;         /* array of character info */
+    unsigned char *pglyphBase; /* start of array of glyphs */
+{
+    ExtentInfoRec info;                /* used by QueryGlyphExtents() */
+    XID gcvals[3];
+    int oldAlu, oldFS;
+    unsigned long      oldFG;
+    xRectangle backrect;
+
+    QueryGlyphExtents(pGC->font, ppci, (unsigned long)nglyph, &info);
+
+    if (info.overallWidth >= 0)
+    {
+       backrect.x = x;
+       backrect.width = info.overallWidth;
+    }
+    else
+    {
+       backrect.x = x + info.overallWidth;
+       backrect.width = -info.overallWidth;
+    }
+    backrect.y = y - FONTASCENT(pGC->font);
+    backrect.height = FONTASCENT(pGC->font) + FONTDESCENT(pGC->font);
+
+    oldAlu = pGC->alu;
+    oldFG = pGC->fgPixel;
+    oldFS = pGC->fillStyle;
+
+    /* fill in the background */
+    gcvals[0] = GXcopy;
+    gcvals[1] = pGC->bgPixel;
+    gcvals[2] = FillSolid;
+    DoChangeGC(pGC, GCFunction|GCForeground|GCFillStyle, gcvals, 0);
+    ValidateGC(pDrawable, pGC);
+    (*pGC->ops->PolyFillRect)(pDrawable, pGC, 1, &backrect);
+
+    /* put down the glyphs */
+    gcvals[0] = oldFG;
+    DoChangeGC(pGC, GCForeground, gcvals, 0);
+    ValidateGC(pDrawable, pGC);
+    (*pGC->ops->PolyGlyphBlt)(pDrawable, pGC, x, y, nglyph, ppci,
+                             (char *)pglyphBase);
+
+    /* put all the toys away when done playing */
+    gcvals[0] = oldAlu;
+    gcvals[1] = oldFG;
+    gcvals[2] = oldFS;
+    DoChangeGC(pGC, GCFunction|GCForeground|GCFillStyle, gcvals, 0);
+
+}
diff --git a/Xserver/programs/Xserver/mi/miinitext.c b/Xserver/programs/Xserver/mi/miinitext.c
new file mode 100644 (file)
index 0000000..7ee3a17
--- /dev/null
@@ -0,0 +1,280 @@
+/***********************************************************
+
+Copyright (c) 1987  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+
+Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
+
+                        All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and its 
+documentation for any purpose and without fee is hereby granted, 
+provided that the above copyright notice appear in all copies and that
+both that copyright notice and this permission notice appear in 
+supporting documentation, and that the name of Digital not be
+used in advertising or publicity pertaining to distribution of the
+software without specific, written prior permission.  
+
+DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
+ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
+DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
+ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+SOFTWARE.
+
+******************************************************************/
+/* $XConsortium: miinitext.c /main/41 1996/09/28 17:15:08 rws $ */
+/* $XFree86: xc/programs/Xserver/mi/miinitext.c,v 3.17.2.3 1997/05/22 14:00:46 dawes Exp $ */
+
+#include "misc.h"
+#include "extension.h"
+
+#ifdef NOPEXEXT /* sleaze for Solaris cpp building XsunMono */
+#undef PEXEXT
+#endif
+
+extern Bool noTestExtensions;
+#ifdef XKB
+extern Bool noXkbExtension;
+#endif
+
+#if NeedFunctionPrototypes
+#define INITARGS void
+#else
+#define INITARGS /*nothing*/
+#endif
+typedef void (*InitExtension)(INITARGS);
+
+/* FIXME: this whole block of externs should be from the appropriate headers */
+#ifdef BEZIER
+extern void BezierExtensionInit(INITARGS);
+#endif
+#ifdef XTESTEXT1
+extern void XTestExtension1Init(INITARGS);
+#endif
+#ifdef SHAPE
+extern void ShapeExtensionInit(INITARGS);
+#endif
+#ifdef MITSHM
+extern void ShmExtensionInit(INITARGS);
+#endif
+#ifdef PEXEXT
+#ifndef PEX_MODULE
+extern void PexExtensionInit(INITARGS);
+#endif
+InitExtension PexExtensionInitPtr = NULL;
+#endif
+#ifdef MULTIBUFFER
+extern void MultibufferExtensionInit(INITARGS);
+#endif
+#ifdef XINPUT
+extern void XInputExtensionInit(INITARGS);
+#endif
+#ifdef XTEST
+extern void XTestExtensionInit(INITARGS);
+#endif
+#ifdef BIGREQS
+extern void BigReqExtensionInit(INITARGS);
+#endif
+#ifdef MITMISC
+extern void MITMiscExtensionInit(INITARGS);
+#endif
+#ifdef XIDLE
+extern void XIdleExtensionInit(INITARGS);
+#endif
+#ifdef XTRAP
+extern void DEC_XTRAPInit(INITARGS);
+#endif
+#ifdef SCREENSAVER
+extern void ScreenSaverExtensionInit (INITARGS);
+#endif
+#ifdef XV
+extern void XvExtensionInit(INITARGS);
+#endif
+#ifdef XIE
+#ifndef XIE_MODULE
+extern void XieInit(INITARGS);
+#endif
+InitExtension XieInitPtr = NULL;
+#endif
+#ifdef XSYNC
+extern void SyncExtensionInit(INITARGS);
+#endif
+#ifdef XKB
+extern void XkbExtensionInit(INITARGS);
+#endif
+#ifdef XCMISC
+extern void XCMiscExtensionInit(INITARGS);
+#endif
+#ifdef XRECORD
+extern void RecordExtensionInit(INITARGS);
+#endif
+#ifdef LBX
+extern void     LbxExtensionInit(INITARGS);
+#endif
+#ifdef DBE
+extern void     DbeExtensionInit(INITARGS);
+#endif
+#ifdef XAPPGROUP
+extern void XagExtensionInit(INITARGS);
+#endif
+#ifdef XCSECURITY
+extern void SecurityExtensionInit(INITARGS);
+#endif
+#ifdef XPRINT
+extern void    XpExtensionInit(INITARGS);
+#endif
+#ifdef XF86VIDMODE
+extern void    XFree86VidModeExtensionInit(INITARGS);
+#endif
+#ifdef XF86MISC
+extern void    XFree86MiscExtensionInit(INITARGS);
+#endif
+#ifdef XFreeXDGA
+extern void XFree86DGAExtensionInit(INITARGS);
+#endif
+#ifdef DPMSExtension
+extern void DPMSExtensionInit(INITARGS);
+#endif
+#ifdef GLXEXT
+#ifndef GLX_MODULE
+extern void GlxExtensionInit(INITARGS);
+#else
+InitExtension GlxExtensionInitPtr = NULL;
+#endif
+#endif
+
+/*ARGSUSED*/
+void
+InitExtensions(argc, argv)
+    int                argc;
+    char       *argv[];
+{
+#ifdef BEZIER
+    BezierExtensionInit();
+#endif
+#ifdef XTESTEXT1
+    if (!noTestExtensions) XTestExtension1Init();
+#endif
+#ifdef SHAPE
+    ShapeExtensionInit();
+#endif
+#ifdef MITSHM
+    ShmExtensionInit();
+#endif
+#ifdef PEXEXT
+#ifndef PEX_MODULE
+    PexExtensionInit();
+#else
+    if (PexExtensionInitPtr != NULL) {
+       (*PexExtensionInitPtr)();
+    }
+#endif
+#endif
+#ifdef MULTIBUFFER
+    MultibufferExtensionInit();
+#endif
+#ifdef XINPUT
+    XInputExtensionInit();
+#endif
+#ifdef XTEST
+    if (!noTestExtensions) XTestExtensionInit();
+#endif
+#ifdef BIGREQS
+    BigReqExtensionInit();
+#endif
+#ifdef MITMISC
+    MITMiscExtensionInit();
+#endif
+#ifdef XIDLE
+    XIdleExtensionInit();
+#endif
+#ifdef XTRAP
+    if (!noTestExtensions) DEC_XTRAPInit();
+#endif
+#ifdef SCREENSAVER
+    ScreenSaverExtensionInit ();
+#endif
+#ifdef XV
+    XvExtensionInit();
+#endif
+#ifdef XIE
+#ifndef XIE_MODULE
+    XieInit();
+#else
+    if (XieInitPtr != NULL) {
+       (*XieInitPtr)();
+    }
+#endif
+#endif
+#ifdef XSYNC
+    SyncExtensionInit();
+#endif
+#ifdef XKB
+    if (!noXkbExtension) XkbExtensionInit();
+#endif
+#ifdef XCMISC
+    XCMiscExtensionInit();
+#endif
+#ifdef XRECORD
+    if (!noTestExtensions) RecordExtensionInit(); 
+#endif
+#ifdef LBX
+    LbxExtensionInit();
+#endif
+#ifdef DBE
+    DbeExtensionInit();
+#endif
+#ifdef XAPPGROUP
+    XagExtensionInit();
+#endif
+#ifdef XCSECURITY
+    SecurityExtensionInit();
+#endif
+#ifdef XPRINT
+    XpExtensionInit();
+#endif
+#if defined(XF86VIDMODE) && !defined(PRINT_ONLY_SERVER)
+    XFree86VidModeExtensionInit();
+#endif
+#if defined(XF86MISC) && !defined(PRINT_ONLY_SERVER)
+    XFree86MiscExtensionInit();
+#endif
+#if defined(XFreeXDGA) && !defined(PRINT_ONLY_SERVER)
+    XFree86DGAExtensionInit();
+#endif
+#if defined(DPMSExtension) && !defined(PRINT_ONLY_SERVER)
+    DPMSExtensionInit();
+#endif
+#ifdef GLXEXT
+#ifndef GLX_MODULE
+    GlxExtensionInit();
+#else
+    if (GlxExtensionInitPtr != NULL) {
+        (*GlxExtensionInitPtr)();
+    }
+#endif
+#endif
+}
diff --git a/Xserver/programs/Xserver/mi/miline.h b/Xserver/programs/Xserver/mi/miline.h
new file mode 100644 (file)
index 0000000..ff0f8e8
--- /dev/null
@@ -0,0 +1,168 @@
+/* $XConsortium: miline.h /main/6 1996/08/12 21:51:09 dpw $ */
+
+/*
+
+Copyright (c) 1994  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+*/
+
+#ifndef MILINE_H
+
+/*
+ * Public definitions used for configuring basic pixelization aspects
+ * of the sample implementation line-drawing routines provided in
+ * {mfb,mi,cfb*} at run-time.
+ */
+
+#define XDECREASING    4
+#define YDECREASING    2
+#define YMAJOR         1
+
+#define OCTANT1                (1 << (YDECREASING))
+#define OCTANT2                (1 << (YDECREASING|YMAJOR))
+#define OCTANT3                (1 << (XDECREASING|YDECREASING|YMAJOR))
+#define OCTANT4                (1 << (XDECREASING|YDECREASING))
+#define OCTANT5                (1 << (XDECREASING))
+#define OCTANT6                (1 << (XDECREASING|YMAJOR))
+#define OCTANT7                (1 << (YMAJOR))
+#define OCTANT8                (1 << (0))
+
+#define XMAJOROCTANTS          (OCTANT1 | OCTANT4 | OCTANT5 | OCTANT8)
+
+#define DEFAULTZEROLINEBIAS    (OCTANT2 | OCTANT3 | OCTANT4 | OCTANT5)
+
+/*
+ * Devices can configure the rendering of routines in mi, mfb, and cfb*
+ * by specifying a thin line bias to be applied to a particular screen
+ * using the following function.  The bias parameter is an OR'ing of
+ * the appropriate OCTANT constants defined above to indicate which
+ * octants to bias a line to prefer an axial step when the Bresenham
+ * error term is exactly zero.  The octants are mapped as follows:
+ *
+ *   \    |    /
+ *    \ 3 | 2 /
+ *     \  |  /
+ *    4 \ | / 1
+ *       \|/
+ *   -----------
+ *       /|\
+ *    5 / | \ 8
+ *     /  |  \
+ *    / 6 | 7 \
+ *   /    |    \
+ *
+ * For more information, see "Ambiguities in Incremental Line Rastering,"
+ * Jack E. Bresenham, IEEE CG&A, May 1987.
+ */
+
+extern void miSetZeroLineBias(
+#if NeedFunctionPrototypes
+    ScreenPtr /* pScreen */,
+    unsigned int /* bias */
+#endif
+);
+
+/*
+ * Private definitions needed for drawing thin (zero width) lines
+ * Used by the mi, mfb, and all cfb* components.
+ */
+
+#define X_AXIS 0
+#define Y_AXIS 1
+
+#define OUT_LEFT  0x08
+#define OUT_RIGHT 0x04
+#define OUT_ABOVE 0x02
+#define OUT_BELOW 0x01
+
+#define OUTCODES(_result, _x, _y, _pbox) \
+    if     ( (_x) <  (_pbox)->x1) (_result) |= OUT_LEFT; \
+    else if ( (_x) >= (_pbox)->x2) (_result) |= OUT_RIGHT; \
+    if     ( (_y) <  (_pbox)->y1) (_result) |= OUT_ABOVE; \
+    else if ( (_y) >= (_pbox)->y2) (_result) |= OUT_BELOW;
+
+#define SWAPINT(i, j) \
+{  register int _t = i;  i = j;  j = _t; }
+
+#define SWAPPT(i, j) \
+{  DDXPointRec _t; _t = i;  i = j; j = _t; }
+
+#define SWAPINT_PAIR(x1, y1, x2, y2)\
+{   int t = x1;  x1 = x2;  x2 = t;\
+        t = y1;  y1 = y2;  y2 = t;\
+}
+
+#define miGetZeroLineBias(_pScreen) \
+    ((miZeroLineScreenIndex < 0) ? \
+               0 : ((_pScreen)->devPrivates[miZeroLineScreenIndex].uval))
+
+#define CalcLineDeltas(_x1,_y1,_x2,_y2,_adx,_ady,_sx,_sy,_SX,_SY,_octant) \
+    (_octant) = 0;                             \
+    (_sx) = (_SX);                             \
+    if (((_adx) = (_x2) - (_x1)) < 0) {                \
+       (_adx) = -(_adx);                       \
+       (_sx = -(_sx));                         \
+       (_octant) |= XDECREASING;               \
+    }                                          \
+    (_sy) = (_SY);                             \
+    if (((_ady) = (_y2) - (_y1)) < 0) {                \
+       (_ady) = -(_ady);                       \
+       (_sy = -(_sy));                         \
+       (_octant) |= YDECREASING;               \
+    }
+
+#define SetYMajorOctant(_octant)       ((_octant) |= YMAJOR)
+
+#define FIXUP_ERROR(_e, _octant, _bias) \
+    (_e) -= (((_bias) >> (_octant)) & 1)
+
+#define IsXMajorOctant(_octant)                (!((_octant) & YMAJOR))
+#define IsYMajorOctant(_octant)                ((_octant) & YMAJOR)
+#define IsXDecreasingOctant(_octant)   ((_octant) & XDECREASING)
+#define IsYDecreasingOctant(_octant)   ((_octant) & YDECREASING)
+
+extern int miZeroLineScreenIndex;
+
+extern int miZeroClipLine(
+#if NeedFunctionPrototypes
+    int /*xmin*/,
+    int /*ymin*/,
+    int /*xmax*/,
+    int /*ymax*/,
+    int * /*new_x1*/,
+    int * /*new_y1*/,
+    int * /*new_x2*/,
+    int * /*new_y2*/,
+    unsigned int /*adx*/,
+    unsigned int /*ady*/,
+    int * /*pt1_clipped*/,
+    int * /*pt2_clipped*/,
+    int /*octant*/,
+    unsigned int /*bias*/,
+    int /*oc1*/,
+    int /*oc2*/
+#endif
+);
+
+#endif /* MILINE_H */
diff --git a/Xserver/programs/Xserver/mi/mipointer.c b/Xserver/programs/Xserver/mi/mipointer.c
new file mode 100644 (file)
index 0000000..1b82411
--- /dev/null
@@ -0,0 +1,512 @@
+/*
+ * mipointer.c
+ */
+
+/* $XConsortium: mipointer.c,v 5.24 94/04/17 20:27:39 dpw Exp $ */
+/* $XFree86: xc/programs/Xserver/mi/mipointer.c,v 3.1 1996/03/10 12:12:44 dawes Exp $ */
+
+/*
+
+Copyright (c) 1989  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+*/
+
+# define NEED_EVENTS
+# include   "X.h"
+# include   "Xmd.h"
+# include   "Xproto.h"
+# include   "misc.h"
+# include   "windowstr.h"
+# include   "pixmapstr.h"
+# include   "mi.h"
+# include   "scrnintstr.h"
+# include   "mipointrst.h"
+# include   "cursorstr.h"
+# include   "dixstruct.h"
+
+static int  miPointerScreenIndex;
+static unsigned long miPointerGeneration = 0;
+
+#define GetScreenPrivate(s) ((miPointerScreenPtr) ((s)->devPrivates[miPointerScreenIndex].ptr))
+#define SetupScreen(s) miPointerScreenPtr  pScreenPriv = GetScreenPrivate(s)
+
+/*
+ * until more than one pointer device exists.
+ */
+
+static miPointerRec miPointer;
+
+static Bool miPointerRealizeCursor (),     miPointerUnrealizeCursor ();
+static Bool miPointerDisplayCursor ();
+static void miPointerConstrainCursor (),    miPointerPointerNonInterestBox();
+static void miPointerCursorLimits ();
+static Bool miPointerSetCursorPosition ();
+
+static Bool miPointerCloseScreen();
+
+static void miPointerMove ();
+
+Bool
+miPointerInitialize (pScreen, spriteFuncs, screenFuncs, waitForUpdate)
+    ScreenPtr              pScreen;
+    miPointerSpriteFuncPtr  spriteFuncs;
+    miPointerScreenFuncPtr  screenFuncs;
+    Bool                   waitForUpdate;
+{
+    miPointerScreenPtr pScreenPriv;
+
+    if (miPointerGeneration != serverGeneration)
+    {
+       miPointerScreenIndex = AllocateScreenPrivateIndex();
+       if (miPointerScreenIndex < 0)
+           return FALSE;
+       miPointerGeneration = serverGeneration;
+    }
+    pScreenPriv = (miPointerScreenPtr) xalloc (sizeof (miPointerScreenRec));
+    if (!pScreenPriv)
+       return FALSE;
+    pScreenPriv->spriteFuncs = spriteFuncs;
+    pScreenPriv->screenFuncs = screenFuncs;
+    /*
+     * check for uninitialized methods
+     */
+    if (!screenFuncs->EnqueueEvent)
+       screenFuncs->EnqueueEvent = mieqEnqueue;
+    if (!screenFuncs->NewEventScreen)
+       screenFuncs->NewEventScreen = mieqSwitchScreen;
+    pScreenPriv->waitForUpdate = waitForUpdate;
+    pScreenPriv->CloseScreen = pScreen->CloseScreen;
+    pScreen->CloseScreen = miPointerCloseScreen;
+    pScreen->devPrivates[miPointerScreenIndex].ptr = (pointer) pScreenPriv;
+    /*
+     * set up screen cursor method table
+     */
+    pScreen->ConstrainCursor = miPointerConstrainCursor;
+    pScreen->CursorLimits = miPointerCursorLimits;
+    pScreen->DisplayCursor = miPointerDisplayCursor;
+    pScreen->RealizeCursor = miPointerRealizeCursor;
+    pScreen->UnrealizeCursor = miPointerUnrealizeCursor;
+    pScreen->SetCursorPosition = miPointerSetCursorPosition;
+    pScreen->RecolorCursor = miRecolorCursor;
+    pScreen->PointerNonInterestBox = miPointerPointerNonInterestBox;
+    /*
+     * set up the pointer object
+     */
+    miPointer.pScreen = NULL;
+    miPointer.pSpriteScreen = NULL;
+    miPointer.pCursor = NULL;
+    miPointer.pSpriteCursor = NULL;
+    miPointer.limits.x1 = 0;
+    miPointer.limits.x2 = 32767;
+    miPointer.limits.y1 = 0;
+    miPointer.limits.y2 = 32767;
+    miPointer.confined = FALSE;
+    miPointer.x = 0;
+    miPointer.y = 0;
+    miPointer.history_start = miPointer.history_end = 0;
+    return TRUE;
+}
+
+static Bool
+miPointerCloseScreen (index, pScreen)
+    int                index;
+    ScreenPtr  pScreen;
+{
+    SetupScreen(pScreen);
+
+    if (pScreen == miPointer.pScreen)
+       miPointer.pScreen = 0;
+    if (pScreen == miPointer.pSpriteScreen)
+       miPointer.pSpriteScreen = 0;
+    pScreen->CloseScreen = pScreenPriv->CloseScreen;
+    xfree ((pointer) pScreenPriv);
+    return (*pScreen->CloseScreen) (index, pScreen);
+}
+
+/*
+ * DIX/DDX interface routines
+ */
+
+static Bool
+miPointerRealizeCursor (pScreen, pCursor)
+    ScreenPtr  pScreen;
+    CursorPtr  pCursor;
+{
+    SetupScreen(pScreen);
+
+    return (*pScreenPriv->spriteFuncs->RealizeCursor) (pScreen, pCursor);
+}
+
+static Bool
+miPointerUnrealizeCursor (pScreen, pCursor)
+    ScreenPtr  pScreen;
+    CursorPtr  pCursor;
+{
+    SetupScreen(pScreen);
+
+    return (*pScreenPriv->spriteFuncs->UnrealizeCursor) (pScreen, pCursor);
+}
+
+static Bool
+miPointerDisplayCursor (pScreen, pCursor)
+    ScreenPtr  pScreen;
+    CursorPtr  pCursor;
+{
+    SetupScreen(pScreen);
+
+    miPointer.pCursor = pCursor;
+    miPointer.pScreen = pScreen;
+    miPointerUpdate ();
+    return TRUE;
+}
+
+static void
+miPointerConstrainCursor (pScreen, pBox)
+    ScreenPtr  pScreen;
+    BoxPtr     pBox;
+{
+    miPointer.limits = *pBox;
+    miPointer.confined = PointerConfinedToScreen();
+}
+
+/*ARGSUSED*/
+static void
+miPointerPointerNonInterestBox (pScreen, pBox)
+    ScreenPtr  pScreen;
+    BoxPtr     pBox;
+{
+    /* until DIX uses this, this will remain a stub */
+}
+
+/*ARGSUSED*/
+static void
+miPointerCursorLimits(pScreen, pCursor, pHotBox, pTopLeftBox)
+    ScreenPtr  pScreen;
+    CursorPtr  pCursor;
+    BoxPtr     pHotBox;
+    BoxPtr     pTopLeftBox;
+{
+    *pTopLeftBox = *pHotBox;
+}
+
+static Bool GenerateEvent;
+
+static Bool
+miPointerSetCursorPosition(pScreen, x, y, generateEvent)
+    ScreenPtr pScreen;
+    int       x, y;
+    Bool      generateEvent;
+{
+    SetupScreen (pScreen);
+
+    GenerateEvent = generateEvent;
+    /* device dependent - must pend signal and call miPointerWarpCursor */
+    (*pScreenPriv->screenFuncs->WarpCursor) (pScreen, x, y);
+    if (!generateEvent)
+       miPointerUpdate();
+    return TRUE;
+}
+
+/* Once signals are ignored, the WarpCursor function can call this */
+
+void
+miPointerWarpCursor (pScreen, x, y)
+    ScreenPtr  pScreen;
+    int                x, y;
+{
+    SetupScreen (pScreen);
+
+    if (miPointer.pScreen != pScreen)
+       (*pScreenPriv->screenFuncs->NewEventScreen) (pScreen, TRUE);
+
+    if (GenerateEvent)
+    {
+       miPointerMove (pScreen, x, y, GetTimeInMillis()); 
+    }
+    else
+    {
+       /* everything from miPointerMove except the event and history */
+
+       if (!pScreenPriv->waitForUpdate && pScreen == miPointer.pSpriteScreen)
+       {
+           miPointer.devx = x;
+           miPointer.devy = y;
+           (*pScreenPriv->spriteFuncs->MoveCursor) (pScreen, x, y);
+       }
+       miPointer.x = x;
+       miPointer.y = y;
+       miPointer.pScreen = pScreen;
+    }
+}
+
+/*
+ * Pointer/CursorDisplay interface routines
+ */
+
+int
+miPointerGetMotionBufferSize ()
+{
+    return MOTION_SIZE;
+}
+
+int
+miPointerGetMotionEvents (pPtr, coords, start, stop, pScreen)
+    DeviceIntPtr    pPtr;
+    xTimecoord     *coords;
+    unsigned long   start, stop;
+    ScreenPtr      pScreen;
+{
+    int                    i;
+    int                    count = 0;
+    miHistoryPtr    h;
+
+    for (i = miPointer.history_start; i != miPointer.history_end;)
+    {
+       h = &miPointer.history[i];
+       if (h->event.time >= stop)
+           break;
+       if (h->event.time >= start)
+       {
+           *coords++ = h->event;
+           count++;
+       }
+       if (++i == MOTION_SIZE) i = 0;
+    }
+    return count;
+}
+
+    
+/*
+ * miPointerUpdate
+ *
+ * Syncronize the sprite with the cursor - called from ProcessInputEvents
+ */
+
+void
+miPointerUpdate ()
+{
+    ScreenPtr          pScreen;
+    miPointerScreenPtr pScreenPriv;
+    int                        x, y, devx, devy;
+
+    pScreen = miPointer.pScreen;
+    x = miPointer.x;
+    y = miPointer.y;
+    devx = miPointer.devx;
+    devy = miPointer.devy;
+    if (!pScreen)
+       return;
+    pScreenPriv = GetScreenPrivate (pScreen);
+    /*
+     * if the cursor has switched screens, disable the sprite
+     * on the old screen
+     */
+    if (pScreen != miPointer.pSpriteScreen)
+    {
+       if (miPointer.pSpriteScreen)
+       {
+           miPointerScreenPtr  pOldPriv;
+       
+           pOldPriv = GetScreenPrivate (miPointer.pSpriteScreen);
+           if (miPointer.pCursor)
+           {
+               (*pOldPriv->spriteFuncs->SetCursor)
+                               (miPointer.pSpriteScreen, NullCursor, 0, 0);
+           }
+           (*pOldPriv->screenFuncs->CrossScreen) (miPointer.pSpriteScreen, FALSE);
+       }
+       (*pScreenPriv->screenFuncs->CrossScreen) (pScreen, TRUE);
+       (*pScreenPriv->spriteFuncs->SetCursor)
+                               (pScreen, miPointer.pCursor, x, y);
+       miPointer.devx = x;
+       miPointer.devy = y;
+       miPointer.pSpriteCursor = miPointer.pCursor;
+       miPointer.pSpriteScreen = pScreen;
+    }
+    /*
+     * if the cursor has changed, display the new one
+     */
+    else if (miPointer.pCursor != miPointer.pSpriteCursor)
+    {
+       (*pScreenPriv->spriteFuncs->SetCursor) 
+           (pScreen, miPointer.pCursor, x, y);
+       miPointer.devx = x;
+       miPointer.devy = y;
+       miPointer.pSpriteCursor = miPointer.pCursor;
+    }
+    else if (x != devx || y != devy)
+    {
+       miPointer.devx = x;
+       miPointer.devy = y;
+       (*pScreenPriv->spriteFuncs->MoveCursor) (pScreen, x, y);
+    }
+}
+
+/*
+ * miPointerDeltaCursor.  The pointer has moved dx,dy from it's previous
+ * position.
+ */
+
+void
+miPointerDeltaCursor (dx, dy, time)
+    int                    dx, dy;
+    unsigned long   time;
+{
+    miPointerAbsoluteCursor (miPointer.x + dx, miPointer.y + dy, time);
+}
+
+/*
+ * miPointerAbsoluteCursor.  The pointer has moved to x,y
+ */
+
+void
+miPointerAbsoluteCursor (x, y, time)
+    int                    x, y;
+    unsigned long   time;
+{
+    miPointerScreenPtr pScreenPriv;
+    ScreenPtr          pScreen;
+    ScreenPtr          newScreen;
+
+    pScreen = miPointer.pScreen;
+    if (!pScreen)
+       return;     /* called before ready */
+    if (x < 0 || x >= pScreen->width || y < 0 || y >= pScreen->height)
+    {
+       pScreenPriv = GetScreenPrivate (pScreen);
+       if (!miPointer.confined)
+       {
+           newScreen = pScreen;
+           (*pScreenPriv->screenFuncs->CursorOffScreen) (&newScreen, &x, &y);
+           if (newScreen != pScreen)
+           {
+               pScreen = newScreen;
+               (*pScreenPriv->screenFuncs->NewEventScreen) (pScreen, FALSE);
+               pScreenPriv = GetScreenPrivate (pScreen);
+               /* Smash the confine to the new screen */
+               miPointer.limits.x2 = pScreen->width;
+               miPointer.limits.y2 = pScreen->height;
+           }
+       }
+    }
+    /*
+     * constrain the hot-spot to the current
+     * limits
+     */
+    if (x < miPointer.limits.x1)
+       x = miPointer.limits.x1;
+    if (x >= miPointer.limits.x2)
+       x = miPointer.limits.x2 - 1;
+    if (y < miPointer.limits.y1)
+       y = miPointer.limits.y1;
+    if (y >= miPointer.limits.y2)
+       y = miPointer.limits.y2 - 1;
+    if (miPointer.x == x && miPointer.y == y && miPointer.pScreen == pScreen)
+       return;
+    miPointerMove (pScreen, x, y, time);
+}
+
+void
+miPointerPosition (x, y)
+    int            *x, *y;
+{
+    *x = miPointer.x;
+    *y = miPointer.y;
+}
+
+/*
+ * miPointerMove.  The pointer has moved to x,y on current screen
+ */
+
+static void
+miPointerMove (pScreen, x, y, time)
+    ScreenPtr      pScreen;
+    int                    x, y;
+    unsigned long   time;
+{
+    SetupScreen(pScreen);
+    xEvent             xE;
+    miHistoryPtr       history;
+    int                        prev, end, start;
+
+    if (!pScreenPriv->waitForUpdate && pScreen == miPointer.pSpriteScreen)
+    {
+       miPointer.devx = x;
+       miPointer.devy = y;
+       (*pScreenPriv->spriteFuncs->MoveCursor) (pScreen, x, y);
+    }
+    miPointer.x = x;
+    miPointer.y = y;
+    miPointer.pScreen = pScreen;
+
+    xE.u.u.type = MotionNotify;
+    xE.u.keyButtonPointer.rootX = x;
+    xE.u.keyButtonPointer.rootY = y;
+    xE.u.keyButtonPointer.time = time;
+    (*pScreenPriv->screenFuncs->EnqueueEvent) (&xE);
+
+    end = miPointer.history_end;
+    start = miPointer.history_start;
+    prev = end - 1;
+    if (end == 0)
+       prev = MOTION_SIZE - 1;
+    history = &miPointer.history[prev];
+    if (end == start || history->event.time != time)
+    {
+       history = &miPointer.history[end];
+       if (++end == MOTION_SIZE) 
+           end = 0;
+       if (end == start)
+       {
+           start = end + 1;
+           if (start == MOTION_SIZE)
+               start = 0;
+           miPointer.history_start = start;
+       }
+       miPointer.history_end = end;
+    }
+    history->event.x = x;
+    history->event.y = y;
+    history->event.time = time;
+    history->pScreen = pScreen;
+}
+
+void
+_miRegisterPointerDevice (pScreen, pDevice)
+    ScreenPtr  pScreen;
+    DeviceIntPtr pDevice;
+{
+    miPointer.pPointer = (DevicePtr)pDevice;
+}
+
+/* obsolete: for binary compatibility */
+#ifdef miRegisterPointerDevice
+#undef miRegisterPointerDevice
+void
+miRegisterPointerDevice (pScreen, pDevice)
+    ScreenPtr  pScreen;
+    DevicePtr pDevice;
+{
+    miPointer.pPointer = pDevice;
+}
+#endif /* miRegisterPointerDevice */
diff --git a/Xserver/programs/Xserver/mi/mipointer.h b/Xserver/programs/Xserver/mi/mipointer.h
new file mode 100644 (file)
index 0000000..121ed1c
--- /dev/null
@@ -0,0 +1,189 @@
+/*
+ * mipointer.h
+ *
+ */
+
+/* $XConsortium: mipointer.h,v 5.7 94/04/17 20:27:40 dpw Exp $ */
+/* $XFree86: xc/programs/Xserver/mi/mipointer.h,v 3.2 1996/03/10 12:12:45 dawes Exp $ */
+
+/*
+
+Copyright (c) 1989  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+*/
+
+#ifndef MIPOINTER_H
+#define MIPOINTER_H
+
+typedef struct _miPointerSpriteFuncRec {
+    Bool       (*RealizeCursor)(
+#if NeedFunctionPrototypes
+                    ScreenPtr /* pScr */,
+                    CursorPtr /* pCurs */
+#endif
+                    );
+    Bool       (*UnrealizeCursor)(
+#if NeedFunctionPrototypes
+                    ScreenPtr /* pScr */,
+                    CursorPtr /* pCurs */
+#endif
+                    );
+    void       (*SetCursor)(
+#if NeedFunctionPrototypes
+                    ScreenPtr /* pScr */,
+                    CursorPtr /* pCurs */,
+                    int  /* x */,
+                    int  /* y */
+#endif
+                    );
+    void       (*MoveCursor)(
+#if NeedFunctionPrototypes
+                    ScreenPtr /* pScr */,
+                    int  /* x */,
+                    int  /* y */
+#endif
+                    );
+} miPointerSpriteFuncRec, *miPointerSpriteFuncPtr;
+
+typedef struct _miPointerScreenFuncRec {
+    Bool       (*CursorOffScreen)(
+#if NeedFunctionPrototypes
+                    ScreenPtr* /* ppScr */,
+                    int*  /* px */,
+                    int*  /* py */
+#endif
+                    );
+    void       (*CrossScreen)(
+#if NeedFunctionPrototypes
+                    ScreenPtr /* pScr */,
+                    int  /* entering */
+#endif
+                    );
+    void       (*WarpCursor)(
+#if NeedFunctionPrototypes
+                    ScreenPtr /* pScr */,
+                    int  /* x */,
+                    int  /* y */
+#endif
+                    );
+    void       (*EnqueueEvent)(
+#if NeedFunctionPrototypes
+                    xEventPtr /* event */
+#endif
+                    );
+    void       (*NewEventScreen)(
+#if NeedFunctionPrototypes
+                    ScreenPtr /* pScr */,
+                   Bool /* fromDIX */
+#endif
+                    );
+} miPointerScreenFuncRec, *miPointerScreenFuncPtr;
+
+extern Bool miDCInitialize(
+#if NeedFunctionPrototypes
+    ScreenPtr /*pScreen*/,
+    miPointerScreenFuncPtr /*screenFuncs*/
+#endif
+);
+
+extern Bool miPointerInitialize(
+#if NeedFunctionPrototypes
+    ScreenPtr /*pScreen*/,
+    miPointerSpriteFuncPtr /*spriteFuncs*/,
+    miPointerScreenFuncPtr /*screenFuncs*/,
+    Bool /*waitForUpdate*/
+#endif
+);
+
+extern void miPointerWarpCursor(
+#if NeedFunctionPrototypes
+    ScreenPtr /*pScreen*/,
+    int /*x*/,
+    int /*y*/
+#endif
+);
+
+extern int miPointerGetMotionBufferSize(
+#if NeedFunctionPrototypes
+    void
+#endif
+);
+
+extern int miPointerGetMotionEvents(
+#if NeedFunctionPrototypes
+    DeviceIntPtr /*pPtr*/,
+    xTimecoord * /*coords*/,
+    unsigned long /*start*/,
+    unsigned long /*stop*/,
+    ScreenPtr /*pScreen*/
+#endif
+);
+
+extern void miPointerUpdate(
+#if NeedFunctionPrototypes
+    void
+#endif
+);
+
+extern void miPointerDeltaCursor(
+#if NeedFunctionPrototypes
+    int /*dx*/,
+    int /*dy*/,
+    unsigned long /*time*/
+#endif
+);
+
+extern void miPointerAbsoluteCursor(
+#if NeedFunctionPrototypes
+    int /*x*/,
+    int /*y*/,
+    unsigned long /*time*/
+#endif
+);
+
+extern void miPointerPosition(
+#if NeedFunctionPrototypes
+    int * /*x*/,
+    int * /*y*/
+#endif
+);
+
+#undef miRegisterPointerDevice
+extern void miRegisterPointerDevice(
+#if NeedFunctionPrototypes
+    ScreenPtr /*pScreen*/,
+    DevicePtr /*pDevice*/
+#endif
+);
+
+#define miRegisterPointerDevice(pScreen,pDevice) \
+       _miRegisterPointerDevice(pScreen,pDevice)
+
+extern void _miRegisterPointerDevice(
+#if NeedFunctionPrototypes
+    ScreenPtr /*pScreen*/,
+    DeviceIntPtr /*pDevice*/
+#endif
+);
+
+#endif /* MIPOINTER_H */
diff --git a/Xserver/programs/Xserver/mi/mipointrst.h b/Xserver/programs/Xserver/mi/mipointrst.h
new file mode 100644 (file)
index 0000000..0b45e1f
--- /dev/null
@@ -0,0 +1,63 @@
+/*
+ * mipointrst.h
+ *
+ */
+
+/* $XConsortium: mipointrst.h,v 5.7 94/04/17 20:27:41 dpw Exp $ */
+
+/*
+
+Copyright (c) 1989  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+*/
+
+# include   <mipointer.h>
+# include   <input.h>
+
+#define MOTION_SIZE    256
+
+typedef struct {
+    xTimecoord     event;
+    ScreenPtr      pScreen;
+} miHistoryRec, *miHistoryPtr;
+
+typedef struct {
+    ScreenPtr              pScreen;    /* current screen */
+    ScreenPtr              pSpriteScreen;/* screen containing current sprite */
+    CursorPtr              pCursor;    /* current cursor */
+    CursorPtr              pSpriteCursor;/* cursor on screen */
+    BoxRec                 limits;     /* current constraints */
+    Bool                   confined;   /* pointer can't change screens */
+    int                            x, y;       /* hot spot location */
+    int                            devx, devy; /* sprite position */
+    DevicePtr              pPointer;   /* pointer device structure */
+    miHistoryRec           history[MOTION_SIZE];
+    int                            history_start, history_end;
+} miPointerRec, *miPointerPtr;
+
+typedef struct {
+    miPointerSpriteFuncPtr  spriteFuncs;       /* sprite-specific methods */
+    miPointerScreenFuncPtr  screenFuncs;       /* screen-specific methods */
+    CloseScreenProcPtr     CloseScreen;
+    Bool                   waitForUpdate;      /* don't move cursor in SIGIO */
+} miPointerScreenRec, *miPointerScreenPtr;
diff --git a/Xserver/programs/Xserver/mi/mipoly.c b/Xserver/programs/Xserver/mi/mipoly.c
new file mode 100644 (file)
index 0000000..f7ae592
--- /dev/null
@@ -0,0 +1,125 @@
+/***********************************************************
+
+Copyright (c) 1987  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+
+Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
+
+                        All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and its 
+documentation for any purpose and without fee is hereby granted, 
+provided that the above copyright notice appear in all copies and that
+both that copyright notice and this permission notice appear in 
+supporting documentation, and that the name of Digital not be
+used in advertising or publicity pertaining to distribution of the
+software without specific, written prior permission.  
+
+DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
+ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
+DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
+ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+SOFTWARE.
+
+******************************************************************/
+/* $XConsortium: mipoly.c,v 5.1 94/04/17 20:27:41 keith Exp $ */
+/*
+ *  mipoly.c
+ *
+ *  Written by Brian Kelleher; June 1986
+ *
+ *  Draw polygons.  This routine translates the point by the
+ *  origin if pGC->miTranslate is non-zero, and calls
+ *  to the appropriate routine to actually scan convert the
+ *  polygon.
+ */
+#include "X.h"
+#include "windowstr.h"
+#include "gcstruct.h"
+#include "pixmapstr.h"
+#include "mi.h"
+#include "miscstruct.h"
+
+
+void
+miFillPolygon(dst, pgc, shape, mode, count, pPts)
+    DrawablePtr                dst;
+    register GCPtr     pgc;
+    int                        shape, mode;
+    register int       count;
+    DDXPointPtr                pPts;
+{
+    int                        i;
+    register int       xorg, yorg;
+    register DDXPointPtr ppt;
+
+    if (count == 0)
+       return;
+
+    ppt = pPts;
+    if (pgc->miTranslate)
+    {
+       xorg = dst->x;
+       yorg = dst->y;
+
+        if (mode == CoordModeOrigin) 
+        {
+               for (i = 0; i<count; i++) 
+                {    
+                   ppt->x += xorg;
+                   ppt++->y += yorg;
+               }
+        }
+        else 
+        {
+           ppt->x += xorg;
+           ppt++->y += yorg;
+           for (i = 1; i<count; i++) 
+            {
+               ppt->x += (ppt-1)->x;
+               ppt->y += (ppt-1)->y;
+               ppt++;
+           }
+        }
+    }
+    else
+    {
+       if (mode == CoordModePrevious)
+        {
+           ppt++;
+           for (i = 1; i<count; i++) 
+            {
+               ppt->x += (ppt-1)->x;
+               ppt->y += (ppt-1)->y;
+               ppt++;
+           }
+        }
+    }
+    if (shape == Convex)
+       miFillConvexPoly(dst, pgc, count, pPts);
+    else
+       miFillGeneralPoly(dst, pgc, count, pPts);
+}
diff --git a/Xserver/programs/Xserver/mi/mipoly.h b/Xserver/programs/Xserver/mi/mipoly.h
new file mode 100644 (file)
index 0000000..7c8452c
--- /dev/null
@@ -0,0 +1,230 @@
+/* $XConsortium: mipoly.h,v 1.5 94/04/17 20:27:42 dpw Exp $ */
+/*
+
+Copyright (c) 1987  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be included
+in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR
+OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall
+not be used in advertising or otherwise to promote the sale, use or
+other dealings in this Software without prior written authorization
+from the X Consortium.
+
+*/
+
+
+/*
+ *     fill.h
+ *
+ *     Created by Brian Kelleher; Oct 1985
+ *
+ *     Include file for filled polygon routines.
+ *
+ *     These are the data structures needed to scan
+ *     convert regions.  Two different scan conversion
+ *     methods are available -- the even-odd method, and
+ *     the winding number method.
+ *     The even-odd rule states that a point is inside
+ *     the polygon if a ray drawn from that point in any
+ *     direction will pass through an odd number of
+ *     path segments.
+ *     By the winding number rule, a point is decided
+ *     to be inside the polygon if a ray drawn from that
+ *     point in any direction passes through a different
+ *     number of clockwise and counter-clockwise path
+ *     segments.
+ *
+ *     These data structures are adapted somewhat from
+ *     the algorithm in (Foley/Van Dam) for scan converting
+ *     polygons.
+ *     The basic algorithm is to start at the top (smallest y)
+ *     of the polygon, stepping down to the bottom of
+ *     the polygon by incrementing the y coordinate.  We
+ *     keep a list of edges which the current scanline crosses,
+ *     sorted by x.  This list is called the Active Edge Table (AET)
+ *     As we change the y-coordinate, we update each entry in 
+ *     in the active edge table to reflect the edges new xcoord.
+ *     This list must be sorted at each scanline in case
+ *     two edges intersect.
+ *     We also keep a data structure known as the Edge Table (ET),
+ *     which keeps track of all the edges which the current
+ *     scanline has not yet reached.  The ET is basically a
+ *     list of ScanLineList structures containing a list of
+ *     edges which are entered at a given scanline.  There is one
+ *     ScanLineList per scanline at which an edge is entered.
+ *     When we enter a new edge, we move it from the ET to the AET.
+ *
+ *     From the AET, we can implement the even-odd rule as in
+ *     (Foley/Van Dam).
+ *     The winding number rule is a little trickier.  We also
+ *     keep the EdgeTableEntries in the AET linked by the
+ *     nextWETE (winding EdgeTableEntry) link.  This allows
+ *     the edges to be linked just as before for updating
+ *     purposes, but only uses the edges linked by the nextWETE
+ *     link as edges representing spans of the polygon to
+ *     drawn (as with the even-odd rule).
+ */
+
+/*
+ * for the winding number rule
+ */
+#define CLOCKWISE          1
+#define COUNTERCLOCKWISE  -1 
+
+typedef struct _EdgeTableEntry {
+     int ymax;             /* ycoord at which we exit this edge. */
+     BRESINFO bres;        /* Bresenham info to run the edge     */
+     struct _EdgeTableEntry *next;       /* next in the list     */
+     struct _EdgeTableEntry *back;       /* for insertion sort   */
+     struct _EdgeTableEntry *nextWETE;   /* for winding num rule */
+     int ClockWise;        /* flag for winding number rule       */
+} EdgeTableEntry;
+
+
+typedef struct _ScanLineList{
+     int scanline;              /* the scanline represented */
+     EdgeTableEntry *edgelist;  /* header node              */
+     struct _ScanLineList *next;  /* next in the list       */
+} ScanLineList;
+
+
+typedef struct {
+     int ymax;                 /* ymax for the polygon     */
+     int ymin;                 /* ymin for the polygon     */
+     ScanLineList scanlines;   /* header node              */
+} EdgeTable;
+
+
+/*
+ * Here is a struct to help with storage allocation
+ * so we can allocate a big chunk at a time, and then take
+ * pieces from this heap when we need to.
+ */
+#define SLLSPERBLOCK 25
+
+typedef struct _ScanLineListBlock {
+     ScanLineList SLLs[SLLSPERBLOCK];
+     struct _ScanLineListBlock *next;
+} ScanLineListBlock;
+
+/*
+ * number of points to buffer before sending them off
+ * to scanlines() :  Must be an even number
+ */
+#define NUMPTSTOBUFFER 200
+
+\f
+/*
+ *
+ *     a few macros for the inner loops of the fill code where
+ *     performance considerations don't allow a procedure call.
+ *
+ *     Evaluate the given edge at the given scanline.
+ *     If the edge has expired, then we leave it and fix up
+ *     the active edge table; otherwise, we increment the
+ *     x value to be ready for the next scanline.
+ *     The winding number rule is in effect, so we must notify
+ *     the caller when the edge has been removed so he
+ *     can reorder the Winding Active Edge Table.
+ */
+#define EVALUATEEDGEWINDING(pAET, pPrevAET, y, fixWAET) { \
+   if (pAET->ymax == y) {          /* leaving this edge */ \
+      pPrevAET->next = pAET->next; \
+      pAET = pPrevAET->next; \
+      fixWAET = 1; \
+      if (pAET) \
+         pAET->back = pPrevAET; \
+   } \
+   else { \
+      BRESINCRPGONSTRUCT(pAET->bres); \
+      pPrevAET = pAET; \
+      pAET = pAET->next; \
+   } \
+}
+
+
+/*
+ *     Evaluate the given edge at the given scanline.
+ *     If the edge has expired, then we leave it and fix up
+ *     the active edge table; otherwise, we increment the
+ *     x value to be ready for the next scanline.
+ *     The even-odd rule is in effect.
+ */
+#define EVALUATEEDGEEVENODD(pAET, pPrevAET, y) { \
+   if (pAET->ymax == y) {          /* leaving this edge */ \
+      pPrevAET->next = pAET->next; \
+      pAET = pPrevAET->next; \
+      if (pAET) \
+         pAET->back = pPrevAET; \
+   } \
+   else { \
+      BRESINCRPGONSTRUCT(pAET->bres); \
+      pPrevAET = pAET; \
+      pAET = pAET->next; \
+   } \
+}
+
+/* mipolyutil.c */
+
+extern Bool miInsertEdgeInET(
+#if NeedFunctionPrototypes
+    EdgeTable * /*ET*/,
+    EdgeTableEntry * /*ETE*/,
+    int /*scanline*/,
+    ScanLineListBlock ** /*SLLBlock*/,
+    int * /*iSLLBlock*/
+#endif
+);
+
+extern Bool miCreateETandAET(
+#if NeedFunctionPrototypes
+    int /*count*/,
+    DDXPointPtr /*pts*/,
+    EdgeTable * /*ET*/,
+    EdgeTableEntry * /*AET*/,
+    EdgeTableEntry * /*pETEs*/,
+    ScanLineListBlock * /*pSLLBlock*/
+#endif
+);
+
+extern void miloadAET(
+#if NeedFunctionPrototypes
+    EdgeTableEntry * /*AET*/,
+    EdgeTableEntry * /*ETEs*/
+#endif
+);
+
+extern void micomputeWAET(
+#if NeedFunctionPrototypes
+    EdgeTableEntry * /*AET*/
+#endif
+);
+
+extern int miInsertionSort(
+#if NeedFunctionPrototypes
+    EdgeTableEntry * /*AET*/
+#endif
+);
+
+extern void miFreeStorage(
+#if NeedFunctionPrototypes
+    ScanLineListBlock * /*pSLLBlock*/
+#endif
+);
diff --git a/Xserver/programs/Xserver/mi/mipolycon.c b/Xserver/programs/Xserver/mi/mipolycon.c
new file mode 100644 (file)
index 0000000..8001f15
--- /dev/null
@@ -0,0 +1,246 @@
+/***********************************************************
+
+Copyright (c) 1987  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+
+Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
+
+                        All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and its 
+documentation for any purpose and without fee is hereby granted, 
+provided that the above copyright notice appear in all copies and that
+both that copyright notice and this permission notice appear in 
+supporting documentation, and that the name of Digital not be
+used in advertising or publicity pertaining to distribution of the
+software without specific, written prior permission.  
+
+DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
+ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
+DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
+ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+SOFTWARE.
+
+******************************************************************/
+/* $XConsortium: mipolycon.c,v 5.1 94/04/17 20:27:43 keith Exp $ */
+#include "gcstruct.h"
+#include "pixmap.h"
+#include "miscanfill.h"
+
+static int getPolyYBounds();
+
+/*
+ *     convexpoly.c
+ *
+ *     Written by Brian Kelleher; Dec. 1985.
+ *
+ *     Fill a convex polygon.  If the given polygon
+ *     is not convex, then the result is undefined.
+ *     The algorithm is to order the edges from smallest
+ *     y to largest by partitioning the array into a left
+ *     edge list and a right edge list.  The algorithm used
+ *     to traverse each edge is an extension of Bresenham's
+ *     line algorithm with y as the major axis.
+ *     For a derivation of the algorithm, see the author of
+ *     this code.
+ */
+Bool
+miFillConvexPoly(dst, pgc, count, ptsIn)
+    DrawablePtr dst;
+    GCPtr      pgc;
+    int                count;                /* number of points        */
+    DDXPointPtr ptsIn;                /* the points              */
+{
+    register int xl, xr;        /* x vals of left and right edges */
+    register int dl, dr;        /* decision variables             */
+    register int ml, m1l;       /* left edge slope and slope+1    */
+    int mr, m1r;                /* right edge slope and slope+1   */
+    int incr1l, incr2l;         /* left edge error increments     */
+    int incr1r, incr2r;         /* right edge error increments    */
+    int dy;                     /* delta y                        */
+    int y;                      /* current scanline               */
+    int left, right;            /* indices to first endpoints     */
+    int i;                      /* loop counter                   */
+    int nextleft, nextright;    /* indices to second endpoints    */
+    DDXPointPtr ptsOut, FirstPoint; /* output buffer               */
+    int *width, *FirstWidth;    /* output buffer                  */
+    int imin;                   /* index of smallest vertex (in y) */
+    int ymin;                   /* y-extents of polygon            */
+    int ymax;
+
+    /*
+     *  find leftx, bottomy, rightx, topy, and the index
+     *  of bottomy. Also translate the points.
+     */
+    imin = getPolyYBounds(ptsIn, count, &ymin, &ymax);
+
+    dy = ymax - ymin + 1;
+    if ((count < 3) || (dy < 0))
+       return(TRUE);
+    ptsOut = FirstPoint = (DDXPointPtr )ALLOCATE_LOCAL(sizeof(DDXPointRec)*dy);
+    width = FirstWidth = (int *)ALLOCATE_LOCAL(sizeof(int) * dy);
+    if(!FirstPoint || !FirstWidth)
+    {
+       if (FirstWidth) DEALLOCATE_LOCAL(FirstWidth);
+       if (FirstPoint) DEALLOCATE_LOCAL(FirstPoint);
+       return(FALSE);
+    }
+
+    nextleft = nextright = imin;
+    y = ptsIn[nextleft].y;
+
+    /*
+     *  loop through all edges of the polygon
+     */
+    do {
+        /*
+         *  add a left edge if we need to
+         */
+        if (ptsIn[nextleft].y == y) {
+            left = nextleft;
+
+            /*
+             *  find the next edge, considering the end
+             *  conditions of the array.
+             */
+            nextleft++;
+            if (nextleft >= count)
+                nextleft = 0;
+
+            /*
+             *  now compute all of the random information
+             *  needed to run the iterative algorithm.
+             */
+            BRESINITPGON(ptsIn[nextleft].y-ptsIn[left].y,
+                         ptsIn[left].x,ptsIn[nextleft].x,
+                         xl, dl, ml, m1l, incr1l, incr2l);
+        }
+
+        /*
+         *  add a right edge if we need to
+         */
+        if (ptsIn[nextright].y == y) {
+            right = nextright;
+
+            /*
+             *  find the next edge, considering the end
+             *  conditions of the array.
+             */
+            nextright--;
+            if (nextright < 0)
+                nextright = count-1;
+
+            /*
+             *  now compute all of the random information
+             *  needed to run the iterative algorithm.
+             */
+            BRESINITPGON(ptsIn[nextright].y-ptsIn[right].y,
+                         ptsIn[right].x,ptsIn[nextright].x,
+                         xr, dr, mr, m1r, incr1r, incr2r);
+        }
+
+        /*
+         *  generate scans to fill while we still have
+         *  a right edge as well as a left edge.
+         */
+        i = min(ptsIn[nextleft].y, ptsIn[nextright].y) - y;
+       /* in case we're called with non-convex polygon */
+       if(i < 0)
+        {
+           DEALLOCATE_LOCAL(FirstWidth);
+           DEALLOCATE_LOCAL(FirstPoint);
+           return(TRUE);
+       }
+        while (i-- > 0) 
+        {
+            ptsOut->y = y;
+
+            /*
+             *  reverse the edges if necessary
+             */
+            if (xl < xr) 
+            {
+                *(width++) = xr - xl;
+                (ptsOut++)->x = xl;
+            }
+            else 
+            {
+                *(width++) = xl - xr;
+                (ptsOut++)->x = xr;
+            }
+            y++;
+
+            /* increment down the edges */
+            BRESINCRPGON(dl, xl, ml, m1l, incr1l, incr2l);
+            BRESINCRPGON(dr, xr, mr, m1r, incr1r, incr2r);
+        }
+    }  while (y != ymax);
+
+    /*
+     * Finally, fill the <remaining> spans
+     */
+    (*pgc->ops->FillSpans)(dst, pgc, 
+                     ptsOut-FirstPoint,FirstPoint,FirstWidth,
+                     1);
+    DEALLOCATE_LOCAL(FirstWidth);
+    DEALLOCATE_LOCAL(FirstPoint);
+    return(TRUE);
+}
+
+\f
+/*
+ *     Find the index of the point with the smallest y.
+ */
+static
+int
+getPolyYBounds(pts, n, by, ty)
+    DDXPointPtr pts;
+    int n;
+    int *by, *ty;
+{
+    register DDXPointPtr ptMin;
+    int ymin, ymax;
+    DDXPointPtr ptsStart = pts;
+
+    ptMin = pts;
+    ymin = ymax = (pts++)->y;
+
+    while (--n > 0) {
+        if (pts->y < ymin)
+       {
+            ptMin = pts;
+            ymin = pts->y;
+        }
+       if(pts->y > ymax)
+            ymax = pts->y;
+
+        pts++;
+    }
+
+    *by = ymin;
+    *ty = ymax;
+    return(ptMin-ptsStart);
+}
diff --git a/Xserver/programs/Xserver/mi/mipolygen.c b/Xserver/programs/Xserver/mi/mipolygen.c
new file mode 100644 (file)
index 0000000..8a4d359
--- /dev/null
@@ -0,0 +1,227 @@
+/***********************************************************
+
+Copyright (c) 1987  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+
+Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
+
+                        All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and its 
+documentation for any purpose and without fee is hereby granted, 
+provided that the above copyright notice appear in all copies and that
+both that copyright notice and this permission notice appear in 
+supporting documentation, and that the name of Digital not be
+used in advertising or publicity pertaining to distribution of the
+software without specific, written prior permission.  
+
+DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
+ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
+DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
+ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+SOFTWARE.
+
+******************************************************************/
+/* $XConsortium: mipolygen.c,v 5.2 94/04/17 20:27:43 dpw Exp $ */
+#include "X.h"
+#include "gcstruct.h"
+#include "miscanfill.h"
+#include "mipoly.h"
+#include "pixmap.h"
+
+/*
+ *
+ *     Written by Brian Kelleher;  Oct. 1985
+ *
+ *     Routine to fill a polygon.  Two fill rules are
+ *     supported: frWINDING and frEVENODD.
+ *
+ *     See fillpoly.h for a complete description of the algorithm.
+ */
+
+Bool
+miFillGeneralPoly(dst, pgc, count, ptsIn)
+    DrawablePtr dst;
+    GCPtr      pgc;
+    int                count;              /* number of points        */
+    DDXPointPtr ptsIn;              /* the points              */
+{
+    register EdgeTableEntry *pAET;  /* the Active Edge Table   */
+    register int y;                 /* the current scanline    */
+    register int nPts = 0;          /* number of pts in buffer */
+    register EdgeTableEntry *pWETE; /* Winding Edge Table      */
+    register ScanLineList *pSLL;    /* Current ScanLineList    */
+    register DDXPointPtr ptsOut;      /* ptr to output buffers   */
+    int *width;
+    DDXPointRec FirstPoint[NUMPTSTOBUFFER]; /* the output buffers */
+    int FirstWidth[NUMPTSTOBUFFER];
+    EdgeTableEntry *pPrevAET;       /* previous AET entry      */
+    EdgeTable ET;                   /* Edge Table header node  */
+    EdgeTableEntry AET;             /* Active ET header node   */
+    EdgeTableEntry *pETEs;          /* Edge Table Entries buff */
+    ScanLineListBlock SLLBlock;     /* header for ScanLineList */
+    int fixWAET = 0;
+
+    if (count < 3)
+       return(TRUE);
+
+    if(!(pETEs = (EdgeTableEntry *)
+        ALLOCATE_LOCAL(sizeof(EdgeTableEntry) * count)))
+       return(FALSE);
+    ptsOut = FirstPoint;
+    width = FirstWidth;
+    if (!miCreateETandAET(count, ptsIn, &ET, &AET, pETEs, &SLLBlock))
+    {
+       DEALLOCATE_LOCAL(pETEs);
+       return(FALSE);
+    }
+    pSLL = ET.scanlines.next;
+
+    if (pgc->fillRule == EvenOddRule) 
+    {
+        /*
+         *  for each scanline
+         */
+        for (y = ET.ymin; y < ET.ymax; y++) 
+        {
+            /*
+             *  Add a new edge to the active edge table when we
+             *  get to the next edge.
+             */
+            if (pSLL && y == pSLL->scanline) 
+            {
+                miloadAET(&AET, pSLL->edgelist);
+                pSLL = pSLL->next;
+            }
+            pPrevAET = &AET;
+            pAET = AET.next;
+
+            /*
+             *  for each active edge
+             */
+            while (pAET) 
+            {
+                ptsOut->x = pAET->bres.minor;
+               ptsOut++->y = y;
+                *width++ = pAET->next->bres.minor - pAET->bres.minor;
+                nPts++;
+
+                /*
+                 *  send out the buffer when its full
+                 */
+                if (nPts == NUMPTSTOBUFFER) 
+               {
+                   (*pgc->ops->FillSpans)(dst, pgc,
+                                     nPts, FirstPoint, FirstWidth,
+                                     1);
+                    ptsOut = FirstPoint;
+                    width = FirstWidth;
+                    nPts = 0;
+                }
+                EVALUATEEDGEEVENODD(pAET, pPrevAET, y)
+                EVALUATEEDGEEVENODD(pAET, pPrevAET, y);
+            }
+            miInsertionSort(&AET);
+        }
+    }
+    else      /* default to WindingNumber */
+    {
+        /*
+         *  for each scanline
+         */
+        for (y = ET.ymin; y < ET.ymax; y++) 
+        {
+            /*
+             *  Add a new edge to the active edge table when we
+             *  get to the next edge.
+             */
+            if (pSLL && y == pSLL->scanline) 
+            {
+                miloadAET(&AET, pSLL->edgelist);
+                micomputeWAET(&AET);
+                pSLL = pSLL->next;
+            }
+            pPrevAET = &AET;
+            pAET = AET.next;
+            pWETE = pAET;
+
+            /*
+             *  for each active edge
+             */
+            while (pAET) 
+            {
+                /*
+                 *  if the next edge in the active edge table is
+                 *  also the next edge in the winding active edge
+                 *  table.
+                 */
+                if (pWETE == pAET) 
+                {
+                    ptsOut->x = pAET->bres.minor;
+                   ptsOut++->y = y;
+                    *width++ = pAET->nextWETE->bres.minor - pAET->bres.minor;
+                    nPts++;
+
+                    /*
+                     *  send out the buffer
+                     */
+                    if (nPts == NUMPTSTOBUFFER) 
+                    {
+                       (*pgc->ops->FillSpans)(dst, pgc, nPts, FirstPoint,
+                                         FirstWidth, 1);
+                        ptsOut = FirstPoint;
+                        width  = FirstWidth;
+                        nPts = 0;
+                    }
+
+                    pWETE = pWETE->nextWETE;
+                    while (pWETE != pAET)
+                        EVALUATEEDGEWINDING(pAET, pPrevAET, y, fixWAET);
+                    pWETE = pWETE->nextWETE;
+                }
+                EVALUATEEDGEWINDING(pAET, pPrevAET, y, fixWAET);
+            }
+
+            /*
+             *  reevaluate the Winding active edge table if we
+             *  just had to resort it or if we just exited an edge.
+             */
+            if (miInsertionSort(&AET) || fixWAET) 
+            {
+                micomputeWAET(&AET);
+                fixWAET = 0;
+            }
+        }
+    }
+
+    /*
+     *     Get any spans that we missed by buffering
+     */
+    (*pgc->ops->FillSpans)(dst, pgc, nPts, FirstPoint, FirstWidth, 1);
+    DEALLOCATE_LOCAL(pETEs);
+    miFreeStorage(SLLBlock.next);
+    return(TRUE);
+}
diff --git a/Xserver/programs/Xserver/mi/mipolypnt.c b/Xserver/programs/Xserver/mi/mipolypnt.c
new file mode 100644 (file)
index 0000000..7bb10b1
--- /dev/null
@@ -0,0 +1,120 @@
+/***********************************************************
+
+Copyright (c) 1987  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+
+Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
+
+                        All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and its 
+documentation for any purpose and without fee is hereby granted, 
+provided that the above copyright notice appear in all copies and that
+both that copyright notice and this permission notice appear in 
+supporting documentation, and that the name of Digital not be
+used in advertising or publicity pertaining to distribution of the
+software without specific, written prior permission.  
+
+DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
+ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
+DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
+ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+SOFTWARE.
+
+******************************************************************/
+/* $XConsortium: mipolypnt.c,v 5.2 94/04/17 20:27:44 dpw Exp $ */
+#include "X.h"
+#include "Xprotostr.h"
+#include "pixmapstr.h"
+#include "gcstruct.h"
+#include "windowstr.h"
+
+void
+miPolyPoint(pDrawable, pGC, mode, npt, pptInit)
+    DrawablePtr        pDrawable;
+    GCPtr              pGC;
+    int                mode;           /* Origin or Previous */
+    int                npt;
+    xPoint             *pptInit;
+{
+
+    int                xorg;
+    int                yorg;
+    int                nptTmp;
+    XID                        fsOld, fsNew;
+    int                        *pwidthInit, *pwidth;
+    int                        i;
+    register xPoint    *ppt;
+
+    /* make pointlist origin relative */
+    if (mode == CoordModePrevious)
+    {
+        ppt = pptInit;
+        nptTmp = npt;
+       nptTmp--;
+       while(nptTmp--)
+       {
+           ppt++;
+           ppt->x += (ppt-1)->x;
+           ppt->y += (ppt-1)->y;
+       }
+    }
+
+    if(pGC->miTranslate)
+    {
+       ppt = pptInit;
+       nptTmp = npt;
+       xorg = pDrawable->x;
+       yorg = pDrawable->y;
+       while(nptTmp--)
+       {
+           ppt->x += xorg;
+           ppt++->y += yorg;
+       }
+    }
+
+    fsOld = pGC->fillStyle;
+    fsNew = FillSolid;
+    if(pGC->fillStyle != FillSolid)
+    {
+       DoChangeGC(pGC, GCFillStyle, &fsNew, 0);
+       ValidateGC(pDrawable, pGC);
+    }
+    if(!(pwidthInit = (int *)ALLOCATE_LOCAL(npt * sizeof(int))))
+       return;
+    pwidth = pwidthInit;
+    for(i = 0; i < npt; i++)
+       *pwidth++ = 1;
+    (*pGC->ops->FillSpans)(pDrawable, pGC, npt, pptInit, pwidthInit, FALSE); 
+
+    if(fsOld != FillSolid)
+    {
+       DoChangeGC(pGC, GCFillStyle, &fsOld, 0);
+       ValidateGC(pDrawable, pGC);
+    }
+    DEALLOCATE_LOCAL(pwidthInit);
+}
+
diff --git a/Xserver/programs/Xserver/mi/mipolyrect.c b/Xserver/programs/Xserver/mi/mipolyrect.c
new file mode 100644 (file)
index 0000000..acaa95a
--- /dev/null
@@ -0,0 +1,188 @@
+/***********************************************************
+
+Copyright (c) 1987  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+
+Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
+
+                        All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and its 
+documentation for any purpose and without fee is hereby granted, 
+provided that the above copyright notice appear in all copies and that
+both that copyright notice and this permission notice appear in 
+supporting documentation, and that the name of Digital not be
+used in advertising or publicity pertaining to distribution of the
+software without specific, written prior permission.  
+
+DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
+ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
+DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
+ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+SOFTWARE.
+
+******************************************************************/
+/* $XConsortium: mipolyrect.c,v 5.8 94/04/17 20:27:44 keith Exp $ */
+#include "X.h"
+#include "Xprotostr.h"
+#include "miscstruct.h"
+#include "gcstruct.h"
+#include "pixmap.h"
+
+void
+miPolyRectangle(pDraw, pGC, nrects, pRects)
+    DrawablePtr        pDraw;
+    GCPtr      pGC;
+    int                nrects;
+    xRectangle *pRects;
+{
+    int i;
+    xRectangle *pR = pRects;
+    DDXPointRec rect[5];
+    int            bound_tmp;
+
+#define MINBOUND(dst,eqn)      bound_tmp = eqn; \
+                               if (bound_tmp < -32768) \
+                                   bound_tmp = -32768; \
+                               dst = bound_tmp;
+
+#define MAXBOUND(dst,eqn)      bound_tmp = eqn; \
+                               if (bound_tmp > 32767) \
+                                   bound_tmp = 32767; \
+                               dst = bound_tmp;
+
+#define MAXUBOUND(dst,eqn)     bound_tmp = eqn; \
+                               if (bound_tmp > 65535) \
+                                   bound_tmp = 65535; \
+                               dst = bound_tmp;
+
+    if (pGC->lineStyle == LineSolid && pGC->joinStyle == JoinMiter &&
+       pGC->lineWidth != 0)
+    {
+       xRectangle  *tmp, *t;
+       int         ntmp;
+       int         offset1, offset2, offset3;
+       int         x, y, width, height;
+
+       ntmp = (nrects << 2);
+       offset2 = pGC->lineWidth;
+       offset1 = offset2 >> 1;
+       offset3 = offset2 - offset1;
+       tmp = (xRectangle *) ALLOCATE_LOCAL(ntmp * sizeof (xRectangle));
+       if (!tmp)
+           return;
+       t = tmp;
+       for (i = 0; i < nrects; i++)
+       {
+           x = pR->x;
+           y = pR->y;
+           width = pR->width;
+           height = pR->height;
+           pR++;
+           if (width == 0 && height == 0)
+           {
+               rect[0].x = x;
+               rect[0].y = y;
+               rect[1].x = x;
+               rect[1].y = y;
+               (*pGC->ops->Polylines)(pDraw, pGC, CoordModeOrigin, 2, rect);
+           }
+           else if (height < offset2 || width < offset1)
+           {
+               if (height == 0)
+               {
+                   t->x = x;
+                   t->width = width;
+               }
+               else
+               {
+                   MINBOUND (t->x, x - offset1)
+                   MAXUBOUND (t->width, width + offset2)
+               }
+               if (width == 0)
+               {
+                   t->y = y;
+                   t->height = height;
+               }
+               else
+               {
+                   MINBOUND (t->y, y - offset1)
+                   MAXUBOUND (t->height, height + offset2)
+               }
+               t++;
+           }
+           else
+           {
+               MINBOUND(t->x, x - offset1)
+               MINBOUND(t->y, y - offset1)
+               MAXUBOUND(t->width, width + offset2)
+               t->height = offset2;
+               t++;
+               MINBOUND(t->x, x - offset1)
+               MAXBOUND(t->y, y + offset3);
+               t->width = offset2;
+               t->height = height - offset2;
+               t++;
+               MAXBOUND(t->x, x + width - offset1);
+               MAXBOUND(t->y, y + offset3)
+               t->width = offset2;
+               t->height = height - offset2;
+               t++;
+               MINBOUND(t->x, x - offset1)
+               MAXBOUND(t->y, y + height - offset1)
+               MAXUBOUND(t->width, width + offset2)
+               t->height = offset2;
+               t++;
+           }
+       }
+       (*pGC->ops->PolyFillRect) (pDraw, pGC, t - tmp, tmp);
+       DEALLOCATE_LOCAL ((pointer) tmp);
+    }
+    else
+    {
+
+       for (i=0; i<nrects; i++)
+       {
+           rect[0].x = pR->x;
+           rect[0].y = pR->y;
+    
+           MAXBOUND(rect[1].x, pR->x + (int) pR->width)
+           rect[1].y = rect[0].y;
+    
+           rect[2].x = rect[1].x;
+           MAXBOUND(rect[2].y, pR->y + (int) pR->height);
+    
+           rect[3].x = rect[0].x;
+           rect[3].y = rect[2].y;
+    
+           rect[4].x = rect[0].x;
+           rect[4].y = rect[0].y;
+    
+            (*pGC->ops->Polylines)(pDraw, pGC, CoordModeOrigin, 5, rect);
+           pR++;
+       }
+    }
+}
diff --git a/Xserver/programs/Xserver/mi/mipolyseg.c b/Xserver/programs/Xserver/mi/mipolyseg.c
new file mode 100644 (file)
index 0000000..5b53d8c
--- /dev/null
@@ -0,0 +1,80 @@
+/***********************************************************
+
+Copyright (c) 1987  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+
+Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
+
+                        All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and its 
+documentation for any purpose and without fee is hereby granted, 
+provided that the above copyright notice appear in all copies and that
+both that copyright notice and this permission notice appear in 
+supporting documentation, and that the name of Digital not be
+used in advertising or publicity pertaining to distribution of the
+software without specific, written prior permission.  
+
+DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
+ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
+DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
+ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+SOFTWARE.
+
+******************************************************************/
+/* $XConsortium: mipolyseg.c,v 5.1 94/04/17 20:27:45 keith Exp $ */
+#include "X.h"
+#include "Xprotostr.h"
+#include "miscstruct.h"
+#include "gcstruct.h"
+#include "pixmap.h"
+
+/*****************************************************************
+ * miPolySegment
+ *
+ *    For each segment, draws a line between (x1, y1) and (x2, y2).  The
+ *    lines are drawn in the order listed.
+ *
+ *    Walks the segments, compressing them into format for PolyLines.
+ *    
+ *****************************************************************/
+
+
+void
+miPolySegment(pDraw, pGC, nseg, pSegs)
+    DrawablePtr pDraw;
+    GCPtr      pGC;
+    int                nseg;
+    xSegment   *pSegs;
+{
+    int i;
+
+    for (i=0; i<nseg; i++)
+    {
+        (*pGC->ops->Polylines)(pDraw, pGC, CoordModeOrigin, 2,(DDXPointPtr)pSegs);
+       pSegs++;
+    }
+}
diff --git a/Xserver/programs/Xserver/mi/mipolytext.c b/Xserver/programs/Xserver/mi/mipolytext.c
new file mode 100644 (file)
index 0000000..95cd6bd
--- /dev/null
@@ -0,0 +1,197 @@
+/*******************************************************************
+
+Copyright (c) 1987  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+
+Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
+
+                        All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and its 
+documentation for any purpose and without fee is hereby granted, 
+provided that the above copyright notice appear in all copies and that
+both that copyright notice and this permission notice appear in 
+supporting documentation, and that the name of Digital not be
+used in advertising or publicity pertaining to distribution of the
+software without specific, written prior permission.  
+
+DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
+ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
+DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
+ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+SOFTWARE.
+
+************************************************************************/
+/* $XConsortium: mipolytext.c,v 5.4 94/04/17 20:27:45 keith Exp $ */
+/*
+ * mipolytext.c - text routines
+ *
+ * Author:     haynes
+ *             Digital Equipment Corporation
+ *             Western Software Laboratory
+ * Date:       Thu Feb  5 1987
+ */
+
+#include       "X.h"
+#include       "Xmd.h"
+#include       "Xproto.h"
+#include       "misc.h"
+#include       "gcstruct.h"
+#include       "fontstruct.h"
+#include       "dixfontstr.h"
+
+int
+miPolyText(pDraw, pGC, x, y, count, chars, fontEncoding)
+    DrawablePtr pDraw;
+    GCPtr      pGC;
+    int                x, y;
+    int                count;
+    char       *chars;
+    FontEncoding fontEncoding;
+{
+    unsigned long n, i;
+    int w;
+    CharInfoPtr charinfo[255]; /* encoding only has 1 byte for count */
+
+    GetGlyphs(pGC->font, (unsigned long)count, (unsigned char *)chars,
+             fontEncoding, &n, charinfo);
+    w = 0;
+    for (i=0; i < n; i++) w += charinfo[i]->metrics.characterWidth;
+    if (n != 0)
+        (*pGC->ops->PolyGlyphBlt)(
+           pDraw, pGC, x, y, n, charinfo, FONTGLYPHS(pGC->font));
+    return x+w;
+}
+
+
+int
+miPolyText8(pDraw, pGC, x, y, count, chars)
+    DrawablePtr pDraw;
+    GCPtr      pGC;
+    int                x, y;
+    int        count;
+    char       *chars;
+{
+    unsigned long n, i;
+    int w;
+    CharInfoPtr charinfo[255]; /* encoding only has 1 byte for count */
+
+    GetGlyphs(pGC->font, (unsigned long)count, (unsigned char *)chars,
+             Linear8Bit, &n, charinfo);
+    w = 0;
+    for (i=0; i < n; i++) w += charinfo[i]->metrics.characterWidth;
+    if (n != 0)
+        (*pGC->ops->PolyGlyphBlt)(
+           pDraw, pGC, x, y, n, charinfo, FONTGLYPHS(pGC->font));
+    return x+w;
+}
+
+
+int
+miPolyText16(pDraw, pGC, x, y, count, chars)
+    DrawablePtr pDraw;
+    GCPtr      pGC;
+    int                x, y;
+    int                count;
+    unsigned short *chars;
+{
+    unsigned long n, i;
+    int w;
+    CharInfoPtr charinfo[255]; /* encoding only has 1 byte for count */
+
+    GetGlyphs(pGC->font, (unsigned long)count, (unsigned char *)chars,
+             (FONTLASTROW(pGC->font) == 0) ? Linear16Bit : TwoD16Bit,
+             &n, charinfo);
+    w = 0;
+    for (i=0; i < n; i++) w += charinfo[i]->metrics.characterWidth;
+    if (n != 0)
+        (*pGC->ops->PolyGlyphBlt)(
+           pDraw, pGC, x, y, n, charinfo, FONTGLYPHS(pGC->font));
+    return x+w;
+}
+
+
+int
+miImageText(pDraw, pGC, x, y, count, chars, fontEncoding)
+    DrawablePtr pDraw;
+    GCPtr      pGC;
+    int        x, y;
+    int        count;
+    char       *chars;
+    FontEncoding fontEncoding;
+{
+    unsigned long n, i;
+    FontPtr font = pGC->font;
+    int w;
+    CharInfoPtr charinfo[255];
+
+    GetGlyphs(font, (unsigned long)count, (unsigned char *)chars,
+             fontEncoding, &n, charinfo);
+    w = 0;
+    for (i=0; i < n; i++) w += charinfo[i]->metrics.characterWidth;
+    if (n !=0 )
+        (*pGC->ops->ImageGlyphBlt)(pDraw, pGC, x, y, n, charinfo, FONTGLYPHS(font));
+    return x+w;
+}
+
+
+void
+miImageText8(pDraw, pGC, x, y, count, chars)
+    DrawablePtr pDraw;
+    GCPtr      pGC;
+    int                x, y;
+    int                count;
+    char       *chars;
+{
+    unsigned long n;
+    FontPtr font = pGC->font;
+    CharInfoPtr charinfo[255]; /* encoding only has 1 byte for count */
+
+    GetGlyphs(font, (unsigned long)count, (unsigned char *)chars,
+             Linear8Bit, &n, charinfo);
+    if (n !=0 )
+        (*pGC->ops->ImageGlyphBlt)(pDraw, pGC, x, y, n, charinfo, FONTGLYPHS(font));
+}
+
+
+void
+miImageText16(pDraw, pGC, x, y, count, chars)
+    DrawablePtr pDraw;
+    GCPtr      pGC;
+    int                x, y;
+    int                count;
+    unsigned short *chars;
+{
+    unsigned long n;
+    FontPtr font = pGC->font;
+    CharInfoPtr charinfo[255]; /* encoding only has 1 byte for count */
+
+    GetGlyphs(font, (unsigned long)count, (unsigned char *)chars,
+             (FONTLASTROW(pGC->font) == 0) ? Linear16Bit : TwoD16Bit,
+             &n, charinfo);
+    if (n !=0 )
+        (*pGC->ops->ImageGlyphBlt)(pDraw, pGC, x, y, n, charinfo, FONTGLYPHS(font));
+}
diff --git a/Xserver/programs/Xserver/mi/mipolyutil.c b/Xserver/programs/Xserver/mi/mipolyutil.c
new file mode 100644 (file)
index 0000000..74e654d
--- /dev/null
@@ -0,0 +1,399 @@
+/***********************************************************
+
+Copyright (c) 1987  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+
+Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
+
+                        All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and its 
+documentation for any purpose and without fee is hereby granted, 
+provided that the above copyright notice appear in all copies and that
+both that copyright notice and this permission notice appear in 
+supporting documentation, and that the name of Digital not be
+used in advertising or publicity pertaining to distribution of the
+software without specific, written prior permission.  
+
+DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
+ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
+DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
+ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+SOFTWARE.
+
+******************************************************************/
+/* $XConsortium: mipolyutil.c,v 1.16 94/04/17 20:27:46 dpw Exp $ */
+#include "miscstruct.h"
+#include "gc.h"
+#include "miscanfill.h"
+#include "mipoly.h"
+
+#define MAXINT 0x7fffffff
+#define MININT -MAXINT
+
+/*
+ *     fillUtils.c
+ *
+ *     Written by Brian Kelleher;  Oct. 1985
+ *
+ *     This module contains all of the utility functions
+ *     needed to scan convert a polygon.
+ *
+ */
+\f
+/*
+ *     InsertEdgeInET
+ *
+ *     Insert the given edge into the edge table.
+ *     First we must find the correct bucket in the
+ *     Edge table, then find the right slot in the
+ *     bucket.  Finally, we can insert it.
+ *
+ */
+Bool
+miInsertEdgeInET(ET, ETE, scanline, SLLBlock, iSLLBlock)
+    EdgeTable *ET;
+    EdgeTableEntry *ETE;
+    int scanline;
+    ScanLineListBlock **SLLBlock;
+    int *iSLLBlock;
+{
+    register EdgeTableEntry *start, *prev;
+    register ScanLineList *pSLL, *pPrevSLL;
+    ScanLineListBlock *tmpSLLBlock;
+
+    /*
+     * find the right bucket to put the edge into
+     */
+    pPrevSLL = &ET->scanlines;
+    pSLL = pPrevSLL->next;
+    while (pSLL && (pSLL->scanline < scanline)) 
+    {
+        pPrevSLL = pSLL;
+        pSLL = pSLL->next;
+    }
+
+    /*
+     * reassign pSLL (pointer to ScanLineList) if necessary
+     */
+    if ((!pSLL) || (pSLL->scanline > scanline)) 
+    {
+        if (*iSLLBlock > SLLSPERBLOCK-1) 
+        {
+            tmpSLLBlock = 
+                 (ScanLineListBlock *)xalloc(sizeof(ScanLineListBlock));
+           if (!tmpSLLBlock)
+               return FALSE;
+            (*SLLBlock)->next = tmpSLLBlock;
+            tmpSLLBlock->next = (ScanLineListBlock *)NULL;
+            *SLLBlock = tmpSLLBlock;
+            *iSLLBlock = 0;
+        }
+        pSLL = &((*SLLBlock)->SLLs[(*iSLLBlock)++]);
+
+        pSLL->next = pPrevSLL->next;
+        pSLL->edgelist = (EdgeTableEntry *)NULL;
+        pPrevSLL->next = pSLL;
+    }
+    pSLL->scanline = scanline;
+
+    /*
+     * now insert the edge in the right bucket
+     */
+    prev = (EdgeTableEntry *)NULL;
+    start = pSLL->edgelist;
+    while (start && (start->bres.minor < ETE->bres.minor)) 
+    {
+        prev = start;
+        start = start->next;
+    }
+    ETE->next = start;
+
+    if (prev)
+        prev->next = ETE;
+    else
+        pSLL->edgelist = ETE;
+    return TRUE;
+}
+\f
+/*
+ *     CreateEdgeTable
+ *
+ *     This routine creates the edge table for
+ *     scan converting polygons. 
+ *     The Edge Table (ET) looks like:
+ *
+ *    EdgeTable
+ *     --------
+ *    |  ymax  |        ScanLineLists
+ *    |scanline|-->------------>-------------->...
+ *     --------   |scanline|   |scanline|
+ *                |edgelist|   |edgelist|
+ *                ---------    ---------
+ *                    |             |
+ *                    |             |
+ *                    V             V
+ *              list of ETEs   list of ETEs
+ *
+ *     where ETE is an EdgeTableEntry data structure,
+ *     and there is one ScanLineList per scanline at
+ *     which an edge is initially entered.
+ *
+ */
+
+Bool
+miCreateETandAET(count, pts, ET, AET, pETEs, pSLLBlock)
+    register int count;
+    register DDXPointPtr pts;
+    EdgeTable *ET;
+    EdgeTableEntry *AET;
+    register EdgeTableEntry *pETEs;
+    ScanLineListBlock   *pSLLBlock;
+{
+    register DDXPointPtr top, bottom;
+    register DDXPointPtr PrevPt, CurrPt;
+    int iSLLBlock = 0;
+
+    int dy;
+
+    if (count < 2)  return TRUE;
+
+    /*
+     *  initialize the Active Edge Table
+     */
+    AET->next = (EdgeTableEntry *)NULL;
+    AET->back = (EdgeTableEntry *)NULL;
+    AET->nextWETE = (EdgeTableEntry *)NULL;
+    AET->bres.minor = MININT;
+
+    /*
+     *  initialize the Edge Table.
+     */
+    ET->scanlines.next = (ScanLineList *)NULL;
+    ET->ymax = MININT;
+    ET->ymin = MAXINT;
+    pSLLBlock->next = (ScanLineListBlock *)NULL;
+
+    PrevPt = &pts[count-1];
+
+    /*
+     *  for each vertex in the array of points.
+     *  In this loop we are dealing with two vertices at
+     *  a time -- these make up one edge of the polygon.
+     */
+    while (count--) 
+    {
+        CurrPt = pts++;
+
+        /*
+         *  find out which point is above and which is below.
+         */
+        if (PrevPt->y > CurrPt->y) 
+        {
+            bottom = PrevPt, top = CurrPt;
+            pETEs->ClockWise = 0;
+        }
+        else 
+        {
+            bottom = CurrPt, top = PrevPt;
+            pETEs->ClockWise = 1;
+        }
+
+        /*
+         * don't add horizontal edges to the Edge table.
+         */
+        if (bottom->y != top->y) 
+        {
+            pETEs->ymax = bottom->y-1;  /* -1 so we don't get last scanline */
+
+            /*
+             *  initialize integer edge algorithm
+             */
+            dy = bottom->y - top->y;
+            BRESINITPGONSTRUCT(dy, top->x, bottom->x, pETEs->bres);
+
+            if (!miInsertEdgeInET(ET, pETEs, top->y, &pSLLBlock, &iSLLBlock))
+           {
+               miFreeStorage(pSLLBlock->next);
+               return FALSE;
+           }
+
+            ET->ymax = max(ET->ymax, PrevPt->y);
+            ET->ymin = min(ET->ymin, PrevPt->y);
+            pETEs++;
+        }
+
+        PrevPt = CurrPt;
+    }
+    return TRUE;
+}
+\f
+/*
+ *     loadAET
+ *
+ *     This routine moves EdgeTableEntries from the
+ *     EdgeTable into the Active Edge Table,
+ *     leaving them sorted by smaller x coordinate.
+ *
+ */
+
+void
+miloadAET(AET, ETEs)
+    register EdgeTableEntry *AET, *ETEs;
+{
+    register EdgeTableEntry *pPrevAET;
+    register EdgeTableEntry *tmp;
+
+    pPrevAET = AET;
+    AET = AET->next;
+    while (ETEs) 
+    {
+        while (AET && (AET->bres.minor < ETEs->bres.minor)) 
+        {
+            pPrevAET = AET;
+            AET = AET->next;
+        }
+        tmp = ETEs->next;
+        ETEs->next = AET;
+        if (AET)
+            AET->back = ETEs;
+        ETEs->back = pPrevAET;
+        pPrevAET->next = ETEs;
+        pPrevAET = ETEs;
+
+        ETEs = tmp;
+    }
+}
+\f
+/*
+ *     computeWAET
+ *
+ *     This routine links the AET by the
+ *     nextWETE (winding EdgeTableEntry) link for
+ *     use by the winding number rule.  The final 
+ *     Active Edge Table (AET) might look something
+ *     like:
+ *
+ *     AET
+ *     ----------  ---------   ---------
+ *     |ymax    |  |ymax    |  |ymax    | 
+ *     | ...    |  |...     |  |...     |
+ *     |next    |->|next    |->|next    |->...
+ *     |nextWETE|  |nextWETE|  |nextWETE|
+ *     ---------   ---------   ^--------
+ *         |                   |       |
+ *         V------------------->       V---> ...
+ *
+ */
+void
+micomputeWAET(AET)
+    register EdgeTableEntry *AET;
+{
+    register EdgeTableEntry *pWETE;
+    register int inside = 1;
+    register int isInside = 0;
+
+    AET->nextWETE = (EdgeTableEntry *)NULL;
+    pWETE = AET;
+    AET = AET->next;
+    while (AET) 
+    {
+        if (AET->ClockWise)
+            isInside++;
+        else
+            isInside--;
+
+        if ((!inside && !isInside) ||
+            ( inside &&  isInside)) 
+        {
+            pWETE->nextWETE = AET;
+            pWETE = AET;
+            inside = !inside;
+        }
+        AET = AET->next;
+    }
+    pWETE->nextWETE = (EdgeTableEntry *)NULL;
+}
+\f
+/*
+ *     InsertionSort
+ *
+ *     Just a simple insertion sort using
+ *     pointers and back pointers to sort the Active
+ *     Edge Table.
+ *
+ */
+
+int
+miInsertionSort(AET)
+    register EdgeTableEntry *AET;
+{
+    register EdgeTableEntry *pETEchase;
+    register EdgeTableEntry *pETEinsert;
+    register EdgeTableEntry *pETEchaseBackTMP;
+    register int changed = 0;
+
+    AET = AET->next;
+    while (AET) 
+    {
+        pETEinsert = AET;
+        pETEchase = AET;
+        while (pETEchase->back->bres.minor > AET->bres.minor)
+            pETEchase = pETEchase->back;
+
+        AET = AET->next;
+        if (pETEchase != pETEinsert) 
+        {
+            pETEchaseBackTMP = pETEchase->back;
+            pETEinsert->back->next = AET;
+            if (AET)
+                AET->back = pETEinsert->back;
+            pETEinsert->next = pETEchase;
+            pETEchase->back->next = pETEinsert;
+            pETEchase->back = pETEinsert;
+            pETEinsert->back = pETEchaseBackTMP;
+            changed = 1;
+        }
+    }
+    return(changed);
+}
+\f
+/*
+ *     Clean up our act.
+ */
+void
+miFreeStorage(pSLLBlock)
+    register ScanLineListBlock   *pSLLBlock;
+{
+    register ScanLineListBlock   *tmpSLLBlock;
+
+    while (pSLLBlock) 
+    {
+        tmpSLLBlock = pSLLBlock->next;
+        xfree(pSLLBlock);
+        pSLLBlock = tmpSLLBlock;
+    }
+}
diff --git a/Xserver/programs/Xserver/mi/mipushpxl.c b/Xserver/programs/Xserver/mi/mipushpxl.c
new file mode 100644 (file)
index 0000000..e9c5531
--- /dev/null
@@ -0,0 +1,199 @@
+/***********************************************************
+
+Copyright (c) 1987  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+
+Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
+
+                        All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and its 
+documentation for any purpose and without fee is hereby granted, 
+provided that the above copyright notice appear in all copies and that
+both that copyright notice and this permission notice appear in 
+supporting documentation, and that the name of Digital not be
+used in advertising or publicity pertaining to distribution of the
+software without specific, written prior permission.  
+
+DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
+ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
+DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
+ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+SOFTWARE.
+
+******************************************************************/
+/* $XConsortium: mipushpxl.c,v 5.5 94/04/17 20:27:47 dpw Exp $ */
+/* $XFree86: xc/programs/Xserver/mi/mipushpxl.c,v 3.1 1996/12/09 12:02:49 dawes Exp $ */
+#include "X.h"
+#include "gcstruct.h"
+#include "scrnintstr.h"
+#include "pixmapstr.h"
+#include "miscstruct.h"
+#include "../mfb/maskbits.h"
+
+#define NPT 128
+
+/* miPushPixels -- squeegees the fill style of pGC through pBitMap
+ * into pDrawable.  pBitMap is a stencil (dx by dy of it is used, it may
+ * be bigger) which is placed on the drawable at xOrg, yOrg.  Where a 1 bit
+ * is set in the bitmap, the fill style is put onto the drawable using
+ * the GC's logical function. The drawable is not changed where the bitmap
+ * has a zero bit or outside the area covered by the stencil.
+
+WARNING:
+    this code works if the 1-bit deep pixmap format returned by GetSpans
+is the same as the format defined by the mfb code (i.e. 32-bit padding
+per scanline, scanline unit = 32 bits; later, this might mean
+bitsizeof(int) padding and sacnline unit == bitsizeof(int).)
+
+ */
+void
+miPushPixels(pGC, pBitMap, pDrawable, dx, dy, xOrg, yOrg)
+    GCPtr      pGC;
+    PixmapPtr  pBitMap;
+    DrawablePtr pDrawable;
+    int                dx, dy, xOrg, yOrg;
+{
+    int                h, dxDivPPW, ibEnd;
+    unsigned long *pwLineStart;
+    register unsigned long     *pw, *pwEnd;
+    register unsigned long msk;
+    register int ib, w;
+    register int ipt;          /* index into above arrays */
+    Bool       fInBox;
+    DDXPointRec        pt[NPT], ptThisLine;
+    int                width[NPT];
+
+    pwLineStart = (unsigned long *)xalloc(BitmapBytePad(dx));
+    if (!pwLineStart)
+       return;
+    ipt = 0;
+    dxDivPPW = dx/PPW;
+
+    for(h = 0, ptThisLine.x = 0, ptThisLine.y = 0; 
+       h < dy; 
+       h++, ptThisLine.y++)
+    {
+
+       (*pBitMap->drawable.pScreen->GetSpans)((DrawablePtr)pBitMap, dx,
+                       &ptThisLine, &dx, 1, (char *)pwLineStart);
+
+       pw = pwLineStart;
+       /* Process all words which are fully in the pixmap */
+       
+       fInBox = FALSE;
+       pwEnd = pwLineStart + dxDivPPW;
+       while(pw  < pwEnd)
+       {
+           w = *pw;
+           msk = endtab[1];
+           for(ib = 0; ib < PPW; ib++)
+           {
+               if(w & msk)
+               {
+                   if(!fInBox)
+                   {
+                       pt[ipt].x = ((pw - pwLineStart) << PWSH) + ib + xOrg;
+                       pt[ipt].y = h + yOrg;
+                       /* start new box */
+                       fInBox = TRUE;
+                   }
+               }
+               else
+               {
+                   if(fInBox)
+                   {
+                       width[ipt] = ((pw - pwLineStart) << PWSH) + 
+                                    ib + xOrg - pt[ipt].x;
+                       if (++ipt >= NPT)
+                       {
+                           (*pGC->ops->FillSpans)(pDrawable, pGC, 
+                                             NPT, pt, width, TRUE);
+                           ipt = 0;
+                       }
+                       /* end box */
+                       fInBox = FALSE;
+                   }
+               }
+               msk = SCRRIGHT(msk, 1);
+           }
+           pw++;
+       }
+       ibEnd = dx & PIM;
+       if(ibEnd)
+       {
+           /* Process final partial word on line */
+           w = *pw;
+           msk = endtab[1];
+           for(ib = 0; ib < ibEnd; ib++)
+           {
+               if(w & msk)
+               {
+                   if(!fInBox)
+                   {
+                       /* start new box */
+                       pt[ipt].x = ((pw - pwLineStart) << PWSH) + ib + xOrg;
+                       pt[ipt].y = h + yOrg;
+                       fInBox = TRUE;
+                   }
+               }
+               else
+               {
+                   if(fInBox)
+                   {
+                       /* end box */
+                       width[ipt] = ((pw - pwLineStart) << PWSH) + 
+                                    ib + xOrg - pt[ipt].x;
+                       if (++ipt >= NPT)
+                       {
+                           (*pGC->ops->FillSpans)(pDrawable, 
+                                             pGC, NPT, pt, width, TRUE);
+                           ipt = 0;
+                       }
+                       fInBox = FALSE;
+                   }
+               }
+               msk = SCRRIGHT(msk, 1);
+           }
+       }
+       /* If scanline ended with last bit set, end the box */
+       if(fInBox)
+       {
+           width[ipt] = dx + xOrg - pt[ipt].x;
+           if (++ipt >= NPT)
+           {
+               (*pGC->ops->FillSpans)(pDrawable, pGC, NPT, pt, width, TRUE);
+               ipt = 0;
+           }
+       }
+    }
+    xfree(pwLineStart);
+    /* Flush any remaining spans */
+    if (ipt)
+    {
+       (*pGC->ops->FillSpans)(pDrawable, pGC, ipt, pt, width, TRUE);
+    }
+}
diff --git a/Xserver/programs/Xserver/mi/miregion.c b/Xserver/programs/Xserver/mi/miregion.c
new file mode 100644 (file)
index 0000000..582d348
--- /dev/null
@@ -0,0 +1,2420 @@
+/***********************************************************
+
+Copyright (c) 1987, 1988, 1989  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+Copyright 1987, 1988, 1989 by 
+Digital Equipment Corporation, Maynard, Massachusetts. 
+
+                        All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and its 
+documentation for any purpose and without fee is hereby granted, 
+provided that the above copyright notice appear in all copies and that
+both that copyright notice and this permission notice appear in 
+supporting documentation, and that the name of Digital not be
+used in advertising or publicity pertaining to distribution of the
+software without specific, written prior permission.  
+
+DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
+ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
+DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
+ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+SOFTWARE.
+
+******************************************************************/
+/* $XConsortium: miregion.c,v 1.60 94/04/17 20:27:49 dpw Exp $ */
+
+#include <stdio.h>
+#include "miscstruct.h"
+#include "regionstr.h"
+#include "Xprotostr.h"
+#include "gc.h"
+
+#if defined (__GNUC__) && !defined (NO_INLINES)
+#define INLINE __inline
+#else
+#define INLINE
+#endif
+
+/*
+ * hack until callers of these functions can deal with out-of-memory
+ */
+
+extern Bool Must_have_memory;
+
+#ifdef DEBUG
+#define assert(expr) {if (!(expr)) \
+               FatalError("Assertion failed file %s, line %d: expr\n", \
+                       __FILE__, __LINE__); }
+#else
+#define assert(expr)
+#endif
+
+#define good(reg) assert(miValidRegion(reg))
+
+/*
+ * The functions in this file implement the Region abstraction used extensively
+ * throughout the X11 sample server. A Region is simply a set of disjoint
+ * (non-overlapping) rectangles, plus an "extent" rectangle which is the
+ * smallest single rectangle that contains all the non-overlapping rectangles.
+ *
+ * A Region is implemented as a "y-x-banded" array of rectangles.  This array
+ * imposes two degrees of order.  First, all rectangles are sorted by top side
+ * y coordinate first (y1), and then by left side x coordinate (x1).
+ *
+ * Furthermore, the rectangles are grouped into "bands".  Each rectangle in a
+ * band has the same top y coordinate (y1), and each has the same bottom y
+ * coordinate (y2).  Thus all rectangles in a band differ only in their left
+ * and right side (x1 and x2).  Bands are implicit in the array of rectangles:
+ * there is no separate list of band start pointers.
+ *
+ * The y-x band representation does not minimize rectangles.  In particular,
+ * if a rectangle vertically crosses a band (the rectangle has scanlines in 
+ * the y1 to y2 area spanned by the band), then the rectangle may be broken
+ * down into two or more smaller rectangles stacked one atop the other. 
+ *
+ *  -----------                                    -----------
+ *  |         |                                    |         |             band 0
+ *  |         |  --------                  -----------  --------
+ *  |         |  |      |  in y-x banded    |         |  |      |   band 1
+ *  |         |  |      |  form is         |         |  |      |
+ *  -----------  |      |                  -----------  --------
+ *               |      |                               |      |   band 2
+ *               --------                               --------
+ *
+ * An added constraint on the rectangles is that they must cover as much
+ * horizontal area as possible: no two rectangles within a band are allowed
+ * to touch.
+ *
+ * Whenever possible, bands will be merged together to cover a greater vertical
+ * distance (and thus reduce the number of rectangles). Two bands can be merged
+ * only if the bottom of one touches the top of the other and they have
+ * rectangles in the same places (of the same width, of course).
+ *
+ * Adam de Boor wrote most of the original region code.  Joel McCormack
+ * substantially modified or rewrote most of the core arithmetic routines,
+ * and added miRegionValidate in order to support several speed improvements
+ * to miValidateTree.  Bob Scheifler changed the representation to be more
+ * compact when empty or a single rectangle, and did a bunch of gratuitous
+ * reformatting.
+ */
+
+/*  true iff two Boxes overlap */
+#define EXTENTCHECK(r1,r2) \
+      (!( ((r1)->x2 <= (r2)->x1)  || \
+          ((r1)->x1 >= (r2)->x2)  || \
+          ((r1)->y2 <= (r2)->y1)  || \
+          ((r1)->y1 >= (r2)->y2) ) )
+
+/* true iff (x,y) is in Box */
+#define INBOX(r,x,y) \
+      ( ((r)->x2 >  x) && \
+        ((r)->x1 <= x) && \
+        ((r)->y2 >  y) && \
+        ((r)->y1 <= y) )
+
+/* true iff Box r1 contains Box r2 */
+#define SUBSUMES(r1,r2) \
+      ( ((r1)->x1 <= (r2)->x1) && \
+        ((r1)->x2 >= (r2)->x2) && \
+        ((r1)->y1 <= (r2)->y1) && \
+        ((r1)->y2 >= (r2)->y2) )
+
+#define xallocData(n) (RegDataPtr)xalloc(REGION_SZOF(n))
+#define xfreeData(reg) if ((reg)->data && (reg)->data->size) xfree((reg)->data)
+
+#define RECTALLOC(pReg,n) \
+if (!(pReg)->data || (((pReg)->data->numRects + (n)) > (pReg)->data->size)) \
+    miRectAlloc(pReg, n)
+
+#define ADDRECT(pNextRect,nx1,ny1,nx2,ny2)     \
+{                                              \
+    pNextRect->x1 = nx1;                       \
+    pNextRect->y1 = ny1;                       \
+    pNextRect->x2 = nx2;                       \
+    pNextRect->y2 = ny2;                       \
+    pNextRect++;                               \
+}
+
+#define NEWRECT(pReg,pNextRect,nx1,ny1,nx2,ny2)                        \
+{                                                                      \
+    if (!(pReg)->data || ((pReg)->data->numRects == (pReg)->data->size))\
+    {                                                                  \
+       miRectAlloc(pReg, 1);                                           \
+       pNextRect = REGION_TOP(pReg);                                   \
+    }                                                                  \
+    ADDRECT(pNextRect,nx1,ny1,nx2,ny2);                                        \
+    pReg->data->numRects++;                                            \
+    assert(pReg->data->numRects<=pReg->data->size);                    \
+}
+
+
+#define DOWNSIZE(reg,numRects)                                          \
+if (((numRects) < ((reg)->data->size >> 1)) && ((reg)->data->size > 50)) \
+{                                                                       \
+    RegDataPtr NewData;                                                         \
+    NewData = (RegDataPtr)xrealloc((reg)->data, REGION_SZOF(numRects));         \
+    if (NewData)                                                        \
+    {                                                                   \
+       NewData->size = (numRects);                                      \
+       (reg)->data = NewData;                                           \
+    }                                                                   \
+}
+
+
+BoxRec miEmptyBox = {0, 0, 0, 0};
+RegDataRec miEmptyData = {0, 0};
+
+#ifdef DEBUG
+int
+miPrintRegion(rgn)
+    RegionPtr rgn;
+{
+    int num, size;
+    register int i;
+    BoxPtr rects;
+
+    num = REGION_NUM_RECTS(rgn);
+    size = REGION_SIZE(rgn);
+    rects = REGION_RECTS(rgn);
+    ErrorF("num: %d size: %d\n", num, size);
+    ErrorF("extents: %d %d %d %d\n",
+          rgn->extents.x1, rgn->extents.y1, rgn->extents.x2, rgn->extents.y2);
+    for (i = 0; i < num; i++)
+      ErrorF("%d %d %d %d \n",
+            rects[i].x1, rects[i].y1, rects[i].x2, rects[i].y2);
+    ErrorF("\n");
+    return(num);
+}
+
+
+Bool
+miRegionsEqual(reg1, reg2)
+    RegionPtr reg1;
+    RegionPtr reg2;
+{
+    int i;
+    BoxPtr rects1, rects2;
+
+    if (reg1->extents.x1 != reg2->extents.x1) return FALSE;
+    if (reg1->extents.x2 != reg2->extents.x2) return FALSE;
+    if (reg1->extents.y1 != reg2->extents.y1) return FALSE;
+    if (reg1->extents.y2 != reg2->extents.y2) return FALSE;
+    if (REGION_NUM_RECTS(reg1) != REGION_NUM_RECTS(reg2)) return FALSE;
+    
+    rects1 = REGION_RECTS(reg1);
+    rects2 = REGION_RECTS(reg2);
+    for (i = 0; i != REGION_NUM_RECTS(reg1); i++) {
+       if (rects1[i].x1 != rects2[i].x1) return FALSE;
+       if (rects1[i].x2 != rects2[i].x2) return FALSE;
+       if (rects1[i].y1 != rects2[i].y1) return FALSE;
+       if (rects1[i].y2 != rects2[i].y2) return FALSE;
+    }
+    return TRUE;
+}
+
+Bool
+miValidRegion(reg)
+    RegionPtr reg;
+{
+    register int i, numRects;
+
+    if ((reg->extents.x1 > reg->extents.x2) ||
+       (reg->extents.y1 > reg->extents.y2))
+       return FALSE;
+    numRects = REGION_NUM_RECTS(reg);
+    if (!numRects)
+       return ((reg->extents.x1 == reg->extents.x2) &&
+               (reg->extents.y1 == reg->extents.y2) &&
+               (reg->data->size || (reg->data == &miEmptyData)));
+    else if (numRects == 1)
+       return (!reg->data);
+    else
+    {
+       register BoxPtr pboxP, pboxN;
+       BoxRec box;
+
+       pboxP = REGION_RECTS(reg);
+       box = *pboxP;
+       box.y2 = pboxP[numRects-1].y2;
+       pboxN = pboxP + 1;
+       for (i = numRects; --i > 0; pboxP++, pboxN++)
+       {
+           if ((pboxN->x1 >= pboxN->x2) ||
+               (pboxN->y1 >= pboxN->y2))
+               return FALSE;
+           if (pboxN->x1 < box.x1)
+               box.x1 = pboxN->x1;
+           if (pboxN->x2 > box.x2)
+               box.x2 = pboxN->x2;
+           if ((pboxN->y1 < pboxP->y1) ||
+               ((pboxN->y1 == pboxP->y1) &&
+                ((pboxN->x1 < pboxP->x2) || (pboxN->y2 != pboxP->y2))))
+               return FALSE;
+       }
+       return ((box.x1 == reg->extents.x1) &&
+               (box.x2 == reg->extents.x2) &&
+               (box.y1 == reg->extents.y1) &&
+               (box.y2 == reg->extents.y2));
+    }
+}
+
+#endif /* DEBUG */
+
+
+/*****************************************************************
+ *   RegionCreate(rect, size)
+ *     This routine does a simple malloc to make a structure of
+ *     REGION of "size" number of rectangles.
+ *****************************************************************/
+
+RegionPtr
+miRegionCreate(rect, size)
+    BoxPtr rect;
+    int size;
+{
+    register RegionPtr pReg;
+   
+    Must_have_memory = TRUE; /* XXX */
+    pReg = (RegionPtr)xalloc(sizeof(RegionRec));
+    Must_have_memory = FALSE; /* XXX */
+    if (rect)
+    {
+       pReg->extents = *rect;
+       pReg->data = (RegDataPtr)NULL;
+    }
+    else
+    {
+       pReg->extents = miEmptyBox;
+       if ((size > 1) && (pReg->data = xallocData(size)))
+       {
+           pReg->data->size = size;
+           pReg->data->numRects = 0;
+       }
+       else
+           pReg->data = &miEmptyData;
+    }
+    return(pReg);
+}
+
+/*****************************************************************
+ *   RegionInit(pReg, rect, size)
+ *     Outer region rect is statically allocated.
+ *****************************************************************/
+
+void
+miRegionInit(pReg, rect, size)
+    RegionPtr pReg;
+    BoxPtr rect;
+    int size;
+{
+    if (rect)
+    {
+       pReg->extents = *rect;
+       pReg->data = (RegDataPtr)NULL;
+    }
+    else
+    {
+       pReg->extents = miEmptyBox;
+       if ((size > 1) && (pReg->data = xallocData(size)))
+       {
+           pReg->data->size = size;
+           pReg->data->numRects = 0;
+       }
+       else
+           pReg->data = &miEmptyData;
+    }
+}
+
+void
+miRegionDestroy(pReg)
+    RegionPtr pReg;
+{
+    good(pReg);
+    xfreeData(pReg);
+    xfree(pReg);
+}
+
+void
+miRegionUninit(pReg)
+    RegionPtr pReg;
+{
+    good(pReg);
+    xfreeData(pReg);
+}
+
+Bool
+miRectAlloc(pRgn, n)
+    register RegionPtr pRgn;
+    int n;
+{
+    Must_have_memory = TRUE; /* XXX */
+    if (!pRgn->data)
+    {
+       n++;
+       pRgn->data = xallocData(n);
+       pRgn->data->numRects = 1;
+       *REGION_BOXPTR(pRgn) = pRgn->extents;
+    }
+    else if (!pRgn->data->size)
+    {
+       pRgn->data = xallocData(n);
+       pRgn->data->numRects = 0;
+    }
+    else
+    {
+       if (n == 1)
+       {
+           n = pRgn->data->numRects;
+           if (n > 500) /* XXX pick numbers out of a hat */
+               n = 250;
+       }
+       n += pRgn->data->numRects;
+       pRgn->data = (RegDataPtr)xrealloc(pRgn->data, REGION_SZOF(n));
+    }
+    Must_have_memory = FALSE; /* XXX */
+    pRgn->data->size = n;
+    return TRUE;
+}
+
+Bool
+miRegionCopy(dst, src)
+    register RegionPtr dst;
+    register RegionPtr src;
+{
+    good(dst);
+    good(src);
+    if (dst == src)
+       return TRUE;
+    dst->extents = src->extents;
+    if (!src->data || !src->data->size)
+    {
+       xfreeData(dst);
+       dst->data = src->data;
+       return TRUE;
+    }
+    if (!dst->data || (dst->data->size < src->data->numRects))
+    {
+       xfreeData(dst);
+       Must_have_memory = TRUE; /* XXX */
+       dst->data = xallocData(src->data->numRects);
+       Must_have_memory = FALSE; /* XXX */
+       dst->data->size = src->data->numRects;
+    }
+    dst->data->numRects = src->data->numRects;
+    memmove((char *)REGION_BOXPTR(dst),(char *)REGION_BOXPTR(src), 
+         dst->data->numRects * sizeof(BoxRec));
+    return TRUE;
+}
+
+
+/*======================================================================
+ *         Generic Region Operator
+ *====================================================================*/
+
+/*-
+ *-----------------------------------------------------------------------
+ * miCoalesce --
+ *     Attempt to merge the boxes in the current band with those in the
+ *     previous one.  We are guaranteed that the current band extends to
+ *      the end of the rects array.  Used only by miRegionOp.
+ *
+ * Results:
+ *     The new index for the previous band.
+ *
+ * Side Effects:
+ *     If coalescing takes place:
+ *         - rectangles in the previous band will have their y2 fields
+ *           altered.
+ *         - pReg->data->numRects will be decreased.
+ *
+ *-----------------------------------------------------------------------
+ */
+INLINE static int
+miCoalesce (pReg, prevStart, curStart)
+    register RegionPtr pReg;           /* Region to coalesce                */
+    int                        prevStart;      /* Index of start of previous band   */
+    int                        curStart;       /* Index of start of current band    */
+{
+    register BoxPtr    pPrevBox;       /* Current box in previous band      */
+    register BoxPtr    pCurBox;        /* Current box in current band       */
+    register int       numRects;       /* Number rectangles in both bands   */
+    register int       y2;             /* Bottom of current band            */
+    /*
+     * Figure out how many rectangles are in the band.
+     */
+    numRects = curStart - prevStart;
+    assert(numRects == pReg->data->numRects - curStart);
+
+    if (!numRects) return curStart;
+
+    /*
+     * The bands may only be coalesced if the bottom of the previous
+     * matches the top scanline of the current.
+     */
+    pPrevBox = REGION_BOX(pReg, prevStart);
+    pCurBox = REGION_BOX(pReg, curStart);
+    if (pPrevBox->y2 != pCurBox->y1) return curStart;
+
+    /*
+     * Make sure the bands have boxes in the same places. This
+     * assumes that boxes have been added in such a way that they
+     * cover the most area possible. I.e. two boxes in a band must
+     * have some horizontal space between them.
+     */
+    y2 = pCurBox->y2;
+
+    do {
+       if ((pPrevBox->x1 != pCurBox->x1) || (pPrevBox->x2 != pCurBox->x2)) {
+           return (curStart);
+       }
+       pPrevBox++;
+       pCurBox++;
+       numRects--;
+    } while (numRects);
+
+    /*
+     * The bands may be merged, so set the bottom y of each box
+     * in the previous band to the bottom y of the current band.
+     */
+    numRects = curStart - prevStart;
+    pReg->data->numRects -= numRects;
+    do {
+       pPrevBox--;
+       pPrevBox->y2 = y2;
+       numRects--;
+    } while (numRects);
+    return prevStart;
+}
+
+
+/* Quicky macro to avoid trivial reject procedure calls to miCoalesce */
+
+#define Coalesce(newReg, prevBand, curBand)                            \
+    if (curBand - prevBand == newReg->data->numRects - curBand) {      \
+       prevBand = miCoalesce(newReg, prevBand, curBand);               \
+    } else {                                                           \
+       prevBand = curBand;                                             \
+    }
+
+/*-
+ *-----------------------------------------------------------------------
+ * miAppendNonO --
+ *     Handle a non-overlapping band for the union and subtract operations.
+ *      Just adds the (top/bottom-clipped) rectangles into the region.
+ *      Doesn't have to check for subsumption or anything.
+ *
+ * Results:
+ *     None.
+ *
+ * Side Effects:
+ *     pReg->data->numRects is incremented and the rectangles overwritten
+ *     with the rectangles we're passed.
+ *
+ *-----------------------------------------------------------------------
+ */
+
+INLINE static Bool
+miAppendNonO (pReg, r, rEnd, y1, y2)
+    register RegionPtr pReg;
+    register BoxPtr    r;
+    BoxPtr             rEnd;
+    register int       y1;
+    register int       y2;
+{
+    register BoxPtr    pNextRect;
+    register int       newRects;
+
+    newRects = rEnd - r;
+
+    assert(y1 < y2);
+    assert(newRects != 0);
+
+    /* Make sure we have enough space for all rectangles to be added */
+    RECTALLOC(pReg, newRects);
+    pNextRect = REGION_TOP(pReg);
+    pReg->data->numRects += newRects;
+    do {
+       assert(r->x1 < r->x2);
+       ADDRECT(pNextRect, r->x1, y1, r->x2, y2);
+       r++;
+    } while (r != rEnd);
+
+    return TRUE;
+}
+
+#define FindBand(r, rBandEnd, rEnd, ry1)                   \
+{                                                          \
+    ry1 = r->y1;                                           \
+    rBandEnd = r+1;                                        \
+    while ((rBandEnd != rEnd) && (rBandEnd->y1 == ry1)) {   \
+       rBandEnd++;                                         \
+    }                                                      \
+}
+
+#define        AppendRegions(newReg, r, rEnd)                                  \
+{                                                                      \
+    int newRects;                                                      \
+    if (newRects = rEnd - r) {                                         \
+       RECTALLOC(newReg, newRects);                                    \
+       memmove((char *)REGION_TOP(newReg),(char *)r,                   \
+              newRects * sizeof(BoxRec));                              \
+       newReg->data->numRects += newRects;                             \
+    }                                                                  \
+}
+
+/*-
+ *-----------------------------------------------------------------------
+ * miRegionOp --
+ *     Apply an operation to two regions. Called by miUnion, miInverse,
+ *     miSubtract, miIntersect....  Both regions MUST have at least one
+ *      rectangle, and cannot be the same object.
+ *
+ * Results:
+ *     TRUE if successful.
+ *
+ * Side Effects:
+ *     The new region is overwritten.
+ *     pOverlap set to TRUE if overlapFunc ever returns TRUE.
+ *
+ * Notes:
+ *     The idea behind this function is to view the two regions as sets.
+ *     Together they cover a rectangle of area that this function divides
+ *     into horizontal bands where points are covered only by one region
+ *     or by both. For the first case, the nonOverlapFunc is called with
+ *     each the band and the band's upper and lower extents. For the
+ *     second, the overlapFunc is called to process the entire band. It
+ *     is responsible for clipping the rectangles in the band, though
+ *     this function provides the boundaries.
+ *     At the end of each band, the new region is coalesced, if possible,
+ *     to reduce the number of rectangles in the region.
+ *
+ *-----------------------------------------------------------------------
+ */
+static Bool
+miRegionOp(newReg, reg1, reg2, overlapFunc, appendNon1, appendNon2, pOverlap)
+    RegionPtr       newReg;                /* Place to store result         */
+    RegionPtr       reg1;                  /* First region in operation     */
+    RegionPtr       reg2;                  /* 2d region in operation        */
+    Bool           (*overlapFunc)();       /* Function to call for over-
+                                            * lapping bands                 */
+    Bool           appendNon1;             /* Append non-overlapping bands  */
+                                           /* in region 1 ? */
+    Bool           appendNon2;             /* Append non-overlapping bands  */
+                                           /* in region 2 ? */
+    Bool           *pOverlap;
+{
+    register BoxPtr r1;                            /* Pointer into first region     */
+    register BoxPtr r2;                            /* Pointer into 2d region        */
+    BoxPtr         r1End;                  /* End of 1st region             */
+    BoxPtr         r2End;                  /* End of 2d region              */
+    short          ybot;                   /* Bottom of intersection        */
+    short          ytop;                   /* Top of intersection           */
+    RegDataPtr     oldData;                /* Old data for newReg           */
+    int                    prevBand;               /* Index of start of
+                                            * previous band in newReg       */
+    int                    curBand;                /* Index of start of current
+                                            * band in newReg                */
+    register BoxPtr r1BandEnd;             /* End of current band in r1     */
+    register BoxPtr r2BandEnd;             /* End of current band in r2     */
+    short          top;                    /* Top of non-overlapping band   */
+    short          bot;                    /* Bottom of non-overlapping band*/
+    register int    r1y1;                  /* Temps for r1->y1 and r2->y1   */
+    register int    r2y1;
+    int                    newSize;
+    int                    numRects;
+
+    /*
+     * Initialization:
+     * set r1, r2, r1End and r2End appropriately, save the rectangles
+     * of the destination region until the end in case it's one of
+     * the two source regions, then mark the "new" region empty, allocating
+     * another array of rectangles for it to use.
+     */
+
+    r1 = REGION_RECTS(reg1);
+    newSize = REGION_NUM_RECTS(reg1);
+    r1End = r1 + newSize;
+    numRects = REGION_NUM_RECTS(reg2);
+    r2 = REGION_RECTS(reg2);
+    r2End = r2 + numRects;
+    assert(r1 != r1End);
+    assert(r2 != r2End);
+
+    oldData = (RegDataPtr)NULL;
+    if (((newReg == reg1) && (newSize > 1)) ||
+       ((newReg == reg2) && (numRects > 1)))
+    {
+       oldData = newReg->data;
+       newReg->data = &miEmptyData;
+    }
+    /* guess at new size */
+    if (numRects > newSize)
+       newSize = numRects;
+    newSize <<= 1;
+    if (!newReg->data)
+       newReg->data = &miEmptyData;
+    else if (newReg->data->size)
+       newReg->data->numRects = 0;
+    if (newSize > newReg->data->size)
+       miRectAlloc(newReg, newSize);
+
+    /*
+     * Initialize ybot.
+     * In the upcoming loop, ybot and ytop serve different functions depending
+     * on whether the band being handled is an overlapping or non-overlapping
+     * band.
+     *         In the case of a non-overlapping band (only one of the regions
+     * has points in the band), ybot is the bottom of the most recent
+     * intersection and thus clips the top of the rectangles in that band.
+     * ytop is the top of the next intersection between the two regions and
+     * serves to clip the bottom of the rectangles in the current band.
+     * For an overlapping band (where the two regions intersect), ytop clips
+     * the top of the rectangles of both regions and ybot clips the bottoms.
+     */
+
+    ybot = min(r1->y1, r2->y1);
+    
+    /*
+     * prevBand serves to mark the start of the previous band so rectangles
+     * can be coalesced into larger rectangles. qv. miCoalesce, above.
+     * In the beginning, there is no previous band, so prevBand == curBand
+     * (curBand is set later on, of course, but the first band will always
+     * start at index 0). prevBand and curBand must be indices because of
+     * the possible expansion, and resultant moving, of the new region's
+     * array of rectangles.
+     */
+    prevBand = 0;
+    
+    do {
+       /*
+        * This algorithm proceeds one source-band (as opposed to a
+        * destination band, which is determined by where the two regions
+        * intersect) at a time. r1BandEnd and r2BandEnd serve to mark the
+        * rectangle after the last one in the current band for their
+        * respective regions.
+        */
+       assert(r1 != r1End);
+       assert(r2 != r2End);
+    
+       FindBand(r1, r1BandEnd, r1End, r1y1);
+       FindBand(r2, r2BandEnd, r2End, r2y1);
+
+       /*
+        * First handle the band that doesn't intersect, if any.
+        *
+        * Note that attention is restricted to one band in the
+        * non-intersecting region at once, so if a region has n
+        * bands between the current position and the next place it overlaps
+        * the other, this entire loop will be passed through n times.
+        */
+       if (r1y1 < r2y1) {
+           if (appendNon1) {
+               top = max(r1y1, ybot);
+               bot = min(r1->y2, r2y1);
+               if (top != bot) {
+                   curBand = newReg->data->numRects;
+                   miAppendNonO(newReg, r1, r1BandEnd, top, bot);
+                   Coalesce(newReg, prevBand, curBand);
+               }
+           }
+           ytop = r2y1;
+       } else if (r2y1 < r1y1) {
+           if (appendNon2) {
+               top = max(r2y1, ybot);
+               bot = min(r2->y2, r1y1);
+               if (top != bot) {
+                   curBand = newReg->data->numRects;
+                   miAppendNonO(newReg, r2, r2BandEnd, top, bot);
+                   Coalesce(newReg, prevBand, curBand);
+               }
+           }
+           ytop = r1y1;
+       } else {
+           ytop = r1y1;
+       }
+
+       /*
+        * Now see if we've hit an intersecting band. The two bands only
+        * intersect if ybot > ytop
+        */
+       ybot = min(r1->y2, r2->y2);
+       if (ybot > ytop) {
+           curBand = newReg->data->numRects;
+           (* overlapFunc)(newReg, r1, r1BandEnd, r2, r2BandEnd, ytop, ybot,
+                           pOverlap);
+           Coalesce(newReg, prevBand, curBand);
+       }
+
+       /*
+        * If we've finished with a band (y2 == ybot) we skip forward
+        * in the region to the next band.
+        */
+       if (r1->y2 == ybot) r1 = r1BandEnd;
+       if (r2->y2 == ybot) r2 = r2BandEnd;
+
+    } while (r1 != r1End && r2 != r2End);
+
+    /*
+     * Deal with whichever region (if any) still has rectangles left.
+     *
+     * We only need to worry about banding and coalescing for the very first
+     * band left.  After that, we can just group all remaining boxes,
+     * regardless of how many bands, into one final append to the list.
+     */
+
+    if ((r1 != r1End) && appendNon1) {
+       /* Do first nonOverlap1Func call, which may be able to coalesce */
+       FindBand(r1, r1BandEnd, r1End, r1y1);
+       curBand = newReg->data->numRects;
+       miAppendNonO(newReg, r1, r1BandEnd, max(r1y1, ybot), r1->y2);
+       Coalesce(newReg, prevBand, curBand);
+       /* Just append the rest of the boxes  */
+       AppendRegions(newReg, r1BandEnd, r1End);
+
+    } else if ((r2 != r2End) && appendNon2) {
+       /* Do first nonOverlap2Func call, which may be able to coalesce */
+       FindBand(r2, r2BandEnd, r2End, r2y1);
+       curBand = newReg->data->numRects;
+       miAppendNonO(newReg, r2, r2BandEnd, max(r2y1, ybot), r2->y2);
+       Coalesce(newReg, prevBand, curBand);
+       /* Append rest of boxes */
+       AppendRegions(newReg, r2BandEnd, r2End);
+    }
+
+    if (oldData)
+       xfree(oldData);
+
+    if (!(numRects = newReg->data->numRects))
+    {
+       xfreeData(newReg);
+       newReg->data = &miEmptyData;
+    }
+    else if (numRects == 1)
+    {
+       newReg->extents = *REGION_BOXPTR(newReg);
+       xfreeData(newReg);
+       newReg->data = (RegDataPtr)NULL;
+    }
+    else
+    {
+       DOWNSIZE(newReg, numRects);
+    }
+
+    return TRUE;
+}
+
+/*-
+ *-----------------------------------------------------------------------
+ * miSetExtents --
+ *     Reset the extents of a region to what they should be. Called by
+ *     miSubtract and miIntersect as they can't figure it out along the
+ *     way or do so easily, as miUnion can.
+ *
+ * Results:
+ *     None.
+ *
+ * Side Effects:
+ *     The region's 'extents' structure is overwritten.
+ *
+ *-----------------------------------------------------------------------
+ */
+void
+miSetExtents (pReg)
+    register RegionPtr pReg;
+{
+    register BoxPtr pBox, pBoxEnd;
+
+    if (!pReg->data)
+       return;
+    if (!pReg->data->size)
+    {
+       pReg->extents.x2 = pReg->extents.x1;
+       pReg->extents.y2 = pReg->extents.y1;
+       return;
+    }
+
+    pBox = REGION_BOXPTR(pReg);
+    pBoxEnd = REGION_END(pReg);
+
+    /*
+     * Since pBox is the first rectangle in the region, it must have the
+     * smallest y1 and since pBoxEnd is the last rectangle in the region,
+     * it must have the largest y2, because of banding. Initialize x1 and
+     * x2 from  pBox and pBoxEnd, resp., as good things to initialize them
+     * to...
+     */
+    pReg->extents.x1 = pBox->x1;
+    pReg->extents.y1 = pBox->y1;
+    pReg->extents.x2 = pBoxEnd->x2;
+    pReg->extents.y2 = pBoxEnd->y2;
+
+    assert(pReg->extents.y1 < pReg->extents.y2);
+    while (pBox <= pBoxEnd) {
+       if (pBox->x1 < pReg->extents.x1)
+           pReg->extents.x1 = pBox->x1;
+       if (pBox->x2 > pReg->extents.x2)
+           pReg->extents.x2 = pBox->x2;
+       pBox++;
+    };
+
+    assert(pReg->extents.x1 < pReg->extents.x2);
+}
+
+/*======================================================================
+ *         Region Intersection
+ *====================================================================*/
+/*-
+ *-----------------------------------------------------------------------
+ * miIntersectO --
+ *     Handle an overlapping band for miIntersect.
+ *
+ * Results:
+ *     TRUE if successful.
+ *
+ * Side Effects:
+ *     Rectangles may be added to the region.
+ *
+ *-----------------------------------------------------------------------
+ */
+/*ARGSUSED*/
+static Bool
+miIntersectO (pReg, r1, r1End, r2, r2End, y1, y2, pOverlap)
+    register RegionPtr pReg;
+    register BoxPtr    r1;
+    BoxPtr             r1End;
+    register BoxPtr    r2;
+    BoxPtr             r2End;
+    short              y1;
+    short              y2;
+    Bool               *pOverlap;
+{
+    register int       x1;
+    register int       x2;
+    register BoxPtr    pNextRect;
+
+    pNextRect = REGION_TOP(pReg);
+
+    assert(y1 < y2);
+    assert(r1 != r1End && r2 != r2End);
+
+    do {
+       x1 = max(r1->x1, r2->x1);
+       x2 = min(r1->x2, r2->x2);
+
+       /*
+        * If there's any overlap between the two rectangles, add that
+        * overlap to the new region.
+        */
+       if (x1 < x2)
+           NEWRECT(pReg, pNextRect, x1, y1, x2, y2);
+
+       /*
+        * Advance the pointer(s) with the leftmost right side, since the next
+        * rectangle on that list may still overlap the other region's
+        * current rectangle.
+        */
+       if (r1->x2 == x2) {
+           r1++;
+       }
+       if (r2->x2 == x2) {
+           r2++;
+       }
+    } while ((r1 != r1End) && (r2 != r2End));
+
+    return TRUE;
+}
+
+
+Bool
+miIntersect(newReg, reg1, reg2)
+    register RegionPtr         newReg;     /* destination Region */
+    register RegionPtr         reg1;
+    register RegionPtr reg2;       /* source regions     */
+{
+    good(reg1);
+    good(reg2);
+    good(newReg);
+   /* check for trivial reject */
+    if (REGION_NIL(reg1)  || REGION_NIL(reg2) ||
+       !EXTENTCHECK(&reg1->extents, &reg2->extents))
+    {
+       /* Covers about 20% of all cases */
+       xfreeData(newReg);
+       newReg->extents.x2 = newReg->extents.x1;
+       newReg->extents.y2 = newReg->extents.y1;
+       newReg->data = &miEmptyData;
+    }
+    else if (!reg1->data && !reg2->data)
+    {
+       /* Covers about 80% of cases that aren't trivially rejected */
+       newReg->extents.x1 = max(reg1->extents.x1, reg2->extents.x1);
+       newReg->extents.y1 = max(reg1->extents.y1, reg2->extents.y1);
+       newReg->extents.x2 = min(reg1->extents.x2, reg2->extents.x2);
+       newReg->extents.y2 = min(reg1->extents.y2, reg2->extents.y2);
+       xfreeData(newReg);
+       newReg->data = (RegDataPtr)NULL;
+    }
+    else if (!reg2->data && SUBSUMES(&reg2->extents, &reg1->extents))
+    {
+       return miRegionCopy(newReg, reg1);
+    }
+    else if (!reg1->data && SUBSUMES(&reg1->extents, &reg2->extents))
+    {
+       return miRegionCopy(newReg, reg2);
+    }
+    else if (reg1 == reg2)
+    {
+       return miRegionCopy(newReg, reg1);
+    }
+    else
+    {
+       /* General purpose intersection */
+       Bool overlap; /* result ignored */
+       if (!miRegionOp(newReg, reg1, reg2, miIntersectO, FALSE, FALSE,
+                       &overlap))
+           return FALSE;
+       miSetExtents(newReg);
+    }
+
+    good(newReg);
+    return(TRUE);
+}
+
+#define MERGERECT(r)                                           \
+{                                                              \
+    if (r->x1 <= x2) {                                         \
+       /* Merge with current rectangle */                      \
+       if (r->x1 < x2) *pOverlap = TRUE;                               \
+       if (x2 < r->x2) x2 = r->x2;                             \
+    } else {                                                   \
+       /* Add current rectangle, start new one */              \
+       NEWRECT(pReg, pNextRect, x1, y1, x2, y2);               \
+       x1 = r->x1;                                             \
+       x2 = r->x2;                                             \
+    }                                                          \
+    r++;                                                       \
+}
+
+/*======================================================================
+ *         Region Union
+ *====================================================================*/
+
+/*-
+ *-----------------------------------------------------------------------
+ * miUnionO --
+ *     Handle an overlapping band for the union operation. Picks the
+ *     left-most rectangle each time and merges it into the region.
+ *
+ * Results:
+ *     TRUE if successful.
+ *
+ * Side Effects:
+ *     pReg is overwritten.
+ *     pOverlap is set to TRUE if any boxes overlap.
+ *
+ *-----------------------------------------------------------------------
+ */
+static Bool
+miUnionO (pReg, r1, r1End, r2, r2End, y1, y2, pOverlap)
+    register RegionPtr pReg;
+    register BoxPtr    r1;
+            BoxPtr     r1End;
+    register BoxPtr    r2;
+            BoxPtr     r2End;
+            short      y1;
+            short      y2;
+            Bool       *pOverlap;
+{
+    register BoxPtr     pNextRect;
+    register int        x1;     /* left and right side of current union */
+    register int        x2;
+
+    assert (y1 < y2);
+    assert(r1 != r1End && r2 != r2End);
+
+    pNextRect = REGION_TOP(pReg);
+
+    /* Start off current rectangle */
+    if (r1->x1 < r2->x1)
+    {
+       x1 = r1->x1;
+       x2 = r1->x2;
+       r1++;
+    }
+    else
+    {
+       x1 = r2->x1;
+       x2 = r2->x2;
+       r2++;
+    }
+    while (r1 != r1End && r2 != r2End)
+    {
+       if (r1->x1 < r2->x1) MERGERECT(r1) else MERGERECT(r2);
+    }
+
+    /* Finish off whoever (if any) is left */
+    if (r1 != r1End)
+    {
+       do
+       {
+           MERGERECT(r1);
+       } while (r1 != r1End);
+    }
+    else if (r2 != r2End)
+    {
+       do
+       {
+           MERGERECT(r2);
+       } while (r2 != r2End);
+    }
+    
+    /* Add current rectangle */
+    NEWRECT(pReg, pNextRect, x1, y1, x2, y2);
+
+    return TRUE;
+}
+
+Bool 
+miUnion(newReg, reg1, reg2)
+    RegionPtr          newReg;                  /* destination Region */
+    register RegionPtr         reg1;
+    register RegionPtr reg2;             /* source regions     */
+{
+    Bool overlap; /* result ignored */
+
+    /* Return TRUE if some overlap between reg1, reg2 */
+    good(reg1);
+    good(reg2);
+    good(newReg);
+    /*  checks all the simple cases */
+
+    /*
+     * Region 1 and 2 are the same
+     */
+    if (reg1 == reg2)
+    {
+       return miRegionCopy(newReg, reg1);
+    }
+
+    /*
+     * Region 1 is empty
+     */
+    if (REGION_NIL(reg1))
+    {
+        if (newReg != reg2)
+           return miRegionCopy(newReg, reg2);
+        return TRUE;
+    }
+
+    /*
+     * Region 2 is empty
+     */
+    if (REGION_NIL(reg2))
+    {
+        if (newReg != reg1)
+           return miRegionCopy(newReg, reg1);
+        return TRUE;
+    }
+
+    /*
+     * Region 1 completely subsumes region 2
+     */
+    if (!reg1->data && SUBSUMES(&reg1->extents, &reg2->extents))
+    {
+        if (newReg != reg1)
+           return miRegionCopy(newReg, reg1);
+        return TRUE;
+    }
+
+    /*
+     * Region 2 completely subsumes region 1
+     */
+    if (!reg2->data && SUBSUMES(&reg2->extents, &reg1->extents))
+    {
+        if (newReg != reg2)
+           return miRegionCopy(newReg, reg2);
+        return TRUE;
+    }
+
+    if (!miRegionOp(newReg, reg1, reg2, miUnionO, TRUE, TRUE, &overlap))
+       return FALSE;
+
+    newReg->extents.x1 = min(reg1->extents.x1, reg2->extents.x1);
+    newReg->extents.y1 = min(reg1->extents.y1, reg2->extents.y1);
+    newReg->extents.x2 = max(reg1->extents.x2, reg2->extents.x2);
+    newReg->extents.y2 = max(reg1->extents.y2, reg2->extents.y2);
+    good(newReg);
+    return TRUE;
+}
+
+
+/*======================================================================
+ *         Batch Rectangle Union
+ *====================================================================*/
+
+/*-
+ *-----------------------------------------------------------------------
+ * miRegionAppend --
+ * 
+ *      "Append" the rgn rectangles onto the end of dstrgn, maintaining
+ *      knowledge of YX-banding when it's easy.  Otherwise, dstrgn just
+ *      becomes a non-y-x-banded random collection of rectangles, and not
+ *      yet a true region.  After a sequence of appends, the caller must
+ *      call miRegionValidate to ensure that a valid region is constructed.
+ *
+ * Results:
+ *     TRUE if successful.
+ *
+ * Side Effects:
+ *      dstrgn is modified if rgn has rectangles.
+ *
+ */
+Bool
+miRegionAppend(dstrgn, rgn)
+    register RegionPtr dstrgn;
+    register RegionPtr rgn;
+{
+    int numRects, dnumRects, size;
+    BoxPtr new, old;
+    Bool prepend;
+
+    if (!rgn->data && (dstrgn->data == &miEmptyData))
+    {
+       dstrgn->extents = rgn->extents;
+       dstrgn->data = (RegDataPtr)NULL;
+       return TRUE;
+    }
+
+    numRects = REGION_NUM_RECTS(rgn);
+    if (!numRects)
+       return TRUE;
+    prepend = FALSE;
+    size = numRects;
+    dnumRects = REGION_NUM_RECTS(dstrgn);
+    if (!dnumRects && (size < 200))
+       size = 200; /* XXX pick numbers out of a hat */
+    RECTALLOC(dstrgn, size);
+    old = REGION_RECTS(rgn);
+    if (!dnumRects)
+       dstrgn->extents = rgn->extents;
+    else if (dstrgn->extents.x2 > dstrgn->extents.x1)
+    {
+       register BoxPtr first, last;
+
+       first = old;
+       last = REGION_BOXPTR(dstrgn) + (dnumRects - 1);
+       if ((first->y1 > last->y2) ||
+           ((first->y1 == last->y1) && (first->y2 == last->y2) &&
+            (first->x1 > last->x2)))
+       {
+           if (rgn->extents.x1 < dstrgn->extents.x1)
+               dstrgn->extents.x1 = rgn->extents.x1;
+           if (rgn->extents.x2 > dstrgn->extents.x2)
+               dstrgn->extents.x2 = rgn->extents.x2;
+           dstrgn->extents.y2 = rgn->extents.y2;
+       }
+       else
+       {
+           first = REGION_BOXPTR(dstrgn);
+           last = old + (numRects - 1);
+           if ((first->y1 > last->y2) ||
+               ((first->y1 == last->y1) && (first->y2 == last->y2) &&
+                (first->x1 > last->x2)))
+           {
+               prepend = TRUE;
+               if (rgn->extents.x1 < dstrgn->extents.x1)
+                   dstrgn->extents.x1 = rgn->extents.x1;
+               if (rgn->extents.x2 > dstrgn->extents.x2)
+                   dstrgn->extents.x2 = rgn->extents.x2;
+               dstrgn->extents.y1 = rgn->extents.y1;
+           }
+           else
+               dstrgn->extents.x2 = dstrgn->extents.x1;
+       }
+    }
+    if (prepend)
+    {
+       new = REGION_BOX(dstrgn, numRects);
+       if (dnumRects == 1)
+           *new = *REGION_BOXPTR(dstrgn);
+       else
+           memmove((char *)new,(char *)REGION_BOXPTR(dstrgn), 
+                 dnumRects * sizeof(BoxRec));
+       new = REGION_BOXPTR(dstrgn);
+    }
+    else
+       new = REGION_BOXPTR(dstrgn) + dnumRects;
+    if (numRects == 1)
+       *new = *old;
+    else
+       memmove((char *)new, (char *)old, numRects * sizeof(BoxRec));
+    dstrgn->data->numRects += numRects;
+    return TRUE;
+}
+
+   
+#define ExchangeRects(a, b) \
+{                          \
+    BoxRec     t;          \
+    t = rects[a];          \
+    rects[a] = rects[b];    \
+    rects[b] = t;          \
+}
+
+static void
+QuickSortRects(rects, numRects)
+    register BoxRec     rects[];
+    register int        numRects;
+{
+    register int       y1;
+    register int       x1;
+    register int        i, j;
+    register BoxPtr     r;
+
+    /* Always called with numRects > 1 */
+
+    do
+    {
+       if (numRects == 2)
+       {
+           if (rects[0].y1 > rects[1].y1 ||
+                   (rects[0].y1 == rects[1].y1 && rects[0].x1 > rects[1].x1))
+               ExchangeRects(0, 1);
+           return;
+       }
+
+       /* Choose partition element, stick in location 0 */
+        ExchangeRects(0, numRects >> 1);
+       y1 = rects[0].y1;
+       x1 = rects[0].x1;
+
+        /* Partition array */
+        i = 0;
+        j = numRects;
+        do
+       {
+           r = &(rects[i]);
+           do
+           {
+               r++;
+               i++;
+            } while (i != numRects &&
+                    (r->y1 < y1 || (r->y1 == y1 && r->x1 < x1)));
+           r = &(rects[j]);
+           do
+           {
+               r--;
+               j--;
+            } while (y1 < r->y1 || (y1 == r->y1 && x1 < r->x1));
+            if (i < j)
+               ExchangeRects(i, j);
+        } while (i < j);
+
+        /* Move partition element back to middle */
+        ExchangeRects(0, j);
+
+       /* Recurse */
+        if (numRects-j-1 > 1)
+           QuickSortRects(&rects[j+1], numRects-j-1);
+        numRects = j;
+    } while (numRects > 1);
+}
+
+/*-
+ *-----------------------------------------------------------------------
+ * miRegionValidate --
+ * 
+ *      Take a ``region'' which is a non-y-x-banded random collection of
+ *      rectangles, and compute a nice region which is the union of all the
+ *      rectangles.
+ *
+ * Results:
+ *     TRUE if successful.
+ *
+ * Side Effects:
+ *      The passed-in ``region'' may be modified.
+ *     pOverlap set to TRUE if any retangles overlapped, else FALSE;
+ *
+ * Strategy:
+ *      Step 1. Sort the rectangles into ascending order with primary key y1
+ *             and secondary key x1.
+ *
+ *      Step 2. Split the rectangles into the minimum number of proper y-x
+ *             banded regions.  This may require horizontally merging
+ *             rectangles, and vertically coalescing bands.  With any luck,
+ *             this step in an identity tranformation (ala the Box widget),
+ *             or a coalescing into 1 box (ala Menus).
+ *
+ *     Step 3. Merge the separate regions down to a single region by calling
+ *             miUnion.  Maximize the work each miUnion call does by using
+ *             a binary merge.
+ *
+ *-----------------------------------------------------------------------
+ */
+
+Bool
+miRegionValidate(badreg, pOverlap)
+    RegionPtr badreg;
+    Bool *pOverlap;
+{
+    /* Descriptor for regions under construction  in Step 2. */
+    typedef struct {
+       RegionRec   reg;
+       int         prevBand;
+       int         curBand;
+    } RegionInfo;
+
+            int        numRects;   /* Original numRects for badreg         */
+            RegionInfo *ri;        /* Array of current regions             */
+            int        numRI;      /* Number of entries used in ri         */
+            int        sizeRI;     /* Number of entries available in ri    */
+            int        i;          /* Index into rects                     */
+    register int       j;          /* Index into ri                        */
+    register RegionInfo *rit;       /* &ri[j]                              */
+    register RegionPtr  reg;        /* ri[j].reg                           */
+    register BoxPtr    box;        /* Current box in rects                 */
+    register BoxPtr    riBox;      /* Last box in ri[j].reg                */
+    register RegionPtr  hreg;       /* ri[j_half].reg                      */
+
+    *pOverlap = FALSE;
+    if (!badreg->data)
+    {
+       good(badreg);
+       return TRUE;
+    }
+    numRects = badreg->data->numRects;
+    if (!numRects)
+    {
+       good(badreg);
+       return TRUE;
+    }
+    if (badreg->extents.x1 < badreg->extents.x2)
+    {
+       if ((numRects) == 1)
+       {
+           xfreeData(badreg);
+           badreg->data = (RegDataPtr) NULL;
+       }
+       else
+       {
+           DOWNSIZE(badreg, numRects);
+       }
+       good(badreg);
+       return TRUE;
+    }
+
+    /* Step 1: Sort the rects array into ascending (y1, x1) order */
+    QuickSortRects(REGION_BOXPTR(badreg), numRects);
+
+    /* Step 2: Scatter the sorted array into the minimum number of regions */
+
+    /* Set up the first region to be the first rectangle in badreg */
+    /* Note that step 2 code will never overflow the ri[0].reg rects array */
+    Must_have_memory = TRUE; /* XXX */
+    ri = (RegionInfo *) xalloc(4 * sizeof(RegionInfo));
+    Must_have_memory = FALSE; /* XXX */
+    sizeRI = 4;
+    numRI = 1;
+    ri[0].prevBand = 0;
+    ri[0].curBand = 0;
+    ri[0].reg = *badreg;
+    box = REGION_BOXPTR(&ri[0].reg);
+    ri[0].reg.extents = *box;
+    ri[0].reg.data->numRects = 1;
+
+    /* Now scatter rectangles into the minimum set of valid regions.  If the
+       next rectangle to be added to a region would force an existing rectangle
+       in the region to be split up in order to maintain y-x banding, just
+       forget it.  Try the next region.  If it doesn't fit cleanly into any
+       region, make a new one. */
+
+    for (i = numRects; --i > 0;)
+    {
+       box++;
+       /* Look for a region to append box to */
+       for (j = numRI, rit = ri; --j >= 0; rit++)
+       {
+           reg = &rit->reg;
+           riBox = REGION_END(reg);
+
+           if (box->y1 == riBox->y1 && box->y2 == riBox->y2)
+           {
+               /* box is in same band as riBox.  Merge or append it */
+               if (box->x1 <= riBox->x2)
+               {
+                   /* Merge it with riBox */
+                   if (box->x1 < riBox->x2) *pOverlap = TRUE;
+                   if (box->x2 > riBox->x2) riBox->x2 = box->x2;
+               }
+               else
+               {
+                   RECTALLOC(reg, 1);
+                   *REGION_TOP(reg) = *box;
+                   reg->data->numRects++;
+               }
+               goto NextRect;   /* So sue me */
+           }
+           else if (box->y1 >= riBox->y2)
+           {
+               /* Put box into new band */
+               if (reg->extents.x2 < riBox->x2) reg->extents.x2 = riBox->x2;
+               if (reg->extents.x1 > box->x1)   reg->extents.x1 = box->x1;
+               Coalesce(reg, rit->prevBand, rit->curBand);
+               rit->curBand = reg->data->numRects;
+               RECTALLOC(reg, 1);
+               *REGION_TOP(reg) = *box;
+               reg->data->numRects++;
+               goto NextRect;
+           }
+           /* Well, this region was inappropriate.  Try the next one. */
+       } /* for j */
+
+       /* Uh-oh.  No regions were appropriate.  Create a new one. */
+       if (sizeRI == numRI)
+       {
+           /* Oops, allocate space for new region information */
+           sizeRI <<= 1;
+           Must_have_memory = TRUE; /* XXX */
+           ri = (RegionInfo *) xrealloc(ri, sizeRI * sizeof(RegionInfo));
+           Must_have_memory = FALSE; /* XXX */
+           rit = &ri[numRI];
+       }
+       numRI++;
+       rit->prevBand = 0;
+       rit->curBand = 0;
+       rit->reg.extents = *box;
+       rit->reg.data = (RegDataPtr)NULL;
+       miRectAlloc(&rit->reg, (i+numRI) / numRI); /* MUST force allocation */
+NextRect: ;
+    } /* for i */
+
+    /* Make a final pass over each region in order to Coalesce and set
+       extents.x2 and extents.y2 */
+
+    for (j = numRI, rit = ri; --j >= 0; rit++)
+    {
+       reg = &rit->reg;
+       riBox = REGION_END(reg);
+       reg->extents.y2 = riBox->y2;
+       if (reg->extents.x2 < riBox->x2) reg->extents.x2 = riBox->x2;
+       Coalesce(reg, rit->prevBand, rit->curBand);
+       if (reg->data->numRects == 1) /* keep unions happy below */
+       {
+           xfreeData(reg);
+           reg->data = (RegDataPtr)NULL;
+       }
+    }
+
+    /* Step 3: Union all regions into a single region */
+    while (numRI > 1)
+    {
+       int half = numRI/2;
+       for (j = numRI & 1; j < (half + (numRI & 1)); j++)
+       {
+           reg = &ri[j].reg;
+           hreg = &ri[j+half].reg;
+           miRegionOp(reg, reg, hreg, miUnionO, TRUE, TRUE, pOverlap);
+           if (hreg->extents.x1 < reg->extents.x1)
+               reg->extents.x1 = hreg->extents.x1;
+           if (hreg->extents.y1 < reg->extents.y1)
+               reg->extents.y1 = hreg->extents.y1;
+           if (hreg->extents.x2 > reg->extents.x2)
+               reg->extents.x2 = hreg->extents.x2;
+           if (hreg->extents.y2 > reg->extents.y2)
+               reg->extents.y2 = hreg->extents.y2;
+           xfreeData(hreg);
+       }
+       numRI -= half;
+    }
+    *badreg = ri[0].reg;
+    xfree(ri);
+    good(badreg);
+    return TRUE;
+}
+
+RegionPtr
+miRectsToRegion(nrects, prect, ctype)
+    int                        nrects;
+    register xRectangle        *prect;
+    int                        ctype;
+{
+    register RegionPtr pRgn;
+    register RegDataPtr        pData;
+    register BoxPtr    pBox;
+    register int        i;
+    int                        x1, y1, x2, y2;
+
+    pRgn = miRegionCreate(NullBox, 0);
+    if (!nrects)
+       return pRgn;
+    if (nrects == 1)
+    {
+       x1 = prect->x;
+       y1 = prect->y;
+       if ((x2 = x1 + (int) prect->width) > MAXSHORT)
+           x2 = MAXSHORT;
+       if ((y2 = y1 + (int) prect->height) > MAXSHORT)
+           y2 = MAXSHORT;
+       if (x1 != x2 && y1 != y2)
+       {
+           pRgn->extents.x1 = x1;
+           pRgn->extents.y1 = y1;
+           pRgn->extents.x2 = x2;
+           pRgn->extents.y2 = y2;
+           pRgn->data = (RegDataPtr)NULL;
+       }
+       return pRgn;
+    }
+    Must_have_memory = TRUE; /* XXX */
+    pData = xallocData(nrects);
+    pBox = (BoxPtr) (pData + 1);
+    Must_have_memory = FALSE; /* XXX */
+    for (i = nrects; --i >= 0; prect++)
+    {
+       x1 = prect->x;
+       y1 = prect->y;
+       if ((x2 = x1 + (int) prect->width) > MAXSHORT)
+           x2 = MAXSHORT;
+       if ((y2 = y1 + (int) prect->height) > MAXSHORT)
+           y2 = MAXSHORT;
+       if (x1 != x2 && y1 != y2)
+       {
+           pBox->x1 = x1;
+           pBox->y1 = y1;
+           pBox->x2 = x2;
+           pBox->y2 = y2;
+           pBox++;
+       }
+    }
+    if (pBox != (BoxPtr) (pData + 1))
+    {
+       pData->size = nrects;
+       pData->numRects = pBox - (BoxPtr) (pData + 1);
+       pRgn->data = pData;
+       if (ctype != CT_YXBANDED)
+       {
+           Bool overlap; /* result ignored */
+           pRgn->extents.x1 = pRgn->extents.x2 = 0;
+           miRegionValidate(pRgn, &overlap);
+       }
+       else
+           miSetExtents(pRgn);
+       good(pRgn);
+    }
+    else
+    {
+       xfree (pData);
+    }
+    return pRgn;
+}
+
+/*======================================================================
+ *               Region Subtraction
+ *====================================================================*/
+
+
+/*-
+ *-----------------------------------------------------------------------
+ * miSubtractO --
+ *     Overlapping band subtraction. x1 is the left-most point not yet
+ *     checked.
+ *
+ * Results:
+ *     TRUE if successful.
+ *
+ * Side Effects:
+ *     pReg may have rectangles added to it.
+ *
+ *-----------------------------------------------------------------------
+ */
+/*ARGSUSED*/
+static Bool
+miSubtractO (pReg, r1, r1End, r2, r2End, y1, y2, pOverlap)
+    register RegionPtr pReg;
+    register BoxPtr    r1;
+    BoxPtr             r1End;
+    register BoxPtr    r2;
+    BoxPtr             r2End;
+    register int       y1;
+             int       y2;
+    Bool               *pOverlap;
+{
+    register BoxPtr    pNextRect;
+    register int       x1;
+
+    x1 = r1->x1;
+    
+    assert(y1<y2);
+    assert(r1 != r1End && r2 != r2End);
+
+    pNextRect = REGION_TOP(pReg);
+
+    do
+    {
+       if (r2->x2 <= x1)
+       {
+           /*
+            * Subtrahend entirely to left of minuend: go to next subtrahend.
+            */
+           r2++;
+       }
+       else if (r2->x1 <= x1)
+       {
+           /*
+            * Subtrahend preceeds minuend: nuke left edge of minuend.
+            */
+           x1 = r2->x2;
+           if (x1 >= r1->x2)
+           {
+               /*
+                * Minuend completely covered: advance to next minuend and
+                * reset left fence to edge of new minuend.
+                */
+               r1++;
+               if (r1 != r1End)
+                   x1 = r1->x1;
+           }
+           else
+           {
+               /*
+                * Subtrahend now used up since it doesn't extend beyond
+                * minuend
+                */
+               r2++;
+           }
+       }
+       else if (r2->x1 < r1->x2)
+       {
+           /*
+            * Left part of subtrahend covers part of minuend: add uncovered
+            * part of minuend to region and skip to next subtrahend.
+            */
+           assert(x1<r2->x1);
+           NEWRECT(pReg, pNextRect, x1, y1, r2->x1, y2);
+
+           x1 = r2->x2;
+           if (x1 >= r1->x2)
+           {
+               /*
+                * Minuend used up: advance to new...
+                */
+               r1++;
+               if (r1 != r1End)
+                   x1 = r1->x1;
+           }
+           else
+           {
+               /*
+                * Subtrahend used up
+                */
+               r2++;
+           }
+       }
+       else
+       {
+           /*
+            * Minuend used up: add any remaining piece before advancing.
+            */
+           if (r1->x2 > x1)
+               NEWRECT(pReg, pNextRect, x1, y1, r1->x2, y2);
+           r1++;
+           if (r1 != r1End)
+               x1 = r1->x1;
+       }
+    } while ((r1 != r1End) && (r2 != r2End));
+
+
+    /*
+     * Add remaining minuend rectangles to region.
+     */
+    while (r1 != r1End)
+    {
+       assert(x1<r1->x2);
+       NEWRECT(pReg, pNextRect, x1, y1, r1->x2, y2);
+       r1++;
+       if (r1 != r1End)
+           x1 = r1->x1;
+    }
+    return TRUE;
+}
+       
+/*-
+ *-----------------------------------------------------------------------
+ * miSubtract --
+ *     Subtract regS from regM and leave the result in regD.
+ *     S stands for subtrahend, M for minuend and D for difference.
+ *
+ * Results:
+ *     TRUE if successful.
+ *
+ * Side Effects:
+ *     regD is overwritten.
+ *
+ *-----------------------------------------------------------------------
+ */
+Bool
+miSubtract(regD, regM, regS)
+    register RegionPtr regD;               
+    register RegionPtr         regM;
+    register RegionPtr regS;          
+{
+    Bool overlap; /* result ignored */
+
+    good(regM);
+    good(regS);
+    good(regD);
+   /* check for trivial rejects */
+    if (REGION_NIL(regM) || REGION_NIL(regS) ||
+       !EXTENTCHECK(&regM->extents, &regS->extents))
+    {
+       return miRegionCopy(regD, regM);
+    }
+    else if (regM == regS)
+    {
+       xfreeData(regD);
+       regD->extents.x2 = regD->extents.x1;
+       regD->extents.y2 = regD->extents.y1;
+       regD->data = &miEmptyData;
+       return TRUE;
+    }
+    /* Add those rectangles in region 1 that aren't in region 2,
+       do yucky substraction for overlaps, and
+       just throw away rectangles in region 2 that aren't in region 1 */
+    if (!miRegionOp(regD, regM, regS, miSubtractO, TRUE, FALSE, &overlap))
+       return FALSE;
+
+    /*
+     * Can't alter RegD's extents before we call miRegionOp because
+     * it might be one of the source regions and miRegionOp depends
+     * on the extents of those regions being unaltered. Besides, this
+     * way there's no checking against rectangles that will be nuked
+     * due to coalescing, so we have to examine fewer rectangles.
+     */
+    miSetExtents(regD);
+    good(regD);
+    return TRUE;
+}
+
+/*======================================================================
+ *         Region Inversion
+ *====================================================================*/
+
+/*-
+ *-----------------------------------------------------------------------
+ * miInverse --
+ *     Take a region and a box and return a region that is everything
+ *     in the box but not in the region. The careful reader will note
+ *     that this is the same as subtracting the region from the box...
+ *
+ * Results:
+ *     TRUE.
+ *
+ * Side Effects:
+ *     newReg is overwritten.
+ *
+ *-----------------------------------------------------------------------
+ */
+Bool
+miInverse(newReg, reg1, invRect)
+    RegionPtr    newReg;       /* Destination region */
+    RegionPtr    reg1;         /* Region to invert */
+    BoxPtr               invRect;      /* Bounding box for inversion */
+{
+    RegionRec    invReg;       /* Quick and dirty region made from the
+                                * bounding box */
+    Bool         overlap;      /* result ignored */
+
+    good(reg1);
+    good(newReg);
+   /* check for trivial rejects */
+    if (REGION_NIL(reg1) || !EXTENTCHECK(invRect, &reg1->extents))
+    {
+       newReg->extents = *invRect;
+       xfreeData(newReg);
+       newReg->data = (RegDataPtr)NULL;
+        return TRUE;
+    }
+
+    /* Add those rectangles in region 1 that aren't in region 2,
+       do yucky substraction for overlaps, and
+       just throw away rectangles in region 2 that aren't in region 1 */
+    invReg.extents = *invRect;
+    invReg.data = (RegDataPtr)NULL;
+    if (!miRegionOp(newReg, &invReg, reg1, miSubtractO, TRUE, FALSE, &overlap))
+       return FALSE;
+
+    /*
+     * Can't alter newReg's extents before we call miRegionOp because
+     * it might be one of the source regions and miRegionOp depends
+     * on the extents of those regions being unaltered. Besides, this
+     * way there's no checking against rectangles that will be nuked
+     * due to coalescing, so we have to examine fewer rectangles.
+     */
+    miSetExtents(newReg);
+    good(newReg);
+    return TRUE;
+}
+
+/*
+ *   RectIn(region, rect)
+ *   This routine takes a pointer to a region and a pointer to a box
+ *   and determines if the box is outside/inside/partly inside the region.
+ *
+ *   The idea is to travel through the list of rectangles trying to cover the
+ *   passed box with them. Anytime a piece of the rectangle isn't covered
+ *   by a band of rectangles, partOut is set TRUE. Any time a rectangle in
+ *   the region covers part of the box, partIn is set TRUE. The process ends
+ *   when either the box has been completely covered (we reached a band that
+ *   doesn't overlap the box, partIn is TRUE and partOut is false), the
+ *   box has been partially covered (partIn == partOut == TRUE -- because of
+ *   the banding, the first time this is true we know the box is only
+ *   partially in the region) or is outside the region (we reached a band
+ *   that doesn't overlap the box at all and partIn is false)
+ */
+
+int
+miRectIn(region, prect)
+    register RegionPtr  region;
+    register BoxPtr     prect;
+{
+    register int       x;
+    register int       y;
+    register BoxPtr     pbox;
+    register BoxPtr     pboxEnd;
+    int                        partIn, partOut;
+    int                        numRects;
+
+    good(region);
+    numRects = REGION_NUM_RECTS(region);
+    /* useful optimization */
+    if (!numRects || !EXTENTCHECK(&region->extents, prect))
+        return(rgnOUT);
+
+    if (numRects == 1)
+    {
+       /* We know that it must be rgnIN or rgnPART */
+       if (SUBSUMES(&region->extents, prect))
+           return(rgnIN);
+       else
+           return(rgnPART);
+    }
+
+    partOut = FALSE;
+    partIn = FALSE;
+
+    /* (x,y) starts at upper left of rect, moving to the right and down */
+    x = prect->x1;
+    y = prect->y1;
+
+    /* can stop when both partOut and partIn are TRUE, or we reach prect->y2 */
+    for (pbox = REGION_BOXPTR(region), pboxEnd = pbox + numRects;
+         pbox != pboxEnd;
+         pbox++)
+    {
+
+        if (pbox->y2 <= y)
+           continue;    /* getting up to speed or skipping remainder of band */
+
+        if (pbox->y1 > y)
+        {
+           partOut = TRUE;      /* missed part of rectangle above */
+           if (partIn || (pbox->y1 >= prect->y2))
+              break;
+           y = pbox->y1;        /* x guaranteed to be == prect->x1 */
+        }
+
+        if (pbox->x2 <= x)
+           continue;            /* not far enough over yet */
+
+        if (pbox->x1 > x)
+        {
+           partOut = TRUE;      /* missed part of rectangle to left */
+           if (partIn)
+              break;
+        }
+
+        if (pbox->x1 < prect->x2)
+        {
+            partIn = TRUE;      /* definitely overlap */
+            if (partOut)
+               break;
+        }
+
+        if (pbox->x2 >= prect->x2)
+        {
+           y = pbox->y2;        /* finished with this band */
+           if (y >= prect->y2)
+              break;
+           x = prect->x1;       /* reset x out to left again */
+        }
+       else
+       {
+           /*
+            * Because boxes in a band are maximal width, if the first box
+            * to overlap the rectangle doesn't completely cover it in that
+            * band, the rectangle must be partially out, since some of it
+            * will be uncovered in that band. partIn will have been set true
+            * by now...
+            */
+           partOut = TRUE;
+           break;
+       }
+    }
+
+    return(partIn ? ((y < prect->y2) ? rgnPART : rgnIN) : rgnOUT);
+}
+
+/* TranslateRegion(pReg, x, y)
+   translates in place
+*/
+
+void
+miTranslateRegion(pReg, x, y)
+    register RegionPtr pReg;
+    register int x;
+    register int y;
+{
+    int x1, x2, y1, y2;
+    register int nbox;
+    register BoxPtr pbox;
+
+    good(pReg);
+    pReg->extents.x1 = x1 = pReg->extents.x1 + x;
+    pReg->extents.y1 = y1 = pReg->extents.y1 + y;
+    pReg->extents.x2 = x2 = pReg->extents.x2 + x;
+    pReg->extents.y2 = y2 = pReg->extents.y2 + y;
+    if (((x1 - MINSHORT)|(y1 - MINSHORT)|(MAXSHORT - x2)|(MAXSHORT - y2)) >= 0)
+    {
+       if (pReg->data && (nbox = pReg->data->numRects))
+       {
+           for (pbox = REGION_BOXPTR(pReg); nbox--; pbox++)
+           {
+               pbox->x1 += x;
+               pbox->y1 += y;
+               pbox->x2 += x;
+               pbox->y2 += y;
+           }
+       }
+       return;
+    }
+    if (((x2 - MINSHORT)|(y2 - MINSHORT)|(MAXSHORT - x1)|(MAXSHORT - y1)) <= 0)
+    {
+       pReg->extents.x2 = pReg->extents.x1;
+       pReg->extents.y2 = pReg->extents.y1;
+       xfreeData(pReg);
+       pReg->data = &miEmptyData;
+       return;
+    }
+    if (x1 < MINSHORT)
+       pReg->extents.x1 = MINSHORT;
+    else if (x2 > MAXSHORT)
+       pReg->extents.x2 = MAXSHORT;
+    if (y1 < MINSHORT)
+       pReg->extents.y1 = MINSHORT;
+    else if (y2 > MAXSHORT)
+       pReg->extents.y2 = MAXSHORT;
+    if (pReg->data && (nbox = pReg->data->numRects))
+    {
+       register BoxPtr pboxout;
+
+       for (pboxout = pbox = REGION_BOXPTR(pReg); nbox--; pbox++)
+       {
+           pboxout->x1 = x1 = pbox->x1 + x;
+           pboxout->y1 = y1 = pbox->y1 + y;
+           pboxout->x2 = x2 = pbox->x2 + x;
+           pboxout->y2 = y2 = pbox->y2 + y;
+           if (((x2 - MINSHORT)|(y2 - MINSHORT)|
+                (MAXSHORT - x1)|(MAXSHORT - y1)) <= 0)
+           {
+               pReg->data->numRects--;
+               continue;
+           }
+           if (x1 < MINSHORT)
+               pboxout->x1 = MINSHORT;
+           else if (x2 > MAXSHORT)
+               pboxout->x2 = MAXSHORT;
+           if (y1 < MINSHORT)
+               pboxout->y1 = MINSHORT;
+           else if (y2 > MAXSHORT)
+               pboxout->y2 = MAXSHORT;
+           pboxout++;
+       }
+       if (pboxout != pbox)
+       {
+           if (pReg->data->numRects == 1)
+           {
+               pReg->extents = *REGION_BOXPTR(pReg);
+               xfreeData(pReg);
+               pReg->data = (RegDataPtr)NULL;
+           }
+           else
+               miSetExtents(pReg);
+       }
+    }
+}
+
+void
+miRegionReset(pReg, pBox)
+    RegionPtr pReg;
+    BoxPtr pBox;
+{
+    good(pReg);
+    assert(pBox->x1<=pBox->x2);
+    assert(pBox->y1<=pBox->y2);
+    pReg->extents = *pBox;
+    xfreeData(pReg);
+    pReg->data = (RegDataPtr)NULL;
+}
+
+Bool
+miPointInRegion(pReg, x, y, box)
+    register RegionPtr pReg;
+    register int x, y;
+    BoxPtr box;     /* "return" value */
+{
+    register BoxPtr pbox, pboxEnd;
+    int numRects;
+
+    good(pReg);
+    numRects = REGION_NUM_RECTS(pReg);
+    if (!numRects || !INBOX(&pReg->extents, x, y))
+        return(FALSE);
+    if (numRects == 1)
+    {
+       *box = pReg->extents;
+       return(TRUE);
+    }
+    for (pbox = REGION_BOXPTR(pReg), pboxEnd = pbox + numRects;
+        pbox != pboxEnd;
+        pbox++)
+    {
+        if (y >= pbox->y2)
+          continue;            /* not there yet */
+       if ((y < pbox->y1) || (x < pbox->x1))
+          break;               /* missed it */
+       if (x >= pbox->x2)
+          continue;            /* not there yet */
+       *box = *pbox;
+       return(TRUE);
+    }
+    return(FALSE);
+}
+
+Bool
+miRegionNotEmpty(pReg)
+    RegionPtr pReg;
+{
+    good(pReg);
+    return(!REGION_NIL(pReg));
+}
+
+
+void
+miRegionEmpty(pReg)
+    RegionPtr pReg;
+{
+    good(pReg);
+    xfreeData(pReg);
+    pReg->extents.x2 = pReg->extents.x1;
+    pReg->extents.y2 = pReg->extents.y1;
+    pReg->data = &miEmptyData;
+}
+
+BoxPtr
+miRegionExtents(pReg)
+    RegionPtr pReg;
+{
+    good(pReg);
+    return(&pReg->extents);
+}
+
+#define ExchangeSpans(a, b)                                \
+{                                                          \
+    DDXPointRec     tpt;                                   \
+    register int    tw;                                            \
+                                                           \
+    tpt = spans[a]; spans[a] = spans[b]; spans[b] = tpt;    \
+    tw = widths[a]; widths[a] = widths[b]; widths[b] = tw;  \
+}
+
+/* ||| I should apply the merge sort code to rectangle sorting above, and see
+   if mapping time can be improved.  But right now I've been at work 12 hours,
+   so forget it.
+*/
+
+static void QuickSortSpans(spans, widths, numSpans)
+    register DDXPointRec    spans[];
+    register int           widths[];
+    register int           numSpans;
+{
+    register int           y;
+    register int           i, j, m;
+    register DDXPointPtr    r;
+
+    /* Always called with numSpans > 1 */
+    /* Sorts only by y, doesn't bother to sort by x */
+
+    do
+    {
+       if (numSpans < 9)
+       {
+           /* Do insertion sort */
+           register int yprev;
+
+           yprev = spans[0].y;
+           i = 1;
+           do
+           { /* while i != numSpans */
+               y = spans[i].y;
+               if (yprev > y)
+               {
+                   /* spans[i] is out of order.  Move into proper location. */
+                   DDXPointRec tpt;
+                   int     tw, k;
+
+                   for (j = 0; y >= spans[j].y; j++) {}
+                   tpt = spans[i];
+                   tw  = widths[i];
+                   for (k = i; k != j; k--)
+                   {
+                       spans[k] = spans[k-1];
+                       widths[k] = widths[k-1];
+                   }
+                   spans[j] = tpt;
+                   widths[j] = tw;
+                   y = spans[i].y;
+               } /* if out of order */
+               yprev = y;
+               i++;
+           } while (i != numSpans);
+           return;
+       }
+
+       /* Choose partition element, stick in location 0 */
+       m = numSpans / 2;
+       if (spans[m].y > spans[0].y)            ExchangeSpans(m, 0);
+       if (spans[m].y > spans[numSpans-1].y)   ExchangeSpans(m, numSpans-1);
+       if (spans[m].y > spans[0].y)            ExchangeSpans(m, 0);
+       y = spans[0].y;
+
+        /* Partition array */
+        i = 0;
+        j = numSpans;
+        do
+       {
+           r = &(spans[i]);
+           do
+           {
+               r++;
+               i++;
+            } while (i != numSpans && r->y < y);
+           r = &(spans[j]);
+           do
+           {
+               r--;
+               j--;
+            } while (y < r->y);
+            if (i < j)
+               ExchangeSpans(i, j);
+        } while (i < j);
+
+        /* Move partition element back to middle */
+        ExchangeSpans(0, j);
+
+       /* Recurse */
+        if (numSpans-j-1 > 1)
+           QuickSortSpans(&spans[j+1], &widths[j+1], numSpans-j-1);
+        numSpans = j;
+    } while (numSpans > 1);
+}
+
+#define NextBand()                                                 \
+{                                                                  \
+    clipy1 = pboxBandStart->y1;                                            \
+    clipy2 = pboxBandStart->y2;                                            \
+    pboxBandEnd = pboxBandStart + 1;                               \
+    while (pboxBandEnd != pboxLast && pboxBandEnd->y1 == clipy1) {  \
+       pboxBandEnd++;                                              \
+    }                                                              \
+    for (; ppt != pptLast && ppt->y < clipy1; ppt++, pwidth++) {} \
+}
+
+/*
+    Clip a list of scanlines to a region.  The caller has allocated the
+    space.  FSorted is non-zero if the scanline origins are in ascending
+    order.
+    returns the number of new, clipped scanlines.
+*/
+
+int
+miClipSpans(prgnDst, ppt, pwidth, nspans, pptNew, pwidthNew, fSorted)
+    RegionPtr              prgnDst;
+    register DDXPointPtr    ppt;
+    register int           *pwidth;
+    int                            nspans;
+    register DDXPointPtr    pptNew;
+    int                            *pwidthNew;
+    int                            fSorted;
+{
+    register DDXPointPtr pptLast;
+    int                        *pwidthNewStart;        /* the vengeance of Xerox! */
+    register int       y, x1, x2;
+    register int       numRects;
+
+    good(prgnDst);
+    pptLast = ppt + nspans;
+    pwidthNewStart = pwidthNew;
+
+    if (!prgnDst->data)
+    {
+       /* Do special fast code with clip boundaries in registers(?) */
+       /* It doesn't pay much to make use of fSorted in this case, 
+          so we lump everything together. */
+
+       register    int clipx1, clipx2, clipy1, clipy2;
+
+       clipx1 = prgnDst->extents.x1;
+       clipy1 = prgnDst->extents.y1;
+       clipx2 = prgnDst->extents.x2;
+       clipy2 = prgnDst->extents.y2;
+           
+       for (; ppt != pptLast; ppt++, pwidth++)
+       {
+           y = ppt->y;
+           x1 = ppt->x;
+           if (clipy1 <= y && y < clipy2)
+           {
+               x2 = x1 + *pwidth;
+               if (x1 < clipx1)    x1 = clipx1;
+               if (x2 > clipx2)    x2 = clipx2;
+               if (x1 < x2)
+               {
+                   /* part of span in clip rectangle */
+                   pptNew->x = x1;
+                   pptNew->y = y;
+                   *pwidthNew = x2 - x1;
+                   pptNew++;
+                   pwidthNew++;
+               }
+           }
+       } /* end for */
+
+    }
+    else if (numRects = prgnDst->data->numRects)
+    {
+       /* Have to clip against many boxes */
+       BoxPtr          pboxBandStart, pboxBandEnd;
+       register BoxPtr pbox;
+       register BoxPtr pboxLast;
+       register int    clipy1, clipy2;
+
+       /* In this case, taking advantage of sorted spans gains more than
+          the sorting costs. */
+       if ((! fSorted) && (nspans > 1))
+           QuickSortSpans(ppt, pwidth, nspans);
+
+       pboxBandStart = REGION_BOXPTR(prgnDst);
+       pboxLast = pboxBandStart + numRects;
+    
+       NextBand();
+
+       for (; ppt != pptLast; )
+       {
+           y = ppt->y;
+           if (y < clipy2)
+           {
+               /* span is in the current band */
+               pbox = pboxBandStart;
+               x1 = ppt->x;
+               x2 = x1 + *pwidth;
+               do
+               { /* For each box in band */
+                   register int    newx1, newx2;
+
+                   newx1 = x1;
+                   newx2 = x2;
+                   if (newx1 < pbox->x1)   newx1 = pbox->x1;
+                   if (newx2 > pbox->x2)   newx2 = pbox->x2;
+                   if (newx1 < newx2)
+                   {
+                       /* Part of span in clip rectangle */
+                       pptNew->x = newx1;
+                       pptNew->y = y;
+                       *pwidthNew = newx2 - newx1;
+                       pptNew++;
+                       pwidthNew++;
+                   }
+                   pbox++;
+               } while (pbox != pboxBandEnd);
+               ppt++;
+               pwidth++;
+           }
+           else
+           {
+               /* Move to next band, adjust ppt as needed */
+               pboxBandStart = pboxBandEnd;
+               if (pboxBandStart == pboxLast)
+                   break; /* We're completely done */
+               NextBand();
+           }
+       }
+    }
+    return (pwidthNew - pwidthNewStart);
+}
+
+/* find the band in a region with the most rectangles */
+int
+miFindMaxBand(prgn)
+    RegionPtr prgn;
+{
+    register int nbox;
+    register BoxPtr pbox;
+    register int nThisBand;
+    register int nMaxBand = 0;
+    short yThisBand;
+
+    good(prgn);
+    nbox = REGION_NUM_RECTS(prgn);
+    pbox = REGION_RECTS(prgn);
+
+    while(nbox > 0)
+    {
+       yThisBand = pbox->y1;
+       nThisBand = 0;
+       while((nbox > 0) && (pbox->y1 == yThisBand))
+       {
+           nbox--;
+           pbox++;
+           nThisBand++;
+       }
+       if (nThisBand > nMaxBand)
+           nMaxBand = nThisBand;
+    }
+    return (nMaxBand);
+}
diff --git a/Xserver/programs/Xserver/mi/miscanfill.h b/Xserver/programs/Xserver/mi/miscanfill.h
new file mode 100644 (file)
index 0000000..bb6a5ca
--- /dev/null
@@ -0,0 +1,146 @@
+/* $XConsortium: miscanfill.h,v 1.5 94/04/17 20:27:50 dpw Exp $ */
+/*
+
+Copyright (c) 1987  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be included
+in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR
+OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall
+not be used in advertising or otherwise to promote the sale, use or
+other dealings in this Software without prior written authorization
+from the X Consortium.
+
+*/
+
+
+#ifndef SCANFILLINCLUDED
+#define SCANFILLINCLUDED
+/*
+ *     scanfill.h
+ *
+ *     Written by Brian Kelleher; Jan 1985
+ *
+ *     This file contains a few macros to help track
+ *     the edge of a filled object.  The object is assumed
+ *     to be filled in scanline order, and thus the
+ *     algorithm used is an extension of Bresenham's line
+ *     drawing algorithm which assumes that y is always the
+ *     major axis.
+ *     Since these pieces of code are the same for any filled shape,
+ *     it is more convenient to gather the library in one
+ *     place, but since these pieces of code are also in
+ *     the inner loops of output primitives, procedure call
+ *     overhead is out of the question.
+ *     See the author for a derivation if needed.
+ */
+\f
+
+/*
+ *  In scan converting polygons, we want to choose those pixels
+ *  which are inside the polygon.  Thus, we add .5 to the starting
+ *  x coordinate for both left and right edges.  Now we choose the
+ *  first pixel which is inside the pgon for the left edge and the
+ *  first pixel which is outside the pgon for the right edge.
+ *  Draw the left pixel, but not the right.
+ *
+ *  How to add .5 to the starting x coordinate:
+ *      If the edge is moving to the right, then subtract dy from the
+ *  error term from the general form of the algorithm.
+ *      If the edge is moving to the left, then add dy to the error term.
+ *
+ *  The reason for the difference between edges moving to the left
+ *  and edges moving to the right is simple:  If an edge is moving
+ *  to the right, then we want the algorithm to flip immediately.
+ *  If it is moving to the left, then we don't want it to flip until
+ *  we traverse an entire pixel.
+ */
+#define BRESINITPGON(dy, x1, x2, xStart, d, m, m1, incr1, incr2) { \
+    int dx;      /* local storage */ \
+\
+    /* \
+     *  if the edge is horizontal, then it is ignored \
+     *  and assumed not to be processed.  Otherwise, do this stuff. \
+     */ \
+    if ((dy) != 0) { \
+        xStart = (x1); \
+        dx = (x2) - xStart; \
+        if (dx < 0) { \
+            m = dx / (dy); \
+            m1 = m - 1; \
+            incr1 = -2 * dx + 2 * (dy) * m1; \
+            incr2 = -2 * dx + 2 * (dy) * m; \
+            d = 2 * m * (dy) - 2 * dx - 2 * (dy); \
+        } else { \
+            m = dx / (dy); \
+            m1 = m + 1; \
+            incr1 = 2 * dx - 2 * (dy) * m1; \
+            incr2 = 2 * dx - 2 * (dy) * m; \
+            d = -2 * m * (dy) + 2 * dx; \
+        } \
+    } \
+}
+\f
+#define BRESINCRPGON(d, minval, m, m1, incr1, incr2) { \
+    if (m1 > 0) { \
+        if (d > 0) { \
+            minval += m1; \
+            d += incr1; \
+        } \
+        else { \
+            minval += m; \
+            d += incr2; \
+        } \
+    } else {\
+        if (d >= 0) { \
+            minval += m1; \
+            d += incr1; \
+        } \
+        else { \
+            minval += m; \
+            d += incr2; \
+        } \
+    } \
+}
+
+\f
+/*
+ *     This structure contains all of the information needed
+ *     to run the bresenham algorithm.
+ *     The variables may be hardcoded into the declarations
+ *     instead of using this structure to make use of
+ *     register declarations.
+ */
+typedef struct {
+    int minor;         /* minor axis        */
+    int d;           /* decision variable */
+    int m, m1;       /* slope and slope+1 */
+    int incr1, incr2; /* error increments */
+} BRESINFO;
+
+
+#define BRESINITPGONSTRUCT(dmaj, min1, min2, bres) \
+       BRESINITPGON(dmaj, min1, min2, bres.minor, bres.d, \
+                     bres.m, bres.m1, bres.incr1, bres.incr2)
+
+#define BRESINCRPGONSTRUCT(bres) \
+        BRESINCRPGON(bres.d, bres.minor, bres.m, bres.m1, bres.incr1, bres.incr2)
+
+
+#endif
diff --git a/Xserver/programs/Xserver/mi/miscrinit.c b/Xserver/programs/Xserver/mi/miscrinit.c
new file mode 100644 (file)
index 0000000..c937c6c
--- /dev/null
@@ -0,0 +1,305 @@
+/* $XConsortium: miscrinit.c /main/13 1996/08/12 21:51:16 dpw $ */
+/* $XFree86: xc/programs/Xserver/mi/miscrinit.c,v 3.2 1996/12/23 07:09:46 dawes Exp $ */
+/*
+
+Copyright (c) 1990  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be included
+in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR
+OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall
+not be used in advertising or otherwise to promote the sale, use or
+other dealings in this Software without prior written authorization
+from the X Consortium.
+
+*/
+
+#include "X.h"
+#include "servermd.h"
+#include "misc.h"
+#include "mi.h"
+#include "scrnintstr.h"
+#include "pixmapstr.h"
+#include "mibstore.h"
+#include "dix.h"
+#include "miline.h"
+
+/* We use this structure to propogate some information from miScreenInit to
+ * miCreateScreenResources.  miScreenInit allocates the structure, fills it
+ * in, and puts it into pScreen->devPrivate.  miCreateScreenResources 
+ * extracts the info and frees the structure.  We could've accomplished the
+ * same thing by adding fields to the screen structure, but they would have
+ * ended up being redundant, and would have exposed this mi implementation
+ * detail to the whole server.
+ */
+
+typedef struct
+{
+    pointer pbits; /* pointer to framebuffer */
+    int width;    /* delta to add to a framebuffer addr to move one row down */
+} miScreenInitParmsRec, *miScreenInitParmsPtr;
+
+
+/* this plugs into pScreen->ModifyPixmapHeader */
+Bool
+miModifyPixmapHeader(pPixmap, width, height, depth, bitsPerPixel, devKind,
+                    pPixData)
+    PixmapPtr   pPixmap;
+    int                width;
+    int                height;
+    int                depth;
+    int                bitsPerPixel;
+    int                devKind;
+    pointer     pPixData;
+{
+    if (!pPixmap)
+       return FALSE;
+    pPixmap->drawable.depth = depth;
+    pPixmap->drawable.bitsPerPixel = bitsPerPixel;
+    pPixmap->drawable.id = 0;
+    pPixmap->drawable.serialNumber = NEXT_SERIAL_NUMBER;
+    pPixmap->drawable.x = 0;
+    pPixmap->drawable.y = 0;
+    pPixmap->drawable.width = width;
+    pPixmap->drawable.height = height;
+    pPixmap->devKind = devKind;
+    pPixmap->refcnt = 1;
+    pPixmap->devPrivate.ptr = pPixData;
+    return TRUE;
+}
+
+
+/*ARGSUSED*/
+Bool
+miCloseScreen (index, pScreen)
+    int                index;
+    ScreenPtr  pScreen;
+{
+    return ((*pScreen->DestroyPixmap)((PixmapPtr)pScreen->devPrivate));
+}
+
+/* With the introduction of pixmap privates, the "screen pixmap" can no
+ * longer be created in miScreenInit, since all the modules that could
+ * possibly ask for pixmap private space have not been initialized at
+ * that time.  pScreen->CreateScreenResources is called after all
+ * possible private-requesting modules have been inited; we create the
+ * screen pixmap here.
+ */
+Bool
+miCreateScreenResources(pScreen)
+    ScreenPtr pScreen;
+{
+    miScreenInitParmsPtr pScrInitParms;
+    pointer value;
+
+    pScrInitParms = (miScreenInitParmsPtr)pScreen->devPrivate;
+
+    /* if width is non-zero, pScreen->devPrivate will be a pixmap
+     * else it will just take the value pbits
+     */
+    if (pScrInitParms->width)
+    {
+       PixmapPtr pPixmap;
+
+       /* create a pixmap with no data, then redirect it to point to
+        * the screen
+        */
+       pPixmap = (*pScreen->CreatePixmap)(pScreen, 0, 0, pScreen->rootDepth);
+       if (!pPixmap)
+           return FALSE;
+
+       if (!(*pScreen->ModifyPixmapHeader)(pPixmap, pScreen->width,
+                   pScreen->height, pScreen->rootDepth, pScreen->rootDepth,
+                   PixmapBytePad(pScrInitParms->width, pScreen->rootDepth),
+                   pScrInitParms->pbits))
+           return FALSE;
+       value = (pointer)pPixmap;
+    }
+    else
+    {
+       value = pScrInitParms->pbits;
+    }
+    xfree(pScreen->devPrivate); /* freeing miScreenInitParmsRec */
+    pScreen->devPrivate = value; /* pPixmap or pbits */
+    return TRUE;
+}
+
+Bool
+miScreenDevPrivateInit(pScreen, width, pbits)
+    register ScreenPtr pScreen;
+    int width;
+    pointer pbits;
+{
+    miScreenInitParmsPtr pScrInitParms;
+
+    /* Stash pbits and width in a short-lived miScreenInitParmsRec attached
+     * to the screen, until CreateScreenResources can put them in the
+     * screen pixmap.
+     */
+    pScrInitParms = (miScreenInitParmsPtr)xalloc(sizeof(miScreenInitParmsRec));
+    if (!pScrInitParms)
+       return FALSE;
+    pScrInitParms->pbits = pbits;
+    pScrInitParms->width = width;
+    pScreen->devPrivate = (pointer)pScrInitParms;
+    return TRUE;
+}
+
+/*
+ * If you pass in bsfuncs, then you must preinitialize the missing
+ * screen procs before calling miScreenInit, so that the backing store
+ * code can correctly wrap them.
+ */
+
+Bool
+miScreenInit(pScreen, pbits, xsize, ysize, dpix, dpiy, width,
+            rootDepth, numDepths, depths, rootVisual, numVisuals, visuals,
+            bsfuncs)
+    register ScreenPtr pScreen;
+    pointer pbits;             /* pointer to screen bits */
+    int xsize, ysize;          /* in pixels */
+    int dpix, dpiy;            /* dots per inch */
+    int width;                 /* pixel width of frame buffer */
+    int rootDepth;             /* depth of root window */
+    int numDepths;             /* number of depths supported */
+    DepthRec *depths;          /* supported depths */
+    VisualID rootVisual;       /* root visual */
+    int numVisuals;            /* number of visuals supported */
+    VisualRec *visuals;                /* supported visuals */
+    miBSFuncPtr        bsfuncs;        /* backing store functions */
+{
+    pScreen->width = xsize;
+    pScreen->height = ysize;
+    pScreen->mmWidth = (xsize * 254 + dpix * 5) / (dpix * 10);
+    pScreen->mmHeight = (ysize * 254 + dpiy * 5) / (dpiy * 10);
+    pScreen->numDepths = numDepths;
+    pScreen->rootDepth = rootDepth;
+    pScreen->allowedDepths = depths;
+    pScreen->rootVisual = rootVisual;
+    /* defColormap */
+    pScreen->minInstalledCmaps = 1;
+    pScreen->maxInstalledCmaps = 1;
+    pScreen->backingStoreSupport = Always;
+    pScreen->saveUnderSupport = NotUseful;
+    /* whitePixel, blackPixel */
+    pScreen->ModifyPixmapHeader = miModifyPixmapHeader;
+    pScreen->CreateScreenResources = miCreateScreenResources;
+    pScreen->numVisuals = numVisuals;
+    pScreen->visuals = visuals;
+    if (width)
+    {
+#ifdef MITSHM
+       ShmRegisterFbFuncs(pScreen);
+#endif
+       pScreen->CloseScreen = miCloseScreen;
+    }
+    /* else CloseScreen */
+    /* QueryBestSize, SaveScreen, GetImage, GetSpans */
+    pScreen->PointerNonInterestBox = (void (*)()) 0;
+    pScreen->SourceValidate = (void (*)()) 0;
+    /* CreateWindow, DestroyWindow, PositionWindow, ChangeWindowAttributes */
+    /* RealizeWindow, UnrealizeWindow */
+    pScreen->ValidateTree = miValidateTree;
+    pScreen->PostValidateTree = (void (*)()) 0;
+    pScreen->WindowExposures = miWindowExposures;
+    /* PaintWindowBackground, PaintWindowBorder, CopyWindow */
+    pScreen->ClearToBackground = miClearToBackground;
+    pScreen->ClipNotify = (void (*)()) 0;
+    /* CreatePixmap, DestroyPixmap */
+    /* RealizeFont, UnrealizeFont */
+    /* CreateGC */
+    /* CreateColormap, DestroyColormap, InstallColormap, UninstallColormap */
+    /* ListInstalledColormaps, StoreColors, ResolveColor */
+    pScreen->RegionCreate = miRegionCreate;
+    pScreen->RegionInit = miRegionInit;
+    pScreen->RegionCopy = miRegionCopy;
+    pScreen->RegionDestroy = miRegionDestroy;
+    pScreen->RegionUninit = miRegionUninit;
+    pScreen->Intersect = miIntersect;
+    pScreen->Union = miUnion;
+    pScreen->Subtract = miSubtract;
+    pScreen->Inverse = miInverse;
+    pScreen->RegionReset = miRegionReset;
+    pScreen->TranslateRegion = miTranslateRegion;
+    pScreen->RectIn = miRectIn;
+    pScreen->PointInRegion = miPointInRegion;
+    pScreen->RegionNotEmpty = miRegionNotEmpty;
+    pScreen->RegionEmpty = miRegionEmpty;
+    pScreen->RegionExtents = miRegionExtents;
+    pScreen->RegionAppend = miRegionAppend;
+    pScreen->RegionValidate = miRegionValidate;
+    /* BitmapToRegion */
+    pScreen->RectsToRegion = miRectsToRegion;
+    pScreen->SendGraphicsExpose = miSendGraphicsExpose;
+    pScreen->BlockHandler = (void (*)())NoopDDA;
+    pScreen->WakeupHandler = (void (*)())NoopDDA;
+    pScreen->blockData = (pointer)0;
+    pScreen->wakeupData = (pointer)0;
+    if (bsfuncs)
+       miInitializeBackingStore (pScreen, bsfuncs);
+    pScreen->MarkWindow = miMarkWindow;
+    pScreen->MarkOverlappedWindows = miMarkOverlappedWindows;
+    pScreen->ChangeSaveUnder = miChangeSaveUnder;
+    pScreen->PostChangeSaveUnder = miPostChangeSaveUnder;
+    pScreen->MoveWindow = miMoveWindow;
+    pScreen->ResizeWindow = miSlideAndSizeWindow;
+    pScreen->GetLayerWindow = miGetLayerWindow;
+    pScreen->HandleExposures = miHandleValidateExposures;
+    pScreen->ReparentWindow = (void (*)())0;
+    pScreen->ChangeBorderWidth = miChangeBorderWidth;
+#ifdef SHAPE
+    pScreen->SetShape = miSetShape;
+#endif
+    pScreen->MarkUnrealizedWindow = miMarkUnrealizedWindow;
+
+    miSetZeroLineBias(pScreen, DEFAULTZEROLINEBIAS);
+
+    return miScreenDevPrivateInit(pScreen, width, pbits);
+}
+
+int
+miAllocateGCPrivateIndex()
+{
+    static int privateIndex = -1;
+    static unsigned long miGeneration = 0;
+
+    if (miGeneration != serverGeneration)
+    {
+       privateIndex = AllocateGCPrivateIndex();
+       miGeneration = serverGeneration;
+    }
+    return privateIndex;
+}
+
+int miZeroLineScreenIndex;
+int miZeroLineGeneration;
+
+void
+miSetZeroLineBias(pScreen, bias)
+    ScreenPtr pScreen;
+    unsigned int bias;
+{
+    if (miZeroLineGeneration != serverGeneration)
+    {
+       miZeroLineScreenIndex = AllocateScreenPrivateIndex();
+       miZeroLineGeneration = serverGeneration;
+    }
+    if (miZeroLineScreenIndex >= 0)
+       pScreen->devPrivates[miZeroLineScreenIndex].uval = bias;
+}
diff --git a/Xserver/programs/Xserver/mi/mispans.c b/Xserver/programs/Xserver/mi/mispans.c
new file mode 100644 (file)
index 0000000..0d4bc13
--- /dev/null
@@ -0,0 +1,560 @@
+/***********************************************************
+
+Copyright (c) 1989  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+
+Copyright 1989 by Digital Equipment Corporation, Maynard, Massachusetts.
+
+                        All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and its 
+documentation for any purpose and without fee is hereby granted, 
+provided that the above copyright notice appear in all copies and that
+both that copyright notice and this permission notice appear in 
+supporting documentation, and that the name of Digital not be
+used in advertising or publicity pertaining to distribution of the
+software without specific, written prior permission.  
+
+DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
+ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
+DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
+ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+SOFTWARE.
+
+******************************************************************/
+
+/* $XConsortium: mispans.c,v 5.5 94/04/17 20:27:52 dpw Exp $ */
+/* $XFree86: xc/programs/Xserver/mi/mispans.c,v 3.0 1995/07/07 15:45:49 dawes Exp $ */
+
+#include "misc.h"
+#include "pixmapstr.h"
+#include "gcstruct.h"
+#include "mispans.h"
+
+/*
+
+These routines maintain lists of Spans, in order to implement the
+``touch-each-pixel-once'' rules of wide lines and arcs.
+
+Written by Joel McCormack, Summer 1989.
+
+*/
+
+
+void miInitSpanGroup(spanGroup)
+    SpanGroup *spanGroup;
+{
+    spanGroup->size = 0;
+    spanGroup->count = 0;
+    spanGroup->group = NULL;
+    spanGroup->ymin = MAXSHORT;
+    spanGroup->ymax = MINSHORT;
+} /* InitSpanGroup */
+
+#define YMIN(spans) (spans->points[0].y)
+#define YMAX(spans)  (spans->points[spans->count-1].y)
+
+void miSubtractSpans (spanGroup, sub)
+    SpanGroup  *spanGroup;
+    Spans      *sub;
+{
+    int                i, subCount, spansCount;
+    int                ymin, ymax, xmin, xmax;
+    Spans      *spans;
+    DDXPointPtr        subPt, spansPt;
+    int                *subWid, *spansWid;
+    int                extra;
+
+    ymin = YMIN(sub);
+    ymax = YMAX(sub);
+    spans = spanGroup->group;
+    for (i = spanGroup->count; i; i--, spans++) {
+       if (YMIN(spans) <= ymax && ymin <= YMAX(spans)) {
+           subCount = sub->count;
+           subPt = sub->points;
+           subWid = sub->widths;
+           spansCount = spans->count;
+           spansPt = spans->points;
+           spansWid = spans->widths;
+           extra = 0;
+           for (;;)
+           {
+               while (spansCount && spansPt->y < subPt->y)
+               {
+                   spansPt++;  spansWid++; spansCount--;
+               }
+               if (!spansCount)
+                   break;
+               while (subCount && subPt->y < spansPt->y)
+               {
+                   subPt++;    subWid++;   subCount--;
+               }
+               if (!subCount)
+                   break;
+               if (subPt->y == spansPt->y)
+               {
+                   xmin = subPt->x;
+                   xmax = xmin + *subWid;
+                   if (xmin >= spansPt->x + *spansWid || spansPt->x >= xmax)
+                   {
+                       ;
+                   }
+                   else if (xmin <= spansPt->x)
+                   {
+                       if (xmax >= spansPt->x + *spansWid) 
+                       {
+                           memmove (spansPt, spansPt + 1, sizeof *spansPt * (spansCount - 1));
+                           memmove (spansWid, spansWid + 1, sizeof *spansWid * (spansCount - 1));
+                           spansPt--;
+                           spansWid--;
+                           spans->count--;
+                           extra++;
+                       }
+                       else 
+                       {
+                           *spansWid = *spansWid - (xmax - spansPt->x);
+                           spansPt->x = xmax;
+                       }
+                   }
+                   else
+                   {
+                       if (xmax >= spansPt->x + *spansWid)
+                       {
+                           *spansWid = xmin - spansPt->x;
+                       }
+                       else
+                       {
+                           if (!extra) {
+                               DDXPointPtr newPt;
+                               int         *newwid;
+
+#define EXTRA 8
+                               newPt = (DDXPointPtr) xrealloc (spans->points, (spans->count + EXTRA) * sizeof (DDXPointRec));
+                               if (!newPt)
+                                   break;
+                               spansPt = newPt + (spansPt - spans->points);
+                               spans->points = newPt;
+                               newwid = (int *) xrealloc (spans->widths, (spans->count + EXTRA) * sizeof (int));
+                               if (!newwid)
+                                   break;
+                               spansWid = newwid + (spansWid - spans->widths);
+                               spans->widths = newwid;
+                               extra = EXTRA;
+                           }
+                           memmove (spansPt + 1, spansPt, sizeof *spansPt * (spansCount));
+                           memmove (spansWid + 1, spansWid, sizeof *spansWid * (spansCount));
+                           spans->count++;
+                           extra--;
+                           *spansWid = xmin - spansPt->x;
+                           spansWid++;
+                           spansPt++;
+                           *spansWid = *spansWid - (xmax - spansPt->x);
+                           spansPt->x = xmax;
+                       }
+                   }
+               }
+               spansPt++;  spansWid++; spansCount--;
+           }
+       }
+    }
+}
+    
+void miAppendSpans(spanGroup, otherGroup, spans)
+    SpanGroup   *spanGroup;
+    SpanGroup  *otherGroup;
+    Spans       *spans;
+{
+    register    int ymin, ymax;
+    register    int spansCount;
+
+    spansCount = spans->count;
+    if (spansCount > 0) {
+       if (spanGroup->size == spanGroup->count) {
+           spanGroup->size = (spanGroup->size + 8) * 2;
+           spanGroup->group = (Spans *)
+               xrealloc(spanGroup->group, sizeof(Spans) * spanGroup->size);
+        }
+
+       spanGroup->group[spanGroup->count] = *spans;
+       (spanGroup->count)++;
+       ymin = spans->points[0].y;
+       if (ymin < spanGroup->ymin) spanGroup->ymin = ymin;
+       ymax = spans->points[spansCount - 1].y;
+       if (ymax > spanGroup->ymax) spanGroup->ymax = ymax;
+       if (otherGroup &&
+           otherGroup->ymin < ymax &&
+           ymin < otherGroup->ymax)
+       {
+           miSubtractSpans (otherGroup, spans);
+       }
+    }
+    else
+    {
+       xfree (spans->points);
+       xfree (spans->widths);
+    }
+} /* AppendSpans */
+
+void miFreeSpanGroup(spanGroup)
+    SpanGroup   *spanGroup;
+{
+    if (spanGroup->group != NULL) xfree(spanGroup->group);
+}
+
+static void QuickSortSpansX(points, widths, numSpans)
+    register DDXPointRec    points[];
+    register int           widths[];
+    register int           numSpans;
+{
+    register int           x;
+    register int           i, j, m;
+    register DDXPointPtr    r;
+
+/* Always called with numSpans > 1 */
+/* Sorts only by x, as all y should be the same */
+
+#define ExchangeSpans(a, b)                                \
+{                                                          \
+    DDXPointRec     tpt;                                   \
+    register int    tw;                                            \
+                                                           \
+    tpt = points[a]; points[a] = points[b]; points[b] = tpt;    \
+    tw = widths[a]; widths[a] = widths[b]; widths[b] = tw;  \
+}
+
+    do {
+       if (numSpans < 9) {
+           /* Do insertion sort */
+           register int xprev;
+
+           xprev = points[0].x;
+           i = 1;
+           do { /* while i != numSpans */
+               x = points[i].x;
+               if (xprev > x) {
+                   /* points[i] is out of order.  Move into proper location. */
+                   DDXPointRec tpt;
+                   int     tw, k;
+
+                   for (j = 0; x >= points[j].x; j++) {}
+                   tpt = points[i];
+                   tw  = widths[i];
+                   for (k = i; k != j; k--) {
+                       points[k] = points[k-1];
+                       widths[k] = widths[k-1];
+                   }
+                   points[j] = tpt;
+                   widths[j] = tw;
+                   x = points[i].x;
+               } /* if out of order */
+               xprev = x;
+               i++;
+           } while (i != numSpans);
+           return;
+       }
+
+       /* Choose partition element, stick in location 0 */
+       m = numSpans / 2;
+       if (points[m].x > points[0].x)          ExchangeSpans(m, 0);
+       if (points[m].x > points[numSpans-1].x) ExchangeSpans(m, numSpans-1);
+       if (points[m].x > points[0].x)          ExchangeSpans(m, 0);
+       x = points[0].x;
+
+        /* Partition array */
+        i = 0;
+        j = numSpans;
+        do {
+           r = &(points[i]);
+           do {
+               r++;
+               i++;
+            } while (i != numSpans && r->x < x);
+           r = &(points[j]);
+           do {
+               r--;
+               j--;
+            } while (x < r->x);
+            if (i < j) ExchangeSpans(i, j);
+        } while (i < j);
+
+        /* Move partition element back to middle */
+        ExchangeSpans(0, j);
+
+       /* Recurse */
+        if (numSpans-j-1 > 1)
+           QuickSortSpansX(&points[j+1], &widths[j+1], numSpans-j-1);
+        numSpans = j;
+    } while (numSpans > 1);
+} /* QuickSortSpans */
+
+
+static int UniquifySpansX(spans, newPoints, newWidths)
+    Spans                  *spans;
+    register DDXPointRec    *newPoints;
+    register int           *newWidths;
+{
+    register int newx1, newx2, oldpt, i, y;
+    register DDXPointRec    *oldPoints;
+    register int           *oldWidths;
+    int                            *startNewWidths;
+
+/* Always called with numSpans > 1 */
+/* Uniquify the spans, and stash them into newPoints and newWidths.  Return the
+   number of unique spans. */
+
+
+    startNewWidths = newWidths;
+
+    oldPoints = spans->points;
+    oldWidths = spans->widths;
+
+    y = oldPoints->y;
+    newx1 = oldPoints->x;
+    newx2 = newx1 + *oldWidths;
+
+    for (i = spans->count-1; i != 0; i--) {
+       oldPoints++;
+       oldWidths++;
+       oldpt = oldPoints->x;
+       if (oldpt > newx2) {
+           /* Write current span, start a new one */
+           newPoints->x = newx1;
+           newPoints->y = y;
+           *newWidths = newx2 - newx1;
+           newPoints++;
+           newWidths++;
+           newx1 = oldpt;
+           newx2 = oldpt + *oldWidths;
+       } else {
+           /* extend current span, if old extends beyond new */
+           oldpt = oldpt + *oldWidths;
+           if (oldpt > newx2) newx2 = oldpt;
+       }
+    } /* for */
+
+    /* Write final span */
+    newPoints->x = newx1;
+    *newWidths = newx2 - newx1;
+    newPoints->y = y;
+
+    return (newWidths - startNewWidths) + 1;
+} /* UniquifySpansX */
+
+void
+miDisposeSpanGroup (spanGroup)
+    SpanGroup  *spanGroup;
+{
+    int            i;
+    Spans   *spans;
+
+    for (i = 0; i < spanGroup->count; i++)
+    {
+       spans = spanGroup->group + i;
+       xfree (spans->points);
+       xfree (spans->widths);
+    }
+}
+
+void miFillUniqueSpanGroup(pDraw, pGC, spanGroup)
+    DrawablePtr pDraw;
+    GCPtr      pGC;
+    SpanGroup   *spanGroup;
+{
+    register int    i;
+    register Spans  *spans;
+    register Spans  *yspans;
+    register int    *ysizes;
+    register int    ymin, ylength;
+
+    /* Outgoing spans for one big call to FillSpans */
+    register DDXPointPtr    points;
+    register int           *widths;
+    register int           count;
+
+    if (spanGroup->count == 0) return;
+
+    if (spanGroup->count == 1) {
+       /* Already should be sorted, unique */
+       spans = spanGroup->group;
+       (*pGC->ops->FillSpans)
+           (pDraw, pGC, spans->count, spans->points, spans->widths, TRUE);
+       xfree(spans->points);
+       xfree(spans->widths);
+    }
+    else
+    {
+       /* Yuck.  Gross.  Radix sort into y buckets, then sort x and uniquify */
+       /* This seems to be the fastest thing to do.  I've tried sorting on
+          both x and y at the same time rather than creating into all those
+          y buckets, but it was somewhat slower. */
+
+       ymin    = spanGroup->ymin;
+       ylength = spanGroup->ymax - ymin + 1;
+
+       /* Allocate Spans for y buckets */
+       yspans = (Spans *) xalloc(ylength * sizeof(Spans));
+       ysizes = (int *) xalloc(ylength * sizeof (int));
+
+       if (!yspans || !ysizes)
+       {
+           if (yspans)
+               xfree (yspans);
+           if (ysizes)
+               xfree (ysizes);
+           miDisposeSpanGroup (spanGroup);
+           return;
+       }
+       
+       for (i = 0; i != ylength; i++) {
+           ysizes[i]        = 0;
+           yspans[i].count  = 0;
+           yspans[i].points = NULL;
+           yspans[i].widths = NULL;
+       }
+
+       /* Go through every single span and put it into the correct bucket */
+       count = 0;
+       for (i = 0, spans = spanGroup->group;
+               i != spanGroup->count;
+               i++, spans++) {
+           int         index;
+           int         j;
+
+           for (j = 0, points = spans->points, widths = spans->widths;
+                   j != spans->count;
+                   j++, points++, widths++) {
+               index = points->y - ymin;
+               if (index >= 0 && index < ylength) {
+                   Spans *newspans = &(yspans[index]);
+                   if (newspans->count == ysizes[index]) {
+                       DDXPointPtr newpoints;
+                       int         *newwidths;
+                       ysizes[index] = (ysizes[index] + 8) * 2;
+                       newpoints = (DDXPointPtr) xrealloc(
+                           newspans->points,
+                           ysizes[index] * sizeof(DDXPointRec));
+                       newwidths = (int *) xrealloc(
+                           newspans->widths,
+                           ysizes[index] * sizeof(int));
+                       if (!newpoints || !newwidths)
+                       {
+                           int i;
+
+                           for (i = 0; i < ylength; i++)
+                           {
+                               xfree (yspans[i].points);
+                               xfree (yspans[i].widths);
+                           }
+                           xfree (yspans);
+                           xfree (ysizes);
+                           miDisposeSpanGroup (spanGroup);
+                           return;
+                       }
+                       newspans->points = newpoints;
+                       newspans->widths = newwidths;
+                   }
+                   newspans->points[newspans->count] = *points;
+                   newspans->widths[newspans->count] = *widths;
+                   (newspans->count)++;
+               } /* if y value of span in range */
+           } /* for j through spans */
+           count += spans->count;
+           xfree(spans->points);
+           spans->points = NULL;
+           xfree(spans->widths);
+           spans->widths = NULL;
+       } /* for i thorough Spans */
+
+       /* Now sort by x and uniquify each bucket into the final array */
+       points = (DDXPointPtr) xalloc(count * sizeof(DDXPointRec));
+       widths = (int *)       xalloc(count * sizeof(int));
+       if (!points || !widths)
+       {
+           int i;
+
+           for (i = 0; i < ylength; i++)
+           {
+               xfree (yspans[i].points);
+               xfree (yspans[i].widths);
+           }
+           xfree (yspans);
+           xfree (ysizes);
+           if (points)
+               xfree (points);
+           if (widths)
+               xfree (widths);
+           return;
+       }
+       count = 0;
+       for (i = 0; i != ylength; i++) {
+           int ycount = yspans[i].count;
+           if (ycount > 0) {
+               if (ycount > 1) {
+                   QuickSortSpansX(yspans[i].points, yspans[i].widths, ycount);
+                   count += UniquifySpansX
+                       (&(yspans[i]), &(points[count]), &(widths[count]));
+               } else {
+                   points[count] = yspans[i].points[0];
+                   widths[count] = yspans[i].widths[0];
+                   count++;
+               }
+               xfree(yspans[i].points);
+               xfree(yspans[i].widths);
+           }
+       }
+
+       (*pGC->ops->FillSpans) (pDraw, pGC, count, points, widths, TRUE);
+       xfree(points);
+       xfree(widths);
+       xfree(yspans);
+       xfree(ysizes);          /* use (DE)ALLOCATE_LOCAL for these? */
+    }
+
+    spanGroup->count = 0;
+    spanGroup->ymin = MAXSHORT;
+    spanGroup->ymax = MINSHORT;
+}
+
+
+void miFillSpanGroup(pDraw, pGC, spanGroup)
+    DrawablePtr pDraw;
+    GCPtr      pGC;
+    SpanGroup   *spanGroup;
+{
+    register int    i;
+    register Spans  *spans;
+
+    for (i = 0, spans = spanGroup->group; i != spanGroup->count; i++, spans++) {
+       (*pGC->ops->FillSpans)
+           (pDraw, pGC, spans->count, spans->points, spans->widths, TRUE);
+       xfree(spans->points);
+       xfree(spans->widths);
+    }
+
+    spanGroup->count = 0;
+    spanGroup->ymin = MAXSHORT;
+    spanGroup->ymax = MINSHORT;
+} /* FillSpanGroup */
diff --git a/Xserver/programs/Xserver/mi/mispans.h b/Xserver/programs/Xserver/mi/mispans.h
new file mode 100644 (file)
index 0000000..cc043c4
--- /dev/null
@@ -0,0 +1,133 @@
+/***********************************************************
+
+Copyright (c) 1989  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+
+Copyright 1989 by Digital Equipment Corporation, Maynard, Massachusetts.
+
+                        All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and its 
+documentation for any purpose and without fee is hereby granted, 
+provided that the above copyright notice appear in all copies and that
+both that copyright notice and this permission notice appear in 
+supporting documentation, and that the name of Digital not be
+used in advertising or publicity pertaining to distribution of the
+software without specific, written prior permission.  
+
+DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
+ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
+DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
+ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+SOFTWARE.
+
+******************************************************************/
+
+/* $XConsortium: mispans.h,v 5.3 94/04/17 20:27:52 dpw Exp $ */
+
+typedef struct {
+    int         count;         /* number of spans                  */
+    DDXPointPtr points;                /* pointer to list of start points  */
+    int         *widths;       /* pointer to list of widths        */
+} Spans;
+
+typedef struct {
+    int                size;           /* Total number of *Spans allocated     */
+    int                count;          /* Number of *Spans actually in group   */
+    Spans       *group;                /* List of Spans                        */
+    int                ymin, ymax;     /* Min, max y values encountered        */
+} SpanGroup;
+
+/* Initialize SpanGroup.  MUST BE DONE before use. */
+extern void miInitSpanGroup(
+#if NeedFunctionPrototypes
+    SpanGroup * /*spanGroup*/
+#endif
+);
+
+/* Add a Spans to a SpanGroup. The spans MUST BE in y-sorted order */
+extern void miAppendSpans(
+#if NeedFunctionPrototypes
+    SpanGroup * /*spanGroup*/,
+    SpanGroup * /*otherGroup*/,
+    Spans * /*spans*/
+#endif
+);
+
+/* Paint a span group, possibly with some overlap */
+extern void miFillSpanGroup(
+#if NeedFunctionPrototypes
+    DrawablePtr /*pDraw*/,
+    GCPtr /*pGC*/,
+    SpanGroup * /*spanGroup*/
+#endif
+);
+
+/* Paint a span group, insuring that each pixel is painted at most once */
+extern void miFillUniqueSpanGroup(
+#if NeedFunctionPrototypes
+    DrawablePtr /*pDraw*/,
+    GCPtr /*pGC*/,
+    SpanGroup * /*spanGroup*/
+#endif
+);
+
+/* Free up data in a span group.  MUST BE DONE or you'll suffer memory leaks */
+extern void miFreeSpanGroup(
+#if NeedFunctionPrototypes
+    SpanGroup * /*spanGroup*/
+#endif
+);
+
+extern void miSubtractSpans(
+#if NeedFunctionPrototypes
+    SpanGroup * /*spanGroup*/,
+    Spans * /*sub*/
+#endif
+);
+
+extern void miDisposeSpanGroup(
+#if NeedFunctionPrototypes
+    SpanGroup * /*spanGroup*/
+#endif
+);
+
+extern int miClipSpans(
+#if NeedFunctionPrototypes
+    RegionPtr /*prgnDst*/,
+    DDXPointPtr /*ppt*/,
+    int * /*pwidth*/,
+    int /*nspans*/,
+    DDXPointPtr /*pptNew*/,
+    int * /*pwidthNew*/,
+    int /*fSorted*/
+#endif
+);
+
+/* Rops which must use span groups */
+#define miSpansCarefulRop(rop) (((rop) & 0xc) == 0x8 || ((rop) & 0x3) == 0x2)
+#define miSpansEasyRop(rop)    (!miSpansCarefulRop(rop))
+
diff --git a/Xserver/programs/Xserver/mi/misprite.c b/Xserver/programs/Xserver/mi/misprite.c
new file mode 100644 (file)
index 0000000..4f5ff5e
--- /dev/null
@@ -0,0 +1,2069 @@
+/*
+ * misprite.c
+ *
+ * machine independent software sprite routines
+ */
+
+/* $XConsortium: misprite.c,v 5.47 94/04/17 20:27:53 dpw Exp $ */
+/* $XFree86: xc/programs/Xserver/mi/misprite.c,v 3.0 1996/08/25 14:13:56 dawes Exp $ */
+
+/*
+
+Copyright (c) 1989  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+*/
+
+# include   "X.h"
+# include   "Xproto.h"
+# include   "misc.h"
+# include   "pixmapstr.h"
+# include   "input.h"
+# include   "mi.h"
+# include   "cursorstr.h"
+# include   "font.h"
+# include   "scrnintstr.h"
+# include   "colormapst.h"
+# include   "windowstr.h"
+# include   "gcstruct.h"
+# include   "mipointer.h"
+# include   "mispritest.h"
+# include   "dixfontstr.h"
+# include   "fontstruct.h"
+
+/*
+ * screen wrappers
+ */
+
+static int  miSpriteScreenIndex;
+static unsigned long miSpriteGeneration = 0;
+
+static Bool        miSpriteCloseScreen();
+static void        miSpriteGetImage();
+static void        miSpriteGetSpans();
+static void        miSpriteSourceValidate();
+static Bool        miSpriteCreateGC();
+static void        miSpriteBlockHandler();
+static void        miSpriteInstallColormap();
+static void        miSpriteStoreColors();
+
+static void        miSpritePaintWindowBackground();
+static void        miSpritePaintWindowBorder();
+static void        miSpriteCopyWindow();
+static void        miSpriteClearToBackground();
+
+static void        miSpriteSaveDoomedAreas();
+static RegionPtr    miSpriteRestoreAreas();
+static void        miSpriteComputeSaved();
+
+#define SCREEN_PROLOGUE(pScreen, field)\
+  ((pScreen)->field = \
+   ((miSpriteScreenPtr) (pScreen)->devPrivates[miSpriteScreenIndex].ptr)->field)
+
+#define SCREEN_EPILOGUE(pScreen, field, wrapper)\
+    ((pScreen)->field = wrapper)
+
+/*
+ * GC func wrappers
+ */
+
+static int  miSpriteGCIndex;
+
+static void miSpriteValidateGC (),  miSpriteCopyGC ();
+static void miSpriteDestroyGC(),    miSpriteChangeGC();
+static void miSpriteChangeClip(),   miSpriteDestroyClip();
+static void miSpriteCopyClip();
+
+static GCFuncs miSpriteGCFuncs = {
+    miSpriteValidateGC,
+    miSpriteChangeGC,
+    miSpriteCopyGC,
+    miSpriteDestroyGC,
+    miSpriteChangeClip,
+    miSpriteDestroyClip,
+    miSpriteCopyClip,
+};
+
+#define GC_FUNC_PROLOGUE(pGC)                                  \
+    miSpriteGCPtr   pGCPriv =                                  \
+       (miSpriteGCPtr) (pGC)->devPrivates[miSpriteGCIndex].ptr;\
+    (pGC)->funcs = pGCPriv->wrapFuncs;                         \
+    if (pGCPriv->wrapOps)                                      \
+       (pGC)->ops = pGCPriv->wrapOps;
+
+#define GC_FUNC_EPILOGUE(pGC)                                  \
+    pGCPriv->wrapFuncs = (pGC)->funcs;                         \
+    (pGC)->funcs = &miSpriteGCFuncs;                           \
+    if (pGCPriv->wrapOps)                                      \
+    {                                                          \
+       pGCPriv->wrapOps = (pGC)->ops;                          \
+       (pGC)->ops = &miSpriteGCOps;                            \
+    }
+
+/*
+ * GC op wrappers
+ */
+
+static void        miSpriteFillSpans(),        miSpriteSetSpans();
+static void        miSpritePutImage();
+static RegionPtr    miSpriteCopyArea(),                miSpriteCopyPlane();
+static void        miSpritePolyPoint(),        miSpritePolylines();
+static void        miSpritePolySegment(),      miSpritePolyRectangle();
+static void        miSpritePolyArc(),          miSpriteFillPolygon();
+static void        miSpritePolyFillRect(),     miSpritePolyFillArc();
+static int         miSpritePolyText8(),        miSpritePolyText16();
+static void        miSpriteImageText8(),       miSpriteImageText16();
+static void        miSpriteImageGlyphBlt(),    miSpritePolyGlyphBlt();
+static void        miSpritePushPixels();
+#ifdef NEED_LINEHELPER
+static void        miSpriteLineHelper();
+#endif
+
+static GCOps miSpriteGCOps = {
+    miSpriteFillSpans,     miSpriteSetSpans,       miSpritePutImage,   
+    miSpriteCopyArea,      miSpriteCopyPlane,      miSpritePolyPoint,
+    miSpritePolylines,     miSpritePolySegment,    miSpritePolyRectangle,
+    miSpritePolyArc,       miSpriteFillPolygon,    miSpritePolyFillRect,
+    miSpritePolyFillArc,    miSpritePolyText8,     miSpritePolyText16,
+    miSpriteImageText8,            miSpriteImageText16,    miSpriteImageGlyphBlt,
+    miSpritePolyGlyphBlt,   miSpritePushPixels
+#ifdef NEED_LINEHELPER
+    , miSpriteLineHelper
+#endif
+};
+
+/*
+ * testing only -- remove cursor for every draw.  Eventually,
+ * each draw operation will perform a bounding box check against
+ * the saved cursor area
+ */
+
+#define GC_SETUP_CHEAP(pDrawable)                                  \
+    miSpriteScreenPtr  pScreenPriv = (miSpriteScreenPtr)           \
+       (pDrawable)->pScreen->devPrivates[miSpriteScreenIndex].ptr; \
+
+#define GC_SETUP(pDrawable, pGC)                                   \
+    GC_SETUP_CHEAP(pDrawable)                                      \
+    miSpriteGCPtr      pGCPrivate = (miSpriteGCPtr)                \
+       (pGC)->devPrivates[miSpriteGCIndex].ptr;                    \
+    GCFuncs *oldFuncs = pGC->funcs;
+
+#define GC_SETUP_AND_CHECK(pDrawable, pGC)                         \
+    GC_SETUP(pDrawable, pGC);                                      \
+    if (GC_CHECK((WindowPtr)pDrawable))                                    \
+       miSpriteRemoveCursor (pDrawable->pScreen);
+    
+#define GC_CHECK(pWin)                                             \
+    (pScreenPriv->isUp &&                                          \
+        (pScreenPriv->pCacheWin == pWin ?                          \
+           pScreenPriv->isInCacheWin : (                           \
+           (pScreenPriv->pCacheWin = (pWin)),                      \
+           (pScreenPriv->isInCacheWin =                            \
+               (pWin)->drawable.x < pScreenPriv->saved.x2 &&       \
+               pScreenPriv->saved.x1 < (pWin)->drawable.x +        \
+                                   (int) (pWin)->drawable.width && \
+               (pWin)->drawable.y < pScreenPriv->saved.y2 &&       \
+               pScreenPriv->saved.y1 < (pWin)->drawable.y +        \
+                                   (int) (pWin)->drawable.height &&\
+               RECT_IN_REGION((pWin)->drawable.pScreen, &(pWin)->borderClip, \
+                       &pScreenPriv->saved) != rgnOUT))))
+
+#define GC_OP_PROLOGUE(pGC) { \
+    (pGC)->funcs = pGCPrivate->wrapFuncs; \
+    (pGC)->ops = pGCPrivate->wrapOps; \
+    }
+
+#define GC_OP_EPILOGUE(pGC) { \
+    pGCPrivate->wrapOps = (pGC)->ops; \
+    (pGC)->funcs = oldFuncs; \
+    (pGC)->ops = &miSpriteGCOps; \
+    }
+
+/*
+ * pointer-sprite method table
+ */
+
+static Bool miSpriteRealizeCursor (),  miSpriteUnrealizeCursor ();
+static void miSpriteSetCursor (),      miSpriteMoveCursor ();
+
+miPointerSpriteFuncRec miSpritePointerFuncs = {
+    miSpriteRealizeCursor,
+    miSpriteUnrealizeCursor,
+    miSpriteSetCursor,
+    miSpriteMoveCursor,
+};
+
+/*
+ * other misc functions
+ */
+
+static void miSpriteRemoveCursor (),   miSpriteRestoreCursor();
+
+/*
+ * miSpriteInitialize -- called from device-dependent screen
+ * initialization proc after all of the function pointers have
+ * been stored in the screen structure.
+ */
+
+Bool
+miSpriteInitialize (pScreen, cursorFuncs, screenFuncs)
+    ScreenPtr              pScreen;
+    miSpriteCursorFuncPtr   cursorFuncs;
+    miPointerScreenFuncPtr  screenFuncs;
+{
+    miSpriteScreenPtr  pPriv;
+    VisualPtr          pVisual;
+    
+    if (miSpriteGeneration != serverGeneration)
+    {
+       miSpriteScreenIndex = AllocateScreenPrivateIndex ();
+       if (miSpriteScreenIndex < 0)
+           return FALSE;
+       miSpriteGeneration = serverGeneration;
+       miSpriteGCIndex = AllocateGCPrivateIndex ();
+    }
+    if (!AllocateGCPrivate(pScreen, miSpriteGCIndex, sizeof(miSpriteGCRec)))
+       return FALSE;
+    pPriv = (miSpriteScreenPtr) xalloc (sizeof (miSpriteScreenRec));
+    if (!pPriv)
+       return FALSE;
+    if (!miPointerInitialize (pScreen, &miSpritePointerFuncs, screenFuncs,TRUE))
+    {
+       xfree ((pointer) pPriv);
+       return FALSE;
+    }
+    for (pVisual = pScreen->visuals;
+        pVisual->vid != pScreen->rootVisual;
+        pVisual++)
+       ;
+    pPriv->pVisual = pVisual;
+    pPriv->CloseScreen = pScreen->CloseScreen;
+    pPriv->GetImage = pScreen->GetImage;
+    pPriv->GetSpans = pScreen->GetSpans;
+    pPriv->SourceValidate = pScreen->SourceValidate;
+    pPriv->CreateGC = pScreen->CreateGC;
+    pPriv->BlockHandler = pScreen->BlockHandler;
+    pPriv->InstallColormap = pScreen->InstallColormap;
+    pPriv->StoreColors = pScreen->StoreColors;
+
+    pPriv->PaintWindowBackground = pScreen->PaintWindowBackground;
+    pPriv->PaintWindowBorder = pScreen->PaintWindowBorder;
+    pPriv->CopyWindow = pScreen->CopyWindow;
+    pPriv->ClearToBackground = pScreen->ClearToBackground;
+
+    pPriv->SaveDoomedAreas = pScreen->SaveDoomedAreas;
+    pPriv->RestoreAreas = pScreen->RestoreAreas;
+
+    pPriv->pCursor = NULL;
+    pPriv->x = 0;
+    pPriv->y = 0;
+    pPriv->isUp = FALSE;
+    pPriv->shouldBeUp = FALSE;
+    pPriv->pCacheWin = NullWindow;
+    pPriv->isInCacheWin = FALSE;
+    pPriv->checkPixels = TRUE;
+    pPriv->pInstalledMap = NULL;
+    pPriv->pColormap = NULL;
+    pPriv->funcs = cursorFuncs;
+    pPriv->colors[SOURCE_COLOR].red = 0;
+    pPriv->colors[SOURCE_COLOR].green = 0;
+    pPriv->colors[SOURCE_COLOR].blue = 0;
+    pPriv->colors[MASK_COLOR].red = 0;
+    pPriv->colors[MASK_COLOR].green = 0;
+    pPriv->colors[MASK_COLOR].blue = 0;
+    pScreen->devPrivates[miSpriteScreenIndex].ptr = (pointer) pPriv;
+    pScreen->CloseScreen = miSpriteCloseScreen;
+    pScreen->GetImage = miSpriteGetImage;
+    pScreen->GetSpans = miSpriteGetSpans;
+    pScreen->SourceValidate = miSpriteSourceValidate;
+    pScreen->CreateGC = miSpriteCreateGC;
+    pScreen->BlockHandler = miSpriteBlockHandler;
+    pScreen->InstallColormap = miSpriteInstallColormap;
+    pScreen->StoreColors = miSpriteStoreColors;
+
+    pScreen->PaintWindowBackground = miSpritePaintWindowBackground;
+    pScreen->PaintWindowBorder = miSpritePaintWindowBorder;
+    pScreen->CopyWindow = miSpriteCopyWindow;
+    pScreen->ClearToBackground = miSpriteClearToBackground;
+
+    pScreen->SaveDoomedAreas = miSpriteSaveDoomedAreas;
+    pScreen->RestoreAreas = miSpriteRestoreAreas;
+
+    return TRUE;
+}
+
+/*
+ * Screen wrappers
+ */
+
+/*
+ * CloseScreen wrapper -- unwrap everything, free the private data
+ * and call the wrapped function
+ */
+
+static Bool
+miSpriteCloseScreen (i, pScreen)
+    ScreenPtr  pScreen;
+{
+    miSpriteScreenPtr   pScreenPriv;
+
+    pScreenPriv = (miSpriteScreenPtr) pScreen->devPrivates[miSpriteScreenIndex].ptr;
+
+    pScreen->CloseScreen = pScreenPriv->CloseScreen;
+    pScreen->GetImage = pScreenPriv->GetImage;
+    pScreen->GetSpans = pScreenPriv->GetSpans;
+    pScreen->SourceValidate = pScreenPriv->SourceValidate;
+    pScreen->CreateGC = pScreenPriv->CreateGC;
+    pScreen->BlockHandler = pScreenPriv->BlockHandler;
+    pScreen->InstallColormap = pScreenPriv->InstallColormap;
+    pScreen->StoreColors = pScreenPriv->StoreColors;
+
+    pScreen->PaintWindowBackground = pScreenPriv->PaintWindowBackground;
+    pScreen->PaintWindowBorder = pScreenPriv->PaintWindowBorder;
+    pScreen->CopyWindow = pScreenPriv->CopyWindow;
+    pScreen->ClearToBackground = pScreenPriv->ClearToBackground;
+
+    pScreen->SaveDoomedAreas = pScreenPriv->SaveDoomedAreas;
+    pScreen->RestoreAreas = pScreenPriv->RestoreAreas;
+
+    xfree ((pointer) pScreenPriv);
+
+    return (*pScreen->CloseScreen) (i, pScreen);
+}
+
+static void
+miSpriteGetImage (pDrawable, sx, sy, w, h, format, planemask, pdstLine)
+    DrawablePtr            pDrawable;
+    int                    sx, sy, w, h;
+    unsigned int    format;
+    unsigned long   planemask;
+    char           *pdstLine;
+{
+    ScreenPtr      pScreen = pDrawable->pScreen;
+    miSpriteScreenPtr    pScreenPriv;
+    
+    SCREEN_PROLOGUE (pScreen, GetImage);
+
+    pScreenPriv = (miSpriteScreenPtr) pScreen->devPrivates[miSpriteScreenIndex].ptr;
+
+    if (pDrawable->type == DRAWABLE_WINDOW &&
+        pScreenPriv->isUp &&
+       ORG_OVERLAP(&pScreenPriv->saved,pDrawable->x,pDrawable->y, sx, sy, w, h))
+    {
+       miSpriteRemoveCursor (pScreen);
+    }
+
+    (*pScreen->GetImage) (pDrawable, sx, sy, w, h,
+                         format, planemask, pdstLine);
+
+    SCREEN_EPILOGUE (pScreen, GetImage, miSpriteGetImage);
+}
+
+static void
+miSpriteGetSpans (pDrawable, wMax, ppt, pwidth, nspans, pdstStart)
+    DrawablePtr        pDrawable;
+    int                wMax;
+    DDXPointPtr        ppt;
+    int                *pwidth;
+    int                nspans;
+    char       *pdstStart;
+{
+    ScreenPtr              pScreen = pDrawable->pScreen;
+    miSpriteScreenPtr      pScreenPriv;
+    
+    SCREEN_PROLOGUE (pScreen, GetSpans);
+
+    pScreenPriv = (miSpriteScreenPtr) pScreen->devPrivates[miSpriteScreenIndex].ptr;
+
+    if (pDrawable->type == DRAWABLE_WINDOW && pScreenPriv->isUp)
+    {
+       register DDXPointPtr    pts;
+       register int            *widths;
+       register int            nPts;
+       register int            xorg,
+                               yorg;
+
+       xorg = pDrawable->x;
+       yorg = pDrawable->y;
+
+       for (pts = ppt, widths = pwidth, nPts = nspans;
+            nPts--;
+            pts++, widths++)
+       {
+           if (SPN_OVERLAP(&pScreenPriv->saved,pts->y+yorg,
+                            pts->x+xorg,*widths))
+           {
+               miSpriteRemoveCursor (pScreen);
+               break;
+           }
+       }
+    }
+
+    (*pScreen->GetSpans) (pDrawable, wMax, ppt, pwidth, nspans, pdstStart);
+
+    SCREEN_EPILOGUE (pScreen, GetSpans, miSpriteGetSpans);
+}
+
+static void
+miSpriteSourceValidate (pDrawable, x, y, width, height)
+    DrawablePtr        pDrawable;
+    int                x, y, width, height;
+{
+    ScreenPtr              pScreen = pDrawable->pScreen;
+    miSpriteScreenPtr      pScreenPriv;
+    
+    SCREEN_PROLOGUE (pScreen, SourceValidate);
+
+    pScreenPriv = (miSpriteScreenPtr) pScreen->devPrivates[miSpriteScreenIndex].ptr;
+
+    if (pDrawable->type == DRAWABLE_WINDOW && pScreenPriv->isUp &&
+       ORG_OVERLAP(&pScreenPriv->saved, pDrawable->x, pDrawable->y,
+                   x, y, width, height))
+    {
+       miSpriteRemoveCursor (pScreen);
+    }
+
+    if (pScreen->SourceValidate)
+       (*pScreen->SourceValidate) (pDrawable, x, y, width, height);
+
+    SCREEN_EPILOGUE (pScreen, SourceValidate, miSpriteSourceValidate);
+}
+
+static Bool
+miSpriteCreateGC (pGC)
+    GCPtr   pGC;
+{
+    ScreenPtr      pScreen = pGC->pScreen;
+    Bool           ret;
+    miSpriteGCPtr   pPriv;
+
+    SCREEN_PROLOGUE (pScreen, CreateGC);
+    
+    pPriv = (miSpriteGCPtr)pGC->devPrivates[miSpriteGCIndex].ptr;
+
+    ret = (*pScreen->CreateGC) (pGC);
+
+    pPriv->wrapOps = NULL;
+    pPriv->wrapFuncs = pGC->funcs;
+    pGC->funcs = &miSpriteGCFuncs;
+
+    SCREEN_EPILOGUE (pScreen, CreateGC, miSpriteCreateGC);
+
+    return ret;
+}
+
+static void
+miSpriteBlockHandler (i, blockData, pTimeout, pReadmask)
+    int        i;
+    pointer    blockData;
+    OSTimePtr  pTimeout;
+    pointer    pReadmask;
+{
+    ScreenPtr          pScreen = screenInfo.screens[i];
+    miSpriteScreenPtr  pPriv;
+
+    pPriv = (miSpriteScreenPtr) pScreen->devPrivates[miSpriteScreenIndex].ptr;
+
+    SCREEN_PROLOGUE(pScreen, BlockHandler);
+    
+    (*pScreen->BlockHandler) (i, blockData, pTimeout, pReadmask);
+
+    SCREEN_EPILOGUE(pScreen, BlockHandler, miSpriteBlockHandler);
+
+    if (!pPriv->isUp && pPriv->shouldBeUp)
+       miSpriteRestoreCursor (pScreen);
+}
+
+static void
+miSpriteInstallColormap (pMap)
+    ColormapPtr        pMap;
+{
+    ScreenPtr          pScreen = pMap->pScreen;
+    miSpriteScreenPtr  pPriv;
+
+    pPriv = (miSpriteScreenPtr) pScreen->devPrivates[miSpriteScreenIndex].ptr;
+
+    SCREEN_PROLOGUE(pScreen, InstallColormap);
+    
+    (*pScreen->InstallColormap) (pMap);
+
+    SCREEN_EPILOGUE(pScreen, InstallColormap, miSpriteInstallColormap);
+
+    pPriv->pInstalledMap = pMap;
+    if (pPriv->pColormap != pMap)
+    {
+       pPriv->checkPixels = TRUE;
+       if (pPriv->isUp)
+           miSpriteRemoveCursor (pScreen);
+    }
+}
+
+static void
+miSpriteStoreColors (pMap, ndef, pdef)
+    ColormapPtr        pMap;
+    int                ndef;
+    xColorItem *pdef;
+{
+    ScreenPtr          pScreen = pMap->pScreen;
+    miSpriteScreenPtr  pPriv;
+    int                        i;
+    int                        updated;
+    VisualPtr          pVisual;
+
+    pPriv = (miSpriteScreenPtr) pScreen->devPrivates[miSpriteScreenIndex].ptr;
+
+    SCREEN_PROLOGUE(pScreen, StoreColors);
+    
+    (*pScreen->StoreColors) (pMap, ndef, pdef);
+
+    SCREEN_EPILOGUE(pScreen, StoreColors, miSpriteStoreColors);
+
+    if (pPriv->pColormap == pMap)
+    {
+       updated = 0;
+       pVisual = pMap->pVisual;
+       if (pVisual->class == DirectColor)
+       {
+           /* Direct color - match on any of the subfields */
+
+#define MaskMatch(a,b,mask) ((a) & (pVisual->mask) == (b) & (pVisual->mask))
+
+#define UpdateDAC(plane,dac,mask) {\
+    if (MaskMatch (pPriv->colors[plane].pixel,pdef[i].pixel,mask)) {\
+       pPriv->colors[plane].dac = pdef[i].dac; \
+       updated = 1; \
+    } \
+}
+
+#define CheckDirect(plane) \
+           UpdateDAC(plane,red,redMask) \
+           UpdateDAC(plane,green,greenMask) \
+           UpdateDAC(plane,blue,blueMask)
+
+           for (i = 0; i < ndef; i++)
+           {
+               CheckDirect (SOURCE_COLOR)
+               CheckDirect (MASK_COLOR)
+           }
+       }
+       else
+       {
+           /* PseudoColor/GrayScale - match on exact pixel */
+           for (i = 0; i < ndef; i++)
+           {
+               if (pdef[i].pixel == pPriv->colors[SOURCE_COLOR].pixel)
+               {
+                   pPriv->colors[SOURCE_COLOR] = pdef[i];
+                   if (++updated == 2)
+                       break;
+               }
+               if (pdef[i].pixel == pPriv->colors[MASK_COLOR].pixel)
+               {
+                   pPriv->colors[MASK_COLOR] = pdef[i];
+                   if (++updated == 2)
+                       break;
+               }
+           }
+       }
+       if (updated)
+       {
+           pPriv->checkPixels = TRUE;
+           if (pPriv->isUp)
+               miSpriteRemoveCursor (pScreen);
+       }
+    }
+}
+
+static void
+miSpriteFindColors (pScreen)
+    ScreenPtr  pScreen;
+{
+    miSpriteScreenPtr  pScreenPriv = (miSpriteScreenPtr)
+                           pScreen->devPrivates[miSpriteScreenIndex].ptr;
+    CursorPtr          pCursor;
+    xColorItem         *sourceColor, *maskColor;
+
+    pCursor = pScreenPriv->pCursor;
+    sourceColor = &pScreenPriv->colors[SOURCE_COLOR];
+    maskColor = &pScreenPriv->colors[MASK_COLOR];
+    if (pScreenPriv->pColormap != pScreenPriv->pInstalledMap ||
+       !(pCursor->foreRed == sourceColor->red &&
+         pCursor->foreGreen == sourceColor->green &&
+          pCursor->foreBlue == sourceColor->blue &&
+         pCursor->backRed == maskColor->red &&
+         pCursor->backGreen == maskColor->green &&
+         pCursor->backBlue == maskColor->blue))
+    {
+       pScreenPriv->pColormap = pScreenPriv->pInstalledMap;
+       sourceColor->red = pCursor->foreRed;
+       sourceColor->green = pCursor->foreGreen;
+       sourceColor->blue = pCursor->foreBlue;
+       FakeAllocColor (pScreenPriv->pColormap, sourceColor);
+       maskColor->red = pCursor->backRed;
+       maskColor->green = pCursor->backGreen;
+       maskColor->blue = pCursor->backBlue;
+       FakeAllocColor (pScreenPriv->pColormap, maskColor);
+       /* "free" the pixels right away, don't let this confuse you */
+       FakeFreeColor(pScreenPriv->pColormap, sourceColor->pixel);
+       FakeFreeColor(pScreenPriv->pColormap, maskColor->pixel);
+    }
+    pScreenPriv->checkPixels = FALSE;
+}
+
+/*
+ * BackingStore wrappers
+ */
+
+static void
+miSpriteSaveDoomedAreas (pWin, pObscured, dx, dy)
+    WindowPtr  pWin;
+    RegionPtr  pObscured;
+    int                dx, dy;
+{
+    ScreenPtr          pScreen;
+    miSpriteScreenPtr   pScreenPriv;
+    BoxRec             cursorBox;
+
+    pScreen = pWin->drawable.pScreen;
+    
+    SCREEN_PROLOGUE (pScreen, SaveDoomedAreas);
+
+    pScreenPriv = (miSpriteScreenPtr) pScreen->devPrivates[miSpriteScreenIndex].ptr;
+    if (pScreenPriv->isUp)
+    {
+       cursorBox = pScreenPriv->saved;
+
+       if (dx || dy)
+       {
+           cursorBox.x1 += dx;
+           cursorBox.y1 += dy;
+           cursorBox.x2 += dx;
+           cursorBox.y2 += dy;
+       }
+       if (RECT_IN_REGION( pScreen, pObscured, &cursorBox) != rgnOUT)
+           miSpriteRemoveCursor (pScreen);
+    }
+
+    (*pScreen->SaveDoomedAreas) (pWin, pObscured, dx, dy);
+
+    SCREEN_EPILOGUE (pScreen, SaveDoomedAreas, miSpriteSaveDoomedAreas);
+}
+
+static RegionPtr
+miSpriteRestoreAreas (pWin, prgnExposed)
+    WindowPtr  pWin;
+    RegionPtr  prgnExposed;
+{
+    ScreenPtr          pScreen;
+    miSpriteScreenPtr   pScreenPriv;
+    RegionPtr          result;
+
+    pScreen = pWin->drawable.pScreen;
+    
+    SCREEN_PROLOGUE (pScreen, RestoreAreas);
+
+    pScreenPriv = (miSpriteScreenPtr) pScreen->devPrivates[miSpriteScreenIndex].ptr;
+    if (pScreenPriv->isUp)
+    {
+       if (RECT_IN_REGION( pScreen, prgnExposed, &pScreenPriv->saved) != rgnOUT)
+           miSpriteRemoveCursor (pScreen);
+    }
+
+    result = (*pScreen->RestoreAreas) (pWin, prgnExposed);
+
+    SCREEN_EPILOGUE (pScreen, RestoreAreas, miSpriteRestoreAreas);
+
+    return result;
+}
+
+/*
+ * Window wrappers
+ */
+
+static void
+miSpritePaintWindowBackground (pWin, pRegion, what)
+    WindowPtr  pWin;
+    RegionPtr  pRegion;
+    int                what;
+{
+    ScreenPtr      pScreen;
+    miSpriteScreenPtr    pScreenPriv;
+
+    pScreen = pWin->drawable.pScreen;
+
+    SCREEN_PROLOGUE (pScreen, PaintWindowBackground);
+
+    pScreenPriv = (miSpriteScreenPtr) pScreen->devPrivates[miSpriteScreenIndex].ptr;
+    if (pScreenPriv->isUp)
+    {
+       /*
+        * If the cursor is on the same screen as the window, check the
+        * region to paint for the cursor and remove it as necessary
+        */
+       if (RECT_IN_REGION( pScreen, pRegion, &pScreenPriv->saved) != rgnOUT)
+           miSpriteRemoveCursor (pScreen);
+    }
+
+    (*pScreen->PaintWindowBackground) (pWin, pRegion, what);
+
+    SCREEN_EPILOGUE (pScreen, PaintWindowBackground, miSpritePaintWindowBackground);
+}
+
+static void
+miSpritePaintWindowBorder (pWin, pRegion, what)
+    WindowPtr  pWin;
+    RegionPtr  pRegion;
+    int                what;
+{
+    ScreenPtr      pScreen;
+    miSpriteScreenPtr    pScreenPriv;
+
+    pScreen = pWin->drawable.pScreen;
+
+    SCREEN_PROLOGUE (pScreen, PaintWindowBorder);
+
+    pScreenPriv = (miSpriteScreenPtr) pScreen->devPrivates[miSpriteScreenIndex].ptr;
+    if (pScreenPriv->isUp)
+    {
+       /*
+        * If the cursor is on the same screen as the window, check the
+        * region to paint for the cursor and remove it as necessary
+        */
+       if (RECT_IN_REGION( pScreen, pRegion, &pScreenPriv->saved) != rgnOUT)
+           miSpriteRemoveCursor (pScreen);
+    }
+
+    (*pScreen->PaintWindowBorder) (pWin, pRegion, what);
+
+    SCREEN_EPILOGUE (pScreen, PaintWindowBorder, miSpritePaintWindowBorder);
+}
+
+static void
+miSpriteCopyWindow (pWin, ptOldOrg, pRegion)
+    WindowPtr  pWin;
+    DDXPointRec        ptOldOrg;
+    RegionPtr  pRegion;
+{
+    ScreenPtr      pScreen;
+    miSpriteScreenPtr    pScreenPriv;
+    BoxRec         cursorBox;
+    int                    dx, dy;
+
+    pScreen = pWin->drawable.pScreen;
+
+    SCREEN_PROLOGUE (pScreen, CopyWindow);
+
+    pScreenPriv = (miSpriteScreenPtr) pScreen->devPrivates[miSpriteScreenIndex].ptr;
+    if (pScreenPriv->isUp)
+    {
+       /*
+        * check both the source and the destination areas.  The given
+        * region is source relative, so offset the cursor box by
+        * the delta position
+        */
+       cursorBox = pScreenPriv->saved;
+       dx = pWin->drawable.x - ptOldOrg.x;
+       dy = pWin->drawable.y - ptOldOrg.y;
+       cursorBox.x1 -= dx;
+       cursorBox.x2 -= dx;
+       cursorBox.y1 -= dy;
+       cursorBox.y2 -= dy;
+       if (RECT_IN_REGION( pScreen, pRegion, &pScreenPriv->saved) != rgnOUT ||
+           RECT_IN_REGION( pScreen, pRegion, &cursorBox) != rgnOUT)
+           miSpriteRemoveCursor (pScreen);
+    }
+
+    (*pScreen->CopyWindow) (pWin, ptOldOrg, pRegion);
+
+    SCREEN_EPILOGUE (pScreen, CopyWindow, miSpriteCopyWindow);
+}
+
+static void
+miSpriteClearToBackground (pWin, x, y, w, h, generateExposures)
+    WindowPtr pWin;
+    short x,y;
+    unsigned short w,h;
+    Bool generateExposures;
+{
+    ScreenPtr          pScreen;
+    miSpriteScreenPtr  pScreenPriv;
+    int                        realw, realh;
+
+    pScreen = pWin->drawable.pScreen;
+
+    SCREEN_PROLOGUE (pScreen, ClearToBackground);
+
+    pScreenPriv = (miSpriteScreenPtr) pScreen->devPrivates[miSpriteScreenIndex].ptr;
+    if (GC_CHECK(pWin))
+    {
+       if (!(realw = w))
+           realw = (int) pWin->drawable.width - x;
+       if (!(realh = h))
+           realh = (int) pWin->drawable.height - y;
+       if (ORG_OVERLAP(&pScreenPriv->saved, pWin->drawable.x, pWin->drawable.y,
+                       x, y, realw, realh))
+       {
+           miSpriteRemoveCursor (pScreen);
+       }
+    }
+
+    (*pScreen->ClearToBackground) (pWin, x, y, w, h, generateExposures);
+
+    SCREEN_EPILOGUE (pScreen, ClearToBackground, miSpriteClearToBackground);
+}
+
+/*
+ * GC Func wrappers
+ */
+
+static void
+miSpriteValidateGC (pGC, changes, pDrawable)
+    GCPtr      pGC;
+    Mask       changes;
+    DrawablePtr        pDrawable;
+{
+    GC_FUNC_PROLOGUE (pGC);
+
+    (*pGC->funcs->ValidateGC) (pGC, changes, pDrawable);
+    
+    pGCPriv->wrapOps = NULL;
+    if (pDrawable->type == DRAWABLE_WINDOW && ((WindowPtr) pDrawable)->viewable)
+    {
+       WindowPtr   pWin;
+       RegionPtr   pRegion;
+
+       pWin = (WindowPtr) pDrawable;
+       pRegion = &pWin->clipList;
+       if (pGC->subWindowMode == IncludeInferiors)
+           pRegion = &pWin->borderClip;
+       if (REGION_NOTEMPTY(pDrawable->pScreen, pRegion))
+           pGCPriv->wrapOps = pGC->ops;
+    }
+
+    GC_FUNC_EPILOGUE (pGC);
+}
+
+static void
+miSpriteChangeGC (pGC, mask)
+    GCPtr          pGC;
+    unsigned long   mask;
+{
+    GC_FUNC_PROLOGUE (pGC);
+
+    (*pGC->funcs->ChangeGC) (pGC, mask);
+    
+    GC_FUNC_EPILOGUE (pGC);
+}
+
+static void
+miSpriteCopyGC (pGCSrc, mask, pGCDst)
+    GCPtr          pGCSrc, pGCDst;
+    unsigned long   mask;
+{
+    GC_FUNC_PROLOGUE (pGCDst);
+
+    (*pGCDst->funcs->CopyGC) (pGCSrc, mask, pGCDst);
+    
+    GC_FUNC_EPILOGUE (pGCDst);
+}
+
+static void
+miSpriteDestroyGC (pGC)
+    GCPtr   pGC;
+{
+    GC_FUNC_PROLOGUE (pGC);
+
+    (*pGC->funcs->DestroyGC) (pGC);
+    
+    GC_FUNC_EPILOGUE (pGC);
+}
+
+static void
+miSpriteChangeClip (pGC, type, pvalue, nrects)
+    GCPtr   pGC;
+    int                type;
+    pointer    pvalue;
+    int                nrects;
+{
+    GC_FUNC_PROLOGUE (pGC);
+
+    (*pGC->funcs->ChangeClip) (pGC, type, pvalue, nrects);
+
+    GC_FUNC_EPILOGUE (pGC);
+}
+
+static void
+miSpriteCopyClip(pgcDst, pgcSrc)
+    GCPtr pgcDst, pgcSrc;
+{
+    GC_FUNC_PROLOGUE (pgcDst);
+
+    (* pgcDst->funcs->CopyClip)(pgcDst, pgcSrc);
+
+    GC_FUNC_EPILOGUE (pgcDst);
+}
+
+static void
+miSpriteDestroyClip(pGC)
+    GCPtr      pGC;
+{
+    GC_FUNC_PROLOGUE (pGC);
+
+    (* pGC->funcs->DestroyClip)(pGC);
+
+    GC_FUNC_EPILOGUE (pGC);
+}
+
+/*
+ * GC Op wrappers
+ */
+
+static void
+miSpriteFillSpans(pDrawable, pGC, nInit, pptInit, pwidthInit, fSorted)
+    DrawablePtr pDrawable;
+    GCPtr      pGC;
+    int                nInit;                  /* number of spans to fill */
+    DDXPointPtr pptInit;               /* pointer to list of start points */
+    int                *pwidthInit;            /* pointer to list of n widths */
+    int        fSorted;
+{
+    GC_SETUP(pDrawable, pGC);
+
+    if (GC_CHECK((WindowPtr) pDrawable))
+    {
+       register DDXPointPtr    pts;
+       register int            *widths;
+       register int            nPts;
+
+       for (pts = pptInit, widths = pwidthInit, nPts = nInit;
+            nPts--;
+            pts++, widths++)
+       {
+            if (SPN_OVERLAP(&pScreenPriv->saved,pts->y,pts->x,*widths))
+            {
+                miSpriteRemoveCursor (pDrawable->pScreen);
+                break;
+            }
+       }
+    }
+
+    GC_OP_PROLOGUE (pGC);
+
+    (*pGC->ops->FillSpans) (pDrawable, pGC, nInit, pptInit, pwidthInit, fSorted);
+
+    GC_OP_EPILOGUE (pGC);
+}
+
+static void
+miSpriteSetSpans(pDrawable, pGC, psrc, ppt, pwidth, nspans, fSorted)
+    DrawablePtr                pDrawable;
+    GCPtr              pGC;
+    char               *psrc;
+    register DDXPointPtr ppt;
+    int                        *pwidth;
+    int                        nspans;
+    int                        fSorted;
+{
+    GC_SETUP(pDrawable, pGC);
+
+    if (GC_CHECK((WindowPtr) pDrawable))
+    {
+       register DDXPointPtr    pts;
+       register int            *widths;
+       register int            nPts;
+
+       for (pts = ppt, widths = pwidth, nPts = nspans;
+            nPts--;
+            pts++, widths++)
+       {
+            if (SPN_OVERLAP(&pScreenPriv->saved,pts->y,pts->x,*widths))
+            {
+                miSpriteRemoveCursor(pDrawable->pScreen);
+                break;
+            }
+       }
+    }
+
+    GC_OP_PROLOGUE (pGC);
+
+    (*pGC->ops->SetSpans) (pDrawable, pGC, psrc, ppt, pwidth, nspans, fSorted);
+
+    GC_OP_EPILOGUE (pGC);
+}
+
+static void
+miSpritePutImage(pDrawable, pGC, depth, x, y, w, h, leftPad, format, pBits)
+    DrawablePtr          pDrawable;
+    GCPtr        pGC;
+    int                  depth;
+    int                  x;
+    int                  y;
+    int                  w;
+    int                  h;
+    int                  format;
+    char         *pBits;
+{
+    GC_SETUP(pDrawable, pGC);
+
+    if (GC_CHECK((WindowPtr) pDrawable))
+    {
+       if (ORG_OVERLAP(&pScreenPriv->saved,pDrawable->x,pDrawable->y,
+                       x,y,w,h))
+       {
+           miSpriteRemoveCursor (pDrawable->pScreen);
+       }
+    }
+
+    GC_OP_PROLOGUE (pGC);
+
+    (*pGC->ops->PutImage) (pDrawable, pGC, depth, x, y, w, h, leftPad, format, pBits);
+
+    GC_OP_EPILOGUE (pGC);
+}
+
+static RegionPtr
+miSpriteCopyArea (pSrc, pDst, pGC, srcx, srcy, w, h, dstx, dsty)
+    DrawablePtr          pSrc;
+    DrawablePtr          pDst;
+    GCPtr        pGC;
+    int                  srcx;
+    int                  srcy;
+    int                  w;
+    int                  h;
+    int                  dstx;
+    int                  dsty;
+{
+    RegionPtr rgn;
+
+    GC_SETUP(pDst, pGC);
+
+    /* check destination/source overlap. */
+    if (GC_CHECK((WindowPtr) pDst) &&
+        (ORG_OVERLAP(&pScreenPriv->saved,pDst->x,pDst->y,dstx,dsty,w,h) ||
+         ((pDst == pSrc) &&
+          ORG_OVERLAP(&pScreenPriv->saved,pSrc->x,pSrc->y,srcx,srcy,w,h))))
+    {
+       miSpriteRemoveCursor (pDst->pScreen);
+    }
+    GC_OP_PROLOGUE (pGC);
+
+    rgn = (*pGC->ops->CopyArea) (pSrc, pDst, pGC, srcx, srcy, w, h,
+                                dstx, dsty);
+
+    GC_OP_EPILOGUE (pGC);
+
+    return rgn;
+}
+
+static RegionPtr
+miSpriteCopyPlane (pSrc, pDst, pGC, srcx, srcy, w, h, dstx, dsty, plane)
+    DrawablePtr          pSrc;
+    DrawablePtr          pDst;
+    register GCPtr pGC;
+    int          srcx,
+                 srcy;
+    int          w,
+                 h;
+    int          dstx,
+                 dsty;
+    unsigned long  plane;
+{
+    RegionPtr rgn;
+
+    GC_SETUP(pDst, pGC);
+
+    /*
+     * check destination/source for overlap.
+     */
+    if (GC_CHECK((WindowPtr) pDst) &&
+       (ORG_OVERLAP(&pScreenPriv->saved,pDst->x,pDst->y,dstx,dsty,w,h) ||
+        ((pDst == pSrc) &&
+         ORG_OVERLAP(&pScreenPriv->saved,pSrc->x,pSrc->y,srcx,srcy,w,h))))
+    {
+       miSpriteRemoveCursor (pDst->pScreen);
+    }
+
+    GC_OP_PROLOGUE (pGC);
+
+    rgn = (*pGC->ops->CopyPlane) (pSrc, pDst, pGC, srcx, srcy, w, h,
+                                 dstx, dsty, plane);
+
+    GC_OP_EPILOGUE (pGC);
+
+    return rgn;
+}
+
+static void
+miSpritePolyPoint (pDrawable, pGC, mode, npt, pptInit)
+    DrawablePtr pDrawable;
+    GCPtr      pGC;
+    int                mode;           /* Origin or Previous */
+    int                npt;
+    xPoint     *pptInit;
+{
+    xPoint     t;
+    int                n;
+    BoxRec     cursor;
+    register xPoint *pts;
+
+    GC_SETUP (pDrawable, pGC);
+
+    if (npt && GC_CHECK((WindowPtr) pDrawable))
+    {
+       cursor.x1 = pScreenPriv->saved.x1 - pDrawable->x;
+       cursor.y1 = pScreenPriv->saved.y1 - pDrawable->y;
+       cursor.x2 = pScreenPriv->saved.x2 - pDrawable->x;
+       cursor.y2 = pScreenPriv->saved.y2 - pDrawable->y;
+
+       if (mode == CoordModePrevious)
+       {
+           t.x = 0;
+           t.y = 0;
+           for (pts = pptInit, n = npt; n--; pts++)
+           {
+               t.x += pts->x;
+               t.y += pts->y;
+               if (cursor.x1 <= t.x && t.x <= cursor.x2 &&
+                   cursor.y1 <= t.y && t.y <= cursor.y2)
+               {
+                   miSpriteRemoveCursor (pDrawable->pScreen);
+                   break;
+               }
+           }
+       }
+       else
+       {
+           for (pts = pptInit, n = npt; n--; pts++)
+           {
+               if (cursor.x1 <= pts->x && pts->x <= cursor.x2 &&
+                   cursor.y1 <= pts->y && pts->y <= cursor.y2)
+               {
+                   miSpriteRemoveCursor (pDrawable->pScreen);
+                   break;
+               }
+           }
+       }
+    }
+
+    GC_OP_PROLOGUE (pGC);
+
+    (*pGC->ops->PolyPoint) (pDrawable, pGC, mode, npt, pptInit);
+
+    GC_OP_EPILOGUE (pGC);
+}
+
+static void
+miSpritePolylines (pDrawable, pGC, mode, npt, pptInit)
+    DrawablePtr          pDrawable;
+    GCPtr        pGC;
+    int                  mode;
+    int                  npt;
+    DDXPointPtr          pptInit;
+{
+    BoxPtr  cursor;
+    register DDXPointPtr pts;
+    int            n;
+    int            x, y, x1, y1, x2, y2;
+    int            lw;
+    int            extra;
+
+    GC_SETUP (pDrawable, pGC);
+
+    if (npt && GC_CHECK((WindowPtr) pDrawable))
+    {
+       cursor = &pScreenPriv->saved;
+       lw = pGC->lineWidth;
+       x = pptInit->x + pDrawable->x;
+       y = pptInit->y + pDrawable->y;
+
+       if (npt == 1)
+       {
+           extra = lw >> 1;
+           if (LINE_OVERLAP(cursor, x, y, x, y, extra))
+               miSpriteRemoveCursor (pDrawable->pScreen);
+       }
+       else
+       {
+           extra = lw >> 1;
+           /*
+            * mitered joins can project quite a way from
+            * the line end; the 11 degree miter limit limits
+            * this extension to 10.43 * lw / 2, rounded up
+            * and converted to int yields 6 * lw
+            */
+           if (pGC->joinStyle == JoinMiter)
+               extra = 6 * lw;
+           else if (pGC->capStyle == CapProjecting)
+               extra = lw;
+           for (pts = pptInit + 1, n = npt - 1; n--; pts++)
+           {
+               x1 = x;
+               y1 = y;
+               if (mode == CoordModeOrigin)
+               {
+                   x2 = pDrawable->x + pts->x;
+                   y2 = pDrawable->y + pts->y;
+               }
+               else
+               {
+                   x2 = x + pts->x;
+                   y2 = y + pts->y;
+               }
+               x = x2;
+               y = y2;
+               LINE_SORT(x1, y1, x2, y2);
+               if (LINE_OVERLAP(cursor, x1, y1, x2, y2, extra))
+               {
+                   miSpriteRemoveCursor (pDrawable->pScreen);
+                   break;
+               }
+           }
+       }
+    }
+    GC_OP_PROLOGUE (pGC);
+
+    (*pGC->ops->Polylines) (pDrawable, pGC, mode, npt, pptInit);
+
+    GC_OP_EPILOGUE (pGC);
+}
+
+static void
+miSpritePolySegment(pDrawable, pGC, nseg, pSegs)
+    DrawablePtr pDrawable;
+    GCPtr      pGC;
+    int                nseg;
+    xSegment   *pSegs;
+{
+    int            n;
+    register xSegment *segs;
+    BoxPtr  cursor;
+    int            x1, y1, x2, y2;
+    int            extra;
+
+    GC_SETUP(pDrawable, pGC);
+
+    if (nseg && GC_CHECK((WindowPtr) pDrawable))
+    {
+       cursor = &pScreenPriv->saved;
+       extra = pGC->lineWidth >> 1;
+       if (pGC->capStyle == CapProjecting)
+           extra = pGC->lineWidth;
+       for (segs = pSegs, n = nseg; n--; segs++)
+       {
+           x1 = segs->x1 + pDrawable->x;
+           y1 = segs->y1 + pDrawable->y;
+           x2 = segs->x2 + pDrawable->x;
+           y2 = segs->y2 + pDrawable->y;
+           LINE_SORT(x1, y1, x2, y2);
+           if (LINE_OVERLAP(cursor, x1, y1, x2, y2, extra))
+           {
+               miSpriteRemoveCursor (pDrawable->pScreen);
+               break;
+           }
+       }
+    }
+
+    GC_OP_PROLOGUE (pGC);
+
+    (*pGC->ops->PolySegment) (pDrawable, pGC, nseg, pSegs);
+
+    GC_OP_EPILOGUE (pGC);
+}
+
+static void
+miSpritePolyRectangle(pDrawable, pGC, nrects, pRects)
+    DrawablePtr        pDrawable;
+    GCPtr      pGC;
+    int                nrects;
+    xRectangle *pRects;
+{
+    register xRectangle *rects;
+    BoxPtr  cursor;
+    int            lw;
+    int            n;
+    int     x1, y1, x2, y2;
+    
+    GC_SETUP (pDrawable, pGC);
+
+    if (GC_CHECK((WindowPtr) pDrawable))
+    {
+       lw = pGC->lineWidth >> 1;
+       cursor = &pScreenPriv->saved;
+       for (rects = pRects, n = nrects; n--; rects++)
+       {
+           x1 = rects->x + pDrawable->x;
+           y1 = rects->y + pDrawable->y;
+           x2 = x1 + (int)rects->width;
+           y2 = y1 + (int)rects->height;
+           if (LINE_OVERLAP(cursor, x1, y1, x2, y1, lw) ||
+               LINE_OVERLAP(cursor, x2, y1, x2, y2, lw) ||
+               LINE_OVERLAP(cursor, x1, y2, x2, y2, lw) ||
+               LINE_OVERLAP(cursor, x1, y1, x1, y2, lw))
+           {
+               miSpriteRemoveCursor (pDrawable->pScreen);
+               break;
+           }
+       }
+    }
+
+    GC_OP_PROLOGUE (pGC);
+
+    (*pGC->ops->PolyRectangle) (pDrawable, pGC, nrects, pRects);
+
+    GC_OP_EPILOGUE (pGC);
+}
+
+static void
+miSpritePolyArc(pDrawable, pGC, narcs, parcs)
+    DrawablePtr        pDrawable;
+    register GCPtr     pGC;
+    int                narcs;
+    xArc       *parcs;
+{
+    BoxPtr  cursor;
+    int            lw;
+    int            n;
+    register xArc *arcs;
+    
+    GC_SETUP (pDrawable, pGC);
+
+    if (GC_CHECK((WindowPtr) pDrawable))
+    {
+       lw = pGC->lineWidth >> 1;
+       cursor = &pScreenPriv->saved;
+       for (arcs = parcs, n = narcs; n--; arcs++)
+       {
+           if (ORG_OVERLAP (cursor, pDrawable->x, pDrawable->y,
+                            arcs->x - lw, arcs->y - lw,
+                            (int) arcs->width + pGC->lineWidth,
+                            (int) arcs->height + pGC->lineWidth))
+           {
+               miSpriteRemoveCursor (pDrawable->pScreen);
+               break;
+           }
+       }
+    }
+
+    GC_OP_PROLOGUE (pGC);
+
+    (*pGC->ops->PolyArc) (pDrawable, pGC, narcs, parcs);
+
+    GC_OP_EPILOGUE (pGC);
+}
+
+static void
+miSpriteFillPolygon(pDrawable, pGC, shape, mode, count, pPts)
+    register DrawablePtr pDrawable;
+    register GCPtr     pGC;
+    int                        shape, mode;
+    int                        count;
+    DDXPointPtr                pPts;
+{
+    int x, y, minx, miny, maxx, maxy;
+    register DDXPointPtr pts;
+    int n;
+
+    GC_SETUP (pDrawable, pGC);
+
+    if (count && GC_CHECK((WindowPtr) pDrawable))
+    {
+       x = pDrawable->x;
+       y = pDrawable->y;
+       pts = pPts;
+       minx = maxx = pts->x;
+       miny = maxy = pts->y;
+       pts++;
+       n = count - 1;
+
+       if (mode == CoordModeOrigin)
+       {
+           for (; n--; pts++)
+           {
+               if (pts->x < minx)
+                   minx = pts->x;
+               else if (pts->x > maxx)
+                   maxx = pts->x;
+               if (pts->y < miny)
+                   miny = pts->y;
+               else if (pts->y > maxy)
+                   maxy = pts->y;
+           }
+           minx += x;
+           miny += y;
+           maxx += x;
+           maxy += y;
+       }
+       else
+       {
+           x += minx;
+           y += miny;
+           minx = maxx = x;
+           miny = maxy = y;
+           for (; n--; pts++)
+           {
+               x += pts->x;
+               y += pts->y;
+               if (x < minx)
+                   minx = x;
+               else if (x > maxx)
+                   maxx = x;
+               if (y < miny)
+                   miny = y;
+               else if (y > maxy)
+                   maxy = y;
+           }
+       }
+       if (BOX_OVERLAP(&pScreenPriv->saved,minx,miny,maxx,maxy))
+           miSpriteRemoveCursor (pDrawable->pScreen);
+    }
+
+    GC_OP_PROLOGUE (pGC);
+
+    (*pGC->ops->FillPolygon) (pDrawable, pGC, shape, mode, count, pPts);
+
+    GC_OP_EPILOGUE (pGC);
+}
+
+static void
+miSpritePolyFillRect(pDrawable, pGC, nrectFill, prectInit)
+    DrawablePtr pDrawable;
+    GCPtr      pGC;
+    int                nrectFill;      /* number of rectangles to fill */
+    xRectangle *prectInit;     /* Pointer to first rectangle to fill */
+{
+    GC_SETUP(pDrawable, pGC);
+
+    if (GC_CHECK((WindowPtr) pDrawable))
+    {
+       register int        nRect;
+       register xRectangle *pRect;
+       register int        xorg, yorg;
+
+       xorg = pDrawable->x;
+       yorg = pDrawable->y;
+
+       for (nRect = nrectFill, pRect = prectInit; nRect--; pRect++) {
+           if (ORGRECT_OVERLAP(&pScreenPriv->saved,xorg,yorg,pRect)){
+               miSpriteRemoveCursor(pDrawable->pScreen);
+               break;
+           }
+       }
+    }
+
+    GC_OP_PROLOGUE (pGC);
+
+    (*pGC->ops->PolyFillRect) (pDrawable, pGC, nrectFill, prectInit);
+
+    GC_OP_EPILOGUE (pGC);
+}
+
+static void
+miSpritePolyFillArc(pDrawable, pGC, narcs, parcs)
+    DrawablePtr        pDrawable;
+    GCPtr      pGC;
+    int                narcs;
+    xArc       *parcs;
+{
+    GC_SETUP(pDrawable, pGC);
+
+    if (GC_CHECK((WindowPtr) pDrawable))
+    {
+       register int    n;
+       BoxPtr          cursor;
+       register xArc *arcs;
+
+       cursor = &pScreenPriv->saved;
+
+       for (arcs = parcs, n = narcs; n--; arcs++)
+       {
+           if (ORG_OVERLAP(cursor, pDrawable->x, pDrawable->y,
+                           arcs->x, arcs->y,
+                           (int) arcs->width, (int) arcs->height))
+           {
+               miSpriteRemoveCursor (pDrawable->pScreen);
+               break;
+           }
+       }
+    }
+
+    GC_OP_PROLOGUE (pGC);
+
+    (*pGC->ops->PolyFillArc) (pDrawable, pGC, narcs, parcs);
+
+    GC_OP_EPILOGUE (pGC);
+}
+
+/*
+ * general Poly/Image text function.  Extract glyph information,
+ * compute bounding box and remove cursor if it is overlapped.
+ */
+
+static Bool
+miSpriteTextOverlap (pDraw, font, x, y, n, charinfo, imageblt, w, cursorBox)
+    DrawablePtr   pDraw;
+    FontPtr      font;
+    int                  x, y;
+    unsigned int  n;
+    CharInfoPtr   *charinfo;
+    Bool         imageblt;
+    unsigned int  w;
+    BoxPtr       cursorBox;
+{
+    ExtentInfoRec extents;
+
+    x += pDraw->x;
+    y += pDraw->y;
+
+    if (FONTMINBOUNDS(font,characterWidth) >= 0)
+    {
+       /* compute an approximate (but covering) bounding box */
+       if (!imageblt || (charinfo[0]->metrics.leftSideBearing < 0))
+           extents.overallLeft = charinfo[0]->metrics.leftSideBearing;
+       else
+           extents.overallLeft = 0;
+       if (w)
+           extents.overallRight = w - charinfo[n-1]->metrics.characterWidth;
+       else
+           extents.overallRight = FONTMAXBOUNDS(font,characterWidth)
+                                   * (n - 1);
+       if (imageblt && (charinfo[n-1]->metrics.characterWidth >
+                        charinfo[n-1]->metrics.rightSideBearing))
+           extents.overallRight += charinfo[n-1]->metrics.characterWidth;
+       else
+           extents.overallRight += charinfo[n-1]->metrics.rightSideBearing;
+       if (imageblt && FONTASCENT(font) > FONTMAXBOUNDS(font,ascent))
+           extents.overallAscent = FONTASCENT(font);
+       else
+           extents.overallAscent = FONTMAXBOUNDS(font, ascent);
+       if (imageblt && FONTDESCENT(font) > FONTMAXBOUNDS(font,descent))
+           extents.overallDescent = FONTDESCENT(font);
+       else
+           extents.overallDescent = FONTMAXBOUNDS(font,descent);
+       if (!BOX_OVERLAP(cursorBox,
+                        x + extents.overallLeft,
+                        y - extents.overallAscent,
+                        x + extents.overallRight,
+                        y + extents.overallDescent))
+           return FALSE;
+       else if (imageblt && w)
+           return TRUE;
+       /* if it does overlap, fall through and compute exactly, because
+        * taking down the cursor is expensive enough to make this worth it
+        */
+    }
+    QueryGlyphExtents(font, charinfo, n, &extents);
+    if (imageblt)
+    {
+       if (extents.overallWidth > extents.overallRight)
+           extents.overallRight = extents.overallWidth;
+       if (extents.overallWidth < extents.overallLeft)
+           extents.overallLeft = extents.overallWidth;
+       if (extents.overallLeft > 0)
+           extents.overallLeft = 0;
+       if (extents.fontAscent > extents.overallAscent)
+           extents.overallAscent = extents.fontAscent;
+       if (extents.fontDescent > extents.overallDescent)
+           extents.overallDescent = extents.fontDescent;
+    }
+    return (BOX_OVERLAP(cursorBox,
+                       x + extents.overallLeft,
+                       y - extents.overallAscent,
+                       x + extents.overallRight,
+                       y + extents.overallDescent));
+}
+
+/*
+ * values for textType:
+ */
+#define TT_POLY8   0
+#define TT_IMAGE8  1
+#define TT_POLY16  2
+#define TT_IMAGE16 3
+
+static int 
+miSpriteText (pDraw, pGC, x, y, count, chars, fontEncoding, textType, cursorBox)
+    DrawablePtr            pDraw;
+    GCPtr          pGC;
+    int                    x,
+                   y;
+    unsigned long    count;
+    char           *chars;
+    FontEncoding    fontEncoding;
+    Bool           textType;
+    BoxPtr         cursorBox;
+{
+    CharInfoPtr *charinfo;
+    register CharInfoPtr *info;
+    unsigned long i;
+    unsigned int  n;
+    int                  w;
+    void         (*drawFunc)();
+
+    Bool imageblt;
+
+    imageblt = (textType == TT_IMAGE8) || (textType == TT_IMAGE16);
+
+    charinfo = (CharInfoPtr *) ALLOCATE_LOCAL(count * sizeof(CharInfoPtr));
+    if (!charinfo)
+       return x;
+
+    GetGlyphs(pGC->font, count, (unsigned char *)chars,
+             fontEncoding, &i, charinfo);
+    n = (unsigned int)i;
+    w = 0;
+    if (!imageblt)
+       for (info = charinfo; i--; info++)
+           w += (*info)->metrics.characterWidth;
+
+    if (n != 0) {
+       if (miSpriteTextOverlap(pDraw, pGC->font, x, y, n, charinfo, imageblt, w, cursorBox))
+           miSpriteRemoveCursor(pDraw->pScreen);
+
+#ifdef AVOID_GLYPHBLT
+       /*
+        * On displays like Apollos, which do not optimize the GlyphBlt functions because they
+        * convert fonts to their internal form in RealizeFont and optimize text directly, we
+        * want to invoke the text functions here, not the GlyphBlt functions.
+        */
+       switch (textType)
+       {
+       case TT_POLY8:
+           drawFunc = (void (*)())pGC->ops->PolyText8;
+           break;
+       case TT_IMAGE8:
+           drawFunc = pGC->ops->ImageText8;
+           break;
+       case TT_POLY16:
+           drawFunc = (void (*)())pGC->ops->PolyText16;
+           break;
+       case TT_IMAGE16:
+           drawFunc = pGC->ops->ImageText16;
+           break;
+       }
+       (*drawFunc) (pDraw, pGC, x, y, (int) count, chars);
+#else /* don't AVOID_GLYPHBLT */
+       /*
+        * On the other hand, if the device does use GlyphBlt ultimately to do text, we
+        * don't want to slow it down by invoking the text functions and having them call
+        * GetGlyphs all over again, so we go directly to the GlyphBlt functions here.
+        */
+       drawFunc = imageblt ? pGC->ops->ImageGlyphBlt : pGC->ops->PolyGlyphBlt;
+       (*drawFunc) (pDraw, pGC, x, y, n, charinfo, FONTGLYPHS(pGC->font));
+#endif /* AVOID_GLYPHBLT */
+    }
+    DEALLOCATE_LOCAL(charinfo);
+    return x + w;
+}
+
+static int
+miSpritePolyText8(pDrawable, pGC, x, y, count, chars)
+    DrawablePtr pDrawable;
+    GCPtr      pGC;
+    int                x, y;
+    int        count;
+    char       *chars;
+{
+    int        ret;
+
+    GC_SETUP (pDrawable, pGC);
+
+    GC_OP_PROLOGUE (pGC);
+
+    if (GC_CHECK((WindowPtr) pDrawable))
+       ret = miSpriteText (pDrawable, pGC, x, y, (unsigned long)count, chars,
+                           Linear8Bit, TT_POLY8, &pScreenPriv->saved);
+    else
+       ret = (*pGC->ops->PolyText8) (pDrawable, pGC, x, y, count, chars);
+
+    GC_OP_EPILOGUE (pGC);
+    return ret;
+}
+
+static int
+miSpritePolyText16(pDrawable, pGC, x, y, count, chars)
+    DrawablePtr pDrawable;
+    GCPtr      pGC;
+    int                x, y;
+    int                count;
+    unsigned short *chars;
+{
+    int        ret;
+
+    GC_SETUP(pDrawable, pGC);
+
+    GC_OP_PROLOGUE (pGC);
+
+    if (GC_CHECK((WindowPtr) pDrawable))
+       ret = miSpriteText (pDrawable, pGC, x, y, (unsigned long)count,
+                           (char *)chars,
+                           FONTLASTROW(pGC->font) == 0 ?
+                           Linear16Bit : TwoD16Bit, TT_POLY16, &pScreenPriv->saved);
+    else
+       ret = (*pGC->ops->PolyText16) (pDrawable, pGC, x, y, count, chars);
+
+    GC_OP_EPILOGUE (pGC);
+    return ret;
+}
+
+static void
+miSpriteImageText8(pDrawable, pGC, x, y, count, chars)
+    DrawablePtr pDrawable;
+    GCPtr      pGC;
+    int                x, y;
+    int                count;
+    char       *chars;
+{
+    GC_SETUP(pDrawable, pGC);
+
+    GC_OP_PROLOGUE (pGC);
+
+    if (GC_CHECK((WindowPtr) pDrawable))
+       (void) miSpriteText (pDrawable, pGC, x, y, (unsigned long)count,
+                            chars, Linear8Bit, TT_IMAGE8, &pScreenPriv->saved);
+    else
+       (*pGC->ops->ImageText8) (pDrawable, pGC, x, y, count, chars);
+
+    GC_OP_EPILOGUE (pGC);
+}
+
+static void
+miSpriteImageText16(pDrawable, pGC, x, y, count, chars)
+    DrawablePtr pDrawable;
+    GCPtr      pGC;
+    int                x, y;
+    int                count;
+    unsigned short *chars;
+{
+    GC_SETUP(pDrawable, pGC);
+
+    GC_OP_PROLOGUE (pGC);
+
+    if (GC_CHECK((WindowPtr) pDrawable))
+       (void) miSpriteText (pDrawable, pGC, x, y, (unsigned long)count,
+                            (char *)chars,
+                           FONTLASTROW(pGC->font) == 0 ?
+                           Linear16Bit : TwoD16Bit, TT_IMAGE16, &pScreenPriv->saved);
+    else
+       (*pGC->ops->ImageText16) (pDrawable, pGC, x, y, count, chars);
+
+    GC_OP_EPILOGUE (pGC);
+}
+
+static void
+miSpriteImageGlyphBlt(pDrawable, pGC, x, y, nglyph, ppci, pglyphBase)
+    DrawablePtr pDrawable;
+    GCPtr      pGC;
+    int        x, y;
+    unsigned int nglyph;
+    CharInfoPtr *ppci;         /* array of character info */
+    pointer    pglyphBase;     /* start of array of glyphs */
+{
+    GC_SETUP(pDrawable, pGC);
+
+    GC_OP_PROLOGUE (pGC);
+
+    if (GC_CHECK((WindowPtr) pDrawable) &&
+       miSpriteTextOverlap (pDrawable, pGC->font, x, y, nglyph, ppci, TRUE, 0, &pScreenPriv->saved))
+    {
+       miSpriteRemoveCursor(pDrawable->pScreen);
+    }
+    (*pGC->ops->ImageGlyphBlt) (pDrawable, pGC, x, y, nglyph, ppci, pglyphBase);
+
+    GC_OP_EPILOGUE (pGC);
+}
+
+static void
+miSpritePolyGlyphBlt(pDrawable, pGC, x, y, nglyph, ppci, pglyphBase)
+    DrawablePtr pDrawable;
+    GCPtr      pGC;
+    int        x, y;
+    unsigned int nglyph;
+    CharInfoPtr *ppci;         /* array of character info */
+    pointer    pglyphBase;     /* start of array of glyphs */
+{
+    GC_SETUP (pDrawable, pGC);
+
+    GC_OP_PROLOGUE (pGC);
+
+    if (GC_CHECK((WindowPtr) pDrawable) &&
+       miSpriteTextOverlap (pDrawable, pGC->font, x, y, nglyph, ppci, FALSE, 0, &pScreenPriv->saved))
+    {
+       miSpriteRemoveCursor(pDrawable->pScreen);
+    }
+    (*pGC->ops->PolyGlyphBlt) (pDrawable, pGC, x, y, nglyph, ppci, pglyphBase);
+
+    GC_OP_EPILOGUE (pGC);
+}
+
+static void
+miSpritePushPixels(pGC, pBitMap, pDrawable, w, h, x, y)
+    GCPtr      pGC;
+    PixmapPtr  pBitMap;
+    DrawablePtr pDrawable;
+    int                w, h, x, y;
+{
+    GC_SETUP(pDrawable, pGC);
+
+    if (GC_CHECK((WindowPtr) pDrawable) &&
+       ORG_OVERLAP(&pScreenPriv->saved,pDrawable->x,pDrawable->y,x,y,w,h))
+    {
+       miSpriteRemoveCursor (pDrawable->pScreen);
+    }
+
+    GC_OP_PROLOGUE (pGC);
+
+    (*pGC->ops->PushPixels) (pGC, pBitMap, pDrawable, w, h, x, y);
+
+    GC_OP_EPILOGUE (pGC);
+}
+
+#ifdef NEED_LINEHELPER
+/*
+ * I don't expect this routine will ever be called, as the GC
+ * will have been unwrapped for the line drawing
+ */
+
+static void
+miSpriteLineHelper()
+{
+    FatalError("miSpriteLineHelper called\n");
+}
+#endif
+
+/*
+ * miPointer interface routines
+ */
+
+#define SPRITE_PAD  8
+
+static Bool
+miSpriteRealizeCursor (pScreen, pCursor)
+    ScreenPtr  pScreen;
+    CursorPtr  pCursor;
+{
+    miSpriteScreenPtr  pScreenPriv;
+
+    pScreenPriv = (miSpriteScreenPtr) pScreen->devPrivates[miSpriteScreenIndex].ptr;
+    if (pCursor == pScreenPriv->pCursor)
+       pScreenPriv->checkPixels = TRUE;
+    return (*pScreenPriv->funcs->RealizeCursor) (pScreen, pCursor);
+}
+
+static Bool
+miSpriteUnrealizeCursor (pScreen, pCursor)
+    ScreenPtr  pScreen;
+    CursorPtr  pCursor;
+{
+    miSpriteScreenPtr  pScreenPriv;
+
+    pScreenPriv = (miSpriteScreenPtr) pScreen->devPrivates[miSpriteScreenIndex].ptr;
+    return (*pScreenPriv->funcs->UnrealizeCursor) (pScreen, pCursor);
+}
+
+static void
+miSpriteSetCursor (pScreen, pCursor, x, y)
+    ScreenPtr  pScreen;
+    CursorPtr  pCursor;
+{
+    miSpriteScreenPtr  pScreenPriv;
+
+    pScreenPriv = (miSpriteScreenPtr) pScreen->devPrivates[miSpriteScreenIndex].ptr;
+    pScreenPriv->shouldBeUp = TRUE;
+    if (pScreenPriv->x == x &&
+       pScreenPriv->y == y &&
+       pScreenPriv->pCursor == pCursor &&
+       !pScreenPriv->checkPixels)
+    {
+       return;
+    }
+    if (!pCursor)
+    {
+       pScreenPriv->shouldBeUp = FALSE;
+       if (pScreenPriv->isUp)
+           miSpriteRemoveCursor (pScreen);
+       pScreenPriv->pCursor = 0;
+       return;
+    }
+    pScreenPriv->x = x;
+    pScreenPriv->y = y;
+    pScreenPriv->pCacheWin = NullWindow;
+    if (pScreenPriv->checkPixels || pScreenPriv->pCursor != pCursor)
+    {
+       pScreenPriv->pCursor = pCursor;
+       miSpriteFindColors (pScreen);
+    }
+    if (pScreenPriv->isUp) {
+       int     sx, sy;
+       /*
+        * check to see if the old saved region
+        * encloses the new sprite, in which case we use
+        * the flicker-free MoveCursor primitive.
+        */
+       sx = pScreenPriv->x - (int)pCursor->bits->xhot;
+       sy = pScreenPriv->y - (int)pCursor->bits->yhot;
+       if (sx + (int) pCursor->bits->width >= pScreenPriv->saved.x1 &&
+           sx < pScreenPriv->saved.x2 &&
+           sy + (int) pCursor->bits->height >= pScreenPriv->saved.y1 &&
+           sy < pScreenPriv->saved.y2 &&
+           (int) pCursor->bits->width + (2 * SPRITE_PAD) ==
+               pScreenPriv->saved.x2 - pScreenPriv->saved.x1 &&
+           (int) pCursor->bits->height + (2 * SPRITE_PAD) ==
+               pScreenPriv->saved.y2 - pScreenPriv->saved.y1
+           )
+       {
+           pScreenPriv->isUp = FALSE;
+           if (!(sx >= pScreenPriv->saved.x1 &&
+                 sx + (int)pCursor->bits->width < pScreenPriv->saved.x2 &&
+                 sy >= pScreenPriv->saved.y1 &&
+                 sy + (int)pCursor->bits->height < pScreenPriv->saved.y2))
+           {
+               int oldx1, oldy1, dx, dy;
+
+               oldx1 = pScreenPriv->saved.x1;
+               oldy1 = pScreenPriv->saved.y1;
+               dx = oldx1 - (sx - SPRITE_PAD);
+               dy = oldy1 - (sy - SPRITE_PAD);
+               pScreenPriv->saved.x1 -= dx;
+               pScreenPriv->saved.y1 -= dy;
+               pScreenPriv->saved.x2 -= dx;
+               pScreenPriv->saved.y2 -= dy;
+               (void) (*pScreenPriv->funcs->ChangeSave) (pScreen,
+                               pScreenPriv->saved.x1,
+                               pScreenPriv->saved.y1,
+                               pScreenPriv->saved.x2 - pScreenPriv->saved.x1,
+                               pScreenPriv->saved.y2 - pScreenPriv->saved.y1,
+                               dx, dy);
+           }
+           (void) (*pScreenPriv->funcs->MoveCursor) (pScreen, pCursor,
+                                 pScreenPriv->saved.x1,
+                                 pScreenPriv->saved.y1,
+                                 pScreenPriv->saved.x2 - pScreenPriv->saved.x1,
+                                 pScreenPriv->saved.y2 - pScreenPriv->saved.y1,
+                                 sx - pScreenPriv->saved.x1,
+                                 sy - pScreenPriv->saved.y1,
+                                 pScreenPriv->colors[SOURCE_COLOR].pixel,
+                                 pScreenPriv->colors[MASK_COLOR].pixel);
+           pScreenPriv->isUp = TRUE;
+       }
+       else
+       {
+           miSpriteRemoveCursor (pScreen);
+       }
+    }
+    if (!pScreenPriv->isUp && pScreenPriv->pCursor)
+       miSpriteRestoreCursor (pScreen);
+}
+
+static void
+miSpriteMoveCursor (pScreen, x, y)
+    ScreenPtr  pScreen;
+    int                x, y;
+{
+    miSpriteScreenPtr  pScreenPriv;
+
+    pScreenPriv = (miSpriteScreenPtr) pScreen->devPrivates[miSpriteScreenIndex].ptr;
+    miSpriteSetCursor (pScreen, pScreenPriv->pCursor, x, y);
+}
+
+/*
+ * undraw/draw cursor
+ */
+
+static void
+miSpriteRemoveCursor (pScreen)
+    ScreenPtr  pScreen;
+{
+    miSpriteScreenPtr   pScreenPriv;
+
+    pScreenPriv = (miSpriteScreenPtr) pScreen->devPrivates[miSpriteScreenIndex].ptr;
+    pScreenPriv->isUp = FALSE;
+    pScreenPriv->pCacheWin = NullWindow;
+    if (!(*pScreenPriv->funcs->RestoreUnderCursor) (pScreen,
+                                        pScreenPriv->saved.x1,
+                                        pScreenPriv->saved.y1,
+                                        pScreenPriv->saved.x2 - pScreenPriv->saved.x1,
+                                        pScreenPriv->saved.y2 - pScreenPriv->saved.y1))
+    {
+       pScreenPriv->isUp = TRUE;
+    }
+}
+
+/*
+ * Called from the block handler, restores the cursor
+ * before waiting for something to do.
+ */
+
+static void
+miSpriteRestoreCursor (pScreen)
+    ScreenPtr  pScreen;
+{
+    miSpriteScreenPtr   pScreenPriv;
+    int                        x, y;
+    CursorPtr          pCursor;
+
+    miSpriteComputeSaved (pScreen);
+    pScreenPriv = (miSpriteScreenPtr) pScreen->devPrivates[miSpriteScreenIndex].ptr;
+    pCursor = pScreenPriv->pCursor;
+    x = pScreenPriv->x - (int)pCursor->bits->xhot;
+    y = pScreenPriv->y - (int)pCursor->bits->yhot;
+    if ((*pScreenPriv->funcs->SaveUnderCursor) (pScreen,
+                                     pScreenPriv->saved.x1,
+                                     pScreenPriv->saved.y1,
+                                     pScreenPriv->saved.x2 - pScreenPriv->saved.x1,
+                                     pScreenPriv->saved.y2 - pScreenPriv->saved.y1))
+    {
+       if (pScreenPriv->checkPixels)
+           miSpriteFindColors (pScreen);
+       if ((*pScreenPriv->funcs->PutUpCursor) (pScreen, pCursor, x, y,
+                                 pScreenPriv->colors[SOURCE_COLOR].pixel,
+                                 pScreenPriv->colors[MASK_COLOR].pixel))
+           pScreenPriv->isUp = TRUE;
+    }
+}
+
+/*
+ * compute the desired area of the screen to save
+ */
+
+static void
+miSpriteComputeSaved (pScreen)
+    ScreenPtr  pScreen;
+{
+    miSpriteScreenPtr   pScreenPriv;
+    int                    x, y, w, h;
+    int                    wpad, hpad;
+    CursorPtr      pCursor;
+
+    pScreenPriv = (miSpriteScreenPtr) pScreen->devPrivates[miSpriteScreenIndex].ptr;
+    pCursor = pScreenPriv->pCursor;
+    x = pScreenPriv->x - (int)pCursor->bits->xhot;
+    y = pScreenPriv->y - (int)pCursor->bits->yhot;
+    w = pCursor->bits->width;
+    h = pCursor->bits->height;
+    wpad = SPRITE_PAD;
+    hpad = SPRITE_PAD;
+    pScreenPriv->saved.x1 = x - wpad;
+    pScreenPriv->saved.y1 = y - hpad;
+    pScreenPriv->saved.x2 = pScreenPriv->saved.x1 + w + wpad * 2;
+    pScreenPriv->saved.y2 = pScreenPriv->saved.y1 + h + hpad * 2;
+}
diff --git a/Xserver/programs/Xserver/mi/misprite.h b/Xserver/programs/Xserver/mi/misprite.h
new file mode 100644 (file)
index 0000000..6fe1bbc
--- /dev/null
@@ -0,0 +1,112 @@
+/*
+ * misprite.h
+ *
+ * software-sprite/sprite drawing interface spec
+ *
+ * mi versions of these routines exist.
+ */
+
+/* $XConsortium: misprite.h,v 5.5 94/04/17 20:27:55 dpw Exp $ */
+
+/*
+
+Copyright (c) 1989  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+*/
+
+typedef struct {
+    Bool       (*RealizeCursor)(
+#if NeedNestedPrototypes
+               ScreenPtr /*pScreen*/,
+               CursorPtr /*pCursor*/
+#endif
+);
+    Bool       (*UnrealizeCursor)(
+#if NeedNestedPrototypes
+               ScreenPtr /*pScreen*/,
+               CursorPtr /*pCursor*/
+#endif
+);
+    Bool       (*PutUpCursor)(
+#if NeedNestedPrototypes
+               ScreenPtr /*pScreen*/,
+               CursorPtr /*pCursor*/,
+               int /*x*/,
+               int /*y*/,
+               unsigned long /*source*/,
+               unsigned long /*mask*/
+#endif
+);
+    Bool       (*SaveUnderCursor)(
+#if NeedNestedPrototypes
+               ScreenPtr /*pScreen*/,
+               int /*x*/,
+               int /*y*/,
+               int /*w*/,
+               int /*h*/
+#endif
+);
+    Bool       (*RestoreUnderCursor)(
+#if NeedNestedPrototypes
+               ScreenPtr /*pScreen*/,
+               int /*x*/,
+               int /*y*/,
+               int /*w*/,
+               int /*h*/
+#endif
+);
+    Bool       (*MoveCursor)(
+#if NeedNestedPrototypes
+               ScreenPtr /*pScreen*/,
+               CursorPtr /*pCursor*/,
+               int /*x*/,
+               int /*y*/,
+               int /*w*/,
+               int /*h*/,
+               int /*dx*/,
+               int /*dy*/,
+               unsigned long /*source*/,
+               unsigned long /*mask*/
+#endif
+);
+    Bool       (*ChangeSave)(
+#if NeedNestedPrototypes
+               ScreenPtr /*pScreen*/,
+               int /*x*/,
+               int /*y*/,
+               int /*w*/,
+               int /*h*/,
+               int /*dx*/,
+               int /*dy*/
+#endif
+);
+
+} miSpriteCursorFuncRec, *miSpriteCursorFuncPtr;
+
+extern Bool miSpriteInitialize(
+#if NeedFunctionPrototypes
+    ScreenPtr /*pScreen*/,
+    miSpriteCursorFuncPtr /*cursorFuncs*/,
+    miPointerScreenFuncPtr /*screenFuncs*/
+#endif
+);
diff --git a/Xserver/programs/Xserver/mi/mispritest.h b/Xserver/programs/Xserver/mi/mispritest.h
new file mode 100644 (file)
index 0000000..bd2122a
--- /dev/null
@@ -0,0 +1,111 @@
+/*
+ * mispritest.h
+ *
+ * mi sprite structures
+ */
+
+/* $XConsortium: mispritest.h,v 5.14 94/04/17 20:27:55 dpw Exp $ */
+
+/*
+
+Copyright (c) 1989  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+*/
+
+# include   "misprite.h"
+
+/*
+ * per screen information
+ */
+
+typedef struct {
+    CloseScreenProcPtr                 CloseScreen;
+    GetImageProcPtr                    GetImage;
+    GetSpansProcPtr                    GetSpans;
+    SourceValidateProcPtr              SourceValidate;
+    CreateGCProcPtr                    CreateGC;
+    ScreenBlockHandlerProcPtr          BlockHandler;
+    InstallColormapProcPtr             InstallColormap;
+    StoreColorsProcPtr                 StoreColors;
+    PaintWindowBackgroundProcPtr       PaintWindowBackground;
+    PaintWindowBorderProcPtr           PaintWindowBorder;
+    CopyWindowProcPtr                  CopyWindow;
+    ClearToBackgroundProcPtr           ClearToBackground;
+    SaveDoomedAreasProcPtr             SaveDoomedAreas;
+    RestoreAreasProcPtr                        RestoreAreas;
+
+    CursorPtr      pCursor;
+    int                    x;
+    int                    y;
+    BoxRec         saved;
+    Bool           isUp;
+    Bool           shouldBeUp;
+    WindowPtr      pCacheWin;
+    Bool           isInCacheWin;
+    Bool           checkPixels;
+    xColorItem     colors[2];
+    ColormapPtr            pInstalledMap;
+    ColormapPtr            pColormap;
+    VisualPtr      pVisual;
+    miSpriteCursorFuncPtr    funcs;
+} miSpriteScreenRec, *miSpriteScreenPtr;
+
+#define SOURCE_COLOR   0
+#define MASK_COLOR     1
+
+typedef struct {
+    GCFuncs            *wrapFuncs;
+    GCOps              *wrapOps;
+} miSpriteGCRec, *miSpriteGCPtr;
+
+/*
+ * Overlap BoxPtr and Box elements
+ */
+#define BOX_OVERLAP(pCbox,X1,Y1,X2,Y2) \
+       (((pCbox)->x1 <= (X2)) && ((X1) <= (pCbox)->x2) && \
+        ((pCbox)->y1 <= (Y2)) && ((Y1) <= (pCbox)->y2))
+
+/*
+ * Overlap BoxPtr, origins, and rectangle
+ */
+#define ORG_OVERLAP(pCbox,xorg,yorg,x,y,w,h) \
+    BOX_OVERLAP((pCbox),(x)+(xorg),(y)+(yorg),(x)+(xorg)+(w),(y)+(yorg)+(h))
+
+/*
+ * Overlap BoxPtr, origins and RectPtr
+ */
+#define ORGRECT_OVERLAP(pCbox,xorg,yorg,pRect) \
+    ORG_OVERLAP((pCbox),(xorg),(yorg),(pRect)->x,(pRect)->y, \
+               (int)((pRect)->width), (int)((pRect)->height))
+/*
+ * Overlap BoxPtr and horizontal span
+ */
+#define SPN_OVERLAP(pCbox,y,x,w) BOX_OVERLAP((pCbox),(x),(y),(x)+(w),(y))
+
+#define LINE_SORT(x1,y1,x2,y2) \
+{ int _t; \
+  if (x1 > x2) { _t = x1; x1 = x2; x2 = _t; } \
+  if (y1 > y2) { _t = y1; y1 = y2; y2 = _t; } }
+
+#define LINE_OVERLAP(pCbox,x1,y1,x2,y2,lw2) \
+    BOX_OVERLAP((pCbox), (x1)-(lw2), (y1)-(lw2), (x2)+(lw2), (y2)+(lw2))
diff --git a/Xserver/programs/Xserver/mi/mistruct.h b/Xserver/programs/Xserver/mi/mistruct.h
new file mode 100644 (file)
index 0000000..87d5e3d
--- /dev/null
@@ -0,0 +1,64 @@
+/* $XConsortium: mistruct.h,v 1.3 94/04/17 20:27:56 jim Exp $ */
+/***********************************************************
+
+Copyright (c) 1987  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+
+Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
+
+                        All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and its 
+documentation for any purpose and without fee is hereby granted, 
+provided that the above copyright notice appear in all copies and that
+both that copyright notice and this permission notice appear in 
+supporting documentation, and that the name of Digital not be
+used in advertising or publicity pertaining to distribution of the
+software without specific, written prior permission.  
+
+DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
+ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
+DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
+ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+SOFTWARE.
+
+******************************************************************/
+#ifndef MISTRUCT_H
+#define MISTRUCT_H
+
+#include "mi.h"
+#include "miscstruct.h"
+
+/* information about dashes */
+typedef struct _miDash {
+    DDXPointRec        pt;
+    int                e1, e2; /* keep these, so we don't have to do it again */
+    int                e;      /* bresenham error term for this point on line */
+    int                which;
+    int                newLine;/* 0 if part of same original line as previous dash */
+    } miDashRec;
+
+#endif /* MISTRUCT_H */
diff --git a/Xserver/programs/Xserver/mi/mivalidate.h b/Xserver/programs/Xserver/mi/mivalidate.h
new file mode 100644 (file)
index 0000000..c2655e2
--- /dev/null
@@ -0,0 +1,53 @@
+/* $XConsortium: mivalidate.h,v 1.3 94/04/17 20:27:57 dpw Exp $ */
+/*
+
+Copyright (c) 1993  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be included
+in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR
+OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall
+not be used in advertising or otherwise to promote the sale, use or
+other dealings in this Software without prior written authorization
+from the X Consortium.
+
+*/
+
+
+#ifndef MIVALIDATE_H
+#define MIVALIDATE_H
+
+#include "miscstruct.h"
+#include "regionstr.h"
+
+typedef union _Validate {
+    struct BeforeValidate {
+       DDXPointRec     oldAbsCorner;   /* old window position */
+       RegionPtr       borderVisible;  /* visible region of border, */
+                                       /* non-null when size changes */
+       Bool            resized;        /* unclipped winSize has changed - */
+                                       /* don't call SaveDoomedAreas */
+    } before;
+    struct AfterValidate {
+       RegionRec       exposed;        /* exposed regions, absolute pos */
+       RegionRec       borderExposed;
+    } after;
+} ValidateRec;
+
+#endif /* MIVALIDATE_H */
diff --git a/Xserver/programs/Xserver/mi/mivaltree.c b/Xserver/programs/Xserver/mi/mivaltree.c
new file mode 100644 (file)
index 0000000..0850230
--- /dev/null
@@ -0,0 +1,730 @@
+/* $XConsortium: mivaltree.c,v 5.33 94/04/17 20:27:58 dpw Exp $ */
+/*
+ * mivaltree.c --
+ *     Functions for recalculating window clip lists. Main function
+ *     is miValidateTree.
+ *
+
+Copyright (c) 1987, 1988, 1989  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+ *
+ * Copyright 1987, 1988, 1989 by 
+ * Digital Equipment Corporation, Maynard, Massachusetts,
+ * 
+ *                         All Rights Reserved
+ * 
+ * Permission to use, copy, modify, and distribute this software and its 
+ * documentation for any purpose and without fee is hereby granted, 
+ * provided that the above copyright notice appear in all copies and that
+ * both that copyright notice and this permission notice appear in 
+ * supporting documentation, and that the name of Digital not be
+ * used in advertising or publicity pertaining to distribution of the
+ * software without specific, written prior permission.  
+ * 
+ * DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
+ * ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
+ * DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
+ * ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+ * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+ * 
+ ******************************************************************/
+
+ /* 
+  * Aug '86: Susan Angebranndt -- original code
+  * July '87: Adam de Boor -- substantially modified and commented
+  * Summer '89: Joel McCormack -- so fast you wouldn't believe it possible.
+  *             In particular, much improved code for window mapping and
+  *             circulating.
+  *            Bob Scheifler -- avoid miComputeClips for unmapped windows,
+  *                             valdata changes
+  */
+
+#include    "X.h"
+#include    "scrnintstr.h"
+#include    "validate.h"
+#include    "windowstr.h"
+#include    "mi.h"
+#include    "regionstr.h"
+#include    "mivalidate.h"
+
+#ifdef SHAPE
+/*
+ * Compute the visibility of a shaped window
+ */
+miShapedWindowIn (pScreen, universe, bounding, rect, x, y)
+    ScreenPtr  pScreen;
+    RegionPtr  universe, bounding;
+    BoxPtr     rect;
+    register int x, y;
+{
+    BoxRec  box;
+    register BoxPtr  boundBox;
+    int            nbox;
+    Bool    someIn, someOut;
+    register int t, x1, y1, x2, y2;
+
+    nbox = REGION_NUM_RECTS (bounding);
+    boundBox = REGION_RECTS (bounding);
+    someIn = someOut = FALSE;
+    x1 = rect->x1;
+    y1 = rect->y1;
+    x2 = rect->x2;
+    y2 = rect->y2;
+    while (nbox--)
+    {
+       if ((t = boundBox->x1 + x) < x1)
+           t = x1;
+       box.x1 = t;
+       if ((t = boundBox->y1 + y) < y1)
+           t = y1;
+       box.y1 = t;
+       if ((t = boundBox->x2 + x) > x2)
+           t = x2;
+       box.x2 = t;
+       if ((t = boundBox->y2 + y) > y2)
+           t = y2;
+       box.y2 = t;
+       if (box.x1 > box.x2)
+           box.x2 = box.x1;
+       if (box.y1 > box.y2)
+           box.y2 = box.y1;
+       switch (RECT_IN_REGION(pScreen, universe, &box))
+       {
+       case rgnIN:
+           if (someOut)
+               return rgnPART;
+           someIn = TRUE;
+           break;
+       case rgnOUT:
+           if (someIn)
+               return rgnPART;
+           someOut = TRUE;
+           break;
+       default:
+           return rgnPART;
+       }
+       boundBox++;
+    }
+    if (someIn)
+       return rgnIN;
+    return rgnOUT;
+}
+#endif
+
+#define HasParentRelativeBorder(w) (!(w)->borderIsPixel && \
+                                   HasBorder(w) && \
+                                   (w)->backgroundState == ParentRelative)
+
+/*-
+ *-----------------------------------------------------------------------
+ * miComputeClips --
+ *     Recompute the clipList, borderClip, exposed and borderExposed
+ *     regions for pParent and its children. Only viewable windows are
+ *     taken into account.
+ *
+ * Results:
+ *     None.
+ *
+ * Side Effects:
+ *     clipList, borderClip, exposed and borderExposed are altered.
+ *     A VisibilityNotify event may be generated on the parent window.
+ *
+ *-----------------------------------------------------------------------
+ */
+
+static void
+miComputeClips (pParent, pScreen, universe, kind, exposed)
+    register WindowPtr pParent;
+    register ScreenPtr pScreen;
+    register RegionPtr universe;
+    VTKind             kind;
+    RegionPtr          exposed; /* for intermediate calculations */
+{
+    int                        dx,
+                       dy;
+    RegionRec          childUniverse;
+    register WindowPtr pChild;
+    int                oldVis, newVis;
+    BoxRec             borderSize;
+    RegionRec          childUnion;
+    Bool               overlap;
+    RegionPtr          borderVisible;
+    Bool               resized;
+    
+    /*
+     * Figure out the new visibility of this window.
+     * The extent of the universe should be the same as the extent of
+     * the borderSize region. If the window is unobscured, this rectangle
+     * will be completely inside the universe (the universe will cover it
+     * completely). If the window is completely obscured, none of the
+     * universe will cover the rectangle.
+     */
+
+    borderSize.x1 = pParent->drawable.x - wBorderWidth(pParent);
+    borderSize.y1 = pParent->drawable.y - wBorderWidth(pParent);
+    dx = (int) pParent->drawable.x + (int) pParent->drawable.width + wBorderWidth(pParent);
+    if (dx > 32767)
+       dx = 32767;
+    borderSize.x2 = dx;
+    dy = (int) pParent->drawable.y + (int) pParent->drawable.height + wBorderWidth(pParent);
+    if (dy > 32767)
+       dy = 32767;
+    borderSize.y2 = dy;
+
+    oldVis = pParent->visibility;
+    switch (RECT_IN_REGION( pScreen, universe, &borderSize)) 
+    {
+       case rgnIN:
+           newVis = VisibilityUnobscured;
+           break;
+       case rgnPART:
+           newVis = VisibilityPartiallyObscured;
+#ifdef SHAPE
+           {
+               RegionPtr   pBounding;
+
+               if ((pBounding = wBoundingShape (pParent)))
+               {
+                   switch (miShapedWindowIn (pScreen, universe, pBounding,
+                                             &borderSize,
+                                             pParent->drawable.x,
+                                             pParent->drawable.y))
+                   {
+                   case rgnIN:
+                       newVis = VisibilityUnobscured;
+                       break;
+                   case rgnOUT:
+                       newVis = VisibilityFullyObscured;
+                       break;
+                   }
+               }
+           }
+#endif
+           break;
+       default:
+           newVis = VisibilityFullyObscured;
+           break;
+    }
+    pParent->visibility = newVis;
+    if (oldVis != newVis &&
+       ((pParent->eventMask | wOtherEventMasks(pParent)) & VisibilityChangeMask))
+       SendVisibilityNotify(pParent);
+
+    dx = pParent->drawable.x - pParent->valdata->before.oldAbsCorner.x;
+    dy = pParent->drawable.y - pParent->valdata->before.oldAbsCorner.y;
+
+    /*
+     * avoid computations when dealing with simple operations
+     */
+
+    switch (kind) {
+    case VTMap:
+    case VTStack:
+    case VTUnmap:
+       break;
+    case VTMove:
+       if ((oldVis == newVis) &&
+           ((oldVis == VisibilityFullyObscured) ||
+            (oldVis == VisibilityUnobscured)))
+       {
+           pChild = pParent;
+           while (1)
+           {
+               if (pChild->viewable)
+               {
+                   if (pChild->visibility != VisibilityFullyObscured)
+                   {
+                       REGION_TRANSLATE( pScreen, &pChild->borderClip,
+                                                     dx, dy);
+                       REGION_TRANSLATE( pScreen, &pChild->clipList,
+                                                     dx, dy);
+                       pChild->drawable.serialNumber = NEXT_SERIAL_NUMBER;
+                       if (pScreen->ClipNotify)
+                           (* pScreen->ClipNotify) (pChild, dx, dy);
+
+                   }
+                   if (pChild->valdata)
+                   {
+                       REGION_INIT(pScreen, 
+                                   &pChild->valdata->after.borderExposed,
+                                   NullBox, 0);
+                       if (HasParentRelativeBorder(pChild))
+                       {
+                           REGION_SUBTRACT(pScreen,
+                                        &pChild->valdata->after.borderExposed,
+                                        &pChild->borderClip,
+                                        &pChild->winSize);
+                       }
+                       REGION_INIT( pScreen, &pChild->valdata->after.exposed,
+                                                NullBox, 0);
+                   }
+                   if (pChild->firstChild)
+                   {
+                       pChild = pChild->firstChild;
+                       continue;
+                   }
+               }
+               while (!pChild->nextSib && (pChild != pParent))
+                   pChild = pChild->parent;
+               if (pChild == pParent)
+                   break;
+               pChild = pChild->nextSib;
+           }
+           return;
+       }
+       /* fall through */
+    default:
+       /*
+        * To calculate exposures correctly, we have to translate the old
+        * borderClip and clipList regions to the window's new location so there
+        * is a correspondence between pieces of the new and old clipping regions.
+        */
+       if (dx || dy) 
+       {
+           /*
+            * We translate the old clipList because that will be exposed or copied
+            * if gravity is right.
+            */
+           REGION_TRANSLATE( pScreen, &pParent->borderClip, dx, dy);
+           REGION_TRANSLATE( pScreen, &pParent->clipList, dx, dy);
+       } 
+       break;
+    }
+
+    borderVisible = pParent->valdata->before.borderVisible;
+    resized = pParent->valdata->before.resized;
+    REGION_INIT( pScreen, &pParent->valdata->after.borderExposed, NullBox, 0);
+    REGION_INIT( pScreen, &pParent->valdata->after.exposed, NullBox, 0);
+
+    /*
+     * Since the borderClip must not be clipped by the children, we do
+     * the border exposure first...
+     *
+     * 'universe' is the window's borderClip. To figure the exposures, remove
+     * the area that used to be exposed from the new.
+     * This leaves a region of pieces that weren't exposed before.
+     */
+
+    if (HasBorder (pParent))
+    {
+       if (borderVisible)
+       {
+           /*
+            * when the border changes shape, the old visible portions
+            * of the border will be saved by DIX in borderVisible --
+            * use that region and destroy it
+            */
+           REGION_SUBTRACT( pScreen, exposed, universe, borderVisible);
+           REGION_DESTROY( pScreen, borderVisible);
+       }
+       else
+       {
+           REGION_SUBTRACT( pScreen, exposed, universe, &pParent->borderClip);
+       }
+       if (HasParentRelativeBorder(pParent) && (dx || dy))
+           REGION_SUBTRACT( pScreen, &pParent->valdata->after.borderExposed,
+                                 universe,
+                                 &pParent->winSize);
+       else
+           REGION_SUBTRACT( pScreen, &pParent->valdata->after.borderExposed,
+                              exposed, &pParent->winSize);
+
+       REGION_COPY( pScreen, &pParent->borderClip, universe);
+    
+       /*
+        * To get the right clipList for the parent, and to make doubly sure
+        * that no child overlaps the parent's border, we remove the parent's
+        * border from the universe before proceeding.
+        */
+    
+       REGION_INTERSECT( pScreen, universe, universe, &pParent->winSize);
+    }
+    else
+       REGION_COPY( pScreen, &pParent->borderClip, universe);
+    
+    if ((pChild = pParent->firstChild) && pParent->mapped)
+    {
+       REGION_INIT(pScreen, &childUniverse, NullBox, 0);
+       REGION_INIT(pScreen, &childUnion, NullBox, 0);
+       if ((pChild->drawable.y < pParent->lastChild->drawable.y) ||
+           ((pChild->drawable.y == pParent->lastChild->drawable.y) &&
+            (pChild->drawable.x < pParent->lastChild->drawable.x)))
+       {
+           for (; pChild; pChild = pChild->nextSib)
+           {
+               if (pChild->viewable)
+                   REGION_APPEND( pScreen, &childUnion, &pChild->borderSize);
+           }
+       }
+       else
+       {
+           for (pChild = pParent->lastChild; pChild; pChild = pChild->prevSib)
+           {
+               if (pChild->viewable)
+                   REGION_APPEND( pScreen, &childUnion, &pChild->borderSize);
+           }
+       }
+       REGION_VALIDATE( pScreen, &childUnion, &overlap);
+
+       for (pChild = pParent->firstChild;
+            pChild;
+            pChild = pChild->nextSib)
+       {
+           if (pChild->viewable) {
+               /*
+                * If the child is viewable, we want to remove its extents
+                * from the current universe, but we only re-clip it if
+                * it's been marked.
+                */
+               if (pChild->valdata) {
+                   /*
+                    * Figure out the new universe from the child's
+                    * perspective and recurse.
+                    */
+                   REGION_INTERSECT( pScreen, &childUniverse,
+                                           universe,
+                                           &pChild->borderSize);
+                   miComputeClips (pChild, pScreen, &childUniverse, kind,
+                                   exposed);
+               }
+               /*
+                * Once the child has been processed, we remove its extents
+                * from the current universe, thus denying its space to any
+                * other sibling.
+                */
+               if (overlap)
+                   REGION_SUBTRACT( pScreen, universe, universe,
+                                         &pChild->borderSize);
+           }
+       }
+       if (!overlap)
+           REGION_SUBTRACT( pScreen, universe, universe, &childUnion);
+       REGION_UNINIT( pScreen, &childUnion);
+       REGION_UNINIT( pScreen, &childUniverse);
+    } /* if any children */
+
+    /*
+     * 'universe' now contains the new clipList for the parent window.
+     *
+     * To figure the exposure of the window we subtract the old clip from the
+     * new, just as for the border.
+     */
+
+    if (oldVis == VisibilityFullyObscured ||
+       oldVis == VisibilityNotViewable)
+    {
+       REGION_COPY( pScreen, &pParent->valdata->after.exposed, universe);
+    }
+    else if (newVis != VisibilityFullyObscured &&
+            newVis != VisibilityNotViewable)
+    {
+       REGION_SUBTRACT( pScreen, &pParent->valdata->after.exposed,
+                              universe, &pParent->clipList);
+    }
+
+    /*
+     * One last thing: backing storage. We have to try to save what parts of
+     * the window are about to be obscured. We can just subtract the universe
+     * from the old clipList and get the areas that were in the old but aren't
+     * in the new and, hence, are about to be obscured.
+     */
+    if (pParent->backStorage && !resized)
+    {
+       REGION_SUBTRACT( pScreen, exposed, &pParent->clipList, universe);
+       (* pScreen->SaveDoomedAreas)(pParent, exposed, dx, dy);
+    }
+    
+    /* HACK ALERT - copying contents of regions, instead of regions */
+    {
+       RegionRec   tmp;
+
+       tmp = pParent->clipList;
+       pParent->clipList = *universe;
+       *universe = tmp;
+    }
+
+#ifdef NOTDEF
+    REGION_COPY( pScreen, &pParent->clipList, universe);
+#endif
+
+    pParent->drawable.serialNumber = NEXT_SERIAL_NUMBER;
+
+    if (pScreen->ClipNotify)
+       (* pScreen->ClipNotify) (pParent, dx, dy);
+}
+
+static void
+miTreeObscured(pParent)
+    register WindowPtr pParent;
+{
+    register WindowPtr pChild;
+    register int    oldVis;
+
+    pChild = pParent;
+    while (1)
+    {
+       if (pChild->viewable)
+       {
+           oldVis = pChild->visibility;
+           if (oldVis != (pChild->visibility = VisibilityFullyObscured) &&
+               ((pChild->eventMask | wOtherEventMasks(pChild)) & VisibilityChangeMask))
+               SendVisibilityNotify(pChild);
+           if (pChild->firstChild)
+           {
+               pChild = pChild->firstChild;
+               continue;
+           }
+       }
+       while (!pChild->nextSib && (pChild != pParent))
+           pChild = pChild->parent;
+       if (pChild == pParent)
+           break;
+       pChild = pChild->nextSib;
+    }
+}
+
+/*-
+ *-----------------------------------------------------------------------
+ * miValidateTree --
+ *     Recomputes the clip list for pParent and all its inferiors.
+ *
+ * Results:
+ *     Always returns 1.
+ *
+ * Side Effects:
+ *     The clipList, borderClip, exposed, and borderExposed regions for
+ *     each marked window are altered.
+ *
+ * Notes:
+ *     This routine assumes that all affected windows have been marked
+ *     (valdata created) and their winSize and borderSize regions
+ *     adjusted to correspond to their new positions. The borderClip and
+ *     clipList regions should not have been touched.
+ *
+ *     The top-most level is treated differently from all lower levels
+ *     because pParent is unchanged. For the top level, we merge the
+ *     regions taken up by the marked children back into the clipList
+ *     for pParent, thus forming a region from which the marked children
+ *     can claim their areas. For lower levels, where the old clipList
+ *     and borderClip are invalid, we can't do this and have to do the
+ *     extra operations done in miComputeClips, but this is much faster
+ *     e.g. when only one child has moved...
+ *
+ *-----------------------------------------------------------------------
+ */
+/*ARGSUSED*/
+int
+miValidateTree (pParent, pChild, kind)
+    WindowPtr          pParent;    /* Parent to validate */
+    WindowPtr          pChild;     /* First child of pParent that was
+                                    * affected */
+    VTKind             kind;       /* What kind of configuration caused call */
+{
+    RegionRec          totalClip;  /* Total clipping region available to
+                                    * the marked children. pParent's clipList
+                                    * merged with the borderClips of all
+                                    * the marked children. */
+    RegionRec          childClip;  /* The new borderClip for the current
+                                    * child */
+    RegionRec          childUnion; /* the space covered by borderSize for
+                                    * all marked children */
+    RegionRec          exposed;    /* For intermediate calculations */
+    register ScreenPtr pScreen;
+    register WindowPtr pWin;
+    Bool               overlap;
+    int                        viewvals;
+    Bool               forward;
+
+    pScreen = pParent->drawable.pScreen;
+    if (pChild == NullWindow)
+       pChild = pParent->firstChild;
+
+    REGION_INIT(pScreen, &childClip, NullBox, 0);
+    REGION_INIT(pScreen, &exposed, NullBox, 0);
+
+    /*
+     * compute the area of the parent window occupied
+     * by the marked children + the parent itself.  This
+     * is the area which can be divied up among the marked
+     * children in their new configuration.
+     */
+    REGION_INIT(pScreen, &totalClip, NullBox, 0);
+    viewvals = 0;
+    if ((pChild->drawable.y < pParent->lastChild->drawable.y) ||
+       ((pChild->drawable.y == pParent->lastChild->drawable.y) &&
+        (pChild->drawable.x < pParent->lastChild->drawable.x)))
+    {
+       forward = TRUE;
+       for (pWin = pChild; pWin; pWin = pWin->nextSib)
+       {
+           if (pWin->valdata)
+           {
+               REGION_APPEND( pScreen, &totalClip, &pWin->borderClip);
+               if (pWin->viewable)
+                   viewvals++;
+           }
+       }
+    }
+    else
+    {
+       forward = FALSE;
+       pWin = pParent->lastChild;
+       while (1)
+       {
+           if (pWin->valdata)
+           {
+               REGION_APPEND( pScreen, &totalClip, &pWin->borderClip);
+               if (pWin->viewable)
+                   viewvals++;
+           }
+           if (pWin == pChild)
+               break;
+           pWin = pWin->prevSib;
+       }
+    }
+    REGION_VALIDATE( pScreen, &totalClip, &overlap);
+
+    /*
+     * Now go through the children of the root and figure their new
+     * borderClips from the totalClip, passing that off to miComputeClips
+     * to handle recursively. Once that's done, we remove the child
+     * from the totalClip to clip any siblings below it.
+     */
+
+    overlap = TRUE;
+    if (kind != VTStack)
+    {
+       REGION_UNION( pScreen, &totalClip, &totalClip, &pParent->clipList);
+       if (viewvals > 1)
+       {
+           /*
+            * precompute childUnion to discover whether any of them
+            * overlap.  This seems redundant, but performance studies
+            * have demonstrated that the cost of this loop is
+            * lower than the cost of multiple Subtracts in the
+            * loop below.
+            */
+           REGION_INIT(pScreen, &childUnion, NullBox, 0);
+           if (forward)
+           {
+               for (pWin = pChild; pWin; pWin = pWin->nextSib)
+                   if (pWin->valdata && pWin->viewable)
+                       REGION_APPEND( pScreen, &childUnion,
+                                                  &pWin->borderSize);
+           }
+           else
+           {
+               pWin = pParent->lastChild;
+               while (1)
+               {
+                   if (pWin->valdata && pWin->viewable)
+                       REGION_APPEND( pScreen, &childUnion,
+                                                  &pWin->borderSize);
+                   if (pWin == pChild)
+                       break;
+                   pWin = pWin->prevSib;
+               }
+           }
+           REGION_VALIDATE(pScreen, &childUnion, &overlap);
+           if (overlap)
+               REGION_UNINIT(pScreen, &childUnion);
+       }
+    }
+
+    for (pWin = pChild;
+        pWin != NullWindow;
+        pWin = pWin->nextSib)
+    {
+       if (pWin->viewable) {
+           if (pWin->valdata) {
+               REGION_INTERSECT( pScreen, &childClip,
+                                       &totalClip,
+                                       &pWin->borderSize);
+               miComputeClips (pWin, pScreen, &childClip, kind, &exposed);
+               if (overlap)
+               {
+                   REGION_SUBTRACT( pScreen, &totalClip,
+                                          &totalClip,
+                                          &pWin->borderSize);
+               }
+           } else if (pWin->visibility == VisibilityNotViewable) {
+               miTreeObscured(pWin);
+           }
+       } else {
+           if (pWin->valdata) {
+               REGION_EMPTY( pScreen, &pWin->clipList);
+               if (pScreen->ClipNotify)
+                   (* pScreen->ClipNotify) (pWin, 0, 0);
+               REGION_EMPTY( pScreen, &pWin->borderClip);
+               pWin->valdata = (ValidatePtr)NULL;
+           }
+       }
+    }
+
+    REGION_UNINIT( pScreen, &childClip);
+    if (!overlap)
+    {
+       REGION_SUBTRACT(pScreen, &totalClip, &totalClip, &childUnion);
+       REGION_UNINIT(pScreen, &childUnion);
+    }
+
+    REGION_INIT( pScreen, &pParent->valdata->after.exposed, NullBox, 0);
+    REGION_INIT( pScreen, &pParent->valdata->after.borderExposed, NullBox, 0);
+
+    /*
+     * each case below is responsible for updating the
+     * clipList and serial number for the parent window
+     */
+
+    switch (kind) {
+    case VTStack:
+       break;
+    default:
+       /*
+        * totalClip contains the new clipList for the parent. Figure out
+        * exposures and obscures as per miComputeClips and reset the parent's
+        * clipList.
+        */
+       REGION_SUBTRACT( pScreen, &pParent->valdata->after.exposed,
+                              &totalClip, &pParent->clipList);
+       /* fall through */
+    case VTMap:
+       if (pParent->backStorage) {
+           REGION_SUBTRACT( pScreen, &exposed, &pParent->clipList, &totalClip);
+           (* pScreen->SaveDoomedAreas)(pParent, &exposed, 0, 0);
+       }
+       
+       REGION_COPY( pScreen, &pParent->clipList, &totalClip);
+       pParent->drawable.serialNumber = NEXT_SERIAL_NUMBER;
+       break;
+    }
+
+    REGION_UNINIT( pScreen, &totalClip);
+    REGION_UNINIT( pScreen, &exposed);
+    if (pScreen->ClipNotify)
+       (*pScreen->ClipNotify) (pParent, 0, 0);
+    return (1);
+}
diff --git a/Xserver/programs/Xserver/mi/miwideline.c b/Xserver/programs/Xserver/mi/miwideline.c
new file mode 100644 (file)
index 0000000..6004913
--- /dev/null
@@ -0,0 +1,2206 @@
+/* $XConsortium: miwideline.c /main/58 1996/08/12 21:51:21 dpw $ */
+/*
+
+Copyright (c) 1988  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be included
+in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR
+OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall
+not be used in advertising or otherwise to promote the sale, use or
+other dealings in this Software without prior written authorization
+from the X Consortium.
+
+*/
+/* $XFree86: xc/programs/Xserver/mi/miwideline.c,v 1.1.1.3.2.2 1998/02/01 22:08:22 robin Exp $ */
+
+/* Author:  Keith Packard, MIT X Consortium */
+
+/*
+ * Mostly integer wideline code.  Uses a technique similar to
+ * bresenham zero-width lines, except walks an X edge
+ */
+
+#include <stdio.h>
+#ifdef _XOPEN_SOURCE
+#include <math.h>
+#else
+#define _XOPEN_SOURCE  /* to get prototype for hypot on some systems */
+#include <math.h>
+#undef _XOPEN_SOURCE
+#endif
+#include "X.h"
+#include "windowstr.h"
+#include "gcstruct.h"
+#include "miscstruct.h"
+#include "miwideline.h"
+#include "mi.h"
+
+#ifdef ICEILTEMPDECL
+ICEILTEMPDECL
+#endif
+
+static void miLineArc();
+
+/*
+ * spans-based polygon filler
+ */
+
+void
+miFillPolyHelper (pDrawable, pGC, pixel, spanData, y, overall_height,
+                 left, right, left_count, right_count)
+    DrawablePtr        pDrawable;
+    GCPtr      pGC;
+    unsigned long   pixel;
+    SpanDataPtr        spanData;
+    int                y;                      /* start y coordinate */
+    int                overall_height;         /* height of entire segment */
+    PolyEdgePtr        left, right;
+    int                left_count, right_count;
+{
+    register int left_x, left_e;
+    int        left_stepx;
+    int        left_signdx;
+    int        left_dy, left_dx;
+
+    register int right_x, right_e;
+    int        right_stepx;
+    int        right_signdx;
+    int        right_dy, right_dx;
+
+    int        height;
+    int        left_height, right_height;
+
+    register DDXPointPtr ppt;
+    DDXPointPtr pptInit;
+    register int *pwidth;
+    int *pwidthInit;
+    XID                oldPixel;
+    int                xorg;
+    Spans      spanRec;
+
+    left_height = 0;
+    right_height = 0;
+    
+    if (!spanData)
+    {
+       pptInit = (DDXPointPtr) ALLOCATE_LOCAL (overall_height * sizeof(*ppt));
+       if (!pptInit)
+           return;
+       pwidthInit = (int *) ALLOCATE_LOCAL (overall_height * sizeof(*pwidth));
+       if (!pwidthInit)
+       {
+           DEALLOCATE_LOCAL (pptInit);
+           return;
+       }
+       ppt = pptInit;
+       pwidth = pwidthInit;
+       oldPixel = pGC->fgPixel;
+       if (pixel != oldPixel)
+       {
+           DoChangeGC (pGC, GCForeground, (XID *)&pixel, FALSE);
+           ValidateGC (pDrawable, pGC);
+       }
+    }
+    else
+    {
+       spanRec.points = (DDXPointPtr) xalloc (overall_height * sizeof (*ppt));
+       if (!spanRec.points)
+           return;
+       spanRec.widths = (int *) xalloc (overall_height * sizeof (int));
+       if (!spanRec.widths)
+       {
+           xfree (spanRec.points);
+           return;
+       }
+       ppt = spanRec.points;
+       pwidth = spanRec.widths;
+    }
+
+    xorg = 0;
+    if (pGC->miTranslate)
+    {
+       y += pDrawable->y;
+       xorg = pDrawable->x;
+    }
+    while ((left_count || left_height) &&
+          (right_count || right_height))
+    {
+       MIPOLYRELOADLEFT
+       MIPOLYRELOADRIGHT
+
+       height = left_height;
+       if (height > right_height)
+           height = right_height;
+
+       left_height -= height;
+       right_height -= height;
+
+       while (--height >= 0)
+       {
+           if (right_x >= left_x)
+           {
+               ppt->y = y;
+               ppt->x = left_x + xorg;
+               ppt++;
+               *pwidth++ = right_x - left_x + 1;
+           }
+           y++;
+       
+           MIPOLYSTEPLEFT
+
+           MIPOLYSTEPRIGHT
+       }
+    }
+    if (!spanData)
+    {
+       (*pGC->ops->FillSpans) (pDrawable, pGC, ppt - pptInit, pptInit, pwidthInit, TRUE);
+       DEALLOCATE_LOCAL (pwidthInit);
+       DEALLOCATE_LOCAL (pptInit);
+       if (pixel != oldPixel)
+       {
+           DoChangeGC (pGC, GCForeground, &oldPixel, FALSE);
+           ValidateGC (pDrawable, pGC);
+       }
+    }
+    else
+    {
+       spanRec.count = ppt - spanRec.points;
+       AppendSpanGroup (pGC, pixel, &spanRec, spanData)
+    }
+}
+
+static void
+miFillRectPolyHelper (pDrawable, pGC, pixel, spanData, x, y, w, h)
+    DrawablePtr        pDrawable;
+    GCPtr      pGC;
+    unsigned long   pixel;
+    SpanDataPtr        spanData;
+    int                x, y, w, h;
+{
+    register DDXPointPtr ppt;
+    register int *pwidth;
+    XID                oldPixel;
+    Spans      spanRec;
+    xRectangle  rect;
+
+    if (!spanData)
+    {
+       rect.x = x;
+       rect.y = y;
+       rect.width = w;
+       rect.height = h;
+       oldPixel = pGC->fgPixel;
+       if (pixel != oldPixel)
+       {
+           DoChangeGC (pGC, GCForeground, (XID *)&pixel, FALSE);
+           ValidateGC (pDrawable, pGC);
+       }
+       (*pGC->ops->PolyFillRect) (pDrawable, pGC, 1, &rect);
+       if (pixel != oldPixel)
+       {
+           DoChangeGC (pGC, GCForeground, &oldPixel, FALSE);
+           ValidateGC (pDrawable, pGC);
+       }
+    }
+    else
+    {
+       spanRec.points = (DDXPointPtr) xalloc (h * sizeof (*ppt));
+       if (!spanRec.points)
+           return;
+       spanRec.widths = (int *) xalloc (h * sizeof (int));
+       if (!spanRec.widths)
+       {
+           xfree (spanRec.points);
+           return;
+       }
+       ppt = spanRec.points;
+       pwidth = spanRec.widths;
+
+       if (pGC->miTranslate)
+       {
+           y += pDrawable->y;
+           x += pDrawable->x;
+       }
+       while (h--)
+       {
+           ppt->x = x;
+           ppt->y = y;
+           ppt++;
+           *pwidth++ = w;
+           y++;
+       }
+       spanRec.count = ppt - spanRec.points;
+       AppendSpanGroup (pGC, pixel, &spanRec, spanData)
+    }
+}
+
+int
+miPolyBuildEdge (x0, y0, k, dx, dy, xi, yi, left, edge)
+    double     x0, y0;
+    double     k;  /* x0 * dy - y0 * dx */
+    register int dx, dy;
+    int                xi, yi;
+    int                left;
+    register PolyEdgePtr edge;
+{
+    int            x, y, e;
+    int            xady;
+
+    if (dy < 0)
+    {
+       dy = -dy;
+       dx = -dx;
+       k = -k;
+    }
+
+#ifdef NOTDEF
+    {
+       double  realk, kerror;
+       realk = x0 * dy - y0 * dx;
+       kerror = Fabs (realk - k);
+       if (kerror > .1)
+           printf ("realk: %g k: %g\n", realk, k);
+    }
+#endif
+    y = ICEIL (y0);
+    xady = ICEIL (k) + y * dx;
+
+    if (xady <= 0)
+       x = - (-xady / dy) - 1;
+    else
+       x = (xady - 1) / dy;
+
+    e = xady - x * dy;
+
+    if (dx >= 0)
+    {
+       edge->signdx = 1;
+       edge->stepx = dx / dy;
+       edge->dx = dx % dy;
+    }
+    else
+    {
+       edge->signdx = -1;
+       edge->stepx = - (-dx / dy);
+       edge->dx = -dx % dy;
+       e = dy - e + 1;
+    }
+    edge->dy = dy;
+    edge->x = x + left + xi;
+    edge->e = e - dy;  /* bias to compare against 0 instead of dy */
+    return y + yi;
+}
+
+#define StepAround(v, incr, max) (((v) + (incr) < 0) ? (max - 1) : ((v) + (incr) == max) ? 0 : ((v) + (incr)))
+
+int
+miPolyBuildPoly (vertices, slopes, count, xi, yi, left, right, pnleft, pnright, h)
+    register PolyVertexPtr vertices;
+    register PolySlopePtr  slopes;
+    int                    count;
+    int                    xi, yi;
+    PolyEdgePtr            left, right;
+    int                    *pnleft, *pnright;
+    int                    *h;
+{
+    int            top, bottom;
+    double  miny, maxy;
+    register int i;
+    int            j;
+    int            clockwise;
+    int            slopeoff;
+    register int s;
+    register int nright, nleft;
+    int            y, lasty, bottomy, topy;
+
+    /* find the top of the polygon */
+    maxy = miny = vertices[0].y;
+    bottom = top = 0;
+    for (i = 1; i < count; i++)
+    {
+       if (vertices[i].y < miny)
+       {
+           top = i;
+           miny = vertices[i].y;
+       }
+       if (vertices[i].y >= maxy)
+       {
+           bottom = i;
+           maxy = vertices[i].y;
+       }
+    }
+    clockwise = 1;
+    slopeoff = 0;
+
+    i = top;
+    j = StepAround (top, -1, count);
+
+    if (slopes[j].dy * slopes[i].dx > slopes[i].dy * slopes[j].dx)
+    {
+       clockwise = -1;
+       slopeoff = -1;
+    }
+
+    bottomy = ICEIL (maxy) + yi;
+
+    nright = 0;
+
+    s = StepAround (top, slopeoff, count);
+    i = top;
+    while (i != bottom)
+    {
+       if (slopes[s].dy != 0)
+       {
+           y = miPolyBuildEdge (vertices[i].x, vertices[i].y,
+                       slopes[s].k,
+                       slopes[s].dx, slopes[s].dy,
+                       xi, yi, 0,
+                       &right[nright]);
+           if (nright != 0)
+               right[nright-1].height = y - lasty;
+           else
+               topy = y;
+           nright++;
+           lasty = y;
+       }
+
+       i = StepAround (i, clockwise, count);
+       s = StepAround (s, clockwise, count);
+    }
+    if (nright != 0)
+       right[nright-1].height = bottomy - lasty;
+
+    if (slopeoff == 0)
+       slopeoff = -1;
+    else
+       slopeoff = 0;
+
+    nleft = 0;
+    s = StepAround (top, slopeoff, count);
+    i = top;
+    while (i != bottom)
+    {
+       if (slopes[s].dy != 0)
+       {
+           y = miPolyBuildEdge (vertices[i].x, vertices[i].y,
+                          slopes[s].k,
+                          slopes[s].dx,  slopes[s].dy, xi, yi, 1,
+                          &left[nleft]);
+    
+           if (nleft != 0)
+               left[nleft-1].height = y - lasty;
+           nleft++;
+           lasty = y;
+       }
+       i = StepAround (i, -clockwise, count);
+       s = StepAround (s, -clockwise, count);
+    }
+    if (nleft != 0)
+       left[nleft-1].height = bottomy - lasty;
+    *pnleft = nleft;
+    *pnright = nright;
+    *h = bottomy - topy;
+    return topy;
+}
+
+static void
+miLineOnePoint (pDrawable, pGC, pixel, spanData, x, y)
+    DrawablePtr            pDrawable;
+    GCPtr          pGC;
+    unsigned long   pixel;
+    SpanDataPtr            spanData;
+    int                    x, y;
+{
+    DDXPointRec pt;
+    int            wid;
+    unsigned long      oldPixel;
+
+    MILINESETPIXEL (pDrawable, pGC, pixel, oldPixel);
+    if (pGC->fillStyle == FillSolid)
+    {
+       pt.x = x;
+       pt.y = y;
+       (*pGC->ops->PolyPoint) (pDrawable, pGC, CoordModeOrigin, 1, &pt);
+    }
+    else
+    {
+       wid = 1;
+       if (pGC->miTranslate) 
+       {
+           x += pDrawable->x;
+           y += pDrawable->y;
+       }
+       pt.x = x;
+       pt.y = y;
+       (*pGC->ops->FillSpans) (pDrawable, pGC, 1, &pt, &wid, TRUE);
+    }
+    MILINERESETPIXEL (pDrawable, pGC, pixel, oldPixel);
+}
+
+static void
+miLineJoin (pDrawable, pGC, pixel, spanData, pLeft, pRight)
+    DrawablePtr            pDrawable;
+    GCPtr          pGC;
+    unsigned long   pixel;
+    SpanDataPtr            spanData;
+    register LineFacePtr pLeft, pRight;
+{
+    double         mx, my;
+    double         denom;
+    PolyVertexRec   vertices[4];
+    PolySlopeRec    slopes[4];
+    int                    edgecount;
+    PolyEdgeRec            left[4], right[4];
+    int                    nleft, nright;
+    int                    y, height;
+    int                    swapslopes;
+    int                    joinStyle = pGC->joinStyle;
+    int                    lw = pGC->lineWidth;
+
+    if (lw == 1 && !spanData) {
+       /* Lines going in the same direction have no join */
+       if (pLeft->dx >= 0 == pRight->dx <= 0)
+           return;
+       if (joinStyle != JoinRound) {
+           denom = - pLeft->dx * (double)pRight->dy + pRight->dx * (double)pLeft->dy;
+           if (denom == 0)
+               return; /* no join to draw */
+       }
+       if (joinStyle != JoinMiter) {
+           miLineOnePoint (pDrawable, pGC, pixel, spanData, pLeft->x, pLeft->y);
+           return;
+       }
+    } else {
+       if (joinStyle == JoinRound)
+       {
+           miLineArc(pDrawable, pGC, pixel, spanData,
+                     pLeft, pRight,
+                     (double)0.0, (double)0.0, TRUE);
+           return;
+       }
+       denom = - pLeft->dx * (double)pRight->dy + pRight->dx * (double)pLeft->dy;
+       if (denom == 0.0)
+           return;     /* no join to draw */
+    }
+
+    swapslopes = 0;
+    if (denom > 0)
+    {
+       pLeft->xa = -pLeft->xa;
+       pLeft->ya = -pLeft->ya;
+       pLeft->dx = -pLeft->dx;
+       pLeft->dy = -pLeft->dy;
+    }
+    else
+    {
+       swapslopes = 1;
+       pRight->xa = -pRight->xa;
+       pRight->ya = -pRight->ya;
+       pRight->dx = -pRight->dx;
+       pRight->dy = -pRight->dy;
+    }
+
+    vertices[0].x = pRight->xa;
+    vertices[0].y = pRight->ya;
+    slopes[0].dx = -pRight->dy;
+    slopes[0].dy =  pRight->dx;
+    slopes[0].k = 0;
+
+    vertices[1].x = 0;
+    vertices[1].y = 0;
+    slopes[1].dx =  pLeft->dy;
+    slopes[1].dy = -pLeft->dx;
+    slopes[1].k = 0;
+
+    vertices[2].x = pLeft->xa;
+    vertices[2].y = pLeft->ya;
+
+    if (joinStyle == JoinMiter)
+    {
+       my = (pLeft->dy  * (pRight->xa * pRight->dy - pRight->ya * pRight->dx) -
+              pRight->dy * (pLeft->xa  * pLeft->dy  - pLeft->ya  * pLeft->dx )) /
+             denom;
+       if (pLeft->dy != 0)
+       {
+           mx = pLeft->xa + (my - pLeft->ya) *
+                           (double) pLeft->dx / (double) pLeft->dy;
+       }
+       else
+       {
+           mx = pRight->xa + (my - pRight->ya) *
+                           (double) pRight->dx / (double) pRight->dy;
+       }
+       /* check miter limit */
+       if ((mx * mx + my * my) * 4 > SQSECANT * lw * lw)
+           joinStyle = JoinBevel;
+    }
+
+    if (joinStyle == JoinMiter)
+    {
+       slopes[2].dx = pLeft->dx;
+       slopes[2].dy = pLeft->dy;
+       slopes[2].k =  pLeft->k;
+       if (swapslopes)
+       {
+           slopes[2].dx = -slopes[2].dx;
+           slopes[2].dy = -slopes[2].dy;
+           slopes[2].k  = -slopes[2].k;
+       }
+       vertices[3].x = mx;
+       vertices[3].y = my;
+       slopes[3].dx = pRight->dx;
+       slopes[3].dy = pRight->dy;
+       slopes[3].k  = pRight->k;
+       if (swapslopes)
+       {
+           slopes[3].dx = -slopes[3].dx;
+           slopes[3].dy = -slopes[3].dy;
+           slopes[3].k  = -slopes[3].k;
+       }
+       edgecount = 4;
+    }
+    else
+    {
+       double  scale, dx, dy, adx, ady;
+
+       adx = dx = pRight->xa - pLeft->xa;
+       ady = dy = pRight->ya - pLeft->ya;
+       if (adx < 0)
+           adx = -adx;
+       if (ady < 0)
+           ady = -ady;
+       scale = ady;
+       if (adx > ady)
+           scale = adx;
+       slopes[2].dx = (dx * 65536) / scale;
+       slopes[2].dy = (dy * 65536) / scale;
+       slopes[2].k = ((pLeft->xa + pRight->xa) * slopes[2].dy -
+                      (pLeft->ya + pRight->ya) * slopes[2].dx) / 2.0;
+       edgecount = 3;
+    }
+
+    y = miPolyBuildPoly (vertices, slopes, edgecount, pLeft->x, pLeft->y,
+                  left, right, &nleft, &nright, &height);
+    miFillPolyHelper (pDrawable, pGC, pixel, spanData, y, height, left, right, nleft, nright);
+}
+
+static int
+miLineArcI (pDraw, pGC, xorg, yorg, points, widths)
+    DrawablePtr            pDraw;
+    GCPtr          pGC;
+    int                    xorg, yorg;
+    DDXPointPtr            points;
+    int                    *widths;
+{
+    register DDXPointPtr tpts, bpts;
+    register int *twids, *bwids;
+    register int x, y, e, ex, slw;
+
+    tpts = points;
+    twids = widths;
+    if (pGC->miTranslate)
+    {
+       xorg += pDraw->x;
+       yorg += pDraw->y;
+    }
+    slw = pGC->lineWidth;
+    if (slw == 1)
+    {
+       tpts->x = xorg;
+       tpts->y = yorg;
+       *twids = 1;
+       return 1;
+    }
+    bpts = tpts + slw;
+    bwids = twids + slw;
+    y = (slw >> 1) + 1;
+    if (slw & 1)
+       e = - ((y << 2) + 3);
+    else
+       e = - (y << 3);
+    ex = -4;
+    x = 0;
+    while (y)
+    {
+       e += (y << 3) - 4;
+       while (e >= 0)
+       {
+           x++;
+           e += (ex = -((x << 3) + 4));
+       }
+       y--;
+       slw = (x << 1) + 1;
+       if ((e == ex) && (slw > 1))
+           slw--;
+       tpts->x = xorg - x;
+       tpts->y = yorg - y;
+       tpts++;
+       *twids++ = slw;
+       if ((y != 0) && ((slw > 1) || (e != ex)))
+       {
+           bpts--;
+           bpts->x = xorg - x;
+           bpts->y = yorg + y;
+           *--bwids = slw;
+       }
+    }
+    return (pGC->lineWidth);
+}
+
+#define CLIPSTEPEDGE(edgey,edge,edgeleft) \
+    if (ybase == edgey) \
+    { \
+       if (edgeleft) \
+       { \
+           if (edge->x > xcl) \
+               xcl = edge->x; \
+       } \
+       else \
+       { \
+           if (edge->x < xcr) \
+               xcr = edge->x; \
+       } \
+       edgey++; \
+       edge->x += edge->stepx; \
+       edge->e += edge->dx; \
+       if (edge->e > 0) \
+       { \
+           edge->x += edge->signdx; \
+           edge->e -= edge->dy; \
+       } \
+    }
+
+static int
+miLineArcD (pDraw, pGC, xorg, yorg, points, widths,
+           edge1, edgey1, edgeleft1, edge2, edgey2, edgeleft2)
+    DrawablePtr            pDraw;
+    GCPtr          pGC;
+    double         xorg, yorg;
+    DDXPointPtr            points;
+    int                    *widths;
+    PolyEdgePtr            edge1, edge2;
+    int                    edgey1, edgey2;
+    Bool           edgeleft1, edgeleft2;
+{
+    register DDXPointPtr pts;
+    register int *wids;
+    double radius, x0, y0, el, er, yk, xlk, xrk, k;
+    int xbase, ybase, y, boty, xl, xr, xcl, xcr;
+    int ymin, ymax;
+    Bool edge1IsMin, edge2IsMin;
+    int ymin1, ymin2;
+
+    pts = points;
+    wids = widths;
+    xbase = floor(xorg);
+    x0 = xorg - xbase;
+    ybase = ICEIL (yorg);
+    y0 = yorg - ybase;
+    if (pGC->miTranslate)
+    {
+       xbase += pDraw->x;
+       ybase += pDraw->y;
+       edge1->x += pDraw->x;
+       edge2->x += pDraw->x;
+       edgey1 += pDraw->y;
+       edgey2 += pDraw->y;
+    }
+    xlk = x0 + x0 + 1.0;
+    xrk = x0 + x0 - 1.0;
+    yk = y0 + y0 - 1.0;
+    radius = ((double)pGC->lineWidth) / 2.0;
+    y = floor(radius - y0 + 1.0);
+    ybase -= y;
+    ymin = ybase;
+    ymax = 65536;
+    edge1IsMin = FALSE;
+    ymin1 = edgey1;
+    if (edge1->dy >= 0)
+    {
+       if (!edge1->dy)
+       {
+           if (edgeleft1)
+               edge1IsMin = TRUE;
+           else
+               ymax = edgey1;
+           edgey1 = 65536;
+       }
+       else
+       {
+           if ((edge1->signdx < 0) == edgeleft1)
+               edge1IsMin = TRUE;
+       }
+    }
+    edge2IsMin = FALSE;
+    ymin2 = edgey2;
+    if (edge2->dy >= 0)
+    {
+       if (!edge2->dy)
+       {
+           if (edgeleft2)
+               edge2IsMin = TRUE;
+           else
+               ymax = edgey2;
+           edgey2 = 65536;
+       }
+       else
+       {
+           if ((edge2->signdx < 0) == edgeleft2)
+               edge2IsMin = TRUE;
+       }
+    }
+    if (edge1IsMin)
+    {
+       ymin = ymin1;
+       if (edge2IsMin && ymin1 > ymin2)
+           ymin = ymin2;
+    } else if (edge2IsMin)
+       ymin = ymin2;
+    el = radius * radius - ((y + y0) * (y + y0)) - (x0 * x0);
+    er = el + xrk;
+    xl = 1;
+    xr = 0;
+    if (x0 < 0.5)
+    {
+       xl = 0;
+       el -= xlk;
+    }
+    boty = (y0 < -0.5) ? 1 : 0;
+    if (ybase + y - boty > ymax)
+       boty = ymax - ybase - y;
+    while (y > boty)
+    {
+       k = (y << 1) + yk;
+       er += k;
+       while (er > 0.0)
+       {
+           xr++;
+           er += xrk - (xr << 1);
+       }
+       el += k;
+       while (el >= 0.0)
+       {
+           xl--;
+           el += (xl << 1) - xlk;
+       }
+       y--;
+       ybase++;
+       if (ybase < ymin)
+           continue;
+       xcl = xl + xbase;
+       xcr = xr + xbase;
+       CLIPSTEPEDGE(edgey1, edge1, edgeleft1);
+       CLIPSTEPEDGE(edgey2, edge2, edgeleft2);
+       if (xcr >= xcl)
+       {
+           pts->x = xcl;
+           pts->y = ybase;
+           pts++;
+           *wids++ = xcr - xcl + 1;
+       }
+    }
+    er = xrk - (xr << 1) - er;
+    el = (xl << 1) - xlk - el;
+    boty = floor(-y0 - radius + 1.0);
+    if (ybase + y - boty > ymax)
+       boty = ymax - ybase - y;
+    while (y > boty)
+    {
+       k = (y << 1) + yk;
+       er -= k;
+       while ((er >= 0.0) && (xr >= 0))
+       {
+           xr--;
+           er += xrk - (xr << 1);
+       }
+       el -= k;
+       while ((el > 0.0) && (xl <= 0))
+       {
+           xl++;
+           el += (xl << 1) - xlk;
+       }
+       y--;
+       ybase++;
+       if (ybase < ymin)
+           continue;
+       xcl = xl + xbase;
+       xcr = xr + xbase;
+       CLIPSTEPEDGE(edgey1, edge1, edgeleft1);
+       CLIPSTEPEDGE(edgey2, edge2, edgeleft2);
+       if (xcr >= xcl)
+       {
+           pts->x = xcl;
+           pts->y = ybase;
+           pts++;
+           *wids++ = xcr - xcl + 1;
+       }
+    }
+    return (pts - points);
+}
+
+int
+miRoundJoinFace (face, edge, leftEdge)
+    register LineFacePtr face;
+    register PolyEdgePtr edge;
+    Bool       *leftEdge;
+{
+    int            y;
+    int            dx, dy;
+    double  xa, ya;
+    Bool       left;
+
+    dx = -face->dy;
+    dy = face->dx;
+    xa = face->xa;
+    ya = face->ya;
+    left = 1;
+    if (ya > 0)
+    {
+       ya = 0.0;
+       xa = 0.0;
+    }
+    if (dy < 0 || dy == 0 && dx > 0)
+    {
+       dx = -dx;
+       dy = -dy;
+       left = !left;
+    }
+    if (dx == 0 && dy == 0)
+       dy = 1;
+    if (dy == 0)
+    {
+       y = ICEIL (face->ya) + face->y;
+       edge->x = -32767;
+       edge->stepx = 0;
+       edge->signdx = 0;
+       edge->e = -1;
+       edge->dy = 0;
+       edge->dx = 0;
+       edge->height = 0;
+    }
+    else
+    {
+       y = miPolyBuildEdge (xa, ya, 0.0, dx, dy, face->x, face->y, !left, edge);
+       edge->height = 32767;
+    }
+    *leftEdge = !left;
+    return y;
+}
+
+void
+miRoundJoinClip (pLeft, pRight, edge1, edge2, y1, y2, left1, left2)
+    register LineFacePtr pLeft, pRight;
+    PolyEdgePtr        edge1, edge2;
+    int                *y1, *y2;
+    Bool       *left1, *left2;
+{
+    double     denom;
+
+    denom = - pLeft->dx * (double)pRight->dy + pRight->dx * (double)pLeft->dy;
+
+    if (denom >= 0)
+    {
+       pLeft->xa = -pLeft->xa;
+       pLeft->ya = -pLeft->ya;
+    }
+    else
+    {
+       pRight->xa = -pRight->xa;
+       pRight->ya = -pRight->ya;
+    }
+    *y1 = miRoundJoinFace (pLeft, edge1, left1);
+    *y2 = miRoundJoinFace (pRight, edge2, left2);
+}
+
+int
+miRoundCapClip (face, isInt, edge, leftEdge)
+    register LineFacePtr face;
+    Bool       isInt;
+    register PolyEdgePtr edge;
+    Bool       *leftEdge;
+{
+    int            y;
+    register int dx, dy;
+    double  xa, ya, k;
+    Bool       left;
+
+    dx = -face->dy;
+    dy = face->dx;
+    xa = face->xa;
+    ya = face->ya;
+    k = 0.0;
+    if (!isInt)
+       k = face->k;
+    left = 1;
+    if (dy < 0 || dy == 0 && dx > 0)
+    {
+       dx = -dx;
+       dy = -dy;
+       xa = -xa;
+       ya = -ya;
+       left = !left;
+    }
+    if (dx == 0 && dy == 0)
+       dy = 1;
+    if (dy == 0)
+    {
+       y = ICEIL (face->ya) + face->y;
+       edge->x = -32767;
+       edge->stepx = 0;
+       edge->signdx = 0;
+       edge->e = -1;
+       edge->dy = 0;
+       edge->dx = 0;
+       edge->height = 0;
+    }
+    else
+    {
+       y = miPolyBuildEdge (xa, ya, k, dx, dy, face->x, face->y, !left, edge);
+       edge->height = 32767;
+    }
+    *leftEdge = !left;
+    return y;
+}
+
+static void
+miLineArc (pDraw, pGC, pixel, spanData, leftFace, rightFace, xorg, yorg, isInt)
+    DrawablePtr            pDraw;
+    register GCPtr  pGC;
+    unsigned long   pixel;
+    SpanDataPtr            spanData;
+    register LineFacePtr leftFace, rightFace;
+    double         xorg, yorg;
+    Bool           isInt;
+{
+    DDXPointPtr points;
+    int *widths;
+    int xorgi, yorgi;
+    XID                oldPixel;
+    Spans spanRec;
+    int n;
+    PolyEdgeRec        edge1, edge2;
+    int                edgey1, edgey2;
+    Bool       edgeleft1, edgeleft2;
+
+    if (isInt)
+    {
+       xorgi = leftFace ? leftFace->x : rightFace->x;
+       yorgi = leftFace ? leftFace->y : rightFace->y;
+    }
+    edgey1 = 65536;
+    edgey2 = 65536;
+    edge1.x = 0; /* not used, keep memory checkers happy */
+    edge1.dy = -1;
+    edge2.x = 0; /* not used, keep memory checkers happy */
+    edge2.dy = -1;
+    edgeleft1 = FALSE;
+    edgeleft2 = FALSE;
+    if ((pGC->lineStyle != LineSolid || pGC->lineWidth > 2) &&
+       (pGC->capStyle == CapRound && pGC->joinStyle != JoinRound ||
+        pGC->joinStyle == JoinRound && pGC->capStyle == CapButt))
+    {
+       if (isInt)
+       {
+           xorg = (double) xorgi;
+           yorg = (double) yorgi;
+       }
+       if (leftFace && rightFace)
+       {
+           miRoundJoinClip (leftFace, rightFace, &edge1, &edge2,
+                            &edgey1, &edgey2, &edgeleft1, &edgeleft2);
+       }
+       else if (leftFace)
+       {
+           edgey1 = miRoundCapClip (leftFace, isInt, &edge1, &edgeleft1);
+       }
+       else if (rightFace)
+       {
+           edgey2 = miRoundCapClip (rightFace, isInt, &edge2, &edgeleft2);
+       }
+       isInt = FALSE;
+    }
+    if (!spanData)
+    {
+       points = (DDXPointPtr)ALLOCATE_LOCAL(sizeof(DDXPointRec) * pGC->lineWidth);
+       if (!points)
+           return;
+       widths = (int *)ALLOCATE_LOCAL(sizeof(int) * pGC->lineWidth);
+       if (!widths)
+       {
+           DEALLOCATE_LOCAL(points);
+           return;
+       }
+       oldPixel = pGC->fgPixel;
+       if (pixel != oldPixel)
+       {
+           DoChangeGC(pGC, GCForeground, (XID *)&pixel, FALSE);
+           ValidateGC (pDraw, pGC);
+       }
+    }
+    else
+    {
+       points = (DDXPointPtr) xalloc (pGC->lineWidth * sizeof (DDXPointRec));
+       if (!points)
+           return;
+       widths = (int *) xalloc (pGC->lineWidth * sizeof (int));
+       if (!widths)
+       {
+           xfree (points);
+           return;
+       }
+       spanRec.points = points;
+       spanRec.widths = widths;
+    }
+    if (isInt)
+       n = miLineArcI(pDraw, pGC, xorgi, yorgi, points, widths);
+    else
+       n = miLineArcD(pDraw, pGC, xorg, yorg, points, widths,
+                      &edge1, edgey1, edgeleft1,
+                      &edge2, edgey2, edgeleft2);
+
+    if (!spanData)
+    {
+       (*pGC->ops->FillSpans)(pDraw, pGC, n, points, widths, TRUE);
+       DEALLOCATE_LOCAL(widths);
+       DEALLOCATE_LOCAL(points);
+       if (pixel != oldPixel)
+       {
+           DoChangeGC(pGC, GCForeground, &oldPixel, FALSE);
+           ValidateGC (pDraw, pGC);
+       }
+    }
+    else
+    {
+       spanRec.count = n;
+       AppendSpanGroup (pGC, pixel, &spanRec, spanData)
+    }
+}
+
+void
+miLineProjectingCap (pDrawable, pGC, pixel, spanData, face, isLeft, xorg, yorg, isInt)
+    DrawablePtr            pDrawable;
+    register GCPtr  pGC;
+    unsigned long   pixel;
+    SpanDataPtr            spanData;
+    register LineFacePtr face;
+    Bool           isLeft;
+    double         xorg, yorg;
+    Bool           isInt;
+{
+    int        xorgi, yorgi;
+    int        lw;
+    PolyEdgeRec        lefts[2], rights[2];
+    int                lefty, righty, topy, bottomy;
+    PolyEdgePtr left, right;
+    PolyEdgePtr        top, bottom;
+    double     xa,ya;
+    double     k;
+    double     xap, yap;
+    int                dx, dy;
+    double     projectXoff, projectYoff;
+    double     maxy;
+    int                finaly;
+    
+    if (isInt)
+    {
+       xorgi = face->x;
+       yorgi = face->y;
+    }
+    lw = pGC->lineWidth;
+    dx = face->dx;
+    dy = face->dy;
+    k = face->k;
+    if (dy == 0)
+    {
+       lefts[0].height = lw;
+       lefts[0].x = xorgi;
+       if (isLeft)
+           lefts[0].x -= (lw >> 1);
+       lefts[0].stepx = 0;
+       lefts[0].signdx = 1;
+       lefts[0].e = -lw;
+       lefts[0].dx = 0;
+       lefts[0].dy = lw;
+       rights[0].height = lw;
+       rights[0].x = xorgi;
+       if (!isLeft)
+           rights[0].x += (lw + 1 >> 1);
+       rights[0].stepx = 0;
+       rights[0].signdx = 1;
+       rights[0].e = -lw;
+       rights[0].dx = 0;
+       rights[0].dy = lw;
+       miFillPolyHelper (pDrawable, pGC, pixel, spanData, yorgi - (lw >> 1), lw,
+                    lefts, rights, 1, 1);
+    }
+    else if (dx == 0)
+    {
+       topy = yorgi;
+       bottomy = yorgi + dy;
+       if (isLeft)
+           topy -= (lw >> 1);
+       else
+           bottomy += (lw >> 1);
+       lefts[0].height = bottomy - topy;
+       lefts[0].x = xorgi - (lw >> 1);
+       lefts[0].stepx = 0;
+       lefts[0].signdx = 1;
+       lefts[0].e = -dy;
+       lefts[0].dx = dx;
+       lefts[0].dy = dy;
+
+       rights[0].height = bottomy - topy;
+       rights[0].x = lefts[0].x + (lw-1);
+       rights[0].stepx = 0;
+       rights[0].signdx = 1;
+       rights[0].e = -dy;
+       rights[0].dx = dx;
+       rights[0].dy = dy;
+       miFillPolyHelper (pDrawable, pGC, pixel, spanData, topy, bottomy - topy, lefts, rights, 1, 1);
+    }
+    else
+    {
+       xa = face->xa;
+       ya = face->ya;
+       projectXoff = -ya;
+       projectYoff = xa;
+       if (dx < 0)
+       {
+           right = &rights[1];
+           left = &lefts[0];
+           top = &rights[0];
+           bottom = &lefts[1];
+       }
+       else
+       {
+           right = &rights[0];
+           left = &lefts[1];
+           top = &lefts[0];
+           bottom = &rights[1];
+       }
+       if (isLeft)
+       {
+           righty = miPolyBuildEdge (xa, ya,
+                    k, dx, dy, xorgi, yorgi, 0, right);
+           
+           xa = -xa;
+           ya = -ya;
+           k = -k;
+           lefty = miPolyBuildEdge (xa - projectXoff, ya - projectYoff,
+                                    k, dx, dy, xorgi, yorgi, 1, left);
+           if (dx > 0)
+           {
+               ya = -ya;
+               xa = -xa;
+           }
+           xap = xa - projectXoff;
+           yap = ya - projectYoff;
+           topy = miPolyBuildEdge (xap, yap, xap * dx + yap * dy,
+                                   -dy, dx, xorgi, yorgi, dx > 0, top);
+           bottomy = miPolyBuildEdge (xa, ya,
+                                      0.0, -dy, dx, xorgi, yorgi, dx < 0, bottom);
+           maxy = -ya;
+       }
+       else
+       {
+           righty = miPolyBuildEdge (xa - projectXoff, ya - projectYoff,
+                    k, dx, dy, xorgi, yorgi, 0, right);
+           
+           xa = -xa;
+           ya = -ya;
+           k = -k;
+           lefty = miPolyBuildEdge (xa, ya,
+                   k, dx, dy, xorgi, yorgi, 1, left);
+           if (dx > 0)
+           {
+               ya = -ya;
+               xa = -xa;
+           }
+           xap = xa - projectXoff;
+           yap = ya - projectYoff;
+           topy = miPolyBuildEdge (xa, ya, 0.0, -dy, dx, xorgi, xorgi, dx > 0, top);
+           bottomy = miPolyBuildEdge (xap, yap, xap * dx + yap * dy,
+                                      -dy, dx, xorgi, xorgi, dx < 0, bottom);
+           maxy = -ya + projectYoff;
+       }
+       finaly = ICEIL(maxy) + yorgi;
+       if (dx < 0)
+       {
+           left->height = bottomy - lefty;
+           right->height = finaly - righty;
+           top->height = righty - topy;
+       }
+       else
+       {
+           right->height =  bottomy - righty;
+           left->height = finaly - lefty;
+           top->height = lefty - topy;
+       }
+       bottom->height = finaly - bottomy;
+       miFillPolyHelper (pDrawable, pGC, pixel, spanData, topy,
+                    bottom->height + bottomy - topy, lefts, rights, 2, 2);
+    }
+}
+
+static void
+miWideSegment (pDrawable, pGC, pixel, spanData,
+              x1, y1, x2, y2, projectLeft, projectRight, leftFace, rightFace)
+    DrawablePtr            pDrawable;
+    GCPtr          pGC;
+    unsigned long   pixel;
+    SpanDataPtr            spanData;
+    register int    x1, y1, x2, y2;
+    Bool           projectLeft, projectRight;
+    register LineFacePtr leftFace, rightFace;
+{
+    double     l, L, r;
+    double     xa, ya;
+    double     projectXoff, projectYoff;
+    double     k;
+    double     maxy;
+    int                x, y;
+    int                dx, dy;
+    int                finaly;
+    PolyEdgePtr left, right;
+    PolyEdgePtr        top, bottom;
+    int                lefty, righty, topy, bottomy;
+    int                signdx;
+    PolyEdgeRec        lefts[2], rights[2];
+    LineFacePtr        tface;
+    int                lw = pGC->lineWidth;
+
+    /* draw top-to-bottom always */
+    if (y2 < y1 || y2 == y1 && x2 < x1)
+    {
+       x = x1;
+       x1 = x2;
+       x2 = x;
+
+       y = y1;
+       y1 = y2;
+       y2 = y;
+
+       x = projectLeft;
+       projectLeft = projectRight;
+       projectRight = x;
+
+       tface = leftFace;
+       leftFace = rightFace;
+       rightFace = tface;
+    }
+
+    dy = y2 - y1;
+    signdx = 1;
+    dx = x2 - x1;
+    if (dx < 0)
+       signdx = -1;
+
+    leftFace->x = x1;
+    leftFace->y = y1;
+    leftFace->dx = dx;
+    leftFace->dy = dy;
+
+    rightFace->x = x2;
+    rightFace->y = y2;
+    rightFace->dx = -dx;
+    rightFace->dy = -dy;
+
+    if (dy == 0)
+    {
+       rightFace->xa = 0;
+       rightFace->ya = (double) lw / 2.0;
+       rightFace->k = -(double) (lw * dx) / 2.0;
+       leftFace->xa = 0;
+       leftFace->ya = -rightFace->ya;
+       leftFace->k = rightFace->k;
+       x = x1;
+       if (projectLeft)
+           x -= (lw >> 1);
+       y = y1 - (lw >> 1);
+       dx = x2 - x;
+       if (projectRight)
+           dx += (lw + 1 >> 1);
+       dy = lw;
+       miFillRectPolyHelper (pDrawable, pGC, pixel, spanData,
+                             x, y, dx, dy);
+    }
+    else if (dx == 0)
+    {
+       leftFace->xa =  (double) lw / 2.0;
+       leftFace->ya = 0;
+       leftFace->k = (double) (lw * dy) / 2.0;
+       rightFace->xa = -leftFace->xa;
+       rightFace->ya = 0;
+       rightFace->k = leftFace->k;
+       y = y1;
+       if (projectLeft)
+           y -= lw >> 1;
+       x = x1 - (lw >> 1);
+       dy = y2 - y;
+       if (projectRight)
+           dy += (lw + 1 >> 1);
+       dx = lw;
+       miFillRectPolyHelper (pDrawable, pGC, pixel, spanData,
+                             x, y, dx, dy);
+    }
+    else
+    {
+       l = ((double) lw) / 2.0;
+       L = hypot ((double) dx, (double) dy);
+
+       if (dx < 0)
+       {
+           right = &rights[1];
+           left = &lefts[0];
+           top = &rights[0];
+           bottom = &lefts[1];
+       }
+       else
+       {
+           right = &rights[0];
+           left = &lefts[1];
+           top = &lefts[0];
+           bottom = &rights[1];
+       }
+       r = l / L;
+
+       /* coord of upper bound at integral y */
+       ya = -r * dx;
+       xa = r * dy;
+
+       if (projectLeft | projectRight)
+       {
+           projectXoff = -ya;
+           projectYoff = xa;
+       }
+
+       /* xa * dy - ya * dx */
+       k = l * L;
+
+       leftFace->xa = xa;
+       leftFace->ya = ya;
+       leftFace->k = k;
+       rightFace->xa = -xa;
+       rightFace->ya = -ya;
+       rightFace->k = k;
+
+       if (projectLeft)
+           righty = miPolyBuildEdge (xa - projectXoff, ya - projectYoff,
+                                     k, dx, dy, x1, y1, 0, right);
+       else
+           righty = miPolyBuildEdge (xa, ya,
+                                     k, dx, dy, x1, y1, 0, right);
+
+       /* coord of lower bound at integral y */
+       ya = -ya;
+       xa = -xa;
+
+       /* xa * dy - ya * dx */
+       k = - k;
+
+       if (projectLeft)
+           lefty = miPolyBuildEdge (xa - projectXoff, ya - projectYoff,
+                                    k, dx, dy, x1, y1, 1, left);
+       else
+           lefty = miPolyBuildEdge (xa, ya,
+                                    k, dx, dy, x1, y1, 1, left);
+
+       /* coord of top face at integral y */
+
+       if (signdx > 0)
+       {
+           ya = -ya;
+           xa = -xa;
+       }
+
+       if (projectLeft)
+       {
+           double xap = xa - projectXoff;
+           double yap = ya - projectYoff;
+           topy = miPolyBuildEdge (xap, yap, xap * dx + yap * dy,
+                                   -dy, dx, x1, y1, dx > 0, top);
+       }
+       else
+           topy = miPolyBuildEdge (xa, ya, 0.0, -dy, dx, x1, y1, dx > 0, top);
+
+       /* coord of bottom face at integral y */
+
+       if (projectRight)
+       {
+           double xap = xa + projectXoff;
+           double yap = ya + projectYoff;
+           bottomy = miPolyBuildEdge (xap, yap, xap * dx + yap * dy,
+                                      -dy, dx, x2, y2, dx < 0, bottom);
+           maxy = -ya + projectYoff;
+       }
+       else
+       {
+           bottomy = miPolyBuildEdge (xa, ya,
+                                      0.0, -dy, dx, x2, y2, dx < 0, bottom);
+           maxy = -ya;
+       }
+
+       finaly = ICEIL (maxy) + y2;
+
+       if (dx < 0)
+       {
+           left->height = bottomy - lefty;
+           right->height = finaly - righty;
+           top->height = righty - topy;
+       }
+       else
+       {
+           right->height =  bottomy - righty;
+           left->height = finaly - lefty;
+           top->height = lefty - topy;
+       }
+       bottom->height = finaly - bottomy;
+       miFillPolyHelper (pDrawable, pGC, pixel, spanData, topy,
+                    bottom->height + bottomy - topy, lefts, rights, 2, 2);
+    }
+}
+
+SpanDataPtr
+miSetupSpanData (pGC, spanData, npt)
+    register GCPtr pGC;
+    SpanDataPtr        spanData;
+    int                npt;
+{
+    if (npt < 3 && pGC->capStyle != CapRound || miSpansEasyRop(pGC->alu))
+       return (SpanDataPtr) NULL;
+    if (pGC->lineStyle == LineDoubleDash)
+       miInitSpanGroup (&spanData->bgGroup);
+    miInitSpanGroup (&spanData->fgGroup);
+    return spanData;
+}
+
+void
+miCleanupSpanData (pDrawable, pGC, spanData)
+    DrawablePtr        pDrawable;
+    GCPtr      pGC;
+    SpanDataPtr        spanData;
+{
+    if (pGC->lineStyle == LineDoubleDash)
+    {
+       XID oldPixel, pixel;
+       
+       pixel = pGC->bgPixel;
+       oldPixel = pGC->fgPixel;
+       if (pixel != oldPixel)
+       {
+           DoChangeGC (pGC, GCForeground, &pixel, FALSE);
+           ValidateGC (pDrawable, pGC);
+       }
+       miFillUniqueSpanGroup (pDrawable, pGC, &spanData->bgGroup);
+       miFreeSpanGroup (&spanData->bgGroup);
+       if (pixel != oldPixel)
+       {
+           DoChangeGC (pGC, GCForeground, &oldPixel, FALSE);
+           ValidateGC (pDrawable, pGC);
+       }
+    }
+    miFillUniqueSpanGroup (pDrawable, pGC, &spanData->fgGroup);
+    miFreeSpanGroup (&spanData->fgGroup);
+}
+
+void
+miWideLine (pDrawable, pGC, mode, npt, pPts)
+    DrawablePtr        pDrawable;
+    register GCPtr pGC;
+    int                mode;
+    register int npt;
+    register DDXPointPtr pPts;
+{
+    int                    x1, y1, x2, y2;
+    SpanDataRec            spanDataRec;
+    SpanDataPtr            spanData;
+    unsigned long   pixel;
+    Bool           projectLeft, projectRight;
+    LineFaceRec            leftFace, rightFace, prevRightFace;
+    LineFaceRec            firstFace;
+    register int    first;
+    Bool           somethingDrawn = FALSE;
+    Bool           selfJoin;
+
+    spanData = miSetupSpanData (pGC, &spanDataRec, npt);
+    pixel = pGC->fgPixel;
+    x2 = pPts->x;
+    y2 = pPts->y;
+    first = TRUE;
+    selfJoin = FALSE;
+    if (npt > 1)
+    {
+       if (mode == CoordModePrevious)
+       {
+           int nptTmp;
+           DDXPointPtr pPtsTmp;
+    
+           x1 = x2;
+           y1 = y2;
+           nptTmp = npt;
+           pPtsTmp = pPts + 1;
+           while (--nptTmp)
+           {
+               x1 += pPtsTmp->x;
+               y1 += pPtsTmp->y;
+               ++pPtsTmp;
+           }
+           if (x2 == x1 && y2 == y1)
+               selfJoin = TRUE;
+       }
+       else if (x2 == pPts[npt-1].x && y2 == pPts[npt-1].y)
+       {
+           selfJoin = TRUE;
+       }
+    }
+    projectLeft = pGC->capStyle == CapProjecting && !selfJoin;
+    projectRight = FALSE;
+    while (--npt)
+    {
+       x1 = x2;
+       y1 = y2;
+       ++pPts;
+       x2 = pPts->x;
+       y2 = pPts->y;
+       if (mode == CoordModePrevious)
+       {
+           x2 += x1;
+           y2 += y1;
+       }
+       if (x1 != x2 || y1 != y2)
+       {
+           somethingDrawn = TRUE;
+           if (npt == 1 && pGC->capStyle == CapProjecting && !selfJoin)
+               projectRight = TRUE;
+           miWideSegment (pDrawable, pGC, pixel, spanData, x1, y1, x2, y2,
+                          projectLeft, projectRight, &leftFace, &rightFace);
+           if (first)
+           {
+               if (selfJoin)
+                   firstFace = leftFace;
+               else if (pGC->capStyle == CapRound)
+               {
+                   if (pGC->lineWidth == 1 && !spanData)
+                       miLineOnePoint (pDrawable, pGC, pixel, spanData, x1, y1);
+                   else
+                       miLineArc (pDrawable, pGC, pixel, spanData,
+                                  &leftFace, (LineFacePtr) NULL,
+                                  (double)0.0, (double)0.0,
+                                  TRUE);
+               }
+           }
+           else
+           {
+               miLineJoin (pDrawable, pGC, pixel, spanData, &leftFace,
+                           &prevRightFace);
+           }
+           prevRightFace = rightFace;
+           first = FALSE;
+           projectLeft = FALSE;
+       }
+       if (npt == 1 && somethingDrawn)
+       {
+           if (selfJoin)
+               miLineJoin (pDrawable, pGC, pixel, spanData, &firstFace,
+                           &rightFace);
+           else if (pGC->capStyle == CapRound)
+           {
+               if (pGC->lineWidth == 1 && !spanData)
+                   miLineOnePoint (pDrawable, pGC, pixel, spanData, x2, y2);
+               else
+                   miLineArc (pDrawable, pGC, pixel, spanData,
+                              (LineFacePtr) NULL, &rightFace,
+                              (double)0.0, (double)0.0,
+                              TRUE);
+           }
+       }
+    }
+    /* handle crock where all points are coincedent */
+    if (!somethingDrawn)
+    {
+       projectLeft = pGC->capStyle == CapProjecting;
+       miWideSegment (pDrawable, pGC, pixel, spanData,
+                      x2, y2, x2, y2, projectLeft, projectLeft,
+                      &leftFace, &rightFace);
+       if (pGC->capStyle == CapRound)
+       {
+           miLineArc (pDrawable, pGC, pixel, spanData,
+                      &leftFace, (LineFacePtr) NULL,
+                      (double)0.0, (double)0.0,
+                      TRUE);
+           rightFace.dx = -1;  /* sleezy hack to make it work */
+           miLineArc (pDrawable, pGC, pixel, spanData,
+                      (LineFacePtr) NULL, &rightFace,
+                      (double)0.0, (double)0.0,
+                      TRUE);
+       }
+    }
+    if (spanData)
+       miCleanupSpanData (pDrawable, pGC, spanData);
+}
+
+#define V_TOP      0
+#define V_RIGHT            1
+#define V_BOTTOM    2
+#define V_LEFT     3
+
+static void
+miWideDashSegment (pDrawable, pGC, spanData, pDashOffset, pDashIndex,
+          x1, y1, x2, y2, projectLeft, projectRight, leftFace, rightFace)
+    DrawablePtr            pDrawable;
+    register GCPtr  pGC;
+    int                    *pDashOffset, *pDashIndex;
+    SpanDataPtr            spanData;
+    int                    x1, y1, x2, y2;
+    Bool           projectLeft, projectRight;
+    LineFacePtr            leftFace, rightFace;
+{
+    int                    dashIndex, dashRemain;
+    unsigned char   *pDash;
+    double         L, l;
+    double         k;
+    PolyVertexRec   vertices[4];
+    PolyVertexRec   saveRight, saveBottom;
+    PolySlopeRec    slopes[4];
+    PolyEdgeRec            left[2], right[2];
+    LineFaceRec            lcapFace, rcapFace;
+    int                    nleft, nright;
+    int                    h;
+    int                    y;
+    int                    dy, dx;
+    unsigned long   pixel;
+    double         LRemain;
+    double         r;
+    double         rdx, rdy;
+    double         dashDx, dashDy;
+    double         saveK;
+    Bool           first = TRUE;
+    double         lcenterx, lcentery, rcenterx, rcentery;
+    unsigned long   fgPixel, bgPixel;
+    
+    dx = x2 - x1;
+    dy = y2 - y1;
+    dashIndex = *pDashIndex;
+    pDash = pGC->dash;
+    dashRemain = pDash[dashIndex] - *pDashOffset;
+    fgPixel = pGC->fgPixel;
+    bgPixel = pGC->bgPixel;
+    if (pGC->fillStyle == FillOpaqueStippled ||
+       pGC->fillStyle == FillTiled)
+    {
+       bgPixel = fgPixel;
+    }
+
+    l = ((double) pGC->lineWidth) / 2.0;
+    if (dx == 0)
+    {
+       L = dy;
+       rdx = 0;
+       rdy = l;
+       if (dy < 0)
+       {
+           L = -dy;
+           rdy = -l;
+       }
+    }
+    else if (dy == 0)
+    {
+       L = dx;
+       rdx = l;
+       rdy = 0;
+       if (dx < 0)
+       {
+           L = -dx;
+           rdx = -l;
+       }
+    }
+    else
+    {
+       L = hypot ((double) dx, (double) dy);
+       r = l / L;
+
+       rdx = r * dx;
+       rdy = r * dy;
+    }
+    k = l * L;
+    LRemain = L;
+    /* All position comments are relative to a line with dx and dy > 0,
+     * but the code does not depend on this */
+    /* top */
+    slopes[V_TOP].dx = dx;
+    slopes[V_TOP].dy = dy;
+    slopes[V_TOP].k = k;
+    /* right */
+    slopes[V_RIGHT].dx = -dy;
+    slopes[V_RIGHT].dy = dx;
+    slopes[V_RIGHT].k = 0;
+    /* bottom */
+    slopes[V_BOTTOM].dx = -dx;
+    slopes[V_BOTTOM].dy = -dy;
+    slopes[V_BOTTOM].k = k;
+    /* left */
+    slopes[V_LEFT].dx = dy;
+    slopes[V_LEFT].dy = -dx;
+    slopes[V_LEFT].k = 0;
+
+    /* preload the start coordinates */
+    vertices[V_RIGHT].x = vertices[V_TOP].x = rdy;
+    vertices[V_RIGHT].y = vertices[V_TOP].y = -rdx;
+
+    vertices[V_BOTTOM].x = vertices[V_LEFT].x = -rdy;
+    vertices[V_BOTTOM].y = vertices[V_LEFT].y = rdx;
+
+    if (projectLeft)
+    {
+       vertices[V_TOP].x -= rdx;
+       vertices[V_TOP].y -= rdy;
+
+       vertices[V_LEFT].x -= rdx;
+       vertices[V_LEFT].y -= rdy;
+
+       slopes[V_LEFT].k = rdx * dx + rdy * dy;
+    }
+
+    lcenterx = x1;
+    lcentery = y1;
+
+    if (pGC->capStyle == CapRound)
+    {
+       lcapFace.dx = dx;
+       lcapFace.dy = dy;
+       lcapFace.x = x1;
+       lcapFace.y = y1;
+
+       rcapFace.dx = -dx;
+       rcapFace.dy = -dy;
+       rcapFace.x = x1;
+       rcapFace.y = y1;
+    }
+    while (LRemain > dashRemain)
+    {
+       dashDx = (dashRemain * dx) / L;
+       dashDy = (dashRemain * dy) / L;
+
+       rcenterx = lcenterx + dashDx;
+       rcentery = lcentery + dashDy;
+
+       vertices[V_RIGHT].x += dashDx;
+       vertices[V_RIGHT].y += dashDy;
+
+       vertices[V_BOTTOM].x += dashDx;
+       vertices[V_BOTTOM].y += dashDy;
+
+       slopes[V_RIGHT].k = vertices[V_RIGHT].x * dx + vertices[V_RIGHT].y * dy;
+
+       if (pGC->lineStyle == LineDoubleDash || !(dashIndex & 1))
+       {
+           if (pGC->lineStyle == LineOnOffDash &&
+               pGC->capStyle == CapProjecting)
+           {
+               saveRight = vertices[V_RIGHT];
+               saveBottom = vertices[V_BOTTOM];
+               saveK = slopes[V_RIGHT].k;
+               
+               if (!first)
+               {
+                   vertices[V_TOP].x -= rdx;
+                   vertices[V_TOP].y -= rdy;
+    
+                   vertices[V_LEFT].x -= rdx;
+                   vertices[V_LEFT].y -= rdy;
+
+                   slopes[V_LEFT].k = vertices[V_LEFT].x *
+                                      slopes[V_LEFT].dy -
+                                      vertices[V_LEFT].y *
+                                      slopes[V_LEFT].dx;
+               }
+               
+               vertices[V_RIGHT].x += rdx;
+               vertices[V_RIGHT].y += rdy;
+
+               vertices[V_BOTTOM].x += rdx;
+               vertices[V_BOTTOM].y += rdy;
+
+               slopes[V_RIGHT].k = vertices[V_RIGHT].x *
+                                  slopes[V_RIGHT].dy -
+                                  vertices[V_RIGHT].y *
+                                  slopes[V_RIGHT].dx;
+           }
+           y = miPolyBuildPoly (vertices, slopes, 4, x1, y1,
+                                left, right, &nleft, &nright, &h);
+           pixel = (dashIndex & 1) ? bgPixel : fgPixel;
+           miFillPolyHelper (pDrawable, pGC, pixel, spanData, y, h, left, right, nleft, nright);
+
+           if (pGC->lineStyle == LineOnOffDash)
+           {
+               switch (pGC->capStyle)
+               {
+               case CapProjecting:
+                   vertices[V_BOTTOM] = saveBottom;
+                   vertices[V_RIGHT] = saveRight;
+                   slopes[V_RIGHT].k = saveK;
+                   break;
+               case CapRound:
+                   if (!first)
+                   {
+                       if (dx < 0)
+                       {
+                           lcapFace.xa = -vertices[V_LEFT].x;
+                           lcapFace.ya = -vertices[V_LEFT].y;
+                           lcapFace.k = slopes[V_LEFT].k;
+                       }
+                       else
+                       {
+                           lcapFace.xa = vertices[V_TOP].x;
+                           lcapFace.ya = vertices[V_TOP].y;
+                           lcapFace.k = -slopes[V_LEFT].k;
+                       }
+                       miLineArc (pDrawable, pGC, pixel, spanData,
+                                  &lcapFace, (LineFacePtr) NULL,
+                                  lcenterx, lcentery, FALSE);
+                   }
+                   if (dx < 0)
+                   {
+                       rcapFace.xa = vertices[V_BOTTOM].x;
+                       rcapFace.ya = vertices[V_BOTTOM].y;
+                       rcapFace.k = slopes[V_RIGHT].k;
+                   }
+                   else
+                   {
+                       rcapFace.xa = -vertices[V_RIGHT].x;
+                       rcapFace.ya = -vertices[V_RIGHT].y;
+                       rcapFace.k = -slopes[V_RIGHT].k;
+                   }
+                   miLineArc (pDrawable, pGC, pixel, spanData,
+                              (LineFacePtr) NULL, &rcapFace,
+                              rcenterx, rcentery, FALSE);
+                   break;
+               }
+           }
+       }
+       LRemain -= dashRemain;
+       ++dashIndex;
+       if (dashIndex == pGC->numInDashList)
+           dashIndex = 0;
+       dashRemain = pDash[dashIndex];
+
+       lcenterx = rcenterx;
+       lcentery = rcentery;
+
+       vertices[V_TOP] = vertices[V_RIGHT];
+       vertices[V_LEFT] = vertices[V_BOTTOM];
+       slopes[V_LEFT].k = -slopes[V_RIGHT].k;
+       first = FALSE;
+    }
+
+    if (pGC->lineStyle == LineDoubleDash || !(dashIndex & 1))
+    {
+       vertices[V_TOP].x -= dx;
+       vertices[V_TOP].y -= dy;
+
+       vertices[V_LEFT].x -= dx;
+       vertices[V_LEFT].y -= dy;
+
+       vertices[V_RIGHT].x = rdy;
+       vertices[V_RIGHT].y = -rdx;
+
+       vertices[V_BOTTOM].x = -rdy;
+       vertices[V_BOTTOM].y = rdx;
+
+       
+       if (projectRight)
+       {
+           vertices[V_RIGHT].x += rdx;
+           vertices[V_RIGHT].y += rdy;
+    
+           vertices[V_BOTTOM].x += rdx;
+           vertices[V_BOTTOM].y += rdy;
+           slopes[V_RIGHT].k = vertices[V_RIGHT].x *
+                               slopes[V_RIGHT].dy -
+                               vertices[V_RIGHT].y *
+                               slopes[V_RIGHT].dx;
+       }
+       else
+           slopes[V_RIGHT].k = 0;
+
+       if (!first && pGC->lineStyle == LineOnOffDash &&
+           pGC->capStyle == CapProjecting)
+       {
+           vertices[V_TOP].x -= rdx;
+           vertices[V_TOP].y -= rdy;
+
+           vertices[V_LEFT].x -= rdx;
+           vertices[V_LEFT].y -= rdy;
+           slopes[V_LEFT].k = vertices[V_LEFT].x *
+                              slopes[V_LEFT].dy -
+                              vertices[V_LEFT].y *
+                              slopes[V_LEFT].dx;
+       }
+       else
+           slopes[V_LEFT].k += dx * dx + dy * dy;
+
+
+       y = miPolyBuildPoly (vertices, slopes, 4, x2, y2,
+                            left, right, &nleft, &nright, &h);
+
+       pixel = (dashIndex & 1) ? pGC->bgPixel : pGC->fgPixel;
+       miFillPolyHelper (pDrawable, pGC, pixel, spanData, y, h, left, right, nleft, nright);
+       if (!first && pGC->lineStyle == LineOnOffDash &&
+           pGC->capStyle == CapRound)
+       {
+           lcapFace.x = x2;
+           lcapFace.y = y2;
+           if (dx < 0)
+           {
+               lcapFace.xa = -vertices[V_LEFT].x;
+               lcapFace.ya = -vertices[V_LEFT].y;
+               lcapFace.k = slopes[V_LEFT].k;
+           }
+           else
+           {
+               lcapFace.xa = vertices[V_TOP].x;
+               lcapFace.ya = vertices[V_TOP].y;
+               lcapFace.k = -slopes[V_LEFT].k;
+           }
+           miLineArc (pDrawable, pGC, pixel, spanData,
+                      &lcapFace, (LineFacePtr) NULL,
+                      rcenterx, rcentery, FALSE);
+       }
+    }
+    dashRemain = ((double) dashRemain) - LRemain;
+    if (dashRemain == 0)
+    {
+       dashIndex++;
+       if (dashIndex == pGC->numInDashList)
+           dashIndex = 0;
+       dashRemain = pDash[dashIndex];
+    }
+
+    leftFace->x = x1;
+    leftFace->y = y1;
+    leftFace->dx = dx;
+    leftFace->dy = dy;
+    leftFace->xa = rdy;
+    leftFace->ya = -rdx;
+    leftFace->k = k;
+
+    rightFace->x = x2;
+    rightFace->y = y2;
+    rightFace->dx = -dx;
+    rightFace->dy = -dy;
+    rightFace->xa = -rdy;
+    rightFace->ya = rdx;
+    rightFace->k = k;
+
+    *pDashIndex = dashIndex;
+    *pDashOffset = pDash[dashIndex] - dashRemain;
+}
+
+void
+miWideDash (pDrawable, pGC, mode, npt, pPts)
+    DrawablePtr        pDrawable;
+    register GCPtr pGC;
+    int                mode;
+    register int npt;
+    register DDXPointPtr pPts;
+{
+    int                    x1, y1, x2, y2;
+    unsigned long   pixel;
+    Bool           projectLeft, projectRight;
+    LineFaceRec            leftFace, rightFace, prevRightFace;
+    LineFaceRec            firstFace;
+    int                    first;
+    int                    dashIndex, dashOffset;
+    register int    prevDashIndex;
+    SpanDataRec            spanDataRec;
+    SpanDataPtr            spanData;
+    Bool           somethingDrawn = FALSE;
+    Bool           selfJoin;
+    Bool           endIsFg, startIsFg, firstIsFg = FALSE, prevIsFg;
+
+    /* XXX backward compatibility */
+    if (pGC->lineWidth == 0)
+    {
+       miZeroDashLine (pDrawable, pGC, mode, npt, pPts);
+       return;
+    }
+    if (pGC->lineStyle == LineDoubleDash && 
+       (pGC->fillStyle == FillOpaqueStippled || pGC->fillStyle == FillTiled))
+    {
+       miWideLine (pDrawable, pGC, mode, npt, pPts);
+       return;
+    }
+    if (npt == 0)
+       return;
+    spanData = miSetupSpanData (pGC, &spanDataRec, npt);
+    x2 = pPts->x;
+    y2 = pPts->y;
+    first = TRUE;
+    selfJoin = FALSE;
+    if (mode == CoordModePrevious)
+    {
+       int nptTmp;
+       DDXPointPtr pPtsTmp;
+
+       x1 = x2;
+       y1 = y2;
+       nptTmp = npt;
+       pPtsTmp = pPts + 1;
+       while (--nptTmp)
+       {
+           x1 += pPtsTmp->x;
+           y1 += pPtsTmp->y;
+           ++pPtsTmp;
+       }
+       if (x2 == x1 && y2 == y1)
+           selfJoin = TRUE;
+    }
+    else if (x2 == pPts[npt-1].x && y2 == pPts[npt-1].y)
+    {
+       selfJoin = TRUE;
+    }
+    projectLeft = pGC->capStyle == CapProjecting && !selfJoin;
+    projectRight = FALSE;
+    dashIndex = 0;
+    dashOffset = 0;
+    miStepDash ((int)pGC->dashOffset, &dashIndex,
+               pGC->dash, (int)pGC->numInDashList, &dashOffset);
+    while (--npt)
+    {
+       x1 = x2;
+       y1 = y2;
+       ++pPts;
+       x2 = pPts->x;
+       y2 = pPts->y;
+       if (mode == CoordModePrevious)
+       {
+           x2 += x1;
+           y2 += y1;
+       }
+       if (x1 != x2 || y1 != y2)
+       {
+           somethingDrawn = TRUE;
+           if (npt == 1 && pGC->capStyle == CapProjecting && 
+               (!selfJoin || !firstIsFg))
+               projectRight = TRUE;
+           prevDashIndex = dashIndex;
+           miWideDashSegment (pDrawable, pGC, spanData, &dashOffset, &dashIndex,
+                               x1, y1, x2, y2,
+                               projectLeft, projectRight, &leftFace, &rightFace);
+           startIsFg = !(prevDashIndex & 1);
+           endIsFg = (dashIndex & 1) ^ (dashOffset != 0);
+           if (pGC->lineStyle == LineDoubleDash || startIsFg)
+           {
+               pixel = startIsFg ? pGC->fgPixel : pGC->bgPixel;
+               if (first || (pGC->lineStyle == LineOnOffDash && !prevIsFg))
+               {
+                   if (first && selfJoin)
+                   {
+                       firstFace = leftFace;
+                       firstIsFg = startIsFg;
+                   }
+                   else if (pGC->capStyle == CapRound)
+                       miLineArc (pDrawable, pGC, pixel, spanData,
+                                  &leftFace, (LineFacePtr) NULL,
+                                  (double)0.0, (double)0.0, TRUE);
+               }
+               else
+               {
+                   miLineJoin (pDrawable, pGC, pixel, spanData, &leftFace,
+                               &prevRightFace);
+               }
+           }
+           prevRightFace = rightFace;
+           prevIsFg = endIsFg;
+           first = FALSE;
+           projectLeft = FALSE;
+       }
+       if (npt == 1 && somethingDrawn)
+       {
+           if (pGC->lineStyle == LineDoubleDash || endIsFg)
+           {
+               pixel = endIsFg ? pGC->fgPixel : pGC->bgPixel;
+               if (selfJoin && (pGC->lineStyle == LineDoubleDash || firstIsFg))
+               {
+                   miLineJoin (pDrawable, pGC, pixel, spanData, &firstFace,
+                               &rightFace);
+               }
+               else 
+               {
+                   if (pGC->capStyle == CapRound)
+                       miLineArc (pDrawable, pGC, pixel, spanData,
+                                   (LineFacePtr) NULL, &rightFace,
+                                   (double)0.0, (double)0.0, TRUE);
+               }
+           }
+           else
+           {
+               /* glue a cap to the start of the line if
+                * we're OnOffDash and ended on odd dash
+                */
+               if (selfJoin && firstIsFg)
+               {
+                   pixel = pGC->fgPixel;
+                   if (pGC->capStyle == CapProjecting)
+                       miLineProjectingCap (pDrawable, pGC, pixel, spanData,
+                                   &firstFace, TRUE,
+                                   (double)0.0, (double)0.0, TRUE);
+                   else if (pGC->capStyle == CapRound)
+                       miLineArc (pDrawable, pGC, pixel, spanData,
+                                   &firstFace, (LineFacePtr) NULL,
+                                   (double)0.0, (double)0.0, TRUE);
+               }
+           }
+       }
+    }
+    /* handle crock where all points are coincident */
+    if (!somethingDrawn && (pGC->lineStyle == LineDoubleDash || !(dashIndex & 1)))
+    {
+       /* not the same as endIsFg computation above */
+       pixel = (dashIndex & 1) ? pGC->bgPixel : pGC->fgPixel;
+       switch (pGC->capStyle) {
+       case CapRound:
+           miLineArc (pDrawable, pGC, pixel, spanData,
+                      (LineFacePtr) NULL, (LineFacePtr) NULL,
+                      (double)x2, (double)y2,
+                      FALSE);
+           break;
+       case CapProjecting:
+           x1 = pGC->lineWidth;
+           miFillRectPolyHelper (pDrawable, pGC, pixel, spanData,
+                                 x2 - (x1 >> 1), y2 - (x1 >> 1), x1, x1);
+           break;
+       }
+    }
+    if (spanData)
+       miCleanupSpanData (pDrawable, pGC, spanData);
+}
+
+/* these are stubs to allow old ddx ValidateGCs to work without change */
+
+void
+miMiter()
+{
+}
+
+void
+miNotMiter()
+{
+}
diff --git a/Xserver/programs/Xserver/mi/miwideline.h b/Xserver/programs/Xserver/mi/miwideline.h
new file mode 100644 (file)
index 0000000..ee3c0ef
--- /dev/null
@@ -0,0 +1,246 @@
+/* $XConsortium: miwideline.h,v 1.11 94/04/17 20:28:02 dpw Exp $ */
+/*
+
+Copyright (c) 1988  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be included
+in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR
+OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall
+not be used in advertising or otherwise to promote the sale, use or
+other dealings in this Software without prior written authorization
+from the X Consortium.
+
+*/
+
+/* Author:  Keith Packard, MIT X Consortium */
+
+#include "mispans.h"
+
+/* 
+ * interface data to span-merging polygon filler
+ */
+
+typedef struct _SpanData {
+    SpanGroup  fgGroup, bgGroup;
+} SpanDataRec, *SpanDataPtr;
+
+#define AppendSpanGroup(pGC, pixel, spanPtr, spanData) { \
+       SpanGroup   *group, *othergroup = NULL; \
+       if (pixel == pGC->fgPixel) \
+       { \
+           group = &spanData->fgGroup; \
+           if (pGC->lineStyle == LineDoubleDash) \
+               othergroup = &spanData->bgGroup; \
+       } \
+       else \
+       { \
+           group = &spanData->bgGroup; \
+           othergroup = &spanData->fgGroup; \
+       } \
+       miAppendSpans (group, othergroup, spanPtr); \
+}
+
+/*
+ * Polygon edge description for integer wide-line routines
+ */
+
+typedef struct _PolyEdge {
+    int            height;     /* number of scanlines to process */
+    int            x;          /* starting x coordinate */
+    int            stepx;      /* fixed integral dx */
+    int            signdx;     /* variable dx sign */
+    int            e;          /* initial error term */
+    int            dy;
+    int            dx;
+} PolyEdgeRec, *PolyEdgePtr;
+
+#define SQSECANT 108.856472512142 /* 1/sin^2(11/2) - miter limit constant */
+
+/*
+ * types for general polygon routines
+ */
+
+typedef struct _PolyVertex {
+    double  x, y;
+} PolyVertexRec, *PolyVertexPtr;
+
+typedef struct _PolySlope {
+    int            dx, dy;
+    double  k;     /* x0 * dy - y0 * dx */
+} PolySlopeRec, *PolySlopePtr;
+
+/*
+ * Line face description for caps/joins
+ */
+
+typedef struct _LineFace {
+    double  xa, ya;
+    int            dx, dy;
+    int            x, y;
+    double  k;
+} LineFaceRec, *LineFacePtr;
+
+/*
+ * macros for polygon fillers
+ */
+
+#define MIPOLYRELOADLEFT    if (!left_height && left_count) { \
+                               left_height = left->height; \
+                               left_x = left->x; \
+                               left_stepx = left->stepx; \
+                               left_signdx = left->signdx; \
+                               left_e = left->e; \
+                               left_dy = left->dy; \
+                               left_dx = left->dx; \
+                               --left_count; \
+                               ++left; \
+                           }
+
+#define MIPOLYRELOADRIGHT   if (!right_height && right_count) { \
+                               right_height = right->height; \
+                               right_x = right->x; \
+                               right_stepx = right->stepx; \
+                               right_signdx = right->signdx; \
+                               right_e = right->e; \
+                               right_dy = right->dy; \
+                               right_dx = right->dx; \
+                               --right_count; \
+                               ++right; \
+                       }
+
+#define MIPOLYSTEPLEFT  left_x += left_stepx; \
+                       left_e += left_dx; \
+                       if (left_e > 0) \
+                       { \
+                           left_x += left_signdx; \
+                           left_e -= left_dy; \
+                       }
+
+#define MIPOLYSTEPRIGHT right_x += right_stepx; \
+                       right_e += right_dx; \
+                       if (right_e > 0) \
+                       { \
+                           right_x += right_signdx; \
+                           right_e -= right_dy; \
+                       }
+
+#define MILINESETPIXEL(pDrawable, pGC, pixel, oldPixel) { \
+    oldPixel = pGC->fgPixel; \
+    if (pixel != oldPixel) { \
+       DoChangeGC (pGC, GCForeground, (XID *) &pixel, FALSE); \
+       ValidateGC (pDrawable, pGC); \
+    } \
+}
+#define MILINERESETPIXEL(pDrawable, pGC, pixel, oldPixel) { \
+    if (pixel != oldPixel) { \
+       DoChangeGC (pGC, GCForeground, (XID *) &oldPixel, FALSE); \
+       ValidateGC (pDrawable, pGC); \
+    } \
+}
+
+#ifdef NOINLINEICEIL
+#define ICEIL(x) ((int)ceil(x))
+#else
+#ifdef __GNUC__
+static __inline int ICEIL(x)
+    double x;
+{
+    int _cTmp = x;
+    return ((x == _cTmp) || (x < 0.0)) ? _cTmp : _cTmp+1;
+}
+#else
+#define ICEIL(x) ((((x) == (_cTmp = (x))) || ((x) < 0.0)) ? _cTmp : _cTmp+1)
+#define ICEILTEMPDECL static int _cTmp;
+#endif
+#endif
+
+extern void miFillPolyHelper(
+#if NeedFunctionPrototypes
+    DrawablePtr /*pDrawable*/,
+    GCPtr /*pGC*/,
+    unsigned long /*pixel*/,
+    SpanDataPtr /*spanData*/,
+    int /*y*/,
+    int /*overall_height*/,
+    PolyEdgePtr /*left*/,
+    PolyEdgePtr /*right*/,
+    int /*left_count*/,
+    int /*right_count*/
+#endif
+);
+extern int miRoundJoinFace(
+#if NeedFunctionPrototypes
+    LineFacePtr /*face*/,
+    PolyEdgePtr /*edge*/,
+    Bool * /*leftEdge*/
+#endif
+);
+
+extern void miRoundJoinClip(
+#if NeedFunctionPrototypes
+    LineFacePtr /*pLeft*/,
+    LineFacePtr /*pRight*/,
+    PolyEdgePtr /*edge1*/,
+    PolyEdgePtr /*edge2*/,
+    int * /*y1*/,
+    int * /*y2*/,
+    Bool * /*left1*/,
+    Bool * /*left2*/
+#endif
+);
+
+extern int miRoundCapClip(
+#if NeedFunctionPrototypes
+    LineFacePtr /*face*/,
+    Bool /*isInt*/,
+    PolyEdgePtr /*edge*/,
+    Bool * /*leftEdge*/
+#endif
+);
+
+extern void miLineProjectingCap(
+#if NeedFunctionPrototypes
+    DrawablePtr /*pDrawable*/,
+    GCPtr /*pGC*/,
+    unsigned long /*pixel*/,
+    SpanDataPtr /*spanData*/,
+    LineFacePtr /*face*/,
+    Bool /*isLeft*/,
+    double /*xorg*/,
+    double /*yorg*/,
+    Bool /*isInt*/
+#endif
+);
+
+extern SpanDataPtr miSetupSpanData(
+#if NeedFunctionPrototypes
+    GCPtr /*pGC*/,
+    SpanDataPtr /*spanData*/,
+    int /*npt*/
+#endif
+);
+
+extern void miCleanupSpanData(
+#if NeedFunctionPrototypes
+    DrawablePtr /*pDrawable*/,
+    GCPtr /*pGC*/,
+    SpanDataPtr /*spanData*/
+#endif
+);
diff --git a/Xserver/programs/Xserver/mi/miwindow.c b/Xserver/programs/Xserver/mi/miwindow.c
new file mode 100644 (file)
index 0000000..0735481
--- /dev/null
@@ -0,0 +1,1145 @@
+/***********************************************************
+
+Copyright (c) 1987  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+
+Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
+
+                        All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and its 
+documentation for any purpose and without fee is hereby granted, 
+provided that the above copyright notice appear in all copies and that
+both that copyright notice and this permission notice appear in 
+supporting documentation, and that the name of Digital not be
+used in advertising or publicity pertaining to distribution of the
+software without specific, written prior permission.  
+
+DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
+ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
+DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
+ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+SOFTWARE.
+
+******************************************************************/
+/* $XConsortium: miwindow.c,v 5.16 94/04/17 20:28:03 dpw Exp $ */
+#include "X.h"
+#include "miscstruct.h"
+#include "region.h"
+#include "mi.h"
+#include "windowstr.h"
+#include "scrnintstr.h"
+#include "pixmapstr.h"
+#include "mivalidate.h"
+
+void 
+miClearToBackground(pWin, x, y, w, h, generateExposures)
+    WindowPtr pWin;
+    int x,y;
+    int w,h;
+    Bool generateExposures;
+{
+    BoxRec box;
+    RegionRec  reg;
+    RegionPtr pBSReg = NullRegion;
+    ScreenPtr  pScreen;
+    BoxPtr  extents;
+    int            x1, y1, x2, y2;
+
+    /* compute everything using ints to avoid overflow */
+
+    x1 = pWin->drawable.x + x;
+    y1 = pWin->drawable.y + y;
+    if (w)
+        x2 = x1 + (int) w;
+    else
+        x2 = x1 + (int) pWin->drawable.width - (int) x;
+    if (h)
+        y2 = y1 + h;   
+    else
+        y2 = y1 + (int) pWin->drawable.height - (int) y;
+
+    extents = &pWin->clipList.extents;
+    
+    /* clip the resulting rectangle to the window clipList extents.  This
+     * makes sure that the result will fit in a box, given that the
+     * screen is < 32768 on a side.
+     */
+
+    if (x1 < extents->x1)
+       x1 = extents->x1;
+    if (x2 > extents->x2)
+       x2 = extents->x2;
+    if (y1 < extents->y1)
+       y1 = extents->y1;
+    if (y2 > extents->y2)
+       y2 = extents->y2;
+
+    if (x2 <= x1 || y2 <= y1)
+    {
+       x2 = x1 = 0;
+       y2 = y1 = 0;
+    }
+
+    box.x1 = x1;
+    box.x2 = x2;
+    box.y1 = y1;
+    box.y2 = y2;
+
+    pScreen = pWin->drawable.pScreen;
+    REGION_INIT(pScreen, &reg, &box, 1);
+    if (pWin->backStorage)
+    {
+       /*
+        * If the window has backing-store on, call through the
+        * ClearToBackground vector to handle the special semantics
+        * (i.e. things backing store is to be cleared out and
+        * an Expose event is to be generated for those areas in backing
+        * store if generateExposures is TRUE).
+        */
+       pBSReg = (* pScreen->ClearBackingStore)(pWin, x, y, w, h,
+                                                generateExposures);
+    }
+
+    REGION_INTERSECT(pScreen, &reg, &reg, &pWin->clipList);
+    if (generateExposures)
+       (*pScreen->WindowExposures)(pWin, &reg, pBSReg);
+    else if (pWin->backgroundState != None)
+        (*pScreen->PaintWindowBackground)(pWin, &reg, PW_BACKGROUND);
+    REGION_UNINIT(pScreen, &reg);
+    if (pBSReg)
+       REGION_DESTROY(pScreen, pBSReg);
+}
+
+/*
+ * For SaveUnders using backing-store. The idea is that when a window is mapped
+ * with saveUnder set TRUE, any windows it obscures will have its backing
+ * store turned on setting the DIXsaveUnder bit,
+ * The backing-store code must be written to allow for this
+ */
+
+/*-
+ *-----------------------------------------------------------------------
+ * miCheckSubSaveUnder --
+ *     Check all the inferiors of a window for coverage by saveUnder
+ *     windows. Called from ChangeSaveUnder and CheckSaveUnder.
+ *     This code is very inefficient.
+ *
+ * Results:
+ *     TRUE if any windows need to have backing-store removed.
+ *
+ * Side Effects:
+ *     Windows may have backing-store turned on or off.
+ *
+ *-----------------------------------------------------------------------
+ */
+static Bool
+miCheckSubSaveUnder(pParent, pFirst, pRegion)
+    register WindowPtr pParent;        /* Parent to check */
+    WindowPtr          pFirst;         /* first reconfigured window */
+    RegionPtr          pRegion;        /* Initial area obscured by saveUnder */
+{
+    register WindowPtr pChild;         /* Current child */
+    register ScreenPtr pScreen;        /* Screen to use */
+    RegionRec          SubRegion;      /* Area of children obscured */
+    Bool               res = FALSE;    /* result */
+    Bool               subInited=FALSE;/* SubRegion initialized */
+
+    pScreen = pParent->drawable.pScreen;
+    if ( (pChild = pParent->firstChild) )
+    {
+       /*
+        * build region above first changed window
+        */
+
+       for (; pChild != pFirst; pChild = pChild->nextSib)
+           if (pChild->viewable && pChild->saveUnder)
+               REGION_UNION(pScreen, pRegion, pRegion, &pChild->borderSize);
+       
+       /*
+        * check region below and including first changed window
+        */
+
+       for (; pChild; pChild = pChild->nextSib)
+       {
+           if (pChild->viewable)
+           {
+               /*
+                * don't save under nephew/niece windows;
+                * use a separate region
+                */
+
+               if (pChild->firstChild)
+               {
+                   if (!subInited)
+                   {
+                       REGION_INIT(pScreen, &SubRegion, NullBox, 0);
+                       subInited = TRUE;
+                   }
+                   REGION_COPY(pScreen, &SubRegion, pRegion);
+                   res |= miCheckSubSaveUnder(pChild, pChild->firstChild,
+                                            &SubRegion);
+               }
+               else
+               {
+                   res |= miCheckSubSaveUnder(pChild, pChild->firstChild,
+                                            pRegion);
+               }
+
+               if (pChild->saveUnder)
+                   REGION_UNION(pScreen, pRegion, pRegion, &pChild->borderSize);
+           }
+       }
+
+       if (subInited)
+           REGION_UNINIT(pScreen, &SubRegion);
+    }
+
+    /*
+     * Check the state of this window. DIX save unders are
+     * enabled for viewable windows with some client expressing
+     * exposure interest and which intersect the save under region
+     */
+
+    if (pParent->viewable && 
+       ((pParent->eventMask | wOtherEventMasks(pParent)) & ExposureMask) &&
+       REGION_NOTEMPTY(pScreen, &pParent->borderSize) &&
+       RECT_IN_REGION(pScreen, pRegion, REGION_EXTENTS(pScreen, 
+                                       &pParent->borderSize)) != rgnOUT)
+    {
+       if (!pParent->DIXsaveUnder)
+       {
+           pParent->DIXsaveUnder = TRUE;
+           (*pScreen->ChangeWindowAttributes) (pParent, CWBackingStore);
+       }
+    }
+    else
+    {
+       if (pParent->DIXsaveUnder)
+       {
+           res = TRUE;
+           pParent->DIXsaveUnder = FALSE;
+       }
+    }
+    return res;
+}
+
+
+/*-
+ *-----------------------------------------------------------------------
+ * miChangeSaveUnder --
+ *     Change the save-under state of a tree of windows. Called when
+ *     a window with saveUnder TRUE is mapped/unmapped/reconfigured.
+ *     
+ * Results:
+ *     TRUE if any windows need to have backing-store removed (which
+ *     means that PostChangeSaveUnder needs to be called later to 
+ *     finish the job).
+ *
+ * Side Effects:
+ *     Windows may have backing-store turned on or off.
+ *
+ *-----------------------------------------------------------------------
+ */
+Bool
+miChangeSaveUnder(pWin, first)
+    register WindowPtr pWin;
+    WindowPtr          first;          /* First window to check.
+                                        * Used when pWin was restacked */
+{
+    RegionRec  rgn;    /* Area obscured by saveUnder windows */
+    register ScreenPtr pScreen;
+    Bool       res;
+
+    if (!deltaSaveUndersViewable && !numSaveUndersViewable)
+       return FALSE;
+    numSaveUndersViewable += deltaSaveUndersViewable;
+    deltaSaveUndersViewable = 0;
+    pScreen = pWin->drawable.pScreen;
+    REGION_INIT(pScreen, &rgn, NullBox, 1);
+    res = miCheckSubSaveUnder (pWin->parent,
+                              pWin->saveUnder ? first : pWin->nextSib,
+                              &rgn);
+    REGION_UNINIT(pScreen, &rgn);
+    return res;
+}
+
+/*-
+ *-----------------------------------------------------------------------
+ * miPostChangeSaveUnder --
+ *     Actually turn backing-store off for those windows that no longer
+ *     need to have it on.
+ *
+ * Results:
+ *     None.
+ *
+ * Side Effects:
+ *     Backing-store and SAVE_UNDER_CHANGE_BIT are turned off for those
+ *     windows affected.
+ *
+ *-----------------------------------------------------------------------
+ */
+void
+miPostChangeSaveUnder(pWin, pFirst)
+    WindowPtr          pWin;
+    WindowPtr          pFirst;
+{
+    register WindowPtr pParent, pChild;
+    ChangeWindowAttributesProcPtr ChangeWindowAttributes;
+
+    if (!(pParent = pWin->parent))
+       return;
+    ChangeWindowAttributes = pParent->drawable.pScreen->ChangeWindowAttributes;
+    if (!pParent->DIXsaveUnder &&
+       (pParent->backingStore == NotUseful) && pParent->backStorage)
+       (*ChangeWindowAttributes)(pParent, CWBackingStore);
+    if (!(pChild = pFirst))
+       return;
+    while (1)
+    {
+       if (!pChild->DIXsaveUnder &&
+           (pChild->backingStore == NotUseful) && pChild->backStorage)
+           (*ChangeWindowAttributes)(pChild, CWBackingStore);
+       if (pChild->firstChild)
+       {
+           pChild = pChild->firstChild;
+           continue;
+       }
+       while (!pChild->nextSib)
+       {
+           pChild = pChild->parent;
+           if (pChild == pParent)
+               return;
+       }
+       pChild = pChild->nextSib;
+    }
+}
+
+void
+miMarkWindow(pWin)
+    register WindowPtr pWin;
+{
+    register ValidatePtr val;
+
+    if (pWin->valdata)
+       return;
+    val = (ValidatePtr)xnfalloc(sizeof(ValidateRec));
+    val->before.oldAbsCorner.x = pWin->drawable.x;
+    val->before.oldAbsCorner.y = pWin->drawable.y;
+    val->before.borderVisible = NullRegion;
+    val->before.resized = FALSE;
+    pWin->valdata = val;
+}
+
+Bool
+miMarkOverlappedWindows(pWin, pFirst, ppLayerWin)
+    WindowPtr pWin;
+    WindowPtr pFirst;
+    WindowPtr *ppLayerWin;
+{
+    register BoxPtr box;
+    register WindowPtr pChild, pLast;
+    Bool anyMarked = FALSE;
+    void (* MarkWindow)() = pWin->drawable.pScreen->MarkWindow;
+    ScreenPtr pScreen = pWin->drawable.pScreen;
+
+    /* single layered systems are easy */
+    if (ppLayerWin) *ppLayerWin = pWin;
+
+    if (pWin == pFirst)
+    {
+       /* Blindly mark pWin and all of its inferiors.   This is a slight
+        * overkill if there are mapped windows that outside pWin's border,
+        * but it's better than wasting time on RectIn checks.
+        */
+       pChild = pWin;
+       while (1)
+       {
+           if (pChild->viewable)
+           {
+               (* MarkWindow)(pChild);
+               if (pChild->firstChild)
+               {
+                   pChild = pChild->firstChild;
+                   continue;
+               }
+           }
+           while (!pChild->nextSib && (pChild != pWin))
+               pChild = pChild->parent;
+           if (pChild == pWin)
+               break;
+           pChild = pChild->nextSib;
+       }
+       anyMarked = TRUE;
+       pFirst = pFirst->nextSib;
+    }
+    if ( (pChild = pFirst) )
+    {
+       box = REGION_EXTENTS(pChild->drawable.pScreen, &pWin->borderSize);
+       pLast = pChild->parent->lastChild;
+       while (1)
+       {
+           if (pChild->viewable && RECT_IN_REGION(pScreen, &pChild->borderSize,
+                                                      box))
+           {
+               (* MarkWindow)(pChild);
+               anyMarked = TRUE;
+               if (pChild->firstChild)
+               {
+                   pChild = pChild->firstChild;
+                   continue;
+               }
+           }
+           while (!pChild->nextSib && (pChild != pLast))
+               pChild = pChild->parent;
+           if (pChild == pLast)
+               break;
+           pChild = pChild->nextSib;
+       }
+    }
+    if (anyMarked)
+       (* MarkWindow)(pWin->parent);
+    return anyMarked;
+}
+
+/*****
+ *  miHandleValidateExposures(pWin)
+ *    starting at pWin, draw background in any windows that have exposure
+ *    regions, translate the regions, restore any backing store,
+ *    and then send any regions still exposed to the client
+ *****/
+void
+miHandleValidateExposures(pWin)
+    WindowPtr pWin;
+{
+    register WindowPtr pChild;
+    register ValidatePtr val;
+    ScreenPtr pScreen = pWin->drawable.pScreen;
+    void (* WindowExposures)();
+
+    pChild = pWin;
+    WindowExposures = pChild->drawable.pScreen->WindowExposures;
+    while (1)
+    {
+       if ( (val = pChild->valdata) )
+       {
+           if (REGION_NOTEMPTY(pScreen, &val->after.borderExposed))
+               (*pChild->drawable.pScreen->PaintWindowBorder)(pChild,
+                                                   &val->after.borderExposed,
+                                                   PW_BORDER);
+           REGION_UNINIT(pScreen, &val->after.borderExposed);
+           (*WindowExposures)(pChild, &val->after.exposed, NullRegion);
+           REGION_UNINIT(pScreen, &val->after.exposed);
+           xfree(val);
+           pChild->valdata = (ValidatePtr)NULL;
+           if (pChild->firstChild)
+           {
+               pChild = pChild->firstChild;
+               continue;
+           }
+       }
+       while (!pChild->nextSib && (pChild != pWin))
+           pChild = pChild->parent;
+       if (pChild == pWin)
+           break;
+       pChild = pChild->nextSib;
+    }
+}
+
+void
+miMoveWindow(pWin, x, y, pNextSib, kind)
+    register WindowPtr pWin;
+    int x,y;
+    WindowPtr pNextSib;
+    VTKind kind;
+{
+    WindowPtr pParent;
+    Bool WasViewable = (Bool)(pWin->viewable);
+    short bw;
+    RegionPtr oldRegion;
+    DDXPointRec oldpt;
+    Bool anyMarked;
+    register ScreenPtr pScreen;
+    WindowPtr windowToValidate;
+#ifdef DO_SAVE_UNDERS
+    Bool dosave = FALSE;
+#endif
+    WindowPtr pLayerWin;
+
+    /* if this is a root window, can't be moved */
+    if (!(pParent = pWin->parent))
+       return ;
+    pScreen = pWin->drawable.pScreen;
+    bw = wBorderWidth (pWin);
+
+    oldpt.x = pWin->drawable.x;
+    oldpt.y = pWin->drawable.y;
+    if (WasViewable)
+    {
+       oldRegion = REGION_CREATE(pScreen, NullBox, 1);
+       REGION_COPY(pScreen, oldRegion, &pWin->borderClip);
+       anyMarked = (*pScreen->MarkOverlappedWindows)(pWin, pWin, &pLayerWin);
+    }
+    pWin->origin.x = x + (int)bw;
+    pWin->origin.y = y + (int)bw;
+    x = pWin->drawable.x = pParent->drawable.x + x + (int)bw;
+    y = pWin->drawable.y = pParent->drawable.y + y + (int)bw;
+
+    SetWinSize (pWin);
+    SetBorderSize (pWin);
+
+    (*pScreen->PositionWindow)(pWin, x, y);
+
+    windowToValidate = MoveWindowInStack(pWin, pNextSib);
+
+    ResizeChildrenWinSize(pWin, x - oldpt.x, y - oldpt.y, 0, 0);
+
+    if (WasViewable)
+    {
+       if (pLayerWin == pWin)
+           anyMarked |= (*pScreen->MarkOverlappedWindows)
+                               (pWin, windowToValidate, (WindowPtr *)NULL);
+       else
+           anyMarked |= (*pScreen->MarkOverlappedWindows)
+                               (pWin, pLayerWin, (WindowPtr *)NULL);
+
+#ifdef DO_SAVE_UNDERS
+       if (DO_SAVE_UNDERS(pWin))
+       {
+           dosave = (*pScreen->ChangeSaveUnder)(pLayerWin, windowToValidate);
+       }
+#endif /* DO_SAVE_UNDERS */
+
+       if (anyMarked)
+       {
+           (*pScreen->ValidateTree)(pLayerWin->parent, NullWindow, kind);
+           (* pWin->drawable.pScreen->CopyWindow)(pWin, oldpt, oldRegion);
+           REGION_DESTROY(pScreen, oldRegion);
+           /* XXX need to retile border if ParentRelative origin */
+           (*pScreen->HandleExposures)(pLayerWin->parent);
+       }
+#ifdef DO_SAVE_UNDERS
+       if (dosave)
+           (*pScreen->PostChangeSaveUnder)(pLayerWin, windowToValidate);
+#endif /* DO_SAVE_UNDERS */
+       if (anyMarked && pScreen->PostValidateTree)
+           (*pScreen->PostValidateTree)(pLayerWin->parent, NullWindow, kind);
+    }
+    if (pWin->realized)
+       WindowsRestructured ();
+}
+
+
+/*
+ * pValid is a region of the screen which has been
+ * successfully copied -- recomputed exposed regions for affected windows
+ */
+
+static int
+miRecomputeExposures (pWin, value)
+    register WindowPtr pWin;
+    pointer            value; /* must conform to VisitWindowProcPtr */
+{
+    register ScreenPtr pScreen;
+    RegionPtr  pValid = (RegionPtr)value;
+
+    if (pWin->valdata)
+    {
+       pScreen = pWin->drawable.pScreen;
+       /*
+        * compute exposed regions of this window
+        */
+       REGION_SUBTRACT(pScreen, &pWin->valdata->after.exposed,
+                       &pWin->clipList, pValid);
+       /*
+        * compute exposed regions of the border
+        */
+       REGION_SUBTRACT(pScreen, &pWin->valdata->after.borderExposed,
+                            &pWin->borderClip, &pWin->winSize);
+       REGION_SUBTRACT(pScreen, &pWin->valdata->after.borderExposed,
+                            &pWin->valdata->after.borderExposed, pValid);
+       return WT_WALKCHILDREN;
+    }
+    return WT_NOMATCH;
+}
+
+void
+miSlideAndSizeWindow(pWin, x, y, w, h, pSib)
+    register WindowPtr pWin;
+    int x,y;
+    unsigned int w, h;
+    WindowPtr pSib;
+{
+    WindowPtr pParent;
+    Bool WasViewable = (Bool)(pWin->viewable);
+    unsigned short width = pWin->drawable.width,
+                  height = pWin->drawable.height;
+    short oldx = pWin->drawable.x,
+         oldy = pWin->drawable.y;
+    int bw = wBorderWidth (pWin);
+    short dw, dh;
+    DDXPointRec oldpt;
+    RegionPtr oldRegion;
+    Bool anyMarked;
+    register ScreenPtr pScreen;
+    WindowPtr pFirstChange;
+    register WindowPtr pChild;
+    RegionPtr  gravitate[StaticGravity + 1];
+    register unsigned g;
+    int                nx, ny;         /* destination x,y */
+    int                newx, newy;     /* new inner window position */
+    RegionPtr  pRegion;
+    RegionPtr  destClip;       /* portions of destination already written */
+    RegionPtr  oldWinClip;     /* old clip list for window */
+    RegionPtr  borderVisible = NullRegion; /* visible area of the border */
+    RegionPtr  bsExposed = NullRegion;     /* backing store exposures */
+    Bool       shrunk = FALSE; /* shrunk in an inner dimension */
+    Bool       moved = FALSE;  /* window position changed */
+#ifdef DO_SAVE_UNDERS
+    Bool       dosave = FALSE;
+#endif
+    WindowPtr  pLayerWin;
+
+    /* if this is a root window, can't be resized */
+    if (!(pParent = pWin->parent))
+       return ;
+
+    pScreen = pWin->drawable.pScreen;
+    newx = pParent->drawable.x + x + bw;
+    newy = pParent->drawable.y + y + bw;
+    if (WasViewable)
+    {
+       anyMarked = FALSE;
+       /*
+        * save the visible region of the window
+        */
+       oldRegion = REGION_CREATE(pScreen, NullBox, 1);
+       REGION_COPY(pScreen, oldRegion, &pWin->winSize);
+
+       /*
+        * categorize child windows into regions to be moved
+        */
+       for (g = 0; g <= StaticGravity; g++)
+           gravitate[g] = (RegionPtr) NULL;
+       for (pChild = pWin->firstChild; pChild; pChild = pChild->nextSib)
+       {
+           g = pChild->winGravity;
+           if (g != UnmapGravity)
+           {
+               if (!gravitate[g])
+                   gravitate[g] = REGION_CREATE(pScreen, NullBox, 1);
+               REGION_UNION(pScreen, gravitate[g],
+                                  gravitate[g], &pChild->borderClip);
+           }
+           else
+           {
+               UnmapWindow(pChild, TRUE);
+               anyMarked = TRUE;
+           }
+       }
+       anyMarked |= (*pScreen->MarkOverlappedWindows)(pWin, pWin, 
+                                                      &pLayerWin);
+
+       oldWinClip = NULL;
+       if (pWin->bitGravity != ForgetGravity)
+       {
+           oldWinClip = REGION_CREATE(pScreen, NullBox, 1);
+           REGION_COPY(pScreen, oldWinClip, &pWin->clipList);
+       }
+       /*
+        * if the window is changing size, borderExposed
+        * can't be computed correctly without some help.
+        */
+       if (pWin->drawable.height > h || pWin->drawable.width > w)
+           shrunk = TRUE;
+
+       if (newx != oldx || newy != oldy)
+           moved = TRUE;
+
+       if ((pWin->drawable.height != h || pWin->drawable.width != w) &&
+           HasBorder (pWin))
+       {
+           borderVisible = REGION_CREATE(pScreen, NullBox, 1);
+           /* for tiled borders, we punt and draw the whole thing */
+           if (pWin->borderIsPixel || !moved)
+           {
+               if (shrunk || moved)
+                   REGION_SUBTRACT(pScreen, borderVisible,
+                                         &pWin->borderClip,
+                                         &pWin->winSize);
+               else
+                   REGION_COPY(pScreen, borderVisible,
+                                           &pWin->borderClip);
+           }
+       }
+    }
+    pWin->origin.x = x + bw;
+    pWin->origin.y = y + bw;
+    pWin->drawable.height = h;
+    pWin->drawable.width = w;
+
+    x = pWin->drawable.x = newx;
+    y = pWin->drawable.y = newy;
+
+    SetWinSize (pWin);
+    SetBorderSize (pWin);
+
+    dw = (int)w - (int)width;
+    dh = (int)h - (int)height;
+    ResizeChildrenWinSize(pWin, x - oldx, y - oldy, dw, dh);
+
+    /* let the hardware adjust background and border pixmaps, if any */
+    (*pScreen->PositionWindow)(pWin, x, y);
+
+    pFirstChange = MoveWindowInStack(pWin, pSib);
+
+    if (WasViewable)
+    {
+       pRegion = REGION_CREATE(pScreen, NullBox, 1);
+       if (pWin->backStorage)
+           REGION_COPY(pScreen, pRegion, &pWin->clipList);
+
+       if (pLayerWin == pWin)
+           anyMarked |= (*pScreen->MarkOverlappedWindows)(pWin, pFirstChange,
+                                               (WindowPtr *)NULL);
+       else
+           anyMarked |= (*pScreen->MarkOverlappedWindows)(pWin, pLayerWin,
+                                               (WindowPtr *)NULL);
+
+       if (pWin->valdata)
+       {
+           pWin->valdata->before.resized = TRUE;
+           pWin->valdata->before.borderVisible = borderVisible;
+       }
+
+#ifdef DO_SAVE_UNDERS
+       if (DO_SAVE_UNDERS(pWin))
+       {
+           dosave = (*pScreen->ChangeSaveUnder)(pLayerWin, pFirstChange);
+       }
+#endif /* DO_SAVE_UNDERS */
+
+       if (anyMarked)
+           (*pScreen->ValidateTree)(pLayerWin->parent, pFirstChange, VTOther);
+       /*
+        * the entire window is trashed unless bitGravity
+        * recovers portions of it
+        */
+       REGION_COPY(pScreen, &pWin->valdata->after.exposed, &pWin->clipList);
+    }
+
+    GravityTranslate (x, y, oldx, oldy, dw, dh, pWin->bitGravity, &nx, &ny);
+
+    if (pWin->backStorage &&
+       ((pWin->backingStore == Always) || WasViewable))
+    {
+       if (!WasViewable)
+           pRegion = &pWin->clipList; /* a convenient empty region */
+       if (pWin->bitGravity == ForgetGravity)
+           bsExposed = (*pScreen->TranslateBackingStore)
+                               (pWin, 0, 0, NullRegion, oldx, oldy);
+       else
+       {
+           bsExposed = (*pScreen->TranslateBackingStore)
+                            (pWin, nx - x, ny - y, pRegion, oldx, oldy);
+       }
+    }
+
+    if (WasViewable)
+    {
+       /* avoid the border */
+       if (HasBorder (pWin))
+       {
+           int offx, offy, dx, dy;
+
+           /* kruft to avoid double translates for each gravity */
+           offx = 0;
+           offy = 0;
+           for (g = 0; g <= StaticGravity; g++)
+           {
+               if (!gravitate[g])
+                   continue;
+
+               /* align winSize to gravitate[g].
+                * winSize is in new coordinates,
+                * gravitate[g] is still in old coordinates */
+               GravityTranslate (x, y, oldx, oldy, dw, dh, g, &nx, &ny);
+               
+               dx = (oldx - nx) - offx;
+               dy = (oldy - ny) - offy;
+               if (dx || dy)
+               {
+                   REGION_TRANSLATE(pScreen, &pWin->winSize, dx, dy);
+                   offx += dx;
+                   offy += dy;
+               }
+               REGION_INTERSECT(pScreen, gravitate[g], gravitate[g],
+                                &pWin->winSize);
+           }
+           /* get winSize back where it belongs */
+           if (offx || offy)
+               REGION_TRANSLATE(pScreen, &pWin->winSize, -offx, -offy);
+       }
+       /*
+        * add screen bits to the appropriate bucket
+        */
+
+       if (oldWinClip)
+       {
+           /*
+            * clip to new clipList
+            */
+           REGION_COPY(pScreen, pRegion, oldWinClip);
+           REGION_TRANSLATE(pScreen, pRegion, nx - oldx, ny - oldy);
+           REGION_INTERSECT(pScreen, oldWinClip, pRegion, &pWin->clipList);
+           /*
+            * don't step on any gravity bits which will be copied after this
+            * region.  Note -- this assumes that the regions will be copied
+            * in gravity order.
+            */
+           for (g = pWin->bitGravity + 1; g <= StaticGravity; g++)
+           {
+               if (gravitate[g])
+                   REGION_SUBTRACT(pScreen, oldWinClip, oldWinClip,
+                                       gravitate[g]);
+           }
+           REGION_TRANSLATE(pScreen, oldWinClip, oldx - nx, oldy - ny);
+           g = pWin->bitGravity;
+           if (!gravitate[g])
+               gravitate[g] = oldWinClip;
+           else
+           {
+               REGION_UNION(pScreen, gravitate[g], gravitate[g], oldWinClip);
+               REGION_DESTROY(pScreen, oldWinClip);
+           }
+       }
+
+       /*
+        * move the bits on the screen
+        */
+
+       destClip = NULL;
+
+       for (g = 0; g <= StaticGravity; g++)
+       {
+           if (!gravitate[g])
+               continue;
+
+           GravityTranslate (x, y, oldx, oldy, dw, dh, g, &nx, &ny);
+
+           oldpt.x = oldx + (x - nx);
+           oldpt.y = oldy + (y - ny);
+
+           /* Note that gravitate[g] is *translated* by CopyWindow */
+
+           /* only copy the remaining useful bits */
+
+           REGION_INTERSECT(pScreen, gravitate[g], gravitate[g], oldRegion);
+
+           /* clip to not overwrite already copied areas */
+
+           if (destClip) {
+               REGION_TRANSLATE(pScreen, destClip, oldpt.x - x, oldpt.y - y);
+               REGION_SUBTRACT(pScreen, gravitate[g], gravitate[g], destClip);
+               REGION_TRANSLATE(pScreen, destClip, x - oldpt.x, y - oldpt.y);
+           }
+
+           /* and move those bits */
+
+           if (oldpt.x != x || oldpt.y != y)
+               (*pWin->drawable.pScreen->CopyWindow)(pWin, oldpt, gravitate[g]);
+
+           /* remove any overwritten bits from the remaining useful bits */
+
+           REGION_SUBTRACT(pScreen, oldRegion, oldRegion, gravitate[g]);
+
+           /*
+            * recompute exposed regions of child windows
+            */
+       
+           for (pChild = pWin->firstChild; pChild; pChild = pChild->nextSib)
+           {
+               if (pChild->winGravity != g)
+                   continue;
+               REGION_INTERSECT(pScreen, pRegion,
+                                      &pChild->borderClip, gravitate[g]);
+               TraverseTree (pChild, miRecomputeExposures, (pointer)pRegion);
+           }
+
+           /*
+            * remove the successfully copied regions of the
+            * window from its exposed region
+            */
+
+           if (g == pWin->bitGravity)
+               REGION_SUBTRACT(pScreen, &pWin->valdata->after.exposed,
+                                    &pWin->valdata->after.exposed, gravitate[g]);
+           if (!destClip)
+               destClip = gravitate[g];
+           else
+           {
+               REGION_UNION(pScreen, destClip, destClip, gravitate[g]);
+               REGION_DESTROY(pScreen, gravitate[g]);
+           }
+       }
+
+       REGION_DESTROY(pScreen, oldRegion);
+       REGION_DESTROY(pScreen, pRegion);
+       if (destClip)
+           REGION_DESTROY(pScreen, destClip);
+       if (bsExposed)
+       {
+           RegionPtr   valExposed = NullRegion;
+
+           if (pWin->valdata)
+               valExposed = &pWin->valdata->after.exposed;
+           (*pScreen->WindowExposures) (pWin, valExposed, bsExposed);
+           if (valExposed)
+               REGION_EMPTY(pScreen, valExposed);
+           REGION_DESTROY(pScreen, bsExposed);
+       }
+       if (anyMarked)
+           (*pScreen->HandleExposures)(pLayerWin->parent);
+#ifdef DO_SAVE_UNDERS
+       if (dosave)
+       {
+           (*pScreen->PostChangeSaveUnder)(pLayerWin, pFirstChange);
+       }
+#endif /* DO_SAVE_UNDERS */
+       if (anyMarked && pScreen->PostValidateTree)
+           (*pScreen->PostValidateTree)(pLayerWin->parent, pFirstChange,
+                                         VTOther);
+    }
+    else if (bsExposed)
+    {
+       (*pScreen->WindowExposures) (pWin, NullRegion, bsExposed);
+       REGION_DESTROY(pScreen, bsExposed);
+    }
+    if (pWin->realized)
+       WindowsRestructured ();
+}
+
+WindowPtr
+miGetLayerWindow(pWin)
+    WindowPtr pWin;
+{
+    return pWin->firstChild;
+}
+
+#ifdef SHAPE
+/******
+ *
+ * miSetShape
+ *    The border/window shape has changed.  Recompute winSize/borderSize
+ *    and send appropriate exposure events
+ */
+
+void
+miSetShape(pWin)
+    register WindowPtr pWin;
+{
+    Bool       WasViewable = (Bool)(pWin->viewable);
+    register ScreenPtr pScreen = pWin->drawable.pScreen;
+    Bool       anyMarked;
+    WindowPtr  pParent = pWin->parent;
+    RegionPtr  pOldClip, bsExposed;
+#ifdef DO_SAVE_UNDERS
+    Bool       dosave = FALSE;
+#endif
+    WindowPtr   pLayerWin;
+
+    if (WasViewable)
+    {
+       anyMarked = (*pScreen->MarkOverlappedWindows)(pWin, pWin,
+                                                     &pLayerWin);
+       if (pWin->valdata)
+       {
+           if (HasBorder (pWin))
+           {
+               RegionPtr       borderVisible;
+
+               borderVisible = REGION_CREATE(pScreen, NullBox, 1);
+               REGION_SUBTRACT(pScreen, borderVisible,
+                                     &pWin->borderClip, &pWin->winSize);
+               pWin->valdata->before.borderVisible = borderVisible;
+           }
+           pWin->valdata->before.resized = TRUE;
+       }
+    }
+
+    SetWinSize (pWin);
+    SetBorderSize (pWin);
+
+    ResizeChildrenWinSize(pWin, 0, 0, 0, 0);
+
+    if (WasViewable)
+    {
+       if (pWin->backStorage)
+       {
+           pOldClip = REGION_CREATE(pScreen, NullBox, 1);
+           REGION_COPY(pScreen, pOldClip, &pWin->clipList);
+       }
+
+       anyMarked |= (*pScreen->MarkOverlappedWindows)(pWin, pWin,
+                                               (WindowPtr *)NULL);
+
+#ifdef DO_SAVE_UNDERS
+       if (DO_SAVE_UNDERS(pWin))
+       {
+           dosave = (*pScreen->ChangeSaveUnder)(pLayerWin, pLayerWin);
+       }
+#endif /* DO_SAVE_UNDERS */
+
+       if (anyMarked)
+           (*pScreen->ValidateTree)(pLayerWin->parent, NullWindow, VTOther);
+    }
+
+    if (pWin->backStorage &&
+       ((pWin->backingStore == Always) || WasViewable))
+    {
+       if (!WasViewable)
+           pOldClip = &pWin->clipList; /* a convenient empty region */
+       bsExposed = (*pScreen->TranslateBackingStore)
+                            (pWin, 0, 0, pOldClip,
+                             pWin->drawable.x, pWin->drawable.y);
+       if (WasViewable)
+           REGION_DESTROY(pScreen, pOldClip);
+       if (bsExposed)
+       {
+           RegionPtr   valExposed = NullRegion;
+    
+           if (pWin->valdata)
+               valExposed = &pWin->valdata->after.exposed;
+           (*pScreen->WindowExposures) (pWin, valExposed, bsExposed);
+           if (valExposed)
+               REGION_EMPTY(pScreen, valExposed);
+           REGION_DESTROY(pScreen, bsExposed);
+       }
+    }
+    if (WasViewable)
+    {
+       if (anyMarked)
+           (*pScreen->HandleExposures)(pLayerWin->parent);
+#ifdef DO_SAVE_UNDERS
+       if (dosave)
+           (*pScreen->PostChangeSaveUnder)(pLayerWin, pLayerWin);
+#endif /* DO_SAVE_UNDERS */
+       if (anyMarked && pScreen->PostValidateTree)
+           (*pScreen->PostValidateTree)(pLayerWin->parent, NullWindow, VTOther);
+    }
+    if (pWin->realized)
+       WindowsRestructured ();
+    CheckCursorConfinement(pWin);
+}
+#endif
+
+/* Keeps the same inside(!) origin */
+
+void
+miChangeBorderWidth(pWin, width)
+    register WindowPtr pWin;
+    unsigned int width;
+{
+    WindowPtr pParent;
+    int oldwidth;
+    Bool anyMarked;
+    register ScreenPtr pScreen;
+    Bool WasViewable = (Bool)(pWin->viewable);
+    Bool HadBorder;
+#ifdef DO_SAVE_UNDERS
+    Bool       dosave = FALSE;
+#endif
+    WindowPtr  pLayerWin;
+
+    oldwidth = wBorderWidth (pWin);
+    if (oldwidth == width)
+       return;
+    HadBorder = HasBorder(pWin);
+    pScreen = pWin->drawable.pScreen;
+    pParent = pWin->parent;
+    if (WasViewable && width < oldwidth)
+       anyMarked = (*pScreen->MarkOverlappedWindows)(pWin, pWin, &pLayerWin);
+
+    pWin->borderWidth = width;
+    SetBorderSize (pWin);
+
+    if (WasViewable)
+    {
+       if (width > oldwidth)
+       {
+           anyMarked = (*pScreen->MarkOverlappedWindows)(pWin, pWin,
+                                                         &pLayerWin);
+           /*
+            * save the old border visible region to correctly compute
+            * borderExposed.
+            */
+           if (pWin->valdata && HadBorder)
+           {
+               RegionPtr   borderVisible;
+               borderVisible = REGION_CREATE(pScreen, NULL, 1);
+               REGION_SUBTRACT(pScreen, borderVisible,
+                                     &pWin->borderClip, &pWin->winSize);
+               pWin->valdata->before.borderVisible = borderVisible;
+           }
+       }
+#ifdef DO_SAVE_UNDERS
+       if (DO_SAVE_UNDERS(pWin))
+       {
+           dosave = (*pScreen->ChangeSaveUnder)(pLayerWin, pWin->nextSib);
+       }
+#endif /* DO_SAVE_UNDERS */
+
+       if (anyMarked)
+       {
+           (*pScreen->ValidateTree)(pLayerWin->parent, pLayerWin, VTOther);
+           (*pScreen->HandleExposures)(pLayerWin->parent);
+       }
+#ifdef DO_SAVE_UNDERS
+       if (dosave)
+           (*pScreen->PostChangeSaveUnder)(pLayerWin, pWin->nextSib);
+#endif /* DO_SAVE_UNDERS */
+       if (anyMarked && pScreen->PostValidateTree)
+           (*pScreen->PostValidateTree)(pLayerWin->parent, pLayerWin,
+                                         VTOther);
+    }
+    if (pWin->realized)
+       WindowsRestructured ();
+}
+
+void
+miMarkUnrealizedWindow(pChild, pWin, fromConfigure)
+    WindowPtr pChild;
+    WindowPtr pWin;
+    Bool fromConfigure;
+{
+    if ((pChild != pWin) || fromConfigure)
+    {
+       REGION_EMPTY(pChild->drawable.pScreen, &pChild->clipList);
+       if (pChild->drawable.pScreen->ClipNotify)
+           (* pChild->drawable.pScreen->ClipNotify)(pChild, 0, 0);
+       REGION_EMPTY(pChild->drawable.pScreen, &pChild->borderClip);
+    }
+}
diff --git a/Xserver/programs/Xserver/mi/mizerarc.c b/Xserver/programs/Xserver/mi/mizerarc.c
new file mode 100644 (file)
index 0000000..50eba96
--- /dev/null
@@ -0,0 +1,849 @@
+/************************************************************
+
+Copyright (c) 1989  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+Author:  Bob Scheifler, MIT X Consortium
+
+********************************************************/
+
+/* $XConsortium: mizerarc.c,v 5.36 94/04/17 20:28:04 dpw Exp $ */
+
+/* Derived from:
+ * "Algorithm for drawing ellipses or hyperbolae with a digital plotter"
+ * by M. L. V. Pitteway
+ * The Computer Journal, November 1967, Volume 10, Number 3, pp. 282-289
+ */
+
+#include <math.h>
+#include "X.h"
+#include "Xprotostr.h"
+#include "miscstruct.h"
+#include "gcstruct.h"
+#include "pixmapstr.h"
+#include "mi.h"
+#include "mizerarc.h"
+
+#define FULLCIRCLE (360 * 64)
+#define OCTANT (45 * 64)
+#define QUADRANT (90 * 64)
+#define HALFCIRCLE (180 * 64)
+#define QUADRANT3 (270 * 64)
+
+#ifndef M_PI
+#define M_PI   3.14159265358979323846
+#endif
+
+#define Dsin(d)        ((d) == 0 ? 0.0 : ((d) == QUADRANT ? 1.0 : \
+                ((d) == HALFCIRCLE ? 0.0 : \
+                ((d) == QUADRANT3 ? -1.0 : sin((double)d*(M_PI/11520.0))))))
+
+#define Dcos(d)        ((d) == 0 ? 1.0 : ((d) == QUADRANT ? 0.0 : \
+                ((d) == HALFCIRCLE ? -1.0 : \
+                ((d) == QUADRANT3 ? 0.0 : cos((double)d*(M_PI/11520.0))))))
+
+#define EPSILON45 64
+
+typedef struct {
+    int skipStart;
+    int haveStart;
+    DDXPointRec startPt;
+    int haveLast;
+    int skipLast;
+    DDXPointRec endPt;
+    int dashIndex;
+    int dashOffset;
+    int dashIndexInit;
+    int dashOffsetInit;
+} DashInfo;
+
+static miZeroArcPtRec oob = {65536, 65536, 0};
+
+/*
+ * (x - l)^2 / (W/2)^2  + (y + H/2)^2 / (H/2)^2 = 1
+ *
+ * where l is either 0 or .5
+ *
+ * alpha = 4(W^2)
+ * beta = 4(H^2)
+ * gamma = 0
+ * u = 2(W^2)H
+ * v = 4(H^2)l
+ * k = -4(H^2)(l^2)
+ *
+ */
+
+Bool
+miZeroArcSetup(arc, info, ok360)
+    register xArc *arc;
+    register miZeroArcRec *info;
+    Bool ok360;
+{
+    int l;
+    int angle1, angle2;
+    int startseg, endseg;
+    int startAngle, endAngle;
+    int i, overlap;
+    miZeroArcPtRec start, end;
+
+    l = arc->width & 1;
+    if (arc->width == arc->height)
+    {
+       info->alpha = 4;
+       info->beta = 4;
+       info->k1 = -8;
+       info->k3 = -16;
+       info->b = 12;
+       info->a = (arc->width << 2) - 12;
+       info->d = 17 - (arc->width << 1);
+       if (l)
+       {
+           info->b -= 4;
+           info->a += 4;
+           info->d -= 7;
+       }
+    }
+    else if (!arc->width || !arc->height)
+    {
+       info->alpha = 0;
+       info->beta = 0;
+       info->k1 = 0;
+       info->k3 = 0;
+       info->a = -(int)arc->height;
+       info->b = 0;
+       info->d = -1;
+    }
+    else
+    {
+       /* initial conditions */
+       info->alpha = (arc->width * arc->width) << 2;
+       info->beta = (arc->height * arc->height) << 2;
+       info->k1 = info->beta << 1;
+       info->k3 = info->k1 + (info->alpha << 1);
+       info->b = l ? 0 : -info->beta;
+       info->a = info->alpha * arc->height;
+       info->d = info->b - (info->a >> 1) - (info->alpha >> 2);
+       if (l)
+           info->d -= info->beta >> 2;
+       info->a -= info->b;
+       /* take first step, d < 0 always */
+       info->b -= info->k1;
+       info->a += info->k1;
+       info->d += info->b;
+       /* octant change, b < 0 always */
+       info->k1 = -info->k1;
+       info->k3 = -info->k3;
+       info->b = -info->b;
+       info->d = info->b - info->a - info->d;
+       info->a = info->a - (info->b << 1);
+    }
+    info->dx = 1;
+    info->dy = 0;
+    info->w = (arc->width + 1) >> 1;
+    info->h = arc->height >> 1;
+    info->xorg = arc->x + (arc->width >> 1);
+    info->yorg = arc->y;
+    info->xorgo = info->xorg + l;
+    info->yorgo = info->yorg + arc->height;
+    if (!arc->width)
+    {
+       if (!arc->height)
+       {
+           info->x = 0;
+           info->y = 0;
+           info->initialMask = 0;
+           info->startAngle = 0;
+           info->endAngle = 0;
+           info->start = oob;
+           info->end = oob;
+           return FALSE;
+       }
+       info->x = 0;
+       info->y = 1;
+    }
+    else
+    {
+       info->x = 1;
+       info->y = 0;
+    }
+    angle1 = arc->angle1;
+    angle2 = arc->angle2;
+    if ((angle1 == 0) && (angle2 >= FULLCIRCLE))
+    {
+       startAngle = 0;
+       endAngle = 0;
+    }
+    else
+    {
+       if (angle2 > FULLCIRCLE)
+           angle2 = FULLCIRCLE;
+       else if (angle2 < -FULLCIRCLE)
+           angle2 = -FULLCIRCLE;
+       if (angle2 < 0)
+       {
+           startAngle = angle1 + angle2;
+           endAngle = angle1;
+       }
+       else
+       {
+           startAngle = angle1;
+           endAngle = angle1 + angle2;
+       }
+       if (startAngle < 0)
+           startAngle = FULLCIRCLE - (-startAngle) % FULLCIRCLE;
+       if (startAngle >= FULLCIRCLE)
+           startAngle = startAngle % FULLCIRCLE;
+       if (endAngle < 0)
+           endAngle = FULLCIRCLE - (-endAngle) % FULLCIRCLE;
+       if (endAngle >= FULLCIRCLE)
+           endAngle = endAngle % FULLCIRCLE;
+    }
+    info->startAngle = startAngle;
+    info->endAngle = endAngle;
+    if (ok360 && (startAngle == endAngle) && arc->angle2 &&
+       arc->width && arc->height)
+    {
+       info->initialMask = 0xf;
+       info->start = oob;
+       info->end = oob;
+       return TRUE;
+    }
+    startseg = startAngle / OCTANT;
+    if (!arc->height || (((startseg + 1) & 2) && arc->width))
+    {
+       start.x = Dcos(startAngle) * ((arc->width + 1) / 2.0);
+       if (start.x < 0)
+           start.x = -start.x;
+       start.y = -1;
+    }
+    else
+    {
+       start.y = Dsin(startAngle) * (arc->height / 2.0);
+       if (start.y < 0)
+           start.y = -start.y;
+       start.y = info->h - start.y;
+       start.x = 65536;
+    }
+    endseg = endAngle / OCTANT;
+    if (!arc->height || (((endseg + 1) & 2) && arc->width))
+    {
+       end.x = Dcos(endAngle) * ((arc->width + 1) / 2.0);
+       if (end.x < 0)
+           end.x = -end.x;
+       end.y = -1;
+    }
+    else
+    {
+       end.y = Dsin(endAngle) * (arc->height / 2.0);
+       if (end.y < 0)
+           end.y = -end.y;
+       end.y = info->h - end.y;
+       end.x = 65536;
+    }
+    info->firstx = start.x;
+    info->firsty = start.y;
+    info->initialMask = 0;
+    overlap = arc->angle2 && (endAngle <= startAngle);
+    for (i = 0; i < 4; i++)
+    {
+       if (overlap ?
+           ((i * QUADRANT <= endAngle) || ((i + 1) * QUADRANT > startAngle)) :
+           ((i * QUADRANT <= endAngle) && ((i + 1) * QUADRANT > startAngle)))
+           info->initialMask |= (1 << i);
+    }
+    start.mask = info->initialMask;
+    end.mask = info->initialMask;
+    startseg >>= 1;
+    endseg >>= 1;
+    overlap = overlap && (endseg == startseg);
+    if (start.x != end.x || start.y != end.y || !overlap)
+    {
+       if (startseg & 1)
+       {
+           if (!overlap)
+               info->initialMask &= ~(1 << startseg);
+           if (start.x > end.x || start.y > end.y)
+               end.mask &= ~(1 << startseg);
+       }
+       else
+       {
+           start.mask &= ~(1 << startseg);
+           if (((start.x < end.x || start.y < end.y) ||
+                (start.x == end.x && start.y == end.y && (endseg & 1))) &&
+               !overlap)
+               end.mask &= ~(1 << startseg);
+       }
+       if (endseg & 1)
+       {
+           end.mask &= ~(1 << endseg);
+           if (((start.x > end.x || start.y > end.y) ||
+                (start.x == end.x && start.y == end.y && !(startseg & 1))) &&
+               !overlap)
+               start.mask &= ~(1 << endseg);
+       }
+       else
+       {
+           if (!overlap)
+               info->initialMask &= ~(1 << endseg);
+           if (start.x < end.x || start.y < end.y)
+               start.mask &= ~(1 << endseg);
+       }
+    }
+    /* take care of case when start and stop are both near 45 */
+    /* handle here rather than adding extra code to pixelization loops */
+    if (startAngle &&
+       ((start.y < 0 && end.y >= 0) || (start.y >= 0 && end.y < 0)))
+    {
+       i = (startAngle + OCTANT) % OCTANT;
+       if (i < EPSILON45 || i > OCTANT - EPSILON45)
+       {
+           i = (endAngle + OCTANT) % OCTANT;
+           if (i < EPSILON45 || i > OCTANT - EPSILON45)
+           {
+               if (start.y < 0)
+               {
+                   i = Dsin(startAngle) * (arc->height / 2.0);
+                   if (i < 0)
+                       i = -i;
+                   if (info->h - i == end.y)
+                       start.mask = end.mask;
+               }
+               else
+               {
+                   i = Dsin(endAngle) * (arc->height / 2.0);
+                   if (i < 0)
+                       i = -i;
+                   if (info->h - i == start.y)
+                       end.mask = start.mask;
+               }
+           }
+       }
+    }
+    if (startseg & 1)
+    {
+       info->start = start;
+       info->end = oob;
+    }
+    else
+    {
+       info->end = start;
+       info->start = oob;
+    }
+    if (endseg & 1)
+    {
+       info->altend = end;
+       if (info->altend.x < info->end.x || info->altend.y < info->end.y)
+       {
+           miZeroArcPtRec tmp;
+           tmp = info->altend;
+           info->altend = info->end;
+           info->end = tmp;
+       }
+       info->altstart = oob;
+    }
+    else
+    {
+       info->altstart = end;
+       if (info->altstart.x < info->start.x ||
+           info->altstart.y < info->start.y)
+       {
+           miZeroArcPtRec tmp;
+           tmp = info->altstart;
+           info->altstart = info->start;
+           info->start = tmp;
+       }
+       info->altend = oob;
+    }
+    if (!info->start.x || !info->start.y)
+    {
+       info->initialMask = info->start.mask;
+       info->start = info->altstart;
+    }
+    if (!arc->width && (arc->height == 1))
+    {
+       /* kludge! */
+       info->initialMask |= info->end.mask;
+       info->initialMask |= info->initialMask << 1;
+       info->end.x = 0;
+       info->end.mask = 0;
+    }
+    return FALSE;
+}
+
+#define Pixelate(xval,yval) \
+    { \
+       pts->x = xval; \
+       pts->y = yval; \
+       pts++; \
+    }
+
+#define DoPix(idx,xval,yval) if (mask & (1 << idx)) Pixelate(xval, yval);
+
+DDXPointPtr
+miZeroArcPts(arc, pts)
+    xArc *arc;
+    register DDXPointPtr pts;
+{
+    miZeroArcRec info;
+    register int x, y, a, b, d, mask;
+    register int k1, k3, dx, dy;
+    Bool do360;
+
+    do360 = miZeroArcSetup(arc, &info, TRUE);
+    MIARCSETUP();
+    mask = info.initialMask;
+    if (!(arc->width & 1))
+    {
+       DoPix(1, info.xorgo, info.yorg);
+       DoPix(3, info.xorgo, info.yorgo);
+    }
+    if (!info.end.x || !info.end.y)
+    {
+       mask = info.end.mask;
+       info.end = info.altend;
+    }
+    if (do360 && (arc->width == arc->height) && !(arc->width & 1))
+    {
+       int yorgh = info.yorg + info.h;
+       int xorghp = info.xorg + info.h;
+       int xorghn = info.xorg - info.h;
+
+       while (1)
+       {
+           Pixelate(info.xorg + x, info.yorg + y);
+           Pixelate(info.xorg - x, info.yorg + y);
+           Pixelate(info.xorg - x, info.yorgo - y);
+           Pixelate(info.xorg + x, info.yorgo - y);
+           if (a < 0)
+               break;
+           Pixelate(xorghp - y, yorgh - x);
+           Pixelate(xorghn + y, yorgh - x);
+           Pixelate(xorghn + y, yorgh + x);
+           Pixelate(xorghp - y, yorgh + x);
+           MIARCCIRCLESTEP(;);
+       }
+       if (x > 1 && pts[-1].x == pts[-5].x && pts[-1].y == pts[-5].y)
+           pts -= 4;
+       x = info.w;
+       y = info.h;
+    }
+    else if (do360)
+    {
+       while (y < info.h || x < info.w)
+       {
+           MIARCOCTANTSHIFT(;);
+           Pixelate(info.xorg + x, info.yorg + y);
+           Pixelate(info.xorgo - x, info.yorg + y);
+           Pixelate(info.xorgo - x, info.yorgo - y);
+           Pixelate(info.xorg + x, info.yorgo - y);
+           MIARCSTEP(;,;);
+       }
+    }
+    else
+    {
+       while (y < info.h || x < info.w)
+       {
+           MIARCOCTANTSHIFT(;);
+           if ((x == info.start.x) || (y == info.start.y))
+           {
+               mask = info.start.mask;
+               info.start = info.altstart;
+           }
+           DoPix(0, info.xorg + x, info.yorg + y);
+           DoPix(1, info.xorgo - x, info.yorg + y);
+           DoPix(2, info.xorgo - x, info.yorgo - y);
+           DoPix(3, info.xorg + x, info.yorgo - y);
+           if ((x == info.end.x) || (y == info.end.y))
+           {
+               mask = info.end.mask;
+               info.end = info.altend;
+           }
+           MIARCSTEP(;,;);
+       }
+    }
+    if ((x == info.start.x) || (y == info.start.y))
+       mask = info.start.mask;
+    DoPix(0, info.xorg + x, info.yorg + y);
+    DoPix(2, info.xorgo - x, info.yorgo - y);
+    if (arc->height & 1)
+    {
+       DoPix(1, info.xorgo - x, info.yorg + y);
+       DoPix(3, info.xorg + x, info.yorgo - y);
+    }
+    return pts;
+}
+
+#undef DoPix
+#define DoPix(idx,xval,yval) \
+    if (mask & (1 << idx)) \
+    { \
+       arcPts[idx]->x = xval; \
+       arcPts[idx]->y = yval; \
+       arcPts[idx]++; \
+    }
+
+static void
+miZeroArcDashPts(pGC, arc, dinfo, points, maxPts, evenPts, oddPts)
+    GCPtr pGC;
+    xArc *arc;
+    DashInfo *dinfo;
+    int maxPts;
+    register DDXPointPtr points, *evenPts, *oddPts;
+{
+    miZeroArcRec info;
+    register int x, y, a, b, d, mask;
+    register int k1, k3, dx, dy;
+    int dashRemaining;
+    DDXPointPtr arcPts[4];
+    DDXPointPtr startPts[5], endPts[5];
+    int deltas[5];
+    DDXPointPtr startPt, pt, lastPt, pts;
+    int i, j, delta, ptsdelta, seg, startseg;
+
+    for (i = 0; i < 4; i++)
+       arcPts[i] = points + (i * maxPts);
+    (void)miZeroArcSetup(arc, &info, FALSE);
+    MIARCSETUP();
+    mask = info.initialMask;
+    startseg = info.startAngle / QUADRANT;
+    startPt = arcPts[startseg];
+    if (!(arc->width & 1))
+    {
+       DoPix(1, info.xorgo, info.yorg);
+       DoPix(3, info.xorgo, info.yorgo);
+    }
+    if (!info.end.x || !info.end.y)
+    {
+       mask = info.end.mask;
+       info.end = info.altend;
+    }
+    while (y < info.h || x < info.w)
+    {
+       MIARCOCTANTSHIFT(;);
+       if ((x == info.firstx) || (y == info.firsty))
+           startPt = arcPts[startseg];
+       if ((x == info.start.x) || (y == info.start.y))
+       {
+           mask = info.start.mask;
+           info.start = info.altstart;
+       }
+       DoPix(0, info.xorg + x, info.yorg + y);
+       DoPix(1, info.xorgo - x, info.yorg + y);
+       DoPix(2, info.xorgo - x, info.yorgo - y);
+       DoPix(3, info.xorg + x, info.yorgo - y);
+       if ((x == info.end.x) || (y == info.end.y))
+       {
+           mask = info.end.mask;
+           info.end = info.altend;
+       }
+       MIARCSTEP(;,;);
+    }
+    if ((x == info.firstx) || (y == info.firsty))
+       startPt = arcPts[startseg];
+    if ((x == info.start.x) || (y == info.start.y))
+       mask = info.start.mask;
+    DoPix(0, info.xorg + x, info.yorg + y);
+    DoPix(2, info.xorgo - x, info.yorgo - y);
+    if (arc->height & 1)
+    {
+       DoPix(1, info.xorgo - x, info.yorg + y);
+       DoPix(3, info.xorg + x, info.yorgo - y);
+    }
+    for (i = 0; i < 4; i++)
+    {
+       seg = (startseg + i) & 3;
+       pt = points + (seg * maxPts);
+       if (seg & 1)
+       {
+           startPts[i] = pt;
+           endPts[i] = arcPts[seg];
+           deltas[i] = 1;
+       }
+       else
+       {
+           startPts[i] = arcPts[seg] - 1;
+           endPts[i] = pt - 1;
+           deltas[i] = -1;
+       }
+    }
+    startPts[4] = startPts[0];
+    endPts[4] = startPt;
+    startPts[0] = startPt;
+    if (startseg & 1)
+    {
+       if (startPts[4] != endPts[4])
+           endPts[4]--;
+       deltas[4] = 1;
+    }
+    else
+    {
+       if (startPts[0] > startPts[4])
+           startPts[0]--;
+       if (startPts[4] < endPts[4])
+           endPts[4]--;
+       deltas[4] = -1;
+    }
+    if (arc->angle2 < 0)
+    {
+       DDXPointPtr tmps, tmpe;
+       int tmpd;
+
+       tmpd = deltas[0];
+       tmps = startPts[0] - tmpd;
+       tmpe = endPts[0] - tmpd;
+       startPts[0] = endPts[4] - deltas[4];
+       endPts[0] = startPts[4] - deltas[4];
+       deltas[0] = -deltas[4];
+       startPts[4] = tmpe;
+       endPts[4] = tmps;
+       deltas[4] = -tmpd;
+       tmpd = deltas[1];
+       tmps = startPts[1] - tmpd;
+       tmpe = endPts[1] - tmpd;
+       startPts[1] = endPts[3] - deltas[3];
+       endPts[1] = startPts[3] - deltas[3];
+       deltas[1] = -deltas[3];
+       startPts[3] = tmpe;
+       endPts[3] = tmps;
+       deltas[3] = -tmpd;
+       tmps = startPts[2] - deltas[2];
+       startPts[2] = endPts[2] - deltas[2];
+       endPts[2] = tmps;
+       deltas[2] = -deltas[2];
+    }
+    for (i = 0; i < 5 && startPts[i] == endPts[i]; i++)
+       ;
+    if (i == 5)
+       return;
+    pt = startPts[i];
+    for (j = 4; startPts[j] == endPts[j]; j--)
+       ;
+    lastPt = endPts[j] - deltas[j];
+    if (dinfo->haveLast &&
+       (pt->x == dinfo->endPt.x) && (pt->y == dinfo->endPt.y))
+    {
+       startPts[i] += deltas[i];
+    }
+    else
+    {
+       dinfo->dashIndex = dinfo->dashIndexInit;
+       dinfo->dashOffset = dinfo->dashOffsetInit;
+    }
+    if (!dinfo->skipStart && (info.startAngle != info.endAngle))
+    {
+       dinfo->startPt = *pt;
+       dinfo->haveStart = TRUE;
+    }
+    else if (!dinfo->skipLast && dinfo->haveStart &&
+            (lastPt->x == dinfo->startPt.x) &&
+            (lastPt->y == dinfo->startPt.y) &&
+            (lastPt != startPts[i]))
+       endPts[j] = lastPt;
+    if (info.startAngle != info.endAngle)
+    {
+       dinfo->haveLast = TRUE;
+       dinfo->endPt = *lastPt;
+    }
+    dashRemaining = pGC->dash[dinfo->dashIndex] - dinfo->dashOffset;
+    for (i = 0; i < 5; i++)
+    {
+       pt = startPts[i];
+       lastPt = endPts[i];
+       delta = deltas[i];
+       while (pt != lastPt)
+       {
+           if (dinfo->dashIndex & 1)
+           {
+               pts = *oddPts;
+               ptsdelta = -1;
+           }
+           else
+           {
+               pts = *evenPts;
+               ptsdelta = 1;
+           }
+           while ((pt != lastPt) && --dashRemaining >= 0)
+           {
+               *pts = *pt;
+               pts += ptsdelta;
+               pt += delta;
+           }
+           if (dinfo->dashIndex & 1)
+               *oddPts = pts;
+           else
+               *evenPts = pts;
+           if (dashRemaining <= 0)
+           {
+               if (++(dinfo->dashIndex) == pGC->numInDashList)
+                   dinfo->dashIndex = 0;
+               dashRemaining = pGC->dash[dinfo->dashIndex];
+           }
+       }
+    }
+    dinfo->dashOffset = pGC->dash[dinfo->dashIndex] - dashRemaining;
+}
+
+void
+miZeroPolyArc(pDraw, pGC, narcs, parcs)
+    DrawablePtr        pDraw;
+    GCPtr      pGC;
+    int                narcs;
+    xArc       *parcs;
+{
+    int maxPts = 0;
+    register int n, maxw;
+    register xArc *arc;
+    register int i;
+    DDXPointPtr points, pts, oddPts;
+    register DDXPointPtr pt;
+    int numPts;
+    Bool dospans;
+    int *widths;
+    XID fgPixel = pGC->fgPixel;
+    DashInfo dinfo;
+
+    for (arc = parcs, i = narcs; --i >= 0; arc++)
+    {
+       if (!miCanZeroArc(arc))
+           miPolyArc(pDraw, pGC, 1, arc);
+       else
+       {
+           if (arc->width > arc->height)
+               n = arc->width + (arc->height >> 1);
+           else
+               n = arc->height + (arc->width >> 1);
+           if (n > maxPts)
+               maxPts = n;
+       }
+    }
+    if (!maxPts)
+       return;
+    numPts = maxPts << 2;
+    dospans = (pGC->lineStyle != LineSolid) || (pGC->fillStyle != FillSolid);
+    if (dospans)
+    {
+       widths = (int *)ALLOCATE_LOCAL(sizeof(int) * numPts);
+       if (!widths)
+           return;
+       maxw = 0;
+    }
+    if (pGC->lineStyle != LineSolid)
+    {
+       numPts <<= 1;
+       dinfo.haveStart = FALSE;
+       dinfo.skipStart = FALSE;
+       dinfo.haveLast = FALSE;
+       dinfo.dashIndexInit = 0;
+       dinfo.dashOffsetInit = 0;
+       miStepDash((int)pGC->dashOffset, &dinfo.dashIndexInit,
+                  (unsigned char *) pGC->dash, (int)pGC->numInDashList,
+                  &dinfo.dashOffsetInit);
+    }
+    points = (DDXPointPtr)ALLOCATE_LOCAL(sizeof(DDXPointRec) * numPts);
+    if (!points)
+    {
+       if (dospans)
+       {
+           DEALLOCATE_LOCAL(widths);
+       }
+       return;
+    }
+    for (arc = parcs, i = narcs; --i >= 0; arc++)
+    {
+       if (miCanZeroArc(arc))
+       {
+           if (pGC->lineStyle == LineSolid)
+               pts = miZeroArcPts(arc, points);
+           else
+           {
+               pts = points;
+               oddPts = &points[(numPts >> 1) - 1];
+               dinfo.skipLast = i;
+               miZeroArcDashPts(pGC, arc, &dinfo,
+                                oddPts + 1, maxPts, &pts, &oddPts);
+               dinfo.skipStart = TRUE;
+           }
+           n = pts - points;
+           if (!dospans)
+               (*pGC->ops->PolyPoint)(pDraw, pGC, CoordModeOrigin, n, points);
+           else
+           {
+               if (n > maxw)
+               {
+                   while (maxw < n)
+                       widths[maxw++] = 1;
+               }
+               if (pGC->miTranslate)
+               {
+                   for (pt = points; pt != pts; pt++)
+                   {
+                       pt->x += pDraw->x;
+                       pt->y += pDraw->y;
+                   }
+               }
+               (*pGC->ops->FillSpans)(pDraw, pGC, n, points, widths, FALSE);
+           }
+           if (pGC->lineStyle != LineDoubleDash)
+               continue;
+           if ((pGC->fillStyle == FillSolid) ||
+               (pGC->fillStyle == FillStippled))
+           {
+               DoChangeGC(pGC, GCForeground, (XID *)&pGC->bgPixel, 0);
+               ValidateGC(pDraw, pGC);
+           }
+           pts = &points[numPts >> 1];
+           oddPts++;
+           n = pts - oddPts;
+           if (!dospans)
+               (*pGC->ops->PolyPoint)(pDraw, pGC, CoordModeOrigin, n, oddPts);
+           else
+           {
+               if (n > maxw)
+               {
+                   while (maxw < n)
+                       widths[maxw++] = 1;
+               }
+               if (pGC->miTranslate)
+               {
+                   for (pt = oddPts; pt != pts; pt++)
+                   {
+                       pt->x += pDraw->x;
+                       pt->y += pDraw->y;
+                   }
+               }
+               (*pGC->ops->FillSpans)(pDraw, pGC, n, oddPts, widths, FALSE);
+           }
+           if ((pGC->fillStyle == FillSolid) ||
+               (pGC->fillStyle == FillStippled))
+           {
+               DoChangeGC(pGC, GCForeground, &fgPixel, 0);
+               ValidateGC(pDraw, pGC);
+           }
+       }
+    }
+    DEALLOCATE_LOCAL(points);
+    if (dospans)
+    {
+       DEALLOCATE_LOCAL(widths);
+    }
+}
diff --git a/Xserver/programs/Xserver/mi/mizerarc.h b/Xserver/programs/Xserver/mi/mizerarc.h
new file mode 100644 (file)
index 0000000..84a16af
--- /dev/null
@@ -0,0 +1,138 @@
+/************************************************************
+
+Copyright (c) 1989  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+********************************************************/
+
+/* $XConsortium: mizerarc.h,v 5.13 94/04/17 20:28:04 dpw Exp $ */
+
+typedef struct {
+    int x;
+    int y;
+    int mask;
+} miZeroArcPtRec;
+
+typedef struct {
+    int x, y, k1, k3, a, b, d, dx, dy;
+    int alpha, beta;
+    int xorg, yorg;
+    int xorgo, yorgo;
+    int w, h;
+    int initialMask;
+    miZeroArcPtRec start, altstart, end, altend;
+    int firstx, firsty;
+    int startAngle, endAngle;
+} miZeroArcRec;
+
+#define miCanZeroArc(arc) (((arc)->width == (arc)->height) || \
+                          (((arc)->width <= 800) && ((arc)->height <= 800)))
+
+#define MIARCSETUP() \
+    x = info.x; \
+    y = info.y; \
+    k1 = info.k1; \
+    k3 = info.k3; \
+    a = info.a; \
+    b = info.b; \
+    d = info.d; \
+    dx = info.dx; \
+    dy = info.dy
+
+#define MIARCOCTANTSHIFT(clause) \
+    if (a < 0) \
+    { \
+       if (y == info.h) \
+       { \
+           d = -1; \
+           a = b = k1 = 0; \
+       } \
+       else \
+       { \
+           dx = (k1 << 1) - k3; \
+           k1 = dx - k1; \
+           k3 = -k3; \
+           b = b + a - (k1 >> 1); \
+           d = b + ((-a) >> 1) - d + (k3 >> 3); \
+           if (dx < 0) \
+               a = -((-dx) >> 1) - a; \
+           else \
+               a = (dx >> 1) - a; \
+           dx = 0; \
+           dy = 1; \
+           clause \
+       } \
+    }
+
+#define MIARCSTEP(move1,move2) \
+    b -= k1; \
+    if (d < 0) \
+    { \
+       x += dx; \
+       y += dy; \
+       a += k1; \
+       d += b; \
+       move1 \
+    } \
+    else \
+    { \
+       x++; \
+       y++; \
+       a += k3; \
+       d -= a; \
+       move2 \
+    }
+
+#define MIARCCIRCLESTEP(clause) \
+    b -= k1; \
+    x++; \
+    if (d < 0) \
+    { \
+       a += k1; \
+       d += b; \
+    } \
+    else \
+    { \
+       y++; \
+       a += k3; \
+       d -= a; \
+       clause \
+    }
+
+/* mizerarc.c */
+
+extern Bool miZeroArcSetup(
+#if NeedFunctionPrototypes
+    xArc * /*arc*/,
+    miZeroArcRec * /*info*/,
+    Bool /*ok360*/
+#endif
+);
+
+extern DDXPointPtr miZeroArcPts(
+#if NeedFunctionPrototypes
+    xArc * /*arc*/,
+    DDXPointPtr /*pts*/
+#endif
+);
+
diff --git a/Xserver/programs/Xserver/mi/mizerline.c b/Xserver/programs/Xserver/mi/mizerline.c
new file mode 100644 (file)
index 0000000..960255b
--- /dev/null
@@ -0,0 +1,961 @@
+/***********************************************************
+
+Copyright (c) 1987  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+
+Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
+
+                        All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and its 
+documentation for any purpose and without fee is hereby granted, 
+provided that the above copyright notice appear in all copies and that
+both that copyright notice and this permission notice appear in 
+supporting documentation, and that the name of Digital not be
+used in advertising or publicity pertaining to distribution of the
+software without specific, written prior permission.  
+
+DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
+ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
+DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
+ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+SOFTWARE.
+
+******************************************************************/
+/* $XConsortium: mizerline.c,v 5.9 94/08/02 15:01:29 dpw Exp $ */
+#include "X.h"
+
+#include "misc.h"
+#include "scrnintstr.h"
+#include "gcstruct.h"
+#include "windowstr.h"
+#include "pixmap.h"
+#include "mi.h"
+#include "miline.h"
+
+/*
+
+The bresenham error equation used in the mi/mfb/cfb line routines is:
+
+       e = error
+       dx = difference in raw X coordinates
+       dy = difference in raw Y coordinates
+       M = # of steps in X direction
+       N = # of steps in Y direction
+       B = 0 to prefer diagonal steps in a given octant,
+           1 to prefer axial steps in a given octant
+
+       For X major lines:
+               e = 2Mdy - 2Ndx - dx - B
+               -2dx <= e < 0
+
+       For Y major lines:
+               e = 2Ndx - 2Mdy - dy - B
+               -2dy <= e < 0
+
+At the start of the line, we have taken 0 X steps and 0 Y steps,
+so M = 0 and N = 0:
+
+       X major e = 2Mdy - 2Ndx - dx - B
+                 = -dx - B
+
+       Y major e = 2Ndx - 2Mdy - dy - B
+                 = -dy - B
+
+At the end of the line, we have taken dx X steps and dy Y steps,
+so M = dx and N = dy:
+
+       X major e = 2Mdy - 2Ndx - dx - B
+                 = 2dxdy - 2dydx - dx - B
+                 = -dx - B
+       Y major e = 2Ndx - 2Mdy - dy - B
+                 = 2dydx - 2dxdy - dy - B
+                 = -dy - B
+
+Thus, the error term is the same at the start and end of the line.
+
+Let us consider clipping an X coordinate.  There are 4 cases which
+represent the two independent cases of clipping the start vs. the
+end of the line and an X major vs. a Y major line.  In any of these
+cases, we know the number of X steps (M) and we wish to find the
+number of Y steps (N).  Thus, we will solve our error term equation.
+If we are clipping the start of the line, we will find the smallest
+N that satisfies our error term inequality.  If we are clipping the
+end of the line, we will find the largest number of Y steps that
+satisfies the inequality.  In that case, since we are representing
+the Y steps as (dy - N), we will actually want to solve for the
+smallest N in that equation.
+\f
+Case 1:  X major, starting X coordinate moved by M steps
+
+               -2dx <= 2Mdy - 2Ndx - dx - B < 0
+       2Ndx <= 2Mdy - dx - B + 2dx     2Ndx > 2Mdy - dx - B
+       2Ndx <= 2Mdy + dx - B           N > (2Mdy - dx - B) / 2dx
+       N <= (2Mdy + dx - B) / 2dx
+
+Since we are trying to find the smallest N that satisfies these
+equations, we should use the > inequality to find the smallest:
+
+       N = floor((2Mdy - dx - B) / 2dx) + 1
+         = floor((2Mdy - dx - B + 2dx) / 2dx)
+         = floor((2Mdy + dx - B) / 2dx)
+
+Case 1b: X major, ending X coordinate moved to M steps
+
+Same derivations as Case 1, but we want the largest N that satisfies
+the equations, so we use the <= inequality:
+
+       N = floor((2Mdy + dx - B) / 2dx)
+
+Case 2: X major, ending X coordinate moved by M steps
+
+               -2dx <= 2(dx - M)dy - 2(dy - N)dx - dx - B < 0
+               -2dx <= 2dxdy - 2Mdy - 2dxdy + 2Ndx - dx - B < 0
+               -2dx <= 2Ndx - 2Mdy - dx - B < 0
+       2Ndx >= 2Mdy + dx + B - 2dx     2Ndx < 2Mdy + dx + B
+       2Ndx >= 2Mdy - dx + B           N < (2Mdy + dx + B) / 2dx
+       N >= (2Mdy - dx + B) / 2dx
+
+Since we are trying to find the highest number of Y steps that
+satisfies these equations, we need to find the smallest N, so
+we should use the >= inequality to find the smallest:
+
+       N = ceiling((2Mdy - dx + B) / 2dx)
+         = floor((2Mdy - dx + B + 2dx - 1) / 2dx)
+         = floor((2Mdy + dx + B - 1) / 2dx)
+
+Case 2b: X major, starting X coordinate moved to M steps from end
+
+Same derivations as Case 2, but we want the smallest number of Y
+steps, so we want the highest N, so we use the < inequality:
+
+       N = ceiling((2Mdy + dx + B) / 2dx) - 1
+         = floor((2Mdy + dx + B + 2dx - 1) / 2dx) - 1
+         = floor((2Mdy + dx + B + 2dx - 1 - 2dx) / 2dx)
+         = floor((2Mdy + dx + B - 1) / 2dx)
+\f
+Case 3: Y major, starting X coordinate moved by M steps
+
+               -2dy <= 2Ndx - 2Mdy - dy - B < 0
+       2Ndx >= 2Mdy + dy + B - 2dy     2Ndx < 2Mdy + dy + B
+       2Ndx >= 2Mdy - dy + B           N < (2Mdy + dy + B) / 2dx
+       N >= (2Mdy - dy + B) / 2dx
+
+Since we are trying to find the smallest N that satisfies these
+equations, we should use the >= inequality to find the smallest:
+
+       N = ceiling((2Mdy - dy + B) / 2dx)
+         = floor((2Mdy - dy + B + 2dx - 1) / 2dx)
+         = floor((2Mdy - dy + B - 1) / 2dx) + 1
+
+Case 3b: Y major, ending X coordinate moved to M steps
+
+Same derivations as Case 3, but we want the largest N that satisfies
+the equations, so we use the < inequality:
+
+       N = ceiling((2Mdy + dy + B) / 2dx) - 1
+         = floor((2Mdy + dy + B + 2dx - 1) / 2dx) - 1
+         = floor((2Mdy + dy + B + 2dx - 1 - 2dx) / 2dx)
+         = floor((2Mdy + dy + B - 1) / 2dx)
+
+Case 4: Y major, ending X coordinate moved by M steps
+
+               -2dy <= 2(dy - N)dx - 2(dx - M)dy - dy - B < 0
+               -2dy <= 2dxdy - 2Ndx - 2dxdy + 2Mdy - dy - B < 0
+               -2dy <= 2Mdy - 2Ndx - dy - B < 0
+       2Ndx <= 2Mdy - dy - B + 2dy     2Ndx > 2Mdy - dy - B
+       2Ndx <= 2Mdy + dy - B           N > (2Mdy - dy - B) / 2dx
+       N <= (2Mdy + dy - B) / 2dx
+
+Since we are trying to find the highest number of Y steps that
+satisfies these equations, we need to find the smallest N, so
+we should use the > inequality to find the smallest:
+
+       N = floor((2Mdy - dy - B) / 2dx) + 1
+
+Case 4b: Y major, starting X coordinate moved to M steps from end
+
+Same analysis as Case 4, but we want the smallest number of Y steps
+which means the largest N, so we use the <= inequality:
+
+       N = floor((2Mdy + dy - B) / 2dx)
+\f
+Now let's try the Y coordinates, we have the same 4 cases.
+
+Case 5: X major, starting Y coordinate moved by N steps
+
+               -2dx <= 2Mdy - 2Ndx - dx - B < 0
+       2Mdy >= 2Ndx + dx + B - 2dx     2Mdy < 2Ndx + dx + B
+       2Mdy >= 2Ndx - dx + B           M < (2Ndx + dx + B) / 2dy
+       M >= (2Ndx - dx + B) / 2dy
+
+Since we are trying to find the smallest M, we use the >= inequality:
+
+       M = ceiling((2Ndx - dx + B) / 2dy)
+         = floor((2Ndx - dx + B + 2dy - 1) / 2dy)
+         = floor((2Ndx - dx + B - 1) / 2dy) + 1
+
+Case 5b: X major, ending Y coordinate moved to N steps
+
+Same derivations as Case 5, but we want the largest M that satisfies
+the equations, so we use the < inequality:
+
+       M = ceiling((2Ndx + dx + B) / 2dy) - 1
+         = floor((2Ndx + dx + B + 2dy - 1) / 2dy) - 1
+         = floor((2Ndx + dx + B + 2dy - 1 - 2dy) / 2dy)
+         = floor((2Ndx + dx + B - 1) / 2dy)
+
+Case 6: X major, ending Y coordinate moved by N steps
+
+               -2dx <= 2(dx - M)dy - 2(dy - N)dx - dx - B < 0
+               -2dx <= 2dxdy - 2Mdy - 2dxdy + 2Ndx - dx - B < 0
+               -2dx <= 2Ndx - 2Mdy - dx - B < 0
+       2Mdy <= 2Ndx - dx - B + 2dx     2Mdy > 2Ndx - dx - B
+       2Mdy <= 2Ndx + dx - B           M > (2Ndx - dx - B) / 2dy
+       M <= (2Ndx + dx - B) / 2dy
+
+Largest # of X steps means smallest M, so use the > inequality:
+
+       M = floor((2Ndx - dx - B) / 2dy) + 1
+
+Case 6b: X major, starting Y coordinate moved to N steps from end
+
+Same derivations as Case 6, but we want the smallest # of X steps
+which means the largest M, so use the <= inequality:
+
+       M = floor((2Ndx + dx - B) / 2dy)
+\f
+Case 7: Y major, starting Y coordinate moved by N steps
+
+               -2dy <= 2Ndx - 2Mdy - dy - B < 0
+       2Mdy <= 2Ndx - dy - B + 2dy     2Mdy > 2Ndx - dy - B
+       2Mdy <= 2Ndx + dy - B           M > (2Ndx - dy - B) / 2dy
+       M <= (2Ndx + dy - B) / 2dy
+
+To find the smallest M, use the > inequality:
+
+       M = floor((2Ndx - dy - B) / 2dy) + 1
+         = floor((2Ndx - dy - B + 2dy) / 2dy)
+         = floor((2Ndx + dy - B) / 2dy)
+
+Case 7b: Y major, ending Y coordinate moved to N steps
+
+Same derivations as Case 7, but we want the largest M that satisfies
+the equations, so use the <= inequality:
+
+       M = floor((2Ndx + dy - B) / 2dy)
+
+Case 8: Y major, ending Y coordinate moved by N steps
+
+               -2dy <= 2(dy - N)dx - 2(dx - M)dy - dy - B < 0
+               -2dy <= 2dxdy - 2Ndx - 2dxdy + 2Mdy - dy - B < 0
+               -2dy <= 2Mdy - 2Ndx - dy - B < 0
+       2Mdy >= 2Ndx + dy + B - 2dy     2Mdy < 2Ndx + dy + B
+       2Mdy >= 2Ndx - dy + B           M < (2Ndx + dy + B) / 2dy
+       M >= (2Ndx - dy + B) / 2dy
+
+To find the highest X steps, find the smallest M, use the >= inequality:
+
+       M = ceiling((2Ndx - dy + B) / 2dy)
+         = floor((2Ndx - dy + B + 2dy - 1) / 2dy)
+         = floor((2Ndx + dy + B - 1) / 2dy)
+
+Case 8b: Y major, starting Y coordinate moved to N steps from the end
+
+Same derivations as Case 8, but we want to find the smallest # of X
+steps which means the largest M, so we use the < inequality:
+
+       M = ceiling((2Ndx + dy + B) / 2dy) - 1
+         = floor((2Ndx + dy + B + 2dy - 1) / 2dy) - 1
+         = floor((2Ndx + dy + B + 2dy - 1 - 2dy) / 2dy)
+         = floor((2Ndx + dy + B - 1) / 2dy)
+\f
+So, our equations are:
+
+       1:  X major move x1 to x1+M     floor((2Mdy + dx - B) / 2dx)
+       1b: X major move x2 to x1+M     floor((2Mdy + dx - B) / 2dx)
+       2:  X major move x2 to x2-M     floor((2Mdy + dx + B - 1) / 2dx)
+       2b: X major move x1 to x2-M     floor((2Mdy + dx + B - 1) / 2dx)
+
+       3:  Y major move x1 to x1+M     floor((2Mdy - dy + B - 1) / 2dx) + 1
+       3b: Y major move x2 to x1+M     floor((2Mdy + dy + B - 1) / 2dx)
+       4:  Y major move x2 to x2-M     floor((2Mdy - dy - B) / 2dx) + 1
+       4b: Y major move x1 to x2-M     floor((2Mdy + dy - B) / 2dx)
+
+       5:  X major move y1 to y1+N     floor((2Ndx - dx + B - 1) / 2dy) + 1
+       5b: X major move y2 to y1+N     floor((2Ndx + dx + B - 1) / 2dy)
+       6:  X major move y2 to y2-N     floor((2Ndx - dx - B) / 2dy) + 1
+       6b: X major move y1 to y2-N     floor((2Ndx + dx - B) / 2dy)
+
+       7:  Y major move y1 to y1+N     floor((2Ndx + dy - B) / 2dy)
+       7b: Y major move y2 to y1+N     floor((2Ndx + dy - B) / 2dy)
+       8:  Y major move y2 to y2-N     floor((2Ndx + dy + B - 1) / 2dy)
+       8b: Y major move y1 to y2-N     floor((2Ndx + dy + B - 1) / 2dy)
+
+We have the following constraints on all of the above terms:
+
+       0 < M,N <= 2^15          2^15 can be imposed by miZeroClipLine
+       0 <= dx/dy <= 2^16 - 1
+       0 <= B <= 1
+
+The floor in all of the above equations can be accomplished with a
+simple C divide operation provided that both numerator and denominator
+are positive.
+
+Since dx,dy >= 0 and since moving an X coordinate implies that dx != 0
+and moving a Y coordinate implies dy != 0, we know that the denominators
+are all > 0.
+
+For all lines, (-B) and (B-1) are both either 0 or -1, depending on the
+bias.  Thus, we have to show that the 2MNdxy +/- dxy terms are all >= 1
+or > 0 to prove that the numerators are positive (or zero).
+
+For X Major lines we know that dx > 0 and since 2Mdy is >= 0 due to the
+constraints, the first four equations all have numerators >= 0.
+
+For the second four equations, M > 0, so 2Mdy >= 2dy so (2Mdy - dy) >= dy
+So (2Mdy - dy) > 0, since they are Y major lines.  Also, (2Mdy + dy) >= 3dy
+or (2Mdy + dy) > 0.  So all of their numerators are >= 0.
+
+For the third set of four equations, N > 0, so 2Ndx >= 2dx so (2Ndx - dx)
+>= dx > 0.  Similarly (2Ndx + dx) >= 3dx > 0.  So all numerators >= 0.
+
+For the fourth set of equations, dy > 0 and 2Ndx >= 0, so all numerators
+are > 0.
+
+To consider overflow, consider the case of 2 * M,N * dx,dy + dx,dy.  This
+is bounded <= 2 * 2^15 * (2^16 - 1) + (2^16 - 1)
+          <= 2^16 * (2^16 - 1) + (2^16 - 1)
+          <= 2^32 - 2^16 + 2^16 - 1
+          <= 2^32 - 1
+Since the (-B) and (B-1) terms are all 0 or -1, the maximum value of
+the numerator is therefore (2^32 - 1), which does not overflow an unsigned
+32 bit variable.
+
+*/
+
+#define MIOUTCODES(outcode, x, y, xmin, ymin, xmax, ymax) \
+{\
+     if (x < xmin) outcode |= OUT_LEFT;\
+     if (x > xmax) outcode |= OUT_RIGHT;\
+     if (y < ymin) outcode |= OUT_ABOVE;\
+     if (y > ymax) outcode |= OUT_BELOW;\
+}
+
+/* Bit codes for the terms of the 16 clipping equations defined below. */
+
+#define T_2NDX         (1 << 0)
+#define T_2MDY         (0)                             /* implicit term */
+#define T_DXNOTY       (1 << 1)
+#define T_DYNOTX       (0)                             /* implicit term */
+#define T_SUBDXORY     (1 << 2)
+#define T_ADDDX                (T_DXNOTY)                      /* composite term */
+#define T_SUBDX                (T_DXNOTY | T_SUBDXORY)         /* composite term */
+#define T_ADDDY                (T_DYNOTX)                      /* composite term */
+#define T_SUBDY                (T_DYNOTX | T_SUBDXORY)         /* composite term */
+#define T_BIASSUBONE   (1 << 3)
+#define T_SUBBIAS      (0)                             /* implicit term */
+#define T_DIV2DX       (1 << 4)
+#define T_DIV2DY       (0)                             /* implicit term */
+#define T_ADDONE       (1 << 5)
+
+/* Bit masks defining the 16 equations used in miZeroClipLine. */
+
+#define EQN1   (T_2MDY | T_ADDDX | T_SUBBIAS    | T_DIV2DX)
+#define EQN1B  (T_2MDY | T_ADDDX | T_SUBBIAS    | T_DIV2DX)
+#define EQN2   (T_2MDY | T_ADDDX | T_BIASSUBONE | T_DIV2DX)
+#define EQN2B  (T_2MDY | T_ADDDX | T_BIASSUBONE | T_DIV2DX)
+
+#define EQN3   (T_2MDY | T_SUBDY | T_BIASSUBONE | T_DIV2DX | T_ADDONE)
+#define EQN3B  (T_2MDY | T_ADDDY | T_BIASSUBONE | T_DIV2DX)
+#define EQN4   (T_2MDY | T_SUBDY | T_SUBBIAS    | T_DIV2DX | T_ADDONE)
+#define EQN4B  (T_2MDY | T_ADDDY | T_SUBBIAS    | T_DIV2DX)
+
+#define EQN5   (T_2NDX | T_SUBDX | T_BIASSUBONE | T_DIV2DY | T_ADDONE)
+#define EQN5B  (T_2NDX | T_ADDDX | T_BIASSUBONE | T_DIV2DY)
+#define EQN6   (T_2NDX | T_SUBDX | T_SUBBIAS    | T_DIV2DY | T_ADDONE)
+#define EQN6B  (T_2NDX | T_ADDDX | T_SUBBIAS    | T_DIV2DY)
+
+#define EQN7   (T_2NDX | T_ADDDY | T_SUBBIAS    | T_DIV2DY)
+#define EQN7B  (T_2NDX | T_ADDDY | T_SUBBIAS    | T_DIV2DY)
+#define EQN8   (T_2NDX | T_ADDDY | T_BIASSUBONE | T_DIV2DY)
+#define EQN8B  (T_2NDX | T_ADDDY | T_BIASSUBONE | T_DIV2DY)
+
+/* miZeroClipLine
+ *
+ * returns:  1 for partially clipped line
+ *          -1 for completely clipped line
+ *
+ */
+int
+miZeroClipLine(xmin, ymin, xmax, ymax,
+              new_x1, new_y1, new_x2, new_y2,
+              adx, ady,
+              pt1_clipped, pt2_clipped, octant, bias, oc1, oc2)
+    int xmin, ymin, xmax, ymax;
+    int *new_x1, *new_y1, *new_x2, *new_y2;
+    int *pt1_clipped, *pt2_clipped;
+    unsigned int adx, ady;
+    int octant;
+    unsigned int bias;
+    int oc1, oc2;
+{
+    int swapped = 0;
+    int clipDone = 0;
+    CARD32 utmp;
+    int clip1, clip2;
+    int x1, y1, x2, y2;
+    int x1_orig, y1_orig, x2_orig, y2_orig;
+    int xmajor;
+    int negslope, anchorval;
+    unsigned int eqn;
+
+    x1 = x1_orig = *new_x1;
+    y1 = y1_orig = *new_y1;
+    x2 = x2_orig = *new_x2;
+    y2 = y2_orig = *new_y2;
+
+    clip1 = 0;
+    clip2 = 0;
+
+    xmajor = IsXMajorOctant(octant);
+    bias = ((bias >> octant) & 1);
+
+    while (1)
+    {
+        if ((oc1 & oc2) != 0)                  /* trivial reject */
+       {
+           clipDone = -1;
+           clip1 = oc1;
+           clip2 = oc2;
+           break;
+       }
+        else if ((oc1 | oc2) == 0)             /* trivial accept */
+        {
+           clipDone = 1;
+           if (swapped)
+           {
+               SWAPINT_PAIR(x1, y1, x2, y2);
+               SWAPINT(clip1, clip2);
+           }
+           break;
+        }
+        else                   /* have to clip */
+        {
+           /* only clip one point at a time */
+           if (oc1 == 0)
+           {
+               SWAPINT_PAIR(x1, y1, x2, y2);
+               SWAPINT_PAIR(x1_orig, y1_orig, x2_orig, y2_orig);
+               SWAPINT(oc1, oc2);
+               SWAPINT(clip1, clip2);
+               swapped = !swapped;
+           }
+    
+           clip1 |= oc1;
+           if (oc1 & OUT_LEFT)
+           {
+               negslope = IsYDecreasingOctant(octant);
+               utmp = xmin - x1_orig;
+               if (utmp <= 32767)              /* clip based on near endpt */
+               {
+                   if (xmajor)
+                       eqn = (swapped) ? EQN2 : EQN1;
+                   else
+                       eqn = (swapped) ? EQN4 : EQN3;
+                   anchorval = y1_orig;
+               }
+               else                            /* clip based on far endpt */
+               {
+                   utmp = x2_orig - xmin;
+                   if (xmajor)
+                       eqn = (swapped) ? EQN1B : EQN2B;
+                   else
+                       eqn = (swapped) ? EQN3B : EQN4B;
+                   anchorval = y2_orig;
+                   negslope = !negslope;
+               }
+               x1 = xmin;
+           }
+           else if (oc1 & OUT_ABOVE)
+           {
+               negslope = IsXDecreasingOctant(octant);
+               utmp = ymin - y1_orig;
+               if (utmp <= 32767)              /* clip based on near endpt */
+               {
+                   if (xmajor)
+                       eqn = (swapped) ? EQN6 : EQN5;
+                   else
+                       eqn = (swapped) ? EQN8 : EQN7;
+                   anchorval = x1_orig;
+               }
+               else                            /* clip based on far endpt */
+               {
+                   utmp = y2_orig - ymin;
+                   if (xmajor)
+                       eqn = (swapped) ? EQN5B : EQN6B;
+                   else
+                       eqn = (swapped) ? EQN7B : EQN8B;
+                   anchorval = x2_orig;
+                   negslope = !negslope;
+               }
+               y1 = ymin;
+           }
+           else if (oc1 & OUT_RIGHT)
+           {
+               negslope = IsYDecreasingOctant(octant);
+               utmp = x1_orig - xmax;
+               if (utmp <= 32767)              /* clip based on near endpt */
+               {
+                   if (xmajor)
+                       eqn = (swapped) ? EQN2 : EQN1;
+                   else
+                       eqn = (swapped) ? EQN4 : EQN3;
+                   anchorval = y1_orig;
+               }
+               else                            /* clip based on far endpt */
+               {
+                   /*
+                    * Technically since the equations can handle
+                    * utmp == 32768, this overflow code isn't
+                    * needed since X11 protocol can't generate
+                    * a line which goes more than 32768 pixels
+                    * to the right of a clip rectangle.
+                    */
+                   utmp = xmax - x2_orig;
+                   if (xmajor)
+                       eqn = (swapped) ? EQN1B : EQN2B;
+                   else
+                       eqn = (swapped) ? EQN3B : EQN4B;
+                   anchorval = y2_orig;
+                   negslope = !negslope;
+               }
+               x1 = xmax;
+           }
+           else if (oc1 & OUT_BELOW)
+           {
+               negslope = IsXDecreasingOctant(octant);
+               utmp = y1_orig - ymax;
+               if (utmp <= 32767)              /* clip based on near endpt */
+               {
+                   if (xmajor)
+                       eqn = (swapped) ? EQN6 : EQN5;
+                   else
+                       eqn = (swapped) ? EQN8 : EQN7;
+                   anchorval = x1_orig;
+               }
+               else                            /* clip based on far endpt */
+               {
+                   /*
+                    * Technically since the equations can handle
+                    * utmp == 32768, this overflow code isn't
+                    * needed since X11 protocol can't generate
+                    * a line which goes more than 32768 pixels
+                    * below the bottom of a clip rectangle.
+                    */
+                   utmp = ymax - y2_orig;
+                   if (xmajor)
+                       eqn = (swapped) ? EQN5B : EQN6B;
+                   else
+                       eqn = (swapped) ? EQN7B : EQN8B;
+                   anchorval = x2_orig;
+                   negslope = !negslope;
+               }
+               y1 = ymax;
+           }
+
+           if (swapped)
+               negslope = !negslope;
+
+           utmp <<= 1;                 /* utmp = 2N or 2M */
+           if (eqn & T_2NDX)
+               utmp = (utmp * adx);
+           else /* (eqn & T_2MDY) */
+               utmp = (utmp * ady);
+           if (eqn & T_DXNOTY)
+               if (eqn & T_SUBDXORY)
+                   utmp -= adx;
+               else
+                   utmp += adx;
+           else /* (eqn & T_DYNOTX) */
+               if (eqn & T_SUBDXORY)
+                   utmp -= ady;
+               else
+                   utmp += ady;
+           if (eqn & T_BIASSUBONE)
+               utmp += bias - 1;
+           else /* (eqn & T_SUBBIAS) */
+               utmp -= bias;
+           if (eqn & T_DIV2DX)
+               utmp /= (adx << 1);
+           else /* (eqn & T_DIV2DY) */
+               utmp /= (ady << 1);
+           if (eqn & T_ADDONE)
+               utmp++;
+
+           if (negslope)
+               utmp = -utmp;
+
+           if (eqn & T_2NDX)   /* We are calculating X steps */
+               x1 = anchorval + utmp;
+           else                /* else, Y steps */
+               y1 = anchorval + utmp;
+
+           oc1 = 0;
+           MIOUTCODES(oc1, x1, y1, xmin, ymin, xmax, ymax);
+        }
+    }
+
+    *new_x1 = x1;
+    *new_y1 = y1;
+    *new_x2 = x2;
+    *new_y2 = y2;
+    
+    *pt1_clipped = clip1;
+    *pt2_clipped = clip2;
+
+    return clipDone;
+}
+
+
+/* Draw lineSolid, fillStyle-independent zero width lines.
+ *
+ * Must keep X and Y coordinates in "ints" at least until after they're
+ * translated and clipped to accomodate CoordModePrevious lines with very
+ * large coordinates.
+ *
+ * Draws the same pixels regardless of sign(dx) or sign(dy).
+ *
+ * Ken Whaley
+ *
+ */
+
+/* largest positive value that can fit into a component of a point.
+ * Assumes that the point structure is {type x, y;} where type is
+ * a signed type.
+ */
+#define MAX_COORDINATE ((1 << (((sizeof(DDXPointRec) >> 1) << 3) - 1)) - 1)
+
+#define MI_OUTPUT_POINT(xx, yy)\
+{\
+    if ( !new_span && yy == current_y)\
+    {\
+        if (xx < spans->x)\
+           spans->x = xx;\
+       ++*widths;\
+    }\
+    else\
+    {\
+        ++Nspans;\
+       ++spans;\
+       ++widths;\
+       spans->x = xx;\
+       spans->y = yy;\
+       *widths = 1;\
+       current_y = yy;\
+        new_span = FALSE;\
+    }\
+}
+
+void
+miZeroLine(pDraw, pGC, mode, npt, pptInit)
+    DrawablePtr pDraw;
+    GCPtr      pGC;
+    int                mode;           /* Origin or Previous */
+    int                npt;            /* number of points */
+    DDXPointPtr pptInit;
+{
+    int Nspans, current_y;
+    DDXPointPtr ppt; 
+    DDXPointPtr pspanInit, spans;
+    int *pwidthInit, *widths, list_len;
+    int xleft, ytop, xright, ybottom;
+    int new_x1, new_y1, new_x2, new_y2;
+    int x, y, x1, y1, x2, y2, xstart, ystart;
+    int oc1, oc2;
+    int result;
+    int pt1_clipped, pt2_clipped = 0;
+    Bool new_span;
+    int signdx, signdy;
+    int clipdx, clipdy;
+    int width, height;
+    int adx, ady;
+    int octant;
+    unsigned int bias = miGetZeroLineBias(pDraw->pScreen);
+    int e, e1, e2, e3; /* Bresenham error terms */
+    int length;                /* length of lines == # of pixels on major axis */
+
+    xleft   = pDraw->x;
+    ytop    = pDraw->y;
+    xright  = pDraw->x + pDraw->width - 1;
+    ybottom = pDraw->y + pDraw->height - 1;
+
+    if (!pGC->miTranslate)
+    {
+       /* do everything in drawable-relative coordinates */
+       xleft    = 0;
+       ytop     = 0;
+       xright  -= pDraw->x;
+       ybottom -= pDraw->y;
+    }
+
+    /* it doesn't matter whether we're in drawable or screen coordinates,
+     * FillSpans simply cannot take starting coordinates outside of the
+     * range of a DDXPointRec component.
+     */
+    if (xright > MAX_COORDINATE)
+       xright = MAX_COORDINATE;
+    if (ybottom > MAX_COORDINATE)
+       ybottom = MAX_COORDINATE;
+
+    /* since we're clipping to the drawable's boundaries & coordinate
+     * space boundaries, we're guaranteed that the larger of width/height
+     * is the longest span we'll need to output
+     */
+    width = xright - xleft + 1;
+    height = ybottom - ytop + 1;
+    list_len = (height >= width) ? height : width;
+    pspanInit = (DDXPointPtr)ALLOCATE_LOCAL(list_len * sizeof(DDXPointRec));
+    pwidthInit = (int *)ALLOCATE_LOCAL(list_len * sizeof(int));
+    if (!pspanInit || !pwidthInit)
+       return;
+
+    Nspans = 0;
+    new_span = TRUE;
+    spans  = pspanInit - 1;
+    widths = pwidthInit - 1;
+    ppt = pptInit;
+
+    xstart = ppt->x;
+    ystart = ppt->y;
+    if (pGC->miTranslate)
+    {
+       xstart += pDraw->x;
+       ystart += pDraw->y;
+    }
+    
+    /* x2, y2, oc2 copied to x1, y1, oc1 at top of loop to simplify
+     * iteration logic
+     */
+    x2 = xstart;
+    y2 = ystart;
+    oc2 = 0;
+    MIOUTCODES(oc2, x2, y2, xleft, ytop, xright, ybottom);
+
+    while (--npt > 0)
+    {
+       if (Nspans > 0)
+           (*pGC->ops->FillSpans)(pDraw, pGC, Nspans, pspanInit,
+                                  pwidthInit, FALSE);
+       Nspans = 0;
+       new_span = TRUE;
+       spans  = pspanInit - 1;
+       widths = pwidthInit - 1;
+
+       x1  = x2;
+       y1  = y2;
+       oc1 = oc2;
+       ++ppt;
+
+       x2 = ppt->x;
+       y2 = ppt->y;
+       if (pGC->miTranslate && (mode != CoordModePrevious))
+       {
+           x2 += pDraw->x;
+           y2 += pDraw->y;
+       }
+       else if (mode == CoordModePrevious)
+       {
+           x2 += x1;
+           y2 += y1;
+       }
+
+       oc2 = 0;
+       MIOUTCODES(oc2, x2, y2, xleft, ytop, xright, ybottom);
+
+       CalcLineDeltas(x1, y1, x2, y2, adx, ady, signdx, signdy, 1, 1, octant);
+
+       if (adx > ady)
+       {
+           e1 = ady << 1;
+           e2 = e1 - (adx << 1);
+           e  = e1 - adx;
+           length  = adx;      /* don't draw endpoint in main loop */
+
+           FIXUP_ERROR(e, octant, bias);
+
+           new_x1 = x1;
+           new_y1 = y1;
+           new_x2 = x2;
+           new_y2 = y2;
+           pt1_clipped = 0;
+           pt2_clipped = 0;
+
+           if ((oc1 | oc2) != 0)
+           {
+               result = miZeroClipLine(xleft, ytop, xright, ybottom,
+                                       &new_x1, &new_y1, &new_x2, &new_y2,
+                                       adx, ady,
+                                       &pt1_clipped, &pt2_clipped,
+                                       octant, bias, oc1, oc2);
+               if (result == -1)
+                   continue;
+
+               length = abs(new_x2 - new_x1);
+
+               /* if we've clipped the endpoint, always draw the full length
+                * of the segment, because then the capstyle doesn't matter 
+                */
+               if (pt2_clipped)
+                   length++;
+
+               if (pt1_clipped)
+               {
+                   /* must calculate new error terms */
+                   clipdx = abs(new_x1 - x1);
+                   clipdy = abs(new_y1 - y1);
+                   e += (clipdy * e2) + ((clipdx - clipdy) * e1);
+               }
+           }
+
+           /* draw the segment */
+
+           x = new_x1;
+           y = new_y1;
+           
+           e3 = e2 - e1;
+           e  = e - e1;
+
+           while (length--)
+           {
+               MI_OUTPUT_POINT(x, y);
+               e += e1;
+               if (e >= 0)
+               {
+                   y += signdy;
+                   e += e3;
+               }
+               x += signdx;
+           }
+       }
+       else    /* Y major line */
+       {
+           e1 = adx << 1;
+           e2 = e1 - (ady << 1);
+           e  = e1 - ady;
+           length  = ady;      /* don't draw endpoint in main loop */
+
+           SetYMajorOctant(octant);
+           FIXUP_ERROR(e, octant, bias);
+
+           new_x1 = x1;
+           new_y1 = y1;
+           new_x2 = x2;
+           new_y2 = y2;
+           pt1_clipped = 0;
+           pt2_clipped = 0;
+
+           if ((oc1 | oc2) != 0)
+           {
+               result = miZeroClipLine(xleft, ytop, xright, ybottom,
+                                       &new_x1, &new_y1, &new_x2, &new_y2,
+                                       adx, ady,
+                                       &pt1_clipped, &pt2_clipped,
+                                       octant, bias, oc1, oc2);
+               if (result == -1)
+                   continue;
+
+               length = abs(new_y2 - new_y1);
+
+               /* if we've clipped the endpoint, always draw the full length
+                * of the segment, because then the capstyle doesn't matter 
+                */
+               if (pt2_clipped)
+                   length++;
+
+               if (pt1_clipped)
+               {
+                   /* must calculate new error terms */
+                   clipdx = abs(new_x1 - x1);
+                   clipdy = abs(new_y1 - y1);
+                   e += (clipdx * e2) + ((clipdy - clipdx) * e1);
+               }
+           }
+
+           /* draw the segment */
+
+           x = new_x1;
+           y = new_y1;
+
+           e3 = e2 - e1;
+           e  = e - e1;
+
+           while (length--)
+           {
+               MI_OUTPUT_POINT(x, y);
+               e += e1;
+               if (e >= 0)
+               {
+                   x += signdx;
+                   e += e3;
+               }
+               y += signdy;
+           }
+       }
+    }
+
+    /* only do the capnotlast check on the last segment
+     * and only if the endpoint wasn't clipped.  And then, if the last
+     * point is the same as the first point, do not draw it, unless the
+     * line is degenerate
+     */
+    if ( (! pt2_clipped) && (pGC->capStyle != CapNotLast) &&
+               (((xstart != x2) || (ystart != y2)) || (ppt == pptInit + 1)))
+    {
+       MI_OUTPUT_POINT(x, y);
+    }    
+
+    if (Nspans > 0)
+       (*pGC->ops->FillSpans)(pDraw, pGC, Nspans, pspanInit,
+                              pwidthInit, FALSE);
+
+    DEALLOCATE_LOCAL(pwidthInit);
+    DEALLOCATE_LOCAL(pspanInit);
+}
+
+void
+miZeroDashLine(dst, pgc, mode, nptInit, pptInit)
+DrawablePtr dst;
+GCPtr pgc;
+int mode;
+int nptInit;           /* number of points in polyline */
+DDXPointRec *pptInit;  /* points in the polyline */
+{
+    /* XXX kludge until real zero-width dash code is written */
+    pgc->lineWidth = 1;
+    miWideDash (dst, pgc, mode, nptInit, pptInit);
+    pgc->lineWidth = 0;
+}
diff --git a/Xserver/programs/Xserver/os/Imakefile b/Xserver/programs/Xserver/os/Imakefile
new file mode 100644 (file)
index 0000000..cec7922
--- /dev/null
@@ -0,0 +1,157 @@
+XCOMM $XConsortium: Imakefile /main/84 1996/12/15 21:26:59 rws $
+XCOMM $XFree86: xc/programs/Xserver/os/Imakefile,v 3.18.2.2 1998/02/21 06:07:15 robin Exp $
+#include <Server.tmpl>
+
+/*
+ * If you have any extra files to be put into the library, define them here.
+ */
+
+#ifdef HPArchitecture
+#define OtherSources hpsocket.c 
+#define OtherObjects hpsocket.o
+#endif
+
+#ifdef AmoebaArchitecture
+#define OtherSources iopreader.c
+#define OtherObjects iopreader.o
+#endif
+
+/*
+ * do not modify the following two definitions
+ */
+
+#ifndef OtherSources
+#define OtherSources
+#endif
+
+#ifndef OtherObjects
+#define OtherObjects
+#endif
+
+#if HasXdmAuth
+XDMAUTHDEFS = -DHASXDMAUTH
+XDMAUTHOBJS = xdmauth.o
+XDMAUTHSRCS = xdmauth.c
+#else
+XDMAUTHDEFS = 
+XDMAUTHOBJS =
+XDMAUTHSCRS =
+#endif
+
+#if HasSecureRPC
+RPCDEFS = -DSECURE_RPC
+RPCOBJS = rpcauth.o
+RPCSRCS = rpcauth.c
+#else
+RPCDEFS =
+RPCOBJS =
+RPCSRCS =
+#endif
+
+#if HasKrb5
+KRB5OBJS = k5auth.o k5encode.o
+KRB5SRCS = k5auth.c k5encode.c
+#endif
+
+#if HasBSD44Sockets
+   SOCK_DEFINES = -DBSD44SOCKETS
+#endif
+
+#if BuildLBX
+   LBX_SRCS = lbxio.c
+   LBX_OBJS = lbxio.o
+#else
+   LBX_SRCS =
+   LBX_OBJS =
+#endif
+
+BOOTSTRAPCFLAGS = 
+           SRCS = WaitFor.c access.c connection.c io.c oscolor.c \
+                  osinit.c utils.c auth.c mitauth.c secauth.c $(XDMAUTHSRCS) \
+                  $(RPCSRCS) $(KRB5SRCS) xdmcp.c decompress.c OtherSources \
+                  transport.c xalloc.c $(LBX_SRCS)
+           OBJS = WaitFor.o access.o connection.o io.o oscolor.o \
+                  osinit.o utils.o auth.o mitauth.o secauth.o $(XDMAUTHOBJS) \
+                  $(RPCOBJS) $(KRB5OBJS) xdmcp.o decompress.o OtherObjects \
+                  transport.o xalloc.o $(LBX_OBJS)
+
+#if SpecialMalloc
+     MEM_DEFINES = -DSPECIAL_MALLOC
+#endif /* SpecialMalloc */
+#if UseInternalMalloc
+     MEM_DEFINES = -DINTERNAL_MALLOC
+#endif
+#if UseMemLeak
+     MEM_DEFINES = -DMEMBUG
+#endif
+#if UseRgbTxt
+    RGB_DEFINES = -DUSE_RGB_TXT
+#endif
+    DBM_DEFINES = NdbmDefines
+    ADM_DEFINES = -DADMPATH=\"$(ADMDIR)/X\%smsgs\"
+    EXT_DEFINES = ExtensionDefines
+  XDMCP_DEFINES = ServerXdmcpDefines
+     OS_DEFINES = ServerOSDefines
+   KRB5_DEFINES = Krb5Defines
+        DEFINES = -DXSERV_t -DTRANS_SERVER ConnectionFlags $(MEM_DEFINES) $(XDMAUTHDEFS) $(RPCDEFS) $(SIGNAL_DEFINES) $(OS_DEFINES) $(KRB5_DEFINES) $(RGB_DEFINES)
+       INCLUDES = -I.  -I../include -I$(XINCLUDESRC) -I$(EXTINCSRC) -I$(TOP)/lib/Xau -I../lbx Krb5Includes
+ DEPEND_DEFINES = $(DBM_DEFINES) $(XDMCP_DEFINES) $(EXT_DEFINES) $(TRANS_INCLUDES) ConnectionFlags
+       LINTLIBS = ../dix/llib-ldix.ln
+
+#ifdef NEED_ALLOCA_FROM_LIBPW
+          PWLIB = /lib/libPW.a
+#endif /* NEED_ALLOCA_FROM_LIBPW */
+
+NormalLibraryObjectRule()
+NormalLibraryTarget(os,$(OBJS))
+LintLibraryTarget(os,$(SRCS))
+NormalLintTarget($(SRCS))
+
+#ifdef NEED_ALLOCA_FROM_LIBPW
+XCOMM
+XCOMM And this one is to get the version of alloca that lives in /lib/libPW.a
+XCOMM without getting all of the rest of the stuff in there.
+XCOMM
+alloca.o:  $(PWLIB)
+       rm -f alloca.o
+       ar x $(PWLIB) alloca.o
+#endif /* NEED_ALLOCA_FROM_LIBPW */
+
+SpecialCObjectRule(access,$(ICONFIGFILES),$(SOCK_DEFINES) $(XDMCP_DEFINES))
+SpecialCObjectRule(auth,$(ICONFIGFILES),$(XDMCP_DEFINES))
+SpecialCObjectRule(xdmauth,$(ICONFIGFILES),$(XDMCP_DEFINES))
+SpecialCObjectRule(xdmcp,$(ICONFIGFILES),$(SOCK_DEFINES) $(XDMCP_DEFINES))
+SpecialCObjectRule(connection,$(ICONFIGFILES),$(SOCK_DEFINES) $(XDMCP_DEFINES))
+SpecialCObjectRule(transport,$(ICONFIGFILES),$(TRANS_INCLUDES) $(CONN_DEFINES) $(SOCK_DEFINES))
+LinkSourceFile(transport.c,$(TRANSCOMMSRC))
+SpecialCObjectRule(osinit,$(ICONFIGFILES),$(ADM_DEFINES))
+SpecialCObjectRule(WaitFor,$(ICONFIGFILES),$(EXT_DEFINES))
+SpecialCObjectRule(io,$(ICONFIGFILES),$(EXT_DEFINES))
+#if BuildLBX
+SpecialCObjectRule(lbxio,$(ICONFIGFILES),$(EXT_DEFINES))
+#endif
+SpecialCObjectRule(utils,$(ICONFIGFILES),$(XDMCP_DEFINES) $(EXT_DEFINES))
+SpecialCObjectRule(xalloc,$(ICONFIGFILES),NullParameter)
+#if defined(SparcArchitecture) && HasGcc && !HasGcc2
+oscolor.o: oscolor.c $(ICONFIGFILES)
+       $(RM) $@
+       cc -c $(DBM_DEFINES) $(CDEBUGFLAGS) $(ALLDEFINES) $*.c
+#else
+SpecialCObjectRule(oscolor,$(ICONFIGFILES),$(DBM_DEFINES))
+#endif
+
+#if UseXserverWrapper
+AllTarget(wrapper.o)
+
+       WRAPPER_DEFINES = -DXSERVER_PATH=\"$(BINDIR)/X\"
+
+SpecialCObjectRule(wrapper,NullParameter,$(WRAPPER_DEFINES))
+#endif
+
+#if HasKrb5
+LinkSourceFile(k5encode.c,$(XAUTHSRC))
+#endif
+
+InstallLinkKitLibrary(os,$(LINKKITDIR)/lib)
+
+DependTarget()
diff --git a/Xserver/programs/Xserver/os/WaitFor.c b/Xserver/programs/Xserver/os/WaitFor.c
new file mode 100644 (file)
index 0000000..4210cfe
--- /dev/null
@@ -0,0 +1,788 @@
+/***********************************************************
+
+Copyright (c) 1987  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+
+Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
+
+                        All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and its 
+documentation for any purpose and without fee is hereby granted, 
+provided that the above copyright notice appear in all copies and that
+both that copyright notice and this permission notice appear in 
+supporting documentation, and that the name of Digital not be
+used in advertising or publicity pertaining to distribution of the
+software without specific, written prior permission.  
+
+DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
+ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
+DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
+ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+SOFTWARE.
+
+******************************************************************/
+
+/* $XConsortium: WaitFor.c /main/55 1996/12/02 10:22:24 lehors $ */
+/* $XFree86: xc/programs/Xserver/os/WaitFor.c,v 3.11.2.3 1998/01/31 14:23:33 hohndel Exp $ */
+
+/*****************************************************************
+ * OS Dependent input routines:
+ *
+ *  WaitForSomething
+ *  TimerForce, TimerSet, TimerCheck, TimerFree
+ *
+ *****************************************************************/
+
+#ifdef WIN32
+#include <X11/Xwinsock.h>
+#endif
+#include "Xos.h"                       /* for strings, fcntl, time */
+
+#include <errno.h>
+#ifdef X_NOT_STDC_ENV
+extern int errno;
+#endif
+
+#include <stdio.h>
+#include "X.h"
+#include "misc.h"
+
+#ifdef MINIX
+#include <sys/nbio.h>
+#define select(n,r,w,x,t) nbio_select(n,r,w,x,t)
+#endif
+#ifdef __EMX__
+#define select(n,r,w,x,t) os2PseudoSelect(n,r,w,x,t)
+#endif
+#include <X11/Xpoll.h>
+#include "osdep.h"
+#include "dixstruct.h"
+#include "opaque.h"
+
+#ifdef DPMSExtension
+#include "dpms.h"
+extern void DPMSSet();
+#endif
+
+extern fd_set AllSockets;
+extern fd_set AllClients;
+extern fd_set LastSelectMask;
+extern fd_set WellKnownConnections;
+extern fd_set EnabledDevices;
+extern fd_set ClientsWithInput;
+extern fd_set ClientsWriteBlocked;
+extern fd_set OutputPending;
+
+extern int ConnectionTranslation[];
+
+extern Bool NewOutputPending;
+extern Bool AnyClientsWriteBlocked;
+
+extern WorkQueuePtr workQueue;
+
+
+#ifdef XTESTEXT1
+/*
+ * defined in xtestext1dd.c
+ */
+extern int playback_on;
+#endif /* XTESTEXT1 */
+
+struct _OsTimerRec {
+    OsTimerPtr         next;
+    CARD32             expires;
+    OsTimerCallback    callback;
+    pointer            arg;
+};
+
+static void DoTimer();
+static OsTimerPtr timers;
+
+/*****************
+ * WaitForSomething:
+ *     Make the server suspend until there is
+ *     1. data from clients or
+ *     2. input events available or
+ *     3. ddx notices something of interest (graphics
+ *        queue ready, etc.) or
+ *     4. clients that have buffered replies/events are ready
+ *
+ *     If the time between INPUT events is
+ *     greater than ScreenSaverTime, the display is turned off (or
+ *     saved, depending on the hardware).  So, WaitForSomething()
+ *     has to handle this also (that's why the select() has a timeout.
+ *     For more info on ClientsWithInput, see ReadRequestFromClient().
+ *     pClientsReady is an array to store ready client->index values into.
+ *****************/
+
+static INT32 timeTilFrob = 0;          /* while screen saving */
+
+#if !defined(AMOEBA)
+
+int
+WaitForSomething(pClientsReady)
+    int *pClientsReady;
+{
+    int i;
+    struct timeval waittime, *wt;
+    INT32 timeout;
+#ifdef DPMSExtension
+    INT32 standbyTimeout, suspendTimeout, offTimeout;
+#endif
+    fd_set clientsReadable;
+    fd_set clientsWritable;
+    int curclient;
+    int selecterr;
+    int nready;
+    fd_set devicesReadable;
+    CARD32 now;
+
+    FD_ZERO(&clientsReadable);
+
+    /* We need a while loop here to handle 
+       crashed connections and the screen saver timeout */
+    while (1)
+    {
+       /* deal with any blocked jobs */
+       if (workQueue)
+           ProcessWorkQueue();
+
+       if (XFD_ANYSET (&ClientsWithInput))
+       {
+           XFD_COPYSET (&ClientsWithInput, &clientsReadable);
+           break;
+       }
+#ifdef DPMSExtension
+       if (ScreenSaverTime > 0 || DPMSEnabled || timers)
+#else
+       if (ScreenSaverTime > 0 || timers)
+#endif
+           now = GetTimeInMillis();
+       wt = NULL;
+       if (timers)
+       {
+           while (timers && timers->expires <= now)
+               DoTimer(timers, now, &timers);
+           if (timers)
+           {
+               timeout = timers->expires - now;
+               waittime.tv_sec = timeout / MILLI_PER_SECOND;
+               waittime.tv_usec = (timeout % MILLI_PER_SECOND) *
+                   (1000000 / MILLI_PER_SECOND);
+               wt = &waittime;
+           }
+       }
+#ifdef DPMSExtension
+       if (ScreenSaverTime > 0 ||
+           (DPMSEnabled &&
+            (DPMSStandbyTime > 0 || DPMSSuspendTime > 0 || DPMSOffTime > 0)))
+#else
+       if (ScreenSaverTime > 0)
+#endif
+       {
+#ifdef DPMSExtension
+
+           if (ScreenSaverTime > 0)
+               timeout = (ScreenSaverTime -
+                          (now - lastDeviceEventTime.milliseconds));
+           if (DPMSStandbyTime > 0)
+               standbyTimeout = (DPMSStandbyTime -
+                                 (now - lastDeviceEventTime.milliseconds));
+           if (DPMSSuspendTime > 0)
+               suspendTimeout = (DPMSSuspendTime -
+                                 (now - lastDeviceEventTime.milliseconds));
+           if (DPMSOffTime > 0)
+               offTimeout = (DPMSOffTime -
+                             (now - lastDeviceEventTime.milliseconds));
+#else
+           timeout = (ScreenSaverTime -
+                      (now - lastDeviceEventTime.milliseconds));
+#endif /* DPMSExtension */
+#ifdef DPMSExtension
+           if (timeout <= 0 && ScreenSaverTime > 0)
+#else
+           if (timeout <= 0) /* may be forced by AutoResetServer() */
+#endif /* DPMSExtension */
+           {
+               INT32 timeSinceSave;
+
+               timeSinceSave = -timeout;
+               if (timeSinceSave >= timeTilFrob && timeTilFrob >= 0)
+               {
+                   ResetOsBuffers(); /* not ideal, but better than nothing */
+                   SaveScreens(SCREEN_SAVER_ON, ScreenSaverActive);
+#ifdef DPMSExtension
+                   if (ScreenSaverInterval > 0 &&
+                       DPMSPowerLevel == DPMSModeOn)
+#else
+                   if (ScreenSaverInterval)
+#endif /* DPMSExtension */
+                       /* round up to the next ScreenSaverInterval */
+                       timeTilFrob = ScreenSaverInterval *
+                               ((timeSinceSave + ScreenSaverInterval) /
+                                       ScreenSaverInterval);
+                   else
+                       timeTilFrob = -1;
+               }
+               timeout = timeTilFrob - timeSinceSave;
+           }
+           else
+           {
+               if (ScreenSaverTime > 0 && timeout > ScreenSaverTime)
+                   timeout = ScreenSaverTime;
+               timeTilFrob = 0;
+           }
+#ifdef DPMSExtension
+           if (DPMSEnabled)
+           {
+               if (standbyTimeout > 0 
+                   && (timeout <= 0 || timeout > standbyTimeout))
+                   timeout = standbyTimeout;
+               if (suspendTimeout > 0 
+                   && (timeout <= 0 || timeout > suspendTimeout))
+                   timeout = suspendTimeout;
+               if (offTimeout > 0 
+                   && (timeout <= 0 || timeout > offTimeout))
+                   timeout = offTimeout;
+           }
+#endif
+           if (timeout > 0 && (!wt || timeout < (timers->expires - now)))
+           {
+               waittime.tv_sec = timeout / MILLI_PER_SECOND;
+               waittime.tv_usec = (timeout % MILLI_PER_SECOND) *
+                                       (1000000 / MILLI_PER_SECOND);
+               wt = &waittime;
+           }
+#ifdef DPMSExtension
+           /* don't bother unless it's switched on */
+           if (DPMSEnabled)
+           {
+               /*
+                * If this mode's enabled, and if the time's come
+                * and if we're still at a lesser mode, do it now.
+                */
+               if (DPMSStandbyTime > 0) {
+                   if (standbyTimeout <= 0) {
+                       if (DPMSPowerLevel < DPMSModeStandby) {
+                           DPMSSet(DPMSModeStandby);
+                       }
+                   }
+               }
+               /*
+                * and ditto.  Note that since these modes can have the
+                * same timeouts, they can happen at the same time.
+                */
+               if (DPMSSuspendTime > 0) {
+                   if (suspendTimeout <= 0) {
+                       if (DPMSPowerLevel < DPMSModeSuspend) {
+                           DPMSSet(DPMSModeSuspend);
+                       }
+                   }
+               }
+               if (DPMSOffTime > 0) {
+                   if (offTimeout <= 0) {
+                       if (DPMSPowerLevel < DPMSModeOff) {
+                           DPMSSet(DPMSModeOff);
+                       }
+                   }
+               }
+           }
+#endif
+       }
+       XFD_COPYSET(&AllSockets, &LastSelectMask);
+       BlockHandler((pointer)&wt, (pointer)&LastSelectMask);
+       if (NewOutputPending)
+           FlushAllOutput();
+#ifdef XTESTEXT1
+       /* XXX how does this interact with new write block handling? */
+       if (playback_on) {
+           wt = &waittime;
+           XTestComputeWaitTime (&waittime);
+       }
+#endif /* XTESTEXT1 */
+       /* keep this check close to select() call to minimize race */
+       if (dispatchException)
+           i = -1;
+       else if (AnyClientsWriteBlocked)
+       {
+           XFD_COPYSET(&ClientsWriteBlocked, &clientsWritable);
+           i = Select (MAXSOCKS, &LastSelectMask, &clientsWritable, NULL, wt);
+       }
+       else
+           i = Select (MAXSOCKS, &LastSelectMask, NULL, NULL, wt);
+       selecterr = errno;
+       WakeupHandler(i, (pointer)&LastSelectMask);
+#ifdef XTESTEXT1
+       if (playback_on) {
+           i = XTestProcessInputAction (i, &waittime);
+       }
+#endif /* XTESTEXT1 */
+       if (i <= 0) /* An error or timeout occurred */
+       {
+
+           if (dispatchException)
+               return 0;
+           FD_ZERO(&clientsWritable);
+           if (i < 0) 
+               if (selecterr == EBADF)    /* Some client disconnected */
+               {
+                   CheckConnections ();
+                   if (! XFD_ANYSET (&AllClients))
+                       return 0;
+               }
+               else if (selecterr == EINVAL)
+               {
+                   FatalError("WaitForSomething(): select: errno=%d\n",
+                       selecterr);
+               }
+               else if (selecterr != EINTR)
+               {
+                   ErrorF("WaitForSomething(): select: errno=%d\n",
+                       selecterr);
+               }
+           if (timers)
+           {
+               now = GetTimeInMillis();
+               while (timers && timers->expires <= now)
+                   DoTimer(timers, now, &timers);
+           }
+           if (*checkForInput[0] != *checkForInput[1])
+               return 0;
+       }
+       else
+       {
+#ifdef WIN32
+           fd_set tmp_set;
+#endif
+           if (AnyClientsWriteBlocked && XFD_ANYSET (&clientsWritable))
+           {
+               NewOutputPending = TRUE;
+               XFD_ORSET(&OutputPending, &clientsWritable, &OutputPending);
+               XFD_UNSET(&ClientsWriteBlocked, &clientsWritable);
+               if (! XFD_ANYSET(&ClientsWriteBlocked))
+                   AnyClientsWriteBlocked = FALSE;
+           }
+
+           XFD_ANDSET(&devicesReadable, &LastSelectMask, &EnabledDevices);
+           XFD_ANDSET(&clientsReadable, &LastSelectMask, &AllClients); 
+#ifndef WIN32
+           if (LastSelectMask.fds_bits[0] & WellKnownConnections.fds_bits[0]) 
+#else
+           XFD_ANDSET(&tmp_set, &LastSelectMask, &WellKnownConnections);
+           if (XFD_ANYSET(&tmp_set))
+#endif
+               QueueWorkProc(EstablishNewConnections, NULL,
+                             (pointer)&LastSelectMask);
+#ifdef DPMSExtension
+           if (XFD_ANYSET (&devicesReadable) && (DPMSPowerLevel != DPMSModeOn))
+               DPMSSet(DPMSModeOn);
+#endif
+           if (XFD_ANYSET (&devicesReadable) || XFD_ANYSET (&clientsReadable))
+               break;
+       }
+    }
+
+    nready = 0;
+    if (XFD_ANYSET (&clientsReadable))
+    {
+#ifndef WIN32
+       for (i=0; i<howmany(XFD_SETSIZE, NFDBITS); i++)
+       {
+           int highest_priority;
+
+           while (clientsReadable.fds_bits[i])
+           {
+               int client_priority, client_index;
+
+               curclient = ffs (clientsReadable.fds_bits[i]) - 1;
+               client_index = ConnectionTranslation[curclient + (i << 5)];
+#else
+       int highest_priority;
+       fd_set savedClientsReadable;
+       XFD_COPYSET(&clientsReadable, &savedClientsReadable);
+       for (i = 0; i < XFD_SETCOUNT(&savedClientsReadable); i++)
+       {
+           int client_priority, client_index;
+
+           curclient = XFD_FD(&savedClientsReadable, i);
+           client_index = ConnectionTranslation[curclient];
+#endif
+#ifdef XSYNC
+               /*  We implement "strict" priorities.
+                *  Only the highest priority client is returned to
+                *  dix.  If multiple clients at the same priority are
+                *  ready, they are all returned.  This means that an
+                *  aggressive client could take over the server.
+                *  This was not considered a big problem because
+                *  aggressive clients can hose the server in so many 
+                *  other ways :)
+                */
+               client_priority = clients[client_index]->priority;
+               if (nready == 0 || client_priority > highest_priority)
+               {
+                   /*  Either we found the first client, or we found
+                    *  a client whose priority is greater than all others
+                    *  that have been found so far.  Either way, we want 
+                    *  to initialize the list of clients to contain just
+                    *  this client.
+                    */
+                   pClientsReady[0] = client_index;
+                   highest_priority = client_priority;
+                   nready = 1;
+               }
+               /*  the following if makes sure that multiple same-priority 
+                *  clients get batched together
+                */
+               else if (client_priority == highest_priority)
+#endif
+               {
+                   pClientsReady[nready++] = client_index;
+               }
+#ifndef WIN32
+               clientsReadable.fds_bits[i] &= ~(((fd_mask)1) << curclient);
+           }
+#else
+           FD_CLR(curclient, &clientsReadable);
+#endif
+       }
+    }
+    return nready;
+}
+
+#if 0
+/*
+ * This is not always a macro.
+ */
+ANYSET(src)
+    FdMask     *src;
+{
+    int i;
+
+    for (i=0; i<mskcnt; i++)
+       if (src[ i ])
+           return (TRUE);
+    return (FALSE);
+}
+#endif
+
+#else /* AMOEBA */
+
+#define dbprintf(list)  /* printf list */
+
+int
+WaitForSomething(pClientsReady)
+    int                *pClientsReady;
+{
+    register int       i, wt, nt;
+    struct timeval     *wtp;
+    long               alwaysCheckForInput[2];
+    int                nready;
+    int                timeout;
+    unsigned long      now;
+
+    WakeupInitWaiters();
+
+    /* Be sure to check for input on every sweep in the dispatcher.
+     * This routine should be in InitInput, but since this is more
+     * or less a device dependent routine, and the semantics of it
+     * are device independent I decided to put it here.
+     */
+    alwaysCheckForInput[0] = 0;
+    alwaysCheckForInput[1] = 1;
+    SetInputCheck(&alwaysCheckForInput[0], &alwaysCheckForInput[1]);
+
+    while (1) {
+       /* deal with any blocked jobs */
+       if (workQueue)
+           ProcessWorkQueue();
+
+       if (ANYSET(ClientsWithInput)) {
+           FdSet clientsReadable;
+           int highest_priority;
+
+           COPYBITS(ClientsWithInput, clientsReadable);
+           dbprintf(("WaitFor: "));
+           nready = 0;
+           for (i=0; i < mskcnt; i++) {
+               while (clientsReadable[i]) {
+                   int client_priority, curclient, client_index;
+
+                   curclient = ffs (clientsReadable[i]) - 1;
+                   client_index = ConnectionTranslation[curclient + (i << 5)];
+                   dbprintf(("%d has input\n", curclient));
+#ifdef XSYNC
+                   client_priority = clients[client_index]->priority;
+                   if (nready == 0 || client_priority > highest_priority)
+                   {
+                       pClientsReady[0] = client_index;
+                       highest_priority = client_priority;
+                       nready = 1;
+                   }
+                   else if (client_priority == highest_priority)
+#endif
+                   {
+                       pClientsReady[nready++] = client_index;
+                   }
+                   clientsReadable[i] &= ~(((FdMask)1) << curclient);
+               }
+           }
+           break;
+       }       
+
+       wt = -1;
+       now = GetTimeInMillis();
+       if (timers)
+       {
+           while (timers && timers->expires <= now)
+               DoTimer(timers, now, &timers);
+           if (timers)
+           {
+               timeout = timers->expires - now;
+               wt = timeout;
+           }
+       }
+       if (ScreenSaverTime) {
+           timeout = ScreenSaverTime - TimeSinceLastInputEvent();
+           if (timeout <= 0) { /* may be forced by AutoResetServer() */
+               long timeSinceSave;
+
+               timeSinceSave = -timeout;
+               if ((timeSinceSave >= timeTilFrob) && (timeTilFrob >= 0)) {
+                   SaveScreens(SCREEN_SAVER_ON, ScreenSaverActive);
+                   if (ScreenSaverInterval)
+                       /* round up to the next ScreenSaverInterval */
+                       timeTilFrob = ScreenSaverInterval *
+                               ((timeSinceSave + ScreenSaverInterval) /
+                                       ScreenSaverInterval);
+                   else
+                       timeTilFrob = -1;
+               }
+               timeout = timeTilFrob - timeSinceSave;
+           } else {
+               if (timeout > ScreenSaverTime)
+                   timeout = ScreenSaverTime;
+               timeTilFrob = 0;
+           }
+           
+           if (wt < 0 || (timeTilFrob >= 0 && wt > timeout)) {
+               wt = timeout;
+           }
+       }
+
+       /* Check for new clients. We do this here and not in the listener
+        * threads because we cannot be sure that dix is re-entrant, and
+        * we need to call some dix routines during startup.
+        */
+       if (nNewConns) {
+           QueueWorkProc(EstablishNewConnections, NULL,
+                         (pointer) 0);
+       }
+
+       /* Call device dependent block handlers, which may want to
+        * specify a different timeout (e.g. used for key auto-repeat).
+        */
+       wtp = (struct timeval *) NULL;
+       BlockHandler((pointer)&wtp, (pointer)NULL);
+       if (wtp) wt = (wtp->tv_sec * 1000) + (wtp->tv_usec / 1000);
+
+       if (NewOutputPending)
+           FlushAllOutput();
+
+       /* TODO: XTESTEXT1 */
+
+       nready = AmFindReadyClients(pClientsReady, AllSockets);
+
+       /* If we found some work, or the iop server has us informed about
+        * new device events, we return.
+        */
+       if (nready || AmoebaEventsAvailable())
+           break;
+
+       if (dispatchException)
+           return 0;
+
+       /* Nothing interesting is available. Go to sleep with a timeout.
+        * The other threads will wake us when needed.
+        */
+       i = SleepMainThread(wt);
+
+       /* Wake up any of the sleeping handlers */
+       WakeupHandler((unsigned long)0, (pointer)NULL);
+
+       /* TODO: XTESTEXT1 */
+
+       if (dispatchException)
+           return 0;
+
+       if (i == -1) {
+           /* An error or timeout occurred */
+           return 0;
+       }
+    }
+
+    dbprintf(("WaitForSomething: %d clients ready\n", nready));
+    return nready;
+}
+
+#endif /* AMOEBA */
+
+
+static void
+DoTimer(timer, now, prev)
+    register OsTimerPtr timer;
+    CARD32 now;
+    OsTimerPtr *prev;
+{
+    CARD32 newTime;
+
+    *prev = timer->next;
+    timer->next = NULL;
+    newTime = (*timer->callback)(timer, now, timer->arg);
+    if (newTime)
+       TimerSet(timer, 0, newTime, timer->callback, timer->arg);
+}
+
+OsTimerPtr
+TimerSet(timer, flags, millis, func, arg)
+    register OsTimerPtr timer;
+    int flags;
+    CARD32 millis;
+    OsTimerCallback func;
+    pointer arg;
+{
+    register OsTimerPtr *prev;
+    CARD32 now = GetTimeInMillis();
+
+    if (!timer)
+    {
+       timer = (OsTimerPtr)xalloc(sizeof(struct _OsTimerRec));
+       if (!timer)
+           return NULL;
+    }
+    else
+    {
+       for (prev = &timers; *prev; prev = &(*prev)->next)
+       {
+           if (*prev == timer)
+           {
+               *prev = timer->next;
+               if (flags & TimerForceOld)
+                   (void)(*timer->callback)(timer, now, timer->arg);
+               break;
+           }
+       }
+    }
+    if (!millis)
+       return timer;
+    if (!(flags & TimerAbsolute))
+       millis += now;
+    timer->expires = millis;
+    timer->callback = func;
+    timer->arg = arg;
+    if (millis <= now)
+    {
+       timer->next = NULL;
+       millis = (*timer->callback)(timer, now, timer->arg);
+       if (!millis)
+           return timer;
+    }
+    for (prev = &timers;
+        *prev && millis > (*prev)->expires;
+        prev = &(*prev)->next)
+       ;
+    timer->next = *prev;
+    *prev = timer;
+    return timer;
+}
+
+Bool
+TimerForce(timer)
+    register OsTimerPtr timer;
+{
+    register OsTimerPtr *prev;
+    register CARD32 newTime;
+
+    for (prev = &timers; *prev; prev = &(*prev)->next)
+    {
+       if (*prev == timer)
+       {
+           DoTimer(timer, GetTimeInMillis(), prev);
+           return TRUE;
+       }
+    }
+    return FALSE;
+}
+
+
+void
+TimerCancel(timer)
+    register OsTimerPtr timer;
+{
+    register OsTimerPtr *prev;
+
+    if (!timer)
+       return;
+    for (prev = &timers; *prev; prev = &(*prev)->next)
+    {
+       if (*prev == timer)
+       {
+           *prev = timer->next;
+           break;
+       }
+    }
+}
+
+void
+TimerFree(timer)
+    register OsTimerPtr timer;
+{
+    if (!timer)
+       return;
+    TimerCancel(timer);
+    xfree(timer);
+}
+
+void
+TimerCheck()
+{
+    register CARD32 now = GetTimeInMillis();
+
+    while (timers && timers->expires <= now)
+       DoTimer(timers, now, &timers);
+}
+
+void
+TimerInit()
+{
+    OsTimerPtr timer;
+
+    while (timer = timers)
+    {
+       timers = timer->next;
+       xfree(timer);
+    }
+}
diff --git a/Xserver/programs/Xserver/os/access.c b/Xserver/programs/Xserver/os/access.c
new file mode 100644 (file)
index 0000000..05b6b86
--- /dev/null
@@ -0,0 +1,1398 @@
+/* $XConsortium: access.c /main/68 1996/12/15 22:57:09 rws $ */
+/* $XFree86: xc/programs/Xserver/os/access.c,v 3.18.2.4 1998/02/21 06:07:16 robin Exp $ */
+/***********************************************************
+
+Copyright (c) 1987  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+
+Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
+
+                        All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and its 
+documentation for any purpose and without fee is hereby granted, 
+provided that the above copyright notice appear in all copies and that
+both that copyright notice and this permission notice appear in 
+supporting documentation, and that the name of Digital not be
+used in advertising or publicity pertaining to distribution of the
+software without specific, written prior permission.  
+
+DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
+ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
+DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
+ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+SOFTWARE.
+
+******************************************************************/
+
+#ifdef WIN32
+#include <X11/Xwinsock.h>
+#endif
+
+#include <stdio.h>
+#include <X11/Xtrans.h>
+#include <X11/Xauth.h>
+#include "X.h"
+#include "Xproto.h"
+#include "misc.h"
+#include "site.h"
+#include <errno.h>
+#include <sys/types.h>
+#ifndef WIN32
+#if !defined(AMOEBA) && !defined(MINIX)
+#ifdef ESIX
+#include <lan/socket.h>
+#else
+#ifndef Lynx
+#include <sys/socket.h>
+#else
+#include <socket.h>
+#endif
+#endif
+#include <sys/ioctl.h>
+#else
+#ifdef AMOEBA
+#define port am_port_t
+#include <amoeba.h>
+#include <cmdreg.h>
+#include <stdcom.h>
+#include <stderr.h>
+#include <ampolicy.h>
+#include <server/ip/hton.h>
+#include <server/ip/types.h>
+#include <server/ip/tcpip.h>
+#include <server/ip/tcp_io.h>
+#include <server/ip/gen/in.h>
+#include <server/ip/gen/tcp.h>
+#include <server/ip/gen/tcp_io.h>
+#include <server/ip/gen/socket.h>
+#undef port
+#endif
+#endif /* AMOEBA || MINIX */
+#include <ctype.h>
+
+#if defined(TCPCONN) || defined(STREAMSCONN) || defined(ISC) || defined(SCO)
+#include <netinet/in.h>
+#endif /* TCPCONN || STREAMSCONN || ISC || SCO */
+#ifdef DNETCONN
+#include <netdnet/dn.h>
+#include <netdnet/dnetdb.h>
+#endif
+
+#if !defined(AMOEBA)
+#ifdef hpux
+# include <sys/utsname.h>
+# ifdef HAS_IFREQ
+#  include <net/if.h>
+# endif
+#else
+#if defined(SVR4) ||  (defined(SYSV) && defined(i386)) || defined(MINIX)
+# include <sys/utsname.h>
+#endif
+#if defined(SYSV) &&  defined(i386)
+# include <sys/stream.h>
+# ifdef ISC
+#  include <sys/stropts.h>
+#  include <sys/sioctl.h>
+# endif /* ISC */
+#endif
+#ifdef ESIX
+# include <lan/if.h>
+#else
+#ifndef MINIX
+# include <net/if.h>
+#endif
+#endif
+#endif /* hpux */
+#endif /* !AMOEBA */
+
+#ifdef SVR4
+#ifndef SCO
+#include <sys/sockio.h>
+#endif
+#include <sys/stropts.h>
+#endif
+
+#ifdef ESIX
+#include <lan/netdb.h>
+#else
+#if !defined(AMOEBA) && !defined(MINIX)
+#include <netdb.h>
+#else
+#ifdef AMOEBA
+#include <server/ip/gen/netdb.h>
+#endif
+#ifdef MINIX
+#include <net/hton.h>
+#include <net/gen/netdb.h>
+#define INADDR_BROADCAST 0xFFFFFFFF
+#endif
+#endif /* AMOEBA || MINIX */
+#endif /* ESIX */
+
+#ifdef CSRG_BASED
+#include <sys/param.h>
+#if (BSD >= 199103)
+#define VARIABLE_IFREQ
+#endif
+#endif
+
+#if defined(Lynx) && defined(BSD44SOCKETS)
+#define VARIABLE_IFREQ
+#endif
+
+#endif /* WIN32 */
+
+#ifndef PATH_MAX
+#ifndef Lynx
+#include <sys/param.h>
+#else
+#include <param.h>
+#endif 
+#ifndef PATH_MAX
+#ifdef MAXPATHLEN
+#define PATH_MAX MAXPATHLEN
+#else
+#define PATH_MAX 1024
+#endif
+#endif
+#endif 
+
+#include "dixstruct.h"
+#include "osdep.h"
+
+#ifdef XCSECURITY
+#define _SECURITY_SERVER
+#include "extensions/security.h"
+#endif
+
+Bool defeatAccessControl = FALSE;
+
+#define acmp(a1, a2, len) memcmp((char *)(a1), (char *)(a2), len)
+#define acopy(a1, a2, len) memmove((char *)(a2), (char *)(a1), len)
+#define addrEqual(fam, address, length, host) \
+                        ((fam) == (host)->family &&\
+                         (length) == (host)->len &&\
+                         !acmp (address, (host)->addr, length))
+
+static int ConvertAddr(
+#if NeedFunctionPrototypes
+    struct sockaddr */*saddr*/,
+    int */*len*/,
+    pointer */*addr*/
+#endif
+);
+
+static int CheckAddr(
+#if NeedFunctionPrototypes
+    int /*family*/,
+    pointer /*pAddr*/,
+    unsigned /*length*/
+#endif
+);
+
+static Bool NewHost(
+#if NeedFunctionPrototypes
+    int /*family*/,
+    pointer /*addr*/,
+    int /*len*/
+#endif
+);
+
+typedef struct _host {
+       short           family;
+       short           len;
+       unsigned char   *addr;
+       struct _host *next;
+} HOST;
+
+#define MakeHost(h,l)  (h)=(HOST *) xalloc(sizeof *(h)+(l));\
+                       (h)->addr=(unsigned char *) ((h) + 1);
+#define FreeHost(h)    xfree(h)
+static HOST *selfhosts = NULL;
+static HOST *validhosts = NULL;
+static int AccessEnabled = DEFAULT_ACCESS_CONTROL;
+static int LocalHostEnabled = FALSE;
+static int UsingXdmcp = FALSE;
+
+
+/*
+ * called when authorization is not enabled to add the
+ * local host to the access list
+ */
+
+void
+EnableLocalHost ()
+{
+    if (!UsingXdmcp)
+    {
+       LocalHostEnabled = TRUE;
+       AddLocalHosts ();
+    }
+}
+
+/*
+ * called when authorization is enabled to keep us secure
+ */
+void
+DisableLocalHost ()
+{
+    HOST *self;
+
+    LocalHostEnabled = FALSE;
+    for (self = selfhosts; self; self = self->next)
+       (void) RemoveHost ((ClientPtr)NULL, self->family, self->len, (pointer)self->addr);
+}
+
+/*
+ * called at init time when XDMCP will be used; xdmcp always
+ * adds local hosts manually when needed
+ */
+
+void
+AccessUsingXdmcp ()
+{
+    UsingXdmcp = TRUE;
+    LocalHostEnabled = FALSE;
+}
+
+
+#if ((defined(SVR4) && !defined(SCO325) && !defined(sun) && !defined(NCR)) || defined(ISC)) && defined(SIOCGIFCONF)
+
+/* Deal with different SIOCGIFCONF ioctl semantics on these OSs */
+
+static int
+ifioctl (fd, cmd, arg)
+    int fd;
+    int cmd;
+    char *arg;
+{
+    struct strioctl ioc;
+    int ret;
+
+    bzero((char *) &ioc, sizeof(ioc));
+    ioc.ic_cmd = cmd;
+    ioc.ic_timout = 0;
+    if (cmd == SIOCGIFCONF)
+    {
+       ioc.ic_len = ((struct ifconf *) arg)->ifc_len;
+       ioc.ic_dp = ((struct ifconf *) arg)->ifc_buf;
+#ifdef ISC
+       /* SIOCGIFCONF is somewhat brain damaged on ISC. The argument
+        * buffer must contain the ifconf structure as header. Ifc_req
+        * is also not a pointer but a one element array of ifreq
+        * structures. On return this array is extended by enough
+        * ifreq fields to hold all interfaces. The return buffer length
+        * is placed in the buffer header.
+        */
+        ((struct ifconf *) ioc.ic_dp)->ifc_len =
+                                         ioc.ic_len - sizeof(struct ifconf);
+#endif
+    }
+    else
+    {
+       ioc.ic_len = sizeof(struct ifreq);
+       ioc.ic_dp = arg;
+    }
+    ret = ioctl(fd, I_STR, (char *) &ioc);
+    if (ret >= 0 && cmd == SIOCGIFCONF)
+#ifdef SVR4
+       ((struct ifconf *) arg)->ifc_len = ioc.ic_len;
+#endif
+#ifdef ISC
+    {
+       ((struct ifconf *) arg)->ifc_len =
+                                ((struct ifconf *)ioc.ic_dp)->ifc_len;
+       ((struct ifconf *) arg)->ifc_buf = 
+                       (caddr_t)((struct ifconf *)ioc.ic_dp)->ifc_req;
+    }
+#endif
+    return(ret);
+}
+#else /* ((SVR4 && !sun) || ISC) && SIOCGIFCONF */
+#define ifioctl ioctl
+#endif /* ((SVR4 && !sun) || ISC) && SIOCGIFCONF */
+
+/*
+ * DefineSelf (fd):
+ *
+ * Define this host for access control.  Find all the hosts the OS knows about 
+ * for this fd and add them to the selfhosts list.
+ */
+
+#ifdef WINTCP /* NCR Wollongong based TCP */
+
+#include <sys/un.h>
+#include <stropts.h>
+#include <tiuser.h>
+
+#include <sys/stream.h>
+#include <net/if.h>
+#include <netinet/ip.h>
+#include <netinet/ip_var.h>
+#include <netinet/in.h>
+#include <netinet/in_var.h>
+
+void
+DefineSelf (fd)
+    int fd;
+{
+    /*
+     * The Wolongong drivers used by NCR SVR4/MP-RAS don't understand the
+     * socket IO calls that most other drivers seem to like. Because of
+     * this, this routine must be special cased for NCR. Eventually,
+     * this will be cleared up.
+     */
+
+    struct ipb ifnet;
+    struct in_ifaddr ifaddr;
+    struct strioctl str;
+    unsigned char *addr;
+    register HOST *host;
+    int        family, len;
+
+    if ((fd = open ("/dev/ip", O_RDWR, 0 )) < 0)
+        Error ("Getting interface configuration (1)");
+
+    /* Indicate that we want to start at the begining */
+    ifnet.ib_next = (struct ipb *) 1;
+
+    while (ifnet.ib_next)
+    {
+       str.ic_cmd = IPIOC_GETIPB;
+       str.ic_timout = 0;
+       str.ic_len = sizeof (struct ipb);
+       str.ic_dp = (char *) &ifnet;
+
+       if (ioctl (fd, (int) I_STR, (char *) &str) < 0)
+       {
+           close (fd);
+           Error ("Getting interface configuration (2)");
+       }
+
+       ifaddr.ia_next = (struct in_ifaddr *) ifnet.if_addrlist;
+       str.ic_cmd = IPIOC_GETINADDR;
+       str.ic_timout = 0;
+       str.ic_len = sizeof (struct in_ifaddr);
+       str.ic_dp = (char *) &ifaddr;
+
+       if (ioctl (fd, (int) I_STR, (char *) &str) < 0)
+       {
+           close (fd);
+           Error ("Getting interface configuration (3)");
+       }
+
+       len = sizeof(struct sockaddr_in);
+       family = ConvertAddr (IA_SIN(&ifaddr), &len, (pointer *)&addr);
+        if (family == -1 || family == FamilyLocal)
+           continue;
+        for (host = selfhosts;
+            host && !addrEqual (family, addr, len, host);
+            host = host->next)
+           ;
+        if (host)
+           continue;
+       MakeHost(host,len)
+       if (host)
+       {
+           host->family = family;
+           host->len = len;
+           acopy(addr, host->addr, len);
+           host->next = selfhosts;
+           selfhosts = host;
+       }
+#ifdef XDMCP
+        {
+           struct sockaddr broad_addr;
+
+           /*
+            * If this isn't an Internet Address, don't register it.
+            */
+           if (family != FamilyInternet)
+               continue;
+
+           /*
+            * ignore 'localhost' entries as they're not useful
+            * on the other end of the wire
+            */
+           if (len == 4 &&
+               addr[0] == 127 && addr[1] == 0 &&
+               addr[2] == 0 && addr[3] == 1)
+               continue;
+
+           XdmcpRegisterConnection (family, (char *)addr, len);
+
+
+#define IA_BROADADDR(ia) ((struct sockaddr_in *)(&((struct in_ifaddr *)ia)->ia_broadaddr))
+
+           XdmcpRegisterBroadcastAddress (
+               (struct sockaddr_in *) IA_BROADADDR(&ifaddr));
+
+#undef IA_BROADADDR
+       }
+#endif /* XDMCP */
+    }
+
+    close(fd);
+
+    /*
+     * add something of FamilyLocalHost
+     */
+    for (host = selfhosts;
+        host && !addrEqual(FamilyLocalHost, "", 0, host);
+        host = host->next);
+    if (!host)
+    {
+       MakeHost(host, 0);
+       if (host)
+       {
+           host->family = FamilyLocalHost;
+           host->len = 0;
+           acopy("", host->addr, 0);
+           host->next = selfhosts;
+           selfhosts = host;
+       }
+    }
+}
+
+#else /* WINTCP */
+
+#if !defined(SIOCGIFCONF) || (defined (hpux) && ! defined (HAS_IFREQ))
+void
+DefineSelf (fd)
+    int fd;
+{
+#if !defined(TCPCONN) && !defined(STREAMSCONN) && !defined(UNIXCONN) && !defined(MNX_TCPCONN)
+    return;
+#else
+    register int n;
+    int        len;
+    caddr_t    addr;
+    int                family;
+    register HOST      *host;
+
+    struct utsname name;
+    register struct hostent  *hp;
+
+    union {
+       struct  sockaddr   sa;
+       struct  sockaddr_in  in;
+    } saddr;
+       
+    struct     sockaddr_in     *inetaddr;
+    struct sockaddr_in broad_addr;
+
+    /* Why not use gethostname()?  Well, at least on my system, I've had to
+     * make an ugly kernel patch to get a name longer than 8 characters, and
+     * uname() lets me access to the whole string (it smashes release, you
+     * see), whereas gethostname() kindly truncates it for me.
+     */
+    uname(&name);
+    hp = gethostbyname (name.nodename);
+    if (hp != NULL)
+    {
+       saddr.sa.sa_family = hp->h_addrtype;
+       inetaddr = (struct sockaddr_in *) (&(saddr.sa));
+       acopy ( hp->h_addr, &(inetaddr->sin_addr), hp->h_length);
+       len = sizeof(saddr.sa);
+       family = ConvertAddr ( &(saddr.sa), &len, (pointer *)&addr);
+       if ( family != -1 && family != FamilyLocal )
+       {
+           for (host = selfhosts;
+                host && !addrEqual (family, addr, len, host);
+                host = host->next) ;
+           if (!host)
+           {
+               /* add this host to the host list.      */
+               MakeHost(host,len)
+               if (host)
+               {
+                   host->family = family;
+                   host->len = len;
+                   acopy ( addr, host->addr, len);
+                   host->next = selfhosts;
+                   selfhosts = host;
+               }
+#ifdef XDMCP
+               /*
+                *  If this is an Internet Address, but not the localhost
+                *  address (127.0.0.1), register it.
+                */
+               if (family == FamilyInternet &&
+                   !(len == 4 && addr[0] == 127 && addr[1] == 0 &&
+                     addr[2] == 0 && addr[3] == 1)
+                  )
+               {
+                   XdmcpRegisterConnection (family, (char *)addr, len);
+                   broad_addr = *inetaddr;
+                   ((struct sockaddr_in *) &broad_addr)->sin_addr.s_addr =
+                       htonl (INADDR_BROADCAST);
+                   XdmcpRegisterBroadcastAddress ((struct sockaddr_in *)
+                                                  &broad_addr);
+               }
+#endif /* XDMCP */
+           }
+       }
+    }
+    /*
+     * now add a host of family FamilyLocalHost...
+     */
+    for (host = selfhosts;
+        host && !addrEqual(FamilyLocalHost, "", 0, host);
+        host = host->next);
+    if (!host)
+    {
+       MakeHost(host, 0);
+       if (host)
+       {
+           host->family = FamilyLocalHost;
+           host->len = 0;
+           acopy("", host->addr, 0);
+           host->next = selfhosts;
+           selfhosts = host;
+       }
+    }
+#endif /* !TCPCONN && !STREAMSCONN && !UNIXCONN && !MNX_TCPCONN */
+}
+
+#else
+
+#ifdef VARIABLE_IFREQ
+#define ifr_size(p) (sizeof (struct ifreq) + \
+                    (p->ifr_addr.sa_len > sizeof (p->ifr_addr) ? \
+                     p->ifr_addr.sa_len - sizeof (p->ifr_addr) : 0))
+#define ifraddr_size(a) (a.sa_len)
+#else
+#define ifr_size(p) (sizeof (struct ifreq))
+#define ifraddr_size(a) (sizeof (a))
+#endif
+
+void
+DefineSelf (fd)
+    int fd;
+{
+    char               buf[2048], *cp, *cplim;
+    struct ifconf      ifc;
+    register int       n;
+    int                len;
+    unsigned char *    addr;
+    int                family;
+    register HOST      *host;
+    register struct ifreq *ifr;
+    
+#ifdef DNETCONN
+    struct dn_naddr *dnaddr = getnodeadd();
+    /*
+     * AF_DECnet may not be listed in the interface list.  Instead use
+     * the supported library call to find out the local address (if any).
+     */
+    if (dnaddr)
+    {    
+       addr = (unsigned char *) dnaddr;
+       len = dnaddr->a_len + sizeof(dnaddr->a_len);
+       family = FamilyDECnet;
+       for (host = selfhosts;
+            host && !addrEqual (family, addr, len, host);
+            host = host->next)
+           ;
+        if (!host)
+       {
+           MakeHost(host,len)
+           if (host)
+           {
+               host->family = family;
+               host->len = len;
+               acopy(addr, host->addr, len);
+               host->next = selfhosts;
+               selfhosts = host;
+           }
+       }
+    }
+#endif
+    ifc.ifc_len = sizeof (buf);
+    ifc.ifc_buf = buf;
+    if (ifioctl (fd, (int) SIOCGIFCONF, (pointer) &ifc) < 0)
+        Error ("Getting interface configuration (4)");
+
+#ifdef ISC
+#define IFC_IFC_REQ (struct ifreq *) ifc.ifc_buf
+#else
+#define IFC_IFC_REQ ifc.ifc_req
+#endif
+
+    cplim = (char *) IFC_IFC_REQ + ifc.ifc_len;
+    
+    for (cp = (char *) IFC_IFC_REQ; cp < cplim; cp += ifr_size (ifr))
+    {
+       ifr = (struct ifreq *) cp;
+       len = ifraddr_size (ifr->ifr_addr);
+#ifdef DNETCONN
+       /*
+        * DECnet was handled up above.
+        */
+       if (ifr->ifr_addr.sa_family == AF_DECnet)
+           continue;
+#endif /* DNETCONN */
+       family = ConvertAddr (&ifr->ifr_addr, &len, (pointer *)&addr);
+        if (family == -1 || family == FamilyLocal)
+           continue;
+#ifdef DEF_SELF_DEBUG
+       if (family == FamilyInternet) 
+           ErrorF("Xserver: DefineSelf(): ifname = %s, addr = %d.%d.%d.%d\n",
+                  ifr->ifr_name, addr[0], addr[1], addr[2], addr[3]);
+#endif
+        for (host = selfhosts;
+            host && !addrEqual (family, addr, len, host);
+            host = host->next)
+           ;
+        if (host)
+           continue;
+       MakeHost(host,len)
+       if (host)
+       {
+           host->family = family;
+           host->len = len;
+           acopy(addr, host->addr, len);
+           host->next = selfhosts;
+           selfhosts = host;
+       }
+#ifdef XDMCP
+       {
+           struct sockaddr broad_addr;
+
+           /*
+            * If this isn't an Internet Address, don't register it.
+            */
+           if (family != FamilyInternet)
+               continue;
+
+           /*
+            * ignore 'localhost' entries as they're not useful
+            * on the other end of the wire
+            */
+           if (len == 4 &&
+               addr[0] == 127 && addr[1] == 0 &&
+               addr[2] == 0 && addr[3] == 1)
+               continue;
+
+           XdmcpRegisterConnection (family, (char *)addr, len);
+           broad_addr = ifr->ifr_addr;
+           ((struct sockaddr_in *) &broad_addr)->sin_addr.s_addr =
+               htonl (INADDR_BROADCAST);
+#ifdef SIOCGIFBRDADDR
+           {
+               struct ifreq    broad_req;
+    
+               broad_req = *ifr;
+               if (ifioctl (fd, SIOCGIFFLAGS, (char *) &broad_req) != -1 &&
+                   (broad_req.ifr_flags & IFF_BROADCAST) &&
+                   (broad_req.ifr_flags & IFF_UP)
+                   )
+               {
+                   broad_req = *ifr;
+                   if (ifioctl (fd, SIOCGIFBRDADDR, &broad_req) != -1)
+                       broad_addr = broad_req.ifr_addr;
+                   else
+                       continue;
+               }
+               else
+                   continue;
+           }
+#endif
+#ifdef DEF_SELF_DEBUG
+           ErrorF("Xserver: DefineSelf(): ifname = %s, baddr = %s\n",
+                  ifr->ifr_name,
+                  inet_ntoa(((struct sockaddr_in *) &broad_addr)->sin_addr));
+#endif
+           XdmcpRegisterBroadcastAddress ((struct sockaddr_in *) &broad_addr);
+       }
+#endif
+    }
+    /*
+     * add something of FamilyLocalHost
+     */
+    for (host = selfhosts;
+        host && !addrEqual(FamilyLocalHost, "", 0, host);
+        host = host->next);
+    if (!host)
+    {
+       MakeHost(host, 0);
+       if (host)
+       {
+           host->family = FamilyLocalHost;
+           host->len = 0;
+           acopy("", host->addr, 0);
+           host->next = selfhosts;
+           selfhosts = host;
+       }
+    }
+}
+#endif /* hpux && !HAS_IFREQ */
+#endif /* WINTCP */
+
+#ifdef XDMCP
+void
+AugmentSelf(from, len)
+    pointer from;
+    int            len;
+{
+    int family;
+    pointer addr;
+    register HOST *host;
+
+    family = ConvertAddr(from, &len, (pointer *)&addr);
+    if (family == -1 || family == FamilyLocal)
+       return;
+    for (host = selfhosts; host; host = host->next)
+    {
+       if (addrEqual(family, addr, len, host))
+           return;
+    }
+    MakeHost(host,len)
+    if (!host)
+       return;
+    host->family = family;
+    host->len = len;
+    acopy(addr, host->addr, len);
+    host->next = selfhosts;
+    selfhosts = host;
+}
+#endif
+
+void
+AddLocalHosts ()
+{
+    HOST    *self;
+
+    for (self = selfhosts; self; self = self->next)
+       (void) NewHost (self->family, self->addr, self->len);
+}
+
+/* Reset access control list to initial hosts */
+void
+ResetHosts (display)
+    char *display;
+{
+    register HOST      *host;
+    char                lhostname[120], ohostname[120];
+    char               *hostname = ohostname;
+    char               fname[PATH_MAX + 1];
+    int                        fnamelen;
+    FILE               *fd;
+    char               *ptr;
+    int                 i, hostlen;
+#ifndef AMOEBA
+    union {
+        struct sockaddr        sa;
+#if defined(TCPCONN) || defined(STREAMSCONN) || defined(MNX_TCPCONN)
+        struct sockaddr_in in;
+#endif /* TCPCONN || STREAMSCONN */
+#ifdef DNETCONN
+        struct sockaddr_dn dn;
+#endif
+    }                  saddr;
+#endif /* AMOEBA */
+#ifdef DNETCONN
+    struct nodeent     *np;
+    struct dn_naddr    dnaddr, *dnaddrp, *dnet_addr();
+#endif
+#ifdef K5AUTH
+    krb5_principal      princ;
+    krb5_data          kbuf;
+#endif
+    int                        family;
+    pointer            addr;
+    int                len;
+    register struct hostent *hp;
+
+    AccessEnabled = defeatAccessControl ? FALSE : DEFAULT_ACCESS_CONTROL;
+    LocalHostEnabled = FALSE;
+    while (host = validhosts)
+    {
+        validhosts = host->next;
+        FreeHost (host);
+    }
+#ifndef __EMX__
+#define ETC_HOST_PREFIX "/etc/X"
+#define ETC_HOST_SUFFIX ".hosts"
+#else
+#define ETC_HOST_PREFIX "/XFree86/lib/X11/X"
+#define ETC_HOST_SUFFIX ".hosts"
+#endif /* __EMX__ */
+    fnamelen = strlen(ETC_HOST_PREFIX) + strlen(ETC_HOST_SUFFIX) +
+               strlen(display) + 1;
+    if (fnamelen > sizeof(fname))
+       FatalError("Display name `%s' is too long\n");
+    sprintf(fname, ETC_HOST_PREFIX "%s" ETC_HOST_SUFFIX, display);
+#ifdef __EMX__
+    strcpy(fname, (char*)__XOS2RedirRoot(fname));
+#endif /* __EMX__ */
+
+    if (fd = fopen (fname, "r")) 
+    {
+        while (fgets (ohostname, sizeof (ohostname), fd))
+       {
+       if (*ohostname == '#')
+           continue;
+       if (ptr = strchr(ohostname, '\n'))
+           *ptr = 0;
+#ifdef __EMX__
+       if (ptr = strchr(ohostname, '\r'))
+           *ptr = 0;
+#endif
+        hostlen = strlen(ohostname) + 1;
+        for (i = 0; i < hostlen; i++)
+           lhostname[i] = tolower(ohostname[i]);
+       hostname = ohostname;
+       if (!strncmp("local:", lhostname, 6))
+       {
+           family = FamilyLocalHost;
+           NewHost(family, "", 0);
+       }
+#if defined(TCPCONN) || defined(STREAMSCONN) || defined(MNX_TCPCONN)
+       else if (!strncmp("inet:", lhostname, 5))
+       {
+           family = FamilyInternet;
+           hostname = ohostname + 5;
+       }
+#endif
+#ifdef DNETCONN
+       else if (!strncmp("dnet:", lhostname, 5))
+       {
+           family = FamilyDECnet;
+           hostname = ohostname + 5;
+       }
+#endif
+#ifdef SECURE_RPC
+       else if (!strncmp("nis:", lhostname, 4))
+       {
+           family = FamilyNetname;
+           hostname = ohostname + 4;
+       }
+#endif
+#ifdef K5AUTH
+       else if (!strncmp("krb:", lhostname, 4))
+       {
+           family = FamilyKrb5Principal;
+           hostname = ohostname + 4;
+       }
+#endif
+#ifdef DNETCONN
+       if ((family == FamilyDECnet) ||
+           (ptr = strchr(hostname, ':')) && (*(ptr + 1) == ':') &&
+           !(*ptr = '\0'))     /* bash trailing colons if necessary */
+       {
+           /* node name (DECnet names end in "::") */
+           dnaddrp = dnet_addr(hostname);
+           if (!dnaddrp && (np = getnodebyname (hostname)))
+           {
+               /* node was specified by name */
+               saddr.sa.sa_family = np->n_addrtype;
+               len = sizeof(saddr.sa);
+               if (ConvertAddr (&saddr.sa, &len, (pointer *)&addr) == FamilyDECnet)
+               {
+                   bzero ((char *) &dnaddr, sizeof (dnaddr));
+                   dnaddr.a_len = np->n_length;
+                   acopy (np->n_addr, dnaddr.a_addr, np->n_length);
+                   dnaddrp = &dnaddr;
+               }
+           }
+           if (dnaddrp)
+               (void) NewHost(FamilyDECnet, (pointer)dnaddrp,
+                       (int)(dnaddrp->a_len + sizeof(dnaddrp->a_len)));
+       }
+       else
+#endif /* DNETCONN */
+#ifdef K5AUTH
+       if (family == FamilyKrb5Principal)
+       {
+            krb5_parse_name(hostname, &princ);
+           XauKrb5Encode(princ, &kbuf);
+           (void) NewHost(FamilyKrb5Principal, kbuf.data, kbuf.length);
+           krb5_free_principal(princ);
+        }
+       else
+#endif
+#ifdef SECURE_RPC
+       if ((family == FamilyNetname) || (strchr(hostname, '@')))
+       {
+           SecureRPCInit ();
+           (void) NewHost (FamilyNetname, hostname, strlen (hostname));
+       }
+       else
+#endif /* SECURE_RPC */
+#if defined(TCPCONN) || defined(STREAMSCONN) || defined(MNX_TCPCONN)
+       {
+           /* host name */
+           if (family == FamilyInternet && (hp = gethostbyname (hostname)) ||
+                (hp = gethostbyname (hostname)))
+           {
+               saddr.sa.sa_family = hp->h_addrtype;
+               len = sizeof(saddr.sa);
+               if ((family = ConvertAddr (&saddr.sa, &len, (pointer *)&addr)) != -1)
+               {
+#ifdef h_addr                          /* new 4.3bsd version of gethostent */
+                   char **list;
+
+                   /* iterate over the addresses */
+                   for (list = hp->h_addr_list; *list; list++)
+                       (void) NewHost (family, (pointer)*list, len);
+#else
+                   (void) NewHost (family, (pointer)hp->h_addr, len);
+#endif
+               }
+           }
+        }
+#endif /* TCPCONN || STREAMSCONN */
+       family = FamilyWild;
+        }
+        fclose (fd);
+    }
+}
+
+/* Is client on the local host */
+Bool LocalClient(client)
+    ClientPtr client;
+{
+    int                alen, family, notused;
+    Xtransaddr         *from = NULL;
+    pointer            addr;
+    register HOST      *host;
+
+#ifdef XCSECURITY
+    /* untrusted clients can't change host access */
+    if (client->trustLevel != XSecurityClientTrusted)
+    {
+       SecurityAudit("client %d attempted to change host access\n",
+                     client->index);
+       return FALSE;
+    }
+#endif
+#ifdef LBX
+    if (!((OsCommPtr)client->osPrivate)->trans_conn)
+       return FALSE;
+#endif
+    if (!_XSERVTransGetPeerAddr (((OsCommPtr)client->osPrivate)->trans_conn,
+       &notused, &alen, &from))
+    {
+       family = ConvertAddr ((struct sockaddr *) from,
+           &alen, (pointer *)&addr);
+       if (family == -1)
+       {
+           xfree ((char *) from);
+           return FALSE;
+       }
+       if (family == FamilyLocal)
+       {
+           xfree ((char *) from);
+           return TRUE;
+       }
+       for (host = selfhosts; host; host = host->next)
+       {
+           if (addrEqual (family, addr, alen, host))
+               return TRUE;
+       }
+       xfree ((char *) from);
+    }
+    return FALSE;
+}
+
+static Bool
+AuthorizedClient(client)
+    ClientPtr client;
+{
+    if (!client || defeatAccessControl)
+       return TRUE;
+    return LocalClient(client);
+}
+
+/* Add a host to the access control list.  This is the external interface
+ * called from the dispatcher */
+
+int
+AddHost (client, family, length, pAddr)
+    ClientPtr          client;
+    int                 family;
+    unsigned            length;        /* of bytes in pAddr */
+    pointer             pAddr;
+{
+    int                        len;
+
+    if (!AuthorizedClient(client))
+       return(BadAccess);
+    switch (family) {
+    case FamilyLocalHost:
+       len = length;
+       LocalHostEnabled = TRUE;
+       break;
+#ifdef K5AUTH
+    case FamilyKrb5Principal:
+        len = length;
+        break;
+#endif
+#ifdef SECURE_RPC
+    case FamilyNetname:
+       len = length;
+       SecureRPCInit ();
+       break;
+#endif
+    case FamilyInternet:
+    case FamilyDECnet:
+    case FamilyChaos:
+       if ((len = CheckAddr (family, pAddr, length)) < 0)
+       {
+           client->errorValue = length;
+           return (BadValue);
+       }
+       break;
+    case FamilyLocal:
+    default:
+       client->errorValue = family;
+       return (BadValue);
+    }
+    if (NewHost (family, pAddr, len))
+       return Success;
+    return BadAlloc;
+}
+
+Bool
+#if NeedFunctionPrototypes
+ForEachHostInFamily (
+    int            family,
+    Bool    (*func)(
+#if NeedNestedPrototypes
+            unsigned char * /* addr */,
+            short           /* len */,
+            pointer         /* closure */
+#endif
+            ),
+    pointer closure)
+#else
+ForEachHostInFamily (family, func, closure)
+    int            family;
+    Bool    (*func)();
+    pointer closure;
+#endif
+{
+    HOST    *host;
+
+    for (host = validhosts; host; host = host->next)
+       if (family == host->family && func (host->addr, host->len, closure))
+           return TRUE;
+    return FALSE;
+}
+
+/* Add a host to the access control list. This is the internal interface 
+ * called when starting or resetting the server */
+static Bool
+NewHost (family, addr, len)
+    int                family;
+    pointer    addr;
+    int                len;
+{
+    register HOST *host;
+
+    for (host = validhosts; host; host = host->next)
+    {
+        if (addrEqual (family, addr, len, host))
+           return TRUE;
+    }
+    MakeHost(host,len)
+    if (!host)
+       return FALSE;
+    host->family = family;
+    host->len = len;
+    acopy(addr, host->addr, len);
+    host->next = validhosts;
+    validhosts = host;
+    return TRUE;
+}
+
+/* Remove a host from the access control list */
+
+int
+RemoveHost (client, family, length, pAddr)
+    ClientPtr          client;
+    int                 family;
+    unsigned            length;        /* of bytes in pAddr */
+    pointer             pAddr;
+{
+    int                        len;
+    register HOST      *host, **prev;
+
+    if (!AuthorizedClient(client))
+       return(BadAccess);
+    switch (family) {
+    case FamilyLocalHost:
+       len = length;
+       LocalHostEnabled = FALSE;
+       break;
+#ifdef K5AUTH
+    case FamilyKrb5Principal:
+        len = length;
+       break;
+#endif
+#ifdef SECURE_RPC
+    case FamilyNetname:
+       len = length;
+       break;
+#endif
+    case FamilyInternet:
+    case FamilyDECnet:
+    case FamilyChaos:
+       if ((len = CheckAddr (family, pAddr, length)) < 0)
+       {
+           client->errorValue = length;
+            return(BadValue);
+       }
+       break;
+    case FamilyLocal:
+    default:
+       client->errorValue = family;
+        return(BadValue);
+    }
+    for (prev = &validhosts;
+         (host = *prev) && (!addrEqual (family, pAddr, len, host));
+         prev = &host->next)
+        ;
+    if (host)
+    {
+        *prev = host->next;
+        FreeHost (host);
+    }
+    return (Success);
+}
+
+/* Get all hosts in the access control list */
+int
+GetHosts (data, pnHosts, pLen, pEnabled)
+    pointer            *data;
+    int                        *pnHosts;
+    int                        *pLen;
+    BOOL               *pEnabled;
+{
+    int                        len;
+    register int       n = 0;
+    register unsigned char *ptr;
+    register HOST      *host;
+    int                        nHosts = 0;
+
+    *pEnabled = AccessEnabled ? EnableAccess : DisableAccess;
+    for (host = validhosts; host; host = host->next)
+    {
+       nHosts++;
+       n += (((host->len + 3) >> 2) << 2) + sizeof(xHostEntry);
+    }
+    if (n)
+    {
+        *data = ptr = (pointer) xalloc (n);
+       if (!ptr)
+       {
+           return(BadAlloc);
+       }
+        for (host = validhosts; host; host = host->next)
+       {
+           len = host->len;
+           ((xHostEntry *)ptr)->family = host->family;
+           ((xHostEntry *)ptr)->length = len;
+           ptr += sizeof(xHostEntry);
+           acopy (host->addr, ptr, len);
+           ptr += ((len + 3) >> 2) << 2;
+        }
+    } else {
+       *data = NULL;
+    }
+    *pnHosts = nHosts;
+    *pLen = n;
+    return(Success);
+}
+
+/* Check for valid address family and length, and return address length. */
+
+/*ARGSUSED*/
+static int
+CheckAddr (family, pAddr, length)
+    int                        family;
+    pointer            pAddr;
+    unsigned           length;
+{
+    int        len;
+
+    switch (family)
+    {
+#if defined(TCPCONN) || defined(STREAMSCONN) || defined(AMTCPCONN) || defined(MNX_TCPCONN)
+      case FamilyInternet:
+#if !defined(AMOEBA)
+       if (length == sizeof (struct in_addr))
+#else
+       if (length == sizeof(ipaddr_t))
+#endif
+           len = length;
+       else
+           len = -1;
+        break;
+#endif 
+#ifdef DNETCONN
+      case FamilyDECnet:
+        {
+           struct dn_naddr *dnaddr = (struct dn_naddr *) pAddr;
+
+           if ((length < sizeof(dnaddr->a_len)) ||
+               (length < dnaddr->a_len + sizeof(dnaddr->a_len)))
+               len = -1;
+           else
+               len = dnaddr->a_len + sizeof(dnaddr->a_len);
+           if (len > sizeof(struct dn_naddr))
+               len = -1;
+       }
+        break;
+#endif
+      default:
+        len = -1;
+    }
+    return (len);
+}
+
+/* Check if a host is not in the access control list. 
+ * Returns 1 if host is invalid, 0 if we've found it. */
+
+InvalidHost (saddr, len)
+#ifndef AMOEBA_ORIG
+    register struct sockaddr   *saddr;
+#else
+    register ipaddr_t          *saddr;
+#endif
+    int                                len;
+{
+    int                        family;
+    pointer                    addr;
+    register HOST              *selfhost, *host;
+
+    if (!AccessEnabled)   /* just let them in */
+        return(0);    
+    family = ConvertAddr (saddr, &len, (pointer *)&addr);
+    if (family == -1)
+        return 1;
+    if (family == FamilyLocal)
+    {
+       if (!LocalHostEnabled)
+       {
+           /*
+            * check to see if any local address is enabled.  This 
+            * implicitly enables local connections.
+            */
+           for (selfhost = selfhosts; selfhost; selfhost=selfhost->next)
+           {
+               for (host = validhosts; host; host=host->next)
+               {
+                   if (addrEqual (selfhost->family, selfhost->addr,
+                                  selfhost->len, host))
+                       return 0;
+               }
+           }
+           return 1;
+       } else
+           return 0;
+    }
+    for (host = validhosts; host; host = host->next)
+    {
+        if (addrEqual (family, addr, len, host))
+           return (0);
+    }
+    return (1);
+}
+
+static int
+ConvertAddr (saddr, len, addr)
+#ifndef AMOEBA_ORIG
+    register struct sockaddr   *saddr;
+#else
+    register ipaddr_t          *saddr;
+#endif
+    int                                *len;
+    pointer                    *addr;
+{
+#ifndef AMOEBA
+    if (*len == 0)
+        return (FamilyLocal);
+    switch (saddr->sa_family)
+    {
+    case AF_UNSPEC:
+#if defined(UNIXCONN) || defined(LOCALCONN) || defined(OS2PIPECONN)
+    case AF_UNIX:
+#endif
+        return FamilyLocal;
+#if defined(TCPCONN) || defined(STREAMSCONN) || defined(MNX_TCPCONN)
+    case AF_INET:
+        *len = sizeof (struct in_addr);
+        *addr = (pointer) &(((struct sockaddr_in *) saddr)->sin_addr);
+        return FamilyInternet;
+#endif
+#ifdef DNETCONN
+    case AF_DECnet:
+       {
+           struct sockaddr_dn *sdn = (struct sockaddr_dn *) saddr;
+           *len = sdn->sdn_nodeaddrl + sizeof(sdn->sdn_nodeaddrl);
+           *addr = (pointer) &(sdn->sdn_add);
+       }
+        return FamilyDECnet;
+#endif
+#ifdef CHAOSCONN
+    case AF_CHAOS:
+       {
+           not implemented
+       }
+       return FamilyChaos;
+#endif
+    default:
+        return -1;
+    }
+#else /* AMOEBA */
+    if (*len == 0) return -1;
+    *len = sizeof (ipaddr_t);
+    *addr = (pointer) saddr;
+    return FamilyInternet;
+#endif /* AMOEBA */
+}
+
+int
+ChangeAccessControl(client, fEnabled)
+    ClientPtr client;
+    int fEnabled;
+{
+    if (!AuthorizedClient(client))
+       return BadAccess;
+    AccessEnabled = fEnabled;
+    return Success;
+}
+
+/* returns FALSE if xhost + in effect, else TRUE */
+int
+GetAccessControl()
+{
+    return AccessEnabled;
+}
+
diff --git a/Xserver/programs/Xserver/os/auth.c b/Xserver/programs/Xserver/os/auth.c
new file mode 100644 (file)
index 0000000..68025de
--- /dev/null
@@ -0,0 +1,411 @@
+/* $XConsortium: auth.c /main/27 1996/12/02 10:22:41 lehors $ */
+/*
+
+Copyright (c) 1988  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be included
+in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR
+OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall
+not be used in advertising or otherwise to promote the sale, use or
+other dealings in this Software without prior written authorization
+from the X Consortium.
+
+*/
+
+/*
+ * authorization hooks for the server
+ * Author:  Keith Packard, MIT X Consortium
+ */
+
+#ifdef K5AUTH
+# include   <krb5/krb5.h>
+#endif
+# include   "X.h"
+# include   "Xauth.h"
+# include   "misc.h"
+# include   "dixstruct.h"
+# include   <sys/types.h>
+# include   <sys/stat.h>
+#ifdef XCSECURITY
+#define _SECURITY_SERVER
+# include   "extensions/security.h"
+#endif
+#ifdef WIN32
+#include "Xw32defs.h"
+#endif
+
+struct protocol {
+    unsigned short   name_length;
+    char    *name;
+    int     (*Add)();      /* new authorization data */
+    XID            (*Check)();     /* verify client authorization data */
+    int     (*Reset)();            /* delete all authorization data entries */
+    XID            (*ToID)();      /* convert cookie to ID */
+    int            (*FromID)();    /* convert ID to cookie */
+    int            (*Remove)();    /* remove a specific cookie */
+#ifdef XCSECURITY
+    XID     (*Generate)();
+#endif
+};
+
+extern int  MitAddCookie ();
+extern XID  MitCheckCookie ();
+extern int  MitResetCookie ();
+extern XID  MitToID ();
+extern int  MitFromID (), MitRemoveCookie ();
+extern XID  MitGenerateCookie();
+
+#ifdef HASXDMAUTH
+extern int  XdmAddCookie ();
+extern XID  XdmCheckCookie ();
+extern int  XdmResetCookie ();
+extern XID  XdmToID ();
+extern int  XdmFromID (), XdmRemoveCookie ();
+#endif
+
+#ifdef SECURE_RPC
+extern int  SecureRPCAdd();
+extern XID  SecureRPCCheck();
+extern int  SecureRPCReset();
+extern XID  SecureRPCToID();
+extern int  SecureRPCFromID(), SecureRPCRemove();
+#endif
+
+#ifdef K5AUTH
+extern int K5Add();
+extern XID K5Check();
+extern int K5Reset();
+extern XID K5ToID();
+extern int K5FromID(), K5Remove();
+#endif
+
+extern XID AuthSecurityCheck();
+
+static struct protocol   protocols[] = {
+{   (unsigned short) 18,    "MIT-MAGIC-COOKIE-1",
+               MitAddCookie,   MitCheckCookie, MitResetCookie,
+               MitToID,        MitFromID,      MitRemoveCookie,
+#ifdef XCSECURITY
+               MitGenerateCookie
+#endif
+},
+#ifdef HASXDMAUTH
+{   (unsigned short) 19,    "XDM-AUTHORIZATION-1",
+               XdmAddCookie,   XdmCheckCookie, XdmResetCookie,
+               XdmToID,        XdmFromID,      XdmRemoveCookie,
+#ifdef XCSECURITY
+               NULL
+#endif
+},
+#endif
+#ifdef SECURE_RPC
+{   (unsigned short) 9,    "SUN-DES-1",
+               SecureRPCAdd,   SecureRPCCheck, SecureRPCReset,
+               SecureRPCToID,  SecureRPCFromID,SecureRPCRemove,
+#ifdef XCSECURITY
+               NULL
+#endif
+},
+#endif
+#ifdef K5AUTH
+{   (unsigned short) 14, "MIT-KERBEROS-5",
+               K5Add, K5Check, K5Reset,
+               K5ToID, K5FromID, K5Remove,
+#ifdef XCSECURITY
+               NULL
+#endif
+},
+#endif
+#ifdef XCSECURITY
+{   (unsigned short) XSecurityAuthorizationNameLen,
+       XSecurityAuthorizationName,
+               NULL, AuthSecurityCheck, NULL,
+               NULL, NULL, NULL,
+               NULL
+},
+#endif
+};
+
+# define NUM_AUTHORIZATION  (sizeof (protocols) /\
+                            sizeof (struct protocol))
+
+/*
+ * Initialize all classes of authorization by reading the
+ * specified authorization file
+ */
+
+static char *authorization_file = (char *)NULL;
+
+static Bool ShouldLoadAuth = TRUE;
+
+void
+InitAuthorization (file_name)
+char   *file_name;
+{
+    authorization_file = file_name;
+}
+
+int
+LoadAuthorization ()
+{
+    FILE    *f;
+    Xauth   *auth;
+    int            i;
+    int            count = 0;
+
+    ShouldLoadAuth = FALSE;
+    if (!authorization_file)
+       return 0;
+    f = fopen (authorization_file, "r");
+    if (!f)
+       return 0;
+    while (auth = XauReadAuth (f)) {
+       for (i = 0; i < NUM_AUTHORIZATION; i++) {
+           if (protocols[i].name_length == auth->name_length &&
+               memcmp (protocols[i].name, auth->name, (int) auth->name_length) == 0 &&
+               protocols[i].Add)
+           {
+               ++count;
+               (*protocols[i].Add) (auth->data_length, auth->data,
+                                        FakeClientID(0));
+           }
+       }
+       XauDisposeAuth (auth);
+    }
+    fclose (f);
+    return count;
+}
+
+#ifdef XDMCP
+/*
+ * XdmcpInit calls this function to discover all authorization
+ * schemes supported by the display
+ */
+void
+RegisterAuthorizations ()
+{
+    int            i;
+
+    for (i = 0; i < NUM_AUTHORIZATION; i++)
+       XdmcpRegisterAuthorization (protocols[i].name,
+                                   (int)protocols[i].name_length);
+}
+#endif
+
+XID
+CheckAuthorization (name_length, name, data_length, data, client, reason)
+    unsigned int name_length;
+    char       *name;
+    unsigned int data_length;
+    char       *data;
+    ClientPtr client;
+    char       **reason;       /* failure message.  NULL for default msg */
+{
+    int        i;
+    struct stat buf;
+    static time_t lastmod = 0;
+
+    if (!authorization_file || stat(authorization_file, &buf))
+    {
+       lastmod = 0;
+       ShouldLoadAuth = TRUE;  /* stat lost, so force reload */
+    }
+    else if (buf.st_mtime > lastmod)
+    {
+       lastmod = buf.st_mtime;
+       ShouldLoadAuth = TRUE;
+    }
+    if (ShouldLoadAuth)
+    {
+       if (LoadAuthorization())
+           DisableLocalHost(); /* got at least one */
+       else
+           EnableLocalHost ();
+    }
+    if (name_length)
+       for (i = 0; i < NUM_AUTHORIZATION; i++) {
+           if (protocols[i].name_length == name_length &&
+               memcmp (protocols[i].name, name, (int) name_length) == 0)
+           {
+               return (*protocols[i].Check) (data_length, data, client, reason);
+           }
+       }
+    return (XID) ~0L;
+}
+
+void
+ResetAuthorization ()
+{
+    int        i;
+
+    for (i = 0; i < NUM_AUTHORIZATION; i++)
+       if (protocols[i].Reset)
+           (*protocols[i].Reset)();
+    ShouldLoadAuth = TRUE;
+}
+
+XID
+AuthorizationToID (name_length, name, data_length, data)
+unsigned short name_length;
+char   *name;
+unsigned short data_length;
+char   *data;
+{
+    int        i;
+
+    for (i = 0; i < NUM_AUTHORIZATION; i++) {
+       if (protocols[i].name_length == name_length &&
+           memcmp (protocols[i].name, name, (int) name_length) == 0 &&
+           protocols[i].ToID)
+       {
+           return (*protocols[i].ToID) (data_length, data);
+       }
+    }
+    return (XID) ~0L;
+}
+
+int
+AuthorizationFromID (id, name_lenp, namep, data_lenp, datap)
+XID id;
+unsigned short *name_lenp;
+char   **namep;
+unsigned short *data_lenp;
+char   **datap;
+{
+    int        i;
+
+    for (i = 0; i < NUM_AUTHORIZATION; i++) {
+       if (protocols[i].FromID &&
+           (*protocols[i].FromID) (id, data_lenp, datap)) {
+           *name_lenp = protocols[i].name_length;
+           *namep = protocols[i].name;
+           return 1;
+       }
+    }
+    return 0;
+}
+
+int
+RemoveAuthorization (name_length, name, data_length, data)
+unsigned short name_length;
+char   *name;
+unsigned short data_length;
+char   *data;
+{
+    int        i;
+
+    for (i = 0; i < NUM_AUTHORIZATION; i++) {
+       if (protocols[i].name_length == name_length &&
+           memcmp (protocols[i].name, name, (int) name_length) == 0 &&
+           protocols[i].Remove)
+       {
+           return (*protocols[i].Remove) (data_length, data);
+       }
+    }
+    return 0;
+}
+
+int
+AddAuthorization (name_length, name, data_length, data)
+unsigned int name_length;
+char   *name;
+unsigned int data_length;
+char   *data;
+{
+    int        i;
+
+    for (i = 0; i < NUM_AUTHORIZATION; i++) {
+       if (protocols[i].name_length == name_length &&
+           memcmp (protocols[i].name, name, (int) name_length) == 0 &&
+           protocols[i].Add)
+       {
+           return (*protocols[i].Add) (data_length, data, FakeClientID(0));
+       }
+    }
+    return 0;
+}
+
+#ifdef XCSECURITY
+
+XID
+GenerateAuthorization(name_length, name, data_length, data,
+                     data_length_return, data_return)
+unsigned int name_length;
+char   *name;
+unsigned int data_length;
+char   *data;
+unsigned int *data_length_return;
+char   **data_return;
+{
+    int        i;
+
+    for (i = 0; i < NUM_AUTHORIZATION; i++) {
+       if (protocols[i].name_length == name_length &&
+           memcmp (protocols[i].name, name, (int) name_length) == 0 &&
+           protocols[i].Generate)
+       {
+           return (*protocols[i].Generate) (data_length, data,
+                       FakeClientID(0), data_length_return, data_return);
+       }
+    }
+    return -1;
+}
+
+/* A random number generator that is more unpredictable
+   than that shipped with some systems.
+   This code is taken from the C standard. */
+
+static unsigned long int next = 1;
+
+static int
+xdm_rand()
+{
+    next = next * 1103515245 + 12345;
+    return (unsigned int)(next/65536) % 32768;
+}
+
+static void
+xdm_srand(seed)
+    unsigned int seed;
+{
+    next = seed;
+}
+
+void
+GenerateRandomData (len, buf)
+int    len;
+char   *buf;
+{
+    static int seed;
+    int value;
+    int i;
+
+    seed += GetTimeInMillis();
+    xdm_srand (seed);
+    for (i = 0; i < len; i++)
+    {
+       value = xdm_rand ();
+       buf[i] ^= (value & 0xff00) >> 8;
+    }
+
+    /* XXX add getrusage, popen("ps -ale") */
+}
+
+#endif /* XCSECURITY */
diff --git a/Xserver/programs/Xserver/os/connection.c b/Xserver/programs/Xserver/os/connection.c
new file mode 100644 (file)
index 0000000..76df583
--- /dev/null
@@ -0,0 +1,1258 @@
+/* $TOG: connection.c /main/156 1997/06/05 18:43:01 sekhar $ */
+/***********************************************************
+
+Copyright (c) 1987, 1989  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+
+Copyright 1987, 1989 by Digital Equipment Corporation, Maynard, Massachusetts.
+
+                        All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and its 
+documentation for any purpose and without fee is hereby granted, 
+provided that the above copyright notice appear in all copies and that
+both that copyright notice and this permission notice appear in 
+supporting documentation, and that the name of Digital not be
+used in advertising or publicity pertaining to distribution of the
+software without specific, written prior permission.  
+
+DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
+ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
+DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
+ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+SOFTWARE.
+
+******************************************************************/
+/* $XFree86: xc/programs/Xserver/os/connection.c,v 3.25.2.2 1997/07/05 15:55:45 dawes Exp $ */
+/*****************************************************************
+ *  Stuff to create connections --- OS dependent
+ *
+ *      EstablishNewConnections, CreateWellKnownSockets, ResetWellKnownSockets,
+ *      CloseDownConnection, CheckConnections, AddEnabledDevice,
+ *     RemoveEnabledDevice, OnlyListToOneClient,
+ *      ListenToAllClients,
+ *
+ *      (WaitForSomething is in its own file)
+ *
+ *      In this implementation, a client socket table is not kept.
+ *      Instead, what would be the index into the table is just the
+ *      file descriptor of the socket.  This won't work for if the
+ *      socket ids aren't small nums (0 - 2^8)
+ *
+ *****************************************************************/
+
+#ifdef WIN32
+#include <X11/Xwinsock.h>
+#endif
+#include "X.h"
+#include "Xproto.h"
+#include <X11/Xtrans.h>
+#include <errno.h>
+#ifdef X_NOT_STDC_ENV
+extern int errno;
+#endif
+
+#include <signal.h>
+#include <stdio.h>
+
+#ifndef WIN32
+#ifndef MINIX
+#ifndef Lynx
+#include <sys/socket.h>
+#else
+#include <socket.h>
+#endif
+#endif
+
+#ifdef hpux
+#include <sys/utsname.h>
+#include <sys/ioctl.h>
+#endif
+
+#ifdef AIXV3
+#include <sys/ioctl.h>
+#endif
+
+#ifdef MINIX
+#include <sys/nbio.h>
+
+#define select(n,r,w,x,t) nbio_select(n,r,w,x,t)
+#endif
+
+#ifdef __EMX__
+#define select(n,r,w,x,t) os2PseudoSelect(n,r,w,x,t)
+extern __const__ int _nfiles;
+#endif
+
+#if defined(TCPCONN) || defined(STREAMSCONN)
+# include <netinet/in.h>
+
+/*================================================================
+   BEGIN ORL VNC modification
+   include arpa/inet.h for inet_ntoa function prototype */
+
+#include <arpa/inet.h>
+
+/* END ORL VNC modification
+================================================================*/
+
+# ifndef hpux
+#  ifdef apollo
+#   ifndef NO_TCP_H
+#    include <netinet/tcp.h>
+#   endif
+#  else
+#   ifdef CSRG_BASED
+#    include <sys/param.h>
+#   endif
+#    ifndef __EMX__
+#     include <netinet/tcp.h>
+#    endif
+#  endif
+# endif
+#endif
+
+#ifdef AMTCPCONN
+#include <server/ip/types.h>
+#include <server/ip/gen/in.h>
+#include <server/ip/gen/inet.h>
+#endif
+
+#if !defined(AMOEBA) && !defined(_MINIX) && !defined(__EMX__)
+#ifndef Lynx
+#include <sys/uio.h>
+#else
+#include <uio.h>
+#endif
+#endif
+#endif /* WIN32 */
+#include "misc.h"              /* for typedef of pointer */
+#include <X11/Xpoll.h>
+#include "osdep.h"
+#include "opaque.h"
+#include "dixstruct.h"
+#ifdef XAPPGROUP
+#include "extensions/Xagsrv.h"
+#endif
+#ifdef XCSECURITY
+#define _SECURITY_SERVER
+#include "extensions/security.h"
+#endif
+#ifdef LBX
+#include "lbxserve.h"
+#endif
+
+#ifdef X_NOT_POSIX
+#define Pid_t int
+#else
+#define Pid_t pid_t
+#endif
+
+#ifdef DNETCONN
+#include <netdnet/dn.h>
+#endif /* DNETCONN */
+
+extern char *display;          /* The display number */
+int lastfdesc;                 /* maximum file descriptor */
+
+fd_set WellKnownConnections;   /* Listener mask */
+fd_set EnabledDevices;         /* mask for input devices that are on */
+fd_set AllSockets;             /* select on this */
+fd_set AllClients;             /* available clients */
+fd_set LastSelectMask;         /* mask returned from last select call */
+fd_set ClientsWithInput;       /* clients with FULL requests in buffer */
+fd_set ClientsWriteBlocked;    /* clients who cannot receive output */
+fd_set OutputPending;          /* clients with reply/event data ready to go */
+int MaxClients = MAXSOCKS;
+Bool NewOutputPending;         /* not yet attempted to write some new output */
+Bool AnyClientsWriteBlocked;   /* true if some client blocked on write */
+
+Bool RunFromSmartParent;       /* send SIGUSR1 to parent process */
+Bool PartialNetwork;           /* continue even if unable to bind all addrs */
+char *protNoListen;             /* don't listen on this protocol */
+static Pid_t ParentProcess;
+
+static Bool debug_conns = FALSE;
+
+fd_set IgnoredClientsWithInput;
+static fd_set GrabImperviousClients;
+static fd_set SavedAllClients;
+static fd_set SavedAllSockets;
+static fd_set SavedClientsWithInput;
+int GrabInProgress = 0;
+
+#ifndef WIN32
+int ConnectionTranslation[MAXSOCKS];
+#else
+/* SPAM ALERT !!!
+ * On NT fds are not between 0 and MAXSOCKS, they are unrelated, and there is
+ * not even a known maximum value, so use something quite arbitrary for now.
+ * This is clearly boggus and another form of storage which doesn't use the fd
+ * as a direct index should really be implemented for NT.
+ */
+#define MAXFD 500
+int ConnectionTranslation[MAXFD];
+#endif
+
+XtransConnInfo         *ListenTransConns = NULL;
+int            *ListenTransFds = NULL;
+int            ListenTransCount;
+
+extern int auditTrailLevel;
+
+static void ErrorConnMax(
+#if NeedFunctionPrototypes
+XtransConnInfo /* trans_conn */
+#endif
+);
+
+#ifndef LBX
+static
+#endif
+void CloseDownFileDescriptor(
+#if NeedFunctionPrototypes
+#ifdef LBX
+    ClientPtr  client
+#else
+    register OsCommPtr /*oc*/
+#endif
+#endif
+);
+
+#ifdef LBX
+extern int LbxFlushClient();
+extern void LbxCloseClient();
+#endif /* LBX */
+
+static XtransConnInfo
+lookup_trans_conn (fd)
+    int fd;
+{
+    if (ListenTransFds)
+    {
+       int i;
+       for (i = 0; i < ListenTransCount; i++)
+           if (ListenTransFds[i] == fd)
+               return ListenTransConns[i];
+    }
+
+    return (NULL);
+}
+
+#ifdef XDMCP
+void XdmcpOpenDisplay(), XdmcpInit(), XdmcpReset(), XdmcpCloseDisplay();
+#endif
+
+/*****************
+ * CreateWellKnownSockets
+ *    At initialization, create the sockets to listen on for new clients.
+ *****************/
+
+void
+CreateWellKnownSockets()
+{
+    int                request, i;
+    int                partial;
+    char       port[20];
+
+    FD_ZERO(&AllSockets);
+    FD_ZERO(&AllClients);
+    FD_ZERO(&LastSelectMask);
+    FD_ZERO(&ClientsWithInput);
+
+#ifndef WIN32
+    for (i=0; i<MAXSOCKS; i++) ConnectionTranslation[i] = 0;
+#else
+    for (i=0; i<MAXFD; i++) ConnectionTranslation[i] = 0;
+#endif
+#ifdef XNO_SYSCONF      /* should only be on FreeBSD 1.x and NetBSD 0.x */
+#undef _SC_OPEN_MAX
+#endif
+#ifndef __EMX__
+#ifdef _SC_OPEN_MAX
+    lastfdesc = sysconf(_SC_OPEN_MAX) - 1;
+#else
+#ifdef hpux /* || defined(__EMX__) ? */
+    lastfdesc = _NFILE - 1;
+#else
+    lastfdesc = getdtablesize() - 1;
+#endif
+#endif
+#else
+    lastfdesc = _nfiles - 1;
+#endif
+
+    if (lastfdesc > MAXSOCKS)
+    {
+       lastfdesc = MAXSOCKS;
+       if (debug_conns)
+           ErrorF( "GOT TO END OF SOCKETS %d\n", MAXSOCKS);
+    }
+
+    FD_ZERO (&WellKnownConnections);
+
+    sprintf (port, "%d", atoi (display));
+
+    if (protNoListen)
+        if (_XSERVTransNoListen(protNoListen))
+        {
+           FatalError ("Failed to disable listen for %s", protNoListen);
+       }
+    
+    if ((_XSERVTransMakeAllCOTSServerListeners (port, &partial,
+       &ListenTransCount, &ListenTransConns) >= 0) &&
+       (ListenTransCount >= 1))
+    {
+       if (!PartialNetwork && partial)
+       {
+           FatalError ("Failed to establish all listening sockets");
+       }
+       else
+       {
+           ListenTransFds = (int *) xalloc (ListenTransCount * sizeof (int));
+
+           for (i = 0; i < ListenTransCount; i++)
+           {
+               int fd = _XSERVTransGetConnectionNumber (ListenTransConns[i]);
+               
+               ListenTransFds[i] = fd;
+               FD_SET (fd, &WellKnownConnections);
+
+               if (!_XSERVTransIsLocal (ListenTransConns[i]))
+               {
+                   DefineSelf (fd);
+               }
+           }
+       }
+    }
+
+    if (!XFD_ANYSET (&WellKnownConnections))
+        FatalError ("Cannot establish any listening sockets - Make sure an X server isn't already running");
+#ifndef WIN32
+    OsSignal (SIGPIPE, SIG_IGN);
+    OsSignal (SIGHUP, AutoResetServer);
+#endif
+    OsSignal (SIGINT, GiveUp);
+    OsSignal (SIGTERM, GiveUp);
+    XFD_COPYSET (&WellKnownConnections, &AllSockets);
+    ResetHosts(display);
+    /*
+     * Magic:  If SIGUSR1 was set to SIG_IGN when
+     * the server started, assume that either
+     *
+     *  a- The parent process is ignoring SIGUSR1
+     *
+     * or
+     *
+     *  b- The parent process is expecting a SIGUSR1
+     *     when the server is ready to accept connections
+     *
+     * In the first case, the signal will be harmless,
+     * in the second case, the signal will be quite
+     * useful
+     */
+#ifndef WIN32
+/*================================================================
+   BEGIN ORL VNC modification
+   Don't use SIGUSR1 - linuxthread uses this internally */
+
+/* apparently no longer true. */
+
+    if (OsSignal (SIGUSR1, SIG_IGN) == SIG_IGN)
+       RunFromSmartParent = TRUE;
+    ParentProcess = getppid ();
+    if (RunFromSmartParent) {
+       if (ParentProcess > 0) {
+           kill (ParentProcess, SIGUSR1);
+       }
+    }
+
+
+/* END ORL VNC modification
+================================================================*/
+#endif
+#ifdef XDMCP
+    XdmcpInit ();
+#endif
+}
+
+void
+ResetWellKnownSockets ()
+{
+    int i;
+
+    ResetOsBuffers();
+
+    for (i = 0; i < ListenTransCount; i++)
+    {
+       int status = _XSERVTransResetListener (ListenTransConns[i]);
+
+       if (status != TRANS_RESET_NOOP)
+       {
+           if (status == TRANS_RESET_FAILURE)
+           {
+               /*
+                * ListenTransConns[i] freed by xtrans.
+                * Remove it from out list.
+                */
+
+               FD_CLR (ListenTransFds[i], &WellKnownConnections);
+               ListenTransFds[i] = ListenTransFds[ListenTransCount - 1];
+               ListenTransConns[i] = ListenTransConns[ListenTransCount - 1];
+               ListenTransCount -= 1;
+               i -= 1;
+           }
+           else if (status == TRANS_RESET_NEW_FD)
+           {
+               /*
+                * A new file descriptor was allocated (the old one was closed)
+                */
+
+               int newfd = _XSERVTransGetConnectionNumber (ListenTransConns[i]);
+
+               FD_CLR (ListenTransFds[i], &WellKnownConnections);
+               ListenTransFds[i] = newfd;
+               FD_SET(newfd, &WellKnownConnections);
+           }
+       }
+    }
+
+    ResetAuthorization ();
+    ResetHosts(display);
+    /*
+     * See above in CreateWellKnownSockets about SIGUSR1
+     */
+#ifndef WIN32
+/*================================================================
+   BEGIN ORL VNC modification
+   Don't use SIGUSR1 - linuxthread uses this internally */
+
+    if (RunFromSmartParent) {
+       if (ParentProcess > 0) {
+           kill (ParentProcess, SIGUSR1);
+       }
+    }
+
+/* END ORL VNC modification
+================================================================*/
+#endif
+    /*
+     * restart XDMCP
+     */
+#ifdef XDMCP
+    XdmcpReset ();
+#endif
+}
+
+static void
+AuthAudit (client, letin, saddr, len, proto_n, auth_proto, auth_id)
+    ClientPtr client;
+    Bool letin;
+    struct sockaddr *saddr;
+    int len;
+    unsigned short proto_n;
+    char *auth_proto;
+    int auth_id;
+{
+    char addr[128];
+    char *out = addr;
+
+    if (!((OsCommPtr)client->osPrivate)->trans_conn) {
+       strcpy(addr, "LBX proxy at ");
+       out += strlen(addr);
+    }
+    if (!len)
+        strcpy(out, "local host");
+    else
+       switch (saddr->sa_family)
+       {
+       case AF_UNSPEC:
+#if defined(UNIXCONN) || defined(LOCALCONN) || defined(OS2PIPECONN)
+       case AF_UNIX:
+#endif
+           strcpy(out, "local host");
+           break;
+#if defined(TCPCONN) || defined(STREAMSCONN) || defined(MNX_TCPCONN)
+       case AF_INET:
+           sprintf(out, "IP %s port %d",
+                   inet_ntoa(((struct sockaddr_in *) saddr)->sin_addr),
+                   ntohs(((struct sockaddr_in *) saddr)->sin_port));
+           break;
+#endif
+#ifdef DNETCONN
+       case AF_DECnet:
+           sprintf(out, "DN %s",
+                   dnet_ntoa(&((struct sockaddr_dn *) saddr)->sdn_add));
+           break;
+#endif
+#ifdef AMRPCCONN
+       case FamilyAmoeba:
+           sprintf(addr, "AM %s", saddr);
+           break;
+#endif
+#if defined(AMTCPCONN) && !(defined(TCPCONN) || defined(STREAMSCONN))
+       case AF_INET:
+           sprintf(addr, "AMIP %s", inet_ntoa(*((ipaddr_t *) saddr)));
+           break;
+#endif
+       default:
+           strcpy(out, "unknown address");
+       }
+    if (letin)
+       AuditF("client %d connected from %s\n", client->index, addr);
+    else
+       AuditF("client %d rejected from %s\n", client->index, addr);
+    if (proto_n)
+       AuditF("  Auth name: %.*s ID: %d\n", proto_n, auth_proto, auth_id);
+}
+
+XID
+AuthorizationIDOfClient(client)
+    ClientPtr client;
+{
+    if (client->osPrivate)
+       return ((OsCommPtr)client->osPrivate)->auth_id;
+    else
+       return None;
+}
+
+
+/*****************************************************************
+ * ClientAuthorized
+ *
+ *    Sent by the client at connection setup:
+ *                typedef struct _xConnClientPrefix {
+ *                   CARD8     byteOrder;
+ *                   BYTE      pad;
+ *                   CARD16    majorVersion, minorVersion;
+ *                   CARD16    nbytesAuthProto;    
+ *                   CARD16    nbytesAuthString;   
+ *                 } xConnClientPrefix;
+ *
+ *             It is hoped that eventually one protocol will be agreed upon.  In the
+ *        mean time, a server that implements a different protocol than the
+ *        client expects, or a server that only implements the host-based
+ *        mechanism, will simply ignore this information.
+ *
+ *****************************************************************/
+
+char * 
+ClientAuthorized(client, proto_n, auth_proto, string_n, auth_string)
+    ClientPtr client;
+    char *auth_proto, *auth_string;
+    unsigned int proto_n, string_n;
+{
+    register OsCommPtr         priv;
+    Xtransaddr         *from = NULL;
+    int                family;
+    int                        fromlen;
+    XID                        auth_id;
+    char               *reason = NULL;
+    XtransConnInfo     trans_conn;
+
+    auth_id = CheckAuthorization (proto_n, auth_proto,
+                                 string_n, auth_string, client, &reason);
+
+    priv = (OsCommPtr)client->osPrivate;
+    trans_conn = priv->trans_conn;
+#ifdef LBX
+    if (!trans_conn) {
+       ClientPtr lbxpc = LbxProxyClient(priv->proxy);
+       trans_conn = ((OsCommPtr)lbxpc->osPrivate)->trans_conn;
+       if (auth_id == (XID) ~0L && !GetAccessControl())
+           auth_id = ((OsCommPtr)lbxpc->osPrivate)->auth_id;
+#ifdef XCSECURITY
+       else if (auth_id != (XID) ~0L && !SecuritySameLevel(lbxpc, auth_id)) {
+           auth_id = (XID) ~0L;
+           reason = "Client trust level differs from that of LBX Proxy";
+       }
+#endif
+    }
+#endif
+    if (auth_id == (XID) ~0L)
+    {
+       if (
+#ifdef XCSECURITY          
+           (proto_n == 0 ||
+           strncmp (auth_proto, XSecurityAuthorizationName, proto_n) != 0) &&
+#endif
+           _XSERVTransGetPeerAddr (trans_conn,
+               &family, &fromlen, &from) != -1)
+       {
+#ifdef AMRPCCONN
+           /* Amoeba RPC connections are already checked by the capability. */
+           if (family == FamilyAmoeba) {
+               auth_id = (XID) 0;
+           }
+           else
+#endif
+           if (
+#ifdef LBX
+               !priv->trans_conn ||
+#endif
+               InvalidHost ((struct sockaddr *) from, fromlen))
+               AuthAudit(client, FALSE, (struct sockaddr *) from,
+                         fromlen, proto_n, auth_proto, auth_id);
+           else
+           {
+               auth_id = (XID) 0;
+               if (auditTrailLevel > 1)
+                   AuthAudit(client, TRUE,
+                       (struct sockaddr *) from, fromlen,
+                       proto_n, auth_proto, auth_id);
+           }
+
+           xfree ((char *) from);
+       }
+
+       if (auth_id == (XID) ~0L)
+           if (reason)
+               return reason;
+           else
+               return "Client is not authorized to connect to Server";
+    }
+    else if (auditTrailLevel > 1)
+    {
+       if (_XSERVTransGetPeerAddr (trans_conn,
+           &family, &fromlen, &from) != -1)
+       {
+           AuthAudit(client, TRUE, (struct sockaddr *) from, fromlen,
+                     proto_n, auth_proto, auth_id);
+
+           xfree ((char *) from);
+       }
+    }
+    priv->auth_id = auth_id;
+    priv->conn_time = 0;
+
+#ifdef XDMCP
+    /* indicate to Xdmcp protocol that we've opened new client */
+    XdmcpOpenDisplay(priv->fd);
+#endif /* XDMCP */
+#ifdef XAPPGROUP
+    if (ClientStateCallback)
+        XagCallClientStateChange (client);
+#endif
+    /* At this point, if the client is authorized to change the access control
+     * list, we should getpeername() information, and add the client to
+     * the selfhosts list.  It's not really the host machine, but the
+     * true purpose of the selfhosts list is to see who may change the
+     * access control list.
+     */
+    return((char *)NULL);
+}
+
+static ClientPtr
+#ifdef LBX
+AllocNewConnection (trans_conn, fd, conn_time, Flush, Close, proxy)
+#else
+AllocNewConnection (trans_conn, fd, conn_time)
+#endif
+    XtransConnInfo trans_conn;
+    int            fd;
+    CARD32  conn_time;
+#ifdef LBX
+    int     (*Flush)();
+    void    (*Close)();
+    LbxProxyPtr proxy;
+#endif
+{
+    OsCommPtr  oc;
+    ClientPtr  client;
+    
+    if (
+#ifdef LBX
+       trans_conn &&
+#endif
+#ifndef WIN32
+       fd >= lastfdesc
+#else
+       XFD_SETCOUNT(&AllClients) >= MaxClients
+#endif
+       )
+       return NullClient;
+    oc = (OsCommPtr)xalloc(sizeof(OsCommRec));
+    if (!oc)
+       return NullClient;
+    oc->trans_conn = trans_conn;
+    oc->fd = fd;
+    oc->input = (ConnectionInputPtr)NULL;
+    oc->output = (ConnectionOutputPtr)NULL;
+    oc->auth_id = None;
+    oc->conn_time = conn_time;
+#ifdef LBX
+    oc->proxy = proxy;
+    oc->Flush = Flush;
+    oc->Close = Close;
+    oc->largereq = (ConnectionInputPtr) NULL;
+#endif
+    if (!(client = NextAvailableClient((pointer)oc)))
+    {
+       xfree (oc);
+       return NullClient;
+    }
+#ifdef LBX
+    if (trans_conn)
+#endif
+    {
+       ConnectionTranslation[fd] = client->index;
+       if (GrabInProgress)
+       {
+           FD_SET(fd, &SavedAllClients);
+           FD_SET(fd, &SavedAllSockets);
+       }
+       else
+       {
+           FD_SET(fd, &AllClients);
+           FD_SET(fd, &AllSockets);
+       }
+    }
+    return client;
+}
+
+#ifdef LBX
+
+int
+ClientConnectionNumber (client)
+    ClientPtr  client;
+{
+    OsCommPtr oc = (OsCommPtr) client->osPrivate;
+
+    return oc->fd;
+}
+
+ClientPtr
+AllocLbxClientConnection (client, proxy)
+    ClientPtr client;
+    LbxProxyPtr proxy;
+{
+    OsCommPtr oc = (OsCommPtr) client->osPrivate;
+
+    return AllocNewConnection ((XtransConnInfo)NULL, oc->fd, GetTimeInMillis(),
+                              LbxFlushClient, LbxCloseClient, proxy);
+}
+
+void
+LbxProxyConnection (client, proxy)
+    ClientPtr  client;
+    LbxProxyPtr proxy;
+{
+    OsCommPtr  oc = (OsCommPtr) client->osPrivate;
+
+    FlushClient(client, oc, (char *)NULL, 0);
+    oc->proxy = proxy;
+    oc->Flush = LbxFlushClient;
+    oc->Close = LbxCloseClient;
+    LbxPrimeInput(client, proxy);
+}
+
+#endif
+
+/*****************
+ * EstablishNewConnections
+ *    If anyone is waiting on listened sockets, accept them.
+ *    Returns a mask with indices of new clients.  Updates AllClients
+ *    and AllSockets.
+ *****************/
+
+/*ARGSUSED*/
+Bool
+EstablishNewConnections(clientUnused, closure)
+    ClientPtr clientUnused;
+    pointer closure;
+{
+#ifndef WIN32
+    fd_mask readyconnections;     /* mask of listeners that are ready */
+#else
+    fd_set  readyconnections;     /* set of listeners that are ready */
+#endif
+    int curconn;                  /* fd of listener that's ready */
+    register int newconn;         /* fd of new client */
+    CARD32 connect_time;
+    register int i;
+    register ClientPtr client;
+    register OsCommPtr oc;
+    fd_set tmask;
+
+#ifndef AMOEBA
+    XFD_ANDSET (&tmask, (fd_set*)closure, &WellKnownConnections);
+#ifndef WIN32
+    readyconnections = tmask.fds_bits[0];
+    if (!readyconnections)
+       return TRUE;
+#else
+    XFD_COPYSET(&tmask, &readyconnections);
+    if (!XFD_ANYSET(&readyconnections))
+       return TRUE;
+#endif
+    connect_time = GetTimeInMillis();
+    /* kill off stragglers */
+    for (i=1; i<currentMaxClients; i++)
+    {
+       if (client = clients[i])
+       {
+           oc = (OsCommPtr)(client->osPrivate);
+           if (oc && (oc->conn_time != 0) &&
+               (connect_time - oc->conn_time) >= TimeOutValue || 
+               client->noClientException != Success && !client->clientGone)
+               CloseDownClient(client);     
+       }
+    }
+#else /* AMOEBA */
+    /* EstablishNewConnections is only called when there is one new
+     * connection waiting on the first transport.
+     */
+    readyconnections = 1;
+#endif /* AMOEBA */
+#ifndef WIN32
+    while (readyconnections) 
+#else
+    for (i = 0; i < XFD_SETCOUNT(&readyconnections); i++) 
+#endif
+    {
+       XtransConnInfo trans_conn, new_trans_conn;
+       int status;
+
+#ifndef WIN32
+       curconn = ffs (readyconnections) - 1;
+       readyconnections &= ~(1 << curconn);
+#else
+       curconn = XFD_FD(&readyconnections, i);
+#endif
+
+       if ((trans_conn = lookup_trans_conn (curconn)) == NULL)
+           continue;
+
+       if ((new_trans_conn = _XSERVTransAccept (trans_conn, &status)) == NULL)
+           continue;
+
+       newconn = _XSERVTransGetConnectionNumber (new_trans_conn);
+
+       _XSERVTransSetOption(new_trans_conn, TRANS_NONBLOCKING, 1);
+
+       if (!AllocNewConnection (new_trans_conn, newconn, connect_time
+#ifdef LBX
+                                , StandardFlushClient,
+                                CloseDownFileDescriptor, (LbxProxyPtr)NULL
+#endif
+                               ))
+       {
+           ErrorConnMax(new_trans_conn);
+           _XSERVTransClose(new_trans_conn);
+       }
+    }
+    return TRUE;
+}
+
+#define NOROOM "Maximum number of clients reached"
+
+/************
+ *   ErrorConnMax
+ *     Fail a connection due to lack of client or file descriptor space
+ ************/
+
+static void
+ErrorConnMax(trans_conn)
+XtransConnInfo trans_conn;
+{
+    register int fd = _XSERVTransGetConnectionNumber (trans_conn);
+    xConnSetupPrefix csp;
+    char pad[3];
+    struct iovec iov[3];
+    char byteOrder = 0;
+    int whichbyte = 1;
+#ifndef AMOEBA
+    struct timeval waittime;
+    fd_set mask;
+
+    /* if these seems like a lot of trouble to go to, it probably is */
+    waittime.tv_sec = BOTIMEOUT / MILLI_PER_SECOND;
+    waittime.tv_usec = (BOTIMEOUT % MILLI_PER_SECOND) *
+                      (1000000 / MILLI_PER_SECOND);
+    FD_ZERO(&mask);
+    FD_SET(fd, &mask);
+    (void)Select(fd + 1, &mask, NULL, NULL, &waittime);
+#endif
+    /* try to read the byte-order of the connection */
+    (void)_XSERVTransRead(trans_conn, &byteOrder, 1);
+    if ((byteOrder == 'l') || (byteOrder == 'B'))
+    {
+       csp.success = xFalse;
+       csp.lengthReason = sizeof(NOROOM) - 1;
+       csp.length = (sizeof(NOROOM) + 2) >> 2;
+       csp.majorVersion = X_PROTOCOL;
+       csp.minorVersion = X_PROTOCOL_REVISION;
+       if (((*(char *) &whichbyte) && (byteOrder == 'B')) ||
+           (!(*(char *) &whichbyte) && (byteOrder == 'l')))
+       {
+           swaps(&csp.majorVersion, whichbyte);
+           swaps(&csp.minorVersion, whichbyte);
+           swaps(&csp.length, whichbyte);
+       }
+       iov[0].iov_len = sz_xConnSetupPrefix;
+       iov[0].iov_base = (char *) &csp;
+       iov[1].iov_len = csp.lengthReason;
+       iov[1].iov_base = NOROOM;
+       iov[2].iov_len = (4 - (csp.lengthReason & 3)) & 3;
+       iov[2].iov_base = pad;
+       (void)_XSERVTransWritev(trans_conn, iov, 3);
+    }
+}
+
+/************
+ *   CloseDownFileDescriptor:
+ *     Remove this file descriptor and it's I/O buffers, etc.
+ ************/
+
+#ifdef LBX
+void
+CloseDownFileDescriptor(client)
+    ClientPtr  client;
+#else
+static void
+CloseDownFileDescriptor(oc)
+    register OsCommPtr oc;
+#endif
+{
+#ifdef LBX
+    register OsCommPtr oc = (OsCommPtr) client->osPrivate;
+#endif
+    int connection = oc->fd;
+
+    if (oc->trans_conn) {
+       _XSERVTransDisconnect(oc->trans_conn);
+       _XSERVTransClose(oc->trans_conn);
+    }
+#ifdef LBX
+    ConnectionTranslation[connection] = 0;
+#else
+    FreeOsBuffers(oc);
+#endif
+    FD_CLR(connection, &AllSockets);
+    FD_CLR(connection, &AllClients);
+    FD_CLR(connection, &ClientsWithInput);
+    FD_CLR(connection, &GrabImperviousClients);
+    if (GrabInProgress)
+    {
+       FD_CLR(connection, &SavedAllSockets);
+       FD_CLR(connection, &SavedAllClients);
+       FD_CLR(connection, &SavedClientsWithInput);
+    }
+    FD_CLR(connection, &ClientsWriteBlocked);
+    if (!XFD_ANYSET(&ClientsWriteBlocked))
+       AnyClientsWriteBlocked = FALSE;
+    FD_CLR(connection, &OutputPending);
+#ifndef LBX
+    xfree(oc);
+#endif
+}
+
+/*****************
+ * CheckConections
+ *    Some connection has died, go find which one and shut it down 
+ *    The file descriptor has been closed, but is still in AllClients.
+ *    If would truly be wonderful if select() would put the bogus
+ *    file descriptors in the exception mask, but nooooo.  So we have
+ *    to check each and every socket individually.
+ *****************/
+
+void
+CheckConnections()
+{
+#ifndef WIN32
+    fd_mask            mask;
+#endif
+    fd_set             tmask; 
+    register int       curclient, curoff;
+    int                        i;
+    struct timeval     notime;
+    int r;
+#ifdef WIN32
+    fd_set savedAllClients;
+#endif
+
+#ifndef AMOEBA
+    notime.tv_sec = 0;
+    notime.tv_usec = 0;
+
+#ifndef WIN32
+    for (i=0; i<howmany(XFD_SETSIZE, NFDBITS); i++)
+    {
+       mask = AllClients.fds_bits[i];
+        while (mask)
+       {
+           curoff = ffs (mask) - 1;
+           curclient = curoff + (i << 5);
+            FD_ZERO(&tmask);
+            FD_SET(curclient, &tmask);
+            r = Select (curclient + 1, &tmask, NULL, NULL, &notime);
+            if (r < 0)
+               CloseDownClient(clients[ConnectionTranslation[curclient]]);
+           mask &= ~(1 << curoff);
+       }
+    }  
+#else
+    XFD_COPYSET(&AllClients, &savedAllClients);
+    for (i = 0; i < XFD_SETCOUNT(&savedAllClients); i++)
+    {
+       curclient = XFD_FD(&savedAllClients, i);
+       FD_ZERO(&tmask);
+       FD_SET(curclient, &tmask);
+       r = Select (curclient + 1, &tmask, NULL, NULL, &notime);
+       if (r < 0)
+           CloseDownClient(clients[ConnectionTranslation[curclient]]);
+    }  
+#endif
+#endif
+}
+
+
+/*****************
+ * CloseDownConnection
+ *    Delete client from AllClients and free resources 
+ *****************/
+
+void
+CloseDownConnection(client)
+    ClientPtr client;
+{
+    OsCommPtr oc = (OsCommPtr)client->osPrivate;
+
+    if (oc->output && oc->output->count)
+       FlushClient(client, oc, (char *)NULL, 0);
+#ifdef XDMCP
+    XdmcpCloseDisplay(oc->fd);
+#endif
+#ifndef LBX
+    CloseDownFileDescriptor(oc);
+#else
+    (*oc->Close) (client);
+    FreeOsBuffers(oc);
+    xfree(oc);
+#endif
+    client->osPrivate = (pointer)NULL;
+    if (auditTrailLevel > 1)
+       AuditF("client %d disconnected\n", client->index);
+}
+
+
+AddEnabledDevice(fd)
+    int fd;
+{
+    FD_SET(fd, &EnabledDevices);
+    FD_SET(fd, &AllSockets);
+}
+
+
+RemoveEnabledDevice(fd)
+    int fd;
+{
+    FD_CLR(fd, &EnabledDevices);
+    FD_CLR(fd, &AllSockets);
+}
+
+/*****************
+ * OnlyListenToOneClient:
+ *    Only accept requests from  one client.  Continue to handle new
+ *    connections, but don't take any protocol requests from the new
+ *    ones.  Note that if GrabInProgress is set, EstablishNewConnections
+ *    needs to put new clients into SavedAllSockets and SavedAllClients.
+ *    Note also that there is no timeout for this in the protocol.
+ *    This routine is "undone" by ListenToAllClients()
+ *****************/
+
+OnlyListenToOneClient(client)
+    ClientPtr client;
+{
+    OsCommPtr oc = (OsCommPtr)client->osPrivate;
+    int connection = oc->fd;
+
+    if (! GrabInProgress)
+    {
+       XFD_COPYSET(&ClientsWithInput, &SavedClientsWithInput);
+       XFD_ANDSET(&ClientsWithInput,
+                      &ClientsWithInput, &GrabImperviousClients);
+       if (FD_ISSET(connection, &SavedClientsWithInput))
+       {
+           FD_CLR(connection, &SavedClientsWithInput);
+           FD_SET(connection, &ClientsWithInput);
+       }
+       XFD_UNSET(&SavedClientsWithInput, &GrabImperviousClients);
+       XFD_COPYSET(&AllSockets, &SavedAllSockets);
+       XFD_COPYSET(&AllClients, &SavedAllClients);
+       XFD_UNSET(&AllSockets, &AllClients);
+       XFD_ANDSET(&AllClients, &AllClients, &GrabImperviousClients);
+       FD_SET(connection, &AllClients);
+       XFD_ORSET(&AllSockets, &AllSockets, &AllClients);
+       GrabInProgress = client->index;
+    }
+}
+
+/****************
+ * ListenToAllClients:
+ *    Undoes OnlyListentToOneClient()
+ ****************/
+
+ListenToAllClients()
+{
+    if (GrabInProgress)
+    {
+       XFD_ORSET(&AllSockets, &AllSockets, &SavedAllSockets);
+       XFD_ORSET(&AllClients, &AllClients, &SavedAllClients);
+       XFD_ORSET(&ClientsWithInput, &ClientsWithInput, &SavedClientsWithInput);
+       GrabInProgress = 0;
+    }  
+}
+
+/****************
+ * IgnoreClient
+ *    Removes one client from input masks.
+ *    Must have cooresponding call to AttendClient.
+ ****************/
+
+IgnoreClient (client)
+    ClientPtr  client;
+{
+    OsCommPtr oc = (OsCommPtr)client->osPrivate;
+    int connection = oc->fd;
+#ifdef LBX
+    LbxClientPtr lbxClient = LbxClient(client);
+#endif
+
+    isItTimeToYield = TRUE;
+#ifdef LBX
+    if (lbxClient) {
+       lbxClient->ignored = TRUE;
+       return;
+    }
+#endif
+    if (!GrabInProgress || FD_ISSET(connection, &AllClients))
+    {
+       if (FD_ISSET (connection, &ClientsWithInput))
+           FD_SET(connection, &IgnoredClientsWithInput);
+       else
+           FD_CLR(connection, &IgnoredClientsWithInput);
+       FD_CLR(connection, &ClientsWithInput);
+       FD_CLR(connection, &AllSockets);
+       FD_CLR(connection, &AllClients);
+       FD_CLR(connection, &LastSelectMask);
+    }
+    else
+    {
+       if (FD_ISSET (connection, &SavedClientsWithInput))
+           FD_SET(connection, &IgnoredClientsWithInput);
+       else
+           FD_CLR(connection, &IgnoredClientsWithInput);
+       FD_CLR(connection, &SavedClientsWithInput);
+       FD_CLR(connection, &SavedAllSockets);
+       FD_CLR(connection, &SavedAllClients);
+    }
+}
+
+/****************
+ * AttendClient
+ *    Adds one client back into the input masks.
+ ****************/
+
+AttendClient (client)
+    ClientPtr  client;
+{
+    OsCommPtr oc = (OsCommPtr)client->osPrivate;
+    int connection = oc->fd;
+#ifdef LBX
+    LbxClientPtr lbxClient = LbxClient(client);
+
+    if (lbxClient) {
+       lbxClient->ignored = FALSE;
+       return;
+    }
+#endif
+    if (!GrabInProgress || GrabInProgress == client->index ||
+       FD_ISSET(connection, &GrabImperviousClients))
+    {
+       FD_SET(connection, &AllClients);
+       FD_SET(connection, &AllSockets);
+       FD_SET(connection, &LastSelectMask);
+       if (FD_ISSET (connection, &IgnoredClientsWithInput))
+           FD_SET(connection, &ClientsWithInput);
+    }
+    else
+    {
+       FD_SET(connection, &SavedAllClients);
+       FD_SET(connection, &SavedAllSockets);
+       if (FD_ISSET(connection, &IgnoredClientsWithInput))
+           FD_SET(connection, &SavedClientsWithInput);
+    }
+}
+
+/* make client impervious to grabs; assume only executing client calls this */
+
+MakeClientGrabImpervious(client)
+    ClientPtr client;
+{
+    OsCommPtr oc = (OsCommPtr)client->osPrivate;
+    int connection = oc->fd;
+
+    FD_SET(connection, &GrabImperviousClients);
+
+    if (ServerGrabCallback)
+    {
+       ServerGrabInfoRec grabinfo;
+       grabinfo.client = client;
+       grabinfo.grabstate  = CLIENT_IMPERVIOUS;
+       CallCallbacks(&ServerGrabCallback, &grabinfo);
+    }
+}
+
+/* make client pervious to grabs; assume only executing client calls this */
+
+MakeClientGrabPervious(client)
+    ClientPtr client;
+{
+    OsCommPtr oc = (OsCommPtr)client->osPrivate;
+    int connection = oc->fd;
+
+    FD_CLR(connection, &GrabImperviousClients);
+    if (GrabInProgress && (GrabInProgress != client->index))
+    {
+       if (FD_ISSET(connection, &ClientsWithInput))
+       {
+           FD_SET(connection, &SavedClientsWithInput);
+           FD_CLR(connection, &ClientsWithInput);
+       }
+       FD_CLR(connection, &AllSockets);
+       FD_CLR(connection, &AllClients);
+       isItTimeToYield = TRUE;
+    }
+
+    if (ServerGrabCallback)
+    {
+       ServerGrabInfoRec grabinfo;
+       grabinfo.client = client;
+       grabinfo.grabstate  = CLIENT_PERVIOUS;
+       CallCallbacks(&ServerGrabCallback, &grabinfo);
+    }
+}
diff --git a/Xserver/programs/Xserver/os/decompress.c b/Xserver/programs/Xserver/os/decompress.c
new file mode 100644 (file)
index 0000000..d7f471b
--- /dev/null
@@ -0,0 +1,388 @@
+/* $XConsortium: decompress.c,v 1.5 94/04/17 20:26:57 dpw Exp $ */
+/*
+
+Copyright (c) 1990  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be included
+in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR
+OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall
+not be used in advertising or otherwise to promote the sale, use or
+other dealings in this Software without prior written authorization
+from the X Consortium.
+
+*/
+
+
+/* 
+ * decompress - cat a compressed file
+ */
+
+#include <stdio.h>
+
+#ifdef TEST
+#define xalloc(s)   malloc(s)
+#define xfree(s)    free(s)
+
+typedef char   *FID;
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <ctype.h>
+
+#else
+#include    "Xos.h"
+#include    "misc.h"
+#endif
+
+#define BITS   16
+
+/*
+ * a code_int must be able to hold 2**BITS values of type int, and also -1
+ */
+#if BITS > 15
+typedef long int       code_int;
+#else
+typedef int            code_int;
+#endif
+
+typedef long int         count_int;
+
+#ifdef NO_UCHAR
+ typedef char  char_type;
+#else
+ typedef       unsigned char   char_type;
+#endif /* UCHAR */
+
+static char_type magic_header[] = { "\037\235" };      /* 1F 9D */
+
+/* Defines for third byte of header */
+#define BIT_MASK       0x1f
+#define BLOCK_MASK     0x80
+/* Masks 0x40 and 0x20 are free.  I think 0x20 should mean that there is
+   a fourth header byte (for expansion).
+*/
+
+#define INIT_BITS 9                    /* initial number of bits/code */
+
+#ifdef COMPATIBLE              /* But wrong! */
+# define MAXCODE(n_bits)       (1 << (n_bits) - 1)
+#else
+# define MAXCODE(n_bits)       ((1 << (n_bits)) - 1)
+#endif /* COMPATIBLE */
+
+static code_int getcode();
+
+/*
+ * the next two codes should not be changed lightly, as they must not
+ * lie within the contiguous general code space.
+ */ 
+#define FIRST  257     /* first free entry */
+#define        CLEAR   256     /* table clear output code */
+
+#define STACK_SIZE  8192
+
+typedef struct _compressedFILE {
+    FILE       *file;
+
+    char_type      *stackp;
+    code_int       oldcode;
+    char_type      finchar;
+
+    int                block_compress;
+    int                maxbits;
+    code_int   maxcode, maxmaxcode;
+
+    code_int   free_ent;
+    int                clear_flg;
+    int                n_bits;
+
+    /* bit buffer */
+    int                offset, size;
+    char_type  buf[BITS];
+
+    char_type      de_stack[STACK_SIZE];
+    char_type      *tab_suffix;
+    unsigned short  *tab_prefix;
+} CompressedFile;
+
+static int hsize_table[] = {
+    5003,      /* 12 bits - 80% occupancy */
+    9001,      /* 13 bits - 91% occupancy */
+    18013,     /* 14 bits - 91% occupancy */
+    35023,     /* 15 bits - 94% occupancy */
+    69001      /* 16 bits - 95% occupancy */
+};
+
+FID
+CompressedFontFileInit (f)
+    FILE       *f;
+{
+    int                    code;
+    int                    maxbits;
+    int                    hsize;
+    CompressedFile  *file;
+    int                    extra;
+
+    if ((getc(f) != (magic_header[0] & 0xFF)) ||
+       (getc(f) != (magic_header[1] & 0xFF)))
+    {
+       return 0;
+    }
+    code = getc (f);
+    maxbits = code & BIT_MASK;
+    if (maxbits > BITS || maxbits < 12)
+       return 0;
+    hsize = hsize_table[maxbits - 12];
+    extra = (1 << maxbits) * sizeof (char_type) +
+           hsize * sizeof (unsigned short);
+    file = (CompressedFile *) xalloc (sizeof (CompressedFile) + extra);
+    if (!file)
+       return 0;
+    file->file = f;
+    file->maxbits = maxbits;
+    file->block_compress = code & BLOCK_MASK;
+    file->maxmaxcode = 1 << file->maxbits;
+    file->tab_suffix = (char_type *) &file[1];
+    file->tab_prefix = (unsigned short *) (file->tab_suffix + file->maxmaxcode);
+    /*
+     * As above, initialize the first 256 entries in the table.
+     */
+    file->maxcode = MAXCODE(file->n_bits = INIT_BITS);
+    for ( code = 255; code >= 0; code-- ) {
+       file->tab_prefix[code] = 0;
+       file->tab_suffix[code] = (char_type) code;
+    }
+    file->free_ent = ((file->block_compress) ? FIRST : 256 );
+    file->clear_flg = 0;
+    file->offset = 0;
+    file->size = 0;
+    file->stackp = file->de_stack;
+    file->finchar = file->oldcode = getcode (file);
+    if (file->oldcode != -1)
+       *file->stackp++ = file->finchar;
+    return (FID) file;
+}
+
+FILE *
+CompressedFontFileDone (fid)
+    FID                    fid;
+{
+    CompressedFile  *file;
+    FILE    *f;
+
+    file = (CompressedFile *) fid;
+    f = file->file;
+    xfree (file);
+    return f;
+}
+
+#define getdcchar(file)    ((file)->stackp > (file)->de_stack ? (*--((file)->stackp)) : _filldcbuf (file))
+
+_filldcbuf (file)
+    CompressedFile  *file;
+{
+    register char_type *stackp;
+    register code_int code, incode;
+
+    if (file->stackp > file->de_stack)
+       return *--file->stackp;
+
+    if (file->oldcode == -1)
+       return EOF;
+
+    stackp = file->stackp;
+    code = getcode (file);
+    if (code == -1)
+       return EOF;
+
+    if ( (code == CLEAR) && file->block_compress ) {
+       for ( code = 255; code >= 0; code-- )
+           file->tab_prefix[code] = 0;
+       file->clear_flg = 1;
+       file->free_ent = FIRST - 1;
+       if ( (code = getcode (file)) == -1 )    /* O, untimely death! */
+           return EOF;
+    }
+    incode = code;
+    /*
+     * Special case for KwKwK string.
+     */
+    if ( code >= file->free_ent ) {
+       *stackp++ = file->finchar;
+       code = file->oldcode;
+    }
+
+    /*
+     * Generate output characters in reverse order
+     */
+    while ( code >= 256 )
+    {
+       *stackp++ = file->tab_suffix[code];
+       code = file->tab_prefix[code];
+    }
+    file->finchar = file->tab_suffix[code];
+
+    /*
+     * Generate the new entry.
+     */
+    if ( (code=file->free_ent) < file->maxmaxcode ) {
+       file->tab_prefix[code] = (unsigned short)file->oldcode;
+       file->tab_suffix[code] = file->finchar;
+       file->free_ent = code+1;
+    } 
+    /*
+     * Remember previous code.
+     */
+    file->oldcode = incode;
+    file->stackp = stackp;
+    return file->finchar;
+}
+
+/*****************************************************************
+ * TAG( getcode )
+ *
+ * Read one code from the standard input.  If EOF, return -1.
+ * Inputs:
+ *     stdin
+ * Outputs:
+ *     code or -1 is returned.
+ */
+
+static char_type rmask[9] = {0x00, 0x01, 0x03, 0x07, 0x0f, 0x1f, 0x3f, 0x7f, 0xff};
+
+static code_int
+getcode(file)
+    CompressedFile  *file;
+{
+    register code_int code;
+    register int r_off, bits;
+    register char_type *bp = file->buf;
+    register FILE   *fp;
+
+    if ( file->clear_flg > 0 || file->offset >= file->size ||
+       file->free_ent > file->maxcode )
+    {
+       /*
+        * If the next entry will be too big for the current code
+        * size, then we must increase the size.  This implies reading
+        * a new buffer full, too.
+        */
+       if ( file->free_ent > file->maxcode ) {
+           file->n_bits++;
+           if ( file->n_bits == file->maxbits )
+               file->maxcode = file->maxmaxcode;       /* won't get any bigger now */
+           else
+               file->maxcode = MAXCODE(file->n_bits);
+       }
+       if ( file->clear_flg > 0) {
+           file->maxcode = MAXCODE (file->n_bits = INIT_BITS);
+           file->clear_flg = 0;
+       }
+       bits = file->n_bits;
+       fp = file->file;
+       while (bits > 0 && (code = getc (fp)) != EOF)
+       {
+           *bp++ = code;
+           --bits;
+       }
+       bp = file->buf;
+       if (bits == file->n_bits)
+           return -1;                  /* end of file */
+       file->size = file->n_bits - bits;
+       file->offset = 0;
+       /* Round size down to integral number of codes */
+       file->size = (file->size << 3) - (file->n_bits - 1);
+    }
+    r_off = file->offset;
+    bits = file->n_bits;
+    /*
+     * Get to the first byte.
+     */
+    bp += (r_off >> 3);
+    r_off &= 7;
+    /* Get first part (low order bits) */
+#ifdef NO_UCHAR
+    code = ((*bp++ >> r_off) & rmask[8 - r_off]) & 0xff;
+#else
+    code = (*bp++ >> r_off);
+#endif /* NO_UCHAR */
+    bits -= (8 - r_off);
+    r_off = 8 - r_off;         /* now, offset into code word */
+    /* Get any 8 bit parts in the middle (<=1 for up to 16 bits). */
+    if ( bits >= 8 ) {
+#ifdef NO_UCHAR
+       code |= (*bp++ & 0xff) << r_off;
+#else
+       code |= *bp++ << r_off;
+#endif /* NO_UCHAR */
+       r_off += 8;
+       bits -= 8;
+    }
+    /* high order bits. */
+    code |= (*bp & rmask[bits]) << r_off;
+    file->offset += file->n_bits;
+
+    return code;
+}
+
+CompressedFontFileRead (buf, itemsize, nitems, fid)
+    char       *buf;
+    unsigned   itemsize;
+    unsigned   nitems;
+    FID                fid;
+{
+    CompressedFile  *file;
+    int                    c;
+    int                    nbytes;
+
+    file = (CompressedFile *) fid;
+    nbytes = nitems * itemsize;
+    while (nbytes)
+    {
+       if ((c = getdcchar (file)) == EOF)
+           break;
+       *buf++ = c;
+       --nbytes;
+    }
+    return nitems - nbytes / itemsize;
+}
+
+CompressedFontFileSkip (bytes, fid)
+    unsigned   bytes;
+    FID                fid;
+{
+    int            c;
+
+    while (bytes-- && ((c = getdcchar((CompressedFile *)fid)) != EOF))
+           ;
+    return c;
+}
+
+#ifdef TEST
+main ()
+{
+    CompressedFile  *input;
+    int                    c;
+    
+    input = (CompressedFile *) CompressedFontFileInit (stdin);
+    while ((c = getdcchar (input)) != -1)
+       putchar (c);
+}
+#endif
diff --git a/Xserver/programs/Xserver/os/genalloca.c b/Xserver/programs/Xserver/os/genalloca.c
new file mode 100644 (file)
index 0000000..ae4d2d7
--- /dev/null
@@ -0,0 +1,189 @@
+/*
+       alloca -- (mostly) portable public-domain implementation -- D A Gwyn
+
+       This implementation of the PWB library alloca() function,
+       which is used to allocate space off the run-time stack so
+       that it is automatically reclaimed upon procedure exit, 
+       was inspired by discussions with J. Q. Johnson of Cornell.
+
+       It should work under any C implementation that uses an
+       actual procedure stack (as opposed to a linked list of
+       frames).  There are some preprocessor constants that can
+       be defined when compiling for your specific system, for
+       improved efficiency; however, the defaults should be okay.
+
+       The general concept of this implementation is to keep
+       track of all alloca()-allocated blocks, and reclaim any
+       that are found to be deeper in the stack than the current
+       invocation.  This heuristic does not reclaim storage as
+       soon as it becomes invalid, but it will do so eventually.
+
+       As a special case, alloca(0) reclaims storage without
+       allocating any.  It is a good idea to use alloca(0) in
+       your main control loop, etc. to force garbage collection.
+*/
+#ifndef lint
+static char    SCCSid[] = "@(#)alloca.c        1.1";   /* for the "what" utility */
+#endif
+
+#ifdef emacs
+#include "config.h"
+#ifdef static
+/* actually, only want this if static is defined as ""
+   -- this is for usg, in which emacs must undefine static
+   in order to make unexec workable
+   */
+#ifndef STACK_DIRECTION
+you
+lose
+-- must know STACK_DIRECTION at compile-time
+#endif /* STACK_DIRECTION undefined */
+#endif /* static */
+#endif /* emacs */
+
+#ifdef X3J11
+typedef void   *pointer;               /* generic pointer type */
+#else
+typedef char   *pointer;               /* generic pointer type */
+#endif
+
+#define        NULL    0                       /* null pointer constant */
+
+extern void    Xfree();
+extern pointer Xalloc();
+
+/*
+       Define STACK_DIRECTION if you know the direction of stack
+       growth for your system; otherwise it will be automatically
+       deduced at run-time.
+
+       STACK_DIRECTION > 0 => grows toward higher addresses
+       STACK_DIRECTION < 0 => grows toward lower addresses
+       STACK_DIRECTION = 0 => direction of growth unknown
+*/
+
+#ifndef STACK_DIRECTION
+#define        STACK_DIRECTION 0               /* direction unknown */
+#endif
+
+#if STACK_DIRECTION != 0
+
+#define        STACK_DIR       STACK_DIRECTION /* known at compile-time */
+
+#else  /* STACK_DIRECTION == 0; need run-time code */
+
+static int     stack_dir;              /* 1 or -1 once known */
+#define        STACK_DIR       stack_dir
+
+static void
+find_stack_direction (/* void */)
+{
+  static char  *addr = NULL;   /* address of first
+                                  `dummy', once known */
+  auto char    dummy;          /* to get stack address */
+
+  if (addr == NULL)
+    {                          /* initial entry */
+      addr = &dummy;
+
+      find_stack_direction (); /* recurse once */
+    }
+  else                         /* second entry */
+    if (&dummy > addr)
+      stack_dir = 1;           /* stack grew upward */
+    else
+      stack_dir = -1;          /* stack grew downward */
+}
+
+#endif /* STACK_DIRECTION == 0 */
+
+/*
+       An "alloca header" is used to:
+       (a) chain together all alloca()ed blocks;
+       (b) keep track of stack depth.
+
+       It is very important that sizeof(header) agree with malloc()
+       alignment chunk size.  The following default should work okay.
+*/
+
+#ifndef        ALIGN_SIZE
+#define        ALIGN_SIZE      sizeof(double)
+#endif
+
+typedef union hdr
+{
+  char align[ALIGN_SIZE];      /* to force sizeof(header) */
+  struct
+    {
+      union hdr *next;         /* for chaining headers */
+      char *deep;              /* for stack depth measure */
+    } h;
+} header;
+
+/*
+       alloca( size ) returns a pointer to at least `size' bytes of
+       storage which will be automatically reclaimed upon exit from
+       the procedure that called alloca().  Originally, this space
+       was supposed to be taken from the current stack frame of the
+       caller, but that method cannot be made to work for some
+       implementations of C, for example under Gould's UTX/32.
+*/
+
+static header *last_alloca_header = NULL; /* -> last alloca header */
+
+pointer
+alloca (size)                  /* returns pointer to storage */
+     unsigned  size;           /* # bytes to allocate */
+{
+  auto char    probe;          /* probes stack depth: */
+  register char        *depth = &probe;
+
+#if STACK_DIRECTION == 0
+  if (STACK_DIR == 0)          /* unknown growth direction */
+    find_stack_direction ();
+#endif
+
+                               /* Reclaim garbage, defined as all alloca()ed storage that
+                                  was allocated from deeper in the stack than currently. */
+
+  {
+    register header    *hp;    /* traverses linked list */
+
+    for (hp = last_alloca_header; hp != NULL;)
+      if (STACK_DIR > 0 && hp->h.deep > depth
+         || STACK_DIR < 0 && hp->h.deep < depth)
+       {
+         register header       *np = hp->h.next;
+
+         Xfree ((pointer) hp); /* collect garbage */
+
+         hp = np;              /* -> next header */
+       }
+      else
+       break;                  /* rest are not deeper */
+
+    last_alloca_header = hp;   /* -> last valid storage */
+  }
+
+  if (size == 0)
+    return NULL;               /* no allocation required */
+
+  /* Allocate combined header + user data storage. */
+
+  {
+    register pointer   new = Xalloc (sizeof (header) + size);
+    if (!new)
+       return NULL;
+    /* address of header */
+
+    ((header *)new)->h.next = last_alloca_header;
+    ((header *)new)->h.deep = depth;
+
+    last_alloca_header = (header *)new;
+
+    /* User storage begins just after header. */
+
+    return (pointer)((char *)new + sizeof(header));
+  }
+}
+
diff --git a/Xserver/programs/Xserver/os/hpsocket.c b/Xserver/programs/Xserver/os/hpsocket.c
new file mode 100644 (file)
index 0000000..971ace6
--- /dev/null
@@ -0,0 +1,68 @@
+/* $XConsortium: hpsocket.c,v 1.3 94/04/17 20:26:58 dpw Exp $ */
+/*
+
+Copyright (c) 1988  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be included
+in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR
+OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall
+not be used in advertising or otherwise to promote the sale, use or
+other dealings in this Software without prior written authorization
+from the X Consortium.
+
+*/
+
+/*
+ * special socket routine for hp
+ */
+
+#include <sys/types.h>
+#include <sys/socket.h>
+
+int
+set_socket_option (socket_id, option)
+int socket_id;
+char option;
+{
+       int optlen = 1;
+       char optval = 0x0;
+
+       getsockopt (socket_id, SOL_SOCKET, option, &optval, &optlen);
+
+       optval |= option;
+
+       setsockopt (socket_id, SOL_SOCKET, option, &optval, 1);
+}
+
+
+int
+unset_socket_option (socket_id, option)
+int socket_id;
+char option;
+{
+       int optlen = 1;
+       char optval = 0x0;
+
+       getsockopt (socket_id, SOL_SOCKET, option, &optval, &optlen);
+
+       optval &= ~option;
+
+       setsockopt (socket_id, SOL_SOCKET, option, &optval, 1);
+}
diff --git a/Xserver/programs/Xserver/os/io.c b/Xserver/programs/Xserver/os/io.c
new file mode 100644 (file)
index 0000000..9f5ea5c
--- /dev/null
@@ -0,0 +1,1259 @@
+/***********************************************************
+
+Copyright (c) 1987, 1989  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+
+Copyright 1987, 1989 by Digital Equipment Corporation, Maynard, Massachusetts.
+
+                        All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and its 
+documentation for any purpose and without fee is hereby granted, 
+provided that the above copyright notice appear in all copies and that
+both that copyright notice and this permission notice appear in 
+supporting documentation, and that the name of Digital not be
+used in advertising or publicity pertaining to distribution of the
+software without specific, written prior permission.  
+
+DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
+ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
+DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
+ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+SOFTWARE.
+
+******************************************************************/
+/* $XConsortium: io.c /main/72 1996/12/27 15:40:56 rws $ */
+/* $XFree86: xc/programs/Xserver/os/io.c,v 3.15 1997/01/18 06:58:00 dawes Exp $ */
+/*****************************************************************
+ * i/o functions
+ *
+ *   WriteToClient, ReadRequestFromClient
+ *   InsertFakeRequest, ResetCurrentRequest
+ *
+ *****************************************************************/
+
+#ifdef WIN32
+#include <X11/Xwinsock.h>
+#endif
+#include <stdio.h>
+#include <X11/Xtrans.h>
+#ifdef X_NOT_STDC_ENV
+extern int errno;
+#endif
+#include "Xmd.h"
+#include <errno.h>
+#if !defined(AMOEBA) && !defined(MINIX) && !defined(__EMX__) && !defined(WIN32)
+#ifndef Lynx
+#include <sys/uio.h>
+#else
+#include <uio.h>
+#endif
+#endif
+#include "X.h"
+#define NEED_REPLIES
+#include "Xproto.h"
+#include "os.h"
+#include "Xpoll.h"
+#include "osdep.h"
+#include "opaque.h"
+#include "dixstruct.h"
+#include "misc.h"
+#ifdef LBX
+#include "lbxserve.h"
+#endif
+
+CallbackListPtr       ReplyCallback;
+CallbackListPtr       FlushCallback;
+
+/* check for both EAGAIN and EWOULDBLOCK, because some supposedly POSIX
+ * systems are broken and return EWOULDBLOCK when they should return EAGAIN
+ */
+#ifndef __EMX__
+#if defined(EAGAIN) && defined(EWOULDBLOCK)
+#define ETEST(err) (err == EAGAIN || err == EWOULDBLOCK)
+#else
+#ifdef EAGAIN
+#define ETEST(err) (err == EAGAIN)
+#else
+#define ETEST(err) (err == EWOULDBLOCK)
+#endif
+#endif
+#else /* __EMX__  Writing to full pipes may return ENOSPC */
+#define ETEST(err) (err == EAGAIN || err == EWOULDBLOCK || err == ENOSPC)
+#endif
+
+extern fd_set ClientsWithInput, IgnoredClientsWithInput, AllClients;
+extern fd_set ClientsWriteBlocked;
+extern fd_set OutputPending;
+extern int ConnectionTranslation[];
+extern Bool NewOutputPending;
+extern Bool AnyClientsWriteBlocked;
+
+Bool CriticalOutputPending;
+int timesThisConnection = 0;
+ConnectionInputPtr FreeInputs = (ConnectionInputPtr)NULL;
+ConnectionOutputPtr FreeOutputs = (ConnectionOutputPtr)NULL;
+OsCommPtr AvailableInput = (OsCommPtr)NULL;
+
+#define get_req_len(req,cli) ((cli)->swapped ? \
+                             lswaps((req)->length) : (req)->length)
+
+#ifdef BIGREQS
+#include "bigreqstr.h"
+
+#define get_big_req_len(req,cli) ((cli)->swapped ? \
+                                 lswapl(((xBigReq *)(req))->length) : \
+                                 ((xBigReq *)(req))->length)
+#endif
+
+#define MAX_TIMES_PER         10
+
+/*
+ *   A lot of the code in this file manipulates a ConnectionInputPtr:
+ *
+ *    -----------------------------------------------
+ *   |------- bufcnt ------->|           |           |
+ *   |           |- gotnow ->|           |           |
+ *   |           |-------- needed ------>|           |
+ *   |-----------+--------- size --------+---------->|
+ *    -----------------------------------------------
+ *   ^           ^
+ *   |           |
+ *   buffer   bufptr
+ *
+ *  buffer is a pointer to the start of the buffer.
+ *  bufptr points to the start of the current request.
+ *  bufcnt counts how many bytes are in the buffer.
+ *  size is the size of the buffer in bytes.
+ *
+ *  In several of the functions, gotnow and needed are local variables
+ *  that do the following:
+ *
+ *  gotnow is the number of bytes of the request that we're
+ *  trying to read that are currently in the buffer.
+ *  Typically, gotnow = (buffer + bufcnt) - bufptr
+ *
+ *  needed = the length of the request that we're trying to
+ *  read.  Watch out: needed sometimes counts bytes and sometimes
+ *  counts CARD32's.
+ */
+
+
+/*****************************************************************
+ * ReadRequestFromClient
+ *    Returns one request in client->requestBuffer.  The request
+ *    length will be in client->req_len.  Return status is:
+ *
+ *    > 0  if  successful, specifies length in bytes of the request
+ *    = 0  if  entire request is not yet available
+ *    < 0  if  client should be terminated
+ *
+ *    The request returned must be contiguous so that it can be
+ *    cast in the dispatcher to the correct request type.  Because requests
+ *    are variable length, ReadRequestFromClient() must look at the first 4
+ *    or 8 bytes of a request to determine the length (the request length is
+ *    in the 3rd and 4th bytes of the request unless it is a Big Request
+ *    (see the Big Request Extension), in which case the 3rd and 4th bytes
+ *    are zero and the following 4 bytes are the request length.
+ *
+ *    Note: in order to make the server scheduler (WaitForSomething())
+ *    "fair", the ClientsWithInput mask is used.  This mask tells which
+ *    clients have FULL requests left in their buffers.  Clients with
+ *    partial requests require a read.  Basically, client buffers
+ *    are drained before select() is called again.  But, we can't keep
+ *    reading from a client that is sending buckets of data (or has
+ *    a partial request) because others clients need to be scheduled.
+ *****************************************************************/
+
+#define YieldControl()                         \
+        { isItTimeToYield = TRUE;              \
+         timesThisConnection = 0; }
+#define YieldControlNoInput()                  \
+        { YieldControl();                      \
+         FD_CLR(fd, &ClientsWithInput); }
+#define YieldControlDeath()                    \
+        { timesThisConnection = 0; }
+
+#if defined(LBX) || defined(LBX_COMPAT)
+int
+StandardReadRequestFromClient(client)
+    ClientPtr client;
+#else
+int
+ReadRequestFromClient(client)
+    ClientPtr client;
+#endif
+{
+    OsCommPtr oc = (OsCommPtr)client->osPrivate;
+    register ConnectionInputPtr oci = oc->input;
+    int fd = oc->fd;
+    register int gotnow, needed;
+    int result;
+    register xReq *request;
+    Bool need_header;
+#ifdef BIGREQS
+    Bool move_header;
+#endif
+
+    /* If an input buffer was empty, either free it if it is too big
+     * or link it into our list of free input buffers.  This means that
+     * different clients can share the same input buffer (at different
+     * times).  This was done to save memory.
+     */
+
+    if (AvailableInput)
+    {
+       if (AvailableInput != oc)
+       {
+           register ConnectionInputPtr aci = AvailableInput->input;
+           if (aci->size > BUFWATERMARK)
+           {
+               xfree(aci->buffer);
+               xfree(aci);
+           }
+           else
+           {
+               aci->next = FreeInputs;
+               FreeInputs = aci;
+           }
+           AvailableInput->input = (ConnectionInputPtr)NULL;
+       }
+       AvailableInput = (OsCommPtr)NULL;
+    }
+
+    /* make sure we have an input buffer */
+
+    if (!oci)
+    {
+       if (oci = FreeInputs)
+       {
+           FreeInputs = oci->next;
+       }
+       else if (!(oci = AllocateInputBuffer()))
+       {
+           YieldControlDeath();
+           return -1;
+       }
+       oc->input = oci;
+    }
+
+    /* advance to start of next request */
+
+    oci->bufptr += oci->lenLastReq;
+
+    need_header = FALSE;
+#ifdef BIGREQS
+    move_header = FALSE;
+#endif
+    gotnow = oci->bufcnt + oci->buffer - oci->bufptr;
+    if (gotnow < sizeof(xReq))
+    {
+       /* We don't have an entire xReq yet.  Can't tell how big
+        * the request will be until we get the whole xReq.
+        */
+       needed = sizeof(xReq);
+       need_header = TRUE;
+    }
+    else
+    {
+       /* We have a whole xReq.  We can tell how big the whole
+        * request will be unless it is a Big Request.
+        */
+       request = (xReq *)oci->bufptr;
+       needed = get_req_len(request, client);
+#ifdef BIGREQS
+       if (!needed && client->big_requests)
+       {
+           /* It's a Big Request. */
+           move_header = TRUE;
+           if (gotnow < sizeof(xBigReq))
+           {
+               /* Still need more data to tell just how big. */
+               needed = sizeof(xBigReq) >> 2; /* needed is in CARD32s now */
+               need_header = TRUE;
+           }
+           else
+               needed = get_big_req_len(request, client);
+       }
+#endif
+       client->req_len = needed;
+       needed <<= 2; /* needed is in bytes now */
+    }
+    if (gotnow < needed)
+    {
+       /* Need to read more data, either so that we can get a
+        * complete xReq (if need_header is TRUE), a complete
+        * xBigReq (if move_header is TRUE), or the rest of the
+        * request (if need_header and move_header are both FALSE).
+        */
+
+       oci->lenLastReq = 0;
+       if (needed > MAXBUFSIZE)
+       {
+           /* request is too big for us to handle */
+           YieldControlDeath();
+           return -1;
+       }
+       if ((gotnow == 0) ||
+           ((oci->bufptr - oci->buffer + needed) > oci->size))
+       {
+           /* no data, or the request is too big to fit in the buffer */
+
+           if ((gotnow > 0) && (oci->bufptr != oci->buffer))
+               /* save the data we've already read */
+               memmove(oci->buffer, oci->bufptr, gotnow);
+           if (needed > oci->size)
+           {
+               /* make buffer bigger to accomodate request */
+               char *ibuf;
+
+               ibuf = (char *)xrealloc(oci->buffer, needed);
+               if (!ibuf)
+               {
+                   YieldControlDeath();
+                   return -1;
+               }
+               oci->size = needed;
+               oci->buffer = ibuf;
+           }
+           oci->bufptr = oci->buffer;
+           oci->bufcnt = gotnow;
+       }
+       /*  XXX this is a workaround.  This function is sometimes called
+        *  after the trans_conn has been freed.  In this case trans_conn
+        *  will be null.  Really ought to restructure things so that we
+        *  never get here in those circumstances.
+        */
+       if (!oc->trans_conn)
+       {
+           /*  treat as if an error occured on the read, which is what
+            *  used to happen
+            */
+           YieldControlDeath();
+           return -1;
+       }
+#ifdef LBX
+       if (oc->proxy && oc->proxy->compHandle)
+           result = (*oc->proxy->streamOpts.streamCompRead)(fd,
+                            (unsigned char *)oci->buffer + oci->bufcnt,
+                            oci->size - oci->bufcnt);
+       else
+#endif
+           result = _XSERVTransRead(oc->trans_conn, oci->buffer + oci->bufcnt,
+                                    oci->size - oci->bufcnt); 
+       if (result <= 0)
+       {
+           if ((result < 0) && ETEST(errno))
+           {
+#if defined(SVR4) && defined(i386) && !defined(sun)
+#if defined(LBX) && 0
+               /*
+                * For LBX connections, we can get a valid EWOULDBLOCK
+                * There is probably a better way of distinguishing LBX
+                * connections, but this works. (DHD)
+                */
+               extern int LbxRead();
+               if (oc->Read == LbxRead)
+#else
+               if (0)
+#endif
+#endif
+               {
+                   YieldControlNoInput();
+                   return 0;
+               }
+           }
+           YieldControlDeath();
+           return -1;
+       }
+       oci->bufcnt += result;
+       gotnow += result;
+       /* free up some space after huge requests */
+       if ((oci->size > BUFWATERMARK) &&
+           (oci->bufcnt < BUFSIZE) && (needed < BUFSIZE))
+       {
+           char *ibuf;
+
+           ibuf = (char *)xrealloc(oci->buffer, BUFSIZE);
+           if (ibuf)
+           {
+               oci->size = BUFSIZE;
+               oci->buffer = ibuf;
+               oci->bufptr = ibuf + oci->bufcnt - gotnow;
+           }
+       }
+       if (need_header && gotnow >= needed)
+       {
+           /* We wanted an xReq, now we've gotten it. */
+           request = (xReq *)oci->bufptr;
+           needed = get_req_len(request, client);
+#ifdef BIGREQS
+           if (!needed && client->big_requests)
+           {
+               move_header = TRUE;
+               if (gotnow < sizeof(xBigReq))
+                   needed = sizeof(xBigReq) >> 2;
+               else
+                   needed = get_big_req_len(request, client);
+           }
+#endif
+           client->req_len = needed;
+           needed <<= 2;
+       }
+       if (gotnow < needed)
+       {
+           /* Still don't have enough; punt. */
+           YieldControlNoInput();
+           return 0;
+       }
+    }
+    if (needed == 0)
+    {
+#ifdef BIGREQS
+       if (client->big_requests)
+           needed = sizeof(xBigReq);
+       else
+#endif
+           needed = sizeof(xReq);
+    }
+    oci->lenLastReq = needed;
+
+    /*
+     *  Check to see if client has at least one whole request in the
+     *  buffer beyond the request we're returning to the caller.
+     *  If there is only a partial request, treat like buffer
+     *  is empty so that select() will be called again and other clients
+     *  can get into the queue.   
+     */
+
+    gotnow -= needed;
+    if (gotnow >= sizeof(xReq)) 
+    {
+       request = (xReq *)(oci->bufptr + needed);
+       if (gotnow >= (result = (get_req_len(request, client) << 2))
+#ifdef BIGREQS
+           && (result ||
+               (client->big_requests &&
+                (gotnow >= sizeof(xBigReq) &&
+                 gotnow >= (get_big_req_len(request, client) << 2))))
+#endif
+           )
+           FD_SET(fd, &ClientsWithInput);
+       else
+           YieldControlNoInput();
+    }
+    else
+    {
+       if (!gotnow)
+           AvailableInput = oc;
+       YieldControlNoInput();
+    }
+    if (++timesThisConnection >= MAX_TIMES_PER)
+       YieldControl();
+#ifdef BIGREQS
+    if (move_header)
+    {
+       request = (xReq *)oci->bufptr;
+       oci->bufptr += (sizeof(xBigReq) - sizeof(xReq));
+       *(xReq *)oci->bufptr = *request;
+       oci->lenLastReq -= (sizeof(xBigReq) - sizeof(xReq));
+       client->req_len -= (sizeof(xBigReq) - sizeof(xReq)) >> 2;
+    }
+#endif
+    client->requestBuffer = (pointer)oci->bufptr;
+    return needed;
+}
+
+/*****************************************************************
+ * InsertFakeRequest
+ *    Splice a consed up (possibly partial) request in as the next request.
+ *
+ **********************/
+
+Bool
+InsertFakeRequest(client, data, count)
+    ClientPtr client;
+    char *data;
+    int count;
+{
+    OsCommPtr oc = (OsCommPtr)client->osPrivate;
+    register ConnectionInputPtr oci = oc->input;
+    int fd = oc->fd;
+    register int gotnow, moveup;
+
+    if (AvailableInput)
+    {
+       if (AvailableInput != oc)
+       {
+           register ConnectionInputPtr aci = AvailableInput->input;
+           if (aci->size > BUFWATERMARK)
+           {
+               xfree(aci->buffer);
+               xfree(aci);
+           }
+           else
+           {
+               aci->next = FreeInputs;
+               FreeInputs = aci;
+           }
+           AvailableInput->input = (ConnectionInputPtr)NULL;
+       }
+       AvailableInput = (OsCommPtr)NULL;
+    }
+    if (!oci)
+    {
+       if (oci = FreeInputs)
+           FreeInputs = oci->next;
+       else if (!(oci = AllocateInputBuffer()))
+           return FALSE;
+       oc->input = oci;
+    }
+    oci->bufptr += oci->lenLastReq;
+    oci->lenLastReq = 0;
+    gotnow = oci->bufcnt + oci->buffer - oci->bufptr;
+    if ((gotnow + count) > oci->size)
+    {
+       char *ibuf;
+
+       ibuf = (char *)xrealloc(oci->buffer, gotnow + count);
+       if (!ibuf)
+           return(FALSE);
+       oci->size = gotnow + count;
+       oci->buffer = ibuf;
+       oci->bufptr = ibuf + oci->bufcnt - gotnow;
+    }
+    moveup = count - (oci->bufptr - oci->buffer);
+    if (moveup > 0)
+    {
+       if (gotnow > 0)
+           memmove(oci->bufptr + moveup, oci->bufptr, gotnow);
+       oci->bufptr += moveup;
+       oci->bufcnt += moveup;
+    }
+    memmove(oci->bufptr - count, data, count);
+    oci->bufptr -= count;
+    gotnow += count;
+    if ((gotnow >= sizeof(xReq)) &&
+       (gotnow >= (int)(get_req_len((xReq *)oci->bufptr, client) << 2)))
+       FD_SET(fd, &ClientsWithInput);
+    else
+       YieldControlNoInput();
+    return(TRUE);
+}
+
+/*****************************************************************
+ * ResetRequestFromClient
+ *    Reset to reexecute the current request, and yield.
+ *
+ **********************/
+
+ResetCurrentRequest(client)
+    ClientPtr client;
+{
+    OsCommPtr oc = (OsCommPtr)client->osPrivate;
+    register ConnectionInputPtr oci = oc->input;
+    int fd = oc->fd;
+    register xReq *request;
+    int gotnow, needed;
+#ifdef LBX
+    Bool part;
+    LbxClientPtr lbxClient = LbxClient(client);
+
+    if (lbxClient) {
+       LbxSetForBlock(lbxClient);
+       if (!oci) {
+           AppendFakeRequest(client,
+                             client->requestBuffer, client->req_len << 2);
+           return;
+       }
+    }
+#endif
+    if (AvailableInput == oc)
+       AvailableInput = (OsCommPtr)NULL;
+    oci->lenLastReq = 0;
+    gotnow = oci->bufcnt + oci->buffer - oci->bufptr;
+    if (gotnow < sizeof(xReq))
+    {
+       YieldControlNoInput();
+    }
+    else
+    {
+       request = (xReq *)oci->bufptr;
+       needed = get_req_len(request, client);
+#ifdef BIGREQS
+       if (!needed && client->big_requests)
+       {
+           oci->bufptr -= sizeof(xBigReq) - sizeof(xReq);
+           *(xReq *)oci->bufptr = *request;
+           ((xBigReq *)oci->bufptr)->length = client->req_len;
+           if (client->swapped)
+           {
+               char n;
+               swapl(&((xBigReq *)oci->bufptr)->length, n);
+           }
+       }
+#endif
+       if (gotnow >= (needed << 2))
+       {
+           if (FD_ISSET(fd, &AllClients))
+           {
+               FD_SET(fd, &ClientsWithInput);
+           }
+           else
+           {
+               FD_SET(fd, &IgnoredClientsWithInput);
+           }
+           YieldControl();
+       }
+       else
+           YieldControlNoInput();
+    }
+}
+
+
+
+/*****************************************************************
+ *  PeekNextRequest and SkipRequests were implemented to support DBE 
+ *  idioms, but can certainly be used outside of DBE.  There are two 
+ *  related macros in os.h, ReqLen and CastxReq.  See the porting 
+ *  layer document for more details.
+ *
+ **********************/
+
+
+/*****************************************************************
+ *  PeekNextRequest
+ *      lets you look ahead at the unexecuted requests in a 
+ *      client's request buffer.
+ *
+ *      Note: this implementation of PeekNextRequest ignores the
+ *      readmore parameter.
+ *
+ **********************/
+
+xReqPtr
+PeekNextRequest(req, client, readmore)
+    xReqPtr req;       /* request we're starting from */
+    ClientPtr client;  /* client whose requests we're skipping */
+    Bool readmore;     /* attempt to read more if next request isn't there? */
+{
+    register ConnectionInputPtr oci = ((OsCommPtr)client->osPrivate)->input;
+    xReqPtr pnextreq;
+    int needed, gotnow, reqlen;
+
+    if (!oci) return NULL;
+
+    if (!req)
+    {
+       /* caller wants the request after the one currently being executed */
+       pnextreq = (xReqPtr)
+           (((CARD32 *)client->requestBuffer) + client->req_len);
+    }
+    else
+    {
+       /* caller wants the request after the one specified by req */
+       reqlen = get_req_len(req, client);
+#ifdef BIGREQS
+       if (!reqlen) reqlen = get_big_req_len(req, client);
+#endif
+       pnextreq = (xReqPtr)(((char *)req) + (reqlen << 2));
+    }
+
+    /* see how much of the next request we have available */
+
+    gotnow = oci->bufcnt - (((char *)pnextreq) - oci->buffer);
+
+    if (gotnow < sizeof(xReq))
+       return NULL;
+
+    needed = get_req_len(pnextreq, client) << 2;
+#ifdef BIGREQS
+    if (!needed)
+    {
+       /* it's a big request */
+       if (gotnow < sizeof(xBigReq))
+           return NULL;
+       needed = get_big_req_len(pnextreq, client) << 2;
+    }
+#endif
+
+    /* if we have less than we need, return NULL */
+
+    return (gotnow < needed) ? NULL : pnextreq;
+}
+
+/*****************************************************************
+ *  SkipRequests 
+ *      lets you skip over some of the requests in a client's
+ *      request buffer.  Presumably the caller has used PeekNextRequest
+ *      to examine the requests being skipped and has performed whatever 
+ *      actions they dictate.
+ *
+ **********************/
+
+CallbackListPtr SkippedRequestsCallback = NULL;
+
+void
+SkipRequests(req, client, numskipped)
+    xReqPtr req;       /* last request being skipped */
+    ClientPtr client;   /* client whose requests we're skipping */
+    int numskipped;    /* how many requests we're skipping */
+{
+    OsCommPtr oc = (OsCommPtr)client->osPrivate;
+    register ConnectionInputPtr oci = oc->input;
+    int reqlen;
+
+    /* see if anyone wants to snoop the skipped requests */
+
+    if (SkippedRequestsCallback)
+    {
+       SkippedRequestInfoRec skipinfo;
+       skipinfo.req = req;
+       skipinfo.client = client;
+       skipinfo.numskipped = numskipped;
+       CallCallbacks(&SkippedRequestsCallback, &skipinfo);
+    }
+
+    /* adjust the sequence number */
+    client->sequence += numskipped;
+
+    /* twiddle the oci to skip over the requests */
+
+    reqlen = get_req_len(req, client);
+#ifdef BIGREQS
+    if (!reqlen) reqlen = get_big_req_len(req, client);
+#endif
+    reqlen <<= 2;
+    oci->bufptr = (char *)req;
+    oci->lenLastReq = reqlen;
+
+    /* see if any requests left in the buffer */
+
+    if ( ((char *)req + reqlen) == (oci->buffer + oci->bufcnt) )
+    {
+       /* no requests; mark input buffer as available and client
+        * as having no input
+        */
+       int fd = oc->fd;
+       AvailableInput = oc;
+       YieldControlNoInput();
+    }
+}
+
+
+    /* lookup table for adding padding bytes to data that is read from
+       or written to the X socket.  */
+static int padlength[4] = {0, 3, 2, 1};
+
+ /********************
+ * FlushClient()
+ *    If the client isn't keeping up with us, then we try to continue
+ *    buffering the data and set the apropriate bit in ClientsWritable
+ *    (which is used by WaitFor in the select).  If the connection yields
+ *    a permanent error, or we can't allocate any more space, we then
+ *    close the connection.
+ *
+ **********************/
+
+int
+#ifdef LBX
+StandardFlushClient(who, oc, extraBuf, extraCount)
+#else
+FlushClient(who, oc, extraBuf, extraCount)
+#endif
+    ClientPtr who;
+    OsCommPtr oc;
+    char *extraBuf;
+    int extraCount; /* do not modify... returned below */
+{
+    register ConnectionOutputPtr oco = oc->output;
+    int connection = oc->fd;
+    XtransConnInfo trans_conn = oc->trans_conn;
+    struct iovec iov[3];
+    static char padBuffer[3];
+    long written;
+    long padsize;
+    long notWritten;
+    long todo;
+
+    if (!oco)
+       return 0;
+    written = 0;
+    padsize = padlength[extraCount & 3];
+    notWritten = oco->count + extraCount + padsize;
+    todo = notWritten;
+    while (notWritten) {
+       long before = written;  /* amount of whole thing written */
+       long remain = todo;     /* amount to try this time, <= notWritten */
+       int i = 0;
+       long len;
+
+       /* You could be very general here and have "in" and "out" iovecs
+        * and write a loop without using a macro, but what the heck.  This
+        * translates to:
+        *
+        *     how much of this piece is new?
+        *     if more new then we are trying this time, clamp
+        *     if nothing new
+        *         then bump down amount already written, for next piece
+        *         else put new stuff in iovec, will need all of next piece
+        *
+        * Note that todo had better be at least 1 or else we'll end up
+        * writing 0 iovecs.
+        */
+#define InsertIOV(pointer, length) \
+       len = (length) - before; \
+       if (len > remain) \
+           len = remain; \
+       if (len <= 0) { \
+           before = (-len); \
+       } else { \
+           iov[i].iov_len = len; \
+           iov[i].iov_base = (pointer) + before; \
+           i++; \
+           remain -= len; \
+           before = 0; \
+       }
+
+       InsertIOV ((char *)oco->buf, oco->count)
+       InsertIOV (extraBuf, extraCount)
+       InsertIOV (padBuffer, padsize)
+
+       errno = 0;
+       if (trans_conn && (len = _XSERVTransWritev(trans_conn, iov, i)) >= 0)
+       {
+           written += len;
+           notWritten -= len;
+           todo = notWritten;
+       }
+       else if (ETEST(errno)
+#ifdef SUNSYSV /* check for another brain-damaged OS bug */
+                || (errno == 0)
+#endif
+#ifdef EMSGSIZE /* check for another brain-damaged OS bug */
+                || ((errno == EMSGSIZE) && (todo == 1))
+#endif
+               )
+       {
+           /* If we've arrived here, then the client is stuffed to the gills
+              and not ready to accept more.  Make a note of it and buffer
+              the rest. */
+           FD_SET(connection, &ClientsWriteBlocked);
+           AnyClientsWriteBlocked = TRUE;
+
+           if (written < oco->count)
+           {
+               if (written > 0)
+               {
+                   oco->count -= written;
+                   memmove((char *)oco->buf,
+                           (char *)oco->buf + written,
+                         oco->count);
+                   written = 0;
+               }
+           }
+           else
+           {
+               written -= oco->count;
+               oco->count = 0;
+           }
+
+           if (notWritten > oco->size)
+           {
+               unsigned char *obuf;
+
+               obuf = (unsigned char *)xrealloc(oco->buf,
+                                                notWritten + BUFSIZE);
+               if (!obuf)
+               {
+                   _XSERVTransDisconnect(oc->trans_conn);
+                   _XSERVTransClose(oc->trans_conn);
+                   oc->trans_conn = NULL;
+                   MarkClientException(who);
+                   oco->count = 0;
+                   return(-1);
+               }
+               oco->size = notWritten + BUFSIZE;
+               oco->buf = obuf;
+           }
+
+           /* If the amount written extended into the padBuffer, then the
+              difference "extraCount - written" may be less than 0 */
+           if ((len = extraCount - written) > 0)
+               memmove ((char *)oco->buf + oco->count,
+                        extraBuf + written,
+                      len);
+
+           oco->count = notWritten; /* this will include the pad */
+           /* return only the amount explicitly requested */
+           return extraCount;
+       }
+#ifdef EMSGSIZE /* check for another brain-damaged OS bug */
+       else if (errno == EMSGSIZE)
+       {
+           todo >>= 1;
+       }
+#endif
+       else
+       {
+           if (oc->trans_conn)
+           {
+               _XSERVTransDisconnect(oc->trans_conn);
+               _XSERVTransClose(oc->trans_conn);
+               oc->trans_conn = NULL;
+           }
+           MarkClientException(who);
+           oco->count = 0;
+           return(-1);
+       }
+    }
+
+    /* everything was flushed out */
+    oco->count = 0;
+    /* check to see if this client was write blocked */
+    if (AnyClientsWriteBlocked)
+    {
+       FD_CLR(oc->fd, &ClientsWriteBlocked);
+       if (! XFD_ANYSET(&ClientsWriteBlocked))
+           AnyClientsWriteBlocked = FALSE;
+    }
+    if (oco->size > BUFWATERMARK)
+    {
+       xfree(oco->buf);
+       xfree(oco);
+    }
+    else
+    {
+       oco->next = FreeOutputs;
+       FreeOutputs = oco;
+    }
+    oc->output = (ConnectionOutputPtr)NULL;
+    return extraCount; /* return only the amount explicitly requested */
+}
+
+ /********************
+ * FlushAllOutput()
+ *    Flush all clients with output.  However, if some client still
+ *    has input in the queue (more requests), then don't flush.  This
+ *    will prevent the output queue from being flushed every time around
+ *    the round robin queue.  Now, some say that it SHOULD be flushed
+ *    every time around, but...
+ *
+ **********************/
+
+void
+FlushAllOutput()
+{
+    register int index, base, mask;
+    OsCommPtr oc;
+    register ClientPtr client;
+    Bool newoutput = NewOutputPending;
+#ifdef WIN32
+    fd_set newOutputPending;
+#endif
+
+    if (FlushCallback)
+       CallCallbacks(&FlushCallback, NULL);
+
+    if (!newoutput)
+       return;
+
+    /*
+     * It may be that some client still has critical output pending,
+     * but he is not yet ready to receive it anyway, so we will
+     * simply wait for the select to tell us when he's ready to receive.
+     */
+    CriticalOutputPending = FALSE;
+    NewOutputPending = FALSE;
+
+#ifndef WIN32
+    for (base = 0; base < howmany(XFD_SETSIZE, NFDBITS); base++)
+    {
+       mask = OutputPending.fds_bits[ base ];
+       OutputPending.fds_bits[ base ] = 0;
+       while (mask)
+       {
+           index = ffs(mask) - 1;
+           mask &= ~lowbit(mask);
+           if ((index = ConnectionTranslation[(base << 5) + index]) == 0)
+               continue;
+           client = clients[index];
+           if (client->clientGone)
+               continue;
+           oc = (OsCommPtr)client->osPrivate;
+           if (
+#ifdef LBX
+               !oc->proxy &&
+#endif
+               FD_ISSET(oc->fd, &ClientsWithInput))
+           {
+               FD_SET(oc->fd, &OutputPending); /* set the bit again */
+               NewOutputPending = TRUE;
+           }
+           else
+               (void)FlushClient(client, oc, (char *)NULL, 0);
+       }
+    }
+#else  /* WIN32 */
+    FD_ZERO(&newOutputPending);
+    for (base = 0; base < XFD_SETCOUNT(&OutputPending); base++)
+    {
+           index = XFD_FD(&OutputPending, base);
+           if ((index = ConnectionTranslation[index]) == 0)
+               continue;
+           client = clients[index];
+           if (client->clientGone)
+               continue;
+           oc = (OsCommPtr)client->osPrivate;
+           if (
+#ifdef LBX
+               !oc->proxy &&
+#endif
+               FD_ISSET(oc->fd, &ClientsWithInput))
+           {
+               FD_SET(oc->fd, &newOutputPending); /* set the bit again */
+               NewOutputPending = TRUE;
+           }
+           else
+               (void)FlushClient(client, oc, (char *)NULL, 0);
+    }
+    XFD_COPYSET(&newOutputPending, &OutputPending);
+#endif /* WIN32 */
+}
+
+void
+FlushIfCriticalOutputPending()
+{
+    if (CriticalOutputPending)
+       FlushAllOutput();
+}
+
+void
+SetCriticalOutputPending()
+{
+    CriticalOutputPending = TRUE;
+}
+
+/*****************
+ * WriteToClient
+ *    Copies buf into ClientPtr.buf if it fits (with padding), else
+ *    flushes ClientPtr.buf and buf to client.  As of this writing,
+ *    every use of WriteToClient is cast to void, and the result
+ *    is ignored.  Potentially, this could be used by requests
+ *    that are sending several chunks of data and want to break
+ *    out of a loop on error.  Thus, we will leave the type of
+ *    this routine as int.
+ *****************/
+
+int
+WriteToClient (who, count, buf)
+    ClientPtr who;
+    char *buf;
+    int count;
+{
+    OsCommPtr oc = (OsCommPtr)who->osPrivate;
+    register ConnectionOutputPtr oco = oc->output;
+    int padBytes;
+
+    if (!count)
+       return(0);
+
+    if (!oco)
+    {
+       if (oco = FreeOutputs)
+       {
+           FreeOutputs = oco->next;
+       }
+       else if (!(oco = AllocateOutputBuffer()))
+       {
+           if (oc->trans_conn) {
+               _XSERVTransDisconnect(oc->trans_conn);
+               _XSERVTransClose(oc->trans_conn);
+               oc->trans_conn = NULL;
+           }
+           MarkClientException(who);
+           return -1;
+       }
+       oc->output = oco;
+    }
+
+    padBytes = padlength[count & 3];
+
+    if(ReplyCallback)
+    {
+        ReplyInfoRec replyinfo;
+
+       replyinfo.client = who;
+       replyinfo.replyData = buf;
+       replyinfo.dataLenBytes = count + padBytes;
+       if (who->replyBytesRemaining)
+       { /* still sending data of an earlier reply */
+           who->replyBytesRemaining -= count + padBytes;
+           replyinfo.startOfReply = FALSE;
+           replyinfo.bytesRemaining = who->replyBytesRemaining;
+           CallCallbacks((&ReplyCallback), (pointer)&replyinfo);
+       }
+       else if (who->clientState == ClientStateRunning
+                && buf[0] == X_Reply)
+        { /* start of new reply */
+           CARD32 replylen;
+           unsigned long bytesleft;
+           char n;
+
+           replylen = ((xGenericReply *)buf)->length;
+           if (who->swapped)
+               swapl(&replylen, n);
+           bytesleft = (replylen * 4) + SIZEOF(xReply) - count - padBytes;
+           replyinfo.startOfReply = TRUE;
+           replyinfo.bytesRemaining = who->replyBytesRemaining = bytesleft;
+           CallCallbacks((&ReplyCallback), (pointer)&replyinfo);
+       }                             
+    } 
+  
+    if (oco->count + count + padBytes > oco->size)
+    {
+       FD_CLR(oc->fd, &OutputPending);
+       CriticalOutputPending = FALSE;
+       NewOutputPending = FALSE;
+       return FlushClient(who, oc, buf, count);
+    }
+
+    NewOutputPending = TRUE;
+    FD_SET(oc->fd, &OutputPending);
+    memmove((char *)oco->buf + oco->count, buf, count);
+    oco->count += count + padBytes;
+    return(count);
+}
+
+ConnectionInputPtr
+AllocateInputBuffer()
+{
+    register ConnectionInputPtr oci;
+
+    oci = (ConnectionInputPtr)xalloc(sizeof(ConnectionInput));
+    if (!oci)
+       return (ConnectionInputPtr)NULL;
+    oci->buffer = (char *)xalloc(BUFSIZE);
+    if (!oci->buffer)
+    {
+       xfree(oci);
+       return (ConnectionInputPtr)NULL;
+    }
+    oci->size = BUFSIZE;
+    oci->bufptr = oci->buffer;
+    oci->bufcnt = 0;
+    oci->lenLastReq = 0;
+    return oci;
+}
+
+ConnectionOutputPtr
+AllocateOutputBuffer()
+{
+    register ConnectionOutputPtr oco;
+
+    oco = (ConnectionOutputPtr)xalloc(sizeof(ConnectionOutput));
+    if (!oco)
+       return (ConnectionOutputPtr)NULL;
+    oco->buf = (unsigned char *) xalloc(BUFSIZE);
+    if (!oco->buf)
+    {
+       xfree(oco);
+       return (ConnectionOutputPtr)NULL;
+    }
+    oco->size = BUFSIZE;
+    oco->count = 0;
+#ifdef LBX
+    oco->nocompress = FALSE;
+#endif
+    return oco;
+}
+
+void
+FreeOsBuffers(oc)
+    OsCommPtr oc;
+{
+    register ConnectionInputPtr oci;
+    register ConnectionOutputPtr oco;
+
+    if (AvailableInput == oc)
+       AvailableInput = (OsCommPtr)NULL;
+    if (oci = oc->input)
+    {
+       if (FreeInputs)
+       {
+           xfree(oci->buffer);
+           xfree(oci);
+       }
+       else
+       {
+           FreeInputs = oci;
+           oci->next = (ConnectionInputPtr)NULL;
+           oci->bufptr = oci->buffer;
+           oci->bufcnt = 0;
+           oci->lenLastReq = 0;
+       }
+    }
+    if (oco = oc->output)
+    {
+       if (FreeOutputs)
+       {
+           xfree(oco->buf);
+           xfree(oco);
+       }
+       else
+       {
+           FreeOutputs = oco;
+           oco->next = (ConnectionOutputPtr)NULL;
+           oco->count = 0;
+       }
+    }
+#ifdef LBX
+    if (oci = oc->largereq) {
+       xfree(oci->buffer);
+       xfree(oci);
+    }
+#endif
+}
+
+void
+ResetOsBuffers()
+{
+    register ConnectionInputPtr oci;
+    register ConnectionOutputPtr oco;
+
+    while (oci = FreeInputs)
+    {
+       FreeInputs = oci->next;
+       xfree(oci->buffer);
+       xfree(oci);
+    }
+    while (oco = FreeOutputs)
+    {
+       FreeOutputs = oco->next;
+       xfree(oco->buf);
+       xfree(oco);
+    }
+}
diff --git a/Xserver/programs/Xserver/os/iopreader.c b/Xserver/programs/Xserver/os/iopreader.c
new file mode 100644 (file)
index 0000000..092c7a7
--- /dev/null
@@ -0,0 +1,179 @@
+/* $XConsortium: iopreader.c,v 1.2 94/04/12 17:24:33 dpw Exp $ */
+
+/* Copyright (c) 1987 by the Regents of the University of California
+ * Copyright (c) 1994 by the Vrije Universiteit, Amsterdam.
+ *
+ * Permission to use, copy, modify, and distribute this
+ * software and its documentation for any purpose and without
+ * fee is hereby granted, provided that the above copyright
+ * notice appear in all copies.  The University of California
+ * and the Vrije Universiteit make no representations about
+ * the suitability of this software for any purpose.
+ * It is provided "as is" without express or implied warranty.
+ */
+
+#ifdef AMOEBA
+/*
+ * iopreader.c
+ *
+ */
+#define port am_port_t
+#include <amoeba.h>
+#include <ampolicy.h>
+#include <cmdreg.h>
+#include <stdcom.h>
+#include <stderr.h>
+#include <server/iop/iop.h>
+#undef port
+
+#include "osdep.h"
+
+#define DEVREADER_STACK        8000
+#define        MAXEVENTQUEUE   32
+
+capability iopcap;
+
+static mutex lock;
+static semaphore empty, filled;
+
+static IOPEvent event_queue[MAXEVENTQUEUE];
+static int event_qin, event_qout;
+
+void IOPCleanUp();
+static void IOPServerReader();
+
+/*
+ * Initialize the IOP server
+ */
+void
+InitializeIOPServerReader()
+{
+    capability         hostcap;
+    errstat            err;
+
+    /*
+     * Initialize event queue
+     */
+    event_qin = event_qout = 0;
+    sema_init(&empty, MAXEVENTQUEUE);
+    sema_init(&filled, 0);
+    mu_init(&lock);
+
+    /* 
+     * Get IOP capability, and enable the server
+     */
+    if (XServerHostName == NULL)
+       FatalError("No hostname, no screen\n");
+    
+    if ((err = host_lookup(XServerHostName, &hostcap)) != STD_OK ||
+        (err = dir_lookup(&hostcap, DEF_IOPSVRNAME, &iopcap)) != STD_OK)
+    {
+       FatalError("Cannot find IOP server for %s: %s\n",
+                   XServerHostName, err_why(err));
+    }
+
+    /*
+     * Enable IOP server
+     */
+    if ((err = iop_enable(&iopcap)) != STD_OK)
+       FatalError("iop_enable failed (%s)\n", err_why(err));
+
+    /*
+     * Start IOP reader thread
+     */
+    atexit(IOPCleanUp);
+    if (thread_newthread(IOPServerReader, DEVREADER_STACK, 0, 0) <= 0)
+       FatalError("Cannot start IOP reader thread\n");
+}
+
+/*
+ * IOP clean up, actuall disable the IOP server. Its the IOP's own choice
+ * what do do (perhaps restore the screen?).
+ */
+void
+IOPCleanUp()
+{
+    errstat err;
+
+    if ((err = iop_disable(&iopcap)) != STD_OK)
+       ErrorF("iop_disable failed (%s)\n", err_why(err));
+}
+
+/*
+ * This threads polls the IOP server for events. Once an event (or a
+ * number of events) are read, they are queued up using a traditional
+ * producer/consumer approach.
+ */
+static void
+IOPServerReader()
+{
+    IOPEvent           queue[MAXEVENTQUEUE-1];
+    int                        nevents, i;
+    errstat            err;
+
+    WaitForInitialization();
+
+#ifdef XDEBUG
+    if (amDebug) ErrorF("IOPServerReader() running ...\n");
+#endif
+
+    for (;;) {
+       do {
+           nevents = MAXEVENTQUEUE - 1;
+           err = iop_getevents(&iopcap, queue, &nevents);
+           if (err != STD_OK) {
+               if (err != RPC_FAILURE) {
+                   ErrorF("iop_getevents failed (%s)\n", err_why(err));
+               }
+               nevents = 0;
+           }
+       } while (nevents <= 0);
+
+       /* store event(s) in the global event queue */
+       sema_mdown(&empty, nevents);
+       mu_lock(&lock);
+       for (i = 0; i < nevents; i++) {
+           event_queue[event_qin] = queue[i];
+           event_qin = (event_qin + 1) % MAXEVENTQUEUE;
+       }
+       mu_unlock(&lock);
+       sema_mup(&filled, nevents);
+       WakeUpMainThread();
+    }
+}
+
+/*
+ * Return the number of IOP events waiting
+ */
+int
+AmoebaEventsAvailable()
+{
+    return sema_level(&filled);
+}
+
+/*
+ * Get the IOP events from the queue. ``size'' is the maximum the
+ * requestor cares to handle, the actual size read is returned as
+ * result.
+ */
+int
+AmoebaGetEvents(queue, size)
+    IOPEvent   *queue;
+    int                size;
+{
+    int                nevents, i;
+
+    if (sema_level(&filled) <= 0) return 0;
+    if ((nevents = sema_level(&filled)) > size)
+       nevents = size;
+    sema_mdown(&filled, nevents);
+    mu_lock(&lock);
+    for (i = 0; i < nevents; i++) {
+       queue[i] = event_queue[event_qout];
+       event_qout = (event_qout + 1) % MAXEVENTQUEUE;
+    }
+    mu_unlock(&lock);
+    sema_mup(&empty, nevents);
+    return nevents;
+}
+#endif /* AMOEBA */
diff --git a/Xserver/programs/Xserver/os/k5auth.c b/Xserver/programs/Xserver/os/k5auth.c
new file mode 100644 (file)
index 0000000..c3ffdba
--- /dev/null
@@ -0,0 +1,799 @@
+/* $XConsortium: k5auth.c,v 1.9 95/04/06 16:10:29 mor Exp $ */
+/* $XFree86: xc/programs/Xserver/os/k5auth.c,v 3.2 1996/05/10 07:02:15 dawes Exp $ */
+/*
+
+Copyright (c) 1993, 1994  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be included
+in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR
+OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall
+not be used in advertising or otherwise to promote the sale, use or
+other dealings in this Software without prior written authorization
+from the X Consortium.
+
+*/
+
+/*
+ * Kerberos V5 authentication scheme
+ * Author: Tom Yu <tlyu@MIT.EDU>
+ *
+ * Mostly snarfed wholesale from the user_user demo in the
+ * krb5 distribution. (At least the checking part)
+ */
+
+#include <sys/types.h>
+#include <sys/socket.h>
+#ifdef TCPCONN
+#include <netinet/in.h>
+#endif
+#ifdef DNETCONN
+#include <netdnet/dn.h>
+#endif
+#include <arpa/inet.h>
+#include <krb5/krb5.h>
+/* 9/93: krb5.h leaks some symbols */
+#undef BITS32
+#undef xfree
+#include <krb5/los-proto.h>
+#include "X.h"
+#include "os.h"
+#include "osdep.h"
+#include "Xproto.h"
+#include "Xfuncs.h"
+#include "dixstruct.h"
+#include <com_err.h>
+#include "Xauth.h"
+
+extern int (*k5_Vector[256])();
+extern int SendConnSetup();
+extern char *display;          /* need this to generate rcache name */
+
+static XID krb5_id = ~0L;
+static krb5_principal srvname = NULL; /* service name */
+static char *ccname = NULL;
+static char *ktname = NULL;    /* key table name */
+static char kerror[256];
+
+/*
+ * tgt_keyproc:
+ *
+ * extract session key from a credentials struct
+ */
+krb5_error_code tgt_keyproc(keyprocarg, principal, vno, key)
+    krb5_pointer keyprocarg;
+    krb5_principal principal;
+    krb5_kvno vno;
+    krb5_keyblock **key;
+{
+    krb5_creds *creds = (krb5_creds *)keyprocarg;
+    
+    return krb5_copy_keyblock(&creds->keyblock, key);
+}
+
+/*
+ * k5_cmpenc:
+ *
+ * compare "encoded" principals
+ */
+Bool k5_cmpenc(pname, plen, buf)
+    unsigned char *pname;
+    short plen;
+    krb5_data *buf;
+{
+    return (plen == buf->length &&
+           memcmp(pname, buf->data, plen) == 0);
+}
+
+/*
+ * K5Check:
+ *
+ * This is stage 0 of the krb5 authentication protocol.  It
+ * goes through the current credentials cache and extracts the
+ * primary principal and tgt to send to the client, or as
+ * appropriate, extracts from a keytab.
+ *
+ * The packet sent to the client has the following format:
+ *
+ * CARD8       reqType = 2
+ * CARD8       data    = 0
+ * CARD16      length  = total length of packet (in 32 bit units)
+ * CARD16      plen    = length of encoded principal following
+ * STRING8     princ   = encoded principal
+ * STRING8     ticket  = server tgt
+ *
+ * For client-server authentication, the packet is as follows:
+ *
+ * CARD8       reqType = 3
+ * CARD8       data    = 0
+ * CARD16      length  = total length
+ * STRING8     princ   = encoded principal of server
+ */
+XID K5Check(data_length, data, client, reason)
+    unsigned short data_length;
+    char *data;
+    ClientPtr client;
+    char **reason;
+{
+    krb5_error_code retval;
+    CARD16 tlen;
+    krb5_principal sprinc, cprinc;
+    krb5_ccache cc;
+    krb5_creds *creds;
+    char *outbuf, *cp;
+    krb5_data princ;
+    register char n;
+    xReq prefix;
+
+    if (krb5_id == ~0L)
+       return ~0L;
+    if (!ccname && !srvname)
+       return ~0L;
+    if (ccname)
+    {
+       if ((creds = (krb5_creds *)malloc(sizeof(krb5_creds))) == NULL)
+           return ~0L;
+       if (retval = krb5_cc_resolve(ccname, &cc))
+           return ~0L;
+       bzero((char*)creds, sizeof (krb5_creds));
+       if (retval = krb5_cc_get_principal(cc, &cprinc))
+       {
+           krb5_free_creds(creds);
+           krb5_cc_close(cc);
+           return ~0L;
+       }
+       creds->client = cprinc;
+       if (retval =
+           krb5_build_principal_ext(&sprinc, 
+                                    krb5_princ_realm(creds->client)->length,
+                                    krb5_princ_realm(creds->client)->data,
+                                    6, "krbtgt",
+                                    krb5_princ_realm(creds->client)->length,
+                                    krb5_princ_realm(creds->client)->data,
+                                    0))
+       {
+           krb5_free_creds(creds);
+           krb5_cc_close(cc);
+           return ~0L;
+       }
+       creds->server = sprinc;
+       retval = krb5_get_credentials(KRB5_GC_CACHED, cc, creds);
+       krb5_cc_close(cc);
+       if (retval)
+       {
+           krb5_free_creds(creds);
+           return ~0L;
+       }
+       if (retval = XauKrb5Encode(cprinc, &princ))
+       {
+           krb5_free_creds(creds);
+           return ~0L;
+       }
+       tlen = sz_xReq + 2 + princ.length + creds->ticket.length;
+       prefix.reqType = 2;     /* opcode = authenticate user-to-user */
+    }
+    else if (srvname)
+    {
+       if (retval = XauKrb5Encode(srvname, &princ))
+       {
+           return ~0L;
+       }
+       tlen = sz_xReq + princ.length;
+       prefix.reqType = 3;     /* opcode = authenticate client-server */
+    }
+    prefix.data = 0;           /* stage = 0 */
+    prefix.length = (tlen + 3) >> 2; /* round up to nearest multiple
+                                       of 4 bytes */
+    if (client->swapped)
+    {
+       swaps(&prefix.length, n);
+    }
+    if ((cp = outbuf = (char *)malloc(tlen)) == NULL)
+    {
+       if (ccname)
+       {
+           krb5_free_creds(creds);
+       }
+       free(princ.data);
+       return ~0L;
+    }
+    memcpy(cp, &prefix, sz_xReq);
+    cp += sz_xReq;
+    if (ccname)
+    {
+       memcpy(cp, &princ.length, 2);
+       if (client->swapped)
+       {
+           swaps((CARD16 *)cp, n);
+       }
+       cp += 2;
+    }
+    memcpy(cp, princ.data, princ.length);
+    cp += princ.length;
+    free(princ.data);          /* we don't need that anymore */
+    if (ccname)
+       memcpy(cp, creds->ticket.data, creds->ticket.length);
+    WriteToClient(client, tlen, outbuf);
+    free(outbuf);
+    client->requestVector = k5_Vector; /* hack in our dispatch vector */
+    client->clientState = ClientStateAuthenticating;
+    if (ccname)
+    {
+       ((OsCommPtr)client->osPrivate)->authstate.srvcreds = (pointer)creds; /* save tgt creds */
+       ((OsCommPtr)client->osPrivate)->authstate.ktname = NULL;
+       ((OsCommPtr)client->osPrivate)->authstate.srvname = NULL;
+    }
+    if (srvname)
+    {
+       ((OsCommPtr)client->osPrivate)->authstate.srvcreds = NULL;
+       ((OsCommPtr)client->osPrivate)->authstate.ktname = (pointer)ktname;
+       ((OsCommPtr)client->osPrivate)->authstate.srvname = (pointer)srvname;
+    }
+    ((OsCommPtr)client->osPrivate)->authstate.stageno = 1; /* next stage is 1 */
+    return krb5_id;
+}
+
+/*
+ * k5_stage1:
+ *
+ * This gets called out of the dispatcher after K5Check frobs with the
+ * client->requestVector.  It accepts the ap_req from the client and verifies
+ * it.  In addition, if the client has set AP_OPTS_MUTUAL_REQUIRED, it then
+ * sends an ap_rep to the client to achieve mutual authentication.
+ *
+ * client stage1 packet format is as follows:
+ *
+ * CARD8       reqType = 1
+ * CARD8       data    = ignored
+ * CARD16      length  = total length
+ * STRING8     data    = the actual ap_req
+ *
+ * stage2 packet sent back to client for mutual authentication:
+ *
+ * CARD8       reqType = 2
+ * CARD8       data    = 2
+ * CARD16      length  = total length
+ * STRING8     data    = the ap_rep
+ */
+int k5_stage1(client)
+    register ClientPtr client;
+{
+    long addrlen;
+    krb5_error_code retval, retval2;
+    register char n;
+    struct sockaddr cli_net_addr;
+    xReq prefix;
+    krb5_principal cprinc;
+    krb5_data buf;
+    krb5_creds *creds = (krb5_creds *)((OsCommPtr)client->osPrivate)->authstate.srvcreds;
+    krb5_keyblock *skey;
+    krb5_address cli_addr, **localaddrs = NULL;
+    krb5_tkt_authent *authdat;
+    krb5_ap_rep_enc_part rep;
+    krb5_int32 ctime, cusec;
+    krb5_rcache rcache = NULL;
+    char *cachename = NULL, *rc_type = NULL, *rc_base = "rcX", *kt = NULL;
+    REQUEST(xReq);
+
+    if (((OsCommPtr)client->osPrivate)->authstate.stageno != 1)
+    {
+       if (creds)
+           krb5_free_creds(creds);
+       return(SendConnSetup(client, "expected Krb5 stage1 packet"));
+    }
+    addrlen = sizeof (cli_net_addr);
+    if (getpeername(((OsCommPtr)client->osPrivate)->fd,
+                   &cli_net_addr, &addrlen) == -1)
+    {
+       if (creds)
+           krb5_free_creds(creds);
+       return(SendConnSetup(client, "Krb5 stage1: getpeername failed"));
+    }
+    if (cli_net_addr.sa_family == AF_UNSPEC
+#if defined(UNIXCONN) || defined(LOCALCONN) || defined(OS2PIPECONN)
+       || cli_net_addr.sa_family == AF_UNIX
+#endif
+       )                       /* assume local host */
+    {
+       krb5_os_localaddr(&localaddrs);
+       if (!localaddrs || !localaddrs[0])
+       {
+           if (creds)
+               krb5_free_creds(creds);
+           return(SendConnSetup(client, "Krb5 failed to get localaddrs"));
+       }
+       cli_addr.addrtype = localaddrs[0]->addrtype;
+       cli_addr.length = localaddrs[0]->length;
+       cli_addr.contents = localaddrs[0]->contents;
+    }
+    else
+    {
+       cli_addr.addrtype = cli_net_addr.sa_family; /* the values
+                                                      are compatible */
+       switch (cli_net_addr.sa_family)
+       {
+#ifdef TCPCONN
+       case AF_INET:
+           cli_addr.length = sizeof (struct in_addr);
+           cli_addr.contents =
+               (krb5_octet *)&((struct sockaddr_in *)&cli_net_addr)->sin_addr;
+           break;
+#endif
+#ifdef DNETCONN
+       case AF_DECnet:
+           cli_addr.length = sizeof (struct dn_naddr);
+           cli_addr.contents =
+               (krb5_octet *)&((struct sockaddr_dn *)&cli_net_addr)->sdn_add;
+           break;
+#endif
+       default:
+           if (localaddrs)
+               krb5_free_addresses(localaddrs);
+           if (creds)
+               krb5_free_creds(creds);
+           sprintf(kerror, "Krb5 stage1: unknown address family %d from getpeername",
+                   cli_net_addr.sa_family);    
+           return(SendConnSetup(client, kerror));
+       }
+    }
+    if ((rcache = (krb5_rcache)malloc(sizeof(*rcache))) == NULL)
+    {
+       if (localaddrs)
+           krb5_free_addresses(localaddrs);
+       if (creds)
+           krb5_free_creds(creds);
+       return(SendConnSetup(client, "malloc bombed for krb5_rcache"));
+    }
+    if ((rc_type = krb5_rc_default_type()) == NULL)
+       rc_type = "dfl";
+    if (retval = krb5_rc_resolve_type(&rcache, rc_type))
+    {
+       if (localaddrs)
+           krb5_free_addresses(localaddrs);
+       if (creds)
+           krb5_free_creds(creds);
+       free(rcache);
+       strcpy(kerror, "krb5_rc_resolve_type failed: ");
+       strncat(kerror, error_message(retval), 231);
+       return(SendConnSetup(client, kerror));
+    }
+    if ((cachename = (char *)malloc(strlen(rc_base) + strlen(display) + 1))
+       == NULL)
+    {
+       if (localaddrs)
+           krb5_free_addresses(localaddrs);
+       if (creds)
+           krb5_free_creds(creds);
+       free(rcache);
+       return(SendConnSetup(client, "Krb5: malloc bombed for cachename"));
+    }
+    strcpy(cachename, rc_base);
+    strcat(cachename, display);
+    if (retval = krb5_rc_resolve(rcache, cachename))
+    {
+       if (localaddrs)
+           krb5_free_addresses(localaddrs);
+       if (creds)
+           krb5_free_creds(creds);
+       free(rcache);
+       free(cachename);
+       strcpy(kerror, "krb5_rc_resolve failed: ");
+       strncat(kerror, error_message(retval), 236);
+       return(SendConnSetup(client, kerror));
+    }
+    free(cachename);
+    if (krb5_rc_recover(rcache))
+    {
+       extern krb5_deltat krb5_clockskew;
+       if (retval = krb5_rc_initialize(rcache, krb5_clockskew))
+       {
+           if (localaddrs)
+               krb5_free_addresses(localaddrs);
+           if (creds)
+               krb5_free_creds(creds);
+           if (retval2 = krb5_rc_close(rcache))
+           {
+               strcpy(kerror, "krb5_rc_close failed: ");
+               strncat(kerror, error_message(retval2), 238);
+               return(SendConnSetup(client, kerror));
+           }
+           free(rcache);
+           strcpy(kerror, "krb5_rc_initialize failed: ");
+           strncat(kerror, error_message(retval), 233);
+           return(SendConnSetup(client, kerror));
+       }
+    }
+    buf.length = (stuff->length << 2) - sz_xReq;
+    buf.data = (char *)stuff + sz_xReq;
+    if (creds)
+    {
+       retval = krb5_rd_req(&buf,
+                            NULL, /* don't bother with server name */
+                            &cli_addr,
+                            NULL, /* no fetchfrom */
+                            tgt_keyproc,
+                            creds, /* credentials as arg to
+                                      keyproc */
+                            rcache,
+                            &authdat);
+       krb5_free_creds(creds);
+    }
+    else if (kt = (char *)((OsCommPtr)client->osPrivate)->authstate.ktname)
+    {
+       retval = krb5_rd_req(&buf, srvname, &cli_addr, kt, NULL, NULL,
+                            rcache, &authdat);
+       ((OsCommPtr)client->osPrivate)->authstate.ktname = NULL;
+    }
+    else
+    {
+       if (localaddrs)
+           krb5_free_addresses(localaddrs);
+       return(SendConnSetup(client, "Krb5: neither srvcreds nor ktname set"));
+    }
+    if (localaddrs)
+       krb5_free_addresses(localaddrs);
+    if (rcache)
+    {
+       if (retval2 = krb5_rc_close(rcache))
+       {
+           strcpy(kerror, "krb5_rc_close failed (2): ");
+           strncat(kerror, error_message(retval2), 230);
+           return(SendConnSetup(client, kerror));
+       }
+       free(rcache);
+    }
+    if (retval)
+    {
+       strcpy(kerror, "Krb5: Bad application request: ");
+       strncat(kerror, error_message(retval), 224);
+       return(SendConnSetup(client, kerror));
+    }
+    cprinc = authdat->ticket->enc_part2->client;
+    skey = authdat->ticket->enc_part2->session;
+    if (XauKrb5Encode(cprinc, &buf))
+    {
+       krb5_free_tkt_authent(authdat);
+       return(SendConnSetup(client, "XauKrb5Encode bombed"));
+    }
+    /*
+     * Now check to see if the principal we got is one that we want to let in
+     */
+    if (ForEachHostInFamily(FamilyKrb5Principal, k5_cmpenc, (pointer)&buf))
+    {
+       free(buf.data);
+       /*
+        * The following deals with sending an ap_rep to the client to
+        * achieve mutual authentication.  The client sends back a stage 3
+        * packet if all is ok.
+        */
+       if (authdat->ap_options | AP_OPTS_MUTUAL_REQUIRED)
+       {
+           /*
+            * stage 2: send ap_rep to client
+            */
+           if (retval = krb5_us_timeofday(&ctime, &cusec))
+           {
+               krb5_free_tkt_authent(authdat);
+               strcpy(kerror, "error in krb5_us_timeofday: ");
+               strncat(kerror, error_message(retval), 234);
+               return(SendConnSetup(client, kerror));
+           }
+           rep.ctime = ctime;
+           rep.cusec = cusec;
+           rep.subkey = NULL;
+           rep.seq_number = 0;
+           if (retval = krb5_mk_rep(&rep, skey, &buf))
+           {
+               krb5_free_tkt_authent(authdat);
+               strcpy(kerror, "error in krb5_mk_rep: ");
+               strncat(kerror, error_message(retval), 238);
+               return(SendConnSetup(client, kerror));
+           }
+           prefix.reqType = 2; /* opcode = authenticate */
+           prefix.data = 2;    /* stage = 2 */
+           prefix.length = (buf.length + sz_xReq + 3) >> 2;
+           if (client->swapped)
+           {
+               swaps(&prefix.length, n);
+           }
+           WriteToClient(client, sz_xReq, (char *)&prefix);
+           WriteToClient(client, buf.length, buf.data);
+           free(buf.data);
+           krb5_free_tkt_authent(authdat);
+           ((OsCommPtr)client->osPrivate)->authstate.stageno = 3; /* expect stage3 packet */
+           return(Success);
+       }
+       else
+       {
+           free(buf.data);
+           krb5_free_tkt_authent(authdat);
+           return(SendConnSetup(client, NULL)); /* success! */
+       }
+    }
+    else
+    {
+       char *kname;
+       
+       krb5_free_tkt_authent(authdat);
+       free(buf.data);
+       retval = krb5_unparse_name(cprinc, &kname);
+       if (retval == 0)
+       {
+           sprintf(kerror, "Principal \"%s\" is not authorized to connect",
+                   kname);
+           if (kname)
+               free(kname);
+           return(SendConnSetup(client, kerror));
+       }
+       else
+           return(SendConnSetup(client,"Principal is not authorized to connect to Server"));
+    }
+}
+
+/*
+ * k5_stage3:
+ *
+ * Get the short ack packet from the client.  This packet can conceivably
+ * be expanded to allow for switching on end-to-end encryption.
+ *
+ * stage3 packet format:
+ *
+ * CARD8       reqType = 3
+ * CARD8       data    = ignored (for now)
+ * CARD16      length  = should be zero
+ */
+int k5_stage3(client)
+    register ClientPtr client;
+{
+    REQUEST(xReq);
+
+    if (((OsCommPtr)client->osPrivate)->authstate.stageno != 3)
+    {
+       return(SendConnSetup(client, "expected Krb5 stage3 packet"));
+    }
+    else
+       return(SendConnSetup(client, NULL)); /* success! */
+}
+
+k5_bad(client)
+    register ClientPtr client;
+{
+    if (((OsCommPtr)client->osPrivate)->authstate.srvcreds)
+       krb5_free_creds((krb5_creds *)((OsCommPtr)client->osPrivate)->authstate.srvcreds);
+    sprintf(kerror, "unrecognized Krb5 auth packet %d, expecting %d",
+           ((xReq *)client->requestBuffer)->reqType,
+           ((OsCommPtr)client->osPrivate)->authstate.stageno);
+    return(SendConnSetup(client, kerror));
+}
+
+/*
+ * K5Add:
+ *
+ * Takes the name of a credentials cache and resolves it.  Also adds the
+ * primary principal of the ccache to the acl.
+ *
+ * Now will also take a service name.
+ */
+int K5Add(data_length, data, id)
+    unsigned short data_length;
+    char *data;
+    XID id;
+{
+    krb5_principal princ;
+    krb5_error_code retval;
+    krb5_keytab_entry tmp_entry;
+    krb5_keytab keytab;
+    krb5_kvno kvno = 0;
+    krb5_ccache cc;
+    char *nbuf, *cp;
+    krb5_data kbuf;
+    int i, ktlen;
+    
+    krb5_init_ets();           /* can't think of a better place to put it */
+    krb5_id = ~0L;
+    if (data_length < 3)
+       return 0;
+    if ((nbuf = (char *)malloc(data_length - 2)) == NULL)
+       return 0;
+    memcpy(nbuf, data + 3, data_length - 3);
+    nbuf[data_length - 3] = '\0';
+    if (ccname)
+    {
+       free(ccname);
+       ccname = NULL;
+    }
+    if (srvname)
+    {
+       krb5_free_principal(srvname);
+       srvname = NULL;
+    }
+    if (ktname)
+    {
+       free(ktname);
+       ktname = NULL;
+    }
+    if (!strncmp(data, "UU:", 3))
+    {
+       if (retval = krb5_cc_resolve(nbuf, &cc))
+       {
+           ErrorF("K5Add: krb5_cc_resolve of \"%s\" failed: %s\n",
+                  nbuf, error_message(retval));
+           free(nbuf);
+           return 0;
+       }
+       if (cc && !(retval = krb5_cc_get_principal(cc, &princ)))
+       {
+           if (XauKrb5Encode(princ, &kbuf))
+           {
+               free(nbuf);
+               krb5_free_principal(princ);
+               krb5_cc_close(cc);
+               return 0;
+           }
+           if (krb5_cc_close(cc))
+               return 0;
+           AddHost(NULL, FamilyKrb5Principal, kbuf.length, kbuf.data);
+           krb5_free_principal(princ);
+           free(kbuf.data);
+           ccname = nbuf;
+           krb5_id = id;
+           return 1;
+       }
+       else
+       {
+           ErrorF("K5Add: getting principal from cache \"%s\" failed: %s\n",
+                  nbuf, error_message(retval));
+       }
+    }
+    else if (!strncmp(data, "CS:", 3))
+    {
+       if ((cp = strchr(nbuf, ',')) == NULL)
+       {
+           free(nbuf);
+           return 0;
+       }
+       *cp = '\0';             /* gross but it works :-) */
+       ktlen = strlen(cp + 1);
+       if ((ktname = (char *)malloc(ktlen + 1)) == NULL)
+       {
+           free(nbuf);
+           return 0;
+       }
+       strcpy(ktname, cp + 1);
+       retval = krb5_sname_to_principal(NULL, /* NULL for hostname uses
+                                                 local host name*/
+                                        nbuf, KRB5_NT_SRV_HST,
+                                        &srvname);
+       free(nbuf);
+       if (retval)
+       {
+           free(ktname);
+           ktname = NULL;
+           return 0;
+       }
+       if (retval = krb5_kt_resolve(ktname, &keytab))
+       {
+           free(ktname);
+           ktname = NULL;
+           krb5_free_principal(srvname);
+           srvname = NULL;
+           return 0;
+       }
+       retval = krb5_kt_get_entry(keytab, srvname, kvno, &tmp_entry);
+       krb5_kt_free_entry(&tmp_entry);
+       if (retval)
+       {
+           free(ktname);
+           ktname = NULL;
+           krb5_free_principal(srvname);
+           srvname = NULL;
+           return 0;
+       }
+       if (XauKrb5Encode(srvname, &kbuf))
+       {
+           free(ktname);
+           ktname = NULL;
+           krb5_free_principal(srvname);
+           srvname = NULL;
+           return 0;
+       }
+       AddHost(NULL, FamilyKrb5Principal, kbuf.length, kbuf.data);
+       krb5_id = id;
+       return 1;
+    }
+    else
+    {
+       ErrorF("K5Add: credentials cache name \"%.*s\" in auth file: unknown type\n",
+              data_length, data);
+    }
+    return 0;
+}
+
+/*
+ * K5Reset:
+ *
+ * Reset krb5_id, also nuke the current principal from the acl.
+ */
+int K5Reset()
+{
+    krb5_principal princ;
+    krb5_error_code retval;
+    krb5_ccache cc;
+    krb5_data kbuf;
+    int i;
+    
+    if (ccname)
+    {
+       if (retval = krb5_cc_resolve(ccname, &cc))
+       {
+           free(ccname);
+           ccname = NULL;
+       }
+       if (cc && !(retval = krb5_cc_get_principal(cc, &princ)))
+       {
+           if (XauKrb5Encode(princ, &kbuf))
+               return 1;
+           RemoveHost(NULL, FamilyKrb5Principal, kbuf.length, kbuf.data);
+           krb5_free_principal(princ);
+           free(kbuf.data);
+           if (krb5_cc_close(cc))
+               return 1;
+           free(ccname);
+           ccname = NULL;
+       }
+    }
+    if (srvname)
+    {
+       if (XauKrb5Encode(srvname, &kbuf))
+           return 1;
+       RemoveHost(NULL, FamilyKrb5Principal, kbuf.length, kbuf.data);
+       krb5_free_principal(srvname);
+       free(kbuf.data);
+       srvname = NULL;
+    }
+    if (ktname)
+    {
+       free(ktname);
+       ktname = NULL;
+    }
+    krb5_id = ~0L;
+    return 0;
+}
+
+XID K5ToID(data_length, data)
+    unsigned short data_length;
+    char *data;
+{
+    return krb5_id;
+}
+
+int K5FromID(id, data_lenp, datap)
+    XID id;
+    unsigned short *data_lenp;
+    char **datap;
+{
+    return 0;
+}
+
+int K5Remove(data_length, data)
+    unsigned short data_length;
+    char *data;
+{
+    return 0;
+}
diff --git a/Xserver/programs/Xserver/os/lbxio.c b/Xserver/programs/Xserver/os/lbxio.c
new file mode 100644 (file)
index 0000000..dd636ce
--- /dev/null
@@ -0,0 +1,572 @@
+/***********************************************************
+Copyright 1987, 1989 by Digital Equipment Corporation, Maynard, Massachusetts,
+and the Massachusetts Institute of Technology, Cambridge, Massachusetts.
+Copyright 1996 X Consortium, Inc.
+
+                        All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and its 
+documentation for any purpose and without fee is hereby granted, 
+provided that the above copyright notice appear in all copies and that
+both that copyright notice and this permission notice appear in 
+supporting documentation, and that the names of Digital or MIT not be
+used in advertising or publicity pertaining to distribution of the
+software without specific, written prior permission.  
+
+DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
+ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
+DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
+ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+SOFTWARE.
+
+******************************************************************/
+/* $XConsortium: lbxio.c /main/10 1996/12/16 23:03:30 rws $ */
+
+
+
+
+/* $XFree86: xc/programs/Xserver/os/lbxio.c,v 3.8 1997/01/18 07:18:31 dawes Exp $ */
+
+#include <stdio.h>
+#include <X11/Xtrans.h>
+#ifdef X_NOT_STDC_ENV
+extern int errno;
+#endif
+#include "Xmd.h"
+#include <errno.h>
+#ifndef Lynx
+#include <sys/param.h>
+#ifndef __EMX__
+#include <sys/uio.h>
+#endif
+#else
+#include <uio.h>
+#endif
+#include "X.h"
+#include "Xproto.h"
+#include "os.h"
+#include "Xpoll.h"
+#include "osdep.h"
+#include "opaque.h"
+#include "dixstruct.h"
+#include "misc.h"
+#include "lbxserve.h"
+
+/* check for both EAGAIN and EWOULDBLOCK, because some supposedly POSIX
+ * systems are broken and return EWOULDBLOCK when they should return EAGAIN
+ */
+#if defined(EAGAIN) && defined(EWOULDBLOCK)
+#define ETEST(err) (err == EAGAIN || err == EWOULDBLOCK)
+#else
+#ifdef EAGAIN
+#define ETEST(err) (err == EAGAIN)
+#else
+#define ETEST(err) (err == EWOULDBLOCK)
+#endif
+#endif
+
+extern fd_set ClientsWithInput, IgnoredClientsWithInput;
+extern fd_set AllClients, AllSockets;
+extern fd_set ClientsWriteBlocked;
+extern fd_set OutputPending;
+extern int ConnectionTranslation[];
+extern Bool NewOutputPending;
+extern Bool AnyClientsWriteBlocked;
+extern Bool CriticalOutputPending;
+extern int timesThisConnection;
+extern ConnectionInputPtr FreeInputs;
+extern ConnectionOutputPtr FreeOutputs;
+extern OsCommPtr AvailableInput;
+
+#define get_req_len(req,cli) ((cli)->swapped ? \
+                             lswaps((req)->length) : (req)->length)
+
+#define YieldControl()                         \
+        { isItTimeToYield = TRUE;              \
+         timesThisConnection = 0; }
+#define YieldControlNoInput()                  \
+        { YieldControl();                      \
+         FD_CLR(fd, &ClientsWithInput); }
+
+void
+SwitchClientInput (client, pending)
+    ClientPtr client;
+    Bool pending;
+{
+    OsCommPtr oc = (OsCommPtr)client->osPrivate;
+    
+    ConnectionTranslation[oc->fd] = client->index;
+    if (pending)
+       FD_SET(oc->fd, &ClientsWithInput);
+    else
+       YieldControl();
+}
+
+void
+LbxPrimeInput(client, proxy)
+    ClientPtr  client;
+    LbxProxyPtr proxy;
+{
+    OsCommPtr oc = (OsCommPtr)client->osPrivate;
+    ConnectionInputPtr oci = oc->input;
+
+    if (oci && proxy->compHandle) {
+       char *extra = oci->bufptr + oci->lenLastReq;
+       int left = oci->bufcnt + oci->buffer - extra;
+
+       (*proxy->streamOpts.streamCompStuffInput)(oc->fd,
+                                                 (unsigned char *)extra,
+                                                 left);
+       oci->bufcnt -= left;
+       AvailableInput = oc;
+    }
+}
+
+void
+AvailableClientInput (client)
+    ClientPtr  client;
+{
+    OsCommPtr oc = (OsCommPtr)client->osPrivate;
+
+    if (FD_ISSET(oc->fd, &AllSockets))
+       FD_SET(oc->fd, &ClientsWithInput);
+}
+
+/*****************************************************************
+ * AppendFakeRequest
+ *    Append a (possibly partial) request in as the last request.
+ *
+ **********************/
+Bool
+AppendFakeRequest (client, data, count)
+    ClientPtr client;
+    char *data;
+    int count;
+{
+    OsCommPtr oc = (OsCommPtr)client->osPrivate;
+    register ConnectionInputPtr oci = oc->input;
+    int fd = oc->fd;
+    register int gotnow;
+
+    if (!oci)
+    {
+       if (oci = FreeInputs)
+           FreeInputs = oci->next;
+       else if (!(oci = AllocateInputBuffer()))
+           return FALSE;
+       oc->input = oci;
+    } else if (AvailableInput == oc)
+       AvailableInput = (OsCommPtr)NULL;
+    /* do not free AvailableInput here, it could be proxy's */
+    oci->bufptr += oci->lenLastReq;
+    oci->lenLastReq = 0;
+    gotnow = oci->bufcnt + oci->buffer - oci->bufptr;
+    if ((gotnow + count) > oci->size)
+    {
+       char *ibuf;
+
+       ibuf = (char *)xrealloc(oci->buffer, gotnow + count);
+       if (!ibuf)
+           return(FALSE);
+       oci->size = gotnow + count;
+       oci->buffer = ibuf;
+       oci->bufptr = ibuf + oci->bufcnt - gotnow;
+    }
+    if (oci->bufcnt + count > oci->size) {
+       memmove(oci->buffer, oci->bufptr, gotnow);
+       oci->bufcnt = gotnow;
+       oci->bufptr = oci->buffer;
+    }
+    memmove(oci->bufptr + gotnow, data, count);
+    oci->bufcnt += count;
+    gotnow += count;
+    if ((gotnow >= sizeof(xReq)) &&
+       (gotnow >= (int)(get_req_len((xReq *)oci->bufptr, client) << 2)))
+       FD_SET(fd, &ClientsWithInput);
+    else
+       YieldControlNoInput();
+    return(TRUE);
+}
+
+static int
+LbxWrite(trans_conn, proxy, buf, len)
+    XtransConnInfo trans_conn;
+    LbxProxyPtr proxy;
+    char *buf;
+    int len;
+{
+    struct iovec iov;
+    int n;
+    int notWritten;
+
+    notWritten = len;
+    iov.iov_base = buf;
+    iov.iov_len = len;
+    while (notWritten) {
+       errno = 0;
+       if (proxy->compHandle)
+           n = (*proxy->streamOpts.streamCompWriteV)(proxy->fd, &iov, 1);
+       else
+           n = _XSERVTransWritev(trans_conn, &iov, 1);
+       if (n >= 0) {
+           iov.iov_base = (char *)iov.iov_base + n;
+           notWritten -= n;
+           iov.iov_len = notWritten;
+       }
+       else if (ETEST(errno)
+#ifdef SUNSYSV /* check for another brain-damaged OS bug */
+                || (errno == 0)
+#endif
+#ifdef EMSGSIZE /* check for another brain-damaged OS bug */
+                || ((errno == EMSGSIZE) && (iov.iov_len == 1))
+#endif
+               )
+           break;
+#ifdef EMSGSIZE /* check for another brain-damaged OS bug */
+       else if (errno == EMSGSIZE)
+           iov.iov_len >>= 1;
+#endif
+       else
+           return -1;
+    }
+    return len - notWritten;
+}
+
+static Bool
+LbxAppendOutput(proxy, client, oco)
+    LbxProxyPtr proxy;
+    ClientPtr client;
+    ConnectionOutputPtr oco;
+{
+    ConnectionOutputPtr noco = proxy->olast;
+    LbxClientPtr lbxClient = LbxClient(client);
+
+    if (!lbxClient) {
+       xfree(oco->buf);
+       xfree(oco);
+       return TRUE;
+    }
+    if (noco)
+       LbxReencodeOutput(client,
+                         (char *)noco->buf, &noco->count,
+                         (char *)oco->buf, &oco->count);
+    else
+       LbxReencodeOutput(client,
+                         (char *)NULL, (int *)NULL,
+                         (char *)oco->buf, &oco->count);
+    if (!oco->count) {
+       if (oco->size > BUFWATERMARK)
+       {
+           xfree(oco->buf);
+           xfree(oco);
+       }
+       else
+       {
+           oco->next = FreeOutputs;
+           FreeOutputs = oco;
+       }
+       return TRUE;
+    }
+    if ((lbxClient->id != proxy->cur_send_id) && proxy->lbxClients[0]) {
+       xLbxSwitchEvent *ev;
+       int n;
+
+       if (!noco || (noco->size - noco->count) < sz_xLbxSwitchEvent) {
+           if (noco = FreeOutputs)
+               FreeOutputs = noco->next;
+           else
+               noco = AllocateOutputBuffer();
+           if (!noco) {
+               MarkClientException(client);
+               return FALSE;
+           }
+           noco->next = NULL;
+           if (proxy->olast)
+               proxy->olast->next = noco;
+           else
+               proxy->ofirst = noco;
+           proxy->olast = noco;
+       }
+       ev = (xLbxSwitchEvent *) (noco->buf + noco->count);
+       noco->count += sz_xLbxSwitchEvent;
+       proxy->cur_send_id = lbxClient->id;
+       ev->type = LbxEventCode;
+       ev->lbxType = LbxSwitchEvent;
+       ev->pad = 0;
+       ev->client = proxy->cur_send_id;
+       if (LbxProxyClient(proxy)->swapped) {
+           swapl(&ev->client, n);
+       }
+    }
+    oco->next = NULL;
+    if (proxy->olast)
+       proxy->olast->next = oco;
+    else
+       proxy->ofirst = oco;
+    proxy->olast = oco;
+    return TRUE;
+}
+
+static int
+LbxClientOutput(client, oc, extraBuf, extraCount, nocompress)
+    ClientPtr client;
+    OsCommPtr oc;
+    char *extraBuf;
+    int extraCount;
+    Bool nocompress;
+{
+    ConnectionOutputPtr oco;
+    int len;
+
+    if (oco = oc->output) {
+       oc->output = NULL;
+       if (!LbxAppendOutput(oc->proxy, client, oco))
+           return -1;
+    }
+
+    if (extraCount) {
+       NewOutputPending = TRUE;
+       FD_SET(oc->fd, &OutputPending);
+       len = (extraCount + 3) & ~3;
+       if ((oco = FreeOutputs) && (oco->size >= len))
+           FreeOutputs = oco->next;
+       else {
+           oco = (ConnectionOutputPtr)xalloc(sizeof(ConnectionOutput));
+           if (!oco) {
+               MarkClientException(client);
+               return -1;
+           }
+           oco->size = len;
+           if (oco->size < BUFSIZE)
+               oco->size = BUFSIZE;
+           oco->buf = (unsigned char *) xalloc(oco->size);
+           if (!oco->buf) {
+               xfree(oco);
+               MarkClientException(client);
+               return -1;
+           }
+       }
+       oco->count = len;
+       oco->nocompress = nocompress;
+       memmove((char *)oco->buf, extraBuf, extraCount);
+       if (!nocompress && oco->count < oco->size)
+           oc->output = oco;
+       else if (!LbxAppendOutput(oc->proxy, client, oco))
+           return -1;
+    }
+    return extraCount;
+}
+
+void
+LbxForceOutput(proxy)
+    LbxProxyPtr proxy;
+{
+    int i;
+    LbxClientPtr lbxClient;
+    OsCommPtr coc;
+    ConnectionOutputPtr oco;
+
+    for (i = proxy->maxIndex; i >= 0; i--) { /* proxy must be last */
+       lbxClient = proxy->lbxClients[i];
+       if (!lbxClient)
+           continue;
+       coc = (OsCommPtr)lbxClient->client->osPrivate;
+       if (oco = coc->output) {
+           coc->output = NULL;
+           LbxAppendOutput(proxy, lbxClient->client, oco);
+       }
+    }
+}
+
+int
+LbxFlushClient(who, oc, extraBuf, extraCount)
+    ClientPtr who;
+    OsCommPtr oc;
+    char *extraBuf;
+    int extraCount;
+{
+    LbxProxyPtr proxy;
+    ConnectionOutputPtr oco;
+    int n;
+    XtransConnInfo trans_conn;
+
+    if (extraBuf)
+       return LbxClientOutput(who, oc, extraBuf, extraCount, FALSE);
+    proxy = oc->proxy;
+    if (!proxy->lbxClients[0])
+       return 0;
+    LbxForceOutput(proxy);
+    if (!proxy->compHandle)
+       trans_conn = ((OsCommPtr)LbxProxyClient(proxy)->osPrivate)->trans_conn;
+    while (oco = proxy->ofirst) {
+       /* XXX bundle up into writev someday */
+       if (proxy->compHandle) {
+           if (oco->nocompress)
+               (*proxy->streamOpts.streamCompOff)(proxy->fd);
+           n = LbxWrite(NULL, proxy, (char *)oco->buf, oco->count);
+           if (oco->nocompress)
+               (*proxy->streamOpts.streamCompOn)(proxy->fd);
+       } else
+           n = LbxWrite(trans_conn, proxy, (char *)oco->buf, oco->count);
+       if (n < 0) {
+           ClientPtr pclient = LbxProxyClient(proxy);
+           if (proxy->compHandle)
+               trans_conn = ((OsCommPtr)pclient->osPrivate)->trans_conn;
+           _XSERVTransDisconnect(trans_conn);
+           _XSERVTransClose(trans_conn);
+           ((OsCommPtr)pclient->osPrivate)->trans_conn = NULL;
+           MarkClientException(pclient);
+           return 0;
+       } else if (n == oco->count) {
+           proxy->ofirst = oco->next;
+           if (!proxy->ofirst)
+               proxy->olast = NULL;
+           if (oco->size > BUFWATERMARK)
+           {
+               xfree(oco->buf);
+               xfree(oco);
+           }
+           else
+           {
+               oco->next = FreeOutputs;
+               oco->count = 0;
+               FreeOutputs = oco;
+           }
+       } else {
+           if (n) {
+               oco->count -= n;
+               memmove((char *)oco->buf, (char *)oco->buf + n, oco->count);
+           }
+           break;
+       }
+    }
+    if ((proxy->compHandle &&
+        (*proxy->streamOpts.streamCompFlush)(proxy->fd)) ||
+       proxy->ofirst) {
+       FD_SET(proxy->fd, &ClientsWriteBlocked);
+       AnyClientsWriteBlocked = TRUE;
+    }
+    return 0;
+}
+
+int
+UncompressedWriteToClient (who, count, buf)
+    ClientPtr who;
+    char *buf;
+    int count;
+{
+    return LbxClientOutput(who, (OsCommPtr)who->osPrivate, buf, count, TRUE);
+}
+
+LbxFreeOsBuffers(proxy)
+    LbxProxyPtr proxy;
+{
+    ConnectionOutputPtr oco;
+
+    while (oco = proxy->ofirst) {
+       proxy->ofirst = oco->next;
+       xfree(oco->buf);
+       xfree(oco);
+    }
+}
+
+Bool
+AllocateLargeReqBuffer(client, size)
+    ClientPtr client;
+    int size;
+{
+    OsCommPtr oc = (OsCommPtr)client->osPrivate;
+    register ConnectionInputPtr oci;
+
+    if (!(oci = oc->largereq)) {
+       if (oci = FreeInputs)
+           FreeInputs = oci->next;
+       else {
+           oci = (ConnectionInputPtr)xalloc(sizeof(ConnectionInput));
+           if (!oci)
+               return FALSE;
+           oci->buffer = NULL;
+           oci->size = 0;
+       }
+    }
+    if (oci->size < size) {
+       char *ibuf;
+
+       oci->size = size;
+       if (size < BUFSIZE)
+           oci->size = BUFSIZE;
+       if (!(ibuf = (char *)xrealloc(oci->buffer, oci->size)))
+       {
+           xfree(oci->buffer);
+           xfree(oci);
+           oc->largereq = NULL;
+           return FALSE;
+       }
+       oci->buffer = ibuf;
+    }
+    oci->bufptr = oci->buffer;
+    oci->bufcnt = 0;
+    oci->lenLastReq = size;
+    oc->largereq = oci;
+    return TRUE;
+}
+
+Bool
+AddToLargeReqBuffer(client, data, size)
+    ClientPtr client;
+    char *data;
+    int size;
+{
+    OsCommPtr oc = (OsCommPtr)client->osPrivate;
+    register ConnectionInputPtr oci = oc->largereq;
+
+    if (!oci || (oci->bufcnt + size > oci->lenLastReq))
+       return FALSE;
+    memcpy(oci->buffer + oci->bufcnt, data, size);
+    oci->bufcnt += size;
+    return TRUE;
+}
+
+static OsCommRec lbxAvailableInput;
+
+int
+PrepareLargeReqBuffer(client)
+    ClientPtr client;
+{
+    OsCommPtr oc = (OsCommPtr)client->osPrivate;
+    register ConnectionInputPtr oci = oc->largereq;
+
+    if (!oci)
+       return client->req_len << 2;
+    oc->largereq = NULL;
+    if (oci->bufcnt != oci->lenLastReq) {
+       xfree(oci->buffer);
+       xfree(oci);
+       return client->req_len << 2;
+    }
+    client->requestBuffer = oci->buffer;
+    client->req_len = oci->lenLastReq >> 2;
+    oci->bufcnt = 0;
+    oci->lenLastReq = 0;
+    if (AvailableInput)
+    {
+       register ConnectionInputPtr aci = AvailableInput->input;
+       if (aci->size > BUFWATERMARK)
+       {
+           xfree(aci->buffer);
+           xfree(aci);
+       }
+       else
+       {
+           aci->next = FreeInputs;
+           FreeInputs = aci;
+       }
+       AvailableInput->input = (ConnectionInputPtr)NULL;
+    }
+    lbxAvailableInput.input = oci;
+    AvailableInput = &lbxAvailableInput;
+    return client->req_len << 2;
+}
diff --git a/Xserver/programs/Xserver/os/mitauth.c b/Xserver/programs/Xserver/os/mitauth.c
new file mode 100644 (file)
index 0000000..3c163d4
--- /dev/null
@@ -0,0 +1,195 @@
+/* $XConsortium: mitauth.c /main/11 1996/10/28 22:56:36 dpw $ */
+/*
+
+Copyright (c) 1988  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be included
+in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR
+OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall
+not be used in advertising or otherwise to promote the sale, use or
+other dealings in this Software without prior written authorization
+from the X Consortium.
+
+*/
+
+/*
+ * MIT-MAGIC-COOKIE-1 authorization scheme
+ * Author:  Keith Packard, MIT X Consortium
+ */
+
+#include "X.h"
+#include "os.h"
+#include "dixstruct.h"
+
+static struct auth {
+    struct auth        *next;
+    unsigned short     len;
+    char       *data;
+    XID                id;
+} *mit_auth;
+
+int
+MitAddCookie (data_length, data, id)
+unsigned short data_length;
+char   *data;
+XID    id;
+{
+    struct auth        *new;
+
+    new = (struct auth *) xalloc (sizeof (struct auth));
+    if (!new)
+       return 0;
+    new->data = (char *) xalloc ((unsigned) data_length);
+    if (!new->data) {
+       xfree(new);
+       return 0;
+    }
+    new->next = mit_auth;
+    mit_auth = new;
+    memmove(new->data, data, (int) data_length);
+    new->len = data_length;
+    new->id = id;
+    return 1;
+}
+
+XID
+MitCheckCookie (data_length, data, client, reason)
+    unsigned short     data_length;
+    char       *data;
+    ClientPtr client;
+    char       **reason;
+{
+    struct auth        *auth;
+
+    for (auth = mit_auth; auth; auth=auth->next) {
+        if (data_length == auth->len &&
+          memcmp (data, auth->data, (int) data_length) == 0)
+           return auth->id;
+    }
+    *reason = "Invalid MIT-MAGIC-COOKIE-1 key";
+    return (XID) -1;
+}
+
+int
+MitResetCookie ()
+{
+    struct auth        *auth, *next;
+
+    for (auth = mit_auth; auth; auth=next) {
+       next = auth->next;
+       xfree (auth->data);
+       xfree (auth);
+    }
+    mit_auth = 0;
+    return 0;
+}
+
+XID
+MitToID (data_length, data)
+unsigned short data_length;
+char   *data;
+{
+    struct auth        *auth;
+
+    for (auth = mit_auth; auth; auth=auth->next) {
+       if (data_length == auth->len &&
+           memcmp (data, auth->data, data_length) == 0)
+           return auth->id;
+    }
+    return (XID) -1;
+}
+
+int
+MitFromID (id, data_lenp, datap)
+XID id;
+unsigned short *data_lenp;
+char   **datap;
+{
+    struct auth        *auth;
+
+    for (auth = mit_auth; auth; auth=auth->next) {
+       if (id == auth->id) {
+           *data_lenp = auth->len;
+           *datap = auth->data;
+           return 1;
+       }
+    }
+    return 0;
+}
+
+int
+MitRemoveCookie (data_length, data)
+unsigned short data_length;
+char   *data;
+{
+    struct auth        *auth, *prev;
+
+    prev = 0;
+    for (auth = mit_auth; auth; prev = auth, auth=auth->next) {
+       if (data_length == auth->len &&
+           memcmp (data, auth->data, data_length) == 0)
+       {
+           if (prev)
+               prev->next = auth->next;
+           else
+               mit_auth = auth->next;
+           xfree (auth->data);
+           xfree (auth);
+           return 1;
+       }
+    }
+    return 0;
+}
+
+#ifdef XCSECURITY
+
+static char cookie[16]; /* 128 bits */
+
+XID
+MitGenerateCookie (data_length, data, id, data_length_return, data_return)
+    unsigned int data_length;
+    char *data;
+    XID id;
+    unsigned int *data_length_return;
+    char       **data_return;
+{
+    int i = 0;
+    int status;
+
+    while (data_length--)
+    {
+       cookie[i++] += *data++;
+       if (i >= sizeof (cookie)) i = 0;
+    }
+    GenerateRandomData(sizeof (cookie), cookie);
+    status = MitAddCookie(sizeof (cookie), cookie, id);
+    if (!status)
+    {
+       id = -1;
+    }
+    else
+    {
+       *data_return = cookie;
+       *data_length_return = sizeof (cookie);
+    }
+    return id;
+}
+
+#endif /* XCSECURITY */
diff --git a/Xserver/programs/Xserver/os/oscolor.c b/Xserver/programs/Xserver/os/oscolor.c
new file mode 100644 (file)
index 0000000..3943109
--- /dev/null
@@ -0,0 +1,305 @@
+/***********************************************************
+
+Copyright (c) 1987  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+
+Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
+
+                        All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and its 
+documentation for any purpose and without fee is hereby granted, 
+provided that the above copyright notice appear in all copies and that
+both that copyright notice and this permission notice appear in 
+supporting documentation, and that the name of Digital not be
+used in advertising or publicity pertaining to distribution of the
+software without specific, written prior permission.  
+
+DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
+ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
+DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
+ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+SOFTWARE.
+
+******************************************************************/
+/* $XConsortium: oscolor.c,v 1.23 94/04/17 20:27:04 dpw Exp $ */
+/* $XFree86: xc/programs/Xserver/os/oscolor.c,v 3.2.4.1 1998/01/22 10:47:14 dawes Exp $ */
+
+#ifndef USE_RGB_TXT
+
+#ifdef NDBM
+#include <ndbm.h>
+#else
+#ifdef SVR4
+#include <rpcsvc/dbm.h>
+#else
+#include <dbm.h>
+#endif
+#endif
+#include "rgb.h"
+#include "os.h"
+#include "opaque.h"
+
+/* Note that we are assuming there is only one database for all the screens. */
+
+#ifdef NDBM
+DBM *rgb_dbm = (DBM *)NULL;
+#else
+int rgb_dbm = 0;
+#endif
+
+extern void CopyISOLatin1Lowered();
+
+int
+OsInitColors()
+{
+    if (!rgb_dbm)
+    {
+#ifdef NDBM
+       rgb_dbm = dbm_open(rgbPath, 0, 0);
+#else
+       if (dbminit(rgbPath) == 0)
+           rgb_dbm = 1;
+#endif
+       if (!rgb_dbm) {
+           ErrorF( "Couldn't open RGB_DB '%s'\n", rgbPath );
+           return FALSE;
+       }
+    }
+    return TRUE;
+}
+
+/*ARGSUSED*/
+int
+OsLookupColor(screen, name, len, pred, pgreen, pblue)
+    int                screen;
+    char       *name;
+    unsigned   len;
+    unsigned short     *pred, *pgreen, *pblue;
+
+{
+    datum              dbent;
+    RGB                        rgb;
+    char               buf[64];
+    char               *lowername;
+
+    if(!rgb_dbm)
+       return(0);
+
+    /* we use xalloc here so that we can compile with cc without alloca
+     * when otherwise using gcc */
+    if (len < sizeof(buf))
+       lowername = buf;
+    else if (!(lowername = (char *)xalloc(len + 1)))
+       return(0);
+    CopyISOLatin1Lowered ((unsigned char *) lowername, (unsigned char *) name,
+                         (int)len);
+
+    dbent.dptr = lowername;
+    dbent.dsize = len;
+#ifdef NDBM
+    dbent = dbm_fetch(rgb_dbm, dbent);
+#else
+    dbent = fetch (dbent);
+#endif
+
+    if (len >= sizeof(buf))
+       xfree(lowername);
+
+    if(dbent.dptr)
+    {
+       memmove((char *) &rgb, dbent.dptr, sizeof (RGB));
+       *pred = rgb.red;
+       *pgreen = rgb.green;
+       *pblue = rgb.blue;
+       return (1);
+    }
+    return(0);
+}
+
+#else /* USE_RGB_TXT */
+
+
+/*
+ * The dbm routines are a porting hassle. This implementation will do
+ * the same thing by reading the rgb.txt file directly, which is much
+ * more portable.
+ */
+
+#include <stdio.h>
+#include "os.h"
+#include "opaque.h"
+
+#define HASHSIZE 511
+
+typedef struct _dbEntry * dbEntryPtr;
+typedef struct _dbEntry {
+  dbEntryPtr     link;
+  unsigned short red;
+  unsigned short green;
+  unsigned short blue;
+  char           name[1];      /* some compilers complain if [0] */
+} dbEntry;
+
+
+extern void CopyISOLatin1Lowered();
+
+static dbEntryPtr hashTab[HASHSIZE];
+
+
+static dbEntryPtr
+lookup(name, len, create)
+     char *name;
+     int  len;
+     Bool create;
+{
+  unsigned int h = 0, g;
+  dbEntryPtr   entry, *prev;
+  char         *str = name;
+
+  if (!(name = (char*)ALLOCATE_LOCAL(len +1))) return NULL;
+  CopyISOLatin1Lowered(name, str, len);
+  name[len] = '\0';
+
+  for(str = name; *str; str++) {
+    h = (h << 4) + *str;
+    if ((g = h) & 0xf0000000) h ^= (g >> 24);
+    h &= g;
+  }
+  h %= HASHSIZE;
+
+  if ( entry = hashTab[h] )
+    {
+      for( ; entry; prev = (dbEntryPtr*)entry, entry = entry->link )
+       if (! strcmp(name, entry->name) ) break;
+    }
+  else
+    prev = &(hashTab[h]);
+
+  if (!entry && create && (entry = (dbEntryPtr)xalloc(sizeof(dbEntry) +len)))
+    {
+      *prev = entry;
+      entry->link = NULL;
+      strcpy( entry->name, name );
+    }
+
+  DEALLOCATE_LOCAL(name);
+
+  return entry;
+}
+
+
+Bool
+OsInitColors()
+{
+  FILE       *rgb;
+  char       *path;
+  char       line[BUFSIZ];
+  char       name[BUFSIZ];
+  int        red, green, blue, lineno = 0;
+  dbEntryPtr entry;
+
+  static Bool was_here = FALSE;
+
+  if (!was_here)
+    {
+#ifndef __EMX__
+      path = (char*)ALLOCATE_LOCAL(strlen(rgbPath) +5);
+      strcpy(path, rgbPath);
+      strcat(path, ".txt");
+#else
+      char *tmp = (char*)__XOS2RedirRoot(rgbPath);
+      path = (char*)ALLOCATE_LOCAL(strlen(tmp) +5);
+      strcpy(path, tmp);
+      strcat(path, ".txt");
+#endif
+      if (!(rgb = fopen(path, "r")))
+        {
+          ErrorF( "Couldn't open RGB_DB '%s'\n", rgbPath );
+          DEALLOCATE_LOCAL(path);
+          return FALSE;
+       }
+
+      while(fgets(line, sizeof(line), rgb))
+       {
+         lineno++;
+#ifndef __EMX__
+         if (sscanf(line,"%d %d %d %[^\n]\n", &red, &green, &blue, name) == 4)
+#else
+         if (sscanf(line,"%d %d %d %[^\n\r]\n", &red, &green, &blue, name) == 4)
+#endif
+           {
+             if (red >= 0   && red <= 0xff &&
+                 green >= 0 && green <= 0xff &&
+                 blue >= 0  && blue <= 0xff)
+               {
+                 if (entry = lookup(name, strlen(name), TRUE))
+                   {
+                     entry->red   = (red * 65535)   / 255;
+                     entry->green = (green * 65535) / 255;
+                     entry->blue  = (blue  * 65535) / 255;
+                   }
+               }
+             else
+               ErrorF("Value out of range: %s:%d\n", path, lineno);
+           }
+         else if (*line && *line != '#' && *line != '!')
+           ErrorF("Syntax Error: %s:%d\n", path, lineno);
+       }
+      
+      fclose(rgb);
+      DEALLOCATE_LOCAL(path);
+
+      was_here = TRUE;
+    }
+
+  return TRUE;
+}
+
+
+
+Bool
+OsLookupColor(screen, name, len, pred, pgreen, pblue)
+    int                   screen;
+    char          *name;
+    unsigned      len;
+    unsigned short *pred, *pgreen, *pblue;
+
+{
+  dbEntryPtr entry;
+
+  if (entry = lookup(name, len, FALSE))
+    {
+      *pred   = entry->red;
+      *pgreen = entry->green;
+      *pblue  = entry->blue;
+      return TRUE;
+    }
+
+  return FALSE;
+}
+
+#endif /* USE_RGB_TXT */
diff --git a/Xserver/programs/Xserver/os/osdep.h b/Xserver/programs/Xserver/os/osdep.h
new file mode 100644 (file)
index 0000000..31dde6a
--- /dev/null
@@ -0,0 +1,224 @@
+/***********************************************************
+
+Copyright (c) 1987  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+
+Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
+
+                        All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and its 
+documentation for any purpose and without fee is hereby granted, 
+provided that the above copyright notice appear in all copies and that
+both that copyright notice and this permission notice appear in 
+supporting documentation, and that the name of Digital not be
+used in advertising or publicity pertaining to distribution of the
+software without specific, written prior permission.  
+
+DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
+ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
+DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
+ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+SOFTWARE.
+
+******************************************************************/
+/* $XConsortium: osdep.h /main/42 1996/12/15 21:27:39 rws $ */
+/* $XFree86: xc/programs/Xserver/os/osdep.h,v 3.4 1996/12/23 07:09:58 dawes Exp $ */
+
+#ifdef AMOEBA
+#include <stddef.h>
+#define port am_port_t
+#include <amoeba.h>
+#include <stdio.h>
+#include <assert.h>
+#include <semaphore.h>
+#include <circbuf.h>
+#include <exception.h>
+#include <vc.h>
+#include <fault.h>
+#include <module/signals.h>
+#include <server/x11/Xamoeba.h>
+#undef  port
+#endif
+
+#define BOTIMEOUT 200 /* in milliseconds */
+#define BUFSIZE 4096
+#define BUFWATERMARK 8192
+#ifndef MAXBUFSIZE
+#define MAXBUFSIZE (1 << 22)
+#endif
+
+#include <X11/Xmd.h>
+
+#ifndef sgi        /* SGI defines OPEN_MAX in a useless way */
+#ifndef X_NOT_POSIX
+#ifdef _POSIX_SOURCE
+#include <limits.h>
+#else
+#define _POSIX_SOURCE
+#include <limits.h>
+#undef _POSIX_SOURCE
+#endif
+#else /* X_NOT_POSIX */
+#ifdef WIN32
+#define _POSIX_
+#include <limits.h>
+#undef _POSIX_
+#endif
+#endif /* X_NOT_POSIX */
+#endif
+
+#ifndef OPEN_MAX
+#ifdef SVR4
+#define OPEN_MAX 128
+#else
+#include <sys/param.h>
+#ifndef OPEN_MAX
+#if defined(NOFILE) && !defined(NOFILES_MAX)
+#define OPEN_MAX NOFILE
+#else
+#ifndef __EMX__
+#define OPEN_MAX NOFILES_MAX
+#else
+#define OPEN_MAX 256
+#endif
+#endif
+#endif
+#endif
+#endif
+
+#if OPEN_MAX <= 128
+#define MAXSOCKS (OPEN_MAX - 1)
+#else
+#define MAXSOCKS 128
+#endif
+
+#ifndef NULL
+#define NULL 0
+#endif
+
+#ifdef AMOEBA
+#include "X.h"
+#include "misc.h"
+
+#define FamilyAmoeba 33
+
+extern char             *XServerHostName;       /* X server host name */
+extern char             *XTcpServerName;        /* TCP/IP server name */
+extern int              maxClient;              /* Highest client# */
+extern int              nNewConns;              /* # of new clients */
+#endif /* AMOEBA */
+
+typedef struct _connectionInput {
+    struct _connectionInput *next;
+    char *buffer;               /* contains current client input */
+    char *bufptr;               /* pointer to current start of data */
+    int  bufcnt;                /* count of bytes in buffer */
+    int lenLastReq;
+    int size;
+} ConnectionInput, *ConnectionInputPtr;
+
+typedef struct _connectionOutput {
+    struct _connectionOutput *next;
+    int size;
+    unsigned char *buf;
+    int count;
+#ifdef LBX
+    Bool nocompress;
+#endif
+} ConnectionOutput, *ConnectionOutputPtr;
+
+#ifdef K5AUTH
+typedef struct _k5_state {
+    int                stageno;        /* current stage of auth protocol */
+    pointer    srvcreds;       /* server credentials */
+    pointer    srvname;        /* server principal name */
+    pointer    ktname;         /* key table: principal-key pairs */
+    pointer    skey;           /* session key */
+}           k5_state;
+#endif
+
+#ifdef LBX
+typedef struct _LbxProxy *OsProxyPtr;
+#endif
+
+typedef struct _osComm {
+    int fd;
+    ConnectionInputPtr input;
+    ConnectionOutputPtr output;
+    XID        auth_id;                /* authorization id */
+#ifdef K5AUTH
+    k5_state   authstate;      /* state of setup auth conversation */
+#endif
+    CARD32 conn_time;          /* timestamp if not established, else 0  */
+    struct _XtransConnInfo *trans_conn; /* transport connection object */
+#ifdef LBX
+    OsProxyPtr proxy;
+    ConnectionInputPtr largereq;
+    void (*Close) ();
+    int  (*Flush) ();
+#endif
+} OsCommRec, *OsCommPtr;
+
+#ifdef LBX
+#define FlushClient(who, oc, extraBuf, extraCount) \
+    (*(oc)->Flush)(who, oc, extraBuf, extraCount)
+extern int StandardFlushClient(
+#if NeedFunctionPrototypes
+    ClientPtr /*who*/,
+    OsCommPtr /*oc*/,
+    char* /*extraBuf*/,
+    int /*extraCount*/
+#endif
+);
+#else
+extern int FlushClient(
+#if NeedFunctionPrototypes
+    ClientPtr /*who*/,
+    OsCommPtr /*oc*/,
+    char* /*extraBuf*/,
+    int /*extraCount*/
+#endif
+);
+#endif
+
+extern void FreeOsBuffers(
+#if NeedFunctionPrototypes
+    OsCommPtr /*oc*/
+#endif
+);
+
+extern ConnectionInputPtr AllocateInputBuffer(
+#if NeedFunctionPrototypes
+    void
+#endif
+);
+
+extern ConnectionOutputPtr AllocateOutputBuffer(
+#if NeedFunctionPrototypes
+    void
+#endif
+);
diff --git a/Xserver/programs/Xserver/os/osinit.c b/Xserver/programs/Xserver/os/osinit.c
new file mode 100644 (file)
index 0000000..12f40b8
--- /dev/null
@@ -0,0 +1,205 @@
+/***********************************************************
+
+Copyright (c) 1987  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+
+Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
+
+                        All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and its 
+documentation for any purpose and without fee is hereby granted, 
+provided that the above copyright notice appear in all copies and that
+both that copyright notice and this permission notice appear in 
+supporting documentation, and that the name of Digital not be
+used in advertising or publicity pertaining to distribution of the
+software without specific, written prior permission.  
+
+DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
+ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
+DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
+ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+SOFTWARE.
+
+******************************************************************/
+/* $XConsortium: osinit.c /main/45 1996/12/02 10:23:13 lehors $ */
+/* $XFree86: xc/programs/Xserver/os/osinit.c,v 3.12 1997/01/18 06:58:02 dawes Exp $ */
+
+#include <stdio.h>
+#include "X.h"
+#include "os.h"
+#include "osdep.h"
+#include "Xos.h"
+
+#ifndef PATH_MAX
+#ifdef MAXPATHLEN
+#define PATH_MAX MAXPATHLEN
+#else
+#define PATH_MAX 1024
+#endif
+#endif
+
+#if !defined(SYSV) && !defined(AMOEBA) && !defined(_MINIX) && !defined(WIN32) && !defined(Lynx) || defined(hpux) || defined(AIXV4)
+#include <sys/resource.h>
+#endif
+
+#ifndef ADMPATH
+#define ADMPATH "/usr/adm/X%smsgs"
+#endif
+
+extern char *display;
+#ifdef RLIMIT_DATA
+int limitDataSpace = -1;
+#endif
+#ifdef RLIMIT_STACK
+int limitStackSpace = -1;
+#endif
+#ifdef RLIMIT_NOFILE
+int limitNoFile = -1;
+#endif
+
+Bool OsDelayInitColors = FALSE;
+
+void
+OsInit()
+{
+#ifndef AMOEBA
+    static Bool been_here = FALSE;
+    char fname[PATH_MAX];
+
+#ifdef macII
+    set42sig();
+#endif
+
+    if (!been_here) {
+#if !defined(MINIX) && !defined(SCO)
+       fclose(stdin);
+       fclose(stdout);
+#endif
+       /* hack test to decide where to log errors */
+       if (write (2, fname, 0)) 
+       {
+           FILE *err;
+           sprintf (fname, ADMPATH, display);
+           /*
+            * uses stdio to avoid os dependencies here,
+            * a real os would use
+            *  open (fname, O_WRONLY|O_APPEND|O_CREAT, 0666)
+            */
+           if (!(err = fopen (fname, "a+")))
+               err = fopen ("/dev/null", "w");
+           if (err && (fileno(err) != 2)) {
+               dup2 (fileno (err), 2);
+               fclose (err);
+           }
+#if defined(SYSV) || defined(SVR4) || defined(MINIX) || defined(__EMX__) || defined(WIN32)
+           {
+           static char buf[BUFSIZ];
+           setvbuf (stderr, buf, _IOLBF, BUFSIZ);
+           }
+#else
+           setlinebuf(stderr);
+#endif
+       }
+
+#ifndef X_NOT_POSIX
+       if (getpgrp () == 0)
+           setpgid (0, 0);
+#else
+#if !defined(SYSV) && !defined(WIN32)
+       if (getpgrp (0) == 0)
+           setpgrp (0, getpid ());
+#endif
+#endif
+
+#ifdef RLIMIT_DATA
+       if (limitDataSpace >= 0)
+       {
+           struct rlimit       rlim;
+
+           if (!getrlimit(RLIMIT_DATA, &rlim))
+           {
+               if ((limitDataSpace > 0) && (limitDataSpace < rlim.rlim_max))
+                   rlim.rlim_cur = limitDataSpace;
+               else
+                   rlim.rlim_cur = rlim.rlim_max;
+               (void)setrlimit(RLIMIT_DATA, &rlim);
+           }
+       }
+#endif
+#ifdef RLIMIT_STACK
+       if (limitStackSpace >= 0)
+       {
+           struct rlimit       rlim;
+
+           if (!getrlimit(RLIMIT_STACK, &rlim))
+           {
+               if ((limitStackSpace > 0) && (limitStackSpace < rlim.rlim_max))
+                   rlim.rlim_cur = limitStackSpace;
+               else
+                   rlim.rlim_cur = rlim.rlim_max;
+               (void)setrlimit(RLIMIT_STACK, &rlim);
+           }
+       }
+#endif
+#ifdef RLIMIT_NOFILE
+       if (limitNoFile >= 0)
+       {
+           struct rlimit       rlim;
+
+           if (!getrlimit(RLIMIT_NOFILE, &rlim))
+           {
+               if ((limitNoFile > 0) && (limitNoFile < rlim.rlim_max))
+                   rlim.rlim_cur = limitNoFile;
+               else
+                   rlim.rlim_cur = rlim.rlim_max;
+               if (rlim.rlim_cur > MAXSOCKS)
+                   rlim.rlim_cur = MAXSOCKS;
+               (void)setrlimit(RLIMIT_NOFILE, &rlim);
+           }
+       }
+#endif
+#ifdef SERVER_LOCK
+       LockServer();
+#endif
+       been_here = TRUE;
+    }
+#endif /* AMOEBA */
+    TimerInit();
+#ifdef DDXOSINIT
+    OsVendorInit();
+#endif
+    OsInitAllocator();
+    if (!OsDelayInitColors) OsInitColors();
+}
+
+void
+OsCleanup()
+{
+#ifdef SERVER_LOCK
+    UnlockServer();
+#endif
+}
diff --git a/Xserver/programs/Xserver/os/rpcauth.c b/Xserver/programs/Xserver/os/rpcauth.c
new file mode 100644 (file)
index 0000000..6f01040
--- /dev/null
@@ -0,0 +1,206 @@
+/* $XConsortium: rpcauth.c,v 1.9 94/04/17 20:27:06 gildea Exp $ */
+/* $XFree86: xc/programs/Xserver/os/rpcauth.c,v 3.0 1995/07/07 15:46:07 dawes Exp $ */
+/*
+
+Copyright (c) 1991  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be included
+in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR
+OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall
+not be used in advertising or otherwise to promote the sale, use or
+other dealings in this Software without prior written authorization
+from the X Consortium.
+
+*/
+
+/*
+ * SUN-DES-1 authentication mechanism
+ * Author:  Mayank Choudhary, Sun Microsystems
+ */
+
+
+#ifdef SECURE_RPC
+
+#include <stdlib.h>
+#include "X.h"
+#include "Xauth.h"
+#include "misc.h"
+#include "os.h"
+#include "dixstruct.h"
+
+#include <rpc/rpc.h>
+
+#ifdef ultrix
+#include <time.h>
+#include <rpc/auth_des.h>
+#endif
+
+static enum auth_stat why;
+
+static char * 
+authdes_ezdecode(inmsg, len)
+char *inmsg;
+int  len;
+{
+    struct rpc_msg  msg;
+    char            cred_area[MAX_AUTH_BYTES];
+    char            verf_area[MAX_AUTH_BYTES];
+    char            *temp_inmsg;
+    struct svc_req  r;
+    bool_t          res0, res1;
+    XDR             xdr;
+    SVCXPRT         xprt;
+
+    temp_inmsg = (char *) xalloc(len);
+    memmove(temp_inmsg, inmsg, len);
+
+    memset((char *)&msg, 0, sizeof(msg));
+    memset((char *)&r, 0, sizeof(r));
+    memset(cred_area, 0, sizeof(cred_area));
+    memset(verf_area, 0, sizeof(verf_area));
+
+    msg.rm_call.cb_cred.oa_base = cred_area;
+    msg.rm_call.cb_verf.oa_base = verf_area;
+    why = AUTH_FAILED; 
+    xdrmem_create(&xdr, temp_inmsg, len, XDR_DECODE);
+
+    if ((r.rq_clntcred = (caddr_t) xalloc(MAX_AUTH_BYTES)) == NULL)
+        goto bad1;
+    r.rq_xprt = &xprt;
+
+    /* decode into msg */
+    res0 = xdr_opaque_auth(&xdr, &(msg.rm_call.cb_cred)); 
+    res1 = xdr_opaque_auth(&xdr, &(msg.rm_call.cb_verf));
+    if ( ! (res0 && res1) )
+         goto bad2;
+
+    /* do the authentication */
+
+    r.rq_cred = msg.rm_call.cb_cred;        /* read by opaque stuff */
+    if (r.rq_cred.oa_flavor != AUTH_DES) {
+        why = AUTH_TOOWEAK;
+        goto bad2;
+    }
+#ifdef SVR4
+    if ((why = __authenticate(&r, &msg)) != AUTH_OK) {
+#else
+    if ((why = _authenticate(&r, &msg)) != AUTH_OK) {
+#endif
+            goto bad2;
+    }
+    return (((struct authdes_cred *) r.rq_clntcred)->adc_fullname.name); 
+
+bad2:
+    xfree(r.rq_clntcred);
+bad1:
+    return ((char *)0); /* ((struct authdes_cred *) NULL); */
+}
+
+static XID  rpc_id = (XID) ~0L;
+
+static Bool
+CheckNetName (addr, len, closure)
+    unsigned char    *addr;
+    int                    len;
+    pointer        closure;
+{
+    return (len == strlen ((char *) closure) &&
+           strncmp ((char *) addr, (char *) closure, len) == 0);
+}
+
+static char rpc_error[MAXNETNAMELEN+50];
+
+XID
+SecureRPCCheck (data_length, data, client, reason)
+    register unsigned short    data_length;
+    char       *data;
+    ClientPtr client;
+    char       **reason;
+{
+    char *fullname;
+    
+    if (rpc_id == (XID) ~0L) {
+       *reason = "Secure RPC authorization not initialized";
+    } else {
+       fullname = authdes_ezdecode(data, data_length);
+       if (fullname == (char *)0) {
+           sprintf(rpc_error, "Unable to authenticate secure RPC client (why=%d)", why);
+           *reason = rpc_error;
+       } else {
+           if (ForEachHostInFamily (FamilyNetname, CheckNetName,
+                                    (pointer) fullname))
+               return rpc_id;
+           else {
+               sprintf(rpc_error, "Principal \"%s\" is not authorized to connect",
+                       fullname);
+               *reason = rpc_error;
+           }
+       }
+    }
+    return (XID) ~0L;
+}
+    
+
+SecureRPCInit ()
+{
+    if (rpc_id == ~0L)
+       AddAuthorization (9, "SUN-DES-1", 0, (char *) 0);
+}
+
+int
+SecureRPCAdd (data_length, data, id)
+unsigned short data_length;
+char   *data;
+XID    id;
+{
+    if (data_length)
+       AddHost ((pointer) 0, FamilyNetname, data_length, data);
+    rpc_id = id;
+}
+
+int
+SecureRPCReset ()
+{
+    rpc_id = (XID) ~0L;
+}
+
+XID
+SecureRPCToID (data_length, data)
+    unsigned short     data_length;
+    char               *data;
+{
+    return rpc_id;
+}
+
+SecureRPCFromID (id, data_lenp, datap)
+     XID id;
+     unsigned short    *data_lenp;
+     char      **datap;
+{
+    return 0;
+}
+
+SecureRPCRemove (data_length, data)
+     unsigned short    data_length;
+     char      *data;
+{
+    return 0;
+}
+#endif /* SECURE_RPC */
diff --git a/Xserver/programs/Xserver/os/secauth.c b/Xserver/programs/Xserver/os/secauth.c
new file mode 100644 (file)
index 0000000..0c78947
--- /dev/null
@@ -0,0 +1,209 @@
+/* $XConsortium: secauth.c /main/4 1996/11/27 16:57:14 swick $ */
+/*
+Copyright (c) 1996  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be included
+in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR
+OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall
+not be used in advertising or otherwise to promote the sale, use or
+other dealings in this Software without prior written authorization
+from the X Consortium.
+*/
+
+#include "X.h"
+#include "os.h"
+#include "osdep.h"
+#include "dixstruct.h"
+
+/*================================================================
+   BEGIN ORL VNC modification
+   Need function prototype for SecurityGetSitePolicyStrings even when
+   XCSECURITY isn't defined */
+
+/* REMOVE
+#ifdef XCSECURITY
+*/
+#define _SECURITY_SERVER
+#include "extensions/security.h"
+/* REMOVE
+#endif
+*/
+
+/* END ORL VNC modification
+================================================================*/
+
+static char InvalidPolicyReason[] = "invalid policy specification";
+static char PolicyViolationReason[] = "policy violation";
+
+static Bool
+AuthCheckSitePolicy(data_lengthP, dataP, client, reason)
+    unsigned short *data_lengthP;
+    char       **dataP;
+    ClientPtr  client;
+    char       **reason;
+{
+    char       *policy = *dataP;
+    int                length;
+    Bool       permit;
+    int                nPolicies;
+    char       **sitePolicies;
+    int                nSitePolicies;
+    Bool       found = FALSE;
+
+    if ((length = *data_lengthP) < 2) {
+       *reason = InvalidPolicyReason;
+       return FALSE;
+    }
+
+    permit = (*policy++ == 0);
+    nPolicies = *policy++;
+
+    length -= 2;
+
+    sitePolicies = SecurityGetSitePolicyStrings(&nSitePolicies);
+
+    while (nPolicies) {
+       int strLen, sitePolicy;
+
+       if (length == 0) {
+           *reason = InvalidPolicyReason;
+           return FALSE;
+       }
+
+       strLen = *policy++;
+       if (--length < strLen) {
+           *reason = InvalidPolicyReason;
+           return FALSE;
+       }
+
+       if (!found)
+       {
+           for (sitePolicy = 0; sitePolicy < nSitePolicies; sitePolicy++)
+           {
+               char *testPolicy = sitePolicies[sitePolicy];
+               if ((strLen == strlen(testPolicy)) &&
+                   (strncmp(policy, testPolicy, strLen) == 0))
+               {
+                   found = TRUE; /* need to continue parsing the policy... */
+                   break;
+               }
+           }
+       }
+
+       policy += strLen;
+       length -= strLen;
+       nPolicies--;
+    }
+
+    if (found != permit)
+    {
+       *reason = PolicyViolationReason;
+       return FALSE;
+    }
+
+    *data_lengthP = length;
+    *dataP = policy;
+    return TRUE;
+}
+
+XID
+AuthSecurityCheck (data_length, data, client, reason)
+    unsigned short     data_length;
+    char       *data;
+    ClientPtr client;
+    char       **reason;
+{
+#ifdef XCSECURITY
+    OsCommPtr oc = (OsCommPtr)client->osPrivate;
+    register ConnectionInputPtr oci = oc->input;
+    xConnSetupPrefix csp;
+    xReq freq;
+
+    if (client->clientState == ClientStateCheckedSecurity)
+    {
+       *reason = "repeated security check not permitted";
+       return (XID) -1;
+    }
+    else if (data_length > 0)
+    {
+       char policy_mask = *data++;
+
+       if (--data_length == 1) {
+           *reason = InvalidPolicyReason;
+           return (XID) -1;
+       }
+
+       if (policy_mask & 0x01) /* Extensions policy */
+       {
+        /* AuthCheckExtensionPolicy(&data_length, &data, client, reason) */
+           *reason = "security policy not implemented";
+           return (XID) -1;
+       }
+
+       if (policy_mask & 0x02) /* Site policy */
+       {
+           if (!AuthCheckSitePolicy(&data_length, &data, client, reason))
+               return (XID) -1;
+       }
+
+       if (data_length > 0) {  /* did we consume the whole policy? */
+           *reason = InvalidPolicyReason;
+           return (XID) -1;
+       }
+
+    }
+    else if (!GetAccessControl())
+    {
+       *reason = "server host access control is disabled";
+       return (XID) -1;
+    }
+
+    client->clientState = ClientStateCheckingSecurity;
+
+    csp.success = 2 /* Authenticate */;
+    csp.lengthReason = 0;
+    csp.length = 0;
+    csp.majorVersion = X_PROTOCOL;
+    csp.minorVersion = X_PROTOCOL_REVISION;
+    if (client->swapped)
+       WriteSConnSetupPrefix(client, &csp);
+    else
+       (void)WriteToClient(client, sz_xConnSetupPrefix, (char *) &csp);
+
+    /*
+     * Next time the client sends the real auth data, we want
+     * ProcEstablishConnection to be called.
+     */
+
+    freq.reqType = 1;
+    freq.length = (sz_xReq + sz_xConnClientPrefix) >> 2;
+    client->swapped = FALSE;
+    if (!InsertFakeRequest(client, (char *)&freq, sz_xReq))
+    {
+       *reason = "internal error";
+       return (XID) -1;
+    }
+
+    return (XID) 0;
+#else
+    *reason = "method not supported";
+    return (XID) -1;
+#endif
+}
diff --git a/Xserver/programs/Xserver/os/utils.c b/Xserver/programs/Xserver/os/utils.c
new file mode 100644 (file)
index 0000000..d2d0422
--- /dev/null
@@ -0,0 +1,1541 @@
+/* $TOG: utils.c /main/128 1997/06/01 13:50:39 sekhar $ */
+/*
+
+Copyright (c) 1987  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be included
+in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR
+OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall
+not be used in advertising or otherwise to promote the sale, use or
+other dealings in this Software without prior written authorization
+from the X Consortium.
+
+
+Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts,
+Copyright 1994 Quarterdeck Office Systems.
+
+                        All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and its
+documentation for any purpose and without fee is hereby granted,
+provided that the above copyright notice appear in all copies and that
+both that copyright notice and this permission notice appear in
+supporting documentation, and that the names of Digital and
+Quarterdeck not be used in advertising or publicity pertaining to
+distribution of the software without specific, written prior
+permission.
+
+DIGITAL AND QUARTERDECK DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
+SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
+FITNESS, IN NO EVENT SHALL DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT
+OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
+OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
+OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE
+OR PERFORMANCE OF THIS SOFTWARE.
+
+*/
+/* $XFree86: xc/programs/Xserver/os/utils.c,v 3.27.2.6 1998/02/20 15:13:58 robin Exp $ */
+
+#ifdef WIN32
+#include <X11/Xwinsock.h>
+#endif
+#include "Xos.h"
+#include <stdio.h>
+#include "misc.h"
+#include "X.h"
+#include "input.h"
+#include "opaque.h"
+#ifdef X_POSIX_C_SOURCE
+#define _POSIX_C_SOURCE X_POSIX_C_SOURCE
+#include <signal.h>
+#undef _POSIX_C_SOURCE
+#else
+#if defined(X_NOT_POSIX) || defined(_POSIX_SOURCE)
+#include <signal.h>
+#else
+#define _POSIX_SOURCE
+#include <signal.h>
+#undef _POSIX_SOURCE
+#endif
+#endif
+#if !defined(SYSV) && !defined(AMOEBA) && !defined(_MINIX) && !defined(WIN32) && !defined(Lynx) || defined(hpux) || defined(AIXV4)
+#include <sys/resource.h>
+#endif
+#include <time.h>
+#include <sys/stat.h>
+#include <ctype.h>    /* for isspace */
+#if NeedVarargsPrototypes
+#include <stdarg.h>
+#endif
+
+#ifdef AMOEBA
+#include "osdep.h"
+#include <amoeba.h>
+#include <module/mutex.h>
+
+static mutex print_lock;
+#endif
+
+#if defined(__STDC__) || defined(AMOEBA)
+/* DHD: SVR4.0 has a prototype for abs() in stdlib.h */
+/* DHD: might be better to move this include higher up? */
+#ifdef abs
+#undef abs
+#endif
+#ifndef NOSTDHDRS
+#include <stdlib.h>    /* for malloc() */
+#endif
+#endif
+
+extern char *display;
+
+extern CARD32 defaultScreenSaverTime;  /* for parsing command line */
+extern CARD32 defaultScreenSaverInterval;
+extern int defaultScreenSaverBlanking;
+extern int defaultBackingStore;
+extern Bool disableBackingStore;
+extern Bool disableSaveUnders;
+extern Bool PartialNetwork;
+#ifndef NOLOGOHACK
+extern int logoScreenSaver;
+#endif
+#ifdef RLIMIT_DATA
+extern int limitDataSpace;
+#endif
+#ifdef RLIMIT_STACK
+extern int limitStackSpace;
+#endif
+#ifdef RLIMIT_NOFILE
+extern int limitNoFile;
+#endif
+extern int defaultColorVisualClass;
+extern Bool permitOldBugs;
+extern int monitorResolution;
+extern Bool defeatAccessControl;
+#ifdef SERVER_LOCK
+static Bool nolock = FALSE;
+#endif
+
+extern char* protNoListen;
+
+Bool CoreDump;
+Bool noTestExtensions;
+
+int auditTrailLevel = 1;
+
+void ddxUseMsg();
+#if NeedVarargsPrototypes
+void VErrorF(char*, va_list);
+#endif
+
+#ifdef DEBUG
+#ifndef SPECIAL_MALLOC
+#define MEMBUG
+#endif
+#endif
+
+#ifdef MEMBUG
+#define MEM_FAIL_SCALE 100000
+long Memory_fail = 0;
+#ifdef linux
+#include <stdlib.h>  /* for random() */
+#endif
+#endif
+
+#ifdef sgi
+int userdefinedfontpath = 0;
+#endif /* sgi */
+
+Bool Must_have_memory = FALSE;
+
+char *dev_tty_from_init = NULL;                /* since we need to parse it anyway */
+
+OsSigHandlerPtr
+OsSignal(sig, handler)
+    int sig;
+    OsSigHandlerPtr handler;
+{
+#ifdef X_NOT_POSIX
+    return signal(sig, handler);
+#else
+    struct sigaction act, oact;
+
+    sigemptyset(&act.sa_mask);
+    if (handler != SIG_IGN)
+       sigaddset(&act.sa_mask, sig);
+    act.sa_flags = 0;
+    act.sa_handler = handler;
+    sigaction(sig, &act, &oact);
+    return oact.sa_handler;
+#endif
+}
+
+#include <errno.h>
+extern int errno;
+
+#ifdef SERVER_LOCK
+/*
+ * Explicit support for a server lock file like the ones used for UUCP.
+ * For architectures with virtual terminals that can run more than one
+ * server at a time.  This keeps the servers from stomping on each other
+ * if the user forgets to give them different display numbers.
+ */
+#ifndef __EMX__
+#define LOCK_DIR "/tmp"
+#define LOCK_TMP_PREFIX "/.tX"
+#define LOCK_PREFIX "/.X"
+#define LOCK_SUFFIX "-lock"
+#else
+#define LOCK_TMP_PREFIX "/xf86$"
+#define LOCK_PREFIX "/xf86_"
+#define LOCK_SUFFIX ".lck"
+#endif
+
+#ifdef _MINIX
+#include <limits.h>    /* For PATH_MAX */
+#endif
+
+#ifdef __EMX__
+#define link rename
+#endif
+
+#ifndef PATH_MAX
+#ifndef Lynx
+#include <sys/param.h>
+#else
+#include <param.h>
+#endif
+#ifndef PATH_MAX
+#ifdef MAXPATHLEN
+#define PATH_MAX MAXPATHLEN
+#else
+#define PATH_MAX 1024
+#endif
+#endif
+#endif
+
+static Bool StillLocking = FALSE;
+static char LockFile[PATH_MAX];
+
+/*
+ * LockServer --
+ *      Check if the server lock file exists.  If so, check if the PID
+ *      contained inside is valid.  If so, then die.  Otherwise, create
+ *      the lock file containing the PID.
+ */
+void
+LockServer()
+{
+#ifndef AMOEBA
+  char tmp[PATH_MAX], pid_str[12];
+  int lfd, i, haslock, l_pid, t;
+  char *tmppath = NULL;
+  int len;
+
+  if (nolock) return;
+  /*
+   * Path names
+   */
+#ifndef __EMX__
+  tmppath = LOCK_DIR;
+#else
+  /* OS/2 uses TMP directory, must also prepare for 8.3 names */
+  tmppath = getenv("TMP");
+  if (!tmppath)
+    FatalError("No TMP dir found\n");
+#endif
+
+  len = strlen(LOCK_PREFIX) > strlen(LOCK_TMP_PREFIX) ? strlen(LOCK_PREFIX) :
+                                               strlen(LOCK_TMP_PREFIX);
+  len += strlen(tmppath) + strlen(display) + strlen(LOCK_SUFFIX) + 1;
+  if (len > sizeof(LockFile))
+    FatalError("Display name `%s' is too long\n");
+  (void)sprintf(tmp, "%s" LOCK_TMP_PREFIX "%s" LOCK_SUFFIX, tmppath, display);
+  (void)sprintf(LockFile, "%s" LOCK_PREFIX "%s" LOCK_SUFFIX, tmppath, display);
+
+  /*
+   * Create a temporary file containing our PID.  Attempt three times
+   * to create the file.
+   */
+  StillLocking = TRUE;
+  i = 0;
+  do {
+    i++;
+    lfd = open(tmp, O_CREAT | O_EXCL | O_WRONLY, 0644);
+    if (lfd < 0)
+       sleep(2);
+    else
+       break;
+  } while (i < 3);
+  if (lfd < 0) {
+    unlink(tmp);
+    i = 0;
+    do {
+      i++;
+      lfd = open(tmp, O_CREAT | O_EXCL | O_WRONLY, 0644);
+      if (lfd < 0)
+         sleep(2);
+      else
+         break;
+    } while (i < 3);
+  }
+  if (lfd < 0)
+    FatalError("Could not create lock file in %s\n", tmp);
+  (void) sprintf(pid_str, "%10d\n", getpid());
+  (void) write(lfd, pid_str, 11);
+#ifndef __EMX__
+#ifndef USE_CHMOD
+  (void) fchmod(lfd, 0444);
+#else
+  (void) chmod(tmp, 0444);
+#endif
+#endif
+  (void) close(lfd);
+
+  /*
+   * OK.  Now the tmp file exists.  Try three times to move it in place
+   * for the lock.
+   */
+  i = 0;
+  haslock = 0;
+  while ((!haslock) && (i++ < 3)) {
+    haslock = (link(tmp,LockFile) == 0);
+    if (haslock) {
+      /*
+       * We're done.
+       */
+      break;
+    }
+    else {
+      /*
+       * Read the pid from the existing file
+       */
+      lfd = open(LockFile, O_RDONLY);
+      if (lfd < 0) {
+        unlink(tmp);
+        FatalError("Can't read lock file %s\n", LockFile);
+      }
+      pid_str[0] = '\0';
+      if (read(lfd, pid_str, 11) != 11) {
+        /*
+         * Bogus lock file.
+         */
+        unlink(LockFile);
+        close(lfd);
+        continue;
+      }
+      pid_str[11] = '\0';
+      sscanf(pid_str, "%d", &l_pid);
+      close(lfd);
+
+      /*
+       * Now try to kill the PID to see if it exists.
+       */
+      errno = 0;
+      t = kill(l_pid, 0);
+      if ((t< 0) && (errno == ESRCH)) {
+        /*
+         * Stale lock file.
+         */
+        unlink(LockFile);
+        continue;
+      }
+      else if (((t < 0) && (errno == EPERM)) || (t == 0)) {
+        /*
+         * Process is still active.
+         */
+        unlink(tmp);
+       FatalError("Server is already active for display %s\n%s %s\n%s\n",
+                  display, "\tIf this server is no longer running, remove",
+                  LockFile, "\tand start again.");
+      }
+    }
+  }
+  unlink(tmp);
+  if (!haslock)
+    FatalError("Could not create server lock file: %s\n", LockFile);
+  StillLocking = FALSE;
+#endif /* !AMOEBA */
+}
+
+/*
+ * UnlockServer --
+ *      Remove the server lock file.
+ */
+void
+UnlockServer()
+{
+#ifndef AMOEBA
+  if (nolock) return;
+
+  if (!StillLocking){
+
+#ifdef __EMX__
+  (void) chmod(LockFile,S_IREAD|S_IWRITE);
+#endif /* __EMX__ */
+  (void) unlink(LockFile);
+  }
+#endif
+
+}
+#endif /* SERVER_LOCK */
+
+/* Force connections to close on SIGHUP from init */
+
+/*ARGSUSED*/
+SIGVAL
+AutoResetServer (sig)
+    int sig;
+{
+    dispatchException |= DE_RESET;
+    isItTimeToYield = TRUE;
+#ifdef GPROF
+    chdir ("/tmp");
+    exit (0);
+#endif
+#if defined(SYSV) && defined(X_NOT_POSIX)
+    OsSignal (SIGHUP, AutoResetServer);
+#endif
+#ifdef AMOEBA
+    WakeUpMainThread();
+#endif
+}
+
+/* Force connections to close and then exit on SIGTERM, SIGINT */
+
+/*ARGSUSED*/
+SIGVAL
+GiveUp(sig)
+    int sig;
+{
+    dispatchException |= DE_TERMINATE;
+    isItTimeToYield = TRUE;
+#if defined(SYSV) && defined(X_NOT_POSIX)
+    if (sig)
+       OsSignal(sig, SIG_IGN);
+#endif
+#ifdef AMOEBA
+    WakeUpMainThread();
+#endif
+}
+
+#if __GNUC__
+static void AbortServer() __attribute__((noreturn));
+#endif
+
+static void
+AbortServer()
+{
+    extern void AbortDDX();
+
+    OsCleanup();
+    AbortDDX();
+    fflush(stderr);
+#ifdef AMOEBA
+    IOPCleanUp();
+#endif
+    if (CoreDump)
+       abort();
+    exit (1);
+}
+
+void
+Error(str)
+    char *str;
+{
+#ifdef AMOEBA
+    mu_lock(&print_lock);
+#endif
+    perror(str);
+#ifdef AMOEBA
+    mu_unlock(&print_lock);
+#endif
+}
+
+#ifndef DDXTIME
+CARD32
+GetTimeInMillis()
+{
+#ifndef AMOEBA
+    struct timeval  tp;
+
+    X_GETTIMEOFDAY(&tp);
+    return(tp.tv_sec * 1000) + (tp.tv_usec / 1000);
+#else
+    return sys_milli();
+#endif
+}
+#endif
+
+AdjustWaitForDelay (waitTime, newdelay)
+    pointer        waitTime;
+    unsigned long   newdelay;
+{
+    static struct timeval   delay_val;
+    struct timeval         **wt = (struct timeval **) waitTime;
+    unsigned long          olddelay;
+
+    if (*wt == NULL)
+    {
+       delay_val.tv_sec = newdelay / 1000;
+       delay_val.tv_usec = 1000 * (newdelay % 1000);
+       *wt = &delay_val;
+    }
+    else
+    {
+       olddelay = (*wt)->tv_sec * 1000 + (*wt)->tv_usec / 1000;
+       if (newdelay < olddelay)
+       {
+           (*wt)->tv_sec = newdelay / 1000;
+           (*wt)->tv_usec = 1000 * (newdelay % 1000);
+       }
+    }
+}
+
+void UseMsg()
+{
+#if !defined(AIXrt) && !defined(AIX386)
+#ifndef AMOEBA
+    ErrorF("use: X [:<display>] [option]\n");
+#else
+    ErrorF("use: X [[<host>]:<display>] [option]\n");
+#endif
+    ErrorF("-a #                   mouse acceleration (pixels)\n");
+    ErrorF("-ac                    disable access control restrictions\n");
+#ifdef MEMBUG
+    ErrorF("-alloc int             chance alloc should fail\n");
+#endif
+    ErrorF("-audit int             set audit trail level\n");  
+    ErrorF("-auth file             select authorization file\n");      
+    ErrorF("bc                     enable bug compatibility\n");
+    ErrorF("-bs                    disable any backing store support\n");
+    ErrorF("-c                     turns off key-click\n");
+    ErrorF("c #                    key-click volume (0-100)\n");
+    ErrorF("-cc int                default color visual class\n");
+    ErrorF("-co file               color database file\n");
+#if 0
+    ErrorF("-config file           read options from file\n");
+#endif
+    ErrorF("-core                  generate core dump on fatal error\n");
+    ErrorF("-dpi int               screen resolution in dots per inch\n");
+#ifdef DPMSExtension
+    ErrorF("dpms                   enables VESA DPMS monitor control\n");
+    ErrorF("-dpms                  disables VESA DPMS monitor control\n");
+#endif
+    ErrorF("-deferglyphs [none|all|16] defer loading of [no|all|16-bit] glyphs\n");
+    ErrorF("-f #                   bell base (0-100)\n");
+    ErrorF("-fc string             cursor font\n");
+    ErrorF("-fn string             default font name\n");
+    ErrorF("-fp string             default font path\n");
+    ErrorF("-help                  prints message with these options\n");
+    ErrorF("-I                     ignore all remaining arguments\n");
+#ifdef RLIMIT_DATA
+    ErrorF("-ld int                limit data space to N Kb\n");
+#endif
+#ifdef RLIMIT_NOFILE
+    ErrorF("-lf int                limit number of open files to N\n");
+#endif
+#ifdef RLIMIT_STACK
+    ErrorF("-ls int                limit stack space to N Kb\n");
+#endif
+#ifdef SERVER_LOCK
+    ErrorF("-nolock                disable the locking mechanism\n");
+#endif
+#ifndef NOLOGOHACK
+    ErrorF("-logo                  enable logo in screen saver\n");
+    ErrorF("nologo                 disable logo in screen saver\n");
+#endif
+    ErrorF("-nolisten string       don't listen on protocol\n");
+    ErrorF("-p #                   screen-saver pattern duration (minutes)\n");
+    ErrorF("-pn                    accept failure to listen on all ports\n");
+    ErrorF("-nopn                  reject failure to listen on all ports\n");
+    ErrorF("-r                     turns off auto-repeat\n");
+    ErrorF("r                      turns on auto-repeat \n");
+    ErrorF("-s #                   screen-saver timeout (minutes)\n");
+#ifdef XCSECURITY
+    ErrorF("-sp file               security policy file\n");
+#endif
+    ErrorF("-su                    disable any save under support\n");
+    ErrorF("-t #                   mouse threshold (pixels)\n");
+    ErrorF("-terminate             terminate at server reset\n");
+    ErrorF("-to #                  connection time out\n");
+    ErrorF("-tst                   disable testing extensions\n");
+    ErrorF("ttyxx                  server started from init on /dev/ttyxx\n");
+    ErrorF("v                      video blanking for screen-saver\n");
+    ErrorF("-v                     screen-saver without video blanking\n");
+    ErrorF("-wm                    WhenMapped default backing-store\n");
+    ErrorF("-x string              loads named extension at init time \n");
+#ifdef AMOEBA
+    ErrorF("-tcp capability        specify TCP/IP server capability\n");
+#endif
+#ifdef XDMCP
+    XdmcpUseMsg();
+#endif
+#endif /* !AIXrt && ! AIX386 */
+#ifdef XKB
+    XkbUseMsg();
+#endif
+    ddxUseMsg();
+}
+
+/*
+ * This function parses the command line. Handles device-independent fields
+ * and allows ddx to handle additional fields.  It is not allowed to modify
+ * argc or any of the strings pointed to by argv.
+ */
+void
+ProcessCommandLine ( argc, argv )
+int    argc;
+char   *argv[];
+
+{
+    int i, skip;
+
+#ifdef AMOEBA
+    mu_init(&print_lock);
+#endif
+
+    defaultKeyboardControl.autoRepeat = TRUE;
+
+#ifdef PART_NET
+       PartialNetwork = TRUE;
+#endif
+
+    for ( i = 1; i < argc; i++ )
+    {
+       /* call ddx first, so it can peek/override if it wants */
+        if(skip = ddxProcessArgument(argc, argv, i))
+       {
+           i += (skip - 1);
+       }
+       else if(argv[i][0] ==  ':')  
+       {
+           /* initialize display */
+           display = argv[i];
+           display++;
+       }
+#ifdef AMOEBA
+        else if (strchr(argv[i], ':') != NULL) {
+            char *p;
+
+            XServerHostName = argv[i];
+            if ((p = strchr(argv[i], ':')) != NULL) {
+                *p++ = '\0';
+                display = p;
+            }
+        } else if (strcmp( argv[i], "-tcp") == 0) {
+            if (++i < argc)
+                XTcpServerName = argv[i];
+            else
+                UseMsg();
+        }
+#endif /* AMOEBA */
+       else if ( strcmp( argv[i], "-a") == 0)
+       {
+           if(++i < argc)
+               defaultPointerControl.num = atoi(argv[i]);
+           else
+               UseMsg();
+       }
+       else if ( strcmp( argv[i], "-ac") == 0)
+       {
+           defeatAccessControl = TRUE;
+       }
+#ifdef MEMBUG
+       else if ( strcmp( argv[i], "-alloc") == 0)
+       {
+           if(++i < argc)
+               Memory_fail = atoi(argv[i]);
+           else
+               UseMsg();
+       }
+#endif
+       else if ( strcmp( argv[i], "-audit") == 0)
+       {
+           if(++i < argc)
+               auditTrailLevel = atoi(argv[i]);
+           else
+               UseMsg();
+       }
+       else if ( strcmp( argv[i], "-auth") == 0)
+       {
+           if(++i < argc)
+               InitAuthorization (argv[i]);
+           else
+               UseMsg();
+       }
+       else if ( strcmp( argv[i], "bc") == 0)
+           permitOldBugs = TRUE;
+       else if ( strcmp( argv[i], "-bs") == 0)
+           disableBackingStore = TRUE;
+       else if ( strcmp( argv[i], "c") == 0)
+       {
+           if(++i < argc)
+               defaultKeyboardControl.click = atoi(argv[i]);
+           else
+               UseMsg();
+       }
+       else if ( strcmp( argv[i], "-c") == 0)
+       {
+           defaultKeyboardControl.click = 0;
+       }
+       else if ( strcmp( argv[i], "-cc") == 0)
+       {
+           if(++i < argc)
+               defaultColorVisualClass = atoi(argv[i]);
+           else
+               UseMsg();
+       }
+       else if ( strcmp( argv[i], "-co") == 0)
+       {
+           if(++i < argc)
+               rgbPath = argv[i];
+           else
+               UseMsg();
+       }
+       else if ( strcmp( argv[i], "-core") == 0)
+           CoreDump = TRUE;
+       else if ( strcmp( argv[i], "-dpi") == 0)
+       {
+           if(++i < argc)
+               monitorResolution = atoi(argv[i]);
+           else
+               UseMsg();
+       }
+#ifdef DPMSExtension
+       else if ( strcmp( argv[i], "dpms") == 0)
+           DPMSEnabledSwitch = TRUE;
+       else if ( strcmp( argv[i], "-dpms") == 0)
+           DPMSDisabledSwitch = TRUE;
+#endif
+       else if ( strcmp( argv[i], "-deferglyphs") == 0)
+       {
+           if(++i >= argc || !ParseGlyphCachingMode(argv[i]))
+               UseMsg();
+       }
+       else if ( strcmp( argv[i], "-f") == 0)
+       {
+           if(++i < argc)
+               defaultKeyboardControl.bell = atoi(argv[i]);
+           else
+               UseMsg();
+       }
+       else if ( strcmp( argv[i], "-fc") == 0)
+       {
+           if(++i < argc)
+               defaultCursorFont = argv[i];
+           else
+               UseMsg();
+       }
+       else if ( strcmp( argv[i], "-fn") == 0)
+       {
+           if(++i < argc)
+               defaultTextFont = argv[i];
+           else
+               UseMsg();
+       }
+       else if ( strcmp( argv[i], "-fp") == 0)
+       {
+           if(++i < argc)
+           {
+#ifdef sgi
+               userdefinedfontpath = 1;
+#endif /* sgi */
+               defaultFontPath = argv[i];
+           }
+           else
+               UseMsg();
+       }
+       else if ( strcmp( argv[i], "-help") == 0)
+       {
+           UseMsg();
+           exit(0);
+       }
+#ifdef XKB
+        else if ( (skip=XkbProcessArguments(argc,argv,i))!=0 ) {
+           if (skip>0)
+                i+= skip-1;
+           else UseMsg();
+       }
+#endif
+#ifdef RLIMIT_DATA
+       else if ( strcmp( argv[i], "-ld") == 0)
+       {
+           if(++i < argc)
+           {
+               limitDataSpace = atoi(argv[i]);
+               if (limitDataSpace > 0)
+                   limitDataSpace *= 1024;
+           }
+           else
+               UseMsg();
+       }
+#endif
+#ifdef RLIMIT_NOFILE
+       else if ( strcmp( argv[i], "-lf") == 0)
+       {
+           if(++i < argc)
+               limitNoFile = atoi(argv[i]);
+           else
+               UseMsg();
+       }
+#endif
+#ifdef RLIMIT_STACK
+       else if ( strcmp( argv[i], "-ls") == 0)
+       {
+           if(++i < argc)
+           {
+               limitStackSpace = atoi(argv[i]);
+               if (limitStackSpace > 0)
+                   limitStackSpace *= 1024;
+           }
+           else
+               UseMsg();
+       }
+#endif
+#ifdef SERVER_LOCK
+       else if ( strcmp ( argv[i], "-nolock") == 0)
+       {
+           nolock = TRUE;
+       }
+#endif
+#ifndef NOLOGOHACK
+       else if ( strcmp( argv[i], "-logo") == 0)
+       {
+           logoScreenSaver = 1;
+       }
+       else if ( strcmp( argv[i], "nologo") == 0)
+       {
+           logoScreenSaver = 0;
+       }
+#endif
+       else if ( strcmp( argv[i], "-nolisten") == 0)
+       {
+            if(++i < argc)
+               protNoListen = argv[i];
+           else
+               UseMsg();
+       }
+       else if ( strcmp( argv[i], "-p") == 0)
+       {
+           if(++i < argc)
+               defaultScreenSaverInterval = ((CARD32)atoi(argv[i])) *
+                                            MILLI_PER_MIN;
+           else
+               UseMsg();
+       }
+       else if ( strcmp( argv[i], "-pn") == 0)
+           PartialNetwork = TRUE;
+       else if ( strcmp( argv[i], "-nopn") == 0)
+           PartialNetwork = FALSE;
+       else if ( strcmp( argv[i], "r") == 0)
+           defaultKeyboardControl.autoRepeat = TRUE;
+       else if ( strcmp( argv[i], "-r") == 0)
+           defaultKeyboardControl.autoRepeat = FALSE;
+       else if ( strcmp( argv[i], "-s") == 0)
+       {
+           if(++i < argc)
+               defaultScreenSaverTime = ((CARD32)atoi(argv[i])) *
+                                        MILLI_PER_MIN;
+           else
+               UseMsg();
+       }
+       else if ( strcmp( argv[i], "-su") == 0)
+           disableSaveUnders = TRUE;
+       else if ( strcmp( argv[i], "-t") == 0)
+       {
+           if(++i < argc)
+               defaultPointerControl.threshold = atoi(argv[i]);
+           else
+               UseMsg();
+       }
+       else if ( strcmp( argv[i], "-terminate") == 0)
+       {
+           extern Bool terminateAtReset;
+           
+           terminateAtReset = TRUE;
+       }
+       else if ( strcmp( argv[i], "-to") == 0)
+       {
+           if(++i < argc)
+               TimeOutValue = ((CARD32)atoi(argv[i])) * MILLI_PER_SECOND;
+           else
+               UseMsg();
+       }
+       else if ( strcmp( argv[i], "-tst") == 0)
+       {
+           noTestExtensions = TRUE;
+       }
+       else if ( strcmp( argv[i], "v") == 0)
+           defaultScreenSaverBlanking = PreferBlanking;
+       else if ( strcmp( argv[i], "-v") == 0)
+           defaultScreenSaverBlanking = DontPreferBlanking;
+       else if ( strcmp( argv[i], "-wm") == 0)
+           defaultBackingStore = WhenMapped;
+       else if ( strcmp( argv[i], "-x") == 0)
+       {
+           if(++i >= argc)
+               UseMsg();
+           /* For U**x, which doesn't support dynamic loading, there's nothing
+            * to do when we see a -x.  Either the extension is linked in or
+            * it isn't */
+       }
+       else if ( strcmp( argv[i], "-I") == 0)
+       {
+           /* ignore all remaining arguments */
+           break;
+       }
+       else if (strncmp (argv[i], "tty", 3) == 0)
+       {
+           /* just in case any body is interested */
+           dev_tty_from_init = argv[i];
+       }
+#ifdef XDMCP
+       else if ((skip = XdmcpOptions(argc, argv, i)) != i)
+       {
+           i = skip - 1;
+       }
+#endif
+#ifdef XPRINT
+       else if ((skip = XprintOptions(argc, argv, i)) != i)
+       {
+           i = skip - 1;
+       }
+#endif
+#ifdef XCSECURITY
+       else if ((skip = XSecurityOptions(argc, argv, i)) != i)
+       {
+           i = skip - 1;
+       }
+#endif
+       else
+       {
+           ErrorF("Unrecognized option: %s\n", argv[i]);
+           UseMsg();
+           exit (1);
+        }
+    }
+}
+
+#if 0
+static void
+InsertFileIntoCommandLine(resargc, resargv, prefix_argc, prefix_argv,
+                         filename, suffix_argc, suffix_argv)
+    int *resargc;
+    char ***resargv;
+    int prefix_argc;
+    char **prefix_argv;
+    char *filename;
+    int suffix_argc;
+    char **suffix_argv;
+{
+    struct stat     st;
+    FILE           *f;
+    char           *p;
+    char           *q;
+    int             insert_argc;
+    char           *buf;
+    int             len;
+    int             i;
+
+    f = fopen(filename, "r");
+    if (!f)
+       FatalError("Can't open option file %s\n", filename);
+
+    fstat(fileno(f), &st);
+
+    buf = (char *) xalloc((unsigned) st.st_size + 1);
+    if (!buf)
+       FatalError("Out of Memory\n");
+
+    len = fread(buf, 1, (unsigned) st.st_size, f);
+
+    fclose(f);
+
+    if (len < 0)
+       FatalError("Error reading option file %s\n", filename);
+
+    buf[len] = '\0';
+
+    p = buf;
+    q = buf;
+    insert_argc = 0;
+
+    while (*p)
+    {
+       while (isspace(*p))
+           p++;
+       if (!*p)
+           break;
+       if (*p == '#')
+       {
+           while (*p && *p != '\n')
+               p++;
+       } else
+       {
+           while (*p && !isspace(*p))
+               *q++ = *p++;
+           /* Since p and q might still be pointing at the same place, we       */
+           /* need to step p over the whitespace now before we add the null.    */
+           if (*p)
+               p++;
+           *q++ = '\0';
+           insert_argc++;
+       }
+    }
+
+    buf = (char *) xrealloc(buf, q - buf);
+    if (!buf)
+       FatalError("Out of memory reallocing option buf\n");
+
+    *resargc = prefix_argc + insert_argc + suffix_argc;
+    *resargv = (char **) xalloc((*resargc + 1) * sizeof(char *));
+
+    memcpy(*resargv, prefix_argv, prefix_argc * sizeof(char *));
+
+    p = buf;
+    for (i = 0; i < insert_argc; i++)
+    {
+       (*resargv)[prefix_argc + i] = p;
+       p += strlen(p) + 1;
+    }
+
+    memcpy(*resargv + prefix_argc + insert_argc,
+          suffix_argv, suffix_argc * sizeof(char *));
+
+    (*resargv)[*resargc] = NULL;
+} /* end InsertFileIntoCommandLine */
+
+void
+ExpandCommandLine(pargc, pargv)
+    int *pargc;
+    char ***pargv;
+{
+    int i;
+
+    for (i = 1; i < *pargc; i++)
+    {
+       if ( (0 == strcmp((*pargv)[i], "-config")) && (i < (*pargc - 1)) )
+       {
+           InsertFileIntoCommandLine(pargc, pargv,
+                                         i, *pargv,
+                                         (*pargv)[i+1], /* filename */
+                                         *pargc - i - 2, *pargv + i + 2);
+           i--;
+       }
+    }
+} /* end ExpandCommandLine */
+#endif
+
+#if defined(TCPCONN) || defined(STREAMSCONN)
+#ifndef WIN32
+#include <netdb.h>
+#endif
+#endif
+
+/* Implement a simple-minded font authorization scheme.  The authorization
+   name is "hp-hostname-1", the contents are simply the host name. */
+int
+set_font_authorizations(authorizations, authlen, client)
+char **authorizations;
+int *authlen;
+pointer client;
+{
+#define AUTHORIZATION_NAME "hp-hostname-1"
+#if defined(TCPCONN) || defined(STREAMSCONN)
+    static char result[1024];
+    static char *p = NULL;
+
+    if (p == NULL)
+    {
+       char hname[1024], *hnameptr;
+       struct hostent *host;
+       int len;
+
+       gethostname(hname, 1024);
+       host = gethostbyname(hname);
+       if (host == NULL)
+           hnameptr = hname;
+       else
+           hnameptr = host->h_name;
+
+       p = result;
+        *p++ = sizeof(AUTHORIZATION_NAME) >> 8;
+        *p++ = sizeof(AUTHORIZATION_NAME) & 0xff;
+        *p++ = (len = strlen(hnameptr) + 1) >> 8;
+        *p++ = (len & 0xff);
+
+       memmove(p, AUTHORIZATION_NAME, sizeof(AUTHORIZATION_NAME));
+       p += sizeof(AUTHORIZATION_NAME);
+       memmove(p, hnameptr, len);
+       p += len;
+    }
+    *authlen = p - result;
+    *authorizations = result;
+    return 1;
+#else /* TCPCONN */
+    return 0;
+#endif /* TCPCONN */
+}
+
+/* XALLOC -- X's internal memory allocator.  Why does it return unsigned
+ * long * instead of the more common char *?  Well, if you read K&R you'll
+ * see they say that alloc must return a pointer "suitable for conversion"
+ * to whatever type you really want.  In a full-blown generic allocator
+ * there's no way to solve the alignment problems without potentially
+ * wasting lots of space.  But we have a more limited problem. We know
+ * we're only ever returning pointers to structures which will have to
+ * be long word aligned.  So we are making a stronger guarantee.  It might
+ * have made sense to make Xalloc return char * to conform with people's
+ * expectations of malloc, but this makes lint happier.
+ */
+
+#ifndef INTERNAL_MALLOC
+
+unsigned long * 
+Xalloc (amount)
+    unsigned long amount;
+{
+#if !defined(__STDC__) && !defined(AMOEBA)
+    char               *malloc();
+#endif
+    register pointer  ptr;
+       
+    if ((long)amount <= 0) {
+       return (unsigned long *)NULL;
+    }
+    /* aligned extra on long word boundary */
+    amount = (amount + (sizeof(long) - 1)) & ~(sizeof(long) - 1);
+#ifdef MEMBUG
+    if (!Must_have_memory && Memory_fail &&
+       ((random() % MEM_FAIL_SCALE) < Memory_fail))
+       return (unsigned long *)NULL;
+#endif
+    if (ptr = (pointer)malloc(amount)) {
+       return (unsigned long *)ptr;
+    }
+    if (Must_have_memory)
+       FatalError("Out of memory");
+    return (unsigned long *)NULL;
+}
+
+/*****************
+ * XNFalloc 
+ * "no failure" realloc, alternate interface to Xalloc w/o Must_have_memory
+ *****************/
+
+unsigned long *
+XNFalloc (amount)
+    unsigned long amount;
+{
+#if !defined(__STDC__) && !defined(AMOEBA)
+    char             *malloc();
+#endif
+    register pointer ptr;
+
+    if ((long)amount <= 0)
+    {
+        return (unsigned long *)NULL;
+    }
+    /* aligned extra on long word boundary */
+    amount = (amount + (sizeof(long) - 1)) & ~(sizeof(long) - 1);
+    ptr = (pointer)malloc(amount);
+    if (!ptr)
+    {
+        FatalError("Out of memory");
+    }
+    return ((unsigned long *)ptr);
+}
+
+/*****************
+ * Xcalloc
+ *****************/
+
+unsigned long *
+Xcalloc (amount)
+    unsigned long   amount;
+{
+    unsigned long   *ret;
+
+    ret = Xalloc (amount);
+    if (ret)
+       bzero ((char *) ret, (int) amount);
+    return ret;
+}
+
+/*****************
+ * Xrealloc
+ *****************/
+
+unsigned long *
+Xrealloc (ptr, amount)
+    register pointer ptr;
+    unsigned long amount;
+{
+#if !defined(__STDC__) && !defined(AMOEBA)
+    char *malloc();
+    char *realloc();
+#endif
+
+#ifdef MEMBUG
+    if (!Must_have_memory && Memory_fail &&
+       ((random() % MEM_FAIL_SCALE) < Memory_fail))
+       return (unsigned long *)NULL;
+#endif
+    if ((long)amount <= 0)
+    {
+       if (ptr && !amount)
+           free(ptr);
+       return (unsigned long *)NULL;
+    }
+    amount = (amount + (sizeof(long) - 1)) & ~(sizeof(long) - 1);
+    if (ptr)
+        ptr = (pointer)realloc((char *)ptr, amount);
+    else
+       ptr = (pointer)malloc(amount);
+    if (ptr)
+        return (unsigned long *)ptr;
+    if (Must_have_memory)
+       FatalError("Out of memory");
+    return (unsigned long *)NULL;
+}
+                    
+/*****************
+ * XNFrealloc 
+ * "no failure" realloc, alternate interface to Xrealloc w/o Must_have_memory
+ *****************/
+
+unsigned long *
+XNFrealloc (ptr, amount)
+    register pointer ptr;
+    unsigned long amount;
+{
+    if (( ptr = (pointer)Xrealloc( ptr, amount ) ) == NULL)
+    {
+        FatalError( "Out of memory" );
+    }
+    return ((unsigned long *)ptr);
+}
+
+/*****************
+ *  Xfree
+ *    calls free 
+ *****************/    
+
+void
+Xfree(ptr)
+    register pointer ptr;
+{
+    if (ptr)
+       free((char *)ptr); 
+}
+
+void
+OsInitAllocator ()
+{
+#ifdef MEMBUG
+    static int been_here;
+
+    /* Check the memory system after each generation */
+    if (been_here)
+       CheckMemory ();
+    else
+       been_here = 1;
+#endif
+}
+#endif
+
+void
+AuditPrefix(f)
+    char *f;
+{
+#ifdef X_NOT_STDC_ENV
+    long tm;
+#else
+    time_t tm;
+#endif
+    char *autime, *s;
+    if (*f != ' ')
+    {
+       time(&tm);
+       autime = ctime(&tm);
+       if (s = strchr(autime, '\n'))
+           *s = '\0';
+       if (s = strrchr(argvGlobal[0], '/'))
+           s++;
+       else
+           s = argvGlobal[0];
+       ErrorF("AUDIT: %s: %d %s: ", autime, getpid(), s);
+    }
+}
+
+/*VARARGS1*/
+void
+AuditF(
+#if NeedVarargsPrototypes
+    char * f, ...)
+#else
+    f, s0, s1, s2, s3, s4, s5, s6, s7, s8, s9) /* limit of ten args */
+    char *f;
+    char *s0, *s1, *s2, *s3, *s4, *s5, *s6, *s7, *s8, *s9;
+#endif
+{
+#if NeedVarargsPrototypes
+    va_list args;
+#endif
+
+    AuditPrefix(f);
+
+#if NeedVarargsPrototypes
+    va_start(args, f);
+    VErrorF(f, args);
+    va_end(args);
+#else
+    ErrorF(f, s0, s1, s2, s3, s4, s5, s6, s7, s8, s9);
+#endif
+}
+
+/*VARARGS1*/
+void
+FatalError(
+#if NeedVarargsPrototypes
+    char *f, ...)
+#else
+f, s0, s1, s2, s3, s4, s5, s6, s7, s8, s9) /* limit of ten args */
+    char *f;
+    char *s0, *s1, *s2, *s3, *s4, *s5, *s6, *s7, *s8, *s9;
+#endif
+{
+#if NeedVarargsPrototypes
+    va_list args;
+#endif
+    ErrorF("\nFatal server error:\n");
+#if NeedVarargsPrototypes
+    va_start(args, f);
+    VErrorF(f, args);
+    va_end(args);
+#else
+    ErrorF(f, s0, s1, s2, s3, s4, s5, s6, s7, s8, s9);
+#endif
+    ErrorF("\n");
+#ifdef DDXOSFATALERROR
+    OsVendorFatalError();
+#endif
+    AbortServer();
+    /*NOTREACHED*/
+}
+
+#if NeedVarargsPrototypes
+void
+VErrorF(f, args)
+    char *f;
+    va_list args;
+{
+    vfprintf(stderr, f, args);
+}
+#endif
+
+/*VARARGS1*/
+void
+ErrorF(
+#if NeedVarargsPrototypes
+    char * f, ...)
+#else
+ f, s0, s1, s2, s3, s4, s5, s6, s7, s8, s9) /* limit of ten args */
+    char *f;
+    char *s0, *s1, *s2, *s3, *s4, *s5, *s6, *s7, *s8, *s9;
+#endif
+{
+#if NeedVarargsPrototypes
+    va_list args;
+    va_start(args, f);
+    VErrorF(f, args);
+    va_end(args);
+#else
+#ifdef AMOEBA
+    mu_lock(&print_lock);
+#endif
+    fprintf( stderr, f, s0, s1, s2, s3, s4, s5, s6, s7, s8, s9);
+#ifdef AMOEBA
+    mu_unlock(&print_lock);
+#endif
+#endif
+}
+
+#if !defined(WIN32) && !defined(__EMX__)
+/*
+ * "safer" versions of system(3), popen(3) and pclose(3) which give up
+ * all privs before running a command.
+ *
+ * This is based on the code in FreeBSD 2.2 libc.
+ */
+
+int
+System(command)
+    char *command;
+{
+    int pid, p;
+    void (*csig)();
+    int status;
+
+    if (!command)
+       return(1);
+
+#ifdef SIGCHLD
+    csig = signal(SIGCHLD, SIG_DFL);
+#endif
+
+    ErrorF("System: `%s'\n", command);
+
+    switch (pid = fork()) {
+    case -1:   /* error */
+       p = -1;
+    case 0:    /* child */
+       setgid(getgid());
+       setuid(getuid());
+       execl("/bin/sh", "sh", "-c", command, (char *)NULL);
+       _exit(127);
+    default:   /* parent */
+       do {
+           p = waitpid(pid, &status, 0);
+       } while (p == -1 && errno == EINTR);
+       
+    }
+
+#ifdef SIGCHLD
+    signal(SIGCHLD, csig);
+#endif
+
+    return p == -1 ? -1 : status;
+}
+
+static struct pid {
+    struct pid *next;
+    FILE *fp;
+    int pid;
+} *pidlist;
+
+pointer
+Popen(command, type)
+    char *command;
+    char *type;
+{
+    struct pid *cur;
+    FILE *iop;
+    int pdes[2], pid;
+    void (*csig)();
+
+    if (command == NULL || type == NULL)
+       return NULL;
+
+    if ((*type != 'r' && *type != 'w') || type[1])
+       return NULL;
+
+    if ((cur = (struct pid *)xalloc(sizeof(struct pid))) == NULL)
+       return NULL;
+
+    if (pipe(pdes) < 0) {
+       xfree(cur);
+       return NULL;
+    }
+
+    switch (pid = fork()) {
+    case -1:   /* error */
+       close(pdes[0]);
+       close(pdes[1]);
+       xfree(cur);
+       return NULL;
+    case 0:    /* child */
+       setgid(getgid());
+       setuid(getuid());
+       if (*type == 'r') {
+           if (pdes[1] != 1) {
+               /* stdout */
+               dup2(pdes[1], 1);
+               close(pdes[1]);
+           }
+           close(pdes[0]);
+       } else {
+           if (pdes[0] != 0) {
+               /* stdin */
+               dup2(pdes[0], 0);
+               close(pdes[0]);
+           }
+           close(pdes[1]);
+       }
+       execl("/bin/sh", "sh", "-c", command, (char *)NULL);
+       _exit(127);
+    }
+
+    /* parent */
+    if (*type == 'r') {
+       iop = fdopen(pdes[0], type);
+       close(pdes[1]);
+    } else {
+       iop = fdopen(pdes[1], type);
+       close(pdes[0]);
+    }
+
+    cur->fp = iop;
+    cur->pid = pid;
+    cur->next = pidlist;
+    pidlist = cur;
+
+#if 0
+    ErrorF("Popen: `%s', fp = %p\n", command, iop);
+#endif
+
+    return iop;
+}
+
+int
+Pclose(iop)
+    pointer iop;
+{
+    struct pid *cur, *last;
+    int omask;
+    int pstat;
+    int pid;
+
+#if 0
+    ErrorF("Pclose: fp = %p\n", iop);
+#endif
+
+    fclose(iop);
+
+    for (last = NULL, cur = pidlist; cur; last = cur, cur = cur->next)
+       if (cur->fp = iop)
+           break;
+    if (cur == NULL)
+       return -1;
+
+    do {
+       pid = waitpid(cur->pid, &pstat, 0);
+    } while (pid == -1 && errno == EINTR);
+
+    if (last == NULL)
+       pidlist = cur->next;
+    else
+       last->next = cur->next;
+    xfree(cur);
+
+    return pid == -1 ? -1 : pstat;
+}
+#endif /* !WIN32 && !__EMX__ */
diff --git a/Xserver/programs/Xserver/os/wrapper.c b/Xserver/programs/Xserver/os/wrapper.c
new file mode 100644 (file)
index 0000000..07e8da0
--- /dev/null
@@ -0,0 +1,241 @@
+/*
+ * X server wrapper.
+ *
+ * This wrapper makes some sanity checks on the command line arguments
+ * and environment variables when run with euid == 0 && euid != uid.
+ * If the checks fail, the wrapper exits with a message.
+ * If they succeed, it exec's the Xserver.
+ */
+
+/*
+ * Copyright (c) 1998 by The XFree86 Project, Inc.  All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject
+ * to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE XFREE86 PROJECT BE LIABLE FOR ANY CLAIM, DAMAGES
+ * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
+ * OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ * Except as contained in this notice, the name of the XFree86 Project
+ * shall not be used in advertising or otherwise to promote the sale,
+ * use or other dealings in this Software without prior written
+ * authorization from the XFree86 Project.
+ */
+
+/* $XFree86: xc/programs/Xserver/os/wrapper.c,v 1.1.2.5 1998/02/27 15:28:59 dawes Exp $ */
+
+/* This is normally set in the Imakefile */
+#ifndef XSERVER_PATH
+#define XSERVER_PATH   "/usr/X11R6/bin/X"
+#endif
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+#include <unistd.h>
+
+/* Neither of these should be required for XFree86 3.3.2 */
+#ifndef REJECT_CONFIG
+#define REJECT_CONFIG 0
+#endif
+#ifndef REJECT_XKBDIR
+#define REJECT_XKBDIR 0
+#endif
+
+/* Consider LD* variables insecure ? */
+#ifndef REMOVE_ENV_LD
+#define REMOVE_ENV_LD 1
+#endif
+
+/* Remove long environment variables? */
+#ifndef REMOVE_LONG_ENV
+#define REMOVE_LONG_ENV 1
+#endif
+
+/* Check args and env only if running setuid (euid == 0 && euid != uid) ? */
+#ifndef CHECK_EUID
+#define CHECK_EUID 1
+#endif
+
+/*
+ * Maybe the locale can be faked to make isprint(3) report that everything
+ * is printable?  Avoid it by default.
+ */
+#ifndef USE_ISPRINT
+#define USE_ISPRINT 0
+#endif
+
+#define MAX_ARG_LENGTH         128
+#define MAX_ENV_LENGTH         256
+#define MAX_ENV_PATH_LENGTH    2048
+
+#if USE_ISPRINT
+#include <ctype.h>
+#define checkPrintable(c) isprint(c)
+#else
+#define checkPrintable(c) (((c) & 0x7f) >= 0x20 && ((c) & 0x7f) != 0x7f)
+#endif
+
+enum BadCode {
+    NotBad = 0,
+    UnsafeArg,
+    ArgTooLong,
+    UnprintableArg,
+    EnvTooLong,
+    InternalError
+};
+
+#define ARGMSG \
+    "\nIf the arguments used are valid, and have been rejected incorrectly\n" \
+      "please send details of the arguments and why they are valid to\n" \
+      "XFree86@XFree86.org.  In the meantime, you can start the Xserver as\n" \
+      "the \"super user\" (root).\n"   
+
+#define ENVMSG \
+    "\nIf the environment is valid, and have been rejected incorrectly\n" \
+      "please send details of the environment and why it is valid to\n" \
+      "XFree86@XFree86.org.  In the meantime, you can start the Xserver as\n" \
+      "the \"super user\" (root).\n"
+
+int
+main(int argc, char **argv, char **envp)
+{
+    enum BadCode bad = NotBad;
+    int i, j;
+    char *a, *e;
+
+#if CHECK_EUID
+    if (geteuid() == 0 && getuid() != geteuid()) {
+#endif
+       /* Check each argv[] */
+       for (i = 1; i < argc; i++) {
+
+           /* Check for known bad arguments */
+#if REJECT_CONFIG
+           if (strcmp(argv[i], "-config") == 0) {
+               bad = UnsafeArg;
+               break;
+           }
+#endif
+#if REJECT_XKBDIR
+           if (strcmp(argv[i], "-xkbdir") == 0) {
+               bad = UnsafeArg;
+               break;
+           }
+#endif
+           if (strlen(argv[i]) > MAX_ARG_LENGTH) {
+               bad = ArgTooLong;
+               break;
+           }
+           a = argv[i];
+           while (*a) {
+               if (checkPrintable(*a) == 0) {
+                   bad = UnprintableArg;
+                   break;
+               }
+               a++;
+           }
+           if (bad)
+               break;
+       }
+       /* Check each envp[] */
+       if (!bad)
+           for (i = 0; envp[i]; i++) {
+
+               /* Check for bad environment variables and values */
+#if REMOVE_ENV_LD
+               while (envp[i] && (strncmp(envp[i], "LD", 2) == 0)) {
+                   for (j = i; envp[j]; j++) {
+                       envp[j] = envp[j+1];
+                   }
+               }
+#endif   
+               if (envp[i] && (strlen(envp[i]) > MAX_ENV_LENGTH)) {
+#if REMOVE_LONG_ENV
+                   for (j = i; envp[j]; j++) {
+                       envp[j] = envp[j+1];
+                   }
+                   i--;
+#else
+                   char *eq;
+                   int len;
+
+                   eq = strchr(envp[i], '=');
+                   if (!eq)
+                       continue;
+                   len = eq - envp[i];
+                   e = malloc(len + 1);
+                   if (!e) {
+                       bad = InternalError;
+                       break;
+                   }
+                   strncpy(e, envp[i], len);
+                   e[len] = 0;
+                   if (len >= 4 &&
+                       (strcmp(e + len - 4, "PATH") == 0 ||
+                        strcmp(e, "TERMCAP") == 0)) {
+                       if (strlen(envp[i]) > MAX_ENV_PATH_LENGTH) {
+                           bad = EnvTooLong;
+                           break;
+                       } else {
+                           free(e);
+                       }
+                   } else {
+                       bad = EnvTooLong;
+                       break;
+                   }
+#endif
+               }
+           }
+#if CHECK_EUID
+    }
+#endif
+    switch (bad) {
+    case NotBad:
+       execve(XSERVER_PATH, argv, envp);
+       fprintf(stderr, "execve failed for %s (errno %d)\n", XSERVER_PATH,
+               errno);
+       break;
+    case UnsafeArg:
+       fprintf(stderr, "Command line argument number %d is unsafe\n", i);
+       fprintf(stderr, ARGMSG);
+       break;
+    case ArgTooLong:
+       fprintf(stderr, "Command line argument number %d is too long\n", i);
+       fprintf(stderr, ARGMSG);
+       break;
+    case UnprintableArg:
+       fprintf(stderr, "Command line argument number %d contains unprintable"
+               " characters\n", i);
+       fprintf(stderr, ARGMSG);
+       break;
+    case EnvTooLong:
+       fprintf(stderr, "Environment variable `%s' is too long\n", e);
+       fprintf(stderr, ENVMSG);
+       break;
+    case InternalError:
+       fprintf(stderr, "Internal Error\n");
+       break;
+    default:
+       fprintf(stderr, "Unknown error\n");
+       fprintf(stderr, ARGMSG);
+       fprintf(stderr, ENVMSG);
+       break;
+    }
+    exit(1);
+}
+
diff --git a/Xserver/programs/Xserver/os/xalloc.c b/Xserver/programs/Xserver/os/xalloc.c
new file mode 100644 (file)
index 0000000..e744291
--- /dev/null
@@ -0,0 +1,724 @@
+/*
+Copyright (C) 1995 Pascal Haible.  All Rights Reserved.
+
+Permission is hereby granted, free of charge, to any person obtaining a
+copy of this software and associated documentation files (the "Software"),
+to deal in the Software without restriction, including without limitation
+the rights to use, copy, modify, merge, publish, distribute, sublicense,
+and/or sell copies of the Software, and to permit persons to whom the
+Software is furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+PASCAL HAIBLE BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
+OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
+
+Except as contained in this notice, the name of Pascal Haible shall
+not be used in advertising or otherwise to promote the sale, use or other
+dealings in this Software without prior written authorization from
+Pascal Haible.
+*/
+
+/* $XFree86: xc/programs/Xserver/os/xalloc.c,v 3.12.2.1 1997/05/10 07:03:02 hohndel Exp $ */
+
+/* Only used if INTERNAL_MALLOC is defined
+ * - otherwise xalloc() in utils.c is used
+ */
+#ifdef INTERNAL_MALLOC
+
+#if defined(__STDC__) || defined(AMOEBA)
+#ifndef NOSTDHDRS
+#include <stdlib.h>    /* for malloc() etc. */
+#endif
+#else
+extern char *malloc();
+extern char *calloc();
+extern char *realloc();
+#endif
+
+#include "Xos.h"
+#include "misc.h"
+#include "X.h"
+
+#ifdef XALLOC_LOG
+#include <stdio.h>
+#endif
+
+extern Bool Must_have_memory;
+
+/*
+ ***** New malloc approach for the X server *****
+ * Pascal Haible 1995
+ *
+ * Some statistics about memory allocation of the X server
+ * The test session included several clients of different size, including
+ * xv, emacs and xpaint with a new canvas of 3000x2000, zoom 5.
+ * All clients were running together.
+ * A protocolling version of Xalloc recorded 318917 allocating actions
+ * (191573 Xalloc, 85942 XNFalloc, 41438 Xrealloc, 279727 Xfree).
+ * Results grouped by size, excluding the next lower size
+ * (i.e. size=32 means 16<size<=32):
+ *
+ *    size   nr of alloc   max nr of blocks allocated together
+ *       8     1114            287
+ *      16     17341           4104
+ *      32     147352          2068
+ *      64     59053           2518
+ *     128     46882           1230
+ *     256     20544           1217
+ *     512     6808            117
+ *    1024     8254            171
+ *    2048     4841            287
+ *    4096     2429            84
+ *    8192     3364            85
+ *   16384     573             22
+ *   32768     49              7
+ *   65536     45              5
+ *  131072     48              2
+ *  262144     209             2
+ *  524288     7               4
+ * 1048576     2               1
+ * 8388608     2               2
+ *
+ * The most used sizes:
+ * count size
+ * 24  136267
+ * 40  37055
+ * 72  17278
+ * 56  13504
+ * 80  9372
+ * 16  8966
+ * 32  8411
+ * 136 8399
+ * 104 7690
+ * 12  7630
+ * 120 5512
+ * 88  4634
+ * 152 3062
+ * 52  2881
+ * 48  2736
+ * 156 1569
+ * 168 1487
+ * 160 1483
+ * 28  1446
+ * 1608        1379
+ * 184 1305
+ * 552 1270
+ * 64  934
+ * 320 891
+ * 8   754
+ *
+ * Conclusions: more than the half of all allocations are <= 32 bytes.
+ * But of these about 150,000 blocks, only a maximum of about 6,000 are
+ * allocated together (including memory leaks..).
+ * On the other side, only 935 of the 191573 or 0.5% were larger than 8kB
+ * (362 or 0.2% larger than 16k).
+ *
+ * What makes the server really grow is the fragmentation of the heap,
+ * and the fact that it can't shrink.
+ * To cure this, we do the following:
+ * - large blocks (>=11k) are mmapped on xalloc, and unmapped on xfree,
+ *   so we don't need any free lists etc.
+ *   As this needs 2 system calls, we only do this for the quite
+ *   infrequent large (>=11k) blocks.
+ * - instead of reinventing the wheel, we use system malloc for medium
+ *   sized blocks (>256, <11k).
+ * - for small blocks (<=256) we use an other approach:
+ *   As we need many small blocks, and most ones for a short time,
+ *   we don't go through the system malloc:
+ *   for each fixed sizes a seperate list of free blocks is kept.
+ *   to KISS (Keep it Small and Simple), we don't free them
+ *   (not freeing a block of 32 bytes won't be worse than having fragmented
+ *   a larger area on allocation).
+ *   This way, we (almost) allways have a fitting free block right at hand,
+ *   and don't have to walk any lists.
+ */
+
+/*
+ * structure layout of a allocated block
+ * unsigned long       size:
+ *                             rounded up netto size for small and medium blocks
+ *                             brutto size == mmap'ed area for large blocks
+ * unsigned long       DEBUG ? MAGIC : unused
+ * ....                        data
+ * ( unsigned long     MAGIC2 ) only if SIZE_TAIL defined
+ *
+ */
+/* use otherwise unused long in the header to store a magic */
+/* shouldn't this be removed for production release ? */
+#define XALLOC_DEBUG
+
+#ifdef XALLOC_DEBUG
+/* Xfree fills the memory with a certain pattern (currently 0xF0) */
+/* this should really be removed for production release! */
+#define XFREE_ERASES
+#endif
+
+/* this must be a multiple of SIZE_STEPS below */
+#define MAX_SMALL 264          /* quite many blocks of 264 */
+
+#define MIN_LARGE (11*1024)
+/* worst case is 25% loss with a page size of 4k */
+
+/* SIZE_STEPS defines the granularity of size of small blocks -
+ * this makes blocks align to that, too! */
+#define SIZE_STEPS             (sizeof(double))
+#define SIZE_HEADER            (2*sizeof(long)) /* = sizeof(double) for 32bit */
+#ifdef XALLOC_DEBUG
+#if defined(__sparc__) || defined(__hppa__)
+#define SIZE_TAIL              (2*sizeof(long)) /* = sizeof(double) for 32bit */
+#else
+#define SIZE_TAIL              (sizeof(long))
+#endif
+#endif
+
+#undef TAIL_SIZE
+#ifdef SIZE_TAIL
+#define TAIL_SIZE              SIZE_TAIL
+#else
+#define TAIL_SIZE              0
+#endif
+
+#ifdef __alpha__
+#define MAGIC                  0x1404196414071968
+#define MAGIC2                 0x2515207525182079
+#else
+#define MAGIC                  0x14071968
+#define MAGIC2                 0x25182079
+#endif
+
+/* To get some statistics about memory allocation */
+
+#ifdef XALLOC_LOG
+#define XALLOC_LOG_FILE "/tmp/Xalloc.log"      /* unsecure... */
+#define LOG_BODY(_body)                                        \
+               { FILE *f;                              \
+                 f = fopen(XALLOC_LOG_FILE, "a");      \
+                 if (NULL!=f) {                        \
+                       _body;                          \
+                       fclose(f);                      \
+                 }                                     \
+               }
+#if defined(linux) && defined(i386)
+#define LOG_ALLOC(_fun, _size, _ret)                                           \
+       {       unsigned long *from;                                            \
+               __asm__("movl %%ebp,%0" : /*OUT*/ "=r" (from) : /*IN*/ );       \
+               LOG_BODY(fprintf(f, "%s\t%i\t%p\t[%lu]\n", _fun, _size, _ret, *(from+1))) \
+       }
+#else
+#define LOG_ALLOC(_fun, _size, _ret)                           \
+       LOG_BODY(fprintf(f, "%s\t%i\t%p\n", _fun, _size, _ret))
+#endif
+#define LOG_REALLOC(_fun, _ptr, _size, _ret)                   \
+       LOG_BODY(fprintf(f, "%s\t%p\t%i\t%p\n", _fun, _ptr, _size, _ret))
+#define LOG_FREE(_fun, _ptr)                                   \
+       LOG_BODY(fprintf(f, "%s\t%p\n", _fun, _ptr))
+#else
+#define LOG_ALLOC(_fun, _size, _ret)
+#define LOG_REALLOC(_fun, _ptr, _size, _ret)
+#define LOG_FREE(_fun, _ptr)
+#endif /* XALLOC_LOG */
+
+static unsigned long *free_lists[MAX_SMALL/SIZE_STEPS];
+
+/*
+ * systems that support it should define HAS_MMAP_ANON or MMAP_DEV_ZERO
+ * and include the appropriate header files for
+ * mmap(), munmap(), PROT_READ, PROT_WRITE, MAP_PRIVATE,
+ * PAGE_SIZE or _SC_PAGESIZE (and MAP_ANON for HAS_MMAP_ANON).
+ *
+ * systems that don't support MAP_ANON fall through to the 2 fold behaviour
+ */
+
+#if defined(linux)
+#define HAS_MMAP_ANON
+#include <sys/types.h>
+#include <sys/mman.h>
+#include <asm/page.h>  /* PAGE_SIZE */
+#endif /* linux */
+
+#if defined(CSRG_BASED)
+#define HAS_MMAP_ANON
+#define HAS_GETPAGESIZE
+#include <sys/types.h>
+#include <sys/mman.h>
+#endif /* CSRG_BASED */
+
+#if defined(SVR4)
+#define MMAP_DEV_ZERO
+#include <sys/types.h>
+#include <sys/mman.h>
+#include <unistd.h>
+#endif /* SVR4 */
+
+#if defined(sun) && !defined(SVR4) /* SunOS */
+#define MMAP_DEV_ZERO  /* doesn't SunOS have MAP_ANON ?? */
+#define HAS_GETPAGESIZE
+#include <sys/types.h>
+#include <sys/mman.h>
+#endif /* sun && !SVR4 */
+
+#ifdef XNO_SYSCONF
+#undef _SC_PAGESIZE
+#endif
+
+#if defined(HAS_MMAP_ANON) || defined (MMAP_DEV_ZERO)
+static int pagesize;
+#endif
+
+#ifdef MMAP_DEV_ZERO
+static int devzerofd = -1;
+#include <errno.h>
+#ifdef X_NOT_STDC_ENV
+extern int errno;
+#endif
+#endif
+
+
+unsigned long *
+Xalloc (amount)
+    unsigned long amount;
+{
+    register unsigned long *ptr;
+    int indx;
+
+    /* sanity checks */
+
+    /* zero size requested */
+    if (amount == 0) {
+       LOG_ALLOC("Xalloc=0", amount, 0);
+       return (unsigned long *)NULL;
+    }
+    /* negative size (or size > 2GB) - what do we do? */
+    if ((long)amount < 0) {
+       /* Diagnostic */
+#ifdef FATALERRORS
+       FatalError("Xalloc: Xalloc(<0)\n");
+#else
+       ErrorF("Xalloc warning: Xalloc(<0) ignored..\n");
+#endif
+       LOG_ALLOC("Xalloc<0", amount, 0);
+       return (unsigned long *)NULL;
+    }
+
+    /* alignment check */
+#if defined(__alpha__) || defined(__sparc__) || defined(__mips__) || defined(__hppa__)
+    amount = (amount + (sizeof(long)-1)) & ~(sizeof(long)-1);
+#endif
+
+    if (amount <= MAX_SMALL) {
+       /*
+        * small block
+        */
+       /* pick a ready to use small chunk */
+       indx = (amount-1) / SIZE_STEPS;
+       ptr = free_lists[indx];
+       if (NULL == ptr) {
+               /* list empty - get 20 or 40 more */
+               /* amount = size rounded up */
+               amount = (indx+1) * SIZE_STEPS;
+               ptr = (unsigned long *)calloc(1,(amount+SIZE_HEADER+TAIL_SIZE)
+                                               * (amount<100 ? 40 : 20));
+               if (NULL!=ptr) {
+                       int i;
+                       unsigned long *p1, *p2;
+                       p2 = (unsigned long *)((char *)ptr + SIZE_HEADER);
+                       for (i=0; i<(amount<100 ? 40 : 20); i++) {
+                               p1 = p2;
+                               p1[-2] = amount;
+#ifdef XALLOC_DEBUG
+                               p1[-1] = MAGIC;
+#endif /* XALLOC_DEBUG */
+#ifdef SIZE_TAIL
+                               *(unsigned long *)((unsigned char *)p1 + amount) = MAGIC2;
+#endif /* SIZE_TAIL */
+                               p2 = (unsigned long *)((char *)p1 + SIZE_HEADER + amount + TAIL_SIZE);
+                               *(unsigned long **)p1 = p2;
+                       }
+                       /* last one has no next one */
+                       *(unsigned long **)p1 = NULL;
+                       /* put the second in the list */
+                       free_lists[indx] = (unsigned long *)((char *)ptr + SIZE_HEADER + amount + TAIL_SIZE + SIZE_HEADER);
+                       /* take the fist one */
+                       ptr = (unsigned long *)((char *)ptr + SIZE_HEADER);
+                       LOG_ALLOC("Xalloc-S", amount, ptr);
+                       return ptr;
+               } /* else fall through to 'Out of memory' */
+       } else {
+               /* take that piece of mem out of the list */
+               free_lists[indx] = *((unsigned long **)ptr);
+               /* already has size (and evtl. magic) filled in */
+               LOG_ALLOC("Xalloc-S", amount, ptr);
+               return ptr;
+       }
+
+#if defined(HAS_MMAP_ANON) || defined(MMAP_DEV_ZERO)
+    } else if (amount >= MIN_LARGE) {
+       /*
+        * large block
+        */
+       /* mmapped malloc */
+       /* round up amount */
+       amount += SIZE_HEADER + TAIL_SIZE;
+       /* round up brutto amount to a multiple of the page size */
+       amount = (amount + pagesize-1) & ~(pagesize-1);
+#ifdef MMAP_DEV_ZERO
+       ptr = (unsigned long *)mmap((caddr_t)0,
+                                       (size_t)amount,
+                                       PROT_READ | PROT_WRITE,
+                                       MAP_PRIVATE,
+                                       devzerofd,
+                                       (off_t)0);
+#else
+       ptr = (unsigned long *)mmap((caddr_t)0,
+                                       (size_t)amount,
+                                       PROT_READ | PROT_WRITE,
+                                       MAP_ANON | MAP_PRIVATE,
+                                       -1,
+                                       (off_t)0);
+#endif
+       if (-1!=(long)ptr) {
+               ptr[0] = amount - SIZE_HEADER - TAIL_SIZE;
+#ifdef XALLOC_DEBUG
+               ptr[1] = MAGIC;
+#endif /* XALLOC_DEBUG */
+#ifdef SIZE_TAIL
+# ifdef __hppa__
+               /* reserved space for 2 * sizeof(long), so use correct one */
+               /* see SIZE_TAIL macro */
+               ((unsigned long *)((char *)ptr + amount))[-2] = MAGIC2;
+# else
+               ((unsigned long *)((char *)ptr + amount))[-1] = MAGIC2;
+# endif /* __hppa__ */
+#endif /* SIZE_TAIL */
+               ptr = (unsigned long *)((char *)ptr + SIZE_HEADER);
+               LOG_ALLOC("Xalloc-L", amount, ptr);
+               return ptr;
+       } /* else fall through to 'Out of memory' */
+#endif /* HAS_MMAP_ANON || MMAP_DEV_ZERO */
+    } else {
+       /*
+        * medium sized block
+        */
+       /* 'normal' malloc() */
+       ptr=(unsigned long *)calloc(1,amount+SIZE_HEADER+TAIL_SIZE);
+       if (ptr != (unsigned long *)NULL) {
+               ptr[0] = amount;
+#ifdef XALLOC_DEBUG
+               ptr[1] = MAGIC;
+#endif /* XALLOC_DEBUG */
+#ifdef SIZE_TAIL
+               *(unsigned long *)((char *)ptr + amount + SIZE_HEADER) = MAGIC2;
+#endif /* SIZE_TAIL */
+               ptr = (unsigned long *)((char *)ptr + SIZE_HEADER);
+               LOG_ALLOC("Xalloc-M", amount, ptr);
+               return ptr;
+       }
+    }
+    if (Must_have_memory)
+       FatalError("Out of memory");
+    LOG_ALLOC("Xalloc-oom", amount, 0);
+    return (unsigned long *)NULL;
+}
+
+/*****************
+ * XNFalloc 
+ * "no failure" realloc, alternate interface to Xalloc w/o Must_have_memory
+ *****************/
+
+unsigned long *
+XNFalloc (amount)
+    unsigned long amount;
+{
+    register unsigned long *ptr;
+
+    /* zero size requested */
+    if (amount == 0) {
+       LOG_ALLOC("XNFalloc=0", amount, 0);
+       return (unsigned long *)NULL;
+    }
+    /* negative size (or size > 2GB) - what do we do? */
+    if ((long)amount < 0) {
+       /* Diagnostic */
+#ifdef FATALERRORS
+       FatalError("Xalloc: XNFalloc(<0)\n");
+#else
+       ErrorF("Xalloc warning: XNFalloc(<0) ignored..\n");
+#endif
+       LOG_ALLOC("XNFalloc<0", amount, 0);
+       return (unsigned long *)NULL;
+    }
+    ptr = Xalloc(amount);
+    if (!ptr)
+    {
+        FatalError("Out of memory");
+    }
+    return ptr;
+}
+
+/*****************
+ * Xcalloc
+ *****************/
+
+unsigned long *
+Xcalloc (amount)
+    unsigned long   amount;
+{
+    unsigned long   *ret;
+
+    ret = Xalloc (amount);
+    if (ret
+#if defined(HAS_MMAP_ANON) || defined(MMAP_DEV_ZERO)
+           && (amount < MIN_LARGE)     /* mmaped anonymous mem is already cleared */
+#endif
+       )
+       bzero ((char *) ret, (int) amount);
+    return ret;
+}
+
+/*****************
+ * Xrealloc
+ *****************/
+
+unsigned long *
+Xrealloc (ptr, amount)
+    register pointer ptr;
+    unsigned long amount;
+{
+    register unsigned long *new_ptr;
+
+    /* zero size requested */
+    if (amount == 0) {
+       if (ptr)
+               Xfree(ptr);
+       LOG_REALLOC("Xrealloc=0", ptr, amount, 0);
+       return (unsigned long *)NULL;
+    }
+    /* negative size (or size > 2GB) - what do we do? */
+    if ((long)amount < 0) {
+       /* Diagnostic */
+#ifdef FATALERRORS
+       FatalError("Xalloc: Xrealloc(<0)\n");
+#else
+       ErrorF("Xalloc warning: Xrealloc(<0) ignored..\n");
+#endif
+       if (ptr)
+               Xfree(ptr);     /* ?? */
+       LOG_REALLOC("Xrealloc<0", ptr, amount, 0);
+       return (unsigned long *)NULL;
+    }
+
+    new_ptr = Xalloc(amount);
+    if ( (new_ptr) && (ptr) ) {
+       unsigned long old_size;
+       old_size = ((unsigned long *)ptr)[-2];
+#ifdef XALLOC_DEBUG
+       if (MAGIC != ((unsigned long *)ptr)[-1]) {
+#ifdef FATALERRORS
+               FatalError("Xalloc error: header corrupt in Xrealloc() :-(\n");
+#else
+               ErrorF("Xalloc error: header corrupt in Xrealloc() :-(\n");
+#endif
+               LOG_REALLOC("Xalloc error: header corrupt in Xrealloc() :-(",
+                       ptr, amount, 0);
+               return (unsigned long *)NULL;
+       }
+#endif /* XALLOC_DEBUG */
+       /* copy min(old size, new size) */
+       memcpy((char *)new_ptr, (char *)ptr, (amount < old_size ? amount : old_size));
+    }
+    if (ptr)
+       Xfree(ptr);
+    if (new_ptr) {
+       LOG_REALLOC("Xrealloc", ptr, amount, new_ptr);
+       return new_ptr;
+    }
+    if (Must_have_memory)
+       FatalError("Out of memory");
+    LOG_REALLOC("Xrealloc", ptr, amount, 0);
+    return (unsigned long *)NULL;
+}
+                    
+/*****************
+ * XNFrealloc 
+ * "no failure" realloc, alternate interface to Xrealloc w/o Must_have_memory
+ *****************/
+
+unsigned long *
+XNFrealloc (ptr, amount)
+    register pointer ptr;
+    unsigned long amount;
+{
+    if (( ptr = (pointer)Xrealloc( ptr, amount ) ) == NULL)
+    {
+        FatalError( "Out of memory" );
+    }
+    return ((unsigned long *)ptr);
+}
+
+/*****************
+ *  Xfree
+ *    calls free 
+ *****************/    
+
+void
+Xfree(ptr)
+    register pointer ptr;
+{
+    unsigned long size;
+    unsigned long *pheader;
+
+    /* free(NULL) IS valid :-(  - and widely used throughout the server.. */
+    if (!ptr)
+       return;
+
+    pheader = (unsigned long *)((char *)ptr - SIZE_HEADER);
+#ifdef XALLOC_DEBUG
+    if (MAGIC != pheader[1]) {
+       /* Diagnostic */
+#ifdef FATALERRORS
+       FatalError("Xalloc error: Header corrupt in Xfree() :-(\n");
+#else
+       ErrorF("Xalloc error: Header corrupt in Xfree() :-(\n");
+#endif
+       LOG_FREE("Xalloc error:  Header corrupt in Xfree() :-(", ptr);
+       return;
+    }
+#endif /* XALLOC_DEBUG */
+
+    size = pheader[0];
+    if (size <= MAX_SMALL) {
+       int indx;
+       /*
+        * small block
+        */
+#ifdef SIZE_TAIL
+       if (MAGIC2 != *(unsigned long *)((char *)ptr + size)) {
+               /* Diagnostic */
+#ifdef FATALERRORS
+               FatalError("Xalloc error: Tail corrupt in Xfree() for small block (adr=0x%x, val=0x%x)\n",(char *)ptr + size,*(unsigned long *)((char *)ptr + size));
+#else
+               ErrorF("Xalloc error: Tail corrupt in Xfree() for small block (adr=0x%x, val=0x%x)\n",(char *)ptr + size,*(unsigned long *)((char *)ptr + size));
+#endif
+               LOG_FREE("Xalloc error: Tail corrupt in Xfree() for small block", ptr);
+               return;
+       }
+#endif /* SIZE_TAIL */
+
+#ifdef XFREE_ERASES
+       memset(ptr,0xF0,size);
+#endif /* XFREE_ERASES */
+
+       /* put this small block at the head of the list */
+       indx = (size-1) / SIZE_STEPS;
+       *(unsigned long **)(ptr) = free_lists[indx];
+       free_lists[indx] = (unsigned long *)ptr;
+       LOG_FREE("Xfree", ptr);
+       return;
+
+#if defined(HAS_MMAP_ANON) || defined(MMAP_DEV_ZERO)
+    } else if (size >= MIN_LARGE) {
+       /*
+        * large block
+        */
+#ifdef SIZE_TAIL
+       if (MAGIC2 != ((unsigned long *)((char *)ptr + size))[0]) {
+               /* Diagnostic */
+#ifdef FATALERRORS
+               FatalError("Xalloc error: Tail corrupt in Xfree() for big block (adr=0x%x, val=0x%x)\n",(char *)ptr+size,((unsigned long *)((char *)ptr + size))[0]);
+#else
+               ErrorF("Xalloc error: Tail corrupt in Xfree() for big block (adr=0x%x, val=0x%x)\n",(char *)ptr+size,((unsigned long *)((char *)ptr + size))[0]);
+#endif
+               LOG_FREE("Xalloc error: Tail corrupt in Xfree() for big block", ptr);
+               return;
+       }
+       size += SIZE_TAIL;
+#endif /* SIZE_TAIL */
+
+       LOG_FREE("Xfree", ptr);
+       size += SIZE_HEADER;
+       munmap((caddr_t)pheader, (size_t)size);
+       /* no need to clear - mem is inaccessible after munmap.. */
+#endif /* HAS_MMAP_ANON */
+
+    } else {
+       /*
+        * medium sized block
+        */
+#ifdef SIZE_TAIL
+       if (MAGIC2 != *(unsigned long *)((char *)ptr + size)) {
+               /* Diagnostic */
+#ifdef FATALERRORS
+               FatalError("Xalloc error: Tail corrupt in Xfree() for medium block (adr=0x%x, val=0x%x)\n",(char *)ptr + size,*(unsigned long *)((char *)ptr + size));
+#else
+               ErrorF("Xalloc error: Tail corrupt in Xfree() for medium block (adr=0x%x, val=0x%x)\n",(char *)ptr + size,*(unsigned long *)((char *)ptr + size));
+#endif
+               LOG_FREE("Xalloc error: Tail corrupt in Xfree() for medium block", ptr);
+               return;
+       }
+#endif /* SIZE_TAIL */
+
+#ifdef XFREE_ERASES
+       memset(pheader,0xF0,size+SIZE_HEADER);
+#endif /* XFREE_ERASES */
+
+       LOG_FREE("Xfree", ptr);
+       free((char *)pheader);
+    }
+}
+
+void
+OsInitAllocator ()
+{
+    static Bool beenhere = FALSE;
+
+    if (beenhere)
+       return;
+    beenhere = TRUE;
+
+#if defined(HAS_MMAP_ANON) || defined (MMAP_DEV_ZERO)
+#if defined(_SC_PAGESIZE) /* || defined(linux) */
+    pagesize = sysconf(_SC_PAGESIZE);
+#else
+#ifdef HAS_GETPAGESIZE
+    pagesize = getpagesize();
+#else
+    pagesize = PAGE_SIZE;
+#endif
+#endif
+#endif
+
+    /* set up linked lists of free blocks */
+    bzero ((char *) free_lists, MAX_SMALL/SIZE_STEPS*sizeof(unsigned long *));
+
+#ifdef MMAP_DEV_ZERO
+    /* open /dev/zero on systems that have mmap, but not MAP_ANON */
+    if (devzerofd < 0) {
+       if ((devzerofd = open("/dev/zero", O_RDWR, 0)) < 0)
+           FatalError("OsInitAllocator: Cannot open /dev/zero (errno=%d)\n",
+                       errno);
+    }
+#endif
+
+#ifdef XALLOC_LOG
+    /* reset the log file to zero length */
+    {
+       FILE *f;
+       f = fopen(XALLOC_LOG_FILE, "w");
+       if (NULL!=f)
+               fclose(f);
+    }
+#endif
+}
+
+#else /* !INTERNAL_MALLOC */
+/* This is to avoid an empty .o */
+static int no_internal_xalloc;
+#endif /* INTERNAL_MALLOC */
diff --git a/Xserver/programs/Xserver/os/xdmauth.c b/Xserver/programs/Xserver/os/xdmauth.c
new file mode 100644 (file)
index 0000000..22a28d8
--- /dev/null
@@ -0,0 +1,519 @@
+/* $XConsortium: xdmauth.c,v 1.14 95/07/10 21:18:07 gildea Exp $ */
+/*
+
+Copyright (c) 1988  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be included
+in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR
+OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall
+not be used in advertising or otherwise to promote the sale, use or
+other dealings in this Software without prior written authorization
+from the X Consortium.
+
+*/
+
+/*
+ * XDM-AUTHENTICATION-1 (XDMCP authentication) and
+ * XDM-AUTHORIZATION-1 (client authorization) protocols
+ *
+ * Author:  Keith Packard, MIT X Consortium
+ */
+
+#include "X.h"
+#include "Xtrans.h"
+#include "os.h"
+#include "osdep.h"
+#include "dixstruct.h"
+
+#ifdef HASXDMAUTH
+
+static Bool authFromXDMCP;
+
+#ifdef XDMCP
+#include "Xmd.h"
+#undef REQUEST
+#include "Xdmcp.h"
+
+/* XDM-AUTHENTICATION-1 */
+
+static XdmAuthKeyRec   privateKey;
+static char XdmAuthenticationName[] = "XDM-AUTHENTICATION-1";
+#define XdmAuthenticationNameLen (sizeof XdmAuthenticationName - 1)
+static XdmAuthKeyRec   rho;
+
+static Bool XdmAuthenticationValidator (privateData, incomingData, packet_type)
+    ARRAY8Ptr  privateData, incomingData;
+    xdmOpCode  packet_type;
+{
+    XdmAuthKeyPtr      incoming;
+
+    XdmcpUnwrap (incomingData->data, &privateKey,
+                             incomingData->data,incomingData->length);
+    switch (packet_type)
+    {
+    case ACCEPT:
+       if (incomingData->length != 8)
+           return FALSE;
+       incoming = (XdmAuthKeyPtr) incomingData->data;
+       XdmcpDecrementKey (incoming);
+       return XdmcpCompareKeys (incoming, &rho);
+    }
+    return FALSE;
+}
+
+static Bool
+XdmAuthenticationGenerator (privateData, outgoingData, packet_type)
+    ARRAY8Ptr  privateData, outgoingData;
+    xdmOpCode  packet_type;
+{
+    outgoingData->length = 0;
+    outgoingData->data = 0;
+    switch (packet_type)
+    {
+    case REQUEST:
+       if (XdmcpAllocARRAY8 (outgoingData, 8))
+           XdmcpWrap (&rho, &privateKey, outgoingData->data, 8);
+    }
+    return TRUE;
+}
+
+static Bool
+XdmAuthenticationAddAuth (name_len, name, data_len, data)
+    int            name_len, data_len;
+    char    *name, *data;
+{
+    Bool    ret;
+    XdmcpUnwrap (data, &privateKey, data, data_len);
+    authFromXDMCP = TRUE;
+    ret = AddAuthorization (name_len, name, data_len, data);
+    authFromXDMCP = FALSE;
+    return ret;
+}
+
+
+#define atox(c)        ('0' <= c && c <= '9' ? c - '0' : \
+                'a' <= c && c <= 'f' ? c - 'a' + 10 : \
+                'A' <= c && c <= 'F' ? c - 'A' + 10 : -1)
+
+static int
+HexToBinary (in, out, len)
+    char    *out, *in;
+    int len;
+{
+    int            top, bottom;
+
+    while (len > 0)
+    {
+       top = atox(in[0]);
+       if (top == -1)
+           return 0;
+       bottom = atox(in[1]);
+       if (bottom == -1)
+           return 0;
+       *out++ = (top << 4) | bottom;
+       in += 2;
+       len -= 2;
+    }
+    if (len)
+       return 0;
+    *out++ = '\0';
+    return 1;
+}
+
+void
+XdmAuthenticationInit (cookie, cookie_len)
+    char    *cookie;
+    int            cookie_len;
+{
+    bzero (privateKey.data, 8);
+    if (!strncmp (cookie, "0x", 2) || !strncmp (cookie, "0X", 2))
+    {
+       if (cookie_len > 2 + 2 * 8)
+           cookie_len = 2 + 2 * 8;
+       HexToBinary (cookie + 2, (char *)privateKey.data, cookie_len - 2);
+    }
+    else
+    {
+       if (cookie_len > 7)
+           cookie_len = 7;
+       memmove (privateKey.data + 1, cookie, cookie_len);
+    }
+    XdmcpGenerateKey (&rho);
+    XdmcpRegisterAuthentication (XdmAuthenticationName, XdmAuthenticationNameLen,
+                                &rho,
+                                sizeof (rho),
+                                XdmAuthenticationValidator,
+                                XdmAuthenticationGenerator,
+                                XdmAuthenticationAddAuth);
+}
+
+#endif /* XDMCP */
+
+/* XDM-AUTHORIZATION-1 */
+typedef struct _XdmAuthorization {
+    struct _XdmAuthorization   *next;
+    XdmAuthKeyRec              rho;
+    XdmAuthKeyRec              key;
+    XID                                id;
+} XdmAuthorizationRec, *XdmAuthorizationPtr;
+
+static XdmAuthorizationPtr xdmAuth;
+
+typedef struct _XdmClientAuth {
+    struct _XdmClientAuth   *next;
+    XdmAuthKeyRec          rho;
+    char                   client[6];
+    long                   time;
+} XdmClientAuthRec, *XdmClientAuthPtr;
+
+static XdmClientAuthPtr    xdmClients;
+static long        clockOffset;
+static Bool        gotClock;
+
+#define TwentyMinutes  (20 * 60)
+#define TwentyFiveMinutes (25 * 60)
+
+static Bool
+XdmClientAuthCompare (a, b)
+    XdmClientAuthPtr   a, b;
+{
+    int        i;
+
+    if (!XdmcpCompareKeys (&a->rho, &b->rho))
+       return FALSE;
+    for (i = 0; i < 6; i++)
+       if (a->client[i] != b->client[i])
+           return FALSE;
+    return a->time == b->time;
+}
+
+static void
+XdmClientAuthDecode (plain, auth)
+    unsigned char      *plain;
+    XdmClientAuthPtr   auth;
+{
+    int            i, j;
+
+    j = 0;
+    for (i = 0; i < 8; i++)
+    {
+       auth->rho.data[i] = plain[j];
+       ++j;
+    }
+    for (i = 0; i < 6; i++)
+    {
+       auth->client[i] = plain[j];
+       ++j;
+    }
+    auth->time = 0;
+    for (i = 0; i < 4; i++)
+    {
+       auth->time |= plain[j] << ((3 - i) << 3);
+       j++;
+    }
+}
+
+static void
+XdmClientAuthTimeout (now)
+    long       now;
+{
+    XdmClientAuthPtr   client, next, prev;
+
+    prev = 0;
+    for (client = xdmClients; client; client=next)
+    {
+       next = client->next;
+       if (abs (now - client->time) > TwentyFiveMinutes)
+       {
+           if (prev)
+               prev->next = next;
+           else
+               xdmClients = next;
+           xfree (client);
+       }
+       else
+           prev = client;
+    }
+}
+
+static XdmClientAuthPtr
+XdmAuthorizationValidate (plain, length, rho, xclient, reason)
+    unsigned char      *plain;
+    int                        length;
+    XdmAuthKeyPtr      rho;
+    ClientPtr          xclient;
+    char               **reason;
+{
+    XdmClientAuthPtr   client, existing;
+    long               now;
+    int                        i;
+
+    if (length != (192 / 8)) {
+       if (reason)
+           *reason = "Bad XDM authorization key length";
+       return NULL;
+    }
+    client = (XdmClientAuthPtr) xalloc (sizeof (XdmClientAuthRec));
+    if (!client)
+       return NULL;
+    XdmClientAuthDecode (plain, client);
+    if (!XdmcpCompareKeys (&client->rho, rho))
+    {
+       xfree (client);
+       if (reason)
+           *reason = "Invalid XDM-AUTHORIZATION-1 key value";
+       return NULL;
+    }
+    for (i = 18; i < 24; i++)
+       if (plain[i] != 0) {
+           xfree (client);
+           if (reason)
+               *reason = "Invalid XDM-AUTHORIZATION-1 key value";
+           return NULL;
+       }
+    if (xclient) {
+       int family, addr_len;
+       Xtransaddr *addr;
+
+       if (_XSERVTransGetPeerAddr(((OsCommPtr)xclient->osPrivate)->trans_conn,
+                                  &family, &addr_len, &addr) == 0
+           && _XSERVTransConvertAddress(&family, &addr_len, &addr) == 0) {
+#ifdef TCPCONN
+           if (family == FamilyInternet &&
+               memcmp((char *)addr, client->client, 4) != 0) {
+               xfree (client);
+               xfree (addr);
+               if (reason)
+                   *reason = "Invalid XDM-AUTHORIZATION-1 key value";
+               return NULL;
+
+           }
+#endif
+           xfree (addr);
+       }
+    }
+    now = time(0);
+    if (!gotClock)
+    {
+       clockOffset = client->time - now;
+       gotClock = TRUE;
+    }
+    now += clockOffset;
+    XdmClientAuthTimeout (now);
+    if (abs (client->time - now) > TwentyMinutes)
+    {
+       xfree (client);
+       if (reason)
+           *reason = "Excessive XDM-AUTHORIZATION-1 time offset";
+       return NULL;
+    }
+    for (existing = xdmClients; existing; existing=existing->next)
+    {
+       if (XdmClientAuthCompare (existing, client))
+       {
+           xfree (client);
+           if (reason)
+               *reason = "XDM authorization key matches an existing client!";
+           return NULL;
+       }
+    }
+    return client;
+}
+
+int
+XdmAddCookie (data_length, data, id)
+unsigned short data_length;
+char   *data;
+XID    id;
+{
+    XdmAuthorizationPtr        new;
+    unsigned char      *rho_bits, *key_bits;
+
+    switch (data_length)
+    {
+    case 16:               /* auth from files is 16 bytes long */
+       if (authFromXDMCP)
+       {
+           /* R5 xdm sent bogus authorization data in the accept packet,
+            * but we can recover */
+           rho_bits = rho.data;
+           key_bits = (unsigned char *) data;
+           key_bits[0] = '\0';
+       }
+       else
+       {
+           rho_bits = (unsigned char *) data;
+           key_bits = (unsigned char *) (data + 8);
+       }
+       break;
+    case 8:                /* auth from XDMCP is 8 bytes long */
+       rho_bits = rho.data;
+       key_bits = (unsigned char *) data;
+       break;
+    default:
+       return 0;
+    }
+    /* the first octet of the key must be zero */
+    if (key_bits[0] != '\0')
+       return 0;
+    new = (XdmAuthorizationPtr) xalloc (sizeof (XdmAuthorizationRec));
+    if (!new)
+       return 0;
+    new->next = xdmAuth;
+    xdmAuth = new;
+    memmove (new->key.data, key_bits, (int) 8);
+    memmove (new->rho.data, rho_bits, (int) 8);
+    new->id = id;
+    return 1;
+}
+
+XID
+XdmCheckCookie (cookie_length, cookie, xclient, reason)
+    unsigned short     cookie_length;
+    char       *cookie;
+    ClientPtr xclient;
+    char       **reason;
+{
+    XdmAuthorizationPtr        auth;
+    XdmClientAuthPtr   client;
+    unsigned char      *plain;
+
+    /* Auth packets must be a multiple of 8 bytes long */
+    if (cookie_length & 7)
+       return (XID) -1;
+    plain = (unsigned char *) xalloc (cookie_length);
+    if (!plain)
+       return (XID) -1;
+    for (auth = xdmAuth; auth; auth=auth->next) {
+       XdmcpUnwrap (cookie, &auth->key, plain, cookie_length);
+       if (client = XdmAuthorizationValidate (plain, cookie_length, &auth->rho, xclient, reason))
+       {
+           client->next = xdmClients;
+           xdmClients = client;
+           xfree (plain);
+           return auth->id;
+       }
+    }
+    xfree (plain);
+    return (XID) -1;
+}
+
+int
+XdmResetCookie ()
+{
+    XdmAuthorizationPtr        auth, next_auth;
+    XdmClientAuthPtr   client, next_client;
+
+    for (auth = xdmAuth; auth; auth=next_auth)
+    {
+       next_auth = auth->next;
+       xfree (auth);
+    }
+    xdmAuth = 0;
+    for (client = xdmClients; client; client=next_client)
+    {
+       next_client = client->next;
+       xfree (client);
+    }
+    xdmClients = (XdmClientAuthPtr) 0;
+    return 1;
+}
+
+XID
+XdmToID (cookie_length, cookie)
+unsigned short cookie_length;
+char   *cookie;
+{
+    XdmAuthorizationPtr        auth;
+    XdmClientAuthPtr   client;
+    unsigned char      *plain;
+
+    plain = (unsigned char *) xalloc (cookie_length);
+    if (!plain)
+       return (XID) -1;
+    for (auth = xdmAuth; auth; auth=auth->next) {
+       XdmcpUnwrap (cookie, &auth->key, plain, cookie_length);
+       if (client = XdmAuthorizationValidate (plain, cookie_length, &auth->rho, NULL, NULL))
+       {
+           xfree (client);
+           xfree (cookie);
+           return auth->id;
+       }
+    }
+    xfree (cookie);
+    return (XID) -1;
+}
+
+int
+XdmFromID (id, data_lenp, datap)
+XID id;
+unsigned short *data_lenp;
+char   **datap;
+{
+    XdmAuthorizationPtr        auth;
+
+    for (auth = xdmAuth; auth; auth=auth->next) {
+       if (id == auth->id) {
+           *data_lenp = 16;
+           *datap = (char *) &auth->rho;
+           return 1;
+       }
+    }
+    return 0;
+}
+
+int
+XdmRemoveCookie (data_length, data)
+unsigned short data_length;
+char   *data;
+{
+    XdmAuthorizationPtr        auth, prev;
+    XdmAuthKeyPtr      key_bits, rho_bits;
+
+    prev = 0;
+    switch (data_length)
+    {
+    case 16:
+       rho_bits = (XdmAuthKeyPtr) data;
+       key_bits = (XdmAuthKeyPtr) (data + 8);
+       break;
+    case 8:
+       rho_bits = &rho;
+       key_bits = (XdmAuthKeyPtr) data;
+       break;
+    default:
+       return 0;
+    }
+    for (auth = xdmAuth; auth; auth=auth->next) {
+       if (XdmcpCompareKeys (rho_bits, &auth->rho) &&
+           XdmcpCompareKeys (key_bits, &auth->key))
+       {
+           if (prev)
+               prev->next = auth->next;
+           else
+               xdmAuth = auth->next;
+           xfree (auth);
+           return 1;
+       }
+    }
+    return 0;
+}
+
+#endif
diff --git a/Xserver/programs/Xserver/os/xdmcp.c b/Xserver/programs/Xserver/os/xdmcp.c
new file mode 100644 (file)
index 0000000..5de14cd
--- /dev/null
@@ -0,0 +1,1464 @@
+/* $XConsortium: xdmcp.c /main/34 1996/12/02 10:23:29 lehors $ */
+/* $XFree86: xc/programs/Xserver/os/xdmcp.c,v 3.9 1997/01/18 06:58:04 dawes Exp $ */
+/*
+ * Copyright 1989 Network Computing Devices, Inc., Mountain View, California.
+ *
+ * Permission to use, copy, modify, and distribute this software and its
+ * documentation for any purpose and without fee is hereby granted, provided
+ * that the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the name of N.C.D. not be used in advertising or
+ * publicity pertaining to distribution of the software without specific,
+ * written prior permission.  N.C.D. makes no representations about the
+ * suitability of this software for any purpose.  It is provided "as is"
+ * without express or implied warranty.
+ *
+ */
+
+#ifdef WIN32
+/* avoid conflicting definitions */
+#define BOOL wBOOL
+#define ATOM wATOM
+#define FreeResource wFreeResource
+#include <winsock.h>
+#undef BOOL
+#undef ATOM
+#undef FreeResource
+#undef CreateWindowA
+#undef RT_FONT
+#undef RT_CURSOR
+#endif
+#include "Xos.h"
+#if !defined(MINIX) && !defined(WIN32)
+#ifndef Lynx
+#include <sys/param.h>
+#include <sys/socket.h>
+#else
+#include <socket.h>
+#endif
+#include <netinet/in.h>
+#include <netdb.h>
+#else
+#if defined(MINIX)
+#include <net/hton.h>
+#include <net/netlib.h>
+#include <net/gen/netdb.h>
+#include <net/gen/udp.h>
+#include <net/gen/udp_io.h>
+#include <sys/nbio.h>
+#include <sys/ioctl.h>
+#endif
+#endif
+#include <stdio.h>
+#include "X.h"
+#include "Xmd.h"
+#include "misc.h"
+#include "Xpoll.h"
+#include "osdep.h"
+#include "input.h"
+#include "dixstruct.h"
+#include "opaque.h"
+
+#ifdef STREAMSCONN
+#include <tiuser.h>
+#include <netconfig.h>
+#include <netdir.h>
+#endif
+
+#ifdef XDMCP
+#undef REQUEST
+#include "Xdmcp.h"
+
+extern char *display;
+extern fd_set EnabledDevices;
+extern fd_set AllClients;
+extern char *defaultDisplayClass;
+
+static int                 xdmcpSocket, sessionSocket;
+static xdmcp_states        state;
+static struct sockaddr_in   req_sockaddr;
+static int                 req_socklen;
+static CARD32              SessionID;
+static CARD32              timeOutTime;
+static int                 timeOutRtx;
+static CARD32              defaultKeepaliveDormancy = XDM_DEF_DORMANCY;
+static CARD32              keepaliveDormancy = XDM_DEF_DORMANCY;
+static CARD16              DisplayNumber;
+static xdmcp_states        XDM_INIT_STATE = XDM_OFF;
+#ifdef HASXDMAUTH
+static char                *xdmAuthCookie;
+#endif
+
+static XdmcpBuffer         buffer;
+
+static struct sockaddr_in   ManagerAddress;
+
+static void get_xdmcp_sock(
+#if NeedFunctionPrototypes
+    void
+#endif
+);
+
+static void send_query_msg(
+#if NeedFunctionPrototypes
+    void
+#endif
+);
+
+static void recv_willing_msg(
+#if NeedFunctionPrototypes
+    struct sockaddr_in */*from*/,
+    int /*fromlen*/,
+    unsigned /*length*/
+#endif
+);
+
+static void send_request_msg(
+#if NeedFunctionPrototypes
+    void
+#endif
+);
+
+static void recv_accept_msg(
+#if NeedFunctionPrototypes
+    unsigned /*length*/
+#endif
+);
+
+static void recv_decline_msg(
+#if NeedFunctionPrototypes
+    unsigned /*length*/
+#endif
+);
+
+static void send_manage_msg(
+#if NeedFunctionPrototypes
+    void
+#endif
+);
+
+static void recv_refuse_msg(
+#if NeedFunctionPrototypes
+    unsigned /*length*/
+#endif
+);
+
+static void recv_failed_msg(
+#if NeedFunctionPrototypes
+    unsigned /*length*/
+#endif
+);
+
+static void send_keepalive_msg(
+#if NeedFunctionPrototypes
+    void
+#endif
+);
+
+static void recv_alive_msg(
+#if NeedFunctionPrototypes
+    unsigned /*length*/
+#endif
+);
+
+static XdmcpFatal(
+#if NeedFunctionPrototypes
+    char */*type*/,
+    ARRAY8Ptr /*status*/
+#endif
+);
+
+static XdmcpWarning(
+#if NeedFunctionPrototypes
+    char */*str*/
+#endif
+);
+
+static get_manager_by_name(
+#if NeedFunctionPrototypes
+    int /*argc*/,
+    char **/*argv*/,
+    int /*i*/
+#endif
+);
+
+static void receive_packet(
+#if NeedFunctionPrototypes
+    void
+#endif
+);
+
+static send_packet(
+#if NeedFunctionPrototypes
+    void
+#endif
+);
+
+extern int XdmcpDeadSession(
+#if NeedFunctionPrototypes
+    char */*reason*/
+#endif
+);
+
+static void timeout(
+#if NeedFunctionPrototypes
+    void
+#endif
+);
+
+static restart(
+#if NeedFunctionPrototypes
+    void
+#endif
+);
+
+static void XdmcpBlockHandler(
+#if NeedFunctionPrototypes
+    pointer /*data*/,
+    struct timeval **/*wt*/,
+    pointer /*LastSelectMask*/
+#endif
+);
+
+static void XdmcpWakeupHandler(
+#if NeedFunctionPrototypes
+    pointer /*data*/,
+    int /*i*/,
+    pointer /*LastSelectMask*/
+#endif
+);
+
+void XdmcpRegisterManufacturerDisplayID(
+#if NeedFunctionPrototypes
+    char    * /*name*/,
+    int            /*length*/
+#endif
+);
+
+#ifdef MINIX
+static void read_cb(
+#if NeedFunctionPrototypes
+    nbio_ref_t /*ref*/,
+    int                /*res*/,
+    int                /*err*/
+#endif
+);
+#endif
+
+static short   xdm_udp_port = XDM_UDP_PORT;
+static Bool    OneSession = FALSE;
+
+XdmcpUseMsg ()
+{
+    ErrorF("-query host-name       contact named host for XDMCP\n");
+    ErrorF("-broadcast             broadcast for XDMCP\n");
+    ErrorF("-indirect host-name    contact named host for indirect XDMCP\n");
+    ErrorF("-port port-num         UDP port number to send messages to\n");
+    ErrorF("-once                  Terminate server after one session\n");
+    ErrorF("-class display-class   specify display class to send in manage\n");
+#ifdef HASXDMAUTH
+    ErrorF("-cookie xdm-auth-bits  specify the magic cookie for XDMCP\n");
+#endif
+    ErrorF("-displayID display-id  manufacturer display ID for request\n");
+}
+
+int 
+XdmcpOptions(argc, argv, i)
+    int            argc, i;
+    char    **argv;
+{
+    if (strcmp(argv[i], "-query") == 0) {
+       get_manager_by_name(argc, argv, ++i);
+       XDM_INIT_STATE = XDM_QUERY;
+       AccessUsingXdmcp ();
+       return (i + 1);
+    }
+    if (strcmp(argv[i], "-broadcast") == 0) {
+       XDM_INIT_STATE = XDM_BROADCAST;
+       AccessUsingXdmcp ();
+       return (i + 1);
+    }
+    if (strcmp(argv[i], "-indirect") == 0) {
+       get_manager_by_name(argc, argv, ++i);
+       XDM_INIT_STATE = XDM_INDIRECT;
+       AccessUsingXdmcp ();
+       return (i + 1);
+    }
+    if (strcmp(argv[i], "-port") == 0) {
+       ++i;
+       xdm_udp_port = atoi(argv[i]);
+       return (i + 1);
+    }
+    if (strcmp(argv[i], "-once") == 0) {
+       OneSession = TRUE;
+       return (i + 1);
+    }
+    if (strcmp(argv[i], "-class") == 0) {
+       ++i;
+       defaultDisplayClass = argv[i];
+       return (i + 1);
+    }
+#ifdef HASXDMAUTH
+    if (strcmp(argv[i], "-cookie") == 0) {
+       ++i;
+       xdmAuthCookie = argv[i];
+       return (i + 1);
+    }
+#endif
+    if (strcmp(argv[i], "-displayID") == 0) {
+       ++i;
+       XdmcpRegisterManufacturerDisplayID (argv[i], strlen (argv[i]));
+       return (i + 1);
+    }
+    return (i);
+}
+
+/*
+ * This section is a collection of routines for
+ * registering server-specific data with the XDMCP
+ * state machine.
+ */
+
+
+/*
+ * Save all broadcast addresses away so BroadcastQuery
+ * packets get sent everywhere
+ */
+
+#define MAX_BROADCAST  10
+
+static struct sockaddr_in   BroadcastAddresses[MAX_BROADCAST];
+static int                 NumBroadcastAddresses;
+
+void
+XdmcpRegisterBroadcastAddress (addr)
+    struct sockaddr_in *addr;
+{
+    struct sockaddr_in *bcast;
+    if (NumBroadcastAddresses >= MAX_BROADCAST)
+       return;
+    bcast = &BroadcastAddresses[NumBroadcastAddresses++];
+    bzero (bcast, sizeof (struct sockaddr_in));
+#ifdef BSD44SOCKETS
+    bcast->sin_len = addr->sin_len;
+#endif
+    bcast->sin_family = addr->sin_family;
+    bcast->sin_port = htons (xdm_udp_port);
+    bcast->sin_addr = addr->sin_addr;
+}
+
+/*
+ * Each authentication type is registered here; Validator
+ * will be called to check all access attempts using
+ * the specified authentication type
+ */
+
+static ARRAYofARRAY8   AuthenticationNames, AuthenticationDatas;
+typedef struct _AuthenticationFuncs {
+    Bool    (*Validator)();
+    Bool    (*Generator)();
+    Bool    (*AddAuth)();
+} AuthenticationFuncsRec, *AuthenticationFuncsPtr;
+
+static AuthenticationFuncsPtr  AuthenticationFuncsList;
+
+void
+XdmcpRegisterAuthentication (name, namelen, data, datalen, Validator, Generator, AddAuth)
+    char    *name;
+    int            namelen;
+    char    *data;
+    int            datalen;
+    Bool    (*Validator)();
+    Bool    (*Generator)();
+    Bool    (*AddAuth)();
+{
+    int            i;
+    ARRAY8  AuthenticationName, AuthenticationData;
+    static AuthenticationFuncsPtr      newFuncs;
+
+    if (!XdmcpAllocARRAY8 (&AuthenticationName, namelen))
+       return;
+    if (!XdmcpAllocARRAY8 (&AuthenticationData, datalen))
+    {
+       XdmcpDisposeARRAY8 (&AuthenticationName);
+       return;
+    }
+    for (i = 0; i < namelen; i++)
+       AuthenticationName.data[i] = name[i];
+    for (i = 0; i < datalen; i++)
+       AuthenticationData.data[i] = data[i];
+    if (!(XdmcpReallocARRAYofARRAY8 (&AuthenticationNames,
+                                    AuthenticationNames.length + 1) &&
+         XdmcpReallocARRAYofARRAY8 (&AuthenticationDatas,
+                                    AuthenticationDatas.length + 1) &&
+         (newFuncs = (AuthenticationFuncsPtr) xalloc (
+                       (AuthenticationNames.length + 1) * sizeof (AuthenticationFuncsRec)))))
+    {
+       XdmcpDisposeARRAY8 (&AuthenticationName);
+       XdmcpDisposeARRAY8 (&AuthenticationData);
+       return;
+    }
+    for (i = 0; i < AuthenticationNames.length - 1; i++)
+       newFuncs[i] = AuthenticationFuncsList[i];
+    newFuncs[AuthenticationNames.length-1].Validator = Validator;
+    newFuncs[AuthenticationNames.length-1].Generator = Generator;
+    newFuncs[AuthenticationNames.length-1].AddAuth = AddAuth;
+    xfree (AuthenticationFuncsList);
+    AuthenticationFuncsList = newFuncs;
+    AuthenticationNames.data[AuthenticationNames.length-1] = AuthenticationName;
+    AuthenticationDatas.data[AuthenticationDatas.length-1] = AuthenticationData;
+}
+
+/*
+ * Select the authentication type to be used; this is
+ * set by the manager of the host to be connected to.
+ */
+
+ARRAY8         noAuthenticationName = {(CARD16) 0, (CARD8Ptr) 0};
+ARRAY8         noAuthenticationData = {(CARD16) 0, (CARD8Ptr) 0};
+ARRAY8Ptr      AuthenticationName = &noAuthenticationName;
+ARRAY8Ptr      AuthenticationData = &noAuthenticationData;
+AuthenticationFuncsPtr AuthenticationFuncs;
+
+void
+XdmcpSetAuthentication (name)
+    ARRAY8Ptr  name;
+{
+    int        i;
+
+    for (i = 0; i < AuthenticationNames.length; i++)
+       if (XdmcpARRAY8Equal (&AuthenticationNames.data[i], name))
+       {
+           AuthenticationName = &AuthenticationNames.data[i];
+           AuthenticationData = &AuthenticationDatas.data[i];
+           AuthenticationFuncs = &AuthenticationFuncsList[i];
+           break;
+       }
+}
+
+/*
+ * Register the host address for the display
+ */
+
+static ARRAY16         ConnectionTypes;
+static ARRAYofARRAY8   ConnectionAddresses;
+static long            xdmcpGeneration;
+
+void
+XdmcpRegisterConnection (type, address, addrlen)
+    int            type;
+    char    *address;
+    int            addrlen;
+{
+    int            i;
+    CARD8   *newAddress;
+
+    if (xdmcpGeneration != serverGeneration)
+    {
+       XdmcpDisposeARRAY16 (&ConnectionTypes);
+       XdmcpDisposeARRAYofARRAY8 (&ConnectionAddresses);
+       xdmcpGeneration = serverGeneration;
+    }
+    newAddress = (CARD8 *) xalloc (addrlen * sizeof (CARD8));
+    if (!newAddress)
+       return;
+    if (!XdmcpReallocARRAY16 (&ConnectionTypes, ConnectionTypes.length + 1))
+    {
+       xfree (newAddress);
+       return;
+    }
+    if (!XdmcpReallocARRAYofARRAY8 (&ConnectionAddresses,
+                                   ConnectionAddresses.length +  1))
+    {
+       xfree (newAddress);
+       return;
+    }
+    ConnectionTypes.data[ConnectionTypes.length - 1] = (CARD16) type;
+    for (i = 0; i < addrlen; i++)
+       newAddress[i] = address[i];
+    ConnectionAddresses.data[ConnectionAddresses.length-1].data = newAddress;
+    ConnectionAddresses.data[ConnectionAddresses.length-1].length = addrlen;
+}
+
+/*
+ * Register an Authorization Name.  XDMCP advertises this list
+ * to the manager.
+ */
+
+static ARRAYofARRAY8   AuthorizationNames;
+
+void
+XdmcpRegisterAuthorizations ()
+{
+    XdmcpDisposeARRAYofARRAY8 (&AuthorizationNames);
+    RegisterAuthorizations ();
+}
+
+void
+XdmcpRegisterAuthorization (name, namelen)
+    char    *name;
+    int            namelen;
+{
+    ARRAY8  authName;
+    int            i;
+
+    authName.data = (CARD8 *) xalloc (namelen * sizeof (CARD8));
+    if (!authName.data)
+       return;
+    if (!XdmcpReallocARRAYofARRAY8 (&AuthorizationNames, AuthorizationNames.length +1))
+    {
+       xfree (authName.data);
+       return;
+    }
+    for (i = 0; i < namelen; i++)
+       authName.data[i] = (CARD8) name[i];
+    authName.length = namelen;
+    AuthorizationNames.data[AuthorizationNames.length-1] = authName;
+}
+
+/*
+ * Register the DisplayClass string
+ */
+
+ARRAY8 DisplayClass;
+
+void
+XdmcpRegisterDisplayClass (name, length)
+    char    *name;
+    int            length;
+{
+    int            i;
+
+    XdmcpDisposeARRAY8 (&DisplayClass);
+    if (!XdmcpAllocARRAY8 (&DisplayClass, length))
+       return;
+    for (i = 0; i < length; i++)
+       DisplayClass.data[i] = (CARD8) name[i];
+}
+
+/*
+ * Register the Manufacturer display ID
+ */
+
+ARRAY8 ManufacturerDisplayID;
+
+void
+XdmcpRegisterManufacturerDisplayID (name, length)
+    char    *name;
+    int            length;
+{
+    int            i;
+
+    XdmcpDisposeARRAY8 (&ManufacturerDisplayID);
+    if (!XdmcpAllocARRAY8 (&ManufacturerDisplayID, length))
+       return;
+    for (i = 0; i < length; i++)
+       ManufacturerDisplayID.data[i] = (CARD8) name[i];
+}
+
+/* 
+ * initialize XDMCP; create the socket, compute the display
+ * number, set up the state machine
+ */
+
+void 
+XdmcpInit()
+{
+    state = XDM_INIT_STATE;
+#ifdef HASXDMAUTH
+    if (xdmAuthCookie)
+       XdmAuthenticationInit (xdmAuthCookie, strlen (xdmAuthCookie));
+#endif
+    if (state != XDM_OFF)
+    {
+       XdmcpRegisterAuthorizations();
+       XdmcpRegisterDisplayClass (defaultDisplayClass, strlen (defaultDisplayClass));
+       AccessUsingXdmcp();
+       RegisterBlockAndWakeupHandlers (XdmcpBlockHandler, XdmcpWakeupHandler,
+                                       (pointer) 0);
+       timeOutRtx = 0;
+       DisplayNumber = (CARD16) atoi(display);
+       get_xdmcp_sock();
+       send_packet();
+    }
+}
+
+void
+XdmcpReset ()
+{
+    state = XDM_INIT_STATE;
+    if (state != XDM_OFF)
+    {
+       RegisterBlockAndWakeupHandlers (XdmcpBlockHandler, XdmcpWakeupHandler,
+                                       (pointer) 0);
+       timeOutRtx = 0;
+       send_packet();
+    }
+}
+
+/*
+ * Called whenever a new connection is created; notices the
+ * first connection and saves it to terminate the session
+ * when it is closed
+ */
+
+void
+XdmcpOpenDisplay(sock)
+    int        sock;
+{
+    if (state != XDM_AWAIT_MANAGE_RESPONSE)
+       return;
+    state = XDM_RUN_SESSION;
+    sessionSocket = sock;
+}
+
+void 
+XdmcpCloseDisplay(sock)
+    int        sock;
+{
+    if ((state != XDM_RUN_SESSION && state != XDM_AWAIT_ALIVE_RESPONSE)
+       || sessionSocket != sock)
+           return;
+    state = XDM_INIT_STATE;
+    if (OneSession)
+       dispatchException |= DE_TERMINATE;
+    else
+       dispatchException |= DE_RESET;
+    isItTimeToYield = TRUE;
+}
+
+/*
+ * called before going to sleep, this routine
+ * may modify the timeout value about to be sent
+ * to select; in this way XDMCP can do appropriate things
+ * dynamically while starting up
+ */
+
+/*ARGSUSED*/
+static void
+XdmcpBlockHandler(data, wt, pReadmask)
+    pointer        data;   /* unused */
+    struct timeval  **wt;
+    pointer        pReadmask;
+{
+    fd_set *LastSelectMask = (fd_set*)pReadmask;
+    CARD32 millisToGo, wtMillis;
+    static struct timeval waittime;
+
+    if (state == XDM_OFF)
+       return;
+    FD_SET(xdmcpSocket, LastSelectMask);
+    if (timeOutTime == 0)
+       return;
+    millisToGo = GetTimeInMillis();
+    if (millisToGo < timeOutTime)
+       millisToGo = timeOutTime - millisToGo;
+    else
+       millisToGo = 0;
+    if (*wt == NULL)
+    {
+       waittime.tv_sec = (millisToGo) / 1000;
+       waittime.tv_usec = 1000 * (millisToGo % 1000);
+       *wt = &waittime;
+    }
+    else
+    {
+       wtMillis = (*wt)->tv_sec * 1000 + (*wt)->tv_usec / 1000;
+       if (millisToGo < wtMillis)
+       {
+           (*wt)->tv_sec = (millisToGo) / 1000;
+           (*wt)->tv_usec = 1000 * (millisToGo % 1000);
+       }
+    }
+}
+
+/*
+ * called after select returns; this routine will
+ * recognise when XDMCP packets await and
+ * process them appropriately
+ */
+
+/*ARGSUSED*/
+static void
+XdmcpWakeupHandler(data, i, pReadmask)
+    pointer data;   /* unused */
+    int            i;
+    pointer pReadmask;
+{
+    fd_set* LastSelectMask = (fd_set*)pReadmask;
+    fd_set   devicesReadable;
+
+    if (state == XDM_OFF)
+       return;
+    if (i > 0)
+    {
+       if (FD_ISSET(xdmcpSocket, LastSelectMask))
+       {
+           receive_packet();
+           FD_CLR(xdmcpSocket, LastSelectMask);
+       } 
+       XFD_ANDSET(&devicesReadable, LastSelectMask, &EnabledDevices);
+       if (XFD_ANYSET(&devicesReadable))
+       {
+           if (state == XDM_AWAIT_USER_INPUT)
+               restart();
+           else if (state == XDM_RUN_SESSION)
+               keepaliveDormancy = defaultKeepaliveDormancy;
+       }
+       if (XFD_ANYSET(&AllClients) && state == XDM_RUN_SESSION)
+           timeOutTime = GetTimeInMillis() +  keepaliveDormancy * 1000;
+    }
+    else if (timeOutTime && GetTimeInMillis() >= timeOutTime)
+    {
+       if (state == XDM_RUN_SESSION)
+       {
+           state = XDM_KEEPALIVE;
+           send_packet();
+       }
+       else
+           timeout();
+    }
+}
+
+/*
+ * This routine should be called from the routine that drives the
+ * user's host menu when the user selects a host
+ */
+
+XdmcpSelectHost(host_sockaddr, host_len, AuthenticationName)
+    struct sockaddr_in *host_sockaddr;
+    int                        host_len;
+    ARRAY8Ptr          AuthenticationName;
+{
+    state = XDM_START_CONNECTION;
+    memmove(&req_sockaddr, host_sockaddr, host_len);
+    req_socklen = host_len;
+    XdmcpSetAuthentication (AuthenticationName);
+    send_packet();
+}
+
+/*
+ * !!! this routine should be replaced by a routine that adds
+ * the host to the user's host menu. the current version just
+ * selects the first host to respond with willing message.
+ */
+
+/*ARGSUSED*/
+XdmcpAddHost(from, fromlen, AuthenticationName, hostname, status)
+    struct sockaddr_in  *from;
+    ARRAY8Ptr          AuthenticationName, hostname, status;
+{
+    XdmcpSelectHost(from, fromlen, AuthenticationName);
+}
+
+/*
+ * A message is queued on the socket; read it and
+ * do the appropriate thing
+ */
+
+ARRAY8 UnwillingMessage = { (CARD8) 14, (CARD8 *) "Host unwilling" };
+
+static void
+receive_packet()
+{
+    struct sockaddr_in from;
+    int fromlen = sizeof(struct sockaddr_in);
+    XdmcpHeader        header;
+
+    /* read message off socket */
+    if (!XdmcpFill (xdmcpSocket, &buffer, (struct sockaddr *) &from, &fromlen))
+       return;
+
+    /* reset retransmission backoff */
+    timeOutRtx = 0;
+
+    if (!XdmcpReadHeader (&buffer, &header))
+       return;
+
+    if (header.version != XDM_PROTOCOL_VERSION)
+       return;
+
+    switch (header.opcode) {
+    case WILLING:
+       recv_willing_msg(&from, fromlen, header.length);
+       break;
+    case UNWILLING:
+       XdmcpFatal("Manager unwilling", &UnwillingMessage);
+       break;
+    case ACCEPT:
+       recv_accept_msg(header.length);
+       break;
+    case DECLINE:
+       recv_decline_msg(header.length);
+       break;
+    case REFUSE:
+       recv_refuse_msg(header.length);
+       break;
+    case FAILED:
+       recv_failed_msg(header.length);
+       break;
+    case ALIVE:
+       recv_alive_msg(header.length);
+       break;
+    }
+}
+
+/*
+ * send the appropriate message given the current state
+ */
+
+static
+send_packet()
+{
+    int rtx;
+    switch (state) {
+    case XDM_QUERY:
+    case XDM_BROADCAST:
+    case XDM_INDIRECT:
+       send_query_msg();
+       break;
+    case XDM_START_CONNECTION:
+       send_request_msg();
+       break;
+    case XDM_MANAGE:
+       send_manage_msg();
+       break;
+    case XDM_KEEPALIVE:
+       send_keepalive_msg();
+       break;
+    }
+    rtx = (XDM_MIN_RTX << timeOutRtx);
+    if (rtx > XDM_MAX_RTX)
+       rtx = XDM_MAX_RTX;
+    timeOutTime = GetTimeInMillis() + rtx * 1000;
+}
+
+/*
+ * The session is declared dead for some reason; too many
+ * timeouts, or Keepalive failure.
+ */
+
+XdmcpDeadSession (reason)
+    char *reason;
+{
+    ErrorF ("XDM: %s, declaring session dead\n", reason);
+    state = XDM_INIT_STATE;
+    isItTimeToYield = TRUE;
+    dispatchException |= DE_RESET;
+    timeOutTime = 0;
+    timeOutRtx = 0;
+    send_packet();
+}
+
+/*
+ * Timeout waiting for an XDMCP response.
+ */
+
+static void
+timeout()
+{
+    timeOutRtx++;
+    if (state == XDM_AWAIT_ALIVE_RESPONSE && timeOutRtx >= XDM_KA_RTX_LIMIT )
+    {
+       XdmcpDeadSession ("too many keepalive retransmissions");
+       return;
+    }
+    else if (timeOutRtx >= XDM_RTX_LIMIT)
+    {
+       ErrorF("XDM: too many retransmissions\n");
+       state = XDM_AWAIT_USER_INPUT;
+       timeOutTime = 0;
+       timeOutRtx = 0;
+       return;
+    }
+
+    switch (state) {
+    case XDM_COLLECT_QUERY:
+       state = XDM_QUERY;
+       break;
+    case XDM_COLLECT_BROADCAST_QUERY:
+       state = XDM_BROADCAST;
+       break;
+    case XDM_COLLECT_INDIRECT_QUERY:
+       state = XDM_INDIRECT;
+       break;
+    case XDM_AWAIT_REQUEST_RESPONSE:
+       state = XDM_START_CONNECTION;
+       break;
+    case XDM_AWAIT_MANAGE_RESPONSE:
+       state = XDM_MANAGE;
+       break;
+    case XDM_AWAIT_ALIVE_RESPONSE:
+       state = XDM_KEEPALIVE;
+       break;
+    }
+    send_packet();
+}
+
+static
+restart()
+{
+    state = XDM_INIT_STATE;
+    timeOutRtx = 0;
+    send_packet();
+}
+
+XdmcpCheckAuthentication (Name, Data, packet_type)
+    ARRAY8Ptr  Name, Data;
+    int        packet_type;
+{
+    return (XdmcpARRAY8Equal (Name, AuthenticationName) &&
+           (AuthenticationName->length == 0 ||
+            (*AuthenticationFuncs->Validator) (AuthenticationData, Data, packet_type)));
+}
+
+XdmcpAddAuthorization (name, data)
+    ARRAY8Ptr  name, data;
+{
+    Bool    (*AddAuth)(), AddAuthorization();
+
+    if (AuthenticationFuncs && AuthenticationFuncs->AddAuth)
+       AddAuth = AuthenticationFuncs->AddAuth;
+    else
+       AddAuth = AddAuthorization;
+    return (*AddAuth) ((unsigned short)name->length,
+                      (char *)name->data,
+                      (unsigned short)data->length,
+                      (char *)data->data);
+}
+
+/*
+ * from here to the end of this file are routines private
+ * to the state machine.
+ */
+
+static void
+get_xdmcp_sock()
+{
+#ifdef STREAMSCONN
+    struct netconfig *nconf;
+
+    if ((xdmcpSocket = t_open("/dev/udp", O_RDWR, 0)) < 0) {
+       XdmcpWarning("t_open() of /dev/udp failed");
+       return;
+    }
+
+    if( t_bind(xdmcpSocket,NULL,NULL) < 0 ) {
+       XdmcpWarning("UDP socket creation failed");
+       t_error("t_bind(xdmcpSocket) failed" );
+       t_close(xdmcpSocket);
+       return;
+    }
+
+    /*
+     * This part of the code looks contrived. It will actually fit in nicely
+     * when the CLTS part of Xtrans is implemented.
+     */
+    if( (nconf=getnetconfigent("udp")) == NULL ) {
+       XdmcpWarning("UDP socket creation failed: getnetconfigent()");
+       t_unbind(xdmcpSocket);
+       t_close(xdmcpSocket);
+       return;
+    }
+    if( netdir_options(nconf, ND_SET_BROADCAST, xdmcpSocket, NULL) ) {
+       XdmcpWarning("UDP set broadcast option failed: netdir_options()");
+       freenetconfigent(nconf);
+       t_unbind(xdmcpSocket);
+       t_close(xdmcpSocket);
+       return;
+    }
+    freenetconfigent(nconf);
+#else
+#ifndef _MINIX
+    int soopts = 1;
+
+    if ((xdmcpSocket = socket(AF_INET, SOCK_DGRAM, 0)) < 0)
+#else /* MINIX */
+    char *udp_device;
+    int r, s_errno;
+    nwio_udpopt_t udpopt;
+    nbio_ref_t ref;
+
+    udp_device= getenv("UDP_DEVICE");
+    if (udp_device == NULL)
+       udp_device= UDP_DEVICE;
+    xdmcpSocket= open(udp_device, O_RDWR);
+    if (xdmcpSocket != -1)
+    {
+       udpopt.nwuo_flags= NWUO_COPY | NWUO_LP_SEL | NWUO_EN_LOC | 
+               NWUO_DI_BROAD | NWUO_RP_ANY | NWUO_RA_ANY | NWUO_RWDATALL |
+               NWUO_DI_IPOPT;
+       r= ioctl(xdmcpSocket, NWIOSUDPOPT, &udpopt);
+       if (r == -1)
+       {
+               s_errno= errno;
+               close(xdmcpSocket);
+               xdmcpSocket= -1;
+               errno= s_errno;
+       }
+       ioctl(xdmcpSocket, NWIOGUDPOPT, &udpopt);
+       ErrorF("0x%x, 0x%x, 0x%x, 0x%x, 0x%x\n", 
+               udpopt.nwuo_flags,
+               udpopt.nwuo_locport,
+               udpopt.nwuo_remport,
+               udpopt.nwuo_locaddr,
+               udpopt.nwuo_remaddr);
+    }
+    if (xdmcpSocket != -1)
+    {
+       fcntl(xdmcpSocket, F_SETFD, fcntl(xdmcpSocket, F_GETFD) | 
+                                                               FD_ASYNCHIO);
+       nbio_register(xdmcpSocket);
+       ref.ref_int= xdmcpSocket;
+       nbio_setcallback(xdmcpSocket, ASIO_READ, read_cb, ref);
+    }
+    if (xdmcpSocket == -1)
+#endif /* !MINIX */
+       XdmcpWarning("UDP socket creation failed");
+#ifdef SO_BROADCAST
+    else if (setsockopt(xdmcpSocket, SOL_SOCKET, SO_BROADCAST, (char *)&soopts,
+       sizeof(soopts)) < 0)
+           XdmcpWarning("UDP set broadcast socket-option failed");
+#endif /* SO_BROADCAST */
+#endif /* STREAMSCONN */
+}
+
+static void
+send_query_msg()
+{
+    XdmcpHeader        header;
+    Bool       broadcast = FALSE;
+    int                i;
+
+    header.version = XDM_PROTOCOL_VERSION;
+    switch(state){
+    case XDM_QUERY:
+       header.opcode = (CARD16) QUERY; 
+       state = XDM_COLLECT_QUERY;
+       break;
+    case XDM_BROADCAST:
+       header.opcode = (CARD16) BROADCAST_QUERY;
+       state = XDM_COLLECT_BROADCAST_QUERY;
+       broadcast = TRUE;
+       break;
+    case XDM_INDIRECT:
+       header.opcode = (CARD16) INDIRECT_QUERY;
+       state = XDM_COLLECT_INDIRECT_QUERY;
+       break;
+    }
+    header.length = 1;
+    for (i = 0; i < AuthenticationNames.length; i++)
+       header.length += 2 + AuthenticationNames.data[i].length;
+
+    XdmcpWriteHeader (&buffer, &header);
+    XdmcpWriteARRAYofARRAY8 (&buffer, &AuthenticationNames);
+    if (broadcast)
+    {
+       int i;
+
+       for (i = 0; i < NumBroadcastAddresses; i++)
+           XdmcpFlush (xdmcpSocket, &buffer, &BroadcastAddresses[i],
+                       sizeof (struct sockaddr_in));
+    }
+    else
+    {
+       XdmcpFlush (xdmcpSocket, &buffer, &ManagerAddress,
+                   sizeof (ManagerAddress));
+    }
+}
+
+static void
+recv_willing_msg(from, fromlen, length)
+    struct sockaddr_in *from;
+    int                        fromlen;
+    unsigned           length;
+{
+    ARRAY8     authenticationName;
+    ARRAY8     hostname;
+    ARRAY8     status;
+
+    authenticationName.data = 0;
+    hostname.data = 0;
+    status.data = 0;
+    if (XdmcpReadARRAY8 (&buffer, &authenticationName) &&
+       XdmcpReadARRAY8 (&buffer, &hostname) &&
+       XdmcpReadARRAY8 (&buffer, &status))
+    {
+       if (length == 6 + authenticationName.length +
+                     hostname.length + status.length)
+       {
+           switch (state)
+           {
+           case XDM_COLLECT_QUERY:
+               XdmcpSelectHost(from, fromlen, &authenticationName);
+               break;
+           case XDM_COLLECT_BROADCAST_QUERY:
+           case XDM_COLLECT_INDIRECT_QUERY:
+               XdmcpAddHost(from, fromlen, &authenticationName, &hostname, &status);
+               break;
+           }
+       }
+    }
+    XdmcpDisposeARRAY8 (&authenticationName);
+    XdmcpDisposeARRAY8 (&hostname);
+    XdmcpDisposeARRAY8 (&status);
+}
+
+static void
+send_request_msg()
+{
+    XdmcpHeader            header;
+    int                    length;
+    int                    i;
+    ARRAY8         authenticationData;
+
+    header.version = XDM_PROTOCOL_VERSION;
+    header.opcode = (CARD16) REQUEST;
+
+    length = 2;                                            /* display number */
+    length += 1 + 2 * ConnectionTypes.length;      /* connection types */
+    length += 1;                                   /* connection addresses */
+    for (i = 0; i < ConnectionAddresses.length; i++)
+       length += 2 + ConnectionAddresses.data[i].length;
+    authenticationData.length = 0;
+    authenticationData.data = 0;
+    if (AuthenticationFuncs)
+    {
+       (*AuthenticationFuncs->Generator) (AuthenticationData,
+                                          &authenticationData,
+                                          REQUEST);
+    }
+    length += 2 + AuthenticationName->length;      /* authentication name */
+    length += 2 + authenticationData.length;       /* authentication data */
+    length += 1;                                   /* authorization names */
+    for (i = 0; i < AuthorizationNames.length; i++)
+       length += 2 + AuthorizationNames.data[i].length;
+    length += 2 + ManufacturerDisplayID.length;            /* display ID */
+    header.length = length;
+
+    if (!XdmcpWriteHeader (&buffer, &header))
+    {
+       XdmcpDisposeARRAY8 (&authenticationData);
+       return;
+    }
+    XdmcpWriteCARD16 (&buffer, DisplayNumber);
+    XdmcpWriteARRAY16 (&buffer, &ConnectionTypes);
+    XdmcpWriteARRAYofARRAY8 (&buffer, &ConnectionAddresses);
+
+    XdmcpWriteARRAY8 (&buffer, AuthenticationName);
+    XdmcpWriteARRAY8 (&buffer, &authenticationData);
+    XdmcpDisposeARRAY8 (&authenticationData);
+    XdmcpWriteARRAYofARRAY8 (&buffer, &AuthorizationNames);
+    XdmcpWriteARRAY8 (&buffer, &ManufacturerDisplayID);
+    if (XdmcpFlush (xdmcpSocket, &buffer, &req_sockaddr, req_socklen))
+       state = XDM_AWAIT_REQUEST_RESPONSE;
+}
+
+static void
+recv_accept_msg(length)
+    unsigned           length;
+{
+    CARD32  AcceptSessionID;
+    ARRAY8  AcceptAuthenticationName, AcceptAuthenticationData;
+    ARRAY8  AcceptAuthorizationName, AcceptAuthorizationData;
+
+    if (state != XDM_AWAIT_REQUEST_RESPONSE)
+       return;
+    AcceptAuthenticationName.data = 0;
+    AcceptAuthenticationData.data = 0;
+    AcceptAuthorizationName.data = 0;
+    AcceptAuthorizationData.data = 0;
+    if (XdmcpReadCARD32 (&buffer, &AcceptSessionID) &&
+       XdmcpReadARRAY8 (&buffer, &AcceptAuthenticationName) &&
+       XdmcpReadARRAY8 (&buffer, &AcceptAuthenticationData) &&
+       XdmcpReadARRAY8 (&buffer, &AcceptAuthorizationName) &&
+       XdmcpReadARRAY8 (&buffer, &AcceptAuthorizationData))
+    {
+       if (length == 12 + AcceptAuthenticationName.length +
+                          AcceptAuthenticationData.length +
+                          AcceptAuthorizationName.length +
+                          AcceptAuthorizationData.length)
+       {
+           if (!XdmcpCheckAuthentication (&AcceptAuthenticationName,
+                                     &AcceptAuthenticationData, ACCEPT))
+           {
+               XdmcpFatal ("Authentication Failure", &AcceptAuthenticationName);
+           }
+           /* permit access control manipulations from this host */
+           AugmentSelf (&req_sockaddr, req_socklen);
+           /* if the authorization specified in the packet fails
+            * to be acceptable, enable the local addresses
+            */
+           if (!XdmcpAddAuthorization (&AcceptAuthorizationName,
+                                       &AcceptAuthorizationData))
+           {
+               AddLocalHosts ();
+           }
+           SessionID = AcceptSessionID;
+           state = XDM_MANAGE;
+           send_packet();
+       }
+    }
+    XdmcpDisposeARRAY8 (&AcceptAuthenticationName);
+    XdmcpDisposeARRAY8 (&AcceptAuthenticationData);
+    XdmcpDisposeARRAY8 (&AcceptAuthorizationName);
+    XdmcpDisposeARRAY8 (&AcceptAuthorizationData);
+}
+
+static void
+recv_decline_msg(length)
+    unsigned           length;
+{
+    ARRAY8  status, DeclineAuthenticationName, DeclineAuthenticationData;
+
+    status.data = 0;
+    DeclineAuthenticationName.data = 0;
+    DeclineAuthenticationData.data = 0;
+    if (XdmcpReadARRAY8 (&buffer, &status) &&
+       XdmcpReadARRAY8 (&buffer, &DeclineAuthenticationName) &&
+       XdmcpReadARRAY8 (&buffer, &DeclineAuthenticationData))
+    {
+       if (length == 6 + status.length +
+                         DeclineAuthenticationName.length +
+                         DeclineAuthenticationData.length &&
+           XdmcpCheckAuthentication (&DeclineAuthenticationName,
+                                     &DeclineAuthenticationData, DECLINE))
+       {
+           XdmcpFatal ("Session declined", &status);
+       }
+    }
+    XdmcpDisposeARRAY8 (&status);
+    XdmcpDisposeARRAY8 (&DeclineAuthenticationName);
+    XdmcpDisposeARRAY8 (&DeclineAuthenticationData);
+}
+
+static void
+send_manage_msg()
+{
+    XdmcpHeader        header;
+
+    header.version = XDM_PROTOCOL_VERSION;
+    header.opcode = (CARD16) MANAGE;
+    header.length = 8 + DisplayClass.length;
+
+    if (!XdmcpWriteHeader (&buffer, &header))
+       return;
+    XdmcpWriteCARD32 (&buffer, SessionID);
+    XdmcpWriteCARD16 (&buffer, DisplayNumber);
+    XdmcpWriteARRAY8 (&buffer, &DisplayClass);
+    state = XDM_AWAIT_MANAGE_RESPONSE;
+    XdmcpFlush (xdmcpSocket, &buffer, &req_sockaddr, req_socklen);
+}
+
+static void
+recv_refuse_msg(length)
+    unsigned           length;
+{
+    CARD32  RefusedSessionID;
+
+    if (state != XDM_AWAIT_MANAGE_RESPONSE)
+       return;
+    if (length != 4)
+       return;
+    if (XdmcpReadCARD32 (&buffer, &RefusedSessionID))
+    {
+       if (RefusedSessionID == SessionID)
+       {
+           state = XDM_START_CONNECTION;
+           send_packet();
+       }
+    }
+}
+
+static void
+recv_failed_msg(length)
+    unsigned           length;
+{
+    CARD32  FailedSessionID;
+    ARRAY8  status;
+
+    if (state != XDM_AWAIT_MANAGE_RESPONSE)
+       return;
+    status.data = 0;
+    if (XdmcpReadCARD32 (&buffer, &FailedSessionID) &&
+       XdmcpReadARRAY8 (&buffer, &status))
+    {
+       if (length == 6 + status.length &&
+           SessionID == FailedSessionID)
+       {
+           XdmcpFatal ("Session failed", &status);
+       }
+    }
+    XdmcpDisposeARRAY8 (&status);
+}
+
+static void
+send_keepalive_msg()
+{
+    XdmcpHeader        header;
+
+    header.version = XDM_PROTOCOL_VERSION;
+    header.opcode = (CARD16) KEEPALIVE;
+    header.length = 6;
+
+    XdmcpWriteHeader (&buffer, &header);
+    XdmcpWriteCARD16 (&buffer, DisplayNumber);
+    XdmcpWriteCARD32 (&buffer, SessionID);
+
+    state = XDM_AWAIT_ALIVE_RESPONSE;
+    XdmcpFlush (xdmcpSocket, &buffer, &req_sockaddr, req_socklen);
+}
+
+static void
+recv_alive_msg (length)
+    unsigned           length;
+{
+    CARD8   SessionRunning;
+    CARD32  AliveSessionID;
+    int            dormancy;
+
+    if (state != XDM_AWAIT_ALIVE_RESPONSE)
+       return;
+    if (length != 5)
+       return;
+    if (XdmcpReadCARD8 (&buffer, &SessionRunning) &&
+       XdmcpReadCARD32 (&buffer, &AliveSessionID))
+    {
+       if (SessionRunning && AliveSessionID == SessionID)
+       {
+           /* backoff dormancy period */
+           state = XDM_RUN_SESSION;
+           if ((GetTimeInMillis() - lastDeviceEventTime.milliseconds) >
+               keepaliveDormancy * 1000)
+           {
+               keepaliveDormancy <<= 1;
+               if (keepaliveDormancy > XDM_MAX_DORMANCY)
+                   keepaliveDormancy = XDM_MAX_DORMANCY;
+           }
+           timeOutTime = GetTimeInMillis() + keepaliveDormancy * 1000;
+       }
+       else
+       {
+           XdmcpDeadSession ("Alive respose indicates session dead");
+       }
+    }
+}
+
+static 
+XdmcpFatal (type, status)
+    char       *type;
+    ARRAY8Ptr  status;
+{
+    FatalError ("XDMCP fatal error: %s %*.*s\n", type,
+          status->length, status->length, status->data);
+}
+
+static 
+XdmcpWarning(str)
+    char *str;
+{
+    ErrorF("XDMCP warning: %s\n", str);
+}
+
+static
+get_manager_by_name(argc, argv, i)
+    int            argc, i;
+    char    **argv;
+{
+    struct hostent *hep;
+
+    if (i == argc)
+    {
+       ErrorF("Xserver: missing host name in command line\n");
+       exit(1);
+    }
+    if (!(hep = gethostbyname(argv[i])))
+    {
+       ErrorF("Xserver: unknown host: %s\n", argv[i]);
+       exit(1);
+    }
+#ifndef _MINIX
+    if (hep->h_length == sizeof (struct in_addr))
+#else
+    if (hep->h_length == sizeof (ipaddr_t))
+#endif
+    {
+       memmove(&ManagerAddress.sin_addr, hep->h_addr, hep->h_length);
+#ifdef BSD44SOCKETS
+       ManagerAddress.sin_len = sizeof(ManagerAddress);
+#endif
+       ManagerAddress.sin_family = AF_INET;
+       ManagerAddress.sin_port = htons (xdm_udp_port);
+    }
+    else
+    {
+       ErrorF ("Xserver: host on strange network %s\n", argv[i]);
+       exit (1);
+    }
+}
+
+#ifdef MINIX
+static char read_buffer[XDM_MAX_MSGLEN+sizeof(udp_io_hdr_t)];
+static int read_inprogress;
+static int read_size;
+
+int
+XdmcpFill (fd, buffer, from, fromlen)
+int             fd;
+XdmcpBufferPtr  buffer;
+XdmcpNetaddr    from;       /* return */
+int             *fromlen;   /* return */
+{
+       int r;
+
+       if (read_inprogress)
+               return 0;
+
+       if (read_size != 0)
+       {
+               r= read_size;
+               read_size= 0;
+               return MNX_XdmcpFill(fd, buffer, from, fromlen, read_buffer,
+                       r);
+       }
+
+       r= read(fd, read_buffer, sizeof(read_buffer));
+       if (r > 0)
+       {
+               return MNX_XdmcpFill(fd, buffer, from, fromlen, read_buffer,
+                       r);
+       }
+       else if (r == -1 && errno == EINPROGRESS)
+       {
+               read_inprogress= 1;
+               nbio_inprogress(fd, ASIO_READ, 1 /* read */, 0 /* write */,
+                       0 /* except */);
+               return 0;
+       }
+       else
+               FatalError("XdmcpFill: read failed: %s\n",
+                       r == 0 ? "EOF" : strerror(errno));
+       return 0;
+}
+
+static void read_cb(ref, res, err)
+nbio_ref_t ref;
+int res;
+int err;
+{
+       if (res <= 0)
+       {
+               FatalError("xdmcp'read_cb: read failed: %s\n",
+                       res == 0 ? "EOF" : strerror(err));
+       }
+       read_inprogress= 0;
+       read_size= res;
+}
+#endif
+
+#else
+static int xdmcp_non_empty; /* avoid complaint by ranlib */
+#endif /* XDMCP */
diff --git a/Xserver/registry b/Xserver/registry
new file mode 100644 (file)
index 0000000..e44178c
--- /dev/null
@@ -0,0 +1,1629 @@
+/* $XConsortium: registry /main/119 1996/10/08 12:31:00 swick $ */
+
+                                 X Registry
+
+The X Consortium is maintaining a registry of certain X-related items, to
+aid in avoiding conflicts and to aid in sharing of such items.  Requests to
+register items, or questions about registration, should be addressed to
+       xregistry@x.org
+or to
+       Registry
+       X Consortium
+       201 Broadway
+       Cambridge MA 02139-1955
+       USA
+
+Electronic mail will be acknowledged upon receipt.  Please allow up to 4 weeks
+for a formal response to registration and inquiries.
+
+The registry is published as part of the X software distribution from the
+X Consortium.  It is also usually available by sending a message to
+xstuff@x.org.  The message can have a subject line and no body, or a
+single-line body and no subject, in either case the line looking like:
+       send docs registry
+
+All registered items must have the postal address of someone responsible for
+the item, or a reference to a document describing the item and the postal
+address of where to write to obtain the document.
+
+Registration of conflicting items will not be permitted (the same value will
+not be assigned two different meanings) except where explicitly indicated.
+
+1. ORGANIZATION NAMES
+
+These should generally be used as prefixes for other registered names.
+
+Name                                           Reference
+----                                           ---------
+"Acorn"                                                [49]
+"Adobe"                                                [69]
+"AIX"                                          [33]
+"ALLINK"                                       [99]
+"APOLLO"                                       [1]
+"Apple"                                                [22]
+"ARDENT"                                       [2]
+"BBN"                                          [61]
+"CRAB"                                         [84]
+"CRUC"                                         [30]
+"DEC"                                          [82]
+"DG"                                           [48]
+"DME"                                          [7]
+"Dt"                                           [114]
+"EFW"                                          [124]
+"ES"                                           [75]
+"FXD"                                          [55]
+"FUJITSU"                                      [87]
+"IBM"                                          [33]
+"ICS"                                          [31]
+"ILA"                                          [62]
+"IPSYS"                                                [59]
+"IXI"                                          [20]
+"JCC"                                          [90]
+"JUP"                                          [93]
+"KPC"                                          [98]
+"LJK"                                          [56]
+"LTA"                                          [60]
+"MEGATEK"                                      [112]
+"Metheus"                                      [117]
+"MIT"                                          [8]
+"MOTIF"                                                [7]
+"NCD"                                          [66]
+"OMRON"                                                [45]
+"ORL"                                          [65]
+"OSF"                                          [7]
+"Panasonic"                                    [52]
+"PERITEK"                                      [116]
+"PFU"                                          [32]
+"RATIONAL"                                     [88]
+"SGCS"                                         [83]
+"SGI"                                          [6]
+"SONY"                                         [37]
+"stellar"                                      [28]
+"STI"                                          [73]
+"Sun"                                          [58]
+"Tech-Source"                                  [106]
+"TEK"                                          [43]
+"visual"                                       [5]
+"VIT"                                          [46]
+"WN"                                           [103]
+"WRI"                                          [102]
+"WYSE"                                         [68]
+"X/software"                                   [115]
+"X3D"                                          [8]
+"XC"                                           [104]
+"Xerox"                                                [91]
+"XFree86"                                      [113]
+"XUG"                                          [31]
+
+
+2. KEYSYMS
+
+Only "private" keysyms (with 29th bit set) can be registered by organizations;
+standard keysyms must be approved by the Consortium.  Since keysym numeric
+values are explicitly private, we will permit (but not encourage) conflicting
+registration here.
+
+Name                   Value                   Reference
+----                   -----                   ---------
+hpXK_mute_acute                0x100000A8              [36]
+hpXK_mute_grave                0x100000A9              [36]
+hpXK_mute_asciicircum  0x100000AA              [36]
+hpXK_mute_diaeresis    0x100000AB              [36]
+hpXK_mute_asciitilde   0x100000AC              [36]
+hpXK_lira              0x100000AF              [36]
+hpXK_guilder           0x100000BE              [36]
+hpXK_Ydiaeresis                0x100000EE              [36]
+hpXK_IO                        0x100000EE              [36]
+hpXK_longminus         0x100000F6              [36]
+hpXK_block             0x100000FC              [36]
+apXK_LineDel           0x1000FF00              [1]
+apXK_CharDel           0x1000FF01              [1]
+apXK_Copy              0x1000FF02              [1]
+apXK_Cut               0x1000FF03              [1]
+apXK_Paste             0x1000FF04              [1]
+apXK_Move              0x1000FF05              [1]
+apXK_Grow              0x1000FF06              [1]
+apXK_Cmd               0x1000FF07              [1]
+apXK_Shell             0x1000FF08              [1]
+apXK_LeftBar           0x1000FF09              [1]
+apXK_RightBar          0x1000FF0A              [1]
+apXK_LeftBox           0x1000FF0B              [1]
+apXK_RightBox          0x1000FF0C              [1]
+apXK_UpBox             0x1000FF0D              [1]
+apXK_DownBox           0x1000FF0E              [1]
+apXK_Pop               0x1000FF0F              [1]
+apXK_Read              0x1000FF10              [1]
+apXK_Edit              0x1000FF11              [1]
+apXK_Save              0x1000FF12              [1]
+apXK_Exit              0x1000FF13              [1]
+apXK_Repeat            0x1000FF14              [1]
+hpXK_Modelock1         0x1000FF48              [36]
+hpXK_Modelock2         0x1000FF49              [36]
+hpXK_Reset             0x1000FF6C              [36]
+hpXK_System            0x1000FF6D              [36]
+hpXK_User              0x1000FF6E              [36]
+hpXK_ClearLine         0x1000FF6F              [36]
+hpXK_InsertLine                0x1000FF70              [36]
+hpXK_DeleteLine                0x1000FF71              [36]
+hpXK_InsertChar                0x1000FF72              [36]
+hpXK_DeleteChar                0x1000FF73              [36]
+hpXK_BackTab           0x1000FF74              [36]
+hpXK_KP_BackTab                0x1000FF75              [36]
+apXK_KP_parenleft      0x1000FFA8              [1]
+apXK_KP_parenright     0x1000FFA9              [1]
+
+IXK_2ND_FUNC_L         0x10004001              [50]
+IXK_2ND_FUNC_R         0x10004002              [50]
+IXK_REMOVE             0x10004003              [50]
+IXK_REPEAT             0x10004004              [50]
+IXK_A1                 0x10004101              [50]
+IXK_A2                 0x10004102              [50]
+IXK_A3                 0x10004103              [50]
+IXK_A4                 0x10004104              [50]
+IXK_A5                 0x10004105              [50]
+IXK_A6                 0x10004106              [50]
+IXK_A7                 0x10004107              [50]
+IXK_A8                 0x10004108              [50]
+IXK_A9                 0x10004109              [50]
+IXK_A10                        0x1000410A              [50]
+IXK_A11                        0x1000410B              [50]
+IXK_A12                        0x1000410C              [50]
+IXK_A13                        0x1000410D              [50]
+IXK_A14                        0x1000410E              [50]
+IXK_A15                        0x1000410F              [50]
+IXK_B1                 0x10004201              [50]
+IXK_B2                 0x10004202              [50]
+IXK_B3                 0x10004203              [50]
+IXK_B4                 0x10004204              [50]
+IXK_B5                 0x10004205              [50]
+IXK_B6                 0x10004206              [50]
+IXK_B7                 0x10004207              [50]
+IXK_B8                 0x10004208              [50]
+IXK_B9                 0x10004209              [50]
+IXK_B10                        0x1000420A              [50]
+IXK_B11                        0x1000420B              [50]
+IXK_B12                        0x1000420C              [50]
+IXK_B13                        0x1000420D              [50]
+IXK_B14                        0x1000420E              [50]
+IXK_B15                        0x1000420F              [50]
+IXK_B16                        0x10004210              [50]
+
+DXK_Remove             0x1000FF00              [27]
+DXK_ring_accent                0x1000FEB0              [27]
+DXK_circumflex_accent  0x1000FE5E              [27]
+DXK_cedilla_accent     0x1000FE2C              [27]
+DXK_acute_accent       0x1000FE27              [27]
+DXK_grave_accent       0x1000FE60              [27]
+DXK_tilde              0x1000FE7E              [27]
+DXK_diaeresis          0x1000FE22              [27]
+
+osfXK_Copy             0x1004FF02              [7]
+osfXK_Cut              0x1004FF03              [7]
+osfXK_Paste            0x1004FF04              [7]
+osfXK_BackTab          0x1004FF07              [7]
+osfXK_BackSpace                0x1004FF08              [7]
+osfXK_Clear            0x1004FF0B              [7]
+osfXK_Escape           0x1004FF1B              [7]
+osfXK_AddMode          0x1004FF31              [7]
+osfXK_PrimaryPaste     0x1004FF32              [7]
+osfXK_QuickPaste       0x1004FF33              [7]
+osfXK_PageLeft         0x1004FF40              [7]
+osfXK_PageUp           0x1004FF41              [7]
+osfXK_PageDown         0x1004FF42              [7]
+osfXK_PageRight                0x1004FF43              [7]
+osfXK_Activate         0x1004FF44              [7]
+osfXK_MenuBar          0x1004FF45              [7]
+osfXK_Left             0x1004FF51              [7]
+osfXK_Up               0x1004FF52              [7]
+osfXK_Right            0x1004FF53              [7]
+osfXK_Down             0x1004FF54              [7]
+osfXK_Prior            0x1004FF55              [7]
+osfXK_Next             0x1004FF56              [7]
+osfXK_EndLine          0x1004FF57              [7]
+osfXK_BeginLine                0x1004FF58              [7]
+osfXK_EndData          0x1004FF59              [7]
+osfXK_BeginData                0x1004FF5A              [7]
+osfXK_PrevMenu         0x1004FF5B              [7]
+osfXK_NextMenu         0x1004FF5C              [7]
+osfXK_PrevField                0x1004FF5D              [7]
+osfXK_NextField                0x1004FF5E              [7]
+osfXK_Select           0x1004FF60              [7]
+osfXK_Insert           0x1004FF63              [7]
+osfXK_Undo             0x1004FF65              [7]
+osfXK_Menu             0x1004FF67              [7]
+osfXK_Cancel           0x1004FF69              [7]
+osfXK_Help             0x1004FF6A              [7]
+osfXK_SelectAll                0x1004FF71              [7]
+osfXK_DeselectAll      0x1004FF72              [7]
+osfXK_Reselect         0x1004FF73              [7]
+osfXK_Extend           0x1004FF74              [7]
+osfXK_Restore          0x1004FF78              [7]
+osfXK_SwitchDirection  0x1004FF7E              [7]
+osfXK_PriorMinor       0x1004FFF5              [7]
+osfXK_NextMinor                0x1004FFF6              [7]
+osfXK_RightLine                0x1004FFF7              [7]
+osfXK_LeftLine         0x1004FFF8              [7]
+osfXK_Delete           0x1004FFFF              [7]
+
+SunXK_FA_Grave         0x1005FF00              [58]
+SunXK_FA_Circum                0x1005FF01              [58]
+SunXK_FA_Tilde         0x1005FF02              [58]
+SunXK_FA_Acute         0x1005FF03              [58]
+SunXK_FA_Diaeresis     0x1005FF04              [58]
+SunXK_FA_Cedilla       0x1005FF05              [58]
+SunXK_F36              0x1005FF10              [58]
+SunXK_F37              0x1005FF11              [58]
+SunXK_Sys_Req          0x1005FF60              [58]
+SunXK_Props            0x1005FF70              [58]
+SunXK_Front            0x1005FF71              [58]
+SunXK_Copy             0x1005FF72              [58]
+SunXK_Open             0x1005FF73              [58]
+SunXK_Paste            0x1005FF74              [58]
+SunXK_Cut              0x1005FF75              [58]
+SunXK_PowerSwitch              0x1005FF76      [58]
+SunXK_AudioLowerVolume         0x1005FF77      [58]
+SunXK_AudioMute                        0x1005FF78      [58]
+SunXK_AudioRaiseVolume         0x1005FF79      [58]
+SunXK_VideoDegauss             0x1005FF7A      [58]
+SunXK_VideoLowerBrightness     0x1005FF7B      [58]
+SunXK_VideoRaiseBrightness     0x1005FF7C      [58]
+SunXK_PowerSwitchShift         0x1005FF7D      [58]
+
+WYXK_Setup             0x1006FF00              [68]
+
+ncdXK_Setup            0x1006FF00              [66]
+
+XeroxXK_PointerButton1 0x10070001              [91]
+XeroxXK_PointerButton2 0x10070002              [91]
+XeroxXK_PointerButton3 0x10070003              [91]
+XeroxXK_PointerButton4 0x10070004              [91]
+XeroxXK_PointerButton5 0x10070005              [91]
+
+XF86XK_ModeLock                0x1008FF01              [113]
+
+Range 0x11000000 to 0x1100FFFF is allocated for keypad keysyms.
+
+
+3. AUTHORIZATION PROTOCOL NAMES
+
+See Section 8 of the protocol.  Names should generally have an organizational
+prefix.
+
+Name                                           Reference
+----                                           ---------
+"MIT-KERBEROS-4"                               [21]
+"MIT-KERBEROS-5"                               [21]
+"MIT-MAGIC-COOKIE-1"                           [8]
+"SUN-DES-1"                                    [57]
+"XC-QUERY-SECURITY-1"                          [8]
+"XDM-AUTHORIZATION-1"                          [8], [11]
+
+4. VENDOR STRING FORMATS
+      
+See Section 8 of the protocol.
+
+String                                         Reference
+----                                           ---------
+"Acorn Computers Ltd"                          [49]
+"Apollo Computer Inc."                         [1]
+"Apple Computer, Inc."                         [22]
+"Ardent Computer Corporation"                  [2]
+"Crab Advanced Technologies Ltd"               [84]
+"Crucible"                                     [30]
+"Data General Corporation"                     [48]
+"Digital Equipment Corporation"                        [82]
+"EFW, Inc."                                    [124]
+"Evans & Sutherland"                           [75]
+"FUJITSU LIMITED"                              [87]
+"International Business Machines"              [33]
+"JAPAN COMPUTER CORP."                         [90]
+"Jupiter Systems Inc."                         [93]
+"Kubota Pacific Computer"                      [98]
+"Matsushita Electric Industrial Co., Ltd."     [52]
+"Megatek Corporation"                          [112]
+"Metheus Corporation"                          [117]
+"MIT X Consortium"                             [8]
+"Network Computing Devices Inc."               [66]
+"OMRON Corporation"                            [45]
+"Peritek Corporation"                          [116]
+"PFU LIMITED"                                  [32]
+"Silicon Graphics Computer Systems"            [6]
+"Snitily Graphics Consulting Services"         [83]
+"Sony Corporation"                             [37]
+"Stellar Computer Inc."                                [28]
+"Sun Microsystems, Inc."                       [101]
+"Tech-Source Inc."                             [106]
+"The XFree86 Project, Inc"                     [113]
+"VIT-Visual Information Technologies, Inc (VITec)"     [46]
+"Wolfram Research, Inc."                       [102]
+"Wyse Technology Inc."                         [68]
+"X/software Germany"                           [115]
+"X11/NeWS - Sun Microsystems, Inc."            [58]
+"X Consortium"                                 [104]
+
+5. PROTOCOL EXTENSION NAMES
+
+As used in the QueryExtension and ListExtensions protocol requests.
+The name should generally have an organizational prefix.
+
+Name                                           Reference
+----                                           ---------
+"Acorn-Noise"                                  [49]
+"Adobe-DPS-Extension"                          [42]
+"AixDeviceControlExtension"                    [33]
+"AixExtension"                                 [33]
+"AixEventControlExtension"                     [33]
+"AixStatExtension"                             [33]
+"AixDialExtension"                             [33]
+"AixLpfkExtension"                             [33]
+"APOLLO-SHARE"                                 [1]
+"ARDENT-XDoubleBuffer"                         [2], [3]
+"ARDENT-XTitan"                                        [2], [4]
+"bezier"                                       [34]
+"BIG-REQUESTS"                                 [97]
+"DEC-XTRAP"                                    [51]
+"DOUBLE-BUFFER"                                        [123]
+"ESMultiScreenExtension"                       [75]
+"ESSetBitsExtension"                           [75]
+"ESTraverse3DExtension"                                [75]
+"ESVideoModeExtension"                         [75]
+"ESLayersExtension"                            [75]
+"ESCursorAttrExtension"                                [75]
+"ESPickExtension"                              [75]
+"FUJITSU-Control-Modifiers"                    [87]
+"FUJITSU-VX-VideoControl"                      [87]
+"FUJITSU-VX-DeviceControl"                     [87]
+"JUPMISC"                                      [93]
+"KPC-XPeer"                                    [98]
+"LBX"                                          [125]
+"MEX-Metheus-Extension-to-X"                   [117]
+"MIT-SCREEN-SAVER"                             [96]
+"MIT-SHM"                                      [8]
+"MIT-SUNDRY-NONSTANDARD"                       [8]
+"Multi-Buffering"                              [8], [10]
+"NCD-SIE"                                      [66]
+"ORL-SYNC"                                     [65]
+"PanasonicDosEmulatorExtension"                        [52]
+"PFU-GAOpAttr"                                 [32]
+"RECORD"                                       [122]
+"SECURITY"                                     [126]
+"SGI-GLX"                                      [6]
+"SGI-XGL"                                      [6]
+"SGI-MISCELLANEOUS"                            [6]
+"SHAPE"                                                [8], [13]
+"SonyKeyboardExtension"                                [37]
+"SonySoundExtension"                           [37]
+"SonyVideoExtension"                           [37]
+"SonyPrinterExtension"                         [37]
+"stellar-cm"                                   [29]
+"stellar-db"                                   [29]
+"stellar-im"                                   [29]
+"stellar-shmLink"                              [28]
+"stellar-xfdi"                                 [29]
+"stellar-xtest"                                        [28]
+"SUN_TSOL"                                     [121]
+"SYNC"                                         [108]
+"TsiOvlExtension"                              [106]
+"TekCms"                                       [43]
+"TeKDisplayListExtension"                      [43]
+"TeKHardCopySupport"                           [43]
+"TeKPeerWindows"                               [43]
+"VEX"                                          [14]
+"VIT-Image Display List Extension"             [46]
+"X/software X/bigX"                            [115]
+"X/software X/keymapX"                         [115]
+"X/software X/metaX"                           [115]
+"X/software X/shadowX"                         [115]
+"X/software X/translucentX"                    [115]
+"X3D-PEX"                                      [8], [9]
+"XC-APPGROUP"                                  [127]
+"XC-MISC"                                      [109]
+"XFree86-VidModeExtension"                     [113]
+"XIE"                                          [110]
+"XInputExtension"                              [128]
+"XKEYBOARD"                                    [111]
+"XPRINT"                                       [129]
+"XTEST"                                                [8]
+"XTestExtension1"                              [35]
+"XVideo"                                       [118]
+"ZoidExtension"                                        [34]
+
+6. HOST FAMILIES
+
+See the "family" component of the HOST structure in the protocol.
+Values for private families will be assigned by the X Consortium.
+
+Value  Name                                    Reference
+-----  ----                                    ---------
+0      Internet                                [23]
+1      DECnet                                  [23]
+2      Chaos                                   [23]
+252    LocalHost                               [105]
+253    Kerberos5Principal                      [94]
+254    Netname                                 [57]
+
+7. PROPERTY NAMES
+
+As stored on windows in the server.  See Sections 4.1.2, 4.1.3, 5.1.1, and
+6.4 of the ICCCM, and Section 14.1 of the Xlib manual.  Registration must
+include the context in which the property is used (e.g. root window, top-level
+client window).  In general, private property names should start with a
+leading underscore, followed by the organizational prefix, followed by another
+underscore.
+
+Name                                           Reference
+----                                           ---------
+"RGB_DEFAULT_MAP"                              [18]
+"RGB_BEST_MAP"                                 [18]
+"RGB_RED_MAP"                                  [18]
+"RGB_GREEN_MAP"                                        [18]
+"RGB_BLUE_MAP"                                 [18]
+"RGB_GRAY_MAP"                                 [18]
+"WM_CLASS"                                     [16]
+"WM_CLIENT_MACHINE"                            [16]
+"WM_COLORMAP_WINDOW"                           [16]
+"WM_COMMAND"                                   [16]
+"WM_HINTS"                                     [16]
+"WM_ICON_NAME"                                 [16]
+"WM_ICON_SIZE"                                 [16]
+"WM_NAME"                                      [16]
+"WM_NORMAL_HINTS"                              [16]
+"WM_PROTOCOLS"                                 [16]
+"WM_STATE"                                     [16]
+"WM_TRANSIENT_FOR"                             [16]
+"WM_ZOOM_HINTS"                                        [17], [18]
+"_MIT_OBJ_CLASS"                               [94]
+"_NCD_WM_RUNNING"                              [66]
+"_RATIONAL_ROSE_TAG"                           [88]
+"_RATIONAL_ROSE_MSG"                           [88]
+"_SGI_GL_COLORMAP"                             [6]
+
+8. PROPERTY TYPE NAMES
+
+See "PROPERTY NAMES" above.
+
+Name                                           Reference
+----                                           ---------
+"ATOM"                                         [16]
+"ATOM_PAIR"                                    [16]
+"BITMAP"                                       [16]
+"COMPOUND_TEXT"                                        [8], [12]
+"DRAWABLE"                                     [16]
+"INCR"                                         [16]
+"INCREMENTAL"                                  [17], [16]
+"INTEGER"                                      [16]
+"PIXMAP"                                       [16]
+"RGB_COLOR_MAP"                                        [18]
+"SPAN"                                         [16]
+"STRING"                                       [16]
+"WINDOW"                                       [16]
+"WM_HINTS"                                     [16]
+"WM_ICON_SIZE"                                 [16]
+"WM_SIZE_HINTS"                                        [16]
+"WM_STATE"                                     [16]
+"_SONY_CDFF"                                   [37]
+"_SONY_XWD"                                    [37]
+"_SONY_XPICT"                                  [37]
+"_SJIS_STRING"                                 [37]
+"_EUC_STRING"                                  [37]
+"_JIS_STRING"                                  [37]
+"_WRI_XWD_RLED"                                        [102]
+"_XWNMO"                                       [45]
+
+9. SELECTION NAMES
+
+See Section 2.6.1 of the ICCCM.  In general, private selection names should
+start with a leading underscore, followed by the organizational prefix,
+followed by another underscore.
+
+Name                                           Reference
+----                                           ---------
+"CLIPBOARD"                                    [16]
+"PD_SELECTION"                                 [37]
+"PRIMARY"                                      [16]
+"PRIMARY_FONT"                                 [47]
+"SECONDARY"                                    [16]
+"_JAPANESE_CONVERSION"                         [37]
+"_CHINESE_CONVERSION"                          [37]
+"_HUNGLE_CONVERSION"                           [37]
+"_EUROPEAN_CONVERSION"                         [37]
+"__SAM_" (prefix)                              [67]
+
+10. SELECTION TARGETS
+
+See Section 2.6.2 of the ICCCM.  In general, private selection targets should
+start with a leading underscore, followed by the organizational prefix,
+followed by another underscore.
+
+Name                                           Reference
+----                                           ---------
+"BACKGROUND"                                   [16]
+"BITMAP"                                       [16]
+"CHARACTER_POSITION"                           [16]
+"CLASS"                                                [16]
+"CLIENT_WINDOW"                                        [16]
+"COLORMAP"                                     [16]
+"COLUMN_NUMBER"                                        [16]
+"COMPOUND_TEXT"                                        [8], [12]
+"DELETE"                                       [16]
+"DRAWABLE"                                     [16]
+"FILE_NAME"                                    [16]
+"FOREGROUND"                                   [16]
+"HOST_NAME"                                    [16]
+"INSERT_PROPERTY"                              [16]
+"INSERT_SELECTION"                             [16]
+"LENGTH"                                       [16]
+"LINE_NUMBER"                                  [16]
+"LIST_LENGTH"                                  [16]
+"MODULE"                                       [16]
+"MULTIPLE"                                     [16]
+"NAME"                                         [16]
+"ODIF"                                         [16]
+"OWNER_OS"                                     [16]
+"PIXMAP"                                       [16]
+"PROCEDURE"                                    [16]
+"PROCESS"                                      [16]
+"STRING"                                       [16]
+"TARGETS"                                      [16]
+"TASK"                                         [16]
+"TEXT"                                         [16]
+"TIMESTAMP"                                    [16]
+"USER"                                         [16]
+"_ADOBE_EPS"                                   [69]
+"_ADOBE_EPSI"                                  [69]
+"_SONY_CDFF"                                   [37]
+"_SONY_XWD"                                    [37]
+"_SONY_XPICT"                                  [37]
+"_SJIS_STRING"                                 [37]
+"_EUC_STRING"                                  [37]
+"_JIS_STRING"                                  [37]
+"_WRI_XWD_RLED"                                        [102]
+
+11. WM_PROTOCOLS PROTOCOLS
+
+See Section 4.1.2.7 of the ICCCM.  In general, private protocols should start
+with a leading underscore, followed by the organizational prefix, followed by
+another underscore.
+
+Name                                           Reference
+----                                           ---------
+"WM_DELETE_WINDOW"                             [16]
+"WM_TAKE_FOCUS"                                        [16]
+"WM_SAVE_YOURSELF"                             [16]
+
+12. CLIENTMESSAGE TYPES
+
+See the "type" field in the ClientMessage event in the protocol, and Section
+4.2.8 of the ICCCM.  In general, private types should start with a leading
+underscore, followed by the organizational prefix, followed by another
+underscore.
+
+Name                                           Reference
+----                                           ---------
+"PD_ACTIVE"                                    [37]
+"WM_CHANGE_STATE"                              [16]
+"WM_PROTOCOLS"                                 [16]
+"_CONVERSION_REQUEST"                          [37]
+"_CONVERSION_NOTIFY"                           [37]
+"_CONVERSION_END"                              [37]
+
+13. FONT FOUNDRY NAMES
+
+See Section 3.1.2.1 of the XLFD.  This will typically be an organization name.
+
+Name                                           Reference
+----                                           ---------
+"Acorn"                                                [49]
+"Adobe"                                                [24]
+"AIX"                                          [33]
+"Apple"                                                [22]
+"Bitstream"                                    [25]
+"Cognition"                                    [89]
+"Cronyx"                                       [120]
+"DEC"                                          [27]
+"eands"                                                [75]
+"fujitsu"                                      [87]
+"FujiXerox"                                    [64]
+"IBM"                                          [33]
+"IPSYS"                                                [59]
+"Metheus"                                      [117]
+"MISC"                                         [8]
+"NCD"                                          [66]
+"omron"                                                [45]
+"Panasonic"                                    [52]
+"Sony"                                         [37]
+"Sun"                                          [92]
+
+14. FONT CHARSET (REGISTRY AND ENCODING) NAMES
+
+See Sections 3.1.2.12 of the XLFD.  For ISO standards, the format
+will generally be: "ISO" + <standard-number> + "-" + <part-number>
+
+Name                                           Reference
+----                                           ---------
+"DEC"                                          [27]
+       registry prefix
+"DEC.CNS11643.1986-2"                          [53]
+       CNS11643 2-plane using the encoding
+       suggested in that standard
+"DEC.DTSCS.1990-2"                             [54]
+       DEC Taiwan Supplemental Character Set
+"fujitsu.u90x01.1991-0"                                [87]
+"fujitsu.u90x03.1991-0"                                [87]
+"GB2312.1980-0"                                        [39],[12]
+       China (PRC) Hanzi, GL encoding
+"GB2312.1980-1"                                        [39]
+       (deprecated)
+       China (PRC) Hanzi, GR encoding
+"HP-Arabic8"                                   [36]
+       HPARABIC8 8-bit character set
+"HP-East8"                                     [36]
+       HPEAST8 8-bit character set
+"HP-Greek8"                                    [36]
+       HPGREEK8 8-bit character set
+"HP-Hebrew8"                                   [36]
+       HPHEBREW8 8-bit character set
+"HP-Japanese15"                                        [36]
+       HPJAPAN15 15-bit characer set,
+       modified from industry defacto
+       standard Shift-JIS
+"HP-Kana8"                                     [36]
+       HPKANA8 8-bit character set
+"HP-Korean15"                                  [36]
+       HPKOREAN15 15-bit character set
+"HP-Roman8"                                    [36]
+       HPROMAN8 8-bit character set
+"HP-SChinese15"                                        [36]
+       HPSCHINA15 15-bit character set for
+       support of Simplified Chinese
+"HP-TChinese15"                                        [36]
+       HPTCHINA15 15-bit character set for
+       support of Traditional Chinese
+"HP-Turkish8"                                  [36]
+       HPTURKISH8 8-bit character set
+"IPSYS"                                                [59]
+       registry prefix
+"IPSYS.IE-1"                                   [59]
+"ISO2022"<REG>"-"<ENC>                         [44]
+"ISO646.1991-IRV"                              [107]
+       ISO 646 International Reference Version
+"ISO8859-1"                                    [15],[12]
+       ISO Latin alphabet No. 1
+"ISO8859-2"                                    [15],[12]
+       ISO Latin alphabet No. 2
+"ISO8859-3"                                    [15],[12]
+       ISO Latin alphabet No. 3
+"ISO8859-4"                                    [15],[12]
+       ISO Latin alphabet No. 4
+"ISO8859-5"                                    [15],[12]
+       ISO Latin/Cyrillic alphabet
+"ISO8859-6"                                    [15],[12]
+       ISO Latin/Arabic alphabet
+"ISO8859-7"                                    [15],[12]
+       ISO Latin/Greek alphabet
+"ISO8859-8"                                    [15],[12]
+       ISO Latin/Hebrew alphabet
+"ISO8859-9"                                    [15],[12]
+       ISO Latin alphabet No. 5
+"JISX0201.1976-0"                              [38],[12]
+       8-Bit Alphanumeric-Katakana Code
+"JISX0208.1983-0"                              [40],[12]
+       Japanese Graphic Character Set,
+       GL encoding
+"JISX0208.1990-0"                              [71]
+       Japanese Graphic Character Set,
+       GL encoding
+"JISX0208.1983-1"                              [40]
+       (deprecated)
+       Japanese Graphic Character Set,
+       GL encoding
+"JISX0212.1990-0"                              [72]
+       Supplementary Japanese Graphic Character Set,
+       GL encoding
+"KOI8-R"                                       [119]
+"KSC5601.1987-0"                               [41],[12]
+       Korean Graphic Character Set,
+       GL encoding
+"KSC5601.1987-1"                               [41]
+       (deprecated)
+       Korean Graphic Character Set,
+       GL encoding
+"omron_CNS11643-0"                             [45]
+"omron_CNS11643-1"                             [45]
+"omron_BIG5-0"                                 [45]
+"omron_BIG5-1"                                 [45]
+"wn.tamil.1993"                                        [103]
+
+
+15. FONT PROPERTY NAMES
+
+See QueryFont in the protocol, and Section 3.2 of the XLFD.  In general,
+private properties should start with a leading underscore, followed by the
+organizational prefix, followed by another underscore.
+
+Name                                           Reference
+----                                           ---------
+"ADD_STYLE_NAME"                               [19]
+"AVERAGE_WIDTH"                                        [19]
+"AVG_CAPITAL_WIDTH"                            [19]
+"AVG_LOWERCASE_WIDTH"                          [19]
+"CAP_HEIGHT"                                   [19]
+"CHARSET_ENCODING"                             [19]
+"CHARSET_REGISTRY"                             [19]
+"COPYRIGHT"                                    [19]
+"DESTINATION"                                  [19]
+"END_SPACE"                                    [19]
+"FACE_NAME"                                    [19]
+"FIGURE_WIDTH"                                 [19]
+"FOUNDRY"                                      [19]
+"FAMILY_NAME"                                  [19]
+"ITALIC_ANGLE"                                 [19]
+"MAX_SPACE"                                    [19]
+"MIN_SPACE"                                    [19]
+"NORM_SPACE"                                   [19]
+"NOTICE"                                       [19]
+"PIXEL_SIZE"                                   [19]
+"POINT_SIZE"                                   [19]
+"QUAD_WIDTH"                                   [17], [19]
+"RELATIVE_SETWIDTH"                            [19]
+"RELATIVE_WEIGHT"                              [19]
+"RESOLUTION"                                   [17], [19]
+"RESOLUTION_X"                                 [19]
+"RESOLUTION_Y"                                 [19]
+"SETWIDTH_NAME"                                        [19]
+"SLANT"                                                [19]
+"SMALL_CAP_SIZE"                               [19]
+"SPACING"                                      [19]
+"STRIKEOUT_ASCENT"                             [19]
+"STRIKEOUT_DESCENT"                            [19]
+"SUBSCRIPT_SIZE"                               [19]
+"SUBSCRIPT_X"                                  [19]
+"SUBSCRIPT_Y"                                  [19]
+"SUPERSCRIPT_SIZE"                             [19]
+"SUPERSCRIPT_X"                                        [19]
+"SUPERSCRIPT_Y"                                        [19]
+"UNDERLINE_POSITION"                           [19]
+"UNDERLINE_THICKNESS"                          [19]
+"X_HEIGHT"                                     [19]
+"WEIGHT"                                       [19]
+"WEIGHT_NAME"                                  [19]
+"_ADOBE_POSTSCRIPT_FONTNAME"                   [69]
+
+16. RESOURCE TYPES
+
+See Chapter 15 of the Xlib manual and Section 9.1 of the Xt manual.
+
+Name                                           Reference
+----                                           ---------
+"AcceleratorTable"                             [26]
+"Bool"                                         [26]
+"Boolean"                                      [26]
+"Callback"                                     [26]
+"CallProc"                                     [26]
+"CharSet"                                      [37]
+"Color"                                                [26]
+"CompoundText"                                 [12]
+"Cursor"                                       [26]
+"Dimension"                                    [26]
+"Display"                                      [26]
+"EditMode"                                     [26]
+"File"                                         [26]
+"Float"                                                [26]
+"Font"                                         [26]
+"FontList"                                     [37]
+"FontStruct"                                   [26]
+"Function"                                     [26]
+"Geometry"                                     [26]
+"Immediate"                                    [26]
+"Int"                                          [26]
+"Justify"                                      [26]
+"KeyboardType"                                 [37]
+"Language"                                     [37]
+"Orientation"                                  [26]
+"PEXtClipIndicator"                            [75]
+"PEXtColorBundle"                              [75]
+"PEXtControlFlag"                              [75]
+"PEXtCullMode"                                 [75]
+"PEXtDeferralMode"                             [75]
+"PEXtDepthCueMode"                             [75]
+"PEXtDistinguishMode"                          [75]
+"PEXtEdgeFlag"                                 [75]
+"PEXtGeneralColor"                             [75]
+"PEXtGravity"                                  [75]
+"PEXtHLHSRMode"                                        [75]
+"PEXtIntList"                                  [75]
+"PEXtInteriorStyle"                            [75]
+"PEXtLightSourceType"                          [75]
+"PEXtLimit"                                    [75]
+"PEXtLimit3"                                   [75]
+"PEXtLineType"                                 [75]
+"PEXtModificationMode"                         [75]
+"PEXtPickHighlightMode"                                [75]
+"PEXtPickMode"                                 [75]
+"PEXtPoint"                                    [75]
+"PEXtPoint3"                                   [75]
+"PEXtProjectionType"                           [75]
+"PEXtReflectanceEquation"                      [75]
+"PEXtResizePolicy"                             [75]
+"PEXtShadingMethod"                            [75]
+"PEXtTraversalPolicy"                          [75]
+"PEXtVector"                                   [75]
+"PEXtVector3"                                  [75]
+"PEXtWorkstationType"                          [75]
+"Pixel"                                                [26]
+"Pixmap"                                       [26]
+"Pointer"                                      [26]
+"Position"                                     [26]
+"Short"                                                [26]
+"String"                                       [18],[26]
+"StringTable"                                  [26]
+"TranslationTable"                             [26]
+"UnsignedChar"                                 [26]
+"Widget"                                       [26]
+"Window"                                       [26]
+"Xai" (prefix)                                 [59]
+"Xi" (prefix)                                  [31]
+"XMex" (prefix)                                        [117]
+
+17. APPLICATION CLASSES
+
+See Section 4.1.2.5 of the ICCCM and Section 14.1.8 of the Xlib manual.
+[Only class names, not instance names.]
+
+Name                                           Reference
+----                                           ---------
+"BuilderXcessory"                              [31]
+"BX"                                           [31]
+"Clock"                                                [47]
+"Csm"                                          [75]
+"Exterm"                                       [45]
+"Listres"                                      [47]
+"Medit"                                                [45]
+"Xai"                                          [59]
+"Xbiff"                                                [47]
+"XCalc"                                                [47]
+"XClipboard"                                   [47]
+"XClock"                                       [47]
+"XCutsel"                                      [47]
+"Xditview"                                     [47]
+"Xedit"                                                [47]
+"XEyes"                                                [47]
+"Xfd"                                          [47]
+"XFontSel"                                     [47]
+"Xgc"                                          [47]
+"XLogo"                                                [47]
+"Xman"                                         [47]
+"Xmh"                                          [47]
+"Xsm"                                          [49]
+"XTerm"                                                [47]
+"Xwnmo"                                                [45]
+
+
+18. CLASS EXTENSION RECORD TYPES
+
+See Section 1.4.12 of the Xt Intrinsics manual.
+
+Name                                           Reference
+----                                           ---------
+"Xai" (prefix)                                 [59]
+"XaiCoreClassExtension"                                [59]
+
+19. DISPLAY MANUFACTURER ID
+
+See Section 9 of the X Display Manager Control Protocol.
+
+Name                                           Reference
+----                                           ---------
+"Acorn"                                                [49]
+"CRAB"                                         [84]
+"EFW"                                          [124]
+"FUJITSU"                                      [87]
+"HDS"                                          [70]
+"JCC"                                          [90]
+"Jupiter"                                      [93]
+"TD"                                           [63]
+"Metheus"                                      [117]
+"MIT"                                          [8]
+"NCD"                                          [66]
+"PERITEK"                                      [116]
+"WYSE"                                         [68]
+"X/software-X/bigX"                            [115]
+
+
+20. NON-STANDARD CHARACTER SET ENCODINGS
+
+See Section 6 of the Compound Text standard.
+
+Name                                           Reference
+----                                           ---------
+"DEC.CNS11643.1986-2"                          [53]
+       CNS11643 2-plane using the recommended
+       internal representation scheme
+"DEC.DTSCS.1990-2"                             [54]
+       DEC Taiwan Supplemental Character Set
+"fujitsu.u90x03"                               [87]
+"ILA"                                          [62]
+       registry prefix
+"IPSYS"                                                [59]
+       registry prefix
+"omron_UDC"                                    [45]
+        omron User Defined Charset
+"omron_UDC_ja"                                 [45]
+        omron User Defined Charset for Japanese
+"omron_UDC_zh"                                 [45]
+        omron User Defined Charset for Chinese(Main land)
+"omron_UDC_tw"                                 [45]
+        omron User Defined Charset for Chinese(Taiwan)
+
+
+21. PEX VENDOR ID
+
+For identifying GDPs, GSEs, enum values/types, OC types, table types.
+See PEX 5.1 interoperability conventions.
+
+Value  Name                                    Reference
+-----  ----                                    ---------
+1      MIT                                     [8]
+2      GfxBase, Inc.                           [74]
+3      Silicon Graphics Computer Systems       [6]
+4      Evans & Sutherland                      [75]
+5      Sun Microsystems, Inc.                  [76]
+6      Sumitomo Electric Workstation Corp.     [77]
+7      Hewlett-Packard Co.                     [78]
+8      Metro Link Inc.                         [79]
+9      Stardent Computer                       [80]
+10     Sony Microsystems                       [81]
+11     Digital Equipment Corp.                 [82]
+12     Network Computing Devices               [66]
+13     ShoGraphics, Inc.                       [85]
+14     Tektronix, Inc.                         [86]
+15     FUJITSU LIMITED                         [87]
+16     International Business Machines         [33]
+17     Kubota Pacific Computer                 [95]
+18     Hitachi, Ltd.                           [100]
+19     Megatek Corporation                     [112]
+20     The XFree86 Project, Inc                [113]
+21     Metheus Corp.                           [117]
+
+
+22. XIM ENCODINGS
+
+Names of encodings used for text exchanged in the Input Method Protocol.
+See XIM_ENCODING_NEGOTIATION in section 4.6 of the XIM standard.
+
+"COMPOUND_TEXT"                                        [104]
+
+
+REFERENCES
+
+[1]    Keith Dawson
+       MS: CHR 03 DE
+       Apollo Computer Inc.
+       300 Apollo Drive
+       Chelmsford, MA 01824
+
+[2]    Mark Patrick
+       Ardent Computer
+       880 West Maude Avenue
+       Sunnyvale, CA 94086
+
+[3]    X+ Multiple Buffering/Stereo Library Extension
+       Mark Patrick, Ardent
+
+[4]    Ardent X Server Private Extension
+       Mark Patrick, Ardent
+
+[5]    Visual Technology, Inc.
+
+[6]    Philip Karlton
+       System Software Division
+       Silicon Graphics Computer Systems
+       2011 N. Shoreline Blvd.
+       Mountain View, CA 94309-7311
+
+[7]    Ellis Cohen
+       Open Softare Foundation
+       11 Cambridge Center
+       Cambridge MA 02142
+
+[8]    X Consortium
+       201 Broadway
+       Cambridge MA 01239-1955
+
+[9]    PEX Protocol Specification
+       PEX Protocol Encoding
+       PEX Introduction and Overview
+       Randi Rost, Digital, document editor
+
+[10]   Extending X for Double-Buffering, Multi-Buffering, and Stereo
+       X Consortium
+       201 Broadway
+       Cambridge MA 01239-1955
+
+[11]   X Display Manager Control Protocol
+       X Consortium
+       201 Broadway
+       Cambridge MA 01239-1955
+
+[12]   Compound Text Encoding
+       X Consortium
+       201 Broadway
+       Cambridge MA 01239-1955
+
+[13]   X11 Nonrectangular Window Shape Extension
+       X Consortium
+       201 Broadway
+       Cambridge MA 01239-1955
+
+[14]   VEX - Video Extension to X
+       Todd Brunhoff, Tektronix
+
+[15]   ISO 8859, Information processing - 8-bit single-byte coded graphic
+       character sets, parts 1 through 9
+
+[16]   Inter-Client Communication Conventions Manual
+       X Consortium
+       201 Broadway
+       Cambridge MA 01239-1955
+
+[17]   Obsolete
+
+[18]   Xlib Manual
+       X Consortium
+       201 Broadway
+       Cambridge MA 01239-1955
+
+[19]   X Logical Font Description Conventions
+       X Consortium
+       201 Broadway
+       Cambridge MA 01239-1955
+
+[20]   IXI Limited
+
+[21]   MIT Project Athena
+
+[22]   Apple Computer, Inc.
+
+[23]   X Window System Protocol
+       X Consortium
+       201 Broadway
+       Cambridge MA 01239-1955
+
+[24]   Adobe Systems, Inc.
+
+[25]   Bitstream, Inc.
+
+[26]   Xt Intrinsics Manual
+       X Consortium
+       201 Broadway
+       Cambridge MA 01239-1955
+
+[27]   Digital Equipment Corporation
+
+[28]   Steve Pitschke
+       Stellar Computer, Inc.
+       95 Wells Ave.
+       Newton, MA 02159
+
+[29]   Jeff Vroom
+       Stellar Computer, Inc.
+       95 Wells Ave.
+       Newton, MA 02159
+
+[30]   Crucible
+       Santa Cruz, CA
+
+[31]   Chris D. Peterson
+       Integrated Computer Solutions, Inc.
+       201 Broadway
+       Cambridge, MA  02139
+
+[32]   Kyou Katoh
+       PFU LIMITED
+       687-1 Tsuruma 7 Gou Machida-shi
+       Tokyo 194, Japan
+
+[33]   Jeanne K. Smith
+       D46/996    3500
+       International Business Machines
+       11400 Burnet Road
+       Austin, TX  78758
+
+[34]   Anonymous
+       MIT Software Distribution
+
+[35]   Larry Woestman
+       Hewlett Packard Co.
+       Corvallis Workstation Operation
+       1000 NE Circle Blvd.
+       Corvallis, OR 97330
+
+[36]   Tom McFarland
+       Hewlett-Packard, Co.
+       Corvallis Information Systems
+       1000 N.E. Circle Blvd.
+       Covallis, OR  97330
+
+[37]   Hideo Irie
+       Work Station Division
+       SuperMicro Systems Group
+       Sony Corporation
+       6-7-35 Kitasinagawa Sinagawa-ku
+       Tokyo, Japan
+
+[38]   JIS X 0201-1976 (reaffirmed 1984)
+
+[39]   GB2312-1980
+
+[40]   JIS X 0208-1983
+
+[41]   KS C5601-1987
+
+[42]   Linda Gass
+       Adobe Systems
+       PO Box 7900
+       Mountain View, CA 94039-7900
+
+[43]   Dave Cassing
+       X Strategy Team 
+       Tektronix, Inc.
+       PO Box 1000
+       Wilsonville, Oregon 97070-1000
+
+[44]   ISO2022<REG>-<ENC>
+
+       REG := [_L_<GL_register>][_R_<GR_register>]
+       ENC := [L<GL_EscapeSequence>][R<GR_EscapeSequence>]
+       <GL_EscapeSequence> :=
+               <Left_set><intermediate characters><Final_byte>
+       <GR_EscapeSequence> :=
+               <Right_set><intermediate characters><Final_byte>
+       <Left_set> :=
+                 '4'   /* 94-character sets */
+               | 'M'   /* Multiple-byte character sets */
+       <Right_set> :=
+                 <Left_set>
+               | '6'   /* 96-character sets */
+       <Final_byte> :=
+               "30" - "7E" /* hex encoding of Latin-1 3/0 - 7/14 */
+       <intermediate characters> :=
+                 <empty>
+               | <intermediate character><intermediate characters>
+       <intermediate character> :=
+                 "20" - "2F" /* hex encoding of Latin-1 2/0 - Latin-1 2/15 */
+
+       The "ISO2022" prefix identifies this as an ISO2022-conforming encoding.
+       [] denotes an optional construct.  <GL_register> and <GR_register> are
+       organizational strings that identify this encoding as having a GL or GR
+       component that is not registered with ECMA, but rather is private to
+       the given organization.  At least one of L<GL_EscapeSequence> or
+       R<GR_EscapeSequence> must be present.  If one is missing, the contents
+       of the font in that graphics half is undefined.
+
+[45]   Hiroshi Kuribayashi
+       OMRON Corporation
+       Computer System R&D Laboratory
+       Shimokaiinji, Nagaokakyo-city
+       Kyoto, 617, Japan
+
+[46]   Kyle Marvin
+       Visual Information Technologies, Inc. (VITec)
+       3460 Lotus Drive
+       Plano, TX 75075
+
+[47]   X11R4
+
+[48]   Data General Corp.
+       62 T.W. Alexander Dr.
+       R.T.P. NC, 27709
+       Attn: Janet Leising
+
+[49]   John Bowler
+       Acorn Computers Limited
+       Cambridge Technopark
+       645 Newmarket Road
+       Cambridge
+       CB5 8PB
+       England
+
+[50]   Rick Franklin
+       Intergraph Corporation
+       One Madison Industrial Park
+       Huntsville, Al.  35894-0001
+
+[51]   Dan Coutu
+       Digital Equipment Corporation ZKO 3-3/T13
+       110 Spitbrook Rd.
+       Nashua, NH 03062-2698
+
+[52]   Takayuki Kageyama
+       Computer Division
+       Information Equipment Sector
+       Matsushita Electric Industrial Co., Ltd.
+       1006, Kadoma, Osaka, 571 Japan
+
+[53]   CNS11643
+       National Bureau of Standards
+       Taiwan, Republic of China
+
+[54]   KH Chan
+       Digital Equipment Co.
+       2-4/F Henan Building
+       90 Jaffe Road, Wanchai,
+       Hong Kong
+
+[55]   Mike Wexler
+       FXD/Telerate, Inc.
+       2091 Landings Drive
+       Mountain View, CA 94043
+
+[56]   Lawrence J. Kilgallen
+       Box 81
+       MIT Station
+       Cambridge, MA 02139-0901
+
+[57]   David Rosenthal
+       Sun Microsystems, Inc.
+       2550 Garcia Avenue
+       Mountain View, CA  94043
+
+[58]   Murali V. Srinivasan
+       MTV21-228
+       Sun Microsystems, Inc.
+       2550 Garcia Avenue
+       Mountain View, CA  94043-1100
+
+[59]   Keith Robson
+       Ipsys Software plc
+       Marlborough Court, Pickford St.,
+       Macclesfield, Cheshire, SK11 6JD
+       England
+
+[60]   David Lewis
+       Lewis, Trachtenberg & Associates
+       One Kendall Square      (Building 200, Fourth Floor)
+       Cambridge, MA 02139-1564
+
+[61]   James J Dempsey
+       Bolt Beranek and Newman Inc.
+       150 CambridgePark Drive
+       Cambridge MA 02140
+
+[62]   Glenn Adams
+       International Lisp Associates
+       114 Mount Auburn Street
+       Cambridge, MA 02138
+
+[63]   Sigvald Refsum
+       Tandberg Data A/S
+       PO Box 9
+       Korsvoll, N-0808 OSLO 8
+
+[64]   Masahiko Muramatsu
+       System Techonology Development Center
+       Fuji Xerox Co.,LTD.
+       KSP/R&D Business Park Bldg.
+       100-1, Sakado, Takatsu-ku, Kawasaki-City, Kanagawa-Ken,
+       213 JAPAN
+
+[65]   Tim Glauert
+       Olivetti Research Limited
+       24a Trumpington Street
+       Cambridge, England
+
+[66]   Jim Fulton
+       Network Computing Devices
+       350 North Bernardo Ave.
+       Mountain View, CA  94043
+
+[67]   John Mackin
+       6/23 Northwood Street
+       Camperdown 2050
+       AUSTRALIA
+
+[68]   Bill Rainey
+       Wyse Technology
+       3471 N. First Street
+       San Jose, CA 95134
+
+[69]   PostScript Developer Support
+       Adobe Systems Incorporated
+       PO Box 7900
+       Mountain View, CA 94039-7900
+
+[70]   Adrian Bereanu
+       Human Designed Systems
+
+[71]   JIS X 0208-1990
+
+[72]   JIS X 0212-1990
+
+[73]   Dan Greening
+       Software Transformation
+       1601 Saratoga-Sunnyvale Rd
+       Cupertino, CA 95014
+
+[74]   Dale Luck
+       GfxBase, Inc.
+       1881 Ellwell Dr.
+       Milpitas, CA 95035
+
+[75]   Gary G. Cannon
+       Evans & Sutherland
+       580 Arapeen Dr.
+       P.O. Box 58700
+       Salt Lake City, UT 84158
+
+[76]   Cheryl Huntington
+       MS. MTV21-04
+       Sun Microsystems
+       2550 Garcia Ave.
+       Mountain View, CA.  94043-1100
+
+[77]   Junichi Hiramoto
+       Manager, Engineering Department
+       Sumitomo Electric Workstation Corp.
+       No. 30 Kowa Bldg.  2-4-5 Roppongi, Minato-ku
+       Tokyo, 106 Japan
+
+[78]   Jeff Stevenson; MS 74
+       Hewlett-Packard Co.
+       3404 E. Harmony Road
+       Fort Collins, CO  80525-9599
+
+[79]   Garry M. Paxinos
+       Metro Link Incorporated
+       2213 W. McNab Rd
+       Pompano Beach, FL 33069
+
+[80]   John Dennis
+       Stardent Computer
+       6 New England Tech Center
+       521 Virginia Road
+       Concord, MA 01742
+
+[81]   Mark Patrick
+       Sony Microsystems
+       651 River Oaks Parkway
+       San Jose, CA 95134
+
+[82]   Dick Coulter
+       MLO1-2/U2
+       Digital Equipment Corp.
+       146 Main St.
+       Maynard, MA  01754
+
+[83]   Mark W. Snitily
+       Snitily Graphics Consulting Services
+       894 Brookgrove Lane
+       Cupertino, CA 95014
+
+[84]   Paul Verey
+       Crab Advanced Technologies Ltd.
+       First Base, Beacontree Plaza, Gillette Way
+       Reading, RG2 0BP
+
+[85]   Ken Garnett
+       ShoGraphics, Inc.
+       1890 N. Shoreline Blvd.
+       Mountain View, CA 94043
+
+[86]   Michael F. Cripps
+       Tektronix, Inc
+       P.O Boc 1000 MS 60-850
+       Wilsonville, OR 97070-1000
+
+[87]   Kyou Katoh
+       FUJITSU LIMITED
+       1015 Kamikodanaka Nakahara-ku
+       Kawasaki 221, Japan
+
+[88]   David Kaelbling
+       Rational
+       12 Mountain Rock Ln.
+       Norfolk, MA 02056
+
+[89]   Hal Berman
+       Cognition Corporation
+       755 Middlesex Turnpike
+       Billerica, MA 01821
+
+[90]   Takatoshi Ishii
+       Japan Computer Corp.
+       2-6-9, Higashi Kanda, Chiyoda-ku,
+       Tokyo 101 Japan
+
+[91]   Bill Janssen
+       Xerox PARC
+       3333 Coyote Hill Rd.
+       Palo Alto, CA 94304
+
+[92]   Rick Heli
+       Sun Microsystems, Inc.
+       2550 Garcia Avenue
+       Mountain View, CA  94043-1100
+
+[93]   Russell Leefer
+       Jupiter Systems
+       Suite 200
+       1351 Harbor Bay Parkway
+       Alameda, CA 94501
+
+[94]   Bob Scheifler
+       X Consortium
+       201 Broadway
+       Cambridge MA 01239-1955
+
+[95]   Greg Stiehl
+       Kubota Pacific Computer
+       2630 Walsh Avenue
+       Santa Clara, CA 95051-0905
+
+[96]   MIT Screen Saver Extension
+       X Consortium
+       201 Broadway
+       Cambridge MA 01239-1955
+
+[97]   Big Requests Extension
+       X Consortium
+       201 Broadway
+       Cambridge MA 01239-1955
+
+[98]   Randi Rost
+       Kubota Pacific Computer
+       2630 Walsh Avenue
+       Santa Clara, CA 95051-0905
+
+[99]   Ilan Aisic
+       NYNEX ALLINK Co.
+       4 Gannett Drive
+       White Plains, NY 10604
+
+[100]  Toshiyuki Kuwana
+       Information Equipment Engineering Dept.
+       Omika Works, Hitatchi Ltd.
+       5-2-1 Omika-cho, Hitachi-shi, Ibaraki-ken, 319-12 Japan
+
+[101]  Milind Pansare
+       Mailstop MTV21-228
+       Sun Microsystems, Inc.
+       2550 Garcia Ave.,
+       Mountain View CA. 94043
+
+[102]  John L. Cwikla
+       Wolfram Research, Inc.
+       100 Trade Center Drive
+       Champaign IL, 61820-7237
+
+[103]  University of Washington
+       for WM Tamil fonts
+
+[104]  X Consortium
+       201 Broadway
+       Cambridge MA 01239-1955
+
+[105]  Stephen Gildea
+       X Consortium
+       201 Broadway
+       Cambridge MA 01239-1955
+
+[106]  Selwyn Henriques
+       Tech-Source, Inc.
+       442 S North Lake Blvd.
+       Altamonte Springs FL 32701
+
+[107]  ISO/IEC 646:1991, Information technology -- ISO 7-bit coded
+       character set for information interchange
+
+[108]  X Synchronization Extension
+       X Consortium
+       201 Broadway
+       Cambridge MA 01239-1955
+
+[109]  XC-MISC Extension
+       X Consortium
+       201 Broadway
+       Cambridge MA 01239-1955
+
+[110]  X Image Extension
+       X Consortium
+       201 Broadway
+       Cambridge MA 01239-1955
+
+[111]  X Keyboard Extension
+       X Consortium
+       201 Broadway
+       Cambridge MA 01239-1955
+
+[112]  Allan Frankel
+       Megatek Corporation
+       16868 Via Del Campo Court
+       San Diego, CA  92127-1714
+
+[113]  David Wexelblat
+       The XFree86 Project, Inc.
+       c/o AIB Software Corporation
+       46030 Manekin Plaza, Suite 160
+       Dulles, VA  20166
+
+[114]  Stuart W. Marks
+       SunSoft, Inc.
+       2550 Garcia Avenue, Mail Stop UMTV 21-122
+       Mountain View, CA  94043-1100
+
+[115]  Michael Gehret
+       X/software
+       Marktstrasse 8, D-87730
+       Groenenbach, Germany
+
+[116]  Bob Schulman
+       Peritek Corp.
+       5550 Redwood Road
+       Oakland, CA 94619
+
+[117]  Alan Ricker
+       Metheus Coporation
+       1600 NW Compton Dr.
+       Beaverton OR, 97006
+
+[118]  X Video Extension Protocol Description
+       Version 2, 25-JUL-91
+       David Carver
+
+[119]  Network Working Group's RFC1489
+
+[120]   Cronyx Ltd.
+       Research Computer Center
+       Moscow State University
+       Moscow 119899, Russia
+       Phone: +7 (095) 939-2323
+       Fax: +7 (095) 939-0300
+       E-mail: info@cronyx.ru
+
+[121]  Sun Microsystems Federal, Inc.  Trusted Solaris Extension, 
+       Milind Pansare
+       Secure User Interface Group,
+       Sun Microsystems Federal, Inc.
+       Mail Stop MIL06-94
+       2550 Garcia Avenue,
+       Mountain View, CA 94043-1100
+
+[122]  Record Extension
+       X Consortium
+       201 Broadway
+       Cambridge MA 02139-1955
+
+[123]  Double Buffer Extension Specification
+       X Consortium
+       201 Broadway
+       Cambridge MA 02139-1955
+
+[124]  James A. Moulton
+       EFW, Inc
+       4700 Marine Creek Parkway
+       Ft. Worth, Texas 76136
+
+[125]  Low Bandwidth X Extension Specification
+       X Consortium
+       201 Broadway
+       Cambridge MA 02139-1955
+
+[126]  Security Extension Specification
+       X Consortium
+       201 Broadway
+       Cambridge MA 02139-1955
+
+[127]  Application Group Extension Specification
+       X Consortium
+       201 Broadway
+       Cambridge MA 02139-1955
+
+[128]  X11 Input Extension Protocol Specification
+       X Consortium
+       201 Broadway
+       Cambridge MA 02139-1955
+
+[129]  X Print Extension Protocol Specification
+       X Consortium
+       201 Broadway
+       Cambridge MA 02139-1955